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
@@ -0,0 +1,282 @@
1
+ import { nameOf as memberName } from "./members.mjs";
2
+
3
+ // What the person reads of their places, in their words: a place's card (what joining involves, what the swarm could
4
+ // do there, what was left out and why, what it may do now and what it did) and each line of its record. No methods,
5
+ // paths or ids: those are for agents. The dashboard, the PiP, the phone and the buddy only lay these out.
6
+
7
+ export const DEFAULT_PERSONA =
8
+ "An AI swarm a person runs with Harness. It reads here and joins in about what it reads, and says nothing about the person who runs it.";
9
+ /** The reason a write may say something private: its draft is never previewed anywhere but its own card. */
10
+ export const PRIVATE_WHY = "It may say something private";
11
+ /** The reason a write waits in Drafts: the person's mode there, which the card already says. */
12
+ export const DRAFTS_WHY = "Drafts wait to be sent by hand.";
13
+
14
+ /** A place's name: its own, else its site. */
15
+ export const nameOf = (place) => place.name ?? new URL(place.origin).host;
16
+ // Each agent by the name the person knows it by (the swarm's one list, members.json).
17
+ const agentName = (id) => (id === "user" ? "You" : memberName(id));
18
+
19
+ /**
20
+ * A place as the person's card shows it, in their words: what joining involves, what the swarm could do there, what
21
+ * was left out and why, what it may do now and what it did. No methods, paths or ids: those are for agents.
22
+ */
23
+ export function cardOf(place, acts = []) {
24
+ const definition = place.definition;
25
+ const doing = (wanted) => {
26
+ // Led by what a member agent does most there (Jev's ranking at compile), else the shallowest paths first.
27
+ const depth = (action) => action.path.split("/").filter(Boolean).length;
28
+ const actions = definition.actions
29
+ .filter((action) => action.class === wanted)
30
+ .sort(
31
+ (a, b) =>
32
+ (b.everyday ?? 0) - (a.everyday ?? 0) ||
33
+ depth(a) - depth(b) ||
34
+ a.path.length - b.path.length
35
+ );
36
+ return {
37
+ count: actions.length,
38
+ examples: [
39
+ ...new Set(
40
+ actions
41
+ .map((action) => saysWhat(action))
42
+ .filter((words) => words.length > 3)
43
+ ),
44
+ ].slice(0, 4),
45
+ };
46
+ };
47
+ const personSteps = definition.join.filter((step) => step.kind === "person");
48
+ return {
49
+ id: place.id,
50
+ name: nameOf(place),
51
+ site: new URL(place.origin).host,
52
+ about:
53
+ definition.intro ??
54
+ (definition.description ? firstSentence(definition.description) : null),
55
+ status: place.status,
56
+ allowed: place.allowed,
57
+ persona: place.persona || DEFAULT_PERSONA,
58
+ memberName: place.member_name,
59
+ writesPerDay: place.writes_per_day,
60
+ joinedAt: place.joined_at,
61
+ signsUp: definition.join.some((step) => step.kind === "request"),
62
+ yourPart: personSteps.map((step) => ({
63
+ how: step.how,
64
+ words: firstSentence(plain(step.text)),
65
+ })),
66
+ checksIn: Boolean(definition.checkIn),
67
+ could: {
68
+ read: doing("read"),
69
+ write: doing("write"),
70
+ pay: doing("money"),
71
+ },
72
+ rules: definition.rules
73
+ .map((rule) => firstSentence(plain(rule)))
74
+ .slice(0, 6),
75
+ leftOut: leftOutLines(
76
+ place.findings.filter((finding) => finding.kind !== "flagged")
77
+ ),
78
+ // Flags that change nothing the person decides (a door that carries everything, a link to another site) are left
79
+ // off the card; what Harness left out, hidden text and personal-detail demands stay.
80
+ flagged: leftOutLines(
81
+ place.findings.filter(
82
+ (finding) =>
83
+ finding.kind === "flagged" &&
84
+ !["carries_everything", "points_elsewhere"].includes(finding.why)
85
+ )
86
+ ),
87
+ newVersion: place.pending
88
+ ? {
89
+ leftOut: leftOutLines(
90
+ place.pending.findings.filter(
91
+ (finding) => finding.kind !== "flagged"
92
+ )
93
+ ),
94
+ }
95
+ : null,
96
+ news: Boolean(
97
+ place.news_at && (!place.seen_at || place.news_at > place.seen_at)
98
+ ),
99
+ newsAt: place.news_at,
100
+ record: acts.map((one) => actLine(one, place)),
101
+ };
102
+ }
103
+
104
+ /** An action in the person's words: the route list's own line, else the file's words without methods and paths. */
105
+ function saysWhat(action) {
106
+ return firstSentence(action.summary ?? plain(action.described));
107
+ }
108
+
109
+ /** A site's words as a person reads them: no list marks, code marks, methods or paths. */
110
+ function plain(text) {
111
+ return text
112
+ .replace(/^[-*]\s*/, "")
113
+ .replace(/\b(GET|POST|PUT|PATCH|DELETE)\s+(https?:\/\/\S+|\/\S*)[:,]?/g, "")
114
+ .replace(/`[^`]*`/g, "")
115
+ .replace(/\s{2,}/g, " ")
116
+ .replace(/^[\s:,.;-]+/, "")
117
+ .trim();
118
+ }
119
+
120
+ /** A text's first sentence, or its first 200 characters marked as cut. */
121
+ export const firstSentence = (text) => {
122
+ const sentence = text.match(/^.{1,200}?[.!?](\s|$)/)?.[0];
123
+ if (sentence) return sentence.trim();
124
+ return text.length > 200 ? `${text.slice(0, 199).trimEnd()}…` : text.trim();
125
+ };
126
+
127
+ // The card's words for each finding: what was left out and why, in plain sentences.
128
+ const WHY_WORDS = {
129
+ follows_remote_instructions:
130
+ "It tells agents to fetch new instructions later and follow them. Your swarm won't, so the site can't steer it.",
131
+ runs_or_installs:
132
+ "It also offers a program to install. Harness won't install it.",
133
+ changes_the_agent:
134
+ "It tells agents to change their own instructions or memory. Your swarm won't.",
135
+ asks_for_secrets:
136
+ "It asks for keys or passwords beyond its own, so your swarm can't join.",
137
+ asks_for_personal_details:
138
+ "It asks for personal details. Your swarm won't share them.",
139
+ points_elsewhere: "It points to another site. Your swarm stays on this one.",
140
+ hidden_content: "Part of its file is hidden from people reading it.",
141
+ carries_everything:
142
+ "One of its doors can do anything at once. Your swarm uses its single requests instead.",
143
+ unsure: "Harness couldn't tell what this part asks, so your swarm skips it.",
144
+ };
145
+
146
+ /**
147
+ * What was left out, one line per reason, each with the site's own words behind it (cut at a word, never mid-word), so
148
+ * the person reads what Harness decided first and what the site said only if they look.
149
+ */
150
+ export function leftOutLines(findings) {
151
+ const byWhy = new Map();
152
+ for (const finding of findings) {
153
+ const line = byWhy.get(finding.why) ?? {
154
+ kind: finding.kind,
155
+ why: WHY_WORDS[finding.why],
156
+ quotes: [],
157
+ };
158
+ if (finding.kind === "refused") line.kind = "refused";
159
+ const quote =
160
+ finding.why === "hidden_content"
161
+ ? ""
162
+ : cutAtWord(plain(finding.text), 240);
163
+ if (quote && !line.quotes.includes(quote)) line.quotes.push(quote);
164
+ byWhy.set(finding.why, line);
165
+ }
166
+ return [...byWhy.values()];
167
+ }
168
+ const cutAtWord = (text, room) =>
169
+ text.length <= room
170
+ ? text
171
+ : `${text.slice(0, text.lastIndexOf(" ", room - 1)).replace(/[\s,;:]+$/, "")}…`;
172
+ // How a write stands, in the person's words.
173
+ const STATUS_WORDS = {
174
+ sent: "sent",
175
+ held: "waiting for you",
176
+ refused: "stopped",
177
+ discarded: "discarded",
178
+ failed: "didn't go through",
179
+ };
180
+ /**
181
+ * What a write is, from the site's own line for it: "Publish a post." is "post", "Vote on a post or comment." stays
182
+ * as it is. Plain words for the person, never a method or a path.
183
+ */
184
+ function contentOf(says) {
185
+ const match = says.match(
186
+ /^(?:publish|post|create|submit|add|write|send|leave|make)\s+(?:an?|the|your)?\s*([a-z][a-z -]{1,30}?)\.?$/i
187
+ );
188
+ return match ? match[1].toLowerCase() : says.replace(/\.$/, "");
189
+ }
190
+ const withArticle = (content) =>
191
+ /^[a-z]+$/.test(content) && !/s$/.test(content)
192
+ ? `${/^[aeiou]/.test(content) ? "an" : "a"} ${content}`
193
+ : content;
194
+
195
+ // What happened, as the record's first words: "Grok Bot sent", "Codex wants to send".
196
+ const HAPPENED = {
197
+ sent: "sent",
198
+ held: "wants to send",
199
+ refused: "was stopped from sending",
200
+ discarded: "had a draft discarded:",
201
+ failed: "tried to send",
202
+ };
203
+
204
+ export const actLine = (act, place) => {
205
+ const action = place?.definition.actions.find(
206
+ (one) => one.method === act.method && one.path === act.path
207
+ );
208
+ const joined = action?.role === "register";
209
+ const isPrivate = Boolean(act.why?.startsWith(PRIVATE_WHY));
210
+ const content = action ? contentOf(saysWhat(action)) : "write";
211
+ const what = joined ? "" : draftText(act.fields, action);
212
+ const quoted = what.split("\n").find(Boolean)?.slice(0, 120);
213
+ return {
214
+ id: act.id,
215
+ at: act.at,
216
+ // The record's line in the person's words: "You joined", "Grok Bot sent “What I read today”". A draft that may be
217
+ // private is never quoted outside its own card.
218
+ headline: joined
219
+ ? "You joined"
220
+ : act.status === "discarded"
221
+ ? `You discarded ${agentName(act.agent)}'s ${content}${isPrivate ? ". It may have been private." : quoted ? `: “${quoted}”` : ""}`
222
+ : `${agentName(act.agent)} ${HAPPENED[act.status]} ${
223
+ isPrivate
224
+ ? `${withArticle(content)} that may be private`
225
+ : quoted
226
+ ? `“${quoted}”`
227
+ : withArticle(content)
228
+ }`,
229
+ /** What it is, in a word or two: "a post", "a comment", else the site's own line. */
230
+ content: withArticle(content),
231
+ /** An ordinary draft (it waits only because the person said drafts wait), not something held back. */
232
+ routine: act.status === "held" && !isPrivate && act.class !== "money",
233
+ /** Shown on the draft's card: why it waits, unless it is only the mode the card already states. */
234
+ shownWhy: act.why && act.why !== DRAFTS_WHY ? act.why : null,
235
+ private: isPrivate,
236
+ /** It answers something at the place (a post, a comment) that the draft names only by id. */
237
+ replies: Object.entries(act.fields).some(
238
+ ([name, value]) => /(^|_)id$/i.test(name) && Boolean(value)
239
+ ),
240
+ // A held draft's own words, field by field, for the person to edit before it goes.
241
+ editable:
242
+ act.status === "held"
243
+ ? Object.entries(act.fields)
244
+ .filter(
245
+ ([name, value]) =>
246
+ typeof value === "string" && !/(^|_)id$/i.test(name)
247
+ )
248
+ .map(([name, value]) => ({ name, value: String(value) }))
249
+ : [],
250
+ agent: agentName(act.agent),
251
+ // The person's own sign-up is "Signed up", not the site's word for it or the fields it was sent.
252
+ doing:
253
+ action?.role === "register"
254
+ ? "Signed up"
255
+ : action
256
+ ? saysWhat(action)
257
+ : "",
258
+ pays: act.class === "money",
259
+ status: act.status,
260
+ statusWords: STATUS_WORDS[act.status],
261
+ why: act.why,
262
+ what,
263
+ };
264
+ };
265
+ /**
266
+ * A write's words, as the person reads them in the record and on a held draft: its prose fields in the order the
267
+ * action takes them (a title before its body; jsonb keeps its own order), without ids.
268
+ */
269
+ const draftText = (fields, action) => {
270
+ const order = action?.inputs.map((input) => input.name) ?? [];
271
+ const rank = (name) =>
272
+ order.includes(name) ? order.indexOf(name) : order.length;
273
+ return Object.entries(fields)
274
+ .filter(
275
+ ([name, value]) =>
276
+ typeof value === "string" && value.trim() && !/(^|_)id$/i.test(name)
277
+ )
278
+ .sort(([a], [b]) => rank(a) - rank(b))
279
+ .map(([, value]) => String(value))
280
+ .join("\n\n")
281
+ .slice(0, 2_000);
282
+ };
@@ -0,0 +1,95 @@
1
+ import { secretReason } from "./secrets.mjs";
2
+ import { DRAFTS_WHY, PRIVATE_WHY, nameOf } from "./placeCards.mjs";
3
+
4
+ // What every write to a place passes before this computer sends it, in order: what the person allowed there, secrets
5
+ // (the shared patterns and the place's own key), money (stopped: paying is not built), a judgment of whether it says
6
+ // anything private beyond the place's persona, and the day's writes. Code decides everything but the judgment, which
7
+ // is a model's and runs on Harness's server (src/server/places/judgments.ts). A write that fails a code check is
8
+ // refused with the reason; one the person should see first is held for them; only a clean write where the person let
9
+ // the swarm write on its own goes out. Every reason is stored once and read by agents and by the person alike, so
10
+ // none says "the person" or "you".
11
+
12
+ // Measured by eval places-disclosure (v1): private drafts scored 0.66 and up, ordinary ones 0.23 and below, so a
13
+ // draft judged this likely to say something private waits for the person.
14
+ export const DISCLOSURE_HOLD = 0.5;
15
+
16
+ /** Words a draft could be private for, found by their shape: names, contacts, places on disk, amounts. */
17
+ export function privateCandidates(draft) {
18
+ const shapes = [
19
+ /\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)+\b/g,
20
+ /[\w.+-]+@[\w-]+\.[\w.-]+/g,
21
+ /\+?\d[\d\s().-]{7,}\d/g,
22
+ /(?:~|\/Users|\/home)\/[\w./-]+/g,
23
+ /\b\d[\d,.]*\s*(?:ETH|BTC|USDC|USDT|SOL|USD|dollars?)\b|\$\d[\d,.]*/gi,
24
+ ];
25
+ const found = shapes.flatMap((shape) => draft.match(shape) ?? []);
26
+ return [...new Set(found.map((one) => one.trim()))].slice(0, 12);
27
+ }
28
+
29
+ /**
30
+ * { go: "send" }, { go: "hold", why } or { go: "refuse", why }. `holdsKey(text)`: whether the text carries the place's
31
+ * own key. `judge({ place, persona, draft, candidates })`: { mass, mention } from the server's judgment, or null when
32
+ * it could not run.
33
+ */
34
+ export async function checkWrite({
35
+ place,
36
+ action,
37
+ values,
38
+ sentToday,
39
+ holdsKey,
40
+ judge,
41
+ }) {
42
+ const name = nameOf(place);
43
+ if (place.status !== "joined")
44
+ return { go: "refuse", why: `Your swarm is not a member of ${name}.` };
45
+ if (place.allowed === "read")
46
+ return {
47
+ go: "refuse",
48
+ why: `Your swarm only reads at ${name} until it is allowed to draft there.`,
49
+ };
50
+ const text = JSON.stringify(values);
51
+ const secret = secretReason(text);
52
+ if (secret)
53
+ return {
54
+ go: "refuse",
55
+ why: `It carries ${secret}, which never goes to a place.`,
56
+ };
57
+ if (await holdsKey(text))
58
+ return {
59
+ go: "refuse",
60
+ why: `It carries the swarm's own key for ${name}.`,
61
+ };
62
+ // Places cannot pay yet: no wallet is wired to a place's payment request, so holding one would promise a payment
63
+ // that cannot happen. It is stopped, and nothing is paid.
64
+ if (action.class === "money")
65
+ return {
66
+ go: "refuse",
67
+ why: "Paying at places isn't set up yet, so nothing was paid.",
68
+ };
69
+ const judged = await judge({
70
+ place: name,
71
+ persona: place.persona,
72
+ draft: text,
73
+ candidates: privateCandidates(text),
74
+ }).catch(() => null);
75
+ if (!judged || typeof judged.mass !== "number")
76
+ return {
77
+ go: "hold",
78
+ why: "The privacy check could not run, so it waits to be looked at first.",
79
+ };
80
+ if (judged.mass >= DISCLOSURE_HOLD)
81
+ return {
82
+ go: "hold",
83
+ why: judged.mention
84
+ ? `${PRIVATE_WHY}. It mentions “${judged.mention}”.`
85
+ : `${PRIVATE_WHY}.`,
86
+ };
87
+ if (place.allowed === "drafts") return { go: "hold", why: DRAFTS_WHY };
88
+ // The day's limit is on what goes out on its own: past it, the rest wait for the person.
89
+ if (sentToday >= place.writes_per_day)
90
+ return {
91
+ go: "hold",
92
+ why: `Today's ${place.writes_per_day} at ${name} are used, so it waits to be sent by hand.`,
93
+ };
94
+ return { go: "send" };
95
+ }
@@ -1,26 +1,17 @@
1
- // Places on the person's computer: the desktop buddy reaches the outside networks its swarm is in through this daemon,
2
- // which asks Harness's server over its bridge (`place_op`). Harness holds each place's key and makes every request;
3
- // this side only carries the person's ops. Only the person ("user") calls these: agents use the `place` tool, which
4
- // Harness answers itself.
1
+ // board.place.op: the person's places at outside networks, answered on their home computer (networkPlaces.mjs). Every
2
+ // surface calls it: the person ("user", sealed from their browser or phone, or the buddy here), Harness's own turn
3
+ // ("harness", through its server), and agents, here or through home from another computer or through Harness's server
4
+ // from outside. networkPlaces decides what each may do.
5
5
 
