litmus-cli 1.5.2 → 1.5.4

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 (134) hide show
  1. package/dist/commands/connect.d.ts +47 -1
  2. package/dist/commands/connect.d.ts.map +1 -1
  3. package/dist/commands/connect.js +312 -127
  4. package/dist/commands/connect.js.map +1 -1
  5. package/dist/commands/diagnose-connection.js +1 -1
  6. package/dist/commands/diagnose-connection.js.map +1 -1
  7. package/dist/commands/doctor.d.ts.map +1 -1
  8. package/dist/commands/doctor.js +81 -20
  9. package/dist/commands/doctor.js.map +1 -1
  10. package/dist/commands/init.d.ts +1 -0
  11. package/dist/commands/init.d.ts.map +1 -1
  12. package/dist/commands/init.js +3 -1
  13. package/dist/commands/init.js.map +1 -1
  14. package/dist/commands/status.d.ts.map +1 -1
  15. package/dist/commands/status.js +40 -14
  16. package/dist/commands/status.js.map +1 -1
  17. package/dist/commands/submit.d.ts.map +1 -1
  18. package/dist/commands/submit.js +4 -1
  19. package/dist/commands/submit.js.map +1 -1
  20. package/dist/cursor-session/package.json +1 -1
  21. package/dist/cursor-session/session.cjs +19 -10
  22. package/dist/lib/activity-tail.d.ts.map +1 -1
  23. package/dist/lib/activity-tail.js +3 -0
  24. package/dist/lib/activity-tail.js.map +1 -1
  25. package/dist/lib/ai-tracking.d.ts +11 -1
  26. package/dist/lib/ai-tracking.d.ts.map +1 -1
  27. package/dist/lib/ai-tracking.js +48 -12
  28. package/dist/lib/ai-tracking.js.map +1 -1
  29. package/dist/lib/api.d.ts +2 -1
  30. package/dist/lib/api.d.ts.map +1 -1
  31. package/dist/lib/api.js +10 -5
  32. package/dist/lib/api.js.map +1 -1
  33. package/dist/lib/backfill-tools.d.ts.map +1 -1
  34. package/dist/lib/backfill-tools.js +6 -0
  35. package/dist/lib/backfill-tools.js.map +1 -1
  36. package/dist/lib/backfill.d.ts.map +1 -1
  37. package/dist/lib/backfill.js +3 -0
  38. package/dist/lib/backfill.js.map +1 -1
  39. package/dist/lib/backlog-flush.d.ts.map +1 -1
  40. package/dist/lib/backlog-flush.js +11 -1
  41. package/dist/lib/backlog-flush.js.map +1 -1
  42. package/dist/lib/capture-conversations.d.ts +2 -1
  43. package/dist/lib/capture-conversations.d.ts.map +1 -1
  44. package/dist/lib/capture-conversations.js +3 -2
  45. package/dist/lib/capture-conversations.js.map +1 -1
  46. package/dist/lib/capture-folder-policy.d.ts +2 -0
  47. package/dist/lib/capture-folder-policy.d.ts.map +1 -0
  48. package/dist/lib/capture-folder-policy.js +7 -0
  49. package/dist/lib/capture-folder-policy.js.map +1 -0
  50. package/dist/lib/capture-network.d.ts +2 -0
  51. package/dist/lib/capture-network.d.ts.map +1 -1
  52. package/dist/lib/capture-network.js +7 -0
  53. package/dist/lib/capture-network.js.map +1 -1
  54. package/dist/lib/capture-selection-server.d.ts +1 -0
  55. package/dist/lib/capture-selection-server.d.ts.map +1 -1
  56. package/dist/lib/capture-selection-server.js +4 -2
  57. package/dist/lib/capture-selection-server.js.map +1 -1
  58. package/dist/lib/capture-selftest.d.ts +18 -0
  59. package/dist/lib/capture-selftest.d.ts.map +1 -1
  60. package/dist/lib/capture-selftest.js +31 -2
  61. package/dist/lib/capture-selftest.js.map +1 -1
  62. package/dist/lib/config.d.ts +2 -0
  63. package/dist/lib/config.d.ts.map +1 -1
  64. package/dist/lib/config.js.map +1 -1
  65. package/dist/lib/connect-skills.d.ts.map +1 -1
  66. package/dist/lib/connect-skills.js +48 -38
  67. package/dist/lib/connect-skills.js.map +1 -1
  68. package/dist/lib/cursor-session.d.ts +1 -0
  69. package/dist/lib/cursor-session.d.ts.map +1 -1
  70. package/dist/lib/cursor-session.js +1 -1
  71. package/dist/lib/cursor-session.js.map +1 -1
  72. package/dist/lib/editor-server.d.ts +5 -2
  73. package/dist/lib/editor-server.d.ts.map +1 -1
  74. package/dist/lib/editor-server.js +6 -3
  75. package/dist/lib/editor-server.js.map +1 -1
  76. package/dist/lib/hook-logger.cjs +62 -0
  77. package/dist/lib/hosted-capture.d.ts.map +1 -1
  78. package/dist/lib/hosted-capture.js +59 -14
  79. package/dist/lib/hosted-capture.js.map +1 -1
  80. package/dist/lib/hosted-transcripts.d.ts.map +1 -1
  81. package/dist/lib/hosted-transcripts.js +11 -0
  82. package/dist/lib/hosted-transcripts.js.map +1 -1
  83. package/dist/lib/hosted-watcher.js +108 -15
  84. package/dist/lib/hosted-watcher.js.map +1 -1
  85. package/dist/lib/isolated-host-policy.d.ts +4 -0
  86. package/dist/lib/isolated-host-policy.d.ts.map +1 -0
  87. package/dist/lib/isolated-host-policy.js +17 -0
  88. package/dist/lib/isolated-host-policy.js.map +1 -0
  89. package/dist/lib/launcher-cleanup-journal.d.ts +34 -0
  90. package/dist/lib/launcher-cleanup-journal.d.ts.map +1 -1
  91. package/dist/lib/launcher-cleanup-journal.js +75 -1
  92. package/dist/lib/launcher-cleanup-journal.js.map +1 -1
  93. package/dist/lib/portal-launcher.d.ts +48 -3
  94. package/dist/lib/portal-launcher.d.ts.map +1 -1
  95. package/dist/lib/portal-launcher.js +473 -42
  96. package/dist/lib/portal-launcher.js.map +1 -1
  97. package/dist/lib/prepared-editor.js +1 -1
  98. package/dist/lib/prepared-editor.js.map +1 -1
  99. package/dist/lib/schemas.d.ts +1 -0
  100. package/dist/lib/schemas.d.ts.map +1 -1
  101. package/dist/lib/schemas.js +1 -0
  102. package/dist/lib/schemas.js.map +1 -1
  103. package/dist/lib/selected-capture-control.d.ts.map +1 -1
  104. package/dist/lib/selected-capture-control.js +1 -0
  105. package/dist/lib/selected-capture-control.js.map +1 -1
  106. package/dist/lib/session-over.d.ts +6 -0
  107. package/dist/lib/session-over.d.ts.map +1 -1
  108. package/dist/lib/session-over.js +12 -1
  109. package/dist/lib/session-over.js.map +1 -1
  110. package/dist/lib/skill-import.d.ts +4 -4
  111. package/dist/lib/skill-import.js +4 -4
  112. package/dist/lib/ssh-client.d.ts +12 -0
  113. package/dist/lib/ssh-client.d.ts.map +1 -1
  114. package/dist/lib/ssh-client.js +38 -1
  115. package/dist/lib/ssh-client.js.map +1 -1
  116. package/dist/lib/ssh-config-file.d.ts +1 -1
  117. package/dist/lib/ssh-config-file.d.ts.map +1 -1
  118. package/dist/lib/ssh-config-file.js +37 -3
  119. package/dist/lib/ssh-config-file.js.map +1 -1
  120. package/dist/lib/vscode-server-preparation.d.ts +14 -2
  121. package/dist/lib/vscode-server-preparation.d.ts.map +1 -1
  122. package/dist/lib/vscode-server-preparation.js +36 -15
  123. package/dist/lib/vscode-server-preparation.js.map +1 -1
  124. package/dist/lib/watcher.js +11 -0
  125. package/dist/lib/watcher.js.map +1 -1
  126. package/dist/lib/workspace-attempt.d.ts +19 -0
  127. package/dist/lib/workspace-attempt.d.ts.map +1 -0
  128. package/dist/lib/workspace-attempt.js +34 -0
  129. package/dist/lib/workspace-attempt.js.map +1 -0
  130. package/dist/lib/zip.d.ts +1 -1
  131. package/dist/lib/zip.d.ts.map +1 -1
  132. package/dist/lib/zip.js +7 -2
  133. package/dist/lib/zip.js.map +1 -1
  134. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { configureClaudeDesktopConnection, removeClaudeDesktopConnection } from
