tryharness 0.7.68 → 0.7.70

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.
@@ -22,9 +22,16 @@ import {
22
22
  } from "./cards.mjs";
23
23
  import { PICKABLE, resolvePick, setRunPick } from "./models.mjs";
24
24
  import { onMachine, placeTask } from "./machineRoutes.mjs";
25
+ import { computerAddress } from "./computerAddress.mjs";
25
26
  import { within } from "./folders.mjs";
26
27
  import { recordClaims } from "./audit.mjs";
27
- import { limitedCaller, RUN_CALLER } from "./runAuthority.mjs";
28
+ import {
29
+ HOSTED_CALLER,
30
+ limitedCaller,
31
+ PROPOSERS,
32
+ RUN_CALLER,
33
+ } from "./runAuthority.mjs";
34
+ import { prepareScratch, threadScratch } from "./scratch.mjs";
28
35
 
29
36
  // An agent working in a thread may bring another agent in for part of the work there, as Harness does when it names
30
37
  // one; an agent that moves money or takes positions joins only when the person names it (members.mjs TAGGED_ONLY).
@@ -83,9 +90,17 @@ export function createTaskCommands({
83
90
  yourTurns,
84
91
  authority,
85
92
  actors,
93
+ dispatches = null,
94
+ promptFlow = null,
86
95
  files: boardFiles,
87
96
  // Threads mirrored from another app (environments.mjs), when the person reads them here.
88
97
  outside = () => null,
98
+ // The local injection guard's reading of words (localStack.mjs readByGuard).
99
+ readByGuard = async () => ({
100
+ score: null,
101
+ verdict: "clean",
102
+ unavailable: true,
103
+ }),
89
104
  }) {
90
105
  // The one open thread an agent is working in now, when the work it hands on may join it there.
91
106
  const soleThreadOf = (agent, target, folder) => {
@@ -152,7 +167,23 @@ export function createTaskCommands({
152
167
  }),
153
168
  };
154
169
  };
