claude-code-kanban 7.28.0 → 7.30.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 CHANGED
@@ -62,13 +62,15 @@ const COMMANDS = {
62
62
  },
63
63
  },
64
64
  pane: {
65
- summary: 'Add live panes (a URL or a local file) to a session\'s view, without switching to them',
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
- if (!target) {
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 body = { target: cliTarget(target), title: getArgValue(args, 'title') || '' };
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
  {
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
- const KINDS = new Set([...FILE_KINDS, 'url', 'message']);
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
 
@@ -42,10 +43,17 @@ function isOwnOrigin(url, { boardPort, boardHosts = [], hubUrl }) {
42
43
 
43
44
  const emptyLayout = () => ({ rev: 0, nextId: 1, panes: [], updatedAt: null });
44
45
 
45
- const targetKey = (kind, target) => (isFileKind(kind) ? `file:${canonicalPath(target)}` : `${kind}:${target}`);
46
+ const targetKey = (kind, target) =>
47
+ isFileKind(kind)
48
+ ? `file:${canonicalPath(target)}`
49
+ : kind === 'scratchpad'
50
+ ? `scratchpad:${canonicalPath(target)}`
51
+ : `${kind}:${target}`;
46
52
 
47
53
  function defaultTitle(kind, target) {
48
54
  if (kind === 'message') return 'Message';
55
+ if (kind === 'shell') return 'Shell';
56
+ if (kind === 'scratchpad') return path.basename(path.dirname(target));
49
57
  if (kind !== 'url') return path.basename(target);
50
58
  try {
51
59
  return new URL(target).host;
@@ -125,7 +133,7 @@ function createPaneStore({ load, save, onChange = () => {}, now = Date.now }) {
125
133
 
126
134
  // The same target added again returns its pane where it is, so a repeated `pane add` is harmless.
127
135
  // `show` marks a show card's file, which the board renders with the card's theme.
128
- function add(sessionId, { kind, target, title, show }) {
136
+ function add(sessionId, { kind, target, title, show, cwd, run }) {
129
137
  if (!KINDS.has(kind)) throw httpError(400, `Unknown pane kind: ${kind}`, 'bad_kind');
130
138
  if (kind === 'message' && target.length > MAX_MESSAGE_TARGET) {
131
139
  throw httpError(400, `A message target holds at most ${MAX_MESSAGE_TARGET} characters`, 'bad_target');
@@ -142,6 +150,8 @@ function createPaneStore({ load, save, onChange = () => {}, now = Date.now }) {
142
150
  target,
143
151
  title: paneTitle(kind, target, title),
144
152
  ...(show && { show: true }),
153
+ ...(cwd && { cwd }),
154
+ ...(run && { run }),
145
155
  addedAt: now(),
146
156
  };
147
157
  layout.panes.push(pane);
@@ -224,7 +234,17 @@ function createPaneStore({ load, save, onChange = () => {}, now = Date.now }) {
224
234
  return out;
225
235
  }
226
236
 
227
- return { get, add, remove, removeShow, rename, setDock, reorder, prune, reload, fileTargets };
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 };
228
248
  }
229
249
 
230
250
  module.exports = { createPaneStore, isOwnOrigin, portOf, MAX_PANES, MAX_TITLE };
@@ -0,0 +1,119 @@
1
+ // One `scratch ui --json` browser viewer per pad, for scratchpad panes. Each child holds a pipe on
2
+ // its stdin that cck never writes to: when cck exits, the pipe closes and the viewer exits with it.
3
+
4
+ const path = require('node:path');
5
+ const { canonicalPath } = require('./linked-docs');
6
+
7
+ const READY_TIMEOUT_MS = 15000;
8
+ const HEALTH_TIMEOUT_MS = 1500;
9
+
10
+ /**
11
+ * @param {object} o
12
+ * @param {() => string|null} o.resolveBin the `scratch` executable, or null when it cannot be launched
13
+ * @param {(file: string, args: string[], opts: object) => import('node:child_process').ChildProcess} o.spawn
14
+ * @param {(pad: string) => void} [o.onExit] the canonical pad dir of a viewer that exited
15
+ */
16
+ function createScratchServers({ resolveBin, spawn, fetch = globalThis.fetch, onExit = () => {}, max = 4, readyTimeoutMs = READY_TIMEOUT_MS }) {
17
+ // Map order is recency: the first entry is the one stopped when a new pad needs room.
18
+ const live = new Map();
19
+ const starting = new Map();
20
+
21
+ function stop(key) {
22
+ const entry = live.get(key);
23
+ if (!entry) return;
24
+ live.delete(key);
25
+ entry.child.kill();
26
+ }
27
+
28
+ async function healthy(entry, key) {
29
+ try {
30
+ const res = await fetch(new URL(`/__scratch/health${new URL(entry.url).search}`, entry.url), {
31
+ signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS),
32
+ });
33
+ if (!res.ok) return false;
34
+ const { pid, pads } = await res.json();
35
+ return pid === entry.pid && Array.isArray(pads) && pads.some((p) => canonicalPath(p) === key);
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+
41
+ async function start(dir, key) {
42
+ const file = resolveBin();
43
+ if (!file) {
44
+ const err = new Error('scratch CLI not found on PATH');
45
+ err.status = 501;
46
+ throw err;
47
+ }
48
+ // No `detached`: on Windows it overrides `windowsHide` and the bun shim opens a console window.
49
+ const child = spawn(file, ['ui', path.basename(dir), '--dir', path.dirname(dir), '--json'], {
50
+ stdio: ['pipe', 'pipe', 'pipe'],
51
+ windowsHide: true,
52
+ });
53
+ child.stdin.on('error', () => {});
54
+ let stderr = '';
55
+ child.stderr.on('data', (b) => {
56
+ stderr = (stderr + b).slice(-2000);
57
+ });
58
+ return new Promise((resolve, reject) => {
59
+ let buf = '';
60
+ let entry = null;
61
+ const fail = (msg) => {
62
+ clearTimeout(timer);
63
+ child.kill();
64
+ reject(new Error(`${msg}${stderr.trim() ? `: ${stderr.trim().split('\n').pop()}` : ''}`));
65
+ };
66
+ const timer = setTimeout(() => fail('scratch viewer did not start'), readyTimeoutMs);
67
+ // Read stdout to the end, so a chatty viewer never fills the pipe and blocks.
68
+ child.stdout.on('data', (b) => {
69
+ if (entry) return;
70
+ buf += b;
71
+ const nl = buf.indexOf('\n');
72
+ if (nl < 0) return;
73
+ clearTimeout(timer);
74
+ try {
75
+ const ready = JSON.parse(buf.slice(0, nl));
76
+ entry = { child, url: ready.url, pid: ready.pid };
77
+ } catch {
78
+ fail('scratch viewer printed no ready line (needs scratch with `ui --json`)');
79
+ return;
80
+ }
81
+ buf = '';
82
+ while (live.size >= max) stop(live.keys().next().value);
83
+ live.set(key, entry);
84
+ resolve(entry);
85
+ });
86
+ child.on('error', (e) => fail(`scratch viewer failed to start (${e.message})`));
87
+ child.on('exit', (code) => {
88
+ if (!entry) {
89
+ fail(`scratch viewer exited (${code})`);
90
+ return;
91
+ }
92
+ if (live.get(key) === entry) live.delete(key);
93
+ onExit(key);
94
+ });
95
+ child.unref();
96
+ child.stdin.unref?.();
97
+ child.stdout.unref?.();
98
+ child.stderr.unref?.();
99
+ });
100
+ }
101
+
102
+ /** The viewer URL for the pad at `dir`, started when no live one answers for it. */
103
+ async function serve(dir) {
104
+ const key = canonicalPath(dir);
105
+ const entry = live.get(key);
106
+ if (entry && (await healthy(entry, key))) {
107
+ live.delete(key);
108
+ live.set(key, entry);
109
+ return entry.url;
110
+ }
111
+ if (entry) stop(key);
112
+ if (!starting.has(key)) starting.set(key, start(dir, key).finally(() => starting.delete(key)));
113
+ return (await starting.get(key)).url;
114
+ }
115
+
116
+ return { serve, size: () => live.size };
117
+ }
118
+
119
+ module.exports = { createScratchServers };
@@ -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
 
@@ -56,12 +56,14 @@ function init(msg) {
56
56
  liveSessions,
57
57
  isLiveElsewhere: (id, exceptPid) => isSessionLive(liveSessions(), id, exceptPid),
58
58
  resolveCwd: (id) => ask('resolveCwd', id),
59
+ shellRun: (id) => ask('shellRun', id),
59
60
  isAllowedFolder: (dir) => ask('isAllowedFolder', dir),
60
61
  load: () => msg.saved,
61
62
  save: (data) => send({ t: 'save', data }),
62
63
  onChange: pushState,
63
64
  onExit: (id) => send({ t: 'exit', id }),
64
65
  onRekey: (from, to) => send({ t: 'rekey', from, to }),
66
+ onFork: (id, parent) => send({ t: 'fork', id, parent }),
65
67
  });
66
68
  pushState();
67
69
  }
package/lib/terminal.js CHANGED
@@ -351,12 +351,14 @@ function clientConfigFor(config, available) {
351
351
  * @param {(id: string) => string|null|Promise<string|null>} o.resolveCwd null = unknown session
352
352
  * @param {(id: string, exceptPid?: number) => boolean} o.isLiveElsewhere
353
353
  * @param {(dir: string) => boolean|Promise<boolean>} o.isAllowedFolder where a new session may start
354
+ * @param {(id: string) => string|null|Promise<string|null>} [o.shellRun] a command a new shell-mode PTY types and runs
354
355
  * @param {() => {pid: number|null, sessionId: string, cwd: string|null, startedAt: number}[]} o.liveSessions
355
356
  * claude's live-session registry, read fresh
356
357
  * @param {(cmd: string) => string|null} o.which
357
358
  * @param {string} [o.token]
358
359
  * @param {() => void} [o.onChange] a terminal started, ended or moved to another session id
359
360
  * @param {(from: string, to: string) => void} [o.onRekey] a terminal moved to another session id
361
+ * @param {(id: string, parent: string) => void} [o.onFork] a terminal started a fork of the parent session
360
362
  * @param {() => {sessions?: string[], taskLists?: Object<string, string>}|null} [o.load] the saved list, read when config.restore is on
361
363
  * @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
364
  * @param {object} [o.pty] stands in for @lydell/node-pty in tests
@@ -526,10 +528,12 @@ function createTerminalService(o) {
526
528
  // is the claude command typed at the shell prompt once the shell's startup output settles,
527
529
  // and Enter is left to the user; bracketed paste keeps a prompt's line breaks from running
528
530
  // the command early (checked in Git Bash and pwsh).
529
- function queueText(s, raw, submit) {
531
+ // `run` is a one-line command for the shell itself, typed plain and run with Enter, since cmd
532
+ // knows no bracketed paste.
533
+ function queueText(s, raw, submit, run = false) {
530
534
  let armed = !submit;
531
535
  let timer = null;
532
- const text = bracketed(raw);
536
+ const text = run ? `${raw}\r` : bracketed(raw);
533
537
  s.onOutput = (data) => {
534
538
  if (submit) {
535
539
  const on = data.lastIndexOf('\x1b[?2004h');
@@ -672,8 +676,10 @@ function createTerminalService(o) {
672
676
  name: spec?.name || null, worktree: spec?.worktree || false, taskList, onOutput: null, awaitingTrust: false, edit: !!spec?.edit,
673
677
  forkOf: spec?.forkOf || null, resumeOf: spec?.resume || null, restore: spec?.restore !== false, prompted: !!spec?.prompt,
674
678
  };
679
+ if (s.forkOf) o.onFork?.(id, s.forkOf);
675
680
  if (s.edit) queueText(s, claudeCommand(shell, claudeArgs, spec.prompt), false);
676
681
  else if (spec?.prompt) queueText(s, spec.prompt, true);
682
+ else if (spec?.run) queueText(s, spec.run, false, true);
677
683
  if (mode === 'pick') watchPick(s);
678
684
 
679
685
  proc.onData((data) => {
@@ -857,6 +863,9 @@ function createTerminalService(o) {
857
863
  }
858
864
  } else if (mode !== 'shell' && known === null) {
859
865
  return { code: 4004, status: 404, error: 'unknown session' };
866
+ } else if (mode === 'shell' && !spec) {
867
+ const run = await o.shellRun?.(id);
868
+ if (run) spec = { run };
860
869
  }
861
870
  if (shuttingDown) return { code: 1001, status: 503, error: 'the terminal is shutting down' };
862
871
  const running = sessions.get(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-kanban",
3
- "version": "7.28.0",
3
+ "version": "7.30.0",
4
4
  "description": "A web-based Kanban board for viewing Claude Code tasks with agent teams support",
5
5
  "main": "server.js",
6
6
  "type": "commonjs",