@akjamie/agentic-sdlc 0.0.0-stage → 1.0.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/Jenkinsfile +80 -0
- 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 +162 -0
- package/assets/schema/templates/design.md +16 -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 +48 -0
- package/assets/skills/asdlc-doctor/SKILL.md +82 -0
- package/assets/skills/asdlc-impl-review/SKILL.md +214 -0
- package/assets/skills/asdlc-init/SKILL.md +68 -0
- package/assets/skills/asdlc-lint/SKILL.md +56 -0
- package/assets/skills/asdlc-new/SKILL.md +74 -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 +194 -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 +86 -0
- package/src/commands/apply.js +114 -0
- package/src/commands/approve.js +166 -0
- package/src/commands/archive.js +115 -0
- package/src/commands/doctor.js +163 -0
- package/src/commands/init.js +201 -0
- package/src/commands/lint.js +103 -0
- package/src/commands/new.js +142 -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/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 +19 -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 +54 -0
- package/src/lib/prtype.js +41 -0
- package/src/lib/schema.js +86 -0
- package/src/lib/speclint.js +168 -0
- package/src/lib/tdd.js +71 -0
- package/src/lib/yaml.js +18 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { resolveRepoRoot, openspecDir } from './paths.js';
|
|
3
|
+
import { exists, readText } from './fs.js';
|
|
4
|
+
import { readYaml } from './yaml.js';
|
|
5
|
+
import { fail } from './errors.js';
|
|
6
|
+
|
|
7
|
+
export function toChangeSlug(changeId) {
|
|
8
|
+
return String(changeId)
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
11
|
+
.replace(/^-+|-+$/g, '');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function extractRequirementTerms(text) {
|
|
15
|
+
const s = String(text ?? '')
|
|
16
|
+
.replace(/\b[A-Za-z]{2,10}-\d+\b[:\s-]*/g, '')
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replace(/\b(i\s+want\s+to\s+build|i\s+want\s+to\s+add|i\s+want\s+to|we\s+need\s+to|please\s+add|build|create|add|implement)\b/gi, '')
|
|
19
|
+
.replace(/\b(a|an|the|of|for|with|in|on|to|and|by)\b/gi, '')
|
|
20
|
+
.replace(/[^a-z0-9\s]/g, ' ')
|
|
21
|
+
.trim();
|
|
22
|
+
const words = s.split(/\s+/).filter(Boolean);
|
|
23
|
+
return words.slice(0, 5).join(' ');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function deriveChangeSlug(input, opts = {}) {
|
|
27
|
+
if (opts.id) return toChangeSlug(opts.id);
|
|
28
|
+
const text = String(input ?? '').trim();
|
|
29
|
+
if (!text) return 'change';
|
|
30
|
+
|
|
31
|
+
// If already a short alphanumeric ID or slug (e.g. TECH-1234 or rate-limiting) without spaces
|
|
32
|
+
if (!text.includes(' ') && text.length <= 40 && /^[a-zA-Z0-9_-]+$/.test(text)) {
|
|
33
|
+
return toChangeSlug(text);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Extract ticket ID if present (e.g. "TECH-1234: i want to build...")
|
|
37
|
+
const ticketMatch = text.match(/\b([A-Za-z]{2,10}-\d+)\b/);
|
|
38
|
+
const ticket = ticketMatch ? ticketMatch[1].toLowerCase() : null;
|
|
39
|
+
|
|
40
|
+
// Strip filler phrases and ticket prefix
|
|
41
|
+
let cleaned = text
|
|
42
|
+
.replace(/\b[A-Za-z]{2,10}-\d+\b[:\s-]*/g, '')
|
|
43
|
+
.toLowerCase()
|
|
44
|
+
.replace(/\b(i\s+want\s+to\s+build|i\s+want\s+to\s+add|i\s+want\s+to|we\s+need\s+to|please\s+add|build|create|add|implement)\b/gi, '')
|
|
45
|
+
.replace(/\b(a|an|the|of|for|with|in|on|to|and|by)\b/gi, '')
|
|
46
|
+
.trim();
|
|
47
|
+
|
|
48
|
+
if (!cleaned) cleaned = text.toLowerCase();
|
|
49
|
+
|
|
50
|
+
const words = cleaned
|
|
51
|
+
.replace(/[^a-z0-9\s-]/g, ' ')
|
|
52
|
+
.split(/\s+/)
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.slice(0, 4);
|
|
55
|
+
|
|
56
|
+
const keywords = words.join('-');
|
|
57
|
+
if (ticket && keywords) return `${ticket}-${keywords}`.slice(0, 40).replace(/-+$/, '');
|
|
58
|
+
if (ticket) return ticket;
|
|
59
|
+
if (keywords) return keywords.slice(0, 40).replace(/-+$/, '');
|
|
60
|
+
const fallback = toChangeSlug(text).slice(0, 40);
|
|
61
|
+
if (fallback) return fallback;
|
|
62
|
+
|
|
63
|
+
// Non-ASCII fallback (e.g. pure Chinese input): generate deterministic slug from content hash
|
|
64
|
+
const hash = Math.abs(text.split('').reduce((acc, c) => ((acc << 5) - acc) + c.charCodeAt(0), 0)).toString(36);
|
|
65
|
+
return `change-${hash || Date.now().toString(36)}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function requireRepo(opts = {}) {
|
|
69
|
+
const repoRoot = resolveRepoRoot(opts);
|
|
70
|
+
if (!exists(openspecDir(repoRoot))) {
|
|
71
|
+
fail(`no OpenSpec project found at ${repoRoot}`, {
|
|
72
|
+
code: 'NOT_INITIALIZED',
|
|
73
|
+
hint: 'Run `asdlc init` first.',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return repoRoot;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function jsonOut(value) {
|
|
80
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Policy-as-code for the lint harness: severities live in the repo's
|
|
84
|
+
// openspec/config.yaml so a BU can tune policy without forking the tool.
|
|
85
|
+
export function readLintConfig(repoRoot) {
|
|
86
|
+
const cfg = path.join(openspecDir(repoRoot), 'config.yaml');
|
|
87
|
+
const empty = { rules: {}, version: null };
|
|
88
|
+
if (!exists(cfg)) return empty;
|
|
89
|
+
try {
|
|
90
|
+
const parsed = readYaml(cfg) ?? {};
|
|
91
|
+
const lint = parsed.lint ?? {};
|
|
92
|
+
return {
|
|
93
|
+
rules: typeof lint.rules === 'object' && lint.rules !== null ? lint.rules : {},
|
|
94
|
+
version: typeof lint.version === 'string' ? lint.version : null,
|
|
95
|
+
};
|
|
96
|
+
} catch {
|
|
97
|
+
return empty;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class AsdlcError extends Error {
|
|
2
|
+
constructor(message, { code = 'ASDLC_ERROR', exitCode = 1, detail, hint } = {}) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'AsdlcError';
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.exitCode = exitCode;
|
|
7
|
+
this.detail = detail;
|
|
8
|
+
this.hint = hint;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function fail(message, opts) {
|
|
13
|
+
throw new AsdlcError(message, opts);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function assert(condition, message, opts) {
|
|
17
|
+
if (!condition) fail(message, opts);
|
|
18
|
+
}
|
package/src/lib/exec.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
export function runShell(command, cwd, { env = {}, timeout = 600000, input } = {}) {
|
|
4
|
+
const res = spawnSync(command, {
|
|
5
|
+
cwd,
|
|
6
|
+
encoding: 'utf8',
|
|
7
|
+
shell: true,
|
|
8
|
+
timeout,
|
|
9
|
+
env: { ...process.env, ...env },
|
|
10
|
+
input, // optional stdin: feeds prompts to a headless verifier agent
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
status: res.status ?? 1,
|
|
14
|
+
stdout: res.stdout ?? '',
|
|
15
|
+
stderr: res.stderr ?? '',
|
|
16
|
+
failed: res.error != null || res.status === null,
|
|
17
|
+
error: res.error?.message,
|
|
18
|
+
};
|
|
19
|
+
}
|
package/src/lib/fs.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function exists(p) {
|
|
5
|
+
return fs.existsSync(p);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function ensureDir(p) {
|
|
9
|
+
fs.mkdirSync(p, { recursive: true });
|
|
10
|
+
return p;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function readText(p) {
|
|
14
|
+
return fs.readFileSync(p, 'utf8');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function writeText(p, content) {
|
|
18
|
+
ensureDir(path.dirname(p));
|
|
19
|
+
fs.writeFileSync(p, content, 'utf8');
|
|
20
|
+
return p;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function readJson(p) {
|
|
24
|
+
return JSON.parse(readText(p));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function writeJson(p, value) {
|
|
28
|
+
return writeText(p, `${JSON.stringify(value, null, 2)}\n`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function listDir(p) {
|
|
32
|
+
if (!exists(p)) return [];
|
|
33
|
+
return fs.readdirSync(p, { withFileTypes: true });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function copyTree(src, dest) {
|
|
37
|
+
ensureDir(dest);
|
|
38
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
39
|
+
const from = path.join(src, entry.name);
|
|
40
|
+
const to = path.join(dest, entry.name);
|
|
41
|
+
if (entry.isDirectory()) copyTree(from, to);
|
|
42
|
+
else fs.copyFileSync(from, to);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function removeDir(p) {
|
|
47
|
+
if (exists(p)) fs.rmSync(p, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'out', '.next', 'coverage', 'vendor', 'target']);
|
|
51
|
+
|
|
52
|
+
// Recursively list files under `root` as POSIX-style paths relative to root.
|
|
53
|
+
export function walkFiles(root, { maxDepth = 4, limit = 4000 } = {}) {
|
|
54
|
+
const out = [];
|
|
55
|
+
const visit = (dir, depth) => {
|
|
56
|
+
if (out.length >= limit || depth > maxDepth) return;
|
|
57
|
+
let entries;
|
|
58
|
+
try {
|
|
59
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
60
|
+
} catch {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
if (out.length >= limit) return;
|
|
65
|
+
if (entry.isDirectory() && (entry.name.startsWith('.') || SKIP_DIRS.has(entry.name))) continue;
|
|
66
|
+
const full = path.join(dir, entry.name);
|
|
67
|
+
if (entry.isDirectory()) visit(full, depth + 1);
|
|
68
|
+
else out.push(path.relative(root, full).replaceAll('\\', '/'));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
visit(root, 0);
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function findUp(startDir, predicate) {
|
|
76
|
+
let dir = path.resolve(startDir);
|
|
77
|
+
for (;;) {
|
|
78
|
+
if (predicate(dir)) return dir;
|
|
79
|
+
const parent = path.dirname(dir);
|
|
80
|
+
if (parent === dir) return null;
|
|
81
|
+
dir = parent;
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/lib/git.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { exists } from './fs.js';
|
|
3
|
+
|
|
4
|
+
export function git(args, cwd = process.cwd(), { allowFail = false } = {}) {
|
|
5
|
+
try {
|
|
6
|
+
return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
7
|
+
} catch (err) {
|
|
8
|
+
if (allowFail) return null;
|
|
9
|
+
const detail = err.stderr ? String(err.stderr).trim() : err.message;
|
|
10
|
+
throw Object.assign(new Error(detail), { code: 'GIT_ERROR', exitCode: 1 });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isGitRepo(dir) {
|
|
15
|
+
return exists(`${dir}/.git`) && git(['rev-parse', '--is-inside-work-tree'], dir, { allowFail: true }) === 'true';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function headSha(cwd) {
|
|
19
|
+
return git(['rev-parse', 'HEAD'], cwd, { allowFail: true });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function currentBranch(cwd) {
|
|
23
|
+
return git(['rev-parse', '--abbrev-ref', 'HEAD'], cwd, { allowFail: true });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function commitAll(cwd, message) {
|
|
27
|
+
git(['add', '-A'], cwd);
|
|
28
|
+
git(
|
|
29
|
+
['-c', 'user.name=asdlc-bot', '-c', 'user.email=asdlc-bot@example.invalid', 'commit', '-m', message],
|
|
30
|
+
cwd,
|
|
31
|
+
);
|
|
32
|
+
return headSha(cwd);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function tag(cwd, name, { message } = {}) {
|
|
36
|
+
if (message) git(['tag', '-a', name, '-m', message], cwd);
|
|
37
|
+
else git(['tag', name], cwd);
|
|
38
|
+
return name;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// TRUE only when `sha` is an ancestor of `ref` (i.e. actually merged into ref).
|
|
42
|
+
export function isAncestor(cwd, sha, ref) {
|
|
43
|
+
try {
|
|
44
|
+
execFileSync('git', ['merge-base', '--is-ancestor', sha, ref], { cwd, stdio: 'ignore' });
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function commitInfo(cwd, sha) {
|
|
52
|
+
const out = git(['log', '-1', '--format=%an%x09%ae%x09%s', sha], cwd, { allowFail: true });
|
|
53
|
+
if (!out) return null;
|
|
54
|
+
const [name, email, subject] = out.split('\t');
|
|
55
|
+
return { name, email, subject };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// TRUE when `relPath` is committed (tracked) in this repo. Used to distinguish a
|
|
59
|
+
// committed schema copy (an override) from a CI-materialized working-tree copy.
|
|
60
|
+
export function isPathTracked(cwd, relPath) {
|
|
61
|
+
const out = git(['ls-files', '--', relPath], cwd, { allowFail: true });
|
|
62
|
+
return Boolean(out && out.trim());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The last commit on `ref` that touched any of `paths` - this IS the "approved
|
|
66
|
+
// commit" (v6 4): path-limited, so review.md/tasks.md commits never move it.
|
|
67
|
+
export function lastCommitTouching(cwd, ref, paths = []) {
|
|
68
|
+
if (!paths.length) return null;
|
|
69
|
+
return git(['log', '-1', '--format=%H', ref, '--', ...paths], cwd, { allowFail: true }) || null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// TRUE when the change dir already exists on `ref` (so this is a revision/impl,
|
|
73
|
+
// not a first spec PR).
|
|
74
|
+
export function changeOnRef(cwd, ref, slug) {
|
|
75
|
+
return Boolean(git(['log', '-1', '--format=%H', ref, '--', `openspec/changes/${slug}/proposal.md`], cwd, { allowFail: true }));
|
|
76
|
+
}
|
|
@@ -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,54 @@
|
|
|
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
|
+
};
|
|
16
|
+
|
|
17
|
+
function deepMerge(base, over) {
|
|
18
|
+
const out = { ...base };
|
|
19
|
+
for (const [k, v] of Object.entries(over ?? {})) {
|
|
20
|
+
const a = base[k];
|
|
21
|
+
out[k] = v && typeof v === 'object' && !Array.isArray(v) && a && typeof a === 'object' && !Array.isArray(a)
|
|
22
|
+
? deepMerge(a, v) : v;
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function loadPolicy(repoRoot) {
|
|
28
|
+
const p = path.join(repoRoot, POLICY_REL);
|
|
29
|
+
if (!exists(p)) return { ...DEFAULT_POLICY };
|
|
30
|
+
try {
|
|
31
|
+
return deepMerge(DEFAULT_POLICY, readYaml(p) ?? {});
|
|
32
|
+
} catch {
|
|
33
|
+
return { ...DEFAULT_POLICY };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Gitignore-style glob: * = within a segment, ** = across segments.
|
|
38
|
+
export function globToRe(glob) {
|
|
39
|
+
const s = String(glob)
|
|
40
|
+
.replace(/[.+^${}()|[\]\\?]/g, '\\$&')
|
|
41
|
+
.replace(/\*\*/g, '\u0000')
|
|
42
|
+
.replace(/\*/g, '[^/]*')
|
|
43
|
+
.replace(/\u0000/g, '.*');
|
|
44
|
+
return new RegExp(`^${s}$`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function matchesAny(p, globs = []) {
|
|
48
|
+
return globs.some((g) => globToRe(g).test(p));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// rollout_mode: checkName -> 'block' | 'advisory'. Missing => block.
|
|
52
|
+
export function isAdvisory(policy, checkName) {
|
|
53
|
+
return policy?.rollout_mode?.[checkName] === 'advisory';
|
|
54
|
+
}
|
|
@@ -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
|
+
}
|