@yaks/browse 0.0.0-stage → 0.2.36

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 (271) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +324 -2
  3. package/_dist/app.d.ts +8 -0
  4. package/_dist/app.d.ts.map +1 -0
  5. package/_dist/cli.d.ts +16 -0
  6. package/_dist/cli.d.ts.map +1 -0
  7. package/_dist/hosting.d.ts +24 -0
  8. package/_dist/hosting.d.ts.map +1 -0
  9. package/_dist/mod.d.ts +7 -0
  10. package/_dist/mod.d.ts.map +1 -0
  11. package/_dist/types.d.ts +5 -0
  12. package/_dist/types.d.ts.map +1 -0
  13. package/_dist/url.d.ts +2 -0
  14. package/_dist/url.d.ts.map +1 -0
  15. package/app.js +10 -0
  16. package/app.js.map +1 -0
  17. package/app.ts +10 -0
  18. package/browser-links.js +22 -0
  19. package/browser-links.js.map +1 -0
  20. package/browser-links.ts +28 -0
  21. package/cli.js +172 -0
  22. package/cli.js.map +1 -0
  23. package/cli.ts +168 -0
  24. package/client.js +748 -0
  25. package/client.js.map +1 -0
  26. package/client.ts +734 -0
  27. package/clipboard.js +18 -0
  28. package/clipboard.js.map +1 -0
  29. package/clipboard.ts +17 -0
  30. package/commands.js +1157 -0
  31. package/commands.js.map +1 -0
  32. package/commands.ts +1108 -0
  33. package/components/Ansi.tsx +160 -0
  34. package/components/App.tsx +446 -0
  35. package/components/Canvas.tsx +625 -0
  36. package/components/Card.tsx +276 -0
  37. package/components/Chat.tsx +205 -0
  38. package/components/Configuration.tsx +218 -0
  39. package/components/Decision.tsx +49 -0
  40. package/components/Dot.tsx +52 -0
  41. package/components/Entity.tsx +609 -0
  42. package/components/Fault.tsx +43 -0
  43. package/components/Filter.tsx +103 -0
  44. package/components/Keybindings.tsx +100 -0
  45. package/components/Keys.tsx +67 -0
  46. package/components/Markdown.tsx +90 -0
  47. package/components/Navigation.tsx +161 -0
  48. package/components/New.tsx +490 -0
  49. package/components/Peek.tsx +168 -0
  50. package/components/Prio.tsx +20 -0
  51. package/components/Run.tsx +263 -0
  52. package/components/Search.tsx +280 -0
  53. package/components/Stamp.tsx +44 -0
  54. package/components/Status.tsx +514 -0
  55. package/components/Sync.tsx +173 -0
  56. package/components/Tile.tsx +50 -0
  57. package/components/answered.js +23 -0
  58. package/components/answered.js.map +1 -0
  59. package/components/answered.ts +25 -0
  60. package/components/comp.js +11 -0
  61. package/components/comp.js.map +1 -0
  62. package/components/comp.ts +10 -0
  63. package/components/drag.js +173 -0
  64. package/components/drag.js.map +1 -0
  65. package/components/drag.ts +198 -0
  66. package/components/fields.tsx +90 -0
  67. package/components/fixtures/README.md +10 -0
  68. package/components/fixtures/archetypes.json +3646 -0
  69. package/components/hits.js +63 -0
  70. package/components/hits.js.map +1 -0
  71. package/components/hits.ts +84 -0
  72. package/components/icons.tsx +177 -0
  73. package/components/inspect.tsx +331 -0
  74. package/components/mount.ts +79 -0
  75. package/components/nav.tsx +479 -0
  76. package/components/offers.js +26 -0
  77. package/components/offers.js.map +1 -0
  78. package/components/offers.ts +54 -0
  79. package/components/page.js +21 -0
  80. package/components/page.js.map +1 -0
  81. package/components/page.ts +18 -0
  82. package/components/read.js +5 -0
  83. package/components/read.js.map +1 -0
  84. package/components/read.ts +7 -0
  85. package/components/registry.js +285 -0
  86. package/components/registry.js.map +1 -0
  87. package/components/registry.ts +317 -0
  88. package/components/session_status.tsx +115 -0
  89. package/components/subscriptions.js +149 -0
  90. package/components/subscriptions.js.map +1 -0
  91. package/components/subscriptions.ts +161 -0
  92. package/components/title.tsx +21 -0
  93. package/components/useQuery.js +166 -0
  94. package/components/useQuery.js.map +1 -0
  95. package/components/useQuery.ts +211 -0
  96. package/components/views/Board.tsx +450 -0
  97. package/components/views/BoardTile.tsx +65 -0
  98. package/components/views/Dashboard.tsx +148 -0
  99. package/components/views/Debug.tsx +445 -0
  100. package/components/views/Dependency.tsx +51 -0
  101. package/components/views/Entry.tsx +500 -0
  102. package/components/views/Gist.tsx +28 -0
  103. package/components/views/Inline.tsx +54 -0
  104. package/components/views/Json.tsx +19 -0
  105. package/components/views/Layout.tsx +211 -0
  106. package/components/views/List.tsx +238 -0
  107. package/components/views/Md.tsx +43 -0
  108. package/components/views/Media.tsx +48 -0
  109. package/components/views/Memory.tsx +32 -0
  110. package/components/views/Relate.tsx +205 -0
  111. package/components/views/Search.tsx +42 -0
  112. package/components/views/Session.tsx +850 -0
  113. package/components/views/SessionManage.tsx +127 -0
  114. package/components/views/Show.tsx +758 -0
  115. package/components/views/Shown.tsx +72 -0
  116. package/components/views/Split.tsx +58 -0
  117. package/components/views/TaskTile.tsx +37 -0
  118. package/components/views/Title.tsx +105 -0
  119. package/components/views/Wake.tsx +77 -0
  120. package/components/views/Web.tsx +49 -0
  121. package/components/wells.js +30 -0
  122. package/components/wells.js.map +1 -0
  123. package/components/wells.ts +33 -0
  124. package/configuration.js +38 -0
  125. package/configuration.js.map +1 -0
  126. package/configuration.ts +41 -0
  127. package/decision_sync.js +88 -0
  128. package/decision_sync.js.map +1 -0
  129. package/decision_sync.ts +93 -0
  130. package/deno.json +1 -0
  131. package/domain-host.tsx +108 -0
  132. package/edge.js +193 -0
  133. package/edge.js.map +1 -0
  134. package/edge.ts +196 -0
  135. package/entry_log.js +241 -0
  136. package/entry_log.js.map +1 -0
  137. package/entry_log.ts +214 -0
  138. package/failure.js +22 -0
  139. package/failure.js.map +1 -0
  140. package/failure.ts +34 -0
  141. package/front.json +61 -0
  142. package/highlight.js +143 -0
  143. package/highlight.js.map +1 -0
  144. package/highlight.ts +149 -0
  145. package/history.js +68 -0
  146. package/history.js.map +1 -0
  147. package/history.ts +72 -0
  148. package/host_commands.js +107 -0
  149. package/host_commands.js.map +1 -0
  150. package/host_commands.ts +38 -0
  151. package/hosting.js +53 -0
  152. package/hosting.js.map +1 -0
  153. package/hosting.ts +72 -0
  154. package/idb.js +14 -0
  155. package/idb.js.map +1 -0
  156. package/idb.ts +15 -0
  157. package/index.js +232 -0
  158. package/index.js.map +1 -0
  159. package/index.ts +252 -0
  160. package/keybindings.js +136 -0
  161. package/keybindings.js.map +1 -0
  162. package/keybindings.ts +37 -0
  163. package/kit.js +103 -0
  164. package/kit.js.map +1 -0
  165. package/kit.ts +119 -0
  166. package/layout.js +254 -0
  167. package/layout.js.map +1 -0
  168. package/layout.ts +210 -0
  169. package/legacy_outbox.js +53 -0
  170. package/legacy_outbox.js.map +1 -0
  171. package/legacy_outbox.ts +63 -0
  172. package/live.js +2883 -0
  173. package/live.js.map +1 -0
  174. package/live.ts +3334 -0
  175. package/live_archetypes.js +92 -0
  176. package/live_archetypes.js.map +1 -0
  177. package/live_archetypes.ts +113 -0
  178. package/live_client.js +145 -0
  179. package/live_client.js.map +1 -0
  180. package/live_client.ts +120 -0
  181. package/main.tsx +5 -0
  182. package/mod.js +7 -0
  183. package/mod.js.map +1 -0
  184. package/mod.ts +7 -0
  185. package/mount.tsx +50 -0
  186. package/navigation.js +120 -0
  187. package/navigation.js.map +1 -0
  188. package/navigation.ts +152 -0
  189. package/near.js +83 -0
  190. package/near.js.map +1 -0
  191. package/near.ts +83 -0
  192. package/new.js +295 -0
  193. package/new.js.map +1 -0
  194. package/new.ts +361 -0
  195. package/outbox.js +112 -0
  196. package/outbox.js.map +1 -0
  197. package/outbox.ts +129 -0
  198. package/owner.js +39 -0
  199. package/owner.js.map +1 -0
  200. package/owner.ts +37 -0
  201. package/package.json +81 -4
  202. package/paste.js +157 -0
  203. package/paste.js.map +1 -0
  204. package/paste.ts +122 -0
  205. package/props.js +303 -0
  206. package/props.js.map +1 -0
  207. package/props.ts +358 -0
  208. package/providers.js +136 -0
  209. package/providers.js.map +1 -0
  210. package/providers.ts +194 -0
  211. package/query.js +987 -0
  212. package/query.js.map +1 -0
  213. package/query.ts +1113 -0
  214. package/remote.js +37 -0
  215. package/remote.js.map +1 -0
  216. package/remote.ts +46 -0
  217. package/resolver.js +149 -0
  218. package/resolver.js.map +1 -0
  219. package/resolver.ts +213 -0
  220. package/rfc2047.js +37 -0
  221. package/rfc2047.js.map +1 -0
  222. package/rfc2047.ts +40 -0
  223. package/row_holds.js +107 -0
  224. package/row_holds.js.map +1 -0
  225. package/row_holds.ts +93 -0
  226. package/served.ts +42 -0
  227. package/session_worktree.js +7 -0
  228. package/session_worktree.js.map +1 -0
  229. package/session_worktree.ts +16 -0
  230. package/sessions.js +57 -0
  231. package/sessions.js.map +1 -0
  232. package/sessions.ts +53 -0
  233. package/sha.js +161 -0
  234. package/sha.js.map +1 -0
  235. package/sha.ts +164 -0
  236. package/styles.css +2823 -0
  237. package/subs.js +36 -0
  238. package/subs.js.map +1 -0
  239. package/subs.ts +40 -0
  240. package/terminal-route.js +13 -0
  241. package/terminal-route.js.map +1 -0
  242. package/terminal-route.ts +17 -0
  243. package/terminal.js +251 -0
  244. package/terminal.js.map +1 -0
  245. package/terminal.ts +186 -0
  246. package/time.js +142 -0
  247. package/time.js.map +1 -0
  248. package/time.ts +133 -0
  249. package/title.js +25 -0
  250. package/title.js.map +1 -0
  251. package/title.ts +50 -0
  252. package/tui/doc.ts +6 -0
  253. package/tui/testing.ts +19 -0
  254. package/twin.js +11 -0
  255. package/twin.js.map +1 -0
  256. package/twin.ts +13 -0
  257. package/types.js +456 -0
  258. package/types.js.map +1 -0
  259. package/types.ts +1370 -0
  260. package/url.js +77 -0
  261. package/url.js.map +1 -0
  262. package/url.ts +85 -0
  263. package/verb.js +82 -0
  264. package/verb.js.map +1 -0
  265. package/verb.ts +137 -0
  266. package/warmth.js +41 -0
  267. package/warmth.js.map +1 -0
  268. package/warmth.ts +54 -0
  269. package/wire.js +86 -0
  270. package/wire.js.map +1 -0
  271. package/wire.ts +63 -0
