tryharness 0.7.41 → 0.7.43
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/cli.mjs +118 -5
- package/lib/actorRoster.mjs +16 -2
- package/lib/adapters.mjs +2 -1
- package/lib/answers.mjs +30 -0
- package/lib/boardCommands.mjs +9 -1
- package/lib/boardFiles.mjs +1 -1
- package/lib/boardProtocol.json +1 -0
- package/lib/bridge.mjs +49 -9
- package/lib/cards.mjs +22 -4
- package/lib/compaction.mjs +90 -0
- package/lib/context.mjs +19 -11
- package/lib/coordinator.mjs +176 -12
- package/lib/daemon.mjs +424 -44
- package/lib/fit.mjs +65 -0
- package/lib/folders.mjs +20 -0
- package/lib/frames.mjs +3 -2
- package/lib/goalCommands.mjs +12 -0
- package/lib/handover.mjs +128 -0
- package/lib/loopBackstop.mjs +104 -0
- package/lib/machineIdentity.mjs +43 -0
- package/lib/machineRoutes.mjs +97 -0
- package/lib/machineRuns.mjs +133 -0
- package/lib/machineSeal.mjs +157 -0
- package/lib/mcp-stdio.mjs +54 -11
- package/lib/nudge.mjs +211 -44
- package/lib/oneLine.mjs +27 -0
- package/lib/ownMachines.mjs +748 -0
- package/lib/paths.mjs +1 -0
- package/lib/plans.mjs +3 -2
- package/lib/provenance.mjs +4 -1
- package/lib/runBrief.mjs +346 -0
- package/lib/runWorker.mjs +24 -173
- package/lib/runner.mjs +26 -2
- package/lib/store.mjs +232 -16
- package/lib/stuck.mjs +198 -0
- package/lib/swarm.mjs +3 -1
- package/lib/taskCommands.mjs +268 -31
- package/lib/taskRuns.mjs +9 -0
- package/lib/team.json +192 -0
- package/lib/team.mjs +417 -0
- package/lib/threadRuns.mjs +18 -7
- package/lib/threadView.mjs +13 -0
- package/lib/trails.mjs +49 -0
- package/lib/wakes.mjs +201 -69
- package/lib/worktrees.mjs +9 -0
- package/package.json +1 -1
package/lib/team.mjs
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { nameOf } from "./members.mjs";
|
|
3
|
+
|
|
4
|
+
// How the agents in a thread work as a team (team.json, read by the server too through src/shared/team.ts): the team's
|
|
5
|
+
// shape, who holds each role, how careful the work must be, and the route the work takes between the roles. Without one,
|
|
6
|
+
// every round handed the next piece to whichever single agent looked likeliest, and the busiest agent did most of the
|
|
7
|
+
// work while nobody checked it or pulled parallel results together (board, October 20: 30 of 52 hand-ons to one agent,
|
|
8
|
+
// 24 of 34 to the same agent as the round before, and 42 of 50 assemblies gave the whole message to one agent).
|
|
9
|
+
//
|
|
10
|
+
// The plan is set in the thread's first assembly round (src/server/swarm/coordinator.ts teamPlan) and kept here. The
|
|
11
|
+
// route is followed here: the round is told which step the thread is at, whether that step's agents have reported since
|
|
12
|
+
// it began, and where the work may go next (`exits`); Jev judges only what needs judgment (did a check pass), and the
|
|
13
|
+
// daemon moves the thread to the step the round chose.
|
|
14
|
+
|
|
15
|
+
export const TEAM = JSON.parse(
|
|
16
|
+
readFileSync(new URL("./team.json", import.meta.url), "utf8")
|
|
17
|
+
);
|
|
18
|
+
const SHAPES = TEAM.shapes;
|
|
19
|
+
export const SHAPE_IDS = Object.keys(SHAPES);
|
|
20
|
+
export const ROLE_IDS = Object.keys(TEAM.roles);
|
|
21
|
+
export const RIGOR_LEVELS = Object.keys(TEAM.rigor);
|
|
22
|
+
// Every runner's reported states that end a turn: a question to the person (needs_input) is not the step's end.
|
|
23
|
+
const FINISHED = new Set(["done", "failed", "unknown"]);
|
|
24
|
+
|
|
25
|
+
/** Whether a model takes a goal and finds its own route (the brief gives it intent), from its name. */
|
|
26
|
+
export const goalLevel = (model) =>
|
|
27
|
+
Boolean(model) &&
|
|
28
|
+
TEAM.goalLevelModels.some((family) =>
|
|
29
|
+
String(model).toLowerCase().includes(family)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const stepsOf = (plan) =>
|
|
33
|
+
(SHAPES[plan.shape]?.steps ?? []).filter(
|
|
34
|
+
(step) => (plan.roles[step.role] ?? []).length > 0
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
/** A plan as the round proposed it, kept only where it names a known shape, known roles and agents that may hold them. */
|
|
38
|
+
export function validPlan(proposed, { members }) {
|
|
39
|
+
const shape = SHAPES[proposed?.shape];
|
|
40
|
+
if (!shape) return null;
|
|
41
|
+
const allowed = new Set(members);
|
|
42
|
+
const roles = {};
|
|
43
|
+
for (const role of shape.roles) {
|
|
44
|
+
const holders = [
|
|
45
|
+
...new Set((proposed.roles?.[role] ?? []).map(String)),
|
|
46
|
+
].filter((agent) => allowed.has(agent));
|
|
47
|
+
if (holders.length)
|
|
48
|
+
roles[role] = TEAM.several.includes(role) ? holders : holders.slice(0, 1);
|
|
49
|
+
}
|
|
50
|
+
// The author never checks or reviews its own work.
|
|
51
|
+
const builder = roles.builder?.[0];
|
|
52
|
+
for (const role of ["checker", "reviewer"])
|
|
53
|
+
if (builder && roles[role]?.[0] === builder) delete roles[role];
|
|
54
|
+
const plan = {
|
|
55
|
+
shape: proposed.shape,
|
|
56
|
+
rigor: RIGOR_LEVELS.includes(proposed.rigor) ? proposed.rigor : "standard",
|
|
57
|
+
roles,
|
|
58
|
+
};
|
|
59
|
+
return stepsOf(plan).length ? plan : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// How old a note is, in the words a brief uses.
|
|
63
|
+
const age = (iso) => {
|
|
64
|
+
const days = Math.floor((Date.now() - Date.parse(iso)) / 86_400_000);
|
|
65
|
+
return days < 1 ? "today" : days === 1 ? "yesterday" : `${days} days ago`;
|
|
66
|
+
};
|
|
67
|
+
const NOTE_CHARS = 600;
|
|
68
|
+
|
|
69
|
+
export function createTeam({ store, log = () => {} }) {
|
|
70
|
+
const key = (goalId) => `team:${goalId}`;
|
|
71
|
+
const read = (goalId) => {
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(store.meta(key(goalId)) || "null");
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const write = (goalId, plan) => store.meta(key(goalId), JSON.stringify(plan));
|
|
79
|
+
const now = () => new Date().toISOString();
|
|
80
|
+
|
|
81
|
+
/** The thread's plan, or null when it has none (a thread from before teams, or one not yet assembled). */
|
|
82
|
+
const plan = (goalId) => read(goalId);
|
|
83
|
+
|
|
84
|
+
/** The roles an agent holds in the thread. */
|
|
85
|
+
const rolesOf = (goalId, agent) => {
|
|
86
|
+
const current = read(goalId);
|
|
87
|
+
return current
|
|
88
|
+
? Object.entries(current.roles)
|
|
89
|
+
.filter(([, holders]) => holders.includes(agent))
|
|
90
|
+
.map(([role]) => role)
|
|
91
|
+
: [];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** One line naming who holds what, as the thread and the briefs say it. */
|
|
95
|
+
const lineup = (current) =>
|
|
96
|
+
stepsOf(current)
|
|
97
|
+
.map((step) => step.role)
|
|
98
|
+
.filter((role, index, all) => all.indexOf(role) === index)
|
|
99
|
+
.map(
|
|
100
|
+
(role) =>
|
|
101
|
+
`${current.roles[role].map(nameOf).join(" and ")}: ${TEAM.roles[role].name}`
|
|
102
|
+
)
|
|
103
|
+
.join("; ");
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Keep the plan the round proposed, starting at its first step. Says in the thread who holds what. Returns the plan
|
|
107
|
+
* kept, or null when the proposal named nothing usable.
|
|
108
|
+
*/
|
|
109
|
+
const set = (goalId, proposed, { members, by, post }) => {
|
|
110
|
+
const valid = validPlan(proposed, { members });
|
|
111
|
+
if (!valid) {
|
|
112
|
+
log(`team plan for ${goalId} not kept: ${JSON.stringify(proposed)}`);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const kept = {
|
|
116
|
+
...valid,
|
|
117
|
+
step: stepsOf(valid)[0].id,
|
|
118
|
+
stepAt: now(),
|
|
119
|
+
sendsBack: 0,
|
|
120
|
+
by,
|
|
121
|
+
at: now(),
|
|
122
|
+
};
|
|
123
|
+
write(goalId, kept);
|
|
124
|
+
post?.(
|
|
125
|
+
`The team for this thread (${SHAPES[kept.shape].name}, ${kept.rigor}): ${lineup(kept)}.`
|
|
126
|
+
);
|
|
127
|
+
return kept;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Move the thread to a step of its route (an id, "done"). A judged step's outcome is kept with the commit its
|
|
132
|
+
* check saw (`head`), so a later change makes it stale; a send-back is counted.
|
|
133
|
+
*/
|
|
134
|
+
const moveTo = (goalId, step, { outcome = null, head = null } = {}) => {
|
|
135
|
+
const current = read(goalId);
|
|
136
|
+
if (!current) return null;
|
|
137
|
+
const known =
|
|
138
|
+
step === "done" || stepsOf(current).some((s) => s.id === step);
|
|
139
|
+
if (!known) return current;
|
|
140
|
+
const judged = stepsOf(current).find((s) => s.id === current.step)?.judges;
|
|
141
|
+
const moved = {
|
|
142
|
+
...current,
|
|
143
|
+
step,
|
|
144
|
+
stepAt: now(),
|
|
145
|
+
sendsBack: current.sendsBack + (outcome === "sent_back" ? 1 : 0),
|
|
146
|
+
...(judged && (outcome === "passed" || outcome === "sent_back")
|
|
147
|
+
? { lastCheck: { step: current.step, outcome, head, at: now() } }
|
|
148
|
+
: {}),
|
|
149
|
+
};
|
|
150
|
+
write(goalId, moved);
|
|
151
|
+
return moved;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/** Whether the thread's team checks its work: its route has a step that judges. */
|
|
155
|
+
const checksWork = (current) => stepsOf(current).some((s) => s.judges);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Whether the team's last check passed on the code as it is now (`head`, the thread's branch; null for a thread
|
|
159
|
+
* with no branch of its own, where the pass alone counts). True for a team that does not check its work.
|
|
160
|
+
*/
|
|
161
|
+
const checkedNow = (goalId, head = null) => {
|
|
162
|
+
const current = read(goalId);
|
|
163
|
+
if (!current || !checksWork(current)) return true;
|
|
164
|
+
const last = current.lastCheck;
|
|
165
|
+
return Boolean(
|
|
166
|
+
last?.outcome === "passed" && (!head || !last.head || last.head === head)
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Agents were just given work outside the route (the person wrote to them, or a free round picked one): the thread
|
|
172
|
+
* moves to the earliest step one of them holds, so the route goes on from there.
|
|
173
|
+
*/
|
|
174
|
+
const acted = (goalId, agents) => {
|
|
175
|
+
const current = read(goalId);
|
|
176
|
+
if (!current || !agents.length) return;
|
|
177
|
+
const step = stepsOf(current).find((s) =>
|
|
178
|
+
current.roles[s.role].some((holder) => agents.includes(holder))
|
|
179
|
+
);
|
|
180
|
+
if (step && step.id !== current.step) moveTo(goalId, step.id);
|
|
181
|
+
else if (step) write(goalId, { ...current, stepAt: now() });
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* What the round reads about the team: the plan, the step the thread is at, whether everyone on that step has reported
|
|
186
|
+
* since it began, and where the work may go next. `runs` are the thread's runs (store.threadRuns).
|
|
187
|
+
*/
|
|
188
|
+
// When every holder of a step reported after `since`: the last of their reports, else null.
|
|
189
|
+
const reportedAll = (holders, runs, since) => {
|
|
190
|
+
const last = holders.map(
|
|
191
|
+
(agent) =>
|
|
192
|
+
runs
|
|
193
|
+
.filter(
|
|
194
|
+
(run) =>
|
|
195
|
+
run.target_agent === agent &&
|
|
196
|
+
FINISHED.has(run.status) &&
|
|
197
|
+
(run.reported_at ?? "") > since
|
|
198
|
+
)
|
|
199
|
+
.map((run) => run.reported_at)
|
|
200
|
+
.sort()
|
|
201
|
+
.at(-1) ?? null
|
|
202
|
+
);
|
|
203
|
+
return last.every(Boolean) ? last.sort().at(-1) : null;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The route as the work actually went: agents hand each other work by name as well as through the route (October 20,
|
|
208
|
+
* live run: the builder asked the checker itself, and the route still waited at the build). A step that is done and
|
|
209
|
+
* whose next step's agents have reported since moves on, up to a step that judges, whose outcome is the round's.
|
|
210
|
+
*/
|
|
211
|
+
const catchUp = (goalId, current, runs) => {
|
|
212
|
+
const steps = stepsOf(current);
|
|
213
|
+
let caught = current;
|
|
214
|
+
for (;;) {
|
|
215
|
+
const at = steps.findIndex((s) => s.id === caught.step);
|
|
216
|
+
const step = steps[at];
|
|
217
|
+
const next = steps[at + 1];
|
|
218
|
+
if (!step || step.judges || !next) break;
|
|
219
|
+
const done = reportedAll(current.roles[step.role], runs, caught.stepAt);
|
|
220
|
+
if (!done || !reportedAll(current.roles[next.role], runs, done)) break;
|
|
221
|
+
caught = { ...caught, step: next.id, stepAt: done };
|
|
222
|
+
}
|
|
223
|
+
if (caught !== current) write(goalId, caught);
|
|
224
|
+
return caught;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const roundView = (goalId, runs, { head = null } = {}) => {
|
|
228
|
+
const kept = read(goalId);
|
|
229
|
+
if (!kept) return null;
|
|
230
|
+
const current = catchUp(goalId, kept, runs);
|
|
231
|
+
const steps = stepsOf(current);
|
|
232
|
+
// The route is done but the code changed after its last check passed: the work goes to the check again.
|
|
233
|
+
const firstJudge = steps.findIndex((s) => s.judges);
|
|
234
|
+
const recheck =
|
|
235
|
+
current.step === "done" &&
|
|
236
|
+
firstJudge > 0 &&
|
|
237
|
+
Boolean(head) &&
|
|
238
|
+
current.lastCheck?.outcome === "passed" &&
|
|
239
|
+
Boolean(current.lastCheck.head) &&
|
|
240
|
+
current.lastCheck.head !== head;
|
|
241
|
+
if (recheck) {
|
|
242
|
+
const [made, judge] = [steps[firstJudge - 1], steps[firstJudge]];
|
|
243
|
+
return {
|
|
244
|
+
shape: current.shape,
|
|
245
|
+
rigor: current.rigor,
|
|
246
|
+
roles: current.roles,
|
|
247
|
+
sendsBack: current.sendsBack,
|
|
248
|
+
step: {
|
|
249
|
+
id: made.id,
|
|
250
|
+
role: made.role,
|
|
251
|
+
agents: current.roles[made.role],
|
|
252
|
+
judges: false,
|
|
253
|
+
finished: true,
|
|
254
|
+
},
|
|
255
|
+
exits: [
|
|
256
|
+
{
|
|
257
|
+
outcome: "done",
|
|
258
|
+
step: judge.id,
|
|
259
|
+
role: judge.role,
|
|
260
|
+
agents: current.roles[judge.role],
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const at = steps.findIndex((s) => s.id === current.step);
|
|
266
|
+
const view = {
|
|
267
|
+
shape: current.shape,
|
|
268
|
+
rigor: current.rigor,
|
|
269
|
+
roles: current.roles,
|
|
270
|
+
sendsBack: current.sendsBack,
|
|
271
|
+
step: null,
|
|
272
|
+
exits: [],
|
|
273
|
+
};
|
|
274
|
+
if (at === -1) return view;
|
|
275
|
+
const step = steps[at];
|
|
276
|
+
const holders = current.roles[step.role];
|
|
277
|
+
const reportedSince = (agent) =>
|
|
278
|
+
runs.some(
|
|
279
|
+
(run) =>
|
|
280
|
+
run.target_agent === agent &&
|
|
281
|
+
FINISHED.has(run.status) &&
|
|
282
|
+
(run.reported_at ?? "") > current.stepAt
|
|
283
|
+
);
|
|
284
|
+
const finished = holders.every(reportedSince);
|
|
285
|
+
view.step = {
|
|
286
|
+
id: step.id,
|
|
287
|
+
role: step.role,
|
|
288
|
+
agents: holders,
|
|
289
|
+
judges: Boolean(step.judges),
|
|
290
|
+
finished,
|
|
291
|
+
};
|
|
292
|
+
if (!finished) return view;
|
|
293
|
+
const following = steps[at + 1];
|
|
294
|
+
const toStep = (s, outcome) =>
|
|
295
|
+
s
|
|
296
|
+
? { outcome, step: s.id, role: s.role, agents: current.roles[s.role] }
|
|
297
|
+
: { outcome, step: "done", role: null, agents: [] };
|
|
298
|
+
if (!step.judges) view.exits = [toStep(following, "done")];
|
|
299
|
+
else {
|
|
300
|
+
const back = steps.find((s) => s.id === step.sendBack);
|
|
301
|
+
view.exits = [
|
|
302
|
+
toStep(following, "passed"),
|
|
303
|
+
back && current.sendsBack < TEAM.sendBackLimit
|
|
304
|
+
? toStep(back, "sent_back")
|
|
305
|
+
: { outcome: "sent_back", step: "stop", role: null, agents: [] },
|
|
306
|
+
];
|
|
307
|
+
}
|
|
308
|
+
return view;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* An agent's note on what it learned doing its part, for the next holder of its role in the thread's folder: its own
|
|
313
|
+
* words and its reason ("X, because Y"), replacing one of its own notes when `replaces` names it.
|
|
314
|
+
*/
|
|
315
|
+
const learn = (goalId, agent, { text, reason, replaces = null }) => {
|
|
316
|
+
const thread = store.getTask(goalId);
|
|
317
|
+
const words = String(text || "").trim();
|
|
318
|
+
const why = String(reason || "").trim();
|
|
319
|
+
if (!words || !why)
|
|
320
|
+
return {
|
|
321
|
+
ok: false,
|
|
322
|
+
error: "say what you learned (text) and why it holds (reason)",
|
|
323
|
+
};
|
|
324
|
+
const note = store.addTeamNote({
|
|
325
|
+
agent,
|
|
326
|
+
role: rolesOf(goalId, agent)[0] ?? null,
|
|
327
|
+
folder: thread?.goal?.workspace ?? null,
|
|
328
|
+
thread: goalId,
|
|
329
|
+
text: words.slice(0, NOTE_CHARS),
|
|
330
|
+
reason: why.slice(0, NOTE_CHARS),
|
|
331
|
+
replaces: replaces ? String(replaces) : null,
|
|
332
|
+
});
|
|
333
|
+
return { ok: true, note };
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// What earlier holders of a role learned in this folder, newest first, marked as their notes to check.
|
|
337
|
+
const notesFor = (role, folder) =>
|
|
338
|
+
store
|
|
339
|
+
.teamNotes({ role, folder, limit: 5 })
|
|
340
|
+
.map(
|
|
341
|
+
(note) =>
|
|
342
|
+
`${nameOf(note.agent)}, ${age(note.created_at)} (note ${note.id.slice(0, 8)}, unchecked: verify before relying on it): ${note.text}, because ${note.reason}`
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
/** The brief's section on the team, for an agent woken in a thread with a plan. `model`: the agent's model, if known. */
|
|
346
|
+
const brief = (goalId, agent, { model = null } = {}) => {
|
|
347
|
+
const current = read(goalId);
|
|
348
|
+
if (!current) return "";
|
|
349
|
+
const steps = stepsOf(current);
|
|
350
|
+
// The role the agent acts in now comes first: the one its current step is for, when it holds several.
|
|
351
|
+
const now = steps.find((s) => s.id === current.step)?.role;
|
|
352
|
+
const mine = rolesOf(goalId, agent).sort(
|
|
353
|
+
(a, b) => Number(b === now) - Number(a === now)
|
|
354
|
+
);
|
|
355
|
+
const lines = [
|
|
356
|
+
`The team (${SHAPES[current.shape].name}): ${lineup(current)}.`,
|
|
357
|
+
`How careful this work must be: ${current.rigor}. ${TEAM.rigor[current.rigor]}`,
|
|
358
|
+
];
|
|
359
|
+
const folder = store.getTask(goalId)?.goal?.workspace ?? null;
|
|
360
|
+
const learned = [];
|
|
361
|
+
for (const [index, role] of mine.entries()) {
|
|
362
|
+
const contract = TEAM.roles[role];
|
|
363
|
+
if (index > 0) {
|
|
364
|
+
lines.push(`You are also its ${contract.name}, at a later step.`);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
learned.push(...notesFor(role, folder));
|
|
368
|
+
const at = steps.findIndex((s) => s.role === role);
|
|
369
|
+
const next = steps[at + 1];
|
|
370
|
+
lines.push(
|
|
371
|
+
`Your role now: ${contract.name}. ${contract.owns}`,
|
|
372
|
+
`Never: ${contract.never}`,
|
|
373
|
+
`Bring back: ${contract.bringsBack}`,
|
|
374
|
+
next
|
|
375
|
+
? `Next on the team: ${current.roles[next.role].map(nameOf).join(" and ")} (${TEAM.roles[next.role].name}).`
|
|
376
|
+
: "After you, the thread's coordinator reads your result and decides whether the goal is reached. It is not an agent: do not address it, or Harness, to hand the work back."
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
if (!mine.length)
|
|
380
|
+
lines.push(
|
|
381
|
+
"You hold no role on this team: do what you were asked and hand anything else to the agent whose role it is."
|
|
382
|
+
);
|
|
383
|
+
// Goal-level models get the intent and find the route; others do their best work on smaller checked steps.
|
|
384
|
+
if (!goalLevel(model))
|
|
385
|
+
lines.push(
|
|
386
|
+
"Work in small steps: do one part, check that it works, then the next, and say which parts are done."
|
|
387
|
+
);
|
|
388
|
+
if (mine.length)
|
|
389
|
+
lines.push(
|
|
390
|
+
`Before you stop: if you learned something about this folder that the next ${TEAM.roles[mine[0]].name} here should know (a trap, a check that matters, how the code really works), save it with save_learning (id ${goalId}): what you learned and why it holds.`
|
|
391
|
+
);
|
|
392
|
+
return [
|
|
393
|
+
"Your part on the team:",
|
|
394
|
+
...lines.map((line) => `- ${line}`),
|
|
395
|
+
...(learned.length
|
|
396
|
+
? [
|
|
397
|
+
"What earlier agents in your role learned in this folder (theirs, not the person's):",
|
|
398
|
+
...learned.map((note) => `- ${note}`),
|
|
399
|
+
]
|
|
400
|
+
: []),
|
|
401
|
+
"How this team works:",
|
|
402
|
+
...TEAM.rules.map((rule) => `- ${rule}`),
|
|
403
|
+
].join("\n");
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
return {
|
|
407
|
+
plan,
|
|
408
|
+
set,
|
|
409
|
+
moveTo,
|
|
410
|
+
acted,
|
|
411
|
+
roundView,
|
|
412
|
+
checkedNow,
|
|
413
|
+
learn,
|
|
414
|
+
brief,
|
|
415
|
+
rolesOf,
|
|
416
|
+
};
|
|
417
|
+
}
|
package/lib/threadRuns.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { nameOf } from "./members.mjs";
|
|
5
|
+
import { oneLine } from "./oneLine.mjs";
|
|
5
6
|
import { setRunPick } from "./models.mjs";
|
|
6
7
|
import { t3Access, startT3SignIn, steerT3Run } from "./t3.mjs";
|
|
7
8
|
import { t3Model, t3Open, t3Project, t3Provider } from "./places.mjs";
|
|
@@ -20,6 +21,9 @@ export function createThreadRuns({
|
|
|
20
21
|
restrictedWait,
|
|
21
22
|
pauseGoal,
|
|
22
23
|
homeOf,
|
|
24
|
+
// A coding agent not installed here but on another of the person's computers that has the thread's repository:
|
|
25
|
+
// { machine, folder } there (ownMachines.mjs), or null.
|
|
26
|
+
placeElsewhere = () => null,
|
|
23
27
|
}) {
|
|
24
28
|
const { RUNNERS } = authority;
|
|
25
29
|
const inT3 = (thread, agent, review) => {
|
|
@@ -188,7 +192,7 @@ export function createThreadRuns({
|
|
|
188
192
|
const thread = store.getTask(goalId);
|
|
189
193
|
void steerT3Run(
|
|
190
194
|
running.id,
|
|
191
|
-
`The person just wrote in the thread "${thread.objective
|
|
195
|
+
`The person just wrote in the thread "${oneLine(thread.objective)}" while you work:\n\n${words}\n\nTake it into account in what you are doing now.`
|
|
192
196
|
).then((delivery) => {
|
|
193
197
|
if (!delivery) {
|
|
194
198
|
note(`${who} reads your message when its current turn ends.`);
|
|
@@ -228,11 +232,17 @@ export function createThreadRuns({
|
|
|
228
232
|
} = {}
|
|
229
233
|
) => {
|
|
230
234
|
const task = store.getTask(goalId);
|
|
235
|
+
// An agent on another of the person's computers takes its turn there, in that computer's checkout of the thread's
|
|
236
|
+
// repository (machineRuns.mjs); here it works in the thread's own worktree.
|
|
237
|
+
const elsewhere =
|
|
238
|
+
task && !installedAgents.includes(agent)
|
|
239
|
+
? placeElsewhere(agent, task.goal?.workspace ?? null)
|
|
240
|
+
: null;
|
|
231
241
|
if (
|
|
232
242
|
!task ||
|
|
233
243
|
task.status !== "open" ||
|
|
234
244
|
!RUNNERS.has(agent) ||
|
|
235
|
-
!installedAgents.includes(agent)
|
|
245
|
+
(!installedAgents.includes(agent) && !elsewhere)
|
|
236
246
|
)
|
|
237
247
|
return;
|
|
238
248
|
const goal = task.goal;
|
|
@@ -278,9 +288,9 @@ export function createThreadRuns({
|
|
|
278
288
|
const brief = swarmBrief(task, agent, reason, { review });
|
|
279
289
|
// A coding thread in a repository works in its own worktree, so threads never share a checkout; one whose agents the
|
|
280
290
|
// person uses in T3 Code works in T3 (inT3), where T3 makes and keeps the checkout.
|
|
281
|
-
const t3 = inT3(task, agent, review);
|
|
291
|
+
const t3 = !elsewhere && inT3(task, agent, review);
|
|
282
292
|
// The person uses this agent in T3 Code but this turn runs here: the thread says why, once for each reason.
|
|
283
|
-
const gap = t3 || review ? null : t3Gap(agent, goal.workspace);
|
|
293
|
+
const gap = t3 || review || elsewhere ? null : t3Gap(agent, goal.workspace);
|
|
284
294
|
if (gap && !store.meta(`t3-gap-note:${goalId}:${agent}:${gap}`)) {
|
|
285
295
|
store.meta(`t3-gap-note:${goalId}:${agent}:${gap}`, "1");
|
|
286
296
|
store.roomPost({
|
|
@@ -290,8 +300,8 @@ export function createThreadRuns({
|
|
|
290
300
|
text: `${nameOf(agent)} is working on this computer, not in T3 Code: ${gap}.`,
|
|
291
301
|
});
|
|
292
302
|
}
|
|
293
|
-
let folder = goal.workspace;
|
|
294
|
-
if (!t3)
|
|
303
|
+
let folder = elsewhere?.folder ?? goal.workspace;
|
|
304
|
+
if (!t3 && !elsewhere)
|
|
295
305
|
try {
|
|
296
306
|
folder = worktrees.folderFor(task);
|
|
297
307
|
} catch (error) {
|
|
@@ -320,6 +330,7 @@ export function createThreadRuns({
|
|
|
320
330
|
parentId: goalId,
|
|
321
331
|
runWorkspace: folder,
|
|
322
332
|
kind: "wake",
|
|
333
|
+
targetMachine: elsewhere?.machine ?? null,
|
|
323
334
|
});
|
|
324
335
|
if (t3) store.meta(`t3-run:${wake.id}`, "1");
|
|
325
336
|
store.meta(
|
|
@@ -395,7 +406,7 @@ export function createThreadRuns({
|
|
|
395
406
|
goalId: here,
|
|
396
407
|
author: "harness",
|
|
397
408
|
kind: "note",
|
|
398
|
-
text: `Overlap: the thread "${there.objective
|
|
409
|
+
text: `Overlap: the thread "${oneLine(there.objective, 100)}" is also changing ${named}. Merging both will need care; say so if one should wait.`,
|
|
399
410
|
});
|
|
400
411
|
notifyBoard(store.getTask(here));
|
|
401
412
|
}
|
package/lib/threadView.mjs
CHANGED
|
@@ -104,6 +104,18 @@ export function createThreadView({
|
|
|
104
104
|
return capitalized(shorten(words || "New thread", TITLE_LIMIT));
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
// A question's decisions as one-tap choices, when the coordinator gave them (coordinator.mjs).
|
|
108
|
+
const choicesFor = (post) => {
|
|
109
|
+
try {
|
|
110
|
+
const choices = JSON.parse(
|
|
111
|
+
store.meta(`question-choices:${post.id}`) || "[]"
|
|
112
|
+
);
|
|
113
|
+
return choices.length ? { choices } : {};
|
|
114
|
+
} catch {
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
107
119
|
// What waits on the person, newest last. An item's id stays the same while it waits, so a notice sent for it once is
|
|
108
120
|
// not sent again, and every surface clears it together once it is answered.
|
|
109
121
|
function needsYouOf(thread, posts, runs) {
|
|
@@ -142,6 +154,7 @@ export function createThreadView({
|
|
|
142
154
|
text: asked.text,
|
|
143
155
|
seq: asked.seq,
|
|
144
156
|
at: asked.created_at,
|
|
157
|
+
...choicesFor(asked),
|
|
145
158
|
});
|
|
146
159
|
const goal = goals?.record(thread.id);
|
|
147
160
|
// A review waits only in an open thread that is still moving: one the lead closed, or one left for two days, the
|
package/lib/trails.mjs
CHANGED
|
@@ -26,6 +26,10 @@ const EDIT_TOOLS = new Set([
|
|
|
26
26
|
"write",
|
|
27
27
|
"apply_patch",
|
|
28
28
|
]);
|
|
29
|
+
// The newest messages a trail keeps, each up to the length the room digest shows of a post: enough to replay the last
|
|
30
|
+
// few exchanges of a session too full to resume.
|
|
31
|
+
const SAID_KEPT = 6;
|
|
32
|
+
const SAID_CHARS = 1_200;
|
|
29
33
|
const BRIEF_SKIP =
|
|
30
34
|
/^<(?:command-|local-command|system-reminder|task-notification|user-prompt-submit-hook)|^Caveat:/;
|
|
31
35
|
|
|
@@ -100,6 +104,9 @@ function exitCodeOf(text) {
|
|
|
100
104
|
* A session's trail: { agent, sessionId, cwd, brief, startedAt, endedAt, calls, usage, turns }. A call is
|
|
101
105
|
* { at, tool, input (clipped text), named (path words), edited (paths), command, exitCode, error }; usage is one row
|
|
102
106
|
* per model call { at, input, cached, output }; turns are the person's messages and stops, { at, interrupted }. Claude Code and Codex are read in full; other agents fall back to none.
|
|
107
|
+
* It also keeps the model the session last ran on, the context window the agent reported for it (Codex says so with
|
|
108
|
+
* every token count; Claude Code does not), and the newest messages said, { at, by: "person" | "agent", text, cut }, so a
|
|
109
|
+
* session too full to resume can be replayed from (handover.mjs).
|
|
103
110
|
*/
|
|
104
111
|
export async function readTrail(agent, file) {
|
|
105
112
|
if (!["claude-code", "codex"].includes(agent) || !fs.existsSync(file))
|
|
@@ -114,6 +121,19 @@ export async function readTrail(agent, file) {
|
|
|
114
121
|
calls: [],
|
|
115
122
|
usage: [],
|
|
116
123
|
turns: [],
|
|
124
|
+
model: null,
|
|
125
|
+
window: null,
|
|
126
|
+
said: [],
|
|
127
|
+
};
|
|
128
|
+
const say = (at, by, text) => {
|
|
129
|
+
if (!text) return;
|
|
130
|
+
trail.said.push({
|
|
131
|
+
at,
|
|
132
|
+
by,
|
|
133
|
+
text: text.slice(0, SAID_CHARS),
|
|
134
|
+
cut: text.length > SAID_CHARS,
|
|
135
|
+
});
|
|
136
|
+
if (trail.said.length > SAID_KEPT) trail.said.shift();
|
|
117
137
|
};
|
|
118
138
|
const byId = new Map();
|
|
119
139
|
const add = (at, tool, input, id) => {
|
|
@@ -185,8 +205,22 @@ export async function readTrail(agent, file) {
|
|
|
185
205
|
else if (words && !BRIEF_SKIP.test(words)) {
|
|
186
206
|
trail.turns.push({ at, interrupted: false });
|
|
187
207
|
trail.brief ??= words;
|
|
208
|
+
say(at, "person", words);
|
|
188
209
|
}
|
|
189
210
|
}
|
|
211
|
+
if (row.type === "assistant") {
|
|
212
|
+
trail.model = row.message?.model ?? trail.model;
|
|
213
|
+
if (Array.isArray(content))
|
|
214
|
+
say(
|
|
215
|
+
at,
|
|
216
|
+
"agent",
|
|
217
|
+
content
|
|
218
|
+
.filter((part) => part?.type === "text")
|
|
219
|
+
.map((part) => part.text)
|
|
220
|
+
.join("\n")
|
|
221
|
+
.trim()
|
|
222
|
+
);
|
|
223
|
+
}
|
|
190
224
|
if (Array.isArray(content))
|
|
191
225
|
for (const part of content) {
|
|
192
226
|
if (part?.type === "tool_use")
|
|
@@ -230,8 +264,23 @@ export async function readTrail(agent, file) {
|
|
|
230
264
|
) {
|
|
231
265
|
trail.turns.push({ at, interrupted: false });
|
|
232
266
|
trail.brief ??= words;
|
|
267
|
+
say(at, "person", words);
|
|
233
268
|
}
|
|
234
269
|
}
|
|
270
|
+
if (
|
|
271
|
+
row.type === "response_item" &&
|
|
272
|
+
payload.type === "message" &&
|
|
273
|
+
payload.role === "assistant"
|
|
274
|
+
)
|
|
275
|
+
say(at, "agent", textOf(payload.content).trim());
|
|
276
|
+
if (row.type === "turn_context" && payload.model)
|
|
277
|
+
trail.model = payload.model;
|
|
278
|
+
if (
|
|
279
|
+
row.type === "event_msg" &&
|
|
280
|
+
payload.type === "token_count" &&
|
|
281
|
+
payload.info?.model_context_window
|
|
282
|
+
)
|
|
283
|
+
trail.window = payload.info.model_context_window;
|
|
235
284
|
if (
|
|
236
285
|
row.type === "event_msg" &&
|
|
237
286
|
payload.type === "turn_aborted" &&
|