specdojo 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/agents/specdojo-orchestrator.md +165 -0
- package/CHANGELOG.md +298 -0
- package/README.md +92 -42
- package/dist/agent-response.js +20 -0
- package/dist/agent.js +4 -4
- package/dist/build-command.js +28 -8
- package/dist/catalog-build-references.js +144 -0
- package/dist/catalog-build-render.js +144 -0
- package/dist/catalog-build.js +13 -290
- package/dist/catalog-generate.js +6 -9
- package/dist/catalog-plan-generate.js +2 -2
- package/dist/catalog-plan.js +6 -6
- package/dist/catalog-scaffold.js +4 -4
- package/dist/catalog.js +2 -2
- package/dist/dashboard-exec-records.js +105 -0
- package/dist/dashboard-routines.js +255 -0
- package/dist/dashboard-shared.js +14 -0
- package/dist/dashboard-timeline.js +175 -0
- package/dist/dashboard.js +31 -444
- package/dist/deliverable-trash.js +3 -3
- package/dist/devcontainer-command.js +43 -0
- package/dist/devcontainer-scaffold.js +165 -0
- package/dist/doc-index.js +3 -3
- package/dist/exec-agent-config.js +107 -9
- package/dist/exec-agent-git-state.js +18 -0
- package/dist/exec-agent-protected-config.js +46 -8
- package/dist/exec-commands.js +557 -0
- package/dist/exec-core.js +457 -0
- package/dist/exec-evidence.js +254 -11
- package/dist/exec-handoff.js +336 -0
- package/dist/exec-parent-validation.js +317 -43
- package/dist/exec-pipeline-state.js +74 -9
- package/dist/exec-plans-core.js +693 -0
- package/dist/exec-plans-generation.js +206 -0
- package/dist/exec-plans-storage.js +131 -0
- package/dist/exec-plans.js +3 -1016
- package/dist/exec-protection-handoff.js +43 -2
- package/dist/exec-provider-scaffold.js +247 -15
- package/dist/exec-register-resume.js +65 -19
- package/dist/exec-register.js +9 -3
- package/dist/exec-repo-integration-git.js +23 -0
- package/dist/exec-repo-integration-sync.js +264 -0
- package/dist/exec-repo-integration.js +534 -0
- package/dist/exec-repo-trace.js +182 -0
- package/dist/exec-reporter-output.js +206 -0
- package/dist/exec-reporter.js +525 -248
- package/dist/exec-results.js +103 -71
- package/dist/exec-run-agent-pipeline.js +256 -0
- package/dist/exec-run-agent.js +531 -0
- package/dist/exec-run-in-place.js +541 -0
- package/dist/exec-run-job.js +717 -0
- package/dist/exec-run-lifecycle-commands.js +522 -0
- package/dist/exec-run-lock.js +110 -107
- package/dist/exec-run-mode-shared.js +140 -0
- package/dist/exec-run-register-command.js +244 -0
- package/dist/exec-run-register-core.js +386 -0
- package/dist/exec-run-register-mode.js +206 -0
- package/dist/exec-run-register-resume.js +393 -0
- package/dist/exec-run-register-state.js +322 -0
- package/dist/exec-run-register-worktree.js +509 -0
- package/dist/exec-run-schedule-mode.js +294 -0
- package/dist/exec-run-schedule-prepare.js +353 -0
- package/dist/exec-run-schedule-task.js +572 -0
- package/dist/exec-run-shared.js +399 -0
- package/dist/exec-run.js +11 -4953
- package/dist/exec-shared.js +9 -2
- package/dist/exec-slot-lock.js +242 -0
- package/dist/exec-task-repos.js +415 -0
- package/dist/exec-trial-commands.js +558 -0
- package/dist/exec-trial-core.js +371 -0
- package/dist/exec-trial.js +2 -895
- package/dist/exec-worktree-command.js +87 -43
- package/dist/exec-worktree-ops-commit.js +707 -0
- package/dist/exec-worktree-ops-lifecycle.js +292 -0
- package/dist/exec-worktree-ops-merge.js +303 -0
- package/dist/exec-worktree-ops.js +3 -847
- package/dist/exec-worktree.js +146 -31
- package/dist/exec.js +2 -999
- package/dist/frontmatter-namespace.js +2 -2
- package/dist/grade-apply.js +734 -0
- package/dist/grade-command-apply.js +250 -0
- package/dist/grade-command-inspect.js +138 -0
- package/dist/grade-command-plan.js +101 -0
- package/dist/grade-command-shared.js +68 -0
- package/dist/grade-core.js +307 -0
- package/dist/grade-markdown.js +274 -0
- package/dist/grade-pipeline-state.js +184 -0
- package/dist/grade-plan.js +507 -0
- package/dist/grade-result.js +133 -5
- package/dist/grade-target-discovery.js +265 -0
- package/dist/grade-targets.js +432 -0
- package/dist/grade.js +14 -2451
- package/dist/init-command.js +443 -0
- package/dist/job-definition.js +670 -0
- package/dist/job.js +64 -578
- package/dist/kata-command.js +2 -2
- package/dist/orchestrator.js +213 -0
- package/dist/register-command-types.js +1 -0
- package/dist/register-core.js +363 -0
- package/dist/register-create-commands.js +245 -0
- package/dist/register-event-merge.js +169 -0
- package/dist/register-events.js +4 -4
- package/dist/register-item.js +13 -7
- package/dist/register-maintenance-commands.js +187 -0
- package/dist/register-migration.js +268 -0
- package/dist/register-renumber.js +314 -0
- package/dist/register-transition-commands.js +248 -0
- package/dist/register-update.js +230 -0
- package/dist/register-views.js +256 -0
- package/dist/register.js +175 -1975
- package/dist/review-grade.js +252 -0
- package/dist/review-plan.js +114 -4
- package/dist/review-types.js +40 -1
- package/dist/routine-definition.js +401 -0
- package/dist/routine.js +73 -402
- package/dist/schedule-approach.js +2 -2
- package/dist/schedule-build.js +2 -2
- package/dist/schedule-strategy-generate-document.js +273 -0
- package/dist/schedule-strategy-generate-scope.js +199 -0
- package/dist/schedule-strategy-generate.js +9 -473
- package/dist/schedule.js +19 -6
- package/dist/specdojo-config.js +465 -20
- package/dist/specdojo-gitignore.js +135 -0
- package/dist/specdojo.js +6 -0
- package/dist/viewpoint-document-kinds-check.js +128 -0
- package/dist/yaml-pages.js +4 -4
- package/dist/yaml.js +28 -0
- package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
- package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
- package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
- package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
- package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
- package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
- package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
- package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
- package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
- package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
- package/docs/ja/specdojo/guides/exec-config-guide.md +93 -49
- package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
- package/docs/ja/specdojo/guides/kata-guide.md +4 -4
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +45 -22
- package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
- package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
- package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
- package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
- package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
- package/docs/ja/specdojo/guides/review-guide.md +195 -158
- package/docs/ja/specdojo/guides/routine-operation-guide.md +75 -10
- package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
- package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
- package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
- package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
- package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
- package/docs/ja/specdojo/guides/waza-guide.md +15 -2
- package/docs/ja/specdojo/index.md +2 -2
- package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
- package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
- package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
- package/docs/ja/specdojo/references/command-reference.md +335 -92
- package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
- package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
- package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
- package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
- package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
- package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
- package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
- package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
- package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
- package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
- package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
- package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
- package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
- package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
- package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
- package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
- package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
- package/docs/ja/specdojo/samples/bps-sample.md +74 -21
- package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
- package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
- package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
- package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
- package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
- package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
- package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
- package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
- package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
- package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
- package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
- package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
- package/docs/ja/specdojo/templates/bps-template.md +91 -0
- package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
- package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
- package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
- package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
- package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
- package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
- package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
- package/package.json +17 -12
- package/templates/antigravity/README.md +29 -4
- package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
- package/templates/antigravity/exec-defaults-snippet.yaml +10 -7
- package/templates/antigravity/orchestrator.md +18 -7
- package/templates/antigravity/settings.global.json +55 -0
- package/templates/claude/agents/claude-executor.md +14 -0
- package/templates/claude/agents/claude-reporter.md +16 -0
- package/templates/claude/agents/specdojo-orchestrator.md +18 -7
- package/templates/claude/settings.edit.json +27 -1
- package/templates/codex/README.md +5 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
- package/templates/codex/orchestrator.md +18 -7
- package/templates/copilot/README.md +7 -5
- package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
- package/templates/devcontainer/devcontainer.json +27 -0
- package/templates/devcontainer/emacs/init.el +88 -0
- package/templates/devcontainer/post-create.sh +62 -0
- package/templates/init-agent-members.yaml +200 -0
- package/templates/init-exec-defaults.yaml +74 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
- package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
- package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
package/dist/specdojo-config.js
CHANGED
|
@@ -1,12 +1,62 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, join, resolve } from "node:path";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, posix, relative, resolve } from "node:path";
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
|
-
import
|
|
4
|
+
import { dump, load } from "./yaml.js";
|
|
5
|
+
import Ajv2020Module from "ajv/dist/2020.js";
|
|
5
6
|
import { runProviderScaffold, specdojoPackageRootDir } from "./exec-provider-scaffold.js";
|
|
7
|
+
import { ensureGitignore, formatGitignoreReport, gitignorePatternsForLayouts, } from "./specdojo-gitignore.js";
|
|
6
8
|
/** Default IANA time zone for register date derivation when run.register_date_timezone is unset. */
|
|
7
9
|
export const DEFAULT_REGISTER_DATE_TIMEZONE = "UTC";
|
|
8
10
|
export const SPECDOJO_CONFIG_REFERENCE_URL = "https://specdojo.github.io/specdojo/ja/specdojo/references/specdojo-config-reference.html";
|
|
11
|
+
export const REPO_NAME_PATTERN = /^[a-z0-9-]+$/;
|
|
12
|
+
/**
|
|
13
|
+
* Directory name of the project repository worktree under `<worktree_base>/<task-id>/` when the
|
|
14
|
+
* project declares `repos`. Product worktrees sit beside it as `<task-id>/<repo-name>/`, so a
|
|
15
|
+
* repository must not use this name.
|
|
16
|
+
*/
|
|
17
|
+
export const PROJECT_REPO_WORKTREE_DIRNAME = "project";
|
|
18
|
+
function readTextFileOrNull(path) {
|
|
19
|
+
try {
|
|
20
|
+
return readFileSync(path, "utf8");
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* True when `rootDir` is the project worktree of a multi-repository exec task, i.e.
|
|
28
|
+
* `<worktree_base>/<task-name>/project/` checked out on `exec/<task-name>`. Detected from the
|
|
29
|
+
* linked worktree's `.git` file and HEAD only (no git process), so it is cheap enough to run on
|
|
30
|
+
* every config load.
|
|
31
|
+
*/
|
|
32
|
+
export function isMultiRepoProjectWorktree(rootDir) {
|
|
33
|
+
const root = resolve(rootDir);
|
|
34
|
+
if (basename(root) !== PROJECT_REPO_WORKTREE_DIRNAME)
|
|
35
|
+
return false;
|
|
36
|
+
const dotGit = join(root, ".git");
|
|
37
|
+
if (!existsSync(dotGit) || statSync(dotGit).isDirectory())
|
|
38
|
+
return false;
|
|
39
|
+
const gitdirLine = readTextFileOrNull(dotGit)
|
|
40
|
+
?.split(/\r?\n/)
|
|
41
|
+
.find((line) => line.startsWith("gitdir:"));
|
|
42
|
+
if (!gitdirLine)
|
|
43
|
+
return false;
|
|
44
|
+
const gitdir = resolve(root, gitdirLine.slice("gitdir:".length).trim());
|
|
45
|
+
const head = readTextFileOrNull(join(gitdir, "HEAD"))?.trim();
|
|
46
|
+
return head === `ref: refs/heads/exec/${basename(dirname(root))}`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Absolute root of a declared repository. Normally `path` is resolved from the SpecDojo root.
|
|
50
|
+
* Inside the project worktree of a multi-repository exec task, the repository is the sibling
|
|
51
|
+
* worktree `<task-name>/<repo-name>/`, so `path` (written for the main checkout) is not used.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveRepoRoot(rootDir, repo) {
|
|
54
|
+
if (isMultiRepoProjectWorktree(rootDir))
|
|
55
|
+
return join(dirname(resolve(rootDir)), repo.name);
|
|
56
|
+
return resolve(rootDir, repo.path);
|
|
57
|
+
}
|
|
9
58
|
export const DEFAULT_PROJECT_CONTEXT = ["prj-overview"];
|
|
59
|
+
export const DEFAULT_AGENT_MEMBERS_PATH = ".specdojo/agent-members.yaml";
|
|
10
60
|
function findUpward(startDir, name) {
|
|
11
61
|
let currentDir = resolve(startDir);
|
|
12
62
|
while (true) {
|
|
@@ -28,6 +78,10 @@ export function specdojoRootDir() {
|
|
|
28
78
|
return dirname(gitMarker);
|
|
29
79
|
return process.cwd();
|
|
30
80
|
}
|
|
81
|
+
/** Default worktree directory beside the repository, derived from its directory name. */
|
|
82
|
+
export function defaultWorktreeBase(rootDir = specdojoRootDir()) {
|
|
83
|
+
return `../${basename(resolve(rootDir))}-worktrees`;
|
|
84
|
+
}
|
|
31
85
|
export function loadEnv() {
|
|
32
86
|
// Load .env from the repository root if present.
|
|
33
87
|
// Safe if missing.
|
|
@@ -88,20 +142,257 @@ export function getProjectContext(project) {
|
|
|
88
142
|
? [...DEFAULT_PROJECT_CONTEXT]
|
|
89
143
|
: [...project.project_context];
|
|
90
144
|
}
|
|
145
|
+
export function getProjectRepos(project) {
|
|
146
|
+
return project.repos ? project.repos.map((repo) => ({ ...repo })) : [];
|
|
147
|
+
}
|
|
148
|
+
function isRecord(value) {
|
|
149
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
150
|
+
}
|
|
151
|
+
const REPO_KEYS = new Set(["name", "path", "integration_branch", "setup"]);
|
|
152
|
+
const REPO_SETUP_KEYS = new Set(["install", "build"]);
|
|
153
|
+
/**
|
|
154
|
+
* Validate `projects.<projectId>.repos`. Returns one message per problem (empty when valid) so
|
|
155
|
+
* loadConfig can report every misconfigured repository at once. `path` is resolved from
|
|
156
|
+
* `rootDir` (the SpecDojo root) and must exist.
|
|
157
|
+
*/
|
|
158
|
+
export function validateProjectRepos(projectId, project, projectIds, rootDir) {
|
|
159
|
+
const repos = project.repos;
|
|
160
|
+
if (repos === undefined)
|
|
161
|
+
return [];
|
|
162
|
+
const where = `projects.${projectId}.repos`;
|
|
163
|
+
if (!Array.isArray(repos))
|
|
164
|
+
return [`${where} must be an array`];
|
|
165
|
+
const errors = [];
|
|
166
|
+
const seen = new Map();
|
|
167
|
+
repos.forEach((repo, index) => {
|
|
168
|
+
const at = `${where}[${index}]`;
|
|
169
|
+
if (!isRecord(repo)) {
|
|
170
|
+
errors.push(`${at} must be an object with name and path`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
for (const key of Object.keys(repo).sort()) {
|
|
174
|
+
if (!REPO_KEYS.has(key))
|
|
175
|
+
errors.push(`${at}: unknown key "${key}"`);
|
|
176
|
+
}
|
|
177
|
+
const name = repo.name;
|
|
178
|
+
if (typeof name !== "string" || !REPO_NAME_PATTERN.test(name)) {
|
|
179
|
+
errors.push(`${at}.name must match ${String(REPO_NAME_PATTERN)} (got ${JSON.stringify(name)})`);
|
|
180
|
+
}
|
|
181
|
+
else if (name === PROJECT_REPO_WORKTREE_DIRNAME) {
|
|
182
|
+
errors.push(`${at}.name "${name}" is reserved: the project repository worktree uses ` +
|
|
183
|
+
`<worktree_base>/<task-id>/${PROJECT_REPO_WORKTREE_DIRNAME}/`);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const firstIndex = seen.get(name);
|
|
187
|
+
if (firstIndex !== undefined) {
|
|
188
|
+
errors.push(`${at}.name "${name}" duplicates ${where}[${firstIndex}].name`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
seen.set(name, index);
|
|
192
|
+
}
|
|
193
|
+
if (projectIds.includes(name)) {
|
|
194
|
+
errors.push(`${at}.name "${name}" collides with project id "${name}"; ` +
|
|
195
|
+
`"${name}:<...>" in targets would be ambiguous between a repository path and a doc id`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const path = repo.path;
|
|
199
|
+
if (typeof path !== "string" || path.trim().length === 0) {
|
|
200
|
+
errors.push(`${at}.path must be a non-empty string`);
|
|
201
|
+
}
|
|
202
|
+
else if (isAbsolute(path)) {
|
|
203
|
+
errors.push(`${at}.path must be relative to the SpecDojo root (got absolute "${path}")`);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const absolutePath = typeof name === "string" && REPO_NAME_PATTERN.test(name)
|
|
207
|
+
? resolveRepoRoot(rootDir, { name, path })
|
|
208
|
+
: resolve(rootDir, path);
|
|
209
|
+
if (!existsSync(absolutePath)) {
|
|
210
|
+
errors.push(`${at}.path "${path}" does not exist (resolved to ${absolutePath})`);
|
|
211
|
+
}
|
|
212
|
+
else if (!statSync(absolutePath).isDirectory()) {
|
|
213
|
+
errors.push(`${at}.path "${path}" is not a directory (resolved to ${absolutePath})`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (repo.integration_branch !== undefined &&
|
|
217
|
+
!isOmittedOrNonEmptyString(repo.integration_branch)) {
|
|
218
|
+
errors.push(`${at}.integration_branch must be a non-empty string when present`);
|
|
219
|
+
}
|
|
220
|
+
const setup = repo.setup;
|
|
221
|
+
if (setup !== undefined) {
|
|
222
|
+
if (!isRecord(setup)) {
|
|
223
|
+
errors.push(`${at}.setup must be an object ({ install?: boolean, build?: boolean })`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
for (const [key, value] of Object.entries(setup).sort(([a], [b]) => a.localeCompare(b))) {
|
|
227
|
+
if (!REPO_SETUP_KEYS.has(key))
|
|
228
|
+
errors.push(`${at}.setup: unknown key "${key}"`);
|
|
229
|
+
else if (typeof value !== "boolean")
|
|
230
|
+
errors.push(`${at}.setup.${key} must be a boolean`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
return errors;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Resolve a `targets` / `paths` value. The value is a repository path only when the prefix
|
|
239
|
+
* before the first `:` is a declared repository name; any other value (including doc ids such as
|
|
240
|
+
* `prj-0001:foo` and un-prefixed values) is returned unchanged as `project`.
|
|
241
|
+
*/
|
|
242
|
+
export function resolveRepoQualifiedRef(value, repos) {
|
|
243
|
+
const trimmed = value.trim();
|
|
244
|
+
const separator = trimmed.indexOf(":");
|
|
245
|
+
if (separator <= 0)
|
|
246
|
+
return { kind: "project", value: trimmed };
|
|
247
|
+
const prefix = trimmed.slice(0, separator);
|
|
248
|
+
if (!repos.some((repo) => repo.name === prefix))
|
|
249
|
+
return { kind: "project", value: trimmed };
|
|
250
|
+
const rawPath = trimmed.slice(separator + 1).replaceAll("\\", "/");
|
|
251
|
+
if (rawPath.trim().length === 0) {
|
|
252
|
+
throw new Error(`Invalid repository path "${value}": the path after "${prefix}:" is empty`);
|
|
253
|
+
}
|
|
254
|
+
if (posix.isAbsolute(rawPath) || /^[A-Za-z]:\//.test(rawPath)) {
|
|
255
|
+
throw new Error(`Invalid repository path "${value}": the path must be relative to repository "${prefix}"`);
|
|
256
|
+
}
|
|
257
|
+
const normalized = posix.normalize(rawPath).replace(/\/+$/, "");
|
|
258
|
+
if (normalized === ".." || normalized.startsWith("../")) {
|
|
259
|
+
throw new Error(`Invalid repository path "${value}": the path escapes repository "${prefix}"`);
|
|
260
|
+
}
|
|
261
|
+
return { kind: "repo", repo: prefix, path: normalized === "" ? "." : normalized };
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Resolve a `<repo>:<path>` value to an absolute path under the declared repository. Returns
|
|
265
|
+
* null for values that are not repository-qualified so callers keep their current handling.
|
|
266
|
+
*/
|
|
267
|
+
export function resolveRepoQualifiedPath(rootDir, project, value) {
|
|
268
|
+
const repos = getProjectRepos(project);
|
|
269
|
+
const ref = resolveRepoQualifiedRef(value, repos);
|
|
270
|
+
if (ref.kind !== "repo")
|
|
271
|
+
return null;
|
|
272
|
+
const repo = repos.find((candidate) => candidate.name === ref.repo);
|
|
273
|
+
if (!repo)
|
|
274
|
+
return null;
|
|
275
|
+
return {
|
|
276
|
+
repo: ref.repo,
|
|
277
|
+
path: ref.path,
|
|
278
|
+
absolutePath: resolve(resolveRepoRoot(rootDir, repo), ref.path),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
91
281
|
export function loadMemberRoster(baseDir, project) {
|
|
92
282
|
const membersPath = getProjectMembersPath(project);
|
|
93
|
-
|
|
283
|
+
let humanRoster;
|
|
284
|
+
let humanFullPath;
|
|
285
|
+
if (membersPath) {
|
|
286
|
+
humanFullPath = resolve(baseDir, membersPath);
|
|
287
|
+
if (!existsSync(humanFullPath)) {
|
|
288
|
+
throw new Error(`members_path not found: ${humanFullPath}`);
|
|
289
|
+
}
|
|
290
|
+
const parsed = readYamlFile(humanFullPath);
|
|
291
|
+
if (!parsed || !Array.isArray(parsed.members)) {
|
|
292
|
+
throw new Error(`Invalid members file: ${humanFullPath} (expected { members: [...] })`);
|
|
293
|
+
}
|
|
294
|
+
const legacyAgent = parsed.members.find((member) => member?.type === "agent");
|
|
295
|
+
if (legacyAgent) {
|
|
296
|
+
throw new Error(`Invalid members file: ${humanFullPath}: agent '${legacyAgent.nickname ?? "<unknown>"}' ` +
|
|
297
|
+
`must be moved to ${resolve(baseDir, configuredAgentMembersPath(baseDir))}. ` +
|
|
298
|
+
`Run: specdojo config migrate-members --dry-run`);
|
|
299
|
+
}
|
|
300
|
+
validateMemberFile("pm-members.schema.yaml", humanFullPath, parsed);
|
|
301
|
+
humanRoster = parsed;
|
|
302
|
+
}
|
|
303
|
+
const agentMembersPath = configuredAgentMembersPath(baseDir);
|
|
304
|
+
const agentFullPath = resolve(baseDir, agentMembersPath);
|
|
305
|
+
let agentRoster;
|
|
306
|
+
if (existsSync(agentFullPath)) {
|
|
307
|
+
agentRoster = readYamlFile(agentFullPath);
|
|
308
|
+
if (!agentRoster || !Array.isArray(agentRoster.members)) {
|
|
309
|
+
throw new Error(`Invalid agent members file: ${agentFullPath} (expected { members: [...] })`);
|
|
310
|
+
}
|
|
311
|
+
const human = agentRoster.members.find((member) => member?.type === "human");
|
|
312
|
+
if (human) {
|
|
313
|
+
throw new Error(`Invalid agent members file: ${agentFullPath}: human '${human.nickname ?? "<unknown>"}' is not allowed`);
|
|
314
|
+
}
|
|
315
|
+
validateMemberFile("agent-members.schema.yaml", agentFullPath, agentRoster);
|
|
316
|
+
}
|
|
317
|
+
if (!humanRoster && !agentRoster)
|
|
94
318
|
return null;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
319
|
+
const membersWithSources = [
|
|
320
|
+
...(humanRoster?.members.map((member) => ({ member, source: humanFullPath })) ?? []),
|
|
321
|
+
...(agentRoster?.members.map((member) => ({ member, source: agentFullPath })) ?? []),
|
|
322
|
+
];
|
|
323
|
+
const seen = new Map();
|
|
324
|
+
for (const { member, source } of membersWithSources) {
|
|
325
|
+
const previousSource = seen.get(member.nickname);
|
|
326
|
+
if (previousSource) {
|
|
327
|
+
throw new Error(`Duplicate member nickname '${member.nickname}' across ${previousSource} and ${source}`);
|
|
328
|
+
}
|
|
329
|
+
seen.set(member.nickname, source);
|
|
98
330
|
}
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
331
|
+
const members = membersWithSources.map(({ member }) => member);
|
|
332
|
+
if (humanRoster)
|
|
333
|
+
return { ...humanRoster, members };
|
|
334
|
+
return { version: agentRoster?.version ?? 1, members };
|
|
335
|
+
}
|
|
336
|
+
const Ajv2020 = Ajv2020Module.default;
|
|
337
|
+
const memberSchemaValidators = new Map();
|
|
338
|
+
function readYamlFile(path) {
|
|
339
|
+
try {
|
|
340
|
+
return load(readFileSync(path, "utf8"));
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
throw new Error(`Invalid YAML: ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function memberSchemaValidator(schemaName) {
|
|
347
|
+
const schemaDir = join(specdojoPackageRootDir(), "docs", "specdojo", "schemas", "v1");
|
|
348
|
+
const cacheKey = `${schemaDir}/${schemaName}`;
|
|
349
|
+
const cached = memberSchemaValidators.get(cacheKey);
|
|
350
|
+
if (cached)
|
|
351
|
+
return cached;
|
|
352
|
+
const ajv = new Ajv2020({ allErrors: true, strict: false });
|
|
353
|
+
ajv.addFormat("email", /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
|
|
354
|
+
for (const entry of ["exec-common.schema.yaml", "pm-members.schema.yaml"]) {
|
|
355
|
+
if (entry === schemaName)
|
|
356
|
+
continue;
|
|
357
|
+
const path = join(schemaDir, entry);
|
|
358
|
+
if (existsSync(path))
|
|
359
|
+
ajv.addSchema(readYamlFile(path), entry);
|
|
360
|
+
}
|
|
361
|
+
const validator = ajv.compile(readYamlFile(join(schemaDir, schemaName)));
|
|
362
|
+
memberSchemaValidators.set(cacheKey, validator);
|
|
363
|
+
return validator;
|
|
364
|
+
}
|
|
365
|
+
function validateMemberFile(schemaName, path, value) {
|
|
366
|
+
const validate = memberSchemaValidator(schemaName);
|
|
367
|
+
if (validate(value))
|
|
368
|
+
return;
|
|
369
|
+
const details = (validate.errors ?? [])
|
|
370
|
+
.map((error) => `${error.instancePath || "/"} ${error.message ?? "is invalid"}`)
|
|
371
|
+
.join("; ");
|
|
372
|
+
throw new Error(`Schema validation failed: ${path}: ${details}`);
|
|
373
|
+
}
|
|
374
|
+
function dumpMemberFile(path, schemaName, value) {
|
|
375
|
+
const schemaPath = join(specdojoPackageRootDir(), "docs", "specdojo", "schemas", "v1", schemaName);
|
|
376
|
+
const schemaRef = relative(dirname(path), schemaPath).replaceAll("\\", "/");
|
|
377
|
+
return (`# yaml-language-server: $schema=${schemaRef}\n` + dump(value, { lineWidth: 100, noRefs: true }));
|
|
378
|
+
}
|
|
379
|
+
function configuredAgentMembersPath(baseDir) {
|
|
380
|
+
const configPath = resolve(baseDir, ".specdojo", "specdojo.config.json");
|
|
381
|
+
if (!existsSync(configPath))
|
|
382
|
+
return DEFAULT_AGENT_MEMBERS_PATH;
|
|
383
|
+
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
384
|
+
const configured = parsed.agent_members_path?.trim() || DEFAULT_AGENT_MEMBERS_PATH;
|
|
385
|
+
assertProtectedAgentMembersPath(configured, configPath);
|
|
386
|
+
return configured;
|
|
387
|
+
}
|
|
388
|
+
function assertProtectedAgentMembersPath(path, source) {
|
|
389
|
+
const normalized = path.replaceAll("\\", "/");
|
|
390
|
+
if (isAbsolute(path) ||
|
|
391
|
+
!normalized.startsWith(".specdojo/") ||
|
|
392
|
+
normalized.includes("../") ||
|
|
393
|
+
!/\.ya?ml$/i.test(normalized)) {
|
|
394
|
+
throw new Error(`Invalid agent_members_path in ${source}: expected a repository-relative YAML path under .specdojo/`);
|
|
103
395
|
}
|
|
104
|
-
return parsed;
|
|
105
396
|
}
|
|
106
397
|
export function assertValidActor(actor, roster) {
|
|
107
398
|
if (!roster)
|
|
@@ -109,7 +400,7 @@ export function assertValidActor(actor, roster) {
|
|
|
109
400
|
const known = roster.members.map((m) => m.nickname);
|
|
110
401
|
if (!known.includes(actor)) {
|
|
111
402
|
throw new Error(`Unknown actor: "${actor}". Must be one of: ${known.join(", ")}\n` +
|
|
112
|
-
`Register
|
|
403
|
+
`Register a human in members_path or an agent in agent_members_path before use.`);
|
|
113
404
|
}
|
|
114
405
|
}
|
|
115
406
|
function isOmittedOrNonEmptyString(value) {
|
|
@@ -145,6 +436,12 @@ export function loadConfig() {
|
|
|
145
436
|
if (!parsed || parsed.version !== 1 || typeof parsed.projects !== "object") {
|
|
146
437
|
throw new Error(`Invalid .specdojo/specdojo.config.json: expected { version: 1, projects: { ... } }`);
|
|
147
438
|
}
|
|
439
|
+
if (parsed.agent_members_path !== undefined) {
|
|
440
|
+
if (!isOmittedOrNonEmptyString(parsed.agent_members_path)) {
|
|
441
|
+
throw new Error(`Invalid .specdojo/specdojo.config.json: agent_members_path must be a non-empty string`);
|
|
442
|
+
}
|
|
443
|
+
assertProtectedAgentMembersPath(parsed.agent_members_path, configPath);
|
|
444
|
+
}
|
|
148
445
|
for (const [projectId, project] of Object.entries(parsed.projects)) {
|
|
149
446
|
if (!isValidProjectConfig(project)) {
|
|
150
447
|
throw new Error(`Invalid .specdojo/specdojo.config.json: projects.${projectId} must omit ` +
|
|
@@ -152,6 +449,15 @@ export function loadConfig() {
|
|
|
152
449
|
`and project_context must be a string[] when present`);
|
|
153
450
|
}
|
|
154
451
|
}
|
|
452
|
+
const projectIds = Object.keys(parsed.projects);
|
|
453
|
+
const rootDir = dirname(dirname(configPath));
|
|
454
|
+
const repoErrors = projectIds
|
|
455
|
+
.sort()
|
|
456
|
+
.flatMap((projectId) => validateProjectRepos(projectId, parsed.projects[projectId], projectIds, rootDir));
|
|
457
|
+
if (repoErrors.length > 0) {
|
|
458
|
+
throw new Error(`Invalid .specdojo/specdojo.config.json (${configPath}):\n` +
|
|
459
|
+
repoErrors.map((message) => ` - ${message}`).join("\n"));
|
|
460
|
+
}
|
|
155
461
|
return { configPath, config: parsed };
|
|
156
462
|
}
|
|
157
463
|
export function writeConfig(config) {
|
|
@@ -159,19 +465,51 @@ export function writeConfig(config) {
|
|
|
159
465
|
mkdirSync(dirname(configPath), { recursive: true });
|
|
160
466
|
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
161
467
|
}
|
|
468
|
+
// Resolve the repo-root-relative paths whose generated/ outputs must stay untracked.
|
|
469
|
+
// members/roles/viewpoints are single files, so they never hold a generated/ directory.
|
|
470
|
+
export function projectGitignoreLayout(project) {
|
|
471
|
+
const projectPaths = [
|
|
472
|
+
getProjectCatalogPath(project),
|
|
473
|
+
getProjectSchedulePath(project),
|
|
474
|
+
getProjectExecutionPath(project),
|
|
475
|
+
getProjectTimelinePath(project),
|
|
476
|
+
getProjectRegisterPath(project),
|
|
477
|
+
getProjectRoutinesPath(project),
|
|
478
|
+
getProjectJobsPath(project),
|
|
479
|
+
].filter((path) => path !== undefined);
|
|
480
|
+
return {
|
|
481
|
+
basePath: project.base_path,
|
|
482
|
+
projectPaths,
|
|
483
|
+
executionPath: getProjectExecutionPath(project),
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function writeGitignoreForConfig(config, dryRun) {
|
|
487
|
+
const layouts = Object.keys(config.projects)
|
|
488
|
+
.sort()
|
|
489
|
+
.map((id) => projectGitignoreLayout(config.projects[id]));
|
|
490
|
+
const result = ensureGitignore(specdojoRootDir(), gitignorePatternsForLayouts(layouts), {
|
|
491
|
+
dryRun,
|
|
492
|
+
});
|
|
493
|
+
process.stdout.write(formatGitignoreReport(result, dryRun));
|
|
494
|
+
}
|
|
162
495
|
export function registerConfigCommands(program) {
|
|
163
496
|
const cfg = program
|
|
164
497
|
.command("config")
|
|
165
498
|
.description("Config helpers (.specdojo/specdojo.config.json)");
|
|
166
499
|
cfg
|
|
167
500
|
.command("init")
|
|
168
|
-
.description("Create .specdojo/specdojo.config.json template (does not overwrite existing)"
|
|
169
|
-
.
|
|
501
|
+
.description("Create .specdojo/specdojo.config.json template (does not overwrite existing) " +
|
|
502
|
+
"and add the lines excluding specdojo outputs to .gitignore")
|
|
503
|
+
.option("--dry-run", "Show the planned config and .gitignore lines without writing", false)
|
|
504
|
+
.action((opts) => {
|
|
505
|
+
const dryRun = !!opts.dryRun;
|
|
170
506
|
const { configPath, config } = loadConfig();
|
|
171
507
|
if (config) {
|
|
172
508
|
process.stdout.write(`Already exists: ${configPath}\n`);
|
|
509
|
+
writeGitignoreForConfig(config, dryRun);
|
|
173
510
|
return;
|
|
174
511
|
}
|
|
512
|
+
const worktreeBase = defaultWorktreeBase();
|
|
175
513
|
const template = {
|
|
176
514
|
version: 1,
|
|
177
515
|
current_project: "prj-0001",
|
|
@@ -181,19 +519,43 @@ export function registerConfigCommands(program) {
|
|
|
181
519
|
project_register_path: "controls/project-register",
|
|
182
520
|
project_context: ["prj-overview"],
|
|
183
521
|
run: {
|
|
184
|
-
worktree_base:
|
|
522
|
+
worktree_base: worktreeBase,
|
|
185
523
|
},
|
|
186
524
|
},
|
|
187
525
|
},
|
|
188
526
|
};
|
|
189
|
-
|
|
190
|
-
|
|
527
|
+
if (dryRun) {
|
|
528
|
+
process.stdout.write(`Would create (dry-run): ${configPath}\n`);
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
writeConfig(template);
|
|
532
|
+
process.stdout.write(`Created: ${configPath}\n`);
|
|
533
|
+
}
|
|
534
|
+
writeGitignoreForConfig(template, dryRun);
|
|
535
|
+
if (dryRun)
|
|
536
|
+
return;
|
|
191
537
|
process.stdout.write("Next steps:\n" +
|
|
192
538
|
" 1. Keep this repository beside the product repository as app1-specdojo/.\n" +
|
|
193
|
-
|
|
539
|
+
` 2. Review the project ID and paths; worktrees default to ${worktreeBase}.\n` +
|
|
194
540
|
" 3. Optional agent setup: npx specdojo config scaffold --provider <name>\n" +
|
|
195
541
|
" 4. Create a register: npx specdojo register scaffold --project prj-0001\n" +
|
|
196
|
-
` 5. Before using catalog or schedule, add the required paths: ${SPECDOJO_CONFIG_REFERENCE_URL}\n`
|
|
542
|
+
` 5. Before using catalog or schedule, add the required paths: ${SPECDOJO_CONFIG_REFERENCE_URL}\n` +
|
|
543
|
+
' 6. To let tasks change the product repository, declare it under "repos" ' +
|
|
544
|
+
'(e.g. { "name": "app1", "path": "../app1" }) and write targets/paths as app1:<path>.\n');
|
|
545
|
+
});
|
|
546
|
+
cfg
|
|
547
|
+
.command("migrate-members")
|
|
548
|
+
.description("Move agent entries from project pm-members.yaml files to protected agent members")
|
|
549
|
+
.option("--project <projectId>", "Migrate only one project (default: all configured projects)")
|
|
550
|
+
.option("--dry-run", "Show planned changes without writing", false)
|
|
551
|
+
.action((opts) => {
|
|
552
|
+
try {
|
|
553
|
+
migrateAgentMembers({ projectId: opts.project, dryRun: !!opts.dryRun });
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
557
|
+
process.exitCode = 1;
|
|
558
|
+
}
|
|
197
559
|
});
|
|
198
560
|
cfg
|
|
199
561
|
.command("scaffold")
|
|
@@ -201,6 +563,7 @@ export function registerConfigCommands(program) {
|
|
|
201
563
|
.requiredOption("--provider <name>", "Provider template to copy (antigravity|claude|codex|copilot|opencode)")
|
|
202
564
|
.option("--force", "Overwrite existing files", false)
|
|
203
565
|
.option("--dry-run", "Show planned files without writing", false)
|
|
566
|
+
.option("--global", "Merge provider permissions into user-level settings (currently antigravity only)", false)
|
|
204
567
|
.action(async (opts) => {
|
|
205
568
|
try {
|
|
206
569
|
await runProviderScaffold(String(opts.provider), {
|
|
@@ -208,6 +571,7 @@ export function registerConfigCommands(program) {
|
|
|
208
571
|
repoRoot: specdojoRootDir(),
|
|
209
572
|
force: !!opts.force,
|
|
210
573
|
dryRun: !!opts.dryRun,
|
|
574
|
+
global: !!opts.global,
|
|
211
575
|
});
|
|
212
576
|
}
|
|
213
577
|
catch (error) {
|
|
@@ -217,6 +581,87 @@ export function registerConfigCommands(program) {
|
|
|
217
581
|
}
|
|
218
582
|
});
|
|
219
583
|
}
|
|
584
|
+
export function migrateAgentMembers(options) {
|
|
585
|
+
const rootDir = options.rootDir ? resolve(options.rootDir) : specdojoRootDir();
|
|
586
|
+
const configPath = join(rootDir, ".specdojo", "specdojo.config.json");
|
|
587
|
+
if (!existsSync(configPath))
|
|
588
|
+
throw new Error(`No config found: ${configPath}`);
|
|
589
|
+
const config = JSON.parse(readFileSync(configPath, "utf8"));
|
|
590
|
+
const projectEntries = options.projectId
|
|
591
|
+
? [[options.projectId, config.projects[options.projectId]]]
|
|
592
|
+
: Object.entries(config.projects);
|
|
593
|
+
if (options.projectId && !config.projects[options.projectId]) {
|
|
594
|
+
throw new Error(`Unknown project: ${options.projectId}`);
|
|
595
|
+
}
|
|
596
|
+
const agentRelPath = config.agent_members_path?.trim() || DEFAULT_AGENT_MEMBERS_PATH;
|
|
597
|
+
assertProtectedAgentMembersPath(agentRelPath, configPath);
|
|
598
|
+
const agentPath = resolve(rootDir, agentRelPath);
|
|
599
|
+
let existingAgents = { version: 1, members: [] };
|
|
600
|
+
if (existsSync(agentPath)) {
|
|
601
|
+
existingAgents = readYamlFile(agentPath);
|
|
602
|
+
validateMemberFile("agent-members.schema.yaml", agentPath, existingAgents);
|
|
603
|
+
}
|
|
604
|
+
const agentNicknames = new Set(existingAgents.members.map((member) => member.nickname));
|
|
605
|
+
const moved = [];
|
|
606
|
+
const updates = [];
|
|
607
|
+
for (const [projectId, project] of projectEntries) {
|
|
608
|
+
if (!project)
|
|
609
|
+
continue;
|
|
610
|
+
const relPath = getProjectMembersPath(project);
|
|
611
|
+
if (!relPath)
|
|
612
|
+
throw new Error(`projects.${projectId}.members_path is required`);
|
|
613
|
+
const path = resolve(rootDir, relPath);
|
|
614
|
+
if (!existsSync(path))
|
|
615
|
+
throw new Error(`members_path not found: ${path}`);
|
|
616
|
+
const roster = readYamlFile(path);
|
|
617
|
+
if (!roster || !Array.isArray(roster.members)) {
|
|
618
|
+
throw new Error(`Invalid members file: ${path} (expected { members: [...] })`);
|
|
619
|
+
}
|
|
620
|
+
const humans = roster.members.filter((member) => member.type !== "agent");
|
|
621
|
+
const agents = roster.members.filter((member) => member.type === "agent");
|
|
622
|
+
const humanNicknames = new Set();
|
|
623
|
+
for (const human of humans) {
|
|
624
|
+
if (humanNicknames.has(human.nickname)) {
|
|
625
|
+
throw new Error(`Duplicate human nickname '${human.nickname}' while migrating ${path}`);
|
|
626
|
+
}
|
|
627
|
+
humanNicknames.add(human.nickname);
|
|
628
|
+
}
|
|
629
|
+
for (const agent of agents) {
|
|
630
|
+
if (agentNicknames.has(agent.nickname)) {
|
|
631
|
+
throw new Error(`Duplicate agent nickname '${agent.nickname}' while migrating ${path}`);
|
|
632
|
+
}
|
|
633
|
+
agentNicknames.add(agent.nickname);
|
|
634
|
+
moved.push(agent);
|
|
635
|
+
}
|
|
636
|
+
const humanRoster = { ...roster, members: humans };
|
|
637
|
+
validateMemberFile("pm-members.schema.yaml", path, humanRoster);
|
|
638
|
+
updates.push({ path, roster: humanRoster, count: agents.length });
|
|
639
|
+
}
|
|
640
|
+
const mergedAgents = {
|
|
641
|
+
version: existingAgents.version || 1,
|
|
642
|
+
members: [...existingAgents.members, ...moved],
|
|
643
|
+
};
|
|
644
|
+
validateMemberFile("agent-members.schema.yaml", agentPath, mergedAgents);
|
|
645
|
+
for (const update of updates) {
|
|
646
|
+
for (const human of update.roster.members) {
|
|
647
|
+
if (agentNicknames.has(human.nickname)) {
|
|
648
|
+
throw new Error(`Duplicate member nickname '${human.nickname}' across ${update.path} and ${agentPath}`);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
const verb = options.dryRun ? "Would move" : "Moved";
|
|
653
|
+
for (const update of updates) {
|
|
654
|
+
process.stdout.write(`${verb} ${update.count} agent member(s) from ${update.path}\n`);
|
|
655
|
+
}
|
|
656
|
+
process.stdout.write(`${options.dryRun ? "Would write" : "Wrote"} ${mergedAgents.members.length} agent member(s) to ${agentPath}\n`);
|
|
657
|
+
if (options.dryRun)
|
|
658
|
+
return;
|
|
659
|
+
for (const update of updates) {
|
|
660
|
+
writeFileSync(update.path, dumpMemberFile(update.path, "pm-members.schema.yaml", update.roster), "utf8");
|
|
661
|
+
}
|
|
662
|
+
mkdirSync(dirname(agentPath), { recursive: true });
|
|
663
|
+
writeFileSync(agentPath, dumpMemberFile(agentPath, "agent-members.schema.yaml", mergedAgents), "utf8");
|
|
664
|
+
}
|
|
220
665
|
export function registerProjectCommands(program) {
|
|
221
666
|
const pj = program.command("project").description("Project registry commands");
|
|
222
667
|
pj.command("list")
|