tryharness 0.7.67 → 0.7.69

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 (54) hide show
  1. package/lib/boardFileCommands.mjs +5 -7
  2. package/lib/boardFiles.mjs +5 -0
  3. package/lib/boardProtocol.json +50 -64
  4. package/lib/boardWaits.mjs +6 -0
  5. package/lib/cards.mjs +13 -1
  6. package/lib/comfyExecution.mjs +545 -0
  7. package/lib/context.mjs +34 -20
  8. package/lib/contextWorker.mjs +199 -0
  9. package/lib/coordinator.mjs +224 -22
  10. package/lib/daemon.mjs +196 -14
  11. package/lib/dispatchContract.json +313 -0
  12. package/lib/dispatchTools.js +87 -0
  13. package/lib/dispatches.mjs +975 -0
  14. package/lib/environment.mjs +54 -69
  15. package/lib/files.mjs +35 -0
  16. package/lib/frames.mjs +5 -9
  17. package/lib/goalCommands.mjs +13 -10
  18. package/lib/kept.mjs +131 -0
  19. package/lib/landed.mjs +1 -34
  20. package/lib/library.mjs +18 -11
  21. package/lib/live.mjs +30 -11
  22. package/lib/localAgentAsk.mjs +27 -4
  23. package/lib/localStack.mjs +17 -13
  24. package/lib/machineRoutes.mjs +5 -0
  25. package/lib/machineRuns.mjs +2 -1
  26. package/lib/mcp-stdio.mjs +42 -1
  27. package/lib/openHere.mjs +36 -0
  28. package/lib/openRequests.mjs +56 -0
  29. package/lib/ownMachines.mjs +232 -24
  30. package/lib/phones.mjs +29 -4
  31. package/lib/places.mjs +44 -11
  32. package/lib/portCalls.mjs +54 -0
  33. package/lib/promptDecider.mjs +471 -0
  34. package/lib/promptFlow.mjs +562 -0
  35. package/lib/promptScopes.mjs +670 -0
  36. package/lib/provenance.mjs +3 -2
  37. package/lib/runAuthority.mjs +14 -2
  38. package/lib/runBrief.mjs +2 -2
  39. package/lib/runWorker.mjs +25 -5
  40. package/lib/runner.mjs +62 -6
  41. package/lib/sealed.mjs +37 -0
  42. package/lib/sessionControl.mjs +47 -14
  43. package/lib/sessionIndex.mjs +11 -3
  44. package/lib/store.mjs +362 -40
  45. package/lib/swarm.mjs +85 -34
  46. package/lib/swarmMemory.mjs +39 -16
  47. package/lib/taskCommands.mjs +125 -1
  48. package/lib/team.json +10 -0
  49. package/lib/team.mjs +287 -26
  50. package/lib/threadBriefs.mjs +43 -31
  51. package/lib/threadRuns.mjs +47 -3
  52. package/npm-shrinkwrap.json +14 -14
  53. package/package.json +4 -4
  54. package/release.json +55 -43
@@ -8,26 +8,37 @@ export const LOCAL_DECIDERS = ["claude-code", "codex"];
8
8
 
9
9
  /**
10
10
  * One question to `agent`, answered with one JSON object. It runs in the system's temporary folder, away from any
11
- * repository, and has no deadline of its own: it ends when the agent answers or exits.
11
+ * repository, and has no deadline of its own: it ends when the agent answers or exits. `model` names the agent's own
12
+ * model; without it the agent uses its default.
12
13
  */
