tryharness 0.7.83 → 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 (215) 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 +191 -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 +52 -0
  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 +2426 -338
  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 +1 -1
  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/originals.mjs +216 -0
  107. package/lib/outsideEvents.mjs +383 -0
  108. package/lib/outsideRuns.mjs +230 -0
  109. package/lib/ownMachines.mjs +674 -256
  110. package/lib/pain.mjs +215 -0
  111. package/lib/pairing.mjs +91 -11
  112. package/lib/paths.mjs +42 -3
  113. package/lib/peerProcess.mjs +21 -7
  114. package/lib/peopleLink.mjs +268 -0
  115. package/lib/personNotices.mjs +3 -2
  116. package/lib/phones.mjs +252 -542
  117. package/lib/placeCards.mjs +282 -0
  118. package/lib/placeChecks.mjs +95 -0
  119. package/lib/placeCommands.mjs +8 -17
  120. package/lib/placeRequests.mjs +152 -0
  121. package/lib/placeStore.mjs +295 -0
  122. package/lib/placeTool.d.ts +12 -0
  123. package/lib/placeTool.js +40 -0
  124. package/lib/places.mjs +63 -14
  125. package/lib/plans.mjs +53 -8
  126. package/lib/presence.mjs +270 -0
  127. package/lib/privateNetwork.d.ts +2 -0
  128. package/lib/privateNetwork.js +93 -0
  129. package/lib/proposals.mjs +300 -0
  130. package/lib/publicFetch.d.ts +32 -0
  131. package/lib/publicFetch.js +248 -0
  132. package/lib/reach.mjs +128 -0
  133. package/lib/rebuildable.mjs +72 -0
  134. package/lib/recall.mjs +216 -0
  135. package/lib/record.mjs +13 -0
  136. package/lib/reflexes.mjs +392 -0
  137. package/lib/relayLimits.mjs +31 -2
  138. package/lib/releaseNotice.mjs +198 -0
  139. package/lib/removeHarness.mjs +15 -4
  140. package/lib/repoLinks.mjs +204 -35
  141. package/lib/runAuthority.mjs +102 -39
  142. package/lib/runBrief.mjs +93 -40
  143. package/lib/runRequests.mjs +52 -14
  144. package/lib/runUsage.mjs +31 -0
  145. package/lib/runWorker.mjs +74 -25
  146. package/lib/runner.mjs +289 -45
  147. package/lib/runtime-install.mjs +37 -8
  148. package/lib/schedules.mjs +171 -47
  149. package/lib/screenWatches.mjs +221 -0
  150. package/lib/sealed.mjs +12 -30
  151. package/lib/sealedThreads.mjs +198 -392
  152. package/lib/secretStore.mjs +178 -0
  153. package/lib/secrets.mjs +11 -0
  154. package/lib/seen.mjs +3 -9
  155. package/lib/selfUpdate.mjs +51 -15
  156. package/lib/senseCall.mjs +1514 -0
  157. package/lib/senseHook.mjs +114 -0
  158. package/lib/senseTools.mjs +1298 -0
  159. package/lib/sessionBriefs.mjs +87 -0
  160. package/lib/sessionControl.mjs +63 -13
  161. package/lib/sessionFiles.mjs +85 -0
  162. package/lib/setupChoices.mjs +12 -3
  163. package/lib/setupMode.mjs +70 -25
  164. package/lib/sharedKeys.mjs +166 -0
  165. package/lib/sleep.mjs +396 -0
  166. package/lib/sources.mjs +306 -0
  167. package/lib/speech.mjs +166 -411
  168. package/lib/spoken.mjs +210 -0
  169. package/lib/steerHook.mjs +3 -1
  170. package/lib/steerQueue.mjs +40 -11
  171. package/lib/store.mjs +323 -130
  172. package/lib/stuck.mjs +85 -7
  173. package/lib/swarm.mjs +157 -49
  174. package/lib/swarmDevices.mjs +25 -85
  175. package/lib/swarmMemory.mjs +93 -9
  176. package/lib/t3.mjs +73 -3
  177. package/lib/taskCommands.mjs +51 -60
  178. package/lib/taskRooms.mjs +30 -4
  179. package/lib/taskRules.json +29 -0
  180. package/lib/taskRules.mjs +21 -0
  181. package/lib/taskRuns.mjs +74 -11
  182. package/lib/team.mjs +2 -1
  183. package/lib/threadActions.mjs +37 -9
  184. package/lib/threadAuthority.mjs +4 -4
  185. package/lib/threadBriefs.mjs +173 -43
  186. package/lib/threadNotes.mjs +320 -0
  187. package/lib/threadRecord.mjs +491 -0
  188. package/lib/threadRuns.mjs +216 -108
  189. package/lib/threadView.mjs +27 -30
  190. package/lib/threadWatches.mjs +1962 -0
  191. package/lib/timeSense.mjs +839 -0
  192. package/lib/tripwires.mjs +454 -0
  193. package/lib/ui.mjs +1 -1
  194. package/lib/vault.mjs +560 -45
  195. package/lib/vaultCommands.mjs +5 -3
  196. package/lib/vaultPeers.mjs +165 -0
  197. package/lib/vaultTools.d.ts +4 -1
  198. package/lib/vaultTools.js +22 -1
  199. package/lib/verdicts.mjs +12 -26
  200. package/lib/versions.mjs +117 -0
  201. package/lib/waitTool.mjs +278 -0
  202. package/lib/wakePicture.mjs +268 -0
  203. package/lib/wakeQueue.mjs +108 -0
  204. package/lib/watchResponses.mjs +533 -0
  205. package/lib/watches.mjs +290 -145
  206. package/lib/windowAsks.mjs +80 -17
  207. package/lib/worktrees.mjs +159 -9
  208. package/npm-shrinkwrap.json +138 -631
  209. package/package.json +7 -6
  210. package/release.json +211 -129
  211. package/lib/callSessions.mjs +0 -51
  212. package/lib/directLink.mjs +0 -349
  213. package/lib/peopleBoard.mjs +0 -131
  214. package/lib/projects.mjs +0 -2917
  215. package/lib/roomChannels.mjs +0 -667
