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/lib/daemon.mjs CHANGED
@@ -64,11 +64,12 @@ import {
64
64
  import { createStuck, STUCK_THRESHOLDS } from "./stuck.mjs";
65
65
  import { createLoopBackstop } from "./loopBackstop.mjs";
66
66
  import {
67
+ DISPATCHER,
67
68
  ASKED_BY_TASK,
68
69
  CLOUD_HOMED,
69
70
  TARGETS,
70
- aboutOf,
71
71
  member,
72
+ aboutOf,
72
73
  nameOf,
73
74
  } from "./members.mjs";
74
75
  import { fingerprint } from "./sealed.mjs";
@@ -169,6 +170,7 @@ import { createThreadActions, inRoom, mentionsIn } from "./threadActions.mjs";
169
170
  import { createThreadAuthority } from "./threadAuthority.mjs";
170
171
  import { createDispatches } from "./dispatches.mjs";
171
172
  import { createCapabilityCheck } from "./capabilityCheck.mjs";
173
+ import { createDispatcher } from "./dispatcher.mjs";
172
174
  import { createThreadBriefs } from "./threadBriefs.mjs";
173
175
 
174
176
  // claude-mem 13.35.0, scratch worker with 3,000 observations, on the same machine: the whole lookup (git calls,
@@ -1026,7 +1028,20 @@ export async function startDaemon() {
1026
1028
  const handoffs = createHandoffs({
1027
1029
  store,
1028
1030
  wakeAgain: (agent, taskId) => actions.wakeAgain(agent, taskId),
1029
- moveTo: (task, to) => actions.moveHandoff(task, to),
1031
+ giveBack: (task) => {
1032
+ const thread = store.getTask(task.parent_id);
1033
+ if (thread?.kind !== "goal" || thread.status !== "open") return false;
1034
+ // Taken back first, so a wake that lands later cannot start the same work twice.
1035
+ store.removeTask(task.id);
1036
+ notifyBoard(store.getTask(task.id));
1037
+ // Jev passes over the agent in this thread for a while (coordinator.mjs failedHereLately) and places it again.
1038
+ store.meta(
1039
+ `job-failed:${thread.id}:${task.target_agent}`,
1040
+ new Date().toISOString()
1041
+ );
1042
+ coordinator.resumed(thread.id);
1043
+ return true;
1044
+ },
1030
1045
  say: (threadId, text) => {
1031
1046
  const thread = store.getTask(threadId);
1032
1047
  if (thread) actions.say(thread, text);
@@ -1275,23 +1290,42 @@ export async function startDaemon() {
1275
1290
  ? threadRuns.wake(goalId, agent, reason, {
1276
1291
  review,
1277
1292
  routeMachine,
1278
- go: threadAuthority.personsGo("harness", agent),
1293
+ // The person's words whole go into the agent's brief, not only the line that says why it was woken.
1294
+ words,
1295
+ asker: DISPATCHER,
1296
+ go: threadAuthority.personsGo(DISPATCHER, agent),
1279
1297
  })
1280
- : actions.ask(goalId, agent, reason, "harness", words);
1281
- // The swarm's manager (manager.mjs): the person's asks, kept to their words.
1298
+ : actions.ask(goalId, agent, reason, DISPATCHER, words);
1299
+ // The dispatcher slot (dispatcher.mjs): what words the swarm's threads and checks results against the person's words,
1300
+ // as the person picked; the relay's LFM3-Omni by default, downloaded in the background from the start.
1301
+ // One dispatcher per swarm, on whichever computer is home (owner, November 1): the pick is kept on the board, which
1302
+ // follows home, and only the computer holding the board downloads the local model. A pick made before it was kept
1303
+ // there (this computer's config) moves onto the board once.
1304
+ const configPick = readJson(paths.config, {}).dispatcher ?? null;
1305
+ if (configPick && holdsBoard() && !store.boardSetting("dispatcher")) {
1306
+ store.setBoardSetting("dispatcher", configPick);
1307
+ const config = readJson(paths.config, {});
1308
+ delete config.dispatcher;
1309
+ writeJsonAtomic(paths.config, config);
1310
+ }
1311
+ const dispatcher = createDispatcher({
1312
+ root: path.join(paths.home, "local"),
1313
+ read: () => store.boardSetting("dispatcher"),
1314
+ write: (value) => store.setBoardSetting("dispatcher", value),
1315
+ inference: local.inference,
1316
+ wanted: () =>
1317
+ holdsBoard() && readJson(paths.config, {}).localModels === "download",
1318
+ installedAgents: () => installedAgents,
1319
+ askHarness,
1320
+ log,
1321
+ });
1322
+ dispatcher.warm();
1323
+ // The swarm's manager (manager.mjs): the person's asks, kept to their words, judged by the dispatcher.
1282
1324
  const manager = createManager({
1283
1325
  store,
1284
- askHarness,
1285
- usesServer: () =>
1286
- coordinatorMode() !== "local" &&
1287
- state.connected &&
1288
- bridge.has("swarm_manager"),
1289
- localJudge: () =>
1290
- coordinatorMode() === "local"
1291
- ? (coordinatorPick() ??
1292
- LOCAL_DECIDERS.find((agent) => installedAgents.includes(agent)) ??
1293
- null)
1294
- : null,
1326
+ dispatcher,
1327
+ goals,
1328
+ settled: (threadId) => coordinator.resumed(threadId),
1295
1329
  handOn: handOnAgent,
1296
1330
  post: (entry) => {
1297
1331
  const posted = store.roomPost(entry);
@@ -1341,6 +1375,7 @@ export async function startDaemon() {
1341
1375
  store,
1342
1376
  askHarness,
1343
1377
  isTaskRoom: (thread) => Boolean(store.meta(`task-room:${thread.id}`)),
1378
+ swarmAgents: () => available(),
1344
1379
  readsLessons: () => harnessReads("swarm_lessons"),
1345
1380
  isCoordinatorPost,
1346
1381
  embed: (texts, kind) => local.embed(texts, kind),
@@ -1652,7 +1687,7 @@ export async function startDaemon() {
1652
1687
  store.addContribution({
1653
1688
  taskId: threadId,
1654
1689
  kind: "file",
1655
- author: "harness",
1690
+ author: DISPATCHER,
1656
1691
  text: `harness attached ${fileLine(file)}`,
1657
1692
  source: `file:${file.id}`,
1658
1693
  });
@@ -1661,7 +1696,7 @@ export async function startDaemon() {
1661
1696
  },
1662
1697
  },
1663
1698
  wake: (goalId, post, names) =>
1664
- actions.wakeFor(goalId, post, "harness", names),
1699
+ actions.wakeFor(goalId, post, DISPATCHER, names),
1665
1700
  notify: (text) => {
1666
1701
  localEvent("snippet", text);
1667
1702
  notices.notify(text);
@@ -1781,6 +1816,7 @@ export async function startDaemon() {
1781
1816
  log,
1782
1817
  });
1783
1818
  const coordinator = createCoordinator({
1819
+ dispatcher,
1784
1820
  moves,
1785
1821
  holdsBoard,
1786
1822
  store,
@@ -1832,6 +1868,8 @@ export async function startDaemon() {
1832
1868
  // October 26 over security audit S4: waiting on every round's Start costs the swarm acting on its own).
1833
1869
  handOn: handOnAgent,
1834
1870
  openAsks: (goalId) => manager.open(goalId),
1871
+ doneAsks: (goalId) =>
1872
+ manager.asks(goalId).filter((ask) => ask.status === "done"),
1835
1873
  harnessQueued: (goalId) => asks.waitingFor(goalId, "harness"),
1836
1874
  failedAsks: (goalId) => asks.failed(goalId),
1837
1875
  pauseGoal: actions.pause,
@@ -1957,6 +1995,8 @@ export async function startDaemon() {
1957
1995
  resumed: (id) => coordinator.resumed(id),
1958
1996
  assembles: () => coordinator.assembles(),
1959
1997
  },
1998
+ // The dispatcher slot the person fills (dispatcher.mjs): its setting, read and changed from the CLI.
1999
+ dispatcher,
1960
2000
  roster: () =>
1961
2001
  available().map((id) => ({ id, about: aboutOf(id), setup: setupOf(id) })),
1962
2002
  worktrees,
@@ -2625,7 +2665,11 @@ export async function startDaemon() {
2625
2665
  ask: (type, input) => bridge.ask(type, input),
2626
2666
  boardCommand: (request) => boardCommand(request),
2627
2667
  filesRoot: paths.files,
2628
- changed: saveStatus,
2668
+ // A computer that became home fetches the dispatcher's model then (the others never do).
2669
+ changed: () => {
2670
+ saveStatus();
2671
+ dispatcher.warm();
2672
+ },
2629
2673
  folders: (options) => machineFolders(options),
2630
2674
  repositoryOf: (folder) => repositoryName(folder),
2631
2675
  inventoryChanged: () => {
@@ -2771,7 +2815,7 @@ export async function startDaemon() {
2771
2815
  knownFolders: () => folders.known().map((place) => place.path),
2772
2816
  agents: () => [
2773
2817
  ...installedAgents.filter((agent) => RUNNERS.has(agent)),
2774
- "harness",
2818
+ ...(actors.available().includes("harness") ? ["harness"] : []),
2775
2819
  ],
2776
2820
  worktreeRoot: path.join(paths.home, "projects"),
2777
2821
  maxPosts: DEFAULT_MAX_POSTS,