deepline 0.3.582 → 0.4.0

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 (196) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +79 -36
  2. package/dist/bundling-sources/sdk/src/index.ts +2 -0
  3. package/dist/bundling-sources/sdk/src/release.ts +7 -3
  4. package/dist/bundling-sources/sdk/src/types.ts +37 -0
  5. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +22 -3
  6. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +94 -5
  7. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +66 -12
  8. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/deployment/runtime-topology.ts +6 -1
  10. package/dist/bundling-sources/shared_libs/play-runtime/deployment/runtime-tuple-recovery.ts +9 -3
  11. package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +86 -20
  12. package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +17 -6
  13. package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +22 -6
  14. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +14 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +54 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/postgres-adapter.ts +2 -1
  17. package/dist/bundling-sources/shared_libs/play-runtime/row-failure-summary.ts +1 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +4 -1
  19. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +62 -6
  20. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +14 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +197 -19
  22. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +25 -1
  23. package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +5 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +140 -1
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-wake-policy.ts +419 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +47 -4
  27. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +24 -0
  28. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +1 -1
  29. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +36 -19
  30. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +380 -51
  31. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +21 -10
  32. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +32 -0
  33. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -0
  34. package/dist/bundling-sources/shared_libs/plays/deploy/api-client.ts +3 -1
  35. package/dist/bundling-sources/shared_libs/plays/deploy/run-deployment.ts +34 -4
  36. package/dist/bundling-sources/shared_libs/plays/docflow-recording-lint.ts +512 -0
  37. package/dist/bundling-sources/shared_libs/plays/docflow-requirement.ts +346 -0
  38. package/dist/bundling-sources/shared_libs/plays/docflow-rule-codes.ts +38 -0
  39. package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +42 -2
  40. package/dist/bundling-sources/shared_libs/plays/docflow.ts +223 -32
  41. package/dist/bundling-sources/shared_libs/plays/play-check-compact.ts +14 -1
  42. package/dist/bundling-sources/shared_libs/plays/run-result.ts +35 -0
  43. package/dist/cli/{agents-UAXDG4FS.mjs → agents-AHXB7N7Y.mjs} +68 -4
  44. package/dist/cli/{agents-2L73CJHH.js → agents-KBZ7OUZS.js} +95 -31
  45. package/dist/cli/{auth-3B2QB4UH.mjs → auth-3CACO52T.mjs} +5 -5
  46. package/dist/cli/auth-UOHCO5K6.js +44 -0
  47. package/dist/cli/{billing-E7FO622G.js → billing-5KXPGKMO.js} +105 -105
  48. package/dist/cli/{billing-CPBRWG3M.mjs → billing-TSTK63NB.mjs} +9 -9
  49. package/dist/cli/{chunk-3DVWSTAI.mjs → chunk-2GWKBQJZ.mjs} +1 -1
  50. package/dist/cli/{chunk-PNQVB4UD.mjs → chunk-3DJMPID5.mjs} +11 -11
  51. package/dist/cli/{chunk-FBSPHBAF.js → chunk-3ET6NRXP.js} +7 -3
  52. package/dist/cli/{chunk-NZR5PBNP.mjs → chunk-3MWTAM3F.mjs} +3 -3
  53. package/dist/cli/{chunk-ROUNT4NX.mjs → chunk-4ANDW2OT.mjs} +1 -1
  54. package/dist/cli/{chunk-ZH23XGJO.js → chunk-4BSCSQ6I.js} +4 -4
  55. package/dist/cli/{chunk-7QX5PCHP.mjs → chunk-4UEXAMDU.mjs} +2 -2
  56. package/dist/cli/{chunk-3EOET5UB.js → chunk-5XGLDVSD.js} +100 -100
  57. package/dist/cli/{chunk-MRSYC74T.js → chunk-7XXJJVSI.js} +5 -5
  58. package/dist/cli/{chunk-NJGXYYHN.js → chunk-7ZCD7OPO.js} +5 -5
  59. package/dist/cli/{chunk-JF4DUC2F.mjs → chunk-AJJSKKH4.mjs} +2 -2
  60. package/dist/cli/{chunk-XYQMOXP4.mjs → chunk-BHF5UW34.mjs} +1 -1
  61. package/dist/cli/{chunk-POYADK77.js → chunk-BO2TXH5Y.js} +20 -20
  62. package/dist/cli/{chunk-RNZXMOA6.mjs → chunk-BUC2TNF2.mjs} +2 -2
  63. package/dist/cli/{chunk-EGH4JNJP.js → chunk-BUUAFSSN.js} +68 -50
  64. package/dist/cli/{chunk-GZBXN56A.js → chunk-C45E47KC.js} +23 -23
  65. package/dist/cli/{chunk-HP6A3JCX.js → chunk-D4R3AL4F.js} +5 -5
  66. package/dist/cli/{chunk-ABJZQHON.mjs → chunk-DAZRIAXW.mjs} +4 -4
  67. package/dist/cli/{chunk-SKKRESFB.js → chunk-DNOZQGJF.js} +3 -3
  68. package/dist/cli/{chunk-DPLYQITT.js → chunk-DUL6UQ2T.js} +2 -2
  69. package/dist/cli/{chunk-U2QQQNWW.mjs → chunk-ES3S6UXR.mjs} +2 -2
  70. package/dist/cli/{chunk-4TTEAUZV.mjs → chunk-FDAYUP3M.mjs} +3 -3
  71. package/dist/cli/{chunk-V54YQHPV.js → chunk-FEVUIT2U.js} +6 -6
  72. package/dist/cli/{chunk-KDITCSPN.mjs → chunk-FSPEUU3V.mjs} +68 -6
  73. package/dist/cli/{chunk-OUFOJTEJ.mjs → chunk-FZZMCVOS.mjs} +5 -5
  74. package/dist/cli/{chunk-ISN4F6AY.js → chunk-GHOB72U6.js} +13 -13
  75. package/dist/cli/{chunk-LHA45DNY.mjs → chunk-GLYWRTEL.mjs} +3 -3
  76. package/dist/cli/{chunk-LDMCTV2Z.mjs → chunk-HNTIGYRT.mjs} +1 -1
  77. package/dist/cli/{chunk-EB2YLLZJ.js → chunk-IGPHYKEJ.js} +41 -41
  78. package/dist/cli/{chunk-VA35T3AF.js → chunk-ISSYN3DJ.js} +20 -20
  79. package/dist/cli/{chunk-DSHIB2XQ.mjs → chunk-JKQPITEE.mjs} +54 -36
  80. package/dist/cli/{chunk-ZARGHLZZ.mjs → chunk-KMLACXI2.mjs} +7 -3
  81. package/dist/cli/{chunk-DI5MULNX.js → chunk-KQXACHYA.js} +26 -26
  82. package/dist/cli/{chunk-CPZL6Z7D.js → chunk-LW2GKYZW.js} +2 -2
  83. package/dist/cli/{chunk-G5YU6RJ4.mjs → chunk-O2KSPI2M.mjs} +2 -2
  84. package/dist/cli/{chunk-H3KVMALU.js → chunk-O6GT6JD7.js} +9 -9
  85. package/dist/cli/{chunk-4ZAWRCB6.mjs → chunk-OCXWUWUI.mjs} +5 -5
  86. package/dist/cli/{chunk-YPP436NM.js → chunk-QKRDAJ3T.js} +53 -53
  87. package/dist/cli/{chunk-KQEW3EAU.js → chunk-QQESWF6D.js} +16 -16
  88. package/dist/cli/{chunk-CYZSHD66.js → chunk-REX5SUYU.js} +2 -2
  89. package/dist/cli/{chunk-Z3IAEHID.js → chunk-RXIQWG2N.js} +48 -48
  90. package/dist/cli/{chunk-5436ZJPH.js → chunk-S33BN7GZ.js} +3 -3
  91. package/dist/cli/{chunk-JD7P73ZW.mjs → chunk-SGRJJLNV.mjs} +1 -1
  92. package/dist/cli/{chunk-2K6EIL2D.mjs → chunk-TCNYSNVU.mjs} +1 -1
  93. package/dist/cli/{chunk-I5J6HGVR.mjs → chunk-TFPMVSGK.mjs} +2 -2
  94. package/dist/cli/{chunk-6NEMTKTA.mjs → chunk-V73WDQEA.mjs} +5 -5
  95. package/dist/cli/{chunk-Y36SQMSN.js → chunk-VYERVFGB.js} +68 -6
  96. package/dist/cli/{chunk-SYWLWTWM.mjs → chunk-WBRSVML3.mjs} +4 -4
  97. package/dist/cli/{chunk-NVHICORD.mjs → chunk-WW52ANX4.mjs} +2 -2
  98. package/dist/cli/{chunk-3HIJNXRB.js → chunk-XZS35M3Y.js} +10 -10
  99. package/dist/cli/{chunk-ZL3O7F5J.js → chunk-YNYHYL5C.js} +15 -15
  100. package/dist/cli/{chunk-FWB3QR7W.mjs → chunk-ZHE5E2WJ.mjs} +1 -1
  101. package/dist/cli/{chunk-D7J33HTK.mjs → chunk-ZJ2H77VV.mjs} +5 -5
  102. package/dist/cli/{chunk-JUZIMW4S.js → chunk-ZX6UVPGZ.js} +7 -7
  103. package/dist/cli/command-docs.js +2 -2
  104. package/dist/cli/command-docs.mjs +1 -1
  105. package/dist/cli/concurrent-runs-help-H5SZUA5J.js +22 -0
  106. package/dist/cli/{concurrent-runs-help-UFNYQYU2.mjs → concurrent-runs-help-IYELSCHB.mjs} +6 -6
  107. package/dist/cli/{csv-QSDRGLQH.mjs → csv-ENEC3APZ.mjs} +4 -4
  108. package/dist/cli/{csv-ZI5LYFHF.js → csv-X6CP57R4.js} +13 -13
  109. package/dist/cli/{db-ZDL6Q53U.js → db-6HLRSE2M.js} +27 -27
  110. package/dist/cli/{db-WVWXNNMO.mjs → db-YGKRFK4T.mjs} +6 -6
  111. package/dist/cli/{describe-UUQBKUVL.mjs → describe-4SGQEX7K.mjs} +18 -18
  112. package/dist/cli/describe-Q2OYHDVZ.js +50 -0
  113. package/dist/cli/describe-core.d.mts +2 -2
  114. package/dist/cli/describe-core.d.ts +2 -2
  115. package/dist/cli/{executions-SCGHTWTC.js → executions-IC55YJ67.js} +8 -8
  116. package/dist/cli/{executions-QN3OYJKT.mjs → executions-PO2IOSZ7.mjs} +6 -6
  117. package/dist/cli/{feedback-7QPHLXGU.mjs → feedback-6BUD5F4I.mjs} +6 -6
  118. package/dist/cli/{feedback-6QQ7ONLW.js → feedback-BCGQLZ5T.js} +14 -14
  119. package/dist/cli/git-5X3MLBIP.js +26 -0
  120. package/dist/cli/{git-HFPJX573.mjs → git-IN4IBL2K.mjs} +5 -5
  121. package/dist/cli/index.js +148 -148
  122. package/dist/cli/index.mjs +47 -47
  123. package/dist/cli/{integrations-ND2HULSH.js → integrations-R2Z2MDO3.js} +29 -29
  124. package/dist/cli/{integrations-4SZ5O24P.mjs → integrations-ZMGB6NQA.mjs} +7 -7
  125. package/dist/cli/{legacy-noops-WUP3TBR2.mjs → legacy-noops-GIC5OZKP.mjs} +6 -6
  126. package/dist/cli/{legacy-noops-GQF6AYP5.js → legacy-noops-X4JPRPTJ.js} +9 -9
  127. package/dist/cli/{mcp-3GUFYGCQ.mjs → mcp-G4IRJIKK.mjs} +4 -4
  128. package/dist/cli/{mcp-L3YYVEU6.js → mcp-USZKTVL2.js} +24 -24
  129. package/dist/cli/{monitors-OFCVJSH5.mjs → monitors-SNFZPSCY.mjs} +7 -7
  130. package/dist/cli/{monitors-CVZZN5WG.js → monitors-T7LRP7OB.js} +100 -100
  131. package/dist/cli/{org-MQ5AUN7I.js → org-2L2ZZL2P.js} +121 -121
  132. package/dist/cli/{org-3DTAYA52.mjs → org-YTXLKW52.mjs} +6 -6
  133. package/dist/cli/{outcomes-42W24EXG.mjs → outcomes-CJWBIFTA.mjs} +6 -6
  134. package/dist/cli/{outcomes-MGDUYHUD.js → outcomes-O63F57JF.js} +14 -14
  135. package/dist/cli/{play-PD45RNYZ.mjs → play-6UWPUHC6.mjs} +331 -70
  136. package/dist/cli/{play-IMAD7QTV.js → play-T353SULJ.js} +930 -669
  137. package/dist/cli/{providers-DYKHG7NV.mjs → providers-LZABK2UW.mjs} +6 -6
  138. package/dist/cli/{providers-WONHPTRG.js → providers-XORJH2VW.js} +9 -9
  139. package/dist/cli/{quickstart-5QPGHLEX.mjs → quickstart-O4RF7J55.mjs} +4 -4
  140. package/dist/cli/{quickstart-6AAFULGC.js → quickstart-QBNUNPZR.js} +6 -6
  141. package/dist/cli/{run-WOW7QO3W.js → run-2CPMFC6W.js} +44 -44
  142. package/dist/cli/{run-4K6ZU7H7.mjs → run-GBRPFC6P.mjs} +23 -23
  143. package/dist/cli/{search-CKVFWVXQ.mjs → search-G7TS7OFB.mjs} +7 -7
  144. package/dist/cli/search-M3AHFCKQ.js +32 -0
  145. package/dist/cli/{search-output-WWB25JWA.mjs → search-output-BIIJRUCP.mjs} +4 -4
  146. package/dist/cli/{search-output-B5QE7ZNK.js → search-output-NRKLNWSD.js} +6 -6
  147. package/dist/cli/{secrets-SVZB6TSW.mjs → secrets-DN3XEZNH.mjs} +6 -6
  148. package/dist/cli/{secrets-WKIMR346.js → secrets-FUXYSEL5.js} +15 -15
  149. package/dist/cli/{sessions-P3QENG6T.mjs → sessions-PMUTPCTT.mjs} +6 -6
  150. package/dist/cli/sessions-VMBMBGVJ.js +23 -0
  151. package/dist/cli/{settings-V5ABL6D2.mjs → settings-N6GNS2KA.mjs} +12 -12
  152. package/dist/cli/{settings-UIFRGJW3.js → settings-ZDTWCQ6B.js} +85 -85
  153. package/dist/cli/{setup-E67NJTEF.mjs → setup-LJ3KWPSA.mjs} +9 -9
  154. package/dist/cli/{setup-A5MIJU3S.js → setup-PN5TSSJE.js} +49 -49
  155. package/dist/cli/{skills-WLHOQ4DO.mjs → skills-7J42K6VC.mjs} +7 -7
  156. package/dist/cli/skills-CXDENBLF.js +37 -0
  157. package/dist/cli/{tools-EG4KL3BB.mjs → tools-M3S6D6DA.mjs} +17 -17
  158. package/dist/cli/tools-WY2GMOC7.js +57 -0
  159. package/dist/cli/{update-IPFBE6SA.mjs → update-XTVFG74E.mjs} +9 -9
  160. package/dist/cli/update-ZB2IBGXG.js +37 -0
  161. package/dist/cli/{views-ZIBY2RVB.js → views-B4X2FWTF.js} +21 -21
  162. package/dist/cli/{views-XDN6SEWY.mjs → views-UFYRDO4X.mjs} +6 -6
  163. package/dist/cli/{workflow-BLKPBRBT.js → workflow-I2RM2J2J.js} +53 -29
  164. package/dist/cli/{workflow-O2XPMOVL.mjs → workflow-ZLMS3PDE.mjs} +42 -18
  165. package/dist/{client-QznpkWrk.d.ts → client-2QWMJInp.d.ts} +1 -1
  166. package/dist/{client-CmG8MT0x.d.mts → client-7H8TXmLa.d.mts} +1 -1
  167. package/dist/{client-core-CY0jNW0e.d.mts → client-core-BraEuxbg.d.mts} +67 -4
  168. package/dist/{client-core-CXDqfeiB.d.ts → client-core-DRglY5xa.d.ts} +67 -4
  169. package/dist/index.d.mts +3 -3
  170. package/dist/index.d.ts +3 -3
  171. package/dist/index.js +9 -9
  172. package/dist/index.mjs +6 -6
  173. package/dist/install-integrity.json +125 -120
  174. package/dist/plays/bundle-play-file.mjs +5 -0
  175. package/dist/plays/play-description.d.mts +1 -1
  176. package/dist/plays/play-description.d.ts +1 -1
  177. package/dist/plays/run-request.d.mts +1 -1
  178. package/dist/plays/run-request.d.ts +1 -1
  179. package/dist/release.d.mts +3 -3
  180. package/dist/release.d.ts +3 -3
  181. package/dist/release.js +2 -2
  182. package/dist/release.mjs +1 -1
  183. package/dist/server.d.mts +2 -2
  184. package/dist/server.d.ts +2 -2
  185. package/dist/server.js +5 -5
  186. package/dist/server.mjs +3 -3
  187. package/package.json +1 -1
  188. package/dist/cli/auth-ALBG5LF4.js +0 -44
  189. package/dist/cli/concurrent-runs-help-E3YMAO5Q.js +0 -22
  190. package/dist/cli/describe-QB5T47B3.js +0 -50
  191. package/dist/cli/git-4FXTWHXT.js +0 -26
  192. package/dist/cli/search-YZIJS7QU.js +0 -32
  193. package/dist/cli/sessions-VQPGPXMU.js +0 -23
  194. package/dist/cli/skills-GTBK33MV.js +0 -37
  195. package/dist/cli/tools-GPAIPRPQ.js +0 -57
  196. package/dist/cli/update-QLWS32WR.js +0 -37
