toolroll 0.9.118 → 0.9.120

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 (75) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +22 -22
  3. package/dist/assignment.js +43 -30
  4. package/dist/browser/workspace.css +1 -1
  5. package/dist/browser/workspace.js +32 -31
  6. package/dist/builder.js +288 -237
  7. package/dist/central-recovery-stage.js +3 -3
  8. package/dist/check-failure.js +2 -2
  9. package/dist/check-levels.js +3 -0
  10. package/dist/check-report.js +58 -7
  11. package/dist/cli-help.js +1 -0
  12. package/dist/codex-limits.js +40 -22
  13. package/dist/contracts/console-api.js +6 -1
  14. package/dist/contracts/engine-api.js +1 -0
  15. package/dist/contracts/release-check.js +7 -4
  16. package/dist/contracts/release-terms.js +11 -2
  17. package/dist/contracts/verification-receipt.js +1 -1
  18. package/dist/deploy-gate.js +7 -1
  19. package/dist/direct-chat.js +3 -3
  20. package/dist/easy-start.js +8 -6
  21. package/dist/engine-reads.js +74 -0
  22. package/dist/flexible-conversation-schema.js +24 -0
  23. package/dist/flexible-conversation.js +162 -0
  24. package/dist/flexible-custody.js +3 -0
  25. package/dist/flexible-import.js +89 -0
  26. package/dist/flexible-save.js +128 -0
  27. package/dist/flexible-session.js +93 -13
  28. package/dist/flexible-ship.js +3 -3
  29. package/dist/flexible-thread.js +2 -2
  30. package/dist/install-mode.js +1 -1
  31. package/dist/local-checks.js +32 -0
  32. package/dist/local-landing.js +758 -0
  33. package/dist/local-owner.js +3 -0
  34. package/dist/operate.js +165 -26
  35. package/dist/passwordless.js +1 -1
  36. package/dist/plan-limits-demand.js +48 -0
  37. package/dist/project-delete.js +1 -0
  38. package/dist/rehearsal.js +27 -0
  39. package/dist/release-adapters.js +170 -2
  40. package/dist/release-approval.js +11 -8
  41. package/dist/release-card.js +7 -2
  42. package/dist/release-carry.js +1 -1
  43. package/dist/release-cli.js +115 -14
  44. package/dist/release-main-proof.js +49 -0
  45. package/dist/release-main.js +110 -0
  46. package/dist/release-recheck.js +10 -3
  47. package/dist/release.js +221 -33
  48. package/dist/reply-shape.js +6 -1
  49. package/dist/result-actions.js +7 -1
  50. package/dist/result-follow-ups.js +30 -12
  51. package/dist/review-context.js +2 -1
  52. package/dist/serve.js +31 -14
  53. package/dist/server/direct-chat.js +109 -3
  54. package/dist/server/engine-api.js +65 -6
  55. package/dist/server/render-results.js +8 -4
  56. package/dist/server/render-tasks.js +10 -1
  57. package/dist/server/route-table.js +15 -1
  58. package/dist/server/send-back-build.js +4 -0
  59. package/dist/server/settings.js +33 -7
  60. package/dist/server/task-views.js +20 -0
  61. package/dist/server/tasks.js +108 -6
  62. package/dist/settings-groups-ui.js +3 -3
  63. package/dist/store.js +29 -4
  64. package/dist/subscription-usage.js +11 -5
  65. package/dist/surface.js +11 -2
  66. package/dist/task-base.js +23 -4
  67. package/dist/task-outcome-cli.js +10 -1
  68. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  69. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  70. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  71. package/dist/tui/linux-x64/toolroll-tui +0 -0
  72. package/dist/verification-evidence.js +20 -7
  73. package/dist/workspace-ui.js +1 -1
  74. package/package.json +2 -1
  75. package/scripts/release-proof.mjs +240 -0
@@ -6,9 +6,9 @@ import { openStore } from "./store.js";
6
6
  import { holdAutoPublish, autoPublishHeld, PUBLISH_ALLOWED_ACTION, PUBLISH_HELD_ACTION } from "./release-auto.js";
7
7
  import { revokeCoordinator } from "./coordinator.js";
8
8
  export const MAX_STAGE_BYTES = 128 * 1024 * 1024;
