lightman-agent 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/agent.config.template.json +30 -30
  2. package/package.json +52 -52
  3. package/public/assets/index-CcBNCz6h.css +1 -1
  4. package/public/assets/index-D9QHMG8k.js +1 -0
  5. package/public/assets/index-H-8HDl46.js +1 -1
  6. package/public/assets/index-YodeiCia.css +1 -0
  7. package/public/assets/index-legacy-DWtNM8y7.js +41 -0
  8. package/public/assets/museum-map-CwVDA2z1.svg +4182 -0
  9. package/public/assets/polyfills-legacy-DyVYWHbW.js +4 -0
  10. package/public/index.html +7 -2
  11. package/public/templates/custom08/elements/back-button.svg +20 -0
  12. package/public/templates/custom08/elements/base-map-background.svg +37 -0
  13. package/public/templates/custom08/elements/base-map.svg +1191 -0
  14. package/public/templates/custom08/elements/gallery-1-2-3-info-panel.svg +236 -0
  15. package/public/templates/custom08/elements/gallery-4-5-6-7-info-panel.svg +266 -0
  16. package/public/templates/custom08/elements/gallery-8-9-info-panel.svg +274 -0
  17. package/public/templates/custom08/elements/gallery-labels/_nav-map-styles.css +554 -0
  18. package/public/templates/custom08/elements/gallery-labels/_styles.css +556 -0
  19. package/public/templates/custom08/elements/gallery-labels/gallery-1.svg +35 -0
  20. package/public/templates/custom08/elements/gallery-labels/gallery-2.svg +34 -0
  21. package/public/templates/custom08/elements/gallery-labels/gallery-3.svg +34 -0
  22. package/public/templates/custom08/elements/gallery-labels/gallery-4.svg +37 -0
  23. package/public/templates/custom08/elements/gallery-labels/gallery-5.svg +34 -0
  24. package/public/templates/custom08/elements/gallery-labels/gallery-6.svg +34 -0
  25. package/public/templates/custom08/elements/gallery-labels/gallery-7.svg +34 -0
  26. package/public/templates/custom08/elements/gallery-labels/gallery-8.svg +37 -0
  27. package/public/templates/custom08/elements/gallery-labels/gallery-9.svg +34 -0
  28. package/public/templates/custom08/elements/hand-hint.png +0 -0
  29. package/public/templates/custom08/elements/idle-screen-bg.svg +5 -0
  30. package/public/templates/custom08/elements/idle-screen-map.svg +627 -0
  31. package/public/templates/custom08/elements/idle-screen-text.svg +350 -0
  32. package/public/templates/custom08/elements/key-map-1.svg +986 -0
  33. package/public/templates/custom08/elements/key-map-2.svg +1018 -0
  34. package/public/templates/custom08/elements/key-map-3.svg +1019 -0
  35. package/public/templates/custom08/elements/key-map-combined.svg +1001 -0
  36. package/public/templates/custom08/elements/map-highlight-marker.svg +11 -0
  37. package/public/templates/custom08/elements/map-pin-marker.svg +15 -0
  38. package/public/templates/custom08/elements/map-teardrop-star-marker.svg +13 -0
  39. package/public/templates/custom08/elements/nav-circle-galleries-1-3.svg +21 -0
  40. package/public/templates/custom08/elements/nav-circle-galleries-4-7.svg +24 -0
  41. package/public/templates/custom08/elements/nav-circle-galleries-8-9.svg +20 -0
  42. package/public/templates/custom08/elements/section1-map.svg +1435 -0
  43. package/public/templates/custom08/elements/section2-map.svg +1724 -0
  44. package/public/templates/custom08/elements/section3-map.svg +1295 -0
  45. package/public/templates/custom08/fonts/CabinetGrotesk-Variable.ttf +0 -0
  46. package/public/templates/custom08/images/highlights/Screenshot_2026-03-05_at_7.23.12_PM.png +0 -0
  47. package/public/templates/custom08/images/highlights/Screenshot_2026-03-05_at_7.23.56_PM.png +0 -0
  48. package/public/templates/custom08/images/highlights/Screenshot_2026-03-05_at_7.24.24_PM.png +0 -0
  49. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.31.58_PM.jpg +0 -0
  50. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.32.11_PM.jpg +0 -0
  51. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.32.36_PM.jpg +0 -0
  52. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.32.48_PM.jpg +0 -0
  53. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.32.59_PM.jpg +0 -0
  54. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.33.15_PM.jpg +0 -0
  55. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.33.27_PM.jpg +0 -0
  56. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.33.34_PM.jpg +0 -0
  57. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.33.42_PM.jpg +0 -0
  58. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.33.50_PM.jpg +0 -0
  59. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.33.58_PM.jpg +0 -0
  60. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.34.04_PM.jpg +0 -0
  61. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.34.11_PM.jpg +0 -0
  62. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.34.20_PM.jpg +0 -0
  63. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.34.57_PM.jpg +0 -0
  64. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.35.03_PM.jpg +0 -0
  65. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.35.16_PM.jpg +0 -0
  66. package/public/templates/custom08/images/highlights/Screenshot_2026-03-24_at_11.35.23_PM.jpg +0 -0
  67. package/public/templates/custom08/images/highlights/prologue-highlight.png +0 -0
  68. package/scripts/guardian.ps1 +75 -75
  69. package/scripts/install-linux.sh +134 -134
  70. package/scripts/install-rpi.sh +117 -117
  71. package/scripts/install-windows.ps1 +505 -505
  72. package/scripts/launch-kiosk.vbs +101 -101
  73. package/scripts/lightman-agent.logrotate +12 -12
  74. package/scripts/lightman-agent.service +38 -38
  75. package/scripts/lightman-shell.bat +107 -107
  76. package/scripts/reinstall-windows.ps1 +26 -26
  77. package/scripts/restore-desktop.ps1 +32 -32
  78. package/scripts/setup.ps1 +116 -116
  79. package/scripts/setup.sh +115 -115
  80. package/scripts/sync-display.mjs +20 -0
  81. package/scripts/uninstall-linux.sh +50 -50
  82. package/scripts/uninstall-windows.ps1 +54 -54
  83. package/src/commands/display.ts +177 -177
  84. package/src/commands/kiosk.ts +113 -113
  85. package/src/commands/maintenance.ts +106 -106
  86. package/src/commands/network.ts +129 -129
  87. package/src/commands/power.ts +163 -163
  88. package/src/commands/rpi.ts +45 -45
  89. package/src/commands/screenshot.ts +166 -166
  90. package/src/commands/serial.ts +17 -17
  91. package/src/commands/update.ts +124 -124
  92. package/src/index.ts +652 -652
  93. package/src/lib/config.ts +69 -69
  94. package/src/lib/identity.ts +40 -40
  95. package/src/lib/logger.ts +137 -137
  96. package/src/lib/platform.ts +10 -10
  97. package/src/lib/rpi.ts +180 -180
  98. package/src/lib/screens.ts +128 -128
  99. package/src/lib/types.ts +176 -176
  100. package/src/services/commands.ts +107 -107
  101. package/src/services/health.ts +161 -161
  102. package/src/services/kiosk.ts +384 -384
  103. package/src/services/localEvents.ts +60 -60
  104. package/src/services/logForwarder.ts +72 -72
  105. package/src/services/multiScreenKiosk.ts +324 -324
  106. package/src/services/oscBridge.ts +186 -186
  107. package/src/services/powerScheduler.ts +260 -260
  108. package/src/services/provisioning.ts +120 -120
  109. package/src/services/serialBridge.ts +230 -230
  110. package/src/services/serviceLauncher.ts +183 -183
  111. package/src/services/staticServer.ts +226 -226
  112. package/src/services/updater.ts +249 -249
  113. package/src/services/watchdog.ts +310 -310
  114. package/src/services/websocket.ts +152 -152
  115. package/tsconfig.json +28 -28
