akm-cli 0.9.10 → 0.9.12
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/CHANGELOG.md +226 -0
- package/STABILITY.md +28 -15
- package/dist/assets/hints/cli-hints-full.md +1 -1
- package/dist/assets/improve-strategies/consolidate.json +1 -1
- package/dist/assets/improve-strategies/default.json +1 -1
- package/dist/assets/improve-strategies/thorough.json +1 -2
- package/dist/cli/shared.js +16 -4
- package/dist/cli.js +15 -13
- package/dist/commands/agent/agent-dispatch.js +8 -0
- package/dist/commands/command/execution-source-loader.js +25 -22
- package/dist/commands/command/portable-template.js +4 -26
- package/dist/commands/config-cli.js +10 -4
- package/dist/commands/env/env-binding.js +10 -3
- package/dist/commands/env/env-cli.js +7 -0
- package/dist/commands/env/secret-cli.js +15 -4
- package/dist/commands/health/checks.js +209 -78
- package/dist/commands/health/improve-metrics.js +12 -0
- package/dist/commands/health.js +16 -4
- package/dist/commands/improve/distill/quality-gate.js +15 -7
- package/dist/commands/improve/distill.js +28 -12
- package/dist/commands/improve/eval-cases.js +9 -2
- package/dist/commands/improve/execution.js +1 -2
- package/dist/commands/improve/extract.js +82 -56
- package/dist/commands/improve/improve-strategies.js +26 -8
- package/dist/commands/improve/improve.js +32 -4
- package/dist/commands/improve/loop-stages.js +13 -3
- package/dist/commands/improve/preparation.js +9 -6
- package/dist/commands/improve/reflect.js +61 -77
- package/dist/commands/lint/index.js +3 -1
- package/dist/commands/migrate-cli.js +6 -4
- package/dist/commands/proposal/drain-policies.js +22 -2
- package/dist/commands/proposal/repository.js +4 -4
- package/dist/commands/proposal/validators/proposal-quality-validators.js +23 -2
- package/dist/commands/proposal/validators/proposals.js +10 -19
- package/dist/commands/read/show.js +42 -31
- package/dist/commands/registry-cli.js +4 -2
- package/dist/commands/sources/init.js +4 -8
- package/dist/commands/sources/self-update.js +2 -2
- package/dist/commands/sources/source-clone.js +5 -7
- package/dist/commands/sources/sources-cli.js +3 -5
- package/dist/commands/tasks/tasks-cli.js +36 -12
- package/dist/commands/tasks/tasks.js +38 -35
- package/dist/commands/tasks/validate.js +186 -0
- package/dist/commands/url-checker.js +75 -16
- package/dist/commands/workflow-cli.js +17 -15
- package/dist/core/activation-policy.js +31 -3
- package/dist/core/adapter/execution-source.js +39 -11
- package/dist/core/asset/stash-meta.js +7 -41
- package/dist/core/bundle-id.js +7 -1
- package/dist/core/common.js +8 -17
- package/dist/core/config/config-schema.js +3 -23
- package/dist/core/config/config-walker.js +50 -4
- package/dist/core/config/config.js +21 -5
- package/dist/core/config/legacy-source-shape-shim.js +79 -0
- package/dist/core/config/schema/embedding.js +2 -2
- package/dist/core/config/schema/engines.js +19 -2
- package/dist/core/config/schema/index-config.js +19 -21
- package/dist/core/config/schema/primitives.js +21 -10
- package/dist/core/config/schema/sources-bundles.js +1 -6
- package/dist/core/errors.js +2 -3
- package/dist/core/improve-result.js +8 -0
- package/dist/core/improve-types.js +17 -0
- package/dist/core/json-schema.js +1 -11
- package/dist/core/maintenance-barrier.js +17 -2
- package/dist/core/paths.js +124 -15
- package/dist/core/state/migrations.js +28 -0
- package/dist/core/state-db.js +28 -1
- package/dist/core/write-source.js +6 -6
- package/dist/indexer/bundle-identity-guard.js +3 -0
- package/dist/indexer/ensure-index.js +5 -0
- package/dist/indexer/indexer.js +11 -3
- package/dist/indexer/lookup/adapter-concept-owner.js +14 -3
- package/dist/indexer/passes/metadata.js +16 -5
- package/dist/indexer/search/search-fields.js +1 -30
- package/dist/indexer/search/search-source.js +3 -2
- package/dist/integrations/agent/engine-resolution.js +107 -4
- package/dist/integrations/agent/execution-lowering.js +15 -2
- package/dist/integrations/agent/model-map.js +16 -10
- package/dist/integrations/agent/prompts.js +13 -6
- package/dist/integrations/agent/runner-dispatch.js +16 -3
- package/dist/integrations/agent/runner.js +2 -0
- package/dist/integrations/lockfile.js +22 -7
- package/dist/llm/client.js +16 -0
- package/dist/llm/index-passes.js +3 -2
- package/dist/output/shapes/passthrough.js +10 -3
- package/dist/output/shapes.js +5 -3
- package/dist/output/text/workflow-format.js +8 -1
- package/dist/scripts/akm-migrate-node.js +2028 -1613
- package/dist/scripts/akm-migrate.js +2027 -1612
- package/dist/setup/setup.js +14 -21
- package/dist/sources/include.js +150 -20
- package/dist/sources/providers/git-install.js +14 -12
- package/dist/sources/providers/git-provider.js +3 -3
- package/dist/sources/snapshot-fetchers/website-ingest.js +54 -16
- package/dist/sources/website-url.js +12 -4
- package/dist/storage/engines/sqlite-migrations.js +40 -10
- package/dist/storage/like-pattern.js +7 -0
- package/dist/storage/repositories/extract-sessions-repository.js +23 -0
- package/dist/storage/repositories/index-connection.js +27 -10
- package/dist/storage/repositories/index-entry-schema.js +19 -2
- package/dist/storage/repositories/index-schema.js +30 -9
- package/dist/storage/repositories/proposals-repository.js +2 -1
- package/dist/storage/repositories/task-history-repository.js +14 -7
- package/dist/storage/repositories/workflow-runs-repository.js +15 -1
- package/dist/storage/sqlite-read-snapshot.js +11 -9
- package/dist/tasks/backends/cron.js +34 -5
- package/dist/tasks/backends/launchd.js +23 -26
- package/dist/tasks/backends/schtasks.js +50 -3
- package/dist/tasks/frozen-script.js +2 -0
- package/dist/tasks/prepare/prepare.js +2 -7
- package/dist/tasks/prepare/script-capture.js +38 -6
- package/dist/tasks/schedule.js +154 -13
- package/dist/tasks/scheduler-sync.js +51 -25
- package/dist/tasks/source/task-source-v3-frozen.js +0 -1
- package/dist/tasks/source/task-source-v4.js +0 -1
- package/dist/workflows/exec/child-workflow.js +2 -3
- package/dist/workflows/exec/dispatch-redaction.js +21 -7
- package/dist/workflows/exec/exec-unit.js +3 -4
- package/dist/workflows/exec/run-workflow.js +19 -10
- package/dist/workflows/exec/step-work.js +35 -56
- package/dist/workflows/freeze/resolve-steps.js +19 -11
- package/dist/workflows/freeze/source-freeze.js +7 -0
- package/dist/workflows/freeze/targets/child-workflow.js +12 -18
- package/dist/workflows/freeze/targets/command.js +14 -2
- package/dist/workflows/ir/environment-v4.js +4 -2
- package/dist/workflows/ir/freeze-v4.js +2 -5
- package/dist/workflows/ir/plan-hash.js +0 -3
- package/dist/workflows/ir/schema-v4.js +14 -9
- package/dist/workflows/ir/schema.js +1 -3
- package/dist/workflows/resource-limits.js +35 -48
- package/dist/workflows/runtime/plan-classifier.js +89 -41
- package/dist/workflows/runtime/run-outputs.js +1 -21
- package/dist/workflows/runtime/runs.js +76 -150
- package/dist/workflows/source-files.js +28 -54
- package/dist/workflows/source-ir/program.js +2 -2
- package/dist/workflows/source-ir/semantics.js +5 -23
- package/docs/integration/bundling-akm.md +1 -1
- package/docs/migration/v0.8-to-v0.9.md +32 -0
- package/docs/migration/v0.9.1-to-v0.9.2.md +20 -0
- package/docs/reference/cli.md +105 -22
- package/docs/reference/configuration.md +12 -2
- package/docs/reference/data-and-telemetry.md +1 -1
- package/docs/reference/tasks.md +8 -0
- package/package.json +1 -1
- package/schemas/akm-config.json +11 -8
|
@@ -33,17 +33,49 @@ const SCRIPT_INTERPRETERS = Object.freeze({
|
|
|
33
33
|
".kt": "kotlin",
|
|
34
34
|
".kts": "kotlin",
|
|
35
35
|
});
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const SHEBANG_INTERPRETERS = [
|
|
37
|
+
[/^(bash|sh|zsh|dash|ksh)$/, "sh"],
|
|
38
|
+
[/^python[0-9.]*$/, "python"],
|
|
39
|
+
[/^ruby$/, "ruby"],
|
|
40
|
+
[/^perl$/, "perl"],
|
|
41
|
+
[/^php$/, "php"],
|
|
42
|
+
[/^lua$/, "lua"],
|
|
43
|
+
[/^node$/, "node"],
|
|
44
|
+
];
|
|
45
|
+
function interpreterFromShebang(bytes) {
|
|
46
|
+
if (!bytes || bytes.length < 2 || bytes[0] !== 0x23 || bytes[1] !== 0x21)
|
|
47
|
+
return undefined;
|
|
48
|
+
const newline = bytes.indexOf(0x0a);
|
|
49
|
+
const lineBytes = newline === -1 ? bytes.subarray(2) : bytes.subarray(2, newline);
|
|
50
|
+
const tokens = Buffer.from(lineBytes).toString("utf8").trim().split(/\s+/).filter(Boolean);
|
|
51
|
+
const [first, second] = tokens;
|
|
52
|
+
const named = first?.split("/").pop() === "env" ? second : first?.split("/").pop();
|
|
53
|
+
if (!named)
|
|
54
|
+
return undefined;
|
|
55
|
+
for (const [pattern, interpreter] of SHEBANG_INTERPRETERS) {
|
|
56
|
+
if (pattern.test(named))
|
|
57
|
+
return interpreter;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
function nodeStripsTypeScript() {
|
|
62
|
+
const features = process.features;
|
|
63
|
+
return Boolean(features?.typescript);
|
|
64
|
+
}
|
|
65
|
+
export function scriptInterpreter(extension, ref, bytes) {
|
|
66
|
+
const interpreter = SCRIPT_INTERPRETERS[extension] ?? (extension === "" ? interpreterFromShebang(bytes) : undefined);
|
|
38
67
|
if (!interpreter) {
|
|
39
68
|
throw new UsageError(`Task v3 script target ${JSON.stringify(ref)} has no closed runtime interpreter for extension ${JSON.stringify(extension)}.`, "TASK_TARGET_UNSUPPORTED");
|
|
40
69
|
}
|
|
41
70
|
if (interpreter !== "bun")
|
|
42
71
|
return interpreter;
|
|
43
|
-
if (
|
|
44
|
-
|
|
72
|
+
if (process.versions.bun) {
|
|
73
|
+
return isBunStandaloneMain() ? "bun-standalone" : "bun";
|
|
74
|
+
}
|
|
75
|
+
if (extension === ".js" || (extension === ".ts" && nodeStripsTypeScript())) {
|
|
76
|
+
return "node";
|
|
45
77
|
}
|
|
46
|
-
|
|
78
|
+
throw new UsageError(`Task v3 script target ${JSON.stringify(ref)} requires Bun for ${extension} execution, but this runtime cannot provide it.`, "TASK_TARGET_UNSUPPORTED");
|
|
47
79
|
}
|
|
48
80
|
export function captureDirectoryIdentity(bundleRoot, workingDirectory) {
|
|
49
81
|
try {
|
|
@@ -69,7 +101,7 @@ export function captureScriptTarget(ref, file, bundleRoot, readFile) {
|
|
|
69
101
|
const bytes = Uint8Array.from(raw);
|
|
70
102
|
const cwdIdentity = captureDirectoryIdentity(bundleRoot);
|
|
71
103
|
return Object.freeze({
|
|
72
|
-
interpreter: scriptInterpreter(extension, ref),
|
|
104
|
+
interpreter: scriptInterpreter(extension, ref, bytes),
|
|
73
105
|
extension,
|
|
74
106
|
bytesBase64: Buffer.from(bytes).toString("base64"),
|
|
75
107
|
byteLength: bytes.byteLength,
|
package/dist/tasks/schedule.js
CHANGED
|
@@ -15,10 +15,13 @@
|
|
|
15
15
|
* • a launchd plist `<StartCalendarInterval>` / `<StartInterval>` (macOS),
|
|
16
16
|
* • Task Scheduler XML triggers (Windows).
|
|
17
17
|
*
|
|
18
|
-
* The shared subset is `*`, single integers, `*\/N`, `A-B/N`,
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* day-of-week
|
|
18
|
+
* The shared subset is `*`, single integers, `*\/N`, `A-B`, `A-B/N`, comma
|
|
19
|
+
* lists, three-letter day/month names (`MON`, `JAN`) and name ranges
|
|
20
|
+
* (`MON-FRI`), plus the `@hourly / @daily / @weekly / @monthly / @yearly /
|
|
21
|
+
* @annually / @reboot` aliases. Day-of-month AND day-of-week combined in the
|
|
22
|
+
* same expression are rejected with a {@link UsageError} — cron gives that
|
|
23
|
+
* combination OR semantics no other backend can express portably, and it is
|
|
24
|
+
* genuinely ambiguous to a person reading the schedule back.
|
|
22
25
|
*
|
|
23
26
|
* Cron is the most permissive of the three backends; some patterns it
|
|
24
27
|
* accepts (e.g. `@hourly` = `0 * * * *`) have no clean schtasks primitive.
|
|
@@ -33,7 +36,58 @@ const ALIAS_TO_CRON = {
|
|
|
33
36
|
"@midnight": "0 0 * * *",
|
|
34
37
|
"@weekly": "0 0 * * 0",
|
|
35
38
|
"@monthly": "0 0 1 * *",
|
|
39
|
+
"@yearly": "0 0 1 1 *",
|
|
40
|
+
"@annually": "0 0 1 1 *",
|
|
36
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* vixie-cron's one true nickname with no 5-field equivalent — it fires once at
|
|
44
|
+
* daemon startup, not on a recurring calendar boundary. Passed straight
|
|
45
|
+
* through, unexpanded, on the cron backend (a real crontab line is just
|
|
46
|
+
* `@reboot <command>`); launchd and schtasks have no "run at boot" trigger in
|
|
47
|
+
* the vocabulary this module targets, so those backends reject it.
|
|
48
|
+
*/
|
|
49
|
+
const REBOOT_ALIAS = "@reboot";
|
|
50
|
+
/** Placeholder fields for the `@reboot` `ScheduleSpec` — never read: cron's translator emits `spec.cron` verbatim, and launchd/schtasks refuse `@reboot` before touching `fields`. */
|
|
51
|
+
const REBOOT_FIELDS = {
|
|
52
|
+
minute: { kind: "star" },
|
|
53
|
+
hour: { kind: "star" },
|
|
54
|
+
dom: { kind: "star" },
|
|
55
|
+
month: { kind: "star" },
|
|
56
|
+
dow: { kind: "star" },
|
|
57
|
+
};
|
|
58
|
+
const DOW_NAMES = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
59
|
+
const MONTH_NAMES = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
60
|
+
/**
|
|
61
|
+
* Substitute three-letter day-of-week / month names (and name ranges, e.g.
|
|
62
|
+
* `MON-FRI`) with their numeric cron equivalents, case-insensitively, so the
|
|
63
|
+
* existing numeric grammar below (value / range / list) parses the result
|
|
64
|
+
* unchanged. Tokens that are not recognized names pass through untouched —
|
|
65
|
+
* they are numbers already, or genuinely invalid and left for the numeric
|
|
66
|
+
* parsers to reject with their own message.
|
|
67
|
+
*/
|
|
68
|
+
function substituteNamedTokens(raw, fieldName) {
|
|
69
|
+
const names = fieldName === "month" ? MONTH_NAMES : DOW_NAMES;
|
|
70
|
+
const offset = fieldName === "month" ? 1 : 0;
|
|
71
|
+
const indexOf = (token) => {
|
|
72
|
+
const idx = names.indexOf(token.toLowerCase());
|
|
73
|
+
return idx === -1 ? undefined : idx + offset;
|
|
74
|
+
};
|
|
75
|
+
return raw
|
|
76
|
+
.split(",")
|
|
77
|
+
.map((part) => {
|
|
78
|
+
const rangeMatch = part.match(/^([A-Za-z]{3})-([A-Za-z]{3})$/);
|
|
79
|
+
if (rangeMatch) {
|
|
80
|
+
const start = indexOf(rangeMatch[1]);
|
|
81
|
+
const end = indexOf(rangeMatch[2]);
|
|
82
|
+
if (start !== undefined && end !== undefined)
|
|
83
|
+
return `${start}-${end}`;
|
|
84
|
+
return part;
|
|
85
|
+
}
|
|
86
|
+
const single = /^[A-Za-z]{3}$/.test(part) ? indexOf(part) : undefined;
|
|
87
|
+
return single !== undefined ? String(single) : part;
|
|
88
|
+
})
|
|
89
|
+
.join(",");
|
|
90
|
+
}
|
|
37
91
|
const FIELD_LIMITS = {
|
|
38
92
|
minute: { min: 0, max: 59 },
|
|
39
93
|
hour: { min: 0, max: 23 },
|
|
@@ -41,10 +95,17 @@ const FIELD_LIMITS = {
|
|
|
41
95
|
month: { min: 1, max: 12 },
|
|
42
96
|
dow: { min: 0, max: 6 },
|
|
43
97
|
};
|
|
44
|
-
const SUPPORTED_HINT = "Supported subset: `*`, single integers (`5`), steps (`*/N`, `A-B/N`), and comma lists
|
|
45
|
-
"
|
|
46
|
-
"
|
|
98
|
+
const SUPPORTED_HINT = "Supported subset: `*`, single integers (`5`), ranges (`A-B`), steps (`*/N`, `A-B/N`), and comma lists " +
|
|
99
|
+
"(`7,37`). Day-of-week and month fields also accept three-letter names and name ranges (`MON`, `MON-FRI`, " +
|
|
100
|
+
"`JAN`). Aliases: `@hourly`, `@daily`, `@weekly`, `@monthly`, `@yearly`/`@annually`, `@reboot` (cron only).";
|
|
47
101
|
export function parseSchedule(input, backend) {
|
|
102
|
+
const trimmed = input.trim();
|
|
103
|
+
if (trimmed.toLowerCase() === REBOOT_ALIAS) {
|
|
104
|
+
if (backend !== "cron") {
|
|
105
|
+
throw new UsageError(`Schedule "${input}" (@reboot, run once at startup) has no ${backend === "launchd" ? "macOS launchd" : "Windows Task Scheduler"} equivalent this release expresses. Use a cron-backed install, or rewrite the task with a recurring schedule.`, "INVALID_FLAG_VALUE");
|
|
106
|
+
}
|
|
107
|
+
return { raw: input, cron: REBOOT_ALIAS, fields: REBOOT_FIELDS };
|
|
108
|
+
}
|
|
48
109
|
const cron = expandAlias(input);
|
|
49
110
|
const fields = parseCronFields(cron, input);
|
|
50
111
|
const spec = { raw: input, cron, fields };
|
|
@@ -84,7 +145,8 @@ function parseCronFields(cron, original) {
|
|
|
84
145
|
dow: parseField(dow, "day-of-week", FIELD_LIMITS.dow, original),
|
|
85
146
|
};
|
|
86
147
|
}
|
|
87
|
-
function parseField(
|
|
148
|
+
function parseField(rawInput, name, limit, original) {
|
|
149
|
+
const raw = name === "month" || name === "day-of-week" ? substituteNamedTokens(rawInput, name) : rawInput;
|
|
88
150
|
if (raw === "*")
|
|
89
151
|
return { kind: "star" };
|
|
90
152
|
const stepMatch = raw.match(/^\*\/(\d+)$/);
|
|
@@ -109,6 +171,19 @@ function parseField(raw, name, limit, original) {
|
|
|
109
171
|
}
|
|
110
172
|
return { kind: "rangeStep", start, end, step };
|
|
111
173
|
}
|
|
174
|
+
// Plain range, no step: `A-B` (e.g. `1-5` for Mon-Fri, `1-5` for the first
|
|
175
|
+
// five days of the month). Represented as a `rangeStep` with `step: 1` so
|
|
176
|
+
// every downstream consumer (verbatim cron passthrough, launchd/schtasks
|
|
177
|
+
// expansion) reuses the exact same handling a stepped range already gets.
|
|
178
|
+
const rangeMatch = raw.match(/^(\d+)-(\d+)$/);
|
|
179
|
+
if (rangeMatch) {
|
|
180
|
+
const start = Number(rangeMatch[1]);
|
|
181
|
+
const end = Number(rangeMatch[2]);
|
|
182
|
+
if (start < limit.min || end > limit.max || start > end) {
|
|
183
|
+
throw new UsageError(`Invalid ${name} range "${raw}" in schedule "${original}" (allowed ${limit.min}-${limit.max}).`, "INVALID_FLAG_VALUE");
|
|
184
|
+
}
|
|
185
|
+
return { kind: "rangeStep", start, end, step: 1 };
|
|
186
|
+
}
|
|
112
187
|
if (/^\d+$/.test(raw)) {
|
|
113
188
|
const value = Number(raw);
|
|
114
189
|
if (value < limit.min || value > limit.max) {
|
|
@@ -161,6 +236,42 @@ export function translateToLaunchd(spec) {
|
|
|
161
236
|
})),
|
|
162
237
|
};
|
|
163
238
|
}
|
|
239
|
+
// A day-of-week or month range/list (`1-5` for Mon-Fri, `1,3,5`) has no
|
|
240
|
+
// single-dict launchd primitive either, but — unlike a step — it names a
|
|
241
|
+
// small, closed set of concrete values, so it genuinely IS expressible: one
|
|
242
|
+
// calendar dict per (month, weekday) combination, same trick as the
|
|
243
|
+
// minute/hour step expansion above. Only attempted when the remaining
|
|
244
|
+
// fields are already single values or `*`; anything else (e.g. a minute
|
|
245
|
+
// step combined with a weekday range) falls through to the generic path
|
|
246
|
+
// below, where `rejectStepInsideCalendar` reports the field it actually
|
|
247
|
+
// cannot express.
|
|
248
|
+
const dowValues = expandListLikeField(f.dow, FIELD_LIMITS.dow);
|
|
249
|
+
const monthValues = expandListLikeField(f.month, FIELD_LIMITS.month);
|
|
250
|
+
const remainingFieldsAreSimple = (f.minute.kind === "value" || f.minute.kind === "star") &&
|
|
251
|
+
(f.hour.kind === "value" || f.hour.kind === "star") &&
|
|
252
|
+
(f.dom.kind === "value" || f.dom.kind === "star");
|
|
253
|
+
if ((dowValues || monthValues) && remainingFieldsAreSimple) {
|
|
254
|
+
const base = {};
|
|
255
|
+
if (f.minute.kind === "value")
|
|
256
|
+
base.Minute = f.minute.value;
|
|
257
|
+
if (f.hour.kind === "value")
|
|
258
|
+
base.Hour = f.hour.value;
|
|
259
|
+
if (f.dom.kind === "value")
|
|
260
|
+
base.Day = f.dom.value;
|
|
261
|
+
const months = monthValues ?? (f.month.kind === "value" ? [f.month.value] : [undefined]);
|
|
262
|
+
const weekdays = dowValues ?? (f.dow.kind === "value" ? [f.dow.value] : [undefined]);
|
|
263
|
+
const calendars = [];
|
|
264
|
+
for (const month of months) {
|
|
265
|
+
for (const weekday of weekdays) {
|
|
266
|
+
calendars.push({
|
|
267
|
+
...base,
|
|
268
|
+
...(month !== undefined ? { Month: month } : {}),
|
|
269
|
+
...(weekday !== undefined ? { Weekday: weekday } : {}),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return { calendars };
|
|
274
|
+
}
|
|
164
275
|
// Otherwise build a calendar dict from concrete values. launchd treats any
|
|
165
276
|
// omitted key as "every value", so a `*` field translates to "no key".
|
|
166
277
|
// Exception: launchd does not support arbitrary step values inside a
|
|
@@ -199,12 +310,21 @@ function expandFieldValues(field, limit) {
|
|
|
199
310
|
values.push(value);
|
|
200
311
|
return values;
|
|
201
312
|
}
|
|
313
|
+
/** Discrete values named by a `list` or (stepless) `rangeStep` field; `null` for anything else (`*`, `value`, `step`). */
|
|
314
|
+
function expandListLikeField(field, limit) {
|
|
315
|
+
if (field.kind === "list")
|
|
316
|
+
return field.values;
|
|
317
|
+
if (field.kind === "rangeStep")
|
|
318
|
+
return expandFieldValues(field, limit);
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
202
321
|
function rejectStepInsideCalendar(field, name, spec) {
|
|
203
322
|
if (field.kind === "step") {
|
|
204
323
|
throw new UsageError(`Schedule "${spec.raw}" uses step (${name} = */N) in a position macOS launchd cannot express. ${SUPPORTED_HINT}`, "INVALID_FLAG_VALUE", "Either restrict the step to the minute or hour field only, or rewrite the schedule with concrete values.");
|
|
205
324
|
}
|
|
206
325
|
if (field.kind === "rangeStep") {
|
|
207
|
-
|
|
326
|
+
const shape = field.step === 1 ? "A-B" : "A-B/N";
|
|
327
|
+
throw new UsageError(`Schedule "${spec.raw}" uses a range (${name} = ${shape}) in a position macOS launchd cannot express. ${SUPPORTED_HINT}`, "INVALID_FLAG_VALUE", "Restrict the range to the minute, hour, day-of-week, or month field, or rewrite the schedule with a concrete value.");
|
|
208
328
|
}
|
|
209
329
|
if (field.kind === "list") {
|
|
210
330
|
throw new UsageError(`Schedule "${spec.raw}" uses comma list (${name} = a,b,...) which macOS launchd cannot express as a single trigger. ${SUPPORTED_HINT}`, "INVALID_FLAG_VALUE", "Either install one task per list element, or rewrite the schedule with a step (`*/N`) or single value.");
|
|
@@ -286,20 +406,41 @@ export function translateToSchtasks(spec) {
|
|
|
286
406
|
f.dow.kind === "star") {
|
|
287
407
|
return { kind: "daily", atHour: f.hour.value, atMinute: f.minute.value };
|
|
288
408
|
}
|
|
289
|
-
// `M H * * D` → WEEKLY at H:M on day D
|
|
409
|
+
// `M H * * D` → WEEKLY at H:M on day(s) D — a single day, a plain range
|
|
410
|
+
// (`1-5`, e.g. from `MON-FRI`), or a comma list all name a small closed set
|
|
411
|
+
// of weekdays that Task Scheduler's native `<DaysOfWeek>` already takes as
|
|
412
|
+
// a set, so no expansion into multiple triggers is needed.
|
|
290
413
|
if (f.minute.kind === "value" &&
|
|
291
414
|
f.hour.kind === "value" &&
|
|
292
415
|
f.dom.kind === "star" &&
|
|
293
416
|
f.month.kind === "star" &&
|
|
294
|
-
f.dow.kind === "value") {
|
|
417
|
+
(f.dow.kind === "value" || f.dow.kind === "list" || f.dow.kind === "rangeStep")) {
|
|
418
|
+
const daysOfWeek = f.dow.kind === "value" ? [f.dow.value] : expandListLikeField(f.dow, FIELD_LIMITS.dow);
|
|
295
419
|
return {
|
|
296
420
|
kind: "weekly",
|
|
297
421
|
atHour: f.hour.value,
|
|
298
422
|
atMinute: f.minute.value,
|
|
299
|
-
daysOfWeek
|
|
423
|
+
daysOfWeek,
|
|
300
424
|
};
|
|
301
425
|
}
|
|
302
|
-
|
|
426
|
+
// `M H D * *` / `M H D m *` → MONTHLY at H:M on day(s)-of-month D, in the
|
|
427
|
+
// given month(s) m (or every month when `m` is `*`). Task Scheduler's
|
|
428
|
+
// `ScheduleByMonth` trigger takes both as native sets, same as `ScheduleByWeek`
|
|
429
|
+
// above.
|
|
430
|
+
if (f.minute.kind === "value" &&
|
|
431
|
+
f.hour.kind === "value" &&
|
|
432
|
+
(f.dom.kind === "value" || f.dom.kind === "list") &&
|
|
433
|
+
(f.month.kind === "star" || f.month.kind === "value" || f.month.kind === "list") &&
|
|
434
|
+
f.dow.kind === "star") {
|
|
435
|
+
const daysOfMonth = f.dom.kind === "value" ? [f.dom.value] : f.dom.values;
|
|
436
|
+
const months = f.month.kind === "star"
|
|
437
|
+
? Array.from({ length: 12 }, (_, i) => i + 1)
|
|
438
|
+
: f.month.kind === "value"
|
|
439
|
+
? [f.month.value]
|
|
440
|
+
: f.month.values;
|
|
441
|
+
return { kind: "monthly", atHour: f.hour.value, atMinute: f.minute.value, daysOfMonth, months };
|
|
442
|
+
}
|
|
443
|
+
throw new UsageError(`Schedule "${spec.raw}" cannot be expressed as a Windows Task Scheduler trigger. ${SUPPORTED_HINT}`, "INVALID_FLAG_VALUE", "Use one of: minute steps/range-steps, fixed-minute hour steps/range-steps, hourly, daily, weekly on one or more weekdays, or monthly on one or more days-of-month.");
|
|
303
444
|
}
|
|
304
445
|
function minuteValuesTrigger(minutes, spec) {
|
|
305
446
|
if (minutes.length > MAX_SCHTASKS_TRIGGERS) {
|
|
@@ -323,27 +323,9 @@ async function compileTaskSources(input, collector, out, failures) {
|
|
|
323
323
|
});
|
|
324
324
|
const document = projectTaskSourceV4(parsed.v4);
|
|
325
325
|
const qualifiedRef = makeBundleRef(input.bundleName, conceptId);
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
|
|
329
|
-
// applyInputDefaults + validateInputs pair akm task run uses
|
|
330
|
-
// (src/tasks/run/load-task.ts). parseTaskSource's own parse-time check
|
|
331
|
-
// (task-source-v4.ts's parseScheduleEntry) already rejects an
|
|
332
|
-
// unknown/malformed entry against the RAW supplied values; this is a
|
|
333
|
-
// deliberate second, independent gate over the DEFAULTED view — the
|
|
334
|
-
// exact set of values the compiled invocation below actually delivers
|
|
335
|
-
// — so a violation fails HERE, recorded as a task failure at sync,
|
|
336
|
-
// rather than surfacing for the first time when the scheduler fires
|
|
337
|
-
// the compiled invocation.
|
|
338
|
-
const contract = parsed.v4.inputs ?? {};
|
|
339
|
-
for (const scheduleEntry of parsed.v4.schedule) {
|
|
340
|
-
const defaultedInputs = applyInputDefaults(contract, { ...scheduleEntry.inputs });
|
|
341
|
-
const errors = validateInputs(contract, defaultedInputs);
|
|
342
|
-
if (errors.length > 0) {
|
|
343
|
-
throw new UsageError(`Task ${JSON.stringify(qualifiedRef)} schedule[${scheduleEntry.ordinal}].inputs does not satisfy ` +
|
|
344
|
-
`its declared inputs once defaults are applied: ${errors.join("; ")}`, "TASK_SOURCE_INVALID");
|
|
345
|
-
}
|
|
346
|
-
}
|
|
326
|
+
// See assertTaskScheduleInputsSatisfyContract's own docblock (below in
|
|
327
|
+
// this file) for why this second, defaults-applied gate exists.
|
|
328
|
+
assertTaskScheduleInputsSatisfyContract(parsed.v4, qualifiedRef);
|
|
347
329
|
await prepareTaskV3Execution(document, {
|
|
348
330
|
taskId: id,
|
|
349
331
|
taskRef: qualifiedRef,
|
|
@@ -380,16 +362,60 @@ async function compileTaskSources(input, collector, out, failures) {
|
|
|
380
362
|
inputs: schedule.inputs,
|
|
381
363
|
})),
|
|
382
364
|
});
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
out.push(binding);
|
|
386
|
-
}
|
|
365
|
+
assertTaskScheduleCronValid(parsed.v4, input.backend);
|
|
366
|
+
out.push(...sourceBindings);
|
|
387
367
|
}
|
|
388
368
|
catch (cause) {
|
|
389
369
|
failures.push(taskFailure(sourcePath, qualifiedRefForFailure, cause));
|
|
390
370
|
}
|
|
391
371
|
}
|
|
392
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* P2b Lane B (spec §4.4, rows B-50/F-B2): validate every v4 `schedule:`
|
|
375
|
+
* entry's `inputs` against the task's OWN declared contract WITH DEFAULTS
|
|
376
|
+
* APPLIED — the same `applyInputDefaults` + `validateInputs` pair
|
|
377
|
+
* `akm task run` uses (`src/tasks/run/load-task.ts`). `parseTaskSource`'s
|
|
378
|
+
* own parse-time check (`task-source-v4.ts`'s `parseScheduleEntry`) already
|
|
379
|
+
* rejects an unknown/malformed entry against the RAW supplied values; this
|
|
380
|
+
* is a deliberate second, independent gate over the DEFAULTED view — the
|
|
381
|
+
* exact set of values a compiled invocation actually delivers — so a
|
|
382
|
+
* violation fails HERE, recorded as a task failure at sync, rather than
|
|
383
|
+
* surfacing for the first time when the scheduler fires the invocation.
|
|
384
|
+
*
|
|
385
|
+
* Extracted so `akm task validate` can run the IDENTICAL gate
|
|
386
|
+
* over a bare file path without a second, potentially-diverging copy of
|
|
387
|
+
* this check. `refLabel` is only the text embedded in the thrown message —
|
|
388
|
+
* `compileTaskSources` passes its bundle-qualified ref; `akm task validate`,
|
|
389
|
+
* which never resolves a bundle for a bare file, passes the file path.
|
|
390
|
+
*/
|
|
391
|
+
export function assertTaskScheduleInputsSatisfyContract(v4, refLabel) {
|
|
392
|
+
const contract = v4.inputs ?? {};
|
|
393
|
+
for (const scheduleEntry of v4.schedule) {
|
|
394
|
+
const defaultedInputs = applyInputDefaults(contract, { ...scheduleEntry.inputs });
|
|
395
|
+
const errors = validateInputs(contract, defaultedInputs);
|
|
396
|
+
if (errors.length > 0) {
|
|
397
|
+
throw new UsageError(`Task ${JSON.stringify(refLabel)} schedule[${scheduleEntry.ordinal}].inputs does not satisfy ` +
|
|
398
|
+
`its declared inputs once defaults are applied: ${errors.join("; ")}`, "TASK_SOURCE_INVALID");
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Validate every v4 `schedule:` entry's `cron` against the active scheduler
|
|
404
|
+
* backend's dialect (`parseSchedule`, `./schedule.ts`) — cron is the most
|
|
405
|
+
* permissive of the three backends, so a task authored on Linux can carry a
|
|
406
|
+
* cron expression launchd/schtasks cannot translate; `compileTaskSources`
|
|
407
|
+
* re-checks against the LOCAL backend on every sync rather than trusting
|
|
408
|
+
* whatever backend the file was authored against.
|
|
409
|
+
*
|
|
410
|
+
* Extracted alongside {@link assertTaskScheduleInputsSatisfyContract}
|
|
411
|
+
* so `akm task validate` shares this exact gate instead of a second copy
|
|
412
|
+
* that could silently drift from what `akm task sync` actually enforces.
|
|
413
|
+
*/
|
|
414
|
+
export function assertTaskScheduleCronValid(v4, backend) {
|
|
415
|
+
for (const scheduleEntry of v4.schedule) {
|
|
416
|
+
parseSchedule(scheduleEntry.cron, backend);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
393
419
|
async function compileWorkflowSources(input, collector, out, evidence, failures) {
|
|
394
420
|
if (input.adapterId !== "akm" && input.adapterId !== "akm-workflow")
|
|
395
421
|
return;
|
|
@@ -377,7 +377,6 @@ export function parseTaskV3Document(value, options) {
|
|
|
377
377
|
if (own(input, "with"))
|
|
378
378
|
sourceError(ctx, ["with"], "is legal only with uses.");
|
|
379
379
|
const run = stringField(input.run, ctx, ["run"], { nonempty: true });
|
|
380
|
-
noGithubExpression(run, ctx, ["run"]);
|
|
381
380
|
let shell;
|
|
382
381
|
if (own(input, "shell")) {
|
|
383
382
|
const rawShell = stringField(input.shell, ctx, ["shell"], { nonempty: true });
|
|
@@ -259,7 +259,6 @@ function parseTarget(input, ctx) {
|
|
|
259
259
|
if (own(input, "with"))
|
|
260
260
|
sourceError(ctx, ["with"], "is legal only with uses: akm/command; declare typed inputs: instead.");
|
|
261
261
|
const run = stringField(input.run, ctx, ["run"], { nonempty: true });
|
|
262
|
-
noGithubExpression(run, ctx, ["run"]);
|
|
263
262
|
let shell;
|
|
264
263
|
if (own(input, "shell")) {
|
|
265
264
|
const rawShell = stringField(input.shell, ctx, ["shell"], { nonempty: true });
|
|
@@ -250,9 +250,8 @@ async function driveChildRun(input, childRow) {
|
|
|
250
250
|
// (dispatchJournaledAttempt awaits this call with no try of its own),
|
|
251
251
|
// so an uncaught throw here escaped all the way into the scheduler and
|
|
252
252
|
// was silently swallowed (R1, above). Reachable causes include the
|
|
253
|
-
// child's own LeaseHeartbeat.assertAlive() firing mid-drive,
|
|
254
|
-
//
|
|
255
|
-
// WORKFLOW_OUTPUT_INVALID), requireExecutableWorkflowPlan rejecting a
|
|
253
|
+
// child's own LeaseHeartbeat.assertAlive() firing mid-drive,
|
|
254
|
+
// requireExecutableWorkflowPlan rejecting a
|
|
256
255
|
// tampered child plan_json, and the child's status changing between
|
|
257
256
|
// this function's own step 5 read and the drive's internal
|
|
258
257
|
// getNextWorkflowStep re-read — none of which match
|
|
@@ -15,21 +15,23 @@
|
|
|
15
15
|
* @module workflows/exec/dispatch-redaction
|
|
16
16
|
*/
|
|
17
17
|
import { collectSensitiveValues, isEnvPassthroughValueSafeToExpose, redactSensitiveText, redactSensitiveValue, } from "../../core/redaction.js";
|
|
18
|
+
import { lookupApiKeyFileValue } from "../../integrations/agent/engine-resolution.js";
|
|
18
19
|
/**
|
|
19
20
|
* Every exact value that must never survive into the journal from ONE frozen
|
|
20
21
|
* dispatch: the resolved `env` bindings injected into the child, the selected
|
|
21
|
-
* engine's (and its SDK fallback's) credential env
|
|
22
|
-
* `envPassthrough` value the redaction
|
|
22
|
+
* engine's (and its SDK fallback's) credential — an env value, or a
|
|
23
|
+
* file-backed one (#905) — and any `envPassthrough` value the redaction
|
|
24
|
+
* policy does not consider safe to expose.
|
|
23
25
|
*
|
|
24
26
|
* Shared by the unit path and the gate-judge path. There is deliberately ONE
|
|
25
27
|
* collector: a second, parallel implementation is exactly how a dispatch path
|
|
26
28
|
* silently loses the scrub.
|
|
27
29
|
*
|
|
28
|
-
* The credential values are read from `process.env`
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* the set.
|
|
30
|
+
* The credential values are read from `process.env` (or disk, for a file-
|
|
31
|
+
* backed one) AT CALL TIME, so a caller must collect no earlier than the
|
|
32
|
+
* dispatch whose outcome it scrubs. A snapshot taken when the dispatch was
|
|
33
|
+
* merely *planned* can predate a credential the dispatch then resolves live,
|
|
34
|
+
* leaving the exact value it must remove out of the set.
|
|
33
35
|
*/
|
|
34
36
|
export function collectWorkflowDispatchSensitiveValues(dispatch, env) {
|
|
35
37
|
const values = new Set([...Object.values(env ?? {}), ...(dispatch.sensitiveValues ?? [])]);
|
|
@@ -42,6 +44,13 @@ export function collectWorkflowDispatchSensitiveValues(dispatch, env) {
|
|
|
42
44
|
if (value)
|
|
43
45
|
values.add(value);
|
|
44
46
|
}
|
|
47
|
+
// #905: file-backed credential — best-effort read, never throws, so a
|
|
48
|
+
// broken apiKeyFile is reported by the real dispatch, not this collector.
|
|
49
|
+
if (runner.apiKeyFile) {
|
|
50
|
+
const value = lookupApiKeyFileValue(runner.apiKeyFile);
|
|
51
|
+
if (value)
|
|
52
|
+
values.add(value);
|
|
53
|
+
}
|
|
45
54
|
return;
|
|
46
55
|
}
|
|
47
56
|
for (const name of runner.profile.envPassthrough ?? []) {
|
|
@@ -55,6 +64,11 @@ export function collectWorkflowDispatchSensitiveValues(dispatch, env) {
|
|
|
55
64
|
if (value)
|
|
56
65
|
values.add(value);
|
|
57
66
|
}
|
|
67
|
+
if (runner.fallbackApiKeyFile) {
|
|
68
|
+
const value = lookupApiKeyFileValue(runner.fallbackApiKeyFile);
|
|
69
|
+
if (value)
|
|
70
|
+
values.add(value);
|
|
71
|
+
}
|
|
58
72
|
}
|
|
59
73
|
};
|
|
60
74
|
addCredential(dispatch.runner);
|
|
@@ -220,10 +220,9 @@ function truncationNote(read) {
|
|
|
220
220
|
* The captured stdout, with an unmistakable truncation block appended when the
|
|
221
221
|
* retention cap discarded part of it.
|
|
222
222
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* is missing rather than inferring it from a suspiciously round length.
|
|
223
|
+
* Truncated data must never be mistakable for complete data. The block names
|
|
224
|
+
* both byte counts, so a reader can see exactly how much is missing rather
|
|
225
|
+
* than inferring it from a suspiciously round length.
|
|
227
226
|
*/
|
|
228
227
|
function markTruncatedStdout(result) {
|
|
229
228
|
const read = result.stdoutRead;
|
|
@@ -36,6 +36,10 @@ export async function runWorkflowSteps(options) {
|
|
|
36
36
|
let target = options.target;
|
|
37
37
|
let params = options.params;
|
|
38
38
|
let parameterFlags = options.parameterFlags;
|
|
39
|
+
// `--new` only applies to the FIRST resolution of `target` (a ref); every
|
|
40
|
+
// retry re-targets the run id `startWorkflowRun` already created, so it is
|
|
41
|
+
// cleared alongside `params`/`parameterFlags` below (#919).
|
|
42
|
+
let newRun = options.newRun;
|
|
39
43
|
let remainingRetries = options.maxRetries ?? 0;
|
|
40
44
|
let remainingSteps = options.maxSteps;
|
|
41
45
|
const executed = [];
|
|
@@ -51,6 +55,7 @@ export async function runWorkflowSteps(options) {
|
|
|
51
55
|
target,
|
|
52
56
|
...(params !== undefined ? { params } : { params: undefined }),
|
|
53
57
|
...(parameterFlags !== undefined ? { parameterFlags } : { parameterFlags: undefined }),
|
|
58
|
+
newRun,
|
|
54
59
|
...(remainingSteps !== undefined ? { maxSteps: remainingSteps } : { maxSteps: undefined }),
|
|
55
60
|
}, liveEvidence);
|
|
56
61
|
executed.push(...result.executed);
|
|
@@ -72,12 +77,14 @@ export async function runWorkflowSteps(options) {
|
|
|
72
77
|
target = result.run.id;
|
|
73
78
|
params = undefined;
|
|
74
79
|
parameterFlags = undefined;
|
|
80
|
+
newRun = undefined;
|
|
75
81
|
remainingRetries -= 1;
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
async function runWorkflowAttempt(options, liveEvidence) {
|
|
79
85
|
const next = await getNextWorkflowStep(options.target, options.params, {
|
|
80
86
|
parameterFlags: options.parameterFlags,
|
|
87
|
+
newRun: options.newRun,
|
|
81
88
|
});
|
|
82
89
|
// Version/canonical/hash validation precedes every executable mutation,
|
|
83
90
|
// including lease acquisition. Historical rows remain inspectable/abandonable.
|
|
@@ -137,8 +144,14 @@ async function runWorkflowAttempt(options, liveEvidence) {
|
|
|
137
144
|
const result = await withWorkflowRunsConnection(() => driveRun(options, next, leaseHolder, heartbeat, liveEvidence));
|
|
138
145
|
// Creation-time notices reach the caller only here: the run row has no
|
|
139
146
|
// warnings column, and a later invocation of the same run must stay silent
|
|
140
|
-
// about a decision it did not make. `driveRun` never sets `warnings
|
|
141
|
-
|
|
147
|
+
// about a decision it did not make. `driveRun` never sets `warnings` or
|
|
148
|
+
// `resumed` — both are properties of THIS resolution of `target`, not of
|
|
149
|
+
// the run row (#919).
|
|
150
|
+
return {
|
|
151
|
+
...result,
|
|
152
|
+
...(next.resumed ? { resumed: true } : {}),
|
|
153
|
+
...(next.startWarnings?.length ? { warnings: next.startWarnings } : {}),
|
|
154
|
+
};
|
|
142
155
|
}
|
|
143
156
|
finally {
|
|
144
157
|
heartbeat?.stop();
|
|
@@ -639,14 +652,10 @@ async function driveRun(options, initial, leaseHolder, heartbeat,
|
|
|
639
652
|
/**
|
|
640
653
|
* The COMPLETE in-memory evidence of every step THIS call has completed,
|
|
641
654
|
* keyed by step id, preferred over the re-read row when the downstream scope
|
|
642
|
-
* is rebuilt below
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
* retains 8 MiB). Preferring the live value keeps the persistence bound
|
|
647
|
-
* invisible to the run that produced it. A LATER `akm workflow run` starts
|
|
648
|
-
* with an empty map and reads the rows, where a reference into a truncated
|
|
649
|
-
* artifact fails loudly by name (`isTruncatedEvidence`).
|
|
655
|
+
* is rebuilt below — avoiding a re-parse of a row this same invocation just
|
|
656
|
+
* wrote (step artifacts are persisted whole, so the two values agree; this
|
|
657
|
+
* is purely an avoided round trip, not a correctness dependency). A LATER
|
|
658
|
+
* `akm workflow run` starts with an empty map and reads the rows directly.
|
|
650
659
|
*
|
|
651
660
|
* Only steps some OTHER step's references NAME are stored (`referencedStepIds`
|
|
652
661
|
* — the set-time filter): a step nothing downstream reads has no consumer to
|