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