2
2
  import { waitForWorkspace } from "../lib/workspace-start-wait.js";
3
3
  import { startBackgroundLauncher } from "../lib/portal-launcher-background.js";
4
4
  import { desktopAppProbeCommand, desktopRuntimeReady } from "../lib/desktop-readiness.js";
5
- import { startPortalPreparation, runPortalLauncher, reportLauncherTiming, openDesktop, openTerminal, openNativeEditor, desktopLaunchOutcome, closeOwnedMacTerminal, removeTerminalLauncher } from "../lib/portal-launcher.js";
5
+ import { startPortalPreparation, runPortalLauncher, reportLauncherTiming, openDesktop, openTerminal, openNativeEditor, desktopLaunchOutcome, closeOwnedMacEditorWindows, closeOwnedMacTerminal, closeOwnedMacClaudeSession, closeOwnedMacCodexProcess, macClaudeProcess, macCodexProcess, removeTerminalLauncher } from "../lib/portal-launcher.js";
6
6
  import { startHostedCapture } from "../lib/hosted-capture.js";
7
7
  import { installSshForwardHook } from "../lib/install-ssh-forward-hook.js";
8
8
  import { runSsh } from "./ssh.js";
@@ -14,7 +14,7 @@ import { createPreparedDesktopReadiness } from "../lib/prepared-desktop.js";
14
14
  import { findInstalledExecutable } from "../lib/installed-tools.js";
15
15
  import { clearLauncherInventoryCache, loadLauncherInventoryCache, saveLauncherInventoryCache } from "../lib/launcher-inventory-cache.js";
16
16
  import { clearLauncherPreparationCache, hasLauncherPreparationCache, saveLauncherPreparationCache } from "../lib/launcher-preparation-cache.js";
17
- import { attemptIndependentCleanup, queueLauncherCleanup, reconcileLauncherCleanup } from "../lib/launcher-cleanup-journal.js";
17
+ import { attemptIndependentCleanup, hasOwnedClaudeWindow, markLauncherCleanupClaudeProcess, markLauncherCleanupClaudeWindow, markLauncherCleanupCodexProcess, queueLauncherCleanup, reconcileLauncherCleanup } from "../lib/launcher-cleanup-journal.js";
18
18
  import { prepareVscodeServer } from "../lib/vscode-server-preparation.js";
19
19
  import { closedState } from "../lib/session-state.js";
20
20
  import { updateSshConfig, createSshConfigCleanupPlan, executeSshConfigCleanupPlan } from "../lib/ssh-config-file.js";
@@ -35,7 +35,7 @@ import { editorInstallCandidates, editorSpawnSpec } from "../lib/editor-binary.j
35
35
  import { isWsl, whichOnPath, windowsSideEditor, wslEditorHint } from "../lib/wsl.js";