@@ -1,26 +1,21 @@
1
1
  // The person's devices across all their computers: one list, kept by home, that only the person changes.
2
2
  //
3
- // Each computer pairs its own devices (phones.mjs: a browser or phone holds a key for that computer alone). This module
4
- // makes them one swarm: every computer reports its devices and the browsers asking to link to it, home keeps the whole
5
- // list, and a decision the person makes on any of their computers (allow, turn down, disconnect) reaches the computer the
6
- // device is paired with. Decisions travel only on the sealed line between the person's own computers (ownMachines.mjs),
7
- // so Harness's server, which carries that line, can neither add a device nor take one away (security audit,
8
- // October 26: "devices registered to the swarm").
9
- //
10
- // A device is let in by the person's own action: a link or QR code made on one of their computers, or an ask they
11
- // allowed on one of their computers or devices. One paired through an offer Harness made (a cloud computer's seeded
12
- // link, cloudBoot.mjs) waits until they allow it, unless it is the first device of a cloud computer that is on its own:
13
- // that one is the browser where the person pressed Add, and the box is Harness's to run anyway.
3
+ // Each computer keeps the devices that reached it (phones.mjs: a browser or phone on the person's signed device list).
4
+ // This module makes them one swarm: every computer reports its devices, home keeps the whole list, and a decision the
5
+ // person makes on any of their computers (allow, turn down, disconnect) reaches the computer the device reached.
6
+ // Decisions travel only on the sealed line between the person's own computers (ownMachines.mjs), so Harness's server,
7
+ // which carries that line, can neither add a device nor take one away (security audit, October 26: "devices registered
8
+ // to the swarm"). A device an older version left waiting for the person stays waiting until they allow it.
14
9
 