9
- const SUPPORTED_SCHEMA = 184;
10
- const SCHEMA_OBJECT_COUNT = 724;
11
- const SCHEMA_DIGEST = "e56d12d9ce4f612ab6de397055ca9aeb233d939c001446fd90b7b3ebbcc5a62c";
9
+ const SUPPORTED_SCHEMA = 185;
10
+ const SCHEMA_OBJECT_COUNT = 726;
11
+ const SCHEMA_DIGEST = "8e589635cf648eef4a4c85fb12c614b3c004d983df639ccd2bf95b3005bf5791";
12
12
  const INVENTORY = [
13
13
  ["person-credentials", "store.ts:revokeApiToken", "credential", true],
14
14
  ["lead-credentials", "store.ts:revokeLeadCredentials", "credential", true],
@@ -4,7 +4,7 @@ import { busyMachineTimeout, CHECK_LOAD_CAPTURE, readCheckLoad } from "./check-l
4
4
  import { regateTask } from "./dispose.js";
5
5
  import { INFRA_RERUNS_PER_CANDIDATE, INFRA_RERUNS_PER_INCIDENT } from "./release.js";
6
6
  import { releaseCheckScope } from "./scope.js";
7
- import { isVerificationReceipt, verificationEvidence } from "./verification-evidence.js";
7
+ import { coveragePasses, isVerificationReceipt, verificationEvidence } from "./verification-evidence.js";
8
8
  import { checkAttemptOf } from "./store.js";
9
9
  import { endedInterrupted } from "./run-ending.js";
10
10
  export { INFRA_RERUNS_PER_CANDIDATE, INFRA_RERUNS_PER_INCIDENT };
@@ -18,7 +18,7 @@ const PLANE_INFRA = {
18
18
  const busyWords = (why) => `${why}: Toolroll's own machine, so this commit's check runs again`;
19
19
  export function classifyCheckFailure(facts, report, load = null) {
20
20
  const result = facts.result;
21
- const passedCoverage = facts.coverage === undefined || facts.coverage === "full" || facts.coverage === "composed";
21
+ const passedCoverage = coveragePasses(facts.coverage);
22
22
  if (result.configured && result.ran === true && result.exitCode === 0 && passedCoverage)
23
23
  return null;
24
24
  if (!result.configured)
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
+ import { folderAnswers } from "./folder-gate.js";
3
4
  import { approvalOf } from "./scope.js";
4
5
  export const CHECK_LEVELS = ["quick", "full", "off"];
5
6
  export const isCheckLevel = (value) => typeof value === "string" && CHECK_LEVELS.includes(value);
@@ -107,6 +108,8 @@ export function runCheckLevel(store, runId) {
107
108
  return row !== null && isCheckLevel(row.outcome) ? row.outcome : null;
108
109
  }
109
110
  export function suggestQuickCommand(repo) {
111
+ if (!folderAnswers(repo))
112
+ return null;
110
113
  const file = join(repo, "package.json");
111
114
  if (!existsSync(file))
112
115
  return null;
@@ -2,7 +2,7 @@ import { createHash, randomBytes } from "node:crypto";
2
2
  import { lstatSync, realpathSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { readVerifiedCommit, verifiedBlobs, verifiedTreeEntries } from "./commit-extract.js";
5
- import { CHECK_PARTS, CHECK_REPORT_MAX_BYTES, CHECK_REPORT_PREFIX, learnRequest, readCheckReport, } from "./contracts/release-check.js";
5
+ import { CHECK_PARTS, CHECK_REPORT_MAX_BYTES, CHECK_REPORT_PREFIX, DEPLOY_PART, learnRequest, readCheckReport, } from "./contracts/release-check.js";
6
6
  import { readVerifiedArtifact, storeEvidence } from "./evidence.js";
7
7
  import { releaseBaselineRecord } from "./release-card.js";
8
8
  import { checkAttemptOf, recordCheckAttempt } from "./store.js";
@@ -130,25 +130,30 @@ export function prepareCheckAttempt(store, root, input, now) {
130
130
  }
131
131
  baseFacts = baseRead.facts;
132
132
  }
133
- const owed = fullObligationsOf(read.facts, baseFacts, baseFacts === null ? [] : versionBumpsOf(gitDir, baseFacts, read.facts));
133
+ const fullOwed = fullObligationsOf(read.facts, baseFacts, baseFacts === null ? [] : versionBumpsOf(gitDir, baseFacts, read.facts));
134
+ const deploy = input.deploy ?? null;
135
+ if (deploy !== null && plan !== null)
136
+ throw new Error("A deploy check runs no targeted plan.");
137
+ const owed = deploy === null ? fullOwed : ["build", DEPLOY_PART, ...(fullOwed.includes("upgrade") ? ["upgrade"] : [])];
134
138
  const release = input.release !== false;
135
139
  const ciSubstitute = !release;
136
- const inventory = inventoryOf(read.facts, plan, { owed, release });
140
+ const inventory = deploy === null ? inventoryOf(read.facts, plan, { owed: fullOwed, release }) : { version: 1, units: [], parts: owed, ciSubstitute: false, release: true, deploy: true };
137
141
  const context = checkContextOf(read.facts, input.command, input.access);
138
142
  const nonce = randomBytes(32).toString("hex");
139
- const mode = plan === null ? "full" : "targeted";
143
+ const mode = deploy !== null ? "deploy" : plan === null ? "full" : "targeted";
140
144
  sealJson(store, root, input.runId, "check-context.json", context, CHECK_CONTEXT_CAPTURE, now);
141
145
  if (plan !== null)
142
146
  sealJson(store, root, input.runId, "targeted-plan.json", plan, TARGETED_PLAN_CAPTURE, now);
143
147
  if (snapshot !== null)
144
148
  sealJson(store, root, input.runId, "obligation-snapshot.json", snapshot, OBLIGATION_SNAPSHOT_CAPTURE, now);
145
149
  recordCheckAttempt(store, {
146
- run: input.runId, authority: input.authority ?? null, mode, baseRun: plan?.base ?? null,
150
+ run: input.runId, authority: input.authority ?? null, mode: mode === "deploy" ? "full" : mode, baseRun: plan?.base ?? null,
147
151
  planDigest: plan === null ? null : payloadDigest(plan), snapshotDigest: snapshot === null ? null : payloadDigest(snapshot),
148
152
  inventoryDigest: payloadDigest(inventory), contextDigest: payloadDigest(context), nonceHash: sha256(nonce),
149
153
  }, now);
150
154
  const learn = learnRequest(input.learn ?? []);
151
- const stdin = JSON.stringify({ nonce, mode, plan, watch: [...(input.watch ?? [])], limitMs: Number.isSafeInteger(input.limitMs) && input.limitMs >= input.command.timeoutMs ? input.limitMs : input.command.timeoutMs, reportBytes: CHECK_ARTIFACT_CAP, ...(plan === null ? { owed, ciSubstitute } : {}), ...(learn.length > 0 ? { learn } : {}) });
155
+ const stdin = JSON.stringify({ nonce, mode, plan, watch: [...(input.watch ?? [])], limitMs: Number.isSafeInteger(input.limitMs) && input.limitMs >= input.command.timeoutMs ? input.limitMs : input.command.timeoutMs, reportBytes: CHECK_ARTIFACT_CAP, ...(plan === null ? { owed, ciSubstitute } : {}), ...(learn.length > 0 && deploy === null ? { learn } : {}),
156
+ ...(deploy === null ? {} : { copy: deploy.copy }) });
152
157
  return { runId: input.runId, nonce, stdin, mode, inventory, context, plan, snapshot, watch: [...(input.watch ?? [])], learn };
153
158
  }
154
159
  export function sealJson(store, root, runId, name, value, capture, now) {
@@ -213,6 +218,50 @@ export function readSealedJson(store, root, runId, capture) {
213
218
  return null;
214
219
  }
215
220
  }
221
+ export function deployCheckProblem(input) {
222
+ const { report, inventory, exitCode } = input;
223
+ if (exitCode === null)
224
+ return "the deploy check didn't end on its own (it timed out or was stopped), so it has no result";
225
+ if (report === null)
226
+ return "the deploy check gave no valid report for this run";
227
+ if (report.mode !== "deploy")
228
+ return `the check reported a ${report.mode} run, not the deploy check it was asked for`;
229
+ if (report.exitCode !== exitCode)
230
+ return `the check's report says exit ${report.exitCode}, but it exited ${exitCode}`;
231
+ if (inventory === null)
232
+ return "the check's sealed inventory can't be read";
233
+ if (inventory.sealed.deploy !== true || inventory.sealed.release !== true)
234
+ return "the check wasn't sealed as a deploy check before it ran";
235
+ if (exitCode !== 0)
236
+ return null;
237
+ const parts = new Map(report.parts.map(one => [one.part, one]));
238
+ if (parts.size !== report.parts.length)
239
+ return "the report names a part twice";
240
+ const owed = new Set(["build", DEPLOY_PART, ...inventory.sealed.parts]);
241
+ for (const part of owed) {
242
+ const one = parts.get(part);
243
+ if (one === undefined || one.selected !== true)
244
+ return `the deploy check owed the ${part}, and the report doesn't say it ran`;
245
+ }
246
+ for (const part of report.parts) {
247
+ if (!part.selected)
248
+ continue;
249
+ if (!part.ran || part.code === null)
250
+ return `${part.part} has no result: it was selected and never ran`;
251
+ if (part.timedOut || part.stopped === true || part.signal != null)
252
+ return `${part.part} has no result: it was stopped before it finished`;
253
+ if (part.code !== 0)
254
+ return `${part.part} exited ${part.code}, yet the check exited 0`;
255
+ }
256
+ if (owed.has("upgrade")) {
257
+ const upgrades = report.upgrades;
258
+ if (upgrades === null || !upgrades.finished || upgrades.inventoried !== true)
259
+ return "the upgrade path has no complete result";
260
+ if (upgrades.versions.length === 0 || upgrades.versions.some(one => one.state !== "passed"))
261
+ return "the upgrade path didn't pass every version it listed";
262
+ }
263
+ return null;
264
+ }
216
265
  export function fullCheckProblem(input) {
217
266
  const { report, inventory, exitCode } = input;
218
267
  if (exitCode === null)
@@ -232,7 +281,9 @@ export function fullCheckProblem(input) {
232
281
  const parts = new Map(report.parts.map(one => [one.part, one]));
233
282
  if (parts.size !== report.parts.length || CHECK_PARTS.some(part => !parts.has(part)))
234
283
  return "the report doesn't account for every part of the check exactly once";
235
- const owed = new Set(["typecheck", "build", ...inventory.sealed.parts]);
284
+ if (inventory.sealed.deploy === true)
285
+ return "the check was sealed as a deploy check, not a full one";
286
+ const owed = new Set(["typecheck", "build", ...inventory.sealed.parts.filter((part) => CHECK_PARTS.includes(part))]);
236
287
  for (const part of CHECK_PARTS)
237
288
  if (owed.has(part) && parts.get(part).selected !== true)
238
289
  return `the report says the ${part} wasn't selected, but the check owed it`;
package/dist/cli-help.js CHANGED
@@ -98,6 +98,7 @@ Tasks (\`toolroll task --help\` lists every task command)
98
98
  the yes — nothing builds without one
99
99
  toolroll task accept <id> --finish
100
100
  accept the result you read (--despite "<why>": accept it with a reason, without finishing)
101
+ toolroll task land <id> put accepted work on your branch as one commit (no pull requests)
101
102
  toolroll task send-back <id> --feedback "<what to change>"
102
103
  send the result back for changes
103
104
  toolroll task retry <id> build it again
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
3
3
  import { codingEnvironment } from "./coding-provider.js";
4
4
  import { codexLimitsOf, record } from "./provider-limits.js";
5
5
  import { refreshSubscriptions } from "./subscription-usage.js";
6
+ import { directChatRunning, onPlanLimitsViewed, planLimitsWanted } from "./plan-limits-demand.js";
6
7
  import { billingOf } from "./spend.js";
7
8
  import { envValue } from "./names.js";
8
9
  function accountBilling(account) {
@@ -103,28 +104,7 @@ export function readCodexLimits(options = {}) {
103
104
  export function startCodexLimits(store, signedIn, everyMs = 5 * 60_000) {
104
105
  if (process.env["VITEST"] !== undefined || envValue(process.env, "NO_PLAN_PROBE") !== undefined || store.isDemo())
105
106
  return () => { };
106
- let stopped = false, busy = false;
107
- const pass = async () => {
108
- if (stopped || busy)
109
- return;
110
- busy = true;
111
- try {
112
- await codexLimitsPass(store, { signedIn, stopped: () => stopped });
113
- if (!stopped) {
114
- await refreshSubscriptions(store, store.databaseFile(), { skipCodex: true });
115
- }
116
- }
117
- catch {
118
- }
119
- finally {
120
- busy = false;
121
- }
122
- };
123
- const timer = setInterval(() => void pass(), everyMs);
124
- timer.unref?.();
125
- const first = setTimeout(() => void pass(), 10_000);
126
- first.unref?.();
127
- return () => { stopped = true; clearInterval(timer); clearTimeout(first); };
107
+ return scheduleLimitsLoop(store, { signedIn }, everyMs);
128
108
  }
129
109
  export async function codexLimitsPass(store, seams) {
130
110
  if (billingOf("codex") !== "subscription")
@@ -132,8 +112,12 @@ export async function codexLimitsPass(store, seams) {
132
112
  const recent = new Date(Date.now() - 6 * 3_600_000).toISOString();
133
113
  if (store.handle.prepare("SELECT 1 AS live FROM run WHERE provider = 'codex' AND outcome IS NULL AND started_at > ? LIMIT 1").get(recent) !== undefined)
134
114
  return "skipped";
115
+ if (directChatRunning(store, "codex", new Date()))
116
+ return "skipped";
135
117
  if (!(await seams.signedIn()))
136
118
  return "skipped";
119
+ if (seams.stillWanted?.() === false)
120
+ return "skipped";
137
121
  const reading = await (seams.read ?? (() => readCodexLimits()))();
138
122
  if (reading !== null && seams.stopped?.() !== true)
139
123
  store.recordProviderLimits(reading, new Date());
@@ -144,3 +128,37 @@ export async function codexSignedInNow(check) {
144
128
  return false;
145
129
  return (await check("codex", true)).state === "connected";
146
130
  }
131
+ const VIEWED_PASS_GAP_MS = 60_000;
132
+ export function scheduleLimitsLoop(store, seams, everyMs = 5 * 60_000) {
133
+ const clock = seams.clock ?? (() => new Date());
134
+ let stopped = false, busy = false, lastPass = -Infinity;
135
+ const pass = async (viewed) => {
136
+ if (stopped || busy)
137
+ return;
138
+ const now = clock();
139
+ if (!planLimitsWanted(store, now))
140
+ return;
141
+ if (viewed && now.getTime() - lastPass < VIEWED_PASS_GAP_MS)
142
+ return;
143
+ busy = true;
144
+ lastPass = now.getTime();
145
+ try {
146
+ const stillWanted = () => !stopped && planLimitsWanted(store, clock());
147
+ await codexLimitsPass(store, { signedIn: seams.signedIn, stopped: () => stopped, stillWanted, ...(seams.readCodex === undefined ? {} : { read: seams.readCodex }) });
148
+ if (stillWanted()) {
149
+ await refreshSubscriptions(store, store.databaseFile(), { skipCodex: true, now: clock(), stillWanted, ...(seams.readers === undefined ? {} : { readers: seams.readers }) });
150
+ }
151
+ }
152
+ catch {
153
+ }
154
+ finally {
155
+ busy = false;
156
+ }
157
+ };
158
+ const timer = setInterval(() => void pass(false), everyMs);
159
+ timer.unref?.();
160
+ const first = setTimeout(() => void pass(false), 10_000);
161
+ first.unref?.();
162
+ const stopListening = onPlanLimitsViewed(store, () => void pass(true));
163
+ return () => { stopped = true; clearInterval(timer); clearTimeout(first); stopListening(); };
164
+ }
@@ -62,6 +62,7 @@ export const CONSOLE_FORMS = {
62
62
  threadTurn: formContract("POST /agents/live/thread/<id>/turn", ["message", "key", "password"]),
63
63
  threadShip: formContract("POST /agents/live/thread/<id>/ship", ["terms", "digest"]),
64
64
  threadSendBack: formContract("POST /agents/live/thread/<id>/ship/send-back", ["feedback", "key", "password"]),
65
+ threadSave: formContract("POST /agents/live/thread/<id>/save", []),
65
66
  threadClose: formContract("POST /agents/live/thread/<id>/stop, /agents/live/thread/<id>/end, /agents/live/thread/<id>/ship/cancel", []),
66
67
  term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password", "task", "run"]),
67
68
  termAgent: formContract("POST /term/agent/sign-in, /term/agent/install", ["agent", "password", "confirm"]),
@@ -178,7 +179,7 @@ export const CONSOLE_FORMS = {
178
179
  chatAck: formContract("POST /chat/ack/<id>", ["token", "nonce"]),
179
180
  recipes: formContract("POST /recipes/prepare, /recipes/preview, /recipes/import, /recipes/launch, /recipes/save", ["repo", "projectRevision", "recipe", "recipeRevision", "document", "purpose", "source", "sourceRevision", "preview", "next"]),
180
181
  runNote: formContract("POST /r/<run>/note", ["note"]),
181
- diffComment: formContract("POST /r/<run>/comment", ["return", "tab", "intent", "batch", "source", "context", "note", "path", "line", "request", "image", "comment"]),
182
+ diffComment: formContract("POST /r/<run>/comment", ["return", "tab", "intent", "batch", "source", "context", "note", "path", "line", "request", "image", "comment", "approve"]),
182
183
  editorLinks: formContract("POST /session/editor-links", ["on", "return"]),
183
184
  revise: formContract("POST /r/<run>/revise", ["return", "batch", "source"]),
184
185
  followUp: formContract("POST /r/<run>/checks|add-tests", ["return", "level"]),
@@ -205,6 +206,7 @@ export const CONSOLE_FORMS = {
205
206
  taskApprove: formContract("POST /t/<task>/approve", ["return", "digest", "token", "nonce", "rebuild", "sheet"]),
206
207
  taskAcceptProof: formContract("POST /t/<task>/accept-proof", ["run", "note", "return"]),
207
208
  taskComplete: formContract("POST /t/<task>/complete", ["receipt", "run", "accept", "note", "publish", "return"]),
209
+ taskLand: formContract("POST /t/<task>/land", ["key", "into", "undo"]),
208
210
  taskStop: formContract("POST /t/<task>/stop", ["run", "return"]),
209
211
  taskPause: formContract("POST /t/<task>/pause", ["run", "request", "note", "mode", "return", "key"]),
210
212
  taskResume: formContract("POST /t/<task>/resume|resume-arm", ["run", "token", "nonce", "return"]),
@@ -216,6 +218,9 @@ export const CONSOLE_FORMS = {
216
218
  directChatShipPreview: formContract("POST /engine/direct-chats/<id>/ship-preview", ["mode", "title", "goal"]),
217
219
  directChatShip: formContract("POST /engine/direct-chats/<id>/ship", ["mode", "title", "goal", "termsDigest", "password"]),
218
220
  directChatShipCancel: formContract("POST /engine/direct-chats/<id>/ship-cancel", ["shipId"]),
221
+ directChatPageShipReview: formContract("POST /direct-chats/<id>/ship-review", []),
222
+ directChatPageShip: formContract("POST /direct-chats/<id>/ship", ["mode", "termsDigest", "title", "goal", "password"]),
223
+ directChatPageReply: formContract("POST /direct-chats/<id>/reply", ["prompt", "request"]),
219
224
  };
220
225
  export const BODILESS_POSTS = [
221
226
  "POST /settings/models/<unknown action>",
@@ -9,6 +9,7 @@ const liveRecordSchema = z.union([
9
9
  z.object({ k: z.literal("open"), at: iso, detail: z.enum(["base", "commands"]), s: z.number().int().optional() }),
10
10
  z.object({ k: z.literal("start"), at: iso, s: z.number().int().optional() }),
11
11
  z.object({ k: z.literal("say"), at: iso, t: z.array(z.string()), s: z.number().int().optional() }),
12
+ z.object({ k: z.literal("you"), at: iso, t: z.array(z.string()) }),
12
13
  z.object({ k: z.literal("step"), at: iso, id: z.string(), kind: z.string(), target: z.string().optional(), once: z.literal(true).optional(), s: z.number().int().optional() }),
13
14
  z.object({ k: z.literal("done"), at: iso, id: z.string(), ok: z.boolean().nullable(), out: z.array(z.string()).optional(), s: z.number().int().optional() }),
14
15
  z.object({ k: z.literal("cut"), at: iso, s: z.number().int().optional() }),
@@ -1,6 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import { readVersioned, versioned } from "./contract.js";
3
3
  export const CHECK_PARTS = ["typecheck", "build", "unit", "flows", "app", "flows-real", "app-real", "upgrade"];
4
+ export const DEPLOY_PART = "rehearsal";
5
+ export const REPORT_PARTS = [...CHECK_PARTS, DEPLOY_PART];
4
6
  export const JOURNEY_SCRIPTS = ["app", "flows"];
5
7
  const hex64 = z.string().regex(/^[0-9a-f]{64}$/);
6
8
  const repoPath = z.string().min(1).max(512).regex(/^(?!\/)(?!.*(?:^|\/)\.\.?(?:\/|$))[^\u0000-\u001f\\]+$/);
@@ -12,11 +14,11 @@ export const CHECK_REPORT_PREFIX = "TOOLROLL_CHECK_REPORT ";
12
14
  export const CHECK_REPORT_MAX_BYTES = 256 * 1024;
13
15
  export const checkReportSchema = versioned(1, {
14
16
  nonce: hex64,
15
- mode: z.enum(["full", "targeted"]),
17
+ mode: z.enum(["full", "targeted", "deploy"]),
16
18
  planDigest: hex64.nullable(),
17
19
  exitCode: z.int().min(0).max(255),
18
20
  parts: z.array(z.strictObject({
19
- part: z.enum(CHECK_PARTS),
21
+ part: z.enum(REPORT_PARTS),
20
22
  selected: z.boolean(),
21
23
  ran: z.boolean(),
22
24
  code: z.int().min(0).max(255).nullable(),
@@ -25,7 +27,7 @@ export const checkReportSchema = versioned(1, {
25
27
  signal: z.string().max(20).nullable().optional(),
26
28
  stopped: z.boolean().optional(),
27
29
  spawnFailed: z.boolean().optional(),
28
- })).max(CHECK_PARTS.length),
30
+ })).max(REPORT_PARTS.length),
29
31
  units: z.strictObject({
30
32
  reusedFromCI: z.boolean(),
31
33
  finished: z.boolean(),
@@ -67,9 +69,10 @@ export function readCheckReport(input) {
67
69
  }
68
70
  export const checkInventorySchema = versioned(1, {
69
71
  units: z.array(repoPath).max(20_000),
70
- parts: z.array(z.enum(CHECK_PARTS)).max(CHECK_PARTS.length),
72
+ parts: z.array(z.enum(REPORT_PARTS)).max(REPORT_PARTS.length),
71
73
  ciSubstitute: z.boolean().optional(),
72
74
  release: z.boolean().optional(),
75
+ deploy: z.literal(true).optional(),
73
76
  });
74
77
  export const sealedInventorySchema = versioned(1, {
75
78
  sealed: checkInventorySchema,
@@ -56,7 +56,8 @@ export function storedReleaseTerms(raw) {
56
56
  return { ok: true, terms: read.value };
57
57
  }
58
58
  export const releaseCheckPurposeSchema = versioned(1, {
59
- purpose: z.literal("release-check"),
59
+ purpose: z.enum(["release-check", "main-release"]),
60
+ check: z.enum(["deploy", "full"]).optional(),
60
61
  repo: z.string().min(1).max(4096),
61
62
  packageVersion: z.string().regex(/^\d+\.\d+\.\d+$/),
62
63
  branch: z.string().min(1).max(255).regex(/^[A-Za-z0-9._/-]+$/),
@@ -68,7 +69,15 @@ export const releaseCheckPurposeSchema = versioned(1, {
68
69
  access: z.enum(["sandboxed", "sign-ins", "unsandboxed"]),
69
70
  });
70
71
  export function readReleaseCheckPurpose(input) {
71
- return readVersioned(releaseCheckPurposeSchema, input);
72
+ const read = readVersioned(releaseCheckPurposeSchema, input);
73
+ if (read.ok && (read.value.purpose === "main-release") !== (read.value.check !== undefined))
74
+ return { ok: false, issues: [{ path: "check", kind: "invalid", line: "check: only a main release names its check, and it always does" }] };
75
+ return read;
76
+ }
77
+ export function purposeCheckMode(purpose) {
78
+ if (purpose == null)
79
+ return null;
80
+ return purpose.purpose === "main-release" && purpose.check === "deploy" ? "deploy" : "full";
72
81
  }
73
82
  export function releaseCheckPurposeDigest(purpose) {
74
83
  return createHash("sha256").update(`release-check-purpose:${JSON.stringify(purpose)}`).digest("hex");
@@ -48,7 +48,7 @@ export const receiptLogSchema = z.strictObject({
48
48
  captureStatus: z.enum(["ok", "failed"]).nullable(),
49
49
  });
50
50
  export const RECEIPT_VERSION = 3;
51
- export const RECEIPT_COVERAGES = ["full", "composed", "partial", "identity-removed", "no-result"];
51
+ export const RECEIPT_COVERAGES = ["full", "composed", "partial", "identity-removed", "no-result", "deploy"];
52
52
  const receiptFields = {
53
53
  run: z.int(),
54
54
  head: z.string(),
@@ -4,6 +4,7 @@ import { verificationEvidence } from "./verification-evidence.js";
4
4
  import { refArchived } from "./task-archive.js";
5
5
  import { releaseCiRunningOf } from "./release-ci-hold.js";
6
6
  import { nightlyDebtHold } from "./nightly-github.js";
7
+ import { mainReleaseProofProblem } from "./release-main-proof.js";
7
8
  export function deploymentGate(store, input) {
8
9
  const refuse = (message) => ({ ok: false, message });
9
10
  const run = store.getRun(input.runId);
@@ -48,8 +49,13 @@ export function deploymentGate(store, input) {
48
49
  }
49
50
  const live = ref.repo === null ? null : store.liveVerifyCommand(ref.repo);
50
51
  const result = gate["result"];
51
- if (gate["coverage"] !== undefined && gate["coverage"] !== "full" && gate["coverage"] !== "composed")
52
+ if (gate["coverage"] !== undefined && gate["coverage"] !== "full" && gate["coverage"] !== "composed" && gate["coverage"] !== "deploy")
52
53
  return refuse(`The release check didn't cover this candidate (${String(gate["coverage"])}).`);
54
+ if (gate["coverage"] === "deploy") {
55
+ const problem = mainReleaseProofProblem(store, ref.externalId, scope, input.now);
56
+ if (problem !== null)
57
+ return refuse(`This candidate passed only the deploy check, which deploys a release from main alone: ${problem}.`);
58
+ }
53
59
  const command = gate["command"];
54
60
  if (gate["run"] !== input.runId || gate["head"] !== head || gate["scopeDigest"] !== scope.digest || result?.ran !== true || result.exitCode !== 0
55
61
  || live === null || command?.command !== live.command)
@@ -907,8 +907,8 @@ export class DirectChatHost {
907
907
  if (finalStatus === "completed") {
908
908
  const changed = diff?.changedFiles.length ?? 0;
909
909
  const diffPart = changed > 0
910
- ? `${changed} ${changed === 1 ? "file" : "files"} changed — ready to review or ship.`
911
- : "no file changes yet.";
910
+ ? `${changed} ${changed === 1 ? "file" : "files"} changed. [Review it](/direct-chats/${thread.id})`
911
+ : `no file changes yet. [Open it](/direct-chats/${thread.id})`;
912
912
  const snippet = sanitizeLine(assistantText).slice(0, 160);
913
913
  text = snippet !== ""
914
914
  ? `Direct Chat finished — "${title}" (${providerLabel}, ${proj}): ${diffPart}\n${snippet}${assistantText.trim().length > 160 ? "…" : ""}`
@@ -916,7 +916,7 @@ export class DirectChatHost {
916
916
  }
917
917
  else {
918
918
  const reason = sanitizeLine(errorText ?? "Ended without completing.").slice(0, 180);
919
- text = `Direct Chat ${finalStatus} — "${title}" (${providerLabel}, ${proj}): ${reason}`;
919
+ text = `Direct Chat ${finalStatus} — "${title}" (${providerLabel}, ${proj}): ${reason} [Open it](/direct-chats/${thread.id})`;
920
920
  }
921
921
  this.store.appendLeadMessage({ thread: leadThreadId, turn: null, role: "assistant", text, activity: null }, now);
922
922
  }
@@ -226,8 +226,7 @@ export async function runEasyStart(mode, args, seams) {
226
226
  write(died);
227
227
  return EXIT.failed;
228
228
  }
229
- const child = ownedNow();
230
- if (child !== null) {
229
+ if (ownedNow() !== null) {
231
230
  if (exit === "keep") {
232
231
  const said = await handoff();
233
232
  write(said);
@@ -236,10 +235,13 @@ export async function runEasyStart(mode, args, seams) {
236
235
  return EXIT.ok;
237
236
  }
238
237
  }
239
- write("Stopping Toolroll… (running work is saved)");
240
- stopOwned(child);
241
- await child.exited;
242
- write("Toolroll stopped.");
238
+ const child = ownedNow();
239
+ if (child !== null) {
240
+ write("Stopping Toolroll… (running work is saved)");
241
+ stopOwned(child);
242
+ await child.exited;
243
+ write("Toolroll stopped.");
244
+ }
243
245
  }
244
246
  write("Reopen with: toolroll");
245
247
  return EXIT.ok;
@@ -17,6 +17,8 @@ import { DIFF_CONTEXT_MAX, ENGINE_API_VERSION } from "./contracts/engine-api.js"
17
17
  import { agentSetupOf, detectionLines, NO_AGENT_YET, npmRegistryOf } from "./agent-detect.js";
18
18
  import { readVerifiedArtifact, reportShotsOf, scanPatchForSecrets } from "./evidence.js";
19
19
  import { fastCompletionProblem } from "./fast-start.js";
20
+ import { cleanLiveText, HIDDEN_LINE } from "./live-records.js";
21
+ import { keyShaped } from "./flexible-conversation.js";
20
22
  import { viewedGitSync } from "./teardown-git.js";
21
23
  import { wasInterrupted } from "./run-ending.js";
22
24
  import { agentChoicesFor, routeOfTask } from "./agentconfig.js";
@@ -573,3 +575,75 @@ function agentChoicesOf(store, taskId, ref, now) {
573
575
  const pairs = (phase) => choices[phase].filter(one => one.selectable).map(one => ({ provider: one.provider, model: one.model }));
574
576
  return { plan: pairs("plan"), build: pairs("build") };
575
577
  }
578
+ function shownPatch(text) {
579
+ let inKey = false, inHunk = false;
580
+ return text.replace(/\r\n/g, "\n").split("\n").map(line => {
581
+ if (line.startsWith("diff --git ")) {
582
+ inHunk = false;
583
+ inKey = false;
584
+ return keyShaped(line) ? `diff --git a/${HIDDEN_NAME} b/${HIDDEN_NAME}` : cleanLiveText(line);
585
+ }
586
+ const named = inHunk ? null : /^(---|\+\+\+) (.*)$/.exec(line);
587
+ if (named !== null)
588
+ return keyShaped(named[2]) ? `${named[1]} ${named[1] === "---" ? "a" : "b"}/${HIDDEN_NAME}` : cleanLiveText(line);
589
+ const hunk = /^(@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@)(.*)$/.exec(line);
590
+ if (hunk !== null) {
591
+ inHunk = true;
592
+ const context = hunk[2];
593
+ return PRIVATE_KEY_MARK.test(context) || PRIVATE_KEY_MARK.test(cleanLiveText(context)) || keyShaped(context) ? hunk[1] : cleanLiveText(line);
594
+ }
595
+ const marker = inHunk && /^[-+ ]/.test(line) ? line[0] : "";
596
+ const body = marker === "" ? line : line.slice(1);
597
+ const seen = cleanLiveText(body);
598
+ if (marker !== "" && (/-----BEGIN [A-Z ]*PRIVATE KEY-----/.test(body) || /-----BEGIN [A-Z ]*PRIVATE KEY-----/.test(seen)))
599
+ inKey = true;
600
+ const hide = (marker !== "" && inKey) || keyShaped(body);
601
+ if (marker !== "" && (/-----END [A-Z ]*PRIVATE KEY-----/.test(body) || /-----END [A-Z ]*PRIVATE KEY-----/.test(seen)))
602
+ inKey = false;
603
+ return hide ? `${marker}${HIDDEN_LINE}` : `${marker}${seen}`;
604
+ }).join("\n");
605
+ }
606
+ const PRIVATE_KEY_MARK = /-----(?:BEGIN|END) [A-Z ]*PRIVATE KEY-----/;
607
+ const HIDDEN_NAME = "[a name was hidden]";
608
+ export function threadDiffOf(thread, turn, changes, seen = {}) {
609
+ const empty = (problem) => ({ version: ENGINE_API_VERSION, task: thread, run: turn, totals: null, files: [], patchTruncated: false, problem });
610
+ if (!changes.ok)
611
+ return empty(`This thread's changes can't be read: ${cleanLiveText(changes.message)}`);
612
+ if ("none" in changes && seen.edited === true)
613
+ return empty("The agent has uncommitted edits. Ask it to commit them: Ship and Save as branch take committed work only.");
614
+ if ("none" in changes)
615
+ return empty("No committed changes yet. Ask the agent to commit its work: Ship sends committed work only.");
616
+ const files = patchFiles(changes.patch).map((text, index) => {
617
+ const parsed = parseReviewDiff(text).files[0];
618
+ let additions = 0, deletions = 0;
619
+ for (const line of text.split("\n")) {
620
+ if (line.startsWith("+") && !line.startsWith("+++"))
621
+ additions += 1;
622
+ else if (line.startsWith("-") && !line.startsWith("---"))
623
+ deletions += 1;
624
+ }
625
+ const binary = /^(?:Binary files .* differ|GIT binary patch)$/m.test(text);
626
+ const shownPath = (path) => keyShaped(path) ? HIDDEN_NAME : cleanLiveText(path);
627
+ return { file: index, path: shownPath(parsed?.path ?? "changed file"), oldPath: parsed?.oldPath == null ? null : shownPath(parsed.oldPath), additions, deletions, binary,
628
+ hunks: parsed?.hunks.length ?? 0 };
629
+ });
630
+ if (files.length === 0)
631
+ return empty("No committed changes yet. Ask the agent to commit its work: Ship sends committed work only.");
632
+ return { version: ENGINE_API_VERSION, task: thread, run: turn, totals: null, files, patchTruncated: changes.truncated, problem: null };
633
+ }
634
+ export function threadDiffFileOf(thread, turn, changes, file) {
635
+ if (!changes.ok || "none" in changes)
636
+ return null;
637
+ const text = patchFiles(changes.patch)[file];
638
+ if (text === undefined)
639
+ return null;
640
+ const parsed = parseReviewDiff(shownPatch(text));
641
+ const one = parsed.files[0];
642
+ if (one === undefined)
643
+ return null;
644
+ return { version: ENGINE_API_VERSION, task: thread, run: turn,
645
+ file: { file, path: keyShaped(one.path) ? HIDDEN_NAME : cleanLiveText(one.path), oldPath: one.oldPath === null ? null : keyShaped(one.oldPath) ? HIDDEN_NAME : cleanLiveText(one.oldPath),
646
+ meta: one.meta.map(cleanLiveText), hunks: one.hunks.map(hunk => ({ ...hunk, header: cleanLiveText(hunk.header) })),
647
+ lineCount: patchLineCount(one.hunks) },
648
+ linesTruncated: parsed.linesTruncated };
649
+ }
@@ -0,0 +1,24 @@
1
+ export const V185_SCHEMA = `
2
+ CREATE TABLE IF NOT EXISTS flexible_turn_said (
3
+ turn TEXT PRIMARY KEY CHECK (length(turn) = 32 AND turn NOT GLOB '*[^0-9a-f]*'),
4
+ thread TEXT NOT NULL CHECK (length(thread) = 32 AND thread NOT GLOB '*[^0-9a-f]*'),
5
+ seq INTEGER NOT NULL CHECK (seq >= 1),
6
+ said TEXT NOT NULL CHECK (length(said) BETWEEN 1 AND 100000),
7
+ said_at TEXT NOT NULL,
8
+ start_tip TEXT CHECK (start_tip IS NULL OR (length(start_tip) IN (40, 64) AND start_tip NOT GLOB '*[^0-9a-f]*')),
9
+ reply TEXT CHECK (reply IS NULL OR length(reply) <= 20000),
10
+ files TEXT CHECK (files IS NULL OR length(files) <= 20000),
11
+ UNIQUE (thread, seq)
12
+ );
13
+ CREATE TRIGGER IF NOT EXISTS flexible_turn_said_written_once BEFORE UPDATE ON flexible_turn_said
14
+ WHEN NEW.turn IS NOT OLD.turn OR NEW.thread IS NOT OLD.thread OR NEW.seq IS NOT OLD.seq OR NEW.said IS NOT OLD.said OR NEW.said_at IS NOT OLD.said_at
15
+ OR (OLD.start_tip IS NOT NULL AND NEW.start_tip IS NOT OLD.start_tip)
16
+ OR (OLD.reply IS NOT NULL AND NEW.reply IS NOT OLD.reply)
17
+ OR (OLD.files IS NOT NULL AND NEW.files IS NOT OLD.files)
18
+ BEGIN
19
+ SELECT RAISE(ABORT, 'what was said in a flexible turn is written once');
20
+ END;
21
+ `;
22
+ export const V185_TABLES = Object.freeze(["flexible_turn_said"]);
23
+ export const V185_STEPS = Object.freeze(["flexible-conversation"]);
24
+ export const V185_OBJECTS = Object.freeze([["table", "flexible_turn_said"], ["trigger", "flexible_turn_said_written_once"]]);