tryharness 0.7.45 → 0.7.54

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 (125) hide show
  1. package/README.md +239 -14
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +497 -196
  5. package/lib/actorRoster.mjs +28 -5
  6. package/lib/adapters.mjs +165 -222
  7. package/lib/agentRuntimeConfig.mjs +36 -0
  8. package/lib/agentRuntimes.mjs +570 -0
  9. package/lib/agentSignIn.mjs +226 -0
  10. package/lib/atlas.mjs +7 -2
  11. package/lib/audit.mjs +643 -0
  12. package/lib/backupSetup.mjs +141 -0
  13. package/lib/boardAccess.mjs +8 -1
  14. package/lib/boardBackup.mjs +283 -0
  15. package/lib/boardCommands.mjs +5 -10
  16. package/lib/boardFileCommands.mjs +2 -1
  17. package/lib/boardMirror.mjs +523 -0
  18. package/lib/boardProtocol.json +263 -6
  19. package/lib/boardTools.mjs +2 -6
  20. package/lib/boardWaits.mjs +102 -0
  21. package/lib/book.mjs +659 -0
  22. package/lib/bridge.mjs +26 -4
  23. package/lib/browserWake.mjs +60 -0
  24. package/lib/cards.mjs +159 -16
  25. package/lib/cloudBoot.mjs +124 -0
  26. package/lib/commands.mjs +25 -5
  27. package/lib/connectionTools.d.ts +13 -0
  28. package/lib/connectionTools.js +45 -0
  29. package/lib/connectorAuth.mjs +309 -0
  30. package/lib/connectorCatalog.json +41 -0
  31. package/lib/connectorCommands.mjs +121 -0
  32. package/lib/connectorGoogle.mjs +513 -0
  33. package/lib/connectors.mjs +805 -0
  34. package/lib/context.mjs +18 -4
  35. package/lib/contractGate.mjs +377 -0
  36. package/lib/coordinator.mjs +152 -39
  37. package/lib/coreModels.mjs +78 -0
  38. package/lib/daemon.mjs +973 -54
  39. package/lib/desk.mjs +239 -0
  40. package/lib/desktop.mjs +113 -8
  41. package/lib/digest.mjs +32 -0
  42. package/lib/directLink.mjs +283 -0
  43. package/lib/environments.mjs +825 -0
  44. package/lib/folders.mjs +4 -4
  45. package/lib/gitHost.mjs +174 -0
  46. package/lib/goalCommands.mjs +58 -14
  47. package/lib/hookDialects.mjs +298 -0
  48. package/lib/inference.mjs +263 -152
  49. package/lib/landed.mjs +887 -0
  50. package/lib/lessons.mjs +6 -0
  51. package/lib/lineup.mjs +324 -0
  52. package/lib/live.mjs +284 -13
  53. package/lib/localmodels.mjs +10 -0
  54. package/lib/machineIdentity.mjs +3 -0
  55. package/lib/machineRoutes.mjs +40 -2
  56. package/lib/machineRuns.mjs +30 -3
  57. package/lib/machineSeal.mjs +69 -10
  58. package/lib/mcp-stdio.mjs +189 -120
  59. package/lib/mcpRelay.mjs +119 -0
  60. package/lib/members.json +26 -0
  61. package/lib/members.mjs +33 -0
  62. package/lib/modelMemory.mjs +100 -0
  63. package/lib/models.mjs +48 -15
  64. package/lib/museSession.mjs +122 -0
  65. package/lib/nativeHost.mjs +203 -0
  66. package/lib/neovim.mjs +126 -0
  67. package/lib/network.mjs +7 -2
  68. package/lib/nudge.mjs +57 -18
  69. package/lib/onboard.mjs +430 -1
  70. package/lib/oneclawLocal.mjs +150 -0
  71. package/lib/ownMachines.mjs +828 -39
  72. package/lib/pairing.mjs +182 -0
  73. package/lib/paths.mjs +8 -0
  74. package/lib/personModel.mjs +89 -0
  75. package/lib/phones.mjs +119 -3
  76. package/lib/placeCommands.mjs +27 -0
  77. package/lib/places.mjs +337 -9
  78. package/lib/plans.mjs +151 -27
  79. package/lib/profile.mjs +152 -0
  80. package/lib/projects.mjs +624 -137
  81. package/lib/readiness.mjs +400 -0
  82. package/lib/record.mjs +115 -0
  83. package/lib/repoLinks.mjs +354 -0
  84. package/lib/roomChannels.mjs +641 -0
  85. package/lib/runBrief.mjs +32 -2
  86. package/lib/runRequests.mjs +157 -0
  87. package/lib/runWorker.mjs +37 -9
  88. package/lib/runner.mjs +74 -11
  89. package/lib/secretPatterns.json +55 -0
  90. package/lib/secrets.mjs +10 -27
  91. package/lib/seen.mjs +102 -0
  92. package/lib/service.mjs +11 -6
  93. package/lib/sessionControl.mjs +386 -96
  94. package/lib/sessionIndex.mjs +5 -3
  95. package/lib/specialties.json +74 -0
  96. package/lib/specialties.mjs +477 -0
  97. package/lib/specialtyKeys.d.ts +3 -0
  98. package/lib/specialtyKeys.js +58 -0
  99. package/lib/specialtyNotice.mjs +147 -0
  100. package/lib/specialtySnapshot.mjs +138 -0
  101. package/lib/store.mjs +829 -29
  102. package/lib/subagents.mjs +8 -4
  103. package/lib/swarm.mjs +483 -37
  104. package/lib/swarmMemory.mjs +947 -0
  105. package/lib/t3.mjs +56 -17
  106. package/lib/taskCommands.mjs +91 -13
  107. package/lib/taskRuns.mjs +68 -11
  108. package/lib/team.json +253 -144
  109. package/lib/team.mjs +538 -147
  110. package/lib/threadLine.mjs +116 -0
  111. package/lib/threadRuns.mjs +78 -12
  112. package/lib/threadView.mjs +66 -16
  113. package/lib/tokenizer.mjs +405 -0
  114. package/lib/ui.mjs +16 -2
  115. package/lib/usageTotals.mjs +148 -0
  116. package/lib/vault.mjs +1144 -0
  117. package/lib/vaultCloud.mjs +117 -0
  118. package/lib/vaultCommands.mjs +201 -0
  119. package/lib/vaultTools.d.ts +12 -0
  120. package/lib/vaultTools.js +42 -0
  121. package/lib/windowAsks.mjs +42 -0
  122. package/lib/workFocus.mjs +59 -0
  123. package/lib/workLinks.mjs +90 -0
  124. package/lib/worktrees.mjs +51 -13
  125. package/package.json +10 -5
