specdojo 0.2.1 → 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.
Files changed (168) hide show
  1. package/.github/agents/specdojo-orchestrator.md +165 -0
  2. package/CHANGELOG.md +280 -0
  3. package/README.md +92 -42
  4. package/dist/agent-response.js +20 -0
  5. package/dist/agent.js +4 -4
  6. package/dist/build-command.js +28 -8
  7. package/dist/dashboard.js +122 -1
  8. package/dist/devcontainer-command.js +43 -0
  9. package/dist/devcontainer-scaffold.js +165 -0
  10. package/dist/exec-agent-config.js +107 -9
  11. package/dist/exec-agent-git-state.js +18 -0
  12. package/dist/exec-agent-protected-config.js +46 -8
  13. package/dist/exec-evidence.js +254 -11
  14. package/dist/exec-handoff.js +336 -0
  15. package/dist/exec-parent-validation.js +317 -43
  16. package/dist/exec-pipeline-state.js +74 -9
  17. package/dist/exec-plans.js +115 -113
  18. package/dist/exec-protection-handoff.js +43 -2
  19. package/dist/exec-provider-scaffold.js +247 -15
  20. package/dist/exec-register-resume.js +65 -19
  21. package/dist/exec-register.js +9 -3
  22. package/dist/exec-repo-integration.js +811 -0
  23. package/dist/exec-repo-trace.js +182 -0
  24. package/dist/exec-reporter.js +613 -132
  25. package/dist/exec-results.js +81 -56
  26. package/dist/exec-run-lock.js +110 -107
  27. package/dist/exec-run.js +1585 -356
  28. package/dist/exec-shared.js +7 -0
  29. package/dist/exec-slot-lock.js +242 -0
  30. package/dist/exec-task-repos.js +415 -0
  31. package/dist/exec-trial.js +51 -25
  32. package/dist/exec-worktree-command.js +87 -43
  33. package/dist/exec-worktree-ops.js +502 -57
  34. package/dist/exec-worktree.js +114 -27
  35. package/dist/exec.js +13 -6
  36. package/dist/grade-result.js +128 -0
  37. package/dist/grade.js +809 -72
  38. package/dist/init-command.js +443 -0
  39. package/dist/job.js +160 -10
  40. package/dist/orchestrator.js +213 -0
  41. package/dist/register-event-merge.js +169 -0
  42. package/dist/register-item.js +7 -1
  43. package/dist/register.js +294 -86
  44. package/dist/review-grade.js +252 -0
  45. package/dist/review-plan.js +111 -1
  46. package/dist/review-types.js +40 -1
  47. package/dist/routine.js +72 -5
  48. package/dist/schedule-build.js +2 -2
  49. package/dist/schedule.js +17 -4
  50. package/dist/specdojo-config.js +465 -19
  51. package/dist/specdojo-gitignore.js +135 -0
  52. package/dist/specdojo.js +6 -0
  53. package/dist/viewpoint-document-kinds-check.js +128 -0
  54. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
  55. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
  56. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
  57. package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
  58. package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
  59. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
  60. package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
  61. package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
  62. package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
  63. package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
  64. package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
  65. package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
  66. package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
  67. package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
  68. package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
  69. package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
  70. package/docs/ja/specdojo/guides/exec-config-guide.md +91 -47
  71. package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
  72. package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
  73. package/docs/ja/specdojo/guides/kata-guide.md +4 -4
  74. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +25 -4
  75. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
  76. package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
  77. package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
  78. package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
  79. package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
  80. package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
  81. package/docs/ja/specdojo/guides/review-guide.md +195 -158
  82. package/docs/ja/specdojo/guides/routine-operation-guide.md +74 -9
  83. package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
  84. package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
  85. package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
  86. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
  87. package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
  88. package/docs/ja/specdojo/guides/waza-guide.md +15 -2
  89. package/docs/ja/specdojo/index.md +2 -2
  90. package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
  91. package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
  92. package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
  93. package/docs/ja/specdojo/references/command-reference.md +335 -92
  94. package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
  95. package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
  96. package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
  97. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
  98. package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
  99. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
  100. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
  101. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
  102. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
  103. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
  104. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
  105. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
  106. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
  107. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
  108. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
  109. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
  110. package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
  111. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
  112. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
  113. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
  114. package/docs/ja/specdojo/samples/bps-sample.md +74 -21
  115. package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
  116. package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
  117. package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
  118. package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
  119. package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
  120. package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
  121. package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
  122. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
  123. package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
  124. package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
  125. package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
  126. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
  127. package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
  128. package/docs/ja/specdojo/templates/bps-template.md +91 -0
  129. package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
  130. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
  131. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
  132. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
  133. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
  134. package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
  135. package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
  136. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
  137. package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
  138. package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
  139. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
  140. package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
  141. package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
  142. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
  143. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
  144. package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
  145. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
  146. package/package.json +15 -9
  147. package/templates/antigravity/README.md +27 -2
  148. package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
  149. package/templates/antigravity/exec-defaults-snippet.yaml +7 -6
  150. package/templates/antigravity/orchestrator.md +18 -7
  151. package/templates/antigravity/settings.global.json +55 -0
  152. package/templates/claude/agents/claude-executor.md +14 -0
  153. package/templates/claude/agents/claude-reporter.md +16 -0
  154. package/templates/claude/agents/specdojo-orchestrator.md +18 -7
  155. package/templates/claude/settings.edit.json +27 -1
  156. package/templates/codex/README.md +5 -4
  157. package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
  158. package/templates/codex/orchestrator.md +18 -7
  159. package/templates/copilot/README.md +7 -5
  160. package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
  161. package/templates/devcontainer/devcontainer.json +27 -0
  162. package/templates/devcontainer/emacs/init.el +88 -0
  163. package/templates/devcontainer/post-create.sh +62 -0
  164. package/templates/init-agent-members.yaml +200 -0
  165. package/templates/init-exec-defaults.yaml +72 -0
  166. package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
  167. package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
  168. package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
