specdojo 0.4.1 → 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 +39 -0
- package/dist/catalog/build.js +7 -7
- package/dist/catalog/generate.js +27 -12
- package/dist/commands/init.js +26 -7
- package/dist/commands/orchestrator.js +9 -2
- package/dist/dashboard/timeline-build.js +4 -151
- package/dist/devcontainer/command.js +1 -1
- package/dist/devcontainer/scaffold.js +24 -9
- package/dist/exec/core.js +4 -0
- package/dist/exec/events.js +17 -6
- package/dist/exec/plans-core.js +26 -6
- package/dist/exec/plans-generation.js +13 -0
- package/dist/exec/plans-storage.js +15 -3
- 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 +55 -12
- package/dist/register/approach.js +29 -1
- package/dist/register/core.js +3 -2
- package/dist/register/create-commands.js +9 -0
- package/dist/register/cross-project.js +141 -0
- package/dist/register/derivation.js +28 -7
- package/dist/register/external-project.js +136 -0
- package/dist/register/item.js +26 -5
- package/dist/register/register.js +45 -28
- package/dist/schedule/strategy-generate-scope.js +2 -1
- package/dist/schedule/strategy-profiles.js +3 -0
- package/dist/shared/agent-types.js +4 -0
- package/dist/shared/catalog-files.js +31 -0
- package/dist/shared/lefthook-scaffold.js +177 -0
- package/dist/shared/provider-scaffold.js +3 -3
- package/dist/shared/specdojo-config.js +130 -6
- package/dist/shared/timeline-index.js +125 -0
- 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/plan-result-lifecycle-guide.md +4 -2
- package/docs/ja/specdojo/guides/quick-start-guide.md +374 -68
- package/docs/ja/specdojo/guides/register-operation-guide.md +30 -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 +77 -29
- package/docs/ja/specdojo/references/specdojo-config-reference.md +41 -12
- 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 +34 -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/init-agent-members.yaml +3 -3
- package/templates/lefthook/tools/install-lefthook.mjs +46 -0
- package/templates/lefthook/tools/specdojo-pre-commit.mjs +207 -0
- package/templates/opencode/README.md +8 -2
- 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 +60 -6
- /package/dist/{shared → kata}/yaml-schema-modeline.js +0 -0
|
@@ -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);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { gitOutput, gitResult, worktreeStatusPaths } from "../shared/git.js";
|
|
5
|
+
import { loadConfig, resolveExternalProjectRoot, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
6
|
+
const CROSS_PROJECT_TRANSITIONS = new Set([
|
|
7
|
+
"start",
|
|
8
|
+
"wait",
|
|
9
|
+
"review",
|
|
10
|
+
"close",
|
|
11
|
+
"reject",
|
|
12
|
+
"defer",
|
|
13
|
+
"reopen",
|
|
14
|
+
]);
|
|
15
|
+
export function resolveProjectIntegrationBranch(projectId, project) {
|
|
16
|
+
return project.integration_branch?.trim() || `project/${projectId}/develop`;
|
|
17
|
+
}
|
|
18
|
+
function currentBranch(repoRoot) {
|
|
19
|
+
const result = gitResult(repoRoot, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
20
|
+
// register の既存単体利用は Git 初期化前でも許している。branch を読めない場所では
|
|
21
|
+
// current_project へフォールバックし、別 project の記帳を選んだときだけ Git を必須にする。
|
|
22
|
+
if (result.status !== 0)
|
|
23
|
+
return undefined;
|
|
24
|
+
return typeof result.stdout === "string" ? result.stdout.trim() : undefined;
|
|
25
|
+
}
|
|
26
|
+
function worktreeForBranch(repoRoot, branch) {
|
|
27
|
+
const output = gitOutput(repoRoot, ["worktree", "list", "--porcelain"]);
|
|
28
|
+
let path;
|
|
29
|
+
for (const line of output.split(/\r?\n/)) {
|
|
30
|
+
if (line.startsWith("worktree ")) {
|
|
31
|
+
path = resolve(line.slice("worktree ".length));
|
|
32
|
+
}
|
|
33
|
+
else if (line === `branch refs/heads/${branch}`) {
|
|
34
|
+
return path;
|
|
35
|
+
}
|
|
36
|
+
else if (line === "") {
|
|
37
|
+
path = undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
function requireLocalBranch(repoRoot, projectId, branch) {
|
|
43
|
+
const result = gitResult(repoRoot, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]);
|
|
44
|
+
if (result.status === 0)
|
|
45
|
+
return;
|
|
46
|
+
if (result.status === 1) {
|
|
47
|
+
throw new Error(`Integration branch for project ${projectId} does not exist locally: ${branch}`);
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Failed to inspect integration branch for project ${projectId}: ${branch}`);
|
|
50
|
+
}
|
|
51
|
+
function configuredCurrentProject(config, branch) {
|
|
52
|
+
const projectIds = Object.keys(config.projects).sort((left, right) => right.length - left.length);
|
|
53
|
+
if (branch) {
|
|
54
|
+
const exact = projectIds.find((projectId) => resolveProjectIntegrationBranch(projectId, config.projects[projectId]) === branch);
|
|
55
|
+
if (exact)
|
|
56
|
+
return exact;
|
|
57
|
+
const named = projectIds.find((projectId) => branch.startsWith(`feature/${projectId}/`) || branch.startsWith(`exec/${projectId}-`));
|
|
58
|
+
if (named)
|
|
59
|
+
return named;
|
|
60
|
+
}
|
|
61
|
+
return config.current_project?.trim() || projectIds[0];
|
|
62
|
+
}
|
|
63
|
+
export function assertCrossProjectMutationAllowed(command, projectId, commit) {
|
|
64
|
+
if (command !== "add") {
|
|
65
|
+
if (CROSS_PROJECT_TRANSITIONS.has(command)) {
|
|
66
|
+
throw new Error(`Cross-project register ${command} is not supported for ${projectId}. ` +
|
|
67
|
+
`Run the command in the worktree for project ${projectId}.`);
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`Cross-project register ${command} is not supported for ${projectId}. ` +
|
|
70
|
+
`Only register add --project ${projectId} --commit can write to another project.`);
|
|
71
|
+
}
|
|
72
|
+
if (!commit) {
|
|
73
|
+
throw new Error(`Cross-project register add requires --commit so the item is not left in another worktree.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function resolveCrossProjectMutationTarget(command, opts) {
|
|
77
|
+
const projectId = opts.project?.trim();
|
|
78
|
+
if (!projectId)
|
|
79
|
+
return undefined;
|
|
80
|
+
const repoRoot = specdojoRootDir();
|
|
81
|
+
const { config, configPath } = loadConfig(repoRoot);
|
|
82
|
+
if (!config)
|
|
83
|
+
throw new Error(`register commands require specdojo.config.json (${configPath})`);
|
|
84
|
+
const project = config.projects[projectId];
|
|
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
|
+
}
|
|
92
|
+
throw new Error(`Unknown project: ${projectId} (check ${configPath})`);
|
|
93
|
+
}
|
|
94
|
+
const branch = resolveProjectIntegrationBranch(projectId, project);
|
|
95
|
+
const branchNow = currentBranch(repoRoot);
|
|
96
|
+
if (branchNow === branch)
|
|
97
|
+
return undefined;
|
|
98
|
+
if (configuredCurrentProject(config, branchNow) === projectId)
|
|
99
|
+
return undefined;
|
|
100
|
+
assertCrossProjectMutationAllowed(command, projectId, opts.commit);
|
|
101
|
+
requireLocalBranch(repoRoot, projectId, branch);
|
|
102
|
+
return { projectId, branch };
|
|
103
|
+
}
|
|
104
|
+
function removeTemporaryWorktree(repoRoot, path, parent) {
|
|
105
|
+
gitOutput(repoRoot, ["worktree", "remove", path]);
|
|
106
|
+
rmSync(parent, { recursive: true, force: true });
|
|
107
|
+
}
|
|
108
|
+
export async function inCrossProjectWorktree(target, operation) {
|
|
109
|
+
const repoRoot = specdojoRootDir();
|
|
110
|
+
const existing = worktreeForBranch(repoRoot, target.branch);
|
|
111
|
+
const temporaryParent = existing
|
|
112
|
+
? undefined
|
|
113
|
+
: mkdtempSync(join(tmpdir(), `specdojo-register-${target.projectId}-`));
|
|
114
|
+
const worktreePath = existing ?? join(temporaryParent, "worktree");
|
|
115
|
+
if (!existing) {
|
|
116
|
+
try {
|
|
117
|
+
gitOutput(repoRoot, ["worktree", "add", worktreePath, target.branch]);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
rmSync(temporaryParent, { recursive: true, force: true });
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const originalDirectory = process.cwd();
|
|
125
|
+
let succeeded = false;
|
|
126
|
+
try {
|
|
127
|
+
process.chdir(worktreePath);
|
|
128
|
+
const result = await operation();
|
|
129
|
+
succeeded = true;
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
process.chdir(originalDirectory);
|
|
134
|
+
if (temporaryParent && succeeded) {
|
|
135
|
+
removeTemporaryWorktree(repoRoot, worktreePath, temporaryParent);
|
|
136
|
+
}
|
|
137
|
+
else if (temporaryParent && worktreeStatusPaths(worktreePath).length === 0) {
|
|
138
|
+
removeTemporaryWorktree(repoRoot, worktreePath, temporaryParent);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
2
|
+
import { basename, resolve } from "node:path";
|
|
3
|
+
import { gitOutput, gitResult } from "../shared/git.js";
|
|
3
4
|
import { getProjectRegisterPath, loadConfig, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
4
|
-
import { loadRegisterItemDocs, PJR_ID_RE } from "./item.js";
|
|
5
|
+
import { displayIdFromTicketFilename, loadRegisterItemDocs, PJR_ID_RE, } from "./item.js";
|
|
6
|
+
import { resolveProjectIntegrationBranch } from "./cross-project.js";
|
|
5
7
|
const QUALIFIED_REGISTER_ITEM_REF_RE = /^([a-z][a-z0-9-]*):(PJR-[0-9ABCDEFGHJKMNPQRSTVWXYZ]{4})$/;
|
|
6
8
|
export function parseRegisterItemRef(value, currentProjectId) {
|
|
7
9
|
if (PJR_ID_RE.test(value))
|
|
@@ -24,14 +26,35 @@ export function normalizeDerivedFrom(values, options) {
|
|
|
24
26
|
throw new Error("--from must contain a register item ID");
|
|
25
27
|
return refs;
|
|
26
28
|
}
|
|
27
|
-
function configuredItemIds(config, projectId) {
|
|
29
|
+
function configuredItemIds(config, projectId, currentProjectId) {
|
|
28
30
|
const project = config.projects[projectId];
|
|
29
31
|
if (!project)
|
|
30
|
-
|
|
32
|
+
throw new Error(`Cannot verify derived_from item: unknown project ${projectId}`);
|
|
31
33
|
const registerPath = getProjectRegisterPath(project);
|
|
32
34
|
if (!registerPath) {
|
|
33
35
|
throw new Error(`Cannot verify derived_from item in configured project ${projectId}: project_register_path is not set`);
|
|
34
36
|
}
|
|
37
|
+
if (projectId !== currentProjectId) {
|
|
38
|
+
const repoRoot = specdojoRootDir();
|
|
39
|
+
const branch = resolveProjectIntegrationBranch(projectId, project);
|
|
40
|
+
const exists = gitResult(repoRoot, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]);
|
|
41
|
+
if (exists.status !== 0) {
|
|
42
|
+
throw new Error(`Cannot verify derived_from item in project ${projectId}: ` +
|
|
43
|
+
`integration branch does not exist locally: ${branch}`);
|
|
44
|
+
}
|
|
45
|
+
const files = gitOutput(repoRoot, [
|
|
46
|
+
"ls-tree",
|
|
47
|
+
"-r",
|
|
48
|
+
"--name-only",
|
|
49
|
+
branch,
|
|
50
|
+
"--",
|
|
51
|
+
registerPath.replaceAll("\\", "/"),
|
|
52
|
+
]);
|
|
53
|
+
return new Set(files
|
|
54
|
+
.split(/\r?\n/)
|
|
55
|
+
.map((path) => displayIdFromTicketFilename(basename(path)))
|
|
56
|
+
.filter((id) => id !== undefined));
|
|
57
|
+
}
|
|
35
58
|
const absolutePath = resolve(specdojoRootDir(), registerPath);
|
|
36
59
|
return new Set(loadRegisterItemDocs(absolutePath).map((doc) => doc.id));
|
|
37
60
|
}
|
|
@@ -44,11 +67,9 @@ function validateDerivedFromWithConfig(opts, config, idsByProject) {
|
|
|
44
67
|
if (parsed.projectId === opts.projectId && parsed.itemId === opts.itemId) {
|
|
45
68
|
throw new Error(`Item ${opts.itemId} cannot derive from itself`);
|
|
46
69
|
}
|
|
47
|
-
if (!config.projects[parsed.projectId])
|
|
48
|
-
continue;
|
|
49
70
|
let ids = idsByProject.get(parsed.projectId);
|
|
50
71
|
if (!idsByProject.has(parsed.projectId)) {
|
|
51
|
-
ids = configuredItemIds(config, parsed.projectId);
|
|
72
|
+
ids = configuredItemIds(config, parsed.projectId, opts.projectId);
|
|
52
73
|
idsByProject.set(parsed.projectId, ids);
|
|
53
74
|
}
|
|
54
75
|
if (!ids?.has(parsed.itemId)) {
|
|
@@ -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
|
+
}
|
package/dist/register/item.js
CHANGED
|
@@ -96,16 +96,37 @@ export function displayIdFromTicketFilename(filename) {
|
|
|
96
96
|
export function ticketRefCell(filename) {
|
|
97
97
|
return `[${filename.replace(/\.md$/, "")}](./${filename})`;
|
|
98
98
|
}
|
|
99
|
-
//
|
|
100
|
-
|
|
99
|
+
// Markdown のコードスパン。コードとして明示された内容は、表セルでも著者の記法を保持する。
|
|
100
|
+
const MARKDOWN_CODE_SPAN = /(`+)[\s\S]*?\1/g;
|
|
101
|
+
// コードスパン外の未エスケープな強調記号をエスケープする。
|
|
102
|
+
// 記号の直前に偶数個のバックスラッシュがある場合は Markdown 上で未エスケープなので、
|
|
103
|
+
// バックスラッシュを 1 個加える。奇数個なら既にエスケープ済みとして保持する。
|
|
104
|
+
function escapeTableCellEmphasis(text) {
|
|
105
|
+
const escapeSegment = (segment) => segment.replace(/(?<!\\)((?:\\\\)*)[*_]/g, (match) => {
|
|
106
|
+
return `${match.slice(0, -1)}\\${match.slice(-1)}`;
|
|
107
|
+
});
|
|
108
|
+
let result = "";
|
|
109
|
+
let lastIndex = 0;
|
|
110
|
+
for (const match of text.matchAll(MARKDOWN_CODE_SPAN)) {
|
|
111
|
+
const start = match.index ?? 0;
|
|
112
|
+
result += escapeSegment(text.slice(lastIndex, start));
|
|
113
|
+
result += match[0];
|
|
114
|
+
lastIndex = start + match[0].length;
|
|
115
|
+
}
|
|
116
|
+
return result + escapeSegment(text.slice(lastIndex));
|
|
117
|
+
}
|
|
118
|
+
// 表セルへ埋め込むために1行化し、列区切りの `|` と強調記号の `*` / `_` を
|
|
119
|
+
// エスケープする。既存コードスパンとエスケープ済みの記号は保持し、複数回の呼び出しに
|
|
120
|
+
// 対して冪等にする。
|
|
101
121
|
export function toCell(text) {
|
|
102
122
|
if (typeof text !== "string")
|
|
103
123
|
return "";
|
|
104
|
-
|
|
124
|
+
const normalized = text
|
|
105
125
|
.replace(/\r?\n/g, " ")
|
|
106
126
|
.replace(/\s+/g, " ")
|
|
107
127
|
.replace(/(?<!\\)((\\\\)*)\|/g, "$1\\|")
|
|
108
128
|
.trim();
|
|
129
|
+
return escapeTableCellEmphasis(normalized);
|
|
109
130
|
}
|
|
110
131
|
// H1(`# PJR-XXXX タイトル`)からタイトルを導出する。表示 ID の接頭辞は取り除く。
|
|
111
132
|
export function titleFromBody(body, id) {
|
|
@@ -140,10 +161,10 @@ export function descriptionFromBody(body) {
|
|
|
140
161
|
}
|
|
141
162
|
if (paragraph.length === 0)
|
|
142
163
|
return CELL_TODO;
|
|
143
|
-
const text =
|
|
164
|
+
const text = paragraph.join(" ");
|
|
144
165
|
if (text.startsWith(CELL_TODO))
|
|
145
166
|
return CELL_TODO;
|
|
146
|
-
return text;
|
|
167
|
+
return toCell(text);
|
|
147
168
|
}
|
|
148
169
|
// ================================
|
|
149
170
|
// Reading
|
|
@@ -18,6 +18,7 @@ import { applyItemUpdate, assertTerminalOperationAllowed, loadItemForUpdate, upd
|
|
|
18
18
|
import { generateDerivedViewFiles, loadRegisterItems, VALID_BUILD_SCOPES, writeDerivedViews, } from "./views.js";
|
|
19
19
|
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
20
20
|
import { registerLifecyclePoolPath } from "./lifecycle-lock.js";
|
|
21
|
+
import { inCrossProjectWorktree, resolveCrossProjectMutationTarget } from "./cross-project.js";
|
|
21
22
|
export { PJR_ID_ALPHABET, PJR_ID_RE, TERMINAL_STATUSES_SET, toCell, VALID_PRIORITIES, VALID_DIFFICULTIES, VALID_STATUSES, VALID_TYPES, };
|
|
22
23
|
export { REGISTER_TOPIC_RE, VALID_TICKET_STATUSES, buildRegisterItemContent, extractTableHeading, findMarkdownReferenceFiles, generatePjrId, injectRegisterRows, parsePjrIndex, resolveRegisterPaths, } from "./core.js";
|
|
23
24
|
export { applyRegisterMigrationPlan, planRegisterMigration, } from "./migration.js";
|
|
@@ -135,38 +136,54 @@ function commitRegisterMutation(repoRoot, paths, command, result, preexisting, m
|
|
|
135
136
|
throw new Error(`Register commit incomplete: target paths remained dirty after hook stabilization:\n` +
|
|
136
137
|
remaining.map((path) => ` ${path}`).join("\n"));
|
|
137
138
|
}
|
|
139
|
+
async function runRegisterMutationInCurrentWorktree(command, opts, mutate, requireCleanRegister) {
|
|
140
|
+
const paths = resolveRegisterPaths(opts);
|
|
141
|
+
if (!opts.commit || opts.dryRun) {
|
|
142
|
+
mutate({ paths, assertCommitTargetsClean: () => undefined });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const repoRoot = specdojoRootDir();
|
|
146
|
+
if (!paths.executionPath) {
|
|
147
|
+
throw new Error(`Execution path is not configured for project ${paths.projectId}`);
|
|
148
|
+
}
|
|
149
|
+
const mutex = new CrossProcessMutex(registerLifecyclePoolPath(paths.executionPath), {
|
|
150
|
+
actor: registerEventActor(opts),
|
|
151
|
+
label: `register ${command}`,
|
|
152
|
+
}, {
|
|
153
|
+
onWait: () => process.stdout.write("Waiting for the register lifecycle lock held by another operation\n"),
|
|
154
|
+
});
|
|
155
|
+
await mutex.runExclusive(() => {
|
|
156
|
+
const preexisting = new Set(worktreeStatusPaths(repoRoot));
|
|
157
|
+
if (requireCleanRegister) {
|
|
158
|
+
const registerPrefix = `${repoRelative(repoRoot, paths.projectRegisterPath)}/`;
|
|
159
|
+
const dirtyRegisterPaths = [...preexisting].filter((path) => path === registerPrefix.slice(0, -1) || path.startsWith(registerPrefix));
|
|
160
|
+
if (dirtyRegisterPaths.length > 0) {
|
|
161
|
+
throw new Error(`Cannot add to project ${paths.projectId} because its register has uncommitted changes:\n` +
|
|
162
|
+
dirtyRegisterPaths.map((path) => ` ${path}`).join("\n"));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const assertCommitTargetsClean = (targets) => {
|
|
166
|
+
const overlapping = targets
|
|
167
|
+
.map((target) => repoRelative(repoRoot, target))
|
|
168
|
+
.filter((target) => preexisting.has(target));
|
|
169
|
+
if (overlapping.length === 0)
|
|
170
|
+
return;
|
|
171
|
+
throw new Error(`Cannot use --commit because register targets already have uncommitted changes:\n` +
|
|
172
|
+
overlapping.map((path) => ` ${path}`).join("\n"));
|
|
173
|
+
};
|
|
174
|
+
const result = mutate({ paths, assertCommitTargetsClean });
|
|
175
|
+
rebuildRegisterViews(paths);
|
|
176
|
+
commitRegisterMutation(repoRoot, paths, command, result, preexisting, opts.message);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
138
179
|
async function runRegisterMutation(command, opts, mutate) {
|
|
139
180
|
try {
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
|
|
181
|
+
const crossProjectTarget = resolveCrossProjectMutationTarget(command, opts);
|
|
182
|
+
if (crossProjectTarget) {
|
|
183
|
+
await inCrossProjectWorktree(crossProjectTarget, () => runRegisterMutationInCurrentWorktree(command, opts, mutate, true));
|
|
143
184
|
return;
|
|
144
185
|
}
|
|
145
|
-
|
|
146
|
-
if (!paths.executionPath) {
|
|
147
|
-
throw new Error(`Execution path is not configured for project ${paths.projectId}`);
|
|
148
|
-
}
|
|
149
|
-
const mutex = new CrossProcessMutex(registerLifecyclePoolPath(paths.executionPath), {
|
|
150
|
-
actor: registerEventActor(opts),
|
|
151
|
-
label: `register ${command}`,
|
|
152
|
-
}, {
|
|
153
|
-
onWait: () => process.stdout.write("Waiting for the register lifecycle lock held by another operation\n"),
|
|
154
|
-
});
|
|
155
|
-
await mutex.runExclusive(() => {
|
|
156
|
-
const preexisting = new Set(worktreeStatusPaths(repoRoot));
|
|
157
|
-
const assertCommitTargetsClean = (targets) => {
|
|
158
|
-
const overlapping = targets
|
|
159
|
-
.map((target) => repoRelative(repoRoot, target))
|
|
160
|
-
.filter((target) => preexisting.has(target));
|
|
161
|
-
if (overlapping.length === 0)
|
|
162
|
-
return;
|
|
163
|
-
throw new Error(`Cannot use --commit because register targets already have uncommitted changes:\n` +
|
|
164
|
-
overlapping.map((path) => ` ${path}`).join("\n"));
|
|
165
|
-
};
|
|
166
|
-
const result = mutate({ paths, assertCommitTargetsClean });
|
|
167
|
-
rebuildRegisterViews(paths);
|
|
168
|
-
commitRegisterMutation(repoRoot, paths, command, result, preexisting, opts.message);
|
|
169
|
-
});
|
|
186
|
+
await runRegisterMutationInCurrentWorktree(command, opts, mutate, false);
|
|
170
187
|
}
|
|
171
188
|
catch (error) {
|
|
172
189
|
printCommandError(error);
|
|
@@ -2,8 +2,9 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { basename, join, relative, resolve } from "node:path";
|
|
3
3
|
import { collectResolvedDeliverables } from "../catalog/build.js";
|
|
4
4
|
import { resolveBasePath } from "../catalog/paths.js";
|
|
5
|
+
import { collectCatalogFilesByDomain } from "../shared/catalog-files.js";
|
|
5
6
|
import { readYaml } from "../shared/fs.js";
|
|
6
|
-
import {
|
|
7
|
+
import { loadTimelineIndex } from "../shared/timeline-index.js";
|
|
7
8
|
export function isRecord(value) {
|
|
8
9
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
10
|
}
|
|
@@ -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.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { readYaml } from "./fs.js";
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
// 1 ドメインが dct-<domain>-<sub>.yaml のように複数ファイルへ分割されることがあるため、
|
|
8
|
+
// ファイル名ではなく各カタログの domain 値で突き合わせる。
|
|
9
|
+
export function collectCatalogFilesByDomain(catalogPath) {
|
|
10
|
+
const byDomain = new Map();
|
|
11
|
+
if (!existsSync(catalogPath))
|
|
12
|
+
return byDomain;
|
|
13
|
+
const files = readdirSync(catalogPath)
|
|
14
|
+
.filter((file) => /^dct-.+\.ya?ml$/.test(file))
|
|
15
|
+
.sort();
|
|
16
|
+
for (const file of files) {
|
|
17
|
+
const fullPath = join(catalogPath, file);
|
|
18
|
+
const parsed = readYaml(fullPath);
|
|
19
|
+
if (!isRecord(parsed))
|
|
20
|
+
continue;
|
|
21
|
+
const domain = parsed.domain;
|
|
22
|
+
if (typeof domain !== "string" || domain.trim().length === 0)
|
|
23
|
+
continue;
|
|
24
|
+
const group = byDomain.get(domain);
|
|
25
|
+
if (group)
|
|
26
|
+
group.push(fullPath);
|
|
27
|
+
else
|
|
28
|
+
byDomain.set(domain, [fullPath]);
|
|
29
|
+
}
|
|
30
|
+
return byDomain;
|
|
31
|
+
}
|