claude-code-kanban 7.29.0 → 7.31.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/cli.js +14 -5
- package/hub-app.json +12 -1
- package/lib/panes.js +17 -3
- package/lib/terminal-client.js +11 -1
- package/lib/terminal-host.js +6 -1
- package/lib/terminal.js +26 -9
- package/package.json +1 -1
- package/plugin/plugins/claude-code-kanban/.claude-plugin/plugin.json +1 -1
- package/plugin/plugins/claude-code-kanban/skills/addon/references/build.md +15 -3
- package/plugin/plugins/claude-code-kanban/skills/addon/scripts/theme-check.mjs +94 -0
- package/public/app.js +368 -125
- package/public/index.html +4 -1
- package/public/style.css +16 -1
- package/server.js +65 -10
package/cli.js
CHANGED
|
@@ -62,13 +62,15 @@ const COMMANDS = {
|
|
|
62
62
|
},
|
|
63
63
|
},
|
|
64
64
|
pane: {
|
|
65
|
-
summary: 'Add live panes (a URL
|
|
65
|
+
summary: 'Add live panes (a URL, a local file or a shell) to a session\'s view, without switching to them',
|
|
66
66
|
verbs: {
|
|
67
67
|
add: {
|
|
68
68
|
summary: 'Add a pane to a session; it opens as a tab next to Board, in the background',
|
|
69
|
-
usage: 'claude-code-kanban pane add <url|file> [--title <text>] [--session <id>] [--json]',
|
|
69
|
+
usage: 'claude-code-kanban pane add <url|file> | --shell [<folder>] [--run <cmd>] [--title <text>] [--session <id>] [--json]',
|
|
70
70
|
flags: {
|
|
71
71
|
'<url|file>': 'An http(s) URL, or a local HTML, markdown, text or image file (relative paths resolve against the current dir)',
|
|
72
|
+
'--shell [<folder>]': 'A plain shell (the terminal shell, no claude) in <folder> (default: the current dir). Needs the board\'s terminal. Each add opens a new shell; closing the pane ends it',
|
|
73
|
+
'--run <cmd>': 'With --shell: a one-line command the shell runs when it starts, and again on each restart',
|
|
72
74
|
'--title <text>': 'Tab title (default: the host or file name)',
|
|
73
75
|
[SESSION_FLAG]: SESSION_FLAG_HELP,
|
|
74
76
|
'--json': 'Output JSON (the new pane, with frameable: true, false, or null when unknown)',
|
|
@@ -77,6 +79,7 @@ const COMMANDS = {
|
|
|
77
79
|
examples: [
|
|
78
80
|
'claude-code-kanban pane add http://localhost:5173',
|
|
79
81
|
'claude-code-kanban pane add ./report.html --title Report',
|
|
82
|
+
'claude-code-kanban pane add --shell . --run "npm test -- --watch" --title Tests',
|
|
80
83
|
],
|
|
81
84
|
run: runPaneAddCli,
|
|
82
85
|
},
|
|
@@ -807,15 +810,21 @@ const panesPath = (sessionId, paneId) =>
|
|
|
807
810
|
`/api/panes/${encodeURIComponent(sessionId)}${paneId ? `/${encodeURIComponent(paneId)}` : ''}`;
|
|
808
811
|
|
|
809
812
|
async function runPaneAddCli(args, entry) {
|
|
810
|
-
const [target] = positionals(args, ['--session', '--title']);
|
|
811
|
-
|
|
813
|
+
const [target] = positionals(args, ['--session', '--title', '--run']);
|
|
814
|
+
const shell = args.includes('--shell');
|
|
815
|
+
if (!target && !shell) {
|
|
812
816
|
printLeafHelp(entry);
|
|
813
817
|
return 1;
|
|
814
818
|
}
|
|
819
|
+
const run = getArgValue(args, 'run');
|
|
820
|
+
if (run && !shell) return usageError(entry, '--run needs --shell');
|
|
815
821
|
const resolved = await resolveSessionArg(entry, args, PANES_WHY);
|
|
816
822
|
if (!resolved) return 1;
|
|
817
823
|
try {
|
|
818
|
-
const
|
|
824
|
+
const title = getArgValue(args, 'title') || '';
|
|
825
|
+
const body = shell
|
|
826
|
+
? { kind: 'shell', target: canonicalDir(target || '.'), title, ...(run && { run }) }
|
|
827
|
+
: { target: cliTarget(target), title };
|
|
819
828
|
const out = await cliPostJson(panesPath(resolved.id), body, 'Pane add');
|
|
820
829
|
if (!out) return 1;
|
|
821
830
|
const { pane } = out;
|
package/hub-app.json
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"key": "zenCentered",
|
|
38
38
|
"type": "boolean",
|
|
39
39
|
"label": "Center zen mode",
|
|
40
|
-
"help": "In zen mode, centers the session card and its panel in the sidebar's height.",
|
|
40
|
+
"help": "In zen mode, centers the session card and its panel, or the group or project, in the sidebar's height.",
|
|
41
41
|
"default": false
|
|
42
42
|
},
|
|
43
43
|
{
|
|
@@ -53,6 +53,17 @@
|
|
|
53
53
|
{ "value": "grid", "label": "Grid" }
|
|
54
54
|
],
|
|
55
55
|
"default": "dots"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"key": "terminalHost",
|
|
59
|
+
"type": "choice",
|
|
60
|
+
"label": "Terminal host (Windows)",
|
|
61
|
+
"help": "Bundled passes color queries through, so apps such as hunk and vim follow the board's theme. Applies to terminals started after the change.",
|
|
62
|
+
"options": [
|
|
63
|
+
{ "value": "system", "label": "System" },
|
|
64
|
+
{ "value": "bundled", "label": "Bundled" }
|
|
65
|
+
],
|
|
66
|
+
"default": "system"
|
|
56
67
|
}
|
|
57
68
|
],
|
|
58
69
|
"keys": { "keeps": ["ctrl+alt+1", "ctrl+alt+2", "ctrl+alt+3", "ctrl+alt+4", "ctrl+alt+5", "ctrl+alt+6", "ctrl+alt+7", "ctrl+alt+8", "ctrl+alt+9", "ctrl+alt+n", "ctrl+alt+r", "ctrl+alt+s", "ctrl+alt+shift+s","ctrl+shift+d", "ctrl+shift+k", "ctrl+shift+l", "ctrl+shift+m", "ctrl+shift+p", "ctrl+shift+z"] },
|
package/lib/panes.js
CHANGED
|
@@ -12,7 +12,8 @@ const { pruneMap } = require('./retention');
|
|
|
12
12
|
const MAX_PANES = 50;
|
|
13
13
|
const MAX_TITLE = 100;
|
|
14
14
|
const FILE_KINDS = new Set(['html', 'markdown', 'text', 'image']);
|
|
15
|
-
|
|
15
|
+
// A shell pane's target is the id of its PTY, and its `cwd` the folder the shell starts in.
|
|
16
|
+
const KINDS = new Set([...FILE_KINDS, 'url', 'message', 'scratchpad', 'shell']);
|
|
16
17
|
const MAX_MESSAGE_TARGET = 300;
|
|
17
18
|
const isFileKind = (kind) => FILE_KINDS.has(kind);
|
|
18
19
|
|
|
@@ -51,6 +52,7 @@ const targetKey = (kind, target) =>
|
|
|
51
52
|
|
|
52
53
|
function defaultTitle(kind, target) {
|
|
53
54
|
if (kind === 'message') return 'Message';
|
|
55
|
+
if (kind === 'shell') return 'Shell';
|
|
54
56
|
if (kind === 'scratchpad') return path.basename(path.dirname(target));
|
|
55
57
|
if (kind !== 'url') return path.basename(target);
|
|
56
58
|
try {
|
|
@@ -131,7 +133,7 @@ function createPaneStore({ load, save, onChange = () => {}, now = Date.now }) {
|
|
|
131
133
|
|
|
132
134
|
// The same target added again returns its pane where it is, so a repeated `pane add` is harmless.
|
|
133
135
|
// `show` marks a show card's file, which the board renders with the card's theme.
|
|
134
|
-
function add(sessionId, { kind, target, title, show }) {
|
|
136
|
+
function add(sessionId, { kind, target, title, show, cwd, run }) {
|
|
135
137
|
if (!KINDS.has(kind)) throw httpError(400, `Unknown pane kind: ${kind}`, 'bad_kind');
|
|
136
138
|
if (kind === 'message' && target.length > MAX_MESSAGE_TARGET) {
|
|
137
139
|
throw httpError(400, `A message target holds at most ${MAX_MESSAGE_TARGET} characters`, 'bad_target');
|
|
@@ -148,6 +150,8 @@ function createPaneStore({ load, save, onChange = () => {}, now = Date.now }) {
|
|
|
148
150
|
target,
|
|
149
151
|
title: paneTitle(kind, target, title),
|
|
150
152
|
...(show && { show: true }),
|
|
153
|
+
...(cwd && { cwd }),
|
|
154
|
+
...(run && { run }),
|
|
151
155
|
addedAt: now(),
|
|
152
156
|
};
|
|
153
157
|
layout.panes.push(pane);
|
|
@@ -230,7 +234,17 @@ function createPaneStore({ load, save, onChange = () => {}, now = Date.now }) {
|
|
|
230
234
|
return out;
|
|
231
235
|
}
|
|
232
236
|
|
|
233
|
-
|
|
237
|
+
// The shell pane whose PTY has this id, or null.
|
|
238
|
+
function shellPane(ptyId) {
|
|
239
|
+
reload();
|
|
240
|
+
for (const layout of bySession.values()) {
|
|
241
|
+
const pane = layout.panes.find((p) => p.kind === 'shell' && p.target === ptyId);
|
|
242
|
+
if (pane) return { ...pane };
|
|
243
|
+
}
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return { get, add, remove, removeShow, rename, setDock, reorder, prune, reload, fileTargets, shellPane };
|
|
234
248
|
}
|
|
235
249
|
|
|
236
250
|
module.exports = { createPaneStore, isOwnOrigin, portOf, MAX_PANES, MAX_TITLE };
|
package/lib/terminal-client.js
CHANGED
|
@@ -27,6 +27,7 @@ function hostError(message) {
|
|
|
27
27
|
* @param {boolean} o.isDefaultDir
|
|
28
28
|
* @param {string} o.sessionsDir claude's live-session registry
|
|
29
29
|
* @param {(id: string) => string|null|Promise<string|null>} o.resolveCwd
|
|
30
|
+
* @param {(id: string) => string|null} [o.shellRun]
|
|
30
31
|
* @param {(dir: string) => boolean|Promise<boolean>} o.isAllowedFolder
|
|
31
32
|
* @param {string} [o.token]
|
|
32
33
|
* @param {() => {sessions?: string[]}|null} [o.load]
|
|
@@ -34,6 +35,7 @@ function hostError(message) {
|
|
|
34
35
|
* @param {() => void} [o.onChange]
|
|
35
36
|
* @param {(id: string) => void} [o.onExit]
|
|
36
37
|
* @param {(from: string, to: string) => void} [o.onRekey]
|
|
38
|
+
* @param {(id: string, parent: string) => void} [o.onFork]
|
|
37
39
|
*/
|
|
38
40
|
function createTerminalClient(o) {
|
|
39
41
|
const { config, net } = o;
|
|
@@ -85,6 +87,7 @@ function createTerminalClient(o) {
|
|
|
85
87
|
o.onChange?.();
|
|
86
88
|
} else if (msg.t === 'exit') o.onExit?.(msg.id);
|
|
87
89
|
else if (msg.t === 'rekey') o.onRekey?.(msg.from, msg.to);
|
|
90
|
+
else if (msg.t === 'fork') o.onFork?.(msg.id, msg.parent);
|
|
88
91
|
else if (msg.t === 'save') o.save?.(msg.data);
|
|
89
92
|
else if (msg.t === 'reply') {
|
|
90
93
|
const pending = calls.get(msg.id);
|
|
@@ -98,6 +101,7 @@ function createTerminalClient(o) {
|
|
|
98
101
|
|
|
99
102
|
const ASKS = {
|
|
100
103
|
resolveCwd: [o.resolveCwd, null],
|
|
104
|
+
shellRun: [o.shellRun ?? (() => null), null],
|
|
101
105
|
isAllowedFolder: [o.isAllowedFolder, false],
|
|
102
106
|
};
|
|
103
107
|
|
|
@@ -211,6 +215,12 @@ function createTerminalClient(o) {
|
|
|
211
215
|
if (child?.connected) child.send({ t: 'port', url });
|
|
212
216
|
}
|
|
213
217
|
|
|
218
|
+
// Terminals started after the change use it; a restarted host gets it with its config.
|
|
219
|
+
function setConptyDll(on) {
|
|
220
|
+
config.conptyDll = !!on;
|
|
221
|
+
if (child?.connected) child.send({ t: 'conptyDll', on: config.conptyDll });
|
|
222
|
+
}
|
|
223
|
+
|
|
214
224
|
// With no host there are no terminals, which the hub's eviction check must still read.
|
|
215
225
|
async function sessions() {
|
|
216
226
|
return child?.connected ? call('sessions') : [];
|
|
@@ -236,7 +246,7 @@ function createTerminalClient(o) {
|
|
|
236
246
|
|
|
237
247
|
return {
|
|
238
248
|
token, handleUpgrade, clientConfig, unavailableReason, authorized, isRunning, hasTerminal, sessionOfTerminal, startNew, end, paste, type, restore,
|
|
239
|
-
setServerUrl, sessions, stats, shutdown, started,
|
|
249
|
+
setServerUrl, setConptyDll, sessions, stats, shutdown, started,
|
|
240
250
|
ids: () => [...ids],
|
|
241
251
|
awaitingTrust: () => [...awaitingTrust],
|
|
242
252
|
};
|
package/lib/terminal-host.js
CHANGED
|
@@ -9,6 +9,7 @@ const { whichSync } = require('./open-editor');
|
|
|
9
9
|
|
|
10
10
|
let service = null;
|
|
11
11
|
let serverUrl = null;
|
|
12
|
+
let config = null;
|
|
12
13
|
let lastState = null;
|
|
13
14
|
let nextAsk = 0;
|
|
14
15
|
const asks = new Map();
|
|
@@ -43,9 +44,10 @@ function pushState() {
|
|
|
43
44
|
|
|
44
45
|
function init(msg) {
|
|
45
46
|
serverUrl = msg.serverUrl;
|
|
47
|
+
config = msg.config;
|
|
46
48
|
const liveSessions = () => readLiveSessions(msg.sessionsDir);
|
|
47
49
|
service = createTerminalService({
|
|
48
|
-
config
|
|
50
|
+
config,
|
|
49
51
|
// cck checked Host, Origin and exposure before it handed the socket over.
|
|
50
52
|
net: { EXPOSED: false, upgradeVerdict: () => null },
|
|
51
53
|
claudeDir: msg.claudeDir,
|
|
@@ -56,12 +58,14 @@ function init(msg) {
|
|
|
56
58
|
liveSessions,
|
|
57
59
|
isLiveElsewhere: (id, exceptPid) => isSessionLive(liveSessions(), id, exceptPid),
|
|
58
60
|
resolveCwd: (id) => ask('resolveCwd', id),
|
|
61
|
+
shellRun: (id) => ask('shellRun', id),
|
|
59
62
|
isAllowedFolder: (dir) => ask('isAllowedFolder', dir),
|
|
60
63
|
load: () => msg.saved,
|
|
61
64
|
save: (data) => send({ t: 'save', data }),
|
|
62
65
|
onChange: pushState,
|
|
63
66
|
onExit: (id) => send({ t: 'exit', id }),
|
|
64
67
|
onRekey: (from, to) => send({ t: 'rekey', from, to }),
|
|
68
|
+
onFork: (id, parent) => send({ t: 'fork', id, parent }),
|
|
65
69
|
});
|
|
66
70
|
pushState();
|
|
67
71
|
}
|
|
@@ -87,6 +91,7 @@ async function call(msg) {
|
|
|
87
91
|
process.on('message', (msg, socket) => {
|
|
88
92
|
if (msg.t === 'init') init(msg);
|
|
89
93
|
else if (msg.t === 'port') serverUrl = msg.url;
|
|
94
|
+
else if (msg.t === 'conptyDll' && config) config.conptyDll = msg.on;
|
|
90
95
|
else if (msg.t === 'upgrade') {
|
|
91
96
|
if (!socket) return;
|
|
92
97
|
service.handleUpgrade({ method: msg.method, url: msg.url, headers: msg.headers }, socket, Buffer.from(msg.head, 'base64'));
|
package/lib/terminal.js
CHANGED
|
@@ -114,6 +114,7 @@ function readTerminalConfig({ argv = process.argv, env = process.env, getArgValu
|
|
|
114
114
|
scrollback: posInt(cfg.scrollback, 5000),
|
|
115
115
|
noFlicker: cfg.noFlicker !== false,
|
|
116
116
|
restore: cfg.restore !== false,
|
|
117
|
+
conptyDll: cfg.conptyDll === true,
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
120
|
|
|
@@ -351,12 +352,14 @@ function clientConfigFor(config, available) {
|
|
|
351
352
|
* @param {(id: string) => string|null|Promise<string|null>} o.resolveCwd null = unknown session
|
|
352
353
|
* @param {(id: string, exceptPid?: number) => boolean} o.isLiveElsewhere
|
|
353
354
|
* @param {(dir: string) => boolean|Promise<boolean>} o.isAllowedFolder where a new session may start
|
|
355
|
+
* @param {(id: string) => string|null|Promise<string|null>} [o.shellRun] a command a new shell-mode PTY types and runs
|
|
354
356
|
* @param {() => {pid: number|null, sessionId: string, cwd: string|null, startedAt: number}[]} o.liveSessions
|
|
355
357
|
* claude's live-session registry, read fresh
|
|
356
358
|
* @param {(cmd: string) => string|null} o.which
|
|
357
359
|
* @param {string} [o.token]
|
|
358
360
|
* @param {() => void} [o.onChange] a terminal started, ended or moved to another session id
|
|
359
361
|
* @param {(from: string, to: string) => void} [o.onRekey] a terminal moved to another session id
|
|
362
|
+
* @param {(id: string, parent: string) => void} [o.onFork] a terminal started a fork of the parent session
|
|
360
363
|
* @param {() => {sessions?: string[], taskLists?: Object<string, string>}|null} [o.load] the saved list, read when config.restore is on
|
|
361
364
|
* @param {(data: {sessions: string[], taskLists?: Object<string, string>}) => void} [o.save] the session ids to resume on the next start, and the shared task list of each that has one
|
|
362
365
|
* @param {object} [o.pty] stands in for @lydell/node-pty in tests
|
|
@@ -526,10 +529,12 @@ function createTerminalService(o) {
|
|
|
526
529
|
// is the claude command typed at the shell prompt once the shell's startup output settles,
|
|
527
530
|
// and Enter is left to the user; bracketed paste keeps a prompt's line breaks from running
|
|
528
531
|
// the command early (checked in Git Bash and pwsh).
|
|
529
|
-
|
|
532
|
+
// `run` is a one-line command for the shell itself, typed plain and run with Enter, since cmd
|
|
533
|
+
// knows no bracketed paste.
|
|
534
|
+
function queueText(s, raw, submit, run = false) {
|
|
530
535
|
let armed = !submit;
|
|
531
536
|
let timer = null;
|
|
532
|
-
const text = bracketed(raw);
|
|
537
|
+
const text = run ? `${raw}\r` : bracketed(raw);
|
|
533
538
|
s.onOutput = (data) => {
|
|
534
539
|
if (submit) {
|
|
535
540
|
const on = data.lastIndexOf('\x1b[?2004h');
|
|
@@ -648,6 +653,19 @@ function createTerminalService(o) {
|
|
|
648
653
|
}
|
|
649
654
|
}
|
|
650
655
|
|
|
656
|
+
// Windows' own ConPTY swallows OSC 10/11 color queries and drops OSC replies on input, so apps such as
|
|
657
|
+
// hunk cannot read the theme. The ConPTY that node-pty ships passes both; a spawn it fails falls back.
|
|
658
|
+
function spawnPty(args, opts) {
|
|
659
|
+
if (process.platform === 'win32' && config.conptyDll) {
|
|
660
|
+
try {
|
|
661
|
+
return pty.spawn(shell, args, { ...opts, useConptyDll: true });
|
|
662
|
+
} catch (e) {
|
|
663
|
+
console.log(`Bundled ConPTY failed, using the system one: ${e.message}`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return pty.spawn(shell, args, opts);
|
|
667
|
+
}
|
|
668
|
+
|
|
651
669
|
function spawnSession(id, mode, cwdCandidate, cols, rows, spec, extraEnv) {
|
|
652
670
|
const cwd = cwdCandidate && fs.existsSync(cwdCandidate) ? cwdCandidate : os.homedir();
|
|
653
671
|
const terminalId = savedTerminalIds[id] || crypto.randomUUID();
|
|
@@ -657,13 +675,7 @@ function createTerminalService(o) {
|
|
|
657
675
|
// Git Bash's login profile cds to $HOME unless this is set.
|
|
658
676
|
if (shellFamily(shell) === 'gitbash') env.CHERE_INVOKING = '1';
|
|
659
677
|
const claudeArgs = claudeArgsFor(mode, id, spec);
|
|
660
|
-
const proc =
|
|
661
|
-
name: 'xterm-256color',
|
|
662
|
-
cols,
|
|
663
|
-
rows,
|
|
664
|
-
cwd,
|
|
665
|
-
env,
|
|
666
|
-
});
|
|
678
|
+
const proc = spawnPty(shellArgs(shell, spec?.edit ? null : claudeArgs), { name: 'xterm-256color', cols, rows, cwd, env });
|
|
667
679
|
const term = new Headless({ cols, rows, scrollback: config.scrollback, allowProposedApi: true });
|
|
668
680
|
const serializer = new Serialize();
|
|
669
681
|
term.loadAddon(serializer);
|
|
@@ -672,8 +684,10 @@ function createTerminalService(o) {
|
|
|
672
684
|
name: spec?.name || null, worktree: spec?.worktree || false, taskList, onOutput: null, awaitingTrust: false, edit: !!spec?.edit,
|
|
673
685
|
forkOf: spec?.forkOf || null, resumeOf: spec?.resume || null, restore: spec?.restore !== false, prompted: !!spec?.prompt,
|
|
674
686
|
};
|
|
687
|
+
if (s.forkOf) o.onFork?.(id, s.forkOf);
|
|
675
688
|
if (s.edit) queueText(s, claudeCommand(shell, claudeArgs, spec.prompt), false);
|
|
676
689
|
else if (spec?.prompt) queueText(s, spec.prompt, true);
|
|
690
|
+
else if (spec?.run) queueText(s, spec.run, false, true);
|
|
677
691
|
if (mode === 'pick') watchPick(s);
|
|
678
692
|
|
|
679
693
|
proc.onData((data) => {
|
|
@@ -857,6 +871,9 @@ function createTerminalService(o) {
|
|
|
857
871
|
}
|
|
858
872
|
} else if (mode !== 'shell' && known === null) {
|
|
859
873
|
return { code: 4004, status: 404, error: 'unknown session' };
|
|
874
|
+
} else if (mode === 'shell' && !spec) {
|
|
875
|
+
const run = await o.shellRun?.(id);
|
|
876
|
+
if (run) spec = { run };
|
|
860
877
|
}
|
|
861
878
|
if (shuttingDown) return { code: 1001, status: 503, error: 'the terminal is shutting down' };
|
|
862
879
|
const running = sessions.get(id);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-kanban",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "claude-code-kanban dashboard integration: agent activity tracking, context and cost tracking, board moves and reviews delivered to the session, and skills to drive the board from a session"
|
|
5
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Build an add-on
|
|
2
2
|
|
|
3
|
-
An add-on is one HTML page and a small server that serves it. The board frames the page by its URL, so any stack works; this guide uses Node with no dependencies. The build is done when the server answers 200 and `addon add` printed an id.
|
|
3
|
+
An add-on is one HTML page and a small server that serves it. The board frames the page by its URL, so any stack works; this guide uses Node with no dependencies. The build is done when the theme check passes, the server answers 200 and `addon add` printed an id.
|
|
4
4
|
|
|
5
5
|
## 1. Write the server and the page
|
|
6
6
|
|
|
@@ -28,7 +28,7 @@ The URL is the page's only input from the board. The page reads the values the b
|
|
|
28
28
|
|
|
29
29
|
## 3. Take the board's theme
|
|
30
30
|
|
|
31
|
-
Style the page with the variables of the HTML contract in [the show skill](../../show/SKILL.md#html-contract), in its flat style. Set fallback values for them in `:where(:root)`, and
|
|
31
|
+
Style the page with the variables of the HTML contract in [the show skill](../../show/SKILL.md#html-contract), in its flat style. Set fallback values for them in `:where(:root)`, and set `:root { color-scheme: var(--color-scheme, light dark); }` so scrollbars and form controls follow the board, not the OS. Apply the board's values from its message, which it sends on each load and each theme change:
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
addEventListener('message', (e) => {
|
|
@@ -69,7 +69,19 @@ When the content follows files, the server watches them (`fs.watch`) and pushes
|
|
|
69
69
|
|
|
70
70
|
The dock is 360 to 900 px wide and the full height of the terminal. Lay the page out in normal flow that wraps at 360 px, and let the body scroll.
|
|
71
71
|
|
|
72
|
-
## 7.
|
|
72
|
+
## 7. Verify the theme
|
|
73
|
+
|
|
74
|
+
Run the static check, `scripts/theme-check.mjs` in this skill's base directory, on the page, and fix every error before you register it:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
node <skill base dir>/scripts/theme-check.mjs <folder>/index.html
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
It fails on a literal color (hex, `rgb()`, `hsl()`, `oklch()`, a named color) in CSS, a `style` attribute, an SVG `fill` or `stroke`, or a JS string, and on a page with no `cck-show:tokens` listener. It warns on a variable that is not a board token, a token with no fallback, a literal font, and a missing `color-scheme`. A literal color is allowed only as a token's fallback in `:where(:root)`. For a shade, mix a token: `color-mix(in srgb, var(--color-accent) 14%, transparent)`.
|
|
81
|
+
|
|
82
|
+
A pass does not prove the page follows the theme. The check reads one file, so it does not see colors built at runtime (`'#' + hex`, colors from the server), linked stylesheets, library CSS, canvas or images. Keep those on tokens too, and when the page has any of them, open it on the rail and switch the board between light and dark.
|
|
83
|
+
|
|
84
|
+
## 8. Run and register
|
|
73
85
|
|
|
74
86
|
1. Start the server where the user can see and stop it, such as a tmux window, or ask the user to start it.
|
|
75
87
|
2. Check that it answers 200: `curl -s -o /dev/null -w '%{http_code}' http://localhost:4100/`.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Static theme check for an add-on page: node theme-check.mjs <page.html>. Exits 1 on an error.
|
|
2
|
+
// The token list mirrors the HTML contract in skills/show/SKILL.md.
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
const CONTRACT = new Set([
|
|
6
|
+
'--color-bg', '--color-bg-subtle', '--color-text', '--color-text-muted', '--color-border', '--color-accent',
|
|
7
|
+
'--color-info', '--color-success', '--color-warning', '--color-danger', '--font-sans', '--font-mono', '--color-scheme',
|
|
8
|
+
...Array.from({ length: 8 }, (_, i) => `--color-series-${i + 1}`),
|
|
9
|
+
...Array.from({ length: 5 }, (_, i) => `--color-ramp-${i + 1}`),
|
|
10
|
+
]);
|
|
11
|
+
const NAMED = 'white|black|red|green|blue|gray|grey|silver|orange|yellow|purple|pink|navy|teal|maroon|olive|lime|aqua|fuchsia|gold|crimson|tomato|coral|salmon|indigo|violet|brown|beige|ivory|khaki|lavender|tan|cyan|magenta|whitesmoke|gainsboro|lightgray|lightgrey|darkgray|darkgrey|dimgray|dimgrey';
|
|
12
|
+
const RAW_FN = '#[0-9a-f]{3,8}\\b|\\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\\(';
|
|
13
|
+
const RAW = new RegExp(`${RAW_FN}|\\b(?:${NAMED})\\b`, 'i');
|
|
14
|
+
// In JS a named color is too likely an ordinary word, so only hex and color functions count.
|
|
15
|
+
const RAW_JS = new RegExp(RAW_FN, 'i');
|
|
16
|
+
const COLOR_PROPS = /^(?:color|background(?:-color|-image)?|border(?:-[a-z]+)*|outline(?:-color)?|fill|stroke|box-shadow|text-shadow|caret-color|accent-color|text-decoration(?:-color)?|column-rule(?:-color)?|stop-color|flood-color|lighting-color|--[\w-]+)$/i;
|
|
17
|
+
|
|
18
|
+
const file = process.argv[2];
|
|
19
|
+
const src = readFileSync(file, 'utf8');
|
|
20
|
+
const lineOf = (i) => src.slice(0, i).split('\n').length;
|
|
21
|
+
const findings = [];
|
|
22
|
+
const report = (level, i, rule, text) =>
|
|
23
|
+
findings.push({ level, line: i == null ? 0 : lineOf(i), rule, text: text.trim().slice(0, 110) });
|
|
24
|
+
|
|
25
|
+
const usedVars = new Set();
|
|
26
|
+
const definedVars = new Set();
|
|
27
|
+
const fallbackVars = new Set();
|
|
28
|
+
const collectVars = (s) => {
|
|
29
|
+
for (const v of s.matchAll(/var\(\s*(--[\w-]+)/g)) usedVars.add(v[1]);
|
|
30
|
+
};
|
|
31
|
+
const stripVars = (s) => s.replace(/var\([^)]*\)/g, '');
|
|
32
|
+
|
|
33
|
+
// CSS: every declaration inside <style> blocks and style="" attributes.
|
|
34
|
+
function checkCss(css, base, inline) {
|
|
35
|
+
const bodies = inline
|
|
36
|
+
? [{ sel: '[style]', body: css, at: 0 }]
|
|
37
|
+
: [...css.matchAll(/([^{}]*)\{([^{}]*)\}/g)].map((m) => ({ sel: m[1].trim(), body: m[2], at: m.index + m[1].length + 1 }));
|
|
38
|
+
for (const { sel, body, at } of bodies) {
|
|
39
|
+
const isRoot = /(^|,)\s*(:where\(\s*:root\s*\)|:root|html)\s*$/.test(sel);
|
|
40
|
+
for (const d of body.matchAll(/([-\w]+)\s*:\s*([^;]+)/g)) {
|
|
41
|
+
const [, prop, value] = d;
|
|
42
|
+
const i = base + at + d.index;
|
|
43
|
+
collectVars(value);
|
|
44
|
+
if (prop.startsWith('--')) {
|
|
45
|
+
definedVars.add(prop);
|
|
46
|
+
if (isRoot && CONTRACT.has(prop)) fallbackVars.add(prop);
|
|
47
|
+
}
|
|
48
|
+
if (/^font(-family)?$/.test(prop) && !/var\(--font-/.test(value) && !/^(inherit|initial|unset)$/.test(value.trim()))
|
|
49
|
+
report('warn', i, 'font-literal', `${prop}: ${value}`);
|
|
50
|
+
if (!COLOR_PROPS.test(prop) || !RAW.test(stripVars(value))) continue;
|
|
51
|
+
if (isRoot && CONTRACT.has(prop)) continue; // fallback value for a board token
|
|
52
|
+
if (/^(?:transparent|currentcolor|inherit|none)$/i.test(value.trim())) continue;
|
|
53
|
+
report('error', i, prop.startsWith('--') ? 'raw-color-in-custom-prop' : 'raw-color', `${sel ? `${sel.split('\n').pop().trim()} { ` : ''}${prop}: ${value}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const m of src.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/gi)) checkCss(m[1], m.index + m[0].indexOf(m[1]), false);
|
|
59
|
+
for (const m of src.matchAll(/\sstyle\s*=\s*"([^"]*)"/gi)) checkCss(m[1], m.index, true);
|
|
60
|
+
for (const m of src.matchAll(/\s(fill|stroke|color|bgcolor|stop-color)\s*=\s*"([^"]*)"/gi)) {
|
|
61
|
+
collectVars(m[2]);
|
|
62
|
+
if (RAW.test(stripVars(m[2]))) report('error', m.index, 'raw-color-attr', `${m[1]}="${m[2]}"`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// JS: string literals and template parts that carry a color.
|
|
66
|
+
let hasListener = false;
|
|
67
|
+
for (const m of src.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/gi)) {
|
|
68
|
+
const js = m[1];
|
|
69
|
+
const base = m.index + m[0].indexOf(js);
|
|
70
|
+
if (/cck-show:tokens/.test(js)) hasListener = true;
|
|
71
|
+
for (const s of js.matchAll(/(['"`])((?:\\.|(?!\1)[^\\])*)\1/g)) {
|
|
72
|
+
const str = s[2];
|
|
73
|
+
collectVars(str);
|
|
74
|
+
const selectorArg = /(?:querySelector(?:All)?|closest|matches|getElementById)\(\s*$/.test(js.slice(Math.max(0, s.index - 30), s.index));
|
|
75
|
+
if (!selectorArg && RAW_JS.test(stripVars(str)))
|
|
76
|
+
report('error', base + s.index, 'raw-color-js', s[0]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!/color-scheme\s*:\s*var\(\s*--color-scheme/.test(src))
|
|
81
|
+
report('warn', null, 'no-color-scheme', 'color-scheme does not follow var(--color-scheme): scrollbars and native controls follow the OS');
|
|
82
|
+
if (!hasListener) report('error', null, 'no-token-listener', "no 'cck-show:tokens' message listener");
|
|
83
|
+
for (const v of usedVars) {
|
|
84
|
+
if (!CONTRACT.has(v) && !definedVars.has(v)) report('warn', null, 'unknown-var', `${v} is not a board token and is not defined`);
|
|
85
|
+
if (CONTRACT.has(v) && v !== '--color-scheme' && !fallbackVars.has(v)) report('warn', null, 'no-fallback', `${v} has no fallback in :where(:root)`);
|
|
86
|
+
}
|
|
87
|
+
const unused = [...CONTRACT].filter((t) => !usedVars.has(t) && !t.startsWith('--color-series') && !t.startsWith('--color-ramp') && t !== '--color-scheme');
|
|
88
|
+
if (unused.length) report('info', null, 'unused-tokens', unused.join(', '));
|
|
89
|
+
|
|
90
|
+
findings.sort((a, b) => a.line - b.line);
|
|
91
|
+
for (const f of findings) console.log(`${f.level.padEnd(5)} ${String(f.line || '-').padStart(4)} ${f.rule.padEnd(24)} ${f.text}`);
|
|
92
|
+
const errors = findings.filter((f) => f.level === 'error').length;
|
|
93
|
+
console.log(`\n${errors} error(s), ${findings.filter((f) => f.level === 'warn').length} warning(s)`);
|
|
94
|
+
process.exit(errors ? 1 : 0);
|