@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/commands.js ADDED
@@ -0,0 +1,1157 @@
1
+ import { vocab } from "./types.js";
2
+ // The `:` command line's grammar — one vocabulary for both faces. A verb
3
+ // is a pure function from (line, context) to INTENT: changes to land, an
4
+ // entity to open, a line for the status bar. Nothing here touches the
5
+ // wire, a signal, or a DOM — Status.tsx and the TUI run the result through
6
+ // mutate()/navigate — which is why every verb below is a table test.
7
+ //
8
+ // :new <title> a task where you're standing (a board's query rides
9
+ // along, so it lands ON the board you made it on)
10
+ // :done :wip status moves on the focused entity
11
+ // :open …and back to open — but
12
+ // :open T-42 an ARGUMENT means navigate. Shape is the whole rule.
13
+ // :claim [session] lease the focused entity
14
+ // :set .prop=v … the write grammar (client.ts param); a value rides
15
+ // the door's own convention (Ctx.read) — @file and @-
16
+ // where the door has a filesystem, literal elsewhere
17
+ //
18
+ // A bad command throws; the bar shows the message, exactly as a malformed
19
+ // board query does (query.ts). Platform-local verbs (the TUI's :q, the
20
+ // web's :zoom) ride in run()'s `local` table — the shared list is the
21
+ // language both faces speak, and each adds only what the other can't do.
22
+ import { HUMAN, SHORT } from "@yaks/id";
23
+ import { EID } from "./types.js";
24
+ import { idOf, uuid } from "./types.js";
25
+ import { cascade, commentChanges as agentCommentChanges, derefChanges, derefWith, dreamChanges, find, mailChanges, need, param, patches, replyChanges, spec, statusChanges, taskChanges, uniq, UUID } from "./client.js";
26
+ import { matchQuery, parseQuery, selected } from "./query.js";
27
+ import { adopt, parse, timeInstant } from "@yaks/query";
28
+ import { id, slotsOf, text } from "./verb.js";
29
+ import { newPath } from "./navigation.js";
30
+ // A `:` command's argument, built terse: `a('id', 'T-42', { kind: id })`. The
31
+ // default kind is free text; `eg` is the concrete sample the palette ghosts,
32
+ // `need: false` marks it optional, `rest: true` a trailing catch-all. The
33
+ // slots ARE the ghost — one per typed word — replacing the old prose regex.
34
+ let a = (name, eg, opts = {})=>({
35
+ name,
36
+ kind: text,
37
+ ...eg ? {
38
+ eg
39
+ } : {},
40
+ ...opts
41
+ });
42
+ // The reader over an in-memory Row[] — the browser/TUI cache and the tests.
43
+ // Every method is the same scan those doors already ran; `deps` is empty
44
+ // because a cache carries edges elsewhere and the browser never spawns through
45
+ // this path.
46
+ export let rowsReader = (all)=>({
47
+ find: (id)=>find(all, id),
48
+ need: (id, where, comp)=>need(all, id, where, comp),
49
+ session: (sid)=>all.find((r)=>r.comps.session && String(r.comps.session.id) == sid),
50
+ cascade: (eid)=>cascade(all, eid),
51
+ select: (filter)=>{
52
+ let preds = parseQuery(filter);
53
+ return all.filter((r)=>selected(r.comps, preds) && matchQuery(r.comps, preds));
54
+ },
55
+ deps: ()=>[]
56
+ });
57
+ // The reader a verb reads through: the one the door handed in, else one wrapped
58
+ // around the rows in hand. So a verb never branches on which door it runs at.
59
+ let graphOf = (ctx)=>ctx.graph ?? rowsReader(ctx.rows);
60
+ // A change-builder corpus: the specific rows a builder resolves ids against,
61
+ // deduped. A builder still takes a Row[] and calls find()/sessionFor() over it,
62
+ // so the door hands it exactly the entities it will touch (the target, the
63
+ // author session, a dream cursor) — never the whole graph.
64
+ let corpus = (...rows)=>uniq(rows.filter((r)=>!!r));
65
+ // The headless focus, resolved through a reader: a session's single claim is an
66
+ // unambiguous "here". The db-backed twin of focusOf() — same rule, scoped
67
+ // reads. undefined when the session holds no lease, or more than one.
68
+ export let focusFor = (g, session)=>{
69
+ if (!session) return undefined;
70
+ let me = g.session(session);
71
+ if (!me) return undefined;
72
+ let mine = g.select(`.claim.session=${me.eid}`);
73
+ return mine.length == 1 ? mine[0].eid : undefined;
74
+ };
75
+ export let spawnTask = (spawn)=>typeof spawn == 'string' ? spawn : undefined;
76
+ export let spawnSpec = (spawn)=>typeof spawn == 'string' ? {
77
+ task: spawn
78
+ } : spawn;
79
+ // Where a HEADLESS caller stands: its session's single claim. The shell
80
+ // door resolves focus through this — one lease is an unambiguous
81
+ // "here"; none or several mean the line must lead with an id.
82
+ export let focusOf = (rows, session)=>{
83
+ if (!session) return undefined;
84
+ let me = rows.find((r)=>String(r.comps.session?.id ?? '') == session);
85
+ if (!me) return undefined;
86
+ let mine = rows.filter((r)=>r.comps.claim?.session == me.eid);
87
+ return mine.length == 1 ? mine[0].eid : undefined;
88
+ };
89
+ let here = (ctx)=>{
90
+ let r = ctx.eid ? graphOf(ctx).find(ctx.eid) : undefined;
91
+ if (!r) throw new Error('nothing focused');
92
+ return r;
93
+ };
94
+ // A letter's page, through the door's own @ convention (T-10461). `read`
95
+ // is the same seam the dot-params use, so a door with no filesystem —
96
+ // the web bar, MCP — leaves it absent and every page stays literal. It
97
+ // reads only when the page IS a reference: one token, no whitespace, so
98
+ // prose that opens `@someone` keeps its words either way. @@ escapes,
99
+ // and a missing file throws before the mail is minted.
100
+ let page = (body, ctx)=>ctx.read && /^@\S+$/.test(body) ? String(ctx.read({
101
+ comp: 'doc',
102
+ prop: 'body',
103
+ value: body
104
+ }, undefined, body).value) : body;
105
+ // Status is DERIVED (D-24102): a close mints its mark, apply() stamps at/by/via.
106
+ // `done` wears `completed`, `cancel` wears `cancelled`, `reopen` retracts both
107
+ // with `started` and any claim. `wip` leases under a session and wears
108
+ // `started` without one — see the verb below.
109
+ let complete = (_rest, ctx)=>{
110
+ let r = here(ctx);
111
+ if (!r.comps.task) throw new Error(`${idOf(r)} is not a task`);
112
+ return {
113
+ changes: [
114
+ {
115
+ eid: r.eid,
116
+ name: 'cancelled',
117
+ comp: null
118
+ },
119
+ {
120
+ eid: r.eid,
121
+ name: 'completed',
122
+ comp: {}
123
+ }
124
+ ],
125
+ msg: `${idOf(r)} → done`
126
+ };
127
+ };
128
+ let reopen = (_rest, ctx)=>{
129
+ let r = here(ctx);
130
+ if (!r.comps.task) throw new Error(`${idOf(r)} is not a task`);
131
+ return {
132
+ changes: [
133
+ {
134
+ eid: r.eid,
135
+ name: 'completed',
136
+ comp: null
137
+ },
138
+ {
139
+ eid: r.eid,
140
+ name: 'cancelled',
141
+ comp: null
142
+ },
143
+ {
144
+ eid: r.eid,
145
+ name: 'started',
146
+ comp: null
147
+ },
148
+ {
149
+ eid: r.eid,
150
+ name: 'claim',
151
+ comp: null
152
+ }
153
+ ],
154
+ msg: `${idOf(r)} → open`
155
+ };
156
+ };
157
+ let go = (id, ctx)=>{
158
+ let r = graphOf(ctx).find(id);
159
+ if (!r) throw new Error(`no such entity: ${id}`);
160
+ return {
161
+ go: r.eid
162
+ };
163
+ };
164
+ // What a new task inherits from where you're standing: a board hands over
165
+ // its query's scalar equalities — the same adopt() a board drop uses, so
166
+ // the task JOINS the board — a project hands over itself, and a task the
167
+ // project it belongs to.
168
+ let inherit = (ctx)=>{
169
+ let r = ctx.eid ? graphOf(ctx).find(ctx.eid) : undefined;
170
+ if (!r) return {};
171
+ if (r.comps.board) {
172
+ return adopt(parse(String(r.comps.board.query ?? '')), vocab);
173
+ }
174
+ if (r.comps.project) return {
175
+ filed: {
176
+ project: r.eid
177
+ }
178
+ };
179
+ let p = r.comps.filed?.project;
180
+ return p ? {
181
+ filed: {
182
+ project: p
183
+ }
184
+ } : {};
185
+ };
186
+ // :delete tombstones the focused entity — or the one the line names. The one
187
+ // warm verb that REMOVES, so the graph can shrink and not only grow. Death
188
+ // CASCADES: comments aimed at it, cards and knocks/wakes
189
+ // viewing it die with it. A leaf goes quietly; a target with dependents
190
+ // REFUSES without --cascade, naming what it would take, so the blast radius is
191
+ // never a surprise. `:forget` is the same verb, said the way a memory wants to
192
+ // hear it. This pass sees only the rows in hand (a palette is wire-free); the
193
+ // shell's `task delete` queries the graph for the authoritative set.
194
+ let del = (rest, ctx)=>{
195
+ let words = rest.trim().split(/\s+/).filter(Boolean);
196
+ let ok = words.some((w)=>w == '--cascade' || w == '--force');
197
+ let named = words.find((w)=>!w.startsWith('--'));
198
+ let g = graphOf(ctx);
199
+ let r = named ? g.need(named) : here(ctx);
200
+ let victims = g.cascade(r.eid);
201
+ if (victims.length && !ok) {
202
+ throw new Error(`${idOf(r)} would also delete ${victims.length} dependent${victims.length == 1 ? '' : 's'} (${victims.map(idOf).join(', ')}) — add --cascade to take them too`);
203
+ }
204
+ return {
205
+ changes: [
206
+ {
207
+ eid: r.eid,
208
+ name: 'entity',
209
+ comp: null
210
+ }
211
+ ],
212
+ msg: `deleted ${idOf(r)}${victims.length ? ` (+${victims.length} dependent${victims.length == 1 ? '' : 's'})` : ''}`
213
+ };
214
+ };
215
+ // Blank cards are the canvas's scratch paper: mint the smallest sound entity
216
+ // and let its own title/editor take the next words. Curated on purpose — most
217
+ // components are facets or machinery, not things that stand alone.
218
+ export let cardCommands = [
219
+ 'task',
220
+ 'session',
221
+ 'doc',
222
+ 'memory'
223
+ ];
224
+ let readParams = (args, ctx)=>{
225
+ let read = ctx.read ?? ((p)=>p);
226
+ return args.map((arg)=>{
227
+ let p = param(arg, read);
228
+ if (!p) throw new Error(`not a param: ${arg}`);
229
+ return p;
230
+ });
231
+ };
232
+ // A session card is a continuation recipe, not a copy of the run. Only the
233
+ // configuration that makes another run usable rides forward; pid, transcript,
234
+ // status, and the other lifecycle facts belong to the session that earned
235
+ // them. The focused session is what a browser can name, while headless doors
236
+ // name their calling session in the context.
237
+ let sessionDefaults = (ctx)=>{
238
+ let g = graphOf(ctx);
239
+ let focused = ctx.eid ? g.find(ctx.eid) : undefined;
240
+ let source = (focused?.comps.session ? focused : undefined) ?? (ctx.session ? g.session(ctx.session) : undefined);
241
+ let session = source?.comps.session;
242
+ if (!session) return {};
243
+ let keys = [
244
+ 'cwd',
245
+ 'provider',
246
+ 'model',
247
+ 'effort',
248
+ 'requested_task',
249
+ 'persona',
250
+ 'actor'
251
+ ];
252
+ return Object.fromEntries(keys.filter((key)=>session[key] != null).map((key)=>[
253
+ key,
254
+ session[key]
255
+ ]));
256
+ };
257
+ let card = (kind)=>({
258
+ args: [
259
+ a(kind == 'task' ? 'title' : 'params', {
260
+ task: 'P1 .filed.domain=Eng title…',
261
+ session: '.session.id=review',
262
+ doc: '.doc.title=Notes .doc.body=…',
263
+ memory: '.doc.title=Lesson .memory.scope=home'
264
+ }[kind], {
265
+ rest: true,
266
+ need: false
267
+ })
268
+ ],
269
+ about: `add a ${kind} card`,
270
+ dots: true,
271
+ run: (rest, ctx)=>{
272
+ let [line, ...lines] = rest.split('\n');
273
+ // A leading doc setter is the card property's explicit spelling; its
274
+ // value may contain spaces. Otherwise a task speaks the typed-task
275
+ // grammar: first line title, following lines body.
276
+ let explicit = kind == 'task' && /^\s*\./.test(line) && /(?:^|\s)\.doc\.(?:title|body)=/.test(line);
277
+ let typed = kind == 'task' && !explicit ? spec(rest, ctx.read) : undefined;
278
+ let text = kind == 'task' && explicit ? line : rest.trim();
279
+ let args = typed || !text ? [] : text.split(/\s+(?=\.)/);
280
+ let ps = readParams(args, ctx);
281
+ let grouped = typed?.grouped ?? patches(ps);
282
+ let allowed = kind == 'task' ? [
283
+ 'doc',
284
+ 'task',
285
+ 'filed',
286
+ 'accept'
287
+ ] : kind == 'memory' ? [
288
+ 'doc',
289
+ 'memory'
290
+ ] : [
291
+ kind
292
+ ];
293
+ for (let p of ps){
294
+ if (!allowed.includes(p.comp)) {
295
+ throw new Error(`${kind}: cannot set ${p.comp}.${p.prop}`);
296
+ }
297
+ }
298
+ for (let name of Object.keys(typed?.grouped ?? {})){
299
+ if (!allowed.includes(name)) {
300
+ throw new Error(`${kind}: cannot set ${name}`);
301
+ }
302
+ }
303
+ let eid = uuid();
304
+ let changes = kind == 'session' ? [
305
+ {
306
+ eid,
307
+ name: 'session',
308
+ comp: {
309
+ id: uuid(),
310
+ ...sessionDefaults(ctx),
311
+ ...grouped.session
312
+ }
313
+ }
314
+ ] : kind == 'task' ? taskChanges(eid, {
315
+ ...grouped,
316
+ doc: {
317
+ title: typed?.title ?? '',
318
+ body: typed?.body ?? (explicit ? lines.join('\n').trim() : ''),
319
+ ...grouped.doc
320
+ }
321
+ }) : [
322
+ {
323
+ eid,
324
+ name: 'doc',
325
+ comp: {
326
+ title: typed?.title ?? '',
327
+ body: typed?.body ?? (explicit ? lines.join('\n').trim() : ''),
328
+ ...grouped.doc
329
+ }
330
+ },
331
+ ...kind == 'doc' ? [] : [
332
+ {
333
+ eid,
334
+ name: kind,
335
+ // An absent memory scope means fleet-wide, represented as null.
336
+ comp: {
337
+ scope: null,
338
+ ...grouped.memory
339
+ }
340
+ }
341
+ ]
342
+ ];
343
+ if (kind == 'task') {
344
+ changes[0].$num = true;
345
+ }
346
+ return {
347
+ changes,
348
+ card: eid,
349
+ msg: `new ${kind}`
350
+ };
351
+ }
352
+ });
353
+ let commentChanges = (...args)=>agentCommentChanges(...args).map((c)=>c.name == 'comment' ? {
354
+ ...c,
355
+ $num: true
356
+ } : c);
357
+ export let commands = {
358
+ // :new speaks the spec grammar (client.ts): 'P1 .filed.domain=Eng Ship it'
359
+ // — typed setters win over what the context hands down.
360
+ new: {
361
+ dots: true,
362
+ args: [
363
+ a('title', 'P1 .filed.domain=Eng title…', {
364
+ rest: true
365
+ })
366
+ ],
367
+ about: 'file a task where you stand',
368
+ run: (rest, ctx)=>{
369
+ let { title, body, grouped } = spec(rest, ctx.read);
370
+ if (!title) throw new Error('new: needs a title');
371
+ let inherited = inherit(ctx);
372
+ for (let [comp, values] of Object.entries(inherited)){
373
+ grouped[comp] = {
374
+ ...values,
375
+ ...grouped[comp]
376
+ };
377
+ }
378
+ return {
379
+ changes: taskChanges(uuid(), {
380
+ ...grouped,
381
+ doc: {
382
+ title,
383
+ body,
384
+ ...grouped.doc
385
+ }
386
+ }, true),
387
+ msg: `new: ${title}`
388
+ };
389
+ }
390
+ },
391
+ open: {
392
+ args: [
393
+ a('id', 'T-42', {
394
+ kind: id,
395
+ need: false
396
+ })
397
+ ],
398
+ about: 'reopen the task — or go to T-42',
399
+ words: [
400
+ 0,
401
+ 1
402
+ ],
403
+ run: (rest, ctx)=>rest.trim() ? go(rest.trim(), ctx) : reopen(rest, ctx)
404
+ },
405
+ // :fix is capture-to-agent in one line: a bare id runs an agent on
406
+ // that task; anything else is a spec line that FILES the task first.
407
+ // A fix without a named task is a fix for the TOOL you're typing into
408
+ // — whatever card you're looking at — so it routes to the deployment's
409
+ // own project (venture alias `tasks`; the sole repo-bearing project when no
410
+ // alias stands). Explicit .filed.project= always wins. The spawn is an
411
+ // INTENT like go: this module never touches the wire.
412
+ fix: {
413
+ dots: true,
414
+ args: [
415
+ a('task', 'T-42 | the toolbar clips at small widths', {
416
+ rest: true,
417
+ need: false
418
+ })
419
+ ],
420
+ about: 'run a fix agent — here, on T-42, or on a task your words file',
421
+ run: (rest, ctx)=>{
422
+ let g = graphOf(ctx);
423
+ let text = rest.trim();
424
+ // Bare :fix means HERE — said on a task's card (or in its
425
+ // comments, once those run commands), the target is understood.
426
+ if (!text) {
427
+ let r = here(ctx);
428
+ if (!r.comps.task) throw new Error(`${idOf(r)} is not a task`);
429
+ return {
430
+ spawn: r.eid,
431
+ msg: `${idOf(r)} → agent`
432
+ };
433
+ }
434
+ if (HUMAN.test(text) || SHORT.test(text) || EID.test(text)) {
435
+ let r = g.find(text);
436
+ if (!r?.comps.task) throw new Error(`no such task: ${text}`);
437
+ return {
438
+ spawn: r.eid,
439
+ msg: `${idOf(r)} → agent`
440
+ };
441
+ }
442
+ let { title, body, grouped } = spec(text, ctx.read);
443
+ if (!title) throw new Error('fix: needs a title');
444
+ let filed = {
445
+ ...grouped.filed
446
+ };
447
+ if (!filed.project) {
448
+ let tasks = g.find('tasks');
449
+ if (tasks?.comps.project) filed.project = tasks.eid;
450
+ else {
451
+ let repos = g.select('.repo .project');
452
+ if (repos.length == 1) filed.project = repos[0].eid;
453
+ }
454
+ }
455
+ let eid = uuid();
456
+ return {
457
+ changes: taskChanges(eid, {
458
+ ...grouped,
459
+ doc: {
460
+ title,
461
+ body,
462
+ ...grouped.doc
463
+ },
464
+ filed
465
+ }),
466
+ spawn: eid,
467
+ msg: `fix: ${title}`
468
+ };
469
+ }
470
+ },
471
+ chat: {
472
+ dots: true,
473
+ args: [
474
+ a('prompt', '.session.provider=codex .session.model=gpt-6.2-sol prompt…', {
475
+ rest: true,
476
+ need: false
477
+ })
478
+ ],
479
+ about: 'start a taskless chat',
480
+ run: (rest, ctx)=>{
481
+ let { title, body, grouped } = spec(rest, ctx.read);
482
+ for (let name of Object.keys(grouped)){
483
+ if (![
484
+ 'doc',
485
+ 'session',
486
+ 'spawn'
487
+ ].includes(name)) {
488
+ throw new Error(`chat: cannot set ${name}`);
489
+ }
490
+ }
491
+ for (let name of Object.keys(grouped.session ?? {})){
492
+ if (![
493
+ 'provider',
494
+ 'model',
495
+ 'effort'
496
+ ].includes(name)) {
497
+ throw new Error(`chat: cannot set session.${name}`);
498
+ }
499
+ }
500
+ let prompt = [
501
+ title,
502
+ body
503
+ ].filter(Boolean).join('\n');
504
+ let launch = {
505
+ ...grouped.session,
506
+ ...grouped.spawn
507
+ };
508
+ return {
509
+ spawn: {
510
+ // A taskless run has no checkout for a process-backed fallback.
511
+ // Keep an explicit model free to infer its own provider, but make
512
+ // the bare chat's default execution path graph-native.
513
+ ...!launch.provider && !launch.model ? {
514
+ provider: 'codex'
515
+ } : {},
516
+ ...prompt ? {
517
+ prompt
518
+ } : {},
519
+ ...launch
520
+ },
521
+ msg: 'chat → agent'
522
+ };
523
+ }
524
+ },
525
+ comment: {
526
+ dots: true,
527
+ args: [
528
+ a('text', '.doc.body=@- | words…', {
529
+ rest: true
530
+ })
531
+ ],
532
+ about: 'comment on the focused entity',
533
+ run: (rest, ctx)=>{
534
+ let r = here(ctx);
535
+ let text = rest.trim();
536
+ let p = param(text, ctx.read);
537
+ if (p && (p.comp != 'doc' || p.prop != 'body')) {
538
+ throw new Error(`comment: cannot set ${p.comp}.${p.prop}`);
539
+ }
540
+ let body = p ? String(p.value) : page(text, ctx);
541
+ if (!body) throw new Error('comment: needs words or .doc.body=<text>');
542
+ let made = commentChanges(corpus(r, ctx.session ? graphOf(ctx).session(ctx.session) : undefined), r.eid, body, ctx.session);
543
+ return {
544
+ changes: made,
545
+ msg: `comment → ${idOf(r)}`
546
+ };
547
+ }
548
+ },
549
+ done: {
550
+ args: [],
551
+ about: 'move the focused task to done (shell: `task done T-3 [comment]` names one explicitly)',
552
+ words: [
553
+ 0,
554
+ 0
555
+ ],
556
+ run: complete
557
+ },
558
+ wip: {
559
+ args: [],
560
+ about: 'take up the focused task — a session claims it, a person marks it started (shell: `task wip T-3`)',
561
+ words: [
562
+ 0,
563
+ 0
564
+ ],
565
+ run: (_rest, ctx)=>{
566
+ let r = here(ctx);
567
+ if (!r.comps.task) throw new Error(`${idOf(r)} is not a task`);
568
+ return {
569
+ changes: statusChanges(r.eid, 'wip', ctx.session),
570
+ msg: `${idOf(r)} → wip`
571
+ };
572
+ }
573
+ },
574
+ cancel: {
575
+ args: [
576
+ a('reason', 'reason', {
577
+ rest: true,
578
+ need: false
579
+ })
580
+ ],
581
+ about: 'call off the focused task; the words become a comment ' + '(shell: `task cancel T-3 [reason]` names one explicitly)',
582
+ run: (rest, ctx)=>{
583
+ let g = graphOf(ctx);
584
+ let r = here(ctx);
585
+ if (!r.comps.task) throw new Error(`${idOf(r)} is not a task`);
586
+ let reason = rest.trim();
587
+ return {
588
+ changes: [
589
+ {
590
+ eid: r.eid,
591
+ name: 'completed',
592
+ comp: null
593
+ },
594
+ // The `cancelled` mark IS the status now (D-24102); its optional
595
+ // reason rides the comp, apply() stamps at/by/via.
596
+ {
597
+ eid: r.eid,
598
+ name: 'cancelled',
599
+ comp: reason ? {
600
+ reason
601
+ } : {}
602
+ },
603
+ // the why also rides the same atomic batch — as plain commentary,
604
+ // never a machine trail (the journal records the change)
605
+ ...reason ? commentChanges(corpus(r, ctx.session ? g.session(ctx.session) : undefined), r.eid, reason, ctx.session) : []
606
+ ],
607
+ msg: `${idOf(r)} → cancelled${reason ? ` — ${reason}` : ''}`
608
+ };
609
+ }
610
+ },
611
+ // :meta leaves a quiet transcript memo — a comment TAGGED `meta`, anchored
612
+ // at the caller session's newest MESSAGE entry, for the dream (T-12800) to
613
+ // harvest at consolidation. The tag is the whole point: it marks the note
614
+ // as a memo for the dream, read later, not words to the doer. A fresh
615
+ // session with no message yet anchors on the session entity, so a memo
616
+ // never fails for want of a transcript position.
617
+ meta: {
618
+ args: [
619
+ a('observation', 'the observation to leave for the dream', {
620
+ rest: true
621
+ })
622
+ ],
623
+ about: 'leave a quiet meta memo in the transcript (harvested by the dream, not live)',
624
+ run: (rest, ctx)=>{
625
+ let text = page(rest.trim(), ctx);
626
+ if (!text) throw new Error('meta: needs words (:meta the observation)');
627
+ let g = graphOf(ctx);
628
+ let me = ctx.session ? g.session(ctx.session) : undefined;
629
+ if (!me) throw new Error('meta: run under a session');
630
+ // The newest prose entry of my session — the transcript position the
631
+ // memo anchors to. The db reader answers entries in seq order already;
632
+ // the sort makes the cache reader agree, so .at(-1) is newest either way.
633
+ let anchor = g.select(`.entry.session=${me.eid} .content`).sort((a, b)=>Number(a.comps.entry?.seq ?? 0) - Number(b.comps.entry?.seq ?? 0)).at(-1) ?? me;
634
+ let made = commentChanges(corpus(anchor, me), anchor.eid, text, ctx.session);
635
+ let eid = made.find((c)=>c.name == 'comment').eid;
636
+ return {
637
+ changes: [
638
+ ...made,
639
+ {
640
+ eid,
641
+ name: 'meta',
642
+ comp: {}
643
+ }
644
+ ],
645
+ msg: `meta → ${idOf(anchor)}`
646
+ };
647
+ }
648
+ },
649
+ // :dream starts a venture's consolidation cycle (T-12800) — mint the
650
+ // per-venture `dream` cursor and arm its first cadence wake. A named project
651
+ // wins; otherwise the focused entity, which must be a project. Idempotent: a
652
+ // second dream on the same venture is refused by dreamChanges.
653
+ dream: {
654
+ args: [
655
+ a('project', 'P-19', {
656
+ kind: id,
657
+ need: false
658
+ })
659
+ ],
660
+ about: 'start a venture dreaming — the graph-native consolidation cycle',
661
+ run: (rest, ctx)=>{
662
+ let g = graphOf(ctx);
663
+ let first = rest.trim().split(/\s+/).filter(Boolean)[0];
664
+ let r = first ? g.find(first) : here(ctx);
665
+ if (!r) throw new Error(`dream: no such project: ${first}`);
666
+ // dreamChanges resolves the project and refuses a venture already
667
+ // dreaming — so the corpus is the project plus any dream cursor scoped
668
+ // to it, the one existence check it makes.
669
+ let made = dreamChanges(corpus(r, ...g.select(`.dream.scope=${r.eid}`)), {
670
+ project: r.eid
671
+ });
672
+ return {
673
+ changes: made.changes,
674
+ msg: `dreaming ${idOf(r)}`
675
+ };
676
+ }
677
+ },
678
+ // :knock is the attention lever: bring the focused entity to someone's
679
+ // attention NOW. The first word IS the recipient (alias, id) and must
680
+ // resolve; the rest ride as a plain comment on the target — the knock
681
+ // artifact itself never carries prose. Delivery is the server's
682
+ // ladder; the stamp on the K-entity says what happened.
683
+ //
684
+ // A BARE `:knock` still asks the entity's own project — no word was
685
+ // said, so nothing can be mistaken. But a first word that fails to
686
+ // resolve used to fall through to that same default while folding the
687
+ // word into the BODY (T-10905), and nothing looked wrong: the receipt
688
+ // read `→ knock project`, delivery happened, an operator woke — and the
689
+ // message they read opened with a stray token while the recipient it
690
+ // named was never asked. Those two cases are indistinguishable from the
691
+ // inside, so any word given must NAME someone: an unresolved address
692
+ // must never become content. `:wake`, the same sentence with a clock,
693
+ // has always refused an unresolvable first word — the siblings agree now.
694
+ knock: {
695
+ args: [
696
+ a('to', 'homelab', {
697
+ kind: id,
698
+ need: false
699
+ }),
700
+ a('words', 'need the key today', {
701
+ rest: true,
702
+ need: false
703
+ })
704
+ ],
705
+ about: "someone's attention, now — on the focused entity",
706
+ run: (rest, ctx)=>{
707
+ let g = graphOf(ctx);
708
+ let r = here(ctx);
709
+ let [first, ...more] = rest.trim().split(/\s+/).filter(Boolean);
710
+ let to = first ? g.find(first) : undefined;
711
+ if (first && !to) {
712
+ throw new Error(`knock: no such recipient: ${first} — name an alias or id ` + `(:knock homelab …, :knock P-19 …)`);
713
+ }
714
+ let words = more.filter(Boolean).join(' ');
715
+ let toEid = to?.eid ?? r.comps.filed?.project;
716
+ if (!toEid) {
717
+ throw new Error('knock: name a recipient (:knock homelab …)');
718
+ }
719
+ let k = uuid();
720
+ return {
721
+ changes: [
722
+ {
723
+ eid: k,
724
+ name: 'knock',
725
+ comp: {
726
+ target: r.eid
727
+ }
728
+ },
729
+ {
730
+ eid: k,
731
+ name: 'deliver',
732
+ comp: {
733
+ to: toEid
734
+ }
735
+ },
736
+ ...words ? commentChanges(corpus(r, ctx.session ? g.session(ctx.session) : undefined), r.eid, words, ctx.session) : []
737
+ ],
738
+ msg: `${idOf(r)} → knock ${to ? first : 'project'}`
739
+ };
740
+ }
741
+ },
742
+ // :wake is :knock with a clock: the same sentence, said later. First
743
+ // word is who; the rest is WHEN ('in 60m', 'after 8 hours', '9am
744
+ // tomorrow', an ISO stamp) — unless its last word names an entity,
745
+ // which is what to look at (else: where you stand). The phrase
746
+ // resolves HERE, at mint, and the line says the moment it landed on,
747
+ // so a time already past is visible rather than a silent knock now.
748
+ wake: {
749
+ args: [
750
+ a('to', 'homelab', {
751
+ kind: id
752
+ }),
753
+ a('when', 'in 60m'),
754
+ a('target', 'T-42', {
755
+ kind: id,
756
+ need: false
757
+ }),
758
+ a('note', '-- what I was mid-doing', {
759
+ rest: true,
760
+ need: false
761
+ })
762
+ ],
763
+ about: 'a knock on a timer — wake someone at a time, with an optional note',
764
+ run: (rest, ctx)=>{
765
+ // `-- note` folds a note onto the wake (like :mail's `-- body`): what the
766
+ // setter was mid-doing, relayed into the knock's words when it fires so a
767
+ // resumed session reconstitutes. The head before it is the ordinary
768
+ // who / when / target sentence.
769
+ let m = rest.match(/^([\s\S]*?)\s+--\s+([\s\S]+)$/);
770
+ let head = m ? m[1] : rest;
771
+ let note = m ? m[2].trim() : '';
772
+ let g = graphOf(ctx);
773
+ let words = head.trim().split(/\s+/).filter(Boolean);
774
+ let to = words[0] ? g.find(words[0]) : undefined;
775
+ // A present-but-unresolved first word is a lookup miss, not a missing
776
+ // argument — say so (the sibling of knock's "no such recipient"), so the
777
+ // reader isn't sent hunting for a syntax error that isn't there (T-13972).
778
+ if (words[0] && !to) {
779
+ throw new Error(`wake: no such recipient: ${words[0]} — name an alias or id ` + `(:wake homelab in 60m, :wake P-19 in 1h)`);
780
+ }
781
+ if (!to) throw new Error('wake: name who to wake (:wake homelab in 60m)');
782
+ let more = words.slice(1);
783
+ let last = more.length > 1 ? g.find(more[more.length - 1]) : undefined;
784
+ if (last) more = more.slice(0, -1);
785
+ let when = more.join(' ');
786
+ let at = timeInstant(when);
787
+ if (at == null) {
788
+ throw new Error(`wake: when is "${when}"? (in 60m, 9am tomorrow, 2026-07-25T09:00)`);
789
+ }
790
+ let about = last ?? (ctx.eid ? g.find(ctx.eid) : undefined);
791
+ let w = uuid();
792
+ return {
793
+ changes: [
794
+ {
795
+ eid: w,
796
+ name: 'wake',
797
+ comp: {
798
+ at: new Date(at).toISOString(),
799
+ ...about ? {
800
+ target: about.eid
801
+ } : {},
802
+ ...note ? {
803
+ note
804
+ } : {}
805
+ }
806
+ },
807
+ {
808
+ eid: w,
809
+ name: 'deliver',
810
+ comp: {
811
+ to: to.eid
812
+ }
813
+ }
814
+ ],
815
+ msg: `wake ${idOf(to)}${about ? ` → ${idOf(about)}` : ''} at ${new Date(at).toString().slice(0, 21)}`
816
+ };
817
+ }
818
+ },
819
+ // :park is :wake aimed at YOURSELF — the dep-loop's arming act (D-21448). A
820
+ // session working a task gated by open `requires` blockers ends its turn but
821
+ // must leave a PENDING WAKE on its OWN session, so settled()/reapLeases()
822
+ // RETAIN its claim (parkedWaiting) instead of lapsing it; the dep-completion
823
+ // knock then resumes it WARM when a blocker lands. The wake is
824
+ // the parked marker + a safety fallback; the knock is the real resume. The
825
+ // held claim IS the wait registration — no new facet. Targets the caller's
826
+ // own SESSION (deliver.to = session), which is what pendingWake(session)
827
+ // reads — never the actor, whose cadence wake is a different thing.
828
+ park: {
829
+ args: [
830
+ a('when', 'in 12h', {
831
+ need: false
832
+ }),
833
+ a('note', '-- what I was mid-doing', {
834
+ rest: true,
835
+ need: false
836
+ })
837
+ ],
838
+ about: 'park until your blockers land — keep your claim, resume warm on a dep',
839
+ run: (rest, ctx)=>{
840
+ let g = graphOf(ctx);
841
+ let me = ctx.session ? g.session(ctx.session) : undefined;
842
+ if (!me) {
843
+ throw new Error('park: no session to park — park is for a managed session ' + 'waiting on its `requires` blockers');
844
+ }
845
+ let m = rest.match(/^([\s\S]*?)\s+--\s+([\s\S]+)$/);
846
+ let head = (m ? m[1] : rest).trim();
847
+ let note = m ? m[2].trim() : '';
848
+ let at = timeInstant(head || 'in 12h');
849
+ if (at == null) {
850
+ throw new Error(`park: when is "${head}"? (in 12h, 6am tomorrow)`);
851
+ }
852
+ // The gated task this session holds — its single claim, the thing it is
853
+ // waiting on. The fired wake (or the resuming knock) points back at it.
854
+ let task = focusFor(g, ctx.session);
855
+ let taskRow = task ? g.find(task) : undefined;
856
+ let w = uuid();
857
+ return {
858
+ changes: [
859
+ {
860
+ eid: w,
861
+ name: 'wake',
862
+ comp: {
863
+ at: new Date(at).toISOString(),
864
+ ...task ? {
865
+ target: task
866
+ } : {},
867
+ ...note ? {
868
+ note
869
+ } : {}
870
+ }
871
+ },
872
+ {
873
+ eid: w,
874
+ name: 'deliver',
875
+ comp: {
876
+ to: me.eid
877
+ }
878
+ }
879
+ ],
880
+ msg: `parked${taskRow ? ` on ${idOf(taskRow)}` : ''} — claim held, ` + `resume when a blocker lands (fallback wake ${new Date(at).toString().slice(0, 21)})`
881
+ };
882
+ }
883
+ },
884
+ // :mail is the letter in one line — to, subject, then `--` folds the
885
+ // envelope open into the page. Minting doc+mail IS the send request
886
+ // (the mailer effect delivers and stamps the receipt); the verb mints
887
+ // PROSE only — a letter is words an agent wrote.
888
+ // `to` stays as given: raw address or graph reference, the address
889
+ // book resolves at delivery.
890
+ mail: {
891
+ args: [
892
+ a('to', 'jeff', {
893
+ kind: id
894
+ }),
895
+ a('subject', 'subject…'),
896
+ a('body', '-- body…', {
897
+ rest: true
898
+ })
899
+ ],
900
+ about: 'send a letter: to, subject, -- body',
901
+ run: (rest, ctx)=>{
902
+ let [, head, body] = rest.match(/^([\s\S]*?)\s+--\s+([\s\S]+)$/) ?? [];
903
+ let [to, ...subj] = (head ?? '').trim().split(/\s+/).filter(Boolean);
904
+ if (!to || !subj.length || !body?.trim()) {
905
+ throw new Error('mail: to, subject, then -- body (:mail jeff lunch? -- noon?)');
906
+ }
907
+ let subject = subj.join(' ');
908
+ return {
909
+ changes: mailChanges({
910
+ to,
911
+ subject,
912
+ body: page(body.trim(), ctx)
913
+ }).changes,
914
+ msg: `mail → ${to} — ${subject}`
915
+ };
916
+ }
917
+ },
918
+ // :reply answers a mail where you stand — or the E-id the line leads
919
+ // with. The words ARE the page (a lone @file is that page — see
920
+ // `page`); the mail tool resolves the far side, threading and attention.
921
+ reply: {
922
+ args: [
923
+ a('id', 'E-9', {
924
+ kind: id,
925
+ need: false
926
+ }),
927
+ a('answer', 'the answer…', {
928
+ rest: true
929
+ })
930
+ ],
931
+ about: 'answer the mail — Re: threads at delivery',
932
+ run: (rest, ctx)=>{
933
+ let [, first, more] = rest.trim().match(/^(\S+)\s*([\s\S]*)$/) ?? [];
934
+ let named = first ? graphOf(ctx).find(first) : undefined;
935
+ let row = named?.comps.mail ? named : here(ctx);
936
+ if (!row.comps.mail) throw new Error(`${idOf(row)} is not a mail`);
937
+ let body = (row == named ? more : rest).trim();
938
+ if (!body) throw new Error('reply: needs words (:reply E-9 on it)');
939
+ let made = replyChanges(row, page(body, ctx));
940
+ return {
941
+ changes: made.changes,
942
+ msg: `${idOf(row)} ← reply`
943
+ };
944
+ }
945
+ },
946
+ claim: {
947
+ args: [
948
+ a('session', undefined, {
949
+ need: false
950
+ })
951
+ ],
952
+ about: 'lease the focused entity',
953
+ words: [
954
+ 0,
955
+ 1
956
+ ],
957
+ run: (rest, ctx)=>{
958
+ let r = here(ctx);
959
+ let session = rest.trim() || ctx.session;
960
+ if (!session) throw new Error('claim: name a session (:claim sess-1)');
961
+ return {
962
+ changes: [
963
+ {
964
+ eid: r.eid,
965
+ name: 'claim',
966
+ comp: {
967
+ session
968
+ }
969
+ }
970
+ ],
971
+ msg: `${idOf(r)} ⚑ ${session}`
972
+ };
973
+ }
974
+ },
975
+ // Params start at a dot, which is what lets a value hold spaces
976
+ // (:set .doc.title=two words) without quoting rules the CLI's argv gives
977
+ // it for free. Values ride ctx.read — one @file convention for every
978
+ // door that has a filesystem, the same one `task set` speaks.
979
+ set: {
980
+ dots: true,
981
+ args: [
982
+ a('param', '.comp.prop=value'),
983
+ a('more', '…', {
984
+ rest: true,
985
+ need: false
986
+ })
987
+ ],
988
+ about: 'patch the focused entity',
989
+ run: (rest, ctx)=>{
990
+ let r = here(ctx);
991
+ let args = rest.trim().split(/\s+(?=\.)/).filter(Boolean);
992
+ if (!args.length) throw new Error('set: needs .comp.prop=value');
993
+ let ps = readParams(args, ctx);
994
+ return {
995
+ changes: Object.entries(patches(ps)).map(([name, comp])=>({
996
+ eid: r.eid,
997
+ name,
998
+ comp
999
+ })),
1000
+ msg: `${idOf(r)} ${args.join(' ')}`
1001
+ };
1002
+ }
1003
+ },
1004
+ delete: {
1005
+ args: [
1006
+ a('id', 'T-42', {
1007
+ kind: id,
1008
+ need: false
1009
+ }),
1010
+ a('--cascade', '--cascade', {
1011
+ need: false
1012
+ })
1013
+ ],
1014
+ about: 'tombstone an entity — the cascade takes its dependents (--cascade)',
1015
+ run: del
1016
+ },
1017
+ forget: {
1018
+ args: [
1019
+ a('id', 'M-7', {
1020
+ kind: id,
1021
+ need: false
1022
+ }),
1023
+ a('--cascade', '--cascade', {
1024
+ need: false
1025
+ })
1026
+ ],
1027
+ about: 'tombstone a memory (delete, said for memories)',
1028
+ run: del
1029
+ },
1030
+ // New, started from where you stand, as the entity menu starts it: a
1031
+ // blank one of the same components, or one made inside this.
1032
+ like: {
1033
+ args: [],
1034
+ about: 'start a new entity made of the same components as this one',
1035
+ words: [
1036
+ 0,
1037
+ 0
1038
+ ],
1039
+ run: (_, ctx)=>{
1040
+ let r = here(ctx);
1041
+ return {
1042
+ page: newPath({
1043
+ like: idOf(r)
1044
+ }),
1045
+ msg: `new like ${idOf(r)}`
1046
+ };
1047
+ }
1048
+ },
1049
+ child: {
1050
+ args: [],
1051
+ about: 'start a new entity inside this one, or an outline of them',
1052
+ words: [
1053
+ 0,
1054
+ 0
1055
+ ],
1056
+ run: (_, ctx)=>{
1057
+ let r = here(ctx);
1058
+ return {
1059
+ page: newPath({
1060
+ in: idOf(r)
1061
+ }),
1062
+ msg: `new in ${idOf(r)}`
1063
+ };
1064
+ }
1065
+ },
1066
+ task: card('task'),
1067
+ session: card('session'),
1068
+ doc: card('doc'),
1069
+ memory: card('memory')
1070
+ };
1071
+ export let run = (line, ctx, local = {})=>{
1072
+ let [, name, rest] = line.trim().match(/^(\S+)\s*(.*)$/s) ?? [];
1073
+ if (!name) return {};
1074
+ let v = {
1075
+ ...commands,
1076
+ ...local
1077
+ }[name];
1078
+ if (!v) throw new Error(`not a command: ${name}`);
1079
+ let words = (rest ?? '').trim().split(/\s+/).filter(Boolean).length;
1080
+ if (v.words && (words < v.words[0] || words > v.words[1])) {
1081
+ throw new Error(`${name}: usage :${`${name} ${slotsOf(v.args)}`.trim()} ` + `(got ${words} argument${words == 1 ? '' : 's'})`);
1082
+ }
1083
+ return v.run(rest ?? '', ctx);
1084
+ };
1085
+ // The order in a piece of writing: only the FIRST line commands, and the
1086
+ // rest rides as prose, so `:fix` plus a paragraph of context is both the
1087
+ // order and the note. A leading space escapes it — prose that opens with
1088
+ // a colon is rare, and never indented by accident. The rule lives with
1089
+ // the vocabulary because both ends need it: the effect that RUNS a
1090
+ // comment's order, and the composer that completes one as it's typed.
1091
+ export let orderIn = (body)=>{
1092
+ let [first = ''] = body.split('\n');
1093
+ return /^:\S/.test(first) ? first.trim() : '';
1094
+ };
1095
+ // The door every non-typing caller enters by: the line with or without
1096
+ // its colon, and the changes deref'd — any reference a verb produced may
1097
+ // be a human id (T-3, P-19) or an alias (jeff), and client.ts resolves
1098
+ // them HERE rather than letting a miss fail as an FK later.
1099
+ //
1100
+ // No Ctx.read: this door is MCP over /mcp, where the caller's line is
1101
+ // spoken to the SERVER's process. `@/etc/passwd` there would read the
1102
+ // server's disk, not the caller's, so values stay literal — an MCP caller
1103
+ // passes a long body as a string (task_new/graph_apply take one whole).
1104
+ export let commandOut = (all, line, eid, session, graph)=>{
1105
+ let out = run(line.replace(/^:/, ''), {
1106
+ eid,
1107
+ rows: all,
1108
+ session,
1109
+ graph
1110
+ });
1111
+ if (!out.changes) return out;
1112
+ // Resolve the output's references — a verb may leave a human id in a ref
1113
+ // value (`:set .filed.project=P-19`). Over the db reader that resolution is a keyed
1114
+ // lookup, never a whole-graph corpus; over rows it reads what's in hand.
1115
+ let changes = graph ? derefWith((v, where, comp)=>!v || UUID.test(v) ? v : graph.need(v, where, comp).eid, out.changes) : derefChanges(all, out.changes);
1116
+ return {
1117
+ ...out,
1118
+ changes
1119
+ };
1120
+ };
1121
+ // Typeahead over the table: prefix matches lead (`:d` is to the point),
1122
+ // substring matches trail, both in table order. An empty line lists
1123
+ // everything — that's the menu.
1124
+ export let suggest = (line, all)=>{
1125
+ let name = line.trimStart().split(/\s/)[0] ?? '';
1126
+ let rows = Object.entries(all);
1127
+ if (!name) return rows;
1128
+ return [
1129
+ ...rows.filter(([n])=>n.startsWith(name)),
1130
+ ...rows.filter(([n])=>!n.startsWith(name) && n.includes(name))
1131
+ ];
1132
+ };
1133
+ // What one slot paints faded: its concrete sample if it has one, else the
1134
+ // metavar with a trailing `…` for a catch-all — `eg ?? name`, the teaching
1135
+ // half of the vocabulary (`jeff` reads faster than `<to>`).
1136
+ let ghostSlot = (arg)=>arg.eg ?? `${arg.name}${arg.rest ? '…' : ''}`;
1137
+ // What to paint faded past the caret: the best match's remaining letters
1138
+ // while the verb is still being typed; once it stands, the sample args it
1139
+ // hasn't been given yet — one Arg slot per typed word (T-12929), no longer
1140
+ // a regex over a prose example.
1141
+ export let ghost = (line, all)=>{
1142
+ let m = line.match(/^(\S+)(\s+(.*))?$/s);
1143
+ if (!m) return '';
1144
+ let [, name, spaced, rest] = m;
1145
+ if (!spaced) {
1146
+ let best = Object.keys(all).find((n)=>n.startsWith(name) && n != name);
1147
+ if (best) return best.slice(name.length);
1148
+ if (!all[name]) return '';
1149
+ }
1150
+ let cmd = all[name];
1151
+ if (!cmd?.args.length) return '';
1152
+ let typed = (rest ?? '').split(/\s+/).filter(Boolean).length;
1153
+ let left = cmd.args.slice(typed);
1154
+ if (!left.length) return '';
1155
+ return (/\s$/.test(line) ? '' : ' ') + left.map(ghostSlot).join(' ');
1156
+ };
1157
+ //# sourceMappingURL=commands.js.map