@xmoon76/dsh-pi-tui 0.5.4 → 0.5.6
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 +46 -42
- package/README.md +46 -27
- package/cordis.patch.yml +77 -7
- package/dist/bootstrap-DQ4YPL-7.mjs +113583 -0
- package/dist/builtins.mjs +3 -9
- package/dist/{runtime-vc4mdr-R.mjs → client-bootstrap-Cr1JCaF5.mjs} +3670 -2277
- package/dist/disposal-BYBbEpVY.mjs +54 -0
- package/dist/dist-CIsR7cz4.mjs +15717 -0
- package/dist/{entry-control-DvSrndWd.mjs → entry-control-DnduyDiw.mjs} +12 -31
- package/dist/{extensions-CcuMY4n2.mjs → extensions-Bp0L37lP.mjs} +1239 -271
- package/dist/extensions.mjs +1 -1
- package/dist/host-bootstrap-DilsvA6f.mjs +281 -0
- package/dist/host-foundation-probe--5jtvHVe.mjs +413 -0
- package/dist/host-runtime.d.mts +30 -0
- package/dist/host-runtime.mjs +1317 -0
- package/dist/index.d.mts +19 -18
- package/dist/index.mjs +18410 -8836
- package/dist/local-client.mjs +2027 -187
- package/dist/local-discovery-C9VMjc0K.mjs +759 -0
- package/dist/local-discovery-CDaQHA_R.mjs +2 -0
- package/dist/local-host.mjs +1088 -87
- package/dist/local-transport-BVwFYq_Y.mjs +513 -0
- package/dist/{context-summary-DAisTA_7.mjs → pasted-path-range-CMnxuGPx.mjs} +7613 -216
- package/dist/pasted-path-range-r6qzV_tC.mjs +17510 -0
- package/dist/performance-host.d.mts +2 -2
- package/dist/performance-host.mjs +258 -1
- package/dist/pi-tui-remote-contribution-B0EQsP0N.mjs +85 -0
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +70 -0
- package/dist/pi-tui-terminal-progress-contract-MLXZ-i3t.mjs +905 -0
- package/dist/pi-tui-web-access-contract-BN8Cc_Ho.mjs +118 -0
- package/dist/{runtime-status-0lp9CM0V.mjs → runtime-status-Cj1nFOdS.mjs} +72 -214
- package/dist/session-BKGXyh80.mjs +15794 -0
- package/dist/{session-tdJHLnJR.mjs → session-CPt_U8_f.mjs} +10707 -3657
- package/dist/{startup-JaVZoTIl.mjs → startup-7BYWuvBU.mjs} +124 -8
- package/dist/startup.d.mts +1 -1
- package/dist/startup.mjs +1 -1
- package/dist/{client-bootstrap-F5DHFI9t.mjs → terminal-progress-source-DrqQhtT8.mjs} +3653 -2969
- package/dist/visual-tools.d.mts +2 -2
- package/dist/visual-tools.mjs +26 -31
- package/dist/web-preferences.d.mts +29 -0
- package/dist/web-preferences.mjs +15 -0
- package/dist/web-roster-CjqnUXNk.mjs +285 -0
- package/generated/dsh-presets/cordis.patch.yml +5 -3
- package/generated/dsh-presets/ptc.patch.yml +7 -7
- package/generated/dsh-presets/standard.patch.yml +6 -4
- package/package.json +195 -172
- package/dist/host-bootstrap-DAgKknbY.mjs +0 -119
- package/dist/performance-host-CcDJjjVA.mjs +0 -266
- package/dist/rolldown-runtime-8H4AJuhK.mjs +0 -14
- package/dist/terminal-progress-source-xor3vakJ.mjs +0 -2256
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//#region src/runtime/remote/pi-tui-web-access-contract.ts
|
|
2
|
+
/** The wire namespace (and Host Cordis service key) of the toggle. */
|
|
3
|
+
const PI_TUI_WEB_ACCESS_NAMESPACE = "piTuiWebAccess";
|
|
4
|
+
/** The status method's stable endpoint identity. */
|
|
5
|
+
const PI_TUI_WEB_ACCESS_GET_STATUS_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiWebAccess/getStatus";
|
|
6
|
+
/** The mutation method's stable endpoint identity. */
|
|
7
|
+
const PI_TUI_WEB_ACCESS_SET_ENABLED_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiWebAccess/setEnabled";
|
|
8
|
+
/** The authenticated-URL method's stable endpoint identity. */
|
|
9
|
+
const PI_TUI_WEB_ACCESS_GET_AUTHENTICATED_URL_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiWebAccess/getAuthenticatedUrl";
|
|
10
|
+
/** One strict JSON codec that validates a wire boolean. */
|
|
11
|
+
const BOOLEAN_CODEC = {
|
|
12
|
+
mode: "strict",
|
|
13
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiWebAccess/setEnabled:enabled",
|
|
14
|
+
create: () => ({ parse: (value) => {
|
|
15
|
+
if (typeof value !== "boolean") throw new TypeError("piTuiWebAccess/setEnabled: the wire value must be a boolean");
|
|
16
|
+
return value;
|
|
17
|
+
} })
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Validate and detach one wire `PiTuiWebAccessStatus`. The status is produced by
|
|
21
|
+
* this package's own Host service, but it is still a wire boundary on the
|
|
22
|
+
* Client and the ONLY place the shape crosses.
|
|
23
|
+
*/
|
|
24
|
+
function parsePiTuiWebAccessStatus(value) {
|
|
25
|
+
if (typeof value !== "object" || value === null) throw new TypeError("piTuiWebAccess: the result must be an object");
|
|
26
|
+
const record = value;
|
|
27
|
+
const field = record.state === "unavailable" ? "reason" : void 0;
|
|
28
|
+
for (const key of Object.keys(record)) if (key !== "state" && key !== field) throw new TypeError(`piTuiWebAccess: unexpected result field ${JSON.stringify(key)}`);
|
|
29
|
+
if (record.state === "disabled" || record.state === "enabled" || record.state === "changing") return { state: record.state };
|
|
30
|
+
if (record.state !== "unavailable") throw new TypeError("piTuiWebAccess: the result state must be disabled, enabled, changing or unavailable");
|
|
31
|
+
if (typeof record.reason !== "string" || record.reason === "") throw new TypeError("piTuiWebAccess: an unavailable result needs a non-empty reason");
|
|
32
|
+
return {
|
|
33
|
+
state: "unavailable",
|
|
34
|
+
reason: record.reason
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const PI_TUI_WEB_ACCESS_STATUS_CODEC = {
|
|
38
|
+
mode: "strict",
|
|
39
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiWebAccess:status",
|
|
40
|
+
create: () => ({ parse: parsePiTuiWebAccessStatus }),
|
|
41
|
+
decode: parsePiTuiWebAccessStatus
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The `getStatus` invocation both contributions derive from. The Host
|
|
45
|
+
* registers this exact object; the Client mounts this exact object.
|
|
46
|
+
*/
|
|
47
|
+
const PI_TUI_WEB_ACCESS_GET_STATUS = {
|
|
48
|
+
id: PI_TUI_WEB_ACCESS_GET_STATUS_ENDPOINT,
|
|
49
|
+
service: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
50
|
+
namespace: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
51
|
+
method: "getStatus",
|
|
52
|
+
invocation: { kind: "direct" },
|
|
53
|
+
parameters: [],
|
|
54
|
+
result: PI_TUI_WEB_ACCESS_STATUS_CODEC
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The `setEnabled` invocation both contributions derive from. `enabled` is one
|
|
58
|
+
* required boolean: the Host Gateway decodes it through {@link BOOLEAN_CODEC},
|
|
59
|
+
* so a malformed value is refused at the wire boundary and never reaches the
|
|
60
|
+
* toggle.
|
|
61
|
+
*/
|
|
62
|
+
const PI_TUI_WEB_ACCESS_SET_ENABLED = {
|
|
63
|
+
id: PI_TUI_WEB_ACCESS_SET_ENABLED_ENDPOINT,
|
|
64
|
+
service: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
65
|
+
namespace: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
66
|
+
method: "setEnabled",
|
|
67
|
+
invocation: { kind: "direct" },
|
|
68
|
+
parameters: [{
|
|
69
|
+
name: "enabled",
|
|
70
|
+
wire: "enabled",
|
|
71
|
+
source: "json",
|
|
72
|
+
codec: BOOLEAN_CODEC
|
|
73
|
+
}],
|
|
74
|
+
result: PI_TUI_WEB_ACCESS_STATUS_CODEC
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Validate and detach one wire `PiTuiWebAccessAuthenticatedUrl`.
|
|
78
|
+
*
|
|
79
|
+
* It is the ONE place the token-carrying value crosses the wire, so the shape is
|
|
80
|
+
* parsed strictly: exactly one `url` field, a non-empty string, and an absolute
|
|
81
|
+
* `http(s)` URL. Nothing is normalized or rewritten — the Client opens/copies
|
|
82
|
+
* the official URL verbatim.
|
|
83
|
+
*/
|
|
84
|
+
function parsePiTuiWebAccessAuthenticatedUrl(value) {
|
|
85
|
+
if (typeof value !== "object" || value === null) throw new TypeError("piTuiWebAccess: the authenticated URL result must be an object");
|
|
86
|
+
const record = value;
|
|
87
|
+
for (const key of Object.keys(record)) if (key !== "url") throw new TypeError(`piTuiWebAccess: unexpected authenticated URL field ${JSON.stringify(key)}`);
|
|
88
|
+
if (typeof record.url !== "string" || record.url === "") throw new TypeError("piTuiWebAccess: the authenticated URL must be a non-empty string");
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = new URL(record.url);
|
|
92
|
+
} catch {
|
|
93
|
+
throw new TypeError("piTuiWebAccess: the authenticated URL must be an absolute URL");
|
|
94
|
+
}
|
|
95
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new TypeError("piTuiWebAccess: the authenticated URL must be an http(s) URL");
|
|
96
|
+
return { url: record.url };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The `getAuthenticatedUrl` invocation both contributions derive from: no
|
|
100
|
+
* parameters, one strict `{url}` result. The Host registers this exact object;
|
|
101
|
+
* the Client mounts this exact object.
|
|
102
|
+
*/
|
|
103
|
+
const PI_TUI_WEB_ACCESS_GET_AUTHENTICATED_URL = {
|
|
104
|
+
id: PI_TUI_WEB_ACCESS_GET_AUTHENTICATED_URL_ENDPOINT,
|
|
105
|
+
service: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
106
|
+
namespace: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
107
|
+
method: "getAuthenticatedUrl",
|
|
108
|
+
invocation: { kind: "direct" },
|
|
109
|
+
parameters: [],
|
|
110
|
+
result: {
|
|
111
|
+
mode: "strict",
|
|
112
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiWebAccess:authenticatedUrl",
|
|
113
|
+
create: () => ({ parse: parsePiTuiWebAccessAuthenticatedUrl }),
|
|
114
|
+
decode: parsePiTuiWebAccessAuthenticatedUrl
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
//#endregion
|
|
118
|
+
export { PI_TUI_WEB_ACCESS_SET_ENABLED as i, PI_TUI_WEB_ACCESS_GET_STATUS as n, PI_TUI_WEB_ACCESS_NAMESPACE as r, PI_TUI_WEB_ACCESS_GET_AUTHENTICATED_URL as t };
|
|
@@ -15,10 +15,10 @@ function isVisualToolName(name) {
|
|
|
15
15
|
/** Prefix of the durable publication receipt block. */
|
|
16
16
|
const VISUAL_PUBLISHED_PREFIX = "visual-published-v1:";
|
|
17
17
|
/** The one accepted reference spelling (lowercase hex, exactly 20 digits). */
|
|
18
|
-
const VISUAL_REFERENCE_PATTERN$1 = /^
|
|
18
|
+
const VISUAL_REFERENCE_PATTERN$1 = /^sv2_[0-9a-f]{20}$/u;
|
|
19
19
|
/** Parse exactly `<ref block>`; anything else is human text. */
|
|
20
20
|
function parseOfficialReferenceBlock(text) {
|
|
21
|
-
if (!text.startsWith("visual-ref-
|
|
21
|
+
if (!text.startsWith("visual-ref-v2:")) return void 0;
|
|
22
22
|
const ref = text.slice(14);
|
|
23
23
|
return VISUAL_REFERENCE_PATTERN$1.test(ref) ? ref : void 0;
|
|
24
24
|
}
|
|
@@ -170,7 +170,7 @@ function parseOfficialReceiptBlock(text) {
|
|
|
170
170
|
* Each tool has one canonical tail composition, and a result carries at most
|
|
171
171
|
* that composition:
|
|
172
172
|
*
|
|
173
|
-
* - a generator: optionally one `visual-ref-
|
|
173
|
+
* - a generator: optionally one `visual-ref-v2` block immediately followed by
|
|
174
174
|
* one `visual-v1` fact block of the MATCHING type, or the fact block alone
|
|
175
175
|
* (the reference is only projected for a root call inside an open step);
|
|
176
176
|
* - the publication tool: one `visual-published-v1` receipt block.
|
|
@@ -1071,39 +1071,42 @@ function resultFact(blocks) {
|
|
|
1071
1071
|
//#endregion
|
|
1072
1072
|
//#region src/domain/visual/reference.ts
|
|
1073
1073
|
/**
|
|
1074
|
-
* The stable, model-visible visual reference (`
|
|
1075
|
-
*
|
|
1074
|
+
* The stable, model-visible visual reference (`sv2_…`) and the machine block
|
|
1075
|
+
* that carries it.
|
|
1076
1076
|
*
|
|
1077
1077
|
* A reference names ONE generating visual tool result. It is derived from the
|
|
1078
|
-
* exact official identity tuple —
|
|
1078
|
+
* exact official identity tuple — turn, the ABSOLUTE seq of the open
|
|
1079
1079
|
* `step/start`, and the model's `tool/call` id — so the same figure produced
|
|
1080
|
-
* twice is two references, while a replayed log derives the
|
|
1081
|
-
* The
|
|
1082
|
-
*
|
|
1080
|
+
* twice is two references, while a replayed (fork-inherited) log derives the
|
|
1081
|
+
* same reference. The tuple deliberately contains NO Session id: rc.1 ordinary
|
|
1082
|
+
* forks inherit the log without a durable ancestor pointer, and a reference
|
|
1083
|
+
* must stay stable inside that inherited prefix. The hash is NOT a permission
|
|
1084
|
+
* token: every publication re-verifies the tuple against committed session
|
|
1085
|
+
* events.
|
|
1083
1086
|
*
|
|
1084
|
-
* The reference rides in its own TEXT content block, `visual-ref-
|
|
1087
|
+
* The reference rides in its own TEXT content block, `visual-ref-v2:sv2_…`,
|
|
1085
1088
|
* inserted before the final `visual-v1:` fact block by the generating tool's
|
|
1086
1089
|
* `projectContent`; it is never part of the durable fact itself.
|
|
1087
1090
|
* @module @xmoon76/dsh-pi-tui/domain/visual/reference
|
|
1088
1091
|
*/
|
|
1089
1092
|
/** Prefix of the machine block carrying the stable reference. */
|
|
1090
|
-
const VISUAL_REFERENCE_PREFIX = "visual-ref-
|
|
1093
|
+
const VISUAL_REFERENCE_PREFIX = "visual-ref-v2:";
|
|
1091
1094
|
/** The one accepted reference spelling: lowercase hex, exactly 20 digits. */
|
|
1092
|
-
const VISUAL_REFERENCE_PATTERN = /^
|
|
1095
|
+
const VISUAL_REFERENCE_PATTERN = /^sv2_[0-9a-f]{20}$/u;
|
|
1093
1096
|
/**
|
|
1094
1097
|
* The stable reference for one committed generating call.
|
|
1095
1098
|
* @param identity - the exact official tuple of the generating result.
|
|
1096
|
-
* @returns the `
|
|
1099
|
+
* @returns the `sv2_` reference.
|
|
1097
1100
|
*/
|
|
1098
1101
|
function visualReference(identity) {
|
|
1099
1102
|
const tuple = [
|
|
1100
|
-
|
|
1103
|
+
"sv2",
|
|
1101
1104
|
String(identity.turn),
|
|
1102
1105
|
String(identity.stepStartSeq),
|
|
1103
1106
|
identity.callId,
|
|
1104
1107
|
""
|
|
1105
1108
|
].join("\0");
|
|
1106
|
-
return `
|
|
1109
|
+
return `sv2_${createHash("sha256").update(tuple, "utf8").digest("hex").slice(0, 20)}`;
|
|
1107
1110
|
}
|
|
1108
1111
|
/** Serialize the machine block for one reference. */
|
|
1109
1112
|
function visualReferenceLine(reference) {
|
|
@@ -1111,7 +1114,7 @@ function visualReferenceLine(reference) {
|
|
|
1111
1114
|
}
|
|
1112
1115
|
/** Parse one machine block that carries only a reference. */
|
|
1113
1116
|
function parseVisualReferenceLine(text) {
|
|
1114
|
-
if (!text.startsWith("visual-ref-
|
|
1117
|
+
if (!text.startsWith("visual-ref-v2:")) return void 0;
|
|
1115
1118
|
const reference = text.slice(14);
|
|
1116
1119
|
return VISUAL_REFERENCE_PATTERN.test(reference) ? reference : void 0;
|
|
1117
1120
|
}
|
|
@@ -1236,135 +1239,6 @@ function visualPartsFromText(result) {
|
|
|
1236
1239
|
};
|
|
1237
1240
|
}
|
|
1238
1241
|
//#endregion
|
|
1239
|
-
//#region src/domain/visual/origin.ts
|
|
1240
|
-
/** The empty proof: no seq is attributed to any Session. */
|
|
1241
|
-
const NO_SPANS = Object.freeze([]);
|
|
1242
|
-
/** Whether one value is a structurally usable, non-empty range. */
|
|
1243
|
-
function isValidSpan(span) {
|
|
1244
|
-
return typeof span.sessionId === "string" && span.sessionId !== "" && Number.isSafeInteger(span.startSeq) && Number.isSafeInteger(span.endSeqExclusive) && span.startSeq >= 0 && span.endSeqExclusive > span.startSeq;
|
|
1245
|
-
}
|
|
1246
|
-
/** Freeze one validated range. */
|
|
1247
|
-
function frozenSpan(span) {
|
|
1248
|
-
return Object.freeze({
|
|
1249
|
-
startSeq: span.startSeq,
|
|
1250
|
-
endSeqExclusive: span.endSeqExclusive,
|
|
1251
|
-
sessionId: span.sessionId
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
/**
|
|
1255
|
-
* The ONE always-proven range of a log: a Session's OWN events.
|
|
1256
|
-
*
|
|
1257
|
-
* Events at or after the fork cut belong to the current Session by
|
|
1258
|
-
* construction, so this needs no ancestry read. An empty range covers nothing.
|
|
1259
|
-
* @param sessionId - the owning Session id.
|
|
1260
|
-
* @param startSeq - the first own seq (the inherited cut).
|
|
1261
|
-
* @param endSeqExclusive - the exclusive end (the log length).
|
|
1262
|
-
* @returns one frozen span, or the empty list for an empty/invalid range.
|
|
1263
|
-
*/
|
|
1264
|
-
function ownVisualOriginSpans(sessionId, startSeq, endSeqExclusive) {
|
|
1265
|
-
const span = {
|
|
1266
|
-
startSeq,
|
|
1267
|
-
endSeqExclusive,
|
|
1268
|
-
sessionId
|
|
1269
|
-
};
|
|
1270
|
-
if (!isValidSpan(span)) return NO_SPANS;
|
|
1271
|
-
return Object.freeze([frozenSpan(span)]);
|
|
1272
|
-
}
|
|
1273
|
-
/**
|
|
1274
|
-
* Merge ranges into the canonical ordered, non-overlapping form.
|
|
1275
|
-
*
|
|
1276
|
-
* Adjacent ranges of the SAME Session are coalesced; adjacent ranges of
|
|
1277
|
-
* DIFFERENT Sessions stay separate because the cut is a real identity change.
|
|
1278
|
-
* An overlapping, duplicated or malformed range set is refused as a whole
|
|
1279
|
-
* (`undefined`) instead of silently attributing one seq twice.
|
|
1280
|
-
* @param parts - the candidate ranges, in any order.
|
|
1281
|
-
* @returns the canonical frozen ranges, or undefined for an unusable set.
|
|
1282
|
-
*/
|
|
1283
|
-
function mergeVisualOriginSpans(parts) {
|
|
1284
|
-
const sorted = [...parts].sort((left, right) => left.startSeq - right.startSeq);
|
|
1285
|
-
const spans = [];
|
|
1286
|
-
for (const part of sorted) {
|
|
1287
|
-
if (!isValidSpan(part)) return void 0;
|
|
1288
|
-
const last = spans[spans.length - 1];
|
|
1289
|
-
if (last === void 0) {
|
|
1290
|
-
spans.push(frozenSpan(part));
|
|
1291
|
-
continue;
|
|
1292
|
-
}
|
|
1293
|
-
if (part.startSeq < last.endSeqExclusive) return void 0;
|
|
1294
|
-
if (part.startSeq === last.endSeqExclusive && part.sessionId === last.sessionId) {
|
|
1295
|
-
spans[spans.length - 1] = frozenSpan({
|
|
1296
|
-
startSeq: last.startSeq,
|
|
1297
|
-
endSeqExclusive: part.endSeqExclusive,
|
|
1298
|
-
sessionId: last.sessionId
|
|
1299
|
-
});
|
|
1300
|
-
continue;
|
|
1301
|
-
}
|
|
1302
|
-
spans.push(frozenSpan(part));
|
|
1303
|
-
}
|
|
1304
|
-
return Object.freeze(spans);
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Clip proven ranges to one half-open window.
|
|
1308
|
-
*
|
|
1309
|
-
* This is how a descendant reuses an ancestor's proof: the ancestor's full
|
|
1310
|
-
* range list is intersected with the prefix window the descendant inherited.
|
|
1311
|
-
* An invalid input set proves nothing.
|
|
1312
|
-
* @param spans - the proven ranges.
|
|
1313
|
-
* @param startSeq - inclusive window start.
|
|
1314
|
-
* @param endSeqExclusive - exclusive window end.
|
|
1315
|
-
* @returns the clipped ranges, still ordered and non-overlapping.
|
|
1316
|
-
*/
|
|
1317
|
-
function intersectVisualOriginSpans(spans, startSeq, endSeqExclusive) {
|
|
1318
|
-
if (!Number.isSafeInteger(startSeq) || !Number.isSafeInteger(endSeqExclusive) || endSeqExclusive <= startSeq) return NO_SPANS;
|
|
1319
|
-
const merged = mergeVisualOriginSpans(spans);
|
|
1320
|
-
if (merged === void 0) return NO_SPANS;
|
|
1321
|
-
const clipped = [];
|
|
1322
|
-
for (const span of merged) {
|
|
1323
|
-
const start = Math.max(span.startSeq, startSeq);
|
|
1324
|
-
const end = Math.min(span.endSeqExclusive, endSeqExclusive);
|
|
1325
|
-
if (end <= start) continue;
|
|
1326
|
-
clipped.push(frozenSpan({
|
|
1327
|
-
startSeq: start,
|
|
1328
|
-
endSeqExclusive: end,
|
|
1329
|
-
sessionId: span.sessionId
|
|
1330
|
-
}));
|
|
1331
|
-
}
|
|
1332
|
-
return Object.freeze(clipped);
|
|
1333
|
-
}
|
|
1334
|
-
/**
|
|
1335
|
-
* Resolve the proven origin of one seq, once.
|
|
1336
|
-
* @param spans - the proven ranges.
|
|
1337
|
-
* @param seq - one log seq.
|
|
1338
|
-
* @returns the original Session id, or undefined when the seq is unproven.
|
|
1339
|
-
*/
|
|
1340
|
-
function originSessionIdAt(spans, seq) {
|
|
1341
|
-
return createVisualOriginReader(spans)(seq);
|
|
1342
|
-
}
|
|
1343
|
-
/**
|
|
1344
|
-
* Build the ONE seq→origin lookup of a replay scan.
|
|
1345
|
-
*
|
|
1346
|
-
* The ranges are validated once; a malformed set proves nothing. The lookup is
|
|
1347
|
-
* a binary search, so one replay pass costs `O(events · log(spans))` and never
|
|
1348
|
-
* rescans the ranges per event.
|
|
1349
|
-
* @param spans - the proven ranges.
|
|
1350
|
-
* @returns the lookup (undefined for an unproven seq).
|
|
1351
|
-
*/
|
|
1352
|
-
function createVisualOriginReader(spans) {
|
|
1353
|
-
const merged = mergeVisualOriginSpans(spans);
|
|
1354
|
-
if (merged === void 0) return () => void 0;
|
|
1355
|
-
return (seq) => {
|
|
1356
|
-
let low = 0;
|
|
1357
|
-
let high = merged.length - 1;
|
|
1358
|
-
while (low <= high) {
|
|
1359
|
-
const middle = low + high >> 1;
|
|
1360
|
-
const span = merged[middle];
|
|
1361
|
-
if (seq < span.startSeq) high = middle - 1;
|
|
1362
|
-
else if (seq >= span.endSeqExclusive) low = middle + 1;
|
|
1363
|
-
else return span.sessionId;
|
|
1364
|
-
}
|
|
1365
|
-
};
|
|
1366
|
-
}
|
|
1367
|
-
//#endregion
|
|
1368
1242
|
//#region src/domain/visual/publication.ts
|
|
1369
1243
|
/** The durable event types this authority reads. */
|
|
1370
1244
|
const RELEVANT_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -1374,7 +1248,8 @@ const RELEVANT_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
|
1374
1248
|
"step/end",
|
|
1375
1249
|
"assistant/message",
|
|
1376
1250
|
"tool/call",
|
|
1377
|
-
"tool/result"
|
|
1251
|
+
"tool/result",
|
|
1252
|
+
"session/end-seed"
|
|
1378
1253
|
]);
|
|
1379
1254
|
/**
|
|
1380
1255
|
* Narrow one raw session event log to the shapes this authority reads.
|
|
@@ -1407,62 +1282,35 @@ function isModelOnlyReplacement(event) {
|
|
|
1407
1282
|
if (surfaceOp === void 0) return false;
|
|
1408
1283
|
return surfaceOp.op === "replace";
|
|
1409
1284
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* The executing step's `(turn, step)` key, located by its seq range.
|
|
1415
|
-
*
|
|
1416
|
-
* The step's model response lands AFTER its `step/start` and BEFORE the next
|
|
1417
|
-
* step boundary, so the range identifies it exactly even in a multi-step turn.
|
|
1418
|
-
* This reads only the boundary events, not the tool events.
|
|
1419
|
-
* @param events - the authority events.
|
|
1420
|
-
* @param turn - the executing turn.
|
|
1421
|
-
* @param stepStartSeq - the seq of the executing step's `step/start`.
|
|
1422
|
-
* @returns the step key, or undefined when its response is not observed.
|
|
1423
|
-
*/
|
|
1424
|
-
function executingStepKey(events, turn, stepStartSeq) {
|
|
1425
|
-
let nextBoundary = Number.POSITIVE_INFINITY;
|
|
1426
|
-
for (const event of events) {
|
|
1427
|
-
if (event.seq <= stepStartSeq) continue;
|
|
1428
|
-
if (event.type !== "step/start" && event.type !== "step/end" && event.type !== "turn/end") continue;
|
|
1429
|
-
if (event.seq < nextBoundary) nextBoundary = event.seq;
|
|
1430
|
-
}
|
|
1431
|
-
for (const event of events) {
|
|
1432
|
-
if (event.type !== "assistant/message" || isModelOnlyReplacement(event)) continue;
|
|
1433
|
-
if (event.data.turn !== turn) continue;
|
|
1434
|
-
if (event.seq <= stepStartSeq || event.seq >= nextBoundary) continue;
|
|
1435
|
-
return `${event.data.turn}:${event.data.step}`;
|
|
1436
|
-
}
|
|
1285
|
+
/** The composite call identity, INCLUDING the fork epoch. */
|
|
1286
|
+
function callKey(epoch, turn, step, callId) {
|
|
1287
|
+
return `${epoch}:${turn}:${step}:${callId}`;
|
|
1437
1288
|
}
|
|
1438
1289
|
/**
|
|
1439
1290
|
* Index one committed log exactly once.
|
|
1440
1291
|
*
|
|
1441
|
-
*
|
|
1442
|
-
*
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1445
|
-
* unproven seq is not indexed at all: it can neither be a source nor publish.
|
|
1446
|
-
* @param sessionId - the observed session identity.
|
|
1292
|
+
* The epoch starts at 0 and increments on every official inherited fork
|
|
1293
|
+
* marker; the inherited marker itself grants no tool-call qualification. Each
|
|
1294
|
+
* model response's requested call ids are counted per ACTUAL `step/start` seq,
|
|
1295
|
+
* because the same `(turn, step)` can be re-opened across fork generations.
|
|
1447
1296
|
* @param events - the authority events.
|
|
1448
|
-
* @param originOf - optional proven seq→origin lookup.
|
|
1449
1297
|
* @returns the indexed calls and the per-step requested-id counts.
|
|
1450
1298
|
*/
|
|
1451
|
-
function indexLog(
|
|
1452
|
-
const originAt = originOf ?? (() => sessionId);
|
|
1299
|
+
function indexLog(events) {
|
|
1453
1300
|
const calls = [];
|
|
1454
1301
|
const byKey = /* @__PURE__ */ new Map();
|
|
1455
1302
|
const stepCallIds = /* @__PURE__ */ new Map();
|
|
1456
|
-
let
|
|
1303
|
+
let epoch = 0;
|
|
1304
|
+
let openStep;
|
|
1457
1305
|
for (const event of events) {
|
|
1458
1306
|
if (isModelOnlyReplacement(event)) continue;
|
|
1459
1307
|
switch (event.type) {
|
|
1460
1308
|
case "assistant/message": {
|
|
1461
|
-
|
|
1462
|
-
let counts = stepCallIds.get(
|
|
1309
|
+
if (openStep === void 0) break;
|
|
1310
|
+
let counts = stepCallIds.get(openStep.seq);
|
|
1463
1311
|
if (counts === void 0) {
|
|
1464
1312
|
counts = /* @__PURE__ */ new Map();
|
|
1465
|
-
stepCallIds.set(
|
|
1313
|
+
stepCallIds.set(openStep.seq, counts);
|
|
1466
1314
|
}
|
|
1467
1315
|
for (const block of event.data.message.content) {
|
|
1468
1316
|
if (block.type !== "tool-call" || typeof block.id !== "string") continue;
|
|
@@ -1473,34 +1321,42 @@ function indexLog(sessionId, events, originOf) {
|
|
|
1473
1321
|
case "turn/start":
|
|
1474
1322
|
case "turn/end":
|
|
1475
1323
|
case "step/end":
|
|
1476
|
-
|
|
1324
|
+
openStep = void 0;
|
|
1477
1325
|
break;
|
|
1478
1326
|
case "step/start":
|
|
1479
|
-
|
|
1327
|
+
openStep = {
|
|
1328
|
+
seq: event.seq,
|
|
1329
|
+
turn: event.data.turn,
|
|
1330
|
+
step: event.data.step,
|
|
1331
|
+
epoch
|
|
1332
|
+
};
|
|
1333
|
+
break;
|
|
1334
|
+
case "session/end-seed":
|
|
1335
|
+
if (event.data.inherited === true) {
|
|
1336
|
+
epoch += 1;
|
|
1337
|
+
openStep = void 0;
|
|
1338
|
+
}
|
|
1480
1339
|
break;
|
|
1481
1340
|
case "tool/call": {
|
|
1482
|
-
if (
|
|
1483
|
-
const originSessionId = originAt(event.seq);
|
|
1484
|
-
if (originSessionId === void 0 || originAt(openStepStartSeq) !== originSessionId) break;
|
|
1341
|
+
if (openStep === void 0) break;
|
|
1485
1342
|
const call = {
|
|
1486
1343
|
callId: event.data.callId,
|
|
1487
1344
|
name: event.data.name,
|
|
1488
1345
|
arguments: event.data.arguments,
|
|
1489
1346
|
turn: event.data.turn,
|
|
1490
1347
|
step: event.data.step,
|
|
1491
|
-
stepStartSeq:
|
|
1348
|
+
stepStartSeq: openStep.seq,
|
|
1492
1349
|
callSeq: event.seq,
|
|
1493
|
-
|
|
1350
|
+
epoch: openStep.epoch,
|
|
1494
1351
|
ref: visualReference({
|
|
1495
|
-
sessionId: originSessionId,
|
|
1496
1352
|
turn: event.data.turn,
|
|
1497
|
-
stepStartSeq:
|
|
1353
|
+
stepStartSeq: openStep.seq,
|
|
1498
1354
|
callId: event.data.callId
|
|
1499
1355
|
}),
|
|
1500
1356
|
result: void 0,
|
|
1501
1357
|
ambiguous: false
|
|
1502
1358
|
};
|
|
1503
|
-
const key = callKey(call.turn, call.step, call.callId);
|
|
1359
|
+
const key = callKey(call.epoch, call.turn, call.step, call.callId);
|
|
1504
1360
|
const existing = byKey.get(key);
|
|
1505
1361
|
if (existing !== void 0) {
|
|
1506
1362
|
existing.ambiguous = true;
|
|
@@ -1511,10 +1367,9 @@ function indexLog(sessionId, events, originOf) {
|
|
|
1511
1367
|
break;
|
|
1512
1368
|
}
|
|
1513
1369
|
case "tool/result": {
|
|
1514
|
-
const key = callKey(event.data.turn, event.data.step, event.data.message.toolCallId);
|
|
1370
|
+
const key = callKey(epoch, event.data.turn, event.data.step, event.data.message.toolCallId);
|
|
1515
1371
|
const call = byKey.get(key);
|
|
1516
1372
|
if (call === void 0) break;
|
|
1517
|
-
if (originAt(event.seq) !== call.originSessionId) break;
|
|
1518
1373
|
if (call.result !== void 0 || event.seq <= call.callSeq) {
|
|
1519
1374
|
call.ambiguous = true;
|
|
1520
1375
|
break;
|
|
@@ -1587,7 +1442,7 @@ function qualifySource(call) {
|
|
|
1587
1442
|
svgSource: void 0,
|
|
1588
1443
|
svgAdmissionWidth: void 0
|
|
1589
1444
|
},
|
|
1590
|
-
|
|
1445
|
+
epoch: call.epoch
|
|
1591
1446
|
} : void 0;
|
|
1592
1447
|
if (fact.type !== "svg") return void 0;
|
|
1593
1448
|
const authorization = authorizeSvg(call.arguments, result.content, "ok");
|
|
@@ -1601,7 +1456,7 @@ function qualifySource(call) {
|
|
|
1601
1456
|
svgSource: authorization.source,
|
|
1602
1457
|
svgAdmissionWidth: authorization.admission.width
|
|
1603
1458
|
},
|
|
1604
|
-
|
|
1459
|
+
epoch: call.epoch
|
|
1605
1460
|
};
|
|
1606
1461
|
}
|
|
1607
1462
|
/**
|
|
@@ -1701,7 +1556,7 @@ function requestedReferences(rawArguments) {
|
|
|
1701
1556
|
* `tool/call.arguments` with the same one — so a successful receipt can always
|
|
1702
1557
|
* be replay-verified, and a replay can never accept a document the live body
|
|
1703
1558
|
* would have refused. The document is closed: only `visuals` at the root, only
|
|
1704
|
-
* `ref` per entry, 1–8 entries, well-formed `
|
|
1559
|
+
* `ref` per entry, 1–8 entries, well-formed `sv2_` references, no duplicates.
|
|
1705
1560
|
* @param args - the model-supplied arguments (already JSON-parsed).
|
|
1706
1561
|
* @returns the accepted references, or the verbatim refusal reason.
|
|
1707
1562
|
*/
|
|
@@ -1733,7 +1588,7 @@ function parsePresentVisualArguments(args) {
|
|
|
1733
1588
|
};
|
|
1734
1589
|
if (!isReferenceSpelling(fields.ref)) return {
|
|
1735
1590
|
ok: false,
|
|
1736
|
-
reason: "every visual ref must look like
|
|
1591
|
+
reason: "every visual ref must look like sv2_ followed by 20 lowercase hex digits"
|
|
1737
1592
|
};
|
|
1738
1593
|
refs.push(fields.ref);
|
|
1739
1594
|
}
|
|
@@ -1750,12 +1605,13 @@ function parsePresentVisualArguments(args) {
|
|
|
1750
1605
|
* Whether one generating source may be published by the given publisher.
|
|
1751
1606
|
*
|
|
1752
1607
|
* Stated once so the live tool body and cold replay cannot disagree: the SAME
|
|
1753
|
-
*
|
|
1754
|
-
*
|
|
1755
|
-
*
|
|
1608
|
+
* fork epoch recorded both, the same turn, an EARLIER model step, and the source
|
|
1609
|
+
* result committed before the publishing call. The epoch equality is what stops
|
|
1610
|
+
* a child from RE-publishing a figure it merely inherited; the inherited
|
|
1611
|
+
* successful publication itself still replays from its own epoch.
|
|
1756
1612
|
*/
|
|
1757
1613
|
function isPublishableBy(qualified, publisher) {
|
|
1758
|
-
return qualified.
|
|
1614
|
+
return qualified.epoch === publisher.epoch && qualified.source.turn === publisher.turn && qualified.source.stepStartSeq < publisher.stepStartSeq && qualified.source.resultSeq < publisher.callSeq;
|
|
1759
1615
|
}
|
|
1760
1616
|
/**
|
|
1761
1617
|
* Collect the successfully published visuals of one committed log.
|
|
@@ -1765,12 +1621,11 @@ function isPublishableBy(qualified, publisher) {
|
|
|
1765
1621
|
* result pair exactly, the receipt is present in the FINAL content, and the
|
|
1766
1622
|
* requested references equal the receipt's references position by position.
|
|
1767
1623
|
* Repeated references keep only their FIRST successful publication.
|
|
1768
|
-
* @param sessionId - the observed session identity.
|
|
1769
1624
|
* @param events - the exact committed events, in `seq` order.
|
|
1770
1625
|
* @returns the published visuals in durable order, first-wins.
|
|
1771
1626
|
*/
|
|
1772
|
-
function collectPublishedVisuals(
|
|
1773
|
-
const indexed = indexLog(
|
|
1627
|
+
function collectPublishedVisuals(events) {
|
|
1628
|
+
const indexed = indexLog(events);
|
|
1774
1629
|
const sourcesByRef = /* @__PURE__ */ new Map();
|
|
1775
1630
|
for (const qualified of sourcesOf(indexed.calls)) {
|
|
1776
1631
|
const ref = qualified.source.ref;
|
|
@@ -1829,10 +1684,9 @@ function collectPublishedVisuals(sessionId, events, originSpans) {
|
|
|
1829
1684
|
* @returns the receipt to persist, or the verbatim refusal reason.
|
|
1830
1685
|
*/
|
|
1831
1686
|
function decidePublication(input) {
|
|
1832
|
-
const {
|
|
1833
|
-
const indexed = indexLog(
|
|
1834
|
-
const
|
|
1835
|
-
const ids = stepKey === void 0 ? 0 : indexed.stepCallIds.get(stepKey)?.get(callId) ?? 0;
|
|
1687
|
+
const { events, refs, turn, stepStartSeq, callId } = input;
|
|
1688
|
+
const indexed = indexLog(events);
|
|
1689
|
+
const ids = indexed.stepCallIds.get(stepStartSeq)?.get(callId) ?? 0;
|
|
1836
1690
|
if (ids > 1) return {
|
|
1837
1691
|
ok: false,
|
|
1838
1692
|
reason: `the model response for this step requested "${callId}" ${ids} times; a duplicated call id cannot publish`
|
|
@@ -1885,6 +1739,10 @@ function decidePublication(input) {
|
|
|
1885
1739
|
ok: false,
|
|
1886
1740
|
reason: `visual ref ${ref} belongs to a later model step`
|
|
1887
1741
|
};
|
|
1742
|
+
if (qualified.epoch !== publisher.epoch) return {
|
|
1743
|
+
ok: false,
|
|
1744
|
+
reason: `visual ref ${ref} belongs to an earlier fork epoch; an inherited generating result cannot be published again`
|
|
1745
|
+
};
|
|
1888
1746
|
if (!isPublishableBy(qualified, publisher)) return {
|
|
1889
1747
|
ok: false,
|
|
1890
1748
|
reason: "Source visual is not committed yet; call present_visual after the generating tool has finished."
|
|
@@ -1920,4 +1778,4 @@ function decidePublication(input) {
|
|
|
1920
1778
|
/** The Host-plane service the visual-tools row provides after it mounts. */
|
|
1921
1779
|
const VISUAL_TOOLS_STATUS_SERVICE = "piTuiVisualToolsStatus";
|
|
1922
1780
|
//#endregion
|
|
1923
|
-
export {
|
|
1781
|
+
export { SVG_MAX_RASTER_SIDE as A, chartHumanText as C, admitSvg as D, chartValueRows as E, VISUAL_PUBLISHED_PREFIX as F, humanFacingVisualResult as I, isVisualToolName as L, CHART_TOOL_NAME as M, PRESENT_VISUAL_TOOL_NAME as N, SVG_MAX_PNG_BYTES as O, SVG_TOOL_NAME as P, chartFactFromArgs as S, chartTextRows as T, svgDigest as _, isModelOnlyReplacement as a, chartContentBlocks as b, visualParts as c, visualReference as d, visualReferenceLine as f, svgDetailRows as g, svgContentBlocks as h, decidePublication as i, SVG_RASTER_TIMEOUT_MS as j, SVG_MAX_RASTER_PIXELS as k, visualPartsForStatus as l, svgArgsProblem as m, asVisualSessionEvents as n, parsePresentVisualArguments as o, authorizeSvg as p, collectPublishedVisuals as r, visualFactLine as s, VISUAL_TOOLS_STATUS_SERVICE as t, visualPartsFromText as u, svgFactFromArgs as v, chartProjection as w, chartDisplayTitle as x, chartArgsProblem as y };
|