toolroll 0.9.116 → 0.9.117

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 (129) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +43 -26
  3. package/dist/acp-agents.js +14 -1
  4. package/dist/acp-client.js +19 -1
  5. package/dist/agent-change-check.js +60 -0
  6. package/dist/agent-change-schema.js +19 -0
  7. package/dist/agent-detect.js +11 -1
  8. package/dist/agent-fence.js +39 -10
  9. package/dist/agent-network-request.js +108 -0
  10. package/dist/agent-requests.js +105 -0
  11. package/dist/approval-summary.js +3 -3
  12. package/dist/backup.js +17 -1
  13. package/dist/batch-checks.js +81 -18
  14. package/dist/browser/terminal.js +41 -41
  15. package/dist/browser/workspace.css +2 -2
  16. package/dist/browser/workspace.js +36 -36
  17. package/dist/builder.js +3 -1
  18. package/dist/candidate-materialize.js +119 -0
  19. package/dist/central-enrollment-contract.js +156 -0
  20. package/dist/central-recovery-stage.js +329 -0
  21. package/dist/chat-actions.js +101 -2
  22. package/dist/chat-channel.js +40 -0
  23. package/dist/check-only-standing.js +13 -0
  24. package/dist/check-only.js +25 -13
  25. package/dist/check-recovery-hold.js +199 -0
  26. package/dist/check-recovery-index-schema.js +3 -0
  27. package/dist/check-screenshots.js +83 -0
  28. package/dist/cli.js +125 -6
  29. package/dist/codex-limits.js +4 -0
  30. package/dist/connect-cli.js +257 -11
  31. package/dist/contracts/chat-actions.js +4 -0
  32. package/dist/contracts/console-api.js +14 -3
  33. package/dist/contracts/engine-api.js +331 -2
  34. package/dist/contracts/lead-tools.js +56 -2
  35. package/dist/contracts/provider.js +1 -1
  36. package/dist/contracts/route.js +1 -1
  37. package/dist/contracts/terminal-connection.js +50 -0
  38. package/dist/converse.js +80 -4
  39. package/dist/device-pair.js +280 -0
  40. package/dist/direct-chat-artifacts.js +347 -0
  41. package/dist/direct-chat-catalog.js +311 -0
  42. package/dist/direct-chat-fence.js +96 -0
  43. package/dist/direct-chat-git.js +343 -0
  44. package/dist/direct-chat-laptop.js +19 -0
  45. package/dist/direct-chat-schema.js +181 -0
  46. package/dist/direct-chat-ship.js +861 -0
  47. package/dist/direct-chat-workspace.js +389 -0
  48. package/dist/direct-chat.js +2107 -0
  49. package/dist/doctor.js +1 -1
  50. package/dist/easy-start.js +18 -0
  51. package/dist/egress.js +25 -4
  52. package/dist/engine-chat.js +454 -0
  53. package/dist/engine-reads.js +141 -13
  54. package/dist/exec.js +4 -3
  55. package/dist/flexible-agents.js +8 -16
  56. package/dist/flexible-session.js +91 -47
  57. package/dist/flexible-ship.js +87 -7
  58. package/dist/flexible-start.js +4 -1
  59. package/dist/flexible-thread.js +2 -3
  60. package/dist/flexible-turns.js +26 -5
  61. package/dist/flow-triggers.js +13 -4
  62. package/dist/flows-ui.js +54 -20
  63. package/dist/handoff-cli.js +630 -0
  64. package/dist/invoke.js +55 -13
  65. package/dist/lead-contract.js +5 -4
  66. package/dist/lead-doors.js +80 -1
  67. package/dist/lead-progress.js +9 -0
  68. package/dist/lead-tools.js +681 -10
  69. package/dist/lead.js +37 -9
  70. package/dist/live-bus.js +11 -0
  71. package/dist/live-terminal.js +132 -12
  72. package/dist/local-handoff.js +363 -0
  73. package/dist/local-owner-acts.js +264 -2
  74. package/dist/local-owner.js +16 -1
  75. package/dist/multiplayer-handoff.js +528 -0
  76. package/dist/multiplayer-presence.js +471 -0
  77. package/dist/names.js +17 -4
  78. package/dist/needs-you.js +10 -0
  79. package/dist/operate.js +280 -19
  80. package/dist/policy.js +2 -2
  81. package/dist/project-delete-ui.js +18 -11
  82. package/dist/project-delete.js +65 -4
  83. package/dist/project-tools.js +1 -1
  84. package/dist/prompt.js +1 -1
  85. package/dist/provider-connection.js +2 -0
  86. package/dist/provider-home.js +251 -8
  87. package/dist/provider.js +3 -2
  88. package/dist/publish.js +119 -64
  89. package/dist/pull-request-flow.js +35 -14
  90. package/dist/read-executor-worker.js +1 -1
  91. package/dist/read-executor.js +95 -1
  92. package/dist/restore-retirement.js +152 -0
  93. package/dist/result-follow-ups.js +116 -37
  94. package/dist/route-change.js +44 -4
  95. package/dist/scope.js +62 -5
  96. package/dist/serve.js +49 -5
  97. package/dist/server/chat.js +94 -13
  98. package/dist/server/direct-chat.js +583 -0
  99. package/dist/server/engine-api.js +219 -21
  100. package/dist/server/flows.js +43 -10
  101. package/dist/server/found-repos.js +25 -0
  102. package/dist/server/guards.js +20 -6
  103. package/dist/server/live.js +81 -23
  104. package/dist/server/pages.js +67 -13
  105. package/dist/server/people-tokens.js +47 -6
  106. package/dist/server/remote.js +29 -0
  107. package/dist/server/render-results.js +6 -2
  108. package/dist/server/render-settings.js +4 -2
  109. package/dist/server/render-tasks.js +18 -17
  110. package/dist/server/route-table.js +69 -2
  111. package/dist/server/settings.js +22 -7
  112. package/dist/server/task-views.js +15 -3
  113. package/dist/server/tasks.js +39 -2
  114. package/dist/server/terminals.js +185 -11
  115. package/dist/settings-proofs.js +1 -1
  116. package/dist/store.js +499 -56
  117. package/dist/subscription-chat.js +33 -6
  118. package/dist/subscription-usage.js +233 -0
  119. package/dist/task-live.js +2 -1
  120. package/dist/teardown-git.js +34 -4
  121. package/dist/terminal-connection.js +159 -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-contract.js +1 -1
  127. package/dist/tui-launch.js +32 -1
  128. package/dist/workspace-identity-schema.js +21 -0
  129. package/package.json +3 -1
package/dist/operate.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { FLEXIBLE_CANDIDATE_FIXED, FLEXIBLE_FILED_PREFIX, flexibleMergeRefusal } from "./flexible-merge-guard.js";
2
+ import { clearResolvedAgentRequests, fileAgentRequest, listAgentRequests, resolveAgentRequest, waitForAgentRequest } from "./agent-requests.js";
3
+ import { readStoredGeminiStatus, refreshSubscriptions } from "./subscription-usage.js";
4
+ import { liveCommandsShown } from "./live-detail.js";
2
5
  import { flexibleArmedPass } from "./flexible-ship.js";
