tryharness 0.7.44 → 0.7.53

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 (101) hide show
  1. package/README.md +232 -12
  2. package/cli.mjs +406 -184
  3. package/lib/actorRoster.mjs +28 -5
  4. package/lib/adapters.mjs +9 -1
  5. package/lib/agentRuntimeConfig.mjs +36 -0
  6. package/lib/agentRuntimes.mjs +560 -0
  7. package/lib/atlas.mjs +7 -2
  8. package/lib/boardCommands.mjs +5 -10
  9. package/lib/boardFileCommands.mjs +2 -1
  10. package/lib/boardMirror.mjs +459 -0
  11. package/lib/boardProtocol.json +259 -6
  12. package/lib/boardTools.mjs +2 -6
  13. package/lib/bridge.mjs +27 -3
  14. package/lib/browserWake.mjs +60 -0
  15. package/lib/cards.mjs +35 -2
  16. package/lib/commands.mjs +20 -5
  17. package/lib/connectionTools.d.ts +13 -0
  18. package/lib/connectionTools.js +45 -0
  19. package/lib/connectorAuth.mjs +309 -0
  20. package/lib/connectorCatalog.json +41 -0
  21. package/lib/connectorCommands.mjs +121 -0
  22. package/lib/connectorGoogle.mjs +513 -0
  23. package/lib/connectors.mjs +805 -0
  24. package/lib/coordinator.mjs +16 -2
  25. package/lib/coreModels.mjs +78 -0
  26. package/lib/daemon.mjs +775 -46
  27. package/lib/desktop.mjs +7 -2
  28. package/lib/digest.mjs +32 -0
  29. package/lib/directLink.mjs +283 -0
  30. package/lib/environments.mjs +595 -0
  31. package/lib/folders.mjs +2 -2
  32. package/lib/goalCommands.mjs +61 -12
  33. package/lib/inference.mjs +263 -152
  34. package/lib/lessons.mjs +6 -0
  35. package/lib/lineup.mjs +324 -0
  36. package/lib/localmodels.mjs +10 -0
  37. package/lib/machineIdentity.mjs +3 -0
  38. package/lib/machineRoutes.mjs +40 -2
  39. package/lib/machineRuns.mjs +30 -3
  40. package/lib/machineSeal.mjs +69 -10
  41. package/lib/mcp-stdio.mjs +180 -98
  42. package/lib/mcpRelay.mjs +119 -0
  43. package/lib/members.json +12 -0
  44. package/lib/members.mjs +33 -0
  45. package/lib/modelMemory.mjs +100 -0
  46. package/lib/modelTiers.json +1183 -0
  47. package/lib/modelTiers.mjs +133 -0
  48. package/lib/models.mjs +41 -8
  49. package/lib/museSession.mjs +119 -0
  50. package/lib/nativeHost.mjs +203 -0
  51. package/lib/network.mjs +38 -1
  52. package/lib/nudge.mjs +10 -2
  53. package/lib/onboard.mjs +430 -1
  54. package/lib/oneclawLocal.mjs +150 -0
  55. package/lib/ownMachines.mjs +521 -36
  56. package/lib/pairing.mjs +165 -0
  57. package/lib/paths.mjs +4 -0
  58. package/lib/phones.mjs +61 -0
  59. package/lib/placeCommands.mjs +27 -0
  60. package/lib/places.mjs +10 -2
  61. package/lib/plans.mjs +151 -27
  62. package/lib/profile.mjs +152 -0
  63. package/lib/projectGit.mjs +328 -0
  64. package/lib/projectSettings.mjs +120 -0
  65. package/lib/projects.mjs +2539 -0
  66. package/lib/readiness.mjs +283 -0
  67. package/lib/repoLinks.mjs +354 -0
  68. package/lib/roomChannels.mjs +641 -0
  69. package/lib/runBrief.mjs +32 -2
  70. package/lib/runRequests.mjs +157 -0
  71. package/lib/runWorker.mjs +20 -7
  72. package/lib/runner.mjs +67 -8
  73. package/lib/secretPatterns.json +55 -0
  74. package/lib/secrets.mjs +10 -27
  75. package/lib/seen.mjs +102 -0
  76. package/lib/service.mjs +11 -6
  77. package/lib/sessionControl.mjs +10 -8
  78. package/lib/sessionIndex.mjs +5 -3
  79. package/lib/store.mjs +559 -30
  80. package/lib/subagents.mjs +8 -4
  81. package/lib/swarm.mjs +379 -38
  82. package/lib/swarmMemory.mjs +947 -0
  83. package/lib/t3.mjs +43 -13
  84. package/lib/taskCommands.mjs +58 -5
  85. package/lib/taskRuns.mjs +61 -11
  86. package/lib/team.json +17 -15
  87. package/lib/team.mjs +68 -18
  88. package/lib/threadRuns.mjs +50 -7
  89. package/lib/threadView.mjs +68 -15
  90. package/lib/tokenizer.mjs +405 -0
  91. package/lib/ui.mjs +16 -2
  92. package/lib/usageTotals.mjs +148 -0
  93. package/lib/vault.mjs +1144 -0
  94. package/lib/vaultCloud.mjs +117 -0
  95. package/lib/vaultCommands.mjs +201 -0
  96. package/lib/vaultTools.d.ts +12 -0
  97. package/lib/vaultTools.js +42 -0
  98. package/lib/windowAsks.mjs +42 -0
  99. package/lib/workFocus.mjs +59 -0
  100. package/lib/workLinks.mjs +90 -0
  101. package/package.json +9 -4
