summrise-agent 1.2.455 → 1.2.457

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.
package/bin/summrise.js CHANGED
@@ -38,6 +38,8 @@ exports.BOOT_TASKS = exports.psq = void 0;
38
38
  exports.psArgv = psArgv;
39
39
  exports.deskShortcutRepairPs = deskShortcutRepairPs;
40
40
  exports.startDesktopPs = startDesktopPs;
41
+ exports.desktopTaskPs = desktopTaskPs;
42
+ exports.desktopStartPs = desktopStartPs;
41
43
  exports.parseAgentPort = parseAgentPort;
42
44
  exports.parseDeviceToken = parseDeviceToken;
43
45
  exports.parseTargetArg = parseTargetArg;
@@ -305,6 +307,63 @@ function startDesktopPs(deskDirQ) {
305
307
  `& "$dir\\node_modules\\electron\\dist\\electron.exe" .`,
306
308
  ];
307
309
  }
310
+ /** The desktop shell's watchdog pair + its task, as ONE PowerShell script.
311
+ *
312
+ * WHY IT IS A FILE AND NOT AN INLINE -Command: it has to write two other files whose
313
+ * contents contain quotes, and every attempt to do that inside one command string turns
314
+ * into quoting hell — the first version of this shipped as a hand-written file for that
315
+ * reason. `summrise setup` writes it and `summrise desktop` runs it, so a machine that
316
+ * never ran setup can still get a working task by asking for the window. Idempotent:
317
+ * ensure-desktop.ps1 exits when electron is already alive, so the 5-minute trigger never
318
+ * steals focus. unit-tested. */
319
+ function desktopTaskPs(installQ) {
320
+ return [
321
+ "# written by `summrise setup` / `summrise desktop` -- the desktop shell's task + watchdog.",
322
+ "$ErrorActionPreference = 'Stop'",
323
+ `$q = '${installQ}'`,
324
+ `$en = Join-Path $q 'scripts\\ensure-desktop.ps1'`,
325
+ `$vb = Join-Path $q 'scripts\\desktop-pulse.vbs'`,
326
+ `Set-Content -Path $en -Value ('if (Get-Process electron -ErrorAction SilentlyContinue) { exit }; & powershell -NoProfile -ExecutionPolicy Bypass -File "' + $q + '\\scripts\\start-desktop.ps1"') -Force`,
327
+ `Set-Content -Path $vb -Value ('CreateObject("WScript.Shell").Run "powershell -NoProfile -ExecutionPolicy Bypass -File " & Chr(34) & "' + $en + '" & Chr(34), 0, False') -Force`,
328
+ `$da = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument ('"' + $vb + '"') -WorkingDirectory $q`,
329
+ `$dt1 = New-ScheduledTaskTrigger -AtLogOn`,
330
+ `$dw1 = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(3) -RepetitionInterval (New-TimeSpan -Minutes 5)`,
331
+ `$pr = New-ScheduledTaskPrincipal -UserId ('{0}\\{1}' -f $env:USERDOMAIN, $env:USERNAME) -LogonType Interactive -RunLevel Highest`,
332
+ `$st = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 10) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew`,
333
+ `Register-ScheduledTask SummriseDesktop -Action $da -Trigger @($dt1,$dw1) -Principal $pr -Settings $st -Force | Out-Null`,
334
+ `Start-ScheduledTask -TaskName SummriseDesktop`,
335
+ ];
336
+ }
337
+ /** Ask whether the shell is up, and start it if it is not — printing ONE WORD the caller
338
+ * can trust: `already-running`, `started`, or `not-started`. A command that says "ok"
339
+ * without distinguishing those three is how an operator ends up staring at a desktop
340
+ * wondering whether anything happened.
341
+ *
342
+ * TWO THINGS MEASURED ON THE DEVICE, both of which made the first version of this wrong:
343
+ *
344
+ * 1. `powershell -File '<path>'` DOES NOT WORK. The single quotes are for PowerShell's own
345
+ * strings; at the cmd layer they are literal characters, so PowerShell received a path
346
+ * with quotes in it and answered "不支持给定路径的格式" (the path format is not
347
+ * supported). Double quotes are what `-File` wants, and `psq()` — which escapes for a
348
+ * PS string — is the wrong tool here. The same mistake sat in `setup`, unnoticed because
349
+ * the task had been registered by hand.
350
+ *
351
+ * 2. DO NOT RE-REGISTER THE TASK TO START IT. `Register-ScheduledTask` needs the user's
352
+ * principal as `DOMAIN\user`, and a shell running as a service account has no such
353
+ * mapping: from a PTY running as systemprofile the device answered "帐户名与安全标识间
354
+ * 无任何映射完成 … UserId" while the task itself was Ready. The task already carries the
355
+ * right principal — it is `setup` that creates it — so starting it is all that is needed,
356
+ * and registering is reserved for the case where it is genuinely absent. */
357
+ function desktopStartPs(installQ) {
358
+ return [
359
+ `if (Get-Process electron -ErrorAction SilentlyContinue) { Write-Output 'already-running'; exit 0 }`,
360
+ `$t = Get-ScheduledTask -TaskName SummriseDesktop -ErrorAction SilentlyContinue`,
361
+ `if (-not $t) { & powershell -NoProfile -ExecutionPolicy Bypass -File "${installQ}\\scripts\\register-desktop-task.ps1" }`,
362
+ `Start-ScheduledTask -TaskName SummriseDesktop -ErrorAction SilentlyContinue`,
363
+ `Start-Sleep -Seconds 3`,
364
+ `if (Get-Process electron -ErrorAction SilentlyContinue) { Write-Output 'started' } else { Write-Output 'not-started'; exit 1 }`,
365
+ ].join("; ");
366
+ }
308
367
  // exported: agent bind port plumbing (custom-port installs). server.port
