toolroll 0.9.109 → 0.9.110

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 (135) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/agent-detect.js +244 -0
  3. package/dist/agent-fence.js +12 -1
  4. package/dist/agentconfig.js +2 -2
  5. package/dist/approval-summary.js +344 -0
  6. package/dist/attest.js +2 -2
  7. package/dist/browser/workspace.css +2 -2
  8. package/dist/browser/workspace.js +27 -27
  9. package/dist/builder.js +36 -2
  10. package/dist/chat-actions.js +24 -17
  11. package/dist/chat-core.js +3 -1
  12. package/dist/chat-decide.js +101 -46
  13. package/dist/chat-delivery-state.js +2 -0
  14. package/dist/chat-delivery.js +3 -2
  15. package/dist/chat-live.js +2 -1
  16. package/dist/chat-task-actions.js +6 -0
  17. package/dist/check-report.js +1 -1
  18. package/dist/cli.js +2 -0
  19. package/dist/console-instance.js +10 -1
  20. package/dist/contracts/console-api.js +10 -5
  21. package/dist/contracts/engine-api.js +271 -0
  22. package/dist/coordinator.js +2 -2
  23. package/dist/discord-api.js +4 -3
  24. package/dist/discord-chat.js +3 -1
  25. package/dist/easy-start-args.js +7 -3
  26. package/dist/easy-start.js +25 -0
  27. package/dist/egress.js +72 -10
  28. package/dist/engine-handoff.js +34 -0
  29. package/dist/engine-reads.js +261 -0
  30. package/dist/eval-world.js +3 -2
  31. package/dist/evidence.js +2 -0
  32. package/dist/fast-start.js +55 -14
  33. package/dist/fast-terms.js +2 -2
  34. package/dist/first-run.js +10 -2
  35. package/dist/flexible-agents.js +234 -0
  36. package/dist/flexible-answers-schema.js +61 -0
  37. package/dist/flexible-answers.js +889 -0
  38. package/dist/flexible-custody.js +494 -0
  39. package/dist/flexible-import.js +782 -0
  40. package/dist/flexible-launch-schema.js +72 -0
  41. package/dist/flexible-launch.js +331 -0
  42. package/dist/flexible-launcher.js +88 -0
  43. package/dist/flexible-levels.js +34 -0
  44. package/dist/flexible-merge-guard.js +47 -0
  45. package/dist/flexible-refs.js +47 -0
  46. package/dist/flexible-relay-cancel.js +19 -0
  47. package/dist/flexible-relay-schema.js +55 -0
  48. package/dist/flexible-relay-upstreams.js +36 -0
  49. package/dist/flexible-relay.js +1032 -0
  50. package/dist/flexible-session.js +732 -0
  51. package/dist/flexible-ship-schema.js +81 -0
  52. package/dist/flexible-ship.js +694 -0
  53. package/dist/flexible-start.js +80 -0
  54. package/dist/flexible-thread.js +175 -25
  55. package/dist/flexible-turns-schema.js +69 -0
  56. package/dist/flexible-turns.js +490 -0
  57. package/dist/flexible.js +10 -1
  58. package/dist/flow-actions.js +6 -4
  59. package/dist/flow-steps.js +1 -1
  60. package/dist/flows-cli.js +2 -1
  61. package/dist/git-views.js +6 -3
  62. package/dist/install-mode.js +225 -0
  63. package/dist/lead-doors.js +7 -1
  64. package/dist/limits-ui.js +7 -0
  65. package/dist/live-reply.js +6 -0
  66. package/dist/live-terminal.js +425 -29
  67. package/dist/local-owner.js +6 -0
  68. package/dist/model-choices.js +12 -6
  69. package/dist/notification-delivery.js +11 -0
  70. package/dist/operate.js +74 -30
  71. package/dist/outbound-privacy.js +204 -0
  72. package/dist/passwordless.js +2 -1
  73. package/dist/project-delete.js +14 -0
  74. package/dist/provider-connection.js +5 -3
  75. package/dist/publish.js +5 -0
  76. package/dist/pull-request-flow.js +26 -7
  77. package/dist/push.js +5 -1
  78. package/dist/release-card.js +11 -3
  79. package/dist/release.js +10 -1
  80. package/dist/route-store.js +2 -2
  81. package/dist/sandbox-launch.js +32 -8
  82. package/dist/sandbox-runtime.js +16 -7
  83. package/dist/sandbox-tools.js +176 -0
  84. package/dist/scope.js +12 -36
  85. package/dist/scout-net.js +7 -2
  86. package/dist/serve.js +58 -11
  87. package/dist/server/chrome.js +3 -1
  88. package/dist/server/console.css +33 -6
  89. package/dist/server/engine-api.js +378 -0
  90. package/dist/server/flows.js +2 -2
  91. package/dist/server/http.js +7 -0
  92. package/dist/server/link-redemption.js +52 -0
  93. package/dist/server/mutation-key.js +21 -7
  94. package/dist/server/pages.js +69 -40
  95. package/dist/server/people-tokens.js +17 -41
  96. package/dist/server/render-chat.js +1 -0
  97. package/dist/server/render-new-task.js +3 -3
  98. package/dist/server/render-results.js +4 -4
  99. package/dist/server/render-tasks.js +129 -138
  100. package/dist/server/route-table.js +30 -1
  101. package/dist/server/settings-section-table.js +3 -0
  102. package/dist/server/settings-sections.js +33 -0
  103. package/dist/server/settings.js +84 -10
  104. package/dist/server/task-views.js +8 -2
  105. package/dist/server/tasks.js +25 -8
  106. package/dist/server/terminals.js +181 -28
  107. package/dist/server/welcome.js +35 -10
  108. package/dist/settings-groups-ui.js +2 -2
  109. package/dist/settings-proofs.js +13 -9
  110. package/dist/slack-api.js +4 -3
  111. package/dist/slack-chat.js +5 -3
  112. package/dist/spend.js +46 -12
  113. package/dist/status-probe.js +343 -0
  114. package/dist/store.js +102 -5
  115. package/dist/teams-api.js +4 -3
  116. package/dist/teams-chat.js +4 -2
  117. package/dist/telegram-lead.js +2 -1
  118. package/dist/telegram-live.js +2 -1
  119. package/dist/telegram-team.js +2 -1
  120. package/dist/telegram.js +17 -5
  121. package/dist/trusted-path.js +162 -0
  122. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  123. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  124. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  125. package/dist/tui/linux-x64/toolroll-tui +0 -0
  126. package/dist/tui-launch.js +282 -0
  127. package/dist/tui-source.js +5 -3
  128. package/dist/tui.js +1 -1
  129. package/dist/webhooks.js +8 -4
  130. package/dist/welcome-facts.js +22 -15
  131. package/dist/workspace-ui.js +5 -0
  132. package/package.json +1 -1
  133. package/scripts/crash-canary.mjs +1 -1
  134. package/scripts/pilot.mjs +1 -1
  135. package/scripts/provider-canary.mjs +5 -3
