claude-code-kanban 7.28.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 +81 -11
- 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
|
@@ -10303,7 +10303,7 @@ const LINKED_DOC_OPENERS = {
|
|
|
10303
10303
|
url: { tag: '', hint: ' — opens in a new tab', cls: ' is-url', noun: 'URL' },
|
|
10304
10304
|
scratch: {
|
|
10305
10305
|
tag: '(scratchpad)',
|
|
10306
|
-
hint: ' — opens in the scratch viewer',
|
|
10306
|
+
hint: ' — opens in the scratch viewer; Ctrl+click opens it in a pane',
|
|
10307
10307
|
cls: ' is-editor',
|
|
10308
10308
|
noun: 'path',
|
|
10309
10309
|
url: '/api/scratchpad/open',
|
|
@@ -10766,6 +10766,9 @@ function bindLinkedDocsHandlers(container, sessionId) {
|
|
|
10766
10766
|
removeSessionPreviewPath(sessionId, hit.dataset.path);
|
|
10767
10767
|
forgetServerLinkedDoc(sessionId, hit.dataset.path);
|
|
10768
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);
|
|
10769
10772
|
} else {
|
|
10770
10773
|
openLinkedDoc(hit.dataset.path, getSessionBaseDir(sessionId));
|
|
10771
10774
|
}
|
|
@@ -10886,6 +10889,8 @@ function setupEventSource() {
|
|
|
10886
10889
|
fetchSessions().catch(() => {});
|
|
10887
10890
|
if (currentSessionId) fetchTasks(currentSessionId);
|
|
10888
10891
|
refetchPaneLayout();
|
|
10892
|
+
// A restarted board started none of the viewers the frames still point at.
|
|
10893
|
+
onScratchpadExited(null);
|
|
10889
10894
|
if (sgRev === null) syncSessionGroups();
|
|
10890
10895
|
else if (sgUnsent) persistSessionGroups();
|
|
10891
10896
|
else sgRefresh();
|
|
@@ -11025,6 +11030,10 @@ function setupEventSource() {
|
|
|
11025
11030
|
applyPaneLayout(data.sessionId, data.layout);
|
|
11026
11031
|
}
|
|
11027
11032
|
|
|
11033
|
+
if (data.type === 'scratchpad:exited') {
|
|
11034
|
+
onScratchpadExited(data.manifest);
|
|
11035
|
+
}
|
|
11036
|
+
|
|
11028
11037
|
if (data.type === 'addon:changed' && dockSid) {
|
|
11029
11038
|
fetchDockAddons(dockSid);
|
|
11030
11039
|
}
|
|
@@ -14428,6 +14437,8 @@ const PANE_ICONS = {
|
|
|
14428
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>',
|
|
14429
14438
|
message:
|
|
14430
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>',
|
|
14431
14442
|
warning:
|
|
14432
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>',
|
|
14433
14444
|
};
|
|
@@ -14679,6 +14690,18 @@ function paneUrlFrame(pane, className) {
|
|
|
14679
14690
|
return frame;
|
|
14680
14691
|
}
|
|
14681
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
|
+
|
|
14682
14705
|
async function loadPaneView(sid, pane, view, scroll) {
|
|
14683
14706
|
const blocked = paneBlockedHtml(pane);
|
|
14684
14707
|
if (blocked) {
|
|
@@ -14686,14 +14709,7 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14686
14709
|
return;
|
|
14687
14710
|
}
|
|
14688
14711
|
if (pane.kind === 'url') {
|
|
14689
|
-
const frame =
|
|
14690
|
-
frame.addEventListener('load', () => {
|
|
14691
|
-
view.classList.remove('keys-bridged');
|
|
14692
|
-
frame.hostKeysSig = null;
|
|
14693
|
-
pushTerminalClaims();
|
|
14694
|
-
});
|
|
14695
|
-
view.appendChild(frame);
|
|
14696
|
-
view.insertAdjacentHTML('beforeend', paneUrlBarHtml());
|
|
14712
|
+
const frame = mountPaneUrlFrame(pane, view);
|
|
14697
14713
|
// Framed at once; a refusal found by the probe swaps the frame for the card.
|
|
14698
14714
|
if ((await probePaneFraming(sid, pane)) === false) {
|
|
14699
14715
|
frame.remove();
|
|
@@ -14706,6 +14722,10 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14706
14722
|
await loadMessagePaneView(sid, pane, view);
|
|
14707
14723
|
return;
|
|
14708
14724
|
}
|
|
14725
|
+
if (pane.kind === 'scratchpad') {
|
|
14726
|
+
await loadScratchpadPaneView(pane, view);
|
|
14727
|
+
return;
|
|
14728
|
+
}
|
|
14709
14729
|
const data = await getJson('/api/preview', null, { query: { path: pane.target } });
|
|
14710
14730
|
if (data?.kind === 'html') {
|
|
14711
14731
|
// A show card's own zoom follows the text zoom (showBridge), so its frame is not .modal-zoomable.
|
|
@@ -14740,6 +14760,40 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14740
14760
|
view.insertAdjacentHTML('beforeend', paneCardHtml(title, text, button));
|
|
14741
14761
|
}
|
|
14742
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
|
+
|
|
14743
14797
|
// The target is the message's pin id, `type|timestamp|text`. The log holds only the latest pages,
|
|
14744
14798
|
// so a message not loaded comes from the page that ends at its timestamp.
|
|
14745
14799
|
async function findPaneMessage(sid, target) {
|
|
@@ -15116,7 +15170,7 @@ async function reloadPane(id) {
|
|
|
15116
15170
|
if (!pane) return;
|
|
15117
15171
|
const sid = paneSessionId();
|
|
15118
15172
|
const view = paneFrames.get(`${sid}/${pane.id}`);
|
|
15119
|
-
if (pane.kind !== 'url' && view) {
|
|
15173
|
+
if (pane.kind !== 'url' && pane.kind !== 'scratchpad' && view) {
|
|
15120
15174
|
await reloadPaneView(sid, pane, view);
|
|
15121
15175
|
} else {
|
|
15122
15176
|
unmountPane(sid, pane.id);
|
|
@@ -15327,7 +15381,16 @@ function openPaneMenu(x, y, id) {
|
|
|
15327
15381
|
'Pane actions',
|
|
15328
15382
|
paneMenuLabel(pane, label) +
|
|
15329
15383
|
(message ? '' : paneMenuItem('copy', url ? 'Copy URL' : 'Copy path')) +
|
|
15330
|
-
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
|
+
) +
|
|
15331
15394
|
(message
|
|
15332
15395
|
? ''
|
|
15333
15396
|
: paneMenuItem('link', paneIsLinked(pane) ? 'Remove from linked documents' : 'Add to linked documents')) +
|
|
@@ -15448,6 +15511,13 @@ function applyPaneLine(view) {
|
|
|
15448
15511
|
markSourceLine(body, line);
|
|
15449
15512
|
}
|
|
15450
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
|
+
|
|
15451
15521
|
async function openPaneAtLine(sid, { path, line }, base) {
|
|
15452
15522
|
const onScreen = await postPane(sid, { target: path, base });
|
|
15453
15523
|
if (onScreen === null) return;
|
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');
|