package/client.js ADDED
@@ -0,0 +1,748 @@
1
+ // The headless client half — what the CLI and the MCP server share. Talks
2
+ // to a running tasks server over HTTP (/query to read, /apply
3
+ // to write; writes broadcast to every live client), assembles entities
4
+ // the same way live.ts does, and owns the dot-param grammar:
5
+ // `.doc.title=Hello` sets doc.title; a property is always named with its
6
+ // component. Values that look like numbers become numbers.
7
+ import { IdError } from "./types.js";
8
+ import { answering, parse } from "@yaks/id";
9
+ import { identityEid } from "@yaks/graph/identity";
10
+ import { ownsSessionBranch } from "./session_worktree.js";
11
+ import { byName, comps, deaths, kindOf, shapeOf, stamped, statusOf, uuid, vocab } from "./types.js";
12
+ import { aliasOf, idOf, shortHex } from "./types.js";
13
+ import { fieldOp, parseProp, propAt, refOf } from "./props.js";
14
+ import { nearest, offer } from "./near.js";
15
+ import { catalog, spawnDefault } from "./providers.js";
16
+ export { idOf };
17
+ // Task status is DERIVED (D-24102): read it off the comps a row carries. A
18
+ // non-task row has no task comp, so this stays undefined the way `.task?.status`
19
+ // did — every caller that guarded on truthiness keeps its meaning.
20
+ export let taskStatus = (r)=>r.comps.task ? statusOf(r.comps) : undefined;
21
+ // The changes a UI picker sends to set a task to a chosen DERIVED status
22
+ // (D-24102): each move retracts conflicting facets before minting its own, so
23
+ // cancelled→done and done→wip are real transitions rather than precedence
24
+ // accidents. A session's wip is its live claim; anyone else's is the `started`
25
+ // mark. Open retracts both.
26
+ export let statusChanges = (eid, status, session)=>status == 'done' ? [
27
+ {
28
+ eid,
29
+ name: 'cancelled',
30
+ comp: null
31
+ },
32
+ {
33
+ eid,
34
+ name: 'completed',
35
+ comp: {}
36
+ }
37
+ ] : status == 'cancelled' ? [
38
+ {
39
+ eid,
40
+ name: 'completed',
41
+ comp: null
42
+ },
43
+ {
44
+ eid,
45
+ name: 'cancelled',
46
+ comp: {}
47
+ }
48
+ ] : status == 'wip' ? [
49
+ {
50
+ eid,
51
+ name: 'completed',
52
+ comp: null
53
+ },
54
+ {
55
+ eid,
56
+ name: 'cancelled',
57
+ comp: null
58
+ },
59
+ session ? {
60
+ eid,
61
+ name: 'claim',
62
+ comp: {
63
+ session
64
+ }
65
+ } : {
66
+ eid,
67
+ name: 'started',
68
+ comp: {}
69
+ }
70
+ ] : [
71
+ {
72
+ eid,
73
+ name: 'completed',
74
+ comp: null
75
+ },
76
+ {
77
+ eid,
78
+ name: 'cancelled',
79
+ comp: null
80
+ },
81
+ {
82
+ eid,
83
+ name: 'started',
84
+ comp: null
85
+ },
86
+ {
87
+ eid,
88
+ name: 'claim',
89
+ comp: null
90
+ }
91
+ ];
92
+ export let rowOf = (r)=>{
93
+ let { kind, ...comps } = r;
94
+ let entity = comps.entity;
95
+ return {
96
+ eid: String(entity.eid),
97
+ num: Number(entity.num ?? 0),
98
+ ...entity.prefix ? {
99
+ prefix: String(entity.prefix)
100
+ } : {},
101
+ kind: kind ? String(kind) : kindOf(comps),
102
+ comps: comps
103
+ };
104
+ };
105
+ // The graph as rows: one per entity, components merged in; kind derived.
106
+ // Quarantine is absent unless the caller takes the explicit reveal branch.
107
+ export let rows = ({ changes }, quarantined = false)=>{
108
+ let out = new Map();
109
+ for (let { eid, name, comp } of changes){
110
+ if (!comp) continue;
111
+ let row = out.get(eid);
112
+ if (!row) {
113
+ row = {
114
+ eid,
115
+ num: 0,
116
+ kind: 'entity',
117
+ comps: {}
118
+ };
119
+ out.set(eid, row);
120
+ }
121
+ if (name == 'entity') {
122
+ if ('num' in comp) row.num = Number(comp.num ?? 0);
123
+ if (comp.prefix) row.prefix = String(comp.prefix);
124
+ // A presence transition echoes only the derived archetype pointer.
125
+ // Keep the identity stamped earlier in the same batch.
126
+ row.comps.entity = {
127
+ ...row.comps.entity,
128
+ ...comp
129
+ };
130
+ } else row.comps[name] = comp;
131
+ }
132
+ for (let r of out.values())r.kind = kindOf(r.comps);
133
+ let rows = [
134
+ ...out.values()
135
+ ];
136
+ return quarantined ? rows : rows.filter((r)=>!r.comps.quarantined);
137
+ };
138
+ // One row per eid, oldest first — a snapshot walks the entity table in num
139
+ // order, so a set stitched from several queries answers in that same order.
140
+ export let uniq = (all)=>[
141
+ ...new Map(all.map((r)=>[
142
+ r.eid,
143
+ r
144
+ ])).values()
145
+ ].sort((a, b)=>a.num - b.num);
146
+ // A search by meaning (`.near`) ranks each row it answers (`rank.score`).
147
+ export let hitOf = (r)=>({
148
+ eid: r.eid,
149
+ num: r.num,
150
+ kind: r.kind,
151
+ title: String(r.comps.doc?.title ?? ''),
152
+ score: Number(r.comps.rank?.score ?? 0)
153
+ });
154
+ // '.doc.title=Hello' → {comp, prop, value}; null if the argument isn't a
155
+ // dot-param at all (a bare word). A property is named with its component, as
156
+ // in a query: '.filed.assignee=jeff' patches filed.assignee and derefParams
157
+ // turns the value into an eid at the door. A name alone is a component, and a
158
+ // property named alone is refused with the forms that name it (@yaks/vocab
159
+ // `aim`).
160
+ // A hyphen is admitted into the NAME so a hyphenated spelling reaches
161
+ // aim() and earns the same `unknown prop` error as any other unknown.
162
+ // No column is hyphenated, so nothing new routes — but before this, a
163
+ // name the pattern rejected returned null, and cli.ts's split() files
164
+ // every non-param token under `words`: `.blocked-by=T-1` became part of
165
+ // a task's TITLE. Silence, not an edge and not an error.
166
+ // `read` is the door's value convention (inflate, where there's a filesystem)
167
+ // and it runs HERE, before the value is READ: `.doc.body=@edit.json` routes a
168
+ // $edit operator exactly as `--body=@edit.json` does. Applied after param()
169
+ // it only ever saw an already-parsed value, so the file's text landed as prose.
170
+ export let param = (arg, read = (p)=>p)=>{
171
+ let m = arg.match(/^\.([A-Za-z_-]+)(?:\.([A-Za-z_-]+))?=(.*)$/s);
172
+ if (!m) return null;
173
+ let [, a, b, raw] = m;
174
+ let p;
175
+ if (b) {
176
+ if (!(b in (comps[a] ?? {}))) {
177
+ // The same teaching the query door gives: a refusal names the
178
+ // component's columns and their types.
179
+ throw new Error(`no such prop: .${a}.${b}${comps[a] ? ` — ${shapeOf(a, Object.keys(comps[a]), (col)=>comps[a][col])}` : ''}`);
180
+ }
181
+ p = {
182
+ comp: a,
183
+ prop: b,
184
+ value: raw
185
+ };
186
+ } else {
187
+ p = {
188
+ ...vocab.aim(a)[0],
189
+ value: raw
190
+ };
191
+ }
192
+ if (!p.prop) {
193
+ // A component name is a presence mark, not a column. Column-bearing marks
194
+ // keep their explicit write spelling; stamped-only marks stay protected.
195
+ // A genuinely empty writable component speaks Boolean presence so the
196
+ // same dot-param compiler can add ({}) or remove (null) it at every door.
197
+ let cols = Object.keys(comps[p.comp] ?? {});
198
+ if (cols.length) {
199
+ throw new Error(`.${p.comp} is a mark — write it as .${p.comp}.${cols[0]}=<value> (e.g. .${p.comp}.${cols[0]}=now)`);
200
+ }
201
+ if (Object.keys(stamped[p.comp] ?? {}).length) {
202
+ throw new Error(`.${p.comp} is a server-stamped mark; it isn't set through a dot-param`);
203
+ }
204
+ let present = parseProp({
205
+ comp: p.comp,
206
+ prop: '',
207
+ name: p.comp,
208
+ type: 'bool'
209
+ }, raw);
210
+ return {
211
+ ...p,
212
+ value: !!present
213
+ };
214
+ }
215
+ // The @file / @- doors first: what the door reads is what gets read below.
216
+ let val = String(read({
217
+ ...p,
218
+ value: raw
219
+ }).value);
220
+ // A `$`-sigil object value is a field OPERATOR, not a literal — the same
221
+ // value graph_apply takes as a comp value, so the update doors speak the one
222
+ // operator too. It rides through untouched (no scalar parse, no deref) for
223
+ // apply() to resolve against the CURRENT stored value; apply() also owns
224
+ // every refusal — an unknown `$op`, a non-text column, a hunk that misses.
225
+ let op = fieldOp(val);
226
+ if (op) return {
227
+ ...p,
228
+ value: op
229
+ };
230
+ let declared = propAt(p.comp, p.prop);
231
+ p.value = typeof declared.type == 'object' && 'eid' in declared.type ? val : parseProp(declared, val);
232
+ return p;
233
+ };
234
+ // Reference values at a door: uuids pass through, '' clears, anything
235
+ // else must resolve — an alias (jeff), a human id (T-3), a bare num — or
236
+ // the door throws, never a silent FK failure later. One resolver for
237
+ // every write door (CLI, MCP task_new/update/command, graph_apply).
238
+ export let UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
239
+ // The near match, offered only once the handle it prints RESOLVES here —
240
+ // find() is the same reading of "what names an entity" the caller just
241
+ // failed, so a suggestion can never route somewhere the retry won't.
242
+ // `comp` narrows to the reference's declared target, so a bad
243
+ // `.filed.project=` is only ever answered with a project.
244
+ //
245
+ // A title is MATCHED only for the kinds it names (types.ts byName), though
246
+ // every title still shows. Untargeted, the pool is the whole graph and a
247
+ // common word opens somebody's ticket every time — `tasks` reached T-801
248
+ // ("Tasks: add cancelled state…") ahead of the project called Task Graph.
249
+ // An alias always rides: it is a typed handle whatever wears it.
250
+ export let nearby = (all)=>(v, comp = '')=>{
251
+ let names = aliasNames(all);
252
+ let hit = nearest(v, all.filter((r)=>!comp || r.comps[comp]).map((r)=>({
253
+ eid: r.eid,
254
+ id: idOf(r),
255
+ alias: names.get(r.eid),
256
+ title: r.comps.doc?.title,
257
+ named: byName.has(r.kind)
258
+ })));
259
+ if (!hit) return;
260
+ return find(all, hit.alias ?? hit.id)?.eid == hit.eid ? offer(hit) : undefined;
261
+ };
262
+ // find(), where a miss is the door's error. One message for every lookup,
263
+ // so a mistyped handle teaches at whichever door heard it.
264
+ export let need = (all, id, where = '', comp = '')=>{
265
+ let hit = find(all, id);
266
+ if (hit) return hit;
267
+ let near = nearby(all)(id, comp);
268
+ throw new Error(`no entity: ${id}${where}${near ? ` — did you mean ${near}?` : ''}`);
269
+ };
270
+ // The collateral of a delete: the entities the host tombstones ALONGSIDE
271
+ // the target, because they exist ABOUT it — comments aimed at it, cards and
272
+ // knocks/wakes viewing it — walked transitively down the same
273
+ // `deaths('cascade')` worklist the reaper uses, so a delete guard names
274
+ // exactly what the wire would take. The target itself is never in the list:
275
+ // it's the thing you asked to delete; this is what rides along.
276
+ //
277
+ // Two doors read this: a PURE pass over rows already in hand (the palette
278
+ // verb, which is wire-free), and an async pass that QUERIES the live graph
279
+ // (the CLI, whose reader diet is bounded and so can't see every comment on an
280
+ // arbitrary target). Same closure, two sources.
281
+ export let cascade = (all, eid)=>{
282
+ let aimed = deaths('cascade');
283
+ let doomed = [
284
+ eid
285
+ ];
286
+ for(let i = 0; i < doomed.length; i++){
287
+ for (let [comp, col] of aimed){
288
+ for (let r of all){
289
+ if (r.comps[comp]?.[col] == doomed[i] && !doomed.includes(r.eid)) {
290
+ doomed.push(r.eid);
291
+ }
292
+ }
293
+ }
294
+ }
295
+ return doomed.slice(1).flatMap((d)=>all.find((r)=>r.eid == d) ?? []);
296
+ };
297
+ export let deref = (all, v, where = '', comp = '')=>!v || UUID.test(v) ? v : need(all, v, where, comp).eid;
298
+ // Deref a change batch through a resolver — one core, two sources. `resolve`
299
+ // turns a human id (or an eid) into the eid it names, throwing the door's
300
+ // error on a miss; a uuid/empty passes through untouched (its callers own that
301
+ // short-circuit). rows-backed derefChanges reads a materialized Row[]; the
302
+ // db-backed command executor hands a resolver keyed off the live graph, so a
303
+ // verb's output resolves its refs without a whole-graph corpus (M-21143).
304
+ export let derefWith = (resolve, changes)=>changes.map((c)=>({
305
+ ...c,
306
+ eid: resolve(c.eid, ' (eid)'),
307
+ comp: c.comp == null ? c.comp : Object.fromEntries(Object.entries(c.comp).map(([prop, value])=>{
308
+ let target = refOf(c.name, prop);
309
+ return [
310
+ prop,
311
+ target != null && (typeof value == 'string' || typeof value == 'number') ? resolve(String(value), ` (.${prop})`, target) : value
312
+ ];
313
+ }))
314
+ }));
315
+ export let derefChanges = (all, changes)=>derefWith((v, where, comp)=>deref(all, v, where, comp), changes);
316
+ // Group routed params into per-component patches.
317
+ export let patches = (params)=>{
318
+ let out = {};
319
+ for (let { comp, prop, value } of params){
320
+ if (!prop) {
321
+ out[comp] = value ? {} : null;
322
+ continue;
323
+ }
324
+ ;
325
+ (out[comp] ??= {})[prop] = value;
326
+ }
327
+ return out;
328
+ };
329
+ // A task, TYPED: 'P1 .filed.domain=Eng Build a thing\nnotes…' — the first line
330
+ // is setters + title, every later line is body. Dot-params parse
331
+ // anywhere in the line (their syntax can't be prose); the P1 shorthand
332
+ // only parses while it LEADS, so a title like 'Fix the P2 endpoint'
333
+ // keeps its words. One parser for every door that takes a typed task —
334
+ // the board's quick-add, :new, whatever comes next. A malformed
335
+ // dot-param stays a word rather than throwing: mid-typing is not an
336
+ // error, and Enter files what the preview showed. `read` is the door's
337
+ // value convention (inflate, where there's a filesystem) — it runs
338
+ // OUTSIDE the not-a-param catch, so a missing @file is an error and
339
+ // never a word swallowed into the title.
340
+ export let spec = (text, read = (p)=>p)=>{
341
+ let [line, ...rest] = text.split('\n');
342
+ let words = [];
343
+ let ps = [];
344
+ let leading = true;
345
+ for (let w of line.trim().split(/\s+/).filter(Boolean)){
346
+ let priority = leading && /^[Pp][+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(w);
347
+ if (priority) {
348
+ ps.push(param(`.filed.priority=${w}`));
349
+ continue;
350
+ }
351
+ if (w.startsWith('.')) {
352
+ let d = null;
353
+ try {
354
+ d = param(w);
355
+ } catch {}
356
+ // A param, so parse it again through the door's value convention —
357
+ // OUTSIDE the catch, so a missing @file is an error and never a word
358
+ // swallowed into the title.
359
+ if (d) {
360
+ ps.push(param(w, read));
361
+ continue;
362
+ }
363
+ }
364
+ leading = false;
365
+ words.push(w);
366
+ }
367
+ return {
368
+ title: words.join(' '),
369
+ body: rest.join('\n').trim(),
370
+ grouped: patches(ps)
371
+ };
372
+ };
373
+ // The standard task-create batch: a doc face, workflow state, then any
374
+ // other grouped components verbatim. Callers put title/body into
375
+ // grouped.doc first.
376
+ export let taskChanges = (eid, grouped, number = false)=>[
377
+ {
378
+ eid,
379
+ name: 'doc',
380
+ comp: {
381
+ body: '',
382
+ ...grouped.doc ?? {}
383
+ },
384
+ ...number ? {
385
+ $num: true
386
+ } : {}
387
+ },
388
+ // A new task is born open — no mark (D-24102). status is derived, not
389
+ // writable, so drop any that rode in on the spec (`.task.status=` on new).
390
+ {
391
+ eid,
392
+ name: 'task',
393
+ comp: (({ status: _drop, ...task })=>task)(grouped.task ?? {})
394
+ },
395
+ ...Object.entries(grouped).filter(([n])=>n != 'doc' && n != 'task').map(([name, comp])=>({
396
+ eid,
397
+ name,
398
+ comp
399
+ }))
400
+ ];
401
+ // Each entity's alias among these rows, from the alias keys that name it.
402
+ export let aliasNames = (all)=>new Map(all.flatMap((r)=>{
403
+ let a = aliasOf(r.comps);
404
+ return a ? [
405
+ [
406
+ a.eid,
407
+ a.name
408
+ ]
409
+ ] : [];
410
+ }));
411
+ // Resolve 'T-3' / a bare num / a full eid / a SHORT-eid handle / an alias to a
412
+ // row among these. A human id first, as @yaks/id's `answering` reads it, then
413
+ // exact eid, then a sigilled hex prefix, then an alias key's name. An id or a
414
+ // handle several rows answer to throws, naming them.
415
+ export let find = (all, id)=>{
416
+ let p = parse(id);
417
+ if (p) {
418
+ let held = answering(all.filter((r)=>r.num == p.num), p.prefix, (r)=>r);
419
+ if (held.length > 1) {
420
+ throw new IdError(`${id} is an ambiguous id — matches ${held.map((r)=>`${idOf(r)} (${r.eid})`).join(', ')}`);
421
+ }
422
+ return held[0];
423
+ }
424
+ let exact = all.find((r)=>r.eid == id.toLowerCase());
425
+ if (exact) return exact;
426
+ let hex = shortHex(id);
427
+ if (hex) {
428
+ let hits = all.filter((r)=>r.eid.replaceAll('-', '').startsWith(hex));
429
+ if (hits.length > 1) {
430
+ throw new IdError(`${id} is an ambiguous id — matches ${hits.map((r)=>`${idOf(r)} (${r.eid})`).join(', ')}; use more characters`);
431
+ }
432
+ return hits[0];
433
+ }
434
+ if (id.includes('#')) {
435
+ throw new IdError(`${id}: expected # followed by 6–64 hex characters`);
436
+ }
437
+ let named = all.map((r)=>aliasOf(r.comps)).find((a)=>a?.name == id);
438
+ return named && all.find((r)=>r.eid == named.eid);
439
+ };
440
+ // A spawn as @yaks/spawn writes it (packages/spawn/tools.ts session_spawn):
441
+ // the session, its first entry carrying the instruction and the `using` it
442
+ // runs on, and the claim on the task it works. A native session (@yaks/harness,
443
+ // as `yak session new` begins one) is marked so, with the persona it wears
444
+ // where it was sent to one and the topic it is opened on; the harness admits
445
+ // that persona's instructions and the topic's tree before its first turn
446
+ // (packages/harness/effects.ts). The host reads the
447
+ // entry and starts the run; anything it cannot honor shows on the session.
448
+ export let sessionFrames = (session, body, using, opening)=>{
449
+ let { operator, task, persona, topic, native } = opening;
450
+ let entry = uuid();
451
+ return [
452
+ {
453
+ eid: session,
454
+ name: 'session',
455
+ comp: {
456
+ operator,
457
+ ...persona ? {
458
+ persona
459
+ } : {},
460
+ ...topic ? {
461
+ topic
462
+ } : {}
463
+ }
464
+ },
465
+ ...native ? [
466
+ {
467
+ eid: session,
468
+ name: 'native',
469
+ comp: {}
470
+ }
471
+ ] : [],
472
+ {
473
+ eid: entry,
474
+ name: 'entry',
475
+ comp: {
476
+ session
477
+ }
478
+ },
479
+ {
480
+ eid: entry,
481
+ name: 'content',
482
+ comp: {
483
+ body
484
+ }
485
+ },
486
+ {
487
+ eid: entry,
488
+ name: 'using',
489
+ comp: using
490
+ },
491
+ ...task ? [
492
+ {
493
+ eid: task,
494
+ name: 'claim',
495
+ comp: {
496
+ session
497
+ }
498
+ }
499
+ ] : []
500
+ ];
501
+ };
502
+ // Find-or-mint the session entity for an external session id: its eid
503
+ // plus the change that creates or refreshes it. cwd is where it runs; pid
504
+ // is the provider process it runs IN (the SessionStart hook walks /proc for
505
+ // it) — liveness for every provider, and the anchor that lets Claude's
506
+ // channel follow a /clear rotation under the same process.
507
+ export let sessionFor = (all, session, cwd, pid, self)=>{
508
+ let s = all.find((r)=>r.comps.session && r.comps.session.id == session);
509
+ let eid = s?.eid ?? uuid();
510
+ let comp = s ? {} : {
511
+ id: session
512
+ };
513
+ // A swept branch is still ours to regrow. Hooks
514
+ // may refresh a provider pid, but never relocate a tree the server cut.
515
+ let tree = s?.comps.worktree;
516
+ let owned = s?.comps.session.origin == 'managed' && tree && ownsSessionBranch(s.eid, tree.branch, s.num);
517
+ if (cwd && !owned && s?.comps.session.cwd != cwd) comp.cwd = cwd;
518
+ if (pid && s?.comps.session.pid != pid) comp.pid = pid;
519
+ for (let k of [
520
+ 'agent_type',
521
+ 'source',
522
+ 'transcript',
523
+ 'turn'
524
+ ]){
525
+ if (self?.[k] && s?.comps.session[k] != self[k]) comp[k] = self[k];
526
+ }
527
+ if (self?.pane !== undefined && s?.comps.session.pane != self.pane) {
528
+ comp.pane = self.pane;
529
+ }
530
+ if (self?.operator != undefined && (s?.comps.session.operator == null || !!s.comps.session.operator != self.operator)) {
531
+ comp.operator = Number(self.operator);
532
+ }
533
+ // A tool-only session has no cwd to place it. Its first task interaction
534
+ // anchors it to that venture; an identity it already wears always wins.
535
+ if (self?.actor && !s?.comps.session.actor) {
536
+ comp.actor = self.actor;
537
+ }
538
+ // Who spawned this run — set once, at birth: lineage is history, not a
539
+ // field a later reify should relabel.
540
+ if (self?.parent && !s?.comps.session.parent) {
541
+ comp.parent = self.parent;
542
+ }
543
+ let changes = Object.keys(comp).length ? [
544
+ {
545
+ eid,
546
+ name: 'session',
547
+ comp
548
+ }
549
+ ] : [];
550
+ return {
551
+ eid,
552
+ changes
553
+ };
554
+ };
555
+ let taskActor = (all, target)=>String(all.find((r)=>r.eid == target)?.comps.filed?.project ?? '') || undefined;
556
+ // The claim pointing at a session entity — one batch, atomic on the server.
557
+ // Set or clear this actor's standing instruction about one entity. A
558
+ // subscription needs its own entity because MANY actors subscribe to one
559
+ // target — unlike a claim, which is a comp on the task itself. Reusing
560
+ // the existing row's eid is what makes saying it twice idempotent, and
561
+ // what makes watch→mute a change of mind rather than a second opinion.
562
+ export let subChanges = (all, actor, target, mode)=>{
563
+ let had = all.find((r)=>r.comps.subscription && String(r.comps.subscription.actor) == actor && String(r.comps.subscription.target) == target);
564
+ if (!mode) {
565
+ return had ? [
566
+ {
567
+ eid: had.eid,
568
+ name: 'subscription',
569
+ comp: {
570
+ mode: null
571
+ }
572
+ }
573
+ ] : [];
574
+ }
575
+ return [
576
+ {
577
+ eid: had?.eid ?? uuid(),
578
+ name: 'subscription',
579
+ comp: {
580
+ actor: actor,
581
+ target: target,
582
+ mode
583
+ }
584
+ }
585
+ ];
586
+ };
587
+ // THE precedence every spawn door shares, so the browser and the TUI never
588
+ // resolve a launch differently: the explicit ask (a :fix dot-param, the Run
589
+ // form), then the provider table's own default, model→provider inference and
590
+ // readiness both. An explicit model without a provider leaves the transport
591
+ // to readiness. Effort falls to the chosen model's own default, then medium
592
+ // when the model has the axis at all.
593
+ export let spawnPlan = (ps, ask = {}, blocked)=>{
594
+ let d = spawnDefault(ps, ask, blocked);
595
+ let provider = ask.provider ?? d.provider;
596
+ let model = ask.model ?? d.model;
597
+ let axis = catalog(ps).find((p)=>p.model == model)?.efforts ?? [];
598
+ return {
599
+ provider,
600
+ model,
601
+ effort: ask.effort ?? (model ? ps.find((p)=>p.name == provider)?.defaults?.[model] : undefined) ?? (axis.length ? axis.includes('medium') ? 'medium' : axis[0] : undefined)
602
+ };
603
+ };
604
+ // A comment: a doc aimed at the target. The session reification lets the
605
+ // server stamp its instrument; `event` marks machinery speaking (M-4062)
606
+ // so the mail relay skips it. A verdict adds review judgment to the same
607
+ // entity — rationale, aim, and authorship stay the comment's.
608
+ export let commentChanges = (all, target, body, session, mark = {})=>{
609
+ let s = session ? sessionFor(all, session, undefined, undefined, {
610
+ actor: taskActor(all, target)
611
+ }) : undefined;
612
+ let eid = uuid();
613
+ return [
614
+ ...s?.changes ?? [],
615
+ {
616
+ eid,
617
+ name: 'doc',
618
+ comp: {
619
+ title: '',
620
+ body
621
+ }
622
+ },
623
+ {
624
+ eid,
625
+ name: 'comment',
626
+ comp: {
627
+ target: target
628
+ }
629
+ },
630
+ ...mark.verdict == null ? [] : [
631
+ {
632
+ eid,
633
+ name: 'review',
634
+ comp: {
635
+ verdict: mark.verdict
636
+ }
637
+ }
638
+ ]
639
+ ];
640
+ };
641
+ // A commit message's first line — what a compact row shows of it.
642
+ export let subject = (message)=>String(message ?? '').split('\n')[0];
643
+ // The send batch: a mail is a document that travels — subject rides
644
+ // doc.title, the body doc.body, and WHERE it goes the shared `deliver {to}`.
645
+ // `to` stays AS GIVEN (a raw address or a graph reference) — a graph
646
+ // reference resolves at the door, a raw @-address is find-or-minted into its
647
+ // address-book entity there, never here.
648
+ export let mailChanges = (m)=>{
649
+ let eid = uuid();
650
+ let changes = [
651
+ {
652
+ eid,
653
+ name: 'doc',
654
+ comp: {
655
+ title: m.subject,
656
+ body: m.body ?? ''
657
+ }
658
+ },
659
+ {
660
+ eid,
661
+ name: 'deliver',
662
+ comp: {
663
+ to: m.to
664
+ }
665
+ },
666
+ {
667
+ eid,
668
+ name: 'mail',
669
+ comp: m.replyTo ? {
670
+ reply_to: m.replyTo
671
+ } : {}
672
+ }
673
+ ];
674
+ return {
675
+ eid,
676
+ changes
677
+ };
678
+ };
679
+ // The mail tool owns addressing, threading and the caller's attention. The
680
+ // command submits its words through that boundary so every door answers the
681
+ // same way, with the runner supplying the caller's identity.
682
+ export let replyChanges = (row, body)=>{
683
+ let eid = uuid();
684
+ let changes = [
685
+ {
686
+ eid,
687
+ name: 'call',
688
+ comp: {
689
+ to: identityEid('tool', [
690
+ 'mail_reply'
691
+ ]),
692
+ args: {
693
+ letter: row.eid,
694
+ body
695
+ }
696
+ }
697
+ }
698
+ ];
699
+ return {
700
+ eid,
701
+ changes
702
+ };
703
+ };
704
+ // The dream batch (T-12800): a venture's consolidation cursor plus the first
705
+ // cadence wake that starts it. `scope` is the project the dream combs; `floor`
706
+ // starts a week back so the first run has a window. The wake is UNTARGETED
707
+ // (deliver.to = the dream), so replaceWakes keeps one cadence clock and the
708
+ // server arms it on apply; its knock hooks dreamComb, which re-arms
709
+ // the next at each run's end. One dream per venture — a second on the same
710
+ // project is refused, so `task dream` is safe to run twice.
711
+ export let dreamChanges = (all, d)=>{
712
+ let project = find(all, d.project);
713
+ if (!project?.comps.project) throw new Error(`not a project: ${d.project}`);
714
+ let had = all.find((r)=>r.comps.dream?.scope == project.eid);
715
+ if (had) throw new Error(`${idOf(had)} already dreams ${idOf(project)}`);
716
+ let eid = uuid();
717
+ let w = uuid();
718
+ let floor = d.floor ?? new Date(Date.now() - 7 * 86_400_000).toISOString();
719
+ let changes = [
720
+ {
721
+ eid,
722
+ name: 'dream',
723
+ comp: {
724
+ scope: project.eid,
725
+ floor
726
+ }
727
+ },
728
+ {
729
+ eid: w,
730
+ name: 'wake',
731
+ comp: {
732
+ at: new Date(Date.now() + 1000).toISOString()
733
+ }
734
+ },
735
+ {
736
+ eid: w,
737
+ name: 'deliver',
738
+ comp: {
739
+ to: eid
740
+ }
741
+ }
742
+ ];
743
+ return {
744
+ eid,
745
+ changes
746
+ };
747
+ };
748
+ //# sourceMappingURL=client.js.map