package/dist/scope.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export { ACCEPTANCE_LIMITS, EVIDENCE_KINDS } from "./contracts/acceptance-terms.js";
2
+ import { flexibleCandidateChangeRefusal } from "./flexible-merge-guard.js";
2
3
  import { cardShowsScope, cardTermsDigest } from "./chat-terms.js";
3
4
  import { mintSecret } from "./secret-mint.js";
5
+ import { sessionStandsIn } from "./install-mode.js";
4
6
  import { passwordlessOn } from "./passwordless.js";
5
7
  import { routeChangeProblem } from "./route-change-check.js";
6
8
  import { issueImported } from "./task-source.js";
@@ -18,10 +20,10 @@ import { levelOfProfile } from "./policy.js";
18
20
  import { canonicalJson } from "./canonical-json.js";
19
21
  export { isAcpProfile };
20
22
  import { createHash, randomBytes, scryptSync, timingSafeEqual } from "node:crypto";
21
- import { networkFromValue, networkWords } from "./egress.js";
22
- import { isWritesMode, writesWords } from "./writes-mode.js";
23
- import { checkAccessWords, isCheckAccess } from "./check-access.js";
24
- import { MAX_MACH_LOOKUP, MAX_READ_DENY, sandboxTermsWords, validMachLookup, validReadDeny } from "./project-sandbox.js";
23
+ import { networkFromValue } from "./egress.js";
24
+ import { isWritesMode } from "./writes-mode.js";
25
+ import { isCheckAccess } from "./check-access.js";
26
+ import { MAX_MACH_LOOKUP, MAX_READ_DENY, validMachLookup, validReadDeny } from "./project-sandbox.js";
25
27
  import { z } from "zod";
26
28
  import {} from "./contracts/acceptance-terms.js";
27
29
  import { parseContract } from "./contracts/contract.js";