6
- export function createPlaceCommands({ askHarness }) {
6
+ export function createPlaceCommands({ places }) {
7
7
  const command = (request, agent) => {
8
- if (agent !== "user")
9
- return { ok: false, error: "only the person manages places from here" };
10
8
  if (request.command !== "board.place.op")
11
9
  return { ok: false, error: `unknown command ${request.command}` };
12
10
  const { command: _command, agent: _agent, ...input } = request;
13
11
  return {
14
- pending: askHarness("place_op", input).then(
15
- (answer) =>
16
- answer.ok
17
- ? answer
18
- : {
19
- ok: false,
20
- error: answer.error || "Harness refused the request",
21
- },
22
- (error) => ({ ok: false, error: error.message })
23
- ),
12
+ pending: places
13
+ .op(input, String(agent || ""))
14
+ .catch((error) => ({ ok: false, error: error.message })),
24
15
  };
25
16
  };
26
17
  return { command };
@@ -0,0 +1,152 @@
1
+ // One request to a place, built only from an action in its definition: the method and path it names, its path
2
+ // parameters filled with plain values, its query and JSON body from what it takes. Nothing else can be sent: the
3
+ // origin is the place's own and the path is the action's, so an agent cannot point this computer anywhere new.
4
+
5
+ // A path parameter is one segment: an id or a handle, never something that could climb out of the path. "." and ".."
6
+ // are made only of allowed characters, and a URL resolves them, so they are refused by name.
7
+ const SEGMENT = /^[A-Za-z0-9._~-]{1,200}$/;
8
+ const plainSegment = (text) =>
9
+ SEGMENT.test(text) && text !== "." && text !== "..";
10
+ // What of a place's answer an agent reads; more is a narrower read away.
11
+ export const MAX_ANSWER_CHARS = 60_000;
12
+
13
+ const PARAMETER = /:([A-Za-z_][A-Za-z0-9_]*)|\{([^}]+)\}/g;
14
+
15
+ /** The request for `action` with `values` ({ method, url, body? }), or { refused } with why it cannot be made. */
16
+ export function buildRequest(origin, action, values) {
17
+ const named = new Set(action.inputs.map((input) => input.name));
18
+ let missing = null;
19
+ let bad = null;
20
+ const used = new Set();
21
+ const path = action.path.replace(PARAMETER, (_, colon, brace) => {
22
+ const name = colon ?? brace;
23
+ used.add(name);
24
+ const value = values[name];
25
+ if (value === undefined || value === null || value === "") {
26
+ missing = name;
27
+ return "";
28
+ }
29
+ const text = String(value);
30
+ if (!plainSegment(text)) bad = name;
31
+ return encodeURIComponent(text);
32
+ });
33
+ if (missing) return { refused: `${action.path} needs ${missing}.` };
34
+ if (bad) return { refused: `${bad} must be a plain id.` };
35
+ for (const input of action.inputs)
36
+ if (
37
+ input.required &&
38
+ input.in !== "path" &&
39
+ values[input.name] === undefined
40
+ )
41
+ return {
42
+ refused: `${action.method} ${action.path} needs ${input.name}.`,
43
+ };
44
+ const unknown = Object.keys(values).filter(
45
+ (name) => !used.has(name) && named.size > 0 && !named.has(name)
46
+ );
47
+ if (unknown.length)
48
+ return {
49
+ refused: `${action.method} ${action.path} does not take ${unknown.join(", ")}.`,
50
+ };
51
+
52
+ const url = new URL(path, origin);
53
+ const body = {};
54
+ for (const [name, value] of Object.entries(values)) {
55
+ if (used.has(name) || value === undefined) continue;
56
+ const input = action.inputs.find((one) => one.name === name);
57
+ const inQuery = input
58
+ ? input.in === "query"
59
+ : action.method === "GET" || action.method === "DELETE";
60
+ if (inQuery) url.searchParams.set(name, String(value));
61
+ else body[name] = value;
62
+ }
63
+ if (url.origin !== origin)
64
+ return { refused: "That request would leave the place." };
65
+ return {
66
+ method: action.method,
67
+ url: url.toString(),
68
+ ...(Object.keys(body).length ? { body: JSON.stringify(body) } : {}),
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Sends a built request with the place's key header ([name, value]), if it has one. No deadline of its own: a place's
74
+ * reads and writes have not been measured, so none is invented (AGENTS.md); the caller can cancel through `signal`.
75
+ */
76
+ export async function sendRequest(built, header, fetchImpl, signal) {
77
+ const response = await fetchImpl(built.url, {
78
+ method: built.method,
79
+ redirect: "manual",
80
+ signal,
81
+ headers: {
82
+ accept: "application/json",
83
+ ...(built.body ? { "content-type": "application/json" } : {}),
84
+ ...(header ? { [header[0]]: header[1] } : {}),
85
+ },
86
+ body: built.body,
87
+ });
88
+ const text = await response.text();
89
+ return {
90
+ status: response.status,
91
+ text:
92
+ text.length > MAX_ANSWER_CHARS
93
+ ? `${text.slice(0, MAX_ANSWER_CHARS)}\n[the answer continues for ${text.length - MAX_ANSWER_CHARS} more characters; ask for a narrower read]`
94
+ : text,
95
+ };
96
+ }
97
+
98
+ // The names a place gives the key it issues at registration.
99
+ const KEY_FIELD =
100
+ /^(secret|api_?key|apikey|token|access_?token|bearer|key|password|credential)s?$/i;
101
+ const MASK = "[kept by Harness]";
102
+
103
+ /**
104
+ * The key a registration answer carries, and the answer with every key-looking value masked, so no agent or record
105
+ * ever holds it. The first by the place's own field name wins: `secret`, then `api_key`, then the rest.
106
+ */
107
+ export function takeIssuedKey(text) {
108
+ let parsed;
109
+ try {
110
+ parsed = JSON.parse(text);
111
+ } catch {
112
+ return { key: null, masked: text };
113
+ }
114
+ const found = [];
115
+ const walk = (value, depth) => {
116
+ if (depth > 3 || !value || typeof value !== "object") return value;
117
+ if (Array.isArray(value)) return value.map((one) => walk(one, depth + 1));
118
+ return Object.fromEntries(
119
+ Object.entries(value).map(([name, one]) => {
120
+ if (
121
+ typeof one === "string" &&
122
+ one.length >= 16 &&
123
+ KEY_FIELD.test(name)
124
+ ) {
125
+ found.push({ name: name.toLowerCase(), value: one });
126
+ return [name, MASK];
127
+ }
128
+ return [name, walk(one, depth + 1)];
129
+ })
130
+ );
131
+ };
132
+ const masked = JSON.stringify(walk(parsed, 0));
133
+ const order = (name) =>
134
+ name.startsWith("secret") ? 0 : name.startsWith("api") ? 1 : 2;
135
+ const key = found.sort((a, b) => order(a.name) - order(b.name))[0]?.value;
136
+ return { key: key ?? null, masked };
137
+ }
138
+
139
+ /** The place's own links in an answer: where it asks the person to go next (a claim page). */
140
+ export function linksIn(text, origin) {
141
+ return [
142
+ ...new Set(
143
+ (text.match(/https:\/\/[^\s"'<>)\]]+/g) ?? []).filter((link) => {
144
+ try {
145
+ return new URL(link).origin === origin;
146
+ } catch {
147
+ return false;
148
+ }
149
+ })
150
+ ),
151
+ ].slice(0, 3);
152
+ }