tryharness 0.7.69 → 0.7.71

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/cli.mjs CHANGED
@@ -35,7 +35,7 @@ import { backupCommand, offerBackup } from "./lib/backupSetup.mjs";
35
35
  import pc from "picocolors";
36
36
  import { removeLocalWakes } from "./lib/wakes.mjs";
37
37
  import { detectAgents } from "./lib/commands.mjs";
38
- import { nameOf } from "./lib/members.mjs";
38
+ import { PROPOSERS, nameOf } from "./lib/members.mjs";
39
39
  import { daemonRequest } from "./lib/control-client.mjs";
40
40
  import { ensureDir, readJson, writeJsonAtomic } from "./lib/files.mjs";
41
41
  import { hostApp, processTable } from "./lib/live.mjs";
@@ -1247,7 +1247,8 @@ async function board() {
1247
1247
  }
1248
1248
  // Standing permission: a coding agent starts the tasks you or Harness post for it without a Start. On by default
1249
1249
  // for the folders you have used it in; name folders and a daily cap instead, turn it off, or back on to the default.
1250
- // Tasks another agent wrote always wait for you.
1250
+ // Tasks another agent wrote wait for you, except a clean ask from one of your own agents elsewhere you named with
1251
+ // --from (Grok Bot, Muse) in a thread; --from none takes them back.
1251
1252
  if (sub === "standing") {
1252
1253
  const rest = argv
1253
1254
  .slice(argv.indexOf(sub) + 1)
@@ -1255,33 +1256,49 @@ async function board() {
1255
1256
  (value, index, all) =>
1256
1257
  !value.startsWith("--") &&
1257
1258
  all[index - 1] !== "--cap" &&
1258
- all[index - 1] !== "--as"
1259
+ all[index - 1] !== "--as" &&
1260
+ all[index - 1] !== "--from"
1259
1261
  );
1260
1262
  const [target, ...dirs] = rest;
1261
1263
  const usage =
1262
- "usage: tryharness board standing [<agent> <folder> [<folder>...] [--cap <runs a day, default 10>] | <agent> off | <agent> on]";
1264
+ "usage: tryharness board standing [<agent> <folder> [<folder>...] [--cap <runs a day, default 10>] | <agent> off | <agent> on | <agent> --from <agent>[,...] | <agent> --from none]";
1263
1265
  if (target && !AGENTS.includes(target)) throw new Error(usage);
1264
1266
  const toggle =
1265
1267
  dirs.length === 1 && ["on", "off"].includes(dirs[0]) ? dirs[0] : null;
1268
+ const from = argv.includes("--from") ? arg("--from", "") : null;
1269
+ const proposers =
1270
+ from === null
1271
+ ? undefined
1272
+ : from === "none"
1273
+ ? []
1274
+ : from.split(",").filter(Boolean);
1266
1275
  const response = !target
1267
1276
  ? await daemonRequest({ command: "board.standing", agent })
1268
- : toggle
1277
+ : proposers && !dirs.length
1269
1278
  ? await daemonRequest({
1270
- command: `board.standing.${toggle}`,
1279
+ command: "board.standing.set",
1271
1280
  agent,
1272
1281
  targetAgent: target,
1282
+ proposers,
1273
1283
  })
1274
- : dirs.length
1284
+ : toggle
1275
1285
  ? await daemonRequest({
1276
- command: "board.standing.set",
1286
+ command: `board.standing.${toggle}`,
1277
1287
  agent,
1278
1288
  targetAgent: target,
1279
- workspaces: dirs.map((dir) => path.resolve(dir)),
1280
- dailyCap: Number(arg("--cap", "10")),
1281
1289
  })
1282
- : (() => {
1283
- throw new Error(usage);
1284
- })();
1290
+ : dirs.length
1291
+ ? await daemonRequest({
1292
+ command: "board.standing.set",
1293
+ agent,
1294
+ targetAgent: target,
1295
+ workspaces: dirs.map((dir) => path.resolve(dir)),
1296
+ dailyCap: Number(arg("--cap", "10")),
1297
+ ...(proposers ? { proposers } : {}),
1298
+ })
1299
+ : (() => {
1300
+ throw new Error(usage);
1301
+ })();
1285
1302
  if (!response.ok)
1286
1303
  throw new Error(response.error || "standing permission failed");
1287
1304
  if (!response.standing.length) {
@@ -1301,8 +1318,14 @@ async function board() {
1301
1318
  ? `in the ${rule.workspaces.length} folder${rule.workspaces.length === 1 ? "" : "s"} you have used it in (${rule.workspaces.slice(0, 5).join(", ")}${rule.workspaces.length > 5 ? ", ..." : ""})`
1302
1319
  : "in folders you have used it in (none yet)"
1303
1320
  : `in ${rule.workspaces.join(", ")}`;
1321
+ const everyone = PROPOSERS.every((name) =>
1322
+ rule.proposers?.includes(name)
1323
+ );
1324
+ const from = rule.proposers?.length
1325
+ ? `, and on clean asks from ${everyone ? "any of your agents" : rule.proposers.join(", ")} (stop: ${relayCommand()} board standing ${rule.agent} --from none)`
1326
+ : "";
1304
1327
  console.log(
1305
- `${rule.agent} starts tasks from you or Harness without asking, ${where}; ${rule.runs_today} of ${rule.daily_cap} today. Turn it off: ${relayCommand()} board standing ${rule.agent} off`
1328
+ `${rule.agent} starts tasks from you or Harness without asking${from}, ${where}; ${rule.runs_today} of ${rule.daily_cap} today. Turn it off: ${relayCommand()} board standing ${rule.agent} off`
1306
1329
  );
1307
1330
  }
1308
1331
  return;
@@ -3,7 +3,7 @@ import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { spawn, spawnSync } from "node:child_process";
5
5
  import { randomBytes } from "node:crypto";
6
- import { secretReason } from "./secrets.mjs";
6
+ import { maskReason } from "./secrets.mjs";
7
7
 
8
8
  const { cloud: CLOUD_LIST } = JSON.parse(
9
9
  fs.readFileSync(new URL("./members.json", import.meta.url), "utf8")
@@ -148,7 +148,7 @@ const clean = (text) =>
148
148
  .map((line) => line.trimEnd())
149
149
  .filter(Boolean)
150
150
  .map((line) =>
151
- secretReason(line)
151
+ maskReason(line)
152
152
  ? "(something secret was printed here; it stays on this computer)"
153
153
  : line
154
154
  );
@@ -17,13 +17,12 @@ export function createBoardCommands({
17
17
  const agent = String(request.agent);
18
18
  // The computer the call came from: this one, or a worker whose call home opened (ownMachines.mjs).
19
19
  const machine = machineOf(request);
20
- const lastLooked = store.lastSeenAt(agent, machine);
21
20
  store.touchAgent(agent, machine);
22
21
  const id = String(request.id || "");
23
22
  const expected = Number.isInteger(request.expectedVersion)
24
23
  ? request.expectedVersion
25
24
  : null;
26
- const context = { agent, lastLooked, id, expected, machine };
25
+ const context = { agent, id, expected, machine };
27
26
  const owner = boardCommandOwner(String(request.command));
28
27
  const handler = Object.hasOwn(handlers, owner) ? handlers[owner] : task;
29
28
  return handler(request, context);
package/lib/cards.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { computerHandle } from "./ownMachines.mjs";
1
+ import { computerHandle } from "./computerAddress.mjs";
2
2
  import { createHash } from "node:crypto";
3
3
  import { member, nameOf } from "./members.mjs";
4
4
  import { agentModelInUse, describeAgentModel } from "./models.mjs";
@@ -272,7 +272,7 @@ export function cardLine(card, now = Date.now(), { evidence = true } = {}) {
272
272
  if (specialties) parts.push(specialties);
273
273
  if (card.machines?.length)
274
274
  parts.push(
275
- `On the person's computers: ${card.machines.map((computer) => `${card.name} (${computer.label}${computer.online ? "" : ", offline"})`).join(", ")}; name one with # in a thread (@${card.id === "claude-code" ? "claude" : card.id} #${computerHandle(card.machines[0].label)}), or target_machine on a task.`
275
+ `On the person's computers: ${card.machines.map((computer) => `${card.name} (${computer.label}${computer.online ? "" : ", offline"})`).join(", ")}; name one in a thread (@${card.id} on ${computerHandle(card.machines[0].label)}), or with target_machine on a task, thread or post.`
276
276
  );
277
277
  parts.push(sentence(card.answers));
278
278
  const { done, failed, ended, medianMinutes } = card.record;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Which of the person's computers a message sends its agents to. Three ways name one, all the same choice:
3
+ *
4
+ * - `#pop-os` anywhere in the words: every agent the message wakes works there (the composers' menus write this);
5
+ * - `@claude-code on pop-os`: only that agent works there, as people and agents write it in plain words;
6
+ * - a typed computer the caller passes alongside the words (an agent's `target_machine`), for every agent it wakes.
7
+ *
8
+ * A computer is named only by one of the person's own computers' exact name or handle; "Claude on MacBook" with no @ and
9
+ * "@codex on this bug" name none. Two different computers for the same agent, or a typed computer no one has, are a
10
+ * refusal, never a silent pick: the caller says why rather than running the work on Home.
11
+ */
12
+ /**
13
+ * How a computer is written after # in a message ("Work Mac" is #Work-Mac): its name with spaces as dashes and anything
14
+ * but letters, digits, dots, dashes and underscores left out. Every menu writes it this way and computerAddress reads it.
15
+ */
16
+ export const computerHandle = (label) =>
17
+ String(label ?? "")
18
+ .trim()
19
+ .replace(/\s+/g, "-")
20
+ .replace(/[^\w.-]/g, "");
21
+
22
+ // Punctuation that may close a computer's name in a sentence ("on pop-os:", "#linux."), before a space or the end.
23
+ const CLOSES_NAME = /^[.,;:!?)]*(?:\s|$)/;
24
+
25
+ const asChoice = (computer) => ({ id: computer.id, label: computer.label });
26
+
27
+ // A computer's names in any case: as the person called it and as it is written after #.
28
+ const namesOf = (computer) =>
29
+ [computerHandle(computer.label), String(computer.label ?? "").trim()]
30
+ .filter(Boolean)
31
+ .map((name) => name.toLowerCase());
32
+
33
+ /** The computers whose name or handle `text` starts with, ending where a name ends. */
34
+ const computersAtStart = (text, computers) => {
35
+ const lower = text.toLowerCase();
36
+ return computers.filter((computer) =>
37
+ namesOf(computer).some(
38
+ (name) =>
39
+ lower.startsWith(name) && CLOSES_NAME.test(text.slice(name.length))
40
+ )
41
+ );
42
+ };
43
+
44
+ const listOf = (computers) =>
45
+ computers.map((computer) => computer.label || computer.id).join(", ");
46
+
47
+ /**
48
+ * The computers `text` names, for the agents it wakes. `computers`: every computer of the person's ([{ id, label }]).
49
+ * `target`: a typed computer name or id. `agentOf`: an @ name to the agent's id ("claude" is claude-code), null for
50
+ * anything else. Returns { ok: true, forAgent(agent) → { id, label } | null } or { ok: false, error }.
51
+ */
52
+ export function computerAddress({
53
+ text,
54
+ computers,
55
+ target = null,
56
+ recipient = null,
57
+ agentOf = (name) => name,
58
+ }) {
59
+ const refuse = (error) => ({ ok: false, error });
60
+ const original = String(text ?? "");
61
+ // A task already names its recipient in a typed field; "On pop-os: ..." is the same address without repeating @agent.
62
+ const words =
63
+ recipient && /^\s*on\s+/i.test(original)
64
+ ? `@${recipient} ${original.trimStart()}`
65
+ : original;
66
+ let typed = null;
67
+ if (target != null && String(target).trim()) {
68
+ const wanted = String(target).trim();
69
+ const byId = computers.find((computer) => computer.id === wanted);
70
+ const found = byId
71
+ ? [byId]
72
+ : computers.filter((computer) =>
73
+ namesOf(computer).includes(wanted.toLowerCase())
74
+ );
75
+ if (!found.length)
76
+ return refuse(
77
+ `No computer is called "${target}". Your computers: ${listOf(computers)}.`
78
+ );
79
+ if (found.length > 1)
80
+ return refuse(
81
+ `"${target}" could be ${listOf(found)}: give the computer's id from list_agents`
82
+ );
83
+ typed = asChoice(found[0]);
84
+ }
85
+ // With one computer, an unrelated # remains ordinary text.
86
+ const several = computers.length > 1;
87
+
88
+ const tagged = new Map();
89
+ if (several)
90
+ for (const match of words.matchAll(/(?:^|[\s(])#([A-Za-z0-9][\w.-]*)/g)) {
91
+ const name = match[1].replace(/[.,;:!?]+$/, "").toLowerCase();
92
+ const found = computers.filter(
93
+ (computer) => computerHandle(computer.label).toLowerCase() === name
94
+ );
95
+ if (found.length > 1)
96
+ return refuse(
97
+ `#${match[1]} could be ${listOf(found)}: rename one so each has its own name`
98
+ );
99
+ if (found.length) tagged.set(found[0].id, found[0]);
100
+ }
101
+ if (tagged.size > 1)
102
+ return refuse(
103
+ `the message names more than one computer with # (${listOf([...tagged.values()])}); name one`
104
+ );
105
+ const hashed = tagged.size ? asChoice([...tagged.values()][0]) : null;
106
+ if (typed && hashed && typed.id !== hashed.id)
107
+ return refuse(
108
+ `the message names ${hashed.label} with # but the computer given is ${typed.label}; name one`
109
+ );
110
+ const shared = typed ?? hashed;
111
+
112
+ const pins = new Map();
113
+ for (const match of words.matchAll(
114
+ /@([a-z][a-z0-9-]*)(?::\S+)?\s+on\s+#?/gi
115
+ )) {
116
+ const agent = agentOf(match[1].toLowerCase());
117
+ if (!agent) continue;
118
+ const after = words.slice(match.index + match[0].length);
119
+ const found = computersAtStart(after, computers);
120
+ if (!found.length) {
121
+ // A # or a computer-shaped handle makes an unknown address explicit. A plain phrase before a colon can be
122
+ // ordinary prose ("on this:", "On Monday:"), so it does not choose or refuse a computer.
123
+ const unknown = after.match(/^([\w.-]+(?: [\w.-]+)*):(?:\s|$)/)?.[1];
124
+ const explicit =
125
+ match[0].endsWith("#") ||
126
+ (unknown && /^[\w.-]+$/.test(unknown) && /[-._\d]/.test(unknown));
127
+ if (several && unknown && explicit)
128
+ return refuse(
129
+ `No computer is called "${unknown}". Your computers: ${listOf(computers)}.`
130
+ );
131
+ continue;
132
+ }
133
+ if (found.length > 1)
134
+ return refuse(
135
+ `"@${match[1]} on" could mean ${listOf(found)}: rename one so each has its own name`
136
+ );
137
+ const chosen = asChoice(found[0]);
138
+ const earlier = pins.get(agent) ?? shared;
139
+ if (earlier && earlier.id !== chosen.id)
140
+ return refuse(
141
+ `the message sends @${match[1]} to both ${earlier.label} and ${chosen.label}; name one computer`
142
+ );
143
+ pins.set(agent, chosen);
144
+ }
145
+ return {
146
+ ok: true,
147
+ shared,
148
+ forAgent: (agent) => pins.get(agent) ?? shared,
149
+ };
150
+ }
@@ -364,9 +364,11 @@ export function createCoordinator({
364
364
  );
365
365
  // The route: where it stands, or none yet, which the person's message to the swarm triages (on the privacy setting,
366
366
  // this computer's next round). A round that starts the next piece a framer split off routes it with the same facts.
367
- const teamView = keepsTeams()
368
- ? team.roundView(thread.id, runs, { head: headOf(thread.id) })
369
- : null;
367
+ const repairRoute = keepsTeams() && team.needsRouting(thread.id);
368
+ const teamView =
369
+ keepsTeams() && !repairRoute
370
+ ? team.roundView(thread.id, runs, { head: headOf(thread.id) })
371
+ : null;
370
372
  if (teamView && !keepsPlacement())
371
373
  teamView.steps = teamView.steps.map(({ machines, ...step }) => step);
372
374
  const pins = keepsTeams() ? pinsNow() : {};
@@ -376,7 +378,7 @@ export function createCoordinator({
376
378
  };
377
379
  const teamFacts = teamView
378
380
  ? { team: teamView, ...(teamView.nextPiece ? routing : {}) }
379
- : keepsTeams() && (asked || mode() === "local")
381
+ : keepsTeams() && (asked || mode() === "local" || repairRoute)
380
382
  ? { team: null, ...routing }
381
383
  : {};
382
384
  // Earlier words close in meaning to the newest post that the transcript no longer carries, from this thread and the
@@ -686,7 +688,7 @@ export function createCoordinator({
686
688
  const message = asked?.seq
687
689
  ? store.roomPosts(thread.id, asked.seq - 1, 1)[0]
688
690
  : null;
689
- return message?.seq === asked?.seq ? message.created_at : null;
691
+ return message && message.seq === asked?.seq ? message.created_at : null;
690
692
  };
691
693
  const applyTeamPlan = (thread, decision, coordinator, asked = null) => {
692
694
  const proposed = decision.team?.plan;
@@ -694,7 +696,7 @@ export function createCoordinator({
694
696
  !proposed ||
695
697
  decision.team?.step === "piece" ||
696
698
  !keepsTeams() ||
697
- team.plan(thread.id)
699
+ (team.plan(thread.id) && !team.needsRouting(thread.id))
698
700
  )
699
701
  return null;
700
702
  // The route answers the person's message: its first step began when they sent it (team.mjs set).
@@ -854,7 +856,7 @@ export function createCoordinator({
854
856
  given.team?.plan &&
855
857
  given.team.step !== "piece" &&
856
858
  keepsTeams() &&
857
- !team.plan(thread.id)
859
+ (!team.plan(thread.id) || team.needsRouting(thread.id))
858
860
  ) {
859
861
  pauseGoal(
860
862
  thread.id,
@@ -864,6 +866,19 @@ export function createCoordinator({
864
866
  return;
865
867
  }
866
868
  const decision = guardQuestion(thread, given, candidates, rules);
869
+ if (
870
+ keepsTeams() &&
871
+ team.needsRouting(thread.id) &&
872
+ ["hand_on", "assemble"].includes(decision.action) &&
873
+ decision.team?.step !== "piece"
874
+ ) {
875
+ pauseGoal(
876
+ thread.id,
877
+ "The saved route needs an executable replacement before another agent can start."
878
+ );
879
+ notifyBoard(store.getTask(thread.id));
880
+ return;
881
+ }
867
882
  // The person's message is never met with silence: a round that brings no one in and asks them nothing lets the
868
883
  // agents hear it as they wrote it, as with `@swarm`. That is the fallback whenever Jev does not understand the
869
884
  // message. A message naming an agent is not silent: that agent has it.
@@ -1147,9 +1162,11 @@ export function createCoordinator({
1147
1162
  const assembling = Boolean(asked) && assembles();
1148
1163
  const resumedNow = store.meta(`coordinator-resumed:${goalId}`) === "1";
1149
1164
  const inventoryWaiting = Boolean(store.meta(`inventory-wait:${goalId}`));
1165
+ const repairRoute = keepsTeams() && team.needsRouting(goalId);
1150
1166
  if (
1151
1167
  !assembling &&
1152
- (active || (!posts.length && !resumedNow && !inventoryWaiting))
1168
+ (active ||
1169
+ (!posts.length && !resumedNow && !inventoryWaiting && !repairRoute))
1153
1170
  ) {
1154
1171
  if (posts.length) await keepGoalNow(thread, state);
1155
1172
  return;
package/lib/daemon.mjs CHANGED
@@ -102,7 +102,11 @@ import { createRunBriefs } from "./runBrief.mjs";
102
102
  import { createHandover } from "./handover.mjs";
103
103
  import { createCompaction } from "./compaction.mjs";
104
104
  import { oneLine } from "./oneLine.mjs";
105
- import { createRunAuthority, RUN_CALLER } from "./runAuthority.mjs";
105
+ import {
106
+ createRunAuthority,
107
+ HOSTED_CALLER,
108
+ RUN_CALLER,
109
+ } from "./runAuthority.mjs";
106
110
  import { createActorRoster } from "./actorRoster.mjs";
107
111
  import { createLineup, createLineupCommands } from "./lineup.mjs";
108
112
  import {
@@ -393,7 +397,9 @@ export async function startDaemon() {
393
397
  task.target_agent === agent &&
394
398
  task.claimed_machine === from &&
395
399
  ["claimed", "running"].includes(task.status) &&
396
- !restrictedRun(store, task)
400
+ !restrictedRun(store, task) &&
401
+ // A start on another agent's ask grants no secrets (runAuthority.mjs admitPosted).
402
+ !store.standingProposal(taskId)
397
403
  );
398
404
  },
399
405
  // The run an agent's call is part of: the one it names when it holds it, or its only run on that computer.
@@ -1481,6 +1487,7 @@ export async function startDaemon() {
1481
1487
  swarmCommand: (...args) => swarmCommand(...args),
1482
1488
  validAgent,
1483
1489
  wakeFor: actions.wakeFor,
1490
+ computerAddress: actions.computerAddress,
1484
1491
  resumed: (id) => coordinator.resumed(id),
1485
1492
  files: boardFiles,
1486
1493
  });
@@ -1929,6 +1936,7 @@ export async function startDaemon() {
1929
1936
  roomAgents: ROOM_AGENTS,
1930
1937
  mentionsIn,
1931
1938
  wakeFor: actions.wakeFor,
1939
+ computerAddress: actions.computerAddress,
1932
1940
  notifyBoard,
1933
1941
  goalCommand,
1934
1942
  stopThreadRuns,
@@ -2173,6 +2181,7 @@ export async function startDaemon() {
2173
2181
  dispatches,
2174
2182
  promptFlow,
2175
2183
  outside: () => environments,
2184
+ readByGuard: (text) => local.readByGuard(text),
2176
2185
  CLOUD_TARGETS,
2177
2186
  desk,
2178
2187
  OPENED,
@@ -2657,6 +2666,7 @@ export async function startDaemon() {
2657
2666
  },
2658
2667
  log,
2659
2668
  modelFor: modelForRun,
2669
+ held: () => worker.held(),
2660
2670
  });
2661
2671
  network = createNetwork({
2662
2672
  store,
@@ -3042,7 +3052,12 @@ export async function startDaemon() {
3042
3052
  ok: true,
3043
3053
  stopped: worker.interruptAll(request.reason),
3044
3054
  }),
3045
- "runs.hold": (request) => ({ ok: true, held: worker.hold(request.on) }),
3055
+ "runs.hold": (request) => {
3056
+ const held = worker.hold(request.on);
3057
+ // A worker's held runs include the work home lists for it (machineRuns.mjs).
3058
+ if (!held) void machineRuns.check();
3059
+ return { ok: true, held };
3060
+ },
3046
3061
  // A board run's brief, section by section: as a run would get it now (dry run, nothing written), or as one got it.
3047
3062
  "runs.brief": (request) => {
3048
3063
  const task = store.getTask(String(request.id || ""));
@@ -3290,6 +3305,7 @@ export async function startDaemon() {
3290
3305
  ...(message.input || {}),
3291
3306
  command: String(message.input?.command || ""),
3292
3307
  hostedCaller: true,
3308
+ [HOSTED_CALLER]: true,
3293
3309
  });
3294
3310
  } catch (error) {
3295
3311
  return {
package/lib/firewall.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { secretReason } from "./secrets.mjs";
1
+ import { maskReason } from "./secrets.mjs";
2
2
  import { personalSpans } from "./personal.mjs";
3
3
 
4
4
  // The handoff firewall: two small local models on the text agents pass each other. Inbound, an injection guard reads
@@ -149,8 +149,7 @@ export function createFirewall({ inference, log = () => {} }) {
149
149
  });
150
150
  const candidates = lines.filter(
151
151
  ({ line }) =>
152
- line.length <= 2_000 &&
153
- (CANDIDATE_LINE.test(line) || secretReason(line))
152
+ line.length <= 2_000 && (CANDIDATE_LINE.test(line) || maskReason(line))
154
153
  );
155
154
  let probabilities = [];
156
155
  if (candidates.length) {
@@ -173,14 +172,14 @@ export function createFirewall({ inference, log = () => {} }) {
173
172
  }
174
173
  }
175
174
  candidates.forEach(({ line, start }, i) => {
176
- const flagged = (probabilities[i] ?? 0) >= 0.74 || secretReason(line);
175
+ const flagged = (probabilities[i] ?? 0) >= 0.74 || maskReason(line);
177
176
  if (!flagged) return;
178
177
  const span = secretSpan(line);
179
178
  if (span)
180
179
  spans.push({
181
180
  start: start + span.at,
182
181
  end: start + span.at + span.text.length,
183
- reason: secretReason(line) || "a credential",
182
+ reason: maskReason(line) || "a credential",
184
183
  });
185
184
  });
186
185
  return spans.sort((a, b) => a.start - b.start);
@@ -9,7 +9,7 @@ import { TAGGED_ONLY, nameOf } from "./members.mjs";
9
9
  import { picksIn } from "./models.mjs";
10
10
  import { roomPage } from "./roomPage.mjs";
11
11
  import { FROM_MACHINE, withComputer } from "./machineRoutes.mjs";
12
- import { callerLimit } from "./runAuthority.mjs";
12
+ import { callerLimit, HOSTED_CALLER } from "./runAuthority.mjs";
13
13
 
14
14
  export function createGoalCommands({
15
15
  DEFAULT_MAX_POSTS,
@@ -40,6 +40,8 @@ export function createGoalCommands({
40
40
  swarmCommand,
41
41
  validAgent,
42
42
  wakeFor,
43
+ // The computers a post sends its agents to (threadActions.mjs computerAddress).
44
+ computerAddress,
43
45
  resumed,
44
46
  files: boardFiles,
45
47
  // The thread's team (team.mjs): an agent's note on what it learned in its role.
@@ -314,6 +316,13 @@ export function createGoalCommands({
314
316
  agent === "user" || agent === "harness"
315
317
  ? mentions
316
318
  : [...new Set([...asked, ...answered])];
319
+ // A computer chosen for the agents it wakes that cannot be read refuses the post, which then wakes no one on
320
+ // Home in its place (computerAddress.mjs).
321
+ const target = request.targetMachine ?? null;
322
+ if (wakes.length || target) {
323
+ const address = computerAddress(text, agent, { target });
324
+ if (!address.ok) return { ok: false, error: address.error };
325
+ }
317
326
  for (const name of answered) store.meta(waitingKey(name, agent), "");
318
327
  if (agent !== "user" && agent !== "harness")
319
328
  for (const name of asked) store.meta(waitingKey(agent, name), "1");
@@ -367,6 +376,9 @@ export function createGoalCommands({
367
376
  !["user", "harness"].includes(agent)),
368
377
  limited: callerLimit(request),
369
378
  window: request.fromWindow === true,
379
+ target: request.targetMachine ?? null,
380
+ // Harness's server itself, which no local or other computer's caller can claim (runAuthority.mjs).
381
+ server: request[HOSTED_CALLER] === true,
370
382
  guard: verdict ?? {
371
383
  score: null,
372
384
  verdict: "clean",
@@ -43,6 +43,8 @@ export function createMachineRuns({
43
43
  // The model and effort the run starts with, from the person's choice here (models.mjs createModelRouter): a choice
44
44
  // for an agent is kept on the computer that runs it, so it is read here, not on home.
45
45
  modelFor = async () => null,
46
+ // The person holds new runs on this computer (runWorker.mjs hold): none of home's work starts here meanwhile.
47
+ held = () => false,
46
48
  }) {
47
49
  const active = new Map();
48
50
  const steps = new Map();
@@ -66,9 +68,12 @@ export function createMachineRuns({
66
68
  clearTimeout(steps.get(taskId)?.timer);
67
69
  steps.delete(taskId);
68
70
  };
69
- // A thread with no folder: its turn here works in that thread's scratch folder on this computer (scratch.mjs).
71
+ // A thread with no folder: its turn here works in that thread's scratch folder on this computer (scratch.mjs), as
72
+ // does a task naming no folder that home says goes there (taskCommands.mjs forWorker).
70
73
  const inScratch = (task) =>
71
- !task.run_workspace && task.kind === "wake" && Boolean(task.parent_id);
74
+ !task.run_workspace &&
75
+ Boolean(task.parent_id) &&
76
+ (task.kind === "wake" || (task.kind === "task" && task.scratch === true));
72
77
  const slotOf = (task) =>
73
78
  task.run_workspace
74
79
  ? path.resolve(task.run_workspace)
@@ -120,12 +125,17 @@ export function createMachineRuns({
120
125
  return { env: answer.env, scrub };
121
126
  };
122
127
 
123
- const start = async (task, slot) => {
128
+ // What a run needs before it starts here, made before home hands it over: a start on another agent's ask is checked
129
+ // again by home as it is taken (board.machine.take), and nothing is awaited between that answer and the start.
130
+ const prepare = async (task) => ({
131
+ chosen: await modelFor(task, task.target_agent).catch(() => null),
132
+ cwd: inScratch(task) ? await scratchFor(task) : task.run_workspace,
133
+ });
134
+ const start = async (task, slot, { chosen, cwd }) => {
124
135
  const agent = task.target_agent;
125
136
  log(`running ${agent}'s task ${task.id} from your home computer`);
126
- const secrets = await secretsFor(task, agent);
127
- const chosen = await modelFor(task, agent).catch(() => null);
128
- const cwd = inScratch(task) ? await scratchFor(task) : task.run_workspace;
137
+ // A start on another of the person's agents' asks on standing permission grants no secrets (runAuthority.mjs).
138
+ const secrets = task.standing ? {} : await secretsFor(task, agent);
129
139
  // Sent again with the finish: the two calls go to home at once, and a finish that arrives first closes the run to
130
140
  // the session call (two-machines: home kept no session, one run in four).
131
141
  let session = null;
@@ -238,16 +248,52 @@ export function createMachineRuns({
238
248
  continue;
239
249
  }
240
250
  const slot = slotOf(task);
241
- if (active.has(slot)) continue;
251
+ if (held() || active.has(slot)) continue;
252
+ active.set(slot, task.id);
253
+ const prepared = await prepare(task).catch(() => null);
254
+ // Preparing awaited the model and home's files: a hold or a changed folder since then starts nothing.
255
+ const refusedNow = prepared ? refusalFor(task) : null;
256
+ if (!prepared || held() || refusedNow) {
257
+ active.delete(slot);
258
+ if (refusedNow) await refuse(task, refusedNow);
259
+ continue;
260
+ }
242
261
  const taken = await callHome({
243
262
  command: "board.machine.take",
244
263
  agent: task.target_agent,
245
264
  id: task.id,
246
265
  expectedVersion: task.version,
247
266
  });
248
- if (!taken?.ok) continue;
249
- active.set(slot, task.id);
250
- void start(taken.task, slot);
267
+ if (!taken?.ok) {
268
+ active.delete(slot);
269
+ continue;
270
+ }
271
+ // What home handed over is what was prepared: the same agent, folder and kind of place, still one this
272
+ // computer runs in. Anything else is ended with why, since it is taken now.
273
+ const changed = held()
274
+ ? "This computer is holding new runs, so it did not start."
275
+ : taken.task.target_agent !== task.target_agent ||
276
+ (taken.task.run_workspace ?? null) !==
277
+ (task.run_workspace ?? null) ||
278
+ inScratch(taken.task) !== inScratch(task)
279
+ ? "It changed on your home computer while this computer was getting it ready, so it did not start."
280
+ : refusalFor(taken.task);
281
+ if (changed) {
282
+ active.delete(slot);
283
+ log(
284
+ `did not run task ${task.id} from your home computer: ${changed}`
285
+ );
286
+ await callHome({
287
+ command: "board.machine.finish",
288
+ agent: task.target_agent,
289
+ id: task.id,
290
+ status: "failed",
291
+ result: changed,
292
+ failure: "start",
293
+ });
294
+ continue;
295
+ }
296
+ void start(taken.task, slot, prepared);
251
297
  }
252
298
  } finally {
253
299
  asking = false;