@@ -460,6 +462,9 @@ function proposeLocked(store, input) {
460
462
  const { taskId, goal, outOfScope = null, touches = [], budgetMicrousd = null, acceptance = [], qualityMode = "default", now, mutation = {}, profile, permissionMode, posture, proposedVia = null } = input;
461
463
  const draft = { goal, outOfScope, touches: [...touches], budgetMicrousd, acceptance: [...acceptance], qualityMode, candidate: input.candidate ?? null };
462
464
  const previous = store.getScope(taskId);
465
+ const fixed = flexibleCandidateChangeRefusal(store, taskId, previous?.candidate, draft.candidate);
466
+ if (fixed !== null)
467
+ throw new Error(fixed);
463
468
  const scope = {
464
469
  taskId,
465
470
  ...draft,
@@ -624,7 +629,7 @@ export function proveAccountNow(store, by, token, options = {}) {
624
629
  if (facts != null && facts.actor === by && !facts.live())
625
630
  return { ok: false, reason: "not-an-approver" };
626
631
  if (token === "") {
627
- if (options.credential !== true && facts != null && facts.actor === by && facts.live() && passwordlessOn(store))
632
+ if (options.credential !== true && facts != null && facts.actor === by && facts.live() && sessionStandsIn(store))
628
633
  return { ok: true, method: "session", at: now };
629
634
  if (ssoNowAvailable(by, now)) {
630
635
  const at = facts.ssoNow();
@@ -651,7 +656,7 @@ export function proveAccountNow(store, by, token, options = {}) {
651
656
  }
652
657
  export function passwordlessSessionFor(store, by) {
653
658
  const facts = freshFacts.getStore();
654
- return facts != null && facts.actor === by && facts.live() && passwordlessOn(store);
659
+ return facts != null && facts.actor === by && facts.live() && sessionStandsIn(store);
655
660
  }
656
661
  export const credentialProof = (method) => method === "password-now" || method === "sso-now";
657
662
  export function proveCredential(store, by, token, repo) {
@@ -934,30 +939,6 @@ export function scopeRouteWords(scope, readiness = NO_READINESS) {
934
939
  const route = routeFromJson(scope.proposedRouteJson ?? null);
935
940
  return route === null ? [] : routeWords(projectRoute(route, readiness));
936
941
  }
937
- export function describeScope(scope, readiness = NO_READINESS, evidence = null) {
938
- const approval = approvalOf(scope);
939
- return [
940
- ` goal ${scope.goal}`,
941
- ...(scope.outOfScope === null ? [] : [` not this ${scope.outOfScope}`]),
942
- ...(scope.candidate ? [` commit ${scope.candidate.slice(0, 7)} — checked out by Toolroll, no agent runs`] : []),
943
- ...(scope.touches.length === 0 ? [] : [` files ${scope.touches.join(", ")}`]),
944
- ...acceptanceWords(scope.acceptance),
945
- ...(scope.budgetMicrousd === null
946
- ? []
947
- : [` budget $${(scope.budgetMicrousd / 1_000_000).toFixed(2)} per build attempt — the agent is stopped at this figure`]),
948
- ...scopeRouteWords(scope, readiness),
949
- ...(evidence === null ? [] : [` why model ${evidence.replace(/^Why this model: /, "")}`]),
950
- ...chainTermsLines(scope).map((line, at) => at === 0 ? ` fallback ${line}` : ` ${line}`),
951
- ...(scope.profile === null || scope.profile === undefined ? [] : [` network ${networkWords(scope.profile.network ?? null).replace(/^Network: /, "")}`]),
952
- ...(scope.profile === null || scope.profile === undefined ? [] : [` writes ${writesWords(scope.profile.writes)}`]),
953
- ...(scope.profile?.checkAccess === undefined ? [] : [` checks ${checkAccessWords(scope.profile.checkAccess)}`]),
954
- ...(scope.profile === null || scope.profile === undefined ? [] : ((terms) => [` reads ${terms.reads}`, ...(terms.mach === null ? [] : [` services ${terms.mach}`])])(sandboxTermsWords(scope.profile))),
955
- ...releaseTermsWords(scope.releaseTerms ?? null),
956
- ...(scope.releaseCheck == null ? [] : [` release ${releaseCheckSentence(scope.releaseCheck)}`]),
957
- ` version ${scope.digest.slice(0, 8)} (the full plan version is in --json)`,
958
- ` approved ${describeApproval(approval)}`,
959
- ];
960
- }
961
942
  export function releaseTermsSentence(terms) {
962
943
  if (!terms.policy.carry)
963
944
  return `Release ${terms.packageVersion} from pull request #${terms.pr} at ${terms.approvedSha.slice(0, 7)}. Every later commit asks for your approval again.`;
@@ -978,12 +959,7 @@ export function releaseAsksAgainWords(terms) {
978
959
  `and always once the deploy starts. Repository ${terms.repo}, branch ${terms.branch} into ${terms.base}, check grant ${terms.grant.id}, ${terms.access === "sandboxed" ? "checks in the sandbox" : `checks outside the sandbox (${terms.access}), carried because the project allows it`}, until ${terms.expiresAt}.`,
979
960
  ];
980
961
  }
981
- function releaseTermsWords(terms) {
982
- if (terms === null)
983
- return [];
984
- return [` release ${releaseTermsSentence(terms)}`, ...(terms.policy.carry ? releaseAsksAgainWords(terms).map(line => ` ${line}`) : [])];
985
- }
986
- function describeApproval(approval) {
962
+ export function describeApproval(approval) {
987
963
  if (approval.approved)
988
964
  return `yes, by ${approval.by} at ${approval.at}`;
989
965
  if (approval.reason === "changed") {
package/dist/scout-net.js CHANGED
@@ -71,19 +71,24 @@ function demoTarget(demoUrl) {
71
71
  }
72
72
  }
73
73
  const CONNECT_TIMEOUT_MS = 10_000;
74
- export async function connectFirst(addresses, port, timeoutMs = CONNECT_TIMEOUT_MS) {
74
+ export async function connectFirst(addresses, port, timeoutMs = CONNECT_TIMEOUT_MS, signal) {
75
75
  for (const address of addresses) {
76
+ if (signal?.aborted === true)
77
+ return null;
76
78
  const socket = await new Promise(done => {
77
79
  const attempt = connect({ host: address, port });
78
80
  const give = (value) => {
79
81
  attempt.removeAllListeners("connect").removeAllListeners("error").removeAllListeners("timeout");
80
82
  attempt.setTimeout(0);
83
+ signal?.removeEventListener("abort", aborted);
81
84
  if (value === null)
82
85
  attempt.destroy();
83
86
  done(value);
84
87
  };
88
+ const aborted = () => give(null);
89
+ signal?.addEventListener("abort", aborted, { once: true });
85
90
  attempt.setTimeout(timeoutMs);
86
- attempt.once("connect", () => give(attempt));
91
+ attempt.once("connect", () => give(signal?.aborted === true ? null : attempt));
87
92
  attempt.once("error", () => give(null));
88
93
  attempt.once("timeout", () => give(null));
89
94
  });
package/dist/serve.js CHANGED
@@ -22,6 +22,9 @@ import { accessKey, countsKey, indexKey, projectSummaryOf, RevisionCache, summar
22
22
  import { usageChipOf } from './limits-ui.js';
23
23
  const BACKGROUND_CHECKS_MS = 30_000;
24
24
  const LOCAL_AGENTS_EVERY_MS = 2 * 60_000;
25
+ const LOCAL_AGENTS = ["claude", "codex"];
26
+ const SIGNED_IN_STATES = new Set(["connected", "key-works", "key-present"]);
27
+ const SIGNED_IN_HOLD_MS = 10 * 60_000;
25
28
  import { browserCrewFromIndex, browserCrewOf, browserNavigationOf, browserProjectsOf, needsYouLabelOf } from './browser-workspace.js';
26
29
  import { PAGE_WORK_HEADER, PAGE_WORK_VERSION } from './page-work-contract.js';
27
30
  import { sharedActionPayload } from './chat-actions.js';
@@ -58,6 +61,7 @@ import { createPersonalQueueRuntime } from './lead-queue-runtime.js';
58
61
  import {} from "./tools-ui.js";
59
62
  import { WORK_INDEX_MAX_LIMIT, workCountsByProject, workIndexPage } from "./work-index.js";
60
63
  import { withWorkReads } from "./work-reads.js";
64
+ import { createEngineHandlers } from "./server/engine-api.js";
61
65
  import { WORKSPACE_MOTION_SCRIPT } from "./workspace-motion.js";
62
66
  import { prepareWorkspaceRevision, WorkspaceValidatorCache } from "./workspace-revision.js";
63
67
  import { createHash, randomBytes } from "node:crypto";
@@ -91,6 +95,9 @@ import { projectHoldings, projectRunning } from "./project-delete.js";
91
95
  import { canonicalProject, projectName, resolveCeiling, rowVisible } from "./project.js";
92
96
  import { noteSignInProbe, signInNotices } from "./provider-auth.js";
93
97
  import { createConnectionChecker } from "./provider-connection.js";
98
+ import { detectAgents } from "./agent-detect.js";
99
+ import { acpCheckedHere, firstTaskRouted } from "./welcome-facts.js";
100
+ import { BACKGROUND_STATUS_TIMEOUT_MS, givenRepos, statusProbe } from "./status-probe.js";
94
101
  import { ALL_CREDENTIAL_ENV } from "./provider.js";
95
102
  import { hstsFor, LOOPBACK_PEERS, plainHttpRefusal, requestFromThisComputer, transportOf } from "./public-access.js";
96
103
  import { attachReadExecutor, defaultReadWorkers, ReadExecutor } from "./read-executor.js";
@@ -104,7 +111,7 @@ import { instrumentRequest } from "./server-telemetry.js";
104
111
  import { createChatHandlers } from './server/chat.js';
105
112
  import { createLiveHandlers } from './server/live.js';
106
113
  import { createTerminalHandlers, terminalHostFor } from './server/terminals.js';
107
- import { passwordlessOn } from './passwordless.js';
114
+ import { declareSoloOnUpgrade, sessionStandsIn } from './install-mode.js';
108
115
  import { keepTypedFields, openProjectFor, settingsCrumbs } from './settings-kit.js';
109
116
  import { createSweepHandlers } from './server/sweeps.js';
110
117
  import { createFlowsHandlers } from './server/flows.js';
@@ -175,6 +182,7 @@ export function createDecisionServer(options) {
175
182
  get browserKeys() { return browserKeys; },
176
183
  });
177
184
  const { store, evidenceRoot } = options;
185
+ declareSoloOnUpgrade(store, new Date());
178
186
  let coding = options.codingWorkspace ?? null;
179
187
  let codingProblem;
180
188
  if (coding === null && options.localRunner !== undefined && !store.isDemo()) {
@@ -224,7 +232,8 @@ export function createDecisionServer(options) {
224
232
  const workspaceIncarnation = randomBytes(16).toString('hex');
225
233
  const workspaceValidators = new WorkspaceValidatorCache();
226
234
  const providerHome = options.connectionHome ?? homedir();
227
- const checkConnection = createConnectionChecker({ home: providerHome, clock, ...(options.connectionProbe === undefined ? {} : { probe: options.connectionProbe }) });
235
+ const checkConnection = createConnectionChecker({ home: providerHome, clock,
236
+ probe: options.connectionProbe ?? statusProbe({ store, untrusted: givenRepos(options), timeoutMs: BACKGROUND_STATUS_TIMEOUT_MS }) });
228
237
  const fenceHere = options.fenceAvailable === undefined ? macosFenceAvailable() || linuxFenceAvailable() : false;
229
238
  if (options.telegramTokenFile !== undefined) {
230
239
  try {
@@ -586,7 +595,7 @@ export function createDecisionServer(options) {
586
595
  const flushBudget = () => { try {
587
596
  requestBudget.flush();
588
597
  }
589
- catch { } };
598
+ catch { } engineHandlers.upkeep(); };
590
599
  const timer = setInterval(flushBudget, REQUEST_BUDGET_FLUSH_MS);
591
600
  timer.unref?.();
592
601
  server.on("close", () => { clearInterval(timer); flushBudget(); });
@@ -613,6 +622,7 @@ export function createDecisionServer(options) {
613
622
  return null;
614
623
  return address.address === "127.0.0.1" ? `127.0.0.1:${port}` : address.address === "::1" ? `[::1]:${port}` : null;
615
624
  },
625
+ servedPort,
616
626
  });
617
627
  const consoleCommand = (change) => {
618
628
  const port = servedPort() ?? 4180;
@@ -704,7 +714,8 @@ export function createDecisionServer(options) {
704
714
  const workspaceRead = method === "GET" && url.searchParams.get('format') === 'workspace';
705
715
  const purpose = workspaceRead ? readPurpose(request.headers['x-toolroll-read']) : 'poll';
706
716
  const noTouch = edgeRoute?.domain === 'live' || (fragmentName !== null && NO_TOUCH_FRAGMENTS.has(fragmentName)) || /^\/code\/[a-f0-9]{32}\/state$/.test(url.pathname) || url.pathname === '/term/state'
707
- || url.pathname === '/agents/live' || /^\/agents\/live\/[0-9]{1,15}$/.test(url.pathname) || (url.pathname === '/agents' && url.searchParams.get('view') === 'live');
717
+ || url.pathname === '/agents/live' || /^\/agents\/live\/[0-9]{1,15}$/.test(url.pathname) || (url.pathname === '/agents' && url.searchParams.get('view') === 'live')
718
+ || /^\/agents\/live\/(?:run\/[0-9]{1,15}|thread\/[0-9a-f]{32})$/.test(url.pathname);
708
719
  const touch = !(method === "GET" && (noTouch || (workspaceRead && purpose !== 'navigate')));
709
720
  if (purpose === 'prefetch' && (request.headers.authorization !== undefined || !prefetchRoute(matchedRoute?.id, url))) {
710
721
  request.resume();
@@ -763,7 +774,7 @@ export function createDecisionServer(options) {
763
774
  returnTo: safeReturn(url.pathname + url.search),
764
775
  appOrigins: [consoleOrigin(request.headers.host), publicOrigin?.origin ?? null, options.configDir === undefined ? null : loadConsoleUrl(process.env, options.configDir)],
765
776
  browser: who.via === 'cookie',
766
- passwordless: who.via === 'cookie' && passwordlessOn(store),
777
+ passwordless: who.via === 'cookie' && who.authority !== 'local-owner' && sessionStandsIn(store),
767
778
  advanced: advancedShownFor(store, who.name),
768
779
  openProject: who.via === 'cookie' ? who.session.project : null,
769
780
  sso: who.via === 'cookie' && who.session.sso !== undefined ? { label: ssoSettings()?.label ?? "your identity provider",
@@ -781,6 +792,7 @@ export function createDecisionServer(options) {
781
792
  ...(who.via === "cookie" && who.authority === "local-owner" && store.accountOf(who.name)?.passwordSet === false
782
793
  ? { localStepUp: localOwnerRefusal(false, method === "GET" ? passwordSetNext(pagePathOf(url)) : "/").href } : {}),
783
794
  reconnect: browserKeys.stale(who, method === "GET" ? safeReturn(pagePathOf(url)) : "/"),
795
+ ...(method === "POST" && who.via === "cookie" && request.headers["x-toolroll-act"] === "in-place" && request.headers["x-toolroll-client"] === "terminal" ? { terminalAct: true } : {}),
784
796
  };
785
797
  if (purpose !== 'prefetch')
786
798
  response.once("finish", () => keepSlowRequest(store, timeline, matchedRoute?.id ?? "unmatched", response.statusCode, clock()));
@@ -981,21 +993,52 @@ export function createDecisionServer(options) {
981
993
  }
982
994
  let localSignIn = null;
983
995
  let localSignInChecking = null;
996
+ let localAgents = null;
984
997
  let leadRecheckedAt = 0;
998
+ const signedInSeen = new Map();
999
+ function heldSignIn(agent, value, at) {
1000
+ if (value !== null && SIGNED_IN_STATES.has(value.state)) {
1001
+ signedInSeen.set(agent, { at, value });
1002
+ return value;
1003
+ }
1004
+ const seen = signedInSeen.get(agent);
1005
+ if (value === null || value.state === "unverified")
1006
+ return seen !== undefined && at - seen.at < SIGNED_IN_HOLD_MS ? seen.value : value;
1007
+ signedInSeen.delete(agent);
1008
+ return value;
1009
+ }
985
1010
  function checkLocalAgents(fresh = false) {
986
1011
  if (localSignInChecking !== null)
987
1012
  return localSignInChecking;
988
- localSignInChecking = Promise.all(["claude", "codex"].map(one => connectionCheck(one, fresh).then(value => value.state, () => "unverified")))
989
- .then(([claude, codex]) => {
990
- localSignIn = { at: Date.now(), signedIn: [claude, codex].some(state => state === "connected" || state === "key-works" || state === "key-present"), states: { claude: claude, codex: codex } };
1013
+ const ask = (again) => Promise.all(LOCAL_AGENTS.map(one => connectionCheck(one, again).catch(() => null)));
1014
+ localSignInChecking = ask(fresh)
1015
+ .then(first => first.some(one => one !== null && SIGNED_IN_STATES.has(one.state)) || !first.some(one => one === null || one.state === "unverified") ? first : ask(true))
1016
+ .then(async (answers) => {
1017
+ const at = clock().getTime();
1018
+ const [claudeSeen, codexSeen] = answers.map((value, index) => heldSignIn(LOCAL_AGENTS[index], value, at));
1019
+ const claude = claudeSeen?.state ?? "unverified", codex = codexSeen?.state ?? "unverified";
1020
+ localSignIn = { at: Date.now(), signedIn: [claude, codex].some(state => SIGNED_IN_STATES.has(state)), states: { claude, codex } };
991
1021
  leadByDefault();
992
1022
  if (options.leadByDefault === true && !store.isDemo())
993
1023
  fillRoutingOnSignIn(store, localSignIn.states, clock());
1024
+ const held = { ...(claudeSeen ? { claude: claudeSeen } : {}), ...(codexSeen ? { codex: codexSeen } : {}) };
1025
+ const check = (provider, again) => { const kept = held[provider]; return kept !== undefined ? Promise.resolve(kept) : checkConnection(provider, again); };
1026
+ localAgents = await detectAgents({ check, home: providerHome, clock, routed: firstTaskRouted(store), acpChecked: acpCheckedHere(store) });
1027
+ const pick = localAgents.firstTask;
1028
+ if ((pick === "claude" || pick === "codex") && options.leadByDefault === true && !store.isDemo())
1029
+ fillDefaultRouting(store, pick, "toolroll", { kind: "detected" }, clock());
994
1030
  })
995
1031
  .catch(() => { })
996
1032
  .finally(() => { localSignInChecking = null; });
997
1033
  return localSignInChecking;
998
1034
  }
1035
+ function localAgentsSettled(maxMs) {
1036
+ const checking = localSignInChecking;
1037
+ if (checking === null)
1038
+ return Promise.resolve();
1039
+ let timer;
1040
+ return Promise.race([checking, new Promise(done => { timer = setTimeout(done, maxMs); timer.unref?.(); })]).finally(() => clearTimeout(timer));
1041
+ }
999
1042
  function localAgentSignedIn() {
1000
1043
  return localSignIn?.signedIn ?? null;
1001
1044
  }
@@ -1764,7 +1807,7 @@ export function createDecisionServer(options) {
1764
1807
  liveHandlers.close();
1765
1808
  detachReads();
1766
1809
  liveFollower.close();
1767
- void Promise.all([closeCoding(), terminalClosing.close?.().then(problem => { terminalClosing.problem = problem; }), bounded(team.close()), bounded(personalQueue.close()), bounded(leadMaintenance?.stop()), bounded(backgroundChecks?.stop()), bounded(reads?.close())])
1810
+ void Promise.all([closeCoding(), terminalClosing.close?.().then(problem => { terminalClosing.problem = problem; }), bounded(team.close()), bounded(personalQueue.close()), bounded(leadMaintenance?.stop()), bounded(backgroundChecks?.stop()), bounded(reads?.close()), bounded(engineHandlers.close())])
1768
1811
  .then(() => closeServer(error => callback?.(error ?? terminalClosing.problem ?? undefined))).catch(error => {
1769
1812
  if (callback)
1770
1813
  callback(error instanceof Error ? error : Error('Coding session shutdown failed.'));
@@ -1844,6 +1887,7 @@ export function createDecisionServer(options) {
1844
1887
  get leadRecheckedAt() { return leadRecheckedAt; },
1845
1888
  set leadRecheckedAt(value) { leadRecheckedAt = value; },
1846
1889
  get checkLocalAgents() { return checkLocalAgents; },
1890
+ get localAgentsSettled() { return localAgentsSettled; },
1847
1891
  get localSignIn() { return localSignIn; },
1848
1892
  set localSignIn(value) { localSignIn = value; },
1849
1893
  get agentSignInCommand() { return agentSignInCommand; },
@@ -1928,9 +1972,11 @@ export function createDecisionServer(options) {
1928
1972
  get keyEpoch() { return keyEpoch; },
1929
1973
  get browserKeys() { return browserKeys; },
1930
1974
  get outsideAdmissions() { return outsideAdmissions; },
1975
+ get localAgents() { return localAgents; },
1931
1976
  };
1932
1977
  const tasksHandlers = createTasksHandlers(handlerRuntime);
1933
1978
  const pagesHandlers = createPagesHandlers(handlerRuntime, { listFor: tasksHandlers.workListFor, showOrder: tasksHandlers.showOrder });
1979
+ const engineHandlers = createEngineHandlers(handlerRuntime);
1934
1980
  const flowsHandlers = createFlowsHandlers(handlerRuntime);
1935
1981
  const chatHandlers = createChatHandlers(handlerRuntime);
1936
1982
  const settingsHandlers = createSettingsHandlers(handlerRuntime);
@@ -1963,14 +2009,15 @@ export function createDecisionServer(options) {
1963
2009
  };
1964
2010
  const liveHandlers = createLiveHandlers(handlerRuntime, { bus: liveBus, workspaceRevision, chatProjectOf: chatHandlers.chatProjectOf, projectSummaryFor, projectScopeFor });
1965
2011
  liveTurnStarted = liveHandlers.turnStarted;
1966
- const terminalHandlers = createTerminalHandlers(handlerRuntime, { ...terminals, bus: liveBus, allowedHost, publicOrigin, forwardedSourceOf, server });
2012
+ const terminalHandlers = createTerminalHandlers(handlerRuntime, { ...terminals, bus: liveBus, allowedHost, publicOrigin, forwardedSourceOf, server,
2013
+ ...(options.agentCommandEnv === undefined ? {} : { agentEnv: options.agentCommandEnv }) });
1967
2014
  terminalClosing.close = terminalHandlers.close;
1968
2015
  const remoteHandlers = createRemoteHandlers(remoteRuntime);
1969
2016
  const registry = createHandlerRegistry([
1970
2017
  ...tasksHandlers.registrations, ...flowsHandlers.registrations, ...chatHandlers.registrations,
1971
2018
  ...settingsHandlers.registrations, ...peopleHandlers.registrations, ...pagesHandlers.registrations,
1972
2019
  ...remoteHandlers.registrations, ...liveHandlers.registrations, ...terminalHandlers.registrations, ...createSweepHandlers(handlerRuntime).registrations,
1973
- ...createWelcomeHandlers(handlerRuntime).registrations,
2020
+ ...createWelcomeHandlers(handlerRuntime).registrations, ...engineHandlers.registrations,
1974
2021
  ]);
1975
2022
  function dispatchConsole(route, ctx) {
1976
2023
  const { who, response } = ctx;
@@ -57,7 +57,7 @@ import { readFileSync } from "node:fs";
57
57
  import { join } from "node:path";
58
58
  import {} from "node:http";
59
59
  import { attributes, html, joinHtml, postForm, scriptElement, styleElement } from "../html.js";
60
- import { page, respond } from "./http.js";
60
+ import { page, refusedInPlace, respond } from "./http.js";
61
61
  import {} from "./render-pages.js";
62
62
  import {} from "./session.js";
63
63
  export function consoleSpend(summary) {
@@ -86,6 +86,8 @@ export function refuse(response, who, status, message, backHref = "/", act) {
86
86
  if (who === null || who.via === "bearer") {
87
87
  return respond(response, status, "text/plain; charset=utf-8", message);
88
88
  }
89
+ if (refusedInPlace(response, status, message))
90
+ return;
89
91
  const path = new URL(requestContext.getStore()?.returnTo ?? "/", "http://standing-orders.local").pathname;
90
92
  const generic = /^there'?s no page at this address\.?$/i.test(message.replace("\u2019", "'"));
91
93
  const body = html `<div class="k-refusal">${status === 404
@@ -1245,6 +1245,12 @@
1245
1245
  .approval-detail p, .approval-detail ul, .approval-detail dl { margin: var(--so-space-xs) 0; }
1246
1246
  .approval-detail ul { padding-left: 1.25rem; }
1247
1247
  .approval-detail .revision-card { margin: 0; padding: 0; border: 0; background: none; }
1248
+ /* The approval summary's usual settings, one tap away (approval-summary.ts). */
1249
+ details.terms-usual > summary { color: var(--muted-foreground); }
1250
+ details.terms-usual > .approval-rows { margin: var(--so-space-sm) 0 0; gap: var(--so-space-sm); }
1251
+ details.terms-usual .approval-row dt { font: var(--so-typography-caption); color: var(--so-muted); }
1252
+ details.terms-usual .approval-row dd p, .plan-sheet details.terms-usual .approval-row dd p { font-size: var(--so-typography-body-font-size); line-height: 1.5; color: var(--so-ink); }
1253
+ .approval-revision-plain { max-width: 75ch; margin: 0; font-size: 14px; line-height: 1.6; }
1248
1254
  .approval-roles { display: grid; gap: var(--so-space-sm); }
1249
1255
  .approval-roles > div { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: var(--so-space-md); }
1250
1256
  .approval-roles dt { color: var(--muted-foreground); font-weight: 500; }
@@ -1253,14 +1259,35 @@
1253
1259
  .chat-plan .approval-sheet { padding: 0; border: 0; background: none; }
1254
1260
  /* The plan sheet (task page, docs/plans/task-page-steps.md): the same terms read top to bottom — one lead sentence,
1255
1261
  Steps, Done when, Will change / Won't touch, Worth knowing, the agent — every part open, small muted headings. */
1256
- .plan-sheet { display: grid; gap: 22px; margin: 0; min-width: 0; color: var(--so-ink); }
1262
+ /* The plan sheet (the terms diet, DESIGN.md Signal): three groups under hairlines — the plan, before you approve, what
1263
+ it may do — 24px above each hairline and 16px below; 20px between parts, 8px from a heading to its body. */
1264
+ .plan-sheet { display: grid; gap: 0; margin: 0; min-width: 0; color: var(--so-ink); }
1265
+ .plan-sheet > .approval-note { margin: 0 0 var(--so-space-lg); }
1266
+ .plan-group { display: grid; gap: var(--so-space-xl); min-width: 0; }
1267
+ .plan-group + .plan-group { margin-top: var(--so-space-2xl); padding-top: var(--so-space-lg); border-top: 1px solid var(--so-line); }
1268
+ .plan-notice { display: grid; gap: var(--so-space-sm); padding: var(--so-space-md) var(--so-space-lg); border-radius: var(--so-radius-md); background: var(--so-raised); color: var(--so-ink); }
1269
+ .plan-notice > *, .plan-notice p { margin: 0; }
1270
+ .plan-sheet .approval-revision.plan-sheet-revision { margin: 0; font-size: var(--so-typography-body-reading-font-size); font-weight: 500; line-height: 1.6; }
1271
+ .plan-sheet .plan-sheet-brief { color: var(--so-ink); }
1272
+ .plan-sheet-foot { margin: 0; font: var(--so-typography-caption); font-weight: 400; color: var(--so-muted); }
1273
+ .plan-sheet-foot .mono { font: var(--so-typography-mono); }
1274
+ .plan-sheet .approval-path { font: var(--so-typography-mono); color: var(--so-ink); overflow-wrap: anywhere; }
1275
+ details.plan-sheet-full { margin: 0; }
1276
+ details.plan-sheet-full > summary { min-height: 32px; font: var(--so-typography-label); color: var(--so-ink); cursor: pointer; }
1277
+ details.plan-sheet-full[open] { display: grid; gap: var(--so-space-xl); }
1257
1278
  .plan-sheet > * { margin: 0; }
1258
- .plan-sheet-lead { max-width: 66ch; font-size: 17px; line-height: 1.5; letter-spacing: -.01em; overflow-wrap: anywhere; }
1259
- .plan-sheet-lead-long { font-size: 15px; line-height: 1.6; letter-spacing: 0; }
1279
+ .plan-sheet-lead { max-width: 66ch; font-size: 16px; font-weight: 500; line-height: 1.5; letter-spacing: -.01em; color: var(--so-ink); overflow-wrap: anywhere; }
1280
+ .plan-sheet-lead-long { font-size: var(--so-typography-title-font-size); font-weight: 400; line-height: 1.6; letter-spacing: 0; }
1260
1281
  .plan-sheet-text { max-width: 66ch; font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; white-space: pre-wrap; }
1261
- .plan-sheet-part { display: grid; align-content: start; gap: var(--so-space-sm); min-width: 0; max-width: 75ch; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
1282
+ .plan-sheet-part { display: grid; align-content: start; gap: var(--so-space-sm); min-width: 0; max-width: 75ch; font-size: var(--so-typography-body-reading-font-size); line-height: 1.6; color: var(--so-ink); overflow-wrap: anywhere; }
1262
1283
  .plan-sheet-part > *, .plan-sheet-part p, .plan-sheet-part ul, .plan-sheet-part ol, .plan-sheet-part dl { margin: 0; }
1263
- .plan-sheet-h { margin: 0; font-size: 12px; font-weight: 500; line-height: 1.5; letter-spacing: 0; text-transform: none; color: var(--so-muted); }
1284
+ /* Section headings read as headings (Title, ink), beating the workspace's generic h3 (.so-native-region :where(h3)). */
1285
+ .plan-sheet .plan-sheet-h { margin: 0; font: var(--so-typography-title); letter-spacing: var(--so-typography-title-letter-spacing); text-transform: none; color: var(--so-ink); }
1286
+ .plan-sheet .approval-goal { font-size: var(--so-typography-body-reading-font-size); line-height: 1.6; color: var(--so-ink); }
1287
+ .plan-sheet .approval-rows { gap: var(--so-space-md); }
1288
+ .plan-sheet .approval-row { grid-template-columns: 120px minmax(0, 1fr); }
1289
+ .plan-sheet .approval-row dt { font: var(--so-typography-caption); color: var(--so-muted); }
1290
+ .plan-sheet .approval-row dd, .plan-sheet .approval-row dd p { font-size: var(--so-typography-body-reading-font-size); line-height: 1.6; color: var(--so-ink); }
1264
1291
  .plan-sheet-sub { color: var(--so-muted); font-size: 12.5px; }
1265
1292
  .plan-sheet-steps { display: grid; gap: var(--so-space-sm); padding: 0; list-style: none; counter-reset: plan-step; }
1266
1293
  .plan-sheet-steps > li { display: flex; gap: var(--so-space-md); counter-increment: plan-step; }
@@ -1270,7 +1297,7 @@
1270
1297
  .plan-sheet-done > li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--so-space-xs) var(--so-space-md); padding: var(--so-space-sm) 0; border-bottom: 1px solid var(--so-line); }
1271
1298
  .plan-sheet-done > li:last-child { border-bottom: 0; }
1272
1299
  .plan-sheet-done > li > span:first-child { flex: 1 1 260px; min-width: 0; }
1273
- .plan-sheet-how { flex: none; font-size: 12.5px; color: var(--so-muted); }
1300
+ .plan-sheet-how { flex: none; font: var(--so-typography-caption); font-weight: 400; color: var(--so-muted); }
1274
1301
  .plan-sheet-pair { display: flex; flex-wrap: wrap; gap: var(--so-space-lg) 40px; }
1275
1302
  .plan-sheet-pair > .plan-sheet-part { flex: 1 1 220px; }
1276
1303
  .plan-sheet .approval-paths li { color: var(--so-ink); font-size: 13px; line-height: 1.7; }