specdojo 0.4.2 → 0.4.4
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 +2 -0
- package/CHANGELOG.md +29 -0
- package/dist/catalog/build.js +15 -13
- 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/docs/doc-index.js +11 -0
- 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 +146 -0
- package/dist/kata/command.js +64 -2
- package/dist/kata/kata.js +69 -12
- package/dist/register/approach.js +29 -1
- package/dist/register/core.js +3 -3
- 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/register/item.js +31 -5
- 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/dist/shared/text.js +3 -1
- 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 +6 -0
- package/docs/ja/specdojo/guides/practice-system-composition-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/rulebooks/dct-rulebook.md +2 -1
- package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +4 -0
- 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 +10 -10
- package/templates/antigravity/README.md +1 -1
- package/templates/antigravity/orchestrator.md +2 -0
- package/templates/antigravity/settings.global.json +5 -0
- package/templates/claude/README.md +11 -8
- package/templates/claude/agents/specdojo-orchestrator.md +2 -0
- 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/agents/specdojo-orchestrator.toml +2 -0
- package/templates/codex/orchestrator.md +2 -0
- 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 +61 -5
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { extname, resolve } from "node:path";
|
|
3
|
+
import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
|
|
4
|
+
import { getKataAuthority, isSpecdojoSourceRepository, loadConfig, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
5
|
+
import { parsePracticeId, practiceLocalId } from "../shared/practice-id.js";
|
|
6
|
+
import { load } from "../shared/yaml.js";
|
|
7
|
+
import { resolveSpecdojoReferencePathIfExists } from "../docs/template-resolution.js";
|
|
8
|
+
export const KATA_AUTHORING_BASE = "docs/ja/specdojo";
|
|
9
|
+
export const LEGACY_KATA_AUTHORING_BASE = "docs/ja/kata";
|
|
10
|
+
export const AUTHORING_KINDS = ["rulebook", "recipe", "sample", "template"];
|
|
11
|
+
const KIND_DIR = {
|
|
12
|
+
rulebook: "rulebooks",
|
|
13
|
+
recipe: "recipes",
|
|
14
|
+
sample: "samples",
|
|
15
|
+
template: "templates",
|
|
16
|
+
};
|
|
17
|
+
const AUTHORING_KIND_BY_APPROACH = {
|
|
18
|
+
"rulebook-authoring": "rulebook",
|
|
19
|
+
"recipe-authoring": "recipe",
|
|
20
|
+
"sample-authoring": "sample",
|
|
21
|
+
"template-authoring": "template",
|
|
22
|
+
};
|
|
23
|
+
export function authoringKind(approach) {
|
|
24
|
+
return approach ? AUTHORING_KIND_BY_APPROACH[approach] : undefined;
|
|
25
|
+
}
|
|
26
|
+
export function isAuthoringApproach(approach) {
|
|
27
|
+
return (approach !== undefined &&
|
|
28
|
+
Object.prototype.hasOwnProperty.call(AUTHORING_KIND_BY_APPROACH, approach));
|
|
29
|
+
}
|
|
30
|
+
export function kataKindDirectory(kind) {
|
|
31
|
+
return `${KATA_AUTHORING_BASE}/${KIND_DIR[kind]}`;
|
|
32
|
+
}
|
|
33
|
+
export function authoredKataDirectory(kind, authority) {
|
|
34
|
+
const directory = kataKindDirectory(kind);
|
|
35
|
+
return authority === "specdojo" ? directory : `${directory}/${authority}`;
|
|
36
|
+
}
|
|
37
|
+
export function legacyKataKindDirectory(kind) {
|
|
38
|
+
return `${LEGACY_KATA_AUTHORING_BASE}/${KIND_DIR[kind]}`;
|
|
39
|
+
}
|
|
40
|
+
export function authoredKataPath(id, kind, extension = "md") {
|
|
41
|
+
const authority = parsePracticeId(id).authority;
|
|
42
|
+
const directory = authoredKataDirectory(kind, authority ?? "specdojo");
|
|
43
|
+
return `${directory}/${practiceLocalId(id)}.${extension}`;
|
|
44
|
+
}
|
|
45
|
+
export function legacyAuthoredKataPath(id, kind, extension = "md") {
|
|
46
|
+
return `${legacyKataKindDirectory(kind)}/${practiceLocalId(id)}.${extension}`;
|
|
47
|
+
}
|
|
48
|
+
const warnedLegacyPaths = new Set();
|
|
49
|
+
export function warnLegacyAuthoredKata(id, canonicalPath, legacyPath, rootDir, duplicate) {
|
|
50
|
+
const warningKey = `${resolve(rootDir, legacyPath)}:${duplicate ? "duplicate" : "legacy"}`;
|
|
51
|
+
if (warnedLegacyPaths.has(warningKey))
|
|
52
|
+
return;
|
|
53
|
+
warnedLegacyPaths.add(warningKey);
|
|
54
|
+
const detail = duplicate
|
|
55
|
+
? `both ${canonicalPath} and legacy ${legacyPath} exist; using ${canonicalPath}; remove the legacy file`
|
|
56
|
+
: `legacy path ${legacyPath} is deprecated; move it to ${canonicalPath}`;
|
|
57
|
+
process.stderr.write(`warning: Kata ${id}: ${detail}.\n`);
|
|
58
|
+
}
|
|
59
|
+
export function resolveAuthoredKataPathIfExists(id, kind, extension, rootDir = specdojoRootDir()) {
|
|
60
|
+
const authority = parsePracticeId(id).authority;
|
|
61
|
+
const canonicalPath = authoredKataPath(id, kind, extension);
|
|
62
|
+
const canonicalAbsolutePath = resolve(rootDir, canonicalPath);
|
|
63
|
+
if (!authority || authority === "specdojo") {
|
|
64
|
+
return existsSync(canonicalAbsolutePath)
|
|
65
|
+
? { relativePath: canonicalPath, absolutePath: canonicalAbsolutePath, legacy: false }
|
|
66
|
+
: undefined;
|
|
67
|
+
}
|
|
68
|
+
if (authority !== configuredKataAuthority(rootDir))
|
|
69
|
+
return undefined;
|
|
70
|
+
const legacyPath = legacyAuthoredKataPath(id, kind, extension);
|
|
71
|
+
const legacyAbsolutePath = resolve(rootDir, legacyPath);
|
|
72
|
+
const canonicalExists = existsSync(canonicalAbsolutePath);
|
|
73
|
+
const legacyExists = existsSync(legacyAbsolutePath);
|
|
74
|
+
if (canonicalExists && legacyExists) {
|
|
75
|
+
warnLegacyAuthoredKata(id, canonicalPath, legacyPath, rootDir, true);
|
|
76
|
+
}
|
|
77
|
+
else if (legacyExists) {
|
|
78
|
+
warnLegacyAuthoredKata(id, canonicalPath, legacyPath, rootDir, false);
|
|
79
|
+
}
|
|
80
|
+
if (canonicalExists) {
|
|
81
|
+
return { relativePath: canonicalPath, absolutePath: canonicalAbsolutePath, legacy: false };
|
|
82
|
+
}
|
|
83
|
+
return legacyExists
|
|
84
|
+
? { relativePath: legacyPath, absolutePath: legacyAbsolutePath, legacy: true }
|
|
85
|
+
: undefined;
|
|
86
|
+
}
|
|
87
|
+
export function configuredKataAuthority(rootDir = specdojoRootDir()) {
|
|
88
|
+
return getKataAuthority(loadConfig(rootDir).config, rootDir);
|
|
89
|
+
}
|
|
90
|
+
export function assertAuthorableKataId(id, kind, rootDir = specdojoRootDir()) {
|
|
91
|
+
const parsed = parsePracticeId(id);
|
|
92
|
+
const expectedSuffix = `-${kind}`;
|
|
93
|
+
if (!parsed.localId.endsWith(expectedSuffix)) {
|
|
94
|
+
throw new Error(`Kata id ${id} must end with ${expectedSuffix} for ${kind}-authoring`);
|
|
95
|
+
}
|
|
96
|
+
if (!parsed.authority) {
|
|
97
|
+
throw new Error(`Kata id ${id} must include a repository authority`);
|
|
98
|
+
}
|
|
99
|
+
if (parsed.authority === "specdojo") {
|
|
100
|
+
if (!isSpecdojoSourceRepository(rootDir)) {
|
|
101
|
+
throw new Error(`Kata authority "specdojo" is reserved for the SpecDojo repository; use ${configuredKataAuthority(rootDir)}:${parsed.localId}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const expected = configuredKataAuthority(rootDir);
|
|
106
|
+
if (parsed.authority !== expected) {
|
|
107
|
+
throw new Error(`Kata id ${id} must use this repository's kata_authority "${expected}"`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function dataFileId(path) {
|
|
112
|
+
try {
|
|
113
|
+
const content = readFileSync(path, "utf8");
|
|
114
|
+
const extension = extname(path).toLowerCase();
|
|
115
|
+
if (extension === ".md" || extension === ".mdx") {
|
|
116
|
+
const id = readSpecdojoNamespace(content).id;
|
|
117
|
+
return typeof id === "string" ? id : undefined;
|
|
118
|
+
}
|
|
119
|
+
const parsed = extension === ".json" ? JSON.parse(content) : load(content);
|
|
120
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
121
|
+
return undefined;
|
|
122
|
+
const id = parsed.id;
|
|
123
|
+
return typeof id === "string" ? id : undefined;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function authoredKataExists(id, rootDir = specdojoRootDir()) {
|
|
130
|
+
for (const kind of AUTHORING_KINDS) {
|
|
131
|
+
const extensions = kind === "rulebook" || kind === "recipe" ? ["md"] : ["md", "yaml", "yml", "json"];
|
|
132
|
+
for (const extension of extensions) {
|
|
133
|
+
const resolved = resolveAuthoredKataPathIfExists(id, kind, extension, rootDir);
|
|
134
|
+
if (resolved && dataFileId(resolved.absolutePath) === id)
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
export function authoringStandardId(kind) {
|
|
141
|
+
return `specdojo:${kind}-authoring-standard`;
|
|
142
|
+
}
|
|
143
|
+
export function authoringStandardPath(kind) {
|
|
144
|
+
const path = `docs/ja/specdojo/standards/${kind}-authoring-standard.md`;
|
|
145
|
+
return resolveSpecdojoReferencePathIfExists(path) ?? path;
|
|
146
|
+
}
|
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, authoredKataDirectory, legacyKataKindDirectory, warnLegacyAuthoredKata, } from "./authoring.js";
|
|
6
9
|
export const KATA_RESOURCE_KINDS = [
|
|
7
10
|
"rulebook",
|
|
8
11
|
"standard",
|
|
@@ -121,6 +124,63 @@ 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 canonicalDir = authoredKataDirectory(kind, configuredAuthority);
|
|
132
|
+
const legacyDir = legacyKataKindDirectory(kind);
|
|
133
|
+
const resourcesFrom = (relativeDir) => {
|
|
134
|
+
const absoluteDir = resolve(repositoryRoot, relativeDir);
|
|
135
|
+
return relativeFiles(absoluteDir).flatMap((filePath) => {
|
|
136
|
+
const resolvedPath = resolve(absoluteDir, filePath);
|
|
137
|
+
const id = resourceId(resolvedPath);
|
|
138
|
+
let authority;
|
|
139
|
+
try {
|
|
140
|
+
authority = parsePracticeId(id).authority;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
if (authority !== configuredAuthority)
|
|
146
|
+
return [];
|
|
147
|
+
return [
|
|
148
|
+
{
|
|
149
|
+
id,
|
|
150
|
+
kind,
|
|
151
|
+
ejectable: false,
|
|
152
|
+
relativePath: normalizeRelativePath(join(relativeDir, filePath)),
|
|
153
|
+
repositoryPath: resolvedPath,
|
|
154
|
+
resolvedPath,
|
|
155
|
+
source: "repository",
|
|
156
|
+
state: "ejected",
|
|
157
|
+
difference: "-",
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
const canonical = resourcesFrom(canonicalDir);
|
|
163
|
+
const canonicalIds = new Set(canonical.map((resource) => resource.id));
|
|
164
|
+
const legacy = resourcesFrom(legacyDir).flatMap((resource) => {
|
|
165
|
+
const canonicalPath = normalizeRelativePath(join(canonicalDir, relative(legacyDir, resource.relativePath)));
|
|
166
|
+
const duplicate = canonicalIds.has(resource.id);
|
|
167
|
+
warnLegacyAuthoredKata(resource.id, canonicalPath, resource.relativePath, repositoryRoot, duplicate);
|
|
168
|
+
return duplicate ? [] : [resource];
|
|
169
|
+
});
|
|
170
|
+
return [...canonical, ...legacy];
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function specdojoOwnedResource(resource) {
|
|
174
|
+
if (resource.kind === "standard")
|
|
175
|
+
return true;
|
|
176
|
+
try {
|
|
177
|
+
const authority = parsePracticeId(resource.id).authority;
|
|
178
|
+
return authority === undefined || authority === "specdojo";
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
124
184
|
const ALL_LIST_KINDS = [...KATA_RESOURCE_KINDS, ...KATA_REFERENCED_KINDS];
|
|
125
185
|
function assertKind(kind) {
|
|
126
186
|
if (kind === undefined)
|
|
@@ -136,10 +196,12 @@ export function listKataResources(options = {}) {
|
|
|
136
196
|
const configs = options.all || (kind !== undefined && !isEjectableKind(kind))
|
|
137
197
|
? RESOURCE_KINDS
|
|
138
198
|
: EJECTABLE_KINDS;
|
|
139
|
-
|
|
199
|
+
const bundledAndOverrides = configs
|
|
140
200
|
.filter((config) => kind === undefined || config.kind === kind)
|
|
141
201
|
.flatMap((config) => enumerateConfig(config, options.roots ?? {}))
|
|
142
|
-
.
|
|
202
|
+
.filter(specdojoOwnedResource);
|
|
203
|
+
const authored = enumerateAuthoredResources(options.roots ?? {}).filter((resource) => kind === undefined || resource.kind === kind);
|
|
204
|
+
return [...bundledAndOverrides, ...authored].sort((first, second) => first.kind.localeCompare(second.kind) ||
|
|
143
205
|
first.relativePath.localeCompare(second.relativePath));
|
|
144
206
|
}
|
|
145
207
|
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, resolveAuthoredKataPathIfExists, } 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,13 @@ const KIND_DIR = {
|
|
|
16
18
|
template: "templates",
|
|
17
19
|
};
|
|
18
20
|
function rulebookFsPath(rulebookId) {
|
|
19
|
-
const
|
|
21
|
+
const authority = parsePracticeId(rulebookId).authority;
|
|
22
|
+
if (authority && authority !== "specdojo") {
|
|
23
|
+
const rootDir = specdojoRootDir();
|
|
24
|
+
return (resolveAuthoredKataPathIfExists(rulebookId, "rulebook", "md", rootDir)?.absolutePath ??
|
|
25
|
+
resolve(rootDir, practiceRepoPath("rulebook", rulebookId, "md", rootDir)));
|
|
26
|
+
}
|
|
27
|
+
const relativePath = practiceRepoPath("rulebook", rulebookId, "md");
|
|
20
28
|
return (resolveSpecdojoPathIfExists(relativePath) ??
|
|
21
29
|
specdojoResourceCandidates(relativePath).repositoryPath);
|
|
22
30
|
}
|
|
@@ -53,14 +61,59 @@ function formatExt(targetFormat) {
|
|
|
53
61
|
// Canonical repo-root-relative path (no leading slash): the agent opens these files
|
|
54
62
|
// from the run CWD (repo root or worktree root).
|
|
55
63
|
function repoPath(kind, id, ext) {
|
|
56
|
-
return
|
|
64
|
+
return practiceRepoPath(kind, id, ext);
|
|
65
|
+
}
|
|
66
|
+
function isSpecdojoResourceId(id) {
|
|
67
|
+
const authority = parsePracticeId(id).authority;
|
|
68
|
+
return !authority || authority === "specdojo";
|
|
69
|
+
}
|
|
70
|
+
function kataReferencePath(relativePath, id) {
|
|
71
|
+
if (!isSpecdojoResourceId(id))
|
|
72
|
+
return relativePath;
|
|
73
|
+
return resolveSpecdojoReferencePathIfExists(relativePath) ?? relativePath;
|
|
74
|
+
}
|
|
75
|
+
function kataFsPath(kind, relativePath, id) {
|
|
76
|
+
if (!isSpecdojoResourceId(id)) {
|
|
77
|
+
const rootDir = specdojoRootDir();
|
|
78
|
+
const extension = relativePath.split(".").pop();
|
|
79
|
+
if (extension && ["md", "yaml", "yml", "json"].includes(extension)) {
|
|
80
|
+
return (resolveAuthoredKataPathIfExists(id, kind, extension, rootDir)?.absolutePath ?? resolve(rootDir, relativePath));
|
|
81
|
+
}
|
|
82
|
+
return resolve(rootDir, relativePath);
|
|
83
|
+
}
|
|
84
|
+
return (resolveSpecdojoPathIfExists(relativePath) ??
|
|
85
|
+
specdojoResourceCandidates(relativePath).repositoryPath);
|
|
86
|
+
}
|
|
87
|
+
function practiceRepoPath(kind, id, ext, rootDir = specdojoRootDir()) {
|
|
88
|
+
const authority = parsePracticeId(id).authority;
|
|
89
|
+
const directory = kind === "rulebook" ? "rulebooks" : KIND_DIR[kind];
|
|
90
|
+
if (authority && authority !== "specdojo") {
|
|
91
|
+
if (authority !== configuredKataAuthority(rootDir)) {
|
|
92
|
+
return `${KATA_UNRESOLVABLE_BASE}/${directory}/${practiceLocalId(id)}.${ext}`;
|
|
93
|
+
}
|
|
94
|
+
return authoredKataPath(id, kind).replace(/\.md$/, `.${ext}`);
|
|
95
|
+
}
|
|
96
|
+
return `${DOCS_BASE}/${directory}/${practiceLocalId(id)}.${ext}`;
|
|
97
|
+
}
|
|
98
|
+
const KATA_UNRESOLVABLE_BASE = ".specdojo/unresolvable-kata";
|
|
99
|
+
export function resolveKataDocumentPathIfExists(kind, id, extension, roots = {}) {
|
|
100
|
+
const repositoryRoot = roots.repositoryRoot ?? specdojoRootDir();
|
|
101
|
+
const authority = parsePracticeId(id).authority;
|
|
102
|
+
if (authority && authority !== "specdojo") {
|
|
103
|
+
if (authority !== configuredKataAuthority(repositoryRoot))
|
|
104
|
+
return undefined;
|
|
105
|
+
if (!["md", "yaml", "yml", "json"].includes(extension))
|
|
106
|
+
return undefined;
|
|
107
|
+
return resolveAuthoredKataPathIfExists(id, kind, extension, repositoryRoot)?.absolutePath;
|
|
108
|
+
}
|
|
109
|
+
return resolveSpecdojoPathIfExists(practiceRepoPath(kind, id, extension, repositoryRoot), roots);
|
|
57
110
|
}
|
|
58
111
|
// 宣言 ID は拡張子を持たないため、対象形式を優先しつつ実在する例外形式も解決する。
|
|
59
112
|
// dct-index の YAML 正本に対する Markdown 生成ビュー template などが該当する。
|
|
60
113
|
function declaredRefExt(kind, id, preferredExt) {
|
|
61
114
|
const candidates = kind === "recipe" ? ["md"] : [preferredExt, "md", "yaml", "json"];
|
|
62
115
|
for (const ext of [...new Set(candidates)]) {
|
|
63
|
-
if (
|
|
116
|
+
if (resolveKataDocumentPathIfExists(kind, id, ext))
|
|
64
117
|
return ext;
|
|
65
118
|
}
|
|
66
119
|
return preferredExt;
|
|
@@ -74,8 +127,11 @@ function resolveRef(kind, declaredId, ext) {
|
|
|
74
127
|
return MISSING;
|
|
75
128
|
}
|
|
76
129
|
if (primaryId) {
|
|
77
|
-
const
|
|
78
|
-
|
|
130
|
+
const resolvedExt = declaredRefExt(kind, primaryId, ext);
|
|
131
|
+
const relativePath = !isSpecdojoResourceId(primaryId)
|
|
132
|
+
? (resolveAuthoredKataPathIfExists(primaryId, kind, resolvedExt)?.relativePath ?? repoPath(kind, primaryId, resolvedExt))
|
|
133
|
+
: repoPath(kind, primaryId, resolvedExt);
|
|
134
|
+
return kataReferencePath(relativePath, primaryId);
|
|
79
135
|
}
|
|
80
136
|
return MISSING;
|
|
81
137
|
}
|
|
@@ -93,8 +149,7 @@ export function resolveKataRefs(rulebookId, targetKind) {
|
|
|
93
149
|
const fm = usableRulebookId ? loadRulebookRefs(usableRulebookId) : {};
|
|
94
150
|
return {
|
|
95
151
|
rulebook: usableRulebookId
|
|
96
|
-
? (
|
|
97
|
-
rulebookRepoPath(usableRulebookId))
|
|
152
|
+
? kataReferencePath(rulebookRepoPath(usableRulebookId), usableRulebookId)
|
|
98
153
|
: MISSING,
|
|
99
154
|
recipe: usableRulebookId ? resolveRef("recipe", fm.recipe, "md") : MISSING,
|
|
100
155
|
sample: usableRulebookId
|
|
@@ -107,7 +162,10 @@ export function resolveKataRefs(rulebookId, targetKind) {
|
|
|
107
162
|
}
|
|
108
163
|
// rulebook の repo 相対パス(先頭スラッシュ無し)。
|
|
109
164
|
function rulebookRepoPath(rulebookId) {
|
|
110
|
-
return
|
|
165
|
+
return !isSpecdojoResourceId(rulebookId)
|
|
166
|
+
? (resolveAuthoredKataPathIfExists(rulebookId, "rulebook", "md")?.relativePath ??
|
|
167
|
+
practiceRepoPath("rulebook", rulebookId, "md"))
|
|
168
|
+
: practiceRepoPath("rulebook", rulebookId, "md");
|
|
111
169
|
}
|
|
112
170
|
// 主 rulebook の frontmatter `includes` から、併せて適用する rulebook の宣言順・重複除去済み
|
|
113
171
|
// ID 一覧を返す。自己参照は除外する。単一段のみ(include 先の include はたどらない)。
|
|
@@ -135,7 +193,7 @@ export function resolveIncludedRulebooks(rulebookId) {
|
|
|
135
193
|
}
|
|
136
194
|
return declaredIncludeIds(rulebookId)
|
|
137
195
|
.filter((id) => existsSync(rulebookFsPath(id)))
|
|
138
|
-
.map((id) =>
|
|
196
|
+
.map((id) => kataReferencePath(rulebookRepoPath(id), id));
|
|
139
197
|
}
|
|
140
198
|
// validate 用: 主 rulebook が宣言する include の一覧(実在に関わらず)。
|
|
141
199
|
// 自己参照フラグ付きで返し、呼び出し側で存在・種別を検査する。
|
|
@@ -175,8 +233,7 @@ export function declaredKata(rulebookId) {
|
|
|
175
233
|
out.push({
|
|
176
234
|
kind,
|
|
177
235
|
id,
|
|
178
|
-
fsPath:
|
|
179
|
-
specdojoResourceCandidates(relativePath).repositoryPath,
|
|
236
|
+
fsPath: kataFsPath(kind, relativePath, id),
|
|
180
237
|
});
|
|
181
238
|
}
|
|
182
239
|
};
|
|
@@ -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) {
|
package/dist/register/core.js
CHANGED
|
@@ -241,9 +241,9 @@ export function generatePjrId(existingIds, nextCandidate = defaultPjrCandidate,
|
|
|
241
241
|
}
|
|
242
242
|
export function formatTableRow(item) {
|
|
243
243
|
// frontmatter・本文由来を問わず、表へ展開する全セルを同じ規則で無害化する。
|
|
244
|
-
// 列区切りの
|
|
245
|
-
//
|
|
246
|
-
//
|
|
244
|
+
// 列区切りの `|`、強調記号、改行をエスケープし、素の URL を autolink、山括弧
|
|
245
|
+
// プレースホルダをインラインコード化する。既存の Markdown 記法は変換処理が保持するため、
|
|
246
|
+
// 再生成しても二重に囲まれない。
|
|
247
247
|
const cells = [
|
|
248
248
|
item.id,
|
|
249
249
|
item.status,
|
|
@@ -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
|
+
}
|