specdojo 0.2.1 → 0.3.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 +165 -0
- package/CHANGELOG.md +298 -0
- package/README.md +92 -42
- package/dist/agent-response.js +20 -0
- package/dist/agent.js +4 -4
- package/dist/build-command.js +28 -8
- package/dist/catalog-build-references.js +144 -0
- package/dist/catalog-build-render.js +144 -0
- package/dist/catalog-build.js +13 -290
- package/dist/catalog-generate.js +6 -9
- package/dist/catalog-plan-generate.js +2 -2
- package/dist/catalog-plan.js +6 -6
- package/dist/catalog-scaffold.js +4 -4
- package/dist/catalog.js +2 -2
- package/dist/dashboard-exec-records.js +105 -0
- package/dist/dashboard-routines.js +255 -0
- package/dist/dashboard-shared.js +14 -0
- package/dist/dashboard-timeline.js +175 -0
- package/dist/dashboard.js +31 -444
- package/dist/deliverable-trash.js +3 -3
- package/dist/devcontainer-command.js +43 -0
- package/dist/devcontainer-scaffold.js +165 -0
- package/dist/doc-index.js +3 -3
- package/dist/exec-agent-config.js +107 -9
- package/dist/exec-agent-git-state.js +18 -0
- package/dist/exec-agent-protected-config.js +46 -8
- package/dist/exec-commands.js +557 -0
- package/dist/exec-core.js +457 -0
- package/dist/exec-evidence.js +254 -11
- package/dist/exec-handoff.js +336 -0
- package/dist/exec-parent-validation.js +317 -43
- package/dist/exec-pipeline-state.js +74 -9
- package/dist/exec-plans-core.js +693 -0
- package/dist/exec-plans-generation.js +206 -0
- package/dist/exec-plans-storage.js +131 -0
- package/dist/exec-plans.js +3 -1016
- package/dist/exec-protection-handoff.js +43 -2
- package/dist/exec-provider-scaffold.js +247 -15
- package/dist/exec-register-resume.js +65 -19
- package/dist/exec-register.js +9 -3
- package/dist/exec-repo-integration-git.js +23 -0
- package/dist/exec-repo-integration-sync.js +264 -0
- package/dist/exec-repo-integration.js +534 -0
- package/dist/exec-repo-trace.js +182 -0
- package/dist/exec-reporter-output.js +206 -0
- package/dist/exec-reporter.js +525 -248
- package/dist/exec-results.js +103 -71
- package/dist/exec-run-agent-pipeline.js +256 -0
- package/dist/exec-run-agent.js +531 -0
- package/dist/exec-run-in-place.js +541 -0
- package/dist/exec-run-job.js +717 -0
- package/dist/exec-run-lifecycle-commands.js +522 -0
- package/dist/exec-run-lock.js +110 -107
- package/dist/exec-run-mode-shared.js +140 -0
- package/dist/exec-run-register-command.js +244 -0
- package/dist/exec-run-register-core.js +386 -0
- package/dist/exec-run-register-mode.js +206 -0
- package/dist/exec-run-register-resume.js +393 -0
- package/dist/exec-run-register-state.js +322 -0
- package/dist/exec-run-register-worktree.js +509 -0
- package/dist/exec-run-schedule-mode.js +294 -0
- package/dist/exec-run-schedule-prepare.js +353 -0
- package/dist/exec-run-schedule-task.js +572 -0
- package/dist/exec-run-shared.js +399 -0
- package/dist/exec-run.js +11 -4953
- package/dist/exec-shared.js +9 -2
- package/dist/exec-slot-lock.js +242 -0
- package/dist/exec-task-repos.js +415 -0
- package/dist/exec-trial-commands.js +558 -0
- package/dist/exec-trial-core.js +371 -0
- package/dist/exec-trial.js +2 -895
- package/dist/exec-worktree-command.js +87 -43
- package/dist/exec-worktree-ops-commit.js +707 -0
- package/dist/exec-worktree-ops-lifecycle.js +292 -0
- package/dist/exec-worktree-ops-merge.js +303 -0
- package/dist/exec-worktree-ops.js +3 -847
- package/dist/exec-worktree.js +146 -31
- package/dist/exec.js +2 -999
- package/dist/frontmatter-namespace.js +2 -2
- package/dist/grade-apply.js +734 -0
- package/dist/grade-command-apply.js +250 -0
- package/dist/grade-command-inspect.js +138 -0
- package/dist/grade-command-plan.js +101 -0
- package/dist/grade-command-shared.js +68 -0
- package/dist/grade-core.js +307 -0
- package/dist/grade-markdown.js +274 -0
- package/dist/grade-pipeline-state.js +184 -0
- package/dist/grade-plan.js +507 -0
- package/dist/grade-result.js +133 -5
- package/dist/grade-target-discovery.js +265 -0
- package/dist/grade-targets.js +432 -0
- package/dist/grade.js +14 -2451
- package/dist/init-command.js +443 -0
- package/dist/job-definition.js +670 -0
- package/dist/job.js +64 -578
- package/dist/kata-command.js +2 -2
- package/dist/orchestrator.js +213 -0
- package/dist/register-command-types.js +1 -0
- package/dist/register-core.js +363 -0
- package/dist/register-create-commands.js +245 -0
- package/dist/register-event-merge.js +169 -0
- package/dist/register-events.js +4 -4
- package/dist/register-item.js +13 -7
- package/dist/register-maintenance-commands.js +187 -0
- package/dist/register-migration.js +268 -0
- package/dist/register-renumber.js +314 -0
- package/dist/register-transition-commands.js +248 -0
- package/dist/register-update.js +230 -0
- package/dist/register-views.js +256 -0
- package/dist/register.js +175 -1975
- package/dist/review-grade.js +252 -0
- package/dist/review-plan.js +114 -4
- package/dist/review-types.js +40 -1
- package/dist/routine-definition.js +401 -0
- package/dist/routine.js +73 -402
- package/dist/schedule-approach.js +2 -2
- package/dist/schedule-build.js +2 -2
- package/dist/schedule-strategy-generate-document.js +273 -0
- package/dist/schedule-strategy-generate-scope.js +199 -0
- package/dist/schedule-strategy-generate.js +9 -473
- package/dist/schedule.js +19 -6
- package/dist/specdojo-config.js +465 -20
- package/dist/specdojo-gitignore.js +135 -0
- package/dist/specdojo.js +6 -0
- package/dist/viewpoint-document-kinds-check.js +128 -0
- package/dist/yaml-pages.js +4 -4
- package/dist/yaml.js +28 -0
- package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
- package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
- package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
- package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
- package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
- package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
- package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
- package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
- package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
- package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
- package/docs/ja/specdojo/guides/exec-config-guide.md +93 -49
- package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
- package/docs/ja/specdojo/guides/kata-guide.md +4 -4
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +45 -22
- package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
- package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
- package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
- package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
- package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
- package/docs/ja/specdojo/guides/review-guide.md +195 -158
- package/docs/ja/specdojo/guides/routine-operation-guide.md +75 -10
- package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
- package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
- package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
- package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
- package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
- package/docs/ja/specdojo/guides/waza-guide.md +15 -2
- package/docs/ja/specdojo/index.md +2 -2
- package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
- package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
- package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
- package/docs/ja/specdojo/references/command-reference.md +335 -92
- package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
- package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
- package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
- package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
- package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
- package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
- package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
- package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
- package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
- package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
- package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
- package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
- package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
- package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
- package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
- package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
- package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
- package/docs/ja/specdojo/samples/bps-sample.md +74 -21
- package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
- package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
- package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
- package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
- package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
- package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
- package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
- package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
- package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
- package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
- package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
- package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
- package/docs/ja/specdojo/templates/bps-template.md +91 -0
- package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
- package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
- package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
- package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
- package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
- package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
- package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
- package/package.json +17 -12
- package/templates/antigravity/README.md +29 -4
- package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
- package/templates/antigravity/exec-defaults-snippet.yaml +10 -7
- package/templates/antigravity/orchestrator.md +18 -7
- package/templates/antigravity/settings.global.json +55 -0
- package/templates/claude/agents/claude-executor.md +14 -0
- package/templates/claude/agents/claude-reporter.md +16 -0
- package/templates/claude/agents/specdojo-orchestrator.md +18 -7
- package/templates/claude/settings.edit.json +27 -1
- package/templates/codex/README.md +5 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
- package/templates/codex/orchestrator.md +18 -7
- package/templates/copilot/README.md +7 -5
- package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
- package/templates/devcontainer/devcontainer.json +27 -0
- package/templates/devcontainer/emacs/init.el +88 -0
- package/templates/devcontainer/post-create.sh +62 -0
- package/templates/init-agent-members.yaml +200 -0
- package/templates/init-exec-defaults.yaml +74 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
- package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
- package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { resolveMemberCommand, } from "./exec-agent-config.js";
|
|
4
|
+
import { buildInPlaceStem } from "./exec-plans.js";
|
|
5
|
+
import { generateRegisterPlan, normalizePjrId, requireRunnableRegisterItem, resolveRegisterRunTarget, sanitizeRegisterConclusion, selectRegisterCommitPaths, selectRegisterRunArtifactResidue, ticketPathFromItem, } from "./exec-register.js";
|
|
6
|
+
import { registerEventFilePath } from "./register-events.js";
|
|
7
|
+
import { displayIdFromTicketFilename } from "./register-item.js";
|
|
8
|
+
import { isResultUnfilled, readResultFrontmatterSnapshot, scaffoldResult, updateResultStatus, } from "./exec-results.js";
|
|
9
|
+
import { gitOutput, gitResult } from "./exec-worktree.js";
|
|
10
|
+
import { stabilizeCommitTargets, stageCommitTargets, unstageCommitTargets, worktreeStatusPaths, } from "./exec-worktree-ops.js";
|
|
11
|
+
import { resolveAgentOverride, selectCandidates, } from "./exec-run-shared.js";
|
|
12
|
+
import { expandPromptRefs } from "./exec-run-agent.js";
|
|
13
|
+
import { runAgentPipeline } from "./exec-run-agent-pipeline.js";
|
|
14
|
+
import { spawnAgentInPlace } from "./exec-run-in-place.js";
|
|
15
|
+
import { commitSubject, repoRelativePath, spawnSelf } from "./exec-run-mode-shared.js";
|
|
16
|
+
// --register の単一 agent 実行(--by 指定時)の agent を解決する。owner(Role code)や
|
|
17
|
+
// role からの自動選択は行わない(PJR-ADZ6)。agent は全員 stage_role を持つ pipeline
|
|
18
|
+
// メンバーであり、owner・role から選ぶと pipeline 用でない agent(翻訳専用など)や
|
|
19
|
+
// result を書かない executor が単独で選ばれてしまうため。--by が無い場合の agent は
|
|
20
|
+
// resolveRegisterPipelineCommand が stage_role から選ぶ。
|
|
21
|
+
export function resolveRegisterCommand(item, roster, opts, execDefaults = {}) {
|
|
22
|
+
const by = opts.by?.trim();
|
|
23
|
+
if (!by) {
|
|
24
|
+
throw new Error(`No agent specified for register item ${item.id} (owner: ${item.owner || "-"}). ` +
|
|
25
|
+
"Specify --by <nickname>, or --executor-by <nickname> --reporter-by <nickname>.");
|
|
26
|
+
}
|
|
27
|
+
const member = roster?.members.find((m) => m.nickname === by && m.type === "agent");
|
|
28
|
+
const command = member ? resolveMemberCommand(execDefaults, member) : undefined;
|
|
29
|
+
if (!command)
|
|
30
|
+
throw new Error(`Agent command not found for actor: ${by}`);
|
|
31
|
+
return { command, actor: by };
|
|
32
|
+
}
|
|
33
|
+
// --register を executor/reporter パイプラインで実行するかを判定する。--executor-by /
|
|
34
|
+
// --reporter-by の指定があれば pipeline、どちらも無く --by も無い場合も stage_role からの
|
|
35
|
+
// 自動選択で pipeline にする。--by だけを指定した場合に限り、従来の単一 agent 実行
|
|
36
|
+
// (resolveRegisterCommand)を使う。両者は互いに排他である。
|
|
37
|
+
export function isRegisterPipelineRequested(opts) {
|
|
38
|
+
if (opts.executorBy || opts.reporterBy)
|
|
39
|
+
return true;
|
|
40
|
+
return !opts.by?.trim();
|
|
41
|
+
}
|
|
42
|
+
// `--executor-by` keeps its original single-nickname form and additionally accepts a complete
|
|
43
|
+
// PJR-ID-to-nickname map. Requiring complete coverage makes an omitted item an input error instead
|
|
44
|
+
// of silently falling back to a different executor, while rejecting extra IDs catches typos and
|
|
45
|
+
// stale invocations before any register transition or worktree setup occurs.
|
|
46
|
+
export function parseRegisterExecutorSelection(raw, selectedIds) {
|
|
47
|
+
if (raw === undefined)
|
|
48
|
+
return { kind: "none" };
|
|
49
|
+
const value = raw.trim();
|
|
50
|
+
if (!value)
|
|
51
|
+
throw new Error("--executor-by must not be empty.");
|
|
52
|
+
if (!value.includes("="))
|
|
53
|
+
return { kind: "shared", executor: value };
|
|
54
|
+
const executors = new Map();
|
|
55
|
+
for (const entry of value.split(",")) {
|
|
56
|
+
const parts = entry.split("=");
|
|
57
|
+
if (parts.length !== 2) {
|
|
58
|
+
throw new Error(`Invalid --executor-by item assignment: ${entry}. Use PJR-ID=nickname separated by commas.`);
|
|
59
|
+
}
|
|
60
|
+
const id = normalizePjrId(parts[0]);
|
|
61
|
+
const executor = parts[1].trim();
|
|
62
|
+
if (!executor) {
|
|
63
|
+
throw new Error(`Invalid --executor-by item assignment for ${id}: nickname is empty.`);
|
|
64
|
+
}
|
|
65
|
+
if (executors.has(id)) {
|
|
66
|
+
throw new Error(`Duplicate --executor-by item assignment: ${id}.`);
|
|
67
|
+
}
|
|
68
|
+
executors.set(id, executor);
|
|
69
|
+
}
|
|
70
|
+
const selected = new Set(selectedIds);
|
|
71
|
+
const outsideTarget = [...executors.keys()].filter((id) => !selected.has(id));
|
|
72
|
+
if (outsideTarget.length > 0) {
|
|
73
|
+
throw new Error(`--executor-by item assignments include IDs outside the register execution target: ${outsideTarget.join(", ")}.`);
|
|
74
|
+
}
|
|
75
|
+
const missing = selectedIds.filter((id) => !executors.has(id));
|
|
76
|
+
if (missing.length > 0) {
|
|
77
|
+
throw new Error(`--executor-by item assignments must cover every selected register item; missing: ${missing.join(", ")}.`);
|
|
78
|
+
}
|
|
79
|
+
return { kind: "per-item", executors };
|
|
80
|
+
}
|
|
81
|
+
export function selectedRegisterExecutor(selection, itemId) {
|
|
82
|
+
if (selection.kind === "none")
|
|
83
|
+
return undefined;
|
|
84
|
+
return selection.kind === "shared" ? selection.executor : selection.executors.get(itemId);
|
|
85
|
+
}
|
|
86
|
+
// --register 向けの executor/reporter 解決。Schedule タスクの agent_pipeline と異なり、
|
|
87
|
+
// register 項目には per-item のパイプライン宣言が無いため、owner/role からの自動選択は行わない。
|
|
88
|
+
// --executor-by / --reporter-by は両方そろえて明示する。どちらも無い場合は stage_role:
|
|
89
|
+
// executor(mode: edit)と stage_role: reporter の agent から priority 順に自動選択する。
|
|
90
|
+
// stage_role を持たない agent(翻訳専用など)は候補に入らない(PJR-ADZ6)。
|
|
91
|
+
export function resolveRegisterPipelineCommand(roster, opts, execDefaults = {}) {
|
|
92
|
+
if (!opts.executorBy && !opts.reporterBy) {
|
|
93
|
+
return autoSelectRegisterPipelineAgents(roster, execDefaults);
|
|
94
|
+
}
|
|
95
|
+
if (!opts.executorBy || !opts.reporterBy) {
|
|
96
|
+
throw new Error("--register pipeline execution requires both --executor-by and --reporter-by.");
|
|
97
|
+
}
|
|
98
|
+
const executorResolution = resolveAgentOverride("edit", opts.executorBy, {}, roster, execDefaults, "executor");
|
|
99
|
+
if (executorResolution.kind === "error") {
|
|
100
|
+
throw new Error(executorResolution.message.replace(/^--by/, "--executor-by"));
|
|
101
|
+
}
|
|
102
|
+
if (executorResolution.kind !== "command") {
|
|
103
|
+
throw new Error(`--executor-by agent not found in agent-members.yaml: ${opts.executorBy}`);
|
|
104
|
+
}
|
|
105
|
+
const reporterResolution = resolveAgentOverride("edit", opts.reporterBy, {}, roster, execDefaults, "reporter");
|
|
106
|
+
if (reporterResolution.kind === "error") {
|
|
107
|
+
throw new Error(reporterResolution.message.replace(/^--by/, "--reporter-by"));
|
|
108
|
+
}
|
|
109
|
+
if (reporterResolution.kind !== "command") {
|
|
110
|
+
throw new Error(`--reporter-by agent not found in agent-members.yaml: ${opts.reporterBy}`);
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
executor: {
|
|
114
|
+
command: executorResolution.command,
|
|
115
|
+
actor: executorResolution.actor ?? opts.executorBy,
|
|
116
|
+
provider: executorResolution.provider,
|
|
117
|
+
},
|
|
118
|
+
reporterCandidates: [
|
|
119
|
+
{
|
|
120
|
+
command: reporterResolution.command,
|
|
121
|
+
actor: reporterResolution.actor ?? opts.reporterBy,
|
|
122
|
+
provider: reporterResolution.provider,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// --executor-by / --reporter-by も --by も無い --register 実行の agent を stage_role から選ぶ。
|
|
128
|
+
// executor は mode: edit の executor(mode 未指定を含む)、reporter は mode を問わない
|
|
129
|
+
// reporter を priority 順に候補とする。stage_role を持たない agent は selectCandidates の
|
|
130
|
+
// 段指定によって除外される。どちらかの段に候補が無い場合は明示指定を求めるエラーにする。
|
|
131
|
+
export function autoSelectRegisterPipelineAgents(roster, execDefaults) {
|
|
132
|
+
const toCandidates = (members) => members.flatMap((member) => {
|
|
133
|
+
const command = resolveMemberCommand(execDefaults, member);
|
|
134
|
+
return command ? [{ command, actor: member.nickname, provider: member.provider }] : [];
|
|
135
|
+
});
|
|
136
|
+
const executor = toCandidates(selectCandidates({ capabilities: [], stage_role: "executor" }, roster, "edit", undefined, execDefaults))[0];
|
|
137
|
+
const reporterCandidates = toCandidates(selectCandidates({ capabilities: [], stage_role: "reporter" }, roster, undefined, undefined, execDefaults));
|
|
138
|
+
if (!executor || reporterCandidates.length === 0) {
|
|
139
|
+
const missing = [
|
|
140
|
+
...(executor ? [] : ["stage_role: executor (mode: edit)"]),
|
|
141
|
+
...(reporterCandidates.length > 0 ? [] : ["stage_role: reporter"]),
|
|
142
|
+
];
|
|
143
|
+
throw new Error(`No agent found for --register pipeline stage (${missing.join(", ")}). ` +
|
|
144
|
+
"Specify --executor-by <nickname> --reporter-by <nickname>, or --by <nickname>.");
|
|
145
|
+
}
|
|
146
|
+
return { executor, reporterCandidates };
|
|
147
|
+
}
|
|
148
|
+
// register の状態遷移を CLI 経由で実行する。register 側のガード(終端状態の拒否)と
|
|
149
|
+
// 派生ビュー再生成を一元的に通すため、直接ファイルを書き換えず自プロセスを spawn する。
|
|
150
|
+
export function spawnRegisterTransition(projectId, args, cwd) {
|
|
151
|
+
const fullArgs = ["register", ...args];
|
|
152
|
+
if (projectId)
|
|
153
|
+
fullArgs.push("--project", projectId);
|
|
154
|
+
return spawnSelf(fullArgs, cwd);
|
|
155
|
+
}
|
|
156
|
+
// 成功したIDの実行によって生じた変更だけを1コミットにまとめる。開始前スナップショット
|
|
157
|
+
// (preexisting)に無いパスと runnerManaged を対象にし、利用者の既存変更は除外する。
|
|
158
|
+
// commit 後は hook が変更した対象を amend し、対象差分が消えるまで収束を検証する。
|
|
159
|
+
export function commitRegisterItemChanges(repoRoot, item, preexisting, runnerManaged = []) {
|
|
160
|
+
const remainingPaths = () => selectRegisterCommitPaths(preexisting, worktreeStatusPaths(repoRoot), runnerManaged);
|
|
161
|
+
const paths = remainingPaths();
|
|
162
|
+
if (paths.length === 0)
|
|
163
|
+
return { committed: false };
|
|
164
|
+
try {
|
|
165
|
+
stageCommitTargets(repoRoot, paths);
|
|
166
|
+
const staged = gitResult(repoRoot, ["diff", "--cached", "--quiet", "--", ...paths]);
|
|
167
|
+
if (staged.status === 0)
|
|
168
|
+
return { committed: false };
|
|
169
|
+
if (staged.status !== 1)
|
|
170
|
+
throw new Error("Failed to inspect staged register changes.");
|
|
171
|
+
const subject = commitSubject(`exec(register ${item.id}): `, item.title);
|
|
172
|
+
gitOutput(repoRoot, ["commit", "-m", subject, "--", ...paths]);
|
|
173
|
+
stabilizeCommitTargets(repoRoot, remainingPaths);
|
|
174
|
+
const sha = gitOutput(repoRoot, ["rev-parse", "--short", "HEAD"]).trim();
|
|
175
|
+
return { committed: true, sha };
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
unstageCommitTargets(repoRoot, [...paths, ...remainingPaths()]);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export function registerEventPathForTicket(registerPaths, ticketPath) {
|
|
183
|
+
if (!ticketPath)
|
|
184
|
+
return undefined;
|
|
185
|
+
const displayId = displayIdFromTicketFilename(basename(ticketPath));
|
|
186
|
+
return displayId
|
|
187
|
+
? registerEventFilePath(registerPaths.projectRegisterPath, displayId)
|
|
188
|
+
: undefined;
|
|
189
|
+
}
|
|
190
|
+
export function registerRunnerManagedPaths(repoRoot, registerPaths, planPath, resultPath, currentPaths, ticketPath, additionalManagedPaths = []) {
|
|
191
|
+
// 状態遷移の書き込み先は個票(正本)。pjr-index と派生ビューは生成物として同時に更新される。
|
|
192
|
+
// 移行完了後の pjr-index.md は非追跡の生成物になり存在しないため、存在する場合のみ対象に含める
|
|
193
|
+
// (存在しないパスを git add すると pathspec エラーになる)。
|
|
194
|
+
const managed = [planPath, resultPath, ...additionalManagedPaths];
|
|
195
|
+
if (existsSync(registerPaths.pjrIndexPath))
|
|
196
|
+
managed.push(registerPaths.pjrIndexPath);
|
|
197
|
+
if (ticketPath)
|
|
198
|
+
managed.push(ticketPath);
|
|
199
|
+
const eventPath = registerEventPathForTicket(registerPaths, ticketPath);
|
|
200
|
+
if (eventPath)
|
|
201
|
+
managed.push(eventPath);
|
|
202
|
+
const exact = new Set(managed.map((path) => repoRelativePath(repoRoot, path)));
|
|
203
|
+
const prefixes = [registerPaths.generatedPath, registerPaths.controlsGeneratedPath].map((path) => `${repoRelativePath(repoRoot, path)}/`);
|
|
204
|
+
for (const path of currentPaths) {
|
|
205
|
+
const normalized = path.replaceAll("\\", "/");
|
|
206
|
+
if (prefixes.some((prefix) => normalized.startsWith(prefix)))
|
|
207
|
+
exact.add(path);
|
|
208
|
+
}
|
|
209
|
+
return [...exact];
|
|
210
|
+
}
|
|
211
|
+
export function registerReporterManagedPaths(registerPaths) {
|
|
212
|
+
return [
|
|
213
|
+
registerPaths.projectRegisterPath,
|
|
214
|
+
registerPaths.generatedPath,
|
|
215
|
+
registerPaths.controlsGeneratedPath,
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
// register 項目1件の in-place 実行。plan 生成 → `register start` → agent 実行 → 成否を
|
|
219
|
+
// register の状態遷移(成功: review / 失敗: waiting)と result に反映し、成功かつ
|
|
220
|
+
// registerCommit 有効なら当該IDの変更だけを commit する。ID別の結果を要約で返す。
|
|
221
|
+
// schedule のタスクではないため exec の claim/complete イベントは記録しない。
|
|
222
|
+
export async function runSingleRegisterItem(context, opts, pjrId) {
|
|
223
|
+
const { projectId, schedulePath, executionPath, repoRoot } = context;
|
|
224
|
+
const { registerPaths, item } = resolveRegisterRunTarget(projectId, pjrId);
|
|
225
|
+
// 状態遷移の書き込み先(登録項目の正本)。commit 対象に必ず含める。
|
|
226
|
+
const ticketPath = ticketPathFromItem(item, registerPaths.projectRegisterPath);
|
|
227
|
+
requireRunnableRegisterItem(item);
|
|
228
|
+
const pipelineMode = isRegisterPipelineRequested(opts);
|
|
229
|
+
const pipelineAgents = pipelineMode
|
|
230
|
+
? resolveRegisterPipelineCommand(context.roster, opts, context.execDefaults)
|
|
231
|
+
: undefined;
|
|
232
|
+
// agent(result frontmatter へ記録する actor)は executor 側にする。Schedule の
|
|
233
|
+
// agent_pipeline(scaffoldResult 呼び出し時に executor の actor を渡す)と揃える。
|
|
234
|
+
const { command, actor } = pipelineAgents
|
|
235
|
+
? { command: pipelineAgents.executor.command, actor: pipelineAgents.executor.actor }
|
|
236
|
+
: resolveRegisterCommand(item, context.roster, opts, context.execDefaults);
|
|
237
|
+
const stem = buildInPlaceStem(pjrId.toLowerCase());
|
|
238
|
+
// ID単位 commit のため、この項目が変更を生じる前の作業ツリー状態を記録する。
|
|
239
|
+
const preexisting = context.registerCommit ? worktreeStatusPaths(repoRoot) : [];
|
|
240
|
+
const residue = context.registerCommit ? selectRegisterRunArtifactResidue(preexisting) : [];
|
|
241
|
+
if (residue.length > 0) {
|
|
242
|
+
process.stderr.write(`Warning: pre-existing uncommitted register plan/result files detected before ${item.id}; ` +
|
|
243
|
+
`left out of this item's commit:\n${residue.map((path) => ` ${path}`).join("\n")}\n`);
|
|
244
|
+
}
|
|
245
|
+
const { planPath } = await generateRegisterPlan({
|
|
246
|
+
executionPath,
|
|
247
|
+
projectId,
|
|
248
|
+
registerPaths,
|
|
249
|
+
item,
|
|
250
|
+
stem,
|
|
251
|
+
});
|
|
252
|
+
const prompt = expandPromptRefs(readFileSync(planPath, "utf8"));
|
|
253
|
+
const { resultPath, supersededPaths } = await scaffoldResult({
|
|
254
|
+
executionPath,
|
|
255
|
+
taskId: item.id,
|
|
256
|
+
mode: "edit",
|
|
257
|
+
projectId,
|
|
258
|
+
origin: "register",
|
|
259
|
+
planRef: `exec/plans/${stem}-plan.md`,
|
|
260
|
+
agent: actor,
|
|
261
|
+
startedAt: new Date().toISOString(),
|
|
262
|
+
stem,
|
|
263
|
+
...(item.targets && item.targets.length > 0 ? { targets: item.targets } : {}),
|
|
264
|
+
});
|
|
265
|
+
const resultScaffold = readResultFrontmatterSnapshot(resultPath);
|
|
266
|
+
process.stdout.write(`Register item: ${item.id} — ${item.title} [${item.type}]\n`);
|
|
267
|
+
process.stdout.write(` Agent: ${actor}${pipelineAgents ? " (executor)" : ""}\n`);
|
|
268
|
+
if (pipelineAgents) {
|
|
269
|
+
process.stdout.write(` Agent: ${pipelineAgents.reporterCandidates[0]?.actor} (reporter)\n`);
|
|
270
|
+
}
|
|
271
|
+
if (!spawnRegisterTransition(projectId, ["start", "--id", item.id, "--by", actor])) {
|
|
272
|
+
throw new Error(`register start failed: ${item.id}`);
|
|
273
|
+
}
|
|
274
|
+
let exitCode;
|
|
275
|
+
let pipelineBlockReason;
|
|
276
|
+
if (pipelineAgents) {
|
|
277
|
+
process.stdout.write(`Running ${item.id} in place (executor/reporter pipeline)\n`);
|
|
278
|
+
const pipelineOutcome = await runAgentPipeline({
|
|
279
|
+
repoRoot,
|
|
280
|
+
cwd: repoRoot,
|
|
281
|
+
schedulePath,
|
|
282
|
+
executionPath,
|
|
283
|
+
taskId: item.id,
|
|
284
|
+
executor: pipelineAgents.executor,
|
|
285
|
+
reporterCandidates: pipelineAgents.reporterCandidates,
|
|
286
|
+
planPath,
|
|
287
|
+
planPrompt: prompt,
|
|
288
|
+
resultPath,
|
|
289
|
+
registerPaths: registerReporterManagedPaths(registerPaths),
|
|
290
|
+
execDefaults: context.execDefaults,
|
|
291
|
+
providerConcurrencyGate: context.providerConcurrencyGate,
|
|
292
|
+
});
|
|
293
|
+
exitCode = pipelineOutcome.exitCode;
|
|
294
|
+
pipelineBlockReason = pipelineOutcome.blockReason;
|
|
295
|
+
if (pipelineOutcome.exitCode !== 0) {
|
|
296
|
+
process.stdout.write(`run blocked: ${item.id} (${pipelineOutcome.blockReason ?? "pipeline failed"})\n`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
process.stdout.write(`Running ${item.id} in place: ${command}\n`);
|
|
301
|
+
exitCode = await spawnAgentInPlace(command, prompt, repoRoot, schedulePath, executionPath, resultPath);
|
|
302
|
+
}
|
|
303
|
+
// in-place 実行と同じ補助判定: agent が result 必須節を埋めずに終了コード 0 で
|
|
304
|
+
// 終わった場合は block として扱う(runInPlaceMode と同じ理由)。pipeline モードでは
|
|
305
|
+
// reporter が renderReporterResult で本文を埋めるため通常は該当しないが、
|
|
306
|
+
// フォーマット不整合等の防御として同じチェックを維持する。
|
|
307
|
+
let effectiveExit = exitCode;
|
|
308
|
+
let blockReason = pipelineBlockReason;
|
|
309
|
+
if (exitCode === 0 && isResultUnfilled(resultPath, "edit", resultScaffold)) {
|
|
310
|
+
effectiveExit = 1;
|
|
311
|
+
blockReason =
|
|
312
|
+
"agent exited 0 but result is incomplete or its frontmatter differs from the scaffold (treated as blocked)";
|
|
313
|
+
process.stdout.write(`run blocked: ${item.id} (result incomplete or frontmatter changed despite exit 0)\n`);
|
|
314
|
+
}
|
|
315
|
+
await updateResultStatus(resultPath, effectiveExit === 0 ? "complete" : "blocked", new Date().toISOString(), blockReason);
|
|
316
|
+
if (effectiveExit === 0) {
|
|
317
|
+
let transition = "review";
|
|
318
|
+
let reason;
|
|
319
|
+
if (!spawnRegisterTransition(projectId, ["review", "--id", item.id, "--by", actor])) {
|
|
320
|
+
process.stderr.write(`register review transition failed: ${item.id}\n`);
|
|
321
|
+
transition = "none";
|
|
322
|
+
reason = "register review transition failed";
|
|
323
|
+
}
|
|
324
|
+
let commit = context.registerCommit ? "no-changes" : "off";
|
|
325
|
+
if (context.registerCommit) {
|
|
326
|
+
const currentPaths = worktreeStatusPaths(repoRoot);
|
|
327
|
+
const runnerManaged = registerRunnerManagedPaths(repoRoot, registerPaths, planPath, resultPath, currentPaths, ticketPath, supersededPaths);
|
|
328
|
+
try {
|
|
329
|
+
const result = commitRegisterItemChanges(repoRoot, item, preexisting, runnerManaged);
|
|
330
|
+
if (result.committed)
|
|
331
|
+
commit = `committed ${result.sha}`;
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
335
|
+
const commitReason = sanitizeRegisterConclusion(`register commit incomplete: ${detail}`);
|
|
336
|
+
process.stderr.write(`run commit failed: ${item.id}: ${detail}\n`);
|
|
337
|
+
if (spawnRegisterTransition(projectId, [
|
|
338
|
+
"wait",
|
|
339
|
+
"--id",
|
|
340
|
+
item.id,
|
|
341
|
+
"--reason",
|
|
342
|
+
commitReason,
|
|
343
|
+
"--by",
|
|
344
|
+
actor,
|
|
345
|
+
])) {
|
|
346
|
+
transition = "waiting";
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
process.stderr.write(`register wait transition failed: ${item.id}\n`);
|
|
350
|
+
transition = "none";
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
id: item.id,
|
|
354
|
+
title: item.title,
|
|
355
|
+
outcome: "failure",
|
|
356
|
+
transition,
|
|
357
|
+
commit: "incomplete",
|
|
358
|
+
reason: commitReason,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
process.stdout.write(`run done: ${item.id} (status: review — confirm and close with "register close")\n`);
|
|
363
|
+
return { id: item.id, title: item.title, outcome: "success", transition, commit, reason };
|
|
364
|
+
}
|
|
365
|
+
const waitingReason = sanitizeRegisterConclusion(blockReason ?? `agent exited with non-zero code (exit ${exitCode})`);
|
|
366
|
+
if (!spawnRegisterTransition(projectId, [
|
|
367
|
+
"wait",
|
|
368
|
+
"--id",
|
|
369
|
+
item.id,
|
|
370
|
+
"--reason",
|
|
371
|
+
waitingReason,
|
|
372
|
+
"--by",
|
|
373
|
+
actor,
|
|
374
|
+
])) {
|
|
375
|
+
process.stderr.write(`register wait transition failed: ${item.id}\n`);
|
|
376
|
+
}
|
|
377
|
+
process.stdout.write(`run failed: ${item.id} (exit ${effectiveExit}; status: waiting)\n`);
|
|
378
|
+
return {
|
|
379
|
+
id: item.id,
|
|
380
|
+
title: item.title,
|
|
381
|
+
outcome: "failure",
|
|
382
|
+
transition: "waiting",
|
|
383
|
+
commit: context.registerCommit ? "skipped" : "off",
|
|
384
|
+
reason: waitingReason,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { loadExecDefaultsConfig, ProviderConcurrencyGate } from "./exec-agent-config.js";
|
|
3
|
+
import { activateResolvedProjectPaths, resolveProjectPaths } from "./exec-project.js";
|
|
4
|
+
import { qualifyTaskId } from "./exec-shared.js";
|
|
5
|
+
import { specdojoRootDir } from "./specdojo-config.js";
|
|
6
|
+
import { execLifecyclePoolPath, execLocksDir } from "./exec-run-lock.js";
|
|
7
|
+
import { CrossProcessMutex } from "./exec-slot-lock.js";
|
|
8
|
+
import { buildInPlaceStem } from "./exec-plans.js";
|
|
9
|
+
import { formatRegisterRunSummary, parseRegisterIds, parseRegisterSelectionFilter, registerRunExitCode, requireRunnableRegisterItem, resolveRegisterRunTarget, selectRegisterItems, } from "./exec-register.js";
|
|
10
|
+
import { loadRegisterItems, resolveRegisterPaths } from "./register.js";
|
|
11
|
+
import { findExecWorktree, resolveWorktreeBase } from "./exec-worktree.js";
|
|
12
|
+
import { findResumableRegisterRun } from "./exec-register-resume.js";
|
|
13
|
+
import { configuredWorktreeBase, parseParallel, resolveExecDefaultsPath, runCompletionDrivenWorkerPool, } from "./exec-run-shared.js";
|
|
14
|
+
import { loadRosterForExecutionPath } from "./exec-run-agent.js";
|
|
15
|
+
import { resolveRegisterCommand, isRegisterPipelineRequested, parseRegisterExecutorSelection, selectedRegisterExecutor, resolveRegisterPipelineCommand, runSingleRegisterItem, } from "./exec-run-register-core.js";
|
|
16
|
+
import { runSingleRegisterItemWorktree } from "./exec-run-register-worktree.js";
|
|
17
|
+
import { resumeSingleRegisterItemWorktree } from "./exec-run-register-resume.js";
|
|
18
|
+
// register 項目の実行(複数ID)。in-place モードは指定順に1件ずつ直列実行し、各IDが plan/result
|
|
19
|
+
// 生成・start・agent実行・review/waiting 遷移まで完結してから次へ進む。worktree モードは成果物を
|
|
20
|
+
// worktree に隔離し、状態遷移を root で直列化する(--parallel で並列化可能)。失敗時は
|
|
21
|
+
// failureMode(stop: 残りを skip / continue: 継続)に従う。最後にID別の成否・状態遷移・
|
|
22
|
+
// commit結果を一覧表示し、いずれかが failure ならプロセス終了コードへ反映する。
|
|
23
|
+
export async function runRegisterMode(opts) {
|
|
24
|
+
const resolvedPaths = resolveProjectPaths({ project: opts.project });
|
|
25
|
+
activateResolvedProjectPaths(resolvedPaths);
|
|
26
|
+
const { schedulePath, executionPath } = resolvedPaths;
|
|
27
|
+
const repoRoot = specdojoRootDir();
|
|
28
|
+
const projectId = resolvedPaths.projectId ?? opts.project ?? process.env.SPECDOJO_PROJECT ?? "";
|
|
29
|
+
if (!projectId) {
|
|
30
|
+
throw new Error("--register requires a project id. Use --project <id> or set current_project in specdojo.config.json.");
|
|
31
|
+
}
|
|
32
|
+
const selectionFilter = opts.registerFilter
|
|
33
|
+
? parseRegisterSelectionFilter({
|
|
34
|
+
types: opts.registerTypes,
|
|
35
|
+
priorities: opts.registerPriorities,
|
|
36
|
+
statuses: opts.registerStatuses,
|
|
37
|
+
limit: opts.registerLimit,
|
|
38
|
+
})
|
|
39
|
+
: undefined;
|
|
40
|
+
const selectedIds = selectionFilter
|
|
41
|
+
? selectRegisterItems(loadRegisterItems(resolveRegisterPaths({ project: projectId })).map((view) => view.item), selectionFilter).map((item) => item.id)
|
|
42
|
+
: undefined;
|
|
43
|
+
const { ids, duplicates } = selectedIds
|
|
44
|
+
? { ids: selectedIds, duplicates: [] }
|
|
45
|
+
: parseRegisterIds(opts.register);
|
|
46
|
+
const executorSelection = parseRegisterExecutorSelection(opts.executorBy, ids);
|
|
47
|
+
if (ids.length === 0) {
|
|
48
|
+
process.stdout.write("No matching register items.\n");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const hasExecutorSelection = executorSelection.kind !== "none";
|
|
52
|
+
const optsForItem = (pjrId) => ({
|
|
53
|
+
...opts,
|
|
54
|
+
executorBy: selectedRegisterExecutor(executorSelection, pjrId),
|
|
55
|
+
});
|
|
56
|
+
for (const duplicate of duplicates) {
|
|
57
|
+
process.stdout.write(`Skipping duplicate register item id: ${duplicate}\n`);
|
|
58
|
+
}
|
|
59
|
+
const failureMode = opts.onFailure
|
|
60
|
+
? opts.onFailure
|
|
61
|
+
: "stop";
|
|
62
|
+
// --executor-by / --reporter-by は両方揃って初めて pipeline モードになる。片方だけの指定は
|
|
63
|
+
// 曖昧なため、実行前に明示的なエラーで止める(isRegisterPipelineRequested は片方でも true を
|
|
64
|
+
// 返すため、resolveRegisterPipelineCommand 側の対称チェックとは別に、ここで早期に検知する)。
|
|
65
|
+
// 再開は state が示す段だけを実行する。stale executor の再実行では各 agent の明示指定を
|
|
66
|
+
// 個別に許可し、省略時は state に記録された actor を使う。
|
|
67
|
+
if (!opts.resume &&
|
|
68
|
+
((hasExecutorSelection && !opts.reporterBy) || (!hasExecutorSelection && opts.reporterBy))) {
|
|
69
|
+
throw new Error("--register pipeline execution requires both --executor-by and --reporter-by.");
|
|
70
|
+
}
|
|
71
|
+
const roster = loadRosterForExecutionPath(executionPath);
|
|
72
|
+
const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
|
|
73
|
+
const useWorktree = !!opts.worktree;
|
|
74
|
+
const parallel = parseParallel(opts.parallel);
|
|
75
|
+
const worktreeBase = resolveWorktreeBase(repoRoot, opts.worktreeBase, configuredWorktreeBase(schedulePath));
|
|
76
|
+
if (opts.dryRun && opts.resume) {
|
|
77
|
+
process.stdout.write(`[dry-run] resume pipeline for register items: ${ids.join(", ")}\n`);
|
|
78
|
+
for (const pjrId of ids) {
|
|
79
|
+
const { item } = resolveRegisterRunTarget(projectId, pjrId);
|
|
80
|
+
requireRunnableRegisterItem(item);
|
|
81
|
+
const worktree = findExecWorktree(repoRoot, qualifyTaskId(projectId, item.id));
|
|
82
|
+
if (!worktree) {
|
|
83
|
+
process.stdout.write(`[dry-run] ${item.id}: no exec worktree — not resumable\n`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const lookup = findResumableRegisterRun({
|
|
87
|
+
repoRoot,
|
|
88
|
+
worktreePath: worktree.path,
|
|
89
|
+
executionPath,
|
|
90
|
+
taskId: item.id,
|
|
91
|
+
...(opts.resumeFrom === "executor" ? { resumeFrom: "executor" } : {}),
|
|
92
|
+
});
|
|
93
|
+
process.stdout.write(lookup.kind === "resumable"
|
|
94
|
+
? `[dry-run] ${item.id}: resume the ${lookup.target.stage} stage of run ${lookup.target.runId} in ${worktree.path}\n`
|
|
95
|
+
: `[dry-run] ${item.id}: not resumable (${lookup.reason})\n`);
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (opts.dryRun) {
|
|
100
|
+
const modeLabel = useWorktree
|
|
101
|
+
? `worktree${parallel > 1 ? `, parallel: ${parallel}` : ", serial"}`
|
|
102
|
+
: "in-place, serial";
|
|
103
|
+
process.stdout.write(`[dry-run] register items (${modeLabel}): ${ids.join(", ")} [on-failure: ${failureMode}, commit: ${useWorktree ? "always (worktree)" : opts.registerCommit ? "per-id" : "off"}]\n`);
|
|
104
|
+
const pipelineMode = isRegisterPipelineRequested(opts);
|
|
105
|
+
for (const pjrId of ids) {
|
|
106
|
+
const itemOpts = optsForItem(pjrId);
|
|
107
|
+
const { item } = resolveRegisterRunTarget(projectId, pjrId);
|
|
108
|
+
const category = requireRunnableRegisterItem(item);
|
|
109
|
+
const stem = buildInPlaceStem(pjrId.toLowerCase());
|
|
110
|
+
process.stdout.write(`[dry-run] register item: ${item.id} — ${item.title} [${item.type}/${category}]\n`);
|
|
111
|
+
if (pipelineMode) {
|
|
112
|
+
const { executor, reporterCandidates } = resolveRegisterPipelineCommand(roster, itemOpts, execDefaults);
|
|
113
|
+
process.stdout.write(`[dry-run] executor: ${executor.actor}\n`);
|
|
114
|
+
process.stdout.write(`[dry-run] executor command: ${executor.command}\n`);
|
|
115
|
+
process.stdout.write(`[dry-run] reporter: ${reporterCandidates[0]?.actor}\n`);
|
|
116
|
+
process.stdout.write(`[dry-run] reporter command: ${reporterCandidates[0]?.command}\n`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const { command, actor } = resolveRegisterCommand(item, roster, itemOpts, execDefaults);
|
|
120
|
+
process.stdout.write(`[dry-run] actor: ${actor}\n`);
|
|
121
|
+
process.stdout.write(`[dry-run] command: ${command}\n`);
|
|
122
|
+
}
|
|
123
|
+
process.stdout.write(`[dry-run] plan: ${join(executionPath, "exec", "plans", `${stem}-plan.md`)}\n`);
|
|
124
|
+
}
|
|
125
|
+
process.stdout.write(`[dry-run] cwd: ${useWorktree ? `${worktreeBase}/<worktree>` : repoRoot}\n`);
|
|
126
|
+
process.stdout.write(`[dry-run] transitions: start (in-progress) → review on success / waiting on failure\n`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const context = {
|
|
130
|
+
projectId,
|
|
131
|
+
schedulePath,
|
|
132
|
+
executionPath,
|
|
133
|
+
repoRoot,
|
|
134
|
+
roster,
|
|
135
|
+
execDefaults,
|
|
136
|
+
// provider の max_concurrency は、同じ project の exec run(主 run と --join run)を跨いで
|
|
137
|
+
// ロックディレクトリの枠で統制する。
|
|
138
|
+
providerConcurrencyGate: new ProviderConcurrencyGate(execDefaults, execLocksDir(executionPath)),
|
|
139
|
+
registerCommit: !!opts.registerCommit,
|
|
140
|
+
worktree: useWorktree,
|
|
141
|
+
worktreeBase,
|
|
142
|
+
};
|
|
143
|
+
const skippedSummary = (pjrId) => ({
|
|
144
|
+
id: pjrId,
|
|
145
|
+
title: "-",
|
|
146
|
+
outcome: "skipped",
|
|
147
|
+
transition: "none",
|
|
148
|
+
commit: "skipped",
|
|
149
|
+
reason: "stopped after an earlier failure (--on-failure stop)",
|
|
150
|
+
});
|
|
151
|
+
const summaries = [];
|
|
152
|
+
// 再開は既存 worktree の reporter 段だけを実行する。それ以外の経路(plan 生成・executor 実行)
|
|
153
|
+
// は通らないため、通常実行と同じ並列・直列の枠だけを共有する。
|
|
154
|
+
const runItem = (pjrId, lifecycleLock) => opts.resume
|
|
155
|
+
? resumeSingleRegisterItemWorktree(context, optsForItem(pjrId), pjrId, lifecycleLock)
|
|
156
|
+
: runSingleRegisterItemWorktree(context, optsForItem(pjrId), pjrId, lifecycleLock);
|
|
157
|
+
// worktree 実行の root 側の手順(start 遷移・checkpoint・merge・wait commit・派生ビューの
|
|
158
|
+
// 再生成)は、同じ project の別プロセス(--join run)とも重ならないよう、ロックディレクトリの
|
|
159
|
+
// mutex で直列化する。一方の run が root に記帳ファイルを書いている途中で、もう一方の統合が
|
|
160
|
+
// 始まらない。直列実行でも別プロセスと重なり得るため、並列・直列の両方で使う。
|
|
161
|
+
const lifecycleLock = useWorktree
|
|
162
|
+
? new CrossProcessMutex(execLifecyclePoolPath(executionPath), { actor: opts.by ?? "exec-run", label: ids.join(",") }, {
|
|
163
|
+
onWait: () => process.stdout.write(" Waiting for the register lifecycle lock held by another exec run\n"),
|
|
164
|
+
})
|
|
165
|
+
: undefined;
|
|
166
|
+
if (useWorktree && parallel > 1) {
|
|
167
|
+
// 並列実行: 成果物は worktree ごとに隔離し、状態遷移は lifecycleLock で直列化する。
|
|
168
|
+
// stop 指定でも実行中の項目は完走し、未着手の残りだけを skipped にする。
|
|
169
|
+
const queue = [...ids];
|
|
170
|
+
const byId = new Map();
|
|
171
|
+
let stop = false;
|
|
172
|
+
await runCompletionDrivenWorkerPool({
|
|
173
|
+
maxParallel: parallel,
|
|
174
|
+
fillSlots: (openSlots) => (stop ? [] : queue.splice(0, openSlots)),
|
|
175
|
+
runItem: (pjrId) => runItem(pjrId, lifecycleLock),
|
|
176
|
+
onSettled: (pjrId, summary) => {
|
|
177
|
+
byId.set(pjrId, summary);
|
|
178
|
+
if (summary.outcome === "failure" && failureMode === "stop") {
|
|
179
|
+
stop = true;
|
|
180
|
+
return { stop: true };
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
for (const pjrId of ids)
|
|
185
|
+
summaries.push(byId.get(pjrId) ?? skippedSummary(pjrId));
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
let stopped = false;
|
|
189
|
+
for (const pjrId of ids) {
|
|
190
|
+
if (stopped) {
|
|
191
|
+
summaries.push(skippedSummary(pjrId));
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const summary = useWorktree
|
|
195
|
+
? await runItem(pjrId, lifecycleLock)
|
|
196
|
+
: await runSingleRegisterItem(context, optsForItem(pjrId), pjrId);
|
|
197
|
+
summaries.push(summary);
|
|
198
|
+
if (summary.outcome === "failure" && failureMode === "stop")
|
|
199
|
+
stopped = true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
process.stdout.write(`${formatRegisterRunSummary(summaries)}\n`);
|
|
203
|
+
const exitCode = registerRunExitCode(summaries);
|
|
204
|
+
if (exitCode !== 0)
|
|
205
|
+
process.exitCode = exitCode;
|
|
206
|
+
}
|