specdojo 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/.github/agents/specdojo-orchestrator.md +61 -2
  2. package/CHANGELOG.md +43 -0
  3. package/README.md +8 -7
  4. package/dist/commands/init.js +72 -15
  5. package/dist/commands/night-orchestrator.js +287 -0
  6. package/dist/commands/orchestrator.js +10 -3
  7. package/dist/devcontainer/command.js +3 -1
  8. package/dist/devcontainer/scaffold.js +166 -5
  9. package/dist/exec/agent-config.js +60 -2
  10. package/dist/exec/parent-validation.js +14 -0
  11. package/dist/exec/pipeline-state.js +13 -0
  12. package/dist/exec/register.js +23 -1
  13. package/dist/exec/repo-integration.js +1 -1
  14. package/dist/exec/reporter.js +113 -13
  15. package/dist/exec/results.js +36 -14
  16. package/dist/exec/run/agent-pipeline.js +3 -0
  17. package/dist/exec/run/agent.js +40 -5
  18. package/dist/exec/run/job.js +2 -2
  19. package/dist/exec/run/lifecycle-commands.js +2 -2
  20. package/dist/exec/run/register-command.js +23 -4
  21. package/dist/exec/run/register-core.js +17 -0
  22. package/dist/exec/run/register-mode.js +39 -16
  23. package/dist/exec/run/register-post-review.js +420 -0
  24. package/dist/exec/run/register-resume.js +27 -11
  25. package/dist/exec/run/register-worktree.js +66 -2
  26. package/dist/exec/run/run.js +1 -1
  27. package/dist/exec/run/shared.js +22 -24
  28. package/dist/exec/task-repos.js +102 -15
  29. package/dist/register/core.js +14 -2
  30. package/dist/register/create-commands.js +62 -6
  31. package/dist/register/event-merge.js +13 -1
  32. package/dist/register/events.js +4 -0
  33. package/dist/register/item.js +9 -0
  34. package/dist/register/migration.js +1 -0
  35. package/dist/register/register.js +2 -2
  36. package/dist/shared/git.js +45 -15
  37. package/dist/shared/provider-scaffold.js +3 -2
  38. package/dist/shared/specdojo-config.js +69 -16
  39. package/dist/shared/text.js +4 -1
  40. package/dist/shared/workspace-scaffold.js +69 -0
  41. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +2 -1
  42. package/docs/ja/specdojo/exec-templates/xep-register-template.md +2 -0
  43. package/docs/ja/specdojo/exec-templates/xrp-register-post-run-template.md +46 -0
  44. package/docs/ja/specdojo/guides/branch-workflow-guide.md +34 -1
  45. package/docs/ja/specdojo/guides/docs-structure-guide.md +2 -0
  46. package/docs/ja/specdojo/guides/exec-config-guide.md +79 -11
  47. package/docs/ja/specdojo/guides/exec-operation-guide.md +39 -1
  48. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +9 -3
  49. package/docs/ja/specdojo/guides/quick-start-guide.md +9 -6
  50. package/docs/ja/specdojo/guides/register-operation-guide.md +42 -0
  51. package/docs/ja/specdojo/guides/remote-host-development-guide.md +52 -6
  52. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +1 -1
  53. package/docs/ja/specdojo/guides/waza-guide.md +1 -1
  54. package/docs/ja/specdojo/references/command-reference.md +101 -56
  55. package/docs/ja/specdojo/references/specdojo-config-reference.md +33 -7
  56. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +5 -2
  57. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +92 -18
  58. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +6 -1
  59. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +12 -0
  60. package/docs/specdojo/schemas/v1/register-events.schema.yaml +2 -0
  61. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +21 -0
  62. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +35 -0
  63. package/package.json +17 -17
  64. package/templates/antigravity/README.md +1 -1
  65. package/templates/antigravity/orchestrator.md +61 -2
  66. package/templates/claude/agents/specdojo-orchestrator.md +61 -2
  67. package/templates/codex/README.md +17 -0
  68. package/templates/codex/agents/specdojo-orchestrator.toml +61 -2
  69. package/templates/codex/orchestrator.md +61 -2
  70. package/templates/devcontainer/devcontainer.json +3 -0
  71. package/templates/devcontainer/post-create.sh +15 -7
  72. package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +38 -5
  73. package/templates/devcontainer/remote-host/ssh-config.sample +3 -0
  74. package/templates/devcontainer/vim/vimrc +37 -0
  75. package/templates/init-agent-members.yaml +3 -3
  76. package/templates/init-exec-defaults.yaml +20 -1
  77. package/templates/opencode/agents/specdojo-orchestrator.md +61 -2
@@ -1,8 +1,8 @@
1
1
  import { existsSync } from "node:fs";
2
- import { join } from "node:path";
2
+ import { isAbsolute, join, resolve } from "node:path";
3
3
  import { listFilesRecursive, readYaml } from "./shared.js";
4
4
  import { acquirePoolSlot, releaseLock } from "./slot-lock.js";
