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
@@ -141,6 +141,14 @@ export type PlayDocflowBinding = {
141
141
  * {@link attachBindingsToBlocks}; the edge is what readers resolve against.
142
142
  */
143
143
  arm?: PlayDocflowArm;
144
+ /**
145
+ * `show:"ownerName,territory"` — the fields of this node's value a reader
146
+ * should see first, as paths into it. Plays can return anything, so which
147
+ * fields matter is the author's to say; without it, displays fall back to a
148
+ * neutral peek and never guess. Absent (never empty) when undeclared, so a
149
+ * diagram that declares none hashes byte for byte as before.
150
+ */
151
+ show?: string[];
144
152
  };
145
153
 
146
154
  export type PlayDocflow = {
@@ -159,11 +167,29 @@ export type PlayDocflow = {
159
167
  subgraphs?: PlayDocflowSubgraph[];
160
168
  /** Mermaid directives accepted by the parser but not applied by React Flow. */
161
169
  ignoredDirectives?: string[];
170
+ /**
171
+ * `%% @input show:"leadId,company.name"` in the block: the fields of the
172
+ * run's input a reader sees first (the Start card, each run's input pill).
173
+ * Absent when undeclared, so an existing diagram hashes as before.
174
+ */
175
+ inputShow?: string[];
162
176
  };
163
177
 
164
178
  export type PlayDocflowParseResult = {
179
+ /**
180
+ * The diagram, minus whatever did not resolve. Diagram problems never block
181
+ * a play (they only affect display), so a binding that names no box, or a
182
+ * second arm claiming the same side, is dropped and the rest still draws.
183
+ * Null when there is no block for the export, or its block did not parse.
184
+ */
165
185
  docflow: PlayDocflow | null;
186
+ /** Every diagram problem in the file. Advisory: report, never refuse. */
166
187
  errors: string[];
188
+ /**
189
+ * Why this export's diagram could not be read at all, when its block failed
190
+ * to parse. The play then runs as if it had no diagram.
191
+ */
192
+ unreadReason?: string;
167
193
  };
168
194
 
169
195
  export type ParsePlayDocflowOptions = {
@@ -198,16 +224,26 @@ export type PlayDocflowFileParseResult = {
198
224
  */
199
225
  bindings: PlayDocflowBinding[];
200
226
  errors: string[];
227
+ /**
228
+ * Blocks dropped because they did not parse, with the first reason. The
229
+ * export is the authored header (`null` for an unnamed block).
230
+ */
231
+ unreadBlocks: Array<{ authoredExportName: string | null; reason: string }>;
201
232
  };
202
233
 
203
234
  export type PlayDocflowLintIssue = {
204
235
  code:
205
236
  | 'docflow_branch_labels_required'
206
237
  | 'docflow_branch_requires_decision'
238
+ | 'docflow_decision_arms_incomplete'
239
+ | 'docflow_decision_outside_region'
240
+ | 'docflow_region_exits_unlabeled'
241
+ | 'docflow_show_undeclared'
207
242
  | 'docflow_direction_not_top_down'
208
243
  | 'docflow_layout_complexity'
209
244
  | 'docflow_topology_invalid'
210
- | 'docflow_io_ambiguous'
245
+ | 'docflow_io_missing'
246
+ | 'docflow_box_is_sketch'
211
247
  | 'docflow_input_not_found'
212
248
  | 'docflow_output_not_found'
213
249
  | 'docflow_label_counts_rows'
@@ -216,6 +252,12 @@ export type PlayDocflowLintIssue = {
216
252
  message: string;
217
253
  path?: string;
218
254
  hint?: string;
255
+ /** The diagram box (or subgraph) the issue is about, when it is about one. */
256
+ node?: string;
257
+ /** The entry file's line to edit: the box's annotation, or its diagram line. */
258
+ line?: number;
259
+ /** One line to paste, tailored to this box: an annotation, edge or move. */
260
+ fix?: string;
219
261
  };
220
262
 
221
263
  export class PlayDocflowCompileError extends Error {
@@ -228,8 +270,14 @@ export class PlayDocflowCompileError extends Error {
228
270
  }
229
271
  }
230
272
 
273
+ // Boxes one view of the canvas shows: the top level with every region folded
274
+ // (the default), or one opened region's direct members. A region counts as one
275
+ // box at the level that holds it, so a Play with several phases stays readable.
231
276
  const DOCFLOW_MAX_NODES = 12;
232
- const DOCFLOW_MAX_BRANCHES = 3;
277
+ // Outcomes one decision draws. A decision legitimately has N outcomes (six
278
+ // territory reps are six arms), and the canvas lays them out side by side, so
279
+ // this is a readability warning, never a publish-blocking error.
280
+ const DOCFLOW_MAX_BRANCHES = 8;
233
281
  const DOCFLOW_MAX_LABEL_LENGTH = 48;
234
282
 
235
283
  // A node label names the thing; the runtime counts it. A label that bakes a
@@ -262,7 +310,14 @@ const MERMAID_NODE = /^\s*\/\/\s*@mermaid-node\s+([A-Za-z][\w-]*)(?:\s+(.*))?$/;
262
310
  /** Whole-file pre-filter for {@link MERMAID_NODE}; skips splitting clean files. */
263
311
  const MERMAID_NODE_HINT = /@mermaid-node/;
264
312
  const ATTRIBUTE = /([A-Za-z][\w-]*)\s*:\s*"([^"\n]*)"/y;
265
- const MERMAID_NODE_ATTRIBUTES = ['label', 'type', 'in', 'out', 'arm'] as const;
313
+ const MERMAID_NODE_ATTRIBUTES = [
314
+ 'label',
315
+ 'type',
316
+ 'in',
317
+ 'out',
318
+ 'arm',
319
+ 'show',
320
+ ] as const;
266
321
  const MERMAID_NODE_ID = /^[A-Za-z][\w-]*/;
267
322
  /**
268
323
  * `class a,b,c sketch` — the author declaring that no statement runs these boxes.
@@ -549,7 +604,7 @@ function parseEdgeChain(
549
604
 
550
605
  function parseContractPaths(
551
606
  value: string | undefined,
552
- attribute: 'in' | 'out',
607
+ attribute: 'in' | 'out' | 'show',
553
608
  nodeId: string,
554
609
  line: number,
555
610
  errors: string[],
@@ -627,6 +682,150 @@ function rootPath(path: string): string {
627
682
  return path.split('.')[0]!;
628
683
  }
629
684
 
685
+ const escapeRegExp = (text: string) =>
686
+ text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
687
+
688
+ /**
689
+ * Where a box lives in the entry file, so a lint issue can name the line to
690
+ * edit: its `// @mermaid-node` annotation, or the diagram line that declares it
691
+ * (`id[…]`, `id{…}`, `subgraph id`). Undefined without source, or when the box
692
+ * is not written in the entry file.
693
+ */
694
+ function docflowSourceLocator(sourceCode: string | undefined) {
695
+ const lines = sourceCode?.split(/\r?\n/) ?? [];
696
+ const diagramLines: number[] = [];
697
+ let inside = false;
698
+ lines.forEach((text, index) => {
699
+ if (!inside && /\/\*\*\s*@mermaid\b/.test(text)) inside = true;
700
+ if (inside) diagramLines.push(index);
701
+ if (inside && text.includes('*/')) inside = false;
702
+ });
703
+ const first = (indexes: Iterable<number>, pattern: RegExp) => {
704
+ for (const index of indexes) {
705
+ if (pattern.test(lines[index]!)) return index + 1;
706
+ }
707
+ return undefined;
708
+ };
709
+ return {
710
+ annotation(id: string): number | undefined {
711
+ return first(
712
+ lines.keys(),
713
+ new RegExp(`//\\s*@mermaid-node\\s+${escapeRegExp(id)}(?![\\w-])`),
714
+ );
715
+ },
716
+ diagram(id: string): number | undefined {
717
+ const name = `(?<![\\w-])${escapeRegExp(id)}(?![\\w-])`;
718
+ return (
719
+ first(diagramLines, new RegExp(`${name}\\s*[[({>]`)) ??
720
+ first(diagramLines, new RegExp(`\\bsubgraph\\s+${name}`)) ??
721
+ first(
722
+ diagramLines.filter(
723
+ (index) => !/^\s*\*?\s*(?:class\s|%%)/.test(lines[index]!),
724
+ ),
725
+ new RegExp(name),
726
+ )
727
+ );
728
+ },
729
+ };
730
+ }
731
+
732
+ /**
733
+ * The `// @mermaid-node` line this binding should read, with `changes`
734
+ * applied: what a fix tells the author to paste. Attributes keep the order the
735
+ * syntax help teaches.
736
+ */
737
+ function docflowAnnotationFix(
738
+ binding: Pick<
739
+ PlayDocflowBinding,
740
+ 'nodeId' | 'kind' | 'inputs' | 'outputs' | 'arm' | 'show' | 'label'
741
+ >,
742
+ changes: { in?: string; out?: string; show?: string } = {},
743
+ ): string {
744
+ const join = (paths: string[] | undefined) =>
745
+ paths?.length ? paths.join(',') : undefined;
746
+ const attributes: Array<[string, string | undefined]> = [
747
+ ['type', binding.kind && binding.kind !== 'action' ? binding.kind : undefined],
748
+ ['in', changes.in ?? join(binding.inputs)],
749
+ ['out', changes.out ?? join(binding.outputs)],
750
+ ['arm', binding.arm],
751
+ ['show', changes.show ?? join(binding.show)],
752
+ ['label', binding.label],
753
+ ];
754
+ return [
755
+ `// @mermaid-node ${binding.nodeId}`,
756
+ ...attributes
757
+ .filter(([, value]) => value !== undefined)
758
+ .map(([name, value]) => `${name}:"${value}"`),
759
+ ].join(' ');
760
+ }
761
+
762
+ /**
763
+ * The top-level field names of the object literal a bound statement builds
764
+ * (`const x = { a, b: 1, ...rest }` → `['a', 'b']`, spread `true`), read from
765
+ * the statement's first `{` on `lines[startLine]` onward. Null when the text is
766
+ * not a closed literal within a bounded scan; the caller then knows nothing.
767
+ */
768
+ function objectLiteralFields(
769
+ lines: readonly string[],
770
+ startLine: number,
771
+ ): { fields: string[]; spread: boolean } | null {
772
+ const text = lines.slice(startLine, startLine + 200).join('\n');
773
+ const open = text.indexOf('{');
774
+ if (open < 0) return null;
775
+ const fields: string[] = [];
776
+ let spread = false;
777
+ let depth = 0;
778
+ let quote: string | null = null;
779
+ // At depth 1, the start of each property (after `{` or a top-level `,`).
780
+ let atProperty = false;
781
+ for (let index = open; index < text.length && index < open + 8_000; index++) {
782
+ const char = text[index]!;
783
+ if (quote) {
784
+ if (char === '\\') index += 1;
785
+ else if (char === quote) quote = null;
786
+ continue;
787
+ }
788
+ if (char === '/' && (text[index + 1] === '/' || text[index + 1] === '*')) {
789
+ const end =
790
+ text[index + 1] === '/'
791
+ ? text.indexOf('\n', index)
792
+ : text.indexOf('*/', index + 2) + 1;
793
+ if (end <= 0) return null;
794
+ index = end;
795
+ continue;
796
+ }
797
+ if (char === '"' || char === "'" || char === '`') {
798
+ quote = char;
799
+ atProperty = false;
800
+ continue;
801
+ }
802
+ if (char === '{' || char === '[' || char === '(') {
803
+ depth += 1;
804
+ atProperty = depth === 1;
805
+ continue;
806
+ }
807
+ if (char === '}' || char === ']' || char === ')') {
808
+ depth -= 1;
809
+ if (depth === 0) return { fields, spread };
810
+ continue;
811
+ }
812
+ if (depth !== 1) continue;
813
+ if (char === ',') {
814
+ atProperty = true;
815
+ continue;
816
+ }
817
+ if (!atProperty || /\s/.test(char)) continue;
818
+ atProperty = false;
819
+ if (text.startsWith('...', index)) {
820
+ spread = true;
821
+ continue;
822
+ }
823
+ const name = /^[A-Za-z_$][\w$]*/.exec(text.slice(index))?.[0];
824
+ if (name) fields.push(name);
825
+ }
826
+ return null;
827
+ }
828
+
630
829
  function levenshtein(left: string, right: string): number {
631
830
  const row = Array.from({ length: right.length + 1 }, (_, index) => index);
632
831
  for (let leftIndex = 1; leftIndex <= left.length; leftIndex += 1) {
@@ -714,6 +913,8 @@ type ParsedDocflowBlock = ParsedDocflowBlockGraph & {
714
913
  syntax: NonNullable<PlayDocflow['syntax']>;
715
914
  mermaidSource: string;
716
915
  bindings: PlayDocflowBinding[];
916
+ /** The block's `%% @input show:"…"` fields, when declared. */
917
+ inputShow?: string[];
717
918
  };
718
919
 
719
920
  /** How a block is named in a diagnostic. */
@@ -728,9 +929,60 @@ function blockLabel(block: { authoredExportName: string | null }): string {
728
929
  * null when the block does not open with a direction, which is the one error
729
930
  * that makes the rest of the block unreadable.
730
931
  */
932
+ /**
933
+ * Where each diagram line sits in the play file, so a syntax error names the
934
+ * line the author has to fix rather than leaving them to find it. The diagram
935
+ * lines are the block's own lines in order (blank and `%%` lines dropped), so a
936
+ * forward scan over the block's raw lines, gutter stripped, finds each one.
937
+ */
938
+ type DocflowLineLocator = (diagramLine: string) => number | null;
939
+
940
+ function docflowBlockLineLocator(
941
+ sourceCode: string,
942
+ blockStart: number,
943
+ blockText: string,
944
+ ): DocflowLineLocator {
945
+ const firstLine = sourceCode.slice(0, blockStart).split(/\r?\n/).length;
946
+ const rawLines = blockText.split(/\r?\n/).map((line) =>
947
+ line
948
+ .replace(/^\s*\/\*\*/, '')
949
+ .replace(/\*\/\s*$/, '')
950
+ .replace(/^\s*\* ?/, '')
951
+ .trim(),
952
+ );
953
+ let cursor = 0;
954
+ return (diagramLine) => {
955
+ const wanted = diagramLine.trim();
956
+ if (!wanted) return null;
957
+ for (let index = cursor; index < rawLines.length; index += 1) {
958
+ // The header line `@mermaid flowchart TD` carries the diagram's first
959
+ // line after its tag.
960
+ const raw = rawLines[index]!.replace(/^@mermaid\b\s*/, '');
961
+ if (raw === wanted || raw.endsWith(` ${wanted}`)) {
962
+ cursor = index + 1;
963
+ return firstLine + index;
964
+ }
965
+ }
966
+ return null;
967
+ };
968
+ }
969
+
970
+ /** Suffixes the errors pushed since `from` with the file line they are about. */
971
+ function locateDocflowErrors(
972
+ errors: string[],
973
+ from: number,
974
+ line: number | null,
975
+ ): void {
976
+ if (line === null) return;
977
+ for (let index = from; index < errors.length; index += 1) {
978
+ errors[index] = `${errors[index]} (line ${line})`;
979
+ }
980
+ }
981
+
731
982
  function parseDocflowBlockGraph(
732
983
  mermaidSource: string,
733
984
  errors: string[],
985
+ locate: DocflowLineLocator = () => null,
734
986
  ): ParsedDocflowBlockGraph | null {
735
987
  const docLines = mermaidSource
736
988
  .split(/\r?\n/)
@@ -739,11 +991,21 @@ function parseDocflowBlockGraph(
739
991
  | PlayDocflow['direction']
740
992
  | undefined;
741
993
  if (!direction) {
994
+ const firstErrorAt = errors.length;
742
995
  errors.push(
743
- 'Docflow must start with `flowchart` or `graph` and direction `LR`, `RL`, `TB`, `TD`, or `BT`.',
996
+ docLines[0]
997
+ ? `Docflow must start with \`flowchart\` or \`graph\` and direction \`LR\`, \`RL\`, \`TB\`, \`TD\`, or \`BT\`; found: ${docLines[0].trim()}`
998
+ : 'Docflow must start with `flowchart` or `graph` and direction `LR`, `RL`, `TB`, `TD`, or `BT`.',
999
+ );
1000
+ locateDocflowErrors(
1001
+ errors,
1002
+ firstErrorAt,
1003
+ docLines[0] ? locate(docLines[0]) : null,
744
1004
  );
745
1005
  return null;
746
1006
  }
1007
+ // Consumes the header line, so the scan for the body starts after it.
1008
+ locate(docLines[0]!);
747
1009
 
748
1010
  const nodes = new Map<string, PlayDocflowNode>();
749
1011
  const edges: PlayDocflowEdge[] = [];
@@ -823,91 +1085,101 @@ function parseDocflowBlockGraph(
823
1085
  }
824
1086
  return sawDeclaration;
825
1087
  };
1088
+ /** File line each still-open subgraph was opened on. */
1089
+ const openedAt = new Map<PlayDocflowSubgraph, number | null>();
826
1090
  for (const line of docLines.slice(1)) {
827
- const opened = SUBGRAPH_OPEN.exec(line);
828
- if (opened) {
829
- const id = opened[1]!;
830
- const rawLabel = opened[2]?.trim() ?? '';
831
- const label =
832
- rawLabel.length >= 2 &&
833
- ((rawLabel.startsWith('"') && rawLabel.endsWith('"')) ||
834
- (rawLabel.startsWith("'") && rawLabel.endsWith("'")))
835
- ? rawLabel.slice(1, -1)
836
- : rawLabel;
837
- const parent = subgraphStack[subgraphStack.length - 1];
838
- const subgraph: PlayDocflowSubgraph = {
839
- id,
840
- label: label || id,
841
- memberIds: [],
842
- ...(parent ? { parentId: parent.id } : {}),
843
- };
844
- subgraphs.set(id, subgraph);
845
- subgraphStack.push(subgraph);
846
- continue;
847
- }
848
- if (SUBGRAPH_END.test(line)) {
849
- if (subgraphStack.length === 0) {
850
- errors.push(
851
- 'Docflow has an `end` with no open `subgraph` above it. Every `end` closes exactly one `subgraph`.',
852
- );
1091
+ const lineErrorsFrom = errors.length;
1092
+ const fileLine = locate(line);
1093
+ try {
1094
+ const opened = SUBGRAPH_OPEN.exec(line);
1095
+ if (opened) {
1096
+ const id = opened[1]!;
1097
+ const rawLabel = opened[2]?.trim() ?? '';
1098
+ const label =
1099
+ rawLabel.length >= 2 &&
1100
+ ((rawLabel.startsWith('"') && rawLabel.endsWith('"')) ||
1101
+ (rawLabel.startsWith("'") && rawLabel.endsWith("'")))
1102
+ ? rawLabel.slice(1, -1)
1103
+ : rawLabel;
1104
+ const parent = subgraphStack[subgraphStack.length - 1];
1105
+ const subgraph: PlayDocflowSubgraph = {
1106
+ id,
1107
+ label: label || id,
1108
+ memberIds: [],
1109
+ ...(parent ? { parentId: parent.id } : {}),
1110
+ };
1111
+ subgraphs.set(id, subgraph);
1112
+ subgraphStack.push(subgraph);
1113
+ openedAt.set(subgraph, fileLine);
1114
+ continue;
853
1115
  }
854
- subgraphStack.pop();
855
- continue;
856
- }
857
- let declaredOnThisLine = false;
858
- const isDirective =
859
- /^\s*(?:direction|classDef|class|style|linkStyle|click)\b/i.test(line);
860
- if (isDirective) {
861
- const sketch = SKETCH_CLASS.exec(line);
862
- if (sketch) {
863
- for (const id of sketch[1]!.split(',')) {
864
- const trimmed = id.trim();
865
- if (trimmed) sketchIds.add(trimmed);
1116
+ if (SUBGRAPH_END.test(line)) {
1117
+ if (subgraphStack.length === 0) {
1118
+ errors.push(
1119
+ 'Docflow has an `end` with no open `subgraph` above it. Every `end` closes exactly one `subgraph`.',
1120
+ );
866
1121
  }
867
- } else {
868
- ignoredDirectives.push(line.trim());
1122
+ subgraphStack.pop();
1123
+ continue;
869
1124
  }
870
- }
871
- if (!isDirective) {
872
- declaredOnThisLine = addNodes(line, line);
873
- }
874
- const chain = parseEdgeChain(line);
875
- if (!chain) {
876
- if (!isDirective && !declaredOnThisLine) {
877
- // Mermaid the parser could not consume at all: no edge, no node
878
- // declaration, not a directive it knowingly ignores. It used to be
879
- // skipped in silence, so a typo'd arrow or a stray token simply removed
880
- // part of the diagram and nothing said so.
881
- errors.push(
882
- `Docflow line is not an edge, a node declaration, or a directive this parser understands: ${line.trim()}`,
883
- );
1125
+ let declaredOnThisLine = false;
1126
+ const isDirective =
1127
+ /^\s*(?:direction|classDef|class|style|linkStyle|click)\b/i.test(line);
1128
+ if (isDirective) {
1129
+ const sketch = SKETCH_CLASS.exec(line);
1130
+ if (sketch) {
1131
+ for (const id of sketch[1]!.split(',')) {
1132
+ const trimmed = id.trim();
1133
+ if (trimmed) sketchIds.add(trimmed);
1134
+ }
1135
+ } else {
1136
+ ignoredDirectives.push(line.trim());
1137
+ }
884
1138
  }
885
- continue;
886
- }
887
- addNodes(line, line);
888
- for (const node of chain.nodes) {
889
- // An edge endpoint may name a subgraph id; keep the edge but do not
890
- // materialize a regular node for the region.
891
- if (subgraphIds.has(node.id)) continue;
892
- const existing = nodes.get(node.id);
893
- if (!existing) {
894
- nodes.set(node.id, node);
895
- subgraphStack[subgraphStack.length - 1]?.memberIds.push(node.id);
896
- } else if (existing.label === existing.id && node.label !== node.id) {
897
- existing.label = node.label;
898
- existing.kind = node.kind;
1139
+ if (!isDirective) {
1140
+ declaredOnThisLine = addNodes(line, line);
899
1141
  }
900
- }
901
- for (let index = 0; index < chain.nodes.length - 1; index += 1) {
902
- edges.push({
903
- from: chain.nodes[index]!.id,
904
- to: chain.nodes[index + 1]!.id,
905
- ...(chain.labels[index] ? { label: chain.labels[index] } : {}),
906
- });
1142
+ const chain = parseEdgeChain(line);
1143
+ if (!chain) {
1144
+ if (!isDirective && !declaredOnThisLine) {
1145
+ // Mermaid the parser could not consume at all: no edge, no node
1146
+ // declaration, not a directive it knowingly ignores. It used to be
1147
+ // skipped in silence, so a typo'd arrow or a stray token simply removed
1148
+ // part of the diagram and nothing said so.
1149
+ errors.push(
1150
+ `Docflow line is not an edge, a node declaration, or a directive this parser understands: ${line.trim()}`,
1151
+ );
1152
+ }
1153
+ continue;
1154
+ }
1155
+ addNodes(line, line);
1156
+ for (const node of chain.nodes) {
1157
+ // An edge endpoint may name a subgraph id; keep the edge but do not
1158
+ // materialize a regular node for the region.
1159
+ if (subgraphIds.has(node.id)) continue;
1160
+ const existing = nodes.get(node.id);
1161
+ if (!existing) {
1162
+ nodes.set(node.id, node);
1163
+ subgraphStack[subgraphStack.length - 1]?.memberIds.push(node.id);
1164
+ } else if (existing.label === existing.id && node.label !== node.id) {
1165
+ existing.label = node.label;
1166
+ existing.kind = node.kind;
1167
+ }
1168
+ }
1169
+ for (let index = 0; index < chain.nodes.length - 1; index += 1) {
1170
+ edges.push({
1171
+ from: chain.nodes[index]!.id,
1172
+ to: chain.nodes[index + 1]!.id,
1173
+ ...(chain.labels[index] ? { label: chain.labels[index] } : {}),
1174
+ });
1175
+ }
1176
+ } finally {
1177
+ locateDocflowErrors(errors, lineErrorsFrom, fileLine);
907
1178
  }
908
1179
  }
909
1180
 
910
1181
  if (subgraphStack.length > 0) {
1182
+ const unclosedFrom = errors.length;
911
1183
  errors.push(
912
1184
  `Docflow subgraph${subgraphStack.length === 1 ? '' : 's'} ${subgraphStack
913
1185
  .map((subgraph) => `"${subgraph.id}"`)
@@ -915,6 +1187,11 @@ function parseDocflowBlockGraph(
915
1187
  ', ',
916
1188
  )} ${subgraphStack.length === 1 ? 'is' : 'are'} never closed with \`end\`. Everything below an unclosed subgraph is silently drawn inside it.`,
917
1189
  );
1190
+ locateDocflowErrors(
1191
+ errors,
1192
+ unclosedFrom,
1193
+ openedAt.get(subgraphStack[0]!) ?? null,
1194
+ );
918
1195
  }
919
1196
 
920
1197
  // An id that only ever appeared as an edge endpoint has no label of its own,
@@ -957,9 +1234,42 @@ function materializeDocflow(block: ParsedDocflowBlock): PlayDocflow {
957
1234
  ...(block.ignoredDirectives.length
958
1235
  ? { ignoredDirectives: block.ignoredDirectives }
959
1236
  : {}),
1237
+ ...(block.inputShow?.length ? { inputShow: block.inputShow } : {}),
960
1238
  };
961
1239
  }
962
1240
 
1241
+ /** `%% @input show:"a,b.c"`: the run input's declared fields, in a block. */
1242
+ const MERMAID_INPUT_SHOW = /^\s*%%\s*@input\b(.*)$/;
1243
+
1244
+ /**
1245
+ * Reads a block's `%% @input show:"…"` line. A Mermaid `%%` comment, so the
1246
+ * diagram still renders anywhere Mermaid does; one per block, `show` only.
1247
+ */
1248
+ function parseBlockInputShow(
1249
+ diagram: string,
1250
+ errors: string[],
1251
+ ): string[] | undefined {
1252
+ const declarations = diagram
1253
+ .split(/\r?\n/)
1254
+ .map((line) => MERMAID_INPUT_SHOW.exec(line)?.[1])
1255
+ .filter((rest): rest is string => rest !== undefined);
1256
+ if (declarations.length === 0) return undefined;
1257
+ if (declarations.length > 1) {
1258
+ errors.push(
1259
+ "Docflow `%% @input` appears more than once in one diagram. Declare the input's fields once.",
1260
+ );
1261
+ return undefined;
1262
+ }
1263
+ const match = /^\s+show:"([^"]*)"\s*$/.exec(declarations[0]!);
1264
+ if (!match) {
1265
+ errors.push(
1266
+ 'Docflow `%% @input` takes one attribute: show:"field,nested.field", the run input fields a reader sees first.',
1267
+ );
1268
+ return undefined;
1269
+ }
1270
+ return parseContractPaths(match[1], 'show', '@input', 0, errors);
1271
+ }
1272
+
963
1273
  /**
964
1274
  * Parses EVERY `@mermaid` block in a file and binds each to the export it
965
1275
  * describes. One file can carry one play or several; a block names its export
@@ -974,15 +1284,21 @@ export function parsePlayDocflowFile(
974
1284
  const rawBlocks: Array<{
975
1285
  syntax: NonNullable<PlayDocflow['syntax']>;
976
1286
  body: string;
1287
+ locate: DocflowLineLocator;
977
1288
  }> = [];
978
1289
  JSDOC_BLOCK.lastIndex = 0;
979
1290
  for (const match of sourceCode.matchAll(JSDOC_BLOCK)) {
980
1291
  const cleanedBody = cleanBlockBody(match[1]!);
981
1292
  const mermaid = /^@mermaid(?:[ \t]+|\r?\n|$)([\s\S]*)$/.exec(cleanedBody);
982
1293
  if (!mermaid) continue;
983
- rawBlocks.push({ syntax: 'mermaid', body: mermaid[1]!.trim() });
1294
+ rawBlocks.push({
1295
+ syntax: 'mermaid',
1296
+ body: mermaid[1]!.trim(),
1297
+ locate: docflowBlockLineLocator(sourceCode, match.index!, match[0]),
1298
+ });
984
1299
  }
985
- if (rawBlocks.length === 0) return { blocks: [], bindings: [], errors };
1300
+ if (rawBlocks.length === 0)
1301
+ return { blocks: [], bindings: [], errors, unreadBlocks: [] };
986
1302
 
987
1303
  // Ids whose annotation was written but refused. They are NOT unbound boxes:
988
1304
  // the author already has one actionable error about them, and telling them to
@@ -1003,12 +1319,24 @@ export function parsePlayDocflowFile(
1003
1319
  );
1004
1320
 
1005
1321
  const parsedBlocks: ParsedDocflowBlock[] = [];
1322
+ const unreadBlocks: PlayDocflowFileParseResult['unreadBlocks'] = [];
1006
1323
  for (const raw of rawBlocks) {
1007
1324
  const { exportName, diagram } = splitBlockExportHeader(raw.body);
1008
- const graph = parseDocflowBlockGraph(diagram, errors);
1009
- if (!graph) continue;
1325
+ const blockErrorsFrom = errors.length;
1326
+ const graph = parseDocflowBlockGraph(diagram, errors, raw.locate);
1327
+ const inputShow = graph ? parseBlockInputShow(diagram, errors) : undefined;
1328
+ // A block that did not parse cleanly is not drawn at all: the play runs
1329
+ // as if it had no diagram, and the reason is reported, never enforced.
1330
+ if (!graph || errors.length > blockErrorsFrom) {
1331
+ unreadBlocks.push({
1332
+ authoredExportName: exportName,
1333
+ reason: errors[blockErrorsFrom] ?? 'the diagram did not parse',
1334
+ });
1335
+ continue;
1336
+ }
1010
1337
  parsedBlocks.push({
1011
1338
  ...graph,
1339
+ ...(inputShow?.length ? { inputShow } : {}),
1012
1340
  authoredExportName: exportName,
1013
1341
  exportName: null,
1014
1342
  syntax: raw.syntax,
@@ -1024,6 +1352,7 @@ export function parsePlayDocflowFile(
1024
1352
  bindings,
1025
1353
  errors,
1026
1354
  rejectedNodeIds,
1355
+ unreadBlocks.length > 0,
1027
1356
  );
1028
1357
 
1029
1358
  return {
@@ -1035,6 +1364,7 @@ export function parsePlayDocflowFile(
1035
1364
  })),
1036
1365
  bindings,
1037
1366
  errors,
1367
+ unreadBlocks,
1038
1368
  };
1039
1369
  }
1040
1370
 
@@ -1283,6 +1613,9 @@ function attachBindingsToBlocks(
1283
1613
  bindings: readonly PlayDocflowBinding[],
1284
1614
  errors: string[],
1285
1615
  rejectedNodeIds: ReadonlySet<string>,
1616
+ /** A block was not read: its annotations have nothing to name, and its
1617
+ * own parse error already says why. */
1618
+ someBlockUnread = false,
1286
1619
  ): void {
1287
1620
  const lineStarts = sourceLineStartsForDocflow(sourceCode);
1288
1621
  const exportRanges = playExportSourceRanges(sourceCode);
@@ -1291,7 +1624,8 @@ function attachBindingsToBlocks(
1291
1624
  // A helper module can serve several plays, each drawing only its own
1292
1625
  // boxes, so an imported annotation this play's diagram does not draw is
1293
1626
  // another play's. An annotation in the play's own file must name a node.
1294
- if (owners.length === 0 && binding.sourcePath) continue;
1627
+ if (owners.length === 0 && (binding.sourcePath || someBlockUnread))
1628
+ continue;
1295
1629
  if (owners.length === 0) {
1296
1630
  errors.push(
1297
1631
  `Docflow annotation "${binding.nodeId}" does not name a graph node.`,
@@ -1330,18 +1664,20 @@ function attachBindingsToBlocks(
1330
1664
  owner.bindings.push(binding);
1331
1665
  }
1332
1666
  for (const block of blocks) {
1333
- for (const binding of block.bindings) {
1667
+ for (const binding of [...block.bindings]) {
1334
1668
  const node = block.nodes.get(binding.nodeId)!;
1335
- if (binding.label) node.label = binding.label;
1336
1669
  // A box cannot be both a sketch and a bound statement. Silently letting
1337
1670
  // one win renders a real, traceable step as scenery — or the reverse — and
1338
- // the author who wrote both has no way to see which they got.
1671
+ // the author who wrote both has no way to see which they got. The
1672
+ // drawing keeps the sketch; the binding is reported and dropped.
1339
1673
  if (block.sketchIds.has(binding.nodeId)) {
1340
1674
  errors.push(
1341
1675
  `Docflow box "${binding.nodeId}" is declared \`class ${binding.nodeId} sketch\` and also bound by \`// @mermaid-node ${binding.nodeId}\` on line ${binding.line}. It is one or the other: drop it from the class line, or drop the annotation.`,
1342
1676
  );
1677
+ block.bindings.splice(block.bindings.indexOf(binding), 1);
1343
1678
  continue;
1344
1679
  }
1680
+ if (binding.label) node.label = binding.label;
1345
1681
  if (binding.kind) node.kind = binding.kind;
1346
1682
  }
1347
1683
  projectRecordedArms(block, errors);
@@ -1356,7 +1692,7 @@ function attachBindingsToBlocks(
1356
1692
  continue;
1357
1693
  errors.push(
1358
1694
  `Docflow box "${node.id}" in \`${blockLabel(block)}\` points at nothing, so the canvas can only draw it and say nothing about it. ` +
1359
- `Either put \`// @mermaid-node ${node.id}\` above the statement it runs, or — if this play has no such statement, because the work happens in another module or inside a loop — add it to a \`class ${node.id} sketch\` line in the block to declare it a sketch.`,
1695
+ `Put \`// @mermaid-node ${node.id}\` above the statement it runs, in this file or a module it imports. Only a box no statement runs, such as the event that starts the play, belongs on a \`class ${node.id} sketch\` line.`,
1360
1696
  );
1361
1697
  }
1362
1698
  }
@@ -1370,6 +1706,65 @@ function sourceLineStartsForDocflow(sourceCode: string): number[] {
1370
1706
  return starts;
1371
1707
  }
1372
1708
 
1709
+ /**
1710
+ * A `@mermaid` the diagram parser did not read as a diagram, and why. Without
1711
+ * this, a play whose diagram was written in the wrong comment form checked as
1712
+ * having "no authored Mermaid visualization", which sends the author to write
1713
+ * one they already wrote.
1714
+ */
1715
+ export type UnreadDocflowBlock = { line: number; reason: string };
1716
+
1717
+ /**
1718
+ * Every `@mermaid` tag in a comment that `parsePlayDocflowFile` skipped. Only
1719
+ * comments are considered: a `@mermaid` inside a string literal is text.
1720
+ */
1721
+ export function findUnreadDocflowBlocks(
1722
+ sourceCode: string,
1723
+ ): UnreadDocflowBlock[] {
1724
+ const spans = (pattern: RegExp) =>
1725
+ [...sourceCode.matchAll(pattern)].map((match) => ({
1726
+ start: match.index!,
1727
+ end: match.index! + match[0].length,
1728
+ body: match[1] ?? '',
1729
+ }));
1730
+ const jsdocs = spans(/\/\*\*([\s\S]*?)\*\//g);
1731
+ const blockComments = spans(/\/\*(?!\*)([\s\S]*?)\*\//g);
1732
+ const lineOf = (index: number) =>
1733
+ sourceCode.slice(0, index).split(/\r?\n/).length;
1734
+ const unread: UnreadDocflowBlock[] = [];
1735
+ for (const match of sourceCode.matchAll(/@mermaid(?![-\w])/g)) {
1736
+ const at = match.index!;
1737
+ const jsdoc = jsdocs.find((span) => span.start < at && at < span.end);
1738
+ if (jsdoc) {
1739
+ if (/^@mermaid(?:[ \t]+|\r?\n|$)/.test(cleanBlockBody(jsdoc.body)))
1740
+ continue;
1741
+ unread.push({
1742
+ line: lineOf(at),
1743
+ reason:
1744
+ '`@mermaid` must be the first thing in its `/** … */` block; text above it in the same block hides the diagram',
1745
+ });
1746
+ continue;
1747
+ }
1748
+ if (blockComments.some((span) => span.start < at && at < span.end)) {
1749
+ unread.push({
1750
+ line: lineOf(at),
1751
+ reason:
1752
+ 'it is in a `/* … */` comment; a diagram is read only from a `/** @mermaid … */` block (two asterisks)',
1753
+ });
1754
+ continue;
1755
+ }
1756
+ const lineStart = sourceCode.lastIndexOf('\n', at - 1) + 1;
1757
+ if (sourceCode.slice(lineStart, at).includes('//')) {
1758
+ unread.push({
1759
+ line: lineOf(at),
1760
+ reason:
1761
+ 'it is in a `//` comment; a diagram is read only from a `/** @mermaid … */` block',
1762
+ });
1763
+ }
1764
+ }
1765
+ return unread;
1766
+ }
1767
+
1373
1768
  /**
1374
1769
  * Parses the intentionally small authoring surface. Mermaid remains an export
1375
1770
  * target; this owns the stable IDs and bindings that make the diagram truthful.
@@ -1399,9 +1794,19 @@ export function parsePlayDocflow(
1399
1794
  ),
1400
1795
  )
1401
1796
  : undefined);
1797
+ const unread = selected
1798
+ ? undefined
1799
+ : parsed.unreadBlocks.find(
1800
+ (block) =>
1801
+ (block.authoredExportName ?? PLAY_DEFAULT_EXPORT) === requested,
1802
+ ) ??
1803
+ (parsed.unreadBlocks.length === 1 && parsed.blocks.length === 0
1804
+ ? parsed.unreadBlocks[0]
1805
+ : undefined);
1402
1806
  return {
1403
- docflow: parsed.errors.length ? null : (selected?.docflow ?? null),
1807
+ docflow: selected?.docflow ?? null,
1404
1808
  errors: parsed.errors,
1809
+ ...(unread ? { unreadReason: unread.reason } : {}),
1405
1810
  };
1406
1811
  }
1407
1812
 
@@ -1500,9 +1905,17 @@ function parseDocflowBindingsInSource(
1500
1905
  index + 1,
1501
1906
  errors,
1502
1907
  );
1908
+ const show = parseContractPaths(
1909
+ attributes.show,
1910
+ 'show',
1911
+ id,
1912
+ index + 1,
1913
+ errors,
1914
+ );
1503
1915
  if (
1504
1916
  (attributes.in !== undefined && !inputs) ||
1505
- (attributes.out !== undefined && !outputs)
1917
+ (attributes.out !== undefined && !outputs) ||
1918
+ (attributes.show !== undefined && !show)
1506
1919
  ) {
1507
1920
  continue;
1508
1921
  }
@@ -1525,6 +1938,7 @@ function parseDocflowBindingsInSource(
1525
1938
  // explicit `undefined` key survives `JSON.stringify` round-trips in some
1526
1939
  // callers and would reintroduce the hash drift this omission avoids.
1527
1940
  ...(arm ? { arm } : {}),
1941
+ ...(show?.length ? { show } : {}),
1528
1942
  ...inferred,
1529
1943
  });
1530
1944
  }
@@ -1572,6 +1986,34 @@ export function lintPlayDocflow(
1572
1986
  indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);
1573
1987
  }
1574
1988
 
1989
+ // Each issue about one box names it, the entry-file line to edit and a fix
1990
+ // to paste. A structural fix edits the diagram; a binding fix edits the
1991
+ // annotation, unless that annotation lives in an imported module.
1992
+ const locate = docflowSourceLocator(sourceCode);
1993
+ const bindingOf = new Map(
1994
+ docflow.bindings.map((binding) => [binding.nodeId, binding]),
1995
+ );
1996
+ const at = (
1997
+ node: string,
1998
+ where: 'diagram' | 'annotation',
1999
+ ): { node: string; line?: number } => {
2000
+ const binding = bindingOf.get(node);
2001
+ const annotation =
2002
+ binding && !binding.sourcePath ? locate.annotation(node) : undefined;
2003
+ const line =
2004
+ where === 'annotation'
2005
+ ? (annotation ?? locate.diagram(node))
2006
+ : (locate.diagram(node) ?? annotation);
2007
+ return line === undefined ? { node } : { node, line };
2008
+ };
2009
+ const drawn = (id: string) => {
2010
+ const node = byId.get(id);
2011
+ if (!node) return id;
2012
+ const open = node.kind === 'decision' ? '{' : '[';
2013
+ const close = node.kind === 'decision' ? '}' : ']';
2014
+ return `${id}${open}${node.label}${close}`;
2015
+ };
2016
+
1575
2017
  if (docflow.direction !== 'TB' && docflow.direction !== 'TD') {
1576
2018
  issues.push({
1577
2019
  code: 'docflow_direction_not_top_down',
@@ -1631,6 +2073,8 @@ export function lintPlayDocflow(
1631
2073
  message: `Docflow node "${node.id}" branches ${branches.length} ways but is not a decision.`,
1632
2074
  path: `docflow.nodes.${node.id}`,
1633
2075
  hint: 'Insert a decision node for the branch so the split is explicit in the UI.',
2076
+ ...at(node.id, 'diagram'),
2077
+ fix: `${node.id}{${node.label}?} -->|<outcome>| ${branches[0]!.to}`,
1634
2078
  });
1635
2079
  }
1636
2080
  if (node.kind === 'decision' && branches.length > 1) {
@@ -1639,31 +2083,77 @@ export function lintPlayDocflow(
1639
2083
  labels.some((label) => !label) ||
1640
2084
  new Set(labels).size !== labels.length
1641
2085
  ) {
2086
+ const unlabeled =
2087
+ branches.find((edge) => !edge.label?.trim()) ?? branches[0]!;
1642
2088
  issues.push({
1643
2089
  code: 'docflow_branch_labels_required',
1644
2090
  severity: 'error',
1645
2091
  message: `Decision "${node.id}" must give every branch a unique label.`,
1646
2092
  path: `docflow.nodes.${node.id}`,
1647
2093
  hint: 'Use `decision -->|outcome| next` for every decision edge.',
2094
+ ...at(node.id, 'diagram'),
2095
+ fix: `${node.id} -->|<outcome>| ${unlabeled.to}`,
2096
+ });
2097
+ }
2098
+ }
2099
+ // A decision is a state with one transition per outcome. With fewer than
2100
+ // two drawn arms the canvas cannot say which way a run went: a lone arm
2101
+ // reads as a plain step, and its untaken alternative (the else, the
2102
+ // unknown, the review) is missing from the picture. Warning: the run is
2103
+ // right, only the diagram is incomplete.
2104
+ if (node.kind === 'decision' && branches.length < 2) {
2105
+ issues.push({
2106
+ code: 'docflow_decision_arms_incomplete',
2107
+ severity: 'warning',
2108
+ message: `Decision "${node.id}" draws ${branches.length === 0 ? 'no arms' : `one arm (to ${branches[0]!.to})`}, so the canvas cannot show which way a run went. A decision draws one labeled edge per outcome the code can take.`,
2109
+ path: `docflow.nodes.${node.id}`,
2110
+ hint: `Draw every outcome as \`${node.id} -->|<outcome>| <next>\`, including the else, unknown or review path, or make the box a plain action if nothing branches here.`,
2111
+ ...at(node.id, 'diagram'),
2112
+ fix: `${node.id} -->|<other outcome>| <next box>`,
2113
+ });
2114
+ }
2115
+ // A decision outside a frame whose arms land inside it draws as one wire
2116
+ // into the frame, with every arm label piled beside it and exclusive
2117
+ // outcomes stacked as if they ran in sequence. Warning: the run is right,
2118
+ // only the picture misleads.
2119
+ if (node.kind === 'decision' && branches.length > 1) {
2120
+ for (const subgraph of docflow.subgraphs ?? []) {
2121
+ if (subgraph.memberIds.includes(node.id)) continue;
2122
+ const inside = branches.filter((edge) =>
2123
+ subgraph.memberIds.includes(edge.to),
2124
+ );
2125
+ if (inside.length < 2) continue;
2126
+ issues.push({
2127
+ code: 'docflow_decision_outside_region',
2128
+ severity: 'warning',
2129
+ message: `Decision "${node.id}" is outside subgraph "${subgraph.id}", but ${inside.length} of its arms (${inside.map((edge) => edge.to).join(', ')}) are inside it, so the canvas draws them as one wire into the frame.`,
2130
+ path: `docflow.nodes.${node.id}`,
2131
+ hint: 'Draw the decision in the same subgraph as its arms.',
2132
+ ...at(node.id, 'diagram'),
2133
+ fix: `Move \`${drawn(node.id)}\` inside \`subgraph ${subgraph.id}\`.`,
1648
2134
  });
1649
2135
  }
1650
2136
  }
1651
2137
  if (branches.length > DOCFLOW_MAX_BRANCHES) {
1652
2138
  issues.push({
1653
2139
  code: 'docflow_layout_complexity',
1654
- severity: 'error',
1655
- message: `Docflow node "${node.id}" has ${branches.length} branches; the dashboard supports at most ${DOCFLOW_MAX_BRANCHES} readable branches from one node.`,
2140
+ severity: 'warning',
2141
+ message: `Decision "${node.id}" has ${branches.length} branches; more than ${DOCFLOW_MAX_BRANCHES} arms side by side are hard to read.`,
1656
2142
  path: `docflow.nodes.${node.id}`,
1657
- hint: 'Split this choice into smaller named decisions.',
2143
+ hint: 'Group related outcomes into a first decision (for example US vs international) with its own named arms.',
2144
+ ...at(node.id, 'diagram'),
2145
+ fix: `${node.id} -->|<group of outcomes>| <nextDecision>{<Which one?>}`,
1658
2146
  });
1659
2147
  }
1660
2148
  if (node.label.length > DOCFLOW_MAX_LABEL_LENGTH) {
1661
2149
  issues.push({
1662
2150
  code: 'docflow_layout_complexity',
1663
2151
  severity: 'warning',
1664
- message: `Docflow node "${node.id}" has a ${node.label.length}-character label; labels over ${DOCFLOW_MAX_LABEL_LENGTH} characters are truncated in the graph.`,
2152
+ message: `Box "${node.id}" has a ${node.label.length}-character title; titles over ${DOCFLOW_MAX_LABEL_LENGTH} characters are cut off on the canvas.`,
1665
2153
  path: `docflow.nodes.${node.id}.label`,
1666
- hint: 'Move detail into code or a conceptual node and keep the card title short.',
2154
+ hint: 'Keep the card title short and move the detail into code.',
2155
+ ...at(node.id, 'diagram'),
2156
+ fix: `${node.id}${node.kind === 'decision' ? '{' : '['}<title of ${DOCFLOW_MAX_LABEL_LENGTH} characters or fewer>${node.kind === 'decision' ? '}' : ']'}`,
1667
2157
  });
1668
2158
  }
1669
2159
  // A label names the thing; the runtime counts it. Warning, not error: this
@@ -1671,12 +2161,79 @@ export function lintPlayDocflow(
1671
2161
  // should not be able to hard-fail `plays check`.
1672
2162
  const countFragment = docflowLabelCountFragment(node.label);
1673
2163
  if (countFragment) {
2164
+ const counted = node.label
2165
+ .replace(countFragment, '')
2166
+ .replace(/\s{2,}/g, ' ')
2167
+ .trim();
1674
2168
  issues.push({
1675
2169
  code: 'docflow_label_counts_rows',
1676
2170
  severity: 'warning',
1677
- message: `Docflow node "${node.id}" labels a count ("${countFragment}") in "${node.label}"; row counts come from the run, so an authored number goes stale as soon as the input changes.`,
2171
+ message: `Box "${node.id}" puts a count ("${countFragment}") in its title "${node.label}"; the run shows the live count, so an authored number goes stale as soon as the input changes.`,
1678
2172
  path: `docflow.nodes.${node.id}.label`,
1679
2173
  hint: 'Name what the node IS ("Seed rows"), not how many it holds — the canvas already shows the live count beside the node.',
2174
+ ...at(node.id, 'diagram'),
2175
+ fix: `${node.id}${node.kind === 'decision' ? '{' : '['}${counted || '<what it is>'}${node.kind === 'decision' ? '}' : ']'}`,
2176
+ });
2177
+ }
2178
+ // A sketch is a box no statement runs, so a run can never light it up. An
2179
+ // external trigger at the top of the flow, or a legend beside it, is
2180
+ // honestly a sketch; a box the flow passes INTO is a step the Play takes,
2181
+ // so its sketch hides real work from every run.
2182
+ if (node.sketch && node.kind !== 'conceptual' && (indegree.get(node.id) ?? 0) > 0) {
2183
+ issues.push({
2184
+ code: 'docflow_box_is_sketch',
2185
+ severity: 'warning',
2186
+ message: `Box "${node.id}" is a step in the flow but is drawn as a sketch, so no run can show it was reached or what it produced.`,
2187
+ path: `docflow.nodes.${node.id}`,
2188
+ hint: `Bind it: put this annotation above the statement that does the work (in this file or a module it imports), and drop ${node.id} from the \`class … sketch\` line.`,
2189
+ ...at(node.id, 'diagram'),
2190
+ fix: `${node.kind === 'decision' ? `// @mermaid-node ${node.id} type:"decision"` : `// @mermaid-node ${node.id}`} in:"<what it reads>" out:"<what it produces>"`,
2191
+ });
2192
+ }
2193
+ }
2194
+
2195
+ // A region drawn as one folded card hides which outcome leaves by which
2196
+ // wire. When it exits to more than one place, every exit must say which
2197
+ // outcome takes it; otherwise the folded card shows bare wires. Warning: the
2198
+ // run is right, only the picture is ambiguous.
2199
+ {
2200
+ const subgraphs = docflow.subgraphs ?? [];
2201
+ const membersOf = new Map<string, Set<string>>();
2202
+ const collect = (id: string): Set<string> => {
2203
+ const cached = membersOf.get(id);
2204
+ if (cached) return cached;
2205
+ const subgraph = subgraphs.find((candidate) => candidate.id === id);
2206
+ const members = new Set<string>(subgraph?.memberIds ?? []);
2207
+ for (const child of subgraphs) {
2208
+ if (child.parentId === id) {
2209
+ for (const member of collect(child.id)) members.add(member);
2210
+ }
2211
+ }
2212
+ membersOf.set(id, members);
2213
+ return members;
2214
+ };
2215
+ for (const subgraph of subgraphs) {
2216
+ const members = collect(subgraph.id);
2217
+ const exits = docflow.edges.filter(
2218
+ (edge) => members.has(edge.from) && !members.has(edge.to),
2219
+ );
2220
+ if (new Set(exits.map((edge) => edge.to)).size < 2) continue;
2221
+ const unlabeled = exits.filter((edge) => !edge.label?.trim());
2222
+ if (unlabeled.length === 0) continue;
2223
+ issues.push({
2224
+ code: 'docflow_region_exits_unlabeled',
2225
+ severity: 'warning',
2226
+ message: `Subgraph "${subgraph.id}" leaves to ${new Set(exits.map((edge) => edge.to)).size} places, but ${unlabeled.map((edge) => `${edge.from} --> ${edge.to}`).join(', ')} ${unlabeled.length === 1 ? 'has' : 'have'} no label, so its folded card shows a bare wire.`,
2227
+ path: `docflow.subgraphs.${subgraph.id}`,
2228
+ hint: 'Label every exit with the outcome that takes it.',
2229
+ node: subgraph.id,
2230
+ ...(() => {
2231
+ const line = locate.diagram(subgraph.id);
2232
+ return line === undefined ? {} : { line };
2233
+ })(),
2234
+ fix: unlabeled
2235
+ .map((edge) => `${edge.from} -->|<outcome>| ${edge.to}`)
2236
+ .join('; '),
1680
2237
  });
1681
2238
  }
1682
2239
  }
@@ -1692,20 +2249,50 @@ export function lintPlayDocflow(
1692
2249
  for (const binding of docflow.bindings) {
1693
2250
  const node = byId.get(binding.nodeId);
1694
2251
  if (!node) continue;
1695
- if (binding.ioConfidence === 'ambiguous' && node.kind === 'action') {
1696
- issues.push({
1697
- code: 'docflow_io_ambiguous',
1698
- severity: 'warning',
1699
- message: `Could not determine what "${binding.nodeId}" reads or changes.`,
1700
- path: `docflow.nodes.${binding.nodeId}`,
1701
- hint: 'Add in:"…" and out:"…", or annotate a clearer assignment.',
1702
- });
1703
- }
1704
2252
  // Imported annotations retain their own file and line. Names and assigned
1705
2253
  // variables must be checked in that file, not in the entry's namespace.
1706
2254
  const bindingSource = binding.sourcePath
1707
2255
  ? (moduleSources?.get(binding.sourcePath) ?? sourceCode)
1708
2256
  : sourceCode;
2257
+ const boundLine =
2258
+ bindingSource?.split(/\r?\n/)[binding.line - 1]?.trim() ?? '';
2259
+ const assignedName = /^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=/.exec(
2260
+ boundLine,
2261
+ )?.[1];
2262
+ // A bound box names what it reads and what it produces, so a run can show
2263
+ // both on the canvas. Inference covers a plain assignment; anything else
2264
+ // (an await, a call with effects) needs the author to say.
2265
+ if (node.kind !== 'conceptual') {
2266
+ // A chained per-row column (`.withColumn(…)`) reads its row; only what
2267
+ // it adds needs naming.
2268
+ const readsItsRow = boundLine.startsWith('.');
2269
+ const missing = [
2270
+ ...(binding.inputs?.length || readsItsRow ? [] : ['in']),
2271
+ ...(binding.outputs?.length ? [] : ['out']),
2272
+ ];
2273
+ if (missing.length > 0) {
2274
+ const produced = /^return\b/.test(boundLine)
2275
+ ? '$output'
2276
+ : (assignedName ?? '<what it produces>');
2277
+ issues.push({
2278
+ code: 'docflow_io_missing',
2279
+ severity: 'warning',
2280
+ message:
2281
+ missing.length === 2
2282
+ ? `Box "${binding.nodeId}" does not say what it reads or produces, so a run cannot show its input or its result.`
2283
+ : missing[0] === 'in'
2284
+ ? `Box "${binding.nodeId}" does not say what it reads, so a run cannot show its input.`
2285
+ : `Box "${binding.nodeId}" does not say what it produces, so a run cannot show its result.`,
2286
+ path: `docflow.nodes.${binding.nodeId}`,
2287
+ hint: `Add ${missing.map((name) => `${name}:"…"`).join(' and ')} to its annotation.`,
2288
+ ...at(binding.nodeId, 'annotation'),
2289
+ fix: docflowAnnotationFix(binding, {
2290
+ ...(missing.includes('in') ? { in: '<what it reads>' } : {}),
2291
+ ...(missing.includes('out') ? { out: produced } : {}),
2292
+ }),
2293
+ });
2294
+ }
2295
+ }
1709
2296
  if (!bindingSource) continue;
1710
2297
  const sourceIdentifiers = identifiersForSource(bindingSource);
1711
2298
  // What a module's box reads may be the play's own input, which the entry
@@ -1715,11 +2302,35 @@ export function lintPlayDocflow(
1715
2302
  sourceCode && bindingSource !== sourceCode
1716
2303
  ? new Set([...sourceIdentifiers, ...identifiersForSource(sourceCode)])
1717
2304
  : sourceIdentifiers;
1718
- const boundLine =
1719
- bindingSource.split(/\r?\n/)[binding.line - 1]?.trim() ?? '';
1720
- const assignedName = /^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=/.exec(
1721
- boundLine,
1722
- )?.[1];
2305
+ // A box bound to a statement that builds an object: which of its fields a
2306
+ // reader should see is the author's call. Without `show:` every display
2307
+ // falls back to the neutral peek (first field · N fields). An object of one
2308
+ // field shows that field whole, so there is nothing to choose. The hint
2309
+ // names the object's own fields, so the fix can be pasted.
2310
+ const builtObject =
2311
+ !binding.show?.length &&
2312
+ /^(?:(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=|return)\s*\{/.test(
2313
+ boundLine,
2314
+ )
2315
+ ? objectLiteralFields(bindingSource.split(/\r?\n/), binding.line - 1)
2316
+ : null;
2317
+ if (
2318
+ builtObject &&
2319
+ (builtObject.spread || builtObject.fields.length > 1)
2320
+ ) {
2321
+ const example = builtObject.fields.slice(0, 2).join(',');
2322
+ issues.push({
2323
+ code: 'docflow_show_undeclared',
2324
+ severity: 'warning',
2325
+ message: `Box "${binding.nodeId}" produces an object${builtObject.fields.length > 1 ? ` (${builtObject.fields.join(', ')})` : ''} but names no fields to show, so the canvas shows only its first field and a field count.`,
2326
+ path: `docflow.nodes.${binding.nodeId}.show`,
2327
+ hint: `Name the fields a reader should see first: show:"${example || 'field,nested.field'}".`,
2328
+ ...at(binding.nodeId, 'annotation'),
2329
+ fix: docflowAnnotationFix(binding, {
2330
+ show: example || 'field,nested.field',
2331
+ }),
2332
+ });
2333
+ }
1723
2334
  for (const path of binding.inputs ?? []) {
1724
2335
  const root = rootPath(path);
1725
2336
  if (inputIdentifiers.has(root)) continue;
@@ -1728,16 +2339,29 @@ export function lintPlayDocflow(
1728
2339
  .sort(
1729
2340
  (left, right) => levenshtein(root, left) - levenshtein(root, right),
1730
2341
  )[0];
2342
+ const close = suggestion && levenshtein(root, suggestion) <= 3;
1731
2343
  issues.push({
1732
2344
  code: 'docflow_input_not_found',
1733
2345
  severity: 'error',
1734
2346
  message: `Input "${path}" is not in scope for docflow node "${binding.nodeId}".`,
1735
2347
  path: `docflow.nodes.${binding.nodeId}.in`,
1736
- ...(suggestion && levenshtein(root, suggestion) <= 3
2348
+ ...(close
1737
2349
  ? { hint: `Did you mean "${suggestion}"?` }
1738
2350
  : {
1739
2351
  hint: 'Use an identifier or property path that exists in this play.',
1740
2352
  }),
2353
+ ...at(binding.nodeId, 'annotation'),
2354
+ fix: docflowAnnotationFix(binding, {
2355
+ in: (binding.inputs ?? [])
2356
+ .map((candidate) =>
2357
+ candidate === path
2358
+ ? close
2359
+ ? `${suggestion}${path.slice(root.length)}`
2360
+ : '<a name in scope>'
2361
+ : candidate,
2362
+ )
2363
+ .join(','),
2364
+ }),
1741
2365
  });
1742
2366
  }
1743
2367
  for (const path of binding.outputs ?? []) {
@@ -1754,6 +2378,8 @@ export function lintPlayDocflow(
1754
2378
  message: `Output "${path}" does not match the assigned variable "${assignedName}" for docflow node "${binding.nodeId}" — out: names bind to the variable the annotated statement assigns, so write out:"${assignedName}" (the node id can stay "${binding.nodeId}").`,
1755
2379
  path: `docflow.nodes.${binding.nodeId}.out`,
1756
2380
  hint: `The node id and the out: name are independent: the id labels the diagram box, out: must be the assigned variable/column name.`,
2381
+ ...at(binding.nodeId, 'annotation'),
2382
+ fix: docflowAnnotationFix(binding, { out: assignedName }),
1757
2383
  });
1758
2384
  continue;
1759
2385
  }
@@ -1764,17 +2390,36 @@ export function lintPlayDocflow(
1764
2390
  message: `Output "${path}" is not declared by docflow node "${binding.nodeId}".`,
1765
2391
  path: `docflow.nodes.${binding.nodeId}.out`,
1766
2392
  hint: 'Use an identifier or property path that exists in this play.',
2393
+ ...at(binding.nodeId, 'annotation'),
2394
+ fix: docflowAnnotationFix(binding, {
2395
+ out: assignedName ?? '<a name this statement assigns>',
2396
+ }),
1767
2397
  });
1768
2398
  }
1769
2399
  }
1770
2400
 
1771
- if (docflow.nodes.length > DOCFLOW_MAX_NODES) {
2401
+ // Regions fold by default, so count what each view of the canvas shows.
2402
+ for (const view of docflowCanvasViews(docflow)) {
2403
+ if (view.boxes <= DOCFLOW_MAX_NODES) continue;
1772
2404
  issues.push({
1773
2405
  code: 'docflow_layout_complexity',
1774
2406
  severity: 'warning',
1775
- message: `Docflow has ${docflow.nodes.length} nodes; more than ${DOCFLOW_MAX_NODES} makes the default graph hard to scan.`,
1776
- path: 'docflow.nodes',
1777
- hint: 'Keep the primary business path here and move supporting explanation into concise conceptual nodes.',
2407
+ message: view.regionId
2408
+ ? `Subgraph "${view.regionId}" shows ${view.boxes} boxes when opened; more than ${DOCFLOW_MAX_NODES} makes it hard to scan.`
2409
+ : `The diagram shows ${view.boxes} top-level boxes with every subgraph folded; more than ${DOCFLOW_MAX_NODES} makes the default view hard to scan.`,
2410
+ path: view.regionId ? `docflow.subgraphs.${view.regionId}` : 'docflow.nodes',
2411
+ hint: view.regionId
2412
+ ? 'Split the subgraph into nested phases, or move supporting detail into code.'
2413
+ : 'Group related steps into named `subgraph` phases; each folds to one box.',
2414
+ ...(view.regionId
2415
+ ? (() => {
2416
+ const line = locate.diagram(view.regionId);
2417
+ return { node: view.regionId, ...(line === undefined ? {} : { line }) };
2418
+ })()
2419
+ : {}),
2420
+ fix: view.regionId
2421
+ ? `subgraph <phase>["<Phase title>"] … end, inside \`subgraph ${view.regionId}\``
2422
+ : 'subgraph <phase>["<Phase title>"] … end, around related steps',
1778
2423
  });
1779
2424
  }
1780
2425
 
@@ -1797,7 +2442,7 @@ export function lintPlayDocflow(
1797
2442
  code: 'docflow_layout_complexity',
1798
2443
  severity: 'warning',
1799
2444
  message:
1800
- 'Docflow contains a feedback loop, which renders as a secondary dashed path.',
2445
+ 'The diagram contains a feedback loop, which renders as a secondary dashed path.',
1801
2446
  path: 'docflow.edges',
1802
2447
  hint: 'Label feedback edges clearly and keep the main forward path acyclic.',
1803
2448
  });
@@ -1805,3 +2450,28 @@ export function lintPlayDocflow(
1805
2450
 
1806
2451
  return issues;
1807
2452
  }
2453
+
2454
+ /**
2455
+ * The boxes each view of the canvas draws: the top level with every region
2456
+ * folded to one card, and each region opened alone (its direct nodes plus one
2457
+ * card per child region).
2458
+ */
2459
+ function docflowCanvasViews(
2460
+ docflow: PlayDocflow,
2461
+ ): { regionId: string | null; boxes: number }[] {
2462
+ const subgraphs = docflow.subgraphs ?? [];
2463
+ const regionIds = new Set(subgraphs.map((subgraph) => subgraph.id));
2464
+ const parentOf = new Map<string, string>();
2465
+ for (const subgraph of subgraphs) {
2466
+ if (subgraph.parentId) parentOf.set(subgraph.id, subgraph.parentId);
2467
+ for (const member of subgraph.memberIds) {
2468
+ if (!regionIds.has(member)) parentOf.set(member, subgraph.id);
2469
+ }
2470
+ }
2471
+ const boxes = new Map<string | null, number>();
2472
+ const count = (parent: string | null) =>
2473
+ boxes.set(parent, (boxes.get(parent) ?? 0) + 1);
2474
+ for (const node of docflow.nodes) count(parentOf.get(node.id) ?? null);
2475
+ for (const subgraph of subgraphs) count(parentOf.get(subgraph.id) ?? null);
2476
+ return [...boxes].map(([regionId, total]) => ({ regionId, boxes: total }));
2477
+ }