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/public/index.html CHANGED
@@ -980,9 +980,12 @@
980
980
  </div>
981
981
  <input id="pane-pop-input" class="form-input" placeholder="Search linked docs, or paste a URL or a file path" autocomplete="off" data-bwignore data-1p-ignore data-lpignore="true" spellcheck="false">
982
982
  <div id="pane-pop-detect" class="pane-pop-detect"></div>
983
+ <button id="pane-pop-shell" class="pane-pop-row pane-pop-shell" type="button" onclick="addShellPane()" title="A plain shell, no claude, in the session's folder or the folder typed above (Ctrl+Enter)">
984
+ <svg class="kind" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg><span>New shell</span><span class="pane-pop-shell-dir"></span>
985
+ </button>
983
986
  <div class="pane-pop-label">Linked docs</div>
984
987
  <div id="pane-pop-docs" class="pane-pop-docs"></div>
985
- <div class="sp-hint"><kbd>Enter</kbd> add &middot; <kbd>&uarr;</kbd><kbd>&darr;</kbd> select &middot; <kbd>Esc</kbd> close</div>
988
+ <div class="sp-hint"><kbd>Enter</kbd> add &middot; <kbd>Ctrl</kbd><kbd>Enter</kbd> new shell &middot; <kbd>&uarr;</kbd><kbd>&darr;</kbd> select &middot; <kbd>Esc</kbd> close</div>
986
989
  </div>
987
990
  </div>
988
991
 
package/public/style.css CHANGED
@@ -5612,6 +5612,21 @@ body.show-resizing iframe {
5612
5612
  border-top: 1px solid var(--border);
5613
5613
  }
5614
5614
 
