specdojo 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/agents/specdojo-orchestrator.md +165 -0
- package/CHANGELOG.md +280 -0
- package/README.md +143 -30
- package/dist/agent-response.js +20 -0
- package/dist/agent.js +4 -4
- package/dist/build-command.js +28 -8
- package/dist/dashboard.js +140 -9
- package/dist/devcontainer-command.js +43 -0
- package/dist/devcontainer-scaffold.js +165 -0
- 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-evidence.js +254 -11
- package/dist/exec-format.js +13 -4
- 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.js +115 -113
- 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.js +811 -0
- package/dist/exec-repo-trace.js +182 -0
- package/dist/exec-reporter.js +613 -132
- package/dist/exec-results.js +81 -56
- package/dist/exec-run-lock.js +110 -107
- package/dist/exec-run.js +1585 -356
- package/dist/exec-shared.js +7 -0
- package/dist/exec-slot-lock.js +242 -0
- package/dist/exec-task-repos.js +415 -0
- package/dist/exec-trial.js +51 -25
- package/dist/exec-worktree-command.js +87 -43
- package/dist/exec-worktree-ops.js +502 -57
- package/dist/exec-worktree.js +114 -27
- package/dist/exec.js +13 -6
- package/dist/grade-result.js +128 -0
- package/dist/grade.js +809 -72
- package/dist/init-command.js +443 -0
- package/dist/job.js +160 -10
- package/dist/orchestrator.js +213 -0
- package/dist/package-paths.js +19 -1
- package/dist/register-event-merge.js +169 -0
- package/dist/register-item.js +7 -1
- package/dist/register.js +294 -86
- package/dist/review-grade.js +252 -0
- package/dist/review-plan.js +111 -1
- package/dist/review-types.js +40 -1
- package/dist/routine.js +72 -5
- package/dist/schedule-build.js +2 -2
- package/dist/schedule.js +17 -4
- package/dist/specdojo-config.js +466 -20
- package/dist/specdojo-gitignore.js +135 -0
- package/dist/specdojo.js +8 -1
- package/dist/viewpoint-document-kinds-check.js +128 -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 +91 -47
- 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 +25 -4
- 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 +261 -32
- 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 +184 -0
- package/docs/ja/specdojo/guides/review-guide.md +195 -158
- package/docs/ja/specdojo/guides/routine-operation-guide.md +74 -9
- 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 +336 -93
- 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 +16 -9
- package/templates/antigravity/README.md +60 -0
- package/templates/antigravity/agent-members-snippet.yaml +61 -0
- package/templates/antigravity/exec-defaults-snippet.yaml +39 -0
- package/templates/antigravity/orchestrator.md +157 -0
- 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 +164 -0
- package/templates/claude/settings.edit.json +27 -1
- package/templates/codex/README.md +5 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +165 -0
- package/templates/codex/orchestrator.md +157 -0
- 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 +72 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +204 -0
- 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
package/dist/exec-run.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { selfRunArgs } from "./spawn-self.js";
|
|
5
|
-
import { defaultExecDefaultsPath, createProviderCapacityTracker, hasMemberCommandSource, loadExecDefaultsConfig, resolveMemberCommand, resolveRateLimitDetection, resolveRateLimitPolicy, } from "./exec-agent-config.js";
|
|
5
|
+
import { defaultExecDefaultsPath, createProviderCapacityTracker, hasMemberCommandSource, loadExecDefaultsConfig, ProviderConcurrencyGate, providerSlotPoolPath, resolveMaxConcurrency, resolveMaxConcurrentRuns, resolveRegisterExecution, resolveMemberCommand, resolveRateLimitDetection, resolveRateLimitPolicy, } from "./exec-agent-config.js";
|
|
6
6
|
import { activateResolvedProjectPaths, resolveProjectPaths } from "./exec-project.js";
|
|
7
7
|
import { acquireSchedulerLock, buildEvent, canCompleteTask, readAllEventFiles, foldEventsToState, releaseSchedulerLock, writeEventFile, } from "./exec-events.js";
|
|
8
8
|
import { limitEventMeta, normalizeAgentLimit, selectDueDeferredLimitTasks, } from "./exec-limit.js";
|
|
@@ -11,28 +11,34 @@ import { buildInitialStateFromStrategy } from "./exec-schedule-initial.js";
|
|
|
11
11
|
import { readReadySnapshot } from "./exec-schedule-ready.js";
|
|
12
12
|
import { listFilesRecursive, qualifyTaskId, randomHex, readYaml } from "./exec-shared.js";
|
|
13
13
|
import { getProjectExecutionPath, getProjectSchedulePath, loadConfig, loadMemberRoster, specdojoRootDir, } from "./specdojo-config.js";
|
|
14
|
-
import { acquireExecRunLock, EXEC_RUN_LOCK_TOKEN_ENV, inheritsExecRunLock, releaseExecRunLock, ROUTINE_BUSY_SKIP_EXIT_CODE, ROUTINE_EXEC_ENV, } from "./exec-run-lock.js";
|
|
14
|
+
import { acquireExecRunLock, collectExecLockUsage, EXEC_RUN_LOCK_TOKEN_ENV, execLifecyclePoolPath, execLocksDir, formatExecLockUsage, inheritsExecRunLock, releaseExecRunLock, ROUTINE_BUSY_SKIP_EXIT_CODE, ROUTINE_EXEC_ENV, } from "./exec-run-lock.js";
|
|
15
|
+
import { CrossProcessMutex, getActiveExecLocksDir, setActiveExecLocksDir, } from "./exec-slot-lock.js";
|
|
15
16
|
import { replaceDocIndexRefs } from "./doc-index.js";
|
|
16
17
|
import { extractLocalId, extractPhaseSuffix, normalizePhaseSetSelection, phaseSetNames, } from "./schedule-phase-sets.js";
|
|
17
|
-
import { archivePlan, buildInPlaceStem, generateDeliverablePlan, generateSinglePlan, loadPlan, parsePlanTaskIdentity, resolveDeliverableTarget, finalizeResultSectionsForDeliverable,
|
|
18
|
+
import { archivePlan, buildInPlaceStem, generateDeliverablePlan, generateSinglePlan, loadPlan, parsePlanTaskIdentity, resolveDeliverableTarget, finalizeResultSectionsForDeliverable, targetDocIdsForScheduledTask, stemFromPlanPath, reviewGradeSubject, } from "./exec-plans.js";
|
|
19
|
+
import { ensureReviewGrade } from "./review-grade.js";
|
|
18
20
|
import { buildTaskView } from "./exec-task-view.js";
|
|
19
|
-
import { formatRegisterRunSummary, generateRegisterPlan, isRegisterFailureMode, parseRegisterIds, parseRegisterSelectionFilter, registerRunExitCode, requireRunnableRegisterItem, resolveRegisterRunTarget, sanitizeRegisterConclusion, selectRegisterItems, selectRegisterCommitPaths, selectRegisterRunArtifactResidue, ticketPathFromItem, } from "./exec-register.js";
|
|
21
|
+
import { formatRegisterRunSummary, generateRegisterPlan, isRegisterFailureMode, normalizePjrId, parseRegisterIds, parseRegisterSelectionFilter, registerRunExitCode, requireRunnableRegisterItem, resolveRegisterRunTarget, sanitizeRegisterConclusion, selectRegisterItems, selectRegisterCommitPaths, selectRegisterRunArtifactResidue, ticketPathFromItem, } from "./exec-register.js";
|
|
20
22
|
import { loadRegisterItems, resolveRegisterPaths, } from "./register.js";
|
|
21
23
|
import { registerEventFilePath } from "./register-events.js";
|
|
22
|
-
import { displayIdFromTicketFilename } from "./register-item.js";
|
|
24
|
+
import { applyRegisterItemFields, CELL_NONE, displayIdFromTicketFilename, readRegisterItemContent, registerItemFieldsFromItem, } from "./register-item.js";
|
|
23
25
|
import { isResultUnfilled, readResultFrontmatterSnapshot, renderReporterResult, scaffoldResult, updateResultStatus, } from "./exec-results.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
26
|
+
import { formatMarkdownFile } from "./exec-format.js";
|
|
27
|
+
import { completeJobRun, executeJobCommand, generateJobReviewPlan, isJobCommandTask, jobRunUsesReviewedIntegration, loadJobDefinition, loadJobRunRecord, materializeJobRun, recordJobRunReview, resolveJobPaths, resolveJobReviewAgentNominations, } from "./job.js";
|
|
28
|
+
import { appendGitFailureLog, ensureExecWorktree, findExecWorktree, gitEnvironment, gitOutput, gitResult, resolveWorktreeBase, summarizeGitHookFailure, worktreeNameFromTaskId, } from "./exec-worktree.js";
|
|
29
|
+
import { configuredProductRepos, missingProductWorktrees, plannedProjectWorktreePath, productRepoEnvironment, productRootsFromEnvironment, withAgentExtraRoots, withoutInheritedRepoEnvironment, withProductRepoPrompt, withProductWorktrees, } from "./exec-task-repos.js";
|
|
30
|
+
import { abortMerge, checkpointAndEnsureWorktree, commitTargetPaths, commitWorktreeChanges, currentBranch, discardStaleExecWorktree, isExecBranchMergedIntoCurrent, mergeWorktreeIntoCurrent, normalizeResultWhitespace, releaseRootWorkingCopies, removeWorktree, stabilizeCommitTargets, stageCommitTargets, taskTargetsAtHead, unstageCommitTargets, WorktreeRemovedBranchDeletionError, worktreeStatusPaths, } from "./exec-worktree-ops.js";
|
|
31
|
+
import { commitProductWorktrees, integrateTaskRepositories, projectMergeBlockers, PROJECT_REPO_NAME, RepoIntegrationError, syncTaskWorktreesWithIntegrationTargets, } from "./exec-repo-integration.js";
|
|
32
|
+
import { productIntegrationTrace, recordResultTrace, refsTrailer, registerProjectMergeMessage, traceKey, withCommitTrailers, } from "./exec-repo-trace.js";
|
|
33
|
+
import { agentProtectedConfigViolation, captureAgentProtectedConfigAcrossRepos, captureAgentProtectedConfigSnapshot, changedAgentProtectedConfigAcrossRepos, changedAgentProtectedConfigPaths, qualifiedRepoPaths, } from "./exec-agent-protected-config.js";
|
|
34
|
+
import { agentGitStateViolation, captureAgentGitStateAcrossRepos, captureAgentGitStateSnapshot, changedAgentGitStateAcrossRepos, changedAgentGitStateFields, qualifiedGitStateFields, } from "./exec-agent-git-state.js";
|
|
35
|
+
import { recordGitStateBlock, recordGitStateBlockAcrossRepos, recordProtectedConfigBlock, recordProtectedConfigBlockAcrossRepos, } from "./exec-protection-handoff.js";
|
|
30
36
|
import { buildPhaseModeIndex, resolveAgentAssignment, resolveAgentPipeline, resolveApproach, resolveTaskCapabilities, resolveTaskExecution, resolveTaskMode, resolveTaskProficiency, } from "./exec-strategy.js";
|
|
31
|
-
import { recordCommandEvidence, recordExecutorEvidence, recordReporterFailureOutput, writeExecutorEvidence, } from "./exec-evidence.js";
|
|
32
|
-
import { failedParentValidationReason, hasRecordedParentValidations, replaceParentValidationResults,
|
|
33
|
-
import { runReporterWithFormatRetry } from "./exec-reporter.js";
|
|
37
|
+
import { recordCommandEvidence, recordExecutorEvidence, recordParentValidationFailureOutput, recordReporterFailureOutput, snapshotWorktreeChanges, validateResumedTargetCoverage, writeExecutorEvidence, } from "./exec-evidence.js";
|
|
38
|
+
import { failedParentValidationReason, hasRecordedParentValidations, parentValidationGateFor, parentValidationPoolPath, replaceParentValidationResults, parentValidationDisplayCommands, parentValidationLabels, parentValidationRoots, recordedParentValidationLabel, resolveParentValidationConcurrency, runParentValidationBatch, } from "./exec-parent-validation.js";
|
|
39
|
+
import { deriveReporterFacts, evidenceForReporter, runReporterWithFormatRetry, } from "./exec-reporter.js";
|
|
34
40
|
import { findResumableRegisterRun, resolveRegisterResumeArtifacts, } from "./exec-register-resume.js";
|
|
35
|
-
import { createPipelineState, loadPipelineResumeCheckpoint, pipelineStateLocation, readPipelineState, updatePipelineStage, writePipelineState, } from "./exec-pipeline-state.js";
|
|
41
|
+
import { createPipelineState, integratedRepoNames, loadPipelineResumeCheckpoint, pipelineStateLocation, readPipelineState, updatePipelineRepoIntegration, updatePipelineStage, writePipelineState, } from "./exec-pipeline-state.js";
|
|
36
42
|
function pinnedExecutor(task) {
|
|
37
43
|
return typeof task?.agent === "string" ? task.agent : task?.agent?.executor;
|
|
38
44
|
}
|
|
@@ -41,7 +47,7 @@ function pinnedReporter(task) {
|
|
|
41
47
|
}
|
|
42
48
|
// Resolve the agent override for a task's mode. A single explicit --by nickname wins for every
|
|
43
49
|
// mode. Otherwise the mode-specific --edit-by / --review-by nickname applies. Commands are always
|
|
44
|
-
// resolved from
|
|
50
|
+
// resolved from agent-members.yaml and exec-defaults.yaml; raw command strings are not accepted.
|
|
45
51
|
export function resolveAgentOverride(mode, agentNicknameOverride, modeAgentOverrides, roster, execDefaults = {}, stageRole) {
|
|
46
52
|
const nickname = agentNicknameOverride ??
|
|
47
53
|
(mode === "review" ? modeAgentOverrides.review : modeAgentOverrides.edit);
|
|
@@ -65,7 +71,7 @@ export function resolveAgentOverride(mode, agentNicknameOverride, modeAgentOverr
|
|
|
65
71
|
if (!member || !command) {
|
|
66
72
|
return {
|
|
67
73
|
kind: "error",
|
|
68
|
-
message: `${flag} agent nickname not found in
|
|
74
|
+
message: `${flag} agent nickname not found in agent-members.yaml (or has no resolvable command): ${nickname}`,
|
|
69
75
|
};
|
|
70
76
|
}
|
|
71
77
|
return {
|
|
@@ -351,17 +357,50 @@ export function parseExecRunBusyPolicy(value) {
|
|
|
351
357
|
}
|
|
352
358
|
return policy;
|
|
353
359
|
}
|
|
354
|
-
|
|
360
|
+
export function resolveRegisterWorktree(opts, execDefaults) {
|
|
361
|
+
if (opts.worktree && opts.inPlace) {
|
|
362
|
+
throw new Error("Specify either --worktree or --in-place, not both.");
|
|
363
|
+
}
|
|
364
|
+
if (opts.worktree)
|
|
365
|
+
return true;
|
|
366
|
+
if (opts.inPlace)
|
|
367
|
+
return false;
|
|
368
|
+
return resolveRegisterExecution(execDefaults) === "worktree";
|
|
369
|
+
}
|
|
370
|
+
const EXCLUSIVE_EXEC_RUN = { shareable: false, join: false };
|
|
371
|
+
function resolveJoinSlotLimit(opts, schedulePath, executionPath) {
|
|
372
|
+
const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
|
|
373
|
+
return resolveMaxConcurrentRuns(execDefaults) - 1;
|
|
374
|
+
}
|
|
375
|
+
async function withProjectExecRunLock(opts, commandLabel, action, sharing = EXCLUSIVE_EXEC_RUN) {
|
|
355
376
|
const resolvedPaths = resolveProjectPaths({ project: opts.project });
|
|
377
|
+
const locksDir = execLocksDir(resolvedPaths.executionPath);
|
|
378
|
+
const previousLocksDir = getActiveExecLocksDir();
|
|
356
379
|
if (inheritsExecRunLock(resolvedPaths.executionPath)) {
|
|
357
|
-
|
|
380
|
+
setActiveExecLocksDir(locksDir);
|
|
381
|
+
try {
|
|
382
|
+
await action();
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
setActiveExecLocksDir(previousLocksDir);
|
|
386
|
+
}
|
|
358
387
|
return;
|
|
359
388
|
}
|
|
360
389
|
const policy = parseExecRunBusyPolicy(opts.ifBusy);
|
|
390
|
+
const joinLimit = sharing.join
|
|
391
|
+
? resolveJoinSlotLimit(opts, resolvedPaths.schedulePath, resolvedPaths.executionPath)
|
|
392
|
+
: 0;
|
|
393
|
+
if (sharing.join && joinLimit < 1) {
|
|
394
|
+
throw new Error("--join is disabled: run.max_concurrent_runs in exec-defaults is 1 (raise it to allow joining runs)");
|
|
395
|
+
}
|
|
361
396
|
const handle = await acquireExecRunLock(resolvedPaths.executionPath, {
|
|
362
397
|
actor: opts.by ?? `exec-${commandLabel}`,
|
|
363
398
|
ifBusy: policy,
|
|
364
|
-
|
|
399
|
+
shareable: sharing.shareable || sharing.join,
|
|
400
|
+
...(sharing.join ? { join: { limit: joinLimit } } : {}),
|
|
401
|
+
onWait: () => process.stdout.write(sharing.join
|
|
402
|
+
? `[${commandLabel}] exec busy — waiting for a join slot (see "exec slots")\n`
|
|
403
|
+
: `[${commandLabel}] exec busy — waiting\n`),
|
|
365
404
|
});
|
|
366
405
|
if (!handle) {
|
|
367
406
|
process.stdout.write(`[${commandLabel}] skipped: exec busy\n`);
|
|
@@ -370,12 +409,17 @@ async function withProjectExecRunLock(opts, commandLabel, action) {
|
|
|
370
409
|
}
|
|
371
410
|
return;
|
|
372
411
|
}
|
|
412
|
+
if (sharing.join) {
|
|
413
|
+
process.stdout.write(`[${commandLabel}] running as a joined exec (${basename(handle.lockDir)})\n`);
|
|
414
|
+
}
|
|
373
415
|
const previousInheritedToken = process.env[EXEC_RUN_LOCK_TOKEN_ENV];
|
|
374
416
|
process.env[EXEC_RUN_LOCK_TOKEN_ENV] = handle.token;
|
|
417
|
+
setActiveExecLocksDir(locksDir);
|
|
375
418
|
try {
|
|
376
419
|
await action();
|
|
377
420
|
}
|
|
378
421
|
finally {
|
|
422
|
+
setActiveExecLocksDir(previousLocksDir);
|
|
379
423
|
if (previousInheritedToken === undefined)
|
|
380
424
|
delete process.env[EXEC_RUN_LOCK_TOKEN_ENV];
|
|
381
425
|
else
|
|
@@ -405,10 +449,69 @@ export function loadPrompt(executionPath, taskId) {
|
|
|
405
449
|
const plan = loadPlan(executionPath, taskId);
|
|
406
450
|
return plan ? expandPromptRefs(plan) : null;
|
|
407
451
|
}
|
|
408
|
-
function
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
452
|
+
export function resolveResumedCoverageTargets(plan, initialChangeTargets = []) {
|
|
453
|
+
const declared = [
|
|
454
|
+
...new Set((parsePlanTaskIdentity(plan)?.targets ?? []).map((target) => target.trim())),
|
|
455
|
+
].filter(Boolean);
|
|
456
|
+
if (declared.length > 0)
|
|
457
|
+
return { source: "declared", targets: declared };
|
|
458
|
+
const initial = [...new Set(initialChangeTargets.map((target) => target.trim()))].filter(Boolean);
|
|
459
|
+
return initial.length > 0
|
|
460
|
+
? { source: "initial-changes", targets: initial }
|
|
461
|
+
: { source: "none", targets: [] };
|
|
462
|
+
}
|
|
463
|
+
function executorEvidenceContract(parentValidations, options = {}) {
|
|
464
|
+
const parentValidationLabelList = parentValidationLabels(parentValidations);
|
|
465
|
+
const parentValidationCommands = parentValidationDisplayCommands(parentValidations);
|
|
466
|
+
const parentValidationInstruction = parentValidationLabelList.length > 0
|
|
467
|
+
? `\nThe SpecDojo parent runner will execute these allowlisted validations after you exit: ${parentValidationLabelList.join(", ")} (${parentValidationCommands.join(", ")}). Do not run those commands inside the agent sandbox or report duplicate executor results for them. Run only the remaining sandbox-safe validations required by the plan. Parent-run results will be appended to evidence with source=runner and are authoritative.\n`
|
|
468
|
+
: "";
|
|
469
|
+
const coverage = {
|
|
470
|
+
source: options.coverageSource ?? "none",
|
|
471
|
+
targets: [...(options.initialChangeTargets ?? [])],
|
|
472
|
+
};
|
|
473
|
+
const coverageInstruction = coverage.source === "initial-changes"
|
|
474
|
+
? `The plan declares no \`targets\`. The paths below were materially changed by the first
|
|
475
|
+
executor attempt and are an incomplete lower bound, not an upper bound on the work required.
|
|
476
|
+
Inspect the entire plan and any additional artifacts it requires. For each lower-bound path,
|
|
477
|
+
include one \`target_coverage\` entry and use the path exactly as the entry's \`target\` value:
|
|
478
|
+
${coverage.targets.map((target) => `- \`${target}\``).join("\n")}`
|
|
479
|
+
: coverage.source === "declared"
|
|
480
|
+
? `For each entry in plan frontmatter \`targets\`, include one \`target_coverage\` entry in
|
|
481
|
+
the evidence envelope. Use the target ID exactly as written in the plan. Declared targets take
|
|
482
|
+
priority over any files recorded by an earlier attempt.`
|
|
483
|
+
: `The plan declares no \`targets\` and no first-attempt change lower bound was recorded.
|
|
484
|
+
Omit \`target_coverage\` and state in \`final_message\` which artifacts you verified and which
|
|
485
|
+
remain unverified.`;
|
|
486
|
+
const resumeInstruction = options.resumed
|
|
487
|
+
? `
|
|
488
|
+
This executor invocation resumes an interrupted attempt. Existing worktree changes may represent
|
|
489
|
+
only a partial implementation; they are not proof that the plan is complete. Re-read the entire
|
|
490
|
+
plan before reporting success. ${coverageInstruction}
|
|
491
|
+
|
|
492
|
+
${options.resumeHandoff?.length
|
|
493
|
+
? `The previous attempt left these failure details. Address them before reporting success:\n${options.resumeHandoff.map((detail) => `- ${detail}`).join("\n")}\n`
|
|
494
|
+
: ""}
|
|
495
|
+
|
|
496
|
+
A changed target must use status \`changed\`, provide its
|
|
497
|
+
repository-relative \`path\`, and actually be present in the cumulative worktree diff. A target
|
|
498
|
+
that legitimately needs no change must use status \`unchanged\` and provide a concrete \`reason\`;
|
|
499
|
+
the runner will preserve that reason in the result. If you cannot account for every target, exit
|
|
500
|
+
non-zero instead of claiming completion.${options.existingChanges?.length
|
|
501
|
+
? `\n\nChanges already present when this resumed invocation started:\n${options.existingChanges.map((path) => `- \`${path}\``).join("\n")}`
|
|
502
|
+
: ""}
|
|
503
|
+
`
|
|
504
|
+
: "";
|
|
505
|
+
const targetCoverageExample = options.resumed
|
|
506
|
+
? ',"target_coverage":[{"target":"exact declared target id or lower-bound path","status":"changed|unchanged","path":"repo-relative path for changed targets","reason":"required when unchanged"}]'
|
|
507
|
+
: "";
|
|
508
|
+
const reviewValidationInstruction = options.mode === "review"
|
|
509
|
+
? `
|
|
510
|
+
For a review task, report only checks you actually ran in \`validations\`. Do not add optional
|
|
511
|
+
checks you chose not to run as \`not_run\` or \`not_applicable\`. Describe them instead in
|
|
512
|
+
\`final_message\` under "確認できなかった範囲" so the reporter can record that scope in the
|
|
513
|
+
review result and reflect it in the verdict.
|
|
514
|
+
`
|
|
412
515
|
: "";
|
|
413
516
|
return `
|
|
414
517
|
|
|
@@ -425,42 +528,106 @@ The parent runner owns Git commits and repository configuration. Do not run git
|
|
|
425
528
|
local, global, or system Git configuration, including user.name and user.email. A Git state change
|
|
426
529
|
will stop the pipeline before validation, reporting, commit, or merge.
|
|
427
530
|
|
|
531
|
+
Do not create disposable or scratch files at the repository root; place them in \`tmp/\` within
|
|
532
|
+
the worktree or outside the repository. Files under \`tmp/\` are excluded from commits.
|
|
533
|
+
|
|
428
534
|
When writing Markdown in the final evidence, wrap identifiers or field names containing an
|
|
429
535
|
underscore in inline code (for example, \`depends_on\`).
|
|
430
536
|
${parentValidationInstruction}
|
|
537
|
+
${resumeInstruction}
|
|
538
|
+
${reviewValidationInstruction}
|
|
539
|
+
|
|
540
|
+
Use validation status \`requires_human\` only for a check that cannot run from the agent sandbox,
|
|
541
|
+
such as launching a real agent CLI, consuming a usage quota or incurring a charge, or requiring
|
|
542
|
+
credentials or a host-side operation. Do not use it for a check that could run but was skipped;
|
|
543
|
+
report that as \`not_run\`. A \`requires_human\` check is carried into the result as a human handoff
|
|
544
|
+
and does not block pipeline completion.
|
|
545
|
+
|
|
546
|
+
Use validation status \`not_applicable\` when the repository does not meet a check's applicability
|
|
547
|
+
conditions, and include a non-empty \`reason\`. The runner carries it into the result without
|
|
548
|
+
blocking completion, but rejects the claim when it can confirm the check applies:
|
|
549
|
+
- \`npm run <script>\` / \`npm test\`: the script exists in package.json.
|
|
550
|
+
- \`npx <package>\`: the package is in package.json dependencies or devDependencies.
|
|
551
|
+
- A command that targets a declared product repository (a \`<repo>:<path>\` argument or
|
|
552
|
+
\`--prefix <repo>\`) is judged by that repository's package.json, not the project repository's.
|
|
553
|
+
- \`specdojo catalog validate\`: the run's target project (or \`--project <id>\`) sets \`catalog_path\`
|
|
554
|
+
and your changes reach \`docs/ja/projects/\`. A project without \`catalog_path\`, or changes
|
|
555
|
+
outside \`docs/ja/projects/\`, is a valid reason; state it in \`reason\`.
|
|
556
|
+
|
|
557
|
+
Do not run or report \`specdojo index build\`. It writes \`.specdojo/doc-index.json\`, which the
|
|
558
|
+
agent may not write, and the runner regenerates the index while preparing the worktree and before
|
|
559
|
+
integration.
|
|
431
560
|
|
|
432
561
|
End the final response with exactly one machine-readable report using this envelope. Do not place
|
|
433
562
|
Markdown fences around the JSON.
|
|
434
563
|
|
|
435
564
|
<specdojo_executor_evidence>
|
|
436
|
-
{"final_message":"concise outcome","validations":[{"command":"exact command","status":"passed|failed|not_run","summary":"concise result"}]}
|
|
565
|
+
{"final_message":"concise outcome","validations":[{"command":"exact command","status":"passed|failed|not_run|not_applicable|requires_human","summary":"concise result or required human check","reason":"required when status is not_applicable"}]${targetCoverageExample}}
|
|
437
566
|
</specdojo_executor_evidence>
|
|
438
567
|
`;
|
|
439
568
|
}
|
|
440
|
-
export function buildExecutorPrompt(plan,
|
|
441
|
-
|
|
569
|
+
export function buildExecutorPrompt(plan, parentValidations = [], options = {}) {
|
|
570
|
+
const coverage = resolveResumedCoverageTargets(plan, options.initialChangeTargets);
|
|
571
|
+
return `${plan.trimEnd()}${executorEvidenceContract(parentValidations, {
|
|
572
|
+
...options,
|
|
573
|
+
mode: options.mode ?? parsePlanTaskIdentity(plan)?.mode ?? "edit",
|
|
574
|
+
initialChangeTargets: coverage.targets,
|
|
575
|
+
coverageSource: coverage.source,
|
|
576
|
+
})}`;
|
|
442
577
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
578
|
+
function resumedTargetCoverageFailure(params) {
|
|
579
|
+
if (!params.resumed)
|
|
580
|
+
return undefined;
|
|
581
|
+
const targets = resolveResumedCoverageTargets(params.plan, params.initialChangeTargets).targets;
|
|
582
|
+
const coverage = validateResumedTargetCoverage(targets, params.evidence);
|
|
583
|
+
if (coverage.ok)
|
|
584
|
+
return undefined;
|
|
585
|
+
params.evidence.stage.status = "failed";
|
|
586
|
+
writeExecutorEvidence(params.evidencePath, params.evidence);
|
|
587
|
+
return coverage.reason;
|
|
588
|
+
}
|
|
589
|
+
// 同じ exec run 内の親検証は run 全体の gate(既定 1 本)で直列化する。executor と reporter は
|
|
590
|
+
// gate の外で並列に動き、検証だけが順番待ちになる。`cwd` に文字列を渡すとプロジェクト worktree
|
|
591
|
+
// だけを持つ run として扱い、プロダクトリポジトリへ割り当てた検証は failed になる(PJR-V96B)。
|
|
592
|
+
export async function runConfiguredParentValidationBatch(execDefaults, cwd, options = {}) {
|
|
593
|
+
const entries = execDefaults.pipeline?.parent_validations;
|
|
594
|
+
if (!entries?.length)
|
|
595
|
+
return { validations: [], failureOutputs: [] };
|
|
596
|
+
const labels = parentValidationLabels(entries);
|
|
597
|
+
const label = options.label ?? basename(typeof cwd === "string" ? cwd : cwd.project);
|
|
598
|
+
const batch = await parentValidationGateFor(execDefaults).run(label, labels, async () => {
|
|
599
|
+
process.stdout.write(` Running parent validations (${label}): ${labels.join(", ")}\n`);
|
|
600
|
+
return await runParentValidationBatch(entries, cwd, options.invoke);
|
|
601
|
+
});
|
|
602
|
+
for (const validation of batch.validations) {
|
|
603
|
+
process.stdout.write(` Parent validation ${recordedParentValidationLabel(validation)}: ${validation.status}\n`);
|
|
451
604
|
}
|
|
452
|
-
return
|
|
605
|
+
return batch;
|
|
606
|
+
}
|
|
607
|
+
export async function runConfiguredParentValidations(execDefaults, cwd, options = {}) {
|
|
608
|
+
return (await runConfiguredParentValidationBatch(execDefaults, cwd, options)).validations;
|
|
453
609
|
}
|
|
454
610
|
async function refreshParentValidationsForReporterResume(params) {
|
|
455
|
-
const
|
|
456
|
-
|
|
611
|
+
const configuredEntries = params.execDefaults.pipeline?.parent_validations;
|
|
612
|
+
const force = params.force === true && (configuredEntries?.length ?? 0) > 0;
|
|
613
|
+
if (!force &&
|
|
614
|
+
hasRecordedParentValidations(params.evidence.validations, configuredEntries) &&
|
|
457
615
|
!failedParentValidationReason(params.evidence.validations)) {
|
|
458
616
|
return params.evidence;
|
|
459
617
|
}
|
|
460
|
-
process.stdout.write(
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
|
|
618
|
+
process.stdout.write(` Refreshing parent validations before ${params.stageLabel ?? "reporter"} resume` +
|
|
619
|
+
`${force ? " (integration targets were merged into the worktree)" : ""}.\n`);
|
|
620
|
+
const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, parentValidationRoots(params.cwd, params.productWorktrees), { label: params.evidence.task_id });
|
|
621
|
+
const evidenceWithValidations = replaceParentValidationResults(params.evidence, parentValidationBatch.validations);
|
|
622
|
+
const evidence = recordParentValidationFailureOutput({
|
|
623
|
+
worktreePath: params.cwd,
|
|
624
|
+
evidencePath: params.evidencePath,
|
|
625
|
+
evidence: evidenceWithValidations,
|
|
626
|
+
failureOutputs: parentValidationBatch.failureOutputs,
|
|
627
|
+
});
|
|
628
|
+
if (parentValidationBatch.failureOutputs.length === 0) {
|
|
629
|
+
writeExecutorEvidence(params.evidencePath, evidence);
|
|
630
|
+
}
|
|
464
631
|
process.stdout.write(` Refreshed executor evidence: ${relative(params.cwd, params.evidencePath).split(sep).join("/")}\n`);
|
|
465
632
|
return evidence;
|
|
466
633
|
}
|
|
@@ -468,9 +635,17 @@ async function refreshParentValidationsForReporterResume(params) {
|
|
|
468
635
|
// その途中で runner が終了しても agent 出力と変更一覧を失わないよう、ここでは保存済み evidence
|
|
469
636
|
// へ runner-owned validation だけを追記する。
|
|
470
637
|
async function appendParentValidationsToExecutorEvidence(params) {
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
|
|
638
|
+
const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, parentValidationRoots(params.cwd, params.productWorktrees), { label: params.evidence.task_id });
|
|
639
|
+
const evidenceWithValidations = replaceParentValidationResults(params.evidence, parentValidationBatch.validations);
|
|
640
|
+
const evidence = recordParentValidationFailureOutput({
|
|
641
|
+
worktreePath: params.cwd,
|
|
642
|
+
evidencePath: params.evidencePath,
|
|
643
|
+
evidence: evidenceWithValidations,
|
|
644
|
+
failureOutputs: parentValidationBatch.failureOutputs,
|
|
645
|
+
});
|
|
646
|
+
if (parentValidationBatch.failureOutputs.length === 0) {
|
|
647
|
+
writeExecutorEvidence(params.evidencePath, evidence);
|
|
648
|
+
}
|
|
474
649
|
return evidence;
|
|
475
650
|
}
|
|
476
651
|
export function executorRequirements(task) {
|
|
@@ -538,12 +713,7 @@ export function loadRosterForExecutionPath(executionPath) {
|
|
|
538
713
|
for (const project of Object.values(config.projects)) {
|
|
539
714
|
const projExecPath = resolve(rootDir, getProjectExecutionPath(project));
|
|
540
715
|
if (projExecPath === executionPath) {
|
|
541
|
-
|
|
542
|
-
return loadMemberRoster(rootDir, project);
|
|
543
|
-
}
|
|
544
|
-
catch {
|
|
545
|
-
return null;
|
|
546
|
-
}
|
|
716
|
+
return loadMemberRoster(rootDir, project);
|
|
547
717
|
}
|
|
548
718
|
}
|
|
549
719
|
return null;
|
|
@@ -624,9 +794,19 @@ function reportProtectionHandoffRecord(recorded, resultPath) {
|
|
|
624
794
|
//
|
|
625
795
|
// resultPath は保護機構が block したときの申し送り記録先(agent が動く cwd 側の result)。
|
|
626
796
|
// 未指定でも block と終了コードの扱いは変わらない。
|
|
797
|
+
function rateLimitPrefix(result) {
|
|
798
|
+
return result === "rate_limit" ? "rate limit reached; " : "";
|
|
799
|
+
}
|
|
627
800
|
async function runWithRetry(candidates, prompt, execDefaults, cwd, env, resultPath) {
|
|
628
801
|
const policy = resolveRateLimitPolicy(execDefaults, candidates[0]?.provider);
|
|
629
802
|
let attempts = 0;
|
|
803
|
+
// PJR-98G4: agentEnvironment が渡したプロダクト worktree を、provider の追加ディレクトリと
|
|
804
|
+
// 保護設定・Git 状態の検査対象に加える。宣言の無い project では cwd だけになる。
|
|
805
|
+
const productRoots = productRootsFromEnvironment(env);
|
|
806
|
+
const agentRepos = [
|
|
807
|
+
{ root: cwd },
|
|
808
|
+
...productRoots.map((root) => ({ name: root.name, root: root.path })),
|
|
809
|
+
];
|
|
630
810
|
// One pass tries every candidate in priority order with no wait between switches.
|
|
631
811
|
const runPass = async () => {
|
|
632
812
|
let lastStderr = "";
|
|
@@ -639,17 +819,18 @@ async function runWithRetry(candidates, prompt, execDefaults, cwd, env, resultPa
|
|
|
639
819
|
}
|
|
640
820
|
const detection = resolveRateLimitDetection(execDefaults, candidates[idx].provider);
|
|
641
821
|
attempts++;
|
|
642
|
-
const protectedConfigBefore =
|
|
643
|
-
const gitStateBefore =
|
|
644
|
-
const attempt = await executeAgent(candidates[idx].command, prompt, detection, candidates[idx].provider, policy?.cooldown_seconds, cwd, env);
|
|
645
|
-
const protectedConfigChanges =
|
|
822
|
+
const protectedConfigBefore = captureAgentProtectedConfigAcrossRepos(agentRepos);
|
|
823
|
+
const gitStateBefore = captureAgentGitStateAcrossRepos(agentRepos);
|
|
824
|
+
const attempt = await executeAgent(withAgentExtraRoots(candidates[idx].command, candidates[idx].provider, productRoots.map((root) => root.path)), prompt, detection, candidates[idx].provider, policy?.cooldown_seconds, cwd, env);
|
|
825
|
+
const protectedConfigChanges = changedAgentProtectedConfigAcrossRepos(protectedConfigBefore);
|
|
646
826
|
if (protectedConfigChanges.length > 0) {
|
|
647
|
-
|
|
827
|
+
// 利用上限で止まった場合も保護の検査は飛ばさない。止まった理由として利用上限を先に記録する。
|
|
828
|
+
const reason = rateLimitPrefix(attempt.result) +
|
|
829
|
+
agentProtectedConfigViolation(qualifiedRepoPaths(protectedConfigChanges));
|
|
648
830
|
process.stderr.write(`blocked: ${reason}\n`);
|
|
649
|
-
reportProtectionHandoffRecord(
|
|
831
|
+
reportProtectionHandoffRecord(recordProtectedConfigBlockAcrossRepos({
|
|
650
832
|
resultPath,
|
|
651
|
-
|
|
652
|
-
paths: protectedConfigChanges,
|
|
833
|
+
changes: protectedConfigChanges,
|
|
653
834
|
reason,
|
|
654
835
|
}), resultPath);
|
|
655
836
|
return {
|
|
@@ -660,15 +841,15 @@ async function runWithRetry(candidates, prompt, execDefaults, cwd, env, resultPa
|
|
|
660
841
|
protectionBlock: true,
|
|
661
842
|
};
|
|
662
843
|
}
|
|
663
|
-
const gitStateChanges =
|
|
844
|
+
const gitStateChanges = changedAgentGitStateAcrossRepos(gitStateBefore);
|
|
664
845
|
if (gitStateChanges.length > 0) {
|
|
665
|
-
|
|
846
|
+
// 利用上限で止まった場合も保護の検査は飛ばさない。止まった理由として利用上限を先に記録する。
|
|
847
|
+
const reason = rateLimitPrefix(attempt.result) +
|
|
848
|
+
agentGitStateViolation(qualifiedGitStateFields(gitStateChanges));
|
|
666
849
|
process.stderr.write(`blocked: ${reason}\n`);
|
|
667
|
-
reportProtectionHandoffRecord(
|
|
850
|
+
reportProtectionHandoffRecord(recordGitStateBlockAcrossRepos({
|
|
668
851
|
resultPath,
|
|
669
|
-
|
|
670
|
-
before: gitStateBefore,
|
|
671
|
-
fields: gitStateChanges,
|
|
852
|
+
changes: gitStateChanges,
|
|
672
853
|
reason,
|
|
673
854
|
}), resultPath);
|
|
674
855
|
return {
|
|
@@ -749,17 +930,58 @@ function pathInsideWorktree(repoRoot, worktreePath, sourcePath) {
|
|
|
749
930
|
}
|
|
750
931
|
return resolve(worktreePath, repoRelative);
|
|
751
932
|
}
|
|
752
|
-
function
|
|
933
|
+
function reportProductWorktrees(worktree) {
|
|
934
|
+
for (const product of worktree.repos ?? []) {
|
|
935
|
+
process.stdout.write(` [run] ${product.created ? "setup" : "reuse"}: worktree ${product.path} ` +
|
|
936
|
+
`(${product.branch} in ${product.name})\n`);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
// productWorktrees(PJR-98G4)は、cwd(プロジェクト worktree)以外に agent が書き込むプロダクト
|
|
940
|
+
// worktree。SPECDOJO_REPO_<NAME> で絶対パスを渡し、runWithRetry はここから provider の追加
|
|
941
|
+
// ディレクトリと保護検査の対象を導く。
|
|
942
|
+
function agentEnvironment(repoRoot, worktreePath, schedulePath, executionPath, productWorktrees) {
|
|
753
943
|
return {
|
|
754
|
-
...gitEnvironment(),
|
|
944
|
+
...withoutInheritedRepoEnvironment(gitEnvironment()),
|
|
755
945
|
SPECDOJO_SCHEDULE_PATH: pathInsideWorktree(repoRoot, worktreePath, schedulePath),
|
|
756
946
|
SPECDOJO_EXECUTION_PATH: pathInsideWorktree(repoRoot, worktreePath, executionPath),
|
|
947
|
+
...productRepoEnvironment(worktreePath, productWorktrees),
|
|
757
948
|
};
|
|
758
949
|
}
|
|
759
950
|
function findClaimEventPath(schedulePath, taskId) {
|
|
760
951
|
const claims = readAllEventFiles(schedulePath).filter((item) => item.event.task_id === taskId && item.event.type === "claim");
|
|
761
952
|
return claims[claims.length - 1]?.path ?? null;
|
|
762
953
|
}
|
|
954
|
+
// review フェーズの前段で runner が対象文書へ grade を実行する(PJR-KCMH、PJR-2ZVS 3.6)。
|
|
955
|
+
// executor には実行させない。評価結果が最新(content_hash 一致)なら再実行しない。
|
|
956
|
+
// grade の失敗は review を止めず、結果を plan に示して review の verdict に委ねる。
|
|
957
|
+
async function gradeBeforeReviewPlan(params) {
|
|
958
|
+
const { task, projectId } = params;
|
|
959
|
+
if ((task.mode ?? "edit") !== "review" || !projectId)
|
|
960
|
+
return undefined;
|
|
961
|
+
const subject = reviewGradeSubject(params.catalogPath ?? "", task);
|
|
962
|
+
if (!subject) {
|
|
963
|
+
process.stdout.write(" [grade] skipped: grade subject is not resolvable\n");
|
|
964
|
+
return { action: "not-run", detail: "評価対象のパスを解決できない" };
|
|
965
|
+
}
|
|
966
|
+
process.stdout.write(` [grade] checking ${subject.path} (--target ${subject.target})\n`);
|
|
967
|
+
const outcome = await ensureReviewGrade({
|
|
968
|
+
taskId: qualifyTaskId(projectId, task.id),
|
|
969
|
+
projectId,
|
|
970
|
+
subjectPath: subject.path,
|
|
971
|
+
target: subject.target,
|
|
972
|
+
repoRoot: params.repoRoot,
|
|
973
|
+
dryRun: params.dryRun,
|
|
974
|
+
});
|
|
975
|
+
const summary = outcome.action === "skipped"
|
|
976
|
+
? "skipped: content_hash matches the stored grade"
|
|
977
|
+
: outcome.action === "executed"
|
|
978
|
+
? `executed: run id ${outcome.runId}`
|
|
979
|
+
: outcome.action === "failed"
|
|
980
|
+
? `failed: run id ${outcome.runId}; ${outcome.detail}`
|
|
981
|
+
: `not run: ${outcome.detail}`;
|
|
982
|
+
process.stdout.write(` [grade] ${summary}\n`);
|
|
983
|
+
return outcome;
|
|
984
|
+
}
|
|
763
985
|
async function prepareSingleTask(task, projectId, repoRoot, schedulePath, executionPath, roster, localIdToPhaseSets, phaseSetSuffixToId, agentNicknameOverride, modeAgentOverrides, stageAgentOverrides, actorOverride, dryRun, skipClaim, worktreeBase, planGenPaths, execDefaults, hasProviderCapacity, pipelineResume) {
|
|
764
986
|
const mode = task.mode ?? "edit";
|
|
765
987
|
process.stdout.write(`Task: ${task.id}${task.name ? ` — ${task.name}` : ""} [${mode}]\n`);
|
|
@@ -769,7 +991,7 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
769
991
|
}
|
|
770
992
|
// Mode-specific overrides (--edit-by / --review-by) let nightly batch runs route edit and
|
|
771
993
|
// review to different agents (e.g. local LLMs) without editing the roster. They take an agent
|
|
772
|
-
// nickname whose command is resolved from
|
|
994
|
+
// nickname whose command is resolved from agent-members.yaml; a mode without an override falls back
|
|
773
995
|
// to normal auto-selection.
|
|
774
996
|
const overrideResolution = resolveAgentOverride(mode, task.agent_pipeline
|
|
775
997
|
? (stageAgentOverrides.executor ?? agentNicknameOverride ?? pinnedExecutor(task))
|
|
@@ -861,6 +1083,13 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
861
1083
|
return "failure";
|
|
862
1084
|
}
|
|
863
1085
|
}
|
|
1086
|
+
const reviewGradeOutcome = await gradeBeforeReviewPlan({
|
|
1087
|
+
task,
|
|
1088
|
+
projectId,
|
|
1089
|
+
catalogPath: planGenPaths.catalogPath,
|
|
1090
|
+
repoRoot,
|
|
1091
|
+
dryRun,
|
|
1092
|
+
});
|
|
864
1093
|
// Plans are generated on demand here; `exec refresh` does not manage them.
|
|
865
1094
|
await generateSinglePlan({
|
|
866
1095
|
executionPath,
|
|
@@ -870,6 +1099,7 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
870
1099
|
viewpointsPath: planGenPaths.viewpointsPath,
|
|
871
1100
|
projectContext: planGenPaths.projectContext,
|
|
872
1101
|
task,
|
|
1102
|
+
...(reviewGradeOutcome ? { reviewGradeOutcome } : {}),
|
|
873
1103
|
});
|
|
874
1104
|
const planPrompt = loadPrompt(executionPath, task.id);
|
|
875
1105
|
if (!planPrompt) {
|
|
@@ -884,14 +1114,20 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
884
1114
|
: undefined;
|
|
885
1115
|
const worktreeTaskId = qualifyTaskId(projectId, task.id);
|
|
886
1116
|
const worktreeName = worktreeNameFromTaskId(worktreeTaskId);
|
|
1117
|
+
// PJR-98G4: repos を宣言した project では <base>/<task>/project/ と <base>/<task>/<repo>/ を作る。
|
|
1118
|
+
const products = configuredProductRepos(schedulePath);
|
|
887
1119
|
if (dryRun) {
|
|
888
1120
|
const worktree = {
|
|
889
|
-
path:
|
|
1121
|
+
path: plannedProjectWorktreePath(worktreeBase, worktreeTaskId, products),
|
|
890
1122
|
branch: `exec/${worktreeName}`,
|
|
891
1123
|
name: worktreeName,
|
|
892
1124
|
created: false,
|
|
893
1125
|
};
|
|
894
1126
|
process.stdout.write(` [run] would setup: worktree ${worktree.path} (${worktree.branch})\n`);
|
|
1127
|
+
for (const product of products) {
|
|
1128
|
+
process.stdout.write(` [run] would setup: worktree ${join(worktreeBase, worktreeName, product.name)} ` +
|
|
1129
|
+
`(${worktree.branch} in ${product.repoRoot})\n`);
|
|
1130
|
+
}
|
|
895
1131
|
const claimMsg = skipClaim
|
|
896
1132
|
? ` [dry-run] already claimed: ${task.id} as ${actor} (skip claim)`
|
|
897
1133
|
: ` [dry-run] would claim: ${task.id} as ${actor}`;
|
|
@@ -924,9 +1160,6 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
924
1160
|
}
|
|
925
1161
|
const planRef = `exec/plans/${task.id}-plan.md`;
|
|
926
1162
|
const startedAt = new Date().toISOString();
|
|
927
|
-
const reviewSections = (task.mode ?? "edit") === "review"
|
|
928
|
-
? reviewResultSectionsForDeliverable(planGenPaths.catalogPath ?? "", task.local_id)
|
|
929
|
-
: undefined;
|
|
930
1163
|
const finalizeSections = task.approach === "finalize" || task.approach === "bootstrap-finalize"
|
|
931
1164
|
? finalizeResultSectionsForDeliverable(planGenPaths.catalogPath ?? "", task.local_id, task.approach)
|
|
932
1165
|
: undefined;
|
|
@@ -941,7 +1174,6 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
941
1174
|
startedAt,
|
|
942
1175
|
...(task.approach ? { approach: task.approach } : {}),
|
|
943
1176
|
...(targets ? { targets } : {}),
|
|
944
|
-
...(reviewSections ? { reviewSections } : {}),
|
|
945
1177
|
...(finalizeSections ? { finalizeSections } : {}),
|
|
946
1178
|
});
|
|
947
1179
|
// Keep the execution checkpoint visible at root, but commit it only on the exec branch. The
|
|
@@ -959,6 +1191,7 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
959
1191
|
const discarded = discardStaleExecWorktree({
|
|
960
1192
|
context: { repoRoot, schedulePath, executionPath },
|
|
961
1193
|
worktreeTaskId,
|
|
1194
|
+
products,
|
|
962
1195
|
});
|
|
963
1196
|
if (discarded) {
|
|
964
1197
|
process.stdout.write(` [run] discarded stale worktree/branch: ${discarded}\n`);
|
|
@@ -969,6 +1202,15 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
969
1202
|
resultPath,
|
|
970
1203
|
claimEventPath,
|
|
971
1204
|
];
|
|
1205
|
+
const checkpointFailureLogPath = pipelineRunId
|
|
1206
|
+
? integrateLogPath(pipelineStateLocation({
|
|
1207
|
+
repoRoot,
|
|
1208
|
+
worktreePath: repoRoot,
|
|
1209
|
+
executionPath,
|
|
1210
|
+
taskId: task.id,
|
|
1211
|
+
runId: pipelineRunId,
|
|
1212
|
+
}).path)
|
|
1213
|
+
: undefined;
|
|
972
1214
|
let worktree;
|
|
973
1215
|
try {
|
|
974
1216
|
worktree = checkpointAndEnsureWorktree({
|
|
@@ -977,6 +1219,8 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
977
1219
|
base: worktreeBase,
|
|
978
1220
|
checkpointPaths,
|
|
979
1221
|
commitMessage: `exec(${task.id}): prepare execution`,
|
|
1222
|
+
products,
|
|
1223
|
+
failureLogPath: checkpointFailureLogPath,
|
|
980
1224
|
});
|
|
981
1225
|
}
|
|
982
1226
|
catch (error) {
|
|
@@ -991,6 +1235,7 @@ async function prepareSingleTask(task, projectId, repoRoot, schedulePath, execut
|
|
|
991
1235
|
}
|
|
992
1236
|
const setupAction = worktree.created ? "setup" : "reuse";
|
|
993
1237
|
process.stdout.write(` [run] ${setupAction}: worktree ${worktree.path} (${worktree.branch})\n`);
|
|
1238
|
+
reportProductWorktrees(worktree);
|
|
994
1239
|
return {
|
|
995
1240
|
task,
|
|
996
1241
|
actor,
|
|
@@ -1072,7 +1317,7 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1072
1317
|
let resumeIntegration = false;
|
|
1073
1318
|
if (!prepared.pipelineRunId) {
|
|
1074
1319
|
process.stdout.write(` Running: ${prepared.agentCandidates[0]?.command ?? ""}\n`);
|
|
1075
|
-
const outcome = await runWithRetry(prepared.agentCandidates, prepared.prompt, execDefaults, prepared.worktree.path, agentEnvironment(repoRoot, prepared.worktree.path, schedulePath, executionPath), worktreeResultPath);
|
|
1320
|
+
const outcome = await runWithRetry(prepared.agentCandidates, withProductRepoPrompt(prepared.prompt, prepared.worktree.repos), execDefaults, prepared.worktree.path, agentEnvironment(repoRoot, prepared.worktree.path, schedulePath, executionPath, prepared.worktree.repos), worktreeResultPath);
|
|
1076
1321
|
result = outcome.result;
|
|
1077
1322
|
stderr = outcome.stderr;
|
|
1078
1323
|
exitCode = outcome.exitCode;
|
|
@@ -1110,6 +1355,7 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1110
1355
|
executorEvidence = await refreshParentValidationsForReporterResume({
|
|
1111
1356
|
execDefaults,
|
|
1112
1357
|
cwd: prepared.worktree.path,
|
|
1358
|
+
productWorktrees: prepared.worktree.repos,
|
|
1113
1359
|
evidence: executorEvidence,
|
|
1114
1360
|
evidencePath: executorEvidencePath,
|
|
1115
1361
|
});
|
|
@@ -1159,7 +1405,13 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1159
1405
|
}, executorStartedAt);
|
|
1160
1406
|
writePipelineState(pipelineStatePath, pipelineState);
|
|
1161
1407
|
process.stdout.write(` Running executor: ${prepared.agentCandidates[0]?.command ?? ""}\n`);
|
|
1162
|
-
const
|
|
1408
|
+
const executorPrompt = prepared.pipelineResumeStage === "executor"
|
|
1409
|
+
? buildExecutorPrompt(prepared.plan, execDefaults.pipeline?.parent_validations, {
|
|
1410
|
+
resumed: true,
|
|
1411
|
+
existingChanges: worktreeStatusPaths(prepared.worktree.path),
|
|
1412
|
+
})
|
|
1413
|
+
: prepared.prompt;
|
|
1414
|
+
const executorOutcome = await runWithRetry(prepared.agentCandidates, withProductRepoPrompt(executorPrompt, prepared.worktree.repos), execDefaults, prepared.worktree.path, agentEnvironment(repoRoot, prepared.worktree.path, schedulePath, executionPath, prepared.worktree.repos), worktreeResultPath);
|
|
1163
1415
|
result = executorOutcome.result;
|
|
1164
1416
|
stderr = executorOutcome.stderr;
|
|
1165
1417
|
exitCode = executorOutcome.exitCode;
|
|
@@ -1180,12 +1432,26 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1180
1432
|
attempts,
|
|
1181
1433
|
stdout,
|
|
1182
1434
|
stderr,
|
|
1435
|
+
productWorktrees: prepared.worktree.repos,
|
|
1183
1436
|
});
|
|
1184
1437
|
executorEvidenceRef = relative(prepared.worktree.path, recorded.evidencePath)
|
|
1185
1438
|
.split(sep)
|
|
1186
1439
|
.join("/");
|
|
1187
1440
|
executorEvidencePath = recorded.evidencePath;
|
|
1188
1441
|
executorEvidence = recorded.evidence;
|
|
1442
|
+
const coverageFailure = result === "success"
|
|
1443
|
+
? resumedTargetCoverageFailure({
|
|
1444
|
+
resumed: prepared.pipelineResumeStage === "executor",
|
|
1445
|
+
plan: prepared.plan,
|
|
1446
|
+
evidence: executorEvidence,
|
|
1447
|
+
evidencePath: executorEvidencePath,
|
|
1448
|
+
})
|
|
1449
|
+
: undefined;
|
|
1450
|
+
if (result === "success" && coverageFailure) {
|
|
1451
|
+
result = "failure";
|
|
1452
|
+
stderr = coverageFailure;
|
|
1453
|
+
pipelineBlockReason = coverageFailure;
|
|
1454
|
+
}
|
|
1189
1455
|
const executorCompletedAt = new Date().toISOString();
|
|
1190
1456
|
pipelineState = updatePipelineStage(pipelineState, "executor", {
|
|
1191
1457
|
status: result === "success"
|
|
@@ -1205,6 +1471,7 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1205
1471
|
executorEvidence = await appendParentValidationsToExecutorEvidence({
|
|
1206
1472
|
execDefaults,
|
|
1207
1473
|
cwd: prepared.worktree.path,
|
|
1474
|
+
productWorktrees: prepared.worktree.repos,
|
|
1208
1475
|
evidence: executorEvidence,
|
|
1209
1476
|
evidencePath: executorEvidencePath,
|
|
1210
1477
|
});
|
|
@@ -1222,6 +1489,12 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1222
1489
|
stderr = pipelineBlockReason;
|
|
1223
1490
|
}
|
|
1224
1491
|
else {
|
|
1492
|
+
const reporterEvidence = evidenceForReporter(executorEvidence, {
|
|
1493
|
+
repoRoot,
|
|
1494
|
+
worktreePath: prepared.worktree.path,
|
|
1495
|
+
executionPath,
|
|
1496
|
+
resultPath: worktreeResultPath,
|
|
1497
|
+
});
|
|
1225
1498
|
const reporterStartedAt = new Date().toISOString();
|
|
1226
1499
|
pipelineState = updatePipelineStage(pipelineState, "reporter", {
|
|
1227
1500
|
status: "running",
|
|
@@ -1233,10 +1506,10 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1233
1506
|
process.stdout.write(` Running reporter: ${prepared.reporterCandidates[0].command}\n`);
|
|
1234
1507
|
const reporter = await runReporterWithFormatRetry({
|
|
1235
1508
|
plan: prepared.plan,
|
|
1236
|
-
evidence:
|
|
1509
|
+
evidence: reporterEvidence,
|
|
1237
1510
|
mode: prepared.task.mode ?? "edit",
|
|
1238
1511
|
invoke: async (reporterPrompt) => {
|
|
1239
|
-
const outcome = await runWithRetry(prepared.reporterCandidates ?? [], reporterPrompt, execDefaults, prepared.worktree.path, agentEnvironment(repoRoot, prepared.worktree.path, schedulePath, executionPath), worktreeResultPath);
|
|
1512
|
+
const outcome = await runWithRetry(prepared.reporterCandidates ?? [], reporterPrompt, execDefaults, prepared.worktree.path, agentEnvironment(repoRoot, prepared.worktree.path, schedulePath, executionPath, prepared.worktree.repos), worktreeResultPath);
|
|
1240
1513
|
reporterAttempts += outcome.attempts;
|
|
1241
1514
|
if (outcome.limit)
|
|
1242
1515
|
reporterLimit = outcome.limit;
|
|
@@ -1245,20 +1518,14 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1245
1518
|
});
|
|
1246
1519
|
if (reporter.result === "success") {
|
|
1247
1520
|
try {
|
|
1248
|
-
await renderReporterResult(worktreeResultPath, reporter.output);
|
|
1249
|
-
const
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
if (
|
|
1255
|
-
|
|
1256
|
-
stderr = reporter.output.block_reason;
|
|
1257
|
-
}
|
|
1258
|
-
else if (parentValidationFailure) {
|
|
1259
|
-
pipelineBlockReason = parentValidationFailure;
|
|
1260
|
-
stderr = parentValidationFailure;
|
|
1261
|
-
}
|
|
1521
|
+
await renderReporterResult(worktreeResultPath, reporter.output, reporterEvidence);
|
|
1522
|
+
const facts = deriveReporterFacts(reporterEvidence, {
|
|
1523
|
+
mode: prepared.task.mode ?? "edit",
|
|
1524
|
+
});
|
|
1525
|
+
result = facts.outcome === "complete" ? "success" : "failure";
|
|
1526
|
+
pipelineBlockReason = facts.block_reason || undefined;
|
|
1527
|
+
if (pipelineBlockReason)
|
|
1528
|
+
stderr = pipelineBlockReason;
|
|
1262
1529
|
process.stdout.write(` Reporter complete: ${prepared.reporterCandidates[0].actor ?? "reporter"} (format attempts: ${reporter.formatAttempts})\n`);
|
|
1263
1530
|
if (result === "success") {
|
|
1264
1531
|
const reporterCompletedAt = new Date().toISOString();
|
|
@@ -1365,8 +1632,8 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1365
1632
|
}
|
|
1366
1633
|
else {
|
|
1367
1634
|
// Record completion and integration start before the first commit. The succeeded state
|
|
1368
|
-
// is committed on the exec branch before
|
|
1369
|
-
// durable integrate checkpoint after
|
|
1635
|
+
// is committed on the project exec branch before its merge, so successful runs retain a
|
|
1636
|
+
// durable integrate checkpoint after all worktrees are removed.
|
|
1370
1637
|
if (worktreeResultPath)
|
|
1371
1638
|
await updateResultStatus(worktreeResultPath, "complete", completedAt);
|
|
1372
1639
|
const integrateStartedAt = new Date().toISOString();
|
|
@@ -1377,32 +1644,78 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1377
1644
|
started_at: integrateStartedAt,
|
|
1378
1645
|
completed_at: null,
|
|
1379
1646
|
}));
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
})
|
|
1647
|
+
const mergeMessage = commitSubject(`exec(${prepared.task.id}): `, prepared.task.name?.trim() || "apply task changes");
|
|
1648
|
+
const productNames = (prepared.worktree.repos ?? []).map((product) => product.name);
|
|
1649
|
+
try {
|
|
1650
|
+
const productOutcomes = commitProductWorktrees({
|
|
1651
|
+
worktree: prepared.worktree,
|
|
1652
|
+
message: mergeMessage,
|
|
1653
|
+
targets: taskTargetsAtHead(context, prepared.worktree, prepared.task.id),
|
|
1654
|
+
scopeLogPath: integrateLogPath(pipelineStatePath),
|
|
1655
|
+
failureLogPath: integrateLogPath(pipelineStatePath),
|
|
1656
|
+
resultPath: worktreeResultPath,
|
|
1657
|
+
});
|
|
1658
|
+
const productRootNewFiles = productOutcomes.flatMap((outcome) => outcome.rootNewFiles.map((path) => `${outcome.repo}:${path}`));
|
|
1391
1659
|
commitWorktreeChanges({
|
|
1392
1660
|
context,
|
|
1393
1661
|
worktree: prepared.worktree,
|
|
1394
1662
|
taskId: prepared.task.id,
|
|
1663
|
+
scopeLogPath: integrateLogPath(pipelineStatePath),
|
|
1664
|
+
failureLogPath: integrateLogPath(pipelineStatePath),
|
|
1665
|
+
productsIntegratedByCaller: true,
|
|
1666
|
+
productRootNewFiles,
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
catch (error) {
|
|
1670
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1671
|
+
const repo = productNames.find((name) => message.startsWith(`${name}:`)) ?? PROJECT_REPO_NAME;
|
|
1672
|
+
recordRepoIntegration(pipelineStatePath, repo, {
|
|
1673
|
+
status: "failed",
|
|
1674
|
+
error: message,
|
|
1675
|
+
});
|
|
1676
|
+
throw new RepoIntegrationError({
|
|
1677
|
+
repo,
|
|
1678
|
+
cause: message,
|
|
1679
|
+
integrated: [],
|
|
1680
|
+
pending: [...productNames, PROJECT_REPO_NAME],
|
|
1395
1681
|
});
|
|
1396
1682
|
}
|
|
1397
|
-
|
|
1398
|
-
// names the task; the prepare/apply commits stay on the exec branch.
|
|
1399
|
-
mergeWorktreeIntoCurrent({
|
|
1400
|
-
context,
|
|
1683
|
+
integrateTaskRepositories({
|
|
1401
1684
|
worktree: prepared.worktree,
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1685
|
+
mergeMessage,
|
|
1686
|
+
checkProject: () => projectMergeBlockers({
|
|
1687
|
+
context,
|
|
1688
|
+
worktree: prepared.worktree,
|
|
1689
|
+
taskId: prepared.task.id,
|
|
1690
|
+
releasePaths: prepared.checkpointPaths,
|
|
1691
|
+
}),
|
|
1692
|
+
beforeProjectMerge: () => {
|
|
1693
|
+
if (!pipelineStatePath)
|
|
1694
|
+
return;
|
|
1695
|
+
const integrateCompletedAt = new Date().toISOString();
|
|
1696
|
+
recordIntegrateStage(pipelineStatePath, integrateCompletedAt, () => ({
|
|
1697
|
+
status: "succeeded",
|
|
1698
|
+
completed_at: integrateCompletedAt,
|
|
1699
|
+
}));
|
|
1700
|
+
commitWorktreeChanges({
|
|
1701
|
+
context,
|
|
1702
|
+
worktree: prepared.worktree,
|
|
1703
|
+
taskId: prepared.task.id,
|
|
1704
|
+
failureLogPath: integrateLogPath(pipelineStatePath),
|
|
1705
|
+
productsIntegratedByCaller: true,
|
|
1706
|
+
});
|
|
1707
|
+
},
|
|
1708
|
+
mergeProject: () => mergeWorktreeIntoCurrent({
|
|
1709
|
+
context,
|
|
1710
|
+
worktree: prepared.worktree,
|
|
1711
|
+
taskId: prepared.task.id,
|
|
1712
|
+
message: mergeMessage,
|
|
1713
|
+
releaseRootPaths: prepared.checkpointPaths,
|
|
1714
|
+
failureLogPath: integrateLogPath(pipelineStatePath),
|
|
1715
|
+
}),
|
|
1716
|
+
record: (repo, patch) => recordRepoIntegration(pipelineStatePath, repo, patch),
|
|
1405
1717
|
failureLogPath: integrateLogPath(pipelineStatePath),
|
|
1718
|
+
lockPath: schedulePath,
|
|
1406
1719
|
});
|
|
1407
1720
|
}
|
|
1408
1721
|
removeWorktree({
|
|
@@ -1454,9 +1767,11 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1454
1767
|
if (worktreeResultPath)
|
|
1455
1768
|
await updateResultStatus(worktreeResultPath, "blocked", completedAt, reason);
|
|
1456
1769
|
spawnBlock(projectId, prepared.task.id, prepared.actor, reason, activeLimit
|
|
1457
|
-
?
|
|
1458
|
-
|
|
1459
|
-
|
|
1770
|
+
? {
|
|
1771
|
+
...limitEventMeta(activeLimit, {
|
|
1772
|
+
attempts: totalAttempts,
|
|
1773
|
+
worktree: prepared.worktree.path,
|
|
1774
|
+
}),
|
|
1460
1775
|
...(prepared.pipelineRunId
|
|
1461
1776
|
? pipelineRecoveryMeta({
|
|
1462
1777
|
stage: pipelineFailureStage,
|
|
@@ -1465,7 +1780,7 @@ async function runPreparedTask(prepared, projectId, repoRoot, schedulePath, exec
|
|
|
1465
1780
|
runId: pipelineState?.run_id ?? prepared.pipelineRunId,
|
|
1466
1781
|
})
|
|
1467
1782
|
: {}),
|
|
1468
|
-
}
|
|
1783
|
+
}
|
|
1469
1784
|
: {
|
|
1470
1785
|
limit_deferred: "false",
|
|
1471
1786
|
...(prepared.pipelineRunId
|
|
@@ -1927,6 +2242,44 @@ export function resolveInPlaceCommand(task, roster, opts, execDefaults = {}) {
|
|
|
1927
2242
|
...(candidate.provider ? { provider: candidate.provider } : {}),
|
|
1928
2243
|
};
|
|
1929
2244
|
}
|
|
2245
|
+
// Default two-stage pipeline for in-place runs whose task has no schedule definition (a
|
|
2246
|
+
// bring-your-own --plan or --deliverable). Stage requirements are left open so explicit
|
|
2247
|
+
// --executor-by / --reporter-by nicknames (or stage_role-based auto selection) decide the agents.
|
|
2248
|
+
const DEFAULT_IN_PLACE_AGENT_PIPELINE = {
|
|
2249
|
+
stages: [{ stage_role: "executor" }, { stage_role: "reporter" }],
|
|
2250
|
+
};
|
|
2251
|
+
// Decide whether an in-place run without a schedule-defined task (--plan / --deliverable) uses
|
|
2252
|
+
// the executor/reporter pipeline. --executor-by / --reporter-by opt in to the pipeline. A --by
|
|
2253
|
+
// nickname that names a pipeline stage agent is rejected as a configuration error: an executor
|
|
2254
|
+
// stage agent never writes the result, so a single-agent run would always end with an unfilled
|
|
2255
|
+
// result instead of a meaningful outcome.
|
|
2256
|
+
export function resolveInPlaceAgentPipeline(task, roster, opts, source) {
|
|
2257
|
+
if (task?.agent_pipeline)
|
|
2258
|
+
return task.agent_pipeline;
|
|
2259
|
+
const flag = source === "plan" ? "--plan" : "--deliverable";
|
|
2260
|
+
if (opts.executorBy || opts.reporterBy) {
|
|
2261
|
+
if (opts.by) {
|
|
2262
|
+
throw new Error("--by cannot be combined with --executor-by / --reporter-by.");
|
|
2263
|
+
}
|
|
2264
|
+
if (!task) {
|
|
2265
|
+
throw new Error(`${flag} pipeline execution requires a plan with task_id in its frontmatter (the reporter fills the scaffolded result).`);
|
|
2266
|
+
}
|
|
2267
|
+
return DEFAULT_IN_PLACE_AGENT_PIPELINE;
|
|
2268
|
+
}
|
|
2269
|
+
const by = opts.by?.trim();
|
|
2270
|
+
if (!by)
|
|
2271
|
+
return undefined;
|
|
2272
|
+
const member = roster?.members.find((m) => m.type === "agent" && m.nickname === by);
|
|
2273
|
+
if (member?.stage_role === "executor") {
|
|
2274
|
+
throw new Error(`--by ${by} is a pipeline executor agent (stage_role: executor) and does not write the result. ` +
|
|
2275
|
+
`Run ${flag} with --executor-by ${by} --reporter-by <reporter> instead.`);
|
|
2276
|
+
}
|
|
2277
|
+
if (member?.stage_role === "reporter") {
|
|
2278
|
+
throw new Error(`--by ${by} is a pipeline reporter agent (stage_role: reporter) and cannot run a plan by itself. ` +
|
|
2279
|
+
`Run ${flag} with --executor-by <executor> --reporter-by ${by} instead.`);
|
|
2280
|
+
}
|
|
2281
|
+
return undefined;
|
|
2282
|
+
}
|
|
1930
2283
|
async function spawnAgentInPlace(command, prompt, cwd, schedulePath, executionPath, resultPath) {
|
|
1931
2284
|
const protectedConfigBefore = captureAgentProtectedConfigSnapshot(cwd);
|
|
1932
2285
|
const gitStateBefore = captureAgentGitStateSnapshot(cwd);
|
|
@@ -2051,6 +2404,14 @@ async function runInPlaceMode(opts) {
|
|
|
2051
2404
|
critical_first_rank: 0,
|
|
2052
2405
|
};
|
|
2053
2406
|
}
|
|
2407
|
+
// --plan / --deliverable tasks carry no schedule-defined agent_pipeline. Opt in to the
|
|
2408
|
+
// executor/reporter pipeline via --executor-by / --reporter-by, and reject a pipeline stage
|
|
2409
|
+
// agent passed to --by before it runs (it would leave the result unfilled).
|
|
2410
|
+
if (!opts.task) {
|
|
2411
|
+
const pipeline = resolveInPlaceAgentPipeline(task, roster, opts, opts.plan ? "plan" : "deliverable");
|
|
2412
|
+
if (pipeline && task)
|
|
2413
|
+
task.agent_pipeline = pipeline;
|
|
2414
|
+
}
|
|
2054
2415
|
const { command, actor, provider } = resolveInPlaceCommand(task, roster, opts, execDefaults);
|
|
2055
2416
|
const reporterCandidates = task?.agent_pipeline && task
|
|
2056
2417
|
? resolveReporterAgentCandidates(task, roster, execDefaults, undefined, opts.reporterBy ?? pinnedReporter(task))
|
|
@@ -2074,6 +2435,13 @@ async function runInPlaceMode(opts) {
|
|
|
2074
2435
|
// Generate the plan on demand (skip for bring-your-own --plan).
|
|
2075
2436
|
const generatedPlan = !opts.plan;
|
|
2076
2437
|
if (opts.task && task) {
|
|
2438
|
+
const reviewGradeOutcome = await gradeBeforeReviewPlan({
|
|
2439
|
+
task,
|
|
2440
|
+
projectId,
|
|
2441
|
+
catalogPath,
|
|
2442
|
+
repoRoot,
|
|
2443
|
+
dryRun: false,
|
|
2444
|
+
});
|
|
2077
2445
|
await generateSinglePlan({
|
|
2078
2446
|
executionPath,
|
|
2079
2447
|
projectId,
|
|
@@ -2083,6 +2451,7 @@ async function runInPlaceMode(opts) {
|
|
|
2083
2451
|
projectContext,
|
|
2084
2452
|
task,
|
|
2085
2453
|
...(stem ? { stem } : {}),
|
|
2454
|
+
...(reviewGradeOutcome ? { reviewGradeOutcome } : {}),
|
|
2086
2455
|
});
|
|
2087
2456
|
}
|
|
2088
2457
|
else if (target) {
|
|
@@ -2114,9 +2483,6 @@ async function runInPlaceMode(opts) {
|
|
|
2114
2483
|
let resultPath;
|
|
2115
2484
|
let resultScaffold;
|
|
2116
2485
|
if (task && slug) {
|
|
2117
|
-
const reviewSections = (task.mode ?? "edit") === "review"
|
|
2118
|
-
? reviewResultSectionsForDeliverable(catalogPath ?? "", task.local_id)
|
|
2119
|
-
: undefined;
|
|
2120
2486
|
const finalizeSections = task.approach === "finalize" || task.approach === "bootstrap-finalize"
|
|
2121
2487
|
? finalizeResultSectionsForDeliverable(catalogPath ?? "", task.local_id, task.approach)
|
|
2122
2488
|
: undefined;
|
|
@@ -2133,7 +2499,6 @@ async function runInPlaceMode(opts) {
|
|
|
2133
2499
|
...(stem ? { stem } : {}),
|
|
2134
2500
|
...(task.approach ? { approach: task.approach } : {}),
|
|
2135
2501
|
...(targets ? { targets } : {}),
|
|
2136
|
-
...(reviewSections ? { reviewSections } : {}),
|
|
2137
2502
|
...(finalizeSections ? { finalizeSections } : {}),
|
|
2138
2503
|
})).resultPath;
|
|
2139
2504
|
resultScaffold = readResultFrontmatterSnapshot(resultPath);
|
|
@@ -2215,6 +2580,12 @@ async function runInPlaceMode(opts) {
|
|
|
2215
2580
|
}
|
|
2216
2581
|
if (outcome.result === "success") {
|
|
2217
2582
|
pipelineFailureStage = "reporter";
|
|
2583
|
+
const reporterEvidence = evidenceForReporter(recorded.evidence, {
|
|
2584
|
+
repoRoot,
|
|
2585
|
+
worktreePath: repoRoot,
|
|
2586
|
+
executionPath,
|
|
2587
|
+
...(resultPath ? { resultPath } : {}),
|
|
2588
|
+
});
|
|
2218
2589
|
const reporterStartedAt = new Date().toISOString();
|
|
2219
2590
|
pipelineState = updatePipelineStage(pipelineState, "reporter", {
|
|
2220
2591
|
status: "running",
|
|
@@ -2226,7 +2597,7 @@ async function runInPlaceMode(opts) {
|
|
|
2226
2597
|
process.stdout.write(`Running reporter: ${reporterCandidates?.[0]?.command ?? ""}\n`);
|
|
2227
2598
|
const reporter = await runReporterWithFormatRetry({
|
|
2228
2599
|
plan: planPrompt,
|
|
2229
|
-
evidence:
|
|
2600
|
+
evidence: reporterEvidence,
|
|
2230
2601
|
mode: task.mode ?? "edit",
|
|
2231
2602
|
invoke: async (reporterPrompt) => {
|
|
2232
2603
|
const reporterOutcome = await runWithRetry(reporterCandidates ?? [], reporterPrompt, execDefaults, repoRoot, {
|
|
@@ -2244,13 +2615,10 @@ async function runInPlaceMode(opts) {
|
|
|
2244
2615
|
});
|
|
2245
2616
|
if (reporter.result === "success" && resultPath) {
|
|
2246
2617
|
try {
|
|
2247
|
-
await renderReporterResult(resultPath, reporter.output);
|
|
2248
|
-
const
|
|
2249
|
-
exitCode =
|
|
2250
|
-
pipelineBlockReason =
|
|
2251
|
-
reporter.output.outcome === "blocked"
|
|
2252
|
-
? reporter.output.block_reason
|
|
2253
|
-
: parentValidationFailure;
|
|
2618
|
+
await renderReporterResult(resultPath, reporter.output, reporterEvidence);
|
|
2619
|
+
const facts = deriveReporterFacts(reporterEvidence, { mode: task.mode ?? "edit" });
|
|
2620
|
+
exitCode = facts.outcome === "complete" ? 0 : 1;
|
|
2621
|
+
pipelineBlockReason = facts.block_reason || undefined;
|
|
2254
2622
|
process.stdout.write(`Reporter complete: ${reporterCandidates?.[0]?.actor ?? "reporter"} (format attempts: ${reporter.formatAttempts})\n`);
|
|
2255
2623
|
}
|
|
2256
2624
|
catch (error) {
|
|
@@ -2433,6 +2801,12 @@ async function runCommandJobMode(params) {
|
|
|
2433
2801
|
process.stdout.write(`Command evidence: ${evidenceRef}\n`);
|
|
2434
2802
|
const commandSucceeded = commandOutcome.exitCode === 0 && !commandOutcome.error;
|
|
2435
2803
|
if (!commandSucceeded || !analysisCandidate) {
|
|
2804
|
+
const reporterEvidence = evidenceForReporter(recorded.evidence, {
|
|
2805
|
+
repoRoot,
|
|
2806
|
+
worktreePath: repoRoot,
|
|
2807
|
+
executionPath,
|
|
2808
|
+
resultPath,
|
|
2809
|
+
});
|
|
2436
2810
|
const reason = commandSucceeded
|
|
2437
2811
|
? undefined
|
|
2438
2812
|
: commandOutcome.error
|
|
@@ -2441,20 +2815,18 @@ async function runCommandJobMode(params) {
|
|
|
2441
2815
|
await renderReporterResult(resultPath, {
|
|
2442
2816
|
schema_version: 1,
|
|
2443
2817
|
mode: "edit",
|
|
2444
|
-
outcome: commandSucceeded ? "complete" : "blocked",
|
|
2445
2818
|
summary: [
|
|
2446
2819
|
commandSucceeded
|
|
2447
2820
|
? "runner が解決済みコマンドを直接実行し、終了コード 0 を確認した。"
|
|
2448
2821
|
: `runner が解決済みコマンドを直接実行したが、${reason}。`,
|
|
2449
2822
|
],
|
|
2450
|
-
changed_files:
|
|
2451
|
-
path
|
|
2823
|
+
changed_files: reporterEvidence.changes.map(({ path }) => ({
|
|
2824
|
+
path,
|
|
2452
2825
|
summary: "runner command の実行後に検出した変更",
|
|
2453
2826
|
})),
|
|
2454
2827
|
handoff: [`command evidence: ${evidenceRef}`],
|
|
2455
2828
|
approach: "Job Definition から materialize したコマンドを agent の解釈を介さず実行し、runner evidence を正本とした。",
|
|
2456
|
-
|
|
2457
|
-
});
|
|
2829
|
+
}, reporterEvidence);
|
|
2458
2830
|
await updateResultStatus(resultPath, commandSucceeded ? "complete" : "blocked", new Date().toISOString(), reason);
|
|
2459
2831
|
completeJobRun({
|
|
2460
2832
|
projectId,
|
|
@@ -2531,9 +2903,374 @@ async function runCommandJobMode(params) {
|
|
|
2531
2903
|
process.exitCode = 1;
|
|
2532
2904
|
}
|
|
2533
2905
|
}
|
|
2906
|
+
const ACCEPTED_JOB_REVIEW_VERDICTS = new Set(["complete", "complete-with-findings"]);
|
|
2907
|
+
function jobChildArgs(opts, projectId, scheduledAt) {
|
|
2908
|
+
const args = ["exec", "run", "--job", String(opts.job), "--project", projectId];
|
|
2909
|
+
const inputs = Array.isArray(opts.input) ? opts.input : opts.input ? [opts.input] : [];
|
|
2910
|
+
for (const input of inputs)
|
|
2911
|
+
args.push("--input", input);
|
|
2912
|
+
args.push("--scheduled-at", scheduledAt);
|
|
2913
|
+
if (opts.jobTrigger)
|
|
2914
|
+
args.push("--job-trigger", opts.jobTrigger);
|
|
2915
|
+
if (opts.by)
|
|
2916
|
+
args.push("--by", opts.by);
|
|
2917
|
+
if (opts.reporterBy)
|
|
2918
|
+
args.push("--reporter-by", opts.reporterBy);
|
|
2919
|
+
if (opts.execDefaults)
|
|
2920
|
+
args.push("--exec-defaults", opts.execDefaults);
|
|
2921
|
+
return args;
|
|
2922
|
+
}
|
|
2923
|
+
function commitJobPaths(worktreePath, paths, subject, body) {
|
|
2924
|
+
const unique = [...new Set(paths)].sort();
|
|
2925
|
+
if (unique.length === 0)
|
|
2926
|
+
throw new Error("Job Run produced no tracked output to commit.");
|
|
2927
|
+
stageCommitTargets(worktreePath, unique);
|
|
2928
|
+
const staged = gitResult(worktreePath, ["diff", "--cached", "--quiet", "--", ...unique]);
|
|
2929
|
+
if (staged.status === 0)
|
|
2930
|
+
throw new Error("Job Run output has no staged changes.");
|
|
2931
|
+
if (staged.status !== 1)
|
|
2932
|
+
throw new Error("Failed to inspect staged Job Run output.");
|
|
2933
|
+
const commit = gitResult(worktreePath, ["commit", "-m", subject, "-m", body, "--", ...unique]);
|
|
2934
|
+
if (commit.status !== 0) {
|
|
2935
|
+
const output = [commit.stdout, commit.stderr]
|
|
2936
|
+
.filter((part) => typeof part === "string" && part.length > 0)
|
|
2937
|
+
.join("\n");
|
|
2938
|
+
throw new Error(`git commit failed: ${summarizeGitHookFailure(output)}`);
|
|
2939
|
+
}
|
|
2940
|
+
stabilizeCommitTargets(worktreePath, () => worktreeStatusPaths(worktreePath).filter((path) => unique.includes(path)));
|
|
2941
|
+
return gitOutput(worktreePath, ["rev-parse", "HEAD"]).trim();
|
|
2942
|
+
}
|
|
2943
|
+
function jobReviewVerdict(resultPath) {
|
|
2944
|
+
const match = readFileSync(resultPath, "utf8").match(/^- verdict:\s*(complete|complete-with-findings|incomplete|grade-stale|grade-unavailable|changed-during-review)\s*$/m);
|
|
2945
|
+
return match?.[1];
|
|
2946
|
+
}
|
|
2947
|
+
async function fillIncompleteJobReviewResult(resultPath, reason) {
|
|
2948
|
+
const safeReason = reason.replace(/\s+/g, " ").trim();
|
|
2949
|
+
let content = readFileSync(resultPath, "utf8");
|
|
2950
|
+
content = content
|
|
2951
|
+
.replace(/_TODO_: 評価結果サイドカー[^\n]*/, `Job Run の review を完了できなかった: ${safeReason}`)
|
|
2952
|
+
.replace(/_TODO_: 変更内容[^\n]*/, `- runner が review を完了できなかったため統合不可と判断した。`)
|
|
2953
|
+
.replace(/_TODO_: 未充足事項[^\n]*/, `- ${safeReason}`)
|
|
2954
|
+
.replace(/_TODO_: `approach`[^\n]*/, "Job Run の出力は変更していない。")
|
|
2955
|
+
.replace(/- verdict: _TODO_([^\n]*)/, "- verdict: incomplete");
|
|
2956
|
+
writeFileSync(resultPath, content, "utf8");
|
|
2957
|
+
await formatMarkdownFile(resultPath);
|
|
2958
|
+
}
|
|
2959
|
+
async function overrideJobReviewDecision(resultPath, verdict, reason) {
|
|
2960
|
+
let content = readFileSync(resultPath, "utf8");
|
|
2961
|
+
content = content.replace(/^- verdict:\s*(?:complete|complete-with-findings|incomplete|grade-stale|grade-unavailable|changed-during-review)\s*$/m, `- verdict: ${verdict}`);
|
|
2962
|
+
const instruction = `- runner 判定: ${reason.replace(/\s+/g, " ").trim()}`;
|
|
2963
|
+
if (!content.includes(instruction)) {
|
|
2964
|
+
content = content.replace("\n## 4. approach に応じた確認", `\n${instruction}\n\n## 4. approach に応じた確認`);
|
|
2965
|
+
}
|
|
2966
|
+
writeFileSync(resultPath, content, "utf8");
|
|
2967
|
+
await formatMarkdownFile(resultPath);
|
|
2968
|
+
}
|
|
2969
|
+
// Child process marker for the Job executed inside the review worktree. The child must run
|
|
2970
|
+
// the Job in place; without it a Job that declares task.review would re-enter the worktree.
|
|
2971
|
+
const JOB_REVIEW_WORKTREE_CHILD_ENV = "SPECDOJO_JOB_REVIEW_WORKTREE_CHILD";
|
|
2972
|
+
function jobReviewAgentSourceLabel(nomination, cliFlag) {
|
|
2973
|
+
return nomination.source === "cli"
|
|
2974
|
+
? cliFlag
|
|
2975
|
+
: `task.review.agent.${cliFlag === "--review-by" ? "executor" : "reporter"}`;
|
|
2976
|
+
}
|
|
2977
|
+
function resolveJobReviewAgents(task, roster, execDefaults, opts, definition) {
|
|
2978
|
+
// Resolution order: --review-by / --reporter-by, then the Job's task.review.agent, then
|
|
2979
|
+
// capability based auto selection.
|
|
2980
|
+
const nominations = resolveJobReviewAgentNominations({ reviewBy: opts.reviewBy, reporterBy: opts.reporterBy }, definition);
|
|
2981
|
+
const override = resolveAgentOverride("review", nominations.executor?.nickname, {}, roster, execDefaults, "executor");
|
|
2982
|
+
if (override.kind === "error") {
|
|
2983
|
+
throw new Error(nominations.executor
|
|
2984
|
+
? override.message.replace(/^--by/, jobReviewAgentSourceLabel(nominations.executor, "--review-by"))
|
|
2985
|
+
: override.message);
|
|
2986
|
+
}
|
|
2987
|
+
let executor;
|
|
2988
|
+
if (override.kind === "command") {
|
|
2989
|
+
executor = {
|
|
2990
|
+
command: override.command,
|
|
2991
|
+
actor: override.actor ?? String(nominations.executor?.nickname),
|
|
2992
|
+
provider: override.provider,
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
else {
|
|
2996
|
+
const requirements = executorRequirements(task);
|
|
2997
|
+
const member = requirements
|
|
2998
|
+
? selectCandidates(requirements, roster, "review", undefined, execDefaults)[0]
|
|
2999
|
+
: undefined;
|
|
3000
|
+
const command = member ? resolveMemberCommand(execDefaults, member) : undefined;
|
|
3001
|
+
if (!member || !command)
|
|
3002
|
+
throw new Error("No review executor is available for Job Run review.");
|
|
3003
|
+
executor = { command, actor: member.nickname, provider: member.provider };
|
|
3004
|
+
}
|
|
3005
|
+
let reporterCandidates;
|
|
3006
|
+
try {
|
|
3007
|
+
reporterCandidates = resolveReporterAgentCandidates(task, roster, execDefaults, undefined, nominations.reporter?.nickname);
|
|
3008
|
+
}
|
|
3009
|
+
catch (error) {
|
|
3010
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3011
|
+
if (nominations.reporter?.source !== "job")
|
|
3012
|
+
throw error;
|
|
3013
|
+
throw new Error(message.replace(/^--reporter-by/, jobReviewAgentSourceLabel(nominations.reporter, "--reporter-by")), { cause: error });
|
|
3014
|
+
}
|
|
3015
|
+
if (reporterCandidates.length === 0) {
|
|
3016
|
+
throw new Error("No reporter is available for Job Run review.");
|
|
3017
|
+
}
|
|
3018
|
+
return { executor, reporterCandidates };
|
|
3019
|
+
}
|
|
3020
|
+
function jobReviewTaskView(runId, jobName) {
|
|
3021
|
+
return {
|
|
3022
|
+
id: `${runId}-review`,
|
|
3023
|
+
local_id: runId,
|
|
3024
|
+
name: `${jobName} の実行結果レビュー`,
|
|
3025
|
+
mode: "review",
|
|
3026
|
+
schedule_file: "",
|
|
3027
|
+
fifo_rank: 0,
|
|
3028
|
+
critical_first_rank: 0,
|
|
3029
|
+
agent_pipeline: {
|
|
3030
|
+
stages: [{ stage_role: "executor" }, { stage_role: "reporter" }],
|
|
3031
|
+
},
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
function describeJobReviewAgent(actor, nomination, cliFlag) {
|
|
3035
|
+
const source = nomination ? jobReviewAgentSourceLabel(nomination, cliFlag) : "auto";
|
|
3036
|
+
return `${actor ?? "(unknown)"} (${source})`;
|
|
3037
|
+
}
|
|
3038
|
+
async function runJobWorktreeMode(opts) {
|
|
3039
|
+
const resolvedPaths = resolveProjectPaths({ project: opts.project });
|
|
3040
|
+
activateResolvedProjectPaths(resolvedPaths);
|
|
3041
|
+
const { schedulePath, executionPath } = resolvedPaths;
|
|
3042
|
+
const projectId = resolvedPaths.projectId ?? opts.project ?? process.env.SPECDOJO_PROJECT ?? "";
|
|
3043
|
+
if (!projectId)
|
|
3044
|
+
throw new Error("--job requires a project id.");
|
|
3045
|
+
const trigger = opts.jobTrigger === "ci"
|
|
3046
|
+
? "ci"
|
|
3047
|
+
: process.env[ROUTINE_EXEC_ENV] === "1" || opts.jobTrigger === "routine"
|
|
3048
|
+
? "routine"
|
|
3049
|
+
: "manual";
|
|
3050
|
+
const preview = await materializeJobRun({
|
|
3051
|
+
projectId,
|
|
3052
|
+
jobId: String(opts.job).trim(),
|
|
3053
|
+
inputs: opts.input,
|
|
3054
|
+
scheduledAt: opts.scheduledAt,
|
|
3055
|
+
trigger,
|
|
3056
|
+
dryRun: true,
|
|
3057
|
+
});
|
|
3058
|
+
if (preview.duplicateComplete) {
|
|
3059
|
+
process.stdout.write(`Job Run already complete: ${preview.record.run_id} (${preview.record.state})\n`);
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
if (opts.dryRun) {
|
|
3063
|
+
process.stdout.write(`[dry-run] job worktree: ${projectId}-${preview.record.run_id}\n`);
|
|
3064
|
+
process.stdout.write(`[dry-run] job: ${preview.definition.id}\n`);
|
|
3065
|
+
process.stdout.write(`[dry-run] run: ${preview.record.run_id}\n`);
|
|
3066
|
+
process.stdout.write("[dry-run] lifecycle: execute -> commit -> review -> merge|waiting\n");
|
|
3067
|
+
process.stdout.write(`[dry-run] review declared by job: ${preview.definition.task.review ? "yes" : "no (--worktree)"}\n`);
|
|
3068
|
+
const nominations = resolveJobReviewAgentNominations({ reviewBy: opts.reviewBy, reporterBy: opts.reporterBy }, preview.definition);
|
|
3069
|
+
try {
|
|
3070
|
+
const roster = loadRosterForExecutionPath(executionPath);
|
|
3071
|
+
const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
|
|
3072
|
+
const agents = resolveJobReviewAgents(jobReviewTaskView(preview.record.run_id, preview.definition.name), roster, execDefaults, opts, preview.definition);
|
|
3073
|
+
process.stdout.write(`[dry-run] review executor: ${describeJobReviewAgent(agents.executor.actor, nominations.executor, "--review-by")}\n`);
|
|
3074
|
+
process.stdout.write(`[dry-run] review reporter: ${describeJobReviewAgent(agents.reporterCandidates[0]?.actor, nominations.reporter, "--reporter-by")}\n`);
|
|
3075
|
+
}
|
|
3076
|
+
catch (error) {
|
|
3077
|
+
process.stdout.write(`[dry-run] review agents: unresolved (${error instanceof Error ? error.message : String(error)})\n`);
|
|
3078
|
+
}
|
|
3079
|
+
return;
|
|
3080
|
+
}
|
|
3081
|
+
const repoRoot = specdojoRootDir();
|
|
3082
|
+
const baseCommit = gitOutput(repoRoot, ["rev-parse", "HEAD"]).trim();
|
|
3083
|
+
const worktreeBase = resolveWorktreeBase(repoRoot, opts.worktreeBase, configuredWorktreeBase(schedulePath));
|
|
3084
|
+
const worktreeTaskId = `${projectId}-${preview.record.run_id}`;
|
|
3085
|
+
const worktree = ensureExecWorktree({ repoRoot, worktreeBase, taskId: worktreeTaskId });
|
|
3086
|
+
// materializeJobRun resolves an omitted --scheduled-at to the manual launch time. Reuse that
|
|
3087
|
+
// exact slot in the child so the worktree writes the Job Run that the parent previewed.
|
|
3088
|
+
const childArgs = jobChildArgs(opts, projectId, preview.record.scheduled_at);
|
|
3089
|
+
const [executable, fullArgs] = selfRunArgs(childArgs);
|
|
3090
|
+
process.stdout.write(`Running Job Run ${preview.record.run_id} in ${worktree.path}.\n`);
|
|
3091
|
+
const child = spawnSync(executable, fullArgs, {
|
|
3092
|
+
cwd: worktree.path,
|
|
3093
|
+
env: {
|
|
3094
|
+
...process.env,
|
|
3095
|
+
[ROUTINE_EXEC_ENV]: trigger === "routine" ? "1" : "0",
|
|
3096
|
+
[JOB_REVIEW_WORKTREE_CHILD_ENV]: "1",
|
|
3097
|
+
},
|
|
3098
|
+
stdio: "inherit",
|
|
3099
|
+
});
|
|
3100
|
+
if (child.status === ROUTINE_BUSY_SKIP_EXIT_CODE) {
|
|
3101
|
+
removeWorktree({
|
|
3102
|
+
context: { repoRoot, schedulePath, executionPath },
|
|
3103
|
+
worktree,
|
|
3104
|
+
taskId: `${preview.record.run_id}-review`,
|
|
3105
|
+
force: true,
|
|
3106
|
+
deleteBranch: true,
|
|
3107
|
+
});
|
|
3108
|
+
process.exitCode = ROUTINE_BUSY_SKIP_EXIT_CODE;
|
|
3109
|
+
return;
|
|
3110
|
+
}
|
|
3111
|
+
const executionRel = relative(repoRoot, executionPath);
|
|
3112
|
+
const worktreeExecutionPath = resolve(worktree.path, executionRel);
|
|
3113
|
+
const worktreeJobPaths = resolveJobPaths(projectId);
|
|
3114
|
+
const runPath = resolve(worktree.path, relative(repoRoot, preview.runPath));
|
|
3115
|
+
if (!existsSync(runPath)) {
|
|
3116
|
+
throw new Error(`Job Run record was not created in worktree: ${preview.record.run_id}`);
|
|
3117
|
+
}
|
|
3118
|
+
let record = loadJobRunRecord(runPath);
|
|
3119
|
+
const outputPaths = worktreeStatusPaths(worktree.path);
|
|
3120
|
+
const outputCommit = commitJobPaths(worktree.path, outputPaths, `chore(routine): ${preview.definition.name}`, `Job Run: ${record.run_id}\nState: ${record.state}`);
|
|
3121
|
+
const reviewTaskId = `${record.run_id}-review`;
|
|
3122
|
+
const reviewTask = jobReviewTaskView(record.run_id, preview.definition.name);
|
|
3123
|
+
const { planPath, resultPath } = await generateJobReviewPlan({
|
|
3124
|
+
...worktreeJobPaths,
|
|
3125
|
+
jobsPath: resolve(worktree.path, relative(repoRoot, worktreeJobPaths.jobsPath)),
|
|
3126
|
+
executionPath: worktreeExecutionPath,
|
|
3127
|
+
runsPath: resolve(worktree.path, relative(repoRoot, worktreeJobPaths.runsPath)),
|
|
3128
|
+
statePath: resolve(worktree.path, relative(repoRoot, worktreeJobPaths.statePath)),
|
|
3129
|
+
}, preview.definition, record, { branch: worktree.branch, baseCommit, outputCommit });
|
|
3130
|
+
const rootExecDefaultsPath = resolve(repoRoot, resolveExecDefaultsPath(opts, schedulePath));
|
|
3131
|
+
const execDefaultsRelative = relative(repoRoot, rootExecDefaultsPath);
|
|
3132
|
+
const execDefaultsPath = execDefaultsRelative === ".." || execDefaultsRelative.startsWith(`..${sep}`)
|
|
3133
|
+
? rootExecDefaultsPath
|
|
3134
|
+
: resolve(worktree.path, execDefaultsRelative);
|
|
3135
|
+
const execDefaults = loadExecDefaultsConfig(execDefaultsPath, worktreeExecutionPath);
|
|
3136
|
+
const originalCwd = process.cwd();
|
|
3137
|
+
let reviewReason;
|
|
3138
|
+
let verdict;
|
|
3139
|
+
try {
|
|
3140
|
+
process.chdir(worktree.path);
|
|
3141
|
+
const roster = loadRosterForExecutionPath(worktreeExecutionPath);
|
|
3142
|
+
const agents = resolveJobReviewAgents(reviewTask, roster, execDefaults, opts, preview.definition);
|
|
3143
|
+
await scaffoldResult({
|
|
3144
|
+
executionPath: worktreeExecutionPath,
|
|
3145
|
+
taskId: reviewTaskId,
|
|
3146
|
+
mode: "review",
|
|
3147
|
+
projectId,
|
|
3148
|
+
origin: "job",
|
|
3149
|
+
jobId: record.job_id,
|
|
3150
|
+
runId: record.run_id,
|
|
3151
|
+
planRef: relative(worktree.path, planPath).split(sep).join("/"),
|
|
3152
|
+
agent: agents.executor.actor,
|
|
3153
|
+
startedAt: new Date().toISOString(),
|
|
3154
|
+
stem: reviewTaskId,
|
|
3155
|
+
});
|
|
3156
|
+
const reviewOutcome = await runAgentPipeline({
|
|
3157
|
+
repoRoot: worktree.path,
|
|
3158
|
+
cwd: worktree.path,
|
|
3159
|
+
schedulePath: resolve(worktree.path, relative(repoRoot, schedulePath)),
|
|
3160
|
+
executionPath: worktreeExecutionPath,
|
|
3161
|
+
taskId: reviewTaskId,
|
|
3162
|
+
executor: agents.executor,
|
|
3163
|
+
reporterCandidates: agents.reporterCandidates,
|
|
3164
|
+
planPath,
|
|
3165
|
+
planPrompt: expandPromptRefs(readFileSync(planPath, "utf8")),
|
|
3166
|
+
resultPath,
|
|
3167
|
+
execDefaults,
|
|
3168
|
+
mode: "review",
|
|
3169
|
+
});
|
|
3170
|
+
reviewReason = reviewOutcome.blockReason;
|
|
3171
|
+
await updateResultStatus(resultPath, reviewOutcome.exitCode === 0 ? "complete" : "blocked", new Date().toISOString(), reviewReason);
|
|
3172
|
+
verdict = reviewOutcome.exitCode === 0 ? jobReviewVerdict(resultPath) : undefined;
|
|
3173
|
+
if (!verdict && reviewOutcome.exitCode === 0)
|
|
3174
|
+
reviewReason = "review result has no verdict";
|
|
3175
|
+
}
|
|
3176
|
+
catch (error) {
|
|
3177
|
+
reviewReason = error instanceof Error ? error.message : String(error);
|
|
3178
|
+
if (!existsSync(resultPath)) {
|
|
3179
|
+
await scaffoldResult({
|
|
3180
|
+
executionPath: worktreeExecutionPath,
|
|
3181
|
+
taskId: reviewTaskId,
|
|
3182
|
+
mode: "review",
|
|
3183
|
+
projectId,
|
|
3184
|
+
origin: "job",
|
|
3185
|
+
jobId: record.job_id,
|
|
3186
|
+
runId: record.run_id,
|
|
3187
|
+
planRef: relative(worktree.path, planPath).split(sep).join("/"),
|
|
3188
|
+
agent: "specdojo-runner",
|
|
3189
|
+
startedAt: new Date().toISOString(),
|
|
3190
|
+
stem: reviewTaskId,
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
await fillIncompleteJobReviewResult(resultPath, reviewReason);
|
|
3194
|
+
await updateResultStatus(resultPath, "blocked", new Date().toISOString(), reviewReason);
|
|
3195
|
+
verdict = "incomplete";
|
|
3196
|
+
}
|
|
3197
|
+
finally {
|
|
3198
|
+
process.chdir(originalCwd);
|
|
3199
|
+
}
|
|
3200
|
+
const allowedReviewPrefixes = [
|
|
3201
|
+
`${relative(worktree.path, worktreeExecutionPath).split(sep).join("/")}/exec/evidence/${reviewTaskId}/`,
|
|
3202
|
+
];
|
|
3203
|
+
const allowedReviewFiles = new Set([
|
|
3204
|
+
relative(worktree.path, planPath).split(sep).join("/"),
|
|
3205
|
+
relative(worktree.path, resultPath).split(sep).join("/"),
|
|
3206
|
+
relative(worktree.path, runPath).split(sep).join("/"),
|
|
3207
|
+
]);
|
|
3208
|
+
const reviewChanges = worktreeStatusPaths(worktree.path);
|
|
3209
|
+
const unexpected = reviewChanges.filter((path) => !allowedReviewFiles.has(path) &&
|
|
3210
|
+
!allowedReviewPrefixes.some((prefix) => path.startsWith(prefix)));
|
|
3211
|
+
if (unexpected.length > 0) {
|
|
3212
|
+
reviewReason = `review executor changed Job output: ${unexpected.join(", ")}`;
|
|
3213
|
+
verdict = "changed-during-review";
|
|
3214
|
+
await overrideJobReviewDecision(resultPath, verdict, reviewReason);
|
|
3215
|
+
}
|
|
3216
|
+
if (unexpected.length === 0 && record.state !== "succeeded") {
|
|
3217
|
+
reviewReason = record.attempts.at(-1)?.reason ?? `Job Run state is ${record.state}`;
|
|
3218
|
+
verdict = "incomplete";
|
|
3219
|
+
await overrideJobReviewDecision(resultPath, verdict, reviewReason);
|
|
3220
|
+
}
|
|
3221
|
+
if (!reviewReason && verdict && !ACCEPTED_JOB_REVIEW_VERDICTS.has(verdict)) {
|
|
3222
|
+
reviewReason = `review verdict is ${verdict}`;
|
|
3223
|
+
}
|
|
3224
|
+
record = recordJobRunReview(runPath, {
|
|
3225
|
+
plan_ref: relative(worktree.path, planPath).split(sep).join("/"),
|
|
3226
|
+
result_ref: relative(worktree.path, resultPath).split(sep).join("/"),
|
|
3227
|
+
branch: worktree.branch,
|
|
3228
|
+
...(verdict ? { verdict: verdict } : {}),
|
|
3229
|
+
...(reviewReason ? { reason: reviewReason } : {}),
|
|
3230
|
+
});
|
|
3231
|
+
const committableReviewPaths = worktreeStatusPaths(worktree.path).filter((path) => allowedReviewFiles.has(path) ||
|
|
3232
|
+
allowedReviewPrefixes.some((prefix) => path.startsWith(prefix)));
|
|
3233
|
+
commitJobPaths(worktree.path, committableReviewPaths, `chore(routine): review ${record.run_id}`, `Job Run: ${record.run_id}\nState: ${record.state}\nVerdict: ${verdict ?? "unavailable"}`);
|
|
3234
|
+
const accepted = record.state === "succeeded" &&
|
|
3235
|
+
verdict !== undefined &&
|
|
3236
|
+
ACCEPTED_JOB_REVIEW_VERDICTS.has(verdict) &&
|
|
3237
|
+
unexpected.length === 0;
|
|
3238
|
+
if (!accepted) {
|
|
3239
|
+
const reason = record.state !== "succeeded"
|
|
3240
|
+
? `Job Run state is ${record.state}`
|
|
3241
|
+
: (reviewReason ?? `review verdict is ${verdict ?? "unavailable"}`);
|
|
3242
|
+
process.stdout.write(`[routine-job] waiting run_id=${record.run_id} review=${verdict ?? "unavailable"} worktree=${worktree.path} reason=${reason}\n`);
|
|
3243
|
+
process.exitCode = child.status || 1;
|
|
3244
|
+
return;
|
|
3245
|
+
}
|
|
3246
|
+
mergeWorktreeIntoCurrent({
|
|
3247
|
+
context: { repoRoot, schedulePath, executionPath },
|
|
3248
|
+
worktree,
|
|
3249
|
+
taskId: reviewTaskId,
|
|
3250
|
+
message: `chore(routine): merge ${record.run_id}`,
|
|
3251
|
+
});
|
|
3252
|
+
removeWorktree({
|
|
3253
|
+
context: { repoRoot, schedulePath, executionPath },
|
|
3254
|
+
worktree,
|
|
3255
|
+
taskId: reviewTaskId,
|
|
3256
|
+
deleteBranch: true,
|
|
3257
|
+
});
|
|
3258
|
+
process.stdout.write(`[routine-job] merged run_id=${record.run_id} review=${verdict} branch=${worktree.branch}\n`);
|
|
3259
|
+
}
|
|
2534
3260
|
async function runJobMode(opts) {
|
|
2535
3261
|
const resolvedPaths = resolveProjectPaths({ project: opts.project });
|
|
2536
3262
|
activateResolvedProjectPaths(resolvedPaths);
|
|
3263
|
+
const isWorktreeChild = process.env[JOB_REVIEW_WORKTREE_CHILD_ENV] === "1";
|
|
3264
|
+
if (!isWorktreeChild) {
|
|
3265
|
+
// A Job's task.review declaration takes precedence over the caller: it routes the Run
|
|
3266
|
+
// through the reviewed integration path even without --worktree (routine action.commit).
|
|
3267
|
+
const reviewProjectId = resolvedPaths.projectId ?? opts.project ?? process.env.SPECDOJO_PROJECT ?? "";
|
|
3268
|
+
const definition = loadJobDefinition(resolveJobPaths(reviewProjectId || undefined), String(opts.job).trim());
|
|
3269
|
+
if (jobRunUsesReviewedIntegration(definition, { worktree: opts.worktree, isWorktreeChild })) {
|
|
3270
|
+
await runJobWorktreeMode(opts);
|
|
3271
|
+
return;
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
2537
3274
|
const { schedulePath, executionPath } = resolvedPaths;
|
|
2538
3275
|
const projectId = resolvedPaths.projectId ?? opts.project ?? process.env.SPECDOJO_PROJECT ?? "";
|
|
2539
3276
|
if (!projectId)
|
|
@@ -2677,63 +3414,85 @@ async function runJobMode(opts) {
|
|
|
2677
3414
|
process.exitCode = effectiveExit || 1;
|
|
2678
3415
|
}
|
|
2679
3416
|
}
|
|
2680
|
-
//
|
|
2681
|
-
//
|
|
2682
|
-
//
|
|
2683
|
-
//
|
|
3417
|
+
// --register の単一 agent 実行(--by 指定時)の agent を解決する。owner(Role code)や
|
|
3418
|
+
// role からの自動選択は行わない(PJR-ADZ6)。agent は全員 stage_role を持つ pipeline
|
|
3419
|
+
// メンバーであり、owner・role から選ぶと pipeline 用でない agent(翻訳専用など)や
|
|
3420
|
+
// result を書かない executor が単独で選ばれてしまうため。--by が無い場合の agent は
|
|
3421
|
+
// resolveRegisterPipelineCommand が stage_role から選ぶ。
|
|
2684
3422
|
export function resolveRegisterCommand(item, roster, opts, execDefaults = {}) {
|
|
2685
3423
|
const by = opts.by?.trim();
|
|
2686
|
-
if (by) {
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
3424
|
+
if (!by) {
|
|
3425
|
+
throw new Error(`No agent specified for register item ${item.id} (owner: ${item.owner || "-"}). ` +
|
|
3426
|
+
"Specify --by <nickname>, or --executor-by <nickname> --reporter-by <nickname>.");
|
|
3427
|
+
}
|
|
3428
|
+
const member = roster?.members.find((m) => m.nickname === by && m.type === "agent");
|
|
3429
|
+
const command = member ? resolveMemberCommand(execDefaults, member) : undefined;
|
|
3430
|
+
if (!command)
|
|
3431
|
+
throw new Error(`Agent command not found for actor: ${by}`);
|
|
3432
|
+
return { command, actor: by };
|
|
3433
|
+
}
|
|
3434
|
+
// --register を executor/reporter パイプラインで実行するかを判定する。--executor-by /
|
|
3435
|
+
// --reporter-by の指定があれば pipeline、どちらも無く --by も無い場合も stage_role からの
|
|
3436
|
+
// 自動選択で pipeline にする。--by だけを指定した場合に限り、従来の単一 agent 実行
|
|
3437
|
+
// (resolveRegisterCommand)を使う。両者は互いに排他である。
|
|
3438
|
+
export function isRegisterPipelineRequested(opts) {
|
|
3439
|
+
if (opts.executorBy || opts.reporterBy)
|
|
3440
|
+
return true;
|
|
3441
|
+
return !opts.by?.trim();
|
|
3442
|
+
}
|
|
3443
|
+
// `--executor-by` keeps its original single-nickname form and additionally accepts a complete
|
|
3444
|
+
// PJR-ID-to-nickname map. Requiring complete coverage makes an omitted item an input error instead
|
|
3445
|
+
// of silently falling back to a different executor, while rejecting extra IDs catches typos and
|
|
3446
|
+
// stale invocations before any register transition or worktree setup occurs.
|
|
3447
|
+
export function parseRegisterExecutorSelection(raw, selectedIds) {
|
|
3448
|
+
if (raw === undefined)
|
|
3449
|
+
return { kind: "none" };
|
|
3450
|
+
const value = raw.trim();
|
|
3451
|
+
if (!value)
|
|
3452
|
+
throw new Error("--executor-by must not be empty.");
|
|
3453
|
+
if (!value.includes("="))
|
|
3454
|
+
return { kind: "shared", executor: value };
|
|
3455
|
+
const executors = new Map();
|
|
3456
|
+
for (const entry of value.split(",")) {
|
|
3457
|
+
const parts = entry.split("=");
|
|
3458
|
+
if (parts.length !== 2) {
|
|
3459
|
+
throw new Error(`Invalid --executor-by item assignment: ${entry}. Use PJR-ID=nickname separated by commas.`);
|
|
2704
3460
|
}
|
|
2705
|
-
const
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
const roleMatch = roleMatches[0];
|
|
2713
|
-
if (roleMatch) {
|
|
2714
|
-
const command = resolveMemberCommand(execDefaults, roleMatch);
|
|
2715
|
-
if (command)
|
|
2716
|
-
return { command, actor: roleMatch.nickname };
|
|
3461
|
+
const id = normalizePjrId(parts[0]);
|
|
3462
|
+
const executor = parts[1].trim();
|
|
3463
|
+
if (!executor) {
|
|
3464
|
+
throw new Error(`Invalid --executor-by item assignment for ${id}: nickname is empty.`);
|
|
3465
|
+
}
|
|
3466
|
+
if (executors.has(id)) {
|
|
3467
|
+
throw new Error(`Duplicate --executor-by item assignment: ${id}.`);
|
|
2717
3468
|
}
|
|
3469
|
+
executors.set(id, executor);
|
|
2718
3470
|
}
|
|
2719
|
-
const
|
|
2720
|
-
const
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
throw new Error(`No agent found for register item ${item.id} (owner: ${item.owner || "-"}). Specify --by <nickname>.`);
|
|
3471
|
+
const selected = new Set(selectedIds);
|
|
3472
|
+
const outsideTarget = [...executors.keys()].filter((id) => !selected.has(id));
|
|
3473
|
+
if (outsideTarget.length > 0) {
|
|
3474
|
+
throw new Error(`--executor-by item assignments include IDs outside the register execution target: ${outsideTarget.join(", ")}.`);
|
|
2724
3475
|
}
|
|
2725
|
-
|
|
3476
|
+
const missing = selectedIds.filter((id) => !executors.has(id));
|
|
3477
|
+
if (missing.length > 0) {
|
|
3478
|
+
throw new Error(`--executor-by item assignments must cover every selected register item; missing: ${missing.join(", ")}.`);
|
|
3479
|
+
}
|
|
3480
|
+
return { kind: "per-item", executors };
|
|
2726
3481
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
return !!(opts.executorBy || opts.reporterBy);
|
|
3482
|
+
function selectedRegisterExecutor(selection, itemId) {
|
|
3483
|
+
if (selection.kind === "none")
|
|
3484
|
+
return undefined;
|
|
3485
|
+
return selection.kind === "shared" ? selection.executor : selection.executors.get(itemId);
|
|
2732
3486
|
}
|
|
2733
3487
|
// --register 向けの executor/reporter 解決。Schedule タスクの agent_pipeline と異なり、
|
|
2734
|
-
// register 項目には per-item のパイプライン宣言が無いため、owner/role
|
|
2735
|
-
// --executor-by / --reporter-by
|
|
3488
|
+
// register 項目には per-item のパイプライン宣言が無いため、owner/role からの自動選択は行わない。
|
|
3489
|
+
// --executor-by / --reporter-by は両方そろえて明示する。どちらも無い場合は stage_role:
|
|
3490
|
+
// executor(mode: edit)と stage_role: reporter の agent から priority 順に自動選択する。
|
|
3491
|
+
// stage_role を持たない agent(翻訳専用など)は候補に入らない(PJR-ADZ6)。
|
|
2736
3492
|
export function resolveRegisterPipelineCommand(roster, opts, execDefaults = {}) {
|
|
3493
|
+
if (!opts.executorBy && !opts.reporterBy) {
|
|
3494
|
+
return autoSelectRegisterPipelineAgents(roster, execDefaults);
|
|
3495
|
+
}
|
|
2737
3496
|
if (!opts.executorBy || !opts.reporterBy) {
|
|
2738
3497
|
throw new Error("--register pipeline execution requires both --executor-by and --reporter-by.");
|
|
2739
3498
|
}
|
|
@@ -2742,14 +3501,14 @@ export function resolveRegisterPipelineCommand(roster, opts, execDefaults = {})
|
|
|
2742
3501
|
throw new Error(executorResolution.message.replace(/^--by/, "--executor-by"));
|
|
2743
3502
|
}
|
|
2744
3503
|
if (executorResolution.kind !== "command") {
|
|
2745
|
-
throw new Error(`--executor-by agent not found in
|
|
3504
|
+
throw new Error(`--executor-by agent not found in agent-members.yaml: ${opts.executorBy}`);
|
|
2746
3505
|
}
|
|
2747
3506
|
const reporterResolution = resolveAgentOverride("edit", opts.reporterBy, {}, roster, execDefaults, "reporter");
|
|
2748
3507
|
if (reporterResolution.kind === "error") {
|
|
2749
3508
|
throw new Error(reporterResolution.message.replace(/^--by/, "--reporter-by"));
|
|
2750
3509
|
}
|
|
2751
3510
|
if (reporterResolution.kind !== "command") {
|
|
2752
|
-
throw new Error(`--reporter-by agent not found in
|
|
3511
|
+
throw new Error(`--reporter-by agent not found in agent-members.yaml: ${opts.reporterBy}`);
|
|
2753
3512
|
}
|
|
2754
3513
|
return {
|
|
2755
3514
|
executor: {
|
|
@@ -2766,12 +3525,40 @@ export function resolveRegisterPipelineCommand(roster, opts, execDefaults = {})
|
|
|
2766
3525
|
],
|
|
2767
3526
|
};
|
|
2768
3527
|
}
|
|
3528
|
+
// --executor-by / --reporter-by も --by も無い --register 実行の agent を stage_role から選ぶ。
|
|
3529
|
+
// executor は mode: edit の executor(mode 未指定を含む)、reporter は mode を問わない
|
|
3530
|
+
// reporter を priority 順に候補とする。stage_role を持たない agent は selectCandidates の
|
|
3531
|
+
// 段指定によって除外される。どちらかの段に候補が無い場合は明示指定を求めるエラーにする。
|
|
3532
|
+
function autoSelectRegisterPipelineAgents(roster, execDefaults) {
|
|
3533
|
+
const toCandidates = (members) => members.flatMap((member) => {
|
|
3534
|
+
const command = resolveMemberCommand(execDefaults, member);
|
|
3535
|
+
return command ? [{ command, actor: member.nickname, provider: member.provider }] : [];
|
|
3536
|
+
});
|
|
3537
|
+
const executor = toCandidates(selectCandidates({ capabilities: [], stage_role: "executor" }, roster, "edit", undefined, execDefaults))[0];
|
|
3538
|
+
const reporterCandidates = toCandidates(selectCandidates({ capabilities: [], stage_role: "reporter" }, roster, undefined, undefined, execDefaults));
|
|
3539
|
+
if (!executor || reporterCandidates.length === 0) {
|
|
3540
|
+
const missing = [
|
|
3541
|
+
...(executor ? [] : ["stage_role: executor (mode: edit)"]),
|
|
3542
|
+
...(reporterCandidates.length > 0 ? [] : ["stage_role: reporter"]),
|
|
3543
|
+
];
|
|
3544
|
+
throw new Error(`No agent found for --register pipeline stage (${missing.join(", ")}). ` +
|
|
3545
|
+
"Specify --executor-by <nickname> --reporter-by <nickname>, or --by <nickname>.");
|
|
3546
|
+
}
|
|
3547
|
+
return { executor, reporterCandidates };
|
|
3548
|
+
}
|
|
2769
3549
|
// register pipeline の reporter 段だけを実行する。executor 直後の通常経路と、executor が
|
|
2770
3550
|
// 成功したまま reporter だけが失敗した run の再開経路の双方から共有し、reporter 起動・
|
|
2771
3551
|
// result 描画・pipeline-state 更新のみを担う(register の状態遷移と commit は呼び出し側)。
|
|
2772
3552
|
async function runReporterStage(params) {
|
|
2773
3553
|
const { repoRoot, cwd, schedulePath, executionPath, reporterCandidates, execDefaults } = params;
|
|
2774
|
-
const env = agentEnvironment(repoRoot, cwd, schedulePath, executionPath);
|
|
3554
|
+
const env = agentEnvironment(repoRoot, cwd, schedulePath, executionPath, params.productWorktrees);
|
|
3555
|
+
const reporterEvidence = evidenceForReporter(params.evidence, {
|
|
3556
|
+
repoRoot,
|
|
3557
|
+
worktreePath: cwd,
|
|
3558
|
+
executionPath,
|
|
3559
|
+
resultPath: params.resultPath,
|
|
3560
|
+
...(params.registerPaths ? { registerPaths: params.registerPaths } : {}),
|
|
3561
|
+
});
|
|
2775
3562
|
let state = params.state;
|
|
2776
3563
|
const reporterStartedAt = new Date().toISOString();
|
|
2777
3564
|
state = updatePipelineStage(state, "reporter", {
|
|
@@ -2783,10 +3570,10 @@ async function runReporterStage(params) {
|
|
|
2783
3570
|
writePipelineState(params.statePath, state);
|
|
2784
3571
|
process.stdout.write(` Running reporter: ${reporterCandidates[0]?.command ?? ""}\n`);
|
|
2785
3572
|
let reporterAttempts = 0;
|
|
2786
|
-
const
|
|
3573
|
+
const runReporter = () => runReporterWithFormatRetry({
|
|
2787
3574
|
plan: params.planPrompt,
|
|
2788
|
-
evidence:
|
|
2789
|
-
mode: "edit",
|
|
3575
|
+
evidence: reporterEvidence,
|
|
3576
|
+
mode: params.mode ?? "edit",
|
|
2790
3577
|
invoke: async (reporterPrompt) => {
|
|
2791
3578
|
const reporterOutcome = await runWithRetry(reporterCandidates, reporterPrompt, execDefaults, cwd, env, params.resultPath);
|
|
2792
3579
|
reporterAttempts += reporterOutcome.attempts;
|
|
@@ -2797,17 +3584,17 @@ async function runReporterStage(params) {
|
|
|
2797
3584
|
};
|
|
2798
3585
|
},
|
|
2799
3586
|
});
|
|
3587
|
+
const reporter = params.providerConcurrencyGate
|
|
3588
|
+
? await params.providerConcurrencyGate.run(reporterCandidates[0]?.provider, runReporter, `${params.evidence.task_id} reporter`)
|
|
3589
|
+
: await runReporter();
|
|
2800
3590
|
let exitCode = 1;
|
|
2801
3591
|
let blockReason;
|
|
2802
3592
|
if (reporter.result === "success") {
|
|
2803
3593
|
try {
|
|
2804
|
-
await renderReporterResult(params.resultPath, reporter.output);
|
|
2805
|
-
const
|
|
2806
|
-
exitCode =
|
|
2807
|
-
blockReason =
|
|
2808
|
-
reporter.output.outcome === "blocked"
|
|
2809
|
-
? reporter.output.block_reason
|
|
2810
|
-
: parentValidationFailure;
|
|
3594
|
+
await renderReporterResult(params.resultPath, reporter.output, reporterEvidence);
|
|
3595
|
+
const facts = deriveReporterFacts(reporterEvidence, { mode: params.mode ?? "edit" });
|
|
3596
|
+
exitCode = facts.outcome === "complete" ? 0 : 1;
|
|
3597
|
+
blockReason = facts.block_reason || undefined;
|
|
2811
3598
|
process.stdout.write(` Reporter complete: ${reporterCandidates[0]?.actor ?? "reporter"} (format attempts: ${reporter.formatAttempts})\n`);
|
|
2812
3599
|
}
|
|
2813
3600
|
catch (error) {
|
|
@@ -2849,7 +3636,7 @@ async function runReporterStage(params) {
|
|
|
2849
3636
|
async function runAgentPipeline(params) {
|
|
2850
3637
|
const { repoRoot, cwd, schedulePath, executionPath, taskId, executor, reporterCandidates, planPrompt, resultPath, execDefaults, } = params;
|
|
2851
3638
|
const startedAt = new Date().toISOString();
|
|
2852
|
-
const runId = `${new Date().toISOString().replace(/[-:.]/g, "")}-${randomHex(4)}`;
|
|
3639
|
+
const runId = params.runId ?? `${new Date().toISOString().replace(/[-:.]/g, "")}-${randomHex(4)}`;
|
|
2853
3640
|
const stateLocation = pipelineStateLocation({
|
|
2854
3641
|
repoRoot,
|
|
2855
3642
|
worktreePath: cwd,
|
|
@@ -2873,9 +3660,21 @@ async function runAgentPipeline(params) {
|
|
|
2873
3660
|
});
|
|
2874
3661
|
state = updatePipelineStage(state, "executor", { status: "running", started_at: startedAt }, startedAt);
|
|
2875
3662
|
writePipelineState(stateLocation.path, state);
|
|
2876
|
-
const env = agentEnvironment(repoRoot, cwd, schedulePath, executionPath);
|
|
2877
|
-
const executorPrompt = buildExecutorPrompt(planPrompt, execDefaults.pipeline?.parent_validations
|
|
2878
|
-
|
|
3663
|
+
const env = agentEnvironment(repoRoot, cwd, schedulePath, executionPath, params.productWorktrees);
|
|
3664
|
+
const executorPrompt = withProductRepoPrompt(buildExecutorPrompt(planPrompt, execDefaults.pipeline?.parent_validations, {
|
|
3665
|
+
mode: params.mode ?? "edit",
|
|
3666
|
+
resumed: params.resumedExecutor,
|
|
3667
|
+
...(params.resumedExecutor ? { existingChanges: worktreeStatusPaths(cwd) } : {}),
|
|
3668
|
+
...(params.resumedExecutor
|
|
3669
|
+
? { initialChangeTargets: params.initialChangeTargets ?? [] }
|
|
3670
|
+
: {}),
|
|
3671
|
+
...(params.resumedExecutor ? { resumeHandoff: params.resumeHandoff ?? [] } : {}),
|
|
3672
|
+
}), params.productWorktrees);
|
|
3673
|
+
const changesBeforeAttempt = snapshotWorktreeChanges(cwd, params.productWorktrees);
|
|
3674
|
+
const runExecutor = () => runWithRetry([executor], executorPrompt, execDefaults, cwd, env, resultPath);
|
|
3675
|
+
const outcome = params.providerConcurrencyGate
|
|
3676
|
+
? await params.providerConcurrencyGate.run(executor.provider, runExecutor, `${taskId} executor`)
|
|
3677
|
+
: await runExecutor();
|
|
2879
3678
|
const recorded = recordExecutorEvidence({
|
|
2880
3679
|
repoRoot,
|
|
2881
3680
|
worktreePath: cwd,
|
|
@@ -2894,15 +3693,27 @@ async function runAgentPipeline(params) {
|
|
|
2894
3693
|
attempts: outcome.attempts,
|
|
2895
3694
|
stdout: outcome.stdout,
|
|
2896
3695
|
stderr: outcome.stderr,
|
|
3696
|
+
changesBeforeAttempt,
|
|
3697
|
+
productWorktrees: params.productWorktrees,
|
|
2897
3698
|
});
|
|
3699
|
+
const coverageFailure = outcome.result === "success"
|
|
3700
|
+
? resumedTargetCoverageFailure({
|
|
3701
|
+
resumed: !!params.resumedExecutor,
|
|
3702
|
+
plan: planPrompt,
|
|
3703
|
+
evidence: recorded.evidence,
|
|
3704
|
+
evidencePath: recorded.evidencePath,
|
|
3705
|
+
initialChangeTargets: params.initialChangeTargets,
|
|
3706
|
+
})
|
|
3707
|
+
: undefined;
|
|
3708
|
+
const executorResult = coverageFailure ? "failure" : outcome.result;
|
|
2898
3709
|
const evidenceRef = relative(cwd, recorded.evidencePath).split(sep).join("/");
|
|
2899
3710
|
const executorCompletedAt = new Date().toISOString();
|
|
2900
3711
|
state = updatePipelineStage(state, "executor", {
|
|
2901
|
-
status:
|
|
3712
|
+
status: executorResult === "success"
|
|
2902
3713
|
? "succeeded"
|
|
2903
3714
|
: outcome.protectionBlock
|
|
2904
3715
|
? "blocked"
|
|
2905
|
-
:
|
|
3716
|
+
: executorResult === "rate_limit"
|
|
2906
3717
|
? "rate_limited"
|
|
2907
3718
|
: "failed",
|
|
2908
3719
|
attempts: outcome.attempts,
|
|
@@ -2911,13 +3722,14 @@ async function runAgentPipeline(params) {
|
|
|
2911
3722
|
}, executorCompletedAt);
|
|
2912
3723
|
writePipelineState(stateLocation.path, state);
|
|
2913
3724
|
process.stdout.write(` Executor evidence: ${evidenceRef}\n`);
|
|
2914
|
-
if (
|
|
2915
|
-
const blockReason =
|
|
2916
|
-
|
|
2917
|
-
|
|
3725
|
+
if (executorResult !== "success") {
|
|
3726
|
+
const blockReason = coverageFailure ??
|
|
3727
|
+
(executorResult === "rate_limit"
|
|
3728
|
+
? "executor rate limit reached"
|
|
3729
|
+
: extractBlockReason(outcome.stderr));
|
|
2918
3730
|
return {
|
|
2919
3731
|
exitCode: 1,
|
|
2920
|
-
runResult:
|
|
3732
|
+
runResult: executorResult,
|
|
2921
3733
|
blockReason,
|
|
2922
3734
|
stateRef: stateLocation.ref,
|
|
2923
3735
|
evidenceRef,
|
|
@@ -2926,6 +3738,7 @@ async function runAgentPipeline(params) {
|
|
|
2926
3738
|
recorded.evidence = await appendParentValidationsToExecutorEvidence({
|
|
2927
3739
|
execDefaults,
|
|
2928
3740
|
cwd,
|
|
3741
|
+
productWorktrees: params.productWorktrees,
|
|
2929
3742
|
evidence: recorded.evidence,
|
|
2930
3743
|
evidencePath: recorded.evidencePath,
|
|
2931
3744
|
});
|
|
@@ -2937,11 +3750,15 @@ async function runAgentPipeline(params) {
|
|
|
2937
3750
|
reporterCandidates,
|
|
2938
3751
|
planPrompt,
|
|
2939
3752
|
resultPath,
|
|
3753
|
+
registerPaths: params.registerPaths,
|
|
2940
3754
|
execDefaults,
|
|
2941
3755
|
evidence: recorded.evidence,
|
|
2942
3756
|
evidencePath: recorded.evidencePath,
|
|
2943
3757
|
state,
|
|
2944
3758
|
statePath: stateLocation.path,
|
|
3759
|
+
providerConcurrencyGate: params.providerConcurrencyGate,
|
|
3760
|
+
productWorktrees: params.productWorktrees,
|
|
3761
|
+
mode: params.mode,
|
|
2945
3762
|
});
|
|
2946
3763
|
return {
|
|
2947
3764
|
exitCode: reporterOutcome.exitCode,
|
|
@@ -2967,17 +3784,23 @@ export function commitRegisterItemChanges(repoRoot, item, preexisting, runnerMan
|
|
|
2967
3784
|
const paths = remainingPaths();
|
|
2968
3785
|
if (paths.length === 0)
|
|
2969
3786
|
return { committed: false };
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
3787
|
+
try {
|
|
3788
|
+
stageCommitTargets(repoRoot, paths);
|
|
3789
|
+
const staged = gitResult(repoRoot, ["diff", "--cached", "--quiet", "--", ...paths]);
|
|
3790
|
+
if (staged.status === 0)
|
|
3791
|
+
return { committed: false };
|
|
3792
|
+
if (staged.status !== 1)
|
|
3793
|
+
throw new Error("Failed to inspect staged register changes.");
|
|
3794
|
+
const subject = commitSubject(`exec(register ${item.id}): `, item.title);
|
|
3795
|
+
gitOutput(repoRoot, ["commit", "-m", subject, "--", ...paths]);
|
|
3796
|
+
stabilizeCommitTargets(repoRoot, remainingPaths);
|
|
3797
|
+
const sha = gitOutput(repoRoot, ["rev-parse", "--short", "HEAD"]).trim();
|
|
3798
|
+
return { committed: true, sha };
|
|
3799
|
+
}
|
|
3800
|
+
catch (error) {
|
|
3801
|
+
unstageCommitTargets(repoRoot, [...paths, ...remainingPaths()]);
|
|
3802
|
+
throw error;
|
|
3803
|
+
}
|
|
2981
3804
|
}
|
|
2982
3805
|
function repoRelativePath(repoRoot, path) {
|
|
2983
3806
|
return relative(repoRoot, path).split(sep).join("/");
|
|
@@ -3021,6 +3844,13 @@ function registerRunnerManagedPaths(repoRoot, registerPaths, planPath, resultPat
|
|
|
3021
3844
|
}
|
|
3022
3845
|
return [...exact];
|
|
3023
3846
|
}
|
|
3847
|
+
function registerReporterManagedPaths(registerPaths) {
|
|
3848
|
+
return [
|
|
3849
|
+
registerPaths.projectRegisterPath,
|
|
3850
|
+
registerPaths.generatedPath,
|
|
3851
|
+
registerPaths.controlsGeneratedPath,
|
|
3852
|
+
];
|
|
3853
|
+
}
|
|
3024
3854
|
// register 項目1件の in-place 実行。plan 生成 → `register start` → agent 実行 → 成否を
|
|
3025
3855
|
// register の状態遷移(成功: review / 失敗: waiting)と result に反映し、成功かつ
|
|
3026
3856
|
// registerCommit 有効なら当該IDの変更だけを commit する。ID別の結果を要約で返す。
|
|
@@ -3066,6 +3896,7 @@ async function runSingleRegisterItem(context, opts, pjrId) {
|
|
|
3066
3896
|
agent: actor,
|
|
3067
3897
|
startedAt: new Date().toISOString(),
|
|
3068
3898
|
stem,
|
|
3899
|
+
...(item.targets && item.targets.length > 0 ? { targets: item.targets } : {}),
|
|
3069
3900
|
});
|
|
3070
3901
|
const resultScaffold = readResultFrontmatterSnapshot(resultPath);
|
|
3071
3902
|
process.stdout.write(`Register item: ${item.id} — ${item.title} [${item.type}]\n`);
|
|
@@ -3091,7 +3922,9 @@ async function runSingleRegisterItem(context, opts, pjrId) {
|
|
|
3091
3922
|
planPath,
|
|
3092
3923
|
planPrompt: prompt,
|
|
3093
3924
|
resultPath,
|
|
3925
|
+
registerPaths: registerReporterManagedPaths(registerPaths),
|
|
3094
3926
|
execDefaults: context.execDefaults,
|
|
3927
|
+
providerConcurrencyGate: context.providerConcurrencyGate,
|
|
3095
3928
|
});
|
|
3096
3929
|
exitCode = pipelineOutcome.exitCode;
|
|
3097
3930
|
pipelineBlockReason = pipelineOutcome.blockReason;
|
|
@@ -3210,7 +4043,7 @@ export function registerStatePaths(repoRoot, registerPaths, ticketPath) {
|
|
|
3210
4043
|
}
|
|
3211
4044
|
// register 状態遷移の pjr-index / 派生ビュー変更を root へ 1 コミットする。hook が対象を
|
|
3212
4045
|
// 整形した場合は同じ commit へ収束するまで amend する。commit 対象が無ければ何もしない。
|
|
3213
|
-
function commitRegisterState(repoRoot, registerPaths, message, ticketPath, additionalPaths = []) {
|
|
4046
|
+
function commitRegisterState(repoRoot, registerPaths, message, ticketPath, additionalPaths = [], failureLogPath) {
|
|
3214
4047
|
const paths = [
|
|
3215
4048
|
...new Set([
|
|
3216
4049
|
...registerStatePaths(repoRoot, registerPaths, ticketPath),
|
|
@@ -3219,14 +4052,36 @@ function commitRegisterState(repoRoot, registerPaths, message, ticketPath, addit
|
|
|
3219
4052
|
];
|
|
3220
4053
|
if (paths.length === 0)
|
|
3221
4054
|
return;
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
4055
|
+
const remainingPaths = () => registerStatePaths(repoRoot, registerPaths, ticketPath);
|
|
4056
|
+
try {
|
|
4057
|
+
stageCommitTargets(repoRoot, paths);
|
|
4058
|
+
const staged = gitResult(repoRoot, ["diff", "--cached", "--quiet", "--", ...paths]);
|
|
4059
|
+
if (staged.status === 0)
|
|
4060
|
+
return;
|
|
4061
|
+
if (staged.status !== 1)
|
|
4062
|
+
throw new Error("Failed to inspect staged register-state changes.");
|
|
4063
|
+
const commit = gitResult(repoRoot, ["commit", "-m", message, "--", ...paths]);
|
|
4064
|
+
if (commit.status !== 0) {
|
|
4065
|
+
const output = [commit.stdout, commit.stderr]
|
|
4066
|
+
.filter((part) => typeof part === "string" && part.length > 0)
|
|
4067
|
+
.join("\n");
|
|
4068
|
+
appendGitFailureLog(failureLogPath, [
|
|
4069
|
+
`=== ${new Date().toISOString()} git commit register state ===`,
|
|
4070
|
+
`exit: ${commit.status ?? "unknown"}`,
|
|
4071
|
+
"--- stdout ---",
|
|
4072
|
+
typeof commit.stdout === "string" ? commit.stdout : "",
|
|
4073
|
+
"--- stderr ---",
|
|
4074
|
+
typeof commit.stderr === "string" ? commit.stderr : "",
|
|
4075
|
+
"",
|
|
4076
|
+
]);
|
|
4077
|
+
throw new Error(`git commit failed: ${summarizeGitHookFailure(output)}`);
|
|
4078
|
+
}
|
|
4079
|
+
stabilizeCommitTargets(repoRoot, remainingPaths, undefined, failureLogPath);
|
|
4080
|
+
}
|
|
4081
|
+
catch (error) {
|
|
4082
|
+
unstageCommitTargets(repoRoot, [...paths, ...remainingPaths()]);
|
|
4083
|
+
throw error;
|
|
4084
|
+
}
|
|
3230
4085
|
}
|
|
3231
4086
|
function registerPathsInsideWorktree(repoRoot, worktreePath, paths) {
|
|
3232
4087
|
return {
|
|
@@ -3252,6 +4107,47 @@ function copyRepoPaths(sourceRoot, targetRoot, repoRoot, paths) {
|
|
|
3252
4107
|
copyFileSync(source, target);
|
|
3253
4108
|
}
|
|
3254
4109
|
}
|
|
4110
|
+
// 失敗時に root へ戻すのは runner が生成・更新した plan / result だけに限定する。個票と
|
|
4111
|
+
// event は agent が編集した未検証の本文を含みうるため、root に残してある checkpoint 版を
|
|
4112
|
+
// wait 遷移の入力にする。派生ビューは遷移後に root で再生成する。
|
|
4113
|
+
function registerFailureArtifactPaths(repoRoot, paths) {
|
|
4114
|
+
return paths.filter((path) => /(?:^|\/)exec\/(?:plans|results)\//.test(repoRelativePath(repoRoot, path)));
|
|
4115
|
+
}
|
|
4116
|
+
// wait commit の個票は検証済みの root 本文を使う一方、exec branch には agent が編集した本文を
|
|
4117
|
+
// 残す。root の frontmatter から lifecycle フィールドだけを重ね、resume 後も waiting 状態と
|
|
4118
|
+
// 未統合の作業内容の両方を保持する。
|
|
4119
|
+
function restorePreservedRegisterTicket(worktreePath, repoRoot, preserved) {
|
|
4120
|
+
if (!preserved)
|
|
4121
|
+
return;
|
|
4122
|
+
const rel = repoRelativePath(repoRoot, preserved.path);
|
|
4123
|
+
const rootTicketPath = resolve(repoRoot, rel);
|
|
4124
|
+
const worktreeTicketPath = resolve(worktreePath, rel);
|
|
4125
|
+
if (!existsSync(rootTicketPath)) {
|
|
4126
|
+
mkdirSync(dirname(worktreeTicketPath), { recursive: true });
|
|
4127
|
+
writeFileSync(worktreeTicketPath, preserved.content, "utf8");
|
|
4128
|
+
return;
|
|
4129
|
+
}
|
|
4130
|
+
try {
|
|
4131
|
+
const rootContent = readFileSync(rootTicketPath, "utf8");
|
|
4132
|
+
const parsed = readRegisterItemContent(rootContent, basename(rel));
|
|
4133
|
+
if (!parsed)
|
|
4134
|
+
throw new Error(`could not parse register item: ${rel}`);
|
|
4135
|
+
const content = applyRegisterItemFields(preserved.content, {
|
|
4136
|
+
...registerItemFieldsFromItem(parsed.item),
|
|
4137
|
+
block_reason: parsed.blockReason === CELL_NONE ? null : parsed.blockReason,
|
|
4138
|
+
});
|
|
4139
|
+
mkdirSync(dirname(worktreeTicketPath), { recursive: true });
|
|
4140
|
+
writeFileSync(worktreeTicketPath, content, "utf8");
|
|
4141
|
+
}
|
|
4142
|
+
catch (error) {
|
|
4143
|
+
// frontmatter 自体が壊れている場合も agent の作業を失わない。root の wait commit はすでに
|
|
4144
|
+
// clean な checkpoint 版で確定しているため、worktree 側だけ元の内容へ戻して警告する。
|
|
4145
|
+
mkdirSync(dirname(worktreeTicketPath), { recursive: true });
|
|
4146
|
+
writeFileSync(worktreeTicketPath, preserved.content, "utf8");
|
|
4147
|
+
process.stderr.write(`warning: could not apply the waiting lifecycle to ${rel} in the exec branch: ` +
|
|
4148
|
+
`${error instanceof Error ? error.message : String(error)}\n`);
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
3255
4151
|
// register の状態遷移(start / wait / review)が書き換える追跡ファイル(root 側の絶対パス):
|
|
3256
4152
|
// 個票、append-only のイベント、存在する場合は登録簿本体(移行前のレイアウト)。gitignore 済みの
|
|
3257
4153
|
// 派生ビューは含めない。
|
|
@@ -3266,13 +4162,12 @@ function registerTransitionPaths(registerPaths, ticketPath) {
|
|
|
3266
4162
|
paths.push(registerPaths.pjrIndexPath);
|
|
3267
4163
|
return paths;
|
|
3268
4164
|
}
|
|
3269
|
-
// register 項目の実行管理ファイル(root
|
|
3270
|
-
//
|
|
4165
|
+
// register 項目の実行管理ファイル(root 側の絶対パス)。再開時は plan / result /
|
|
4166
|
+
// 遷移ファイルに加え、start 遷移で再生成された派生ビューも、初回 checkpoint と同じ基準で
|
|
4167
|
+
// runner 管理パスとして扱う。この集合を失敗時の wait commit、merge 前の root 解放で使う。
|
|
3271
4168
|
function registerBookkeepingPaths(params) {
|
|
3272
|
-
const { registerPaths, planPath, resultPath, ticketPath } = params;
|
|
3273
|
-
return
|
|
3274
|
-
...new Set([planPath, resultPath, ...registerTransitionPaths(registerPaths, ticketPath)]),
|
|
3275
|
-
];
|
|
4169
|
+
const { repoRoot, registerPaths, planPath, resultPath, ticketPath } = params;
|
|
4170
|
+
return registerRunnerManagedPaths(repoRoot, registerPaths, planPath, resultPath, worktreeStatusPaths(repoRoot), ticketPath).map((path) => resolve(repoRoot, path));
|
|
3276
4171
|
}
|
|
3277
4172
|
// root の登録簿派生ビュー(pjr-index / generated)は非追跡の生成物で、merge や複製では更新され
|
|
3278
4173
|
// ない。個票の状態を root 側へ反映したあとに再生成して、root の表示を個票と揃える。失敗しても
|
|
@@ -3282,18 +4177,21 @@ function rebuildRootRegisterViews(projectId, itemId) {
|
|
|
3282
4177
|
process.stderr.write(`warning: could not rebuild register views at root for ${itemId}\n`);
|
|
3283
4178
|
}
|
|
3284
4179
|
}
|
|
3285
|
-
// register worktree 実行の失敗確定。worktree
|
|
3286
|
-
//
|
|
3287
|
-
// `exec(register X): wait` commit 1
|
|
3288
|
-
//
|
|
3289
|
-
// 記帳ファイルで競合しないようにする。worktree が無い(checkpoint 前の失敗)場合は root の
|
|
3290
|
-
// 実行管理ファイルをそのまま commit する。
|
|
4180
|
+
// register worktree 実行の失敗確定。worktree 側の plan / blocked result だけを root へ写し、
|
|
4181
|
+
// 個票・event は root に残る検証済み checkpoint 版を基準に waiting へ遷移する。統合ブランチには
|
|
4182
|
+
// `exec(register X): wait` commit 1件だけを作り、未検証の個票本文は exec branch に保持する。
|
|
4183
|
+
// worktree が無い(checkpoint 前の失敗)場合は root の実行管理ファイルをそのまま commit する。
|
|
3291
4184
|
function registerWaitSummary(params) {
|
|
3292
4185
|
const { repoRoot, projectId, registerPaths, item, ticketPath, actor, worktree } = params;
|
|
3293
4186
|
const blockReason = sanitizeRegisterConclusion(params.reason);
|
|
3294
4187
|
const bookkeepingPaths = [...params.bookkeepingPaths];
|
|
3295
|
-
|
|
3296
|
-
|
|
4188
|
+
const preservedTicketPath = worktree && ticketPath ? pathInsideWorktree(repoRoot, worktree.path, ticketPath) : undefined;
|
|
4189
|
+
const preservedTicket = ticketPath && preservedTicketPath && existsSync(preservedTicketPath)
|
|
4190
|
+
? { path: ticketPath, content: readFileSync(preservedTicketPath, "utf8") }
|
|
4191
|
+
: undefined;
|
|
4192
|
+
if (worktree) {
|
|
4193
|
+
copyRepoPaths(worktree.path, repoRoot, repoRoot, registerFailureArtifactPaths(repoRoot, bookkeepingPaths));
|
|
4194
|
+
}
|
|
3297
4195
|
let transition = "waiting";
|
|
3298
4196
|
if (!spawnRegisterTransition(projectId, [
|
|
3299
4197
|
"wait",
|
|
@@ -3321,11 +4219,9 @@ function registerWaitSummary(params) {
|
|
|
3321
4219
|
syncExecBranchAfterWait({
|
|
3322
4220
|
repoRoot,
|
|
3323
4221
|
worktree,
|
|
3324
|
-
registerPaths,
|
|
3325
4222
|
item,
|
|
3326
|
-
ticketPath,
|
|
3327
4223
|
bookkeepingPaths: committedPaths,
|
|
3328
|
-
|
|
4224
|
+
preservedTicket,
|
|
3329
4225
|
});
|
|
3330
4226
|
}
|
|
3331
4227
|
return {
|
|
@@ -3372,35 +4268,68 @@ function commitRegisterWaitState(params) {
|
|
|
3372
4268
|
function isRegisterResultPath(repoRoot, path) {
|
|
3373
4269
|
return /\/exec\/results\/[^/]+-result\.md$/.test(repoRelativePath(repoRoot, path));
|
|
3374
4270
|
}
|
|
3375
|
-
// wait commit
|
|
3376
|
-
//
|
|
3377
|
-
//
|
|
3378
|
-
//
|
|
3379
|
-
//
|
|
3380
|
-
//
|
|
3381
|
-
//
|
|
4271
|
+
// wait commit と、その時点までに統合先へ入った変更を exec branch へ通常 merge する。
|
|
4272
|
+
// worktree の記帳パスには、root へ複製した blocked result などが未 commit のまま残っている。
|
|
4273
|
+
// そのままでは root の wait commit に上書きされるとして merge 開始前に拒否されるため、root に
|
|
4274
|
+
// commit 済みの記帳パスだけを先に exec branch の HEAD へ戻す。checkpoint と wait commit は
|
|
4275
|
+
// 共通祖先に存在しないイベントファイルなどを双方で追加するため、記帳パスの競合だけは root 側の
|
|
4276
|
+
// 内容で解決する。それ以外の競合は自動解決せず、merge を abort する。
|
|
4277
|
+
// merge commit は runner 内部の同期であり、失敗原因となった統合 hook を再実行しないよう
|
|
4278
|
+
// --no-verify を指定する。同期に失敗した場合は root の記帳内容を worktree へ戻して保持する。
|
|
3382
4279
|
function syncExecBranchAfterWait(params) {
|
|
3383
4280
|
const { repoRoot, worktree, item } = params;
|
|
3384
|
-
const
|
|
4281
|
+
const bookkeepingPaths = params.bookkeepingPaths.map((path) => repoRelativePath(repoRoot, path));
|
|
3385
4282
|
try {
|
|
3386
4283
|
const targetBranch = currentBranch(repoRoot);
|
|
3387
|
-
|
|
4284
|
+
// The same content is already durable in the root wait commit. Releasing these working copies
|
|
4285
|
+
// is what lets a normal merge start; all other dirty paths remain untouched.
|
|
4286
|
+
releaseRootWorkingCopies(worktree.path, bookkeepingPaths);
|
|
4287
|
+
const mergeMessage = `exec(register ${item.id}): merge ${targetBranch} after wait`;
|
|
4288
|
+
const mergeResult = gitResult(worktree.path, [
|
|
3388
4289
|
"merge",
|
|
3389
|
-
"--no-
|
|
4290
|
+
"--no-commit",
|
|
4291
|
+
"--no-ff",
|
|
3390
4292
|
"--no-verify",
|
|
3391
|
-
"-s",
|
|
3392
|
-
"ours",
|
|
3393
4293
|
"-m",
|
|
3394
|
-
|
|
4294
|
+
mergeMessage,
|
|
3395
4295
|
targetBranch,
|
|
3396
4296
|
]);
|
|
4297
|
+
if (mergeResult.status !== 0) {
|
|
4298
|
+
const mergeHead = gitResult(worktree.path, [
|
|
4299
|
+
"rev-parse",
|
|
4300
|
+
"--verify",
|
|
4301
|
+
"--quiet",
|
|
4302
|
+
"MERGE_HEAD",
|
|
4303
|
+
]);
|
|
4304
|
+
if (mergeHead.status !== 0) {
|
|
4305
|
+
const stderr = typeof mergeResult.stderr === "string" ? mergeResult.stderr.trim() : "";
|
|
4306
|
+
throw new Error(`git merge failed before conflict resolution${stderr ? `: ${stderr}` : ""}`);
|
|
4307
|
+
}
|
|
4308
|
+
const conflicted = gitOutput(worktree.path, ["diff", "--name-only", "--diff-filter=U", "-z"])
|
|
4309
|
+
.split("\0")
|
|
4310
|
+
.filter((path) => path.length > 0);
|
|
4311
|
+
const allowed = new Set(bookkeepingPaths);
|
|
4312
|
+
const unexpected = conflicted.filter((path) => !allowed.has(path));
|
|
4313
|
+
if (unexpected.length > 0) {
|
|
4314
|
+
throw new Error(`wait sync conflicts outside register bookkeeping: ${unexpected.join(", ")}`);
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
3397
4317
|
copyRepoPaths(repoRoot, worktree.path, repoRoot, params.bookkeepingPaths);
|
|
3398
|
-
|
|
4318
|
+
restorePreservedRegisterTicket(worktree.path, repoRoot, params.preservedTicket);
|
|
4319
|
+
stageCommitTargets(worktree.path, bookkeepingPaths);
|
|
4320
|
+
const unresolved = gitOutput(worktree.path, ["diff", "--name-only", "--diff-filter=U"]).trim();
|
|
4321
|
+
if (unresolved)
|
|
4322
|
+
throw new Error(`wait sync has unresolved conflicts: ${unresolved}`);
|
|
4323
|
+
gitOutput(worktree.path, ["commit", "--no-verify", "-m", mergeMessage]);
|
|
3399
4324
|
}
|
|
3400
4325
|
catch (error) {
|
|
3401
|
-
|
|
4326
|
+
abortMerge(worktree.path);
|
|
4327
|
+
// The pre-merge release is safe to repeat from root and restores the visible waiting state even
|
|
4328
|
+
// when the merge was rejected before MERGE_HEAD was created.
|
|
4329
|
+
copyRepoPaths(repoRoot, worktree.path, repoRoot, params.bookkeepingPaths);
|
|
4330
|
+
restorePreservedRegisterTicket(worktree.path, repoRoot, params.preservedTicket);
|
|
3402
4331
|
process.stderr.write(`warning: could not sync the exec branch of ${item.id} with the wait commit; ` +
|
|
3403
|
-
`the resumed merge may conflict
|
|
4332
|
+
`the resumed merge may still conflict: ` +
|
|
3404
4333
|
`${error instanceof Error ? error.message : String(error)}\n`);
|
|
3405
4334
|
}
|
|
3406
4335
|
}
|
|
@@ -3420,6 +4349,22 @@ function recordIntegrateStage(statePath, updatedAt, buildPatch) {
|
|
|
3420
4349
|
`${error instanceof Error ? error.message : String(error)}\n`);
|
|
3421
4350
|
}
|
|
3422
4351
|
}
|
|
4352
|
+
// 複数リポジトリ統合の進捗を同じ pipeline state へ追記する。プロダクトを統合するたびに
|
|
4353
|
+
// project worktree 側へ書くため、途中で失敗しても `--resume` は Git の実状態とこの記録の両方を
|
|
4354
|
+
// 手掛かりに、統合済みリポジトリを飛ばせる。
|
|
4355
|
+
function recordRepoIntegration(statePath, repo, patch) {
|
|
4356
|
+
if (!statePath || !existsSync(statePath))
|
|
4357
|
+
return;
|
|
4358
|
+
const updatedAt = new Date().toISOString();
|
|
4359
|
+
try {
|
|
4360
|
+
const state = readPipelineState(statePath);
|
|
4361
|
+
writePipelineState(statePath, updatePipelineRepoIntegration(state, repo, patch, updatedAt));
|
|
4362
|
+
}
|
|
4363
|
+
catch (error) {
|
|
4364
|
+
process.stderr.write(`warning: could not record repository ${repo} in ${statePath}: ` +
|
|
4365
|
+
`${error instanceof Error ? error.message : String(error)}\n`);
|
|
4366
|
+
}
|
|
4367
|
+
}
|
|
3423
4368
|
function integrateLogPath(statePath) {
|
|
3424
4369
|
return statePath ? join(dirname(statePath), "integrate.log") : undefined;
|
|
3425
4370
|
}
|
|
@@ -3514,6 +4459,10 @@ async function finalizeRegisterWorktreeRun(params) {
|
|
|
3514
4459
|
}
|
|
3515
4460
|
await updateResultStatus(worktreeResultPath, "complete", completedAt);
|
|
3516
4461
|
const subject = commitSubject(`exec(register ${item.id}): `, item.title);
|
|
4462
|
+
// PJR-30SW: プロダクト側の commit と merge commit、プロジェクト側の merge commit に
|
|
4463
|
+
// `Refs: <project-id>:<item-id>` を付ける(PJR-1SXK)。
|
|
4464
|
+
const itemTraceKey = traceKey(projectId, item.id);
|
|
4465
|
+
const productMessage = withCommitTrailers(subject, [refsTrailer(projectId, item.id)]);
|
|
3517
4466
|
const integrateStartedAt = new Date().toISOString();
|
|
3518
4467
|
recordIntegrateStage(params.pipelineStatePath, integrateStartedAt, (current) => ({
|
|
3519
4468
|
status: "running",
|
|
@@ -3523,45 +4472,108 @@ async function finalizeRegisterWorktreeRun(params) {
|
|
|
3523
4472
|
completed_at: null,
|
|
3524
4473
|
}));
|
|
3525
4474
|
try {
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
4475
|
+
const productNames = (worktree.repos ?? []).map((product) => product.name);
|
|
4476
|
+
try {
|
|
4477
|
+
const productOutcomes = commitProductWorktrees({
|
|
4478
|
+
worktree,
|
|
4479
|
+
message: productMessage,
|
|
4480
|
+
targets: taskTargetsAtHead(wtContext, worktree, stem),
|
|
4481
|
+
scopeLogPath: integrateLogPath(params.pipelineStatePath),
|
|
4482
|
+
failureLogPath: integrateLogPath(params.pipelineStatePath),
|
|
4483
|
+
resultPath: worktreeResultPath,
|
|
4484
|
+
});
|
|
4485
|
+
const productRootNewFiles = productOutcomes.flatMap((outcome) => outcome.rootNewFiles.map((path) => `${outcome.repo}:${path}`));
|
|
4486
|
+
commitWorktreeChanges({
|
|
4487
|
+
context: wtContext,
|
|
4488
|
+
worktree,
|
|
4489
|
+
taskId: stem,
|
|
4490
|
+
message: subject,
|
|
4491
|
+
scopeLogPath: integrateLogPath(params.pipelineStatePath),
|
|
4492
|
+
failureLogPath: integrateLogPath(params.pipelineStatePath),
|
|
4493
|
+
productsIntegratedByCaller: true,
|
|
4494
|
+
productRootNewFiles,
|
|
4495
|
+
});
|
|
3536
4496
|
}
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
4497
|
+
catch (error) {
|
|
4498
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4499
|
+
const repo = productNames.find((name) => message.startsWith(`${name}:`)) ?? PROJECT_REPO_NAME;
|
|
4500
|
+
recordRepoIntegration(params.pipelineStatePath, repo, {
|
|
4501
|
+
status: "failed",
|
|
4502
|
+
error: message,
|
|
4503
|
+
});
|
|
4504
|
+
throw new RepoIntegrationError({
|
|
4505
|
+
repo,
|
|
4506
|
+
cause: message,
|
|
4507
|
+
integrated: [],
|
|
4508
|
+
pending: [...productNames, PROJECT_REPO_NAME],
|
|
4509
|
+
});
|
|
3546
4510
|
}
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
4511
|
+
let executor = actor;
|
|
4512
|
+
let reporter = "-";
|
|
4513
|
+
if (params.pipelineStatePath && existsSync(params.pipelineStatePath)) {
|
|
4514
|
+
const state = readPipelineState(params.pipelineStatePath);
|
|
4515
|
+
executor = state.stages.executor.actor ?? executor;
|
|
4516
|
+
reporter = state.stages.reporter.actor ?? reporter;
|
|
4517
|
+
}
|
|
4518
|
+
const mergeMessage = registerProjectMergeMessage({
|
|
4519
|
+
subject,
|
|
4520
|
+
executor,
|
|
4521
|
+
reporter,
|
|
4522
|
+
projectId,
|
|
4523
|
+
itemId: item.id,
|
|
4524
|
+
});
|
|
4525
|
+
integrateTaskRepositories({
|
|
4526
|
+
worktree,
|
|
4527
|
+
mergeMessage,
|
|
4528
|
+
productMergeMessage: productMessage,
|
|
4529
|
+
checkProject: () => projectMergeBlockers({
|
|
4530
|
+
context: wtContext,
|
|
4531
|
+
worktree,
|
|
4532
|
+
taskId: stem,
|
|
4533
|
+
releasePaths: params.bookkeepingPaths,
|
|
4534
|
+
ownedPaths: params.bookkeepingPaths,
|
|
4535
|
+
}),
|
|
4536
|
+
beforeProjectMerge: () => {
|
|
4537
|
+
// review は exec branch 側(worktree)で記録し、最後の project merge commit に
|
|
4538
|
+
// 同梱する。統合ブランチで遷移すると first-parent に独立した commit が増える。
|
|
4539
|
+
if (!spawnRegisterTransition(projectId, ["review", "--id", item.id, "--by", actor], worktree.path)) {
|
|
4540
|
+
throw new Error(`register review transition failed: ${item.id}`);
|
|
4541
|
+
}
|
|
4542
|
+
// プロダクトの統合後・プロジェクトの統合前に、統合先の commit snapshot を result の
|
|
4543
|
+
// trace 表へ記録し、プロジェクト側の merge commit に同梱する。宣言の無い project では
|
|
4544
|
+
// 記録せず、result は従来どおりになる。
|
|
4545
|
+
const products = worktree.repos ?? [];
|
|
4546
|
+
const tracePaths = [];
|
|
4547
|
+
if (products.length > 0 && existsSync(worktreeResultPath)) {
|
|
4548
|
+
recordResultTrace({
|
|
4549
|
+
resultPath: worktreeResultPath,
|
|
4550
|
+
traceKey: itemTraceKey,
|
|
4551
|
+
traces: products.map(productIntegrationTrace),
|
|
4552
|
+
});
|
|
4553
|
+
tracePaths.push(worktreeResultPath);
|
|
4554
|
+
}
|
|
4555
|
+
const integrateCompletedAt = new Date().toISOString();
|
|
4556
|
+
recordIntegrateStage(params.pipelineStatePath, integrateCompletedAt, () => ({
|
|
4557
|
+
status: "succeeded",
|
|
4558
|
+
completed_at: integrateCompletedAt,
|
|
4559
|
+
}));
|
|
4560
|
+
commitRegisterState(worktree.path, worktreeRegisterPaths, `exec(register ${item.id}): review`, worktreeTicketPath, [...(params.pipelineStatePath ? [params.pipelineStatePath] : []), ...tracePaths], integrateLogPath(params.pipelineStatePath));
|
|
4561
|
+
},
|
|
4562
|
+
mergeProject: () => mergeWorktreeIntoCurrent({
|
|
3556
4563
|
context: wtContext,
|
|
3557
4564
|
worktree,
|
|
3558
4565
|
taskId: stem,
|
|
3559
|
-
message:
|
|
3560
|
-
`Transition: start → review\nExecutor: ${executor}\nReporter: ${reporter}\nRefs: ${item.id}`,
|
|
4566
|
+
message: mergeMessage,
|
|
3561
4567
|
releaseRootPaths: [...params.bookkeepingPaths],
|
|
4568
|
+
// waiting を複数回経た項目では、wait 時の同期後も統合先と exec branch の双方で
|
|
4569
|
+
// 記帳ファイルが変わる。項目自身の記帳ファイルだけの競合は exec branch 側で解決する。
|
|
4570
|
+
resolveConflictsWithBranchPaths: [...params.bookkeepingPaths],
|
|
3562
4571
|
failureLogPath: integrateLogPath(params.pipelineStatePath),
|
|
3563
|
-
})
|
|
3564
|
-
|
|
4572
|
+
}),
|
|
4573
|
+
record: (repo, patch) => recordRepoIntegration(params.pipelineStatePath, repo, patch),
|
|
4574
|
+
failureLogPath: integrateLogPath(params.pipelineStatePath),
|
|
4575
|
+
lockPath: schedulePath,
|
|
4576
|
+
});
|
|
3565
4577
|
// 撤去も統合の一部として扱う。merge 前に失敗した場合は waiting へ戻し、merge 後の撤去
|
|
3566
4578
|
// だけが失敗した場合は review を維持して `--resume` で cleanup だけをやり直す。撤去後の
|
|
3567
4579
|
// branch 削除だけが失敗した場合は、成果の統合を取り消さず cleanup 警告として扱う。
|
|
@@ -3615,11 +4627,13 @@ async function finalizeRegisterWorktreeRun(params) {
|
|
|
3615
4627
|
};
|
|
3616
4628
|
}
|
|
3617
4629
|
// 失敗 / rate limit: worktree は保持し(調査・再開のため)、waiting へ遷移する。
|
|
3618
|
-
const reason =
|
|
3619
|
-
?
|
|
3620
|
-
:
|
|
3621
|
-
? "
|
|
3622
|
-
:
|
|
4630
|
+
const reason = params.runnerBlockReason
|
|
4631
|
+
? params.runnerBlockReason
|
|
4632
|
+
: unfilledBlock
|
|
4633
|
+
? "agent exited 0 but result is incomplete or its frontmatter differs from the scaffold (treated as blocked)"
|
|
4634
|
+
: agentResult === "rate_limit"
|
|
4635
|
+
? "rate limit reached"
|
|
4636
|
+
: extractBlockReason(params.stderr);
|
|
3623
4637
|
await updateResultStatus(worktreeResultPath, "blocked", completedAt, sanitizeRegisterConclusion(reason));
|
|
3624
4638
|
process.stdout.write(`run failed: ${item.id} (status: waiting; worktree kept: ${worktree.path})\n`);
|
|
3625
4639
|
return waitSummary(reason);
|
|
@@ -3655,6 +4669,11 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3655
4669
|
context.roster?.members.find((m) => m.nickname === actor && m.type === "agent")?.provider;
|
|
3656
4670
|
const stem = buildInPlaceStem(pjrId.toLowerCase());
|
|
3657
4671
|
const worktreeTaskId = qualifyTaskId(projectId, item.id);
|
|
4672
|
+
const pipelineRunId = pipelineAgents
|
|
4673
|
+
? `${new Date().toISOString().replace(/[-:.]/g, "")}-${randomHex(4)}`
|
|
4674
|
+
: undefined;
|
|
4675
|
+
// PJR-98G4: repos を宣言した project では、プロダクトの worktree も同じタスクの下に作る。
|
|
4676
|
+
const products = configuredProductRepos(schedulePath);
|
|
3658
4677
|
// Phase 1: plan/result 生成 → register start → checkpoint → worktree 作成(root で直列化)。
|
|
3659
4678
|
const setup = async () => {
|
|
3660
4679
|
// executor が成功した run の worktree を、全体再実行が破棄しないよう保護する。
|
|
@@ -3672,7 +4691,7 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3672
4691
|
reason: sanitizeRegisterConclusion(protection),
|
|
3673
4692
|
};
|
|
3674
4693
|
}
|
|
3675
|
-
const discarded = discardStaleExecWorktree({ context: wtContext, worktreeTaskId });
|
|
4694
|
+
const discarded = discardStaleExecWorktree({ context: wtContext, worktreeTaskId, products });
|
|
3676
4695
|
if (discarded)
|
|
3677
4696
|
process.stdout.write(` [run] discarded stale worktree/branch: ${discarded}\n`);
|
|
3678
4697
|
const { planPath } = await generateRegisterPlan({
|
|
@@ -3702,6 +4721,15 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3702
4721
|
}
|
|
3703
4722
|
const checkpointRel = registerRunnerManagedPaths(repoRoot, registerPaths, planPath, resultPath, worktreeStatusPaths(repoRoot), ticketPath, supersededPaths);
|
|
3704
4723
|
const checkpointPaths = checkpointRel.map((rel) => resolve(repoRoot, rel));
|
|
4724
|
+
const checkpointFailureLogPath = pipelineRunId
|
|
4725
|
+
? integrateLogPath(pipelineStateLocation({
|
|
4726
|
+
repoRoot,
|
|
4727
|
+
worktreePath: repoRoot,
|
|
4728
|
+
executionPath,
|
|
4729
|
+
taskId: item.id,
|
|
4730
|
+
runId: pipelineRunId,
|
|
4731
|
+
}).path)
|
|
4732
|
+
: undefined;
|
|
3705
4733
|
try {
|
|
3706
4734
|
const worktree = checkpointAndEnsureWorktree({
|
|
3707
4735
|
context: wtContext,
|
|
@@ -3709,9 +4737,12 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3709
4737
|
base: worktreeBase,
|
|
3710
4738
|
checkpointPaths,
|
|
3711
4739
|
commitMessage: `exec(register ${item.id}): start`,
|
|
4740
|
+
products,
|
|
4741
|
+
failureLogPath: checkpointFailureLogPath,
|
|
3712
4742
|
});
|
|
3713
4743
|
const setupAction = worktree.created ? "setup" : "reuse";
|
|
3714
4744
|
process.stdout.write(` [run] ${setupAction}: worktree ${worktree.path} (${worktree.branch})\n`);
|
|
4745
|
+
reportProductWorktrees(worktree);
|
|
3715
4746
|
return {
|
|
3716
4747
|
worktree,
|
|
3717
4748
|
planPath,
|
|
@@ -3733,7 +4764,12 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3733
4764
|
ticketPath,
|
|
3734
4765
|
reason: `checkpoint failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3735
4766
|
actor,
|
|
3736
|
-
bookkeepingPaths:
|
|
4767
|
+
bookkeepingPaths: [
|
|
4768
|
+
...checkpointPaths,
|
|
4769
|
+
...(checkpointFailureLogPath && existsSync(checkpointFailureLogPath)
|
|
4770
|
+
? [checkpointFailureLogPath]
|
|
4771
|
+
: []),
|
|
4772
|
+
],
|
|
3737
4773
|
});
|
|
3738
4774
|
}
|
|
3739
4775
|
};
|
|
@@ -3742,7 +4778,7 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3742
4778
|
return prepared;
|
|
3743
4779
|
const { worktree, planPath, resultPath, resultScaffold, prompt, bookkeepingPaths } = prepared;
|
|
3744
4780
|
// Phase 2: agent を worktree 内で実行(ロック外・並列可能な長時間部分)。
|
|
3745
|
-
const env = agentEnvironment(repoRoot, worktree.path, schedulePath, executionPath);
|
|
4781
|
+
const env = agentEnvironment(repoRoot, worktree.path, schedulePath, executionPath, worktree.repos);
|
|
3746
4782
|
let agentResult;
|
|
3747
4783
|
let stderr = "";
|
|
3748
4784
|
// pipeline 実行のみ run state を持つ。統合段の記録先として Phase 3 へ渡す。
|
|
@@ -3761,7 +4797,11 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3761
4797
|
planPath,
|
|
3762
4798
|
planPrompt: prompt,
|
|
3763
4799
|
resultPath: worktreeResultPathForPipeline,
|
|
4800
|
+
registerPaths: registerReporterManagedPaths(registerPaths),
|
|
3764
4801
|
execDefaults: context.execDefaults,
|
|
4802
|
+
providerConcurrencyGate: context.providerConcurrencyGate,
|
|
4803
|
+
productWorktrees: worktree.repos,
|
|
4804
|
+
runId: pipelineRunId,
|
|
3765
4805
|
});
|
|
3766
4806
|
agentResult = pipelineOutcome.runResult;
|
|
3767
4807
|
stderr = pipelineOutcome.blockReason ?? "";
|
|
@@ -3769,7 +4809,7 @@ async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecycleLock
|
|
|
3769
4809
|
}
|
|
3770
4810
|
else {
|
|
3771
4811
|
process.stdout.write(`Running ${item.id} in worktree: ${command}\n CWD: ${worktree.path}\n`);
|
|
3772
|
-
const outcome = await runWithRetry([{ command, actor, provider: resolvedProvider }], prompt, context.execDefaults, worktree.path, env, pathInsideWorktree(repoRoot, worktree.path, resultPath));
|
|
4812
|
+
const outcome = await runWithRetry([{ command, actor, provider: resolvedProvider }], withProductRepoPrompt(prompt, worktree.repos), context.execDefaults, worktree.path, env, pathInsideWorktree(repoRoot, worktree.path, resultPath));
|
|
3773
4813
|
agentResult = outcome.result;
|
|
3774
4814
|
stderr = outcome.stderr;
|
|
3775
4815
|
}
|
|
@@ -3833,7 +4873,10 @@ export function resolveRegisterResumeReporter(roster, opts, execDefaults, record
|
|
|
3833
4873
|
return { kind: "error", message: resolution.message.replace(/^--by/, "--reporter-by") };
|
|
3834
4874
|
}
|
|
3835
4875
|
if (resolution.kind !== "command") {
|
|
3836
|
-
return {
|
|
4876
|
+
return {
|
|
4877
|
+
kind: "error",
|
|
4878
|
+
message: `reporter agent not found in agent-members.yaml: ${nickname}`,
|
|
4879
|
+
};
|
|
3837
4880
|
}
|
|
3838
4881
|
return {
|
|
3839
4882
|
kind: "command",
|
|
@@ -3859,7 +4902,10 @@ export function resolveRegisterResumeExecutor(roster, opts, execDefaults, record
|
|
|
3859
4902
|
return { kind: "error", message: resolution.message.replace(/^--by/, "--executor-by") };
|
|
3860
4903
|
}
|
|
3861
4904
|
if (resolution.kind !== "command") {
|
|
3862
|
-
return {
|
|
4905
|
+
return {
|
|
4906
|
+
kind: "error",
|
|
4907
|
+
message: `executor agent not found in agent-members.yaml: ${nickname}`,
|
|
4908
|
+
};
|
|
3863
4909
|
}
|
|
3864
4910
|
return {
|
|
3865
4911
|
kind: "command",
|
|
@@ -3882,6 +4928,7 @@ async function resumeRegisterIntegration(params) {
|
|
|
3882
4928
|
// waiting のまま統合しないよう、通常実行と同じく in-progress へ戻してから統合する。ただし
|
|
3883
4929
|
// merge 済みで worktree 撤去だけを再試行する場合は、root はすでに review なので遷移を
|
|
3884
4930
|
// 再記録しない(finalize は cleanup だけを行う)。
|
|
4931
|
+
let validationFailure;
|
|
3885
4932
|
if (!isExecBranchMergedIntoCurrent({
|
|
3886
4933
|
context: {
|
|
3887
4934
|
repoRoot: params.context.repoRoot,
|
|
@@ -3893,6 +4940,20 @@ async function resumeRegisterIntegration(params) {
|
|
|
3893
4940
|
const beginFailure = await params.begin(actor, "integration resumed");
|
|
3894
4941
|
if (beginFailure)
|
|
3895
4942
|
return beginFailure;
|
|
4943
|
+
// PJR-GENJ: 統合先の最新を取り込んだ worktree で親検証をやり直し、失敗なら統合せず waiting へ
|
|
4944
|
+
// 戻す。前回の親検証が失敗・未記録の場合も同じく検証してから統合する。
|
|
4945
|
+
if (target.stage === "integrate") {
|
|
4946
|
+
const evidence = await refreshParentValidationsForReporterResume({
|
|
4947
|
+
execDefaults: params.context.execDefaults,
|
|
4948
|
+
cwd: worktree.path,
|
|
4949
|
+
productWorktrees: worktree.repos,
|
|
4950
|
+
evidence: target.evidence,
|
|
4951
|
+
evidencePath: resolve(worktree.path, target.evidenceRef),
|
|
4952
|
+
force: params.syncedIntegrationTargets,
|
|
4953
|
+
stageLabel: "integration",
|
|
4954
|
+
});
|
|
4955
|
+
validationFailure = failedParentValidationReason(evidence.validations);
|
|
4956
|
+
}
|
|
3896
4957
|
}
|
|
3897
4958
|
// reporter が記入済みの result をそのまま使う。agent は起動しないため、成果は success 扱いで
|
|
3898
4959
|
// 統合だけを実行する(result が未記入なら finalize 側の downgrade が blocked に落とす)。
|
|
@@ -3906,10 +4967,11 @@ async function resumeRegisterIntegration(params) {
|
|
|
3906
4967
|
stem: params.stem,
|
|
3907
4968
|
worktreeResultPath,
|
|
3908
4969
|
resultScaffold,
|
|
3909
|
-
agentResult: "success",
|
|
3910
|
-
stderr: "",
|
|
4970
|
+
agentResult: validationFailure ? "failure" : "success",
|
|
4971
|
+
stderr: validationFailure ?? "",
|
|
4972
|
+
...(validationFailure ? { runnerBlockReason: validationFailure } : {}),
|
|
3911
4973
|
actor,
|
|
3912
|
-
bookkeepingPaths: params.bookkeepingPaths,
|
|
4974
|
+
bookkeepingPaths: params.bookkeepingPaths(),
|
|
3913
4975
|
pipelineStatePath: target.statePath,
|
|
3914
4976
|
resumedIntegration: true,
|
|
3915
4977
|
});
|
|
@@ -3940,15 +5002,25 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
3940
5002
|
};
|
|
3941
5003
|
};
|
|
3942
5004
|
const worktreeTaskId = qualifyTaskId(projectId, item.id);
|
|
3943
|
-
const
|
|
3944
|
-
if (!
|
|
5005
|
+
const foundWorktree = findExecWorktree(repoRoot, worktreeTaskId);
|
|
5006
|
+
if (!foundWorktree) {
|
|
3945
5007
|
return refuse(`no exec worktree to resume for ${item.id}; run the item again instead`);
|
|
3946
5008
|
}
|
|
5009
|
+
// PJR-98G4: プロダクトの worktree も揃っていることを再開の条件にする。欠けたまま再開すると、
|
|
5010
|
+
// agent がプロダクト側の変更先を失う。
|
|
5011
|
+
const products = configuredProductRepos(schedulePath);
|
|
5012
|
+
const worktree = withProductWorktrees(foundWorktree, products, worktreeTaskId);
|
|
5013
|
+
const missingProducts = missingProductWorktrees(products, worktree);
|
|
5014
|
+
if (missingProducts.length > 0) {
|
|
5015
|
+
return refuse(`product worktrees are missing for ${item.id}: ${missingProducts.join(", ")}; ` +
|
|
5016
|
+
`run the item again instead`);
|
|
5017
|
+
}
|
|
3947
5018
|
const lookup = findResumableRegisterRun({
|
|
3948
5019
|
repoRoot,
|
|
3949
5020
|
worktreePath: worktree.path,
|
|
3950
5021
|
executionPath,
|
|
3951
5022
|
taskId: item.id,
|
|
5023
|
+
...(opts.resumeFrom === "executor" ? { resumeFrom: "executor" } : {}),
|
|
3952
5024
|
});
|
|
3953
5025
|
if (lookup.kind !== "resumable")
|
|
3954
5026
|
return refuse(lookup.reason);
|
|
@@ -3967,7 +5039,10 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
3967
5039
|
return refuse(`result not found in the worktree: ${artifacts.resultRef}`);
|
|
3968
5040
|
}
|
|
3969
5041
|
// root 側の実行管理ファイル。plan / result は前回の wait commit で統合ブランチに入っている。
|
|
3970
|
-
|
|
5042
|
+
// begin は個票と event を root へ写し、派生ビューを再生成する。その後の差分を拾うため、
|
|
5043
|
+
// 再開開始前に集合を固定せず finalize の直前に評価する。
|
|
5044
|
+
const bookkeepingPaths = () => registerBookkeepingPaths({
|
|
5045
|
+
repoRoot,
|
|
3971
5046
|
registerPaths,
|
|
3972
5047
|
planPath: resolve(repoRoot, artifacts.planRef),
|
|
3973
5048
|
resultPath: resolve(repoRoot, artifacts.resultRef),
|
|
@@ -3989,6 +5064,40 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
3989
5064
|
};
|
|
3990
5065
|
return lifecycleLock ? lifecycleLock.runExclusive(start) : start();
|
|
3991
5066
|
};
|
|
5067
|
+
// PJR-GENJ / PJR-PG6W: どの段の再開でも、親検証または agent の起動前に統合先の最新を exec
|
|
5068
|
+
// branch と worktree へ取り込む。wait 後に統合先で直した不具合や、人が適用した保護対象設定を
|
|
5069
|
+
// executor に反映するためである。register の遷移(begin)より前に行い、取り込めない場合は状態を
|
|
5070
|
+
// 変えずに再開を拒否する。merge 済みで撤去だけが残る統合再開は取り込まない。
|
|
5071
|
+
// PJR-6RN3: 前回の統合段で統合済み(merged / unchanged)と記録されたプロダクトも取り込まない。
|
|
5072
|
+
// 取り込むと exec branch に新しい merge commit ができ、統合段がそのプロダクトを再び統合する。
|
|
5073
|
+
let syncedIntegrationTargets = false;
|
|
5074
|
+
if (!isExecBranchMergedIntoCurrent({
|
|
5075
|
+
context: { repoRoot, schedulePath, executionPath },
|
|
5076
|
+
worktree,
|
|
5077
|
+
})) {
|
|
5078
|
+
let synced;
|
|
5079
|
+
try {
|
|
5080
|
+
const projectTarget = currentBranch(repoRoot);
|
|
5081
|
+
process.stdout.write(` Syncing integration targets before ${target.stage} resume: ${item.id}\n`);
|
|
5082
|
+
synced = syncTaskWorktreesWithIntegrationTargets({
|
|
5083
|
+
worktree,
|
|
5084
|
+
projectTarget,
|
|
5085
|
+
message: `exec(register ${item.id}): merge integration target before resume`,
|
|
5086
|
+
projectTheirsPaths: bookkeepingPaths().map((path) => repoRelativePath(repoRoot, path)),
|
|
5087
|
+
integratedProducts: integratedRepoNames(target.state),
|
|
5088
|
+
});
|
|
5089
|
+
}
|
|
5090
|
+
catch (error) {
|
|
5091
|
+
return refuse(`cannot sync the worktree with the integration target before resume: ` +
|
|
5092
|
+
`${error instanceof Error ? error.message : String(error)}; ` +
|
|
5093
|
+
`resolve it in ${worktree.path} and resume again`);
|
|
5094
|
+
}
|
|
5095
|
+
for (const entry of synced) {
|
|
5096
|
+
process.stdout.write(` [sync] ${entry.repo}: ${entry.status} (${entry.target})` +
|
|
5097
|
+
`${entry.detail ? ` — ${entry.detail}` : ""}\n`);
|
|
5098
|
+
}
|
|
5099
|
+
syncedIntegrationTargets = synced.some((entry) => entry.status === "merged");
|
|
5100
|
+
}
|
|
3992
5101
|
if (target.stage === "integrate") {
|
|
3993
5102
|
// 統合は runner の作業だが、register の遷移とイベントには実行者が必要になる。前回 run の
|
|
3994
5103
|
// reporter(無ければ executor)を引き継ぎ、--reporter-by で明示指定もできる。
|
|
@@ -4012,6 +5121,7 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
4012
5121
|
bookkeepingPaths,
|
|
4013
5122
|
begin,
|
|
4014
5123
|
lifecycleLock,
|
|
5124
|
+
syncedIntegrationTargets,
|
|
4015
5125
|
});
|
|
4016
5126
|
}
|
|
4017
5127
|
// plan は root(統合ブランチ)の checkpoint 済みファイルを正本にする。worktree 側の plan は
|
|
@@ -4028,7 +5138,7 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
4028
5138
|
if (reporter.kind === "error")
|
|
4029
5139
|
return refuse(reporter.message);
|
|
4030
5140
|
process.stdout.write(`Register item: ${item.id} — ${item.title} [${item.type}]\n`);
|
|
4031
|
-
process.stdout.write(` Resuming executor from
|
|
5141
|
+
process.stdout.write(` Resuming executor from run ${target.runId} in a new pipeline checkpoint\n` +
|
|
4032
5142
|
` CWD: ${worktree.path}\n Agent: ${executor.candidate.actor} (executor)\n`);
|
|
4033
5143
|
const beginFailure = await begin(executor.candidate.actor, "executor resumed");
|
|
4034
5144
|
if (beginFailure)
|
|
@@ -4045,7 +5155,13 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
4045
5155
|
planPath,
|
|
4046
5156
|
planPrompt: prompt,
|
|
4047
5157
|
resultPath: worktreeResultPath,
|
|
5158
|
+
registerPaths: registerReporterManagedPaths(registerPaths),
|
|
4048
5159
|
execDefaults: context.execDefaults,
|
|
5160
|
+
resumedExecutor: true,
|
|
5161
|
+
initialChangeTargets: target.initialChanges,
|
|
5162
|
+
resumeHandoff: target.handoff,
|
|
5163
|
+
providerConcurrencyGate: context.providerConcurrencyGate,
|
|
5164
|
+
productWorktrees: worktree.repos,
|
|
4049
5165
|
});
|
|
4050
5166
|
const finalize = async () => finalizeRegisterWorktreeRun({
|
|
4051
5167
|
context,
|
|
@@ -4059,7 +5175,7 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
4059
5175
|
agentResult: outcome.runResult,
|
|
4060
5176
|
stderr: outcome.blockReason ?? "",
|
|
4061
5177
|
actor: executor.candidate.actor,
|
|
4062
|
-
bookkeepingPaths,
|
|
5178
|
+
bookkeepingPaths: bookkeepingPaths(),
|
|
4063
5179
|
pipelineStatePath: resolve(worktree.path, outcome.stateRef),
|
|
4064
5180
|
});
|
|
4065
5181
|
return lifecycleLock ? lifecycleLock.runExclusive(finalize) : finalize();
|
|
@@ -4076,8 +5192,10 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
4076
5192
|
const evidence = await refreshParentValidationsForReporterResume({
|
|
4077
5193
|
execDefaults: context.execDefaults,
|
|
4078
5194
|
cwd: worktree.path,
|
|
5195
|
+
productWorktrees: worktree.repos,
|
|
4079
5196
|
evidence: target.evidence,
|
|
4080
5197
|
evidencePath: resolve(worktree.path, target.evidenceRef),
|
|
5198
|
+
force: syncedIntegrationTargets,
|
|
4081
5199
|
});
|
|
4082
5200
|
const resultScaffold = readResultFrontmatterSnapshot(worktreeResultPath);
|
|
4083
5201
|
const outcome = await runReporterStage({
|
|
@@ -4088,11 +5206,14 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
4088
5206
|
reporterCandidates: [reporter.candidate],
|
|
4089
5207
|
planPrompt: prompt,
|
|
4090
5208
|
resultPath: worktreeResultPath,
|
|
5209
|
+
registerPaths: registerReporterManagedPaths(registerPaths),
|
|
4091
5210
|
execDefaults: context.execDefaults,
|
|
4092
5211
|
evidence,
|
|
4093
5212
|
evidencePath: resolve(worktree.path, target.evidenceRef),
|
|
4094
5213
|
state: target.state,
|
|
4095
5214
|
statePath: target.statePath,
|
|
5215
|
+
providerConcurrencyGate: context.providerConcurrencyGate,
|
|
5216
|
+
productWorktrees: worktree.repos,
|
|
4096
5217
|
});
|
|
4097
5218
|
const finalize = async () => finalizeRegisterWorktreeRun({
|
|
4098
5219
|
context,
|
|
@@ -4106,7 +5227,7 @@ async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lifecycleL
|
|
|
4106
5227
|
agentResult: outcome.runResult,
|
|
4107
5228
|
stderr: outcome.blockReason ?? "",
|
|
4108
5229
|
actor: reporter.candidate.actor,
|
|
4109
|
-
bookkeepingPaths,
|
|
5230
|
+
bookkeepingPaths: bookkeepingPaths(),
|
|
4110
5231
|
pipelineStatePath: target.statePath,
|
|
4111
5232
|
});
|
|
4112
5233
|
return lifecycleLock ? lifecycleLock.runExclusive(finalize) : finalize();
|
|
@@ -4136,13 +5257,19 @@ async function runRegisterMode(opts) {
|
|
|
4136
5257
|
const selectedIds = selectionFilter
|
|
4137
5258
|
? selectRegisterItems(loadRegisterItems(resolveRegisterPaths({ project: projectId })).map((view) => view.item), selectionFilter).map((item) => item.id)
|
|
4138
5259
|
: undefined;
|
|
4139
|
-
if (selectedIds?.length === 0) {
|
|
4140
|
-
process.stdout.write("No matching register items.\n");
|
|
4141
|
-
return;
|
|
4142
|
-
}
|
|
4143
5260
|
const { ids, duplicates } = selectedIds
|
|
4144
5261
|
? { ids: selectedIds, duplicates: [] }
|
|
4145
5262
|
: parseRegisterIds(opts.register);
|
|
5263
|
+
const executorSelection = parseRegisterExecutorSelection(opts.executorBy, ids);
|
|
5264
|
+
if (ids.length === 0) {
|
|
5265
|
+
process.stdout.write("No matching register items.\n");
|
|
5266
|
+
return;
|
|
5267
|
+
}
|
|
5268
|
+
const hasExecutorSelection = executorSelection.kind !== "none";
|
|
5269
|
+
const optsForItem = (pjrId) => ({
|
|
5270
|
+
...opts,
|
|
5271
|
+
executorBy: selectedRegisterExecutor(executorSelection, pjrId),
|
|
5272
|
+
});
|
|
4146
5273
|
for (const duplicate of duplicates) {
|
|
4147
5274
|
process.stdout.write(`Skipping duplicate register item id: ${duplicate}\n`);
|
|
4148
5275
|
}
|
|
@@ -4155,7 +5282,7 @@ async function runRegisterMode(opts) {
|
|
|
4155
5282
|
// 再開は state が示す段だけを実行する。stale executor の再実行では各 agent の明示指定を
|
|
4156
5283
|
// 個別に許可し、省略時は state に記録された actor を使う。
|
|
4157
5284
|
if (!opts.resume &&
|
|
4158
|
-
((
|
|
5285
|
+
((hasExecutorSelection && !opts.reporterBy) || (!hasExecutorSelection && opts.reporterBy))) {
|
|
4159
5286
|
throw new Error("--register pipeline execution requires both --executor-by and --reporter-by.");
|
|
4160
5287
|
}
|
|
4161
5288
|
const roster = loadRosterForExecutionPath(executionPath);
|
|
@@ -4178,6 +5305,7 @@ async function runRegisterMode(opts) {
|
|
|
4178
5305
|
worktreePath: worktree.path,
|
|
4179
5306
|
executionPath,
|
|
4180
5307
|
taskId: item.id,
|
|
5308
|
+
...(opts.resumeFrom === "executor" ? { resumeFrom: "executor" } : {}),
|
|
4181
5309
|
});
|
|
4182
5310
|
process.stdout.write(lookup.kind === "resumable"
|
|
4183
5311
|
? `[dry-run] ${item.id}: resume the ${lookup.target.stage} stage of run ${lookup.target.runId} in ${worktree.path}\n`
|
|
@@ -4192,19 +5320,20 @@ async function runRegisterMode(opts) {
|
|
|
4192
5320
|
process.stdout.write(`[dry-run] register items (${modeLabel}): ${ids.join(", ")} [on-failure: ${failureMode}, commit: ${useWorktree ? "always (worktree)" : opts.registerCommit ? "per-id" : "off"}]\n`);
|
|
4193
5321
|
const pipelineMode = isRegisterPipelineRequested(opts);
|
|
4194
5322
|
for (const pjrId of ids) {
|
|
5323
|
+
const itemOpts = optsForItem(pjrId);
|
|
4195
5324
|
const { item } = resolveRegisterRunTarget(projectId, pjrId);
|
|
4196
5325
|
const category = requireRunnableRegisterItem(item);
|
|
4197
5326
|
const stem = buildInPlaceStem(pjrId.toLowerCase());
|
|
4198
5327
|
process.stdout.write(`[dry-run] register item: ${item.id} — ${item.title} [${item.type}/${category}]\n`);
|
|
4199
5328
|
if (pipelineMode) {
|
|
4200
|
-
const { executor, reporterCandidates } = resolveRegisterPipelineCommand(roster,
|
|
5329
|
+
const { executor, reporterCandidates } = resolveRegisterPipelineCommand(roster, itemOpts, execDefaults);
|
|
4201
5330
|
process.stdout.write(`[dry-run] executor: ${executor.actor}\n`);
|
|
4202
5331
|
process.stdout.write(`[dry-run] executor command: ${executor.command}\n`);
|
|
4203
5332
|
process.stdout.write(`[dry-run] reporter: ${reporterCandidates[0]?.actor}\n`);
|
|
4204
5333
|
process.stdout.write(`[dry-run] reporter command: ${reporterCandidates[0]?.command}\n`);
|
|
4205
5334
|
}
|
|
4206
5335
|
else {
|
|
4207
|
-
const { command, actor } = resolveRegisterCommand(item, roster,
|
|
5336
|
+
const { command, actor } = resolveRegisterCommand(item, roster, itemOpts, execDefaults);
|
|
4208
5337
|
process.stdout.write(`[dry-run] actor: ${actor}\n`);
|
|
4209
5338
|
process.stdout.write(`[dry-run] command: ${command}\n`);
|
|
4210
5339
|
}
|
|
@@ -4221,6 +5350,9 @@ async function runRegisterMode(opts) {
|
|
|
4221
5350
|
repoRoot,
|
|
4222
5351
|
roster,
|
|
4223
5352
|
execDefaults,
|
|
5353
|
+
// provider の max_concurrency は、同じ project の exec run(主 run と --join run)を跨いで
|
|
5354
|
+
// ロックディレクトリの枠で統制する。
|
|
5355
|
+
providerConcurrencyGate: new ProviderConcurrencyGate(execDefaults, execLocksDir(executionPath)),
|
|
4224
5356
|
registerCommit: !!opts.registerCommit,
|
|
4225
5357
|
worktree: useWorktree,
|
|
4226
5358
|
worktreeBase,
|
|
@@ -4237,12 +5369,20 @@ async function runRegisterMode(opts) {
|
|
|
4237
5369
|
// 再開は既存 worktree の reporter 段だけを実行する。それ以外の経路(plan 生成・executor 実行)
|
|
4238
5370
|
// は通らないため、通常実行と同じ並列・直列の枠だけを共有する。
|
|
4239
5371
|
const runItem = (pjrId, lifecycleLock) => opts.resume
|
|
4240
|
-
? resumeSingleRegisterItemWorktree(context,
|
|
4241
|
-
: runSingleRegisterItemWorktree(context,
|
|
5372
|
+
? resumeSingleRegisterItemWorktree(context, optsForItem(pjrId), pjrId, lifecycleLock)
|
|
5373
|
+
: runSingleRegisterItemWorktree(context, optsForItem(pjrId), pjrId, lifecycleLock);
|
|
5374
|
+
// worktree 実行の root 側の手順(start 遷移・checkpoint・merge・wait commit・派生ビューの
|
|
5375
|
+
// 再生成)は、同じ project の別プロセス(--join run)とも重ならないよう、ロックディレクトリの
|
|
5376
|
+
// mutex で直列化する。一方の run が root に記帳ファイルを書いている途中で、もう一方の統合が
|
|
5377
|
+
// 始まらない。直列実行でも別プロセスと重なり得るため、並列・直列の両方で使う。
|
|
5378
|
+
const lifecycleLock = useWorktree
|
|
5379
|
+
? new CrossProcessMutex(execLifecyclePoolPath(executionPath), { actor: opts.by ?? "exec-run", label: ids.join(",") }, {
|
|
5380
|
+
onWait: () => process.stdout.write(" Waiting for the register lifecycle lock held by another exec run\n"),
|
|
5381
|
+
})
|
|
5382
|
+
: undefined;
|
|
4242
5383
|
if (useWorktree && parallel > 1) {
|
|
4243
5384
|
// 並列実行: 成果物は worktree ごとに隔離し、状態遷移は lifecycleLock で直列化する。
|
|
4244
5385
|
// stop 指定でも実行中の項目は完走し、未着手の残りだけを skipped にする。
|
|
4245
|
-
const lifecycleLock = new SerialAsyncLock();
|
|
4246
5386
|
const queue = [...ids];
|
|
4247
5387
|
const byId = new Map();
|
|
4248
5388
|
let stop = false;
|
|
@@ -4269,8 +5409,8 @@ async function runRegisterMode(opts) {
|
|
|
4269
5409
|
continue;
|
|
4270
5410
|
}
|
|
4271
5411
|
const summary = useWorktree
|
|
4272
|
-
? await runItem(pjrId)
|
|
4273
|
-
: await runSingleRegisterItem(context,
|
|
5412
|
+
? await runItem(pjrId, lifecycleLock)
|
|
5413
|
+
: await runSingleRegisterItem(context, optsForItem(pjrId), pjrId);
|
|
4274
5414
|
summaries.push(summary);
|
|
4275
5415
|
if (summary.outcome === "failure" && failureMode === "stop")
|
|
4276
5416
|
stopped = true;
|
|
@@ -4286,12 +5426,12 @@ export function registerRunCommand(exec) {
|
|
|
4286
5426
|
.command("run")
|
|
4287
5427
|
.description("Run AI agent for a ready task (--auto selects next by strategy)");
|
|
4288
5428
|
rcmd.option("--project <projectId>", "Project id in .specdojo/specdojo.config.json");
|
|
4289
|
-
rcmd.option("--by <nickname>", "Select
|
|
5429
|
+
rcmd.option("--by <nickname>", "Select an agent-members.yaml agent for a manual target");
|
|
4290
5430
|
rcmd.option("--auto", "Automatically select and run next ready task", false);
|
|
4291
5431
|
rcmd.option("--task <taskId>", "Task ID to run (manual selection)");
|
|
4292
5432
|
rcmd.option("--deliverable <localId>", "Catalog deliverable local_id target (unique project-wide)");
|
|
4293
5433
|
rcmd.option("--plan <path>", "Run an existing plan file (in-place; no generation)");
|
|
4294
|
-
rcmd.option("--register <pjrIds...>", "One or more project register item IDs (PJR-XXXX) to run;
|
|
5434
|
+
rcmd.option("--register <pjrIds...>", "One or more project register item IDs (PJR-XXXX) to run; execution location defaults to run.register_execution in exec-defaults (in-place when unset)");
|
|
4295
5435
|
rcmd.option("--register-filter", "Select register items deterministically with --register-types/--register-priorities/--register-statuses/--register-limit", false);
|
|
4296
5436
|
rcmd.option("--register-types <types>", "Comma-separated register item types");
|
|
4297
5437
|
rcmd.option("--register-priorities <priorities>", "Comma-separated register priorities");
|
|
@@ -4301,11 +5441,13 @@ export function registerRunCommand(exec) {
|
|
|
4301
5441
|
rcmd.option("--input <key=value...>", "Job input values (repeat or provide multiple key=value pairs)");
|
|
4302
5442
|
rcmd.option("--scheduled-at <dateTime>", "Scheduled occurrence time for a Job Run");
|
|
4303
5443
|
rcmd.option("--job-trigger <source>", "Job trigger source: manual|routine|ci", "manual");
|
|
4304
|
-
rcmd.option("--register-commit", "With
|
|
5444
|
+
rcmd.option("--register-commit", "With in-place --register: commit each successful item's changes as a separate commit (default: leave changes in the working tree). Ignored in worktree mode, which always commits", false);
|
|
4305
5445
|
rcmd.option("--on-failure <mode>", "With --register: stop|continue remaining items after a failure (default: stop)");
|
|
4306
|
-
rcmd.option("--resume", "With
|
|
4307
|
-
rcmd.option("--
|
|
4308
|
-
rcmd.option("--
|
|
5446
|
+
rcmd.option("--resume", "With register worktree mode: resume the stage where a run stopped (executor, reporter, or integration), reusing the existing worktree and checkpoints", false);
|
|
5447
|
+
rcmd.option("--resume-from <stage>", "With --resume: resume a reporter-stage run from executor instead (accepted value: executor)");
|
|
5448
|
+
rcmd.option("--force-restart", "With register worktree mode: re-run the whole item even when a resumable executor result exists (discards the worktree and its uncommitted changes)", false);
|
|
5449
|
+
rcmd.option("--worktree", "Use a git worktree and integrate back (requires --task, --register, or --job; Job runs are committed and reviewed before merge)", false);
|
|
5450
|
+
rcmd.option("--in-place", "Run a register item in the current working tree (overrides run.register_execution; cannot be combined with --worktree)", false);
|
|
4309
5451
|
rcmd.option("--track-state", "Record claim/complete events (requires --task; --by optional, actor auto-derived from the resolved agent)", false);
|
|
4310
5452
|
rcmd.option("--archive-on-success", "Archive the generated plan to exec/plans/done/ after a successful in-place run", false);
|
|
4311
5453
|
rcmd.option("--parallel <n>", "Number of worktree instances to run in parallel", "1");
|
|
@@ -4314,12 +5456,13 @@ export function registerRunCommand(exec) {
|
|
|
4314
5456
|
rcmd.option("--loop", "Repeat rounds until no ready tasks remain, rebuilding doc-index and running exec refresh between rounds", false);
|
|
4315
5457
|
rcmd.option("--max-rounds <n>", "Maximum number of rounds when using --loop (ignored without --loop)");
|
|
4316
5458
|
rcmd.option("--if-busy <policy>", "When another exec is running for the project: skip|wait|fail (default: fail)", "fail");
|
|
5459
|
+
rcmd.option("--join", "With register worktree mode: run next to a running register worktree exec instead of waiting for it, sharing its provider caps, lifecycle serialization, and parent-validation slots (up to run.max_concurrent_runs; --if-busy applies when all join slots are taken)", false);
|
|
4317
5460
|
rcmd.option("--exec-defaults <path>", "Path to exec-defaults.yaml global config (default: .specdojo/exec-defaults.yaml)");
|
|
4318
5461
|
rcmd.option("--agent-config <path>", "Deprecated alias for --exec-defaults");
|
|
4319
|
-
rcmd.option("--edit-by <nickname>", "
|
|
4320
|
-
rcmd.option("--review-by <nickname>", "
|
|
4321
|
-
rcmd.option("--executor-by <nickname>", "
|
|
4322
|
-
rcmd.option("--reporter-by <nickname>", "
|
|
5462
|
+
rcmd.option("--edit-by <nickname>", "agent-members.yaml nickname for edit-mode tasks in --auto batch runs");
|
|
5463
|
+
rcmd.option("--review-by <nickname>", "agent-members.yaml nickname for review-mode tasks in --auto batch runs");
|
|
5464
|
+
rcmd.option("--executor-by <nickname>", "Executor nickname; with --register, also accepts PJR-ID=nickname assignments separated by commas. With --plan / --deliverable, runs the executor/reporter pipeline");
|
|
5465
|
+
rcmd.option("--reporter-by <nickname>", "agent-members.yaml reporter nickname for agent_pipeline tasks (with --plan / --deliverable, runs the executor/reporter pipeline)");
|
|
4323
5466
|
rcmd.option("--dry-run", "Print resolved command without executing", false);
|
|
4324
5467
|
rcmd.action(async (opts) => {
|
|
4325
5468
|
try {
|
|
@@ -4362,13 +5505,33 @@ export function registerRunCommand(exec) {
|
|
|
4362
5505
|
process.exitCode = 1;
|
|
4363
5506
|
return;
|
|
4364
5507
|
}
|
|
5508
|
+
if (opts.worktree && opts.inPlace) {
|
|
5509
|
+
process.stdout.write("Specify either --worktree or --in-place, not both.\n");
|
|
5510
|
+
process.exitCode = 1;
|
|
5511
|
+
return;
|
|
5512
|
+
}
|
|
5513
|
+
if (opts.inPlace && !hasRegister) {
|
|
5514
|
+
process.stdout.write("--in-place requires --register or --register-filter.\n");
|
|
5515
|
+
process.exitCode = 1;
|
|
5516
|
+
return;
|
|
5517
|
+
}
|
|
5518
|
+
if (hasRegister) {
|
|
5519
|
+
const { schedulePath, executionPath } = resolveProjectPaths({ project: opts.project });
|
|
5520
|
+
const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
|
|
5521
|
+
opts.worktree = resolveRegisterWorktree(opts, execDefaults);
|
|
5522
|
+
}
|
|
4365
5523
|
if (hasRegister && !opts.worktree && parseParallel(opts.parallel) !== 1) {
|
|
4366
|
-
process.stdout.write("--parallel with --register requires --worktree
|
|
5524
|
+
process.stdout.write("--parallel with --register requires worktree mode; use --worktree or configure run.register_execution: worktree.\n");
|
|
5525
|
+
process.exitCode = 1;
|
|
5526
|
+
return;
|
|
5527
|
+
}
|
|
5528
|
+
if (opts.join && !(hasRegister && opts.worktree)) {
|
|
5529
|
+
process.stdout.write("--join requires --register (or --register-filter) in worktree mode.\n");
|
|
4367
5530
|
process.exitCode = 1;
|
|
4368
5531
|
return;
|
|
4369
5532
|
}
|
|
4370
5533
|
if (hasRegister && opts.worktree && opts.registerCommit) {
|
|
4371
|
-
process.stdout.write("Note: --register-commit is ignored
|
|
5534
|
+
process.stdout.write("Note: --register-commit is ignored in worktree mode; worktree runs always commit (checkpoint + merge back).\n");
|
|
4372
5535
|
}
|
|
4373
5536
|
if ((opts.registerCommit || opts.onFailure) && !hasRegister) {
|
|
4374
5537
|
process.stdout.write("--register-commit and --on-failure require --register.\n");
|
|
@@ -4380,10 +5543,20 @@ export function registerRunCommand(exec) {
|
|
|
4380
5543
|
process.exitCode = 1;
|
|
4381
5544
|
return;
|
|
4382
5545
|
}
|
|
5546
|
+
if (opts.resumeFrom && !opts.resume) {
|
|
5547
|
+
process.stdout.write("--resume-from requires --resume.\n");
|
|
5548
|
+
process.exitCode = 1;
|
|
5549
|
+
return;
|
|
5550
|
+
}
|
|
5551
|
+
if (opts.resumeFrom && opts.resumeFrom !== "executor") {
|
|
5552
|
+
process.stdout.write('--resume-from must be "executor".\n');
|
|
5553
|
+
process.exitCode = 1;
|
|
5554
|
+
return;
|
|
5555
|
+
}
|
|
4383
5556
|
// 再開は既存 worktree の成果を再利用する操作のため、worktree 実行に限る。in-place 実行は
|
|
4384
5557
|
// executor の変更が作業ツリーに残り、再開時のID単位 commit が対象を判別できない。
|
|
4385
5558
|
if ((opts.resume || opts.forceRestart) && !opts.worktree) {
|
|
4386
|
-
process.stdout.write("--resume and --force-restart require --worktree
|
|
5559
|
+
process.stdout.write("--resume and --force-restart require register worktree mode; use --worktree or configure run.register_execution: worktree.\n");
|
|
4387
5560
|
process.exitCode = 1;
|
|
4388
5561
|
return;
|
|
4389
5562
|
}
|
|
@@ -4402,11 +5575,6 @@ export function registerRunCommand(exec) {
|
|
|
4402
5575
|
process.exitCode = 1;
|
|
4403
5576
|
return;
|
|
4404
5577
|
}
|
|
4405
|
-
if (hasJob && opts.worktree) {
|
|
4406
|
-
process.stdout.write("--worktree is not yet supported with --job.\n");
|
|
4407
|
-
process.exitCode = 1;
|
|
4408
|
-
return;
|
|
4409
|
-
}
|
|
4410
5578
|
if (opts.onFailure && !isRegisterFailureMode(opts.onFailure)) {
|
|
4411
5579
|
process.stdout.write(`--on-failure must be "stop" or "continue": ${opts.onFailure}\n`);
|
|
4412
5580
|
process.exitCode = 1;
|
|
@@ -4427,8 +5595,8 @@ export function registerRunCommand(exec) {
|
|
|
4427
5595
|
process.exitCode = 1;
|
|
4428
5596
|
return;
|
|
4429
5597
|
}
|
|
4430
|
-
if (opts.worktree && !hasTask && !hasRegister) {
|
|
4431
|
-
process.stdout.write("--worktree requires --task or --
|
|
5598
|
+
if (opts.worktree && !hasTask && !hasRegister && !hasJob) {
|
|
5599
|
+
process.stdout.write("--worktree requires --task, --register, or --job.\n");
|
|
4432
5600
|
process.exitCode = 1;
|
|
4433
5601
|
return;
|
|
4434
5602
|
}
|
|
@@ -4439,8 +5607,11 @@ export function registerRunCommand(exec) {
|
|
|
4439
5607
|
process.exitCode = 1;
|
|
4440
5608
|
return;
|
|
4441
5609
|
}
|
|
5610
|
+
// register worktree 実行だけが共有資源をプロセス横断で統制するため、後から --join する
|
|
5611
|
+
// run を受け入れる。それ以外の run は従来どおり project 全体を排他する。
|
|
5612
|
+
const registerWorktreeLockSharing = hasRegister && opts.worktree ? { shareable: true, join: !!opts.join } : EXCLUSIVE_EXEC_RUN;
|
|
4442
5613
|
await withProjectExecRunLock(opts, "run", async () => {
|
|
4443
|
-
// Register-item run:
|
|
5614
|
+
// Register-item run: use the configured location or an explicit CLI override, with state tracked
|
|
4444
5615
|
// via register transitions (start → review / waiting) instead of exec events.
|
|
4445
5616
|
if (hasRegister) {
|
|
4446
5617
|
await runRegisterMode(opts);
|
|
@@ -4475,7 +5646,59 @@ export function registerRunCommand(exec) {
|
|
|
4475
5646
|
else {
|
|
4476
5647
|
await runManualMode(opts);
|
|
4477
5648
|
}
|
|
4478
|
-
});
|
|
5649
|
+
}, registerWorktreeLockSharing);
|
|
5650
|
+
}
|
|
5651
|
+
catch (error) {
|
|
5652
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5653
|
+
process.stdout.write(message + "\n");
|
|
5654
|
+
process.exitCode = 1;
|
|
5655
|
+
}
|
|
5656
|
+
});
|
|
5657
|
+
}
|
|
5658
|
+
// 同じ project の exec run が共有する枠(主 run・--join run・register lifecycle・provider の
|
|
5659
|
+
// max_concurrency・親検証)の上限と現在の使用数を表示する。ロックは取得しない。
|
|
5660
|
+
export function formatExecSlotsReport(executionPath, execDefaults) {
|
|
5661
|
+
const lockRoot = execLocksDir(executionPath);
|
|
5662
|
+
const providers = Object.keys(execDefaults.providers ?? {}).sort();
|
|
5663
|
+
const providerPools = providers.flatMap((provider) => {
|
|
5664
|
+
const cap = resolveMaxConcurrency(execDefaults, provider);
|
|
5665
|
+
return cap === undefined
|
|
5666
|
+
? []
|
|
5667
|
+
: [
|
|
5668
|
+
{
|
|
5669
|
+
name: `provider ${provider}`,
|
|
5670
|
+
path: providerSlotPoolPath(lockRoot, provider),
|
|
5671
|
+
limit: cap,
|
|
5672
|
+
},
|
|
5673
|
+
];
|
|
5674
|
+
});
|
|
5675
|
+
const parentValidationPools = execDefaults.pipeline?.parent_validations?.length
|
|
5676
|
+
? [
|
|
5677
|
+
{
|
|
5678
|
+
name: "parent validations",
|
|
5679
|
+
path: parentValidationPoolPath(lockRoot),
|
|
5680
|
+
limit: resolveParentValidationConcurrency(execDefaults.pipeline.parent_validation_concurrency),
|
|
5681
|
+
},
|
|
5682
|
+
]
|
|
5683
|
+
: [];
|
|
5684
|
+
const entries = collectExecLockUsage(executionPath, {
|
|
5685
|
+
joinLimit: resolveMaxConcurrentRuns(execDefaults) - 1,
|
|
5686
|
+
pools: [...providerPools, ...parentValidationPools],
|
|
5687
|
+
});
|
|
5688
|
+
return (`max concurrent runs: ${resolveMaxConcurrentRuns(execDefaults)}\n` +
|
|
5689
|
+
formatExecLockUsage(entries));
|
|
5690
|
+
}
|
|
5691
|
+
export function registerSlotsCommand(exec) {
|
|
5692
|
+
const cmd = exec
|
|
5693
|
+
.command("slots")
|
|
5694
|
+
.description("Show the limits and current usage of the slots shared by concurrent exec runs of a project");
|
|
5695
|
+
cmd.option("--project <projectId>", "Project id in .specdojo/specdojo.config.json");
|
|
5696
|
+
cmd.option("--exec-defaults <path>", "Path to exec-defaults.yaml global config (default: .specdojo/exec-defaults.yaml)");
|
|
5697
|
+
cmd.action((opts) => {
|
|
5698
|
+
try {
|
|
5699
|
+
const { schedulePath, executionPath } = resolveProjectPaths({ project: opts.project });
|
|
5700
|
+
const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
|
|
5701
|
+
process.stdout.write(formatExecSlotsReport(executionPath, execDefaults));
|
|
4479
5702
|
}
|
|
4480
5703
|
catch (error) {
|
|
4481
5704
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -4656,10 +5879,10 @@ export function registerCycleCommand(exec) {
|
|
|
4656
5879
|
cmd.option("--parallel <n>", "Number of tasks to resume / run in parallel", "1");
|
|
4657
5880
|
cmd.option("--loop", "Repeat the auto step until no Ready tasks remain", false);
|
|
4658
5881
|
cmd.option("--max-rounds <n>", "Maximum number of auto rounds when using --loop");
|
|
4659
|
-
cmd.option("--edit-by <nickname>", "
|
|
4660
|
-
cmd.option("--review-by <nickname>", "
|
|
4661
|
-
cmd.option("--executor-by <nickname>", "
|
|
4662
|
-
cmd.option("--reporter-by <nickname>", "
|
|
5882
|
+
cmd.option("--edit-by <nickname>", "agent-members.yaml nickname for edit-mode tasks (resume + auto)");
|
|
5883
|
+
cmd.option("--review-by <nickname>", "agent-members.yaml nickname for review-mode tasks (resume + auto)");
|
|
5884
|
+
cmd.option("--executor-by <nickname>", "agent-members.yaml executor nickname for pipeline tasks (resume + auto)");
|
|
5885
|
+
cmd.option("--reporter-by <nickname>", "agent-members.yaml reporter nickname for pipeline tasks (resume + auto)");
|
|
4663
5886
|
cmd.option("--worktree-base <path>", "Override worktree base directory");
|
|
4664
5887
|
cmd.option("--exec-defaults <path>", "Path to exec-defaults.yaml global config (default: .specdojo/exec-defaults.yaml)");
|
|
4665
5888
|
cmd.option("--if-busy <policy>", "When another exec is running for the project: skip|wait|fail (default: fail)", "fail");
|
|
@@ -4686,9 +5909,11 @@ function prepareScheduleIntegrationResume(params) {
|
|
|
4686
5909
|
if (!stateRef) {
|
|
4687
5910
|
throw new Error(`integration resume has no pipeline_state_ref for ${task.id}`);
|
|
4688
5911
|
}
|
|
4689
|
-
const
|
|
4690
|
-
|
|
5912
|
+
const worktreeTaskId = qualifyTaskId(projectId, task.id);
|
|
5913
|
+
const foundWorktree = findExecWorktree(repoRoot, worktreeTaskId);
|
|
5914
|
+
if (!foundWorktree)
|
|
4691
5915
|
throw new Error(`no exec worktree to resume integration for ${task.id}`);
|
|
5916
|
+
const worktree = withProductWorktrees(foundWorktree, configuredProductRepos(schedulePath), worktreeTaskId);
|
|
4692
5917
|
const checkpoint = loadPipelineResumeCheckpoint({
|
|
4693
5918
|
worktreePath: worktree.path,
|
|
4694
5919
|
stateRef,
|
|
@@ -4808,7 +6033,9 @@ async function runResumeMode(opts) {
|
|
|
4808
6033
|
const taskState = snapshot.tasks[opts.task];
|
|
4809
6034
|
const blockedPipelineStage = taskState?.meta?.pipeline_stage;
|
|
4810
6035
|
const canResumeBlockedPipeline = taskState?.state === "blocked" &&
|
|
4811
|
-
(blockedPipelineStage === "
|
|
6036
|
+
(blockedPipelineStage === "executor" ||
|
|
6037
|
+
blockedPipelineStage === "reporter" ||
|
|
6038
|
+
blockedPipelineStage === "integrate") &&
|
|
4812
6039
|
typeof taskState.meta?.pipeline_state_ref === "string";
|
|
4813
6040
|
if (canResumeBlockedPipeline) {
|
|
4814
6041
|
const actor = taskState.last_by ?? opts.by ?? "exec-pipeline-resume";
|
|
@@ -4820,7 +6047,9 @@ async function runResumeMode(opts) {
|
|
|
4820
6047
|
by: actor,
|
|
4821
6048
|
msg: blockedPipelineStage === "integrate"
|
|
4822
6049
|
? "resume integration from persisted pipeline state"
|
|
4823
|
-
:
|
|
6050
|
+
: blockedPipelineStage === "reporter"
|
|
6051
|
+
? "resume reporter from persisted pipeline state"
|
|
6052
|
+
: "resume executor from persisted pipeline state",
|
|
4824
6053
|
meta,
|
|
4825
6054
|
}));
|
|
4826
6055
|
}
|
|
@@ -4925,11 +6154,11 @@ export function registerResumeCommand(exec) {
|
|
|
4925
6154
|
cmd.option("--project <projectId>", "Project id in .specdojo/specdojo.config.json");
|
|
4926
6155
|
cmd.option("--task <taskId>", 'Resume only this task ("doing", blocked pipeline stage, or due with --due)');
|
|
4927
6156
|
cmd.option("--due", "Atomically claim and resume only retryable limit blocks whose resume time has arrived", false);
|
|
4928
|
-
cmd.option("--by <nickname>", "Select
|
|
4929
|
-
cmd.option("--edit-by <nickname>", "
|
|
4930
|
-
cmd.option("--review-by <nickname>", "
|
|
4931
|
-
cmd.option("--executor-by <nickname>", "
|
|
4932
|
-
cmd.option("--reporter-by <nickname>", "
|
|
6157
|
+
cmd.option("--by <nickname>", "Select an agent-members.yaml agent (default: the agent that claimed the task)");
|
|
6158
|
+
cmd.option("--edit-by <nickname>", "agent-members.yaml nickname for edit-mode tasks (overrides the claiming actor)");
|
|
6159
|
+
cmd.option("--review-by <nickname>", "agent-members.yaml nickname for review-mode tasks (overrides the claiming actor)");
|
|
6160
|
+
cmd.option("--executor-by <nickname>", "agent-members.yaml executor nickname for pipeline tasks");
|
|
6161
|
+
cmd.option("--reporter-by <nickname>", "agent-members.yaml reporter nickname for pipeline tasks");
|
|
4933
6162
|
cmd.option("--parallel <n>", "Number of tasks to resume in parallel", "1");
|
|
4934
6163
|
cmd.option("--worktree-base <path>", "Override worktree base directory");
|
|
4935
6164
|
cmd.option("--exec-defaults <path>", "Path to exec-defaults.yaml global config (default: .specdojo/exec-defaults.yaml)");
|