tryharness 0.7.54 → 0.7.57
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 +15 -16
- package/cli.mjs +377 -62
- package/lib/activity.mjs +10 -10
- package/lib/adapters.mjs +16 -0
- package/lib/agentBinaries.mjs +71 -0
- package/lib/agentRuntimeConfig.mjs +1 -1
- package/lib/agentRuntimes.mjs +9 -3
- package/lib/agentSignIn.mjs +271 -41
- package/lib/answers.mjs +5 -5
- package/lib/archetypes.d.ts +64 -0
- package/lib/archetypes.js +989 -0
- package/lib/asks.mjs +4 -4
- package/lib/audit.mjs +36 -13
- package/lib/backupSetup.mjs +4 -2
- package/lib/boardAccess.mjs +17 -11
- package/lib/boardBackup.mjs +6 -6
- package/lib/boardFileCommands.mjs +6 -6
- package/lib/boardFiles.mjs +13 -12
- package/lib/boardMirror.mjs +82 -47
- package/lib/boardProtocol.json +30 -1
- package/lib/boardWaits.mjs +2 -3
- package/lib/book.mjs +6 -6
- package/lib/bridge.mjs +5 -5
- package/lib/cards.mjs +2 -2
- package/lib/cloudAgents.mjs +216 -0
- package/lib/cloudAi.mjs +1312 -0
- package/lib/cloudAssistants.mjs +242 -0
- package/lib/cloudBoot.mjs +81 -86
- package/lib/cloudSave.mjs +197 -0
- package/lib/cloudSsh.mjs +178 -0
- package/lib/context.mjs +3 -3
- package/lib/contractGate.mjs +34 -12
- package/lib/control-client.mjs +9 -1
- package/lib/controlSocket.mjs +86 -0
- package/lib/coordinator.mjs +103 -101
- package/lib/daemon.mjs +1128 -2865
- package/lib/desk.mjs +7 -6
- package/lib/desktop.mjs +72 -68
- package/lib/directLink.mjs +16 -5
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +14 -6
- package/lib/firewall.mjs +9 -9
- package/lib/folders.mjs +18 -14
- package/lib/frames.mjs +2 -3
- package/lib/gitHost.mjs +3 -3
- package/lib/goalCommands.mjs +25 -7
- package/lib/goals.mjs +7 -7
- package/lib/guestRequests.mjs +94 -0
- package/lib/handoffs.mjs +8 -7
- package/lib/handover.mjs +4 -4
- package/lib/harnessModel.mjs +6 -6
- package/lib/harnessOffers.mjs +266 -0
- package/lib/inference.mjs +26 -8
- package/lib/jobAnswers.mjs +190 -0
- package/lib/landed.mjs +1 -1
- package/lib/lane.mjs +42 -11
- package/lib/lessons.mjs +16 -16
- package/lib/library.mjs +3 -3
- package/lib/lineup.mjs +3 -0
- package/lib/linkRelay.mjs +574 -0
- package/lib/localAgentAsk.mjs +74 -0
- package/lib/localStack.mjs +536 -0
- package/lib/localmodels.mjs +6 -4
- package/lib/loopBackstop.mjs +4 -4
- package/lib/machineIdentity.mjs +9 -1
- package/lib/machineRoutes.mjs +181 -2
- package/lib/machineRuns.mjs +76 -1
- package/lib/machineSeal.mjs +39 -12
- package/lib/mcp-stdio.mjs +96 -26
- package/lib/mcpRelay.mjs +1 -1
- package/lib/members.json +13 -0
- package/lib/members.mjs +1 -1
- package/lib/models.mjs +77 -23
- package/lib/museSession.mjs +6 -1
- package/lib/nativeHost.mjs +35 -7
- package/lib/network.mjs +50 -5
- package/lib/notify.mjs +7 -5
- package/lib/nudge.mjs +3 -3
- package/lib/ocr.mjs +9 -9
- package/lib/onboard.mjs +26 -20
- package/lib/oneLine.mjs +7 -7
- package/lib/ownMachines.mjs +928 -149
- package/lib/pairing.mjs +33 -6
- package/lib/paths.mjs +15 -1
- package/lib/peerProcess.mjs +124 -0
- package/lib/personModel.mjs +3 -3
- package/lib/personNotices.mjs +151 -0
- package/lib/phones.mjs +490 -38
- package/lib/placeCommands.mjs +4 -4
- package/lib/places.mjs +70 -2
- package/lib/profile.mjs +67 -14
- package/lib/projectGit.mjs +158 -14
- package/lib/projectPieces.mjs +902 -0
- package/lib/projectSettings.mjs +7 -4
- package/lib/projects.mjs +384 -62
- package/lib/provenance.mjs +5 -1
- package/lib/proxyLinks.mjs +267 -0
- package/lib/reactions.mjs +7 -5
- package/lib/readiness.mjs +12 -7
- package/lib/record.mjs +19 -6
- package/lib/redact.mjs +4 -4
- package/lib/relayLimits.mjs +62 -0
- package/lib/release.mjs +170 -0
- package/lib/releaseKeys.json +6 -0
- package/lib/repoLinks.mjs +4 -4
- package/lib/roomChannels.mjs +24 -0
- package/lib/roomPage.mjs +1 -1
- package/lib/runAuthority.mjs +101 -0
- package/lib/runBrief.mjs +19 -8
- package/lib/runWorker.mjs +14 -5
- package/lib/runner.mjs +215 -25
- package/lib/runtime-install.mjs +143 -9
- package/lib/schedules.mjs +2 -2
- package/lib/screens.mjs +1 -1
- package/lib/sealed.mjs +11 -2
- package/lib/sealedThreads.mjs +671 -0
- package/lib/secretPatterns.json +1 -1
- package/lib/secrets.mjs +4 -4
- package/lib/seen.mjs +6 -6
- package/lib/serverWords.mjs +175 -0
- package/lib/service.mjs +22 -12
- package/lib/sessionControl.mjs +6 -6
- package/lib/specialties.mjs +6 -6
- package/lib/specialtyKeys.js +4 -5
- package/lib/specialtyNotice.mjs +7 -7
- package/lib/specialtySnapshot.mjs +5 -5
- package/lib/speech.mjs +5 -5
- package/lib/store.mjs +140 -39
- package/lib/stuck.mjs +1 -1
- package/lib/swarm.mjs +167 -16
- package/lib/swarmDevices.mjs +319 -0
- package/lib/swarmMemory.mjs +27 -25
- package/lib/t3.mjs +13 -13
- package/lib/taskCommands.mjs +44 -11
- package/lib/taskRooms.mjs +125 -0
- package/lib/taskRuns.mjs +36 -1
- package/lib/team.mjs +41 -18
- package/lib/threadActions.mjs +315 -0
- package/lib/threadAuthority.mjs +101 -0
- package/lib/threadBriefs.mjs +178 -0
- package/lib/threadLine.mjs +2 -2
- package/lib/threadRuns.mjs +138 -43
- package/lib/threadView.mjs +5 -5
- package/lib/usageTotals.mjs +2 -3
- package/lib/vault.mjs +101 -10
- package/lib/vaultCloud.mjs +2 -2
- package/lib/vaultCommands.mjs +15 -6
- package/lib/vaultTools.js +2 -2
- package/lib/verdicts.mjs +328 -0
- package/lib/wakes.mjs +1 -1
- package/lib/watches.mjs +2 -2
- package/lib/windowAsks.mjs +13 -5
- package/lib/worktrees.mjs +112 -18
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +11 -10
- package/release.json +220 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { offerable } from "./folders.mjs";
|
|
3
|
+
|
|
4
|
+
// What a thread may hold before it pauses: posts, and wakes of any one agent.
|
|
5
|
+
export const DEFAULT_MAX_POSTS = 500;
|
|
6
|
+
export const DEFAULT_MAX_WAKES = 50;
|
|
7
|
+
|
|
8
|
+
// The Harness conversation a task was handed on from, if any.
|
|
9
|
+
export const conversationOf = (task) =>
|
|
10
|
+
task.context_refs?.find((ref) => ref.kind === "conversation")?.ref ?? null;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A task's own room: every task for one of the person's agents opens a thread, and the task is its first job, so the
|
|
14
|
+
* agents on it can post, ask each other by name and be seen working together. The task keeps its own authority.
|
|
15
|
+
*
|
|
16
|
+
* Work Harness hands on from one of the person's Harness conversations goes into one thread while it is open: a build
|
|
17
|
+
* and its review, or two parts of one bug, are one piece of work, not two threads.
|
|
18
|
+
*
|
|
19
|
+
* `runsHere(agent)` says whether an agent is a coding agent this daemon runs (runAuthority.mjs).
|
|
20
|
+
*/
|
|
21
|
+
export function createTaskRooms({ store, worktrees, runsHere, notifyBoard }) {
|
|
22
|
+
const roomOfConversation = (conversation) => {
|
|
23
|
+
const room = store.getTask(
|
|
24
|
+
store.meta(`conversation-room:${conversation}`) || ""
|
|
25
|
+
);
|
|
26
|
+
const filed = store.meta(`thread-filed:${room?.id}`);
|
|
27
|
+
return room?.kind === "goal" &&
|
|
28
|
+
room.status === "open" &&
|
|
29
|
+
!filed?.includes('"done":true')
|
|
30
|
+
? room
|
|
31
|
+
: null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const postJob = (room, task, poster, machine) => {
|
|
35
|
+
store.setParent(task.id, room.id);
|
|
36
|
+
store.roomPost({
|
|
37
|
+
goalId: room.id,
|
|
38
|
+
author: poster,
|
|
39
|
+
kind: "job",
|
|
40
|
+
text: task.brief ? `${task.objective}\n\n${task.brief}` : task.objective,
|
|
41
|
+
mentions: [task.target_agent],
|
|
42
|
+
machine,
|
|
43
|
+
});
|
|
44
|
+
notifyBoard(store.getTask(room.id));
|
|
45
|
+
return room;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const join = (room, task, poster, machine) => {
|
|
49
|
+
const joining = [task.target_agent, poster].filter(
|
|
50
|
+
(agent) => agent !== "user" && !room.goal.team.includes(agent)
|
|
51
|
+
);
|
|
52
|
+
if (joining.length)
|
|
53
|
+
store.setGoalTeam(room.id, [...room.goal.team, ...joining]);
|
|
54
|
+
// A thread with no folder yet takes the folder of the first coding work handed into it, as a task's own thread
|
|
55
|
+
// does, so that work is a turn in the thread and runs where the agent lives, in T3 Code when that is its home
|
|
56
|
+
// (threadRuns.mjs). Work in another repository never joins a thread that has one (taskCommands.mjs).
|
|
57
|
+
const adopted =
|
|
58
|
+
!room.goal.workspace &&
|
|
59
|
+
runsHere(task.target_agent) &&
|
|
60
|
+
task.run_workspace &&
|
|
61
|
+
offerable(task.run_workspace)
|
|
62
|
+
? path.resolve(task.run_workspace)
|
|
63
|
+
: null;
|
|
64
|
+
if (adopted) {
|
|
65
|
+
store.setGoalFolder(room.id, adopted);
|
|
66
|
+
if (task.trust === "user" && !worktrees.get(room.id))
|
|
67
|
+
worktrees.inPlace(room.id);
|
|
68
|
+
store.roomPost({
|
|
69
|
+
goalId: room.id,
|
|
70
|
+
author: "harness",
|
|
71
|
+
kind: "note",
|
|
72
|
+
text: `Now working in ${adopted}.`,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return postJob(room, task, poster, machine);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The thread `task` is worked in, opened for it or joined. `into`: the thread the poster is working in, which the
|
|
80
|
+
* task joins (taskCommands.mjs). `folder`: where a coding agent that asked works, so its turn on the answer runs
|
|
81
|
+
* there (answers.mjs) when the task names no folder. `machine`: the computer the poster wrote from. `hosted`: posted
|
|
82
|
+
* through Harness.
|
|
83
|
+
*/
|
|
84
|
+
const open = (
|
|
85
|
+
task,
|
|
86
|
+
poster,
|
|
87
|
+
provenance,
|
|
88
|
+
{ hosted = false, into = null, folder = null, machine = null } = {}
|
|
89
|
+
) => {
|
|
90
|
+
const conversation = conversationOf(task);
|
|
91
|
+
const joined = into
|
|
92
|
+
? store.getTask(into)
|
|
93
|
+
: conversation
|
|
94
|
+
? roomOfConversation(conversation)
|
|
95
|
+
: null;
|
|
96
|
+
if (joined) return join(joined, task, poster, machine);
|
|
97
|
+
// The asker is in the room it opened, roster member or not, so it can follow the work it asked for.
|
|
98
|
+
const team = [
|
|
99
|
+
...new Set([
|
|
100
|
+
task.target_agent,
|
|
101
|
+
...(poster !== "user" ? [poster] : []),
|
|
102
|
+
"harness",
|
|
103
|
+
]),
|
|
104
|
+
];
|
|
105
|
+
const room = store.createGoal({
|
|
106
|
+
objective: task.objective,
|
|
107
|
+
brief: task.brief,
|
|
108
|
+
originAgent: poster,
|
|
109
|
+
provenance,
|
|
110
|
+
team,
|
|
111
|
+
facilitator: "harness",
|
|
112
|
+
workspace: task.run_workspace || folder,
|
|
113
|
+
maxPosts: DEFAULT_MAX_POSTS,
|
|
114
|
+
maxWakes: DEFAULT_MAX_WAKES,
|
|
115
|
+
});
|
|
116
|
+
// Its agents work where the task does, as the task would have alone; work another agent asked for gets a copy.
|
|
117
|
+
if (provenance?.trust === "user") worktrees.inPlace(room.id);
|
|
118
|
+
store.meta(`task-room:${room.id}`, task.id);
|
|
119
|
+
if (conversation) store.meta(`conversation-room:${conversation}`, room.id);
|
|
120
|
+
if (hosted) store.meta(`hosted-thread:${room.id}`, "1");
|
|
121
|
+
return postJob(room, task, poster, machine);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return { open };
|
|
125
|
+
}
|
package/lib/taskRuns.mjs
CHANGED
|
@@ -43,6 +43,12 @@ export function createTaskRuns({
|
|
|
43
43
|
t3Missed,
|
|
44
44
|
nativeRequests = null,
|
|
45
45
|
onOutput = () => {},
|
|
46
|
+
// Why an agent's run may not start on this computer's inference as it stands, or null (cloudAi.mjs refusal, the
|
|
47
|
+
// inference boundary): every run starts here, from this computer's board or from home's.
|
|
48
|
+
inferenceRefusal = () => null,
|
|
49
|
+
// What a run ends saying when any of its agent's calls ran on Harness's AI in place of the person's own link or key
|
|
50
|
+
// since it started (cloudAi.mjs noteFor), or null.
|
|
51
|
+
inferenceNote = () => null,
|
|
46
52
|
}) {
|
|
47
53
|
const taskRuns = new Map();
|
|
48
54
|
const validRunId = (runId) =>
|
|
@@ -173,8 +179,16 @@ export function createTaskRuns({
|
|
|
173
179
|
);
|
|
174
180
|
} catch {}
|
|
175
181
|
};
|
|
182
|
+
const runStart = Date.now();
|
|
176
183
|
const emit = (kind, rawText, extra) => {
|
|
177
|
-
|
|
184
|
+
// A run any of whose calls went to Harness's AI in place of the person's own link or key ends saying so, once.
|
|
185
|
+
const note =
|
|
186
|
+
kind === "done" || kind === "failed"
|
|
187
|
+
? inferenceNote(message.agent, runStart)
|
|
188
|
+
: null;
|
|
189
|
+
const text = scrub.text(
|
|
190
|
+
note ? [rawText, note].filter(Boolean).join("\n\n") : rawText
|
|
191
|
+
);
|
|
178
192
|
if (kind === "done" || kind === "failed")
|
|
179
193
|
for (const [stream, rest] of scrub.flush()) appendLog(stream, rest);
|
|
180
194
|
if (kind === "accepted") task.status = "running";
|
|
@@ -200,6 +214,13 @@ export function createTaskRuns({
|
|
|
200
214
|
appendLog(stream, text);
|
|
201
215
|
onOutput(message.runId);
|
|
202
216
|
};
|
|
217
|
+
// Checked before T3 Code takes a turn as well: it runs the same agent, on the same settings, on this computer.
|
|
218
|
+
const refused = inferenceRefusal(message.agent);
|
|
219
|
+
if (refused) {
|
|
220
|
+
appendLog("stderr", `${refused}\n`);
|
|
221
|
+
emit("failed", refused, { failure: "start" });
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
203
224
|
const hooks = nativeRequests
|
|
204
225
|
? {
|
|
205
226
|
requestApproval: (approval, signal) =>
|
|
@@ -250,6 +271,19 @@ export function createTaskRuns({
|
|
|
250
271
|
});
|
|
251
272
|
persistTask(record);
|
|
252
273
|
};
|
|
274
|
+
// The runs going on this computer now, newest first: what someone at its terminal (SSH into a cloud computer) sees.
|
|
275
|
+
const running = () =>
|
|
276
|
+
[...taskRuns.values()]
|
|
277
|
+
.filter((task) => task.status === "starting" || task.status === "running")
|
|
278
|
+
.sort((a, b) => b.startedAt.localeCompare(a.startedAt))
|
|
279
|
+
.map(({ runId, agent, title, cwd, startedAt, updatedAt }) => ({
|
|
280
|
+
runId,
|
|
281
|
+
agent,
|
|
282
|
+
title,
|
|
283
|
+
cwd,
|
|
284
|
+
startedAt,
|
|
285
|
+
updatedAt,
|
|
286
|
+
}));
|
|
253
287
|
return {
|
|
254
288
|
validRunId,
|
|
255
289
|
taskFiles,
|
|
@@ -258,5 +292,6 @@ export function createTaskRuns({
|
|
|
258
292
|
lastStepAt,
|
|
259
293
|
startTask,
|
|
260
294
|
requeue,
|
|
295
|
+
running,
|
|
261
296
|
};
|
|
262
297
|
}
|
package/lib/team.mjs
CHANGED
|
@@ -3,20 +3,19 @@ import { nameOf } from "./members.mjs";
|
|
|
3
3
|
import { specialtyName } from "./specialties.mjs";
|
|
4
4
|
import { namedFiles } from "./worktrees.mjs";
|
|
5
5
|
|
|
6
|
-
// How the agents in a thread work as a team (team.json,
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// to one agent).
|
|
6
|
+
// How the agents in a thread work as a team (team.json, which Harness's server reads too): one route, frame, make,
|
|
7
|
+
// check, combine, judge, whose steps the rigor picks, each step held by the agents Jev routed it to for the specialty
|
|
8
|
+
// it asks for. Without it, every round handed the next piece to whichever single agent looked likeliest, and the
|
|
9
|
+
// busiest agent did most of the work while nobody checked it or pulled parallel results together (on one real board, 30
|
|
10
|
+
// of 52 hand-ons to one agent, and 42 of 50 assemblies gave the whole message to one agent).
|
|
12
11
|
//
|
|
13
|
-
// Jev triages the goal in the thread's first assembly round (
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
12
|
+
// Jev triages the goal in the thread's first assembly round (Harness's coordinator): its rigor, whether a framer splits
|
|
13
|
+
// it into pieces, the specialty each step asks for and who holds each. A goal that is split runs its frame first; the
|
|
14
|
+
// framer's report gives the pieces, and each is routed by Jev as it starts. The route is followed here: the round is
|
|
15
|
+
// told which step the thread is at, whether that step's agents have reported since it began, and where the work may go
|
|
16
|
+
// next (`exits`); Jev judges only what needs judgment (did a check pass), and the daemon moves the thread to the step
|
|
17
|
+
// the round chose. Every run is marked with the step it worked and the specialty that step asked for, and a check's
|
|
18
|
+
// outcome is written on the runs it judged, for the record (record.mjs).
|
|
20
19
|
|
|
21
20
|
export const TEAM = JSON.parse(
|
|
22
21
|
readFileSync(new URL("./team.json", import.meta.url), "utf8")
|
|
@@ -49,9 +48,6 @@ export const stepsFor = (rigor, { makers, framed }) =>
|
|
|
49
48
|
!(framed && id === "frame")
|
|
50
49
|
);
|
|
51
50
|
|
|
52
|
-
const holdersOf = (steps, id) =>
|
|
53
|
-
steps.find((step) => step.id === id)?.agents ?? [];
|
|
54
|
-
|
|
55
51
|
// A specialty on the list, else none (the route still runs; the run counts toward no specialty).
|
|
56
52
|
const KNOWN = new Set(
|
|
57
53
|
JSON.parse(
|
|
@@ -427,6 +423,32 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
427
423
|
return moved;
|
|
428
424
|
};
|
|
429
425
|
|
|
426
|
+
/** The person's verdict returns that run's piece to Make, even after the route moved on. */
|
|
427
|
+
const sendBack = (goalId, runId) => {
|
|
428
|
+
const current = read(goalId);
|
|
429
|
+
const run = store.getTask(runId);
|
|
430
|
+
if (!current || !run) return;
|
|
431
|
+
const held = current.history?.findLast(
|
|
432
|
+
(entry) =>
|
|
433
|
+
entry.step === "make" &&
|
|
434
|
+
entry.agents.includes(run.target_agent) &&
|
|
435
|
+
entry.at <= run.reported_at
|
|
436
|
+
);
|
|
437
|
+
const piece = held?.piece ?? current.piece;
|
|
438
|
+
if (!current.pieces[piece]?.steps.some((step) => step.id === "make"))
|
|
439
|
+
return;
|
|
440
|
+
const moved = {
|
|
441
|
+
...current,
|
|
442
|
+
piece,
|
|
443
|
+
step: "make",
|
|
444
|
+
stepAt: now(),
|
|
445
|
+
lastCheck: null,
|
|
446
|
+
sendsBack: current.sendsBack + 1,
|
|
447
|
+
};
|
|
448
|
+
moved.history = started(moved, "make");
|
|
449
|
+
write(goalId, moved);
|
|
450
|
+
};
|
|
451
|
+
|
|
430
452
|
/** Whether the thread's route checks its work: one of its pieces has a step that judges. */
|
|
431
453
|
const checksWork = (current) =>
|
|
432
454
|
current.pieces.some((piece) =>
|
|
@@ -484,8 +506,8 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
484
506
|
};
|
|
485
507
|
|
|
486
508
|
/**
|
|
487
|
-
* The route as the work actually went: agents hand each other work by name as well as through the route (
|
|
488
|
-
* live run
|
|
509
|
+
* The route as the work actually went: agents hand each other work by name as well as through the route (in a
|
|
510
|
+
* live run the builder asked the checker itself, and the route still waited at the build). A step that is done and
|
|
489
511
|
* whose next step's agents have reported since moves on, up to a step that judges, whose outcome is the round's.
|
|
490
512
|
*/
|
|
491
513
|
const catchUp = (goalId, current, runs) => {
|
|
@@ -793,6 +815,7 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
793
815
|
|
|
794
816
|
return {
|
|
795
817
|
plan,
|
|
818
|
+
sendBack,
|
|
796
819
|
set,
|
|
797
820
|
routePiece,
|
|
798
821
|
moveTo,
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { picksIn } from "./models.mjs";
|
|
2
|
+
import { MEMBERS, nameOf } from "./members.mjs";
|
|
3
|
+
import { notifyDesktop } from "./notify.mjs";
|
|
4
|
+
|
|
5
|
+
// A name after @ is an id or a one-word alias ("@grok" is Grok Bot); "@claude" is Claude Code.
|
|
6
|
+
const ONE_WORD_ALIASES = new Map(
|
|
7
|
+
MEMBERS.flatMap((entry) =>
|
|
8
|
+
entry.aliases
|
|
9
|
+
.filter((alias) => !/\s/.test(alias))
|
|
10
|
+
.map((alias) => [alias.toLowerCase(), entry.id])
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
/** The members of `team` that `text` names with @. */
|
|
15
|
+
export const mentionsIn = (text, team) =>
|
|
16
|
+
[
|
|
17
|
+
...new Set(
|
|
18
|
+
[...String(text).matchAll(/@([a-z][a-z0-9-]*)/g)].map((match) =>
|
|
19
|
+
match[1] === "claude"
|
|
20
|
+
? "claude-code"
|
|
21
|
+
: (ONE_WORD_ALIASES.get(match[1]) ?? match[1])
|
|
22
|
+
)
|
|
23
|
+
),
|
|
24
|
+
].filter((name) => team.includes(name));
|
|
25
|
+
|
|
26
|
+
/** Who may act in a thread: the person, its facilitator and its team. */
|
|
27
|
+
export const inRoom = (goal, agent) =>
|
|
28
|
+
agent === "user" ||
|
|
29
|
+
agent === goal.goal.facilitator ||
|
|
30
|
+
goal.goal.team.includes(agent);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* What happens in a thread when someone names an agent, asks one, or work stops moving: the agents named are woken
|
|
34
|
+
* (coding agents here get a run, the others get the ask as a task in the thread), the coordinator says what it must,
|
|
35
|
+
* and work a woken agent never picked up goes to another.
|
|
36
|
+
*
|
|
37
|
+
* The getters (`threadRuns()`, `asks()`, `boardCommand()`, `ownMachines()`, `threadView()`) are modules made after
|
|
38
|
+
* this one. `authority` is the thread authority (threadAuthority.mjs), `briefs` what agents are told
|
|
39
|
+
* (threadBriefs.mjs), `harness` how Harness's server takes thread tasks (harnessOffers.mjs).
|
|
40
|
+
*/
|
|
41
|
+
export function createThreadActions({
|
|
42
|
+
store,
|
|
43
|
+
lineup,
|
|
44
|
+
installedAgents,
|
|
45
|
+
runsHere,
|
|
46
|
+
askable,
|
|
47
|
+
onServer,
|
|
48
|
+
homedOnServer,
|
|
49
|
+
authority,
|
|
50
|
+
briefs,
|
|
51
|
+
harness,
|
|
52
|
+
localWaker,
|
|
53
|
+
notices,
|
|
54
|
+
notifyBoard,
|
|
55
|
+
send,
|
|
56
|
+
serverHas,
|
|
57
|
+
threadRuns,
|
|
58
|
+
asks,
|
|
59
|
+
boardCommand,
|
|
60
|
+
ownMachines,
|
|
61
|
+
threadView,
|
|
62
|
+
}) {
|
|
63
|
+
/** Pauses a thread, saying why in it and on the desktop. */
|
|
64
|
+
const pause = (goalId, reason) => {
|
|
65
|
+
const task = store.setGoalState(goalId, {
|
|
66
|
+
status: "paused",
|
|
67
|
+
pausedReason: reason,
|
|
68
|
+
});
|
|
69
|
+
store.roomPost({
|
|
70
|
+
goalId,
|
|
71
|
+
author: "harness",
|
|
72
|
+
kind: "note",
|
|
73
|
+
text: `Paused: ${reason}. Resume it from the thread when you want it to go on.`,
|
|
74
|
+
});
|
|
75
|
+
notifyDesktop(`${threadView().row(task).title} is paused: ${reason}`);
|
|
76
|
+
notifyBoard(task);
|
|
77
|
+
return task;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Posts one ask as a task in the thread, in its asker's name, so its authority is the asker's (an agent's ask to
|
|
82
|
+
* Bankr waits for the person). `id`: an agent on Harness's server gets the ask's own id, so a send that may have
|
|
83
|
+
* reached Harness is found there rather than posted twice (asks.mjs).
|
|
84
|
+
*/
|
|
85
|
+
const postAsk = (task, { agent, reason, asker, words, id, resend }) => {
|
|
86
|
+
const from = inRoom(task, asker) ? asker : task.goal.facilitator;
|
|
87
|
+
// Only the person's own ask carries the person's authority; an agent's or Harness's is labelled agent-written, so
|
|
88
|
+
// Bankr holds a send to an address that agent supplied for the person, inside the person's limits.
|
|
89
|
+
const written =
|
|
90
|
+
from === "user"
|
|
91
|
+
? {}
|
|
92
|
+
: {
|
|
93
|
+
provenance: {
|
|
94
|
+
trust: "agent",
|
|
95
|
+
chain: [...(task.origin_chain || []), from].slice(-16),
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
const posted = boardCommand()({
|
|
99
|
+
command: "board.post",
|
|
100
|
+
agent: from,
|
|
101
|
+
...(homedOnServer(agent) ? { id, resend } : {}),
|
|
102
|
+
objective: `Asked in "${task.objective}": ${reason}`.slice(0, 500),
|
|
103
|
+
brief:
|
|
104
|
+
agent === "harness"
|
|
105
|
+
? briefs.harnessAsk(task, words)
|
|
106
|
+
: onServer(agent)
|
|
107
|
+
? briefs.specialistHistory(task, words)
|
|
108
|
+
: briefs.swarmBrief(task, agent, reason, { ask: true }),
|
|
109
|
+
targetAgent: agent,
|
|
110
|
+
parentId: task.id,
|
|
111
|
+
...(onServer(agent)
|
|
112
|
+
? { contextRefs: [{ kind: "ask", ref: String(words) }] }
|
|
113
|
+
: {}),
|
|
114
|
+
...written,
|
|
115
|
+
});
|
|
116
|
+
if (agent === "harness" && posted?.ok && posted.task)
|
|
117
|
+
harness.offerAsk(task, posted.task.id, from, words);
|
|
118
|
+
return posted;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Ask an agent that is not started here (asks.mjs). Returns what the asker is told when it does not go at once. */
|
|
122
|
+
const ask = (goalId, agent, reason, asker, words = reason) =>
|
|
123
|
+
asks().ask(goalId, agent, { reason, asker, words: String(words) });
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The agents a post names, woken. `why`: what they are told in place of "mentioned you" (the coordinator's word to
|
|
127
|
+
* everyone in a thread). `guard`: the injection guard's reading of the words, where the caller had it read
|
|
128
|
+
* (firewall.mjs inspect). `answering`: the agent whose turn is on its own task's answer. `go`: a shared project's go
|
|
129
|
+
* for a wake the other side asked for (projects.mjs), in place of the person's own. Returns what each ask that did
|
|
130
|
+
* not go at once is waiting for, or why it could not go, for the post's author.
|
|
131
|
+
*/
|
|
132
|
+
const wakeFor = (
|
|
133
|
+
goalId,
|
|
134
|
+
post,
|
|
135
|
+
author,
|
|
136
|
+
names = post.mentions,
|
|
137
|
+
{
|
|
138
|
+
hosted = false,
|
|
139
|
+
window = false,
|
|
140
|
+
why = null,
|
|
141
|
+
guard,
|
|
142
|
+
answering = null,
|
|
143
|
+
go: projectGo = null,
|
|
144
|
+
// The asker's run was restricted or a review ("restricted" or "review"): what it asks for runs no further.
|
|
145
|
+
limited = null,
|
|
146
|
+
} = {}
|
|
147
|
+
) => {
|
|
148
|
+
const goal = store.goal(goalId);
|
|
149
|
+
const { picks } = picksIn(store, post.text, names);
|
|
150
|
+
const told = [];
|
|
151
|
+
for (const agent of names) {
|
|
152
|
+
if (agent === author) continue;
|
|
153
|
+
const reason = why
|
|
154
|
+
? `${why}: ${post.text.slice(0, 300)}`
|
|
155
|
+
: `${author} mentioned you: ${post.text.slice(0, 300)}`;
|
|
156
|
+
const refuse = (because) =>
|
|
157
|
+
told.push(
|
|
158
|
+
asks().refuse(goalId, agent, { reason, asker: author }, because)
|
|
159
|
+
);
|
|
160
|
+
// An agent the person took out of their swarm (lineup.mjs) is not woken, whatever names it.
|
|
161
|
+
if (agent !== "harness" && !lineup.has(agent))
|
|
162
|
+
refuse(
|
|
163
|
+
`it is not in your swarm. Add it with: npx tryharness agents add ${agent}`
|
|
164
|
+
);
|
|
165
|
+
else if (
|
|
166
|
+
runsHere(agent) &&
|
|
167
|
+
!installedAgents.includes(agent) &&
|
|
168
|
+
!ownMachines()?.placeElsewhere(agent, goal?.workspace ?? null)
|
|
169
|
+
)
|
|
170
|
+
refuse(
|
|
171
|
+
// Another computer is named only when the person has one: on one computer it would only confuse.
|
|
172
|
+
ownMachines()?.siblings()?.length
|
|
173
|
+
? "it is not installed on this computer, nor on another of your computers with this thread's repository"
|
|
174
|
+
: "it is not installed on this computer"
|
|
175
|
+
);
|
|
176
|
+
else if (runsHere(agent))
|
|
177
|
+
threadRuns().wake(goalId, agent, reason, {
|
|
178
|
+
go:
|
|
179
|
+
projectGo ??
|
|
180
|
+
authority.personsGo(author, agent, {
|
|
181
|
+
hosted,
|
|
182
|
+
guard,
|
|
183
|
+
limited,
|
|
184
|
+
window,
|
|
185
|
+
}),
|
|
186
|
+
review: limited === "review",
|
|
187
|
+
asker: author,
|
|
188
|
+
pick: picks.get(agent),
|
|
189
|
+
words: post.text,
|
|
190
|
+
held:
|
|
191
|
+
guard === undefined
|
|
192
|
+
? null
|
|
193
|
+
: authority.guardWait(author, agent, guard),
|
|
194
|
+
answer: agent === answering,
|
|
195
|
+
});
|
|
196
|
+
else if (askable(agent))
|
|
197
|
+
told.push(ask(goalId, agent, reason, author, post.text));
|
|
198
|
+
// Harness by name: the person's @harness or an agent's ask. A message naming no one falls to Harness as
|
|
199
|
+
// coordinator.
|
|
200
|
+
else if (
|
|
201
|
+
agent === "harness" &&
|
|
202
|
+
post.kind === "post" &&
|
|
203
|
+
(author !== "user" || mentionsIn(post.text, [agent]).length)
|
|
204
|
+
)
|
|
205
|
+
told.push(ask(goalId, agent, reason, author, post.text));
|
|
206
|
+
}
|
|
207
|
+
// Harness follows through the board change; it is woken by mentions, results and questions, not by every note.
|
|
208
|
+
if (goal && names.includes(goal.facilitator))
|
|
209
|
+
notifyBoard(store.getTask(goalId));
|
|
210
|
+
return told.filter(Boolean);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/** Said in the thread by its coordinator; an agent named in `wake` is woken with it. */
|
|
214
|
+
const say = (thread, text, { wake = null } = {}) => {
|
|
215
|
+
const post = store.roomPost({
|
|
216
|
+
goalId: thread.id,
|
|
217
|
+
author: thread.goal.facilitator,
|
|
218
|
+
kind: "note",
|
|
219
|
+
text,
|
|
220
|
+
mentions: wake ? [wake] : [],
|
|
221
|
+
});
|
|
222
|
+
if (wake && thread.status === "open")
|
|
223
|
+
wakeFor(thread.id, post, thread.goal.facilitator, [wake], {
|
|
224
|
+
why: "Your ask could not be sent",
|
|
225
|
+
});
|
|
226
|
+
notifyBoard(store.getTask(thread.id));
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// A wake from here that found no gateway goes through Harness's server, for an agent woken from there.
|
|
230
|
+
const wakeFromServer = (agent, taskId) => {
|
|
231
|
+
if (serverHas("wake_again"))
|
|
232
|
+
send({ type: "wake_again", agent, task: taskId });
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* A handoff not picked up is woken again past any wake still out: here for an agent on this computer's gateway, on
|
|
237
|
+
* Harness's server for one woken from there.
|
|
238
|
+
*/
|
|
239
|
+
const wakeAgain = (agent, taskId) =>
|
|
240
|
+
void localWaker.wake(agent, taskId, { force: true }).then((outcome) => {
|
|
241
|
+
if (outcome === "none") wakeFromServer(agent, taskId);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Work a woken agent never picked up goes to another in its asker's name. The late agent's task is taken back first,
|
|
246
|
+
* so a wake that lands later cannot start the same work twice.
|
|
247
|
+
*/
|
|
248
|
+
const moveHandoff = (task, to) => {
|
|
249
|
+
const thread = store.getTask(task.parent_id);
|
|
250
|
+
if (thread?.kind !== "goal" || thread.status !== "open") return false;
|
|
251
|
+
store.removeTask(task.id);
|
|
252
|
+
notifyBoard(store.getTask(task.id));
|
|
253
|
+
const prefix = `Asked in "${thread.objective}": `;
|
|
254
|
+
const words = task.objective.startsWith(prefix)
|
|
255
|
+
? task.objective.slice(prefix.length)
|
|
256
|
+
: task.objective;
|
|
257
|
+
const asker =
|
|
258
|
+
task.origin_agent === to ? thread.goal.facilitator : task.origin_agent;
|
|
259
|
+
ask(
|
|
260
|
+
thread.id,
|
|
261
|
+
to,
|
|
262
|
+
`${nameOf(task.target_agent)} didn't pick this up, so it is yours: ${words}`,
|
|
263
|
+
asker,
|
|
264
|
+
words
|
|
265
|
+
);
|
|
266
|
+
return true;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Work that stopped moving (stuck.mjs) is said once where it belongs: in its thread by the lead, whose coordinator
|
|
271
|
+
* looks again; loose work is also told to whoever posted it (the person on the desktop, an agent in the work's room
|
|
272
|
+
* or on the task, and by a wake where it can be woken). A claim past its lease still tells the person on the desktop.
|
|
273
|
+
*/
|
|
274
|
+
const tellStuck = (finding) => {
|
|
275
|
+
const { task } = finding;
|
|
276
|
+
if (finding.kind === "lease")
|
|
277
|
+
notices.notify(
|
|
278
|
+
`${nameOf(finding.agent)} stopped checking in on: ${String(task.objective).slice(0, 80)}. Release it from the buddy or your phone.`
|
|
279
|
+
);
|
|
280
|
+
const thread = finding.thread ? store.getTask(finding.thread) : null;
|
|
281
|
+
if (thread) say(thread, finding.text);
|
|
282
|
+
// Work posted on its own lives in a room of its own (task-room): it is still loose work, told to its poster too.
|
|
283
|
+
const loose = !thread || store.meta(`task-room:${thread.id}`) === task.id;
|
|
284
|
+
if (!loose) return;
|
|
285
|
+
const poster = task.origin_agent;
|
|
286
|
+
if (poster === "user") {
|
|
287
|
+
if (finding.kind !== "lease") notices.notify(finding.text);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (!thread)
|
|
291
|
+
store.addContribution({
|
|
292
|
+
taskId: task.id,
|
|
293
|
+
kind: "note",
|
|
294
|
+
author: "harness",
|
|
295
|
+
text: finding.text,
|
|
296
|
+
source: "stuck",
|
|
297
|
+
});
|
|
298
|
+
void localWaker.wake(poster, task.id, { holds: false }).then((outcome) => {
|
|
299
|
+
if (outcome === "none" && homedOnServer(poster))
|
|
300
|
+
wakeFromServer(poster, task.id);
|
|
301
|
+
});
|
|
302
|
+
notifyBoard(store.getTask(task.id));
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
pause,
|
|
307
|
+
postAsk,
|
|
308
|
+
ask,
|
|
309
|
+
wakeFor,
|
|
310
|
+
say,
|
|
311
|
+
wakeAgain,
|
|
312
|
+
moveHandoff,
|
|
313
|
+
tellStuck,
|
|
314
|
+
};
|
|
315
|
+
}
|