5
- import { specdojoRootDir, } from "../shared/specdojo-config.js";
5
+ import { getProjectExecutionPath, loadConfig, specdojoRootDir, } from "../shared/specdojo-config.js";
6
6
  import { resolveParentValidationConcurrency, resolveParentValidationDefinitions, } from "./parent-validation.js";
7
7
  const PLACEHOLDER_PATTERN = /\{([a-z][a-z0-9_]*)\}/g;
8
8
  const BUILTIN_VARIABLE_NAMES = new Set(["nickname", "mode", "proficiency"]);
@@ -88,6 +88,10 @@ export function resolveRateLimitDetection(config, provider) {
88
88
  const override = provider ? config.providers?.[provider]?.rate_limit_detection : undefined;
89
89
  return override ?? config.rate_limit_detection;
90
90
  }
91
+ export function resolveConnectionErrorDetection(config, provider) {
92
+ const override = provider ? config.providers?.[provider]?.connection_error_detection : undefined;
93
+ return override ?? config.connection_error_detection;
94
+ }
91
95
  export function resolveRateLimitPolicy(config, provider) {
92
96
  const override = provider ? config.providers?.[provider]?.rate_limit_policy : undefined;
93
97
  return override ?? config.rate_limit_policy;
@@ -151,6 +155,7 @@ export function providerSlotPoolPath(lockRoot, provider) {
151
155
  }
152
156
  export const DEFAULT_MAX_CONCURRENT_RUNS = 4;
153
157
  export const DEFAULT_REGISTER_EXECUTION = "in-place";
158
+ export const DEFAULT_REGISTER_POST_REVIEW = false;
154
159
  // Preserve the historical default for repositories that have not opted into worktree execution.
155
160
  // Invalid YAML-sourced values are rejected instead of silently changing where agents write.
156
161
  export function resolveRegisterExecution(config) {
@@ -162,6 +167,15 @@ export function resolveRegisterExecution(config) {
162
167
  }
163
168
  return raw;
164
169
  }
170
+ export function resolveRegisterPostReview(config) {
171
+ const raw = config.run?.register_post_review;
172
+ if (raw === undefined)
173
+ return DEFAULT_REGISTER_POST_REVIEW;
174
+ if (typeof raw !== "boolean") {
175
+ throw new Error(`run.register_post_review in exec-defaults must be true or false: ${String(raw)}`);
176
+ }
177
+ return raw;
178
+ }
165
179
  // Resolve how many `exec run` processes may run at once for one project. Invalid values fall back
166
180
  // to the default so a typo cannot silently disable the busy guard.
167
181
  export function resolveMaxConcurrentRuns(config) {
@@ -269,6 +283,37 @@ function loadLegacyRateLimitPolicy(executionPath) {
269
283
  }
270
284
  return undefined;
271
285
  }
286
+ function projectParentValidations(executionPath) {
287
+ if (!executionPath)
288
+ return [];
289
+ const { config } = loadConfig();
290
+ if (!config)
291
+ return [];
292
+ const rootDir = specdojoRootDir();
293
+ const targetExecutionPath = resolve(executionPath);
294
+ const normalizedTarget = targetExecutionPath.replaceAll("\\", "/");
295
+ for (const [projectId, project] of Object.entries(config.projects)) {
296
+ const configuredExecutionPath = getProjectExecutionPath(project);
297
+ const resolvedExecutionPath = resolve(rootDir, configuredExecutionPath);
298
+ const normalizedConfigured = configuredExecutionPath.replaceAll("\\", "/");
299
+ // Job review loads defaults before changing cwd to its worktree. In that case loadConfig()
300
+ // resolves the main checkout while executionPath already points into the worktree; the
301
+ // repository-relative project path remains the same suffix in both locations.
302
+ const isProjectWorktreePath = !isAbsolute(configuredExecutionPath) &&
303
+ normalizedTarget.endsWith(`/${normalizedConfigured.replace(/^\.\//, "")}`);
304
+ if (resolvedExecutionPath !== targetExecutionPath && !isProjectWorktreePath)
305
+ continue;
306
+ const entries = project.run
307
+ ?.parent_validations;
308
+ if (entries === undefined)
309
+ return [];
310
+ if (!Array.isArray(entries)) {
311
+ throw new Error(`Invalid .specdojo/specdojo.config.json: projects.${projectId}.run.parent_validations must be an array`);
312
+ }
313
+ return entries;
314
+ }
315
+ return [];
316
+ }
272
317
  export function loadExecDefaultsConfig(configPath, executionPath) {
273
318
  const path = configPath ?? defaultExecDefaultsPath();
274
319
  let defaults = {};
@@ -286,6 +331,19 @@ export function loadExecDefaultsConfig(configPath, executionPath) {
286
331
  if (legacyPolicy)
287
332
  defaults.rate_limit_policy = legacyPolicy;
288
333
  }
334
+ const additionalParentValidations = projectParentValidations(executionPath);
335
+ if (additionalParentValidations.length > 0) {
336
+ defaults = {
337
+ ...defaults,
338
+ pipeline: {
339
+ ...defaults.pipeline,
340
+ parent_validations: [
341
+ ...(defaults.pipeline?.parent_validations ?? []),
342
+ ...additionalParentValidations,
343
+ ],
344
+ },
345
+ };
346
+ }
289
347
  resolveParentValidationDefinitions(defaults.pipeline?.parent_validations);
290
348
  resolveParentValidationConcurrency(defaults.pipeline?.parent_validation_concurrency);
291
349
  resolveRegisterExecution(defaults);
@@ -57,6 +57,20 @@ const PARENT_VALIDATION_REGISTRY = {
57
57
  displayCommand: "npm run lint:md",
58
58
  timeoutMs: 10 * 60 * 1_000,
59
59
  },
60
+ build: {
61
+ id: "build",
62
+ command: process.platform === "win32" ? "npm.cmd" : "npm",
63
+ args: ["run", "build"],
64
+ displayCommand: "npm run build",
65
+ timeoutMs: 10 * 60 * 1_000,
66
+ },
67
+ "format-check": {
68
+ id: "format-check",
69
+ command: process.platform === "win32" ? "npm.cmd" : "npm",
70
+ args: ["run", "format:check"],
71
+ displayCommand: "npm run format:check",
72
+ timeoutMs: 10 * 60 * 1_000,
73
+ },
60
74
  };
61
75
  function truncateHead(value, limit) {
62
76
  if (value.length <= limit)
@@ -22,6 +22,7 @@ export function createPipelineState(input) {
22
22
  reporter: emptyStage(input.reporterActor),
23
23
  },
24
24
  ...(input.artifacts ? { artifacts: input.artifacts } : {}),
25
+ ...(input.integrationBranches ? { integration_branches: input.integrationBranches } : {}),
25
26
  };
26
27
  }
