@tea-agent/loop-agent 0.52.0-next.6 → 0.52.0-next.8

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/build-stamp.json +3 -3
  3. package/dist/worker/console/chat/context-insights.js +37 -0
  4. package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +2 -2
  5. package/dist/worker/console/chat/routes.js +22 -38
  6. package/dist/worker/console/chat/terminal-sessions.js +10 -4
  7. package/dist/worker/console/chat/tool-presentation.js +17 -10
  8. package/dist/worker/console/chat/turn-process.js +7 -12
  9. package/dist/worker/console/chat/workspace-changes.js +3 -133
  10. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-BiFM8_eW.js → abnfDiagram-N423BO3Z-BeB0jyn_.js} +1 -1
  11. package/dist/worker/console/static/assets/{arc-Ci4EnVJs.js → arc-B4E8rogW.js} +1 -1
  12. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-C9Hnq824.js → architectureDiagram-T3A2C74G-CuD5BPrV.js} +1 -1
  13. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Erza3vCj.js → blockDiagram-VBNYF7ZC-DOR4BrbY.js} +1 -1
  14. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-DhiEJ_zn.js → c4Diagram-5PPSVZJV-GuWkFUBT.js} +1 -1
  15. package/dist/worker/console/static/assets/channel-DFwPpXxz.js +1 -0
  16. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-Jwoe5Hha.js → chunk-2GRJ4B5K-Bvp_6a1j.js} +1 -1
  17. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-B2p-ASWD.js → chunk-2Q5K7J3B-zgyCBGFw.js} +1 -1
  18. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-CinVrkm9.js → chunk-5RXB4S5H-Bd7_XVhV.js} +1 -1
  19. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-DPEKo8K0.js → chunk-5VM5RSS4-CO5JbujI.js} +1 -1
  20. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-BWkVY9W5.js → chunk-6Q2QTUOP-DPb24xsc.js} +1 -1
  21. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-CMFm2SFJ.js → chunk-GF5L2VYU-D4OKjlIA.js} +1 -1
  22. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Du_X-MSA.js → chunk-JWPE2WC7-BdtF1gRX.js} +1 -1
  23. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-cTlf6fnC.js → chunk-KBJHAD2P-cSxCzmVA.js} +1 -1
  24. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-C5ve9fxF.js → chunk-RYQCIY6F-De4Oormb.js} +1 -1
  25. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-CRxS8vXT.js → chunk-XXDRQBXY-CMIvrR5C.js} +1 -1
  26. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-D9pWfL1L.js +1 -0
  27. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-D9pWfL1L.js +1 -0
  28. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BEnyQAzp.js → cose-bilkent-JH36ORCC-9SmHPXIr.js} +1 -1
  29. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-DvPiK5od.js → cynefinDiagram-MW4NZA55-wl-77tI0.js} +1 -1
  30. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-DxigWx8E.js → dagre-VZM6K2ZE-yqj9yJJQ.js} +1 -1
  31. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-D50wvAbw.js → diagram-7IWD3JNH-D-rMYS98.js} +1 -1
  32. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-B6PmMJzk.js → diagram-B4RE2ZJO-CQFAofzl.js} +1 -1
  33. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-BbT1ZLia.js → diagram-LBJQPF4R-CfUQmVKd.js} +1 -1
  34. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-CizMPXm7.js → diagram-Q27KOJAE-BkK1xnZN.js} +1 -1
  35. package/dist/worker/console/static/assets/{diagram-UB23O5K3-DjxNSFmF.js → diagram-UB23O5K3-BQQRT4QA.js} +1 -1
  36. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-Bwg25Xpv.js → ebnfDiagram-BXEA7PRR--rItMGHc.js} +1 -1
  37. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-aHHIkVbd.js → erDiagram-JOGREHBK-YO3gwIVo.js} +1 -1
  38. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-CBQFor5-.js → flowDiagram-UKHOOZJN-sVlorROr.js} +1 -1
  39. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-Bhv0b_Ay.js → ganttDiagram-PKOTCBZU-DRBbNi-x.js} +1 -1
  40. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-CcTjAWTv.js → gitGraphDiagram-DS77QQ5N-D0VaAfPP.js} +1 -1
  41. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-Bwt6_MRI.js → infoDiagram-6WML65LV-DtHpfgsg.js} +1 -1
  42. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-JcDN-oJ0.js → ishikawaDiagram-WSZJBQD7-Ea8r9FLd.js} +1 -1
  43. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-C7YA3mW8.js → journeyDiagram-NVQOT4AX-CVJVcKLc.js} +1 -1
  44. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-CfgSiedW.js → kanban-definition-27J2QSJJ-CUdymoGj.js} +1 -1
  45. package/dist/worker/console/static/assets/{linear-Dy5YZwCe.js → linear-D5880Sph.js} +1 -1
  46. package/dist/worker/console/static/assets/{main-D39kbkZI.js → main-2IXI34Fw.js} +132 -132
  47. package/dist/worker/console/static/assets/main-Ckf7id9T.css +1 -0
  48. package/dist/worker/console/static/assets/{mermaid.core-CWATftfi.js → mermaid.core-D6dkYx5V.js} +4 -4
  49. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-DXcCCbEa.js → mindmap-definition-FAOFIHXS-DhZljSlQ.js} +1 -1
  50. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-CoS0ZgLy.js → pegDiagram-VL7TDLO6-2S30TPom.js} +1 -1
  51. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-DotRKEI5.js → pieDiagram-7S7Q4E2Y-B9y_krb1.js} +1 -1
  52. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-DMdkO7Rz.js → quadrantDiagram-CIZ2JOQS-C-XgJLT_.js} +1 -1
  53. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-rj-Qc0fo.js → railroadDiagram-AXF67PYL-CTeVrhCo.js} +1 -1
  54. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DDBta62g.js → requirementDiagram-LRYGKXZP-B7K6JWmy.js} +1 -1
  55. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-DWqZxqI8.js → sankeyDiagram-W5VNT64P-QAlLfn7A.js} +1 -1
  56. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-C0fVeYqG.js → sequenceDiagram-SI44F4Z6-BdWZWKdx.js} +1 -1
  57. package/dist/worker/console/static/assets/{sheet-workbook-CNv6AzfM.js → sheet-workbook-BoC0pAy2.js} +1 -1
  58. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-DOvvHUh-.js → sizeCapture-X5ZJPWSS-D6ASD67I.js} +1 -1
  59. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-DgqVm117.js → stateDiagram-OKZ733FA-C3MgmUi2.js} +1 -1
  60. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BEwsMVdO.js +1 -0
  61. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-C6H8hfVq.js → swimlanes-SLNWSIFB-Dqrd-WNB.js} +2 -2
  62. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-D9l9u9WV.js +8 -0
  63. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-DyUP-YKn.js → timeline-definition-Z64GVDOM-lQftYLJh.js} +1 -1
  64. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-CwY3bnAh.js → vennDiagram-T6HMQDX7-WA2DaCGk.js} +1 -1
  65. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-DE1T6Hko.js → wardleyDiagram-T6FBY63Y-CFpLw8Jh.js} +1 -1
  66. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-C0h8BPyy.js → xychartDiagram-ELKLHX3M-zgM9I8sM.js} +1 -1
  67. package/dist/worker/console/static/index.html +2 -2
  68. package/dist/worker/console/static-src/operator-chat/user-turn-anchors-merge.js +50 -0
  69. package/package.json +3 -3
  70. package/dist/worker/console/static/assets/channel-o866H8CG.js +0 -1
  71. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-iDhRZSeN.js +0 -1
  72. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-iDhRZSeN.js +0 -1
  73. package/dist/worker/console/static/assets/main-C537vZah.css +0 -1
  74. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-8zVknfpQ.js +0 -1
  75. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BTTCojly.js +0 -8