@@ -1,54 +1,54 @@
1
- # LIGHTMAN Agent - Windows Uninstaller
2
- # Removes everything: service, tasks, processes, files, shell.
3
- #Requires -RunAsAdministrator
4
-
5
- $ErrorActionPreference = "Continue"
6
- $NssmExe = "C:\ProgramData\Lightman\nssm\nssm.exe"
7
- $ServiceName = "LightmanAgent"
8
-
9
- Write-Host ""
10
- Write-Host "=== LIGHTMAN Agent - Uninstaller ===" -ForegroundColor Cyan
11
-
12
- # 1. Service
13
- Write-Host "[1/6] Removing service..." -ForegroundColor Yellow
14
- if (Test-Path $NssmExe) { & $NssmExe stop $ServiceName 2>$null; & $NssmExe remove $ServiceName confirm 2>$null }
15
- foreach ($sn in @($ServiceName,"lightmanagent.exe")) { sc.exe stop $sn 2>$null; sc.exe delete $sn 2>$null }
16
- $s = Get-Service -DisplayName "LIGHTMAN*" -ErrorAction SilentlyContinue
17
- if ($s) { Stop-Service $s.Name -Force -ErrorAction SilentlyContinue; sc.exe delete $s.Name 2>$null }
18
-
19
- # 2. Tasks
20
- Write-Host "[2/6] Removing tasks..." -ForegroundColor Yellow
21
- foreach ($tn in @("LIGHTMAN Agent","LIGHTMAN Kiosk Browser","LIGHTMAN Guardian")) {
22
- $t = Get-ScheduledTask -TaskName $tn -ErrorAction SilentlyContinue
23
- if ($t) { Stop-ScheduledTask -TaskName $tn -ErrorAction SilentlyContinue; Unregister-ScheduledTask -TaskName $tn -Confirm:$false -ErrorAction SilentlyContinue }
24
- }
25
-
26
- # 3. Processes
27
- Write-Host "[3/6] Killing processes..." -ForegroundColor Yellow
28
- Get-Process -Name "node" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
29
- Get-Process -Name "chrome" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
30
-
31
- # 4. Firewall
32
- Write-Host "[4/6] Removing firewall rule..." -ForegroundColor Yellow
33
- Remove-NetFirewallRule -DisplayName "LIGHTMAN Agent WebSocket" -ErrorAction SilentlyContinue
34
-
35
- # 5. Shell
36
- Write-Host "[5/6] Restoring shell..." -ForegroundColor Yellow
37
- $HKLMPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
38
- $shell = (Get-ItemProperty -Path $HKLMPath -Name "Shell" -ErrorAction SilentlyContinue).Shell
39
- if ($shell -and $shell -like "*lightman*") {
40
- $orig = (Get-ItemProperty -Path $HKLMPath -Name "Shell_Original" -ErrorAction SilentlyContinue).Shell_Original
41
- Set-ItemProperty -Path $HKLMPath -Name "Shell" -Value $(if ($orig) { $orig } else { "explorer.exe" })
42
- Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "Shell" -ErrorAction SilentlyContinue
43
- Write-Host " Shell restored"
44
- }
45
-
46
- # 6. Files
47
- Write-Host "[6/6] Removing files..." -ForegroundColor Yellow
48
- Remove-Item "C:\Program Files\Lightman" -Recurse -Force -ErrorAction SilentlyContinue
49
- $choice = Read-Host "Remove all data (logs, chrome cache, nssm)? [y/N]"
50
- if ($choice -eq 'y') { Remove-Item "C:\ProgramData\Lightman" -Recurse -Force -ErrorAction SilentlyContinue }
51
-
52
- Write-Host ""
53
- Write-Host "=== Done. Reboot: Restart-Computer ===" -ForegroundColor Green
54
- Write-Host ""
1
+ # LIGHTMAN Agent - Windows Uninstaller
2
+ # Removes everything: service, tasks, processes, files, shell.
3
+ #Requires -RunAsAdministrator
4
+
5
+ $ErrorActionPreference = "Continue"
6
+ $NssmExe = "C:\ProgramData\Lightman\nssm\nssm.exe"
7
+ $ServiceName = "LightmanAgent"
8
+
9
+ Write-Host ""
10
+ Write-Host "=== LIGHTMAN Agent - Uninstaller ===" -ForegroundColor Cyan
11
+
12
+ # 1. Service
13
+ Write-Host "[1/6] Removing service..." -ForegroundColor Yellow
14
+ if (Test-Path $NssmExe) { & $NssmExe stop $ServiceName 2>$null; & $NssmExe remove $ServiceName confirm 2>$null }
15
+ foreach ($sn in @($ServiceName,"lightmanagent.exe")) { sc.exe stop $sn 2>$null; sc.exe delete $sn 2>$null }
16
+ $s = Get-Service -DisplayName "LIGHTMAN*" -ErrorAction SilentlyContinue
17
+ if ($s) { Stop-Service $s.Name -Force -ErrorAction SilentlyContinue; sc.exe delete $s.Name 2>$null }
18
+
19
+ # 2. Tasks
20
+ Write-Host "[2/6] Removing tasks..." -ForegroundColor Yellow
21
+ foreach ($tn in @("LIGHTMAN Agent","LIGHTMAN Kiosk Browser","LIGHTMAN Guardian")) {
22
+ $t = Get-ScheduledTask -TaskName $tn -ErrorAction SilentlyContinue
23
+ if ($t) { Stop-ScheduledTask -TaskName $tn -ErrorAction SilentlyContinue; Unregister-ScheduledTask -TaskName $tn -Confirm:$false -ErrorAction SilentlyContinue }
24
+ }
25
+
26
+ # 3. Processes
27
+ Write-Host "[3/6] Killing processes..." -ForegroundColor Yellow
28
+ Get-Process -Name "node" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
29
+ Get-Process -Name "chrome" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
30
+
31
+ # 4. Firewall
32
+ Write-Host "[4/6] Removing firewall rule..." -ForegroundColor Yellow
33
+ Remove-NetFirewallRule -DisplayName "LIGHTMAN Agent WebSocket" -ErrorAction SilentlyContinue
34
+
35
+ # 5. Shell
36
+ Write-Host "[5/6] Restoring shell..." -ForegroundColor Yellow
37
+ $HKLMPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
38
+ $shell = (Get-ItemProperty -Path $HKLMPath -Name "Shell" -ErrorAction SilentlyContinue).Shell
39
+ if ($shell -and $shell -like "*lightman*") {
40
+ $orig = (Get-ItemProperty -Path $HKLMPath -Name "Shell_Original" -ErrorAction SilentlyContinue).Shell_Original
41
+ Set-ItemProperty -Path $HKLMPath -Name "Shell" -Value $(if ($orig) { $orig } else { "explorer.exe" })
42
+ Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "Shell" -ErrorAction SilentlyContinue
43
+ Write-Host " Shell restored"
44
+ }
45
+
46
+ # 6. Files
47
+ Write-Host "[6/6] Removing files..." -ForegroundColor Yellow
48
+ Remove-Item "C:\Program Files\Lightman" -Recurse -Force -ErrorAction SilentlyContinue
49
+ $choice = Read-Host "Remove all data (logs, chrome cache, nssm)? [y/N]"
50
+ if ($choice -eq 'y') { Remove-Item "C:\ProgramData\Lightman" -Recurse -Force -ErrorAction SilentlyContinue }
51
+
52
+ Write-Host ""
53
+ Write-Host "=== Done. Reboot: Restart-Computer ===" -ForegroundColor Green
54
+ Write-Host ""
@@ -1,177 +1,177 @@
1
- import { execFile, spawn } from 'child_process';
2
- import { z } from 'zod';
3
- import type { CommandHandler } from '../lib/types.js';
4
- import { getPlatform } from '../lib/platform.js';
5
- import type { Logger } from '../lib/logger.js';
6
-
7
- // --- Zod Schemas ---
8
- const BrightnessArgsSchema = z.object({
9
- level: z.number().int().min(0).max(100),
10
- });
11
-
12
- const PowerArgsSchema = z.object({
13
- state: z.enum(['on', 'off', 'standby']),
14
- });
15
-
16
- const RotateArgsSchema = z.object({
17
- rotation: z.enum(['normal', 'left', 'right', 'inverted']),
18
- });
19
-
20
- const VolumeArgsSchema = z.object({
21
- level: z.number().int().min(0).max(100),
22
- });
23
-
24
- function execFilePromise(cmd: string, args: string[]): Promise<string> {
25
- return new Promise((resolve, reject) => {
26
- execFile(cmd, args, (err, stdout, stderr) => {
27
- if (err) {
28
- reject(new Error(stderr || err.message));
29
- return;
30
- }
31
- resolve(stdout.trim());
32
- });
33
- });
34
- }
35
-
36
- /**
37
- * Pipe data to a command via stdin using spawn (no shell).
38
- */
39
- function spawnWithStdin(cmd: string, args: string[], stdinData: string): Promise<string> {
40
- return new Promise((resolve, reject) => {
41
- const child = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'] });
42
- let stdout = '';
43
- let stderr = '';
44
-
45
- child.stdout.on('data', (data: Buffer) => { stdout += data.toString(); });
46
- child.stderr.on('data', (data: Buffer) => { stderr += data.toString(); });
47
-
48
- child.on('error', (err) => reject(new Error(err.message)));
49
- child.on('close', (code) => {
50
- if (code !== 0) {
51
- reject(new Error(stderr || `Process exited with code ${code}`));
52
- return;
53
- }
54
- resolve(stdout.trim());
55
- });
56
-
57
- child.stdin.write(stdinData);
58
- child.stdin.end();
59
- });
60
- }
61
-
62
- /**
63
- * Detect the primary connected display output name from xrandr.
64
- */
65
- async function getConnectedDisplay(): Promise<string> {
66
- const output = await execFilePromise('xrandr', []);
67
- const match = output.match(/^(\S+)\s+connected/m);
68
- if (!match) {
69
- throw new Error('No connected display found');
70
- }
71
- return match[1];
72
- }
73
-
74
- export function registerDisplayCommands(
75
- register: (command: string, handler: CommandHandler) => void,
76
- logger: Logger
77
- ): void {
78
- // display:brightness — set screen brightness (Linux only)
79
- register('display:brightness', async (args) => {
80
- if (getPlatform() !== 'linux') {
81
- throw new Error('Not supported on this platform');
82
- }
83
-
84
- const parsed = BrightnessArgsSchema.safeParse(args ?? {});
85
- if (!parsed.success) {
86
- throw new Error('Invalid brightness level, must be 0-100');
87
- }
88
-
89
- const { level } = parsed.data;
90
- const brightness = (level / 100).toFixed(2);
91
-
92
- logger.info(`Setting brightness to ${level}%`);
93
-
94
- const display = await getConnectedDisplay();
95
- await execFilePromise('xrandr', ['--output', display, '--brightness', brightness]);
96
- return { level };
97
- });
98
-
99
- // display:power — control display power via CEC (Linux only)
100
- register('display:power', async (args) => {
101
- if (getPlatform() !== 'linux') {
102
- throw new Error('Not supported on this platform');
103
- }
104
-
105
- const parsed = PowerArgsSchema.safeParse(args ?? {});
106
- if (!parsed.success) {
107
- throw new Error('Invalid state, must be on | off | standby');
108
- }
109
-
110
- const { state } = parsed.data;
111
-
112
- const cecCommands: Readonly<Record<string, string>> = {
113
- on: 'on 0',
114
- off: 'standby 0',
115
- standby: 'standby 0',
116
- };
117
-
118
- const cecCmd = cecCommands[state];
119
-
120
- logger.info(`Setting display power to ${state}`);
121
-
122
- // Pipe CEC command via spawn stdin (no shell)
123
- await spawnWithStdin('cec-client', ['-s', '-d', '1'], cecCmd + '\n');
124
- return { state };
125
- });
126
-
127
- // display:rotate — rotate display output (Linux only)
128
- register('display:rotate', async (args) => {
129
- if (getPlatform() !== 'linux') {
130
- throw new Error('Not supported on this platform');
131
- }
132
-
133
- const parsed = RotateArgsSchema.safeParse(args ?? {});
134
- if (!parsed.success) {
135
- throw new Error('Invalid rotation, must be normal | left | right | inverted');
136
- }
137
-
138
- const { rotation } = parsed.data;
139
-
140
- logger.info(`Setting display rotation to ${rotation}`);
141
-
142
- const display = await getConnectedDisplay();
143
- await execFilePromise('xrandr', ['--output', display, '--rotate', rotation]);
144
- return { rotation };
145
- });
146
-
147
- // display:volume — set audio volume (Linux only)
148
- register('display:volume', async (args) => {
149
- if (getPlatform() !== 'linux') {
150
- throw new Error('Not supported on this platform');
151
- }
152
-
153
- const parsed = VolumeArgsSchema.safeParse(args ?? {});
154
- if (!parsed.success) {
155
- throw new Error('Invalid volume level, must be 0-100');
156
- }
157
-
158
- const { level } = parsed.data;
159
-
160
- logger.info(`Setting volume to ${level}%`);
161
-
162
- await execFilePromise('amixer', ['set', 'Master', `${level}%`]);
163
- return { level };
164
- });
165
-
166
- // display:info — query display information (Linux with fallback)
167
- register('display:info', async () => {
168
- if (getPlatform() !== 'linux') {
169
- throw new Error('Not supported on this platform');
170
- }
171
-
172
- logger.info('Querying display info');
173
-
174
- const stdout = await execFilePromise('xrandr', ['--query']);
175
- return { raw: stdout };
176
- });
177
- }
1
+ import { execFile, spawn } from 'child_process';
2
+ import { z } from 'zod';
3
+ import type { CommandHandler } from '../lib/types.js';
4
+ import { getPlatform } from '../lib/platform.js';
5
+ import type { Logger } from '../lib/logger.js';
6
+
7
+ // --- Zod Schemas ---
8
+ const BrightnessArgsSchema = z.object({
9
+ level: z.number().int().min(0).max(100),
10
+ });
11
+
12
+ const PowerArgsSchema = z.object({
13
+ state: z.enum(['on', 'off', 'standby']),
14
+ });
15
+
16
+ const RotateArgsSchema = z.object({
17
+ rotation: z.enum(['normal', 'left', 'right', 'inverted']),
18
+ });
19
+
20
+ const VolumeArgsSchema = z.object({
21
+ level: z.number().int().min(0).max(100),
22
+ });
23
+
24
+ function execFilePromise(cmd: string, args: string[]): Promise<string> {
25
+ return new Promise((resolve, reject) => {
26
+ execFile(cmd, args, (err, stdout, stderr) => {
27
+ if (err) {
28
+ reject(new Error(stderr || err.message));
29
+ return;
30
+ }
31
+ resolve(stdout.trim());
32
+ });
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Pipe data to a command via stdin using spawn (no shell).
38
+ */
39
+ function spawnWithStdin(cmd: string, args: string[], stdinData: string): Promise<string> {
40
+ return new Promise((resolve, reject) => {
41
+ const child = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'] });
42
+ let stdout = '';
43
+ let stderr = '';
44
+
45
+ child.stdout.on('data', (data: Buffer) => { stdout += data.toString(); });
46
+ child.stderr.on('data', (data: Buffer) => { stderr += data.toString(); });
47
+
48
+ child.on('error', (err) => reject(new Error(err.message)));
49
+ child.on('close', (code) => {
50
+ if (code !== 0) {
51
+ reject(new Error(stderr || `Process exited with code ${code}`));
52
+ return;
53
+ }
54
+ resolve(stdout.trim());
55
+ });
56
+
57
+ child.stdin.write(stdinData);
58
+ child.stdin.end();
59
+ });
60
+ }
61
+
62
+ /**
63
+ * Detect the primary connected display output name from xrandr.
64
+ */
65
+ async function getConnectedDisplay(): Promise<string> {
66
+ const output = await execFilePromise('xrandr', []);
67
+ const match = output.match(/^(\S+)\s+connected/m);
68
+ if (!match) {
69
+ throw new Error('No connected display found');
70
+ }
71
+ return match[1];
72
+ }
73
+
74
+ export function registerDisplayCommands(
75
+ register: (command: string, handler: CommandHandler) => void,
76
+ logger: Logger
77
+ ): void {
78
+ // display:brightness — set screen brightness (Linux only)
79
+ register('display:brightness', async (args) => {
80
+ if (getPlatform() !== 'linux') {
81
+ throw new Error('Not supported on this platform');
82
+ }
83
+
84
+ const parsed = BrightnessArgsSchema.safeParse(args ?? {});
85
+ if (!parsed.success) {
86
+ throw new Error('Invalid brightness level, must be 0-100');
87
+ }
88
+
89
+ const { level } = parsed.data;
90
+ const brightness = (level / 100).toFixed(2);
91
+
92
+ logger.info(`Setting brightness to ${level}%`);
93
+
94
+ const display = await getConnectedDisplay();
95
+ await execFilePromise('xrandr', ['--output', display, '--brightness', brightness]);
96
+ return { level };
97
+ });
98
+
99
+ // display:power — control display power via CEC (Linux only)
100
+ register('display:power', async (args) => {
101
+ if (getPlatform() !== 'linux') {
102
+ throw new Error('Not supported on this platform');
103
+ }
104
+
105
+ const parsed = PowerArgsSchema.safeParse(args ?? {});
106
+ if (!parsed.success) {
107
+ throw new Error('Invalid state, must be on | off | standby');
108
+ }
109
+
110
+ const { state } = parsed.data;
111
+
112
+ const cecCommands: Readonly<Record<string, string>> = {
113
+ on: 'on 0',
114
+ off: 'standby 0',
115
+ standby: 'standby 0',
116
+ };
117
+
118
+ const cecCmd = cecCommands[state];
119
+
120
+ logger.info(`Setting display power to ${state}`);
121
+
122
+ // Pipe CEC command via spawn stdin (no shell)
123
+ await spawnWithStdin('cec-client', ['-s', '-d', '1'], cecCmd + '\n');
124
+ return { state };
125
+ });
126
+
127
+ // display:rotate — rotate display output (Linux only)
128
+ register('display:rotate', async (args) => {
129
+ if (getPlatform() !== 'linux') {
130
+ throw new Error('Not supported on this platform');
131
+ }
132
+
133
+ const parsed = RotateArgsSchema.safeParse(args ?? {});
134
+ if (!parsed.success) {
135
+ throw new Error('Invalid rotation, must be normal | left | right | inverted');
136
+ }
137
+
138
+ const { rotation } = parsed.data;
139
+
140
+ logger.info(`Setting display rotation to ${rotation}`);
141
+
142
+ const display = await getConnectedDisplay();
143
+ await execFilePromise('xrandr', ['--output', display, '--rotate', rotation]);
144
+ return { rotation };
145
+ });
146
+
147
+ // display:volume — set audio volume (Linux only)
148
+ register('display:volume', async (args) => {
149
+ if (getPlatform() !== 'linux') {
150
+ throw new Error('Not supported on this platform');
151
+ }
152
+
153
+ const parsed = VolumeArgsSchema.safeParse(args ?? {});
154
+ if (!parsed.success) {
155
+ throw new Error('Invalid volume level, must be 0-100');
156
+ }
157
+
158
+ const { level } = parsed.data;
159
+
160
+ logger.info(`Setting volume to ${level}%`);
161
+
162
+ await execFilePromise('amixer', ['set', 'Master', `${level}%`]);
163
+ return { level };
164
+ });
165
+
166
+ // display:info — query display information (Linux with fallback)
167
+ register('display:info', async () => {
168
+ if (getPlatform() !== 'linux') {
169
+ throw new Error('Not supported on this platform');
170
+ }
171
+
172
+ logger.info('Querying display info');
173
+
174
+ const stdout = await execFilePromise('xrandr', ['--query']);
175
+ return { raw: stdout };
176
+ });
177
+ }