@akjamie/agentic-sdlc 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +219 -2
- package/assets/ci/asdlc-ai-review.yml +65 -0
- package/assets/config/config.yaml +76 -0
- package/assets/githooks/post-merge +22 -0
- package/assets/githooks/pre-push +17 -0
- package/assets/policy/policy.yaml +46 -0
- package/assets/schema/schema.yaml +168 -0
- package/assets/schema/templates/design.md +134 -0
- package/assets/schema/templates/proposal.md +25 -0
- package/assets/schema/templates/review.md +24 -0
- package/assets/schema/templates/spec.md +37 -0
- package/assets/schema/templates/tasks.md +10 -0
- package/assets/skills/asdlc-apply/SKILL.md +128 -0
- package/assets/skills/asdlc-approve/SKILL.md +107 -0
- package/assets/skills/asdlc-archive/SKILL.md +49 -0
- package/assets/skills/asdlc-doctor/SKILL.md +82 -0
- package/assets/skills/asdlc-impl-review/SKILL.md +219 -0
- package/assets/skills/asdlc-init/SKILL.md +68 -0
- package/assets/skills/asdlc-lint/SKILL.md +59 -0
- package/assets/skills/asdlc-new/SKILL.md +107 -0
- package/assets/skills/asdlc-pr/SKILL.md +59 -0
- package/assets/skills/asdlc-review/SKILL.md +80 -0
- package/assets/skills/asdlc-spec-review/SKILL.md +206 -0
- package/assets/skills/asdlc-status/SKILL.md +49 -0
- package/assets/skills/asdlc-upgrade/SKILL.md +34 -0
- package/assets/skills/asdlc-verify/SKILL.md +55 -0
- package/assets/skills/batch-grill-me/SKILL.md +136 -0
- package/assets/skills/grilling/SKILL.md +136 -0
- package/bin/asdlc.js +6 -0
- package/package.json +43 -4
- package/src/cli.js +89 -0
- package/src/commands/apply.js +114 -0
- package/src/commands/approve.js +166 -0
- package/src/commands/archive.js +143 -0
- package/src/commands/doctor.js +163 -0
- package/src/commands/init.js +201 -0
- package/src/commands/lint.js +127 -0
- package/src/commands/new.js +171 -0
- package/src/commands/pr.js +495 -0
- package/src/commands/skills.js +184 -0
- package/src/commands/status.js +65 -0
- package/src/commands/test.js +137 -0
- package/src/commands/update.js +103 -0
- package/src/commands/upgrade.js +175 -0
- package/src/commands/verify.js +229 -0
- package/src/index.js +3 -0
- package/src/lib/agents.js +73 -0
- package/src/lib/cliutil.js +99 -0
- package/src/lib/errors.js +18 -0
- package/src/lib/exec.js +23 -0
- package/src/lib/fs.js +83 -0
- package/src/lib/git.js +76 -0
- package/src/lib/graphify.js +106 -0
- package/src/lib/log.js +15 -0
- package/src/lib/openspec.js +91 -0
- package/src/lib/paths.js +43 -0
- package/src/lib/policy.js +60 -0
- package/src/lib/prtype.js +41 -0
- package/src/lib/schema.js +86 -0
- package/src/lib/speclint.js +173 -0
- package/src/lib/tdd.js +71 -0
- package/src/lib/yaml.js +18 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { exists, readText, writeText } from './fs.js';
|
|
4
|
+
import { headSha } from './git.js';
|
|
5
|
+
|
|
6
|
+
// graphify is a BU-standard authoring aid: it builds a code-derived knowledge
|
|
7
|
+
// graph (deterministic AST, no LLM key) that the drafting agent queries for a
|
|
8
|
+
// map of the codebase before writing a spec. It is NOT a gate.
|
|
9
|
+
//
|
|
10
|
+
// The graph is a DERIVED CACHE bound to the current HEAD (graphify-out/), never
|
|
11
|
+
// committed; refreshed when HEAD moves.
|
|
12
|
+
|
|
13
|
+
const GRAPH_REL = 'graphify-out/graph.json';
|
|
14
|
+
const REF_REL = 'graphify-out/.asdlc_ref';
|
|
15
|
+
export const GITIGNORE_LINE = 'graphify-out/';
|
|
16
|
+
|
|
17
|
+
function which(name) {
|
|
18
|
+
const finder = process.platform === 'win32' ? 'where' : 'which';
|
|
19
|
+
const r = spawnSync(finder, [name], { encoding: 'utf8' });
|
|
20
|
+
if (r.status !== 0) return null;
|
|
21
|
+
return r.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0] ?? null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function graphifyAvailable() {
|
|
25
|
+
return Boolean(which('graphify'));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Default-install per the BU standard (uv preferred, else pip). Never throws.
|
|
29
|
+
export function ensureGraphify({ autoInstall = true } = {}) {
|
|
30
|
+
if (graphifyAvailable()) return { installed: true, action: 'present' };
|
|
31
|
+
if (!autoInstall) return { installed: false, action: 'missing' };
|
|
32
|
+
const viaUv = Boolean(which('uv'));
|
|
33
|
+
const cmd = viaUv ? ['uv', 'tool', 'install', '--upgrade', 'graphifyy'] : ['pip', 'install', 'graphifyy'];
|
|
34
|
+
try {
|
|
35
|
+
execFileSync(cmd[0], cmd.slice(1), { encoding: 'utf8', stdio: 'pipe' });
|
|
36
|
+
} catch {
|
|
37
|
+
/* fall through to the availability check */
|
|
38
|
+
}
|
|
39
|
+
return { installed: graphifyAvailable(), action: viaUv ? 'uv-install' : 'pip-install' };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function run(args, cwd) {
|
|
43
|
+
try {
|
|
44
|
+
return { status: 0, stdout: execFileSync('graphify', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }) };
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return { status: e.status ?? 1, stdout: (e.stdout ?? '').toString(), stderr: (e.stderr ?? '').toString() };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function graphExists(repoRoot) {
|
|
51
|
+
return exists(path.join(repoRoot, GRAPH_REL));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function readRef(repoRoot) {
|
|
55
|
+
const p = path.join(repoRoot, REF_REL);
|
|
56
|
+
return exists(p) ? readText(p).trim() : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function writeRef(repoRoot) {
|
|
60
|
+
const sha = headSha(repoRoot);
|
|
61
|
+
if (sha) writeText(path.join(repoRoot, REF_REL), sha);
|
|
62
|
+
return sha;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// missing | stale | fresh (relative to the current HEAD)
|
|
66
|
+
export function graphStatus(repoRoot, head = headSha(repoRoot)) {
|
|
67
|
+
if (!graphExists(repoRoot)) return 'missing';
|
|
68
|
+
if (!head) return 'unknown';
|
|
69
|
+
return readRef(repoRoot) === head ? 'fresh' : 'stale';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// First build: code-only AST (deterministic, no LLM key).
|
|
73
|
+
export function buildGraph(repoRoot) {
|
|
74
|
+
const res = run(['extract', '.', '--code-only'], repoRoot);
|
|
75
|
+
if (res.status === 0) writeRef(repoRoot);
|
|
76
|
+
return res;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Incremental code refresh (no LLM key).
|
|
80
|
+
export function refreshGraph(repoRoot) {
|
|
81
|
+
const res = run(['update', '.'], repoRoot);
|
|
82
|
+
if (res.status === 0) writeRef(repoRoot);
|
|
83
|
+
return res;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Build if missing, refresh if stale for `head`.
|
|
87
|
+
export function ensureFreshGraph(repoRoot, head = headSha(repoRoot)) {
|
|
88
|
+
const status = graphStatus(repoRoot, head);
|
|
89
|
+
if (status === 'missing') return { status, result: buildGraph(repoRoot) };
|
|
90
|
+
if (status === 'stale') return { status, result: refreshGraph(repoRoot) };
|
|
91
|
+
return { status };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function graphifyQuery(repoRoot, question) {
|
|
95
|
+
return run(['query', question], repoRoot);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Idempotently add a line to .gitignore. Returns true if it changed the file.
|
|
99
|
+
export function ensureGitignore(repoRoot, line = GITIGNORE_LINE) {
|
|
100
|
+
const p = path.join(repoRoot, '.gitignore');
|
|
101
|
+
const cur = exists(p) ? readText(p) : '';
|
|
102
|
+
if (cur.split(/\r?\n/).some((l) => l.trim() === line)) return false;
|
|
103
|
+
const sep = cur && !cur.endsWith('\n') ? '\n' : '';
|
|
104
|
+
writeText(p, `${cur}${sep}${line}\n`);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
package/src/lib/log.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const useColor = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
2
|
+
|
|
3
|
+
const paint = (code, text) => (useColor ? `\u001b[${code}m${text}\u001b[0m` : text);
|
|
4
|
+
|
|
5
|
+
export const log = {
|
|
6
|
+
info: (msg = '') => process.stdout.write(`${msg}\n`),
|
|
7
|
+
step: (msg) => process.stdout.write(`${paint(36, '•')} ${msg}\n`),
|
|
8
|
+
ok: (msg) => process.stdout.write(`${paint(32, '\u2713')} ${msg}\n`),
|
|
9
|
+
warn: (msg) => process.stderr.write(`${paint(33, '!')} ${msg}\n`),
|
|
10
|
+
error: (msg) => process.stderr.write(`${paint(31, '\u00d7')} ${msg}\n`),
|
|
11
|
+
plain: (msg) => process.stdout.write(`${msg}\n`),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const dim = (text) => paint(90, text);
|
|
15
|
+
export const bold = (text) => paint(1, text);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { exists } from './fs.js';
|
|
4
|
+
import { runShell } from './exec.js';
|
|
5
|
+
|
|
6
|
+
const isWin = process.platform === 'win32';
|
|
7
|
+
|
|
8
|
+
// PINNED: CI and dev machines must run the same engine version.
|
|
9
|
+
export const OPENSPEC_PINNED = '1.13.2';
|
|
10
|
+
|
|
11
|
+
const quote = (value) => (/[\s"]/.test(value) ? `"${String(value).replace(/"/g, '\\"')}"` : String(value));
|
|
12
|
+
|
|
13
|
+
function exec(file, args, cwd) {
|
|
14
|
+
if (isWin) {
|
|
15
|
+
return spawnSync(`${quote(file)} ${args.map(quote).join(' ')}`, {
|
|
16
|
+
cwd,
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
shell: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return spawnSync(file, args, { cwd, encoding: 'utf8' });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function localBin(cwd, name) {
|
|
25
|
+
const candidates = [
|
|
26
|
+
path.join(cwd, 'node_modules', '.bin', isWin ? `${name}.cmd` : name),
|
|
27
|
+
path.join(cwd, 'node_modules', '.bin', name),
|
|
28
|
+
];
|
|
29
|
+
return candidates.find((p) => exists(p)) ?? null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function which(name) {
|
|
33
|
+
const finder = isWin ? 'where' : 'which';
|
|
34
|
+
const res = spawnSync(finder, [name], { encoding: 'utf8' });
|
|
35
|
+
if (res.status !== 0) return null;
|
|
36
|
+
const lines = res.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
|
|
37
|
+
if (!lines.length) return null;
|
|
38
|
+
if (isWin) return lines.find((l) => l.toLowerCase().endsWith('.cmd')) ?? lines[0];
|
|
39
|
+
return lines[0];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function findOpenspec(cwd) {
|
|
43
|
+
const local = localBin(cwd, 'openspec');
|
|
44
|
+
if (local) return { file: local, kind: 'local' };
|
|
45
|
+
const global = which('openspec');
|
|
46
|
+
if (global) return { file: global, kind: 'global' };
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function runOpenspec(args, cwd) {
|
|
51
|
+
const found = findOpenspec(cwd);
|
|
52
|
+
if (!found) {
|
|
53
|
+
return { status: 127, stdout: '', stderr: 'openspec not found', missing: true };
|
|
54
|
+
}
|
|
55
|
+
const res = exec(found.file, args, cwd);
|
|
56
|
+
return {
|
|
57
|
+
status: res.status ?? 1,
|
|
58
|
+
stdout: res.stdout ?? '',
|
|
59
|
+
stderr: res.stderr ?? '',
|
|
60
|
+
missing: false,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function openspecVersion(cwd) {
|
|
65
|
+
const res = runOpenspec(['--version'], cwd);
|
|
66
|
+
return res.status === 0 ? res.stdout.trim() : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Install OpenSpec as a repo devDependency (pinned) when the CLI is absent.
|
|
70
|
+
// Works for any repo - creates a package.json first when needed - so
|
|
71
|
+
// `asdlc init` is fully self-contained (req: init includes openspec install).
|
|
72
|
+
export function ensureOpenspec(repoRoot) {
|
|
73
|
+
if (openspecVersion(repoRoot)) return { installed: true, action: 'present' };
|
|
74
|
+
|
|
75
|
+
if (!exists(path.join(repoRoot, 'package.json'))) {
|
|
76
|
+
runShell('npm init -y', repoRoot);
|
|
77
|
+
}
|
|
78
|
+
const res = runShell(
|
|
79
|
+
`npm install --save-dev @fission-ai/openspec@${OPENSPEC_PINNED} --no-audit --no-fund`,
|
|
80
|
+
repoRoot,
|
|
81
|
+
);
|
|
82
|
+
const installed = Boolean(openspecVersion(repoRoot));
|
|
83
|
+
return { installed, action: 'npm-install', status: res.status, stderr: (res.stderr || '').slice(0, 300) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function validateChange(cwd, { strict = true, all = true } = {}) {
|
|
87
|
+
const args = ['validate'];
|
|
88
|
+
if (all) args.push('--all');
|
|
89
|
+
if (strict) args.push('--strict');
|
|
90
|
+
return runOpenspec(args, cwd);
|
|
91
|
+
}
|
package/src/lib/paths.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { exists, findUp } from './fs.js';
|
|
4
|
+
|
|
5
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
export const packageRoot = path.resolve(here, '..', '..');
|
|
8
|
+
export const assetsDir = path.join(packageRoot, 'assets');
|
|
9
|
+
export const configAssetFile = path.join(assetsDir, 'config', 'config.yaml');
|
|
10
|
+
export const ciAssetDir = path.join(assetsDir, 'ci');
|
|
11
|
+
export const githooksAssetDir = path.join(assetsDir, 'githooks');
|
|
12
|
+
export const policyAssetFile = path.join(assetsDir, 'policy', 'policy.yaml');
|
|
13
|
+
export const skillsAssetDir = path.join(assetsDir, 'skills');
|
|
14
|
+
|
|
15
|
+
// The BU-managed OpenSpec schema: installed ONCE per machine into OpenSpec's
|
|
16
|
+
// global schemas dir. Repos carry NO copy and must not override it.
|
|
17
|
+
// The schema NAME (agentic-repo-change) lives in schema.yaml, not the path.
|
|
18
|
+
export const SCHEMA_NAME = 'agentic-repo-change';
|
|
19
|
+
export const schemaAssetDir = path.join(assetsDir, 'schema');
|
|
20
|
+
|
|
21
|
+
// We REUSE OpenSpec's engine: the default schema, not a fork.
|
|
22
|
+
export const DEFAULT_SCHEMA = 'spec-driven';
|
|
23
|
+
|
|
24
|
+
export const OPENSPEC_DIR = 'openspec';
|
|
25
|
+
export const CHANGES_DIR = 'changes';
|
|
26
|
+
export const SPECS_DIR = 'specs';
|
|
27
|
+
|
|
28
|
+
export function findRepoRoot(start = process.cwd()) {
|
|
29
|
+
return findUp(start, (dir) => exists(path.join(dir, '.git')) || exists(path.join(dir, OPENSPEC_DIR)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function resolveRepoRoot(opts = {}) {
|
|
33
|
+
if (opts.repoRoot) return path.resolve(opts.repoRoot);
|
|
34
|
+
return findRepoRoot(process.cwd()) ?? process.cwd();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function openspecDir(repoRoot) {
|
|
38
|
+
return path.join(repoRoot, OPENSPEC_DIR);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function changeDir(repoRoot, changeId) {
|
|
42
|
+
return path.join(openspecDir(repoRoot), CHANGES_DIR, changeId);
|
|
43
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { exists } from './fs.js';
|
|
3
|
+
import { readYaml } from './yaml.js';
|
|
4
|
+
|
|
5
|
+
// Platform-owned strategy file (v6 7.3). Loaded from .sdlc/policy.yaml.
|
|
6
|
+
export const POLICY_REL = '.sdlc/policy.yaml';
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_POLICY = {
|
|
9
|
+
locked_paths: ['openspec/changes/*/proposal.md', 'openspec/changes/*/specs/**'],
|
|
10
|
+
controlled: ['openspec/changes/*/design.md'],
|
|
11
|
+
fast_path: { allow_paths: ['docs/**'], allow_kinds: [] },
|
|
12
|
+
reviewers: { spec: null, design: null },
|
|
13
|
+
ai_review: { trigger: 'on-ready-and-push', debounce_seconds: 120 },
|
|
14
|
+
rollout_mode: {},
|
|
15
|
+
web_search: 'allow',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function deepMerge(base, over) {
|
|
19
|
+
const out = { ...base };
|
|
20
|
+
for (const [k, v] of Object.entries(over ?? {})) {
|
|
21
|
+
const a = base[k];
|
|
22
|
+
out[k] = v && typeof v === 'object' && !Array.isArray(v) && a && typeof a === 'object' && !Array.isArray(a)
|
|
23
|
+
? deepMerge(a, v) : v;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function loadPolicy(repoRoot) {
|
|
29
|
+
const p = path.join(repoRoot, POLICY_REL);
|
|
30
|
+
if (!exists(p)) return { ...DEFAULT_POLICY };
|
|
31
|
+
try {
|
|
32
|
+
return deepMerge(DEFAULT_POLICY, readYaml(p) ?? {});
|
|
33
|
+
} catch {
|
|
34
|
+
return { ...DEFAULT_POLICY };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Gitignore-style glob: * = within a segment, ** = across segments.
|
|
39
|
+
export function globToRe(glob) {
|
|
40
|
+
const s = String(glob)
|
|
41
|
+
.replace(/[.+^${}()|[\]\\?]/g, '\\$&')
|
|
42
|
+
.replace(/\*\*/g, '\u0000')
|
|
43
|
+
.replace(/\*/g, '[^/]*')
|
|
44
|
+
.replace(/\u0000/g, '.*');
|
|
45
|
+
return new RegExp(`^${s}$`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function matchesAny(p, globs = []) {
|
|
49
|
+
return globs.some((g) => globToRe(g).test(p));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// rollout_mode: checkName -> 'block' | 'advisory'. Missing => block.
|
|
53
|
+
export function isAdvisory(policy, checkName) {
|
|
54
|
+
return policy?.rollout_mode?.[checkName] === 'advisory';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Web-search policy egress guard: enabled by default ('allow'), blocked only when explicitly 'deny'.
|
|
58
|
+
export function canWebSearch(policy) {
|
|
59
|
+
return policy?.web_search !== 'deny';
|
|
60
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { matchesAny } from './policy.js';
|
|
2
|
+
|
|
3
|
+
// PR type is determined by PATHS ONLY (v6 7.1), never by labels or declarations.
|
|
4
|
+
const CHANGE = /^openspec\/changes\/([^/]+)\//;
|
|
5
|
+
const SPECS = /^openspec\/specs\//;
|
|
6
|
+
|
|
7
|
+
export function changeIdOf(pathname) {
|
|
8
|
+
const m = String(pathname).match(CHANGE);
|
|
9
|
+
return m ? m[1] : null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// -> { type, reason } where type is one of:
|
|
13
|
+
// spec | impl | archive | fast | emergency | normal | invalid
|
|
14
|
+
export function classifyPR({ changedFiles = [], changeOnMain = false, policy, emergency = false } = {}) {
|
|
15
|
+
const files = changedFiles.filter(Boolean);
|
|
16
|
+
if (emergency) return { type: 'emergency', reason: 'marked emergency' };
|
|
17
|
+
|
|
18
|
+
const changeFiles = files.filter((f) => CHANGE.test(f));
|
|
19
|
+
const outside = files.filter((f) => !CHANGE.test(f));
|
|
20
|
+
|
|
21
|
+
if (files.length > 0 && changeFiles.length === 0
|
|
22
|
+
&& files.every((f) => matchesAny(f, policy?.fast_path?.allow_paths ?? []))) {
|
|
23
|
+
return { type: 'fast', reason: 'all paths in fast_path.allow_paths' };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const archiveOnly = files.length > 0
|
|
27
|
+
&& files.every((f) => CHANGE.test(f) || SPECS.test(f))
|
|
28
|
+
&& files.some((f) => SPECS.test(f));
|
|
29
|
+
if (archiveOnly) return { type: 'archive', reason: 'change dir + specs merge only' };
|
|
30
|
+
|
|
31
|
+
if (changeFiles.length > 0 && !changeOnMain) {
|
|
32
|
+
// First spec PR must contain the change dir ONLY - no source alongside.
|
|
33
|
+
return outside.length === 0
|
|
34
|
+
? { type: 'spec', reason: 'new change dir, no source' }
|
|
35
|
+
: { type: 'invalid', reason: 'first PR mixes spec files and source; split it' };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (changeFiles.length > 0 && changeOnMain) return { type: 'impl', reason: 'existing change dir + source/tasks' };
|
|
39
|
+
if (outside.length > 0) return { type: 'normal', reason: 'no change dir (outside the SDD flow)' };
|
|
40
|
+
return { type: 'normal', reason: files.length === 0 ? 'no changes' : 'unclassified' };
|
|
41
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import { exists, ensureDir, copyTree, removeDir, readText } from './fs.js';
|
|
4
|
+
import { parseYaml } from './yaml.js';
|
|
5
|
+
import { schemaAssetDir, SCHEMA_NAME } from './paths.js';
|
|
6
|
+
import { isPathTracked } from './git.js';
|
|
7
|
+
|
|
8
|
+
// Mirror OpenSpec's getGlobalDataDir() exactly (dist/core/global-config.js) so
|
|
9
|
+
// we install into the directory OpenSpec resolves "user override" schemas from.
|
|
10
|
+
export function globalDataDir(env = process.env, platform = os.platform(), homedir = os.homedir()) {
|
|
11
|
+
const join = platform === 'win32' ? path.win32.join : path.posix.join;
|
|
12
|
+
if (env.XDG_DATA_HOME) return join(env.XDG_DATA_HOME, 'openspec');
|
|
13
|
+
if (platform === 'win32') {
|
|
14
|
+
if (env.LOCALAPPDATA) return join(env.LOCALAPPDATA, 'openspec');
|
|
15
|
+
return join(homedir, 'AppData', 'Local', 'openspec');
|
|
16
|
+
}
|
|
17
|
+
return join(homedir, '.local', 'share', 'openspec');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function globalSchemasDir(opts = {}) {
|
|
21
|
+
const env = opts.env ?? process.env;
|
|
22
|
+
const platform = opts.platform ?? os.platform();
|
|
23
|
+
const homedir = opts.homedir ?? os.homedir();
|
|
24
|
+
return path.join(globalDataDir(env, platform, homedir), 'schemas');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function installedSchemaDir(opts = {}) {
|
|
28
|
+
return path.join(globalSchemasDir(opts), SCHEMA_NAME);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Install the BU-managed schema ONCE per machine (not per repo).
|
|
32
|
+
export function installSchema(opts = {}) {
|
|
33
|
+
const dest = installedSchemaDir(opts);
|
|
34
|
+
removeDir(dest); // always replace -> no stale half-copies
|
|
35
|
+
ensureDir(globalSchemasDir(opts));
|
|
36
|
+
copyTree(schemaAssetDir, dest);
|
|
37
|
+
return dest;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function readInstalledVersion(opts = {}) {
|
|
41
|
+
const p = path.join(installedSchemaDir(opts), 'schema.yaml');
|
|
42
|
+
if (!exists(p)) return null;
|
|
43
|
+
const parsed = parseYaml(readText(p)) ?? {};
|
|
44
|
+
return parsed.version != null ? String(parsed.version) : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The version bundled with THIS asdlc package (the source of truth to install).
|
|
48
|
+
export function builtinSchemaVersion() {
|
|
49
|
+
const p = path.join(schemaAssetDir, 'schema.yaml');
|
|
50
|
+
if (!exists(p)) return null;
|
|
51
|
+
const parsed = parseYaml(readText(p)) ?? {};
|
|
52
|
+
return parsed.version != null ? String(parsed.version) : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A project-local copy of the managed schema SHADOWS the central one, because
|
|
56
|
+
// OpenSpec resolves project > user > package. The BU forbids local overrides.
|
|
57
|
+
export function localOverride(repoRoot) {
|
|
58
|
+
const rel = `openspec/schemas/${SCHEMA_NAME}`;
|
|
59
|
+
const present = exists(path.join(repoRoot, rel));
|
|
60
|
+
return { present, tracked: present ? isPathTracked(repoRoot, rel) : false, path: rel };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The gate check: schema installed centrally, version matches the repo pin,
|
|
64
|
+
// and NOT overridden by a committed local copy.
|
|
65
|
+
export function checkSchema(repoRoot, { expectedVersion = null, ...opts } = {}) {
|
|
66
|
+
const override = localOverride(repoRoot);
|
|
67
|
+
if (override.tracked) {
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
reason: `local schema override detected: ${override.path} is committed and shadows the BU-managed schema`,
|
|
71
|
+
hint: 'remove openspec/schemas/' + SCHEMA_NAME + ' and run `asdlc init`',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const installed = readInstalledVersion(opts);
|
|
75
|
+
if (!installed) {
|
|
76
|
+
return { ok: false, reason: 'BU-managed schema not installed on this machine', hint: 'run `asdlc init`' };
|
|
77
|
+
}
|
|
78
|
+
if (expectedVersion && installed !== String(expectedVersion)) {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
reason: `schema version mismatch: machine has v${installed}, repo pins v${expectedVersion}`,
|
|
82
|
+
hint: 'run `asdlc init`',
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { ok: true, installed, builtin: builtinSchemaVersion(), override };
|
|
86
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Deterministic spec lint harness: enforces BDD + Acceptance Criteria.
|
|
2
|
+
// Pure functions (text -> findings). No LLM => stable, reproducible.
|
|
3
|
+
// The ONLY filesystem access is the optional (test: <path>) existence check,
|
|
4
|
+
// which is enabled by passing `repoRoot`.
|
|
5
|
+
import { exists } from './fs.js';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
//
|
|
8
|
+
// Rules:
|
|
9
|
+
// R0 no-requirements blocker
|
|
10
|
+
// R1 purpose blocker (new capability: ## Purpose >= 50 chars)
|
|
11
|
+
// R2 normative blocker (each Requirement needs SHALL/MUST)
|
|
12
|
+
// R3 scenario blocker (each Requirement needs >= 1 scenario)
|
|
13
|
+
// R4 when/then/given blocker/major (BDD shape)
|
|
14
|
+
// R5 ac blocker (each Requirement needs >= 1 AC<n>)
|
|
15
|
+
// R6 ac-test blocker (each AC needs a (test: <path>) mapping)
|
|
16
|
+
// R7 test-strategy blocker (## Test Strategy present)
|
|
17
|
+
// R8 removed-reason major (REMOVED requires **Reason**)
|
|
18
|
+
|
|
19
|
+
const REQ_HEAD = /^###\s+Requirement:\s*(.+?)\s*$/;
|
|
20
|
+
const SCEN_HEAD = /^####\s+Scenario:\s*(.+?)\s*$/;
|
|
21
|
+
const SEC_HEAD = /^##\s+(.+?)\s*$/;
|
|
22
|
+
const OPERATIONS = /^##\s+(ADDED|MODIFIED|REMOVED|RENAMED)\s+Requirements\s*$/;
|
|
23
|
+
|
|
24
|
+
function topSection(text, name) {
|
|
25
|
+
const lines = text.split('\n');
|
|
26
|
+
const re = new RegExp(`^##\\s+${name}\\s*$`, 'i');
|
|
27
|
+
const start = lines.findIndex((l) => re.test(l));
|
|
28
|
+
if (start < 0) return null;
|
|
29
|
+
const out = [];
|
|
30
|
+
for (let i = start + 1; i < lines.length; i += 1) {
|
|
31
|
+
if (SEC_HEAD.test(lines[i])) break;
|
|
32
|
+
out.push(lines[i]);
|
|
33
|
+
}
|
|
34
|
+
return out.join('\n');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function requirements(text) {
|
|
38
|
+
const out = [];
|
|
39
|
+
let section = null;
|
|
40
|
+
let cur = null;
|
|
41
|
+
for (const line of text.split('\n')) {
|
|
42
|
+
if (SEC_HEAD.test(line)) {
|
|
43
|
+
if (cur) { out.push(cur); cur = null; }
|
|
44
|
+
const op = line.match(OPERATIONS);
|
|
45
|
+
if (op) section = op[1];
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const r = line.match(REQ_HEAD);
|
|
49
|
+
if (r) {
|
|
50
|
+
if (cur) out.push(cur);
|
|
51
|
+
cur = { name: r[1], section, text: [] };
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (cur) cur.text.push(line);
|
|
55
|
+
}
|
|
56
|
+
if (cur) out.push(cur);
|
|
57
|
+
return out.map((r) => ({ ...r, body: r.text.join('\n') }));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function scenarios(body) {
|
|
61
|
+
const out = [];
|
|
62
|
+
let cur = null;
|
|
63
|
+
for (const line of body.split('\n')) {
|
|
64
|
+
const s = line.match(SCEN_HEAD);
|
|
65
|
+
if (s) {
|
|
66
|
+
if (cur) out.push(cur);
|
|
67
|
+
cur = { name: s[1], text: [] };
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (cur) cur.text.push(line);
|
|
71
|
+
}
|
|
72
|
+
if (cur) out.push(cur);
|
|
73
|
+
return out.map((s) => ({ name: s.name, text: s.text.join('\n') }));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function acceptanceCriteria(body) {
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const line of body.split('\n')) {
|
|
79
|
+
const m = line.match(/^\s*-\s*\[[ xX]\]\s*(AC\d+)\s*:\s*(.+)$/);
|
|
80
|
+
if (!m) continue;
|
|
81
|
+
const t = line.match(/\(test:\s*([^)]+?)\s*\)/i);
|
|
82
|
+
out.push({ id: m[1], text: m[2].replace(/\(test:.*$/i, '').trim(), test: t ? t[1].trim() : null });
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function sortFindings(a, b) {
|
|
88
|
+
const key = (x) => `${x.location}||${x.code}||${x.message}`;
|
|
89
|
+
return key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Policy-as-code: severities are configurable per repo (openspec/config.yaml
|
|
93
|
+
// -> lint.rules), and the ruleset is versioned so historic changes can be
|
|
94
|
+
// grandfathered instead of silently invalidated by future rule changes.
|
|
95
|
+
export const LINT_VERSION = 2;
|
|
96
|
+
|
|
97
|
+
const DEFAULT_SEVERITY = {
|
|
98
|
+
'R0-no-requirements': 'blocker',
|
|
99
|
+
'R1-purpose': 'blocker',
|
|
100
|
+
'R2-normative': 'blocker',
|
|
101
|
+
'R3-scenario': 'blocker',
|
|
102
|
+
'R4-when': 'blocker',
|
|
103
|
+
'R4-then': 'blocker',
|
|
104
|
+
'R4-given': 'major',
|
|
105
|
+
'R5-ac': 'blocker',
|
|
106
|
+
'R5-scenario-coverage': 'blocker',
|
|
107
|
+
'R6-ac-test': 'blocker',
|
|
108
|
+
'R7-test-strategy': 'blocker',
|
|
109
|
+
'R8-removed-reason': 'major',
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export function lintSpecText(text, { requireGiven = true, repoRoot = null, rules = {} } = {}) {
|
|
113
|
+
const findings = [];
|
|
114
|
+
const add = (code, rawSeverity, message, location = '') => {
|
|
115
|
+
const configured = rules[code] ?? DEFAULT_SEVERITY[code] ?? rawSeverity;
|
|
116
|
+
if (configured === 'off') return;
|
|
117
|
+
findings.push({ code, severity: configured, location, message });
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const hasAdded = /^##\s+ADDED\s+Requirements\s*$/m.test(text);
|
|
121
|
+
const purpose = topSection(text, 'Purpose') ?? '';
|
|
122
|
+
if (hasAdded && purpose.trim().length < 50) {
|
|
123
|
+
add('R1-purpose', 'blocker', 'Purpose missing or shorter than 50 characters', '## Purpose');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if ((topSection(text, 'Test Strategy') ?? '').trim().length === 0) {
|
|
127
|
+
add('R7-test-strategy', 'blocker', 'Missing or empty ## Test Strategy', '## Test Strategy');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const reqs = requirements(text);
|
|
131
|
+
if (reqs.length === 0) add('R0-no-requirements', 'blocker', 'No "### Requirement:" found', '');
|
|
132
|
+
|
|
133
|
+
for (const r of reqs) {
|
|
134
|
+
if (r.section === 'REMOVED') {
|
|
135
|
+
if (!/\*\*Reason\*\*/.test(r.body)) add('R8-removed-reason', 'major', `REMOVED "${r.name}" lacks **Reason**`, r.name);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (r.section === 'RENAMED') continue;
|
|
139
|
+
if (!/\b(SHALL|MUST)\b/.test(r.body)) add('R2-normative', 'blocker', `"${r.name}" has no SHALL/MUST statement`, r.name);
|
|
140
|
+
|
|
141
|
+
const scens = scenarios(r.body);
|
|
142
|
+
if (scens.length === 0) add('R3-scenario', 'blocker', `"${r.name}" has no Scenario`, r.name);
|
|
143
|
+
for (const s of scens) {
|
|
144
|
+
if (!/\*\*WHEN\*\*/.test(s.text)) add('R4-when', 'blocker', `Scenario "${s.name}" missing WHEN`, `${r.name} / ${s.name}`);
|
|
145
|
+
if (!/\*\*THEN\*\*/.test(s.text)) add('R4-then', 'blocker', `Scenario "${s.name}" missing THEN`, `${r.name} / ${s.name}`);
|
|
146
|
+
if (requireGiven && !/\*\*GIVEN\*\*/.test(s.text)) add('R4-given', 'major', `Scenario "${s.name}" missing GIVEN`, `${r.name} / ${s.name}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const acs = acceptanceCriteria(r.body);
|
|
150
|
+
if (acs.length === 0) {
|
|
151
|
+
add('R5-ac', 'blocker', `"${r.name}" has no Acceptance criteria (AC<n>)`, r.name);
|
|
152
|
+
} else if (scens.length > acs.length) {
|
|
153
|
+
add('R5-scenario-coverage', 'blocker', `"${r.name}" defines ${scens.length} scenario(s) but only ${acs.length} acceptance criteria (each scenario requires AC coverage)`, r.name);
|
|
154
|
+
}
|
|
155
|
+
for (const ac of acs) {
|
|
156
|
+
if (!ac.test) {
|
|
157
|
+
add('R6-ac-test', 'blocker', `"${ac.id}" has no (test: <path>) mapping`, `${r.name} / ${ac.id}`);
|
|
158
|
+
} else if (repoRoot) {
|
|
159
|
+
// "Does the mapping exist" is not enough: the referenced test file must
|
|
160
|
+
// actually exist, otherwise the AC is unverifiable decoration.
|
|
161
|
+
if (!exists(resolve(repoRoot, ac.test))) {
|
|
162
|
+
add('R6-ac-missing-test', 'blocker', `"${ac.id}" maps to a test that does not exist: ${ac.test}`, `${r.name} / ${ac.id}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return findings.sort(sortFindings);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function countBlockers(findings) {
|
|
172
|
+
return findings.filter((f) => f.severity === 'blocker').length;
|
|
173
|
+
}
|