tryharness 0.7.75 → 0.7.77
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 +66 -3
- package/lib/actorRoster.mjs +20 -9
- package/lib/adoption.mjs +5 -3
- package/lib/audit.mjs +7 -2
- package/lib/boardFiles.mjs +4 -2
- package/lib/boardMirror.mjs +2 -0
- package/lib/boardProtocol.json +4 -0
- package/lib/bridge.mjs +3 -0
- package/lib/capabilityCheck.mjs +39 -3
- package/lib/coordinator.mjs +464 -105
- package/lib/daemon.mjs +64 -20
- package/lib/dispatcher.mjs +568 -0
- package/lib/goalCommands.mjs +21 -6
- package/lib/handoffs.mjs +8 -7
- package/lib/handover.mjs +2 -2
- package/lib/inference.mjs +53 -3
- package/lib/jobAnswers.mjs +7 -6
- package/lib/lessons.mjs +6 -1
- package/lib/lineup.mjs +17 -9
- package/lib/localAgentAsk.mjs +68 -29
- package/lib/localmodels.mjs +59 -25
- package/lib/machineRoutes.mjs +1 -0
- package/lib/manager.mjs +97 -52
- package/lib/members.json +5 -1
- package/lib/members.mjs +21 -1
- package/lib/moves.mjs +15 -2
- package/lib/plans.mjs +2 -1
- package/lib/projects.mjs +16 -9
- package/lib/runAuthority.mjs +2 -1
- package/lib/runBrief.mjs +2 -2
- package/lib/runWorker.mjs +6 -6
- package/lib/snippets.mjs +5 -5
- package/lib/store.mjs +68 -4
- package/lib/swarm.mjs +53 -9
- package/lib/taskCommands.mjs +8 -8
- package/lib/taskRooms.mjs +6 -8
- package/lib/team.mjs +5 -3
- package/lib/threadActions.mjs +6 -30
- package/lib/threadAuthority.mjs +16 -3
- package/lib/threadRuns.mjs +26 -16
- package/lib/verdicts.mjs +2 -2
- package/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/release.json +45 -44
package/lib/coordinator.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { LOCAL_DECIDERS, askLocalAgent } from "./localAgentAsk.mjs";
|
|
|
2
2
|
import { roundFields } from "./cards.mjs";
|
|
3
3
|
import {
|
|
4
4
|
CLOUD_HOMED,
|
|
5
|
+
DISPATCHER,
|
|
5
6
|
MACHINE_RUNNERS,
|
|
6
7
|
MEMBERS,
|
|
7
8
|
TAGGED_ONLY,
|
|
@@ -143,6 +144,8 @@ export function createCoordinator({
|
|
|
143
144
|
store,
|
|
144
145
|
mode,
|
|
145
146
|
askHarness,
|
|
147
|
+
// The dispatcher slot (dispatcher.mjs): who words a round Jev decides, sent with it to a server that takes it.
|
|
148
|
+
dispatcher = null,
|
|
146
149
|
connected,
|
|
147
150
|
serverHas,
|
|
148
151
|
roster,
|
|
@@ -178,6 +181,8 @@ export function createCoordinator({
|
|
|
178
181
|
moves = null,
|
|
179
182
|
// The person's open asks in a thread (manager.mjs): while any is open, the goal is not met nor ready for review.
|
|
180
183
|
openAsks = () => [],
|
|
184
|
+
// The person's asks the manager has seen done in a thread.
|
|
185
|
+
doneAsks = () => [],
|
|
181
186
|
computerOf = (goalId) => store.meta(`thread-work-computer:${goalId}`) || null,
|
|
182
187
|
// A post from the other side of a shared project (projects.mjs): their own swarm sorts it, so it starts no round here.
|
|
183
188
|
fromPartner = () => false,
|
|
@@ -214,6 +219,113 @@ export function createCoordinator({
|
|
|
214
219
|
.threadRuns(goalId)
|
|
215
220
|
.some((run) => run.target_agent === agent && going(run)) ||
|
|
216
221
|
hostedAtWork(goalId).includes(agent);
|
|
222
|
+
// Everything the person asked is done (the manager's record) and they have said nothing since: a round then wakes no
|
|
223
|
+
// one. In the A1 run (thread a7aa2891, November 1) the manager had posted "Done: ... shown in #5" when a second round
|
|
224
|
+
// asked Claude Code to "finalize" it, and Claude Code posted its answer twice.
|
|
225
|
+
const allDone = (thread, asked) =>
|
|
226
|
+
!asked &&
|
|
227
|
+
openAsks(thread.id).length === 0 &&
|
|
228
|
+
doneAsks(thread.id).length > 0;
|
|
229
|
+
// The person's message a round answers, whole, as they wrote it: the one they sent the swarm, else their newest post
|
|
230
|
+
// that no agent has answered since (a new thread's opening message is one: it is no ask to the swarm, and the live
|
|
231
|
+
// A1 run on November 1 handed Claude Code a brief in its place).
|
|
232
|
+
const personMessage = (thread, asked) => {
|
|
233
|
+
if (asked) return store.roomPosts(thread.id, asked.seq - 1, 1)[0] ?? null;
|
|
234
|
+
const posts = store.roomPosts(thread.id, 0, 500);
|
|
235
|
+
const newest = posts.findLast(
|
|
236
|
+
(post) => post.author === "user" && post.kind === "post"
|
|
237
|
+
);
|
|
238
|
+
if (!newest) return null;
|
|
239
|
+
const answered = posts.some(
|
|
240
|
+
(post) =>
|
|
241
|
+
post.seq > newest.seq &&
|
|
242
|
+
post.author !== "user" &&
|
|
243
|
+
post.author !== thread.goal.facilitator &&
|
|
244
|
+
["post", "result"].includes(post.kind)
|
|
245
|
+
);
|
|
246
|
+
return answered ? null : newest;
|
|
247
|
+
};
|
|
248
|
+
// An agent is handed each of the person's messages once, whichever round hands it on: a new thread's opening round
|
|
249
|
+
// and its message-to-the-swarm round both handed Claude Code the A1 message (live, November 1).
|
|
250
|
+
// A run of the agent that ended after the message was handed to it frees the message for another try (a retry
|
|
251
|
+
// after a failure is new work).
|
|
252
|
+
const deliveredKey = (thread, agent) => `delivered:${thread.id}:${agent}`;
|
|
253
|
+
const delivered = (thread, agent, message) => {
|
|
254
|
+
if (!message) return false;
|
|
255
|
+
let kept = null;
|
|
256
|
+
try {
|
|
257
|
+
kept = JSON.parse(store.meta(deliveredKey(thread, agent)) || "null");
|
|
258
|
+
} catch {
|
|
259
|
+
kept = null;
|
|
260
|
+
}
|
|
261
|
+
if (kept?.seq !== message.seq) return false;
|
|
262
|
+
return !store
|
|
263
|
+
.threadRuns(thread.id)
|
|
264
|
+
.some(
|
|
265
|
+
(run) =>
|
|
266
|
+
run.target_agent === agent &&
|
|
267
|
+
!going(run) &&
|
|
268
|
+
String(run.updated_at) > kept.at
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
// Claimed before the capability check, so a round deciding at the same time sees it; let go when the check says no.
|
|
272
|
+
const markDelivered = (thread, agent, message) => {
|
|
273
|
+
if (message)
|
|
274
|
+
store.meta(
|
|
275
|
+
deliveredKey(thread, agent),
|
|
276
|
+
JSON.stringify({ seq: message.seq, at: new Date().toISOString() })
|
|
277
|
+
);
|
|
278
|
+
};
|
|
279
|
+
const unmarkDelivered = (thread, agent, message) => {
|
|
280
|
+
if (delivered(thread, agent, message))
|
|
281
|
+
store.meta(deliveredKey(thread, agent), "");
|
|
282
|
+
};
|
|
283
|
+
// A round decided to answer the person's message, and an agent answered it while the round was worded: handing it
|
|
284
|
+
// on now would be on stale facts.
|
|
285
|
+
const answeredMeanwhile = (thread, decision, asked) =>
|
|
286
|
+
Number.isInteger(decision.answers) && !personMessage(thread, asked);
|
|
287
|
+
const wholeWords = (message) =>
|
|
288
|
+
`The person's message #${message.seq}, as they wrote it:\n\n${message.text.slice(0, 20_000)}`;
|
|
289
|
+
// A review checks an agent's work in the thread; with none there, Jev's "review" is told and shown as a look (the
|
|
290
|
+
// owner's A1 test, November 1: a lookup went out as "Review the current state of post 1"), still run read-only as Jev
|
|
291
|
+
// asked. A server that offers "look" lets Jev say so itself.
|
|
292
|
+
const modeIn = (thread, mode, alongside = []) => {
|
|
293
|
+
if (mode !== "review") return mode === "look" ? "look" : "work";
|
|
294
|
+
// In an assembly a review checks the work being made beside it.
|
|
295
|
+
if (alongside.some((part) => part.mode === "work")) return "review";
|
|
296
|
+
const checkable = store
|
|
297
|
+
.roomPosts(thread.id, 0, 500)
|
|
298
|
+
.some(
|
|
299
|
+
(post) =>
|
|
300
|
+
post.author !== "user" &&
|
|
301
|
+
post.author !== thread.goal.facilitator &&
|
|
302
|
+
["result", "post"].includes(post.kind)
|
|
303
|
+
);
|
|
304
|
+
return checkable ? "review" : "look";
|
|
305
|
+
};
|
|
306
|
+
const modeTag = (mode) =>
|
|
307
|
+
mode === "review"
|
|
308
|
+
? "(review, no changes) "
|
|
309
|
+
: mode === "look"
|
|
310
|
+
? "(look, no changes) "
|
|
311
|
+
: "";
|
|
312
|
+
// The routing line beside the person's words, from code: how Jev picked the agent to work on them.
|
|
313
|
+
const routingLine = ({ mode, decide = false, loop = null }) =>
|
|
314
|
+
[
|
|
315
|
+
mode === "look"
|
|
316
|
+
? "Jev picked you to find out and answer this. Change nothing."
|
|
317
|
+
: mode === "review"
|
|
318
|
+
? "Jev picked you to check the work this is about and report on it. Change nothing."
|
|
319
|
+
: "Jev picked you for this.",
|
|
320
|
+
decide
|
|
321
|
+
? "A choice in it is not the person's to make: decide it with your best default, say in the thread which you chose and why, and carry on."
|
|
322
|
+
: "",
|
|
323
|
+
loop === "repeating" || loop === "stuck_on_part"
|
|
324
|
+
? "What was tried before did not work (see the thread): take a different approach."
|
|
325
|
+
: "",
|
|
326
|
+
]
|
|
327
|
+
.filter(Boolean)
|
|
328
|
+
.join(" ");
|
|
217
329
|
const failedHereLately = (threadId, agent) => {
|
|
218
330
|
const at = Date.parse(store.meta(`job-failed:${threadId}:${agent}`) || "");
|
|
219
331
|
return Date.now() - at < FAILED_REST_MS;
|
|
@@ -237,28 +349,122 @@ export function createCoordinator({
|
|
|
237
349
|
// The moves go to a coordinator that takes them: this computer's, or a Harness with swarm_moves.
|
|
238
350
|
const movesTaken = () =>
|
|
239
351
|
Boolean(moves) && (mode() === "local" || serverHas("swarm_moves"));
|
|
240
|
-
//
|
|
241
|
-
//
|
|
352
|
+
// The capability check runs after delivery (owner, November 1: "The capability check should move to be between
|
|
353
|
+
// delivery and manager"): Jev picks agents and computers from what it knows of them, the computer the work goes to
|
|
354
|
+
// looks whether it can do it before the agent starts, and a "no" comes back to Jev here, beside that computer, for the
|
|
355
|
+
// rounds on the same message from the person.
|
|
356
|
+
const checksTaken = () =>
|
|
357
|
+
Boolean(capabilities) &&
|
|
358
|
+
(mode() === "local" || serverHas("capability_checks"));
|
|
359
|
+
const answersKey = (thread) => `capabilities:${thread.id}`;
|
|
360
|
+
const keptAnswers = (thread) => {
|
|
361
|
+
try {
|
|
362
|
+
return JSON.parse(store.meta(answersKey(thread)) || "null");
|
|
363
|
+
} catch {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
242
367
|
const canDo = async (thread, posts, asked) => {
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
let kept = JSON.parse(store.meta(key) || "null");
|
|
250
|
-
const message = asked && posts.find((post) => post.seq === asked.seq);
|
|
251
|
-
if (message && kept?.seq !== message.seq) {
|
|
252
|
-
kept = {
|
|
253
|
-
seq: message.seq,
|
|
254
|
-
answers: await capabilities.check(message.text),
|
|
255
|
-
};
|
|
256
|
-
store.meta(key, JSON.stringify(kept));
|
|
368
|
+
if (!checksTaken()) return new Map();
|
|
369
|
+
let kept = keptAnswers(thread);
|
|
370
|
+
// A new message from the person is new work: what computers said about the last one does not hold for it.
|
|
371
|
+
if (asked && kept?.seq !== asked.seq) {
|
|
372
|
+
kept = { seq: asked.seq, answers: [] };
|
|
373
|
+
store.meta(answersKey(thread), JSON.stringify(kept));
|
|
257
374
|
}
|
|
375
|
+
// Jev hears only the computers that said no to this message; a yes is kept so the same work is not checked twice.
|
|
258
376
|
return new Map(
|
|
259
|
-
(kept?.answers ?? [])
|
|
377
|
+
(kept?.answers ?? [])
|
|
378
|
+
.filter(({ answer }) => answer === "no")
|
|
379
|
+
.map(({ id, answer, why }) => [id, { answer, why }])
|
|
260
380
|
);
|
|
261
381
|
};
|
|
382
|
+
// The computer a coding agent's work goes to when Jev named none: this one where the agent runs here, else the first
|
|
383
|
+
// of its computers online.
|
|
384
|
+
const defaultComputer = (thread, agent) =>
|
|
385
|
+
localAgents().includes(agent)
|
|
386
|
+
? null
|
|
387
|
+
: ((machinesOf(agent, thread.goal.workspace) ?? []).find(
|
|
388
|
+
(computer) => computer.online
|
|
389
|
+
)?.id ?? null);
|
|
390
|
+
// The computer the agent's work lands on, as the run is placed (threadRuns.mjs wake): the computer holding the
|
|
391
|
+
// thread's checkout, else the one this agent or the thread worked on before, else the route's computer for it, else
|
|
392
|
+
// the one Jev picked when it is online, else the agent's default. The check looks at the same computer.
|
|
393
|
+
const placedOn = (thread, agent, computer) => {
|
|
394
|
+
const online = (id) =>
|
|
395
|
+
Boolean(id) &&
|
|
396
|
+
(machinesOf(agent, thread.goal.workspace) ?? []).some(
|
|
397
|
+
(each) => each.id === id && each.online
|
|
398
|
+
);
|
|
399
|
+
return (
|
|
400
|
+
computerOf(thread.id) ||
|
|
401
|
+
store.meta(`thread-computer:${thread.id}:${agent}`) ||
|
|
402
|
+
store.meta(`thread-computer:${thread.id}`) ||
|
|
403
|
+
team?.machineFor?.(thread.id, agent) ||
|
|
404
|
+
(online(computer) ? computer : null) ||
|
|
405
|
+
defaultComputer(thread, agent)
|
|
406
|
+
);
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* The check after delivery (owner, November 1: "The capability check should move to be between delivery and
|
|
410
|
+
* manager"), for a coding agent's work, on the computer it lands on, before the agent starts. Kept for the person's
|
|
411
|
+
* message, beside that computer, so the same work is not looked at twice. True: the work goes ahead. False: the
|
|
412
|
+
* computer said no and the thread says what it found; the message goes back to Jev when another computer is online,
|
|
413
|
+
* and otherwise the thread waits on the person. A computer picked again after saying no pauses the thread.
|
|
414
|
+
*/
|
|
415
|
+
const checkedOn = async (thread, agent, computer, work, asked) => {
|
|
416
|
+
if (!checksTaken() || !MACHINE_RUNNERS.includes(agent)) return true;
|
|
417
|
+
const target = placedOn(thread, agent, computer);
|
|
418
|
+
const id = target ?? capabilities.here();
|
|
419
|
+
const label = capabilities.labelOf(target);
|
|
420
|
+
const kept = keptAnswers(thread) ?? {
|
|
421
|
+
seq: asked?.seq ?? null,
|
|
422
|
+
answers: [],
|
|
423
|
+
};
|
|
424
|
+
const before = kept.answers.find((each) => each.id === id);
|
|
425
|
+
if (before?.answer === "no") {
|
|
426
|
+
pauseGoal(
|
|
427
|
+
thread.id,
|
|
428
|
+
`${label} said it cannot do this (${before.why}) and was picked again`
|
|
429
|
+
);
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
if (before) return true;
|
|
433
|
+
const found = await capabilities
|
|
434
|
+
.on(target, String(work))
|
|
435
|
+
.catch((error) => ({ answer: "unknown", why: error.message }));
|
|
436
|
+
// Read again: the other parts of an assembly are checked at the same time and keep their answers too.
|
|
437
|
+
const latest = keptAnswers(thread) ?? kept;
|
|
438
|
+
store.meta(
|
|
439
|
+
answersKey(thread),
|
|
440
|
+
JSON.stringify({
|
|
441
|
+
...latest,
|
|
442
|
+
answers: [
|
|
443
|
+
...latest.answers.filter((each) => each.id !== id),
|
|
444
|
+
{ id, label, answer: found.answer, why: found.why },
|
|
445
|
+
],
|
|
446
|
+
})
|
|
447
|
+
);
|
|
448
|
+
if (found.answer !== "no") return true;
|
|
449
|
+
if (!capabilities.choosing()) {
|
|
450
|
+
pauseGoal(
|
|
451
|
+
thread.id,
|
|
452
|
+
`${label} cannot do this for ${nameOf(agent)}: ${found.why}`
|
|
453
|
+
);
|
|
454
|
+
notifyBoard(store.getTask(thread.id));
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
postAsCoordinator({
|
|
458
|
+
goalId: thread.id,
|
|
459
|
+
author: thread.goal.facilitator,
|
|
460
|
+
kind: "note",
|
|
461
|
+
text: `${label} cannot do this for ${nameOf(agent)}: ${found.why} Jev picks again.`,
|
|
462
|
+
});
|
|
463
|
+
if (asked) store.meta(`swarm-asked:${thread.id}`, JSON.stringify(asked));
|
|
464
|
+
store.meta(`coordinator-resumed:${thread.id}`, "1");
|
|
465
|
+
poke(thread.id);
|
|
466
|
+
return false;
|
|
467
|
+
};
|
|
262
468
|
// The person's pins: specialty -> the agent that holds it when a step asks for it.
|
|
263
469
|
const pinsNow = () =>
|
|
264
470
|
Object.fromEntries(
|
|
@@ -570,10 +776,11 @@ export function createCoordinator({
|
|
|
570
776
|
const reachable = connected();
|
|
571
777
|
const names = pool.filter(
|
|
572
778
|
(agent) =>
|
|
573
|
-
agent !== "harness" &&
|
|
574
779
|
!asked.named.includes(agent) &&
|
|
575
780
|
(!TAGGED.has(agent) || inThread.includes(agent)) &&
|
|
576
|
-
(reachable || CODING.has(agent))
|
|
781
|
+
(reachable || CODING.has(agent)) &&
|
|
782
|
+
// One already handed this message has it (the A1 run's opening round, November 1).
|
|
783
|
+
!delivered(thread, agent, { seq: asked.seq })
|
|
577
784
|
);
|
|
578
785
|
const words = store
|
|
579
786
|
.roomPosts(thread.id, Math.max(0, asked.seq - 1), 1)
|
|
@@ -582,20 +789,21 @@ export function createCoordinator({
|
|
|
582
789
|
const joining = names.filter((agent) => !thread.goal.team.includes(agent));
|
|
583
790
|
if (joining.length)
|
|
584
791
|
store.setGoalTeam(thread.id, [...thread.goal.team, ...joining]);
|
|
792
|
+
for (const agent of names) markDelivered(thread, agent, { seq: asked.seq });
|
|
585
793
|
const list = names.map(nameOf).join(", ");
|
|
586
794
|
store.roomPost({
|
|
587
795
|
goalId: thread.id,
|
|
588
796
|
author: thread.goal.facilitator,
|
|
589
797
|
kind: "note",
|
|
590
798
|
text: why
|
|
591
|
-
? `
|
|
799
|
+
? `Jev could not work out who does what (${why}), so your message went to every agent here: ${list}.`
|
|
592
800
|
: `Your message went to every agent here: ${list}.`,
|
|
593
801
|
});
|
|
594
802
|
wakeAll(
|
|
595
803
|
thread.id,
|
|
596
804
|
names,
|
|
597
805
|
words,
|
|
598
|
-
`${asked.swarm ? "the person wrote to the whole swarm and " : ""}every agent here heard the person's message as they wrote it${why ? ", since
|
|
806
|
+
`${asked.swarm ? "the person wrote to the whole swarm and " : ""}every agent here heard the person's message as they wrote it${why ? ", since Jev could not work out who does what" : asked.swarm ? "" : ", since Jev found no one part in it"}. Do the part of it that is yours; if none of it is, say so in one line and stop`
|
|
599
807
|
);
|
|
600
808
|
notifyBoard(store.getTask(thread.id));
|
|
601
809
|
return names;
|
|
@@ -629,6 +837,7 @@ export function createCoordinator({
|
|
|
629
837
|
action: "hand_on",
|
|
630
838
|
agent: decider,
|
|
631
839
|
mode: "work",
|
|
840
|
+
decide: true,
|
|
632
841
|
text: `No need to ask the person this: ${String(decision.text).slice(0, 2_000)} Decide it with your best default, say in the thread which you chose and why, and carry on.`,
|
|
633
842
|
};
|
|
634
843
|
};
|
|
@@ -653,6 +862,8 @@ export function createCoordinator({
|
|
|
653
862
|
if (store.meta(`goal-kept:${thread.id}`) === String(personSaid(thread)))
|
|
654
863
|
return false;
|
|
655
864
|
goals.set(thread.id, decision.goal, { by: coordinator, seq: newest });
|
|
865
|
+
// Either round may word the goal for this post first (the goal round and the thread's own); the other keeps it.
|
|
866
|
+
store.meta(`goal-kept:${thread.id}`, String(personSaid(thread)));
|
|
656
867
|
return false;
|
|
657
868
|
}
|
|
658
869
|
if (!decision.met && !decision.goalState) return false;
|
|
@@ -1016,7 +1227,8 @@ export function createCoordinator({
|
|
|
1016
1227
|
).filter(
|
|
1017
1228
|
(part) =>
|
|
1018
1229
|
candidates.some((candidate) => candidate.id === part?.agent) &&
|
|
1019
|
-
part.text
|
|
1230
|
+
(part.text || asked) &&
|
|
1231
|
+
!allDone(thread, asked)
|
|
1020
1232
|
);
|
|
1021
1233
|
if (!parts.length) {
|
|
1022
1234
|
if (unheard) tellEveryone(thread, asked, null, { decided: true });
|
|
@@ -1032,65 +1244,109 @@ export function createCoordinator({
|
|
|
1032
1244
|
notifyBoard(store.getTask(thread.id));
|
|
1033
1245
|
return;
|
|
1034
1246
|
}
|
|
1035
|
-
const joining = parts
|
|
1036
|
-
.map((part) => part.agent)
|
|
1037
|
-
.filter((agent) => !thread.goal.team.includes(agent));
|
|
1038
|
-
if (joining.length)
|
|
1039
|
-
store.setGoalTeam(thread.id, [...thread.goal.team, ...joining]);
|
|
1040
1247
|
const worded = parts.map((part) => {
|
|
1041
|
-
const
|
|
1248
|
+
const mode = modeIn(
|
|
1249
|
+
thread,
|
|
1250
|
+
part.mode,
|
|
1251
|
+
parts.filter((other) => other !== part)
|
|
1252
|
+
);
|
|
1042
1253
|
return {
|
|
1043
1254
|
...part,
|
|
1044
|
-
|
|
1045
|
-
|
|
1255
|
+
mode,
|
|
1256
|
+
review: part.mode === "review" && REVIEWERS.has(part.agent),
|
|
1257
|
+
text: String(part.text ?? "").slice(0, 2_000),
|
|
1046
1258
|
};
|
|
1047
1259
|
});
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
.map(
|
|
1056
|
-
(part) =>
|
|
1057
|
-
`@${part.agent} ${part.review ? "(review, no changes) " : ""}${part.text}`
|
|
1058
|
-
)
|
|
1059
|
-
.join("\n\n"),
|
|
1060
|
-
});
|
|
1061
|
-
// The team moves first, so each brief says the step its agent now acts in.
|
|
1062
|
-
const moved = moveTeam(
|
|
1063
|
-
thread,
|
|
1064
|
-
decision,
|
|
1065
|
-
[...worded.map((part) => part.agent), ...(asked?.named ?? [])],
|
|
1066
|
-
coordinator
|
|
1260
|
+
const message = personMessage(thread, asked);
|
|
1261
|
+
if (answeredMeanwhile(thread, decision, asked)) {
|
|
1262
|
+
notifyBoard(store.getTask(thread.id));
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
const fresh = worded.filter(
|
|
1266
|
+
(part) => !delivered(thread, part.agent, message)
|
|
1067
1267
|
);
|
|
1068
|
-
if (!
|
|
1268
|
+
if (!fresh.length) {
|
|
1069
1269
|
notifyBoard(store.getTask(thread.id));
|
|
1070
1270
|
return;
|
|
1071
1271
|
}
|
|
1072
|
-
for (const part of
|
|
1073
|
-
|
|
1272
|
+
for (const part of fresh) markDelivered(thread, part.agent, message);
|
|
1273
|
+
// Each part is checked on the computer it goes to before anyone starts; one "no" sends the whole message back to
|
|
1274
|
+
// Jev, so no agent starts on half an assembly.
|
|
1275
|
+
return Promise.all(
|
|
1276
|
+
fresh.map((part) =>
|
|
1277
|
+
checkedOn(
|
|
1278
|
+
thread,
|
|
1279
|
+
part.agent,
|
|
1280
|
+
part.computer ?? null,
|
|
1281
|
+
message?.text ?? part.text,
|
|
1282
|
+
asked
|
|
1283
|
+
)
|
|
1284
|
+
)
|
|
1285
|
+
).then((checks) => {
|
|
1286
|
+
if (!checks.every(Boolean)) {
|
|
1287
|
+
for (const part of fresh)
|
|
1288
|
+
unmarkDelivered(thread, part.agent, message);
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
const joining = parts
|
|
1292
|
+
.map((part) => part.agent)
|
|
1293
|
+
.filter((agent) => !thread.goal.team.includes(agent));
|
|
1294
|
+
if (joining.length)
|
|
1295
|
+
store.setGoalTeam(thread.id, [...thread.goal.team, ...joining]);
|
|
1296
|
+
// Named as the post's addressees so the thread shows who it is to; each is woken below, not by the post.
|
|
1297
|
+
postAsCoordinator({
|
|
1298
|
+
goalId: thread.id,
|
|
1299
|
+
author: coordinator,
|
|
1300
|
+
kind: "post",
|
|
1301
|
+
mentions: fresh.map((part) => part.agent),
|
|
1302
|
+
text: fresh
|
|
1303
|
+
.map(
|
|
1304
|
+
(part) =>
|
|
1305
|
+
`@${part.agent} ${modeTag(part.mode)}${message ? `your message #${message.seq}.${part.text ? ` Your part: ${part.text}` : ""}` : part.text}`
|
|
1306
|
+
)
|
|
1307
|
+
.join("\n\n"),
|
|
1308
|
+
});
|
|
1309
|
+
// The team moves first, so each brief says the step its agent now acts in.
|
|
1310
|
+
const moved = moveTeam(
|
|
1074
1311
|
thread,
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
? part.text
|
|
1078
|
-
: `${coordinator} asked you: ${part.text.slice(0, 300)}`,
|
|
1079
|
-
{
|
|
1080
|
-
review: part.review,
|
|
1081
|
-
words: part.text,
|
|
1082
|
-
computer: part.computer ?? null,
|
|
1083
|
-
},
|
|
1312
|
+
decision,
|
|
1313
|
+
[...fresh.map((part) => part.agent), ...(asked?.named ?? [])],
|
|
1084
1314
|
coordinator
|
|
1085
1315
|
);
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
)
|
|
1092
|
-
|
|
1093
|
-
|
|
1316
|
+
if (!moved) {
|
|
1317
|
+
notifyBoard(store.getTask(thread.id));
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
// Each agent gets the person's words whole, with its part beside them (owner, November 1: "the swarm should know
|
|
1321
|
+
// about the full words from the user ... lossy notes are unacceptable").
|
|
1322
|
+
for (const part of fresh) {
|
|
1323
|
+
const words = message
|
|
1324
|
+
? [
|
|
1325
|
+
wholeWords(message),
|
|
1326
|
+
routingLine({ mode: part.mode }),
|
|
1327
|
+
part.text ? `Your part, from the dispatcher: ${part.text}` : "",
|
|
1328
|
+
]
|
|
1329
|
+
.filter(Boolean)
|
|
1330
|
+
.join("\n\n")
|
|
1331
|
+
: part.text;
|
|
1332
|
+
handOnOrHold(
|
|
1333
|
+
thread,
|
|
1334
|
+
part.agent,
|
|
1335
|
+
withheld || message
|
|
1336
|
+
? words
|
|
1337
|
+
: `${nameOf(coordinator)} asked you: ${part.text.slice(0, 300)}`,
|
|
1338
|
+
{ review: part.review, words, computer: part.computer ?? null },
|
|
1339
|
+
coordinator
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
if (withheld)
|
|
1343
|
+
saidWithheld(
|
|
1344
|
+
thread,
|
|
1345
|
+
withheld,
|
|
1346
|
+
fresh.map((part) => part.agent)
|
|
1347
|
+
);
|
|
1348
|
+
notifyBoard(store.getTask(thread.id));
|
|
1349
|
+
});
|
|
1094
1350
|
}
|
|
1095
1351
|
if (decision.action === "ask_person" && decision.text) {
|
|
1096
1352
|
const asked = postAsCoordinator({
|
|
@@ -1109,8 +1365,9 @@ export function createCoordinator({
|
|
|
1109
1365
|
if (
|
|
1110
1366
|
decision.action === "hand_on" &&
|
|
1111
1367
|
candidates.some((candidate) => candidate.id === decision.agent) &&
|
|
1112
|
-
decision.text
|
|
1368
|
+
(decision.text || personMessage(thread, asked))
|
|
1113
1369
|
) {
|
|
1370
|
+
const mode = modeIn(thread, decision.mode);
|
|
1114
1371
|
const review =
|
|
1115
1372
|
decision.mode === "review" && REVIEWERS.has(decision.agent);
|
|
1116
1373
|
const agent = review
|
|
@@ -1120,19 +1377,73 @@ export function createCoordinator({
|
|
|
1120
1377
|
// not handed to it again: Bankr was handed the same purchase twice, and a round begun on a new thread's title
|
|
1121
1378
|
// posted "@claude-code (review, no changes)" after the person's own ask had started Claude Code, whose turn did
|
|
1122
1379
|
// the review instead (live, October 31). The person's new message is new work, and still reaches it.
|
|
1123
|
-
if (
|
|
1380
|
+
if (
|
|
1381
|
+
(!asked && holdsWork(thread.id, agent)) ||
|
|
1382
|
+
allDone(thread, asked) ||
|
|
1383
|
+
answeredMeanwhile(thread, decision, asked) ||
|
|
1384
|
+
delivered(thread, agent, personMessage(thread, asked))
|
|
1385
|
+
) {
|
|
1124
1386
|
notifyBoard(store.getTask(thread.id));
|
|
1125
1387
|
return;
|
|
1126
1388
|
}
|
|
1389
|
+
// Answering the person's message, the agent gets their words whole with the routing line, and the thread one
|
|
1390
|
+
// routing line; between agents, the dispatcher's brief. A review runs with its read-only switch.
|
|
1391
|
+
const message = personMessage(thread, asked);
|
|
1392
|
+
const brief = String(decision.text ?? "").slice(0, 4_000);
|
|
1393
|
+
const text = message
|
|
1394
|
+
? `${wholeWords(message)}\n\n${routingLine({ ...decision, mode })}`
|
|
1395
|
+
: brief;
|
|
1396
|
+
// Delivered, then checked on the computer it goes to before anything starts (capability check after delivery);
|
|
1397
|
+
// a "no" goes back to Jev and nothing is posted or woken.
|
|
1398
|
+
markDelivered(thread, agent, message);
|
|
1399
|
+
return checkedOn(
|
|
1400
|
+
thread,
|
|
1401
|
+
agent,
|
|
1402
|
+
decision.computer ?? null,
|
|
1403
|
+
message?.text ?? brief,
|
|
1404
|
+
asked
|
|
1405
|
+
).then((can) => {
|
|
1406
|
+
if (!can) {
|
|
1407
|
+
unmarkDelivered(thread, agent, message);
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
handOnNow({
|
|
1411
|
+
thread,
|
|
1412
|
+
decision,
|
|
1413
|
+
agent,
|
|
1414
|
+
mode,
|
|
1415
|
+
review,
|
|
1416
|
+
message,
|
|
1417
|
+
text,
|
|
1418
|
+
coordinator,
|
|
1419
|
+
withheld,
|
|
1420
|
+
});
|
|
1421
|
+
});
|
|
1422
|
+
} else if (withheld) saidWithheld(thread, withheld, []);
|
|
1423
|
+
notifyBoard(store.getTask(thread.id));
|
|
1424
|
+
};
|
|
1425
|
+
|
|
1426
|
+
const handOnNow = ({
|
|
1427
|
+
thread,
|
|
1428
|
+
decision,
|
|
1429
|
+
agent,
|
|
1430
|
+
mode,
|
|
1431
|
+
review,
|
|
1432
|
+
message,
|
|
1433
|
+
text,
|
|
1434
|
+
coordinator,
|
|
1435
|
+
withheld,
|
|
1436
|
+
}) => {
|
|
1437
|
+
{
|
|
1127
1438
|
if (!thread.goal.team.includes(agent))
|
|
1128
1439
|
store.setGoalTeam(thread.id, [...thread.goal.team, agent]);
|
|
1129
|
-
const text = String(decision.text).slice(0, 4_000);
|
|
1130
|
-
// The brief is posted for everyone to read and the agent is woken here, so a review runs with its read-only switch.
|
|
1131
1440
|
postAsCoordinator({
|
|
1132
1441
|
goalId: thread.id,
|
|
1133
1442
|
author: coordinator,
|
|
1134
1443
|
kind: "post",
|
|
1135
|
-
text:
|
|
1444
|
+
text: message
|
|
1445
|
+
? `@${agent} ${modeTag(mode)}your message #${message.seq}.`
|
|
1446
|
+
: `@${agent} ${modeTag(mode)}${text}`,
|
|
1136
1447
|
});
|
|
1137
1448
|
if (!moveTeam(thread, decision, [agent], coordinator)) {
|
|
1138
1449
|
notifyBoard(store.getTask(thread.id));
|
|
@@ -1141,12 +1452,16 @@ export function createCoordinator({
|
|
|
1141
1452
|
handOnOrHold(
|
|
1142
1453
|
thread,
|
|
1143
1454
|
agent,
|
|
1144
|
-
withheld
|
|
1455
|
+
withheld
|
|
1456
|
+
? text
|
|
1457
|
+
: message
|
|
1458
|
+
? text
|
|
1459
|
+
: `${nameOf(coordinator)} asked you: ${text.slice(0, 300)}`,
|
|
1145
1460
|
{ review, words: text, computer: decision.computer ?? null },
|
|
1146
1461
|
coordinator
|
|
1147
1462
|
);
|
|
1148
1463
|
if (withheld) saidWithheld(thread, withheld, [agent]);
|
|
1149
|
-
}
|
|
1464
|
+
}
|
|
1150
1465
|
notifyBoard(store.getTask(thread.id));
|
|
1151
1466
|
};
|
|
1152
1467
|
|
|
@@ -1190,12 +1505,22 @@ export function createCoordinator({
|
|
|
1190
1505
|
try {
|
|
1191
1506
|
const reply = await askHarness(
|
|
1192
1507
|
"coordinate",
|
|
1193
|
-
{ ...gathered, goalOnly: true },
|
|
1508
|
+
worded({ ...gathered, goalOnly: true }),
|
|
1194
1509
|
null
|
|
1195
1510
|
);
|
|
1196
1511
|
if (!reply.ok)
|
|
1197
|
-
throw new Error(reply.error || "
|
|
1512
|
+
throw new Error(reply.error || "Jev did not keep the goal");
|
|
1198
1513
|
decision = reply.result ?? reply;
|
|
1514
|
+
// The goal's words are the dispatcher's (dispatcher.mjs), whoever wrote them before.
|
|
1515
|
+
if (dispatcher && (decision.goal || decision.goalDue)) {
|
|
1516
|
+
const kept = await dispatcher.words(decision, gathered, null);
|
|
1517
|
+
decision = kept.decision;
|
|
1518
|
+
if (kept.failed.length)
|
|
1519
|
+
noteOnce(
|
|
1520
|
+
thread,
|
|
1521
|
+
`The dispatcher could not write ${kept.failed.join("; ")}.`
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1199
1524
|
} catch (failure) {
|
|
1200
1525
|
error = failure.message;
|
|
1201
1526
|
}
|
|
@@ -1213,9 +1538,16 @@ export function createCoordinator({
|
|
|
1213
1538
|
});
|
|
1214
1539
|
if (!decision?.goal) return;
|
|
1215
1540
|
const now = store.getTask(thread.id);
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1541
|
+
// Read only words Harness's server wrote: the dispatcher's own here are this computer's.
|
|
1542
|
+
const fromServer =
|
|
1543
|
+
!dispatcher || dispatcher.setting().provider === "surplus";
|
|
1544
|
+
const screened =
|
|
1545
|
+
serverWords && fromServer
|
|
1546
|
+
? await serverWords.screen(
|
|
1547
|
+
{ goal: decision.goal },
|
|
1548
|
+
readingFor(thread.id)
|
|
1549
|
+
)
|
|
1550
|
+
: { reason: null };
|
|
1219
1551
|
if (screened.reason) {
|
|
1220
1552
|
saidWithheld(now, screened, []);
|
|
1221
1553
|
return;
|
|
@@ -1225,10 +1557,16 @@ export function createCoordinator({
|
|
|
1225
1557
|
};
|
|
1226
1558
|
|
|
1227
1559
|
// One coordinator's decision for the round's facts: Harness's server, or a coding agent here with its tools off.
|
|
1560
|
+
// The relay's dispatcher words every round (dispatcher.mjs), so a server that takes it (swarm_dispatcher) writes
|
|
1561
|
+
// nothing and returns Jev's decision only; an older server's words are replaced here.
|
|
1562
|
+
const worded = (gathered) =>
|
|
1563
|
+
dispatcher && serverHas("swarm_dispatcher")
|
|
1564
|
+
? { ...gathered, dispatcher: { provider: "relay" } }
|
|
1565
|
+
: gathered;
|
|
1228
1566
|
const decideWith = async (coordinator, gathered) => {
|
|
1229
1567
|
if (coordinator !== JEV) return localDecision(coordinator, gathered);
|
|
1230
1568
|
// No deadline of its own: the round ends when Harness answers or the connection drops.
|
|
1231
|
-
const reply = await askHarness("coordinate", gathered, null);
|
|
1569
|
+
const reply = await askHarness("coordinate", worded(gathered), null);
|
|
1232
1570
|
if (!reply.ok)
|
|
1233
1571
|
throw new Error(reply.error || "Harness did not coordinate this round");
|
|
1234
1572
|
return reply.result ?? reply;
|
|
@@ -1285,15 +1623,17 @@ export function createCoordinator({
|
|
|
1285
1623
|
store.meta(`coordinator-post:${post.id}`)
|
|
1286
1624
|
);
|
|
1287
1625
|
if (!begun) {
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1626
|
+
Promise.resolve(
|
|
1627
|
+
apply(
|
|
1628
|
+
thread,
|
|
1629
|
+
intent.decision,
|
|
1630
|
+
intent.coordinator,
|
|
1631
|
+
intent.candidates,
|
|
1632
|
+
intent.asked,
|
|
1633
|
+
intent.rules,
|
|
1634
|
+
intent.withheld
|
|
1635
|
+
)
|
|
1636
|
+
).catch((error) => log(`coordinator ${goalId}: ${error.message}`));
|
|
1297
1637
|
continue;
|
|
1298
1638
|
}
|
|
1299
1639
|
for (const agent of wokenBy(intent.decision)) {
|
|
@@ -1417,7 +1757,7 @@ export function createCoordinator({
|
|
|
1417
1757
|
store.meta(`inventory-wait:${goalId}`, waitingFor);
|
|
1418
1758
|
store.roomPost({
|
|
1419
1759
|
goalId,
|
|
1420
|
-
author:
|
|
1760
|
+
author: DISPATCHER,
|
|
1421
1761
|
kind: "note",
|
|
1422
1762
|
text: `Waiting for repository inventory from ${waitingFor}. Work starts automatically when it arrives.`,
|
|
1423
1763
|
});
|
|
@@ -1442,7 +1782,7 @@ export function createCoordinator({
|
|
|
1442
1782
|
store.meta(`inventory-unavailable:${goalId}`, unavailable);
|
|
1443
1783
|
store.roomPost({
|
|
1444
1784
|
goalId,
|
|
1445
|
-
author:
|
|
1785
|
+
author: DISPATCHER,
|
|
1446
1786
|
kind: "note",
|
|
1447
1787
|
text: `Repository inventory did not arrive from ${unavailable}. Continuing on eligible computers.`,
|
|
1448
1788
|
});
|
|
@@ -1561,7 +1901,7 @@ export function createCoordinator({
|
|
|
1561
1901
|
.join(" and ");
|
|
1562
1902
|
noteOnce(
|
|
1563
1903
|
thread,
|
|
1564
|
-
`${
|
|
1904
|
+
`${jevCould(error)}${others ? `, and ${others} could not stand in` : ""}.`
|
|
1565
1905
|
);
|
|
1566
1906
|
notifyBoard(store.getTask(goalId));
|
|
1567
1907
|
return;
|
|
@@ -1569,12 +1909,29 @@ export function createCoordinator({
|
|
|
1569
1909
|
if (decidedBy !== JEV && !local)
|
|
1570
1910
|
noteOnce(
|
|
1571
1911
|
thread,
|
|
1572
|
-
`${
|
|
1912
|
+
`${jevCould(error)}; ${nameOf(decidedBy)} coordinated it.`
|
|
1573
1913
|
);
|
|
1574
|
-
//
|
|
1575
|
-
//
|
|
1914
|
+
// The dispatcher writes what the decision needs in words (dispatcher.mjs), replacing whatever a coordinator wrote,
|
|
1915
|
+
// so every word in the thread is from what signs it; a job it could not do is said in the thread.
|
|
1916
|
+
if (dispatcher) {
|
|
1917
|
+
const answering = personMessage(thread, asked);
|
|
1918
|
+
const worded = await dispatcher.words(decision, gathered, answering);
|
|
1919
|
+
decision = {
|
|
1920
|
+
...worded.decision,
|
|
1921
|
+
...(answering ? { answers: answering.seq } : {}),
|
|
1922
|
+
};
|
|
1923
|
+
if (worded.failed.length)
|
|
1924
|
+
noteOnce(
|
|
1925
|
+
thread,
|
|
1926
|
+
`The dispatcher could not write ${worded.failed.join("; ")}.`
|
|
1927
|
+
);
|
|
1928
|
+
}
|
|
1929
|
+
// Words from Harness's server keep the person's go only once this computer read them (serverWords.mjs): a round's
|
|
1930
|
+
// words are the server's only when the person put the dispatcher on a Surplus model, or there is no dispatcher.
|
|
1931
|
+
const serverWrote =
|
|
1932
|
+
!dispatcher || dispatcher.setting().provider === "surplus";
|
|
1576
1933
|
let withheld = null;
|
|
1577
|
-
if (decidedBy === JEV && serverWords) {
|
|
1934
|
+
if (decidedBy === JEV && serverWords && serverWrote) {
|
|
1578
1935
|
const { reason, asks } = await serverWords.screen(
|
|
1579
1936
|
decision,
|
|
1580
1937
|
readingFor(goalId)
|
|
@@ -1595,7 +1952,8 @@ export function createCoordinator({
|
|
|
1595
1952
|
withheld,
|
|
1596
1953
|
};
|
|
1597
1954
|
keepIntent(goalId, intent);
|
|
1598
|
-
|
|
1955
|
+
// Kept until the decision is carried out, its check on the computer the work goes to included.
|
|
1956
|
+
await apply(
|
|
1599
1957
|
store.getTask(goalId),
|
|
1600
1958
|
decision,
|
|
1601
1959
|
intent.coordinator,
|
|
@@ -1607,12 +1965,13 @@ export function createCoordinator({
|
|
|
1607
1965
|
keepIntent(goalId, null);
|
|
1608
1966
|
};
|
|
1609
1967
|
|
|
1610
|
-
// Why
|
|
1611
|
-
const
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1968
|
+
// Why Jev did not decide, as one clause: its own words when it said why, else the failure behind it.
|
|
1969
|
+
const jevCould = (error) => {
|
|
1970
|
+
// Jev decides; a server from before November 1 said "Harness" for it.
|
|
1971
|
+
const why = String(error || "it did not answer")
|
|
1972
|
+
.replace(/\.+$/, "")
|
|
1973
|
+
.replace(/^Harness (could|cannot|decided)/, "Jev $1");
|
|
1974
|
+
return /^Jev /.test(why) ? why : `Jev could not decide this round (${why})`;
|
|
1616
1975
|
};
|
|
1617
1976
|
|
|
1618
1977
|
// The coordinator's note, unless the thread's newest post already says the same: a repeat after new work is said
|