tryharness 0.7.68 → 0.7.69
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/lib/boardProtocol.json +47 -64
- package/lib/cards.mjs +13 -1
- package/lib/comfyExecution.mjs +545 -0
- package/lib/coordinator.mjs +201 -13
- package/lib/daemon.mjs +142 -6
- package/lib/dispatchContract.json +313 -0
- package/lib/dispatchTools.js +87 -0
- package/lib/dispatches.mjs +975 -0
- package/lib/localAgentAsk.mjs +27 -4
- package/lib/machineRoutes.mjs +5 -0
- package/lib/machineRuns.mjs +2 -1
- package/lib/mcp-stdio.mjs +41 -0
- package/lib/ownMachines.mjs +177 -23
- package/lib/promptDecider.mjs +471 -0
- package/lib/promptFlow.mjs +562 -0
- package/lib/promptScopes.mjs +670 -0
- package/lib/provenance.mjs +3 -2
- package/lib/runAuthority.mjs +14 -2
- package/lib/runBrief.mjs +1 -1
- package/lib/runWorker.mjs +25 -5
- package/lib/runner.mjs +62 -6
- package/lib/store.mjs +225 -13
- package/lib/taskCommands.mjs +125 -1
- package/lib/team.json +10 -0
- package/lib/team.mjs +270 -14
- package/lib/threadBriefs.mjs +30 -29
- package/lib/threadRuns.mjs +47 -3
- package/npm-shrinkwrap.json +10 -10
- package/package.json +3 -3
- package/release.json +31 -24
package/lib/runAuthority.mjs
CHANGED
|
@@ -120,7 +120,7 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
120
120
|
);
|
|
121
121
|
const standingRules = () => store.standing(runners(), startOfToday());
|
|
122
122
|
// null when the run may start now; otherwise why it waits for the person.
|
|
123
|
-
const standingVerdict = ({ trust, target, workspace }) => {
|
|
123
|
+
const standingVerdict = ({ trust, target, workspace, capacity = true }) => {
|
|
124
124
|
if (trust !== "user")
|
|
125
125
|
return "Another agent wrote it, so it never starts without the person.";
|
|
126
126
|
const rule = standingRules().find((entry) => entry.agent === target);
|
|
@@ -132,7 +132,7 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
132
132
|
return rule.mode === "default"
|
|
133
133
|
? `${target} has not worked in ${workspace} before, so its first run there waits for the person.`
|
|
134
134
|
: `${workspace} is outside the folders ${target} may run in without asking (${rule.workspaces.join(", ")}).`;
|
|
135
|
-
if (rule.runs_today >= rule.daily_cap)
|
|
135
|
+
if (capacity && rule.runs_today >= rule.daily_cap)
|
|
136
136
|
return `${target} already started ${rule.runs_today} runs today without asking, its daily limit.`;
|
|
137
137
|
return null;
|
|
138
138
|
};
|
|
@@ -168,6 +168,18 @@ export function createRunAuthority({ store, installedAgents }) {
|
|
|
168
168
|
request[RUN_CALLER] = run;
|
|
169
169
|
if (!runMayAsk(command))
|
|
170
170
|
return "A run Harness started cannot do that; only the person can.";
|
|
171
|
+
if (
|
|
172
|
+
run.dispatchScope &&
|
|
173
|
+
!new Set([
|
|
174
|
+
"board.dispatch.workspace",
|
|
175
|
+
"board.dispatch.propose",
|
|
176
|
+
"board.dispatch.view",
|
|
177
|
+
"board.dispatch.apply",
|
|
178
|
+
"board.dispatch.scope.list",
|
|
179
|
+
"board.dispatch.scope.read",
|
|
180
|
+
]).has(command)
|
|
181
|
+
)
|
|
182
|
+
return "This run has only its scoped workspace and dispatch tools.";
|
|
171
183
|
if (run.restricted && command.startsWith("mcp."))
|
|
172
184
|
return "A restricted run reaches this computer's board, not the person's Harness.";
|
|
173
185
|
return null;
|
package/lib/runBrief.mjs
CHANGED
package/lib/runWorker.mjs
CHANGED
|
@@ -17,6 +17,7 @@ export const restrictedRun = (store, task) =>
|
|
|
17
17
|
export function createRunWorker({
|
|
18
18
|
RESCAN_MS,
|
|
19
19
|
authority,
|
|
20
|
+
dispatches = null,
|
|
20
21
|
briefs,
|
|
21
22
|
contextEngine,
|
|
22
23
|
installedAgents,
|
|
@@ -85,6 +86,8 @@ export function createRunWorker({
|
|
|
85
86
|
}
|
|
86
87
|
if (!RUNNERS.has(run.target_agent) || !run.run_workspace) return null;
|
|
87
88
|
if (!run.run_authorized_at) return `${who} waits for your Start.`;
|
|
89
|
+
const refusal = dispatches?.refusal(run.id);
|
|
90
|
+
if (refusal) return refusal;
|
|
88
91
|
if (runsHeld)
|
|
89
92
|
return `${who} starts when your Mac is no longer running with its lid closed.`;
|
|
90
93
|
const holder = activeRuns.get(slotOf({ ...run, parent_id: goalId }));
|
|
@@ -115,6 +118,7 @@ export function createRunWorker({
|
|
|
115
118
|
only: onlyItsOwn(),
|
|
116
119
|
})) {
|
|
117
120
|
const agent = task.target_agent;
|
|
121
|
+
if (dispatches?.refusal(task.id)) continue;
|
|
118
122
|
// Where a task runs is settled once, before its slot: a run T3 carries out holds its thread, not a folder.
|
|
119
123
|
if (task.kind === "task" && store.meta(`t3-run:${task.id}`) === null)
|
|
120
124
|
store.meta(`t3-run:${task.id}`, taskInT3(task, agent) ? "1" : "0");
|
|
@@ -156,7 +160,7 @@ export function createRunWorker({
|
|
|
156
160
|
resumeSession,
|
|
157
161
|
again,
|
|
158
162
|
t3: inT3,
|
|
159
|
-
} = await briefs.prepare(task, agent);
|
|
163
|
+
} = dispatches?.briefFor(task) ?? (await briefs.prepare(task, agent));
|
|
160
164
|
const startedAt = new Date().toISOString();
|
|
161
165
|
const stoppedFor = Boolean(again);
|
|
162
166
|
// The session it resumes is the run's from its first moment, so Open never resumes it beside the run before the
|
|
@@ -164,13 +168,25 @@ export function createRunWorker({
|
|
|
164
168
|
if (resumeSession && !task.session_id)
|
|
165
169
|
store.setRunSession(task.id, resumeSession);
|
|
166
170
|
const readOnly = store.meta(`review:${task.id}`) === "1";
|
|
167
|
-
const
|
|
171
|
+
const dispatchOptions = dispatches?.optionsFor(task) ?? {};
|
|
172
|
+
const restricted =
|
|
173
|
+
restrictedRun(store, task) || Boolean(dispatchOptions.dispatchScope);
|
|
168
174
|
// Work another person asked for runs with only this person's own agent settings: the repository's own (its
|
|
169
175
|
// .claude hooks, .pi, opencode.json) can be that person's, and would run here (security audit P4, October 25).
|
|
170
176
|
const ownSettingsOnly = store.meta(`other-person-run:${task.id}`) === "1";
|
|
171
177
|
const chosen = await modelForRun(task, agent);
|
|
172
178
|
store.setRunModel(task.id, chosen);
|
|
173
179
|
const { model, effort } = chosen;
|
|
180
|
+
// Preparation may await context/model selection. Recheck a queued dispatch
|
|
181
|
+
// immediately before any executor or secret-use grant receives the task.
|
|
182
|
+
const refusal = dispatches?.begin(task.id);
|
|
183
|
+
if (refusal) {
|
|
184
|
+
activeRuns.delete(slotOf(task));
|
|
185
|
+
store.requeueRun(task.id);
|
|
186
|
+
log(`board task ${task.id} held before execution: ${refusal}`);
|
|
187
|
+
notifyBoard(store.getTask(task.id));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
174
190
|
const t3 = inT3 ? t3Turn(task, agent, { model, effort }) : null;
|
|
175
191
|
// The person's environment grants (vault.mjs), never for a run they did not authorize: the values are in this
|
|
176
192
|
// run's environment, and what it says is scrubbed of them.
|
|
@@ -191,7 +207,11 @@ export function createRunWorker({
|
|
|
191
207
|
...(stoppedFor ? { again: true } : {}),
|
|
192
208
|
...(resumeSession && !t3 ? { resumeSession } : {}),
|
|
193
209
|
...(readOnly ? { readOnly } : {}),
|
|
194
|
-
...(
|
|
210
|
+
...(dispatchOptions.dispatchScope
|
|
211
|
+
? dispatchOptions
|
|
212
|
+
: restricted
|
|
213
|
+
? { restricted }
|
|
214
|
+
: {}),
|
|
195
215
|
...(ownSettingsOnly ? { ownSettingsOnly } : {}),
|
|
196
216
|
...(t3 ? { t3 } : {}),
|
|
197
217
|
...(granted ? { env: granted.env, scrub: granted.values } : {}),
|
|
@@ -244,11 +264,11 @@ export function createRunWorker({
|
|
|
244
264
|
setImmediate(runBoard);
|
|
245
265
|
if (extra?.usage) store.setRunUsage(task.id, extra.usage);
|
|
246
266
|
// Its changes are committed before it reports, so the audit of its report sees what was not.
|
|
247
|
-
commitRun(task);
|
|
267
|
+
if (!dispatchOptions.dispatchScope) commitRun(task);
|
|
248
268
|
// A run that failed without reaching its agent's own report ended early: the runner says why.
|
|
249
269
|
const reported = store.reportTask(task.id, agent, {
|
|
250
270
|
status: kind,
|
|
251
|
-
result: text || "",
|
|
271
|
+
result: dispatches?.resultFor(task, text || "") ?? (text || ""),
|
|
252
272
|
// Stopped for the person's steer (threadRuns.mjs): the person ended it, not the agent or its provider.
|
|
253
273
|
failure: store.meta(`steered:${task.id}`)
|
|
254
274
|
? "person"
|
package/lib/runner.mjs
CHANGED
|
@@ -22,8 +22,9 @@ const issueCapability = (task) => {
|
|
|
22
22
|
capabilities.set(token, {
|
|
23
23
|
id: task.runId,
|
|
24
24
|
agent: task.agent,
|
|
25
|
-
restricted: task.restricted === true,
|
|
25
|
+
restricted: task.restricted === true || Boolean(task.dispatchScope),
|
|
26
26
|
review: task.readOnly === true,
|
|
27
|
+
dispatchScope: task.dispatchScope ?? null,
|
|
27
28
|
});
|
|
28
29
|
return token;
|
|
29
30
|
};
|
|
@@ -316,12 +317,15 @@ const readOnlyClaude = (task) => [
|
|
|
316
317
|
// Codex's review: its read-only permission profile, with the same places denied to every command it runs (the run's
|
|
317
318
|
// own folder stays readable when it lies inside one) and no web search. Probed with `codex sandbox` 0.164: a denied
|
|
318
319
|
// file is "Operation not permitted", the folder reads, writes and the daemon's socket are refused.
|
|
319
|
-
const codexReview = (task, home = os.homedir()) => {
|
|
320
|
+
const codexReview = (task, executable, home = os.homedir()) => {
|
|
320
321
|
const places = Object.fromEntries(
|
|
321
322
|
secretPlaces(home).map((place) => [place, "deny"])
|
|
322
323
|
);
|
|
323
324
|
places[path.join(home, ".codex", "shell_snapshots")] = "read";
|
|
324
325
|
if (task.cwd) places[task.cwd] = "read";
|
|
326
|
+
// Standalone Codex lives inside its denied credential home and reexecutes
|
|
327
|
+
// itself to load AGENTS.md. Only its confirmed, resolved file needs access.
|
|
328
|
+
if (executable) places[executable] = "read";
|
|
325
329
|
const table = Object.entries(places)
|
|
326
330
|
.map(
|
|
327
331
|
([place, access]) => `${JSON.stringify(place)}=${JSON.stringify(access)}`
|
|
@@ -342,7 +346,54 @@ const codexReview = (task, home = os.homedir()) => {
|
|
|
342
346
|
/** The coding agents whose runs Harness can hold to read-only: only they review or audit. */
|
|
343
347
|
export const READ_ONLY_AGENTS = new Set(["claude-code", "codex"]);
|
|
344
348
|
|
|
345
|
-
export function agentInvocation(task) {
|
|
349
|
+
export function agentInvocation(task, { executable = null } = {}) {
|
|
350
|
+
if (task.dispatchScope) {
|
|
351
|
+
if (task.agent !== "claude-code")
|
|
352
|
+
throw new Error(
|
|
353
|
+
"No mediated workspace executor is registered for this agent"
|
|
354
|
+
);
|
|
355
|
+
const mcp = {
|
|
356
|
+
mcpServers: {
|
|
357
|
+
harness: {
|
|
358
|
+
command: process.execPath,
|
|
359
|
+
args: [
|
|
360
|
+
fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
|
|
361
|
+
"--agent",
|
|
362
|
+
"claude-code",
|
|
363
|
+
"--restricted",
|
|
364
|
+
"--scope",
|
|
365
|
+
task.dispatchScope,
|
|
366
|
+
],
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
return {
|
|
371
|
+
command: "claude",
|
|
372
|
+
args: [
|
|
373
|
+
"-p",
|
|
374
|
+
task.brief,
|
|
375
|
+
"--output-format",
|
|
376
|
+
"stream-json",
|
|
377
|
+
"--verbose",
|
|
378
|
+
...modelFlags(task),
|
|
379
|
+
"--tools",
|
|
380
|
+
"",
|
|
381
|
+
"--bare",
|
|
382
|
+
"--restricted",
|
|
383
|
+
"--allowedTools",
|
|
384
|
+
"mcp__harness__dispatch_work mcp__harness__scope_workspace",
|
|
385
|
+
"--permission-mode",
|
|
386
|
+
"dontAsk",
|
|
387
|
+
"--strict-mcp-config",
|
|
388
|
+
"--mcp-config",
|
|
389
|
+
JSON.stringify(mcp),
|
|
390
|
+
"--setting-sources",
|
|
391
|
+
"",
|
|
392
|
+
"--settings",
|
|
393
|
+
JSON.stringify({ disableAllHooks: true }),
|
|
394
|
+
],
|
|
395
|
+
};
|
|
396
|
+
}
|
|
346
397
|
if (task.agent === "claude-code") {
|
|
347
398
|
return {
|
|
348
399
|
command: "claude",
|
|
@@ -381,7 +432,7 @@ export function agentInvocation(task) {
|
|
|
381
432
|
);
|
|
382
433
|
if (task.agent === "codex") {
|
|
383
434
|
return {
|
|
384
|
-
command: "codex",
|
|
435
|
+
command: executable ?? "codex",
|
|
385
436
|
args: [
|
|
386
437
|
"exec",
|
|
387
438
|
...(task.resumeSession ? ["resume", task.resumeSession] : []),
|
|
@@ -392,7 +443,7 @@ export function agentInvocation(task) {
|
|
|
392
443
|
// read-only.
|
|
393
444
|
...(task.readOnly
|
|
394
445
|
? [
|
|
395
|
-
...codexReview(task),
|
|
446
|
+
...codexReview(task, executable),
|
|
396
447
|
"-c",
|
|
397
448
|
'approval_policy="never"',
|
|
398
449
|
"-c",
|
|
@@ -733,7 +784,12 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
733
784
|
const program = agentBinary(task.agent, invocation.command);
|
|
734
785
|
if (!program)
|
|
735
786
|
throw new Error(`${task.agent} is not installed on this computer.`);
|
|
736
|
-
|
|
787
|
+
// Seatbelt checks symlink traversal too: invoke the same exact file granted
|
|
788
|
+
// to the review helper, without exposing its installation directory.
|
|
789
|
+
invocation =
|
|
790
|
+
task.agent === "codex" && task.readOnly
|
|
791
|
+
? agentInvocation(task, { executable: fs.realpathSync(program) })
|
|
792
|
+
: { ...invocation, command: program };
|
|
737
793
|
} catch (error) {
|
|
738
794
|
if (capability) capabilities.delete(capability);
|
|
739
795
|
emit("failed", error.message, { failure: "start" });
|
package/lib/store.mjs
CHANGED
|
@@ -193,6 +193,12 @@ export function openStore(file) {
|
|
|
193
193
|
key text primary key,
|
|
194
194
|
value text not null
|
|
195
195
|
);
|
|
196
|
+
create table if not exists board_dispatch_advisories (
|
|
197
|
+
seq integer primary key autoincrement,
|
|
198
|
+
task_id text not null,
|
|
199
|
+
value text not null
|
|
200
|
+
);
|
|
201
|
+
create index if not exists dispatch_advisories_task on board_dispatch_advisories(task_id,seq);
|
|
196
202
|
create table if not exists board_agents (
|
|
197
203
|
agent text primary key,
|
|
198
204
|
last_seen_at text not null
|
|
@@ -665,6 +671,12 @@ export function openStore(file) {
|
|
|
665
671
|
};
|
|
666
672
|
|
|
667
673
|
const roomPostListeners = [];
|
|
674
|
+
const publishRoomPost = (goalId, post) => {
|
|
675
|
+
for (const listener of roomPostListeners)
|
|
676
|
+
try {
|
|
677
|
+
listener(goalId, post);
|
|
678
|
+
} catch {}
|
|
679
|
+
};
|
|
668
680
|
|
|
669
681
|
// When each agent last called the board, by computer. The buddy, every agent and the other computers call several
|
|
670
682
|
// times a second, and each write waits for the disk (4 s in every 50 on the owner's daemon, October 28), so the times
|
|
@@ -1177,14 +1189,16 @@ export function openStore(file) {
|
|
|
1177
1189
|
workspaces,
|
|
1178
1190
|
daily_cap: row ? Number(row.daily_cap) : DEFAULT_DAILY_RUNS,
|
|
1179
1191
|
set_at: row?.set_at || null,
|
|
1180
|
-
runs_today:
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1192
|
+
runs_today:
|
|
1193
|
+
Number(this.meta(`prompt-quota:${since}:${agent}`) || "0") +
|
|
1194
|
+
Number(
|
|
1195
|
+
execute(
|
|
1196
|
+
"get",
|
|
1197
|
+
"select count(*) as n from board_tasks where target_agent = ? and run_authorized_by = 'standing' and run_authorized_at >= ?",
|
|
1198
|
+
agent,
|
|
1199
|
+
since
|
|
1200
|
+
).n
|
|
1201
|
+
),
|
|
1188
1202
|
};
|
|
1189
1203
|
});
|
|
1190
1204
|
},
|
|
@@ -1201,6 +1215,141 @@ export function openStore(file) {
|
|
|
1201
1215
|
String(value)
|
|
1202
1216
|
);
|
|
1203
1217
|
},
|
|
1218
|
+
// Proposal identity, task and grant must appear together, even after a crash.
|
|
1219
|
+
dispatchTransaction(operation) {
|
|
1220
|
+
db.exec("begin immediate");
|
|
1221
|
+
try {
|
|
1222
|
+
const result = operation();
|
|
1223
|
+
db.exec("commit");
|
|
1224
|
+
return result;
|
|
1225
|
+
} catch (error) {
|
|
1226
|
+
if (db.inTransaction) db.exec("rollback");
|
|
1227
|
+
throw error;
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1230
|
+
appendDispatchAdvisory(id, value) {
|
|
1231
|
+
if (this.meta(`dispatch-advisories:${id}`)) this.dispatchAdvisories(id);
|
|
1232
|
+
execute(
|
|
1233
|
+
"run",
|
|
1234
|
+
"insert into board_dispatch_advisories(task_id,value) values(?,?)",
|
|
1235
|
+
id,
|
|
1236
|
+
JSON.stringify(value)
|
|
1237
|
+
);
|
|
1238
|
+
},
|
|
1239
|
+
dispatchAdvisories(id, before = null) {
|
|
1240
|
+
// Migrate the earlier unbounded meta array without losing its audit records.
|
|
1241
|
+
const key = `dispatch-advisories:${id}`;
|
|
1242
|
+
if (this.meta(key))
|
|
1243
|
+
this.dispatchTransaction(() => {
|
|
1244
|
+
for (const record of JSON.parse(this.meta(key) || "[]"))
|
|
1245
|
+
execute(
|
|
1246
|
+
"run",
|
|
1247
|
+
"insert into board_dispatch_advisories(task_id,value) values(?,?)",
|
|
1248
|
+
id,
|
|
1249
|
+
JSON.stringify(record)
|
|
1250
|
+
);
|
|
1251
|
+
execute("run", "delete from board_meta where key = ?", key);
|
|
1252
|
+
});
|
|
1253
|
+
const rows = execute(
|
|
1254
|
+
"all",
|
|
1255
|
+
"select seq,value from board_dispatch_advisories where task_id = ? and (? is null or seq < ?) order by seq desc limit 32",
|
|
1256
|
+
id,
|
|
1257
|
+
before,
|
|
1258
|
+
before
|
|
1259
|
+
);
|
|
1260
|
+
return {
|
|
1261
|
+
records: rows.map((row) => JSON.parse(row.value)),
|
|
1262
|
+
next_before: rows.length === 32 ? rows.at(-1).seq : null,
|
|
1263
|
+
};
|
|
1264
|
+
},
|
|
1265
|
+
// The task row is the durable execution outbox. Reserve its sole approved
|
|
1266
|
+
// start and authorize that same row atomically; a retry cannot create a task.
|
|
1267
|
+
commitTaskDispatch({
|
|
1268
|
+
id,
|
|
1269
|
+
expectedGrant,
|
|
1270
|
+
expectedVersion,
|
|
1271
|
+
nextGrant,
|
|
1272
|
+
targetAgent = null,
|
|
1273
|
+
scopeRef = null,
|
|
1274
|
+
expectedScope = null,
|
|
1275
|
+
nextScope = null,
|
|
1276
|
+
quota = null,
|
|
1277
|
+
}) {
|
|
1278
|
+
db.exec("begin immediate");
|
|
1279
|
+
try {
|
|
1280
|
+
const task = this.getTask(id);
|
|
1281
|
+
const key = `dispatch-grant:${id}`;
|
|
1282
|
+
const rule = quota
|
|
1283
|
+
? this.standing([quota.agent], quota.period)[0]
|
|
1284
|
+
: null;
|
|
1285
|
+
if (
|
|
1286
|
+
this.meta(key) !== expectedGrant ||
|
|
1287
|
+
task?.version !== expectedVersion ||
|
|
1288
|
+
task.status !== "open" ||
|
|
1289
|
+
task.run_authorized_at ||
|
|
1290
|
+
(scopeRef &&
|
|
1291
|
+
this.meta(`dispatch-scope:${scopeRef}`) !== expectedScope) ||
|
|
1292
|
+
(quota &&
|
|
1293
|
+
(quota.remaining < 1 ||
|
|
1294
|
+
this.meta(quota.key) !== quota.expected ||
|
|
1295
|
+
rule.daily_cap !== quota.limit ||
|
|
1296
|
+
rule.set_at !== quota.rule_epoch ||
|
|
1297
|
+
rule.mode !== quota.rule_mode ||
|
|
1298
|
+
rule.runs_today >= rule.daily_cap))
|
|
1299
|
+
) {
|
|
1300
|
+
db.exec("commit");
|
|
1301
|
+
return false;
|
|
1302
|
+
}
|
|
1303
|
+
if (targetAgent)
|
|
1304
|
+
execute(
|
|
1305
|
+
"run",
|
|
1306
|
+
"update board_tasks set target_agent = ?, holder = ? where id = ?",
|
|
1307
|
+
targetAgent,
|
|
1308
|
+
targetAgent,
|
|
1309
|
+
id
|
|
1310
|
+
);
|
|
1311
|
+
const authorized = this.authorizeRun(id, "dispatch");
|
|
1312
|
+
if (!authorized.ok) {
|
|
1313
|
+
db.exec("rollback");
|
|
1314
|
+
return false;
|
|
1315
|
+
}
|
|
1316
|
+
this.meta(key, nextGrant);
|
|
1317
|
+
if (scopeRef) this.meta(`dispatch-scope:${scopeRef}`, nextScope);
|
|
1318
|
+
if (quota) this.meta(quota.key, quota.next);
|
|
1319
|
+
db.exec("commit");
|
|
1320
|
+
return true;
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
if (db.inTransaction) db.exec("rollback");
|
|
1323
|
+
throw error;
|
|
1324
|
+
}
|
|
1325
|
+
},
|
|
1326
|
+
replaceDispatchGrant({ id, expectedGrant, nextGrant }) {
|
|
1327
|
+
return (
|
|
1328
|
+
execute(
|
|
1329
|
+
"run",
|
|
1330
|
+
"update board_meta set value = ? where key = ? and value = ?",
|
|
1331
|
+
nextGrant,
|
|
1332
|
+
`dispatch-grant:${id}`,
|
|
1333
|
+
expectedGrant
|
|
1334
|
+
).changes === 1
|
|
1335
|
+
);
|
|
1336
|
+
},
|
|
1337
|
+
failUnstartedDispatch(id, reason) {
|
|
1338
|
+
const now = new Date().toISOString();
|
|
1339
|
+
return (
|
|
1340
|
+
execute(
|
|
1341
|
+
"run",
|
|
1342
|
+
`update board_tasks set status = 'failed', failure = 'start', result = ?,
|
|
1343
|
+
holder = null, reported_at = ?, updated_at = ?, version = version + 1
|
|
1344
|
+
where id = ? and origin_agent = 'user' and status = 'open'
|
|
1345
|
+
and run_authorized_at is null and claimed_by is null`,
|
|
1346
|
+
reason,
|
|
1347
|
+
now,
|
|
1348
|
+
now,
|
|
1349
|
+
id
|
|
1350
|
+
).changes === 1
|
|
1351
|
+
);
|
|
1352
|
+
},
|
|
1204
1353
|
// The person's choices about what each agent is good at (specialties.mjs owns the rules; these keep the rows).
|
|
1205
1354
|
specialtyChoices(agent) {
|
|
1206
1355
|
return execute(
|
|
@@ -1531,11 +1680,7 @@ export function openStore(file) {
|
|
|
1531
1680
|
);
|
|
1532
1681
|
const made = post ? { ...post, mentions } : null;
|
|
1533
1682
|
// Whoever follows a room's posts (a shared project carries them to the other side) hears each one as it is made.
|
|
1534
|
-
if (made)
|
|
1535
|
-
for (const listener of roomPostListeners)
|
|
1536
|
-
try {
|
|
1537
|
-
listener(goalId, made);
|
|
1538
|
-
} catch {}
|
|
1683
|
+
if (made) publishRoomPost(goalId, made);
|
|
1539
1684
|
return made;
|
|
1540
1685
|
},
|
|
1541
1686
|
onRoomPost(listener) {
|
|
@@ -2438,6 +2583,73 @@ export function openStore(file) {
|
|
|
2438
2583
|
)
|
|
2439
2584
|
);
|
|
2440
2585
|
},
|
|
2586
|
+
// Retire only an unstarted agent ask, with the task and room receipts in
|
|
2587
|
+
// the same transaction. The route supplies relevance; the store preserves
|
|
2588
|
+
// ownership if another worker claimed or changed the task in the meantime.
|
|
2589
|
+
retireRouteAsk(goalId, id, expectedVersion, reason) {
|
|
2590
|
+
db.exec("begin immediate");
|
|
2591
|
+
try {
|
|
2592
|
+
const task = this.getTask(id);
|
|
2593
|
+
const untouched =
|
|
2594
|
+
task?.kind === "task" &&
|
|
2595
|
+
task.parent_id === goalId &&
|
|
2596
|
+
task.origin_agent !== "user" &&
|
|
2597
|
+
task.status === "open" &&
|
|
2598
|
+
task.version === expectedVersion &&
|
|
2599
|
+
task.context_refs.some((ref) => ref.kind === "ask") &&
|
|
2600
|
+
!task.claimed_by &&
|
|
2601
|
+
!task.claimed_at &&
|
|
2602
|
+
!task.claimed_machine &&
|
|
2603
|
+
!task.target_machine &&
|
|
2604
|
+
!task.session_id &&
|
|
2605
|
+
!task.run_workspace &&
|
|
2606
|
+
!task.run_authorized_at &&
|
|
2607
|
+
!task.usage &&
|
|
2608
|
+
!this.meta(`harness-window:${id}`) &&
|
|
2609
|
+
!this.meta(`harness-served:${id}`);
|
|
2610
|
+
if (!untouched) {
|
|
2611
|
+
db.exec("commit");
|
|
2612
|
+
return false;
|
|
2613
|
+
}
|
|
2614
|
+
const at = new Date().toISOString();
|
|
2615
|
+
const text = `Canceled unstarted route ask ${id} for ${task.target_agent}: ${reason}. No work was reported as completed.`;
|
|
2616
|
+
const retired = execute(
|
|
2617
|
+
"run",
|
|
2618
|
+
`update board_tasks set status = 'failed', failure = 'start', result = ?, holder = null,
|
|
2619
|
+
reported_at = ?, updated_at = ?, version = version + 1 where id = ? and status = 'open' and version = ?`,
|
|
2620
|
+
text,
|
|
2621
|
+
at,
|
|
2622
|
+
at,
|
|
2623
|
+
id,
|
|
2624
|
+
expectedVersion
|
|
2625
|
+
);
|
|
2626
|
+
if (retired.changes !== 1) {
|
|
2627
|
+
db.exec("commit");
|
|
2628
|
+
return false;
|
|
2629
|
+
}
|
|
2630
|
+
this.addContribution({
|
|
2631
|
+
taskId: id,
|
|
2632
|
+
kind: "receipt",
|
|
2633
|
+
author: "harness",
|
|
2634
|
+
text,
|
|
2635
|
+
source: "route",
|
|
2636
|
+
});
|
|
2637
|
+
const receipt = this.addContribution({
|
|
2638
|
+
taskId: goalId,
|
|
2639
|
+
kind: "receipt",
|
|
2640
|
+
author: "harness",
|
|
2641
|
+
text,
|
|
2642
|
+
source: "room",
|
|
2643
|
+
});
|
|
2644
|
+
db.exec("commit");
|
|
2645
|
+
// Other computers hear the receipt only after its cancellation is durable.
|
|
2646
|
+
publishRoomPost(goalId, { ...receipt, mentions: [] });
|
|
2647
|
+
return true;
|
|
2648
|
+
} catch (error) {
|
|
2649
|
+
if (db.inTransaction) db.exec("rollback");
|
|
2650
|
+
throw error;
|
|
2651
|
+
}
|
|
2652
|
+
},
|
|
2441
2653
|
// Stop: every open child closes; the caller stops what is running.
|
|
2442
2654
|
// `agent`: only that agent's runs, the rest of the goal's work going on (a shared project's piece released).
|
|
2443
2655
|
closeGoalChildren(goalId, reason, agent = null) {
|