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
@@ -0,0 +1,344 @@
1
+ import { createHash } from "node:crypto";
2
+ import { resolveScopeProfile } from "./agentconfig.js";
3
+ import { isProtectedWork } from "./approval-policy.js";
4
+ import { permissionPlainWords, scopeFullAccess } from "./chat-terms.js";
5
+ import { checkAccessWords } from "./check-access.js";
6
+ import { networkWords, unaccountedHosts } from "./egress.js";
7
+ import { agentModelName } from "./model-names.js";
8
+ import { makesNoPlan, NO_READINESS, projectRoute, routeFromJson, sizeWords } from "./phase-routing.js";
9
+ import { sandboxTermsWords } from "./project-sandbox.js";
10
+ import { qualityModeTitle } from "./quality.js";
11
+ import { approvalOf, chainTermsLines, describeApproval, liveChainFromJson, releaseAsksAgainWords, releaseCheckSentence, releaseTermsSentence } from "./scope.js";
12
+ import { writesWords } from "./writes-mode.js";
13
+ export const NO_CONTEXT = { usual: null, revision: null, rules: null };
14
+ export const USUAL_LABEL = "Your usual project settings";
15
+ const OTHER_LABEL = "Other settings";
16
+ export const EVIDENCE_WORDS = { check: "runs automatically", screenshot: "shown in a screenshot", "changed-path": "seen in the changed files", "manual-review": "you review it" };
17
+ export const REPAIR_BRIEF = / — (repair exactly the unmet criteria named below; a comment cannot widen the scope\. Unmet: ([^.]+)\.|Collect only the missing observations for ([^.]+)\. .*|Diagnose the saved failed project check and repair within the original scope\. .*)$/s;
18
+ const money = (micro) => `$${(micro / 1_000_000).toFixed(2)}`;
19
+ const minutes = (seconds) => `${Math.round(seconds / 60)} min`;
20
+ const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
21
+ const plural = (n, one) => `${n} ${one}${n === 1 ? "" : "s"}`;
22
+ const VERB = { plan: "plans", build: "builds", repair: "fixes", review: "reviews" };
23
+ const ROLE = { plan: "planner", build: "builder", repair: "fixer", review: "reviewer" };
24
+ const PERMISSION_KEYS = ["permissionArgv", "approvalArgv", "sandboxMode", "permission"];
25
+ function agentWords(route, profile) {
26
+ if (route === null) {
27
+ if (profile == null)
28
+ return null;
29
+ return `${agentModelName(profile.provider, profile.model)} builds and fixes`;
30
+ }
31
+ const unplanned = makesNoPlan(route.size, route.risk);
32
+ const groups = [];
33
+ const asked = [];
34
+ for (const leg of route.legs) {
35
+ const name = agentModelName(leg.provider, leg.model);
36
+ if (unplanned && leg.phase === "plan" && leg.chosen === "recommended") {
37
+ asked.push(`${name} plans only if you ask for a plan`);
38
+ continue;
39
+ }
40
+ const group = groups.find(one => one.name === name);
41
+ if (group === undefined)
42
+ groups.push({ name, verbs: [VERB[leg.phase]] });
43
+ else
44
+ group.verbs.push(VERB[leg.phase]);
45
+ }
46
+ const list = (verbs) => verbs.length <= 1 ? verbs.join("") : `${verbs.slice(0, -1).join(", ")} and ${verbs.at(-1)}`;
47
+ const who = [...groups.map(one => `${one.name} ${list(one.verbs)}`), ...asked].join("; ");
48
+ const size = sizeWords(route);
49
+ return size === null ? who : `${who} (${lowerFirst(size)})`;
50
+ }
51
+ function limitWords(profile) {
52
+ if ("idleTimeoutSeconds" in profile)
53
+ return `stops after ${minutes(profile.timeoutSeconds)}, or ${minutes(profile.idleTimeoutSeconds)} silent`;
54
+ const time = `${minutes(profile.timeoutSeconds)} ${profile.timeoutKind === "idle" ? "without progress" : "per attempt"}`;
55
+ return typeof profile.maxTurns === "number" ? `stops after ${profile.maxTurns} turns or ${time}` : `stops after ${time}`;
56
+ }
57
+ function fixWords(profile) {
58
+ const model = profile.repairModel === "inherit" ? "the same model" : profile.repairModel;
59
+ if ("repairIdleTimeoutSeconds" in profile)
60
+ return `on ${model}, up to ${minutes(profile.repairTimeoutSeconds)}, or ${minutes(profile.repairIdleTimeoutSeconds)} silent`;
61
+ return typeof profile.repairMaxTurns === "number"
62
+ ? `on ${model}, up to ${profile.repairMaxTurns} turns and ${minutes(profile.repairTimeoutSeconds)}`
63
+ : `on ${model}, up to ${minutes(profile.repairTimeoutSeconds)}`;
64
+ }
65
+ const SETTINGS = [
66
+ { label: "Writes", fields: ["writes"], words: profile => writesWords(profile.writes), routine: profile => profile.writes === "workspace" },
67
+ { label: "Reads", fields: ["fencePolicy", "readDeny"], words: profile => sandboxTermsWords(profile).reads, routine: () => true },
68
+ { label: "Time limit", fields: ["maxTurns", "timeoutSeconds", "timeoutKind", "idleTimeoutSeconds"], words: limitWords, routine: () => true },
69
+ { label: "Fixes", fields: ["repairModel", "repairMaxTurns", "repairTimeoutSeconds", "repairIdleTimeoutSeconds"], words: fixWords, routine: () => true },
70
+ ];
71
+ const valueOf = (profile, keys) => JSON.stringify(keys.map(key => profile[key] ?? null));
72
+ function releaseAuthorityWords(release) {
73
+ return `Repository ${release.repo}, branch ${release.branch} into ${release.base}, check grant ${release.grant.id}, ${release.access === "sandboxed" ? "checks in the sandbox" : `checks outside the sandbox (${release.access})`}.`;
74
+ }
75
+ const ACCESS_GROUPS = [
76
+ { name: "network", fields: ["network"], words: profile => lowerFirst(networkWords(profile.network ?? null, profile.provider).replace(/^Network: /, "")) },
77
+ { name: "tools", fields: PERMISSION_KEYS, words: profile => permissionPlainWords(profile) ?? "not known" },
78
+ { name: "writes", fields: ["writes"], words: profile => writesWords(profile.writes) },
79
+ { name: "reads", fields: ["fencePolicy", "readDeny"], words: profile => sandboxTermsWords(profile).reads },
80
+ { name: "project checks", fields: ["checkAccess"], words: profile => checkAccessWords(profile.checkAccess ?? "sandboxed") },
81
+ { name: "macOS services", fields: ["machLookup"], words: profile => sandboxTermsWords(profile).mach ?? "none beyond the sandbox's" },
82
+ { name: "time limit", fields: ["maxTurns", "timeoutSeconds", "timeoutKind", "idleTimeoutSeconds"], words: limitWords },
83
+ { name: "fixes", fields: ["repairModel", "repairMaxTurns", "repairTimeoutSeconds", "repairIdleTimeoutSeconds"], words: fixWords },
84
+ ];
85
+ const rawOf = (value) => value === undefined ? "none" : typeof value === "string" ? value : JSON.stringify(value);
86
+ function changeOf(label, was, now, fields, words) {
87
+ const differing = fields.filter(field => JSON.stringify(was[field] ?? null) !== JSON.stringify(now[field] ?? null));
88
+ if (differing.length === 0)
89
+ return null;
90
+ const before = words(was), after = words(now);
91
+ if (before !== after)
92
+ return { label, was: before, now: after };
93
+ return { label, was: differing.map(field => `${field} ${rawOf(was[field])}`).join(", "), now: differing.map(field => `${field} ${rawOf(now[field])}`).join(", ") };
94
+ }
95
+ function profileChanges(before, next, prefix = "") {
96
+ return ACCESS_GROUPS.flatMap(group => {
97
+ const change = changeOf(`${prefix}${group.name}`, before, next, group.fields, one => group.words(one));
98
+ return change === null ? [] : [change];
99
+ });
100
+ }
101
+ function fallbackDifferences(scope) {
102
+ const chain = liveChainFromJson(scope.proposedChainJson ?? null);
103
+ if (chain === null)
104
+ return [];
105
+ return chain.slice(1).map((entry, at) => {
106
+ const differs = profileChanges(chain[0].profile, entry.profile);
107
+ return differs.length === 0 ? `Fallback ${at + 2} has the same access and limits as the first.`
108
+ : `Fallback ${at + 2} differs from the first: ${differs.map(one => `${one.label}: ${one.now} (the first: ${one.was})`).join("; ")}.`;
109
+ });
110
+ }
111
+ export function revisionParts(facts) {
112
+ const notes = [];
113
+ if (!facts.hadPlan)
114
+ notes.push("The earlier version had no plan, so nothing was copied.");
115
+ else if (facts.changed !== null && facts.changed.length === 0)
116
+ notes.push("It keeps the same limits.");
117
+ else if (facts.changed !== null)
118
+ notes.push(`${facts.changed.length === 1 ? "One limit changes" : `${facts.changed.length} limits change`} from that build: ${facts.changed.map(one => one.label).join(", ")}.`);
119
+ if (facts.repair !== null && facts.problem === null) {
120
+ notes.push(facts.repair.cap !== null && (facts.repair.remaining ?? 0) > 0
121
+ ? `${plural(facts.repair.remaining, "more attempt")} can run without asking you.`
122
+ : "Each extra attempt asks you first.");
123
+ }
124
+ return { lead: facts.sourceRun === null ? `This revises ${facts.sourceTask}.` : `This revises build #${facts.sourceRun}.`, notes };
125
+ }
126
+ export function revisionWords(facts) {
127
+ const parts = revisionParts(facts);
128
+ return [parts.lead, ...parts.notes].join(" ");
129
+ }
130
+ export function revisionChangeRows(facts) {
131
+ return (facts?.changed ?? []).map(one => ({ label: `${one.label.charAt(0).toUpperCase()}${one.label.slice(1)}`, words: `was ${one.was}, now ${one.now}`, fields: [] }));
132
+ }
133
+ export function approvalSummaryOf(scope, context = NO_CONTEXT) {
134
+ const profile = scope.profile ?? null;
135
+ const route = routeFromJson(scope.proposedRouteJson ?? null);
136
+ const usualProfile = context.usual?.profile ?? null;
137
+ const decisions = [];
138
+ const differs = [];
139
+ const warnings = [];
140
+ const usual = [];
141
+ decisions.push({ label: "Goal", words: scope.goal, fields: ["goal"] });
142
+ if (scope.outOfScope !== null)
143
+ decisions.push({ label: "Won’t touch", words: scope.outOfScope, fields: ["outOfScope"] });
144
+ decisions.push(scope.acceptance.length === 0
145
+ ? { label: "Done when", words: "You decide when you review the result.", fields: ["acceptance"] }
146
+ : { label: "Done when", words: `${scope.acceptance[0].statement} (${scope.acceptance[0].evidence.map(kind => EVIDENCE_WORDS[kind] ?? kind).join(", ")})`,
147
+ lines: scope.acceptance.slice(1).map(one => `${one.statement} (${one.evidence.map(kind => EVIDENCE_WORDS[kind] ?? kind).join(", ")})`), fields: ["acceptance"] });
148
+ if (scope.candidate)
149
+ decisions.push({ label: "Commit", words: `${scope.candidate}, checked out as it is; no agent runs`, fields: ["candidate"] });
150
+ const agent = agentWords(route, profile);
151
+ if (agent !== null)
152
+ decisions.push({ label: "Agent", words: agent, fields: [...(route === null ? [] : ["route", ...route.legs.map(leg => `route.${leg.phase}`)]), ...(profile === null ? [] : ["profile.provider", "profile.model"])] });
153
+ const permissionKey = profile === null ? null : PERMISSION_KEYS.find(key => key in profile) ?? null;
154
+ const tools = permissionPlainWords(profile);
155
+ const usualTools = usualProfile === null ? null : permissionPlainWords(usualProfile);
156
+ decisions.push({ label: "Files", words: scope.touches.length === 0 ? "any file in the project" : `only ${scope.touches.join(", ")}`, fields: ["touches"] });
157
+ if (profile !== null) {
158
+ const network = profile.network ?? null;
159
+ const wide = network !== null && (network.mode === "open" || network.loopback === "any" || unaccountedHosts(network, profile.provider).length > 0);
160
+ decisions.push({ label: "Network", words: lowerFirst(networkWords(network, profile.provider).replace(/^Network: /, "")), fields: ["profile.network"], ...(wide ? { risky: true } : {}) });
161
+ }
162
+ if (tools !== null) {
163
+ decisions.push({ label: "Tools", words: `${tools}${usualTools !== null && usualTools !== tools ? " (not the project’s usual)" : ""}`,
164
+ fields: permissionKey === null ? [] : [`profile.${permissionKey}`], ...(scopeFullAccess(profile) ? { risky: true } : {}) });
165
+ }
166
+ decisions.push({ label: "May cost", words: scope.budgetMicrousd === null ? "no cap: an attempt runs until it finishes or reaches its time limit" : `up to ${money(scope.budgetMicrousd)} per attempt; the agent is stopped there`,
167
+ fields: ["budget"], ...(scope.budgetMicrousd === null ? { risky: true } : {}) });
168
+ if (scope.releaseTerms != null) {
169
+ const terms = scope.releaseTerms;
170
+ decisions.push({ label: "Release", words: releaseTermsSentence(terms), lines: terms.policy.carry ? releaseAsksAgainWords(terms)
171
+ : [releaseAuthorityWords(terms) + ` Until ${terms.expiresAt}.`], fields: ["releaseTerms"] });
172
+ }
173
+ if (scope.releaseCheck != null)
174
+ decisions.push({ label: "Release", words: releaseCheckSentence(scope.releaseCheck), lines: [releaseAuthorityWords(scope.releaseCheck)], fields: ["releaseCheck"] });
175
+ const byHand = route === null ? [] : route.legs.filter(leg => leg.chosen !== "recommended");
176
+ if (byHand.length > 0)
177
+ differs.push({ label: "Your pick", words: `${byHand.map(leg => `${ROLE[leg.phase]} ${agentModelName(leg.provider, leg.model)}`).join("; ")}, not the project’s usual pick`, fields: ["route"] });
178
+ const quality = scope.qualityMode ?? "default";
179
+ const qualityRow = { label: "Checks", words: qualityModeTitle(quality), fields: ["qualityMode"] };
180
+ if (context.usual !== null && quality !== context.usual.qualityMode)
181
+ differs.push({ ...qualityRow, words: `${qualityRow.words} (usually ${qualityModeTitle(context.usual.qualityMode)})` });
182
+ else
183
+ usual.push(qualityRow);
184
+ if (profile !== null) {
185
+ for (const setting of SETTINGS) {
186
+ const row = { label: setting.label, words: setting.words(profile), fields: setting.fields.filter(key => key in profile).map(key => `profile.${key}`) };
187
+ if (usualProfile !== null && valueOf(profile, setting.fields) !== valueOf(usualProfile, setting.fields))
188
+ differs.push({ ...row, words: `${row.words} (usually ${setting.words(usualProfile)})`, ...(setting.routine(profile) ? {} : { risky: true }) });
189
+ else if (!setting.routine(profile))
190
+ differs.push({ ...row, risky: true });
191
+ else
192
+ usual.push(row);
193
+ }
194
+ if (profile.checkAccess !== undefined)
195
+ warnings.push({ words: `Project checks: ${checkAccessWords(profile.checkAccess)}.`, fields: ["profile.checkAccess"] });
196
+ else
197
+ usual.push({ label: "Project checks", words: checkAccessWords("sandboxed"), fields: [] });
198
+ const mach = sandboxTermsWords(profile).mach;
199
+ if (mach !== null)
200
+ warnings.push({ words: `It ${mach}.`, fields: ["profile.machLookup"] });
201
+ }
202
+ const chain = chainTermsLines(scope);
203
+ if (chain.length > 0)
204
+ warnings.push({ words: [...chain, ...fallbackDifferences(scope)].join(" "), fields: ["chain"] });
205
+ const rules = context.rules;
206
+ if (rules !== null && isProtectedWork(rules, [...scope.touches]))
207
+ warnings.push({ words: "This project protects this work: two people must approve it.", fields: [] });
208
+ if (rules?.notRequester === true)
209
+ warnings.push({ words: "The person who asked for this can’t approve it.", fields: [] });
210
+ const revision = context.revision === null ? null : revisionWords(context.revision);
211
+ const revisionNotes = context.revision === null ? [] : revisionParts(context.revision).notes;
212
+ const revisionChanges = revisionChangeRows(context.revision);
213
+ if (context.revision?.problem != null)
214
+ warnings.push({ words: `Toolroll can’t check what this revises (${context.revision.problem}), so no fix runs on its own.`, fields: [] });
215
+ const usualLabel = context.usual === null ? OTHER_LABEL : USUAL_LABEL;
216
+ const key = createHash("sha256").update(JSON.stringify({ v: 2, digest: scope.digest, revision, revisionChanges, decisions, differs, warnings, usual, usualLabel, baseline: context.usual }), "utf8").digest("hex").slice(0, 32);
217
+ const why = context.evidence == null || context.evidence === "" ? null : context.evidence.replace(/^Why this model: /, "");
218
+ return { revision, revisionNotes, revisionChanges, decisions, why, differs, warnings, usual, usualLabel, key };
219
+ }
220
+ export function summaryFields(summary) {
221
+ return new Set([...summary.decisions, ...summary.differs, ...summary.usual, ...summary.warnings].flatMap(one => one.fields));
222
+ }
223
+ export function boundFieldsOf(scope) {
224
+ const fields = ["goal", "touches", "acceptance", "budget", "qualityMode"];
225
+ if (scope.outOfScope !== null)
226
+ fields.push("outOfScope");
227
+ if (scope.candidate)
228
+ fields.push("candidate");
229
+ if (scope.releaseTerms != null)
230
+ fields.push("releaseTerms");
231
+ if (scope.releaseCheck != null)
232
+ fields.push("releaseCheck");
233
+ const route = routeFromJson(scope.proposedRouteJson ?? null);
234
+ if (route !== null)
235
+ fields.push("route", ...route.legs.map(leg => `route.${leg.phase}`));
236
+ if (chainTermsLines(scope).length > 0)
237
+ fields.push("chain");
238
+ for (const key of Object.keys(scope.profile ?? {}))
239
+ fields.push(`profile.${key}`);
240
+ return fields;
241
+ }
242
+ export function summaryLines(summary) {
243
+ const pad = (label) => ` ${label.padEnd(12)} `;
244
+ const indent = " ".repeat(15);
245
+ const row = (one) => [`${pad(one.label)}${one.words}`, ...(one.lines ?? []).map(line => `${indent}${line}`)];
246
+ return [
247
+ ...(summary.revision === null ? [] : [`${pad("Revision")}${summary.revision}`]),
248
+ ...summary.revisionChanges.map(one => `${pad("Changed")}${one.label.toLowerCase()}: ${one.words}`),
249
+ ...summary.decisions.flatMap(row),
250
+ ...(summary.why === null ? [] : [`${pad("Why model")}${summary.why}`]),
251
+ ...summary.differs.flatMap(row),
252
+ ...summary.warnings.map(one => `${pad("Note")}${one.words}`),
253
+ ...(summary.usual.length === 0 ? [] : [`${pad("Usual")}${summary.usualLabel}: ${summary.usual.map(one => `${lowerFirst(one.label)} ${one.words}`).join(" · ")}`]),
254
+ ];
255
+ }
256
+ export function summaryText(summary, omit = () => false) {
257
+ return [
258
+ ...(summary.revision === null ? [] : [summary.revision, ...summary.revisionChanges.map(one => `${one.label}: ${one.words}`), ""]),
259
+ ...summary.warnings.map(one => one.words),
260
+ ...(summary.warnings.length === 0 ? [] : [""]),
261
+ ...[...summary.decisions.filter(one => !omit(one)), ...(summary.why === null ? [] : [{ label: "Why model", words: summary.why }]), ...summary.differs].flatMap((one) => [`${one.label}: ${one.words}`, ...(one.lines ?? []).map(line => ` ${line}`)]),
262
+ ...(summary.usual.length === 0 ? [] : ["", `${summary.usualLabel}: ${summary.usual.map(one => `${lowerFirst(one.label)} ${one.words}`).join(" · ")}`]),
263
+ ].join("\n");
264
+ }
265
+ export function describeScope(scope, readiness = NO_READINESS, evidence = null, context = null) {
266
+ const route = routeFromJson(scope.proposedRouteJson ?? null);
267
+ const halted = route !== null && projectRoute(route, readiness).halted;
268
+ return [
269
+ ...summaryLines(approvalSummaryOf(scope, { ...(context ?? NO_CONTEXT), evidence })),
270
+ ...(halted ? [" Note An agent here is reported unavailable: nothing runs until it is back or you change the agent."] : []),
271
+ ` version ${scope.digest.slice(0, 8)} (the full plan version is in --json)`,
272
+ ` approved ${describeApproval(approvalOf(scope))}`,
273
+ ];
274
+ }
275
+ export function usualSettingsOf(store, repo, scope, platform = process.platform) {
276
+ const qualityMode = store.qualityDefault().mode;
277
+ const profile = scope.profile ?? null;
278
+ if (profile === null)
279
+ return { profile: null, qualityMode };
280
+ const resolved = resolveScopeProfile(store, repo, undefined, { provider: profile.provider, model: profile.model }, platform, { walk: false });
281
+ return resolved.ok ? { profile: resolved.profile, qualityMode } : null;
282
+ }
283
+ export function limitChanges(before, next) {
284
+ const out = [];
285
+ const scopeOf = (one) => ({ qualityMode: one.qualityMode ?? "default", budgetMicrousd: one.budgetMicrousd, outOfScope: one.outOfScope ?? null, touches: [...one.touches].sort() });
286
+ const was = scopeOf(before), now = scopeOf(next);
287
+ const push = (change) => { if (change !== null)
288
+ out.push(change); };
289
+ push(changeOf("checks level", was, now, ["qualityMode"], one => qualityModeTitle(one["qualityMode"])));
290
+ push(changeOf("cost", was, now, ["budgetMicrousd"], one => one["budgetMicrousd"] === null ? "no cap" : `up to ${money(one["budgetMicrousd"])} per attempt`));
291
+ push(changeOf("won’t touch", was, now, ["outOfScope"], one => one["outOfScope"] ?? "nothing ruled out"));
292
+ push(changeOf("files", was, now, ["touches"], one => one["touches"].length === 0 ? "any file" : `only ${one["touches"].join(", ")}`));
293
+ const wasProfile = before.profile ?? null, nowProfile = next.profile ?? null;
294
+ if (wasProfile === null || nowProfile === null) {
295
+ if (wasProfile !== nowProfile)
296
+ out.push({ label: "agent setup", was: wasProfile === null ? "none" : "set", now: nowProfile === null ? "none" : "set" });
297
+ }
298
+ else
299
+ out.push(...profileChanges(wasProfile, nowProfile));
300
+ const wasChain = liveChainFromJson(before.proposedChainJson ?? null) ?? [], nowChain = liveChainFromJson(next.proposedChainJson ?? null) ?? [];
301
+ for (let at = 1; at < Math.max(wasChain.length, nowChain.length); at++) {
302
+ const one = wasChain[at], two = nowChain[at];
303
+ const name = (entry) => entry === undefined ? "none" : `${agentModelName(entry.profile.provider, entry.profile.model)}${entry.authMode === "api-key" ? " on an API key" : ""}`;
304
+ if (one === undefined || two === undefined || name(one) !== name(two)) {
305
+ out.push({ label: `fallback ${at + 1}`, was: name(one), now: name(two) });
306
+ continue;
307
+ }
308
+ out.push(...profileChanges(one.profile, two.profile, `fallback ${at + 1} `));
309
+ }
310
+ return out;
311
+ }
312
+ export function revisionFactsOf(store, lineage, scope) {
313
+ if (lineage === null)
314
+ return null;
315
+ const source = lineage.sourceHadScope ? store.getScope(lineage.sourceTask) : null;
316
+ const changed = source === null ? null : limitChanges(source, scope);
317
+ return {
318
+ sourceTask: lineage.sourceTask,
319
+ sourceRun: lineage.sourceRun,
320
+ hadPlan: lineage.sourceHadScope,
321
+ changed,
322
+ problem: lineage.problem ?? null,
323
+ repair: lineage.repair === null ? null : { cap: lineage.repair.cap, remaining: lineage.repair.remaining },
324
+ };
325
+ }
326
+ export function summaryContextOf(store, taskId, scope, now, evidence = null, project = null) {
327
+ const ref = store.lookupRef(taskId);
328
+ const repo = ref?.repo ?? project;
329
+ const lineage = ref !== null && ref.revisionBriefArtifact !== null ? store.revisionLineageOf(taskId, now) : null;
330
+ return {
331
+ usual: usualSettingsOf(store, repo, scope),
332
+ revision: revisionFactsOf(store, lineage, scope),
333
+ rules: repo === null ? null : store.approvalRules(repo),
334
+ evidence,
335
+ };
336
+ }
337
+ export function approvalSummaryFor(store, taskId, now, evidence = null) {
338
+ const scope = store.getScope(taskId);
339
+ return scope === null ? null : approvalSummaryOf(scope, summaryContextOf(store, taskId, scope, now, evidence));
340
+ }
341
+ export function shipSummaryOf(digest, decisions, warnings) {
342
+ const key = createHash("sha256").update(JSON.stringify({ v: 2, kind: "flexible-ship", digest, decisions, warnings }), "utf8").digest("hex").slice(0, 32);
343
+ return { revision: null, revisionNotes: [], revisionChanges: [], decisions, why: null, differs: [], warnings, usual: [], usualLabel: USUAL_LABEL, key };
344
+ }
package/dist/attest.js CHANGED
@@ -32,13 +32,13 @@ export function versionInRange(version, range) {
32
32
  return false;
33
33
  return atLeast(v, floor) && !atLeast(v, ceiling);
34
34
  }
35
- export function resolveExecutable(binary) {
35
+ export function resolveExecutable(binary, path = process.env["PATH"] ?? "") {
36
36
  const candidates = [];
37
37
  if (binary.includes("/") || isAbsolute(binary)) {
38
38
  candidates.push(binary);
39
39
  }
40
40
  else {
41
- for (const dir of (process.env["PATH"] ?? "").split(delimiter)) {
41
+ for (const dir of path.split(delimiter)) {
42
42
  if (dir !== "")
43
43
  candidates.push(join(dir, binary));
44
44
  }