tryharness 0.7.73 → 0.7.76

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.
Files changed (49) hide show
  1. package/assets/pi-extension.ts +7 -1
  2. package/cli.mjs +67 -4
  3. package/lib/actorRoster.mjs +20 -9
  4. package/lib/adoption.mjs +5 -3
  5. package/lib/audit.mjs +7 -2
  6. package/lib/boardFiles.mjs +4 -2
  7. package/lib/boardMirror.mjs +2 -0
  8. package/lib/boardProtocol.json +4 -0
  9. package/lib/bridge.mjs +3 -0
  10. package/lib/capabilityCheck.mjs +39 -3
  11. package/lib/coordinator.mjs +480 -117
  12. package/lib/daemon.mjs +74 -21
  13. package/lib/dispatcher.mjs +568 -0
  14. package/lib/goalCommands.mjs +21 -6
  15. package/lib/handoffs.mjs +8 -7
  16. package/lib/handover.mjs +2 -2
  17. package/lib/inference.mjs +53 -3
  18. package/lib/jobAnswers.mjs +7 -6
  19. package/lib/lessons.mjs +6 -1
  20. package/lib/library.mjs +83 -7
  21. package/lib/lineup.mjs +17 -9
  22. package/lib/localAgentAsk.mjs +68 -29
  23. package/lib/localStack.mjs +19 -3
  24. package/lib/localmodels.mjs +59 -25
  25. package/lib/machineRoutes.mjs +1 -0
  26. package/lib/manager.mjs +97 -52
  27. package/lib/mcp-stdio.mjs +14 -7
  28. package/lib/members.json +5 -1
  29. package/lib/members.mjs +21 -1
  30. package/lib/moves.mjs +15 -2
  31. package/lib/nudge.mjs +5 -0
  32. package/lib/plans.mjs +2 -1
  33. package/lib/projects.mjs +16 -9
  34. package/lib/runAuthority.mjs +2 -1
  35. package/lib/runBrief.mjs +2 -2
  36. package/lib/runWorker.mjs +6 -6
  37. package/lib/snippets.mjs +5 -5
  38. package/lib/store.mjs +79 -10
  39. package/lib/swarm.mjs +56 -12
  40. package/lib/taskCommands.mjs +8 -8
  41. package/lib/taskRooms.mjs +6 -8
  42. package/lib/team.mjs +5 -3
  43. package/lib/threadActions.mjs +6 -30
  44. package/lib/threadAuthority.mjs +16 -3
  45. package/lib/threadRuns.mjs +26 -16
  46. package/lib/verdicts.mjs +2 -2
  47. package/npm-shrinkwrap.json +14 -14
  48. package/package.json +4 -4
  49. package/release.json +50 -49
package/lib/handoffs.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { nameOf } from "./members.mjs";
1
+ import { JEV, nameOf } from "./members.mjs";
2
2
 
3
3
  // Work handed to an agent that has to be woken (Grok Bot by email, OpenClaw and Hermes on their gateways) is watched
4
4
  // until the agent picks it up. A wake can be accepted and still never start a run (two of Grok Bot's emails once went
5
5
  // unanswered for 2 h and 20 min), so a missed pickup is never silent: the agent is woken again at 3 minutes, and at 10
6
- // the work moves to Harness, whose server takes it at once. The thread says so each time, and the person can put the
7
- // work back.
6
+ // the dispatcher takes the work back and Jev picks another agent for it (owner, November 1: Harness is not
7
+ // load-bearing; it took every missed pickup before). The thread says so each time.
8
8
  //
9
9
  // The 3 and 10 minutes: Grok Bot's 36 email wakes over five days were claimed 13 to 59 s after sending, so 3
10
10
  // minutes is three times its slowest normal pickup.
