@bigmistqke/workpad 0.0.0-stage → 0.18.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/LICENSE +21 -0
- package/README.md +781 -2
- package/bin/workpad.ts +1509 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/workpad.js +1190 -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 +2098 -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 +211 -0
- package/dist/src/html.js +34 -0
- package/dist/src/hub.js +341 -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 +665 -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 +588 -0
- package/solid/index.tsx +80 -0
- package/src/agents.ts +133 -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 +137 -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 +238 -0
- package/src/html.ts +44 -0
- package/src/hub.ts +426 -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 +748 -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,316 @@
|
|
|
1
|
+
import { claudePid, claudeProcess, recordedSession } from "./session.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
6
|
+
// plugins/claude/doctor.ts
|
|
7
|
+
const SERVER = "workpad";
|
|
8
|
+
const FLAG = "--dangerously-load-development-channels";
|
|
9
|
+
/** A JSON file, null when it isn't there, `undefined` when it can't be read or parsed (said in `why`). */
|
|
10
|
+
function readJson(file) {
|
|
11
|
+
if (!fs.existsSync(file)) return null;
|
|
12
|
+
try {
|
|
13
|
+
return { value: JSON.parse(fs.readFileSync(file, "utf8")) };
|
|
14
|
+
} catch (err) {
|
|
15
|
+
return {
|
|
16
|
+
value: void 0,
|
|
17
|
+
why: err.code ?? "not valid JSON"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** `$VAR` and `${VAR}` in a command as Claude Code expands them; CLAUDE_PROJECT_DIR is the project. */
|
|
22
|
+
function expand(s, env) {
|
|
23
|
+
return s.replace(/\$\{(\w+)\}|\$(\w+)/g, (_, a, b) => env[a ?? b] ?? "");
|
|
24
|
+
}
|
|
25
|
+
/** Start the channel's command, ask it to initialize, and stop it: whether it answered, or why not. */
|
|
26
|
+
function probe(command, args, cwd, env) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
let out = "";
|
|
29
|
+
let err = "";
|
|
30
|
+
const child = spawn(command, args, {
|
|
31
|
+
cwd,
|
|
32
|
+
env,
|
|
33
|
+
stdio: [
|
|
34
|
+
"pipe",
|
|
35
|
+
"pipe",
|
|
36
|
+
"pipe"
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
const done = (why) => {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
child.kill();
|
|
42
|
+
resolve(why);
|
|
43
|
+
};
|
|
44
|
+
const timer = setTimeout(() => done(`no answer to initialize within 15s${err ? `: ${err.trim().split("\n").at(-1)}` : ""}`), 15e3);
|
|
45
|
+
child.on("error", (e) => done(`it doesn't start: ${e.message}`));
|
|
46
|
+
child.on("exit", (code) => done(`it exited (${code}) before answering${err ? `: ${err.trim().split("\n").at(-1)}` : ""}`));
|
|
47
|
+
child.stderr.on("data", (d) => err += d);
|
|
48
|
+
child.stdout.on("data", (d) => {
|
|
49
|
+
out += d;
|
|
50
|
+
for (const line of out.split("\n")) try {
|
|
51
|
+
if (JSON.parse(line)?.result?.serverInfo?.name === SERVER) return done(null);
|
|
52
|
+
} catch {}
|
|
53
|
+
});
|
|
54
|
+
child.stdin.write(JSON.stringify({
|
|
55
|
+
jsonrpc: "2.0",
|
|
56
|
+
id: 1,
|
|
57
|
+
method: "initialize",
|
|
58
|
+
params: {
|
|
59
|
+
protocolVersion: "2025-06-18",
|
|
60
|
+
capabilities: {},
|
|
61
|
+
clientInfo: {
|
|
62
|
+
name: "workpad-doctor",
|
|
63
|
+
version: "1"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}) + "\n");
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** The main checkout of a git worktree, or null when `dir` is no worktree (or no repository). */
|
|
70
|
+
function mainCheckout(dir) {
|
|
71
|
+
const git = (...args) => spawnSync("git", [
|
|
72
|
+
"-C",
|
|
73
|
+
dir,
|
|
74
|
+
...args
|
|
75
|
+
], { encoding: "utf8" });
|
|
76
|
+
const common = git("rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
77
|
+
const own = git("rev-parse", "--path-format=absolute", "--git-dir");
|
|
78
|
+
if (common.status !== 0 || own.status !== 0) return null;
|
|
79
|
+
if (common.stdout.trim() === own.stdout.trim()) return null;
|
|
80
|
+
return path.dirname(common.stdout.trim());
|
|
81
|
+
}
|
|
82
|
+
/** Where Claude Code is told to use or not use the project's .mcp.json servers, and what each says of ours. */
|
|
83
|
+
function approvals(dir, home = os.homedir()) {
|
|
84
|
+
const files = [{
|
|
85
|
+
file: path.join(dir, ".claude", "settings.json"),
|
|
86
|
+
read: (v) => v
|
|
87
|
+
}, {
|
|
88
|
+
file: path.join(dir, ".claude", "settings.local.json"),
|
|
89
|
+
read: (v) => v
|
|
90
|
+
}];
|
|
91
|
+
const main = mainCheckout(dir);
|
|
92
|
+
if (main && !fs.existsSync(path.join(dir, ".claude", "settings.local.json"))) files.push({
|
|
93
|
+
file: path.join(main, ".claude", "settings.local.json"),
|
|
94
|
+
read: (v) => v
|
|
95
|
+
});
|
|
96
|
+
files.push({
|
|
97
|
+
file: path.join(home, ".claude", "settings.json"),
|
|
98
|
+
read: (v) => v
|
|
99
|
+
});
|
|
100
|
+
files.push({
|
|
101
|
+
file: path.join(home, ".claude.json"),
|
|
102
|
+
read: (v) => v?.projects?.[dir]
|
|
103
|
+
});
|
|
104
|
+
const lines = [];
|
|
105
|
+
let enabled = null;
|
|
106
|
+
const unreadable = [];
|
|
107
|
+
for (const { file, read } of files) {
|
|
108
|
+
const json = readJson(file);
|
|
109
|
+
if (!json) continue;
|
|
110
|
+
if (json.value === void 0) {
|
|
111
|
+
unreadable.push(`${file} (${json.why})`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const scope = read(json.value);
|
|
115
|
+
if (!scope) continue;
|
|
116
|
+
if (Array.isArray(scope.disabledMcpjsonServers) && scope.disabledMcpjsonServers.includes(SERVER)) lines.push({
|
|
117
|
+
mark: "fail",
|
|
118
|
+
text: `the server is disabled in ${file} (disabledMcpjsonServers)`,
|
|
119
|
+
fix: `remove "${SERVER}" from disabledMcpjsonServers there, then restart the session`
|
|
120
|
+
});
|
|
121
|
+
if (!enabled && (scope.enableAllProjectMcpServers === true || Array.isArray(scope.enabledMcpjsonServers) && scope.enabledMcpjsonServers.includes(SERVER))) enabled = file;
|
|
122
|
+
}
|
|
123
|
+
for (const file of unreadable) lines.push({
|
|
124
|
+
mark: "skip",
|
|
125
|
+
text: `couldn't read ${file}: a setting there isn't checked`
|
|
126
|
+
});
|
|
127
|
+
if (!lines.some((l) => l.mark === "fail")) lines.push(enabled ? {
|
|
128
|
+
mark: "ok",
|
|
129
|
+
text: `the server is enabled (${enabled}) and disabled nowhere`
|
|
130
|
+
} : {
|
|
131
|
+
mark: "fail",
|
|
132
|
+
text: "the server is approved nowhere: Claude Code asks \"New MCP server found\" at the next start, and an Esc there disables it",
|
|
133
|
+
fix: `answer "Use this MCP server", or add "enabledMcpjsonServers": ["${SERVER}"] to ${path.join(dir, ".claude", "settings.local.json")}`
|
|
134
|
+
});
|
|
135
|
+
return lines;
|
|
136
|
+
}
|
|
137
|
+
/** The claude process's command line and folder. */
|
|
138
|
+
function claudeLaunch(pid) {
|
|
139
|
+
const ps = spawnSync("ps", [
|
|
140
|
+
"-o",
|
|
141
|
+
"args=",
|
|
142
|
+
"-p",
|
|
143
|
+
String(pid)
|
|
144
|
+
], { encoding: "utf8" });
|
|
145
|
+
const lsof = spawnSync("lsof", [
|
|
146
|
+
"-a",
|
|
147
|
+
"-p",
|
|
148
|
+
String(pid),
|
|
149
|
+
"-d",
|
|
150
|
+
"cwd",
|
|
151
|
+
"-Fn"
|
|
152
|
+
], { encoding: "utf8" });
|
|
153
|
+
const cwd = lsof.status === 0 ? lsof.stdout.split("\n").find((l) => l.startsWith("n"))?.slice(1) ?? null : null;
|
|
154
|
+
return {
|
|
155
|
+
args: ps.status === 0 ? ps.stdout.trim() : null,
|
|
156
|
+
cwd
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** The workpad version a project pins (its package.json), and the one installed there, when it has them. */
|
|
160
|
+
function pinned(dir) {
|
|
161
|
+
const pkg = readJson(path.join(dir, "package.json"))?.value;
|
|
162
|
+
return {
|
|
163
|
+
pin: pkg?.dependencies?.["@bigmistqke/workpad"] ?? pkg?.devDependencies?.["@bigmistqke/workpad"] ?? null,
|
|
164
|
+
installed: readJson(path.join(dir, "node_modules", "@bigmistqke", "workpad", "package.json"))?.value?.version ?? null
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async function doctor(ctx) {
|
|
168
|
+
const dir = ctx.project.dir;
|
|
169
|
+
const lines = [];
|
|
170
|
+
const mcpFile = path.join(dir, ".mcp.json");
|
|
171
|
+
const mcp = readJson(mcpFile);
|
|
172
|
+
const entry = mcp?.value?.mcpServers?.[SERVER];
|
|
173
|
+
if (!mcp) lines.push({
|
|
174
|
+
mark: "fail",
|
|
175
|
+
text: `no ${mcpFile}`,
|
|
176
|
+
fix: "workpad claude install"
|
|
177
|
+
});
|
|
178
|
+
else if (mcp.value === void 0) lines.push({
|
|
179
|
+
mark: "fail",
|
|
180
|
+
text: `${mcpFile}: ${mcp.why}`,
|
|
181
|
+
fix: "fix the file"
|
|
182
|
+
});
|
|
183
|
+
else if (!entry?.command) lines.push({
|
|
184
|
+
mark: "fail",
|
|
185
|
+
text: `${mcpFile} has no "${SERVER}" server`,
|
|
186
|
+
fix: "workpad claude install"
|
|
187
|
+
});
|
|
188
|
+
else {
|
|
189
|
+
const env = {
|
|
190
|
+
...process.env,
|
|
191
|
+
CLAUDE_PROJECT_DIR: process.env.CLAUDE_PROJECT_DIR ?? dir,
|
|
192
|
+
...entry.env ?? {}
|
|
193
|
+
};
|
|
194
|
+
const why = await probe(expand(entry.command, env), (entry.args ?? []).map((a) => expand(a, env)), dir, env);
|
|
195
|
+
const shown = [entry.command, ...entry.args ?? []].join(" ");
|
|
196
|
+
lines.push(why ? {
|
|
197
|
+
mark: "fail",
|
|
198
|
+
text: `the channel's command in ${mcpFile} doesn't answer: ${why}`,
|
|
199
|
+
fix: `run it by hand to see why: ${shown}`
|
|
200
|
+
} : {
|
|
201
|
+
mark: "ok",
|
|
202
|
+
text: `${mcpFile} has the channel, and its command answers (${shown})`
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
lines.push(...approvals(dir));
|
|
206
|
+
const pid = claudePid();
|
|
207
|
+
const envSession = process.env.CLAUDE_CODE_SESSION_ID || null;
|
|
208
|
+
if (!pid) lines.push({
|
|
209
|
+
mark: "skip",
|
|
210
|
+
text: envSession ? "couldn't find the claude process (is ps permitted here?): its launch flag and folder are not checked" : "not run from a Claude Code session: its launch and channel are not checked"
|
|
211
|
+
});
|
|
212
|
+
else {
|
|
213
|
+
const { args, cwd } = claudeLaunch(pid);
|
|
214
|
+
if (args == null) lines.push({
|
|
215
|
+
mark: "skip",
|
|
216
|
+
text: `couldn't read the command line of claude (pid ${pid})`
|
|
217
|
+
});
|
|
218
|
+
else if (new RegExp(`${FLAG}(=|\\s+)\\S*server:${SERVER}\\b`).test(args)) lines.push({
|
|
219
|
+
mark: "ok",
|
|
220
|
+
text: `the session was started with ${FLAG} server:${SERVER}`
|
|
221
|
+
});
|
|
222
|
+
else lines.push({
|
|
223
|
+
mark: "fail",
|
|
224
|
+
text: `the session was started without ${FLAG} server:${SERVER}: Claude Code drops what the channel sends`,
|
|
225
|
+
fix: `restart it with: claude ${FLAG} server:${SERVER} (a resume or a restore keeps no flag it wasn't given)`
|
|
226
|
+
});
|
|
227
|
+
if (cwd == null) lines.push({
|
|
228
|
+
mark: "skip",
|
|
229
|
+
text: `couldn't read the folder claude (pid ${pid}) runs in`
|
|
230
|
+
});
|
|
231
|
+
else if (path.resolve(cwd) === dir) lines.push({
|
|
232
|
+
mark: "ok",
|
|
233
|
+
text: `the session runs in the project's folder`
|
|
234
|
+
});
|
|
235
|
+
else lines.push({
|
|
236
|
+
mark: "fail",
|
|
237
|
+
text: `the session runs in ${cwd}, not the project's folder: it doesn't see ${mcpFile}`,
|
|
238
|
+
fix: `start claude in ${dir}`
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
let stuckWhy = null;
|
|
242
|
+
const server = await ctx.running().catch((err) => (stuckWhy = err.message, null));
|
|
243
|
+
const { pin, installed } = pinned(dir);
|
|
244
|
+
if (stuckWhy) lines.push({
|
|
245
|
+
mark: "fail",
|
|
246
|
+
text: stuckWhy,
|
|
247
|
+
fix: "restart the server"
|
|
248
|
+
});
|
|
249
|
+
else if (!server) lines.push({
|
|
250
|
+
mark: "fail",
|
|
251
|
+
text: "the project's server isn't running",
|
|
252
|
+
fix: "workpad show <page> starts it; a shared server is started outside the sandboxes (workpad serve)"
|
|
253
|
+
});
|
|
254
|
+
else {
|
|
255
|
+
const expected = installed ?? ctx.version;
|
|
256
|
+
lines.push(server.version === expected ? {
|
|
257
|
+
mark: "ok",
|
|
258
|
+
text: `the server runs at ${server.base}, ${server.version}${pin ? ` (pinned ${pin})` : ""}`
|
|
259
|
+
} : {
|
|
260
|
+
mark: "fail",
|
|
261
|
+
text: `the server runs ${server.version}, the project ${installed ? `has ${installed} installed` : `runs ${ctx.version}`}${pin ? ` (pinned ${pin})` : ""}`,
|
|
262
|
+
fix: "restart the server so it runs the installed version"
|
|
263
|
+
});
|
|
264
|
+
const session = pid ? recordedSession(ctx.dataDir, claudeProcess()) ?? envSession : envSession;
|
|
265
|
+
if (pid && !session) lines.push({
|
|
266
|
+
mark: "fail",
|
|
267
|
+
text: "no session id: the hooks recorded none and CLAUDE_CODE_SESSION_ID is empty",
|
|
268
|
+
fix: "workpad claude install, then restart the session"
|
|
269
|
+
});
|
|
270
|
+
else if (session) {
|
|
271
|
+
const channels = await fetch(`${server.base}/api/channels`, {
|
|
272
|
+
headers: { "x-workpad-token": ctx.token },
|
|
273
|
+
signal: AbortSignal.timeout(5e3)
|
|
274
|
+
}).then((r) => r.ok ? r.json() : null).catch(() => null);
|
|
275
|
+
const mine = channels?.filter((c) => c.session === session) ?? [];
|
|
276
|
+
if (!channels) lines.push({
|
|
277
|
+
mark: "skip",
|
|
278
|
+
text: `the server doesn't list its channels (older than ${ctx.version}?)`
|
|
279
|
+
});
|
|
280
|
+
else if (!mine.length) lines.push({
|
|
281
|
+
mark: "fail",
|
|
282
|
+
text: `no channel holds a line for this session (${session}) at the server`,
|
|
283
|
+
fix: "restart the session with the flag; when it has one already, see .workpad/claude/channel.log"
|
|
284
|
+
});
|
|
285
|
+
else {
|
|
286
|
+
lines.push({
|
|
287
|
+
mark: "ok",
|
|
288
|
+
text: `a channel holds a line for this session (${session})`
|
|
289
|
+
});
|
|
290
|
+
lines.push(mine.some((c) => c.confirmed) ? {
|
|
291
|
+
mark: "ok",
|
|
292
|
+
text: "its ping was confirmed: what it pushes reaches the session"
|
|
293
|
+
} : {
|
|
294
|
+
mark: "fail",
|
|
295
|
+
text: "its ping was never confirmed: it listens on no page yet",
|
|
296
|
+
fix: "workpad agent ping, and confirm the pong it pushes"
|
|
297
|
+
});
|
|
298
|
+
const pages = (await ctx.status().catch(() => [])).filter((p) => p.subscribers.includes(session)).map((p) => p.page);
|
|
299
|
+
lines.push({
|
|
300
|
+
mark: "skip",
|
|
301
|
+
text: pages.length ? `it follows ${pages.length} page${pages.length > 1 ? "s" : ""}, those this session is subscribed to: ${pages.join(", ")}` : "it follows no page: only those this session made (workpad new) or listened on by name (listen --page) are its own"
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const sign = {
|
|
307
|
+
ok: "✓",
|
|
308
|
+
fail: "✗",
|
|
309
|
+
skip: "–"
|
|
310
|
+
};
|
|
311
|
+
for (const l of lines) console.log(`${sign[l.mark]} ${l.text}${l.fix ? `\n → ${l.fix}` : ""}`);
|
|
312
|
+
const failed = lines.filter((l) => l.mark === "fail").length;
|
|
313
|
+
console.log(failed ? `\n${failed} to fix.` : "\nThe channel has what it needs.");
|
|
314
|
+
if (failed) process.exitCode = 1;
|
|
315
|
+
}
|
|
316
|
+
export { approvals, doctor, expand, mainCheckout };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { identity, stopReminder, workpadCommand } from "../../src/agents.js";
|
|
2
|
+
import { read, receivedBy } from "../../src/events.js";
|
|
3
|
+
import { channel } from "./channel.js";
|
|
4
|
+
import { doctor } from "./doctor.js";
|
|
5
|
+
import { recordSession } from "./session.js";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
// plugins/claude/index.ts
|
|
9
|
+
/** The hooks install adds: each mode, and the event it runs on. */
|
|
10
|
+
const MODES = {
|
|
11
|
+
session: "SessionStart",
|
|
12
|
+
stop: "Stop"
|
|
13
|
+
};
|
|
14
|
+
/** A hook command of this plugin's, also one that runs workpad another way (`node …/workpad.ts`). */
|
|
15
|
+
const OURS = /\bworkpad(?:\.ts"?)? claude hook \w+/;
|
|
16
|
+
const ours = (command = "") => OURS.test(command);
|
|
17
|
+
function claude() {
|
|
18
|
+
return {
|
|
19
|
+
name: "claude",
|
|
20
|
+
session: () => process.env.CLAUDE_CODE_SESSION_ID || null,
|
|
21
|
+
commands: {
|
|
22
|
+
hook: {
|
|
23
|
+
description: "what Claude Code runs on an event: record the session for the channel; then session says nothing, and stop, when the session's pages have something left for the agent, continues the turn once",
|
|
24
|
+
args: "<session|stop>",
|
|
25
|
+
async run(ctx) {
|
|
26
|
+
const mode = ctx.positionals[0];
|
|
27
|
+
if (!mode || !(mode in MODES)) throw new Error(`usage: workpad claude hook <${Object.keys(MODES).join("|")}>`);
|
|
28
|
+
try {
|
|
29
|
+
await hook(ctx, mode);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(`workpad claude hook ${mode}: ${err.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
channel: {
|
|
36
|
+
description: "the MCP channel Claude Code starts with each session (with the development-channels flag): pushes the reader's answers on the session's pages into it",
|
|
37
|
+
run: channel
|
|
38
|
+
},
|
|
39
|
+
doctor: {
|
|
40
|
+
description: "check what the channel needs, a line each with what to do: the .mcp.json entry and its command, the server approved and disabled in no settings file, the session started with the channels flag in the project's folder, the server up at the project's version, a channel for this session, its ping confirmed",
|
|
41
|
+
run: doctor
|
|
42
|
+
},
|
|
43
|
+
install: {
|
|
44
|
+
description: "add the channel to this project's .mcp.json and its hooks to .claude/settings.json",
|
|
45
|
+
run: (ctx) => {
|
|
46
|
+
installChannel(ctx.project.dir);
|
|
47
|
+
installHooks(ctx.project.dir);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
uninstall: {
|
|
51
|
+
description: "take the channel and its hooks out of this project's settings again; other hooks, servers and settings stay",
|
|
52
|
+
run: (ctx) => {
|
|
53
|
+
uninstallChannel(ctx.project.dir);
|
|
54
|
+
uninstallHooks(ctx.project.dir);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** The JSON Claude Code passes a hook on its standard input, or nothing. */
|
|
61
|
+
function hookInput() {
|
|
62
|
+
if (process.stdin.isTTY) return {};
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(fs.readFileSync(0, "utf8") || "{}");
|
|
65
|
+
} catch {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function hook(ctx, mode) {
|
|
70
|
+
const input = hookInput();
|
|
71
|
+
if (input.session_id) recordSession(ctx.dataDir, input.session_id);
|
|
72
|
+
if (mode === "session") return;
|
|
73
|
+
const agent = identity(input.session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null);
|
|
74
|
+
const left = await stopReminder(ctx, agent, inFlight(ctx, agent, input.transcript_path));
|
|
75
|
+
if (!left) return;
|
|
76
|
+
if (input.stop_hook_active) return void console.log(JSON.stringify({ systemMessage: left.shown }));
|
|
77
|
+
console.log(JSON.stringify({ hookSpecificOutput: {
|
|
78
|
+
hookEventName: "Stop",
|
|
79
|
+
additionalContext: left.reason
|
|
80
|
+
} }));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The answers this agent received that its conversation doesn't hold yet: its channel sent them
|
|
84
|
+
* (marked received as it does), and Claude Code keeps a channel's message until the turn ends. Told
|
|
85
|
+
* apart by the transcript: an answer that reached the agent is in it, by its id (the channel's
|
|
86
|
+
* message names it). Without a transcript, none: better a reminder too many than one missed.
|
|
87
|
+
*/
|
|
88
|
+
function inFlight(ctx, agent, transcript) {
|
|
89
|
+
if (!agent || !transcript) return /* @__PURE__ */ new Set();
|
|
90
|
+
let text;
|
|
91
|
+
try {
|
|
92
|
+
text = fs.readFileSync(transcript, "utf8");
|
|
93
|
+
} catch {
|
|
94
|
+
return /* @__PURE__ */ new Set();
|
|
95
|
+
}
|
|
96
|
+
const received = receivedBy(read(ctx.eventsFile).events, agent);
|
|
97
|
+
return new Set([...received].filter((id) => !text.includes(id)));
|
|
98
|
+
}
|
|
99
|
+
/** A JSON file of Claude Code's settings ({} when there is none). */
|
|
100
|
+
function readJson(file) {
|
|
101
|
+
if (!fs.existsSync(file)) return {};
|
|
102
|
+
try {
|
|
103
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
104
|
+
} catch {
|
|
105
|
+
throw new Error(`${file} is not valid JSON; fix it first`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Write it in one rename; one left empty goes. */
|
|
109
|
+
function writeJson(file, value) {
|
|
110
|
+
if (!Object.keys(value).length) return void fs.rmSync(file, { force: true });
|
|
111
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
112
|
+
fs.writeFileSync(`${file}.tmp`, JSON.stringify(value, null, 2) + "\n");
|
|
113
|
+
fs.renameSync(`${file}.tmp`, file);
|
|
114
|
+
}
|
|
115
|
+
/** The hook groups of one event without ours, and without the groups that leaves empty. */
|
|
116
|
+
const without = (groups) => groups.map((g) => ({
|
|
117
|
+
...g,
|
|
118
|
+
hooks: (g.hooks ?? []).filter((h) => !ours(h.command))
|
|
119
|
+
})).filter((g) => g.hooks.length);
|
|
120
|
+
const settingsFile = (dir) => path.join(dir, ".claude", "settings.json");
|
|
121
|
+
/** Add the hooks to the project's .claude/settings.json, in place of ours that run another command. */
|
|
122
|
+
function installHooks(dir) {
|
|
123
|
+
const file = settingsFile(dir);
|
|
124
|
+
const settings = readJson(file);
|
|
125
|
+
const bin = workpadCommand(dir).join(" ");
|
|
126
|
+
const hooks = settings.hooks ??= {};
|
|
127
|
+
const changed = [];
|
|
128
|
+
for (const [mode, event] of Object.entries(MODES)) {
|
|
129
|
+
const command = `${bin} claude hook ${mode}`;
|
|
130
|
+
const groups = hooks[event] ?? [];
|
|
131
|
+
const now = groups.flatMap((g) => g.hooks ?? []).filter((h) => ours(h.command));
|
|
132
|
+
if (now.length === 1 && now[0].command === command) continue;
|
|
133
|
+
hooks[event] = [...without(groups), { hooks: [{
|
|
134
|
+
type: "command",
|
|
135
|
+
command
|
|
136
|
+
}] }];
|
|
137
|
+
changed.push(event);
|
|
138
|
+
}
|
|
139
|
+
for (const [event, groups] of Object.entries(hooks)) if (!Object.values(MODES).includes(event) && groups.some((g) => g.hooks?.some((h) => ours(h.command)))) {
|
|
140
|
+
const kept = without(groups);
|
|
141
|
+
if (kept.length) hooks[event] = kept;
|
|
142
|
+
else delete hooks[event];
|
|
143
|
+
changed.push(event);
|
|
144
|
+
}
|
|
145
|
+
if (!changed.length) return console.log(`hooks already installed: ${file}`);
|
|
146
|
+
writeJson(file, settings);
|
|
147
|
+
console.log(`hooks set in ${file}: ${changed.join(", ")}`);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Take our hooks out of the project's .claude/settings.json, and nothing else: other hooks and
|
|
151
|
+
* settings stay. A file that held only ours goes.
|
|
152
|
+
*/
|
|
153
|
+
function uninstallHooks(dir) {
|
|
154
|
+
const file = settingsFile(dir);
|
|
155
|
+
const settings = readJson(file);
|
|
156
|
+
const removed = [];
|
|
157
|
+
for (const [event, groups] of Object.entries(settings.hooks ?? {})) {
|
|
158
|
+
if (!groups.some((g) => g.hooks?.some((h) => ours(h.command)))) continue;
|
|
159
|
+
const kept = without(groups);
|
|
160
|
+
removed.push(event);
|
|
161
|
+
if (kept.length) settings.hooks[event] = kept;
|
|
162
|
+
else delete settings.hooks[event];
|
|
163
|
+
}
|
|
164
|
+
if (!removed.length) return console.log(`no workpad hooks in ${file}`);
|
|
165
|
+
if (settings.hooks && !Object.keys(settings.hooks).length) delete settings.hooks;
|
|
166
|
+
writeJson(file, settings);
|
|
167
|
+
console.log(`hooks removed from ${file}: ${removed.join(", ")}`);
|
|
168
|
+
}
|
|
169
|
+
const mcpFile = (dir) => path.join(dir, ".mcp.json");
|
|
170
|
+
/** Register the channel (channel.ts) in the project's .mcp.json, as the server `workpad`. */
|
|
171
|
+
function installChannel(dir) {
|
|
172
|
+
const file = mcpFile(dir);
|
|
173
|
+
const config = readJson(file);
|
|
174
|
+
const [command, ...args] = [
|
|
175
|
+
...workpadCommand(dir),
|
|
176
|
+
"claude",
|
|
177
|
+
"channel"
|
|
178
|
+
];
|
|
179
|
+
const servers = config.mcpServers ??= {};
|
|
180
|
+
const now = servers.workpad;
|
|
181
|
+
if (now?.command === command && JSON.stringify(now.args) === JSON.stringify(args)) return console.log(`channel already installed: ${file}`);
|
|
182
|
+
servers.workpad = {
|
|
183
|
+
command,
|
|
184
|
+
args
|
|
185
|
+
};
|
|
186
|
+
writeJson(file, config);
|
|
187
|
+
console.log(`channel added to ${file}; a session loads it when started with: claude --dangerously-load-development-channels server:workpad`);
|
|
188
|
+
}
|
|
189
|
+
/** Take the channel out of the project's .mcp.json; other servers stay. A file that held only it goes. */
|
|
190
|
+
function uninstallChannel(dir) {
|
|
191
|
+
const file = mcpFile(dir);
|
|
192
|
+
const config = readJson(file);
|
|
193
|
+
if (!(config.mcpServers?.workpad)?.args?.includes("channel")) return console.log(`no workpad channel in ${file}`);
|
|
194
|
+
delete config.mcpServers.workpad;
|
|
195
|
+
if (!Object.keys(config.mcpServers).length) delete config.mcpServers;
|
|
196
|
+
writeJson(file, config);
|
|
197
|
+
console.log(`channel removed from ${file}`);
|
|
198
|
+
}
|
|
199
|
+
export { claude as default };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
// plugins/claude/session.ts
|
|
5
|
+
/**
|
|
6
|
+
* The pid of the claude process this one runs under: the nearest ancestor named `claude`, or null
|
|
7
|
+
* when there is none (a claude run through node, a test, a terminal). One wrapper in between
|
|
8
|
+
* (`npx workpad`) is looked past by name.
|
|
9
|
+
*/
|
|
10
|
+
function claudePid() {
|
|
11
|
+
const ps = spawnSync("ps", [
|
|
12
|
+
"-A",
|
|
13
|
+
"-o",
|
|
14
|
+
"pid=,ppid=,comm="
|
|
15
|
+
], { encoding: "utf8" });
|
|
16
|
+
if (ps.status !== 0) return null;
|
|
17
|
+
const parent = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const line of ps.stdout.split("\n")) {
|
|
19
|
+
const m = line.trim().match(/^(\d+)\s+(\d+)\s+(.*)$/);
|
|
20
|
+
if (m) parent.set(Number(m[1]), [Number(m[2]), path.basename(m[3])]);
|
|
21
|
+
}
|
|
22
|
+
for (let p = process.ppid; p > 1 && parent.has(p); p = parent.get(p)[0]) if (parent.get(p)[1] === "claude") return p;
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The claude process this one runs under, as `<pid>-<start time>` (a pid is reused, its start time
|
|
27
|
+
* tells the two apart): claudePid, or the parent when there is none.
|
|
28
|
+
*/
|
|
29
|
+
function claudeProcess() {
|
|
30
|
+
const pid = claudePid() ?? process.ppid;
|
|
31
|
+
const started = spawnSync("ps", [
|
|
32
|
+
"-o",
|
|
33
|
+
"lstart=",
|
|
34
|
+
"-p",
|
|
35
|
+
String(pid)
|
|
36
|
+
], { encoding: "utf8" });
|
|
37
|
+
const at = started.status === 0 ? Date.parse(started.stdout.trim()) : NaN;
|
|
38
|
+
return Number.isNaN(at) ? String(pid) : `${pid}-${at / 1e3}`;
|
|
39
|
+
}
|
|
40
|
+
const sessionsDir = (dataDir) => path.join(dataDir, "sessions");
|
|
41
|
+
/** The conversation a hook says this claude process is on; records of processes that ended go. */
|
|
42
|
+
function recordSession(dataDir, session) {
|
|
43
|
+
const dir = sessionsDir(dataDir);
|
|
44
|
+
const file = path.join(dir, claudeProcess());
|
|
45
|
+
if (fs.existsSync(file) && fs.readFileSync(file, "utf8") === session) return;
|
|
46
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
47
|
+
for (const name of fs.readdirSync(dir)) if (!alive(Number(name.split("-")[0]))) fs.rmSync(path.join(dir, name));
|
|
48
|
+
fs.writeFileSync(`${file}.tmp`, session);
|
|
49
|
+
fs.renameSync(`${file}.tmp`, file);
|
|
50
|
+
}
|
|
51
|
+
/** The conversation the hooks last recorded for this claude process, or null when none ran yet. */
|
|
52
|
+
function recordedSession(dataDir, claude) {
|
|
53
|
+
try {
|
|
54
|
+
return fs.readFileSync(path.join(sessionsDir(dataDir), claude), "utf8") || null;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function alive(pid) {
|
|
60
|
+
if (!pid) return false;
|
|
61
|
+
try {
|
|
62
|
+
process.kill(pid, 0);
|
|
63
|
+
return true;
|
|
64
|
+
} catch (err) {
|
|
65
|
+
return err.code === "EPERM";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export { claudePid, claudeProcess, recordSession, recordedSession };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Syntax highlighting for code blocks. [Shiki](https://shiki.style) runs on the server, so no script
|
|
2
|
+
runs on the page, and the colours follow the page theme. It applies to every
|
|
3
|
+
fence that no other block claims by name, and to the code view of
|
|
4
|
+
repository files. Write an ordinary fence with a language:
|
|
5
|
+
|
|
6
|
+
````markdown
|
|
7
|
+
```ts
|
|
8
|
+
const page = await workpad.show('plan')
|
|
9
|
+
```
|
|
10
|
+
````
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const page = await workpad.show('plan')
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
A `diff` fence (what `git diff` or `diff -u` prints) is shown for reading:
|
|
17
|
+
each file's headers become its name, a hunk's `@@ … @@` line becomes a `⋯`
|
|
18
|
+
where lines are skipped, lines have their numbers in a gutter and are tinted
|
|
19
|
+
when added or removed. Each line in a hunk also says where it is from
|
|
20
|
+
(`src/a.ts:12`), and a comment on it records that. A hunk can start with a
|
|
21
|
+
bare `@@`: its lines show without numbers. `---` and `+++` lines name the file
|
|
22
|
+
without a `diff --git` above them. Use four backticks around it, since a diff
|
|
23
|
+
can hold three.
|
|
24
|
+
|
|
25
|
+
A line longer than the block scrolls it sideways, on a page and in a chat
|
|
26
|
+
message alike. A fence that says `{wrap}` wraps its long lines at the block's
|
|
27
|
+
edge instead, a diff's rows too:
|
|
28
|
+
|
|
29
|
+
````markdown
|
|
30
|
+
```sh {wrap}
|
|
31
|
+
workpad append --page plan --type chat:message --data '{"chat":"notes","text":"a long line"}'
|
|
32
|
+
```
|
|
33
|
+
````
|
|
34
|
+
|
|
35
|
+
A missing or unknown language renders as plain text. Fences named after
|
|
36
|
+
another block, such as `mermaid`, still go to that block.
|
|
37
|
+
|
|
38
|
+
It's a built-in plugin. For options, replace it in the config with your own
|
|
39
|
+
`code(…)`:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import code from '@bigmistqke/workpad/code'
|
|
43
|
+
|
|
44
|
+
export default defineConfig({
|
|
45
|
+
plugins: [code({
|
|
46
|
+
themes: { light: 'github-light', dark: 'github-dark' }, // any Shiki theme names
|
|
47
|
+
colorReplacements: { 'github-light': { '#e36209': '#0f766e' } }, // per theme
|
|
48
|
+
})],
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Without options it uses the GitHub themes, with their oranges swapped for a
|
|
53
|
+
teal that fits the default palette. If you pass `themes`, nothing is swapped
|
|
54
|
+
unless you also pass `colorReplacements`.
|