155
- return (request, { agent, id, expected, lastLooked, machine }) => {
170
+ // What a worker is told of a task home lists for it, sealed like every answer between the person's computers
171
+ // (machineRuns.mjs): started on another agent's ask on standing permission, so it gets none of the person's secrets,
172
+ // and, naming no folder, run in its thread's scratch folder there.
173
+ const forWorker = (task) => ({
174
+ ...task,
175
+ standing: Boolean(store.standingProposal(task.id)),
176
+ scratch: !task.run_workspace && task.kind === "task" && !!task.parent_id,
177
+ });
178
+ return (request, { agent, id, expected, machine }) => {
179
+ if (request.command.startsWith("board.prompt."))
180
+ return promptFlow
181
+ ? promptFlow.command(request, { agent, id, machine })
182
+ : { ok: false, error: "prompt execution is unavailable" };
183
+ if (request.command.startsWith("board.dispatch."))
184
+ return dispatches
185
+ ? dispatches.command(request, { agent, id, machine })
186
+ : { ok: false, error: "typed dispatch is unavailable" };
156
187
  let outcome;
157
188
  // A call from one of the person's other computers, which home answers on its board (ownMachines.mjs).
158
189
  const fromElsewhere = Boolean(machine) && machine !== machines.self();
@@ -180,6 +211,70 @@ export function createTaskCommands({
180
211
  };
181
212
  }
182
213
  if (request.command === "board.post") {
214
+ if (Object.hasOwn(request, "promptDispatch")) {
215
+ if (typeof request.promptDispatch !== "boolean")
216
+ return { ok: false, error: "invalid prompt dispatch mode" };
217
+ if (request.promptDispatch) {
218
+ const promptFields = new Set([
219
+ "command",
220
+ "agent",
221
+ "id",
222
+ "callerPid",
223
+ "objective",
224
+ "brief",
225
+ "runWorkspace",
226
+ "requestRef",
227
+ "promptDispatch",
228
+ ]);
229
+ if (Object.keys(request).some((key) => !promptFields.has(key)))
230
+ return {
231
+ ok: false,
232
+ error: "unsupported prompt dispatch arguments",
233
+ };
234
+ if (
235
+ agent !== "user" ||
236
+ request[RUN_CALLER] ||
237
+ request.hostedCaller ||
238
+ request.parentId ||
239
+ request.thread ||
240
+ request.targetAgent ||
241
+ request.targetAgents ||
242
+ request.targetMachine ||
243
+ request.deferDispatch ||
244
+ request.review ||
245
+ request.inSession ||
246
+ request.model
247
+ )
248
+ return {
249
+ ok: false,
250
+ error:
251
+ "prompt dispatch requires an owner prompt and its workspace context",
252
+ };
253
+ return dispatches.command(
254
+ {
255
+ command: "board.dispatch.prompt",
256
+ agent,
257
+ prompt: [
258
+ String(request.objective || ""),
259
+ String(request.brief || ""),
260
+ ]
261
+ .filter(Boolean)
262
+ .join("\n\n"),
263
+ runWorkspace: request.runWorkspace,
264
+ requestRef: request.requestRef ?? request.id,
265
+ },
266
+ { agent, id, machine }
267
+ );
268
+ }
269
+ }
270
+ if (
271
+ (Object.hasOwn(request, "deferDispatch") &&
272
+ typeof request.deferDispatch !== "boolean") ||
273
+ (Object.hasOwn(request, "dispatchStarts") &&
274
+ (request.deferDispatch !== true ||
275
+ ![0, 1].includes(request.dispatchStarts)))
276
+ )
277
+ return { ok: false, error: "invalid typed dispatch options" };
183
278
  const objective = String(request.objective || "").trim();
184
279
  if (!objective) return { ok: false, error: "a task needs an objective" };
185
280
  // A thread with another person themselves (not one of their agents) is the person's own: no agent here claims or runs it.
@@ -270,6 +365,23 @@ export function createTaskCommands({
270
365
  viaServer: request.hostedCaller === true,
271
366
  });
272
367
  const goalParent = parentTask?.kind === "goal" ? parentTask : null;
368
+ const deferred = request.deferDispatch === true;
369
+ if (
370
+ deferred &&
371
+ (agent !== "user" ||
372
+ provenance.trust !== "user" ||
373
+ request[RUN_CALLER] ||
374
+ request.hostedCaller ||
375
+ request.thread ||
376
+ request.parentId ||
377
+ request.targetAgents ||
378
+ ![0, 1].includes(request.dispatchStarts ?? 1))
379
+ )
380
+ return {
381
+ ok: false,
382
+ error:
383
+ "only the owner can stage an exact local run with a zero-or-one start limit",
384
+ };
273
385
  if (goalParent) {
274
386
  if (!inRoom(goalParent, agent))
275
387
  return { ok: false, error: `${agent} is not on this goal's team` };
@@ -345,11 +457,27 @@ export function createTaskCommands({
345
457
  }
346
458
  // Which of the person's computers the work is for: the one named, else the poster's own when it works there in a
347
459
  // folder, else the one with the agent and the thread's repository, else the only one with the agent.
460
+ const recipient = String(request.targetAgent || "");
461
+ const address =
462
+ !request.thread && authority.RUNNERS.has(recipient)
463
+ ? computerAddress({
464
+ text: objective,
465
+ computers: machines.all(),
466
+ target: request.targetMachine ?? null,
467
+ recipient,
468
+ agentOf: (name) => {
469
+ const found = resolveMember(name);
470
+ return found.ok ? found.id : null;
471
+ },
472
+ })
473
+ : null;
474
+ if (address && !address.ok) return { ok: false, error: address.error };
348
475
  const placed = request.thread
349
476
  ? { ok: true, machine: null }
350
477
  : placeTask({
351
478
  agent: request.targetAgent ? String(request.targetAgent) : null,
352
- named: request.targetMachine ?? null,
479
+ named:
480
+ address?.forAgent(recipient)?.id ?? request.targetMachine ?? null,
353
481
  machines: machines.all(),
354
482
  poster:
355
483
  fromElsewhere && typeof request.posterCwd === "string"
@@ -509,7 +637,7 @@ export function createTaskCommands({
509
637
  // Asking for a run in a folder is the person's Start; a scratch folder they never asked for goes by standing permission.
510
638
  runWorkspace: thread ? null : runWorkspace,
511
639
  runAuthorizedBy:
512
- !thread && runWorkspace && !scratch && agent === "user"
640
+ !deferred && !thread && runWorkspace && !scratch && agent === "user"
513
641
  ? "user"
514
642
  : null,
515
643
  targetMachine,
@@ -525,6 +653,22 @@ export function createTaskCommands({
525
653
  getProjects()?.channelOpened(task.id);
526
654
  }
527
655
  if (pick) setRunPick(store, task.id, pick, agent);
656
+ if (deferred) {
657
+ try {
658
+ if (!dispatches) throw new Error("typed dispatch is unavailable");
659
+ dispatches.stage(store.getTask(task.id), request.dispatchStarts ?? 1);
660
+ notifyBoard(store.getTask(task.id));
661
+ return { ok: true, task: store.getTask(task.id) };
662
+ } catch (error) {
663
+ store.failUnstartedDispatch(task.id, error.message);
664
+ notifyBoard(store.getTask(task.id));
665
+ return {
666
+ ok: false,
667
+ error: error.message,
668
+ task: store.getTask(task.id),
669
+ };
670
+ }
671
+ }
528
672
  // A job in a goal's room runs on the goal's authority; anywhere else, standing permission decides. The goal covers
529
673
  // jobs from the person, Harness and the coding agents on this machine, with the person's go (personsGo) unless an
530
674
  // agent's words came from above the poster; a job from a member that runs elsewhere (Grok Bot, Muse, a connected
@@ -600,13 +744,59 @@ export function createTaskCommands({
600
744
  const note = task.target_agent
601
745
  ? actors.setupNote(task.target_agent)
602
746
  : null;
603
- outcome = {
747
+ const posted = (started) => ({
604
748
  ok: true,
605
749
  task: labelled(store.getTask(task.id)),
606
750
  thread: thread ? store.getThread(task.id) : null,
607
- ...(standing ? { standing } : {}),
751
+ ...(started ? { standing: started } : {}),
608
752
  ...(note ? { note } : {}),
609
- };
753
+ });
754
+ // A task one of the person's own agents elsewhere posted through Harness's server for a coding agent: when the
755
+ // person named that agent on the coding agent's standing permission, posting it is its start, on the computer it
756
+ // was placed on (runAuthority.mjs admitPosted), once the guard here reads its words clean.
757
+ const proposed =
758
+ request[HOSTED_CALLER] === true &&
759
+ PROPOSERS.includes(agent) &&
760
+ !thread &&
761
+ !goalParent &&
762
+ !request.parentId &&
763
+ authority.RUNNERS.has(target)
764
+ ? store.getTask(task.id)
765
+ : null;
766
+ if (proposed?.parent_id) {
767
+ const scratch =
768
+ !elsewhere && !proposed.run_workspace
769
+ ? threadScratch(proposed.parent_id)
770
+ : null;
771
+ return {
772
+ pending: readByGuard(
773
+ [proposed.objective, proposed.brief].filter(Boolean).join("\n\n")
774
+ ).then((guard) => {
775
+ const started = authority.admitPosted(
776
+ proposed,
777
+ {
778
+ proposer: agent,
779
+ hosted: true,
780
+ guard,
781
+ limited,
782
+ window: request.fromWindow === true,
783
+ },
784
+ { scratch }
785
+ );
786
+ if (started.started && scratch) prepareScratch(proposed.parent_id);
787
+ else if (!started.started)
788
+ store.roomPost({
789
+ goalId: proposed.parent_id,
790
+ author: "harness",
791
+ kind: "note",
792
+ text: `${nameOf(target)} waits for your Start: ${started.reason}`,
793
+ });
794
+ notifyBoard(store.getTask(task.id));
795
+ return posted(started);
796
+ }),
797
+ };
798
+ }
799
+ outcome = posted(standing);
610
800
  } else if (request.command === "board.list") {
611
801
  const tasks = store
612
802
  .listTasks({
@@ -617,10 +807,22 @@ export function createTaskCommands({
617
807
  machine,
618
808
  })
619
809
  .map(labelled);
810
+ // Each result carries its receipt and the files on it this caller may open, by id: get_task with `ack` set to
811
+ // the receipt is what takes it off this list.
620
812
  const finished =
621
813
  agent === "user" || agent === "harness"
622
814
  ? []
623
- : store.finishedFor(agent, lastLooked);
815
+ : store.finishedFor(agent).map((result) => ({
816
+ ...result,
817
+ files: store
818
+ .taskFiles(result.id)
819
+ .filter(
820
+ (file) =>
821
+ boardFiles.visibleFile(file, agent, request.hostedCaller) &&
822
+ (!request.hostedCaller || file.cloud)
823
+ )
824
+ .map((file) => ({ id: file.id, name: file.name })),
825
+ }));
624
826
  const extra = finished.length ? { finished } : {};
625
827
  // A session starting (nudge.mjs, the Pi and OpenCode plugins) also hears who else is in the swarm.
626
828
  if (request.swarm) {
@@ -715,10 +917,16 @@ export function createTaskCommands({
715
917
  task && !request.hostedCaller
716
918
  ? frames.get(task.kind === "goal" ? id : (task.parent_id ?? ""))
717
919
  : null;
920
+ // The asker's receipt for a result it was told under finished; read in the same answer it acknowledges.
921
+ const ack =
922
+ task && typeof request.ack === "string" && request.ack
923
+ ? store.ackResult(agent, id, request.ack)
924
+ : null;
718
925
  if (task)
719
926
  return {
720
927
  ok: true,
721
928
  task: labelled({ ...task, files, ...(frame ? { frame } : {}) }),
929
+ ...(ack ? ack : {}),
722
930
  ...(request.steps === true
723
931
  ? { steps: readRunSteps(taskFiles(id).log, 200) }
724
932
  : {}),
@@ -784,11 +992,30 @@ export function createTaskCommands({
784
992
  ok: false,
785
993
  error: `standing permission is for a coding agent: ${[...authority.RUNNERS].join(", ")}`,
786
994
  };
995
+ // The person's own agents elsewhere whose clean asks in a thread start this agent on its standing permission
996
+ // (runAuthority.mjs admitProposed); its mode, folders and daily limit stay as they are. [] takes them all back.
997
+ const proposers =
998
+ request.command === "board.standing.set" &&
999
+ Object.hasOwn(request, "proposers")
1000
+ ? request.proposers
1001
+ : null;
1002
+ if (
1003
+ proposers !== null &&
1004
+ (!Array.isArray(proposers) ||
1005
+ proposers.length > PROPOSERS.length ||
1006
+ !proposers.every((name) => PROPOSERS.includes(name)))
1007
+ )
1008
+ return {
1009
+ ok: false,
1010
+ error: `only your own agents elsewhere can start a coding agent: ${PROPOSERS.join(", ")}`,
1011
+ };
787
1012
  if (request.command === "board.standing.off")
788
1013
  store.setStanding(target, "off");
789
1014
  else if (request.command === "board.standing.on")
790
1015
  store.resetStanding(target);
791
- else {
1016
+ else if (proposers !== null && request.workspaces === undefined) {
1017
+ // Only who may start it changed.
1018
+ } else {
792
1019
  const workspaces = Array.isArray(request.workspaces)
793
1020
  ? [...new Set(request.workspaces.map(String))]
794
1021
  : [];
@@ -817,6 +1044,8 @@ export function createTaskCommands({
817
1044
  dailyCap
818
1045
  );
819
1046
  }
1047
+ if (proposers !== null)
1048
+ store.setStandingProposers(target, [...new Set(proposers)]);
820
1049
  return { ok: true, standing: authority.standingRules() };
821
1050
  } else if (request.command === "board.agents")
822
1051
  return {
@@ -1010,9 +1239,18 @@ export function createTaskCommands({
1010
1239
  const agents = Array.isArray(request.agents)
1011
1240
  ? request.agents.map(String).filter(validAgent).slice(0, 16)
1012
1241
  : [];
1242
+ // A turn another of the person's agents asked for is checked again before a worker sees it (runAuthority.mjs).
1243
+ const held = (task) => {
1244
+ const why = authority.recheckProposed(task);
1245
+ if (why) notifyBoard(store.getTask(task.id));
1246
+ return Boolean(why);
1247
+ };
1013
1248
  return {
1014
1249
  ok: true,
1015
- tasks: store.runnableTasks(agents, machine, { only: true }),
1250
+ tasks: store
1251
+ .runnableTasks(agents, machine, { only: true })
1252
+ .filter((task) => !held(task))
1253
+ .map(forWorker),
1016
1254
  };
1017
1255
  } else if (request.command === "board.machine.take") {
1018
1256
  const task = store.getTask(id);
@@ -1025,8 +1263,14 @@ export function createTaskCommands({
1025
1263
  ok: false,
1026
1264
  error: "that task is not for this computer's agent",
1027
1265
  };
1266
+ const held = task.status === "open" && authority.recheckProposed(task);
1267
+ if (held) {
1268
+ notifyBoard(store.getTask(id));
1269
+ return { ok: false, error: `it waits for the person's Start: ${held}` };
1270
+ }
1028
1271
  const claimed = store.claimTask(id, agent, expected, null, machine);
1029
1272
  outcome = claimed.ok ? store.startRun(id, agent) : claimed;
1273
+ if (outcome.ok) outcome = { ...outcome, task: forWorker(outcome.task) };
1030
1274
  // A thread's turn carries the thread as home's run worker would hand it over, and goes on in the session of the
1031
1275
  // turn the person's steer stopped there (threadRuns.mjs).
1032
1276
  if (outcome.ok && outcome.task.kind === "wake") {
@@ -1097,7 +1341,24 @@ export function createTaskCommands({
1097
1341
  else if (request.command === "board.machine.info") {
1098
1342
  if (!fromElsewhere)
1099
1343
  return { ok: false, error: "only another computer says what it has" };
1344
+ if (
1345
+ !Array.isArray(request.folders) ||
1346
+ request.folders.some(
1347
+ (folder) =>
1348
+ typeof folder?.path !== "string" ||
1349
+ !path.isAbsolute(folder.path) ||
1350
+ typeof folder.repository !== "string"
1351
+ )
1352
+ )
1353
+ return {
1354
+ ok: false,
1355
+ error: "worker inventory needs valid folder and repository entries",
1356
+ };
1100
1357
  machines.learn(machine, {
1358
+ request:
1359
+ typeof request.inventoryRequest === "string"
1360
+ ? request.inventoryRequest
1361
+ : null,
1101
1362
  folders: (Array.isArray(request.folders) ? request.folders : [])
1102
1363
  .filter(
1103
1364
  (folder) =>
package/lib/team.json CHANGED
@@ -1,5 +1,15 @@
1
1
  {
2
2
  "version": 2,
3
+ "fileSpecialties": [
4
+ "building-features",
5
+ "debugging",
6
+ "testing",
7
+ "code-review",
8
+ "frontend",
9
+ "infrastructure",
10
+ "data-sql",
11
+ "smart-contracts"
12
+ ],
3
13
  "rules": [
4
14
  "Whoever already holds the context does the work. Hand a piece to an agent new to the thread only when it needs little reading in and its answer can be checked.",
5
15
  "The dispatcher routes and never frames, makes or judges. The framer says what good looks like, and the frame goes with the work, so the check and the judge test against it rather than the maker's own idea of done.",