primitive-admin 1.1.0-alpha.4 → 1.1.0-alpha.41

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 (219) hide show
  1. package/README.md +325 -31
  2. package/assets/skill/skills/primitive-platform/SKILL.md +281 -0
  3. package/dist/bin/primitive.d.ts +2 -0
  4. package/dist/bin/primitive.js +268 -16
  5. package/dist/bin/primitive.js.map +1 -1
  6. package/dist/src/commands/admins.d.ts +2 -0
  7. package/dist/src/commands/admins.js +123 -18
  8. package/dist/src/commands/admins.js.map +1 -1
  9. package/dist/src/commands/analytics.d.ts +2 -0
  10. package/dist/src/commands/analytics.js +464 -55
  11. package/dist/src/commands/analytics.js.map +1 -1
  12. package/dist/src/commands/apps.d.ts +2 -0
  13. package/dist/src/commands/apps.js +55 -13
  14. package/dist/src/commands/apps.js.map +1 -1
  15. package/dist/src/commands/auth.d.ts +2 -0
  16. package/dist/src/commands/auth.js +177 -7
  17. package/dist/src/commands/auth.js.map +1 -1
  18. package/dist/src/commands/blob-buckets.d.ts +2 -0
  19. package/dist/src/commands/blob-buckets.js +422 -0
  20. package/dist/src/commands/blob-buckets.js.map +1 -0
  21. package/dist/src/commands/catalog.d.ts +2 -0
  22. package/dist/src/commands/catalog.js +34 -35
  23. package/dist/src/commands/catalog.js.map +1 -1
  24. package/dist/src/commands/collection-type-configs.d.ts +2 -0
  25. package/dist/src/commands/collection-type-configs.js +178 -0
  26. package/dist/src/commands/collection-type-configs.js.map +1 -0
  27. package/dist/src/commands/collections.d.ts +2 -0
  28. package/dist/src/commands/collections.js +515 -0
  29. package/dist/src/commands/collections.js.map +1 -0
  30. package/dist/src/commands/comparisons.d.ts +2 -0
  31. package/dist/src/commands/comparisons.js +6 -6
  32. package/dist/src/commands/comparisons.js.map +1 -1
  33. package/dist/src/commands/cron-triggers.d.ts +2 -0
  34. package/dist/src/commands/cron-triggers.js +357 -0
  35. package/dist/src/commands/cron-triggers.js.map +1 -0
  36. package/dist/src/commands/database-types.d.ts +2 -0
  37. package/dist/src/commands/database-types.js +471 -0
  38. package/dist/src/commands/database-types.js.map +1 -0
  39. package/dist/src/commands/databases.d.ts +2 -0
  40. package/dist/src/commands/databases.js +1462 -83
  41. package/dist/src/commands/databases.js.map +1 -1
  42. package/dist/src/commands/documents.d.ts +2 -0
  43. package/dist/src/commands/documents.js +518 -11
  44. package/dist/src/commands/documents.js.map +1 -1
  45. package/dist/src/commands/email-templates.d.ts +2 -0
  46. package/dist/src/commands/email-templates.js +281 -0
  47. package/dist/src/commands/email-templates.js.map +1 -0
  48. package/dist/src/commands/env.d.ts +12 -0
  49. package/dist/src/commands/env.js +260 -0
  50. package/dist/src/commands/env.js.map +1 -0
  51. package/dist/src/commands/group-type-configs.d.ts +2 -0
  52. package/dist/src/commands/group-type-configs.js +181 -0
  53. package/dist/src/commands/group-type-configs.js.map +1 -0
  54. package/dist/src/commands/groups.d.ts +2 -0
  55. package/dist/src/commands/groups.js +48 -45
  56. package/dist/src/commands/groups.js.map +1 -1
  57. package/dist/src/commands/guides.d.ts +159 -0
  58. package/dist/src/commands/guides.js +449 -35
  59. package/dist/src/commands/guides.js.map +1 -1
  60. package/dist/src/commands/init.d.ts +17 -0
  61. package/dist/src/commands/init.js +811 -201
  62. package/dist/src/commands/init.js.map +1 -1
  63. package/dist/src/commands/integrations.d.ts +2 -0
  64. package/dist/src/commands/integrations.js +533 -46
  65. package/dist/src/commands/integrations.js.map +1 -1
  66. package/dist/src/commands/llm.d.ts +2 -0
  67. package/dist/src/commands/llm.js +4 -2
  68. package/dist/src/commands/llm.js.map +1 -1
  69. package/dist/src/commands/metadata.d.ts +2 -0
  70. package/dist/src/commands/metadata.js +194 -0
  71. package/dist/src/commands/metadata.js.map +1 -0
  72. package/dist/src/commands/prompts.d.ts +2 -0
  73. package/dist/src/commands/prompts.js +50 -52
  74. package/dist/src/commands/prompts.js.map +1 -1
  75. package/dist/src/commands/rule-sets.d.ts +3 -0
  76. package/dist/src/commands/rule-sets.js +388 -0
  77. package/dist/src/commands/rule-sets.js.map +1 -0
  78. package/dist/src/commands/scripts.d.ts +2 -0
  79. package/dist/src/commands/scripts.js +667 -0
  80. package/dist/src/commands/scripts.js.map +1 -0
  81. package/dist/src/commands/secrets.d.ts +2 -0
  82. package/dist/src/commands/secrets.js +108 -0
  83. package/dist/src/commands/secrets.js.map +1 -0
  84. package/dist/src/commands/skill.d.ts +2 -0
  85. package/dist/src/commands/skill.js +29 -0
  86. package/dist/src/commands/skill.js.map +1 -0
  87. package/dist/src/commands/sync.d.ts +175 -0
  88. package/dist/src/commands/sync.js +4412 -233
  89. package/dist/src/commands/sync.js.map +1 -1
  90. package/dist/src/commands/tokens.d.ts +2 -0
  91. package/dist/src/commands/tokens.js +122 -19
  92. package/dist/src/commands/tokens.js.map +1 -1
  93. package/dist/src/commands/users.d.ts +2 -0
  94. package/dist/src/commands/users.js +440 -22
  95. package/dist/src/commands/users.js.map +1 -1
  96. package/dist/src/commands/waitlist.d.ts +2 -0
  97. package/dist/src/commands/waitlist.js +10 -10
  98. package/dist/src/commands/waitlist.js.map +1 -1
  99. package/dist/src/commands/webhooks.d.ts +2 -0
  100. package/dist/src/commands/webhooks.js +391 -0
  101. package/dist/src/commands/webhooks.js.map +1 -0
  102. package/dist/src/commands/workflows.d.ts +49 -0
  103. package/dist/src/commands/workflows.js +1009 -123
  104. package/dist/src/commands/workflows.js.map +1 -1
  105. package/dist/src/lib/api-client.d.ts +1283 -0
  106. package/dist/src/lib/api-client.js +1129 -83
  107. package/dist/src/lib/api-client.js.map +1 -1
  108. package/dist/src/lib/auth-flow.d.ts +8 -0
  109. package/dist/src/lib/block-layout.d.ts +160 -0
  110. package/dist/src/lib/block-layout.js +451 -0
  111. package/dist/src/lib/block-layout.js.map +1 -0
  112. package/dist/src/lib/cli-manifest.d.ts +60 -0
  113. package/dist/src/lib/cli-manifest.js +70 -0
  114. package/dist/src/lib/cli-manifest.js.map +1 -0
  115. package/dist/src/lib/config.d.ts +53 -0
  116. package/dist/src/lib/config.js +92 -53
  117. package/dist/src/lib/config.js.map +1 -1
  118. package/dist/src/lib/confirm-prompt.d.ts +83 -0
  119. package/dist/src/lib/confirm-prompt.js +110 -0
  120. package/dist/src/lib/confirm-prompt.js.map +1 -0
  121. package/dist/src/lib/constants.d.ts +2 -0
  122. package/dist/src/lib/constants.js +3 -0
  123. package/dist/src/lib/constants.js.map +1 -0
  124. package/dist/src/lib/crash-handlers.d.ts +20 -0
  125. package/dist/src/lib/crash-handlers.js +49 -0
  126. package/dist/src/lib/crash-handlers.js.map +1 -0
  127. package/dist/src/lib/credentials-store.d.ts +79 -0
  128. package/dist/src/lib/credentials-store.js +307 -0
  129. package/dist/src/lib/credentials-store.js.map +1 -0
  130. package/dist/src/lib/csv.d.ts +48 -0
  131. package/dist/src/lib/csv.js +177 -0
  132. package/dist/src/lib/csv.js.map +1 -0
  133. package/dist/src/lib/db-codegen/dbFingerprint.d.ts +10 -0
  134. package/dist/src/lib/db-codegen/dbFingerprint.js +17 -0
  135. package/dist/src/lib/db-codegen/dbFingerprint.js.map +1 -0
  136. package/dist/src/lib/db-codegen/dbGenerator.d.ts +111 -0
  137. package/dist/src/lib/db-codegen/dbGenerator.js +371 -0
  138. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -0
  139. package/dist/src/lib/db-codegen/dbNaming.d.ts +45 -0
  140. package/dist/src/lib/db-codegen/dbNaming.js +104 -0
  141. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -0
  142. package/dist/src/lib/db-codegen/dbTemplates.d.ts +97 -0
  143. package/dist/src/lib/db-codegen/dbTemplates.js +159 -0
  144. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -0
  145. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +78 -0
  146. package/dist/src/lib/db-codegen/dbTsTypes.js +112 -0
  147. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -0
  148. package/dist/src/lib/env-resolver.d.ts +62 -0
  149. package/dist/src/lib/env-resolver.js +121 -0
  150. package/dist/src/lib/env-resolver.js.map +1 -0
  151. package/dist/src/lib/fetch.d.ts +5 -0
  152. package/dist/src/lib/generated-allowlist.d.ts +28 -0
  153. package/dist/src/lib/generated-allowlist.js +220 -0
  154. package/dist/src/lib/generated-allowlist.js.map +1 -0
  155. package/dist/src/lib/init-config.d.ts +59 -0
  156. package/dist/src/lib/init-config.js +113 -0
  157. package/dist/src/lib/init-config.js.map +1 -0
  158. package/dist/src/lib/migration-nag.d.ts +49 -0
  159. package/dist/src/lib/migration-nag.js +163 -0
  160. package/dist/src/lib/migration-nag.js.map +1 -0
  161. package/dist/src/lib/output.d.ts +86 -0
  162. package/dist/src/lib/output.js +150 -8
  163. package/dist/src/lib/output.js.map +1 -1
  164. package/dist/src/lib/paginate.d.ts +33 -0
  165. package/dist/src/lib/paginate.js +42 -0
  166. package/dist/src/lib/paginate.js.map +1 -0
  167. package/dist/src/lib/project-config.d.ts +97 -0
  168. package/dist/src/lib/project-config.js +209 -0
  169. package/dist/src/lib/project-config.js.map +1 -0
  170. package/dist/src/lib/query-operators.d.ts +43 -0
  171. package/dist/src/lib/query-operators.js +80 -0
  172. package/dist/src/lib/query-operators.js.map +1 -0
  173. package/dist/src/lib/refresh-admin-credentials.d.ts +65 -0
  174. package/dist/src/lib/refresh-admin-credentials.js +103 -0
  175. package/dist/src/lib/refresh-admin-credentials.js.map +1 -0
  176. package/dist/src/lib/resolve-platform.d.ts +45 -0
  177. package/dist/src/lib/resolve-platform.js +43 -0
  178. package/dist/src/lib/resolve-platform.js.map +1 -0
  179. package/dist/src/lib/skill-installer.d.ts +23 -0
  180. package/dist/src/lib/skill-installer.js +135 -0
  181. package/dist/src/lib/skill-installer.js.map +1 -0
  182. package/dist/src/lib/snapshots.d.ts +99 -0
  183. package/dist/src/lib/snapshots.js +357 -0
  184. package/dist/src/lib/snapshots.js.map +1 -0
  185. package/dist/src/lib/sync-paths.d.ts +72 -0
  186. package/dist/src/lib/sync-paths.js +130 -0
  187. package/dist/src/lib/sync-paths.js.map +1 -0
  188. package/dist/src/lib/template.d.ts +97 -0
  189. package/dist/src/lib/template.js +336 -62
  190. package/dist/src/lib/template.js.map +1 -1
  191. package/dist/src/lib/token-inject.d.ts +56 -0
  192. package/dist/src/lib/token-inject.js +204 -0
  193. package/dist/src/lib/token-inject.js.map +1 -0
  194. package/dist/src/lib/toml-database-config.d.ts +152 -0
  195. package/dist/src/lib/toml-database-config.js +600 -0
  196. package/dist/src/lib/toml-database-config.js.map +1 -0
  197. package/dist/src/lib/toml-metadata-config.d.ts +139 -0
  198. package/dist/src/lib/toml-metadata-config.js +427 -0
  199. package/dist/src/lib/toml-metadata-config.js.map +1 -0
  200. package/dist/src/lib/toml-params-validator.d.ts +129 -0
  201. package/dist/src/lib/toml-params-validator.js +298 -0
  202. package/dist/src/lib/toml-params-validator.js.map +1 -0
  203. package/dist/src/lib/version-check.d.ts +10 -0
  204. package/dist/src/lib/version-check.js +172 -0
  205. package/dist/src/lib/version-check.js.map +1 -0
  206. package/dist/src/lib/workflow-apply.d.ts +66 -0
  207. package/dist/src/lib/workflow-apply.js +117 -0
  208. package/dist/src/lib/workflow-apply.js.map +1 -0
  209. package/dist/src/lib/workflow-fragments.d.ts +41 -0
  210. package/dist/src/lib/workflow-fragments.js +121 -0
  211. package/dist/src/lib/workflow-fragments.js.map +1 -0
  212. package/dist/src/lib/workflow-toml-validator.d.ts +95 -0
  213. package/dist/src/lib/workflow-toml-validator.js +323 -0
  214. package/dist/src/lib/workflow-toml-validator.js.map +1 -0
  215. package/dist/src/types/index.d.ts +520 -0
  216. package/dist/src/validators.d.ts +64 -0
  217. package/dist/src/validators.js +63 -0
  218. package/dist/src/validators.js.map +1 -0
  219. package/package.json +18 -4
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Push-time validator for workflow TOML files (issue #685, #998).
3
+ *
4
+ * Detects the common footgun where a user writes `[steps.<id>.<field>]` under
5
+ * an open `[[steps]]` array. TOML parses that as a sub-table on the
6
+ * most-recent step keyed by the step's id (e.g. `steps[0]["refresh-each"]`),
7
+ * not as the intended `steps[0].request`. The result is a step with an
8
+ * unrecognized top-level field — the runtime silently ignores it, and the
9
+ * step then runs with an empty `request` block.
10
+ *
11
+ * The validator walks every step in `tomlData.steps[]`. For a step whose
12
+ * `kind` the CLI KNOWS about, it reports any top-level field not in the
13
+ * generated allowlist. For an UNKNOWN kind (an old CLI run against a newer
14
+ * server that registered a step kind the CLI doesn't have), it SKIPS the
15
+ * per-field allowlist check — but still runs the kind-agnostic
16
+ * misnested-header footgun detector. This is the #998 fix: the recurring
17
+ * "newer server kind → false-reject of valid fields" failure (#685/#802/#971
18
+ * were all false rejections) becomes "unvalidated, not rejected."
19
+ *
20
+ * ── Source of truth (#998) ───────────────────────────────────────────────
21
+ * The allowlist field union and the known-kind set are GENERATED from the
22
+ * server step runners (`src/workflows/steps/*.ts`) and the universal
23
+ * `BaseStepDefinition` shape into the committed
24
+ * `cli/src/lib/generated-allowlist.ts` artifact (the CLI does NOT import
25
+ * server `src/` at runtime — only the build-time generator does). The union is
26
+ * derived from what each runner READS, not what the `*StepDefinition` TYPE
27
+ * declares — types over-declare and would weaken the footgun detector. A CI
28
+ * freshness guard (`gen-allowlist.mjs --check`, also asserted by the #985
29
+ * drift-guard test) keeps the committed artifact in sync with the runners, so
30
+ * the hand-edit drift class (#685/#802/#971) cannot recur for the same-version
31
+ * case. Regenerate with `node cli/scripts/gen-allowlist.mjs`.
32
+ */
33
+ import { GENERATED_ALLOWLISTED_FIELDS, GENERATED_KNOWN_KINDS, } from "./generated-allowlist.js";
34
+ /**
35
+ * Universal-and-consumed allowlist of top-level fields permitted on a step
36
+ * (known kinds). Generated from the runners; see header.
37
+ */
38
+ const ALLOWLISTED_FIELDS = new Set(GENERATED_ALLOWLISTED_FIELDS);
39
+ /**
40
+ * The set of step kinds the CLI knows about (the server's registered kinds at
41
+ * generation time). A step whose `kind` is NOT in this set has its per-field
42
+ * allowlist check skipped — the kind-agnostic footgun detector still runs.
43
+ */
44
+ const KNOWN_KINDS = new Set(GENERATED_KNOWN_KINDS);
45
+ /**
46
+ * Read-only view of `ALLOWLISTED_FIELDS` for the drift-guard test (#985).
47
+ *
48
+ * Exported so `cli/tests/unit/workflow-toml-validator-drift-guard.test.ts` can
49
+ * assert this set stays a superset of every top-level field the step runners
50
+ * in `src/workflows/steps/*.ts` actually read — checking the *live* set the
51
+ * validator enforces rather than a copy that could itself drift. Not part of
52
+ * the public validator API; consumed only by the guard.
53
+ */
54
+ export const ALLOWLISTED_FIELDS_FOR_DRIFT_GUARD = ALLOWLISTED_FIELDS;
55
+ /**
56
+ * Read-only view of `KNOWN_KINDS` for the drift-guard test (#998). Lets the
57
+ * guard assert the generated known-kind set matches a fresh scan.
58
+ */
59
+ export const KNOWN_KINDS_FOR_DRIFT_GUARD = KNOWN_KINDS;
60
+ /**
61
+ * Walk a parsed workflow TOML document and return all unknown-field errors.
62
+ *
63
+ * @param tomlData The output of `TOML.parse()` for a workflow TOML file.
64
+ * @returns An array of error objects, one per offending field. Empty if no
65
+ * errors were found.
66
+ */
67
+ export function validateWorkflowToml(tomlData) {
68
+ const errors = [];
69
+ if (tomlData === null || tomlData === undefined) {
70
+ return errors;
71
+ }
72
+ const steps = tomlData.steps;
73
+ // No steps section at all → nothing to validate. This is fine for
74
+ // partial TOML files (some commands accept a metadata-only file).
75
+ if (steps === undefined || steps === null) {
76
+ return errors;
77
+ }
78
+ // `steps` is a table instead of an array. This typically means the user
79
+ // wrote `[steps.foo]` with no preceding `[[steps]]` array marker, so
80
+ // TOML resolved `steps` to a table. The runtime expects an array — flag
81
+ // it with a clear shape diagnostic.
82
+ if (!Array.isArray(steps)) {
83
+ if (typeof steps === "object") {
84
+ errors.push({
85
+ stepIndex: -1,
86
+ stepId: null,
87
+ field: "__steps_shape__",
88
+ hint: 'The `steps` section is a table, not an array. Workflow TOML expects `[[steps]]` array markers — add `[[steps]]` before any `[steps.<field>]` blocks.',
89
+ });
90
+ }
91
+ else {
92
+ errors.push({
93
+ stepIndex: -1,
94
+ stepId: null,
95
+ field: "__steps_shape__",
96
+ hint: `The \`steps\` section must be an array of step tables (received: ${typeof steps}).`,
97
+ });
98
+ }
99
+ return errors;
100
+ }
101
+ for (let i = 0; i < steps.length; i++) {
102
+ const step = steps[i];
103
+ // Defensive: array entry isn't an object. Should be near-impossible with
104
+ // valid `[[steps]]` syntax, but possible if the user writes `steps =
105
+ // ["a", "b"]`. Surface it so the user gets a diagnostic instead of a
106
+ // silent skip.
107
+ if (step === null || typeof step !== "object" || Array.isArray(step)) {
108
+ errors.push({
109
+ stepIndex: i,
110
+ stepId: null,
111
+ field: "__step_shape__",
112
+ hint: `Each entry in \`steps[]\` must be a table. Got: ${step === null ? "null" : Array.isArray(step) ? "array" : typeof step}.`,
113
+ });
114
+ continue;
115
+ }
116
+ validateStepObject(step, i, /* parentStepId */ null, errors);
117
+ // Codex finding 2 (PR #762, 2026-05-15): a `collect` step's nested
118
+ // `step` field is itself a step definition that the collect runner
119
+ // executes. The outer-step allowlist accepts `step` as a top-level
120
+ // field, but that's a structural pass-through — we need to recurse
121
+ // into the inner step's keys to catch the same misnested-header
122
+ // footgun (e.g. `[steps.step.call.request]` parses as `step.step =
123
+ // { call: { request: {...} } }`, with `call` as an unknown inner
124
+ // field; without the recursion this slips through). We only recurse
125
+ // for `kind === "collect"` — other kinds with a `step`-named field
126
+ // (none today) would need their own audit.
127
+ if (step.kind === "collect" &&
128
+ step.step !== null &&
129
+ typeof step.step === "object" &&
130
+ !Array.isArray(step.step)) {
131
+ const outerStepId = typeof step.id === "string" ? step.id : null;
132
+ validateStepObject(step.step, i, outerStepId, errors);
133
+ }
134
+ }
135
+ return errors;
136
+ }
137
+ /**
138
+ * Validate a single step object's top-level keys against the allowlist and
139
+ * push any errors found onto `errors`. Used for both the top-level
140
+ * `steps[]` walk and the recursive `collect.step` walk.
141
+ *
142
+ * When `parentStepId` is set, the step being validated is the inner step
143
+ * of a `collect`. Errors carry the outer-step context so the rendered
144
+ * diagnostic can point operators at the right slot in the TOML.
145
+ */
146
+ function validateStepObject(step, stepIndex, parentStepId, errors) {
147
+ const stepId = typeof step.id === "string" ? step.id : null;
148
+ // #998: kind-membership branch. The CLI ships independently and may run
149
+ // against a NEWER server that registered a step kind the CLI's generated
150
+ // known-kind set doesn't have. For such an UNKNOWN kind we skip the
151
+ // per-field allowlist check (so a valid new-kind field is never falsely
152
+ // rejected — the recurring #685/#802/#971 failure) while STILL running the
153
+ // kind-agnostic misnested-header footgun detector below. For a KNOWN kind
154
+ // the full allowlist check applies as before. A missing/non-string `kind`
155
+ // is treated as known so the legacy strict check still catches obviously
156
+ // malformed steps (the runtime would reject a kindless step anyway).
157
+ const kind = typeof step.kind === "string" ? step.kind : null;
158
+ const isKnownKind = kind === null || KNOWN_KINDS.has(kind);
159
+ for (const key of Object.keys(step)) {
160
+ const value = step[key];
161
+ // Codex finding 1 (PR #762, 2026-05-15): self-id misnesting must be
162
+ // checked BEFORE the allowlist skip. When the step's `id` happens to
163
+ // match an allowlisted field name (e.g. `id = "query"`,
164
+ // `id = "request"`, `id = "input"`, `id = "output"`), TOML's
165
+ // `[steps.<id>.<sub-field>]` misnest produces a sub-table on the step
166
+ // keyed by the id — the same shape the validator was meant to catch.
167
+ // The allowlist would otherwise skip it as "expected per-kind field".
168
+ // Heuristic: when `step[step.id]` is a non-array table, this is
169
+ // (effectively always) the misnest pattern. Scalars are fine (the
170
+ // user really did mean to set the scalar field).
171
+ //
172
+ // Codex finding (PR #819, 2026-05-21): the heuristic over-fires for the
173
+ // `switch` step kind. A switch legitimately named `id = "default"` has a
174
+ // real `[steps.default]` fallback that parses as a non-array table at
175
+ // `step.default` — structurally identical to the misnest shape, but it's
176
+ // the field's *valid* form. (Likewise `id = "cases"`.) For these ids the
177
+ // footgun and the legitimate declaration are indistinguishable, so the
178
+ // heuristic must defer to the allowlist. Carve-out scope is narrow on
179
+ // purpose: only `kind === "switch"` with key `cases`/`default`. Every
180
+ // other (kind, id) collision — e.g. `id = "query"` on a database step —
181
+ // is still treated as the footgun, preserving finding 1's safety net.
182
+ const isSwitchFallbackField = step.kind === "switch" && (key === "cases" || key === "default");
183
+ const isSelfIdMisnest = stepId !== null &&
184
+ key === stepId &&
185
+ value !== null &&
186
+ typeof value === "object" &&
187
+ !Array.isArray(value) &&
188
+ !isSwitchFallbackField;
189
+ // Known kind → full allowlist check (an allowlisted field passes).
190
+ // Unknown kind → skip the per-field allowlist check entirely: only the
191
+ // structural footgun (self-id misnest) below can flag a field. The
192
+ // footgun check is kind-agnostic, so it fires on every step regardless.
193
+ if (!isSelfIdMisnest && (!isKnownKind || ALLOWLISTED_FIELDS.has(key)))
194
+ continue;
195
+ // Two failure modes are common enough to call out specifically in
196
+ // the hint:
197
+ //
198
+ // 1) `[steps.<id>.<field>]` under `[[steps]]` — TOML places the
199
+ // sub-table under `steps[N][<id>]`. We detect this when the
200
+ // unknown field name equals the step's own id (including the
201
+ // self-id-allowlist-collision case above). We use the first
202
+ // sub-key of the offending value (e.g. `request`) to build a
203
+ // concrete corrected-form example so the user sees exactly what
204
+ // to rewrite, not just an abstract `<field>`.
205
+ //
206
+ // 2) Any other unknown top-level field — covered by the generic hint.
207
+ let hint;
208
+ if (stepId !== null && key === stepId) {
209
+ const subKey = value && typeof value === "object" && !Array.isArray(value)
210
+ ? Object.keys(value)[0]
211
+ : null;
212
+ const exampleSub = subKey ?? "request";
213
+ hint =
214
+ `This is usually caused by writing [steps.${stepId}.${exampleSub}] instead of [steps.${exampleSub}]. ` +
215
+ `TOML can't address an array element by id — use [steps.${exampleSub}] (refers to the most recent step).`;
216
+ }
217
+ else {
218
+ hint =
219
+ `\`${key}\` is not a recognized step field. ` +
220
+ `If you meant to write a nested config block on this step, use [steps.${key}] (which refers to the most recent step) instead of [steps.<id>.${key}].`;
221
+ }
222
+ errors.push({
223
+ stepIndex,
224
+ stepId,
225
+ field: key,
226
+ hint,
227
+ parentStepId,
228
+ });
229
+ }
230
+ // #1252 — form-urlencoded body conflict. `[steps.request.form]` encodes an
231
+ // `application/x-www-form-urlencoded` body; it cannot coexist with a
232
+ // `request.body` or a raw/multipart `bodyMode`. The runtime rejects the same
233
+ // combination, but catching it at push time gives a clearer, earlier
234
+ // diagnostic. (`request.form` itself needs no allowlist entry — the validator
235
+ // only checks top-level step fields, and `request` is already allowlisted.)
236
+ if (step.kind === "integration.call" &&
237
+ step.request !== null &&
238
+ typeof step.request === "object" &&
239
+ !Array.isArray(step.request)) {
240
+ const req = step.request;
241
+ const hasForm = req.form !== undefined && req.form !== null;
242
+ if (hasForm) {
243
+ if (req.body !== undefined && req.body !== null) {
244
+ errors.push({
245
+ stepIndex,
246
+ stepId,
247
+ field: "request.form",
248
+ hint: "`request.form` (application/x-www-form-urlencoded) cannot be combined with `request.body`. " +
249
+ "Use one request body — either the JSON `body` or the `form` table.",
250
+ parentStepId,
251
+ });
252
+ }
253
+ const mode = step.bodyMode;
254
+ if (mode === "raw" || mode === "multipart") {
255
+ errors.push({
256
+ stepIndex,
257
+ stepId,
258
+ field: "request.form",
259
+ hint: `\`request.form\` (application/x-www-form-urlencoded) cannot be combined with bodyMode "${mode}". ` +
260
+ "Remove `form` or the `bodyMode`.",
261
+ parentStepId,
262
+ });
263
+ }
264
+ }
265
+ }
266
+ }
267
+ /**
268
+ * Render a multi-line diagnostic for a list of errors. Designed for the
269
+ * shape called out in the issue:
270
+ *
271
+ * Error in workflows/refresh.toml:
272
+ * steps[0] (id="refresh-each") has unknown field "refresh-each".
273
+ * This is usually caused by writing [steps.refresh-each.request] instead of [steps.request].
274
+ * TOML can't address an array element by id — use [steps.request] (refers to the most recent step).
275
+ *
276
+ * @param filePath The TOML file path (or display name) to include in the
277
+ * header.
278
+ * @param errors The error list from `validateWorkflowToml`.
279
+ * @returns A multi-line string ready to print to stderr.
280
+ */
281
+ export function formatWorkflowTomlErrors(filePath, errors) {
282
+ if (errors.length === 0)
283
+ return "";
284
+ const lines = [`Error in ${filePath}:`];
285
+ for (const err of errors) {
286
+ if (err.field === "__steps_shape__") {
287
+ lines.push(` ${err.hint}`);
288
+ continue;
289
+ }
290
+ if (err.field === "__step_shape__") {
291
+ lines.push(` steps[${err.stepIndex}] is malformed: ${err.hint}`);
292
+ continue;
293
+ }
294
+ // For errors inside a `collect` step's nested inner step (codex review,
295
+ // 2026-05-15), use a `steps[N].step` slot prefix so operators see that
296
+ // the offending field is on the inner step, not the outer collect.
297
+ // The outer step's id (if any) is also included in the prefix so the
298
+ // diagnostic can be cross-referenced against the parent's TOML header.
299
+ //
300
+ // #971: top-level errors carry `parentStepId: null` (set explicitly at the
301
+ // top-level `validateStepObject` call); only genuine collect-inner errors
302
+ // carry a real id (or `undefined` if a future caller omits it). Use a
303
+ // non-null check so BOTH `null` and `undefined` top-level errors render as
304
+ // a bare `steps[N]` without the `(inside collect step)` suffix. The prior
305
+ // `!== undefined` check treated `null` as inner (`null !== undefined` is
306
+ // `true`), mislabeling every top-level error as inside a collect step (a
307
+ // regression from PR #762).
308
+ const isInnerStep = err.parentStepId != null;
309
+ const slot = isInnerStep
310
+ ? `steps[${err.stepIndex}].step`
311
+ : `steps[${err.stepIndex}]`;
312
+ const idPart = err.stepId ? ` (id="${err.stepId}")` : "";
313
+ const parentPart = isInnerStep && err.parentStepId
314
+ ? ` (inside collect step id="${err.parentStepId}")`
315
+ : isInnerStep
316
+ ? ` (inside collect step)`
317
+ : "";
318
+ lines.push(` ${slot}${idPart}${parentPart} has unknown field "${err.field}".`);
319
+ lines.push(` ${err.hint}`);
320
+ }
321
+ return lines.join("\n");
322
+ }
323
+ //# sourceMappingURL=workflow-toml-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-toml-validator.js","sourceRoot":"","sources":["../../../src/lib/workflow-toml-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAElC;;;GAG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