tryharness 0.7.53 → 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 +23 -19
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +484 -90
- package/lib/activity.mjs +10 -10
- package/lib/adapters.mjs +173 -222
- package/lib/agentBinaries.mjs +71 -0
- package/lib/agentRuntimeConfig.mjs +1 -1
- package/lib/agentRuntimes.mjs +34 -18
- package/lib/agentSignIn.mjs +456 -0
- 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 +666 -0
- package/lib/backupSetup.mjs +143 -0
- package/lib/boardAccess.mjs +24 -11
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardFileCommands.mjs +6 -6
- package/lib/boardFiles.mjs +13 -12
- package/lib/boardMirror.mjs +124 -25
- package/lib/boardProtocol.json +88 -2
- package/lib/boardWaits.mjs +101 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +6 -6
- package/lib/cards.mjs +138 -28
- package/lib/cloudAgents.mjs +216 -0
- package/lib/cloudAi.mjs +1312 -0
- package/lib/cloudAssistants.mjs +242 -0
- package/lib/cloudBoot.mjs +119 -0
- package/lib/cloudSave.mjs +197 -0
- package/lib/cloudSsh.mjs +178 -0
- package/lib/commands.mjs +7 -2
- package/lib/context.mjs +19 -5
- package/lib/contractGate.mjs +399 -0
- package/lib/control-client.mjs +9 -1
- package/lib/controlSocket.mjs +86 -0
- package/lib/coordinator.mjs +252 -144
- package/lib/daemon.mjs +1351 -2767
- package/lib/desk.mjs +240 -0
- package/lib/desktop.mjs +178 -74
- package/lib/directLink.mjs +16 -5
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +247 -9
- package/lib/firewall.mjs +9 -9
- package/lib/folders.mjs +20 -16
- package/lib/frames.mjs +2 -3
- package/lib/gitHost.mjs +174 -0
- 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/hookDialects.mjs +298 -0
- package/lib/inference.mjs +26 -8
- package/lib/jobAnswers.mjs +190 -0
- package/lib/landed.mjs +887 -0
- 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/live.mjs +284 -13
- 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 +163 -27
- package/lib/mcpRelay.mjs +1 -1
- package/lib/members.json +29 -2
- package/lib/members.mjs +1 -1
- package/lib/models.mjs +85 -31
- package/lib/museSession.mjs +21 -13
- package/lib/nativeHost.mjs +36 -8
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +50 -5
- package/lib/notify.mjs +7 -5
- package/lib/nudge.mjs +50 -19
- package/lib/ocr.mjs +9 -9
- package/lib/onboard.mjs +26 -20
- package/lib/oneLine.mjs +7 -7
- package/lib/ownMachines.mjs +1223 -140
- package/lib/pairing.mjs +60 -16
- package/lib/paths.mjs +19 -1
- package/lib/peerProcess.mjs +124 -0
- package/lib/personModel.mjs +89 -0
- package/lib/personNotices.mjs +151 -0
- package/lib/phones.mjs +538 -31
- package/lib/placeCommands.mjs +4 -4
- package/lib/places.mjs +400 -12
- 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 +145 -23
- package/lib/record.mjs +128 -0
- 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 +31 -7
- package/lib/runner.mjs +223 -29
- 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 +378 -90
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +57 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/speech.mjs +5 -5
- package/lib/store.mjs +420 -36
- package/lib/stuck.mjs +1 -1
- package/lib/swarm.mjs +304 -37
- package/lib/swarmDevices.mjs +319 -0
- package/lib/swarmMemory.mjs +27 -25
- package/lib/t3.mjs +24 -15
- package/lib/taskCommands.mjs +80 -20
- package/lib/taskRooms.mjs +125 -0
- package/lib/taskRuns.mjs +45 -3
- package/lib/team.json +255 -148
- package/lib/team.mjs +554 -190
- package/lib/threadActions.mjs +315 -0
- package/lib/threadAuthority.mjs +101 -0
- package/lib/threadBriefs.mjs +178 -0
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +209 -50
- package/lib/threadView.mjs +20 -7
- 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 +157 -25
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +12 -11
- package/release.json +220 -0
- package/lib/modelTiers.json +0 -1183
- package/lib/modelTiers.mjs +0 -133
package/lib/team.mjs
CHANGED
|
@@ -1,105 +1,184 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { nameOf } from "./members.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { specialtyName } from "./specialties.mjs";
|
|
4
|
+
import { namedFiles } from "./worktrees.mjs";
|
|
4
5
|
|
|
5
|
-
// How the agents in a thread work as a team (team.json,
|
|
6
|
-
//
|
|
7
|
-
// every round handed the next piece to whichever single agent looked likeliest, and the
|
|
8
|
-
// work while nobody checked it or pulled parallel results together (board,
|
|
9
|
-
//
|
|
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).
|
|
10
11
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
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).
|
|
15
19
|
|
|
16
20
|
export const TEAM = JSON.parse(
|
|
17
21
|
readFileSync(new URL("./team.json", import.meta.url), "utf8")
|
|
18
22
|
);
|
|
19
|
-
const
|
|
20
|
-
export const
|
|
23
|
+
const ROUTE = TEAM.route;
|
|
24
|
+
export const STEP_IDS = ROUTE.map((step) => step.id);
|
|
21
25
|
export const ROLE_IDS = Object.keys(TEAM.roles);
|
|
22
26
|
export const RIGOR_LEVELS = Object.keys(TEAM.rigor);
|
|
27
|
+
const stepOf = (id) => ROUTE.find((step) => step.id === id);
|
|
23
28
|
// Every runner's reported states that end a turn: a question to the person (needs_input) is not the step's end.
|
|
24
29
|
const FINISHED = new Set(["done", "failed", "unknown"]);
|
|
30
|
+
// The most pieces one framer's split is routed as; more read as one list.
|
|
31
|
+
const MOST_PIECES = 4;
|
|
25
32
|
|
|
26
|
-
/**
|
|
27
|
-
export const
|
|
33
|
+
/** The role a step is held as when it asks for this specialty: named by the step and the specialty (team.json). */
|
|
34
|
+
export const roleFor = (step, specialty) =>
|
|
35
|
+
ROLE_IDS.find((role) =>
|
|
36
|
+
specialty ? TEAM.roles[role].steps[step]?.includes(specialty) : false
|
|
37
|
+
) ?? stepOf(step).role;
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The steps a piece's route runs at a rigor: Combine below thorough only when several agents made it. A piece the
|
|
41
|
+
* framer split off has its frame already (its brief), and so does a goal whose makers the person tagged (their words).
|
|
42
|
+
*/
|
|
43
|
+
export const stepsFor = (rigor, { makers, framed }) =>
|
|
44
|
+
STEP_IDS.filter(
|
|
45
|
+
(id) =>
|
|
46
|
+
(TEAM.rigor[rigor].steps.includes(id) ||
|
|
47
|
+
(id === "combine" && (rigor === "thorough" || makers > 1))) &&
|
|
48
|
+
!(framed && id === "frame")
|
|
32
49
|
);
|
|
33
50
|
|
|
51
|
+
// A specialty on the list, else none (the route still runs; the run counts toward no specialty).
|
|
52
|
+
const KNOWN = new Set(
|
|
53
|
+
JSON.parse(
|
|
54
|
+
readFileSync(new URL("./specialties.json", import.meta.url), "utf8")
|
|
55
|
+
).headings.flatMap((heading) => heading.specialties.map(({ id }) => id))
|
|
56
|
+
);
|
|
57
|
+
const knownSpecialty = (id) => (KNOWN.has(String(id)) ? String(id) : null);
|
|
58
|
+
|
|
34
59
|
/**
|
|
35
|
-
* A
|
|
36
|
-
*
|
|
37
|
-
*
|
|
60
|
+
* A route as the round proposed it, kept only where it names known steps and agents of the swarm, with the person's
|
|
61
|
+
* choices over Jev's, step by step: an agent they tagged fills a step (Make, when Jev put it on none: "@codex fix this"
|
|
62
|
+
* puts Codex on Make), a pin holds the step whose specialty it is for unless a tagged agent does, and Jev's pick stands
|
|
63
|
+
* otherwise. The rigor then picks the steps that run. No agent checks or judges what it made, and the framer never
|
|
64
|
+
* judges the piece it framed: a pin that would do so gives way to Jev's pick, and a step left with no one is dropped
|
|
65
|
+
* and the thread says so (`unfilled`).
|
|
38
66
|
*/
|
|
39
|
-
export function validPlan(
|
|
40
|
-
|
|
41
|
-
|
|
67
|
+
export function validPlan(
|
|
68
|
+
proposed,
|
|
69
|
+
{ members, named = [], pins = {}, piece = false }
|
|
70
|
+
) {
|
|
42
71
|
const allowed = new Set(members);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
72
|
+
const rigor = RIGOR_LEVELS.includes(proposed?.rigor)
|
|
73
|
+
? proposed.rigor
|
|
74
|
+
: "standard";
|
|
75
|
+
const split = !piece && Boolean(proposed?.split);
|
|
76
|
+
const given = new Map(
|
|
77
|
+
(Array.isArray(proposed?.steps) ? proposed.steps : [])
|
|
78
|
+
.filter((step) => STEP_IDS.includes(step?.id))
|
|
79
|
+
.map((step) => [
|
|
80
|
+
step.id,
|
|
81
|
+
{
|
|
82
|
+
specialty: knownSpecialty(step.specialty),
|
|
83
|
+
agents: [
|
|
84
|
+
...new Set(
|
|
85
|
+
(step.agents ?? [])
|
|
86
|
+
.map(String)
|
|
87
|
+
.filter((agent) => allowed.has(agent))
|
|
88
|
+
),
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
])
|
|
92
|
+
);
|
|
93
|
+
const tagged = named.filter((agent) => allowed.has(agent));
|
|
94
|
+
const placedByJev = new Set([...given.values()].flatMap((s) => s.agents));
|
|
95
|
+
const unplaced = tagged.filter((agent) => !placedByJev.has(agent));
|
|
96
|
+
const holders = {};
|
|
97
|
+
const pinned = new Set();
|
|
98
|
+
// Whom a step may not go to: a check or judgment never to a maker, a judgment never to the framer.
|
|
99
|
+
const barred = (id) =>
|
|
100
|
+
id === "check"
|
|
101
|
+
? holders.make
|
|
102
|
+
: id === "judge"
|
|
103
|
+
? [...holders.make, ...holders.frame]
|
|
104
|
+
: [];
|
|
105
|
+
const steps = STEP_IDS.map((id) => {
|
|
106
|
+
const step = given.get(id) ?? { specialty: null, agents: [] };
|
|
107
|
+
const taggedHere = step.agents.filter((agent) => tagged.includes(agent));
|
|
108
|
+
const pin = step.specialty ? pins[step.specialty] : null;
|
|
109
|
+
let agents = step.agents;
|
|
110
|
+
if (id === "make" && unplaced.length && !split)
|
|
111
|
+
agents = [...new Set([...taggedHere, ...unplaced])];
|
|
112
|
+
else if (taggedHere.length) agents = taggedHere;
|
|
113
|
+
else if (pin && allowed.has(pin) && !barred(id).includes(pin)) {
|
|
114
|
+
agents = [pin];
|
|
115
|
+
pinned.add(id);
|
|
116
|
+
}
|
|
117
|
+
// Make is never left empty while the person tagged someone.
|
|
118
|
+
if (id === "make" && !agents.length && !split) agents = tagged;
|
|
119
|
+
agents = stepOf(id).together
|
|
120
|
+
? agents.slice(0, TEAM.mostSideBySide)
|
|
121
|
+
: agents.slice(0, 1);
|
|
122
|
+
holders[id] = agents;
|
|
123
|
+
return { id, specialty: step.specialty, agents };
|
|
124
|
+
});
|
|
125
|
+
const makers = holders.make;
|
|
126
|
+
// A tagged maker means the person framed the work themselves, unless they also named who frames it.
|
|
127
|
+
const framedByTag =
|
|
128
|
+
makers.some((agent) => tagged.includes(agent)) &&
|
|
129
|
+
!holders.frame.some((agent) => tagged.includes(agent));
|
|
130
|
+
const running = split
|
|
131
|
+
? ["frame"]
|
|
132
|
+
: stepsFor(rigor, { makers: makers.length, framed: piece || framedByTag });
|
|
133
|
+
const unfilled = [];
|
|
134
|
+
const kept = steps
|
|
135
|
+
.filter((step) => running.includes(step.id))
|
|
136
|
+
.flatMap((step) => {
|
|
137
|
+
const own = step.agents.some((agent) => barred(step.id).includes(agent));
|
|
138
|
+
if (own || !step.agents.length) {
|
|
139
|
+
unfilled.push({ step: step.id, own });
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
return [
|
|
143
|
+
{
|
|
144
|
+
...step,
|
|
145
|
+
role: roleFor(step.id, step.specialty),
|
|
146
|
+
...(pinned.has(step.id) ? { pinned: true } : {}),
|
|
147
|
+
},
|
|
148
|
+
];
|
|
54
149
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
// The author never checks or reviews its own work.
|
|
59
|
-
const builder = roles.builder?.[0];
|
|
60
|
-
for (const role of ["checker", "reviewer"])
|
|
61
|
-
if (builder && roles[role]?.[0] === builder) delete roles[role];
|
|
62
|
-
const plan = {
|
|
63
|
-
shape: proposed.shape,
|
|
64
|
-
rigor: RIGOR_LEVELS.includes(proposed.rigor) ? proposed.rigor : "standard",
|
|
65
|
-
roles,
|
|
66
|
-
};
|
|
67
|
-
// A role of the shape nobody holds because no agent here meets its floor: the thread says so, with who fell short.
|
|
68
|
-
const unfilled = shape.roles
|
|
69
|
-
.filter(
|
|
70
|
-
(role) => !roles[role] && (TEAM.roles[role].floor ?? "any") !== "any"
|
|
71
|
-
)
|
|
72
|
-
.map((role) => ({
|
|
73
|
-
role,
|
|
74
|
-
floor: TEAM.roles[role].floor,
|
|
75
|
-
short: members
|
|
76
|
-
.filter(
|
|
77
|
-
(agent) =>
|
|
78
|
-
!meetsFloor(
|
|
79
|
-
tiers[agent]?.level ?? "unknown",
|
|
80
|
-
TEAM.roles[role].floor
|
|
81
|
-
)
|
|
82
|
-
)
|
|
83
|
-
.map((agent) => ({ agent, level: tiers[agent]?.level ?? "unknown" })),
|
|
84
|
-
}))
|
|
85
|
-
.filter(
|
|
86
|
-
(each) => each.short.length && each.short.length === members.length
|
|
87
|
-
);
|
|
88
|
-
return stepsOf(plan).length ? { ...plan, leftOut, unfilled } : null;
|
|
150
|
+
if (!kept.length) return null;
|
|
151
|
+
if (!split && !kept.some((step) => step.id === "make")) return null;
|
|
152
|
+
return { rigor, split, steps: kept, unfilled };
|
|
89
153
|
}
|
|
90
154
|
|
|
91
|
-
//
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
155
|
+
// The route as the thread says it: "frame: Claude Code (framer, planning and coordination); make: Codex (builder, ...)".
|
|
156
|
+
const lineup = (steps) =>
|
|
157
|
+
steps
|
|
158
|
+
.map(
|
|
159
|
+
(step) =>
|
|
160
|
+
`${step.id}: ${step.agents.map(nameOf).join(" and ")} (${TEAM.roles[step.role].name}${step.specialty ? `, ${specialtyName(step.specialty)}` : ""})`
|
|
161
|
+
)
|
|
162
|
+
.join("; ");
|
|
163
|
+
|
|
164
|
+
// Why a step of the route runs with nobody: the thread's words.
|
|
165
|
+
const unfilledLine = ({ step, own }) =>
|
|
166
|
+
own
|
|
167
|
+
? `No agent here could ${step} this without ${step === "judge" ? "judging" : "checking"} its own work, so it goes without a ${step}.`
|
|
168
|
+
: `No agent here was routed to ${step} it, so it goes without that step.`;
|
|
99
169
|
|
|
100
|
-
// The
|
|
101
|
-
|
|
102
|
-
|
|
170
|
+
// The pieces a framer's report splits a goal into: each on its own line as "Piece:" and its brief (the framer's
|
|
171
|
+
// contract in team.json asks for exactly that form).
|
|
172
|
+
export const piecesIn = (text) =>
|
|
173
|
+
String(text || "")
|
|
174
|
+
.split("\n")
|
|
175
|
+
.map((line) =>
|
|
176
|
+
/^\s*(?:[-*]\s*)?\**piece\b[^:]{0,12}:\**\s*(.+)$/i
|
|
177
|
+
.exec(line)?.[1]
|
|
178
|
+
?.trim()
|
|
179
|
+
)
|
|
180
|
+
.filter(Boolean)
|
|
181
|
+
.slice(0, MOST_PIECES);
|
|
103
182
|
|
|
104
183
|
// How old a note is, in the words a brief uses.
|
|
105
184
|
const age = (iso) => {
|
|
@@ -107,70 +186,127 @@ const age = (iso) => {
|
|
|
107
186
|
return days < 1 ? "today" : days === 1 ? "yesterday" : `${days} days ago`;
|
|
108
187
|
};
|
|
109
188
|
const NOTE_CHARS = 600;
|
|
189
|
+
const BRIEF_CHARS = 1_000;
|
|
110
190
|
|
|
111
191
|
export function createTeam({ store, log = () => {} }) {
|
|
112
192
|
const key = (goalId) => `team:${goalId}`;
|
|
193
|
+
// A plan from before routes (a shape and roles) is no plan: the thread's next message to the swarm routes it anew.
|
|
113
194
|
const read = (goalId) => {
|
|
114
195
|
try {
|
|
115
|
-
|
|
196
|
+
const kept = JSON.parse(store.meta(key(goalId)) || "null");
|
|
197
|
+
return Array.isArray(kept?.pieces) ? kept : null;
|
|
116
198
|
} catch {
|
|
117
199
|
return null;
|
|
118
200
|
}
|
|
119
201
|
};
|
|
120
202
|
const write = (goalId, plan) => store.meta(key(goalId), JSON.stringify(plan));
|
|
121
203
|
const now = () => new Date().toISOString();
|
|
204
|
+
const pieceOf = (current) => current.pieces[current.piece];
|
|
205
|
+
const stepsOfNow = (current) => pieceOf(current)?.steps ?? [];
|
|
206
|
+
|
|
207
|
+
// Where each step began and who held it, so a run is marked with the step it worked.
|
|
208
|
+
const started = (current, step) => {
|
|
209
|
+
const entry = stepsOfNow(current).find((s) => s.id === step);
|
|
210
|
+
return entry
|
|
211
|
+
? [
|
|
212
|
+
...(current.history ?? []),
|
|
213
|
+
{
|
|
214
|
+
piece: current.piece,
|
|
215
|
+
step,
|
|
216
|
+
specialty: entry.specialty,
|
|
217
|
+
agents: entry.agents,
|
|
218
|
+
at: now(),
|
|
219
|
+
},
|
|
220
|
+
].slice(-40)
|
|
221
|
+
: (current.history ?? []);
|
|
222
|
+
};
|
|
122
223
|
|
|
123
|
-
|
|
224
|
+
// Every finished run of the thread not yet marked takes the step its agent held when it reported: a run the person's
|
|
225
|
+
// tag started before the route began counts toward the step its agent was routed to, and a checker an agent asked by
|
|
226
|
+
// name while it worked counts as the check the route caught up to.
|
|
227
|
+
const markRuns = (current, runs) => {
|
|
228
|
+
const history = current.history ?? [];
|
|
229
|
+
for (const run of runs) {
|
|
230
|
+
if (run.step || !run.reported_at) continue;
|
|
231
|
+
const entry = history.findLast(
|
|
232
|
+
(each) =>
|
|
233
|
+
each.at < run.reported_at && each.agents.includes(run.target_agent)
|
|
234
|
+
);
|
|
235
|
+
if (!entry) continue;
|
|
236
|
+
store.setRunStep(run.id, entry);
|
|
237
|
+
run.step = entry.step;
|
|
238
|
+
run.specialty = entry.specialty;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/** The thread's plan, or null when it has none (a thread from before routes, or one not yet triaged). */
|
|
124
243
|
const plan = (goalId) => read(goalId);
|
|
125
244
|
|
|
126
|
-
/** The roles an agent holds in the thread. */
|
|
245
|
+
/** The roles an agent holds in the thread's piece now. */
|
|
127
246
|
const rolesOf = (goalId, agent) => {
|
|
128
247
|
const current = read(goalId);
|
|
129
248
|
return current
|
|
130
|
-
?
|
|
131
|
-
.filter((
|
|
132
|
-
.map((
|
|
249
|
+
? stepsOfNow(current)
|
|
250
|
+
.filter((step) => step.agents.includes(agent))
|
|
251
|
+
.map((step) => step.role)
|
|
133
252
|
: [];
|
|
134
253
|
};
|
|
135
254
|
|
|
136
|
-
/**
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.
|
|
255
|
+
/** The step of the route the agent was last given in the thread, or null in a thread without a route. */
|
|
256
|
+
const stepHeld = (goalId, agent) =>
|
|
257
|
+
read(goalId)?.history?.findLast((entry) => entry.agents.includes(agent))
|
|
258
|
+
?.step ?? null;
|
|
259
|
+
|
|
260
|
+
/** The step of the piece now that the agent holds because the person pinned it for the step's specialty, if any. */
|
|
261
|
+
const pinnedStep = (goalId, agent) => {
|
|
262
|
+
const current = read(goalId);
|
|
263
|
+
const step = current
|
|
264
|
+
? stepsOfNow(current).find((s) => s.id === current.step)
|
|
265
|
+
: null;
|
|
266
|
+
return step?.pinned && step.agents.includes(agent) ? step : null;
|
|
267
|
+
};
|
|
146
268
|
|
|
147
269
|
/**
|
|
148
|
-
* Keep the
|
|
270
|
+
* Keep the route the round proposed, starting at its first step, and say in the thread who holds what. `named`: the
|
|
271
|
+
* agents the person tagged in the message; `pins`: specialty -> the agent the person pinned for it. Returns the plan
|
|
149
272
|
* kept, or null when the proposal named nothing usable.
|
|
150
273
|
*/
|
|
151
|
-
const set = (
|
|
152
|
-
|
|
274
|
+
const set = (
|
|
275
|
+
goalId,
|
|
276
|
+
proposed,
|
|
277
|
+
{ members, named = [], pins = {}, by, post }
|
|
278
|
+
) => {
|
|
279
|
+
const checked = validPlan(proposed, { members, named, pins });
|
|
153
280
|
if (!checked) {
|
|
154
|
-
log(`
|
|
281
|
+
log(`route for ${goalId} not kept: ${JSON.stringify(proposed)}`);
|
|
155
282
|
return null;
|
|
156
283
|
}
|
|
157
|
-
const {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
284
|
+
const { unfilled, steps, rigor, split } = checked;
|
|
285
|
+
const fresh = {
|
|
286
|
+
version: 2,
|
|
287
|
+
rigor,
|
|
288
|
+
split,
|
|
289
|
+
pieces: [{ brief: null, rigor, steps }],
|
|
290
|
+
piece: 0,
|
|
291
|
+
step: steps[0].id,
|
|
162
292
|
sendsBack: 0,
|
|
163
293
|
by,
|
|
164
294
|
at: now(),
|
|
165
295
|
};
|
|
296
|
+
const kept = {
|
|
297
|
+
...fresh,
|
|
298
|
+
stepAt: now(),
|
|
299
|
+
history: started(fresh, steps[0].id),
|
|
300
|
+
};
|
|
166
301
|
write(goalId, kept);
|
|
167
302
|
post?.(
|
|
168
303
|
[
|
|
169
|
-
`The
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
304
|
+
`The route for this thread (${rigor}): ${lineup(steps)}.`,
|
|
305
|
+
...(split
|
|
306
|
+
? [
|
|
307
|
+
"The framer splits it into pieces, and each piece is routed when it starts.",
|
|
308
|
+
]
|
|
309
|
+
: []),
|
|
174
310
|
...unfilled.map(unfilledLine),
|
|
175
311
|
].join(" ")
|
|
176
312
|
);
|
|
@@ -178,35 +314,150 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
178
314
|
};
|
|
179
315
|
|
|
180
316
|
/**
|
|
181
|
-
*
|
|
182
|
-
* check
|
|
317
|
+
* The next piece the framer split off, routed as the round proposed: it starts at its first step, and the thread says
|
|
318
|
+
* who holds what. A check that passed the piece before is kept with the commit it saw.
|
|
319
|
+
*/
|
|
320
|
+
const routePiece = (
|
|
321
|
+
goalId,
|
|
322
|
+
proposed,
|
|
323
|
+
{ members, named = [], pins = {}, outcome = null, head = null, post }
|
|
324
|
+
) => {
|
|
325
|
+
const current = read(goalId);
|
|
326
|
+
const index = current ? current.piece + 1 : -1;
|
|
327
|
+
if (!current || !current.pieces[index]) return null;
|
|
328
|
+
const checked = validPlan(proposed, { members, named, pins, piece: true });
|
|
329
|
+
if (!checked) {
|
|
330
|
+
log(`route for piece ${index + 1} of ${goalId} not kept`);
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
judge(goalId, current, outcome, head);
|
|
334
|
+
const after = read(goalId);
|
|
335
|
+
const pieces = after.pieces.map((each, at) =>
|
|
336
|
+
at === index
|
|
337
|
+
? { ...each, rigor: checked.rigor, steps: checked.steps }
|
|
338
|
+
: each
|
|
339
|
+
);
|
|
340
|
+
const moved = {
|
|
341
|
+
...after,
|
|
342
|
+
pieces,
|
|
343
|
+
piece: index,
|
|
344
|
+
step: checked.steps[0].id,
|
|
345
|
+
stepAt: now(),
|
|
346
|
+
sendsBack: 0,
|
|
347
|
+
};
|
|
348
|
+
moved.history = started(moved, moved.step);
|
|
349
|
+
write(goalId, moved);
|
|
350
|
+
// The framing piece is not one of the person's pieces: the count is of the split's.
|
|
351
|
+
const of = pieces.length - 1;
|
|
352
|
+
post?.(
|
|
353
|
+
[
|
|
354
|
+
`Piece ${index} of ${of} (${checked.rigor}): ${lineup(checked.steps)}.`,
|
|
355
|
+
...checked.unfilled.map(unfilledLine),
|
|
356
|
+
].join(" ")
|
|
357
|
+
);
|
|
358
|
+
return moved;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* A judged step's outcome: kept with the commit its check saw (`head`), so a later change makes it stale, and written
|
|
363
|
+
* on the runs made since the piece's make step last began, with each checker's model, for the record.
|
|
364
|
+
*/
|
|
365
|
+
const judge = (goalId, current, outcome, head) => {
|
|
366
|
+
const step = stepsOfNow(current).find((s) => s.id === current.step);
|
|
367
|
+
if (!step || !stepOf(step.id).judges) return;
|
|
368
|
+
if (outcome !== "passed" && outcome !== "sent_back") return;
|
|
369
|
+
const runs = store.threadRuns(goalId);
|
|
370
|
+
markRuns(current, runs);
|
|
371
|
+
const latest = (agent) =>
|
|
372
|
+
runs.findLast(
|
|
373
|
+
(run) => run.target_agent === agent && run.step === current.step
|
|
374
|
+
);
|
|
375
|
+
const by = step.agents.map((agent) => ({
|
|
376
|
+
agent,
|
|
377
|
+
model: latest(agent)?.run_model?.model ?? null,
|
|
378
|
+
}));
|
|
379
|
+
// The runs this judgment is of: the piece's make runs no earlier step judged. A run a tag started before the route
|
|
380
|
+
// began is the piece's too; a run sent back keeps that outcome, and the run made again takes this one.
|
|
381
|
+
const pieceAt =
|
|
382
|
+
(current.history ?? []).find((entry) => entry.piece === current.piece)
|
|
383
|
+
?.at ?? "";
|
|
384
|
+
for (const run of runs)
|
|
385
|
+
if (
|
|
386
|
+
run.step === "make" &&
|
|
387
|
+
!run.checked &&
|
|
388
|
+
(run.reported_at ?? "") > pieceAt &&
|
|
389
|
+
FINISHED.has(run.status)
|
|
390
|
+
)
|
|
391
|
+
store.setRunChecked(run.id, {
|
|
392
|
+
outcome,
|
|
393
|
+
step: current.step,
|
|
394
|
+
by,
|
|
395
|
+
at: now(),
|
|
396
|
+
});
|
|
397
|
+
write(goalId, {
|
|
398
|
+
...current,
|
|
399
|
+
lastCheck: { step: current.step, outcome, head, at: now() },
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Move the thread to a step of its piece's route (an id, "done"). A judged step's outcome is kept (judge); a
|
|
405
|
+
* send-back is counted.
|
|
183
406
|
*/
|
|
184
407
|
const moveTo = (goalId, step, { outcome = null, head = null } = {}) => {
|
|
185
408
|
const current = read(goalId);
|
|
186
409
|
if (!current) return null;
|
|
187
410
|
const known =
|
|
188
|
-
step === "done" ||
|
|
411
|
+
step === "done" || stepsOfNow(current).some((s) => s.id === step);
|
|
189
412
|
if (!known) return current;
|
|
190
|
-
|
|
413
|
+
judge(goalId, current, outcome, head);
|
|
414
|
+
const after = read(goalId);
|
|
191
415
|
const moved = {
|
|
192
|
-
...
|
|
416
|
+
...after,
|
|
193
417
|
step,
|
|
194
418
|
stepAt: now(),
|
|
195
|
-
sendsBack:
|
|
196
|
-
...(judged && (outcome === "passed" || outcome === "sent_back")
|
|
197
|
-
? { lastCheck: { step: current.step, outcome, head, at: now() } }
|
|
198
|
-
: {}),
|
|
419
|
+
sendsBack: after.sendsBack + (outcome === "sent_back" ? 1 : 0),
|
|
199
420
|
};
|
|
421
|
+
moved.history = started(moved, step);
|
|
200
422
|
write(goalId, moved);
|
|
201
423
|
return moved;
|
|
202
424
|
};
|
|
203
425
|
|
|
204
|
-
/**
|
|
205
|
-
const
|
|
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
|
+
|
|
452
|
+
/** Whether the thread's route checks its work: one of its pieces has a step that judges. */
|
|
453
|
+
const checksWork = (current) =>
|
|
454
|
+
current.pieces.some((piece) =>
|
|
455
|
+
piece.steps.some((step) => stepOf(step.id).judges)
|
|
456
|
+
);
|
|
206
457
|
|
|
207
458
|
/**
|
|
208
|
-
* Whether the
|
|
209
|
-
* with no branch of its own, where the pass alone counts). True for a
|
|
459
|
+
* Whether the route's last check passed on the code as it is now (`head`, the thread's branch; null for a thread
|
|
460
|
+
* with no branch of its own, where the pass alone counts). True for a route that does not check its work.
|
|
210
461
|
*/
|
|
211
462
|
const checkedNow = (goalId, head = null) => {
|
|
212
463
|
const current = read(goalId);
|
|
@@ -219,22 +470,23 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
219
470
|
|
|
220
471
|
/**
|
|
221
472
|
* Agents were just given work outside the route (the person wrote to them, or a free round picked one): the thread
|
|
222
|
-
* moves to the earliest step one of them holds, so the route goes on from there.
|
|
473
|
+
* moves to the earliest step of the piece one of them holds, so the route goes on from there.
|
|
223
474
|
*/
|
|
224
475
|
const acted = (goalId, agents) => {
|
|
225
476
|
const current = read(goalId);
|
|
226
477
|
if (!current || !agents.length) return;
|
|
227
|
-
const step =
|
|
228
|
-
|
|
478
|
+
const step = stepsOfNow(current).find((s) =>
|
|
479
|
+
s.agents.some((holder) => agents.includes(holder))
|
|
229
480
|
);
|
|
230
481
|
if (step && step.id !== current.step) moveTo(goalId, step.id);
|
|
231
|
-
else if (step)
|
|
482
|
+
else if (step)
|
|
483
|
+
write(goalId, {
|
|
484
|
+
...current,
|
|
485
|
+
stepAt: now(),
|
|
486
|
+
history: started(current, step.id),
|
|
487
|
+
});
|
|
232
488
|
};
|
|
233
489
|
|
|
234
|
-
/**
|
|
235
|
-
* What the round reads about the team: the plan, the step the thread is at, whether everyone on that step has reported
|
|
236
|
-
* since it began, and where the work may go next. `runs` are the thread's runs (store.threadRuns).
|
|
237
|
-
*/
|
|
238
490
|
// When every holder of a step reported after `since`: the last of their reports, else null.
|
|
239
491
|
const reportedAll = (holders, runs, since) => {
|
|
240
492
|
const last = holders.map(
|
|
@@ -254,33 +506,109 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
254
506
|
};
|
|
255
507
|
|
|
256
508
|
/**
|
|
257
|
-
* The route as the work actually went: agents hand each other work by name as well as through the route (
|
|
258
|
-
* 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
|
|
259
511
|
* whose next step's agents have reported since moves on, up to a step that judges, whose outcome is the round's.
|
|
260
512
|
*/
|
|
261
513
|
const catchUp = (goalId, current, runs) => {
|
|
262
|
-
const steps =
|
|
514
|
+
const steps = stepsOfNow(current);
|
|
263
515
|
let caught = current;
|
|
264
516
|
for (;;) {
|
|
265
517
|
const at = steps.findIndex((s) => s.id === caught.step);
|
|
266
518
|
const step = steps[at];
|
|
267
519
|
const next = steps[at + 1];
|
|
268
|
-
if (!step || step.judges || !next) break;
|
|
269
|
-
const done = reportedAll(
|
|
270
|
-
if (!done || !reportedAll(
|
|
520
|
+
if (!step || stepOf(step.id).judges || !next) break;
|
|
521
|
+
const done = reportedAll(step.agents, runs, caught.stepAt);
|
|
522
|
+
if (!done || !reportedAll(next.agents, runs, done)) break;
|
|
271
523
|
caught = { ...caught, step: next.id, stepAt: done };
|
|
524
|
+
caught.history = [
|
|
525
|
+
...(caught.history ?? []),
|
|
526
|
+
{
|
|
527
|
+
piece: caught.piece,
|
|
528
|
+
step: next.id,
|
|
529
|
+
specialty: next.specialty,
|
|
530
|
+
agents: next.agents,
|
|
531
|
+
at: done,
|
|
532
|
+
},
|
|
533
|
+
];
|
|
272
534
|
}
|
|
273
535
|
if (caught !== current) write(goalId, caught);
|
|
274
536
|
return caught;
|
|
275
537
|
};
|
|
276
538
|
|
|
539
|
+
// The framer's report on a goal it split: its runs' results since its step began, else its posts in the thread.
|
|
540
|
+
const framerSaid = (goalId, current, runs) => {
|
|
541
|
+
const framers = stepsOfNow(current).find((s) => s.id === "frame")?.agents;
|
|
542
|
+
const since = current.stepAt;
|
|
543
|
+
const results = runs
|
|
544
|
+
.filter(
|
|
545
|
+
(run) =>
|
|
546
|
+
framers?.includes(run.target_agent) && (run.reported_at ?? "") > since
|
|
547
|
+
)
|
|
548
|
+
.map((run) => String(run.result || ""));
|
|
549
|
+
const posts = store
|
|
550
|
+
.roomPosts(goalId, 0, 500)
|
|
551
|
+
.filter(
|
|
552
|
+
(post) => framers?.includes(post.author) && post.created_at > since
|
|
553
|
+
)
|
|
554
|
+
.map((post) => post.text);
|
|
555
|
+
// Its result, else its posts: an agent's result is also posted, and its pieces are read once.
|
|
556
|
+
return (
|
|
557
|
+
results.some((text) => piecesIn(text).length) ? results : posts
|
|
558
|
+
).join("\n");
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
// A split goal's frame is done: the pieces its framer gave are kept, to be routed one after another. A framer that gave
|
|
562
|
+
// none leaves one piece, the goal as it framed it.
|
|
563
|
+
const splitInto = (goalId, current, runs) => {
|
|
564
|
+
if (!current.split || current.pieces.length > 1) return current;
|
|
565
|
+
const briefs = piecesIn(framerSaid(goalId, current, runs));
|
|
566
|
+
const pieces = [
|
|
567
|
+
...current.pieces,
|
|
568
|
+
...(briefs.length ? briefs : [null]).map((brief) => ({
|
|
569
|
+
brief: brief ? brief.slice(0, BRIEF_CHARS) : null,
|
|
570
|
+
rigor: null,
|
|
571
|
+
steps: [],
|
|
572
|
+
})),
|
|
573
|
+
];
|
|
574
|
+
const kept = { ...current, pieces };
|
|
575
|
+
write(goalId, kept);
|
|
576
|
+
return kept;
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* What the round reads about the route: the piece and its steps, the step the thread is at, whether everyone on it
|
|
581
|
+
* has reported since it began, and where the work may go next: a step of the piece, "done", "stop" (sent back as
|
|
582
|
+
* often as the route allows), or "piece" (the next piece, which the round routes at once: `nextPiece`).
|
|
583
|
+
* `runs` are the thread's runs (store.threadRuns).
|
|
584
|
+
*/
|
|
277
585
|
const roundView = (goalId, runs, { head = null } = {}) => {
|
|
278
586
|
const kept = read(goalId);
|
|
279
587
|
if (!kept) return null;
|
|
280
|
-
|
|
281
|
-
|
|
588
|
+
markRuns(kept, runs);
|
|
589
|
+
let current = catchUp(goalId, kept, runs);
|
|
590
|
+
const steps = stepsOfNow(current);
|
|
591
|
+
const piece = pieceOf(current);
|
|
592
|
+
const base = {
|
|
593
|
+
rigor: piece.rigor ?? current.rigor,
|
|
594
|
+
piece:
|
|
595
|
+
current.piece > 0
|
|
596
|
+
? {
|
|
597
|
+
number: current.piece,
|
|
598
|
+
of: current.pieces.length - 1,
|
|
599
|
+
brief: piece.brief,
|
|
600
|
+
}
|
|
601
|
+
: null,
|
|
602
|
+
steps: steps.map(({ id, specialty, role, agents }) => ({
|
|
603
|
+
id,
|
|
604
|
+
specialty,
|
|
605
|
+
role,
|
|
606
|
+
agents,
|
|
607
|
+
})),
|
|
608
|
+
sendsBack: current.sendsBack,
|
|
609
|
+
};
|
|
282
610
|
// The route is done but the code changed after its last check passed: the work goes to the check again.
|
|
283
|
-
const firstJudge = steps.findIndex((s) => s.judges);
|
|
611
|
+
const firstJudge = steps.findIndex((s) => stepOf(s.id).judges);
|
|
284
612
|
const recheck =
|
|
285
613
|
current.step === "done" &&
|
|
286
614
|
firstJudge > 0 &&
|
|
@@ -289,41 +617,31 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
289
617
|
Boolean(current.lastCheck.head) &&
|
|
290
618
|
current.lastCheck.head !== head;
|
|
291
619
|
if (recheck) {
|
|
292
|
-
const [made,
|
|
620
|
+
const [made, judged] = [steps[firstJudge - 1], steps[firstJudge]];
|
|
293
621
|
return {
|
|
294
|
-
|
|
295
|
-
rigor: current.rigor,
|
|
296
|
-
roles: current.roles,
|
|
297
|
-
sendsBack: current.sendsBack,
|
|
622
|
+
...base,
|
|
298
623
|
step: {
|
|
299
624
|
id: made.id,
|
|
300
625
|
role: made.role,
|
|
301
|
-
|
|
626
|
+
specialty: made.specialty,
|
|
627
|
+
agents: made.agents,
|
|
302
628
|
judges: false,
|
|
303
629
|
finished: true,
|
|
304
630
|
},
|
|
305
631
|
exits: [
|
|
306
632
|
{
|
|
307
633
|
outcome: "done",
|
|
308
|
-
step:
|
|
309
|
-
role:
|
|
310
|
-
agents:
|
|
634
|
+
step: judged.id,
|
|
635
|
+
role: judged.role,
|
|
636
|
+
agents: judged.agents,
|
|
311
637
|
},
|
|
312
638
|
],
|
|
313
639
|
};
|
|
314
640
|
}
|
|
315
641
|
const at = steps.findIndex((s) => s.id === current.step);
|
|
316
|
-
const view = {
|
|
317
|
-
shape: current.shape,
|
|
318
|
-
rigor: current.rigor,
|
|
319
|
-
roles: current.roles,
|
|
320
|
-
sendsBack: current.sendsBack,
|
|
321
|
-
step: null,
|
|
322
|
-
exits: [],
|
|
323
|
-
};
|
|
642
|
+
const view = { ...base, step: null, exits: [] };
|
|
324
643
|
if (at === -1) return view;
|
|
325
644
|
const step = steps[at];
|
|
326
|
-
const holders = current.roles[step.role];
|
|
327
645
|
const reportedSince = (agent) =>
|
|
328
646
|
runs.some(
|
|
329
647
|
(run) =>
|
|
@@ -331,23 +649,35 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
331
649
|
FINISHED.has(run.status) &&
|
|
332
650
|
(run.reported_at ?? "") > current.stepAt
|
|
333
651
|
);
|
|
334
|
-
const finished =
|
|
652
|
+
const finished = step.agents.every(reportedSince);
|
|
653
|
+
const judges = Boolean(stepOf(step.id).judges);
|
|
335
654
|
view.step = {
|
|
336
655
|
id: step.id,
|
|
337
656
|
role: step.role,
|
|
338
|
-
|
|
339
|
-
|
|
657
|
+
specialty: step.specialty,
|
|
658
|
+
agents: step.agents,
|
|
659
|
+
judges,
|
|
340
660
|
finished,
|
|
341
661
|
};
|
|
342
662
|
if (!finished) return view;
|
|
663
|
+
if (!steps[at + 1]) current = splitInto(goalId, current, runs);
|
|
343
664
|
const following = steps[at + 1];
|
|
665
|
+
const nextPiece = current.pieces[current.piece + 1];
|
|
666
|
+
if (!following && nextPiece)
|
|
667
|
+
view.nextPiece = {
|
|
668
|
+
number: current.piece + 1,
|
|
669
|
+
of: current.pieces.length - 1,
|
|
670
|
+
brief: nextPiece.brief,
|
|
671
|
+
};
|
|
344
672
|
const toStep = (s, outcome) =>
|
|
345
673
|
s
|
|
346
|
-
? { outcome, step: s.id, role: s.role, agents:
|
|
347
|
-
:
|
|
348
|
-
|
|
674
|
+
? { outcome, step: s.id, role: s.role, agents: s.agents }
|
|
675
|
+
: nextPiece
|
|
676
|
+
? { outcome, step: "piece", role: null, agents: [] }
|
|
677
|
+
: { outcome, step: "done", role: null, agents: [] };
|
|
678
|
+
if (!judges) view.exits = [toStep(following, "done")];
|
|
349
679
|
else {
|
|
350
|
-
const back = steps.find((s) => s.id === step.sendBack);
|
|
680
|
+
const back = steps.find((s) => s.id === stepOf(step.id).sendBack);
|
|
351
681
|
view.exits = [
|
|
352
682
|
toStep(following, "passed"),
|
|
353
683
|
back && current.sendsBack < TEAM.sendBackLimit
|
|
@@ -392,52 +722,82 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
392
722
|
`${nameOf(note.agent)}, ${age(note.created_at)} (note ${note.id.slice(0, 8)}, unchecked: verify before relying on it): ${note.text}, because ${note.reason}`
|
|
393
723
|
);
|
|
394
724
|
|
|
395
|
-
|
|
396
|
-
const
|
|
725
|
+
// What a step's holder is told beyond its role's contract: the framer whether to split, a maker who checks its work.
|
|
726
|
+
const stepNote = (current, step) => {
|
|
727
|
+
const steps = stepsOfNow(current);
|
|
728
|
+
if (step.id === "frame")
|
|
729
|
+
return current.split && current.piece === 0
|
|
730
|
+
? 'This goal is to be split: give each piece on its own line as "Piece:" followed by its brief, in the order they should run. Each piece is routed to its agents when it starts.'
|
|
731
|
+
: "This is one piece: say what it is and what good looks like; do not split it.";
|
|
732
|
+
if (step.id !== "make") return null;
|
|
733
|
+
return steps.some((s) => s.id === "check")
|
|
734
|
+
? "Another agent checks your work after you: test it yourself as well, and say what you ran."
|
|
735
|
+
: "No other agent checks this at this rigor: test your own work before you report, and say what you ran.";
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
// A check or judgment is of the change as committed on the thread's branch: one git would not commit (threadRuns.mjs)
|
|
739
|
+
// is said to whoever judges next, so it is not passed as made.
|
|
740
|
+
const uncommittedNote = (goalId, step) => {
|
|
741
|
+
if (!stepOf(step.id).judges) return null;
|
|
742
|
+
let left = null;
|
|
743
|
+
try {
|
|
744
|
+
left = JSON.parse(store.meta(`uncommitted:${goalId}`) || "null");
|
|
745
|
+
} catch {}
|
|
746
|
+
if (!left?.files?.length) return null;
|
|
747
|
+
return `Not made yet: ${nameOf(left.agent)}'s change is not committed on the thread's branch (${namedFiles(left.files)} still uncommitted). Check the change as committed, and send back work that is not.`;
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
/** The brief's section on the route, for an agent woken in a thread with one. Every holder gets the same brief. */
|
|
751
|
+
const brief = (goalId, agent) => {
|
|
397
752
|
const current = read(goalId);
|
|
398
753
|
if (!current) return "";
|
|
399
|
-
const steps =
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const mine =
|
|
403
|
-
(
|
|
404
|
-
|
|
754
|
+
const steps = stepsOfNow(current);
|
|
755
|
+
const piece = pieceOf(current);
|
|
756
|
+
// The step the agent acts in now comes first: the thread's current step, when it holds several.
|
|
757
|
+
const mine = steps
|
|
758
|
+
.filter((step) => step.agents.includes(agent))
|
|
759
|
+
.sort(
|
|
760
|
+
(a, b) => Number(b.id === current.step) - Number(a.id === current.step)
|
|
761
|
+
);
|
|
762
|
+
const rigor = piece.rigor ?? current.rigor;
|
|
405
763
|
const lines = [
|
|
406
|
-
`The
|
|
407
|
-
|
|
764
|
+
`The route${current.piece > 0 ? ` for piece ${current.piece} of ${current.pieces.length - 1}` : ""} (${rigor}): ${lineup(steps)}.`,
|
|
765
|
+
...(current.piece > 0 && piece.brief
|
|
766
|
+
? [`This piece, as the framer gave it: ${piece.brief}`]
|
|
767
|
+
: []),
|
|
768
|
+
`How careful this work must be: ${rigor}. ${TEAM.rigor[rigor].says}`,
|
|
408
769
|
];
|
|
409
770
|
const folder = store.getTask(goalId)?.goal?.workspace ?? null;
|
|
410
771
|
const learned = [];
|
|
411
|
-
for (const [index,
|
|
412
|
-
const contract = TEAM.roles[role];
|
|
772
|
+
for (const [index, step] of mine.entries()) {
|
|
773
|
+
const contract = TEAM.roles[step.role];
|
|
413
774
|
if (index > 0) {
|
|
414
|
-
lines.push(
|
|
775
|
+
lines.push(
|
|
776
|
+
`You are also its ${contract.name}, at the ${step.id} step.`
|
|
777
|
+
);
|
|
415
778
|
continue;
|
|
416
779
|
}
|
|
417
|
-
learned.push(...notesFor(role, folder));
|
|
418
|
-
const
|
|
419
|
-
const next = steps[at + 1];
|
|
780
|
+
learned.push(...notesFor(step.role, folder));
|
|
781
|
+
const next = steps[steps.indexOf(step) + 1];
|
|
420
782
|
lines.push(
|
|
421
|
-
`Your role now: ${contract.name}. ${contract.owns}`,
|
|
783
|
+
`Your role now: ${contract.name}${step.specialty ? `, for ${specialtyName(step.specialty)}` : ""}. ${contract.owns}`,
|
|
422
784
|
`Never: ${contract.never}`,
|
|
423
785
|
`Bring back: ${contract.bringsBack}`,
|
|
786
|
+
...[stepNote(current, step), uncommittedNote(goalId, step)].filter(
|
|
787
|
+
Boolean
|
|
788
|
+
),
|
|
424
789
|
next
|
|
425
|
-
? `Next on the
|
|
426
|
-
: "After you, the thread's coordinator reads your result and decides
|
|
790
|
+
? `Next on the route: ${next.agents.map(nameOf).join(" and ")} (${TEAM.roles[next.role].name}).`
|
|
791
|
+
: "After you, the thread's coordinator reads your result and decides what comes next. It is not an agent: do not address it, or Harness, to hand the work back."
|
|
427
792
|
);
|
|
428
793
|
}
|
|
429
794
|
if (!mine.length)
|
|
430
795
|
lines.push(
|
|
431
|
-
"You hold no
|
|
432
|
-
);
|
|
433
|
-
// Agents on top-tier models get the intent and find the route; others do their best work on smaller checked steps.
|
|
434
|
-
if (!goalLevel(tier))
|
|
435
|
-
lines.push(
|
|
436
|
-
"Work in small steps: do one part, check that it works, then the next, and say which parts are done."
|
|
796
|
+
"You hold no step on this route: do what you were asked and hand anything else to the agent whose step it is."
|
|
437
797
|
);
|
|
438
798
|
if (mine.length)
|
|
439
799
|
lines.push(
|
|
440
|
-
`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), add it with swarm_memory (remember, why, thread ${goalId}): what you learned and why it holds.`
|
|
800
|
+
`Before you stop: if you learned something about this folder that the next ${TEAM.roles[mine[0].role].name} here should know (a trap, a check that matters, how the code really works), add it with swarm_memory (remember, why, thread ${goalId}): what you learned and why it holds.`
|
|
441
801
|
);
|
|
442
802
|
return [
|
|
443
803
|
"Your part on the team:",
|
|
@@ -455,7 +815,9 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
455
815
|
|
|
456
816
|
return {
|
|
457
817
|
plan,
|
|
818
|
+
sendBack,
|
|
458
819
|
set,
|
|
820
|
+
routePiece,
|
|
459
821
|
moveTo,
|
|
460
822
|
acted,
|
|
461
823
|
roundView,
|
|
@@ -463,5 +825,7 @@ export function createTeam({ store, log = () => {} }) {
|
|
|
463
825
|
learn,
|
|
464
826
|
brief,
|
|
465
827
|
rolesOf,
|
|
828
|
+
stepHeld,
|
|
829
|
+
pinnedStep,
|
|
466
830
|
};
|
|
467
831
|
}
|