package/CHANGELOG.md CHANGED
@@ -41,7 +41,7 @@
41
41
  - 修复任务管理把已收起的子代理仍然画在图上,导致聚合卡片和成员卡片同时出现、连线交叉杂乱的问题。
42
42
  - 修复点击子代理详情后跳到仓库文件页而不是子代理内容的问题。
43
43
 
44
- ## [0.52.0-next.6] - 2026-10-21
44
+ ## [0.52.0-next.8] - 2026-10-21
45
45
 
46
46
  本预发布快照记录构建时已整理的待发布变化,不表示相对上一构建全部新增。
47
47
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "version": "0.52.0-next.6",
4
- "gitSha": "e1881b3b681c5af2e87f2541f709dbcd87636343",
5
- "builtAt": "2026-10-20T17:00:00.683Z"
3
+ "version": "0.52.0-next.8",
4
+ "gitSha": "9198f0bff8281bf542660d51412f3379a7e2a951",
5
+ "builtAt": "2026-10-21T15:49:45.275Z"
6
6
  }
@@ -673,6 +673,43 @@ export function deriveContextInsights(events, options = {}) {
673
673
  contextEvents.push(contextEvent);
674
674
  if (pruned && typeof data.pruneId === "string")
675
675
  pruneEventsById.set(data.pruneId, contextEvent);
676
+ /*
677
+ * A compaction replaces the oldest prefix of the live surface.
678
+ *
679
+ * Pi reports the size of what it removed (`shadowedTokenCount`)
680
+ * but never the event seqs, and `firstKeptEntryId` is an opaque
681
+ * entry identity — so the exact node set cannot be claimed the
682
+ * way a pruner's `shadowedSeqs` allows. Without this, the ledger
683
+ * kept counting the consumed messages forever and the trend line
684
+ * showed no drop at the compaction, even though the event and its
685
+ * ✂ mark were present.
686
+ *
687
+ * `liveNodes` is appended in event order, so consuming from the
688
+ * front reproduces "the oldest prefix was summarized". The
689
+ * accounting only runs on `compaction_end`, once the size is
690
+ * known; `compaction_start` carries none.
691
+ */
692
+ if (!pruned && event.kind === "compaction_end") {
693
+ const freed = accounting.shadowedTokenCount;
694
+ if (typeof freed === "number" && freed > 0) {
695
+ const consumed = [];
696
+ let remaining = freed;
697
+ let prefix = 0;
698
+ while (remaining > 0 && prefix < liveNodes.length) {
699
+ remaining -= liveNodes[prefix].tokens;
700
+ prefix += 1;
701
+ }
702
+ for (let i = 0; i < prefix; i += 1)
703
+ consumed.push(liveNodes[i].seq);
704
+ if (consumed.length > 0) {
705
+ removedIds = claimNodes(new Set(consumed), event.seq);
706
+ if (removedIds.length > 0)
707
+ removalBasis = "seqs";
708
+ contextEvent.removedIds = removedIds;
709
+ contextEvent.removalBasis = "seqs";
710
+ }
711
+ }
712
+ }
676
713
  const lastStep = trend.at(-1);
677
714
  if (lastStep && event.kind !== "compaction_start") {
678
715
  lastStep.eventMark = pruned ? "prune" : "compact";
@@ -142,12 +142,12 @@ export async function buildBrowserTools(options) {
142
142
  }
143
143
  return p.observe ? automation.act(request, undefined, p.observe) : automation.act(request);
144
144
  }),