13
- export function askLocalAgent(agent, prompt) {
14
+ export function askLocalAgent(
15
+ agent,
16
+ prompt,
17
+ {
18
+ executable = null,
19
+ isolated = false,
20
+ model = null,
21
+ onResponse = () => {},
22
+ } = {}
23
+ ) {
14
24
  return new Promise((resolve, reject) => {
15
25
  const invocation =
16
26
  agent === "codex"
17
27
  ? {
18
- command: "codex",
28
+ command: executable ?? "codex",
19
29
  args: [
20
30
  "exec",
21
31
  "--json",
22
32
  "--sandbox",
23
33
  "read-only",
24
34
  "--skip-git-repo-check",
35
+ ...(model ? ["--model", model] : []),
25
36
  "-",
26
37
  ],
27
38
  stdin: prompt,
28
39
  }
29
40
  : {
30
- command: "claude",
41
+ command: executable ?? "claude",
31
42
  // Only the model reads: the person's MCP servers, hooks and settings made each reading take ~15 s instead
32
43
  // of ~2 s, and a question with no tools uses none of them.
33
44
  args: [
@@ -40,6 +51,8 @@ export function askLocalAgent(agent, prompt) {
40
51
  "--strict-mcp-config",
41
52
  "--setting-sources",
42
53
  "",
54
+ ...(isolated ? ["--bare", "--restricted"] : []),
55
+ ...(model ? ["--model", model] : []),
43
56
  ],
44
57
  };
45
58
  let child;
@@ -53,11 +66,21 @@ export function askLocalAgent(agent, prompt) {
53
66
  child.stdin.on("error", () => {});
54
67
  child.stdin.end(invocation.stdin ?? "");
55
68
  let out = "";
69
+ let errors = "";
56
70
  child.stdout.on("data", (chunk) => {
57
71
  out += chunk;
58
72
  });
73
+ child.stderr.on("data", (chunk) => {
74
+ errors += chunk;
75
+ });
59
76
  child.on("error", reject);
60
77
  child.on("close", (code) => {
78
+ try {
79
+ onResponse({ code, stdout: out, stderr: errors });
80
+ } catch (error) {
81
+ reject(error);
82
+ return;
83
+ }
61
84
  if (code !== 0) {
62
85
  reject(new Error(`${agent} exited with code ${code}`));
63
86
  return;
@@ -3,7 +3,7 @@ import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { execFile } from "node:child_process";
5
5
  import { ATLAS_VERSION } from "./atlas.mjs";
6
- import { createContextEngine } from "./context.mjs";
6
+ import { createContextWorker } from "./contextWorker.mjs";
7
7
  import { createCoreModels } from "./coreModels.mjs";
8
8
  import { readJson, writeJsonAtomic } from "./files.mjs";
9
9
  import { createFirewall } from "./firewall.mjs";
@@ -41,7 +41,7 @@ const COMMANDS = new Set([
41
41
  *
42
42
  * - The context space (search): the search model embeds it in the background, a batch at a time, so no request waits
43
43
  * on it; until it is present, search answers from words and says so.
44
- * - The context engine (context.mjs): the atlas of the folders the swarm works in, what every coding session there
44
+ * - The context engine (context.mjs, in its own thread: contextWorker.mjs): the atlas of the folders the swarm works in, what every coding session there
45
45
  * needed, a context pack for each local agent's brief, the overnight learner, and the library of the person's own
46
46
  * files. Documents and PDFs need only the search model; pictures, recordings and video wait for its image and audio
47
47
  * part, which comes down on the charger.
@@ -195,7 +195,7 @@ export function createLocalStack({
195
195
  path: namedPath(file),
196
196
  }));
197
197
 
198
- const contextEngine = createContextEngine({
198
+ const contextEngine = createContextWorker({
199
199
  store,
200
200
  inference,
201
201
  home: root,
@@ -248,10 +248,13 @@ export function createLocalStack({
248
248
  const file = store.file(fileId);
249
249
  return Boolean(file) && (!hostedCaller || file.cloud);
250
250
  };
251
+ const allowed = libraryThreadFiles()
252
+ .filter((file) => file.thread === thread && readable(file.id))
253
+ .map((file) => file.id);
251
254
  try {
252
255
  const hits = await contextEngine.searchFiles(query, {
253
256
  threads: [thread],
254
- allow: readable,
257
+ allowed,
255
258
  limit: 5,
256
259
  });
257
260
  return hits.map((hit) =>
@@ -458,12 +461,15 @@ export function createLocalStack({
458
461
  const command = (request) => {
459
462
  switch (request.command) {
460
463
  case "local.status":
461
- return {
462
- ok: true,
463
- ...contextEngine.status(),
464
- coreModels: coreModels.status(),
465
- learning: contextEngine.report(),
466
- };
464
+ return contextEngine.status().then(
465
+ (status) => ({
466
+ ok: true,
467
+ ...status,
468
+ coreModels: coreModels.status(),
469
+ learning: contextEngine.report(),
470
+ }),
471
+ (error) => ({ ok: false, error: error.message })
472
+ );
467
473
  case "local.learn":
468
474
  void contextEngine
469
475
  .learn({ force: true })
@@ -506,9 +512,7 @@ export function createLocalStack({
506
512
 
507
513
  const stop = () => {
508
514
  clearInterval(embedTimer);
509
- try {
510
- contextEngine.stop();
511
- } catch {}
515
+ void contextEngine.stop().catch(() => {});
512
516
  inference.stop();
513
517
  };
514
518
 
@@ -46,6 +46,7 @@ const QUEUEABLE = new Set([
46
46
  "board.thread.post",
47
47
  "board.context.add",
48
48
  "board.machine.finish",
49
+ "board.prompt.receipt",
49
50
  ]);
50
51
  export const queueable = (command) => QUEUEABLE.has(String(command));
51
52
 
@@ -148,6 +149,7 @@ export function withComputer(post, computerOf) {
148
149
  // A worker's own upkeep with home, whoever it names: telling home its folders, taking and reporting the runs home keeps
149
150
  // for its agents, the environment grants home's vault lends a run there (vault.mjs checks those itself).
150
151
  const UPKEEP = new Set([
152
+ "board.prompt.receipt",
151
153
  "board.machine.info",
152
154
  "board.machine.runnable",
153
155
  "board.machine.take",
@@ -222,6 +224,9 @@ const AGENT_WORK = new Set([
222
224
  // threads. How the swarm is set up (standing permission, spend ceilings, connectors' grants, the vault, the relay
223
225
  // network, the desk's book, partners on projects, offices) is changed only on home itself or a phone paired with it.
224
226
  const PERSON_WORK = new Set([
227
+ "board.prompt.start",
228
+ "board.prompt.status",
229
+ "board.prompt.cancel",
225
230
  ...AGENT_WORK,
226
231
  "board.run",
227
232
  "board.remove",
@@ -2,6 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { within } from "./folders.mjs";
4
4
  import { provenanceLine } from "./provenance.mjs";
5
+ import { readProfile } from "./profile.mjs";
5
6
  import { prepareScratch, threadScratch } from "./scratch.mjs";
6
7
 
7
8
  // On a worker: the work home keeps for this computer's agents, run here. The person's Start (or a thread's authority)
@@ -94,7 +95,7 @@ export function createMachineRuns({
94
95
  (ref) => `- ${ref.kind}: ${ref.ref}${ref.note ? ` (${ref.note})` : ""}`
95
96
  )
96
97
  .join("\n");
97
- const notice = provenanceLine(task);
98
+ const notice = provenanceLine(task, readProfile()?.displayName);
98
99
  return [notice, task.objective, task.brief, refs ? `Context:\n${refs}` : ""]
99
100
  .filter(Boolean)
100
101
  .join("\n\n");
package/lib/mcp-stdio.mjs CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from "node:fs";
3
+ import {
4
+ DISPATCH_WORK_TOOL,
5
+ SCOPE_WORKSPACE_TOOL,
6
+ dispatchWorkRequest,
7
+ } from "./dispatchTools.js";
3
8
  import { CONNECTION_TOOL, connectionRequest } from "./connectionTools.js";
4
9
  import { USE_SECRET_TOOL, secretToolRequest } from "./vaultTools.js";
5
10
  import { paths } from "./paths.mjs";
@@ -31,11 +36,15 @@ if (process.argv.includes("--check-host") && startedByAnother(agent)) {
31
36
  // (`tryharness connections on`), and never to a restricted run: work another agent or another person's swarm asked
32
37
  // for runs without the person's apps (runner.mjs restrictedMcpConfig).
33
38
  const restricted = process.argv.includes("--restricted");
39
+ const scopeIndex = process.argv.indexOf("--scope");
40
+ const dispatchScope = scopeIndex >= 0 ? process.argv[scopeIndex + 1] : null;
34
41
  const appsOn = !restricted && readJson(paths.config, {}).connectedApps === true;
35
42
  let input = "";
36
43
  let chain = Promise.resolve();
37
44
 
38
45
  const LOCAL_TOOLS = [
46
+ DISPATCH_WORK_TOOL,
47
+ ...(dispatchScope ? [SCOPE_WORKSPACE_TOOL] : []),
39
48
  ARCHETYPE_TOOL,
40
49
  ...(appsOn ? [CONNECTION_TOOL] : []),
41
50
  {
@@ -437,7 +446,7 @@ const LOCAL_TOOLS = [
437
446
  {
438
447
  name: "post_to_room",
439
448
  description:
440
- "Post in a goal's room for the whole team: a finding, partial work, a question or what you did. To ask another agent for help, put its name in ask (claude-code, codex, pi, opencode, grok-bot, openclaw, hermes, bankr, quotient, muse, or harness to have the thread coordinated), say exactly what you need, then stop: you are woken again when it answers you by name. When you answer someone who asked you, name them (@codex) and they are woken. To have a coding agent run on a particular model, write it after the name, @codex:gpt-6-luna or @codex:gpt-6-luna/high with an effort, from list_models. Any other @name, like a thanks, wakes no one. Post results and sources, not secrets: anything that looks like a key is held. For work someone else should do, post_task with parent_id set to the goal id.",
449
+ 'Post in a goal\'s room for the whole team: a finding, partial work, a question or what you did. To ask another agent for help, or to hand it the next step (a review, the next part of the work), put its name in ask (claude-code, codex, pi, opencode, grok-bot, openclaw, hermes, bankr, quotient, muse, or harness to have the thread coordinated), say exactly what you need, then stop: you are woken again when it answers you by name. When you answer someone who asked you, name them (@codex) and they are woken. To have a coding agent run on a particular model, write it after the name, @codex:gpt-6-luna or @codex:gpt-6-luna/high with an effort, from list_models. A name only in your text, like "Next: @codex" or a thanks, wakes no one: the thread then waits for Harness to pass it on. Post results and sources, not secrets: anything that looks like a key is held. For work someone else should do, post_task with parent_id set to the goal id.',
441
450
  inputSchema: {
442
451
  type: "object",
443
452
  properties: {
@@ -825,6 +834,15 @@ const postTask = (args) => ({
825
834
  });
826
835
 
827
836
  const BOARD_CALLS = {
837
+ dispatch_work: dispatchWorkRequest,
838
+ scope_workspace: (args) => ({
839
+ command: "board.dispatch.workspace",
840
+ scopeRef: dispatchScope,
841
+ operation: args.operation,
842
+ path: args.path,
843
+ text: args.text,
844
+ expectedSha256: args.expected_sha256,
845
+ }),
828
846
  connection: connectionRequest,
829
847
  list_agents: () => ({ command: "board.swarm.agents" }),
830
848
  list_models: (args) => ({
@@ -1367,6 +1385,29 @@ async function relay(line) {
1367
1385
  return;
1368
1386
  }
1369
1387
 
1388
+ if (dispatchScope) {
1389
+ const names = new Set(["dispatch_work", "scope_workspace"]);
1390
+ if (request.method === "initialize") write(localInitialize(request));
1391
+ else if (request.method === "tools/list")
1392
+ write({
1393
+ jsonrpc: "2.0",
1394
+ id: request.id,
1395
+ result: { tools: LOCAL_TOOLS.filter((tool) => names.has(tool.name)) },
1396
+ });
1397
+ else if (request.method === "tools/call" && names.has(request.params?.name))
1398
+ write(await localCall(request));
1399
+ else if (request.id !== undefined)
1400
+ write({
1401
+ jsonrpc: "2.0",
1402
+ id: request.id,
1403
+ error: {
1404
+ code: -32601,
1405
+ message: "This scope exposes only dispatch and workspace-file tools.",
1406
+ },
1407
+ });
1408
+ return;
1409
+ }
1410
+
1370
1411
  if (
1371
1412
  request.method === "tools/call" &&
1372
1413
  LOCAL_TOOLS.some((tool) => tool.name === request.params?.name)
@@ -0,0 +1,36 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ /**
4
+ * Open on this computer, by the daemon itself, where the buddy would have opened it: a link (a T3 Code or Codex thread)
5
+ * or an app. For the phone's Open (landed.mjs) and another computer's Open with no buddy running here
6
+ * (openRequests.mjs). The link and the app are this computer's own reading of the work, never the caller's. A test
7
+ * stands in for the opener with HARNESS_OPEN_COMMAND, as notify.mjs takes HARNESS_NOTIFY_COMMAND.
8
+ */
9
+ export function openHere(plan) {
10
+ if (!plan.ok || (!plan.link && !plan.app)) return plan;
11
+ const args =
12
+ process.platform === "darwin"
13
+ ? plan.link
14
+ ? [plan.link]
15
+ : ["-a", plan.app]
16
+ : plan.link
17
+ ? [plan.link]
18
+ : null;
19
+ if (!args)
20
+ return {
21
+ ok: false,
22
+ error: `${plan.opensIn ?? "Its app"} can only be opened on this computer itself.`,
23
+ };
24
+ const child = spawn(
25
+ process.env.HARNESS_OPEN_COMMAND ||
26
+ (process.platform === "darwin" ? "open" : "xdg-open"),
27
+ args,
28
+ {
29
+ detached: true,
30
+ stdio: "ignore",
31
+ }
32
+ );
33
+ child.on("error", () => {});
34
+ child.unref();
35
+ return { ok: true, opensIn: plan.opensIn, openedHere: true };
36
+ }
@@ -0,0 +1,56 @@
1
+ // Open on another of the person's computers (owner, October 28: an agent on another computer opens "on that
2
+ // computer"). That computer plans the Open as its own buddy's Open would (sessionControl.mjs board.live.focus, a T3
3
+ // Code thread by its own link) and its buddy carries it out, so it lands where the person would go to see it there: a
4
+ // T3 thread, a terminal resuming the session, an editor. The buddy hears of it as it hears of any change, from
5
+ // board.wait, and takes it with board.live.opens. With no buddy waiting here, a link or an app opens by the daemon
6
+ // itself, as the phone's Open does (openHere.mjs); anything else says it needs the buddy.
7
+
8
+ // An Open the buddy has not taken within this is dropped, so a buddy started later never opens something the person
9
+ // asked for long before; and a buddy that waited on the board within it is still there, between two of its waits.
10
+ // Measured on this Mac (M5 Pro) with the buddy installed, October 28, 19 samples: handed over to taken 58 to 196 ms
11
+ // (median about 110 ms); one Open arrived while the daemon was busy (3.5 s to answer) and the buddy between waits.
12
+ // 10 s is fifty times the slowest and covers the daemon's stalls of up to 1.8 s after a restart.
13
+ const KEEP_MS = 10_000;
14
+
15
+ /**
16
+ * `plan(open)` plans an Open here as the person: { to, sessionId, folder, fresh } for an agent's session (or, fresh,
17
+ * the agent itself where they use it), { thread } for a thread in this computer's T3 Code. `waits` is the board's
18
+ * (boardWaits.mjs): whether a buddy waits on this computer, and the bump that wakes it.
19
+ */
20
+ export function createOpenRequests({
21
+ plan,
22
+ waits,
23
+ openHere,
24
+ log = () => {},
25
+ now = Date.now,
26
+ keepMs = KEEP_MS,
27
+ }) {
28
+ let queued = [];
29
+
30
+ const open = async (request) => {
31
+ const planned = await plan(request);
32
+ if (!planned?.ok) return planned;
33
+ if (now() - waits.waitedAt() > keepMs) {
34
+ const opened = openHere(planned);
35
+ if (opened.openedHere || !opened.ok) return opened;
36
+ return {
37
+ ok: false,
38
+ error: `${planned.opensIn ?? "It"} opens there only with Harness's buddy running on that computer.`,
39
+ };
40
+ }
41
+ queued.push({ plan: planned, at: now() });
42
+ waits.bump();
43
+ return { ok: true, opensIn: planned.opensIn ?? null, openedThere: true };
44
+ };
45
+
46
+ /** The buddy's: the Opens asked for since it last took them, oldest first. */
47
+ const take = () => {
48
+ const fresh = queued.filter(({ at }) => now() - at <= keepMs);
49
+ for (const { at } of queued)
50
+ log(`open for another computer taken after ${now() - at} ms`);
51
+ queued = [];
52
+ return { ok: true, plans: fresh.map(({ plan: planned }) => planned) };
53
+ };
54
+
55
+ return { open, take };
56
+ }