36
36
  import { parseEditorVersion, parseWorkspaceProbe, remoteProbeCommand, seedVerdict, verifyVerdict, VERIFY_SCHEDULE_MS, } from "../lib/editor-server.js";
37
37
  import { fatal, holdExitFor, success, info, warn, setErrorContext, reportEvent } from "../lib/errors.js";
38
- import { oldWindowsSshHint, parseOpenSshVersion, proxyJumpBroken, readEditorSettings, readSshVersionBanner, sshExecutableFor, sshPreflight, sshPreflightHint, } from "../lib/ssh-client.js";
38
+ import { oldWindowsSshHint, parseOpenSshVersion, proxyJumpBroken, readEditorSettings, readSshVersionBanner, sshExecutableFor, sshPreflight, sshPreflightHint, sshOtherHomeHint, } from "../lib/ssh-client.js";
39
39
  import { editorEndingForewarning } from "../lib/session-end.js";
40
40
  import { attemptRelaunch, platformSupportsGracefulCursorRestart, realCursorProcessIo, } from "../lib/cursor-restart.js";
41
41
  /**
@@ -404,6 +404,7 @@ export const NATIVE_EDITORS = {
404
404
  label: "Cursor",
405
405
  remoteSshExt: "anysphere.remote-ssh",
406
406
  conflictingRemoteSshExt: "ms-vscode-remote.remote-ssh",
407
+ noisyDevContainersExt: "ms-vscode-remote.remote-containers",
407
408
  shellCommand: "Shell Command: Install 'cursor' command",
408
409
  downloadUrl: "https://cursor.com/download",
409
410
  seedCommitPath: "/opt/cursor-server-cache/COMMIT",
@@ -448,16 +449,45 @@ function probeEditorCli(command) {
448
449
  return null;
449
450
  }
450
451
  }
451
- export function resolveEditorCommand(ed) {
452
- const onPath = probeEditorCli(ed.bin);
453
- if (onPath)
454
- return { command: ed.bin, source: "path", version: onPath };
455
- for (const candidate of editorInstallCandidates(ed.ide, process.platform, process.env, os.homedir())) {
456
- if (!existsSync(candidate))
452
+ export function resolveEditorCommand(ed, io = {
453
+ probe: probeEditorCli,
454
+ identify: identifyEditorCli,
455
+ candidates: () => editorInstallCandidates(ed.ide, process.platform, process.env, os.homedir()),
456
+ exists: existsSync,
457
+ }) {
458
+ const onPath = io.probe(ed.bin);
459
+ if (onPath) {
460
+ const identity = io.identify(ed, ed.bin);
461
+ if (identity.kind !== "mismatch")
462
+ return { command: ed.bin, source: "path", version: onPath, identity };
463
+ // A known other product may own the requested command name. Prefer a verified
464
+ // installation of the editor the candidate actually selected before refusing the
465
+ // launch. Unknown wrappers retain the PATH-first behavior above: only positive
466
+ // evidence of the other editor permits us to bypass the candidate's command.
467
+ for (const candidate of io.candidates()) {
468
+ if (!io.exists(candidate))
469
+ continue;
470
+ const version = io.probe(candidate);
471
+ const candidateIdentity = version ? io.identify(ed, candidate) : null;
472
+ if (version && candidateIdentity?.kind === "match") {
473
+ return { command: candidate, source: "install-location", version, identity: candidateIdentity };
474
+ }
475
+ }
476
+ // Preserve the mismatch so the existing refusal names what answered when no
477
+ // verified requested installation exists.
478
+ return { command: ed.bin, source: "path", version: onPath, identity };
479
+ }
480
+ for (const candidate of io.candidates()) {
481
+ if (!io.exists(candidate))
457
482
  continue;
458
- const version = probeEditorCli(candidate);
483
+ const version = io.probe(candidate);
459
484
  if (version)
460
- return { command: candidate, source: "install-location", version };
485
+ return {
486
+ command: candidate,
487
+ source: "install-location",
488
+ version,
489
+ identity: io.identify(ed, candidate),
490
+ };
461
491
  }
462
492
  return null;
463
493
  }
@@ -602,10 +632,23 @@ export function pasteableEditorCommand(ed, resolved, platform) {
602
632
  }
603
633
  /** ENG-3158 — whether `<bin> --list-extensions` output names `ed`'s conflicting extension. */
604
634
  export function conflictingRemoteSshInstalled(ed, listed) {
605
- const conflict = ed.conflictingRemoteSshExt;
606
- if (!conflict)
607
- return false;
608
- return listed.split(/\r?\n/).some((l) => l.trim().toLowerCase() === conflict);
635
+ return !!ed.conflictingRemoteSshExt && extensionListed(listed, ed.conflictingRemoteSshExt);
636
+ }
637
+ function extensionListed(listed, id) {
638
+ return listed.split(/\r?\n/).some((l) => l.trim().toLowerCase() === id);
639
+ }
640
+ /**
641
+ * ENG-4130 — the note when `ed.noisyDevContainersExt` is installed. Printed and carried
642
+ * on: the connection works, and connect changes nothing in the candidate's editor.
643
+ */
644
+ export function noisyDevContainersLines(ed, editorCmd, listed) {
645
+ const ext = ed.noisyDevContainersExt;
646
+ if (!ext || !extensionListed(listed, ext))
647
+ return [];
648
+ return [
649
+ chalk.dim(` Microsoft's Dev Containers extension is installed in ${ed.label}. Its "Setting up Dev Containers" notice can stay up all session; it is harmless and safe to close.`),
650
+ chalk.dim(` To stop it: ${editorCmd} --uninstall-extension ${ext}`),
651
+ ];
609
652
  }
