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,365 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
4
|
+
import { isAbsolute, join, posix, relative } from "node:path";
|
|
5
|
+
import { unified } from "unified";
|
|
6
|
+
import remarkParse from "remark-parse";
|
|
7
|
+
import { collectDocIndexEntries } from "../../docs/doc-index.js";
|
|
8
|
+
import { authoredKataPath, authoringKind, isAuthoringApproach } from "../../kata/authoring.js";
|
|
9
|
+
import { readSpecdojoNamespace } from "../../docs/frontmatter-namespace.js";
|
|
10
|
+
import { gitEnvironment } from "../../shared/git-environment.js";
|
|
11
|
+
import { resolveDeliverableByDocId } from "../plans-core.js";
|
|
12
|
+
import { delay, isLiveLock, readLockOwner, releaseLock, tryAcquireLock, } from "../slot-lock.js";
|
|
13
|
+
import { execLocksDir } from "./lock.js";
|
|
14
|
+
export function parseUnknownScopePolicy(value) {
|
|
15
|
+
if (value === undefined || value === "parallel" || value === "serialize")
|
|
16
|
+
return value ?? "parallel";
|
|
17
|
+
throw new Error("--unknown-scope must be parallel or serialize");
|
|
18
|
+
}
|
|
19
|
+
// No filesystem access: declarations may name a file that does not exist yet. Glob prefixes
|
|
20
|
+
// conservatively reserve their parent directory; line/function suffixes reserve the whole file.
|
|
21
|
+
export function normalizeScopePath(value) {
|
|
22
|
+
const text = value
|
|
23
|
+
.trim()
|
|
24
|
+
.replaceAll("\\", "/")
|
|
25
|
+
.replace(/#.*$|:\d+(?::\d+)?$/g, "");
|
|
26
|
+
if (!text || text.startsWith("/") || text.includes("://"))
|
|
27
|
+
return undefined;
|
|
28
|
+
const match = text.match(/^(?:([a-zA-Z][\w-]*):)?(.*)$/);
|
|
29
|
+
if (!match)
|
|
30
|
+
return undefined;
|
|
31
|
+
const repo = match[1] ?? "project";
|
|
32
|
+
let path = match[2];
|
|
33
|
+
const glob = path.search(/[*?{[]/);
|
|
34
|
+
if (glob >= 0)
|
|
35
|
+
path = path.slice(0, glob).replace(/[^/]*$/, "");
|
|
36
|
+
path = posix.normalize(path).replace(/\/$/, "");
|
|
37
|
+
if (path === ".." || path.startsWith("../"))
|
|
38
|
+
return undefined;
|
|
39
|
+
return `${repo}:${path}`;
|
|
40
|
+
}
|
|
41
|
+
// Generated plans mix task inputs with shared operating instructions. Read only task-specific
|
|
42
|
+
// sections, including findings nested under the otherwise shared procedure section. Parse real
|
|
43
|
+
// headings so headings in fenced examples cannot change which sections are selected.
|
|
44
|
+
function scopeInputText(text) {
|
|
45
|
+
const isPlan = readSpecdojoNamespace(text).type === "exec-plan" || /^# .*Plan:/m.test(text);
|
|
46
|
+
const body = text.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, "");
|
|
47
|
+
const headings = unified()
|
|
48
|
+
.use(remarkParse)
|
|
49
|
+
.parse(body)
|
|
50
|
+
.children.filter((node) => node.type === "heading");
|
|
51
|
+
const parts = [];
|
|
52
|
+
let include = true;
|
|
53
|
+
let start = 0;
|
|
54
|
+
let currentSection = "";
|
|
55
|
+
for (const heading of headings) {
|
|
56
|
+
const offset = heading.position.start.offset;
|
|
57
|
+
if (include)
|
|
58
|
+
parts.push(body.slice(start, offset));
|
|
59
|
+
const title = body
|
|
60
|
+
.slice(offset, heading.position.end.offset)
|
|
61
|
+
.replace(/^#+\s+(?:\d+(?:\.\d+)*\.\s*)?/, "")
|
|
62
|
+
.trim();
|
|
63
|
+
if (heading.depth === 2) {
|
|
64
|
+
if (/^(?:対応結果|関連ドキュメント|共通|変更範囲による実行待ち)/.test(title)) {
|
|
65
|
+
include = false;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
include =
|
|
69
|
+
!isPlan ||
|
|
70
|
+
/^(?:この.*行うこと|対象|個票の(?:入力|追加完了条件)|概要|入力|完了条件|完了の狙い|作業内容|制約|根拠となる成果物と編集対象|新しく作る実践の型)/.test(title);
|
|
71
|
+
}
|
|
72
|
+
else if (isPlan && heading.depth === 3) {
|
|
73
|
+
// Findings are item-specific even when embedded in common instructions.
|
|
74
|
+
if (/^(?:grade result から展開された finding|成果物から届いた Kata が原因の finding)$/.test(title))
|
|
75
|
+
include = true;
|
|
76
|
+
else if (/^進め方$/.test(currentSection))
|
|
77
|
+
include = false;
|
|
78
|
+
}
|
|
79
|
+
if (heading.depth === 2)
|
|
80
|
+
currentSection = title;
|
|
81
|
+
start = offset;
|
|
82
|
+
}
|
|
83
|
+
if (include)
|
|
84
|
+
parts.push(body.slice(start));
|
|
85
|
+
return parts.join("\n");
|
|
86
|
+
}
|
|
87
|
+
// Exclude only prose clauses that explicitly say not to edit their paths. Do not blacklist
|
|
88
|
+
// protected filenames: a positive mention elsewhere or an explicit target must still reserve
|
|
89
|
+
// them. Keep inline code intact so punctuation in paths cannot split a clause.
|
|
90
|
+
function scopeChangeText(text) {
|
|
91
|
+
const unchanged = /(?:変え(?:ない|ず)|(?:変更|編集|更新|修正)(?:し(?:ない|ません|なく)|せず)|触ら(?:ない|ず))(?:こと)?(?:が)?(?:\s*[((][^()()]*[))])?\s*$/;
|
|
92
|
+
const continuedAction = /(?:変更|編集|更新|修正|追加|削除)(?:し|して|する|します)(?:が)?\s*$/;
|
|
93
|
+
const parts = [];
|
|
94
|
+
let clause = "";
|
|
95
|
+
const flush = () => {
|
|
96
|
+
if (!unchanged.test(clause))
|
|
97
|
+
parts.push(clause);
|
|
98
|
+
clause = "";
|
|
99
|
+
};
|
|
100
|
+
for (const [token] of text.matchAll(/`[^`\n]+`|[。;;\n|、,]|[^`。;;\n|、,]+|`/g)) {
|
|
101
|
+
if (/^[。;;\n|]$/.test(token)) {
|
|
102
|
+
flush();
|
|
103
|
+
}
|
|
104
|
+
else if (/^[、,]$/.test(token) && (unchanged.test(clause) || continuedAction.test(clause))) {
|
|
105
|
+
// Split after a predicate, but keep comma-separated path lists with their predicate.
|
|
106
|
+
flush();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
clause += token;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
flush();
|
|
113
|
+
return parts.join("\n");
|
|
114
|
+
}
|
|
115
|
+
export function inferChangeScope(params) {
|
|
116
|
+
const paths = new Set();
|
|
117
|
+
let unresolved = false;
|
|
118
|
+
const add = (path) => {
|
|
119
|
+
const normalized = normalizeScopePath(path);
|
|
120
|
+
if (!normalized) {
|
|
121
|
+
unresolved = true;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!/(?:^|\/)generated(?:\/|$)/.test(normalized.split(":")[1]))
|
|
125
|
+
paths.add(normalized);
|
|
126
|
+
};
|
|
127
|
+
const configPath = (path) => (isAbsolute(path) ? relative(params.repoRoot, path) : path);
|
|
128
|
+
let index = params.documentPaths;
|
|
129
|
+
const targets = isAuthoringApproach(params.approach)
|
|
130
|
+
? params.targets?.slice(0, 1)
|
|
131
|
+
: params.targets;
|
|
132
|
+
// Commit permissions cover whole kata directories; reserve only the resolved task targets.
|
|
133
|
+
for (const target of targets ?? []) {
|
|
134
|
+
if (params.approach === "catalog-planning" &&
|
|
135
|
+
/^domain:[\w-]+$/.test(target) &&
|
|
136
|
+
params.catalogPath) {
|
|
137
|
+
// Every domain may also update the shared dct-index.yaml.
|
|
138
|
+
add(configPath(params.catalogPath));
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (params.approach === "strategy-planning" &&
|
|
142
|
+
/^track:[\w-]+$/.test(target) &&
|
|
143
|
+
params.schedulePath) {
|
|
144
|
+
const track = target.slice("track:".length);
|
|
145
|
+
add(join(configPath(params.schedulePath), `sch-strategy-${track}.yaml`));
|
|
146
|
+
add(join(configPath(params.schedulePath), `sch-track-${track}.yaml`));
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (target.includes("/") || /\.(?:md|tsx?|jsx?|json|ya?ml)$/.test(target)) {
|
|
150
|
+
add(target);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (params.targetPath && target === targets?.[0]) {
|
|
154
|
+
add(params.targetPath);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
index ??= collectDocIndexEntries(join(params.repoRoot, "docs"), params.repoRoot);
|
|
158
|
+
const indexed = index[target]?.replace(/:\d+$/, "");
|
|
159
|
+
if (indexed) {
|
|
160
|
+
add(indexed);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const kind = authoringKind(params.approach);
|
|
164
|
+
if (kind) {
|
|
165
|
+
add(authoredKataPath(target, kind));
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
add(resolveDeliverableByDocId(params.catalogPath ?? "", params.projectId, target, params.repoRoot).info.resolvedPath);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
unresolved = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (params.targetPath)
|
|
176
|
+
add(params.targetPath);
|
|
177
|
+
// Backticks support root files; prose supports src/foo.ts.
|
|
178
|
+
const texts = typeof params.text === "string" ? [params.text] : (params.text ?? []);
|
|
179
|
+
const body = texts.map((text) => scopeChangeText(scopeInputText(text))).join("\n");
|
|
180
|
+
const addTextPath = (path) => {
|
|
181
|
+
// Per-item bookkeeping is already serialized by lifecycle and same-item locks. Its presence
|
|
182
|
+
// in a generated plan must not make an otherwise unknown implementation scope look known.
|
|
183
|
+
if (/(?:^|\/)execution\/(?:runs|exec|conventions)\/|(?:^|\/)controls\/project-register\/pjr-[^/]+\.md$/.test(path))
|
|
184
|
+
return;
|
|
185
|
+
add(path);
|
|
186
|
+
};
|
|
187
|
+
for (const match of body.matchAll(/`([^`\n]+)`/g)) {
|
|
188
|
+
const value = match[1].replace(/#.*$|:\d+(?::\d+)?$/g, "");
|
|
189
|
+
if (/^(?:[\w-]+:)?\.?\/?[\w@.-]+\/[\w@.*?{}[\]/-]*$/.test(value) ||
|
|
190
|
+
/^[\w.-]+\.[a-z0-9]+$/i.test(value))
|
|
191
|
+
addTextPath(value);
|
|
192
|
+
}
|
|
193
|
+
for (const match of body.matchAll(/(?:^|[\s`((・])((?:[\w-]+:)?[\w@.-]+\/[\w@.*?{}[\]/-]+)/gm)) {
|
|
194
|
+
const value = match[1];
|
|
195
|
+
// A slash in prose can also mean alternatives (executor/reporter). Accept filenames,
|
|
196
|
+
// explicit directory/glob syntax, or an existing repository path rather than every slash.
|
|
197
|
+
const normalized = normalizeScopePath(value);
|
|
198
|
+
if (/\/[^/]*\.[\w]+$|\/$|[*?{[]/.test(value) ||
|
|
199
|
+
(normalized?.startsWith("project:") &&
|
|
200
|
+
existsSync(join(params.repoRoot, normalized.slice("project:".length)))))
|
|
201
|
+
addTextPath(value);
|
|
202
|
+
}
|
|
203
|
+
// Ignore derived views even when their layout predates generated/. Keep candidates if Git
|
|
204
|
+
// cannot verify ignore rules (for example, a project not yet initialized as a repository).
|
|
205
|
+
const candidates = [...paths]
|
|
206
|
+
.filter((path) => path.startsWith("project:"))
|
|
207
|
+
.map((path) => path.slice("project:".length));
|
|
208
|
+
if (candidates.length) {
|
|
209
|
+
const ignored = spawnSync("git", ["check-ignore", "-z", "--stdin"], {
|
|
210
|
+
cwd: params.repoRoot,
|
|
211
|
+
env: gitEnvironment(),
|
|
212
|
+
input: `${candidates.join("\0")}\0`,
|
|
213
|
+
encoding: "utf8",
|
|
214
|
+
timeout: 10_000,
|
|
215
|
+
});
|
|
216
|
+
if (!ignored.error && (ignored.status === 0 || ignored.status === 1))
|
|
217
|
+
for (const path of ignored.stdout.split("\0").filter(Boolean))
|
|
218
|
+
paths.delete(`project:${path}`);
|
|
219
|
+
}
|
|
220
|
+
return { paths: [...paths].sort(), unknown: unresolved || paths.size === 0 };
|
|
221
|
+
}
|
|
222
|
+
export function scopeOverlap(a, b) {
|
|
223
|
+
if (a.unknown || b.unknown)
|
|
224
|
+
return "unknown scope (serialize)";
|
|
225
|
+
for (const left of a.paths)
|
|
226
|
+
for (const right of b.paths) {
|
|
227
|
+
const root = (value) => (value.endsWith(":.") ? value.slice(0, -1) : `${value}/`);
|
|
228
|
+
if (left === right || left.startsWith(root(right)) || right.startsWith(root(left)))
|
|
229
|
+
return `${left} <> ${right}`;
|
|
230
|
+
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
function writeReservation(path, record) {
|
|
234
|
+
writeFileSync(`${path}.tmp`, JSON.stringify(record));
|
|
235
|
+
renameSync(`${path}.tmp`, path);
|
|
236
|
+
}
|
|
237
|
+
// The short registry mutex protects check+reserve as one operation, including across --join
|
|
238
|
+
// processes. Per-item heartbeat locks cover setup, agents, validation AND integration. Failed
|
|
239
|
+
// or crashed reservations remain barriers until that same item is retried/resumed.
|
|
240
|
+
export class ChangeScopeGate {
|
|
241
|
+
policy;
|
|
242
|
+
options;
|
|
243
|
+
directory;
|
|
244
|
+
waits = new Map();
|
|
245
|
+
constructor(executionPath, policy = "parallel", options = {}) {
|
|
246
|
+
this.policy = policy;
|
|
247
|
+
this.options = options;
|
|
248
|
+
this.directory = join(execLocksDir(executionPath), "change-scopes");
|
|
249
|
+
}
|
|
250
|
+
async registry(action) {
|
|
251
|
+
mkdirSync(this.directory, { recursive: true });
|
|
252
|
+
let handle;
|
|
253
|
+
while (!(handle = tryAcquireLock(join(this.directory, "registry.lock"), { actor: "change-scope" }, this.options)))
|
|
254
|
+
await delay(this.options.pollMs ?? 200);
|
|
255
|
+
try {
|
|
256
|
+
return action();
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
releaseLock(handle);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async tryAcquire(item, scope) {
|
|
263
|
+
return this.registry(() => {
|
|
264
|
+
const effective = { ...scope, unknown: scope.unknown && this.policy === "serialize" };
|
|
265
|
+
const key = createHash("sha256").update(item).digest("hex");
|
|
266
|
+
const recordPath = join(this.directory, `${key}.json`);
|
|
267
|
+
const lockPath = join(this.directory, `${key}.lock`);
|
|
268
|
+
if (existsSync(recordPath)) {
|
|
269
|
+
const prior = JSON.parse(readFileSync(recordPath, "utf8"));
|
|
270
|
+
effective.paths = [...new Set([...prior.scope.paths, ...effective.paths])];
|
|
271
|
+
effective.unknown ||= prior.scope.unknown;
|
|
272
|
+
}
|
|
273
|
+
for (const name of readdirSync(this.directory).filter((name) => /^[a-f0-9]{64}\.json$/.test(name))) {
|
|
274
|
+
const record = JSON.parse(readFileSync(join(this.directory, name), "utf8"));
|
|
275
|
+
const live = isLiveLock(join(this.directory, name.replace(/\.json$/, ".lock")), this.options.staleMs);
|
|
276
|
+
if (record.item === item && !live)
|
|
277
|
+
continue;
|
|
278
|
+
const overlap = record.item === item ? "same item" : scopeOverlap(effective, record.scope);
|
|
279
|
+
if (!overlap)
|
|
280
|
+
continue;
|
|
281
|
+
const waits = this.waits.get(item) ?? [];
|
|
282
|
+
if (!waits.some((wait) => wait.blocker === record.item && wait.overlap === overlap)) {
|
|
283
|
+
const wait = { item, blocker: record.item, overlap, at: new Date().toISOString() };
|
|
284
|
+
waits.push(wait);
|
|
285
|
+
this.waits.set(item, waits);
|
|
286
|
+
appendFileSync(join(this.directory, "waits.jsonl"), `${JSON.stringify(wait)}\n`);
|
|
287
|
+
process.stdout.write(` [scope] waiting: ${item} — ${record.item}: ${overlap}\n`);
|
|
288
|
+
}
|
|
289
|
+
if (record.state === "blocked" || !live)
|
|
290
|
+
throw new Error(`[scope] ${item} blocked by unintegrated ${record.item}: ${overlap}; resume/retry ${record.item} first`);
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
const handle = tryAcquireLock(lockPath, { actor: "change-scope", label: item }, this.options);
|
|
294
|
+
if (!handle)
|
|
295
|
+
return null;
|
|
296
|
+
try {
|
|
297
|
+
writeReservation(recordPath, { item, scope: effective, state: "running" });
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
releaseLock(handle);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
const waits = this.waits.get(item) ?? [];
|
|
304
|
+
this.waits.delete(item);
|
|
305
|
+
let finished = false;
|
|
306
|
+
return {
|
|
307
|
+
waits,
|
|
308
|
+
finish: async (integrated) => {
|
|
309
|
+
await this.registry(() => {
|
|
310
|
+
if (finished)
|
|
311
|
+
return;
|
|
312
|
+
if (readLockOwner(lockPath)?.token !== handle.token) {
|
|
313
|
+
releaseLock(handle);
|
|
314
|
+
finished = true;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (integrated)
|
|
318
|
+
rmSync(recordPath, { force: true });
|
|
319
|
+
else
|
|
320
|
+
writeReservation(recordPath, { item, scope: effective, state: "blocked" });
|
|
321
|
+
releaseLock(handle);
|
|
322
|
+
finished = true;
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
async acquire(item, scope) {
|
|
329
|
+
while (true) {
|
|
330
|
+
const lease = await this.tryAcquire(item, scope);
|
|
331
|
+
if (lease)
|
|
332
|
+
return lease;
|
|
333
|
+
await delay(this.options.pollMs ?? 200);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
async clearIntegrated(item) {
|
|
337
|
+
await this.registry(() => {
|
|
338
|
+
const key = createHash("sha256").update(item).digest("hex");
|
|
339
|
+
// Batch leases are released by the worker. Standalone schedule resumes run under the
|
|
340
|
+
// exclusive project lock and clear the retained failure barrier after integration.
|
|
341
|
+
if (!isLiveLock(join(this.directory, `${key}.lock`), this.options.staleMs))
|
|
342
|
+
rmSync(join(this.directory, `${key}.json`), { force: true });
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
export function appendScopeWaitNotes(planPath, waits) {
|
|
347
|
+
if (!waits?.length || !existsSync(planPath))
|
|
348
|
+
return;
|
|
349
|
+
const plan = readFileSync(planPath, "utf8");
|
|
350
|
+
// Convention expansion and checkpoint discovery require the snapshot reference to remain
|
|
351
|
+
// the final paragraph. Insert runner notes before it, including for legacy plan references.
|
|
352
|
+
const reference = /\n(?:`共通規約 sha256:[a-f0-9]{64}` `[^`\r\n]+`|\[共通規約 sha256:[a-f0-9]{64}\]\([^\s)]+\))\s*$/.exec(plan);
|
|
353
|
+
const offset = reference?.index ?? plan.length;
|
|
354
|
+
const notes = `## 変更範囲による実行待ち\n\n${waits.map((wait) => `- ${wait.at}: \`${wait.item}\` は \`${wait.blocker}\` の統合を待った。重複: \`${wait.overlap}\`。`).join("\n")}\n`;
|
|
355
|
+
writeFileSync(planPath, `${plan.slice(0, offset).trimEnd()}\n\n${notes}${plan.slice(offset)}`);
|
|
356
|
+
}
|
|
357
|
+
export function scopePlanMetadata(text) {
|
|
358
|
+
const metadata = readSpecdojoNamespace(text);
|
|
359
|
+
return {
|
|
360
|
+
targets: Array.isArray(metadata.targets)
|
|
361
|
+
? metadata.targets.filter((v) => typeof v === "string")
|
|
362
|
+
: undefined,
|
|
363
|
+
approach: metadata.approach,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// 統合の後の片付け(worktree と exec branch の撤去)。`run` はロックの外で走り、`after` は
|
|
2
|
+
// 片付けの結果を受けて、もう一度ロックの中で記帳を仕上げる。
|
|
3
|
+
export class DeferredCleanup {
|
|
4
|
+
run;
|
|
5
|
+
after;
|
|
6
|
+
constructor(run, after) {
|
|
7
|
+
this.run = run;
|
|
8
|
+
this.after = after;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function runLocked(lock, fn) {
|
|
12
|
+
return lock ? lock.runExclusive(fn) : Promise.resolve().then(fn);
|
|
13
|
+
}
|
|
14
|
+
// PJR-NHT7: 遅いファイルシステムでは `git worktree remove` が数十分かかる。統合と記帳は
|
|
15
|
+
// ロックの中で行い、片付けはロックを解放してから行う。片付けの間、別の項目の記帳や
|
|
16
|
+
// `specdojo git` はロックを待たない。`integrate` が DeferredCleanup 以外を返した場合は、
|
|
17
|
+
// それをそのまま結果にする。
|
|
18
|
+
export async function runWithDeferredCleanup(lock, integrate) {
|
|
19
|
+
const integrated = await runLocked(lock, integrate);
|
|
20
|
+
if (!(integrated instanceof DeferredCleanup))
|
|
21
|
+
return integrated;
|
|
22
|
+
let outcome;
|
|
23
|
+
try {
|
|
24
|
+
await integrated.run();
|
|
25
|
+
outcome = { ok: true };
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
outcome = { ok: false, error };
|
|
29
|
+
}
|
|
30
|
+
return runLocked(lock, () => integrated.after(outcome));
|
|
31
|
+
}
|
|
@@ -19,6 +19,7 @@ import { randomHex } from "../shared.js";
|
|
|
19
19
|
import { configuredProductCheckouts, productRepoEnvironment, withAgentExtraRoots, withoutInheritedRepoEnvironment, } from "../task-repos.js";
|
|
20
20
|
import { buildTaskView } from "../task-view.js";
|
|
21
21
|
import { gitEnvironment } from "../worktree.js";
|
|
22
|
+
import { trackExecutor } from "../validation-metrics.js";
|
|
22
23
|
import { appendParentValidationsToExecutorEvidence, buildExecutorPrompt, executorRequirements, expandPromptRefs, extractBlockReason, loadRosterForExecutionPath, reportProtectionHandoffRecord, resolveReporterAgentCandidates, runWithRetry, } from "./agent.js";
|
|
23
24
|
import { pipelineRecoveryMeta, spawnBlock, spawnClaim, spawnComplete, stageActorMeta, } from "./mode-shared.js";
|
|
24
25
|
import { enforceScheduleKataReview, gradeBeforeReviewPlan } from "./schedule-prepare.js";
|
|
@@ -110,7 +111,7 @@ export async function spawnAgentInPlace(command, prompt, cwd, schedulePath, exec
|
|
|
110
111
|
const protectedConfigBefore = captureAgentProtectedConfigSnapshot(cwd);
|
|
111
112
|
const gitStateBefore = captureAgentGitStateSnapshot(cwd);
|
|
112
113
|
const products = configuredProductCheckouts(schedulePath);
|
|
113
|
-
const child = spawn(withAgentExtraRoots(command, provider, products.map((product) => product.path)), {
|
|
114
|
+
const child = spawn(withAgentExtraRoots(command, provider, products.map((product) => product.path), { cwd }), {
|
|
114
115
|
cwd,
|
|
115
116
|
env: {
|
|
116
117
|
...withoutInheritedRepoEnvironment(gitEnvironment()),
|
|
@@ -122,12 +123,14 @@ export async function spawnAgentInPlace(command, prompt, cwd, schedulePath, exec
|
|
|
122
123
|
stdio: ["pipe", "inherit", "inherit"],
|
|
123
124
|
});
|
|
124
125
|
// executeAgent と同じ理由で、stdin を読まないコマンドの EPIPE は無視する。
|
|
126
|
+
const stopTracking = trackExecutor(child.pid, cwd);
|
|
125
127
|
child.stdin.on("error", () => undefined);
|
|
126
128
|
child.stdin.end(prompt);
|
|
127
129
|
const exitCode = await new Promise((resolveExit) => {
|
|
128
130
|
child.once("error", () => resolveExit(1));
|
|
129
131
|
child.once("close", (code) => resolveExit(code ?? 1));
|
|
130
132
|
});
|
|
133
|
+
stopTracking();
|
|
131
134
|
const protectedConfigChanges = changedAgentProtectedConfigPaths(cwd, protectedConfigBefore);
|
|
132
135
|
if (protectedConfigChanges.length > 0) {
|
|
133
136
|
const reason = agentProtectedConfigViolation(protectedConfigChanges);
|
|
@@ -464,7 +467,7 @@ export async function runInPlaceMode(opts) {
|
|
|
464
467
|
SPECDOJO_EXECUTION_PATH: executionPath,
|
|
465
468
|
}, resultPath, (opts.reporterBy ?? pinnedReporter(task))
|
|
466
469
|
? resolvePinnedRateLimitRunOptions(opts, execDefaults, roster, "reporter", reporterCandidates[0])
|
|
467
|
-
: undefined);
|
|
470
|
+
: undefined, "reporter");
|
|
468
471
|
reporterAttempts += reporterOutcome.attempts;
|
|
469
472
|
reporterActor = reporterOutcome.actor ?? reporterActor;
|
|
470
473
|
reporterRateLimitEvents.push(...reporterOutcome.rateLimitEvents);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { isJobCommandTask, loadJobDefinition, materializeJobRun, resolveJobPaths, } from "../../job/job.js";
|
|
4
|
+
import { resolveProjectPaths } from "../project.js";
|
|
5
|
+
import { releaseLock, tryAcquireLock } from "../slot-lock.js";
|
|
6
|
+
import { runJobMode } from "./job.js";
|
|
7
|
+
import { execLocksDir, ExecRunLockTimeoutError, inheritsExecRunLock } from "./lock.js";
|
|
8
|
+
import { withProjectExecRunLock } from "./shared.js";
|
|
9
|
+
/** A sequence waits for exclusive access, including when invoked by routine/cron. */
|
|
10
|
+
export async function runJobWithProjectLock(opts, resolver) {
|
|
11
|
+
const paths = resolveProjectPaths({ project: opts.project });
|
|
12
|
+
const definition = loadJobDefinition(resolveJobPaths(paths.projectId ?? opts.project), String(opts.job));
|
|
13
|
+
if (!isJobCommandTask(definition.task) || !definition.task.steps) {
|
|
14
|
+
await withProjectExecRunLock(opts, "run", () => runJobMode(opts, resolver));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (opts.dryRun) {
|
|
18
|
+
await runJobMode(opts, resolver);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (inheritsExecRunLock(paths.executionPath)) {
|
|
22
|
+
await withProjectExecRunLock(opts, "run", () => runJobMode(opts, resolver));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const preview = await materializeJobRun({
|
|
26
|
+
projectId: paths.projectId ?? opts.project,
|
|
27
|
+
jobId: String(opts.job),
|
|
28
|
+
inputs: opts.input,
|
|
29
|
+
scheduledAt: opts.scheduledAt,
|
|
30
|
+
dryRun: true,
|
|
31
|
+
});
|
|
32
|
+
// Guard the logical Run while waiting too. A duplicate caller must not overwrite a
|
|
33
|
+
// running attempt with a timeout result. Different Runs still queue on the project lock.
|
|
34
|
+
mkdirSync(execLocksDir(paths.executionPath), { recursive: true });
|
|
35
|
+
const guard = tryAcquireLock(join(execLocksDir(paths.executionPath), `${preview.record.run_id}.sequence.lock`), { actor: "job-sequence" });
|
|
36
|
+
if (!guard)
|
|
37
|
+
throw new Error(`Job sequence already running: ${preview.record.run_id}`);
|
|
38
|
+
const frozenOpts = { ...opts, scheduledAt: preview.record.scheduled_at };
|
|
39
|
+
const waitSeconds = isJobCommandTask(preview.record.task)
|
|
40
|
+
? (preview.record.task.lock_wait_seconds ?? 3600)
|
|
41
|
+
: 3600;
|
|
42
|
+
try {
|
|
43
|
+
if (preview.duplicateComplete) {
|
|
44
|
+
await runJobMode(frozenOpts, resolver);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await withProjectExecRunLock({
|
|
49
|
+
...frozenOpts,
|
|
50
|
+
ifBusy: "wait",
|
|
51
|
+
lockWaitMs: waitSeconds * 1000,
|
|
52
|
+
}, "run", () => runJobMode(frozenOpts, resolver));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (!(error instanceof ExecRunLockTimeoutError))
|
|
56
|
+
throw error;
|
|
57
|
+
await runJobMode({
|
|
58
|
+
...frozenOpts,
|
|
59
|
+
sequenceDeferredReason: `project lock wait timed out after ${waitSeconds} seconds`,
|
|
60
|
+
}, resolver);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
releaseLock(guard);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { load } from "../../shared/yaml.js";
|
|
4
|
+
import { executeJobCommand, jobCommandText, recordJobSteps, } from "../../job/job.js";
|
|
5
|
+
import { recordCommandEvidence } from "../evidence.js";
|
|
6
|
+
function completionState(task, cwd) {
|
|
7
|
+
if (!task.completion)
|
|
8
|
+
return { status: "succeeded", reason: "command exited 0" };
|
|
9
|
+
const rule = task.completion;
|
|
10
|
+
const path = resolve(cwd, rule.path);
|
|
11
|
+
const rel = relative(cwd, path);
|
|
12
|
+
if (isAbsolute(rule.path) || rel === ".." || rel.startsWith(`..${sep}`))
|
|
13
|
+
return { status: "failed", reason: "completion.path must stay inside the repository" };
|
|
14
|
+
try {
|
|
15
|
+
const text = readFileSync(path, "utf8");
|
|
16
|
+
const frontmatter = text.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
|
|
17
|
+
const document = path.endsWith(".json") ? JSON.parse(text) : load(frontmatter ?? text);
|
|
18
|
+
let value = document;
|
|
19
|
+
for (const field of rule.field.split(".")) {
|
|
20
|
+
value =
|
|
21
|
+
typeof value === "object" && value !== null && Object.hasOwn(value, field)
|
|
22
|
+
? value[field]
|
|
23
|
+
: undefined;
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === "string" && rule.succeeded.includes(value))
|
|
26
|
+
return { status: "succeeded", reason: "exit 0 and completion state accepted" };
|
|
27
|
+
if (typeof value === "string" && rule.deferred?.includes(value))
|
|
28
|
+
return { status: "deferred", reason: "completion state requires a later retry" };
|
|
29
|
+
return { status: "failed", reason: "completion state missing or not accepted" };
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { status: "failed", reason: "completion state file unavailable or invalid" };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Runs frozen commands serially. Logs are evidence only, never a completion protocol. */
|
|
36
|
+
export async function executeJobSequence(params) {
|
|
37
|
+
const { task, runId, runPath, cwd, executionPath, deferredReason } = params;
|
|
38
|
+
const startedAt = new Date().toISOString();
|
|
39
|
+
const steps = (task.steps ?? []).map(({ id }) => ({
|
|
40
|
+
id,
|
|
41
|
+
status: "deferred",
|
|
42
|
+
reason: deferredReason ?? "preceding step has not completed",
|
|
43
|
+
}));
|
|
44
|
+
recordJobSteps(runPath, steps);
|
|
45
|
+
if (!deferredReason) {
|
|
46
|
+
for (const [index, step] of (task.steps ?? []).entries()) {
|
|
47
|
+
steps[index] = { id: step.id, status: "running", started_at: new Date().toISOString() };
|
|
48
|
+
recordJobSteps(runPath, steps);
|
|
49
|
+
let outcome;
|
|
50
|
+
try {
|
|
51
|
+
outcome = await executeJobCommand(step.command, cwd, step.timeout_seconds === undefined ? {} : { timeoutMs: step.timeout_seconds * 1000 });
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
steps[index] = {
|
|
55
|
+
...steps[index],
|
|
56
|
+
status: "failed",
|
|
57
|
+
completed_at: new Date().toISOString(),
|
|
58
|
+
reason: "command execution threw",
|
|
59
|
+
};
|
|
60
|
+
recordJobSteps(runPath, steps);
|
|
61
|
+
if (step.on_failure !== "continue")
|
|
62
|
+
break;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const verdict = outcome.timedOut
|
|
66
|
+
? {
|
|
67
|
+
status: "deferred",
|
|
68
|
+
reason: `command exceeded ${step.timeout_seconds} seconds`,
|
|
69
|
+
}
|
|
70
|
+
: outcome.error
|
|
71
|
+
? { status: "failed", reason: "command could not be executed" }
|
|
72
|
+
: outcome.exitCode === 75
|
|
73
|
+
? {
|
|
74
|
+
status: "deferred",
|
|
75
|
+
reason: "command exited 75 (temporary unavailability)",
|
|
76
|
+
}
|
|
77
|
+
: outcome.exitCode !== 0
|
|
78
|
+
? {
|
|
79
|
+
status: "failed",
|
|
80
|
+
reason: `command exited ${outcome.exitCode ?? "by signal"}`,
|
|
81
|
+
}
|
|
82
|
+
: completionState(step, cwd);
|
|
83
|
+
steps[index] = {
|
|
84
|
+
id: step.id,
|
|
85
|
+
...verdict,
|
|
86
|
+
started_at: outcome.startedAt,
|
|
87
|
+
completed_at: outcome.completedAt,
|
|
88
|
+
exit_code: outcome.exitCode,
|
|
89
|
+
};
|
|
90
|
+
recordJobSteps(runPath, steps);
|
|
91
|
+
const evidence = recordCommandEvidence({
|
|
92
|
+
repoRoot: cwd,
|
|
93
|
+
worktreePath: cwd,
|
|
94
|
+
executionPath,
|
|
95
|
+
taskId: runId,
|
|
96
|
+
runId: `${runId}-attempt-${params.attempt}-step-${step.id}`,
|
|
97
|
+
actor: "specdojo-runner",
|
|
98
|
+
command: step.command,
|
|
99
|
+
shell: process.platform === "win32" ? process.env.ComSpec || "cmd.exe" : "/bin/sh -eu",
|
|
100
|
+
startedAt: outcome.startedAt,
|
|
101
|
+
completedAt: outcome.completedAt,
|
|
102
|
+
exitCode: outcome.exitCode,
|
|
103
|
+
stdout: outcome.stdout,
|
|
104
|
+
stderr: outcome.stderr,
|
|
105
|
+
stdoutTruncated: outcome.stdoutTruncated,
|
|
106
|
+
stderrTruncated: outcome.stderrTruncated,
|
|
107
|
+
...(outcome.error ? { error: outcome.error } : {}),
|
|
108
|
+
});
|
|
109
|
+
steps[index] = {
|
|
110
|
+
id: step.id,
|
|
111
|
+
...verdict,
|
|
112
|
+
started_at: outcome.startedAt,
|
|
113
|
+
completed_at: outcome.completedAt,
|
|
114
|
+
exit_code: outcome.exitCode,
|
|
115
|
+
evidence_ref: relative(cwd, evidence.evidencePath).split(sep).join("/"),
|
|
116
|
+
};
|
|
117
|
+
recordJobSteps(runPath, steps);
|
|
118
|
+
if (verdict.status !== "succeeded" && step.on_failure !== "continue")
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const failed = steps.some((step) => step.status === "failed");
|
|
123
|
+
const deferred = steps.some((step) => step.status === "deferred");
|
|
124
|
+
return {
|
|
125
|
+
command: jobCommandText(task),
|
|
126
|
+
startedAt,
|
|
127
|
+
completedAt: new Date().toISOString(),
|
|
128
|
+
exitCode: failed ? 1 : deferred ? 75 : 0,
|
|
129
|
+
stdout: JSON.stringify({ steps }),
|
|
130
|
+
stderr: "",
|
|
131
|
+
stdoutTruncated: false,
|
|
132
|
+
stderrTruncated: false,
|
|
133
|
+
...(failed || deferred
|
|
134
|
+
? { reason: deferredReason ?? "sequence contains failed or deferred steps" }
|
|
135
|
+
: {}),
|
|
136
|
+
};
|
|
137
|
+
}
|