@@ -45,6 +45,7 @@ import {
45
45
  failPostgresSchedulerReceipt,
46
46
  failPostgresSchedulerReceipts,
47
47
  getPostgresSchedulerReceipt,
48
+ getPostgresSchedulerReceiptManifests,
48
49
  getPostgresSchedulerReceipts,
49
50
  heartbeatPostgresSchedulerReceipts,
50
51
  markPostgresSchedulerReceiptsQueued,
@@ -927,8 +928,11 @@ export function createReceiptGatewayDispatcher(input: {
927
928
  ): RuntimeStepReceipt | null => {
928
929
  if (!receipt) return null;
929
930
  const { output, outputRef, ...manifest } = receipt;
931
+ // A manifest query already priced the inline body in Postgres; only a
932
+ // receipt read in full is measured here.
930
933
  const outputByteLength =
931
934
  outputRef?.byteLength ??
935
+ receipt.outputByteLength ??
932
936
  (output === undefined
933
937
  ? null
934
938
  : new TextEncoder().encode(JSON.stringify(output)).byteLength);
@@ -1126,11 +1130,15 @@ export function createReceiptGatewayDispatcher(input: {
1126
1130
  if (key instanceof Response) return key;
1127
1131
  const keyScopeError = dispatchOptions.validateKeys?.([key]);
1128
1132
  if (keyScopeError) return keyScopeError;
1129
- const receipt = await getPostgresSchedulerReceipt(
1130
- client,
1131
- { key },
1132
- options,
1133
- );
1133
+ const receipt = hydrateOutput
1134
+ ? await getPostgresSchedulerReceipt(client, { key }, options)
1135
+ : ((
1136
+ await getPostgresSchedulerReceiptManifests(
1137
+ client,
1138
+ { keys: [key] },
1139
+ options,
1140
+ )
1141
+ )[0] ?? null);
1134
1142
  dispatchOptions.onRead?.({
1135
1143
  action: body.action,
1136
1144
  keys: [key],
@@ -1147,11 +1155,14 @@ export function createReceiptGatewayDispatcher(input: {
1147
1155
  if (keys instanceof Response) return keys;
1148
1156
  const keyScopeError = dispatchOptions.validateKeys?.(keys);
1149
1157
  if (keyScopeError) return keyScopeError;
1150
- const receipts = await getPostgresSchedulerReceipts(
1151
- client,
1152
- { keys },
1153
- options,
1154
- );
1158
+ // A manifest read must not fetch the bodies it exists to avoid.
1159
+ const receipts = hydrateOutput
1160
+ ? await getPostgresSchedulerReceipts(client, { keys }, options)
1161
+ : await getPostgresSchedulerReceiptManifests(
1162
+ client,
1163
+ { keys },
1164
+ options,
1165
+ );
1155
1166
  dispatchOptions.onRead?.({
1156
1167
  action: body.action,
1157
1168
  keys,
@@ -249,8 +249,34 @@ export type RuntimeWorkerEarlySandboxHint = {
249
249
  * an older worker drops it and takes the absent path.
250
250
  */
251
251
  sandboxRuntimeLimits?: PlaySandboxRuntimeLimits;
252
+ /**
253
+ * The org's concurrent-runs entitlement as start-run admission resolved it,
254
+ * the same value the launch carries as `concurrentRunsLimit`. The worker's
255
+ * early-sandbox capacity check uses it, so a plan-limited org (no runtime
256
+ * limit-cache row) is judged at its real limit, not the default. Absent or
257
+ * invalid (an older app or gateway): the cache or default, as before.
258
+ * Reader-first: an older worker or gateway drops it.
259
+ */
260
+ concurrentRunsLimit?: number;
252
261
  };
253
262
 
263
+ /**
264
+ * Largest concurrent-runs entitlement a hint may carry: the runtime's
265
+ * `MAX_PLAY_SANDBOX_CONCURRENCY` (kept equal by a test; not imported, so the
266
+ * gateway's hint parser stays free of the scheduler database module).
267
+ */
268
+ export const EARLY_SANDBOX_HINT_CONCURRENT_RUNS_LIMIT_MAX = 250;
269
+
270
+ /** A carried entitlement inside the runtime's bounds, or undefined. */
271
+ function readCarriedConcurrentRunsLimit(value: unknown): number | undefined {
272
+ return typeof value === 'number' &&
273
+ Number.isSafeInteger(value) &&
274
+ value >= 1 &&
275
+ value <= EARLY_SANDBOX_HINT_CONCURRENT_RUNS_LIMIT_MAX
276
+ ? value
277
+ : undefined;
278
+ }
279
+
254
280
  /** Longest placement policy id a hint may carry (catalog ids are ~25). */
255
281
  const EARLY_SANDBOX_HINT_POLICY_ID_MAX_LENGTH = 128;
256
282
 
@@ -314,6 +340,11 @@ export function parseEarlySandboxHint(
314
340
  if (!parsed) return null;
315
341
  sandboxRuntimeLimits = parsed;
316
342
  }
343
+ // Advisory: an invalid entitlement is dropped (the check then uses the
344
+ // cache or default, as before), never a refused hint.
345
+ const concurrentRunsLimit = readCarriedConcurrentRunsLimit(
346
+ value.concurrentRunsLimit,
347
+ );
317
348
  return {
318
349
  workflowId,
319
350
  orgId,
@@ -322,6 +353,7 @@ export function parseEarlySandboxHint(
322
353
  ...(queue ? { queue } : {}),
323
354
  ...(listenerGeneration ? { listenerGeneration } : {}),
324
355
  ...(sandboxRuntimeLimits ? { sandboxRuntimeLimits } : {}),
356
+ ...(concurrentRunsLimit !== undefined ? { concurrentRunsLimit } : {}),
325
357
  };
326
358
  } catch {
327
359
  return null;
@@ -250,6 +250,12 @@ export const PLAY_AUTHORING_CONTRACT_ISSUE_CODES = [
250
250
  'docflow_layout_complexity',
251
251
  'docflow_topology_invalid',
252
252
  'docflow_io_missing',
253
+ 'docflow_inputs_undeclared',
254
+ 'docflow_output_records_empty',
255
+ 'docflow_output_is_tool_result',
256
+ 'docflow_diagram_disabled',
257
+ 'docflow_diagram_opt_out_invalid',
258
+ 'play_diagram_opt_out_available',
253
259
  'docflow_box_is_sketch',
254
260
  'docflow_input_not_found',
255
261
  'docflow_output_not_found',
@@ -273,7 +273,9 @@ export class DeployApiClient {
273
273
  return this.request({
274
274
  method: 'POST',
275
275
  path: '/api/v2/plays/compile-manifest',
276
- body: input,
276
+ // A deployment registers revisions: a Play without a diagram is
277
+ // refused here, with the same issue `plays check` prints.
278
+ body: { ...input, purpose: 'publish' },
277
279
  });
278
280
  }
279
281
 
@@ -1,4 +1,4 @@
1
- import { join } from 'node:path';
1
+ import { dirname, isAbsolute, join, relative } from 'node:path';
2
2
  import { mkdir, mkdtemp, rm } from 'node:fs/promises';
3
3
  import type { PlayCompilerManifest } from '../compiler-manifest';
4
4
  import {
@@ -942,9 +942,39 @@ export async function runDeployment(
942
942
  ),
943
943
  ...play.runPlayStringTargets,
944
944
  ]);
945
- const dependencies = [...dependencyNames]
946
- .map((dependencyName) => manifestByName.get(dependencyName))
947
- .filter((entry): entry is PlayCompilerManifest => Boolean(entry));
945
+ // Where each imported Play file sits, in the frame the parent's
946
+ // `artifact.entryFile` is written in. Static analysis joins an
947
+ // `import child from './child.play'` to its Play by this path, so the
948
+ // `ctx.runPlay(key, child)` call is a play call at its call site.
949
+ const entryFile = play.result.artifact.entryFile;
950
+ const importedFilePaths = new Map(
951
+ (play.result.importedPlayDependencies ?? []).flatMap((dependency) =>
952
+ // A bundler that records no path names no call site: the import
953
+ // then stays the unplaced dependency it was.
954
+ dependency.filePath
955
+ ? [
956
+ [
957
+ dependency.playName,
958
+ isAbsolute(entryFile)
959
+ ? dependency.filePath
960
+ : join(
961
+ dirname(entryFile),
962
+ relative(
963
+ dirname(play.result.filePath),
964
+ dependency.filePath,
965
+ ),
966
+ ).replaceAll('\\', '/'),
967
+ ] as const,
968
+ ]
969
+ : [],
970
+ ),
971
+ );
972
+ const dependencies = [...dependencyNames].flatMap((dependencyName) => {
973
+ const manifest = manifestByName.get(dependencyName);
974
+ if (!manifest) return [];
975
+ const filePath = importedFilePaths.get(dependencyName);
976
+ return [filePath ? { ...manifest, filePath } : manifest];
977
+ });
948
978
  try {
949
979
  const compiled = await client.compileManifest({
950
980
  name: play.name,
@@ -0,0 +1,512 @@
1
+ /**
2
+ * Static checks on what a bound diagram box will RECORD when the Play runs.
3
+ *
4
+ * The runtime records each bound statement's `in:`/`out:` values as small
5
+ * previews right after the statement runs (`packages/play-runtime/
6
+ * docflow-node-io.ts`). Three authoring mistakes make those previews empty
7
+ * even though the Play works:
8
+ *
9
+ * - `out:` names a collection the statement creates empty and later code
10
+ * fills (`const rows: Rec[] = []` then a loop pushes): the box records `[]`.
11
+ * - `out:` names the raw result of `ctx.tools.execute(...)`: its data are read
12
+ * through getters, so the box records `{}`.
13
+ * - the box declares no `in:`: nothing is recorded as its input.
14
+ *
15
+ * Every rule here reads source only, so it runs at source admission (`plays
16
+ * check`, publish) and never at launch. Diagram problems are warnings.
17
+ *
18
+ * This module depends only on `ts-ast` and types, so `docflow.ts` can call it
19
+ * without an import cycle.
20
+ */
21
+ import type { PlayDocflowBinding } from './docflow';
22
+ import {
23
+ astArray,
24
+ isAstNode,
25
+ parsePlaySourceForAnalysis,
26
+ type AstNode,
27
+ } from './ts-ast';
28
+
29
+ type SourceIndex = {
30
+ ast: AstNode;
31
+ lineStarts: number[];
32
+ };
33
+
34
+ /** One parse per distinct source string within a lint pass. */
35
+ export function createRecordingSourceIndex(): (
36
+ source: string,
37
+ ) => SourceIndex | null {
38
+ const cache = new Map<string, SourceIndex | null>();
39
+ return (source) => {
40
+ if (cache.has(source)) return cache.get(source)!;
41
+ const ast = parsePlaySourceForAnalysis(source);
42
+ const index = ast ? { ast, lineStarts: lineStartsOf(source) } : null;
43
+ cache.set(source, index);
44
+ return index;
45
+ };
46
+ }
47
+
48
+ function lineStartsOf(source: string): number[] {
49
+ const starts = [0];
50
+ for (let index = 0; index < source.length; index += 1) {
51
+ if (source[index] === '\n') starts.push(index + 1);
52
+ }
53
+ return starts;
54
+ }
55
+
56
+ const TYPE_KEYS = new Set([
57
+ 'typeAnnotation',
58
+ 'typeParameters',
59
+ 'typeArguments',
60
+ 'returnType',
61
+ ]);
62
+
63
+ function* walk(node: AstNode): Generator<AstNode> {
64
+ const pending: AstNode[] = [node];
65
+ while (pending.length > 0) {
66
+ const current = pending.pop()!;
67
+ yield current;
68
+ for (const [key, child] of Object.entries(current)) {
69
+ // Types are not values: a parameter's annotation declares nothing a
70
+ // statement reads, and a type name is not an input.
71
+ if (key === 'loc' || key === 'range' || TYPE_KEYS.has(key)) continue;
72
+ if (Array.isArray(child)) {
73
+ for (let i = child.length - 1; i >= 0; i -= 1) {
74
+ if (isAstNode(child[i])) pending.push(child[i]);
75
+ }
76
+ } else if (isAstNode(child)) pending.push(child);
77
+ }
78
+ }
79
+ }
80
+
81
+ const start = (node: AstNode) =>
82
+ typeof node.start === 'number' ? node.start : -1;
83
+ const end = (node: AstNode) => (typeof node.end === 'number' ? node.end : -1);
84
+
85
+ const BOUND_STATEMENT_TYPES = new Set([
86
+ 'ExpressionStatement',
87
+ 'IfStatement',
88
+ 'ReturnStatement',
89
+ 'ThrowStatement',
90
+ 'VariableDeclaration',
91
+ ]);
92
+
93
+ /** The smallest bindable statement overlapping 1-based `line`. */
94
+ function boundStatementAt(index: SourceIndex, line: number): AstNode | null {
95
+ const lineStart = index.lineStarts[line - 1];
96
+ const lineEnd = index.lineStarts[line] ?? Number.POSITIVE_INFINITY;
97
+ if (lineStart === undefined) return null;
98
+ let match: AstNode | null = null;
99
+ for (const node of walk(index.ast)) {
100
+ if (!BOUND_STATEMENT_TYPES.has(node.type)) continue;
101
+ if (!(start(node) < lineEnd && end(node) > lineStart)) continue;
102
+ if (!match || end(node) - start(node) < end(match) - start(match)) {
103
+ match = node;
104
+ }
105
+ }
106
+ return match;
107
+ }
108
+
109
+ function unwrap(node: AstNode | null | undefined): AstNode | null {
110
+ let current = node ?? null;
111
+ while (
112
+ current &&
113
+ (current.type === 'TSAsExpression' ||
114
+ current.type === 'TSSatisfiesExpression' ||
115
+ current.type === 'TSTypeAssertion' ||
116
+ current.type === 'TSNonNullExpression' ||
117
+ current.type === 'ParenthesizedExpression' ||
118
+ current.type === 'AwaitExpression')
119
+ ) {
120
+ const next =
121
+ current.type === 'AwaitExpression'
122
+ ? current.argument
123
+ : current.expression;
124
+ current = isAstNode(next) ? next : null;
125
+ }
126
+ return current;
127
+ }
128
+
129
+ const identifierName = (node: unknown): string | null =>
130
+ isAstNode(node) && node.type === 'Identifier' && typeof node.name === 'string'
131
+ ? node.name
132
+ : null;
133
+
134
+ const propertyName = (member: AstNode): string | null =>
135
+ member.computed ? null : identifierName(member.property);
136
+
137
+ /**
138
+ * The declarator of `name` that the bound statement sees: the last one that
139
+ * starts before the statement ends.
140
+ */
141
+ function declaratorFor(
142
+ index: SourceIndex,
143
+ name: string,
144
+ before: number,
145
+ ): AstNode | null {
146
+ let found: AstNode | null = null;
147
+ for (const node of walk(index.ast)) {
148
+ if (node.type !== 'VariableDeclarator') continue;
149
+ if (identifierName(node.id) !== name) continue;
150
+ if (start(node) > before) continue;
151
+ if (!found || start(node) > start(found)) found = node;
152
+ }
153
+ return found;
154
+ }
155
+
156
+ /** `[]`, `{}`, `new Map()`, `new Set()` (any type arguments, no entries). */
157
+ function isEmptyCollection(init: AstNode | null): string | null {
158
+ const value = unwrap(init);
159
+ if (!value) return null;
160
+ if (value.type === 'ArrayExpression' && astArray(value.elements).length === 0)
161
+ return '[]';
162
+ if (
163
+ value.type === 'ObjectExpression' &&
164
+ astArray(value.properties).length === 0
165
+ )
166
+ return '{}';
167
+ if (value.type === 'NewExpression') {
168
+ const ctor = identifierName(value.callee);
169
+ if (
170
+ (ctor === 'Map' || ctor === 'Set') &&
171
+ astArray(value.arguments).length === 0
172
+ )
173
+ return `new ${ctor}()`;
174
+ }
175
+ return null;
176
+ }
177
+
178
+ const MUTATING_METHODS = new Set([
179
+ 'push',
180
+ 'unshift',
181
+ 'splice',
182
+ 'set',
183
+ 'add',
184
+ 'fill',
185
+ 'sort',
186
+ 'reverse',
187
+ ]);
188
+
189
+ /** End of the innermost block that holds `node`: where its name goes out of scope. */
190
+ function scopeEndOf(index: SourceIndex, node: AstNode): number {
191
+ let scopeEnd = end(index.ast);
192
+ let scopeSize = Number.POSITIVE_INFINITY;
193
+ for (const candidate of walk(index.ast)) {
194
+ if (candidate.type !== 'BlockStatement' && candidate.type !== 'Program')
195
+ continue;
196
+ if (start(candidate) > start(node) || end(candidate) < end(node)) continue;
197
+ const size = end(candidate) - start(candidate);
198
+ if (size < scopeSize) {
199
+ scopeSize = size;
200
+ scopeEnd = end(candidate);
201
+ }
202
+ }
203
+ return scopeEnd;
204
+ }
205
+
206
+ /** The first statement in `[after, before)` that fills `name` in place, if any. */
207
+ function firstMutationAfter(
208
+ index: SourceIndex,
209
+ name: string,
210
+ after: number,
211
+ before: number,
212
+ ): AstNode | null {
213
+ let first: AstNode | null = null;
214
+ for (const node of walk(index.ast)) {
215
+ if (start(node) < after || start(node) >= before) continue;
216
+ let mutates = false;
217
+ if (node.type === 'CallExpression' && isAstNode(node.callee)) {
218
+ const callee = node.callee;
219
+ if (
220
+ callee.type === 'MemberExpression' &&
221
+ identifierName(callee.object) === name &&
222
+ MUTATING_METHODS.has(propertyName(callee) ?? '')
223
+ ) {
224
+ mutates = true;
225
+ }
226
+ // Object.assign(name, …)
227
+ if (
228
+ callee.type === 'MemberExpression' &&
229
+ identifierName(callee.object) === 'Object' &&
230
+ propertyName(callee) === 'assign' &&
231
+ identifierName(astArray(node.arguments)[0]) === name
232
+ ) {
233
+ mutates = true;
234
+ }
235
+ }
236
+ if (node.type === 'AssignmentExpression' && isAstNode(node.left)) {
237
+ const left = node.left;
238
+ if (
239
+ left.type === 'MemberExpression' &&
240
+ identifierName(left.object) === name
241
+ ) {
242
+ mutates = true;
243
+ }
244
+ }
245
+ if (mutates && (!first || start(node) < start(first))) first = node;
246
+ }
247
+ return first;
248
+ }
249
+
250
+ /** `ctx.tools.execute(...)`, `await ctx.tools.execute(...)`, any receiver. */
251
+ function isToolExecuteCall(init: AstNode | null): boolean {
252
+ const value = unwrap(init);
253
+ if (!value || value.type !== 'CallExpression' || !isAstNode(value.callee)) {
254
+ return false;
255
+ }
256
+ const callee = value.callee;
257
+ if (
258
+ callee.type !== 'MemberExpression' ||
259
+ propertyName(callee) !== 'execute'
260
+ ) {
261
+ return false;
262
+ }
263
+ const owner = isAstNode(callee.object) ? callee.object : null;
264
+ return Boolean(
265
+ owner &&
266
+ owner.type === 'MemberExpression' &&
267
+ propertyName(owner) === 'tools',
268
+ );
269
+ }
270
+
271
+ const lineOf = (index: SourceIndex, offset: number) => {
272
+ let low = 0;
273
+ let high = index.lineStarts.length - 1;
274
+ while (low < high) {
275
+ const mid = Math.ceil((low + high) / 2);
276
+ if (index.lineStarts[mid]! <= offset) low = mid;
277
+ else high = mid - 1;
278
+ }
279
+ return low + 1;
280
+ };
281
+
282
+ export type DocflowRecordedOutputProblem =
283
+ | {
284
+ kind: 'filled_after';
285
+ name: string;
286
+ emptyAs: string;
287
+ /** Where the empty value is created. */
288
+ declarationLine: number;
289
+ /** The first statement that fills it after the box's statement. */
290
+ mutationLine: number;
291
+ }
292
+ | {
293
+ kind: 'tool_result';
294
+ name: string;
295
+ declarationLine: number;
296
+ /** The call as written, e.g. `ctx.tools.execute` or `deepline.tools.execute`. */
297
+ callee: string;
298
+ };
299
+
300
+ /**
301
+ * What a box's `out:` will record wrong, for each output root this source can
302
+ * prove. Empty when the source does not parse or nothing is wrong.
303
+ */
304
+ export function docflowRecordedOutputProblems(
305
+ binding: Pick<PlayDocflowBinding, 'line' | 'outputs'>,
306
+ source: string,
307
+ indexOf: (source: string) => SourceIndex | null,
308
+ ): DocflowRecordedOutputProblem[] {
309
+ const outputs = binding.outputs ?? [];
310
+ if (outputs.length === 0) return [];
311
+ const index = indexOf(source);
312
+ if (!index) return [];
313
+ const statement = boundStatementAt(index, binding.line);
314
+ const statementEnd = statement
315
+ ? end(statement)
316
+ : (index.lineStarts[binding.line] ?? Number.POSITIVE_INFINITY);
317
+ const problems: DocflowRecordedOutputProblem[] = [];
318
+ const seen = new Set<string>();
319
+ for (const path of outputs) {
320
+ const name = path.split('.')[0]!;
321
+ if (!name || name === '$output' || seen.has(name)) continue;
322
+ seen.add(name);
323
+ const declarator = declaratorFor(index, name, statementEnd);
324
+ if (!declarator) continue;
325
+ const init = isAstNode(declarator.init) ? declarator.init : null;
326
+ // Only the whole value: `out:"lookup.data.email"` reads a getter and
327
+ // records the field.
328
+ if (path === name && isToolExecuteCall(init)) {
329
+ const call = unwrap(init)!;
330
+ const callee = isAstNode(call.callee)
331
+ ? source.slice(start(call.callee), end(call.callee))
332
+ : 'ctx.tools.execute';
333
+ problems.push({
334
+ kind: 'tool_result',
335
+ name,
336
+ declarationLine: lineOf(index, start(declarator)),
337
+ callee: callee.replace(/\s+/g, ''),
338
+ });
339
+ continue;
340
+ }
341
+ const emptyAs = isEmptyCollection(init);
342
+ if (!emptyAs) continue;
343
+ const mutation = firstMutationAfter(
344
+ index,
345
+ name,
346
+ statementEnd,
347
+ scopeEndOf(index, declarator),
348
+ );
349
+ if (!mutation) continue;
350
+ problems.push({
351
+ kind: 'filled_after',
352
+ name,
353
+ emptyAs,
354
+ declarationLine: lineOf(index, start(declarator)),
355
+ mutationLine: lineOf(index, start(mutation)),
356
+ });
357
+ }
358
+ return problems;
359
+ }
360
+
361
+ const NOT_AN_INPUT = new Set([
362
+ 'ctx',
363
+ 'deepline',
364
+ 'undefined',
365
+ 'console',
366
+ 'JSON',
367
+ 'Math',
368
+ 'Object',
369
+ 'Array',
370
+ 'String',
371
+ 'Number',
372
+ 'Boolean',
373
+ 'Promise',
374
+ 'Date',
375
+ 'Map',
376
+ 'Set',
377
+ ]);
378
+
379
+ /**
380
+ * The names a bound statement reads that the file declares elsewhere: the
381
+ * `in:` it should declare. Empty when the source does not parse; capped, since
382
+ * it is a suggestion in a message.
383
+ */
384
+ export function docflowStatementReads(
385
+ line: number,
386
+ source: string,
387
+ indexOf: (source: string) => SourceIndex | null,
388
+ limit = 4,
389
+ ): string[] {
390
+ const index = indexOf(source);
391
+ if (!index) return [];
392
+ const statement = boundStatementAt(index, line);
393
+ if (!statement) return [];
394
+ const declaredInFile = new Set<string>();
395
+ const declaredInStatement = new Set<string>();
396
+ const declare = (pattern: unknown, into: Set<string>) => {
397
+ if (!isAstNode(pattern)) return;
398
+ for (const node of walk(pattern)) {
399
+ const name = identifierName(node);
400
+ if (name) into.add(name);
401
+ }
402
+ };
403
+ // Code and configuration, not values a step started from: functions (a
404
+ // helper the step calls or passes) and module-level literal constants.
405
+ const notValues = new Set<string>();
406
+ const moduleLevel = new Set<AstNode>();
407
+ for (const top of astArray(index.ast.body)) {
408
+ const declaration =
409
+ top.type === 'ExportNamedDeclaration' && isAstNode(top.declaration)
410
+ ? top.declaration
411
+ : top;
412
+ // A module-level constant written as a literal is configuration
413
+ // (`LIMIT`, `DEFAULT_COLUMNS`). A module-level value computed at run time
414
+ // (a script Play's top-level step) is still a value.
415
+ if (
416
+ declaration.type === 'VariableDeclaration' &&
417
+ declaration.kind === 'const'
418
+ ) {
419
+ for (const declarator of astArray(declaration.declarations)) {
420
+ const init = unwrap(
421
+ isAstNode(declarator.init) ? declarator.init : null,
422
+ );
423
+ if (
424
+ init &&
425
+ (init.type === 'Literal' ||
426
+ init.type === 'TemplateLiteral' ||
427
+ init.type === 'ArrayExpression' ||
428
+ init.type === 'ObjectExpression' ||
429
+ init.type === 'UnaryExpression')
430
+ ) {
431
+ moduleLevel.add(declarator);
432
+ }
433
+ }
434
+ }
435
+ if (declaration.type === 'FunctionDeclaration') {
436
+ const name = identifierName(declaration.id);
437
+ if (name) notValues.add(name);
438
+ }
439
+ }
440
+ for (const node of walk(index.ast)) {
441
+ if (node.type === 'FunctionDeclaration') {
442
+ const name = identifierName(node.id);
443
+ if (name) notValues.add(name);
444
+ }
445
+ if (node.type !== 'VariableDeclarator') continue;
446
+ const name = identifierName(node.id);
447
+ if (!name) continue;
448
+ const init = unwrap(isAstNode(node.init) ? node.init : null);
449
+ const isFunction =
450
+ init?.type === 'ArrowFunctionExpression' ||
451
+ init?.type === 'FunctionExpression';
452
+ if (isFunction || moduleLevel.has(node)) notValues.add(name);
453
+ }
454
+ for (const node of walk(index.ast)) {
455
+ const inside =
456
+ start(node) >= start(statement) && end(node) <= end(statement);
457
+ const into = inside ? declaredInStatement : declaredInFile;
458
+ if (node.type === 'VariableDeclarator') declare(node.id, into);
459
+ if (
460
+ node.type === 'FunctionDeclaration' ||
461
+ node.type === 'FunctionExpression' ||
462
+ node.type === 'ArrowFunctionExpression'
463
+ ) {
464
+ for (const param of astArray(node.params)) declare(param, into);
465
+ }
466
+ }
467
+ // Names that are only a property key or member name are not reads.
468
+ const keys = new Set<AstNode>();
469
+ for (const node of walk(statement)) {
470
+ if (
471
+ node.type === 'MemberExpression' &&
472
+ !node.computed &&
473
+ isAstNode(node.property)
474
+ ) {
475
+ keys.add(node.property);
476
+ }
477
+ if (
478
+ (node.type === 'Property' || node.type === 'PropertyDefinition') &&
479
+ !node.computed &&
480
+ !node.shorthand &&
481
+ isAstNode(node.key)
482
+ ) {
483
+ keys.add(node.key);
484
+ }
485
+ if (node.type === 'VariableDeclarator' && isAstNode(node.id)) {
486
+ for (const bound of walk(node.id)) keys.add(bound);
487
+ }
488
+ // A called helper is code, not a value the step reads.
489
+ if (
490
+ (node.type === 'CallExpression' || node.type === 'NewExpression') &&
491
+ isAstNode(node.callee) &&
492
+ node.callee.type === 'Identifier'
493
+ ) {
494
+ keys.add(node.callee);
495
+ }
496
+ }
497
+ const reads: Array<{ name: string; at: number }> = [];
498
+ const seen = new Set<string>();
499
+ for (const node of walk(statement)) {
500
+ if (keys.has(node)) continue;
501
+ const name = identifierName(node);
502
+ if (!name || seen.has(name) || NOT_AN_INPUT.has(name)) continue;
503
+ if (!declaredInFile.has(name) || declaredInStatement.has(name)) continue;
504
+ if (notValues.has(name)) continue;
505
+ seen.add(name);
506
+ reads.push({ name, at: start(node) });
507
+ }
508
+ return reads
509
+ .sort((left, right) => left.at - right.at)
510
+ .slice(0, limit)
511
+ .map((read) => read.name);
512
+ }