tryharness 0.7.82 → 0.7.86

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 (216) hide show
  1. package/README.md +21 -19
  2. package/assets/dsh-plugin.mjs +75 -4
  3. package/assets/herdr-mod/harness/main.js +367 -0
  4. package/assets/herdr-mod/harness/mod.json +6 -0
  5. package/assets/opencode-plugin.js +87 -22
  6. package/assets/pi-extension.ts +81 -2
  7. package/cli.mjs +544 -208
  8. package/lib/adapters.mjs +62 -27
  9. package/lib/agentBinaries.mjs +6 -8
  10. package/lib/agentClaims.mjs +168 -0
  11. package/lib/agentReadTools.json +415 -0
  12. package/lib/agentSignIn.mjs +17 -18
  13. package/lib/agentWiring.mjs +114 -0
  14. package/lib/archetypes.js +10 -11
  15. package/lib/attention.mjs +100 -0
  16. package/lib/audit.mjs +1 -1
  17. package/lib/backupSetup.mjs +6 -28
  18. package/lib/bankrApprovals.mjs +86 -0
  19. package/lib/boardAccess.mjs +40 -66
  20. package/lib/boardBackup.mjs +86 -85
  21. package/lib/boardCommands.mjs +28 -0
  22. package/lib/boardFileCommands.mjs +29 -36
  23. package/lib/boardFiles.mjs +83 -15
  24. package/lib/boardMirror.mjs +78 -11
  25. package/lib/boardProtocol.json +193 -123
  26. package/lib/boardThreads.mjs +19 -37
  27. package/lib/boardTools.mjs +22 -15
  28. package/lib/boardWatches.mjs +43 -15
  29. package/lib/bridge.mjs +7 -3
  30. package/lib/browserAgentTools.mjs +59 -0
  31. package/lib/browserWake.mjs +0 -6
  32. package/lib/cards.mjs +57 -2
  33. package/lib/circling.mjs +189 -0
  34. package/lib/cleanup.mjs +234 -0
  35. package/lib/cloudBoot.mjs +21 -4
  36. package/lib/cloudSave.mjs +46 -5
  37. package/lib/compaction.mjs +8 -1
  38. package/lib/completion.mjs +358 -0
  39. package/lib/computerDevices.mjs +853 -0
  40. package/lib/connectionStatus.mjs +34 -0
  41. package/lib/connectors.mjs +139 -1
  42. package/lib/coordinator.mjs +108 -14
  43. package/lib/coreModels.mjs +36 -12
  44. package/lib/daemon.mjs +2435 -333
  45. package/lib/daemonLock.mjs +103 -0
  46. package/lib/deviceDoor.mjs +308 -0
  47. package/lib/deviceIdentity.mjs +114 -0
  48. package/lib/deviceList.mjs +172 -0
  49. package/lib/deviceSeal.mjs +74 -0
  50. package/lib/dispatcher.mjs +497 -26
  51. package/lib/dispatches.mjs +3 -3
  52. package/lib/environment.mjs +2 -1
  53. package/lib/environments.mjs +67 -41
  54. package/lib/events.mjs +318 -0
  55. package/lib/facts.mjs +170 -0
  56. package/lib/fileSource.mjs +540 -0
  57. package/lib/files.mjs +47 -2
  58. package/lib/gitHost.mjs +39 -1
  59. package/lib/goalCommands.mjs +12 -80
  60. package/lib/handover.mjs +21 -16
  61. package/lib/harnessOffers.mjs +140 -15
  62. package/lib/herdr.mjs +100 -15
  63. package/lib/herdrAppCall.mjs +19 -0
  64. package/lib/herdrCore.mjs +59 -0
  65. package/lib/herdrRuns.mjs +1126 -0
  66. package/lib/hookDialects.mjs +235 -50
  67. package/lib/identityLink.mjs +81 -0
  68. package/lib/inference.mjs +31 -2
  69. package/lib/jamAccess.mjs +82 -0
  70. package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
  71. package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
  72. package/lib/jamKey.mjs +274 -0
  73. package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
  74. package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
  75. package/lib/jamStore.mjs +973 -0
  76. package/lib/jamUpgrade.mjs +112 -0
  77. package/lib/jams.mjs +3079 -0
  78. package/lib/kanban.mjs +13 -7
  79. package/lib/landed.mjs +5 -1
  80. package/lib/library.mjs +41 -22
  81. package/lib/limits.mjs +91 -0
  82. package/lib/lineDiff.mjs +97 -0
  83. package/lib/lineup.mjs +18 -13
  84. package/lib/link.mjs +584 -0
  85. package/lib/localStack.mjs +75 -16
  86. package/lib/localmodels.mjs +58 -78
  87. package/lib/loopBackstop.mjs +2 -1
  88. package/lib/machine.mjs +544 -0
  89. package/lib/machineLink.mjs +446 -0
  90. package/lib/machineRoutes.mjs +68 -19
  91. package/lib/machineRuns.mjs +85 -4
  92. package/lib/machineSeal.mjs +6 -31
  93. package/lib/manager.mjs +134 -12
  94. package/lib/mcp-stdio.mjs +492 -215
  95. package/lib/mcpRelay.mjs +34 -35
  96. package/lib/members.json +2 -2
  97. package/lib/modelRoute.mjs +162 -0
  98. package/lib/nativeHost.mjs +81 -90
  99. package/lib/nativeSenses.mjs +258 -0
  100. package/lib/nerves.mjs +523 -0
  101. package/lib/network.mjs +117 -278
  102. package/lib/networkPlaces.mjs +578 -0
  103. package/lib/nextStep.mjs +95 -0
  104. package/lib/notify.mjs +2 -2
  105. package/lib/nudge.mjs +116 -10
  106. package/lib/onboard.mjs +6 -6
  107. package/lib/originals.mjs +216 -0
  108. package/lib/outsideEvents.mjs +383 -0
  109. package/lib/outsideRuns.mjs +230 -0
  110. package/lib/ownMachines.mjs +674 -256
  111. package/lib/pain.mjs +215 -0
  112. package/lib/pairing.mjs +91 -11
  113. package/lib/paths.mjs +42 -3
  114. package/lib/peerProcess.mjs +21 -7
  115. package/lib/peopleLink.mjs +268 -0
  116. package/lib/personNotices.mjs +3 -2
  117. package/lib/phones.mjs +252 -542
  118. package/lib/placeCards.mjs +282 -0
  119. package/lib/placeChecks.mjs +95 -0
  120. package/lib/placeCommands.mjs +8 -17
  121. package/lib/placeRequests.mjs +152 -0
  122. package/lib/placeStore.mjs +295 -0
  123. package/lib/placeTool.d.ts +12 -0
  124. package/lib/placeTool.js +40 -0
  125. package/lib/places.mjs +63 -14
  126. package/lib/plans.mjs +53 -8
  127. package/lib/presence.mjs +270 -0
  128. package/lib/privateNetwork.d.ts +2 -0
  129. package/lib/privateNetwork.js +93 -0
  130. package/lib/proposals.mjs +300 -0
  131. package/lib/publicFetch.d.ts +32 -0
  132. package/lib/publicFetch.js +248 -0
  133. package/lib/reach.mjs +128 -0
  134. package/lib/rebuildable.mjs +72 -0
  135. package/lib/recall.mjs +216 -0
  136. package/lib/record.mjs +13 -0
  137. package/lib/reflexes.mjs +392 -0
  138. package/lib/relayLimits.mjs +31 -2
  139. package/lib/releaseNotice.mjs +198 -0
  140. package/lib/removeHarness.mjs +15 -4
  141. package/lib/repoLinks.mjs +204 -35
  142. package/lib/runAuthority.mjs +102 -39
  143. package/lib/runBrief.mjs +93 -40
  144. package/lib/runRequests.mjs +52 -14
  145. package/lib/runUsage.mjs +31 -0
  146. package/lib/runWorker.mjs +74 -25
  147. package/lib/runner.mjs +289 -45
  148. package/lib/runtime-install.mjs +37 -8
  149. package/lib/schedules.mjs +171 -47
  150. package/lib/screenWatches.mjs +221 -0
  151. package/lib/sealed.mjs +12 -30
  152. package/lib/sealedThreads.mjs +198 -392
  153. package/lib/secretStore.mjs +178 -0
  154. package/lib/secrets.mjs +11 -0
  155. package/lib/seen.mjs +3 -9
  156. package/lib/selfUpdate.mjs +51 -15
  157. package/lib/senseCall.mjs +1514 -0
  158. package/lib/senseHook.mjs +114 -0
  159. package/lib/senseTools.mjs +1298 -0
  160. package/lib/sessionBriefs.mjs +87 -0
  161. package/lib/sessionControl.mjs +63 -13
  162. package/lib/sessionFiles.mjs +85 -0
  163. package/lib/setupChoices.mjs +12 -3
  164. package/lib/setupMode.mjs +70 -25
  165. package/lib/sharedKeys.mjs +166 -0
  166. package/lib/sleep.mjs +396 -0
  167. package/lib/sources.mjs +306 -0
  168. package/lib/speech.mjs +166 -411
  169. package/lib/spoken.mjs +210 -0
  170. package/lib/steerHook.mjs +3 -1
  171. package/lib/steerQueue.mjs +40 -11
  172. package/lib/store.mjs +323 -130
  173. package/lib/stuck.mjs +85 -7
  174. package/lib/swarm.mjs +157 -49
  175. package/lib/swarmDevices.mjs +25 -85
  176. package/lib/swarmMemory.mjs +93 -9
  177. package/lib/t3.mjs +73 -3
  178. package/lib/taskCommands.mjs +51 -60
  179. package/lib/taskRooms.mjs +30 -4
  180. package/lib/taskRules.json +29 -0
  181. package/lib/taskRules.mjs +21 -0
  182. package/lib/taskRuns.mjs +74 -11
  183. package/lib/team.mjs +2 -1
  184. package/lib/threadActions.mjs +37 -9
  185. package/lib/threadAuthority.mjs +4 -4
  186. package/lib/threadBriefs.mjs +173 -43
  187. package/lib/threadNotes.mjs +320 -0
  188. package/lib/threadRecord.mjs +491 -0
  189. package/lib/threadRuns.mjs +216 -108
  190. package/lib/threadView.mjs +27 -30
  191. package/lib/threadWatches.mjs +1962 -0
  192. package/lib/timeSense.mjs +839 -0
  193. package/lib/tripwires.mjs +454 -0
  194. package/lib/ui.mjs +1 -1
  195. package/lib/vault.mjs +560 -45
  196. package/lib/vaultCommands.mjs +5 -3
  197. package/lib/vaultPeers.mjs +165 -0
  198. package/lib/vaultTools.d.ts +4 -1
  199. package/lib/vaultTools.js +22 -1
  200. package/lib/verdicts.mjs +12 -26
  201. package/lib/versions.mjs +117 -0
  202. package/lib/waitTool.mjs +278 -0
  203. package/lib/wakePicture.mjs +268 -0
  204. package/lib/wakeQueue.mjs +108 -0
  205. package/lib/watchResponses.mjs +533 -0
  206. package/lib/watches.mjs +290 -145
  207. package/lib/windowAsks.mjs +80 -17
  208. package/lib/worktrees.mjs +159 -9
  209. package/npm-shrinkwrap.json +138 -631
  210. package/package.json +7 -6
  211. package/release.json +212 -130
  212. package/lib/callSessions.mjs +0 -51
  213. package/lib/directLink.mjs +0 -349
  214. package/lib/peopleBoard.mjs +0 -131
  215. package/lib/projects.mjs +0 -2917
  216. package/lib/roomChannels.mjs +0 -667
