specdojo 0.4.2 → 0.4.3
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/CHANGELOG.md +17 -0
- package/dist/catalog/build.js +7 -7
- package/dist/catalog/generate.js +27 -12
- package/dist/commands/init.js +10 -7
- package/dist/commands/orchestrator.js +9 -2
- package/dist/devcontainer/command.js +1 -1
- package/dist/devcontainer/scaffold.js +24 -9
- package/dist/exec/core.js +4 -0
- package/dist/exec/plans-core.js +10 -1
- package/dist/exec/plans-generation.js +13 -0
- package/dist/exec/plans-storage.js +4 -0
- package/dist/exec/register.js +64 -6
- package/dist/exec/results.js +5 -1
- package/dist/exec/strategy.js +4 -0
- package/dist/kata/authoring.js +100 -0
- package/dist/kata/command.js +52 -2
- package/dist/kata/kata.js +54 -11
- package/dist/register/approach.js +29 -1
- package/dist/register/create-commands.js +9 -0
- package/dist/register/cross-project.js +9 -2
- package/dist/register/external-project.js +136 -0
- package/dist/schedule/strategy-profiles.js +3 -0
- package/dist/shared/agent-types.js +4 -0
- package/dist/shared/provider-scaffold.js +3 -3
- package/dist/shared/specdojo-config.js +109 -2
- package/docs/ja/specdojo/exec-templates/xep-recipe-authoring-template.md +45 -0
- package/docs/ja/specdojo/exec-templates/xep-rulebook-authoring-template.md +45 -0
- package/docs/ja/specdojo/exec-templates/xep-sample-authoring-template.md +45 -0
- package/docs/ja/specdojo/exec-templates/xep-template-authoring-template.md +45 -0
- package/docs/ja/specdojo/guides/docs-editing-guide.md +32 -0
- package/docs/ja/specdojo/guides/docs-structure-guide.md +1 -1
- package/docs/ja/specdojo/guides/exec-config-guide.md +13 -6
- package/docs/ja/specdojo/guides/kata-guide.md +4 -0
- package/docs/ja/specdojo/guides/quick-start-guide.md +352 -68
- package/docs/ja/specdojo/guides/register-operation-guide.md +18 -0
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +10 -2
- package/docs/ja/specdojo/guides/ryu-guide.md +18 -4
- package/docs/ja/specdojo/guides/use-case-guide.md +2 -2
- package/docs/ja/specdojo/references/command-reference.md +39 -20
- package/docs/ja/specdojo/references/specdojo-config-reference.md +33 -7
- package/docs/ja/specdojo/standards/recipe-authoring-standard.md +10 -10
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +13 -13
- package/docs/ja/specdojo/standards/sample-authoring-standard.md +4 -4
- package/docs/ja/specdojo/standards/template-authoring-standard.md +4 -4
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +6 -0
- package/docs/specdojo/schemas/v1/exec-plan-frontmatter.schema.yaml +6 -6
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +21 -4
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +29 -0
- package/package.json +2 -2
- package/templates/antigravity/README.md +1 -1
- package/templates/antigravity/settings.global.json +5 -0
- package/templates/claude/README.md +11 -8
- package/templates/claude/settings.edit.json +10 -1
- package/templates/claude/settings.orchestrator.json +90 -0
- package/templates/claude/settings.report.json +14 -1
- package/templates/claude/settings.review.json +13 -1
- package/templates/codex/README.md +7 -5
- package/templates/codex/rules/specdojo.rules +48 -0
- package/templates/devcontainer/devcontainer.json +1 -4
- package/templates/opencode/README.md +2 -1
- package/templates/opencode/agents/opencode-executor.md +2 -0
- package/templates/opencode/agents/opencode-review-executor.md +2 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +59 -5
package/dist/kata/command.js
CHANGED
|
@@ -3,6 +3,9 @@ import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
|
3
3
|
import { load } from "../shared/yaml.js";
|
|
4
4
|
import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
|
|
5
5
|
import { specdojoResourceCandidates, } from "../docs/template-resolution.js";
|
|
6
|
+
import { getKataAuthority, loadConfig, specdojoRootDir } from "../shared/specdojo-config.js";
|
|
7
|
+
import { parsePracticeId } from "../shared/practice-id.js";
|
|
8
|
+
import { AUTHORING_KINDS, kataKindDirectory } from "./authoring.js";
|
|
6
9
|
export const KATA_RESOURCE_KINDS = [
|
|
7
10
|
"rulebook",
|
|
8
11
|
"standard",
|
|
@@ -121,6 +124,51 @@ function enumerateConfig(config, roots) {
|
|
|
121
124
|
};
|
|
122
125
|
});
|
|
123
126
|
}
|
|
127
|
+
function enumerateAuthoredResources(roots) {
|
|
128
|
+
const repositoryRoot = roots.repositoryRoot ?? specdojoRootDir();
|
|
129
|
+
const configuredAuthority = getKataAuthority(loadConfig(repositoryRoot).config, repositoryRoot);
|
|
130
|
+
return AUTHORING_KINDS.flatMap((kind) => {
|
|
131
|
+
const relativeDir = kataKindDirectory(kind, true);
|
|
132
|
+
const absoluteDir = resolve(repositoryRoot, relativeDir);
|
|
133
|
+
return relativeFiles(absoluteDir).flatMap((filePath) => {
|
|
134
|
+
const resolvedPath = resolve(absoluteDir, filePath);
|
|
135
|
+
const id = resourceId(resolvedPath);
|
|
136
|
+
let authority;
|
|
137
|
+
try {
|
|
138
|
+
authority = parsePracticeId(id).authority;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
if (authority !== configuredAuthority)
|
|
144
|
+
return [];
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
id,
|
|
148
|
+
kind,
|
|
149
|
+
ejectable: false,
|
|
150
|
+
relativePath: normalizeRelativePath(join(relativeDir, filePath)),
|
|
151
|
+
repositoryPath: resolvedPath,
|
|
152
|
+
resolvedPath,
|
|
153
|
+
source: "repository",
|
|
154
|
+
state: "ejected",
|
|
155
|
+
difference: "-",
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function specdojoOwnedResource(resource) {
|
|
162
|
+
if (resource.kind === "standard")
|
|
163
|
+
return true;
|
|
164
|
+
try {
|
|
165
|
+
const authority = parsePracticeId(resource.id).authority;
|
|
166
|
+
return authority === undefined || authority === "specdojo";
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
124
172
|
const ALL_LIST_KINDS = [...KATA_RESOURCE_KINDS, ...KATA_REFERENCED_KINDS];
|
|
125
173
|
function assertKind(kind) {
|
|
126
174
|
if (kind === undefined)
|
|
@@ -136,10 +184,12 @@ export function listKataResources(options = {}) {
|
|
|
136
184
|
const configs = options.all || (kind !== undefined && !isEjectableKind(kind))
|
|
137
185
|
? RESOURCE_KINDS
|
|
138
186
|
: EJECTABLE_KINDS;
|
|
139
|
-
|
|
187
|
+
const bundledAndOverrides = configs
|
|
140
188
|
.filter((config) => kind === undefined || config.kind === kind)
|
|
141
189
|
.flatMap((config) => enumerateConfig(config, options.roots ?? {}))
|
|
142
|
-
.
|
|
190
|
+
.filter(specdojoOwnedResource);
|
|
191
|
+
const authored = enumerateAuthoredResources(options.roots ?? {}).filter((resource) => kind === undefined || resource.kind === kind);
|
|
192
|
+
return [...bundledAndOverrides, ...authored].sort((first, second) => first.kind.localeCompare(second.kind) ||
|
|
143
193
|
first.relativePath.localeCompare(second.relativePath));
|
|
144
194
|
}
|
|
145
195
|
function localId(id) {
|
package/dist/kata/kata.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
2
3
|
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
3
4
|
import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
|
|
4
|
-
import { practiceLocalId } from "../shared/practice-id.js";
|
|
5
|
+
import { parsePracticeId, practiceLocalId } from "../shared/practice-id.js";
|
|
6
|
+
import { authoredKataPath, configuredKataAuthority } from "./authoring.js";
|
|
5
7
|
import { resolveSpecdojoPathIfExists, resolveSpecdojoReferencePathIfExists, specdojoResourceCandidates, } from "../docs/template-resolution.js";
|
|
6
8
|
import { readYamlSchemaModelineRef } from "./yaml-schema-modeline.js";
|
|
7
9
|
// 実践の型(rulebook / recipe / sample / template)の解決を 1 か所に集約する。
|
|
@@ -16,7 +18,11 @@ const KIND_DIR = {
|
|
|
16
18
|
template: "templates",
|
|
17
19
|
};
|
|
18
20
|
function rulebookFsPath(rulebookId) {
|
|
19
|
-
const relativePath =
|
|
21
|
+
const relativePath = practiceRepoPath("rulebook", rulebookId, "md");
|
|
22
|
+
const authority = parsePracticeId(rulebookId).authority;
|
|
23
|
+
if (authority && authority !== "specdojo") {
|
|
24
|
+
return resolve(specdojoRootDir(), relativePath);
|
|
25
|
+
}
|
|
20
26
|
return (resolveSpecdojoPathIfExists(relativePath) ??
|
|
21
27
|
specdojoResourceCandidates(relativePath).repositoryPath);
|
|
22
28
|
}
|
|
@@ -53,14 +59,53 @@ function formatExt(targetFormat) {
|
|
|
53
59
|
// Canonical repo-root-relative path (no leading slash): the agent opens these files
|
|
54
60
|
// from the run CWD (repo root or worktree root).
|
|
55
61
|
function repoPath(kind, id, ext) {
|
|
56
|
-
return
|
|
62
|
+
return practiceRepoPath(kind, id, ext);
|
|
63
|
+
}
|
|
64
|
+
function isSpecdojoResourceId(id) {
|
|
65
|
+
const authority = parsePracticeId(id).authority;
|
|
66
|
+
return !authority || authority === "specdojo";
|
|
67
|
+
}
|
|
68
|
+
function kataReferencePath(relativePath, id) {
|
|
69
|
+
if (!isSpecdojoResourceId(id))
|
|
70
|
+
return relativePath;
|
|
71
|
+
return resolveSpecdojoReferencePathIfExists(relativePath) ?? relativePath;
|
|
72
|
+
}
|
|
73
|
+
function kataFsPath(relativePath, id) {
|
|
74
|
+
if (!isSpecdojoResourceId(id))
|
|
75
|
+
return resolve(specdojoRootDir(), relativePath);
|
|
76
|
+
return (resolveSpecdojoPathIfExists(relativePath) ??
|
|
77
|
+
specdojoResourceCandidates(relativePath).repositoryPath);
|
|
78
|
+
}
|
|
79
|
+
function practiceRepoPath(kind, id, ext, rootDir = specdojoRootDir()) {
|
|
80
|
+
const authority = parsePracticeId(id).authority;
|
|
81
|
+
const directory = kind === "rulebook" ? "rulebooks" : KIND_DIR[kind];
|
|
82
|
+
if (authority && authority !== "specdojo") {
|
|
83
|
+
if (authority !== configuredKataAuthority(rootDir)) {
|
|
84
|
+
return `${KATA_UNRESOLVABLE_BASE}/${directory}/${practiceLocalId(id)}.${ext}`;
|
|
85
|
+
}
|
|
86
|
+
return authoredKataPath(id, kind).replace(/\.md$/, `.${ext}`);
|
|
87
|
+
}
|
|
88
|
+
return `${DOCS_BASE}/${directory}/${practiceLocalId(id)}.${ext}`;
|
|
89
|
+
}
|
|
90
|
+
const KATA_UNRESOLVABLE_BASE = ".specdojo/unresolvable-kata";
|
|
91
|
+
export function resolveKataDocumentPathIfExists(kind, id, extension, roots = {}) {
|
|
92
|
+
const repositoryRoot = roots.repositoryRoot ?? specdojoRootDir();
|
|
93
|
+
const authority = parsePracticeId(id).authority;
|
|
94
|
+
if (authority && authority !== "specdojo") {
|
|
95
|
+
if (authority !== configuredKataAuthority(repositoryRoot))
|
|
96
|
+
return undefined;
|
|
97
|
+
const relativePath = practiceRepoPath(kind, id, extension, repositoryRoot);
|
|
98
|
+
const absolutePath = resolve(repositoryRoot, relativePath);
|
|
99
|
+
return existsSync(absolutePath) ? absolutePath : undefined;
|
|
100
|
+
}
|
|
101
|
+
return resolveSpecdojoPathIfExists(practiceRepoPath(kind, id, extension, repositoryRoot), roots);
|
|
57
102
|
}
|
|
58
103
|
// 宣言 ID は拡張子を持たないため、対象形式を優先しつつ実在する例外形式も解決する。
|
|
59
104
|
// dct-index の YAML 正本に対する Markdown 生成ビュー template などが該当する。
|
|
60
105
|
function declaredRefExt(kind, id, preferredExt) {
|
|
61
106
|
const candidates = kind === "recipe" ? ["md"] : [preferredExt, "md", "yaml", "json"];
|
|
62
107
|
for (const ext of [...new Set(candidates)]) {
|
|
63
|
-
if (
|
|
108
|
+
if (resolveKataDocumentPathIfExists(kind, id, ext))
|
|
64
109
|
return ext;
|
|
65
110
|
}
|
|
66
111
|
return preferredExt;
|
|
@@ -75,7 +120,7 @@ function resolveRef(kind, declaredId, ext) {
|
|
|
75
120
|
}
|
|
76
121
|
if (primaryId) {
|
|
77
122
|
const relativePath = repoPath(kind, primaryId, declaredRefExt(kind, primaryId, ext));
|
|
78
|
-
return
|
|
123
|
+
return kataReferencePath(relativePath, primaryId);
|
|
79
124
|
}
|
|
80
125
|
return MISSING;
|
|
81
126
|
}
|
|
@@ -93,8 +138,7 @@ export function resolveKataRefs(rulebookId, targetKind) {
|
|
|
93
138
|
const fm = usableRulebookId ? loadRulebookRefs(usableRulebookId) : {};
|
|
94
139
|
return {
|
|
95
140
|
rulebook: usableRulebookId
|
|
96
|
-
? (
|
|
97
|
-
rulebookRepoPath(usableRulebookId))
|
|
141
|
+
? kataReferencePath(rulebookRepoPath(usableRulebookId), usableRulebookId)
|
|
98
142
|
: MISSING,
|
|
99
143
|
recipe: usableRulebookId ? resolveRef("recipe", fm.recipe, "md") : MISSING,
|
|
100
144
|
sample: usableRulebookId
|
|
@@ -107,7 +151,7 @@ export function resolveKataRefs(rulebookId, targetKind) {
|
|
|
107
151
|
}
|
|
108
152
|
// rulebook の repo 相対パス(先頭スラッシュ無し)。
|
|
109
153
|
function rulebookRepoPath(rulebookId) {
|
|
110
|
-
return
|
|
154
|
+
return practiceRepoPath("rulebook", rulebookId, "md");
|
|
111
155
|
}
|
|
112
156
|
// 主 rulebook の frontmatter `includes` から、併せて適用する rulebook の宣言順・重複除去済み
|
|
113
157
|
// ID 一覧を返す。自己参照は除外する。単一段のみ(include 先の include はたどらない)。
|
|
@@ -135,7 +179,7 @@ export function resolveIncludedRulebooks(rulebookId) {
|
|
|
135
179
|
}
|
|
136
180
|
return declaredIncludeIds(rulebookId)
|
|
137
181
|
.filter((id) => existsSync(rulebookFsPath(id)))
|
|
138
|
-
.map((id) =>
|
|
182
|
+
.map((id) => kataReferencePath(rulebookRepoPath(id), id));
|
|
139
183
|
}
|
|
140
184
|
// validate 用: 主 rulebook が宣言する include の一覧(実在に関わらず)。
|
|
141
185
|
// 自己参照フラグ付きで返し、呼び出し側で存在・種別を検査する。
|
|
@@ -175,8 +219,7 @@ export function declaredKata(rulebookId) {
|
|
|
175
219
|
out.push({
|
|
176
220
|
kind,
|
|
177
221
|
id,
|
|
178
|
-
fsPath:
|
|
179
|
-
specdojoResourceCandidates(relativePath).repositoryPath,
|
|
222
|
+
fsPath: kataFsPath(relativePath, id),
|
|
180
223
|
});
|
|
181
224
|
}
|
|
182
225
|
};
|
|
@@ -7,6 +7,7 @@ import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
|
|
|
7
7
|
import { getProjectCatalogPath, loadConfig, specdojoRootDir } from "../shared/specdojo-config.js";
|
|
8
8
|
import { APPROACHES } from "../shared/agent-types.js";
|
|
9
9
|
import { load } from "../shared/yaml.js";
|
|
10
|
+
import { assertAuthorableKataId, authoredKataExists, authoringKind } from "../kata/authoring.js";
|
|
10
11
|
const MAINTENANCE_TARGET_KIND = {
|
|
11
12
|
"rulebook-maintenance": "rulebook",
|
|
12
13
|
"recipe-maintenance": "recipe",
|
|
@@ -75,9 +76,13 @@ export function validateRegisterApproachTargets(opts) {
|
|
|
75
76
|
throw new Error(`Invalid approach: "${approachText}". Must be one of: ${APPROACHES.join(", ")}`);
|
|
76
77
|
}
|
|
77
78
|
approach = approachText;
|
|
78
|
-
|
|
79
|
+
const kind = authoringKind(approach);
|
|
80
|
+
if (!kind && targets.length !== 1) {
|
|
79
81
|
throw new Error(`Approach "${approach}" requires exactly one --target doc id (received ${targets.length})`);
|
|
80
82
|
}
|
|
83
|
+
if (kind && targets.length < 1) {
|
|
84
|
+
throw new Error(`Approach "${approach}" requires the new kata id as the first --target`);
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
if (!approach && !opts.validateTargetsWithoutApproach)
|
|
83
88
|
return;
|
|
@@ -92,6 +97,29 @@ export function validateRegisterApproachTargets(opts) {
|
|
|
92
97
|
}
|
|
93
98
|
return;
|
|
94
99
|
}
|
|
100
|
+
const authoringTargetKind = authoringKind(approach);
|
|
101
|
+
if (authoringTargetKind) {
|
|
102
|
+
const [kataId, ...exampleIds] = targets;
|
|
103
|
+
if (!kataId) {
|
|
104
|
+
throw new Error(`Approach "${approach}" requires the new kata id as the first --target`);
|
|
105
|
+
}
|
|
106
|
+
assertAuthorableKataId(kataId, authoringTargetKind, opts.repoRoot);
|
|
107
|
+
if (entries[kataId] || authoredKataExists(kataId, opts.repoRoot)) {
|
|
108
|
+
throw new Error(`Kata id ${kataId} already exists; use ${authoringTargetKind}-maintenance instead`);
|
|
109
|
+
}
|
|
110
|
+
if (exampleIds.length === 0)
|
|
111
|
+
return;
|
|
112
|
+
if (!opts.catalogPath) {
|
|
113
|
+
throw new Error(`Approach "${approach}" requires catalog_path to resolve exemplar deliverables`);
|
|
114
|
+
}
|
|
115
|
+
const deliverableDocIds = catalogDeliverableDocIds(opts.catalogPath, opts.repoRoot, opts.projectId);
|
|
116
|
+
for (const exampleId of exampleIds) {
|
|
117
|
+
if (!deliverableDocIds.has(exampleId)) {
|
|
118
|
+
throw new Error(`Approach "${approach}" requires every --target after the first to be a catalog deliverable, but ${exampleId} is not one`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
95
123
|
const expectedKind = MAINTENANCE_TARGET_KIND[approach];
|
|
96
124
|
const [targetId] = targets;
|
|
97
125
|
if (expectedKind) {
|
|
@@ -8,6 +8,7 @@ import { CELL_NONE, CELL_TODO, REMOVE_REGISTER_ITEM_FIELD, VALID_PRIORITIES, VAL
|
|
|
8
8
|
import { resolveSpecdojoTemplatePath } from "../docs/template-resolution.js";
|
|
9
9
|
import { validateRegisterApproachTargetsForProject } from "./approach.js";
|
|
10
10
|
import { normalizeDerivedFrom, validateDerivedFrom } from "./derivation.js";
|
|
11
|
+
import { delegateExternalRegisterAdd } from "./external-project.js";
|
|
11
12
|
function collectTarget(value, previous = []) {
|
|
12
13
|
return [...previous, value];
|
|
13
14
|
}
|
|
@@ -76,6 +77,14 @@ export function registerCreateCommands(reg, dependencies) {
|
|
|
76
77
|
addCmd.option("--dry-run", "Print the generated item file without writing", false);
|
|
77
78
|
addRegisterCommitOptions(addCmd);
|
|
78
79
|
addCmd.action(async (opts) => {
|
|
80
|
+
try {
|
|
81
|
+
if (delegateExternalRegisterAdd(opts))
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
printCommandError(error);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
79
88
|
await runRegisterMutation("add", opts, ({ paths, assertCommitTargetsClean }) => {
|
|
80
89
|
const explicitTopic = opts.topic?.trim();
|
|
81
90
|
const topic = explicitTopic || slugify(opts.title);
|
|
@@ -2,7 +2,7 @@ import { mkdtempSync, rmSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { gitOutput, gitResult, worktreeStatusPaths } from "../shared/git.js";
|
|
5
|
-
import { loadConfig, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
5
|
+
import { loadConfig, resolveExternalProjectRoot, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
6
6
|
const CROSS_PROJECT_TRANSITIONS = new Set([
|
|
7
7
|
"start",
|
|
8
8
|
"wait",
|
|
@@ -82,8 +82,15 @@ export function resolveCrossProjectMutationTarget(command, opts) {
|
|
|
82
82
|
if (!config)
|
|
83
83
|
throw new Error(`register commands require specdojo.config.json (${configPath})`);
|
|
84
84
|
const project = config.projects[projectId];
|
|
85
|
-
if (!project)
|
|
85
|
+
if (!project) {
|
|
86
|
+
const externalProject = config.external_projects?.[projectId];
|
|
87
|
+
if (externalProject) {
|
|
88
|
+
const targetRoot = resolveExternalProjectRoot(repoRoot, externalProject);
|
|
89
|
+
throw new Error(`Cross-repository register ${command} is not supported for external project ${projectId}. ` +
|
|
90
|
+
`Run the command in ${targetRoot} for project ${externalProject.project_id}.`);
|
|
91
|
+
}
|
|
86
92
|
throw new Error(`Unknown project: ${projectId} (check ${configPath})`);
|
|
93
|
+
}
|
|
87
94
|
const branch = resolveProjectIntegrationBranch(projectId, project);
|
|
88
95
|
const branchNow = currentBranch(repoRoot);
|
|
89
96
|
if (branchNow === branch)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { loadConfig, resolveExternalProjectRoot, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
5
|
+
export const MINIMUM_EXTERNAL_REGISTER_VERSION = "0.4.2";
|
|
6
|
+
function addValue(args, flag, value) {
|
|
7
|
+
if (value !== undefined)
|
|
8
|
+
args.push(flag, value);
|
|
9
|
+
}
|
|
10
|
+
function rewriteExternalDerivedFrom(value, alias, projectId) {
|
|
11
|
+
const separator = value.indexOf(":");
|
|
12
|
+
if (separator <= 0 || value.slice(0, separator) !== alias)
|
|
13
|
+
return value;
|
|
14
|
+
return `${projectId}:${value.slice(separator + 1)}`;
|
|
15
|
+
}
|
|
16
|
+
/** Build the target CLI invocation without exposing the caller's local alias to the target. */
|
|
17
|
+
export function buildExternalRegisterAddArgs(alias, externalProject, opts) {
|
|
18
|
+
const args = [
|
|
19
|
+
"register",
|
|
20
|
+
"add",
|
|
21
|
+
"--project",
|
|
22
|
+
externalProject.project_id,
|
|
23
|
+
"--type",
|
|
24
|
+
opts.type,
|
|
25
|
+
"--title",
|
|
26
|
+
opts.title,
|
|
27
|
+
"--description",
|
|
28
|
+
opts.description,
|
|
29
|
+
"--priority",
|
|
30
|
+
opts.priority,
|
|
31
|
+
"--status",
|
|
32
|
+
opts.status,
|
|
33
|
+
"--owner",
|
|
34
|
+
opts.owner,
|
|
35
|
+
"--due",
|
|
36
|
+
opts.due,
|
|
37
|
+
"--completed",
|
|
38
|
+
opts.completed,
|
|
39
|
+
"--conclusion",
|
|
40
|
+
opts.conclusion,
|
|
41
|
+
];
|
|
42
|
+
addValue(args, "--difficulty", opts.difficulty);
|
|
43
|
+
addValue(args, "--registered", opts.registered);
|
|
44
|
+
addValue(args, "--approach", opts.approach);
|
|
45
|
+
for (const target of opts.target ?? [])
|
|
46
|
+
addValue(args, "--target", target);
|
|
47
|
+
for (const source of opts.from ?? []) {
|
|
48
|
+
addValue(args, "--from", rewriteExternalDerivedFrom(source, alias, externalProject.project_id));
|
|
49
|
+
}
|
|
50
|
+
addValue(args, "--id", opts.id);
|
|
51
|
+
addValue(args, "--topic", opts.topic);
|
|
52
|
+
addValue(args, "--by", opts.by);
|
|
53
|
+
addValue(args, "--reason", opts.reason);
|
|
54
|
+
if (opts.force)
|
|
55
|
+
args.push("--force");
|
|
56
|
+
if (opts.dryRun)
|
|
57
|
+
args.push("--dry-run");
|
|
58
|
+
args.push("--commit");
|
|
59
|
+
addValue(args, "--message", opts.message);
|
|
60
|
+
return args;
|
|
61
|
+
}
|
|
62
|
+
function versionParts(version) {
|
|
63
|
+
const match = version.match(/(?:^|\s)v?(\d+)\.(\d+)\.(\d+)(?:\s|$|-)/);
|
|
64
|
+
if (!match)
|
|
65
|
+
return undefined;
|
|
66
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
67
|
+
}
|
|
68
|
+
export function supportsExternalRegister(version) {
|
|
69
|
+
const actual = versionParts(version);
|
|
70
|
+
const minimum = versionParts(MINIMUM_EXTERNAL_REGISTER_VERSION);
|
|
71
|
+
if (!actual || !minimum)
|
|
72
|
+
return false;
|
|
73
|
+
for (let index = 0; index < actual.length; index += 1) {
|
|
74
|
+
if (actual[index] !== minimum[index])
|
|
75
|
+
return actual[index] > minimum[index];
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
function targetSpecdojoExecutable(repoRoot) {
|
|
80
|
+
const executable = join(repoRoot, "node_modules", ".bin", process.platform === "win32" ? "specdojo.cmd" : "specdojo");
|
|
81
|
+
if (!existsSync(executable)) {
|
|
82
|
+
throw new Error(`External project repository does not have SpecDojo installed: ${executable}. ` +
|
|
83
|
+
`Install specdojo ${MINIMUM_EXTERNAL_REGISTER_VERSION} or newer in that repository.`);
|
|
84
|
+
}
|
|
85
|
+
return executable;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Delegate `register add` when `--project` names an external-project alias.
|
|
89
|
+
* Returns false for a local project so the normal mutation path can continue.
|
|
90
|
+
*/
|
|
91
|
+
export function delegateExternalRegisterAdd(opts, run = spawnSync) {
|
|
92
|
+
const alias = opts.project?.trim();
|
|
93
|
+
if (!alias)
|
|
94
|
+
return false;
|
|
95
|
+
const rootDir = specdojoRootDir();
|
|
96
|
+
const { config, configPath } = loadConfig(rootDir);
|
|
97
|
+
if (!config)
|
|
98
|
+
throw new Error(`register commands require specdojo.config.json (${configPath})`);
|
|
99
|
+
const externalProject = config.external_projects?.[alias];
|
|
100
|
+
if (!externalProject)
|
|
101
|
+
return false;
|
|
102
|
+
if (!opts.commit) {
|
|
103
|
+
throw new Error(`Cross-repository register add for external project ${alias} requires --commit.`);
|
|
104
|
+
}
|
|
105
|
+
const repoRoot = resolveExternalProjectRoot(rootDir, externalProject);
|
|
106
|
+
const executable = targetSpecdojoExecutable(repoRoot);
|
|
107
|
+
const versionResult = run(executable, ["--version"], {
|
|
108
|
+
cwd: repoRoot,
|
|
109
|
+
encoding: "utf8",
|
|
110
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
111
|
+
});
|
|
112
|
+
if (versionResult.error) {
|
|
113
|
+
throw new Error(`Failed to run SpecDojo in external project ${alias}: ${versionResult.error.message}`);
|
|
114
|
+
}
|
|
115
|
+
if (versionResult.status !== 0) {
|
|
116
|
+
const detail = `${versionResult.stderr ?? versionResult.stdout ?? ""}`.trim();
|
|
117
|
+
throw new Error(`Failed to inspect SpecDojo version in external project ${alias}` +
|
|
118
|
+
(detail ? `: ${detail}` : "."));
|
|
119
|
+
}
|
|
120
|
+
const version = `${versionResult.stdout ?? ""}`.trim();
|
|
121
|
+
if (!supportsExternalRegister(version)) {
|
|
122
|
+
throw new Error(`External project ${alias} uses SpecDojo ${version || "with an unknown version"}; ` +
|
|
123
|
+
`${MINIMUM_EXTERNAL_REGISTER_VERSION} or newer is required for cross-project register add.`);
|
|
124
|
+
}
|
|
125
|
+
const result = run(executable, buildExternalRegisterAddArgs(alias, externalProject, opts), {
|
|
126
|
+
cwd: repoRoot,
|
|
127
|
+
encoding: "utf8",
|
|
128
|
+
stdio: "inherit",
|
|
129
|
+
});
|
|
130
|
+
if (result.error) {
|
|
131
|
+
throw new Error(`Failed to run SpecDojo in external project ${alias}: ${result.error.message}`);
|
|
132
|
+
}
|
|
133
|
+
if (result.status !== 0)
|
|
134
|
+
process.exitCode = result.status ?? 1;
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
@@ -249,6 +249,9 @@ export const STRATEGY_PROFILES = {
|
|
|
249
249
|
},
|
|
250
250
|
};
|
|
251
251
|
export function profileFor(approach) {
|
|
252
|
+
if (!(approach in STRATEGY_PROFILES)) {
|
|
253
|
+
throw new Error(`Approach "${approach}" has no schedule strategy profile; kata authoring approaches are register-only`);
|
|
254
|
+
}
|
|
252
255
|
return STRATEGY_PROFILES[approach];
|
|
253
256
|
}
|
|
254
257
|
// Serializable phase entry for sch-strategy.schema.yaml.
|
|
@@ -8,8 +8,8 @@ function isRecord(value) {
|
|
|
8
8
|
export { specdojoPackageRootDir } from "./package-paths.js";
|
|
9
9
|
export const ORCHESTRATOR_NPM_SCRIPTS = {
|
|
10
10
|
claude: {
|
|
11
|
-
"orch:opus": "specdojo orchestrator launch --provider claude -- --agent specdojo-orchestrator --model opus",
|
|
12
|
-
"orch:sonnet": "specdojo orchestrator launch --provider claude -- --agent specdojo-orchestrator --model sonnet",
|
|
11
|
+
"orch:opus": "specdojo orchestrator launch --provider claude -- --agent specdojo-orchestrator --model opus --settings .specdojo/claude/settings.orchestrator.json",
|
|
12
|
+
"orch:sonnet": "specdojo orchestrator launch --provider claude -- --agent specdojo-orchestrator --model sonnet --settings .specdojo/claude/settings.orchestrator.json",
|
|
13
13
|
},
|
|
14
14
|
codex: {
|
|
15
15
|
"orch:sol": 'specdojo orchestrator launch --provider codex -- -m gpt-5.6-sol "$(cat .specdojo/codex/orchestrator.md)"',
|
|
@@ -75,7 +75,7 @@ export async function buildProviderScaffoldPlan(opts) {
|
|
|
75
75
|
relFile === PROVIDER_GLOBAL_SETTINGS[provider]?.templateRelPath) {
|
|
76
76
|
continue;
|
|
77
77
|
}
|
|
78
|
-
const destinationRelPath = relFile.startsWith("agents/")
|
|
78
|
+
const destinationRelPath = relFile.startsWith("agents/") || relFile.startsWith("rules/")
|
|
79
79
|
? `.${provider}/${relFile}`
|
|
80
80
|
: `.specdojo/${provider}/${relFile}`;
|
|
81
81
|
entries.push({
|
|
@@ -120,6 +120,48 @@ export function resolveRegisterActor(actor, roster) {
|
|
|
120
120
|
accepted.join(", "));
|
|
121
121
|
}
|
|
122
122
|
export const DEFAULT_AGENT_MEMBERS_PATH = ".specdojo/agent-members.yaml";
|
|
123
|
+
export const KATA_AUTHORITY_PATTERN = /^(?!prj-)(?!specdojo$)[a-z][a-z0-9-]*$/;
|
|
124
|
+
function repositoryIdentityRoot(rootDir) {
|
|
125
|
+
const root = resolve(rootDir);
|
|
126
|
+
const dotGit = join(root, ".git");
|
|
127
|
+
if (!existsSync(dotGit) || statSync(dotGit).isDirectory())
|
|
128
|
+
return root;
|
|
129
|
+
const gitdirLine = readTextFileOrNull(dotGit)
|
|
130
|
+
?.split(/\r?\n/)
|
|
131
|
+
.find((line) => line.startsWith("gitdir:"));
|
|
132
|
+
if (!gitdirLine)
|
|
133
|
+
return root;
|
|
134
|
+
const gitdir = resolve(root, gitdirLine.slice("gitdir:".length).trim()).replaceAll("\\", "/");
|
|
135
|
+
const marker = "/.git/worktrees/";
|
|
136
|
+
const markerIndex = gitdir.lastIndexOf(marker);
|
|
137
|
+
return markerIndex >= 0 ? gitdir.slice(0, markerIndex) : root;
|
|
138
|
+
}
|
|
139
|
+
export function defaultKataAuthority(rootDir = specdojoRootDir()) {
|
|
140
|
+
const directoryName = basename(repositoryIdentityRoot(rootDir));
|
|
141
|
+
const normalized = directoryName
|
|
142
|
+
.toLowerCase()
|
|
143
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
144
|
+
.replace(/^-+|-+$/g, "");
|
|
145
|
+
const withLetterPrefix = /^[a-z]/.test(normalized) ? normalized : `repo-${normalized}`;
|
|
146
|
+
const withoutReservedAuthority = withLetterPrefix === "specdojo" || withLetterPrefix.startsWith("prj-")
|
|
147
|
+
? `repo-${withLetterPrefix}`
|
|
148
|
+
: withLetterPrefix;
|
|
149
|
+
return KATA_AUTHORITY_PATTERN.test(withoutReservedAuthority)
|
|
150
|
+
? withoutReservedAuthority
|
|
151
|
+
: "repository";
|
|
152
|
+
}
|
|
153
|
+
export function getKataAuthority(config, rootDir = specdojoRootDir()) {
|
|
154
|
+
return config?.kata_authority?.trim() || defaultKataAuthority(rootDir);
|
|
155
|
+
}
|
|
156
|
+
export function isSpecdojoSourceRepository(rootDir = specdojoRootDir()) {
|
|
157
|
+
try {
|
|
158
|
+
const pkg = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"));
|
|
159
|
+
return pkg.name === "specdojo" && existsSync(join(rootDir, "src", "specdojo.ts"));
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
123
165
|
function findUpward(startDir, name) {
|
|
124
166
|
let currentDir = resolve(startDir);
|
|
125
167
|
while (true) {
|
|
@@ -213,6 +255,64 @@ function isRecord(value) {
|
|
|
213
255
|
}
|
|
214
256
|
const REPO_KEYS = new Set(["name", "path", "integration_branch", "setup"]);
|
|
215
257
|
const REPO_SETUP_KEYS = new Set(["install", "build"]);
|
|
258
|
+
const EXTERNAL_PROJECT_KEYS = new Set(["path", "project_id"]);
|
|
259
|
+
/** Resolve a configured external-project repository from the SpecDojo root. */
|
|
260
|
+
export function resolveExternalProjectRoot(rootDir, project) {
|
|
261
|
+
return resolve(rootDir, project.path);
|
|
262
|
+
}
|
|
263
|
+
/** Return external projects in configuration order with absolute repository roots. */
|
|
264
|
+
export function resolveExternalProjects(rootDir, config) {
|
|
265
|
+
return Object.entries(config.external_projects ?? {}).map(([alias, project]) => ({
|
|
266
|
+
alias,
|
|
267
|
+
...project,
|
|
268
|
+
repoRoot: resolveExternalProjectRoot(rootDir, project),
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
271
|
+
/** Validate top-level `external_projects` declarations. */
|
|
272
|
+
export function validateExternalProjects(externalProjects, projectIds, rootDir) {
|
|
273
|
+
if (externalProjects === undefined)
|
|
274
|
+
return [];
|
|
275
|
+
if (!isRecord(externalProjects))
|
|
276
|
+
return ["external_projects must be an object"];
|
|
277
|
+
const errors = [];
|
|
278
|
+
for (const [alias, value] of Object.entries(externalProjects)) {
|
|
279
|
+
const at = `external_projects.${alias}`;
|
|
280
|
+
if (!REPO_NAME_PATTERN.test(alias)) {
|
|
281
|
+
errors.push(`external project alias ${JSON.stringify(alias)} must match ${String(REPO_NAME_PATTERN)}`);
|
|
282
|
+
}
|
|
283
|
+
if (projectIds.includes(alias)) {
|
|
284
|
+
errors.push(`${at} collides with local project id "${alias}"`);
|
|
285
|
+
}
|
|
286
|
+
if (!isRecord(value)) {
|
|
287
|
+
errors.push(`${at} must be an object with path and project_id`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
for (const key of Object.keys(value).sort()) {
|
|
291
|
+
if (!EXTERNAL_PROJECT_KEYS.has(key))
|
|
292
|
+
errors.push(`${at}: unknown key "${key}"`);
|
|
293
|
+
}
|
|
294
|
+
const path = value.path;
|
|
295
|
+
if (typeof path !== "string" || path.trim().length === 0) {
|
|
296
|
+
errors.push(`${at}.path must be a non-empty string`);
|
|
297
|
+
}
|
|
298
|
+
else if (isAbsolute(path)) {
|
|
299
|
+
errors.push(`${at}.path must be relative to the SpecDojo root (got absolute "${path}")`);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
const absolutePath = resolve(rootDir, path);
|
|
303
|
+
if (!existsSync(absolutePath)) {
|
|
304
|
+
errors.push(`${at}.path "${path}" does not exist (resolved to ${absolutePath})`);
|
|
305
|
+
}
|
|
306
|
+
else if (!statSync(absolutePath).isDirectory()) {
|
|
307
|
+
errors.push(`${at}.path "${path}" is not a directory (resolved to ${absolutePath})`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (typeof value.project_id !== "string" || value.project_id.trim().length === 0) {
|
|
311
|
+
errors.push(`${at}.project_id must be a non-empty string`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return errors;
|
|
315
|
+
}
|
|
216
316
|
/**
|
|
217
317
|
* Validate `projects.<projectId>.repos`. Returns one message per problem (empty when valid) so
|
|
218
318
|
* loadConfig can report every misconfigured repository at once. `path` is resolved from
|
|
@@ -562,6 +662,11 @@ export function loadConfig(configRootDir = specdojoRootDir()) {
|
|
|
562
662
|
}
|
|
563
663
|
assertProtectedAgentMembersPath(parsed.agent_members_path, configPath);
|
|
564
664
|
}
|
|
665
|
+
if (parsed.kata_authority !== undefined &&
|
|
666
|
+
(typeof parsed.kata_authority !== "string" ||
|
|
667
|
+
!KATA_AUTHORITY_PATTERN.test(parsed.kata_authority))) {
|
|
668
|
+
throw new Error(`Invalid .specdojo/specdojo.config.json: kata_authority must match ${KATA_AUTHORITY_PATTERN}`);
|
|
669
|
+
}
|
|
565
670
|
for (const [projectId, project] of Object.entries(parsed.projects)) {
|
|
566
671
|
if (!isValidProjectConfig(project)) {
|
|
567
672
|
throw new Error(`Invalid .specdojo/specdojo.config.json: projects.${projectId} must omit ` +
|
|
@@ -574,9 +679,11 @@ export function loadConfig(configRootDir = specdojoRootDir()) {
|
|
|
574
679
|
const repoErrors = projectIds
|
|
575
680
|
.sort()
|
|
576
681
|
.flatMap((projectId) => validateProjectRepos(projectId, parsed.projects[projectId], projectIds, rootDir));
|
|
577
|
-
|
|
682
|
+
const externalProjectErrors = validateExternalProjects(parsed.external_projects, projectIds, rootDir);
|
|
683
|
+
const configErrors = [...repoErrors, ...externalProjectErrors];
|
|
684
|
+
if (configErrors.length > 0) {
|
|
578
685
|
throw new Error(`Invalid .specdojo/specdojo.config.json (${configPath}):\n` +
|
|
579
|
-
|
|
686
|
+
configErrors.map((message) => ` - ${message}`).join("\n"));
|
|
580
687
|
}
|
|
581
688
|
return { configPath, config: parsed };
|
|
582
689
|
}
|