5615
+ .pane-pop-shell {
5616
+ margin: 0 -6px;
5617
+ width: calc(100% + 12px);
5618
+ }
5619
+
5620
+ .pane-pop-shell[hidden] {
5621
+ display: none;
5622
+ }
5623
+
5624
+ .pane-pop-shell-dir {
5625
+ margin-left: auto;
5626
+ color: var(--text-muted);
5627
+ font-size: 11px;
5628
+ }
5629
+
5615
5630
  .pane-pop-label {
5616
5631
  margin: 6px 2px;
5617
5632
  color: var(--text-muted);
package/server.js CHANGED
@@ -77,6 +77,7 @@ const { createDispatchedStore, scanTranscripts, pruneSessionDirs, pruneContextSt
77
77
  const { freshRateLimits } = require('./lib/rate-limits');
78
78
  const { createWorktreeStore } = require('./lib/worktrees');
79
79
  const { createScratchpadDirResolver, scratchpadRoot } = require('./lib/scratchpad-dir');
80
+ const { createScratchServers } = require('./lib/scratch-servers');
80
81
  const { readSettings } = require('./lib/claude-settings');
81
82
  const { readGitBranch, sessionGitBranch } = require('./lib/git-branch');
82
83
  const { createLinkedDocStore, linkUrl } = require('./lib/linked-docs');
@@ -125,6 +126,7 @@ const SHOW_DIR = path.join(CCK_DIR, 'show');
125
126
  const PINS_FILE = path.join(CCK_DIR, 'pins.json');
126
127
  const USER_GROUPS_FILE = path.join(CCK_DIR, 'groups.json');
127
128
  const DISPATCHED_FILE = path.join(CCK_DIR, 'dispatched.json');
129
+ const FORKS_FILE = path.join(CCK_DIR, 'forks.json');
128
130
  const WORKTREES_FILE = path.join(CCK_DIR, 'worktrees.json');
129
131
  const LINKED_DOCS_FILE = path.join(CCK_DIR, 'linked-docs.json');
130
132
  const PANES_FILE = path.join(CCK_DIR, 'panes.json');
@@ -1555,6 +1557,11 @@ app.get('/api/sessions', async (req, res) => {
1555
1557
  // comes from lookupParentSession, not from the anchor's presence.
1556
1558
  const compactSuppressed = new Set();
1557
1559
  for (const [sid] of sessionsMap) {
1560
+ const fork = forks.get(sid);
1561
+ if (fork) {
1562
+ sessionsMap.get(sid).forkedFromSessionId = fork.parent;
1563
+ continue;
1564
+ }
1558
1565
  // Cheap pre-gate: only a session with a boundary anchor can be a continuation,
1559
1566
  // and lookupParentSession reads JSONLs on a cold cache. A fork with no boundary
1560
1567
  // gets its badge only once a verdict exists (the info modal computes one).
@@ -2384,21 +2391,43 @@ function resolveScratchpad(value) {
2384
2391
  const target = assertOpenTarget(value, 'path');
2385
2392
  const dir = path.basename(target).toLowerCase() === SCRATCHPAD_MANIFEST ? path.dirname(target) : target;
2386
2393
  if (!existsSync(path.join(dir, SCRATCHPAD_MANIFEST))) throw previewError(400, 'Not a scratchpad');
2387
- return { name: path.basename(dir), parent: path.dirname(dir) };
2394
+ return { dir, name: path.basename(dir), parent: path.dirname(dir) };
2395
+ }
2396
+
2397
+ // .cmd/.bat cannot be spawned without a shell since the CVE-2024-27980 fix;
2398
+ // scratch ships a real .exe, so resolve it rather than reintroducing one.
2399
+ function scratchExecutable() {
2400
+ const bin = whichSync('scratch');
2401
+ if (!bin) return { error: 'scratch CLI not found on PATH' };
2402
+ const ext = path.extname(bin).toLowerCase();
2403
+ const file = ext === '.cmd' || ext === '.bat' ? exeBehindShim(bin) : bin;
2404
+ return file ? { file } : { error: 'scratch CLI cannot be launched without a shell' };
2388
2405
  }
2389
2406
 
2407
+ const scratchServers = createScratchServers({
2408
+ resolveBin: () => scratchExecutable().file || null,
2409
+ spawn,
2410
+ onExit: (pad) => broadcast({ type: 'scratchpad:exited', manifest: `${pad}/${SCRATCHPAD_MANIFEST}` }),
2411
+ });
2412
+
2413
+ // API: The URL of a pad's browser viewer for a scratchpad pane, started on first use.
2414
+ app.post('/api/scratchpad/serve', async (req, res) => {
2415
+ try {
2416
+ res.json({ url: await scratchServers.serve(resolveScratchpad(req.body?.path).dir) });
2417
+ } catch (error) {
2418
+ if (error.status) return res.status(error.status).json({ error: error.message });
2419
+ console.error('Error serving scratchpad:', error.message);
2420
+ res.status(502).json({ error: error.message });
2421
+ }
2422
+ });
2423
+
2390
2424
  // API: Open a scratchpad in the external `scratch` viewer — the window outlives
2391
2425
  // this request and cck never waits on it.
2392
2426
  app.post('/api/scratchpad/open', (req, res) => {
2393
2427
  try {
2394
- const bin = whichSync('scratch');
2395
- if (!bin) return res.status(501).json({ error: 'scratch CLI not found on PATH' });
2428
+ const { file, error } = scratchExecutable();
2429
+ if (!file) return res.status(501).json({ error });
2396
2430
  const { name, parent } = resolveScratchpad(req.body?.path);
2397
- // .cmd/.bat cannot be spawned without a shell since the CVE-2024-27980 fix;
2398
- // scratch ships a real .exe, so resolve it rather than reintroducing one.
2399
- const ext = path.extname(bin).toLowerCase();
2400
- const file = ext === '.cmd' || ext === '.bat' ? exeBehindShim(bin) : bin;
2401
- if (!file) return res.status(501).json({ error: 'scratch CLI cannot be launched without a shell' });
2402
2431
  // `scratch ui` is a foreground supervisor: it reloads the window on edits and
2403
2432
  // quits on stdin EOF. So stdin must be an open pipe we never write to —
2404
2433
  // 'ignore' is /dev/null, which reads as EOF and closes the viewer at once.
@@ -3309,6 +3338,8 @@ function isAllowedFolder(dir) {
3309
3338
  // Restore runs before the first full metadata scan, so until that scan has run a session's
3310
3339
  // folder is read from its own JSONL, by the same rules the scan uses.
3311
3340
  function resolveSessionFolder(id) {
3341
+ const shell = panes.shellPane(id);
3342
+ if (shell) return shell.cwd || null;
3312
3343
  if (lastMetadataRefresh || !isSafeId(id)) {
3313
3344
  const meta = loadSessionMetadata()[id];
3314
3345
  return meta ? meta.project || meta.cwd || null : null;
@@ -3358,13 +3389,20 @@ const terminal = createTerminalClient({
3358
3389
  // The project, not the last cwd: `claude --resume` finds a session under the
3359
3390
  // project dir it started in, and cwd drifts into subdirectories.
3360
3391
  resolveCwd: resolveSessionFolder,
3392
+ shellRun: (id) => panes.shellPane(id)?.run || null,
3361
3393
  isAllowedFolder,
3362
3394
  onChange: () => broadcast({ type: 'terminals-update', ids: terminal.ids(), awaitingTrust: terminal.awaitingTrust() }),
3363
3395
  onExit: (id) => {
3364
3396
  if (dispatched.get(id)) broadcast({ type: 'dispatch-update' });
3365
3397
  },
3366
3398
  onRekey: (from, to) => {
3367
- if (dispatched.move(from, to)) broadcast({ type: 'dispatch-update' });
3399
+ const moved = dispatched.move(from, to);
3400
+ if (forks.move(from, to) || moved) broadcast({ type: 'dispatch-update' });
3401
+ },
3402
+ onFork: (id, parent) => {
3403
+ if (!isUUID(id) || !isUUID(parent) || forks.get(id)) return;
3404
+ forks.record(id, { parent, child: true });
3405
+ broadcast({ type: 'dispatch-update' });
3368
3406
  },
3369
3407
  });
3370
3408
 
@@ -3490,6 +3528,7 @@ app.get('/api/terminals', terminalRoute(async (_req, res) => {
3490
3528
  res.json({
3491
3529
  sessions: sessions.map((t) => {
3492
3530
  if (t.id === kanbot.ptyId) return { ...t, kanbot: true };
3531
+ if (t.mode === 'shell' && panes.shellPane(t.id)) return { ...t, pane: true };
3493
3532
  const marker = dispatched.get(t.id);
3494
3533
  return marker ? { ...t, dispatched: { parent: marker.parent || null } } : t;
3495
3534
  }),
@@ -3569,13 +3608,23 @@ app.get('/vendor/xterm/:file', (req, res) => {
3569
3608
 
3570
3609
  // #region DISPATCH
3571
3610
  const dispatched = createDispatchedStore(jsonFile(DISPATCHED_FILE));
3611
+ // Forks started from the board's Fork menu: same shape, no dispatch semantics.
3612
+ const forks = createDispatchedStore(jsonFile(FORKS_FILE));
3572
3613
 
3573
3614
  const linkedDocs = createLinkedDocStore(jsonFile(LINKED_DOCS_FILE));
3574
3615
 
3616
+ const nestStoreOf = (id) => (dispatched.get(id) ? dispatched : forks.get(id) ? forks : null);
3617
+
3575
3618
  function withDispatchMarker(sessions) {
3576
3619
  return sessions.map((s) => {
3577
3620
  const marker = dispatched.get(s.id);
3578
- return marker ? { ...s, dispatched: { parent: marker.parent, child: marker.child } } : s;
3621
+ const nest = marker || forks.get(s.id);
3622
+ if (!nest) return s;
3623
+ return {
3624
+ ...s,
3625
+ ...(marker ? { dispatched: { parent: marker.parent, child: marker.child } } : {}),
3626
+ nest: { parent: nest.parent, child: nest.child },
3627
+ };
3579
3628
  });
3580
3629
  }
3581
3630
 
@@ -3618,10 +3667,10 @@ app.post('/api/dispatch', terminalRoute(async (req, res) => {
3618
3667
  app.post('/api/dispatch/:id/child', (req, res) => {
3619
3668
  const { child } = req.body || {};
3620
3669
  if (typeof child !== 'boolean') return res.status(400).json({ error: 'child must be true or false' });
3621
- const marker = dispatched.get(req.params.id);
3622
- if (!marker) return res.status(404).json({ error: 'not a dispatched session' });
3623
- if (child && !marker.parent) return res.status(400).json({ error: 'child needs a parent session' });
3624
- if (dispatched.setChild(req.params.id, child)) broadcast({ type: 'dispatch-update' });
3670
+ const store = nestStoreOf(req.params.id);
3671
+ if (!store) return res.status(404).json({ error: 'not a dispatched session or a fork started from the board' });
3672
+ if (child && !store.get(req.params.id).parent) return res.status(400).json({ error: 'child needs a parent session' });
3673
+ if (store.setChild(req.params.id, child)) broadcast({ type: 'dispatch-update' });
3625
3674
  res.json({ session: req.params.id, child });
3626
3675
  });
3627
3676
 
@@ -4407,6 +4456,35 @@ async function resolvePaneTarget(target, base) {
4407
4456
  return { kind, target: await fs.realpath(abs) };
4408
4457
  }
4409
4458
 
4459
+ // The pad's manifest, so the pane's Open and Copy act on the same path as its linked-doc row.
4460
+ async function resolveScratchpadPane(target) {
4461
+ return { kind: 'scratchpad', target: await fs.realpath(path.join(resolveScratchpad(target).dir, SCRATCHPAD_MANIFEST)) };
4462
+ }
4463
+
4464
+ const MAX_SHELL_RUN = 1000;
4465
+
4466
+ // The target names the folder; the pane's target becomes a fresh PTY id, which the board's frame
4467
+ // starts in shell mode on first attach. `resolveSessionFolder` gives that id the folder, and
4468
+ // `shellRun` the command each start of the shell types and runs.
4469
+ async function resolveShellPane(target, _base, run) {
4470
+ const reason = terminal.unavailableReason();
4471
+ if (reason) throw previewError(409, `The terminal is off: ${reason}`, 'terminal_off');
4472
+ if (!path.isAbsolute(target) || !isAllowedFolder(target)) {
4473
+ throw previewError(400, 'A shell pane needs an absolute path to an existing folder', 'bad_target');
4474
+ }
4475
+ if (run !== undefined && (typeof run !== 'string' || /[\r\n]/.test(run) || run.length > MAX_SHELL_RUN)) {
4476
+ throw previewError(400, `run must be one line of at most ${MAX_SHELL_RUN} characters`, 'bad_run');
4477
+ }
4478
+ return { kind: 'shell', target: crypto.randomUUID(), cwd: await fs.realpath(target), run: run?.trim() || undefined };
4479
+ }
4480
+
4481
+ // A message target is a session log message id, which the board resolves when it shows the pane.
4482
+ const PANE_RESOLVERS = new Map([
4483
+ ['message', async (target) => ({ kind: 'message', target })],
4484
+ ['scratchpad', resolveScratchpadPane],
4485
+ ['shell', resolveShellPane],
4486
+ ]);
4487
+
4410
4488
  app.get('/api/panes/:sessionId', (req, res) => {
4411
4489
  res.setHeader('Cache-Control', 'no-store');
4412
4490
  res.json(panes.get(req.params.sessionId));
@@ -4414,10 +4492,9 @@ app.get('/api/panes/:sessionId', (req, res) => {
4414
4492
 
4415
4493
  app.post('/api/panes/:sessionId', async (req, res) => {
4416
4494
  try {
4417
- const { target, base, title, kind, show } = req.body || {};
4495
+ const { target, base, title, kind, show, run } = req.body || {};
4418
4496
  if (typeof target !== 'string' || !target) throw previewError(400, 'target is required', 'bad_target');
4419
- // A message target is a session log message id, which the board resolves when it shows the pane.
4420
- const resolved = kind === 'message' ? { kind, target } : await resolvePaneTarget(target, base);
4497
+ const resolved = await (PANE_RESOLVERS.get(kind) ?? resolvePaneTarget)(target, base, run);
4421
4498
  res.json(panes.add(req.params.sessionId, { ...resolved, title, show: show === true }));
4422
4499
  } catch (error) {
4423
4500
  paneRouteError(res, error, 'POST /api/panes');
@@ -4470,8 +4547,10 @@ app.patch('/api/panes/:sessionId/:paneId', (req, res) => {
4470
4547
 
4471
4548
  app.delete('/api/panes/:sessionId/:paneId', (req, res) => {
4472
4549
  const { sessionId, paneId } = req.params;
4550
+ const pane = panes.get(sessionId).panes.find((p) => p.id === paneId);
4473
4551
  const layout = panes.remove(sessionId, paneId);
4474
4552
  if (!layout) return res.status(404).json({ error: `No pane ${paneId} in session ${sessionId}`, code: 'no_pane' });
4553
+ if (pane?.kind === 'shell') terminal.end(pane.target, terminal.token).catch(() => {});
4475
4554
  res.json({ layout });
4476
4555
  });
4477
4556
  // #endregion
@@ -5025,6 +5104,7 @@ async function runRetention() {
5025
5104
  const scan = await scanTranscripts(PROJECTS_DIR);
5026
5105
  const opts = { known: scan?.ids, maxAgeMs: retentionMs(CLAUDE_DIR) };
5027
5106
  const markers = dispatched.prune(opts);
5107
+ const forkMarkers = forks.prune(opts);
5028
5108
  const layouts = panes.prune(opts);
5029
5109
  if (layouts) queuePaneFileWatch();
5030
5110
  const addonSessions = addons.prune(opts);
@@ -5035,8 +5115,8 @@ async function runRetention() {
5035
5115
  const wts = worktrees.prune(scan?.dirs);
5036
5116
  const taskMaps = await pruneTaskMaps(TASK_MAPS_DIR, opts);
5037
5117
  const grouped = expireGroupMembers(scan?.ids);
5038
- if (markers || layouts || addonSessions || reviews || attachments || shows || contexts || wts || taskMaps || grouped.members) {
5039
- console.log(`[retention] removed ${markers} dispatch markers, ${layouts} pane layouts, ${addonSessions} add-on sessions, ${reviews} reviews, ${attachments} attachments, ${shows} show files, ${contexts} context status files, ${wts} worktrees, ${taskMaps} task-list mappings, ${grouped.members} group members, ${grouped.groups} groups`);
5118
+ if (markers || forkMarkers || layouts || addonSessions || reviews || attachments || shows || contexts || wts || taskMaps || grouped.members) {
5119
+ console.log(`[retention] removed ${markers} dispatch markers, ${forkMarkers} fork markers, ${layouts} pane layouts, ${addonSessions} add-on sessions, ${reviews} reviews, ${attachments} attachments, ${shows} show files, ${contexts} context status files, ${wts} worktrees, ${taskMaps} task-list mappings, ${grouped.members} group members, ${grouped.groups} groups`);
5040
5120
  }
5041
5121
  } catch (e) {
5042
5122
  console.warn('[retention] failed:', e.message);