specdojo 0.8.0 → 0.9.1
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 +77 -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/orchestrator.js +5 -77
- package/dist/commands/where.js +25 -0
- package/dist/dashboard/dashboard.js +5 -3
- package/dist/dashboard/routines.js +4 -7
- package/dist/dashboard/shared.js +2 -2
- package/dist/dashboard/timeline.js +14 -14
- package/dist/deliverable/trash.js +2 -1
- 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/opencode-permissions.js +117 -0
- 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 +82 -0
- package/dist/exec/repo-integration-sync.js +17 -5
- package/dist/exec/repo-trace.js +2 -1
- 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 +5 -2
- 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 +2 -2
- package/dist/exec/smoke.js +190 -0
- package/dist/exec/strategy.js +13 -3
- package/dist/exec/task-repos.js +19 -4
- 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 +12 -2
- 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/register/renumber.js +1 -3
- 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 +17 -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/orchestrator-operation-guide.md +1 -1
- 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 +258 -118
- package/docs/ja/specdojo/references/deliverables-reference.md +21 -12
- package/docs/ja/specdojo/references/specdojo-config-reference.md +47 -10
- 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,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
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { stagedMergeBlocker } from "../shared/git.js";
|
|
2
|
+
import { escapeRegExp } from "../shared/text.js";
|
|
3
|
+
import { acquireSchedulerLock, releaseSchedulerLock } from "./events.js";
|
|
4
|
+
import { currentBranch } from "./worktree-ops-commit.js";
|
|
5
|
+
import { abortMerge } from "./worktree-ops-merge.js";
|
|
6
|
+
import { gitOutput, gitResult, summarizeGitHookFailure } from "./worktree.js";
|
|
7
|
+
// PJR-97KE: job の worktree の中で作られた子の run は、wait の commit が job の branch に入り、
|
|
8
|
+
// 本体の作業ツリー(日中の再開の起点)には plan も waiting の記録も無い。wait の後に exec branch
|
|
9
|
+
// へ統合先を取り込む merge(`merge <target> after wait`)の第2親が、その記録を持つ統合先の
|
|
10
|
+
// commit である。本体の HEAD がこの commit を含まないとき、再開の前に本体へ merge する。
|
|
11
|
+
// exec branch の先端ではなくこの commit を取り込むのは、exec branch を本体の祖先にすると
|
|
12
|
+
// 統合の段が「merge 済み」と誤認するためである。記録を複製せず履歴として取り込むので、
|
|
13
|
+
// 後で job の branch を本体へ統合しても、同じ commit を共有して衝突しない。
|
|
14
|
+
const LOCK_TIMEOUT_MS = 10_000;
|
|
15
|
+
const LOCK_STALE_MS = 300_000;
|
|
16
|
+
// exec branch の first-parent 履歴から最新の wait 後の同期 merge を探し、その統合先の commit が
|
|
17
|
+
// 本体の HEAD に含まれていなければ返す。同期 merge が無い、または含まれている場合は null。
|
|
18
|
+
export function findForeignWaitRecords(params) {
|
|
19
|
+
const { repoRoot, worktree, itemId } = params;
|
|
20
|
+
const subject = new RegExp(`^exec\\(register ${escapeRegExp(itemId)}\\): merge (.+) after wait$`);
|
|
21
|
+
const log = gitResult(repoRoot, [
|
|
22
|
+
"log",
|
|
23
|
+
"--first-parent",
|
|
24
|
+
"--merges",
|
|
25
|
+
"--format=%P%x09%s",
|
|
26
|
+
worktree.branch,
|
|
27
|
+
"--",
|
|
28
|
+
]);
|
|
29
|
+
if (log.status !== 0 || typeof log.stdout !== "string")
|
|
30
|
+
return null;
|
|
31
|
+
for (const line of log.stdout.split("\n")) {
|
|
32
|
+
const tab = line.indexOf("\t");
|
|
33
|
+
if (tab < 0)
|
|
34
|
+
continue;
|
|
35
|
+
const match = subject.exec(line.slice(tab + 1));
|
|
36
|
+
if (!match)
|
|
37
|
+
continue;
|
|
38
|
+
const parents = line.slice(0, tab).trim().split(/\s+/);
|
|
39
|
+
const commit = parents[1];
|
|
40
|
+
if (!commit)
|
|
41
|
+
return null;
|
|
42
|
+
const contained = gitResult(repoRoot, ["merge-base", "--is-ancestor", commit, "HEAD"]).status === 0;
|
|
43
|
+
return contained ? null : { commit, target: match[1] };
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// 統合先の wait の記録を本体の現在の branch へ merge commit 1件で取り込む。取り込めない場合は
|
|
48
|
+
// merge を中止して本体を元に戻し、理由を例外で返す。
|
|
49
|
+
export function adoptForeignWaitRecords(params) {
|
|
50
|
+
const { repoRoot, schedulePath, itemId, records } = params;
|
|
51
|
+
const targetBranch = currentBranch(repoRoot);
|
|
52
|
+
const lockDir = acquireSchedulerLock(schedulePath, {
|
|
53
|
+
actor: `register-adopt:${itemId}`,
|
|
54
|
+
lockTimeoutMs: LOCK_TIMEOUT_MS,
|
|
55
|
+
lockStaleMs: LOCK_STALE_MS,
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
const staged = stagedMergeBlocker(repoRoot);
|
|
59
|
+
if (staged)
|
|
60
|
+
throw new Error(staged);
|
|
61
|
+
const message = `exec(register ${itemId}): merge ${records.target} records before resume`;
|
|
62
|
+
const merge = gitResult(repoRoot, ["merge", "--no-ff", "-m", message, records.commit]);
|
|
63
|
+
if (merge.status === 0)
|
|
64
|
+
return;
|
|
65
|
+
const output = [merge.stdout, merge.stderr]
|
|
66
|
+
.filter((part) => typeof part === "string" && part.length > 0)
|
|
67
|
+
.join("\n");
|
|
68
|
+
if (gitResult(repoRoot, ["rev-parse", "--verify", "--quiet", "MERGE_HEAD"]).status === 0) {
|
|
69
|
+
abortMerge(repoRoot);
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`git merge of ${records.target} (${records.commit.slice(0, 12)}) into ${targetBranch} failed: ` +
|
|
72
|
+
summarizeGitHookFailure(output));
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
releaseSchedulerLock(lockDir);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// 取り込んだ commit のうち、本体に無かったものの数(利用者への表示用)。
|
|
79
|
+
export function countForeignCommits(repoRoot, records) {
|
|
80
|
+
const count = Number.parseInt(gitOutput(repoRoot, ["rev-list", "--count", `HEAD..${records.commit}`]).trim(), 10);
|
|
81
|
+
return Number.isFinite(count) ? count : 0;
|
|
82
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
1
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
2
3
|
import { productIntegrationTarget } from "./task-repos.js";
|
|
3
4
|
import { abortMerge } from "./worktree-ops.js";
|
|
4
5
|
import { gitOutput, gitResult } from "./worktree.js";
|
|
@@ -95,8 +96,9 @@ function restoreOriginalWorktree(params) {
|
|
|
95
96
|
* Merge `target` into the branch checked out at `cwd` (an exec worktree) with a merge commit.
|
|
96
97
|
* Uncommitted changes (including untracked files) are stashed before the merge and restored
|
|
97
98
|
* without restoring the old index. Conflicts on `theirsPaths` (repository-relative) take the
|
|
98
|
-
* target side and conflicts on `oursPaths` keep the exec branch side.
|
|
99
|
-
*
|
|
99
|
+
* target side and conflicts on `oursPaths` keep the exec branch side. Conflicts on `resolvedPaths`
|
|
100
|
+
* write the resolver's combination of both sides (when either side deleted the file, the target
|
|
101
|
+
* side is taken). Any other committed conflict aborts the merge. If restoring the stash conflicts,
|
|
100
102
|
* the merge commit is rolled back and the executor changes are restored on the original HEAD.
|
|
101
103
|
*/
|
|
102
104
|
export function syncWorktreeWithIntegrationTarget(params) {
|
|
@@ -126,12 +128,21 @@ export function syncWorktreeWithIntegrationTarget(params) {
|
|
|
126
128
|
const conflicted = zeroSeparated(cwd, ["diff", "--name-only", "--diff-filter=U", "-z"]);
|
|
127
129
|
const theirs = new Set(params.theirsPaths ?? []);
|
|
128
130
|
const ours = new Set(params.oursPaths ?? []);
|
|
129
|
-
const
|
|
131
|
+
const resolvers = params.resolvedPaths ?? new Map();
|
|
132
|
+
const unexpected = conflicted.filter((path) => !theirs.has(path) && !ours.has(path) && !resolvers.has(path));
|
|
130
133
|
if (unexpected.length > 0) {
|
|
131
134
|
throw new Error(`${repo}: merge conflicts with ${target}: ${unexpected.join(", ")}`);
|
|
132
135
|
}
|
|
133
136
|
for (const path of conflicted) {
|
|
134
|
-
const
|
|
137
|
+
const resolver = resolvers.get(path);
|
|
138
|
+
if (resolver && hasPathAt(cwd, "HEAD", path) && hasPathAt(cwd, target, path)) {
|
|
139
|
+
const execContent = gitOutput(cwd, ["show", `HEAD:${path}`]);
|
|
140
|
+
const targetContent = gitOutput(cwd, ["show", `${target}:${path}`]);
|
|
141
|
+
writeFileSync(resolve(cwd, path), resolver(execContent, targetContent), "utf8");
|
|
142
|
+
gitOutput(cwd, ["add", "--", path]);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const side = theirs.has(path) || resolver ? target : "HEAD";
|
|
135
146
|
if (hasPathAt(cwd, side, path)) {
|
|
136
147
|
gitOutput(cwd, ["checkout", side, "--", path]);
|
|
137
148
|
gitOutput(cwd, ["add", "--", path]);
|
|
@@ -274,6 +285,7 @@ export function syncTaskWorktreesWithIntegrationTargets(params) {
|
|
|
274
285
|
message: params.message,
|
|
275
286
|
theirsPaths: params.projectTheirsPaths,
|
|
276
287
|
oursPaths: params.projectOursPaths,
|
|
288
|
+
resolvedPaths: params.projectResolvedPaths,
|
|
277
289
|
}));
|
|
278
290
|
return synced;
|
|
279
291
|
}
|
package/dist/exec/repo-trace.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { productMergeState } from "./repo-integration.js";
|
|
3
|
+
import { escapeMarkdownTableCell } from "../shared/text.js";
|
|
3
4
|
import { productIntegrationTarget } from "./task-repos.js";
|
|
4
5
|
import { gitOutput, gitResult } from "./worktree.js";
|
|
5
6
|
// PJR-30SW: プロダクト側の commit と merge commit へ付ける `Refs:` trailer と、統合後に result へ
|
|
@@ -96,7 +97,7 @@ function traceRows(key, traces, recordedAt) {
|
|
|
96
97
|
]);
|
|
97
98
|
}
|
|
98
99
|
function renderTable(header, rows) {
|
|
99
|
-
const escape = (cell) => cell
|
|
100
|
+
const escape = (cell) => escapeMarkdownTableCell(cell);
|
|
100
101
|
const all = [header.map(escape), ...rows.map((row) => row.map(escape))];
|
|
101
102
|
const widths = header.map((cell, column) => Math.max(3, cell.length, ...all.map((row) => (row[column] ?? "").length)));
|
|
102
103
|
const line = (cells) => `| ${cells.map((cell, column) => cell.padEnd(widths[column] ?? 0)).join(" | ")} |`;
|
package/dist/exec/reporter.js
CHANGED
|
@@ -377,7 +377,7 @@ function isHistoryLinkTargetPath(path) {
|
|
|
377
377
|
if (normalized === "pjr-index.md" || normalized.endsWith("/pjr-index.md")) {
|
|
378
378
|
return false;
|
|
379
379
|
}
|
|
380
|
-
return (
|
|
380
|
+
return (/^docs\/ja\/projects\/.+\/controls\/project-register\/pjr-[^/]+\.md$/u.test(normalized) ||
|
|
381
381
|
/^docs\/ja\/projects\/.+\/exec\/(?:plans|results)\/.+\.md$/u.test(normalized) ||
|
|
382
382
|
(isRunRecordPath(normalized) && /\/(plan|result)\.md$/u.test(normalized)));
|
|
383
383
|
}
|
|
@@ -407,7 +407,7 @@ const CHANGE_SCOPED_VALIDATIONS = [
|
|
|
407
407
|
matchesPath: hasExtension([".md"]),
|
|
408
408
|
},
|
|
409
409
|
{
|
|
410
|
-
pathCondition: "
|
|
410
|
+
pathCondition: "履歴蓄積ファイル(登録簿の個票 controls/project-register/pjr-*.md など、pjr-index.md と runner が書く plan・result を除く)",
|
|
411
411
|
matchesCommand: (command) => /^npm run validate:history-links(?:\s|$)/u.test(command) ||
|
|
412
412
|
/^(?:npx\s+)?specdojo-docs-lint\s+history-links(?:\s|$)/u.test(command) ||
|
|
413
413
|
/^node\s+\S*specdojo-docs-lint\.js\s+history-links(?:\s|$)/u.test(command),
|
package/dist/exec/results.js
CHANGED
|
@@ -9,7 +9,7 @@ import { dump } from "../shared/yaml.js";
|
|
|
9
9
|
import { formatMarkdownFile } from "./format.js";
|
|
10
10
|
import { deriveReporterFacts, mechanicallyNotApplicableReason, runnerOwnedValidationReason, } from "./reporter.js";
|
|
11
11
|
import { isRunRecordPath, listRunRecords, recordPathForRead, recordStem, resolveRunPlanRef, resultForPlan, taskRecordPaths, } from "./run-records.js";
|
|
12
|
-
import { escapeMarkdownInline, expandTemplate, stripTerminalControlSequences } from "./shared.js";
|
|
12
|
+
import { escapeMarkdownInline, expandTemplate, inlineCodeFrontmatterAnglePlaceholders, stripTerminalControlSequences, } from "./shared.js";
|
|
13
13
|
import { isCondenseRecords } from "../shared/condense-records.js";
|
|
14
14
|
import { inlineCode } from "./plans-grade-findings.js";
|
|
15
15
|
export const MAX_INDIVIDUAL_CHANGED_FILES = 50;
|
|
@@ -28,6 +28,22 @@ function serializeYamlString(value) {
|
|
|
28
28
|
const serialized = dump(value, { lineWidth: -1, noRefs: true }).replace(/\n$/, "");
|
|
29
29
|
return serialized.includes("\n") ? JSON.stringify(value) : serialized;
|
|
30
30
|
}
|
|
31
|
+
// executor 由来の condense の記録を frontmatter へ書き写す前に、コードスパン外の山括弧を
|
|
32
|
+
// code span 化する。むき出しの `<provider>` などは lint-fm で失敗する(PJR-V141)。
|
|
33
|
+
// 既に code span の語は変えないため、再シリアライズでも値は変わらない。
|
|
34
|
+
function frontmatterCondenseRecords(records) {
|
|
35
|
+
return records.map((record) => ({
|
|
36
|
+
...record,
|
|
37
|
+
location: inlineCodeFrontmatterAnglePlaceholders(record.location),
|
|
38
|
+
reason: inlineCodeFrontmatterAnglePlaceholders(record.reason),
|
|
39
|
+
cause: record.cause.type === "kata"
|
|
40
|
+
? {
|
|
41
|
+
...record.cause,
|
|
42
|
+
location: inlineCodeFrontmatterAnglePlaceholders(record.cause.location),
|
|
43
|
+
}
|
|
44
|
+
: record.cause,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
31
47
|
function serializeFrontmatter(meta) {
|
|
32
48
|
const inner = [
|
|
33
49
|
`id: ${serializeYamlString(meta.id)}`,
|
|
@@ -60,7 +76,7 @@ function serializeFrontmatter(meta) {
|
|
|
60
76
|
inner.push(` - ${serializeYamlString(target)}`);
|
|
61
77
|
}
|
|
62
78
|
if (meta.condense_records) {
|
|
63
|
-
inner.push(...dump({ condense_records: meta.condense_records }, { lineWidth: -1, noRefs: true })
|
|
79
|
+
inner.push(...dump({ condense_records: frontmatterCondenseRecords(meta.condense_records) }, { lineWidth: -1, noRefs: true })
|
|
64
80
|
.trimEnd()
|
|
65
81
|
.split("\n"));
|
|
66
82
|
}
|
|
@@ -68,7 +84,8 @@ function serializeFrontmatter(meta) {
|
|
|
68
84
|
// シーケンスや制御文字を除去し(色付き hook 出力が result 表示を壊すのを防ぐ)、JSON の
|
|
69
85
|
// 文字列形式で YAML へ埋め込む。改行・引用符・バックスラッシュも値を変えずに保持できる。
|
|
70
86
|
if (meta.block_reason) {
|
|
71
|
-
|
|
87
|
+
// executor の stderr(`blocked: <reason>` など)の山括弧も lint-fm で失敗するため code span 化する。
|
|
88
|
+
const safeReason = inlineCodeFrontmatterAnglePlaceholders(stripTerminalControlSequences(meta.block_reason));
|
|
72
89
|
inner.push(`block_reason: ${JSON.stringify(safeReason)}`);
|
|
73
90
|
}
|
|
74
91
|
return buildSpecdojoFrontmatter(inner);
|
|
@@ -745,7 +762,10 @@ export async function renderReporterResult(resultPath, output, evidence, options
|
|
|
745
762
|
throw new Error("condense requires valid executor condense_records (use [] when no candidates)");
|
|
746
763
|
}
|
|
747
764
|
// Preserve scaffold ownership; add only validated executor facts, never reporter prose.
|
|
748
|
-
const scaffold = {
|
|
765
|
+
const scaffold = {
|
|
766
|
+
...parsed.data,
|
|
767
|
+
condense_records: frontmatterCondenseRecords(evidence.condense_records),
|
|
768
|
+
};
|
|
749
769
|
frontmatter = `---\n${dump({ specdojo: scaffold }, { lineWidth: -1, noRefs: true }).trimEnd()}\n---`;
|
|
750
770
|
recordsBody = `\n\n## 5. 修正・保持の記録\n\n${renderCondenseRecords(evidence.condense_records)}`;
|
|
751
771
|
}
|
package/dist/exec/review-kata.js
CHANGED
|
@@ -37,7 +37,10 @@ export function scheduleKataReviewSubjects(task, deliverable, projectId) {
|
|
|
37
37
|
if (!rule || !["improve-kata", "bootstrap-kata-set"].includes(rule.intent))
|
|
38
38
|
return [];
|
|
39
39
|
const rulebook = deliverable?.deliverable.rulebook;
|
|
40
|
-
|
|
40
|
+
// improve-kata・bootstrap-kata-set の段は実践の型そのものを評価するため、kind: generated の
|
|
41
|
+
// 成果物でも宣言された rulebook を解決する(PJR-DM9B)。generated の扱いだけを外す。
|
|
42
|
+
const kind = deliverable?.deliverable.kind;
|
|
43
|
+
const refs = resolveKataRefs(rulebook, kind === "generated" ? undefined : kind);
|
|
41
44
|
const subjects = [{ path: refs.rulebook, label: "rulebook" }];
|
|
42
45
|
const declarations = rulebook ? loadRulebookRefs(rulebook) : {};
|
|
43
46
|
const declared = rulebook ? declaredKata(rulebook) : [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relative, sep } from "node:path";
|
|
1
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
2
2
|
import { enforceExecutorReportContract, executorCompletionFailure, recordExecutorEvidence, recordParentValidationFailureOutput, recordReporterFailureOutput, snapshotWorktreeChanges, writeExecutorEvidence, } from "../evidence.js";
|
|
3
3
|
import { failedParentValidationReason, hasRecordedParentValidations, parentValidationRoots, parentValidationSelectionForEvidence, replaceParentValidationResults, } from "../parent-validation.js";
|
|
4
4
|
import { createPipelineState, pipelineStateLocation, updatePipelineStage, writePipelineState, } from "../pipeline-state.js";
|
|
@@ -22,6 +22,7 @@ export async function refreshParentValidationsForReporterResume(params) {
|
|
|
22
22
|
`${force ? " (integration targets were merged into the worktree)" : ""}.\n`);
|
|
23
23
|
const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, parentValidationRoots(params.cwd, params.productWorktrees), {
|
|
24
24
|
label: params.evidence.task_id,
|
|
25
|
+
metricsPath: join(dirname(params.evidencePath), "parent-validation-metrics.jsonl"),
|
|
25
26
|
// 統合先を取り込んだ後は executor の変更以外も入るため、変更の種類で選ばずすべて流す。
|
|
26
27
|
...(force ? {} : { selection: parentValidationSelectionForEvidence(params.evidence) }),
|
|
27
28
|
});
|
|
@@ -127,7 +128,7 @@ export async function runReporterStage(params) {
|
|
|
127
128
|
evidence: reporterEvidence,
|
|
128
129
|
mode: params.mode ?? "edit",
|
|
129
130
|
invoke: async (reporterPrompt) => {
|
|
130
|
-
const reporterOutcome = await runWithRetry(reporterCandidates, reporterPrompt, execDefaults, cwd, env, params.resultPath, params.rateLimitOptions);
|
|
131
|
+
const reporterOutcome = await runWithRetry(reporterCandidates, reporterPrompt, execDefaults, cwd, env, params.resultPath, params.rateLimitOptions, "reporter");
|
|
131
132
|
reporterAttempts += reporterOutcome.attempts;
|
|
132
133
|
reporterActor = reporterOutcome.actor ?? reporterActor;
|
|
133
134
|
rateLimitEvents.push(...reporterOutcome.rateLimitEvents);
|
package/dist/exec/run/agent.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { basename, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { trackExecutor, withValidationMetrics } from "../validation-metrics.js";
|
|
4
5
|
import { resolveConnectionErrorDetection, resolveMemberCommand, resolveRateLimitDetection, resolveRateLimitPolicy, } from "../agent-config.js";
|
|
5
6
|
import { decidePinnedWait, normalizeAgentLimit, } from "../limit.js";
|
|
6
7
|
import { replaceDocIndexRefs } from "../../docs/doc-index.js";
|
|
8
|
+
import { localConfigEnvironment } from "../../shared/local-config.js";
|
|
7
9
|
import { loadPlan, parsePlanTaskIdentity } from "../plans.js";
|
|
8
10
|
import { recordParentValidationFailureOutput, validateResumedTargetCoverage, writeExecutorEvidence, } from "../evidence.js";
|
|
9
11
|
import { parentValidationDisplayCommands, parentValidationGateFor, parentValidationLabels, parentValidationRoots, parentValidationSelectionForEvidence, recordedParentValidationLabel, replaceParentValidationResults, runParentValidationBatch, } from "../parent-validation.js";
|
|
@@ -211,10 +213,10 @@ export async function runConfiguredParentValidationBatch(execDefaults, cwd, opti
|
|
|
211
213
|
return { validations: [], failureOutputs: [] };
|
|
212
214
|
const labels = parentValidationLabels(entries);
|
|
213
215
|
const label = options.label ?? basename(typeof cwd === "string" ? cwd : cwd.project);
|
|
214
|
-
const batch = await parentValidationGateFor(execDefaults).run(label, labels, async () => {
|
|
216
|
+
const batch = await withValidationMetrics(label, options.metricsPath, () => parentValidationGateFor(execDefaults).run(label, labels, async () => {
|
|
215
217
|
process.stdout.write(` Running parent validations (${label}): ${labels.join(", ")}\n`);
|
|
216
218
|
return await runParentValidationBatch(entries, cwd, options.invoke, options.selection);
|
|
217
|
-
});
|
|
219
|
+
}));
|
|
218
220
|
for (const validation of batch.validations) {
|
|
219
221
|
process.stdout.write(` Parent validation ${recordedParentValidationLabel(validation)}: ${validation.status}\n`);
|
|
220
222
|
}
|
|
@@ -229,6 +231,7 @@ export async function runConfiguredParentValidations(execDefaults, cwd, options
|
|
|
229
231
|
export async function appendParentValidationsToExecutorEvidence(params) {
|
|
230
232
|
const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, parentValidationRoots(params.cwd, params.productWorktrees), {
|
|
231
233
|
label: params.evidence.task_id,
|
|
234
|
+
metricsPath: join(dirname(params.evidencePath), "parent-validation-metrics.jsonl"),
|
|
232
235
|
selection: parentValidationSelectionForEvidence(params.evidence),
|
|
233
236
|
});
|
|
234
237
|
const evidenceWithValidations = replaceParentValidationResults(params.evidence, parentValidationBatch.validations);
|
|
@@ -313,7 +316,7 @@ export function loadRosterForExecutionPath(executionPath) {
|
|
|
313
316
|
}
|
|
314
317
|
return null;
|
|
315
318
|
}
|
|
316
|
-
export async function executeAgent(agentCommand, prompt, detection, provider, cooldownSeconds, cwd, env, quiet = false) {
|
|
319
|
+
export async function executeAgent(agentCommand, prompt, detection, provider, cooldownSeconds, cwd, env, quiet = false, stageRole = "executor") {
|
|
317
320
|
if (!agentCommand.trim()) {
|
|
318
321
|
return { result: "failure", exitCode: null, stdout: "", stderr: "Empty agent command" };
|
|
319
322
|
}
|
|
@@ -326,6 +329,7 @@ export async function executeAgent(agentCommand, prompt, detection, provider, co
|
|
|
326
329
|
shell: true,
|
|
327
330
|
stdio: ["pipe", "pipe", "pipe"],
|
|
328
331
|
});
|
|
332
|
+
const stopTracking = stageRole === "executor" ? trackExecutor(child.pid, cwd) : () => undefined;
|
|
329
333
|
// stdin を読まずに即終了するコマンドへの書き込みは EPIPE になる。未処理だと
|
|
330
334
|
// プロセスごと落ちて失敗時の後処理(block 遷移・result 更新)が走らないため無視する。
|
|
331
335
|
// 実行結果は終了コードで判定する。
|
|
@@ -351,6 +355,7 @@ export async function executeAgent(agentCommand, prompt, detection, provider, co
|
|
|
351
355
|
});
|
|
352
356
|
child.once("close", (code) => resolveExit(code));
|
|
353
357
|
});
|
|
358
|
+
stopTracking();
|
|
354
359
|
const combinedOutput = `${stdout}\n${stderr}`;
|
|
355
360
|
if (isRateLimitError(exitCode, combinedOutput, detection)) {
|
|
356
361
|
return {
|
|
@@ -392,7 +397,7 @@ export function reportProtectionHandoffRecord(recorded, resultPath) {
|
|
|
392
397
|
function rateLimitPrefix(result) {
|
|
393
398
|
return result === "rate_limit" ? "rate limit reached; " : "";
|
|
394
399
|
}
|
|
395
|
-
export async function runWithRetry(candidates, prompt, execDefaults, cwd, env, resultPath, pinned) {
|
|
400
|
+
export async function runWithRetry(candidates, prompt, execDefaults, cwd, env, resultPath, pinned, stageRole = "executor") {
|
|
396
401
|
const policy = resolveRateLimitPolicy(execDefaults, candidates[0]?.provider);
|
|
397
402
|
let attempts = 0;
|
|
398
403
|
// PJR-98G4: agentEnvironment が渡したプロダクト worktree を、provider の追加ディレクトリと
|
|
@@ -420,7 +425,7 @@ export async function runWithRetry(candidates, prompt, execDefaults, cwd, env, r
|
|
|
420
425
|
lastActor = candidate.actor;
|
|
421
426
|
const protectedConfigBefore = captureAgentProtectedConfigAcrossRepos(agentRepos);
|
|
422
427
|
const gitStateBefore = captureAgentGitStateAcrossRepos(agentRepos);
|
|
423
|
-
const attempt = await executeAgent(withAgentExtraRoots(candidate.command, candidate.provider, productRoots.map((root) => root.path)), prompt, detection, candidate.provider, candidatePolicy?.cooldown_seconds, cwd, env);
|
|
428
|
+
const attempt = await executeAgent(withAgentExtraRoots(candidate.command, candidate.provider, productRoots.map((root) => root.path), { cwd, env }), prompt, detection, candidate.provider, candidatePolicy?.cooldown_seconds, cwd, env, false, stageRole);
|
|
424
429
|
const protectedConfigChanges = changedAgentProtectedConfigAcrossRepos(protectedConfigBefore);
|
|
425
430
|
if (protectedConfigChanges.length > 0) {
|
|
426
431
|
// 利用上限で止まった場合も保護の検査は飛ばさない。止まった理由として利用上限を先に記録する。
|
|
@@ -618,6 +623,7 @@ export function reportProductWorktrees(worktree) {
|
|
|
618
623
|
export function agentEnvironment(repoRoot, worktreePath, schedulePath, executionPath, productWorktrees) {
|
|
619
624
|
return {
|
|
620
625
|
...withoutInheritedRepoEnvironment(gitEnvironment()),
|
|
626
|
+
...localConfigEnvironment(repoRoot),
|
|
621
627
|
SPECDOJO_SCHEDULE_PATH: pathInsideWorktree(repoRoot, worktreePath, schedulePath),
|
|
622
628
|
SPECDOJO_EXECUTION_PATH: pathInsideWorktree(repoRoot, worktreePath, executionPath),
|
|
623
629
|
...productRepoEnvironment(worktreePath, productWorktrees),
|