claude-code-kanban 7.27.0 → 7.29.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/lib/panes.js +8 -2
- package/lib/scratch-servers.js +119 -0
- package/package.json +1 -1
- package/public/app.js +105 -27
- package/public/index.html +3 -0
- package/public/style.css +2 -1
- package/server.js +43 -10
package/lib/panes.js
CHANGED
|
@@ -12,7 +12,7 @@ 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
|
+
const KINDS = new Set([...FILE_KINDS, 'url', 'message', 'scratchpad']);
|
|
16
16
|
const MAX_MESSAGE_TARGET = 300;
|
|
17
17
|
const isFileKind = (kind) => FILE_KINDS.has(kind);
|
|
18
18
|
|
|
@@ -42,10 +42,16 @@ function isOwnOrigin(url, { boardPort, boardHosts = [], hubUrl }) {
|
|
|
42
42
|
|
|
43
43
|
const emptyLayout = () => ({ rev: 0, nextId: 1, panes: [], updatedAt: null });
|
|
44
44
|
|
|
45
|
-
const targetKey = (kind, target) =>
|
|
45
|
+
const targetKey = (kind, target) =>
|
|
46
|
+
isFileKind(kind)
|
|
47
|
+
? `file:${canonicalPath(target)}`
|
|
48
|
+
: kind === 'scratchpad'
|
|
49
|
+
? `scratchpad:${canonicalPath(target)}`
|
|
50
|
+
: `${kind}:${target}`;
|
|
46
51
|
|
|
47
52
|
function defaultTitle(kind, target) {
|
|
48
53
|
if (kind === 'message') return 'Message';
|
|
54
|
+
if (kind === 'scratchpad') return path.basename(path.dirname(target));
|
|
49
55
|
if (kind !== 'url') return path.basename(target);
|
|
50
56
|
try {
|
|
51
57
|
return new URL(target).host;
|
|
@@ -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 };
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -9782,6 +9782,7 @@ async function sendPreviewAction(frame, msg) {
|
|
|
9782
9782
|
//#region MARKDOWN_PREVIEW
|
|
9783
9783
|
const PREVIEW_STORAGE_PREFIX = 'preview-paths-';
|
|
9784
9784
|
let currentPreviewPath = null;
|
|
9785
|
+
let currentPreviewContent = null;
|
|
9785
9786
|
// The session a CLI preview was sent for, which need not be the one on screen.
|
|
9786
9787
|
let previewSessionId = null;
|
|
9787
9788
|
let previewFromTerminal = false;
|
|
@@ -10007,6 +10008,8 @@ function localImageUrl(src, base) {
|
|
|
10007
10008
|
|
|
10008
10009
|
function openPreviewModal(filePath, content, kind, sessionId) {
|
|
10009
10010
|
currentPreviewPath = filePath;
|
|
10011
|
+
currentPreviewContent = kind === 'image' ? null : content;
|
|
10012
|
+
document.getElementById('preview-copy-content-btn').style.display = currentPreviewContent == null ? 'none' : '';
|
|
10010
10013
|
previewSessionId = sessionId;
|
|
10011
10014
|
const fileName = filePath.split(/[\\/]/).pop();
|
|
10012
10015
|
document.getElementById('preview-modal-title').textContent = fileName;
|
|
@@ -10106,6 +10109,7 @@ function closePreviewModal() {
|
|
|
10106
10109
|
// Empty the body so an iframe preview is destroyed and its scripts/timers stop.
|
|
10107
10110
|
document.getElementById('preview-modal-body').innerHTML = '';
|
|
10108
10111
|
currentPreviewPath = null;
|
|
10112
|
+
currentPreviewContent = null;
|
|
10109
10113
|
previewSessionId = null;
|
|
10110
10114
|
if (previewFromTerminal) focusTerminalPane();
|
|
10111
10115
|
previewFromTerminal = false;
|
|
@@ -10299,7 +10303,7 @@ const LINKED_DOC_OPENERS = {
|
|
|
10299
10303
|
url: { tag: '', hint: ' — opens in a new tab', cls: ' is-url', noun: 'URL' },
|
|
10300
10304
|
scratch: {
|
|
10301
10305
|
tag: '(scratchpad)',
|
|
10302
|
-
hint: ' — opens in the scratch viewer',
|
|
10306
|
+
hint: ' — opens in the scratch viewer; Ctrl+click opens it in a pane',
|
|
10303
10307
|
cls: ' is-editor',
|
|
10304
10308
|
noun: 'path',
|
|
10305
10309
|
url: '/api/scratchpad/open',
|
|
@@ -10762,6 +10766,9 @@ function bindLinkedDocsHandlers(container, sessionId) {
|
|
|
10762
10766
|
removeSessionPreviewPath(sessionId, hit.dataset.path);
|
|
10763
10767
|
forgetServerLinkedDoc(sessionId, hit.dataset.path);
|
|
10764
10768
|
afterLinkedDocsChanged(sessionId);
|
|
10769
|
+
} else if ((e.ctrlKey || e.metaKey) && linkedDocOpener(hit.dataset.path) === 'scratch') {
|
|
10770
|
+
if (container.closest('#team-modal')) closeTeamModal();
|
|
10771
|
+
openScratchpadPane(sessionId, hit.dataset.path);
|
|
10765
10772
|
} else {
|
|
10766
10773
|
openLinkedDoc(hit.dataset.path, getSessionBaseDir(sessionId));
|
|
10767
10774
|
}
|
|
@@ -10882,6 +10889,8 @@ function setupEventSource() {
|
|
|
10882
10889
|
fetchSessions().catch(() => {});
|
|
10883
10890
|
if (currentSessionId) fetchTasks(currentSessionId);
|
|
10884
10891
|
refetchPaneLayout();
|
|
10892
|
+
// A restarted board started none of the viewers the frames still point at.
|
|
10893
|
+
onScratchpadExited(null);
|
|
10885
10894
|
if (sgRev === null) syncSessionGroups();
|
|
10886
10895
|
else if (sgUnsent) persistSessionGroups();
|
|
10887
10896
|
else sgRefresh();
|
|
@@ -11021,6 +11030,10 @@ function setupEventSource() {
|
|
|
11021
11030
|
applyPaneLayout(data.sessionId, data.layout);
|
|
11022
11031
|
}
|
|
11023
11032
|
|
|
11033
|
+
if (data.type === 'scratchpad:exited') {
|
|
11034
|
+
onScratchpadExited(data.manifest);
|
|
11035
|
+
}
|
|
11036
|
+
|
|
11024
11037
|
if (data.type === 'addon:changed' && dockSid) {
|
|
11025
11038
|
fetchDockAddons(dockSid);
|
|
11026
11039
|
}
|
|
@@ -12946,20 +12959,6 @@ function showInfoModal(session, teamConfig, tasks, planContent, parentInfo) {
|
|
|
12946
12959
|
if (session.slug && session.hasPlan) {
|
|
12947
12960
|
infoRows.push(['Slug', session.slug, { openClaudeDir: true, openFile: session.planPath }]);
|
|
12948
12961
|
}
|
|
12949
|
-
if (session.project) {
|
|
12950
|
-
const projectName = session.project.split(/[/\\]/).pop();
|
|
12951
|
-
infoRows.push(['Project', projectName, { openPath: session.projectDir }]);
|
|
12952
|
-
infoRows.push(['Path', session.project, { openPath: session.project }]);
|
|
12953
|
-
if (session.cwd) {
|
|
12954
|
-
infoRows.push(['CWD', session.cwd, { openPath: session.cwd }]);
|
|
12955
|
-
}
|
|
12956
|
-
if (session.gitBranch) {
|
|
12957
|
-
infoRows.push(['Branch', session.gitBranch]);
|
|
12958
|
-
}
|
|
12959
|
-
if (session.description) {
|
|
12960
|
-
infoRows.push(['Description', session.description]);
|
|
12961
|
-
}
|
|
12962
|
-
}
|
|
12963
12962
|
if (session.tasksDir) {
|
|
12964
12963
|
infoRows.push(['Tasks Dir', session.tasksDir, { openPath: session.tasksDir }]);
|
|
12965
12964
|
}
|
|
@@ -12977,12 +12976,25 @@ function showInfoModal(session, teamConfig, tasks, planContent, parentInfo) {
|
|
|
12977
12976
|
const configDir = teamConfig.configPath.replace(/[/\\][^/\\]+$/, '');
|
|
12978
12977
|
infoRows.push(['Team Config', teamConfig.configPath, { openPath: configDir, openFile: teamConfig.configPath }]);
|
|
12979
12978
|
}
|
|
12979
|
+
const projectRows = [];
|
|
12980
|
+
if (session.project) {
|
|
12981
|
+
projectRows.push(['Project', session.project, { openPath: session.project }]);
|
|
12982
|
+
if (session.cwd) {
|
|
12983
|
+
projectRows.push(['Working directory', session.cwd, { openPath: session.cwd }]);
|
|
12984
|
+
}
|
|
12985
|
+
if (session.gitBranch) {
|
|
12986
|
+
projectRows.push(['Branch', session.gitBranch]);
|
|
12987
|
+
}
|
|
12988
|
+
if (session.description) {
|
|
12989
|
+
projectRows.push(['Description', session.description]);
|
|
12990
|
+
}
|
|
12991
|
+
}
|
|
12980
12992
|
const clickableStyle =
|
|
12981
12993
|
'font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; color: var(--accent-text); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px;';
|
|
12982
12994
|
const plainStyle =
|
|
12983
12995
|
'font-family: var(--mono); font-size: 12px; color: var(--text-primary); user-select: all; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;';
|
|
12984
12996
|
html += `<div class="team-modal-meta info-grid">`;
|
|
12985
|
-
|
|
12997
|
+
const renderRow = ([label, value, opts]) => {
|
|
12986
12998
|
html += `<span style="font-weight: 500; color: var(--text-secondary); font-size: 12px; white-space: nowrap;">${label}</span>`;
|
|
12987
12999
|
if (opts?.openSession) {
|
|
12988
13000
|
html += `<span onclick="openSessionFromInfo('${escAttrJs(opts.openSession)}')" style="${clickableStyle}" title="Open session in app">${escapeHtml(value)}</span>`;
|
|
@@ -12997,7 +13009,12 @@ function showInfoModal(session, teamConfig, tasks, planContent, parentInfo) {
|
|
|
12997
13009
|
openBtn = `<button data-folder="${folder}" data-file="${file}" data-claude-dir="${opts.openClaudeDir ? '1' : ''}" onclick="openFolderInEditor(this.dataset.claudeDir ? undefined : this.dataset.folder, this.dataset.file || undefined)" title="Open in editor">${ICON_OPEN_EXTERNAL}</button>`;
|
|
12998
13010
|
}
|
|
12999
13011
|
html += `<span class="row-actions">${copyBtn}${openBtn}</span>`;
|
|
13000
|
-
}
|
|
13012
|
+
};
|
|
13013
|
+
infoRows.forEach(renderRow);
|
|
13014
|
+
if (projectRows.length) {
|
|
13015
|
+
html += `<div class="stat-divider"></div>`;
|
|
13016
|
+
projectRows.forEach(renderRow);
|
|
13017
|
+
}
|
|
13001
13018
|
html += `</div>`;
|
|
13002
13019
|
|
|
13003
13020
|
const contextHtml = renderContextDetail(session);
|
|
@@ -14420,6 +14437,8 @@ const PANE_ICONS = {
|
|
|
14420
14437
|
file: '<svg class="kind" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',
|
|
14421
14438
|
message:
|
|
14422
14439
|
'<svg class="kind" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
|
|
14440
|
+
scratchpad:
|
|
14441
|
+
'<svg class="kind" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>',
|
|
14423
14442
|
warning:
|
|
14424
14443
|
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12" y2="17"/></svg>',
|
|
14425
14444
|
};
|
|
@@ -14671,6 +14690,18 @@ function paneUrlFrame(pane, className) {
|
|
|
14671
14690
|
return frame;
|
|
14672
14691
|
}
|
|
14673
14692
|
|
|
14693
|
+
function mountPaneUrlFrame(pane, view) {
|
|
14694
|
+
const frame = paneUrlFrame(pane, 'pane-frame pane-url-frame modal-zoomable');
|
|
14695
|
+
frame.addEventListener('load', () => {
|
|
14696
|
+
view.classList.remove('keys-bridged');
|
|
14697
|
+
frame.hostKeysSig = null;
|
|
14698
|
+
pushTerminalClaims();
|
|
14699
|
+
});
|
|
14700
|
+
view.appendChild(frame);
|
|
14701
|
+
view.insertAdjacentHTML('beforeend', paneUrlBarHtml());
|
|
14702
|
+
return frame;
|
|
14703
|
+
}
|
|
14704
|
+
|
|
14674
14705
|
async function loadPaneView(sid, pane, view, scroll) {
|
|
14675
14706
|
const blocked = paneBlockedHtml(pane);
|
|
14676
14707
|
if (blocked) {
|
|
@@ -14678,14 +14709,7 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14678
14709
|
return;
|
|
14679
14710
|
}
|
|
14680
14711
|
if (pane.kind === 'url') {
|
|
14681
|
-
const frame =
|
|
14682
|
-
frame.addEventListener('load', () => {
|
|
14683
|
-
view.classList.remove('keys-bridged');
|
|
14684
|
-
frame.hostKeysSig = null;
|
|
14685
|
-
pushTerminalClaims();
|
|
14686
|
-
});
|
|
14687
|
-
view.appendChild(frame);
|
|
14688
|
-
view.insertAdjacentHTML('beforeend', paneUrlBarHtml());
|
|
14712
|
+
const frame = mountPaneUrlFrame(pane, view);
|
|
14689
14713
|
// Framed at once; a refusal found by the probe swaps the frame for the card.
|
|
14690
14714
|
if ((await probePaneFraming(sid, pane)) === false) {
|
|
14691
14715
|
frame.remove();
|
|
@@ -14698,6 +14722,10 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14698
14722
|
await loadMessagePaneView(sid, pane, view);
|
|
14699
14723
|
return;
|
|
14700
14724
|
}
|
|
14725
|
+
if (pane.kind === 'scratchpad') {
|
|
14726
|
+
await loadScratchpadPaneView(pane, view);
|
|
14727
|
+
return;
|
|
14728
|
+
}
|
|
14701
14729
|
const data = await getJson('/api/preview', null, { query: { path: pane.target } });
|
|
14702
14730
|
if (data?.kind === 'html') {
|
|
14703
14731
|
// A show card's own zoom follows the text zoom (showBridge), so its frame is not .modal-zoomable.
|
|
@@ -14732,6 +14760,40 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14732
14760
|
view.insertAdjacentHTML('beforeend', paneCardHtml(title, text, button));
|
|
14733
14761
|
}
|
|
14734
14762
|
|
|
14763
|
+
// The viewer runs on its own loopback port, a different origin from the board and the hub, so the
|
|
14764
|
+
// URL pane sandbox holds. The board asks for the URL each time it mounts the view, because the
|
|
14765
|
+
// viewer dies with cck and is started again on demand.
|
|
14766
|
+
async function loadScratchpadPaneView(pane, view) {
|
|
14767
|
+
view.insertAdjacentHTML(
|
|
14768
|
+
'beforeend',
|
|
14769
|
+
'<div class="pane-card pane-starting"><div class="pane-card-box"><p>Starting the scratch viewer…</p></div></div>',
|
|
14770
|
+
);
|
|
14771
|
+
const res = await paneRequest('POST', '/api/scratchpad/serve', { path: pane.target });
|
|
14772
|
+
view.querySelector('.pane-starting')?.remove();
|
|
14773
|
+
if (!res.url) {
|
|
14774
|
+
view.insertAdjacentHTML(
|
|
14775
|
+
'beforeend',
|
|
14776
|
+
paneCardHtml('Scratch viewer unavailable', res.error || pane.target, 'Open in scratch viewer'),
|
|
14777
|
+
);
|
|
14778
|
+
return;
|
|
14779
|
+
}
|
|
14780
|
+
mountPaneUrlFrame({ ...pane, target: res.url }, view);
|
|
14781
|
+
}
|
|
14782
|
+
|
|
14783
|
+
// A viewer that exited leaves its frames on a dead port; the views on screen mount again now,
|
|
14784
|
+
// the others when shown.
|
|
14785
|
+
function onScratchpadExited(manifest) {
|
|
14786
|
+
const dead = [];
|
|
14787
|
+
for (const key of paneFrames.keys()) {
|
|
14788
|
+
const [sid, paneId] = key.split('/');
|
|
14789
|
+
const pane = paneLayout(sid).panes.find((p) => p.id === paneId);
|
|
14790
|
+
if (pane?.kind === 'scratchpad' && (!manifest || canonicalPath(pane.target) === manifest)) dead.push([sid, paneId]);
|
|
14791
|
+
}
|
|
14792
|
+
if (!dead.length) return;
|
|
14793
|
+
for (const [sid, paneId] of dead) unmountPane(sid, paneId);
|
|
14794
|
+
syncPanes();
|
|
14795
|
+
}
|
|
14796
|
+
|
|
14735
14797
|
// The target is the message's pin id, `type|timestamp|text`. The log holds only the latest pages,
|
|
14736
14798
|
// so a message not loaded comes from the page that ends at its timestamp.
|
|
14737
14799
|
async function findPaneMessage(sid, target) {
|
|
@@ -15108,7 +15170,7 @@ async function reloadPane(id) {
|
|
|
15108
15170
|
if (!pane) return;
|
|
15109
15171
|
const sid = paneSessionId();
|
|
15110
15172
|
const view = paneFrames.get(`${sid}/${pane.id}`);
|
|
15111
|
-
if (pane.kind !== 'url' && view) {
|
|
15173
|
+
if (pane.kind !== 'url' && pane.kind !== 'scratchpad' && view) {
|
|
15112
15174
|
await reloadPaneView(sid, pane, view);
|
|
15113
15175
|
} else {
|
|
15114
15176
|
unmountPane(sid, pane.id);
|
|
@@ -15319,7 +15381,16 @@ function openPaneMenu(x, y, id) {
|
|
|
15319
15381
|
'Pane actions',
|
|
15320
15382
|
paneMenuLabel(pane, label) +
|
|
15321
15383
|
(message ? '' : paneMenuItem('copy', url ? 'Copy URL' : 'Copy path')) +
|
|
15322
|
-
paneMenuItem(
|
|
15384
|
+
paneMenuItem(
|
|
15385
|
+
'open',
|
|
15386
|
+
url
|
|
15387
|
+
? 'Open in new tab'
|
|
15388
|
+
: message
|
|
15389
|
+
? 'Open in message dialog'
|
|
15390
|
+
: pane.kind === 'scratchpad'
|
|
15391
|
+
? 'Open in scratch viewer'
|
|
15392
|
+
: 'Open in preview',
|
|
15393
|
+
) +
|
|
15323
15394
|
(message
|
|
15324
15395
|
? ''
|
|
15325
15396
|
: paneMenuItem('link', paneIsLinked(pane) ? 'Remove from linked documents' : 'Add to linked documents')) +
|
|
@@ -15440,6 +15511,13 @@ function applyPaneLine(view) {
|
|
|
15440
15511
|
markSourceLine(body, line);
|
|
15441
15512
|
}
|
|
15442
15513
|
|
|
15514
|
+
// The same pad again returns its pane, so a second Ctrl+click only shows it.
|
|
15515
|
+
async function openScratchpadPane(sid, manifest) {
|
|
15516
|
+
const onScreen = await postPane(sid, { kind: 'scratchpad', target: manifest });
|
|
15517
|
+
if (onScreen) syncPanes();
|
|
15518
|
+
toastPaneAdded(sid, onScreen, linkedDocLabel(manifest));
|
|
15519
|
+
}
|
|
15520
|
+
|
|
15443
15521
|
async function openPaneAtLine(sid, { path, line }, base) {
|
|
15444
15522
|
const onScreen = await postPane(sid, { target: path, base });
|
|
15445
15523
|
if (onScreen === null) return;
|
package/public/index.html
CHANGED
|
@@ -508,6 +508,9 @@
|
|
|
508
508
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
|
|
509
509
|
</button>
|
|
510
510
|
<button class="icon-btn" aria-label="Copy path" title="Copy path" onclick="copyWithFeedback(currentPreviewPath, this)">
|
|
511
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="16" height="16"><path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>
|
|
512
|
+
</button>
|
|
513
|
+
<button id="preview-copy-content-btn" class="icon-btn" aria-label="Copy content" title="Copy content" onclick="copyWithFeedback(currentPreviewContent, this)">
|
|
511
514
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="16" height="16"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
|
|
512
515
|
</button>
|
|
513
516
|
<button class="icon-btn" aria-label="Open in editor" title="Open in editor" onclick="openPreviewInEditor()">
|
package/public/style.css
CHANGED
|
@@ -1422,7 +1422,8 @@ body.booting .boot-splash {
|
|
|
1422
1422
|
.detail-context-stats .stat-value {
|
|
1423
1423
|
color: var(--text-primary);
|
|
1424
1424
|
}
|
|
1425
|
-
.detail-context-stats .stat-divider
|
|
1425
|
+
.detail-context-stats .stat-divider,
|
|
1426
|
+
.info-grid .stat-divider {
|
|
1426
1427
|
grid-column: 1 / -1;
|
|
1427
1428
|
border-top: 1px solid var(--border);
|
|
1428
1429
|
margin: 2px 0;
|
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');
|
|
@@ -2384,21 +2385,43 @@ function resolveScratchpad(value) {
|
|
|
2384
2385
|
const target = assertOpenTarget(value, 'path');
|
|
2385
2386
|
const dir = path.basename(target).toLowerCase() === SCRATCHPAD_MANIFEST ? path.dirname(target) : target;
|
|
2386
2387
|
if (!existsSync(path.join(dir, SCRATCHPAD_MANIFEST))) throw previewError(400, 'Not a scratchpad');
|
|
2387
|
-
return { name: path.basename(dir), parent: path.dirname(dir) };
|
|
2388
|
+
return { dir, name: path.basename(dir), parent: path.dirname(dir) };
|
|
2388
2389
|
}
|
|
2389
2390
|
|
|
2391
|
+
// .cmd/.bat cannot be spawned without a shell since the CVE-2024-27980 fix;
|
|
2392
|
+
// scratch ships a real .exe, so resolve it rather than reintroducing one.
|
|
2393
|
+
function scratchExecutable() {
|
|
2394
|
+
const bin = whichSync('scratch');
|
|
2395
|
+
if (!bin) return { error: 'scratch CLI not found on PATH' };
|
|
2396
|
+
const ext = path.extname(bin).toLowerCase();
|
|
2397
|
+
const file = ext === '.cmd' || ext === '.bat' ? exeBehindShim(bin) : bin;
|
|
2398
|
+
return file ? { file } : { error: 'scratch CLI cannot be launched without a shell' };
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
const scratchServers = createScratchServers({
|
|
2402
|
+
resolveBin: () => scratchExecutable().file || null,
|
|
2403
|
+
spawn,
|
|
2404
|
+
onExit: (pad) => broadcast({ type: 'scratchpad:exited', manifest: `${pad}/${SCRATCHPAD_MANIFEST}` }),
|
|
2405
|
+
});
|
|
2406
|
+
|
|
2407
|
+
// API: The URL of a pad's browser viewer for a scratchpad pane, started on first use.
|
|
2408
|
+
app.post('/api/scratchpad/serve', async (req, res) => {
|
|
2409
|
+
try {
|
|
2410
|
+
res.json({ url: await scratchServers.serve(resolveScratchpad(req.body?.path).dir) });
|
|
2411
|
+
} catch (error) {
|
|
2412
|
+
if (error.status) return res.status(error.status).json({ error: error.message });
|
|
2413
|
+
console.error('Error serving scratchpad:', error.message);
|
|
2414
|
+
res.status(502).json({ error: error.message });
|
|
2415
|
+
}
|
|
2416
|
+
});
|
|
2417
|
+
|
|
2390
2418
|
// API: Open a scratchpad in the external `scratch` viewer — the window outlives
|
|
2391
2419
|
// this request and cck never waits on it.
|
|
2392
2420
|
app.post('/api/scratchpad/open', (req, res) => {
|
|
2393
2421
|
try {
|
|
2394
|
-
const
|
|
2395
|
-
if (!
|
|
2422
|
+
const { file, error } = scratchExecutable();
|
|
2423
|
+
if (!file) return res.status(501).json({ error });
|
|
2396
2424
|
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
2425
|
// `scratch ui` is a foreground supervisor: it reloads the window on edits and
|
|
2403
2426
|
// quits on stdin EOF. So stdin must be an open pipe we never write to —
|
|
2404
2427
|
// 'ignore' is /dev/null, which reads as EOF and closes the viewer at once.
|
|
@@ -4407,6 +4430,17 @@ async function resolvePaneTarget(target, base) {
|
|
|
4407
4430
|
return { kind, target: await fs.realpath(abs) };
|
|
4408
4431
|
}
|
|
4409
4432
|
|
|
4433
|
+
// The pad's manifest, so the pane's Open and Copy act on the same path as its linked-doc row.
|
|
4434
|
+
async function resolveScratchpadPane(target) {
|
|
4435
|
+
return { kind: 'scratchpad', target: await fs.realpath(path.join(resolveScratchpad(target).dir, SCRATCHPAD_MANIFEST)) };
|
|
4436
|
+
}
|
|
4437
|
+
|
|
4438
|
+
// A message target is a session log message id, which the board resolves when it shows the pane.
|
|
4439
|
+
const PANE_RESOLVERS = new Map([
|
|
4440
|
+
['message', async (target) => ({ kind: 'message', target })],
|
|
4441
|
+
['scratchpad', resolveScratchpadPane],
|
|
4442
|
+
]);
|
|
4443
|
+
|
|
4410
4444
|
app.get('/api/panes/:sessionId', (req, res) => {
|
|
4411
4445
|
res.setHeader('Cache-Control', 'no-store');
|
|
4412
4446
|
res.json(panes.get(req.params.sessionId));
|
|
@@ -4416,8 +4450,7 @@ app.post('/api/panes/:sessionId', async (req, res) => {
|
|
|
4416
4450
|
try {
|
|
4417
4451
|
const { target, base, title, kind, show } = req.body || {};
|
|
4418
4452
|
if (typeof target !== 'string' || !target) throw previewError(400, 'target is required', 'bad_target');
|
|
4419
|
-
|
|
4420
|
-
const resolved = kind === 'message' ? { kind, target } : await resolvePaneTarget(target, base);
|
|
4453
|
+
const resolved = await (PANE_RESOLVERS.get(kind) ?? resolvePaneTarget)(target, base);
|
|
4421
4454
|
res.json(panes.add(req.params.sessionId, { ...resolved, title, show: show === true }));
|
|
4422
4455
|
} catch (error) {
|
|
4423
4456
|
paneRouteError(res, error, 'POST /api/panes');
|