145
- tool("browser_tabs", "List/new/select/close tabs. Use an explicit tabId to select or close. A closed/busy tab can be closed explicitly; then select or create a new tab.", Type.Union([
145
+ tool("browser_tabs", "List/new/select/close tabs. Use an explicit tabId to select or close. A closed/busy tab can be closed explicitly; then select or create a new tab.", Object.assign(Type.Union([
146
146
  object({ action: Type.Literal("list"), ...target }),
147
147
  object({ action: Type.Literal("new"), ...target, url: Type.Optional(url), ...unscopedCompletion }),
148
148
  object({ action: Type.Literal("select"), tabId: Type.Integer({ minimum: 1 }), ...scopedCompletion }),
149
149
  object({ action: Type.Literal("close"), tabId: Type.Integer({ minimum: 1 }), ...unscopedCompletion }),
150
- ]), async (p) => {
150
+ ]), { type: "object" }), async (p) => {
151
151
  if (p.action === "list") {
152
152
  if (record(p).observe !== undefined)
153
153
  throw Object.assign(new Error("list does not perform an implicit observation"), { code: "INVALID_OBSERVATION" });
@@ -11,7 +11,8 @@ import { cleanChatTitle, isBlankChatSession } from "./session-store.js";
11
11
  import { projectUserTurnOutline } from "./user-turn-outline.js";
12
12
  import { hashChatTurnPayload, projectCompactSnapshot, } from "./chat-event-store.js";
13
13
  import { fileToolPreview, toolRecord } from "./tool-presentation.js";
14
- import { captureWorkspaceBaseline, captureWorkspaceChanges, fallbackWorkspaceChanges } from "./workspace-changes.js";
14
+ import { projectFileResult } from "./tool-presentation-projection.js";
15
+ import { summarizeTurnFileEdits } from "./workspace-changes.js";
15
16
  import { projectDeferredTurnSummary, projectDeferredTurnSummaries, } from "./deferred-turn.js";
16
17
  import { THINKING_LEVELS, RuntimeSnapshotUnavailableError, } from "./pi-runtime.js";
17
18
  import { ResourcePreferencesError, setSkillAutoInvocationPreference, } from "./resource-preferences-store.js";
@@ -355,25 +356,25 @@ function ensureAgentEndEvent(deps, sessionId, turnId) {
355
356
  });
356
357
  }
357
358
  }
358
- function recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles) {
359
+ function recordTurnFileMutation(event, editToolPaths, editedFiles) {
359
360
  if (event.type === "tool_call" && (event.toolName === "edit" || event.toolName === "write")) {
360
361
  const args = toolRecord(event.args);
361
362
  const path = typeof args?.path === "string" ? args.path : typeof args?.file_path === "string" ? args.file_path : "";
362
363
  if (path && typeof event.toolCallId === "string") {
363
- fallbackToolPaths.set(event.toolCallId, path);
364
+ editToolPaths.set(event.toolCallId, path);
364
365
  }
365
366
  return;
366
367
  }
367
- if (event.type === "tool_result" && !event.isError && (event.toolName === "edit" || event.toolName === "write")) {
368
+ if (event.type === "tool_result" && !event.isError && !event.interrupted && (event.toolName === "edit" || event.toolName === "write")) {
368
369
  const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : "";
369
- const rawPath = fallbackToolPaths.get(toolCallId) ?? "";
370
+ const rawPath = editToolPaths.get(toolCallId) ?? "";
370
371
  if (!rawPath)
371
372
  return;
372
373
  const display = rawPath.replace(/\\/g, "/");
373
- const preview = fileToolPreview(event.result);
374
+ const preview = fileToolPreview(event.result) ?? fileToolPreview(projectFileResult(event.toolName, event.result));
374
375
  const added = preview?.added ?? 0;
375
376
  const deleted = preview?.removed ?? 0;
376
- const existing = fallbackFiles.get(display);
377
+ const existing = editedFiles.get(display);
377
378
  if (existing) {
378
379
  existing.added += added;
379
380
  existing.deleted += deleted;
@@ -382,7 +383,7 @@ function recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles) {
382
383
  }
383
384
  }
384
385
  else {
385
- fallbackFiles.set(display, {
386
+ editedFiles.set(display, {
386
387
  path: rawPath,
387
388
  display,
388
389
  added,
@@ -393,24 +394,12 @@ function recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles) {
393
394
  }
394
395
  }
395
396
  }
396
- async function resolveTurnWorkspaceChanges(input) {
397
- const toolFiles = [...input.fallbackFiles.values()];
398
- if (input.workspaceBaseline) {
399
- const snapshot = await captureWorkspaceChanges({
400
- baseline: input.workspaceBaseline,
401
- sessionId: input.sessionId,
402
- turnId: input.turnId,
403
- turnNumber: input.turnNumber,
404
- failedTurn: input.failedTurn,
405
- toolFiles,
406
- }).catch(() => undefined);
407
- if (snapshot)
408
- return snapshot;
409
- }
410
- return fallbackWorkspaceChanges({
397
+ function resolveTurnWorkspaceChanges(input) {
398
+ return summarizeTurnFileEdits({
411
399
  sessionId: input.sessionId,
412
400
  turnId: input.turnId,
413
- files: toolFiles,
401
+ turnNumber: input.turnNumber,
402
+ files: [...input.editedFiles.values()],
414
403
  failedTurn: input.failedTurn,
415
404
  });
416
405
  }
@@ -2542,7 +2531,6 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
2542
2531
  return;
2543
2532
  }
2544
2533
  const turnId = createdTurn.turn.turnId;
2545
- const workspaceBaseline = await captureWorkspaceBaseline(deps.appData.repoRoot).catch(() => undefined);
2546
2534
  deps.events.setTurnState(sessionId, turnId, "running");
2547
2535
  // Stream events via SSE. Each event is FIRST persisted to the chat event
2548
2536
  // ring (so a reconnect via GET /events can resume by Last-Event-ID), THEN
@@ -2563,8 +2551,8 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
2563
2551
  // Lazily import to avoid circular module load.
2564
2552
  const { runChatTurn } = await import("./session-store.js");
2565
2553
  let firstUserText;
2566
- const fallbackFiles = new Map();
2567
- const fallbackToolPaths = new Map();
2554
+ const editedFiles = new Map();
2555
+ const editToolPaths = new Map();
2568
2556
  try {
2569
2557
  const outcome = await runChatTurn({
2570
2558
  runtime: deps.runtime,
@@ -2624,7 +2612,7 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
2624
2612
  return;
2625
2613
  }
2626
2614
  recordRequestEventFact(deps, sessionId, turnId, event);
2627
- recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles);
2615
+ recordTurnFileMutation(event, editToolPaths, editedFiles);
2628
2616
  const partial = turnEventToStorePartial(event);
2629
2617
  if (!partial)
2630
2618
  return;
@@ -2635,11 +2623,10 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
2635
2623
  });
2636
2624
  const appendWorkspaceChanges = async (failedTurn) => {
2637
2625
  const summary = await resolveTurnWorkspaceChanges({
2638
- workspaceBaseline,
2639
2626
  sessionId,
2640
2627
  turnId,
2641
2628
  turnNumber: createdTurn.turn.ordinal,
2642
- fallbackFiles,
2629
+ editedFiles,
2643
2630
  failedTurn,
2644
2631
  });
2645
2632
  if (!summary)
@@ -2673,11 +2660,10 @@ export async function handleChatPrompt(req, res, deps, sessionId) {
2673
2660
  const message = error instanceof Error ? error.message : String(error);
2674
2661
  {
2675
2662
  const summary = await resolveTurnWorkspaceChanges({
2676
- workspaceBaseline,
2677
2663
  sessionId,
2678
2664
  turnId,
2679
2665
  turnNumber: createdTurn.turn.ordinal,
2680
- fallbackFiles,
2666
+ editedFiles,
2681
2667
  failedTurn: true,
2682
2668
  });
2683
2669
  if (summary) {
@@ -2934,16 +2920,14 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
2934
2920
  // Abort ownership lives in the execution registry (real Stop path).
2935
2921
  void (async () => {
2936
2922
  const { runChatTurn } = await import("./session-store.js");
2937
- const workspaceBaseline = await captureWorkspaceBaseline(deps.appData.repoRoot).catch(() => undefined);
2938
- const fallbackFiles = new Map();
2939
- const fallbackToolPaths = new Map();
2923
+ const editedFiles = new Map();
2924
+ const editToolPaths = new Map();
2940
2925
  const appendWorkspaceChanges = async (failedTurn) => {
2941
2926
  const summary = await resolveTurnWorkspaceChanges({
2942
- workspaceBaseline,
2943
2927
  sessionId,
2944
2928
  turnId: turn.turnId,
2945
2929
  turnNumber: turn.ordinal,
2946
- fallbackFiles,
2930
+ editedFiles,
2947
2931
  failedTurn,
2948
2932
  });
2949
2933
  if (summary)
@@ -2992,7 +2976,7 @@ export async function handleCreateChatTurn(req, res, deps, sessionId, trustedPay
2992
2976
  if (event.type === "heartbeat")
2993
2977
  return;
2994
2978
  recordRequestEventFact(deps, sessionId, turn.turnId, event);
2995
- recordTurnFileMutation(event, fallbackToolPaths, fallbackFiles);
2979
+ recordTurnFileMutation(event, editToolPaths, editedFiles);
2996
2980
  const partial = turnEventToStorePartial(event);
2997
2981
  if (partial)
2998
2982
  deps.events.append(sessionId, turn.turnId, partial);
@@ -328,13 +328,19 @@ export class TerminalSessionRegistry {
328
328
  /** Full buffered output (post-trim prefix may be incomplete). */
329
329
  readAll(sessionId) {
330
330
  const entry = this.mustGet(sessionId);
331
- let text = entry.buffer.join("");
332
- // If the caller reads before any real PTY output has arrived, the
333
- // banner injection in onData hasn't fired yet — fold it in here.
331
+ /*
332
+ * If the caller reads before any real PTY output has arrived, the banner
333
+ * injection in onData hasn't fired yet. Fold it into the BUFFER, not just
334
+ * this response: consuming it here used to drop the banner for every
335
+ * later read, so a reader who opened the panel once and refreshed saw a
336
+ * terminal that had silently lost its startup banner.
337
+ */
334
338
  if (entry.pendingBanner !== undefined) {
335
- text = entry.pendingBanner + text;
339
+ entry.buffer.unshift(entry.pendingBanner);
340
+ entry.bufferChars += entry.pendingBanner.length;
336
341
  entry.pendingBanner = undefined;
337
342
  }
343
+ const text = entry.buffer.join("");
338
344
  return {
339
345
  text,
340
346
  truncated: entry.info.totalOutputChars > entry.bufferChars,
@@ -12,22 +12,29 @@ export function toolRecord(value) {
12
12
  export function patchRows(patch) {
13
13
  const lines = patch.replace(/\r\n/g, "\n").split("\n");
14
14
  let inHunk = false;
15
+ let oldLine, newLine;
15
16
  const rows = [];
16
17
  for (const line of lines) {
17
18
  if (line.startsWith("@@")) {
19
+ const header = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
18
20
  if (inHunk)
19
21
  rows.push({ kind: "gap", text: "⋯" });
22
+ oldLine = header ? Number(header[1]) : undefined;
23
+ newLine = header ? Number(header[2]) : undefined;
20
24
  inHunk = true;
21
25
  continue;
22
26
  }
23
27
  if (!inHunk)
24
28
  continue;
25
- if (line.startsWith("+"))
26
- rows.push({ kind: "add", text: line.slice(1) });
27
- else if (line.startsWith("-"))
28
- rows.push({ kind: "del", text: line.slice(1) });
29
- else if (line.startsWith(" "))
30
- rows.push({ kind: "context", text: line.slice(1) });
29
+ if (line.startsWith("+")) {
30
+ rows.push({ kind: "add", text: line.slice(1), ...(newLine !== undefined ? { newLine: newLine++ } : {}) });
31
+ }
32
+ else if (line.startsWith("-")) {
33
+ rows.push({ kind: "del", text: line.slice(1), ...(oldLine !== undefined ? { oldLine: oldLine++ } : {}) });
34
+ }
35
+ else if (line.startsWith(" ")) {
36
+ rows.push({ kind: "context", text: line.slice(1), ...(oldLine !== undefined ? { oldLine: oldLine++ } : {}), ...(newLine !== undefined ? { newLine: newLine++ } : {}) });
37
+ }
31
38
  }
32
39
  return rows;
33
40
  }
@@ -43,10 +50,10 @@ export function replacementRows(before, after) {
43
50
  if (head === oldLines.length && head === newLines.length)
44
51
  return before === after ? [] : [{ kind: "gap", text: "仅换行格式或末尾换行发生变化" }];
45
52
  return [
46
- ...oldLines.slice(Math.max(0, head - 3), head).map(text => ({ kind: "context", text })),
47
- ...oldLines.slice(head, oldLines.length - tail).map(text => ({ kind: "del", text })),
48
- ...newLines.slice(head, newLines.length - tail).map(text => ({ kind: "add", text })),
49
- ...newLines.slice(newLines.length - tail, newLines.length - tail + 3).map(text => ({ kind: "context", text })),
53
+ ...oldLines.slice(Math.max(0, head - 3), head).map((text, i) => ({ kind: "context", text, oldLine: Math.max(0, head - 3) + i + 1, newLine: Math.max(0, head - 3) + i + 1 })),
54
+ ...oldLines.slice(head, oldLines.length - tail).map((text, i) => ({ kind: "del", text, oldLine: head + i + 1 })),
55
+ ...newLines.slice(head, newLines.length - tail).map((text, i) => ({ kind: "add", text, newLine: head + i + 1 })),
56
+ ...newLines.slice(newLines.length - tail, newLines.length - tail + 3).map((text, i) => ({ kind: "context", text, oldLine: oldLines.length - tail + i + 1, newLine: newLines.length - tail + i + 1 })),
50
57
  ];
51
58
  }
52
59
  export function fileToolPreview(value) {
@@ -6,6 +6,7 @@ import { dagProgressActivityForTool, semanticActivityForTool, } from "./semantic
6
6
  import { compareChatOrder } from "./turn-order.js";
7
7
  import { ensureLinkedSubmissionOrder } from "./timeline-message-order.js";
8
8
  import { fileToolPreview, toolRecord } from "./tool-presentation.js";
9
+ import { summarizeTurnFileEdits } from "./workspace-changes.js";
9
10
  /** Cumulative argument updates may refresh preparing calls, never regress dispatched/settled ones. */
10
11
  export function upsertPreparingTools(existing, content, meta) {
11
12
  let next = existing;
@@ -544,19 +545,12 @@ function deriveToolWorkspaceChanges(group) {
544
545
  });
545
546
  }
546
547
  }
547
- if (byDisplay.size === 0)
548
- return undefined;
549
- const files = [...byDisplay.values()].sort((a, b) => a.display.localeCompare(b.display));
550
- return {
548
+ return summarizeTurnFileEdits({
551
549
  sessionId: "",
552
550
  turnId: group.turnId ?? group.key,
553
- files,
554
- total: files.length,
555
- added: files.reduce((sum, file) => sum + file.added, 0),
556
- deleted: files.reduce((sum, file) => sum + file.deleted, 0),
557
- source: "tool-fallback",
558
- ...(group.turnState === "failed" || group.turnState === "aborted" ? { failedTurn: true } : {}),
559
- };
551
+ files: [...byDisplay.values()],
552
+ failedTurn: group.turnState === "failed" || group.turnState === "aborted",
553
+ });
560
554
  }
561
555
  export function buildTurnProcessGroups(input) {
562
556
  const visible = ensureLinkedSubmissionOrder(input.messages
@@ -696,8 +690,9 @@ export function buildTurnProcessGroups(input) {
696
690
  group.conversationItems = (input.conversationNodes ?? [])
697
691
  .filter((node) => node.location.kind !== "session" && node.location.turnId === group.turnId)
698
692
  .map((node) => ({ kind: node.kind, node }));
693
+ // Old Git snapshots and fallback counts do not prove this turn edited these files.
699
694
  group.workspaceChanges =
700
- (group.turnId ? input.workspaceChanges?.find(item => item.turnId === group.turnId) : undefined) ??
695
+ (group.turnId ? input.workspaceChanges?.find(item => item.turnId === group.turnId && item.source === "tool-events") : undefined) ??
701
696
  deriveToolWorkspaceChanges(group);
702
697
  if (group.conversationItems.some((item) => item.kind === "turn-error")) {
703
698
  group.processItems = group.processItems.filter((item) => item.kind !== "provider-error");
@@ -1,138 +1,8 @@
1
- import { execFile } from "node:child_process";
2
- import { createHash } from "node:crypto";
3
- import { readFile } from "node:fs/promises";
4
- import { resolve } from "node:path";
5
- import { promisify } from "node:util";
6
- const execFileAsync = promisify(execFile);
7
- const MAX_OUTPUT = 8 * 1024 * 1024;
8
- function parseStatus(output) {
9
- const result = new Map();
10
- for (const record of output.split("\0")) {
11
- if (!record || record.length < 4)
12
- continue;
13
- const code = record.slice(0, 2);
14
- const rawPath = record.slice(3).trim();
15
- if (!rawPath)
16
- continue;
17
- const path = rawPath.includes(" -> ") ? rawPath.split(" -> ").at(-1) : rawPath;
18
- const status = code.includes("??") ? "added" : code.includes("D") ? "deleted" : code.includes("R") ? "renamed" : "modified";
19
- result.set(path.replace(/\\/g, "/"), status);
20
- }
21
- return result;
22
- }
23
- function parseNumstat(output) {
24
- const result = new Map();
25
- for (const line of output.split(/\r?\n/)) {
26
- if (!line.trim())
27
- continue;
28
- const parts = line.split("\t");
29
- if (parts.length < 3)
30
- continue;
31
- const path = parts.slice(2).at(-1).replace(/\\/g, "/");
32
- const binary = parts[0] === "-" || parts[1] === "-";
33
- result.set(path, binary ? { added: 0, deleted: 0, binary: true } : { added: Number(parts[0]) || 0, deleted: Number(parts[1]) || 0 });
34
- }
35
- return result;
36
- }
37
- async function git(cwd, args) {
38
- const result = await execFileAsync("git", ["-C", cwd, ...args], { encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true });
39
- return result.stdout;
40
- }
41
- async function digestFiles(cwd, paths) {
42
- const entries = await Promise.all([...paths].map(async (path) => {
43
- try {
44
- const content = await readFile(resolve(cwd, path));
45
- return [path, createHash("sha256").update(content).digest("hex")];
46
- }
47
- catch {
48
- return undefined;
49
- }
50
- }));
51
- return new Map(entries.filter((entry) => Boolean(entry)));
52
- }
53
- export async function captureWorkspaceBaseline(cwd) {
54
- const [status, unstaged, staged] = await Promise.all([
55
- git(cwd, ["status", "--porcelain=v1", "--untracked-files=all", "-z"]),
56
- git(cwd, ["diff", "--numstat"]),
57
- git(cwd, ["diff", "--cached", "--numstat"]),
58
- ]);
59
- const paths = new Set(parseStatus(status).keys());
60
- return { cwd, paths, stats: parseNumstat(`${unstaged}\n${staged}`), digests: await digestFiles(cwd, paths) };
61
- }
62
- export function fallbackWorkspaceChanges(input) {
1
+ // Only confirmed edit/write results belong to a turn. Never infer ownership from Git.
2
+ export function summarizeTurnFileEdits(input) {
63
3
  const files = input.files.filter(file => file.path).sort((a, b) => a.display.localeCompare(b.display));
64
4
  if (files.length === 0)
65
5
  return undefined;
66
- return { sessionId: input.sessionId, turnId: input.turnId, files, total: files.length, added: files.reduce((sum, file) => sum + file.added, 0), deleted: files.reduce((sum, file) => sum + file.deleted, 0), source: "tool-fallback", ...(input.failedTurn ? { failedTurn: true } : {}) };
67
- }
68
- export async function captureWorkspaceChanges(input) {
69
- const [statusText, unstaged, staged] = await Promise.all([
70
- git(input.baseline.cwd, ["status", "--porcelain=v1", "--untracked-files=all", "-z"]),
71
- git(input.baseline.cwd, ["diff", "--numstat"]),
72
- git(input.baseline.cwd, ["diff", "--cached", "--numstat"]),
73
- ]);
74
- const statuses = parseStatus(statusText);
75
- const finalDigests = await digestFiles(input.baseline.cwd, statuses.keys());
76
- const stats = parseNumstat(`${unstaged}\n${staged}`);
77
- const byTool = new Map();
78
- for (const tf of input.toolFiles ?? []) {
79
- const norm = tf.display.replace(/\\/g, "/");
80
- byTool.set(norm, { ...tf, display: norm });
81
- }
82
- for (const [path, status] of statuses) {
83
- if (!stats.has(path) && status === "added") {
84
- try {
85
- const absolute = resolve(input.baseline.cwd, path);
86
- const content = await readFile(absolute);
87
- if (content.includes(0))
88
- stats.set(path, { added: 0, deleted: 0, binary: true });
89
- else
90
- stats.set(path, { added: content.toString("utf8").split(/\r?\n/).filter(Boolean).length, deleted: 0 });
91
- }
92
- catch { /* status remains visible without line counts */ }
93
- }
94
- }
95
- const files = [];
96
- const seen = new Set();
97
- /*
98
- * Sessions can share one working directory, so the two `git status` calls
99
- * bracket every write in the repo — including another Session's. When this
100
- * turn recorded file-tool edits, those records decide WHICH files belong to
101
- * it; the snapshot is then only a source of counts for those same paths.
102
- * Without tool records (shell-driven edits) the snapshot stays authoritative.
103
- */
104
- const toolScoped = byTool.size > 0;
105
- for (const [path, status] of statuses) {
106
- if (toolScoped && !byTool.has(path))
107
- continue;
108
- const stat = stats.get(path) ?? { added: 0, deleted: 0 };
109
- const before = input.baseline.stats.get(path);
110
- const changedSinceBaseline = !input.baseline.paths.has(path) || input.baseline.digests.get(path) !== finalDigests.get(path) || !before || before.added !== stat.added || before.deleted !== stat.deleted || before.binary !== stat.binary;
111
- if (!changedSinceBaseline)
112
- continue;
113
- const toolEntry = byTool.get(path);
114
- const useToolCounts = Boolean(before && toolEntry && (toolEntry.added > 0 || toolEntry.deleted > 0));
115
- const added = useToolCounts ? toolEntry.added : before ? Math.max(0, stat.added - before.added) : stat.added;
116
- const deleted = useToolCounts ? toolEntry.deleted : before ? Math.max(0, stat.deleted - before.deleted) : stat.deleted;
117
- seen.add(path);
118
- files.push({
119
- path,
120
- display: path,
121
- added,
122
- deleted,
123
- ...(toolEntry?.firstChangedLine !== undefined ? { firstChangedLine: toolEntry.firstChangedLine } : {}),
124
- status,
125
- ...(stat.binary ? { binary: true } : {}),
126
- });
127
- }
128
- for (const [normPath, tf] of byTool) {
129
- if (!seen.has(normPath)) {
130
- files.push(tf);
131
- }
132
- }
133
- if (files.length === 0)
134
- return undefined;
135
- files.sort((a, b) => a.display.localeCompare(b.display));
136
6
  return {
137
7
  sessionId: input.sessionId,
138
8
  turnId: input.turnId,
@@ -141,7 +11,7 @@ export async function captureWorkspaceChanges(input) {
141
11
  total: files.length,
142
12
  added: files.reduce((sum, file) => sum + file.added, 0),
143
13
  deleted: files.reduce((sum, file) => sum + file.deleted, 0),
144
- source: "workspace-snapshot",
14
+ source: "tool-events",
145
15
  ...(input.failedTurn ? { failedTurn: true } : {}),
146
16
  };
147
17
  }
@@ -1 +1 @@
1
- import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-BWkVY9W5.js";import{p as f}from"./chunk-JWPE2WC7-Du_X-MSA.js";import{_ as n,l as o}from"./mermaid.core-CWATftfi.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-BIFL8KrA.js";import"./FilePreviewDocx-ybM3ZqSl.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
+ import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-DPb24xsc.js";import{p as f}from"./chunk-JWPE2WC7-BdtF1gRX.js";import{_ as n,l as o}from"./mermaid.core-D6dkYx5V.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-BIFL8KrA.js";import"./FilePreviewDocx-ybM3ZqSl.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-CWATftfi.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};
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-D6dkYx5V.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};