@bigmistqke/workpad 0.0.0-stage → 0.18.1
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 +21 -0
- package/README.md +781 -2
- package/bin/workpad.ts +1526 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/workpad.js +1202 -0
- package/dist/client/runtime.js +1194 -0
- package/dist/define.js +27 -0
- package/dist/plugins/alert/README.md +18 -0
- package/dist/plugins/alert/index.js +40 -0
- package/dist/plugins/alert/public/style.css +40 -0
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +63 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +32 -0
- package/dist/plugins/badge/index.js +28 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/README.md +81 -0
- package/dist/plugins/chat/index.js +96 -0
- package/dist/plugins/chat/public/client.js +3 -0
- package/dist/plugins/chat/public/style.css +143 -0
- package/dist/plugins/claude/README.md +116 -0
- package/dist/plugins/claude/channel.js +130 -0
- package/dist/plugins/claude/doctor.js +316 -0
- package/dist/plugins/claude/index.js +199 -0
- package/dist/plugins/claude/session.js +68 -0
- package/dist/plugins/code/README.md +54 -0
- package/dist/plugins/code/diff.js +75 -0
- package/dist/plugins/code/index.js +105 -0
- package/dist/plugins/code/public/client.js +1 -0
- package/dist/plugins/code/public/style.css +99 -0
- package/dist/plugins/comments/README.md +30 -0
- package/dist/plugins/comments/index.js +39 -0
- package/dist/plugins/comments/public/client.js +24 -0
- package/dist/plugins/comments/public/style.css +224 -0
- package/dist/plugins/details/README.md +24 -0
- package/dist/plugins/details/index.js +28 -0
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +27 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/forge/README.md +22 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/form/README.md +126 -0
- package/dist/plugins/form/index.js +179 -0
- package/dist/plugins/form/public/style.css +172 -0
- package/dist/plugins/grid/README.md +45 -0
- package/dist/plugins/grid/index.js +35 -0
- package/dist/plugins/grid/public/style.css +98 -0
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/index.js +49 -0
- package/dist/plugins/iframe/public/style.css +28 -0
- package/dist/plugins/index.js +44 -0
- package/dist/plugins/lightbox/README.md +24 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +42 -0
- package/dist/plugins/mermaid/public/style.css +21 -0
- package/dist/plugins/opencode/README.md +48 -0
- package/dist/plugins/opencode/channel.js +92 -0
- package/dist/plugins/opencode/index.js +64 -0
- package/dist/plugins/opencode/shim.js +150 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +23 -0
- package/dist/plugins/tabs/README.md +44 -0
- package/dist/plugins/tabs/index.js +75 -0
- package/dist/plugins/tabs/public/client.js +1 -0
- package/dist/plugins/tabs/public/style.css +98 -0
- package/dist/plugins/terminal/README.md +63 -0
- package/dist/plugins/terminal/host.js +338 -0
- package/dist/plugins/terminal/index.js +170 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/public/client.js +41 -0
- package/dist/plugins/terminal/public/style.css +511 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +58 -0
- package/dist/plugins/timeline/README.md +48 -0
- package/dist/plugins/timeline/index.js +83 -0
- package/dist/plugins/timeline/public/style.css +138 -0
- package/dist/plugins/toc/README.md +40 -0
- package/dist/plugins/toc/index.js +29 -0
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +117 -0
- package/dist/plugins/window/README.md +51 -0
- package/dist/plugins/window/index.js +91 -0
- package/dist/solid/index.js +41 -0
- package/dist/src/agents.js +81 -0
- package/dist/src/anchors.js +52 -0
- package/dist/src/api.js +282 -0
- package/dist/src/archive.js +49 -0
- package/dist/src/auth.js +67 -0
- package/dist/src/build.js +159 -0
- package/dist/src/client/page/base.css +1762 -0
- package/dist/src/client/page/main.js +2121 -0
- package/dist/src/config.js +76 -0
- package/dist/src/document.js +93 -0
- package/dist/src/entries.js +264 -0
- package/dist/src/events.js +322 -0
- package/dist/src/files.js +47 -0
- package/dist/src/formstate.js +65 -0
- package/dist/src/help.js +213 -0
- package/dist/src/html.js +34 -0
- package/dist/src/hub.js +348 -0
- package/dist/src/icons.js +6 -0
- package/dist/src/listen.js +132 -0
- package/dist/src/listeners.js +64 -0
- package/dist/src/load.js +81 -0
- package/dist/src/loader.js +179 -0
- package/dist/src/migrate.js +314 -0
- package/dist/src/package.js +52 -0
- package/dist/src/pages/blocks.js +67 -0
- package/dist/src/pages/board.js +59 -0
- package/dist/src/pages/index.js +27 -0
- package/dist/src/pages/markdown.js +863 -0
- package/dist/src/pages/render.js +761 -0
- package/dist/src/pages/window.js +29 -0
- package/dist/src/plugins.js +283 -0
- package/dist/src/public.js +24 -0
- package/dist/src/rename.js +130 -0
- package/dist/src/running.js +146 -0
- package/dist/src/serve.js +188 -0
- package/dist/src/server.js +1105 -0
- package/dist/src/site.js +179 -0
- package/dist/src/state.js +155 -0
- package/dist/src/status.js +323 -0
- package/dist/src/thread.js +68 -0
- package/dist/src/watchdog.js +38 -0
- package/dist/src/ws.js +128 -0
- package/package.json +154 -4
- package/plugins/README.md +304 -0
- package/plugins/alert/README.md +18 -0
- package/plugins/alert/index.ts +50 -0
- package/plugins/alert/public/style.css +40 -0
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +32 -0
- package/plugins/badge/index.ts +36 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/README.md +81 -0
- package/plugins/chat/autosize.ts +139 -0
- package/plugins/chat/client.tsx +187 -0
- package/plugins/chat/index.ts +146 -0
- package/plugins/chat/public/style.css +143 -0
- package/plugins/claude/README.md +116 -0
- package/plugins/claude/channel.ts +136 -0
- package/plugins/claude/doctor.ts +274 -0
- package/plugins/claude/index.ts +248 -0
- package/plugins/claude/session.ts +70 -0
- package/plugins/code/README.md +54 -0
- package/plugins/code/client.ts +73 -0
- package/plugins/code/diff.ts +96 -0
- package/plugins/code/index.ts +136 -0
- package/plugins/code/public/style.css +99 -0
- package/plugins/comments/README.md +30 -0
- package/plugins/comments/client.ts +723 -0
- package/plugins/comments/index.ts +48 -0
- package/plugins/comments/public/style.css +224 -0
- package/plugins/details/README.md +24 -0
- package/plugins/details/index.ts +30 -0
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/README.md +22 -0
- package/plugins/forge/index.ts +84 -0
- package/plugins/form/README.md +126 -0
- package/plugins/form/index.ts +199 -0
- package/plugins/form/public/style.css +172 -0
- package/plugins/grid/README.md +45 -0
- package/plugins/grid/index.ts +41 -0
- package/plugins/grid/public/style.css +98 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/index.ts +53 -0
- package/plugins/iframe/public/style.css +28 -0
- package/plugins/index.ts +49 -0
- package/plugins/lightbox/README.md +24 -0
- package/plugins/lightbox/client.ts +109 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +46 -0
- package/plugins/mermaid/public/style.css +21 -0
- package/plugins/opencode/README.md +48 -0
- package/plugins/opencode/channel.ts +112 -0
- package/plugins/opencode/index.ts +91 -0
- package/plugins/opencode/shim.ts +166 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +28 -0
- package/plugins/tabs/README.md +44 -0
- package/plugins/tabs/client.ts +96 -0
- package/plugins/tabs/index.ts +103 -0
- package/plugins/tabs/public/style.css +98 -0
- package/plugins/terminal/README.md +63 -0
- package/plugins/terminal/client.ts +391 -0
- package/plugins/terminal/host.ts +434 -0
- package/plugins/terminal/index.ts +199 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +266 -0
- package/plugins/terminal/sizes.ts +72 -0
- package/plugins/timeline/README.md +48 -0
- package/plugins/timeline/index.ts +82 -0
- package/plugins/timeline/public/style.css +138 -0
- package/plugins/toc/README.md +40 -0
- package/plugins/toc/client.ts +236 -0
- package/plugins/toc/index.ts +55 -0
- package/plugins/toc/public/style.css +117 -0
- package/plugins/window/README.md +51 -0
- package/plugins/window/index.ts +92 -0
- package/skills/workpad/SKILL.md +592 -0
- package/solid/index.tsx +80 -0
- package/src/agents.ts +134 -0
- package/src/anchors.ts +85 -0
- package/src/api.ts +444 -0
- package/src/archive.ts +75 -0
- package/src/auth.ts +99 -0
- package/src/build.ts +213 -0
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +420 -0
- package/src/client/markdown.ts +147 -0
- package/src/client/page/base.css +1762 -0
- package/src/client/page/board.ts +166 -0
- package/src/client/page/elsewhere.ts +153 -0
- package/src/client/page/fresh.ts +343 -0
- package/src/client/page/heading-link.ts +32 -0
- package/src/client/page/live.ts +134 -0
- package/src/client/page/main.ts +398 -0
- package/src/client/page/orphans.ts +64 -0
- package/src/client/page/place.ts +260 -0
- package/src/client/page/sort.ts +49 -0
- package/src/client/page/sticky.ts +58 -0
- package/src/client/page/theme.ts +36 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +278 -0
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +111 -0
- package/src/client/runtime.ts +499 -0
- package/src/client/scroll.ts +90 -0
- package/src/client/toast.ts +99 -0
- package/src/config.ts +111 -0
- package/src/define.ts +997 -0
- package/src/document.ts +191 -0
- package/src/entries.ts +352 -0
- package/src/events.ts +463 -0
- package/src/files.ts +74 -0
- package/src/formstate.ts +72 -0
- package/src/help.ts +240 -0
- package/src/html.ts +44 -0
- package/src/hub.ts +435 -0
- package/src/icons.ts +18 -0
- package/src/listen.ts +171 -0
- package/src/listeners.ts +89 -0
- package/src/load.ts +113 -0
- package/src/loader.ts +227 -0
- package/src/migrate.ts +352 -0
- package/src/package.ts +62 -0
- package/src/pages/blocks.ts +106 -0
- package/src/pages/board.ts +89 -0
- package/src/pages/index.ts +79 -0
- package/src/pages/markdown.ts +976 -0
- package/src/pages/render.ts +845 -0
- package/src/pages/window.ts +69 -0
- package/src/plugins.ts +319 -0
- package/src/public.ts +39 -0
- package/src/rename.ts +147 -0
- package/src/running.ts +171 -0
- package/src/serve.ts +221 -0
- package/src/server.ts +1385 -0
- package/src/site.ts +170 -0
- package/src/state.ts +327 -0
- package/src/status.ts +466 -0
- package/src/thread.ts +98 -0
- package/src/watchdog.ts +53 -0
- package/src/ws.ts +155 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// The opencode plugin that `workpad opencode install` writes to the project's
|
|
2
|
+
// `.opencode/plugins/workpad.js`. opencode loads it into its own process (under Bun), so it
|
|
3
|
+
// holds no workpad of its own: it runs the project's workpad, as `command`, and only carries
|
|
4
|
+
// between the two what opencode tells a plugin and what it lets one do:
|
|
5
|
+
// - `shell.env`: each command the agent runs gets its session in `OPENCODE_SESSION_ID`, so
|
|
6
|
+
// `workpad new` subscribes it to the page; that session is followed from then on;
|
|
7
|
+
// - the channel (`workpad opencode channel`, one for the opencode process): told the sessions
|
|
8
|
+
// to follow, it says the pong for a `workpad agent ping` in one, and once the agent confirmed it
|
|
9
|
+
// each answer on its pages; these go into their session as a message once it is idle
|
|
10
|
+
// (`session.promptAsync`), with the agent and model its reader last used, and the channel marks
|
|
11
|
+
// the answers received once the message is in. At a turn's end it looks for new pages at once;
|
|
12
|
+
// - `session.idle`, with no answers to bring: `hook stop`; when something is left on its pages,
|
|
13
|
+
// the session goes on once with what to do about it, and a session already sent on shows the
|
|
14
|
+
// reader what is open (a toast) instead;
|
|
15
|
+
// - `chat.message`: the agent and model the reader used, and a message of the reader's lets the
|
|
16
|
+
// session be sent on again.
|
|
17
|
+
// What the plugin sends itself starts with its marker, so it is told apart from the reader's.
|
|
18
|
+
import { ANSWERS_NOTE } from '../../src/agents.ts'
|
|
19
|
+
|
|
20
|
+
/** The plugin's source, running workpad as `command` (`['npx', '@bigmistqke/workpad']`). */
|
|
21
|
+
export const shimSource = (command: string[]) => `// Installed by \`workpad opencode install\`, which writes it again; \`workpad opencode uninstall\` removes it.
|
|
22
|
+
// It brings the reader's answers on this opencode session's workpad pages into it, and sends a
|
|
23
|
+
// turn that ends with something left on them on once. See the opencode plugin of @bigmistqke/workpad.
|
|
24
|
+
import { spawn } from 'node:child_process'
|
|
25
|
+
import readline from 'node:readline'
|
|
26
|
+
|
|
27
|
+
const WORKPAD = ${JSON.stringify(command)}
|
|
28
|
+
const MARK = '[workpad]'
|
|
29
|
+
const ANSWERS_NOTE = ${JSON.stringify(ANSWERS_NOTE)}
|
|
30
|
+
|
|
31
|
+
export const Workpad = async ({ client, directory }) => {
|
|
32
|
+
const env = session => ({ ...process.env, ...(session ? { OPENCODE_SESSION_ID: session } : {}) })
|
|
33
|
+
|
|
34
|
+
/** Run a workpad opencode command for a session: what it printed ('' when it failed). */
|
|
35
|
+
const run = (args, session) =>
|
|
36
|
+
new Promise(resolve => {
|
|
37
|
+
const child = spawn(WORKPAD[0], [...WORKPAD.slice(1), 'opencode', ...args], {
|
|
38
|
+
cwd: directory,
|
|
39
|
+
env: env(session),
|
|
40
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
41
|
+
})
|
|
42
|
+
let out = ''
|
|
43
|
+
child.stdout.on('data', d => (out += d))
|
|
44
|
+
child.on('error', () => resolve(''))
|
|
45
|
+
child.on('close', code => resolve(code === 0 ? out.trim() : ''))
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const known = new Set() // sessions the channel follows
|
|
49
|
+
const busy = new Set() // sessions in a turn
|
|
50
|
+
const sentOn = new Set() // sessions a reminder sent on, until the reader writes again
|
|
51
|
+
const last = new Map() // the agent and model the reader last used, per session
|
|
52
|
+
const held = new Map() // answers waiting for their session to be idle
|
|
53
|
+
|
|
54
|
+
// the channel: one for this process, started on the first session there is
|
|
55
|
+
let channel = null
|
|
56
|
+
const tell = msg => channel?.stdin.write(JSON.stringify(msg) + '\\n')
|
|
57
|
+
const follow = session => {
|
|
58
|
+
if (!session || known.has(session)) return
|
|
59
|
+
known.add(session)
|
|
60
|
+
if (!channel) {
|
|
61
|
+
channel = spawn(WORKPAD[0], [...WORKPAD.slice(1), 'opencode', 'channel'], {
|
|
62
|
+
cwd: directory,
|
|
63
|
+
env: env(),
|
|
64
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
65
|
+
})
|
|
66
|
+
channel.on('error', () => (channel = null))
|
|
67
|
+
readline.createInterface({ input: channel.stdout }).on('line', line => {
|
|
68
|
+
let answer
|
|
69
|
+
try {
|
|
70
|
+
answer = JSON.parse(line)
|
|
71
|
+
} catch {
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
if (!answer.session) return
|
|
75
|
+
held.set(answer.session, [...(held.get(answer.session) ?? []), answer])
|
|
76
|
+
if (!busy.has(answer.session)) void bring(answer.session)
|
|
77
|
+
})
|
|
78
|
+
for (const s of known) tell({ follow: s })
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
tell({ follow: session })
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Send the session a message of the plugin's own; whether it went in. */
|
|
85
|
+
const send = async (session, text) => {
|
|
86
|
+
const { agent, model } = last.get(session) ?? {}
|
|
87
|
+
try {
|
|
88
|
+
const r = await client.session.promptAsync({
|
|
89
|
+
path: { id: session },
|
|
90
|
+
body: { ...(agent ? { agent } : {}), ...(model ? { model } : {}), parts: [{ type: 'text', text: MARK + ' ' + text }] },
|
|
91
|
+
})
|
|
92
|
+
return !r?.error
|
|
93
|
+
} catch {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The answers held for an idle session, as one message; whether there were any. */
|
|
99
|
+
const bring = async session => {
|
|
100
|
+
const answers = held.get(session)
|
|
101
|
+
if (!answers?.length) return false
|
|
102
|
+
held.delete(session)
|
|
103
|
+
busy.add(session)
|
|
104
|
+
const pongs = answers.filter(a => a.pong)
|
|
105
|
+
const real = answers.filter(a => !a.pong)
|
|
106
|
+
const text = [
|
|
107
|
+
...pongs.map(a => a.text),
|
|
108
|
+
...(real.length
|
|
109
|
+
? ['The reader answered on your workpad pages (received already):', ...real.map(a => '- ' + a.text), ANSWERS_NOTE]
|
|
110
|
+
: []),
|
|
111
|
+
].join('\\n')
|
|
112
|
+
if (await send(session, text)) {
|
|
113
|
+
if (real.length) tell({ session, received: real.map(a => a.id) })
|
|
114
|
+
} else held.set(session, [...answers, ...(held.get(session) ?? [])])
|
|
115
|
+
return true
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const toast = message =>
|
|
119
|
+
client.tui?.showToast?.({ body: { message, variant: 'info' } }).catch?.(() => {})
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
'shell.env': async (input, output) => {
|
|
123
|
+
if (!input.sessionID) return
|
|
124
|
+
output.env.OPENCODE_SESSION_ID = input.sessionID
|
|
125
|
+
busy.add(input.sessionID)
|
|
126
|
+
follow(input.sessionID)
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
'chat.message': async (input, output) => {
|
|
130
|
+
const session = input.sessionID
|
|
131
|
+
if (input.agent || input.model) last.set(session, { agent: input.agent, model: input.model })
|
|
132
|
+
busy.add(session)
|
|
133
|
+
if (output.parts.some(p => p.type === 'text' && p.text?.startsWith(MARK))) return
|
|
134
|
+
sentOn.delete(session)
|
|
135
|
+
follow(session)
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
event: async ({ event }) => {
|
|
139
|
+
const session = event.properties?.sessionID
|
|
140
|
+
if (!session) return
|
|
141
|
+
// a turn ends: opencode says so twice (session.status idle, session.idle), once is acted on
|
|
142
|
+
const idle =
|
|
143
|
+
event.type === 'session.idle' || (event.type === 'session.status' && event.properties.status?.type === 'idle')
|
|
144
|
+
if (event.type === 'session.status' && !idle) return void busy.add(session)
|
|
145
|
+
if (!idle || !busy.has(session)) return
|
|
146
|
+
busy.delete(session)
|
|
147
|
+
if (!known.has(session)) return
|
|
148
|
+
// pages it made this turn: the channel looks for them now, not at its next round
|
|
149
|
+
tell({ follow: session })
|
|
150
|
+
if (await bring(session)) return
|
|
151
|
+
const left = await run(['hook', 'stop'], session)
|
|
152
|
+
if (!left || busy.has(session)) return
|
|
153
|
+
let said
|
|
154
|
+
try {
|
|
155
|
+
said = JSON.parse(left)
|
|
156
|
+
} catch {
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
if (sentOn.has(session)) return void toast(said.shown)
|
|
160
|
+
sentOn.add(session)
|
|
161
|
+
busy.add(session)
|
|
162
|
+
if (!(await send(session, said.reason))) busy.delete(session)
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
`
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Content that is never marked as new. Changed blocks get a red bar until the
|
|
2
|
+
reader has seen them; what is inside `quiet` does not count as a change. Use
|
|
3
|
+
it for what changes without being news to the reader: repeating back what
|
|
4
|
+
they answered, a status line, a timestamp. Anything with substance (an
|
|
5
|
+
explanation, a question back, a different reading of their answer) belongs
|
|
6
|
+
outside it, so it is marked.
|
|
7
|
+
|
|
8
|
+
A whole block, a line, or a few words:
|
|
9
|
+
|
|
10
|
+
```markdown
|
|
11
|
+
:::quiet
|
|
12
|
+
Decided: **this week**, as you answered.
|
|
13
|
+
:::
|
|
14
|
+
|
|
15
|
+
::quiet[Last checked 12:04]
|
|
16
|
+
|
|
17
|
+
The build is green :quiet[(as of 12:04)].
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Inside a larger block, such as a card, only the quiet part is ignored: other
|
|
21
|
+
changes in the block still mark it. Hand-written HTML can do the same with a
|
|
22
|
+
`data-wp-quiet` attribute.
|
|
23
|
+
|
|
24
|
+
:::quiet
|
|
25
|
+
This block is quiet: editing it never marks it as new.
|
|
26
|
+
:::
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import { definePlugin, type Plugin } from '@bigmistqke/workpad'
|
|
3
|
+
// Content the new-content marking leaves alone: whatever is inside a quiet wrapper never marks its
|
|
4
|
+
// block as new, and a block that is quiet as a whole is never marked. For what changes without
|
|
5
|
+
// being news to the reader: an echo of their answer, a status line, a timestamp. The mechanism is
|
|
6
|
+
// the data-wp-quiet attribute, which any block or hand-written HTML can use as well.
|
|
7
|
+
import { html, raw, type DirectiveContext } from '@bigmistqke/workpad'
|
|
8
|
+
|
|
9
|
+
export async function render(ctx: DirectiveContext) {
|
|
10
|
+
// the label and content are HTML already
|
|
11
|
+
const label = ctx.label && raw(ctx.label)
|
|
12
|
+
if (ctx.kind === 'textDirective') return html`<span data-wp-quiet>${label}</span>`
|
|
13
|
+
if (ctx.kind === 'leafDirective') return html`<div data-wp-quiet>${label && html`<p>${label}</p>`}</div>`
|
|
14
|
+
return html`<div data-wp-quiet>${raw(await ctx.toHtml(ctx.children))}</div>`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function quiet(): Plugin {
|
|
18
|
+
return definePlugin({
|
|
19
|
+
name: 'quiet',
|
|
20
|
+
blocks: {
|
|
21
|
+
quiet: {
|
|
22
|
+
menu: { group: 'mark', summary: 'not news: an echo of an answer, a timestamp' },
|
|
23
|
+
html: render,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
27
|
+
})
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
One pane, its items as tabs, one showing at a time: an A/B, versions of a
|
|
2
|
+
design, the parts of an answer, a before and an after. It is a window, so ⤢
|
|
3
|
+
fills the browser window with it.
|
|
4
|
+
|
|
5
|
+
Each item is an `:::item[Title]` container, its label the tab's label;
|
|
6
|
+
without a label it is untitled, and its tab is its number. Inside an item,
|
|
7
|
+
headings of any level are its content. The tabs take one colon more than
|
|
8
|
+
their items: `::::tabs` around `:::item`. A `:::form[Title]` or a
|
|
9
|
+
`:::details[Title]` directly in it is an item as it is, its label the tab.
|
|
10
|
+
A row of tabs too long for the header scrolls sideways; ‹ › step through
|
|
11
|
+
the items, and so do ← and → when the block has the focus (a click in it)
|
|
12
|
+
or fills the window.
|
|
13
|
+
|
|
14
|
+
The items are laid over each other, so the pane is as tall as the tallest
|
|
15
|
+
and switching doesn't move the page. Which item shows stays when the page
|
|
16
|
+
updates, even when an item is added before it.
|
|
17
|
+
|
|
18
|
+
A link to an item, `#tab:<its title as a slug>` (`#tab:switch-the-reads`;
|
|
19
|
+
a badge or a `:when` in the title is not in it), or `#tab:<its number>` for an
|
|
20
|
+
untitled one, shows that item.
|
|
21
|
+
|
|
22
|
+
Attributes: `wide`, `height`.
|
|
23
|
+
|
|
24
|
+
```markdown
|
|
25
|
+
::::tabs[Two headers]
|
|
26
|
+
:::item[A]
|
|
27
|
+
The label on the left, the buttons on the right.
|
|
28
|
+
:::
|
|
29
|
+
|
|
30
|
+
:::item[B]
|
|
31
|
+
Everything centred.
|
|
32
|
+
:::
|
|
33
|
+
::::
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
::::tabs[Two headers]
|
|
37
|
+
:::item[A]
|
|
38
|
+
The label on the left, the buttons on the right.
|
|
39
|
+
:::
|
|
40
|
+
|
|
41
|
+
:::item[B]
|
|
42
|
+
Everything centred.
|
|
43
|
+
:::
|
|
44
|
+
::::
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Tabs in the browser: which item shows, by its tab, the ‹ › buttons and ← →, and kept across the
|
|
2
|
+
// page's updates (which write the block anew): the block by its place among the page's tabs, the item
|
|
3
|
+
// by its key (an item the agent adds before it doesn't move what you see). What it changes is state,
|
|
4
|
+
// which a block's signature leaves out (src/client/page/fresh.ts): data-wp-* marks, and the tabs'
|
|
5
|
+
// aria-selected and tabindex. Switching tabs is not a change to the page.
|
|
6
|
+
import type { Api, PageHandle, PluginMount } from '../../src/define'
|
|
7
|
+
|
|
8
|
+
const windows = () => [...document.querySelectorAll<HTMLElement>('#wp-main .wp-tabs-window')]
|
|
9
|
+
const items = (win: HTMLElement) => [
|
|
10
|
+
...win.querySelectorAll<HTMLElement>(':scope > .wp-window-body > .wp-tabs > .wp-tabs-item'),
|
|
11
|
+
]
|
|
12
|
+
const tabsOf = (win: HTMLElement) => [...win.querySelectorAll<HTMLElement>(':scope > .wp-window-bar .wp-tabs-tab')]
|
|
13
|
+
|
|
14
|
+
/** which item shows, by the block's place: its key (Item.key), so an item added before it keeps it showing, and where it was */
|
|
15
|
+
const at = new Map<number, { key: string | null; index: number }>()
|
|
16
|
+
|
|
17
|
+
/** Where the item it showed is now: the one with its key, else the same place. */
|
|
18
|
+
function current(win: HTMLElement, place: number): number {
|
|
19
|
+
const was = at.get(place)
|
|
20
|
+
if (!was) return 0
|
|
21
|
+
const byKey = was.key ? items(win).findIndex(item => item.dataset.key === was.key) : -1
|
|
22
|
+
return byKey >= 0 ? byKey : was.index
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function show(win: HTMLElement, place: number, i: number, focus = false) {
|
|
26
|
+
const all = items(win)
|
|
27
|
+
const n = Math.max(all.length, 1)
|
|
28
|
+
i = Math.min(Math.max(i, 0), n - 1)
|
|
29
|
+
at.set(place, { key: all[i]?.dataset.key ?? null, index: i })
|
|
30
|
+
win.setAttribute('data-wp-tab', String(i))
|
|
31
|
+
all.forEach((item, k) => item.toggleAttribute('data-wp-current', k === i))
|
|
32
|
+
const tabs = tabsOf(win)
|
|
33
|
+
tabs.forEach((tab, k) => {
|
|
34
|
+
tab.setAttribute('aria-selected', String(k === i))
|
|
35
|
+
// one tab in the page's tab order: the one showing (ARIA's roving tabindex)
|
|
36
|
+
tab.tabIndex = k === i ? 0 : -1
|
|
37
|
+
})
|
|
38
|
+
// the tab showing in view, in a row too long for the header: the row scrolls, never the page
|
|
39
|
+
const tab = tabs[i]
|
|
40
|
+
const row = tab?.parentElement
|
|
41
|
+
if (tab && row) {
|
|
42
|
+
if (tab.offsetLeft < row.scrollLeft) row.scrollLeft = tab.offsetLeft
|
|
43
|
+
else if (tab.offsetLeft + tab.offsetWidth > row.scrollLeft + row.clientWidth)
|
|
44
|
+
row.scrollLeft = tab.offsetLeft + tab.offsetWidth - row.clientWidth
|
|
45
|
+
}
|
|
46
|
+
if (focus) tabs[i]?.focus()
|
|
47
|
+
win.toggleAttribute('data-wp-first', i === 0)
|
|
48
|
+
win.toggleAttribute('data-wp-last', i === n - 1)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const apply = () => windows().forEach((win, place) => show(win, place, current(win, place)))
|
|
52
|
+
|
|
53
|
+
function step(win: HTMLElement, to: 'prev' | 'next' | number, focus = false) {
|
|
54
|
+
const place = windows().indexOf(win)
|
|
55
|
+
if (place < 0) return
|
|
56
|
+
const now = current(win, place)
|
|
57
|
+
show(win, place, to === 'prev' ? now - 1 : to === 'next' ? now + 1 : to, focus)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const typing = (el: Element | null) =>
|
|
61
|
+
!!el?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable="false"])')
|
|
62
|
+
|
|
63
|
+
let listening = false
|
|
64
|
+
const mount: PluginMount = (_el: HTMLElement, _handle: PageHandle, core: Api) => {
|
|
65
|
+
apply()
|
|
66
|
+
core.onRendered(apply)
|
|
67
|
+
if (listening) return
|
|
68
|
+
listening = true
|
|
69
|
+
document.addEventListener('click', e => {
|
|
70
|
+
const button = (e.target as Element).closest?.<HTMLElement>('[data-tabs]')
|
|
71
|
+
const win = button?.closest<HTMLElement>('.wp-tabs-window')
|
|
72
|
+
if (!button || !win) return
|
|
73
|
+
const to = button.dataset.tabs!
|
|
74
|
+
step(win, to === 'prev' || to === 'next' ? to : Number(to))
|
|
75
|
+
})
|
|
76
|
+
// a link to an item, or to something in one, that doesn't show: that item shows
|
|
77
|
+
document.addEventListener('wp-reveal', e => {
|
|
78
|
+
const item = (e.target as Element).closest?.<HTMLElement>('.wp-tabs-item')
|
|
79
|
+
const win = item?.closest<HTMLElement>('.wp-tabs-window')
|
|
80
|
+
if (item && win) step(win, items(win).indexOf(item))
|
|
81
|
+
})
|
|
82
|
+
document.addEventListener('keydown', e => {
|
|
83
|
+
if ((e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') || e.metaKey || e.ctrlKey || e.altKey) return
|
|
84
|
+
const target = e.target as Element
|
|
85
|
+
if (typing(target)) return
|
|
86
|
+
// the tabs that have the focus, or the one filling the window
|
|
87
|
+
const win =
|
|
88
|
+
target.closest?.<HTMLElement>('.wp-tabs-window') ??
|
|
89
|
+
document.querySelector<HTMLElement>('#wp-main .wp-tabs-window[data-wp-maximized]')
|
|
90
|
+
if (!win) return
|
|
91
|
+
e.preventDefault()
|
|
92
|
+
// on a tab, the focus moves with it, as ARIA's tabs do
|
|
93
|
+
step(win, e.key === 'ArrowLeft' ? 'prev' : 'next', target.matches?.('[role=tab]'))
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
export default mount
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Tabs: one pane, its items as tabs in the header, one showing at a time: an A/B, versions of a
|
|
2
|
+
// design, the parts of an answer. In a window (src/pages/window.ts), so it fills the browser window
|
|
3
|
+
// too. The items are laid over each other, so the pane is as tall as the tallest and switching
|
|
4
|
+
// doesn't move the page; which one shows is the browser's (client.ts), kept across the page's updates.
|
|
5
|
+
// Always tabs: an untitled item's tab is its number, and a row too long for the header scrolls.
|
|
6
|
+
// Marked up as ARIA's tabs (a tablist of tabs, each controlling its tabpanel), as HTML has none.
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import {
|
|
9
|
+
definePlugin,
|
|
10
|
+
html,
|
|
11
|
+
raw,
|
|
12
|
+
slugText,
|
|
13
|
+
windowFrame,
|
|
14
|
+
type DirectiveContext,
|
|
15
|
+
type Plugin,
|
|
16
|
+
} from '@bigmistqke/workpad'
|
|
17
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
18
|
+
|
|
19
|
+
/** A height in px (a bare number) or a CSS length; else none. */
|
|
20
|
+
const height = (value: string | undefined) =>
|
|
21
|
+
value && /^\d+(\.\d+)?$/.test(value)
|
|
22
|
+
? `${value}px`
|
|
23
|
+
: value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value)
|
|
24
|
+
? value
|
|
25
|
+
: undefined
|
|
26
|
+
|
|
27
|
+
const svg = (d: string) =>
|
|
28
|
+
raw(
|
|
29
|
+
`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`,
|
|
30
|
+
)
|
|
31
|
+
const PREV = svg('M10 3.5 5.5 8l4.5 4.5')
|
|
32
|
+
const NEXT = svg('M6 3.5 10.5 8 6 12.5')
|
|
33
|
+
|
|
34
|
+
export async function render(ctx: DirectiveContext) {
|
|
35
|
+
// one per item (DirectiveContext.items): an `:::item[Title]`, or a form or a details as it is
|
|
36
|
+
const items = await ctx.items()
|
|
37
|
+
// each item's panel has an id: #tab:<its title as a slug> (a repeat numbered, src/anchors.ts), an
|
|
38
|
+
// untitled one #tab:<its number>; its tab's is the panel's after wp- (not a place to link to)
|
|
39
|
+
const ids = items.map((item, i) => ctx.anchor('tab', item.text ? slugText(item.text) : String(i + 1), { numbered: true }))
|
|
40
|
+
const tabs = items.map(
|
|
41
|
+
(item, i) =>
|
|
42
|
+
html`<button
|
|
43
|
+
type="button"
|
|
44
|
+
role="tab"
|
|
45
|
+
class="wp-tabs-tab"
|
|
46
|
+
${ids[i] ? html`id="wp-${ids[i]}" aria-controls="${ids[i]}"` : ''}
|
|
47
|
+
aria-selected="${i === 0 ? 'true' : 'false'}"
|
|
48
|
+
tabindex="${i === 0 ? '0' : '-1'}"
|
|
49
|
+
data-tabs="${String(i)}"
|
|
50
|
+
>
|
|
51
|
+
${item.title ? raw(item.title) : String(i + 1)}
|
|
52
|
+
</button>`,
|
|
53
|
+
)
|
|
54
|
+
const controls = html`<span class="wp-tabs-nav">
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
class="wp-window-button wp-tabs-prev"
|
|
58
|
+
data-tabs="prev"
|
|
59
|
+
title="Previous (←)"
|
|
60
|
+
aria-label="Previous"
|
|
61
|
+
>
|
|
62
|
+
${PREV}
|
|
63
|
+
</button>
|
|
64
|
+
<span class="wp-tabs-list" role="tablist" ${ctx.label ? html`aria-label="${ctx.label}"` : ''}>${tabs}</span>
|
|
65
|
+
<button type="button" class="wp-window-button wp-tabs-next" data-tabs="next" title="Next (→)" aria-label="Next">
|
|
66
|
+
${NEXT}
|
|
67
|
+
</button>
|
|
68
|
+
</span>`
|
|
69
|
+
const body = html`<div class="wp-tabs" tabindex="0">
|
|
70
|
+
${items.map(
|
|
71
|
+
(item, i) =>
|
|
72
|
+
html`<section
|
|
73
|
+
class="wp-tabs-item"
|
|
74
|
+
role="tabpanel"
|
|
75
|
+
data-key="${item.key}"
|
|
76
|
+
${ids[i] ? html`id="${ids[i]}" aria-labelledby="wp-${ids[i]}"` : ''}
|
|
77
|
+
>
|
|
78
|
+
${raw(item.html)}
|
|
79
|
+
</section>`,
|
|
80
|
+
)}
|
|
81
|
+
</div>`
|
|
82
|
+
return windowFrame({
|
|
83
|
+
label: ctx.label,
|
|
84
|
+
className: 'wp-tabs-window',
|
|
85
|
+
controls,
|
|
86
|
+
wide: 'wide' in ctx.attrs,
|
|
87
|
+
height: height(ctx.attrs.height),
|
|
88
|
+
body,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default function tabs(): Plugin {
|
|
93
|
+
return definePlugin({
|
|
94
|
+
name: 'tabs',
|
|
95
|
+
public: builtinPublic('tabs'),
|
|
96
|
+
style: 'style.css',
|
|
97
|
+
setup: () => ({ client: 'client.js' }),
|
|
98
|
+
blocks: {
|
|
99
|
+
tabs: { attrs: ['wide', 'height'], html: render, menu: { group: 'arrange', summary: 'one at a time: versions, A/B, per harness' } },
|
|
100
|
+
},
|
|
101
|
+
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
102
|
+
})
|
|
103
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* Tabs (index.ts): the items over each other in one grid cell, so the pane is as tall as the
|
|
2
|
+
tallest; one shows. Before the browser marks one (data-wp-tab), the first. */
|
|
3
|
+
.wp-tabs {
|
|
4
|
+
display: grid;
|
|
5
|
+
outline: none;
|
|
6
|
+
}
|
|
7
|
+
.wp-tabs:focus-visible {
|
|
8
|
+
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
9
|
+
}
|
|
10
|
+
.wp-tabs > .wp-tabs-item {
|
|
11
|
+
grid-area: 1 / 1;
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
.wp-tabs > .wp-tabs-item > :first-child {
|
|
15
|
+
margin-top: 0;
|
|
16
|
+
}
|
|
17
|
+
.wp-tabs > .wp-tabs-item > :last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
.wp-tabs-window:not([data-wp-tab]) > .wp-window-body > .wp-tabs > .wp-tabs-item:not(:first-child),
|
|
21
|
+
.wp-tabs-window[data-wp-tab] > .wp-window-body > .wp-tabs > .wp-tabs-item:not([data-wp-current]) {
|
|
22
|
+
visibility: hidden;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* the header: ‹ A B C › ; the tabs share the bar with the label, and a row too long scrolls
|
|
26
|
+
sideways between ‹ and ›, its scrollbar hidden (the arrows and ← → step through it) */
|
|
27
|
+
.wp-tabs-nav {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: var(--space-2xs);
|
|
31
|
+
flex: 0 1 auto;
|
|
32
|
+
min-width: 0;
|
|
33
|
+
}
|
|
34
|
+
.wp-tabs-list {
|
|
35
|
+
/* positioned: its tabs' offsetLeft is measured from it (client.ts scrolls the one showing in) */
|
|
36
|
+
position: relative;
|
|
37
|
+
display: flex;
|
|
38
|
+
gap: var(--space-2xs);
|
|
39
|
+
min-width: 0;
|
|
40
|
+
overflow-x: auto;
|
|
41
|
+
scrollbar-width: none;
|
|
42
|
+
}
|
|
43
|
+
.wp-tabs-list::-webkit-scrollbar {
|
|
44
|
+
display: none;
|
|
45
|
+
}
|
|
46
|
+
.wp-tabs-tab {
|
|
47
|
+
flex: none;
|
|
48
|
+
font: var(--ui-tiny) / 1 var(--sans);
|
|
49
|
+
font-variant-numeric: tabular-nums;
|
|
50
|
+
color: var(--muted);
|
|
51
|
+
background: none;
|
|
52
|
+
border: var(--hairline) solid transparent;
|
|
53
|
+
border-radius: var(--radius-pill);
|
|
54
|
+
padding: var(--space-xs) var(--space-md);
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
white-space: nowrap;
|
|
57
|
+
}
|
|
58
|
+
.wp-tabs-tab > * {
|
|
59
|
+
margin: 0;
|
|
60
|
+
}
|
|
61
|
+
.wp-tabs-tab:hover {
|
|
62
|
+
color: var(--text);
|
|
63
|
+
background: color-mix(in srgb, var(--text) var(--tint-faint), transparent);
|
|
64
|
+
}
|
|
65
|
+
.wp-tabs-tab:focus-visible {
|
|
66
|
+
outline: 2px solid color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
67
|
+
outline-offset: -2px;
|
|
68
|
+
}
|
|
69
|
+
.wp-tabs-tab[aria-selected='true'] {
|
|
70
|
+
color: var(--accent);
|
|
71
|
+
border-color: color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
72
|
+
background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
|
|
73
|
+
}
|
|
74
|
+
.wp-tabs-window:not([data-wp-tab]) > .wp-window-bar .wp-tabs-prev,
|
|
75
|
+
.wp-tabs-window[data-wp-first] > .wp-window-bar .wp-tabs-prev,
|
|
76
|
+
.wp-tabs-window[data-wp-last] > .wp-window-bar .wp-tabs-next {
|
|
77
|
+
opacity: 0.35;
|
|
78
|
+
pointer-events: none;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* a badge ending a tab's label: after it, on its line (the renderer puts it first, for a title's
|
|
82
|
+
float, base.css: a tab is one line, never wrapping) */
|
|
83
|
+
.wp-tabs-tab:has(> .wp-title-end) {
|
|
84
|
+
display: inline-flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
gap: var(--space-xs);
|
|
87
|
+
}
|
|
88
|
+
.wp-tabs-tab > .wp-title-end {
|
|
89
|
+
float: none;
|
|
90
|
+
order: 1;
|
|
91
|
+
height: auto;
|
|
92
|
+
margin: 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* a form that is an item: its tab is its title, not shown again over it */
|
|
96
|
+
.wp-tabs-item > form.wp-form > .wp-form-title {
|
|
97
|
+
display: none;
|
|
98
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# A terminal on every page
|
|
2
|
+
|
|
3
|
+
The terminal is a plugin: add it to the config.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import terminal from '@bigmistqke/workpad/terminal'
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
plugins: [terminal()],
|
|
10
|
+
})
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`workpad terminal` prints a link that unlocks a terminal drawer at the
|
|
14
|
+
bottom of every page of the project, in that browser. Collapsed it's a bar;
|
|
15
|
+
open, it shows a terminal with tabs. Each tab is a session in a
|
|
16
|
+
pseudo-terminal, in a small host process of its own that the server starts.
|
|
17
|
+
So the sessions outlive the browser tab (switching pages, reloading or
|
|
18
|
+
opening a second browser tab shows the same ones) and the server: a
|
|
19
|
+
restarted server finds them where they were. The browser morphs the drawer
|
|
20
|
+
from one page into the next (a view transition across the page load), and
|
|
21
|
+
the server writes the current screens into each page, so it never shows
|
|
22
|
+
empty. Ctrl+\` opens and closes it.
|
|
23
|
+
|
|
24
|
+
Several browser windows can show the same tab. A tab has one size, the
|
|
25
|
+
size of the window you used last (opened the drawer, clicked or typed in
|
|
26
|
+
it); the others show it at that size, with a margin or cut off at the right,
|
|
27
|
+
until you use them.
|
|
28
|
+
|
|
29
|
+
Every tab is your shell. The tabs sit at the bar's right, "+" at its end
|
|
30
|
+
opens one, and "×" closes a tab and ends what runs in it. A tab started with
|
|
31
|
+
a program runs it inside your shell, and the shell takes over when it exits:
|
|
32
|
+
leaving `claude` leaves a prompt in the same tab, not a dead one. A tab whose
|
|
33
|
+
shell exited offers to start it again, as it was.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
workpad terminal [page] # the link that opens the drawer in this browser
|
|
37
|
+
workpad terminal --new # a new tab with the shell
|
|
38
|
+
workpad terminal -- <program> … # run a program in a new tab: -- claude --resume <id>
|
|
39
|
+
workpad terminal open <page> # show a page where the drawer you used last is
|
|
40
|
+
workpad terminal stop # end every tab and their host
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
An agent can show you a page: `workpad terminal open <page>` takes the
|
|
44
|
+
browser tab whose drawer you used last to that page, and the drawer comes
|
|
45
|
+
along. A program in a tab knows which tab it runs in (`WORKPAD_TERMINAL`)
|
|
46
|
+
and opens it where that tab's drawer is; without it, where you were last.
|
|
47
|
+
|
|
48
|
+
The terminal runs code, so it needs the project's token: `.workpad/token`,
|
|
49
|
+
made on first use and gitignored. The link (`/_/auth`) sets it as a cookie
|
|
50
|
+
that is only sent from the project's own pages, and requests from another
|
|
51
|
+
origin are refused. Any plugin can ask the core whether a request has it.
|
|
52
|
+
|
|
53
|
+
It needs `node-pty`, an optional dependency; without it the drawer says what
|
|
54
|
+
to install. The host listens on `.workpad/terminal/host.sock`, readable
|
|
55
|
+
by its owner only, and leaves ten minutes after the last tab's program ended.
|
|
56
|
+
|
|
57
|
+
The token keeps other websites out, not agents: it is in the project, and so
|
|
58
|
+
is the config the server runs. **workpad runs with the rights of whoever
|
|
59
|
+
started its server, and adds none**, so start the server where your agents
|
|
60
|
+
run. If they run in a sandbox, start it from inside that sandbox (an agent
|
|
61
|
+
running `workpad show` does); the terminal and everything else it starts
|
|
62
|
+
are then boxed in the same way. A server started outside the sandbox lets an
|
|
63
|
+
agent reach past it, through the terminal or simply by editing `config.ts`.
|