deepline 0.3.583 → 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.
- package/dist/bundling-sources/sdk/src/client-core.ts +79 -36
- package/dist/bundling-sources/sdk/src/index.ts +2 -0
- package/dist/bundling-sources/sdk/src/release.ts +7 -3
- package/dist/bundling-sources/sdk/src/types.ts +37 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +22 -3
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +94 -5
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +66 -12
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -0
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/runtime-topology.ts +6 -1
- package/dist/bundling-sources/shared_libs/play-runtime/deployment/runtime-tuple-recovery.ts +9 -3
- package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +86 -20
- package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +17 -6
- package/dist/bundling-sources/shared_libs/play-runtime/freshness-receipt-execution.ts +22 -6
- package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +54 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/postgres-adapter.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/row-failure-summary.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +4 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +12 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +197 -19
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-writer.ts +25 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +73 -3
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-wake-policy.ts +419 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +20 -6
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +24 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +36 -19
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +380 -51
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +21 -10
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts +32 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -0
- package/dist/bundling-sources/shared_libs/plays/deploy/api-client.ts +3 -1
- package/dist/bundling-sources/shared_libs/plays/deploy/run-deployment.ts +34 -4
- package/dist/bundling-sources/shared_libs/plays/docflow-recording-lint.ts +512 -0
- package/dist/bundling-sources/shared_libs/plays/docflow-requirement.ts +346 -0
- package/dist/bundling-sources/shared_libs/plays/docflow-rule-codes.ts +38 -0
- package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +42 -2
- package/dist/bundling-sources/shared_libs/plays/docflow.ts +223 -32
- package/dist/bundling-sources/shared_libs/plays/play-check-compact.ts +14 -1
- package/dist/bundling-sources/shared_libs/plays/run-result.ts +35 -0
- package/dist/cli/{agents-G344SPW2.mjs → agents-AHXB7N7Y.mjs} +4 -4
- package/dist/cli/{agents-ZPDXVPEE.js → agents-KBZ7OUZS.js} +33 -33
- package/dist/cli/{auth-V66RP2A6.mjs → auth-3CACO52T.mjs} +5 -5
- package/dist/cli/auth-UOHCO5K6.js +44 -0
- package/dist/cli/{billing-ROYUQF67.js → billing-5KXPGKMO.js} +105 -105
- package/dist/cli/{billing-BTMGZJCR.mjs → billing-TSTK63NB.mjs} +9 -9
- package/dist/cli/{chunk-ROWROMXD.mjs → chunk-2GWKBQJZ.mjs} +1 -1
- package/dist/cli/{chunk-VXEZKZU4.mjs → chunk-3DJMPID5.mjs} +11 -11
- package/dist/cli/{chunk-VH45GV3T.js → chunk-3ET6NRXP.js} +7 -3
- package/dist/cli/{chunk-43MKV6E4.mjs → chunk-3MWTAM3F.mjs} +3 -3
- package/dist/cli/{chunk-U6BTY4WS.mjs → chunk-4ANDW2OT.mjs} +1 -1
- package/dist/cli/{chunk-H4BYWEV5.js → chunk-4BSCSQ6I.js} +4 -4
- package/dist/cli/{chunk-ACS6BYE5.mjs → chunk-4UEXAMDU.mjs} +2 -2
- package/dist/cli/{chunk-QPN662ZP.js → chunk-5XGLDVSD.js} +100 -100
- package/dist/cli/{chunk-MFPHCUHK.js → chunk-7XXJJVSI.js} +5 -5
- package/dist/cli/{chunk-QGOHEJVJ.js → chunk-7ZCD7OPO.js} +5 -5
- package/dist/cli/{chunk-AXKFZIXC.mjs → chunk-AJJSKKH4.mjs} +2 -2
- package/dist/cli/{chunk-KSXBLXLV.mjs → chunk-BHF5UW34.mjs} +1 -1
- package/dist/cli/{chunk-AHQDUMDM.js → chunk-BO2TXH5Y.js} +20 -20
- package/dist/cli/{chunk-W5WLWRKL.mjs → chunk-BUC2TNF2.mjs} +2 -2
- package/dist/cli/{chunk-6GYGMWQV.js → chunk-BUUAFSSN.js} +68 -50
- package/dist/cli/{chunk-WUVDJSZE.js → chunk-C45E47KC.js} +23 -23
- package/dist/cli/{chunk-BUMCOVBP.js → chunk-D4R3AL4F.js} +5 -5
- package/dist/cli/{chunk-PVDP3AZY.mjs → chunk-DAZRIAXW.mjs} +4 -4
- package/dist/cli/{chunk-W3ECB7GC.js → chunk-DNOZQGJF.js} +3 -3
- package/dist/cli/{chunk-HYT5B2NL.js → chunk-DUL6UQ2T.js} +2 -2
- package/dist/cli/{chunk-P2YNTAGL.mjs → chunk-ES3S6UXR.mjs} +2 -2
- package/dist/cli/{chunk-K6GDSCFL.mjs → chunk-FDAYUP3M.mjs} +3 -3
- package/dist/cli/{chunk-23LYXVI4.js → chunk-FEVUIT2U.js} +6 -6
- package/dist/cli/{chunk-6S3OAJCJ.mjs → chunk-FSPEUU3V.mjs} +49 -6
- package/dist/cli/{chunk-2QIVGZKS.mjs → chunk-FZZMCVOS.mjs} +5 -5
- package/dist/cli/{chunk-73IZARR5.js → chunk-GHOB72U6.js} +13 -13
- package/dist/cli/{chunk-LVJAHM2I.mjs → chunk-GLYWRTEL.mjs} +3 -3
- package/dist/cli/{chunk-AXOQ2FMS.mjs → chunk-HNTIGYRT.mjs} +1 -1
- package/dist/cli/{chunk-C7UCDL2K.js → chunk-IGPHYKEJ.js} +41 -41
- package/dist/cli/{chunk-PULU5YGX.js → chunk-ISSYN3DJ.js} +20 -20
- package/dist/cli/{chunk-ZHIJA4MW.mjs → chunk-JKQPITEE.mjs} +54 -36
- package/dist/cli/{chunk-EHV52KUV.mjs → chunk-KMLACXI2.mjs} +7 -3
- package/dist/cli/{chunk-WAZR72D5.js → chunk-KQXACHYA.js} +26 -26
- package/dist/cli/{chunk-PGUK5VPC.js → chunk-LW2GKYZW.js} +2 -2
- package/dist/cli/{chunk-J54DMFV5.mjs → chunk-O2KSPI2M.mjs} +2 -2
- package/dist/cli/{chunk-CCC3NIYB.js → chunk-O6GT6JD7.js} +9 -9
- package/dist/cli/{chunk-DNYFNOWG.mjs → chunk-OCXWUWUI.mjs} +5 -5
- package/dist/cli/{chunk-MEAWK5G7.js → chunk-QKRDAJ3T.js} +53 -53
- package/dist/cli/{chunk-N5XRUZRS.js → chunk-QQESWF6D.js} +16 -16
- package/dist/cli/{chunk-2D5YISAL.js → chunk-REX5SUYU.js} +2 -2
- package/dist/cli/{chunk-RO2LTLJA.js → chunk-RXIQWG2N.js} +48 -48
- package/dist/cli/{chunk-VXDKL434.js → chunk-S33BN7GZ.js} +3 -3
- package/dist/cli/{chunk-72MEXMSH.mjs → chunk-SGRJJLNV.mjs} +1 -1
- package/dist/cli/{chunk-HOGRT5X6.mjs → chunk-TCNYSNVU.mjs} +1 -1
- package/dist/cli/{chunk-H7F3ROT3.mjs → chunk-TFPMVSGK.mjs} +2 -2
- package/dist/cli/{chunk-GFX6CDAB.mjs → chunk-V73WDQEA.mjs} +5 -5
- package/dist/cli/{chunk-LHD3HOYN.js → chunk-VYERVFGB.js} +49 -6
- package/dist/cli/{chunk-C233ZRNX.mjs → chunk-WBRSVML3.mjs} +4 -4
- package/dist/cli/{chunk-7AFTLM74.mjs → chunk-WW52ANX4.mjs} +2 -2
- package/dist/cli/{chunk-ZFJNIZHI.js → chunk-XZS35M3Y.js} +10 -10
- package/dist/cli/{chunk-YRNWA2IL.js → chunk-YNYHYL5C.js} +15 -15
- package/dist/cli/{chunk-JQT3SHXL.mjs → chunk-ZHE5E2WJ.mjs} +1 -1
- package/dist/cli/{chunk-N5RCXI3M.mjs → chunk-ZJ2H77VV.mjs} +5 -5
- package/dist/cli/{chunk-GQHZV7EQ.js → chunk-ZX6UVPGZ.js} +7 -7
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/concurrent-runs-help-H5SZUA5J.js +22 -0
- package/dist/cli/{concurrent-runs-help-A2Y33OQ5.mjs → concurrent-runs-help-IYELSCHB.mjs} +6 -6
- package/dist/cli/{csv-PS74WVXE.mjs → csv-ENEC3APZ.mjs} +4 -4
- package/dist/cli/{csv-TKSR2LFV.js → csv-X6CP57R4.js} +13 -13
- package/dist/cli/{db-R6GOM4VC.js → db-6HLRSE2M.js} +27 -27
- package/dist/cli/{db-EXLBRZ7K.mjs → db-YGKRFK4T.mjs} +6 -6
- package/dist/cli/{describe-JJBXFPVQ.mjs → describe-4SGQEX7K.mjs} +18 -18
- package/dist/cli/describe-Q2OYHDVZ.js +50 -0
- package/dist/cli/describe-core.d.mts +2 -2
- package/dist/cli/describe-core.d.ts +2 -2
- package/dist/cli/{executions-474U7R3Y.js → executions-IC55YJ67.js} +8 -8
- package/dist/cli/{executions-5PEODJQG.mjs → executions-PO2IOSZ7.mjs} +6 -6
- package/dist/cli/{feedback-QUQVRDBD.mjs → feedback-6BUD5F4I.mjs} +6 -6
- package/dist/cli/{feedback-URTCAOXP.js → feedback-BCGQLZ5T.js} +14 -14
- package/dist/cli/git-5X3MLBIP.js +26 -0
- package/dist/cli/{git-AQF23KKU.mjs → git-IN4IBL2K.mjs} +5 -5
- package/dist/cli/index.js +148 -148
- package/dist/cli/index.mjs +47 -47
- package/dist/cli/{integrations-NMFOOSS4.js → integrations-R2Z2MDO3.js} +29 -29
- package/dist/cli/{integrations-5POBI72U.mjs → integrations-ZMGB6NQA.mjs} +7 -7
- package/dist/cli/{legacy-noops-6YVCOSFO.mjs → legacy-noops-GIC5OZKP.mjs} +6 -6
- package/dist/cli/{legacy-noops-V75T5LHV.js → legacy-noops-X4JPRPTJ.js} +9 -9
- package/dist/cli/{mcp-7WEYQ5V7.mjs → mcp-G4IRJIKK.mjs} +4 -4
- package/dist/cli/{mcp-N6GYXCUQ.js → mcp-USZKTVL2.js} +24 -24
- package/dist/cli/{monitors-TAK4M5Y4.mjs → monitors-SNFZPSCY.mjs} +7 -7
- package/dist/cli/{monitors-HW4H4PE5.js → monitors-T7LRP7OB.js} +100 -100
- package/dist/cli/{org-FULXOXNE.js → org-2L2ZZL2P.js} +121 -121
- package/dist/cli/{org-3C2RN36N.mjs → org-YTXLKW52.mjs} +6 -6
- package/dist/cli/{outcomes-4KRZL6OL.mjs → outcomes-CJWBIFTA.mjs} +6 -6
- package/dist/cli/{outcomes-O3HDQWGN.js → outcomes-O63F57JF.js} +14 -14
- package/dist/cli/{play-ZTRWUODW.mjs → play-6UWPUHC6.mjs} +331 -70
- package/dist/cli/{play-HA4RGX7T.js → play-T353SULJ.js} +930 -669
- package/dist/cli/{providers-FAKWWJE2.mjs → providers-LZABK2UW.mjs} +6 -6
- package/dist/cli/{providers-DXMKWBZN.js → providers-XORJH2VW.js} +9 -9
- package/dist/cli/{quickstart-YWGBTW77.mjs → quickstart-O4RF7J55.mjs} +4 -4
- package/dist/cli/{quickstart-MA74UPNI.js → quickstart-QBNUNPZR.js} +6 -6
- package/dist/cli/{run-4DXSGXRB.js → run-2CPMFC6W.js} +44 -44
- package/dist/cli/{run-QHCYMSBP.mjs → run-GBRPFC6P.mjs} +23 -23
- package/dist/cli/{search-N4ZOK5XX.mjs → search-G7TS7OFB.mjs} +7 -7
- package/dist/cli/search-M3AHFCKQ.js +32 -0
- package/dist/cli/{search-output-F2OYLVK2.mjs → search-output-BIIJRUCP.mjs} +4 -4
- package/dist/cli/{search-output-D5VAC52B.js → search-output-NRKLNWSD.js} +6 -6
- package/dist/cli/{secrets-LD4FVAQI.mjs → secrets-DN3XEZNH.mjs} +6 -6
- package/dist/cli/{secrets-3KETOTDS.js → secrets-FUXYSEL5.js} +15 -15
- package/dist/cli/{sessions-LPLI4Z4O.mjs → sessions-PMUTPCTT.mjs} +6 -6
- package/dist/cli/sessions-VMBMBGVJ.js +23 -0
- package/dist/cli/{settings-NCGPJG3Z.mjs → settings-N6GNS2KA.mjs} +12 -12
- package/dist/cli/{settings-NFBTCOMB.js → settings-ZDTWCQ6B.js} +85 -85
- package/dist/cli/{setup-NH6MRYXZ.mjs → setup-LJ3KWPSA.mjs} +9 -9
- package/dist/cli/{setup-ATBSUSH4.js → setup-PN5TSSJE.js} +49 -49
- package/dist/cli/{skills-ITPBPIXD.mjs → skills-7J42K6VC.mjs} +7 -7
- package/dist/cli/skills-CXDENBLF.js +37 -0
- package/dist/cli/{tools-2XZPR65V.mjs → tools-M3S6D6DA.mjs} +17 -17
- package/dist/cli/tools-WY2GMOC7.js +57 -0
- package/dist/cli/{update-VFB22FWO.mjs → update-XTVFG74E.mjs} +9 -9
- package/dist/cli/update-ZB2IBGXG.js +37 -0
- package/dist/cli/{views-WJUZOQM2.js → views-B4X2FWTF.js} +21 -21
- package/dist/cli/{views-MRN3HWTG.mjs → views-UFYRDO4X.mjs} +6 -6
- package/dist/cli/{workflow-Q4JFBTVH.js → workflow-I2RM2J2J.js} +17 -17
- package/dist/cli/{workflow-A6P7YV5W.mjs → workflow-ZLMS3PDE.mjs} +7 -7
- package/dist/{client-QznpkWrk.d.ts → client-2QWMJInp.d.ts} +1 -1
- package/dist/{client-CmG8MT0x.d.mts → client-7H8TXmLa.d.mts} +1 -1
- package/dist/{client-core-CY0jNW0e.d.mts → client-core-BraEuxbg.d.mts} +67 -4
- package/dist/{client-core-CXDqfeiB.d.ts → client-core-DRglY5xa.d.ts} +67 -4
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +9 -9
- package/dist/index.mjs +6 -6
- package/dist/install-integrity.json +125 -120
- package/dist/plays/bundle-play-file.mjs +5 -0
- package/dist/plays/play-description.d.mts +1 -1
- package/dist/plays/play-description.d.ts +1 -1
- package/dist/plays/run-request.d.mts +1 -1
- package/dist/plays/run-request.d.ts +1 -1
- package/dist/release.d.mts +3 -3
- package/dist/release.d.ts +3 -3
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +5 -5
- package/dist/server.mjs +3 -3
- package/package.json +1 -1
- package/dist/cli/auth-VU6VIPVY.js +0 -44
- package/dist/cli/concurrent-runs-help-6WUNDV77.js +0 -22
- package/dist/cli/describe-CA2FL2OS.js +0 -50
- package/dist/cli/git-WJ4V2B4T.js +0 -26
- package/dist/cli/search-V765JH2H.js +0 -32
- package/dist/cli/sessions-XC65OMDS.js +0 -23
- package/dist/cli/skills-4NQBTGOL.js +0 -37
- package/dist/cli/tools-ZVOFATX2.js +0 -57
- package/dist/cli/update-QME3KPOP.js +0 -37
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts
CHANGED
|
@@ -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 =
|
|
1130
|
-
client,
|
|
1131
|
-
|
|
1132
|
-
|
|
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
|
-
|
|
1151
|
-
|
|
1152
|
-
{ keys },
|
|
1153
|
-
|
|
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,
|
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-worker-wake.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
946
|
-
|
|
947
|
-
|
|
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
|
+
}
|