tryharness 0.7.83 → 0.7.86
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/README.md +21 -19
- package/assets/dsh-plugin.mjs +75 -4
- package/assets/herdr-mod/harness/main.js +367 -0
- package/assets/herdr-mod/harness/mod.json +6 -0
- package/assets/opencode-plugin.js +87 -22
- package/assets/pi-extension.ts +81 -2
- package/cli.mjs +544 -208
- package/lib/adapters.mjs +62 -27
- package/lib/agentBinaries.mjs +6 -8
- package/lib/agentClaims.mjs +168 -0
- package/lib/agentReadTools.json +415 -0
- package/lib/agentSignIn.mjs +17 -18
- package/lib/agentWiring.mjs +114 -0
- package/lib/archetypes.js +10 -11
- package/lib/attention.mjs +100 -0
- package/lib/audit.mjs +1 -1
- package/lib/backupSetup.mjs +6 -28
- package/lib/bankrApprovals.mjs +86 -0
- package/lib/boardAccess.mjs +40 -66
- package/lib/boardBackup.mjs +86 -85
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +29 -36
- package/lib/boardFiles.mjs +83 -15
- package/lib/boardMirror.mjs +78 -11
- package/lib/boardProtocol.json +191 -123
- package/lib/boardThreads.mjs +19 -37
- package/lib/boardTools.mjs +22 -15
- package/lib/boardWatches.mjs +43 -15
- package/lib/bridge.mjs +7 -3
- package/lib/browserAgentTools.mjs +59 -0
- package/lib/browserWake.mjs +0 -6
- package/lib/cards.mjs +52 -0
- package/lib/circling.mjs +189 -0
- package/lib/cleanup.mjs +234 -0
- package/lib/cloudBoot.mjs +21 -4
- package/lib/cloudSave.mjs +46 -5
- package/lib/compaction.mjs +8 -1
- package/lib/completion.mjs +358 -0
- package/lib/computerDevices.mjs +853 -0
- package/lib/connectionStatus.mjs +34 -0
- package/lib/connectors.mjs +139 -1
- package/lib/coordinator.mjs +108 -14
- package/lib/coreModels.mjs +36 -12
- package/lib/daemon.mjs +2426 -338
- package/lib/daemonLock.mjs +103 -0
- package/lib/deviceDoor.mjs +308 -0
- package/lib/deviceIdentity.mjs +114 -0
- package/lib/deviceList.mjs +172 -0
- package/lib/deviceSeal.mjs +74 -0
- package/lib/dispatcher.mjs +497 -26
- package/lib/dispatches.mjs +3 -3
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +67 -41
- package/lib/events.mjs +318 -0
- package/lib/facts.mjs +170 -0
- package/lib/fileSource.mjs +540 -0
- package/lib/files.mjs +47 -2
- package/lib/gitHost.mjs +39 -1
- package/lib/goalCommands.mjs +12 -80
- package/lib/handover.mjs +21 -16
- package/lib/harnessOffers.mjs +140 -15
- package/lib/herdr.mjs +100 -15
- package/lib/herdrAppCall.mjs +19 -0
- package/lib/herdrCore.mjs +59 -0
- package/lib/herdrRuns.mjs +1126 -0
- package/lib/hookDialects.mjs +235 -50
- package/lib/identityLink.mjs +81 -0
- package/lib/inference.mjs +31 -2
- package/lib/jamAccess.mjs +82 -0
- package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
- package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
- package/lib/jamKey.mjs +274 -0
- package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
- package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
- package/lib/jamStore.mjs +973 -0
- package/lib/jamUpgrade.mjs +112 -0
- package/lib/jams.mjs +3079 -0
- package/lib/kanban.mjs +13 -7
- package/lib/landed.mjs +5 -1
- package/lib/library.mjs +41 -22
- package/lib/limits.mjs +91 -0
- package/lib/lineDiff.mjs +97 -0
- package/lib/lineup.mjs +18 -13
- package/lib/link.mjs +584 -0
- package/lib/localStack.mjs +75 -16
- package/lib/localmodels.mjs +58 -78
- package/lib/loopBackstop.mjs +2 -1
- package/lib/machine.mjs +544 -0
- package/lib/machineLink.mjs +446 -0
- package/lib/machineRoutes.mjs +68 -19
- package/lib/machineRuns.mjs +85 -4
- package/lib/machineSeal.mjs +6 -31
- package/lib/manager.mjs +134 -12
- package/lib/mcp-stdio.mjs +492 -215
- package/lib/mcpRelay.mjs +34 -35
- package/lib/members.json +1 -1
- package/lib/modelRoute.mjs +162 -0
- package/lib/nativeHost.mjs +81 -90
- package/lib/nativeSenses.mjs +258 -0
- package/lib/nerves.mjs +523 -0
- package/lib/network.mjs +117 -278
- package/lib/networkPlaces.mjs +578 -0
- package/lib/nextStep.mjs +95 -0
- package/lib/notify.mjs +2 -2
- package/lib/nudge.mjs +116 -10
- package/lib/originals.mjs +216 -0
- package/lib/outsideEvents.mjs +383 -0
- package/lib/outsideRuns.mjs +230 -0
- package/lib/ownMachines.mjs +674 -256
- package/lib/pain.mjs +215 -0
- package/lib/pairing.mjs +91 -11
- package/lib/paths.mjs +42 -3
- package/lib/peerProcess.mjs +21 -7
- package/lib/peopleLink.mjs +268 -0
- package/lib/personNotices.mjs +3 -2
- package/lib/phones.mjs +252 -542
- package/lib/placeCards.mjs +282 -0
- package/lib/placeChecks.mjs +95 -0
- package/lib/placeCommands.mjs +8 -17
- package/lib/placeRequests.mjs +152 -0
- package/lib/placeStore.mjs +295 -0
- package/lib/placeTool.d.ts +12 -0
- package/lib/placeTool.js +40 -0
- package/lib/places.mjs +63 -14
- package/lib/plans.mjs +53 -8
- package/lib/presence.mjs +270 -0
- package/lib/privateNetwork.d.ts +2 -0
- package/lib/privateNetwork.js +93 -0
- package/lib/proposals.mjs +300 -0
- package/lib/publicFetch.d.ts +32 -0
- package/lib/publicFetch.js +248 -0
- package/lib/reach.mjs +128 -0
- package/lib/rebuildable.mjs +72 -0
- package/lib/recall.mjs +216 -0
- package/lib/record.mjs +13 -0
- package/lib/reflexes.mjs +392 -0
- package/lib/relayLimits.mjs +31 -2
- package/lib/releaseNotice.mjs +198 -0
- package/lib/removeHarness.mjs +15 -4
- package/lib/repoLinks.mjs +204 -35
- package/lib/runAuthority.mjs +102 -39
- package/lib/runBrief.mjs +93 -40
- package/lib/runRequests.mjs +52 -14
- package/lib/runUsage.mjs +31 -0
- package/lib/runWorker.mjs +74 -25
- package/lib/runner.mjs +289 -45
- package/lib/runtime-install.mjs +37 -8
- package/lib/schedules.mjs +171 -47
- package/lib/screenWatches.mjs +221 -0
- package/lib/sealed.mjs +12 -30
- package/lib/sealedThreads.mjs +198 -392
- package/lib/secretStore.mjs +178 -0
- package/lib/secrets.mjs +11 -0
- package/lib/seen.mjs +3 -9
- package/lib/selfUpdate.mjs +51 -15
- package/lib/senseCall.mjs +1514 -0
- package/lib/senseHook.mjs +114 -0
- package/lib/senseTools.mjs +1298 -0
- package/lib/sessionBriefs.mjs +87 -0
- package/lib/sessionControl.mjs +63 -13
- package/lib/sessionFiles.mjs +85 -0
- package/lib/setupChoices.mjs +12 -3
- package/lib/setupMode.mjs +70 -25
- package/lib/sharedKeys.mjs +166 -0
- package/lib/sleep.mjs +396 -0
- package/lib/sources.mjs +306 -0
- package/lib/speech.mjs +166 -411
- package/lib/spoken.mjs +210 -0
- package/lib/steerHook.mjs +3 -1
- package/lib/steerQueue.mjs +40 -11
- package/lib/store.mjs +323 -130
- package/lib/stuck.mjs +85 -7
- package/lib/swarm.mjs +157 -49
- package/lib/swarmDevices.mjs +25 -85
- package/lib/swarmMemory.mjs +93 -9
- package/lib/t3.mjs +73 -3
- package/lib/taskCommands.mjs +51 -60
- package/lib/taskRooms.mjs +30 -4
- package/lib/taskRules.json +29 -0
- package/lib/taskRules.mjs +21 -0
- package/lib/taskRuns.mjs +74 -11
- package/lib/team.mjs +2 -1
- package/lib/threadActions.mjs +37 -9
- package/lib/threadAuthority.mjs +4 -4
- package/lib/threadBriefs.mjs +173 -43
- package/lib/threadNotes.mjs +320 -0
- package/lib/threadRecord.mjs +491 -0
- package/lib/threadRuns.mjs +216 -108
- package/lib/threadView.mjs +27 -30
- package/lib/threadWatches.mjs +1962 -0
- package/lib/timeSense.mjs +839 -0
- package/lib/tripwires.mjs +454 -0
- package/lib/ui.mjs +1 -1
- package/lib/vault.mjs +560 -45
- package/lib/vaultCommands.mjs +5 -3
- package/lib/vaultPeers.mjs +165 -0
- package/lib/vaultTools.d.ts +4 -1
- package/lib/vaultTools.js +22 -1
- package/lib/verdicts.mjs +12 -26
- package/lib/versions.mjs +117 -0
- package/lib/waitTool.mjs +278 -0
- package/lib/wakePicture.mjs +268 -0
- package/lib/wakeQueue.mjs +108 -0
- package/lib/watchResponses.mjs +533 -0
- package/lib/watches.mjs +290 -145
- package/lib/windowAsks.mjs +80 -17
- package/lib/worktrees.mjs +159 -9
- package/npm-shrinkwrap.json +138 -631
- package/package.json +7 -6
- package/release.json +211 -129
- package/lib/callSessions.mjs +0 -51
- package/lib/directLink.mjs +0 -349
- package/lib/peopleBoard.mjs +0 -131
- package/lib/projects.mjs +0 -2917
- package/lib/roomChannels.mjs +0 -667
package/lib/runBrief.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { DISPATCHER, nameOf } from "./members.mjs";
|
|
|
3
3
|
import { claudeMemNotes } from "./claudemem.mjs";
|
|
4
4
|
import { toldBlock } from "./cards.mjs";
|
|
5
5
|
import { fitSections } from "./fit.mjs";
|
|
6
|
+
import { createSessionBriefs } from "./sessionBriefs.mjs";
|
|
6
7
|
import { oneLine } from "./oneLine.mjs";
|
|
7
8
|
import { profileBrief, readProfile } from "./profile.mjs";
|
|
8
9
|
|
|
@@ -41,6 +42,8 @@ export function createRunBriefs({
|
|
|
41
42
|
// What a run in a thread is told of the thread's board of cards (kanban.mjs).
|
|
42
43
|
boardBrief = () => "",
|
|
43
44
|
}) {
|
|
45
|
+
const sessionBriefs = createSessionBriefs(store);
|
|
46
|
+
|
|
44
47
|
// What claude-mem remembers about this folder joins the task's context and the brief, so an agent without claude-mem
|
|
45
48
|
// starts from the same history one with it would. A wake resumes its own session.
|
|
46
49
|
const memoryNotes = async (task, wake, dryRun) => {
|
|
@@ -173,7 +176,17 @@ export function createRunBriefs({
|
|
|
173
176
|
};
|
|
174
177
|
};
|
|
175
178
|
|
|
176
|
-
const sectionsFor = ({
|
|
179
|
+
const sectionsFor = ({
|
|
180
|
+
task,
|
|
181
|
+
agent,
|
|
182
|
+
wake,
|
|
183
|
+
room,
|
|
184
|
+
local,
|
|
185
|
+
memory,
|
|
186
|
+
told,
|
|
187
|
+
dryRun,
|
|
188
|
+
}) => {
|
|
189
|
+
const block = (text) => (told ? told.block(text) : text);
|
|
177
190
|
const pack = local.pack?.parts ?? {};
|
|
178
191
|
const person = RUNNERS.has(agent) ? readProfile() : null;
|
|
179
192
|
const refs = task.context_refs.map(
|
|
@@ -186,7 +199,7 @@ export function createRunBriefs({
|
|
|
186
199
|
name: "provenance",
|
|
187
200
|
priority: "core",
|
|
188
201
|
source: "who wrote the task",
|
|
189
|
-
text: provenanceLine(task, person?.displayName),
|
|
202
|
+
text: block(provenanceLine(task, person?.displayName)),
|
|
190
203
|
},
|
|
191
204
|
...(thread?.kind === "goal"
|
|
192
205
|
? [
|
|
@@ -194,7 +207,9 @@ export function createRunBriefs({
|
|
|
194
207
|
name: "thread board",
|
|
195
208
|
priority: "core",
|
|
196
209
|
source: `thread ${thread.id}`,
|
|
197
|
-
text:
|
|
210
|
+
text: block(
|
|
211
|
+
boardBrief(thread.id, { starting: dryRun ? task.id : null })
|
|
212
|
+
),
|
|
198
213
|
},
|
|
199
214
|
]
|
|
200
215
|
: []),
|
|
@@ -202,13 +217,13 @@ export function createRunBriefs({
|
|
|
202
217
|
name: "objective",
|
|
203
218
|
priority: "core",
|
|
204
219
|
source: `task ${task.id}`,
|
|
205
|
-
text: task.objective,
|
|
220
|
+
text: block(task.objective),
|
|
206
221
|
},
|
|
207
222
|
{
|
|
208
223
|
name: wake ? "wake brief" : "brief",
|
|
209
224
|
priority: "core",
|
|
210
225
|
source: wake ? `thread ${task.parent_id}` : `task ${task.id}`,
|
|
211
|
-
text: wake ? wakeBrief(task) : task.brief,
|
|
226
|
+
text: wake ? wakeBrief(task, told) : task.brief,
|
|
212
227
|
},
|
|
213
228
|
{
|
|
214
229
|
name: "context refs",
|
|
@@ -320,6 +335,17 @@ export function createRunBriefs({
|
|
|
320
335
|
})
|
|
321
336
|
: null;
|
|
322
337
|
if (handed) resumeSession = undefined;
|
|
338
|
+
// What the session this turn goes on in was already told. In T3 the session is the agent's T3 thread.
|
|
339
|
+
const told = wake
|
|
340
|
+
? sessionBriefs.forWake(
|
|
341
|
+
task.parent_id,
|
|
342
|
+
agent,
|
|
343
|
+
t3
|
|
344
|
+
? store.meta(`t3-thread:${task.parent_id}:${agent}`)
|
|
345
|
+
: resumeSession
|
|
346
|
+
)
|
|
347
|
+
: null;
|
|
348
|
+
let whole = null;
|
|
323
349
|
const notes = [
|
|
324
350
|
{
|
|
325
351
|
name: "stopped note",
|
|
@@ -335,33 +361,56 @@ export function createRunBriefs({
|
|
|
335
361
|
!wake && task.parent_id ? store.getTask(task.parent_id) : null;
|
|
336
362
|
const memory = await memoryNotes(task, wake, dryRun);
|
|
337
363
|
const local = await localContext(task, agent, { wake, room, dryRun });
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
364
|
+
const sectionsWith = (toldNow) => {
|
|
365
|
+
const body = sectionsFor({
|
|
366
|
+
task,
|
|
367
|
+
agent,
|
|
368
|
+
wake,
|
|
369
|
+
room,
|
|
370
|
+
local,
|
|
371
|
+
memory,
|
|
372
|
+
told: toldNow,
|
|
373
|
+
dryRun,
|
|
374
|
+
});
|
|
375
|
+
// The earlier session's words follow what the run is asked.
|
|
376
|
+
const asked =
|
|
377
|
+
body.findIndex((section) =>
|
|
378
|
+
["brief", "wake brief"].includes(section.name)
|
|
379
|
+
) + 1;
|
|
380
|
+
return [
|
|
381
|
+
{
|
|
382
|
+
name: "T3 catch-up",
|
|
383
|
+
priority: "core",
|
|
384
|
+
source: `thread ${task.parent_id}`,
|
|
385
|
+
text: t3 && task.parent_id ? t3CatchUp(task.parent_id, agent) : "",
|
|
386
|
+
},
|
|
387
|
+
...notes,
|
|
388
|
+
...body.slice(0, asked),
|
|
389
|
+
...(handed
|
|
390
|
+
? [
|
|
391
|
+
{
|
|
392
|
+
name: "earlier session",
|
|
393
|
+
priority: "recommended",
|
|
394
|
+
source: handed.record.file,
|
|
395
|
+
...handed.section,
|
|
396
|
+
},
|
|
397
|
+
]
|
|
398
|
+
: []),
|
|
399
|
+
// What was found for this turn: a resumed session gets the lines it has not had.
|
|
400
|
+
...body
|
|
401
|
+
.slice(asked)
|
|
402
|
+
.map((section) =>
|
|
403
|
+
toldNow
|
|
404
|
+
? { ...section, text: toldNow.lines(section.text) }
|
|
405
|
+
: section
|
|
406
|
+
),
|
|
407
|
+
];
|
|
408
|
+
};
|
|
409
|
+
// A T3 turn T3 does not answer starts a fresh session here (taskRuns.mjs), which has been told nothing. Made first:
|
|
410
|
+
// wakeBrief notes when the thread was read, and the brief sent must be the last to read it.
|
|
411
|
+
if (t3 && told?.afterSeq)
|
|
412
|
+
whole = fitSections(sectionsWith(null), BRIEF_BUDGET).text;
|
|
413
|
+
sections = sectionsWith(told);
|
|
365
414
|
}
|
|
366
415
|
const fitted = fitSections(sections, BRIEF_BUDGET);
|
|
367
416
|
const report = {
|
|
@@ -371,17 +420,21 @@ export function createRunBriefs({
|
|
|
371
420
|
whole: fitted.whole,
|
|
372
421
|
sent: fitted.sent,
|
|
373
422
|
over: fitted.over,
|
|
374
|
-
session:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
423
|
+
session: {
|
|
424
|
+
...(t3
|
|
425
|
+
? { t3: true }
|
|
426
|
+
: resumeSession
|
|
427
|
+
? { resumes: resumeSession }
|
|
428
|
+
: handed
|
|
429
|
+
? { fresh: true, replaces: handed.record.from, why: handed.why }
|
|
430
|
+
: { fresh: true }),
|
|
431
|
+
...(told?.afterSeq ? { new_after_post: told.afterSeq } : {}),
|
|
432
|
+
},
|
|
381
433
|
sections: fitted.sections,
|
|
382
434
|
};
|
|
383
435
|
if (!dryRun) {
|
|
384
436
|
store.meta(`brief-sections:${task.id}`, JSON.stringify(report));
|
|
437
|
+
told?.remember({ run: task.id, sent: fitted.text });
|
|
385
438
|
if (handed)
|
|
386
439
|
handover.announce({
|
|
387
440
|
threadId: task.parent_id,
|
|
@@ -390,7 +443,7 @@ export function createRunBriefs({
|
|
|
390
443
|
handed,
|
|
391
444
|
});
|
|
392
445
|
}
|
|
393
|
-
return { prompt: fitted.text, resumeSession, again, t3, report };
|
|
446
|
+
return { prompt: fitted.text, whole, resumeSession, again, t3, report };
|
|
394
447
|
};
|
|
395
448
|
|
|
396
449
|
/** What a run that started was told, section by section, or null. */
|
package/lib/runRequests.mjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { nameOf } from "./members.mjs";
|
|
3
3
|
|
|
4
|
+
// A question Harness or Bankr words itself (a spend past a limit, an app's write, a Bankr proposal) left unanswered this
|
|
5
|
+
// long leaves the places that show what waits right now and waits in its thread's list (owner, November 11: "if i dont
|
|
6
|
+
// address it in an hour or so it goes to a notification menu in the thread or something for me to address later").
|
|
7
|
+
// It still waits for the answer: nothing times out.
|
|
8
|
+
const LATER_MS = 60 * 60 * 1000;
|
|
9
|
+
|
|
4
10
|
/** Native permission choices for running, owned executions. A decision never starts or resumes a run. */
|
|
5
11
|
export function createRunRequests({ store, notifyBoard }) {
|
|
6
12
|
const pending = new Map();
|
|
@@ -10,14 +16,22 @@ export function createRunRequests({ store, notifyBoard }) {
|
|
|
10
16
|
);
|
|
11
17
|
const save = () => store.meta("native-run-requests", JSON.stringify(records));
|
|
12
18
|
save();
|
|
19
|
+
// Harness's task on its server is claimed, never started here: its turn runs there while the task is held.
|
|
20
|
+
// A thread's own request (a Bankr proposal from a task on Harness's server, bankrApprovals.mjs) lives while its thread
|
|
21
|
+
// is open; there is no run here to be running.
|
|
13
22
|
const running = (entry) => {
|
|
23
|
+
if (entry.threadId) return store.getTask(entry.threadId)?.status === "open";
|
|
14
24
|
const task = store.getTask(entry.runId);
|
|
15
|
-
return
|
|
25
|
+
return (
|
|
26
|
+
(task?.status === "running" ||
|
|
27
|
+
(task?.status === "claimed" && entry.agent === "harness")) &&
|
|
28
|
+
task.target_agent === entry.agent
|
|
29
|
+
);
|
|
16
30
|
};
|
|
17
31
|
const tell = (entry) => notifyBoard(store.getTask(entry.runId));
|
|
18
|
-
const request = ({ runId, agent, approval, signal }) => {
|
|
32
|
+
const request = ({ runId, agent, threadId, approval, signal }) => {
|
|
19
33
|
signal.throwIfAborted();
|
|
20
|
-
if (!running({ runId, agent }))
|
|
34
|
+
if (!running({ runId, agent, threadId }))
|
|
21
35
|
throw new Error(
|
|
22
36
|
"This native permission does not belong to a running task."
|
|
23
37
|
);
|
|
@@ -39,6 +53,7 @@ export function createRunRequests({ store, notifyBoard }) {
|
|
|
39
53
|
id: randomUUID(),
|
|
40
54
|
runId,
|
|
41
55
|
agent,
|
|
56
|
+
...(threadId ? { threadId } : {}),
|
|
42
57
|
approvalId: approval.approvalId,
|
|
43
58
|
requirement: approval.currentRequirementId,
|
|
44
59
|
revision: createHash("sha256")
|
|
@@ -47,6 +62,8 @@ export function createRunRequests({ store, notifyBoard }) {
|
|
|
47
62
|
text: `Requested action: ${approval.toolName}`,
|
|
48
63
|
details,
|
|
49
64
|
protectedWrite: approval.protectedWrite === true,
|
|
65
|
+
// What the item says on every surface, when the asker words it (Harness's app writes, harnessOffers.mjs).
|
|
66
|
+
...(approval.summary ? { summary: String(approval.summary) } : {}),
|
|
50
67
|
choices: choices.map(({ choiceId, label, decision }) => ({
|
|
51
68
|
id: choiceId,
|
|
52
69
|
label,
|
|
@@ -92,18 +109,39 @@ export function createRunRequests({ store, notifyBoard }) {
|
|
|
92
109
|
if (signal.aborted) aborted();
|
|
93
110
|
});
|
|
94
111
|
};
|
|
112
|
+
// A worded question carries its choices, so a card shows them at once; an agent's own native request is reviewed first.
|
|
113
|
+
const itemOf = (entry) => ({
|
|
114
|
+
id: `permission:${entry.id}`,
|
|
115
|
+
kind: "permission",
|
|
116
|
+
agent: entry.agent,
|
|
117
|
+
runId: entry.runId,
|
|
118
|
+
requestId: entry.id,
|
|
119
|
+
text:
|
|
120
|
+
entry.summary ??
|
|
121
|
+
`${nameOf(entry.agent)} needs your permission to continue.`,
|
|
122
|
+
at: entry.at,
|
|
123
|
+
...(entry.summary
|
|
124
|
+
? {
|
|
125
|
+
choices: entry.choices,
|
|
126
|
+
revision: entry.revision,
|
|
127
|
+
...(Date.now() - Date.parse(entry.at) > LATER_MS
|
|
128
|
+
? { late: true }
|
|
129
|
+
: {}),
|
|
130
|
+
}
|
|
131
|
+
: {}),
|
|
132
|
+
});
|
|
95
133
|
const needs = (runId) =>
|
|
96
134
|
[...pending.values()]
|
|
97
|
-
.filter(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}));
|
|
135
|
+
.filter(
|
|
136
|
+
({ entry }) =>
|
|
137
|
+
entry.runId === runId && !entry.threadId && running(entry)
|
|
138
|
+
)
|
|
139
|
+
.map(({ entry }) => itemOf(entry));
|
|
140
|
+
// A thread's own requests, which belong to no run here.
|
|
141
|
+
const threadNeeds = (threadId) =>
|
|
142
|
+
[...pending.values()]
|
|
143
|
+
.filter(({ entry }) => entry.threadId === threadId && running(entry))
|
|
144
|
+
.map(({ entry }) => itemOf(entry));
|
|
107
145
|
const finish = (runId) => {
|
|
108
146
|
for (const held of pending.values())
|
|
109
147
|
if (held.entry.runId === runId)
|
|
@@ -153,5 +191,5 @@ export function createRunRequests({ store, notifyBoard }) {
|
|
|
153
191
|
held.close("submitted", null, choice.id);
|
|
154
192
|
return { ok: true, status: "submitted" };
|
|
155
193
|
};
|
|
156
|
-
return { request, needs, command, finish };
|
|
194
|
+
return { request, needs, threadNeeds, command, finish };
|
|
157
195
|
}
|
package/lib/runUsage.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// What one run used. Some figures an agent reports count its whole session so far, so a resumed run reports its
|
|
2
|
+
// predecessors' again: Claude Code's dollars and Codex's tokens (a board once summed $360.62 for sessions that cost
|
|
3
|
+
// $78.42). The collector names those figures in `session_totals`; the run's own share is what they grew by.
|
|
4
|
+
|
|
5
|
+
const toOwnShare = (now, was) => {
|
|
6
|
+
// A counter that fell started over: all of it is this run's.
|
|
7
|
+
const grown = now >= was ? now - was : now;
|
|
8
|
+
return Math.round(grown * 1e6) / 1e6;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** `before`: the usage kept for the session's previous run, or null when this run started it. */
|
|
12
|
+
export function ownUsage(reported, before) {
|
|
13
|
+
const totals = reported?.session_totals;
|
|
14
|
+
if (!totals) return reported;
|
|
15
|
+
// A run kept before session_totals existed holds its session's counters as its figures, Codex's input with cached
|
|
16
|
+
// tokens still inside it.
|
|
17
|
+
const earlier =
|
|
18
|
+
before?.session_totals ??
|
|
19
|
+
(before
|
|
20
|
+
? {
|
|
21
|
+
...before,
|
|
22
|
+
input_tokens:
|
|
23
|
+
(Number(before.input_tokens) || 0) -
|
|
24
|
+
(Number(before.cache_read_tokens) || 0),
|
|
25
|
+
}
|
|
26
|
+
: {});
|
|
27
|
+
const own = { ...reported };
|
|
28
|
+
for (const [field, total] of Object.entries(totals))
|
|
29
|
+
own[field] = toOwnShare(total, Number(earlier[field]) || 0);
|
|
30
|
+
return own;
|
|
31
|
+
}
|
package/lib/runWorker.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { herdrTakes } from "./herdrRuns.mjs";
|
|
2
3
|
import { stopAgentTask } from "./runner.mjs";
|
|
3
4
|
import { notifyDesktop } from "./notify.mjs";
|
|
4
5
|
import { receipt, receiptLine } from "./receipts.mjs";
|
|
@@ -36,16 +37,30 @@ export function createRunWorker({
|
|
|
36
37
|
vaultEnv = () => null,
|
|
37
38
|
// A run's receipt was just kept (audit.mjs audits the run's claims with it).
|
|
38
39
|
onReceipt = () => {},
|
|
40
|
+
// What a turn that ended on a wait says, when its agent wrote nothing (threadRecord.mjs); null for no wait.
|
|
41
|
+
waitingLine = () => null,
|
|
39
42
|
}) {
|
|
40
43
|
const { RUNNERS, standingRules } = authority;
|
|
41
|
-
const {
|
|
42
|
-
|
|
44
|
+
const {
|
|
45
|
+
startTurn,
|
|
46
|
+
commitRun,
|
|
47
|
+
settleWake,
|
|
48
|
+
ranOutsideT3,
|
|
49
|
+
t3Turn,
|
|
50
|
+
taskInT3,
|
|
51
|
+
herdrTurn,
|
|
52
|
+
} = threadRuns.worker;
|
|
43
53
|
const activeRuns = new Map();
|
|
44
54
|
const lastStepNotice = new Map();
|
|
45
55
|
// Runs the daemon is stopping for a safety rule, by task id, with the reason: they go back on the board.
|
|
46
56
|
const interrupting = new Map();
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
// Only on the board this computer keeps: a worker's tables are home's copy, and the runs it had going are reported to
|
|
58
|
+
// home by machineRuns.mjs.
|
|
59
|
+
if (holdsBoard())
|
|
60
|
+
for (const id of store.settleInterruptedRuns(machineId()))
|
|
61
|
+
log(
|
|
62
|
+
`board task ${id} was running when the daemon stopped; marked unknown`
|
|
63
|
+
);
|
|
49
64
|
// Standing permission is on by default; the person hears so once, on the first start that has it.
|
|
50
65
|
const defaults = standingRules().filter((rule) => rule.mode === "default");
|
|
51
66
|
if (defaults.length && !store.meta("standing_announced")) {
|
|
@@ -91,8 +106,10 @@ export function createRunWorker({
|
|
|
91
106
|
(held) =>
|
|
92
107
|
held.agent === agent && store.getTask(held.id)?.parent_id === threadId
|
|
93
108
|
);
|
|
94
|
-
//
|
|
95
|
-
|
|
109
|
+
// Who holds new runs, and when they start again as the person reads it: Lid-Closed Mode while the Mac runs warm with
|
|
110
|
+
// the lid closed, a nearly full disk (machine.mjs), Harness stopping. Running ones go on; new ones start once none
|
|
111
|
+
// holds them.
|
|
112
|
+
const holders = new Map();
|
|
96
113
|
// Why work given to an agent in a thread has not started, as the person reads it (the thread's waits, its notes);
|
|
97
114
|
// null when nothing holds it back.
|
|
98
115
|
const whyWaiting = (goalId, run) => {
|
|
@@ -100,16 +117,13 @@ export function createRunWorker({
|
|
|
100
117
|
const who = nameOf(run.target_agent);
|
|
101
118
|
if (run.target_agent === "harness") {
|
|
102
119
|
const why = store.meta(`harness-wait:${run.id}`);
|
|
103
|
-
return why
|
|
104
|
-
? `Harness's part waits for your Harness window: ${why}.`
|
|
105
|
-
: null;
|
|
120
|
+
return why ? `Harness's part waits: ${why}.` : null;
|
|
106
121
|
}
|
|
107
122
|
if (!RUNNERS.has(run.target_agent) || !run.run_workspace) return null;
|
|
108
123
|
if (!run.run_authorized_at) return `${who} waits for your Start.`;
|
|
109
124
|
const refusal = dispatches?.refusal(run.id);
|
|
110
125
|
if (refusal) return refusal;
|
|
111
|
-
if (
|
|
112
|
-
return `${who} starts when your Mac is no longer running with its lid closed.`;
|
|
126
|
+
if (holders.size) return `${who} starts when ${[...holders.values()][0]}.`;
|
|
113
127
|
const own = activeRuns.get(slotOf({ ...run, parent_id: goalId }));
|
|
114
128
|
if (own)
|
|
115
129
|
return `${who} starts when its turn there now ends: an agent takes one turn at a time in a folder.`;
|
|
@@ -136,7 +150,7 @@ export function createRunWorker({
|
|
|
136
150
|
notifyBoard(store.getTask(task.parent_id));
|
|
137
151
|
};
|
|
138
152
|
const runBoard = () => {
|
|
139
|
-
if (
|
|
153
|
+
if (holders.size || !holdsBoard()) return;
|
|
140
154
|
// One run per agent per folder at a time: other agents and other threads' worktrees run side by side.
|
|
141
155
|
for (const task of store.runnableTasks(installedAgents, machineId(), {
|
|
142
156
|
only: onlyItsOwn(),
|
|
@@ -200,6 +214,7 @@ export function createRunWorker({
|
|
|
200
214
|
const startedAt = new Date().toISOString();
|
|
201
215
|
const {
|
|
202
216
|
prompt,
|
|
217
|
+
whole,
|
|
203
218
|
resumeSession,
|
|
204
219
|
again,
|
|
205
220
|
t3: inT3,
|
|
@@ -214,6 +229,8 @@ export function createRunWorker({
|
|
|
214
229
|
// Work another person asked for runs with only this person's own agent settings: the repository's own (its
|
|
215
230
|
// .claude hooks, .pi, opencode.json) can be that person's, and would run here (security audit P4, October 25).
|
|
216
231
|
const ownSettingsOnly = store.meta(`other-person-run:${task.id}`) === "1";
|
|
232
|
+
// A run in a jam's room reaches that room alone (runAuthority.mjs privateReach).
|
|
233
|
+
const jamThread = store.meta(`jam-run:${task.id}`) || null;
|
|
217
234
|
const chosen = await modelForRun(task, agent);
|
|
218
235
|
store.setRunModel(task.id, chosen);
|
|
219
236
|
const { model, effort } = chosen;
|
|
@@ -227,7 +244,11 @@ export function createRunWorker({
|
|
|
227
244
|
notifyBoard(store.getTask(task.id));
|
|
228
245
|
return;
|
|
229
246
|
}
|
|
230
|
-
const
|
|
247
|
+
const folder = threadRuns.worker.folderForRun(task);
|
|
248
|
+
const t3 =
|
|
249
|
+
inT3 && folder === task.run_workspace
|
|
250
|
+
? t3Turn(task, agent, { model, effort })
|
|
251
|
+
: null;
|
|
231
252
|
// The person's environment grants (vault.mjs), never for a run they did not authorize: the values are in this
|
|
232
253
|
// run's environment, and what it says is scrubbed of them.
|
|
233
254
|
// Nor for a turn another of the person's agents asked for on standing permission: that grants a start, no secrets.
|
|
@@ -237,6 +258,22 @@ export function createRunWorker({
|
|
|
237
258
|
? null
|
|
238
259
|
: vaultEnv(task, agent);
|
|
239
260
|
const granted = secrets && Object.keys(secrets.env).length ? secrets : null;
|
|
261
|
+
// Shown in Herdr only where the turn needs no limits a tab can't hold: it runs in the person's own shell, with no run
|
|
262
|
+
// token and no granted secrets.
|
|
263
|
+
let herdr =
|
|
264
|
+
!t3 &&
|
|
265
|
+
!readOnly &&
|
|
266
|
+
!restricted &&
|
|
267
|
+
!ownSettingsOnly &&
|
|
268
|
+
!granted &&
|
|
269
|
+
folder === task.run_workspace
|
|
270
|
+
? herdrTurn(task, agent)
|
|
271
|
+
: null;
|
|
272
|
+
// An agent a tab runs on its own settings goes there only when no model was picked for the run.
|
|
273
|
+
if (herdr && !herdrTakes(agent, { model })) herdr = null;
|
|
274
|
+
// The tab its session still runs in, for a turn on that same session.
|
|
275
|
+
if (herdr && herdr.tab?.session !== (resumeSession ?? null))
|
|
276
|
+
herdr.tab = null;
|
|
240
277
|
startTurn(task);
|
|
241
278
|
taskRuns.startTask(
|
|
242
279
|
{
|
|
@@ -244,7 +281,7 @@ export function createRunWorker({
|
|
|
244
281
|
agent,
|
|
245
282
|
title: oneLine(task.objective),
|
|
246
283
|
brief: prompt,
|
|
247
|
-
cwd:
|
|
284
|
+
cwd: folder,
|
|
248
285
|
...(model ? { model } : {}),
|
|
249
286
|
...(effort ? { effort } : {}),
|
|
250
287
|
// A model of Harness's AI says its window and longest answer, for an agent told them per run (runner.mjs).
|
|
@@ -254,7 +291,9 @@ export function createRunWorker({
|
|
|
254
291
|
...(readOnly ? { readOnly } : {}),
|
|
255
292
|
...(restricted ? { restricted } : {}),
|
|
256
293
|
...(ownSettingsOnly ? { ownSettingsOnly } : {}),
|
|
257
|
-
...(
|
|
294
|
+
...(jamThread ? { jamThread } : {}),
|
|
295
|
+
...(t3 ? { t3: { ...t3, wholeBrief: whole } } : {}),
|
|
296
|
+
...(herdr ? { herdr } : {}),
|
|
258
297
|
...(granted ? { env: granted.env, scrub: granted.values } : {}),
|
|
259
298
|
},
|
|
260
299
|
(kind, text, extra) => {
|
|
@@ -279,6 +318,9 @@ export function createRunWorker({
|
|
|
279
318
|
if (kind === "accepted" && stoppedFor)
|
|
280
319
|
store.meta(`requeued:${task.id}`, "");
|
|
281
320
|
if (kind === "done" || kind === "failed") {
|
|
321
|
+
// A turn that ended to wait, with nothing written, says what it waits for, not that it finished.
|
|
322
|
+
if (kind === "done" && extra?.nothingSaid && task.parent_id)
|
|
323
|
+
text = waitingLine(task.parent_id, agent, startedAt) ?? text;
|
|
282
324
|
ranOutsideT3.delete(task.id);
|
|
283
325
|
lastStepNotice.delete(task.id);
|
|
284
326
|
activeRuns.delete(slotOf(task));
|
|
@@ -440,15 +482,22 @@ export function createRunWorker({
|
|
|
440
482
|
log(`stopping ${stopped.length} board run(s) because ${reason}`);
|
|
441
483
|
return stopped;
|
|
442
484
|
};
|
|
443
|
-
const hold = (
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
485
|
+
const hold = (
|
|
486
|
+
on,
|
|
487
|
+
{
|
|
488
|
+
by = "lid",
|
|
489
|
+
why = "the Mac is warm with its lid closed",
|
|
490
|
+
until = "your Mac is no longer running with its lid closed",
|
|
491
|
+
} = {}
|
|
492
|
+
) => {
|
|
493
|
+
const was = holders.size > 0;
|
|
494
|
+
if (on === true) holders.set(by, until);
|
|
495
|
+
else holders.delete(by);
|
|
496
|
+
const held = holders.size > 0;
|
|
497
|
+
if (on === true) log(`new runs held: ${why}`);
|
|
498
|
+
else if (was && !held) log("new runs start again");
|
|
499
|
+
if (!held) setImmediate(runBoard);
|
|
500
|
+
return held;
|
|
452
501
|
};
|
|
453
502
|
return {
|
|
454
503
|
slotOf,
|
|
@@ -456,7 +505,7 @@ export function createRunWorker({
|
|
|
456
505
|
runBoard,
|
|
457
506
|
interruptAll,
|
|
458
507
|
hold,
|
|
459
|
-
held: () =>
|
|
508
|
+
held: () => holders.size > 0,
|
|
460
509
|
activeRuns: {
|
|
461
510
|
get: (slot) => activeRuns.get(slot),
|
|
462
511
|
values: () => activeRuns.values(),
|