3
- import { closeFlexibleThread, flexibleThreadRecords, flexibleThreadShipTerms, flexibleThreadTitleOf, latestFlexibleShip, removeFlexibleThreadCopy, shipFlexibleThread, stopFlexibleThreadsEverywhere } from "./flexible-session.js";
6
+ import { directChatArmedPass } from "./direct-chat-ship.js";
7
+ import { closeFlexibleThread, flexibleShipNeedsFor, flexibleThreadRecords, flexibleThreadShipTerms, flexibleThreadTitleOf, latestFlexibleShip, removeFlexibleThreadCopy, shipFlexibleThread, stopFlexibleThreadsEverywhere } from "./flexible-session.js";
4
8
  import { runCardCommand } from "./card-cli.js";
5
9
  import { mintSecret } from "./secret-mint.js";
6
10
  import { ACP_AGENTS, ACP_PROVIDER_IDS, isAcpProvider, isKeyedProvider } from "./acp-agents.js";
@@ -94,12 +98,13 @@ import { approvalSummaryFor, approvalSummaryOf, describeScope, summaryContextOf,
94
98
  import { runAssignmentCommand } from "./assignment-adapters.js";
95
99
  import { applyProjectProfile, runProjectCommand } from "./project-cli.js";
96
100
  import { passwordFreeOwner, passwordFreeShell, passwordFreeShellWords, proveTaskBuildsStopped, pullRequestLines, runLocalCompletion, runLocalRevision, runTaskMergeCommand, runTaskOutcomeCommand } from "./task-outcome-cli.js";
97
- import { planAgainAsLocalOwner, requestPlanAsLocalOwner, retryAsLocalOwner } from "./local-owner-acts.js";
101
+ import { applyPendingAgentChanges, planAgainAsLocalOwner, requestPlanAsLocalOwner, retryAsLocalOwner } from "./local-owner-acts.js";
98
102
  import { withTaskAlias } from "./task-aliases.js";
99
103
  import { checklistLines, mergeChecklistOf } from "./merge-checklist.js";
100
104
  import { taskReviewBrief, renderReviewBrief } from "./task-review-brief.js";
101
105
  import { homedir, hostname } from "node:os";
102
106
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
107
+ import { CHECK_RECOVERY_HELD, readCheckRecoveryHoldsForTaskRef } from "./check-recovery-hold.js";
103
108
  import { releaseStalledUpdate, waitingUpdate } from "./toolroll-update.js";
104
109
  import { dur } from "./design/kit.js";
105
110
  import { requeueEligibility, checkoutIdle, setCheckoutIdle, leadQuickAnswersOn, setLeadQuickAnswers, openStore, openStoreNoMigrate, initLocalMode, localModeCandidate, consoleServingNow, consoleComponent, consoleRowForPort, openConsoleRows, enrollOwnerPassword, installationCreatedBy, laptopPortOf, recordLaptopPort, localModeOf, localOwnerBinding, archiveTaskFamily, restoreTaskFamily, shipChecksForTask, elapsedSeconds, CONCURRENT_WRITER_WAIT_MS, isDatabaseBusy, databasePath, BUILT_IN, parseCapabilityKey, verifiedAuthor, isDigestTime, predecessorWatches, RESULT_SCREENSHOTS, lifecycleOf, reportLifecycle, beatLifecycle, } from "./store.js";
@@ -110,7 +115,7 @@ import { authorizePlanUnderMode } from "./plan-auto.js";
110
115
  import { ghDispatchAdapter, mirrorTaskId, syncPass } from "./sync.js";
111
116
  import { LIVE_FILE_BOUND, LIVE_RETAIN_MS, sweepLiveLogs } from "./live.js";
112
117
  import { addRepos, removeRepos, updateRepos, loadRepos, loadProjectRegistry, updateProjectRegistry, registryRemovals } from "./repos.js";
113
- import { deleteProject, holdingsWords, projectHoldings, projectRunning } from "./project-delete.js";
118
+ import { deleteProject, holdingsWords, projectHoldings, projectRunning, PROJECT_RECOVERY_DELETE_MESSAGE } from "./project-delete.js";
114
119
  import { pushPass } from "./push.js";
115
120
  import { chmodSync, closeSync, constants as fsConstants, existsSync, fstatSync, fsyncSync, mkdirSync, openSync, readFileSync, readSync, realpathSync, renameSync, unlinkSync, writeSync, writeFileSync } from "node:fs";
116
121
  import { BRANCH_PREFIX, envValue, existingOrFirst, taskBranches } from "./names.js";
@@ -235,7 +240,7 @@ import { resumeAllowedReleases } from "./release-next.js";
235
240
  import { fileGithubItem, readGithubItem } from "./github-import.js";
236
241
  import { runRelease } from "./release.js";
237
242
  import { releaseAdapters } from "./release-adapters.js";
238
- import { routeChangeOf, routeLegacyPlans } from "./route-change.js";
243
+ import { proposeNetworkChanges, routeChangeOf, routeLegacyPlans } from "./route-change.js";
239
244
  import { installModeNow, sessionStandsIn } from "./install-mode.js";
240
245
  import { parseDemoUrl, projectDemoUrl, saveProjectDemo } from "./project-demo.js";
241
246
  import { effectiveConcurrency, maySlotTake, parseProjectConcurrency, PROJECT_CONCURRENCY_DEFAULT, ProjectPasses, projectConcurrency, saveProjectConcurrency, savedProjectConcurrency } from "./project-concurrency.js";
@@ -784,6 +789,8 @@ export const OPERATE_BOOLEAN_FLAGS = new Set([
784
789
  "now",
785
790
  "preview", "apply",
786
791
  "no-check", "check",
792
+ "wait",
793
+ "live",
787
794
  ]);
788
795
  const PROJECT_NETWORK_VALUE_FLAGS = new Set(["remove", "local"]);
789
796
  export function parseOperateArgs(argv, ownValues = new Set()) {
@@ -1189,7 +1196,11 @@ async function dispatch(command, positional, flags, context) {
1189
1196
  return projectChecksCommand(positional, flags, context);
1190
1197
  if (positional[0] === "demo")
1191
1198
  return projectDemoCommand(positional, flags, context);
1199
+ if (positional[0] === "live-view")
1200
+ return projectLiveViewCommand(positional, flags, context);
1192
1201
  return runProjectCommand(positional, flags, context);
1202
+ case "request":
1203
+ return requestCommand(positional, flags, context);
1193
1204
  case "assignment":
1194
1205
  if (positional[0] === "claim" && currentActor()?.lead === true && !flags.has("token-env") && !flags.has("token-file"))
1195
1206
  return leadClaimCommand(positional, flags, context);
@@ -2132,6 +2143,7 @@ async function tickCommand(flags, context) {
2132
2143
  base = head.stdout.trim();
2133
2144
  }
2134
2145
  await probeRepo(store, repo, runner, clock());
2146
+ applyPendingAgentChanges(store, clock());
2135
2147
  const housekeeping = buildsOnly ? null : await flowHousekeeping(store, repo, clock, flowIoOf(context, pool, git, base), () => context.shouldStop?.() === true || context.shouldPauseAdmission?.() === true);
2136
2148
  const triggerPass = housekeeping?.triggers ?? { added: 0, checked: 0, problems: [] };
2137
2149
  const replyPass = housekeeping?.replies ?? { read: 0, taken: 0, problem: null };
@@ -3041,6 +3053,7 @@ async function reconcileCommand(flags, context) {
3041
3053
  store.settleUnspawnedWitnesses(clock());
3042
3054
  await proveFinishedRunsStopped(store, clock);
3043
3055
  store.settleQuiescentStops(clock());
3056
+ applyPendingAgentChanges(store, clock());
3044
3057
  retryVanishedWhenStopped(store, clock());
3045
3058
  expireFastStarts(store, clock());
3046
3059
  routeLegacyPlans(store, clock());
@@ -4560,9 +4573,33 @@ async function setupCommand(positional, flags, context) {
4560
4573
  return EXIT.ok;
4561
4574
  }
4562
4575
  if (action !== "set" && action !== "clear")
4563
- return fail(write, json, "setup", "usage", "`toolroll setup [show|set --command <cmd> [--timeout-seconds <n>] --yes|clear] --repo <path> --as <you> --token <t>`", EXIT.usage);
4576
+ return fail(write, json, "setup", "usage", "`toolroll setup [show|set --command <cmd> [--timeout-seconds <n>] [--yes|--request <why>]|clear] --repo <path> --as <you> --token <t>`", EXIT.usage);
4564
4577
  if (repo === undefined)
4565
4578
  return fail(write, json, `setup ${action}`, "usage", "which repo? --repo <path>", EXIT.usage);
4579
+ if (action === "set" && flags.has("request")) {
4580
+ const reqCmd = text(flags, "command");
4581
+ if (reqCmd === undefined || reqCmd.trim() === "")
4582
+ return fail(write, json, "setup set", "usage", "--command <cmd> is what every fresh checkout will run", EXIT.usage);
4583
+ if (reqCmd.length > 2000 || hasDisguisedText(reqCmd))
4584
+ return fail(write, json, "setup set", "invalid", "the command must be under 2000 characters with no control or bidi characters", EXIT.usage);
4585
+ const reqCredShaped = /([A-Za-z0-9_-]*(?:token|secret|password|passwd|apikey|api_key|authorization|bearer|credential)[A-Za-z0-9_-]*\s*[=:]\s*)(?![$"']?\$)\S+/i.test(reqCmd) ||
4586
+ /\/\/[^\s/@]+:[^\s/@]+@/.test(reqCmd);
4587
+ if (reqCredShaped)
4588
+ return fail(write, json, "setup set", "credential-shaped", "the command appears to embed a credential — reference an environment variable the runner exports (e.g. $NPM_TOKEN) instead of a literal value", EXIT.usage);
4589
+ const reqTimeoutSeconds = Number(text(flags, "timeout-seconds") ?? "300");
4590
+ if (!Number.isInteger(reqTimeoutSeconds) || reqTimeoutSeconds < 1 || reqTimeoutSeconds > 3600)
4591
+ return fail(write, json, "setup set", "invalid", "--timeout-seconds is 1..3600", EXIT.usage);
4592
+ const resolvedRepo = (await knownProject(context, repo, { listed: true, canonical: true })) ?? resolve(repo);
4593
+ const req = fileAgentRequest(context.databaseFile, {
4594
+ kind: "worktree-setup",
4595
+ repo: resolvedRepo,
4596
+ ...(text(flags, "by") === undefined ? {} : { requester: text(flags, "by") }),
4597
+ summary: `Set worktree setup: ${reqCmd}`,
4598
+ why: text(flags, "why") ?? text(flags, "request") ?? "",
4599
+ params: { command: reqCmd, timeoutSeconds: reqTimeoutSeconds },
4600
+ }, clock());
4601
+ return finishFiledRequest("setup set", req, flags, context);
4602
+ }
4566
4603
  const acting = await askCredentials(flags, context);
4567
4604
  const verified = acting === null ? null : authenticateApprover(store, acting.name, acting.token);
4568
4605
  if (acting === null || !verified?.ok)
@@ -5534,6 +5571,16 @@ async function runWatchLoop(args) {
5534
5571
  catch (error) {
5535
5572
  progress(`watch: the Flexible ship pass failed — ${describe(error)}; retrying on its next interval`);
5536
5573
  }
5574
+ try {
5575
+ const dcShipped = await directChatArmedPass(store, { root: context.evidenceRoot, ...(context.publishExec === undefined ? {} : { exec: context.publishExec }) });
5576
+ if (dcShipped.merged > 0)
5577
+ progress(`watch: merged ${dcShipped.merged} Direct Chat result(s) whose checks passed`);
5578
+ if (dcShipped.cancelled > 0)
5579
+ progress(`watch: stopped ${dcShipped.cancelled} Direct Chat merge(s) whose terms no longer held`);
5580
+ }
5581
+ catch (error) {
5582
+ progress(`watch: the Direct Chat ship pass failed — ${describe(error)}; retrying on its next interval`);
5583
+ }
5537
5584
  }
5538
5585
  if (!stopping() && store.openedPublications().length > 0) {
5539
5586
  try {
@@ -7043,6 +7090,8 @@ async function publishCommand(positional, flags, context) {
7043
7090
  if (action === "merge") {
7044
7091
  const released = store.authorizeMergeIntent(intent.id, intent.headSha, acting.name, clock());
7045
7092
  if (!released.ok) {
7093
+ if (released.reason === "recovery-held")
7094
+ return fail(write, json, "publish merge", "recovery-held", "Checks are on hold after recovery. Earlier execution is unverified.", EXIT.refused);
7046
7095
  return fail(write, json, "publish merge", released.reason, released.reason === "not-waiting"
7047
7096
  ? `PR #${pr} is not waiting for you (it is ${intent.state}) — only a waiting merge takes this yes`
7048
7097
  : `PR #${pr}'s commit moved since this intent was written — the sweep will re-prove and re-ask`, EXIT.refused);
@@ -7054,6 +7103,8 @@ async function publishCommand(positional, flags, context) {
7054
7103
  }
7055
7104
  const refired = store.refireMergeIntent(intent.id, acting.name, clock());
7056
7105
  if (!refired.ok) {
7106
+ if (refired.reason === "recovery-held")
7107
+ return fail(write, json, "publish refire", "recovery-held", "Checks are on hold after recovery. Earlier execution is unverified.", EXIT.refused);
7057
7108
  return fail(write, json, "publish refire", refired.reason, refired.reason === "not-firing"
7058
7109
  ? `PR #${pr} has no half-fired merge (it is ${intent.state})`
7059
7110
  : `PR #${pr}'s merge claim is still live — its owner may finish; refire only recovers one gone silent past its deadline`, EXIT.refused);
@@ -7085,6 +7136,8 @@ async function publishCommand(positional, flags, context) {
7085
7136
  ]);
7086
7137
  }
7087
7138
  const rearmed = store.rearmMergeIntent(publication.id);
7139
+ if (rearmed === "recovery-held")
7140
+ return fail(write, json, "publish rearm", "recovery-held", "Checks are on hold after recovery. Earlier execution is unverified.", EXIT.refused);
7088
7141
  store.resolveEpisodes(`merge-attn:${publication.id}`, context.clock());
7089
7142
  return succeed(write, json, "publish rearm", { pr, rearmed }, () => [
7090
7143
  rearmed
@@ -7706,14 +7759,21 @@ async function addTask(positional, flags, context) {
7706
7759
  const replaces = text(flags, "replaces");
7707
7760
  if (replaces !== undefined && (replaces === id || store.getTask(replaces) === null))
7708
7761
  return fail(write, json, "task add", "unknown-task", `no task \`${replaces}\` to replace`, EXIT.refused);
7762
+ if (replaces !== undefined && builtinReplacementHeld(store, replaces, id))
7763
+ return fail(write, json, "task add", "recovery-held", "This task can't be replaced while earlier check execution is unverified after recovery.", EXIT.refused);
7709
7764
  noteActingPerson(flags, context);
7710
7765
  const outcome = store.replay(mutationFrom(flags, now), "task add", () => {
7711
7766
  if (store.getTask(id) !== null)
7712
7767
  return { ok: false };
7768
+ if (replaces !== undefined)
7769
+ return createBuiltinReplacement(store, { id, title, report: flags.has("report"), repo: text(flags, "repo") ?? null, replaces, now });
7713
7770
  return { ok: true, task: store.createTask({ id, title, ...(flags.has("report") ? { deliverable: "report" } : {}) }, now) };
7714
7771
  }, result => result.ok);
7715
- if (!outcome.ok)
7772
+ if (!outcome.ok) {
7773
+ if ("reason" in outcome)
7774
+ return fail(write, json, "task add", outcome.reason, outcome.reason === "recovery-held" ? "This task can't be replaced while earlier check execution is unverified after recovery." : "The replacement couldn't be filed. Nothing was changed.", EXIT.refused);
7716
7775
  return fail(write, json, "task add", "exists", `\`${id}\` already exists`, EXIT.refused);
7776
+ }
7717
7777
  const filedId = outcome.task.id;
7718
7778
  const remote = activeRemote();
7719
7779
  if (remote !== null && filedId !== id) {
@@ -7723,15 +7783,14 @@ async function addTask(positional, flags, context) {
7723
7783
  }
7724
7784
  }
7725
7785
  remote?.noteTask(filedId);
7726
- store.stampFiledVia(store.refFor(BUILT_IN, filedId).id, "cli");
7786
+ if (replaces === undefined)
7787
+ store.stampFiledVia(store.refFor(BUILT_IN, filedId).id, "cli");
7727
7788
  const placedIn = text(flags, "repo");
7728
- if (placedIn !== undefined) {
7789
+ if (placedIn !== undefined && replaces === undefined) {
7729
7790
  const placed = store.placeTask(store.refFor(BUILT_IN, filedId).id, canonicalProject(placedIn) ?? resolve(placedIn));
7730
7791
  if (typeof placed === "object" && !placed.ok)
7731
7792
  return fail(write, json, "task add", "scoped", "this task already has a scope — placement is immutable once somebody could have approved it", EXIT.refused);
7732
7793
  }
7733
- if (replaces !== undefined)
7734
- store.setTaskState(replaces, "cancelled", now, {}, undefined, outcome.task.id);
7735
7794
  if (checks !== undefined) {
7736
7795
  const chosen = setTaskCheckLevel(store, outcome.task.id, checks, "cli", now);
7737
7796
  if (!chosen.ok)
@@ -7795,6 +7854,8 @@ async function runTaskChecks(positional, flags, context) {
7795
7854
  if (!asked.ok)
7796
7855
  return fail(write, json, "task checks", asked.reason, asked.message, EXIT.refused);
7797
7856
  const done = await runFollowUpCheck(store, context.evidenceRoot, asked.request, { now: clock });
7857
+ if (done?.state === "recovery-held")
7858
+ return fail(write, json, "task checks", "recovery-held", done.note, EXIT.refused);
7798
7859
  const state = done?.state ?? "waiting";
7799
7860
  const words = `${CHECK_LEVEL_WORDS[asked.level]} checks`;
7800
7861
  const payload = { task: taskId, run: result.runId, head: result.head, request: asked.request, level: asked.level, state, exitCode: done?.exitCode ?? null };
@@ -8318,6 +8379,8 @@ async function stateTask(positional, flags, context) {
8318
8379
  noteActingPerson(flags, context);
8319
8380
  const moved = store.setTaskState(id, state, now, mutationFrom(flags, now), text(flags, "reason"), replacedBy);
8320
8381
  if (!moved.ok) {
8382
+ if (moved.reason === "recovery-held")
8383
+ return fail(write, json, "task state", "recovery-held", "This task can't be replaced while earlier check execution is unverified after recovery.", EXIT.refused);
8321
8384
  if (moved.reason === "reason-required" || moved.reason === "bad-reason") {
8322
8385
  return fail(write, json, "task state", moved.reason, moved.reason === "reason-required"
8323
8386
  ? "a coordinator filed this task — add --reason with why you are cancelling it"
@@ -9485,14 +9548,14 @@ async function projectRulesCommand(positional, flags, context) {
9485
9548
  }
9486
9549
  async function projectNetworkCommand(positional, flags, context) {
9487
9550
  const command = "project network";
9488
- const allowed = new Set(["repo", "allow", "remove", "open", "allowlist", "local", "as", "token", "token-file", "token-env", "db", "json"]);
9551
+ const allowed = new Set(["repo", "allow", "remove", "open", "allowlist", "local", "request", "why", "by", "wait", "timeout", "as", "token", "token-file", "token-env", "db", "json"]);
9489
9552
  for (const name of flags.keys())
9490
9553
  if (!allowed.has(name))
9491
9554
  return fail(context.write, context.json, command, "usage", `--${name} is not a project network option.`, EXIT.usage);
9492
9555
  const repoFlag = text(flags, "repo");
9493
9556
  const local = flags.get("local");
9494
9557
  if (positional.length > 1 || repoFlag === undefined || (flags.has("open") && flags.has("allowlist")) || (local !== undefined && local !== "any" && local !== "none"))
9495
- return fail(context.write, context.json, command, "usage", "Use project network --repo <project path> [--allow host,…] [--remove host,…] [--open | --allowlist] [--local any|none].", EXIT.usage);
9558
+ return fail(context.write, context.json, command, "usage", "Use project network --repo <project path> [--allow host,…] [--remove host,…] [--open | --allowlist] [--local any|none] [--request <why>].", EXIT.usage);
9496
9559
  const repo = await knownProject(context, repoFlag, { listed: true, canonical: true });
9497
9560
  if (repo === undefined)
9498
9561
  return fail(context.write, context.json, command, "not-found", "That isn't a project Toolroll knows.", EXIT.refused);
@@ -9521,14 +9584,43 @@ async function projectNetworkCommand(positional, flags, context) {
9521
9584
  };
9522
9585
  if (next.hosts.length > MAX_NETWORK_HOSTS)
9523
9586
  return fail(context.write, context.json, command, "usage", `A project lists at most ${MAX_NETWORK_HOSTS} hosts.`, EXIT.usage);
9587
+ if (flags.has("request")) {
9588
+ const parts = [];
9589
+ if (local === "any")
9590
+ parts.push("Allow this Mac's local services (localhost / ::1)");
9591
+ if (local === "none")
9592
+ parts.push("Block local services (proxy-only)");
9593
+ if (flags.has("open"))
9594
+ parts.push("Switch build network to open (any host)");
9595
+ if (flags.has("allowlist"))
9596
+ parts.push("Switch build network to allowlist");
9597
+ if (add.length > 0)
9598
+ parts.push(`Allow hosts: ${add.join(", ")}`);
9599
+ if (remove.length > 0)
9600
+ parts.push(`Remove hosts: ${remove.join(", ")}`);
9601
+ const req = fileAgentRequest(context.databaseFile, {
9602
+ kind: "network",
9603
+ repo,
9604
+ ...(text(flags, "by") === undefined ? {} : { requester: text(flags, "by") }),
9605
+ summary: parts.join(" · ") || "Update project network policy",
9606
+ why: text(flags, "why") ?? text(flags, "request") ?? "",
9607
+ params: { local: next.loopback, mode: next.mode, hosts: next.hosts, change: { add, remove,
9608
+ ...(flags.has("open") ? { mode: "open" } : flags.has("allowlist") ? { mode: "allowlist" } : {}),
9609
+ ...(local === "any" ? { local: "any" } : local === "none" ? { local: "proxy-only" } : {}) } },
9610
+ }, context.clock());
9611
+ return finishFiledRequest(command, req, flags, context);
9612
+ }
9524
9613
  const acting = await askCredentials(flags, context);
9525
9614
  const verified = acting === null ? null : credentialApprover(context.store, acting.name, acting.token, repo);
9526
9615
  if (acting === null || !verified?.ok || !context.store.accountCanAccess(acting.name, repo))
9527
9616
  return fail(context.write, context.json, command, "refused", "An approver for this project changes what its builds may reach, with their password: pass --as and --token.", EXIT.refused);
9528
- const changed = context.store.setProjectNetwork(repo, next, acting.name, context.clock());
9529
- return succeed(context.write, context.json, command, { repo, before: changed.before, network: changed.after }, () => [
9617
+ const { changed, waiting } = context.store.transact(() => {
9618
+ const changed = context.store.setProjectNetwork(repo, next, acting.name, context.clock());
9619
+ return { changed, waiting: proposeNetworkChanges(context.store, repo, context.clock()) };
9620
+ });
9621
+ return succeed(context.write, context.json, command, { repo, before: changed.before, network: changed.after, waiting }, () => [
9530
9622
  ...words(changed.after),
9531
- "Scopes written from now on use this; scopes already approved keep the network they were approved with.",
9623
+ waiting === 0 ? "Scopes written from now on use this." : `${waiting === 1 ? "1 task waits" : `${waiting} tasks wait`} for your Approve to use it; a running task keeps the network it started with.`,
9532
9624
  ]);
9533
9625
  }
9534
9626
  async function projectWritesCommand(positional, flags, context) {
@@ -9711,6 +9803,8 @@ async function projectDeleteCommand(positional, flags, context) {
9711
9803
  return fail(context.write, context.json, command, "refused", "An instance operator deletes projects: pass --as and --token (or use the remembered login).", EXIT.refused);
9712
9804
  const holdings = projectHoldings(store, repo);
9713
9805
  const running = projectRunning(store, repo, context.clock());
9806
+ if (running.includes(PROJECT_RECOVERY_DELETE_MESSAGE))
9807
+ return fail(context.write, context.json, command, "recovery-held", PROJECT_RECOVERY_DELETE_MESSAGE, EXIT.refused);
9714
9808
  if (running.length > 0)
9715
9809
  return fail(context.write, context.json, command, "running", `Nothing was deleted: ${running.join(", ")}. Stop it, then try again.`, EXIT.refused);
9716
9810
  if (!flags.has("yes")) {
@@ -9721,21 +9815,25 @@ async function projectDeleteCommand(positional, flags, context) {
9721
9815
  }
9722
9816
  const done = await deleteProject(store, repo, { actor: acting.name, via: "command line", now: context.clock(), evidenceRoot: context.evidenceRoot ?? join(dirname(context.databaseFile), "evidence"), poolRoot: join(dirname(context.databaseFile), "worktrees") });
9723
9817
  if (!done.ok)
9724
- return fail(context.write, context.json, command, done.reason, done.said, done.reason === "running" ? EXIT.refused : EXIT.failed);
9818
+ return fail(context.write, context.json, command, done.reason, done.said, (done.reason === "running" || done.reason === "recovery-held") ? EXIT.refused : EXIT.failed);
9725
9819
  if (!("error" in registered) && registered.repos.includes(repo))
9726
9820
  await updateRepos(registryFile, repos => removeRepos(repos, [repo])).catch(() => undefined);
9727
9821
  return succeed(context.write, context.json, command, { repo, deleted: true, removed: done.removed, left: done.left, ledgerEntry: done.ledgerId }, () => [
9728
9822
  `Deleted ${repo}: ${holdingsWords(done.removed)}.`, ...done.left.map(one => `Git kept ${one}.`), `The ledger records it as entry #${done.ledgerId}.`,
9729
9823
  ]);
9730
9824
  }
9731
- function spendCommand(flags, context) {
9825
+ async function spendCommand(flags, context) {
9732
9826
  const command = "spend";
9733
9827
  for (const name of flags.keys())
9734
- if (!["month", "csv", "db", "json"].includes(name))
9828
+ if (!["month", "csv", "live", "db", "json"].includes(name))
9735
9829
  return fail(context.write, context.json, command, "usage", `--${name} is not a spend option.`, EXIT.usage);
9736
9830
  const month = text(flags, "month") === undefined ? monthOf(context.clock()) : monthNamed(text(flags, "month") ?? null);
9737
9831
  if (month === null)
9738
9832
  return fail(context.write, context.json, command, "usage", "Use spend --month YYYY-MM.", EXIT.usage);
9833
+ const refreshed = flags.has("live")
9834
+ ? await refreshSubscriptions(context.store, context.databaseFile, { forceClaude: true, forceGemini: true, now: context.clock() })
9835
+ : null;
9836
+ const gemini = refreshed?.gemini ?? readStoredGeminiStatus(context.databaseFile);
9739
9837
  const items = spendItems(context.store.handle, month.from, month.to);
9740
9838
  const names = subagentNames(context.store.handle);
9741
9839
  if (flags.has("csv")) {
@@ -9753,7 +9851,7 @@ function spendCommand(flags, context) {
9753
9851
  const windows = limitsView(limits, [], { project: repo => basename(repo), subagent: id => String(id) }, context.clock())?.tiles ?? [];
9754
9852
  const tiers = tierReport(context.store.handle, month.from, month.to, items);
9755
9853
  const suggestions = savingsReportOrError(context.store, context.store.knownRepos(), context.clock());
9756
- return succeed(context.write, context.json, command, { month: month.name, totalMicrousd: total, unpriced, items: items.length, budgets, limits, tiers: { rows: tiers.rows, saved: tiers.saved }, suggestions }, () => [
9854
+ return succeed(context.write, context.json, command, { month: month.name, totalMicrousd: total, unpriced, items: items.length, budgets, limits, ...(gemini !== null ? { gemini } : {}), tiers: { rows: tiers.rows, saved: tiers.saved }, suggestions }, () => [
9757
9855
  `${month.name}: ${spendUsd(total)} (${items.length} pieces of work${unpriced > 0 ? `, ${unpriced} unpriced` : ""}; subscription work is $0)`,
9758
9856
  ...windows.map(tile => ` ${`${tile.name} ${tile.window}`.padEnd(24)} ${tile.value}% · ${tile.detail}`),
9759
9857
  ...[...byProject.entries()].sort((a, b) => b[1] - a[1]).slice(0, 10).map(([repo, microusd]) => ` ${basename(repo).padEnd(24)} ${spendUsd(microusd)}`),
@@ -12979,6 +13077,9 @@ async function threadCommand(positional, flags, context) {
12979
13077
  return found.length === 1 ? found[0].id : null;
12980
13078
  };
12981
13079
  if (verb === "ship") {
13080
+ const needs = flexibleShipNeedsFor(store, positional[1] ?? "");
13081
+ if (needs !== null)
13082
+ return fail(write, json, command, needs.reason, needs.message, EXIT.refused);
12982
13083
  if (passwordFreeOwner(store))
12983
13084
  return fail(write, json, command, "laptop", "Nobody on this install has a password, so this thread ships from the workbench (`toolroll`), after its terms are read there.", EXIT.refused);
12984
13085
  const acting = await typedForCommand(flags, context, true);
@@ -13075,3 +13176,163 @@ export function shipOutcomeWord(ship) {
13075
13176
  const word = ship === "merged" ? "Merged" : ship === "sent-back" ? "sent back" : null;
13076
13177
  return word === null ? "" : ` · Ship: ${word}`;
13077
13178
  }
13179
+ class BuiltinReplacementRefused extends Error {
13180
+ reason;
13181
+ constructor(reason) {
13182
+ super(reason);
13183
+ this.reason = reason;
13184
+ }
13185
+ }
13186
+ function createBuiltinReplacement(store, input) {
13187
+ try {
13188
+ return store.transact(() => store.savepoint(() => {
13189
+ if (store.getTask(input.replaces) === null)
13190
+ return { ok: false, reason: "unknown-task" };
13191
+ const task = store.createTask({ id: input.id, title: input.title, ...(input.report ? { deliverable: "report" } : {}) }, input.now);
13192
+ const ref = store.refFor(BUILT_IN, task.id).id;
13193
+ store.stampFiledVia(ref, "cli");
13194
+ if (input.repo !== null) {
13195
+ const placed = store.placeTask(ref, canonicalProject(input.repo) ?? resolve(input.repo));
13196
+ if (typeof placed === "object" && !placed.ok)
13197
+ throw new BuiltinReplacementRefused("scoped");
13198
+ }
13199
+ const moved = store.setTaskState(input.replaces, "cancelled", input.now, {}, undefined, task.id);
13200
+ if (!moved.ok)
13201
+ throw new BuiltinReplacementRefused(moved.reason);
13202
+ return { ok: true, task };
13203
+ }));
13204
+ }
13205
+ catch (error) {
13206
+ if (error instanceof BuiltinReplacementRefused)
13207
+ return { ok: false, reason: error.reason };
13208
+ throw error;
13209
+ }
13210
+ }
13211
+ function builtinReplacementHeld(store, source, target) {
13212
+ if (store.handle.prepare("SELECT 1 FROM action_ledger WHERE action = ? LIMIT 1").get(CHECK_RECOVERY_HELD) === undefined)
13213
+ return false;
13214
+ for (const taskId of [source, target]) {
13215
+ const ref = store.lookupRef(taskId);
13216
+ if (ref === null ? store.getTask(taskId) !== null : readCheckRecoveryHoldsForTaskRef(store, ref.id).kind !== "no-evidence")
13217
+ return true;
13218
+ }
13219
+ return false;
13220
+ }
13221
+ async function finishFiledRequest(command, req, flags, context) {
13222
+ if (flags.get("wait") === true) {
13223
+ const timeoutSeconds = Number(text(flags, "timeout") ?? "300");
13224
+ const safeTimeout = Number.isFinite(timeoutSeconds) && timeoutSeconds > 0 ? Math.min(3600, Math.round(timeoutSeconds)) : 300;
13225
+ const settled = await waitForAgentRequest(context.databaseFile, req.id, safeTimeout);
13226
+ if (settled?.status === "approved") {
13227
+ return succeed(context.write, context.json, command, { requested: true, request: settled }, () => [
13228
+ `Approved (${settled.id}): ${settled.summary}`,
13229
+ ]);
13230
+ }
13231
+ const reason = settled?.status === "declined" ? "declined" : "timeout";
13232
+ const msg = settled?.status === "declined"
13233
+ ? `Request ${req.id} was declined${settled.resolutionNote ? `: ${settled.resolutionNote}` : "."}`
13234
+ : `Request ${req.id} is still pending in Toolroll.app after ${safeTimeout}s.`;
13235
+ return fail(context.write, context.json, command, reason, msg, EXIT.refused);
13236
+ }
13237
+ return succeed(context.write, context.json, command, { requested: true, request: req }, () => [
13238
+ `Requested (${req.id}): ${req.summary}`,
13239
+ `Project: ${req.repo}`,
13240
+ ...(req.why ? [`Why: ${req.why}`] : []),
13241
+ `Waiting for your 1-click approval in Toolroll.app (or run \`toolroll request wait ${req.id}\`).`,
13242
+ ]);
13243
+ }
13244
+ async function projectLiveViewCommand(positional, flags, context) {
13245
+ const command = "project live-view";
13246
+ const allowed = new Set(["repo", "request", "why", "by", "wait", "timeout", "db", "json"]);
13247
+ for (const name of flags.keys())
13248
+ if (!allowed.has(name))
13249
+ return fail(context.write, context.json, command, "usage", `--${name} is not a project live-view option.`, EXIT.usage);
13250
+ const repoFlag = text(flags, "repo");
13251
+ const wanted = positional[1];
13252
+ if (positional.length > 2 || repoFlag === undefined || (wanted !== undefined && wanted !== "on" && wanted !== "off")) {
13253
+ return fail(context.write, context.json, command, "usage", "Use project live-view --repo <project path> [on | off] [--request <why>].", EXIT.usage);
13254
+ }
13255
+ const repo = await knownProject(context, repoFlag, { listed: true, canonical: true });
13256
+ if (repo === undefined)
13257
+ return fail(context.write, context.json, command, "not-found", "That isn't a project Toolroll knows.", EXIT.refused);
13258
+ const current = liveCommandsShown(context.store, repo);
13259
+ if (wanted === undefined) {
13260
+ return succeed(context.write, context.json, command, { repo, showCommands: current }, () => [
13261
+ `${repo}: Live View shell commands are ${current ? "shown" : "hidden (redacted)"}.`,
13262
+ ]);
13263
+ }
13264
+ if (!flags.has("request")) {
13265
+ return fail(context.write, context.json, command, "refused", "Changing Live View shell commands takes operator approval in Toolroll.app → Project Settings, or pass --request \"<why>\" to ask for 1-click approval.", EXIT.refused);
13266
+ }
13267
+ const showCommands = wanted === "on";
13268
+ const req = fileAgentRequest(context.databaseFile, {
13269
+ kind: "live-view",
13270
+ repo,
13271
+ ...(text(flags, "by") === undefined ? {} : { requester: text(flags, "by") }),
13272
+ summary: showCommands ? "Show live shell commands in Activity" : "Hide live shell commands in Activity",
13273
+ why: text(flags, "why") ?? text(flags, "request") ?? "",
13274
+ params: { showCommands },
13275
+ }, context.clock());
13276
+ return finishFiledRequest(command, req, flags, context);
13277
+ }
13278
+ async function requestCommand(positional, flags, context) {
13279
+ const action = positional[0] ?? "list";
13280
+ const command = `request ${action}`;
13281
+ const allowed = new Set(["all", "repo", "timeout", "note", "db", "json"]);
13282
+ for (const name of flags.keys())
13283
+ if (!allowed.has(name))
13284
+ return fail(context.write, context.json, command, "usage", `--${name} is not a request option.`, EXIT.usage);
13285
+ if (action === "list") {
13286
+ const repoFlag = text(flags, "repo");
13287
+ const repo = repoFlag === undefined ? undefined : (await knownProject(context, repoFlag, { listed: true, canonical: true })) ?? resolve(repoFlag);
13288
+ const items = listAgentRequests(context.databaseFile, {
13289
+ ...(flags.has("all") ? {} : { status: "pending" }),
13290
+ ...(repo === undefined ? {} : { repo }),
13291
+ });
13292
+ return succeed(context.write, context.json, command, { requests: items }, () => items.length === 0
13293
+ ? ["No pending agent requests."]
13294
+ : items.map(one => `${one.id} [${one.status}] (${one.requester} · ${one.projectName}) ${one.summary}${one.why ? ` — ${one.why}` : ""}`));
13295
+ }
13296
+ if (action === "show") {
13297
+ const id = positional[1];
13298
+ if (id === undefined)
13299
+ return fail(context.write, context.json, command, "usage", "Use `toolroll request show <id>`.", EXIT.usage);
13300
+ const found = listAgentRequests(context.databaseFile).find(one => one.id === id) ?? null;
13301
+ if (found === null)
13302
+ return fail(context.write, context.json, command, "not-found", `No agent request ${id}.`, EXIT.refused);
13303
+ return succeed(context.write, context.json, command, { request: found }, () => [
13304
+ `${found.id} [${found.status}] ${found.summary}`,
13305
+ `Project: ${found.repo}`,
13306
+ `By: ${found.requester}`,
13307
+ ...(found.why ? [`Why: ${found.why}`] : []),
13308
+ ]);
13309
+ }
13310
+ if (action === "wait") {
13311
+ const id = positional[1];
13312
+ if (id === undefined)
13313
+ return fail(context.write, context.json, command, "usage", "Use `toolroll request wait <id> [--timeout <seconds>]`.", EXIT.usage);
13314
+ const timeoutSeconds = Number(text(flags, "timeout") ?? "300");
13315
+ const safeTimeout = Number.isFinite(timeoutSeconds) && timeoutSeconds > 0 ? Math.min(3600, Math.round(timeoutSeconds)) : 300;
13316
+ const settled = await waitForAgentRequest(context.databaseFile, id, safeTimeout);
13317
+ if (settled === null)
13318
+ return fail(context.write, context.json, command, "not-found", `No agent request ${id}.`, EXIT.refused);
13319
+ if (settled.status === "approved") {
13320
+ return succeed(context.write, context.json, command, { request: settled }, () => [`Approved (${settled.id}): ${settled.summary}`]);
13321
+ }
13322
+ return fail(context.write, context.json, command, settled.status === "declined" ? "declined" : "timeout", settled.status === "declined" ? `Request ${settled.id} was declined.` : `Request ${settled.id} is still pending after ${safeTimeout}s.`, EXIT.refused);
13323
+ }
13324
+ if (action === "decline") {
13325
+ const id = positional[1];
13326
+ if (id === undefined)
13327
+ return fail(context.write, context.json, command, "usage", "Use `toolroll request decline <id> [--note <reason>]`.", EXIT.usage);
13328
+ const resolved = resolveAgentRequest(context.databaseFile, id, "declined", text(flags, "note"), context.clock());
13329
+ if (resolved === null)
13330
+ return fail(context.write, context.json, command, "not-found", `No agent request ${id}.`, EXIT.refused);
13331
+ return succeed(context.write, context.json, command, { request: resolved }, () => [`Declined (${resolved.id}): ${resolved.summary}`]);
13332
+ }
13333
+ if (action === "clear") {
13334
+ const removed = clearResolvedAgentRequests(context.databaseFile);
13335
+ return succeed(context.write, context.json, command, { removed }, () => [`Cleared ${removed} resolved agent request${removed === 1 ? "" : "s"}.`]);
13336
+ }
13337
+ return fail(context.write, context.json, "request", "usage", "Use `toolroll request [list [--all]|show <id>|wait <id>|decline <id>|clear]`.", EXIT.usage);
13338
+ }
package/dist/policy.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { isAcpProfile } from "./acp-agents.js";
2
2
  export const PERMISSION_LEVELS = ["safe", "standard", "escalated"];
3
- export const POLICY_PROVIDERS = ["claude", "codex", "gemini", "openrouter", "opencode", "cursor", "cline", "qwen", "goose"];
3
+ export const POLICY_PROVIDERS = ["claude", "codex", "gemini", "openrouter", "opencode", "cursor", "cline", "qwen", "goose", "antigravity"];
4
4
  export const OPEN_POLICY = { providers: null, models: null, tools: null, ceiling: "escalated" };
5
5
  export const POLICY_SCHEMA = `
6
6
  CREATE TABLE IF NOT EXISTS org_policy (
@@ -44,7 +44,7 @@ export function readPolicy(db) {
44
44
  updatedAt: row["updated_at"] == null ? null : String(row["updated_at"]),
45
45
  };
46
46
  }
47
- export const PROVIDER_NAMES = { claude: "Claude", codex: "Codex", gemini: "Gemini", openrouter: "OpenRouter", opencode: "OpenCode", cursor: "Cursor", cline: "Cline", qwen: "Qwen Code", goose: "Goose" };
47
+ export const PROVIDER_NAMES = { claude: "Claude", codex: "Codex", gemini: "Gemini", openrouter: "OpenRouter", opencode: "OpenCode", cursor: "Cursor", cline: "Cline", qwen: "Qwen Code", goose: "Goose", antigravity: "Antigravity" };
48
48
  export const LEVEL_NAMES = { safe: "Safe", standard: "Standard", escalated: "Escalated" };
49
49
  export const LEVEL_HINTS = {
50
50
  safe: "Edits in the project only. Codex and OpenRouter can't run this low.",
@@ -3,7 +3,7 @@ import { entryMovesOnWords, entryWords } from "./fallback.js";
3
3
  import { sandboxRuntimeWords } from "./sandbox-runtime.js";
4
4
  import { CHECK_ACCESS_WARNINGS, signInHostsMissing } from "./check-access.js";
5
5
  import { html, joinHtml, postForm } from "./html.js";
6
- import { holdingsWords } from "./project-delete.js";
6
+ import { holdingsWords, PROJECT_RECOVERY_DELETE_MESSAGE } from "./project-delete.js";
7
7
  import { acts, btn, codeLine, disclose, formRow, infoLine, input, note, notice, radios, settingsSection, switchInput, textarea } from "./server/kit.js";
8
8
  import { kitSectionForm } from "./settings-kit.js";
9
9
  import { flexibleSettingsHtml } from "./flexible-ui.js";
@@ -105,14 +105,18 @@ function networkHtml(view) {
105
105
  const local = setting.loopback === "any"
106
106
  ? note("On a Mac, builds may reach this Mac's local services: test servers, and anything else listening here.")
107
107
  : note("On a Mac, builds reach no local services. A project whose tests start a local server needs them on.");
108
+ const codexNote = note("Codex's own command sandbox runs offline unless the network is Open with Full access; use Worktree setup to install dependencies before a Codex build starts.");
109
+ const asks = !network.canChange ? [] : (network.requests ?? []).map(one => html `<div data-agent-request="${one.id}" data-agent-request-digest="${one.digest}" data-agent-request-terms="${JSON.stringify({ id: one.id, repo: one.repo, change: one.change, before: one.before, after: one.after, digest: one.digest, words: one.words })}">\
110
+ <p class="k-note"><b>${one.requester} asks:</b> ${one.words.join(" · ")}</p>${one.why === "" ? "" : note(`Why: ${one.why}`)}${kitSectionForm({ proof: "project-network", action: "/settings/project/network", id: `network-request-${one.id}`,
111
+ hidden: { repo: one.repo, request: one.id, digest: one.digest }, save: { label: "Approve" }, body: "" })}</div>`);
108
112
  return settingsSection({ id: "network", title: "Network", state: setting.mode === "open" ? " · Open" : "", lead: reach,
109
- body: joinHtml([local, !network.canChange ? APPROVER_CHANGES : disclose("Change", kitSectionForm({ proof: "project-network", action: "/settings/project/network", id: "network-form", gate: true, hidden: { repo: view.repo },
113
+ body: joinHtml([...asks, local, codexNote, !network.canChange ? APPROVER_CHANGES : disclose("Change", kitSectionForm({ proof: "project-network", action: "/settings/project/network", id: "network-form", gate: true, hidden: { repo: view.repo },
110
114
  body: joinHtml([
111
115
  formRow("This Mac's local services", "Local test servers work, and so does anything else listening on this Mac (a local database, a dev proxy). Linux builds always have local services of their own.", switchInput({ id: "network-local", name: "local", label: "Allowed", on: setting.loopback === "any", attrs: { value: "any", "aria-label": "Builds may reach this Mac's local services" } }), "inline"),
112
116
  formRow("Other hosts builds may reach", "One per line.", textarea({ id: "network-hosts", name: "hosts", value: setting.hosts.join("\n"), rows: 3,
113
117
  attrs: { autocomplete: "off", autocapitalize: "off", spellcheck: "false", placeholder: "api.stripe.com\n*.example.com", "aria-label": "Other hosts builds may reach" } }), "top"),
114
118
  formRow("Open", "Builds may reach any host.", switchInput({ id: "network-open", name: "mode", label: "Open", on: setting.mode === "open", attrs: { value: "open", "aria-label": "Open: builds may reach any host" } }), "inline"),
115
- note("Tasks scoped from now on use this; tasks already approved keep the network they were approved with."),
119
+ note("Idle tasks in this project then wait for your Approve to use the change; a running task keeps its network."),
116
120
  ]) }))]) });
117
121
  }
118
122
  function fallbackHtml(view) {
@@ -192,7 +196,8 @@ function codeMapHtml(view) {
192
196
  ]) });
193
197
  }
194
198
  export function projectSettingsHtml(view, said) {
195
- const answer = said.problem ? notice(said.problem) : said.said ? infoLine(said.said) : "";
199
+ const recoveryShownBelow = view.canDelete && view.running.includes(PROJECT_RECOVERY_DELETE_MESSAGE) && said.problem === PROJECT_RECOVERY_DELETE_MESSAGE;
200
+ const answer = said.problem && !recoveryShownBelow ? notice(said.problem) : said.said ? infoLine(said.said) : "";
196
201
  const project = settingsSection({ id: "project", title: view.name, lead: mono(view.repo),
197
202
  body: joinHtml([
198
203
  note(`Toolroll holds ${holdingsWords(view.holdings)} for this project.`),
@@ -204,13 +209,15 @@ export function projectSettingsHtml(view, said) {
204
209
  writesHtml(view), sandboxHtml(view), checkAccessHtml(view), advanced || view.liveView?.commands === true ? liveViewHtml(view) : "", advanced ? codeMapHtml(view) : ""]);
205
210
  if (!view.canDelete)
206
211
  return joinHtml([answer, project, settings, note("An instance operator can remove or delete a project.")]);
207
- const deleteBody = view.running.length > 0
208
- ? notice(`Its work is running: ${view.running.join(", ")}. Stop it before deleting the project.`)
209
- : joinHtml([note(`Removes everything Toolroll holds for ${view.name}. The repository and its own branches stay. There's no undo.`),
210
- postForm("/settings/project/delete", joinHtml([
211
- formRow(`Type ${view.name} to continue`, null, input({ id: "delete-name", name: "name", attrs: { autocomplete: "off", autocapitalize: "off", spellcheck: "false", required: true, "aria-label": `Type ${view.name} to continue` } })),
212
- acts(btn("Continue", { sm: true, type: "submit", variant: "danger" })),
213
- ]), { hidden: { repo: view.repo } })]);
212
+ const deleteBody = view.running.includes(PROJECT_RECOVERY_DELETE_MESSAGE)
213
+ ? notice(PROJECT_RECOVERY_DELETE_MESSAGE)
214
+ : view.running.length > 0
215
+ ? notice(`Its work is running: ${view.running.join(", ")}. Stop it before deleting the project.`)
216
+ : joinHtml([note(`Removes everything Toolroll holds for ${view.name}. The repository and its own branches stay. There's no undo.`),
217
+ postForm("/settings/project/delete", joinHtml([
218
+ formRow(`Type ${view.name} to continue`, null, input({ id: "delete-name", name: "name", attrs: { autocomplete: "off", autocapitalize: "off", spellcheck: "false", required: true, "aria-label": `Type ${view.name} to continue` } })),
219
+ acts(btn("Continue", { sm: true, type: "submit", variant: "danger" })),
220
+ ]), { hidden: { repo: view.repo } })]);
214
221
  const leave = settingsSection({ id: "remove", title: "Remove or delete",
215
222
  body: joinHtml([
216
223
  formRow("Remove from Toolroll", "Its tasks and results stay saved. Add it again to bring it back.", postForm("/projects/remove", btn("Remove from Toolroll", { sm: true, type: "submit" }), { hidden: { repo: view.repo } }), "inline"),