package/lib/runBrief.mjs CHANGED
@@ -4,6 +4,7 @@ import { claudeMemNotes } from "./claudemem.mjs";
4
4
  import { toldBlock } from "./cards.mjs";
5
5
  import { fitSections } from "./fit.mjs";
6
6
  import { oneLine } from "./oneLine.mjs";
7
+ import { profileBrief, readProfile } from "./profile.mjs";
7
8
 
8
9
  // What a board run is told when it starts, and which session it continues. The brief is made of named sections, each
9
10
  // with a priority, its source and a pointer to where the agent finds it (fit.mjs); over the budget the lowest-priority,
@@ -30,6 +31,8 @@ export function createRunBriefs({
30
31
  localEvent,
31
32
  localReady,
32
33
  log,
34
+ // The swarm's long-running memory (swarmMemory.mjs): what other threads and earlier jobs found, failed at or settled.
35
+ memory = null,
33
36
  roomGuide,
34
37
  store,
35
38
  threadFilesNote,
@@ -65,7 +68,7 @@ export function createRunBriefs({
65
68
 
66
69
  // The context engine's pack (context.mjs), the thread's task frame and the person's lessons that fit this work.
67
70
  const localContext = async (task, agent, { wake, room, dryRun }) => {
68
- const found = { pack: null, frame: "", lessons: [] };
71
+ const found = { pack: null, frame: "", lessons: [], memory: null };
69
72
  try {
70
73
  const thread = wake ? store.getTask(task.parent_id) : null;
71
74
  // The request is the task's own words, or for a thread turn the thread and its newest posts.
@@ -139,6 +142,16 @@ export function createRunBriefs({
139
142
  `lessons-carried:${task.id}`,
140
143
  JSON.stringify(found.lessons.map((lesson) => lesson.id))
141
144
  );
145
+ // Only for an agent that runs on this computer: memory holds the person's words and every thread's work.
146
+ found.memory =
147
+ memory && RUNNERS.has(agent)
148
+ ? await memory.forBrief({
149
+ agent,
150
+ folder: home,
151
+ threadId,
152
+ text: request,
153
+ })
154
+ : null;
142
155
  } catch (error) {
143
156
  log(`context pack for ${task.id}: ${error.message}`);
144
157
  }
@@ -160,6 +173,7 @@ export function createRunBriefs({
160
173
 
161
174
  const sectionsFor = ({ task, agent, wake, room, local, memory }) => {
162
175
  const pack = local.pack?.parts ?? {};
176
+ const person = RUNNERS.has(agent) ? readProfile() : null;
163
177
  const refs = task.context_refs.map(
164
178
  (ref) => `- ${ref.kind}: ${ref.ref}${ref.note ? ` (${ref.note})` : ""}`
165
179
  );
@@ -190,6 +204,14 @@ export function createRunBriefs({
190
204
  pointer: `Context: ${refs.length} reference${refs.length === 1 ? "" : "s"}; get_task ${task.id} lists them.`,
191
205
  },
192
206
  ...(room?.kind === "goal" ? [roomSection(room, agent)] : []),
207
+ // Who the agent works for, from the profile setup imported (profile.mjs); like lessons, only for agents here.
208
+ {
209
+ name: "the person",
210
+ priority: "recommended",
211
+ source: "Harness profile",
212
+ text: person ? profileBrief(person) : "",
213
+ pointer: person ? `You are working for ${person.displayName}.` : "",
214
+ },
193
215
  {
194
216
  name: "task frame",
195
217
  priority: "recommended",
@@ -197,6 +219,14 @@ export function createRunBriefs({
197
219
  text: local.frame,
198
220
  pointer: `What the relay knows about this task on this computer: get_task ${task.id} carries it.`,
199
221
  },
222
+ {
223
+ name: "swarm memory",
224
+ priority: "recommended",
225
+ source: "swarm memory",
226
+ text: local.memory?.text ?? "",
227
+ pointer:
228
+ "What other threads and earlier jobs found, failed at or settled: swarm_memory finds it by what you are looking for.",
229
+ },
200
230
  {
201
231
  name: "lessons",
202
232
  priority: "optional",
@@ -225,7 +255,7 @@ export function createRunBriefs({
225
255
  source: "context engine",
226
256
  text: pack.earlier ?? "",
227
257
  pointer:
228
- "Earlier sessions on these files: search_swarm finds what any of the person's agents did before.",
258
+ "Earlier sessions on these files: swarm_memory finds what any of the person's agents did before.",
229
259
  },
230
260
  {
231
261
  name: "library files",
@@ -0,0 +1,157 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { nameOf } from "./members.mjs";
3
+
4
+ /** Native permission choices for running, owned executions. A decision never starts or resumes a run. */
5
+ export function createRunRequests({ store, notifyBoard }) {
6
+ const pending = new Map();
7
+ const records = JSON.parse(store.meta("native-run-requests") || "[]").map(
8
+ (entry) =>
9
+ entry.status === "waiting" ? { ...entry, status: "interrupted" } : entry
10
+ );
11
+ const save = () => store.meta("native-run-requests", JSON.stringify(records));
12
+ save();
13
+ const running = (entry) => {
14
+ const task = store.getTask(entry.runId);
15
+ return task?.status === "running" && task.target_agent === entry.agent;
16
+ };
17
+ const tell = (entry) => notifyBoard(store.getTask(entry.runId));
18
+ const request = ({ runId, agent, approval, signal }) => {
19
+ signal.throwIfAborted();
20
+ if (!running({ runId, agent }))
21
+ throw new Error(
22
+ "This native permission does not belong to a running task."
23
+ );
24
+ const choices = approval.availableChoices.filter(
25
+ (choice) =>
26
+ choice.scope === "once" &&
27
+ ["approved", "denied", "abort"].includes(choice.decision)
28
+ );
29
+ if (!choices.length)
30
+ throw new Error(
31
+ "The agent offered no one-time decision Harness can present. Configure this permission in the original application."
32
+ );
33
+ const details = String(approval.rawArgs || "");
34
+ if (details.length > 20_000)
35
+ throw new Error(
36
+ "This native permission is too large to review here. Open the original application before granting it."
37
+ );
38
+ const entry = {
39
+ id: randomUUID(),
40
+ runId,
41
+ agent,
42
+ approvalId: approval.approvalId,
43
+ requirement: approval.currentRequirementId,
44
+ revision: createHash("sha256")
45
+ .update(JSON.stringify(approval))
46
+ .digest("hex"),
47
+ text: `Requested action: ${approval.toolName}`,
48
+ details,
49
+ protectedWrite: approval.protectedWrite === true,
50
+ choices: choices.map(({ choiceId, label, decision }) => ({
51
+ id: choiceId,
52
+ label,
53
+ allow: decision === "approved",
54
+ })),
55
+ status: "waiting",
56
+ at: new Date().toISOString(),
57
+ };
58
+ for (const old of pending.values())
59
+ if (
60
+ old.entry.runId === runId &&
61
+ old.entry.approvalId === entry.approvalId
62
+ )
63
+ old.close(
64
+ "replaced",
65
+ new Error("The native permission changed before it was answered.")
66
+ );
67
+ records.push(entry);
68
+ return new Promise((resolve, reject) => {
69
+ const close = (status, error, choice) => {
70
+ if (!pending.has(entry.id)) return;
71
+ entry.status = status;
72
+ pending.delete(entry.id);
73
+ signal.removeEventListener("abort", aborted);
74
+ save();
75
+ tell(entry);
76
+ if (error) {
77
+ error.code = `native_${status}`;
78
+ reject(error);
79
+ } else resolve({ choiceId: choice });
80
+ };
81
+ const aborted = () =>
82
+ close(
83
+ "cancelled",
84
+ new Error(
85
+ "This run stopped before the native permission was answered."
86
+ )
87
+ );
88
+ pending.set(entry.id, { entry, close });
89
+ signal.addEventListener("abort", aborted, { once: true });
90
+ save();
91
+ tell(entry);
92
+ if (signal.aborted) aborted();
93
+ });
94
+ };
95
+ const needs = (runId) =>
96
+ [...pending.values()]
97
+ .filter(({ entry }) => entry.runId === runId && running(entry))
98
+ .map(({ entry }) => ({
99
+ id: `permission:${entry.id}`,
100
+ kind: "permission",
101
+ agent: entry.agent,
102
+ runId,
103
+ requestId: entry.id,
104
+ text: `${nameOf(entry.agent)} needs your permission to continue.`,
105
+ at: entry.at,
106
+ }));
107
+ const finish = (runId) => {
108
+ for (const held of pending.values())
109
+ if (held.entry.runId === runId)
110
+ held.close(
111
+ "ended",
112
+ new Error("This run ended before its native permission was answered.")
113
+ );
114
+ };
115
+ const command = (input, agent) => {
116
+ if (agent !== "user" || input.hostedCaller)
117
+ return {
118
+ ok: false,
119
+ code: "sealed_only",
120
+ error:
121
+ "Read and answer native permissions on your computer or a browser linked to it.",
122
+ };
123
+ const held = pending.get(String(input.requestId || ""));
124
+ if (!held || !running(held.entry))
125
+ return {
126
+ ok: false,
127
+ code: "not_pending",
128
+ error: "This native permission is no longer waiting.",
129
+ };
130
+ const { entry } = held;
131
+ if (input.runId !== entry.runId)
132
+ return {
133
+ ok: false,
134
+ error: "This native permission belongs to another run.",
135
+ };
136
+ if (input.command === "board.native.read")
137
+ return { ok: true, request: entry };
138
+ if (input.command !== "board.native.decide")
139
+ return { ok: false, error: "Unknown native request command." };
140
+ if (input.revision !== entry.revision)
141
+ return {
142
+ ok: false,
143
+ code: "changed",
144
+ error:
145
+ "Read this native permission's current request before answering.",
146
+ };
147
+ const choice = entry.choices.find((option) => option.id === input.choiceId);
148
+ if (!choice)
149
+ return {
150
+ ok: false,
151
+ error: "Choose one of the native options shown for this request.",
152
+ };
153
+ held.close("submitted", null, choice.id);
154
+ return { ok: true, status: "submitted" };
155
+ };
156
+ return { request, needs, command, finish };
157
+ }
package/lib/runWorker.mjs CHANGED
@@ -8,6 +8,12 @@ import { sessionFile } from "./live.mjs";
8
8
  import { oneLine } from "./oneLine.mjs";
9
9
 
10
10
  // `briefs` (runBrief.mjs) says what each run is told and which session it continues.
11
+ /** Another agent's words on a goal's authority, without the person's tap or go (person-wake): restricted (docs/member-runs.md). */
12
+ export const restrictedRun = (store, task) =>
13
+ task.trust !== "user" &&
14
+ task.run_authorized_by === "goal" &&
15
+ store.meta(`person-wake:${task.id}`) !== "1";
16
+
11
17
  export function createRunWorker({
12
18
  RESCAN_MS,
13
19
  authority,
@@ -15,6 +21,9 @@ export function createRunWorker({
15
21
  contextEngine,
16
22
  installedAgents,
17
23
  machineId = () => null,
24
+ // A worker's board tables are a copy of home's: what it runs comes from home (machineRuns.mjs), never from the copy.
25
+ holdsBoard = () => true,
26
+ onlyItsOwn = () => false,
18
27
  localEvent,
19
28
  log,
20
29
  modelForRun,
@@ -23,6 +32,7 @@ export function createRunWorker({
23
32
  sync,
24
33
  taskRuns,
25
34
  threadRuns,
35
+ vaultEnv = () => null,
26
36
  }) {
27
37
  const { RUNNERS, standingRules } = authority;
28
38
  const { commitWake, settleWake, ranOutsideT3, t3Turn, taskInT3 } =
@@ -97,9 +107,11 @@ export function createRunWorker({
97
107
  notifyBoard(store.getTask(task.parent_id));
98
108
  };
99
109
  const runBoard = () => {
100
- if (runsHeld) return;
110
+ if (runsHeld || !holdsBoard()) return;
101
111
  // One run per folder at a time: each thread's worktree is its own folder, so threads run side by side.
102
- for (const task of store.runnableTasks(installedAgents, machineId())) {
112
+ for (const task of store.runnableTasks(installedAgents, machineId(), {
113
+ only: onlyItsOwn(),
114
+ })) {
103
115
  const agent = task.target_agent;
104
116
  // Where a task runs is settled once, before its slot: a run T3 carries out holds its thread, not a folder.
105
117
  if (task.kind === "task" && store.meta(`t3-run:${task.id}`) === null)
@@ -143,15 +155,15 @@ export function createRunWorker({
143
155
  if (resumeSession && !task.session_id)
144
156
  store.setRunSession(task.id, resumeSession);
145
157
  const readOnly = store.meta(`review:${task.id}`) === "1";
146
- // Another agent's words on a goal's authority, without the person's tap or go (person-wake): restricted (docs/member-runs.md).
147
- const restricted =
148
- task.trust !== "user" &&
149
- task.run_authorized_by === "goal" &&
150
- store.meta(`person-wake:${task.id}`) !== "1";
158
+ const restricted = restrictedRun(store, task);
151
159
  const chosen = await modelForRun(task, agent);
152
160
  store.setRunModel(task.id, chosen);
153
161
  const { model, effort } = chosen;
154
162
  const t3 = inT3 ? t3Turn(task, agent, { model, effort }) : null;
163
+ // The person's environment grants (vault.mjs), never for a run they did not authorize: the values are in this
164
+ // run's environment, and what it says is scrubbed of them.
165
+ const secrets = restricted ? null : vaultEnv(task, agent);
166
+ const granted = secrets && Object.keys(secrets.env).length ? secrets : null;
155
167
  taskRuns.startTask(
156
168
  {
157
169
  runId: task.id,
@@ -166,6 +178,7 @@ export function createRunWorker({
166
178
  ...(readOnly ? { readOnly } : {}),
167
179
  ...(restricted ? { restricted } : {}),
168
180
  ...(t3 ? { t3 } : {}),
181
+ ...(granted ? { env: granted.env, scrub: granted.values } : {}),
169
182
  },
170
183
  (kind, text, extra) => {
171
184
  // The agent's session in a thread is resumed when the thread calls on it again; in T3 it is the agent's T3 thread.
package/lib/runner.mjs CHANGED
@@ -3,6 +3,9 @@ import { fileURLToPath } from "node:url";
3
3
  import path from "node:path";
4
4
  import { spawn } from "node:child_process";
5
5
  import { agentEnvironment } from "./agentnode.mjs";
6
+ import { runtimeOf } from "./agentRuntimeConfig.mjs";
7
+ import { runProtocolTask } from "./agentRuntimes.mjs";
8
+ import { scrubValues } from "./vault.mjs";
6
9
 
7
10
  const running = new Set();
8
11
  const children = new Map();
@@ -15,9 +18,19 @@ export function stopAgentTask(runId) {
15
18
  return true;
16
19
  }
17
20
 
21
+ /**
22
+ * Stops every agent process the relay started, as the daemon shuts down. Without the daemon nothing reads their output
23
+ * or reports their end, and they would keep running (and holding memory) with no one waiting on them; the next daemon
24
+ * treats their turns as interrupted. Runs another app carries out are that app's to end.
25
+ */
26
+ export function stopAllRuns() {
27
+ for (const child of children.values())
28
+ if (!child.external) child.kill("SIGTERM");
29
+ }
30
+
18
31
  /** A run another app carries out (T3 Code, t3.mjs): Stop reaches it through `stop`. Returns its release. */
19
32
  export function trackRun(runId, stop) {
20
- const entry = { pid: null, kill: stop };
33
+ const entry = { pid: null, kill: stop, external: true };
21
34
  children.set(runId, entry);
22
35
  return () => {
23
36
  if (children.get(runId) === entry) children.delete(runId);
@@ -76,6 +89,7 @@ export const restrictedMcpConfig = () => ({
76
89
  fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
77
90
  "--agent",
78
91
  "claude-code",
92
+ "--restricted",
79
93
  ],
80
94
  },
81
95
  },
@@ -435,7 +449,7 @@ export function readRunSteps(file, limit = 200) {
435
449
  return steps.slice(-limit);
436
450
  }
437
451
 
438
- export function runAgentTask(task, emit, observe = () => {}) {
452
+ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
439
453
  // One run per folder: two agents in one checkout would trip over each other; a thread's worktree is its own folder.
440
454
  // A read-only review edits nothing, so it goes beside whoever writes there (runWorker.mjs keeps one per agent).
441
455
  const slot = task.readOnly
@@ -456,9 +470,44 @@ export function runAgentTask(task, emit, observe = () => {}) {
456
470
  let environment;
457
471
  try {
458
472
  cwd = resolveWorkingDirectory(task.cwd);
473
+ if (runtimeOf(task.agent)) {
474
+ const controller = new AbortController();
475
+ running.add(slot);
476
+ children.set(task.runId, { kill: () => controller.abort() });
477
+ let released = false;
478
+ const release = () => {
479
+ if (released) return;
480
+ released = true;
481
+ running.delete(slot);
482
+ children.delete(task.runId);
483
+ };
484
+ let settled = false;
485
+ const report = (kind, text, extra) => {
486
+ if (settled) return;
487
+ if (["done", "failed"].includes(kind)) {
488
+ settled = true;
489
+ release();
490
+ }
491
+ emit(kind, text, extra);
492
+ };
493
+ void runProtocolTask(
494
+ { ...task, cwd },
495
+ { ...hooks, emit: report, observe, signal: controller.signal }
496
+ )
497
+ .catch((error) => report("failed", error.message, { failure: "exit" }))
498
+ .finally(release);
499
+ return;
500
+ }
459
501
  invocation = agentInvocation(task);
460
502
  // A Node agent runs on a Node it accepts, whichever Node Harness itself runs on.
461
- environment = agentEnvironment(invocation.command);
503
+ // The person's environment grants for this run (vault.mjs), over the daemon's own environment.
504
+ // HARNESS_RUN_ID tells the agent's own Harness tools which run they serve (mcp-stdio.mjs), where its MCP servers
505
+ // inherit the agent's environment.
506
+ environment = agentEnvironment(invocation.command, {
507
+ ...process.env,
508
+ ...(task.env ?? {}),
509
+ HARNESS_RUN_ID: task.runId,
510
+ });
462
511
  if (environment.error) throw new Error(environment.error);
463
512
  } catch (error) {
464
513
  emit("failed", error.message, { failure: "start" });
@@ -485,6 +534,12 @@ export function runAgentTask(task, emit, observe = () => {}) {
485
534
  children.set(task.runId, child);
486
535
 
487
536
  let resultText = "";
537
+ // A run with secrets in its environment (vault.mjs): its words are cleaned of them before anything is cut short, so
538
+ // a cut never leaves part of a value behind.
539
+ const clean = (text) =>
540
+ task.scrub instanceof Map && task.scrub.size
541
+ ? scrubValues(text, task.scrub)
542
+ : text;
488
543
  let modelError = "";
489
544
  let tail = "";
490
545
  let buffer = "";
@@ -498,7 +553,7 @@ export function runAgentTask(task, emit, observe = () => {}) {
498
553
  buffer = lines.pop() || "";
499
554
  for (const line of lines) {
500
555
  if (!line.trim()) continue;
501
- tail = (tail + "\n" + line).slice(-4_000);
556
+ tail = clean(tail + "\n" + line).slice(-4_000);
502
557
  let event;
503
558
  try {
504
559
  event = JSON.parse(line);
@@ -546,13 +601,15 @@ export function runAgentTask(task, emit, observe = () => {}) {
546
601
  : "";
547
602
  }
548
603
  for (const step of stepsOf(event))
549
- emit("progress", step.text.slice(0, 200), { step });
604
+ emit("progress", clean(step.text).slice(0, 200), {
605
+ step: { ...step, text: clean(step.text) },
606
+ });
550
607
  }
551
608
  });
552
609
  child.stderr?.on("data", (chunk) => {
553
610
  const raw = String(chunk);
554
611
  observe("stderr", raw);
555
- tail = (tail + "\n" + raw).slice(-4_000);
612
+ tail = clean(tail + "\n" + raw).slice(-4_000);
556
613
  });
557
614
  child.on("close", (code) => {
558
615
  running.delete(slot);
@@ -560,7 +617,9 @@ export function runAgentTask(task, emit, observe = () => {}) {
560
617
  if (code === 0 && modelError)
561
618
  emit(
562
619
  "failed",
563
- `${task.agent} stopped on an error from its model: ${modelError}`.slice(
620
+ clean(
621
+ `${task.agent} stopped on an error from its model: ${modelError}`
622
+ ).slice(
564
623
  0,
565
624
  4_000
566
625
  ),
@@ -570,7 +629,7 @@ export function runAgentTask(task, emit, observe = () => {}) {
570
629
  emit(
571
630
  "done",
572
631
  (
573
- resultText ||
632
+ clean(resultText) ||
574
633
  "The run finished; check the repository for its changes."
575
634
  ).slice(0, 20_000),
576
635
  { usage: usage.result() }
@@ -0,0 +1,55 @@
1
+ {
2
+ "about": "What must never leave in a message to someone else's agent or an outside place: keys and tokens by their well-known shapes, private-key blocks, env-style assignments of secrets, and anything that announces itself as a seed phrase. Read by the daemon (cli/lib/secrets.mjs) and by Harness's server (src/shared/secrets.ts), so both check the same list.",
3
+ "patterns": [
4
+ {
5
+ "reason": "a private key block",
6
+ "source": "-----BEGIN [A-Z ]*PRIVATE KEY-----",
7
+ "flags": ""
8
+ },
9
+ {
10
+ "reason": "an OpenAI-style API key",
11
+ "source": "\\bsk-[A-Za-z0-9_-]{20,}\\b",
12
+ "flags": ""
13
+ },
14
+ {
15
+ "reason": "an AWS access key",
16
+ "source": "\\bAKIA[0-9A-Z]{16}\\b",
17
+ "flags": ""
18
+ },
19
+ {
20
+ "reason": "a GitHub token",
21
+ "source": "\\b(ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{30,}\\b|\\bgithub_pat_[A-Za-z0-9_]{40,}\\b",
22
+ "flags": ""
23
+ },
24
+ {
25
+ "reason": "a Slack token",
26
+ "source": "\\bxox[abpr]-[A-Za-z0-9-]{10,}\\b",
27
+ "flags": ""
28
+ },
29
+ {
30
+ "reason": "a JSON web token",
31
+ "source": "\\beyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\b",
32
+ "flags": ""
33
+ },
34
+ {
35
+ "reason": "a 32-byte hex key",
36
+ "source": "\\b(0x)?[0-9a-fA-F]{64}\\b",
37
+ "flags": ""
38
+ },
39
+ {
40
+ "reason": "a Harness connection token",
41
+ "source": "\\bhmcp_[A-Za-z0-9]{12,}\\b",
42
+ "flags": ""
43
+ },
44
+ {
45
+ "reason": "a secret assigned in env style",
46
+ "source": "\\b[A-Z0-9_]*(SECRET|TOKEN|PASSWORD|PRIVATE_KEY|API_KEY)[A-Z0-9_]*\\s*[=:]\\s*['\"]?[^\\s'\"]{8,}",
47
+ "flags": ""
48
+ },
49
+ {
50
+ "reason": "a seed phrase",
51
+ "source": "\\b(seed phrase|mnemonic|recovery phrase)\\b[\\s\\S]{0,40}?(\\b[a-z]{3,8}\\b[\\s,]+){11,}",
52
+ "flags": "i"
53
+ }
54
+ ]
55
+ }
package/lib/secrets.mjs CHANGED
@@ -1,33 +1,16 @@
1
+ import { readFileSync } from "node:fs";
2
+
1
3
  // The outbound guard on a thread: what must never leave the machine in a reply to another
2
4
  // person's agent. A hit does not block forever; it holds the message for the person, with the
3
- // reason, so they can strip it or send it knowingly. Patterns are deliberately plain and
4
- // conservative: keys and tokens by their well-known shapes, private-key blocks, env-style
5
- // assignments of secrets, and anything that announces itself as a seed phrase.
5
+ // reason, so they can strip it or send it knowingly. The patterns live in secretPatterns.json, which
6
+ // Harness's server reads too (src/shared/secrets.ts), so both check the same list.
6
7
 
7
- const PATTERNS = [
8
- { reason: "a private key block", test: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
9
- { reason: "an OpenAI-style API key", test: /\bsk-[A-Za-z0-9_-]{20,}\b/ },
10
- { reason: "an AWS access key", test: /\bAKIA[0-9A-Z]{16}\b/ },
11
- {
12
- reason: "a GitHub token",
13
- test: /\b(ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{30,}\b|\bgithub_pat_[A-Za-z0-9_]{40,}\b/,
14
- },
15
- { reason: "a Slack token", test: /\bxox[abpr]-[A-Za-z0-9-]{10,}\b/ },
16
- {
17
- reason: "a JSON web token",
18
- test: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/,
19
- },
20
- { reason: "a 32-byte hex key", test: /\b(0x)?[0-9a-fA-F]{64}\b/ },
21
- { reason: "a Harness connection token", test: /\bhmcp_[A-Za-z0-9]{12,}\b/ },
22
- {
23
- reason: "a secret assigned in env style",
24
- test: /\b[A-Z0-9_]*(SECRET|TOKEN|PASSWORD|PRIVATE_KEY|API_KEY)[A-Z0-9_]*\s*[=:]\s*['"]?[^\s'"]{8,}/,
25
- },
26
- {
27
- reason: "a seed phrase",
28
- test: /\b(seed phrase|mnemonic|recovery phrase)\b[\s\S]{0,40}?(\b[a-z]{3,8}\b[\s,]+){11,}/i,
29
- },
30
- ];
8
+ const PATTERNS = JSON.parse(
9
+ readFileSync(new URL("./secretPatterns.json", import.meta.url), "utf8")
10
+ ).patterns.map((pattern) => ({
11
+ reason: pattern.reason,
12
+ test: new RegExp(pattern.source, pattern.flags),
13
+ }));
31
14
 
32
15
  /** The reason a text must be held, or null when nothing in it looks like a secret. */
33
16
  export function secretReason(text) {
package/lib/seen.mjs ADDED
@@ -0,0 +1,102 @@
1
+ // What the person saw, for the swarm's memory (owner, October 22: the swarm should know what the person has seen, read
2
+ // from the Harness extension's hidden page, "part of the memories" rather than on its own clock). Each dream asks the
3
+ // person's Harness window (windowAsks.mjs, which wakes the hidden page) for one described frame per hour since the last
4
+ // read, by browser, and drops what the person deleted there since.
5
+ //
6
+ // It stays on this computer: never sent to Harness's server (no dream reads it), never in a brief (the person's local
7
+ // agents run on hosted models too), and recall shows it to the person's own searches only (default no, owner,
8
+ // October 22). Frames themselves stay in the browser; this keeps only their descriptions.
9
+
10
+ // The answering browser keeps what it last read for at most this many of the frames kept here.
11
+ const KEPT_REFS = 200;
12
+ const SHOWN = 6;
13
+
14
+ export function createSeen({
15
+ store,
16
+ askWindows,
17
+ // Whether Harness can carry a sealed question to the window now (connected, and it offers sealed_ask).
18
+ canAsk = () => true,
19
+ log = () => {},
20
+ }) {
21
+ const cursorKey = (browser) => `seen-cursor:${browser}`;
22
+ // Every browser read so far, kept apart from what it saw: one whose items were all forgotten keeps its place.
23
+ const browsers = () => {
24
+ try {
25
+ return JSON.parse(store.meta("seen-browsers") || "[]");
26
+ } catch {
27
+ return [];
28
+ }
29
+ };
30
+
31
+ /** One read from the person's window: { ok, kept, gone } or { ok: false, why }. */
32
+ const read = async () => {
33
+ if (!canAsk())
34
+ return { ok: false, why: "Harness cannot reach the person's window now" };
35
+ const known = browsers();
36
+ const reply = await askWindows({
37
+ tool: "screen_seen_since",
38
+ agent: "memory",
39
+ input: {
40
+ since: Object.fromEntries(
41
+ known.map((browser) => [
42
+ browser,
43
+ Number(store.meta(cursorKey(browser))) || 0,
44
+ ])
45
+ ),
46
+ kept: Object.fromEntries(
47
+ known.map((browser) => [browser, store.seenRefs(browser, KEPT_REFS)])
48
+ ),
49
+ },
50
+ });
51
+ if (!reply?.ok) return { ok: false, why: reply?.error || "no answer" };
52
+ let answer;
53
+ try {
54
+ answer = JSON.parse(reply.text);
55
+ } catch {
56
+ return { ok: false, why: "the window's answer was not readable" };
57
+ }
58
+ const browser = String(answer.browser || "");
59
+ if (!browser) return { ok: false, why: "the window did not say who it is" };
60
+ if (!known.includes(browser))
61
+ store.meta("seen-browsers", JSON.stringify([...known, browser]));
62
+ let kept = 0;
63
+ for (const item of answer.seen ?? [])
64
+ if (
65
+ Number.isInteger(item.ref) &&
66
+ typeof item.text === "string" &&
67
+ item.text.trim() &&
68
+ store.addSeen({
69
+ window: browser,
70
+ ref: item.ref,
71
+ at: new Date(Number(item.at)).toISOString(),
72
+ text: item.text.slice(0, 1_000),
73
+ frames: Number(item.frames) || 1,
74
+ })
75
+ )
76
+ kept++;
77
+ let gone = 0;
78
+ for (const ref of answer.gone ?? [])
79
+ if (store.removeSeen(`${browser}:${ref}`)) gone++;
80
+ if (Number.isFinite(answer.through))
81
+ store.meta(cursorKey(browser), String(answer.through));
82
+ if (kept || gone) log(`seen: kept ${kept}, dropped ${gone} deleted`);
83
+ return { ok: true, kept, gone };
84
+ };
85
+
86
+ const view = (row) => ({
87
+ id: row.id,
88
+ at: row.at,
89
+ text: row.text,
90
+ frames: row.frames,
91
+ });
92
+
93
+ return {
94
+ read,
95
+ /** What the person saw that matches a search of theirs, best first. */
96
+ matching: (query, limit = SHOWN) =>
97
+ store.seenMatching(query, limit).map(view),
98
+ list: (options) => store.seen(options).map(view),
99
+ /** The person forgets one by id: true when it was kept. */
100
+ forget: (id) => store.removeSeen(String(id)),
101
+ };
102
+ }