package/lib/swarm.mjs CHANGED
@@ -4,9 +4,29 @@ import path from "node:path";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { readRunSteps } from "./runner.mjs";
6
6
  import { createSubagents } from "./subagents.mjs";
7
- import { nameOf, resolveMember } from "./members.mjs";
8
- import { setNote, swarmBlock, swarmCards, swarmDigest } from "./cards.mjs";
7
+ import { MACHINE_RUNNERS, member, nameOf, resolveMember } from "./members.mjs";
8
+ import {
9
+ agentSpecialties,
10
+ setNote,
11
+ swarmBlock,
12
+ swarmCards,
13
+ swarmDigest,
14
+ youLine,
15
+ } from "./cards.mjs";
16
+ import {
17
+ SPECIALTIES,
18
+ addSpecialty,
19
+ appoint,
20
+ headingOf,
21
+ offices,
22
+ pins,
23
+ removeSpecialty,
24
+ setPin,
25
+ setPrimary,
26
+ } from "./specialties.mjs";
9
27
  import { askOfRun } from "./threadView.mjs";
28
+ import { createWorkFocus } from "./workFocus.mjs";
29
+ import { createWorkLinks } from "./workLinks.mjs";
10
30
  import {
11
31
  DEFAULT_ROUTING,
12
32
  PICKABLE,
@@ -29,6 +49,13 @@ export const PROCESS_NAMES = {
29
49
  codex: "codex",
30
50
  pi: "pi",
31
51
  opencode: "opencode",
52
+ // The command the person runs when it is not the protocol server Harness runs (Antigravity's `agy`).
53
+ ...Object.fromEntries(
54
+ MACHINE_RUNNERS.filter((id) => member(id)?.runtime).map((id) => [
55
+ id,
56
+ member(id).cli ?? member(id).runtime.command,
57
+ ])
58
+ ),
32
59
  };
33
60
  const SAY_LIMIT = 4_000;
34
61
  // `@swarm` in the person's message: written to their whole swarm, not to one agent.
@@ -37,6 +64,30 @@ const UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
37
64
  // A setup check's own room, from before checks stopped opening one (onboard.mjs): never a thread for the person.
38
65
  const SETUP_CHECK = /^Setup check from Harness: reply ready$/;
39
66
 
67
+ // A specialty as a command names it: its id, or its name as cards show it ("code review").
68
+ const specialtyIdOf = (text) => {
69
+ const wanted = String(text ?? "")
70
+ .trim()
71
+ .toLowerCase();
72
+ return (
73
+ SPECIALTIES.find(
74
+ (specialty) =>
75
+ specialty.id === wanted || specialty.name.toLowerCase() === wanted
76
+ )?.id ?? null
77
+ );
78
+ };
79
+ // Every specialty under its archetype's heading, in the list's order, for the Swarm map to offer.
80
+ const specialtyHeadings = () => {
81
+ const headings = new Map();
82
+ for (const specialty of SPECIALTIES) {
83
+ const heading = headingOf(specialty.id);
84
+ const entry = headings.get(heading.id) ?? { ...heading, specialties: [] };
85
+ entry.specialties.push({ id: specialty.id, name: specialty.name });
86
+ headings.set(heading.id, entry);
87
+ }
88
+ return [...headings.values()];
89
+ };
90
+
40
91
  // The id an agent resumes a session by: the index keys sessions by their file name.
41
92
  export function nativeSessionId(agent, sessionId) {
42
93
  const bare = String(sessionId).replace(/\.jsonl$/, "");
@@ -82,7 +133,10 @@ export function agentProcessCwds(exclude = new Set()) {
82
133
  }
83
134
 
84
135
  export function createSwarm({
136
+ landed = null,
85
137
  store,
138
+ // What this computer hands the person's Harness page through the extension (browserWake.mjs).
139
+ browserWake = null,
86
140
  roomAgents,
87
141
  mentionsIn,
88
142
  wakeFor,
@@ -96,8 +150,12 @@ export function createSwarm({
96
150
  coordinator,
97
151
  worktrees,
98
152
  roster,
153
+ // The coding agents here waiting to join the swarm, with their last check (readiness.mjs), for the person's browser.
154
+ joining = () => [],
99
155
  // Which of the person's computers each coding agent is on (actorRoster.mjs), when there are several.
100
156
  withMachines = (card) => card,
157
+ // Where an agent calling from a computer is (ownMachines.mjs whereIs), for what it is told of itself; null when unknown.
158
+ whereIs = () => null,
101
159
  authorizeRun,
102
160
  pickable,
103
161
  listModels,
@@ -112,6 +170,8 @@ export function createSwarm({
112
170
  // The person's post read for their reaction and for lessons (reactions.mjs, lessons.mjs), and what was learned.
113
171
  heardPerson = () => {},
114
172
  lessons = null,
173
+ // The swarm's long-running memory (swarmMemory.mjs): what swarm_memory recalls, and what the person forgets.
174
+ memory = null,
115
175
  // The subagents each run's own session spawned (subagents.mjs), for the thread's canvas.
116
176
  subagents = createSubagents(),
117
177
  // Work wired to wait for other work in the thread (plans.mjs).
@@ -122,7 +182,26 @@ export function createSwarm({
122
182
  projectOf = () => null,
123
183
  // The person's words name an agent of the other side of a shared project: theirs to answer, not this swarm's to sort.
124
184
  addressesPartner = () => false,
185
+ environments = null,
186
+ notifyFocus = () => {},
125
187
  }) {
188
+ const focus = createWorkFocus({ store });
189
+ const readWork = async (id, hostedCaller = false) => {
190
+ if (environments?.owns(id)) return environments.read(id);
191
+ const local = store.getTask(String(id || ""));
192
+ return local?.kind === "goal"
193
+ ? read(local, hostedCaller)
194
+ : { ok: false, error: "Work thread not found." };
195
+ };
196
+ const related = createWorkLinks({ store, readWork });
197
+ const linkedRevision = (id) => {
198
+ if (environments?.owns(id)) {
199
+ const source = environments.roots().find((entry) => entry.id === id);
200
+ return source ? focus.decorate(source).focus.revision : null;
201
+ }
202
+ const local = store.getTask(id);
203
+ return local?.kind === "goal" ? summary(local, false).focus.revision : null;
204
+ };
126
205
  // What the person let a thread spend of their Harness credits, in dollars, or null for no limit of its own.
127
206
  const ceilingOf = (threadId) => {
128
207
  const limit = Number(store.meta(`spend-ceiling:${threadId}`));
@@ -216,15 +295,18 @@ export function createSwarm({
216
295
  : null;
217
296
  };
218
297
 
219
- const summary = (thread) => {
298
+ const summary = (thread, includeRelated = true) => {
220
299
  const posts = store.roomPosts(thread.id, 0, 500);
221
300
  const runs = store.threadRuns(thread.id);
222
301
  const last = posts.at(-1);
223
302
  const live = runs.find((run) => run.status === "running");
224
303
  const step = live ? readRunSteps(runLog(live.id), 1)[0] : null;
225
304
  const view = threadView?.row(thread, posts) ?? null;
226
- return {
305
+ return focus.decorate({
227
306
  id: thread.id,
307
+ relatedVersion: includeRelated
308
+ ? related.version(thread.id, linkedRevision)
309
+ : null,
228
310
  title: view?.title ?? thread.objective,
229
311
  objective: thread.objective,
230
312
  // The same title, state, line and needs-you items on every surface (threadView.mjs).
@@ -301,9 +383,11 @@ export function createSwarm({
301
383
  checkIns: schedules?.list({ threadId: thread.id }) ?? [],
302
384
  ceilingUsd: ceilingOf(thread.id),
303
385
  changes: worktrees.summary(thread.id),
386
+ // Whether it made anything that can land: its Landed view shows then (landed.mjs).
387
+ landed: landed?.produced(thread, posts) ?? false,
304
388
  // A project shared with another person's swarm (projects.mjs): which, and with whom.
305
389
  project: projectOf(thread.id),
306
- };
390
+ });
307
391
  };
308
392
 
309
393
  // The person's terminal sessions not yet in a thread, newest first, each saying whether it is still open there.
@@ -421,7 +505,7 @@ export function createSwarm({
421
505
  const posts = store.roomPosts(thread.id, 0, 500);
422
506
  return {
423
507
  ok: true,
424
- thread: summary(thread),
508
+ thread: summary(thread, !hostedCaller),
425
509
  posts,
426
510
  // The thread in order as the person reads it: messages, steps gathered into groups, files (threadView.mjs).
427
511
  timeline: threadView?.timeline(thread, posts) ?? [],
@@ -444,6 +528,8 @@ export function createSwarm({
444
528
 
445
529
  // `to`: the one agent the person wrote to (the desktop's agent list), so their words go as written, with no @name.
446
530
  const post = (thread, text, to = null) => {
531
+ if (projectOf(thread.id)?.status === "left")
532
+ return { ok: false, error: "Your participation in this room has ended." };
447
533
  const picked = picksIn(store, text, roomAgents);
448
534
  if (picked.error) return { ok: false, error: picked.error };
449
535
  // A new name in the person's message joins the thread.
@@ -482,7 +568,19 @@ export function createSwarm({
482
568
  return posted;
483
569
  };
484
570
 
485
- return function swarmCommand(request, agent) {
571
+ // One of the person's agents as a command names it, or why not.
572
+ const namedAgent = (target) => {
573
+ const named = resolveMember(target);
574
+ if (named.ok) return named;
575
+ return {
576
+ ok: false,
577
+ error: named.candidates?.length
578
+ ? `"${target}" could be ${named.candidates.join(" or ")}; name one`
579
+ : `no agent called "${target}"`,
580
+ };
581
+ };
582
+
583
+ return function swarmCommand(request, agent, machine = null) {
486
584
  const command = String(request.command);
487
585
  if (command === "board.swarm.list") {
488
586
  if (agent !== "user" && agent !== "harness")
@@ -490,14 +588,183 @@ export function createSwarm({
490
588
  ok: false,
491
589
  error: "only the person and Harness read the swarm",
492
590
  };
493
- return {
591
+ const listed = () => ({
494
592
  ok: true,
495
- threads: store
496
- .goals({ all: request.all === true })
497
- .filter((thread) => !SETUP_CHECK.test(thread.objective))
498
- .map(summary),
593
+ threads: [
594
+ ...store
595
+ .goals({ all: request.all === true })
596
+ .filter((thread) => !SETUP_CHECK.test(thread.objective))
597
+ .map((thread) => summary(thread, !request.hostedCaller)),
598
+ ...(!request.hostedCaller
599
+ ? (environments?.roots() ?? []).map(focus.decorate)
600
+ : []),
601
+ ],
499
602
  sessions: request.sessions === false ? [] : sessions(),
500
603
  agents: roster(),
604
+ joining: request.hostedCaller ? [] : joining(),
605
+ // What waits on the person about an agent, outside any thread (threadView.mjs swarmNeeds).
606
+ needsYou: request.hostedCaller ? [] : (threadView?.swarmNeeds() ?? []),
607
+ });
608
+ // The work in T3 Code beside the board as T3 Code last said it; only the first read waits for it.
609
+ const loading = request.hostedCaller ? null : environments?.ready();
610
+ return loading ? { pending: loading.then(listed) } : listed();
611
+ }
612
+ if (
613
+ [
614
+ "board.swarm.follow",
615
+ "board.swarm.seen",
616
+ "board.swarm.context",
617
+ "board.swarm.links",
618
+ "board.swarm.link",
619
+ ].includes(command)
620
+ ) {
621
+ if (
622
+ agent !== "user" ||
623
+ (request.hostedCaller &&
624
+ (environments?.owns(request.id) ||
625
+ environments?.owns(request.destination)))
626
+ )
627
+ return {
628
+ ok: false,
629
+ error: "Only the person manages their followed work and context.",
630
+ };
631
+ const perform = async () => {
632
+ if (["board.swarm.link", "board.swarm.links"].includes(command)) {
633
+ if (request.hostedCaller || environments?.owns(request.id))
634
+ return {
635
+ ok: false,
636
+ error:
637
+ "Manage related work on your computer or a browser linked to it.",
638
+ };
639
+ const target = store.getTask(String(request.id || ""));
640
+ if (target?.kind !== "goal")
641
+ return {
642
+ ok: false,
643
+ error: "Choose a Harness objective for this work.",
644
+ };
645
+ if (command === "board.swarm.links") return related.read(target.id);
646
+ const result = await related.update(request);
647
+ if (result.ok) notifyFocus(target.id);
648
+ return result;
649
+ }
650
+ const source = await readWork(
651
+ request.id,
652
+ request.hostedCaller === true
653
+ );
654
+ if (!source.ok) return source;
655
+ if (command !== "board.swarm.context") {
656
+ const result = focus.update(source.thread, request);
657
+ if (result.ok) notifyFocus(source.thread.id);
658
+ return result;
659
+ }
660
+ const selected = source.posts.find(
661
+ (entry) => entry.id === request.postId
662
+ );
663
+ if (
664
+ !selected ||
665
+ selected.author === "user" ||
666
+ !["result", "post"].includes(selected.kind)
667
+ )
668
+ return {
669
+ ok: false,
670
+ error: "Choose an agent's result from this work.",
671
+ };
672
+ if (request.destination === request.id)
673
+ return {
674
+ ok: false,
675
+ error: "Choose another work thread for this result.",
676
+ };
677
+ const target = await readWork(
678
+ request.destination,
679
+ request.hostedCaller === true
680
+ );
681
+ if (!target.ok) return target;
682
+ if (target.thread.project?.status === "left")
683
+ return {
684
+ ok: false,
685
+ error: "Your participation in this room has ended.",
686
+ };
687
+ if (target.thread.source && !target.thread.source.controls.send)
688
+ return {
689
+ ok: false,
690
+ error:
691
+ "The destination is read-only. Choose a thread you can message.",
692
+ };
693
+ const url = selected.source?.url ?? source.thread.source?.url ?? null;
694
+ const origin = source.thread.source?.environmentName ?? "Harness";
695
+ const attribution = `${nameOf(selected.author)} · ${origin} · ${source.thread.title}`;
696
+ const text = `Context from ${attribution}\n${url ?? `Harness thread: ${source.thread.id}`}\nRecorded ${selected.created_at}\n\n${selected.text}`;
697
+ if (text.length > 20_000)
698
+ return {
699
+ ok: false,
700
+ error:
701
+ "This result is too long for one message. Select a shorter result in its original session.",
702
+ };
703
+ return {
704
+ ok: true,
705
+ draft: {
706
+ text,
707
+ source: {
708
+ threadId: source.thread.id,
709
+ postId: selected.id,
710
+ author: selected.author,
711
+ url,
712
+ at: selected.created_at,
713
+ truncated: selected.source?.truncated === true,
714
+ },
715
+ },
716
+ destination: {
717
+ id: target.thread.id,
718
+ title: target.thread.title,
719
+ agents: target.thread.agents,
720
+ environment: target.thread.source?.environmentName ?? "Harness",
721
+ partner: target.thread.project?.partner ?? null,
722
+ },
723
+ };
724
+ };
725
+ return {
726
+ pending: perform().catch((error) => ({
727
+ ok: false,
728
+ error: error.message,
729
+ })),
730
+ };
731
+ }
732
+ if (environments?.owns(request.id)) {
733
+ if (request.hostedCaller || !["user", "harness"].includes(agent))
734
+ return {
735
+ ok: false,
736
+ error: "Outside sessions are private to the person.",
737
+ };
738
+ const pending = (operation) => ({
739
+ pending: operation.catch((error) => ({
740
+ ok: false,
741
+ error: error.message,
742
+ })),
743
+ });
744
+ if (command === "board.swarm.read")
745
+ return pending(
746
+ environments
747
+ .read(request.id)
748
+ .then((result) =>
749
+ result.ok
750
+ ? { ...result, thread: focus.decorate(result.thread) }
751
+ : result
752
+ )
753
+ );
754
+ if (command === "board.swarm.post" || command === "board.swarm.stop")
755
+ return pending(
756
+ environments.control(
757
+ {
758
+ ...request,
759
+ action: command === "board.swarm.stop" ? "stop" : "send",
760
+ },
761
+ agent
762
+ )
763
+ );
764
+ return {
765
+ ok: false,
766
+ error:
767
+ "This work belongs to its source environment. Open its original session for this action.",
501
768
  };
502
769
  }
503
770
  // The swarm's shared memory, for any of the person's agents: what any agent wrote in any thread, and the coding
@@ -507,26 +774,35 @@ export function createSwarm({
507
774
  .trim()
508
775
  .slice(0, 500);
509
776
  if (!query) return { ok: false, error: "search needs a query" };
510
- const mine = request.teamOnly
511
- ? store
512
- .goals({ all: true })
513
- .filter((thread) => thread.goal.team.includes(agent))
514
- .map((thread) => thread.id)
515
- : null;
777
+ const hosted = Boolean(request.teamOnly) || request.hostedCaller === true;
778
+ const sessions = hosted ? [] : store.search({ query, limit: 5 });
779
+ if (!memory)
780
+ return { ok: true, threads: [], sessions, lessons: [], weak: true };
516
781
  return {
517
- ok: true,
518
- threads: store.searchThreads(query, { goalIds: mine, k: 8 }),
519
- sessions: request.teamOnly ? [] : store.search({ query, limit: 5 }),
520
- // What the person told the swarm (lessons.mjs), to a caller on this computer.
521
- lessons:
522
- request.teamOnly || request.hostedCaller === true
523
- ? []
524
- : store.lessonsMatching(query, 5).map((lesson) => ({
525
- about: lesson.about,
526
- agent: lesson.agent,
527
- text: lesson.text,
528
- quote: lesson.evidence.at(-1)?.quote ?? null,
529
- })),
782
+ pending: memory
783
+ .recall(query, {
784
+ agent,
785
+ teamOnly: Boolean(request.teamOnly),
786
+ hosted,
787
+ everyFolder: true,
788
+ })
789
+ .then((found) => ({
790
+ ok: true,
791
+ // Posts, job results and receipts with their thread, author and time; a receipt is checked by code.
792
+ threads: found.posts,
793
+ sessions,
794
+ // What the person told the swarm, and what the dream keeps, to a caller on this computer.
795
+ lessons: found.lessons,
796
+ observations: found.observations,
797
+ // What the person saw (seen.mjs), when the person searches.
798
+ ...(found.seen?.length ? { seen: found.seen } : {}),
799
+ weak: found.weak,
800
+ ...(found.weak
801
+ ? {
802
+ note: "Nothing closely matches: these are only the nearest. Say it was not found rather than relying on them.",
803
+ }
804
+ : {}),
805
+ })),
530
806
  };
531
807
  }
532
808
  // Who can be asked: every other agent's card (cards.mjs), and the same cards as the block an agent is told when its
@@ -540,10 +816,14 @@ export function createSwarm({
540
816
  { lessons: local }
541
817
  ).map(withMachines);
542
818
  const told = local ? (lessons?.told() ?? []) : [];
819
+ // Who is asking, and on which computer, ahead of everyone else.
820
+ const you = local ? youLine(agent, whereIs(machine)) : "";
543
821
  return {
544
822
  ok: true,
545
823
  agents,
546
- text: swarmBlock(agents, Date.now(), told),
824
+ text: [you, swarmBlock(agents, Date.now(), told)]
825
+ .filter(Boolean)
826
+ .join("\n\n"),
547
827
  digest: swarmDigest(agents, told),
548
828
  };
549
829
  }
@@ -588,7 +868,7 @@ export function createSwarm({
588
868
  });
589
869
  // Harness's catalog is read the first time it is shown, once the server can send it.
590
870
  return request.refresh === true && agent === "user"
591
- ? { pending: listModels().then(listing) }
871
+ ? { pending: listModels({ protocols: true }).then(listing) }
592
872
  : !named && !harnessModel.listed() && agent === "user"
593
873
  ? { pending: harnessModel.refresh().then(listing) }
594
874
  : listing();
@@ -643,6 +923,7 @@ export function createSwarm({
643
923
  kind: "post",
644
924
  text,
645
925
  mentions: addressed(store.getTask(thread.id), text),
926
+ machine,
646
927
  });
647
928
  wakeFor(thread.id, first, agent);
648
929
  notifyBoard(store.getTask(thread.id));
@@ -718,6 +999,90 @@ export function createSwarm({
718
999
  note: setNote(store, named.id, request.text),
719
1000
  };
720
1001
  }
1002
+ // What one agent is good at on the model it runs on now (specialties.mjs), for the Swarm map: each specialty with
1003
+ // its source and evidence, primary first, the specialties the person pinned it for, and every specialty there is,
1004
+ // under its heading. The person's, like everything from here on: agents read the cards through list_agents.
1005
+ if (command === "board.swarm.specialties") {
1006
+ const named = namedAgent(request.target);
1007
+ if (!named.ok) return named;
1008
+ const { model, effort, specialties } = agentSpecialties(store, named.id);
1009
+ return {
1010
+ ok: true,
1011
+ agent: named.id,
1012
+ model,
1013
+ effort,
1014
+ specialties,
1015
+ pinned: pins(store).filter((pin) => pin.agent === named.id),
1016
+ headings: specialtyHeadings(),
1017
+ };
1018
+ }
1019
+ // The person adds or removes one of an agent's specialties, or makes it the primary. A removal is final for the
1020
+ // agent and the model it runs on now: no benchmark or record brings it back.
1021
+ if (command === "board.swarm.specialty") {
1022
+ if (agent !== "user")
1023
+ return {
1024
+ ok: false,
1025
+ error: "only the person changes an agent's specialties",
1026
+ };
1027
+ const named = namedAgent(request.target);
1028
+ if (!named.ok) return named;
1029
+ const specialty = specialtyIdOf(request.specialty);
1030
+ if (!specialty)
1031
+ return {
1032
+ ok: false,
1033
+ error: `"${request.specialty}" is not a specialty Harness knows`,
1034
+ };
1035
+ const action = String(request.action || "");
1036
+ const change = {
1037
+ add: addSpecialty,
1038
+ remove: removeSpecialty,
1039
+ primary: setPrimary,
1040
+ }[action];
1041
+ if (!change)
1042
+ return { ok: false, error: "the action is add, remove or primary" };
1043
+ const { model } = agentSpecialties(store, named.id);
1044
+ const changed = change(store, named.id, specialty, model);
1045
+ if (!changed.ok) return changed;
1046
+ return {
1047
+ ok: true,
1048
+ agent: named.id,
1049
+ specialties: agentSpecialties(store, named.id).specialties,
1050
+ };
1051
+ }
1052
+ // The person pins an agent for a specialty: it holds that specialty whenever a step asks for it. No agent takes the
1053
+ // pin off.
1054
+ if (command === "board.swarm.pin") {
1055
+ if (agent !== "user")
1056
+ return { ok: false, error: "only the person pins an agent" };
1057
+ const specialty = specialtyIdOf(request.specialty);
1058
+ if (!specialty)
1059
+ return {
1060
+ ok: false,
1061
+ error: `"${request.specialty}" is not a specialty Harness knows`,
1062
+ };
1063
+ if (request.target === null || request.target === undefined)
1064
+ return setPin(store, specialty, null);
1065
+ const named = namedAgent(request.target);
1066
+ if (!named.ok) return named;
1067
+ return setPin(store, specialty, named.id);
1068
+ }
1069
+ // The swarm's offices and who holds each, for the home computer's panel.
1070
+ if (command === "board.swarm.offices")
1071
+ return { ok: true, offices: offices(store) };
1072
+ // The person appoints an agent to an office, or no agent for its default; the rules refuse some, saying why.
1073
+ if (command === "board.swarm.office") {
1074
+ if (agent !== "user")
1075
+ return { ok: false, error: "only the person appoints an office" };
1076
+ const office = String(request.office || "")
1077
+ .trim()
1078
+ .toLowerCase()
1079
+ .replace(/\s+/g, "-");
1080
+ if (request.target === null || request.target === undefined)
1081
+ return appoint(store, office, null);
1082
+ const named = namedAgent(request.target);
1083
+ if (!named.ok) return named;
1084
+ return appoint(store, office, named.id);
1085
+ }
721
1086
  // The person's choice of model and effort for one agent: a model it lists, "auto", or "default" for its own settings.
722
1087
  if (command === "board.swarm.model") {
723
1088
  const named = resolveMember(request.target);
@@ -889,7 +1254,12 @@ export function createSwarm({
889
1254
  ok: true,
890
1255
  lessons: (
891
1256
  lessons?.list({
892
- status: request.replaced === true ? "replaced" : "active",
1257
+ status:
1258
+ request.retired === true
1259
+ ? "retired"
1260
+ : request.replaced === true
1261
+ ? "replaced"
1262
+ : "active",
893
1263
  }) ?? []
894
1264
  ).map((lesson) => {
895
1265
  const last = lesson.evidence.at(-1);
@@ -916,9 +1286,17 @@ export function createSwarm({
916
1286
  };
917
1287
  if (command === "board.swarm.lessons.remove") {
918
1288
  const removed = lessons?.remove(request.id);
919
- return removed
920
- ? { ok: true, lesson: removed }
921
- : { ok: false, error: "no lesson starts with that id" };
1289
+ if (!removed)
1290
+ return { ok: false, error: "no lesson starts with that id" };
1291
+ // The words it came from stop coming back through search and briefs too, so the swarm does not learn it again
1292
+ // from them (eval memory-swarm); they stay in their thread.
1293
+ memory?.forget({
1294
+ ids: removed.evidence.map((entry) => entry.postId).filter(Boolean),
1295
+ mode: "release",
1296
+ by: `lesson:${removed.id}`,
1297
+ reason: "the person took the lesson out",
1298
+ });
1299
+ return { ok: true, lesson: removed };
922
1300
  }
923
1301
  if (command === "board.swarm.lessons.undo")
924
1302
  return {
@@ -947,6 +1325,43 @@ export function createSwarm({
947
1325
  }
948
1326
  ),
949
1327
  };
1328
+ // The swarm's memory (swarmMemory.mjs), the person's: what the dream keeps, what was forgotten or replaced and the
1329
+ // last dream; forgetting posts, lessons or observations by id, Undo, and a dream now.
1330
+ if (command === "board.swarm.memory")
1331
+ return {
1332
+ ok: true,
1333
+ observations: memory?.observations() ?? [],
1334
+ seen: memory?.seen() ?? [],
1335
+ forgotten: store.memoryMarks(),
1336
+ dream: memory?.lastDream() ?? null,
1337
+ };
1338
+ if (command === "board.swarm.forget") {
1339
+ const mode = request.mode === "purge" ? "purge" : "release";
1340
+ const forgotten =
1341
+ memory?.forget({
1342
+ ids: Array.isArray(request.ids) ? request.ids.map(String) : [],
1343
+ mode,
1344
+ by: "user",
1345
+ reason: request.reason ? String(request.reason).slice(0, 200) : null,
1346
+ }) ?? [];
1347
+ return forgotten.length
1348
+ ? { ok: true, forgotten }
1349
+ : { ok: false, error: "nothing with those ids to forget" };
1350
+ }
1351
+ if (command === "board.swarm.unforget") {
1352
+ const back = memory?.unforget(String(request.id || ""));
1353
+ return back
1354
+ ? { ok: true, back }
1355
+ : {
1356
+ ok: false,
1357
+ error:
1358
+ "nothing to bring back with that id (deleted words are gone for good)",
1359
+ };
1360
+ }
1361
+ if (command === "board.swarm.dream")
1362
+ return memory
1363
+ ? { pending: memory.dream() }
1364
+ : { ok: false, error: "this daemon keeps no memory" };
950
1365
  // Check-ins (schedules.mjs), the person's: only the person gets this far, and the lead sets its own in its rounds
951
1366
  // (coordinator.mjs). Every thread's, or ending one by its own id.
952
1367
  if (command === "board.swarm.checkins" && !request.id)
@@ -1049,6 +1464,32 @@ export function createSwarm({
1049
1464
  ? { ok: true, thread: summary(store.getTask(thread.id)) }
1050
1465
  : done;
1051
1466
  }
1467
+ // The person lets Harness finish in their browser now what it left for the browser (owner, October 22: "right
1468
+ // away, even if away"): their extension's hidden Harness page takes it, claiming it only once this is recorded.
1469
+ if (command === "board.swarm.use_browser") {
1470
+ if (agent !== "user")
1471
+ return { ok: false, error: "only you let Harness use your browser" };
1472
+ const run = store
1473
+ .threadRuns(thread.id)
1474
+ .find((candidate) => candidate.id === String(request.runId || ""));
1475
+ if (
1476
+ !run ||
1477
+ run.target_agent !== "harness" ||
1478
+ run.status !== "open" ||
1479
+ !store.meta(`harness-window:${run.id}`)
1480
+ )
1481
+ return { ok: false, error: "that is not waiting for your browser" };
1482
+ if (!browserWake?.listening())
1483
+ return {
1484
+ ok: false,
1485
+ error:
1486
+ "your browser is not connected to this computer; open Harness on your computer instead",
1487
+ };
1488
+ store.meta(`harness-browser-allowed:${run.id}`, new Date().toISOString());
1489
+ browserWake.send({ kind: "board-task", task: run.id });
1490
+ notifyBoard(store.getTask(thread.id));
1491
+ return { ok: true, thread: summary(store.getTask(thread.id)) };
1492
+ }
1052
1493
  // The person's Start for one run in the thread that waits for it.
1053
1494
  if (command === "board.swarm.start_run") {
1054
1495
  const run = store
@@ -1189,6 +1630,11 @@ export function createSwarm({
1189
1630
  return { ok: true, thread: summary(store.getTask(thread.id)) };
1190
1631
  }
1191
1632
  if (command === "board.swarm.resume") {
1633
+ if (projectOf(thread.id)?.status === "left")
1634
+ return {
1635
+ ok: false,
1636
+ error: "Your participation in this room has ended.",
1637
+ };
1192
1638
  if (thread.status !== "paused")
1193
1639
  return { ok: false, error: `the thread is ${thread.status}` };
1194
1640
  store.setGoalState(thread.id, { status: "open" });