610
653
  /**
611
654
  * ENG-2332 — the refusal when the candidate's editor is a different build from the one
@@ -816,7 +859,12 @@ export function editorLaunchPlan(ed, alias, platform = process.platform) {
816
859
  };
817
860
  }
818
861
  return {
819
- args: ["--remote", `ssh-remote+${alias}`, REMOTE_WORKSPACE_DIR],
862
+ // Cursor otherwise dispatches the remote-folder request to whichever surface was
863
+ // last active. When that is the global Agents Window, no assessment IDE attaches.
864
+ // `--classic` explicitly selects Cursor's editor surface without forcing duplicate
865
+ // windows. VS Code keeps its established behavior, and Windows keeps the protocol
866
+ // route measured in ENG-3217.
867
+ args: [...(ed.ide === "cursor" ? ["--classic"] : []), "--remote", `ssh-remote+${alias}`, REMOTE_WORKSPACE_DIR],
820
868
  guidance: null,
821
869
  verifySchedule: VERIFY_SCHEDULE_MS,
822
870
  };
@@ -1487,6 +1535,9 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1487
1535
  return;
1488
1536
  }
1489
1537
  const backendUrl = meta.backendUrl;
1538
+ const startWorkspaceForPolicy = (pubkey) => meta.capturePolicy
1539
+ ? startWorkspace(backendUrl, token, pubkey, meta.capturePolicy)
1540
+ : startWorkspace(backendUrl, token, pubkey);
1490
1541
  // Pick the editor up front (flag or interactive prompt) so the choice is made
1491
1542
  // before the boot wait, not after.
1492
1543
  //
@@ -1494,11 +1545,19 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1494
1545
  // carries only the assessment id, never the token.
1495
1546
  const pageUrl = candidatePageUrl(apiBase, meta.assessmentId);
1496
1547
  attempt.stage("selection");
1497
- const launcherBetaEnabled = meta.launcherBetaEnabled === true;
1548
+ const isolatedWorkspace = meta.capturePolicy === "isolated_workspace_v1";
1549
+ const requestedIde = ideOpt?.trim().toLowerCase();
1550
+ if (isolatedWorkspace && requestedIde && requestedIde !== "browser" && requestedIde !== "ssh") {
1551
+ fatal("This isolated workspace supports the hosted browser and SSH only.", "Use --ide browser or --ide ssh. Native editors and native AI recording are unavailable in this mode.", { severity: "warning" });
1552
+ return;
1553
+ }
1554
+ const launcherBetaEnabled = meta.launcherBetaEnabled === true && meta.capturePolicy !== "isolated_workspace_v1";
1498
1555
  const portalLauncher = launcherBetaEnabled && !ideOpt && !opts.tunnel;
1499
- const { ide: chosenIde, chosen: ideWasChosen } = portalLauncher
1500
- ? { ide: "ssh", chosen: true }
1501
- : await resolveIde(ideOpt, console.log);
1556
+ const { ide: chosenIde, chosen: ideWasChosen } = isolatedWorkspace
1557
+ ? { ide: (requestedIde === "ssh" ? "ssh" : "browser"), chosen: true }
1558
+ : portalLauncher
1559
+ ? { ide: "ssh", chosen: true }
1560
+ : await resolveIde(ideOpt, console.log);
1502
1561
  let ide = chosenIde;
1503
1562
  attempt.editor(ide);
1504
1563
  // ENG-2814: asked here, next to the editor choice, and uploaded once the workspace is
@@ -1507,7 +1566,7 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1507
1566
  if (portalLauncher)
1508
1567
  skillImport.stopPreparation = await startPortalPreparation(backendUrl, token);
1509
1568
  skillImport.stopPreparation?.update("waiting_input");
1510
- const pendingSkills = await offerSkillImport({
1569
+ const pendingSkills = isolatedWorkspace ? null : await offerSkillImport({
1511
1570
  backendUrl, token, flag: opts.skills, verbose, launcherBetaEnabled,
1512
1571
  });
1513
1572
  attempt.stage("ssh_key");
@@ -1532,7 +1591,7 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1532
1591
  const boot = ora("Starting your workspace...").start();
1533
1592
  let initialStart;
1534
1593
  try {
1535
- initialStart = await startWorkspace(backendUrl, token, pubkey);
1594
+ initialStart = await startWorkspaceForPolicy(pubkey);
1536
1595
  }
1537
1596
  catch (err) {
1538
1597
  attempt.evidence(workspaceStartNetworkDetail(err));
@@ -1593,7 +1652,7 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1593
1652
  try {
1594
1653
  const waited = await waitForWorkspace({
1595
1654
  initial: initialStart,
1596
- start: () => startWorkspace(backendUrl, token, pubkey),
1655
+ start: () => startWorkspaceForPolicy(pubkey),
1597
1656
  connection: () => getConnection(backendUrl, token),
1598
1657
  ready: value => Boolean(value.healthy && (ide === "browser" || value.ssh_command)),
1599
1658
  needsReattach: value => ide !== "browser" && !value.ssh_command,
@@ -1650,7 +1709,9 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1650
1709
  attempt.editor(ide);
1651
1710
  }
1652
1711
  else if (fallback === "unavailable") {
1653
- fatal("The browser IDE isn't available for this workspace yet.", "Open it in VS Code instead: run the same litmus connect command with --ide vscode.", { severity: "warning" });
1712
+ fatal("The browser IDE isn't available for this workspace yet.", isolatedWorkspace
1713
+ ? "Use the supported SSH route instead: run the same litmus connect command with --ide ssh."
1714
+ : "Open it in VS Code instead: run the same litmus connect command with --ide vscode.", { severity: "warning" });
1654
1715
  return;
1655
1716
  }
1656
1717
  }
@@ -1747,10 +1808,12 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1747
1808
  if (preflight.ok)
1748
1809
  return false;
1749
1810
  attempt.evidence(preflight.detail.join("\n"));
1750
- fatal("Your computer couldn't open an SSH connection to the workspace.", sshPreflightHint(preflight.detail, Boolean(conn.browser_ide_url), verbose), {
1751
- severity: "error",
1811
+ const otherHome = sshOtherHomeHint(alias, preflight.detail, Boolean(conn.browser_ide_url));
1812
+ fatal("Your computer couldn't open an SSH connection to the workspace.", otherHome ?? sshPreflightHint(preflight.detail, Boolean(conn.browser_ide_url), verbose), {
1813
+ // ENG-4389: a HOME the candidate can fix, not a fault of ours or the network, so no page.
1814
+ severity: otherHome ? "warning" : "error",
1752
1815
  internalDetail: [
1753
- `route=${route} platform=${process.platform} ssh=${sshExecutable}`,
1816
+ `route=${route} platform=${process.platform} ssh=${sshExecutable}${otherHome ? " ssh_config=home_mismatch" : ""}`,
1754
1817
  `client=${sshBanner(sshExecutable) ?? "unreadable"}`,
1755
1818
  ...preflight.detail,
1756
1819
  ].join("\n"),
@@ -1833,7 +1896,7 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1833
1896
  // it is the absence branch's job to say so, below the mismatch refusal, so a candidate
1834
1897
  // whose `code` is Cursor is told THAT rather than that their editor is missing.
1835
1898
  attempt.stage("editor_resolution");
1836
- const identity = resolved ? identifyEditorCli(editor, resolved.command) : { kind: "unverified" };
1899
+ const identity = resolved?.identity ?? { kind: "unverified" };
1837
1900
  attempt.fact("editorIdentity", identity.kind);
1838
1901
  // 5b. Point this machine's Copilot Chat at the Litmus gateway (ENG-1475).
1839
1902
  //
@@ -1977,6 +2040,10 @@ async function connectFlow(token, ideOpt, opts, skillImport, attempt, connectSta
1977
2040
  return;
1978
2041
  }
1979
2042
  }
2043
+ if (listed !== null) {
2044
+ for (const line of noisyDevContainersLines(editor, pasteableEditorCommand(editor, resolved, process.platform), listed))
2045
+ console.log(line);
2046
+ }
1980
2047
  // ENG-2332 — the version check BEFORE anything is opened, then the verification after
1981
2048
  // it. Both, and their order, live in `attemptEditorLaunch`: the guarantee here is a
1982
2049
  // property of the SEQUENCE, so it is held in one testable unit rather than in the
@@ -2174,14 +2241,45 @@ function launcherCleanupHandlers(token, report = (outcome, entry) => {
2174
2241
  return {
2175
2242
  cleanup: async (entry) => {
2176
2243
  const context = { backendUrl: entry.backendOrigin, token, alias: entry.alias };
2244
+ const cleanupTarget = (target, task) => async () => {
2245
+ const started = performance.now();
2246
+ reportLauncherTiming(entry.backendOrigin, token, "cleanup_target_attempted", 0, { cleanupTarget: target });
2247
+ try {
2248
+ const verified = await task();
2249
+ reportLauncherTiming(entry.backendOrigin, token, "cleanup_target_verified", performance.now() - started, {
2250
+ cleanupTarget: target, outcome: verified ? "ok" : "cancelled",
2251
+ });
2252
+ }
2253
+ catch (error) {
2254
+ reportLauncherTiming(entry.backendOrigin, token, "cleanup_target_verified", performance.now() - started, { cleanupTarget: target, outcome: "failed" });
2255
+ throw error;
2256
+ }
2257
+ };
2177
2258
  clearLauncherInventoryCache(context);
2178
2259
  clearLauncherPreparationCache(context);
2179
2260
  await attemptIndependentCleanup([
2180
- async () => { await confirmPortalEditorSessionEnded(entry.alias); },
2181
- () => closeOwnedMacTerminal(entry.alias),
2182
- () => removeClaudeDesktopConnection(entry.alias, entry.assessmentName),
2183
- () => removeTerminalLauncher(entry.alias),
2184
- ...(entry.ssh ? [() => executeSshConfigCleanupPlan(path.join(os.homedir(), ".ssh", "config"), entry.ssh)] : []),
2261
+ // Marking the editor registration ended asks the companion to close;
2262
+ // it is not itself proof that the native window has closed.
2263
+ cleanupTarget("editor_session", async () => {
2264
+ await confirmPortalEditorSessionEnded(entry.alias);
2265
+ const outcome = await closeOwnedMacEditorWindows(entry.alias);
2266
+ return ["closed", "not_found", "unsupported"].includes(outcome);
2267
+ }),
2268
+ cleanupTarget("terminal_window", async () => ["closed", "not_found"].includes(await closeOwnedMacTerminal(entry.alias))),
2269
+ // The connection record and the window are separate Claude resources.
2270
+ // Inspect Claude only after this assessment dispatched its exact alias;
2271
+ // otherwise a never-launched Claude target must not create retries.
2272
+ ...(hasOwnedClaudeWindow(entry) ? [cleanupTarget("claude_window", async () => {
2273
+ const outcome = await closeOwnedMacClaudeSession(entry.alias, entry.claudeProcess, entry.claudeWindow === true);
2274
+ return ["closed", "not_found", "unsupported"].includes(outcome);
2275
+ })] : []),
2276
+ cleanupTarget("claude_connection", async () => ["removed", "absent"].includes(await removeClaudeDesktopConnection(entry.alias, entry.assessmentName))),
2277
+ ...(entry.codexProcess ? [cleanupTarget("codex_window", async () => ["closed", "not_found", "unsupported"].includes(await closeOwnedMacCodexProcess(entry.codexProcess)))] : []),
2278
+ cleanupTarget("terminal_launcher", async () => {
2279
+ removeTerminalLauncher(entry.alias);
2280
+ return !existsSync(path.join(os.homedir(), ".litmus", "launchers", `${entry.alias}.command`));
2281
+ }),
2282
+ ...(entry.ssh ? [cleanupTarget("ssh_config", async () => ["removed", "absent"].includes(await executeSshConfigCleanupPlan(path.join(os.homedir(), ".ssh", "config"), entry.ssh)))] : []),
2185
2283
  ]);
2186
2284
  },
2187
2285
  report,
@@ -2305,129 +2403,167 @@ export function runPreparedPortalLauncher(context, onReady, signal) {
2305
2403
  }
2306
2404
  },
2307
2405
  openUrl: url => url === context.pageUrl ? Promise.resolve(true) : openBrowser(url),
2308
- prepareTools: async (installed, signal, onPrepared, generationValue) => Promise.all(installed.map(async (app) => {
2309
- const started = performance.now();
2310
- const key = `${app.tool}:${app.command}`;
2311
- const generation = parseWorkspaceGeneration(generationValue);
2312
- let preparationInput = null;
2313
- if (generation && !app.unavailable && app.tool === "vscode") {
2314
- const resolved = resolveEditorCommand(NATIVE_EDITORS.vscode);
2315
- const commit = resolved?.version.commit;
2316
- if (resolved && commit && identifyEditorCli(NATIVE_EDITORS.vscode, resolved.command).kind === "match") {
2406
+ prepareTools: async (installed, signal, onPrepared, generationValue, preference) => {
2407
+ const needsSetup = (app) => !app.unavailable && (app.tool === "vscode" || app.tool === "cursor" || app.tool === "codex" || app.tool === "claude");
2408
+ const remaining = installed.filter(needsSetup);
2409
+ const prepared = [];
2410
+ const takeNext = () => {
2411
+ const preferredIndex = preference?.tool ? remaining.findIndex(app => app.tool === preference.tool) : -1;
2412
+ return remaining.splice(preferredIndex >= 0 ? preferredIndex : 0, 1)[0];
2413
+ };
2414
+ const prepareOne = async (app) => {
2415
+ const started = performance.now();
2416
+ const key = `${app.tool}:${app.command}`;
2417
+ const generation = parseWorkspaceGeneration(generationValue);
2418
+ let preparationInput = null;
2419
+ if (generation && !app.unavailable && app.tool === "vscode") {
2420
+ const resolved = resolveEditorCommand(NATIVE_EDITORS.vscode);
2421
+ const commit = resolved?.version.commit;
2422
+ if (resolved && commit && resolved.identity.kind === "match") {
2423
+ preparationInput = {
2424
+ generation, tool: app.tool, command: app.command,
2425
+ preparationFingerprint: createHash("sha256").update(`vscode-server:${commit}`).digest("hex"),
2426
+ };
2427
+ }
2428
+ }
2429
+ else if (generation && !app.unavailable && (app.tool === "codex" || app.tool === "claude")) {
2317
2430
  preparationInput = {
2318
2431
  generation, tool: app.tool, command: app.command,
2319
- preparationFingerprint: createHash("sha256").update(`vscode-server:${commit}`).digest("hex"),
2432
+ preparationFingerprint: createHash("sha256").update(desktopAppProbeCommand(app.tool)).digest("hex"),
2320
2433
  };
2321
2434
  }
2322
- }
2323
- else if (generation && !app.unavailable && (app.tool === "codex" || app.tool === "claude")) {
2324
- preparationInput = {
2325
- generation, tool: app.tool, command: app.command,
2326
- preparationFingerprint: createHash("sha256").update(desktopAppProbeCommand(app.tool)).digest("hex"),
2327
- };
2328
- }
2329
- const cacheHit = preparationInput ? hasLauncherPreparationCache(context, preparationInput) : false;
2330
- if (preparationInput)
2331
- timing(cacheHit ? "tool_preparation_cache_hit" : "tool_preparation_cache_miss", performance.now() - started, { tool: app.tool });
2332
- const temperature = cacheHit || seenPreparation.has(key) ? "warm" : "cold";
2333
- timing("tool_preparation_started", 0, { tool: app.tool, temperature });
2334
- let outcome = "ok";
2335
- let prepared = app;
2336
- let threw = false;
2337
- try {
2338
- if (!app.unavailable && (app.tool === "vscode" || app.tool === "cursor")) {
2339
- // Registration is per assessment, so it must run even when the remote
2340
- // server preparation itself came from the warm cache.
2341
- const registered = await preparePortalEditorSession(app, context, attemptedEditorSessions);
2342
- if (!registered && !attemptedEditorSessions.has(key) && !retryingEditorSessions.has(key)) {
2343
- retryingEditorSessions.add(key);
2344
- void retryPortalEditorSession(app, context, attemptedEditorSessions, signal)
2345
- .finally(() => retryingEditorSessions.delete(key));
2435
+ const cacheHit = preparationInput ? hasLauncherPreparationCache(context, preparationInput) : false;
2436
+ if (preparationInput)
2437
+ timing(cacheHit ? "tool_preparation_cache_hit" : "tool_preparation_cache_miss", performance.now() - started, { tool: app.tool });
2438
+ const temperature = cacheHit || seenPreparation.has(key) ? "warm" : "cold";
2439
+ timing("tool_preparation_started", 0, { tool: app.tool, temperature });
2440
+ let outcome = "ok";
2441
+ let serverSource;
2442
+ let prepared = app;
2443
+ let threw = false;
2444
+ try {
2445
+ if (!app.unavailable && (app.tool === "vscode" || app.tool === "cursor")) {
2446
+ // Registration is per assessment, so it must run even when the remote
2447
+ // server preparation itself came from the warm cache.
2448
+ const registered = await preparePortalEditorSession(app, context, attemptedEditorSessions);
2449
+ if (!registered && !attemptedEditorSessions.has(key) && !retryingEditorSessions.has(key)) {
2450
+ retryingEditorSessions.add(key);
2451
+ void retryPortalEditorSession(app, context, attemptedEditorSessions, signal)
2452
+ .finally(() => retryingEditorSessions.delete(key));
2453
+ }
2346
2454
  }
2347
- }
2348
- if (cacheHit) {
2349
- if (app.tool === "claude") {
2350
- try {
2351
- configureClaudeDesktopConnection(context.alias, context.assessmentName ?? "Assessment");
2455
+ if (cacheHit) {
2456
+ // A hit (or a repeat below) means this generation's exact server was already prepared.
2457
+ if (app.tool === "vscode")
2458
+ serverSource = "present";
2459
+ if (app.tool === "claude") {
2460
+ try {
2461
+ configureClaudeDesktopConnection(context.alias, context.assessmentName ?? "Assessment");
2462
+ }
2463
+ catch {
2464
+ outcome = "failed";
2465
+ prepared = { ...app, unavailable: "desktop_setup_failed" };
2466
+ return prepared;
2467
+ }
2352
2468
  }
2353
- catch {
2354
- outcome = "failed";
2355
- prepared = { ...app, unavailable: "desktop_setup_failed" };
2469
+ return prepared;
2470
+ }
2471
+ if (app.tool === "vscode" && !app.unavailable) {
2472
+ if (attemptedVscode.has(app.command)) {
2473
+ serverSource = "present";
2356
2474
  return prepared;
2357
2475
  }
2476
+ const resolved = resolveEditorCommand(NATIVE_EDITORS.vscode);
2477
+ const commit = resolved?.version.commit;
2478
+ if (resolved && commit && resolved.identity.kind === "match") {
2479
+ const ready = await prepareVscodeServer(context.alias, commit, signal);
2480
+ if (!ready) {
2481
+ outcome = "failed";
2482
+ return prepared;
2483
+ }
2484
+ serverSource = ready;
2485
+ attemptedVscode.add(app.command);
2486
+ }
2487
+ return prepared;
2358
2488
  }
2359
- return prepared;
2360
- }
2361
- if (app.tool === "vscode" && !app.unavailable) {
2362
- if (attemptedVscode.has(app.command))
2489
+ if (app.unavailable) {
2490
+ outcome = "failed";
2363
2491
  return prepared;
2364
- const resolved = resolveEditorCommand(NATIVE_EDITORS.vscode);
2365
- const commit = resolved?.version.commit;
2366
- if (resolved && commit && identifyEditorCli(NATIVE_EDITORS.vscode, resolved.command).kind === "match") {
2367
- const ready = await prepareVscodeServer(context.alias, commit, signal);
2368
- if (!ready) {
2369
- outcome = "failed";
2370
- return prepared;
2492
+ }
2493
+ if (app.tool !== "codex" && app.tool !== "claude")
2494
+ return prepared;
2495
+ if (checkedDesktopApps.has(key))
2496
+ return prepared;
2497
+ if (await desktopRuntimeReady(context.alias, app.tool, signal)) {
2498
+ if (app.tool === "claude") {
2499
+ try {
2500
+ configureClaudeDesktopConnection(context.alias, context.assessmentName ?? "Assessment");
2501
+ }
2502
+ catch {
2503
+ outcome = "failed";
2504
+ prepared = { ...app, unavailable: "desktop_setup_failed" };
2505
+ return prepared;
2506
+ }
2371
2507
  }
2372
- attemptedVscode.add(app.command);
2508
+ checkedDesktopApps.add(key);
2509
+ return prepared;
2373
2510
  }
2511
+ outcome = "failed";
2512
+ prepared = { ...app, unavailable: "workspace_not_ready" };
2374
2513
  return prepared;
2375
2514
  }
2376
- if (app.unavailable) {
2515
+ catch (error) {
2377
2516
  outcome = "failed";
2378
- return prepared;
2517
+ threw = true;
2518
+ throw error;
2379
2519
  }
2380
- if (app.tool !== "codex" && app.tool !== "claude")
2381
- return prepared;
2382
- if (checkedDesktopApps.has(key))
2383
- return prepared;
2384
- if (await desktopRuntimeReady(context.alias, app.tool, signal)) {
2385
- if (app.tool === "claude") {
2386
- try {
2387
- configureClaudeDesktopConnection(context.alias, context.assessmentName ?? "Assessment");
2388
- }
2389
- catch {
2390
- outcome = "failed";
2391
- prepared = { ...app, unavailable: "desktop_setup_failed" };
2392
- return prepared;
2393
- }
2394
- }
2395
- checkedDesktopApps.add(key);
2396
- return prepared;
2520
+ finally {
2521
+ seenPreparation.add(key);
2522
+ if (!threw && !cacheHit && outcome === "ok" && !prepared.unavailable && preparationInput)
2523
+ saveLauncherPreparationCache(context, preparationInput);
2524
+ timing("tool_preparation_completed", performance.now() - started, { tool: app.tool, temperature, outcome, serverSource });
2525
+ if (!threw)
2526
+ await onPrepared(prepared);
2397
2527
  }
2398
- outcome = "failed";
2399
- prepared = { ...app, unavailable: "workspace_not_ready" };
2400
- return prepared;
2401
- }
2402
- catch (error) {
2403
- outcome = "failed";
2404
- threw = true;
2405
- throw error;
2528
+ };
2529
+ for (const app of installed.filter(app => !needsSetup(app))) {
2530
+ prepared.push(app);
2531
+ await onPrepared(app);
2406
2532
  }
2407
- finally {
2408
- seenPreparation.add(key);
2409
- if (!threw && !cacheHit && outcome === "ok" && !prepared.unavailable && preparationInput)
2410
- saveLauncherPreparationCache(context, preparationInput);
2411
- timing("tool_preparation_complete", performance.now() - started, { tool: app.tool, temperature, outcome });
2412
- if (!threw)
2413
- await onPrepared(prepared);
2414
- }
2415
- })),
2533
+ const workers = Array.from({ length: Math.min(2, remaining.length) }, async () => {
2534
+ let preparedOne = false;
2535
+ while (remaining.length && !signal.aborted) {
2536
+ if (preparedOne)
2537
+ await preference?.refresh?.();
2538
+ const app = takeNext();
2539
+ if (!app)
2540
+ break;
2541
+ prepared.push(await prepareOne(app));
2542
+ preparedOne = true;
2543
+ }
2544
+ });
2545
+ await Promise.all(workers);
2546
+ return installed.map(app => prepared.find(candidate => candidate.tool === app.tool) ?? app);
2547
+ },
2416
2548
  launch: async (tool, installed, signal, launchContext) => {
2417
2549
  if (tool === "vscode" || tool === "cursor") {
2418
2550
  const started = performance.now();
2419
2551
  let verified = false;
2420
2552
  let readinessPath;
2421
- const result = await native.launch(tool, launchContext?.generation, remember => openNativeEditor(tool, context.token, signal, undefined, value => { verified = true; readinessPath ?? (readinessPath = "poll"); remember(value); }, launchContext?.generation, launchContext?.remoteReady, () => { verified = true; readinessPath = "event"; }), signal);
2553
+ const result = await native.launch(tool, launchContext?.generation, remember => openNativeEditor(tool, context.token, signal, undefined, value => { verified = true; readinessPath ?? (readinessPath = "poll"); remember(value); }, launchContext?.generation, launchContext?.remoteReady, () => { verified = true; readinessPath = "event"; }, outcome => launchContext?.onLocalOpened?.(outcome)), signal);
2422
2554
  if (result === "failed")
2423
2555
  clearLauncherPreparationCache(context);
2424
- if (verified)
2556
+ if (verified) {
2425
2557
  timing("remote_ready", performance.now() - started, { tool, requestId: launchContext?.requestId, outcome: "ok", readinessPath });
2558
+ timing("remote_connection_ready", performance.now() - started, { tool, requestId: launchContext?.requestId, outcome: "ok", readinessPath });
2559
+ }
2426
2560
  return result;
2427
2561
  }
2428
2562
  if (tool === "browser") {
2429
2563
  const current = await getConnection(context.backendUrl, context.token);
2430
- return current.browser_ide_url && await openBrowser(current.browser_ide_url) ? "dispatched" : "failed";
2564
+ const opened = Boolean(current.browser_ide_url && await openBrowser(current.browser_ide_url));
2565
+ launchContext?.onLocalOpened?.(opened ? "ok" : "failed");
2566
+ return opened ? "dispatched" : "failed";
2431
2567
  }
2432
2568
  if (tool === "codex" || tool === "claude") {
2433
2569
  const app = installed.find(i => i.tool === tool);
@@ -2446,7 +2582,54 @@ export function runPreparedPortalLauncher(context, onReady, signal) {
2446
2582
  }
2447
2583
  // OS handoff is all the opener proves. Do not invent a confirmation
2448
2584
  // prompt or claim an active assessment connection from its exit code.
2585
+ let claudeWasStopped = false;
2586
+ let codexWasStopped = false;
2587
+ if (tool === "claude" && process.platform === "darwin") {
2588
+ try {
2589
+ claudeWasStopped = !await macClaudeProcess();
2590
+ }
2591
+ catch { /* Unknown ownership must not block an otherwise successful launch. */ }
2592
+ }
2593
+ if (tool === "codex" && process.platform === "darwin") {
2594
+ try {
2595
+ codexWasStopped = !await macCodexProcess(app.command);
2596
+ }
2597
+ catch { /* Unknown ownership must not block an otherwise successful launch. */ }
2598
+ }
2449
2599
  const opened = await openDesktop(app, context.alias, signal);
