specdojo 0.3.1 → 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.
- package/.github/agents/specdojo-orchestrator.md +61 -2
- package/CHANGELOG.md +90 -0
- package/README.md +85 -25
- package/dist/{catalog-build-references.js → catalog/build-references.js} +4 -4
- package/dist/catalog/build-render.js +32 -0
- package/dist/{catalog-build.js → catalog/build.js} +9 -9
- package/dist/{catalog.js → catalog/catalog.js} +10 -10
- package/dist/{catalog-generate.js → catalog/generate.js} +8 -8
- package/dist/catalog/paths.js +1 -0
- package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +4 -4
- package/dist/{catalog-plan.js → catalog/plan.js} +4 -4
- package/dist/{catalog-scaffold.js → catalog/scaffold.js} +3 -3
- package/dist/{agent.js → commands/agent.js} +11 -11
- package/dist/{build-command.js → commands/build.js} +2 -2
- package/dist/{init-command.js → commands/init.js} +168 -45
- package/dist/commands/night-orchestrator.js +287 -0
- package/dist/{orchestrator.js → commands/orchestrator.js} +12 -5
- package/dist/{watch.js → commands/watch.js} +3 -3
- package/dist/{dashboard-timeline.js → dashboard/dashboard-timeline.js} +2 -2
- package/dist/{dashboard.js → dashboard/dashboard.js} +11 -10
- package/dist/{dashboard-exec-records.js → dashboard/exec-records.js} +2 -2
- package/dist/{dashboard-routines.js → dashboard/routines.js} +6 -5
- package/dist/{dashboard-shared.js → dashboard/shared.js} +1 -1
- package/dist/{timeline-build.js → dashboard/timeline-build.js} +2 -1
- package/dist/{timeline.js → dashboard/timeline.js} +1 -1
- package/dist/{deliverable.js → deliverable/deliverable.js} +5 -5
- package/dist/{deliverable-trash.js → deliverable/trash.js} +5 -5
- package/dist/{devcontainer-command.js → devcontainer/command.js} +8 -4
- package/dist/devcontainer/scaffold.js +418 -0
- package/dist/{doc-index.js → docs/doc-index.js} +1 -1
- package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +1 -1
- package/dist/{index-command.js → docs/index-command.js} +1 -1
- package/dist/docs/template-resolution.js +1 -0
- package/dist/{viewpoint-document-kinds-check.js → docs/viewpoint-document-kinds-check.js} +1 -1
- package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
- package/dist/{yaml-pages.js → docs/yaml-pages.js} +2 -2
- package/dist/{exec-agent-config.js → exec/agent-config.js} +92 -5
- package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
- package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
- package/dist/{exec-commands.js → exec/commands.js} +22 -18
- package/dist/{exec-core.js → exec/core.js} +11 -11
- package/dist/{exec-events.js → exec/events.js} +2 -2
- package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
- package/dist/exec/exec.js +2 -0
- package/dist/exec/format.js +1 -0
- package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
- package/dist/{exec-limit.js → exec/limit.js} +93 -12
- package/dist/{exec-parent-validation.js → exec/parent-validation.js} +18 -4
- package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +29 -2
- package/dist/{exec-plans-core.js → exec/plans-core.js} +68 -114
- package/dist/{exec-plans-generation.js → exec/plans-generation.js} +53 -10
- package/dist/{exec-plans-storage.js → exec/plans-storage.js} +5 -5
- package/dist/{exec-plans.js → exec/plans.js} +3 -3
- package/dist/{exec-project.js → exec/project.js} +1 -1
- package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
- package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
- package/dist/{exec-register.js → exec/register.js} +114 -9
- package/dist/{exec-repo-integration-git.js → exec/repo-integration-git.js} +2 -2
- package/dist/{exec-repo-integration-sync.js → exec/repo-integration-sync.js} +4 -4
- package/dist/{exec-repo-integration.js → exec/repo-integration.js} +14 -11
- package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
- package/dist/{exec-reporter-output.js → exec/reporter-output.js} +2 -2
- package/dist/{exec-reporter.js → exec/reporter.js} +142 -25
- package/dist/{exec-results.js → exec/results.js} +287 -31
- package/dist/{exec-run-agent-pipeline.js → exec/run/agent-pipeline.js} +35 -12
- package/dist/{exec-run-agent.js → exec/run/agent.js} +115 -28
- package/dist/{exec-run-in-place.js → exec/run/in-place.js} +56 -27
- package/dist/{exec-run-job.js → exec/run/job.js} +65 -36
- package/dist/{exec-run-lifecycle-commands.js → exec/run/lifecycle-commands.js} +30 -22
- package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
- package/dist/{exec-run-mode-shared.js → exec/run/mode-shared.js} +3 -3
- package/dist/{exec-run-register-command.js → exec/run/register-command.js} +38 -11
- package/dist/{exec-run-register-core.js → exec/run/register-core.js} +63 -21
- package/dist/{exec-run-register-mode.js → exec/run/register-mode.js} +58 -31
- package/dist/exec/run/register-post-review.js +420 -0
- package/dist/{exec-run-register-resume.js → exec/run/register-resume.js} +48 -27
- package/dist/{exec-run-register-state.js → exec/run/register-state.js} +13 -10
- package/dist/{exec-run-register-worktree.js → exec/run/register-worktree.js} +119 -24
- package/dist/{exec-run.js → exec/run/run.js} +11 -11
- package/dist/{exec-run-schedule-mode.js → exec/run/schedule-mode.js} +17 -17
- package/dist/{exec-run-schedule-prepare.js → exec/run/schedule-prepare.js} +31 -18
- package/dist/{exec-run-schedule-task.js → exec/run/schedule-task.js} +45 -18
- package/dist/{exec-run-shared.js → exec/run/shared.js} +78 -30
- package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
- package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
- package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
- package/dist/exec/schedule/gantt-chart.js +2 -0
- package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
- package/dist/exec/schedule/index.js +1 -0
- package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
- package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
- package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
- package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
- package/dist/exec/shared.js +63 -0
- package/dist/exec/slot-lock.js +1 -0
- package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
- package/dist/{exec-task-repos.js → exec/task-repos.js} +104 -17
- package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
- package/dist/{exec-trial-commands.js → exec/trial-commands.js} +20 -22
- package/dist/{exec-trial-core.js → exec/trial-core.js} +6 -6
- package/dist/{exec-trial.js → exec/trial.js} +2 -2
- package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
- package/dist/{exec-worktree-ops-commit.js → exec/worktree-ops-commit.js} +25 -60
- package/dist/{exec-worktree-ops-lifecycle.js → exec/worktree-ops-lifecycle.js} +13 -8
- package/dist/{exec-worktree-ops-merge.js → exec/worktree-ops-merge.js} +48 -7
- package/dist/{exec-worktree-ops.js → exec/worktree-ops.js} +3 -3
- package/dist/exec/worktree.js +305 -0
- package/dist/{grade-apply.js → grade/apply.js} +9 -9
- package/dist/{grade-command-apply.js → grade/command-apply.js} +7 -7
- package/dist/{grade-command-inspect.js → grade/command-inspect.js} +6 -6
- package/dist/{grade-command-plan.js → grade/command-plan.js} +5 -5
- package/dist/{grade-core.js → grade/core.js} +3 -3
- package/dist/grade/grade.js +19 -0
- package/dist/{grade-markdown.js → grade/markdown.js} +6 -6
- package/dist/{grade-pipeline-state.js → grade/pipeline-state.js} +4 -4
- package/dist/{grade-plan.js → grade/plan.js} +5 -5
- package/dist/{grade-result.js → grade/result.js} +5 -94
- package/dist/{grade-target-discovery.js → grade/target-discovery.js} +7 -7
- package/dist/{grade-targets.js → grade/targets.js} +11 -8
- package/dist/{job-definition.js → job/definition.js} +25 -6
- package/dist/{job.js → job/job.js} +12 -11
- package/dist/{kata-command.js → kata/command.js} +3 -3
- package/dist/{kata.js → kata/kata.js} +5 -5
- package/dist/register/approach.js +134 -0
- package/dist/{register-core.js → register/core.js} +26 -8
- package/dist/{register-create-commands.js → register/create-commands.js} +171 -8
- package/dist/{register-date.js → register/date.js} +1 -1
- package/dist/register/derivation.js +163 -0
- package/dist/{register-event-merge.js → register/event-merge.js} +44 -3
- package/dist/{register-events.js → register/events.js} +13 -3
- package/dist/{register-history.js → register/history.js} +7 -6
- package/dist/{register-item.js → register/item.js} +32 -5
- package/dist/register/lifecycle-lock.js +5 -0
- package/dist/{register-maintenance-commands.js → register/maintenance-commands.js} +13 -7
- package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
- package/dist/{register-migration.js → register/migration.js} +5 -4
- package/dist/{register.js → register/register.js} +32 -27
- package/dist/{register-renumber.js → register/renumber.js} +38 -11
- package/dist/{register-transition-commands.js → register/transition-commands.js} +3 -3
- package/dist/{register-update.js → register/update.js} +5 -5
- package/dist/{register-views.js → register/views.js} +47 -7
- package/dist/{review-grade.js → review/grade.js} +2 -2
- package/dist/{review-plan.js → review/plan.js} +3 -3
- package/dist/{routine-definition.js → routine/definition.js} +2 -2
- package/dist/{routine.js → routine/routine.js} +49 -22
- package/dist/{schedule-approach.js → schedule/approach.js} +8 -8
- package/dist/{schedule-build.js → schedule/build.js} +7 -4
- package/dist/{schedule.js → schedule/schedule.js} +6 -6
- package/dist/{schedule-strategy-generate-document.js → schedule/strategy-generate-document.js} +2 -2
- package/dist/{schedule-strategy-generate-scope.js → schedule/strategy-generate-scope.js} +4 -4
- package/dist/{schedule-strategy-generate.js → schedule/strategy-generate.js} +10 -10
- package/dist/shared/agent-types.js +23 -0
- package/dist/shared/artifact-path.js +9 -0
- package/dist/{build-if-stale.js → shared/build-if-stale.js} +1 -1
- package/dist/{catalog-build-render.js → shared/catalog-render.js} +3 -32
- package/dist/{exec-slot-lock.js → shared/cross-process-lock.js} +3 -1
- package/dist/shared/fs.js +30 -0
- package/dist/shared/git.js +346 -0
- package/dist/shared/grade-result.js +94 -0
- package/dist/{package-paths.js → shared/package-paths.js} +3 -3
- package/dist/shared/plan-templates.js +114 -0
- package/dist/{exec-provider-scaffold.js → shared/provider-scaffold.js} +6 -3
- package/dist/shared/random.js +4 -0
- package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
- package/dist/shared/schedule-paths.js +9 -0
- package/dist/{specdojo-config.js → shared/specdojo-config.js} +162 -21
- package/dist/{exec-shared.js → shared/text.js} +4 -135
- package/dist/shared/time.js +28 -0
- package/dist/shared/workspace-scaffold.js +69 -0
- package/dist/specdojo.js +22 -22
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +31 -18
- package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xep-register-template.md +3 -2
- package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
- package/docs/ja/specdojo/exec-templates/xrp-register-post-run-template.md +46 -0
- package/docs/ja/specdojo/guides/branch-workflow-guide.md +34 -1
- package/docs/ja/specdojo/guides/docs-structure-guide.md +2 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +169 -26
- package/docs/ja/specdojo/guides/exec-operation-guide.md +184 -13
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +40 -3
- package/docs/ja/specdojo/guides/quick-start-guide.md +89 -21
- package/docs/ja/specdojo/guides/register-operation-guide.md +44 -1
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +61 -6
- package/docs/ja/specdojo/guides/review-guide.md +1 -1
- package/docs/ja/specdojo/guides/routine-operation-guide.md +5 -5
- package/docs/ja/specdojo/guides/specdojo-overview-guide.md +1 -1
- package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
- package/docs/ja/specdojo/guides/waza-guide.md +1 -1
- package/docs/ja/specdojo/references/command-reference.md +124 -55
- package/docs/ja/specdojo/references/specdojo-config-reference.md +33 -7
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +22 -13
- package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
- package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
- package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +111 -17
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +28 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
- package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +38 -0
- package/docs/specdojo/schemas/v1/register-events.schema.yaml +5 -0
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +91 -7
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +36 -1
- package/package.json +17 -17
- package/templates/antigravity/README.md +6 -2
- package/templates/antigravity/agent-members-snippet.yaml +108 -12
- package/templates/antigravity/exec-defaults-snippet.yaml +8 -13
- package/templates/antigravity/orchestrator.md +61 -2
- package/templates/claude/README.md +27 -3
- package/templates/claude/agents/claude-executor.md +0 -1
- package/templates/claude/agents/claude-reporter.md +2 -1
- package/templates/claude/agents/claude-review-executor.md +0 -1
- package/templates/claude/agents/specdojo-orchestrator.md +61 -2
- package/templates/codex/README.md +40 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +61 -2
- package/templates/codex/orchestrator.md +61 -2
- package/templates/devcontainer/devcontainer.json +5 -2
- package/templates/devcontainer/post-create.sh +15 -7
- package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +102 -0
- package/templates/devcontainer/remote-host/ssh-config.sample +19 -0
- package/templates/devcontainer/vim/vimrc +37 -0
- package/templates/init-agent-members.yaml +75 -25
- package/templates/init-exec-defaults.yaml +44 -9
- package/templates/opencode/README.md +17 -3
- package/templates/opencode/agents/opencode-executor.md +0 -1
- package/templates/opencode/agents/opencode-reporter.md +2 -1
- package/templates/opencode/agents/opencode-review-executor.md +0 -1
- package/templates/opencode/agents/specdojo-orchestrator.md +61 -2
- package/dist/devcontainer-scaffold.js +0 -165
- package/dist/exec-schedule-gantt-chart.js +0 -2
- package/dist/exec-worktree.js +0 -474
- package/dist/exec.js +0 -2
- package/dist/grade.js +0 -19
- package/templates/claude/agents/claude-expert-review-executor.md +0 -14
- /package/dist/{catalog-plan-prompt.js → catalog/plan-prompt.js} +0 -0
- /package/dist/{catalog-types.js → catalog/types.js} +0 -0
- /package/dist/{template-frontmatter.js → docs/template-frontmatter.js} +0 -0
- /package/dist/{role-types.js → exec/role-types.js} +0 -0
- /package/dist/{exec-schedule-gantt-chart-scope.js → exec/schedule/gantt-chart-scope.js} +0 -0
- /package/dist/{exec-types.js → exec/types.js} +0 -0
- /package/dist/{grade-command-shared.js → grade/command-shared.js} +0 -0
- /package/dist/{register-command-types.js → register/command-types.js} +0 -0
- /package/dist/{review-types.js → review/types.js} +0 -0
- /package/dist/{schedule-phase-sets.js → schedule/phase-sets.js} +0 -0
- /package/dist/{schedule-strategy-profiles.js → schedule/strategy-profiles.js} +0 -0
- /package/dist/{agent-response.js → shared/agent-response.js} +0 -0
- /package/dist/{catalog-paths.js → shared/catalog-paths.js} +0 -0
- /package/dist/{dist-freshness.js → shared/dist-freshness.js} +0 -0
- /package/dist/{git-environment.js → shared/git-environment.js} +0 -0
- /package/dist/{exec-format.js → shared/markdown-format.js} +0 -0
- /package/dist/{practice-id.js → shared/practice-id.js} +0 -0
- /package/dist/{spawn-self.js → shared/spawn-self.js} +0 -0
- /package/dist/{specdojo-gitignore.js → shared/specdojo-gitignore.js} +0 -0
- /package/dist/{template-resolution.js → shared/template-resolution.js} +0 -0
- /package/dist/{yaml-schema-modeline.js → shared/yaml-schema-modeline.js} +0 -0
- /package/dist/{yaml.js → shared/yaml.js} +0 -0
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
-
import { defaultExecDefaultsPath, loadExecDefaultsConfig, resolveMemberCommand, resolveRateLimitDetection, resolveRateLimitPolicy, } from "
|
|
4
|
-
import { resolveProjectPaths } from "
|
|
5
|
-
import { executeAgent, loadRosterForExecutionPath } from "
|
|
6
|
-
import { gitEnvironment } from "
|
|
7
|
-
import { specdojoRootDir } from "
|
|
3
|
+
import { defaultExecDefaultsPath, loadExecDefaultsConfig, resolveMemberCommand, resolveRateLimitDetection, resolveRateLimitPolicy, } from "../exec/agent-config.js";
|
|
4
|
+
import { resolveProjectPaths } from "../exec/project.js";
|
|
5
|
+
import { executeAgent, loadRosterForExecutionPath } from "../exec/run/run.js";
|
|
6
|
+
import { gitEnvironment } from "../shared/git-environment.js";
|
|
7
|
+
import { resolveAgentMember as resolveRosterAgentMember, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
8
8
|
// Rate limit は通常失敗と異なり、呼び出し側が処理済みにせず中断・再開する必要がある。
|
|
9
9
|
// shell script が出力文字列を解析せず分岐できるよう、一時失敗を表す専用コードにする。
|
|
10
10
|
export const AGENT_RUN_RATE_LIMIT_EXIT_CODE = 75;
|
|
11
11
|
export function resolveAgentMember(roster, nickname) {
|
|
12
|
-
const
|
|
12
|
+
const directMembers = roster?.members.filter((candidate) => {
|
|
13
13
|
return candidate.type === "agent" && candidate.nickname === nickname;
|
|
14
14
|
});
|
|
15
|
-
if (
|
|
16
|
-
return { error: `--by agent nickname not found in agent-members.yaml: ${nickname}` };
|
|
17
|
-
}
|
|
18
|
-
if (members.length !== 1) {
|
|
15
|
+
if (directMembers && directMembers.length > 1) {
|
|
19
16
|
return { error: `--by agent nickname is not unique in agent-members.yaml: ${nickname}` };
|
|
20
17
|
}
|
|
21
|
-
const
|
|
18
|
+
const member = resolveRosterAgentMember(roster, nickname);
|
|
19
|
+
if (!member) {
|
|
20
|
+
return { error: `--by agent nickname not found in agent-members.yaml: ${nickname}` };
|
|
21
|
+
}
|
|
22
22
|
if (member.disabled) {
|
|
23
23
|
return { error: `--by agent is disabled in agent-members.yaml: ${nickname}` };
|
|
24
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { loadConfig, loadEnv, specdojoRootDir } from "
|
|
3
|
-
import { selfRunArgs } from "
|
|
2
|
+
import { loadConfig, loadEnv, specdojoRootDir } from "../shared/specdojo-config.js";
|
|
3
|
+
import { selfRunArgs } from "../shared/spawn-self.js";
|
|
4
4
|
const VALID_SCOPES = [
|
|
5
5
|
"exec",
|
|
6
6
|
"catalog",
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createInterface } from "node:readline/promises";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
|
-
import { dump, load } from "
|
|
5
|
-
import { runScaffold } from "
|
|
6
|
-
import { runDevcontainerScaffold } from "
|
|
7
|
-
import { runProviderScaffold } from "
|
|
8
|
-
import { generateDerivedViewFiles } from "
|
|
9
|
-
import { defaultWorktreeBase, projectGitignoreLayout, specdojoRootDir, } from "
|
|
10
|
-
import { ensureGitignore, formatGitignoreReport, gitignorePatternsForLayouts, } from "
|
|
11
|
-
import { specdojoPackageRootDir } from "
|
|
4
|
+
import { dump, load } from "../shared/yaml.js";
|
|
5
|
+
import { runScaffold } from "../catalog/scaffold.js";
|
|
6
|
+
import { runDevcontainerScaffold } from "../devcontainer/scaffold.js";
|
|
7
|
+
import { runProviderScaffold } from "../shared/provider-scaffold.js";
|
|
8
|
+
import { generateDerivedViewFiles } from "../register/register.js";
|
|
9
|
+
import { defaultWorktreeBase, projectGitignoreLayout, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
10
|
+
import { ensureGitignore, formatGitignoreReport, gitignorePatternsForLayouts, } from "../shared/specdojo-gitignore.js";
|
|
11
|
+
import { specdojoPackageRootDir } from "../shared/package-paths.js";
|
|
12
12
|
const PROVIDERS = ["claude", "codex", "opencode", "antigravity", "copilot"];
|
|
13
13
|
const PARENT_VALIDATION_SCRIPTS = {
|
|
14
14
|
"lint-ts": "lint:ts",
|
|
@@ -18,6 +18,8 @@ const PARENT_VALIDATION_SCRIPTS = {
|
|
|
18
18
|
"validate-schema": "validate:schema",
|
|
19
19
|
typecheck: "typecheck",
|
|
20
20
|
"test-unit": "test:unit",
|
|
21
|
+
build: "build",
|
|
22
|
+
"format-check": "format:check",
|
|
21
23
|
};
|
|
22
24
|
const DEFAULTS = {
|
|
23
25
|
projectId: "prj-0001",
|
|
@@ -63,24 +65,73 @@ function parseCatalog(value) {
|
|
|
63
65
|
}
|
|
64
66
|
throw new Error(`Invalid catalog size: ${value}. Must be small, medium, large, or none`);
|
|
65
67
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
function parseDevcontainerPreset(value) {
|
|
69
|
+
const normalized = value?.trim().toLowerCase();
|
|
70
|
+
if (!normalized || normalized === "none" || normalized === "-")
|
|
71
|
+
return undefined;
|
|
72
|
+
if (normalized === "recommended")
|
|
73
|
+
return normalized;
|
|
74
|
+
throw new Error(`Invalid Dev Container preset: ${value}. Must be recommended or none`);
|
|
75
|
+
}
|
|
76
|
+
function validateProjectId(projectId) {
|
|
77
|
+
if (!/^prj-[0-9]{4,}$/.test(projectId)) {
|
|
78
|
+
throw new Error(`Invalid project ID: ${projectId}. Expected prj-0001 style`);
|
|
69
79
|
}
|
|
70
|
-
|
|
80
|
+
return projectId;
|
|
81
|
+
}
|
|
82
|
+
function validateProjectName(projectName) {
|
|
83
|
+
if (!projectName.trim())
|
|
71
84
|
throw new Error("Project name must not be empty");
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
return projectName;
|
|
86
|
+
}
|
|
87
|
+
function validateNickname(nickname) {
|
|
88
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,62}$/.test(nickname)) {
|
|
89
|
+
throw new Error(`Invalid nickname: ${nickname}`);
|
|
74
90
|
}
|
|
75
|
-
|
|
91
|
+
return nickname;
|
|
92
|
+
}
|
|
93
|
+
function validateDisplayName(displayName) {
|
|
94
|
+
if (!displayName.trim())
|
|
76
95
|
throw new Error("Display name must not be empty");
|
|
77
|
-
|
|
96
|
+
return displayName;
|
|
97
|
+
}
|
|
98
|
+
function validateExecProviders(providers, exec) {
|
|
99
|
+
if (exec && providers.length === 0) {
|
|
78
100
|
throw new Error("--exec requires at least one --provider");
|
|
79
101
|
}
|
|
102
|
+
return providers;
|
|
103
|
+
}
|
|
104
|
+
function validateAnswers(answers) {
|
|
105
|
+
validateProjectId(answers.projectId);
|
|
106
|
+
validateProjectName(answers.projectName);
|
|
107
|
+
validateNickname(answers.nickname);
|
|
108
|
+
validateDisplayName(answers.displayName);
|
|
109
|
+
validateExecProviders(answers.providers, answers.exec);
|
|
110
|
+
if (answers.devcontainerPreset && !answers.devcontainer) {
|
|
111
|
+
throw new Error("--devcontainer-preset requires --devcontainer");
|
|
112
|
+
}
|
|
80
113
|
return answers;
|
|
81
114
|
}
|
|
115
|
+
async function promptUntilValid(prompter, prompt, parse) {
|
|
116
|
+
while (true) {
|
|
117
|
+
const answer = await prompter.question(prompt);
|
|
118
|
+
try {
|
|
119
|
+
return parse(answer);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
82
126
|
export async function collectInitAnswers(options, prompter) {
|
|
83
127
|
if (!prompter) {
|
|
128
|
+
const devcontainer = !!options.devcontainer;
|
|
129
|
+
const explicitPreset = parseDevcontainerPreset(options.devcontainerPreset);
|
|
130
|
+
const devcontainerPreset = devcontainer
|
|
131
|
+
? options.devcontainerPreset === undefined
|
|
132
|
+
? "recommended"
|
|
133
|
+
: explicitPreset
|
|
134
|
+
: explicitPreset;
|
|
84
135
|
const answers = validateAnswers({
|
|
85
136
|
projectId: options.project?.trim() || DEFAULTS.projectId,
|
|
86
137
|
projectName: options.name?.trim() || DEFAULTS.projectName,
|
|
@@ -90,7 +141,8 @@ export async function collectInitAnswers(options, prompter) {
|
|
|
90
141
|
providers: parseProviders(options.provider),
|
|
91
142
|
exec: !!options.exec,
|
|
92
143
|
catalog: parseCatalog(options.catalog),
|
|
93
|
-
devcontainer
|
|
144
|
+
devcontainer,
|
|
145
|
+
...(devcontainerPreset ? { devcontainerPreset } : {}),
|
|
94
146
|
});
|
|
95
147
|
for (const [label, used] of [
|
|
96
148
|
["project", !options.project],
|
|
@@ -102,6 +154,7 @@ export async function collectInitAnswers(options, prompter) {
|
|
|
102
154
|
["exec=no", !options.exec],
|
|
103
155
|
["catalog=none", !options.catalog],
|
|
104
156
|
["devcontainer=no", !options.devcontainer],
|
|
157
|
+
["devcontainer-preset=recommended", devcontainer && options.devcontainerPreset === undefined],
|
|
105
158
|
]) {
|
|
106
159
|
if (used)
|
|
107
160
|
process.stdout.write(`Using default: ${label}\n`);
|
|
@@ -116,18 +169,25 @@ export async function collectInitAnswers(options, prompter) {
|
|
|
116
169
|
const displayNameDefault = options.displayName?.trim() || DEFAULTS.displayName;
|
|
117
170
|
const providerDefault = options.provider?.trim() || DEFAULTS.providers.join(",");
|
|
118
171
|
const execDefault = !!options.exec;
|
|
119
|
-
const catalogDefault = options.catalog?.trim() || "none";
|
|
120
172
|
const devcontainerDefault = !!options.devcontainer;
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
173
|
+
const explicitDevcontainerPreset = parseDevcontainerPreset(options.devcontainerPreset);
|
|
174
|
+
const providerPrompt = `Orchestrator providers (${PROVIDERS.join(", ")}) [${providerDefault}]: `;
|
|
175
|
+
const projectId = await promptUntilValid(prompter, `Project ID [${projectDefault}]: `, (answer) => validateProjectId(answer.trim() || projectDefault));
|
|
176
|
+
const projectName = await promptUntilValid(prompter, `Project name [${nameDefault}]: `, (answer) => validateProjectName(answer.trim() || nameDefault));
|
|
177
|
+
const register = await promptUntilValid(prompter, `Create a project register? [${registerDefault ? "Y/n" : "y/N"}]: `, (answer) => parseBoolean(answer, registerDefault));
|
|
178
|
+
const nickname = await promptUntilValid(prompter, `Your nickname [${nicknameDefault}]: `, (answer) => validateNickname(answer.trim() || nicknameDefault));
|
|
179
|
+
const displayName = await promptUntilValid(prompter, `Your display name [${displayNameDefault}]: `, (answer) => validateDisplayName(answer.trim() || displayNameDefault));
|
|
180
|
+
let providers = await promptUntilValid(prompter, providerPrompt, (answer) => parseProviders(answer.trim() || providerDefault));
|
|
181
|
+
const exec = await promptUntilValid(prompter, `Delegate work to agents (exec)? [${execDefault ? "Y/n" : "y/N"}]: `, (answer) => parseBoolean(answer, execDefault));
|
|
182
|
+
if (exec && providers.length === 0) {
|
|
183
|
+
process.stderr.write("--exec requires at least one --provider\n");
|
|
184
|
+
providers = await promptUntilValid(prompter, providerPrompt, (answer) => validateExecProviders(parseProviders(answer.trim() || providerDefault), true));
|
|
185
|
+
}
|
|
186
|
+
const catalog = parseCatalog(options.catalog);
|
|
187
|
+
const devcontainer = await promptUntilValid(prompter, `Create a Dev Container? [${devcontainerDefault ? "Y/n" : "y/N"}]: `, (answer) => parseBoolean(answer, devcontainerDefault));
|
|
188
|
+
const devcontainerPreset = devcontainer && options.devcontainerPreset === undefined
|
|
189
|
+
? await promptUntilValid(prompter, "Add the recommended Dev Container settings? [Y/n]: ", (answer) => (parseBoolean(answer, true) ? "recommended" : undefined))
|
|
190
|
+
: explicitDevcontainerPreset;
|
|
131
191
|
return validateAnswers({
|
|
132
192
|
projectId,
|
|
133
193
|
projectName,
|
|
@@ -138,6 +198,7 @@ export async function collectInitAnswers(options, prompter) {
|
|
|
138
198
|
exec,
|
|
139
199
|
catalog,
|
|
140
200
|
devcontainer,
|
|
201
|
+
...(devcontainerPreset ? { devcontainerPreset } : {}),
|
|
141
202
|
});
|
|
142
203
|
}
|
|
143
204
|
finally {
|
|
@@ -242,11 +303,62 @@ function selectParentValidations(repoRoot, configured) {
|
|
|
242
303
|
}
|
|
243
304
|
return selected;
|
|
244
305
|
}
|
|
306
|
+
// 別名は向き先の実体が選ばれた provider に含まれる場合だけ残す。別名どうしの連鎖も辿る。
|
|
307
|
+
function selectAliases(aliases, memberNicknames) {
|
|
308
|
+
const targets = new Map(aliases.map((alias) => [alias.nickname, alias.alias_of]));
|
|
309
|
+
const resolvesToSelected = (nickname) => {
|
|
310
|
+
const seen = new Set();
|
|
311
|
+
let current = nickname;
|
|
312
|
+
while (!seen.has(current)) {
|
|
313
|
+
seen.add(current);
|
|
314
|
+
const target = targets.get(current);
|
|
315
|
+
if (!target)
|
|
316
|
+
return false;
|
|
317
|
+
if (memberNicknames.has(target))
|
|
318
|
+
return true;
|
|
319
|
+
current = target;
|
|
320
|
+
}
|
|
321
|
+
return false;
|
|
322
|
+
};
|
|
323
|
+
return aliases.filter((alias) => resolvesToSelected(alias.nickname));
|
|
324
|
+
}
|
|
325
|
+
// 次の手順の案内には、利用者が見慣れた別名を優先して示す(実体の名前でも同じ member が動く)。
|
|
326
|
+
function preferredAgentName(member, aliases) {
|
|
327
|
+
return aliases.find((alias) => alias.alias_of === member.nickname)?.nickname ?? member.nickname;
|
|
328
|
+
}
|
|
245
329
|
function writeExecConfiguration(repoRoot, packageRoot, providers, dryRun) {
|
|
246
330
|
const memberTemplate = loadInitTemplate(packageRoot, "init-agent-members.yaml");
|
|
247
331
|
const defaultsTemplate = loadInitTemplate(packageRoot, "init-exec-defaults.yaml");
|
|
248
332
|
const selected = new Set(providers);
|
|
249
333
|
const members = memberTemplate.members.filter((member) => member.provider && selected.has(member.provider));
|
|
334
|
+
const aliases = selectAliases(memberTemplate.aliases ?? [], new Set(members.map((member) => member.nickname)));
|
|
335
|
+
const pairs = providers.map((provider) => {
|
|
336
|
+
const executor = members.find((member) => member.provider === provider && member.stage_role === "executor" && member.mode === "edit");
|
|
337
|
+
const reporter = members.find((member) => member.provider === provider && member.stage_role === "reporter");
|
|
338
|
+
if (!executor || !reporter) {
|
|
339
|
+
throw new Error(`init-agent-members.yaml must define an edit executor and reporter for ${provider}`);
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
executor: preferredAgentName(executor, aliases),
|
|
343
|
+
reporter: preferredAgentName(reporter, aliases),
|
|
344
|
+
};
|
|
345
|
+
});
|
|
346
|
+
const route = (pairIndex, action) => {
|
|
347
|
+
const resolvedIndex = Math.min(pairIndex, pairs.length - 1);
|
|
348
|
+
const pair = pairs[resolvedIndex];
|
|
349
|
+
const fallback = pairs.length > 1 ? pairs[(resolvedIndex + 1) % pairs.length] : undefined;
|
|
350
|
+
return {
|
|
351
|
+
executor_by: pair.executor,
|
|
352
|
+
reporter_by: pair.reporter,
|
|
353
|
+
on_rate_limit: action === "fallback" && !fallback ? "stop" : action,
|
|
354
|
+
...(fallback
|
|
355
|
+
? {
|
|
356
|
+
fallback_executor_by: fallback.executor,
|
|
357
|
+
fallback_reporter_by: fallback.reporter,
|
|
358
|
+
}
|
|
359
|
+
: {}),
|
|
360
|
+
};
|
|
361
|
+
};
|
|
250
362
|
const providerDefaults = Object.fromEntries(Object.entries(defaultsTemplate.providers).filter(([provider]) => selected.has(provider)));
|
|
251
363
|
const { providers: _providers, ...commonDefaults } = defaultsTemplate;
|
|
252
364
|
const commonPipeline = commonDefaults.pipeline && typeof commonDefaults.pipeline === "object"
|
|
@@ -254,7 +366,14 @@ function writeExecConfiguration(repoRoot, packageRoot, providers, dryRun) {
|
|
|
254
366
|
: {};
|
|
255
367
|
const { parent_validations: configuredParentValidations, ...otherPipeline } = commonPipeline;
|
|
256
368
|
const parentValidations = selectParentValidations(repoRoot, configuredParentValidations);
|
|
257
|
-
const configuredDefaults = {
|
|
369
|
+
const configuredDefaults = {
|
|
370
|
+
...commonDefaults,
|
|
371
|
+
routing: {
|
|
372
|
+
hard: route(0, "wait"),
|
|
373
|
+
medium: route(1, "fallback"),
|
|
374
|
+
easy: route(2, "fallback"),
|
|
375
|
+
},
|
|
376
|
+
};
|
|
258
377
|
if (parentValidations.length > 0 || Object.keys(otherPipeline).length > 0) {
|
|
259
378
|
configuredDefaults.pipeline = {
|
|
260
379
|
...otherPipeline,
|
|
@@ -264,17 +383,12 @@ function writeExecConfiguration(repoRoot, packageRoot, providers, dryRun) {
|
|
|
264
383
|
else {
|
|
265
384
|
delete configuredDefaults.pipeline;
|
|
266
385
|
}
|
|
267
|
-
writeNewFile(repoRoot, ".specdojo/agent-members.yaml", dump({ version: 1, members }, { lineWidth: 120, noRefs: true }), dryRun);
|
|
386
|
+
writeNewFile(repoRoot, ".specdojo/agent-members.yaml", dump({ version: 1, members, ...(aliases.length > 0 ? { aliases } : {}) }, { lineWidth: 120, noRefs: true }), dryRun);
|
|
268
387
|
writeNewFile(repoRoot, ".specdojo/exec-defaults.yaml", dump({ ...configuredDefaults, providers: providerDefaults }, { lineWidth: 120, noRefs: true }), dryRun);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const reporter = members.find((member) => member.provider === primaryProvider && member.stage_role === "reporter");
|
|
274
|
-
if (!executor || !reporter) {
|
|
275
|
-
throw new Error("init-agent-members.yaml must define an edit executor and reporter");
|
|
276
|
-
}
|
|
277
|
-
return { executor: executor.nickname, reporter: reporter.nickname };
|
|
388
|
+
return {
|
|
389
|
+
executor: pairs[0].executor,
|
|
390
|
+
reporter: pairs[0].reporter,
|
|
391
|
+
};
|
|
278
392
|
}
|
|
279
393
|
function scaffoldRegister(repoRoot, config, answers, dryRun) {
|
|
280
394
|
if (!answers.register)
|
|
@@ -392,21 +506,25 @@ export async function runInit(options, deps) {
|
|
|
392
506
|
await runDevcontainerScaffold({
|
|
393
507
|
packageRoot,
|
|
394
508
|
repoRoot,
|
|
509
|
+
workspaceName: options.workspaceName,
|
|
510
|
+
preset: answers.devcontainerPreset,
|
|
395
511
|
providers: answers.providers,
|
|
396
512
|
editors: [],
|
|
397
513
|
ollama: answers.providers.includes("opencode"),
|
|
398
514
|
cron: false,
|
|
399
|
-
tmux:
|
|
515
|
+
tmux: true,
|
|
400
516
|
force: false,
|
|
401
517
|
dryRun,
|
|
402
518
|
});
|
|
403
519
|
}
|
|
404
520
|
const firstProvider = answers.providers[0];
|
|
405
521
|
const script = firstProvider === "claude"
|
|
406
|
-
? "orch:
|
|
407
|
-
: firstProvider === "
|
|
408
|
-
? "orch:
|
|
409
|
-
:
|
|
522
|
+
? "orch:opus"
|
|
523
|
+
: firstProvider === "codex"
|
|
524
|
+
? "orch:sol"
|
|
525
|
+
: firstProvider === "antigravity"
|
|
526
|
+
? "orch:flash"
|
|
527
|
+
: `orch:${firstProvider}`;
|
|
410
528
|
process.stdout.write("Next steps:\n" +
|
|
411
529
|
(firstProvider
|
|
412
530
|
? ` 1. Run npm run ${script} and create the first register item.\n`
|
|
@@ -414,7 +532,10 @@ export async function runInit(options, deps) {
|
|
|
414
532
|
(execAgents
|
|
415
533
|
? ` 2. To run an item without the orchestrator: npx specdojo exec run --register <id> --executor-by ${execAgents.executor} --reporter-by ${execAgents.reporter}\n`
|
|
416
534
|
: "") +
|
|
417
|
-
` ${execAgents ? "3" : "2"}. Review and commit the files created by specdojo init.\n`
|
|
535
|
+
` ${execAgents ? "3" : "2"}. Review and commit the files created by specdojo init.\n` +
|
|
536
|
+
(answers.catalog
|
|
537
|
+
? ""
|
|
538
|
+
: "When deliverables are ready, configure catalog_path in .specdojo/specdojo.config.json and run npx specdojo catalog scaffold (see docs/ja/specdojo/guides/quick-start-guide.md).\n"));
|
|
418
539
|
}
|
|
419
540
|
export function registerInitCommand(program) {
|
|
420
541
|
program
|
|
@@ -430,6 +551,8 @@ export function registerInitCommand(program) {
|
|
|
430
551
|
.option("--exec", "Configure executor and reporter agents", false)
|
|
431
552
|
.option("--catalog <size>", "Create a deliverables catalog (small|medium|large)")
|
|
432
553
|
.option("--devcontainer", "Create a Dev Container for the selected providers", false)
|
|
554
|
+
.option("--devcontainer-preset <name>", "Apply a Dev Container preset when creating it (recommended|none)")
|
|
555
|
+
.option("--workspace-name <name>", "Override the Dev Container workspace parent name used under /workspaces")
|
|
433
556
|
.option("--dry-run", "Show planned files and changes without writing", false)
|
|
434
557
|
.action(async (options) => {
|
|
435
558
|
try {
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
import { resolveProjectPaths } from "../exec/project.js";
|
|
5
|
+
import { loadRegisterItems, resolveRegisterPaths } from "../register/register.js";
|
|
6
|
+
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
7
|
+
export function selectApprovedNightItems(items, limit) {
|
|
8
|
+
return items
|
|
9
|
+
.filter((item) => item.autopilot === "approved" &&
|
|
10
|
+
(item.type === "todo" || item.type === "issue") &&
|
|
11
|
+
item.status === "open")
|
|
12
|
+
.sort((a, b) => (a.id === b.id ? 0 : a.id < b.id ? -1 : 1))
|
|
13
|
+
.slice(0, limit);
|
|
14
|
+
}
|
|
15
|
+
export function parseRegisterRunSummary(output) {
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const line of output.split(/\r?\n/u)) {
|
|
18
|
+
const match = line.match(/^\s+(PJR-[0-9A-Z]{4})\s+(success|failure|skipped)\s+transition=(done|waiting|review|none)\s+commit=.*?(?:\s{2}reason=(.*))?$/u);
|
|
19
|
+
if (!match)
|
|
20
|
+
continue;
|
|
21
|
+
results.push({
|
|
22
|
+
id: match[1],
|
|
23
|
+
outcome: match[2],
|
|
24
|
+
transition: match[3],
|
|
25
|
+
...(match[4]?.trim() ? { reason: match[4].trim() } : {}),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
30
|
+
export function consecutiveFailureCount(previous, outcomes) {
|
|
31
|
+
let count = previous;
|
|
32
|
+
for (const outcome of outcomes) {
|
|
33
|
+
if (outcome.outcome === "failure")
|
|
34
|
+
count += 1;
|
|
35
|
+
else if (outcome.outcome === "success")
|
|
36
|
+
count = 0;
|
|
37
|
+
}
|
|
38
|
+
return count;
|
|
39
|
+
}
|
|
40
|
+
export function requiresDerivedApproval(outcome) {
|
|
41
|
+
if (outcome.outcome !== "failure")
|
|
42
|
+
return false;
|
|
43
|
+
return /protected|agent-config-write|git-state|\b(?:tag|push|publish)\b|CHANGELOG|scope|範囲|承認/iu.test(outcome.reason ?? "");
|
|
44
|
+
}
|
|
45
|
+
function positiveInteger(value, option) {
|
|
46
|
+
if (!/^[1-9]\d*$/u.test(value))
|
|
47
|
+
throw new Error(`${option} must be a positive integer: ${value}`);
|
|
48
|
+
const parsed = Number(value);
|
|
49
|
+
if (!Number.isSafeInteger(parsed))
|
|
50
|
+
throw new Error(`${option} is too large: ${value}`);
|
|
51
|
+
return parsed;
|
|
52
|
+
}
|
|
53
|
+
function safeCell(value) {
|
|
54
|
+
return (value?.trim() || "-").replaceAll("|", "\\|").replace(/\r?\n/gu, " ");
|
|
55
|
+
}
|
|
56
|
+
export function renderNightReport(options) {
|
|
57
|
+
const stamp = options.startedAt
|
|
58
|
+
.replace(/[-:.]/gu, "")
|
|
59
|
+
.replace(/\.\d+Z$/u, "Z")
|
|
60
|
+
.toLowerCase();
|
|
61
|
+
const byId = new Map(options.outcomes.map((outcome) => [outcome.id, outcome]));
|
|
62
|
+
const rows = options.selected.map((item) => {
|
|
63
|
+
const outcome = byId.get(item.id);
|
|
64
|
+
return `| ${item.id} | ${outcome?.outcome ?? "skipped"} | ${outcome?.transition ?? "none"} | ${safeCell(outcome?.reason)} |`;
|
|
65
|
+
});
|
|
66
|
+
const closed = options.outcomes
|
|
67
|
+
.filter((item) => item.transition === "done")
|
|
68
|
+
.map((item) => item.id);
|
|
69
|
+
const waiting = options.outcomes
|
|
70
|
+
.filter((item) => item.transition === "waiting")
|
|
71
|
+
.map((item) => item.id);
|
|
72
|
+
const approvals = [...options.approvalIssues].map(([source, created]) => `${created}(${source} 由来)`);
|
|
73
|
+
const list = (values) => (values.length > 0 ? values.join("、") : "なし");
|
|
74
|
+
return `---
|
|
75
|
+
specdojo:
|
|
76
|
+
id: ${options.projectId}:night-orchestrator-report-${stamp}
|
|
77
|
+
type: report
|
|
78
|
+
status: draft
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
# 夜間 orchestrator 朝報告 ${options.startedAt.slice(0, 10)}
|
|
82
|
+
|
|
83
|
+
- 開始: \`${options.startedAt}\`
|
|
84
|
+
- 完了: \`${options.completedAt}\`
|
|
85
|
+
- 停止理由: ${safeCell(options.stopReason)}
|
|
86
|
+
|
|
87
|
+
## 集計
|
|
88
|
+
|
|
89
|
+
- close: ${list(closed)}
|
|
90
|
+
- \`waiting\`: ${list(waiting)}
|
|
91
|
+
- 新しい承認待ち: ${list(approvals)}
|
|
92
|
+
|
|
93
|
+
## 実行結果
|
|
94
|
+
|
|
95
|
+
| 項目 | 結果 | 遷移 | 理由 |
|
|
96
|
+
| ---- | ---- | ---- | ---- |
|
|
97
|
+
${rows.join("\n") || "| - | skipped | none | 承認済みの open todo/issue なし |"}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
const MAX_CAPTURED_OUTPUT = 2 * 1024 * 1024;
|
|
101
|
+
function appendOutputTail(current, chunk) {
|
|
102
|
+
const combined = current + chunk;
|
|
103
|
+
return combined.length <= MAX_CAPTURED_OUTPUT
|
|
104
|
+
? combined
|
|
105
|
+
: combined.slice(combined.length - MAX_CAPTURED_OUTPUT);
|
|
106
|
+
}
|
|
107
|
+
async function runCaptured(command, args) {
|
|
108
|
+
return await new Promise((resolveRun, reject) => {
|
|
109
|
+
const child = spawn(command, args, {
|
|
110
|
+
cwd: specdojoRootDir(),
|
|
111
|
+
env: process.env,
|
|
112
|
+
stdio: "pipe",
|
|
113
|
+
});
|
|
114
|
+
let stdout = "";
|
|
115
|
+
let stderr = "";
|
|
116
|
+
child.stdout.on("data", (chunk) => {
|
|
117
|
+
const text = chunk.toString();
|
|
118
|
+
stdout = appendOutputTail(stdout, text);
|
|
119
|
+
process.stdout.write(text);
|
|
120
|
+
});
|
|
121
|
+
child.stderr.on("data", (chunk) => {
|
|
122
|
+
const text = chunk.toString();
|
|
123
|
+
stderr = appendOutputTail(stderr, text);
|
|
124
|
+
process.stderr.write(text);
|
|
125
|
+
});
|
|
126
|
+
child.once("error", reject);
|
|
127
|
+
child.once("close", (code) => resolveRun({ code: code ?? 1, stdout, stderr }));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function cliInvocation(args) {
|
|
131
|
+
const entry = process.argv[1];
|
|
132
|
+
if (!entry)
|
|
133
|
+
throw new Error("Cannot resolve the current specdojo CLI entry point.");
|
|
134
|
+
return [process.execPath, [entry, ...args]];
|
|
135
|
+
}
|
|
136
|
+
async function addDerivedApprovalIssue(projectId, item, reason) {
|
|
137
|
+
const [command, args] = cliInvocation([
|
|
138
|
+
"register",
|
|
139
|
+
"add",
|
|
140
|
+
"--project",
|
|
141
|
+
projectId,
|
|
142
|
+
"--type",
|
|
143
|
+
"issue",
|
|
144
|
+
"--title",
|
|
145
|
+
`${item.id} 夜間実行で見つかった承認待ち`,
|
|
146
|
+
"--description",
|
|
147
|
+
`夜間 orchestrator は承認範囲外の対応が必要と判断した。元項目は ${item.id}。理由: ${reason}`,
|
|
148
|
+
"--priority",
|
|
149
|
+
item.priority,
|
|
150
|
+
"--owner",
|
|
151
|
+
item.owner,
|
|
152
|
+
"--from",
|
|
153
|
+
item.id,
|
|
154
|
+
"--topic",
|
|
155
|
+
`night-approval-${item.id.toLowerCase()}`,
|
|
156
|
+
"--by",
|
|
157
|
+
"night-orchestrator",
|
|
158
|
+
"--reason",
|
|
159
|
+
"approved night run requires human authorization",
|
|
160
|
+
]);
|
|
161
|
+
const result = await runCaptured(command, args);
|
|
162
|
+
if (result.code !== 0)
|
|
163
|
+
throw new Error(`Failed to create derived approval for ${item.id}.`);
|
|
164
|
+
const created = result.stdout.match(/\(added (PJR-[0-9A-Z]{4})\)/u)?.[1];
|
|
165
|
+
if (!created)
|
|
166
|
+
throw new Error(`Could not read the derived approval ID for ${item.id}.`);
|
|
167
|
+
return created;
|
|
168
|
+
}
|
|
169
|
+
export function registerNightOrchestratorCommand(orchestrator) {
|
|
170
|
+
orchestrator
|
|
171
|
+
.command("night")
|
|
172
|
+
.description("Run only human-approved register todo/issue items and write a morning report")
|
|
173
|
+
.option("--project <projectId>", "Project id in specdojo.config.json")
|
|
174
|
+
.option("--max-items <n>", "Maximum items in one night", "10")
|
|
175
|
+
.option("--parallel <n>", "Maximum parallel item runs", "2")
|
|
176
|
+
.option("--max-consecutive-failures <n>", "Stop after this many consecutive failures", "2")
|
|
177
|
+
.option("--on-rate-limit <action>", "Override the difficulty route's pinned-agent action: stop|wait|fallback")
|
|
178
|
+
.option("--fallback-executor-by <nickname>", "Fallback executor for rate limits or configured connection errors")
|
|
179
|
+
.option("--scheduled-at <dateTime>", "Scheduled occurrence time used in the report")
|
|
180
|
+
.option("--dry-run", "Print the approved queue without executing", false)
|
|
181
|
+
.action(async (opts) => {
|
|
182
|
+
try {
|
|
183
|
+
const maxItems = positiveInteger(opts.maxItems, "--max-items");
|
|
184
|
+
const parallel = positiveInteger(opts.parallel, "--parallel");
|
|
185
|
+
const maxFailures = positiveInteger(opts.maxConsecutiveFailures, "--max-consecutive-failures");
|
|
186
|
+
if (opts.onRateLimit !== undefined &&
|
|
187
|
+
!["stop", "wait", "fallback"].includes(opts.onRateLimit)) {
|
|
188
|
+
throw new Error('--on-rate-limit must be "stop", "wait", or "fallback".');
|
|
189
|
+
}
|
|
190
|
+
const resolved = resolveProjectPaths({ project: opts.project });
|
|
191
|
+
const projectId = resolved.projectId ?? opts.project;
|
|
192
|
+
if (!projectId)
|
|
193
|
+
throw new Error("orchestrator night requires --project <id>.");
|
|
194
|
+
const items = loadRegisterItems(resolveRegisterPaths({ project: projectId })).map((view) => view.item);
|
|
195
|
+
const selected = selectApprovedNightItems(items, maxItems);
|
|
196
|
+
process.stdout.write(`[night] approved queue (${selected.length}/${maxItems}): ${selected.map((item) => item.id).join(", ") || "none"}\n`);
|
|
197
|
+
if (opts.dryRun)
|
|
198
|
+
return;
|
|
199
|
+
const startedAt = opts.scheduledAt
|
|
200
|
+
? new Date(opts.scheduledAt).toISOString()
|
|
201
|
+
: new Date().toISOString();
|
|
202
|
+
const outcomes = [];
|
|
203
|
+
const approvalIssues = new Map();
|
|
204
|
+
let consecutiveFailures = 0;
|
|
205
|
+
let stopReason;
|
|
206
|
+
for (let offset = 0; offset < selected.length; offset += parallel) {
|
|
207
|
+
const wave = selected.slice(offset, offset + parallel);
|
|
208
|
+
const [command, args] = cliInvocation([
|
|
209
|
+
"exec",
|
|
210
|
+
"run",
|
|
211
|
+
"--project",
|
|
212
|
+
projectId,
|
|
213
|
+
"--register",
|
|
214
|
+
...wave.map((item) => item.id),
|
|
215
|
+
"--worktree",
|
|
216
|
+
"--post-review",
|
|
217
|
+
"--parallel",
|
|
218
|
+
String(parallel),
|
|
219
|
+
"--on-failure",
|
|
220
|
+
"continue",
|
|
221
|
+
...(opts.onRateLimit ? ["--on-rate-limit", opts.onRateLimit] : []),
|
|
222
|
+
...(opts.fallbackExecutorBy ? ["--fallback-executor-by", opts.fallbackExecutorBy] : []),
|
|
223
|
+
]);
|
|
224
|
+
const result = await runCaptured(command, args);
|
|
225
|
+
const parsed = parseRegisterRunSummary(result.stdout);
|
|
226
|
+
const parsedById = new Map(parsed.map((outcome) => [outcome.id, outcome]));
|
|
227
|
+
const waveOutcomes = wave.map((item) => parsedById.get(item.id) ?? {
|
|
228
|
+
id: item.id,
|
|
229
|
+
outcome: "failure",
|
|
230
|
+
transition: "waiting",
|
|
231
|
+
reason: `exec run ended with code ${result.code} without an item summary`,
|
|
232
|
+
});
|
|
233
|
+
outcomes.push(...waveOutcomes);
|
|
234
|
+
for (const outcome of waveOutcomes) {
|
|
235
|
+
if (!requiresDerivedApproval(outcome))
|
|
236
|
+
continue;
|
|
237
|
+
const source = wave.find((item) => item.id === outcome.id);
|
|
238
|
+
if (source) {
|
|
239
|
+
const existing = items.find((item) => item.type === "issue" &&
|
|
240
|
+
!["done", "decided", "rejected", "deferred"].includes(item.status) &&
|
|
241
|
+
item.derivedFrom?.includes(source.id) &&
|
|
242
|
+
item.title.startsWith(`${source.id} 夜間実行で見つかった承認待ち`));
|
|
243
|
+
approvalIssues.set(source.id, existing?.id ??
|
|
244
|
+
(await addDerivedApprovalIssue(projectId, source, outcome.reason ?? "approval required")));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
consecutiveFailures = consecutiveFailureCount(consecutiveFailures, waveOutcomes);
|
|
248
|
+
if (consecutiveFailures >= maxFailures) {
|
|
249
|
+
stopReason = `連続失敗が上限 ${maxFailures} 件に達した`;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const processed = new Set(outcomes.map((outcome) => outcome.id));
|
|
254
|
+
for (const item of selected) {
|
|
255
|
+
if (!processed.has(item.id)) {
|
|
256
|
+
outcomes.push({
|
|
257
|
+
id: item.id,
|
|
258
|
+
outcome: "skipped",
|
|
259
|
+
transition: "none",
|
|
260
|
+
reason: stopReason ?? "not started",
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const completedAt = new Date().toISOString();
|
|
265
|
+
const reportsPath = join(resolved.executionPath, "reports", "night-orchestrator");
|
|
266
|
+
mkdirSync(reportsPath, { recursive: true });
|
|
267
|
+
const reportName = `night-orchestrator-${startedAt.replace(/[-:.]/gu, "").replace(/\.\d+Z$/u, "Z")}.md`;
|
|
268
|
+
const reportPath = join(reportsPath, reportName);
|
|
269
|
+
writeFileSync(reportPath, renderNightReport({
|
|
270
|
+
projectId,
|
|
271
|
+
startedAt,
|
|
272
|
+
completedAt,
|
|
273
|
+
selected,
|
|
274
|
+
outcomes,
|
|
275
|
+
approvalIssues,
|
|
276
|
+
...(stopReason ? { stopReason } : {}),
|
|
277
|
+
}), "utf8");
|
|
278
|
+
process.stdout.write(`[night] morning report: ${relative(specdojoRootDir(), reportPath)}\n`);
|
|
279
|
+
if (outcomes.some((outcome) => outcome.outcome === "failure"))
|
|
280
|
+
process.exitCode = 2;
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
284
|
+
process.exitCode = 1;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|