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
@@ -0,0 +1,147 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { nameOf } from "./members.mjs";
3
+ import { notifyDesktop } from "./notify.mjs";
4
+ import { underperforming as fromRecord } from "./record.mjs";
5
+
6
+ // When an agent is not living up to a specialty it carries (docs/swarm-organization.md): three or more runs with a
7
+ // verdict in it on its model, more rejected than accepted. The liaison tells the person once per agent, specialty and
8
+ // model, in the facts: a needs-you item of kind "agent" that opens the agent in the Swarm map, a notice on this
9
+ // computer and one on their phone. The item waits until the person keeps the specialty or removes it; the notice is
10
+ // never sent again for the same agent, specialty and model, kept or not.
11
+
12
+ const LIST = JSON.parse(
13
+ readFileSync(new URL("./specialties.json", import.meta.url), "utf8")
14
+ );
15
+ const NAMES = new Map(
16
+ LIST.headings.flatMap((heading) =>
17
+ heading.specialties.map((specialty) => [specialty.id, specialty.name])
18
+ )
19
+ );
20
+
21
+ // How often the record is read again for a step down. A verdict changes the record a few times a day at most.
22
+ const CHECK_EVERY_MS = 60_000;
23
+
24
+ // An item's id names the agent, specialty and model, in the characters a phone notice's address allows
25
+ // (src/server/runtime/pushSender.ts).
26
+ const idPart = (text) => String(text).replace(/[^a-zA-Z0-9._-]/g, "_");
27
+ export const noticeIdOf = ({ agent, specialty, model }) =>
28
+ `agent:${idPart(agent)}:${idPart(specialty)}:${idPart(model)}`;
29
+
30
+ // "flint-local/flint" reads "flint": the model, not the provider it is reached through.
31
+ const modelName = (model) => String(model).split("/").at(-1);
32
+
33
+ /** The facts, as every surface says them: "Pi has had 1 of 4 debugging runs accepted on flint. Keep its …?" */
34
+ export function noticeWords({ agent, model, specialty, accepted, judged }) {
35
+ const name = NAMES.get(specialty) ?? specialty;
36
+ return `${nameOf(agent)} has had ${accepted} of ${judged} ${name} runs accepted on ${modelName(model)}. Keep its ${name} specialty?`;
37
+ }
38
+
39
+ export function createSpecialtyNotice({
40
+ store,
41
+ log = () => {},
42
+ // The record's step downs (record.mjs).
43
+ underperforming = fromRecord,
44
+ // Whether the agent still carries the specialty on that model: one the person removed waits on nobody.
45
+ carries = () => true,
46
+ // A notice on this computer: the daemon's, which the buddy posts itself while it runs, so a click opens the item
47
+ // ("agent:<id>" opens the agent in the Swarm map).
48
+ desktop = (title, line) => notifyDesktop(`${title}: ${line}`),
49
+ // Whether this computer may show a notice now (the person's notifications on, the lid not closed).
50
+ speaks = () => true,
51
+ // A message to Harness's server for the person's phone: ids only, never words.
52
+ phone = () => {},
53
+ now = () => new Date(),
54
+ }) {
55
+ /** Said once: on this computer in words, and to the phone as only the kind, the agent and the item. */
56
+ function tell(item) {
57
+ if (speaks())
58
+ desktop("Your swarm", item.text, `agent:${item.agent}`, item.id);
59
+ phone({
60
+ type: "needs_you",
61
+ kind: "agent",
62
+ agent: item.agent,
63
+ item: item.id,
64
+ });
65
+ }
66
+
67
+ const keptKey = (id) => `specialty-kept:${id}`;
68
+ const toldKey = (id) => `told:${id}`;
69
+
70
+ /** Each step down the person has not answered, as a needs-you item. */
71
+ function current() {
72
+ let found = [];
73
+ try {
74
+ found = underperforming(store);
75
+ } catch (error) {
76
+ log(`specialty notice: the record could not be read: ${error.message}`);
77
+ }
78
+ return found
79
+ .filter((step) => carries(step.agent, step.model, step.specialty))
80
+ .map((step) => {
81
+ const id = noticeIdOf(step);
82
+ return {
83
+ id,
84
+ kind: "agent",
85
+ agent: step.agent,
86
+ specialty: step.specialty,
87
+ specialtyName: NAMES.get(step.specialty) ?? step.specialty,
88
+ model: step.model,
89
+ accepted: step.accepted,
90
+ judged: step.judged,
91
+ text: noticeWords(step),
92
+ at: store.meta(toldKey(id)) || now().toISOString(),
93
+ };
94
+ })
95
+ .filter((item) => !store.meta(keptKey(item.id)));
96
+ }
97
+
98
+ /** Tells each step down not told before; marked told first, so a failure to say it never says it twice. */
99
+ function check() {
100
+ for (const item of current()) {
101
+ if (store.meta(toldKey(item.id))) continue;
102
+ store.meta(toldKey(item.id), item.at);
103
+ try {
104
+ tell(item);
105
+ } catch (error) {
106
+ log(`specialty notice: ${item.id} not told: ${error.message}`);
107
+ }
108
+ }
109
+ }
110
+
111
+ /** The person keeps the specialty: the item goes, and the notice is not sent again. Only the person answers. */
112
+ function command(request, agent) {
113
+ if (agent !== "user")
114
+ return {
115
+ ok: false,
116
+ error: "only the person keeps or removes an agent's specialty",
117
+ };
118
+ const id = String(request.item || "");
119
+ if (request.answer !== "keep")
120
+ return {
121
+ ok: false,
122
+ error:
123
+ 'answer "keep"; to remove the specialty, remove it from the agent in the Swarm map',
124
+ };
125
+ const item = current().find((each) => each.id === id);
126
+ if (!item) return { ok: false, error: "that is no longer waiting on you" };
127
+ store.meta(keptKey(id), now().toISOString());
128
+ return { ok: true, item: id };
129
+ }
130
+
131
+ let timer = null;
132
+ return {
133
+ /** What waits on the person now, oldest first. */
134
+ needs: () => current().sort((a, b) => a.at.localeCompare(b.at)),
135
+ check,
136
+ command,
137
+ start() {
138
+ check();
139
+ timer ??= setInterval(check, CHECK_EVERY_MS);
140
+ timer.unref?.();
141
+ },
142
+ stop() {
143
+ clearInterval(timer);
144
+ timer = null;
145
+ },
146
+ };
147
+ }
@@ -0,0 +1,138 @@
1
+ import { effortKey, modelKey } from "./specialtyKeys.js";
2
+
3
+ // What public benchmarks show each agent's model does well, as Harness's server last sent it: the weekly specialty job's
4
+ // snapshot (src/server/specialties/), fetched with the `specialties` bridge message when the server connects and once a
5
+ // day, the way harnessModel.mjs fetches Harness's catalog. The last good copy is kept in the board's meta, so a relay
6
+ // that cannot reach Harness still reads it, and a server with no snapshot or a failed fetch never empties it.
7
+ //
8
+ // The snapshot keeps results for a harness and model together and for the model alone; reading it for an agent prefers
9
+ // the agent's own harness, then the model alone (docs/swarm-organization.md, "The weekly job").
10
+
11
+ const STORE_KEY = "specialty-snapshot";
12
+ const DAY_MS = 24 * 60 * 60 * 1000;
13
+
14
+ const parsed = (text) => {
15
+ try {
16
+ return JSON.parse(text || "null");
17
+ } catch {
18
+ return null;
19
+ }
20
+ };
21
+
22
+ const isSnapshot = (value) =>
23
+ Boolean(value) &&
24
+ Number.isFinite(value.version) &&
25
+ Array.isArray(value.entries) &&
26
+ Array.isArray(value.sources);
27
+
28
+ // The relay's one snapshot, for readers that have no handle on it (specialties.mjs reads it through snapshotFor).
29
+ let current = null;
30
+
31
+ /**
32
+ * `ask()` sends the `specialties` bridge message and resolves with Harness's answer ({ ok, list, snapshot }), or with
33
+ * null when this Harness does not offer it (an older server, or not connected).
34
+ */
35
+ export function createSpecialtySnapshot({ ask, store, log }) {
36
+ /** { at, list, snapshot } as last fetched, plus the last fetch's error. */
37
+ let copy = parsed(store.meta(STORE_KEY));
38
+
39
+ const keep = (next) => {
40
+ copy = next;
41
+ store.meta(STORE_KEY, JSON.stringify(next));
42
+ };
43
+ const noteError = (message) => {
44
+ log(`Specialties from Harness: ${message}`);
45
+ keep({ ...(copy ?? {}), error: String(message).slice(0, 300) });
46
+ };
47
+
48
+ /** Fetches the snapshot; true when a new copy was kept. A failure or an empty answer keeps the last copy. */
49
+ async function refresh() {
50
+ let reply;
51
+ try {
52
+ reply = await ask();
53
+ } catch (error) {
54
+ noteError(error.message);
55
+ return false;
56
+ }
57
+ if (reply == null) return false;
58
+ if (!reply.ok) {
59
+ noteError(reply.error || "Harness refused the request");
60
+ return false;
61
+ }
62
+ // Harness has had no good run yet: whatever this relay kept stays.
63
+ if (reply.snapshot == null) return false;
64
+ if (!isSnapshot(reply.snapshot)) {
65
+ noteError("the snapshot Harness sent is malformed");
66
+ return false;
67
+ }
68
+ keep({
69
+ at: new Date().toISOString(),
70
+ list: reply.list ?? copy?.list ?? null,
71
+ snapshot: reply.snapshot,
72
+ });
73
+ return true;
74
+ }
75
+
76
+ /**
77
+ * An agent's benchmark specialties on its model: [{ specialty, source, score, url, takenAt }], one per specialty and
78
+ * source. A result for this harness wins over the model alone; an effort-specific one over one with no effort named.
79
+ * [] before the first fetch, and for a model no source covers.
80
+ */
81
+ function snapshotFor({ harness = null, model = null, effort = null } = {}) {
82
+ const entries = copy?.snapshot?.entries ?? [];
83
+ const key = modelKey(model);
84
+ if (!key) return [];
85
+ const level = effortKey(effort);
86
+ const fits = entries.filter(
87
+ (entry) =>
88
+ entry.model === key &&
89
+ (entry.harness === null || entry.harness === harness) &&
90
+ (entry.effort === null || entry.effort === level)
91
+ );
92
+ const closeness = (entry) =>
93
+ (entry.harness === harness && harness !== null ? 2 : 0) +
94
+ (entry.effort !== null ? 1 : 0);
95
+ const best = new Map();
96
+ for (const entry of fits) {
97
+ const slot = `${entry.specialty}\u0000${entry.source}`;
98
+ const held = best.get(slot);
99
+ if (!held || closeness(entry) > closeness(held)) best.set(slot, entry);
100
+ }
101
+ return [...best.values()].map((entry) => ({
102
+ specialty: entry.specialty,
103
+ source: entry.sourceName ?? entry.source,
104
+ score: entry.score,
105
+ url: entry.url,
106
+ takenAt: entry.takenAt,
107
+ }));
108
+ }
109
+
110
+ let timer = null;
111
+ /** Fetches once a day from now on. */
112
+ function start() {
113
+ if (timer) return;
114
+ timer = setInterval(() => void refresh(), DAY_MS);
115
+ timer.unref?.();
116
+ }
117
+ function stop() {
118
+ clearInterval(timer);
119
+ timer = null;
120
+ }
121
+
122
+ /** For the buddy: the snapshot's version and date, when it was fetched and the last error. */
123
+ const view = () => ({
124
+ version: copy?.snapshot?.version ?? null,
125
+ takenAt: copy?.snapshot?.takenAt ?? null,
126
+ fetchedAt: copy?.at ?? null,
127
+ ...(copy?.error ? { error: copy.error } : {}),
128
+ });
129
+
130
+ const instance = { refresh, start, stop, snapshotFor, view };
131
+ current = instance;
132
+ return instance;
133
+ }
134
+
135
+ /** snapshotFor of the relay's snapshot; [] before one is created or fetched. */
136
+ export function snapshotFor(query) {
137
+ return current ? current.snapshotFor(query) : [];
138
+ }