15
10
  export const DEVICES_COMMAND = "machine.devices";
16
11
 
17
12
  // On home: what the other computers reported, by computer. On every computer: the person's decisions it has not yet
18
- // seen carried out, by device or ask id.
13
+ // seen carried out, by device id.
19
14
  const REPORTED = "swarm-devices";
20
15
  const DECISIONS = "swarm-device-decisions";
21
16
  const waitingKey = (id) => `device-waiting:${id}`;
22
17
  const DECISION_WORDS = new Set(["allow", "refuse", "remove"]);
23
- // A report is a computer's own devices and asks; more than this is not a person's.
18
+ // A report is a computer's own devices; more than this is not a person's.
24
19
  const MAX_REPORTED = 200;
25
20
  const ID = /^[A-Za-z0-9_-]{8,64}$/;
26
21
 
@@ -28,9 +23,6 @@ export function createSwarmDevices({
28
23
  store,
29
24
  // The person's computers (ownMachines.mjs), or null on a computer that is not in a swarm.
30
25
  computers = () => null,
31
- // This computer's own browsers asking to link (phones.mjs linkAsk): their list, and the person's answer to one.
32
- asks = () => [],
33
- answerAsk = () => ({ ok: false, error: "that browser is no longer asking" }),
34
26
  notify = () => {},
35
27
  log = () => {},
36
28
  }) {
@@ -52,9 +44,9 @@ export function createSwarmDevices({
52
44
  const reported = () => readJson(REPORTED, {});
53
45
 
54
46
  const waiting = (id) => Boolean(store.meta(waitingKey(id)));
55
- // This computer's devices and asks, as the swarm's list holds them.
56
- const mine = () => [
57
- ...store.phones().map((device) => ({
47
+ // This computer's devices, as the swarm's list holds them.
48
+ const mine = () =>
49
+ store.phones().map((device) => ({
58
50
  id: device.id,
59
51
  kind: device.kind || "phone",
60
52
  label: device.label,
@@ -64,30 +56,14 @@ export function createSwarmDevices({
64
56
  : waiting(device.id)
65
57
  ? "waiting"
66
58
  : "listed",
67
- })),
68
- ...asks().map((ask) => ({
69
- id: ask.id,
70
- kind: "ask",
71
- label: ask.label,
72
- at: ask.askedAt,
73
- state: "waiting",
74
- })),
75
- ];
59
+ }));
76
60
  // A decision the person made shows at once in the list, before the computer it is for has carried it out.
77
61
  const decided = (entry) => {
78
62
  const decision = decisions()[entry.id]?.decision;
79
63
  if (!decision || entry.state === "removed") return entry;
80
64
  if (decision === "remove") return { ...entry, state: "removed" };
81
65
  if (entry.state !== "waiting") return entry;
82
- return {
83
- ...entry,
84
- state:
85
- decision === "allow"
86
- ? entry.kind === "ask"
87
- ? "allowed"
88
- : "listed"
89
- : "refused",
90
- };
66
+ return { ...entry, state: decision === "allow" ? "listed" : "refused" };
91
67
  };
92
68
 
93
69
  /** The swarm's whole list, on home; on a worker, its own devices and what home last told it of the others. */
@@ -109,19 +85,13 @@ export function createSwarmDevices({
109
85
  // ---- carrying out the person's decisions on this computer ----
110
86
 
111
87
  const applyHere = (id, decision) => {
112
- const device = store.getPhone(id);
113
- if (device) {
114
- if (decision === "remove") store.revokePhone(id);
115
- else if (decision === "allow") store.meta(waitingKey(id), "");
116
- // A device turned down is disconnected: it never worked here.
117
- else store.revokePhone(id);
118
- return { ok: true };
119
- }
120
- if (asks().some((ask) => ask.id === id))
121
- return answerAsk(id, decision === "allow");
122
- return null;
88
+ if (!store.getPhone(id)) return null;
89
+ if (decision === "allow") store.meta(waitingKey(id), "");
90
+ // A device removed or turned down is disconnected: one turned down never worked here.
91
+ else store.revokePhone(id);
92
+ return { ok: true };
123
93
  };
124
- // The decisions home holds for this computer's own devices and asks, carried out; each is dropped once done.
94
+ // The decisions home holds for this computer's own devices, carried out; each is dropped once done.
125
95
  const carryOut = (forHere) => {
126
96
  let changed = false;
127
97
  for (const [id, entry] of Object.entries(forHere ?? {})) {
@@ -134,7 +104,7 @@ export function createSwarmDevices({
134
104
 
135
105
  // ---- a worker and home ----
136
106
 
137
- // On a worker: its devices and asks to home, which answers with the person's decisions for them. One report at a time;
107
+ // On a worker: its devices to home, which answers with the person's decisions for them. One report at a time;
138
108
  // anything that changes while one is out is sent in the next, right after.
139
109
  let reporting = null;
140
110
  let again = false;
@@ -172,19 +142,15 @@ export function createSwarmDevices({
172
142
  };
173
143
  const clean = (entry) => ({
174
144
  id: String(entry.id),
175
- kind: ["phone", "browser", "ask"].includes(entry.kind)
176
- ? entry.kind
177
- : "phone",
145
+ kind: ["phone", "browser"].includes(entry.kind) ? entry.kind : "phone",
178
146
  label: String(entry.label ?? "").slice(0, 40),
179
147
  at: typeof entry.at === "string" ? entry.at.slice(0, 40) : null,
180
- state: ["listed", "waiting", "removed", "allowed", "refused"].includes(
181
- entry.state
182
- )
148
+ state: ["listed", "waiting", "removed", "refused"].includes(entry.state)
183
149
  ? entry.state
184
150
  : "waiting",
185
151
  });
186
152
 
187
- // On home: the decisions for one computer's devices and asks, and those already carried out dropped.
153
+ // On home: the decisions for one computer's devices, and those already carried out dropped.
188
154
  const decisionsFor = (computer, entries) => {
189
155
  const all = decisions();
190
156
  const ids = new Set(entries.map((entry) => entry.id));
@@ -207,9 +173,7 @@ export function createSwarmDevices({
207
173
  for (const entry of entries)
208
174
  if (entry.state === "waiting" && !known.has(entry.id))
209
175
  notify(
210
- entry.kind === "ask"
211
- ? `A browser (${entry.label}) asks to link to ${labelOf(computer) ?? "another of your computers"}. Allow it on any of your computers or devices: npx tryharness phone allow`
212
- : `${entry.label} was linked to ${labelOf(computer) ?? "another of your computers"} by Harness, not from one of your computers, so it waits for you. Allow it on any of your computers or devices (npx tryharness phone allow), or leave it and it never works.`,
176
+ `${entry.label} waits for you on ${labelOf(computer) ?? "another of your computers"}. Allow it on any of your computers or devices (npx tryharness phone allow), or leave it and it never works.`,
213
177
  `devices:${entry.id}`
214
178
  );
215
179
  };
@@ -248,7 +212,7 @@ export function createSwarmDevices({
248
212
  };
249
213
 
250
214
  /**
251
- * The person's decision on a device or ask, from any of their computers: carried out here when it is this computer's,
215
+ * The person's decision on a device, from any of their computers: carried out here when it is this computer's,
252
216
  * else kept by home for the computer it is for, which hears at once when it can and otherwise on its next report.
253
217
  */
254
218
  const decide = async (id, decision) => {
@@ -283,32 +247,8 @@ export function createSwarmDevices({
283
247
  return { ok: true, computer: labelOf(entry.computer) };
284
248
  };
285
249
 
286
- // A device of the person's that works here: paired, not disconnected and not waiting for them.
287
- const anotherListed = (id) =>
288
- store
289
- .phones()
290
- .some(
291
- (device) =>
292
- device.id !== id && !device.revoked_at && !waiting(device.id)
293
- );
294
-
295
- /**
296
- * A device just paired on this computer. One the person's own action let in (a link or code made here) is listed. One
297
- * paired through an offer Harness made waits for the person, who allows it with one press on any of their computers
298
- * or devices, when this computer works for a home of theirs or already has a device of theirs. The first device of a
299
- * cloud computer on its own is listed: it is the browser where they pressed Add, with nothing else of theirs to press
300
- * on.
301
- */
302
- const paired = (device, { seeded = false } = {}) => {
303
- if (seeded && (own()?.joined?.() || anotherListed(device.id)))
304
- store.meta(waitingKey(device.id), new Date().toISOString());
305
- void report();
306
- return waiting(device.id) ? "waiting" : "listed";
307
- };
308
-
309
250
  return {
310
251
  list,
311
- paired,
312
252
  waiting,
313
253
  decide,
314
254
  report,
@@ -78,6 +78,8 @@ export function createSwarmMemory({
78
78
  agentText = (row) => row.text,
79
79
  // What the person saw (seen.mjs): read at each dream, shown to the person's own searches only.
80
80
  seenMemory = null,
81
+ // Offering a lesson's retirement to the person (proposals.mjs, S8.4): the dream proposes, the person starts it.
82
+ proposeRetire = () => null,
81
83
  log = () => {},
82
84
  }) {
83
85
  // ── The vectors of what memory can show, kept in memory and topped up with what was embedded since ───────────────
@@ -356,6 +358,8 @@ export function createSwarmMemory({
356
358
  proof: observation.proof,
357
359
  quote: observation.evidence.at(-1)?.quote ?? null,
358
360
  thread: observation.evidence.at(-1)?.goalId ?? null,
361
+ // Put in the person's own words (S8.3): its source is them.
362
+ byPerson: observation.evidence.some((entry) => entry.person),
359
363
  // The posts it stands on, to read in full.
360
364
  sources: observation.evidence
361
365
  .map((entry) => entry.contributionId)
@@ -671,6 +675,13 @@ export function createSwarmMemory({
671
675
  folder: lesson.folder,
672
676
  }));
673
677
 
678
+ // The dream that is writing now (its start time), so every write it makes is journaled and can be undone whole
679
+ // (docs/senses-plan.md S8.3); null outside a dream.
680
+ let dreaming = null;
681
+ const journal = (op, target, before = null) => {
682
+ if (dreaming) store.journalDream(dreaming, op, String(target), before);
683
+ };
684
+
674
685
  const applyObservation = async (draft, facts) => {
675
686
  const fact = facts.find((row) => row.id === draft.fact);
676
687
  if (!fact) return null;
@@ -684,17 +695,26 @@ export function createSwarmMemory({
684
695
  ];
685
696
  const match = draft.match ? store.getObservation(draft.match.id) : null;
686
697
  if (match && match.status === "active") {
687
- if (draft.match.relation === "same")
698
+ if (draft.match.relation === "same") {
699
+ journal("observation-confirmed", match.id, {
700
+ evidence: match.evidence,
701
+ });
688
702
  return {
689
703
  ...store.confirmObservation(match.id, evidence),
690
704
  change: "same",
691
705
  };
706
+ }
707
+ // What the person wrote themselves stands: the dream never changes their correction.
708
+ if (match.evidence.some((entry) => entry.person)) return null;
692
709
  const revised = store.reviseObservation(match.id, {
693
710
  text: draft.text,
694
711
  evidence,
695
712
  why: `${nameOf(fact.author)}, ${dateOf(fact.created_at)}: "${clip(draft.quote, 160)}"`,
696
713
  });
697
- if (revised) await embedObservation(revised).catch(() => {});
714
+ if (revised) {
715
+ journal("observation-revised", revised.id, { was: match.id });
716
+ await embedObservation(revised).catch(() => {});
717
+ }
698
718
  return revised ? { ...revised, change: draft.match.relation } : null;
699
719
  }
700
720
  const added = store.addObservation({
@@ -704,6 +724,7 @@ export function createSwarmMemory({
704
724
  text: draft.text,
705
725
  evidence,
706
726
  });
727
+ journal("observation-added", added.id);
707
728
  await embedObservation(added).catch(() => {});
708
729
  return { ...added, change: "new" };
709
730
  };
@@ -791,6 +812,7 @@ export function createSwarmMemory({
791
812
  : []),
792
813
  ],
793
814
  });
815
+ journal("observation-added", added.id);
794
816
  await embedObservation(added).catch(() => {});
795
817
  report.kept.push({ id: added.id, text: added.text, change: "new" });
796
818
  }
@@ -827,6 +849,7 @@ export function createSwarmMemory({
827
849
  ],
828
850
  });
829
851
  await embedObservation(added).catch(() => {});
852
+ journal("observation-added", added.id);
830
853
  return { id: added.id, text: added.text, change: "new" };
831
854
  };
832
855
 
@@ -838,14 +861,24 @@ export function createSwarmMemory({
838
861
  return { ...report, ok: false, why };
839
862
  };
840
863
 
841
- const dream = async ({ limit = DREAM_FACTS, before = null } = {}) => {
864
+ const dream = async (options = {}) => {
865
+ const at = new Date().toISOString();
866
+ dreaming = at;
867
+ try {
868
+ return await dreamAt(at, options);
869
+ } finally {
870
+ dreaming = null;
871
+ }
872
+ };
873
+ const dreamAt = async (at, { limit = DREAM_FACTS, before = null } = {}) => {
842
874
  const report = {
843
875
  ok: true,
844
- at: new Date().toISOString(),
876
+ at,
845
877
  read: 0,
846
878
  kept: [],
847
879
  changed: [],
848
880
  retired: [],
881
+ proposed: [],
849
882
  widened: [],
850
883
  };
851
884
  // On this computer, with no model: kept on the privacy setting too.
@@ -926,13 +959,19 @@ export function createSwarmMemory({
926
959
  if (!lesson) continue;
927
960
  meta(`dream-lesson:${lesson.id}`, report.at);
928
961
  if (verdict.verdict === "one_job") {
929
- const retired = store.retireLesson(
930
- lesson.id,
931
- "an instruction for one job, read after the work"
962
+ // Offered, never done by the dream: it runs once the person starts it (S8.4).
963
+ const offered = proposeRetire(
964
+ store.getLesson(lesson.id) ?? lesson,
965
+ "read after the work"
932
966
  );
933
- if (retired)
934
- report.retired.push({ id: lesson.id, text: lesson.text });
967
+ if (offered)
968
+ report.proposed.push({ id: lesson.id, text: lesson.text });
935
969
  } else if (verdict.scope === "everywhere" && lesson.folder) {
970
+ const was = store.getLesson(lesson.id);
971
+ journal("lesson-widened", lesson.id, {
972
+ scope: was?.scope ?? "this_folder",
973
+ folder: was?.folder ?? lesson.folder,
974
+ });
936
975
  store.widenLesson(lesson.id);
937
976
  report.widened.push({ id: lesson.id, text: lesson.text });
938
977
  }
@@ -966,6 +1005,51 @@ export function createSwarmMemory({
966
1005
  push,
967
1006
  lastDream,
968
1007
  lastFailure: () => meta("dream-failed") || null,
1008
+ /**
1009
+ * The person's Undo of one dream (`at`, its start time): every write it made taken back, newest first, as long as
1010
+ * what it wrote is still as it left it. `{ undone, skipped }`, or null for a dream that wrote nothing.
1011
+ */
1012
+ undoDream(at) {
1013
+ const entries = store.dreamJournal(String(at || ""));
1014
+ if (!entries.length) return null;
1015
+ let undone = 0;
1016
+ let skipped = 0;
1017
+ for (const entry of entries) {
1018
+ const observation = entry.op.startsWith("observation")
1019
+ ? store.getObservation(entry.target)
1020
+ : null;
1021
+ const lesson = entry.op.startsWith("lesson")
1022
+ ? store.getLesson(entry.target)
1023
+ : null;
1024
+ const still = entry.op.startsWith("observation")
1025
+ ? observation?.status === "active"
1026
+ : Boolean(lesson);
1027
+ if (!still) {
1028
+ skipped += 1;
1029
+ continue;
1030
+ }
1031
+ if (entry.op === "observation-added")
1032
+ store.setObservationStatus(entry.target, "undone");
1033
+ else if (entry.op === "observation-confirmed")
1034
+ store.setObservationEvidence(entry.target, entry.before.evidence);
1035
+ else if (entry.op === "observation-revised") {
1036
+ store.setObservationStatus(entry.target, "undone");
1037
+ store.reopenObservation(entry.before.was);
1038
+ } else if (entry.op === "lesson-retired")
1039
+ store.restoreLesson(entry.target);
1040
+ else if (entry.op === "lesson-widened")
1041
+ store.unwidenLesson(entry.target, entry.before);
1042
+ undone += 1;
1043
+ }
1044
+ meta(`dream-undone:${at}`, new Date().toISOString());
1045
+ return { undone, skipped };
1046
+ },
1047
+ /** The person's own words for one belief: a new belief that names them as its source, the old one replaced. */
1048
+ correct(id, text) {
1049
+ const corrected = store.correctObservation(String(id || ""), text);
1050
+ if (corrected) void embedObservation(corrected).catch(() => {});
1051
+ return corrected ? observationView(corrected) : null;
1052
+ },
969
1053
  observations: (options) => store.observations(options).map(observationView),
970
1054
  seen: (options) => seenMemory?.list(options) ?? [],
971
1055
  };
package/lib/t3.mjs CHANGED
@@ -399,6 +399,50 @@ export async function sendToT3(threadId, text) {
399
399
  return sent.delivery === "queued" ? "queued" : "started";
400
400
  }
401
401
 
402
+ // The pictures T3 takes as images; any other file goes as a file (t3_attachment_prepare_upload).
403
+ const T3_IMAGES = new Set([
404
+ "image/gif",
405
+ "image/jpeg",
406
+ "image/png",
407
+ "image/webp",
408
+ ]);
409
+
410
+ /**
411
+ * The person's words and files into a T3 Code thread as T3's own attachments: each file uploaded to the address T3 signs,
412
+ * then one message carrying them all. "started" or "queued" behind its turn.
413
+ */
414
+ export async function sendFilesToT3(threadId, text, files) {
415
+ const attachments = [];
416
+ for (const saved of files) {
417
+ const about = {
418
+ type: T3_IMAGES.has(saved.mime) ? "image" : "file",
419
+ name: saved.name,
420
+ mimeType: saved.mime,
421
+ sizeBytes: saved.bytes,
422
+ };
423
+ const { attachmentId, relativeUrl } = await t3Tool(
424
+ "t3_attachment_prepare_upload",
425
+ { upload: about }
426
+ );
427
+ // Read after the call: t3Tool keeps the address T3 answers on now.
428
+ const { origin } = readJson(file(), {});
429
+ const uploaded = await fetch(`${origin}${relativeUrl}`, {
430
+ method: "POST",
431
+ headers: { "content-type": saved.mime },
432
+ body: fs.readFileSync(saved.path),
433
+ });
434
+ if (!uploaded.ok)
435
+ throw new T3Error("refused", `T3 Code refused ${saved.name}`);
436
+ attachments.push({ ...about, id: attachmentId });
437
+ }
438
+ const sent = await t3Tool("t3_thread_send_attachments", {
439
+ threadId,
440
+ attachments,
441
+ message: text || null,
442
+ });
443
+ return sent.delivery === "queued" ? "queued" : "started";
444
+ }
445
+
402
446
  // ── A thread's turn, carried out by T3 Code ──────────────────────────────────
403
447
 
404
448
  // How often a turn handed to T3 is read back for its steps and its end: as often as the buddy reads a session's feed.
@@ -448,6 +492,26 @@ function didLine(item, text) {
448
492
  return (!raw && text.split("\n")[0]) || String(item.type).replace(/_/g, " ");
449
493
  }
450
494
 
495
+ /**
496
+ * What one item of a T3 thread ran or changed, for going in circles (circling.mjs): `{ command }` or `{ files }`, files
497
+ * under `folder`, T3's checkout. T3 keeps a command as its first line ("$ npm test") and a file change as its path.
498
+ */
499
+ export function t3Acts(item, folder) {
500
+ const text = String(item.text || "").trim();
501
+ if (item.type === "command_execution" && item.title !== "Workspace ready") {
502
+ const command = text
503
+ .split("\n")[0]
504
+ .replace(/^\$\s*/, "")
505
+ .trim();
506
+ return command ? [{ command }] : [];
507
+ }
508
+ if (item.type === "file_change") {
509
+ const file = text.split(" {")[0].trim();
510
+ return file ? [{ files: [path.resolve(folder || "/", file)] }] : [];
511
+ }
512
+ return [];
513
+ }
514
+
451
515
  /** One item of a T3 thread as a step on the board: its words, or what it did in a line; null for T3's own bookkeeping. */
452
516
  export function t3Step(item) {
453
517
  const text = String(item.text || "").trim();
@@ -539,7 +603,7 @@ async function selectionFor({ instanceId, model, effort } = {}) {
539
603
  * its session (the T3 thread, which is how Open finds it), each step, then done with the agent's last words or failed;
540
604
  * Stop interrupts it in T3.
541
605
  */
542
- export function runInT3(run, emit, observe) {
606
+ export function runInT3(run, emit, observe, hooks = {}) {
543
607
  let threadId = run.threadId ?? null,
544
608
  runId = null,
545
609
  cursor = null,
@@ -566,12 +630,14 @@ export function runInT3(run, emit, observe) {
566
630
  release();
567
631
  };
568
632
  // What the turn used, as T3 recorded it, so a turn there counts toward its thread's spend like one run here.
569
- const finish = (kind, text, failure) => {
633
+ // `nothingSaid`: the turn ended with nothing written; one that ended to wait says so instead (runWorker.mjs).
634
+ const finish = (kind, text, failure, nothingSaid = false) => {
570
635
  letGo();
571
636
  emit(kind, text.slice(0, 20_000), {
572
637
  usage:
573
638
  threadId && runId ? (run.usageOf?.(threadId, runId) ?? null) : null,
574
639
  ...(failure ? { failure } : {}),
640
+ ...(nothingSaid ? { nothingSaid } : {}),
575
641
  });
576
642
  };
577
643
  const read = async () => {
@@ -595,6 +661,8 @@ export function runInT3(run, emit, observe) {
595
661
  !seen.has(item.itemId)
596
662
  ) {
597
663
  seen.add(item.itemId);
664
+ for (const act of t3Acts(item, run.checkout || run.cwd))
665
+ hooks.acted?.(act);
598
666
  const step = t3Step(item);
599
667
  if (step) {
600
668
  if (step.kind === "say") last = step.text;
@@ -629,7 +697,9 @@ export function runInT3(run, emit, observe) {
629
697
  return finish(
630
698
  "done",
631
699
  last ||
632
- "The run finished in T3 Code; its changes are in T3's checkout."
700
+ "The run finished in T3 Code; its changes are in T3's checkout.",
701
+ null,
702
+ !last
633
703
  );
634
704
  // A turn restarted with the person's words ends as the next one starts: that one is followed instead.
635
705
  if (ENDED.has(status) && !steering)