@tea-agent/loop-agent 0.51.0-next.2 → 0.51.0-next.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/CHANGELOG.md +31 -3
- package/dist/build-stamp.json +3 -3
- package/dist/shared/pi-context-pressure/checkpoint.js +201 -74
- package/dist/shared/pi-context-pressure/compaction-accounting.js +27 -0
- package/dist/shared/pi-context-pressure/compaction-policy.js +5 -1
- package/dist/shared/pi-context-pressure/exact-tool-policy.js +93 -0
- package/dist/shared/pi-context-pressure/extension.js +59 -6
- package/dist/shared/pi-context-pressure/index.js +3 -1
- package/dist/shared/pi-context-pressure/sift-bridge.js +53 -3
- package/dist/shared/pi-context-pressure/telemetry.js +8 -0
- package/dist/shared/pi-context-pressure/tool-result-pruner.js +5 -0
- package/dist/worker/console/chat/chat-event-projection.js +6 -0
- package/dist/worker/console/chat/chat-event-store.js +7 -0
- package/dist/worker/console/chat/compaction-errors.js +1 -1
- package/dist/worker/console/chat/context-accounting.js +58 -0
- package/dist/worker/console/chat/context-insights.js +95 -35
- package/dist/worker/console/chat/context-usage.js +3 -1
- package/dist/worker/console/chat/pi-runtime/context-edit.js +11 -3
- package/dist/worker/console/chat/pi-runtime.js +45 -3
- package/dist/worker/console/chat/routes.js +10 -0
- package/dist/worker/console/chat/session-mode.js +1 -0
- package/dist/worker/console/chat/terminal-routes.js +15 -1
- package/dist/worker/console/chat/terminal-sessions.js +6 -0
- package/dist/worker/console/chat/vcp-prompt.js +9 -3
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-BDoJuIJc.js → abnfDiagram-N423BO3Z-Cm9fdnXV.js} +1 -1
- package/dist/worker/console/static/assets/{arc-BIcO0B1H.js → arc-INXjsn-p.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-DbxnPcOI.js → architectureDiagram-T3A2C74G-D37KkILZ.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-BG4tXH7C.js → blockDiagram-VBNYF7ZC-KKXC0tnC.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BaNxGG9H.js → c4Diagram-5PPSVZJV-CoiYxKG6.js} +1 -1
- package/dist/worker/console/static/assets/channel-CjI9LnHL.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-BYr2qNac.js → chunk-2GRJ4B5K-DUf1X-RG.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-D3q2b9W9.js → chunk-2Q5K7J3B-CHCaBxdV.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-BFsAsJ8z.js → chunk-5RXB4S5H-BequgbOM.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-Bnp6GtE7.js → chunk-5VM5RSS4-BfCaRimU.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-CzDChmU1.js → chunk-6Q2QTUOP-D8UjJk_C.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-kgZTzZlf.js → chunk-GF5L2VYU-BqVP9DQI.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Vnt5nEN_.js → chunk-JWPE2WC7-DIdHATyu.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CENlGfou.js → chunk-KBJHAD2P-C_lQLU-3.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-DS1bOotT.js → chunk-RYQCIY6F-Dk7kiAO-.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-SkFJspnw.js → chunk-XXDRQBXY-MgUV0HsP.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DckutAaL.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DckutAaL.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BE1OAnpP.js → cose-bilkent-JH36ORCC-DOLAaAUQ.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-BaTDZwL-.js → cynefin-VYW2F7L2-CC8nJgvv.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-BRrIdbbw.js → cynefinDiagram-MW4NZA55-CWKq9Dot.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-B4pDil_r.js → dagre-VZM6K2ZE-DLQrVo6F.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-DvqFh-9w.js → diagram-7IWD3JNH-4GbuYTRz.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-D7me-QwT.js → diagram-B4RE2ZJO-_bsAsFIM.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-EahLHu6K.js → diagram-LBJQPF4R-98UkDrJp.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE--S6g2rQZ.js → diagram-Q27KOJAE-3l4QTjOH.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-BwqA9gGp.js → diagram-UB23O5K3-CHfpyvkh.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-Bdj6kj6x.js → ebnfDiagram-BXEA7PRR-CHaGmmH6.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-_Ii2v364.js → erDiagram-JOGREHBK-CGHzLz5D.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-LM1yby4D.js → flowDiagram-UKHOOZJN-BuMWtKY4.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-_MmByUIz.js → ganttDiagram-PKOTCBZU-C2250UEq.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-Be4J6q3D.js → gitGraphDiagram-DS77QQ5N-CelgpYyy.js} +1 -1
- package/dist/worker/console/static/assets/{index-CpugPRcA.js → index-BlNf823_.js} +159 -147
- package/dist/worker/console/static/assets/{index-BVMJjujb.css → index-CzfumEW1.css} +1 -1
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-CFRi5O36.js → infoDiagram-6WML65LV-BNjkoLGP.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-B2OnsVXe.js → ishikawaDiagram-WSZJBQD7-WsQBCOMy.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-Dnz8Ge36.js → journeyDiagram-NVQOT4AX-DPMg56VB.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-DFPGjB3O.js → kanban-definition-27J2QSJJ-Ces2yNhD.js} +1 -1
- package/dist/worker/console/static/assets/{linear-DrKFn9ZE.js → linear-BWDvQlHY.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-C4__OfPT.js → mermaid.core-B61abuWa.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-CMEMeYGS.js → mindmap-definition-FAOFIHXS-D8C0x0Uc.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-BDNDtN72.js → pegDiagram-VL7TDLO6-CTayvHb1.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-DX12wRku.js → pieDiagram-7S7Q4E2Y-BMlgdA3f.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-DEzotPpD.js → quadrantDiagram-CIZ2JOQS-CfR-Bjz0.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BGbCCVjx.js → railroadDiagram-AXF67PYL-CPZnompR.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-eClVYdkl.js → requirementDiagram-LRYGKXZP-ChfgFRf2.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-Hyw3eFyF.js → sankeyDiagram-W5VNT64P-wJGtKdSl.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-DwysyBPq.js → sequenceDiagram-SI44F4Z6-Bvw8kgEK.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-jLtIaGKt.js → sheet-workbook-DIcc5MII.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-CsA3-7gH.js → sizeCapture-X5ZJPWSS-CxkQAgp9.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-DkUPiKZ8.js → stateDiagram-OKZ733FA-CXxg2h63.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BjyIE-uf.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-qfVo6Xay.js → swimlanes-SLNWSIFB-CW8urXHy.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Dl2sojZu.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-BRTsFNL5.js → timeline-definition-Z64GVDOM-iXcLaMEd.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BI-btTm3.js → vennDiagram-T6HMQDX7-qXN9XhmE.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-BYMVY4Ov.js → wardleyDiagram-T6FBY63Y-CMqSH6Pw.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-CvK7yNi0.js → xychartDiagram-ELKLHX3M-9DphXHpY.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +99 -16
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +27 -5
- package/dist/worker/console/workspace-context.js +3 -0
- package/package.json +6 -3
- package/dist/worker/console/static/assets/channel-DigIZ6M1.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-AY-sL87U.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-AY-sL87U.js +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BiXtsN97.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-ImoXsndy.js +0 -8
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* so it works for idle and restored sessions alike.
|
|
19
19
|
*/
|
|
20
20
|
import { conservativeTokenEstimate } from "../../../shared/pi-context-pressure/compaction-policy.js";
|
|
21
|
+
import { readPruneAccounting, reclaimedAmount, } from "./context-accounting.js";
|
|
21
22
|
/** Fixed-density token estimate for preview text (chars → tokens). */
|
|
22
23
|
export function estimateTokensFromText(text) {
|
|
23
24
|
if (!text)
|
|
@@ -253,12 +254,21 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
253
254
|
const browserMessages = [];
|
|
254
255
|
const browserInjected = [];
|
|
255
256
|
const browserToolResults = [];
|
|
257
|
+
// Keep an immutable-by-retention history separate from the live surface. A
|
|
258
|
+
// prune removes a node from the next request, but it must remain visible in
|
|
259
|
+
// every historical step that predates the removal (dsh-context's `gone`
|
|
260
|
+
// boundary semantics).
|
|
261
|
+
const historyMessages = [];
|
|
262
|
+
const historyInjected = [];
|
|
263
|
+
const historyToolResults = [];
|
|
256
264
|
const archivedElements = [];
|
|
265
|
+
const removedAtBySeq = new Map();
|
|
257
266
|
const liveNodes = [];
|
|
258
267
|
const pendingShadow = new Map();
|
|
268
|
+
const pruneEventsById = new Map();
|
|
259
269
|
const seenReplacementIds = new Set();
|
|
260
270
|
/** Remove the ledger nodes whose seq the removal claims; deduct slices and browser rows. */
|
|
261
|
-
function claimNodes(claimed, removedAtSeq) {
|
|
271
|
+
function claimNodes(claimed, removedAtSeq, pruneId, replacementId) {
|
|
262
272
|
if (claimed.size === 0)
|
|
263
273
|
return [];
|
|
264
274
|
const removedIds = [];
|
|
@@ -269,9 +279,14 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
269
279
|
slice.tokens = Math.max(0, slice.tokens - node.tokens);
|
|
270
280
|
slice.items = Math.max(0, slice.items - 1);
|
|
271
281
|
removedIds.push(node.element.id);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
282
|
+
if (removedAtSeq !== undefined)
|
|
283
|
+
removedAtBySeq.set(node.seq, removedAtSeq);
|
|
284
|
+
archivedElements.push({
|
|
285
|
+
...node.element,
|
|
286
|
+
...(removedAtSeq === undefined ? {} : { removedAtSeq }),
|
|
287
|
+
...(pruneId === undefined ? {} : { pruneId }),
|
|
288
|
+
...(replacementId === undefined ? {} : { replacementId }),
|
|
289
|
+
});
|
|
275
290
|
}
|
|
276
291
|
else {
|
|
277
292
|
kept.push(node);
|
|
@@ -347,6 +362,7 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
347
362
|
at: event.at,
|
|
348
363
|
};
|
|
349
364
|
browserMessages.push(element);
|
|
365
|
+
historyMessages.push(element);
|
|
350
366
|
liveNodes.push({ seq: event.seq, tokens, category: "user", element });
|
|
351
367
|
if (!turnUserBrief.has(event.turnId)) {
|
|
352
368
|
turnUserBrief.set(event.turnId, text.slice(0, 200));
|
|
@@ -381,6 +397,7 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
381
397
|
at: event.at,
|
|
382
398
|
};
|
|
383
399
|
browserMessages.push(element);
|
|
400
|
+
historyMessages.push(element);
|
|
384
401
|
liveNodes.push({ seq: event.seq, tokens, category: "assistant", element });
|
|
385
402
|
}
|
|
386
403
|
const toolsCalled = stepToolsCalled.get(event.turnId) ?? [];
|
|
@@ -451,6 +468,7 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
451
468
|
seq: event.seq,
|
|
452
469
|
at: event.at,
|
|
453
470
|
});
|
|
471
|
+
historyInjected.push(browserInjected[browserInjected.length - 1]);
|
|
454
472
|
}
|
|
455
473
|
if (toolName && atTime > 0) {
|
|
456
474
|
const toolCallId = typeof data.toolCallId === "string" ? data.toolCallId : "";
|
|
@@ -511,13 +529,6 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
511
529
|
claimedKey = replacementPruneId;
|
|
512
530
|
claimed = pendingShadow.get(replacementPruneId);
|
|
513
531
|
}
|
|
514
|
-
else {
|
|
515
|
-
const first = pendingShadow.entries().next();
|
|
516
|
-
if (!first.done) {
|
|
517
|
-
claimedKey = first.value[0];
|
|
518
|
-
claimed = first.value[1];
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
532
|
if (claimed) {
|
|
522
533
|
const sourceSeqs = Array.isArray(data.sourceEventSeqs)
|
|
523
534
|
? data.sourceEventSeqs.filter((value) => typeof value === "number" && Number.isInteger(value) && value >= 0)
|
|
@@ -529,9 +540,13 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
529
540
|
const valid = surfaceOp?.op === "replace" && startSeq !== undefined && endSeq !== undefined &&
|
|
530
541
|
startSeq === minSeq && endSeq === maxSeq && sourceSeqs.length === claimed.size &&
|
|
531
542
|
new Set(sourceSeqs).size === claimed.size && sourceSeqs.every((seq) => claimed.has(seq));
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
claimNodes(claimed, event.seq);
|
|
543
|
+
if (valid) {
|
|
544
|
+
pendingShadow.delete(claimedKey);
|
|
545
|
+
claimNodes(claimed, event.seq, claimedKey, replacementId);
|
|
546
|
+
const pruneEvent = pruneEventsById.get(claimedKey);
|
|
547
|
+
if (pruneEvent)
|
|
548
|
+
pruneEvent.pruneStatus = "durable-completed";
|
|
549
|
+
}
|
|
535
550
|
}
|
|
536
551
|
const resultPreview = typeof data.resultPreview === "string"
|
|
537
552
|
? data.resultPreview
|
|
@@ -558,6 +573,7 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
558
573
|
at: event.at,
|
|
559
574
|
};
|
|
560
575
|
browserToolResults.push(element);
|
|
576
|
+
historyToolResults.push(element);
|
|
561
577
|
liveNodes.push({ seq: event.seq, tokens, category: "toolResults", element });
|
|
562
578
|
}
|
|
563
579
|
break;
|
|
@@ -601,9 +617,11 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
601
617
|
case "compaction_start":
|
|
602
618
|
case "compaction_end":
|
|
603
619
|
case "compact": {
|
|
604
|
-
const
|
|
605
|
-
const
|
|
606
|
-
const
|
|
620
|
+
const accounting = readPruneAccounting(data);
|
|
621
|
+
const before = accounting.tokensBefore;
|
|
622
|
+
const after = accounting.tokensAfter;
|
|
623
|
+
const reclaimedInfo = reclaimedAmount(accounting);
|
|
624
|
+
const reclaimed = reclaimedInfo.unit === "tokens" && reclaimedInfo.value !== null ? reclaimedInfo.value : null;
|
|
607
625
|
const pruned = data.pruned === true || data.kind === "prune";
|
|
608
626
|
// Only explicit ring sequence claims can update the live ledger.
|
|
609
627
|
// Pi firstKeptEntryId values are opaque entry identities, not event
|
|
@@ -621,7 +639,7 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
621
639
|
if (removedIds.length > 0)
|
|
622
640
|
removalBasis = "seqs";
|
|
623
641
|
}
|
|
624
|
-
|
|
642
|
+
const contextEvent = {
|
|
625
643
|
seq: event.seq,
|
|
626
644
|
at: event.at,
|
|
627
645
|
turnId: event.turnId,
|
|
@@ -637,13 +655,24 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
637
655
|
...(after !== undefined ? { tokensAfter: after } : {}),
|
|
638
656
|
...(num(data.charsBefore) !== undefined ? { charsBefore: num(data.charsBefore) } : {}),
|
|
639
657
|
...(num(data.charsAfter) !== undefined ? { charsAfter: num(data.charsAfter) } : {}),
|
|
658
|
+
...(accounting.shadowedTokenCount !== undefined ? { shadowedTokenCount: accounting.shadowedTokenCount } : {}),
|
|
659
|
+
...(accounting.replacementTokenCount !== undefined ? { replacementTokenCount: accounting.replacementTokenCount } : {}),
|
|
660
|
+
...(accounting.netTokensFreed !== undefined ? { netTokensFreed: accounting.netTokensFreed } : {}),
|
|
661
|
+
...(accounting.accounting !== undefined
|
|
662
|
+
? { accounting: accounting.accounting }
|
|
663
|
+
: accounting.charsBefore !== undefined && accounting.charsAfter !== undefined
|
|
664
|
+
? { accounting: "estimated-chars" }
|
|
665
|
+
: {}),
|
|
640
666
|
...(Array.isArray(data.shadowedSeqs) ? { shadowedItems: data.shadowedSeqs.length } : {}),
|
|
641
667
|
...(typeof data.reason === "string" ? { reason: data.reason } : {}),
|
|
642
|
-
...(pruned ? { pruned: true } : {}),
|
|
668
|
+
...(pruned ? { pruned: true, pruneStatus: "durable-pending" } : {}),
|
|
643
669
|
...(removedIds.length > 0 ? { removedIds } : {}),
|
|
644
670
|
...(removalBasis !== undefined ? { removalBasis } : {}),
|
|
645
671
|
detail: boundedText(asRecord(data.details)?.text, 300),
|
|
646
|
-
}
|
|
672
|
+
};
|
|
673
|
+
contextEvents.push(contextEvent);
|
|
674
|
+
if (pruned && typeof data.pruneId === "string")
|
|
675
|
+
pruneEventsById.set(data.pruneId, contextEvent);
|
|
647
676
|
const lastStep = trend.at(-1);
|
|
648
677
|
if (lastStep && event.kind !== "compaction_start") {
|
|
649
678
|
lastStep.eventMark = pruned ? "prune" : "compact";
|
|
@@ -654,6 +683,15 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
654
683
|
break;
|
|
655
684
|
}
|
|
656
685
|
}
|
|
686
|
+
for (const [pruneId, pruneEvent] of pruneEventsById) {
|
|
687
|
+
if (pendingShadow.has(pruneId))
|
|
688
|
+
pruneEvent.pruneStatus = "durable-unresolved";
|
|
689
|
+
}
|
|
690
|
+
for (const pruneEvent of contextEvents) {
|
|
691
|
+
if (pruneEvent.kind === "prune" && pruneEvent.pruneStatus === "durable-pending") {
|
|
692
|
+
pruneEvent.pruneStatus = "durable-unresolved";
|
|
693
|
+
}
|
|
694
|
+
}
|
|
657
695
|
composition.totalTokens = composition.slices.reduce((sum, slice) => sum + slice.tokens, 0);
|
|
658
696
|
composition.contextWindow = contextWindow;
|
|
659
697
|
composition.providerTotal = providerTotal;
|
|
@@ -697,9 +735,15 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
697
735
|
}
|
|
698
736
|
// --- Browser snapshots: live + one per trend step (rolling elements) ---
|
|
699
737
|
const browserSteps = [];
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
738
|
+
const bounded = (elements) => ({
|
|
739
|
+
elements: capElements(elements),
|
|
740
|
+
missing: Math.max(0, elements.length - ELEMENT_LIST_CAP),
|
|
741
|
+
});
|
|
742
|
+
const liveMessages = bounded(browserMessages);
|
|
743
|
+
const liveInjected = bounded(browserInjected);
|
|
744
|
+
const liveToolResults = bounded(browserToolResults);
|
|
745
|
+
const liveArchive = bounded(archivedElements);
|
|
746
|
+
const liveMissing = liveMessages.missing + liveInjected.missing + liveToolResults.missing + liveArchive.missing;
|
|
703
747
|
const liveCategories = [];
|
|
704
748
|
const pushCategory = (category, elements) => {
|
|
705
749
|
if (elements.length === 0)
|
|
@@ -721,15 +765,17 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
721
765
|
}]
|
|
722
766
|
: []);
|
|
723
767
|
pushCategory("tools", browserTools);
|
|
724
|
-
pushCategory("messages", liveMessages);
|
|
725
|
-
pushCategory("injected", liveInjected);
|
|
726
|
-
pushCategory("toolResults", liveToolResults);
|
|
768
|
+
pushCategory("messages", liveMessages.elements);
|
|
769
|
+
pushCategory("injected", liveInjected.elements);
|
|
770
|
+
pushCategory("toolResults", liveToolResults.elements);
|
|
727
771
|
pushCategory("skills", browserSkills);
|
|
728
772
|
browserSteps.push({
|
|
729
773
|
stepId: "live",
|
|
730
774
|
categories: liveCategories,
|
|
731
775
|
totalTokens: liveCategories.reduce((sum, c) => sum + c.totalTokens, 0),
|
|
732
|
-
archive:
|
|
776
|
+
archive: liveArchive.elements,
|
|
777
|
+
coverage: liveMissing > 0 ? "approximate" : "complete",
|
|
778
|
+
missingItems: liveMissing,
|
|
733
779
|
});
|
|
734
780
|
// Retained steps: rebuild each step's makeup from cumulative snapshots at
|
|
735
781
|
// that point in the ring (bounded to the most recent steps).
|
|
@@ -738,10 +784,20 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
738
784
|
for (let i = 0; i < recentTrend.length; i++) {
|
|
739
785
|
const step = recentTrend[i];
|
|
740
786
|
const cutoffSeq = step.seq;
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const
|
|
787
|
+
// Historical surfaces are reconstructed from the full ledger. A node is
|
|
788
|
+
// visible before its removal boundary and absent afterwards; using the
|
|
789
|
+
// current live arrays here would incorrectly erase pre-prune history.
|
|
790
|
+
const upto = (list) => bounded(list.filter((e) => {
|
|
791
|
+
if (e.seq > cutoffSeq)
|
|
792
|
+
return false;
|
|
793
|
+
const removedAt = removedAtBySeq.get(e.seq);
|
|
794
|
+
return removedAt === undefined || removedAt > cutoffSeq;
|
|
795
|
+
}));
|
|
796
|
+
const messagesAt = upto(historyMessages);
|
|
797
|
+
const injectedAt = upto(historyInjected);
|
|
798
|
+
const resultsAt = upto(historyToolResults);
|
|
799
|
+
const archiveAt = bounded(archivedElements.filter((element) => element.removedAtSeq === undefined || element.removedAtSeq <= cutoffSeq));
|
|
800
|
+
const missingItems = messagesAt.missing + injectedAt.missing + resultsAt.missing + archiveAt.missing;
|
|
745
801
|
const categories = [];
|
|
746
802
|
const push = (category, elements) => {
|
|
747
803
|
if (elements.length === 0)
|
|
@@ -763,9 +819,9 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
763
819
|
}]
|
|
764
820
|
: []);
|
|
765
821
|
push("tools", browserTools);
|
|
766
|
-
push("messages", messagesAt);
|
|
767
|
-
push("injected", injectedAt);
|
|
768
|
-
push("toolResults", resultsAt);
|
|
822
|
+
push("messages", messagesAt.elements);
|
|
823
|
+
push("injected", injectedAt.elements);
|
|
824
|
+
push("toolResults", resultsAt.elements);
|
|
769
825
|
push("skills", browserSkills);
|
|
770
826
|
browserSteps.push({
|
|
771
827
|
stepId: String(step.index),
|
|
@@ -773,7 +829,9 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
773
829
|
at: step.at,
|
|
774
830
|
categories,
|
|
775
831
|
totalTokens: categories.reduce((sum, c) => sum + c.totalTokens, 0),
|
|
776
|
-
archive:
|
|
832
|
+
archive: archiveAt.elements,
|
|
833
|
+
coverage: missingItems > 0 ? "approximate" : "complete",
|
|
834
|
+
missingItems,
|
|
777
835
|
});
|
|
778
836
|
}
|
|
779
837
|
return {
|
|
@@ -792,6 +850,7 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
792
850
|
return a.path.localeCompare(b.path);
|
|
793
851
|
}),
|
|
794
852
|
browser: browserSteps,
|
|
853
|
+
browserDroppedSteps: Math.max(0, trend.length - recentTrend.length),
|
|
795
854
|
usage,
|
|
796
855
|
timing,
|
|
797
856
|
systemPromptChars: options.systemPromptChars ?? null,
|
|
@@ -802,5 +861,6 @@ export function deriveContextInsights(events, options = {}) {
|
|
|
802
861
|
tokens: t.tokens,
|
|
803
862
|
})),
|
|
804
863
|
skillInjections: options.skillInjections ?? [],
|
|
864
|
+
...(options.contextPressure ? { contextPressure: options.contextPressure } : {}),
|
|
805
865
|
};
|
|
806
866
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseAssistantContent } from "./assistant-content.js";
|
|
2
|
+
import { readPruneAccounting } from "./context-accounting.js";
|
|
2
3
|
const tokensForText = (value) => typeof value === "string" ? Math.ceil(value.length / 4) : 0;
|
|
3
4
|
function finiteCount(value) {
|
|
4
5
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
@@ -120,7 +121,8 @@ export function deriveChatContextUsage(events) {
|
|
|
120
121
|
else if (event.kind === "compact" || event.kind === "compaction_end") {
|
|
121
122
|
if (data.status !== undefined && data.status !== "completed")
|
|
122
123
|
continue;
|
|
123
|
-
const
|
|
124
|
+
const accounting = readPruneAccounting(data);
|
|
125
|
+
const after = accounting.tokensAfter;
|
|
124
126
|
if (after !== undefined) {
|
|
125
127
|
prompt = after;
|
|
126
128
|
surface = 0;
|
|
@@ -21,6 +21,8 @@ function findToolResultEntry(manager, sourceMessage) {
|
|
|
21
21
|
const sourceToolCallId = typeof sourceMessage.toolCallId === "string"
|
|
22
22
|
? sourceMessage.toolCallId
|
|
23
23
|
: undefined;
|
|
24
|
+
const candidates = [];
|
|
25
|
+
const contentMatches = [];
|
|
24
26
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
25
27
|
const entry = entries[index];
|
|
26
28
|
const id = typeof entry?.id === "string" ? entry.id : undefined;
|
|
@@ -28,7 +30,13 @@ function findToolResultEntry(manager, sourceMessage) {
|
|
|
28
30
|
if (!id || !message)
|
|
29
31
|
continue;
|
|
30
32
|
if (sourceToolCallId && message.toolCallId === sourceToolCallId)
|
|
31
|
-
|
|
33
|
+
candidates.push({ id, message });
|
|
34
|
+
}
|
|
35
|
+
if (candidates.length === 1)
|
|
36
|
+
return candidates[0];
|
|
37
|
+
if (candidates.length > 1) {
|
|
38
|
+
const exact = candidates.filter((candidate) => sameContent(candidate.message, sourceMessage));
|
|
39
|
+
return exact.length === 1 ? exact[0] : undefined;
|
|
32
40
|
}
|
|
33
41
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
34
42
|
const entry = entries[index];
|
|
@@ -37,9 +45,9 @@ function findToolResultEntry(manager, sourceMessage) {
|
|
|
37
45
|
if (!id || !message)
|
|
38
46
|
continue;
|
|
39
47
|
if (sameContent(message, sourceMessage))
|
|
40
|
-
|
|
48
|
+
contentMatches.push({ id, message });
|
|
41
49
|
}
|
|
42
|
-
return undefined;
|
|
50
|
+
return contentMatches.length === 1 ? contentMatches[0] : undefined;
|
|
43
51
|
}
|
|
44
52
|
function replacementContent(message) {
|
|
45
53
|
if (typeof message.content === "string")
|
|
@@ -50,7 +50,7 @@ import { applySkillAutoInvocationPreferences, loadResourcePreferences, } from ".
|
|
|
50
50
|
import { buildPiModeLoopIsolationOptions } from "./pi-mode-loop-isolation.js";
|
|
51
51
|
import { applyWorkflowIntakeSkillAuthority, resolveWorkflowIntakeCapability, verifyWorkflowIntakeSkillInventory, workflowIntakeMaterializationFailure, } from "./workflow-intake-skills.js";
|
|
52
52
|
import { applyProcessRetryOverride, } from "../../../shared/pi-retry-settings.js";
|
|
53
|
-
import { applyProcessCompactionOverride, createCompactionController, createContextPressureExtension, createSiftBridgeState, housekeepSiftStash, isConsoleSiftEnabled, parseCompactionPolicy, parsePiToolResultPruneConfig, parseSiftBridgeConfig, projectPromptPressure, deriveEffectiveWindow, projectSafeTelemetry, emptyContextPressureCounters, } from "../../../shared/pi-context-pressure/index.js";
|
|
53
|
+
import { applyProcessCompactionOverride, createCompactionController, createContextPressureExtension, createSiftBridgeState, housekeepSiftStash, isConsoleSiftEnabled, parseCompactionPolicy, parsePiToolResultPruneConfig, parseSiftBridgeConfig, projectPromptPressure, deriveEffectiveWindow, projectSafeTelemetry, isContextOverflow, emptyContextPressureCounters, } from "../../../shared/pi-context-pressure/index.js";
|
|
54
54
|
import { incrementCounter as incrementPressureCounter } from "../../../shared/pi-context-pressure/telemetry.js";
|
|
55
55
|
import { resolveDefaultChatModel, resolveLowChatModel, } from "./model-resolver.js";
|
|
56
56
|
import { filterActiveInterviewTools } from "../interview/tools.js";
|
|
@@ -857,6 +857,10 @@ export class ConsolePiRuntime {
|
|
|
857
857
|
applyProcessCompactionOverride(manager, {
|
|
858
858
|
policy: parseCompactionPolicy(),
|
|
859
859
|
...(typeof window === "number" ? { contextWindow: window } : {}),
|
|
860
|
+
// Console should allow an explicit compact as soon as there is a
|
|
861
|
+
// previous turn. Pi's 20k default is a useful retention policy for
|
|
862
|
+
// the TUI, but becomes a hard "session too small" gate here.
|
|
863
|
+
keepRecentTokens: 0,
|
|
860
864
|
});
|
|
861
865
|
void sessionId;
|
|
862
866
|
}
|
|
@@ -903,7 +907,7 @@ export class ConsolePiRuntime {
|
|
|
903
907
|
try {
|
|
904
908
|
signal?.throwIfAborted();
|
|
905
909
|
incrementPressureCounter(controller.counters, "pre-prompt-threshold");
|
|
906
|
-
const result = await
|
|
910
|
+
const result = await this.compactWithOverflowFallback(sessionId, session, undefined, signal);
|
|
907
911
|
const snapshot = projectCompactSnapshot(result ?? {});
|
|
908
912
|
onEvent({
|
|
909
913
|
type: "compaction_end",
|
|
@@ -919,6 +923,13 @@ export class ConsolePiRuntime {
|
|
|
919
923
|
...(snapshot.tokensBefore === undefined
|
|
920
924
|
? {}
|
|
921
925
|
: { tokensBefore: snapshot.tokensBefore }),
|
|
926
|
+
...(snapshot.accounting ? {
|
|
927
|
+
shadowedTokenCount: snapshot.accounting.shadowedTokenCount,
|
|
928
|
+
replacementTokenCount: snapshot.accounting.replacementTokenCount,
|
|
929
|
+
netTokensFreed: snapshot.accounting.netTokensFreed,
|
|
930
|
+
accounting: snapshot.accounting.accounting,
|
|
931
|
+
shrinkProof: snapshot.accounting.shrinkProof,
|
|
932
|
+
} : {}),
|
|
922
933
|
});
|
|
923
934
|
}
|
|
924
935
|
catch (error) {
|
|
@@ -3424,9 +3435,33 @@ export class ConsolePiRuntime {
|
|
|
3424
3435
|
if (typeof session.compact !== "function")
|
|
3425
3436
|
throw new Error("COMPACTION_UNSUPPORTED");
|
|
3426
3437
|
incrementPressureCounter(this.getCompactionController(sessionId).counters, "manual");
|
|
3427
|
-
const result = await
|
|
3438
|
+
const result = await this.compactWithOverflowFallback(sessionId, session, customInstructions);
|
|
3428
3439
|
return projectCompactSnapshot(result ?? {});
|
|
3429
3440
|
}
|
|
3441
|
+
async compactWithOverflowFallback(sessionId, session, customInstructions, signal) {
|
|
3442
|
+
if (!session.compact)
|
|
3443
|
+
throw new Error("COMPACTION_UNSUPPORTED");
|
|
3444
|
+
const controller = this.getCompactionController(sessionId);
|
|
3445
|
+
// A fallback belongs to this invocation, never to the next user action.
|
|
3446
|
+
controller.manualCheckpointFallbackArmed = false;
|
|
3447
|
+
try {
|
|
3448
|
+
signal?.throwIfAborted();
|
|
3449
|
+
try {
|
|
3450
|
+
return await session.compact(customInstructions);
|
|
3451
|
+
}
|
|
3452
|
+
catch (error) {
|
|
3453
|
+
// Pi labels both explicit and Console pre-prompt calls "manual".
|
|
3454
|
+
// Retry once only when this summary request was rejected for size.
|
|
3455
|
+
if (signal?.aborted || !isContextOverflow(error) || !controller.manualCheckpointFallbackArmed) {
|
|
3456
|
+
throw error;
|
|
3457
|
+
}
|
|
3458
|
+
return await session.compact(customInstructions);
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
finally {
|
|
3462
|
+
controller.manualCheckpointFallbackArmed = false;
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3430
3465
|
listDatabaseConnections() {
|
|
3431
3466
|
return this.dbConnections.list();
|
|
3432
3467
|
}
|
|
@@ -3738,6 +3773,13 @@ export function mapSdkEvent(sessionId, event, compactionId, step = 1) {
|
|
|
3738
3773
|
: {
|
|
3739
3774
|
estimatedTokensAfter: snapshot.estimatedTokensAfter,
|
|
3740
3775
|
}),
|
|
3776
|
+
...(snapshot.accounting ? {
|
|
3777
|
+
shadowedTokenCount: snapshot.accounting.shadowedTokenCount,
|
|
3778
|
+
replacementTokenCount: snapshot.accounting.replacementTokenCount,
|
|
3779
|
+
netTokensFreed: snapshot.accounting.netTokensFreed,
|
|
3780
|
+
accounting: snapshot.accounting.accounting,
|
|
3781
|
+
shrinkProof: snapshot.accounting.shrinkProof,
|
|
3782
|
+
} : {}),
|
|
3741
3783
|
}
|
|
3742
3784
|
: {}),
|
|
3743
3785
|
willRetry: Boolean(event.willRetry),
|
|
@@ -3856,6 +3856,9 @@ export async function handleContextInsights(res, deps, sessionId) {
|
|
|
3856
3856
|
.map((name) => ({ id: name, description: "" }));
|
|
3857
3857
|
const insights = deriveContextInsights(snapshot, {
|
|
3858
3858
|
sessionId,
|
|
3859
|
+
contextPressure: typeof deps.runtime.getContextPressureTelemetry === "function"
|
|
3860
|
+
? deps.runtime.getContextPressureTelemetry(sessionId)
|
|
3861
|
+
: undefined,
|
|
3859
3862
|
...(systemPromptChars !== undefined ? { systemPromptChars } : {}),
|
|
3860
3863
|
...(systemPromptPreview !== undefined
|
|
3861
3864
|
? { systemPromptPreview }
|
|
@@ -5031,6 +5034,13 @@ export async function handleChatCompact(req, res, deps, sessionId) {
|
|
|
5031
5034
|
...(snapshot.estimatedTokensAfter === undefined
|
|
5032
5035
|
? {}
|
|
5033
5036
|
: { estimatedTokensAfter: snapshot.estimatedTokensAfter }),
|
|
5037
|
+
...(snapshot.accounting ? {
|
|
5038
|
+
shadowedTokenCount: snapshot.accounting.shadowedTokenCount,
|
|
5039
|
+
replacementTokenCount: snapshot.accounting.replacementTokenCount,
|
|
5040
|
+
netTokensFreed: snapshot.accounting.netTokensFreed,
|
|
5041
|
+
accounting: snapshot.accounting.accounting,
|
|
5042
|
+
shrinkProof: snapshot.accounting.shrinkProof,
|
|
5043
|
+
} : {}),
|
|
5034
5044
|
willRetry: false,
|
|
5035
5045
|
};
|
|
5036
5046
|
const event = deps.events.append(sessionId, turnId, {
|
|
@@ -83,6 +83,7 @@ export const PI_CHAT_SYSTEM_PROMPT_BASE = [
|
|
|
83
83
|
"Goal tools (get_goal / create_goal / update_goal) track the session's durable cross-turn objective. Create a Goal only when the user explicitly asks to start one; iterate in bounded rounds until complete or blocked.",
|
|
84
84
|
"schedule_create/list/update/delete manage durable reminders in this bound Chat. A due reminder first writes a durable inbox message, then drives a model turn that acts on it; a busy session skips that turn so the reminder is never lost or stolen from another Turn. Ask for an explicit IANA timezone for daily/weekly/cron or ambiguous local times. Deletion pauses for actual user confirmation.",
|
|
85
85
|
"This session keeps Console compression (L0/L1/L2, sift, strict checkpoint) and existing Aimax / SDD access. Do not create tasks, run DAGs, or start requirement interviews from this session.",
|
|
86
|
+
"Treat compressed or omitted tool output (such as <<stash:...>>, lines omitted, or tool result middle pruned) as incomplete. Before an exact file edit, read a narrow range or use sift_retrieve to recover the source, then verify the exact file before editing.",
|
|
86
87
|
"Obey repository AGENTS.md, skills and extensions when they apply. Choosing Pi mode is not extra write authorization and does not bypass Console access control or output scrubbing.",
|
|
87
88
|
].join("\n");
|
|
88
89
|
export const CHAT_SAFE_EXPLORE_TOOL_IDS = Object.freeze([
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* GET /terminals/:id session info + buffered output
|
|
8
8
|
* POST /terminals/:id/input { data } write to the PTY
|
|
9
9
|
* POST /terminals/:id/resize { cols, rows }
|
|
10
|
+
* POST /terminals/:id/rename { name }
|
|
10
11
|
* POST /terminals/:id/interrupt send Ctrl+C
|
|
11
12
|
* POST /terminals/:id/kill stop and await full exit
|
|
12
13
|
* GET /terminals/:id/stream SSE: buffered replay + live chunks
|
|
@@ -75,7 +76,9 @@ export async function handleTerminalRequest(req, res, deps, pathname) {
|
|
|
75
76
|
sendJson(res, 200, {
|
|
76
77
|
ok: true,
|
|
77
78
|
data: {
|
|
78
|
-
|
|
79
|
+
// The workbench lists only its own shells; model tool PTYs must not
|
|
80
|
+
// appear as tabs or stream their command output into this panel.
|
|
81
|
+
terminals: deps.terminals.list("console-ui"),
|
|
79
82
|
availableShells: availableShellKinds().kinds,
|
|
80
83
|
defaultShell: preferredShellKind(),
|
|
81
84
|
hostPlatform: process.platform,
|
|
@@ -195,6 +198,17 @@ export async function handleTerminalRequest(req, res, deps, pathname) {
|
|
|
195
198
|
sendJson(res, 200, { ok: true });
|
|
196
199
|
return true;
|
|
197
200
|
}
|
|
201
|
+
if (method === "POST" && sub === "rename" && parts.length === 2) {
|
|
202
|
+
const body = await readJsonBody(req);
|
|
203
|
+
const name = typeof body.name === "string" ? body.name.trim() : "";
|
|
204
|
+
if (!name || name.length > 60) {
|
|
205
|
+
sendJson(res, 400, { ok: false, error: { code: "INVALID_INPUT", message: "name (1..60 chars) is required" } });
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const info = deps.terminals.rename(sessionId, name);
|
|
209
|
+
sendJson(res, 200, { ok: true, data: info });
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
198
212
|
if (method === "POST" && sub === "interrupt" && parts.length === 2) {
|
|
199
213
|
deps.terminals.interrupt(sessionId);
|
|
200
214
|
sendJson(res, 200, { ok: true });
|
|
@@ -327,6 +327,12 @@ export class TerminalSessionRegistry {
|
|
|
327
327
|
return;
|
|
328
328
|
entry.pty.write("\x03");
|
|
329
329
|
}
|
|
330
|
+
/** Rename a session (display label only). */
|
|
331
|
+
rename(sessionId, name) {
|
|
332
|
+
const entry = this.mustGet(sessionId);
|
|
333
|
+
entry.info.name = name;
|
|
334
|
+
return { ...entry.info };
|
|
335
|
+
}
|
|
330
336
|
/** Kill and wait for full stop, then remove the registry entry so closed
|
|
331
337
|
* terminals disappear from the list (explicit close = forget). Idempotent. */
|
|
332
338
|
async kill(sessionId) {
|
|
@@ -5,8 +5,14 @@
|
|
|
5
5
|
* structural raw HTML cards directly into the assistant message stream.
|
|
6
6
|
*/
|
|
7
7
|
export function buildVcpSystemPrompt(styleSlug = "auto") {
|
|
8
|
-
const base = `## VCP
|
|
9
|
-
|
|
8
|
+
const base = `## VCP 视觉通感协议(可选输出能力)
|
|
9
|
+
VCP 已启用,但它不是默认输出格式。每次回答先在内部选择 Markdown 或 HTML,不要输出选择过程;如果两者都能清楚表达,优先 Markdown。
|
|
10
|
+
|
|
11
|
+
【先选择输出形式】
|
|
12
|
+
- 优先使用 Markdown:短答、问答、解释、步骤、代码、差异、日志、错误诊断、引用资料、需要快速返回的内容,以及主要由文字组成的普通列表。
|
|
13
|
+
- 选择 HTML 卡片:用户明确要求视觉卡片、HTML、看板或可下载页面;或内容确实需要仪表盘、指标汇总、对比矩阵、时间线、状态面板、图表/流程图、分组信息和明确的视觉层级才能更快理解。
|
|
14
|
+
- 不要因为内容“有结构”就套 HTML。若卡片只是把几段文字换成带边框的容器,使用 Markdown 更快、更省上下文,也更易复制。
|
|
15
|
+
- 如果选择 HTML,可以先用一两句 Markdown 说明,再输出一张卡片;不要同时用 Markdown 和 HTML 重复整份内容。除非用户要求,否则不要为简单回复生成卡片。
|
|
10
16
|
|
|
11
17
|
【输出规则】
|
|
12
18
|
- 卡片必须直接输出裸 HTML,不要使用 Markdown 代码围栏;根节点固定为 \`<div id="vcp-root">\`。
|
|
@@ -42,7 +48,7 @@ export function buildVcpSystemPrompt(styleSlug = "auto") {
|
|
|
42
48
|
};
|
|
43
49
|
const hint = styleHints[styleSlug];
|
|
44
50
|
if (hint) {
|
|
45
|
-
return `${base}\n\n${hint}\n
|
|
51
|
+
return `${base}\n\n${hint}\n仅当你已经选择 HTML 卡片时,才采用该美学风格组织卡片的骨架、色板与排版;选择 Markdown 时不要为了套用风格而生成卡片。`;
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
return base;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-
|
|
1
|
+
import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-D8UjJk_C.js";import{p as f}from"./chunk-JWPE2WC7-DIdHATyu.js";import{_ as n,l as o}from"./mermaid.core-B61abuWa.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-CC8nJgvv.js";import"./index-BlNf823_.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},B={parser:R,db:a,renderer:u,styles:p};export{B as diagram};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Y as ln,$ as an,a0 as F,a1 as q,a2 as j,a3 as un,a4 as y,a5 as tn,a6 as J,a7 as _,a8 as rn,a9 as o,aa as on,ab as sn,ac as fn}from"./mermaid.core-
|
|
1
|
+
import{Y as ln,$ as an,a0 as F,a1 as q,a2 as j,a3 as un,a4 as y,a5 as tn,a6 as J,a7 as _,a8 as rn,a9 as o,aa as on,ab as sn,ac as fn}from"./mermaid.core-B61abuWa.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,z,a){var O=I-l,i=D-h,n=z-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function U(l,h,I,D,v,A,z){var a=l-I,O=h-D,i=(z?A:-A)/J(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,B=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*J(on(0,T*T*R-P*P)),Y=(P*g-m*S)/R,$=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=Y-B,e=$-t,r=w-B,C=p-t;return x*x+e*e>r*r+C*C&&(Y=w,$=p),{cx:Y,cy:$,x01:-n,y01:-d,x11:Y*(v/T-1),y11:$*(v/T-1)}}function hn(){var l=cn,h=yn,I=j(0),D=null,v=gn,A=dn,z=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,B=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(B>tn-y)a.moveTo(s*F(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*F(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=B,S=B,Y=z.apply(this,arguments)/2,$=Y>y&&(D?+D.apply(this,arguments):J(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if($>y){var C=sn($/u*q(Y)),K=sn($/s*q(Y));(P-=C*2)>y?(C*=t?1:-1,R+=C,T-=C):(P=0,R=T=(f+c)/2),(S-=K*2)>y?(K*=t?1:-1,m+=K,g-=K):(S=0,m=g=(f+c)/2)}var G=s*F(m),H=s*q(m),L=u*F(T),M=u*q(T);if(w>y){var N=s*F(g),Q=s*q(g),V=u*F(R),W=u*q(R),E;if(B<an)if(E=pn(G,H,V,W,N,Q,L,M)){var X=G-E[0],Z=H-E[1],b=N-E[0],k=Q-E[1],nn=1/q(fn((X*b+Z*k)/(J(X*X+Z*Z)*J(b*b+k*k)))/2),en=J(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=U(V,W,G,H,s,x,t),r=U(N,Q,L,M,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(G,H),a.arc(0,0,s,m,g,!t)):a.moveTo(G,H),!(u>y)||!(P>y)?a.lineTo(L,M):p>y?(e=U(L,M,N,Q,u,-p,t),r=U(G,H,V,W,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[F(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:j(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:j(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:j(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:j(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:j(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:j(+n),i):A},i.padAngle=function(n){return arguments.length?(z=typeof n=="function"?n:j(+n),i):z},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
|