@@ -1,15 +1,16 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { createHash, randomUUID } from "node:crypto";
3
3
  import { copyFileSync, existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
4
- import { dirname, join, relative, resolve, sep } from "node:path";
4
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
5
5
  import { defaultExecDefaultsPath, loadExecDefaultsConfig, resolveMemberCommand, resolveRateLimitDetection, } from "./exec-agent-config.js";
6
6
  import { agentProtectedConfigViolation, captureAgentProtectedConfigSnapshot, changedAgentProtectedConfigPaths, isAgentProtectedConfigPath, } from "./exec-agent-protected-config.js";
7
7
  import { agentGitStateViolation, captureAgentGitStateSnapshot, changedAgentGitStateFields, } from "./exec-agent-git-state.js";
8
- import { recordExecutorEvidence, } from "./exec-evidence.js";
8
+ import { recordExecutorEvidence, recordParentValidationFailureOutput, } from "./exec-evidence.js";
9
+ import { parentValidationLabels, } from "./exec-parent-validation.js";
9
10
  import { activateResolvedProjectPaths, resolveProjectPaths } from "./exec-project.js";
10
- import { buildExecutorPrompt, isRateLimitError, loadRosterForExecutionPath, runConfiguredParentValidations, } from "./exec-run.js";
11
+ import { buildExecutorPrompt, isRateLimitError, loadRosterForExecutionPath, runConfiguredParentValidationBatch, } from "./exec-run.js";
11
12
  import { parsePlanTaskIdentity } from "./exec-plans.js";
12
- import { runReporterWithFormatRetry } from "./exec-reporter.js";
13
+ import { deriveReporterFacts, evidenceForReporter, runReporterWithFormatRetry, } from "./exec-reporter.js";
13
14
  import { ensureDir, safeSlug } from "./exec-shared.js";
14
15
  import { ensureExecWorktree, execBranchExists, findExecWorktree, gitEnvironment, gitOutput, gitResult, resolveWorktreeBase, worktreeNameFromTaskId, } from "./exec-worktree.js";
15
16
  import { getProjectSchedulePath, loadConfig, specdojoRootDir, } from "./specdojo-config.js";
@@ -176,9 +177,9 @@ function parseRating(value, flag) {
176
177
  function resolveMember(roster, nickname, stageRole) {
177
178
  const member = roster?.members.find((candidate) => candidate.type === "agent" && candidate.nickname === nickname);
178
179
  if (!member)
179
- throw new Error(`Agent nickname not found in pm-members.yaml: ${nickname}`);
180
+ throw new Error(`Agent nickname not found in agent-members.yaml: ${nickname}`);
180
181
  if (member.disabled)
181
- throw new Error(`Agent is disabled in pm-members.yaml: ${nickname}`);
182
+ throw new Error(`Agent is disabled in agent-members.yaml: ${nickname}`);
182
183
  if ((stageRole === "reporter" && member.stage_role !== "reporter") ||
183
184
  (stageRole === "executor" && member.stage_role === "reporter")) {
184
185
  throw new Error(`Agent must have stage_role: ${stageRole}: ${nickname}`);
@@ -258,6 +259,7 @@ function blankTrial(params) {
258
259
  validations_passed: 0,
259
260
  validations_failed: 0,
260
261
  validations_not_run: 0,
262
+ validations_requires_human: 0,
261
263
  files_changed: 0,
262
264
  evidence_ref: null,
263
265
  final_message: "",
@@ -340,8 +342,8 @@ export function buildComparisonRecord(params) {
340
342
  })),
341
343
  agent_selection: {
342
344
  policy: "manual",
343
- target: "pm-members.yaml",
344
- rationale: "A single comparison does not automatically change agent assignment. A human reviews objective and subjective results, then updates pm-members.yaml priority/capabilities when repeated evidence supports the change.",
345
+ target: "agent-members.yaml",
346
+ rationale: "A single comparison does not automatically change agent assignment. A human reviews objective and subjective results, then updates agent-members.yaml priority/capabilities when repeated evidence supports the change.",
345
347
  },
346
348
  };
347
349
  }
@@ -357,13 +359,17 @@ export function updateObjectiveMetrics(trial, evidence, structuredOutput) {
357
359
  trial.executor.validations_passed = 0;
358
360
  trial.executor.validations_failed = 0;
359
361
  trial.executor.validations_not_run = 0;
362
+ trial.executor.validations_requires_human = 0;
360
363
  for (const validation of executorValidations) {
361
364
  if (validation.status === "passed")
362
365
  trial.executor.validations_passed++;
363
366
  else if (validation.status === "failed")
364
367
  trial.executor.validations_failed++;
365
- else
368
+ else if (validation.status === "not_run")
366
369
  trial.executor.validations_not_run++;
370
+ else if (validation.status === "requires_human") {
371
+ trial.executor.validations_requires_human++;
372
+ }
367
373
  }
368
374
  const parentValidations = evidence.validations.filter((validation) => validation.source === "runner");
369
375
  trial.parent_validation.validations_passed = parentValidations.filter((validation) => validation.status === "passed").length;
@@ -381,6 +387,7 @@ async function runOneTrial(params) {
381
387
  trial.executor.duration_ms = executorCompletedAt.getTime() - startedAt.getTime();
382
388
  trial.parent_validation.configured_ids = [...params.parentValidationIds];
383
389
  let parentValidations = [];
390
+ let parentValidationFailureOutputs = [];
384
391
  if (params.parentValidationIds.length === 0) {
385
392
  trial.parent_validation.status = "not_configured";
386
393
  }
@@ -389,7 +396,11 @@ async function runOneTrial(params) {
389
396
  }
390
397
  else {
391
398
  const parentValidationStartedAt = Date.now();
392
- parentValidations = await runConfiguredParentValidations(params.execDefaults, worktree.path);
399
+ const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, worktree.path, {
400
+ label: `${params.record.task_id} (${trial.trial_id})`,
401
+ });
402
+ parentValidations = parentValidationBatch.validations;
403
+ parentValidationFailureOutputs = parentValidationBatch.failureOutputs;
393
404
  trial.parent_validation.duration_ms = Date.now() - parentValidationStartedAt;
394
405
  trial.parent_validation.status = parentValidations.some((validation) => validation.status !== "passed")
395
406
  ? "failed"
@@ -412,16 +423,21 @@ async function runOneTrial(params) {
412
423
  stderr: outcome.stderr,
413
424
  parentValidations,
414
425
  });
426
+ evidenceRecorded.evidence = recordParentValidationFailureOutput({
427
+ worktreePath: worktree.path,
428
+ evidencePath: evidenceRecorded.evidencePath,
429
+ evidence: evidenceRecorded.evidence,
430
+ failureOutputs: parentValidationFailureOutputs,
431
+ });
415
432
  const centralizedEvidenceDir = join(comparisonDir(params.executionPath, params.record.comparison_id), "trials", trial.trial_id);
416
433
  ensureDir(centralizedEvidenceDir);
417
- const centralizedLogPath = join(centralizedEvidenceDir, "executor.log");
418
- const worktreeLogPath = join(dirname(evidenceRecorded.evidencePath), "executor.log");
419
- copyFileSync(worktreeLogPath, centralizedLogPath);
420
434
  const centralizedEvidencePath = join(centralizedEvidenceDir, "evidence.json");
421
- evidenceRecorded.evidence.log_refs = evidenceRecorded.evidence.log_refs.map((ref) => ({
422
- ...ref,
423
- path: repoRelative(params.repoRoot, centralizedLogPath),
424
- }));
435
+ evidenceRecorded.evidence.log_refs = evidenceRecorded.evidence.log_refs.map((ref) => {
436
+ const logName = basename(ref.path);
437
+ const centralizedLogPath = join(centralizedEvidenceDir, logName);
438
+ copyFileSync(join(dirname(evidenceRecorded.evidencePath), logName), centralizedLogPath);
439
+ return { ...ref, path: repoRelative(params.repoRoot, centralizedLogPath) };
440
+ });
425
441
  writeFileSync(centralizedEvidencePath, `${JSON.stringify(evidenceRecorded.evidence, null, 2)}\n`, "utf8");
426
442
  trial.executor.exit_code = outcome.exitCode;
427
443
  trial.executor.attempts = 1;
@@ -429,9 +445,14 @@ async function runOneTrial(params) {
429
445
  updateObjectiveMetrics(trial, evidenceRecorded.evidence, hasValidExecutorEnvelope(outcome.stdout));
430
446
  let reporterSucceeded = true;
431
447
  if (outcome.exitCode === 0 && params.reporterCommand) {
448
+ const reporterEvidence = evidenceForReporter(evidenceRecorded.evidence, {
449
+ repoRoot: params.repoRoot,
450
+ worktreePath: worktree.path,
451
+ executionPath: params.executionPath,
452
+ });
432
453
  const reporter = await runReporterWithFormatRetry({
433
454
  plan: params.plan,
434
- evidence: evidenceRecorded.evidence,
455
+ evidence: reporterEvidence,
435
456
  mode: parsePlanTaskIdentity(params.plan)?.mode ?? "edit",
436
457
  invoke: async (reporterPrompt) => {
437
458
  const reporterOutcome = await spawnAgent(params.reporterCommand, reporterPrompt, worktree.path, worktreeEnvironment(params.repoRoot, worktree.path, params.schedulePath, params.executionPath));
@@ -450,17 +471,20 @@ async function runOneTrial(params) {
450
471
  trial.reporter.format_attempts = reporter.formatAttempts;
451
472
  trial.reporter.format_retries = Math.max(0, reporter.formatAttempts - 1);
452
473
  if (reporter.result === "success") {
474
+ const facts = deriveReporterFacts(reporterEvidence, {
475
+ mode: parsePlanTaskIdentity(params.plan)?.mode ?? "edit",
476
+ });
453
477
  trial.reporter.structured_output = true;
454
- trial.reporter.outcome = reporter.output.outcome;
478
+ trial.reporter.outcome = facts.outcome;
455
479
  trial.reporter.output = reporter.output;
456
- reporterSucceeded = reporter.output.outcome === "complete";
480
+ reporterSucceeded = facts.outcome === "complete";
457
481
  if (reporterSucceeded) {
458
482
  trial.reporter.status = "succeeded";
459
483
  }
460
484
  else {
461
485
  trial.reporter.status = "blocked";
462
- trial.reporter.failure_category = "reported_blocked";
463
- trial.reporter.failure_reason = reporter.output.block_reason;
486
+ trial.reporter.failure_category = "evidence_blocked";
487
+ trial.reporter.failure_reason = facts.block_reason;
464
488
  }
465
489
  }
466
490
  else {
@@ -587,8 +611,10 @@ async function runTrials(opts) {
587
611
  reporterCommands.set(reporter, reporterCommand);
588
612
  reporterRateLimitDetections.set(reporter, resolveRateLimitDetection(defaults, reporterMember.provider));
589
613
  }
590
- const parentValidationIds = defaults.pipeline?.parent_validations ?? [];
591
- const prompt = `${buildExecutorPrompt(planContent, parentValidationIds).trimEnd()}${TRIAL_PROMPT_SUFFIX}`;
614
+ const parentValidationEntries = defaults.pipeline?.parent_validations ?? [];
615
+ // Labels are `<id>` for the project repository and `<repo>:<id>` for a product repository.
616
+ const parentValidationIds = parentValidationLabels(parentValidationEntries);
617
+ const prompt = `${buildExecutorPrompt(planContent, parentValidationEntries).trimEnd()}${TRIAL_PROMPT_SUFFIX}`;
592
618
  const requestedRevision = opts.base?.trim() || "HEAD";
593
619
  const headCommit = resolveBaseCommit(repoRoot, "HEAD");
594
620
  const baseCommit = resolveBaseCommit(repoRoot, requestedRevision);
@@ -695,7 +721,7 @@ function statusTrials(opts) {
695
721
  validations_failed: 0,
696
722
  validations_not_run: 0,
697
723
  };
698
- process.stdout.write(`${trial.trial_id}\t${trial.status}\ttime(executor/parent/total)=${trial.executor.duration_ms ?? "-"}/${parentValidation.duration_ms ?? "-"}/${trial.duration_ms ?? "-"}ms\tfiles=${trial.executor.files_changed}\texecutor-validations(reported/passed/failed/not_run)=${trial.executor.validations_reported ?? trial.executor.validations.length}/${trial.executor.validations_passed}/${trial.executor.validations_failed}/${trial.executor.validations_not_run}\tparent-validations(status/passed/failed/not_run)=${parentValidation.status}/${parentValidation.validations_passed}/${parentValidation.validations_failed}/${parentValidation.validations_not_run}\treporter=${reporterStatus}/${trial.reporter.format_attempts}/${trial.reporter.failure_category ?? "-"}\n`);
724
+ process.stdout.write(`${trial.trial_id}\t${trial.status}\ttime(executor/parent/total)=${trial.executor.duration_ms ?? "-"}/${parentValidation.duration_ms ?? "-"}/${trial.duration_ms ?? "-"}ms\tfiles=${trial.executor.files_changed}\texecutor-validations(reported/passed/failed/not_run/requires_human)=${trial.executor.validations_reported ?? trial.executor.validations.length}/${trial.executor.validations_passed}/${trial.executor.validations_failed}/${trial.executor.validations_not_run}/${trial.executor.validations_requires_human ?? 0}\tparent-validations(status/passed/failed/not_run)=${parentValidation.status}/${parentValidation.validations_passed}/${parentValidation.validations_failed}/${parentValidation.validations_not_run}\treporter=${reporterStatus}/${trial.reporter.format_attempts}/${trial.reporter.failure_category ?? "-"}\n`);
699
725
  }
700
726
  }
701
727
  function rateTrial(opts) {
@@ -4,9 +4,10 @@ import { join, resolve } from "node:path";
4
4
  import { acquireSchedulerLock, foldEventsToState, readAllEventFiles, releaseSchedulerLock, } from "./exec-events.js";
5
5
  import { hasMemberCommandSource, loadExecDefaultsConfig, resolveMemberCommand, } from "./exec-agent-config.js";
6
6
  import { activateResolvedProjectPaths, resolveProjectPaths } from "./exec-project.js";
7
- import { agentGitStateViolation, captureAgentGitStateSnapshot, changedAgentGitStateFields, } from "./exec-agent-git-state.js";
8
- import { agentProtectedConfigViolation, captureAgentProtectedConfigSnapshot, changedAgentProtectedConfigPaths, } from "./exec-agent-protected-config.js";
9
- import { recordGitStateBlock, recordProtectedConfigBlock } from "./exec-protection-handoff.js";
7
+ import { agentGitStateViolation, captureAgentGitStateAcrossRepos, changedAgentGitStateAcrossRepos, qualifiedGitStateFields, } from "./exec-agent-git-state.js";
8
+ import { agentProtectedConfigViolation, captureAgentProtectedConfigAcrossRepos, changedAgentProtectedConfigAcrossRepos, qualifiedRepoPaths, } from "./exec-agent-protected-config.js";
9
+ import { recordGitStateBlockAcrossRepos, recordProtectedConfigBlockAcrossRepos, } from "./exec-protection-handoff.js";
10
+ import { configuredProductRepos, missingProductWorktrees, plannedProjectWorktreePath, pruneOrphanedProductExecBranches, productRepoEnvironment, withAgentExtraRoots, withoutInheritedRepoEnvironment, withProductRepoPrompt, withProductWorktrees, } from "./exec-task-repos.js";
10
11
  import { buildTaskPhaseMap, loadPrompt, loadRosterForExecutionPath, resolveTaskPhaseContext, selectCandidates, } from "./exec-run.js";
11
12
  import { buildScheduleIndex } from "./exec-schedule.js";
12
13
  import { buildInitialStateFromStrategy } from "./exec-schedule-initial.js";
@@ -66,12 +67,19 @@ function requireDoingTask(schedulePath, taskId) {
66
67
  }
67
68
  return state;
68
69
  }
69
- function requireWorktree(repoRoot, worktreeTaskId) {
70
- const worktree = findExecWorktree(repoRoot, worktreeTaskId);
71
- if (!worktree)
70
+ // PJR-98G4: repos を宣言した project では、プロダクトの worktree もタスクの worktree として扱う。
71
+ function requireWorktree(context, worktreeTaskId) {
72
+ const found = findExecWorktree(context.repoRoot, worktreeTaskId);
73
+ if (!found)
72
74
  throw new Error(`Worktree is not prepared for task: ${worktreeTaskId}`);
73
- if (!existsSync(worktree.path)) {
74
- throw new Error(`Registered worktree path does not exist: ${worktree.path}`);
75
+ if (!existsSync(found.path)) {
76
+ throw new Error(`Registered worktree path does not exist: ${found.path}`);
77
+ }
78
+ const products = configuredProductRepos(context.schedulePath);
79
+ const worktree = withProductWorktrees(found, products, worktreeTaskId);
80
+ const missing = missingProductWorktrees(products, worktree);
81
+ if (missing.length > 0) {
82
+ throw new Error(`Product worktrees are not prepared for task ${worktreeTaskId}: ${missing.join(", ")}`);
75
83
  }
76
84
  return worktree;
77
85
  }
@@ -109,10 +117,13 @@ function resolveAgent(context, taskId, opts) {
109
117
  const prompt = loadPrompt(context.executionPath, taskId);
110
118
  if (!prompt)
111
119
  throw new Error(`Plan not found for task: ${taskId}`);
112
- return { actor: nickname, command, prompt };
120
+ return { actor: nickname, command, provider: member?.provider, prompt };
113
121
  }
114
122
  function printWorktree(worktree) {
115
123
  process.stdout.write(`worktree: ${worktree.path}\nbranch: ${worktree.branch}\n`);
124
+ for (const product of worktree.repos ?? []) {
125
+ process.stdout.write(`repo ${product.name}: ${product.path} (${product.branch})\n`);
126
+ }
116
127
  }
117
128
  async function prepare(opts) {
118
129
  const context = resolveContext(opts);
@@ -121,16 +132,29 @@ async function prepare(opts) {
121
132
  const name = worktreeNameFromTaskId(worktreeTaskId);
122
133
  const branch = `exec/${name}`;
123
134
  const base = resolveWorktreeBase(context.repoRoot, opts.worktreeBase, configuredWorktreeBase(context.schedulePath));
135
+ const products = configuredProductRepos(context.schedulePath);
124
136
  const planned = {
125
- path: resolve(base, name),
137
+ path: plannedProjectWorktreePath(base, worktreeTaskId, products),
126
138
  branch,
127
139
  name,
128
140
  created: false,
141
+ ...(products.length > 0
142
+ ? {
143
+ repos: products.map((product) => ({
144
+ name: product.name,
145
+ repoRoot: product.repoRoot,
146
+ path: resolve(base, name, product.name),
147
+ branch,
148
+ created: false,
149
+ })),
150
+ }
151
+ : {}),
129
152
  };
130
153
  if (opts.dryRun) {
131
154
  process.stdout.write(`[dry-run] claim actor: ${state.actor}\n`);
132
155
  process.stdout.write(`[dry-run] checkpoint: exec(${opts.task}): prepare execution\n`);
133
- printWorktree(findExecWorktree(context.repoRoot, worktreeTaskId) ?? planned);
156
+ const existing = findExecWorktree(context.repoRoot, worktreeTaskId);
157
+ printWorktree(existing ? withProductWorktrees(existing, products, worktreeTaskId) : planned);
134
158
  return;
135
159
  }
136
160
  let lockDir = "";
@@ -166,6 +190,7 @@ async function prepare(opts) {
166
190
  base,
167
191
  checkpointPaths: [planPath, resultPath, lockedState.claimEventPath],
168
192
  commitMessage: `exec(${opts.task}): prepare execution`,
193
+ products,
169
194
  });
170
195
  printWorktree(worktree);
171
196
  }
@@ -178,16 +203,19 @@ function status(opts) {
178
203
  const context = resolveContext(opts);
179
204
  const state = taskExecutionState(context.schedulePath, opts.task);
180
205
  const worktreeTaskId = qualifyTaskId(context.projectId, opts.task);
181
- const worktree = findExecWorktree(context.repoRoot, worktreeTaskId);
206
+ const found = findExecWorktree(context.repoRoot, worktreeTaskId);
207
+ const products = configuredProductRepos(context.schedulePath);
182
208
  const branch = `exec/${worktreeNameFromTaskId(worktreeTaskId)}`;
183
209
  process.stdout.write(`task: ${opts.task}\nstate: ${state.state}\n`);
184
210
  process.stdout.write(`claim-actor: ${state.actor ?? "not found"}\n`);
185
- if (!worktree) {
211
+ if (!found) {
186
212
  const base = resolveWorktreeBase(context.repoRoot, opts.worktreeBase, configuredWorktreeBase(context.schedulePath));
187
- process.stdout.write(`worktree: not prepared (expected ${resolve(base, worktreeNameFromTaskId(worktreeTaskId))})\n`);
213
+ const expected = plannedProjectWorktreePath(base, worktreeTaskId, products);
214
+ process.stdout.write(`worktree: not prepared (expected ${expected})\n`);
188
215
  process.stdout.write(`branch: ${branch}\n`);
189
216
  return;
190
217
  }
218
+ const worktree = withProductWorktrees(found, products, worktreeTaskId);
191
219
  const { planRel, resultRel } = taskPaths(context, opts.task);
192
220
  const compareBase = gitOutput(context.repoRoot, ["merge-base", "HEAD", branch]).trim();
193
221
  const merged = gitResult(context.repoRoot, ["merge-base", "--is-ancestor", branch, "HEAD"]).status === 0;
@@ -206,60 +234,71 @@ function status(opts) {
206
234
  const changes = worktreeStatusPaths(worktree.path);
207
235
  process.stdout.write(`uncommitted: ${changes.length > 0 ? changes.join(", ") : "none"}\n`);
208
236
  process.stdout.write(`merged-into-current: ${merged ? "yes" : "no"}\n`);
237
+ for (const name of missingProductWorktrees(products, worktree)) {
238
+ process.stdout.write(`repo ${name}: not prepared\n`);
239
+ }
240
+ for (const product of worktree.repos ?? []) {
241
+ const productChanges = worktreeStatusPaths(product.path).map((path) => `${product.name}:${path}`);
242
+ process.stdout.write(`repo ${product.name} uncommitted: ${productChanges.length > 0 ? productChanges.join(", ") : "none"}\n`);
243
+ }
209
244
  }
210
245
  async function agent(opts) {
211
246
  const context = resolveContext(opts);
212
- const worktree = requireWorktree(context.repoRoot, qualifyTaskId(context.projectId, opts.task));
247
+ const worktree = requireWorktree(context, qualifyTaskId(context.projectId, opts.task));
213
248
  requireInsideWorktree(context.repoRoot, worktree);
214
249
  const resolved = resolveAgent(context, opts.task, opts);
250
+ const productDirs = (worktree.repos ?? []).map((product) => product.path);
251
+ const command = withAgentExtraRoots(resolved.command, resolved.provider, productDirs);
215
252
  if (opts.dryRun) {
216
253
  process.stdout.write(`[dry-run] actor: ${resolved.actor}\n`);
217
- process.stdout.write(`[dry-run] command: ${resolved.command}\n`);
254
+ process.stdout.write(`[dry-run] command: ${command}\n`);
218
255
  process.stdout.write(`[dry-run] cwd: ${worktree.path}\n`);
219
256
  process.stdout.write(`[dry-run] plan: ${resolved.prompt.length} chars\n`);
220
257
  return;
221
258
  }
222
- const protectedConfigBefore = captureAgentProtectedConfigSnapshot(worktree.path);
223
- const gitStateBefore = captureAgentGitStateSnapshot(worktree.path);
224
- const child = spawn(resolved.command, {
259
+ const agentRepos = [
260
+ { root: worktree.path },
261
+ ...(worktree.repos ?? []).map((product) => ({ name: product.name, root: product.path })),
262
+ ];
263
+ const protectedConfigBefore = captureAgentProtectedConfigAcrossRepos(agentRepos);
264
+ const gitStateBefore = captureAgentGitStateAcrossRepos(agentRepos);
265
+ const child = spawn(command, {
225
266
  cwd: worktree.path,
226
267
  env: {
227
- ...gitEnvironment(),
268
+ ...withoutInheritedRepoEnvironment(gitEnvironment()),
228
269
  SPECDOJO_SCHEDULE_PATH: context.schedulePath,
229
270
  SPECDOJO_EXECUTION_PATH: context.executionPath,
271
+ ...productRepoEnvironment(worktree.path, worktree.repos),
230
272
  },
231
273
  shell: true,
232
274
  stdio: ["pipe", "inherit", "inherit"],
233
275
  });
234
- child.stdin.end(resolved.prompt);
276
+ child.stdin.end(withProductRepoPrompt(resolved.prompt, worktree.repos));
235
277
  const exitCode = await new Promise((resolveExit) => {
236
278
  child.once("error", () => resolveExit(1));
237
279
  child.once("close", (code) => resolveExit(code ?? 1));
238
280
  });
239
281
  // 保護機構が block した場合も、対象と提案差分を worktree 側 result の申し送りへ残す。
240
282
  const worktreeResultPath = resolve(worktree.path, taskPaths(context, opts.task).resultRel);
241
- const protectedConfigChanges = changedAgentProtectedConfigPaths(worktree.path, protectedConfigBefore);
283
+ const protectedConfigChanges = changedAgentProtectedConfigAcrossRepos(protectedConfigBefore);
242
284
  if (protectedConfigChanges.length > 0) {
243
- const reason = agentProtectedConfigViolation(protectedConfigChanges);
285
+ const reason = agentProtectedConfigViolation(qualifiedRepoPaths(protectedConfigChanges));
244
286
  process.stderr.write(`blocked: ${reason}\n`);
245
- recordProtectedConfigBlock({
287
+ recordProtectedConfigBlockAcrossRepos({
246
288
  resultPath: worktreeResultPath,
247
- repoRoot: worktree.path,
248
- paths: protectedConfigChanges,
289
+ changes: protectedConfigChanges,
249
290
  reason,
250
291
  });
251
292
  process.exitCode = 1;
252
293
  return;
253
294
  }
254
- const gitStateChanges = changedAgentGitStateFields(worktree.path, gitStateBefore);
295
+ const gitStateChanges = changedAgentGitStateAcrossRepos(gitStateBefore);
255
296
  if (gitStateChanges.length > 0) {
256
- const reason = agentGitStateViolation(gitStateChanges);
297
+ const reason = agentGitStateViolation(qualifiedGitStateFields(gitStateChanges));
257
298
  process.stderr.write(`blocked: ${reason}\n`);
258
- recordGitStateBlock({
299
+ recordGitStateBlockAcrossRepos({
259
300
  resultPath: worktreeResultPath,
260
- repoRoot: worktree.path,
261
- before: gitStateBefore,
262
- fields: gitStateChanges,
301
+ changes: gitStateChanges,
263
302
  reason,
264
303
  });
265
304
  process.exitCode = 1;
@@ -271,7 +310,7 @@ async function agent(opts) {
271
310
  function commit(opts) {
272
311
  const context = resolveContext(opts);
273
312
  requireDoingTask(context.schedulePath, opts.task);
274
- const worktree = requireWorktree(context.repoRoot, qualifyTaskId(context.projectId, opts.task));
313
+ const worktree = requireWorktree(context, qualifyTaskId(context.projectId, opts.task));
275
314
  requireInsideWorktree(context.repoRoot, worktree);
276
315
  commitWorktreeChanges({
277
316
  context,
@@ -283,7 +322,7 @@ function commit(opts) {
283
322
  }
284
323
  function merge(opts) {
285
324
  const context = resolveContext(opts);
286
- const worktree = requireWorktree(context.repoRoot, qualifyTaskId(context.projectId, opts.task));
325
+ const worktree = requireWorktree(context, qualifyTaskId(context.projectId, opts.task));
287
326
  // prepare left the root's own copies of the checkpoint files uncommitted (the exec branch
288
327
  // carries the commit). Release them so the merge can bring the committed versions in.
289
328
  const { claimEventPath } = taskExecutionState(context.schedulePath, opts.task);
@@ -303,7 +342,7 @@ function merge(opts) {
303
342
  }
304
343
  function remove(opts) {
305
344
  const context = resolveContext(opts);
306
- const worktree = requireWorktree(context.repoRoot, qualifyTaskId(context.projectId, opts.task));
345
+ const worktree = requireWorktree(context, qualifyTaskId(context.projectId, opts.task));
307
346
  removeWorktree({
308
347
  context,
309
348
  worktree,
@@ -324,17 +363,22 @@ function prune(opts) {
324
363
  projectId,
325
364
  dryRun: opts.dryRun,
326
365
  });
327
- if (orphaned.length === 0) {
366
+ // PJR-98G4: 宣言済みのプロダクトリポジトリでも、同じ project の孤児 exec branch を検出する。
367
+ const productOrphaned = pruneOrphanedProductExecBranches({
368
+ products: configuredProductRepos(context.schedulePath),
369
+ projectId,
370
+ dryRun: opts.dryRun,
371
+ });
372
+ if (orphaned.length === 0 && productOrphaned.length === 0) {
328
373
  process.stdout.write(`No orphaned exec branches for project ${projectId}.\n`);
329
374
  return;
330
375
  }
376
+ const describe = (merged) => merged ? (opts.dryRun ? "would delete (merged)" : "deleted (merged)") : "kept (not merged)";
331
377
  for (const item of orphaned) {
332
- const action = item.mergedIntoCurrent
333
- ? opts.dryRun
334
- ? "would delete (merged)"
335
- : "deleted (merged)"
336
- : "kept (not merged)";
337
- process.stdout.write(`${item.branch}: ${action}\n`);
378
+ process.stdout.write(`${item.branch}: ${describe(item.mergedIntoCurrent)}\n`);
379
+ }
380
+ for (const item of productOrphaned) {
381
+ process.stdout.write(`${item.repo}:${item.branch}: ${describe(item.mergedIntoTarget)}\n`);
338
382
  }
339
383
  }
340
384
  function addCommonOptions(command) {
@@ -366,7 +410,7 @@ export function registerExecWorktreeCommands(exec) {
366
410
  }
367
411
  });
368
412
  const agentCommand = addCommonOptions(worktree.command("agent").description("Run the task agent once inside its worktree"));
369
- agentCommand.option("--by <nickname>", "Select a pm-members.yaml agent nickname");
413
+ agentCommand.option("--by <nickname>", "Select an agent-members.yaml nickname");
370
414
  agentCommand.option("--dry-run", "Print the resolved command without executing", false);
371
415
  agentCommand.action(async (opts) => {
372
416
  try {