@@ -25,7 +25,8 @@ const minutes = (ms) => Math.max(1, Math.round(ms / 60_000));
25
25
  export function createHandoffs({
26
26
  store,
27
27
  wakeAgain,
28
- moveTo,
28
+ // Takes the work back from the agent that never picked it up, for Jev to place again; false when it cannot.
29
+ giveBack,
29
30
  say,
30
31
  timing = HANDOFF_TIMING,
31
32
  now = Date.now,
@@ -59,18 +60,18 @@ export function createHandoffs({
59
60
 
60
61
  function move(task) {
61
62
  const waited = waitedMs(task);
62
- if (!moveTo(task, "harness")) return;
63
+ if (!giveBack(task)) return;
63
64
  store.meta(
64
65
  movedKey(task.id),
65
66
  JSON.stringify({
66
67
  from: task.target_agent,
67
- to: "harness",
68
+ to: JEV,
68
69
  at: new Date(now()).toISOString(),
69
70
  })
70
71
  );
71
72
  say(
72
73
  task.parent_id,
73
- `${nameOf(task.target_agent)} didn't pick this up in ${minutes(waited)} min, so Harness has it now.`
74
+ `${nameOf(task.target_agent)} didn't pick this up in ${minutes(waited)} min, so Jev picks another agent for it.`
74
75
  );
75
76
  }
76
77
 
package/lib/handover.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readTrail } from "./trails.mjs";
2
2
  import { sessionFile } from "./live.mjs";
3
3
  import { catalogOf } from "./models.mjs";
4
- import { nameOf } from "./members.mjs";
4
+ import { DISPATCHER, nameOf } from "./members.mjs";
5
5
  import { oneLine } from "./oneLine.mjs";
6
6
 
7
7
  // A thread's agent resumes its own session each turn. A session close to its model's window would compact within the
@@ -118,7 +118,7 @@ export function createHandover({ store, log, sync }) {
118
118
  store.meta(`handover:${taskId}`, JSON.stringify(handed.record));
119
119
  store.roomPost({
120
120
  goalId: threadId,
121
- author: "harness",
121
+ author: DISPATCHER,
122
122
  kind: "note",
123
123
  text: `${nameOf(agent)} starts a fresh session here: its last one (${handed.record.from}) was too full to continue, as ${handed.why}. The new session's brief replays its last exchanges from the record and names the old transcript.`,
124
124
  });
package/lib/inference.mjs CHANGED
@@ -147,10 +147,12 @@ export function createInference({
147
147
  root,
148
148
  log = () => {},
149
149
  power = createPower(),
150
- list = MODELS,
150
+ list: given = MODELS,
151
151
  ceilingMb = memoryCeilingMb(),
152
152
  }) {
153
153
  ensureDir(root);
154
+ // A copy: a model the person brings (the dispatcher's own GGUF, useModel) joins this host's list, not the catalog.
155
+ const list = [...given];
154
156
  const deviceFile = path.join(root, "device.json");
155
157
  // The model server answers only this daemon: a key of its own, read from an owner-only file (not the command line,
156
158
  // which any program here can list), and no slots endpoint, which shows what was last sent to a model. The models'
@@ -192,13 +194,19 @@ export function createInference({
192
194
  const weights = entry.llama?.weights
193
195
  ? modelById(entry.llama.weights, list)
194
196
  : null;
197
+ // A model that carries its own projector names the file it is in (the dispatcher's LFM3-Omni).
198
+ const ownProjector = Number.isInteger(entry.llama?.mmproj)
199
+ ? modelFile(root, entry, entry.llama.mmproj)
200
+ : null;
201
+ const projector = weights ? modelFile(root, entry) : ownProjector;
195
202
  lines.push(
196
203
  `[${entry.id}]`,
197
204
  `model = ${modelFile(root, weights ?? entry)}`,
198
- ...(weights ? [`mmproj = ${modelFile(root, entry)}`] : [])
205
+ ...(projector ? [`mmproj = ${projector}`] : [])
199
206
  );
200
207
  for (const [key, value] of Object.entries(entry.llama ?? {}))
201
- if (key !== "weights") lines.push(`${key} = ${value}`);
208
+ if (key !== "weights" && key !== "mmproj")
209
+ lines.push(`${key} = ${value}`);
202
210
  }
203
211
  const file = path.join(root, "router.ini");
204
212
  fs.writeFileSync(file, lines.join("\n") + "\n");
@@ -244,6 +252,13 @@ export function createInference({
244
252
  base,
245
253
  gpu,
246
254
  media: modelsPresent(root, ["search", "media"], list),
255
+ // The GGUF models this server's preset holds: one downloaded after it started needs a restart to load.
256
+ serves: new Set(
257
+ list
258
+ .filter((model) => model.runtime === "llama")
259
+ .filter((model) => modelsPresent(root, [model.id], list))
260
+ .map((model) => model.id)
261
+ ),
247
262
  marker: null,
248
263
  };
249
264
  } catch {}
@@ -584,6 +599,41 @@ export function createInference({
584
599
  return out;
585
600
  })
586
601
  ),
602
+ /**
603
+ * One chat completion on a local GGUF model (the dispatcher's): an OpenAI-style request, its `model` set here. A
604
+ * server started before the model came down is restarted once with it.
605
+ */
606
+ /**
607
+ * A model of the person's own (the dispatcher's fine-tune) in this host's list, replacing one with its id: the
608
+ * server reloads with it the next time it is asked, so a changed file is read again.
609
+ */
610
+ useModel: async (entry) => {
611
+ const at = list.findIndex((each) => each.id === entry.id);
612
+ const same =
613
+ at >= 0 && JSON.stringify(list[at]) === JSON.stringify(entry);
614
+ if (same) return;
615
+ if (at >= 0) list[at] = entry;
616
+ else list.push(entry);
617
+ if (server) await stopServer();
618
+ },
619
+ chat: (id, request, { lane = "handoff" } = {}) =>
620
+ schedule("llama", lane, () =>
621
+ inUse("llama", async () => {
622
+ if (!modelsPresent(root, [id], list))
623
+ throw new Error(
624
+ `${modelById(id, list)?.name ?? id} is not downloaded yet`
625
+ );
626
+ let ready = await llamaFor(id);
627
+ if (!ready.serves?.has(id)) {
628
+ await stopServer();
629
+ ready = await llamaFor(id);
630
+ }
631
+ return post(ready.base, "/v1/chat/completions", {
632
+ ...request,
633
+ model: id,
634
+ });
635
+ })
636
+ ),
587
637
  /**
588
638
  * Embeds recordings and images with the search model's projector, in the same space as typed questions. items:
589
639
  * { title, data (a Buffer of WAV, MP3, FLAC, PNG or JPEG) }. A server started before the projector came down is
@@ -1,5 +1,5 @@
1
1
  import { askerOf } from "./answers.mjs";
2
- import { TAGGED_ONLY, member, nameOf } from "./members.mjs";
2
+ import { DISPATCHER, TAGGED_ONLY, member, nameOf } from "./members.mjs";
3
3
  import { notifyDesktop } from "./notify.mjs";
4
4
  import { restrictedRun } from "./runWorker.mjs";
5
5
  import { secretReason } from "./secrets.mjs";
@@ -83,7 +83,7 @@ export function createJobAnswers({
83
83
  if (!ENDED.includes(task.status)) return;
84
84
  const who = task.claimed_by || task.target_agent || "an agent";
85
85
  // An answer that came through Harness's server (Bankr's, Quotient's, Harness's server answering for a closed
86
- // window) wakes no one with the person's go (personsGo), except Harness's words the guard reads as clean.
86
+ // window) wakes whoever it names with the person's go (personsGo) only on words the guard reads as clean.
87
87
  const hosted =
88
88
  member(who)?.runs === "server" &&
89
89
  (who !== "harness" || Boolean(store.meta(`harness-served:${task.id}`)));
@@ -116,7 +116,7 @@ export function createJobAnswers({
116
116
  const hearsHere =
117
117
  !root ||
118
118
  runsHere(asker) ||
119
- (asker === "harness" && !conversationOf(task));
119
+ ((asker === "harness" || asker === DISPATCHER) && !conversationOf(task));
120
120
  const mentions = [
121
121
  ...new Set([
122
122
  ...(hearsHere ? [asker] : []),
@@ -163,11 +163,12 @@ export function createJobAnswers({
163
163
  });
164
164
  } else if (
165
165
  goal.status === "open" &&
166
- (fromElsewhere(who) || (who === "harness" && hosted)) &&
166
+ (fromElsewhere(who) || hosted) &&
167
167
  !flag
168
168
  )
169
- // An answer from the person's agents elsewhere, or Harness's server's for a closed window, wakes whoever it names
170
- // on the guard's reading of it, as their posts do.
169
+ // An answer from the person's agents elsewhere or on Harness's server, any of them, wakes whoever it names on the
170
+ // guard's reading of it, as their posts do (owner, November 1: no Start for work the person started, but Bankr's
171
+ // spending, which Bankr holds under its own approval and limits).
171
172
  void readByGuard(text).then((guard) => {
172
173
  if (guard?.verdict === "flag" || guard?.verdict === "hold")
173
174
  store.meta(`flagged:${post.id}`, String(guard.score));
package/lib/lessons.mjs CHANGED
@@ -24,6 +24,9 @@ export function createLessons({
24
24
  isCoordinatorPost,
25
25
  // A task's own room (one job given to an agent): what the person writes there settles that job.
26
26
  isTaskRoom = () => false,
27
+ // Every agent in the person's swarm: a lesson can be about any of them, in the thread or not yet (owner, November 1:
28
+ // Harness is no longer put in every thread's team, and "Harness makes the videos" is still about Harness).
29
+ swarmAgents = () => [],
27
30
  // Vectors for texts (`kind` query or document), or null while the local search model is not here.
28
31
  embed = async () => null,
29
32
  log,
@@ -100,7 +103,9 @@ export function createLessons({
100
103
  id: thread.id,
101
104
  title: thread.objective.slice(0, 500),
102
105
  folder: thread.goal?.workspace ?? null,
103
- agents: (thread.goal?.team ?? []).slice(0, 16),
106
+ agents: [
107
+ ...new Set([...(thread.goal?.team ?? []), ...swarmAgents()]),
108
+ ].slice(0, 16),
104
109
  },
105
110
  post: { seq: post.seq, text: post.text.slice(0, POST_CHARS) },
106
111
  before,
package/lib/library.mjs CHANGED
@@ -15,6 +15,12 @@ import { encodeWav } from "./speech.mjs";
15
15
  // against the question, and a part counts by meaning only when it stands out from all the others for that question
16
16
  // (its score in standard deviations, after each kind of part is centred on its own average). Words count beside
17
17
  // meaning, so a code or a name is found as written. Standing out is what lets a search say "nothing here".
18
+ //
19
+ // Recordings are scored against the question less what everyday questions have in common. The search model puts some
20
+ // recordings close to every question: on the person's own folders a Zoom recording's video came back for 10 of 30
21
+ // unrelated questions, its audio file for 7 and two other recordings for 5, standing out for all of them. Taking the
22
+ // common part out of text and pictures too cost more than it fixed: READMEs joined briefs about things written
23
+ // nowhere, and a screenshot lost the code written in it to a README.
18
24
 
19
25
  const MAX_FILES = 5_000;
20
26
  // A folder is walked this far to find its newest files.
@@ -32,6 +38,41 @@ const BRIEF_NEAR_BEST = 1.0;
32
38
  // scored 0.68 and up, never-said questions 0.675 at most).
33
39
  const MIN_SCALE = 200;
34
40
  const FLOOR = { image: 0.7, audio: 0.7, text: 0.7 };
41
+ // Questions about nothing of the person's in particular, across what people look for in files. What they have in
42
+ // common is taken out of a question before recordings are scored against it. None of them is a question the
43
+ // file-search or media-search evals ask.
44
+ const EVERYDAY_QUESTIONS = [
45
+ "what time does the store open",
46
+ "how do I reset my password",
47
+ "recipe for banana bread",
48
+ "the train schedule to Boston",
49
+ "notes about the product launch",
50
+ "a picture of the beach",
51
+ "who won the game last night",
52
+ "how much does the gym membership cost",
53
+ "the plumber's phone number",
54
+ "an email to my landlord",
55
+ "instructions for assembling the desk",
56
+ "my car insurance renewal",
57
+ "a recording of the team standup",
58
+ "slides for the investor meeting",
59
+ "a chart of monthly revenue",
60
+ "the wifi password",
61
+ "a photo of my kids",
62
+ "directions to the airport",
63
+ "the doctor's lab results",
64
+ "a spreadsheet of expenses",
65
+ "the warranty for my laptop",
66
+ "a podcast episode about history",
67
+ "a screenshot of a chat",
68
+ "the speech from the wedding",
69
+ "terms of service",
70
+ "a list of book recommendations",
71
+ "the hiking trail map",
72
+ "my passport scan",
73
+ "a voice memo",
74
+ "a funny video",
75
+ ];
35
76
  const SMALL_GROUP = 20;
36
77
  const WORD_WEIGHT = 2.0;
37
78
  const VECTORS_IDLE_MS = 5 * 60_000;
@@ -137,6 +178,18 @@ const hintedKinds = (text) => {
137
178
 
138
179
  const phrase = (word) => `"${word.replaceAll('"', '""')}"`;
139
180
 
181
+ const dot = (a, b) => {
182
+ let sum = 0;
183
+ for (let i = 0; i < a.length; i += 1) sum += a[i] * b[i];
184
+ return sum;
185
+ };
186
+
187
+ const average = (vectors) =>
188
+ vectors[0].map(
189
+ (_, i) =>
190
+ vectors.reduce((sum, vector) => sum + vector[i], 0) / vectors.length
191
+ );
192
+
140
193
  /**
141
194
  * Meaning scores on one scale for this query (DigUp's Searcher.meaning): each part's similarity minus the average of
142
195
  * its modality, in standard deviations of all of them together.
@@ -271,6 +324,22 @@ export function createLibrary({
271
324
  let refreshing = null;
272
325
  let skipped = [];
273
326
 
327
+ // What the everyday questions have in common: their average, embedded once.
328
+ let everyday = null;
329
+ const everydayCentre = async (lane) => {
330
+ everyday ??= inference
331
+ .embed(
332
+ EVERYDAY_QUESTIONS.map((text) => ({ kind: "query", text })),
333
+ { lane }
334
+ )
335
+ .then(average)
336
+ .catch((error) => {
337
+ everyday = null;
338
+ throw error;
339
+ });
340
+ return everyday;
341
+ };
342
+
274
343
  const vectors = () => {
275
344
  cache ??= store.vectors(version);
276
345
  clearTimeout(dropCache);
@@ -561,6 +630,8 @@ export function createLibrary({
561
630
  ? inFolders
562
631
  : threads.includes(part.source) &&
563
632
  (!readable || readable.has(part.file));
633
+ // A question without a word in it ("", "x") asks for nothing, and some part always scores highest for it.
634
+ if (!/[\p{L}\p{N}]{2,}/u.test(text)) return [];
564
635
  const words = terms(text);
565
636
  const lookup = isLookup(words);
566
637
 
@@ -569,24 +640,29 @@ export function createLibrary({
569
640
  const best = new Map();
570
641
  if (rows.length) {
571
642
  const [q] = await inference.embed([{ kind: "query", text }], { lane });
572
- const scores = rows.map((row) => {
573
- let dot = 0;
574
- for (let i = 0; i < q.length; i += 1) dot += q[i] * row.vector[i];
575
- return dot;
576
- });
643
+ const centre = await everydayCentre(lane);
644
+ const asked = q.map((value, i) => value - centre[i]);
645
+ const scores = rows.map((row) =>
646
+ dot(row.modality === "audio" ? asked : q, row.vector)
647
+ );
577
648
  const z = standOut(
578
649
  scores,
579
650
  rows.map((row) => row.modality)
580
651
  );
581
652
  const scaled = rows.length >= MIN_SCALE;
582
653
  const gate = brief ? BRIEF_Z : Z_GATE;
654
+ // The similarity to the question as asked: the floor for a small library, and what a hit reports.
655
+ const similarity = (row) => dot(q, row.vector);
583
656
  rows.forEach((row, i) => {
584
657
  if (!inScope(row)) return;
585
- const strong = scaled ? z[i] >= gate : scores[i] >= FLOOR[row.modality];
658
+ const strong = scaled
659
+ ? z[i] >= gate
660
+ : similarity(row) >= FLOOR[row.modality];
586
661
  const held = best.get(row.file);
587
662
  if (!held || z[i] > held.z)
588
- best.set(row.file, { part: row, z: z[i], cosine: scores[i], strong });
663
+ best.set(row.file, { part: row, z: z[i], strong });
589
664
  });
665
+ for (const held of best.values()) held.cosine = similarity(held.part);
590
666
  }
591
667
 
592
668
  // Words: a file holding at least half the question's words qualifies, a code or name matched as written. A brief's
package/lib/lineup.mjs CHANGED
@@ -14,12 +14,13 @@ import { createAgentReadiness, SIGN_IN } from "./readiness.mjs";
14
14
  // computer, already ticked, and the person keeps the ones they want; every other agent joins only when they add it
15
15
  // (`npx tryharness agents add`, or Add an agent in the buddy's settings). The list lives in the config as
16
16
  // `swarmAgents`. A config from before the lineup has none, and its swarm stays as it was: every agent the roster finds.
17
- // Harness itself is always in the swarm.
17
+ // Harness is one agent like the others (owner, November 1: "@harness is just another agent"): in the swarm until the
18
+ // person takes it out. A lineup written while Harness was always in left it off the list; it reads with Harness in.
18
19
 
19
20
  /** Agents that run on this computer: the coding agents Harness starts, and the assistants it wakes by webhook. */
20
21
  const HERE = [...MACHINE_RUNNERS, "openclaw", "hermes"];
21
22
  /** Agents that live elsewhere and are added on purpose; Grok Bot and Muse also need their own setup in Harness. */
22
- const ELSEWHERE = ["grok-bot", "bankr", "quotient", "muse"];
23
+ const ELSEWHERE = ["harness", "grok-bot", "bankr", "quotient", "muse"];
23
24
  const NEEDS_SETUP_ELSEWHERE = new Set(["grok-bot", "muse"]);
24
25
 
25
26
  const PROVIDER_KEYS = [
@@ -119,9 +120,17 @@ const signInHint = (id, check) =>
119
120
  ? `sign in to ${nameOf(id)} first: run ${SIGN_IN[id]}`
120
121
  : `sign in to ${nameOf(id)} first`;
121
122
 
123
+ // Lineups this version writes say whether Harness is in; older ones never listed it, as it was always in.
124
+ const LINEUP_VERSION = 2;
125
+
122
126
  /** The lineup in a config, or null for a config from before it (every agent the roster finds is in). */
123
- export const lineupOf = (config) =>
124
- Array.isArray(config?.swarmAgents) ? config.swarmAgents : null;
127
+ export function lineupOf(config) {
128
+ if (!Array.isArray(config?.swarmAgents)) return null;
129
+ const listsHarness = config.swarmLineup >= LINEUP_VERSION;
130
+ return listsHarness || config.swarmAgents.includes("harness")
131
+ ? config.swarmAgents
132
+ : [...config.swarmAgents, "harness"];
133
+ }
125
134
 
126
135
  /** One module the daemon, setup and the CLI share: the lineup in the config file, read again only when it changes. */
127
136
  export function createLineup({ file = paths.config } = {}) {
@@ -145,21 +154,22 @@ export function createLineup({ file = paths.config } = {}) {
145
154
  ...config,
146
155
  swarmAgents: [...new Set(list)],
147
156
  swarmRemoved: [...new Set(kept)],
157
+ swarmLineup: LINEUP_VERSION,
148
158
  });
149
159
  cached = { mtimeMs: -1, list: null };
150
160
  };
151
161
  return {
152
- /** Whether an agent is in the swarm; Harness always is, and so is everyone when there is no lineup yet. */
162
+ /** Whether an agent is in the swarm; everyone is when there is no lineup yet. */
153
163
  has: (agent) => {
154
164
  const list = read();
155
- return agent === "harness" || list === null || list.includes(agent);
165
+ return list === null || list.includes(agent);
156
166
  },
157
167
  list: () => read(),
158
168
  /** Whether the person took this agent out of their swarm themselves. */
159
169
  removedByPerson: (agent) =>
160
170
  (readJson(file, {}).swarmRemoved ?? []).includes(agent),
161
171
  /** Start the lineup (setup) with exactly these agents. */
162
- set: (agents) => write(agents.filter((id) => id !== "harness")),
172
+ set: (agents) => write(agents),
163
173
  add: (agent) => {
164
174
  const list = read();
165
175
  // A swarm from before the lineup keeps everything it had; adding to it changes nothing.
@@ -317,8 +327,6 @@ export function createLineupCommands({
317
327
  if (joined.ok) onChanged(agent);
318
328
  return joined;
319
329
  }
320
- if (agent === "harness")
321
- return { ok: false, error: "Harness is always in your swarm." };
322
330
  lineup.remove(agent);
323
331
  onChanged(agent);
324
332
  return { ok: true, agent, name: nameOf(agent) };
@@ -5,6 +5,9 @@ import { spawn } from "node:child_process";
5
5
  // in its read-only sandbox. The coordinator asks them to decide a round on the privacy setting or as Harness's backup
6
6
  // (coordinator.mjs), and to read a round Harness's server decided before its words reach an agent (serverWords.mjs).
7
7
  export const LOCAL_DECIDERS = ["claude-code", "codex"];
8
+ // The agents that can fill the dispatcher slot (dispatcher.mjs): every coding agent with a one-shot mode and its tools
9
+ // off, each on any model it offers (owner, November 1: "swapped to another agent running on the users machine").
10
+ export const DISPATCH_AGENTS = ["claude-code", "codex", "pi", "opencode"];
8
11
 
9
12
  /**
10
13
  * One question to `agent`, answered with one JSON object. It runs in the system's temporary folder, away from any
@@ -12,7 +15,11 @@ export const LOCAL_DECIDERS = ["claude-code", "codex"];
12
15
  * this computer to answer but never
13
16
  * change it: Codex in its read-only sandbox, Claude Code with only its read, glob and grep tools.
14
17
  */
15
- export function askLocalAgent(agent, prompt, { look = false } = {}) {
18
+ export function askLocalAgent(
19
+ agent,
20
+ prompt,
21
+ { look = false, model = null } = {}
22
+ ) {
16
23
  return new Promise((resolve, reject) => {
17
24
  const invocation =
18
25
  agent === "codex"
@@ -24,36 +31,67 @@ export function askLocalAgent(agent, prompt, { look = false } = {}) {
24
31
  "--sandbox",
25
32
  "read-only",
26
33
  "--skip-git-repo-check",
34
+ ...(model ? ["-m", model] : []),
27
35
  "-",
28
36
  ],
29
37
  stdin: prompt,
30
38
  }
31
- : {
32
- command: "claude",
33
- // Only the model reads: the person's MCP servers, hooks and settings made each reading take ~15 s instead
34
- // of ~2 s, and a question with no tools uses none of them.
35
- args: [
36
- "-p",
37
- prompt,
38
- "--output-format",
39
- "json",
40
- ...(look
41
- ? [
42
- "--tools",
43
- "Read,Glob,Grep",
44
- "--allowedTools",
45
- "Read Glob Grep",
46
- "--add-dir",
47
- os.homedir(),
48
- "--permission-mode",
49
- "dontAsk",
50
- ]
51
- : ["--tools", ""]),
52
- "--strict-mcp-config",
53
- "--setting-sources",
54
- "",
55
- ],
56
- };
39
+ : agent === "pi"
40
+ ? {
41
+ command: "pi",
42
+ args: [
43
+ "-p",
44
+ prompt,
45
+ "--no-session",
46
+ "--no-tools",
47
+ "--no-mcp",
48
+ "--no-extensions",
49
+ "--no-skills",
50
+ "--no-context-files",
51
+ ...(model ? ["--model", model] : []),
52
+ ],
53
+ }
54
+ : agent === "opencode"
55
+ ? {
56
+ command: "opencode",
57
+ // The plan agent edits nothing; --pure leaves the person's plugins out of a one-shot answer.
58
+ args: [
59
+ "run",
60
+ prompt,
61
+ "--pure",
62
+ "--agent",
63
+ "plan",
64
+ ...(model ? ["-m", model] : []),
65
+ ],
66
+ }
67
+ : {
68
+ command: "claude",
69
+ // Only the model reads: the person's MCP servers, hooks and settings made each reading take ~15 s instead
70
+ // of ~2 s, and a question with no tools uses none of them.
71
+ args: [
72
+ "-p",
73
+ prompt,
74
+ "--output-format",
75
+ "json",
76
+ ...(look
77
+ ? [
78
+ "--tools",
79
+ "Read,Glob,Grep",
80
+ "--allowedTools",
81
+ "Read Glob Grep",
82
+ // The whole computer, read only: what a check needs may sit outside the home folder (/opt/homebrew).
83
+ "--add-dir",
84
+ "/",
85
+ "--permission-mode",
86
+ "dontAsk",
87
+ ]
88
+ : ["--tools", ""]),
89
+ "--strict-mcp-config",
90
+ "--setting-sources",
91
+ "",
92
+ ...(model ? ["--model", model] : []),
93
+ ],
94
+ };
57
95
  let child;
58
96
  try {
59
97
  child = spawn(invocation.command, invocation.args, { cwd: os.tmpdir() });
@@ -76,8 +114,9 @@ export function askLocalAgent(agent, prompt, { look = false } = {}) {
76
114
  reject(new Error(`${agent} exited with code ${code}`));
77
115
  return;
78
116
  }
79
- // Claude answers one JSON object with its text in `result`; Codex streams events, its words in agent_message.
80
- let text = "";
117
+ // Claude answers one JSON object with its text in `result`; Codex streams events, its words in agent_message;
118
+ // Pi and OpenCode print their answer as text.
119
+ let text = agent === "pi" || agent === "opencode" ? out : "";
81
120
  for (const line of out.split("\n")) {
82
121
  try {
83
122
  const event = JSON.parse(line);
@@ -155,16 +155,31 @@ export function createLocalStack({
155
155
  };
156
156
  };
157
157
 
158
- // Where people keep their own files and the folders they added (tryharness local add), unless they turned search off.
159
- const libraryFolders = () => {
158
+ // Where people keep their own files and the folders they added (tryharness local add), searched or not.
159
+ const ownFolders = () => {
160
160
  const config = readJson(configPath, {});
161
- if (config.libraryOff === true) return [];
162
161
  const added = Array.isArray(config.localFolders) ? config.localFolders : [];
163
162
  const own = OWN_FOLDERS.map((name) => path.join(os.homedir(), name));
164
163
  return [...new Set([...own, ...added])].filter(
165
164
  (folder) => typeof folder === "string" && fs.existsSync(folder)
166
165
  );
167
166
  };
167
+ // The folders the library searches: the person's own, unless they turned search off.
168
+ const libraryFolders = () =>
169
+ readJson(configPath, {}).libraryOff === true ? [] : ownFolders();
170
+ /** Whether a file is in one of the person's own folders, after links are followed. */
171
+ const inOwnFolder = (file) => {
172
+ let real;
173
+ try {
174
+ real = fs.realpathSync(file);
175
+ } catch {
176
+ return false;
177
+ }
178
+ return ownFolders().some((folder) => {
179
+ const root = fs.realpathSync(folder);
180
+ return real === root || real.startsWith(root + path.sep);
181
+ });
182
+ };
168
183
 
169
184
  let mediaDownload = null;
170
185
  const fetchMedia = () => {
@@ -527,6 +542,7 @@ export function createLocalStack({
527
542
  embed,
528
543
  searchContext,
529
544
  libraryFolders,
545
+ inOwnFolder,
530
546
  localHit,
531
547
  threadFileHits,
532
548
  readFilesSoon,