27
28
  function executionRelative(repoRoot, executionPath) {
@@ -47,6 +48,9 @@ function isStageState(value) {
47
48
  return false;
48
49
  const record = event;
49
50
  return ((record.action === "wait" || record.action === "fallback") &&
51
+ (record.trigger === undefined ||
52
+ record.trigger === "rate_limit" ||
53
+ record.trigger === "connection_error") &&
50
54
  typeof record.from_actor === "string" &&
51
55
  typeof record.to_actor === "string" &&
52
56
  typeof record.resumed_at === "string" &&
@@ -97,6 +101,12 @@ function isArtifactRefs(value) {
97
101
  typeof refs.result_ref === "string" &&
98
102
  !!refs.result_ref);
99
103
  }
104
+ function isIntegrationBranches(value) {
105
+ return (!!value &&
106
+ typeof value === "object" &&
107
+ !Array.isArray(value) &&
108
+ Object.entries(value).every(([repo, branch]) => /^[a-z0-9-]+$/.test(repo) && typeof branch === "string" && !!branch));
109
+ }
100
110
  export function isPipelineState(value) {
101
111
  if (!value || typeof value !== "object" || Array.isArray(value))
102
112
  return false;
@@ -114,6 +124,9 @@ export function isPipelineState(value) {
114
124
  }
115
125
  if (state.artifacts !== undefined && !isArtifactRefs(state.artifacts))
116
126
  return false;
127
+ if (state.integration_branches !== undefined &&
128
+ !isIntegrationBranches(state.integration_branches))
129
+ return false;
117
130
  const stages = state.stages;
118
131
  if (stages.integrate !== undefined && !isIntegrateStageState(stages.integrate))
119
132
  return false;
@@ -277,6 +277,20 @@ function registerCompletionConditions(item, ticketPath) {
277
277
  ? escapeMarkdownInline(item.description)
278
278
  : "- 個票に明示的な完了条件がないため、タイトルと概要を追加条件として扱う。";
279
279
  }
280
+ function registerAutopilotConstraints(item) {
281
+ if (item.autopilot !== "approved")
282
+ return "";
283
+ return [
284
+ "### 夜間 autopilot の制約",
285
+ "",
286
+ "この個票は人が記載済みの完了条件だけを承認した。次の操作は行わない。必要になった場合は、理由を result の申し送りへ記録して異常終了する。",
287
+ "",
288
+ "- decision の決定、保護された設定の変更、公開・tag・push。",
289
+ "- 公開済み CHANGELOG 節の変更、未承認項目の実行、完了条件や変更範囲の拡張。",
290
+ "- 別の登録項目を自分で実行すること。見つけた別問題は夜間 orchestrator が承認待ちとして起票する。",
291
+ "",
292
+ ].join("\n");
293
+ }
280
294
  function indexedDocumentPath(targetId) {
281
295
  const repoRoot = specdojoRootDir();
282
296
  const indexed = collectDocIndexEntries(join(repoRoot, "docs"), repoRoot)[targetId];
@@ -328,7 +342,12 @@ export async function generateRegisterPlan(opts) {
328
342
  targets: item.targets ?? [],
329
343
  deliverable,
330
344
  ...(refs ? { refs } : {}),
331
- additionalConditions: registerCompletionConditions(item, ticketPath),
345
+ additionalConditions: [
346
+ registerCompletionConditions(item, ticketPath),
347
+ registerAutopilotConstraints(item),
348
+ ]
349
+ .filter(Boolean)
350
+ .join("\n\n"),
332
351
  ...(opts.outPath ? { outPath: opts.outPath } : {}),
333
352
  stem: opts.stem,
334
353
  });
@@ -360,7 +379,10 @@ export async function generateRegisterPlan(opts) {
360
379
  _PJR_TICKET_REF_: ticketPath ? `\`${repoRelativePath(ticketPath)}\`` : "-",
361
380
  _RESULT_REF_: resultRef,
362
381
  _GRADE_FINDINGS_: ticketPath ? registerGradeFindingsText(opts.projectId, ticketPath) : "- なし",
382
+ _AUTOPILOT_CONSTRAINTS_: registerAutopilotConstraints(item),
363
383
  };
384
+ // 空に展開される段落(夜間の承認の印がない個票の _AUTOPILOT_CONSTRAINTS_ など)で重なる空行は
385
+ // expandTemplate がまとめる(PJR-283N)。
364
386
  const body = expandTemplate(template, values);
365
387
  // register 項目は対象成果物の schema を特定できないため、schema 検査の項目は落とす。
366
388
  const content = injectCommonConventions(body, MISSING, new Map());
@@ -248,7 +248,7 @@ export function productMergeBlockers(product) {
248
248
  const target = productIntegrationTarget(product);
249
249
  if (target === "HEAD" || !branchExists(product.repoRoot, target)) {
250
250
  blockers.push(block(`integration branch ${target === "HEAD" ? "(detached HEAD)" : target} is not a local ` +
251
- `branch; set repos[].integration_branch`));
251
+ `branch; set repos[].integration_branch or exec run --integration-branch`));
252
252
  return blockers;
253
253
  }
254
254
  if (target === product.branch) {
@@ -3,6 +3,7 @@ import { join, relative, resolve, sep } from "node:path";
3
3
  import { PARENT_VALIDATION_PROJECT_REPO, failedParentValidationReason, } from "./parent-validation.js";
4
4
  import { getProjectExecutionPath, resolveRepoRoot, specdojoRootDir, } from "../shared/specdojo-config.js";
5
5
  import { MAX_TEXT_LENGTH, parseReporterOutput, reporterOutputSchemaForMode, } from "./reporter-output.js";
6
+ import { repoEnvironmentVariableName } from "./task-repos.js";
6
7
  export { REPORTER_OUTPUT_SCHEMA, REVIEW_VERDICTS, parseReporterOutput, reporterOutputSchemaForMode, } from "./reporter-output.js";
7
8
  const REPORTER_FORMAT_ATTEMPTS = 3;
8
9
  function isProjectConfig(value) {
@@ -154,9 +155,10 @@ export function deriveReporterFacts(evidence, options = {}) {
154
155
  commands.add(command);
155
156
  target.set(repo, commands);
156
157
  };
157
- // sandbox で実行できない検証を executor が not_run(親 runner へ委譲)と記録し、runner が
158
- // 同じリポジトリで同じコマンドを実行して通した場合は満たされたものとして扱う。executor の
159
- // failed は runner の結果で打ち消さない(PJR-2GZE)。
158
+ // sandbox で実行できない検証を executor が not_run(親 runner へ委譲)または
159
+ // not_applicable と記録し、runner が同じリポジトリで同じコマンドを実行して通した場合は、
160
+ // 親検証の結果を正として満たされたものと扱う。executor の failed は runner の結果で
161
+ // 打ち消さない(PJR-2GZE、PJR-7AW0)。
160
162
  for (const validation of evidence.validations) {
161
163
  if (validation.status !== "passed")
162
164
  continue;
@@ -173,16 +175,27 @@ export function deriveReporterFacts(evidence, options = {}) {
173
175
  // `npm run check` のような合成コマンドを executor が not_run(親 runner へ委譲)とした場合は、
174
176
  // 対象リポジトリの package.json の script を展開し、構成する各コマンドが同じリポジトリの
175
177
  // 親検証か executor 自身の検証で通っていれば満たされたものとして扱う(PJR-SDWF)。
176
- const isDelegatedValidationSatisfied = (command) => {
178
+ const validationCommandAndRepo = (command) => {
177
179
  const manifest = commandManifest(normalizeValidationCommand(command), applicabilityOptions, specdojoConfig);
178
- const repo = manifest.repoName ?? PARENT_VALIDATION_PROJECT_REPO;
179
- const runnerPassedCommands = runnerPassedCommandsByRepo.get(repo) ?? new Set();
180
- if (runnerPassedCommands.has(manifest.command))
180
+ return {
181
+ command: manifest.command,
182
+ repo: manifest.repoName ?? PARENT_VALIDATION_PROJECT_REPO,
183
+ scripts: manifest.scripts,
184
+ };
185
+ };
186
+ const isPassedParentValidation = (command) => {
187
+ const target = validationCommandAndRepo(command);
188
+ return (runnerPassedCommandsByRepo.get(target.repo) ?? new Set()).has(target.command);
189
+ };
190
+ const isDelegatedValidationSatisfied = (command) => {
191
+ const target = validationCommandAndRepo(command);
192
+ if ((runnerPassedCommandsByRepo.get(target.repo) ?? new Set()).has(target.command)) {
181
193
  return true;
182
- const passedCommands = passedCommandsByRepo.get(repo) ?? new Set();
183
- const components = compositeComponents(manifest.command, manifest.scripts);
194
+ }
195
+ const passedCommands = passedCommandsByRepo.get(target.repo) ?? new Set();
196
+ const components = compositeComponents(target.command, target.scripts);
184
197
  return (components !== undefined &&
185
- components.every((component) => isComponentSatisfied(component, passedCommands, manifest.scripts)));
198
+ components.every((component) => isComponentSatisfied(component, passedCommands, target.scripts)));
186
199
  };
187
200
  // runner が担う検証(index build)の executor 側の not_run / not_applicable は満たしたものとする。
188
201
  // runner の再生成が失敗した場合は worktree の準備で run が止まり、runner の記録に失敗が残れば
@@ -202,6 +215,10 @@ export function deriveReporterFacts(evidence, options = {}) {
202
215
  runnerOwnedValidationReason(validation.command) !== undefined) {
203
216
  return false;
204
217
  }
218
+ if ((validation.status === "not_run" || validation.status === "not_applicable") &&
219
+ isPassedParentValidation(validation.command)) {
220
+ return false;
221
+ }
205
222
  if (validation.status === "not_applicable") {
206
223
  return !isValidNotApplicableValidation(validation.command, validation.reason, applicabilityOptions);
207
224
  }
@@ -279,6 +296,60 @@ export function runnerOwnedValidationReason(command) {
279
296
  return "index は runner が worktree の準備と統合の前に再生成する";
280
297
  }
281
298
  const PROJECT_DOCUMENTS_ROOT = "docs/ja/projects/";
299
+ const hasExtension = (extensions) => (path) => {
300
+ const normalized = path.toLowerCase();
301
+ return extensions.some((extension) => normalized.endsWith(extension));
302
+ };
303
+ // The command-to-change mapping is kept in one place and mirrors the change-type rows in
304
+ // xep-common-conventions-template.md. Checks such as typecheck intentionally remain outside this
305
+ // table: PJR-8WBN requires their existing script-based applicability to stay unchanged.
306
+ const CHANGE_SCOPED_VALIDATIONS = [
307
+ {
308
+ pathCondition: "YAML ファイル(*.yaml / *.yml)",
309
+ matchesCommand: (command) => /^npm run validate:schema:file(?:\s|$)/u.test(command),
310
+ matchesPath: hasExtension([".yaml", ".yml"]),
311
+ },
312
+ {
313
+ pathCondition: "Prettier 対象ファイル(*.md / *.ts / *.js / *.json / *.yaml / *.yml)",
314
+ matchesCommand: (command) => /^(?:npx\s+)?prettier(?:\s|$)/u.test(command),
315
+ matchesPath: hasExtension([".md", ".ts", ".js", ".json", ".yaml", ".yml"]),
316
+ },
317
+ {
318
+ pathCondition: "Markdown ファイル(*.md)",
319
+ matchesCommand: (command) => /^npm run lint:md(?:\s|$)/u.test(command) ||
320
+ /^(?:npx\s+)?(?:markdownlint|markdownlint-cli2)(?:\s|$)/u.test(command) ||
321
+ /^node\s+\S*specdojo-docs-lint\.js\s+markdownlint(?:\s|$)/u.test(command),
322
+ matchesPath: hasExtension([".md"]),
323
+ },
324
+ ];
325
+ function changedPathSides(path) {
326
+ return path.split(" -> ").map((side) => side.replaceAll("\\", "/").replace(/^\.\//u, ""));
327
+ }
328
+ function changePathsForCommand(changedPaths, repoName, config, projectId) {
329
+ const repoNames = declaredRepos(config, projectId).map((repo) => repo.name);
330
+ return changedPaths.flatMap(changedPathSides).flatMap((path) => {
331
+ if (repoName !== undefined) {
332
+ const prefix = `${repoName}:`;
333
+ return path.startsWith(prefix) ? [path.slice(prefix.length)] : [];
334
+ }
335
+ return repoNames.some((name) => path.startsWith(`${name}:`)) ? [] : [path];
336
+ });
337
+ }
338
+ function changeScopedValidationApplicability(command, changedPaths, repoName, config, projectId) {
339
+ const validation = CHANGE_SCOPED_VALIDATIONS.find(({ matchesCommand }) => matchesCommand(command));
340
+ if (!validation)
341
+ return { recognized: false };
342
+ if (changedPaths === undefined)
343
+ return { recognized: true };
344
+ const relevantPaths = changePathsForCommand(changedPaths, repoName, config, projectId);
345
+ return relevantPaths.some(validation.matchesPath)
346
+ ? { recognized: true, applicable: true }
347
+ : {
348
+ recognized: true,
349
+ applicable: false,
350
+ reason: `変更に ${validation.pathCondition} がない`,
351
+ };
352
+ }
282
353
  function changesReachProjectDocuments(changedPaths) {
283
354
  return changedPaths
284
355
  .flatMap((path) => path.split(" -> "))
@@ -336,6 +407,9 @@ export function mechanicallyNotApplicableReason(command, options = {}) {
336
407
  return specdojo.applicable === false ? specdojo.reason : undefined;
337
408
  }
338
409
  const manifest = commandManifest(normalized, options, config);
410
+ const changeScoped = changeScopedValidationApplicability(manifest.command, options.changedPaths, manifest.repoName, config, options.projectId);
411
+ if (changeScoped.applicable === false)
412
+ return changeScoped.reason;
339
413
  const packageJson = manifest.repoName === undefined ? "package.json" : `${manifest.repoName} の package.json`;
340
414
  const scriptName = invokedScriptNameOf(manifest.command);
341
415
  if (scriptName !== undefined && !hasApplicableScript(manifest.scripts, scriptName)) {
@@ -358,11 +432,16 @@ function isValidNotApplicableValidation(command, reason, options) {
358
432
  if (specdojo.recognized)
359
433
  return specdojo.applicable !== true;
360
434
  const manifest = commandManifest(normalized, options, config);
435
+ const changeScoped = changeScopedValidationApplicability(manifest.command, options.changedPaths, manifest.repoName, config, options.projectId);
436
+ if (changeScoped.applicable === false)
437
+ return true;
361
438
  const scriptName = invokedScriptNameOf(manifest.command);
362
439
  if (scriptName !== undefined && hasApplicableScript(manifest.scripts, scriptName))
363
440
  return false;
364
441
  const packageName = npxPackageNameOf(manifest.command);
365
- return packageName === undefined || !manifest.dependencies.has(packageName);
442
+ if (packageName !== undefined)
443
+ return !manifest.dependencies.has(packageName);
444
+ return true;
366
445
  }
367
446
  const PREFIX_OPTION_PATTERN = /(?:^|\s)--prefix(?:=|\s+)(\S+)(?=\s|$)/u;
368
447
  function normalizeRepoPathText(path) {
@@ -380,8 +459,26 @@ function declaredRepos(config, projectId) {
380
459
  typeof repo.path === "string");
381
460
  }
382
461
  /**
383
- * Identifies a command that targets a declared product repository, either through
384
- * `--prefix <repo>` (the repository name or its configured path) or a `<repo>:<path>` argument.
462
+ * True when a command references a shell variable without mistaking a longer variable name for
463
+ * the requested one. Both `$NAME` and `${NAME}` forms are recognized.
464
+ */
465
+ function referencesShellVariable(command, variable) {
466
+ if (command.includes("${" + variable + "}"))
467
+ return true;
468
+ const reference = `$${variable}`;
469
+ let offset = command.indexOf(reference);
470
+ while (offset >= 0) {
471
+ const next = command[offset + reference.length];
472
+ if (next === undefined || !/[A-Za-z0-9_]/u.test(next))
473
+ return true;
474
+ offset = command.indexOf(reference, offset + reference.length);
475
+ }
476
+ return false;
477
+ }
478
+ /**
479
+ * Identifies a command that targets a declared product repository through `--prefix <repo>` (the
480
+ * repository name or its configured path), `$SPECDOJO_REPO_<NAME>` / its braced form, or a
481
+ * `<repo>:<path>` argument.
385
482
  */
386
483
  function productRepoCommand(command, repos) {
387
484
  const prefix = PREFIX_OPTION_PATTERN.exec(command)?.[1];
@@ -395,6 +492,9 @@ function productRepoCommand(command, repos) {
395
492
  command: normalizeValidationCommand(command.replace(PREFIX_OPTION_PATTERN, " ")),
396
493
  };
397
494
  }
495
+ const environmentRepo = repos.find((candidate) => referencesShellVariable(command, repoEnvironmentVariableName(candidate.name)));
496
+ if (environmentRepo)
497
+ return { repo: environmentRepo, command };
398
498
  const tokens = command.split(" ");
399
499
  const repo = repos.find((candidate) => tokens.some((token) => token.startsWith(`${candidate.name}:`)));
400
500
  return repo ? { repo, command } : undefined;
@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSy
3
3
  import { dirname, join, resolve, sep } from "node:path";
4
4
  import { isDeepStrictEqual } from "node:util";
5
5
  import { buildSpecdojoFrontmatter, parseSpecdojoDocument } from "../docs/frontmatter-namespace.js";
6
- import { expandTemplate, stripTerminalControlSequences } from "./shared.js";
6
+ import { escapeMarkdownInline, expandTemplate, stripTerminalControlSequences } from "./shared.js";
7
7
  import { formatMarkdownFile } from "./format.js";
8
8
  import { deriveReporterFacts, mechanicallyNotApplicableReason, runnerOwnedValidationReason, } from "./reporter.js";
9
9
  import { resolveSpecdojoPath, resolveSpecdojoPathIfExists } from "../docs/template-resolution.js";
@@ -325,10 +325,32 @@ function reporterInlineText(value) {
325
325
  .replace(/>/g, "&gt;")
326
326
  .trim();
327
327
  }
328
+ // reporter / executor 由来の自由記述は result の Markdown 本文へ直接入る。改行や山括弧を
329
+ // 正規化したうえで、強調と解釈される `_` / `*` 入りの ASCII トークンを code span にする。
330
+ // escapeMarkdownInline は既存の code span を保持するため、agent が意図して付けた書式は二重化しない。
331
+ function reporterFreeText(value) {
332
+ return escapeMarkdownInline(reporterInlineText(value));
333
+ }
334
+ // reporter や runner の文を `- ` の箇条書きに描くとき、文が自前のリスト記号(`1.`・`1)`・
335
+ // `-`・`*`・`+`)で始まると `- 1. ...` が入れ子のリストとして解釈され、markdownlint の
336
+ // MD029 などに当たって pre-commit hook で記帳の commit が失敗する。箇条書きの記号は runner が
337
+ // 付けるため、先頭の記号は外す(番号の意味は箇条書きの順序で保たれる)。
338
+ export function stripLeadingListMarker(text) {
339
+ let current = text.trim();
340
+ for (;;) {
341
+ const next = current.replace(/^(?:\d{1,9}[.)]|[-*+])(?:\s+|$)/u, "").trim();
342
+ if (next === current)
343
+ return current;
344
+ current = next;
345
+ }
346
+ }
328
347
  function reporterBulletList(values, empty) {
329
348
  if (values.length === 0)
330
349
  return `- ${empty}`;
331
- return values.map((value) => `- ${reporterInlineText(value)}`).join("\n");
350
+ return values
351
+ .map((value) => reporterFreeText(stripLeadingListMarker(reporterInlineText(value))))
352
+ .map((text) => `- ${text || empty}`)
353
+ .join("\n");
332
354
  }
333
355
  function findGitRoot(startDir) {
334
356
  try {
@@ -471,7 +493,7 @@ export function renderEditReporterBody(output, evidence, options) {
471
493
  const summary = reporterSummary !== undefined && reporterSummary.trim().length > 0
472
494
  ? reporterSummary
473
495
  : formatMissingSummary(file, lineStats?.get(displayPath) ?? lineStats?.get(file.path));
474
- return `- \`${reporterInlineText(displayPath).replace(/`/g, "'")}\`: ${reporterInlineText(summary)}`;
496
+ return `- \`${reporterInlineText(displayPath).replace(/`/g, "'")}\`: ${reporterFreeText(summary)}`;
475
497
  })
476
498
  .join("\n");
477
499
  }
@@ -494,7 +516,7 @@ export function renderEditReporterBody(output, evidence, options) {
494
516
  }
495
517
  const lines = [];
496
518
  for (const entry of describedFiles) {
497
- lines.push(`- \`${reporterInlineText(entry.displayPath).replace(/`/g, "'")}\`: ${reporterInlineText(entry.summary)}`);
519
+ lines.push(`- \`${reporterInlineText(entry.displayPath).replace(/`/g, "'")}\`: ${reporterFreeText(entry.summary)}`);
498
520
  }
499
521
  const dirGroups = new Map();
500
522
  for (const entry of undescribedFiles) {
@@ -546,20 +568,20 @@ export function renderEditReporterBody(output, evidence, options) {
546
568
  .filter((entry) => entry.status === "unchanged")
547
569
  .map((entry) => {
548
570
  const target = reporterInlineText(entry.target).replace(/`/g, "'");
549
- return `対象 \`${target}\` は未変更: ${reporterInlineText(entry.reason)}`;
571
+ return `対象 \`${target}\` は未変更: ${reporterFreeText(entry.reason)}`;
550
572
  });
551
573
  const humanValidationNotes = evidence.validations
552
574
  .filter((validation) => validation.source !== "runner" && validation.status === "requires_human")
553
575
  .map((validation) => {
554
576
  const command = reporterInlineText(validation.command).replace(/`/g, "'");
555
- const summary = reporterInlineText(validation.summary) || "要約なし";
577
+ const summary = reporterFreeText(validation.summary) || "要約なし";
556
578
  return `人の確認が必要: \`${command}\`(${summary})`;
557
579
  });
558
580
  const notApplicableValidationNotes = evidence.validations
559
581
  .filter((validation) => validation.source !== "runner" && validation.status === "not_applicable")
560
582
  .map((validation) => {
561
583
  const command = reporterInlineText(validation.command).replace(/`/g, "'");
562
- const reason = reporterInlineText(validation.reason ?? "") || "理由なし";
584
+ const reason = reporterFreeText(validation.reason ?? "") || "理由なし";
563
585
  return `適用外の検証: \`${command}\`(${reason})`;
564
586
  });
565
587
  const changedPaths = evidence.changes.map((change) => change.path);
@@ -570,7 +592,7 @@ export function renderEditReporterBody(output, evidence, options) {
570
592
  if (reason === undefined)
571
593
  return [];
572
594
  const command = reporterInlineText(validation.command).replace(/`/g, "'");
573
- return [`runner が担う検証: \`${command}\`(${reporterInlineText(reason)})`];
595
+ return [`runner が担う検証: \`${command}\`(${reporterFreeText(reason)})`];
574
596
  });
575
597
  const runnerJudgedNotApplicableNotes = evidence.validations
576
598
  .filter((validation) => validation.source !== "runner" && validation.status === "not_run")
@@ -579,11 +601,11 @@ export function renderEditReporterBody(output, evidence, options) {
579
601
  if (reason === undefined)
580
602
  return [];
581
603
  const command = reporterInlineText(validation.command).replace(/`/g, "'");
582
- return [`適用外の検証(runner の判定): \`${command}\`(${reporterInlineText(reason)})`];
604
+ return [`適用外の検証(runner の判定): \`${command}\`(${reporterFreeText(reason)})`];
583
605
  });
584
606
  const rateLimitRecoveryNotes = (evidence.rate_limit_events ?? []).map((event) => event.action === "wait"
585
607
  ? `rate limit 後に ${event.resume_at ?? "再開可能時刻"} まで待ち、${event.to_actor} で ${event.resumed_at} に再開`
586
- : `rate limit 後に ${event.from_actor} から ${event.to_actor} へ切り替え、${event.resumed_at} に再開`);
608
+ : `${event.trigger === "connection_error" ? "接続エラー" : "rate limit"}後に ${event.from_actor} から ${event.to_actor} へ切り替え、${event.resumed_at} に再開`);
587
609
  return [
588
610
  "# Edit Result",
589
611
  "",
@@ -609,7 +631,7 @@ export function renderEditReporterBody(output, evidence, options) {
609
631
  "",
610
632
  options?.approach ? "## 4. 進め方と実践の型の適用" : "## 4. 進め方",
611
633
  "",
612
- reporterInlineText(output.approach),
634
+ reporterFreeText(output.approach),
613
635
  ].join("\n");
614
636
  }
615
637
  // review result の章立ては xrr-template.md と一致させる。review は成果物を再評価しないため、
@@ -617,13 +639,13 @@ export function renderEditReporterBody(output, evidence, options) {
617
639
  function renderReviewReporterBody(output, evidence) {
618
640
  const rateLimitRecoveryNotes = (evidence.rate_limit_events ?? []).map((event) => event.action === "wait"
619
641
  ? `rate limit 後に ${event.resume_at ?? "再開可能時刻"} まで待ち、${event.to_actor} で ${event.resumed_at} に再開`
620
- : `rate limit 後に ${event.from_actor} から ${event.to_actor} へ切り替え、${event.resumed_at} に再開`);
642
+ : `${event.trigger === "connection_error" ? "接続エラー" : "rate limit"}後に ${event.from_actor} から ${event.to_actor} へ切り替え、${event.resumed_at} に再開`);
621
643
  return [
622
644
  "# Review Result",
623
645
  "",
624
646
  "## 1. 評価結果の確認",
625
647
  "",
626
- reporterInlineText(output.grade_check),
648
+ reporterFreeText(output.grade_check),
627
649
  "",
628
650
  "## 2. 判断根拠",
629
651
  "",
@@ -635,7 +657,7 @@ function renderReviewReporterBody(output, evidence) {
635
657
  "",
636
658
  "## 4. approach に応じた確認",
637
659
  "",
638
- reporterInlineText(output.approach),
660
+ reporterFreeText(output.approach),
639
661
  "",
640
662
  "## 5. decision",
641
663
  "",
@@ -157,6 +157,9 @@ export async function runAgentPipeline(params) {
157
157
  plan_ref: relative(repoRoot, params.planPath).split(sep).join("/"),
158
158
  result_ref: relative(cwd, resultPath).split(sep).join("/"),
159
159
  },
160
+ ...(params.integrationBranchOverrides
161
+ ? { integrationBranches: { ...params.integrationBranchOverrides } }
162
+ : {}),
160
163
  });
161
164
  state = updatePipelineStage(state, "executor", { status: "running", started_at: startedAt }, startedAt);
162
165
  writePipelineState(stateLocation.path, state);