tryharness 0.7.67 → 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/boardFileCommands.mjs +5 -7
- package/lib/boardFiles.mjs +5 -0
- package/lib/boardProtocol.json +50 -64
- package/lib/boardWaits.mjs +6 -0
- package/lib/cards.mjs +13 -1
- package/lib/comfyExecution.mjs +545 -0
- package/lib/context.mjs +34 -20
- package/lib/contextWorker.mjs +199 -0
- package/lib/coordinator.mjs +224 -22
- package/lib/daemon.mjs +196 -14
- package/lib/dispatchContract.json +313 -0
- package/lib/dispatchTools.js +87 -0
- package/lib/dispatches.mjs +975 -0
- package/lib/environment.mjs +54 -69
- package/lib/files.mjs +35 -0
- package/lib/frames.mjs +5 -9
- package/lib/goalCommands.mjs +13 -10
- package/lib/kept.mjs +131 -0
- package/lib/landed.mjs +1 -34
- package/lib/library.mjs +18 -11
- package/lib/live.mjs +30 -11
- package/lib/localAgentAsk.mjs +27 -4
- package/lib/localStack.mjs +17 -13
- package/lib/machineRoutes.mjs +5 -0
- package/lib/machineRuns.mjs +2 -1
- package/lib/mcp-stdio.mjs +42 -1
- package/lib/openHere.mjs +36 -0
- package/lib/openRequests.mjs +56 -0
- package/lib/ownMachines.mjs +232 -24
- package/lib/phones.mjs +29 -4
- package/lib/places.mjs +44 -11
- package/lib/portCalls.mjs +54 -0
- 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 +2 -2
- package/lib/runWorker.mjs +25 -5
- package/lib/runner.mjs +62 -6
- package/lib/sealed.mjs +37 -0
- package/lib/sessionControl.mjs +47 -14
- package/lib/sessionIndex.mjs +11 -3
- package/lib/store.mjs +362 -40
- package/lib/swarm.mjs +85 -34
- package/lib/swarmMemory.mjs +39 -16
- package/lib/taskCommands.mjs +125 -1
- package/lib/team.json +10 -0
- package/lib/team.mjs +287 -26
- package/lib/threadBriefs.mjs +43 -31
- package/lib/threadRuns.mjs +47 -3
- package/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/release.json +55 -43
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
|
@@ -116,7 +116,7 @@ export function createRunBriefs({
|
|
|
116
116
|
// The thread's task frame, refreshed now, for an agent on this computer.
|
|
117
117
|
const frame =
|
|
118
118
|
RUNNERS.has(agent) && threadId
|
|
119
|
-
? frameFor(threadId, { pack: found.pack })
|
|
119
|
+
? await frameFor(threadId, { pack: found.pack })
|
|
120
120
|
: null;
|
|
121
121
|
found.frame = frame ? frames.briefText(frame, agent) : "";
|
|
122
122
|
if (found.frame && !dryRun) {
|
|
@@ -182,7 +182,7 @@ export function createRunBriefs({
|
|
|
182
182
|
name: "provenance",
|
|
183
183
|
priority: "core",
|
|
184
184
|
source: "who wrote the task",
|
|
185
|
-
text: provenanceLine(task),
|
|
185
|
+
text: provenanceLine(task, person?.displayName),
|
|
186
186
|
},
|
|
187
187
|
{
|
|
188
188
|
name: "objective",
|
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/sealed.mjs
CHANGED
|
@@ -138,6 +138,43 @@ export async function seal(key, direction, deviceId, requestId, value) {
|
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
// A file part for a phone that asked for bytes (board.file.get raw): the plaintext is BYTES_MAGIC, the length of a JSON
|
|
142
|
+
// header, the header, then the bytes themselves, so they are not base64 inside the seal as well as outside it.
|
|
143
|
+
// The phone tells the two apart by the first bytes (a JSON plaintext starts with "{"): src/shared/crypto/sealedChannel.ts.
|
|
144
|
+
export const BYTES_MAGIC = "HSB1";
|
|
145
|
+
export async function sealFilePart(
|
|
146
|
+
key,
|
|
147
|
+
direction,
|
|
148
|
+
deviceId,
|
|
149
|
+
requestId,
|
|
150
|
+
header,
|
|
151
|
+
bytes
|
|
152
|
+
) {
|
|
153
|
+
const head = encoder.encode(JSON.stringify(header));
|
|
154
|
+
const plain = new Uint8Array(8 + head.length + bytes.length);
|
|
155
|
+
plain.set(encoder.encode(BYTES_MAGIC), 0);
|
|
156
|
+
new DataView(plain.buffer).setUint32(4, head.length);
|
|
157
|
+
plain.set(head, 8);
|
|
158
|
+
plain.set(bytes, 8 + head.length);
|
|
159
|
+
const iv = webcrypto.getRandomValues(new Uint8Array(12));
|
|
160
|
+
const ct = await subtle.encrypt(
|
|
161
|
+
{
|
|
162
|
+
name: "AES-GCM",
|
|
163
|
+
iv,
|
|
164
|
+
additionalData: aad(direction, deviceId, requestId),
|
|
165
|
+
},
|
|
166
|
+
key,
|
|
167
|
+
plain
|
|
168
|
+
);
|
|
169
|
+
return {
|
|
170
|
+
v: SEALED_VERSION,
|
|
171
|
+
deviceId,
|
|
172
|
+
requestId,
|
|
173
|
+
iv: b64u(iv),
|
|
174
|
+
ct: b64u(new Uint8Array(ct)),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
141
178
|
// Throws on a wrong key, a wrong direction, device or request id, or any changed byte.
|
|
142
179
|
export async function open(key, direction, envelope) {
|
|
143
180
|
const plain = await subtle.decrypt(
|
package/lib/sessionControl.mjs
CHANGED
|
@@ -266,10 +266,11 @@ export function createSessionControl({
|
|
|
266
266
|
// its process tree and its terminal. Codex's terminals share one background server, started from wherever Codex first
|
|
267
267
|
// ran: a session there has no app or terminal of its own, and is placed by the Codex terminal working in its folder.
|
|
268
268
|
const placeOfReport = (agentId, folder, request) => {
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
const named = (Array.isArray(request.pids) ? request.pids : []).filter(
|
|
270
|
+
(pid) => Number.isInteger(pid) && pid > 1
|
|
271
|
+
);
|
|
272
|
+
const table = processTable({ having: named });
|
|
273
|
+
const pids = named.filter((pid) => table.has(pid)).slice(0, 2);
|
|
273
274
|
if (harnessRun(folder, pids)) return null;
|
|
274
275
|
let env = placeEnv(request.env);
|
|
275
276
|
let host = pids.map((pid) => hostApp(table, pid)).find(Boolean) ?? null;
|
|
@@ -331,7 +332,8 @@ export function createSessionControl({
|
|
|
331
332
|
return link || command ? { link, command } : null;
|
|
332
333
|
};
|
|
333
334
|
|
|
334
|
-
|
|
335
|
+
// `fresh`: for a decision made once (send into a session, open it where it runs), the process table read now.
|
|
336
|
+
const liveNow = ({ fresh = false } = {}) => {
|
|
335
337
|
const recent = store.recentSessions(200);
|
|
336
338
|
// With the title the index gives it (its first request), when the index has it yet.
|
|
337
339
|
const titleOf = (session) => {
|
|
@@ -346,7 +348,7 @@ export function createSessionControl({
|
|
|
346
348
|
};
|
|
347
349
|
const linksOk = t3LinksOk();
|
|
348
350
|
const handed = handedToT3();
|
|
349
|
-
const table = processTable();
|
|
351
|
+
const table = processTable({ fresh });
|
|
350
352
|
const found = liveSessions({
|
|
351
353
|
exclude: new Set(runningPids()),
|
|
352
354
|
recent,
|
|
@@ -839,7 +841,7 @@ export function createSessionControl({
|
|
|
839
841
|
: `One of Harness's runs is working in this ${nameOf(agentId)} session right now. Open it again once the run is done.`,
|
|
840
842
|
};
|
|
841
843
|
}
|
|
842
|
-
const running = sessionId ? liveNow() : [];
|
|
844
|
+
const running = sessionId ? liveNow({ fresh: true }) : [];
|
|
843
845
|
const live = running.find(
|
|
844
846
|
(row) => row.agent === agentId && row.sessionId === sessionId
|
|
845
847
|
);
|
|
@@ -895,6 +897,39 @@ export function createSessionControl({
|
|
|
895
897
|
: { opensIn: null };
|
|
896
898
|
};
|
|
897
899
|
|
|
900
|
+
/**
|
|
901
|
+
* The agent itself, fresh, for a thread it has not worked in yet (owner, October 28: every agent on a thread opens
|
|
902
|
+
* outside the buddy, a coding agent with no session there "fresh in its home"): where the person uses it, in the
|
|
903
|
+
* thread's folder, never another of its conversations there. In T3 Code that is T3 itself, not the agent's thread for
|
|
904
|
+
* the folder, which is another conversation.
|
|
905
|
+
*/
|
|
906
|
+
const freshPlan = (agentId, folder, act) => {
|
|
907
|
+
const home = homeOf(agentId);
|
|
908
|
+
const where = folder && fs.existsSync(folder) ? folder : null;
|
|
909
|
+
const terminal = () => {
|
|
910
|
+
const { name, app } = lastResort();
|
|
911
|
+
return {
|
|
912
|
+
opensIn: name,
|
|
913
|
+
resume: { agent: agentId, session: null, cwd: where, app },
|
|
914
|
+
};
|
|
915
|
+
};
|
|
916
|
+
const plan =
|
|
917
|
+
home?.kind === "t3"
|
|
918
|
+
? home.app
|
|
919
|
+
? { opensIn: "T3 Code", app: home.app }
|
|
920
|
+
: null
|
|
921
|
+
: placePlan(agentId, home, null, where, act);
|
|
922
|
+
const shown =
|
|
923
|
+
plan ??
|
|
924
|
+
(CODING_AGENTS.includes(agentId) ? terminal() : { opensIn: null });
|
|
925
|
+
return shown.opensIn
|
|
926
|
+
? {
|
|
927
|
+
...shown,
|
|
928
|
+
note: `${nameOf(agentId)} hasn't worked in this thread yet, so it opens fresh in ${shown.opensIn}.`,
|
|
929
|
+
}
|
|
930
|
+
: shown;
|
|
931
|
+
};
|
|
932
|
+
|
|
898
933
|
/**
|
|
899
934
|
* Each coding agent's sessions that ended, as Open offers them: the person's newest (`last`), where the agent opens when
|
|
900
935
|
* it is not running; and the newest few another agent, a run or a test started (`traces`), each saying who.
|
|
@@ -1027,14 +1062,12 @@ export function createSessionControl({
|
|
|
1027
1062
|
if (!validAgent(agentId) || (sessionId && !SESSION_ID.test(sessionId)))
|
|
1028
1063
|
return { ok: false, error: "that session can't be opened" };
|
|
1029
1064
|
// Open itself: the daemon's part happens now, and the app does the rest.
|
|
1065
|
+
const act = request.command === "board.live.focus";
|
|
1030
1066
|
return {
|
|
1031
1067
|
ok: true,
|
|
1032
|
-
...
|
|
1033
|
-
agentId,
|
|
1034
|
-
sessionId || null,
|
|
1035
|
-
folderOf(request),
|
|
1036
|
-
request.command === "board.live.focus"
|
|
1037
|
-
),
|
|
1068
|
+
...(request.fresh === true && !sessionId
|
|
1069
|
+
? freshPlan(agentId, folderOf(request), act)
|
|
1070
|
+
: openPlan(agentId, sessionId || null, folderOf(request), act)),
|
|
1038
1071
|
};
|
|
1039
1072
|
}
|
|
1040
1073
|
if (request.command === "board.live.say") {
|
|
@@ -1042,7 +1075,7 @@ export function createSessionControl({
|
|
|
1042
1075
|
.trim()
|
|
1043
1076
|
.slice(0, 20_000);
|
|
1044
1077
|
if (!text) return { ok: false, error: "a message needs text" };
|
|
1045
|
-
const session = liveNow().find(
|
|
1078
|
+
const session = liveNow({ fresh: true }).find(
|
|
1046
1079
|
(row) => row.agent === request.to && row.sessionId === sessionId
|
|
1047
1080
|
);
|
|
1048
1081
|
if (!session)
|
package/lib/sessionIndex.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { randomBytes } from "node:crypto";
|
|
5
5
|
import { runAsync } from "./commands.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { listJsonlAsync } from "./files.mjs";
|
|
7
7
|
import { parseSessionFile } from "./parsers.mjs";
|
|
8
8
|
import { historyRoots } from "./paths.mjs";
|
|
9
9
|
|
|
@@ -97,6 +97,9 @@ export function createSessionIndex({
|
|
|
97
97
|
|
|
98
98
|
let syncRunning = false;
|
|
99
99
|
let syncAgain = false;
|
|
100
|
+
// Each session file's mtime and size when it was last found indexed: a pass skips it without asking the store until
|
|
101
|
+
// it changes (a pass runs about every second while agents work, over hundreds of files).
|
|
102
|
+
const indexedAs = new Map();
|
|
100
103
|
let targetedOpencode = [];
|
|
101
104
|
async function indexFile(agent, item) {
|
|
102
105
|
const sessionId = path.basename(item.file);
|
|
@@ -172,12 +175,17 @@ export function createSessionIndex({
|
|
|
172
175
|
(agentFilter && agentFilter !== agent)
|
|
173
176
|
)
|
|
174
177
|
continue;
|
|
175
|
-
const files =
|
|
176
|
-
.
|
|
178
|
+
const files = (
|
|
179
|
+
await Promise.all(historyRoots(agent).map(listJsonlAsync))
|
|
180
|
+
)
|
|
181
|
+
.flat()
|
|
177
182
|
.sort((a, b) => b.mtime - a.mtime);
|
|
178
183
|
for (const item of files) {
|
|
184
|
+
const seenAs = `${item.mtime}:${item.size}`;
|
|
185
|
+
if (indexedAs.get(item.file) === seenAs) continue;
|
|
179
186
|
try {
|
|
180
187
|
await indexFile(agent, item);
|
|
188
|
+
indexedAs.set(item.file, seenAs);
|
|
181
189
|
} catch (error) {
|
|
182
190
|
log(`index ${agent} ${item.file}: ${error.message}`);
|
|
183
191
|
}
|