claude-code-kanban 7.29.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 +14 -5
- package/hub-app.json +1 -1
- package/lib/panes.js +17 -3
- package/lib/terminal-client.js +4 -0
- package/lib/terminal-host.js +2 -0
- package/lib/terminal.js +11 -2
- package/package.json +1 -1
- package/public/app.js +307 -73
- package/public/index.html +4 -1
- package/public/style.css +15 -0
- package/server.js +57 -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
|
{
|
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
|
|
package/lib/terminal-host.js
CHANGED
|
@@ -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
|
-
|
|
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
package/public/app.js
CHANGED
|
@@ -95,10 +95,11 @@ let sessionsHasMore = false;
|
|
|
95
95
|
// URL, so a query string would not survive a hub reload.
|
|
96
96
|
const ZEN_KEY = 'zenMode';
|
|
97
97
|
let zenMode = store.getItem(ZEN_KEY) === 'true';
|
|
98
|
-
// Group and project zen: the sidebar shows one group's subtree or one project.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
let
|
|
98
|
+
// Group and project zen: the sidebar shows one group's subtree or one project.
|
|
99
|
+
const ZEN_SCOPE_KEY = 'zenScope';
|
|
100
|
+
const savedZenScope = store.readJson(ZEN_SCOPE_KEY);
|
|
101
|
+
let zenGroup = typeof savedZenScope?.group === 'string' ? savedZenScope.group : null;
|
|
102
|
+
let zenProject = typeof savedZenScope?.project === 'string' ? savedZenScope.project : null;
|
|
102
103
|
let filterProject = FILTER_DEFAULTS.project; // null = all, '__recent__' = last 24h, or project path
|
|
103
104
|
let recentProjects = new Set();
|
|
104
105
|
let projectsCacheDirty = true;
|
|
@@ -264,9 +265,7 @@ function resetState() {
|
|
|
264
265
|
sessionLimit = SESSION_PAGE;
|
|
265
266
|
filterProject = FILTER_DEFAULTS.project;
|
|
266
267
|
zenMode = false;
|
|
267
|
-
|
|
268
|
-
zenProject = null;
|
|
269
|
-
setZenPeek(null);
|
|
268
|
+
setZenScope(null, null);
|
|
270
269
|
store.removeItem(ZEN_KEY);
|
|
271
270
|
renderZenState();
|
|
272
271
|
searchQuery = '';
|
|
@@ -803,6 +802,7 @@ async function fetchTasks(sessionId) {
|
|
|
803
802
|
if (currentSessionId && currentSessionId !== sessionId) deferredPinPlacement.delete(currentSessionId);
|
|
804
803
|
pushSwapHistory(sessionId);
|
|
805
804
|
const switched = sessionId !== currentSessionId;
|
|
805
|
+
if (switched) leaveZenScopeFor(sessionId);
|
|
806
806
|
currentSessionId = sessionId;
|
|
807
807
|
markOpenSessionRead();
|
|
808
808
|
if (switched) autoRevealLog(sessionId);
|
|
@@ -4333,23 +4333,21 @@ function renderSessions() {
|
|
|
4333
4333
|
refreshProjectList();
|
|
4334
4334
|
syncPinPeek();
|
|
4335
4335
|
|
|
4336
|
-
if (zenGroup && !sgGroupById(zenGroup)) {
|
|
4337
|
-
zenGroup = null;
|
|
4336
|
+
if (zenGroup && sgRev !== null && !sgGroupById(zenGroup)) {
|
|
4338
4337
|
zenPeekKey = null;
|
|
4338
|
+
setZenScope(null, null);
|
|
4339
4339
|
renderZenState();
|
|
4340
4340
|
}
|
|
4341
4341
|
// Zen narrows the rendered list only — the session picker keeps calling getFilteredSessions()
|
|
4342
4342
|
// and still offers everything, or there would be no way to switch sessions without leaving zen.
|
|
4343
4343
|
const zenSession = zenMode && currentSessionId ? sessions.find((s) => s.id === currentSessionId) : null;
|
|
4344
|
-
sessionsList.classList.toggle('zen', !!zenSession);
|
|
4345
|
-
sessionsList.dataset.zenState = zenSession ? sessionState(zenSession) : '';
|
|
4346
4344
|
const zenScope = !!(zenGroup || zenProject);
|
|
4345
|
+
sessionsList.classList.toggle('zen', !!zenSession || zenScope);
|
|
4346
|
+
sessionsList.dataset.zenState = zenSession ? sessionState(zenSession) : '';
|
|
4347
4347
|
let filteredSessions;
|
|
4348
4348
|
if (zenScope) {
|
|
4349
4349
|
const scoped = getFilteredSessions({ zen: true });
|
|
4350
|
-
filteredSessions = applyStableSessionOrder(
|
|
4351
|
-
zenProject ? scoped.filter((s) => sessionProjectKey(s) === zenProject) : scoped,
|
|
4352
|
-
);
|
|
4350
|
+
filteredSessions = applyStableSessionOrder(zenProject ? scoped.filter(inZenScope) : scoped);
|
|
4353
4351
|
} else if (zenMode) filteredSessions = zenSession ? [zenSession] : [];
|
|
4354
4352
|
else filteredSessions = applyStableSessionOrder(getFilteredSessions());
|
|
4355
4353
|
|
|
@@ -4360,7 +4358,7 @@ function renderSessions() {
|
|
|
4360
4358
|
for (const g of sessionGroups) for (const m of g.members) if (m.parent) parentOf.set(m.ref, m.parent);
|
|
4361
4359
|
childAnchors = computeChildAnchors(filteredSessions);
|
|
4362
4360
|
for (const s of filteredSessions) {
|
|
4363
|
-
if (childAnchors.has(s.id) && !parentOf.has(s.id)) parentOf.set(s.id, s.
|
|
4361
|
+
if (childAnchors.has(s.id) && !parentOf.has(s.id)) parentOf.set(s.id, s.nest.parent);
|
|
4364
4362
|
}
|
|
4365
4363
|
const nestChildren = (list) => {
|
|
4366
4364
|
if (parentOf.size === 0) return list;
|
|
@@ -5572,19 +5570,20 @@ function sgGroupForSession(session) {
|
|
|
5572
5570
|
return sgGroupOf('session', s.id) || (project ? sgGroupOf('project', project) : null);
|
|
5573
5571
|
}
|
|
5574
5572
|
|
|
5575
|
-
// A `dispatch start --child` session renders in its
|
|
5576
|
-
// the
|
|
5577
|
-
// (drag, pins, search, reveal) agrees with what
|
|
5573
|
+
// A `dispatch start --child` session, or a fork from the Fork menu, renders in its parent's place,
|
|
5574
|
+
// unless the user placed or unnested it or the parent is not in the rendered list. Set by
|
|
5575
|
+
// renderSessions, so every other placement lookup (drag, pins, search, reveal) agrees with what
|
|
5576
|
+
// the sidebar shows.
|
|
5578
5577
|
let childAnchors = new Map();
|
|
5579
5578
|
const placementOf = (session) => childAnchors.get(session.id) ?? session;
|
|
5580
5579
|
|
|
5581
5580
|
function computeChildAnchors(list) {
|
|
5582
5581
|
const out = new Map();
|
|
5583
|
-
if (!list.some((s) => s.
|
|
5582
|
+
if (!list.some((s) => s.nest?.child)) return out;
|
|
5584
5583
|
const byId = new Map(list.map((s) => [s.id, s]));
|
|
5585
5584
|
const placed = new Set();
|
|
5586
5585
|
for (const g of sessionGroups) for (const m of g.members) if (m.type === 'session') placed.add(m.ref);
|
|
5587
|
-
const up = (s) => (s.
|
|
5586
|
+
const up = (s) => (s.nest?.child && !placed.has(s.id) ? byId.get(s.nest.parent) : null);
|
|
5588
5587
|
for (const s of list) {
|
|
5589
5588
|
let anchor = up(s);
|
|
5590
5589
|
if (!anchor) continue;
|
|
@@ -5598,10 +5597,10 @@ function computeChildAnchors(list) {
|
|
|
5598
5597
|
return out;
|
|
5599
5598
|
}
|
|
5600
5599
|
|
|
5601
|
-
function
|
|
5600
|
+
function setNestChild(id, child) {
|
|
5602
5601
|
const s = sessions.find((x) => x.id === id);
|
|
5603
|
-
if (!s?.
|
|
5604
|
-
s.
|
|
5602
|
+
if (!s?.nest || !!s.nest.child === child || (child && !s.nest.parent)) return;
|
|
5603
|
+
s.nest = { ...s.nest, child };
|
|
5605
5604
|
if (child && sgGroupOf('session', id)) {
|
|
5606
5605
|
sgDetach('session', id);
|
|
5607
5606
|
persistSessionGroups();
|
|
@@ -5979,7 +5978,7 @@ function sgGroupDropZone(target) {
|
|
|
5979
5978
|
const targetSessionId = zone.dataset.sessionId;
|
|
5980
5979
|
if (targetSessionId) {
|
|
5981
5980
|
if (targetSessionId === sgDrag.ref) return null;
|
|
5982
|
-
if (dragSession?.
|
|
5981
|
+
if (dragSession?.nest?.parent === targetSessionId) return anchored ? null : { zone, nest: true };
|
|
5983
5982
|
const targetSession = sessions.find((s) => s.id === targetSessionId);
|
|
5984
5983
|
const targetGroup = targetSession ? sgGroupForSession(targetSession) : null;
|
|
5985
5984
|
const targetGroupId = targetGroup?.id || null;
|
|
@@ -6062,13 +6061,13 @@ function sgOnDrop(e) {
|
|
|
6062
6061
|
return;
|
|
6063
6062
|
}
|
|
6064
6063
|
if (hit.nest) {
|
|
6065
|
-
|
|
6064
|
+
setNestChild(drag.ref, true);
|
|
6066
6065
|
sgFinishDrag();
|
|
6067
6066
|
return;
|
|
6068
6067
|
}
|
|
6069
6068
|
// Any other move takes a `--child` session out of its starter's place for good, so it stays
|
|
6070
6069
|
// where it was put after it leaves a group.
|
|
6071
|
-
if (drag.kind === 'session')
|
|
6070
|
+
if (drag.kind === 'session') setNestChild(drag.ref, false);
|
|
6072
6071
|
if (hit.unnest) {
|
|
6073
6072
|
sgFinishDrag();
|
|
6074
6073
|
return;
|
|
@@ -6248,15 +6247,21 @@ function sgOpenMenu(x, y, kind, ref) {
|
|
|
6248
6247
|
menu.setAttribute('role', 'menu');
|
|
6249
6248
|
const canFork = kind === 'session' && !!forkableSession(ref);
|
|
6250
6249
|
const canEnd = kind === 'session' && runningTerminals.has(ref);
|
|
6251
|
-
const
|
|
6250
|
+
const canShell = kind === 'session' && terminalAvailable() && !!getSessionBaseDir(ref);
|
|
6251
|
+
const marker = kind === 'session' ? sessions.find((s) => s.id === ref)?.nest : null;
|
|
6252
6252
|
const nestItem = marker?.child
|
|
6253
6253
|
? '<button class="sg-menu-item" role="menuitem" data-sg-action="unnest">Unnest</button>'
|
|
6254
|
-
:
|
|
6254
|
+
: marker?.parent && sessions.some((s) => s.id === marker.parent)
|
|
6255
|
+
? '<button class="sg-menu-item" role="menuitem" data-sg-action="nest">Nest under parent</button>'
|
|
6256
|
+
: '';
|
|
6255
6257
|
const actions =
|
|
6256
6258
|
nestItem +
|
|
6257
6259
|
(canFork
|
|
6258
6260
|
? '<button class="sg-menu-item" role="menuitem" data-sg-action="fork" title="claude --resume --fork-session">Fork</button>'
|
|
6259
6261
|
: '') +
|
|
6262
|
+
(canShell
|
|
6263
|
+
? '<button class="sg-menu-item" role="menuitem" data-sg-action="shell" title="A plain shell in the session\'s folder, in a pane">New shell</button>'
|
|
6264
|
+
: '') +
|
|
6260
6265
|
(canEnd
|
|
6261
6266
|
? '<button class="sg-menu-item" role="menuitem" data-sg-action="end" title="Alt+Shift+`">End terminal</button>'
|
|
6262
6267
|
: '');
|
|
@@ -6314,11 +6319,12 @@ document.addEventListener('click', (e) => {
|
|
|
6314
6319
|
sgCloseMenu();
|
|
6315
6320
|
if (item.dataset.sgAction === 'fork') return forkSession(sgRef);
|
|
6316
6321
|
if (item.dataset.sgAction === 'end') return closeTerminalSession(sgRef);
|
|
6317
|
-
if (item.dataset.sgAction === '
|
|
6318
|
-
|
|
6322
|
+
if (item.dataset.sgAction === 'shell') return openShellForSession(sgRef);
|
|
6323
|
+
if (item.dataset.sgAction === 'unnest' || item.dataset.sgAction === 'nest') {
|
|
6324
|
+
setNestChild(sgRef, item.dataset.sgAction === 'nest');
|
|
6319
6325
|
return renderSessions();
|
|
6320
6326
|
}
|
|
6321
|
-
if (sgKind === 'session')
|
|
6327
|
+
if (sgKind === 'session') setNestChild(sgRef, false);
|
|
6322
6328
|
if (move === '__none__') {
|
|
6323
6329
|
sgDetach(sgKind, sgRef);
|
|
6324
6330
|
persistSessionGroups();
|
|
@@ -12382,15 +12388,16 @@ function renderFilterState() {
|
|
|
12382
12388
|
function toggleZenMode() {
|
|
12383
12389
|
const leavingSessionZen = zenMode;
|
|
12384
12390
|
if (zenMode) zenMode = false;
|
|
12385
|
-
else if (zenGroup || zenProject)
|
|
12391
|
+
else if (zenGroup || zenProject) setZenScope(null, null);
|
|
12386
12392
|
else {
|
|
12387
12393
|
const el = focusZone === 'sidebar' && sessionsList.querySelector('.kb-selected');
|
|
12388
12394
|
const sel = el && sgDragPayload(el);
|
|
12389
|
-
|
|
12390
|
-
|
|
12395
|
+
setZenScope(
|
|
12396
|
+
sel?.kind === 'group' ? sgGroupById(sel.ref)?.id || null : null,
|
|
12397
|
+
sel?.kind === 'project' ? sel.ref : null,
|
|
12398
|
+
);
|
|
12391
12399
|
zenMode = !zenGroup && !zenProject;
|
|
12392
12400
|
}
|
|
12393
|
-
setZenPeek(zenGroup ? sgKey(zenGroup) : zenProject);
|
|
12394
12401
|
store.setItem(ZEN_KEY, String(zenMode));
|
|
12395
12402
|
renderZenState();
|
|
12396
12403
|
if (zenMode) closeFilterMenu();
|
|
@@ -12400,6 +12407,27 @@ function toggleZenMode() {
|
|
|
12400
12407
|
if (!leavingSessionZen) fetchSessions(false);
|
|
12401
12408
|
}
|
|
12402
12409
|
|
|
12410
|
+
function setZenScope(group, project) {
|
|
12411
|
+
zenGroup = group;
|
|
12412
|
+
zenProject = group ? null : project;
|
|
12413
|
+
setZenPeek(zenGroup ? sgKey(zenGroup) : zenProject);
|
|
12414
|
+
if (zenGroup || zenProject) store.writeJson(ZEN_SCOPE_KEY, { group: zenGroup, project: zenProject });
|
|
12415
|
+
else store.removeItem(ZEN_SCOPE_KEY);
|
|
12416
|
+
}
|
|
12417
|
+
|
|
12418
|
+
function inZenScope(session) {
|
|
12419
|
+
if (zenGroup) return sgSubtreeIds(zenGroup).has(sgGroupForSession(session)?.id);
|
|
12420
|
+
return sessionProjectKey(session) === zenProject;
|
|
12421
|
+
}
|
|
12422
|
+
|
|
12423
|
+
// Opening a session the scope hides would leave it off screen, so the scope gives way.
|
|
12424
|
+
// Not while booting: the restored session may sit outside the restored scope.
|
|
12425
|
+
function leaveZenScopeFor(sessionId) {
|
|
12426
|
+
if ((!zenGroup && !zenProject) || document.body.classList.contains('booting')) return;
|
|
12427
|
+
const session = sessions.find((s) => s.id === sessionId);
|
|
12428
|
+
if (!session || !inZenScope(session)) toggleZenMode();
|
|
12429
|
+
}
|
|
12430
|
+
|
|
12403
12431
|
function applyHubSettings(s) {
|
|
12404
12432
|
sessionsList.classList.toggle('zen-centered', s.zenCentered === true);
|
|
12405
12433
|
if (s.zenPattern) sessionsList.dataset.zenPattern = s.zenPattern;
|
|
@@ -14439,12 +14467,16 @@ const PANE_ICONS = {
|
|
|
14439
14467
|
'<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
14468
|
scratchpad:
|
|
14441
14469
|
'<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>',
|
|
14470
|
+
shell:
|
|
14471
|
+
'<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>',
|
|
14442
14472
|
warning:
|
|
14443
14473
|
'<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>',
|
|
14444
14474
|
};
|
|
14445
14475
|
// Map order is recency: the first entry is the one evicted. Keys are `${sessionId}/${paneId}`,
|
|
14446
14476
|
// and the limit spans sessions, so a session switch cannot pile up frames.
|
|
14447
14477
|
const paneFrames = new Map();
|
|
14478
|
+
// Entries go with their view, in mountPane's eviction and unmountPane.
|
|
14479
|
+
const shellFrames = new Map();
|
|
14448
14480
|
const paneReviews = new WeakMap();
|
|
14449
14481
|
// Off-screen views whose file changed; they reload when shown.
|
|
14450
14482
|
const stalePaneViews = new WeakSet();
|
|
@@ -14547,7 +14579,7 @@ function markPaneSide(el, side, focused) {
|
|
|
14547
14579
|
el.classList.toggle('pane-focus', focused);
|
|
14548
14580
|
}
|
|
14549
14581
|
|
|
14550
|
-
const paneLabel = (p) => (p.kind === 'message' ? p.title : p.target);
|
|
14582
|
+
const paneLabel = (p) => (p.kind === 'message' ? p.title : p.kind === 'shell' ? p.cwd || 'Shell' : p.target);
|
|
14551
14583
|
|
|
14552
14584
|
function paneMenuLabel(pane, label) {
|
|
14553
14585
|
const cut =
|
|
@@ -14662,6 +14694,7 @@ function mountPane(sid, pane) {
|
|
|
14662
14694
|
while (paneFrames.size > PANE_FRAME_LIMIT) {
|
|
14663
14695
|
const [oldKey, oldView] = paneFrames.entries().next().value;
|
|
14664
14696
|
paneFrames.delete(oldKey);
|
|
14697
|
+
shellFrames.delete(oldView.querySelector('.pane-shell-frame'));
|
|
14665
14698
|
oldView.remove();
|
|
14666
14699
|
}
|
|
14667
14700
|
return key;
|
|
@@ -14726,6 +14759,10 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14726
14759
|
await loadScratchpadPaneView(pane, view);
|
|
14727
14760
|
return;
|
|
14728
14761
|
}
|
|
14762
|
+
if (pane.kind === 'shell') {
|
|
14763
|
+
loadShellPaneView(pane, view);
|
|
14764
|
+
return;
|
|
14765
|
+
}
|
|
14729
14766
|
const data = await getJson('/api/preview', null, { query: { path: pane.target } });
|
|
14730
14767
|
if (data?.kind === 'html') {
|
|
14731
14768
|
// A show card's own zoom follows the text zoom (showBridge), so its frame is not .modal-zoomable.
|
|
@@ -14967,6 +15004,7 @@ function focusActivePane() {
|
|
|
14967
15004
|
function focusPaneTarget(target) {
|
|
14968
15005
|
target.focus({ preventScroll: true });
|
|
14969
15006
|
target.contentWindow?.focus();
|
|
15007
|
+
shellFrames.get(target)?.post('focus');
|
|
14970
15008
|
}
|
|
14971
15009
|
|
|
14972
15010
|
function isPaneDocOnScreen() {
|
|
@@ -14994,6 +15032,7 @@ function unmountPane(sid, paneId) {
|
|
|
14994
15032
|
const hadFocus = view?.contains(document.activeElement);
|
|
14995
15033
|
view?.remove();
|
|
14996
15034
|
paneFrames.delete(key);
|
|
15035
|
+
shellFrames.delete(view?.querySelector('.pane-shell-frame'));
|
|
14997
15036
|
// Chrome leaves the window without focus when a focused frame is removed, so no key reaches
|
|
14998
15037
|
// the board until a click. Only when it had focus: under the hub, cck may be off screen.
|
|
14999
15038
|
if (hadFocus) window.focus();
|
|
@@ -15170,6 +15209,10 @@ async function reloadPane(id) {
|
|
|
15170
15209
|
if (!pane) return;
|
|
15171
15210
|
const sid = paneSessionId();
|
|
15172
15211
|
const view = paneFrames.get(`${sid}/${pane.id}`);
|
|
15212
|
+
if (pane.kind === 'shell') {
|
|
15213
|
+
await restartShellPane(sid, pane);
|
|
15214
|
+
return;
|
|
15215
|
+
}
|
|
15173
15216
|
if (pane.kind !== 'url' && pane.kind !== 'scratchpad' && view) {
|
|
15174
15217
|
await reloadPaneView(sid, pane, view);
|
|
15175
15218
|
} else {
|
|
@@ -15182,7 +15225,7 @@ async function reloadPane(id) {
|
|
|
15182
15225
|
|
|
15183
15226
|
function openPaneExternally(id) {
|
|
15184
15227
|
const pane = paneById(id);
|
|
15185
|
-
if (!pane) return;
|
|
15228
|
+
if (!pane || pane.kind === 'shell') return;
|
|
15186
15229
|
if (pane.kind === 'message') {
|
|
15187
15230
|
openPaneMessageDetail(pane);
|
|
15188
15231
|
return;
|
|
@@ -15206,7 +15249,8 @@ async function openPaneMessageDetail(pane) {
|
|
|
15206
15249
|
function copyPaneTarget(id) {
|
|
15207
15250
|
const pane = paneById(id);
|
|
15208
15251
|
if (!pane) return;
|
|
15209
|
-
|
|
15252
|
+
if (pane.kind === 'shell') copyText(pane.cwd || '', 'path');
|
|
15253
|
+
else copyText(pane.target, pane.kind === 'url' ? 'URL' : 'path');
|
|
15210
15254
|
}
|
|
15211
15255
|
|
|
15212
15256
|
function closePaneMenu(restore) {
|
|
@@ -15373,29 +15417,31 @@ function openPaneMenu(x, y, id) {
|
|
|
15373
15417
|
if (!pane) return false;
|
|
15374
15418
|
const url = pane.kind === 'url';
|
|
15375
15419
|
const message = pane.kind === 'message';
|
|
15376
|
-
const
|
|
15420
|
+
const shell = pane.kind === 'shell';
|
|
15377
15421
|
showPaneMenu(
|
|
15378
15422
|
x,
|
|
15379
15423
|
y,
|
|
15380
15424
|
pane.id,
|
|
15381
15425
|
'Pane actions',
|
|
15382
|
-
paneMenuLabel(pane,
|
|
15383
|
-
(message ? '' : paneMenuItem('copy', url ? 'Copy URL' : 'Copy path')) +
|
|
15384
|
-
|
|
15385
|
-
'
|
|
15386
|
-
|
|
15387
|
-
|
|
15388
|
-
|
|
15389
|
-
|
|
15390
|
-
|
|
15391
|
-
|
|
15392
|
-
|
|
15393
|
-
|
|
15394
|
-
|
|
15426
|
+
paneMenuLabel(pane, paneLabel(pane)) +
|
|
15427
|
+
(message ? '' : paneMenuItem('copy', url ? 'Copy URL' : shell ? 'Copy folder path' : 'Copy path')) +
|
|
15428
|
+
(shell
|
|
15429
|
+
? ''
|
|
15430
|
+
: paneMenuItem(
|
|
15431
|
+
'open',
|
|
15432
|
+
url
|
|
15433
|
+
? 'Open in new tab'
|
|
15434
|
+
: message
|
|
15435
|
+
? 'Open in message dialog'
|
|
15436
|
+
: pane.kind === 'scratchpad'
|
|
15437
|
+
? 'Open in scratch viewer'
|
|
15438
|
+
: 'Open in preview',
|
|
15439
|
+
)) +
|
|
15440
|
+
(message || shell
|
|
15395
15441
|
? ''
|
|
15396
15442
|
: paneMenuItem('link', paneIsLinked(pane) ? 'Remove from linked documents' : 'Add to linked documents')) +
|
|
15397
15443
|
paneMenuItem('rename', 'Rename') +
|
|
15398
|
-
paneMenuItem('reload', 'Reload') +
|
|
15444
|
+
paneMenuItem('reload', shell ? 'Restart shell' : 'Reload') +
|
|
15399
15445
|
(url ? paneMenuItem('dock', pane.dock ? 'Remove from the dock' : 'Dock beside the terminal') : '') +
|
|
15400
15446
|
paneGroupMenuItems(pane.id) +
|
|
15401
15447
|
paneMenuItem('close', 'Close pane'),
|
|
@@ -15644,8 +15690,13 @@ function movePanePopHighlight(step) {
|
|
|
15644
15690
|
}
|
|
15645
15691
|
|
|
15646
15692
|
function openPanePop() {
|
|
15647
|
-
|
|
15693
|
+
const sid = paneSessionId();
|
|
15694
|
+
if (!sid) return;
|
|
15648
15695
|
panePopInput.value = '';
|
|
15696
|
+
const shellBtn = document.getElementById('pane-pop-shell');
|
|
15697
|
+
const folder = getSessionBaseDir(sid);
|
|
15698
|
+
shellBtn.hidden = !terminalAvailable() || !folder;
|
|
15699
|
+
shellBtn.querySelector('.pane-pop-shell-dir').textContent = folder ? pathBasename(folder) : '';
|
|
15649
15700
|
renderPanePopDocs();
|
|
15650
15701
|
panePop.classList.add('visible');
|
|
15651
15702
|
panePopInput.focus();
|
|
@@ -15941,7 +15992,10 @@ panePop.addEventListener('keydown', (e) => {
|
|
|
15941
15992
|
return;
|
|
15942
15993
|
}
|
|
15943
15994
|
if (e.target !== panePopInput) return;
|
|
15944
|
-
if (e.key === 'Enter') {
|
|
15995
|
+
if (e.key === 'Enter' && e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
|
|
15996
|
+
e.preventDefault();
|
|
15997
|
+
if (!document.getElementById('pane-pop-shell').hidden) addShellPane();
|
|
15998
|
+
} else if (e.key === 'Enter') {
|
|
15945
15999
|
e.preventDefault();
|
|
15946
16000
|
addPane(panePopMatches[panePopIdx] ?? panePopInput.value);
|
|
15947
16001
|
} else if (matchKey(e, 'ArrowDown', 'ArrowUp')) {
|
|
@@ -16330,13 +16384,31 @@ function ensureTerminalFrame() {
|
|
|
16330
16384
|
return ready;
|
|
16331
16385
|
}
|
|
16332
16386
|
|
|
16333
|
-
function
|
|
16334
|
-
|
|
16387
|
+
function createTerminalFrame(
|
|
16388
|
+
className,
|
|
16389
|
+
title,
|
|
16390
|
+
origin = termFrame.sameOrigin ? location.origin : terminalFrameOrigin(),
|
|
16391
|
+
) {
|
|
16335
16392
|
const el = document.createElement('iframe');
|
|
16336
|
-
el.className =
|
|
16337
|
-
el.title =
|
|
16393
|
+
el.className = className;
|
|
16394
|
+
el.title = title;
|
|
16338
16395
|
el.allow = 'clipboard-read; clipboard-write';
|
|
16339
16396
|
el.src = `${origin}/terminal.html#p=${encodeURIComponent(location.origin)}`;
|
|
16397
|
+
return { el, origin };
|
|
16398
|
+
}
|
|
16399
|
+
|
|
16400
|
+
// The answer to a frame's `loaded`: the frame is new, so it gets everything again.
|
|
16401
|
+
function initTerminalFrame(frameState, post) {
|
|
16402
|
+
const themeOptions = terminalThemeOptions();
|
|
16403
|
+
frameState.inited = false;
|
|
16404
|
+
frameState.claims = null;
|
|
16405
|
+
frameState.theme = JSON.stringify(themeOptions);
|
|
16406
|
+
post('init', terminalInitOptions(themeOptions));
|
|
16407
|
+
}
|
|
16408
|
+
|
|
16409
|
+
function loadTerminalFrame(origin, timeoutMs) {
|
|
16410
|
+
termFrame.el?.remove();
|
|
16411
|
+
const { el } = createTerminalFrame('terminal-frame', 'Terminal', origin);
|
|
16340
16412
|
resetTerminalFrame({ el, origin });
|
|
16341
16413
|
return new Promise((resolve, reject) => {
|
|
16342
16414
|
const timer = setTimeout(() => {
|
|
@@ -16359,6 +16431,7 @@ function sendTerminalTheme() {
|
|
|
16359
16431
|
for (const [frame, post] of [
|
|
16360
16432
|
[termFrame, postToTerminalFrame],
|
|
16361
16433
|
[kanbotState, postToKanbotFrame],
|
|
16434
|
+
...[...shellFrames.values()].map((s) => [s, s.post]),
|
|
16362
16435
|
]) {
|
|
16363
16436
|
if (!frame.inited || key === frame.theme) continue;
|
|
16364
16437
|
frame.theme = key;
|
|
@@ -16551,7 +16624,15 @@ function pushTerminalClaims() {
|
|
|
16551
16624
|
const bridged = bridgedFrameEls();
|
|
16552
16625
|
const urlFrames = urlPaneFrames();
|
|
16553
16626
|
const dockEls = dockFrameEls();
|
|
16554
|
-
if (
|
|
16627
|
+
if (
|
|
16628
|
+
!termFrame.inited &&
|
|
16629
|
+
!kanbotState.inited &&
|
|
16630
|
+
!bridged.length &&
|
|
16631
|
+
!urlFrames.length &&
|
|
16632
|
+
!dockEls.length &&
|
|
16633
|
+
!shellFrames.size
|
|
16634
|
+
)
|
|
16635
|
+
return;
|
|
16555
16636
|
const claims = keyClaims();
|
|
16556
16637
|
const base = bridgeClaims(claims);
|
|
16557
16638
|
sendBridgeClaimsAll(bridged, base);
|
|
@@ -16560,6 +16641,10 @@ function pushTerminalClaims() {
|
|
|
16560
16641
|
const sig = JSON.stringify(claims);
|
|
16561
16642
|
sendFrameClaims(kanbotState, claims, sig, postToKanbotFrame);
|
|
16562
16643
|
sendFrameClaims(termFrame, claims, sig, terminalFrameSend);
|
|
16644
|
+
if (!shellFrames.size) return;
|
|
16645
|
+
const shellClaims = { ...claims, keys: [...claims.keys, ...SHELL_PANE_CLAIMS] };
|
|
16646
|
+
const shellSig = JSON.stringify(shellClaims);
|
|
16647
|
+
for (const s of shellFrames.values()) sendFrameClaims(s, shellClaims, shellSig, s.post);
|
|
16563
16648
|
});
|
|
16564
16649
|
}
|
|
16565
16650
|
|
|
@@ -16617,6 +16702,7 @@ function adjustTerminalFontSize(step) {
|
|
|
16617
16702
|
else store.setItem(TERMINAL_FONT_KEY, String(size));
|
|
16618
16703
|
termState.fontSize = size;
|
|
16619
16704
|
terminalFrameSend('font', { size });
|
|
16705
|
+
for (const s of shellFrames.values()) if (s.inited) s.post('font', { size });
|
|
16620
16706
|
layoutShow();
|
|
16621
16707
|
}
|
|
16622
16708
|
showToast(`Terminal ${size}px`);
|
|
@@ -17046,7 +17132,13 @@ async function renderTerminalManager() {
|
|
|
17046
17132
|
body.innerHTML = list
|
|
17047
17133
|
.map((t) => {
|
|
17048
17134
|
const session = sessions.find((s) => s.id === t.id);
|
|
17049
|
-
const name = t.kanbot
|
|
17135
|
+
const name = t.kanbot
|
|
17136
|
+
? 'Kanbot'
|
|
17137
|
+
: t.pane
|
|
17138
|
+
? `Shell pane · ${pathBasename(t.cwd)}`
|
|
17139
|
+
: session
|
|
17140
|
+
? sessionDisplayName(session)
|
|
17141
|
+
: t.id.slice(0, 8);
|
|
17050
17142
|
const here = t.id === termState.sessionId ? '<span class="terminal-manager-here">this tab</span>' : '';
|
|
17051
17143
|
const attached = t.clients ? `${t.clients} attached` : 'detached';
|
|
17052
17144
|
return `<div class="terminal-manager-row${t.clients ? ' attached' : ''}">
|
|
@@ -17062,7 +17154,7 @@ async function renderTerminalManager() {
|
|
|
17062
17154
|
</div>
|
|
17063
17155
|
</div>
|
|
17064
17156
|
<div class="terminal-manager-actions">
|
|
17065
|
-
|
|
17157
|
+
${t.pane ? '' : `<button type="button" class="btn btn-secondary" data-open="${escapeHtml(t.id)}"${t.kanbot ? ' data-kanbot' : ''}>Open</button>`}
|
|
17066
17158
|
<button type="button" class="btn btn-secondary terminal-manager-end" data-end="${escapeHtml(t.id)}" data-started="${escapeHtml(String(Number(t.startedAt) || 0))}">End</button>
|
|
17067
17159
|
</div>
|
|
17068
17160
|
</div>`;
|
|
@@ -17255,12 +17347,8 @@ function toggleKanbot(force) {
|
|
|
17255
17347
|
}
|
|
17256
17348
|
kanbotState.frame?.focus();
|
|
17257
17349
|
if (!kanbotState.frame) {
|
|
17258
|
-
const frame =
|
|
17259
|
-
|
|
17260
|
-
frame.title = 'Kanbot';
|
|
17261
|
-
frame.allow = 'clipboard-read; clipboard-write';
|
|
17262
|
-
kanbotState.origin = termFrame.sameOrigin ? location.origin : terminalFrameOrigin();
|
|
17263
|
-
frame.src = `${kanbotState.origin}/terminal.html#p=${encodeURIComponent(location.origin)}`;
|
|
17350
|
+
const { el: frame, origin } = createTerminalFrame('kanbot-frame', 'Kanbot');
|
|
17351
|
+
kanbotState.origin = origin;
|
|
17264
17352
|
kanbotState.frame = frame;
|
|
17265
17353
|
el.querySelector('.kanbot-body').appendChild(frame);
|
|
17266
17354
|
return;
|
|
@@ -17303,11 +17391,7 @@ window.addEventListener('message', (e) => {
|
|
|
17303
17391
|
if (typeof m?.type !== 'string' || !m.type.startsWith(TERMINAL_MSG)) return;
|
|
17304
17392
|
const t = m.type.slice(TERMINAL_MSG.length);
|
|
17305
17393
|
if (t === 'loaded') {
|
|
17306
|
-
|
|
17307
|
-
kanbotState.inited = false;
|
|
17308
|
-
kanbotState.claims = null;
|
|
17309
|
-
kanbotState.theme = JSON.stringify(themeOptions);
|
|
17310
|
-
postToKanbotFrame('init', terminalInitOptions(themeOptions));
|
|
17394
|
+
initTerminalFrame(kanbotState, postToKanbotFrame);
|
|
17311
17395
|
return;
|
|
17312
17396
|
}
|
|
17313
17397
|
if (t === 'term') {
|
|
@@ -17339,6 +17423,149 @@ window.addEventListener('message', (e) => {
|
|
|
17339
17423
|
|
|
17340
17424
|
//#endregion
|
|
17341
17425
|
|
|
17426
|
+
//#region SHELL_PANES
|
|
17427
|
+
// A plain shell in a pane (kind `shell`): its own terminal frame, like Kanbot's, on a PTY in shell mode
|
|
17428
|
+
// that belongs to no session. The PTY outlives the frame, so an evicted view attaches again and gets
|
|
17429
|
+
// its screen back; closing the pane ends it on the server.
|
|
17430
|
+
// Only keys a shell does not type: the pane switch and close keys and the session tab keys.
|
|
17431
|
+
const SHELL_PANE_CLAIMS = [
|
|
17432
|
+
...['BracketLeft', 'BracketRight', 'KeyW'].map((code) => ({ altKey: true, key: 'Unidentified', code })),
|
|
17433
|
+
...'123456789'.split('').map((n) => ({ ctrlKey: true, altKey: true, key: 'Unidentified', code: `Digit${n}` })),
|
|
17434
|
+
];
|
|
17435
|
+
const SHELL_RETRY_MS = 1000;
|
|
17436
|
+
const SHELL_RETRIES = 5;
|
|
17437
|
+
|
|
17438
|
+
function loadShellPaneView(pane, view) {
|
|
17439
|
+
if (!terminalAvailable()) {
|
|
17440
|
+
view.insertAdjacentHTML(
|
|
17441
|
+
'beforeend',
|
|
17442
|
+
paneCardHtml(
|
|
17443
|
+
'The terminal is off',
|
|
17444
|
+
'A shell pane runs in the embedded terminal, which this board does not have.',
|
|
17445
|
+
),
|
|
17446
|
+
);
|
|
17447
|
+
return;
|
|
17448
|
+
}
|
|
17449
|
+
const { el, origin } = createTerminalFrame('pane-frame pane-shell-frame', pane.title);
|
|
17450
|
+
const post = (t, data) => el.contentWindow?.postMessage({ ...data, type: TERMINAL_MSG + t }, origin);
|
|
17451
|
+
shellFrames.set(el, { el, origin, post, ptyId: pane.target, inited: false, socketId: 0, ended: false, retries: 0 });
|
|
17452
|
+
view.appendChild(el);
|
|
17453
|
+
}
|
|
17454
|
+
|
|
17455
|
+
function openShellFrame(s) {
|
|
17456
|
+
s.ended = false;
|
|
17457
|
+
setShellCard(s.el);
|
|
17458
|
+
s.post('open', { socketId: ++s.socketId, reset: true, hello: { token: terminalToken, id: s.ptyId, mode: 'shell' } });
|
|
17459
|
+
}
|
|
17460
|
+
|
|
17461
|
+
// No title takes the card away.
|
|
17462
|
+
function setShellCard(el, title, text, button) {
|
|
17463
|
+
const view = el.parentElement;
|
|
17464
|
+
view?.querySelector('.pane-shell-card')?.remove();
|
|
17465
|
+
el.hidden = !!title;
|
|
17466
|
+
if (!title || !view) return;
|
|
17467
|
+
view.insertAdjacentHTML('beforeend', paneCardHtml(title, text, button, { attr: 'data-shell-restart' }));
|
|
17468
|
+
view.lastElementChild.classList.add('pane-shell-card');
|
|
17469
|
+
}
|
|
17470
|
+
|
|
17471
|
+
async function restartShellPane(sid, pane) {
|
|
17472
|
+
await terminalFetch(apiPath`/api/terminals/${pane.target}`, 'DELETE').catch(() => {});
|
|
17473
|
+
unmountPane(sid, pane.id);
|
|
17474
|
+
syncPanes();
|
|
17475
|
+
focusActivePane();
|
|
17476
|
+
}
|
|
17477
|
+
|
|
17478
|
+
function addShellPane() {
|
|
17479
|
+
const sid = paneSessionId();
|
|
17480
|
+
if (!sid) return;
|
|
17481
|
+
const typed = panePopInput.value.trim();
|
|
17482
|
+
closePanePop();
|
|
17483
|
+
openShellForSession(sid, typed && !linkUrl(typed) ? typed : undefined);
|
|
17484
|
+
}
|
|
17485
|
+
|
|
17486
|
+
// Panes hide behind the Claude terminal, so the session leaves terminal mode to show the shell.
|
|
17487
|
+
// The server checks `folder`, so a typed path that is no folder ends in its error toast.
|
|
17488
|
+
async function openShellForSession(sid, folder = getSessionBaseDir(sid)) {
|
|
17489
|
+
if (!folder) {
|
|
17490
|
+
showToast('This session has no folder to start a shell in', 'error');
|
|
17491
|
+
return;
|
|
17492
|
+
}
|
|
17493
|
+
if (sid !== paneSessionId()) await openSession(sid);
|
|
17494
|
+
if (wantsTerminalFor(sid)) exitTerminalMode(sid);
|
|
17495
|
+
if (!(await postPane(sid, { kind: 'shell', target: folder }))) return;
|
|
17496
|
+
syncPanes();
|
|
17497
|
+
focusActivePane();
|
|
17498
|
+
}
|
|
17499
|
+
|
|
17500
|
+
window.addEventListener('message', (e) => {
|
|
17501
|
+
const m = e.data;
|
|
17502
|
+
if (!shellFrames.size || typeof m?.type !== 'string' || !m.type.startsWith(TERMINAL_MSG)) return;
|
|
17503
|
+
let s = null;
|
|
17504
|
+
for (const f of shellFrames.values()) if (f.el.contentWindow === e.source) s = f;
|
|
17505
|
+
if (!s || e.origin !== s.origin) return;
|
|
17506
|
+
const el = s.el;
|
|
17507
|
+
const t = m.type.slice(TERMINAL_MSG.length);
|
|
17508
|
+
if (t === 'loaded') {
|
|
17509
|
+
initTerminalFrame(s, s.post);
|
|
17510
|
+
return;
|
|
17511
|
+
}
|
|
17512
|
+
if (t === 'term') {
|
|
17513
|
+
s.inited = true;
|
|
17514
|
+
pushTerminalClaims();
|
|
17515
|
+
openShellFrame(s);
|
|
17516
|
+
if (document.activeElement === el) s.post('focus');
|
|
17517
|
+
return;
|
|
17518
|
+
}
|
|
17519
|
+
if (t === 'key') {
|
|
17520
|
+
replayKey(m, el);
|
|
17521
|
+
return;
|
|
17522
|
+
}
|
|
17523
|
+
if (t === 'link') {
|
|
17524
|
+
openTerminalLink(m.href);
|
|
17525
|
+
return;
|
|
17526
|
+
}
|
|
17527
|
+
if (t === 'focused') {
|
|
17528
|
+
focusSideOf(el.closest('.pane-view'));
|
|
17529
|
+
return;
|
|
17530
|
+
}
|
|
17531
|
+
if (m.socketId !== s.socketId) return;
|
|
17532
|
+
if (t === 'ws') {
|
|
17533
|
+
if (m.msg?.t === 'ready') s.retries = 0;
|
|
17534
|
+
else if (m.msg?.t === 'exit') {
|
|
17535
|
+
s.ended = true;
|
|
17536
|
+
const clean = m.msg.code === 0 || m.msg.ended;
|
|
17537
|
+
setShellCard(
|
|
17538
|
+
el,
|
|
17539
|
+
'The shell exited',
|
|
17540
|
+
clean ? 'Start a new shell in this pane.' : `Exit code ${m.msg.code}.`,
|
|
17541
|
+
'Restart',
|
|
17542
|
+
);
|
|
17543
|
+
} else if (m.msg?.t === 'error') {
|
|
17544
|
+
s.ended = true;
|
|
17545
|
+
if (m.msg.msg === STALE_TOKEN_MSG) {
|
|
17546
|
+
refreshTerminalToken().then((ok) => ok && el.isConnected && openShellFrame(s));
|
|
17547
|
+
return;
|
|
17548
|
+
}
|
|
17549
|
+
setShellCard(el, 'The shell did not start', m.msg.msg || 'Terminal error', 'Try again');
|
|
17550
|
+
}
|
|
17551
|
+
} else if (t === 'close' && !s.ended && el.isConnected) {
|
|
17552
|
+
if (s.retries++ < SHELL_RETRIES) setTimeout(() => el.isConnected && !s.ended && openShellFrame(s), SHELL_RETRY_MS);
|
|
17553
|
+
else setShellCard(el, 'Lost the connection to the shell', 'The shell may still run on the board.', 'Reconnect');
|
|
17554
|
+
}
|
|
17555
|
+
});
|
|
17556
|
+
|
|
17557
|
+
paneViews.addEventListener('click', (e) => {
|
|
17558
|
+
const view = e.target.closest('[data-shell-restart]')?.closest('.pane-view');
|
|
17559
|
+
const el = view?.querySelector('.pane-shell-frame');
|
|
17560
|
+
const s = el && shellFrames.get(el);
|
|
17561
|
+
if (!s?.inited) return;
|
|
17562
|
+
s.retries = 0;
|
|
17563
|
+
openShellFrame(s);
|
|
17564
|
+
focusPaneTarget(el);
|
|
17565
|
+
});
|
|
17566
|
+
|
|
17567
|
+
//#endregion
|
|
17568
|
+
|
|
17342
17569
|
//#region ASK
|
|
17343
17570
|
// The question the session in the embedded terminal asks with the ask tool; the tool call waits for
|
|
17344
17571
|
// the answer. Hiding keeps the frame, so a half-filled card comes back as it was. Only an answer, a
|
|
@@ -18835,6 +19062,12 @@ function placeholderSession(id, spec) {
|
|
|
18835
19062
|
prompted: !!(spec.prompted || spec.prompt),
|
|
18836
19063
|
name: spec.name || (spec.forkOf && forkLabel(spec.forkOf)) || PLACEHOLDER_NAMES[spec.mode] || PLACEHOLDER_NAMES.new,
|
|
18837
19064
|
dispatched: spec.mode === 'dispatch' ? { parent: spec.parent || null, child: !!spec.child } : undefined,
|
|
19065
|
+
nest:
|
|
19066
|
+
spec.mode === 'dispatch'
|
|
19067
|
+
? { parent: spec.parent || null, child: !!spec.child }
|
|
19068
|
+
: spec.forkOf
|
|
19069
|
+
? { parent: spec.forkOf, child: true }
|
|
19070
|
+
: undefined,
|
|
18838
19071
|
project: spec.cwd,
|
|
18839
19072
|
worktree: spec.worktree ? { repo: spec.cwd, name: spec.worktree === true ? 'new' : spec.worktree } : null,
|
|
18840
19073
|
modifiedAt: new Date(spec.startedAt).toISOString(),
|
|
@@ -19609,6 +19842,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
19609
19842
|
|
|
19610
19843
|
loadSidebarState();
|
|
19611
19844
|
for (const p of readStoredList(COLLAPSED_GROUPS_KEY)) collapsedProjectGroups.add(p);
|
|
19845
|
+
setZenScope(zenGroup, zenProject);
|
|
19612
19846
|
syncSessionGroups();
|
|
19613
19847
|
initSessionGroupsDnd();
|
|
19614
19848
|
initSessionPicker();
|
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 · <kbd>↑</kbd><kbd>↓</kbd> select · <kbd>Esc</kbd> close</div>
|
|
988
|
+
<div class="sp-hint"><kbd>Enter</kbd> add · <kbd>Ctrl</kbd><kbd>Enter</kbd> new shell · <kbd>↑</kbd><kbd>↓</kbd> select · <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
|
@@ -126,6 +126,7 @@ const SHOW_DIR = path.join(CCK_DIR, 'show');
|
|
|
126
126
|
const PINS_FILE = path.join(CCK_DIR, 'pins.json');
|
|
127
127
|
const USER_GROUPS_FILE = path.join(CCK_DIR, 'groups.json');
|
|
128
128
|
const DISPATCHED_FILE = path.join(CCK_DIR, 'dispatched.json');
|
|
129
|
+
const FORKS_FILE = path.join(CCK_DIR, 'forks.json');
|
|
129
130
|
const WORKTREES_FILE = path.join(CCK_DIR, 'worktrees.json');
|
|
130
131
|
const LINKED_DOCS_FILE = path.join(CCK_DIR, 'linked-docs.json');
|
|
131
132
|
const PANES_FILE = path.join(CCK_DIR, 'panes.json');
|
|
@@ -1556,6 +1557,11 @@ app.get('/api/sessions', async (req, res) => {
|
|
|
1556
1557
|
// comes from lookupParentSession, not from the anchor's presence.
|
|
1557
1558
|
const compactSuppressed = new Set();
|
|
1558
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
|
+
}
|
|
1559
1565
|
// Cheap pre-gate: only a session with a boundary anchor can be a continuation,
|
|
1560
1566
|
// and lookupParentSession reads JSONLs on a cold cache. A fork with no boundary
|
|
1561
1567
|
// gets its badge only once a verdict exists (the info modal computes one).
|
|
@@ -3332,6 +3338,8 @@ function isAllowedFolder(dir) {
|
|
|
3332
3338
|
// Restore runs before the first full metadata scan, so until that scan has run a session's
|
|
3333
3339
|
// folder is read from its own JSONL, by the same rules the scan uses.
|
|
3334
3340
|
function resolveSessionFolder(id) {
|
|
3341
|
+
const shell = panes.shellPane(id);
|
|
3342
|
+
if (shell) return shell.cwd || null;
|
|
3335
3343
|
if (lastMetadataRefresh || !isSafeId(id)) {
|
|
3336
3344
|
const meta = loadSessionMetadata()[id];
|
|
3337
3345
|
return meta ? meta.project || meta.cwd || null : null;
|
|
@@ -3381,13 +3389,20 @@ const terminal = createTerminalClient({
|
|
|
3381
3389
|
// The project, not the last cwd: `claude --resume` finds a session under the
|
|
3382
3390
|
// project dir it started in, and cwd drifts into subdirectories.
|
|
3383
3391
|
resolveCwd: resolveSessionFolder,
|
|
3392
|
+
shellRun: (id) => panes.shellPane(id)?.run || null,
|
|
3384
3393
|
isAllowedFolder,
|
|
3385
3394
|
onChange: () => broadcast({ type: 'terminals-update', ids: terminal.ids(), awaitingTrust: terminal.awaitingTrust() }),
|
|
3386
3395
|
onExit: (id) => {
|
|
3387
3396
|
if (dispatched.get(id)) broadcast({ type: 'dispatch-update' });
|
|
3388
3397
|
},
|
|
3389
3398
|
onRekey: (from, to) => {
|
|
3390
|
-
|
|
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' });
|
|
3391
3406
|
},
|
|
3392
3407
|
});
|
|
3393
3408
|
|
|
@@ -3513,6 +3528,7 @@ app.get('/api/terminals', terminalRoute(async (_req, res) => {
|
|
|
3513
3528
|
res.json({
|
|
3514
3529
|
sessions: sessions.map((t) => {
|
|
3515
3530
|
if (t.id === kanbot.ptyId) return { ...t, kanbot: true };
|
|
3531
|
+
if (t.mode === 'shell' && panes.shellPane(t.id)) return { ...t, pane: true };
|
|
3516
3532
|
const marker = dispatched.get(t.id);
|
|
3517
3533
|
return marker ? { ...t, dispatched: { parent: marker.parent || null } } : t;
|
|
3518
3534
|
}),
|
|
@@ -3592,13 +3608,23 @@ app.get('/vendor/xterm/:file', (req, res) => {
|
|
|
3592
3608
|
|
|
3593
3609
|
// #region DISPATCH
|
|
3594
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));
|
|
3595
3613
|
|
|
3596
3614
|
const linkedDocs = createLinkedDocStore(jsonFile(LINKED_DOCS_FILE));
|
|
3597
3615
|
|
|
3616
|
+
const nestStoreOf = (id) => (dispatched.get(id) ? dispatched : forks.get(id) ? forks : null);
|
|
3617
|
+
|
|
3598
3618
|
function withDispatchMarker(sessions) {
|
|
3599
3619
|
return sessions.map((s) => {
|
|
3600
3620
|
const marker = dispatched.get(s.id);
|
|
3601
|
-
|
|
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
|
+
};
|
|
3602
3628
|
});
|
|
3603
3629
|
}
|
|
3604
3630
|
|
|
@@ -3641,10 +3667,10 @@ app.post('/api/dispatch', terminalRoute(async (req, res) => {
|
|
|
3641
3667
|
app.post('/api/dispatch/:id/child', (req, res) => {
|
|
3642
3668
|
const { child } = req.body || {};
|
|
3643
3669
|
if (typeof child !== 'boolean') return res.status(400).json({ error: 'child must be true or false' });
|
|
3644
|
-
const
|
|
3645
|
-
if (!
|
|
3646
|
-
if (child && !
|
|
3647
|
-
if (
|
|
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' });
|
|
3648
3674
|
res.json({ session: req.params.id, child });
|
|
3649
3675
|
});
|
|
3650
3676
|
|
|
@@ -4435,10 +4461,28 @@ async function resolveScratchpadPane(target) {
|
|
|
4435
4461
|
return { kind: 'scratchpad', target: await fs.realpath(path.join(resolveScratchpad(target).dir, SCRATCHPAD_MANIFEST)) };
|
|
4436
4462
|
}
|
|
4437
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
|
+
|
|
4438
4481
|
// A message target is a session log message id, which the board resolves when it shows the pane.
|
|
4439
4482
|
const PANE_RESOLVERS = new Map([
|
|
4440
4483
|
['message', async (target) => ({ kind: 'message', target })],
|
|
4441
4484
|
['scratchpad', resolveScratchpadPane],
|
|
4485
|
+
['shell', resolveShellPane],
|
|
4442
4486
|
]);
|
|
4443
4487
|
|
|
4444
4488
|
app.get('/api/panes/:sessionId', (req, res) => {
|
|
@@ -4448,9 +4492,9 @@ app.get('/api/panes/:sessionId', (req, res) => {
|
|
|
4448
4492
|
|
|
4449
4493
|
app.post('/api/panes/:sessionId', async (req, res) => {
|
|
4450
4494
|
try {
|
|
4451
|
-
const { target, base, title, kind, show } = req.body || {};
|
|
4495
|
+
const { target, base, title, kind, show, run } = req.body || {};
|
|
4452
4496
|
if (typeof target !== 'string' || !target) throw previewError(400, 'target is required', 'bad_target');
|
|
4453
|
-
const resolved = await (PANE_RESOLVERS.get(kind) ?? resolvePaneTarget)(target, base);
|
|
4497
|
+
const resolved = await (PANE_RESOLVERS.get(kind) ?? resolvePaneTarget)(target, base, run);
|
|
4454
4498
|
res.json(panes.add(req.params.sessionId, { ...resolved, title, show: show === true }));
|
|
4455
4499
|
} catch (error) {
|
|
4456
4500
|
paneRouteError(res, error, 'POST /api/panes');
|
|
@@ -4503,8 +4547,10 @@ app.patch('/api/panes/:sessionId/:paneId', (req, res) => {
|
|
|
4503
4547
|
|
|
4504
4548
|
app.delete('/api/panes/:sessionId/:paneId', (req, res) => {
|
|
4505
4549
|
const { sessionId, paneId } = req.params;
|
|
4550
|
+
const pane = panes.get(sessionId).panes.find((p) => p.id === paneId);
|
|
4506
4551
|
const layout = panes.remove(sessionId, paneId);
|
|
4507
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(() => {});
|
|
4508
4554
|
res.json({ layout });
|
|
4509
4555
|
});
|
|
4510
4556
|
// #endregion
|
|
@@ -5058,6 +5104,7 @@ async function runRetention() {
|
|
|
5058
5104
|
const scan = await scanTranscripts(PROJECTS_DIR);
|
|
5059
5105
|
const opts = { known: scan?.ids, maxAgeMs: retentionMs(CLAUDE_DIR) };
|
|
5060
5106
|
const markers = dispatched.prune(opts);
|
|
5107
|
+
const forkMarkers = forks.prune(opts);
|
|
5061
5108
|
const layouts = panes.prune(opts);
|
|
5062
5109
|
if (layouts) queuePaneFileWatch();
|
|
5063
5110
|
const addonSessions = addons.prune(opts);
|
|
@@ -5068,8 +5115,8 @@ async function runRetention() {
|
|
|
5068
5115
|
const wts = worktrees.prune(scan?.dirs);
|
|
5069
5116
|
const taskMaps = await pruneTaskMaps(TASK_MAPS_DIR, opts);
|
|
5070
5117
|
const grouped = expireGroupMembers(scan?.ids);
|
|
5071
|
-
if (markers || layouts || addonSessions || reviews || attachments || shows || contexts || wts || taskMaps || grouped.members) {
|
|
5072
|
-
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`);
|
|
5073
5120
|
}
|
|
5074
5121
|
} catch (e) {
|
|
5075
5122
|
console.warn('[retention] failed:', e.message);
|