agenttwin 0.3.39 → 0.3.43

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 (147) hide show
  1. package/README.md +15 -2
  2. package/dist/api.js +7762 -3145
  3. package/dist/dashboard/assets/dashboard/agent-home.css +9 -0
  4. package/dist/dashboard/assets/next/static/chunks/2960-520ffde27b062af4.js +1 -0
  5. package/dist/dashboard/assets/next/static/chunks/app/_not-found/{page-f05b53aa432a7110.js → page-cbf0a4f7672335b8.js} +1 -1
  6. package/dist/dashboard/assets/next/static/chunks/app/about/page-6e8e140ea96e4e5e.js +1 -0
  7. package/dist/dashboard/assets/next/static/chunks/app/account/password/{page-4db0777af7564cb4.js → page-124ac1de3af2d687.js} +1 -1
  8. package/dist/dashboard/assets/next/static/chunks/app/api-policy/{page-6706d2afc96be601.js → page-35fd8f4fe3b2af15.js} +1 -1
  9. package/dist/dashboard/assets/next/static/chunks/app/auth/{page-6706d2afc96be601.js → page-35fd8f4fe3b2af15.js} +1 -1
  10. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-arga-labs/page-f01a377f117e9baa.js +1 -0
  11. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-mockoon/page-f01a377f117e9baa.js +1 -0
  12. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-pact/page-f01a377f117e9baa.js +1 -0
  13. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-testcontainers/page-f01a377f117e9baa.js +1 -0
  14. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-wiremock/page-f01a377f117e9baa.js +1 -0
  15. package/dist/dashboard/assets/next/static/chunks/app/blog/ai-agent-refunded-twice-after-timeout/page-f01a377f117e9baa.js +1 -0
  16. package/dist/dashboard/assets/next/static/chunks/app/blog/arga-labs-alternatives/page-f01a377f117e9baa.js +1 -0
  17. package/dist/dashboard/assets/next/static/chunks/app/blog/choose-first-agent-workflow-test/page-f01a377f117e9baa.js +1 -0
  18. package/dist/dashboard/assets/next/static/chunks/app/blog/clean-baseline-before-fault-injection/page-f01a377f117e9baa.js +1 -0
  19. package/dist/dashboard/assets/next/static/chunks/app/blog/find-agent-workflows-that-run-twice/page-f01a377f117e9baa.js +1 -0
  20. package/dist/dashboard/assets/next/static/chunks/app/blog/free-digital-twins-for-agent-testing/page-f01a377f117e9baa.js +1 -0
  21. package/dist/dashboard/assets/next/static/chunks/app/blog/idempotency-keys-and-safe-retries/page-f01a377f117e9baa.js +1 -0
  22. package/dist/dashboard/assets/next/static/chunks/app/blog/inject-timeouts-and-rate-limits-into-agent-tool-calls/page-f01a377f117e9baa.js +1 -0
  23. package/dist/dashboard/assets/next/static/chunks/app/blog/keep-real-service-tests-with-digital-twins/page-f01a377f117e9baa.js +1 -0
  24. package/dist/dashboard/assets/next/static/chunks/app/blog/keploy-alternatives-for-database-and-payment-workflows/page-f01a377f117e9baa.js +1 -0
  25. package/dist/dashboard/assets/next/static/chunks/app/blog/{layout-d92d0846e7847b0f.js → layout-89f2942330b48007.js} +1 -1
  26. package/dist/dashboard/assets/next/static/chunks/app/blog/page-f01a377f117e9baa.js +1 -0
  27. package/dist/dashboard/assets/next/static/chunks/app/blog/read-workflow-test-receipts/page-f01a377f117e9baa.js +1 -0
  28. package/dist/dashboard/assets/next/static/chunks/app/blog/regression-tests-for-ai-agent-database-and-slack/page-f01a377f117e9baa.js +1 -0
  29. package/dist/dashboard/assets/next/static/chunks/app/blog/reset-test-environment-between-runs/page-f01a377f117e9baa.js +1 -0
  30. package/dist/dashboard/assets/next/static/chunks/app/blog/simulate-timeouts-and-duplicate-events/page-f01a377f117e9baa.js +1 -0
  31. package/dist/dashboard/assets/next/static/chunks/app/blog/test-boundaries-for-ai-agents/page-f01a377f117e9baa.js +1 -0
  32. package/dist/dashboard/assets/next/static/chunks/app/blog/timeout-retry-double-charge/page-f01a377f117e9baa.js +1 -0
  33. package/dist/dashboard/assets/next/static/chunks/app/blog/we-ran-50-real-incidents-through-agenttwin/page-f01a377f117e9baa.js +1 -0
  34. package/dist/dashboard/assets/next/static/chunks/app/blog/why-ai-agents-delete-production-databases/page-f01a377f117e9baa.js +1 -0
  35. package/dist/dashboard/assets/next/static/chunks/app/blog/workflow-testing-evaluation-checklist/page-f01a377f117e9baa.js +1 -0
  36. package/dist/dashboard/assets/next/static/chunks/app/blog/write-better-workflow-assertions/page-f01a377f117e9baa.js +1 -0
  37. package/dist/dashboard/assets/next/static/chunks/app/compare/{page-6706d2afc96be601.js → page-35fd8f4fe3b2af15.js} +1 -1
  38. package/dist/dashboard/assets/next/static/chunks/app/contact/{page-6706d2afc96be601.js → page-35fd8f4fe3b2af15.js} +1 -1
  39. package/dist/dashboard/assets/next/static/chunks/app/dashboard/layout-0262e35e50882ab7.js +1 -0
  40. package/dist/dashboard/assets/next/static/chunks/app/dashboard/page-943e07dc51384546.js +1 -0
  41. package/dist/dashboard/assets/next/static/chunks/app/demo/{page-db243af5ea4b6376.js → page-9e977d1d883f7386.js} +1 -1
  42. package/dist/dashboard/assets/next/static/chunks/app/developers/page-35fd8f4fe3b2af15.js +1 -0
  43. package/dist/dashboard/assets/next/static/chunks/app/docs/[[...slug]]/page-aea3b669bcb45491.js +1 -0
  44. package/dist/dashboard/assets/next/static/chunks/app/dpa/page-35fd8f4fe3b2af15.js +1 -0
  45. package/dist/dashboard/assets/next/static/chunks/app/enterprise/{page-2451558ccbe066c9.js → page-ce47c76b4160b3c9.js} +1 -1
  46. package/dist/dashboard/assets/next/static/chunks/app/guides/page-35fd8f4fe3b2af15.js +1 -0
  47. package/dist/dashboard/assets/next/static/chunks/app/{layout-13d2f06cab6f3ef6.js → layout-bc1ef1623bd1dca6.js} +1 -1
  48. package/dist/dashboard/assets/next/static/chunks/app/login/page-9a6e88fc56812fbb.js +1 -0
  49. package/dist/dashboard/assets/next/static/chunks/app/not-found-35fd8f4fe3b2af15.js +1 -0
  50. package/dist/dashboard/assets/next/static/chunks/app/onboarding/{page-c4292b08dedb1e5c.js → page-9c1bd81087260f4f.js} +1 -1
  51. package/dist/dashboard/assets/next/static/chunks/app/{page-bfcf9194963bf52b.js → page-7849ed5b53ffb2d1.js} +1 -1
  52. package/dist/dashboard/assets/next/static/chunks/app/pricing/{page-e65353f9ee62da36.js → page-2e2f53160e686d9e.js} +1 -1
  53. package/dist/dashboard/assets/next/static/chunks/app/privacy/page-35fd8f4fe3b2af15.js +1 -0
  54. package/dist/dashboard/assets/next/static/chunks/app/sandbox/page-35fd8f4fe3b2af15.js +1 -0
  55. package/dist/dashboard/assets/next/static/chunks/app/scoreboard/page-35fd8f4fe3b2af15.js +1 -0
  56. package/dist/dashboard/assets/next/static/chunks/app/security/page-35fd8f4fe3b2af15.js +1 -0
  57. package/dist/dashboard/assets/next/static/chunks/app/signup/page-9a6e88fc56812fbb.js +1 -0
  58. package/dist/dashboard/assets/next/static/chunks/app/sitemap.xml/route-f01a377f117e9baa.js +1 -0
  59. package/dist/dashboard/assets/next/static/chunks/app/status/page-d075703822281526.js +1 -0
  60. package/dist/dashboard/assets/next/static/chunks/app/subprocessors/page-35fd8f4fe3b2af15.js +1 -0
  61. package/dist/dashboard/assets/next/static/chunks/app/terms/page-35fd8f4fe3b2af15.js +1 -0
  62. package/dist/dashboard/assets/next/static/chunks/app/v2/dashboard/layout-22d3ae1def1dd220.js +1 -0
  63. package/dist/dashboard/assets/next/static/chunks/app/v2/dashboard/page-1b768bed2b8a2747.js +1 -0
  64. package/dist/dashboard/assets/next/static/chunks/app/v2/layout-38b897124c7f6223.js +1 -0
  65. package/dist/dashboard/assets/next/static/chunks/app/v2/login/page-91f11cbfe46c4c25.js +1 -0
  66. package/dist/dashboard/assets/next/static/chunks/app/v2/onboarding/page-64dd3f1b59afe38a.js +1 -0
  67. package/dist/dashboard/assets/next/static/chunks/app/v2/page-9191727c63b6ce2e.js +1 -0
  68. package/dist/dashboard/assets/next/static/chunks/app/v2/signup/page-91f11cbfe46c4c25.js +1 -0
  69. package/dist/dashboard/assets/next/static/chunks/app/what-is-agenttwin/page-35fd8f4fe3b2af15.js +1 -0
  70. package/dist/dashboard/assets/next/static/chunks/{main-app-cc626a1cec570e8f.js → main-app-85f4e8de9868bedc.js} +1 -1
  71. package/dist/dashboard/assets/next/static/chunks/{webpack-a48857e1e72fd84a.js → webpack-382af3529e0fbd25.js} +1 -1
  72. package/dist/dashboard/assets/next/static/css/01ccda6fe65cfe45.css +1 -0
  73. package/dist/dashboard/assets/next/static/css/41d14b615c51789f.css +1 -0
  74. package/dist/dashboard/assets/next/static/css/8f1b98de253e73ed.css +1 -0
  75. package/dist/dashboard/assets/next/static/css/c3d3b671693fb96d.css +1 -0
  76. package/dist/dashboard/assets/next/static/css/{47a1237f6559b428.css → f55186d294d5c4d4.css} +1 -1
  77. package/dist/dashboard/assets/next/static/sxtodXehxQTT0-7MaA4p7/_buildManifest.js +1 -0
  78. package/dist/dashboard/index.html +2 -2
  79. package/dist/discover-worker.js +164 -1
  80. package/dist/engine.js +10319 -4842
  81. package/dist/gateway.js +7753 -3137
  82. package/dist/live-tui/board.js +1312 -0
  83. package/dist/scan-worker.js +43 -4
  84. package/dist/twins/catalog.json +4 -4
  85. package/dist/twins/engine/v2/agenttwin-clock.mjs +1 -1
  86. package/dist/twins/engine/v2/chunks/{IVRB2YOK.mjs → XWRFNZ2H.mjs} +4 -4
  87. package/dist/twins/engine/v2/volter_world-core.mjs +1 -1
  88. package/dist/twins/engine/v3/agenttwin-clock.mjs +1 -1
  89. package/dist/twins/engine/v3/chunks/{F72NFZTW.mjs → 7PBB7HOX.mjs} +1 -1
  90. package/dist/twins/engine/v3/chunks/UEIYILLP.mjs +11 -0
  91. package/dist/twins/engine/v3/volter_world-core.mjs +1 -1
  92. package/dist/twins/engine/v3/volter_world-ui.mjs +1 -1
  93. package/dist/worker.js +5145 -4536
  94. package/dist/world-host.js +6575 -5336
  95. package/package.json +19 -4
  96. package/dist/dashboard/assets/next/static/KNTxh0SQ8GqNZPTSXNcRe/_buildManifest.js +0 -1
  97. package/dist/dashboard/assets/next/static/chunks/424-5191e91fec0be2c7.js +0 -1
  98. package/dist/dashboard/assets/next/static/chunks/app/about/page-8378255082922f7c.js +0 -1
  99. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-mockoon/page-46b9ffc514b56c84.js +0 -1
  100. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-pact/page-46b9ffc514b56c84.js +0 -1
  101. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-testcontainers/page-46b9ffc514b56c84.js +0 -1
  102. package/dist/dashboard/assets/next/static/chunks/app/blog/agenttwin-vs-wiremock/page-46b9ffc514b56c84.js +0 -1
  103. package/dist/dashboard/assets/next/static/chunks/app/blog/choose-first-agent-workflow-test/page-46b9ffc514b56c84.js +0 -1
  104. package/dist/dashboard/assets/next/static/chunks/app/blog/clean-baseline-before-fault-injection/page-46b9ffc514b56c84.js +0 -1
  105. package/dist/dashboard/assets/next/static/chunks/app/blog/idempotency-keys-and-safe-retries/page-46b9ffc514b56c84.js +0 -1
  106. package/dist/dashboard/assets/next/static/chunks/app/blog/keep-real-service-tests-with-digital-twins/page-46b9ffc514b56c84.js +0 -1
  107. package/dist/dashboard/assets/next/static/chunks/app/blog/keploy-alternatives-for-database-and-payment-workflows/page-46b9ffc514b56c84.js +0 -1
  108. package/dist/dashboard/assets/next/static/chunks/app/blog/page-46b9ffc514b56c84.js +0 -1
  109. package/dist/dashboard/assets/next/static/chunks/app/blog/read-workflow-test-receipts/page-46b9ffc514b56c84.js +0 -1
  110. package/dist/dashboard/assets/next/static/chunks/app/blog/reset-test-environment-between-runs/page-46b9ffc514b56c84.js +0 -1
  111. package/dist/dashboard/assets/next/static/chunks/app/blog/simulate-timeouts-and-duplicate-events/page-46b9ffc514b56c84.js +0 -1
  112. package/dist/dashboard/assets/next/static/chunks/app/blog/test-boundaries-for-ai-agents/page-46b9ffc514b56c84.js +0 -1
  113. package/dist/dashboard/assets/next/static/chunks/app/blog/timeout-retry-double-charge/page-46b9ffc514b56c84.js +0 -1
  114. package/dist/dashboard/assets/next/static/chunks/app/blog/we-ran-50-real-incidents-through-agenttwin/page-46b9ffc514b56c84.js +0 -1
  115. package/dist/dashboard/assets/next/static/chunks/app/blog/why-ai-agents-delete-production-databases/page-46b9ffc514b56c84.js +0 -1
  116. package/dist/dashboard/assets/next/static/chunks/app/blog/workflow-testing-evaluation-checklist/page-46b9ffc514b56c84.js +0 -1
  117. package/dist/dashboard/assets/next/static/chunks/app/blog/write-better-workflow-assertions/page-46b9ffc514b56c84.js +0 -1
  118. package/dist/dashboard/assets/next/static/chunks/app/dashboard/layout-cbd7e31c6d430a1a.js +0 -1
  119. package/dist/dashboard/assets/next/static/chunks/app/dashboard/page-f45f96c066eb9de2.js +0 -1
  120. package/dist/dashboard/assets/next/static/chunks/app/developers/page-6706d2afc96be601.js +0 -1
  121. package/dist/dashboard/assets/next/static/chunks/app/docs/[[...slug]]/page-83fc0a3aa3425b02.js +0 -1
  122. package/dist/dashboard/assets/next/static/chunks/app/dpa/page-6706d2afc96be601.js +0 -1
  123. package/dist/dashboard/assets/next/static/chunks/app/guides/page-6706d2afc96be601.js +0 -1
  124. package/dist/dashboard/assets/next/static/chunks/app/login/page-589519cc705ec22f.js +0 -1
  125. package/dist/dashboard/assets/next/static/chunks/app/not-found-6706d2afc96be601.js +0 -1
  126. package/dist/dashboard/assets/next/static/chunks/app/privacy/page-6706d2afc96be601.js +0 -1
  127. package/dist/dashboard/assets/next/static/chunks/app/sandbox/page-6706d2afc96be601.js +0 -1
  128. package/dist/dashboard/assets/next/static/chunks/app/scoreboard/page-6706d2afc96be601.js +0 -1
  129. package/dist/dashboard/assets/next/static/chunks/app/security/page-6706d2afc96be601.js +0 -1
  130. package/dist/dashboard/assets/next/static/chunks/app/signup/page-589519cc705ec22f.js +0 -1
  131. package/dist/dashboard/assets/next/static/chunks/app/sitemap.xml/route-46b9ffc514b56c84.js +0 -1
  132. package/dist/dashboard/assets/next/static/chunks/app/status/page-47f0d1533bf1206f.js +0 -1
  133. package/dist/dashboard/assets/next/static/chunks/app/subprocessors/page-6706d2afc96be601.js +0 -1
  134. package/dist/dashboard/assets/next/static/chunks/app/terms/page-6706d2afc96be601.js +0 -1
  135. package/dist/dashboard/assets/next/static/chunks/app/v2/dashboard/layout-76020499f90782bd.js +0 -1
  136. package/dist/dashboard/assets/next/static/chunks/app/v2/dashboard/page-cb63082b6709d22e.js +0 -1
  137. package/dist/dashboard/assets/next/static/chunks/app/v2/layout-d3227c5987005526.js +0 -1
  138. package/dist/dashboard/assets/next/static/chunks/app/v2/login/page-40a3cf0903538784.js +0 -1
  139. package/dist/dashboard/assets/next/static/chunks/app/v2/onboarding/page-921ad64530803c42.js +0 -1
  140. package/dist/dashboard/assets/next/static/chunks/app/v2/page-d0b682a723aa566f.js +0 -1
  141. package/dist/dashboard/assets/next/static/chunks/app/v2/signup/page-40a3cf0903538784.js +0 -1
  142. package/dist/dashboard/assets/next/static/chunks/app/what-is-agenttwin/page-6706d2afc96be601.js +0 -1
  143. package/dist/dashboard/assets/next/static/css/37d81e1d2804cc5f.css +0 -1
  144. package/dist/dashboard/assets/next/static/css/423c6df577acd447.css +0 -1
  145. package/dist/dashboard/assets/next/static/css/e7f08eacc20752f3.css +0 -1
  146. package/dist/twins/engine/v3/chunks/7D6PDVOF.mjs +0 -11
  147. /package/dist/dashboard/assets/next/static/{KNTxh0SQ8GqNZPTSXNcRe → sxtodXehxQTT0-7MaA4p7}/_ssgManifest.js +0 -0
