@xmoon76/dsh-pi-tui 0.5.3 → 0.5.4
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/README.en.md +174 -150
- package/README.md +118 -103
- package/cordis.patch.yml +54 -2
- package/dist/builtins.mjs +2 -2
- package/dist/client-bootstrap-F5DHFI9t.mjs +5576 -0
- package/dist/context-summary-DAisTA_7.mjs +8557 -0
- package/dist/dispose-cause-CNFuUnjR.mjs +24 -0
- package/dist/entry-control-DvSrndWd.mjs +111 -0
- package/dist/extension/advanced.d.mts +1 -1
- package/dist/extension/unstable.d.mts +1 -1
- package/dist/{extensions-DzpBiiYb.d.mts → extensions-Bte3XOt5.d.mts} +1 -1
- package/dist/{extensions-a-rxanjw.mjs → extensions-CcuMY4n2.mjs} +722 -324
- package/dist/extensions.d.mts +2 -2
- package/dist/extensions.mjs +1 -1
- package/dist/host-bootstrap-DAgKknbY.mjs +119 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +45243 -27018
- package/dist/local-client.mjs +323 -0
- package/dist/local-host.mjs +176 -0
- package/dist/{performance-host-BJT6scGF.mjs → performance-host-CcDJjjVA.mjs} +1 -1
- package/dist/performance-host.mjs +1 -1
- package/dist/{performance-view-jvvd8Jn7.mjs → performance-view-CfGvLZyD.mjs} +1 -1
- package/dist/{public-types-gZi3iFNh.d.mts → public-types-Dgf1bDke.d.mts} +3 -3
- package/dist/runtime-status-0lp9CM0V.mjs +1923 -0
- package/dist/{runtime-BtPH-UUb.mjs → runtime-vc4mdr-R.mjs} +1395 -1088
- package/dist/{session-BZLxhrPQ.mjs → session-tdJHLnJR.mjs} +3329 -281
- package/dist/{startup-D5Xu8diR.mjs → startup-JaVZoTIl.mjs} +54 -13
- package/dist/startup.d.mts +2 -1
- package/dist/startup.mjs +1 -1
- package/dist/{terminal-progress-source-BlmksrSD.mjs → terminal-progress-source-xor3vakJ.mjs} +102 -46
- package/dist/visual-tools.d.mts +62 -0
- package/dist/visual-tools.mjs +556 -0
- package/generated/dsh-presets/README.md +1 -1
- package/package.json +132 -113
- package/dist/context-summary-CxUpNkA9.mjs +0 -2951
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as cancellationError } from "./tasks-D_z5Yjjr.mjs";
|
|
2
|
-
import { $ as
|
|
3
|
-
import {
|
|
2
|
+
import { $t as contextFormOf, B as systemContextBody, Ct as effortChoicesOf, Dt as sanitizedPhysicalLine, Et as projectModelDirectory, G as toolTitle, I as relativizeToCwd, Mt as formatBytes, Nt as runSyncDisposalSteps, St as PROVIDER_DEFAULT, Ut as subCallDisplayStatus, V as toolCardHeader, X as formatSessionAge, Z as sanitizeTerminalText, a as projectTranscriptStructure, at as sanitizeSessionSearchInput, bt as isBuiltInPresetRow, c as contextPresentationKind, d as assistantVisualPresentation, ft as TSP_CONTINUED_INSPECTION_LABEL, ht as TSP_VISUAL_SELECT_LABEL, it as sameWorkspace, jt as sanitizeDisplayText, mt as TSP_VISUAL_COPY_LABEL, nt as workspaceKey, pt as TSP_VISUAL_CHORDS, rt as buildSessionTree, t as contextClusterSummaryParts, tt as shortSessionId, u as planVisualPlacement, wt as initialEffortOf, xt as presetDisplayText, yt as matchesKeyId } from "./context-summary-DAisTA_7.mjs";
|
|
3
|
+
import { A as chartValueRows, B as humanFacingVisualResult, D as chartHumanText, L as PRESENT_VISUAL_TOOL_NAME, O as chartProjection, T as chartDisplayTitle, _ as authorizeSvg, b as svgDetailRows, d as visualFactLine, f as visualParts, j as admitSvg, m as visualPartsFromText, x as svgDigest } from "./runtime-status-0lp9CM0V.mjs";
|
|
4
|
+
import { View, connect, html, span, ui } from "@stencil-hq/tern";
|
|
4
5
|
//#region src/tui/tsp/editor.ts
|
|
5
6
|
/** The grapheme segmenter (`Intl.Segmenter` on Node 24; one shared instance). */
|
|
6
7
|
const segmenter$3 = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
@@ -316,6 +317,7 @@ function createTspInteractionSeat(options) {
|
|
|
316
317
|
const activate = (slot) => {
|
|
317
318
|
active = slot;
|
|
318
319
|
modalEpoch += 1;
|
|
320
|
+
options.beforeModalSeat?.();
|
|
319
321
|
};
|
|
320
322
|
const detachSlot = (slot) => {
|
|
321
323
|
slot.detach?.();
|
|
@@ -1130,11 +1132,12 @@ function createTspInteractionSeat(options) {
|
|
|
1130
1132
|
size: "md"
|
|
1131
1133
|
}, ...body);
|
|
1132
1134
|
};
|
|
1135
|
+
const renderEmptyLayer = () => ui.col({ key: LAYER_KEY });
|
|
1133
1136
|
const renderLayer = () => {
|
|
1134
1137
|
if (active !== void 0) return ui.col({ key: LAYER_KEY }, active.kind === "approval" ? approvalOverlay(active) : questionOverlay(active));
|
|
1135
1138
|
const callbacks = listCallbacks;
|
|
1136
1139
|
if (listOpen && callbacks !== void 0) return ui.col({ key: LAYER_KEY }, listOverlay(callbacks));
|
|
1137
|
-
return
|
|
1140
|
+
return renderEmptyLayer();
|
|
1138
1141
|
};
|
|
1139
1142
|
const desiredFocusId = () => {
|
|
1140
1143
|
if (active !== void 0 && active.kind === "question" && active.editing === active.tab) return `${LAYER_ID}.${overlayKey()}.${ANSWER_KEY}`;
|
|
@@ -1248,6 +1251,7 @@ function createTspInteractionSeat(options) {
|
|
|
1248
1251
|
return event.ev === "focus" || event.ev === "edit" || event.ev === "undo" || event.ev === "send";
|
|
1249
1252
|
},
|
|
1250
1253
|
renderLayer,
|
|
1254
|
+
renderEmptyLayer,
|
|
1251
1255
|
desiredFocusId,
|
|
1252
1256
|
attentionCount: () => attention,
|
|
1253
1257
|
closeTransientList,
|
|
@@ -1258,7 +1262,7 @@ function createTspInteractionSeat(options) {
|
|
|
1258
1262
|
}
|
|
1259
1263
|
//#endregion
|
|
1260
1264
|
//#region src/tui/tsp/picker-text.ts
|
|
1261
|
-
const graphemeSegmenter$
|
|
1265
|
+
const graphemeSegmenter$2 = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
1262
1266
|
/**
|
|
1263
1267
|
* East Asian Wide/Fullwidth, emoji and supplementary planes occupy two columns;
|
|
1264
1268
|
* everything else one. A conservative classification is fine here: it only makes
|
|
@@ -1272,7 +1276,7 @@ const columnsOf = (grapheme) => {
|
|
|
1272
1276
|
/** The display columns of one text (never UTF-16 units). */
|
|
1273
1277
|
function displayWidth(text) {
|
|
1274
1278
|
let width = 0;
|
|
1275
|
-
for (const { segment } of graphemeSegmenter$
|
|
1279
|
+
for (const { segment } of graphemeSegmenter$2.segment(text)) width += columnsOf(segment);
|
|
1276
1280
|
return width;
|
|
1277
1281
|
}
|
|
1278
1282
|
/**
|
|
@@ -1292,7 +1296,7 @@ function clampMiddle(text, columns) {
|
|
|
1292
1296
|
const budget = Math.max(2, columns - 1);
|
|
1293
1297
|
const head = Math.max(1, Math.ceil(budget / 2));
|
|
1294
1298
|
const tail = Math.max(1, budget - head);
|
|
1295
|
-
const graphemes = [...graphemeSegmenter$
|
|
1299
|
+
const graphemes = [...graphemeSegmenter$2.segment(text)].map((entry) => entry.segment);
|
|
1296
1300
|
const take = (source, room) => {
|
|
1297
1301
|
const kept = [];
|
|
1298
1302
|
let used = 0;
|
|
@@ -2851,13 +2855,13 @@ function presetRows(panel) {
|
|
|
2851
2855
|
return [...rows.filter((row) => row.builtIn), ...rows.filter((row) => !row.builtIn)];
|
|
2852
2856
|
}
|
|
2853
2857
|
/** The rows the current query makes visible, in roster order. */
|
|
2854
|
-
function visibleRows$
|
|
2858
|
+
function visibleRows$2(panel) {
|
|
2855
2859
|
const query = panel.query.toLowerCase();
|
|
2856
2860
|
return presetRows(panel).filter((row) => `${row.name} ${row.id} ${row.description ?? ""}`.toLowerCase().includes(query));
|
|
2857
2861
|
}
|
|
2858
2862
|
/** The browse target, or `undefined` when nothing visible is selected. */
|
|
2859
2863
|
function highlightedRow(panel) {
|
|
2860
|
-
return visibleRows$
|
|
2864
|
+
return visibleRows$2(panel).find((row) => row.id === panel.selected);
|
|
2861
2865
|
}
|
|
2862
2866
|
/** The live Session's preset (`Current session`), for a live subject. */
|
|
2863
2867
|
function currentId(panel) {
|
|
@@ -2915,7 +2919,7 @@ function rowBadges(panel, row) {
|
|
|
2915
2919
|
* shipped preset, the declaration's own metadata otherwise); the raw id rides in
|
|
2916
2920
|
* the card's `title` and is complete on the Details page. */
|
|
2917
2921
|
function presetItems(panel) {
|
|
2918
|
-
return visibleRows$
|
|
2922
|
+
return visibleRows$2(panel).map((row) => ({
|
|
2919
2923
|
id: presetItemId(row.id),
|
|
2920
2924
|
label: row.name,
|
|
2921
2925
|
detail: rowDetail(row),
|
|
@@ -2928,7 +2932,7 @@ function presetItems(panel) {
|
|
|
2928
2932
|
* rows the current query really makes visible. An empty group is never painted, so
|
|
2929
2933
|
* a group's count is always the number of cards below it. */
|
|
2930
2934
|
function presetOrder(panel) {
|
|
2931
|
-
const visible = visibleRows$
|
|
2935
|
+
const visible = visibleRows$2(panel);
|
|
2932
2936
|
const order = [];
|
|
2933
2937
|
const groups = [[
|
|
2934
2938
|
BUILT_IN_GROUP_ID,
|
|
@@ -3206,7 +3210,7 @@ function actionKeyboardLive(panel) {
|
|
|
3206
3210
|
}
|
|
3207
3211
|
/** Step the browse target, wrapping (browse only — never a write). */
|
|
3208
3212
|
function stepRow(panel, delta) {
|
|
3209
|
-
const ids = visibleRows$
|
|
3213
|
+
const ids = visibleRows$2(panel).map((row) => row.id);
|
|
3210
3214
|
if (ids.length === 0) return void 0;
|
|
3211
3215
|
const at = ids.findIndex((id) => id === panel.selected);
|
|
3212
3216
|
return ids[(Math.max(at, 0) + delta + ids.length) % ids.length];
|
|
@@ -3406,7 +3410,7 @@ function rowIntent(panel, item, kind) {
|
|
|
3406
3410
|
if (panel.page !== "catalog") return void 0;
|
|
3407
3411
|
const id = presetRowId(item);
|
|
3408
3412
|
if (id === void 0) return void 0;
|
|
3409
|
-
if (!visibleRows$
|
|
3413
|
+
if (!visibleRows$2(panel).some((row) => row.id === id)) return void 0;
|
|
3410
3414
|
return kind === "activate" ? {
|
|
3411
3415
|
kind: "open-details",
|
|
3412
3416
|
rowId: id
|
|
@@ -3769,7 +3773,7 @@ var TspPresetPicker = class {
|
|
|
3769
3773
|
/** Keep the browse target on a card the current query can actually reach. */
|
|
3770
3774
|
align(panel) {
|
|
3771
3775
|
if (highlightedRow(panel) !== void 0) return;
|
|
3772
|
-
panel.selected = visibleRows$
|
|
3776
|
+
panel.selected = visibleRows$2(panel)[0]?.id;
|
|
3773
3777
|
}
|
|
3774
3778
|
/**
|
|
3775
3779
|
* Keep the visible page coherent with what the current read really offers.
|
|
@@ -3879,7 +3883,7 @@ var TspPresetPicker = class {
|
|
|
3879
3883
|
case "open-details":
|
|
3880
3884
|
if (panel.page !== "catalog") return;
|
|
3881
3885
|
if (intent.rowId !== void 0) {
|
|
3882
|
-
if (!visibleRows$
|
|
3886
|
+
if (!visibleRows$2(panel).some((row) => row.id === intent.rowId)) return;
|
|
3883
3887
|
panel.selected = intent.rowId;
|
|
3884
3888
|
}
|
|
3885
3889
|
if (highlightedRow(panel) === void 0) return;
|
|
@@ -3893,7 +3897,7 @@ var TspPresetPicker = class {
|
|
|
3893
3897
|
this.change(panel);
|
|
3894
3898
|
return;
|
|
3895
3899
|
case "browse-row":
|
|
3896
|
-
if (!visibleRows$
|
|
3900
|
+
if (!visibleRows$2(panel).some((row) => row.id === intent.rowId)) return;
|
|
3897
3901
|
panel.selected = intent.rowId;
|
|
3898
3902
|
panel.zone = "list";
|
|
3899
3903
|
this.change(panel);
|
|
@@ -4054,13 +4058,13 @@ const EMPTY_SNAPSHOT = {
|
|
|
4054
4058
|
searchResults: [],
|
|
4055
4059
|
hasMore: false
|
|
4056
4060
|
};
|
|
4057
|
-
const graphemeSegmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
4058
|
-
function graphemeBounds(text) {
|
|
4059
|
-
return [...graphemeSegmenter.segment(text)].map((segment) => segment.index).concat(text.length);
|
|
4061
|
+
const graphemeSegmenter$1 = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
4062
|
+
function graphemeBounds$1(text) {
|
|
4063
|
+
return [...graphemeSegmenter$1.segment(text)].map((segment) => segment.index).concat(text.length);
|
|
4060
4064
|
}
|
|
4061
|
-
function editQuery(panel, key) {
|
|
4065
|
+
function editQuery$1(panel, key) {
|
|
4062
4066
|
if (key.ctrl === true || key.alt === true || key.meta === true) return void 0;
|
|
4063
|
-
const bounds = graphemeBounds(panel.query);
|
|
4067
|
+
const bounds = graphemeBounds$1(panel.query);
|
|
4064
4068
|
if (key.name === "backspace") {
|
|
4065
4069
|
const start = bounds.filter((index) => index < panel.cursor).at(-1) ?? 0;
|
|
4066
4070
|
return {
|
|
@@ -4096,7 +4100,7 @@ function editQuery(panel, key) {
|
|
|
4096
4100
|
const rawCursor = panel.cursor + key.text.length;
|
|
4097
4101
|
return {
|
|
4098
4102
|
query: prefix + panel.query.slice(panel.cursor),
|
|
4099
|
-
cursor: graphemeBounds(prefix).find((index) => index >= rawCursor) ?? prefix.length
|
|
4103
|
+
cursor: graphemeBounds$1(prefix).find((index) => index >= rawCursor) ?? prefix.length
|
|
4100
4104
|
};
|
|
4101
4105
|
}
|
|
4102
4106
|
function queryMode(panel) {
|
|
@@ -4109,15 +4113,15 @@ function browseRows(panel) {
|
|
|
4109
4113
|
function visibleSearchResults(panel) {
|
|
4110
4114
|
return queryMode(panel) ? panel.snapshot.searchResults : [];
|
|
4111
4115
|
}
|
|
4112
|
-
function visibleRows(panel) {
|
|
4116
|
+
function visibleRows$1(panel) {
|
|
4113
4117
|
return queryMode(panel) ? visibleSearchResults(panel).map((result) => result.row) : browseRows(panel).map((entry) => entry.row);
|
|
4114
4118
|
}
|
|
4115
4119
|
function rowFor(panel, id) {
|
|
4116
|
-
return id === void 0 ? void 0 : visibleRows(panel).find((row) => row.id === id);
|
|
4120
|
+
return id === void 0 ? void 0 : visibleRows$1(panel).find((row) => row.id === id);
|
|
4117
4121
|
}
|
|
4118
4122
|
function firstBrowseId(panel) {
|
|
4119
4123
|
const current = panel.request.subject.currentSessionId;
|
|
4120
|
-
const rows = visibleRows(panel);
|
|
4124
|
+
const rows = visibleRows$1(panel);
|
|
4121
4125
|
return rows.some((row) => row.id === current) ? current : rows[0]?.id;
|
|
4122
4126
|
}
|
|
4123
4127
|
function actionDisabledReason(panel, base) {
|
|
@@ -4544,13 +4548,13 @@ var TspSessionBrowser = class {
|
|
|
4544
4548
|
this.changeScope(panel, intent.scope);
|
|
4545
4549
|
return;
|
|
4546
4550
|
case "browse-row":
|
|
4547
|
-
if (!visibleRows(panel).some((row) => row.id === intent.sessionId)) return;
|
|
4551
|
+
if (!visibleRows$1(panel).some((row) => row.id === intent.sessionId)) return;
|
|
4548
4552
|
panel.selected = intent.sessionId;
|
|
4549
4553
|
panel.zone = "list";
|
|
4550
4554
|
this.change(panel);
|
|
4551
4555
|
return;
|
|
4552
4556
|
case "resume": {
|
|
4553
|
-
if (panel.snapshot.resumePending || !visibleRows(panel).some((row) => row.id === intent.sessionId)) return;
|
|
4557
|
+
if (panel.snapshot.resumePending || !visibleRows$1(panel).some((row) => row.id === intent.sessionId)) return;
|
|
4554
4558
|
if (intent.sessionId === panel.request.subject.currentSessionId) {
|
|
4555
4559
|
this.notify("The current session is already active.", "info");
|
|
4556
4560
|
return;
|
|
@@ -4627,7 +4631,7 @@ var TspSessionBrowser = class {
|
|
|
4627
4631
|
delta: key.name === "left" || key.name === "up" ? -1 : 1
|
|
4628
4632
|
};
|
|
4629
4633
|
if (key.name === "enter") return { kind: "activate-action" };
|
|
4630
|
-
const edited = editQuery(panel, key);
|
|
4634
|
+
const edited = editQuery$1(panel, key);
|
|
4631
4635
|
return edited === void 0 ? void 0 : {
|
|
4632
4636
|
kind: "query",
|
|
4633
4637
|
...edited
|
|
@@ -4638,7 +4642,7 @@ var TspSessionBrowser = class {
|
|
|
4638
4642
|
kind: "scope",
|
|
4639
4643
|
scope: panel.scope === "workspace" ? "all" : "workspace"
|
|
4640
4644
|
};
|
|
4641
|
-
const edited = editQuery(panel, key);
|
|
4645
|
+
const edited = editQuery$1(panel, key);
|
|
4642
4646
|
return edited === void 0 ? void 0 : {
|
|
4643
4647
|
kind: "query",
|
|
4644
4648
|
...edited
|
|
@@ -4649,7 +4653,7 @@ var TspSessionBrowser = class {
|
|
|
4649
4653
|
sessionId: panel.selected,
|
|
4650
4654
|
source: "enter"
|
|
4651
4655
|
};
|
|
4652
|
-
const rows = visibleRows(panel);
|
|
4656
|
+
const rows = visibleRows$1(panel);
|
|
4653
4657
|
const index = rows.findIndex((row) => row.id === panel.selected);
|
|
4654
4658
|
const targetIndex = key.name === "home" ? 0 : key.name === "end" ? rows.length - 1 : key.name === "up" ? Math.max(0, index - 1) : key.name === "down" ? Math.min(rows.length - 1, Math.max(0, index) + 1) : key.name === "page_up" ? Math.max(0, index - 5) : key.name === "page_down" ? Math.min(rows.length - 1, Math.max(0, index) + 5) : void 0;
|
|
4655
4659
|
const target = targetIndex === void 0 ? void 0 : rows[targetIndex];
|
|
@@ -4657,7 +4661,7 @@ var TspSessionBrowser = class {
|
|
|
4657
4661
|
kind: "browse-row",
|
|
4658
4662
|
sessionId: target.id
|
|
4659
4663
|
};
|
|
4660
|
-
const edited = editQuery(panel, key);
|
|
4664
|
+
const edited = editQuery$1(panel, key);
|
|
4661
4665
|
return edited === void 0 ? void 0 : {
|
|
4662
4666
|
kind: "query",
|
|
4663
4667
|
...edited
|
|
@@ -4674,7 +4678,7 @@ var TspSessionBrowser = class {
|
|
|
4674
4678
|
}
|
|
4675
4679
|
rowIntent(panel, item, kind) {
|
|
4676
4680
|
const id = item.startsWith("session:") ? item.slice(8) : void 0;
|
|
4677
|
-
if (id === void 0 || !visibleRows(panel).some((row) => row.id === id)) return void 0;
|
|
4681
|
+
if (id === void 0 || !visibleRows$1(panel).some((row) => row.id === id)) return void 0;
|
|
4678
4682
|
return kind === "select" ? {
|
|
4679
4683
|
kind: "browse-row",
|
|
4680
4684
|
sessionId: id
|
|
@@ -4753,209 +4757,1904 @@ var TspSessionBrowser = class {
|
|
|
4753
4757
|
}
|
|
4754
4758
|
};
|
|
4755
4759
|
//#endregion
|
|
4756
|
-
//#region src/tui/tsp/
|
|
4760
|
+
//#region src/tui/tsp/work-hub.ts
|
|
4757
4761
|
/**
|
|
4758
|
-
* The
|
|
4759
|
-
* `TranscriptStructureBlock[] -> TSP view` mapper and its one
|
|
4760
|
-
* presentation-local identity allocator, moved verbatim from the PR1 spike
|
|
4761
|
-
* (`scripts/support/tern-tsp-transcript-view.ts`, which now re-exports this
|
|
4762
|
-
* module so the spike and its tests keep the SAME oracle).
|
|
4762
|
+
* The internal native TSP Work Hub (PR4 B3-A1).
|
|
4763
4763
|
*
|
|
4764
|
-
*
|
|
4765
|
-
*
|
|
4766
|
-
*
|
|
4767
|
-
*
|
|
4768
|
-
*
|
|
4769
|
-
* wire).
|
|
4764
|
+
* ONE native `ui.picker` in the base inline surface's `layer`, with an
|
|
4765
|
+
* optional side Inspector on wide panes. It is a LOCAL presenter: every row
|
|
4766
|
+
* comes from the ONE `TaskRuntime` projection through the
|
|
4767
|
+
* `TaskCenterPresentationPort`, and this class owns only the discardable
|
|
4768
|
+
* panel state (selection, query, refresh state, targets).
|
|
4770
4769
|
*
|
|
4771
|
-
*
|
|
4772
|
-
*
|
|
4773
|
-
*
|
|
4774
|
-
*
|
|
4775
|
-
*
|
|
4776
|
-
*
|
|
4770
|
+
* A2 adds the ONE local Read intent: `Enter` on the current row and the native
|
|
4771
|
+
* `View details` action ask the SESSION RENDERER to open a read-only Work
|
|
4772
|
+
* Details Reader. This presenter never opens a surface, never keeps a second
|
|
4773
|
+
* row catalog and never calls the business `onSelect` — the Reader's resource,
|
|
4774
|
+
* identity and lifecycle belong to `tsp/session.ts`. A3 opens the real command
|
|
4775
|
+
* path: the registered `/tasks` (`/subagents`) handler reaches this presenter
|
|
4776
|
+
* through the ONE `TaskRuntime`, and the TSP display seam advertises
|
|
4777
|
+
* `supportsTaskCenter` only for a pane that negotiated the kinds this Hub and
|
|
4778
|
+
* its Reader really emit.
|
|
4779
|
+
*
|
|
4780
|
+
* Not owned here: catalog reads, Job observation/Stop, subagent viewer,
|
|
4781
|
+
* Question answering, a second Session or a second surface. The native
|
|
4782
|
+
* picker/Inspector only route SELECT/ACTIVATE/ACTION into local panel state.
|
|
4783
|
+
*
|
|
4784
|
+
* @module @xmoon76/dsh-pi-tui/tui/tsp/work-hub
|
|
4777
4785
|
*/
|
|
4786
|
+
/** The side-Inspector request threshold (pane pixels). */
|
|
4787
|
+
const WIDE_PANE_PIXELS = 1120;
|
|
4778
4788
|
/**
|
|
4779
|
-
*
|
|
4780
|
-
*
|
|
4781
|
-
*
|
|
4782
|
-
*
|
|
4783
|
-
* a cold re-hydration) legitimately gets a fresh key: this is presentation
|
|
4784
|
-
* identity, never a domain or wire identity.
|
|
4789
|
+
* The internal pane floor. Below ~40 terminal columns the native cards/action
|
|
4790
|
+
* bar cannot keep an actionable surface reachable, so A1 renders an explicit
|
|
4791
|
+
* unavailable line instead of a clipped picker. (The FINAL product gate is
|
|
4792
|
+
* A3's; this only keeps the internal presenter honest.)
|
|
4785
4793
|
*/
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4794
|
+
const MIN_PANE_PIXELS = 320;
|
|
4795
|
+
/** The native dismissal action id (idempotent, so it carries no revision). */
|
|
4796
|
+
const CLOSE_ACTION_ID = "close";
|
|
4797
|
+
/**
|
|
4798
|
+
* The native read-only Reader action's BASE id. Its real id carries the frame
|
|
4799
|
+
* revision (`details#<rev>`), so an action painted by an older frame can never
|
|
4800
|
+
* open a newer row.
|
|
4801
|
+
*/
|
|
4802
|
+
const DETAILS_ACTION_ID = "details";
|
|
4803
|
+
/** The truthful Picker message when the pane lacks the Reader's capabilities. */
|
|
4804
|
+
const DETAILS_UNAVAILABLE = "Work details unavailable in this pane.";
|
|
4805
|
+
/** A failed/timed-out/lost work status (attention marker, not a tone-only fact). */
|
|
4806
|
+
const FAILURE_STATUSES = /* @__PURE__ */ new Set([
|
|
4807
|
+
"failed",
|
|
4808
|
+
"timed_out",
|
|
4809
|
+
"lost"
|
|
4810
|
+
]);
|
|
4811
|
+
const graphemeSegmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
4812
|
+
/** The UTF-16 boundaries of the query's grapheme clusters. */
|
|
4813
|
+
function graphemeBounds(text) {
|
|
4814
|
+
return [...graphemeSegmenter.segment(text)].map((segment) => segment.index).concat(text.length);
|
|
4802
4815
|
}
|
|
4803
4816
|
/**
|
|
4804
|
-
*
|
|
4805
|
-
*
|
|
4806
|
-
*
|
|
4807
|
-
* a completed execution status.
|
|
4817
|
+
* The picker's local query editor (the same UTF-16/grapheme semantics as the
|
|
4818
|
+
* Session Browser's input). It only edits the panel's filter text; it never
|
|
4819
|
+
* sends a Host query or re-lists a catalog.
|
|
4808
4820
|
*/
|
|
4809
|
-
function
|
|
4810
|
-
|
|
4821
|
+
function editQuery(panel, key) {
|
|
4822
|
+
if (key.ctrl === true || key.alt === true || key.meta === true) return void 0;
|
|
4823
|
+
const bounds = graphemeBounds(panel.query);
|
|
4824
|
+
if (key.name === "backspace") {
|
|
4825
|
+
const start = bounds.filter((index) => index < panel.cursor).at(-1) ?? 0;
|
|
4826
|
+
return {
|
|
4827
|
+
query: panel.query.slice(0, start) + panel.query.slice(panel.cursor),
|
|
4828
|
+
cursor: start
|
|
4829
|
+
};
|
|
4830
|
+
}
|
|
4831
|
+
if (key.name === "delete") {
|
|
4832
|
+
const end = bounds.find((index) => index > panel.cursor) ?? panel.query.length;
|
|
4833
|
+
return {
|
|
4834
|
+
query: panel.query.slice(0, panel.cursor) + panel.query.slice(end),
|
|
4835
|
+
cursor: panel.cursor
|
|
4836
|
+
};
|
|
4837
|
+
}
|
|
4838
|
+
if (key.name === "left") return {
|
|
4839
|
+
query: panel.query,
|
|
4840
|
+
cursor: bounds.filter((index) => index < panel.cursor).at(-1) ?? 0
|
|
4841
|
+
};
|
|
4842
|
+
if (key.name === "right") return {
|
|
4843
|
+
query: panel.query,
|
|
4844
|
+
cursor: bounds.find((index) => index > panel.cursor) ?? panel.query.length
|
|
4845
|
+
};
|
|
4846
|
+
if (key.name === "home") return {
|
|
4847
|
+
query: panel.query,
|
|
4848
|
+
cursor: 0
|
|
4849
|
+
};
|
|
4850
|
+
if (key.name === "end") return {
|
|
4851
|
+
query: panel.query,
|
|
4852
|
+
cursor: panel.query.length
|
|
4853
|
+
};
|
|
4854
|
+
if (key.text === void 0) return void 0;
|
|
4855
|
+
const prefix = panel.query.slice(0, panel.cursor) + key.text;
|
|
4856
|
+
const rawCursor = panel.cursor + key.text.length;
|
|
4857
|
+
return {
|
|
4858
|
+
query: prefix + panel.query.slice(panel.cursor),
|
|
4859
|
+
cursor: graphemeBounds(prefix).find((index) => index >= rawCursor) ?? prefix.length
|
|
4860
|
+
};
|
|
4811
4861
|
}
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
const result = shownToolResult(message, options);
|
|
4819
|
-
if (result !== "") nodes.push(ui.code({
|
|
4820
|
-
key: "result",
|
|
4821
|
-
text: sanitizeDisplayText(result)
|
|
4822
|
-
}));
|
|
4823
|
-
return nodes;
|
|
4862
|
+
/** A work row = a Subagent/external or Job row (a Question is NOT work). */
|
|
4863
|
+
function isWorkRow(item) {
|
|
4864
|
+
return item.source === "subagent" || item.source === "job";
|
|
4865
|
+
}
|
|
4866
|
+
function isFailureStatus(status) {
|
|
4867
|
+
return FAILURE_STATUSES.has(status);
|
|
4824
4868
|
}
|
|
4825
4869
|
/**
|
|
4826
|
-
* The
|
|
4827
|
-
*
|
|
4828
|
-
*
|
|
4829
|
-
* call's own recorded result; an EMPTY batch is a real settled outcome (a late
|
|
4830
|
-
* reply settled the question without a readable batch) and must NOT fall back
|
|
4831
|
-
* to the timeout payload it replaced.
|
|
4870
|
+
* The panel-local row projection: the input order is preserved (the runtime
|
|
4871
|
+
* already committed the stable pre-order), a query filters only the local
|
|
4872
|
+
* rows, and the group derivation never re-sorts or duplicates a row.
|
|
4832
4873
|
*/
|
|
4833
|
-
function
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
return
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
}
|
|
4861
|
-
}, ...body);
|
|
4874
|
+
function visibleRows(panel) {
|
|
4875
|
+
const query = panel.query.trim().toLocaleLowerCase();
|
|
4876
|
+
if (query === "") return panel.items;
|
|
4877
|
+
return panel.items.filter((item) => [
|
|
4878
|
+
item.label,
|
|
4879
|
+
item.status,
|
|
4880
|
+
item.detail,
|
|
4881
|
+
item.suffix,
|
|
4882
|
+
item.mode,
|
|
4883
|
+
item.access,
|
|
4884
|
+
item.parentLabel,
|
|
4885
|
+
item.value
|
|
4886
|
+
].some((text) => text !== void 0 && text.toLocaleLowerCase().includes(query)));
|
|
4887
|
+
}
|
|
4888
|
+
/** The three fixed groups, in screen order; each keeps the input order. */
|
|
4889
|
+
function groupsOf(rows) {
|
|
4890
|
+
const attention = [];
|
|
4891
|
+
const subagents = [];
|
|
4892
|
+
const jobs = [];
|
|
4893
|
+
for (const row of rows) if (row.source === "question") attention.push(row);
|
|
4894
|
+
else if (row.source === "job") jobs.push(row);
|
|
4895
|
+
else subagents.push(row);
|
|
4896
|
+
return {
|
|
4897
|
+
attention,
|
|
4898
|
+
subagents,
|
|
4899
|
+
jobs
|
|
4900
|
+
};
|
|
4862
4901
|
}
|
|
4863
4902
|
/**
|
|
4864
|
-
* The
|
|
4865
|
-
*
|
|
4866
|
-
*
|
|
4903
|
+
* The Owner-accepted attention-first initial selection. It is the TSP
|
|
4904
|
+
* presenter's own local choice; the runtime's `preferredValue` (active work
|
|
4905
|
+
* first) stays the PiTui cursor preference.
|
|
4867
4906
|
*/
|
|
4868
|
-
function
|
|
4869
|
-
const
|
|
4870
|
-
if (
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
if (
|
|
4875
|
-
return
|
|
4876
|
-
key: "body",
|
|
4877
|
-
text: sanitizeDisplayText(body.join("\n"))
|
|
4878
|
-
})];
|
|
4907
|
+
function chooseInitial(rows) {
|
|
4908
|
+
const question = rows.find((item) => item.source === "question");
|
|
4909
|
+
if (question !== void 0) return question.value;
|
|
4910
|
+
const attention = rows.find((item) => isWorkRow(item) && item.attention === true);
|
|
4911
|
+
if (attention !== void 0) return attention.value;
|
|
4912
|
+
const failed = rows.find((item) => isWorkRow(item) && isFailureStatus(item.status));
|
|
4913
|
+
if (failed !== void 0) return failed.value;
|
|
4914
|
+
return rows.find((item) => isWorkRow(item))?.value;
|
|
4879
4915
|
}
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4916
|
+
/**
|
|
4917
|
+
* Keep the user's selection when it survives; otherwise take the next
|
|
4918
|
+
* surviving row after its old position and, only then, the previous one.
|
|
4919
|
+
* Never falls back to an index as an action target.
|
|
4920
|
+
*/
|
|
4921
|
+
function normalizeSelection(selected, oldVisible, newVisible) {
|
|
4922
|
+
if (selected === void 0) return chooseInitial(newVisible);
|
|
4923
|
+
if (newVisible.some((item) => item.value === selected)) return selected;
|
|
4924
|
+
const at = oldVisible.findIndex((item) => item.value === selected);
|
|
4925
|
+
if (at < 0) return chooseInitial(newVisible);
|
|
4926
|
+
for (let index = at + 1; index < oldVisible.length; index += 1) {
|
|
4927
|
+
const candidate = oldVisible[index];
|
|
4928
|
+
if (newVisible.some((item) => item.value === candidate.value)) return candidate.value;
|
|
4929
|
+
}
|
|
4930
|
+
for (let index = at - 1; index >= 0; index -= 1) {
|
|
4931
|
+
const candidate = oldVisible[index];
|
|
4932
|
+
if (newVisible.some((item) => item.value === candidate.value)) return candidate.value;
|
|
4891
4933
|
}
|
|
4892
|
-
return ui.card({
|
|
4893
|
-
key,
|
|
4894
|
-
head: message.origin ?? "System"
|
|
4895
|
-
}, ui.md({
|
|
4896
|
-
key: "body",
|
|
4897
|
-
text: sanitizeDisplayText(message.text)
|
|
4898
|
-
}));
|
|
4899
4934
|
}
|
|
4900
|
-
function
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
}
|
|
4909
|
-
return
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4935
|
+
function toneOf(item) {
|
|
4936
|
+
if (item.source === "question") return "warning";
|
|
4937
|
+
if (isFailureStatus(item.status)) return "error";
|
|
4938
|
+
if (item.active === true || item.status === "running" || item.status === "stopping") return "accent";
|
|
4939
|
+
return "muted";
|
|
4940
|
+
}
|
|
4941
|
+
/** The second line: real status + the durable kind/mode facts (never invented). */
|
|
4942
|
+
function detailText(item) {
|
|
4943
|
+
if (item.source === "question") return `Question · ${item.status}`;
|
|
4944
|
+
if (item.mode === "external") return "External";
|
|
4945
|
+
if (item.source === "job") return [
|
|
4946
|
+
item.status,
|
|
4947
|
+
item.type ?? "job",
|
|
4948
|
+
item.detail
|
|
4949
|
+
].filter((part) => part !== void 0).join(" · ");
|
|
4950
|
+
return [item.status, item.mode ?? item.suffix].filter((part) => part !== void 0).join(" · ");
|
|
4951
|
+
}
|
|
4952
|
+
function pickerItem(item) {
|
|
4953
|
+
const label = `${item.treePrefix ?? ""}${item.label}`;
|
|
4954
|
+
return {
|
|
4955
|
+
id: item.value,
|
|
4956
|
+
label: sanitizeTerminalText(label),
|
|
4957
|
+
detail: sanitizeTerminalText(detailText(item)),
|
|
4958
|
+
dot: toneOf(item),
|
|
4959
|
+
title: sanitizeTerminalText(`${item.label}\n${detailText(item)}\n${item.value}`)
|
|
4960
|
+
};
|
|
4914
4961
|
}
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
const
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4962
|
+
/** The Inspector's read-only fact rows, from the SAME `TaskPanelItem`. */
|
|
4963
|
+
function inspectorFacts(item) {
|
|
4964
|
+
const type = item.source === "question" ? "Question" : item.mode === "external" ? "External" : item.type ?? item.source ?? "Work";
|
|
4965
|
+
const facts = [["Type", type]];
|
|
4966
|
+
if (item.status !== "" && item.status !== type) facts.push(["Status", item.status]);
|
|
4967
|
+
if (item.mode !== void 0 && item.mode !== "external") facts.push(["Mode", item.mode]);
|
|
4968
|
+
if (item.access !== void 0) facts.push(["Access", item.access]);
|
|
4969
|
+
const parent = item.parentLabel ?? item.parentId;
|
|
4970
|
+
if (parent !== void 0 && parent !== "") facts.push(["Parent", parent]);
|
|
4971
|
+
if (item.depth !== void 0) facts.push(["Depth", String(item.depth)]);
|
|
4972
|
+
facts.push(["Stable ID", item.value]);
|
|
4973
|
+
return facts;
|
|
4974
|
+
}
|
|
4975
|
+
/** The Inspector: selected work facts only, no actions, no invented values. */
|
|
4976
|
+
function workHubInspector(row) {
|
|
4977
|
+
if (row === void 0) return ui.col({ key: "work-hub-inspector" }, ui.text(span("Select a work item.", "muted")));
|
|
4978
|
+
return ui.col({
|
|
4979
|
+
key: "work-hub-inspector",
|
|
4980
|
+
gap: "xs"
|
|
4981
|
+
}, ui.text({ key: "work-hub-inspector-title" }, span("Selected work", "muted")), ui.text({
|
|
4982
|
+
key: "work-hub-inspector-label",
|
|
4983
|
+
wrap: "word"
|
|
4984
|
+
}, span(sanitizeTerminalText(row.label), "accent")), ...inspectorFacts(row).map(([label, value], index) => ui.text({
|
|
4985
|
+
key: `work-hub-inspector-fact-${index}`,
|
|
4986
|
+
wrap: "word"
|
|
4987
|
+
}, [span(`${label.padEnd(10)}`, "muted"), sanitizeTerminalText(value)])));
|
|
4988
|
+
}
|
|
4989
|
+
function subtitleText(groups) {
|
|
4990
|
+
const work = [...groups.subagents, ...groups.jobs];
|
|
4991
|
+
const running = work.filter((item) => item.active === true || item.status === "running" || item.status === "stopping").length;
|
|
4992
|
+
const failed = work.filter((item) => isFailureStatus(item.status)).length;
|
|
4993
|
+
const parts = [];
|
|
4994
|
+
if (groups.attention.length > 0) parts.push(`${groups.attention.length} attention`);
|
|
4995
|
+
if (running > 0) parts.push(`${running} running`);
|
|
4996
|
+
if (failed > 0) parts.push(`${failed} failed`);
|
|
4997
|
+
return parts.length === 0 ? void 0 : parts.join(" · ");
|
|
4929
4998
|
}
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4999
|
+
/**
|
|
5000
|
+
* The ONE layer node: one native picker plus the optional Inspector child.
|
|
5001
|
+
*
|
|
5002
|
+
* The native actions are `Close` plus — ONLY while a current visible row can
|
|
5003
|
+
* be read and the renderer negotiated the Reader's capabilities — the primary
|
|
5004
|
+
* `View details` whose id carries this frame's revision. A pane that cannot
|
|
5005
|
+
* present the Reader paints the truthful unavailability message instead of a
|
|
5006
|
+
* button that would do nothing.
|
|
5007
|
+
*/
|
|
5008
|
+
function hubLayer(panel, wide, admission) {
|
|
5009
|
+
const rows = visibleRows(panel);
|
|
5010
|
+
const groups = groupsOf(rows);
|
|
5011
|
+
const selectedRow = panel.selected === void 0 ? void 0 : rows.find((row) => row.value === panel.selected);
|
|
5012
|
+
const order = [];
|
|
5013
|
+
if (groups.attention.length > 0) {
|
|
5014
|
+
order.push({
|
|
5015
|
+
group: "work-attention",
|
|
5016
|
+
label: "Needs attention",
|
|
5017
|
+
count: groups.attention.length
|
|
5018
|
+
});
|
|
5019
|
+
for (const row of groups.attention) order.push(row.value);
|
|
5020
|
+
}
|
|
5021
|
+
if (groups.subagents.length > 0) {
|
|
5022
|
+
order.push({
|
|
5023
|
+
group: "work-subagents",
|
|
5024
|
+
label: "Work · Subagents",
|
|
5025
|
+
count: groups.subagents.length
|
|
5026
|
+
});
|
|
5027
|
+
for (const row of groups.subagents) order.push(row.value);
|
|
5028
|
+
}
|
|
5029
|
+
if (groups.jobs.length > 0) {
|
|
5030
|
+
order.push({
|
|
5031
|
+
group: "work-jobs",
|
|
5032
|
+
label: "Work · Jobs",
|
|
5033
|
+
count: groups.jobs.length
|
|
5034
|
+
});
|
|
5035
|
+
for (const row of groups.jobs) order.push(row.value);
|
|
5036
|
+
}
|
|
5037
|
+
const message = admission === "unsupported" ? DETAILS_UNAVAILABLE : panel.refresh === "stale" ? `Could not refresh tasks; showing last known entries.${panel.refreshError === void 0 ? "" : ` ${sanitizeTerminalText(panel.refreshError)}`}` : void 0;
|
|
5038
|
+
const subtitle = subtitleText(groups);
|
|
5039
|
+
const detailsAvailable = admission === "available" && selectedRow !== void 0;
|
|
5040
|
+
const focused = panel.zone !== "actions" ? void 0 : detailsAvailable && panel.actionFocus === "details" ? "details" : "close";
|
|
5041
|
+
const actions = [{
|
|
5042
|
+
id: CLOSE_ACTION_ID,
|
|
5043
|
+
label: focused === "close" ? "Close [Enter]" : "Close",
|
|
5044
|
+
keys: ["escape"]
|
|
5045
|
+
}];
|
|
5046
|
+
if (detailsAvailable) actions.push({
|
|
5047
|
+
id: `${DETAILS_ACTION_ID}#${panel.revision}`,
|
|
5048
|
+
label: focused === "details" ? "View details [Enter]" : "View details",
|
|
5049
|
+
primary: true
|
|
5050
|
+
});
|
|
5051
|
+
const props = {
|
|
5052
|
+
key: `work-hub-picker-${panel.serial}`,
|
|
5053
|
+
title: "Work Hub",
|
|
5054
|
+
...subtitle === void 0 ? {} : { subtitle },
|
|
5055
|
+
layout: "cards",
|
|
5056
|
+
size: "lg",
|
|
5057
|
+
preview: wide ? "side" : "none",
|
|
5058
|
+
query: panel.query,
|
|
5059
|
+
cursor: panel.cursor,
|
|
5060
|
+
placeholder: "Search work…",
|
|
5061
|
+
noun: "work",
|
|
5062
|
+
focus: panel.zone === "list" ? "list" : void 0,
|
|
5063
|
+
state: panel.refresh === "loading" ? "loading" : panel.refresh === "stale" ? "error" : "ready",
|
|
5064
|
+
...message === void 0 ? {} : { message },
|
|
5065
|
+
empty: panel.query.trim() === "" ? "No tasks are available for this session." : "No work matches this search.",
|
|
5066
|
+
total: rows.length,
|
|
5067
|
+
items: rows.map(pickerItem),
|
|
5068
|
+
order,
|
|
5069
|
+
...selectedRow === void 0 ? {} : { selected: selectedRow.value },
|
|
5070
|
+
actions
|
|
5071
|
+
};
|
|
5072
|
+
return ui.col({ key: `work-hub-layer-${panel.serial}` }, ui.picker(props, workHubInspector(selectedRow)));
|
|
5073
|
+
}
|
|
5074
|
+
/**
|
|
5075
|
+
* The internal TSP Work Hub presenter. Construction is owned by
|
|
5076
|
+
* `tsp/session.ts`; it is never instantiated by the application layer.
|
|
5077
|
+
*/
|
|
5078
|
+
var TspWorkHub = class {
|
|
5079
|
+
surfaceId;
|
|
5080
|
+
render;
|
|
5081
|
+
canInteract;
|
|
5082
|
+
paneWidth;
|
|
5083
|
+
onViewDetails;
|
|
5084
|
+
detailsAdmissionOf;
|
|
5085
|
+
panel;
|
|
5086
|
+
serial = 0;
|
|
5087
|
+
suspended = false;
|
|
5088
|
+
targets = /* @__PURE__ */ new Map();
|
|
5089
|
+
constructor(deps) {
|
|
5090
|
+
this.surfaceId = deps.surfaceId;
|
|
5091
|
+
this.render = deps.render;
|
|
5092
|
+
this.canInteract = deps.canInteract;
|
|
5093
|
+
this.paneWidth = deps.paneWidth;
|
|
5094
|
+
this.onViewDetails = deps.onViewDetails;
|
|
5095
|
+
this.detailsAdmissionOf = deps.detailsAdmission;
|
|
5096
|
+
}
|
|
5097
|
+
/**
|
|
5098
|
+
* The Task Center presentation sink. Only `openBrowser` reaches a live
|
|
5099
|
+
* panel; the passive PiTui chrome sinks keep NO second business roster or
|
|
5100
|
+
* Quick projection (A1 renders none of them).
|
|
5101
|
+
*/
|
|
5102
|
+
taskPresentation = {
|
|
5103
|
+
openBrowser: (items, onSelect, onClose, options) => this.open(items, onSelect, onClose, options),
|
|
5104
|
+
setQuickTaskItems: () => {},
|
|
5105
|
+
setAgents: () => {},
|
|
5106
|
+
setTasks: () => {},
|
|
5107
|
+
setQuestionAttention: () => {},
|
|
5108
|
+
setTaskSummary: () => {}
|
|
5109
|
+
};
|
|
5110
|
+
current() {
|
|
5111
|
+
const panel = this.panel;
|
|
5112
|
+
if (panel === void 0 || panel.retired) return void 0;
|
|
5113
|
+
return panel;
|
|
5114
|
+
}
|
|
5115
|
+
open(items, onSelect, onClose, options) {
|
|
5116
|
+
const serialBefore = this.serial;
|
|
5117
|
+
this.retire();
|
|
5118
|
+
if (this.serial !== serialBefore) return {
|
|
5119
|
+
close: () => {},
|
|
5120
|
+
setItems: () => {},
|
|
5121
|
+
setRefreshState: () => {}
|
|
5122
|
+
};
|
|
5123
|
+
const panel = {
|
|
5124
|
+
serial: ++this.serial,
|
|
5125
|
+
revision: 0,
|
|
5126
|
+
retired: false,
|
|
5127
|
+
items: [...items],
|
|
5128
|
+
selected: void 0,
|
|
5129
|
+
query: "",
|
|
5130
|
+
cursor: 0,
|
|
5131
|
+
zone: "list",
|
|
5132
|
+
refresh: options.loading ? "loading" : "ready",
|
|
5133
|
+
refreshError: void 0,
|
|
5134
|
+
actionFocus: this.detailsAdmissionOf() === "available" ? "details" : "close",
|
|
5135
|
+
onSelect,
|
|
5136
|
+
onClose,
|
|
5137
|
+
options
|
|
5138
|
+
};
|
|
5139
|
+
panel.selected = chooseInitial(visibleRows(panel));
|
|
5140
|
+
this.panel = panel;
|
|
5141
|
+
this.change(panel);
|
|
5142
|
+
return {
|
|
5143
|
+
close: () => this.closeHandle(panel),
|
|
5144
|
+
setItems: (next, _preferredValue) => this.setItems(panel, next),
|
|
5145
|
+
setRefreshState: (state, error) => this.setRefreshState(panel, state, error)
|
|
5146
|
+
};
|
|
5147
|
+
}
|
|
5148
|
+
setItems(panel, items) {
|
|
5149
|
+
if (this.current() !== panel) return;
|
|
5150
|
+
const oldVisible = visibleRows(panel);
|
|
5151
|
+
panel.items = [...items];
|
|
5152
|
+
if (panel.refresh === "loading") panel.refresh = "ready";
|
|
5153
|
+
panel.selected = normalizeSelection(panel.selected, oldVisible, visibleRows(panel));
|
|
5154
|
+
this.change(panel);
|
|
5155
|
+
}
|
|
5156
|
+
setRefreshState(panel, state, error) {
|
|
5157
|
+
if (this.current() !== panel) return;
|
|
5158
|
+
panel.refresh = state;
|
|
5159
|
+
panel.refreshError = error;
|
|
5160
|
+
this.change(panel);
|
|
5161
|
+
}
|
|
5162
|
+
change(panel) {
|
|
5163
|
+
if (this.panel !== panel || panel.retired) return;
|
|
5164
|
+
panel.revision += 1;
|
|
5165
|
+
this.render();
|
|
5166
|
+
}
|
|
5167
|
+
/**
|
|
5168
|
+
* Programmatic retirement (a sibling presenter's open, a Session hydration,
|
|
5169
|
+
* renderer disposal): retire the panel identity BEFORE notifying its owner,
|
|
5170
|
+
* so a synchronous re-open from that callback owns the slot. No user-close
|
|
5171
|
+
* callback is implied.
|
|
5172
|
+
*/
|
|
5173
|
+
retire() {
|
|
5174
|
+
const panel = this.panel;
|
|
5175
|
+
if (panel === void 0) return;
|
|
5176
|
+
if (panel.retired) return;
|
|
5177
|
+
panel.retired = true;
|
|
5178
|
+
this.panel = void 0;
|
|
5179
|
+
this.targets.clear();
|
|
5180
|
+
panel.options.onRetired("external");
|
|
5181
|
+
}
|
|
5182
|
+
/** The returned handle's `close()`: the TuiApp handle's `external` closure. */
|
|
5183
|
+
closeHandle(panel) {
|
|
5184
|
+
if (panel.retired) return;
|
|
5185
|
+
panel.retired = true;
|
|
5186
|
+
if (this.panel === panel) {
|
|
5187
|
+
this.panel = void 0;
|
|
5188
|
+
this.targets.clear();
|
|
5189
|
+
}
|
|
5190
|
+
try {
|
|
5191
|
+
panel.options.onRetired("external");
|
|
5192
|
+
} finally {
|
|
5193
|
+
this.render();
|
|
5194
|
+
}
|
|
5195
|
+
}
|
|
5196
|
+
/** The user's Esc / native Close: retire, notify `onRetired` and `onClose`. */
|
|
5197
|
+
userClose(panel) {
|
|
5198
|
+
if (panel.retired) return;
|
|
5199
|
+
panel.retired = true;
|
|
5200
|
+
if (this.panel === panel) {
|
|
5201
|
+
this.panel = void 0;
|
|
5202
|
+
this.targets.clear();
|
|
5203
|
+
}
|
|
5204
|
+
try {
|
|
5205
|
+
try {
|
|
5206
|
+
panel.options.onRetired("cancel");
|
|
5207
|
+
} finally {
|
|
5208
|
+
panel.onClose();
|
|
5209
|
+
}
|
|
5210
|
+
} finally {
|
|
5211
|
+
this.render();
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
isOpen() {
|
|
5215
|
+
return this.current() !== void 0;
|
|
5216
|
+
}
|
|
5217
|
+
/**
|
|
5218
|
+
* Invalidate the current frame's targets while another owner takes this
|
|
5219
|
+
* pane's screen (a Modal, or the read-only Reader that covers it). The
|
|
5220
|
+
* selection and query survive; the next real render rebuilds the current
|
|
5221
|
+
* targets.
|
|
5222
|
+
*
|
|
5223
|
+
* The panel revision bump is what retires an ALREADY DELIVERED action id
|
|
5224
|
+
* across that handover. `details#<revision>` names the frame that painted it,
|
|
5225
|
+
* so once this panel is painted again its actions carry a different token. A
|
|
5226
|
+
* delayed `details#N` from before the Reader therefore cannot open a second
|
|
5227
|
+
* reading after the return — a panel whose selection and query are unchanged
|
|
5228
|
+
* would otherwise still match it, letting an old interactive stage run twice.
|
|
5229
|
+
*/
|
|
5230
|
+
suspend() {
|
|
5231
|
+
if (this.suspended) return;
|
|
5232
|
+
this.suspended = true;
|
|
5233
|
+
if (this.panel !== void 0) this.panel.revision += 1;
|
|
5234
|
+
this.targets.clear();
|
|
5235
|
+
}
|
|
5236
|
+
/** The real Picker node target the session renderer asks focus for. */
|
|
5237
|
+
desiredFocusId() {
|
|
5238
|
+
for (const [id, target] of this.targets) if (target.kind === "picker") return id;
|
|
5239
|
+
}
|
|
5240
|
+
tooNarrow() {
|
|
5241
|
+
return this.paneWidth() < MIN_PANE_PIXELS;
|
|
5242
|
+
}
|
|
5243
|
+
/**
|
|
5244
|
+
* The app-side key router. Any key while the hub is open belongs to the
|
|
5245
|
+
* hub (it never leaks to the composer), except the global Ctrl+C cancel,
|
|
5246
|
+
* which the session's existing precedence handles.
|
|
5247
|
+
*/
|
|
5248
|
+
handleKey(key) {
|
|
5249
|
+
const panel = this.current();
|
|
5250
|
+
if (panel === void 0) return false;
|
|
5251
|
+
if (key.ctrl === true && key.name === "c") return false;
|
|
5252
|
+
if (!this.canInteract()) return true;
|
|
5253
|
+
const intent = this.keyIntent(panel, key);
|
|
5254
|
+
if (intent !== void 0) this.act(panel, panel.revision, intent);
|
|
5255
|
+
return true;
|
|
5256
|
+
}
|
|
5257
|
+
keyIntent(panel, key) {
|
|
5258
|
+
if (key.name === "escape") return { kind: "close" };
|
|
5259
|
+
if (this.tooNarrow()) return { kind: "consume" };
|
|
5260
|
+
if (key.name === "tab") return {
|
|
5261
|
+
kind: "zone",
|
|
5262
|
+
zone: panel.zone === "list" ? "actions" : "list"
|
|
5263
|
+
};
|
|
5264
|
+
if (panel.zone === "actions") {
|
|
5265
|
+
if (key.name === "enter") return { kind: "activate-action" };
|
|
5266
|
+
if (key.name === "up" || key.name === "down" || key.name === "left" || key.name === "right") {
|
|
5267
|
+
if (!this.detailsAvailable(panel)) return { kind: "consume" };
|
|
5268
|
+
return {
|
|
5269
|
+
kind: "action-focus",
|
|
5270
|
+
delta: key.name === "up" || key.name === "left" ? -1 : 1
|
|
5271
|
+
};
|
|
5272
|
+
}
|
|
5273
|
+
const edited = editQuery(panel, key);
|
|
5274
|
+
return edited === void 0 ? { kind: "consume" } : {
|
|
5275
|
+
kind: "query",
|
|
5276
|
+
...edited
|
|
5277
|
+
};
|
|
5278
|
+
}
|
|
5279
|
+
if (key.name === "enter") {
|
|
5280
|
+
const current = this.resolveDetails(panel.serial, panel.selected);
|
|
5281
|
+
return current === void 0 ? { kind: "consume" } : {
|
|
5282
|
+
kind: "details",
|
|
5283
|
+
targetValue: current.value
|
|
5284
|
+
};
|
|
5285
|
+
}
|
|
5286
|
+
const rows = visibleRows(panel);
|
|
5287
|
+
const index = rows.findIndex((row) => row.value === panel.selected);
|
|
5288
|
+
const targetIndex = key.name === "home" ? 0 : key.name === "end" ? rows.length - 1 : key.name === "up" ? Math.max(0, index - 1) : key.name === "down" ? Math.min(rows.length - 1, Math.max(0, index) + 1) : key.name === "page_up" ? Math.max(0, index - 5) : key.name === "page_down" ? Math.min(rows.length - 1, Math.max(0, index) + 5) : void 0;
|
|
5289
|
+
const target = targetIndex === void 0 ? void 0 : rows[targetIndex];
|
|
5290
|
+
if (target !== void 0 && target.value !== panel.selected) return {
|
|
5291
|
+
kind: "select",
|
|
5292
|
+
value: target.value
|
|
5293
|
+
};
|
|
5294
|
+
const edited = editQuery(panel, key);
|
|
5295
|
+
return edited === void 0 ? { kind: "consume" } : {
|
|
5296
|
+
kind: "query",
|
|
5297
|
+
...edited
|
|
5298
|
+
};
|
|
5299
|
+
}
|
|
5300
|
+
/** Whether the current row can be read AND the renderer can present it. */
|
|
5301
|
+
detailsAvailable(panel) {
|
|
5302
|
+
return this.detailsAdmissionOf() === "available" && this.resolveDetails(panel.serial, panel.selected) !== void 0;
|
|
5303
|
+
}
|
|
5304
|
+
act(panel, revision, intent) {
|
|
5305
|
+
if (!this.canInteract() || this.current() !== panel || panel.revision !== revision) return;
|
|
5306
|
+
switch (intent.kind) {
|
|
5307
|
+
case "consume": return;
|
|
5308
|
+
case "close":
|
|
5309
|
+
this.userClose(panel);
|
|
5310
|
+
return;
|
|
5311
|
+
case "details": {
|
|
5312
|
+
if (this.detailsAdmissionOf() !== "available") return;
|
|
5313
|
+
const current = this.resolveDetails(panel.serial, intent.targetValue);
|
|
5314
|
+
if (current === void 0) return;
|
|
5315
|
+
const request = {
|
|
5316
|
+
panelSerial: panel.serial,
|
|
5317
|
+
targetValue: current.value
|
|
5318
|
+
};
|
|
5319
|
+
this.onViewDetails(request);
|
|
5320
|
+
return;
|
|
5321
|
+
}
|
|
5322
|
+
case "zone":
|
|
5323
|
+
panel.zone = intent.zone;
|
|
5324
|
+
this.change(panel);
|
|
5325
|
+
return;
|
|
5326
|
+
case "select":
|
|
5327
|
+
if (!visibleRows(panel).some((row) => row.value === intent.value)) return;
|
|
5328
|
+
panel.selected = intent.value;
|
|
5329
|
+
panel.zone = "list";
|
|
5330
|
+
this.change(panel);
|
|
5331
|
+
return;
|
|
5332
|
+
case "query": {
|
|
5333
|
+
const oldVisible = visibleRows(panel);
|
|
5334
|
+
panel.query = intent.query;
|
|
5335
|
+
panel.cursor = intent.cursor;
|
|
5336
|
+
panel.zone = "list";
|
|
5337
|
+
panel.selected = normalizeSelection(panel.selected, oldVisible, visibleRows(panel));
|
|
5338
|
+
this.change(panel);
|
|
5339
|
+
return;
|
|
5340
|
+
}
|
|
5341
|
+
case "action-focus":
|
|
5342
|
+
if (!this.detailsAvailable(panel)) return;
|
|
5343
|
+
panel.actionFocus = panel.actionFocus === "details" ? "close" : "details";
|
|
5344
|
+
this.change(panel);
|
|
5345
|
+
return;
|
|
5346
|
+
case "activate-action":
|
|
5347
|
+
if (panel.zone !== "actions") return;
|
|
5348
|
+
if (this.focusedAction(panel) === "details") {
|
|
5349
|
+
if (this.detailsAdmissionOf() !== "available") return;
|
|
5350
|
+
const current = this.resolveDetails(panel.serial, panel.selected);
|
|
5351
|
+
if (current === void 0) return;
|
|
5352
|
+
this.onViewDetails({
|
|
5353
|
+
panelSerial: panel.serial,
|
|
5354
|
+
targetValue: current.value
|
|
5355
|
+
});
|
|
5356
|
+
return;
|
|
5357
|
+
}
|
|
5358
|
+
this.userClose(panel);
|
|
5359
|
+
return;
|
|
5360
|
+
}
|
|
5361
|
+
}
|
|
5362
|
+
/** The action the action zone's Enter would run, normalized to what exists. */
|
|
5363
|
+
focusedAction(panel) {
|
|
5364
|
+
return panel.actionFocus === "details" && this.detailsAvailable(panel) ? "details" : "close";
|
|
5365
|
+
}
|
|
5366
|
+
eventIntent(panel, event, target) {
|
|
5367
|
+
if (event.ev === "select") {
|
|
5368
|
+
if (target.kind !== "picker" || event.item === void 0) return void 0;
|
|
5369
|
+
return visibleRows(panel).some((row) => row.value === event.item) ? {
|
|
5370
|
+
kind: "select",
|
|
5371
|
+
value: event.item
|
|
5372
|
+
} : void 0;
|
|
5373
|
+
}
|
|
5374
|
+
if (event.ev === "activate") {
|
|
5375
|
+
if (target.kind !== "picker" || event.item === void 0) return void 0;
|
|
5376
|
+
if (event.item !== panel.selected) return void 0;
|
|
5377
|
+
const current = this.resolveDetails(panel.serial, event.item);
|
|
5378
|
+
return current === void 0 ? void 0 : {
|
|
5379
|
+
kind: "details",
|
|
5380
|
+
targetValue: current.value
|
|
5381
|
+
};
|
|
5382
|
+
}
|
|
5383
|
+
if (target.kind !== "picker") return void 0;
|
|
5384
|
+
if (event.ev !== "action") return void 0;
|
|
5385
|
+
if (event.act === CLOSE_ACTION_ID) return { kind: "close" };
|
|
5386
|
+
if (event.act === `${DETAILS_ACTION_ID}#${target.revision}`) {
|
|
5387
|
+
const current = this.resolveDetails(panel.serial, panel.selected);
|
|
5388
|
+
return current === void 0 ? void 0 : {
|
|
5389
|
+
kind: "details",
|
|
5390
|
+
targetValue: current.value
|
|
5391
|
+
};
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
/**
|
|
5395
|
+
* The native event admission: only the surface's own, currently-registered
|
|
5396
|
+
* node of the CURRENT panel/revision may act. The target map is rebuilt
|
|
5397
|
+
* from each real frame, so a retired panel's node is never routable.
|
|
5398
|
+
*/
|
|
5399
|
+
handleEvent(event) {
|
|
5400
|
+
if (event.ev !== "select" && event.ev !== "activate" && event.ev !== "action") return false;
|
|
5401
|
+
if (!("sf" in event) || event.sf !== this.surfaceId || !("id" in event) || typeof event.id !== "string") return false;
|
|
5402
|
+
const target = this.targets.get(event.id);
|
|
5403
|
+
if (target === void 0) return false;
|
|
5404
|
+
const panel = this.current();
|
|
5405
|
+
if (panel === void 0 || target.panel !== panel || target.revision !== panel.revision) return false;
|
|
5406
|
+
if (!this.canInteract()) return false;
|
|
5407
|
+
const intent = this.eventIntent(panel, event, target);
|
|
5408
|
+
if (intent !== void 0) this.act(panel, target.revision, intent);
|
|
5409
|
+
return true;
|
|
5410
|
+
}
|
|
5411
|
+
/**
|
|
5412
|
+
* Build the ONE layer node for the current frame and record its real node
|
|
5413
|
+
* IDs. `undefined` = no panel (the session renderer falls through to its
|
|
5414
|
+
* next presenter / the empty seat layer).
|
|
5415
|
+
*/
|
|
5416
|
+
renderLayer() {
|
|
5417
|
+
this.targets.clear();
|
|
5418
|
+
const panel = this.current();
|
|
5419
|
+
if (panel === void 0) return void 0;
|
|
5420
|
+
if (this.suspended) {
|
|
5421
|
+
this.suspended = false;
|
|
5422
|
+
panel.revision += 1;
|
|
5423
|
+
}
|
|
5424
|
+
if (this.tooNarrow()) return ui.col({}, ui.text({ key: `work-hub-unavailable-${panel.serial}` }, span("Work Hub unavailable at this pane width", "muted")));
|
|
5425
|
+
const revision = panel.revision;
|
|
5426
|
+
const node = hubLayer(panel, this.paneWidth() >= WIDE_PANE_PIXELS, this.detailsAdmissionOf());
|
|
5427
|
+
const pickerKey = `work-hub-picker-${panel.serial}`;
|
|
5428
|
+
for (const root of View.from({ layer: node }).regions) {
|
|
5429
|
+
const visit = (candidate) => {
|
|
5430
|
+
if (candidate === void 0) return;
|
|
5431
|
+
const kind = candidate.props["key"] === pickerKey ? "picker" : "other";
|
|
5432
|
+
this.targets.set(candidate.id, {
|
|
5433
|
+
panel,
|
|
5434
|
+
revision,
|
|
5435
|
+
kind
|
|
5436
|
+
});
|
|
5437
|
+
for (const child of candidate.children) visit(child);
|
|
5438
|
+
};
|
|
5439
|
+
visit(root);
|
|
5440
|
+
}
|
|
5441
|
+
return node;
|
|
5442
|
+
}
|
|
5443
|
+
isCurrentPanel(panelSerial) {
|
|
5444
|
+
return this.current()?.serial === panelSerial;
|
|
5445
|
+
}
|
|
5446
|
+
/**
|
|
5447
|
+
* The ONE current-row resolver used by the Read admission and by every
|
|
5448
|
+
* Reader rerender: the row must survive in the SAME current panel, stay in
|
|
5449
|
+
* the CURRENT visible filter and remain the CURRENT selection. It performs
|
|
5450
|
+
* no source read, no query change and no selection mutation.
|
|
5451
|
+
*/
|
|
5452
|
+
resolveDetails(panelSerial, targetValue) {
|
|
5453
|
+
const panel = this.current();
|
|
5454
|
+
if (panel === void 0 || panel.serial !== panelSerial) return void 0;
|
|
5455
|
+
if (targetValue === void 0 || panel.selected !== targetValue) return void 0;
|
|
5456
|
+
return visibleRows(panel).find((row) => row.value === targetValue);
|
|
5457
|
+
}
|
|
5458
|
+
};
|
|
5459
|
+
//#endregion
|
|
5460
|
+
//#region src/tui/tsp/work-details.ts
|
|
5461
|
+
/**
|
|
5462
|
+
* The Work Details Reader's ONE pure document projection (PR4 B3-A2).
|
|
5463
|
+
*
|
|
5464
|
+
* A Reader is a read-only `mode:'screen'` page presented by the same Tern pane
|
|
5465
|
+
* as the resident inline surface. This module only turns ONE
|
|
5466
|
+
* `TaskPanelItem` — the current, already-authorized Work Hub row — into the
|
|
5467
|
+
* native node tree of that page. It owns no state, opens no surface, reads no
|
|
5468
|
+
* source and calls no business operation: the renderer (`tsp/session.ts`)
|
|
5469
|
+
* owns the temporary Surface, its identity and its lifecycle.
|
|
5470
|
+
*
|
|
5471
|
+
* The document is deliberately plain: a `← Work` navigation row, the full
|
|
5472
|
+
* wrapped label, one derived description, the durable facts that actually
|
|
5473
|
+
* exist on the row, an optional details body and real timestamps. There is NO
|
|
5474
|
+
* fabricated activity stream, Job output, transcript, status timeline or
|
|
5475
|
+
* Stop/Interrupt/Answer control, and the stable row id (`item.value`) is
|
|
5476
|
+
* identity — never regenerated from display text.
|
|
5477
|
+
*
|
|
5478
|
+
* Untrusted text is projected through the SAME display sanitizer as every
|
|
5479
|
+
* other terminal-bound surface; no raw escape/OSC bytes reach the wire.
|
|
5480
|
+
*
|
|
5481
|
+
* @module @xmoon76/dsh-pi-tui/tui/tsp/work-details
|
|
5482
|
+
*/
|
|
5483
|
+
/** The one region a Reader renders its read-only document into. */
|
|
5484
|
+
const WORK_DETAILS_REGION = "main";
|
|
5485
|
+
/**
|
|
5486
|
+
* The key of the Reader's ONE interactive node (the native navigation row the
|
|
5487
|
+
* renderer resolves to its actual node id). Stable for the whole reading.
|
|
5488
|
+
*/
|
|
5489
|
+
function workDetailsBackKey(identity) {
|
|
5490
|
+
return `work-back-${identity.panelSerial}-${identity.readingEpoch}`;
|
|
5491
|
+
}
|
|
5492
|
+
/** The document root key: stable for the whole reading instance. */
|
|
5493
|
+
function documentKey(identity) {
|
|
5494
|
+
return `work-document-${identity.panelSerial}-${identity.readingEpoch}`;
|
|
5495
|
+
}
|
|
5496
|
+
/**
|
|
5497
|
+
* The description's leading word. It states the row's OWN classification: a
|
|
5498
|
+
* Question is never work, and an external leaf is never presented as a local
|
|
5499
|
+
* child Session.
|
|
5500
|
+
*/
|
|
5501
|
+
function sourceWord(item) {
|
|
5502
|
+
if (item.source === "question") return "Question";
|
|
5503
|
+
if (item.source === "job") return "Job";
|
|
5504
|
+
if (item.mode === "external") return "External";
|
|
5505
|
+
if (item.source === "subagent") return "Subagent";
|
|
5506
|
+
return "Work";
|
|
5507
|
+
}
|
|
5508
|
+
/** The one derived description: classification + the row's own status word. */
|
|
5509
|
+
function descriptionText(item) {
|
|
5510
|
+
const word = sourceWord(item);
|
|
5511
|
+
return item.status === "" || item.status === word ? word : `${word} · ${item.status}`;
|
|
5512
|
+
}
|
|
5513
|
+
/**
|
|
5514
|
+
* The largest time value a JS Date can represent (±8.64e15 ms). A value
|
|
5515
|
+
* outside it is not displayable, so the field is omitted instead of fabricated.
|
|
5516
|
+
*/
|
|
5517
|
+
const DISPLAY_TIME_LIMIT = 864e13;
|
|
5518
|
+
/** One real finite millisecond timestamp as UTC ISO 8601, or none. */
|
|
5519
|
+
function isoTime(value) {
|
|
5520
|
+
if (value === void 0 || !Number.isFinite(value) || Math.abs(value) > DISPLAY_TIME_LIMIT) return void 0;
|
|
5521
|
+
return new Date(value).toISOString();
|
|
5522
|
+
}
|
|
5523
|
+
/** One labeled fact line: a muted label and its (wrapped) sanitized value. */
|
|
5524
|
+
function factNode(key, label, value) {
|
|
5525
|
+
return ui.text({
|
|
5526
|
+
key,
|
|
5527
|
+
wrap: "word"
|
|
5528
|
+
}, [span(label.padEnd(10), "muted"), sanitizeDisplayText(value)]);
|
|
5529
|
+
}
|
|
5530
|
+
/**
|
|
5531
|
+
* Build the complete read-only Reader document for ONE current row.
|
|
5532
|
+
*
|
|
5533
|
+
* `onBack` is bound by the Screen owner to the captured reading identity; this
|
|
5534
|
+
* builder holds no mutable state and never decides whether the reader may
|
|
5535
|
+
* close. Every key is stable for the reading instance and never embeds a
|
|
5536
|
+
* revision, selection, row count, width or query.
|
|
5537
|
+
*/
|
|
5538
|
+
function buildWorkDetails(item, identity, onBack) {
|
|
5539
|
+
const started = isoTime(item.startedAt);
|
|
5540
|
+
const finished = isoTime(item.finishedAt);
|
|
5541
|
+
const detail = item.detail === void 0 || item.detail === "" ? void 0 : sanitizeDisplayText(item.detail);
|
|
5542
|
+
const parent = item.parentLabel ?? item.parentId;
|
|
5543
|
+
return ui.col({
|
|
5544
|
+
key: documentKey(identity),
|
|
5545
|
+
gap: "xs"
|
|
5546
|
+
}, ui.row({
|
|
5547
|
+
key: workDetailsBackKey(identity),
|
|
5548
|
+
onClick: onBack
|
|
5549
|
+
}, ui.text(span("← Work", "accent"))), ui.text({
|
|
5550
|
+
key: "work-label",
|
|
5551
|
+
wrap: "word"
|
|
5552
|
+
}, span(sanitizeDisplayText(item.label), "strong")), ui.text({
|
|
5553
|
+
key: "work-description",
|
|
5554
|
+
wrap: "word"
|
|
5555
|
+
}, span(sanitizeDisplayText(descriptionText(item)), "muted")), factNode("work-fact-stable-id", "Stable ID", item.value), ...item.type === void 0 || item.type === "" ? [] : [factNode("work-fact-type", "Type", item.type)], ...item.mode === void 0 || item.mode === "" ? [] : [factNode("work-fact-mode", "Mode", item.mode)], ...item.access === void 0 || item.access === "" ? [] : [factNode("work-fact-access", "Access", item.access)], ...parent === void 0 || parent === "" ? [] : [factNode("work-fact-parent", "Parent", parent)], ...item.depth === void 0 ? [] : [factNode("work-fact-depth", "Depth", String(item.depth))], ...detail === void 0 ? [] : [ui.text({ key: "work-detail-label" }, span("Details", "muted")), ui.text({
|
|
5556
|
+
key: "work-detail",
|
|
5557
|
+
wrap: "word"
|
|
5558
|
+
}, detail)], ...started === void 0 ? [] : [factNode("work-fact-started", "Started", started)], ...finished === void 0 ? [] : [factNode("work-fact-finished", "Finished", finished)]);
|
|
5559
|
+
}
|
|
5560
|
+
//#endregion
|
|
5561
|
+
//#region src/tui/transcript/tool-target-semantics.ts
|
|
5562
|
+
/**
|
|
5563
|
+
* The relativization the head applied to the args-derived summary, applied
|
|
5564
|
+
* HERE to the tool's own proven path so the two strings can be compared.
|
|
5565
|
+
* @param text - the tool's own path.
|
|
5566
|
+
* @param cwd - the workspace root the head relativizes against.
|
|
5567
|
+
*/
|
|
5568
|
+
function relativize(text, cwd) {
|
|
5569
|
+
if (cwd === void 0 || cwd === "") return text;
|
|
5570
|
+
const root = cwd.replace(/[/\\]+$/, "");
|
|
5571
|
+
if (text.startsWith(root + "/") || text.startsWith(root + "\\")) return text.slice(root.length + 1);
|
|
5572
|
+
return text;
|
|
5573
|
+
}
|
|
5574
|
+
/** The paths ONE view proves, per its own shape. */
|
|
5575
|
+
function pathsOfView(view) {
|
|
5576
|
+
if (view === void 0) return [];
|
|
5577
|
+
const paths = /* @__PURE__ */ new Set();
|
|
5578
|
+
if ("locations" in view && view.locations !== void 0) {
|
|
5579
|
+
for (const location of view.locations) if (typeof location.path === "string" && location.path !== "") paths.add(location.path);
|
|
5580
|
+
}
|
|
5581
|
+
if (view.card === "diff") {
|
|
5582
|
+
for (const diff of view.diffs) if (typeof diff.path === "string" && diff.path !== "") paths.add(diff.path);
|
|
5583
|
+
}
|
|
5584
|
+
if (view.card === "read" && typeof view.path === "string" && view.path !== "") paths.add(view.path);
|
|
5585
|
+
return [...paths];
|
|
5586
|
+
}
|
|
5587
|
+
/**
|
|
5588
|
+
* The paths this row's tool proves, from ONE stage only.
|
|
5589
|
+
*
|
|
5590
|
+
* The two stages legitimately spell the SAME file differently: the call view
|
|
5591
|
+
* repeats the argument the model wrote (`src/a.ts`), while the settled result
|
|
5592
|
+
* reports the path the tool resolved (`/workspace/src/a.ts`). Unioning the two
|
|
5593
|
+
* would read one file as two and refuse every settled call — the head would
|
|
5594
|
+
* lose its `path` kind exactly when the call finishes.
|
|
5595
|
+
*
|
|
5596
|
+
* So the settled RESULT is the authority for what happened, and the call view
|
|
5597
|
+
* answers only when the result does NOT prove a path — either because there is
|
|
5598
|
+
* no result view yet (a running call) or because that view carries no path at
|
|
5599
|
+
* all. Whichever stage answers, the "exactly one path" rule is applied WITHIN
|
|
5600
|
+
* that stage, so a genuinely multi-file call still refuses.
|
|
5601
|
+
*/
|
|
5602
|
+
function provenPaths(facts) {
|
|
5603
|
+
const settled = pathsOfView(facts.resultView);
|
|
5604
|
+
if (settled.length > 0) return settled;
|
|
5605
|
+
return pathsOfView(facts.callView);
|
|
5606
|
+
}
|
|
5607
|
+
/**
|
|
5608
|
+
* The tool AUTHOR's own semantic declaration for this call, or undefined. It
|
|
5609
|
+
* is the discriminator that makes `rawInput` safe to read: the same field
|
|
5610
|
+
* holds a command, a pattern, a URL, a skill name or a todo array, and only
|
|
5611
|
+
* the declared kind tells them apart.
|
|
5612
|
+
*/
|
|
5613
|
+
function declaredKind(facts) {
|
|
5614
|
+
const call = facts.callView;
|
|
5615
|
+
if (call === void 0 || !("kind" in call)) return void 0;
|
|
5616
|
+
const kind = call.kind;
|
|
5617
|
+
return typeof kind === "string" ? kind : void 0;
|
|
5618
|
+
}
|
|
5619
|
+
/**
|
|
5620
|
+
* The pattern the tool's own view proves, or undefined. ONLY a tool that
|
|
5621
|
+
* declares the `search` kind may prove a pattern: its salient raw input is
|
|
5622
|
+
* then the pattern the tool searches with. A tool that declares any other
|
|
5623
|
+
* kind proves NOTHING about patterns, no matter what its raw input holds.
|
|
5624
|
+
*/
|
|
5625
|
+
function provenPattern(facts) {
|
|
5626
|
+
if (declaredKind(facts) !== "search") return void 0;
|
|
5627
|
+
const call = facts.callView;
|
|
5628
|
+
if (call === void 0 || !("rawInput" in call)) return void 0;
|
|
5629
|
+
const raw = call.rawInput;
|
|
5630
|
+
return typeof raw === "string" && raw !== "" ? raw : void 0;
|
|
5631
|
+
}
|
|
5632
|
+
/**
|
|
5633
|
+
* Decide the target kind of ONE tool row.
|
|
5634
|
+
*
|
|
5635
|
+
* The inputs are the row's own facts and the tool's registered views; the
|
|
5636
|
+
* output is a kind the client may draw with. The row's DISPLAYED target is
|
|
5637
|
+
* the only string that is ever classified.
|
|
5638
|
+
*
|
|
5639
|
+
* Every refusal below is a CONSEQUENCE of the string-identity proof, not a
|
|
5640
|
+
* separate rule about the row: a merged read group shows `2 files` (never a
|
|
5641
|
+
* proven path), an orphan row shows no target at all, and a row whose tool
|
|
5642
|
+
* declares nothing proves nothing. So the proof itself refuses them.
|
|
5643
|
+
*
|
|
5644
|
+
* @param displayed - the exact string the head will display (the summary).
|
|
5645
|
+
* @param facts - the registered tool's call/result views.
|
|
5646
|
+
* @param cwd - the workspace root the head relativizes against.
|
|
5647
|
+
* @returns the proven kind, or `text` when nothing is proven.
|
|
5648
|
+
*/
|
|
5649
|
+
function toolTargetKind(displayed, facts, cwd) {
|
|
5650
|
+
const pattern = provenPattern(facts);
|
|
5651
|
+
if (pattern !== void 0 && pattern === displayed) return "pattern";
|
|
5652
|
+
const paths = provenPaths(facts);
|
|
5653
|
+
if (paths.length === 1) {
|
|
5654
|
+
const path = paths[0];
|
|
5655
|
+
if (path === displayed || relativize(path, cwd) === displayed) return "path";
|
|
5656
|
+
}
|
|
5657
|
+
return "text";
|
|
5658
|
+
}
|
|
5659
|
+
/**
|
|
5660
|
+
* Read one tool row's registered presentation views through the bridge. The
|
|
5661
|
+
* bridge is the SAME one the PiTui renderer consumes; an absent presenter
|
|
5662
|
+
* yields no views, and the row then stays `text`.
|
|
5663
|
+
* @param presenter - the presentation bridge, when one is wired.
|
|
5664
|
+
* @param message - the folded tool row.
|
|
5665
|
+
* @returns the call/result views the registered tool declares.
|
|
5666
|
+
*/
|
|
5667
|
+
function toolTargetFactsOf(presenter, message) {
|
|
5668
|
+
if (presenter === void 0) return {
|
|
5669
|
+
callView: void 0,
|
|
5670
|
+
resultView: void 0
|
|
5671
|
+
};
|
|
5672
|
+
const callView = presenter.callViewIsToolAuthored === true ? presenter.call(message.name, message.args) : void 0;
|
|
5673
|
+
let resultView;
|
|
5674
|
+
try {
|
|
5675
|
+
resultView = presenter.result(message.name, message.args, {
|
|
5676
|
+
content: message.resultBlocks ?? [],
|
|
5677
|
+
isError: message.status === "error",
|
|
5678
|
+
...message.meta === void 0 ? {} : { meta: message.meta }
|
|
5679
|
+
});
|
|
5680
|
+
} catch {
|
|
5681
|
+
resultView = void 0;
|
|
5682
|
+
}
|
|
5683
|
+
return {
|
|
5684
|
+
callView,
|
|
5685
|
+
resultView
|
|
5686
|
+
};
|
|
5687
|
+
}
|
|
5688
|
+
//#endregion
|
|
5689
|
+
//#region src/tui/tsp/assistant-visual.ts
|
|
5690
|
+
/**
|
|
5691
|
+
* PR3: the ONE pure TSP projector for an Assistant's published visuals.
|
|
5692
|
+
*
|
|
5693
|
+
* It consumes only the PR1-authorized `PublishedVisual[]` and the PR2
|
|
5694
|
+
* `planVisualPlacement()` projection — it never re-derives publication
|
|
5695
|
+
* authority, never parses a marker itself, never reads a Tool card, a blob id
|
|
5696
|
+
* or a cache, and never awaits. The output is the ordered body of the SAME
|
|
5697
|
+
* Assistant `ui.card`: continuous Markdown runs (with the display-only shared
|
|
5698
|
+
* definition prefix), the figure of every inline/tail visual, and every
|
|
5699
|
+
* non-text ContentBlock at its original position through the mapper's own
|
|
5700
|
+
* `nonText` callback.
|
|
5701
|
+
*
|
|
5702
|
+
* A figure is one `ui.col(role='dsh.visual.figure')` inside that card, never a
|
|
5703
|
+
* second top-level card. Its Copy control is a real `html.button` carrying the
|
|
5704
|
+
* ONE pointer action value and NO SDK auto handler: the session owner admits
|
|
5705
|
+
* `event.act === VISUAL_COPY_ACTION` against the copy button node ids of the
|
|
5706
|
+
* current committed frame, so a stale action from an older frame can never be
|
|
5707
|
+
* matched by a ref substring or a bare call id.
|
|
5708
|
+
* @module @xmoon76/dsh-pi-tui/tui/tsp/assistant-visual
|
|
5709
|
+
*/
|
|
5710
|
+
/** The ONE pointer action value a figure's Copy button emits. */
|
|
5711
|
+
const VISUAL_COPY_ACTION = "dsh-visual-copy";
|
|
5712
|
+
/** The figure wrapper's stylesheet role (the scope-local sheet's selector). */
|
|
5713
|
+
const VISUAL_FIGURE_ROLE = "dsh.visual.figure";
|
|
5714
|
+
/** The Copy button's stylesheet role. */
|
|
5715
|
+
const VISUAL_COPY_ROLE = "dsh.visual.copy";
|
|
5716
|
+
/** The figure wrapper key prefix; the published ref completes it. */
|
|
5717
|
+
const VISUAL_FIGURE_KEY_PREFIX = "body-visual-";
|
|
5718
|
+
/** The Copy button's key inside one figure. */
|
|
5719
|
+
const VISUAL_COPY_KEY = "visual-copy";
|
|
5720
|
+
/** The native SVG image's key inside one figure. */
|
|
5721
|
+
const VISUAL_IMAGE_KEY = "visual-image";
|
|
5722
|
+
/** Partition the plan into its per-block pieces, tail figures and run prefixes. */
|
|
5723
|
+
function projectBody(publications, message) {
|
|
5724
|
+
const plan = planVisualPlacement({
|
|
5725
|
+
text: message.text,
|
|
5726
|
+
...message.content === void 0 ? {} : { content: message.content },
|
|
5727
|
+
publications
|
|
5728
|
+
});
|
|
5729
|
+
const piecesByBlock = /* @__PURE__ */ new Map();
|
|
5730
|
+
const tail = [];
|
|
5731
|
+
for (const piece of plan.pieces) {
|
|
5732
|
+
if (piece.kind === "visual" && piece.blockIndex === null) {
|
|
5733
|
+
tail.push({
|
|
5734
|
+
ref: piece.ref,
|
|
5735
|
+
publication: piece.publication
|
|
5736
|
+
});
|
|
5737
|
+
continue;
|
|
5738
|
+
}
|
|
5739
|
+
if (piece.blockIndex === null) continue;
|
|
5740
|
+
const existing = piecesByBlock.get(piece.blockIndex);
|
|
5741
|
+
if (existing === void 0) piecesByBlock.set(piece.blockIndex, [piece]);
|
|
5742
|
+
else existing.push(piece);
|
|
5743
|
+
}
|
|
5744
|
+
const prefixByBlock = /* @__PURE__ */ new Map();
|
|
5745
|
+
for (const definition of plan.definitions) for (const blockIndex of definition.blockIndexes) prefixByBlock.set(blockIndex, definition.prefix);
|
|
5746
|
+
return {
|
|
5747
|
+
piecesByBlock,
|
|
5748
|
+
tail,
|
|
5749
|
+
prefixByBlock
|
|
5750
|
+
};
|
|
5751
|
+
}
|
|
5752
|
+
/** The kind label of one figure head. */
|
|
5753
|
+
function figureKindLabel(source) {
|
|
5754
|
+
return source.chart !== void 0 ? "Chart" : "SVG";
|
|
5755
|
+
}
|
|
5756
|
+
/** The committed display title of one published source (the same text the
|
|
5757
|
+
* figure head and the dock's selection summary use). */
|
|
5758
|
+
function publishedVisualTitle(publication) {
|
|
5759
|
+
const source = publication.source;
|
|
5760
|
+
if (source.chart !== void 0) return sanitizedPhysicalLine(chartDisplayTitle(source.chart));
|
|
5761
|
+
if (source.svg !== void 0) return sanitizedPhysicalLine(source.svg.title);
|
|
5762
|
+
return "Visual";
|
|
5763
|
+
}
|
|
5764
|
+
/** The Copy control: a real button with the ONE session-admitted action value. */
|
|
5765
|
+
function copyButton(source) {
|
|
5766
|
+
const chart = source.chart !== void 0;
|
|
5767
|
+
return html.button({
|
|
5768
|
+
key: VISUAL_COPY_KEY,
|
|
5769
|
+
role: VISUAL_COPY_ROLE,
|
|
5770
|
+
aria: chart ? "Copy chart data" : "Copy SVG",
|
|
5771
|
+
actions: { click: VISUAL_COPY_ACTION }
|
|
5772
|
+
}, chart ? "Copy Data" : "Copy SVG");
|
|
5773
|
+
}
|
|
5774
|
+
/** The native/fallback body of one chart figure. */
|
|
5775
|
+
function chartNodes(fact, supported) {
|
|
5776
|
+
if (!supported) return [ui.code({
|
|
5777
|
+
key: "visual-values",
|
|
5778
|
+
text: sanitizeDisplayText(chartHumanText(fact)),
|
|
5779
|
+
wrap: true
|
|
5780
|
+
})];
|
|
5781
|
+
const projection = chartProjection(fact);
|
|
5782
|
+
return [ui.chart({
|
|
5783
|
+
key: "visual-chart",
|
|
5784
|
+
kind: projection.kind,
|
|
5785
|
+
summary: sanitizeDisplayText(projection.summary),
|
|
5786
|
+
series: projection.series
|
|
5787
|
+
}), ui.code({
|
|
5788
|
+
key: "visual-values",
|
|
5789
|
+
text: sanitizeDisplayText(chartValueRows(fact).join("\n")),
|
|
5790
|
+
wrap: true
|
|
5791
|
+
})];
|
|
5792
|
+
}
|
|
5793
|
+
/** The readable/native body of one SVG figure. */
|
|
5794
|
+
function svgNodes(piece, fact, options) {
|
|
5795
|
+
const nodes = [ui.code({
|
|
5796
|
+
key: "visual-description",
|
|
5797
|
+
text: sanitizeDisplayText(svgDetailRows(fact).join("\n")),
|
|
5798
|
+
wrap: true
|
|
5799
|
+
})];
|
|
5800
|
+
if (!options.nativeImagesSupported) return nodes;
|
|
5801
|
+
const blob = options.requestPublishedSvgBlob?.(piece.publication);
|
|
5802
|
+
if (blob === void 0) return nodes;
|
|
5803
|
+
nodes.push(ui.image({
|
|
5804
|
+
key: VISUAL_IMAGE_KEY,
|
|
5805
|
+
blob,
|
|
5806
|
+
alt: sanitizedPhysicalLine(fact.title),
|
|
5807
|
+
actions: { click: "zoom" }
|
|
5808
|
+
}));
|
|
5809
|
+
return nodes;
|
|
5810
|
+
}
|
|
5811
|
+
/** One figure: head row (kind/title, selection, Copy button) then its body. */
|
|
5812
|
+
function figureNode(piece, options) {
|
|
5813
|
+
const source = piece.publication.source;
|
|
5814
|
+
const head = [ui.text({
|
|
5815
|
+
key: "visual-title",
|
|
5816
|
+
text: sanitizeDisplayText(`${figureKindLabel(source)} · ${publishedVisualTitle(piece.publication)}`),
|
|
5817
|
+
wrap: "word"
|
|
5818
|
+
})];
|
|
5819
|
+
const selected = options.selected;
|
|
5820
|
+
if (selected !== void 0 && selected.ref === piece.ref) head.push(ui.badge({
|
|
5821
|
+
key: "visual-selected",
|
|
5822
|
+
text: `Selected · ${selected.index}/${selected.count}`
|
|
5823
|
+
}));
|
|
5824
|
+
if (source.chart !== void 0 || source.svgSource !== void 0) head.push(copyButton(source));
|
|
5825
|
+
const children = [ui.row({
|
|
5826
|
+
key: "visual-head",
|
|
5827
|
+
wrap: true,
|
|
5828
|
+
gap: "sm"
|
|
5829
|
+
}, ...head)];
|
|
5830
|
+
if (source.chart !== void 0) children.push(...chartNodes(source.chart, options.chartKindsSupported));
|
|
5831
|
+
else if (source.svg !== void 0 && source.svgSource !== void 0) children.push(...svgNodes(piece, source.svg, options));
|
|
5832
|
+
else children.push(ui.text({
|
|
5833
|
+
key: "visual-unavailable",
|
|
5834
|
+
text: "Drawing unavailable — the visual fact is missing"
|
|
5835
|
+
}));
|
|
5836
|
+
return ui.col({
|
|
5837
|
+
key: `${VISUAL_FIGURE_KEY_PREFIX}${piece.ref}`,
|
|
5838
|
+
role: VISUAL_FIGURE_ROLE,
|
|
5839
|
+
gap: "sm"
|
|
5840
|
+
}, ...children);
|
|
5841
|
+
}
|
|
5842
|
+
/**
|
|
5843
|
+
* The ordered body nodes of one eligible final Assistant that owns published
|
|
5844
|
+
* visuals.
|
|
5845
|
+
*
|
|
5846
|
+
* Adjacent text blocks are ONE Markdown document (a bold span or a fence may
|
|
5847
|
+
* cross a ContentBlock boundary); only an inserted figure or a VISIBLE
|
|
5848
|
+
* non-text block flushes the buffer. Reasoning/tool-call blocks have no
|
|
5849
|
+
* Assistant body and therefore never interrupt a Markdown run. The
|
|
5850
|
+
* display-only shared-definition prefix rides each truly independent `ui.md`
|
|
5851
|
+
* run and never enters the source text, search or copy payloads.
|
|
5852
|
+
* @param message - the eligible final Assistant row (its own text/content).
|
|
5853
|
+
* @param publications - the PR1-qualified publications of the row's turn.
|
|
5854
|
+
* @param options - the pane's negotiated capabilities and the mapper's
|
|
5855
|
+
* existing non-text body renderer.
|
|
5856
|
+
* @returns the ordered card children (no card of its own).
|
|
5857
|
+
*/
|
|
5858
|
+
function assistantPublishedVisualNodes(message, publications, options) {
|
|
5859
|
+
const body = projectBody(publications, message);
|
|
5860
|
+
const blocks = message.content !== void 0 && message.content.length > 0 ? message.content : message.text === "" ? [] : [{
|
|
5861
|
+
type: "text",
|
|
5862
|
+
text: message.text
|
|
5863
|
+
}];
|
|
5864
|
+
const nodes = [];
|
|
5865
|
+
let textBuffer = "";
|
|
5866
|
+
let textPrefix = "";
|
|
5867
|
+
let runOrdinal = 0;
|
|
5868
|
+
const flushText = () => {
|
|
5869
|
+
if (textBuffer === "") return;
|
|
5870
|
+
nodes.push(ui.md({
|
|
5871
|
+
key: `body-run-${runOrdinal}`,
|
|
5872
|
+
text: sanitizeDisplayText(`${textPrefix}${textBuffer}`)
|
|
5873
|
+
}));
|
|
5874
|
+
runOrdinal += 1;
|
|
5875
|
+
textBuffer = "";
|
|
5876
|
+
textPrefix = "";
|
|
5877
|
+
};
|
|
5878
|
+
const appendText = (source, blockIndex) => {
|
|
5879
|
+
if (textBuffer === "") textPrefix = body.prefixByBlock.get(blockIndex) ?? "";
|
|
5880
|
+
textBuffer += source;
|
|
5881
|
+
};
|
|
5882
|
+
for (const [blockIndex, block] of blocks.entries()) {
|
|
5883
|
+
if (block.type === "text") {
|
|
5884
|
+
const pieces = body.piecesByBlock.get(blockIndex);
|
|
5885
|
+
if (pieces === void 0) {
|
|
5886
|
+
appendText(block.text, blockIndex);
|
|
5887
|
+
continue;
|
|
5888
|
+
}
|
|
5889
|
+
for (const piece of pieces) {
|
|
5890
|
+
if (piece.kind === "text") {
|
|
5891
|
+
appendText(piece.source, blockIndex);
|
|
5892
|
+
continue;
|
|
5893
|
+
}
|
|
5894
|
+
flushText();
|
|
5895
|
+
nodes.push(figureNode({
|
|
5896
|
+
ref: piece.ref,
|
|
5897
|
+
publication: piece.publication
|
|
5898
|
+
}, options));
|
|
5899
|
+
}
|
|
5900
|
+
continue;
|
|
5901
|
+
}
|
|
5902
|
+
const child = options.nonText?.(block, blockIndex);
|
|
5903
|
+
if (child === void 0 || child.length === 0) continue;
|
|
5904
|
+
flushText();
|
|
5905
|
+
nodes.push(...child);
|
|
5906
|
+
}
|
|
5907
|
+
flushText();
|
|
5908
|
+
for (const piece of body.tail) nodes.push(figureNode(piece, options));
|
|
5909
|
+
return nodes;
|
|
5910
|
+
}
|
|
5911
|
+
//#endregion
|
|
5912
|
+
//#region src/tui/tsp/transcript-view.ts
|
|
5913
|
+
/**
|
|
5914
|
+
* The production TSP transcript mapper (PR3-A): the pure
|
|
5915
|
+
* `TranscriptStructureBlock[] -> TSP view` mapper and its one
|
|
5916
|
+
* presentation-local identity allocator, moved verbatim from the PR1 spike
|
|
5917
|
+
* (`scripts/support/tern-tsp-transcript-view.ts`, which now re-exports this
|
|
5918
|
+
* module so the spike and its tests keep the SAME oracle).
|
|
5919
|
+
*
|
|
5920
|
+
* It reads the canonical transcript structure produced by the production
|
|
5921
|
+
* projector and emits official `@stencil-hq/tern` nodes. It owns no event
|
|
5922
|
+
* application, no turn/tool-result pairing and no durable identity — it never
|
|
5923
|
+
* re-segments Work/Context membership, never classifies a row from its display
|
|
5924
|
+
* text, and never writes transport bytes (the SDK's `View`/`Surface` own the
|
|
5925
|
+
* wire).
|
|
5926
|
+
*
|
|
5927
|
+
* Node keys are presentation identities only: the SDK derives wire ids from a
|
|
5928
|
+
* parent id plus the child's `key`, so a stable `key` keeps an unchanged row
|
|
5929
|
+
* in place across renders. The allocator is scoped to ONE renderer
|
|
5930
|
+
* presentation scope (see `TranscriptNodeKeys`; the renderer re-scopes on a
|
|
5931
|
+
* `sourceIdentity` change); it is not a persistence identity.
|
|
5932
|
+
* @module @xmoon76/dsh-pi-tui/tui/tsp/transcript-view
|
|
5933
|
+
*/
|
|
5934
|
+
/**
|
|
5935
|
+
* One replay-local allocator of presentation keys, scoped to a single
|
|
5936
|
+
* `TranscriptFolder`/`Surface` lifetime. It maps a `TranscriptMessage` object
|
|
5937
|
+
* to `<namespace>-<n>` on first sight, so a retained carrier object keeps its
|
|
5938
|
+
* key through ordinary live updates. A replaced carrier (a merged read group,
|
|
5939
|
+
* a cold re-hydration) legitimately gets a fresh key: this is presentation
|
|
5940
|
+
* identity, never a domain or wire identity.
|
|
5941
|
+
*/
|
|
5942
|
+
var TranscriptNodeKeys = class {
|
|
5943
|
+
#byMessage = /* @__PURE__ */ new WeakMap();
|
|
5944
|
+
#next = 0;
|
|
5945
|
+
/** The stable per-lifetime key of one message, allocated on first sight. */
|
|
5946
|
+
keyFor(message) {
|
|
5947
|
+
const known = this.#byMessage.get(message);
|
|
5948
|
+
if (known !== void 0) return known;
|
|
5949
|
+
this.#next += 1;
|
|
5950
|
+
const key = `msg-${this.#next}`;
|
|
5951
|
+
this.#byMessage.set(message, key);
|
|
5952
|
+
return key;
|
|
5953
|
+
}
|
|
5954
|
+
};
|
|
5955
|
+
/** `ok|error|running` -> the SDK's card/tool `status` vocabulary. */
|
|
5956
|
+
function toolStatus(status) {
|
|
5957
|
+
return status === "ok" ? "done" : status;
|
|
5958
|
+
}
|
|
5959
|
+
/**
|
|
5960
|
+
* Whether one settled tool card has no genuine `tool/call` behind it: an
|
|
5961
|
+
* orphan result (`callCount === 0`, no origin) or the official
|
|
5962
|
+
* `tool-not-started` crash-recovery diagnostic. Such a row must never present
|
|
5963
|
+
* a completed execution status.
|
|
5964
|
+
*/
|
|
5965
|
+
function isUnmatchedToolRow(message) {
|
|
5966
|
+
return message.origin === "tool-not-started" || message.origin === void 0 && message.callCount === 0;
|
|
5967
|
+
}
|
|
5968
|
+
/**
|
|
5969
|
+
* PR-C: the raster media types the project presents as a NATIVE image
|
|
5970
|
+
* attachment. The set is the project's own media vocabulary, never a
|
|
5971
|
+
* negotiated client capability.
|
|
5972
|
+
*/
|
|
5973
|
+
const NATIVE_IMAGE_MEDIA_TYPES = [
|
|
5974
|
+
"image/png",
|
|
5975
|
+
"image/jpeg",
|
|
5976
|
+
"image/webp",
|
|
5977
|
+
"image/gif"
|
|
5978
|
+
];
|
|
5979
|
+
/**
|
|
5980
|
+
* PR-C: the blob id of an image that is NOT ready yet — 64 lowercase hex
|
|
5981
|
+
* zeros. It has the SHAPE of a real blob id, so the pane draws its own
|
|
5982
|
+
* native placeholder for it. The renderer NEVER sends it: no `b` frame names
|
|
5983
|
+
* it, and the real blob id replaces it under the SAME node key when the
|
|
5984
|
+
* authorized read settles.
|
|
5985
|
+
*/
|
|
5986
|
+
const PENDING_IMAGE_BLOB_ID = "0".repeat(64);
|
|
5987
|
+
/**
|
|
5988
|
+
* PR-C: the external-input check on ONE image attachment reference. The
|
|
5989
|
+
* reference crosses a Host boundary, so its identity and its media type are
|
|
5990
|
+
* validated here — the mapper never trusts them because "the tool produced
|
|
5991
|
+
* it".
|
|
5992
|
+
* @param ref - the block's attachment reference (untrusted).
|
|
5993
|
+
* @returns the problem, or `undefined` when the reference is presentable.
|
|
5994
|
+
*/
|
|
5995
|
+
function imageRefProblem(ref) {
|
|
5996
|
+
if (ref === null || typeof ref !== "object") return "invalid";
|
|
5997
|
+
const candidate = ref;
|
|
5998
|
+
if (typeof candidate.attachmentId !== "string" || candidate.attachmentId === "") return "invalid";
|
|
5999
|
+
if (typeof candidate.width !== "number" || !Number.isSafeInteger(candidate.width) || candidate.width <= 0) return "invalid";
|
|
6000
|
+
if (typeof candidate.height !== "number" || !Number.isSafeInteger(candidate.height) || candidate.height <= 0) return "invalid";
|
|
6001
|
+
if (typeof candidate.bytes !== "number" || !Number.isSafeInteger(candidate.bytes) || candidate.bytes < 0) return "invalid";
|
|
6002
|
+
if (typeof candidate.mediaType !== "string" || !NATIVE_IMAGE_MEDIA_TYPES.includes(candidate.mediaType)) return "unsupported-format";
|
|
6003
|
+
}
|
|
6004
|
+
/** PR-C: whether one attachment reference is a presentable native image. */
|
|
6005
|
+
function isPresentableImageRef(ref) {
|
|
6006
|
+
return imageRefProblem(ref) === void 0;
|
|
6007
|
+
}
|
|
6008
|
+
/**
|
|
6009
|
+
* PR-C: whether ONE tool row renders its result BLOCK-WISE (the image path).
|
|
6010
|
+
*
|
|
6011
|
+
* The rule is the single owner of the row-level decision, so the mapper and
|
|
6012
|
+
* the renderer's read path can never disagree about which attachment a row
|
|
6013
|
+
* shows:
|
|
6014
|
+
*
|
|
6015
|
+
* - an `ask_user_question` row keeps its ORIGINAL node structure: the
|
|
6016
|
+
* settled-answer lookup stays the authority of its result, whatever the
|
|
6017
|
+
* row's blocks carry;
|
|
6018
|
+
* - a MERGED read group keeps the flat text result: its `resultBlocks` are
|
|
6019
|
+
* the FIRST member's blocks and never describe the aggregate, so an image
|
|
6020
|
+
* would be attributed to the wrong member. The group's genuine-call
|
|
6021
|
+
* cardinality (`callCount > 1`) is the folder's own aggregation fact — a
|
|
6022
|
+
* single ordinary `read` is never blocked by it;
|
|
6023
|
+
* - every other row projects its images only when its result really carries
|
|
6024
|
+
* an image block.
|
|
6025
|
+
*/
|
|
6026
|
+
function toolRowProjectsImages(message) {
|
|
6027
|
+
if (message.name === "ask_user_question") return false;
|
|
6028
|
+
if ((message.callCount ?? 1) > 1) return false;
|
|
6029
|
+
const blocks = message.resultBlocks;
|
|
6030
|
+
if (blocks === void 0) return false;
|
|
6031
|
+
return blocks.some((block) => block.type === "image");
|
|
6032
|
+
}
|
|
6033
|
+
/**
|
|
6034
|
+
* PR-C: the image blocks ONE tool row projects, in block order. The
|
|
6035
|
+
* eligibility rule is {@link toolRowProjectsImages}; the blocks are returned
|
|
6036
|
+
* with their index so the mapper and the reader agree on the node keys.
|
|
6037
|
+
*/
|
|
6038
|
+
function toolRowImageBlocks(message) {
|
|
6039
|
+
if (!toolRowProjectsImages(message)) return [];
|
|
6040
|
+
const blocks = message.resultBlocks ?? [];
|
|
6041
|
+
const out = [];
|
|
6042
|
+
blocks.forEach((block, index) => {
|
|
6043
|
+
if (block.type === "image") out.push({
|
|
6044
|
+
index,
|
|
6045
|
+
attachment: block.attachment
|
|
6046
|
+
});
|
|
6047
|
+
});
|
|
6048
|
+
return out;
|
|
6049
|
+
}
|
|
6050
|
+
/**
|
|
6051
|
+
* PR-C: the display name of one image attachment: the attachment's own name
|
|
6052
|
+
* when it has one, else `image`. The identity line and the native image's
|
|
6053
|
+
* accessible name are the SAME name — one attachment, one name.
|
|
6054
|
+
*
|
|
6055
|
+
* Exported for the dock's draft projection, so a staged image and a durable
|
|
6056
|
+
* attachment cannot disagree about their display identity.
|
|
6057
|
+
*/
|
|
6058
|
+
function imageDisplayName(ref) {
|
|
6059
|
+
const candidate = ref === null || typeof ref !== "object" ? void 0 : ref;
|
|
6060
|
+
return candidate !== void 0 && typeof candidate.name === "string" && candidate.name !== "" ? candidate.name : "image";
|
|
6061
|
+
}
|
|
6062
|
+
/**
|
|
6063
|
+
* PR-C: the identity segment of one image attachment: the display name (the
|
|
6064
|
+
* attachment's own name, or `image`), its SOURCE pixel size and its SOURCE
|
|
6065
|
+
* byte count. A malformed reference contributes only the parts that are well
|
|
6066
|
+
* formed — the status phrase still says what is wrong.
|
|
6067
|
+
*
|
|
6068
|
+
* Exported (with {@link imageStatusText}) so the dock's draft rows reuse this
|
|
6069
|
+
* ONE identity/status vocabulary instead of formatting a second one.
|
|
6070
|
+
*/
|
|
6071
|
+
function imageIdentityText(ref) {
|
|
6072
|
+
const candidate = ref === null || typeof ref !== "object" ? void 0 : ref;
|
|
6073
|
+
const parts = [imageDisplayName(ref)];
|
|
6074
|
+
if (candidate !== void 0 && typeof candidate.width === "number" && Number.isSafeInteger(candidate.width) && candidate.width > 0 && typeof candidate.height === "number" && Number.isSafeInteger(candidate.height) && candidate.height > 0) parts.push(`${candidate.width}×${candidate.height}`);
|
|
6075
|
+
if (candidate !== void 0 && typeof candidate.bytes === "number" && Number.isSafeInteger(candidate.bytes) && candidate.bytes >= 0) parts.push(formatBytes(candidate.bytes));
|
|
6076
|
+
return `[IMAGE] ${parts.join(" · ")}`;
|
|
6077
|
+
}
|
|
6078
|
+
/** PR-C: the fixed status phrase of one image state (the frozen table). */
|
|
6079
|
+
function imageStatusText(state) {
|
|
6080
|
+
switch (state.state) {
|
|
6081
|
+
case "unsupported": return "Native image display unavailable in this Tern pane";
|
|
6082
|
+
case "no-scope": return "Image unavailable for this session";
|
|
6083
|
+
case "loading": return "Loading image…";
|
|
6084
|
+
case "error": return "Image read failed";
|
|
6085
|
+
case "too-large": return "Image exceeds 16 MiB Blob limit";
|
|
6086
|
+
case "ready": return;
|
|
6087
|
+
}
|
|
6088
|
+
}
|
|
6089
|
+
/**
|
|
6090
|
+
* PR-C: the nodes of ONE image block: the identity line and — when the pane
|
|
6091
|
+
* supports a native image and the read produced bytes — the native image
|
|
6092
|
+
* node. The identity line is ALWAYS drawn: it is the only place the reader
|
|
6093
|
+
* learns WHICH attachment the row carries and what happened to it.
|
|
6094
|
+
*
|
|
6095
|
+
* The image node's key is the SAME for the pending and the ready state, so
|
|
6096
|
+
* the pane replaces the placeholder in place instead of adding a second row.
|
|
6097
|
+
* `keyPrefix` is the row's OWN block namespace (`result-b` for a tool card
|
|
6098
|
+
* body, `body-b` for a User/Assistant message body): two rows under the same
|
|
6099
|
+
* parent card must never share a block key.
|
|
6100
|
+
*/
|
|
6101
|
+
function imageBlockNodes(block, state, keyPrefix) {
|
|
6102
|
+
const problem = imageRefProblem(block.attachment);
|
|
6103
|
+
const identity = imageIdentityText(block.attachment);
|
|
6104
|
+
if (problem !== void 0) {
|
|
6105
|
+
const phrase = problem === "invalid" ? "Invalid image attachment" : "Unsupported image format";
|
|
6106
|
+
return [ui.text({
|
|
6107
|
+
key: `${keyPrefix}${block.index}-info`,
|
|
6108
|
+
text: sanitizeDisplayText(`${identity} · ${phrase}`)
|
|
6109
|
+
})];
|
|
6110
|
+
}
|
|
6111
|
+
const alt = sanitizeDisplayText(imageDisplayName(block.attachment));
|
|
6112
|
+
const status = state === void 0 ? "Native image display unavailable in this Tern pane" : imageStatusText(state);
|
|
6113
|
+
const info = status === void 0 ? identity : `${identity} · ${status}`;
|
|
6114
|
+
const nodes = [ui.text({
|
|
6115
|
+
key: `${keyPrefix}${block.index}-info`,
|
|
6116
|
+
text: sanitizeDisplayText(info)
|
|
6117
|
+
})];
|
|
6118
|
+
if (state === void 0 || state.state === "unsupported" || state.state === "no-scope") return nodes;
|
|
6119
|
+
const blob = state.state === "ready" ? state.blobId : PENDING_IMAGE_BLOB_ID;
|
|
6120
|
+
nodes.push(ui.image({
|
|
6121
|
+
key: `${keyPrefix}${block.index}-image`,
|
|
6122
|
+
blob,
|
|
6123
|
+
alt
|
|
6124
|
+
}));
|
|
6125
|
+
return nodes;
|
|
6126
|
+
}
|
|
6127
|
+
/**
|
|
6128
|
+
* The frozen per-preview node bounds (Owner amendendment, 2026-10-25): OMP's
|
|
6129
|
+
* `12ch × 4lines` cap on the native image node. This is a RESPONSIVE CEILING,
|
|
6130
|
+
* not a fixed pixel size — the image keeps its own aspect ratio inside it, and
|
|
6131
|
+
* it is the reason a split pane stays compact even where the window media query
|
|
6132
|
+
* cannot fire.
|
|
6133
|
+
*/
|
|
6134
|
+
const DOCK_DRAFT_PREVIEW_MAX = {
|
|
6135
|
+
w: "12ch",
|
|
6136
|
+
h: "4lines"
|
|
6137
|
+
};
|
|
6138
|
+
/** The stylesheet role the ONE preview row carries (the sheet's selector). */
|
|
6139
|
+
const DOCK_DRAFT_PREVIEW_ROLE = "dsh.draft-preview";
|
|
6140
|
+
/**
|
|
6141
|
+
* PR4: the dock's draft-preview band — a PURE projection of already-prepared
|
|
6142
|
+
* state, exactly like the transcript image nodes.
|
|
6143
|
+
*
|
|
6144
|
+
* The shape is fixed by the product contract: ONE `ui.row` holding up to
|
|
6145
|
+
* `previewLimit` chips side by side, each chip being its native image plus one
|
|
6146
|
+
* compact `#id · W×H` caption. There is deliberately no extra title line and no
|
|
6147
|
+
* per-image identity line outside the chip, because every extra row competes
|
|
6148
|
+
* with the controlled editor for the dock's height.
|
|
6149
|
+
*
|
|
6150
|
+
* The caller prepares the blob/read state and decides `previewLimit` from the
|
|
6151
|
+
* negotiated capabilities alone; this function never reads bytes, never calls
|
|
6152
|
+
* the SDK and never consults a store. It returns `undefined` when nothing may
|
|
6153
|
+
* be drawn, so a caller cannot wrap the result in a second preview container.
|
|
6154
|
+
*/
|
|
6155
|
+
function dockDraftImageNodes(entries, previewLimit) {
|
|
6156
|
+
if (entries.length === 0 || previewLimit <= 0) return void 0;
|
|
6157
|
+
const shown = entries.slice(0, previewLimit);
|
|
6158
|
+
const chips = [];
|
|
6159
|
+
for (const entry of shown) {
|
|
6160
|
+
const children = [];
|
|
6161
|
+
const state = entry.state;
|
|
6162
|
+
if (state?.state === "ready") children.push(ui.image({
|
|
6163
|
+
key: "image",
|
|
6164
|
+
blob: state.blobId,
|
|
6165
|
+
alt: sanitizeDisplayText(entry.name),
|
|
6166
|
+
max: DOCK_DRAFT_PREVIEW_MAX
|
|
6167
|
+
}));
|
|
6168
|
+
else children.push(ui.text({
|
|
6169
|
+
key: "unavailable",
|
|
6170
|
+
text: "Preview unavailable",
|
|
6171
|
+
wrap: "none",
|
|
6172
|
+
max: { w: DOCK_DRAFT_PREVIEW_MAX.w }
|
|
6173
|
+
}));
|
|
6174
|
+
children.push(ui.text({
|
|
6175
|
+
key: "caption",
|
|
6176
|
+
text: sanitizeDisplayText(entry.caption),
|
|
6177
|
+
wrap: "none",
|
|
6178
|
+
max: { w: DOCK_DRAFT_PREVIEW_MAX.w }
|
|
6179
|
+
}));
|
|
6180
|
+
chips.push(ui.col({
|
|
6181
|
+
key: `draft-chip-${entry.id}-${entry.ordinal}`,
|
|
6182
|
+
gap: "none"
|
|
6183
|
+
}, ...children));
|
|
6184
|
+
}
|
|
6185
|
+
return ui.row({
|
|
6186
|
+
key: "draft-preview",
|
|
6187
|
+
role: DOCK_DRAFT_PREVIEW_ROLE,
|
|
6188
|
+
wrap: false,
|
|
6189
|
+
gap: "sm"
|
|
6190
|
+
}, ...chips);
|
|
6191
|
+
}
|
|
6192
|
+
/**
|
|
6193
|
+
* PR4: a bounded, PAYLOAD-FREE type tag for one block the TSP mapper does not
|
|
6194
|
+
* present. The durable block object never reaches the terminal — no serialized
|
|
6195
|
+
* JSON, no bytes, no path — only its type name does, so an unknown future
|
|
6196
|
+
* block stays visible as a fact instead of being silently dropped.
|
|
6197
|
+
*/
|
|
6198
|
+
function typedBlockText(label, type) {
|
|
6199
|
+
const raw = typeof type === "string" ? sanitizeDisplayText(type).replace(/[\t\r\n]+/g, " ").trim() : "";
|
|
6200
|
+
return `${label} · ${raw === "" ? "unknown" : raw.length <= 60 ? raw : `${raw.slice(0, 59)}…`}`;
|
|
6201
|
+
}
|
|
6202
|
+
/**
|
|
6203
|
+
* PR4: the block-wise body of ONE User/Assistant message: every non-empty
|
|
6204
|
+
* text block stays its own `ui.md`, every image block becomes its identity
|
|
6205
|
+
* line plus the native image node, and every block type the mapper does not
|
|
6206
|
+
* present degrades to its payload-free type tag.
|
|
6207
|
+
*
|
|
6208
|
+
* The image state is looked up in the SAME {@link TranscriptViewOptions.imageStates}
|
|
6209
|
+
* map the Tool path consumes: all three roles present durable attachments of
|
|
6210
|
+
* the one display subject, so a per-role state would be a second truth.
|
|
6211
|
+
*/
|
|
6212
|
+
function bodyBlockNodes(block, index, options) {
|
|
6213
|
+
if (block.type === "text") {
|
|
6214
|
+
if (block.text === "") return [];
|
|
6215
|
+
return [ui.md({
|
|
6216
|
+
key: `body-b${index}-text`,
|
|
6217
|
+
text: sanitizeDisplayText(block.text)
|
|
6218
|
+
})];
|
|
6219
|
+
}
|
|
6220
|
+
if (block.type === "image") {
|
|
6221
|
+
const state = isPresentableImageRef(block.attachment) ? options.imageStates?.get(block.attachment.attachmentId) : void 0;
|
|
6222
|
+
return imageBlockNodes({
|
|
6223
|
+
index,
|
|
6224
|
+
attachment: block.attachment
|
|
6225
|
+
}, state, "body-b");
|
|
6226
|
+
}
|
|
6227
|
+
return [ui.text({
|
|
6228
|
+
key: `body-b${index}-block`,
|
|
6229
|
+
text: sanitizeDisplayText(typedBlockText("Unknown block", block.type))
|
|
6230
|
+
})];
|
|
6231
|
+
}
|
|
6232
|
+
/**
|
|
6233
|
+
* PR4: the ordered body of one User/Assistant message whose content really
|
|
6234
|
+
* carries non-text blocks. The flat `message.text` is NOT drawn beside it —
|
|
6235
|
+
* the blocks are the authority and joining them would duplicate the body.
|
|
6236
|
+
*/
|
|
6237
|
+
function bodyContentNodes(blocks, options) {
|
|
6238
|
+
return blocks.flatMap((block, index) => bodyBlockNodes(block, index, options));
|
|
6239
|
+
}
|
|
6240
|
+
/**
|
|
6241
|
+
* PR4: the ordered body of one Assistant message that carries
|
|
6242
|
+
* `displayBlocks` — the presentation-only evidence of an OPEN opaque block.
|
|
6243
|
+
* A `content` member renders exactly like the settled body; an `open-opaque`
|
|
6244
|
+
* member states its type and that it is still pending, and NEVER fabricates a
|
|
6245
|
+
* blob or an image node. The two lists are never mixed: the caller chooses
|
|
6246
|
+
* one authority, so no image can be drawn twice.
|
|
6247
|
+
*/
|
|
6248
|
+
function assistantDisplayNodes(blocks, options) {
|
|
6249
|
+
return blocks.flatMap((displayBlock, index) => displayBlock.kind === "open-opaque" ? [ui.text({
|
|
6250
|
+
key: `body-b${index}-block`,
|
|
6251
|
+
text: sanitizeDisplayText(`${typedBlockText("Open block", displayBlock.blockType)} · pending`)
|
|
6252
|
+
})] : bodyBlockNodes(displayBlock.block, index, options));
|
|
6253
|
+
}
|
|
6254
|
+
/** Whether one chosen block list must render block-wise: it carries at least
|
|
6255
|
+
* one image the reader has to see. A list without an image keeps the legacy
|
|
6256
|
+
* single flat body and its stable `body` key. */
|
|
6257
|
+
function bodyHasImage(blocks) {
|
|
6258
|
+
return blocks.some((block) => block.type === "image");
|
|
6259
|
+
}
|
|
6260
|
+
/**
|
|
6261
|
+
* PR-C: the block-wise result of one tool row: every non-empty text block
|
|
6262
|
+
* stays a `ui.code`, every image block becomes its identity line plus the
|
|
6263
|
+
* native image node. The flat result is NOT drawn again — it would
|
|
6264
|
+
* duplicate the text blocks.
|
|
6265
|
+
*/
|
|
6266
|
+
function imageResultNodes(blocks, options, wrap) {
|
|
6267
|
+
const nodes = [];
|
|
6268
|
+
blocks.forEach((block, index) => {
|
|
6269
|
+
if (block.type === "text") {
|
|
6270
|
+
if (block.text === "") return;
|
|
6271
|
+
nodes.push(ui.code({
|
|
6272
|
+
key: `result-b${index}-text`,
|
|
6273
|
+
text: sanitizeDisplayText(block.text),
|
|
6274
|
+
...wrap ? { wrap: true } : {}
|
|
6275
|
+
}));
|
|
6276
|
+
return;
|
|
6277
|
+
}
|
|
6278
|
+
if (block.type !== "image") return;
|
|
6279
|
+
const projected = {
|
|
6280
|
+
index,
|
|
6281
|
+
attachment: block.attachment
|
|
6282
|
+
};
|
|
6283
|
+
const state = isPresentableImageRef(block.attachment) ? options.imageStates?.get(block.attachment.attachmentId) : void 0;
|
|
6284
|
+
nodes.push(...imageBlockNodes(projected, state, "result-b"));
|
|
6285
|
+
});
|
|
6286
|
+
return nodes;
|
|
6287
|
+
}
|
|
6288
|
+
/**
|
|
6289
|
+
* PR-D: the chart row's result segment. The FINAL durable content is the
|
|
6290
|
+
* admission source: a valid chart machine line draws as a native chart only
|
|
6291
|
+
* when the pane negotiated the `chart` kind, and the exact values stay a
|
|
6292
|
+
* `ui.code` row in every renderer. A malformed/missing line falls back to the
|
|
6293
|
+
* human blocks (the machine line is never displayed).
|
|
6294
|
+
*/
|
|
6295
|
+
function chartResultNodes(message, options, wrap, flatText) {
|
|
6296
|
+
const base = message.resultBlocks === void 0 ? visualPartsFromText(flatText) : visualParts(message.resultBlocks);
|
|
6297
|
+
const parts = message.status === "ok" ? base : {
|
|
6298
|
+
...base,
|
|
6299
|
+
fact: void 0
|
|
6300
|
+
};
|
|
6301
|
+
const fact = parts.fact?.type === "chart" ? parts.fact : void 0;
|
|
6302
|
+
if (fact === void 0) {
|
|
6303
|
+
const text = parts.humanText === "" ? base.humanText === "" ? flatText : base.humanText : parts.humanText;
|
|
6304
|
+
return text === "" ? [] : [ui.code({
|
|
6305
|
+
key: "result",
|
|
6306
|
+
text: sanitizeDisplayText(text),
|
|
6307
|
+
...wrap ? { wrap: true } : {}
|
|
6308
|
+
})];
|
|
6309
|
+
}
|
|
6310
|
+
const nodes = [];
|
|
6311
|
+
if (options.chartKindsSupported === true) {
|
|
6312
|
+
const projection = chartProjection(fact);
|
|
6313
|
+
nodes.push(ui.chart({
|
|
6314
|
+
key: "result-chart",
|
|
6315
|
+
kind: projection.kind,
|
|
6316
|
+
summary: sanitizeDisplayText(projection.summary),
|
|
6317
|
+
series: projection.series
|
|
6318
|
+
}));
|
|
6319
|
+
nodes.push(ui.code({
|
|
6320
|
+
key: "result",
|
|
6321
|
+
text: sanitizeDisplayText(chartValueRows(fact).join("\n")),
|
|
6322
|
+
...wrap ? { wrap: true } : {}
|
|
6323
|
+
}));
|
|
6324
|
+
} else nodes.push(ui.code({
|
|
6325
|
+
key: "result",
|
|
6326
|
+
text: sanitizeDisplayText(chartHumanText(fact)),
|
|
6327
|
+
...wrap ? { wrap: true } : {}
|
|
6328
|
+
}));
|
|
6329
|
+
return nodes;
|
|
6330
|
+
}
|
|
6331
|
+
/**
|
|
6332
|
+
* PR-D: the SVG row's result segment. The readable description is ALWAYS
|
|
6333
|
+
* drawn; the native image node appears only for a prepared `ready` state
|
|
6334
|
+
* (credential matches the durable call args, admission accepted, `image` +
|
|
6335
|
+
* `blobs` negotiated). The SVG source itself is the card's args row.
|
|
6336
|
+
*/
|
|
6337
|
+
function svgResultNodes(message, options, wrap, flatText, collapsed) {
|
|
6338
|
+
const base = message.resultBlocks === void 0 ? visualPartsFromText(flatText) : visualParts(message.resultBlocks);
|
|
6339
|
+
const parts = message.status === "ok" ? base : {
|
|
6340
|
+
...base,
|
|
6341
|
+
fact: void 0
|
|
6342
|
+
};
|
|
6343
|
+
const fact = parts.fact?.type === "svg" ? parts.fact : void 0;
|
|
6344
|
+
const detail = fact === void 0 ? parts.humanText === "" ? base.humanText === "" ? flatText : base.humanText : parts.humanText : svgDetailRows(fact).join("\n");
|
|
6345
|
+
const nodes = detail === "" ? [] : [ui.code({
|
|
6346
|
+
key: "result",
|
|
6347
|
+
text: sanitizeDisplayText(detail),
|
|
6348
|
+
...wrap ? { wrap: true } : {}
|
|
6349
|
+
})];
|
|
6350
|
+
const state = message.status === "ok" ? options.toolSvgStates?.get(message) : void 0;
|
|
6351
|
+
if (state?.state === "ready" && !collapsed) {
|
|
6352
|
+
const blobId = state.blobId ?? state.request();
|
|
6353
|
+
if (blobId !== void 0) nodes.push(ui.image({
|
|
6354
|
+
key: "result-svg",
|
|
6355
|
+
blob: blobId,
|
|
6356
|
+
alt: sanitizedPhysicalLine(state.fact.title)
|
|
6357
|
+
}));
|
|
6358
|
+
else nodes.push(ui.text({
|
|
6359
|
+
key: "result-svg-status",
|
|
6360
|
+
text: "Native SVG display unavailable in this Tern pane"
|
|
6361
|
+
}));
|
|
6362
|
+
} else if (state?.state === "unsupported") nodes.push(ui.text({
|
|
6363
|
+
key: "result-svg-status",
|
|
6364
|
+
text: "Native SVG display unavailable in this Tern pane"
|
|
6365
|
+
}));
|
|
6366
|
+
else if (state?.state === "invalid") nodes.push(ui.text({
|
|
6367
|
+
key: "result-svg-status",
|
|
6368
|
+
text: sanitizeDisplayText(`Drawing unavailable — ${state.reason}`)
|
|
6369
|
+
}));
|
|
6370
|
+
return nodes;
|
|
6371
|
+
}
|
|
6372
|
+
/**
|
|
6373
|
+
* The publication tool's result segment: its human summary as one `ui.code`
|
|
6374
|
+
* row. The `visual-published-v1:` receipt is a durable machine block that no
|
|
6375
|
+
* human-facing surface displays, so the SAME source-aware projection the PiTui
|
|
6376
|
+
* cards use strips it here; a failure keeps its own readable reason.
|
|
6377
|
+
*/
|
|
6378
|
+
function presentVisualResultNodes(message, wrap, flatText) {
|
|
6379
|
+
const human = humanFacingVisualResult({
|
|
6380
|
+
toolName: PRESENT_VISUAL_TOOL_NAME,
|
|
6381
|
+
blocks: message.resultBlocks,
|
|
6382
|
+
text: flatText
|
|
6383
|
+
});
|
|
6384
|
+
return human.text === "" ? [] : [ui.code({
|
|
6385
|
+
key: "result",
|
|
6386
|
+
text: sanitizeDisplayText(human.text),
|
|
6387
|
+
...wrap ? { wrap: true } : {}
|
|
6388
|
+
})];
|
|
6389
|
+
}
|
|
6390
|
+
/**
|
|
6391
|
+
* PR-C: the result segment of one tool row.
|
|
6392
|
+
*
|
|
6393
|
+
* A row WITHOUT an image block keeps its EXACT previous shape: ONE `ui.code`
|
|
6394
|
+
* with the flat shown result. A row WITH an image block renders block-wise,
|
|
6395
|
+
* in block order, so the text and the image interleave exactly as the tool
|
|
6396
|
+
* produced them.
|
|
6397
|
+
* @param message - the tool row (top level or PTC child).
|
|
6398
|
+
* @param options - the mapper inputs.
|
|
6399
|
+
* @param wrap - whether the parent wraps its body.
|
|
6400
|
+
* @param flatText - the flat result text (the settled-answer authority for a
|
|
6401
|
+
* top-level `ask_user_question` row, the child's own result for a child).
|
|
6402
|
+
*/
|
|
6403
|
+
function toolResultNodes(message, options, wrap, flatText, collapsed = false) {
|
|
6404
|
+
if (message.name === "dsh_pi_tui_chart") return chartResultNodes(message, options, wrap, flatText);
|
|
6405
|
+
if (message.name === "dsh_pi_tui_svg") return svgResultNodes(message, options, wrap, flatText, collapsed);
|
|
6406
|
+
if (message.name === "present_visual") return presentVisualResultNodes(message, wrap, flatText);
|
|
6407
|
+
if (toolRowProjectsImages(message)) return imageResultNodes(message.resultBlocks ?? [], options, wrap);
|
|
6408
|
+
if (flatText === "") return [];
|
|
6409
|
+
return [ui.code({
|
|
6410
|
+
key: "result",
|
|
6411
|
+
text: sanitizeDisplayText(flatText),
|
|
6412
|
+
...wrap ? { wrap: true } : {}
|
|
6413
|
+
})];
|
|
6414
|
+
}
|
|
6415
|
+
function toolBodyParts(message, options, wrap = false, collapsed = false) {
|
|
6416
|
+
const args = [];
|
|
6417
|
+
if (message.args !== "") args.push(ui.code({
|
|
6418
|
+
key: "args",
|
|
6419
|
+
text: sanitizeDisplayText(message.args),
|
|
6420
|
+
...wrap ? { wrap: true } : {}
|
|
6421
|
+
}));
|
|
6422
|
+
return {
|
|
6423
|
+
args,
|
|
6424
|
+
result: toolResultNodes(message, options, wrap, shownToolResult(message, options), collapsed)
|
|
6425
|
+
};
|
|
6426
|
+
}
|
|
6427
|
+
/**
|
|
6428
|
+
* The result body of one tool row. PR3-B B3 (§3.9): an `ask_user_question`
|
|
6429
|
+
* row carrying an official `callId` shows the AUTHORITATIVE settled answer
|
|
6430
|
+
* batch when the projection has one. An ABSENT settled entry falls back to the
|
|
6431
|
+
* call's own recorded result; an EMPTY batch is a real settled outcome (a late
|
|
6432
|
+
* reply settled the question without a readable batch) and must NOT fall back
|
|
6433
|
+
* to the timeout payload it replaced.
|
|
6434
|
+
*/
|
|
6435
|
+
function shownToolResult(message, options) {
|
|
6436
|
+
if (message.name !== "ask_user_question" || message.callId === void 0) return message.result;
|
|
6437
|
+
const settled = options.settledQuestionAnswersLookup?.(message.callId);
|
|
6438
|
+
return settled === void 0 ? message.result : JSON.stringify({ answers: settled });
|
|
6439
|
+
}
|
|
6440
|
+
/**
|
|
6441
|
+
* PR-B2: one native INLINE tool node for one PTC sub-call. Identity is the
|
|
6442
|
+
* child's own durable `subCallId` (never its name, its array position or the
|
|
6443
|
+
* parent's revision); header, target and status come from the same authorities
|
|
6444
|
+
* as the top-level row (`toolCardHeader`, `subCallDisplayStatus`). The body is
|
|
6445
|
+
* the complete child output, wrapped; a child with no header summary shows its
|
|
6446
|
+
* raw args instead of a headless empty card.
|
|
6447
|
+
*/
|
|
6448
|
+
function childToolNode(child, options, parentDisclosure) {
|
|
6449
|
+
const header = toolCardHeader(child.name, child.args, options.cwd);
|
|
6450
|
+
const body = [];
|
|
6451
|
+
if (header.summary === "" && child.args !== "") body.push(ui.code({
|
|
6452
|
+
key: "args",
|
|
6453
|
+
text: sanitizeDisplayText(child.args),
|
|
6454
|
+
wrap: true
|
|
6455
|
+
}));
|
|
6456
|
+
const childKey = `sub-${child.subCallId}`;
|
|
6457
|
+
const childDisclosure = `${parentDisclosure}/${childKey}`;
|
|
6458
|
+
const svgState = child.name === "dsh_pi_tui_svg" && child.status === "ok" ? options.toolSvgStates?.get(child) : void 0;
|
|
6459
|
+
const collapsible = child.name === "dsh_pi_tui_svg" && svgState?.state === "ready";
|
|
6460
|
+
const collapsed = collapsible && options.expandedToolKeys !== void 0 && !options.expandedToolKeys.has(childDisclosure);
|
|
6461
|
+
if (svgState?.state === "ready" || svgState?.state === "unsupported") body.push(ui.code({
|
|
6462
|
+
key: "source",
|
|
6463
|
+
text: sanitizeDisplayText(svgState.source),
|
|
6464
|
+
wrap: true
|
|
6465
|
+
}));
|
|
6466
|
+
body.push(...toolChildNodes(child, options, childDisclosure));
|
|
6467
|
+
body.push(...toolResultNodes(child, options, true, child.result, collapsed));
|
|
6468
|
+
return ui.tool({
|
|
6469
|
+
key: childKey,
|
|
6470
|
+
frame: "inline",
|
|
6471
|
+
name: sanitizedPhysicalLine(child.name),
|
|
6472
|
+
title: sanitizedPhysicalLine(header.title),
|
|
6473
|
+
status: toolStatus(subCallDisplayStatus(child)),
|
|
6474
|
+
...collapsible ? {
|
|
6475
|
+
collapsible: true,
|
|
6476
|
+
collapsed
|
|
6477
|
+
} : {},
|
|
6478
|
+
...header.summary === "" ? {} : {
|
|
6479
|
+
target: sanitizedPhysicalLine(header.summary),
|
|
6480
|
+
targetKind: "text"
|
|
6481
|
+
}
|
|
6482
|
+
}, ...body);
|
|
6483
|
+
}
|
|
6484
|
+
/**
|
|
6485
|
+
* The ordered nested-call block of one tool card: the direct-child count head,
|
|
6486
|
+
* then each child's own native inline tool in durable dispatch order. The
|
|
6487
|
+
* count is the DIRECT children of this card; a child with grandchildren runs
|
|
6488
|
+
* this same rule one level down (never a Work-level lookup).
|
|
6489
|
+
*/
|
|
6490
|
+
function toolChildNodes(parent, options, parentDisclosure) {
|
|
6491
|
+
const subCalls = parent.subCalls;
|
|
6492
|
+
if (subCalls === void 0 || subCalls.length === 0) return [];
|
|
6493
|
+
return [ui.text({
|
|
6494
|
+
key: "child-head",
|
|
6495
|
+
text: `Child calls · ${subCalls.length}`
|
|
6496
|
+
}), ...subCalls.map((child) => childToolNode(child, options, parentDisclosure))];
|
|
6497
|
+
}
|
|
6498
|
+
function toolNode(message, key, options) {
|
|
6499
|
+
const header = toolCardHeader(message.name, message.args, options.cwd);
|
|
6500
|
+
const hasChildren = (message.subCalls?.length ?? 0) > 0;
|
|
6501
|
+
const svgState = message.name === "dsh_pi_tui_svg" && message.status === "ok" ? options.toolSvgStates?.get(message) : void 0;
|
|
6502
|
+
const collapsible = message.name === "dsh_pi_tui_svg" && svgState?.state === "ready";
|
|
6503
|
+
const disclosure = options.scopePrefix !== void 0 && key.startsWith(options.scopePrefix) ? key.slice(options.scopePrefix.length) : key;
|
|
6504
|
+
const collapsed = collapsible && options.expandedToolKeys !== void 0 && !options.expandedToolKeys.has(disclosure);
|
|
6505
|
+
const body = toolBodyParts(message, options, hasChildren, collapsed);
|
|
6506
|
+
if (isUnmatchedToolRow(message)) {
|
|
6507
|
+
const provenance = message.origin === "tool-not-started" ? "not started" : "unmatched result";
|
|
6508
|
+
return ui.card({
|
|
6509
|
+
key,
|
|
6510
|
+
head: sanitizedPhysicalLine(header.title),
|
|
6511
|
+
tone: "warning"
|
|
6512
|
+
}, ui.badge({
|
|
6513
|
+
key: "provenance",
|
|
6514
|
+
text: provenance
|
|
6515
|
+
}), ...body.args, ...body.result);
|
|
6516
|
+
}
|
|
6517
|
+
return ui.tool({
|
|
6518
|
+
key,
|
|
6519
|
+
name: sanitizedPhysicalLine(message.name),
|
|
6520
|
+
title: sanitizedPhysicalLine(header.title),
|
|
6521
|
+
status: toolStatus(message.status),
|
|
6522
|
+
...collapsible ? {
|
|
6523
|
+
collapsible: true,
|
|
6524
|
+
collapsed
|
|
6525
|
+
} : {},
|
|
6526
|
+
...header.summary === "" ? {} : {
|
|
6527
|
+
target: sanitizedPhysicalLine(header.summary),
|
|
6528
|
+
targetKind: toolTargetKind(header.summary, toolTargetFactsOf(options.toolPresenter, message), options.cwd)
|
|
6529
|
+
}
|
|
6530
|
+
}, ...body.args, ...toolChildNodes(message, options, disclosure), ...body.result);
|
|
6531
|
+
}
|
|
6532
|
+
/**
|
|
6533
|
+
* The safe body of one injected Context row through the existing
|
|
6534
|
+
* `systemContextBody` helper (never a raw `<system-reminder>` XML envelope);
|
|
6535
|
+
* a body that is not an envelope at all is shown verbatim.
|
|
6536
|
+
*/
|
|
6537
|
+
function contextBodyNodes(message) {
|
|
6538
|
+
const body = systemContextBody(message.text);
|
|
6539
|
+
if (body === void 0) return [ui.md({
|
|
6540
|
+
key: "body",
|
|
6541
|
+
text: sanitizeDisplayText(message.text)
|
|
6542
|
+
})];
|
|
6543
|
+
if (body.length === 0) return [];
|
|
6544
|
+
return [ui.code({
|
|
6545
|
+
key: "body",
|
|
6546
|
+
text: sanitizeDisplayText(body.join("\n"))
|
|
6547
|
+
})];
|
|
6548
|
+
}
|
|
6549
|
+
function systemNode(message, key) {
|
|
6550
|
+
if (message.context === true) {
|
|
6551
|
+
const kind = contextPresentationKind(message);
|
|
6552
|
+
const head = sanitizedPhysicalLine(message.label ?? contextFormOf(message) ?? "Context");
|
|
6553
|
+
return ui.card({
|
|
6554
|
+
key,
|
|
6555
|
+
head
|
|
6556
|
+
}, ui.badge({
|
|
6557
|
+
key: "kind",
|
|
6558
|
+
text: kind ?? "generic"
|
|
6559
|
+
}), ...contextBodyNodes(message));
|
|
6560
|
+
}
|
|
6561
|
+
return ui.card({
|
|
6562
|
+
key,
|
|
6563
|
+
head: message.origin ?? "System"
|
|
6564
|
+
}, ui.md({
|
|
6565
|
+
key: "body",
|
|
6566
|
+
text: sanitizeDisplayText(message.text)
|
|
6567
|
+
}));
|
|
6568
|
+
}
|
|
6569
|
+
function commandNode(message, key) {
|
|
6570
|
+
const name = message.name ?? "command";
|
|
6571
|
+
const head = sanitizedPhysicalLine(message.args === null || message.args === "" ? `/${name}` : `/${name} ${message.args}`);
|
|
6572
|
+
const outcome = message.outcome;
|
|
6573
|
+
const status = outcome === null ? "running" : outcome.kind === "error" ? "error" : "done";
|
|
6574
|
+
const body = outcome?.text === void 0 || outcome.text === "" ? [] : [ui.md({
|
|
6575
|
+
key: "body",
|
|
6576
|
+
text: sanitizeDisplayText(outcome.text)
|
|
6577
|
+
})];
|
|
6578
|
+
return ui.card({
|
|
6579
|
+
key,
|
|
6580
|
+
head,
|
|
6581
|
+
status
|
|
6582
|
+
}, ...body);
|
|
6583
|
+
}
|
|
6584
|
+
function compactionNode(message, key) {
|
|
6585
|
+
const status = message.error !== void 0 && message.error !== "" ? "error" : message.running === true ? "running" : "done";
|
|
6586
|
+
const body = message.text === "" ? [] : [ui.md({
|
|
6587
|
+
key: "body",
|
|
6588
|
+
text: sanitizeDisplayText(message.text)
|
|
6589
|
+
})];
|
|
6590
|
+
return ui.card({
|
|
6591
|
+
key,
|
|
6592
|
+
head: "Compaction",
|
|
6593
|
+
status
|
|
6594
|
+
}, ui.badge({
|
|
6595
|
+
key: "counts",
|
|
6596
|
+
text: `${message.items} items · ${message.tokens} tokens`
|
|
6597
|
+
}), ...body);
|
|
6598
|
+
}
|
|
6599
|
+
function workflowNode(message, key) {
|
|
6600
|
+
return ui.card({
|
|
6601
|
+
key,
|
|
6602
|
+
head: sanitizedPhysicalLine(message.name)
|
|
6603
|
+
}, ui.badge({
|
|
6604
|
+
key: "state",
|
|
6605
|
+
text: message.status
|
|
6606
|
+
}), ui.badge({
|
|
6607
|
+
key: "members",
|
|
6608
|
+
text: `${message.members.length} members`
|
|
6609
|
+
}));
|
|
4941
6610
|
}
|
|
4942
6611
|
/** One native node for one non-structural transcript row. */
|
|
4943
6612
|
function messageNode(message, key, options) {
|
|
4944
6613
|
switch (message.kind) {
|
|
4945
|
-
case "user":
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
6614
|
+
case "user":
|
|
6615
|
+
if (message.content !== void 0 && bodyHasImage(message.content)) return ui.card({
|
|
6616
|
+
key,
|
|
6617
|
+
head: "You"
|
|
6618
|
+
}, ...bodyContentNodes(message.content, options));
|
|
6619
|
+
return ui.card({
|
|
6620
|
+
key,
|
|
6621
|
+
head: "You"
|
|
6622
|
+
}, ui.md({
|
|
6623
|
+
key: "body",
|
|
6624
|
+
text: sanitizeDisplayText(message.text)
|
|
6625
|
+
}));
|
|
6626
|
+
case "assistant": {
|
|
6627
|
+
const display = message.displayBlocks;
|
|
6628
|
+
if (display !== void 0) return ui.card({
|
|
6629
|
+
key,
|
|
6630
|
+
head: "Assistant"
|
|
6631
|
+
}, ...assistantDisplayNodes(display, options));
|
|
6632
|
+
const presentation = assistantVisualPresentation(message);
|
|
6633
|
+
if (presentation !== void 0 && presentation.publications.length > 0) return ui.card({
|
|
6634
|
+
key,
|
|
6635
|
+
head: "Assistant"
|
|
6636
|
+
}, ...assistantPublishedVisualNodes({
|
|
6637
|
+
text: message.text,
|
|
6638
|
+
...message.content === void 0 ? {} : { content: message.content }
|
|
6639
|
+
}, presentation.publications, {
|
|
6640
|
+
chartKindsSupported: options.chartKindsSupported === true,
|
|
6641
|
+
nativeImagesSupported: options.nativeImagesSupported === true,
|
|
6642
|
+
...options.selectedVisual === void 0 ? {} : { selected: options.selectedVisual },
|
|
6643
|
+
...options.requestPublishedSvgBlob === void 0 ? {} : { requestPublishedSvgBlob: options.requestPublishedSvgBlob },
|
|
6644
|
+
nonText: (block, blockIndex) => block.type === "text" || block.type === "reasoning" || block.type === "tool-call" ? void 0 : bodyBlockNodes(block, blockIndex, options)
|
|
6645
|
+
}));
|
|
6646
|
+
if (message.content !== void 0 && bodyHasImage(message.content)) return ui.card({
|
|
6647
|
+
key,
|
|
6648
|
+
head: "Assistant"
|
|
6649
|
+
}, ...bodyContentNodes(message.content, options));
|
|
6650
|
+
return ui.card({
|
|
6651
|
+
key,
|
|
6652
|
+
head: "Assistant"
|
|
6653
|
+
}, ui.md({
|
|
6654
|
+
key: "body",
|
|
6655
|
+
text: sanitizeDisplayText(message.text)
|
|
6656
|
+
}));
|
|
6657
|
+
}
|
|
4959
6658
|
case "thinking": return ui.card({
|
|
4960
6659
|
key,
|
|
4961
6660
|
head: "Thinking",
|
|
@@ -4979,15 +6678,71 @@ function messageNode(message, key, options) {
|
|
|
4979
6678
|
}));
|
|
4980
6679
|
}
|
|
4981
6680
|
}
|
|
6681
|
+
/**
|
|
6682
|
+
* PR-B3: ONE read-only Preparing row for one live tool call whose arguments
|
|
6683
|
+
* are still streaming. The row is plain TEXT on the native `row` kind: no
|
|
6684
|
+
* badge, no status, no icon, no timer, no action — a Preparing row states
|
|
6685
|
+
* that arguments are arriving, never that a tool is running or done.
|
|
6686
|
+
*
|
|
6687
|
+
* The content is read, never re-derived: the name is the stream's own tool
|
|
6688
|
+
* name (through the shared `toolTitle` table), the summary is the owner's
|
|
6689
|
+
* already-extracted field (sanitized and folded to one line, then
|
|
6690
|
+
* display-relativized against the workspace root) and the byte count is the
|
|
6691
|
+
* owner's exact UTF-8 count through the shared `formatBytes`. The partial
|
|
6692
|
+
* argument prefix and the start time never reach the view.
|
|
6693
|
+
*
|
|
6694
|
+
* The identity is the call's own id when it arrived, and the durable
|
|
6695
|
+
* turn/step/index position before that — never the summary, the name or the
|
|
6696
|
+
* byte count (a byte update must not re-key the row).
|
|
6697
|
+
* @param cwd - the workspace root for the display-only path relativization.
|
|
6698
|
+
* @param keyPrefix - the scope prefix of a STANDALONE row (a row inside a
|
|
6699
|
+
* Work section is already scoped by its section's own id).
|
|
6700
|
+
*/
|
|
6701
|
+
function preparingRow(preview, cwd, keyPrefix) {
|
|
6702
|
+
const key = `preparing-${preview.callId === "" ? `idx-${preview.turn}-${preview.step}-${preview.index}` : preview.callId}`;
|
|
6703
|
+
const name = preview.name ?? "";
|
|
6704
|
+
const title = name === "" ? "Preparing tool…" : `Preparing ${toolTitle(name)}…`;
|
|
6705
|
+
const summary = preview.summary === void 0 ? void 0 : relativizeToCwd(sanitizeDisplayText(preview.summary).replace(/\r\n|\r|\n/g, " "), cwd);
|
|
6706
|
+
return ui.row({
|
|
6707
|
+
key: `${keyPrefix}${key}`,
|
|
6708
|
+
wrap: true
|
|
6709
|
+
}, ui.text({
|
|
6710
|
+
key: "label",
|
|
6711
|
+
text: sanitizeDisplayText(title)
|
|
6712
|
+
}), ...summary === void 0 ? [] : [ui.text({
|
|
6713
|
+
key: "summary",
|
|
6714
|
+
text: ` · ${summary}`
|
|
6715
|
+
})], ui.text({
|
|
6716
|
+
key: "bytes",
|
|
6717
|
+
text: ` · ${formatBytes(preview.argumentBytes)}`
|
|
6718
|
+
}));
|
|
6719
|
+
}
|
|
6720
|
+
/**
|
|
6721
|
+
* PR-B3: the Preparing previews grouped by their durable turn — ascending
|
|
6722
|
+
* turn, and inside a group ascending index. A local, per-call projection: no
|
|
6723
|
+
* long-lived map, no second preview authority and no cached order.
|
|
6724
|
+
*/
|
|
6725
|
+
function groupPreparingPreviews(previews) {
|
|
6726
|
+
const groups = /* @__PURE__ */ new Map();
|
|
6727
|
+
for (const preview of previews) {
|
|
6728
|
+
const group = groups.get(preview.turn);
|
|
6729
|
+
if (group === void 0) groups.set(preview.turn, [preview]);
|
|
6730
|
+
else group.push(preview);
|
|
6731
|
+
}
|
|
6732
|
+
for (const group of groups.values()) group.sort((left, right) => left.index - right.index);
|
|
6733
|
+
return [...groups.entries()].sort((left, right) => left[0] - right[0]);
|
|
6734
|
+
}
|
|
4982
6735
|
/** One native Work container keyed by its canonical span owner. Its ordered
|
|
4983
6736
|
* structural parts place a carried snapshot-only Context cluster as a nested
|
|
4984
|
-
* `clusterNode` card; the flat member sequence is never re-derived here.
|
|
4985
|
-
|
|
6737
|
+
* `clusterNode` card; the flat member sequence is never re-derived here. The
|
|
6738
|
+
* optional Preparing rows are the LAST children of the section: they follow
|
|
6739
|
+
* every durable part of the open run. */
|
|
6740
|
+
function workNode(span, keys, options, prefix, previews = []) {
|
|
4986
6741
|
const head = ["Work", ` · turn ${span.turn}`];
|
|
4987
6742
|
return ui.section({
|
|
4988
6743
|
key: `${prefix}work-${keys.keyFor(span.owner)}`,
|
|
4989
6744
|
head
|
|
4990
|
-
}, ...span.parts.map((part) => part.kind === "message" ? messageNode(part.message, keys.keyFor(part.message), options) : clusterNode(part.cluster, keys, options, prefix)));
|
|
6745
|
+
}, ...span.parts.map((part) => part.kind === "message" ? messageNode(part.message, keys.keyFor(part.message), options) : clusterNode(part.cluster, keys, options, prefix)), ...previews.map((preview) => preparingRow(preview, options.cwd, "")));
|
|
4991
6746
|
}
|
|
4992
6747
|
/** One native Context container keyed by its canonical cluster owner. */
|
|
4993
6748
|
function clusterNode(cluster, keys, options, prefix) {
|
|
@@ -5007,13 +6762,27 @@ function clusterNode(cluster, keys, options, prefix) {
|
|
|
5007
6762
|
*/
|
|
5008
6763
|
function transcriptView(structure, keys, options = {}) {
|
|
5009
6764
|
const prefix = options.scopePrefix ?? "";
|
|
6765
|
+
const groups = groupPreparingPreviews(options.preparingPreviews ?? []);
|
|
6766
|
+
const trailing = structure.length === 0 ? void 0 : structure[structure.length - 1];
|
|
6767
|
+
const openTurn = trailing?.kind === "work" ? trailing.span.turn : void 0;
|
|
6768
|
+
/** The rows the trailing open Work adopts (empty when it adopts none). */
|
|
6769
|
+
let adopted = [];
|
|
6770
|
+
/** The rows that stand alone after the transcript. */
|
|
6771
|
+
const standalone = [];
|
|
6772
|
+
for (const [turn, group] of groups) {
|
|
6773
|
+
if (turn === openTurn) {
|
|
6774
|
+
adopted = group;
|
|
6775
|
+
continue;
|
|
6776
|
+
}
|
|
6777
|
+
for (const preview of group) standalone.push(preparingRow(preview, options.cwd, prefix));
|
|
6778
|
+
}
|
|
5010
6779
|
return ui.col({ key: "transcript" }, ...structure.map((block) => {
|
|
5011
6780
|
switch (block.kind) {
|
|
5012
6781
|
case "message": return messageNode(block.message, `${prefix}${keys.keyFor(block.message)}`, options);
|
|
5013
|
-
case "work": return workNode(block.span, keys, options, prefix);
|
|
6782
|
+
case "work": return workNode(block.span, keys, options, prefix, block === trailing ? adopted : []);
|
|
5014
6783
|
case "context-cluster": return clusterNode(block.cluster, keys, options, prefix);
|
|
5015
6784
|
}
|
|
5016
|
-
}));
|
|
6785
|
+
}), ...standalone);
|
|
5017
6786
|
}
|
|
5018
6787
|
//#endregion
|
|
5019
6788
|
//#region src/tui/tsp/session.ts
|
|
@@ -5066,6 +6835,13 @@ function transcriptView(structure, keys, options = {}) {
|
|
|
5066
6835
|
* gestures are the SDK editor's own affordances.
|
|
5067
6836
|
*/
|
|
5068
6837
|
const DOCK_BANNER = "DSH TSP renderer · experimental composer";
|
|
6838
|
+
/** The exact kinds and feature the Reader's document and keys require. */
|
|
6839
|
+
const WORK_DETAILS_KINDS = [
|
|
6840
|
+
"col",
|
|
6841
|
+
"row",
|
|
6842
|
+
"text"
|
|
6843
|
+
];
|
|
6844
|
+
const WORK_DETAILS_FEATURE = "scroll";
|
|
5069
6845
|
/**
|
|
5070
6846
|
* Probe and connect the TSP renderer. Returns `undefined` when the terminal
|
|
5071
6847
|
* has no TSP (`connect() === null`) — the caller then mounts PiTui exactly as
|
|
@@ -5116,6 +6892,48 @@ function mountTspRenderer(session, options) {
|
|
|
5116
6892
|
mode: "inline",
|
|
5117
6893
|
title: "dsh"
|
|
5118
6894
|
});
|
|
6895
|
+
/**
|
|
6896
|
+
* The dock's draft-preview stylesheet role. The attribute VALUE may contain a
|
|
6897
|
+
* period; the sheet NAME may not (the client rejects a dotted sheet name).
|
|
6898
|
+
*/
|
|
6899
|
+
const DRAFT_PREVIEW_ROLE = "dsh.draft-preview";
|
|
6900
|
+
const DRAFT_PREVIEW_SHEET = "dsh-draft-preview";
|
|
6901
|
+
/**
|
|
6902
|
+
* Whether this pane negotiated the `styles` feature. Without it the frozen
|
|
6903
|
+
* product contract shows NO draft thumbnail at all (summary + composer token
|
|
6904
|
+
* only), so this flag gates the preview row instead of faking a rule.
|
|
6905
|
+
*/
|
|
6906
|
+
const previewStylesSupported = () => session.caps.features.includes("styles");
|
|
6907
|
+
if (previewStylesSupported()) surface.stylesheet(DRAFT_PREVIEW_SHEET, `
|
|
6908
|
+
@media (max-height: 640px) {
|
|
6909
|
+
[data-role="${DRAFT_PREVIEW_ROLE}"] { display: none; }
|
|
6910
|
+
}
|
|
6911
|
+
`);
|
|
6912
|
+
/**
|
|
6913
|
+
* PR3: the ONE scope-local sheet of the Assistant figure Copy control. It is
|
|
6914
|
+
* installed once, only when the pane negotiated `styles`; without the
|
|
6915
|
+
* feature the client's own `html.button` presentation is used unchanged (a
|
|
6916
|
+
* measured visual requirement, not a silent link fallback). The rules use
|
|
6917
|
+
* the client's theme variables so the control follows light/dark, and they
|
|
6918
|
+
* are scoped under the figure role so nothing else is restyled.
|
|
6919
|
+
*/
|
|
6920
|
+
if (session.caps.features.includes("styles")) surface.stylesheet("dsh-visual-copy", `
|
|
6921
|
+
[data-role="${VISUAL_FIGURE_ROLE}"] [data-role="${VISUAL_COPY_ROLE}"] {
|
|
6922
|
+
border: 1px solid var(--accent);
|
|
6923
|
+
background: var(--card);
|
|
6924
|
+
color: var(--t1);
|
|
6925
|
+
padding: 1px 8px;
|
|
6926
|
+
border-radius: 4px;
|
|
6927
|
+
font-family: var(--sans);
|
|
6928
|
+
}
|
|
6929
|
+
[data-role="${VISUAL_FIGURE_ROLE}"] [data-role="${VISUAL_COPY_ROLE}"]:hover {
|
|
6930
|
+
background: var(--raise);
|
|
6931
|
+
}
|
|
6932
|
+
[data-role="${VISUAL_FIGURE_ROLE}"] [data-role="${VISUAL_COPY_ROLE}"]:focus-visible {
|
|
6933
|
+
outline: 1px solid var(--accent);
|
|
6934
|
+
outline-offset: 1px;
|
|
6935
|
+
}
|
|
6936
|
+
`);
|
|
5119
6937
|
let disposed = false;
|
|
5120
6938
|
let exitRequested = false;
|
|
5121
6939
|
/** Monotonic renderer-local identities (notices; scope epochs). */
|
|
@@ -5160,6 +6978,27 @@ function mountTspRenderer(session, options) {
|
|
|
5160
6978
|
let modelPicker;
|
|
5161
6979
|
let presetPicker;
|
|
5162
6980
|
let sessionBrowser;
|
|
6981
|
+
/** B3-A1: the internal native Work Hub presenter (same ONE layer). */
|
|
6982
|
+
let workHub;
|
|
6983
|
+
/**
|
|
6984
|
+
* B3-A2: the ONE temporary `mode:'screen'` Work Details Reader. It is an
|
|
6985
|
+
* ephemeral read-only RENDERING resource of this renderer — not a fifth
|
|
6986
|
+
* Presenter, not a catalog, not a business owner. Exactly one may exist
|
|
6987
|
+
* (open OR closing) at a time.
|
|
6988
|
+
*/
|
|
6989
|
+
let detailsSlot;
|
|
6990
|
+
/** The ONE owned close promise of the retired Reader (teardown awaits it). */
|
|
6991
|
+
let detailsCloseTask;
|
|
6992
|
+
/** Ephemeral per-Reader identity (never a Session generation). */
|
|
6993
|
+
let nextReadingEpoch = 0;
|
|
6994
|
+
/** The synchronous reentrancy boundary of the Screen acquisition. */
|
|
6995
|
+
let openingDetails = false;
|
|
6996
|
+
/**
|
|
6997
|
+
* The shared disposal promise: every `dispose()` call returns THIS promise
|
|
6998
|
+
* while cleanup is pending, so a concurrent caller can never observe a
|
|
6999
|
+
* premature no-op (and the resources are still released exactly once).
|
|
7000
|
+
*/
|
|
7001
|
+
let disposeTask;
|
|
5163
7002
|
const dock = {
|
|
5164
7003
|
statusLine: DOCK_BANNER,
|
|
5165
7004
|
notices: [],
|
|
@@ -5204,8 +7043,11 @@ function mountTspRenderer(session, options) {
|
|
|
5204
7043
|
},
|
|
5205
7044
|
setSettledQuestionAnswersLookup: (lookup) => {
|
|
5206
7045
|
settledQuestionAnswers = lookup;
|
|
5207
|
-
rebuildLastMain();
|
|
7046
|
+
if (!rebuildLastMain()) return;
|
|
5208
7047
|
render();
|
|
7048
|
+
},
|
|
7049
|
+
beforeModalSeat: () => {
|
|
7050
|
+
retireWorkDetails("modal");
|
|
5209
7051
|
}
|
|
5210
7052
|
});
|
|
5211
7053
|
modelPicker = new TspModelPicker({
|
|
@@ -5235,35 +7077,120 @@ function mountTspRenderer(session, options) {
|
|
|
5235
7077
|
scrollSupported: session.caps.features.includes("scroll")
|
|
5236
7078
|
});
|
|
5237
7079
|
modelPicker.resize(session.caps.cols, session.caps.cell.w);
|
|
7080
|
+
workHub = new TspWorkHub({
|
|
7081
|
+
surfaceId: surface.id,
|
|
7082
|
+
render: () => render(),
|
|
7083
|
+
canInteract: () => !disposed && !hydrating && inputBound && !seat.hasModalSeat() && !openingDetails && detailsSlot === void 0 && detailsCloseTask === void 0,
|
|
7084
|
+
paneWidth: () => session.caps.cols * session.caps.cell.w,
|
|
7085
|
+
onViewDetails: (request) => {
|
|
7086
|
+
openWorkDetails(request);
|
|
7087
|
+
},
|
|
7088
|
+
detailsAdmission: () => {
|
|
7089
|
+
if (!readerCapabilityPresent()) return "unsupported";
|
|
7090
|
+
return canPresentWorkDetails() ? "available" : "busy";
|
|
7091
|
+
}
|
|
7092
|
+
});
|
|
5238
7093
|
/**
|
|
5239
|
-
* The ONE
|
|
5240
|
-
*
|
|
7094
|
+
* The ONE seat's FOUR-WAY presenter exclusivity (plan §10.2).
|
|
7095
|
+
*
|
|
7096
|
+
* `presenterOpenGeneration` is the seat's operation witness. A retirement
|
|
7097
|
+
* callback may synchronously open a NEWER presenter while an earlier open is
|
|
7098
|
+
* still retiring its siblings (a Session Browser's `onClose` can open
|
|
7099
|
+
* another panel). The newer lifetime owns the seat, so the earlier open must
|
|
7100
|
+
* come back inert instead of overwriting it. Render priority is NOT a
|
|
7101
|
+
* substitute: a merely hidden sibling keeps its input owner alive.
|
|
7102
|
+
*/
|
|
7103
|
+
let presenterOpenGeneration = 0;
|
|
7104
|
+
/**
|
|
7105
|
+
* Commit one presenter open after retiring the three siblings, or stay inert.
|
|
7106
|
+
*
|
|
7107
|
+
* The sibling sweep is a LIST of retirement steps and the generation is
|
|
7108
|
+
* re-checked BETWEEN them: a retirement callback may synchronously open a
|
|
7109
|
+
* newer presenter, and a stale outer open must then stop sweeping — running
|
|
7110
|
+
* the remaining `retire()` calls would dispose the newer presenter the
|
|
7111
|
+
* callback just opened.
|
|
7112
|
+
*/
|
|
7113
|
+
const openExclusively = (retireSteps, open, inert) => {
|
|
7114
|
+
const generation = ++presenterOpenGeneration;
|
|
7115
|
+
for (const retire of retireSteps) {
|
|
7116
|
+
if (generation !== presenterOpenGeneration) return inert;
|
|
7117
|
+
retire();
|
|
7118
|
+
}
|
|
7119
|
+
if (generation !== presenterOpenGeneration) return inert;
|
|
7120
|
+
return open();
|
|
7121
|
+
};
|
|
7122
|
+
/** The three sibling presenters, in the fixed retirement order. */
|
|
7123
|
+
const siblingRetirements = (...excluded) => {
|
|
7124
|
+
const steps = [];
|
|
7125
|
+
if (!excluded.includes("model")) steps.push(() => modelPicker?.retire());
|
|
7126
|
+
if (!excluded.includes("preset")) steps.push(() => presetPicker?.retire());
|
|
7127
|
+
if (!excluded.includes("browser")) steps.push(() => sessionBrowser?.retire());
|
|
7128
|
+
if (!excluded.includes("hub")) steps.push(() => {
|
|
7129
|
+
retireHubWithDetails("hub-replaced");
|
|
7130
|
+
});
|
|
7131
|
+
return steps;
|
|
7132
|
+
};
|
|
7133
|
+
/**
|
|
7134
|
+
* B3-A2 §8.1: ONE local retirement helper for the Hub seat. The Reader is
|
|
7135
|
+
* revoked SYNCHRONOUSLY first (it physically covers the Hub), then the Hub's
|
|
7136
|
+
* own A1 retirement notifies its owner. It is used by the sibling sweep AND
|
|
7137
|
+
* by every path that replaces the Hub, so a Reader can never outlive the
|
|
7138
|
+
* panel that owns its row identity.
|
|
5241
7139
|
*/
|
|
7140
|
+
const retireHubWithDetails = (reason) => {
|
|
7141
|
+
retireWorkDetails(reason);
|
|
7142
|
+
workHub?.retire();
|
|
7143
|
+
};
|
|
5242
7144
|
const modelPresentation = {
|
|
5243
|
-
open: (request) => {
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
7145
|
+
open: (request) => openExclusively(siblingRetirements("model"), () => modelPicker.presentation.open(request), {
|
|
7146
|
+
setLoading: () => {},
|
|
7147
|
+
setDirectory: () => {},
|
|
7148
|
+
setLoadError: () => {},
|
|
7149
|
+
isDisposed: () => true,
|
|
7150
|
+
close: () => {}
|
|
7151
|
+
}),
|
|
5248
7152
|
notify: (message, kind) => modelPicker.presentation.notify(message, kind)
|
|
5249
7153
|
};
|
|
5250
7154
|
const presetPresentation = {
|
|
5251
|
-
open: (request) => {
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
7155
|
+
open: (request) => openExclusively(siblingRetirements("preset"), () => presetPicker.presentation.open(request), {
|
|
7156
|
+
setLoading: () => {},
|
|
7157
|
+
setRoster: () => {},
|
|
7158
|
+
setLoadError: () => {},
|
|
7159
|
+
isDisposed: () => true,
|
|
7160
|
+
close: () => {}
|
|
7161
|
+
}),
|
|
5256
7162
|
notify: (message, kind) => presetPicker.presentation.notify(message, kind)
|
|
5257
7163
|
};
|
|
5258
7164
|
const sessionBrowserPresentation = {
|
|
5259
|
-
open: (request) => {
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
},
|
|
7165
|
+
open: (request) => openExclusively(siblingRetirements("browser"), () => sessionBrowser.presentation.open(request), {
|
|
7166
|
+
isDisposed: () => true,
|
|
7167
|
+
setSnapshot: () => {},
|
|
7168
|
+
close: () => {}
|
|
7169
|
+
}),
|
|
5264
7170
|
notify: (message, kind) => sessionBrowser.presentation.notify(message, kind)
|
|
5265
7171
|
};
|
|
5266
7172
|
/**
|
|
7173
|
+
* The Task Center presentation sink the surface installs is a SEAT WRAPPER,
|
|
7174
|
+
* not the hub's own port: the Work Hub open retires the three sibling
|
|
7175
|
+
* non-blocking presenters in the SAME synchronous stack. Every other member
|
|
7176
|
+
* is the hub's own passive sink (A1 keeps no second roster/summary/Quick
|
|
7177
|
+
* projection).
|
|
7178
|
+
*/
|
|
7179
|
+
const taskPresentation = {
|
|
7180
|
+
openBrowser: (items, onSelect, onClose, openOptions) => openExclusively([() => {
|
|
7181
|
+
retireWorkDetails("hub-replaced");
|
|
7182
|
+
}, ...siblingRetirements("hub")], () => workHub.taskPresentation.openBrowser(items, onSelect, onClose, openOptions), {
|
|
7183
|
+
close: () => {},
|
|
7184
|
+
setItems: () => {},
|
|
7185
|
+
setRefreshState: () => {}
|
|
7186
|
+
}),
|
|
7187
|
+
setQuickTaskItems: (items) => workHub.taskPresentation.setQuickTaskItems(items),
|
|
7188
|
+
setAgents: (agents) => workHub.taskPresentation.setAgents(agents),
|
|
7189
|
+
setTasks: (jobs) => workHub.taskPresentation.setTasks(jobs),
|
|
7190
|
+
setQuestionAttention: (count) => workHub.taskPresentation.setQuestionAttention(count),
|
|
7191
|
+
setTaskSummary: (summary) => workHub.taskPresentation.setTaskSummary(summary)
|
|
7192
|
+
};
|
|
7193
|
+
/**
|
|
5267
7194
|
* PR3-A supports NO viewer, so this read is the explicit UNSUPPORTED capability
|
|
5268
7195
|
* (the seam's `supportsViewer` is false and `enterView` declines at its real
|
|
5269
7196
|
* admission point). It is deliberately NOT a generation authority: a future
|
|
@@ -5272,28 +7199,345 @@ function mountTspRenderer(session, options) {
|
|
|
5272
7199
|
*/
|
|
5273
7200
|
let viewerGeneration = 0;
|
|
5274
7201
|
/**
|
|
5275
|
-
* PR3-B B3 (§3.9): the authoritative settled-answer lookup installed by the
|
|
5276
|
-
* interaction owner, and the last transcript projection the native nodes were
|
|
5277
|
-
* built from. The lookup is never cached into answers — it is re-read on
|
|
5278
|
-
* every rebuild, so a settled batch reaches the `ask_user_question` row
|
|
5279
|
-
* without a second fold.
|
|
7202
|
+
* PR3-B B3 (§3.9): the authoritative settled-answer lookup installed by the
|
|
7203
|
+
* interaction owner, and the last transcript projection the native nodes were
|
|
7204
|
+
* built from. The lookup is never cached into answers — it is re-read on
|
|
7205
|
+
* every rebuild, so a settled batch reaches the `ask_user_question` row
|
|
7206
|
+
* without a second fold.
|
|
7207
|
+
*/
|
|
7208
|
+
let settledQuestionAnswers;
|
|
7209
|
+
let lastMessages = [];
|
|
7210
|
+
/**
|
|
7211
|
+
* PR-B3: the LAST committed Preparing snapshot — the application owner's
|
|
7212
|
+
* read-only projection of the live tool-call arguments. It is NOT a second
|
|
7213
|
+
* preview authority: the renderer never creates, filters, re-sorts or times
|
|
7214
|
+
* a preview, and it never decides when a Preparing row disappears (the
|
|
7215
|
+
* owner clears the preview and the NEXT snapshot says so). It exists only
|
|
7216
|
+
* so the existing `rebuildLastMain()` repaint (a settled Question answer)
|
|
7217
|
+
* redraws the SAME rows instead of dropping them for one frame.
|
|
7218
|
+
*/
|
|
7219
|
+
let lastStreamingToolPreviews = [];
|
|
7220
|
+
/**
|
|
7221
|
+
* PR-C: the ONE image binding of this renderer, installed by the mount
|
|
7222
|
+
* BEFORE the first tool projection. It carries the mount's loader (the
|
|
7223
|
+
* single cache and read authority) and the scope sampler (the immutable
|
|
7224
|
+
* display-subject identity the read is authorized under). Without it the
|
|
7225
|
+
* renderer has NO image capability.
|
|
7226
|
+
*/
|
|
7227
|
+
let imageBinding;
|
|
7228
|
+
let imageBindingInstalled = false;
|
|
7229
|
+
/**
|
|
7230
|
+
* PR-C: the immutable image scope of the CURRENT display subject, captured
|
|
7231
|
+
* ONCE per projection source. An ordinary repaint or delta REUSES it: the
|
|
7232
|
+
* scope is never re-resolved when an async read settles, so a retired
|
|
7233
|
+
* presentation can never read under a successor's authorization.
|
|
7234
|
+
*/
|
|
7235
|
+
let activeImageScope;
|
|
7236
|
+
/**
|
|
7237
|
+
* PR-C: the CURRENT presentation subscriptions, keyed by attachment id.
|
|
7238
|
+
* They are short-lived presentation subscribers, NOT an image cache: the
|
|
7239
|
+
* loader owns the bytes, this map owns only the "this row waits for this
|
|
7240
|
+
* attachment" fact.
|
|
7241
|
+
*/
|
|
7242
|
+
const imageSubscriptions = /* @__PURE__ */ new Map();
|
|
7243
|
+
/**
|
|
7244
|
+
* PR-C: the image preparation was ABORTED by a fatal blob failure. The
|
|
7245
|
+
* projection must not continue: the last committed frame stands, and the
|
|
7246
|
+
* fatal lifecycle owns the exit.
|
|
7247
|
+
*/
|
|
7248
|
+
let imageProjectionAborted = false;
|
|
7249
|
+
/**
|
|
7250
|
+
* PR-D: the SVG blob preparation was ABORTED by a fatal blob failure (the
|
|
7251
|
+
* tty owner is gone). The same fatal lifecycle owns the exit; the last
|
|
7252
|
+
* committed frame stands and no further blob may be sent.
|
|
7253
|
+
*/
|
|
7254
|
+
let visualProjectionAborted = false;
|
|
7255
|
+
/** PR-D: admitted SVG digests → admission verdicts (bounded replay cache). */
|
|
7256
|
+
const svgAdmissions = /* @__PURE__ */ new Map();
|
|
7257
|
+
/** PR-D: admitted SVG digests → the ONE sender's blob id (content-addressed). */
|
|
7258
|
+
const svgBlobIds = /* @__PURE__ */ new Map();
|
|
7259
|
+
/**
|
|
7260
|
+
* PR-D RFL-016: the tool-card keys the user EXPANDED via the Tern `toggle`
|
|
7261
|
+
* event. A ready SVG card starts collapsed; only the user's expansion
|
|
7262
|
+
* requests its blob (the actual display demand), and collapsing/window/scope
|
|
7263
|
+
* changes release the id cache.
|
|
7264
|
+
*/
|
|
7265
|
+
const expandedToolKeys = /* @__PURE__ */ new Set();
|
|
7266
|
+
/** PR-D RFL-019: the CURRENT projection's actual node key PATH → disclosure.
|
|
7267
|
+
* The path comes from the real tool-node ancestor chain (never by splitting
|
|
7268
|
+
* ids on dots), so dotted subCallIds and an absent ToggleEvent.key are both
|
|
7269
|
+
* unambiguous. A toggle whose id does not end with a current path is
|
|
7270
|
+
* stale/foreign and is ignored. */
|
|
7271
|
+
const toolDisclosureByPath = /* @__PURE__ */ new Map();
|
|
7272
|
+
/**
|
|
7273
|
+
* PR3: the CURRENT committed frame's Assistant figures — the published refs
|
|
7274
|
+
* in paint order, each figure's wrapper node id, and the two Copy-target
|
|
7275
|
+
* indexes (keyboard by ref, pointer by the actual button node id). They are
|
|
7276
|
+
* short-lived event indexes rebuilt by `rebuildLastMain()`; nothing here is a
|
|
7277
|
+
* durable fact, and the maps are REPLACED (never consulted across a rebuild).
|
|
7278
|
+
*/
|
|
7279
|
+
let visualOrder = [];
|
|
7280
|
+
let figureNodeIds = /* @__PURE__ */ new Map();
|
|
7281
|
+
let visualTargets = /* @__PURE__ */ new Map();
|
|
7282
|
+
let visualCopyButtons = /* @__PURE__ */ new Map();
|
|
7283
|
+
/**
|
|
7284
|
+
* PR3: the selected figure of the CURRENT subject. It stores the ref plus
|
|
7285
|
+
* the 1-based position/count painted in the last committed frame; the next
|
|
7286
|
+
* rebuild reconciles it against the new frame's real order (a target that
|
|
7287
|
+
* left the window clears the selection, never a same-named ref elsewhere).
|
|
7288
|
+
*/
|
|
7289
|
+
let selectedVisual;
|
|
7290
|
+
/** The hardware caret this renderer last asked for (the ONE focus truth it
|
|
7291
|
+
* keeps: it re-issues the op only when the DESIRED seat changes, including
|
|
7292
|
+
* the return to the composer after a modal — the pre-B3 one-shot latch left
|
|
7293
|
+
* the composer dead after the first modal close). */
|
|
7294
|
+
let lastAppliedFocusId;
|
|
7295
|
+
/** Apply the seat's desired hardware focus after a committed frame. */
|
|
7296
|
+
const applyFocus = (force) => {
|
|
7297
|
+
if (disposed) return;
|
|
7298
|
+
if (detailsSlot !== void 0) {
|
|
7299
|
+
composer.setFocused(false);
|
|
7300
|
+
lastAppliedFocusId = void 0;
|
|
7301
|
+
return;
|
|
7302
|
+
}
|
|
7303
|
+
const desired = seat.hasModalSeat() ? seat.desiredFocusId() : workHub?.isOpen() === true ? workHub.desiredFocusId() ?? null : sessionBrowser?.isOpen() === true ? sessionBrowser.desiredFocusId() ?? null : presetPicker?.isOpen() === true ? presetPicker.desiredFocusId() ?? null : modelPicker?.isOpen() === true ? modelPicker.desiredFocusId() ?? null : "dock.composer";
|
|
7304
|
+
if (!force && desired === lastAppliedFocusId) return;
|
|
7305
|
+
lastAppliedFocusId = desired;
|
|
7306
|
+
composer.setFocused(desired === "dock.composer");
|
|
7307
|
+
surface.focus(desired);
|
|
7308
|
+
};
|
|
7309
|
+
/** Whether the pane negotiated everything the Reader's document needs. */
|
|
7310
|
+
function readerCapabilitiesNegotiated() {
|
|
7311
|
+
return WORK_DETAILS_KINDS.every((kind) => session.caps.kinds.includes(kind)) && session.caps.features.includes(WORK_DETAILS_FEATURE);
|
|
7312
|
+
}
|
|
7313
|
+
/**
|
|
7314
|
+
* B3-A3: whether this pane can present the WHOLE Work Hub entry — the native
|
|
7315
|
+
* `ui.picker` roster AND a readable Work Details Reader. It is the negotiated
|
|
7316
|
+
* capability of {@link WORK_DETAILS_KINDS}/{@link WORK_DETAILS_FEATURE} plus
|
|
7317
|
+
* the ONE node kind the Hub itself is built from; a pane missing either half
|
|
7318
|
+
* refuses `/tasks` before any TaskRuntime opener runs, instead of mounting a
|
|
7319
|
+
* Hub the user could neither read nor leave.
|
|
7320
|
+
*/
|
|
7321
|
+
function taskCenterCapabilitiesNegotiated() {
|
|
7322
|
+
return session.caps.kinds.includes("picker") && readerCapabilitiesNegotiated();
|
|
7323
|
+
}
|
|
7324
|
+
/**
|
|
7325
|
+
* Whether THIS pane can present a Work Details Reader at all: the negotiated
|
|
7326
|
+
* kinds the document really emits, the official `scroll` feature, and the
|
|
7327
|
+
* renderer's own mounted/bound/no-modal state. It answers the CAPABILITY
|
|
7328
|
+
* question, without any Reader-slot state.
|
|
7329
|
+
*/
|
|
7330
|
+
function readerCapabilityPresent() {
|
|
7331
|
+
return !disposed && !hydrating && inputBound && !seat.hasModalSeat() && readerCapabilitiesNegotiated();
|
|
7332
|
+
}
|
|
7333
|
+
/**
|
|
7334
|
+
* Whether a Reader could be ADMITTED right now. It is the capability above
|
|
7335
|
+
* plus the Reader's own lifecycle: nothing may be admitted while a reading is
|
|
7336
|
+
* opening, open or still closing.
|
|
7337
|
+
*/
|
|
7338
|
+
function canPresentWorkDetails() {
|
|
7339
|
+
return readerCapabilityPresent() && !openingDetails && detailsSlot === void 0 && detailsCloseTask === void 0;
|
|
7340
|
+
}
|
|
7341
|
+
/**
|
|
7342
|
+
* The ONE admission predicate of a NEW Reader (plan §6.2): the predicate
|
|
7343
|
+
* above PLUS a current Hub. It is rechecked immediately before the Screen is
|
|
7344
|
+
* acquired.
|
|
7345
|
+
*
|
|
7346
|
+
* The Hub PAINTS its action from {@link canPresentWorkDetails} for the same
|
|
7347
|
+
* reason: while a Reader is open or still closing the action must not be
|
|
7348
|
+
* offered at all. Whether the client also leaves the base surface on screen is
|
|
7349
|
+
* the client's own presentation decision, and it is NOT inferable from this
|
|
7350
|
+
* SDK call (a measured build covered the base; another may not). Painting an
|
|
7351
|
+
* action that this very predicate would refuse is therefore wrong either way:
|
|
7352
|
+
* it is a dead control if the base is visible and a misleading frame if it is
|
|
7353
|
+
* not.
|
|
7354
|
+
*/
|
|
7355
|
+
function supportsWorkDetails() {
|
|
7356
|
+
return canPresentWorkDetails() && workHub?.isOpen() === true;
|
|
7357
|
+
}
|
|
7358
|
+
function detailsIdentity(slot) {
|
|
7359
|
+
return {
|
|
7360
|
+
panelSerial: slot.panelSerial,
|
|
7361
|
+
readingEpoch: slot.readingEpoch,
|
|
7362
|
+
targetValue: slot.targetValue
|
|
7363
|
+
};
|
|
7364
|
+
}
|
|
7365
|
+
/**
|
|
7366
|
+
* Build the document and resolve the ACTUAL registered node id of its
|
|
7367
|
+
* `← Work` row through the shipped SDK's own view derivation — never a
|
|
7368
|
+
* guessed id path.
|
|
7369
|
+
*/
|
|
7370
|
+
function buildDetailsDocument(slot, item) {
|
|
7371
|
+
const identity = detailsIdentity(slot);
|
|
7372
|
+
const node = buildWorkDetails(item, identity, () => {
|
|
7373
|
+
returnFromWorkDetails(slot);
|
|
7374
|
+
});
|
|
7375
|
+
const backKey = workDetailsBackKey(identity);
|
|
7376
|
+
let backId;
|
|
7377
|
+
for (const root of View.from({ [WORK_DETAILS_REGION]: node }).regions) {
|
|
7378
|
+
const visit = (candidate) => {
|
|
7379
|
+
if (candidate === void 0) return;
|
|
7380
|
+
if (candidate.props["key"] === backKey) backId = candidate.id;
|
|
7381
|
+
for (const child of candidate.children) visit(child);
|
|
7382
|
+
};
|
|
7383
|
+
visit(root);
|
|
7384
|
+
}
|
|
7385
|
+
return {
|
|
7386
|
+
node,
|
|
7387
|
+
backId
|
|
7388
|
+
};
|
|
7389
|
+
}
|
|
7390
|
+
/** The `← Work`/Esc return: admitted only for the CURRENT reading. */
|
|
7391
|
+
function returnFromWorkDetails(slot) {
|
|
7392
|
+
if (detailsSlot !== slot || slot.phase !== "open") return;
|
|
7393
|
+
retireWorkDetails("back");
|
|
7394
|
+
}
|
|
7395
|
+
/**
|
|
7396
|
+
* The ONE Reader retirement: synchronous revocation, one owned asynchronous
|
|
7397
|
+
* close, exactly one `close()` call. It is the SAME operation for Back, a
|
|
7398
|
+
* modal preemption, a sibling presenter, hydration, a disappeared target and
|
|
7399
|
+
* disposal — never a second public Presenter.
|
|
7400
|
+
*/
|
|
7401
|
+
function retireWorkDetails(reason) {
|
|
7402
|
+
const slot = detailsSlot;
|
|
7403
|
+
if (slot === void 0) return detailsCloseTask;
|
|
7404
|
+
if (slot.phase === "closing") return detailsCloseTask;
|
|
7405
|
+
slot.phase = "closing";
|
|
7406
|
+
slot.backId = void 0;
|
|
7407
|
+
options.log?.("tsp renderer: work details retired", {
|
|
7408
|
+
reason,
|
|
7409
|
+
panelSerial: slot.panelSerial
|
|
7410
|
+
});
|
|
7411
|
+
let closeTask;
|
|
7412
|
+
try {
|
|
7413
|
+
closeTask = slot.surface.close({ keep: false });
|
|
7414
|
+
} catch (error) {
|
|
7415
|
+
closeTask = Promise.reject(error);
|
|
7416
|
+
}
|
|
7417
|
+
detailsCloseTask = closeTask;
|
|
7418
|
+
closeTask.then(() => {
|
|
7419
|
+
try {
|
|
7420
|
+
if (detailsSlot === slot) {
|
|
7421
|
+
detailsSlot = void 0;
|
|
7422
|
+
detailsCloseTask = void 0;
|
|
7423
|
+
}
|
|
7424
|
+
if (disposed) return;
|
|
7425
|
+
lastAppliedFocusId = void 0;
|
|
7426
|
+
render();
|
|
7427
|
+
} catch (error) {
|
|
7428
|
+
if (!disposed) routeFatal(error);
|
|
7429
|
+
}
|
|
7430
|
+
}, (error) => {
|
|
7431
|
+
try {
|
|
7432
|
+
if (!disposed) routeFatal(error);
|
|
7433
|
+
} catch (secondary) {
|
|
7434
|
+
options.logError?.("tsp renderer: work details close failure could not be routed", {
|
|
7435
|
+
error: errorText(error),
|
|
7436
|
+
secondary: errorText(secondary)
|
|
7437
|
+
});
|
|
7438
|
+
}
|
|
7439
|
+
});
|
|
7440
|
+
return closeTask;
|
|
7441
|
+
}
|
|
7442
|
+
/**
|
|
7443
|
+
* Open the read-only Reader for the CURRENT Work Hub row. There is NO
|
|
7444
|
+
* independent await in the successful path: the SDK open/render/scroll/focus
|
|
7445
|
+
* calls are synchronous, and only the CLOSE is owned and asynchronous.
|
|
7446
|
+
*/
|
|
7447
|
+
function openWorkDetails(request) {
|
|
7448
|
+
if (disposed) return;
|
|
7449
|
+
const item = workHub?.resolveDetails(request.panelSerial, request.targetValue);
|
|
7450
|
+
if (item === void 0) return;
|
|
7451
|
+
if (!readerCapabilitiesNegotiated()) {
|
|
7452
|
+
display.notify("Work details are unavailable in this Tern pane.", "info");
|
|
7453
|
+
return;
|
|
7454
|
+
}
|
|
7455
|
+
if (!supportsWorkDetails()) return;
|
|
7456
|
+
openingDetails = true;
|
|
7457
|
+
nextReadingEpoch += 1;
|
|
7458
|
+
const readingEpoch = nextReadingEpoch;
|
|
7459
|
+
try {
|
|
7460
|
+
let screen;
|
|
7461
|
+
try {
|
|
7462
|
+
screen = session.open({
|
|
7463
|
+
mode: "screen",
|
|
7464
|
+
title: "Work details"
|
|
7465
|
+
});
|
|
7466
|
+
} catch (error) {
|
|
7467
|
+
routeFatal(error);
|
|
7468
|
+
return;
|
|
7469
|
+
}
|
|
7470
|
+
const slot = {
|
|
7471
|
+
surface: screen,
|
|
7472
|
+
panelSerial: request.panelSerial,
|
|
7473
|
+
targetValue: item.value,
|
|
7474
|
+
readingEpoch,
|
|
7475
|
+
phase: "open",
|
|
7476
|
+
backId: void 0
|
|
7477
|
+
};
|
|
7478
|
+
detailsSlot = slot;
|
|
7479
|
+
try {
|
|
7480
|
+
const document = buildDetailsDocument(slot, item);
|
|
7481
|
+
slot.backId = document.backId;
|
|
7482
|
+
screen.render({ [WORK_DETAILS_REGION]: document.node });
|
|
7483
|
+
screen.scroll(WORK_DETAILS_REGION, "start");
|
|
7484
|
+
screen.focus(WORK_DETAILS_REGION);
|
|
7485
|
+
} catch (error) {
|
|
7486
|
+
retireWorkDetails("failure");
|
|
7487
|
+
routeFatal(error);
|
|
7488
|
+
return;
|
|
7489
|
+
}
|
|
7490
|
+
if (workHub?.resolveDetails(request.panelSerial, request.targetValue) === void 0) retireWorkDetails("target-invalid");
|
|
7491
|
+
} finally {
|
|
7492
|
+
openingDetails = false;
|
|
7493
|
+
}
|
|
7494
|
+
if (detailsSlot !== void 0) {
|
|
7495
|
+
workHub?.suspend();
|
|
7496
|
+
render();
|
|
7497
|
+
}
|
|
7498
|
+
}
|
|
7499
|
+
/**
|
|
7500
|
+
* The Reader's stable rerender: the base render path calls this AFTER its
|
|
7501
|
+
* own frame, and a resize/status update only rebuilds the document. It never
|
|
7502
|
+
* starts a new scroll, re-focuses, opens a Screen or reads a source.
|
|
5280
7503
|
*/
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
7504
|
+
function syncWorkDetails() {
|
|
7505
|
+
const slot = detailsSlot;
|
|
7506
|
+
if (slot === void 0 || slot.phase !== "open") return;
|
|
7507
|
+
const item = workHub?.resolveDetails(slot.panelSerial, slot.targetValue);
|
|
7508
|
+
if (item === void 0) {
|
|
7509
|
+
retireWorkDetails("target-invalid");
|
|
7510
|
+
return;
|
|
7511
|
+
}
|
|
7512
|
+
try {
|
|
7513
|
+
const document = buildDetailsDocument(slot, item);
|
|
7514
|
+
slot.backId = document.backId;
|
|
7515
|
+
slot.surface.render({ [WORK_DETAILS_REGION]: document.node });
|
|
7516
|
+
} catch (error) {
|
|
7517
|
+
retireWorkDetails("failure");
|
|
7518
|
+
routeFatal(error);
|
|
7519
|
+
}
|
|
7520
|
+
}
|
|
7521
|
+
/** Map one visible-Reader key onto the SDK's own scroll operations. */
|
|
7522
|
+
function handleDetailsKey(slot, key) {
|
|
7523
|
+
const step = key.name === "up" ? "line-up" : key.name === "down" ? "line-down" : key.name === "page_up" ? "page-up" : key.name === "page_down" ? "page-down" : key.name === "home" ? "start" : key.name === "end" ? "end" : void 0;
|
|
7524
|
+
if (step !== void 0) {
|
|
7525
|
+
slot.surface.scroll(WORK_DETAILS_REGION, step);
|
|
7526
|
+
return;
|
|
7527
|
+
}
|
|
7528
|
+
if (key.name === "escape") retireWorkDetails("back");
|
|
7529
|
+
}
|
|
7530
|
+
/** Admit one native event for the CURRENT Reader, or report it as foreign. */
|
|
7531
|
+
function handleDetailsEvent(event) {
|
|
7532
|
+
const slot = detailsSlot;
|
|
7533
|
+
if (slot === void 0 || slot.phase !== "open") return false;
|
|
7534
|
+
if (event.ev !== "action") return false;
|
|
7535
|
+
if (!("sf" in event) || event.sf !== slot.surface.id) return false;
|
|
7536
|
+
if (!("id" in event) || event.id === void 0 || event.id !== slot.backId) return false;
|
|
7537
|
+
if (event.act !== "click") return false;
|
|
7538
|
+
returnFromWorkDetails(slot);
|
|
7539
|
+
return true;
|
|
7540
|
+
}
|
|
5297
7541
|
/** Re-render every region in ONE frame (the SDK diffs). The `layer` region is
|
|
5298
7542
|
* ALWAYS submitted (an omitted region would be deleted by the full-view
|
|
5299
7543
|
* diff, wiping an open modal on the next unrelated repaint). */
|
|
@@ -5303,27 +7547,562 @@ function mountTspRenderer(session, options) {
|
|
|
5303
7547
|
sessionBrowser?.suspend();
|
|
5304
7548
|
modelPicker?.suspend();
|
|
5305
7549
|
presetPicker?.suspend();
|
|
7550
|
+
workHub?.suspend();
|
|
5306
7551
|
}
|
|
5307
|
-
|
|
7552
|
+
if (imageProjectionAborted || visualProjectionAborted) return;
|
|
7553
|
+
if (!hydrating) syncImageSubscriptions();
|
|
7554
|
+
const draftStates = prepareDockDraftImageStates();
|
|
7555
|
+
if (imageProjectionAborted) return;
|
|
7556
|
+
const dockNode = dockView(draftStates);
|
|
5308
7557
|
const mainNode = lastMain;
|
|
5309
7558
|
surface.render({
|
|
5310
7559
|
...mainNode === void 0 ? {} : { main: mainNode },
|
|
5311
7560
|
...dockNode === void 0 ? {} : { dock: dockNode },
|
|
5312
|
-
layer: seat.hasModalSeat() ? seat.renderLayer() : sessionBrowser?.renderLayer() ?? presetPicker?.renderLayer() ?? modelPicker?.renderLayer() ?? seat.renderLayer()
|
|
7561
|
+
layer: detailsSlot !== void 0 && seat.hasModalSeat() ? seat.renderEmptyLayer() : seat.hasModalSeat() ? seat.renderLayer() : workHub?.renderLayer() ?? sessionBrowser?.renderLayer() ?? presetPicker?.renderLayer() ?? modelPicker?.renderLayer() ?? seat.renderLayer()
|
|
5313
7562
|
});
|
|
5314
7563
|
applyFocus(false);
|
|
7564
|
+
syncWorkDetails();
|
|
5315
7565
|
}
|
|
7566
|
+
/**
|
|
7567
|
+
* PR-C: whether the pane can carry a native image at all. The `image` kind
|
|
7568
|
+
* and the `blobs` feature are NEGOTIATED by the client — the mapper never
|
|
7569
|
+
* infers them from a TypeScript prop.
|
|
7570
|
+
*/
|
|
7571
|
+
const nativeImagesSupported = () => session.caps.kinds.includes("image") && session.caps.features.includes("blobs");
|
|
7572
|
+
/**
|
|
7573
|
+
* PR-C: the image attachments the CURRENT window projects, in window
|
|
7574
|
+
* order. The row rule is the mapper's own ({@link toolRowImageBlocks}), so
|
|
7575
|
+
* the reader and the view can never disagree: a row that does not project
|
|
7576
|
+
* an image is never read, and a malformed reference is never read either.
|
|
7577
|
+
*
|
|
7578
|
+
* PR4: the SAME enumeration now covers User/Assistant bodies beside Tool
|
|
7579
|
+
* results. The block lists are chosen EXACTLY as the mapper chooses them
|
|
7580
|
+
* (`displayBlocks` outranks settled `content` while an opaque block is open;
|
|
7581
|
+
* User reads `content`), so a body the mapper draws block-wise is a body
|
|
7582
|
+
* whose images are read, and a legacy flat body reads nothing.
|
|
7583
|
+
*/
|
|
7584
|
+
const projectedImageRefs = () => {
|
|
7585
|
+
const refs = [];
|
|
7586
|
+
const push = (attachment) => {
|
|
7587
|
+
if (imageRefProblem(attachment) !== void 0) return;
|
|
7588
|
+
refs.push(attachment);
|
|
7589
|
+
};
|
|
7590
|
+
const pushBodyImages = (blocks) => {
|
|
7591
|
+
for (const block of blocks) if (block.type === "image") push(block.attachment);
|
|
7592
|
+
};
|
|
7593
|
+
const visit = (message) => {
|
|
7594
|
+
if (message.kind === "user") {
|
|
7595
|
+
if (message.content !== void 0) pushBodyImages(message.content);
|
|
7596
|
+
return;
|
|
7597
|
+
}
|
|
7598
|
+
if (message.kind === "assistant") {
|
|
7599
|
+
const display = message.displayBlocks;
|
|
7600
|
+
if (display !== void 0) {
|
|
7601
|
+
for (const block of display) if (block.kind === "content") pushBodyImages([block.block]);
|
|
7602
|
+
return;
|
|
7603
|
+
}
|
|
7604
|
+
if (message.content !== void 0) pushBodyImages(message.content);
|
|
7605
|
+
return;
|
|
7606
|
+
}
|
|
7607
|
+
if (message.kind !== "tool") return;
|
|
7608
|
+
for (const block of toolRowImageBlocks(message)) push(block.attachment);
|
|
7609
|
+
for (const child of message.subCalls ?? []) visit(child);
|
|
7610
|
+
};
|
|
7611
|
+
for (const message of lastMessages) visit(message);
|
|
7612
|
+
return refs;
|
|
7613
|
+
};
|
|
7614
|
+
/** PR-C: drop every presentation subscription of the current subject. */
|
|
7615
|
+
const releaseImageSubscriptions = () => {
|
|
7616
|
+
for (const unsubscribe of imageSubscriptions.values()) unsubscribe();
|
|
7617
|
+
imageSubscriptions.clear();
|
|
7618
|
+
};
|
|
7619
|
+
/**
|
|
7620
|
+
* PR-C: the per-attachment render state of the current subject, prepared
|
|
7621
|
+
* BEFORE the projection so the mapper stays pure and the blob is sent
|
|
7622
|
+
* before the frame that references it.
|
|
7623
|
+
*
|
|
7624
|
+
* The `session.blob()` call is the ONE blob sender of the renderer: the
|
|
7625
|
+
* SDK dedupes the content, so a repeated projection never sends the bytes
|
|
7626
|
+
* twice. The 16 MiB gate is checked against the READY bytes — the
|
|
7627
|
+
* reference's own byte count is identity, never a send permit.
|
|
7628
|
+
*/
|
|
7629
|
+
const prepareImageStates = () => {
|
|
7630
|
+
const binding = imageBinding;
|
|
7631
|
+
if (binding === void 0) return void 0;
|
|
7632
|
+
const states = /* @__PURE__ */ new Map();
|
|
7633
|
+
const refs = projectedImageRefs();
|
|
7634
|
+
if (!nativeImagesSupported()) {
|
|
7635
|
+
for (const ref of refs) states.set(ref.attachmentId, { state: "unsupported" });
|
|
7636
|
+
return states;
|
|
7637
|
+
}
|
|
7638
|
+
const scope = activeImageScope;
|
|
7639
|
+
if (scope === void 0) {
|
|
7640
|
+
for (const ref of refs) states.set(ref.attachmentId, { state: "no-scope" });
|
|
7641
|
+
return states;
|
|
7642
|
+
}
|
|
7643
|
+
for (const ref of refs) {
|
|
7644
|
+
const load = binding.imageLoader.get(ref, scope);
|
|
7645
|
+
if (load.state === "idle" || load.state === "loading") {
|
|
7646
|
+
states.set(ref.attachmentId, { state: "loading" });
|
|
7647
|
+
continue;
|
|
7648
|
+
}
|
|
7649
|
+
if (load.state === "error") {
|
|
7650
|
+
states.set(ref.attachmentId, { state: "error" });
|
|
7651
|
+
continue;
|
|
7652
|
+
}
|
|
7653
|
+
if (load.bytes.length > 16777216) {
|
|
7654
|
+
states.set(ref.attachmentId, { state: "too-large" });
|
|
7655
|
+
continue;
|
|
7656
|
+
}
|
|
7657
|
+
try {
|
|
7658
|
+
states.set(ref.attachmentId, {
|
|
7659
|
+
state: "ready",
|
|
7660
|
+
blobId: session.blob(load.bytes, ref.mediaType)
|
|
7661
|
+
});
|
|
7662
|
+
} catch (error) {
|
|
7663
|
+
routeFatal(error);
|
|
7664
|
+
imageProjectionAborted = true;
|
|
7665
|
+
return;
|
|
7666
|
+
}
|
|
7667
|
+
}
|
|
7668
|
+
return states;
|
|
7669
|
+
};
|
|
7670
|
+
/**
|
|
7671
|
+
* PR-C: the CURRENT window's image subscriptions. An attachment that left
|
|
7672
|
+
* the window is unsubscribed; a new one is subscribed BEFORE it is read.
|
|
7673
|
+
* The loader dedupes the read per (scope, attachment id), so two blocks
|
|
7674
|
+
* naming the same attachment read once.
|
|
7675
|
+
*
|
|
7676
|
+
* PR4: the wanted set is the SAME enumeration as the projection, extended
|
|
7677
|
+
* with the valid RECALLED draft refs of the live composer. A recalled draft
|
|
7678
|
+
* holds no local bytes, so the ONE existing loader (under the CURRENT
|
|
7679
|
+
* immutable scope) is its only authorized read path — and it uses ONE
|
|
7680
|
+
* subscription per attachment id, the same ledger as the transcript rows.
|
|
7681
|
+
*/
|
|
7682
|
+
const syncImageSubscriptions = () => {
|
|
7683
|
+
const binding = imageBinding;
|
|
7684
|
+
const scope = activeImageScope;
|
|
7685
|
+
if (binding === void 0 || scope === void 0 || !nativeImagesSupported()) {
|
|
7686
|
+
releaseImageSubscriptions();
|
|
7687
|
+
return;
|
|
7688
|
+
}
|
|
7689
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
7690
|
+
for (const ref of projectedImageRefs()) wanted.set(ref.attachmentId, ref);
|
|
7691
|
+
for (const ref of recalledDraftRefs()) wanted.set(ref.attachmentId, ref);
|
|
7692
|
+
for (const [id, unsubscribe] of imageSubscriptions) {
|
|
7693
|
+
if (wanted.has(id)) continue;
|
|
7694
|
+
unsubscribe();
|
|
7695
|
+
imageSubscriptions.delete(id);
|
|
7696
|
+
}
|
|
7697
|
+
for (const [id, ref] of wanted) {
|
|
7698
|
+
if (imageSubscriptions.has(id)) continue;
|
|
7699
|
+
const source = projectionScope;
|
|
7700
|
+
const unsubscribe = binding.imageLoader.subscribe(id, () => {
|
|
7701
|
+
if (disposed || hydrating) return;
|
|
7702
|
+
if (source !== projectionScope) return;
|
|
7703
|
+
if (scope !== activeImageScope) return;
|
|
7704
|
+
if (!imageSubscriptions.has(id)) return;
|
|
7705
|
+
if (!rebuildLastMain()) return;
|
|
7706
|
+
render();
|
|
7707
|
+
}, scope);
|
|
7708
|
+
imageSubscriptions.set(id, unsubscribe);
|
|
7709
|
+
if (binding.imageLoader.get(ref, scope).state === "idle") binding.imageLoader.load(ref, scope);
|
|
7710
|
+
}
|
|
7711
|
+
};
|
|
7712
|
+
/**
|
|
7713
|
+
* PR4: the valid recalled-image refs the LIVE composer draft references. A
|
|
7714
|
+
* recalled draft carries no bytes of its own, so its durable ref is the ONE
|
|
7715
|
+
* readable authority — and only while the ref is structurally presentable.
|
|
7716
|
+
* These refs join the SAME subscription/read ledger as the transcript rows.
|
|
7717
|
+
*/
|
|
7718
|
+
const recalledDraftRefs = () => {
|
|
7719
|
+
const binding = imageBinding;
|
|
7720
|
+
if (binding === void 0) return [];
|
|
7721
|
+
const limit = dockPreviewLimit();
|
|
7722
|
+
if (limit === 0) return [];
|
|
7723
|
+
const refs = [];
|
|
7724
|
+
for (const occurrence of binding.draftImages.occurrences().slice(0, limit)) {
|
|
7725
|
+
const image = occurrence.image;
|
|
7726
|
+
if (image.source.type !== "recalled") continue;
|
|
7727
|
+
const ref = image.recalledRef;
|
|
7728
|
+
if (ref === void 0 || imageRefProblem(ref) !== void 0) continue;
|
|
7729
|
+
refs.push(ref);
|
|
7730
|
+
}
|
|
7731
|
+
return refs;
|
|
7732
|
+
};
|
|
7733
|
+
/**
|
|
7734
|
+
* PR4: prepare the dock's per-occurrence state BEFORE the pure dock view.
|
|
7735
|
+
*
|
|
7736
|
+
* The staged LOCAL bytes are the draft's own (no read is authorized or
|
|
7737
|
+
* needed); a recalled draft goes through the ONE existing loader above. Both
|
|
7738
|
+
* send through the SAME `session.blob()` sender, whose content addressing
|
|
7739
|
+
* means a repeated frame never re-sends bytes. Nothing here writes back to
|
|
7740
|
+
* the draft store: a failed preview must not delete the user's draft.
|
|
7741
|
+
*
|
|
7742
|
+
* A fatal blob failure routes the renderer fatal and ABORTS this projection,
|
|
7743
|
+
* exactly like the transcript image path: the caller must not paint a frame
|
|
7744
|
+
* that pretends otherwise.
|
|
7745
|
+
*/
|
|
7746
|
+
const prepareDockDraftImageStates = () => {
|
|
7747
|
+
const binding = imageBinding;
|
|
7748
|
+
if (binding === void 0) return void 0;
|
|
7749
|
+
const limit = dockPreviewLimit();
|
|
7750
|
+
if (limit === 0) return /* @__PURE__ */ new Map();
|
|
7751
|
+
const occurrences = binding.draftImages.occurrences().slice(0, limit);
|
|
7752
|
+
if (occurrences.length === 0) return /* @__PURE__ */ new Map();
|
|
7753
|
+
const states = /* @__PURE__ */ new Map();
|
|
7754
|
+
if (!nativeImagesSupported()) {
|
|
7755
|
+
for (const occurrence of occurrences) states.set(draftOccurrenceKey(occurrence), { state: "unsupported" });
|
|
7756
|
+
return states;
|
|
7757
|
+
}
|
|
7758
|
+
for (const occurrence of occurrences) {
|
|
7759
|
+
const key = draftOccurrenceKey(occurrence);
|
|
7760
|
+
const image = occurrence.image;
|
|
7761
|
+
if (image.source.type === "recalled") {
|
|
7762
|
+
const ref = image.recalledRef;
|
|
7763
|
+
const scope = activeImageScope;
|
|
7764
|
+
if (ref === void 0 || imageRefProblem(ref) !== void 0 || scope === void 0) {
|
|
7765
|
+
states.set(key, { state: "no-scope" });
|
|
7766
|
+
continue;
|
|
7767
|
+
}
|
|
7768
|
+
const load = binding.imageLoader.get(ref, scope);
|
|
7769
|
+
if (load.state === "idle" || load.state === "loading") {
|
|
7770
|
+
states.set(key, { state: "loading" });
|
|
7771
|
+
continue;
|
|
7772
|
+
}
|
|
7773
|
+
if (load.state === "error") {
|
|
7774
|
+
states.set(key, { state: "error" });
|
|
7775
|
+
continue;
|
|
7776
|
+
}
|
|
7777
|
+
if (load.bytes.length > 16777216) {
|
|
7778
|
+
states.set(key, { state: "too-large" });
|
|
7779
|
+
continue;
|
|
7780
|
+
}
|
|
7781
|
+
const blobId = sendDraftBlob(load.bytes, ref.mediaType);
|
|
7782
|
+
if (blobId === void 0) return void 0;
|
|
7783
|
+
states.set(key, {
|
|
7784
|
+
state: "ready",
|
|
7785
|
+
blobId
|
|
7786
|
+
});
|
|
7787
|
+
continue;
|
|
7788
|
+
}
|
|
7789
|
+
if (image.bytes.byteLength > 16777216) {
|
|
7790
|
+
states.set(key, { state: "too-large" });
|
|
7791
|
+
continue;
|
|
7792
|
+
}
|
|
7793
|
+
const blobId = sendDraftBlob(image.bytes, image.mediaType);
|
|
7794
|
+
if (blobId === void 0) return void 0;
|
|
7795
|
+
states.set(key, {
|
|
7796
|
+
state: "ready",
|
|
7797
|
+
blobId
|
|
7798
|
+
});
|
|
7799
|
+
}
|
|
7800
|
+
return states;
|
|
7801
|
+
};
|
|
7802
|
+
/** PR4: send one draft's bytes through the ONE SDK blob sender. `undefined`
|
|
7803
|
+
* means the send failed and the projection was aborted (fatal routed). */
|
|
7804
|
+
const sendDraftBlob = (bytes, mediaType) => {
|
|
7805
|
+
try {
|
|
7806
|
+
return session.blob(bytes, mediaType);
|
|
7807
|
+
} catch (error) {
|
|
7808
|
+
routeFatal(error);
|
|
7809
|
+
imageProjectionAborted = true;
|
|
7810
|
+
return;
|
|
7811
|
+
}
|
|
7812
|
+
};
|
|
7813
|
+
/**
|
|
7814
|
+
* PR-D: prepare the per-row SVG display states BEFORE the pure projection.
|
|
7815
|
+
*
|
|
7816
|
+
* The admission gate runs on the DURABLE call args, and a row is authorized
|
|
7817
|
+
* only when its FINAL result blocks still carry a credential whose digest
|
|
7818
|
+
* matches those args. A ready row sends the SAME admitted bytes through the
|
|
7819
|
+
* ONE `session.blob()` sender (content-addressed, so a repeated projection
|
|
7820
|
+
* never re-sends). A fatal blob failure aborts the projection exactly like
|
|
7821
|
+
* the PR-C image path.
|
|
7822
|
+
*/
|
|
7823
|
+
/**
|
|
7824
|
+
* PR-D display demand: send one admitted SVG through the ONE blob sender
|
|
7825
|
+
* only when the projection actually needs its image node. The map is
|
|
7826
|
+
* content-addressed and pruned to the current window (and cleared on a
|
|
7827
|
+
* subject/scope change), so collapse/paging/backscroll/reconnect do not
|
|
7828
|
+
* accumulate sends or blob ids.
|
|
7829
|
+
*/
|
|
7830
|
+
const sendSvgBlob = (source, digest) => {
|
|
7831
|
+
if (visualProjectionAborted) return void 0;
|
|
7832
|
+
const known = svgBlobIds.get(digest);
|
|
7833
|
+
if (known !== void 0) return known;
|
|
7834
|
+
try {
|
|
7835
|
+
const blobId = session.blob(Buffer.from(source, "utf8"), "image/svg+xml");
|
|
7836
|
+
svgBlobIds.set(digest, blobId);
|
|
7837
|
+
return blobId;
|
|
7838
|
+
} catch (error) {
|
|
7839
|
+
routeFatal(error);
|
|
7840
|
+
visualProjectionAborted = true;
|
|
7841
|
+
return;
|
|
7842
|
+
}
|
|
7843
|
+
};
|
|
7844
|
+
const prepareSvgStates = () => {
|
|
7845
|
+
const states = /* @__PURE__ */ new Map();
|
|
7846
|
+
const admit = (source) => {
|
|
7847
|
+
const digest = svgDigest(source);
|
|
7848
|
+
const cached = svgAdmissions.get(digest);
|
|
7849
|
+
if (cached !== void 0) return cached;
|
|
7850
|
+
const verdict = admitSvg(source);
|
|
7851
|
+
if (svgAdmissions.size >= 32) svgAdmissions.clear();
|
|
7852
|
+
svgAdmissions.set(digest, verdict);
|
|
7853
|
+
return verdict;
|
|
7854
|
+
};
|
|
7855
|
+
const visit = (message) => {
|
|
7856
|
+
if (message.kind !== "tool") return true;
|
|
7857
|
+
if (message.name === "dsh_pi_tui_svg") {
|
|
7858
|
+
if (message.status !== "ok") states.set(message, {
|
|
7859
|
+
state: "invalid",
|
|
7860
|
+
reason: "the tool result was not successful"
|
|
7861
|
+
});
|
|
7862
|
+
else {
|
|
7863
|
+
const blocks = message.resultBlocks ?? (() => {
|
|
7864
|
+
const parts = visualPartsFromText(message.result);
|
|
7865
|
+
return parts.fact === void 0 ? [] : [{
|
|
7866
|
+
type: "text",
|
|
7867
|
+
text: visualFactLine(parts.fact)
|
|
7868
|
+
}];
|
|
7869
|
+
})();
|
|
7870
|
+
const authorization = authorizeSvg(message.args, blocks, message.status, admit);
|
|
7871
|
+
if (authorization.state === "text") states.set(message, {
|
|
7872
|
+
state: "invalid",
|
|
7873
|
+
reason: authorization.reason
|
|
7874
|
+
});
|
|
7875
|
+
else if (!nativeImagesSupported()) states.set(message, {
|
|
7876
|
+
state: "unsupported",
|
|
7877
|
+
fact: authorization.fact,
|
|
7878
|
+
source: authorization.source
|
|
7879
|
+
});
|
|
7880
|
+
else states.set(message, {
|
|
7881
|
+
state: "ready",
|
|
7882
|
+
fact: authorization.fact,
|
|
7883
|
+
source: authorization.source,
|
|
7884
|
+
request: () => sendSvgBlob(authorization.source, authorization.fact.digest)
|
|
7885
|
+
});
|
|
7886
|
+
}
|
|
7887
|
+
}
|
|
7888
|
+
for (const child of message.subCalls ?? []) if (!visit(child)) return false;
|
|
7889
|
+
return true;
|
|
7890
|
+
};
|
|
7891
|
+
for (const message of lastMessages) if (!visit(message)) return void 0;
|
|
7892
|
+
const live = /* @__PURE__ */ new Set();
|
|
7893
|
+
for (const state of states.values()) if (state.state === "ready") live.add(state.fact.digest);
|
|
7894
|
+
for (const message of lastMessages) {
|
|
7895
|
+
if (message.kind !== "assistant" || message.displayBlocks !== void 0) continue;
|
|
7896
|
+
const presentation = assistantVisualPresentation(message);
|
|
7897
|
+
if (presentation === void 0) continue;
|
|
7898
|
+
for (const publication of presentation.publications) {
|
|
7899
|
+
const svg = publication.source.svg;
|
|
7900
|
+
if (svg !== void 0 && publication.source.svgSource !== void 0) live.add(svg.digest);
|
|
7901
|
+
}
|
|
7902
|
+
}
|
|
7903
|
+
for (const digest of [...svgBlobIds.keys()]) if (!live.has(digest)) svgBlobIds.delete(digest);
|
|
7904
|
+
return states;
|
|
7905
|
+
};
|
|
7906
|
+
/**
|
|
7907
|
+
* PR3: the eligible figure sources of the current window, keyed by the
|
|
7908
|
+
* figure wrapper key the mapper writes. The gates are the mapper's own: an
|
|
7909
|
+
* open-`displayBlocks` row is not the settled body, and only a sidecar with
|
|
7910
|
+
* publications draws figures.
|
|
7911
|
+
*/
|
|
7912
|
+
const visualFigureSources = () => {
|
|
7913
|
+
const sources = /* @__PURE__ */ new Map();
|
|
7914
|
+
for (const message of lastMessages) {
|
|
7915
|
+
if (message.kind !== "assistant" || message.displayBlocks !== void 0) continue;
|
|
7916
|
+
const presentation = assistantVisualPresentation(message);
|
|
7917
|
+
if (presentation === void 0 || presentation.publications.length === 0) continue;
|
|
7918
|
+
for (const publication of presentation.publications) sources.set(`${VISUAL_FIGURE_KEY_PREFIX}${publication.ref}`, {
|
|
7919
|
+
message,
|
|
7920
|
+
publication
|
|
7921
|
+
});
|
|
7922
|
+
}
|
|
7923
|
+
return sources;
|
|
7924
|
+
};
|
|
7925
|
+
/**
|
|
7926
|
+
* PR3: index the COMMITTED main tree. The node ids come from the SDK's own
|
|
7927
|
+
* `View.from` derivation over the exact tree this renderer paints, so a
|
|
7928
|
+
* pointer action can be matched by the real button id of the current frame —
|
|
7929
|
+
* never by a ref substring, a bare call id or a guessed path.
|
|
7930
|
+
*/
|
|
7931
|
+
const indexVisualFrame = (root, sources) => {
|
|
7932
|
+
const order = [];
|
|
7933
|
+
const nodeIds = /* @__PURE__ */ new Map();
|
|
7934
|
+
const targets = /* @__PURE__ */ new Map();
|
|
7935
|
+
const copyButtons = /* @__PURE__ */ new Map();
|
|
7936
|
+
const source = projectionScope;
|
|
7937
|
+
if (source === void 0) return {
|
|
7938
|
+
order,
|
|
7939
|
+
nodeIds,
|
|
7940
|
+
targets,
|
|
7941
|
+
copyButtons
|
|
7942
|
+
};
|
|
7943
|
+
const visit = (tree, figure) => {
|
|
7944
|
+
const key = tree.props.key;
|
|
7945
|
+
const entry = typeof key === "string" ? sources.get(key) : void 0;
|
|
7946
|
+
let current = figure;
|
|
7947
|
+
if (entry !== void 0) {
|
|
7948
|
+
current = {
|
|
7949
|
+
message: entry.message,
|
|
7950
|
+
publication: entry.publication,
|
|
7951
|
+
source,
|
|
7952
|
+
scopePrefix
|
|
7953
|
+
};
|
|
7954
|
+
order.push(entry.publication.ref);
|
|
7955
|
+
nodeIds.set(entry.publication.ref, tree.id);
|
|
7956
|
+
targets.set(entry.publication.ref, current);
|
|
7957
|
+
}
|
|
7958
|
+
if (current !== void 0 && key === "visual-copy") copyButtons.set(tree.id, current);
|
|
7959
|
+
for (const child of tree.children) visit(child, current);
|
|
7960
|
+
};
|
|
7961
|
+
for (const region of View.from({ main: root }).regions) if (region !== void 0) visit(region, void 0);
|
|
7962
|
+
return {
|
|
7963
|
+
order,
|
|
7964
|
+
nodeIds,
|
|
7965
|
+
targets,
|
|
7966
|
+
copyButtons
|
|
7967
|
+
};
|
|
7968
|
+
};
|
|
7969
|
+
/** Reconcile the previous selection with a frame's REAL figure order: a
|
|
7970
|
+
* target that left the window clears the selection. */
|
|
7971
|
+
const reconcileVisualSelection = (previous, frame) => {
|
|
7972
|
+
if (previous === void 0) return void 0;
|
|
7973
|
+
const index = frame.order.indexOf(previous.ref);
|
|
7974
|
+
return index < 0 ? void 0 : {
|
|
7975
|
+
ref: previous.ref,
|
|
7976
|
+
index: index + 1,
|
|
7977
|
+
count: frame.order.length
|
|
7978
|
+
};
|
|
7979
|
+
};
|
|
7980
|
+
/** Whether two selection facts paint the same badge. */
|
|
7981
|
+
const sameSelectedVisual = (left, right) => left === right || left !== void 0 && right !== void 0 && left.ref === right.ref && left.index === right.index && left.count === right.count;
|
|
7982
|
+
/** Drop the committed frame's visual index and the selection it belonged to.
|
|
7983
|
+
* Used when the subject/source changes or hydration retires the rows. */
|
|
7984
|
+
const clearVisualFrameState = () => {
|
|
7985
|
+
visualOrder = [];
|
|
7986
|
+
figureNodeIds = /* @__PURE__ */ new Map();
|
|
7987
|
+
visualTargets = /* @__PURE__ */ new Map();
|
|
7988
|
+
visualCopyButtons = /* @__PURE__ */ new Map();
|
|
7989
|
+
selectedVisual = void 0;
|
|
7990
|
+
};
|
|
7991
|
+
/**
|
|
7992
|
+
* PR3: the display-demand sender for one admitted Assistant-published SVG.
|
|
7993
|
+
* It calls the ONLY SVG blob sender and nothing else. A pane without
|
|
7994
|
+
* `image`+`blobs` never reaches it (the mapper draws no image node, and this
|
|
7995
|
+
* guard keeps the sender unreachable even if it did).
|
|
7996
|
+
*/
|
|
7997
|
+
const requestPublishedSvgBlob = (publication) => {
|
|
7998
|
+
if (!nativeImagesSupported()) return void 0;
|
|
7999
|
+
const source = publication.source.svgSource;
|
|
8000
|
+
const svg = publication.source.svg;
|
|
8001
|
+
if (source === void 0 || svg === void 0) return void 0;
|
|
8002
|
+
return sendSvgBlob(source, svg.digest);
|
|
8003
|
+
};
|
|
5316
8004
|
/** Rebuild the canonical transcript from the last projection (same scope and
|
|
5317
|
-
* source identity: a settled-answer repaint is NOT a new subject).
|
|
8005
|
+
* source identity: a settled-answer repaint is NOT a new subject).
|
|
8006
|
+
*
|
|
8007
|
+
* PR-B3: the hydration fence also guards this rebuild. While a NEW subject
|
|
8008
|
+
* is pending, the retired source's messages must not overwrite the
|
|
8009
|
+
* explicit Loading state — an answered-Question lookup that resolves
|
|
8010
|
+
* during that window would otherwise resurrect the old rows (and their old
|
|
8011
|
+
* Preparing rows) under the new subject's scope. */
|
|
5318
8012
|
const rebuildLastMain = () => {
|
|
5319
|
-
if (disposed) return;
|
|
5320
|
-
|
|
8013
|
+
if (disposed || hydrating) return true;
|
|
8014
|
+
if (imageProjectionAborted || visualProjectionAborted) return false;
|
|
8015
|
+
const imageStates = prepareImageStates();
|
|
8016
|
+
if (imageProjectionAborted) return false;
|
|
8017
|
+
const svgStates = prepareSvgStates();
|
|
8018
|
+
if (visualProjectionAborted) return false;
|
|
8019
|
+
const figureSources = visualFigureSources();
|
|
8020
|
+
const build = (selection) => transcriptView(projectTranscriptStructure(lastMessages), scopeKeys, {
|
|
5321
8021
|
...options.cwd === void 0 ? {} : { cwd: options.cwd },
|
|
5322
8022
|
scopePrefix,
|
|
5323
|
-
...settledQuestionAnswers === void 0 ? {} : { settledQuestionAnswersLookup: settledQuestionAnswers }
|
|
8023
|
+
...settledQuestionAnswers === void 0 ? {} : { settledQuestionAnswersLookup: settledQuestionAnswers },
|
|
8024
|
+
...options.toolPresenter === void 0 ? {} : { toolPresenter: options.toolPresenter },
|
|
8025
|
+
preparingPreviews: lastStreamingToolPreviews,
|
|
8026
|
+
chartKindsSupported: session.caps.kinds.includes("chart"),
|
|
8027
|
+
...svgStates === void 0 ? {} : { toolSvgStates: svgStates },
|
|
8028
|
+
expandedToolKeys,
|
|
8029
|
+
imageStates,
|
|
8030
|
+
nativeImagesSupported: nativeImagesSupported(),
|
|
8031
|
+
requestPublishedSvgBlob,
|
|
8032
|
+
...selection === void 0 ? {} : { selectedVisual: selection }
|
|
5324
8033
|
});
|
|
8034
|
+
let selection = selectedVisual;
|
|
8035
|
+
lastMain = build(selection);
|
|
8036
|
+
let frame = indexVisualFrame(lastMain, figureSources);
|
|
8037
|
+
const reconciled = reconcileVisualSelection(selection, frame);
|
|
8038
|
+
if (!sameSelectedVisual(selection, reconciled)) {
|
|
8039
|
+
selection = reconciled;
|
|
8040
|
+
lastMain = build(selection);
|
|
8041
|
+
frame = indexVisualFrame(lastMain, figureSources);
|
|
8042
|
+
}
|
|
8043
|
+
selectedVisual = reconciled;
|
|
8044
|
+
visualOrder = frame.order;
|
|
8045
|
+
figureNodeIds = frame.nodeIds;
|
|
8046
|
+
visualTargets = frame.targets;
|
|
8047
|
+
visualCopyButtons = frame.copyButtons;
|
|
8048
|
+
toolDisclosureByPath.clear();
|
|
8049
|
+
const recordDisclosures = (node, path, parentTool) => {
|
|
8050
|
+
const nodeKey = node.props.key;
|
|
8051
|
+
let tool = parentTool;
|
|
8052
|
+
if (node.kind === "tool" && nodeKey !== void 0) {
|
|
8053
|
+
tool = (nodeKey.startsWith(`${scopePrefix}msg-`) ? nodeKey.slice(scopePrefix.length) : nodeKey.startsWith("msg-") ? nodeKey : void 0) ?? (parentTool !== void 0 ? `${parentTool}/${nodeKey}` : void 0);
|
|
8054
|
+
if (tool !== void 0) toolDisclosureByPath.set(path, tool);
|
|
8055
|
+
}
|
|
8056
|
+
for (const [index, child] of node.children.entries()) {
|
|
8057
|
+
const childKey = child.props.key;
|
|
8058
|
+
recordDisclosures(child, path === "" ? childKey ?? String(index) : `${path}.${childKey ?? String(index)}`, tool);
|
|
8059
|
+
}
|
|
8060
|
+
};
|
|
8061
|
+
recordDisclosures(lastMain, "", void 0);
|
|
8062
|
+
if (visualProjectionAborted) return false;
|
|
8063
|
+
return true;
|
|
8064
|
+
};
|
|
8065
|
+
/**
|
|
8066
|
+
* PR4: the dock's draft-image rows, built at render time from the LIVE
|
|
8067
|
+
* projection (never a retained list) plus the state prepared just above.
|
|
8068
|
+
*
|
|
8069
|
+
* This function only maps already-prepared facts onto the ONE pure
|
|
8070
|
+
* {@link dockDraftImageNodes} projection — it reads no bytes, sends no blob
|
|
8071
|
+
* and consults no store, so the dock's node shape is testable without a
|
|
8072
|
+
* session and cannot drift from the transcript's image vocabulary.
|
|
8073
|
+
*/
|
|
8074
|
+
/**
|
|
8075
|
+
* The frozen preview-count decision (Owner amendment, 2026-10-25). It reads
|
|
8076
|
+
* the NEGOTIATED capabilities and `cols` only — never a terminal height, never
|
|
8077
|
+
* `process.stdout.rows`, never a CSS guess about pane geometry:
|
|
8078
|
+
*
|
|
8079
|
+
* - no `styles`, or no `image`/`blobs`: 0 (the sheet is the only short-window
|
|
8080
|
+
* mechanism, and a bitmap needs the image+blob capability);
|
|
8081
|
+
* - `cols < 72`: 0; `72 … 99`: 1; `>= 100`: 2.
|
|
8082
|
+
*
|
|
8083
|
+
* Any other count would have to infer pane rows, which the protocol does not
|
|
8084
|
+
* publish.
|
|
8085
|
+
*/
|
|
8086
|
+
const dockPreviewLimit = () => {
|
|
8087
|
+
if (!(previewStylesSupported() && session.caps.features.includes("blobs") && session.caps.kinds.includes("image"))) return 0;
|
|
8088
|
+
const cols = session.caps.cols;
|
|
8089
|
+
return cols < 72 ? 0 : cols < 100 ? 1 : 2;
|
|
8090
|
+
};
|
|
8091
|
+
const dockDraftNodes = (states) => {
|
|
8092
|
+
const binding = imageBinding;
|
|
8093
|
+
if (binding === void 0 || states === void 0) return void 0;
|
|
8094
|
+
return dockDraftImageNodes(binding.draftImages.occurrences().map((occurrence) => {
|
|
8095
|
+
const identity = draftIdentityOf(occurrence.image);
|
|
8096
|
+
return {
|
|
8097
|
+
id: occurrence.image.id,
|
|
8098
|
+
ordinal: occurrence.ordinal,
|
|
8099
|
+
caption: `#${occurrence.image.id} · ${identity.width}×${identity.height}`,
|
|
8100
|
+
name: imageDisplayName(identity),
|
|
8101
|
+
state: states.get(draftOccurrenceKey(occurrence))
|
|
8102
|
+
};
|
|
8103
|
+
}), dockPreviewLimit());
|
|
5325
8104
|
};
|
|
5326
|
-
const dockView = () => {
|
|
8105
|
+
const dockView = (draftStates) => {
|
|
5327
8106
|
const lines = [];
|
|
5328
8107
|
for (const facts of dock.welcome) {
|
|
5329
8108
|
const model = facts.model === void 0 ? "" : ` · ${facts.model}`;
|
|
@@ -5348,14 +8127,29 @@ function mountTspRenderer(session, options) {
|
|
|
5348
8127
|
key: "pending-submit",
|
|
5349
8128
|
text: pendingSubmit === "submit" ? "Submitting…" : "Queued…"
|
|
5350
8129
|
}));
|
|
5351
|
-
|
|
8130
|
+
const draftCount = imageBinding?.draftImages.occurrences().length ?? 0;
|
|
8131
|
+
const statusLine = draftCount === 0 ? dock.statusLine : `Draft ${draftCount} · ${dock.statusLine === "" ? DOCK_BANNER : dock.statusLine}`;
|
|
8132
|
+
if (statusLine !== "") lines.push(ui.text({
|
|
5352
8133
|
key: "status",
|
|
5353
|
-
|
|
8134
|
+
wrap: "none",
|
|
8135
|
+
text: sanitizedPhysicalLine(statusLine)
|
|
5354
8136
|
}));
|
|
5355
8137
|
if (seat.attentionCount() > 0) lines.push(ui.text({
|
|
5356
8138
|
key: "question-attention",
|
|
5357
8139
|
text: `Continued questions: ${seat.attentionCount()} · ${TSP_CONTINUED_INSPECTION_LABEL}`
|
|
5358
8140
|
}));
|
|
8141
|
+
if (visualOrder.length > 0) {
|
|
8142
|
+
const selection = selectedVisual;
|
|
8143
|
+
const selectedTarget = selection === void 0 ? void 0 : visualTargets.get(selection.ref);
|
|
8144
|
+
if (selection !== void 0 && selectedTarget !== void 0) lines.push(ui.text({
|
|
8145
|
+
key: "visual-selected",
|
|
8146
|
+
text: sanitizeDisplayText(`Selected ${selection.index}/${selection.count} · ${publishedVisualTitle(selectedTarget.publication)}`)
|
|
8147
|
+
}));
|
|
8148
|
+
lines.push(ui.text({
|
|
8149
|
+
key: "visual-actions",
|
|
8150
|
+
text: `${TSP_VISUAL_SELECT_LABEL} select visual · ${TSP_VISUAL_COPY_LABEL} copy`
|
|
8151
|
+
}));
|
|
8152
|
+
}
|
|
5359
8153
|
for (const notice of dock.notices) {
|
|
5360
8154
|
const noticeText = sanitizeDisplayText(notice.text);
|
|
5361
8155
|
lines.push(ui.text({
|
|
@@ -5363,6 +8157,8 @@ function mountTspRenderer(session, options) {
|
|
|
5363
8157
|
text: notice.kind === "error" ? `! ${noticeText}` : noticeText
|
|
5364
8158
|
}));
|
|
5365
8159
|
}
|
|
8160
|
+
const preview = dockDraftNodes(draftStates);
|
|
8161
|
+
if (preview !== void 0) lines.push(preview);
|
|
5366
8162
|
lines.push(ui.editor({
|
|
5367
8163
|
key: "composer",
|
|
5368
8164
|
text: composer.state().text,
|
|
@@ -5377,7 +8173,7 @@ function mountTspRenderer(session, options) {
|
|
|
5377
8173
|
key: "loading",
|
|
5378
8174
|
text: "Loading session…"
|
|
5379
8175
|
}));
|
|
5380
|
-
const setTranscript = (messages, _activities, _window,
|
|
8176
|
+
const setTranscript = (messages, _activities, _window, streamingToolPreviews, _searchPresentation, source) => {
|
|
5381
8177
|
if (disposed) return;
|
|
5382
8178
|
if (retiredSource !== void 0 && source === retiredSource) return;
|
|
5383
8179
|
if (source !== void 0 && source !== projectionScope) {
|
|
@@ -5387,9 +8183,16 @@ function mountTspRenderer(session, options) {
|
|
|
5387
8183
|
scopeEpoch += 1;
|
|
5388
8184
|
scopePrefix = `s${scopeEpoch}-`;
|
|
5389
8185
|
scopeKeys = new TranscriptNodeKeys();
|
|
8186
|
+
releaseImageSubscriptions();
|
|
8187
|
+
svgBlobIds.clear();
|
|
8188
|
+
expandedToolKeys.clear();
|
|
8189
|
+
clearVisualFrameState();
|
|
8190
|
+
activeImageScope = imageBinding?.imageScope();
|
|
5390
8191
|
}
|
|
5391
8192
|
lastMessages = messages;
|
|
5392
|
-
|
|
8193
|
+
lastStreamingToolPreviews = streamingToolPreviews ?? [];
|
|
8194
|
+
syncImageSubscriptions();
|
|
8195
|
+
if (!rebuildLastMain()) return;
|
|
5393
8196
|
render();
|
|
5394
8197
|
};
|
|
5395
8198
|
/** Mutable renderer-local mirror of the last committed status facts. */
|
|
@@ -5426,12 +8229,17 @@ function mountTspRenderer(session, options) {
|
|
|
5426
8229
|
},
|
|
5427
8230
|
beginSessionHydration() {
|
|
5428
8231
|
if (disposed) return;
|
|
8232
|
+
retireWorkDetails("session-change");
|
|
5429
8233
|
sessionBrowser?.retire();
|
|
5430
8234
|
modelPicker?.retire();
|
|
5431
8235
|
presetPicker?.retire();
|
|
8236
|
+
workHub?.retire();
|
|
5432
8237
|
seat.closeTransientList();
|
|
5433
8238
|
hydrating = true;
|
|
5434
8239
|
retiredSource = projectionScope;
|
|
8240
|
+
releaseImageSubscriptions();
|
|
8241
|
+
clearVisualFrameState();
|
|
8242
|
+
lastStreamingToolPreviews = [];
|
|
5435
8243
|
lastMain = loadingMain();
|
|
5436
8244
|
render();
|
|
5437
8245
|
},
|
|
@@ -5487,7 +8295,9 @@ function mountTspRenderer(session, options) {
|
|
|
5487
8295
|
},
|
|
5488
8296
|
getSessionTitle: () => statusFacts.sessionTitle ?? "",
|
|
5489
8297
|
getViewerGeneration: () => viewerGeneration,
|
|
5490
|
-
supportsTaskCenter
|
|
8298
|
+
get supportsTaskCenter() {
|
|
8299
|
+
return !disposed && taskCenterCapabilitiesNegotiated();
|
|
8300
|
+
},
|
|
5491
8301
|
supportsViewer: false,
|
|
5492
8302
|
get supportsModals() {
|
|
5493
8303
|
return boundHandlers !== void 0;
|
|
@@ -5516,7 +8326,126 @@ function mountTspRenderer(session, options) {
|
|
|
5516
8326
|
if (boundHandlers !== void 0) boundHandlers.exit();
|
|
5517
8327
|
else options.requestExit();
|
|
5518
8328
|
};
|
|
8329
|
+
/**
|
|
8330
|
+
* PR3: the ONE admission predicate of the visual chords and figure Copy
|
|
8331
|
+
* actions. A modal seat, the temporary Reader, or any open native presenter
|
|
8332
|
+
* owns the seat; the hydration window and an unbound/pre-dispose renderer
|
|
8333
|
+
* refuse too, so a hidden base surface never acts behind another owner.
|
|
8334
|
+
*/
|
|
8335
|
+
const visualActionsAdmitted = () => {
|
|
8336
|
+
if (disposed || hydrating || !inputBound) return false;
|
|
8337
|
+
if (seat.hasModalSeat()) return false;
|
|
8338
|
+
if (detailsSlot !== void 0 || openingDetails) return false;
|
|
8339
|
+
if (workHub?.isOpen() === true || sessionBrowser?.isOpen() === true || presetPicker?.isOpen() === true || modelPicker?.isOpen() === true) return false;
|
|
8340
|
+
return true;
|
|
8341
|
+
};
|
|
8342
|
+
/** The EXACT payload of one admitted publication: the final ChartFact as
|
|
8343
|
+
* pretty JSON, or the admitted SVG source verbatim (never trimmed). */
|
|
8344
|
+
const visualCopyPayload = (publication) => {
|
|
8345
|
+
if (publication.source.chart !== void 0) return JSON.stringify(publication.source.chart, null, 2);
|
|
8346
|
+
return publication.source.svgSource;
|
|
8347
|
+
};
|
|
8348
|
+
/** The user-visible noun of one copy outcome. */
|
|
8349
|
+
const visualCopyKind = (publication) => publication.source.chart !== void 0 ? "chart data" : "SVG source";
|
|
8350
|
+
/**
|
|
8351
|
+
* PR3: one admitted visual Copy. The payload is snapshotted at admission
|
|
8352
|
+
* time, so the write can never pick up a later subject's figure. The
|
|
8353
|
+
* synchronous admission is complete before the async clipboard write starts;
|
|
8354
|
+
* the settlement notifies the dock ONLY while the exact subject, row and
|
|
8355
|
+
* publication are still current — an in-flight copy for an older subject may
|
|
8356
|
+
* finish in the OS, but it never writes a success notice onto the new one.
|
|
8357
|
+
*/
|
|
8358
|
+
const issueVisualCopy = (target) => {
|
|
8359
|
+
if (!visualActionsAdmitted()) return;
|
|
8360
|
+
const payload = visualCopyPayload(target.publication);
|
|
8361
|
+
if (payload === void 0) return;
|
|
8362
|
+
const kind = visualCopyKind(target.publication);
|
|
8363
|
+
const isStillCurrent = () => {
|
|
8364
|
+
if (disposed || hydrating) return false;
|
|
8365
|
+
if (target.source !== projectionScope || target.scopePrefix !== scopePrefix) return false;
|
|
8366
|
+
if (!lastMessages.includes(target.message)) return false;
|
|
8367
|
+
const current = assistantVisualPresentation(target.message);
|
|
8368
|
+
return current !== void 0 && current.publications.includes(target.publication);
|
|
8369
|
+
};
|
|
8370
|
+
let task;
|
|
8371
|
+
try {
|
|
8372
|
+
task = options.copyVisual(payload);
|
|
8373
|
+
} catch (error) {
|
|
8374
|
+
options.logError?.("tsp renderer: visual copy failed", {
|
|
8375
|
+
kind,
|
|
8376
|
+
error: errorText(error)
|
|
8377
|
+
});
|
|
8378
|
+
try {
|
|
8379
|
+
display.notify(`Failed to copy ${kind}`, "error");
|
|
8380
|
+
} catch (failure) {
|
|
8381
|
+
routeFatal(failure);
|
|
8382
|
+
}
|
|
8383
|
+
return;
|
|
8384
|
+
}
|
|
8385
|
+
task.then((copied) => {
|
|
8386
|
+
if (!isStillCurrent()) return;
|
|
8387
|
+
try {
|
|
8388
|
+
display.notify(copied ? `Copied ${kind}` : `Failed to copy ${kind}`, copied ? "info" : "error");
|
|
8389
|
+
} catch (error) {
|
|
8390
|
+
routeFatal(error);
|
|
8391
|
+
}
|
|
8392
|
+
}, (error) => {
|
|
8393
|
+
options.logError?.("tsp renderer: visual copy failed", {
|
|
8394
|
+
kind,
|
|
8395
|
+
error: errorText(error)
|
|
8396
|
+
});
|
|
8397
|
+
if (!isStillCurrent()) return;
|
|
8398
|
+
try {
|
|
8399
|
+
display.notify(`Failed to copy ${kind}`, "error");
|
|
8400
|
+
} catch (failure) {
|
|
8401
|
+
routeFatal(failure);
|
|
8402
|
+
}
|
|
8403
|
+
});
|
|
8404
|
+
};
|
|
8405
|
+
/**
|
|
8406
|
+
* PR3 Alt+V: select the next figure of the CURRENT committed frame (wrap to
|
|
8407
|
+
* the first), repaint the selection badge, then reveal the figure through the
|
|
8408
|
+
* existing main-surface scroll. No selection exists before the first press.
|
|
8409
|
+
*/
|
|
8410
|
+
const selectNextVisual = () => {
|
|
8411
|
+
if (!visualActionsAdmitted()) return;
|
|
8412
|
+
const order = visualOrder;
|
|
8413
|
+
if (order.length === 0) return;
|
|
8414
|
+
const current = selectedVisual;
|
|
8415
|
+
const position = current === void 0 ? 0 : (order.indexOf(current.ref) + 1) % order.length;
|
|
8416
|
+
const ref = order[position];
|
|
8417
|
+
if (ref === void 0) return;
|
|
8418
|
+
selectedVisual = {
|
|
8419
|
+
ref,
|
|
8420
|
+
index: position + 1,
|
|
8421
|
+
count: order.length
|
|
8422
|
+
};
|
|
8423
|
+
if (!rebuildLastMain()) return;
|
|
8424
|
+
render();
|
|
8425
|
+
const nodeId = figureNodeIds.get(ref);
|
|
8426
|
+
if (nodeId !== void 0) surface.reveal(nodeId, "nearest");
|
|
8427
|
+
};
|
|
8428
|
+
/** PR3 Alt+C: copy the CURRENT selection; never guess "the last figure". */
|
|
8429
|
+
const copySelectedVisual = () => {
|
|
8430
|
+
if (!visualActionsAdmitted()) return;
|
|
8431
|
+
const current = selectedVisual;
|
|
8432
|
+
const target = current === void 0 ? void 0 : visualTargets.get(current.ref);
|
|
8433
|
+
if (target === void 0) {
|
|
8434
|
+
selectedVisual = void 0;
|
|
8435
|
+
display.notify(`${TSP_VISUAL_SELECT_LABEL} to select a visual`, "info");
|
|
8436
|
+
return;
|
|
8437
|
+
}
|
|
8438
|
+
issueVisualCopy(target);
|
|
8439
|
+
};
|
|
5519
8440
|
const dispatchKey = (key, handlers) => {
|
|
8441
|
+
const details = detailsSlot;
|
|
8442
|
+
if (details !== void 0) {
|
|
8443
|
+
if (details.phase === "closing") return false;
|
|
8444
|
+
if (!seat.hasModalSeat()) {
|
|
8445
|
+
handleDetailsKey(details, key);
|
|
8446
|
+
return false;
|
|
8447
|
+
}
|
|
8448
|
+
}
|
|
5520
8449
|
if (seat.hasModalSeat()) {
|
|
5521
8450
|
seat.handleKey(key, handlers);
|
|
5522
8451
|
return false;
|
|
@@ -5529,6 +8458,7 @@ function mountTspRenderer(session, options) {
|
|
|
5529
8458
|
handlers.cancel();
|
|
5530
8459
|
return false;
|
|
5531
8460
|
}
|
|
8461
|
+
if (workHub?.handleKey(key)) return false;
|
|
5532
8462
|
if (sessionBrowser?.handleKey(key)) return false;
|
|
5533
8463
|
if (presetPicker?.handleKey(key)) return false;
|
|
5534
8464
|
if (modelPicker?.handleKey(key)) return false;
|
|
@@ -5536,6 +8466,19 @@ function mountTspRenderer(session, options) {
|
|
|
5536
8466
|
handlers.cancel();
|
|
5537
8467
|
return false;
|
|
5538
8468
|
}
|
|
8469
|
+
if (matchesKeyId(key, TSP_VISUAL_CHORDS.select)) {
|
|
8470
|
+
selectNextVisual();
|
|
8471
|
+
return false;
|
|
8472
|
+
}
|
|
8473
|
+
if (matchesKeyId(key, TSP_VISUAL_CHORDS.copy)) {
|
|
8474
|
+
copySelectedVisual();
|
|
8475
|
+
return false;
|
|
8476
|
+
}
|
|
8477
|
+
if (key.name === "v" && key.ctrl === true && key.alt !== true && key.meta !== true && key.shift !== true) {
|
|
8478
|
+
handlers.noteUserInput();
|
|
8479
|
+
handlers.pasteMedia();
|
|
8480
|
+
return false;
|
|
8481
|
+
}
|
|
5539
8482
|
const edit = composer.applyKey(key);
|
|
5540
8483
|
if (edit.kind === "submit") {
|
|
5541
8484
|
handlers.noteUserInput();
|
|
@@ -5567,27 +8510,64 @@ function mountTspRenderer(session, options) {
|
|
|
5567
8510
|
const routeInput = (input) => {
|
|
5568
8511
|
if (input.type === "event") {
|
|
5569
8512
|
if (input.event.ev === "error") {
|
|
5570
|
-
|
|
8513
|
+
const detailsSurfaceId = detailsSlot?.surface.id;
|
|
8514
|
+
if (input.event.sf === void 0 || input.event.sf === surface.id || input.event.sf === detailsSurfaceId) options.logError?.("tsp renderer: client rejected protocol operation", {
|
|
5571
8515
|
...input.event.sf === void 0 ? {} : { sf: input.event.sf },
|
|
8516
|
+
...input.event.sf !== void 0 && input.event.sf === detailsSurfaceId ? { origin: "work-details" } : {},
|
|
5572
8517
|
...input.event.s === void 0 ? {} : { s: input.event.s },
|
|
5573
8518
|
...input.event.op === void 0 ? {} : { op: input.event.op },
|
|
5574
8519
|
msg: input.event.msg
|
|
5575
8520
|
});
|
|
5576
8521
|
return false;
|
|
5577
8522
|
}
|
|
8523
|
+
const details = detailsSlot;
|
|
8524
|
+
if (details !== void 0) {
|
|
8525
|
+
if (input.event.ev === "resize" && input.event.sf === details.surface.id) {
|
|
8526
|
+
syncWorkDetails();
|
|
8527
|
+
return false;
|
|
8528
|
+
}
|
|
8529
|
+
if (details.phase === "open" && handleDetailsEvent(input.event)) return false;
|
|
8530
|
+
if ("sf" in input.event && input.event.sf === details.surface.id) return false;
|
|
8531
|
+
if (input.event.ev === "focus" || input.event.ev === "edit" || input.event.ev === "undo" || input.event.ev === "send" || input.event.ev === "toggle" || input.event.ev === "select" || input.event.ev === "activate" || input.event.ev === "action") return false;
|
|
8532
|
+
}
|
|
8533
|
+
if (input.event.ev === "toggle" && input.event.sf === surface.id) {
|
|
8534
|
+
let disclosure;
|
|
8535
|
+
let matched = -1;
|
|
8536
|
+
for (const [path, value] of toolDisclosureByPath) if (path.length > matched && (input.event.id === path || input.event.id.endsWith(`.${path}`))) {
|
|
8537
|
+
disclosure = value;
|
|
8538
|
+
matched = path.length;
|
|
8539
|
+
}
|
|
8540
|
+
if (disclosure === void 0) return false;
|
|
8541
|
+
if (input.event.collapsed) expandedToolKeys.delete(disclosure);
|
|
8542
|
+
else expandedToolKeys.add(disclosure);
|
|
8543
|
+
if (rebuildLastMain()) render();
|
|
8544
|
+
return false;
|
|
8545
|
+
}
|
|
5578
8546
|
if (input.event.ev === "resize" && input.event.sf === surface.id && typeof input.event.cols === "number") {
|
|
5579
8547
|
modelPicker?.resize(input.event.cols, session.caps.cell.w);
|
|
5580
8548
|
render();
|
|
5581
8549
|
}
|
|
8550
|
+
if (input.event.ev === "resize" && detailsSlot !== void 0 && input.event.sf === detailsSlot.surface.id) {
|
|
8551
|
+
syncWorkDetails();
|
|
8552
|
+
return false;
|
|
8553
|
+
}
|
|
5582
8554
|
if (seat.hasModalSeat()) {
|
|
5583
8555
|
if (seat.handleEvent(input.event)) applyFocus(true);
|
|
5584
8556
|
return false;
|
|
5585
8557
|
}
|
|
5586
8558
|
if (!hydrating && inputBound && "sf" in input.event && input.event.sf === surface.id) {
|
|
8559
|
+
if (workHub?.handleEvent(input.event)) return false;
|
|
5587
8560
|
if (sessionBrowser?.handleEvent(input.event)) return false;
|
|
5588
8561
|
if (presetPicker?.handleEvent(input.event)) return false;
|
|
5589
8562
|
if (modelPicker?.handleEvent(input.event)) return false;
|
|
5590
|
-
if (
|
|
8563
|
+
if (input.event.ev === "action" && input.event.act === "dsh-visual-copy") {
|
|
8564
|
+
if (visualActionsAdmitted()) {
|
|
8565
|
+
const target = visualCopyButtons.get(input.event.id);
|
|
8566
|
+
if (target !== void 0) issueVisualCopy(target);
|
|
8567
|
+
}
|
|
8568
|
+
return false;
|
|
8569
|
+
}
|
|
8570
|
+
if ((workHub?.isOpen() === true || sessionBrowser?.isOpen() === true || presetPicker?.isOpen() === true || modelPicker?.isOpen() === true) && input.event.ev === "focus") applyFocus(true);
|
|
5591
8571
|
}
|
|
5592
8572
|
return false;
|
|
5593
8573
|
}
|
|
@@ -5650,6 +8630,13 @@ function mountTspRenderer(session, options) {
|
|
|
5650
8630
|
},
|
|
5651
8631
|
composer,
|
|
5652
8632
|
interaction: seat.presenter,
|
|
8633
|
+
taskPresentation,
|
|
8634
|
+
bindImages: (binding) => {
|
|
8635
|
+
if (disposed) throw new Error("the TSP renderer is disposed");
|
|
8636
|
+
if (imageBindingInstalled) throw new Error("the TSP renderer image binding is already installed");
|
|
8637
|
+
imageBindingInstalled = true;
|
|
8638
|
+
imageBinding = binding;
|
|
8639
|
+
},
|
|
5653
8640
|
bindInput: (handlers) => {
|
|
5654
8641
|
if (disposed) throw new Error("the TSP renderer is disposed");
|
|
5655
8642
|
if (inputBound) throw new Error("the TSP renderer input is already bound");
|
|
@@ -5662,29 +8649,90 @@ function mountTspRenderer(session, options) {
|
|
|
5662
8649
|
if (dispatchKey(key, handlers)) routeExit(true);
|
|
5663
8650
|
}
|
|
5664
8651
|
},
|
|
5665
|
-
dispose:
|
|
5666
|
-
if (
|
|
8652
|
+
dispose: () => {
|
|
8653
|
+
if (disposeTask !== void 0) return disposeTask;
|
|
5667
8654
|
disposed = true;
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
modelPicker?.retire();
|
|
5671
|
-
presetPicker?.retire();
|
|
8655
|
+
const disposal = Promise.withResolvers();
|
|
8656
|
+
disposeTask = disposal.promise;
|
|
5672
8657
|
const failures = [];
|
|
8658
|
+
let detailsClose;
|
|
5673
8659
|
try {
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
8660
|
+
runSyncDisposalSteps("TSP renderer synchronous disposal", [
|
|
8661
|
+
() => {
|
|
8662
|
+
detailsClose = retireWorkDetails("dispose");
|
|
8663
|
+
},
|
|
8664
|
+
() => {
|
|
8665
|
+
releaseImageSubscriptions();
|
|
8666
|
+
},
|
|
8667
|
+
() => {
|
|
8668
|
+
seat.dispose();
|
|
8669
|
+
},
|
|
8670
|
+
() => {
|
|
8671
|
+
workHub?.retire();
|
|
8672
|
+
},
|
|
8673
|
+
() => {
|
|
8674
|
+
sessionBrowser?.retire();
|
|
8675
|
+
},
|
|
8676
|
+
() => {
|
|
8677
|
+
modelPicker?.retire();
|
|
8678
|
+
},
|
|
8679
|
+
() => {
|
|
8680
|
+
presetPicker?.retire();
|
|
8681
|
+
}
|
|
8682
|
+
]);
|
|
5680
8683
|
} catch (error) {
|
|
5681
8684
|
failures.push(error);
|
|
5682
8685
|
}
|
|
5683
|
-
|
|
5684
|
-
|
|
8686
|
+
(async () => {
|
|
8687
|
+
if (detailsClose !== void 0) try {
|
|
8688
|
+
await detailsClose;
|
|
8689
|
+
} catch (error) {
|
|
8690
|
+
failures.push(error);
|
|
8691
|
+
}
|
|
8692
|
+
try {
|
|
8693
|
+
await surface.close({ keep: false });
|
|
8694
|
+
} catch (error) {
|
|
8695
|
+
failures.push(error);
|
|
8696
|
+
}
|
|
8697
|
+
try {
|
|
8698
|
+
await session.close();
|
|
8699
|
+
} catch (error) {
|
|
8700
|
+
failures.push(error);
|
|
8701
|
+
}
|
|
8702
|
+
if (failures.length === 0) disposal.resolve();
|
|
8703
|
+
else if (failures.length === 1) disposal.reject(failures[0]);
|
|
8704
|
+
else disposal.reject(new AggregateError(failures, "TSP renderer disposal"));
|
|
8705
|
+
})();
|
|
8706
|
+
return disposeTask;
|
|
5685
8707
|
}
|
|
5686
8708
|
};
|
|
5687
8709
|
}
|
|
8710
|
+
/**
|
|
8711
|
+
* PR4: the render-state key of ONE draft occurrence. The draft id alone is not
|
|
8712
|
+
* enough — the SAME image can appear under two tokens — so the occurrence's
|
|
8713
|
+
* own text rank is part of the identity, matching the node key the dock builds.
|
|
8714
|
+
*/
|
|
8715
|
+
function draftOccurrenceKey(occurrence) {
|
|
8716
|
+
return `draft-image-${occurrence.image.id}-${occurrence.ordinal}`;
|
|
8717
|
+
}
|
|
8718
|
+
/**
|
|
8719
|
+
* PR4: the attachment-shaped identity of one staged draft. A LOCAL draft keeps
|
|
8720
|
+
* its own metadata; a RECALLED draft's durable ref is the authority for the
|
|
8721
|
+
* same fields (its local bytes are empty by contract). `bytes` is the recorded
|
|
8722
|
+
* byte length, never a send permit.
|
|
8723
|
+
*/
|
|
8724
|
+
function draftIdentityOf(image) {
|
|
8725
|
+
const source = image.source.type === "recalled" && image.recalledRef !== void 0 ? image.recalledRef : void 0;
|
|
8726
|
+
const name = source?.name ?? image.name;
|
|
8727
|
+
return {
|
|
8728
|
+
attachmentId: source?.attachmentId ?? `draft-${image.id}`,
|
|
8729
|
+
mediaType: source?.mediaType ?? image.mediaType,
|
|
8730
|
+
bytes: source?.bytes ?? image.byteLength,
|
|
8731
|
+
width: source?.width ?? image.width,
|
|
8732
|
+
height: source?.height ?? image.height,
|
|
8733
|
+
...name === void 0 ? {} : { name }
|
|
8734
|
+
};
|
|
8735
|
+
}
|
|
5688
8736
|
/** One pending-tail row as a single dock line (the join already ordered and
|
|
5689
8737
|
* classified it; the renderer only presents the row's own DTO fields and
|
|
5690
8738
|
* keeps the non-user Context identity distinct). */
|