@bigmistqke/workpad 0.18.1 → 0.20.0
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/README.md +18 -9
- package/bin/workpad.ts +412 -58
- package/dist/bin/workpad.js +336 -46
- package/dist/client/runtime.js +141 -18
- package/dist/plugins/badge/README.md +59 -10
- package/dist/plugins/badge/index.js +130 -8
- package/dist/plugins/badge/public/style.css +132 -12
- package/dist/plugins/chat/README.md +7 -3
- package/dist/plugins/chat/index.js +8 -1
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +10 -0
- package/dist/plugins/claude/README.md +13 -5
- package/dist/plugins/claude/channel.js +47 -6
- package/dist/plugins/claude/doctor.js +43 -47
- package/dist/plugins/claude/index.js +24 -8
- package/dist/plugins/claude/session.js +46 -1
- package/dist/plugins/comments/README.md +2 -1
- package/dist/plugins/comments/index.js +2 -0
- package/dist/plugins/comments/public/client.js +6 -5
- package/dist/plugins/comments/public/style.css +9 -0
- package/dist/plugins/form/README.md +1 -1
- package/dist/plugins/index.js +3 -1
- package/dist/plugins/opencode/channel.js +43 -7
- package/dist/plugins/opencode/index.js +2 -0
- package/dist/plugins/progress/README.md +41 -0
- package/dist/plugins/progress/index.js +117 -0
- package/dist/plugins/progress/public/client.js +1 -0
- package/dist/plugins/progress/public/style.css +85 -0
- package/dist/plugins/progress/state.js +210 -0
- package/dist/solid/index.js +3 -1
- package/dist/src/agents.js +13 -4
- package/dist/src/anchors.js +25 -1
- package/dist/src/build.js +1 -1
- package/dist/src/client/page/base.css +48 -2
- package/dist/src/client/page/main.js +58 -30
- package/dist/src/document.js +6 -4
- package/dist/src/events.js +22 -11
- package/dist/src/help.js +59 -12
- package/dist/src/hub.js +69 -3
- package/dist/src/listen.js +36 -4
- package/dist/src/listeners.js +14 -4
- package/dist/src/loader.js +7 -2
- package/dist/src/migrate.js +1 -1
- package/dist/src/pages/board.js +9 -4
- package/dist/src/pages/index.js +2 -4
- package/dist/src/pages/markdown.js +50 -19
- package/dist/src/pages/render.js +17 -1
- package/dist/src/server.js +94 -18
- package/dist/src/set.js +99 -0
- package/dist/src/state.js +2 -1
- package/dist/src/status.js +57 -9
- package/dist/src/turns.js +41 -0
- package/package.json +11 -1
- package/plugins/README.md +3 -1
- package/plugins/badge/README.md +59 -10
- package/plugins/badge/index.ts +141 -8
- package/plugins/badge/public/style.css +132 -12
- package/plugins/chat/README.md +7 -3
- package/plugins/chat/client.tsx +20 -3
- package/plugins/chat/index.ts +10 -1
- package/plugins/chat/public/style.css +10 -0
- package/plugins/claude/README.md +13 -5
- package/plugins/claude/channel.ts +45 -7
- package/plugins/claude/doctor.ts +58 -39
- package/plugins/claude/index.ts +30 -8
- package/plugins/claude/session.ts +32 -0
- package/plugins/comments/README.md +2 -1
- package/plugins/comments/client.ts +19 -0
- package/plugins/comments/index.ts +7 -1
- package/plugins/comments/public/style.css +9 -0
- package/plugins/form/README.md +1 -1
- package/plugins/index.ts +2 -0
- package/plugins/opencode/channel.ts +44 -8
- package/plugins/opencode/index.ts +4 -0
- package/plugins/progress/README.md +41 -0
- package/plugins/progress/client.ts +172 -0
- package/plugins/progress/index.ts +166 -0
- package/plugins/progress/public/style.css +85 -0
- package/plugins/progress/state.ts +278 -0
- package/skills/workpad/SKILL.md +149 -18
- package/solid/index.tsx +6 -2
- package/src/agents.ts +24 -2
- package/src/anchors.ts +32 -0
- package/src/build.ts +1 -1
- package/src/client/delivery.ts +49 -0
- package/src/client/forms.ts +18 -11
- package/src/client/page/base.css +48 -2
- package/src/client/page/waiting.ts +45 -25
- package/src/client/read.ts +9 -5
- package/src/client/runtime.ts +7 -3
- package/src/client/toast.ts +27 -3
- package/src/define.ts +120 -9
- package/src/document.ts +19 -5
- package/src/events.ts +47 -6
- package/src/help.ts +58 -11
- package/src/hub.ts +80 -2
- package/src/listen.ts +47 -4
- package/src/listeners.ts +22 -1
- package/src/loader.ts +14 -4
- package/src/migrate.ts +1 -1
- package/src/pages/board.ts +12 -3
- package/src/pages/index.ts +8 -10
- package/src/pages/markdown.ts +59 -12
- package/src/pages/render.ts +20 -2
- package/src/server.ts +127 -19
- package/src/set.ts +118 -0
- package/src/state.ts +3 -0
- package/src/status.ts +115 -14
- package/src/turns.ts +56 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// Where each `:progress` stands, from the log alone: no Node and no DOM in it, so the server (the
|
|
2
|
+
// nudges), the command line (`workpad progress`, `workpad status`), the overview and the page in the
|
|
3
|
+
// browser all read the same thing.
|
|
4
|
+
//
|
|
5
|
+
// A progress is the latest `progress:update` of its page and id: `{ id, n, total, note, eta, state }`.
|
|
6
|
+
// A run starts at the first update after the last that ended one (done or failed), so a progress
|
|
7
|
+
// moved again after it ended runs again. It is stale while it runs and is past its ETA, or has had
|
|
8
|
+
// no update for STALE_AFTER; then the server appends a `progress:stale` nudge for the agent that
|
|
9
|
+
// last moved it, once, and again at most every NUDGE_EVERY while it stays stale.
|
|
10
|
+
import type { WpEvent } from '../../src/define.ts'
|
|
11
|
+
|
|
12
|
+
/** The event `workpad progress` appends: `{ id, n, total, note, eta, state }`. */
|
|
13
|
+
export const UPDATE = 'progress:update'
|
|
14
|
+
/**
|
|
15
|
+
* The server's nudge to the agent that last moved a stale progress: `{ id, to, nudge, since, at }`,
|
|
16
|
+
* `at` when it was due (the clock the server goes by, which a test sets).
|
|
17
|
+
*/
|
|
18
|
+
export const STALE = 'progress:stale'
|
|
19
|
+
|
|
20
|
+
/** Who the server's nudges say they are by (their `by`): no agent, so every agent is handed them. */
|
|
21
|
+
export const NUDGER = 'workpad'
|
|
22
|
+
|
|
23
|
+
export const MINUTE = 60_000
|
|
24
|
+
/** A running progress with no update this long is stale. */
|
|
25
|
+
export const STALE_AFTER = 15 * MINUTE
|
|
26
|
+
/** A stale progress is nudged again at most this often. */
|
|
27
|
+
export const NUDGE_EVERY = 15 * MINUTE
|
|
28
|
+
|
|
29
|
+
export type ProgressState = 'running' | 'done' | 'failed'
|
|
30
|
+
|
|
31
|
+
export interface Progress {
|
|
32
|
+
page: string
|
|
33
|
+
id: string
|
|
34
|
+
/** how far, out of `total`; both null for a progress without a count */
|
|
35
|
+
n: number | null
|
|
36
|
+
total: number | null
|
|
37
|
+
note: string
|
|
38
|
+
state: ProgressState
|
|
39
|
+
/** the time left the agent gave (`--eta`), in seconds from `ts`; null without one */
|
|
40
|
+
eta: number | null
|
|
41
|
+
/** when it last moved: the latest update's time */
|
|
42
|
+
ts: string
|
|
43
|
+
/** when its run started: the first update after the last one that ended a run */
|
|
44
|
+
started: string
|
|
45
|
+
/** the first update with a count in this run, for a rate when no ETA was given */
|
|
46
|
+
first: { n: number; ts: string } | null
|
|
47
|
+
/** the agent that last moved it, when the command line knew */
|
|
48
|
+
by: string | null
|
|
49
|
+
/** the latest update's id */
|
|
50
|
+
event: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A key for a progress across pages: its page and id. */
|
|
54
|
+
export const keyOf = (page: string, id: string) => `${page}\n${id}`
|
|
55
|
+
|
|
56
|
+
/** An id as written in `:progress{id=…}` and on the command line: letters, digits, `-` and `_`. */
|
|
57
|
+
export const isProgressId = (id: string) => /^[A-Za-z0-9_-]+$/.test(id)
|
|
58
|
+
|
|
59
|
+
/** `287/1413` (spaces and thousands separators allowed): the count and the total, or null. */
|
|
60
|
+
export function parseCount(s: string): { n: number; total: number } | null {
|
|
61
|
+
const m = /^\s*([\d,_]+)\s*\/\s*([\d,_]+)\s*$/.exec(s)
|
|
62
|
+
if (!m) return null
|
|
63
|
+
const n = Number(m[1]!.replace(/[,_]/g, ''))
|
|
64
|
+
const total = Number(m[2]!.replace(/[,_]/g, ''))
|
|
65
|
+
if (!Number.isFinite(n) || !Number.isFinite(total) || total <= 0 || n < 0) return null
|
|
66
|
+
return { n, total }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** `20m`, `90s`, `1h30m`, `2h`; a bare number is minutes. Seconds, or null when it isn't one. */
|
|
70
|
+
export function parseDuration(s: string): number | null {
|
|
71
|
+
const t = s.trim().toLowerCase()
|
|
72
|
+
if (/^\d+(\.\d+)?$/.test(t)) return Math.round(Number(t) * 60)
|
|
73
|
+
const re = /(\d+(?:\.\d+)?)\s*(h|hr|hours?|m|min|mins|minutes?|s|sec|secs|seconds?)/gy
|
|
74
|
+
let total = 0
|
|
75
|
+
let at = 0
|
|
76
|
+
let m: RegExpExecArray | null
|
|
77
|
+
while ((m = re.exec(t))) {
|
|
78
|
+
const unit = m[2]![0]
|
|
79
|
+
total += Number(m[1]) * (unit === 'h' ? 3600 : unit === 'm' ? 60 : 1)
|
|
80
|
+
at = re.lastIndex
|
|
81
|
+
while (t[at] === ' ') at++
|
|
82
|
+
re.lastIndex = at
|
|
83
|
+
}
|
|
84
|
+
return at === t.length && at > 0 ? Math.round(total) : null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** What `workpad progress <page> <id> …` says, after the page and id: the update's data, or why not. */
|
|
88
|
+
export function parseArgs(
|
|
89
|
+
args: string[],
|
|
90
|
+
eta?: string | null,
|
|
91
|
+
): { n: number | null; total: number | null; note: string; state: ProgressState; eta: number | null } {
|
|
92
|
+
const [first, ...rest] = args
|
|
93
|
+
if (first === undefined)
|
|
94
|
+
throw new Error('say how far: `<n>/<total> "<note>"`, `"<note>"`, `done "<note>"` or `failed "<note>"`')
|
|
95
|
+
let n: number | null = null
|
|
96
|
+
let total: number | null = null
|
|
97
|
+
let state: ProgressState = 'running'
|
|
98
|
+
let words = args
|
|
99
|
+
const count = parseCount(first)
|
|
100
|
+
if (count) {
|
|
101
|
+
;({ n, total } = count)
|
|
102
|
+
if (n > total) throw new Error(`${first}: the count is past its total`)
|
|
103
|
+
words = rest
|
|
104
|
+
if (n === total) state = 'done'
|
|
105
|
+
} else if (first === 'done' || first === 'failed') {
|
|
106
|
+
state = first
|
|
107
|
+
words = rest
|
|
108
|
+
}
|
|
109
|
+
let seconds: number | null = null
|
|
110
|
+
if (eta != null && eta !== '') {
|
|
111
|
+
seconds = parseDuration(eta)
|
|
112
|
+
if (seconds == null) throw new Error(`--eta ${eta}: a time such as 20m, 90s or 1h30m`)
|
|
113
|
+
}
|
|
114
|
+
return { n, total, note: words.join(' ').trim(), state, eta: state === 'running' ? seconds : null }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const num = (v: unknown): number | null => (typeof v === 'number' && Number.isFinite(v) ? v : null)
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Every progress in the log, by page and id (keyOf), each as its latest update says, with its run's
|
|
121
|
+
* start. `events` in the log's order.
|
|
122
|
+
*/
|
|
123
|
+
export function progressOf(events: WpEvent[]): Map<string, Progress> {
|
|
124
|
+
const out = new Map<string, Progress>()
|
|
125
|
+
for (const e of events) {
|
|
126
|
+
if (e.type !== UPDATE || e.from !== 'cli') continue
|
|
127
|
+
const d = e.data ?? {}
|
|
128
|
+
const id = typeof d.id === 'string' ? d.id : ''
|
|
129
|
+
if (!id) continue
|
|
130
|
+
const key = keyOf(e.page, id)
|
|
131
|
+
const before = out.get(key)
|
|
132
|
+
const state: ProgressState = d.state === 'done' || d.state === 'failed' ? d.state : 'running'
|
|
133
|
+
const n = num(d.n)
|
|
134
|
+
const total = num(d.total)
|
|
135
|
+
// a new run after one ended
|
|
136
|
+
const fresh = !before || before.state !== 'running'
|
|
137
|
+
const started = fresh ? e.ts : before.started
|
|
138
|
+
const first = fresh ? null : before.first
|
|
139
|
+
out.set(key, {
|
|
140
|
+
page: e.page,
|
|
141
|
+
id,
|
|
142
|
+
n,
|
|
143
|
+
total,
|
|
144
|
+
note: typeof d.note === 'string' ? d.note : '',
|
|
145
|
+
state,
|
|
146
|
+
eta: num(d.eta),
|
|
147
|
+
ts: e.ts,
|
|
148
|
+
started,
|
|
149
|
+
first: first ?? (n != null ? { n, ts: e.ts } : null),
|
|
150
|
+
by: e.by ?? null,
|
|
151
|
+
event: e.id,
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
return out
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The progresses of one page, in the order they first appeared. */
|
|
158
|
+
export const progressOn = (events: WpEvent[], page: string): Progress[] => [
|
|
159
|
+
...progressOf(events.filter(e => e.page === page)).values(),
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
/** The running ones of every page, the latest moved first. */
|
|
163
|
+
export const running = (events: WpEvent[]): Progress[] =>
|
|
164
|
+
[...progressOf(events).values()].filter(p => p.state === 'running').sort((a, b) => b.ts.localeCompare(a.ts))
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Milliseconds left, as the agent said (`--eta`), else as the rate since the run's first count
|
|
168
|
+
* says; null when neither can tell. Below zero: past it.
|
|
169
|
+
*/
|
|
170
|
+
export function timeLeft(p: Progress, now: number): number | null {
|
|
171
|
+
if (p.state !== 'running') return null
|
|
172
|
+
const at = Date.parse(p.ts)
|
|
173
|
+
if (p.eta != null) return at + p.eta * 1000 - now
|
|
174
|
+
if (p.n == null || p.total == null || !p.first || p.n <= p.first.n) return null
|
|
175
|
+
const rate = (p.n - p.first.n) / (at - Date.parse(p.first.ts))
|
|
176
|
+
if (!(rate > 0)) return null
|
|
177
|
+
return at + (p.total - p.n) / rate - now
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Is it stale at `now`: running, and past the ETA it was given, or without an update for `after`? */
|
|
181
|
+
export function isStale(p: Progress, now: number, after = STALE_AFTER): boolean {
|
|
182
|
+
if (p.state !== 'running') return false
|
|
183
|
+
if (now - Date.parse(p.ts) >= after) return true
|
|
184
|
+
return p.eta != null && Date.parse(p.ts) + p.eta * 1000 < now
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ---- words ------------------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
/** `1,413` */
|
|
190
|
+
export const thousands = (n: number) => n.toLocaleString('en-US')
|
|
191
|
+
|
|
192
|
+
/** `287 / 1,413`, or '' without a count. */
|
|
193
|
+
export const countText = (p: Pick<Progress, 'n' | 'total'>) =>
|
|
194
|
+
p.n != null && p.total != null ? `${thousands(p.n)} / ${thousands(p.total)}` : ''
|
|
195
|
+
|
|
196
|
+
/** A span of time in a few words: `40 s`, `2 min`, `1 h 20 min`. */
|
|
197
|
+
export function span(ms: number): string {
|
|
198
|
+
const s = Math.max(0, Math.round(ms / 1000))
|
|
199
|
+
if (s < 60) return `${s} s`
|
|
200
|
+
const min = Math.round(s / 60)
|
|
201
|
+
if (min < 60) return `${min} min`
|
|
202
|
+
const h = Math.floor(min / 60)
|
|
203
|
+
const rest = min % 60
|
|
204
|
+
return rest ? `${h} h ${rest} min` : `${h} h`
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** `just now`, `40 s ago`, `2 min ago`. */
|
|
208
|
+
export const ago = (ms: number) => (ms < 10_000 ? 'just now' : `${span(ms)} ago`)
|
|
209
|
+
|
|
210
|
+
/** `~20 min left`, or '' when it can't tell or is past it. */
|
|
211
|
+
export function leftText(p: Progress, now: number): string {
|
|
212
|
+
const left = timeLeft(p, now)
|
|
213
|
+
return left == null || left <= 0 ? '' : `~${span(left)} left`
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The line a progress is in words: `probe 287 / 1,413 · captures 3 and 4 · ~20 min left · 2 min ago`. */
|
|
217
|
+
export function line(p: Progress, now: number): string {
|
|
218
|
+
const parts = [[p.id, countText(p)].filter(Boolean).join(' ')]
|
|
219
|
+
if (p.state !== 'running') parts.push(p.state)
|
|
220
|
+
if (p.note) parts.push(p.note)
|
|
221
|
+
if (isStale(p, now)) parts.push(`no update for ${span(now - Date.parse(p.ts))}`)
|
|
222
|
+
else {
|
|
223
|
+
const left = leftText(p, now)
|
|
224
|
+
if (left) parts.push(left)
|
|
225
|
+
parts.push(ago(now - Date.parse(p.ts)))
|
|
226
|
+
}
|
|
227
|
+
return parts.join(' · ')
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// ---- nudges -----------------------------------------------------------------------------------
|
|
231
|
+
|
|
232
|
+
/** What the server appends for a stale progress, once due: an event's input. */
|
|
233
|
+
export interface Nudge {
|
|
234
|
+
page: string
|
|
235
|
+
type: typeof STALE
|
|
236
|
+
data: { id: string; to: string | null; nudge: string; since: string; at: string }
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The nudge for a stale progress, in words: what is stale, and what to run. */
|
|
240
|
+
export function nudgeText(p: Progress, now: number): string {
|
|
241
|
+
const how = [countText(p), p.note].filter(Boolean).join(', ')
|
|
242
|
+
return `${p.id} has had no update for ${span(now - Date.parse(p.ts))}${how ? ` (${how})` : ''}${
|
|
243
|
+
isStale(p, now) && p.eta != null && now - Date.parse(p.ts) < STALE_AFTER ? ', past its ETA' : ''
|
|
244
|
+
} → workpad progress ${p.page} ${p.id} …, or done/failed`
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The nudges due at `now`: one for each stale progress that has had none since it last moved, or
|
|
249
|
+
* whose latest is `every` old. The log is the only record, so a server that restarts keeps count.
|
|
250
|
+
*/
|
|
251
|
+
export function nudgesDue(
|
|
252
|
+
events: WpEvent[],
|
|
253
|
+
now: number,
|
|
254
|
+
{ staleAfter = STALE_AFTER, every = NUDGE_EVERY }: { staleAfter?: number; every?: number } = {},
|
|
255
|
+
): Nudge[] {
|
|
256
|
+
const last = new Map<string, number>()
|
|
257
|
+
for (const e of events)
|
|
258
|
+
if (e.type === STALE && e.by === NUDGER && typeof e.data?.id === 'string')
|
|
259
|
+
last.set(keyOf(e.page, e.data.id), Date.parse(typeof e.data.at === 'string' ? e.data.at : e.ts))
|
|
260
|
+
const out: Nudge[] = []
|
|
261
|
+
for (const p of progressOf(events).values()) {
|
|
262
|
+
if (!isStale(p, now, staleAfter)) continue
|
|
263
|
+
const before = last.get(keyOf(p.page, p.id))
|
|
264
|
+
// nudged since it last moved, and not long enough ago
|
|
265
|
+
if (before != null && before >= Date.parse(p.ts) && now - before < every) continue
|
|
266
|
+
out.push({
|
|
267
|
+
page: p.page,
|
|
268
|
+
type: STALE,
|
|
269
|
+
data: { id: p.id, to: p.by, nudge: nudgeText(p, now), since: p.ts, at: new Date(now).toISOString() },
|
|
270
|
+
})
|
|
271
|
+
}
|
|
272
|
+
return out
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** The nudges for `page` and `id` no agent marked handled: `workpad progress` handles them by moving it. */
|
|
276
|
+
export function openNudges(events: WpEvent[], page: string, id: string, handled: Set<string>): WpEvent[] {
|
|
277
|
+
return events.filter(e => e.type === STALE && e.page === page && e.data?.id === id && !handled.has(e.id))
|
|
278
|
+
}
|
package/skills/workpad/SKILL.md
CHANGED
|
@@ -33,10 +33,29 @@ them all.
|
|
|
33
33
|
`<topic>-2` and so on, and prints its path. That file is yours: other
|
|
34
34
|
agents may be writing pages in the same project, so never write a page you
|
|
35
35
|
did not get from `workpad new`, and never pick a page name yourself.
|
|
36
|
-
3. Write the page into that file
|
|
36
|
+
3. Write the page into that file with your file tools (Write, then Edit
|
|
37
|
+
for changes), never with a shell regex (`sed`, `perl`, `python -c`): a
|
|
38
|
+
pattern that misses leaves the page half-changed, and shell quoting
|
|
39
|
+
breaks markdown. For a message you `append`, build its JSON in a small
|
|
40
|
+
script file rather than quoting markdown inline.
|
|
37
41
|
4. Run `workpad show <file>`: it starts the project's server if needed and
|
|
38
42
|
prints the URL. Give the user the URL the first time; after that, just
|
|
39
|
-
keep editing the file — the open page follows.
|
|
43
|
+
keep editing the file — the open page follows. To replace one block
|
|
44
|
+
(a form, a heading's section, a chat), don't match its text with
|
|
45
|
+
`sed`, `perl` or a script: `workpad set <file> <anchor> --file -`
|
|
46
|
+
replaces the block that anchor names (`form:logger`, `open-questions`,
|
|
47
|
+
`chat:notes`) with the markdown on standard input, found by parsing the
|
|
48
|
+
page, and leaves the rest as it was:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
workpad set <file> '#open-questions' --file - <<'EOF'
|
|
52
|
+
## Open questions
|
|
53
|
+
|
|
54
|
+
None left.
|
|
55
|
+
EOF
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A name the page doesn't have exits 1, listing those it has. When the project is served
|
|
40
59
|
by the user's shared server and that isn't running, `show` says so and
|
|
41
60
|
starts nothing: tell the user, don't try to start it yourself (it is started outside your sandbox). Should a command say it `cannot read` workpad's config, your sandbox lacks a grant for it: tell the user, rather than working around it. A `listen` meanwhile still works: it waits
|
|
42
61
|
for the server, and answers in the log reach it either way.
|
|
@@ -44,7 +63,8 @@ them all.
|
|
|
44
63
|
is wrong as the page renders (a block nobody brings, a form's input
|
|
45
64
|
outside its form because a block inside it is one colon short, a
|
|
46
65
|
diagram that doesn't parse, an attribute a block doesn't read, a link to
|
|
47
|
-
an anchor that isn't there
|
|
66
|
+
an anchor that isn't there, on the page or on another page of the
|
|
67
|
+
project, with the nearest it has) and exits 1. Fix what it says before telling
|
|
48
68
|
the user the page is ready; the page shows the same above it. After
|
|
49
69
|
workpad is updated to a release that changed the syntax, `workpad
|
|
50
70
|
migrate` lists the pages written the old way and `workpad migrate
|
|
@@ -61,7 +81,8 @@ them all.
|
|
|
61
81
|
|
|
62
82
|
Never edit `.workpad/events.ndjson` yourself: an answer arriving while you
|
|
63
83
|
write it is lost, and running listens stumble over it. To change what you wrote
|
|
64
|
-
(a chat message, a reply), use `workpad edit <event id> --
|
|
84
|
+
(a chat message, a reply), use `workpad edit <event id> --text-file -` with
|
|
85
|
+
the new text on standard input (or `--data <json>` for other fields): it
|
|
65
86
|
merges into the event's data, keeps its id, and the open page shows the new
|
|
66
87
|
version. To clear a page's history and keep the page, `workpad prune
|
|
67
88
|
<file>` (all its events: its questions are open again), with `--type <type>`
|
|
@@ -80,6 +101,45 @@ sets `files: false`, as a project in the home folder does). Link to existing
|
|
|
80
101
|
documents and code from your pages with relative paths instead of copying
|
|
81
102
|
them.
|
|
82
103
|
|
|
104
|
+
### The syntax that is easy to get wrong
|
|
105
|
+
|
|
106
|
+
Blocks nest by colons: the outer block has one more than what it holds.
|
|
107
|
+
There is no block named after an attribute (`compose`, `cols`): put the
|
|
108
|
+
attribute on the block it changes. `workpad docs <block>` has the rest, and
|
|
109
|
+
`workpad check` names a block that doesn't exist.
|
|
110
|
+
|
|
111
|
+
````md
|
|
112
|
+
:::form{name=deploy} one decision, a distinct name
|
|
113
|
+
- :radio[Ship it]{name=go value=yes}
|
|
114
|
+
- :radio[Other]{name=go other} a text box for an answer you didn't list
|
|
115
|
+
- :checkbox[Android]{name=phones} several choices
|
|
116
|
+
:::
|
|
117
|
+
|
|
118
|
+
:::chat{name=notes} talk about one part of the page
|
|
119
|
+
:::
|
|
120
|
+
|
|
121
|
+
::::grid{cols=2} cards: each an :::item (or a :::form)
|
|
122
|
+
:::item[Parser :badge[done]]
|
|
123
|
+
…
|
|
124
|
+
:::
|
|
125
|
+
::::
|
|
126
|
+
|
|
127
|
+
::::grid{cols=2 compose=window title="Light and dark"} two images side by side, in a window
|
|
128
|
+
:::item[Light]
|
|
129
|
+

|
|
130
|
+
:::
|
|
131
|
+
:::item[Dark]
|
|
132
|
+

|
|
133
|
+
:::
|
|
134
|
+
::::
|
|
135
|
+
|
|
136
|
+
::image[The flow]{src="flow.png" compose=window}
|
|
137
|
+
```mermaid {compose=window title="How it's served"}
|
|
138
|
+
:::details[Why not MDX?] depth, folded
|
|
139
|
+
:::
|
|
140
|
+
:badge[you]{background=red} :badge[busy]{color=green live}
|
|
141
|
+
````
|
|
142
|
+
|
|
83
143
|
### Show, don't tell
|
|
84
144
|
|
|
85
145
|
Prose is good at what only prose does: a reason, a trade-off, a nuance,
|
|
@@ -128,8 +188,11 @@ same turn, before you end it:
|
|
|
128
188
|
version: the reader would have to work out which one holds.
|
|
129
189
|
- **Close the questions it made moot**: say in its chat what settled it,
|
|
130
190
|
then `workpad settle <file> <form>`; or, when it waits on something
|
|
131
|
-
else, `workpad hold <file> <form> "<what it waits for>"`.
|
|
132
|
-
|
|
191
|
+
else, `workpad hold <file> <form> "<what it waits for>"`. To settle it
|
|
192
|
+
and put the decision in the form's place in one step:
|
|
193
|
+
`workpad settle <file> <form> --replace-with -`, the decided line
|
|
194
|
+
(`**Decided:** …`) on standard input. Take a form's chat off the page for
|
|
195
|
+
good with `workpad chat prune`.
|
|
133
196
|
- **Re-cut the outline** to the design as it is now: decided things read as
|
|
134
197
|
decisions, open ones as questions, and sections that argue with each
|
|
135
198
|
other become one. A page whose shape is the order of the conversation
|
|
@@ -141,10 +204,37 @@ same turn, before you end it:
|
|
|
141
204
|
Keep every fact, as above: only where it sits changes. In your reply in the
|
|
142
205
|
chat, link the section you changed instead of retelling it.
|
|
143
206
|
|
|
207
|
+
### While long work runs
|
|
208
|
+
|
|
209
|
+
When work takes more than a few minutes (a test run, a build, a batch),
|
|
210
|
+
put a `:progress{id=…}` where the page talks about it, and move it as the
|
|
211
|
+
work goes, without editing the page:
|
|
212
|
+
|
|
213
|
+
```sh
|
|
214
|
+
workpad progress <file> probe 287/1413 "captures 3 and 4" --eta 20m
|
|
215
|
+
workpad progress <file> probe "building the stack" # no count
|
|
216
|
+
workpad progress <file> probe done "all 287 checked" # or n = total
|
|
217
|
+
workpad progress <file> probe failed "Docker ran out of disk"
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The user sees it live on the page and in its corner, so they don't have to
|
|
221
|
+
ask how far it is. End it, `done` or `failed`, when the work ends. One
|
|
222
|
+
without an update for 15 minutes, or past its `--eta`, goes stale, and you
|
|
223
|
+
get a nudge (through your channel, or from `listen --wait`): move it, or
|
|
224
|
+
end it. `workpad status` lists what runs.
|
|
225
|
+
|
|
144
226
|
### Write for a reader who comes back later
|
|
145
227
|
|
|
146
|
-
-
|
|
147
|
-
|
|
228
|
+
- Start with a TL;DR: two or three lines saying where things stand and what
|
|
229
|
+
you need from the reader, each need linked to its form. Then the state of
|
|
230
|
+
things; put depth in `:::details[…]` blocks so the page stays scannable.
|
|
231
|
+
- Keep a page short enough to read in one go. Past about 1,000 words, split
|
|
232
|
+
it: a short page with the state and the questions, linking to pages for
|
|
233
|
+
the depth. A reader who calls a page "unreadable" or "too much noise"
|
|
234
|
+
doesn't come back to it.
|
|
235
|
+
- Every question for the reader goes in a form on a page, never only in the
|
|
236
|
+
terminal or a chat message, so it shows where the reader looks for what
|
|
237
|
+
waits on them.
|
|
148
238
|
- Update your page rather than starting a new one for the same topic; changed
|
|
149
239
|
blocks are highlighted for the user, unchanged ones stay quiet.
|
|
150
240
|
- Put the things you need from the user in forms, one form per decision, each
|
|
@@ -162,8 +252,17 @@ chat, link the section you changed instead of retelling it.
|
|
|
162
252
|
for it, `:radio[Other]{name=… other}`: it has a text box, and sends what
|
|
163
253
|
they typed.
|
|
164
254
|
- Every page ends with a chat, `page`, where the user asks what is about
|
|
165
|
-
none of its questions: answer there as in any chat
|
|
166
|
-
|
|
255
|
+
none of its questions: answer there as in any chat. Pass your reply's
|
|
256
|
+
markdown on standard input, never inside `--data` (shell quoting breaks
|
|
257
|
+
on quotes, backticks and `$`):
|
|
258
|
+
|
|
259
|
+
```sh
|
|
260
|
+
workpad append --page <file> --type chat:message --data '{"chat":"page"}' --text-file - <<'EOF'
|
|
261
|
+
Your reply, in **markdown**: `code`, "quotes" and $ are safe here.
|
|
262
|
+
EOF
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
For talk about one part of a
|
|
167
266
|
page, put a chat there: `:::chat{name=…}`, in its section. It is the same
|
|
168
267
|
chat as under a form, without the question.
|
|
169
268
|
- Your chat messages are small pages: write them as you write a page, with
|
|
@@ -172,8 +271,8 @@ chat, link the section you changed instead of retelling it.
|
|
|
172
271
|
a form in your message: `:::form{name=scope}` in the chat `logger` is the
|
|
173
272
|
question `logger/scope`, listened for and handled like one on the page. A
|
|
174
273
|
form with a single `:button[…]` is a one-press answer. Rework a message
|
|
175
|
-
with `workpad edit <id> --
|
|
176
|
-
answers while it keeps its name.
|
|
274
|
+
with `workpad edit <id> --text-file -` (the new text on standard input);
|
|
275
|
+
its form keeps its answers while it keeps its name.
|
|
177
276
|
- When a question is settled without its form (a chat reached the answer,
|
|
178
277
|
the design moved past it), settle it, so it doesn't stay "unanswered" for
|
|
179
278
|
good: say in its chat what settled it, then `workpad settle <file>
|
|
@@ -224,6 +323,15 @@ Start on them? :button[Start it]
|
|
|
224
323
|
::::
|
|
225
324
|
```
|
|
226
325
|
|
|
326
|
+
**Badges:** `:badge[word]` is a status in a word, a grey dot before it.
|
|
327
|
+
`color`, `background` and `border` take a palette name (red orange yellow
|
|
328
|
+
green blue violet pink grey), each off unless set: `{background=red}` is a
|
|
329
|
+
red pill, its text made readable; `live` pulses the dot. The project's
|
|
330
|
+
presets (`workpad docs badge` lists them) give a word its look
|
|
331
|
+
(`:badge[you]`), or a badge names one (`{preset=person}`); built-in words
|
|
332
|
+
like `done` and `blocked` are presets too. The badge's own attributes win
|
|
333
|
+
over its `preset=`, which wins over its word's.
|
|
334
|
+
|
|
227
335
|
**Nesting containers:** the outer fence needs more colons than anything
|
|
228
336
|
inside it, `::::grid` around `:::item`. A `:::` closes the first open
|
|
229
337
|
container whose fence is no longer than its own, so with equal colons the
|
|
@@ -417,6 +525,12 @@ you a page that already exists, listen on it once and it is yours too (with
|
|
|
417
525
|
a confirmed channel, `workpad listen --channel --page <file>`, which
|
|
418
526
|
exits at once). Never make a copy of it with `workpad new` instead.
|
|
419
527
|
|
|
528
|
+
A page someone else writes for you (a helper agent, a script that exits)
|
|
529
|
+
must have a follower before its link goes to the reader: an answer on a
|
|
530
|
+
page nobody follows reaches nobody. Take it on yourself (`workpad listen
|
|
531
|
+
--channel --page <file>`), or make sure a coordinator's `workpad listen
|
|
532
|
+
--unfollowed` covers it.
|
|
533
|
+
|
|
420
534
|
### Answers come to you
|
|
421
535
|
|
|
422
536
|
A project can have a plugin for your agent program (Claude Code, opencode)
|
|
@@ -446,9 +560,11 @@ ping and then just wait for a pong that may not come.
|
|
|
446
560
|
comes. Other agents' messages from before that someone already received
|
|
447
561
|
are skipped; it says how many, and `workpad listen --wait --page
|
|
448
562
|
<file>` hands them to you when you want to catch up. Once you confirmed,
|
|
449
|
-
the background ping ends (exit 0).
|
|
450
|
-
|
|
451
|
-
|
|
563
|
+
the background ping ends (exit 0). It keeps waiting while your turn
|
|
564
|
+
runs, so work on as long as you need; no pong confirmed within two
|
|
565
|
+
minutes after your turn ended: it ends with exit 1, and that wakes you:
|
|
566
|
+
listen for them, below, and in Claude Code tell the user what `workpad
|
|
567
|
+
claude doctor` says is wrong.
|
|
452
568
|
|
|
453
569
|
The answers come as one line each: the page, what the user did, its id:
|
|
454
570
|
`plan: form scope: "Smaller" (id mwv…; …)`. Act on each, handle it, then
|
|
@@ -492,6 +608,15 @@ the user that nobody is listening and their answers wait.
|
|
|
492
608
|
(its folder) and `url`; act on it in that folder. Use it only when asked
|
|
493
609
|
to look after the whole board, and with a confirmed channel, take
|
|
494
610
|
`workpad listen --channel` instead.
|
|
611
|
+
- `workpad listen --unfollowed` is for a coordinator, so no page swallows
|
|
612
|
+
an answer: it takes only the pages no live session follows (its
|
|
613
|
+
session gone, parked, or with a channel never confirmed), across the
|
|
614
|
+
shared server's projects as above, and hands out the user's answers
|
|
615
|
+
there that no other agent received. A page drops out while its own
|
|
616
|
+
session listens again and joins when it goes; new pages join. What you
|
|
617
|
+
get counts as received; act on it in its project, or hand it on. It
|
|
618
|
+
takes `--wait` (re-run it after each) and, with a confirmed channel,
|
|
619
|
+
`--channel`.
|
|
495
620
|
- `workpad events --page <file> [--type <name>] [--last 1]` lists what was
|
|
496
621
|
submitted so far, for when you need the history rather than the next
|
|
497
622
|
answer. With `--follow` it then prints each new event as it comes, without
|
|
@@ -525,7 +650,7 @@ change that, so answers given while nobody listens wait in the log. So:
|
|
|
525
650
|
### Other agents on a board
|
|
526
651
|
|
|
527
652
|
Any number listen on a page, and each hears everything there: the user's
|
|
528
|
-
answers, and other agents' messages, never your own. So agents can work on
|
|
653
|
+
answers, and other agents' messages (each once), never your own. So agents can work on
|
|
529
654
|
one board together, talking in its chats as the user does. The green dot
|
|
530
655
|
in the page's header lists who listens (click it), and `workpad status`
|
|
531
656
|
names who is subscribed to each page.
|
|
@@ -535,14 +660,20 @@ handled already (`workpad thread <id>` shows who handled it, the page
|
|
|
535
660
|
says "decided"); leave one someone else handled, unless you have
|
|
536
661
|
something to add.
|
|
537
662
|
|
|
663
|
+
When you pass the reader's words to another agent, quote them as they
|
|
664
|
+
wrote them, with a link to where (`workpad url <page> <anchor>`), not your
|
|
665
|
+
summary: a paraphrase turns "min padding" into "grow toward the edges".
|
|
666
|
+
Going the other way, put another agent's terms in plain words before they
|
|
667
|
+
reach the reader.
|
|
668
|
+
|
|
538
669
|
### Status
|
|
539
670
|
|
|
540
671
|
`workpad status` lists, per page, who is subscribed to it, the questions
|
|
541
672
|
waiting for the user (no answer yet, or a listen asks for a new one), the
|
|
542
673
|
answers nobody received, the answers received and not handled (with
|
|
543
674
|
`workpad handled`), the chats waiting for a reply, and who is listening,
|
|
544
|
-
with the `listen` command that takes them
|
|
545
|
-
your inbox. Run it when you resume work, or when you're unsure what is
|
|
675
|
+
with the `listen` command that takes them, and the `:progress` running. It
|
|
676
|
+
covers every page: it is your inbox. Run it when you resume work, or when you're unsure what is
|
|
546
677
|
still open.
|
|
547
678
|
|
|
548
679
|
When `listen` hands you answers, it also says (on stderr) what is left on
|
package/solid/index.tsx
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// the api's events and theme as signals through context.
|
|
10
10
|
import { createContext, createSignal, onSettled, useContext, type Component } from 'solid-js'
|
|
11
11
|
import { render } from '@solidjs/web'
|
|
12
|
-
import type { ClientApi, FormStatus, Listener, Mount, Reactive, Theme, WpEvent } from '@bigmistqke/workpad'
|
|
12
|
+
import type { ClientApi, Delivery, FormStatus, Listener, Mount, Reactive, Theme, WpEvent } from '@bigmistqke/workpad'
|
|
13
13
|
|
|
14
14
|
export interface Workpad {
|
|
15
15
|
/** this page's id */
|
|
@@ -28,6 +28,8 @@ export interface Workpad {
|
|
|
28
28
|
forms(): FormStatus[]
|
|
29
29
|
/** the agent's messages the reader hasn't read. Reactive. */
|
|
30
30
|
unread(): WpEvent[]
|
|
31
|
+
/** where each of the reader's events for an agent went, by its id (see Api.delivery). Reactive. */
|
|
32
|
+
delivery(): ReadonlyMap<string, Delivery>
|
|
31
33
|
/** a message's markdown as HTML, rendered by the server (see Api.markdown) */
|
|
32
34
|
markdown: ClientApi['markdown']
|
|
33
35
|
/** an agent's chat message as a small page, rendered by the server (see Api.message) */
|
|
@@ -38,7 +40,7 @@ export interface Workpad {
|
|
|
38
40
|
|
|
39
41
|
const WorkpadContext = createContext<Workpad>()
|
|
40
42
|
|
|
41
|
-
/** The page's events, theme, listeners, forms
|
|
43
|
+
/** The page's events, theme, listeners, forms, unread messages and deliveries, as signals. Use inside a component passed to solid(). */
|
|
42
44
|
export const useWorkpad = (): Workpad => useContext(WorkpadContext)
|
|
43
45
|
|
|
44
46
|
/** Turn a Solid component into a template client: `export default solid(MyComponent)`. */
|
|
@@ -58,6 +60,7 @@ export function solid<Props extends object>(Component: Component<Props>): Mount<
|
|
|
58
60
|
const listeners = signal(api.listeners)
|
|
59
61
|
const forms = signal(api.forms)
|
|
60
62
|
const unread = signal(api.unread)
|
|
63
|
+
const delivery = signal(api.delivery)
|
|
61
64
|
const value: Workpad = {
|
|
62
65
|
page: api.page,
|
|
63
66
|
events,
|
|
@@ -67,6 +70,7 @@ export function solid<Props extends object>(Component: Component<Props>): Mount<
|
|
|
67
70
|
listeners,
|
|
68
71
|
forms,
|
|
69
72
|
unread,
|
|
73
|
+
delivery,
|
|
70
74
|
markdown: api.markdown,
|
|
71
75
|
message: api.message,
|
|
72
76
|
toast: api.toast,
|
package/src/agents.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { spawnSync } from 'node:child_process'
|
|
|
9
9
|
import type { CommandContext, PageStatus, WpEvent } from './define.ts'
|
|
10
10
|
import { CHAT_MESSAGE, fromReader, statusLines } from './status.ts'
|
|
11
11
|
import { read } from './events.ts'
|
|
12
|
+
import { isStale, line, running } from '../plugins/progress/state.ts'
|
|
12
13
|
|
|
13
14
|
const relFile = (file: string) => path.relative(process.cwd(), file) || file
|
|
14
15
|
|
|
@@ -61,13 +62,19 @@ export async function stopReminder(
|
|
|
61
62
|
}
|
|
62
63
|
})
|
|
63
64
|
const loose = mine.filter(p => p.unheard.length || p.unreceived.length || p.unhandled.length || p.awaitingReply.length)
|
|
64
|
-
|
|
65
|
+
// the session's progress gone stale (plugins/progress), on any page: it moved it last
|
|
66
|
+
const now = Date.now()
|
|
67
|
+
const stale = running(read(ctx.eventsFile).events).filter(p => p.by === session && isStale(p, now))
|
|
68
|
+
if (!loose.length && !stale.length) return null
|
|
65
69
|
// what is left, without the command line: the reason says what to do
|
|
66
70
|
const said = (p: PageStatus) =>
|
|
67
71
|
openOn(p, { waiting: false })
|
|
68
72
|
.filter(l => !l.startsWith('→'))
|
|
69
73
|
.join('; ')
|
|
70
|
-
const shown = `workpad: ${
|
|
74
|
+
const shown = `workpad: ${[
|
|
75
|
+
...loose.map(p => `${p.page}: ${said(p)}`),
|
|
76
|
+
...stale.map(p => `${p.page}: ${line(p, now)}`),
|
|
77
|
+
].join(' · ')}`
|
|
71
78
|
// what to do about each: wait for what nobody listens for, handle what it was given, reply in
|
|
72
79
|
// the chats waiting for it. Pages to wait on: one wait for all of them, said once at the end
|
|
73
80
|
const toWait = loose.filter(p => p.unheard.length || p.unreceived.length)
|
|
@@ -89,6 +96,12 @@ export async function stopReminder(
|
|
|
89
96
|
? [`Before ending your turn, ${PING} run one listen for these pages in the background: \`${waitOn(toWait)}\`.`]
|
|
90
97
|
: [],
|
|
91
98
|
)
|
|
99
|
+
.concat(
|
|
100
|
+
stale.map(
|
|
101
|
+
p =>
|
|
102
|
+
`Your progress ${p.id} on workpad page ${p.page} is stale (${line(p, now)}): move it (\`workpad progress ${p.page} ${p.id} <n>/<total> "<note>"\`), or end it with \`done\` or \`failed\`.`,
|
|
103
|
+
),
|
|
104
|
+
)
|
|
92
105
|
.join('\n')
|
|
93
106
|
return { reason, shown }
|
|
94
107
|
}
|
|
@@ -97,6 +110,8 @@ export async function stopReminder(
|
|
|
97
110
|
export function describe(e: WpEvent): string {
|
|
98
111
|
const d = (e.data ?? {}) as Record<string, unknown>
|
|
99
112
|
if (e.type === CHAT_MESSAGE) return `chat ${d.chat}: "${d.text}"`
|
|
113
|
+
// a nudge (a stale progress): it says itself what to do
|
|
114
|
+
if (typeof d.nudge === 'string') return d.nudge
|
|
100
115
|
if (e.type === 'comments:new') return `comment on "${d.quote ?? d.at ?? ''}": "${d.text}"`
|
|
101
116
|
// what was chosen or written; the button only when it is the answer itself (no fields)
|
|
102
117
|
const fields = Object.entries(d).filter(([, v]) => v !== '' && v != null && !(Array.isArray(v) && !v.length))
|
|
@@ -129,6 +144,13 @@ export const pong = (code: string) =>
|
|
|
129
144
|
export const answerLine = (e: WpEvent, again = false) =>
|
|
130
145
|
`${e.page}: ${describe(e)}${again ? ' (received before, not handled yet)' : ''} (id ${e.id}; \`workpad thread ${e.id}\` shows it with its question)`
|
|
131
146
|
|
|
147
|
+
/**
|
|
148
|
+
* An answer a channel brings from a page no one follows (`workpad listen --unfollowed --channel`):
|
|
149
|
+
* as answerLine, and under the shared server, the project it is in, where its commands run.
|
|
150
|
+
*/
|
|
151
|
+
export const unfollowedLine = (e: WpEvent, again: boolean, from: { project: string; url: string } | null) =>
|
|
152
|
+
`${answerLine(e, again)}, on a page no one follows${from ? `, in ${from.project} (${from.url}): run its workpad commands there` : ''}`
|
|
153
|
+
|
|
132
154
|
/** What to do about answers a channel brought: the same for every agent. */
|
|
133
155
|
export const ANSWERS_NOTE =
|
|
134
156
|
'Act on each as on an answer from `workpad listen`. Then handle it with one of: a reply in its chat (`workpad append`), when you have something to say; else `workpad handled <id>`. Nothing more is needed.'
|