2600
+ if (tool === "claude" && opened) {
2601
+ try {
2602
+ await markLauncherCleanupClaudeWindow(context);
2603
+ }
2604
+ catch { /* Bookkeeping is best-effort; preserve the successful OS handoff. */ }
2605
+ }
2606
+ if (tool === "claude" && opened && claudeWasStopped) {
2607
+ try {
2608
+ for (let attempt = 0; attempt < 20; attempt++) {
2609
+ const launched = await macClaudeProcess();
2610
+ if (launched) {
2611
+ await markLauncherCleanupClaudeProcess(context, launched);
2612
+ break;
2613
+ }
2614
+ await new Promise(resolve => setTimeout(resolve, 100));
2615
+ }
2616
+ }
2617
+ catch { /* Bookkeeping is best-effort; preserve the successful OS handoff. */ }
2618
+ }
2619
+ if (tool === "codex" && opened && codexWasStopped) {
2620
+ try {
2621
+ for (let attempt = 0; attempt < 20; attempt++) {
2622
+ const launched = await macCodexProcess(app.command);
2623
+ if (launched) {
2624
+ await markLauncherCleanupCodexProcess(context, launched);
2625
+ break;
2626
+ }
2627
+ await new Promise(resolve => setTimeout(resolve, 100));
2628
+ }
2629
+ }
2630
+ catch { /* Bookkeeping is best-effort; preserve the successful OS handoff. */ }
2631
+ }
2632
+ launchContext?.onLocalOpened?.(opened ? "ok" : "failed");
2450
2633
  if (!opened)
2451
2634
  desktopReadiness.invalidate();
2452
2635
  // Claude's deep link carries the exact current alias and assessment
@@ -2456,7 +2639,9 @@ export function runPreparedPortalLauncher(context, onReady, signal) {
2456
2639
  return desktopLaunchOutcome(tool, opened);
2457
2640
  }
2458
2641
  const terminal = installed.find(i => i.tool === "ssh");
2459
- return terminal && await openTerminal(context.alias, terminal.command, launchContext?.requestId) ? "dispatched" : "failed";
2642
+ const opened = Boolean(terminal && await openTerminal(context.alias, terminal.command, launchContext?.requestId));
2643
+ launchContext?.onLocalOpened?.(opened ? "ok" : "failed");
2644
+ return opened ? "dispatched" : "failed";
2460
2645
  },
2461
2646
  });
2462
2647
  }