primitive-admin 1.0.44 → 1.0.46
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/README.md +43 -0
- package/assets/skill/skills/primitive-platform/SKILL.md +85 -26
- package/dist/bin/primitive.js +6 -0
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/analytics.js +16 -16
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps.js +14 -14
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth.js +70 -20
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.js +11 -11
- package/dist/src/commands/blob-buckets.js.map +1 -1
- package/dist/src/commands/catalog.js +17 -17
- package/dist/src/commands/catalog.js.map +1 -1
- package/dist/src/commands/collection-type-configs.js +5 -5
- package/dist/src/commands/collection-type-configs.js.map +1 -1
- package/dist/src/commands/collections.js +6 -6
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/comparisons.js +6 -6
- package/dist/src/commands/comparisons.js.map +1 -1
- package/dist/src/commands/cron-triggers.js +17 -17
- package/dist/src/commands/cron-triggers.js.map +1 -1
- package/dist/src/commands/database-types.js +13 -13
- package/dist/src/commands/database-types.js.map +1 -1
- package/dist/src/commands/databases.js +266 -8
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/email-templates.js +6 -6
- package/dist/src/commands/email-templates.js.map +1 -1
- package/dist/src/commands/env.js +6 -6
- package/dist/src/commands/env.js.map +1 -1
- package/dist/src/commands/group-type-configs.js +6 -6
- package/dist/src/commands/group-type-configs.js.map +1 -1
- package/dist/src/commands/groups.js +7 -7
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/init.js +175 -144
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +31 -21
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/prompts.js +17 -16
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.js +8 -8
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/sync.js +1054 -284
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.js +9 -9
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/users.js +44 -3
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/webhooks.js +18 -18
- package/dist/src/commands/webhooks.js.map +1 -1
- package/dist/src/commands/workflows.js +285 -63
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.js +273 -72
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/db-codegen/dbFingerprint.js +17 -0
- package/dist/src/lib/db-codegen/dbFingerprint.js.map +1 -0
- package/dist/src/lib/db-codegen/dbGenerator.js +255 -0
- package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/db-codegen/dbNaming.js +104 -0
- package/dist/src/lib/db-codegen/dbNaming.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTemplates.js +138 -0
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js +61 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -0
- package/dist/src/lib/migration-nag.js +163 -0
- package/dist/src/lib/migration-nag.js.map +1 -0
- package/dist/src/lib/output.js +58 -6
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/refresh-admin-credentials.js +103 -0
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -0
- package/dist/src/lib/template.js +80 -1
- package/dist/src/lib/template.js.map +1 -1
- package/dist/src/lib/toml-database-config.js +565 -0
- package/dist/src/lib/toml-database-config.js.map +1 -0
- package/dist/src/lib/toml-params-validator.js +183 -0
- package/dist/src/lib/toml-params-validator.js.map +1 -0
- package/dist/src/lib/workflow-fragments.js +121 -0
- package/dist/src/lib/workflow-fragments.js.map +1 -0
- package/dist/src/lib/workflow-toml-validator.js +343 -0
- package/dist/src/lib/workflow-toml-validator.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validator: every `$params.X` reference inside an operation's
|
|
3
|
+
* `definition` must correspond to a declared param in
|
|
4
|
+
* `[[operations.params]]` (or the legacy JSON-string params object).
|
|
5
|
+
*
|
|
6
|
+
* Background (issue #752): a typo like `$params.proectId` used to
|
|
7
|
+
* silently no-op at runtime. With native TOML, we can catch these at
|
|
8
|
+
* `sync push` time with the file path and line number of the
|
|
9
|
+
* operation block where the bad reference appears.
|
|
10
|
+
*
|
|
11
|
+
* Design notes:
|
|
12
|
+
* - Line attribution is per-operation, not per-reference. We don't
|
|
13
|
+
* parse `definition` line-by-line; we just locate the
|
|
14
|
+
* `[[operations]]` header for the named op in the raw source and
|
|
15
|
+
* report that line. This is the load-bearing UX (jump to the
|
|
16
|
+
* offending op block); pinpointing the exact `$params.X` reference
|
|
17
|
+
* inside a sub-table would require swapping the TOML parser, which
|
|
18
|
+
* the issue explicitly leaves to implementer judgement.
|
|
19
|
+
* - We intentionally diverge from the server-side `collectParamRefs`
|
|
20
|
+
* in `database-type-operations-controller.ts:1163`. The server pushes
|
|
21
|
+
* the full path (e.g. `"X.Y"` for `$params.X.Y`); the CLI extracts
|
|
22
|
+
* only the first segment (`"X"`). Net effect: the CLI validator is
|
|
23
|
+
* more lenient than the server — `$params.X.Y` passes the CLI check
|
|
24
|
+
* when `X` alone is declared in `[[operations.params]]`, even though
|
|
25
|
+
* the server treats the full path as the lookup key. The server
|
|
26
|
+
* remains authoritative; the CLI's first-segment extraction is a
|
|
27
|
+
* pragmatic choice so authors can declare structured params (e.g.
|
|
28
|
+
* `config: { type: "object" }`) and reference sub-fields like
|
|
29
|
+
* `$params.config.subKey` without listing every sub-field
|
|
30
|
+
* individually (review feedback r3246635661).
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Walk an arbitrary JSON-ish value and collect `$params.X` references
|
|
34
|
+
* found in string-valued leaves, returning only the first dotted segment
|
|
35
|
+
* (`"X"` for `$params.X.Y`). Intentionally more lenient than the
|
|
36
|
+
* server-side helper, which pushes the full path — see the module
|
|
37
|
+
* doc-comment for the rationale.
|
|
38
|
+
*/
|
|
39
|
+
export function collectParamRefs(value) {
|
|
40
|
+
const refs = [];
|
|
41
|
+
if (typeof value === "string") {
|
|
42
|
+
const match = value.match(/^\$params\.(.+)$/);
|
|
43
|
+
if (match) {
|
|
44
|
+
const first = match[1].split(/[.\[]/)[0];
|
|
45
|
+
if (first)
|
|
46
|
+
refs.push(first);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (Array.isArray(value)) {
|
|
50
|
+
for (const item of value) {
|
|
51
|
+
refs.push(...collectParamRefs(item));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (value !== null && typeof value === "object") {
|
|
55
|
+
for (const v of Object.values(value)) {
|
|
56
|
+
refs.push(...collectParamRefs(v));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return refs;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Normalize a `params` value (object, array, or JSON string) into the
|
|
63
|
+
* set of declared param names.
|
|
64
|
+
*/
|
|
65
|
+
export function declaredParamNames(params) {
|
|
66
|
+
const names = new Set();
|
|
67
|
+
if (params == null)
|
|
68
|
+
return names;
|
|
69
|
+
let value = params;
|
|
70
|
+
if (typeof value === "string") {
|
|
71
|
+
try {
|
|
72
|
+
value = JSON.parse(value);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return names;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
for (const row of value) {
|
|
80
|
+
if (row && typeof row === "object" && typeof row.name === "string") {
|
|
81
|
+
names.add(row.name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (typeof value === "object" && value !== null) {
|
|
86
|
+
for (const key of Object.keys(value)) {
|
|
87
|
+
names.add(key);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return names;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Find the 1-indexed line number in `rawToml` where the `[[operations]]`
|
|
94
|
+
* block declaring `opName` starts. Returns 0 if not found.
|
|
95
|
+
*
|
|
96
|
+
* Implementation: walk in source order, track the most recent
|
|
97
|
+
* `[[operations]]` header, and when we see a `name = "<opName>"` line
|
|
98
|
+
* before the next `[[operations]]` or top-level header, return that
|
|
99
|
+
* header's line.
|
|
100
|
+
*/
|
|
101
|
+
export function locateOperationLine(rawToml, opName) {
|
|
102
|
+
const lines = rawToml.split(/\r?\n/);
|
|
103
|
+
let lastOpHeader = 0;
|
|
104
|
+
let armed = false;
|
|
105
|
+
for (let i = 0; i < lines.length; i++) {
|
|
106
|
+
const line = lines[i].trim();
|
|
107
|
+
if (line === "[[operations]]") {
|
|
108
|
+
lastOpHeader = i + 1;
|
|
109
|
+
armed = true;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!armed)
|
|
113
|
+
continue;
|
|
114
|
+
// Another array-of-tables / top-level table → not this op anymore.
|
|
115
|
+
if (line.startsWith("[[") && line !== "[[operations]]" && !line.startsWith("[[operations.")) {
|
|
116
|
+
armed = false;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (line.startsWith("[") && !line.startsWith("[[") && !line.startsWith("[operations.")) {
|
|
120
|
+
armed = false;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const m = line.match(/^name\s*=\s*["'](.+)["']\s*$/);
|
|
124
|
+
if (m && m[1] === opName) {
|
|
125
|
+
return lastOpHeader;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validate `$params` references across every operation in a parsed
|
|
132
|
+
* database-type config.
|
|
133
|
+
*
|
|
134
|
+
* Errors (blocking):
|
|
135
|
+
* - A `$params.X` reference inside `definition` where `X` is not
|
|
136
|
+
* declared in `[[operations.params]]`.
|
|
137
|
+
*
|
|
138
|
+
* Warnings (soft, not blocking):
|
|
139
|
+
* - A param declared in `[[operations.params]]` that is not referenced
|
|
140
|
+
* anywhere in `definition`. Authors may be staging a deprecation.
|
|
141
|
+
*/
|
|
142
|
+
export function validateOperations(opts) {
|
|
143
|
+
const errors = [];
|
|
144
|
+
const warnings = [];
|
|
145
|
+
for (const op of opts.operations) {
|
|
146
|
+
if (!op || !op.name)
|
|
147
|
+
continue;
|
|
148
|
+
const declared = declaredParamNames(op.params);
|
|
149
|
+
const refs = new Set(collectParamRefs(op.definition));
|
|
150
|
+
const line = locateOperationLine(opts.rawToml, op.name);
|
|
151
|
+
for (const ref of refs) {
|
|
152
|
+
if (!declared.has(ref)) {
|
|
153
|
+
errors.push({
|
|
154
|
+
file: opts.filePath,
|
|
155
|
+
line,
|
|
156
|
+
op: op.name,
|
|
157
|
+
message: `$params.${ref} not declared in [[operations.params]] for operation '${op.name}'`,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (const name of declared) {
|
|
162
|
+
if (!refs.has(name)) {
|
|
163
|
+
warnings.push({
|
|
164
|
+
file: opts.filePath,
|
|
165
|
+
line,
|
|
166
|
+
op: op.name,
|
|
167
|
+
message: `param '${name}' declared but not referenced in operation '${op.name}'`,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { errors, warnings };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Format a validation issue as `<file>:<line>: <message>`.
|
|
176
|
+
*/
|
|
177
|
+
export function formatIssue(issue) {
|
|
178
|
+
if (issue.line > 0) {
|
|
179
|
+
return `${issue.file}:${issue.line}: ${issue.message}`;
|
|
180
|
+
}
|
|
181
|
+
return `${issue.file}: ${issue.message}`;
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=toml-params-validator.js.map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...]` at the top of
|
|
5
|
+
* their TOML. The CLI expands those references into a fully-flattened
|
|
6
|
+
* `[[steps]]` list before push — the server never sees fragments and
|
|
7
|
+
* stores only the canonical, expanded JSON.
|
|
8
|
+
*
|
|
9
|
+
* Pinned decisions (#744):
|
|
10
|
+
* - CLI-only. No server-side WorkflowFragment model.
|
|
11
|
+
* - Fragments live at <workflowDir>/../workflow-fragments/<name>.toml.
|
|
12
|
+
* - Fragment files are `[[steps]]` lists only — no `[workflow]` block.
|
|
13
|
+
* - No recursive includes in v1 (fragments cannot themselves `include`).
|
|
14
|
+
* - Unique step ids validated post-expansion; collisions name both
|
|
15
|
+
* locations in the error message.
|
|
16
|
+
*
|
|
17
|
+
* Wiring: `parseTomlFile()` in `cli/src/commands/sync.ts` calls
|
|
18
|
+
* `expandWorkflowTomlData()` after parsing. All 24 push parse sites in
|
|
19
|
+
* sync.ts route through that single seam, so the expansion is uniform.
|
|
20
|
+
* The standalone `expandWorkflow(filePath)` helper backs the
|
|
21
|
+
* `primitive workflows expand` subcommand for debugging.
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, readFileSync } from "fs";
|
|
24
|
+
import { dirname, join, basename } from "path";
|
|
25
|
+
import * as TOML from "@iarna/toml";
|
|
26
|
+
/**
|
|
27
|
+
* Read and expand a workflow TOML file from disk. Returns the parsed
|
|
28
|
+
* TOML with all `include` fragments spliced in. If the file has no
|
|
29
|
+
* `include` key, the parsed TOML is returned unchanged.
|
|
30
|
+
*/
|
|
31
|
+
export function expandWorkflow(workflowPath) {
|
|
32
|
+
const content = readFileSync(workflowPath, "utf-8");
|
|
33
|
+
const parsed = TOML.parse(content);
|
|
34
|
+
return expandWorkflowTomlData(parsed, workflowPath);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Expand the `include` key of an already-parsed TOML object. Resolves
|
|
38
|
+
* fragment files relative to `<workflowPath>/../../workflow-fragments/`.
|
|
39
|
+
* Use this when the TOML has already been parsed elsewhere (e.g. inside
|
|
40
|
+
* `parseTomlFile()`).
|
|
41
|
+
*/
|
|
42
|
+
export function expandWorkflowTomlData(parsed, workflowPath) {
|
|
43
|
+
// Fast path: nothing to expand. Preserve the original shape exactly —
|
|
44
|
+
// including the absence of a `steps` field, since not every TOML file
|
|
45
|
+
// routed through `parseTomlFile()` represents a workflow.
|
|
46
|
+
if (!("include" in parsed)) {
|
|
47
|
+
return parsed;
|
|
48
|
+
}
|
|
49
|
+
const includeList = parsed.include;
|
|
50
|
+
if (!Array.isArray(includeList)) {
|
|
51
|
+
throw new Error(`Workflow '${workflowPath}' has an 'include' key but it is not an array. Use \`include = ["fragment-name"]\`.`);
|
|
52
|
+
}
|
|
53
|
+
// Resolve fragments directory: sibling of workflow's parent directory.
|
|
54
|
+
// E.g. workflow at config/workflows/foo.toml
|
|
55
|
+
// fragments at config/workflow-fragments/<name>.toml
|
|
56
|
+
const fragmentsDir = join(dirname(workflowPath), "..", "workflow-fragments");
|
|
57
|
+
const workflowOwnSteps = Array.isArray(parsed.steps)
|
|
58
|
+
? parsed.steps
|
|
59
|
+
: [];
|
|
60
|
+
const allOriginated = [];
|
|
61
|
+
for (const fragmentName of includeList) {
|
|
62
|
+
if (typeof fragmentName !== "string" || fragmentName.length === 0) {
|
|
63
|
+
throw new Error(`Workflow '${workflowPath}' has an invalid include entry: ${JSON.stringify(fragmentName)}. Each entry must be a fragment name string.`);
|
|
64
|
+
}
|
|
65
|
+
const fragmentPath = join(fragmentsDir, `${fragmentName}.toml`);
|
|
66
|
+
const fragment = readFragmentSafely(fragmentPath, workflowPath, fragmentName);
|
|
67
|
+
for (const step of fragment.steps) {
|
|
68
|
+
allOriginated.push({ step, origin: `fragment '${fragmentName}'` });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const step of workflowOwnSteps) {
|
|
72
|
+
allOriginated.push({ step, origin: `workflow '${basename(workflowPath)}'` });
|
|
73
|
+
}
|
|
74
|
+
assertUniqueStepIds(allOriginated, workflowPath);
|
|
75
|
+
// Build the expanded object: drop `include`, replace `steps` with the
|
|
76
|
+
// concatenated list. Preserve all other top-level keys (workflow,
|
|
77
|
+
// triggers, configs, etc.) exactly as parsed.
|
|
78
|
+
const result = { ...parsed };
|
|
79
|
+
delete result.include;
|
|
80
|
+
result.steps = allOriginated.map((o) => o.step);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
function readFragmentSafely(fragmentPath, workflowPath, fragmentName) {
|
|
84
|
+
if (!existsSync(fragmentPath)) {
|
|
85
|
+
throw new Error(`Workflow '${workflowPath}' includes fragment '${fragmentName}' but the file does not exist at '${fragmentPath}'.`);
|
|
86
|
+
}
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
const content = readFileSync(fragmentPath, "utf-8");
|
|
90
|
+
parsed = TOML.parse(content);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
throw new Error(`Failed to parse fragment '${fragmentName}' at '${fragmentPath}': ${err?.message ?? err}`);
|
|
94
|
+
}
|
|
95
|
+
if ("include" in parsed) {
|
|
96
|
+
throw new Error(`Fragment '${fragmentName}' at '${fragmentPath}' contains its own 'include' key — recursive includes are not supported in v1. Inline the steps directly into this fragment.`);
|
|
97
|
+
}
|
|
98
|
+
if ("workflow" in parsed) {
|
|
99
|
+
throw new Error(`Fragment '${fragmentName}' at '${fragmentPath}' contains a [workflow] block. Fragment files must be [[steps]] lists only.`);
|
|
100
|
+
}
|
|
101
|
+
const steps = Array.isArray(parsed.steps)
|
|
102
|
+
? parsed.steps
|
|
103
|
+
: [];
|
|
104
|
+
return { steps };
|
|
105
|
+
}
|
|
106
|
+
function assertUniqueStepIds(originated, workflowPath) {
|
|
107
|
+
const seen = new Map();
|
|
108
|
+
for (const { step, origin } of originated) {
|
|
109
|
+
const id = step?.id;
|
|
110
|
+
if (id === undefined || id === null)
|
|
111
|
+
continue; // let downstream code complain about missing ids
|
|
112
|
+
if (typeof id !== "string")
|
|
113
|
+
continue;
|
|
114
|
+
if (seen.has(id)) {
|
|
115
|
+
const firstOrigin = seen.get(id);
|
|
116
|
+
throw new Error(`Step id '${id}' appears twice when expanding workflow '${workflowPath}': first in ${firstOrigin}, then in ${origin}.`);
|
|
117
|
+
}
|
|
118
|
+
seen.set(id, origin);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=workflow-fragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-fragments.js","sourceRoot":"","sources":["../../../src/lib/workflow-fragments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AASpC;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,YAAoB;IACjD,MAAM,OAAO,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAwB,CAAC;IAC1D,OAAO,sBAAsB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAA2B,EAC3B,YAAoB;IAEpB,sEAAsE;IACtE,sEAAsE;IACtE,0DAA0D;IAC1D,IAAI,CAAC,CAAC,SAAS,IAAI,MAAM,CAAC,EAAE,CAAC;QAC3B,OAAO,MAA0B,CAAC;IACpC,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;IACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,aAAa,YAAY,qFAAqF,CAC/G,CAAC;IACJ,CAAC;IAED,uEAAuE;IAC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,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;QAC1C,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC;QACpB,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,IAAI;YAAE,SAAS,CAAC,iDAAiD;QAChG,IAAI,OAAO,EAAE,KAAK,QAAQ;YAAE,SAAS;QACrC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACjB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CACb,YAAY,EAAE,4CAA4C,YAAY,eAAe,WAAW,aAAa,MAAM,GAAG,CACvH,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push-time validator for workflow TOML files (issue #685).
|
|
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[]` and reports any
|
|
12
|
+
* top-level field not in the universal-and-consumed allowlist. The allowlist
|
|
13
|
+
* is the union of:
|
|
14
|
+
* - Universal step fields declared on `BaseStepDefinition` in
|
|
15
|
+
* `src/workflows/runner/types.ts`
|
|
16
|
+
* - The top-level fields each step runner in `src/workflows/steps/`
|
|
17
|
+
* actually reads
|
|
18
|
+
*
|
|
19
|
+
* The list is universal-only (not per-kind) by design: the CLI doesn't know
|
|
20
|
+
* which step kinds exist on a given server version, and a per-kind list
|
|
21
|
+
* would couple the CLI tightly to the runtime. A universal allowlist
|
|
22
|
+
* catches the misnested-header footgun cleanly while staying tolerant of
|
|
23
|
+
* future step kinds that consume top-level fields already in the union.
|
|
24
|
+
*
|
|
25
|
+
* Maintenance: when a new step kind starts reading a new top-level field,
|
|
26
|
+
* add the field name to `ALLOWLISTED_FIELDS` below. See `cli/README.md`
|
|
27
|
+
* for the maintenance note.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Universal-only allowlist of top-level fields permitted on a step.
|
|
31
|
+
*
|
|
32
|
+
* Membership combines:
|
|
33
|
+
* 1) Universal fields on `BaseStepDefinition` in
|
|
34
|
+
* `src/workflows/runner/types.ts` and the runner engine's reads of
|
|
35
|
+
* `stepDef.*`.
|
|
36
|
+
* 2) The union of top-level fields actually consumed by step runners in
|
|
37
|
+
* `src/workflows/steps/` (audited 2026-05-15).
|
|
38
|
+
*
|
|
39
|
+
* Keep this sorted to make diffs reviewable.
|
|
40
|
+
*/
|
|
41
|
+
const ALLOWLISTED_FIELDS = new Set([
|
|
42
|
+
// Universal (BaseStepDefinition + engine).
|
|
43
|
+
"as",
|
|
44
|
+
"concurrency",
|
|
45
|
+
"continueOnError",
|
|
46
|
+
"description",
|
|
47
|
+
"forEach",
|
|
48
|
+
"id",
|
|
49
|
+
"kind",
|
|
50
|
+
"maxItems",
|
|
51
|
+
"name",
|
|
52
|
+
"runIf",
|
|
53
|
+
"saveAs",
|
|
54
|
+
"selector",
|
|
55
|
+
"strict",
|
|
56
|
+
"successWhen",
|
|
57
|
+
"timeout",
|
|
58
|
+
// Per-kind, union across runners.
|
|
59
|
+
"_testSteps", // workflow.call test-mode override
|
|
60
|
+
"action",
|
|
61
|
+
"appId",
|
|
62
|
+
"asBase64",
|
|
63
|
+
"attachments",
|
|
64
|
+
"blobId",
|
|
65
|
+
"bodyMode",
|
|
66
|
+
"bucketId",
|
|
67
|
+
"bucketKey",
|
|
68
|
+
"cacheTtlSeconds",
|
|
69
|
+
"cases", // switch: array of { when, output } (#802)
|
|
70
|
+
"configId",
|
|
71
|
+
"content",
|
|
72
|
+
"contentBase64",
|
|
73
|
+
"contentType",
|
|
74
|
+
"context",
|
|
75
|
+
"cursor",
|
|
76
|
+
"cursorField",
|
|
77
|
+
"databaseId",
|
|
78
|
+
"default", // switch: { output } fallback branch (#802)
|
|
79
|
+
"direction",
|
|
80
|
+
"dryRun",
|
|
81
|
+
"durationMs",
|
|
82
|
+
"email",
|
|
83
|
+
"events",
|
|
84
|
+
"expiresInSeconds",
|
|
85
|
+
"feature",
|
|
86
|
+
"filename",
|
|
87
|
+
"filters",
|
|
88
|
+
"groupBy",
|
|
89
|
+
"groupId",
|
|
90
|
+
"groupType",
|
|
91
|
+
"htmlBody",
|
|
92
|
+
"includeUserDetails",
|
|
93
|
+
"input",
|
|
94
|
+
"integrationKey",
|
|
95
|
+
"itemsField",
|
|
96
|
+
"limit",
|
|
97
|
+
"maxPages",
|
|
98
|
+
"message",
|
|
99
|
+
"messages",
|
|
100
|
+
"metrics",
|
|
101
|
+
"model",
|
|
102
|
+
"modelOverride",
|
|
103
|
+
"ms",
|
|
104
|
+
"multipartFields",
|
|
105
|
+
"onPartialFailure",
|
|
106
|
+
"operationName",
|
|
107
|
+
"output",
|
|
108
|
+
"page",
|
|
109
|
+
"params",
|
|
110
|
+
"payload",
|
|
111
|
+
"plugins",
|
|
112
|
+
"prompt",
|
|
113
|
+
"promptKey",
|
|
114
|
+
"query",
|
|
115
|
+
"queryType",
|
|
116
|
+
"request",
|
|
117
|
+
"route",
|
|
118
|
+
"runs",
|
|
119
|
+
"sort",
|
|
120
|
+
"step", // collect: nested inner step definition
|
|
121
|
+
"subject",
|
|
122
|
+
"tags",
|
|
123
|
+
"temperature",
|
|
124
|
+
"templateType",
|
|
125
|
+
"textBody",
|
|
126
|
+
"thinkingLevel",
|
|
127
|
+
"to",
|
|
128
|
+
"tools",
|
|
129
|
+
"tool_choice",
|
|
130
|
+
"top_p",
|
|
131
|
+
"toUserId",
|
|
132
|
+
"type",
|
|
133
|
+
"user",
|
|
134
|
+
"userId",
|
|
135
|
+
"userUlid",
|
|
136
|
+
"variables",
|
|
137
|
+
"windowDays",
|
|
138
|
+
"workflowKey",
|
|
139
|
+
]);
|
|
140
|
+
/**
|
|
141
|
+
* Walk a parsed workflow TOML document and return all unknown-field errors.
|
|
142
|
+
*
|
|
143
|
+
* @param tomlData The output of `TOML.parse()` for a workflow TOML file.
|
|
144
|
+
* @returns An array of error objects, one per offending field. Empty if no
|
|
145
|
+
* errors were found.
|
|
146
|
+
*/
|
|
147
|
+
export function validateWorkflowToml(tomlData) {
|
|
148
|
+
const errors = [];
|
|
149
|
+
if (tomlData === null || tomlData === undefined) {
|
|
150
|
+
return errors;
|
|
151
|
+
}
|
|
152
|
+
const steps = tomlData.steps;
|
|
153
|
+
// No steps section at all → nothing to validate. This is fine for
|
|
154
|
+
// partial TOML files (some commands accept a metadata-only file).
|
|
155
|
+
if (steps === undefined || steps === null) {
|
|
156
|
+
return errors;
|
|
157
|
+
}
|
|
158
|
+
// `steps` is a table instead of an array. This typically means the user
|
|
159
|
+
// wrote `[steps.foo]` with no preceding `[[steps]]` array marker, so
|
|
160
|
+
// TOML resolved `steps` to a table. The runtime expects an array — flag
|
|
161
|
+
// it with a clear shape diagnostic.
|
|
162
|
+
if (!Array.isArray(steps)) {
|
|
163
|
+
if (typeof steps === "object") {
|
|
164
|
+
errors.push({
|
|
165
|
+
stepIndex: -1,
|
|
166
|
+
stepId: null,
|
|
167
|
+
field: "__steps_shape__",
|
|
168
|
+
hint: 'The `steps` section is a table, not an array. Workflow TOML expects `[[steps]]` array markers — add `[[steps]]` before any `[steps.<field>]` blocks.',
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
errors.push({
|
|
173
|
+
stepIndex: -1,
|
|
174
|
+
stepId: null,
|
|
175
|
+
field: "__steps_shape__",
|
|
176
|
+
hint: `The \`steps\` section must be an array of step tables (received: ${typeof steps}).`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return errors;
|
|
180
|
+
}
|
|
181
|
+
for (let i = 0; i < steps.length; i++) {
|
|
182
|
+
const step = steps[i];
|
|
183
|
+
// Defensive: array entry isn't an object. Should be near-impossible with
|
|
184
|
+
// valid `[[steps]]` syntax, but possible if the user writes `steps =
|
|
185
|
+
// ["a", "b"]`. Surface it so the user gets a diagnostic instead of a
|
|
186
|
+
// silent skip.
|
|
187
|
+
if (step === null || typeof step !== "object" || Array.isArray(step)) {
|
|
188
|
+
errors.push({
|
|
189
|
+
stepIndex: i,
|
|
190
|
+
stepId: null,
|
|
191
|
+
field: "__step_shape__",
|
|
192
|
+
hint: `Each entry in \`steps[]\` must be a table. Got: ${step === null ? "null" : Array.isArray(step) ? "array" : typeof step}.`,
|
|
193
|
+
});
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
validateStepObject(step, i, /* parentStepId */ null, errors);
|
|
197
|
+
// Codex finding 2 (PR #762, 2026-05-15): a `collect` step's nested
|
|
198
|
+
// `step` field is itself a step definition that the collect runner
|
|
199
|
+
// executes. The outer-step allowlist accepts `step` as a top-level
|
|
200
|
+
// field, but that's a structural pass-through — we need to recurse
|
|
201
|
+
// into the inner step's keys to catch the same misnested-header
|
|
202
|
+
// footgun (e.g. `[steps.step.call.request]` parses as `step.step =
|
|
203
|
+
// { call: { request: {...} } }`, with `call` as an unknown inner
|
|
204
|
+
// field; without the recursion this slips through). We only recurse
|
|
205
|
+
// for `kind === "collect"` — other kinds with a `step`-named field
|
|
206
|
+
// (none today) would need their own audit.
|
|
207
|
+
if (step.kind === "collect" &&
|
|
208
|
+
step.step !== null &&
|
|
209
|
+
typeof step.step === "object" &&
|
|
210
|
+
!Array.isArray(step.step)) {
|
|
211
|
+
const outerStepId = typeof step.id === "string" ? step.id : null;
|
|
212
|
+
validateStepObject(step.step, i, outerStepId, errors);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return errors;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Validate a single step object's top-level keys against the allowlist and
|
|
219
|
+
* push any errors found onto `errors`. Used for both the top-level
|
|
220
|
+
* `steps[]` walk and the recursive `collect.step` walk.
|
|
221
|
+
*
|
|
222
|
+
* When `parentStepId` is set, the step being validated is the inner step
|
|
223
|
+
* of a `collect`. Errors carry the outer-step context so the rendered
|
|
224
|
+
* diagnostic can point operators at the right slot in the TOML.
|
|
225
|
+
*/
|
|
226
|
+
function validateStepObject(step, stepIndex, parentStepId, errors) {
|
|
227
|
+
const stepId = typeof step.id === "string" ? step.id : null;
|
|
228
|
+
for (const key of Object.keys(step)) {
|
|
229
|
+
const value = step[key];
|
|
230
|
+
// Codex finding 1 (PR #762, 2026-05-15): self-id misnesting must be
|
|
231
|
+
// checked BEFORE the allowlist skip. When the step's `id` happens to
|
|
232
|
+
// match an allowlisted field name (e.g. `id = "query"`,
|
|
233
|
+
// `id = "request"`, `id = "input"`, `id = "output"`), TOML's
|
|
234
|
+
// `[steps.<id>.<sub-field>]` misnest produces a sub-table on the step
|
|
235
|
+
// keyed by the id — the same shape the validator was meant to catch.
|
|
236
|
+
// The allowlist would otherwise skip it as "expected per-kind field".
|
|
237
|
+
// Heuristic: when `step[step.id]` is a non-array table, this is
|
|
238
|
+
// (effectively always) the misnest pattern. Scalars are fine (the
|
|
239
|
+
// user really did mean to set the scalar field).
|
|
240
|
+
//
|
|
241
|
+
// Codex finding (PR #819, 2026-05-21): the heuristic over-fires for the
|
|
242
|
+
// `switch` step kind. A switch legitimately named `id = "default"` has a
|
|
243
|
+
// real `[steps.default]` fallback that parses as a non-array table at
|
|
244
|
+
// `step.default` — structurally identical to the misnest shape, but it's
|
|
245
|
+
// the field's *valid* form. (Likewise `id = "cases"`.) For these ids the
|
|
246
|
+
// footgun and the legitimate declaration are indistinguishable, so the
|
|
247
|
+
// heuristic must defer to the allowlist. Carve-out scope is narrow on
|
|
248
|
+
// purpose: only `kind === "switch"` with key `cases`/`default`. Every
|
|
249
|
+
// other (kind, id) collision — e.g. `id = "query"` on a database step —
|
|
250
|
+
// is still treated as the footgun, preserving finding 1's safety net.
|
|
251
|
+
const isSwitchFallbackField = step.kind === "switch" && (key === "cases" || key === "default");
|
|
252
|
+
const isSelfIdMisnest = stepId !== null &&
|
|
253
|
+
key === stepId &&
|
|
254
|
+
value !== null &&
|
|
255
|
+
typeof value === "object" &&
|
|
256
|
+
!Array.isArray(value) &&
|
|
257
|
+
!isSwitchFallbackField;
|
|
258
|
+
if (!isSelfIdMisnest && ALLOWLISTED_FIELDS.has(key))
|
|
259
|
+
continue;
|
|
260
|
+
// Two failure modes are common enough to call out specifically in
|
|
261
|
+
// the hint:
|
|
262
|
+
//
|
|
263
|
+
// 1) `[steps.<id>.<field>]` under `[[steps]]` — TOML places the
|
|
264
|
+
// sub-table under `steps[N][<id>]`. We detect this when the
|
|
265
|
+
// unknown field name equals the step's own id (including the
|
|
266
|
+
// self-id-allowlist-collision case above). We use the first
|
|
267
|
+
// sub-key of the offending value (e.g. `request`) to build a
|
|
268
|
+
// concrete corrected-form example so the user sees exactly what
|
|
269
|
+
// to rewrite, not just an abstract `<field>`.
|
|
270
|
+
//
|
|
271
|
+
// 2) Any other unknown top-level field — covered by the generic hint.
|
|
272
|
+
let hint;
|
|
273
|
+
if (stepId !== null && key === stepId) {
|
|
274
|
+
const subKey = value && typeof value === "object" && !Array.isArray(value)
|
|
275
|
+
? Object.keys(value)[0]
|
|
276
|
+
: null;
|
|
277
|
+
const exampleSub = subKey ?? "request";
|
|
278
|
+
hint =
|
|
279
|
+
`This is usually caused by writing [steps.${stepId}.${exampleSub}] instead of [steps.${exampleSub}]. ` +
|
|
280
|
+
`TOML can't address an array element by id — use [steps.${exampleSub}] (refers to the most recent step).`;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
hint =
|
|
284
|
+
`\`${key}\` is not a recognized step field. ` +
|
|
285
|
+
`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}].`;
|
|
286
|
+
}
|
|
287
|
+
errors.push({
|
|
288
|
+
stepIndex,
|
|
289
|
+
stepId,
|
|
290
|
+
field: key,
|
|
291
|
+
hint,
|
|
292
|
+
parentStepId,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Render a multi-line diagnostic for a list of errors. Designed for the
|
|
298
|
+
* shape called out in the issue:
|
|
299
|
+
*
|
|
300
|
+
* Error in workflows/refresh.toml:
|
|
301
|
+
* steps[0] (id="refresh-each") has unknown field "refresh-each".
|
|
302
|
+
* This is usually caused by writing [steps.refresh-each.request] instead of [steps.request].
|
|
303
|
+
* TOML can't address an array element by id — use [steps.request] (refers to the most recent step).
|
|
304
|
+
*
|
|
305
|
+
* @param filePath The TOML file path (or display name) to include in the
|
|
306
|
+
* header.
|
|
307
|
+
* @param errors The error list from `validateWorkflowToml`.
|
|
308
|
+
* @returns A multi-line string ready to print to stderr.
|
|
309
|
+
*/
|
|
310
|
+
export function formatWorkflowTomlErrors(filePath, errors) {
|
|
311
|
+
if (errors.length === 0)
|
|
312
|
+
return "";
|
|
313
|
+
const lines = [`Error in ${filePath}:`];
|
|
314
|
+
for (const err of errors) {
|
|
315
|
+
if (err.field === "__steps_shape__") {
|
|
316
|
+
lines.push(` ${err.hint}`);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (err.field === "__step_shape__") {
|
|
320
|
+
lines.push(` steps[${err.stepIndex}] is malformed: ${err.hint}`);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
// For errors inside a `collect` step's nested inner step (codex review,
|
|
324
|
+
// 2026-05-15), use a `steps[N].step` slot prefix so operators see that
|
|
325
|
+
// the offending field is on the inner step, not the outer collect.
|
|
326
|
+
// The outer step's id (if any) is also included in the prefix so the
|
|
327
|
+
// diagnostic can be cross-referenced against the parent's TOML header.
|
|
328
|
+
const isInnerStep = err.parentStepId !== undefined;
|
|
329
|
+
const slot = isInnerStep
|
|
330
|
+
? `steps[${err.stepIndex}].step`
|
|
331
|
+
: `steps[${err.stepIndex}]`;
|
|
332
|
+
const idPart = err.stepId ? ` (id="${err.stepId}")` : "";
|
|
333
|
+
const parentPart = isInnerStep && err.parentStepId
|
|
334
|
+
? ` (inside collect step id="${err.parentStepId}")`
|
|
335
|
+
: isInnerStep
|
|
336
|
+
? ` (inside collect step)`
|
|
337
|
+
: "";
|
|
338
|
+
lines.push(` ${slot}${idPart}${parentPart} has unknown field "${err.field}".`);
|
|
339
|
+
lines.push(` ${err.hint}`);
|
|
340
|
+
}
|
|
341
|
+
return lines.join("\n");
|
|
342
|
+
}
|
|
343
|
+
//# sourceMappingURL=workflow-toml-validator.js.map
|