specdojo 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/agents/specdojo-orchestrator.md +165 -0
- package/CHANGELOG.md +280 -0
- package/README.md +92 -42
- package/dist/agent-response.js +20 -0
- package/dist/agent.js +4 -4
- package/dist/build-command.js +28 -8
- package/dist/dashboard.js +122 -1
- package/dist/devcontainer-command.js +43 -0
- package/dist/devcontainer-scaffold.js +165 -0
- package/dist/exec-agent-config.js +107 -9
- package/dist/exec-agent-git-state.js +18 -0
- package/dist/exec-agent-protected-config.js +46 -8
- package/dist/exec-evidence.js +254 -11
- package/dist/exec-handoff.js +336 -0
- package/dist/exec-parent-validation.js +317 -43
- package/dist/exec-pipeline-state.js +74 -9
- package/dist/exec-plans.js +115 -113
- package/dist/exec-protection-handoff.js +43 -2
- package/dist/exec-provider-scaffold.js +247 -15
- package/dist/exec-register-resume.js +65 -19
- package/dist/exec-register.js +9 -3
- package/dist/exec-repo-integration.js +811 -0
- package/dist/exec-repo-trace.js +182 -0
- package/dist/exec-reporter.js +613 -132
- package/dist/exec-results.js +81 -56
- package/dist/exec-run-lock.js +110 -107
- package/dist/exec-run.js +1585 -356
- package/dist/exec-shared.js +7 -0
- package/dist/exec-slot-lock.js +242 -0
- package/dist/exec-task-repos.js +415 -0
- package/dist/exec-trial.js +51 -25
- package/dist/exec-worktree-command.js +87 -43
- package/dist/exec-worktree-ops.js +502 -57
- package/dist/exec-worktree.js +114 -27
- package/dist/exec.js +13 -6
- package/dist/grade-result.js +128 -0
- package/dist/grade.js +809 -72
- package/dist/init-command.js +443 -0
- package/dist/job.js +160 -10
- package/dist/orchestrator.js +213 -0
- package/dist/register-event-merge.js +169 -0
- package/dist/register-item.js +7 -1
- package/dist/register.js +294 -86
- package/dist/review-grade.js +252 -0
- package/dist/review-plan.js +111 -1
- package/dist/review-types.js +40 -1
- package/dist/routine.js +72 -5
- package/dist/schedule-build.js +2 -2
- package/dist/schedule.js +17 -4
- package/dist/specdojo-config.js +465 -19
- package/dist/specdojo-gitignore.js +135 -0
- package/dist/specdojo.js +6 -0
- package/dist/viewpoint-document-kinds-check.js +128 -0
- package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
- package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
- package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
- package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
- package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
- package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
- package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
- package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
- package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
- package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
- package/docs/ja/specdojo/guides/exec-config-guide.md +91 -47
- package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
- package/docs/ja/specdojo/guides/kata-guide.md +4 -4
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +25 -4
- package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
- package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
- package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
- package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
- package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
- package/docs/ja/specdojo/guides/review-guide.md +195 -158
- package/docs/ja/specdojo/guides/routine-operation-guide.md +74 -9
- package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
- package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
- package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
- package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
- package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
- package/docs/ja/specdojo/guides/waza-guide.md +15 -2
- package/docs/ja/specdojo/index.md +2 -2
- package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
- package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
- package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
- package/docs/ja/specdojo/references/command-reference.md +335 -92
- package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
- package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
- package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
- package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
- package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
- package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
- package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
- package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
- package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
- package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
- package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
- package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
- package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
- package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
- package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
- package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
- package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
- package/docs/ja/specdojo/samples/bps-sample.md +74 -21
- package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
- package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
- package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
- package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
- package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
- package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
- package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
- package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
- package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
- package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
- package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
- package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
- package/docs/ja/specdojo/templates/bps-template.md +91 -0
- package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
- package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
- package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
- package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
- package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
- package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
- package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
- package/package.json +15 -9
- package/templates/antigravity/README.md +27 -2
- package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
- package/templates/antigravity/exec-defaults-snippet.yaml +7 -6
- package/templates/antigravity/orchestrator.md +18 -7
- package/templates/antigravity/settings.global.json +55 -0
- package/templates/claude/agents/claude-executor.md +14 -0
- package/templates/claude/agents/claude-reporter.md +16 -0
- package/templates/claude/agents/specdojo-orchestrator.md +18 -7
- package/templates/claude/settings.edit.json +27 -1
- package/templates/codex/README.md +5 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
- package/templates/codex/orchestrator.md +18 -7
- package/templates/copilot/README.md +7 -5
- package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
- package/templates/devcontainer/devcontainer.json +27 -0
- package/templates/devcontainer/emacs/init.el +88 -0
- package/templates/devcontainer/post-create.sh +62 -0
- package/templates/init-agent-members.yaml +200 -0
- package/templates/init-exec-defaults.yaml +72 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
- package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
- package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, posix } from "node:path";
|
|
3
|
+
export const GITIGNORE_HEADER = "# 依存と specdojo の生成物(specdojo config init が追記)";
|
|
4
|
+
export const NODE_MODULES_PATTERN = "node_modules/";
|
|
5
|
+
// このリポジトリの .gitignore と同じ既定の除外。docs/ 配下の配置はすべてこれで覆える。
|
|
6
|
+
// README の導入手順は npm install の直後に config init を実行するため、依存の node_modules/ も含める。
|
|
7
|
+
export const DEFAULT_GITIGNORE_PATTERNS = [
|
|
8
|
+
NODE_MODULES_PATTERN,
|
|
9
|
+
".specdojo/doc-index.json",
|
|
10
|
+
"docs/**/generated/*",
|
|
11
|
+
"!docs/**/generated/.gitkeep",
|
|
12
|
+
"docs/**/execution/exec/.locks/",
|
|
13
|
+
];
|
|
14
|
+
// repo-root 相対の posix パスへ正規化する。リポジトリ外(絶対パス・`..`)や root 自身は
|
|
15
|
+
// 除外対象にできないため undefined を返す。
|
|
16
|
+
function normalizeRepoPath(value) {
|
|
17
|
+
const trimmed = value?.trim();
|
|
18
|
+
if (!trimmed || isAbsolute(trimmed))
|
|
19
|
+
return undefined;
|
|
20
|
+
const normalized = posix.normalize(trimmed.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
21
|
+
if (normalized === "" || normalized === "." || normalized.startsWith(".."))
|
|
22
|
+
return undefined;
|
|
23
|
+
return normalized;
|
|
24
|
+
}
|
|
25
|
+
function isUnderDocs(path) {
|
|
26
|
+
return path === "docs" || path.startsWith("docs/");
|
|
27
|
+
}
|
|
28
|
+
function generatedPatternsFor(root) {
|
|
29
|
+
return [`${root}/**/generated/*`, `!${root}/**/generated/.gitkeep`];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Derive the .gitignore lines that keep specdojo build outputs untracked for the given layouts.
|
|
33
|
+
* Layouts under docs/ are covered by the defaults; other layouts add patterns derived from
|
|
34
|
+
* base_path, or from each configured path when base_path is absent.
|
|
35
|
+
*/
|
|
36
|
+
export function gitignorePatternsForLayouts(layouts) {
|
|
37
|
+
const patterns = [...DEFAULT_GITIGNORE_PATTERNS];
|
|
38
|
+
const push = (line) => {
|
|
39
|
+
if (!patterns.includes(line))
|
|
40
|
+
patterns.push(line);
|
|
41
|
+
};
|
|
42
|
+
for (const layout of layouts) {
|
|
43
|
+
const base = normalizeRepoPath(layout.basePath);
|
|
44
|
+
const roots = base
|
|
45
|
+
? [base]
|
|
46
|
+
: layout.projectPaths.flatMap((path) => normalizeRepoPath(path) ?? []);
|
|
47
|
+
for (const root of roots) {
|
|
48
|
+
if (isUnderDocs(root))
|
|
49
|
+
continue;
|
|
50
|
+
generatedPatternsFor(root).forEach(push);
|
|
51
|
+
}
|
|
52
|
+
const executionPath = normalizeRepoPath(layout.executionPath);
|
|
53
|
+
if (!executionPath)
|
|
54
|
+
continue;
|
|
55
|
+
const coveredByDefault = isUnderDocs(executionPath) && posix.basename(executionPath) === "execution";
|
|
56
|
+
if (!coveredByDefault)
|
|
57
|
+
push(`${executionPath}/exec/.locks/`);
|
|
58
|
+
}
|
|
59
|
+
return patterns;
|
|
60
|
+
}
|
|
61
|
+
// 既存の .gitignore で node_modules/ と同じ意味(root の node_modules を除外する)になる行。
|
|
62
|
+
const NODE_MODULES_EQUIVALENTS = [
|
|
63
|
+
"node_modules",
|
|
64
|
+
"node_modules/",
|
|
65
|
+
"/node_modules",
|
|
66
|
+
"/node_modules/",
|
|
67
|
+
"**/node_modules",
|
|
68
|
+
"**/node_modules/",
|
|
69
|
+
];
|
|
70
|
+
function isAlreadyPresent(present, pattern) {
|
|
71
|
+
if (present.has(pattern))
|
|
72
|
+
return true;
|
|
73
|
+
if (pattern !== NODE_MODULES_PATTERN)
|
|
74
|
+
return false;
|
|
75
|
+
return NODE_MODULES_EQUIVALENTS.some((line) => present.has(line));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Append the missing patterns to existing .gitignore content. Existing lines are never removed
|
|
79
|
+
* or reordered, and the file's line ending (LF / CRLF) is preserved.
|
|
80
|
+
*/
|
|
81
|
+
export function mergeGitignore(existing, patterns) {
|
|
82
|
+
const present = new Set(existing.split(/\r?\n/).map((line) => line.trim()));
|
|
83
|
+
const added = [];
|
|
84
|
+
const skipped = [];
|
|
85
|
+
for (const pattern of patterns) {
|
|
86
|
+
if (isAlreadyPresent(present, pattern) || added.includes(pattern)) {
|
|
87
|
+
if (!skipped.includes(pattern))
|
|
88
|
+
skipped.push(pattern);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
added.push(pattern);
|
|
92
|
+
}
|
|
93
|
+
if (added.length === 0)
|
|
94
|
+
return { content: existing, added, skipped };
|
|
95
|
+
const eol = existing.includes("\r\n") ? "\r\n" : "\n";
|
|
96
|
+
let content = existing;
|
|
97
|
+
if (content.length > 0 && !content.endsWith("\n"))
|
|
98
|
+
content += eol;
|
|
99
|
+
if (content.length > 0)
|
|
100
|
+
content += eol;
|
|
101
|
+
content += [GITIGNORE_HEADER, ...added].join(eol) + eol;
|
|
102
|
+
return { content, added, skipped };
|
|
103
|
+
}
|
|
104
|
+
/** Read `<repoRoot>/.gitignore`, append the missing patterns and write it back unless dryRun. */
|
|
105
|
+
export function ensureGitignore(repoRoot, patterns, options) {
|
|
106
|
+
const gitignorePath = join(repoRoot, ".gitignore");
|
|
107
|
+
const created = !existsSync(gitignorePath);
|
|
108
|
+
const existing = created ? "" : readFileSync(gitignorePath, "utf8");
|
|
109
|
+
const merged = mergeGitignore(existing, patterns);
|
|
110
|
+
const shouldWrite = !options.dryRun && merged.added.length > 0;
|
|
111
|
+
if (shouldWrite)
|
|
112
|
+
writeFileSync(gitignorePath, merged.content, "utf8");
|
|
113
|
+
return { ...merged, gitignorePath, created, written: shouldWrite };
|
|
114
|
+
}
|
|
115
|
+
export const UNTRACK_IGNORED_COMMAND = "git ls-files -ci --exclude-standard -z | xargs -0 -r git rm -r --cached --quiet";
|
|
116
|
+
/** Human-readable report of an ensureGitignore run, including the untrack guidance. */
|
|
117
|
+
export function formatGitignoreReport(result, dryRun) {
|
|
118
|
+
const lines = [];
|
|
119
|
+
const addVerb = dryRun ? "Would add" : "Added";
|
|
120
|
+
if (result.added.length === 0) {
|
|
121
|
+
lines.push(`.gitignore already excludes node_modules/ and specdojo outputs:${result.gitignorePath}`);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const action = result.created ? (dryRun ? "Would create" : "Created") : "Updated";
|
|
125
|
+
lines.push(`${dryRun ? `${action} (dry-run)` : action}: ${result.gitignorePath}`);
|
|
126
|
+
for (const line of result.added)
|
|
127
|
+
lines.push(` ${addVerb}: ${line}`);
|
|
128
|
+
}
|
|
129
|
+
for (const line of result.skipped)
|
|
130
|
+
lines.push(` Skipped (already present): ${line}`);
|
|
131
|
+
if (result.added.length > 0) {
|
|
132
|
+
lines.push("If node_modules/ or specdojo outputs are already tracked by git, untrack them once and commit:", ` ${UNTRACK_IGNORED_COMMAND}`);
|
|
133
|
+
}
|
|
134
|
+
return lines.join("\n") + "\n";
|
|
135
|
+
}
|
package/dist/specdojo.js
CHANGED
|
@@ -20,6 +20,9 @@ import { registerDashboardCommands } from "./dashboard.js";
|
|
|
20
20
|
import { registerGradeCommand } from "./grade.js";
|
|
21
21
|
import { registerAgentCommands } from "./agent.js";
|
|
22
22
|
import { registerKataCommands } from "./kata-command.js";
|
|
23
|
+
import { registerDevcontainerCommands } from "./devcontainer-command.js";
|
|
24
|
+
import { registerInitCommand } from "./init-command.js";
|
|
25
|
+
import { registerOrchestratorCommands } from "./orchestrator.js";
|
|
23
26
|
/**
|
|
24
27
|
* bin は dist/specdojo.js を指すため、開発チェックアウトで `npm run build` を忘れると
|
|
25
28
|
* 古い挙動のまま実行される。src が dist より新しい場合は警告し、exec 系は中断する。
|
|
@@ -39,6 +42,7 @@ async function main() {
|
|
|
39
42
|
}
|
|
40
43
|
const program = new Command();
|
|
41
44
|
program.name("specdojo").description("SpecDojo helper CLI").version(specdojoPackageVersion());
|
|
45
|
+
registerInitCommand(program);
|
|
42
46
|
registerConfigCommands(program);
|
|
43
47
|
registerProjectCommands(program);
|
|
44
48
|
registerExecCommands(program);
|
|
@@ -57,6 +61,8 @@ async function main() {
|
|
|
57
61
|
registerGradeCommand(program);
|
|
58
62
|
registerAgentCommands(program);
|
|
59
63
|
registerKataCommands(program);
|
|
64
|
+
registerDevcontainerCommands(program);
|
|
65
|
+
registerOrchestratorCommands(program);
|
|
60
66
|
await program.parseAsync(process.argv);
|
|
61
67
|
}
|
|
62
68
|
void main();
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import yaml from "js-yaml";
|
|
5
|
+
// PJR-H220 / PJR-VJP8: 観点の document_kinds は rulebook ID の列挙で宣言する。rulebook を
|
|
6
|
+
// 追加したときに観点ごとの扱いの判断が漏れないよう、include / exclude / confirmed_default の
|
|
7
|
+
// どれにも載っていない rulebook を一覧にする。confirmed_default は判断の記録であり、適用判定
|
|
8
|
+
// (review-plan.ts の viewpointAppliesToDocument)には影響しない。
|
|
9
|
+
export const DEFAULT_VIEWPOINTS_PATH = "docs/ja/specdojo/defaults/pm-review-viewpoints.yaml";
|
|
10
|
+
export const DEFAULT_RULEBOOK_DIR = "docs/ja/specdojo/rulebooks";
|
|
11
|
+
const DECISION_FIELDS = ["include", "exclude", "confirmed_default"];
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function stringList(value) {
|
|
16
|
+
return Array.isArray(value)
|
|
17
|
+
? value.filter((item) => typeof item === "string")
|
|
18
|
+
: [];
|
|
19
|
+
}
|
|
20
|
+
function rulebookIdFromMarkdown(markdown, filePath) {
|
|
21
|
+
const match = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
22
|
+
if (!match)
|
|
23
|
+
return undefined;
|
|
24
|
+
let parsed;
|
|
25
|
+
try {
|
|
26
|
+
parsed = yaml.load(match[1]);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(`Invalid rulebook frontmatter: ${filePath}`, { cause: error });
|
|
30
|
+
}
|
|
31
|
+
const specdojo = isRecord(parsed) && isRecord(parsed["specdojo"]) ? parsed["specdojo"] : {};
|
|
32
|
+
const id = specdojo["id"];
|
|
33
|
+
if (specdojo["type"] !== "rulebook" || typeof id !== "string" || !id.trim())
|
|
34
|
+
return undefined;
|
|
35
|
+
return id;
|
|
36
|
+
}
|
|
37
|
+
/** Collect rulebook IDs from `*-rulebook.md` frontmatter, sorted for stable output. */
|
|
38
|
+
export function collectRulebookIds(rulebookDir = DEFAULT_RULEBOOK_DIR) {
|
|
39
|
+
const ids = readdirSync(rulebookDir)
|
|
40
|
+
.filter((name) => name.endsWith("-rulebook.md"))
|
|
41
|
+
.flatMap((name) => {
|
|
42
|
+
const filePath = path.join(rulebookDir, name);
|
|
43
|
+
const id = rulebookIdFromMarkdown(readFileSync(filePath, "utf8"), filePath);
|
|
44
|
+
return id ? [id] : [];
|
|
45
|
+
});
|
|
46
|
+
return [...new Set(ids)].sort((left, right) => left.localeCompare(right));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A viewpoint that enumerates rulebook IDs in `document_kinds` must decide every rulebook:
|
|
50
|
+
* list it in include / exclude, or record in confirmed_default that the unlisted outcome
|
|
51
|
+
* was reviewed. Viewpoints without any of those lists apply to every kind and are skipped.
|
|
52
|
+
*/
|
|
53
|
+
export function lintViewpointDocumentKinds(viewpointsDoc, rulebookIds) {
|
|
54
|
+
const viewpoints = isRecord(viewpointsDoc) && Array.isArray(viewpointsDoc["viewpoints"])
|
|
55
|
+
? viewpointsDoc["viewpoints"]
|
|
56
|
+
: [];
|
|
57
|
+
const known = new Set(rulebookIds);
|
|
58
|
+
const findings = [];
|
|
59
|
+
for (const viewpoint of viewpoints) {
|
|
60
|
+
if (!isRecord(viewpoint) || typeof viewpoint["id"] !== "string")
|
|
61
|
+
continue;
|
|
62
|
+
const declaration = viewpoint["document_kinds"];
|
|
63
|
+
if (!isRecord(declaration))
|
|
64
|
+
continue;
|
|
65
|
+
if (!DECISION_FIELDS.some((field) => declaration[field] !== undefined))
|
|
66
|
+
continue;
|
|
67
|
+
const viewpointId = viewpoint["id"];
|
|
68
|
+
const decided = new Map();
|
|
69
|
+
for (const field of DECISION_FIELDS) {
|
|
70
|
+
for (const rulebookId of stringList(declaration[field])) {
|
|
71
|
+
decided.set(rulebookId, [...(decided.get(rulebookId) ?? []), field]);
|
|
72
|
+
if (!known.has(rulebookId)) {
|
|
73
|
+
findings.push({ kind: "unknown-rulebook", viewpointId, field, rulebookId });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const [rulebookId, fields] of decided) {
|
|
78
|
+
if (fields.length > 1)
|
|
79
|
+
findings.push({ kind: "duplicate", viewpointId, rulebookId, fields });
|
|
80
|
+
}
|
|
81
|
+
for (const rulebookId of rulebookIds) {
|
|
82
|
+
if (!decided.has(rulebookId))
|
|
83
|
+
findings.push({ kind: "undecided", viewpointId, rulebookId });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return findings;
|
|
87
|
+
}
|
|
88
|
+
export function formatViewpointDocumentKindsFinding(finding) {
|
|
89
|
+
switch (finding.kind) {
|
|
90
|
+
case "undecided":
|
|
91
|
+
return `${finding.viewpointId}: ${finding.rulebookId} is not decided (add it to document_kinds.include / exclude, or to confirmed_default to keep the default)`;
|
|
92
|
+
case "unknown-rulebook":
|
|
93
|
+
return `${finding.viewpointId}: document_kinds.${finding.field} lists unknown rulebook ${finding.rulebookId}`;
|
|
94
|
+
case "duplicate":
|
|
95
|
+
return `${finding.viewpointId}: ${finding.rulebookId} is listed in more than one of document_kinds.${finding.fields.join(" / ")}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Returns error lines; an empty array means every enumerating viewpoint is fully decided. */
|
|
99
|
+
export function checkViewpointDocumentKinds(viewpointsPath = DEFAULT_VIEWPOINTS_PATH, rulebookDir = DEFAULT_RULEBOOK_DIR) {
|
|
100
|
+
const rulebookIds = collectRulebookIds(rulebookDir);
|
|
101
|
+
if (rulebookIds.length === 0) {
|
|
102
|
+
return { rulebookCount: 0, errors: [`No rulebooks found: ${rulebookDir}`] };
|
|
103
|
+
}
|
|
104
|
+
const doc = yaml.load(readFileSync(viewpointsPath, "utf8"));
|
|
105
|
+
const errors = lintViewpointDocumentKinds(doc, rulebookIds).map(formatViewpointDocumentKindsFinding);
|
|
106
|
+
return { rulebookCount: rulebookIds.length, errors };
|
|
107
|
+
}
|
|
108
|
+
function main() {
|
|
109
|
+
const { rulebookCount, errors } = checkViewpointDocumentKinds();
|
|
110
|
+
if (errors.length === 0) {
|
|
111
|
+
process.stdout.write(`${DEFAULT_VIEWPOINTS_PATH}: document_kinds decisions cover all ${rulebookCount} rulebooks\n`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
process.stderr.write(`${DEFAULT_VIEWPOINTS_PATH}: document_kinds decisions are incomplete\n`);
|
|
115
|
+
for (const line of errors)
|
|
116
|
+
process.stderr.write(` - ${line}\n`);
|
|
117
|
+
process.exitCode = 1;
|
|
118
|
+
}
|
|
119
|
+
const invokedPath = process.argv[1];
|
|
120
|
+
if (invokedPath && path.resolve(invokedPath) === fileURLToPath(import.meta.url)) {
|
|
121
|
+
try {
|
|
122
|
+
main();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
process.stderr.write(`viewpoint document_kinds check failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
}
|
|
128
|
+
}
|