deepline 0.3.546 → 0.3.548

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 (204) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +13 -0
  2. package/dist/bundling-sources/sdk/src/index.ts +7 -1
  3. package/dist/bundling-sources/sdk/src/integrations.ts +17 -7
  4. package/dist/bundling-sources/sdk/src/play.ts +71 -0
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +13 -4
  7. package/dist/bundling-sources/sdk/src/types.ts +33 -0
  8. package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +7 -0
  9. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +2 -0
  10. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +1 -0
  11. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +19 -1
  12. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +17 -2
  13. package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +57 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +295 -52
  15. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -1
  16. package/dist/bundling-sources/shared_libs/play-runtime/docflow-decision-tracker.ts +135 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/docflow-fail-open.ts +177 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +99 -2
  19. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -10
  20. package/dist/bundling-sources/shared_libs/play-runtime/fenced-call-diagnostics.ts +211 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +52 -14
  22. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +68 -2
  23. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +18 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +68 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +100 -3
  26. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +9 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +48 -0
  28. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -1
  29. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +716 -51
  30. package/dist/bundling-sources/shared_libs/plays/docflow-decision-arms.ts +146 -0
  31. package/dist/bundling-sources/shared_libs/plays/docflow-flow-order.ts +94 -0
  32. package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +10 -1
  33. package/dist/bundling-sources/shared_libs/plays/docflow.ts +787 -117
  34. package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +8 -2
  35. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +6 -0
  36. package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +13 -0
  37. package/dist/bundling-sources/shared_libs/product-notifications/billing-sales.ts +25 -0
  38. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +3 -0
  39. package/dist/bundling-sources/shared_libs/security/email-domain.ts +24 -0
  40. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +56 -0
  41. package/dist/cli/auth-7UJFY5BY.js +43 -0
  42. package/dist/cli/{auth-KFWG72AZ.mjs → auth-YOOVLLUL.mjs} +5 -5
  43. package/dist/cli/{billing-MMZ336HO.mjs → billing-2NCNX6L2.mjs} +10 -10
  44. package/dist/cli/{billing-OQVOAZ4S.js → billing-HETIOUD6.js} +96 -96
  45. package/dist/cli/{chunk-JVOUQFHT.js → chunk-2OG2KBYJ.js} +1 -1
  46. package/dist/cli/{chunk-JA633HRV.mjs → chunk-3QRU6RY7.mjs} +3 -3
  47. package/dist/cli/{chunk-TI6DTURF.js → chunk-4WAM6TLD.js} +7 -1
  48. package/dist/cli/{chunk-RO66FPTS.mjs → chunk-53QLWPZK.mjs} +1 -1
  49. package/dist/cli/{chunk-6LG7MLJ2.js → chunk-5OJOFUMO.js} +44 -44
  50. package/dist/cli/{chunk-F2VEFMU5.js → chunk-5XFJBIQT.js} +13 -13
  51. package/dist/cli/{chunk-UQJBV5PM.js → chunk-5XXPP3PR.js} +10 -10
  52. package/dist/cli/{chunk-6FBDTYR2.mjs → chunk-64BFUBXX.mjs} +2 -2
  53. package/dist/cli/{chunk-VAT2SXFF.js → chunk-6GIZNOXQ.js} +12 -12
  54. package/dist/cli/{chunk-7MY7KWJS.mjs → chunk-7AJ5V3BK.mjs} +1 -1
  55. package/dist/cli/{chunk-MEGHIX4M.js → chunk-7H6TQ6W2.js} +5 -5
  56. package/dist/cli/{chunk-PMDHY2YK.js → chunk-7JIOJLTS.js} +7 -7
  57. package/dist/cli/{chunk-EEJHB76U.js → chunk-7UJZWI5Z.js} +12 -12
  58. package/dist/cli/{chunk-X5KOHDJN.mjs → chunk-ATTURFOV.mjs} +1 -1
  59. package/dist/cli/{chunk-SH32HL7I.js → chunk-AUYBBFPT.js} +53 -53
  60. package/dist/cli/{chunk-JCWNF44W.js → chunk-BDBEEV6X.js} +22 -22
  61. package/dist/cli/{chunk-WKHPLBJK.js → chunk-BWJZ4NQJ.js} +15 -15
  62. package/dist/cli/{chunk-2JHYYB3F.js → chunk-CSPHSNBW.js} +3 -3
  63. package/dist/cli/{chunk-4AZLGNXV.js → chunk-CXZLHBNK.js} +4 -4
  64. package/dist/cli/{chunk-J65HJCJO.mjs → chunk-F4ON5COB.mjs} +2 -2
  65. package/dist/cli/{chunk-KUK7ARXA.mjs → chunk-FMQA7UZZ.mjs} +2 -2
  66. package/dist/cli/{chunk-UREAIHUU.mjs → chunk-FUUYWEF4.mjs} +3 -3
  67. package/dist/cli/{chunk-HXIR3VQL.mjs → chunk-FZHMNK6F.mjs} +7 -1
  68. package/dist/cli/{chunk-PU3ZAG6V.mjs → chunk-GCEGQ7TQ.mjs} +1 -1
  69. package/dist/cli/{chunk-BLYW6FFB.js → chunk-GJA2PRHJ.js} +2 -2
  70. package/dist/cli/{chunk-TBWYZOSV.js → chunk-GUIYFOG2.js} +3 -3
  71. package/dist/cli/{chunk-BTFUAGHC.js → chunk-HDLMX7SG.js} +16 -16
  72. package/dist/cli/{chunk-VTK3HGMN.mjs → chunk-HIMZ57QD.mjs} +5 -5
  73. package/dist/cli/{chunk-JYG4XZLT.js → chunk-HTZIJORU.js} +99 -99
  74. package/dist/cli/{chunk-VPERQ3U6.mjs → chunk-HU3DDLGD.mjs} +5 -5
  75. package/dist/cli/{chunk-H7Q5IDO3.js → chunk-I2JIWKCQ.js} +20 -20
  76. package/dist/cli/{chunk-MXQP7CXZ.js → chunk-IIWXBRDK.js} +3 -3
  77. package/dist/cli/{chunk-MI7X6V6V.mjs → chunk-IQBXX54G.mjs} +3 -3
  78. package/dist/cli/{chunk-SYTWWVIQ.js → chunk-JQWX377P.js} +5 -5
  79. package/dist/cli/{chunk-Z3UEBFIN.js → chunk-LAVPP6WD.js} +41 -41
  80. package/dist/cli/{chunk-JCH4UNNS.js → chunk-M2OZORIH.js} +2 -2
  81. package/dist/cli/{chunk-Z7SXGOIQ.mjs → chunk-MF7PCM6C.mjs} +1 -1
  82. package/dist/cli/{chunk-7ZW67ME6.mjs → chunk-MQSKSISW.mjs} +1 -1
  83. package/dist/cli/{chunk-JARZ47OP.mjs → chunk-MWQ4WWZF.mjs} +2 -2
  84. package/dist/cli/{chunk-EEG46QZY.mjs → chunk-NFMX7BRF.mjs} +2 -2
  85. package/dist/cli/{chunk-VXTTAYOT.mjs → chunk-OGDQFVCP.mjs} +3 -3
  86. package/dist/cli/{chunk-3DUNNZB6.mjs → chunk-OQCYSLML.mjs} +4 -4
  87. package/dist/cli/{chunk-5W4ENHWM.js → chunk-PVE3A2BO.js} +285 -264
  88. package/dist/cli/{chunk-F5YQXCP3.js → chunk-PVQCX6KQ.js} +50 -7
  89. package/dist/cli/{chunk-GYTSDSQD.mjs → chunk-QQBRXMZM.mjs} +11 -11
  90. package/dist/cli/{chunk-6Y5TU3R7.mjs → chunk-QZ74ZC55.mjs} +1 -1
  91. package/dist/cli/{chunk-5OEFXAKP.mjs → chunk-RMCCB3XY.mjs} +50 -7
  92. package/dist/cli/{chunk-5V7NZKGG.js → chunk-T3RDWG5J.js} +2 -2
  93. package/dist/cli/{chunk-OAKWSLKS.mjs → chunk-TKGFHRHE.mjs} +28 -7
  94. package/dist/cli/{chunk-HJR2DDJS.mjs → chunk-U35ZLVBA.mjs} +2 -2
  95. package/dist/cli/{chunk-ND7SFRQL.js → chunk-U7HJXE6Y.js} +2 -2
  96. package/dist/cli/{chunk-LX2TC3HO.mjs → chunk-UBQQR56I.mjs} +4 -4
  97. package/dist/cli/{chunk-5VNQMVCU.js → chunk-VK2GSTRN.js} +26 -26
  98. package/dist/cli/{chunk-K2XELBPF.mjs → chunk-VSACOMIA.mjs} +5 -5
  99. package/dist/cli/{chunk-IVWU7SJC.js → chunk-WI4MCR7M.js} +5 -5
  100. package/dist/cli/{chunk-LIJKRDDG.js → chunk-WIHQAZPV.js} +6 -6
  101. package/dist/cli/{chunk-LHE2TSV6.mjs → chunk-WVZF4DU7.mjs} +1 -1
  102. package/dist/cli/{chunk-2HSZCQMT.mjs → chunk-WYT3H6JD.mjs} +1 -1
  103. package/dist/cli/{chunk-GOOF7E2B.mjs → chunk-XKEBQVCP.mjs} +5 -5
  104. package/dist/cli/{chunk-P7A3H6G5.mjs → chunk-XU3D2KFR.mjs} +1 -1
  105. package/dist/cli/command-docs.js +2 -2
  106. package/dist/cli/command-docs.mjs +1 -1
  107. package/dist/cli/concurrent-runs-help-A2IQVZRJ.js +21 -0
  108. package/dist/cli/{concurrent-runs-help-C2O5YKQA.mjs → concurrent-runs-help-FDCCZ45D.mjs} +6 -6
  109. package/dist/cli/{csv-Z4DNGR54.mjs → csv-GJYLQ52D.mjs} +4 -4
  110. package/dist/cli/{csv-MJDNOIQJ.js → csv-OCEQWZO3.js} +13 -13
  111. package/dist/cli/{db-4RL2BNOF.mjs → db-5MA2UUHQ.mjs} +7 -7
  112. package/dist/cli/{db-S5QVPK5E.js → db-G5QGXFAX.js} +28 -28
  113. package/dist/cli/{describe-L4P5SZLQ.mjs → describe-4DOJ4DHA.mjs} +19 -19
  114. package/dist/cli/describe-SD7DRTBW.js +50 -0
  115. package/dist/cli/describe-core.d.mts +4 -4
  116. package/dist/cli/describe-core.d.ts +4 -4
  117. package/dist/cli/{executions-RR6O3XK5.mjs → executions-C7SMBHHB.mjs} +7 -7
  118. package/dist/cli/{executions-MFZ2Z36O.js → executions-IYEVUPJI.js} +9 -9
  119. package/dist/cli/{feedback-YDAG7VH2.js → feedback-GYAF46GA.js} +14 -14
  120. package/dist/cli/{feedback-EQBQ3ABB.mjs → feedback-XUU2UKM6.mjs} +6 -6
  121. package/dist/cli/git-7YYVMY6L.js +25 -0
  122. package/dist/cli/{git-YGLCCU35.mjs → git-WVCMK5AH.mjs} +5 -5
  123. package/dist/cli/index.js +146 -146
  124. package/dist/cli/index.mjs +45 -45
  125. package/dist/cli/{integrations-FWYXSBHK.mjs → integrations-FXADGAX2.mjs} +11 -9
  126. package/dist/cli/{integrations-IQXYMRMW.js → integrations-YYBJJFVX.js} +19 -17
  127. package/dist/cli/{legacy-noops-I4YRIX5F.mjs → legacy-noops-LJY7LDUE.mjs} +6 -6
  128. package/dist/cli/{legacy-noops-U7LI7UXC.js → legacy-noops-REZCYES2.js} +9 -9
  129. package/dist/cli/{mcp-GX2UKKWU.js → mcp-L5PURE5S.js} +24 -24
  130. package/dist/cli/{mcp-QJBMB6VS.mjs → mcp-XSB3ZJFR.mjs} +4 -4
  131. package/dist/cli/{monitors-WCJYINGX.js → monitors-I5EIHSGV.js} +119 -101
  132. package/dist/cli/{monitors-Z6EGKYJP.mjs → monitors-UBPF2OLO.mjs} +26 -8
  133. package/dist/cli/{org-NNHICBR2.mjs → org-PHHIN2ER.mjs} +7 -7
  134. package/dist/cli/{org-7SKG423N.js → org-SGSTGGUD.js} +89 -89
  135. package/dist/cli/{play-CXDFPJ7Z.mjs → play-LEJNJLWY.mjs} +295 -67
  136. package/dist/cli/{play-4P4DTG3Q.js → play-WQEKMANL.js} +897 -669
  137. package/dist/cli/{providers-VQLQ7DTR.mjs → providers-3W26ZDAV.mjs} +7 -7
  138. package/dist/cli/{providers-EE4TUE3O.js → providers-RSDXBXIS.js} +10 -10
  139. package/dist/cli/{quickstart-IYNJRB5G.mjs → quickstart-LGJD2M36.mjs} +4 -4
  140. package/dist/cli/{quickstart-RVXHK4WA.js → quickstart-U3QX4EMI.js} +6 -6
  141. package/dist/cli/{run-R3F34KU3.js → run-F2UPZUJS.js} +45 -45
  142. package/dist/cli/{run-VBQPPMEX.mjs → run-YWZ3W5HK.mjs} +25 -25
  143. package/dist/cli/search-K6ANAXLF.js +32 -0
  144. package/dist/cli/{search-B7R62HX5.mjs → search-O2OJH3PY.mjs} +8 -8
  145. package/dist/cli/{search-output-LNQQXIGZ.mjs → search-output-H5BF6SJ3.mjs} +4 -4
  146. package/dist/cli/{search-output-LWHWEPOT.js → search-output-W7OCBYBU.js} +6 -6
  147. package/dist/cli/{secrets-NM3VAJLO.mjs → secrets-65XCAA7U.mjs} +7 -7
  148. package/dist/cli/{secrets-QBOZ7WTD.js → secrets-BN4GYVRI.js} +16 -16
  149. package/dist/cli/sessions-M52QWLA6.js +22 -0
  150. package/dist/cli/{sessions-R5BSIJ4I.mjs → sessions-SVEVESCQ.mjs} +6 -6
  151. package/dist/cli/{settings-POYWKNRD.js → settings-7YMDAFCN.js} +86 -86
  152. package/dist/cli/{settings-S4PN7WLY.mjs → settings-HAU2NP2H.mjs} +13 -13
  153. package/dist/cli/{setup-PFLXVBTL.mjs → setup-5RXHZ6YI.mjs} +9 -9
  154. package/dist/cli/{setup-VHB4Z654.js → setup-G37QXQGM.js} +49 -49
  155. package/dist/cli/{skills-W2TELEU7.mjs → skills-Q7A3XFAU.mjs} +7 -7
  156. package/dist/cli/skills-ZK4D5BJW.js +36 -0
  157. package/dist/cli/tools-DBZTLYFM.js +57 -0
  158. package/dist/cli/{tools-M4FA6N3Y.mjs → tools-ZG4NYRGB.mjs} +18 -18
  159. package/dist/cli/{update-W7LIHEA7.mjs → update-2CMZTZCL.mjs} +9 -9
  160. package/dist/cli/update-LC5HGEEH.js +34 -0
  161. package/dist/cli/{views-KTVPV6UP.mjs → views-A6IIY4OQ.mjs} +7 -7
  162. package/dist/cli/{views-DJXAGD7V.js → views-XUMDMDIE.js} +22 -22
  163. package/dist/cli/{workflow-NVZDJKH2.js → workflow-4EEW6MCD.js} +18 -18
  164. package/dist/cli/{workflow-LGKCRODX.mjs → workflow-74MYISHU.mjs} +8 -8
  165. package/dist/{client-Tp1LSULB.d.mts → client-D1uWA2Vc.d.mts} +1 -1
  166. package/dist/{client-CCyWJqAI.d.ts → client-Hz7SsBXs.d.ts} +1 -1
  167. package/dist/{client-core-BpYiYEfu.d.ts → client-core-D3Ad7Flt.d.ts} +554 -504
  168. package/dist/{client-core-D8eCZz3O.d.mts → client-core-Db_e63Hb.d.mts} +554 -504
  169. package/dist/{compiler-manifest-EBWEUj0b.d.ts → compiler-manifest-BqwVrOri.d.mts} +38 -18
  170. package/dist/{compiler-manifest-EBWEUj0b.d.mts → compiler-manifest-BqwVrOri.d.ts} +38 -18
  171. package/dist/{errors-CParKUQR.d.mts → errors-BU8FB99X.d.mts} +1 -1
  172. package/dist/{errors-Qt0OTA7_.d.ts → errors-DfVN_FUG.d.ts} +1 -1
  173. package/dist/{index-CoqDkIw0.d.ts → index-BGnvtYGc.d.ts} +6 -1
  174. package/dist/{index-BMUVCNp7.d.mts → index-DjZgwpGw.d.mts} +6 -1
  175. package/dist/index.d.mts +28 -8
  176. package/dist/index.d.ts +28 -8
  177. package/dist/index.js +64 -39
  178. package/dist/index.mjs +32 -7
  179. package/dist/install-integrity.json +133 -128
  180. package/dist/plays/bundle-play-file.d.mts +3 -3
  181. package/dist/plays/bundle-play-file.d.ts +3 -3
  182. package/dist/plays/bundle-play-file.mjs +620 -124
  183. package/dist/plays/play-description.d.mts +3 -3
  184. package/dist/plays/play-description.d.ts +3 -3
  185. package/dist/plays/run-request.d.mts +2 -2
  186. package/dist/plays/run-request.d.ts +2 -2
  187. package/dist/release.d.mts +1 -1
  188. package/dist/release.d.ts +1 -1
  189. package/dist/release.js +2 -2
  190. package/dist/release.mjs +1 -1
  191. package/dist/server.d.mts +4 -4
  192. package/dist/server.d.ts +4 -4
  193. package/dist/server.js +6 -6
  194. package/dist/server.mjs +4 -4
  195. package/package.json +1 -1
  196. package/dist/cli/auth-W32GMYND.js +0 -43
  197. package/dist/cli/concurrent-runs-help-6QT7ZR4W.js +0 -21
  198. package/dist/cli/describe-VLU2LUDJ.js +0 -50
  199. package/dist/cli/git-E6W44F5M.js +0 -25
  200. package/dist/cli/search-UUVFXZRA.js +0 -32
  201. package/dist/cli/sessions-K3PD73Q2.js +0 -22
  202. package/dist/cli/skills-QNE2EYT3.js +0 -36
  203. package/dist/cli/tools-3RLI4HGF.js +0 -57
  204. package/dist/cli/update-UT6KIW2W.js +0 -34
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Which arm a drawn decision took, read off the graph and the order bound boxes
3
+ * report in — never off labels, values or log text.
4
+ *
5
+ * A decision box binds the statement that computes its value; the `if` that
6
+ * acts on it is ordinary code. What the runtime CAN see is which bound box the
7
+ * run reaches next. Each arm of a decision therefore owns its ENTRY set: the
8
+ * first bound boxes on a walk from the arm's target through unbound (sketched or
9
+ * conceptual) boxes. After the decision settles, the first bound box the run
10
+ * reports that the decision can reach at all names the arm:
11
+ *
12
+ * - in exactly one arm's entry set → that arm;
13
+ * - in several (two arms rejoin before any bound box), or reachable but in
14
+ * none (an entry box was never observed) → no claim;
15
+ * - not reachable from the decision → unrelated work; keep waiting.
16
+ *
17
+ * The decision itself re-entering (a loop) resolves the same way: if it is an
18
+ * arm's entry, that arm looped back; otherwise the pending choice is dropped.
19
+ *
20
+ * PURE — no runtime imports.
21
+ */
22
+ import type { PlayDocflow } from './docflow';
23
+
24
+ export type DocflowDecisionArm = {
25
+ /** The edge's label, as drawn. */
26
+ label: string;
27
+ /** The edge's target node id. */
28
+ to: string;
29
+ /** First bound boxes on this arm (see the module comment). */
30
+ entry: ReadonlySet<string>;
31
+ };
32
+
33
+ export type DocflowDecisionArmPlan = {
34
+ decisionId: string;
35
+ arms: readonly DocflowDecisionArm[];
36
+ /** Every node reachable from the decision, the decision included on a loop. */
37
+ reach: ReadonlySet<string>;
38
+ };
39
+
40
+ export type DocflowDecisionArmResolution =
41
+ | { kind: 'arm'; arm: DocflowDecisionArm }
42
+ /** The reported box says nothing about this decision. Keep waiting. */
43
+ | { kind: 'unrelated' }
44
+ /** The reported box is downstream but names no single arm. Stop waiting. */
45
+ | { kind: 'unresolvable' };
46
+
47
+ const plansByDocflow = new WeakMap<
48
+ PlayDocflow,
49
+ ReadonlyMap<string, DocflowDecisionArmPlan>
50
+ >();
51
+
52
+ /**
53
+ * One plan per bound, labelled, multi-arm-capable decision. A decision with no
54
+ * labelled outgoing edge has no arm to name and gets no plan.
55
+ */
56
+ export function docflowDecisionArmPlans(
57
+ docflow: PlayDocflow,
58
+ ): ReadonlyMap<string, DocflowDecisionArmPlan> {
59
+ const cached = plansByDocflow.get(docflow);
60
+ if (cached) return cached;
61
+ const sketched = new Set(
62
+ docflow.nodes.filter((node) => node.sketch).map((node) => node.id),
63
+ );
64
+ const bound = new Set(
65
+ docflow.bindings
66
+ .map((binding) => binding.nodeId)
67
+ .filter((nodeId) => !sketched.has(nodeId)),
68
+ );
69
+ const successors = new Map<string, string[]>();
70
+ for (const edge of docflow.edges) {
71
+ successors.set(edge.from, [...(successors.get(edge.from) ?? []), edge.to]);
72
+ }
73
+ const plans = new Map<string, DocflowDecisionArmPlan>();
74
+ for (const node of docflow.nodes) {
75
+ if (node.kind !== 'decision' || !bound.has(node.id)) continue;
76
+ const arms: DocflowDecisionArm[] = [];
77
+ for (const edge of docflow.edges) {
78
+ if (edge.from !== node.id) continue;
79
+ const label = edge.label?.trim();
80
+ if (!label) continue;
81
+ arms.push({
82
+ label,
83
+ to: edge.to,
84
+ entry: entryBoxes(edge.to, bound, successors),
85
+ });
86
+ }
87
+ if (arms.length === 0) continue;
88
+ plans.set(node.id, {
89
+ decisionId: node.id,
90
+ arms,
91
+ reach: reachableFrom(node.id, successors),
92
+ });
93
+ }
94
+ plansByDocflow.set(docflow, plans);
95
+ return plans;
96
+ }
97
+
98
+ function entryBoxes(
99
+ start: string,
100
+ bound: ReadonlySet<string>,
101
+ successors: ReadonlyMap<string, readonly string[]>,
102
+ ): Set<string> {
103
+ const entry = new Set<string>();
104
+ const seen = new Set<string>();
105
+ const queue = [start];
106
+ for (let head = 0; head < queue.length; head += 1) {
107
+ const current = queue[head]!;
108
+ if (seen.has(current)) continue;
109
+ seen.add(current);
110
+ if (bound.has(current)) {
111
+ entry.add(current);
112
+ continue;
113
+ }
114
+ queue.push(...(successors.get(current) ?? []));
115
+ }
116
+ return entry;
117
+ }
118
+
119
+ function reachableFrom(
120
+ start: string,
121
+ successors: ReadonlyMap<string, readonly string[]>,
122
+ ): Set<string> {
123
+ const reach = new Set<string>();
124
+ const queue = [...(successors.get(start) ?? [])];
125
+ for (let head = 0; head < queue.length; head += 1) {
126
+ const current = queue[head]!;
127
+ if (reach.has(current)) continue;
128
+ reach.add(current);
129
+ queue.push(...(successors.get(current) ?? []));
130
+ }
131
+ return reach;
132
+ }
133
+
134
+ /** What the box `reportedNodeId`, reported after the decision settled, says. */
135
+ export function resolveDocflowDecisionArm(
136
+ plan: DocflowDecisionArmPlan,
137
+ reportedNodeId: string,
138
+ ): DocflowDecisionArmResolution {
139
+ const matches = plan.arms.filter((arm) => arm.entry.has(reportedNodeId));
140
+ if (matches.length === 1) return { kind: 'arm', arm: matches[0]! };
141
+ if (matches.length > 1) return { kind: 'unresolvable' };
142
+ if (reportedNodeId === plan.decisionId || plan.reach.has(reportedNodeId)) {
143
+ return { kind: 'unresolvable' };
144
+ }
145
+ return { kind: 'unrelated' };
146
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The parts of a diagram the order reads: box ids, edges and subgraph
3
+ * membership. Structural, so a check report's slimmer diagram (the CLI's) fits
4
+ * as well as a parsed `PlayDocflow`.
5
+ */
6
+ export type DocflowFlowShape = {
7
+ nodes: ReadonlyArray<{ id: string }>;
8
+ edges: ReadonlyArray<{ from: string; to: string }>;
9
+ subgraphs?: ReadonlyArray<{
10
+ id: string;
11
+ memberIds: readonly string[];
12
+ parentId?: string;
13
+ }>;
14
+ };
15
+
16
+ /**
17
+ * Every box and subgraph of a diagram in the order a reader follows it: each
18
+ * after every box that leads into it (longest-path layering over the drawn
19
+ * edges), a subgraph just before its first member, authored order breaking
20
+ * ties. Boxes on a cycle keep authored order after the rest. Unlike the run
21
+ * steps, sketches are included: a diagram review is about every drawn box.
22
+ *
23
+ * PURE and type-only against the parser, so the CLI can order a check's
24
+ * diagram issues without loading it.
25
+ */
26
+ export function docflowFlowOrder(docflow: DocflowFlowShape): string[] {
27
+ const subgraphs = docflow.subgraphs ?? [];
28
+ const regionOf = new Map<string, string>();
29
+ for (const region of subgraphs) {
30
+ for (const memberId of region.memberIds) regionOf.set(memberId, region.id);
31
+ if (region.parentId) regionOf.set(region.id, region.parentId);
32
+ }
33
+ const endpoints = [
34
+ ...docflow.nodes.map((node) => node.id),
35
+ ...subgraphs.map((region) => region.id),
36
+ ];
37
+ const known = new Set(endpoints);
38
+ const next = new Map<string, string[]>();
39
+ const indegree = new Map(endpoints.map((id) => [id, 0]));
40
+ for (const edge of docflow.edges) {
41
+ if (!known.has(edge.from) || !known.has(edge.to)) continue;
42
+ next.set(edge.from, [...(next.get(edge.from) ?? []), edge.to]);
43
+ indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);
44
+ }
45
+ const layer = new Map<string, number>();
46
+ const queue = endpoints.filter((id) => indegree.get(id) === 0);
47
+ for (const id of queue) layer.set(id, 0);
48
+ for (let head = 0; head < queue.length; head += 1) {
49
+ const current = queue[head]!;
50
+ for (const target of next.get(current) ?? []) {
51
+ layer.set(
52
+ target,
53
+ Math.max(layer.get(target) ?? 0, (layer.get(current) ?? 0) + 1),
54
+ );
55
+ const remaining = (indegree.get(target) ?? 0) - 1;
56
+ indegree.set(target, remaining);
57
+ if (remaining === 0) queue.push(target);
58
+ }
59
+ }
60
+ const onCycle = Math.max(0, ...layer.values()) + 1;
61
+ const depthOf = (id: string): number => {
62
+ const own = indegree.get(id) === 0 ? (layer.get(id) ?? 0) : onCycle;
63
+ const region = regionOf.get(id);
64
+ return Math.max(own, region ? depthOf(region) : 0);
65
+ };
66
+ const ordered = docflow.nodes
67
+ .map((node, index) => ({ id: node.id, index }))
68
+ .sort(
69
+ (left, right) =>
70
+ depthOf(left.id) - depthOf(right.id) || left.index - right.index,
71
+ )
72
+ .map(({ id }) => id);
73
+ // A subgraph is read where its first member falls, its members together.
74
+ const result: string[] = [];
75
+ const placed = new Set<string>();
76
+ const place = (id: string) => {
77
+ if (placed.has(id)) return;
78
+ const region = regionOf.get(id);
79
+ if (region && !placed.has(region)) {
80
+ place(region);
81
+ return;
82
+ }
83
+ placed.add(id);
84
+ result.push(id);
85
+ if (known.has(id) && subgraphs.some((candidate) => candidate.id === id)) {
86
+ for (const member of ordered) if (regionOf.get(member) === id) place(member);
87
+ for (const child of subgraphs)
88
+ if (regionOf.get(child.id) === id) place(child.id);
89
+ }
90
+ };
91
+ for (const id of ordered) place(id);
92
+ for (const region of subgraphs) place(region.id);
93
+ return result;
94
+ }
@@ -25,6 +25,8 @@ export type DocflowReasonNodeState = {
25
25
  error?: string | null;
26
26
  nodeIo?: {
27
27
  outputs?: Record<string, { kind: string; value?: unknown }>;
28
+ /** The arm the runtime recorded this decision taking, when it did. */
29
+ decision?: { arm: string; to: string } | null;
28
30
  } | null;
29
31
  };
30
32
 
@@ -338,7 +340,14 @@ export function deriveDocflowUnreachedReason(input: {
338
340
  if (!node || node.kind !== 'decision') continue;
339
341
  const outgoing = graph.successors.get(reachedId) ?? [];
340
342
  if (outgoing.length < 2) continue;
341
- const taken = outgoing.find((edge) => graph.reached.has(edge.to));
343
+ // The recorded arm is the fact; which arm target carries state is only an
344
+ // inference, and a wrong one when arms rejoin at a shared box.
345
+ const recorded = stateFor(nodeStates, reachedId)?.nodeIo?.decision;
346
+ const taken = recorded
347
+ ? outgoing.find(
348
+ (edge) => edge.to === recorded.to && edge.label?.trim() === recorded.arm,
349
+ )
350
+ : outgoing.find((edge) => graph.reached.has(edge.to));
342
351
  const skipped = outgoing.find((edge) => edge.to === skippedId);
343
352
  if (!taken || !skipped || taken.to === skippedId) continue;
344
353
  const takenTarget = reasonNode(graph, docflow, taken.to);