tryharness 0.7.45 → 0.7.54
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 +239 -14
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +497 -196
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +165 -222
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +570 -0
- package/lib/agentSignIn.mjs +226 -0
- package/lib/atlas.mjs +7 -2
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +523 -0
- package/lib/boardProtocol.json +263 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +26 -4
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +159 -16
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +25 -5
- package/lib/connectionTools.d.ts +13 -0
- package/lib/connectionTools.js +45 -0
- package/lib/connectorAuth.mjs +309 -0
- package/lib/connectorCatalog.json +41 -0
- package/lib/connectorCommands.mjs +121 -0
- package/lib/connectorGoogle.mjs +513 -0
- package/lib/connectors.mjs +805 -0
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +152 -39
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +973 -54
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +113 -8
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +825 -0
- package/lib/folders.mjs +4 -4
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +58 -14
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +263 -152
- package/lib/landed.mjs +887 -0
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- package/lib/live.mjs +284 -13
- package/lib/localmodels.mjs +10 -0
- package/lib/machineIdentity.mjs +3 -0
- package/lib/machineRoutes.mjs +40 -2
- package/lib/machineRuns.mjs +30 -3
- package/lib/machineSeal.mjs +69 -10
- package/lib/mcp-stdio.mjs +189 -120
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +26 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/models.mjs +48 -15
- package/lib/museSession.mjs +122 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +57 -18
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +828 -39
- package/lib/pairing.mjs +182 -0
- package/lib/paths.mjs +8 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +119 -3
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +337 -9
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +400 -0
- package/lib/record.mjs +115 -0
- package/lib/repoLinks.mjs +354 -0
- package/lib/roomChannels.mjs +641 -0
- package/lib/runBrief.mjs +32 -2
- package/lib/runRequests.mjs +157 -0
- package/lib/runWorker.mjs +37 -9
- package/lib/runner.mjs +74 -11
- package/lib/secretPatterns.json +55 -0
- package/lib/secrets.mjs +10 -27
- package/lib/seen.mjs +102 -0
- package/lib/service.mjs +11 -6
- package/lib/sessionControl.mjs +386 -96
- package/lib/sessionIndex.mjs +5 -3
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +829 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +483 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +56 -17
- package/lib/taskCommands.mjs +91 -13
- package/lib/taskRuns.mjs +68 -11
- package/lib/team.json +253 -144
- package/lib/team.mjs +538 -147
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +78 -12
- package/lib/threadView.mjs +66 -16
- package/lib/tokenizer.mjs +405 -0
- package/lib/ui.mjs +16 -2
- package/lib/usageTotals.mjs +148 -0
- package/lib/vault.mjs +1144 -0
- package/lib/vaultCloud.mjs +117 -0
- package/lib/vaultCommands.mjs +201 -0
- package/lib/vaultTools.d.ts +12 -0
- package/lib/vaultTools.js +42 -0
- package/lib/windowAsks.mjs +42 -0
- package/lib/workFocus.mjs +59 -0
- package/lib/workLinks.mjs +90 -0
- package/lib/worktrees.mjs +51 -13
- package/package.json +10 -5
package/lib/t3.mjs
CHANGED
|
@@ -42,6 +42,8 @@ export async function findT3(home = t3Home(), hint = null) {
|
|
|
42
42
|
} catch {
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
|
+
// "late" when the limit ran out: either nothing answered in time, or this process was busy past the limit and its
|
|
46
|
+
// timer fired before it read an answer already waiting.
|
|
45
47
|
const answers = async (origin) => {
|
|
46
48
|
try {
|
|
47
49
|
const response = await fetch(`${origin}/.well-known/t3/environment`, {
|
|
@@ -50,19 +52,30 @@ export async function findT3(home = t3Home(), hint = null) {
|
|
|
50
52
|
return (
|
|
51
53
|
response.ok && (await response.json())?.environmentId === environmentId
|
|
52
54
|
);
|
|
53
|
-
} catch {
|
|
54
|
-
return false;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return error?.name === "TimeoutError" ? "late" : false;
|
|
55
57
|
}
|
|
56
58
|
};
|
|
57
|
-
|
|
59
|
+
// The address T3 last answered on is asked again when it was late: the daemon's own work blocked it for up to 11 s
|
|
60
|
+
// during the context engine's pass (October 23, .harness-runs/measure/t3-probe) while T3 answered in under 50 ms,
|
|
61
|
+
// so a late answer there said "not running" and the T3 threads list emptied.
|
|
62
|
+
if (hint) {
|
|
63
|
+
const first = await answers(hint);
|
|
64
|
+
const found = first === "late" ? await answers(hint) : first;
|
|
65
|
+
if (found === true) return { origin: hint, environmentId };
|
|
66
|
+
}
|
|
58
67
|
for (let port = FIRST_PORT; port < FIRST_PORT + PORTS; port++) {
|
|
59
68
|
const origin = `http://127.0.0.1:${port}`;
|
|
60
|
-
if (origin !== hint && (await answers(origin)))
|
|
69
|
+
if (origin !== hint && (await answers(origin)) === true)
|
|
61
70
|
return { origin, environmentId };
|
|
62
71
|
}
|
|
63
72
|
return null;
|
|
64
73
|
}
|
|
65
74
|
|
|
75
|
+
/** Whether T3 Code has run on this computer: it writes its environment id the first time it starts. */
|
|
76
|
+
export const t3Installed = (home = t3Home()) =>
|
|
77
|
+
fs.existsSync(path.join(home, "environment-id"));
|
|
78
|
+
|
|
66
79
|
/** What Harness may do in T3 Code: "send", "read", "expired", or null before the person approves it. */
|
|
67
80
|
export function t3Access() {
|
|
68
81
|
const saved = readJson(file(), null);
|
|
@@ -76,6 +89,8 @@ export function t3Access() {
|
|
|
76
89
|
? "send"
|
|
77
90
|
: "read",
|
|
78
91
|
until: saved.expiresAt,
|
|
92
|
+
environmentId: saved.environmentId,
|
|
93
|
+
grantedAt: saved.approvedAt,
|
|
79
94
|
};
|
|
80
95
|
}
|
|
81
96
|
|
|
@@ -330,7 +345,14 @@ async function callTool(origin, token, name, args) {
|
|
|
330
345
|
}
|
|
331
346
|
|
|
332
347
|
/** One of T3's tools, as Harness was approved to use them, at T3's current address. */
|
|
333
|
-
|
|
348
|
+
const READ_TOOLS = new Set([
|
|
349
|
+
"orchestrator_capabilities",
|
|
350
|
+
"t3_project_list",
|
|
351
|
+
"t3_thread_list",
|
|
352
|
+
"t3_thread_read",
|
|
353
|
+
]);
|
|
354
|
+
|
|
355
|
+
export async function t3Tool(name, args) {
|
|
334
356
|
const saved = readJson(file(), null);
|
|
335
357
|
const access = t3Access();
|
|
336
358
|
if (!access)
|
|
@@ -340,7 +362,7 @@ async function t3Tool(name, args) {
|
|
|
340
362
|
);
|
|
341
363
|
if (access.state === "expired")
|
|
342
364
|
throw new T3Error("expired", "Harness's approval in T3 Code ran out.");
|
|
343
|
-
if (access.state !== "send")
|
|
365
|
+
if (access.state !== "send" && !READ_TOOLS.has(name))
|
|
344
366
|
throw new T3Error(
|
|
345
367
|
"read_only",
|
|
346
368
|
"Harness was approved in T3 Code to read only."
|
|
@@ -429,6 +451,9 @@ function stepOf(item) {
|
|
|
429
451
|
|
|
430
452
|
// The option T3 gives each agent's effort under, by agent.
|
|
431
453
|
const EFFORT_OPTIONS = new Set(["reasoningEffort", "effort"]);
|
|
454
|
+
// An option's choices: `values` since T3 #22889 (October 21), `options: [{ id }]` before.
|
|
455
|
+
const choicesOf = (option) =>
|
|
456
|
+
option.values ?? option.options?.map((level) => level.id) ?? [];
|
|
432
457
|
const versionOf = (id) => (id.match(/\d+/g) ?? []).map(Number);
|
|
433
458
|
const newerFirst = (a, b) => {
|
|
434
459
|
const [left, right] = [versionOf(a.id), versionOf(b.id)];
|
|
@@ -437,6 +462,15 @@ const newerFirst = (a, b) => {
|
|
|
437
462
|
return (right[i] ?? -1) - (left[i] ?? -1);
|
|
438
463
|
return 0;
|
|
439
464
|
};
|
|
465
|
+
const matching = (provider, model) => {
|
|
466
|
+
const offered = provider?.models ?? [];
|
|
467
|
+
return (
|
|
468
|
+
offered.find((entry) => entry.id === model) ??
|
|
469
|
+
offered
|
|
470
|
+
.filter((entry) => entry.id.startsWith(`claude-${model}-`))
|
|
471
|
+
.sort(newerFirst)[0]
|
|
472
|
+
);
|
|
473
|
+
};
|
|
440
474
|
|
|
441
475
|
/**
|
|
442
476
|
* The selection T3 Code runs an agent's turn with: the model and effort the buddy shows for it (the person's pick, else
|
|
@@ -444,26 +478,31 @@ const newerFirst = (a, b) => {
|
|
|
444
478
|
* a short name (opus), which is the newest of that family T3 offers. Null when nothing names a model. A model or effort
|
|
445
479
|
* T3 does not offer fails the turn rather than letting T3 run it on another (October 17: Codex ran on gpt-6-astra
|
|
446
480
|
* for days while the buddy showed gpt-6.1-sol).
|
|
481
|
+
*
|
|
482
|
+
* Since T3 #22889 (October 21) T3 lists a short list of each agent's models and says how many it left out; a model not
|
|
483
|
+
* on it is looked up with T3's search. An older T3 lists every model and leaves out none, so it is never searched.
|
|
447
484
|
*/
|
|
448
485
|
async function selectionFor({ instanceId, model, effort } = {}) {
|
|
449
486
|
if (!model) return null;
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
487
|
+
const offering = async (args) =>
|
|
488
|
+
(await t3Tool("orchestrator_capabilities", args)).providers?.find(
|
|
489
|
+
(entry) => entry.providerInstanceId === instanceId
|
|
490
|
+
);
|
|
491
|
+
const listed = await offering({});
|
|
492
|
+
const searched =
|
|
493
|
+
!matching(listed, model) && listed?.omittedModels
|
|
494
|
+
? await offering({ search: model })
|
|
495
|
+
: null;
|
|
496
|
+
const provider = searched ?? listed;
|
|
497
|
+
const found = matching(provider, model);
|
|
459
498
|
if (!found)
|
|
460
499
|
throw new T3Error(
|
|
461
500
|
"model",
|
|
462
|
-
`T3 Code does not offer ${model} for this agent (it offers ${
|
|
501
|
+
`T3 Code does not offer ${model} for this agent (it offers ${(provider?.models ?? []).map((entry) => entry.id).join(", ") || "none"}).`
|
|
463
502
|
);
|
|
464
503
|
if (!effort) return { instanceId, model: found.id, options: [] };
|
|
465
504
|
const option = found.options?.find((entry) => EFFORT_OPTIONS.has(entry.id));
|
|
466
|
-
if (!option
|
|
505
|
+
if (!option || !choicesOf(option).includes(effort))
|
|
467
506
|
throw new T3Error(
|
|
468
507
|
"model",
|
|
469
508
|
`T3 Code does not offer effort ${effort} for ${found.id}.`
|
package/lib/taskCommands.mjs
CHANGED
|
@@ -18,9 +18,12 @@ import {
|
|
|
18
18
|
swarmBlock,
|
|
19
19
|
swarmDigest,
|
|
20
20
|
toldBlock,
|
|
21
|
+
youLine,
|
|
21
22
|
} from "./cards.mjs";
|
|
22
23
|
import { PICKABLE, resolvePick, setRunPick } from "./models.mjs";
|
|
23
24
|
import { onMachine, placeTask } from "./machineRoutes.mjs";
|
|
25
|
+
import { within } from "./folders.mjs";
|
|
26
|
+
import { recordClaims } from "./audit.mjs";
|
|
24
27
|
|
|
25
28
|
// An agent working in a thread may bring another agent in for part of the work there, as Harness does when it names
|
|
26
29
|
// one; an agent that moves money or takes positions joins only when the person names it (members.mjs TAGGED_ONLY).
|
|
@@ -29,9 +32,17 @@ const joinsThread = (thread, target, roomAgents) =>
|
|
|
29
32
|
thread.goal.team.includes(String(target)) ||
|
|
30
33
|
(roomAgents.includes(String(target)) &&
|
|
31
34
|
!TAGGED_ONLY.includes(String(target)));
|
|
35
|
+
// Work in another repository is its own thread: an agent's session, and its T3 thread, belong to the folder it ran in,
|
|
36
|
+
// so a thread's turns all run in the thread's folder. A thread with no folder yet takes the work's (daemon.mjs joinRoom).
|
|
37
|
+
const sameFolder = (thread, folder) =>
|
|
38
|
+
!folder ||
|
|
39
|
+
!thread.goal.workspace ||
|
|
40
|
+
within(path.resolve(String(folder)), thread.goal.workspace);
|
|
32
41
|
|
|
33
42
|
export function createTaskCommands({
|
|
34
43
|
CLOUD_TARGETS,
|
|
44
|
+
// The onchain desk (desk.mjs): a Bankr ask in a thread under a strategy carries its instructions, never the book.
|
|
45
|
+
desk = null,
|
|
35
46
|
OPENED,
|
|
36
47
|
machines,
|
|
37
48
|
ROOM_AGENTS,
|
|
@@ -70,12 +81,16 @@ export function createTaskCommands({
|
|
|
70
81
|
authority,
|
|
71
82
|
actors,
|
|
72
83
|
files: boardFiles,
|
|
84
|
+
// Threads mirrored from another app (environments.mjs), when the person reads them here.
|
|
85
|
+
outside = () => null,
|
|
73
86
|
}) {
|
|
74
87
|
// The one open thread an agent is working in now, when the work it hands on may join it there.
|
|
75
|
-
const soleThreadOf = (agent, target) => {
|
|
88
|
+
const soleThreadOf = (agent, target, folder) => {
|
|
76
89
|
const working = store.threadsWorkedIn(agent);
|
|
77
90
|
const thread = working.length === 1 ? store.getTask(working[0]) : null;
|
|
78
|
-
return thread &&
|
|
91
|
+
return thread &&
|
|
92
|
+
joinsThread(thread, target, ROOM_AGENTS) &&
|
|
93
|
+
sameFolder(thread, folder)
|
|
79
94
|
? thread.id
|
|
80
95
|
: null;
|
|
81
96
|
};
|
|
@@ -117,6 +132,7 @@ export function createTaskCommands({
|
|
|
117
132
|
hosted: Boolean(request.hostedCaller),
|
|
118
133
|
into: opts.into,
|
|
119
134
|
folder: opts.folder,
|
|
135
|
+
machine: opts.machine,
|
|
120
136
|
}
|
|
121
137
|
);
|
|
122
138
|
const opened = room.id !== opts.into;
|
|
@@ -221,7 +237,7 @@ export function createTaskCommands({
|
|
|
221
237
|
// for the person's Start is decided exactly as for work outside any thread: placing it grants nothing.
|
|
222
238
|
const workingThread =
|
|
223
239
|
!request.parentId && !request.thread && agent !== "user"
|
|
224
|
-
? soleThreadOf(agent, request.targetAgent)
|
|
240
|
+
? soleThreadOf(agent, request.targetAgent, request.runWorkspace)
|
|
225
241
|
: null;
|
|
226
242
|
// Provenance is code's: the local parent's label and what Harness sent from above the poster can only tighten it.
|
|
227
243
|
const parentTask = request.parentId
|
|
@@ -281,6 +297,7 @@ export function createTaskCommands({
|
|
|
281
297
|
kind: "job",
|
|
282
298
|
text: `Posted a job${request.targetAgent ? ` for ${request.targetAgent}` : ""}: ${objective}`,
|
|
283
299
|
mentions: request.targetAgent ? [String(request.targetAgent)] : [],
|
|
300
|
+
machine,
|
|
284
301
|
});
|
|
285
302
|
}
|
|
286
303
|
// The folder a coding agent posts from (its stdio MCP's, which each agent starts in the session's folder); never
|
|
@@ -303,12 +320,16 @@ export function createTaskCommands({
|
|
|
303
320
|
error: `${request.targetAgent} lives in Harness, and the daemon is not connected to it right now`,
|
|
304
321
|
};
|
|
305
322
|
if (goalParent || request.parentId || agent === "user")
|
|
306
|
-
return forwardToHarness({
|
|
323
|
+
return forwardToHarness({
|
|
324
|
+
...(desk ? desk.forBankr(request) : request),
|
|
325
|
+
provenance: upstream,
|
|
326
|
+
});
|
|
307
327
|
return forwardIntoRoom(request, upstream, provenance, {
|
|
308
328
|
agent,
|
|
309
329
|
objective,
|
|
310
330
|
into: workingThread,
|
|
311
331
|
folder: askerFolder,
|
|
332
|
+
machine,
|
|
312
333
|
});
|
|
313
334
|
}
|
|
314
335
|
// Which of the person's computers the work is for: the one named, else the poster's own when it works there in a
|
|
@@ -554,6 +575,7 @@ export function createTaskCommands({
|
|
|
554
575
|
hosted: Boolean(request.hostedCaller),
|
|
555
576
|
into: workingThread,
|
|
556
577
|
folder: askerFolder,
|
|
578
|
+
machine,
|
|
557
579
|
});
|
|
558
580
|
const note = task.target_agent
|
|
559
581
|
? actors.setupNote(task.target_agent)
|
|
@@ -588,13 +610,18 @@ export function createTaskCommands({
|
|
|
588
610
|
{ lessons: local }
|
|
589
611
|
);
|
|
590
612
|
const told = local ? lessons.told() : [];
|
|
591
|
-
// Its parts too, so a session start short of room can send the cards in short form (nudge.mjs).
|
|
613
|
+
// Its parts too, so a session start short of room can send the cards in short form (nudge.mjs). `you`: who the
|
|
614
|
+
// caller is and the computer it runs on, the computer its call came from. Specialties by name here; list_agents
|
|
615
|
+
// gives each one's evidence.
|
|
592
616
|
extra.swarm = {
|
|
593
|
-
text: swarmBlock(cards, Date.now(), told),
|
|
617
|
+
text: swarmBlock(cards, Date.now(), told, { evidence: false }),
|
|
594
618
|
digest: swarmDigest(cards, told),
|
|
595
|
-
cards: cards.map((card) =>
|
|
619
|
+
cards: cards.map((card) =>
|
|
620
|
+
cardLine(card, Date.now(), { evidence: false })
|
|
621
|
+
),
|
|
596
622
|
short: cards.map(shortCardLine),
|
|
597
623
|
told: toldBlock(told),
|
|
624
|
+
you: local ? youLine(agent, machines.whereIs(machine)) : "",
|
|
598
625
|
};
|
|
599
626
|
}
|
|
600
627
|
// The goal rooms an agent is on, for list_tasks and a session start: a start short of room points here for them.
|
|
@@ -610,7 +637,7 @@ export function createTaskCommands({
|
|
|
610
637
|
ok: true,
|
|
611
638
|
tasks,
|
|
612
639
|
...extra,
|
|
613
|
-
unread: store.unreadFor(agent),
|
|
640
|
+
unread: store.unreadFor(agent, machine),
|
|
614
641
|
goals: rooms(),
|
|
615
642
|
}
|
|
616
643
|
: { ok: true, tasks, ...extra };
|
|
@@ -628,6 +655,7 @@ export function createTaskCommands({
|
|
|
628
655
|
author: agent,
|
|
629
656
|
text: String(request.text || "").slice(0, 20000),
|
|
630
657
|
source: request.source ? String(request.source).slice(0, 1024) : null,
|
|
658
|
+
machine,
|
|
631
659
|
});
|
|
632
660
|
return entry
|
|
633
661
|
? { ok: true, entry, context: store.contextCount(id) }
|
|
@@ -802,6 +830,17 @@ export function createTaskCommands({
|
|
|
802
830
|
error:
|
|
803
831
|
"a task given to Harness is taken by an up-to-date Harness window by itself, as its own message; leave it open",
|
|
804
832
|
};
|
|
833
|
+
// The extension's hidden Harness page takes only what the person let it finish in their browser (swarm.mjs
|
|
834
|
+
// board.swarm.use_browser): the message that woke it is no permission.
|
|
835
|
+
else if (
|
|
836
|
+
request.command === "board.claim" &&
|
|
837
|
+
request.browser === true &&
|
|
838
|
+
!store.meta(`harness-browser-allowed:${id}`)
|
|
839
|
+
)
|
|
840
|
+
return {
|
|
841
|
+
ok: false,
|
|
842
|
+
error: "the person has not let Harness use their browser for this",
|
|
843
|
+
};
|
|
805
844
|
else if (request.command === "board.claim") {
|
|
806
845
|
outcome = store.claimTask(
|
|
807
846
|
id,
|
|
@@ -844,7 +883,7 @@ export function createTaskCommands({
|
|
|
844
883
|
store.setRunSession(id, session);
|
|
845
884
|
outcome = { ...outcome, task: store.getTask(id) };
|
|
846
885
|
}
|
|
847
|
-
} else if (request.command === "board.report")
|
|
886
|
+
} else if (request.command === "board.report") {
|
|
848
887
|
outcome = store.reportTask(
|
|
849
888
|
id,
|
|
850
889
|
agent,
|
|
@@ -855,14 +894,42 @@ export function createTaskCommands({
|
|
|
855
894
|
expected,
|
|
856
895
|
machine
|
|
857
896
|
);
|
|
858
|
-
|
|
897
|
+
// What the report claims in its structured fields, which the auditor's code compares with the receipts.
|
|
898
|
+
if (outcome?.ok && request.claims) {
|
|
899
|
+
recordClaims(store, id, request.claims);
|
|
900
|
+
outcome = { ...outcome, task: store.getTask(id) };
|
|
901
|
+
}
|
|
902
|
+
} else if (request.command === "board.answer")
|
|
859
903
|
outcome = store.answerTask(
|
|
860
904
|
id,
|
|
861
905
|
agent,
|
|
862
906
|
String(request.answer || "").slice(0, 20000),
|
|
863
|
-
expected
|
|
907
|
+
expected,
|
|
908
|
+
machine
|
|
864
909
|
);
|
|
865
|
-
|
|
910
|
+
// The hidden Harness page stopped at a question for the person, who may be away: the task waits for them at
|
|
911
|
+
// their computer, saying what it would ask, and is not offered to the browser again until they open Harness. Given
|
|
912
|
+
// back for Harness as this daemon gives back what Harness's server left for the browser (daemon.mjs).
|
|
913
|
+
else if (
|
|
914
|
+
request.command === "board.release" &&
|
|
915
|
+
agent === "harness" &&
|
|
916
|
+
request.browser === true
|
|
917
|
+
) {
|
|
918
|
+
const task = store.getTask(id);
|
|
919
|
+
if (task?.claimed_by !== "harness" || !store.meta(`harness-window:${id}`))
|
|
920
|
+
return {
|
|
921
|
+
ok: false,
|
|
922
|
+
error: "that is not Harness's work in your browser",
|
|
923
|
+
};
|
|
924
|
+
outcome = store.releaseTask(id, "user", expected);
|
|
925
|
+
if (outcome?.ok) {
|
|
926
|
+
store.meta(`harness-browser-allowed:${id}`, "");
|
|
927
|
+
store.meta(
|
|
928
|
+
`harness-browser-stopped:${id}`,
|
|
929
|
+
String(request.why || "a question for you").slice(0, 300)
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
} else if (request.command === "board.release")
|
|
866
933
|
outcome = store.releaseTask(id, agent, expected);
|
|
867
934
|
else if (request.command === "board.remove") {
|
|
868
935
|
if (agent !== "user")
|
|
@@ -870,6 +937,8 @@ export function createTaskCommands({
|
|
|
870
937
|
ok: false,
|
|
871
938
|
error: "only the person removes work from the board",
|
|
872
939
|
};
|
|
940
|
+
// A thread mirrored from T3 Code leaves Harness's list; T3 keeps it.
|
|
941
|
+
if (outside()?.owns(id)) return outside().hide(id);
|
|
873
942
|
const task = store.getTask(id);
|
|
874
943
|
if (!task || task.removed_at)
|
|
875
944
|
return { ok: false, error: "task not found" };
|
|
@@ -961,8 +1030,17 @@ export function createTaskCommands({
|
|
|
961
1030
|
store.meta(`machine-step:${id}`, new Date().toISOString());
|
|
962
1031
|
return { ok: true };
|
|
963
1032
|
} else if (request.command === "board.machine.finish") {
|
|
964
|
-
|
|
1033
|
+
const ran = store.getTask(id);
|
|
1034
|
+
if (request.usage && ran?.claimed_machine === machine)
|
|
965
1035
|
store.setRunUsage(id, request.usage);
|
|
1036
|
+
// The run's session, when its own call did not reach home before the finish (machineRuns.mjs).
|
|
1037
|
+
if (
|
|
1038
|
+
typeof request.session === "string" &&
|
|
1039
|
+
ran?.claimed_machine === machine &&
|
|
1040
|
+
ran.holder === agent &&
|
|
1041
|
+
!ran.session_id
|
|
1042
|
+
)
|
|
1043
|
+
store.setRunSession(id, request.session.slice(0, 256));
|
|
966
1044
|
outcome = store.reportTask(
|
|
967
1045
|
id,
|
|
968
1046
|
agent,
|
package/lib/taskRuns.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { scrubValues } from "./vault.mjs";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
|
|
@@ -8,7 +9,41 @@ import { runInT3 } from "./t3.mjs";
|
|
|
8
9
|
|
|
9
10
|
const TASK_LOG_PAGE = 64_000;
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* What a run with secrets in its environment says, with their values replaced by markers (vault.mjs). An agent's
|
|
14
|
+
* output arrives in pieces, so each stream holds back the end of what it has seen that could begin a value; it is
|
|
15
|
+
* written once the rest arrives, or when the run ends.
|
|
16
|
+
*/
|
|
17
|
+
function streamScrubber(values) {
|
|
18
|
+
if (!(values instanceof Map) || values.size === 0)
|
|
19
|
+
return { text: (text) => text, stream: (_, raw) => raw, flush: () => [] };
|
|
20
|
+
const longest = Math.max(
|
|
21
|
+
...[...values.values()].map((value) => encodeURIComponent(value).length)
|
|
22
|
+
);
|
|
23
|
+
const held = new Map();
|
|
24
|
+
return {
|
|
25
|
+
text: (text) =>
|
|
26
|
+
typeof text === "string" ? scrubValues(text, values) : text,
|
|
27
|
+
stream: (stream, raw) => {
|
|
28
|
+
const clean = scrubValues((held.get(stream) ?? "") + raw, values);
|
|
29
|
+
const keep = Math.min(clean.length, longest - 1);
|
|
30
|
+
held.set(stream, clean.slice(clean.length - keep));
|
|
31
|
+
return clean.slice(0, clean.length - keep);
|
|
32
|
+
},
|
|
33
|
+
flush: () => {
|
|
34
|
+
const rest = [...held].filter(([, text]) => text);
|
|
35
|
+
held.clear();
|
|
36
|
+
return rest;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `onOutput` hears a run's output reach its log: the steps every surface shows from it moved. */
|
|
42
|
+
export function createTaskRuns({
|
|
43
|
+
t3Missed,
|
|
44
|
+
nativeRequests = null,
|
|
45
|
+
onOutput = () => {},
|
|
46
|
+
}) {
|
|
12
47
|
const taskRuns = new Map();
|
|
13
48
|
const validRunId = (runId) =>
|
|
14
49
|
typeof runId === "string" && /^[a-zA-Z0-9._-]{1,128}$/.test(runId);
|
|
@@ -128,13 +163,27 @@ export function createTaskRuns({ t3Missed }) {
|
|
|
128
163
|
};
|
|
129
164
|
taskRuns.set(message.runId, task);
|
|
130
165
|
persistTask(task);
|
|
131
|
-
const
|
|
166
|
+
const scrub = streamScrubber(message.scrub);
|
|
167
|
+
const appendLog = (stream, text) => {
|
|
168
|
+
try {
|
|
169
|
+
fs.appendFileSync(
|
|
170
|
+
files.log,
|
|
171
|
+
stream === "stderr" ? `\n[stderr] ${text}` : text,
|
|
172
|
+
{ mode: 0o600 }
|
|
173
|
+
);
|
|
174
|
+
} catch {}
|
|
175
|
+
};
|
|
176
|
+
const emit = (kind, rawText, extra) => {
|
|
177
|
+
const text = scrub.text(rawText);
|
|
178
|
+
if (kind === "done" || kind === "failed")
|
|
179
|
+
for (const [stream, rest] of scrub.flush()) appendLog(stream, rest);
|
|
132
180
|
if (kind === "accepted") task.status = "running";
|
|
133
181
|
if (kind === "session") {
|
|
134
182
|
task.sessionId = text || null;
|
|
135
183
|
if (extra?.cwd) task.cwd = extra.cwd;
|
|
136
184
|
}
|
|
137
185
|
if (kind === "done" || kind === "failed") {
|
|
186
|
+
nativeRequests?.finish(message.runId);
|
|
138
187
|
task.status = kind;
|
|
139
188
|
task.finishedAt = new Date().toISOString();
|
|
140
189
|
task.message = text || null;
|
|
@@ -146,14 +195,22 @@ export function createTaskRuns({ t3Missed }) {
|
|
|
146
195
|
report(kind, text, extra);
|
|
147
196
|
};
|
|
148
197
|
const observe = (stream, raw) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{ mode: 0o600 }
|
|
154
|
-
);
|
|
155
|
-
} catch {}
|
|
198
|
+
const text = scrub.stream(stream, raw);
|
|
199
|
+
if (!text) return;
|
|
200
|
+
appendLog(stream, text);
|
|
201
|
+
onOutput(message.runId);
|
|
156
202
|
};
|
|
203
|
+
const hooks = nativeRequests
|
|
204
|
+
? {
|
|
205
|
+
requestApproval: (approval, signal) =>
|
|
206
|
+
nativeRequests.request({
|
|
207
|
+
runId: message.runId,
|
|
208
|
+
agent: message.agent,
|
|
209
|
+
approval,
|
|
210
|
+
signal,
|
|
211
|
+
}),
|
|
212
|
+
}
|
|
213
|
+
: {};
|
|
157
214
|
if (message.t3)
|
|
158
215
|
runInT3(
|
|
159
216
|
{
|
|
@@ -176,13 +233,13 @@ export function createTaskRuns({ t3Missed }) {
|
|
|
176
233
|
`[${why} This turn runs on this computer instead, in ${checkout}.]\n`
|
|
177
234
|
);
|
|
178
235
|
t3Missed(message.runId, why);
|
|
179
|
-
runAgentTask({ ...message, cwd: checkout }, emit, observe);
|
|
236
|
+
runAgentTask({ ...message, cwd: checkout }, emit, observe, hooks);
|
|
180
237
|
},
|
|
181
238
|
},
|
|
182
239
|
emit,
|
|
183
240
|
observe
|
|
184
241
|
);
|
|
185
|
-
else runAgentTask(message, emit, observe);
|
|
242
|
+
else runAgentTask(message, emit, observe, hooks);
|
|
186
243
|
};
|
|
187
244
|
const requeue = (id, reason) => {
|
|
188
245
|
const record = taskRuns.get(id);
|