@tea-agent/loop-agent 0.52.0-next.2 → 0.52.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/build-stamp.json +3 -3
  3. package/dist/commands/init-accepted-merge.js +46 -0
  4. package/dist/commands/init-upgrade.js +115 -2
  5. package/dist/commands/init.js +79 -12
  6. package/dist/governance/path-guard.js +2 -0
  7. package/dist/records/harvest.js +1 -1
  8. package/dist/shared/git-progress.js +3 -0
  9. package/dist/task/delegate.js +1 -1
  10. package/dist/task/worktree.js +1 -1
  11. package/dist/worker/console/chat/pi-runtime.js +36 -5
  12. package/dist/worker/console/chat/scheduled-goal-request.js +1 -1
  13. package/dist/worker/console/chat/terminal-sessions.js +15 -0
  14. package/dist/worker/console/chat/workspace-changes.js +10 -0
  15. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-BJkTFDSU.js → abnfDiagram-N423BO3Z-CM5ocMUs.js} +1 -1
  16. package/dist/worker/console/static/assets/{arc-BJoqB-FK.js → arc-CDapwdTN.js} +1 -1
  17. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-Dnks_tKL.js → architectureDiagram-T3A2C74G-Ogy4GOqS.js} +1 -1
  18. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-CYfXZ-MS.js → blockDiagram-VBNYF7ZC-DsiaOIgU.js} +1 -1
  19. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-C8QUVTzH.js → c4Diagram-5PPSVZJV-B84hhgSe.js} +1 -1
  20. package/dist/worker/console/static/assets/channel-BCVzSVXD.js +1 -0
  21. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-BeQTq_mP.js → chunk-2GRJ4B5K-SPqOhMla.js} +1 -1
  22. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-Cz8TULTz.js → chunk-2Q5K7J3B-BL0Q4ZV3.js} +1 -1
  23. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-DTGsDFfs.js → chunk-5RXB4S5H-CJpOcFAh.js} +1 -1
  24. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-D3xtdDtx.js → chunk-5VM5RSS4-DQC6vqVW.js} +1 -1
  25. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-CFcH1dmG.js → chunk-6Q2QTUOP-D4dq_L0l.js} +1 -1
  26. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-D1oWTPzh.js → chunk-GF5L2VYU-DVNZmiVo.js} +1 -1
  27. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-DQ1784gP.js → chunk-JWPE2WC7-B1yOfAhr.js} +1 -1
  28. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-BUa9gwx1.js → chunk-KBJHAD2P-BEPc1N6N.js} +1 -1
  29. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-u-ANrNSL.js → chunk-RYQCIY6F-Da_-gMwh.js} +1 -1
  30. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-Daj0bhib.js → chunk-XXDRQBXY-C75eW9DT.js} +1 -1
  31. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BRlRsJR0.js +1 -0
  32. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BRlRsJR0.js +1 -0
  33. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-Bk1oZEJ1.js → cose-bilkent-JH36ORCC-C4Gn7eYB.js} +1 -1
  34. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-C4Ev_fka.js → cynefinDiagram-MW4NZA55--CBwVt18.js} +1 -1
  35. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-D0n24UDZ.js → dagre-VZM6K2ZE-B8dBxboB.js} +1 -1
  36. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-C1FlRrys.js → diagram-7IWD3JNH-hKtlE0w-.js} +1 -1
  37. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-CWpeId5Y.js → diagram-B4RE2ZJO-BKirx0F3.js} +1 -1
  38. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-CeEU1CTn.js → diagram-LBJQPF4R-bkx-oUrD.js} +1 -1
  39. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-DgpFxfNH.js → diagram-Q27KOJAE-D7sFtSjr.js} +1 -1
  40. package/dist/worker/console/static/assets/{diagram-UB23O5K3--9JrEf2p.js → diagram-UB23O5K3-BPjzGBV_.js} +1 -1
  41. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-D7E9C_OC.js → ebnfDiagram-BXEA7PRR-DODv-GbM.js} +1 -1
  42. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-OYp4ZJQC.js → erDiagram-JOGREHBK-DbfVp5uI.js} +1 -1
  43. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-Cyf8gGYJ.js → flowDiagram-UKHOOZJN-BHWWThbx.js} +1 -1
  44. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-B7gUfjoR.js → ganttDiagram-PKOTCBZU-SWY_8oU3.js} +1 -1
  45. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-mirrpSLp.js → gitGraphDiagram-DS77QQ5N-CJdhHY-i.js} +1 -1
  46. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-gRb5KI0B.js → infoDiagram-6WML65LV-CLC4mTWX.js} +1 -1
  47. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-v3JGPZ1t.js → ishikawaDiagram-WSZJBQD7-CiJDWOmX.js} +1 -1
  48. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-jJLc06Q0.js → journeyDiagram-NVQOT4AX-eIQfMD0f.js} +1 -1
  49. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-BJ7qkdrx.js → kanban-definition-27J2QSJJ-3d6r1cG7.js} +1 -1
  50. package/dist/worker/console/static/assets/{linear-B8iMATOq.js → linear-BjbmxxDk.js} +1 -1
  51. package/dist/worker/console/static/assets/main-B9ZnQejR.css +1 -0
  52. package/dist/worker/console/static/assets/{main-BA6TGEgV.js → main-D4knTr0R.js} +129 -129
  53. package/dist/worker/console/static/assets/{mermaid.core-C-6iih3_.js → mermaid.core-CD2GFYrr.js} +4 -4
  54. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-kUxtuaLJ.js → mindmap-definition-FAOFIHXS-D0ORXhx-.js} +1 -1
  55. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-CWscAnG2.js → pegDiagram-VL7TDLO6-BqNbcp7_.js} +1 -1
  56. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-B4P97R-G.js → pieDiagram-7S7Q4E2Y-CGO0Y13N.js} +1 -1
  57. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-TK_kx3AZ.js → quadrantDiagram-CIZ2JOQS-vH4fdvTV.js} +1 -1
  58. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BvoUgYhv.js → railroadDiagram-AXF67PYL-B_sbmiFS.js} +1 -1
  59. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DD-OVcGf.js → requirementDiagram-LRYGKXZP-DbHtPigL.js} +1 -1
  60. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-C_d-co8f.js → sankeyDiagram-W5VNT64P-BcqNS0Ko.js} +1 -1
  61. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-DEDF0c92.js → sequenceDiagram-SI44F4Z6-5Zf3xJfg.js} +1 -1
  62. package/dist/worker/console/static/assets/{sheet-workbook-BI2AD1uG.js → sheet-workbook-Bvq6WFll.js} +1 -1
  63. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-C9N-yQxX.js → sizeCapture-X5ZJPWSS-BoO7GXeG.js} +1 -1
  64. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-BXgVo9RE.js → stateDiagram-OKZ733FA-3suojNXT.js} +1 -1
  65. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Bq6cg1c9.js +1 -0
  66. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-DsJnGMMG.js → swimlanes-SLNWSIFB-B5CyFSLq.js} +2 -2
  67. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-VvJzDuB_.js +8 -0
  68. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-BHQjX5sj.js → timeline-definition-Z64GVDOM-BuZ_HcXz.js} +1 -1
  69. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-Cq_lSjge.js → vennDiagram-T6HMQDX7-CJ_IDS7Q.js} +1 -1
  70. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-BEX8BDY-.js → wardleyDiagram-T6FBY63Y-BpKLb-Su.js} +1 -1
  71. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-BTyfZdAf.js → xychartDiagram-ELKLHX3M-Mdo6gaIk.js} +1 -1
  72. package/dist/worker/console/static/index.html +2 -2
  73. package/dist/worker/console/static-src/operator-chat/chat-font-size.js +90 -0
  74. package/dist/worker/console/static-src/operator-chat/chat-session-order.js +96 -0
  75. package/dist/worker/scheduler/git-base.js +3 -0
  76. package/dist/worker/scheduler/night-git-finalizer.js +1 -1
  77. package/dist/worker/scheduler/night-harvest.js +1 -1
  78. package/dist/worker/scheduler/prepared-attempt-recovery.js +1 -1
  79. package/dist/worker/scheduler/scheduled-goal-evidence.js +1 -1
  80. package/package.json +3 -3
  81. package/dist/worker/console/static/assets/channel-gvXtLBqv.js +0 -1
  82. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DQ5hdEfB.js +0 -1
  83. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DQ5hdEfB.js +0 -1
  84. package/dist/worker/console/static/assets/main-BWBC5cML.css +0 -1
  85. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-CPyYpg4o.js +0 -1
  86. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BECT1jaq.js +0 -8
