specdojo 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/agents/specdojo-orchestrator.md +4 -1
- package/CHANGELOG.md +64 -0
- package/dist/catalog/catalog.js +16 -14
- package/dist/commands/agent.js +5 -3
- package/dist/commands/build.js +69 -10
- package/dist/commands/git.js +206 -0
- package/dist/commands/init.js +4 -2
- package/dist/commands/where.js +25 -0
- package/dist/dashboard/dashboard.js +5 -3
- package/dist/dashboard/routines.js +4 -7
- package/dist/dashboard/timeline.js +14 -14
- package/dist/docs/index-command.js +2 -2
- package/dist/docs/yaml-business-tables.js +243 -0
- package/dist/docs/yaml-interface-tables.js +106 -0
- package/dist/docs/yaml-pages-command.js +5 -3
- package/dist/docs/yaml-pages.js +146 -3
- package/dist/docs/yaml-table-shared.js +70 -0
- package/dist/docs/yaml-tables.js +39 -0
- package/dist/exec/agent-config.js +9 -0
- package/dist/exec/agent-protected-config.js +2 -0
- package/dist/exec/commands.js +31 -18
- package/dist/exec/events.js +34 -14
- package/dist/exec/evidence.js +13 -3
- package/dist/exec/parent-validation.js +56 -3
- package/dist/exec/plans-core.js +21 -2
- package/dist/exec/plans-generation.js +6 -7
- package/dist/exec/post-integration.js +162 -0
- package/dist/exec/queue-command.js +166 -0
- package/dist/exec/queue.js +285 -0
- package/dist/exec/register-foreign-wait.js +84 -0
- package/dist/exec/repo-integration-sync.js +17 -5
- package/dist/exec/reporter.js +2 -2
- package/dist/exec/results.js +24 -4
- package/dist/exec/review-kata.js +4 -1
- package/dist/exec/run/agent-pipeline.js +3 -2
- package/dist/exec/run/agent.js +12 -6
- package/dist/exec/run/change-scope.js +365 -0
- package/dist/exec/run/deferred-cleanup.js +31 -0
- package/dist/exec/run/in-place.js +4 -1
- package/dist/exec/run/job-lock.js +66 -0
- package/dist/exec/run/job-sequence.js +137 -0
- package/dist/exec/run/job.js +56 -19
- package/dist/exec/run/lifecycle-commands.js +1 -1
- package/dist/exec/run/lock.js +22 -1
- package/dist/exec/run/register-command.js +8 -5
- package/dist/exec/run/register-mode.js +68 -8
- package/dist/exec/run/register-resume.js +68 -14
- package/dist/exec/run/register-state.js +13 -8
- package/dist/exec/run/register-worktree.js +140 -125
- package/dist/exec/run/schedule-mode.js +75 -14
- package/dist/exec/run/schedule-prepare.js +3 -0
- package/dist/exec/run/schedule-task.js +88 -38
- package/dist/exec/run/shared.js +5 -0
- package/dist/exec/schedule/schedule.js +116 -4
- package/dist/exec/shared.js +1 -1
- package/dist/exec/smoke.js +190 -0
- package/dist/exec/strategy.js +13 -3
- package/dist/exec/task-view.js +6 -4
- package/dist/exec/trial-commands.js +5 -2
- package/dist/exec/trial-core.js +6 -1
- package/dist/exec/validation-metrics.js +181 -0
- package/dist/exec/worktree-cleanup-lock.js +26 -0
- package/dist/exec/worktree-command.js +9 -1
- package/dist/exec/worktree-ops-commit.js +2 -2
- package/dist/exec/worktree.js +13 -2
- package/dist/grade/command-apply.js +3 -3
- package/dist/grade/command-inspect.js +5 -3
- package/dist/grade/command-plan.js +1 -1
- package/dist/grade/command-run.js +5 -1
- package/dist/grade/run.js +64 -8
- package/dist/job/definition.js +84 -8
- package/dist/job/job.js +79 -23
- package/dist/register/authoring-sources.js +22 -16
- package/dist/register/maintenance-commands.js +2 -2
- package/dist/register/register.js +31 -7
- package/dist/routine/definition.js +9 -0
- package/dist/routine/routine.js +137 -43
- package/dist/routine/status.js +62 -0
- package/dist/schedule/schedule.js +38 -39
- package/dist/shared/agent-types.js +5 -0
- package/dist/shared/cross-process-lock.js +9 -1
- package/dist/shared/dist-freshness.js +8 -2
- package/dist/shared/git-environment.js +2 -1
- package/dist/shared/git.js +44 -1
- package/dist/shared/lefthook-scaffold.js +3 -0
- package/dist/shared/local-config.js +244 -0
- package/dist/shared/specdojo-config.js +34 -20
- package/dist/shared/specdojo-gitignore.js +1 -0
- package/dist/shared/text.js +9 -1
- package/dist/shared/where-alias.js +13 -0
- package/dist/specdojo.js +4 -0
- package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +2 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +23 -4
- package/docs/ja/specdojo/guides/exec-operation-guide.md +44 -1
- package/docs/ja/specdojo/guides/job-sequence-guide.md +77 -0
- package/docs/ja/specdojo/guides/quick-start-guide.md +3 -3
- package/docs/ja/specdojo/guides/register-operation-guide.md +1 -1
- package/docs/ja/specdojo/guides/routine-operation-guide.md +11 -6
- package/docs/ja/specdojo/guides/schedule-design-guide.md +20 -17
- package/docs/ja/specdojo/guides/waza-guide.md +12 -8
- package/docs/ja/specdojo/recipes/bac-recipe.md +66 -49
- package/docs/ja/specdojo/recipes/bes-recipe.md +90 -54
- package/docs/ja/specdojo/recipes/bps-recipe.md +88 -139
- package/docs/ja/specdojo/recipes/br-recipe.md +40 -47
- package/docs/ja/specdojo/recipes/cdfd-overview-recipe.md +97 -109
- package/docs/ja/specdojo/recipes/cdfd-recipe.md +85 -146
- package/docs/ja/specdojo/recipes/cdfd-uc-recipe.md +91 -110
- package/docs/ja/specdojo/recipes/cnd-recipe.md +79 -69
- package/docs/ja/specdojo/recipes/cpd-recipe.md +78 -64
- package/docs/ja/specdojo/recipes/cxd-recipe.md +92 -75
- package/docs/ja/specdojo/recipes/ifd-recipe.md +79 -68
- package/docs/ja/specdojo/recipes/ifx-cmd-recipe.md +78 -105
- package/docs/ja/specdojo/recipes/ifx-index-recipe.md +105 -71
- package/docs/ja/specdojo/recipes/pm-communication-plan-recipe.md +60 -49
- package/docs/ja/specdojo/recipes/pm-members-recipe.md +50 -51
- package/docs/ja/specdojo/recipes/pm-organization-recipe.md +59 -51
- package/docs/ja/specdojo/recipes/pm-plan-recipe.md +69 -56
- package/docs/ja/specdojo/recipes/pm-quality-management-plan-recipe.md +37 -56
- package/docs/ja/specdojo/recipes/pm-raci-recipe.md +39 -53
- package/docs/ja/specdojo/recipes/pm-roles-recipe.md +52 -79
- package/docs/ja/specdojo/recipes/prj-assumptions-constraints-dependencies-recipe.md +64 -93
- package/docs/ja/specdojo/recipes/prj-charter-recipe.md +71 -106
- package/docs/ja/specdojo/recipes/prj-comparison-of-alternatives-recipe.md +78 -157
- package/docs/ja/specdojo/recipes/prj-issues-and-approach-recipe.md +62 -111
- package/docs/ja/specdojo/recipes/prj-scope-recipe.md +67 -123
- package/docs/ja/specdojo/recipes/prj-stakeholder-register-recipe.md +60 -96
- package/docs/ja/specdojo/recipes/prj-success-criteria-and-acceptance-criteria-recipe.md +61 -105
- package/docs/ja/specdojo/recipes/stsd-recipe.md +79 -109
- package/docs/ja/specdojo/recipes/sysd-critical-flows-recipe.md +78 -55
- package/docs/ja/specdojo/recipes/sysd-cross-cutting-policy-recipe.md +82 -73
- package/docs/ja/specdojo/recipes/sysd-index-recipe.md +78 -59
- package/docs/ja/specdojo/recipes/tsd-recipe.md +149 -129
- package/docs/ja/specdojo/references/command-reference.md +257 -117
- package/docs/ja/specdojo/references/deliverables-reference.md +21 -12
- package/docs/ja/specdojo/references/specdojo-config-reference.md +37 -2
- package/docs/ja/specdojo/rulebooks/atc-index-rulebook.md +101 -257
- package/docs/ja/specdojo/rulebooks/atc-rulebook.md +102 -228
- package/docs/ja/specdojo/rulebooks/bac-rulebook.md +19 -28
- package/docs/ja/specdojo/rulebooks/bdd-rulebook.md +16 -67
- package/docs/ja/specdojo/rulebooks/bds-rulebook.md +30 -51
- package/docs/ja/specdojo/rulebooks/bes-index-rulebook.md +41 -61
- package/docs/ja/specdojo/rulebooks/bes-rulebook.md +22 -50
- package/docs/ja/specdojo/rulebooks/bps-rulebook.md +24 -56
- package/docs/ja/specdojo/rulebooks/br-rulebook.md +13 -38
- package/docs/ja/specdojo/rulebooks/ccd-mermaid-rulebook.md +41 -76
- package/docs/ja/specdojo/rulebooks/cdfd-d2-rulebook.md +18 -93
- package/docs/ja/specdojo/rulebooks/cdfd-mermaid-rulebook.md +18 -52
- package/docs/ja/specdojo/rulebooks/cdfd-overview-rulebook.md +109 -147
- package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +80 -108
- package/docs/ja/specdojo/rulebooks/cdfd-uc-rulebook.md +21 -46
- package/docs/ja/specdojo/rulebooks/cdr-rulebook.md +144 -0
- package/docs/ja/specdojo/rulebooks/cdsd-rulebook.md +27 -48
- package/docs/ja/specdojo/rulebooks/cdt-rulebook.md +37 -50
- package/docs/ja/specdojo/rulebooks/clis-rulebook.md +52 -69
- package/docs/ja/specdojo/rulebooks/cnd-mermaid-rulebook.md +33 -86
- package/docs/ja/specdojo/rulebooks/cnd-rulebook.md +16 -32
- package/docs/ja/specdojo/rulebooks/cop-index-rulebook.md +45 -131
- package/docs/ja/specdojo/rulebooks/cop-rulebook.md +69 -275
- package/docs/ja/specdojo/rulebooks/cpd-mermaid-rulebook.md +20 -112
- package/docs/ja/specdojo/rulebooks/cpd-rulebook.md +23 -56
- package/docs/ja/specdojo/rulebooks/cxd-mermaid-rulebook.md +12 -145
- package/docs/ja/specdojo/rulebooks/cxd-rulebook.md +39 -47
- package/docs/ja/specdojo/rulebooks/dct-index-rulebook.md +37 -56
- package/docs/ja/specdojo/rulebooks/dct-rulebook.md +118 -175
- package/docs/ja/specdojo/rulebooks/dec-rulebook.md +5 -14
- package/docs/ja/specdojo/rulebooks/dmd-index-rulebook.md +22 -66
- package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +36 -94
- package/docs/ja/specdojo/rulebooks/dss-rulebook.md +59 -81
- package/docs/ja/specdojo/rulebooks/etc-index-rulebook.md +31 -131
- package/docs/ja/specdojo/rulebooks/etc-rulebook.md +50 -104
- package/docs/ja/specdojo/rulebooks/gl-rulebook.md +51 -61
- package/docs/ja/specdojo/rulebooks/ifd-mermaid-rulebook.md +38 -45
- package/docs/ja/specdojo/rulebooks/ifx-api-rulebook.md +14 -20
- package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +26 -38
- package/docs/ja/specdojo/rulebooks/ifx-file-rulebook.md +26 -107
- package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +42 -49
- package/docs/ja/specdojo/rulebooks/ifx-msg-rulebook.md +14 -22
- package/docs/ja/specdojo/rulebooks/imp-business-rulebook.md +21 -44
- package/docs/ja/specdojo/rulebooks/imp-data-rulebook.md +41 -64
- package/docs/ja/specdojo/rulebooks/imp-interface-rulebook.md +14 -38
- package/docs/ja/specdojo/rulebooks/imp-operations-rulebook.md +34 -61
- package/docs/ja/specdojo/rulebooks/imp-test-rulebook.md +27 -50
- package/docs/ja/specdojo/rulebooks/itc-index-rulebook.md +70 -199
- package/docs/ja/specdojo/rulebooks/itc-rulebook.md +65 -153
- package/docs/ja/specdojo/rulebooks/mip-index-rulebook.md +74 -150
- package/docs/ja/specdojo/rulebooks/mm-rulebook.md +11 -23
- package/docs/ja/specdojo/rulebooks/mtp-rulebook.md +99 -176
- package/docs/ja/specdojo/rulebooks/nfr-availability-rulebook.md +35 -61
- package/docs/ja/specdojo/rulebooks/nfr-index-rulebook.md +75 -117
- package/docs/ja/specdojo/rulebooks/nfr-integrity-rulebook.md +31 -60
- package/docs/ja/specdojo/rulebooks/nfr-maintainability-rulebook.md +26 -81
- package/docs/ja/specdojo/rulebooks/nfr-operations-rulebook.md +32 -70
- package/docs/ja/specdojo/rulebooks/nfr-performance-rulebook.md +45 -87
- package/docs/ja/specdojo/rulebooks/nfr-reliability-rulebook.md +48 -101
- package/docs/ja/specdojo/rulebooks/nfr-security-safety-rulebook.md +44 -80
- package/docs/ja/specdojo/rulebooks/nfr-usability-rulebook.md +59 -127
- package/docs/ja/specdojo/rulebooks/opd-index-rulebook.md +31 -50
- package/docs/ja/specdojo/rulebooks/opd-rulebook.md +42 -109
- package/docs/ja/specdojo/rulebooks/opr-index-rulebook.md +29 -42
- package/docs/ja/specdojo/rulebooks/opr-rulebook.md +29 -87
- package/docs/ja/specdojo/rulebooks/otp-index-rulebook.md +62 -84
- package/docs/ja/specdojo/rulebooks/otp-rulebook.md +11 -61
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +91 -106
- package/docs/ja/specdojo/rulebooks/pm-change-request-log-rulebook.md +25 -34
- package/docs/ja/specdojo/rulebooks/pm-communication-plan-rulebook.md +30 -53
- package/docs/ja/specdojo/rulebooks/pm-issue-log-rulebook.md +23 -35
- package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +27 -45
- package/docs/ja/specdojo/rulebooks/pm-organization-rulebook.md +37 -45
- package/docs/ja/specdojo/rulebooks/pm-plan-rulebook.md +45 -46
- package/docs/ja/specdojo/rulebooks/pm-quality-management-plan-rulebook.md +37 -48
- package/docs/ja/specdojo/rulebooks/pm-raci-rulebook.md +25 -29
- package/docs/ja/specdojo/rulebooks/pm-risk-register-rulebook.md +28 -35
- package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +36 -41
- package/docs/ja/specdojo/rulebooks/pr-rulebook.md +5 -18
- package/docs/ja/specdojo/rulebooks/prj-assumptions-constraints-dependencies-rulebook.md +16 -37
- package/docs/ja/specdojo/rulebooks/prj-charter-rulebook.md +23 -97
- package/docs/ja/specdojo/rulebooks/prj-comparison-of-alternatives-rulebook.md +39 -57
- package/docs/ja/specdojo/rulebooks/prj-issues-and-approach-rulebook.md +43 -116
- package/docs/ja/specdojo/rulebooks/prj-scope-rulebook.md +16 -51
- package/docs/ja/specdojo/rulebooks/prj-stakeholder-register-rulebook.md +47 -92
- package/docs/ja/specdojo/rulebooks/prj-success-criteria-and-acceptance-criteria-rulebook.md +25 -84
- package/docs/ja/specdojo/rulebooks/sac-rulebook.md +44 -107
- package/docs/ja/specdojo/rulebooks/sf-index-rulebook.md +39 -49
- package/docs/ja/specdojo/rulebooks/sf-rulebook.md +42 -49
- package/docs/ja/specdojo/rulebooks/sld-rulebook.md +64 -89
- package/docs/ja/specdojo/rulebooks/stc-index-rulebook.md +90 -189
- package/docs/ja/specdojo/rulebooks/stc-rulebook.md +45 -105
- package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +6 -12
- package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +49 -68
- package/docs/ja/specdojo/rulebooks/sysd-critical-flows-rulebook.md +51 -60
- package/docs/ja/specdojo/rulebooks/sysd-cross-cutting-policy-rulebook.md +46 -50
- package/docs/ja/specdojo/rulebooks/sysd-index-rulebook.md +39 -64
- package/docs/ja/specdojo/rulebooks/sysd-rulebook.md +47 -60
- package/docs/ja/specdojo/rulebooks/trc-requirements-to-specs-rulebook.md +69 -70
- package/docs/ja/specdojo/rulebooks/trc-requirements-to-tests-rulebook.md +65 -72
- package/docs/ja/specdojo/rulebooks/tsd-index-rulebook.md +35 -46
- package/docs/ja/specdojo/rulebooks/tsd-rulebook.md +49 -66
- package/docs/ja/specdojo/rulebooks/tsp-index-rulebook.md +64 -139
- package/docs/ja/specdojo/rulebooks/uis-rulebook.md +41 -108
- package/docs/ja/specdojo/rulebooks/utc-index-rulebook.md +49 -144
- package/docs/ja/specdojo/rulebooks/utc-rulebook.md +67 -155
- package/docs/ja/specdojo/samples/bds-sample.md +58 -71
- package/docs/ja/specdojo/samples/bes-index-sample.md +20 -37
- package/docs/ja/specdojo/samples/bes-sample.md +43 -53
- package/docs/ja/specdojo/samples/bps-sample.md +42 -54
- package/docs/ja/specdojo/samples/br-sample.md +40 -52
- package/docs/ja/specdojo/samples/ccd-sample.md +0 -1
- package/docs/ja/specdojo/samples/cdr-sample.md +78 -0
- package/docs/ja/specdojo/samples/cdsd-sample.md +47 -63
- package/docs/ja/specdojo/samples/clis-sample.md +70 -77
- package/docs/ja/specdojo/samples/dec-sample.md +2 -3
- package/docs/ja/specdojo/samples/ifx-api-sample.yaml +0 -2
- package/docs/ja/specdojo/samples/ifx-msg-sample.yaml +0 -2
- package/docs/ja/specdojo/samples/job-sequence.yaml +67 -0
- package/docs/ja/specdojo/samples/mip-index-sample.md +98 -20
- package/docs/ja/specdojo/samples/pm-communication-plan-sample.md +26 -19
- package/docs/ja/specdojo/samples/pm-organization-sample.md +39 -50
- package/docs/ja/specdojo/samples/pm-plan-sample.md +61 -67
- package/docs/ja/specdojo/samples/pm-quality-management-plan-sample.md +31 -45
- package/docs/ja/specdojo/samples/pm-raci-sample.md +31 -37
- package/docs/ja/specdojo/samples/prj-assumptions-constraints-dependencies-sample.md +32 -48
- package/docs/ja/specdojo/samples/prj-charter-sample.md +42 -59
- package/docs/ja/specdojo/samples/prj-comparison-of-alternatives-sample.md +55 -61
- package/docs/ja/specdojo/samples/prj-success-criteria-and-acceptance-criteria-sample.md +30 -33
- package/docs/ja/specdojo/samples/sf-index-sample.md +13 -55
- package/docs/ja/specdojo/samples/sf-sample.md +73 -85
- package/docs/ja/specdojo/samples/sld-sample.md +60 -79
- package/docs/ja/specdojo/samples/uis-sample.md +98 -121
- package/docs/ja/specdojo/standards/job-definition-standard.md +24 -9
- package/docs/ja/specdojo/templates/cdr-template.md +58 -0
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +2 -1
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +42 -5
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +35 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +23 -0
- package/docs/specdojo/schemas/v1/job.schema.yaml +63 -2
- package/docs/specdojo/schemas/v1/sch-strategy.schema.yaml +2 -2
- package/package.json +9 -6
- package/templates/antigravity/orchestrator.md +4 -1
- package/templates/claude/agents/specdojo-orchestrator.md +4 -1
- package/templates/codex/agents/specdojo-orchestrator.toml +4 -1
- package/templates/codex/orchestrator.md +4 -1
- package/templates/init-exec-defaults.yaml +13 -0
- package/templates/lefthook/tools/specdojo-pre-commit.mjs +8 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +5 -2
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { DIST_BUILD_FAILURE_MARKER } from "../shared/dist-freshness.js";
|
|
4
|
+
import { matchesParentValidationPaths, runParentValidationBatch, } from "./parent-validation.js";
|
|
5
|
+
import { redactSensitiveText } from "./evidence.js";
|
|
6
|
+
import { gitOutput } from "./worktree.js";
|
|
7
|
+
export function resolvePostIntegrationEntries(value) {
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
return [];
|
|
10
|
+
if (!Array.isArray(value)) {
|
|
11
|
+
throw new Error("pipeline.post_integration in exec-defaults must be an array");
|
|
12
|
+
}
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
return value.map((entry, index) => {
|
|
15
|
+
const where = `pipeline.post_integration[${index}] in exec-defaults`;
|
|
16
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
17
|
+
throw new Error(`${where} must be { id, paths }`);
|
|
18
|
+
}
|
|
19
|
+
const record = entry;
|
|
20
|
+
if (Object.keys(record).some((key) => key !== "id" && key !== "paths")) {
|
|
21
|
+
throw new Error(`${where} accepts only id and paths`);
|
|
22
|
+
}
|
|
23
|
+
if (record.id !== "build-dist")
|
|
24
|
+
throw new Error(`${where}: unknown id (allowed: build-dist)`);
|
|
25
|
+
if (seen.has(record.id))
|
|
26
|
+
throw new Error(`${where}: duplicate id: ${record.id}`);
|
|
27
|
+
seen.add(record.id);
|
|
28
|
+
if (!Array.isArray(record.paths) ||
|
|
29
|
+
record.paths.length === 0 ||
|
|
30
|
+
!record.paths.every((path) => typeof path === "string" && path.trim().length > 0)) {
|
|
31
|
+
throw new Error(`${where}.paths must be a non-empty array of non-empty glob strings`);
|
|
32
|
+
}
|
|
33
|
+
return { id: record.id, paths: record.paths.map((path) => path.trim()) };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Locate the original integration, even if other tasks landed before cleanup resumed. */
|
|
37
|
+
export function integratedCommitRange(repoRoot, branch) {
|
|
38
|
+
const tip = gitOutput(repoRoot, ["rev-parse", "--verify", `${branch}^{commit}`]).trim();
|
|
39
|
+
const outputCommit = gitOutput(repoRoot, [
|
|
40
|
+
"rev-list",
|
|
41
|
+
"--first-parent",
|
|
42
|
+
"--ancestry-path",
|
|
43
|
+
`${tip}..HEAD`,
|
|
44
|
+
])
|
|
45
|
+
.trim()
|
|
46
|
+
.split("\n")
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.at(-1);
|
|
49
|
+
if (!outputCommit)
|
|
50
|
+
throw new Error(`could not locate integrated commit for branch: ${branch}`);
|
|
51
|
+
return {
|
|
52
|
+
baseCommit: gitOutput(repoRoot, ["rev-parse", `${outputCommit}^1`]).trim(),
|
|
53
|
+
outputCommit,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function recorded(logPath, id, outputCommit) {
|
|
57
|
+
if (!existsSync(logPath))
|
|
58
|
+
return false;
|
|
59
|
+
return readFileSync(logPath, "utf8")
|
|
60
|
+
.split("\n")
|
|
61
|
+
.some((line) => {
|
|
62
|
+
try {
|
|
63
|
+
const record = JSON.parse(line);
|
|
64
|
+
return (record.id === id &&
|
|
65
|
+
record.output_commit === outputCommit &&
|
|
66
|
+
["passed", "failed", "skipped"].includes(record.status));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** Leave the marker that `dist-freshness` treats as stale after a failed build; clear it on success. */
|
|
74
|
+
export function updateDistBuildFailureMarker(repoRoot, failed, content) {
|
|
75
|
+
const marker = join(repoRoot, "dist", DIST_BUILD_FAILURE_MARKER);
|
|
76
|
+
if (failed) {
|
|
77
|
+
mkdirSync(dirname(marker), { recursive: true });
|
|
78
|
+
writeFileSync(marker, `${content}\n`, "utf8");
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
rmSync(marker, { force: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Caller retains the exec/lifecycle lock until this completes. Never undo a merged commit. */
|
|
85
|
+
export async function runPostIntegration(params) {
|
|
86
|
+
const log = params.log ??
|
|
87
|
+
((line) => {
|
|
88
|
+
process.stdout.write(line);
|
|
89
|
+
});
|
|
90
|
+
const records = [];
|
|
91
|
+
for (const entry of resolvePostIntegrationEntries(params.entries)) {
|
|
92
|
+
const startedAt = new Date().toISOString();
|
|
93
|
+
try {
|
|
94
|
+
if (recorded(params.logPath, entry.id, params.outputCommit))
|
|
95
|
+
continue;
|
|
96
|
+
// --no-renames includes both the old and new names; -z preserves spaces and newlines.
|
|
97
|
+
const changes = gitOutput(params.repoRoot, [
|
|
98
|
+
"diff",
|
|
99
|
+
"--name-only",
|
|
100
|
+
"--no-renames",
|
|
101
|
+
"-z",
|
|
102
|
+
params.baseCommit,
|
|
103
|
+
params.outputCommit,
|
|
104
|
+
"--",
|
|
105
|
+
])
|
|
106
|
+
.split("\0")
|
|
107
|
+
.filter(Boolean);
|
|
108
|
+
let status = "skipped";
|
|
109
|
+
let summary = "no integrated paths match paths";
|
|
110
|
+
if (changes.some((path) => matchesParentValidationPaths(path, entry.paths))) {
|
|
111
|
+
log(` [post-integration] ${entry.id}: running npm run build\n`);
|
|
112
|
+
const batch = await runParentValidationBatch(["build"], params.repoRoot, params.invoke);
|
|
113
|
+
const validation = batch.validations[0];
|
|
114
|
+
status = validation.status === "passed" ? "passed" : "failed";
|
|
115
|
+
summary = validation.summary;
|
|
116
|
+
}
|
|
117
|
+
records.push({
|
|
118
|
+
id: entry.id,
|
|
119
|
+
command: "npm run build",
|
|
120
|
+
base_commit: params.baseCommit,
|
|
121
|
+
output_commit: params.outputCommit,
|
|
122
|
+
started_at: startedAt,
|
|
123
|
+
completed_at: new Date().toISOString(),
|
|
124
|
+
status,
|
|
125
|
+
summary,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
records.push({
|
|
130
|
+
id: entry.id,
|
|
131
|
+
command: "npm run build",
|
|
132
|
+
base_commit: params.baseCommit,
|
|
133
|
+
output_commit: params.outputCommit,
|
|
134
|
+
started_at: startedAt,
|
|
135
|
+
completed_at: new Date().toISOString(),
|
|
136
|
+
status: "failed",
|
|
137
|
+
summary: redactSensitiveText(error instanceof Error ? error.message : String(error)),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const record = records.at(-1);
|
|
141
|
+
if (record.status !== "skipped") {
|
|
142
|
+
try {
|
|
143
|
+
updateDistBuildFailureMarker(params.repoRoot, record.status === "failed", record.output_commit);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
log(` [post-integration] could not update dist failure marker: ${redactSensitiveText(String(error))}\n`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
log(` [post-integration] ${record.id}: ${record.status}: ${record.summary}\n`);
|
|
150
|
+
if (record.status === "failed") {
|
|
151
|
+
log(" [post-integration] integration kept; fix the build and run npm run build before the next exec run (dist-freshness check remains enabled).\n");
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
mkdirSync(dirname(params.logPath), { recursive: true });
|
|
155
|
+
appendFileSync(params.logPath, `${JSON.stringify(record)}\n`, "utf8");
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
log(` [post-integration] could not record outcome: ${redactSensitiveText(String(error))}\n`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return records;
|
|
162
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { gitEnvironment } from "../shared/git-environment.js";
|
|
4
|
+
import { selfRunArgs } from "../shared/spawn-self.js";
|
|
5
|
+
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
6
|
+
import { addProjectOptions, printCommandError, resolveProjectId } from "./core.js";
|
|
7
|
+
import { runParentValidationBatch } from "./parent-validation.js";
|
|
8
|
+
import { updateDistBuildFailureMarker } from "./post-integration.js";
|
|
9
|
+
import { resolveProjectPaths } from "./project.js";
|
|
10
|
+
import { cancelQueue, createQueueRecord, formatQueueSummary, isQueueFinished, listQueueRecords, loadQueueRecord, queueLockPath, queueRecordPath, queueStepDisplay, runQueue, validateQueueId, writeQueueRecord, } from "./queue.js";
|
|
11
|
+
import { acquireExecRunLock, releaseExecRunLock } from "./run/lock.js";
|
|
12
|
+
/** Spawn the specdojo CLI without a shell and resolve when that process exits. */
|
|
13
|
+
function runSpecdojoStep(argv) {
|
|
14
|
+
const [executable, args] = selfRunArgs(argv);
|
|
15
|
+
return new Promise((resolveOutcome) => {
|
|
16
|
+
const child = spawn(executable, args, {
|
|
17
|
+
cwd: specdojoRootDir(),
|
|
18
|
+
env: gitEnvironment(),
|
|
19
|
+
shell: false,
|
|
20
|
+
stdio: "inherit",
|
|
21
|
+
});
|
|
22
|
+
child.once("error", (error) => resolveOutcome({ exitCode: null, summary: error.message }));
|
|
23
|
+
child.once("close", (code, signal) => resolveOutcome({
|
|
24
|
+
exitCode: code,
|
|
25
|
+
summary: signal ? `terminated by ${signal}` : `exit code ${code ?? "unknown"}`,
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** `post-integration build-dist`: the PJR-8KXJ allowlisted build, under the project exec lock. */
|
|
30
|
+
async function runBuildDistStep(executionPath) {
|
|
31
|
+
const handle = await acquireExecRunLock(executionPath, {
|
|
32
|
+
actor: "exec-queue",
|
|
33
|
+
ifBusy: "wait",
|
|
34
|
+
onWait: () => process.stdout.write("[queue] exec busy — waiting to run build-dist\n"),
|
|
35
|
+
});
|
|
36
|
+
if (!handle)
|
|
37
|
+
return { exitCode: null, summary: "could not acquire the exec lock" };
|
|
38
|
+
try {
|
|
39
|
+
const repoRoot = specdojoRootDir();
|
|
40
|
+
const batch = await runParentValidationBatch(["build"], repoRoot);
|
|
41
|
+
const validation = batch.validations[0];
|
|
42
|
+
const failed = validation?.status !== "passed";
|
|
43
|
+
updateDistBuildFailureMarker(repoRoot, failed, "exec queue build-dist");
|
|
44
|
+
return { exitCode: failed ? 1 : 0, summary: validation?.summary ?? "build did not run" };
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
releaseExecRunLock(handle);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function executeQueueStep(executionPath) {
|
|
51
|
+
return (step) => step.kind === "post-integration" ? runBuildDistStep(executionPath) : runSpecdojoStep(step.argv);
|
|
52
|
+
}
|
|
53
|
+
export function registerExecQueueCommands(exec) {
|
|
54
|
+
const queue = exec
|
|
55
|
+
.command("queue")
|
|
56
|
+
.description("Reserve grade / exec run / post-integration steps and run them in order");
|
|
57
|
+
// Shared by --step and --step-continue so the order of the options is the order of the steps.
|
|
58
|
+
const collected = [];
|
|
59
|
+
const collect = (onFailure) => (spec) => {
|
|
60
|
+
collected.push({ spec, onFailure });
|
|
61
|
+
return collected;
|
|
62
|
+
};
|
|
63
|
+
const add = queue
|
|
64
|
+
.command("add <queueId>")
|
|
65
|
+
.description("Create a queue file under execution/queues/")
|
|
66
|
+
.option("--step <spec>", 'Step that stops the queue on failure (e.g. "exec run --register PJR-XXXX")', collect("stop"))
|
|
67
|
+
.option("--step-continue <spec>", "Step whose failure does not stop the queue", collect("continue"));
|
|
68
|
+
addProjectOptions(add);
|
|
69
|
+
add.action((queueId, opts) => {
|
|
70
|
+
try {
|
|
71
|
+
const { executionPath } = resolveProjectPaths({ project: opts.project });
|
|
72
|
+
const path = queueRecordPath(executionPath, validateQueueId(queueId));
|
|
73
|
+
if (existsSync(path))
|
|
74
|
+
throw new Error(`Queue already exists: ${path}`);
|
|
75
|
+
const record = createQueueRecord({
|
|
76
|
+
queueId,
|
|
77
|
+
projectId: resolveProjectId(opts),
|
|
78
|
+
steps: collected,
|
|
79
|
+
});
|
|
80
|
+
writeQueueRecord(path, record);
|
|
81
|
+
process.stdout.write(`Created queue: ${path}\n`);
|
|
82
|
+
for (const step of record.steps) {
|
|
83
|
+
process.stdout.write(` ${step.index}. [${step.on_failure}] ${queueStepDisplay(step)}\n`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
printCommandError(error);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const run = queue.command("run <queueId>").description("Run (or resume) a queue in order");
|
|
91
|
+
addProjectOptions(run);
|
|
92
|
+
run.action(async (queueId, opts) => {
|
|
93
|
+
try {
|
|
94
|
+
const { executionPath } = resolveProjectPaths({ project: opts.project });
|
|
95
|
+
validateQueueId(queueId);
|
|
96
|
+
const record = await runQueue({
|
|
97
|
+
recordPath: queueRecordPath(executionPath, queueId),
|
|
98
|
+
lockDir: queueLockPath(executionPath, queueId),
|
|
99
|
+
execute: executeQueueStep(executionPath),
|
|
100
|
+
});
|
|
101
|
+
process.exitCode = record.state === "succeeded" ? 0 : 1;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
printCommandError(error);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const status = queue
|
|
108
|
+
.command("status [queueId]")
|
|
109
|
+
.description("Show queues, or the steps of one queue");
|
|
110
|
+
addProjectOptions(status);
|
|
111
|
+
status.action((queueId, opts) => {
|
|
112
|
+
try {
|
|
113
|
+
const { executionPath } = resolveProjectPaths({ project: opts.project });
|
|
114
|
+
if (queueId) {
|
|
115
|
+
validateQueueId(queueId);
|
|
116
|
+
const record = loadQueueRecord(queueRecordPath(executionPath, queueId));
|
|
117
|
+
process.stdout.write(`${formatQueueSummary(record, queueLockPath(executionPath, queueId))}\n`);
|
|
118
|
+
for (const step of record.steps) {
|
|
119
|
+
const detail = step.summary ? ` (${step.summary})` : "";
|
|
120
|
+
process.stdout.write(` ${step.index}. ${step.status} [${step.on_failure}] ${queueStepDisplay(step)}${detail}\n`);
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const { records, errors } = listQueueRecords(executionPath);
|
|
125
|
+
if (records.length === 0)
|
|
126
|
+
process.stdout.write("No queues.\n");
|
|
127
|
+
for (const record of records) {
|
|
128
|
+
process.stdout.write(`${formatQueueSummary(record, queueLockPath(executionPath, record.queue_id))}\n`);
|
|
129
|
+
}
|
|
130
|
+
for (const error of errors)
|
|
131
|
+
process.stderr.write(`ERROR: ${error}\n`);
|
|
132
|
+
if (errors.length)
|
|
133
|
+
process.exitCode = 1;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
printCommandError(error);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const cancel = queue
|
|
140
|
+
.command("cancel <queueId>")
|
|
141
|
+
.description("Cancel a queue; a running queue stops before its next step")
|
|
142
|
+
.requiredOption("--msg <message>", "Reason for cancelling");
|
|
143
|
+
addProjectOptions(cancel);
|
|
144
|
+
cancel.action((queueId, opts) => {
|
|
145
|
+
try {
|
|
146
|
+
const { executionPath } = resolveProjectPaths({ project: opts.project });
|
|
147
|
+
validateQueueId(queueId);
|
|
148
|
+
const record = cancelQueue(queueRecordPath(executionPath, queueId), opts.msg);
|
|
149
|
+
process.stdout.write(`Cancelled queue: ${record.queue_id}\n`);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
printCommandError(error);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** Unfinished queues appended to `exec status`, so reservations stay visible next to tasks. */
|
|
157
|
+
export function writeActiveQueueSummary(executionPath) {
|
|
158
|
+
const { records } = listQueueRecords(executionPath);
|
|
159
|
+
const active = records.filter((record) => !isQueueFinished(record));
|
|
160
|
+
if (active.length === 0)
|
|
161
|
+
return;
|
|
162
|
+
process.stdout.write("\nqueues:\n");
|
|
163
|
+
for (const record of active) {
|
|
164
|
+
process.stdout.write(` ${formatQueueSummary(record, queueLockPath(executionPath, record.queue_id))}\n`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { isLiveLock, releaseLock, tryAcquireLock, } from "../shared/cross-process-lock.js";
|
|
4
|
+
const QUEUE_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
5
|
+
const FINISHED_STATES = [
|
|
6
|
+
"succeeded",
|
|
7
|
+
"completed_with_failures",
|
|
8
|
+
"cancelled",
|
|
9
|
+
];
|
|
10
|
+
const REJECTED_EXEC_RUN_OPTIONS = ["--job", "--plan"];
|
|
11
|
+
const EXEC_RUN_TARGET_OPTIONS = ["--register", "--register-filter", "--auto", "--task"];
|
|
12
|
+
export function queuesDirectory(executionPath) {
|
|
13
|
+
return join(executionPath, "queues");
|
|
14
|
+
}
|
|
15
|
+
export function queueRecordPath(executionPath, queueId) {
|
|
16
|
+
return join(queuesDirectory(executionPath), `${queueId}.json`);
|
|
17
|
+
}
|
|
18
|
+
/** Runtime lock under `exec/.locks/`, which Git already ignores. */
|
|
19
|
+
export function queueLockPath(executionPath, queueId) {
|
|
20
|
+
return join(executionPath, "exec", ".locks", `queue-${queueId}.lock`);
|
|
21
|
+
}
|
|
22
|
+
export function validateQueueId(queueId) {
|
|
23
|
+
if (!QUEUE_ID_PATTERN.test(queueId)) {
|
|
24
|
+
throw new Error(`Invalid queue id: ${queueId} (use lowercase letters, digits and hyphens, up to 64 characters)`);
|
|
25
|
+
}
|
|
26
|
+
return queueId;
|
|
27
|
+
}
|
|
28
|
+
function hasOption(argv, option) {
|
|
29
|
+
return argv.some((token) => token === option || token.startsWith(`${option}=`));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse one `--step` value. The value is split on whitespace only; quoting is not supported, and
|
|
33
|
+
* the leading words select the step kind from the allowlist.
|
|
34
|
+
*/
|
|
35
|
+
export function parseQueueStepSpec(spec, onFailure, index, projectId) {
|
|
36
|
+
const where = `step ${index}`;
|
|
37
|
+
const tokens = spec.trim().split(/\s+/).filter(Boolean);
|
|
38
|
+
if (tokens.some((token) => /["'`\\]/.test(token))) {
|
|
39
|
+
throw new Error(`${where}: quotes and backslashes are not supported (no shell is used)`);
|
|
40
|
+
}
|
|
41
|
+
const head = tokens.slice(0, 2).join(" ");
|
|
42
|
+
const rest = tokens.slice(2);
|
|
43
|
+
const base = { index, on_failure: onFailure, status: "pending" };
|
|
44
|
+
const withProject = (argv) => hasOption(argv, "--project") ? argv : [...argv, "--project", projectId];
|
|
45
|
+
if (head === "grade run") {
|
|
46
|
+
return { ...base, kind: "grade", argv: withProject(["grade", "run", ...rest]) };
|
|
47
|
+
}
|
|
48
|
+
if (head === "exec run") {
|
|
49
|
+
const rejected = REJECTED_EXEC_RUN_OPTIONS.find((option) => hasOption(rest, option));
|
|
50
|
+
if (rejected)
|
|
51
|
+
throw new Error(`${where}: exec run ${rejected} is not supported in a queue`);
|
|
52
|
+
if (!EXEC_RUN_TARGET_OPTIONS.some((option) => hasOption(rest, option))) {
|
|
53
|
+
throw new Error(`${where}: exec run needs one of ${EXEC_RUN_TARGET_OPTIONS.join(", ")} (register or schedule)`);
|
|
54
|
+
}
|
|
55
|
+
return { ...base, kind: "exec-run", argv: withProject(["exec", "run", ...rest]) };
|
|
56
|
+
}
|
|
57
|
+
if (head === "post-integration build-dist" && rest.length === 0) {
|
|
58
|
+
return { ...base, kind: "post-integration", argv: ["build-dist"] };
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`${where}: unsupported step: ${spec.trim() || "(empty)"} (allowed: "grade run ...", "exec run ...", "post-integration build-dist")`);
|
|
61
|
+
}
|
|
62
|
+
export function createQueueRecord(params) {
|
|
63
|
+
validateQueueId(params.queueId);
|
|
64
|
+
if (params.steps.length === 0)
|
|
65
|
+
throw new Error("A queue needs at least one --step");
|
|
66
|
+
const now = params.now ?? new Date().toISOString();
|
|
67
|
+
return {
|
|
68
|
+
version: 1,
|
|
69
|
+
queue_id: params.queueId,
|
|
70
|
+
project_id: params.projectId,
|
|
71
|
+
created_at: now,
|
|
72
|
+
updated_at: now,
|
|
73
|
+
state: "pending",
|
|
74
|
+
steps: params.steps.map((step, offset) => parseQueueStepSpec(step.spec, step.onFailure, offset + 1, params.projectId)),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function isRecord(value) {
|
|
78
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
79
|
+
}
|
|
80
|
+
function isQueueStep(value) {
|
|
81
|
+
return (isRecord(value) &&
|
|
82
|
+
typeof value.index === "number" &&
|
|
83
|
+
(value.kind === "grade" || value.kind === "exec-run" || value.kind === "post-integration") &&
|
|
84
|
+
Array.isArray(value.argv) &&
|
|
85
|
+
value.argv.every((token) => typeof token === "string") &&
|
|
86
|
+
(value.on_failure === "stop" || value.on_failure === "continue") &&
|
|
87
|
+
["pending", "running", "succeeded", "failed"].includes(String(value.status)));
|
|
88
|
+
}
|
|
89
|
+
export function parseQueueRecord(value, source) {
|
|
90
|
+
if (!isRecord(value) ||
|
|
91
|
+
value.version !== 1 ||
|
|
92
|
+
typeof value.queue_id !== "string" ||
|
|
93
|
+
typeof value.project_id !== "string" ||
|
|
94
|
+
typeof value.created_at !== "string" ||
|
|
95
|
+
typeof value.updated_at !== "string" ||
|
|
96
|
+
![
|
|
97
|
+
"pending",
|
|
98
|
+
"running",
|
|
99
|
+
"stopped",
|
|
100
|
+
"succeeded",
|
|
101
|
+
"completed_with_failures",
|
|
102
|
+
"cancelled",
|
|
103
|
+
].includes(String(value.state)) ||
|
|
104
|
+
!Array.isArray(value.steps) ||
|
|
105
|
+
!value.steps.every(isQueueStep)) {
|
|
106
|
+
throw new Error(`Invalid queue record: ${source}`);
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
export function loadQueueRecord(path) {
|
|
111
|
+
if (!existsSync(path))
|
|
112
|
+
throw new Error(`Queue not found: ${path}`);
|
|
113
|
+
let parsed;
|
|
114
|
+
try {
|
|
115
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
throw new Error(`Invalid queue record JSON: ${path}`, { cause: error });
|
|
119
|
+
}
|
|
120
|
+
return parseQueueRecord(parsed, path);
|
|
121
|
+
}
|
|
122
|
+
export function writeQueueRecord(path, record) {
|
|
123
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
124
|
+
writeFileSync(path, `${JSON.stringify(record, null, 2)}\n`, "utf8");
|
|
125
|
+
}
|
|
126
|
+
export function listQueueRecords(executionPath) {
|
|
127
|
+
const directory = queuesDirectory(executionPath);
|
|
128
|
+
if (!existsSync(directory))
|
|
129
|
+
return { records: [], errors: [] };
|
|
130
|
+
const records = [];
|
|
131
|
+
const errors = [];
|
|
132
|
+
for (const name of readdirSync(directory)
|
|
133
|
+
.filter((entry) => entry.endsWith(".json"))
|
|
134
|
+
.sort()) {
|
|
135
|
+
try {
|
|
136
|
+
records.push(loadQueueRecord(join(directory, name)));
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { records, errors };
|
|
143
|
+
}
|
|
144
|
+
export function isQueueFinished(record) {
|
|
145
|
+
return FINISHED_STATES.includes(record.state);
|
|
146
|
+
}
|
|
147
|
+
export function queueStepDisplay(step) {
|
|
148
|
+
return step.kind === "post-integration"
|
|
149
|
+
? "post-integration build-dist"
|
|
150
|
+
: `specdojo ${step.argv.join(" ")}`;
|
|
151
|
+
}
|
|
152
|
+
/** Steps to run on this invocation: unfinished steps, plus the failed step that stopped it. */
|
|
153
|
+
function stepNeedsRun(step) {
|
|
154
|
+
if (step.status === "succeeded")
|
|
155
|
+
return false;
|
|
156
|
+
return !(step.status === "failed" && step.on_failure === "continue");
|
|
157
|
+
}
|
|
158
|
+
export class QueueBusyError extends Error {
|
|
159
|
+
constructor(queueId, lockDir) {
|
|
160
|
+
super(`Queue ${queueId} is already running (lock: ${lockDir})`);
|
|
161
|
+
this.name = "QueueBusyError";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Run a queue's steps in order. A stopped queue resumes at the failed step, and a step left
|
|
166
|
+
* `running` by a runner that died is run again. Cancellation is checked before each step.
|
|
167
|
+
*/
|
|
168
|
+
export async function runQueue(params) {
|
|
169
|
+
const log = params.log ?? ((line) => process.stdout.write(line));
|
|
170
|
+
const initial = loadQueueRecord(params.recordPath);
|
|
171
|
+
const acquire = params.acquire ??
|
|
172
|
+
((lockDir) => tryAcquireLock(lockDir, { actor: "exec-queue", label: `queue ${initial.queue_id}` }));
|
|
173
|
+
const release = params.release ?? releaseLock;
|
|
174
|
+
if (isQueueFinished(initial)) {
|
|
175
|
+
log(`[queue] ${initial.queue_id}: already ${initial.state}\n`);
|
|
176
|
+
return initial;
|
|
177
|
+
}
|
|
178
|
+
mkdirSync(dirname(params.lockDir), { recursive: true });
|
|
179
|
+
const handle = acquire(params.lockDir);
|
|
180
|
+
if (!handle)
|
|
181
|
+
throw new QueueBusyError(initial.queue_id, params.lockDir);
|
|
182
|
+
try {
|
|
183
|
+
const record = loadQueueRecord(params.recordPath);
|
|
184
|
+
// `exec queue cancel` edits the file while this runner holds the lock; keep that state.
|
|
185
|
+
const syncCancellation = () => {
|
|
186
|
+
const latest = loadQueueRecord(params.recordPath);
|
|
187
|
+
if (latest.state === "cancelled" && record.state === "running") {
|
|
188
|
+
record.state = "cancelled";
|
|
189
|
+
record.reason = latest.reason;
|
|
190
|
+
}
|
|
191
|
+
return record.state === "cancelled";
|
|
192
|
+
};
|
|
193
|
+
const save = () => {
|
|
194
|
+
syncCancellation();
|
|
195
|
+
record.updated_at = new Date().toISOString();
|
|
196
|
+
writeQueueRecord(params.recordPath, record);
|
|
197
|
+
};
|
|
198
|
+
record.state = "running";
|
|
199
|
+
delete record.stopped_step;
|
|
200
|
+
delete record.reason;
|
|
201
|
+
save();
|
|
202
|
+
for (const step of record.steps) {
|
|
203
|
+
if (!stepNeedsRun(step))
|
|
204
|
+
continue;
|
|
205
|
+
if (syncCancellation()) {
|
|
206
|
+
save();
|
|
207
|
+
log(`[queue] ${record.queue_id}: cancelled before step ${step.index}\n`);
|
|
208
|
+
return record;
|
|
209
|
+
}
|
|
210
|
+
log(`[queue] ${record.queue_id}: step ${step.index} start: ${queueStepDisplay(step)}\n`);
|
|
211
|
+
step.status = "running";
|
|
212
|
+
step.started_at = new Date().toISOString();
|
|
213
|
+
delete step.completed_at;
|
|
214
|
+
delete step.exit_code;
|
|
215
|
+
delete step.summary;
|
|
216
|
+
save();
|
|
217
|
+
let outcome;
|
|
218
|
+
try {
|
|
219
|
+
outcome = await params.execute(step, record);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
outcome = {
|
|
223
|
+
exitCode: null,
|
|
224
|
+
summary: error instanceof Error ? error.message : String(error),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
step.status = outcome.exitCode === 0 ? "succeeded" : "failed";
|
|
228
|
+
step.completed_at = new Date().toISOString();
|
|
229
|
+
step.exit_code = outcome.exitCode;
|
|
230
|
+
step.summary = outcome.summary;
|
|
231
|
+
log(`[queue] ${record.queue_id}: step ${step.index} ${step.status}: ${outcome.summary}\n`);
|
|
232
|
+
if (step.status === "failed" && step.on_failure === "stop" && !syncCancellation()) {
|
|
233
|
+
record.state = "stopped";
|
|
234
|
+
record.stopped_step = step.index;
|
|
235
|
+
record.reason = `step ${step.index} failed: ${outcome.summary}`;
|
|
236
|
+
save();
|
|
237
|
+
log(`[queue] ${record.queue_id}: stopped at step ${step.index}\n`);
|
|
238
|
+
return record;
|
|
239
|
+
}
|
|
240
|
+
save();
|
|
241
|
+
}
|
|
242
|
+
if (syncCancellation()) {
|
|
243
|
+
save();
|
|
244
|
+
return record;
|
|
245
|
+
}
|
|
246
|
+
record.state = record.steps.some((step) => step.status === "failed")
|
|
247
|
+
? "completed_with_failures"
|
|
248
|
+
: "succeeded";
|
|
249
|
+
save();
|
|
250
|
+
log(`[queue] ${record.queue_id}: ${record.state}\n`);
|
|
251
|
+
return record;
|
|
252
|
+
}
|
|
253
|
+
finally {
|
|
254
|
+
release(handle);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/** Mark a queue cancelled. A running runner stops before its next step. */
|
|
258
|
+
export function cancelQueue(recordPath, reason) {
|
|
259
|
+
const record = loadQueueRecord(recordPath);
|
|
260
|
+
if (record.state === "succeeded" || record.state === "completed_with_failures") {
|
|
261
|
+
throw new Error(`Queue ${record.queue_id} is already ${record.state}`);
|
|
262
|
+
}
|
|
263
|
+
record.state = "cancelled";
|
|
264
|
+
record.reason = reason;
|
|
265
|
+
record.updated_at = new Date().toISOString();
|
|
266
|
+
writeQueueRecord(recordPath, record);
|
|
267
|
+
return record;
|
|
268
|
+
}
|
|
269
|
+
/** One-line progress for `exec queue status` and `exec status`. */
|
|
270
|
+
export function formatQueueSummary(record, lockDir) {
|
|
271
|
+
const done = record.steps.filter((step) => step.status === "succeeded" || step.status === "failed").length;
|
|
272
|
+
const running = record.steps.find((step) => step.status === "running");
|
|
273
|
+
// A record left `running` without a live lock means the runner died; `exec queue run` resumes it.
|
|
274
|
+
const state = record.state === "running" && !isLiveLock(lockDir)
|
|
275
|
+
? "running (runner not alive)"
|
|
276
|
+
: record.state;
|
|
277
|
+
const parts = [`${record.queue_id}`, state, `${done}/${record.steps.length}`];
|
|
278
|
+
if (running)
|
|
279
|
+
parts.push(`current=step ${running.index}: ${queueStepDisplay(running)}`);
|
|
280
|
+
if (record.stopped_step !== undefined)
|
|
281
|
+
parts.push(`stopped=step ${record.stopped_step}`);
|
|
282
|
+
if (record.reason)
|
|
283
|
+
parts.push(`reason=${record.reason}`);
|
|
284
|
+
return parts.join("\t");
|
|
285
|
+
}
|