toolroll 0.9.115 → 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.
- package/CHANGELOG.md +55 -0
- package/README.md +43 -26
- package/dist/acp-agents.js +14 -1
- package/dist/acp-client.js +19 -1
- package/dist/agent-change-check.js +60 -0
- package/dist/agent-change-schema.js +19 -0
- package/dist/agent-detect.js +11 -1
- package/dist/agent-fence.js +39 -10
- package/dist/agent-network-request.js +108 -0
- package/dist/agent-requests.js +105 -0
- package/dist/approval-summary.js +3 -3
- package/dist/backup.js +17 -1
- package/dist/batch-checks.js +81 -18
- package/dist/browser/terminal.js +41 -41
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +36 -36
- package/dist/builder.js +3 -1
- package/dist/candidate-materialize.js +119 -0
- package/dist/central-enrollment-contract.js +156 -0
- package/dist/central-recovery-stage.js +329 -0
- package/dist/chat-actions.js +101 -2
- package/dist/chat-channel.js +40 -0
- package/dist/check-only-standing.js +13 -0
- package/dist/check-only.js +25 -13
- package/dist/check-recovery-hold.js +199 -0
- package/dist/check-recovery-index-schema.js +3 -0
- package/dist/check-screenshots.js +83 -0
- package/dist/cli.js +125 -6
- package/dist/codex-limits.js +4 -0
- package/dist/connect-cli.js +257 -11
- package/dist/contracts/chat-actions.js +4 -0
- package/dist/contracts/console-api.js +15 -4
- package/dist/contracts/engine-api.js +344 -2
- package/dist/contracts/lead-tools.js +56 -2
- package/dist/contracts/provider.js +1 -1
- package/dist/contracts/route.js +1 -1
- package/dist/contracts/terminal-connection.js +50 -0
- package/dist/converse.js +80 -4
- package/dist/device-pair.js +280 -0
- package/dist/direct-chat-artifacts.js +347 -0
- package/dist/direct-chat-catalog.js +311 -0
- package/dist/direct-chat-fence.js +96 -0
- package/dist/direct-chat-git.js +343 -0
- package/dist/direct-chat-laptop.js +19 -0
- package/dist/direct-chat-schema.js +181 -0
- package/dist/direct-chat-ship.js +861 -0
- package/dist/direct-chat-workspace.js +389 -0
- package/dist/direct-chat.js +2107 -0
- package/dist/doctor.js +1 -1
- package/dist/easy-start.js +18 -0
- package/dist/egress.js +25 -4
- package/dist/engine-chat.js +454 -0
- package/dist/engine-reads.js +141 -13
- package/dist/exec.js +4 -3
- package/dist/flexible-agents.js +8 -16
- package/dist/flexible-authority-end.js +2 -0
- package/dist/flexible-interactive-schema.js +133 -0
- package/dist/flexible-interactive.js +94 -0
- package/dist/flexible-session.js +117 -49
- package/dist/flexible-ship.js +87 -7
- package/dist/flexible-sign-in.js +10 -0
- package/dist/flexible-start.js +21 -3
- package/dist/flexible-thread.js +2 -3
- package/dist/flexible-turns.js +26 -5
- package/dist/flexible.js +13 -0
- package/dist/flow-triggers.js +13 -4
- package/dist/flows-ui.js +54 -20
- package/dist/handoff-cli.js +630 -0
- package/dist/invoke.js +55 -13
- package/dist/lead-contract.js +5 -4
- package/dist/lead-doors.js +80 -1
- package/dist/lead-progress.js +9 -0
- package/dist/lead-tools.js +682 -10
- package/dist/lead.js +37 -9
- package/dist/live-bus.js +11 -0
- package/dist/live-terminal.js +132 -12
- package/dist/local-handoff.js +363 -0
- package/dist/local-owner-acts.js +264 -2
- package/dist/local-owner.js +16 -1
- package/dist/multiplayer-handoff.js +528 -0
- package/dist/multiplayer-presence.js +471 -0
- package/dist/names.js +17 -4
- package/dist/needs-you.js +10 -0
- package/dist/operate.js +280 -19
- package/dist/policy.js +2 -2
- package/dist/project-delete-ui.js +18 -11
- package/dist/project-delete.js +65 -4
- package/dist/project-tools.js +1 -1
- package/dist/prompt.js +1 -1
- package/dist/provider-connection.js +2 -0
- package/dist/provider-home.js +251 -8
- package/dist/provider.js +3 -2
- package/dist/publish.js +119 -64
- package/dist/pull-request-flow.js +35 -14
- package/dist/read-executor-worker.js +1 -1
- package/dist/read-executor.js +95 -1
- package/dist/restore-retirement.js +152 -0
- package/dist/result-follow-ups.js +116 -37
- package/dist/route-change.js +44 -4
- package/dist/scope.js +62 -5
- package/dist/serve.js +49 -5
- package/dist/server/chat.js +94 -13
- package/dist/server/console.css +9 -9
- package/dist/server/direct-chat.js +583 -0
- package/dist/server/engine-api.js +219 -21
- package/dist/server/flows.js +47 -13
- package/dist/server/found-repos.js +25 -0
- package/dist/server/guards.js +20 -6
- package/dist/server/live.js +81 -23
- package/dist/server/pages.js +67 -13
- package/dist/server/people-tokens.js +47 -6
- package/dist/server/remote.js +29 -0
- package/dist/server/render-results.js +6 -2
- package/dist/server/render-settings.js +4 -2
- package/dist/server/render-tasks.js +18 -17
- package/dist/server/route-table.js +69 -2
- package/dist/server/settings.js +22 -7
- package/dist/server/task-views.js +15 -3
- package/dist/server/tasks.js +39 -2
- package/dist/server/terminals.js +185 -11
- package/dist/settings-proofs.js +1 -1
- package/dist/spend-report.js +2 -2
- package/dist/spend.js +3 -3
- package/dist/store.js +600 -59
- package/dist/subagent-admin.js +23 -10
- package/dist/subagent-backup-schema.js +36 -0
- package/dist/subagent-backup.js +92 -0
- package/dist/subagent-week.js +2 -2
- package/dist/subagent-work.js +70 -47
- package/dist/subagents-ui.js +6 -2
- package/dist/subagents.js +5 -2
- package/dist/subscription-chat.js +36 -5
- package/dist/subscription-usage.js +233 -0
- package/dist/task-live.js +2 -1
- package/dist/teardown-git.js +34 -4
- package/dist/terminal-connection.js +159 -0
- package/dist/terminal-safety.js +114 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-contract.js +1 -1
- package/dist/tui-launch.js +32 -1
- package/dist/workspace-identity-schema.js +21 -0
- package/package.json +4 -2
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { ChatCore } from "./chat-core.js";
|
|
3
|
+
import { CHAT_PROVIDERS } from "./contracts/chat-tables.js";
|
|
4
|
+
import { revokeCoordinator } from "./coordinator.js";
|
|
5
|
+
import { autoPublishHeld, holdAutoPublish, PUBLISH_ALLOWED_ACTION, PUBLISH_HELD_ACTION } from "./release-auto.js";
|
|
6
|
+
import { RECOVERY_GENERATION_PATTERN, WORKSPACE_ID_PATTERN } from "./workspace-identity-schema.js";
|
|
7
|
+
const CHAT_ACTION_TABLES = ["chat_action", "chat_flow_action", "chat_flow_choice", "chat_flow_note", "chat_question_action", "chat_ask_action", "chat_flow_prompt", "chat_question_prompt"];
|
|
8
|
+
const CHAT_DECIDE_TABLES = ["chat_decide_action", "chat_decide_prompt"];
|
|
9
|
+
const openChatActions = (store) => CHAT_ACTION_TABLES.reduce((sum, table) => sum + count(store, `SELECT count(*) AS n FROM ${table} WHERE consumed IS NULL`), 0)
|
|
10
|
+
+ CHAT_DECIDE_TABLES.reduce((sum, table) => sum + count(store, `SELECT count(*) AS n FROM ${table} WHERE consumed_at IS NULL`), 0)
|
|
11
|
+
+ count(store, "SELECT count(*) AS n FROM chat_note_draft WHERE state IN ('pending', 'armed')");
|
|
12
|
+
const count = (store, sql) => Number(store.handle.prepare(sql).get()?.["n"] ?? 0);
|
|
13
|
+
function freshRecoveryGeneration(exclude) {
|
|
14
|
+
for (let i = 0; i < 16; i += 1) {
|
|
15
|
+
const candidate = randomBytes(16).toString("hex");
|
|
16
|
+
if (RECOVERY_GENERATION_PATTERN.test(candidate) && !exclude.has(candidate))
|
|
17
|
+
return candidate;
|
|
18
|
+
}
|
|
19
|
+
throw new Error("Could not generate a distinct recovery generation");
|
|
20
|
+
}
|
|
21
|
+
export function retireRestoredAuthority(store, options) {
|
|
22
|
+
const { now, actor } = options;
|
|
23
|
+
const identity = store.workspaceIdentity();
|
|
24
|
+
if (!WORKSPACE_ID_PATTERN.test(identity.id) || !RECOVERY_GENERATION_PATTERN.test(identity.recoveryGeneration)) {
|
|
25
|
+
throw new Error("Restored database has an invalid workspace identity");
|
|
26
|
+
}
|
|
27
|
+
const excluded = new Set([identity.recoveryGeneration]);
|
|
28
|
+
if (typeof options.replacedRecoveryGeneration === "string" && options.replacedRecoveryGeneration !== "") {
|
|
29
|
+
excluded.add(options.replacedRecoveryGeneration);
|
|
30
|
+
}
|
|
31
|
+
const nextGeneration = freshRecoveryGeneration(excluded);
|
|
32
|
+
const rotated = store.handle
|
|
33
|
+
.prepare("UPDATE workspace_identity SET recovery_generation = ? WHERE singleton = 1")
|
|
34
|
+
.run(nextGeneration);
|
|
35
|
+
if (Number(rotated.changes) !== 1) {
|
|
36
|
+
throw new Error("Failed to rotate restored workspace recovery generation");
|
|
37
|
+
}
|
|
38
|
+
const apiTokens = count(store, "SELECT count(*) AS n FROM credential WHERE kind = 'person' AND revoked_at IS NULL");
|
|
39
|
+
for (const token of store.apiTokens(null)) {
|
|
40
|
+
if (token.revokedAt === null) {
|
|
41
|
+
store.revokeApiToken(token.id, actor, now, "database restored");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const leadCredentials = count(store, "SELECT count(*) AS n FROM credential WHERE kind = 'lead' AND revoked_at IS NULL");
|
|
45
|
+
for (const row of store.handle.prepare("SELECT DISTINCT account FROM credential WHERE kind = 'lead' AND revoked_at IS NULL").all()) {
|
|
46
|
+
store.revokeLeadCredentials(String(row["account"]), actor, now);
|
|
47
|
+
}
|
|
48
|
+
const coordinatorCredentials = count(store, "SELECT count(*) AS n FROM credential WHERE kind = 'coordinator' AND revoked_at IS NULL");
|
|
49
|
+
for (const row of store.handle.prepare("SELECT id FROM credential WHERE kind = 'coordinator' AND revoked_at IS NULL").all()) {
|
|
50
|
+
if (!revokeCoordinator(store, String(row["id"]), actor, now).ok) {
|
|
51
|
+
throw new Error("Coordinator credential retirement failed during restore");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const row of store.handle.prepare("SELECT id FROM credential WHERE kind = 'coordinator'").all()) {
|
|
55
|
+
store.sweepCoordinatorProposals(now, String(row["id"]));
|
|
56
|
+
}
|
|
57
|
+
const oauthRows = count(store, "SELECT (SELECT count(*) FROM oauth_code) + (SELECT count(*) FROM oauth_grant) + (SELECT count(*) FROM oauth_refresh) AS n");
|
|
58
|
+
store.handle.exec("DELETE FROM oauth_code; DELETE FROM oauth_refresh; DELETE FROM oauth_grant");
|
|
59
|
+
const sessions = store.webSessions(null);
|
|
60
|
+
for (const session of sessions) {
|
|
61
|
+
store.dropWebSession(session.idHash);
|
|
62
|
+
}
|
|
63
|
+
const publicationGrants = count(store, "SELECT count(*) AS n FROM publication_grant WHERE revoked_at IS NULL");
|
|
64
|
+
for (const row of store.handle.prepare("SELECT DISTINCT repo FROM publication_grant WHERE revoked_at IS NULL").all()) {
|
|
65
|
+
if (!store.revokePublicationGrant(String(row["repo"]), actor, now)) {
|
|
66
|
+
throw new Error("Publication grant retirement failed during restore");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const intakeGrants = count(store, "SELECT count(*) AS n FROM intake_grant WHERE revoked_at IS NULL");
|
|
70
|
+
for (const row of store.handle.prepare("SELECT DISTINCT repo FROM intake_grant WHERE revoked_at IS NULL").all()) {
|
|
71
|
+
if (!store.clearIntakeGrant(String(row["repo"]), actor, now)) {
|
|
72
|
+
throw new Error("Intake grant retirement failed during restore");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const releaseTasks = store.handle
|
|
76
|
+
.prepare("SELECT DISTINCT task_id FROM action_ledger WHERE task_id IS NOT NULL AND action IN (?, ?)")
|
|
77
|
+
.all(PUBLISH_HELD_ACTION, PUBLISH_ALLOWED_ACTION);
|
|
78
|
+
let releaseHolds = 0;
|
|
79
|
+
for (const row of releaseTasks) {
|
|
80
|
+
const taskId = String(row["task_id"]);
|
|
81
|
+
if (autoPublishHeld(store, taskId) === null) {
|
|
82
|
+
holdAutoPublish(store, {
|
|
83
|
+
taskId,
|
|
84
|
+
now,
|
|
85
|
+
why: "Restored publication permission is on hold. This does not establish whether earlier work ran or stopped.",
|
|
86
|
+
});
|
|
87
|
+
releaseHolds += 1;
|
|
88
|
+
}
|
|
89
|
+
if (autoPublishHeld(store, taskId) === null) {
|
|
90
|
+
throw new Error("Release publication hold failed during restore");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const chatBindings = count(store, "SELECT count(*) AS n FROM chat_binding WHERE revoked IS NULL");
|
|
94
|
+
const chatPairings = count(store, "SELECT count(*) AS n FROM chat_pair WHERE consumed IS NULL");
|
|
95
|
+
const chatActions = openChatActions(store);
|
|
96
|
+
const stamp = now.toISOString();
|
|
97
|
+
for (const provider of CHAT_PROVIDERS) {
|
|
98
|
+
const chat = new ChatCore(store, provider);
|
|
99
|
+
for (const row of chat.prepare("SELECT id FROM chat_binding WHERE provider = :provider AND revoked IS NULL").all()) {
|
|
100
|
+
chat.revokeBinding({ id: Number(row["id"]) }, now, actor);
|
|
101
|
+
}
|
|
102
|
+
chat.prepare("UPDATE chat_room SET revoked = ?, revoked_by = ? WHERE provider = :provider AND revoked IS NULL").run(stamp, actor);
|
|
103
|
+
}
|
|
104
|
+
store.handle.prepare("UPDATE chat_pair SET consumed = ? WHERE consumed IS NULL").run(stamp);
|
|
105
|
+
for (const table of CHAT_ACTION_TABLES)
|
|
106
|
+
store.handle.prepare(`UPDATE ${table} SET consumed = ? WHERE consumed IS NULL`).run(stamp);
|
|
107
|
+
for (const table of CHAT_DECIDE_TABLES)
|
|
108
|
+
store.handle.prepare(`UPDATE ${table} SET consumed_at = ? WHERE consumed_at IS NULL`).run(stamp);
|
|
109
|
+
store.handle.prepare("UPDATE chat_note_draft SET state = 'discarded' WHERE state IN ('pending', 'armed')").run();
|
|
110
|
+
const afterIdentity = store.workspaceIdentity();
|
|
111
|
+
if (afterIdentity.id !== identity.id || afterIdentity.recoveryGeneration !== nextGeneration || excluded.has(afterIdentity.recoveryGeneration)) {
|
|
112
|
+
throw new Error("Restored workspace identity postcondition failed");
|
|
113
|
+
}
|
|
114
|
+
const stillAllowed = store.handle.prepare(`
|
|
115
|
+
SELECT count(*) AS n FROM action_ledger a
|
|
116
|
+
JOIN (
|
|
117
|
+
SELECT max(id) AS id FROM action_ledger
|
|
118
|
+
WHERE task_id IS NOT NULL AND action IN (?, ?)
|
|
119
|
+
GROUP BY task_id
|
|
120
|
+
) latest ON latest.id = a.id
|
|
121
|
+
WHERE a.action = ?
|
|
122
|
+
`).get(PUBLISH_HELD_ACTION, PUBLISH_ALLOWED_ACTION, PUBLISH_ALLOWED_ACTION);
|
|
123
|
+
if (Number(stillAllowed?.["n"] ?? 0) !== 0
|
|
124
|
+
|| count(store, "SELECT count(*) AS n FROM credential WHERE revoked_at IS NULL") !== 0
|
|
125
|
+
|| count(store, "SELECT count(*) AS n FROM web_session") !== 0
|
|
126
|
+
|| count(store, "SELECT (SELECT count(*) FROM oauth_code) + (SELECT count(*) FROM oauth_grant) + (SELECT count(*) FROM oauth_refresh) AS n") !== 0
|
|
127
|
+
|| count(store, "SELECT count(*) AS n FROM publication_grant WHERE revoked_at IS NULL") !== 0
|
|
128
|
+
|| count(store, "SELECT count(*) AS n FROM intake_grant WHERE revoked_at IS NULL") !== 0
|
|
129
|
+
|| count(store, "SELECT count(*) AS n FROM coordinator_proposal WHERE state IN ('pending', 'confirming')") !== 0
|
|
130
|
+
|| count(store, "SELECT count(*) AS n FROM chat_binding WHERE revoked IS NULL") !== 0
|
|
131
|
+
|| count(store, "SELECT count(*) AS n FROM chat_room WHERE revoked IS NULL") !== 0
|
|
132
|
+
|| count(store, "SELECT count(*) AS n FROM chat_pair WHERE consumed IS NULL") !== 0
|
|
133
|
+
|| openChatActions(store) !== 0) {
|
|
134
|
+
throw new Error("Restored credential retirement postcondition failed");
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
workspaceId: afterIdentity.id,
|
|
138
|
+
previousRecoveryGeneration: identity.recoveryGeneration,
|
|
139
|
+
recoveryGeneration: afterIdentity.recoveryGeneration,
|
|
140
|
+
apiTokens,
|
|
141
|
+
leadCredentials,
|
|
142
|
+
coordinatorCredentials,
|
|
143
|
+
oauthRows,
|
|
144
|
+
webSessions: sessions.length,
|
|
145
|
+
publicationGrants,
|
|
146
|
+
intakeGrants,
|
|
147
|
+
releaseHolds,
|
|
148
|
+
chatBindings,
|
|
149
|
+
chatPairings,
|
|
150
|
+
chatActions,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { keepCheckScreenshots } from "./check-screenshots.js";
|
|
2
|
+
import { CHECK_RECOVERY_HELD, readCheckRecoveryHoldsForRun } from "./check-recovery-hold.js";
|
|
1
3
|
import { widerThan } from "./check-access.js";
|
|
2
4
|
import { recheckStanding } from "./check-only-standing.js";
|
|
3
5
|
import { actualCheckAccess, checkoutLaunchOf, checkoutRunner, ranAtLine, widestRan } from "./invoke.js";
|
|
@@ -129,6 +131,9 @@ function checkTarget(store, runId, level) {
|
|
|
129
131
|
}
|
|
130
132
|
export function requestFollowUpChecks(store, input, now) {
|
|
131
133
|
return store.transact(() => {
|
|
134
|
+
const blocked = recoveryCheckBlock(store, input.runId);
|
|
135
|
+
if (blocked !== null)
|
|
136
|
+
return refuse("recovery-held", CHECK_RECOVERY_MESSAGE);
|
|
132
137
|
const target = checkTarget(store, input.runId, input.level);
|
|
133
138
|
if (!target.ok)
|
|
134
139
|
return target;
|
|
@@ -148,48 +153,75 @@ export function waitingRequestsOfAnyKind(store, now) {
|
|
|
148
153
|
const runs = store.handle.prepare(`SELECT DISTINCT r.run_id AS run FROM action_ledger r WHERE r.action = ? AND r.run_id IS NOT NULL
|
|
149
154
|
AND NOT EXISTS (SELECT 1 FROM action_ledger s WHERE s.run_id = r.run_id AND s.action = ? AND s.outcome = CAST(r.id AS TEXT)) ORDER BY r.id`)
|
|
150
155
|
.all(CHECKS_REQUESTED, CHECKS_STARTED).map(row => Number(row["run"]));
|
|
151
|
-
return runs.flatMap(runId => followUpChecksOf(store, runId, now).filter(one => one.state === "waiting"));
|
|
156
|
+
return runs.flatMap(runId => recoveryCheckBlock(store, runId) !== null ? [] : followUpChecksOf(store, runId, now).filter(one => one.state === "waiting"));
|
|
152
157
|
}
|
|
153
158
|
export async function runFollowUpCheck(store, root, request, deps = {}) {
|
|
154
159
|
const now = deps.now ?? (() => new Date());
|
|
155
160
|
const runner = deps.runner ?? execRun;
|
|
156
|
-
const
|
|
161
|
+
const cleanupGit = deps.git ?? hardenedGit(execRun);
|
|
157
162
|
const asked = store.handle.prepare("SELECT run_id FROM action_ledger WHERE id = ? AND action = ?").get(request, CHECKS_REQUESTED);
|
|
158
163
|
if (asked === undefined)
|
|
159
164
|
return null;
|
|
160
165
|
const runId = Number(asked["run_id"]);
|
|
161
166
|
const wanted = followUpChecksOf(store, runId, now()).find(one => one.request === request);
|
|
162
|
-
if (wanted === undefined
|
|
163
|
-
return
|
|
167
|
+
if (wanted === undefined)
|
|
168
|
+
return null;
|
|
169
|
+
const heldNow = () => {
|
|
170
|
+
const evidence = recoveryCheckBlock(store, runId);
|
|
171
|
+
return evidence === null ? null : { ...wanted, state: "recovery-held", priorState: wanted.state, note: CHECK_RECOVERY_MESSAGE, recovery: evidence, priorExecution: "unverified" };
|
|
172
|
+
};
|
|
173
|
+
const initiallyHeld = heldNow();
|
|
174
|
+
if (initiallyHeld !== null)
|
|
175
|
+
return initiallyHeld;
|
|
176
|
+
if (wanted.state !== "waiting")
|
|
177
|
+
return wanted;
|
|
164
178
|
const target = checkTarget(store, runId, wanted.level);
|
|
165
|
-
const finish = (status, detail) => {
|
|
166
|
-
|
|
179
|
+
const finish = (status, detail, stamp) => store.transact(() => {
|
|
180
|
+
const at = (stamp ?? now()).toISOString(), held = heldNow();
|
|
181
|
+
if (held !== null)
|
|
182
|
+
return held;
|
|
183
|
+
store.recordAction({ at, actor: "system", repo: target.ok ? target.repo : null, taskId: target.ok ? target.taskId : null, runId,
|
|
167
184
|
action: CHECKS_FINISHED, outcome: `${request}:${status}`, source: "work", detail });
|
|
168
185
|
store.bumpWake();
|
|
169
|
-
|
|
186
|
+
return null;
|
|
187
|
+
});
|
|
170
188
|
const claimed = store.transact(() => {
|
|
189
|
+
const at = now().toISOString(), held = heldNow();
|
|
190
|
+
if (held !== null)
|
|
191
|
+
return held;
|
|
171
192
|
if (store.handle.prepare("SELECT 1 FROM action_ledger WHERE run_id = ? AND action = ? AND outcome = ?").get(runId, CHECKS_STARTED, String(request)) !== undefined)
|
|
172
193
|
return false;
|
|
173
|
-
store.recordAction({ at
|
|
194
|
+
store.recordAction({ at, actor: "system", repo: target.ok ? target.repo : null, taskId: target.ok ? target.taskId : null, runId,
|
|
174
195
|
action: CHECKS_STARTED, outcome: String(request), source: "work", detail: `limit ${target.ok ? target.command.timeoutMs : 0}` });
|
|
175
196
|
return true;
|
|
176
197
|
});
|
|
177
|
-
if (
|
|
178
|
-
return
|
|
198
|
+
if (typeof claimed === "object")
|
|
199
|
+
return claimed;
|
|
200
|
+
if (!claimed) {
|
|
201
|
+
const stamp = now();
|
|
202
|
+
return heldNow() ?? followUpChecksOf(store, runId, stamp, root).find(one => one.request === request) ?? null;
|
|
203
|
+
}
|
|
179
204
|
if (!target.ok) {
|
|
180
|
-
finish("not-run", target.message);
|
|
181
|
-
return followUpChecksOf(store, runId, now(), root).find(one => one.request === request) ?? null;
|
|
205
|
+
const held = finish("not-run", target.message);
|
|
206
|
+
return held ?? followUpChecksOf(store, runId, now(), root).find(one => one.request === request) ?? null;
|
|
182
207
|
}
|
|
183
208
|
if (target.head !== wanted.head) {
|
|
184
|
-
finish("not-run", "The result's commit changed after checks were asked for.");
|
|
185
|
-
return followUpChecksOf(store, runId, now(), root).find(one => one.request === request) ?? null;
|
|
209
|
+
const held = finish("not-run", "The result's commit changed after checks were asked for.");
|
|
210
|
+
return held ?? followUpChecksOf(store, runId, now(), root).find(one => one.request === request) ?? null;
|
|
186
211
|
}
|
|
187
212
|
const authorized = wanted.why === "recheck" ? recheckStanding(store, { request, runId, head: target.head, digest: wanted.digest }) : null;
|
|
188
213
|
if (wanted.why === "recheck" && !authorized?.ok) {
|
|
189
|
-
finish("not-run", authorized?.problem ?? "Its authorization couldn't be read.");
|
|
190
|
-
return followUpChecksOf(store, runId, now(), root).find(one => one.request === request) ?? null;
|
|
214
|
+
const held = finish("not-run", authorized?.problem ?? "Its authorization couldn't be read.");
|
|
215
|
+
return held ?? followUpChecksOf(store, runId, now(), root).find(one => one.request === request) ?? null;
|
|
191
216
|
}
|
|
192
|
-
const
|
|
217
|
+
const proveLaunch = () => { const held = heldNow(); if (held !== null)
|
|
218
|
+
throw new CheckRecoveryBlocked(held); };
|
|
219
|
+
const guardedRunner = (file, args, options) => { proveLaunch(); return runner(file, args, options); };
|
|
220
|
+
const git = deps.git ?? hardenedGit((file, args, options) => { proveLaunch(); return execRun(file, args, options); });
|
|
221
|
+
const launched = (inner) => (file, args, options) => {
|
|
222
|
+
proveLaunch();
|
|
223
|
+
if (!authorized?.ok)
|
|
224
|
+
return inner(file, args, options);
|
|
193
225
|
if (widerThan(actualCheckAccess(store, checkoutLaunchOf(store, target.repo, [runId]).access), authorized.access))
|
|
194
226
|
return Promise.resolve({ code: 126, stdout: "", stderr: "", notFound: true, timedOut: false });
|
|
195
227
|
return inner(file, args, options);
|
|
@@ -201,10 +233,14 @@ export async function runFollowUpCheck(store, root, request, deps = {}) {
|
|
|
201
233
|
const bound = (text) => { const hits = scanForSecrets(text); return boundStreamHeadTail(hits.length > 0 ? redactSecretLines(text, hits) : text, 24 * 1024); };
|
|
202
234
|
const note = (label, command, result) => log.push(`=== ${label} ===\n$ ${command}\n(exit ${result.code}${result.notFound ? ", could not start" : ""}${result.timedOut ? ", timed out" : ""})\n\n--- stdout ---\n${bound(result.stdout)}\n\n--- stderr ---\n${bound(result.stderr)}`);
|
|
203
235
|
let result;
|
|
236
|
+
let heldControl = null, checkoutCreated = false;
|
|
204
237
|
try {
|
|
238
|
+
proveLaunch();
|
|
205
239
|
const added = await git("git", ["-C", target.repo, "worktree", "add", "--detach", checkout, target.head], { timeoutMs: 120_000 });
|
|
240
|
+
checkoutCreated = added.code === 0;
|
|
241
|
+
note("Checkout", `git worktree add --detach <fresh folder> ${target.head}`, added);
|
|
242
|
+
proveLaunch();
|
|
206
243
|
if (added.code !== 0) {
|
|
207
|
-
note("Checkout", `git worktree add --detach <fresh folder> ${target.head}`, added);
|
|
208
244
|
result = { ran: false, failure: "The commit couldn't be checked out. It may have been removed from this computer." };
|
|
209
245
|
}
|
|
210
246
|
else {
|
|
@@ -212,8 +248,9 @@ export async function runFollowUpCheck(store, root, request, deps = {}) {
|
|
|
212
248
|
let ready = true;
|
|
213
249
|
if (setup !== null) {
|
|
214
250
|
const shell = approvedCommandShell(setup.command);
|
|
215
|
-
const prepared = await runWithIsolatedDatabase(launched(checkoutRunner(store, target.repo, checkout,
|
|
251
|
+
const prepared = await runWithIsolatedDatabase(launched(checkoutRunner(store, target.repo, checkout, guardedRunner, [runId], level => ranAt.push(level))), shell.file, shell.args, { cwd: checkout, timeoutMs: setup.timeoutMs, processGroup: true, envAllowlist: SETUP_ENV_ALLOWLIST, omitEnv: SETUP_ENV_DENYLIST });
|
|
216
252
|
note("Approved project setup", setup.command, prepared);
|
|
253
|
+
proveLaunch();
|
|
217
254
|
if (prepared.code !== 0 || prepared.timedOut || prepared.notFound) {
|
|
218
255
|
ready = false;
|
|
219
256
|
result = { ran: false, failure: "The project's setup failed, so the check didn't run." };
|
|
@@ -226,8 +263,14 @@ export async function runFollowUpCheck(store, root, request, deps = {}) {
|
|
|
226
263
|
}
|
|
227
264
|
else {
|
|
228
265
|
const shell = approvedCommandShell(live.command);
|
|
229
|
-
const ran = await runWithIsolatedDatabase(launched(checkoutRunner(store, target.repo, checkout,
|
|
266
|
+
const ran = await runWithIsolatedDatabase(launched(checkoutRunner(store, target.repo, checkout, guardedRunner, [runId], level => ranAt.push(level))), shell.file, shell.args, { cwd: checkout, timeoutMs: live.timeoutMs, processGroup: true, envAllowlist: SETUP_ENV_ALLOWLIST, omitEnv: SETUP_ENV_DENYLIST });
|
|
230
267
|
note(`${CHECK_LEVEL_WORDS[target.level]} check`, live.command, ran);
|
|
268
|
+
proveLaunch();
|
|
269
|
+
if (!ran.timedOut && !ran.notFound) {
|
|
270
|
+
const kept = keepCheckScreenshots(store, root, runId, checkout, target.head, now());
|
|
271
|
+
if (kept.length > 0)
|
|
272
|
+
log.push(`=== Screenshots ===\n${kept.join("\n")}`);
|
|
273
|
+
}
|
|
231
274
|
result = ran.timedOut ? { ran: false, failure: "The check ran out of time." } : ran.notFound ? { ran: false, failure: "The check couldn't start." } : { ran: true, exitCode: ran.code };
|
|
232
275
|
}
|
|
233
276
|
}
|
|
@@ -235,33 +278,52 @@ export async function runFollowUpCheck(store, root, request, deps = {}) {
|
|
|
235
278
|
result ??= { ran: false, failure: "The project's setup failed, so the check didn't run." };
|
|
236
279
|
}
|
|
237
280
|
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
if (!(error instanceof CheckRecoveryBlocked))
|
|
283
|
+
throw error;
|
|
284
|
+
heldControl = error.control;
|
|
285
|
+
}
|
|
238
286
|
finally {
|
|
239
|
-
|
|
287
|
+
if (checkoutCreated)
|
|
288
|
+
await cleanupGit("git", ["-C", target.repo, "worktree", "remove", "--force", checkout], { timeoutMs: 120_000 }).catch(() => null);
|
|
240
289
|
rmSync(folder, { recursive: true, force: true });
|
|
241
290
|
}
|
|
242
291
|
const at = now();
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
292
|
+
const saveHeldLog = (held) => {
|
|
293
|
+
const logArtifactId = log.length === 0 ? null : storeEvidence(store, root, runId, "structured-output", `follow-up-check-${request}-held.log`, Buffer.from(log.join("\n\n"), "utf8"), FOLLOW_UP_LOG, at, { captureStatus: "ok" });
|
|
294
|
+
return { ...held, logArtifactId };
|
|
295
|
+
};
|
|
296
|
+
heldControl ??= heldNow();
|
|
297
|
+
if (heldControl !== null)
|
|
298
|
+
return saveHeldLog(heldControl);
|
|
299
|
+
return store.transact(() => {
|
|
300
|
+
const settledHeld = heldNow();
|
|
301
|
+
if (settledHeld !== null)
|
|
302
|
+
return saveHeldLog(settledHeld);
|
|
303
|
+
const ranLine = ranAtLine(widestRan(ranAt));
|
|
304
|
+
if (ranLine !== null)
|
|
305
|
+
log.push(ranLine);
|
|
306
|
+
const text = log.length === 0 ? "No command started." : log.join("\n\n");
|
|
307
|
+
const logId = storeEvidence(store, root, runId, "structured-output", `follow-up-check-${request}.log`, Buffer.from(text, "utf8"), FOLLOW_UP_LOG, at, { captureStatus: "ok" });
|
|
308
|
+
const logArtifact = store.getArtifact(logId);
|
|
309
|
+
const receipt = JSON.stringify({ version: 1, request, run: runId, head: target.head, tested: target.head, level: target.level, checkAccess: widestRan(ranAt),
|
|
310
|
+
command: { repo: target.command.repo, command: target.command.command, digest: target.command.digest, approvedBy: target.command.approvedBy },
|
|
311
|
+
result, log: { artifactId: logArtifact.id, sha256: logArtifact.sha256, bytesStored: logArtifact.bytesStored, truncated: logArtifact.truncated } }, null, 1);
|
|
312
|
+
storeEvidence(store, root, runId, "structured-output", `follow-up-check-${request}.json`, Buffer.from(receipt, "utf8"), FOLLOW_UP_RECEIPT, at, { captureStatus: "ok" });
|
|
313
|
+
if (result.ran)
|
|
314
|
+
finish(result.exitCode === 0 ? "passed" : "failed", `${CHECK_LEVEL_WORDS[target.level]} checks on ${target.head.slice(0, 7)} · exit ${result.exitCode}`, at);
|
|
315
|
+
else
|
|
316
|
+
finish("not-run", result.failure, at);
|
|
317
|
+
return followUpChecksOf(store, runId, at, root).find(one => one.request === request) ?? null;
|
|
318
|
+
});
|
|
258
319
|
}
|
|
259
320
|
export async function runWaitingChecks(store, root, deps = {}) {
|
|
260
321
|
let ran = 0;
|
|
261
322
|
for (const one of waitingCheckRequests(store, (deps.now ?? (() => new Date()))())) {
|
|
262
323
|
if (deps.shouldStop?.() === true)
|
|
263
324
|
break;
|
|
264
|
-
|
|
325
|
+
const done = await runFollowUpCheck(store, root, one.request, deps);
|
|
326
|
+
if (done !== null && done.state !== "waiting" && done.state !== "recovery-held")
|
|
265
327
|
ran++;
|
|
266
328
|
}
|
|
267
329
|
return ran;
|
|
@@ -291,6 +353,9 @@ export function resultCheckLevel(store, runId, now) {
|
|
|
291
353
|
return read.level;
|
|
292
354
|
}
|
|
293
355
|
export function fullCheckGate(store, runId, now) {
|
|
356
|
+
const held = recoveryCheckBlock(store, runId);
|
|
357
|
+
if (held !== null)
|
|
358
|
+
return { state: "recovery-held", message: CHECK_RECOVERY_MESSAGE, recovery: held, priorExecution: "unverified" };
|
|
294
359
|
const level = runCheckLevel(store, runId);
|
|
295
360
|
const repo = repoOfRun(store, runId);
|
|
296
361
|
const run = store.getRun(runId);
|
|
@@ -385,3 +450,17 @@ function changedFilesOf(store, root, runId) {
|
|
|
385
450
|
return [];
|
|
386
451
|
}
|
|
387
452
|
}
|
|
453
|
+
const CHECK_RECOVERY_MESSAGE = "Checks are on hold after recovery. Earlier execution is unverified.";
|
|
454
|
+
class CheckRecoveryBlocked extends Error {
|
|
455
|
+
control;
|
|
456
|
+
constructor(control) {
|
|
457
|
+
super(CHECK_RECOVERY_MESSAGE);
|
|
458
|
+
this.control = control;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function recoveryCheckBlock(store, runId) {
|
|
462
|
+
if (store.handle.prepare("SELECT 1 FROM action_ledger WHERE action = ? LIMIT 1").get(CHECK_RECOVERY_HELD) === undefined)
|
|
463
|
+
return null;
|
|
464
|
+
const evidence = readCheckRecoveryHoldsForRun(store, runId);
|
|
465
|
+
return evidence.kind === "no-evidence" ? null : evidence;
|
|
466
|
+
}
|
package/dist/route-change.js
CHANGED
|
@@ -2,10 +2,29 @@ import { providerName } from "./provider-auth.js";
|
|
|
2
2
|
import { legOf, routeDigestOf, routeFromJson } from "./phase-routing.js";
|
|
3
3
|
import { deployGateScope, releaseCheckScope } from "./scope.js";
|
|
4
4
|
import { BUILT_IN } from "./store.js";
|
|
5
|
+
import { repositoryEcosystems, resolveNetwork } from "./egress.js";
|
|
5
6
|
const ROLE = { plan: "planner", build: "builder", repair: "repair agent", review: "reviewer" };
|
|
6
7
|
const named = (one) => `${providerName(one.provider)} ${one.model ?? "(its default model)"}`;
|
|
7
8
|
const billing = (mode) => mode === "api-key" ? "API key" : mode === "subscription" ? "subscription" : null;
|
|
8
|
-
export function
|
|
9
|
+
export function networkChangeWords(was, now) {
|
|
10
|
+
if (was == null || now == null)
|
|
11
|
+
return [];
|
|
12
|
+
const out = [];
|
|
13
|
+
if (was.mode !== now.mode)
|
|
14
|
+
out.push(now.mode === "open" ? "builds may now reach any host" : "builds now reach only their allowed hosts");
|
|
15
|
+
else if (now.mode === "allowlist") {
|
|
16
|
+
const added = now.hosts.filter(one => !was.hosts.includes(one)), gone = was.hosts.filter(one => !now.hosts.includes(one));
|
|
17
|
+
if (added.length > 0)
|
|
18
|
+
out.push(`builds may now also reach ${added.join(", ")}`);
|
|
19
|
+
if (gone.length > 0)
|
|
20
|
+
out.push(`builds no longer reach ${gone.join(", ")}`);
|
|
21
|
+
}
|
|
22
|
+
if (was.loopback !== now.loopback)
|
|
23
|
+
out.push(now.loopback === "any" ? "builds may now reach this Mac's local services" : "builds no longer reach this Mac's local services");
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
const sentence = (clauses) => clauses.length === 0 ? "" : `${clauses[0].charAt(0).toUpperCase()}${clauses.join("; ").slice(1)}`;
|
|
27
|
+
export function routeChangeWords(sealed, next, network = []) {
|
|
9
28
|
const changes = [];
|
|
10
29
|
for (const phase of ["build", "plan", "repair", "review"]) {
|
|
11
30
|
const now = legOf(next.route, phase);
|
|
@@ -24,9 +43,11 @@ export function routeChangeWords(sealed, next) {
|
|
|
24
43
|
}
|
|
25
44
|
const from = billing(sealed.authMode), to = billing(next.authMode);
|
|
26
45
|
const paid = from !== null && to !== null && from !== to ? ` (${from} → ${to})` : "";
|
|
27
|
-
if (changes.length === 0)
|
|
46
|
+
if (changes.length === 0 && network.length === 0)
|
|
28
47
|
return "The agents' settings changed since you approved this. Approve to continue.";
|
|
29
|
-
|
|
48
|
+
if (changes.length === 0)
|
|
49
|
+
return `${sentence(network)}. Approve to continue.`;
|
|
50
|
+
return `${changes.join("; ")}${paid}${network.length === 0 ? "" : `; ${network.join("; ")}`}. Approve to continue.`;
|
|
30
51
|
}
|
|
31
52
|
export function proposeNewRoute(store, taskRef, taskId, now) {
|
|
32
53
|
return store.transact(() => {
|
|
@@ -44,7 +65,7 @@ export function proposeNewRoute(store, taskRef, taskId, now) {
|
|
|
44
65
|
return null;
|
|
45
66
|
const lastBilled = store.runsFor(taskRef).find(one => one.role === "builder")?.authMode ?? null;
|
|
46
67
|
const billed = store.agentsFor([legOf(route, "build").provider])[0]?.billing ?? null;
|
|
47
|
-
const words = routeChangeWords({ route: sealedRoute, profile: before.approvedProfile ?? null, authMode: lastBilled }, { route, authMode: billed });
|
|
68
|
+
const words = routeChangeWords({ route: sealedRoute, profile: before.approvedProfile ?? null, authMode: lastBilled }, { route, authMode: billed }, networkChangeWords(before.approvedProfile?.network, refiled.profile?.network));
|
|
48
69
|
store.handle.prepare(`INSERT INTO route_change (task_ref, scope_digest, to_route_digest, words, created_at) VALUES (?, ?, ?, ?, ?)
|
|
49
70
|
ON CONFLICT (task_ref) DO UPDATE SET scope_digest = excluded.scope_digest, to_route_digest = excluded.to_route_digest, words = excluded.words, created_at = excluded.created_at`)
|
|
50
71
|
.run(taskRef, refiled.digest, routeDigestOf(route), words, now.toISOString());
|
|
@@ -71,3 +92,22 @@ export function routeLegacyPlans(store, now) {
|
|
|
71
92
|
routed++;
|
|
72
93
|
return routed;
|
|
73
94
|
}
|
|
95
|
+
export function proposeNetworkChanges(store, repo, now) {
|
|
96
|
+
const rows = store.handle.prepare(`SELECT r.id AS ref, r.external_id AS task FROM task_scope s JOIN task_ref r ON r.external_id = s.task_id AND r.backend = ?
|
|
97
|
+
JOIN task t ON t.id = r.external_id WHERE r.repo = ? AND t.state IN ('queued', 'failed') AND s.approved_digest = s.digest`).all(BUILT_IN, repo);
|
|
98
|
+
if (rows.length === 0)
|
|
99
|
+
return 0;
|
|
100
|
+
const project = store.projectNetwork(repo);
|
|
101
|
+
const ecosystems = repositoryEcosystems(repo);
|
|
102
|
+
let proposed = 0;
|
|
103
|
+
for (const row of rows) {
|
|
104
|
+
const sealed = store.getScope(String(row["task"]))?.approvedProfile;
|
|
105
|
+
if (sealed == null)
|
|
106
|
+
continue;
|
|
107
|
+
if (networkChangeWords(sealed.network, resolveNetwork(sealed.provider, project, ecosystems)).length === 0)
|
|
108
|
+
continue;
|
|
109
|
+
if (proposeNewRoute(store, Number(row["ref"]), String(row["task"]), now) !== null)
|
|
110
|
+
proposed++;
|
|
111
|
+
}
|
|
112
|
+
return proposed;
|
|
113
|
+
}
|
package/dist/scope.js
CHANGED
|
@@ -4,6 +4,8 @@ import { cardShowsScope, cardTermsDigest } from "./chat-terms.js";
|
|
|
4
4
|
import { mintSecret } from "./secret-mint.js";
|
|
5
5
|
import { sessionStandsIn } from "./install-mode.js";
|
|
6
6
|
import { laptopShipSealAllowed } from "./flexible-laptop.js";
|
|
7
|
+
import { directChatShipSealAllowed } from "./direct-chat-laptop.js";
|
|
8
|
+
import { agentOnlyChange } from "./agent-change-check.js";
|
|
7
9
|
import { passwordlessOn } from "./passwordless.js";
|
|
8
10
|
import { routeChangeProblem } from "./route-change-check.js";
|
|
9
11
|
import { issueImported } from "./task-source.js";
|
|
@@ -764,9 +766,13 @@ export function approve(store, taskId, by, now, sawDigest, token, mutation = {},
|
|
|
764
766
|
if (authenticated.method === "local-owner") {
|
|
765
767
|
const laptopShip = local !== null && local.act === "ship-thread" && chat === undefined && fastStart === undefined
|
|
766
768
|
&& laptopShipSealAllowed(store, { by, taskId, candidate: store.getScope(taskId)?.candidate ?? null });
|
|
767
|
-
|
|
769
|
+
const directChatShip = local !== null && local.act === "direct-chat-ship" && chat === undefined && fastStart === undefined
|
|
770
|
+
&& directChatShipSealAllowed(store, { by, taskId, candidate: store.getScope(taskId)?.candidate ?? null });
|
|
771
|
+
const agentChange = local !== null && local.act === "change-task-agents" && chat === undefined && fastStart === undefined
|
|
772
|
+
&& agentChangeSealAllowed(store, by, taskId);
|
|
773
|
+
if (local === null || (local.act !== "approve-plan" && !(local.act === "build-now" && fastStart !== undefined) && !laptopShip && !directChatShip && !agentChange))
|
|
768
774
|
return { ok: false, reason: "policy", message: localOwnerRefusal(store.accountOf(by)?.passwordSet === true, "/").message };
|
|
769
|
-
const eligible = laptopShip ? localWorkEligible(store, by, taskId, { act: "ship" }) : localApprovalEligible(store, by, taskId);
|
|
775
|
+
const eligible = (laptopShip || directChatShip) ? localWorkEligible(store, by, taskId, { act: "ship" }) : localApprovalEligible(store, by, taskId);
|
|
770
776
|
if (!eligible.ok)
|
|
771
777
|
return { ok: false, reason: "policy", message: eligible.message };
|
|
772
778
|
}
|
|
@@ -1219,6 +1225,17 @@ const LOCAL_PLAN_WORDS = {
|
|
|
1219
1225
|
unsandboxed: "This project's checks run without a sandbox, so planning needs your password.",
|
|
1220
1226
|
imported: "A task from outside needs your password to plan.",
|
|
1221
1227
|
};
|
|
1228
|
+
const LOCAL_AGENTS_WORDS = {
|
|
1229
|
+
"local-mode-off": "Local mode is off, so changing this task's models needs your password.",
|
|
1230
|
+
"not-owner": "Only this computer's owner changes a task's models here without a password.",
|
|
1231
|
+
"no-scope": "This task has no plan yet.",
|
|
1232
|
+
release: "Changing a release's models needs your password.",
|
|
1233
|
+
protected: "This is protected work, so changing its models needs your password.",
|
|
1234
|
+
escalated: "Work with wider permissions needs your password to change its models.",
|
|
1235
|
+
coordinator: "Work a coordinator filed needs your password to change its models.",
|
|
1236
|
+
unsandboxed: "This project's checks run without a sandbox, so changing models needs your password.",
|
|
1237
|
+
imported: "A task from outside needs your password to change its models.",
|
|
1238
|
+
};
|
|
1222
1239
|
const LOCAL_RETRY_WORDS = {
|
|
1223
1240
|
"local-mode-off": "Local mode is off, so retrying needs your password.",
|
|
1224
1241
|
"not-owner": "Only this computer's owner retries builds here without a password.",
|
|
@@ -1243,7 +1260,7 @@ const LOCAL_REVISE_WORDS = {
|
|
|
1243
1260
|
};
|
|
1244
1261
|
export function localWorkEligible(store, by, taskId, purpose) {
|
|
1245
1262
|
const words = purpose.act === "approve" || purpose.act === "ship" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "revise" ? LOCAL_REVISE_WORDS
|
|
1246
|
-
: purpose.act === "plan" ? LOCAL_PLAN_WORDS : LOCAL_RETRY_WORDS;
|
|
1263
|
+
: purpose.act === "plan" ? LOCAL_PLAN_WORDS : purpose.act === "agents" ? LOCAL_AGENTS_WORDS : LOCAL_RETRY_WORDS;
|
|
1247
1264
|
const no = (reason) => ({ ok: false, reason, message: words[reason] });
|
|
1248
1265
|
if (!localModeOn(store))
|
|
1249
1266
|
return no("local-mode-off");
|
|
@@ -1265,7 +1282,7 @@ export function localWorkEligible(store, by, taskId, purpose) {
|
|
|
1265
1282
|
if (scope.profile == null || levelOfProfile(scope.profile) === "escalated")
|
|
1266
1283
|
return no("escalated");
|
|
1267
1284
|
}
|
|
1268
|
-
else if (purpose.act === "plan") {
|
|
1285
|
+
else if (purpose.act === "plan" || purpose.act === "agents") {
|
|
1269
1286
|
const gate = store.approvalGate(taskId, by, "person");
|
|
1270
1287
|
if (gate.verdict !== "seal" || gate.protectedWork)
|
|
1271
1288
|
return no("protected");
|
|
@@ -1282,7 +1299,7 @@ export function localWorkEligible(store, by, taskId, purpose) {
|
|
|
1282
1299
|
return no("coordinator");
|
|
1283
1300
|
if (purpose.act === "complete" || purpose.act === "revise")
|
|
1284
1301
|
return { ok: true };
|
|
1285
|
-
if ((purpose.act === "plan" || purpose.act === "retry") && issueImported(store, taskId))
|
|
1302
|
+
if ((purpose.act === "plan" || purpose.act === "agents" || purpose.act === "retry") && issueImported(store, taskId))
|
|
1286
1303
|
return no("imported");
|
|
1287
1304
|
const stored = ref["repo"] == null ? undefined : store.handle.prepare("SELECT level FROM project_check_access WHERE repo = ?").get(ref["repo"])?.["level"];
|
|
1288
1305
|
if (stored === "unsandboxed" || scope?.profile?.checkAccess === "unsandboxed")
|
|
@@ -1292,3 +1309,43 @@ export function localWorkEligible(store, by, taskId, purpose) {
|
|
|
1292
1309
|
export function typedPasswordNow(proved) {
|
|
1293
1310
|
return proved.ok && proved.method === "password-now";
|
|
1294
1311
|
}
|
|
1312
|
+
export function agentChangeToolsUnchanged(store, taskId, approvedDigest) {
|
|
1313
|
+
const repo = store.lookupRef(taskId)?.repo ?? null;
|
|
1314
|
+
if (repo === null)
|
|
1315
|
+
return false;
|
|
1316
|
+
const row = store.handle.prepare("SELECT tools_json FROM tool_seal WHERE task = ? AND approved_digest = ?").get(taskId, approvedDigest);
|
|
1317
|
+
if (row === undefined || typeof row["tools_json"] !== "string")
|
|
1318
|
+
return false;
|
|
1319
|
+
let sealed;
|
|
1320
|
+
try {
|
|
1321
|
+
sealed = JSON.parse(row["tools_json"]);
|
|
1322
|
+
}
|
|
1323
|
+
catch {
|
|
1324
|
+
return false;
|
|
1325
|
+
}
|
|
1326
|
+
if (!Array.isArray(sealed))
|
|
1327
|
+
return false;
|
|
1328
|
+
const seen = [];
|
|
1329
|
+
for (const one of sealed) {
|
|
1330
|
+
const entry = one;
|
|
1331
|
+
if (entry === null || typeof entry !== "object" || typeof entry.name !== "string" || typeof entry.digest !== "string")
|
|
1332
|
+
return false;
|
|
1333
|
+
seen.push(JSON.stringify([entry.name, entry.digest]));
|
|
1334
|
+
}
|
|
1335
|
+
const today = store.projectTools(repo).map(one => JSON.stringify([one.name, one.digest]));
|
|
1336
|
+
if (seen.length !== today.length)
|
|
1337
|
+
return false;
|
|
1338
|
+
seen.sort();
|
|
1339
|
+
today.sort();
|
|
1340
|
+
return seen.every((one, index) => one === today[index]);
|
|
1341
|
+
}
|
|
1342
|
+
export function agentChangeSealAllowed(store, by, taskId) {
|
|
1343
|
+
const scope = store.getScope(taskId);
|
|
1344
|
+
if (scope === null || scope.approvedAt === null || scope.approvedDigest === null || scope.approvedDigest === scope.digest)
|
|
1345
|
+
return false;
|
|
1346
|
+
if (scope.approvedBy !== by || (scope.approvalBasis !== "password" && scope.approvalBasis !== "chat"))
|
|
1347
|
+
return false;
|
|
1348
|
+
if (!agentChangeToolsUnchanged(store, taskId, scope.approvedDigest))
|
|
1349
|
+
return false;
|
|
1350
|
+
return agentOnlyChange({ routeJson: scope.approvedRouteJson, profile: scope.approvedProfile, chainJson: scope.approvedChainJson }, { routeJson: scope.proposedRouteJson, profile: scope.profile, chainJson: scope.proposedChainJson }, provider => store.agentsFor([provider])[0]?.billing ?? null).ok;
|
|
1351
|
+
}
|