claude-code-kanban 7.28.0 → 7.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +14 -5
- package/hub-app.json +1 -1
- package/lib/panes.js +24 -4
- package/lib/scratch-servers.js +119 -0
- 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 +378 -74
- package/public/index.html +4 -1
- package/public/style.css +15 -0
- package/server.js +99 -19
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();
|
|
@@ -10303,7 +10309,7 @@ const LINKED_DOC_OPENERS = {
|
|
|
10303
10309
|
url: { tag: '', hint: ' — opens in a new tab', cls: ' is-url', noun: 'URL' },
|
|
10304
10310
|
scratch: {
|
|
10305
10311
|
tag: '(scratchpad)',
|
|
10306
|
-
hint: ' — opens in the scratch viewer',
|
|
10312
|
+
hint: ' — opens in the scratch viewer; Ctrl+click opens it in a pane',
|
|
10307
10313
|
cls: ' is-editor',
|
|
10308
10314
|
noun: 'path',
|
|
10309
10315
|
url: '/api/scratchpad/open',
|
|
@@ -10766,6 +10772,9 @@ function bindLinkedDocsHandlers(container, sessionId) {
|
|
|
10766
10772
|
removeSessionPreviewPath(sessionId, hit.dataset.path);
|
|
10767
10773
|
forgetServerLinkedDoc(sessionId, hit.dataset.path);
|
|
10768
10774
|
afterLinkedDocsChanged(sessionId);
|
|
10775
|
+
} else if ((e.ctrlKey || e.metaKey) && linkedDocOpener(hit.dataset.path) === 'scratch') {
|
|
10776
|
+
if (container.closest('#team-modal')) closeTeamModal();
|
|
10777
|
+
openScratchpadPane(sessionId, hit.dataset.path);
|
|
10769
10778
|
} else {
|
|
10770
10779
|
openLinkedDoc(hit.dataset.path, getSessionBaseDir(sessionId));
|
|
10771
10780
|
}
|
|
@@ -10886,6 +10895,8 @@ function setupEventSource() {
|
|
|
10886
10895
|
fetchSessions().catch(() => {});
|
|
10887
10896
|
if (currentSessionId) fetchTasks(currentSessionId);
|
|
10888
10897
|
refetchPaneLayout();
|
|
10898
|
+
// A restarted board started none of the viewers the frames still point at.
|
|
10899
|
+
onScratchpadExited(null);
|
|
10889
10900
|
if (sgRev === null) syncSessionGroups();
|
|
10890
10901
|
else if (sgUnsent) persistSessionGroups();
|
|
10891
10902
|
else sgRefresh();
|
|
@@ -11025,6 +11036,10 @@ function setupEventSource() {
|
|
|
11025
11036
|
applyPaneLayout(data.sessionId, data.layout);
|
|
11026
11037
|
}
|
|
11027
11038
|
|
|
11039
|
+
if (data.type === 'scratchpad:exited') {
|
|
11040
|
+
onScratchpadExited(data.manifest);
|
|
11041
|
+
}
|
|
11042
|
+
|
|
11028
11043
|
if (data.type === 'addon:changed' && dockSid) {
|
|
11029
11044
|
fetchDockAddons(dockSid);
|
|
11030
11045
|
}
|
|
@@ -12373,15 +12388,16 @@ function renderFilterState() {
|
|
|
12373
12388
|
function toggleZenMode() {
|
|
12374
12389
|
const leavingSessionZen = zenMode;
|
|
12375
12390
|
if (zenMode) zenMode = false;
|
|
12376
|
-
else if (zenGroup || zenProject)
|
|
12391
|
+
else if (zenGroup || zenProject) setZenScope(null, null);
|
|
12377
12392
|
else {
|
|
12378
12393
|
const el = focusZone === 'sidebar' && sessionsList.querySelector('.kb-selected');
|
|
12379
12394
|
const sel = el && sgDragPayload(el);
|
|
12380
|
-
|
|
12381
|
-
|
|
12395
|
+
setZenScope(
|
|
12396
|
+
sel?.kind === 'group' ? sgGroupById(sel.ref)?.id || null : null,
|
|
12397
|
+
sel?.kind === 'project' ? sel.ref : null,
|
|
12398
|
+
);
|
|
12382
12399
|
zenMode = !zenGroup && !zenProject;
|
|
12383
12400
|
}
|
|
12384
|
-
setZenPeek(zenGroup ? sgKey(zenGroup) : zenProject);
|
|
12385
12401
|
store.setItem(ZEN_KEY, String(zenMode));
|
|
12386
12402
|
renderZenState();
|
|
12387
12403
|
if (zenMode) closeFilterMenu();
|
|
@@ -12391,6 +12407,27 @@ function toggleZenMode() {
|
|
|
12391
12407
|
if (!leavingSessionZen) fetchSessions(false);
|
|
12392
12408
|
}
|
|
12393
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
|
+
|
|
12394
12431
|
function applyHubSettings(s) {
|
|
12395
12432
|
sessionsList.classList.toggle('zen-centered', s.zenCentered === true);
|
|
12396
12433
|
if (s.zenPattern) sessionsList.dataset.zenPattern = s.zenPattern;
|
|
@@ -14428,12 +14465,18 @@ const PANE_ICONS = {
|
|
|
14428
14465
|
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
14466
|
message:
|
|
14430
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>',
|
|
14468
|
+
scratchpad:
|
|
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>',
|
|
14431
14472
|
warning:
|
|
14432
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>',
|
|
14433
14474
|
};
|
|
14434
14475
|
// Map order is recency: the first entry is the one evicted. Keys are `${sessionId}/${paneId}`,
|
|
14435
14476
|
// and the limit spans sessions, so a session switch cannot pile up frames.
|
|
14436
14477
|
const paneFrames = new Map();
|
|
14478
|
+
// Entries go with their view, in mountPane's eviction and unmountPane.
|
|
14479
|
+
const shellFrames = new Map();
|
|
14437
14480
|
const paneReviews = new WeakMap();
|
|
14438
14481
|
// Off-screen views whose file changed; they reload when shown.
|
|
14439
14482
|
const stalePaneViews = new WeakSet();
|
|
@@ -14536,7 +14579,7 @@ function markPaneSide(el, side, focused) {
|
|
|
14536
14579
|
el.classList.toggle('pane-focus', focused);
|
|
14537
14580
|
}
|
|
14538
14581
|
|
|
14539
|
-
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);
|
|
14540
14583
|
|
|
14541
14584
|
function paneMenuLabel(pane, label) {
|
|
14542
14585
|
const cut =
|
|
@@ -14651,6 +14694,7 @@ function mountPane(sid, pane) {
|
|
|
14651
14694
|
while (paneFrames.size > PANE_FRAME_LIMIT) {
|
|
14652
14695
|
const [oldKey, oldView] = paneFrames.entries().next().value;
|
|
14653
14696
|
paneFrames.delete(oldKey);
|
|
14697
|
+
shellFrames.delete(oldView.querySelector('.pane-shell-frame'));
|
|
14654
14698
|
oldView.remove();
|
|
14655
14699
|
}
|
|
14656
14700
|
return key;
|
|
@@ -14679,6 +14723,18 @@ function paneUrlFrame(pane, className) {
|
|
|
14679
14723
|
return frame;
|
|
14680
14724
|
}
|
|
14681
14725
|
|
|
14726
|
+
function mountPaneUrlFrame(pane, view) {
|
|
14727
|
+
const frame = paneUrlFrame(pane, 'pane-frame pane-url-frame modal-zoomable');
|
|
14728
|
+
frame.addEventListener('load', () => {
|
|
14729
|
+
view.classList.remove('keys-bridged');
|
|
14730
|
+
frame.hostKeysSig = null;
|
|
14731
|
+
pushTerminalClaims();
|
|
14732
|
+
});
|
|
14733
|
+
view.appendChild(frame);
|
|
14734
|
+
view.insertAdjacentHTML('beforeend', paneUrlBarHtml());
|
|
14735
|
+
return frame;
|
|
14736
|
+
}
|
|
14737
|
+
|
|
14682
14738
|
async function loadPaneView(sid, pane, view, scroll) {
|
|
14683
14739
|
const blocked = paneBlockedHtml(pane);
|
|
14684
14740
|
if (blocked) {
|
|
@@ -14686,14 +14742,7 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14686
14742
|
return;
|
|
14687
14743
|
}
|
|
14688
14744
|
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());
|
|
14745
|
+
const frame = mountPaneUrlFrame(pane, view);
|
|
14697
14746
|
// Framed at once; a refusal found by the probe swaps the frame for the card.
|
|
14698
14747
|
if ((await probePaneFraming(sid, pane)) === false) {
|
|
14699
14748
|
frame.remove();
|
|
@@ -14706,6 +14755,14 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14706
14755
|
await loadMessagePaneView(sid, pane, view);
|
|
14707
14756
|
return;
|
|
14708
14757
|
}
|
|
14758
|
+
if (pane.kind === 'scratchpad') {
|
|
14759
|
+
await loadScratchpadPaneView(pane, view);
|
|
14760
|
+
return;
|
|
14761
|
+
}
|
|
14762
|
+
if (pane.kind === 'shell') {
|
|
14763
|
+
loadShellPaneView(pane, view);
|
|
14764
|
+
return;
|
|
14765
|
+
}
|
|
14709
14766
|
const data = await getJson('/api/preview', null, { query: { path: pane.target } });
|
|
14710
14767
|
if (data?.kind === 'html') {
|
|
14711
14768
|
// A show card's own zoom follows the text zoom (showBridge), so its frame is not .modal-zoomable.
|
|
@@ -14740,6 +14797,40 @@ async function loadPaneView(sid, pane, view, scroll) {
|
|
|
14740
14797
|
view.insertAdjacentHTML('beforeend', paneCardHtml(title, text, button));
|
|
14741
14798
|
}
|
|
14742
14799
|
|
|
14800
|
+
// The viewer runs on its own loopback port, a different origin from the board and the hub, so the
|
|
14801
|
+
// URL pane sandbox holds. The board asks for the URL each time it mounts the view, because the
|
|
14802
|
+
// viewer dies with cck and is started again on demand.
|
|
14803
|
+
async function loadScratchpadPaneView(pane, view) {
|
|
14804
|
+
view.insertAdjacentHTML(
|
|
14805
|
+
'beforeend',
|
|
14806
|
+
'<div class="pane-card pane-starting"><div class="pane-card-box"><p>Starting the scratch viewer…</p></div></div>',
|
|
14807
|
+
);
|
|
14808
|
+
const res = await paneRequest('POST', '/api/scratchpad/serve', { path: pane.target });
|
|
14809
|
+
view.querySelector('.pane-starting')?.remove();
|
|
14810
|
+
if (!res.url) {
|
|
14811
|
+
view.insertAdjacentHTML(
|
|
14812
|
+
'beforeend',
|
|
14813
|
+
paneCardHtml('Scratch viewer unavailable', res.error || pane.target, 'Open in scratch viewer'),
|
|
14814
|
+
);
|
|
14815
|
+
return;
|
|
14816
|
+
}
|
|
14817
|
+
mountPaneUrlFrame({ ...pane, target: res.url }, view);
|
|
14818
|
+
}
|
|
14819
|
+
|
|
14820
|
+
// A viewer that exited leaves its frames on a dead port; the views on screen mount again now,
|
|
14821
|
+
// the others when shown.
|
|
14822
|
+
function onScratchpadExited(manifest) {
|
|
14823
|
+
const dead = [];
|
|
14824
|
+
for (const key of paneFrames.keys()) {
|
|
14825
|
+
const [sid, paneId] = key.split('/');
|
|
14826
|
+
const pane = paneLayout(sid).panes.find((p) => p.id === paneId);
|
|
14827
|
+
if (pane?.kind === 'scratchpad' && (!manifest || canonicalPath(pane.target) === manifest)) dead.push([sid, paneId]);
|
|
14828
|
+
}
|
|
14829
|
+
if (!dead.length) return;
|
|
14830
|
+
for (const [sid, paneId] of dead) unmountPane(sid, paneId);
|
|
14831
|
+
syncPanes();
|
|
14832
|
+
}
|
|
14833
|
+
|
|
14743
14834
|
// The target is the message's pin id, `type|timestamp|text`. The log holds only the latest pages,
|
|
14744
14835
|
// so a message not loaded comes from the page that ends at its timestamp.
|
|
14745
14836
|
async function findPaneMessage(sid, target) {
|
|
@@ -14913,6 +15004,7 @@ function focusActivePane() {
|
|
|
14913
15004
|
function focusPaneTarget(target) {
|
|
14914
15005
|
target.focus({ preventScroll: true });
|
|
14915
15006
|
target.contentWindow?.focus();
|
|
15007
|
+
shellFrames.get(target)?.post('focus');
|
|
14916
15008
|
}
|
|
14917
15009
|
|
|
14918
15010
|
function isPaneDocOnScreen() {
|
|
@@ -14940,6 +15032,7 @@ function unmountPane(sid, paneId) {
|
|
|
14940
15032
|
const hadFocus = view?.contains(document.activeElement);
|
|
14941
15033
|
view?.remove();
|
|
14942
15034
|
paneFrames.delete(key);
|
|
15035
|
+
shellFrames.delete(view?.querySelector('.pane-shell-frame'));
|
|
14943
15036
|
// Chrome leaves the window without focus when a focused frame is removed, so no key reaches
|
|
14944
15037
|
// the board until a click. Only when it had focus: under the hub, cck may be off screen.
|
|
14945
15038
|
if (hadFocus) window.focus();
|
|
@@ -15116,7 +15209,11 @@ async function reloadPane(id) {
|
|
|
15116
15209
|
if (!pane) return;
|
|
15117
15210
|
const sid = paneSessionId();
|
|
15118
15211
|
const view = paneFrames.get(`${sid}/${pane.id}`);
|
|
15119
|
-
if (pane.kind
|
|
15212
|
+
if (pane.kind === 'shell') {
|
|
15213
|
+
await restartShellPane(sid, pane);
|
|
15214
|
+
return;
|
|
15215
|
+
}
|
|
15216
|
+
if (pane.kind !== 'url' && pane.kind !== 'scratchpad' && view) {
|
|
15120
15217
|
await reloadPaneView(sid, pane, view);
|
|
15121
15218
|
} else {
|
|
15122
15219
|
unmountPane(sid, pane.id);
|
|
@@ -15128,7 +15225,7 @@ async function reloadPane(id) {
|
|
|
15128
15225
|
|
|
15129
15226
|
function openPaneExternally(id) {
|
|
15130
15227
|
const pane = paneById(id);
|
|
15131
|
-
if (!pane) return;
|
|
15228
|
+
if (!pane || pane.kind === 'shell') return;
|
|
15132
15229
|
if (pane.kind === 'message') {
|
|
15133
15230
|
openPaneMessageDetail(pane);
|
|
15134
15231
|
return;
|
|
@@ -15152,7 +15249,8 @@ async function openPaneMessageDetail(pane) {
|
|
|
15152
15249
|
function copyPaneTarget(id) {
|
|
15153
15250
|
const pane = paneById(id);
|
|
15154
15251
|
if (!pane) return;
|
|
15155
|
-
|
|
15252
|
+
if (pane.kind === 'shell') copyText(pane.cwd || '', 'path');
|
|
15253
|
+
else copyText(pane.target, pane.kind === 'url' ? 'URL' : 'path');
|
|
15156
15254
|
}
|
|
15157
15255
|
|
|
15158
15256
|
function closePaneMenu(restore) {
|
|
@@ -15319,20 +15417,31 @@ function openPaneMenu(x, y, id) {
|
|
|
15319
15417
|
if (!pane) return false;
|
|
15320
15418
|
const url = pane.kind === 'url';
|
|
15321
15419
|
const message = pane.kind === 'message';
|
|
15322
|
-
const
|
|
15420
|
+
const shell = pane.kind === 'shell';
|
|
15323
15421
|
showPaneMenu(
|
|
15324
15422
|
x,
|
|
15325
15423
|
y,
|
|
15326
15424
|
pane.id,
|
|
15327
15425
|
'Pane actions',
|
|
15328
|
-
paneMenuLabel(pane,
|
|
15329
|
-
(message ? '' : paneMenuItem('copy', url ? 'Copy URL' : 'Copy path')) +
|
|
15330
|
-
|
|
15331
|
-
|
|
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
|
|
15332
15441
|
? ''
|
|
15333
15442
|
: paneMenuItem('link', paneIsLinked(pane) ? 'Remove from linked documents' : 'Add to linked documents')) +
|
|
15334
15443
|
paneMenuItem('rename', 'Rename') +
|
|
15335
|
-
paneMenuItem('reload', 'Reload') +
|
|
15444
|
+
paneMenuItem('reload', shell ? 'Restart shell' : 'Reload') +
|
|
15336
15445
|
(url ? paneMenuItem('dock', pane.dock ? 'Remove from the dock' : 'Dock beside the terminal') : '') +
|
|
15337
15446
|
paneGroupMenuItems(pane.id) +
|
|
15338
15447
|
paneMenuItem('close', 'Close pane'),
|
|
@@ -15448,6 +15557,13 @@ function applyPaneLine(view) {
|
|
|
15448
15557
|
markSourceLine(body, line);
|
|
15449
15558
|
}
|
|
15450
15559
|
|
|
15560
|
+
// The same pad again returns its pane, so a second Ctrl+click only shows it.
|
|
15561
|
+
async function openScratchpadPane(sid, manifest) {
|
|
15562
|
+
const onScreen = await postPane(sid, { kind: 'scratchpad', target: manifest });
|
|
15563
|
+
if (onScreen) syncPanes();
|
|
15564
|
+
toastPaneAdded(sid, onScreen, linkedDocLabel(manifest));
|
|
15565
|
+
}
|
|
15566
|
+
|
|
15451
15567
|
async function openPaneAtLine(sid, { path, line }, base) {
|
|
15452
15568
|
const onScreen = await postPane(sid, { target: path, base });
|
|
15453
15569
|
if (onScreen === null) return;
|
|
@@ -15574,8 +15690,13 @@ function movePanePopHighlight(step) {
|
|
|
15574
15690
|
}
|
|
15575
15691
|
|
|
15576
15692
|
function openPanePop() {
|
|
15577
|
-
|
|
15693
|
+
const sid = paneSessionId();
|
|
15694
|
+
if (!sid) return;
|
|
15578
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) : '';
|
|
15579
15700
|
renderPanePopDocs();
|
|
15580
15701
|
panePop.classList.add('visible');
|
|
15581
15702
|
panePopInput.focus();
|
|
@@ -15871,7 +15992,10 @@ panePop.addEventListener('keydown', (e) => {
|
|
|
15871
15992
|
return;
|
|
15872
15993
|
}
|
|
15873
15994
|
if (e.target !== panePopInput) return;
|
|
15874
|
-
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') {
|
|
15875
15999
|
e.preventDefault();
|
|
15876
16000
|
addPane(panePopMatches[panePopIdx] ?? panePopInput.value);
|
|
15877
16001
|
} else if (matchKey(e, 'ArrowDown', 'ArrowUp')) {
|
|
@@ -16260,13 +16384,31 @@ function ensureTerminalFrame() {
|
|
|
16260
16384
|
return ready;
|
|
16261
16385
|
}
|
|
16262
16386
|
|
|
16263
|
-
function
|
|
16264
|
-
|
|
16387
|
+
function createTerminalFrame(
|
|
16388
|
+
className,
|
|
16389
|
+
title,
|
|
16390
|
+
origin = termFrame.sameOrigin ? location.origin : terminalFrameOrigin(),
|
|
16391
|
+
) {
|
|
16265
16392
|
const el = document.createElement('iframe');
|
|
16266
|
-
el.className =
|
|
16267
|
-
el.title =
|
|
16393
|
+
el.className = className;
|
|
16394
|
+
el.title = title;
|
|
16268
16395
|
el.allow = 'clipboard-read; clipboard-write';
|
|
16269
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);
|
|
16270
16412
|
resetTerminalFrame({ el, origin });
|
|
16271
16413
|
return new Promise((resolve, reject) => {
|
|
16272
16414
|
const timer = setTimeout(() => {
|
|
@@ -16289,6 +16431,7 @@ function sendTerminalTheme() {
|
|
|
16289
16431
|
for (const [frame, post] of [
|
|
16290
16432
|
[termFrame, postToTerminalFrame],
|
|
16291
16433
|
[kanbotState, postToKanbotFrame],
|
|
16434
|
+
...[...shellFrames.values()].map((s) => [s, s.post]),
|
|
16292
16435
|
]) {
|
|
16293
16436
|
if (!frame.inited || key === frame.theme) continue;
|
|
16294
16437
|
frame.theme = key;
|
|
@@ -16481,7 +16624,15 @@ function pushTerminalClaims() {
|
|
|
16481
16624
|
const bridged = bridgedFrameEls();
|
|
16482
16625
|
const urlFrames = urlPaneFrames();
|
|
16483
16626
|
const dockEls = dockFrameEls();
|
|
16484
|
-
if (
|
|
16627
|
+
if (
|
|
16628
|
+
!termFrame.inited &&
|
|
16629
|
+
!kanbotState.inited &&
|
|
16630
|
+
!bridged.length &&
|
|
16631
|
+
!urlFrames.length &&
|
|
16632
|
+
!dockEls.length &&
|
|
16633
|
+
!shellFrames.size
|
|
16634
|
+
)
|
|
16635
|
+
return;
|
|
16485
16636
|
const claims = keyClaims();
|
|
16486
16637
|
const base = bridgeClaims(claims);
|
|
16487
16638
|
sendBridgeClaimsAll(bridged, base);
|
|
@@ -16490,6 +16641,10 @@ function pushTerminalClaims() {
|
|
|
16490
16641
|
const sig = JSON.stringify(claims);
|
|
16491
16642
|
sendFrameClaims(kanbotState, claims, sig, postToKanbotFrame);
|
|
16492
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);
|
|
16493
16648
|
});
|
|
16494
16649
|
}
|
|
16495
16650
|
|
|
@@ -16547,6 +16702,7 @@ function adjustTerminalFontSize(step) {
|
|
|
16547
16702
|
else store.setItem(TERMINAL_FONT_KEY, String(size));
|
|
16548
16703
|
termState.fontSize = size;
|
|
16549
16704
|
terminalFrameSend('font', { size });
|
|
16705
|
+
for (const s of shellFrames.values()) if (s.inited) s.post('font', { size });
|
|
16550
16706
|
layoutShow();
|
|
16551
16707
|
}
|
|
16552
16708
|
showToast(`Terminal ${size}px`);
|
|
@@ -16976,7 +17132,13 @@ async function renderTerminalManager() {
|
|
|
16976
17132
|
body.innerHTML = list
|
|
16977
17133
|
.map((t) => {
|
|
16978
17134
|
const session = sessions.find((s) => s.id === t.id);
|
|
16979
|
-
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);
|
|
16980
17142
|
const here = t.id === termState.sessionId ? '<span class="terminal-manager-here">this tab</span>' : '';
|
|
16981
17143
|
const attached = t.clients ? `${t.clients} attached` : 'detached';
|
|
16982
17144
|
return `<div class="terminal-manager-row${t.clients ? ' attached' : ''}">
|
|
@@ -16992,7 +17154,7 @@ async function renderTerminalManager() {
|
|
|
16992
17154
|
</div>
|
|
16993
17155
|
</div>
|
|
16994
17156
|
<div class="terminal-manager-actions">
|
|
16995
|
-
|
|
17157
|
+
${t.pane ? '' : `<button type="button" class="btn btn-secondary" data-open="${escapeHtml(t.id)}"${t.kanbot ? ' data-kanbot' : ''}>Open</button>`}
|
|
16996
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>
|
|
16997
17159
|
</div>
|
|
16998
17160
|
</div>`;
|
|
@@ -17185,12 +17347,8 @@ function toggleKanbot(force) {
|
|
|
17185
17347
|
}
|
|
17186
17348
|
kanbotState.frame?.focus();
|
|
17187
17349
|
if (!kanbotState.frame) {
|
|
17188
|
-
const frame =
|
|
17189
|
-
|
|
17190
|
-
frame.title = 'Kanbot';
|
|
17191
|
-
frame.allow = 'clipboard-read; clipboard-write';
|
|
17192
|
-
kanbotState.origin = termFrame.sameOrigin ? location.origin : terminalFrameOrigin();
|
|
17193
|
-
frame.src = `${kanbotState.origin}/terminal.html#p=${encodeURIComponent(location.origin)}`;
|
|
17350
|
+
const { el: frame, origin } = createTerminalFrame('kanbot-frame', 'Kanbot');
|
|
17351
|
+
kanbotState.origin = origin;
|
|
17194
17352
|
kanbotState.frame = frame;
|
|
17195
17353
|
el.querySelector('.kanbot-body').appendChild(frame);
|
|
17196
17354
|
return;
|
|
@@ -17233,11 +17391,7 @@ window.addEventListener('message', (e) => {
|
|
|
17233
17391
|
if (typeof m?.type !== 'string' || !m.type.startsWith(TERMINAL_MSG)) return;
|
|
17234
17392
|
const t = m.type.slice(TERMINAL_MSG.length);
|
|
17235
17393
|
if (t === 'loaded') {
|
|
17236
|
-
|
|
17237
|
-
kanbotState.inited = false;
|
|
17238
|
-
kanbotState.claims = null;
|
|
17239
|
-
kanbotState.theme = JSON.stringify(themeOptions);
|
|
17240
|
-
postToKanbotFrame('init', terminalInitOptions(themeOptions));
|
|
17394
|
+
initTerminalFrame(kanbotState, postToKanbotFrame);
|
|
17241
17395
|
return;
|
|
17242
17396
|
}
|
|
17243
17397
|
if (t === 'term') {
|
|
@@ -17269,6 +17423,149 @@ window.addEventListener('message', (e) => {
|
|
|
17269
17423
|
|
|
17270
17424
|
//#endregion
|
|
17271
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
|
+
|
|
17272
17569
|
//#region ASK
|
|
17273
17570
|
// The question the session in the embedded terminal asks with the ask tool; the tool call waits for
|
|
17274
17571
|
// the answer. Hiding keeps the frame, so a half-filled card comes back as it was. Only an answer, a
|
|
@@ -18765,6 +19062,12 @@ function placeholderSession(id, spec) {
|
|
|
18765
19062
|
prompted: !!(spec.prompted || spec.prompt),
|
|
18766
19063
|
name: spec.name || (spec.forkOf && forkLabel(spec.forkOf)) || PLACEHOLDER_NAMES[spec.mode] || PLACEHOLDER_NAMES.new,
|
|
18767
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,
|
|
18768
19071
|
project: spec.cwd,
|
|
18769
19072
|
worktree: spec.worktree ? { repo: spec.cwd, name: spec.worktree === true ? 'new' : spec.worktree } : null,
|
|
18770
19073
|
modifiedAt: new Date(spec.startedAt).toISOString(),
|
|
@@ -19539,6 +19842,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
19539
19842
|
|
|
19540
19843
|
loadSidebarState();
|
|
19541
19844
|
for (const p of readStoredList(COLLAPSED_GROUPS_KEY)) collapsedProjectGroups.add(p);
|
|
19845
|
+
setZenScope(zenGroup, zenProject);
|
|
19542
19846
|
syncSessionGroups();
|
|
19543
19847
|
initSessionGroupsDnd();
|
|
19544
19848
|
initSessionPicker();
|