309
368
  // out of <dir>/config.yaml (first `port:` under top-level `server:`),
310
369
  // canonical 18080 when absent/invalid/missing (fresh installs have no
@@ -1733,23 +1792,12 @@ const commands = {
1733
1792
  // repetition is what reborns a dead shell.
1734
1793
  try {
1735
1794
  const reg = path.join(SCRIPTS_DIR, "register-desktop-task.ps1");
1736
- fs.writeFileSync(reg, [
1737
- "# written by `summrise setup` -- the desktop shell's ONLOGON task + watchdog.",
1738
- "$ErrorActionPreference = 'Stop'",
1739
- `$q = '${(0, exports.psq)(DIR)}'`,
1740
- `$en = Join-Path $q 'scripts\\ensure-desktop.ps1'`,
1741
- `$vb = Join-Path $q 'scripts\\desktop-pulse.vbs'`,
1742
- `Set-Content -Path $en -Value ('if (Get-Process electron -ErrorAction SilentlyContinue) { exit }; & powershell -NoProfile -ExecutionPolicy Bypass -File "' + $q + '\\scripts\\start-desktop.ps1"') -Force`,
1743
- `Set-Content -Path $vb -Value ('CreateObject("WScript.Shell").Run "powershell -NoProfile -ExecutionPolicy Bypass -File " & Chr(34) & "' + $en + '" & Chr(34), 0, False') -Force`,
1744
- `$da = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument ('"' + $vb + '"') -WorkingDirectory $q`,
1745
- `$dt1 = New-ScheduledTaskTrigger -AtLogOn`,
1746
- `$dw1 = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(3) -RepetitionInterval (New-TimeSpan -Minutes 5)`,
1747
- `$pr = New-ScheduledTaskPrincipal -UserId ('{0}\\{1}' -f $env:USERDOMAIN, $env:USERNAME) -LogonType Interactive -RunLevel Highest`,
1748
- `$st = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 10) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew`,
1749
- `Register-ScheduledTask SummriseDesktop -Action $da -Trigger @($dt1,$dw1) -Principal $pr -Settings $st -Force | Out-Null`,
1750
- `Start-ScheduledTask -TaskName SummriseDesktop`,
1751
- ].join("\r\n") + "\r\n");
1752
- sh(`powershell -NoProfile -ExecutionPolicy Bypass -File '${(0, exports.psq)(reg)}'`);
1795
+ fs.writeFileSync(reg, desktopTaskPs(DIR).join("\r\n") + "\r\n");
1796
+ sh(
1797
+ // DOUBLE quotes — a cmd-layer argument. The single-quoted version this shipped with
1798
+ // reached PowerShell with the quotes included and died on the device with
1799
+ // "不支持给定路径的格式" (unsupported path format).
1800
+ `powershell -NoProfile -ExecutionPolicy Bypass -File "${reg}"`);
1753
1801
  console.log("setup: SummriseDesktop registered (logon + a 5-minute watchdog) and started");
1754
1802
  }
1755
1803
  catch {
@@ -1953,6 +2001,44 @@ const commands = {
1953
2001
  },
1954
2002
  // Live view: redraw in place every few seconds until Ctrl+C. `summrise watch
1955
2003
  // <host:port[/path]>` narrows it to one target and adds its outage log.
2004
+ // `summrise desktop` = put the window back, or say it is already there.
2005
+ //
2006
+ // WHY IT EXISTS. The shell is normally started by the SummriseDesktop task, but the LAUNCHER
2007
+ // dies with the console that started it — measured twice on 2026-09-23, both times arriving
2008
+ // as "electron 又不见了" — and until now there was no command to ask for it, only a .ps1 path
2009
+ // an operator had to know. Idempotent by construction (the task's ensure-desktop.ps1 exits
2010
+ // when electron is alive, so a running shell is never disturbed), and it distinguishes the
2011
+ // three outcomes. "ok" without saying WHICH is how an operator ends up staring at a desktop.
2012
+ desktop() {
2013
+ const reg = path.join(SCRIPTS_DIR, "register-desktop-task.ps1");
2014
+ fs.mkdirSync(SCRIPTS_DIR, { recursive: true });
2015
+ if (!fs.existsSync(reg)) {
2016
+ // A machine that never ran setup still gets a working task: the same script setup
2017
+ // writes, from the same builder, so the two cannot drift.
2018
+ fs.writeFileSync(reg, desktopTaskPs(DIR).join("\r\n") + "\r\n");
2019
+ }
2020
+ try {
2021
+ // DOUBLE quotes: this is a cmd-layer argument, and `psq()` escapes for a PowerShell
2022
+ // string instead — the single-quoted version reached PowerShell with the quotes still in
2023
+ // it and failed on the device with "unsupported path format". Same fix in `setup` below.
2024
+ sh(`powershell -NoProfile -ExecutionPolicy Bypass -File "${reg}"`);
2025
+ }
2026
+ catch {
2027
+ /* the task may already exist and be healthy; the check below is the verdict */
2028
+ }
2029
+ const r = (0, child_process_1.spawnSync)("powershell", ["-NoProfile", "-Command", desktopStartPs(DIR)], { encoding: "utf8", shell: true });
2030
+ const out = String(r.stdout || "").trim();
2031
+ if (out.endsWith("already-running")) {
2032
+ console.log("desktop: the Summrise shell is ALREADY RUNNING (look for the window, or the tray icon)");
2033
+ return;
2034
+ }
2035
+ if (out.endsWith("started")) {
2036
+ console.log("desktop: started -- the window should be on your desktop now");
2037
+ return;
2038
+ }
2039
+ console.error(`desktop: the shell did NOT come up. Try it directly to see why: powershell -File "${path.join(SCRIPTS_DIR, "start-desktop.ps1")}"`);
2040
+ process.exit(1);
2041
+ },
1956
2042
  status() {
1957
2043
  // NOT via shell: `shell: true` concatenates argv into one cmd.exe string,
1958
2044
  // so the unquoted filter "IMAGENAME eq …" was split at its spaces, tasklist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "summrise-agent",
3
- "version": "1.2.455",
3
+ "version": "1.2.457",
4
4
  "description": "Summrise Agent — Windows device MCP server (terminal/SSH/serial) + panel. Self-hosted npm distribution.",
5
5
  "//build": "唯一构建路径:在本目录执行 npm run build。它是自包含的:经 npm exec 按需拉取 typescript@5,无需预装任何 node_modules(干净检出可跑;旧脚本引用 ../summrise-desktop-electron/node_modules/.bin/tsc,干净检出必 ENOENT)。必须用 npm exec --package … -- tsc 的形式:npx 会吃掉传给 tsc 的 -p/--outDir 等参数(round-435:npx 写法从未真正跑通过)。先编 electron TS(--noCheck 纯 emit,与 release.yml 一致)同步两处 src/*.js,再编 src/summrise.ts 到 bin/summrise.js 并校验 round-298 标记(弱 oracle,只证某次构建发生,新鲜性由 publish-release.sh 的 tsc 重编 + cmp 门保证)。",
6
6
  "bin": {
Binary file