@@ -0,0 +1,1312 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/flow/live-tui/board.tsx
4
+ import React2, { useEffect, useState, useSyncExternalStore as useSyncExternalStore2 } from "react";
5
+
6
+ // src/flow/live-ink.tsx
7
+ import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
8
+ import { join as join2 } from "path";
9
+ import React, { createContext, useContext, useSyncExternalStore } from "react";
10
+ import { Box, Text, render, useInput } from "ink";
11
+
12
+ // src/flow/triage.ts
13
+ var WEIGHT = { critical: 3, high: 2, medium: 1 };
14
+ function triageFindings(findings, fix) {
15
+ const real = findings.filter((f) => f.severity !== "low");
16
+ const scored = real.map((f) => ({ f, score: (f.atRiskAmount ?? (f.perIncident ?? 0) * 1e3) + (WEIGHT[f.severity] ?? 0) }));
17
+ scored.sort((a, b) => b.score - a.score);
18
+ return scored.map(({ f, score }, i) => {
19
+ const critical = f.severity === "critical" || f.severity === "high" || (f.atRiskAmount ?? 0) > 0;
20
+ const first = i === 0 && !!fix;
21
+ const lane = first ? "now" : critical ? "decide" : "later";
22
+ const status = first ? fix.applied && fix.proven ? "fixed" : "ready" : "open";
23
+ return { rank: i + 1, title: f.title, lane, status, critical, ...f.atRisk ? { cost: f.atRisk, per: `1,000 ${f.unit ?? "requests"}` } : {}, ...f.service ? { service: f.service } : {}, ...f.workflow ? { workflow: f.workflow } : {}, score };
24
+ });
25
+ }
26
+ var laneCounts = (items) => ({ now: items.filter((i) => i.lane === "now").length, decide: items.filter((i) => i.lane === "decide").length, later: items.filter((i) => i.lane === "later").length, fixed: items.filter((i) => i.status === "fixed").length });
27
+
28
+ // src/flow/terminal-caps.ts
29
+ var FULL_CAPS = { tier: "full", color: true, unicode: true, compact: false };
30
+
31
+ // src/flow/live-view.ts
32
+ import { writeFileSync, mkdirSync } from "fs";
33
+ import { join } from "path";
34
+ var STAGES = ["Scan", "Twin", "Run", "Break", "Find", "Fix", "Show"];
35
+ function settle(s) {
36
+ if (!s.board || !s.workflow) return s;
37
+ const title = s.workflow.title, at = s.board.findIndex((b) => b.title === title && b.mark === "run");
38
+ if (at < 0) return s;
39
+ const bad = s.findings.some((f) => f.workflow === title && f.severity !== "low");
40
+ const mark = bad ? s.fix?.proven ? "fixed" : "problem" : "pass";
41
+ return { ...s, board: s.board.map((b, i) => i === at ? { ...b, mark } : b) };
42
+ }
43
+ var setMark = (s, title, mark, force = false) => {
44
+ if (!s.board) return s;
45
+ const from = (m) => m === "wait" || m === "run" || m === "skip";
46
+ const at = s.board.findIndex((b) => b.title === title && (force || from(b.mark) || mark === "fixed" || mark === "fixing"));
47
+ return at < 0 ? s : { ...s, board: s.board.map((b, i) => i === at ? { ...b, mark } : b) };
48
+ };
49
+ var emptyState = (now) => ({ startedAt: now, stage: 0, twins: [], cases: [], findings: [], tail: [] });
50
+ function reduce(s, e, now) {
51
+ switch (e.type) {
52
+ case "stage":
53
+ return { ...s, stage: Math.max(s.stage, e.step) };
54
+ case "workflow":
55
+ return setMark({ ...s, workflow: { title: e.title, entrypoint: e.entrypoint, candidates: e.candidates } }, e.title, "run");
56
+ case "twin":
57
+ return s.twins.some((t) => t.name === e.name) ? s : { ...s, twins: [...s.twins, { name: e.name, title: e.title, tier: e.tier, ...e.detail ? { detail: e.detail } : {}, ...e.host ? { host: e.host } : {}, at: now }] };
58
+ case "cases":
59
+ return { ...s, cases: [...s.cases, ...e.list.filter((c) => !s.cases.some((x) => x.id === c.id)).map((c) => ({ ...c, status: "pending", calls: 0, trace: [] }))] };
60
+ case "case-start": {
61
+ const has = s.cases.some((c) => c.id === e.id);
62
+ return { ...s, cases: has ? s.cases.map((c) => c.id === e.id ? { ...c, title: e.title, status: "running", startedAt: now } : c) : [...s.cases, { id: e.id, title: e.title, status: "running", calls: 0, startedAt: now, trace: [] }] };
63
+ }
64
+ case "case-end":
65
+ return { ...s, cases: s.cases.map((c) => c.id !== e.id ? c : e.calls.length ? { ...c, status: e.status, calls: e.calls.filter((x) => !x.fault).length, trace: e.calls.slice(-8), ...c.startedAt !== void 0 ? { ms: now - c.startedAt } : {} } : { ...c, status: e.status }) };
66
+ case "finding": {
67
+ const at = s.findings.findIndex((f2) => f2.title === e.title && f2.workflow === s.workflow?.title);
68
+ const f = { title: e.title, severity: e.severity, ...s.workflow ? { workflow: s.workflow.title } : {}, ...e.where ? { where: e.where } : {}, ...e.detail ? { detail: e.detail } : {}, ...e.impact ? { impact: e.impact } : {}, ...e.price ? { price: e.price } : {}, ...e.perIncident ? { perIncident: e.perIncident } : {}, ...e.service ? { service: e.service } : {}, ...e.when ? { when: e.when } : {}, ...e.monthly ? { monthly: e.monthly } : {}, ...e.atRisk ? { atRisk: e.atRisk, atRiskAmount: e.atRiskAmount, unit: e.unit, ...e.monthlyAtRisk ? { monthlyAtRisk: e.monthlyAtRisk, customers: e.customers } : {} } : {} };
69
+ return { ...s, findings: at < 0 ? [...s.findings, f] : s.findings.map((x, i) => i === at ? { ...x, ...f } : x) };
70
+ }
71
+ case "fix":
72
+ return { ...s, fix: { title: e.title, ...e.command ? { command: e.command } : {}, ...e.promptFile ? { promptFile: e.promptFile } : {}, ...e.applied !== void 0 ? { applied: e.applied } : {}, ...e.proven !== void 0 ? { proven: e.proven } : {} } };
73
+ case "result": {
74
+ const { type: _t, ...r } = e;
75
+ return { ...s, result: r };
76
+ }
77
+ // The next of several workflows: its progress starts over; problems found so far stay for the last screen.
78
+ case "next-workflow":
79
+ return { ...settle(s), stage: 0, workflow: void 0, twins: [], cases: [], fix: void 0, result: void 0, done: void 0, batch: { n: e.n, of: e.of } };
80
+ case "summary":
81
+ return { ...settle(s), workflows: e.workflows };
82
+ case "skipped":
83
+ return { ...s, skipped: e.list };
84
+ case "discovery": {
85
+ const { type: _t, ...d } = e;
86
+ const items = d.items ?? d.groups.flatMap((g) => Array.from({ length: g.count }, (_x, i) => ({ title: `${g.name}#${i}`, group: g.name })));
87
+ return { ...s, discovery: d, board: items.map((i) => ({ title: i.title, group: i.group, mark: "wait" })) };
88
+ }
89
+ case "mark":
90
+ return setMark(s, e.title, e.mark, true);
91
+ case "marks": {
92
+ if (!s.board) return s;
93
+ const by = new Map(e.list.map((m) => [m.title, m.mark]));
94
+ return { ...s, board: s.board.map((b) => by.has(b.title) ? { ...b, mark: by.get(b.title) } : b) };
95
+ }
96
+ case "done":
97
+ return { ...e.status === "stopped" ? s : settle(s), done: e.status, stage: e.status === "stopped" ? s.stage : STAGES.length + 1 };
98
+ default:
99
+ return s;
100
+ }
101
+ }
102
+ var ESC = "\x1B[";
103
+ var sgr = (code) => (t) => `${ESC}${code}m${t}${ESC}0m`;
104
+ var C = {
105
+ bold: sgr("1"),
106
+ white: sgr("1;97"),
107
+ text: sgr("38;5;252"),
108
+ soft: sgr("38;5;246"),
109
+ faint: sgr("38;5;240"),
110
+ accent: sgr("38;5;44"),
111
+ accentBold: sgr("1;38;5;44"),
112
+ green: sgr("38;5;78"),
113
+ red: sgr("38;5;203"),
114
+ redBold: sgr("1;38;5;203"),
115
+ yellow: sgr("38;5;221"),
116
+ pillRed: sgr("1;38;5;231;48;5;160"),
117
+ pillGreen: sgr("1;38;5;16;48;5;78"),
118
+ pillYellow: sgr("1;38;5;16;48;5;221"),
119
+ pillFaint: sgr("38;5;250;48;5;238")
120
+ };
121
+ var cut = (t, n) => [...t].length <= n ? t : [...t].slice(0, Math.max(0, n - 1)).join("") + "\u2026";
122
+ var BRANDS = {
123
+ stripe: { color: "#635BFF", ink: "#FFFFFF", icon: "stripe" },
124
+ resend: { color: "#000000", ink: "#FFFFFF", icon: "resend" },
125
+ slack: { color: "#4A154B", ink: "#FFFFFF", icon: "slack" },
126
+ openai: { color: "#10A37F", ink: "#FFFFFF", icon: "openai" },
127
+ anthropic: { color: "#D97757", ink: "#FFFFFF", icon: "anthropic" },
128
+ postgres: { color: "#4169E1", ink: "#FFFFFF", icon: "postgresql" },
129
+ postgresql: { color: "#4169E1", ink: "#FFFFFF", icon: "postgresql" },
130
+ redis: { color: "#DC382D", ink: "#FFFFFF", icon: "redis" },
131
+ twilio: { color: "#F22F46", ink: "#FFFFFF", icon: "twilio" },
132
+ sendgrid: { color: "#1A82E2", ink: "#FFFFFF", icon: "sendgrid" },
133
+ postmark: { color: "#FFDE00", ink: "#000000", icon: "postmark" },
134
+ github: { color: "#24292F", ink: "#FFFFFF", icon: "github" },
135
+ shopify: { color: "#7AB55C", ink: "#FFFFFF", icon: "shopify" },
136
+ hubspot: { color: "#FF7A59", ink: "#FFFFFF", icon: "hubspot" },
137
+ notion: { color: "#FFFFFF", ink: "#000000", icon: "notion" },
138
+ linear: { color: "#5E6AD2", ink: "#FFFFFF", icon: "linear" },
139
+ supabase: { color: "#3FCF8E", ink: "#0B0B0B", icon: "supabase" },
140
+ upstash: { color: "#00E9A3", ink: "#0B0B0B", icon: "upstash" },
141
+ upstash_redis: { color: "#00E9A3", ink: "#0B0B0B", icon: "upstash" },
142
+ clerk: { color: "#6C47FF", ink: "#FFFFFF", icon: "clerk" },
143
+ mailgun: { color: "#F06B66", ink: "#FFFFFF", icon: "mailgun" },
144
+ gmail: { color: "#EA4335", ink: "#FFFFFF", icon: "gmail" },
145
+ telegram: { color: "#26A5E4", ink: "#FFFFFF", icon: "telegram" },
146
+ discord: { color: "#5865F2", ink: "#FFFFFF", icon: "discord" },
147
+ zendesk: { color: "#03363D", ink: "#FFFFFF", icon: "zendesk" },
148
+ jira: { color: "#0052CC", ink: "#FFFFFF", icon: "jira" },
149
+ salesforce: { color: "#00A1E0", ink: "#FFFFFF", icon: "salesforce" },
150
+ intercom: { color: "#1F8DED", ink: "#FFFFFF", icon: "intercom" },
151
+ segment: { color: "#52BD94", ink: "#0B0B0B", icon: "segment" },
152
+ posthog: { color: "#F9BD2B", ink: "#000000", icon: "posthog" },
153
+ aws: { color: "#FF9900", ink: "#000000", icon: "amazonwebservices" },
154
+ s3: { color: "#569A31", ink: "#FFFFFF", icon: "amazons3" },
155
+ mongodb: { color: "#47A248", ink: "#FFFFFF", icon: "mongodb" },
156
+ clickhouse: { color: "#FFCC01", ink: "#000000", icon: "clickhouse" },
157
+ kafka: { color: "#231F20", ink: "#FFFFFF", icon: "apachekafka" },
158
+ vercel: { color: "#000000", ink: "#FFFFFF", icon: "vercel" },
159
+ google: { color: "#4285F4", ink: "#FFFFFF", icon: "google" },
160
+ googleoauth: { color: "#4285F4", ink: "#FFFFFF", icon: "google" },
161
+ airtable: { color: "#18BFFF", ink: "#000000", icon: "airtable" },
162
+ mysql: { color: "#4479A1", ink: "#FFFFFF", icon: "mysql" }
163
+ };
164
+ function brandOf(name, title = "") {
165
+ const keys = [name, title, title.split(/\s+/)[0]].map((k) => k.toLowerCase().replace(/[^a-z0-9_]/g, ""));
166
+ for (const k of keys) if (BRANDS[k]) return BRANDS[k];
167
+ return Object.entries(BRANDS).find(([k]) => keys.some((x) => x.startsWith(k) && k.length >= 4))?.[1];
168
+ }
169
+ var hex = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
170
+ function brandHex(name, title) {
171
+ const b = brandOf(name, title);
172
+ if (!b) return void 0;
173
+ let [r, g, bl] = hex(b.color);
174
+ const lum = (0.2126 * r + 0.7152 * g + 0.0722 * bl) / 255;
175
+ if (lum < 0.35) {
176
+ const k = (0.35 - lum) / (1 - lum) + 0.25;
177
+ [r, g, bl] = [r, g, bl].map((c) => Math.round(c + (255 - c) * Math.min(1, k)));
178
+ }
179
+ return "#" + [r, g, bl].map((c) => c.toString(16).padStart(2, "0")).join("");
180
+ }
181
+ function thing(path) {
182
+ const seg = path.split("/").filter((s) => s && !/^(v\d+|api|\{.*\}|:.*|\d+)$/.test(s)).pop() ?? "request";
183
+ const word = seg.replace(/[_-]+/g, " ").replace(/ intents?$/, "").replace(/s$/, "");
184
+ return word || "request";
185
+ }
186
+ function scenario(title, id = "") {
187
+ if (id === "clean" || /^Clean run/i.test(title)) return { name: "Normal run", question: "Your real code runs end to end against the twins, with nothing broken." };
188
+ if (id === "duplicate-delivery" || /arrives twice/i.test(title)) return { name: "Delivered twice", question: "The same request or webhook arrives a second time. Does your app do the work twice?" };
189
+ const withPath = /^(\S+)\s+(\S+):\s*(.*)$/.exec(title), bare = withPath ? null : /^([A-Za-z][\w.-]{1,30}):\s*(.*)$/.exec(title);
190
+ const name = withPath?.[1] ?? bare?.[1];
191
+ const who = name ? name.charAt(0).toUpperCase() + name.slice(1) : "The service";
192
+ const what = withPath ? thing(withPath[2]) : "write", how = (withPath?.[3] ?? bare?.[2] ?? title).toLowerCase();
193
+ if (/reply lost|timeout after write|connection dropped/.test(how)) return { name: `${who} saves, reply lost`, question: `${who} saves the ${what}, then its reply never arrives. Does your app send it again?` };
194
+ if (/slower than|delayed/.test(how)) return { name: `${who} replies too slowly`, question: `${who} applies the ${what} but answers after your timeout. Does your app retry it?` };
195
+ if (/service down|every attempt/.test(how)) return { name: `${who} is down`, question: `Every call to ${who} fails. Does your app say it worked anyway?` };
196
+ if (/answers 500|server error/.test(how)) return { name: `${who} errors once`, question: `${who} fails the first ${what} with a 500. Does your app recover cleanly?` };
197
+ return { name: cut(title, 40), question: title };
198
+ }
199
+ function whenPhrase(when) {
200
+ if (!when) return "";
201
+ if (when === "normal run") return "on a normal run, nothing broken";
202
+ const name = scenario(when.replace(/^injected: /, "")).name, first = name.split(/\s/)[0];
203
+ return `when ${brandOf(first) || /[A-Z].*[A-Z]/.test(first) ? name : name.replace(/^./, (c) => c.toLowerCase())}`;
204
+ }
205
+ var HEADLINES = {
206
+ 1: "Reading your code for workflows that call outside services",
207
+ 2: "Building digital twins of the services it calls",
208
+ 3: "Running your real code against the twins",
209
+ 4: "Breaking it the way production does",
210
+ 5: "Working out what each problem costs",
211
+ 6: "Writing a fix and proving it",
212
+ 7: "Putting the result together"
213
+ };
214
+
215
+ // src/flow/live-ink.tsx
216
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
217
+ var COLOR = { accent: "#22d3ee", text: "#d4d4d8", soft: "#a1a1aa", faint: "#52525b", green: "#4ade80", red: "#f87171", yellow: "#facc15", border: "#3f3f46" };
218
+ var CapsCtx = createContext(FULL_CAPS);
219
+ var GLYPHS = {
220
+ A: [".##.", "#..#", "####", "#..#", "#..#", "...."],
221
+ g: ["....", ".###", "#..#", ".###", "...#", "###."],
222
+ e: ["....", ".##.", "####", "#...", ".###", "...."],
223
+ n: ["....", "###.", "#..#", "#..#", "#..#", "...."],
224
+ t: [".#..", "###.", ".#..", ".#..", "..##", "...."],
225
+ T: ["###", ".#.", ".#.", ".#.", ".#.", "..."],
226
+ w: [".....", "#...#", "#...#", "#.#.#", ".#.#.", "....."],
227
+ i: ["#", ".", "#", "#", "#", "."]
228
+ };
229
+ function wordmarkRows(word = "AgentTwin") {
230
+ const px = [0, 1, 2, 3, 4, 5].map((r) => [...word].map((ch) => GLYPHS[ch]?.[r] ?? ".").join("."));
231
+ const rows = [];
232
+ for (let r = 0; r < 6; r += 2) rows.push([...px[r]].map((top, i) => {
233
+ const bot = px[r + 1][i] === "#";
234
+ return top === "#" ? bot ? "\u2588" : "\u2580" : bot ? "\u2584" : " ";
235
+ }).join(""));
236
+ return rows;
237
+ }
238
+ var mix = (a, b, k) => "#" + [1, 3, 5].map((i) => Math.round(parseInt(a.slice(i, i + 2), 16) * (1 - k) + parseInt(b.slice(i, i + 2), 16) * k).toString(16).padStart(2, "0")).join("");
239
+ var byCount = (a, b) => (a.name === "Other" ? 1 : 0) - (b.name === "Other" ? 1 : 0) || b.count - a.count;
240
+ function packGroups(groups, inner, mode = "mosaic", extraOf, barOver = Infinity) {
241
+ const blocks = groups.map((g) => {
242
+ if (mode === "gap" && g.count > barOver) {
243
+ const cols2 = Math.max(8, Math.min(Math.floor((inner - 1) / 2), 36)), per = Math.ceil(g.count / cols2), x2 = extraOf?.(g.members ?? [g.name]);
244
+ const label2 = `${g.twin ? "\u25C6 " : ""}${g.name} ${g.count}${x2 ? " " + x2 : ""} \xB7 1 mark = ${per}`;
245
+ return { ...g, label: label2, cols: cols2, w: Math.max(cols2 * 2, [...label2].length), lines: 1, bar: true };
246
+ }
247
+ const x = extraOf?.(g.members ?? [g.name]), label = `${g.twin ? "\u25C6 " : ""}${g.name} ${g.count}${x ? " " + x : ""}`, big = g.count > 200;
248
+ const room = mode === "gap" ? Math.floor((inner - 1) / 2) : inner - 1;
249
+ const cols = Math.min(room, mode === "gap" ? Math.max(4, Math.min(big ? 44 : 30, Math.ceil(g.count / 3))) : mode === "dense" ? Math.max(4, Math.min(big ? 120 : 40, Math.ceil(g.count / 2))) : Math.max(4, Math.min(big ? 44 : 24, Math.ceil(g.count / 4))));
250
+ return { ...g, label, cols, w: Math.max(mode === "gap" ? cols * 2 : cols, [...label].length), lines: mode === "mosaic" ? Math.ceil(Math.ceil(g.count / cols) / 2) : Math.ceil(g.count / cols) };
251
+ });
252
+ const rows = [];
253
+ let cur = [], used = 0;
254
+ for (const b of blocks) {
255
+ if (cur.length && used + b.w + 1 > inner) {
256
+ rows.push(cur);
257
+ cur = [];
258
+ used = 0;
259
+ }
260
+ cur.push(b);
261
+ used += b.w + 1;
262
+ }
263
+ if (cur.length) rows.push(cur);
264
+ return { rows, height: rows.reduce((n, r) => n + 1 + Math.max(...r.map((b) => b.lines)), 0) };
265
+ }
266
+ function fitGroups(groups, inner, maxLines, mosaic = true, extraOf) {
267
+ const spaced = packGroups([...groups].sort(byCount), inner, "gap", extraOf);
268
+ if (spaced.height <= maxLines) return { ...spaced, merged: 0, gap: true, mode: "gap" };
269
+ {
270
+ let list2 = [...groups].sort(byCount), merged2 = 0;
271
+ for (; ; ) {
272
+ const packed = packGroups(list2, inner, "gap", extraOf, 150);
273
+ if (packed.height <= maxLines) return { ...packed, merged: merged2, gap: true, mode: "gap" };
274
+ const tail = list2.filter((g) => g.name !== "Other").slice(-2), other = list2.find((g) => g.name === "Other");
275
+ if (list2.length <= 8 || !tail.length) break;
276
+ merged2 += tail.length;
277
+ list2 = [...list2.filter((g) => !tail.includes(g) && g.name !== "Other"), { name: "Other", count: tail.reduce((n, g) => n + g.count, 0) + (other?.count ?? 0), members: [...other?.members ?? ["Other"], ...tail.flatMap((g) => g.members ?? [g.name])] }].sort(byCount);
278
+ }
279
+ }
280
+ const mode = mosaic ? "mosaic" : "dense";
281
+ let list = [...groups].sort(byCount), merged = 0;
282
+ for (; ; ) {
283
+ const packed = packGroups(list, inner, mode, extraOf);
284
+ const tail = list.filter((g) => g.name !== "Other").slice(-2), other = list.find((g) => g.name === "Other");
285
+ if (packed.height <= maxLines || list.length <= (mosaic ? 6 : 3) || !tail.length) return { ...packed, merged, gap: false, mode };
286
+ merged += tail.length;
287
+ list = [...list.filter((g) => !tail.includes(g) && g.name !== "Other"), { name: "Other", count: tail.reduce((n, g) => n + g.count, 0) + (other?.count ?? 0), members: [...other?.members ?? ["Other"], ...tail.flatMap((g) => g.members ?? [g.name])] }].sort(byCount);
288
+ }
289
+ }
290
+ var SPACED = "#52525b";
291
+ var WORST = ["problem", "fixing", "run", "skip", "wait", "fixed", "pass"];
292
+ var WallBlock = React.memo(function WallBlock2({ b, mode, marks, tick, letters }) {
293
+ const cellOf = (i) => {
294
+ const m = marks[i] ?? "wait";
295
+ return { c: m === "run" ? Math.floor(tick / 3) % 2 ? "#ffffff" : COLOR.accent : HUE[m], ch: letters ? LETTER[m] : "\u2584", m };
296
+ };
297
+ const lines = [];
298
+ if (b.bar) {
299
+ const per = Math.ceil(b.count / b.cols), runs = [];
300
+ for (let k = 0; k < b.cols && k * per < b.count; k++) {
301
+ let worst, rank = 99;
302
+ for (let i = k * per; i < Math.min(b.count, (k + 1) * per); i++) {
303
+ const x2 = cellOf(i), r = x2.m ? WORST.indexOf(x2.m) : 4;
304
+ if (r < rank) {
305
+ rank = r;
306
+ worst = x2;
307
+ }
308
+ }
309
+ const x = worst ?? { c: SPACED, ch: "\u2584" }, last = runs[runs.length - 1];
310
+ if (last && last.c === x.c && last.ch === x.ch) last.n++;
311
+ else runs.push({ c: x.c, ch: x.ch, n: 1 });
312
+ }
313
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginRight: 1, width: b.w, children: [
314
+ /* @__PURE__ */ jsx(Text, { color: COLOR.soft, wrap: "truncate-end", children: b.label }),
315
+ /* @__PURE__ */ jsx(Text, { children: runs.map((u, k) => /* @__PURE__ */ jsx(Text, { color: u.c, children: (u.ch + " ").repeat(u.n) }, k)) })
316
+ ] });
317
+ }
318
+ if (mode !== "mosaic") {
319
+ const sep = mode === "gap" ? " " : "";
320
+ for (let r = 0; r < b.lines; r++) {
321
+ const runs = [];
322
+ for (let c = 0; c < b.cols; c++) {
323
+ const i = r * b.cols + c;
324
+ if (i >= b.count) break;
325
+ const x = cellOf(i), last = runs[runs.length - 1];
326
+ if (last && last.c === x.c && last.ch === x.ch) last.n++;
327
+ else runs.push({ ...x, n: 1 });
328
+ }
329
+ lines.push(/* @__PURE__ */ jsx(Text, { children: runs.map((u, k) => /* @__PURE__ */ jsx(Text, { color: u.c, children: (u.ch + sep).repeat(u.n) }, k)) }, r));
330
+ }
331
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginRight: 1, width: b.w, children: [
332
+ /* @__PURE__ */ jsx(Text, { color: COLOR.soft, wrap: "truncate-end", children: b.label }),
333
+ lines
334
+ ] });
335
+ }
336
+ const at = (pr, c) => {
337
+ const i = pr * b.cols + c;
338
+ return i < b.count ? (pr + c) % 2 ? mix(cellOf(i).c, "#000000", 0.28) : cellOf(i).c : void 0;
339
+ };
340
+ for (let r = 0; r < b.lines; r++) {
341
+ const runs = [];
342
+ for (let c = 0; c < b.cols; c++) {
343
+ const top = at(2 * r, c), bot = at(2 * r + 1, c), last = runs[runs.length - 1];
344
+ if (last && last.top === top && last.bot === bot) last.n++;
345
+ else runs.push({ top, bot, n: 1 });
346
+ }
347
+ lines.push(/* @__PURE__ */ jsx(Text, { children: runs.map((u, i) => u.top === void 0 ? /* @__PURE__ */ jsx(Text, { children: " ".repeat(u.n) }, i) : /* @__PURE__ */ jsx(Text, { color: u.top, backgroundColor: u.bot, children: "\u2580".repeat(u.n) }, i)) }, r));
348
+ }
349
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginRight: 1, width: b.w, children: [
350
+ /* @__PURE__ */ jsx(Text, { color: COLOR.soft, wrap: "truncate-end", children: b.label }),
351
+ lines
352
+ ] });
353
+ });
354
+ var LABEL = { pass: "passed", fixed: "problem fixed", fixing: "fixing in background", problem: "open problem", skip: "not tested", wait: "waiting", run: "testing now" };
355
+ var HUE = { pass: COLOR.green, fixed: "#60a5fa", fixing: "#a78bfa", problem: COLOR.red, skip: "#d97706", wait: "#52525b", run: "#ffffff" };
356
+ var LETTER = { pass: "+", fixed: "F", fixing: "~", problem: "X", skip: "?", wait: ".", run: "*" };
357
+ var squareHue = (mark, tick = 0) => mark === "run" ? Math.floor(tick / 3) % 2 ? "#ffffff" : COLOR.accent : HUE[mark];
358
+ function boardView(s) {
359
+ const over = !!s.done;
360
+ const items = (s.board ?? []).map((b) => ({ ...b, mark: over && (b.mark === "wait" || b.mark === "run") ? "skip" : b.mark }));
361
+ const byGroup = /* @__PURE__ */ new Map(), counts = { pass: 0, fixed: 0, fixing: 0, problem: 0, skip: 0, wait: 0, run: 0 };
362
+ for (const b of items) {
363
+ counts[b.mark]++;
364
+ (byGroup.get(b.group) ?? byGroup.set(b.group, []).get(b.group)).push(b.mark);
365
+ }
366
+ const order = ["problem", "fixing", "fixed", "run", "pass", "wait", "skip"];
367
+ for (const [g, list] of byGroup) byGroup.set(g, [...list].sort((x, y) => order.indexOf(x) - order.indexOf(y)));
368
+ return { byGroup, counts, total: items.length };
369
+ }
370
+
371
+ // src/flow/fix-prompt-copy.ts
372
+ import { spawn } from "child_process";
373
+ import { readFile } from "fs/promises";
374
+ import { isAbsolute, resolve } from "path";
375
+ function osc52(text) {
376
+ return `\x1B]52;c;${Buffer.from(text, "utf8").toString("base64")}\x07`;
377
+ }
378
+ var CLIPBOARD = {
379
+ darwin: { command: "pbcopy", args: [] },
380
+ win32: { command: "clip", args: [] },
381
+ linux: { command: "xclip", args: ["-selection", "clipboard"] }
382
+ };
383
+ async function copyFixPrompt(promptFile, options = {}) {
384
+ const max = options.maxBytes ?? 256 * 1024;
385
+ try {
386
+ const path = isAbsolute(promptFile) ? promptFile : resolve(options.cwd ?? process.cwd(), promptFile);
387
+ const text = await readFile(path, "utf8");
388
+ const bytes = Buffer.byteLength(text, "utf8");
389
+ if (!text.trim()) return { ok: false, bytes: 0, reason: "the prompt file is empty" };
390
+ if (bytes > max) return { ok: false, bytes: 0, reason: `the prompt is larger than ${Math.round(max / 1024)} KB` };
391
+ options.write?.(osc52(text));
392
+ const target = CLIPBOARD[options.platform ?? process.platform];
393
+ if (target) {
394
+ try {
395
+ const child = (options.spawn ?? spawn)(target.command, target.args, { stdio: ["pipe", "ignore", "ignore"], windowsHide: true });
396
+ child.on?.("error", () => {
397
+ });
398
+ child.stdin?.end(text);
399
+ } catch {
400
+ }
401
+ }
402
+ return { ok: true, bytes };
403
+ } catch (error) {
404
+ return { ok: false, bytes: 0, reason: error instanceof Error ? error.message : String(error) };
405
+ }
406
+ }
407
+
408
+ // src/flow/live-tui/board.tsx
409
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "fs";
410
+ import { join as join3 } from "path";
411
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
412
+ var Box2 = "box";
413
+ var Text2 = "text";
414
+ var Span = "span";
415
+ var Bold = "b";
416
+ var COLOR2 = { accent: "#22d3ee", text: "#d4d4d8", soft: "#a1a1aa", faint: "#52525b", green: "#4ade80", red: "#f87171", yellow: "#facc15", border: "#3f3f46" };
417
+ var SPIN = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
418
+ var STEPS = ["Find", "Twins", "Test", "Break", "Results", "Fix", "Report"];
419
+ var SAYS = [
420
+ "We read your code and listed everything that can be tested. Nothing has run yet.",
421
+ "Making a digital twin of each service your workflows call, so tests never touch production.",
422
+ "Running each workflow the way it normally runs, on the twins.",
423
+ "Now making the services fail the way they do in real life, and watching what each workflow does.",
424
+ "Checking what broke, and what it would cost.",
425
+ "Problems are listed by how much they matter. Nothing in your code is changed.",
426
+ "Every workflow as one square. Green passed, red has a problem, amber was not tested."
427
+ ];
428
+ var MARKS = ["pass", "fixed", "fixing", "problem", "skip", "wait", "run"];
429
+ var WORST2 = ["problem", "fixing", "run", "skip", "wait", "fixed", "pass"];
430
+ var STRIP_W = 34;
431
+ var clock = (ms) => {
432
+ const s = Math.max(0, Math.floor(ms / 1e3));
433
+ return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
434
+ };
435
+ var cut2 = (t, n) => [...t].length <= n ? t : [...t].slice(0, Math.max(0, n - 1)).join("") + "\u2026";
436
+ var finished = (c) => !["pending", "running"].includes(c.status);
437
+ var plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
438
+ var whole = (t) => t?.replace(/\.00$/, "");
439
+ var whenText = whenPhrase;
440
+ var spin = (tick) => SPIN[tick % SPIN.length];
441
+ var runtime = () => {
442
+ const loaded = globalThis.__agentTwinOpenTui;
443
+ if (!loaded) throw new Error("OpenTUI runtime is not loaded.");
444
+ return loaded;
445
+ };
446
+ function useTick(live) {
447
+ const [tick, setTick] = useState(0);
448
+ useEffect(() => {
449
+ if (!live) return;
450
+ const timer = setInterval(() => setTick((n) => n + 1), 80);
451
+ return () => clearInterval(timer);
452
+ }, [live]);
453
+ return tick;
454
+ }
455
+ function useArrowScroll(total, fit) {
456
+ const max = Math.max(0, total - fit), [top, setTop] = useState(0);
457
+ runtime().react.useKeyboard((key) => {
458
+ if (total <= fit) return;
459
+ const step = key.name === "down" ? 1 : key.name === "up" ? -1 : 0;
460
+ if (step) setTop((value) => Math.max(0, Math.min(max, value + step)));
461
+ });
462
+ return Math.min(top, max);
463
+ }
464
+ function Panel({ title, note, children, width, grow, height }) {
465
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", border: true, borderStyle: "rounded", borderColor: COLOR2.border, paddingX: 1, width, height, flexGrow: grow ? 1 : 0, flexShrink: grow ? 1 : 0, overflow: "hidden", children: [
466
+ /* @__PURE__ */ jsxs2(Box2, { flexDirection: "row", justifyContent: "space-between", children: [
467
+ /* @__PURE__ */ jsx2(Text2, { children: /* @__PURE__ */ jsx2(Bold, { children: title }) }),
468
+ note ?? null
469
+ ] }),
470
+ children
471
+ ] });
472
+ }
473
+ var Rule = () => /* @__PURE__ */ jsx2(Box2, { border: ["top"], borderStyle: "single", borderColor: COLOR2.border });
474
+ function Rail({ s, step, d, counts, over, w }) {
475
+ return /* @__PURE__ */ jsxs2(Panel, { title: "Steps", width: w, height: "100%", children: [
476
+ STEPS.map((name, i) => {
477
+ const n = i + 1, ok = over ? true : n < step, cur = !over && n === step;
478
+ return /* @__PURE__ */ jsxs2(Text2, { children: [
479
+ /* @__PURE__ */ jsx2(Span, { fg: ok ? COLOR2.green : cur ? COLOR2.accent : COLOR2.faint, children: ok ? "\u2713" : cur ? "\u25C6" : "\u25C7" }),
480
+ " ",
481
+ /* @__PURE__ */ jsx2(Span, { fg: ok ? COLOR2.text : cur ? COLOR2.accent : COLOR2.faint, children: cur ? /* @__PURE__ */ jsxs2(Bold, { children: [
482
+ n,
483
+ " ",
484
+ name
485
+ ] }) : `${n} ${name}` })
486
+ ] }, name);
487
+ }),
488
+ /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", marginTop: 1, children: [
489
+ /* @__PURE__ */ jsx2(Text2, { children: /* @__PURE__ */ jsx2(Bold, { children: "Found" }) }),
490
+ /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.text, children: [
491
+ d.workflows,
492
+ " workflows"
493
+ ] }),
494
+ /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.text, children: [
495
+ d.services,
496
+ " services"
497
+ ] }),
498
+ /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.text, children: [
499
+ d.groups.filter((x) => x.name !== "Other" && x.count > 0).length,
500
+ " used by workflows"
501
+ ] }),
502
+ /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.text, children: [
503
+ d.twinnable,
504
+ " twins ready"
505
+ ] }),
506
+ over ? /* @__PURE__ */ jsxs2(Text2, { fg: HUE.skip, children: [
507
+ counts.skip,
508
+ " not tested"
509
+ ] }) : counts.pass + counts.problem + counts.fixed > 0 ? /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.soft, children: [
510
+ counts.pass + counts.problem + counts.fixed,
511
+ " tested so far"
512
+ ] }) : null
513
+ ] })
514
+ ] });
515
+ }
516
+ function Starts({ d, tight }) {
517
+ const per = tight ? 8 : 40, tw = d.twins ?? [], top = Math.max(1, ...d.kinds.map((k) => k.count));
518
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
519
+ d.kinds.slice(0, tight ? 3 : 9).map((k) => /* @__PURE__ */ jsxs2(Text2, { wrapMode: "word", children: [
520
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.accent, children: "\u2588".repeat(Math.max(1, Math.round(k.count / top * 8))) }),
521
+ " ",
522
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: k.count }),
523
+ " ",
524
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: k.name })
525
+ ] }, k.name)),
526
+ d.twins?.length ? /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", marginTop: 1, children: [
527
+ /* @__PURE__ */ jsxs2(Text2, { children: [
528
+ /* @__PURE__ */ jsx2(Bold, { children: "Twins ready " }),
529
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: tw.length > per ? `${Math.min(per, tw.length)} of ${tw.length}` : tw.length })
530
+ ] }),
531
+ /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.green, wrapMode: "word", children: tw.slice(0, per).join(" \xB7 ") })
532
+ ] }) : null,
533
+ /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", marginTop: 1, children: [
534
+ /* @__PURE__ */ jsx2(Text2, { children: /* @__PURE__ */ jsx2(Bold, { children: "This run" }) }),
535
+ /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.text, children: [
536
+ "Tests the ",
537
+ Math.min(d.testing, d.workflows),
538
+ " riskiest first."
539
+ ] }),
540
+ tight ? null : /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.faint, children: "To test more:" }),
541
+ /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.soft, children: [
542
+ tight ? "More: " : "",
543
+ "AGENTTWIN_MAX_WORKFLOWS=",
544
+ d.workflows
545
+ ] })
546
+ ] })
547
+ ] });
548
+ }
549
+ function Triage({ s, max, compact, tight }) {
550
+ const items = triageFindings(s.findings, s.fix), list = items.filter((i) => i.lane !== "later");
551
+ const from = useArrowScroll(list.length, max);
552
+ if (!items.length) return null;
553
+ const c = laneCounts(items), link = s.result?.dashboard, top = list.slice(from, from + max);
554
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", children: [
555
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
556
+ /* @__PURE__ */ jsx2(Bold, { children: "Biggest first" }),
557
+ list.length > max ? /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.faint, children: [
558
+ " ",
559
+ from + 1,
560
+ "-",
561
+ Math.min(list.length, from + max),
562
+ " of ",
563
+ list.length
564
+ ] }) : null
565
+ ] }),
566
+ top.map((i) => /* @__PURE__ */ jsxs2(React2.Fragment, { children: [
567
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, truncate: true, children: [
568
+ /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.faint, children: [
569
+ i.rank,
570
+ " "
571
+ ] }),
572
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: i.title })
573
+ ] }),
574
+ i.cost ? /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.red, children: [
575
+ " ",
576
+ whole(i.cost),
577
+ " per ",
578
+ i.per
579
+ ] }) : null,
580
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.faint, children: [
581
+ " ",
582
+ i.status === "fixed" ? /* @__PURE__ */ jsx2(Span, { fg: COLOR2.green, children: "\u2713 fixed now" }) : i.status === "ready" ? /* @__PURE__ */ jsx2(Span, { fg: COLOR2.accent, children: "fix ready, one command" }) : /* @__PURE__ */ jsx2(Span, { fg: COLOR2.yellow, children: "your decision" })
583
+ ] })
584
+ ] }, i.rank)),
585
+ compact ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
586
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.text, children: [
587
+ c.now ? `${c.now} ready now` : "Nothing fixable now",
588
+ " \xB7 ",
589
+ c.decide,
590
+ " need your decision \xB7 ",
591
+ c.later,
592
+ " can wait"
593
+ ] }),
594
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.soft, truncate: true, children: "No need to wait here. Decide later after npx agenttwin login." }),
595
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.faint, truncate: true, children: "Saved to .agenttwin/triage.json. Nothing changed." })
596
+ ] }) : tight ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
597
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.text, children: [
598
+ c.now,
599
+ " ready \xB7 ",
600
+ c.decide,
601
+ " need decision \xB7 ",
602
+ c.later,
603
+ " can wait"
604
+ ] }),
605
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.soft, truncate: true, children: "Decide later after npx agenttwin login." }),
606
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.faint, truncate: true, children: "Nothing changed. Saved to .agenttwin/triage.json." })
607
+ ] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
608
+ /* @__PURE__ */ jsx2(Text2, { height: 1, children: " " }),
609
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.text, children: c.now ? `${c.now} fixed or ready now` : "Nothing fixable right now" }),
610
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.text, children: [
611
+ c.decide,
612
+ " need",
613
+ c.decide === 1 ? "s" : "",
614
+ " your decision"
615
+ ] }),
616
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.text, children: [
617
+ c.later,
618
+ " can wait"
619
+ ] }),
620
+ /* @__PURE__ */ jsx2(Text2, { height: 1, children: " " }),
621
+ /* @__PURE__ */ jsxs2(Text2, { height: 2, fg: COLOR2.soft, wrapMode: "word", children: [
622
+ "No need to wait here. Decide and track the rest ",
623
+ link ? /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.accent, children: [
624
+ "at ",
625
+ link
626
+ ] }) : /* @__PURE__ */ jsx2(Span, { fg: COLOR2.accent, children: "after npx agenttwin login" })
627
+ ] }),
628
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.faint, truncate: true, children: "Saved to .agenttwin/triage.json. Nothing changed." })
629
+ ] })
630
+ ] });
631
+ }
632
+ function Report({ s, counts, total, width, problems, compact, tight }) {
633
+ const passed = counts.pass + counts.fixed, open = counts.problem + counts.fixing;
634
+ const N = ({ n, c }) => /* @__PURE__ */ jsx2(Bold, { children: /* @__PURE__ */ jsx2(Span, { fg: c, children: String(n).padStart(4) }) });
635
+ return /* @__PURE__ */ jsxs2(Panel, { title: "Result", width, height: "100%", children: [
636
+ problems ? /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
637
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.red, children: /* @__PURE__ */ jsx2(Bold, { children: "\u2717" }) }),
638
+ " ",
639
+ /* @__PURE__ */ jsxs2(Bold, { children: [
640
+ problems,
641
+ " problem",
642
+ problems === 1 ? "" : "s",
643
+ " found"
644
+ ] })
645
+ ] }) : null,
646
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
647
+ /* @__PURE__ */ jsx2(N, { n: passed, c: COLOR2.green }),
648
+ " ",
649
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: "passed" }),
650
+ counts.fixed ? /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.faint, children: [
651
+ " (",
652
+ counts.fixed,
653
+ " after a fix)"
654
+ ] }) : null
655
+ ] }),
656
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
657
+ /* @__PURE__ */ jsx2(N, { n: counts.fixing, c: HUE.fixing }),
658
+ " ",
659
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: "fixing in background" })
660
+ ] }),
661
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
662
+ /* @__PURE__ */ jsx2(N, { n: counts.problem, c: COLOR2.red }),
663
+ " ",
664
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: "open problems" })
665
+ ] }),
666
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
667
+ /* @__PURE__ */ jsx2(N, { n: counts.skip, c: HUE.skip }),
668
+ " ",
669
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: "not tested" })
670
+ ] }),
671
+ compact || tight ? null : /* @__PURE__ */ jsx2(Text2, { height: 1, children: " " }),
672
+ /* @__PURE__ */ jsx2(Text2, { height: 1, children: /* @__PURE__ */ jsx2(Bold, { children: "Proof you can share" }) }),
673
+ /* @__PURE__ */ jsx2(Text2, { height: 1, children: /* @__PURE__ */ jsxs2(Bold, { children: [
674
+ "PASSED ",
675
+ passed,
676
+ " / ",
677
+ total
678
+ ] }) }),
679
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.soft, children: [
680
+ open,
681
+ " open \xB7 ",
682
+ counts.skip,
683
+ " not tested"
684
+ ] }),
685
+ !compact && s.result?.proof ? /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.text, children: [
686
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: "Proof " }),
687
+ s.result.proof
688
+ ] }) : null,
689
+ s.result?.dashboard ? /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.accent, children: [
690
+ "\u25B8 ",
691
+ s.result.dashboard
692
+ ] }) : /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.soft, children: "npx agenttwin login for a link" }),
693
+ !compact && !tight && s.fix?.promptFile ? /* @__PURE__ */ jsxs2(Text2, { height: 1, truncate: true, children: [
694
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: "Agent " }),
695
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: s.fix.promptFile }),
696
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " c copy" })
697
+ ] }) : null,
698
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.soft, children: "npx agenttwin check install" }),
699
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.faint, children: " runs this on every PR" }),
700
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.soft, children: "--json for your agent" }),
701
+ compact || tight ? null : /* @__PURE__ */ jsx2(Text2, { height: 1, children: " " }),
702
+ /* @__PURE__ */ jsx2(Triage, { s, max: compact ? 1 : 3, compact, tight })
703
+ ] });
704
+ }
705
+ function NowLine({ s, tick }) {
706
+ const serious = s.findings.filter((f) => f.severity !== "low"), running = s.cases.find((c) => c.status === "running");
707
+ const worst = [...serious].sort((a, b) => (b.atRiskAmount ?? 0) - (a.atRiskAmount ?? 0))[0];
708
+ const tried = s.cases.filter(finished), ok = tried.filter((c) => c.status === "passed").length, failed = tried.filter((c) => c.status === "found").length;
709
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", paddingX: 1, children: [
710
+ /* @__PURE__ */ jsxs2(Text2, { wrapMode: "word", children: [
711
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.accent, children: spin(tick) }),
712
+ " ",
713
+ /* @__PURE__ */ jsx2(Bold, { children: running && s.stage === 4 ? `Breaking ${s.cases.indexOf(running) + 1}/${s.cases.length} \xB7 ${scenario(running.title, running.id).name}` : HEADLINES[s.stage] ?? "Getting ready" })
714
+ ] }),
715
+ /* @__PURE__ */ jsxs2(Text2, { wrapMode: "word", children: [
716
+ tried.length ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
717
+ /* @__PURE__ */ jsxs2(Span, { fg: ok ? COLOR2.green : COLOR2.faint, children: [
718
+ ok,
719
+ " OK"
720
+ ] }),
721
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " \xB7 " }),
722
+ /* @__PURE__ */ jsxs2(Span, { fg: tried.length - ok - failed ? COLOR2.yellow : COLOR2.faint, children: [
723
+ tried.length - ok - failed,
724
+ " skip"
725
+ ] }),
726
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " \xB7 " }),
727
+ /* @__PURE__ */ jsxs2(Span, { fg: failed ? COLOR2.red : COLOR2.faint, children: [
728
+ failed,
729
+ " failed"
730
+ ] }),
731
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " \xB7 " })
732
+ ] }) : null,
733
+ serious.length ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
734
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.red, children: "\u2717" }),
735
+ " ",
736
+ /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.text, children: [
737
+ plural(serious.length, "problem"),
738
+ " so far"
739
+ ] }),
740
+ worst?.atRisk ? /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.red, children: [
741
+ " \xB7 ",
742
+ whole(worst.atRisk),
743
+ " per 1,000 ",
744
+ worst.unit ?? "requests"
745
+ ] }) : null
746
+ ] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
747
+ /* @__PURE__ */ jsx2(Span, { fg: tried.length ? COLOR2.green : COLOR2.faint, children: tried.length ? "\u2713" : "\u25C7" }),
748
+ " ",
749
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: tried.length ? "No problems so far" : "Nothing tested yet" })
750
+ ] })
751
+ ] })
752
+ ] });
753
+ }
754
+ function StripSummary({ s, counts, total, tick }) {
755
+ const tested = (s.board ?? []).filter((b) => b.mark !== "wait");
756
+ const shown = [...tested].sort((a, b) => WORST2.indexOf(a.mark) - WORST2.indexOf(b.mark));
757
+ const sep = " \xB7 ";
758
+ return /* @__PURE__ */ jsxs2(Panel, { title: "Tested", note: /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.faint, children: [
759
+ total - counts.wait,
760
+ " of ",
761
+ total,
762
+ " workflows"
763
+ ] }), grow: true, height: "100%", children: [
764
+ /* @__PURE__ */ jsxs2(Text2, { children: [
765
+ /* @__PURE__ */ jsxs2(Span, { fg: counts.run ? HUE.run : COLOR2.faint, children: [
766
+ counts.run,
767
+ " testing"
768
+ ] }),
769
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: sep }),
770
+ /* @__PURE__ */ jsxs2(Span, { fg: counts.wait ? COLOR2.soft : COLOR2.faint, children: [
771
+ counts.wait,
772
+ " waiting"
773
+ ] })
774
+ ] }),
775
+ /* @__PURE__ */ jsxs2(Text2, { children: [
776
+ /* @__PURE__ */ jsxs2(Span, { fg: counts.pass + counts.fixed ? COLOR2.green : COLOR2.faint, children: [
777
+ counts.pass + counts.fixed,
778
+ " passed"
779
+ ] }),
780
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: sep }),
781
+ /* @__PURE__ */ jsxs2(Span, { fg: counts.problem ? COLOR2.red : COLOR2.faint, children: [
782
+ counts.problem,
783
+ " problem",
784
+ counts.problem === 1 ? "" : "s"
785
+ ] })
786
+ ] }),
787
+ counts.fixing || counts.skip ? /* @__PURE__ */ jsxs2(Text2, { children: [
788
+ counts.fixing ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
789
+ /* @__PURE__ */ jsxs2(Span, { fg: HUE.fixing, children: [
790
+ counts.fixing,
791
+ " fixing"
792
+ ] }),
793
+ counts.skip ? sep : null
794
+ ] }) : null,
795
+ counts.skip ? /* @__PURE__ */ jsxs2(Span, { fg: HUE.skip, children: [
796
+ counts.skip,
797
+ " skipped"
798
+ ] }) : null
799
+ ] }) : null,
800
+ shown.length ? /* @__PURE__ */ jsx2(Text2, { children: shown.map((b, i) => /* @__PURE__ */ jsx2(Span, { fg: squareHue(b.mark, tick), children: "\u2584 " }, i)) }) : null
801
+ ] });
802
+ }
803
+ var SPACED2 = "#52525b";
804
+ function WallBlock3({ b, mode, cell }) {
805
+ if (b.bar) {
806
+ const per = Math.ceil(b.count / b.cols), runs = [];
807
+ for (let k = 0; k < b.cols && k * per < b.count; k++) {
808
+ let worst, rank = 99;
809
+ for (let i = k * per; i < Math.min(b.count, (k + 1) * per); i++) {
810
+ const x2 = cell(i), r = x2.m ? WORST2.indexOf(x2.m) : 4;
811
+ if (r < rank) {
812
+ rank = r;
813
+ worst = x2;
814
+ }
815
+ }
816
+ const x = worst ?? { c: SPACED2, ch: "\u2584" }, last = runs[runs.length - 1];
817
+ if (last && last.c === x.c && last.ch === x.ch) last.n++;
818
+ else runs.push({ c: x.c, ch: x.ch, n: 1 });
819
+ }
820
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", marginRight: 1, width: b.w, children: [
821
+ /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.soft, truncate: true, children: b.label }),
822
+ /* @__PURE__ */ jsx2(Text2, { children: runs.map((u, k) => /* @__PURE__ */ jsx2(Span, { fg: u.c, children: (u.ch + " ").repeat(u.n) }, k)) })
823
+ ] });
824
+ }
825
+ if (mode !== "mosaic") {
826
+ const sep = mode === "gap" ? " " : "";
827
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", marginRight: 1, width: b.w, children: [
828
+ /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.soft, truncate: true, children: b.label }),
829
+ Array.from({ length: b.lines }, (_, r) => {
830
+ const runs = [];
831
+ for (let c = 0; c < b.cols; c++) {
832
+ const i = r * b.cols + c;
833
+ if (i >= b.count) break;
834
+ const x = cell(i), last = runs[runs.length - 1];
835
+ if (last && last.c === x.c && last.ch === x.ch) last.n++;
836
+ else runs.push({ ...x, n: 1 });
837
+ }
838
+ return /* @__PURE__ */ jsx2(Text2, { children: runs.map((u, k) => /* @__PURE__ */ jsx2(Span, { fg: u.c, children: (u.ch + sep).repeat(u.n) }, k)) }, r);
839
+ })
840
+ ] });
841
+ }
842
+ const at = (pr, c) => {
843
+ const i = pr * b.cols + c;
844
+ return i < b.count ? (pr + c) % 2 ? mix2(cell(i).c, "#000000", 0.28) : cell(i).c : void 0;
845
+ };
846
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", marginRight: 1, width: b.w, children: [
847
+ /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.soft, truncate: true, children: b.label }),
848
+ Array.from({ length: b.lines }, (_, r) => {
849
+ const runs = [];
850
+ for (let c = 0; c < b.cols; c++) {
851
+ const top = at(2 * r, c), bot = at(2 * r + 1, c), last = runs[runs.length - 1];
852
+ if (last && last.top === top && last.bot === bot) last.n++;
853
+ else runs.push({ top, bot, n: 1 });
854
+ }
855
+ return /* @__PURE__ */ jsx2(Text2, { children: runs.map((u, i) => u.top === void 0 ? /* @__PURE__ */ jsx2(Span, { children: " ".repeat(u.n) }, i) : /* @__PURE__ */ jsx2(Span, { fg: u.top, bg: u.bot, children: "\u2580".repeat(u.n) }, i)) }, r);
856
+ })
857
+ ] });
858
+ }
859
+ var mix2 = (a, b, k) => "#" + [1, 3, 5].map((i) => Math.round(parseInt(a.slice(i, i + 2), 16) * (1 - k) + parseInt(b.slice(i, i + 2), 16) * k).toString(16).padStart(2, "0")).join("");
860
+ function Wall({ groups, inner, maxLines, cell, extraOf }) {
861
+ const fitted = fitGroups(groups, inner, maxLines, true, extraOf);
862
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", children: [
863
+ fitted.rows.map((row, r) => /* @__PURE__ */ jsx2(Box2, { flexDirection: "row", children: row.map((b) => /* @__PURE__ */ jsx2(WallBlock3, { b, mode: fitted.mode, cell: (i) => cell(b.members ?? [b.name], i) }, b.name)) }, r)),
864
+ fitted.merged > 0 ? /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.faint, children: [
865
+ fitted.merged,
866
+ " smaller services are grouped as Other"
867
+ ] }) : null
868
+ ] });
869
+ }
870
+ function Wordmark() {
871
+ const rows = wordmarkRows(), w = rows[0].length;
872
+ return /* @__PURE__ */ jsx2(Box2, { flexDirection: "column", children: rows.map((row, r) => /* @__PURE__ */ jsx2(Text2, { children: [...row].map((c, i) => c === " " ? " " : /* @__PURE__ */ jsx2(Span, { fg: mix2(COLOR2.accent, "#a78bfa", i / (w - 1)), children: c }, i)) }, r)) });
873
+ }
874
+ function ResultPanel({ s }) {
875
+ const affected = (s.board ?? []).filter((b) => b.mark === "problem" || b.mark === "fixing" || b.mark === "fixed").length;
876
+ const serious = s.findings.filter((f) => f.severity !== "low");
877
+ const ranked = [...serious].sort((a, b) => (b.atRiskAmount ?? b.perIncident ?? 0) - (a.atRiskAmount ?? a.perIncident ?? 0)), worst = ranked[0];
878
+ const multi = (s.workflows?.length ?? 0) > 1;
879
+ return /* @__PURE__ */ jsxs2(Panel, { title: "Result", grow: true, children: [
880
+ worst ? /* @__PURE__ */ jsxs2(Box2, { flexDirection: "row", justifyContent: "space-between", height: 1, flexShrink: 0, children: [
881
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
882
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.red, children: /* @__PURE__ */ jsx2(Bold, { children: "\u2717" }) }),
883
+ " ",
884
+ /* @__PURE__ */ jsxs2(Bold, { children: [
885
+ serious.length,
886
+ " problem",
887
+ serious.length === 1 ? "" : "s",
888
+ " found",
889
+ affected ? ` \xB7 in ${plural(affected, "workflow")}` : ""
890
+ ] })
891
+ ] }),
892
+ worst.atRisk ? /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
893
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.red, children: /* @__PURE__ */ jsx2(Bold, { children: whole(worst.atRisk) }) }),
894
+ /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.soft, children: [
895
+ " per 1,000 ",
896
+ worst.unit ?? "requests"
897
+ ] })
898
+ ] }) : null
899
+ ] }) : /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
900
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.green, children: "\u2713" }),
901
+ " ",
902
+ /* @__PURE__ */ jsx2(Bold, { children: "No problems found" })
903
+ ] }),
904
+ worst?.atRisk && worst.price ? /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.faint, children: [
905
+ worst.price,
906
+ " each",
907
+ worst.monthlyAtRisk ? /* @__PURE__ */ jsxs2(Span, { children: [
908
+ " \xB7 ",
909
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.red, children: /* @__PURE__ */ jsx2(Bold, { children: whole(worst.monthlyAtRisk) }) }),
910
+ " a month at ",
911
+ (worst.customers ?? 0).toLocaleString("en-US"),
912
+ " customers"
913
+ ] }) : null
914
+ ] }) : worst?.atRisk ? /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
915
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: "monthly figure: " }),
916
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.accent, children: "npx agenttwin costs --customers N" })
917
+ ] }) : null,
918
+ ranked.slice(0, 2).map((f, n) => /* @__PURE__ */ jsxs2(Box2, { flexDirection: "row", justifyContent: "space-between", height: 1, flexShrink: 0, children: [
919
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, truncate: true, children: [
920
+ /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.faint, children: [
921
+ n + 1,
922
+ " "
923
+ ] }),
924
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: f.title })
925
+ ] }),
926
+ f.atRisk || f.price ? /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.red, children: /* @__PURE__ */ jsx2(Bold, { children: f.atRisk ? `${whole(f.atRisk)} / 1k ${f.unit ?? "requests"}` : f.price }) }) : null
927
+ ] }, `${f.title}|${n}`)),
928
+ s.fix ? /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
929
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: "Fix " }),
930
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: s.fix.title })
931
+ ] }) : null,
932
+ s.fix?.promptFile ? /* @__PURE__ */ jsxs2(Text2, { height: 1, truncate: true, children: [
933
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: "Agent " }),
934
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: s.fix.promptFile }),
935
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " c copy" })
936
+ ] }) : null,
937
+ s.result?.proof ? /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
938
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: "Proof " }),
939
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: s.result.proof })
940
+ ] }) : null
941
+ ] });
942
+ }
943
+ function Risk({ s, tick, rows, width }) {
944
+ const hit = (s.board ?? []).filter((b) => b.mark === "problem" || b.mark === "fixing" || b.mark === "fixed").length;
945
+ const serious = s.findings.filter((f) => f.severity !== "low");
946
+ const ranked = [...serious].sort((a, b) => (b.atRiskAmount ?? b.perIncident ?? 0) - (a.atRiskAmount ?? a.perIncident ?? 0));
947
+ const fit = Math.max(2, Math.min(8, Math.floor((rows - 24) / 3))), from = useArrowScroll(ranked.length, fit);
948
+ const running = s.cases.find((c) => c.status === "running");
949
+ const traced = running?.trace.length ? running : [...s.cases].reverse().find((c) => c.trace.length);
950
+ const tried = s.cases.filter(finished), ok = tried.filter((c) => c.status === "passed").length, failed = tried.filter((c) => c.status === "found").length;
951
+ const at = running ? s.cases.indexOf(running) + 1 : 0;
952
+ const headline = running && s.stage === 4 ? `Breaking ${at}/${s.cases.length} \xB7 ${scenario(running.title, running.id).name}` : s.stage ? HEADLINES[s.stage] ?? "" : "Getting ready";
953
+ const sub = s.stage === 4 && running ? scenario(running.title, running.id).question : s.stage === 3 ? "Same code and request your users send; every outside call goes to a twin, nothing to production." : s.stage === 2 ? "Each twin behaves like the real service: its records, its errors, its webhooks." : s.stage === 1 ? "Looking for the routes and jobs that charge, email, write or call an AI model.\nA large repository takes a few minutes. It is working, not stuck." : s.tail.at(-1) ?? "";
954
+ const title = serious.length ? "Risk" : "Now";
955
+ return /* @__PURE__ */ jsxs2(Panel, { title, grow: true, height: "100%", children: [
956
+ serious.length ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
957
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
958
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.red, children: "\u2717" }),
959
+ " ",
960
+ /* @__PURE__ */ jsxs2(Bold, { children: [
961
+ serious.length,
962
+ " problem",
963
+ serious.length === 1 ? "" : "s",
964
+ " so far",
965
+ hit ? ` \xB7 in ${plural(hit, "workflow")}` : ""
966
+ ] })
967
+ ] }),
968
+ ranked.slice(from, from + fit).map((f) => /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", paddingLeft: 2, marginTop: 1, children: [
969
+ f.atRisk ? /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
970
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.red, children: /* @__PURE__ */ jsx2(Bold, { children: whole(f.atRisk) }) }),
971
+ /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.soft, children: [
972
+ " per 1,000 ",
973
+ f.unit ?? "requests"
974
+ ] })
975
+ ] }) : /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.faint, children: "priced at Find" }),
976
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.text, truncate: true, children: f.title }),
977
+ whenText(f.when) || f.service ? /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.faint, truncate: true, children: [whenText(f.when), f.service].filter(Boolean).join(" \xB7 ") }) : null
978
+ ] }, f.title)),
979
+ ranked.length > fit ? /* @__PURE__ */ jsxs2(Text2, { height: 1, fg: COLOR2.faint, children: [
980
+ " ",
981
+ from + 1,
982
+ "-",
983
+ Math.min(ranked.length, from + fit),
984
+ " of ",
985
+ ranked.length,
986
+ " \xB7 rest in the report"
987
+ ] }) : null
988
+ ] }) : /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
989
+ /* @__PURE__ */ jsx2(Span, { fg: tried.length ? COLOR2.green : COLOR2.faint, children: tried.length ? "\u2713" : "\u25C7" }),
990
+ " ",
991
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: tried.length ? "No problems so far" : "Nothing tested yet" }),
992
+ s.cases.length ? /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.faint, children: [
993
+ " ",
994
+ tried.length,
995
+ " of ",
996
+ s.cases.length,
997
+ " scenarios checked"
998
+ ] }) : null
999
+ ] }),
1000
+ /* @__PURE__ */ jsx2(Rule, {}),
1001
+ /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
1002
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.accent, children: spin(tick) }),
1003
+ " ",
1004
+ /* @__PURE__ */ jsx2(Bold, { children: headline })
1005
+ ] }),
1006
+ tried.length ? /* @__PURE__ */ jsxs2(Text2, { height: 1, children: [
1007
+ /* @__PURE__ */ jsxs2(Span, { fg: ok ? COLOR2.green : COLOR2.faint, children: [
1008
+ ok,
1009
+ " OK"
1010
+ ] }),
1011
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " \xB7 " }),
1012
+ /* @__PURE__ */ jsxs2(Span, { fg: tried.length - ok - failed ? COLOR2.yellow : COLOR2.faint, children: [
1013
+ tried.length - ok - failed,
1014
+ " skip"
1015
+ ] }),
1016
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " \xB7 " }),
1017
+ /* @__PURE__ */ jsxs2(Span, { fg: failed ? COLOR2.red : COLOR2.faint, children: [
1018
+ failed,
1019
+ " failed"
1020
+ ] })
1021
+ ] }) : null,
1022
+ sub ? /* @__PURE__ */ jsx2(Text2, { height: 2, fg: COLOR2.soft, wrapMode: "word", children: sub }) : null,
1023
+ traced?.trace.length ? /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", marginTop: 1, children: [
1024
+ /* @__PURE__ */ jsx2(Text2, { height: 1, fg: COLOR2.faint, children: traced === running ? "Calls so far" : `Calls in \u201C${scenario(traced.title, traced.id).name}\u201D` }),
1025
+ traced.trace.slice(-4).map((call, i) => /* @__PURE__ */ jsx2(Text2, { height: 1, truncate: true, children: call.fault ? /* @__PURE__ */ jsx2(Fragment2, { children: /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.yellow, children: [
1026
+ "\u25B2 ",
1027
+ (call.detail || `fault injected on ${call.service}`).replace(/^[a-z-]+ fault:\s*/i, "")
1028
+ ] }) }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
1029
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: "\u2192 " }),
1030
+ /* @__PURE__ */ jsx2(Span, { fg: brandHex(call.service, call.service) ?? COLOR2.accent, children: /* @__PURE__ */ jsx2(Bold, { children: call.service.padEnd(10) }) }),
1031
+ " ",
1032
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.text, children: call.operation.padEnd(7) }),
1033
+ " ",
1034
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: cut2(call.path, Math.max(12, width - 24)) })
1035
+ ] }) }, i))
1036
+ ] }) : null
1037
+ ] });
1038
+ }
1039
+ function Board({ s, d, tick, width, rows, side, maxLinesOverride }) {
1040
+ const over = !!s.done, narrowReport = over && !side;
1041
+ const step = s.done && s.done !== "stopped" ? 7 : Math.max(1, s.stage || (s.workflow ? 2 : 1));
1042
+ const active = step >= 3 && step <= 6;
1043
+ const railW = width >= 150 ? 20 : 22, rightW = active ? width >= 150 ? 58 : 46 : width >= 150 ? 46 : 36, inner = (side ? width - railW - rightW : width) - 4;
1044
+ const { byGroup, counts, total } = boardView(s);
1045
+ const defaultLines = Math.max(5, rows - (side ? 15 : step === 1 ? 20 : 19) - (side && step > 1 && d.twins?.length ? 5 : 0));
1046
+ const maxLines = maxLinesOverride ?? (narrowReport ? Math.max(5, rows - 12) : defaultLines);
1047
+ const cell = (members, i) => {
1048
+ let k = i, mark = "wait";
1049
+ for (const m of members) {
1050
+ const list = byGroup.get(m) ?? [];
1051
+ if (k < list.length) {
1052
+ mark = list[k];
1053
+ break;
1054
+ }
1055
+ k -= list.length;
1056
+ }
1057
+ return { c: squareHue(mark, mark === "run" ? tick : 0), ch: "\u2584", m: mark };
1058
+ };
1059
+ const extraOf = (members) => {
1060
+ let bad = 0, skip = 0;
1061
+ for (const m of members) for (const k of byGroup.get(m) ?? []) {
1062
+ if (k === "problem" || k === "fixing") bad++;
1063
+ if (k === "skip") skip++;
1064
+ }
1065
+ return [bad ? `\u2717${bad}` : "", skip ? `?${skip}` : ""].filter(Boolean).join(" ");
1066
+ };
1067
+ const twinSet = new Set((d.twins ?? []).map((t) => t.toLowerCase()));
1068
+ const groups = d.groups.map((x) => ({ ...x, twin: twinSet.has(x.name.toLowerCase()) }));
1069
+ const legend = MARKS.filter((m) => counts[m] > 0 || m === "pass" || m === "problem").filter((m) => !(over ? m === "wait" || m === "run" : m === "skip"));
1070
+ const compact = side && active;
1071
+ const wallW = narrowReport ? 40 : void 0, reportW = narrowReport ? width - 41 : side ? rightW : width;
1072
+ const nowW = compact ? Math.max(56, width - railW - STRIP_W - 3) : rightW;
1073
+ const right = over ? /* @__PURE__ */ jsx2(Report, { s, counts, total, width: side ? rightW : reportW, problems: side ? void 0 : s.findings.filter((f) => f.severity !== "low").length, compact: !side, tight: rows < 48 }) : step === 1 ? side ? /* @__PURE__ */ jsx2(Panel, { title: "How they start", width: rightW, height: "100%", children: /* @__PURE__ */ jsx2(Starts, { d }) }) : null : side ? step === 6 ? /* @__PURE__ */ jsx2(Panel, { title: "Fix triage", width: nowW, children: /* @__PURE__ */ jsx2(Triage, { s, max: Math.max(3, Math.min(8, Math.floor((rows - 22) / 4))) }) }) : /* @__PURE__ */ jsx2(Box2, { width: nowW, flexDirection: "column", children: /* @__PURE__ */ jsx2(Risk, { s, tick, rows, width: nowW }) }) : /* @__PURE__ */ jsx2(NowLine, { s, tick });
1074
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", children: [
1075
+ /* @__PURE__ */ jsx2(Box2, { paddingX: 1, marginBottom: 1, flexShrink: 0, children: /* @__PURE__ */ jsxs2(Text2, { children: [
1076
+ /* @__PURE__ */ jsx2(Span, { fg: "#ffffff", children: /* @__PURE__ */ jsxs2(Bold, { children: [
1077
+ "Step ",
1078
+ step,
1079
+ " \xB7 ",
1080
+ STEPS[step - 1],
1081
+ " "
1082
+ ] }) }),
1083
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: step === 7 ? "Every workflow as one square. Green passed, red has a problem, amber was not tested." : SAYS[step - 1] })
1084
+ ] }) }),
1085
+ /* @__PURE__ */ jsxs2(Box2, { flexDirection: side || narrowReport ? "row" : "column", flexGrow: 1, flexShrink: 1, overflow: "hidden", children: [
1086
+ side ? /* @__PURE__ */ jsx2(Rail, { s, step, d, counts, over, w: railW }) : null,
1087
+ compact ? /* @__PURE__ */ jsx2(Box2, { width: STRIP_W, marginRight: 1, children: /* @__PURE__ */ jsx2(StripSummary, { s, counts, total, tick }) }) : null,
1088
+ compact ? null : /* @__PURE__ */ jsxs2(Panel, { title: "Every workflow", width: wallW, height: "100%", note: /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.faint, children: side || narrowReport ? `one square each \xB7 ${total}` : `one square each \xB7 ${d.workflows} workflows \xB7 ${d.services} services \xB7 ${d.twinnable} with a twin` }), grow: true, children: [
1089
+ /* @__PURE__ */ jsx2(Wall, { groups, inner: narrowReport ? 36 : inner, maxLines, cell, extraOf }),
1090
+ !side && step === 1 && !over ? /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.soft, truncate: true, children: d.kinds.slice(0, 3).map((k) => `${k.count} ${k.name}`).join(" \xB7 ") }) : null,
1091
+ !side && step === 1 && !over ? /* @__PURE__ */ jsxs2(Text2, { fg: COLOR2.text, truncate: true, children: [
1092
+ "Tests the ",
1093
+ Math.min(d.testing, d.workflows),
1094
+ " riskiest first. All: AGENTTWIN_MAX_WORKFLOWS=",
1095
+ d.workflows
1096
+ ] }) : null,
1097
+ side && step > 1 && d.twins?.length ? /* @__PURE__ */ jsx2(Box2, { marginTop: 1, children: /* @__PURE__ */ jsxs2(Text2, { wrapMode: "word", fg: COLOR2.green, children: [
1098
+ /* @__PURE__ */ jsxs2(Bold, { children: [
1099
+ "Twins ready ",
1100
+ d.twins.length,
1101
+ " "
1102
+ ] }),
1103
+ d.twins.slice(0, 40).join(" \xB7 "),
1104
+ d.twins.length > 40 ? /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.faint, children: [
1105
+ " \xB7 +",
1106
+ d.twins.length - 40,
1107
+ " more"
1108
+ ] }) : null
1109
+ ] }) }) : null,
1110
+ narrowReport ? null : /* @__PURE__ */ jsxs2(Box2, { marginTop: 1, flexWrap: "wrap", children: [
1111
+ twinSet.size ? /* @__PURE__ */ jsx2(Box2, { marginRight: 2, children: /* @__PURE__ */ jsxs2(Text2, { children: [
1112
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.green, children: "\u25C6" }),
1113
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: " has a twin" })
1114
+ ] }) }) : null,
1115
+ legend.map((m) => /* @__PURE__ */ jsx2(Box2, { marginRight: 2, children: /* @__PURE__ */ jsxs2(Text2, { children: [
1116
+ /* @__PURE__ */ jsx2(Span, { fg: HUE[m], children: "\u2584" }),
1117
+ /* @__PURE__ */ jsxs2(Span, { fg: COLOR2.soft, children: [
1118
+ " ",
1119
+ counts[m],
1120
+ " ",
1121
+ LABEL[m]
1122
+ ] })
1123
+ ] }) }, m))
1124
+ ] })
1125
+ ] }),
1126
+ right
1127
+ ] })
1128
+ ] });
1129
+ }
1130
+ function BoardApp({ store, now, columns, rows, note }) {
1131
+ const s = useSyncExternalStore2(store.subscribe, store.get), live = !s.done, tick = useTick(live), t = now();
1132
+ const board = !!s.discovery && !!s.board?.length;
1133
+ const width = Math.min(columns, board ? 180 : 110), side = width >= (board ? 110 : 96);
1134
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", width, height: rows, overflow: "hidden", children: [
1135
+ /* @__PURE__ */ jsxs2(Box2, { flexDirection: "row", justifyContent: "space-between", paddingX: 1, marginBottom: 1, flexShrink: 0, children: [
1136
+ /* @__PURE__ */ jsx2(Wordmark, {}),
1137
+ /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", alignItems: "flex-end", children: [
1138
+ /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.faint, children: s.done === "stopped" ? "stopped" : s.done ? "done" : s.workflow ? s.batch ? `testing workflow ${s.batch.n} of ${s.batch.of}` : "testing" : "scanning your code" }),
1139
+ /* @__PURE__ */ jsx2(Text2, { children: /* @__PURE__ */ jsx2(Bold, { children: !live && (s.workflows?.length ?? 0) > 1 ? `${s.workflows.length} workflows` : s.workflow ? cut2(s.workflow.title, Math.max(12, width - 50)) : "finding a workflow\u2026" }) }),
1140
+ /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.soft, children: clock(t - s.startedAt) })
1141
+ ] })
1142
+ ] }),
1143
+ board && s.discovery ? /* @__PURE__ */ jsx2(Board, { d: s.discovery, s, tick, width, rows, side }) : null,
1144
+ board && s.done && side && (s.findings.length > 0 || s.result?.couldNotRun || s.result?.nothingTested) ? /* @__PURE__ */ jsx2(ResultPanel, { s }) : null,
1145
+ /* @__PURE__ */ jsxs2(Box2, { flexDirection: "row", justifyContent: "space-between", paddingX: 1, flexShrink: 0, children: [
1146
+ note ? /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.green, children: note }) : live ? /* @__PURE__ */ jsxs2(Text2, { children: [
1147
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: "q" }),
1148
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " quit " }),
1149
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: "--plain" }),
1150
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: " full log" })
1151
+ ] }) : /* @__PURE__ */ jsxs2(Text2, { children: [
1152
+ copyablePrompt(s) ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
1153
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: "c" }),
1154
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: " copy fix prompt " })
1155
+ ] }) : null,
1156
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.faint, children: "log " }),
1157
+ /* @__PURE__ */ jsx2(Span, { fg: COLOR2.soft, children: ".agenttwin/last-run.log" })
1158
+ ] }),
1159
+ /* @__PURE__ */ jsx2(Text2, { fg: COLOR2.faint, children: "agenttwin.si" })
1160
+ ] })
1161
+ ] });
1162
+ }
1163
+ function copyablePrompt(s) {
1164
+ return s.done && s.fix?.promptFile ? s.fix.promptFile : void 0;
1165
+ }
1166
+ function LiveRoot({ store, now, onQuit, stream }) {
1167
+ const { useKeyboard, useTerminalDimensions } = runtime().react;
1168
+ const { width, height } = useTerminalDimensions();
1169
+ const [note, setNote] = useState("");
1170
+ useKeyboard((key) => {
1171
+ if (key.name === "q" || key.ctrl && key.name === "c") {
1172
+ onQuit();
1173
+ return;
1174
+ }
1175
+ if (key.name === "c") {
1176
+ const prompt = copyablePrompt(store.get());
1177
+ if (prompt) {
1178
+ void copyFixPrompt(prompt, { write: (text) => stream.write(text) }).then((result) => {
1179
+ setNote(result.ok ? "Copied the fix prompt. Paste it into your coding agent." : `Could not copy: ${result.reason ?? "clipboard unavailable"}.`);
1180
+ const timer = setTimeout(() => setNote(""), 4e3);
1181
+ timer.unref?.();
1182
+ });
1183
+ }
1184
+ }
1185
+ });
1186
+ return /* @__PURE__ */ jsx2(BoardApp, { store, now, columns: width, rows: Math.max(3, height), note: note || void 0 });
1187
+ }
1188
+ async function createOpenTuiLiveView(stream, now = () => Date.now()) {
1189
+ const { createCliRenderer } = runtime().core;
1190
+ const { createRoot } = runtime().react;
1191
+ let state = emptyState(now()), stopped = false, paused = false, root;
1192
+ const listeners = /* @__PURE__ */ new Set(), lines = [];
1193
+ const store = { get: () => state, subscribe: (f) => {
1194
+ listeners.add(f);
1195
+ return () => listeners.delete(f);
1196
+ } };
1197
+ const set = (next) => {
1198
+ state = next;
1199
+ for (const f of listeners) f();
1200
+ };
1201
+ const renderer = await createCliRenderer({
1202
+ stdin: process.stdin,
1203
+ stdout: stream,
1204
+ screenMode: "alternate-screen",
1205
+ exitOnCtrlC: false,
1206
+ exitSignals: [],
1207
+ targetFps: 30,
1208
+ useMouse: false,
1209
+ consoleMode: "disabled"
1210
+ });
1211
+ const mount = () => {
1212
+ if (stopped || paused) return;
1213
+ root = createRoot(renderer);
1214
+ root.render(/* @__PURE__ */ jsx2(LiveRoot, { store, now, onQuit: () => void shutdown(0), stream }));
1215
+ };
1216
+ let closing;
1217
+ const shutdown = (code) => {
1218
+ if (closing) return closing;
1219
+ closing = (async () => {
1220
+ if (stopped) return;
1221
+ stopped = true;
1222
+ process.off("SIGINT", onSignal);
1223
+ process.off("SIGTERM", onSignal);
1224
+ try {
1225
+ root?.unmount();
1226
+ } catch {
1227
+ }
1228
+ renderer.destroy();
1229
+ try {
1230
+ await renderer.closed;
1231
+ } catch {
1232
+ }
1233
+ if (code !== void 0) process.exit(code);
1234
+ })();
1235
+ return closing;
1236
+ };
1237
+ const onSignal = () => {
1238
+ void shutdown(130);
1239
+ };
1240
+ process.once("SIGINT", onSignal);
1241
+ process.once("SIGTERM", onSignal);
1242
+ try {
1243
+ mount();
1244
+ } catch (error) {
1245
+ process.off("SIGINT", onSignal);
1246
+ process.off("SIGTERM", onSignal);
1247
+ renderer.destroy();
1248
+ throw error;
1249
+ }
1250
+ return {
1251
+ kind: "opentui",
1252
+ log(line) {
1253
+ lines.push(line);
1254
+ if (paused) {
1255
+ stream.write(line + "\n");
1256
+ return;
1257
+ }
1258
+ const plain = line.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "").trim();
1259
+ if (plain && !/^\d\/7 |^Summary$|^[│├└]/.test(plain)) set({ ...state, tail: [...state.tail, plain].slice(-4) });
1260
+ },
1261
+ emit(e) {
1262
+ if (e.type === "prompt") {
1263
+ if (e.active && !paused) {
1264
+ paused = true;
1265
+ try {
1266
+ root?.unmount();
1267
+ } catch {
1268
+ }
1269
+ void renderer.suspend().catch(() => {
1270
+ });
1271
+ } else if (!e.active && paused) {
1272
+ paused = false;
1273
+ void renderer.resume().then(mount).catch(() => mount());
1274
+ }
1275
+ return;
1276
+ }
1277
+ set(reduce(state, e, now()));
1278
+ },
1279
+ stop(cwd, quiet) {
1280
+ if (stopped) return;
1281
+ if (!state.done) set({ ...state, done: "stopped" });
1282
+ const writeLogs = () => {
1283
+ if (!cwd) return;
1284
+ try {
1285
+ mkdirSync3(join3(cwd, ".agenttwin"), { recursive: true });
1286
+ const items = triageFindings(state.findings, state.fix);
1287
+ if (items.length) writeFileSync3(join3(cwd, ".agenttwin", "triage.json"), JSON.stringify({ lanes: laneCounts(items), items }, null, 2) + "\n");
1288
+ writeFileSync3(join3(cwd, ".agenttwin", "last-run.log"), lines.map((l) => l.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "")).join("\n") + "\n");
1289
+ } catch {
1290
+ }
1291
+ };
1292
+ stopped = true;
1293
+ process.off("SIGINT", onSignal);
1294
+ process.off("SIGTERM", onSignal);
1295
+ try {
1296
+ root?.unmount();
1297
+ } catch {
1298
+ }
1299
+ renderer.destroy();
1300
+ writeLogs();
1301
+ stream.write(quiet ? "\n" : `
1302
+ Everything the run printed is in .agenttwin/last-run.log; npx agenttwin --plain shows it as it runs.
1303
+
1304
+ `);
1305
+ }
1306
+ };
1307
+ }
1308
+ export {
1309
+ BoardApp,
1310
+ copyablePrompt,
1311
+ createOpenTuiLiveView
1312
+ };