package/CHANGELOG.md CHANGED
@@ -39,7 +39,7 @@
39
39
  - 修复任务管理把已收起的子代理仍然画在图上,导致聚合卡片和成员卡片同时出现、连线交叉杂乱的问题。
40
40
  - 修复点击子代理详情后跳到仓库文件页而不是子代理内容的问题。
41
41
 
42
- ## [0.52.0-next.2] - 2026-10-19
42
+ ## [0.52.0-next.4] - 2026-10-20
43
43
 
44
44
  本预发布快照记录构建时已整理的待发布变化,不表示相对上一构建全部新增。
45
45
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "version": "0.52.0-next.2",
4
- "gitSha": "1419fdf52c41ffd1652c16ddcc3a047d97c8ba18",
5
- "builtAt": "2026-10-19T09:04:47.206Z"
3
+ "version": "0.52.0-next.4",
4
+ "gitSha": "277967526f4238667751cc35b262ccd4f5c55a86",
5
+ "builtAt": "2026-10-20T06:04:34.676Z"
6
6
  }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Accepted-merge normalization for `harness.json`.
3
+ *
4
+ * Extracted from `init.ts` so the edge-following rule can be tested directly:
5
+ * a wrong rule here does not fail loudly, it silently forces every
6
+ * `init upgrade` run back into the same merge task forever.
7
+ */
8
+ /**
9
+ * Actions that rewrite `harness.json` in place.
10
+ *
11
+ * `migrate-harness-governance-root` and `migrate-harness-model-fields` were
12
+ * missing here. A legacy project receives the governance-root migration and
13
+ * the structural reconciliation in the same apply-safe batch, so the first
14
+ * action moves the file off the accepted hash and the second no longer
15
+ * matches it. The chain then stopped at the original hash, the recorded
16
+ * acceptance never matched the on-disk file, and every run regenerated the
17
+ * same merge task.
18
+ *
19
+ * Any future action that rewrites `harness.json` must be registered here.
20
+ */
21
+ export const HARNESS_REWRITE_ACTIONS = new Set([
22
+ "migrate-harness-governance-root",
23
+ "migrate-harness-model-fields",
24
+ "reconcile-harness-structure",
25
+ ]);
26
+ /**
27
+ * Follow exact controller normalization edges, never infer acceptance from
28
+ * shape equality.
29
+ *
30
+ * A receipt advances the chain only when it targets `harness.json`, is a
31
+ * registered rewrite action, and its `beforeSha256` equals the hash reached
32
+ * so far. Receipts without a `beforeSha256` cannot be proven consecutive and
33
+ * are ignored rather than trusted.
34
+ */
35
+ export function normalizedAcceptedHarnessHash(acceptedHash, actions) {
36
+ let current = acceptedHash;
37
+ for (const action of actions) {
38
+ if (action.path === "harness.json" &&
39
+ HARNESS_REWRITE_ACTIONS.has(action.type) &&
40
+ action.beforeSha256 === current &&
41
+ action.afterSha256) {
42
+ current = action.afterSha256;
43
+ }
44
+ }
45
+ return current;
46
+ }
@@ -409,6 +409,7 @@ function runGitQuery(cwd, args) {
409
409
  return new Promise((resolve) => {
410
410
  const child = spawn("git", ["-C", cwd, ...args], {
411
411
  stdio: ["ignore", "pipe", "pipe"],
412
+ windowsHide: true,
412
413
  });
413
414
  const stdoutChunks = [];
414
415
  const stderrChunks = [];
@@ -545,6 +546,62 @@ function runDirectory(repoRoot, runId) {
545
546
  throw new Error("invalid init upgrade run id");
546
547
  return path.join(runRoot(repoRoot), runId);
547
548
  }
549
+ /**
550
+ * Pick the single interrupted run for `--continue` when `--run-id` is absent.
551
+ *
552
+ * Repeated interrupted attempts leave several directories under
553
+ * `.harness/init-upgrades`, and asking the user to copy a run id out of a
554
+ * state file is both error-prone and pointless when only one run can be
555
+ * resumed. This never guesses among candidates: two live runs mean the caller
556
+ * must decide, so the error lists them instead of picking the newest.
557
+ *
558
+ * Only `in-progress` runs qualify; a `failed` run stays opt-in so a broken
559
+ * run cannot be resumed by accident.
560
+ */
561
+ /**
562
+ * Decide which interrupted run `--continue` should resume.
563
+ *
564
+ * Exported as a pure decision so the 0/1/many cases are testable without
565
+ * building a fixture repository. Never guesses: two live runs mean the caller
566
+ * must choose, and a `failed` run stays opt-in.
567
+ */
568
+ export function selectInterruptedRun(candidates) {
569
+ if (candidates.length === 0) {
570
+ return {
571
+ error: "init upgrade --continue found no interrupted run; run `loop-agent init upgrade` to start one, or pass --run-id",
572
+ };
573
+ }
574
+ if (candidates.length === 1)
575
+ return { runId: candidates[0].runId };
576
+ const sorted = [...candidates].sort((left, right) => String(right.updatedAt ?? "").localeCompare(String(left.updatedAt ?? "")));
577
+ const listed = sorted
578
+ .map((candidate) => ` ${candidate.runId}${candidate.phase ? ` (${candidate.phase})` : ""}${candidate.updatedAt ? ` updated ${candidate.updatedAt}` : ""}`)
579
+ .join("\n");
580
+ return {
581
+ error: `init upgrade --continue found ${candidates.length} interrupted runs; pass --run-id with one of:\n${listed}`,
582
+ };
583
+ }
584
+ async function resolveInterruptedRunId(repoRoot) {
585
+ const root = runRoot(repoRoot);
586
+ const entries = await readdir(root, { withFileTypes: true }).catch(() => []);
587
+ const candidates = [];
588
+ for (const entry of entries) {
589
+ if (!entry.isDirectory() || !validRunId(entry.name))
590
+ continue;
591
+ const state = await readState(repoRoot, entry.name).catch(() => undefined);
592
+ if (!state || state.status !== "in-progress")
593
+ continue;
594
+ candidates.push({
595
+ runId: entry.name,
596
+ ...(typeof state.phase === "string" ? { phase: state.phase } : {}),
597
+ ...(typeof state.updatedAt === "string" ? { updatedAt: state.updatedAt } : {}),
598
+ });
599
+ }
600
+ const selection = selectInterruptedRun(candidates);
601
+ if ("error" in selection)
602
+ throw new Error(selection.error);
603
+ return selection.runId;
604
+ }
548
605
  async function exists(filePath) {
549
606
  return Boolean(await stat(filePath).catch(() => undefined));
550
607
  }
@@ -1182,6 +1239,46 @@ async function assertSafeMergePath(repoRoot, relativePath) {
1182
1239
  throw new Error(`init upgrade merge realpath escapes repo: ${normalized}`);
1183
1240
  }
1184
1241
  }
1242
+ /**
1243
+ * Directories whose contents never participate in the merge guard.
1244
+ *
1245
+ * The guard exists to prove that a merge touched only its declared paths, so
1246
+ * it only needs the governance surface. Walking dependency trees and build
1247
+ * output turned `DISCOVER` into a multi-minute scan on real projects (a
1248
+ * `node_modules` alone is tens of thousands of entries), which surfaced as an
1249
+ * external timeout with the run stuck in `DISCOVER`.
1250
+ *
1251
+ * Matching is by directory *name* only, so a file such as `src/dist.ts` or
1252
+ * `src/node_modules.ts` is still hashed normally. Skipping a directory also
1253
+ * excludes the directory entry itself from the snapshot, so no baseline bloat.
1254
+ */
1255
+ const SNAPSHOT_SKIP_DIRECTORY_NAMES = new Set(["node_modules",
1256
+ "dist",
1257
+ "build",
1258
+ "coverage",
1259
+ ".next",
1260
+ ".nuxt",
1261
+ ".turbo",
1262
+ ".cache",
1263
+ ".venv",
1264
+ "venv",
1265
+ "__pycache__",
1266
+ ".pytest_cache",
1267
+ ".mypy_cache",
1268
+ "target",
1269
+ ".gradle",
1270
+ "vendor",
1271
+ ]);
1272
+ /**
1273
+ * Whether a directory entry should be pruned from the workspace snapshot.
1274
+ *
1275
+ * Matches by directory name so `src/node_modules.ts` is still hashed. Exported
1276
+ * for direct testing: the guard's correctness depends on this staying narrow,
1277
+ * and an over-broad rule would silently stop protecting real files.
1278
+ */
1279
+ export function shouldSkipSnapshotDirectory(entry) {
1280
+ return entry.isDirectory() && SNAPSHOT_SKIP_DIRECTORY_NAMES.has(entry.name);
1281
+ }
1185
1282
  async function snapshotWorkspace(repoRoot) {
1186
1283
  const snapshot = {};
1187
1284
  async function visit(directory) {
@@ -1200,6 +1297,10 @@ async function snapshotWorkspace(repoRoot) {
1200
1297
  continue;
1201
1298
  if (relative === RUN_ROOT || relative.startsWith(`${RUN_ROOT}/`))
1202
1299
  continue;
1300
+ // Prune dependency/build directories before recording or descending,
1301
+ // so neither their entry nor their contents enter the baseline.
1302
+ if (shouldSkipSnapshotDirectory(entry))
1303
+ continue;
1203
1304
  if (entry.isSymbolicLink()) {
1204
1305
  snapshot[relative] = `symlink:${await readlink(absolute)}`;
1205
1306
  continue;
@@ -3594,7 +3695,19 @@ async function executeUpgrade(directory, state, input) {
3594
3695
  });
3595
3696
  }
3596
3697
  export async function runInitUpgrade(input) {
3597
- const repoRoot = path.resolve(input.repoRoot);
3698
+ // Canonicalize exactly once, the same way the decision-resume authority and
3699
+ // the controller anchor do. `path.resolve` alone keeps the Windows 8.3
3700
+ // short form (`MICROS~1`) that `realpath` expands, so the repo root
3701
+ // recorded into a pending decision never matched the one checked on
3702
+ // resume — the run then failed as "resume authority does not match
3703
+ // pending actions" even though every other field agreed.
3704
+ // Canonicalize exactly once, the same way the decision-resume authority and
3705
+ // the controller anchor do. `path.resolve` alone keeps the Windows 8.3
3706
+ // short form (`MICROS~1`) that `fs.promises.realpath` expands, so the repo
3707
+ // root recorded into a pending decision never matched the one checked on
3708
+ // resume — the run then failed as "resume authority does not match pending
3709
+ // actions" even though every other field agreed.
3710
+ const repoRoot = await realpath(path.resolve(input.repoRoot)).catch(() => path.resolve(input.repoRoot));
3598
3711
  const mode = input.mode ?? "start";
3599
3712
  if (input.decisionFile && mode !== "continue") {
3600
3713
  throw new Error("init upgrade --decision-file requires --continue and --run-id");
@@ -3621,7 +3734,7 @@ export async function runInitUpgrade(input) {
3621
3734
  };
3622
3735
  }
3623
3736
  const runId = mode === "continue"
3624
- ? input.runId
3737
+ ? input.runId ?? (await resolveInterruptedRunId(repoRoot))
3625
3738
  : input.runId ??
3626
3739
  `init-upgrade-${new Date().toISOString().replace(/[-:.TZ]/g, "").slice(0, 14)}-${randomUUID().slice(0, 8)}`;
3627
3740
  if (!runId)
@@ -3,6 +3,7 @@ import { access, copyFile, lstat, mkdir, readdir, readFile, realpath, rename, rm
3
3
  import path from "node:path";
4
4
  import { isDeepStrictEqual } from "node:util";
5
5
  import { fileURLToPath } from "node:url";
6
+ import { normalizedAcceptedHarnessHash } from "./init-accepted-merge.js";
6
7
  import { GITIGNORE_BLOCK_END, GITIGNORE_BLOCK_START, buildManagedGitignoreBlock, extractGitignoreManagedBlock, mergeGitignoreManagedBlock, } from "../shared/gitignore-managed-block.js";
7
8
  import { isInitRuntimeActive, } from "../shared/runtime-activity.js";
8
9
  import { loadHarnessManifest } from "../governance/harness.js";
@@ -1657,16 +1658,8 @@ async function buildCurrentSurfaceState(input) {
1657
1658
  };
1658
1659
  }
1659
1660
  /** Follow only exact controller normalization edges, never infer acceptance
1660
- * from shape equality. Persisted edges recover an interrupted surface refresh. */
1661
- function normalizedAcceptedHarnessHash(acceptedHash, actions) {
1662
- let current = acceptedHash;
1663
- for (const action of actions) {
1664
- if (action.path === "harness.json" && action.type === "reconcile-harness-structure" &&
1665
- action.beforeSha256 === current && action.afterSha256)
1666
- current = action.afterSha256;
1667
- }
1668
- return current;
1669
- }
1661
+ * from shape equality. Persisted edges recover an interrupted surface refresh.
1662
+ * See `init-accepted-merge.ts` for the rewrite-action set and its history. */
1670
1663
  async function writeInitSurfaceState(input) {
1671
1664
  const state = await buildCurrentSurfaceState(input);
1672
1665
  state.dispositions = [
@@ -2752,7 +2745,59 @@ function actionForMissing(pathName, state) {
2752
2745
  reason: "managed block file is missing or stale",
2753
2746
  };
2754
2747
  }
2755
- function modelMergeTaskFor(pathName, state, allPaths, recordedState) {
2748
+ /**
2749
+ * Fields that carry verification authority.
2750
+ *
2751
+ * The controller preserves these from the project during reconciliation
2752
+ * (`buildHarness` keeps `existing.verification` etc.), so a merge that
2753
+ * rewrites them does not just change configuration — it changes which
2754
+ * checks gate the project. Callers need to know this before editing.
2755
+ */
2756
+ const HARNESS_AUTHORITY_LOCKED_FIELDS = [
2757
+ "verification",
2758
+ "workflowPolicy",
2759
+ "executors",
2760
+ ];
2761
+ /**
2762
+ * Compare two JSON documents and report the differing key paths.
2763
+ *
2764
+ * Values are never emitted: the caller only needs to know *which* paths to
2765
+ * reconcile. Arrays compare as whole values because element-wise paths are
2766
+ * noisy for configuration and rarely actionable.
2767
+ *
2768
+ * Exported so the key-path diff can be tested directly; a wrong diff misleads
2769
+ * the merge more than no diff at all.
2770
+ */
2771
+ export function diffJsonKeyPaths(current, desired) {
2772
+ const added = [];
2773
+ const removed = [];
2774
+ const changed = [];
2775
+ const walk = (left, right, prefix) => {
2776
+ const leftIsRecord = isRecord(left);
2777
+ const rightIsRecord = isRecord(right);
2778
+ if (leftIsRecord && rightIsRecord) {
2779
+ for (const key of new Set([...Object.keys(left), ...Object.keys(right)])) {
2780
+ const nextPrefix = prefix ? `${prefix}.${key}` : key;
2781
+ const inLeft = Object.hasOwn(left, key);
2782
+ const inRight = Object.hasOwn(right, key);
2783
+ if (!inLeft && inRight)
2784
+ added.push(nextPrefix);
2785
+ else if (inLeft && !inRight)
2786
+ removed.push(nextPrefix);
2787
+ else
2788
+ walk(left[key], right[key], nextPrefix);
2789
+ }
2790
+ return;
2791
+ }
2792
+ if (leftIsRecord !== rightIsRecord || !isDeepStrictEqual(left, right)) {
2793
+ if (prefix)
2794
+ changed.push(prefix);
2795
+ }
2796
+ };
2797
+ walk(current, desired, "");
2798
+ return { added: added.sort(), removed: removed.sort(), changed: changed.sort() };
2799
+ }
2800
+ function modelMergeTaskFor(pathName, state, allPaths, recordedState, desiredPatch) {
2756
2801
  return {
2757
2802
  taskId: `init-merge-${sha256Text(pathName).slice(0, 12)}`,
2758
2803
  path: pathName,
@@ -2774,12 +2819,25 @@ function modelMergeTaskFor(pathName, state, allPaths, recordedState) {
2774
2819
  verification: [
2775
2820
  `git diff --check -- ${pathName}`,
2776
2821
  ],
2822
+ // A merge task that only says "complete this task" leaves the caller to
2823
+ // rediscover the authority rules. That is a fact the controller already
2824
+ // holds, so state it in a slot call sites do not overwrite.
2825
+ ...(pathName === "harness.json"
2826
+ ? {
2827
+ authorityLockedFields: [...HARNESS_AUTHORITY_LOCKED_FIELDS],
2828
+ mergeGuidance: [
2829
+ `Keep the project values of these authority fields: ${HARNESS_AUTHORITY_LOCKED_FIELDS.join(", ")}.`,
2830
+ "`.harness/init-surface.json` is rewritten by the controller after a successful merge; do not edit it by hand.",
2831
+ ],
2832
+ }
2833
+ : {}),
2777
2834
  evidence: {
2778
2835
  baseSha256: recordedState?.files[pathName]?.currentSha256,
2779
2836
  currentSha256: state?.currentSha256,
2780
2837
  desiredSha256: state?.sourceSha256,
2781
2838
  sourceAnchorSha256: state?.sourceAnchorSha256,
2782
2839
  },
2840
+ ...(desiredPatch ? { desiredPatch } : {}),
2783
2841
  };
2784
2842
  }
2785
2843
  function recommendedNextFor(report) {
@@ -3056,7 +3114,16 @@ export async function checkInitUpdate(input) {
3056
3114
  }
3057
3115
  else if (modelMigration.kind === "ambiguous") {
3058
3116
  const state = currentState.files["harness.json"];
3059
- const mergeTask = modelMergeTaskFor("harness.json", state, allPaths, recordedState);
3117
+ // The desired structure is computable here, so the caller does
3118
+ // not have to infer which key paths differ.
3119
+ const template = await readJsonIfExists(path.join(assetRoot, "harness.json"));
3120
+ const desiredStructure = buildHarness({
3121
+ existing: harness,
3122
+ template,
3123
+ projectName,
3124
+ governanceRoot,
3125
+ });
3126
+ const mergeTask = modelMergeTaskFor("harness.json", state, allPaths, recordedState, diffJsonKeyPaths(harness, desiredStructure));
3060
3127
  mergeTask.reason = `legacy model configuration requires a human/model merge: ${modelMigration.reason}`;
3061
3128
  mergeTask.mergeRules = [
3062
3129
  "Preserve every existing harness.json field unless the user explicitly approves its migration.",
@@ -52,6 +52,8 @@ export async function listDiffPaths(repoRoot, baseRef, headRef) {
52
52
  const child = spawn('git', ['diff', '--name-only', '-z', `${baseRef}..${headRef}`], {
53
53
  cwd: repoRoot,
54
54
  stdio: ['ignore', 'pipe', 'pipe'],
55
+ // A visible console per call would flash during every guarded write.
56
+ windowsHide: true,
55
57
  });
56
58
  const out = [];
57
59
  child.stdout?.on('data', (chunk) => out.push(chunk));
@@ -193,7 +193,7 @@ function runGit(repoRoot, args) {
193
193
  return new Promise((resolve, reject) => {
194
194
  const child = spawn('git', args, {
195
195
  cwd: repoRoot,
196
- stdio: ['ignore', 'pipe', 'pipe'],
196
+ stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true,
197
197
  });
198
198
  const stdoutChunks = [];
199
199
  const stderrChunks = [];
@@ -151,6 +151,9 @@ async function runGit(repoRoot, args) {
151
151
  const child = spawn('git', args, {
152
152
  cwd: repoRoot,
153
153
  stdio: ['ignore', 'pipe', 'pipe'],
154
+ // Without this Windows allocates a console for every child process, so
155
+ // each git call during a chat turn flashes a console window.
156
+ windowsHide: true,
154
157
  });
155
158
  let stdout = '';
156
159
  let stderr = '';
@@ -192,7 +192,7 @@ async function tryRunGit(repoRoot, args) {
192
192
  return new Promise((resolve) => {
193
193
  const child = spawn('git', args, {
194
194
  cwd: repoRoot,
195
- stdio: ['ignore', 'pipe', 'pipe'],
195
+ stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true,
196
196
  });
197
197
  const out = [];
198
198
  child.stdout?.on('data', (chunk) => out.push(chunk));
@@ -291,7 +291,7 @@ export async function removeWorktree(repoRoot, manifest, opts) {
291
291
  async function runGit(cwd, args) {
292
292
  return new Promise((resolve, reject) => {
293
293
  const child = spawn("git", ["-C", cwd, ...args], {
294
- stdio: ["ignore", "pipe", "pipe"],
294
+ stdio: ["ignore", "pipe", "pipe"], windowsHide: true,
295
295
  });
296
296
  const stdoutChunks = [];
297
297
  const stderrChunks = [];
@@ -187,6 +187,13 @@ export function OPERATOR_CHAT_ACTIVE_TOOL_NAMES() {
187
187
  export function computeOperatorChatActiveToolNames(session, sessionMode = DEFAULT_CONSOLE_CHAT_SESSION_MODE) {
188
188
  return computeChatActiveToolNames(session, sessionMode);
189
189
  }
190
+ /**
191
+ * Last-resort window when neither the provider nor `models.json` declares one.
192
+ * Matches the default the Console model editor writes for a new model, so a
193
+ * gateway that reports nothing still gets proactive compaction instead of
194
+ * running until it rejects the request.
195
+ */
196
+ const DEFAULT_CONTEXT_WINDOW = 128_000;
190
197
  const OPERATOR_CHAT_SESSION_EXCLUDE_TOOLS = Object.freeze([
191
198
  "apply_patch",
192
199
  "apply-patch",
@@ -874,6 +881,31 @@ export class ConsolePiRuntime {
874
881
  });
875
882
  void sessionId;
876
883
  }
884
+ /**
885
+ * Pick the context window to gate proactive compaction on.
886
+ *
887
+ * `getSessionStats().contextUsage.contextWindow` is what the provider
888
+ * reported for the live request, and a private/self-hosted gateway
889
+ * routinely reports `0`, `-1` or nothing at all — it has no obligation to
890
+ * tell us its limit. Gating only on that value silently disabled
891
+ * proactive compaction on such gateways: every session ran until the
892
+ * provider rejected the request, then fell back to the local checkpoint.
893
+ *
894
+ * The model definition in `models.json` (`session.model.contextWindow`)
895
+ * is the configured window and is authoritative when present. The
896
+ * reported value wins only when it is a usable positive number, because
897
+ * a gateway may enforce a tighter limit than the declared window.
898
+ */
899
+ resolveContextWindow(session, reportedWindow) {
900
+ if (typeof reportedWindow === "number" && reportedWindow > 0) {
901
+ return reportedWindow;
902
+ }
903
+ const configured = session.model?.contextWindow;
904
+ if (typeof configured === "number" && configured > 0) {
905
+ return configured;
906
+ }
907
+ return DEFAULT_CONTEXT_WINDOW;
908
+ }
877
909
  async runPrePromptCompaction(sessionId, session, promptText, imageCount, onEvent, signal) {
878
910
  const policy = parseCompactionPolicy();
879
911
  if (signal?.aborted)
@@ -882,8 +914,9 @@ export class ConsolePiRuntime {
882
914
  return;
883
915
  const controller = this.getCompactionController(sessionId);
884
916
  const stats = session.getSessionStats?.();
885
- const window = stats?.contextUsage?.contextWindow;
917
+ const reportedWindow = stats?.contextUsage?.contextWindow;
886
918
  const tokens = stats?.contextUsage?.tokens;
919
+ const window = this.resolveContextWindow(session, reportedWindow);
887
920
  if (typeof window === "number" && window > 0) {
888
921
  this.applySessionRecoveryOverrides(sessionId, this.serviceScopes.get(sessionId) ?? {}, session);
889
922
  }
@@ -896,10 +929,8 @@ export class ConsolePiRuntime {
896
929
  incrementPressureCounter(controller.counters, "usage-unavailable");
897
930
  return;
898
931
  }
899
- const effective = typeof window === "number" && window > 0
900
- ? deriveEffectiveWindow(window, policy)
901
- : undefined;
902
- if (!effective || projection.projected < effective.triggerTokens) {
932
+ const effective = deriveEffectiveWindow(window, policy);
933
+ if (projection.projected < effective.triggerTokens) {
903
934
  controller.pruneArmed = false;
904
935
  return;
905
936
  }
@@ -55,7 +55,7 @@ export function resolveScheduledTaskTime(input, now) {
55
55
  stopAtUtc: new Date(stop).toISOString(), expiresAt: new Date(stop).toISOString(), timezone,
56
56
  allowedHours: schedule.allowedHours ?? [], misfirePolicy: "run-immediately" });
57
57
  }
58
- const git = async (cwd, ...args) => (await execFileAsync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 30000, maxBuffer: 4 * 1024 * 1024 })).stdout.trim();
58
+ const git = async (cwd, ...args) => (await execFileAsync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 30000, maxBuffer: 4 * 1024 * 1024, windowsHide: true })).stdout.trim();
59
59
  const sameSet = (a, b) => JSON.stringify([...new Set(a)].sort()) === JSON.stringify([...new Set(b)].sort());
60
60
  function assertScheduledAcceptanceDoesNotRepeatBackendTests(request) {
61
61
  if (request.workflow !== "backend-test")
@@ -231,6 +231,21 @@ export class TerminalSessionRegistry {
231
231
  rows: options.rows ?? 30,
232
232
  env: process.env ?? {},
233
233
  encoding: "utf8",
234
+ /*
235
+ * winpty allocates a REAL console host window — the black box that
236
+ * flashed on every terminal session — while ConPTY keeps the
237
+ * session headless. node-pty picks ConPTY automatically from
238
+ * Windows build 18309, and `useConpty` is deprecated and ignored
239
+ * in 1.2 (microsoft/node-pty#871), so passing it documents the
240
+ * intent rather than flipping a switch.
241
+ *
242
+ * `useConptyDll` (the bundled conpty.dll) is NOT a drop-in
243
+ * improvement: measured on Windows 10.0.26300 it starts the shell
244
+ * but stops delivering output, so readAll/subscribe see the banner
245
+ * and nothing else. Two terminal tests catch that. Keep the system
246
+ * ConPTY; left undefined on other platforms.
247
+ */
248
+ ...(IS_WINDOWS ? { useConpty: true } : {}),
234
249
  });
235
250
  }
236
251
  catch (error) {
@@ -94,7 +94,17 @@ export async function captureWorkspaceChanges(input) {
94
94
  }
95
95
  const files = [];
96
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;
97
105
  for (const [path, status] of statuses) {
106
+ if (toolScoped && !byTool.has(path))
107
+ continue;
98
108
  const stat = stats.get(path) ?? { added: 0, deleted: 0 };
99
109
  const before = input.baseline.stats.get(path);
100
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;
@@ -1 +1 @@
1
- import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-CFcH1dmG.js";import{p as f}from"./chunk-JWPE2WC7-DQ1784gP.js";import{_ as n,l as o}from"./mermaid.core-C-6iih3_.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-D4dq_L0l.js";import{p as f}from"./chunk-JWPE2WC7-B1yOfAhr.js";import{_ as n,l as o}from"./mermaid.core-CD2GFYrr.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-C-6iih3_.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-CD2GFYrr.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};