@@ -76,9 +76,11 @@ export async function vaultCommands(argv) {
76
76
  const vault = await call("list");
77
77
  for (const request of vault.requests)
78
78
  console.log(
79
- request.why === "missing"
80
- ? `${request.agent} needs ${request.secret}${request.host ? ` for ${request.host}` : ""}: ${relayCommand()} vault add ${request.secret} --hosts ${request.host ?? "<website>"}`
81
- : `${request.agent} asks to use ${request.secret}: ${relayCommand()} vault allow ${request.agent} ${request.secret}`
79
+ request.to
80
+ ? `${request.agent} wants to let ${request.to} use ${request.secret}: allow it in Harness's vault`
81
+ : request.why === "missing"
82
+ ? `${request.agent} needs ${request.secret}${request.host ? ` for ${request.host}` : ""}: ${relayCommand()} vault add ${request.secret} --hosts ${request.host ?? "<website>"}`
83
+ : `${request.agent} asks to use ${request.secret}: ${relayCommand()} vault allow ${request.agent} ${request.secret}`
82
84
  );
83
85
  if (!vault.secrets.length) console.log("Nothing kept yet.");
84
86
  for (const secret of vault.secrets)
@@ -0,0 +1,165 @@
1
+ import { randomUUID } from "node:crypto";
2
+
3
+ // Another person's agent using a secret passed to it, inside a jam both people are in (docs/jam-plan.md J4.8; rule 9:
4
+ // secrets never go agent to agent across people, so the pass waits for the holder's OK, vault.mjs). The value stays on
5
+ // the computer that keeps it: the agent's own call is sent there as an event of the jam, sealed under the jam's key and
6
+ // addressed to that person's computer, which alone acts on it, and the answer comes back the same way with the value
7
+ // replaced. Harness carries only ciphertext. It no longer rides a friendship (owner: "agents arent in dms at all").
8
+ //
9
+ // Harness keeps a jam's events for a computer that is off, for days if it must, so a request sent to a computer that is
10
+ // off would run whenever it came back, long after the agent stopped caring. So a call asks first ("check"), and sends
11
+ // the request only once the other computer answers ("here"). A check that waited days is answered to a call that is
12
+ // gone, and nothing runs. No deadline is involved: none has been measured for this road. Harness says when it took an
13
+ // event whose members' computers are connected, so a call to a computer that is off hears so at once; one that went
14
+ // quiet while connected lasts until the agent's own call gives up.
15
+ const SEEN_CALLS = 1_000;
16
+
17
+ const answerFrom = (result) => ({
18
+ ok: result?.ok === true,
19
+ ...(Number.isInteger(result?.status) ? { status: result.status } : {}),
20
+ ...(typeof result?.response === "string"
21
+ ? { response: result.response }
22
+ : {}),
23
+ ...(typeof result?.error === "string" ? { error: result.error } : {}),
24
+ ...(result?.ended === true ? { ended: true } : {}),
25
+ });
26
+
27
+ export function createVaultPeers({
28
+ // The jam this person is in with `handle` (the one `work` is in, when it names some), or null (jams.mjs jamWith).
29
+ jamWith,
30
+ // Adds an event to that jam for `to`'s computer, and tells `taken` whether Harness took it (jams.mjs vaultSend).
31
+ send,
32
+ // The secret's computer: run another person's agent's request (vault.mjs serveAnotherPerson).
33
+ serve,
34
+ // The agent's computer: a secret was passed to one of its agents, or that ended (vault.mjs).
35
+ onPassed,
36
+ onEnded,
37
+ log = () => {},
38
+ }) {
39
+ // Calls this computer's agents are waiting on.
40
+ const calls = new Map();
41
+ // Requests this computer is running for the other person, so one can be stopped.
42
+ const running = new Map();
43
+ // Harness may deliver a message twice after a lost acknowledgement: a request runs once.
44
+ const seen = new Set();
45
+
46
+ const sendOn = (jamId, to, event, taken = null) =>
47
+ send({ jamId, to, body: event, taken });
48
+
49
+ /** Tell the other person's computer something that needs no answer. False when there is no jam to tell it in. */
50
+ const tell = (handle, event, work = null) => {
51
+ // The jam the work was in; one whose work is gone (an ending) is told in any jam the two share.
52
+ const jamId = jamWith(handle, work) ?? jamWith(handle);
53
+ if (!jamId) return false;
54
+ sendOn(jamId, handle, event);
55
+ return true;
56
+ };
57
+
58
+ /** Run a request on the computer of the person who passed the secret, and hear its answer. */
59
+ const call = (handle, agent, request, { signal } = {}) =>
60
+ new Promise((resolve) => {
61
+ const jamId = jamWith(handle);
62
+ if (!jamId) {
63
+ resolve({
64
+ ok: false,
65
+ error: `You are in no jam with ${handle} to reach their computer through.`,
66
+ });
67
+ return;
68
+ }
69
+ const id = randomUUID();
70
+ const stop = () => {
71
+ if (calls.get(id)?.sent)
72
+ sendOn(jamId, handle, { type: "stop", call: id });
73
+ finish({ ok: false, error: "The call was stopped." });
74
+ };
75
+ const finish = (result) => {
76
+ calls.delete(id);
77
+ signal?.removeEventListener?.("abort", stop);
78
+ resolve(result);
79
+ };
80
+ calls.set(id, { jamId, agent, request, finish, handle, sent: false });
81
+ if (signal?.aborted) {
82
+ stop();
83
+ return;
84
+ }
85
+ signal?.addEventListener?.("abort", stop, { once: true });
86
+ sendOn(jamId, handle, { type: "check", call: id }, (answer) =>
87
+ taken(id, answer)
88
+ );
89
+ });
90
+
91
+ /** Harness took (or refused) a call's check. `connected` is false when the other computer is off. */
92
+ const taken = (id, { ok, connected, error } = {}) => {
93
+ const waiting = calls.get(id);
94
+ if (!waiting) return;
95
+ if (ok === false)
96
+ waiting.finish({
97
+ ok: false,
98
+ error: `Harness could not reach ${waiting.handle}'s computer: ${error ?? "it refused the message"}.`,
99
+ });
100
+ else if (connected === false)
101
+ waiting.finish({
102
+ ok: false,
103
+ error: `${waiting.handle}'s computer is off, and the secret is kept there. Nothing was sent. Try again once it is back.`,
104
+ });
105
+ };
106
+
107
+ const runFor = async (jamId, handle, event) => {
108
+ const id = String(event.call ?? "");
109
+ if (!id || seen.has(id)) return;
110
+ seen.add(id);
111
+ if (seen.size > SEEN_CALLS) seen.delete(seen.values().next().value);
112
+ const stopper = new AbortController();
113
+ running.set(id, stopper);
114
+ let result;
115
+ try {
116
+ result = await serve(handle, String(event.agent ?? ""), event.request, {
117
+ signal: stopper.signal,
118
+ });
119
+ } catch (error) {
120
+ log(`vault: a request for ${handle} failed: ${error.message}`);
121
+ result = { ok: false, error: "The other computer could not run that." };
122
+ } finally {
123
+ running.delete(id);
124
+ }
125
+ sendOn(jamId, handle, {
126
+ type: "answer",
127
+ call: id,
128
+ result: answerFrom(result),
129
+ });
130
+ };
131
+
132
+ /**
133
+ * An event another person's computer added to a jam for this one; `handle` is theirs, from its signature, never what
134
+ * it says.
135
+ */
136
+ const receive = (jamId, event, handle) => {
137
+ const type = String(event?.type ?? "");
138
+ const waiting = calls.get(String(event?.call ?? ""));
139
+ if (type === "check") {
140
+ sendOn(jamId, handle, { type: "here", call: String(event.call ?? "") });
141
+ } else if (type === "here") {
142
+ // A call that is gone, or that already sent its request, sends nothing.
143
+ if (!waiting || waiting.sent || waiting.handle !== handle) return;
144
+ waiting.sent = true;
145
+ sendOn(jamId, handle, {
146
+ type: "use",
147
+ call: event.call,
148
+ agent: waiting.agent,
149
+ request: waiting.request,
150
+ });
151
+ } else if (type === "use") {
152
+ void runFor(jamId, handle, event);
153
+ } else if (type === "stop") {
154
+ running.get(String(event.call ?? ""))?.abort();
155
+ } else if (type === "answer") {
156
+ if (waiting?.handle === handle) waiting.finish(answerFrom(event.result));
157
+ } else if (type === "passed") {
158
+ onPassed(handle, event);
159
+ } else if (type === "ended") {
160
+ onEnded(handle, event);
161
+ }
162
+ };
163
+
164
+ return { call, tell, receive, jamWith };
165
+ }
@@ -4,7 +4,10 @@ export declare const USE_SECRET_TOOL: {
4
4
  inputSchema: Record<string, unknown>;
5
5
  };
6
6
  export function secretToolRequest(input: Record<string, unknown>): {
7
- command: "board.vault.list" | "board.vault.use";
7
+ command: "board.vault.list" | "board.vault.use" | "board.vault.pass";
8
+ secret?: string;
9
+ to?: string;
10
+ work?: string;
8
11
  url?: string;
9
12
  method?: string;
10
13
  headers?: string[];
package/lib/vaultTools.js CHANGED
@@ -4,7 +4,7 @@
4
4
  export const USE_SECRET_TOOL = {
5
5
  name: "use_secret",
6
6
  description:
7
- "Call a website's API with one of the person's secrets (an API key, a token, a password) without ever seeing it. Write {{secret:name}} where it goes: in a header, or in the url or the body only where that secret may go there (list shows each one's places); Harness Relay on the person's computer puts the value in, sends the request only to the websites the person allowed for that secret, and gives you the answer with the value replaced by [secret:name]. If the secret is missing or you may not use it yet, the person is asked: tell them, and try again once they have. list: true shows the secrets you may use and where. Never ask the person to paste a secret into the chat.",
7
+ "Call a website's API with one of the person's secrets (an API key, a token, a password) without ever seeing it. Write {{secret:name}} where it goes: in a header, or in the url or the body only where that secret may go there (list shows each one's places); Harness Relay on the person's computer puts the value in, sends the request only to the websites the person allowed for that secret, and gives you the answer with the value replaced by [secret:name]. If the secret is missing or you may not use it yet, the person is asked: tell them, and try again once they have. list: true shows the secrets you may use and where. To let another agent use a secret you may use, give pass (its name), to (the agent, or another person's agent as handle/agent) and work (the task or thread it is for, unless it is the one you are running): that agent can use it, at the same websites and never seeing the value, until the work ends, and the value stays on the computer that keeps it. Passing to another of the person's agents needs nothing from them; passing to another person's agent asks for their OK once per secret and person. A secret passed to you from another person is named handle/secret. Never ask the person to paste a secret into the chat.",
8
8
  inputSchema: {
9
9
  type: "object",
10
10
  properties: {
@@ -24,6 +24,20 @@ export const USE_SECRET_TOOL = {
24
24
  },
25
25
  body: { type: "string" },
26
26
  list: { type: "boolean", description: "show the secrets you may use" },
27
+ pass: {
28
+ type: "string",
29
+ description: "the name of a secret to let another agent use",
30
+ },
31
+ to: {
32
+ type: "string",
33
+ description:
34
+ "who it is passed to: codex, or ana/claude-code for another person's agent",
35
+ },
36
+ work: {
37
+ type: "string",
38
+ description:
39
+ "the id of the task or thread it is passed for; it ends when that ends",
40
+ },
27
41
  },
28
42
  additionalProperties: false,
29
43
  },
@@ -32,6 +46,13 @@ export const USE_SECRET_TOOL = {
32
46
  /** The daemon request a use_secret call makes. */
33
47
  export function secretToolRequest(input) {
34
48
  if (input.list === true) return { command: "board.vault.list" };
49
+ if (typeof input.pass === "string")
50
+ return {
51
+ command: "board.vault.pass",
52
+ secret: input.pass,
53
+ to: typeof input.to === "string" ? input.to : "",
54
+ ...(typeof input.work === "string" ? { work: input.work } : {}),
55
+ };
35
56
  return {
36
57
  command: "board.vault.use",
37
58
  url: typeof input.url === "string" ? input.url : "",
package/lib/verdicts.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { laneHead, containsCommit, personChanges } from "./projectGit.mjs";
2
+ import { laneHead, containsCommit, personChanges } from "./jamGit.mjs";
3
3
  import { verdictEntriesByRun } from "./record.mjs";
4
4
  import { DISPATCHER, nameOf } from "./members.mjs";
5
5
 
@@ -13,21 +13,15 @@ const acceptance = (verdict) =>
13
13
  verdict === "approves" || verdict === "approves_with_changes";
14
14
 
15
15
  /** Returned results, their judgments and return to Make. Counts stay in board_reactions on this person's computer. */
16
- export function createVerdicts({
17
- store,
18
- log = () => {},
19
- projects,
20
- team,
21
- wakeRun,
22
- }) {
23
- const context = (request) => projects()?.verdictContext(request);
24
- const own = (entry) => Boolean(entry) && entry.work.side === entry.project.me;
16
+ export function createVerdicts({ store, log = () => {}, jams, team, wakeRun }) {
17
+ const context = (request) => jams()?.verdictContext(request);
18
+ const own = (entry) => Boolean(entry) && entry.work.side === entry.jam.me;
25
19
  const belongs = (entry, task) =>
26
20
  own(entry) &&
27
21
  (!entry.where ||
28
22
  (task.run_workspace &&
29
23
  path.resolve(task.run_workspace) === path.resolve(entry.where)));
30
- const runsOf = (entry) => store.threadRuns(entry.project.roomId);
24
+ const runsOf = (entry) => store.threadRuns(entry.jam.roomId);
31
25
  const runOf = (entry) => {
32
26
  const id = entry.work.body.returned?.run;
33
27
  return id ? store.getTask(id) : null;
@@ -82,7 +76,7 @@ export function createVerdicts({
82
76
 
83
77
  const judge = (entry, action, reason, source) => {
84
78
  if (!own(entry)) throw new Error("You judge only your own agents' work.");
85
- if (entry.project.status !== "open")
79
+ if (entry.jam.status !== "open")
86
80
  throw new Error("This shared room is not open.");
87
81
  const run = runOf(entry);
88
82
  if (!run?.reported_at || !["done", "failed"].includes(run.status))
@@ -115,7 +109,7 @@ export function createVerdicts({
115
109
  return { ok: true };
116
110
  store.recordReaction({
117
111
  postId: `verdict:${source}:${run.id}`,
118
- goalId: entry.project.roomId,
112
+ goalId: entry.jam.roomId,
119
113
  postSeq: 0,
120
114
  aboutSeq: null,
121
115
  agent: run.claimed_by ?? run.target_agent,
@@ -139,11 +133,11 @@ export function createVerdicts({
139
133
  action === "send_back" &&
140
134
  !(prior?.verdict === "rejects" && prior.reason === why)
141
135
  ) {
142
- team?.sendBack(entry.project.roomId, run.id);
136
+ team?.sendBack(entry.jam.roomId, run.id);
143
137
  entry.update({ status: "checking" });
144
138
  // A detected review does not grant execution authority. The existing wake policy still decides whether it runs.
145
139
  const next = wakeRun(
146
- entry.project.roomId,
140
+ entry.jam.roomId,
147
141
  entry.work.body.agent,
148
142
  `Return the result to Make. What should change: ${why}\n\nThe result: ${entry.work.body.summary}`,
149
143
  {
@@ -179,11 +173,7 @@ export function createVerdicts({
179
173
 
180
174
  const detect = async (request) => {
181
175
  const entry = context(request);
182
- if (
183
- !own(entry) ||
184
- !entry.work.body.returned ||
185
- entry.project.status !== "open"
186
- )
176
+ if (!own(entry) || !entry.work.body.returned || entry.jam.status !== "open")
187
177
  return;
188
178
  publishJudgment(entry);
189
179
  const run = runOf(entry);
@@ -219,11 +209,7 @@ export function createVerdicts({
219
209
  entry.work.body.status === "merged" ||
220
210
  (result.commit &&
221
211
  result.commit !== entry.work.body.base &&
222
- containsCommit(
223
- entry.project.folder,
224
- result.commit,
225
- entry.project.repo.head
226
- ));
212
+ containsCommit(entry.jam.folder, result.commit, entry.jam.repo.head));
227
213
  const reviewed =
228
214
  !pr?.review?.commit ||
229
215
  pr.review.commit === result.commit ||
@@ -312,7 +298,7 @@ export function createVerdicts({
312
298
  returned: { run: result.run, reportSeq: post?.seq ?? null },
313
299
  verdict: verdict ?? null,
314
300
  changedFiles:
315
- mine && where ? changesOf({ project: p, work, where }).length : 0,
301
+ mine && where ? changesOf({ jam: p, work, where }).length : 0,
316
302
  checkedBy: different
317
303
  ? {
318
304
  who: checked.by
@@ -0,0 +1,117 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+
5
+ // Kept versions of files (docs/senses-plan.md S4.3): the content of a file as an agent read it and as each change
6
+ // left it, so a change can be shown as what changed, and a version another's write replaced can be put back (owner,
7
+ // November 13: "im fine with overwritten versions being kept"). A version is named by its git blob id, so the same
8
+ // content is kept once. Kept 30 days, as the log is (cleanup.mjs trims them).
9
+ const KEEP_DAYS = 30;
10
+ const DAY_MS = 86_400_000;
11
+ // A larger file is not kept: comparing it would cost more than it tells.
12
+ export const LARGEST_BYTES = 2_000_000;
13
+ const ID = /^[0-9a-f]{40}$/;
14
+
15
+ /** The git blob id of some bytes (what `git hash-object` says). */
16
+ export const blobId = (bytes) =>
17
+ crypto
18
+ .createHash("sha1")
19
+ .update(`blob ${bytes.length}\0`)
20
+ .update(bytes)
21
+ .digest("hex");
22
+
23
+ /** `root`: the folder versions are kept in. */
24
+ export function createVersions({ root, now = () => Date.now() }) {
25
+ const fileOf = (id) => path.join(root, id.slice(0, 2), id.slice(2));
26
+
27
+ /** A kept version's bytes, or null when it was never kept or has been trimmed. */
28
+ const read = (id) => {
29
+ if (!ID.test(String(id))) return null;
30
+ try {
31
+ return fs.readFileSync(fileOf(id));
32
+ } catch {
33
+ return null;
34
+ }
35
+ };
36
+
37
+ return {
38
+ read,
39
+ /** The full id of a kept version named by its first characters, or null when none or more than one is kept. */
40
+ find(prefix) {
41
+ const start = String(prefix).toLowerCase();
42
+ if (!/^[0-9a-f]{7,40}$/.test(start)) return null;
43
+ let names = [];
44
+ try {
45
+ names = fs.readdirSync(path.join(root, start.slice(0, 2)));
46
+ } catch {}
47
+ const found = names
48
+ .filter((name) => ID.test(start.slice(0, 2) + name))
49
+ .filter((name) => (start.slice(0, 2) + name).startsWith(start));
50
+ return found.length === 1 ? start.slice(0, 2) + found[0] : null;
51
+ },
52
+ /** Keeps a file as it is now and names it; null when it is gone, not a file, or too large. */
53
+ keep(file) {
54
+ let bytes;
55
+ try {
56
+ const stat = fs.statSync(file);
57
+ if (!stat.isFile() || stat.size > LARGEST_BYTES) return null;
58
+ bytes = fs.readFileSync(file);
59
+ } catch {
60
+ return null;
61
+ }
62
+ const id = blobId(bytes);
63
+ const kept = fileOf(id);
64
+ try {
65
+ if (fs.existsSync(kept)) fs.utimesSync(kept, new Date(), new Date());
66
+ else {
67
+ fs.mkdirSync(path.dirname(kept), { recursive: true, mode: 0o700 });
68
+ fs.writeFileSync(`${kept}.part`, bytes, { mode: 0o600 });
69
+ fs.renameSync(`${kept}.part`, kept);
70
+ }
71
+ } catch {
72
+ return null;
73
+ }
74
+ return id;
75
+ },
76
+ /** Puts a kept version back as `file`, keeping what is there now first. `{ ok, replaced }` or `{ ok: false, error }`. */
77
+ restore(id, file) {
78
+ const bytes = read(id);
79
+ if (!bytes) return { ok: false, error: "that version is not kept" };
80
+ const replaced = this.keep(file);
81
+ try {
82
+ fs.mkdirSync(path.dirname(file), { recursive: true });
83
+ fs.writeFileSync(file, bytes);
84
+ } catch (error) {
85
+ return { ok: false, error: error.message };
86
+ }
87
+ return { ok: true, replaced };
88
+ },
89
+ /** Forgets versions not kept or read for 30 days. Returns how many went. */
90
+ trim() {
91
+ let gone = 0;
92
+ let folders = [];
93
+ try {
94
+ folders = fs.readdirSync(root);
95
+ } catch {}
96
+ for (const folder of folders) {
97
+ const full = path.join(root, folder);
98
+ let names = [];
99
+ try {
100
+ names = fs.readdirSync(full);
101
+ } catch {
102
+ continue;
103
+ }
104
+ for (const name of names) {
105
+ const file = path.join(full, name);
106
+ try {
107
+ if (now() - fs.statSync(file).mtimeMs < KEEP_DAYS * DAY_MS)
108
+ continue;
109
+ fs.rmSync(file, { force: true });
110
+ gone++;
111
+ } catch {}
112
+ }
113
+ }
114
+ return gone;
115
+ },
116
+ };
117
+ }