@akjamie/agentic-sdlc 1.3.0 → 1.5.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.
Files changed (41) hide show
  1. package/README.md +48 -24
  2. package/assets/commands/asdlc-apply.md +24 -0
  3. package/assets/commands/asdlc-approve.md +21 -0
  4. package/assets/commands/asdlc-archive.md +21 -0
  5. package/assets/commands/asdlc-doctor.md +24 -0
  6. package/assets/commands/asdlc-lint.md +30 -0
  7. package/assets/commands/asdlc-new.md +29 -0
  8. package/assets/commands/asdlc-pr.md +25 -0
  9. package/assets/commands/asdlc-status.md +23 -0
  10. package/assets/commands/asdlc-test.md +20 -0
  11. package/assets/commands/asdlc-verify.md +29 -0
  12. package/assets/schema/risk-assessment.schema.json +2 -1
  13. package/assets/skills/asdlc-apply/SKILL.md +1 -1
  14. package/assets/skills/asdlc-approve/SKILL.md +1 -1
  15. package/assets/skills/asdlc-impl-review/SKILL.md +13 -11
  16. package/assets/skills/asdlc-new/SKILL.md +20 -3
  17. package/assets/skills/asdlc-spec-review/SKILL.md +8 -6
  18. package/package.json +1 -1
  19. package/src/assess/ai_judge.js +70 -33
  20. package/src/assess/decide.js +8 -6
  21. package/src/assess/index.js +13 -3
  22. package/src/assess/rules/builtin.js +6 -1
  23. package/src/assess/schema.js +6 -1
  24. package/src/assess/vectors/v1_intent.js +53 -8
  25. package/src/assess/vectors/v3_topology.js +97 -3
  26. package/src/cli.js +1 -1
  27. package/src/commands/apply.js +32 -3
  28. package/src/commands/doctor.js +32 -4
  29. package/src/commands/init.js +5 -55
  30. package/src/commands/lint.js +41 -4
  31. package/src/commands/new.js +23 -22
  32. package/src/commands/skills.js +7 -19
  33. package/src/commands/status.js +170 -9
  34. package/src/commands/test.js +31 -4
  35. package/src/commands/update.js +4 -3
  36. package/src/commands/verify.js +47 -20
  37. package/src/lib/graphify.js +67 -3
  38. package/src/lib/paths.js +1 -0
  39. package/src/lib/speclint.js +5 -3
  40. package/src/lib/tdd.js +6 -2
  41. package/src/lib/tools.js +313 -0
@@ -11,7 +11,7 @@ import { checkSchema } from '../lib/schema.js';
11
11
  import { loadPolicy, isAdvisory, DEFAULT_POLICY, matchesAny } from '../lib/policy.js';
12
12
  import { classifyPR } from '../lib/prtype.js';
13
13
  import { isSinglePrLevel, requiresHumanReview, readChangeLevel, readEffectiveLevel } from '../lib/level.js';
14
- import { assess, renderCheckSummary, loadInitialAssessment } from '../assess/index.js';
14
+ import { assess, renderCheckSummary, loadRiskHistory } from '../assess/index.js';
15
15
  import { checkTestPresence, checkTaskEvidence } from '../lib/tdd.js';
16
16
  import { log, dim } from '../lib/log.js';
17
17
 
@@ -22,15 +22,27 @@ import { log, dim } from '../lib/log.js';
22
22
  function meta(repoRoot, changeId) {
23
23
  const p = path.join(changeDir(repoRoot, toChangeSlug(changeId)), '.openspec.yaml');
24
24
  if (!exists(p)) return {};
25
- const text = readText(p);
26
- const sha = text.match(/^\s*specSha:\s*['"]?([^\s'"]+)['"]?\s*$/m);
27
- const status = text.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
28
- const lvl = text.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
29
- return {
30
- specSha: sha ? sha[1] : null,
31
- status: status ? status[1] : null,
32
- level: lvl ? lvl[1].toUpperCase() : null,
33
- };
25
+ try {
26
+ const data = readYaml(p) ?? {};
27
+ return {
28
+ specSha: data.specSha ? String(data.specSha) : null,
29
+ status: data.status ? String(data.status) : null,
30
+ level: data.level ? String(data.level).toUpperCase() : null,
31
+ escalatedInImpl: data.escalatedInImpl === true || String(data.escalatedInImpl).toLowerCase() === 'true',
32
+ };
33
+ } catch {
34
+ const text = readText(p);
35
+ const sha = text.match(/^\s*specSha:\s*['"]?([^\s'"]+)['"]?\s*$/m);
36
+ const status = text.match(/^\s*status:\s*['"]?([^\s'"]+)['"]?\s*$/m);
37
+ const lvl = text.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
38
+ const esc = text.match(/^\s*escalatedInImpl:\s*['"]?([^\s'"]+)['"]?\s*$/m);
39
+ return {
40
+ specSha: sha ? sha[1] : null,
41
+ status: status ? status[1] : null,
42
+ level: lvl ? lvl[1].toUpperCase() : null,
43
+ escalatedInImpl: esc ? esc[1].toLowerCase() === 'true' : false,
44
+ };
45
+ }
34
46
  }
35
47
 
36
48
  function readYamlConfig(repoRoot) {
@@ -133,15 +145,27 @@ export function runVerify(changeId, opts = {}) {
133
145
  } else {
134
146
  add('level-integrity', 'pass', `conforms to recorded history (${effLevel?.effectiveLevel || 'L1'})`);
135
147
  }
136
- const { specSha, status } = meta(repoRoot, changeId);
137
- const changeLevel = effLevel?.effectiveLevel || meta(repoRoot, changeId).level || null;
148
+ const metaInfo = meta(repoRoot, changeId);
149
+ const { specSha, status } = metaInfo;
150
+ const changeLevel = effLevel?.effectiveLevel || metaInfo.level || null;
138
151
 
139
152
  const changedFiles = (git(['diff', '--name-only', `${base}...${head}`], repoRoot, { allowFail: true }) ?? '')
140
153
  .split(/\r?\n/).filter(Boolean);
141
154
  const changeOnMain = changeOnRef(repoRoot, branch, slug);
142
- const initialAss = loadInitialAssessment(repoRoot, slug);
143
- const wasInitialSinglePr = initialAss && isSinglePrLevel(initialAss.risk?.level);
144
- const isSinglePr = Boolean(wasInitialSinglePr || isSinglePrLevel(changeLevel));
155
+
156
+ // Single-PR privilege applies ONLY if the change is currently L0/L1 OR legitimately entered
157
+ // implementation as L0/L1 and escalated strictly during `impl` (NOT during `new`/`spec`).
158
+ let history = [];
159
+ try { history = loadRiskHistory(repoRoot, slug); } catch { /* handled by readEffectiveLevel */ }
160
+ const preImplRecords = history.filter((r) => r.stage === 'new' || r.stage === 'spec');
161
+ const escalatedOnlyInImpl = Boolean(
162
+ metaInfo.escalatedInImpl ||
163
+ (history.length > 0 &&
164
+ preImplRecords.length > 0 &&
165
+ preImplRecords.every((r) => isSinglePrLevel(r.risk?.level)) &&
166
+ history.some((r) => r.stage === 'impl' && !isSinglePrLevel(r.risk?.level)))
167
+ );
168
+ const isSinglePr = Boolean(isSinglePrLevel(changeLevel) || escalatedOnlyInImpl);
145
169
 
146
170
  const pr = classifyPR({ changedFiles, changeOnMain, policy, emergency: opts.emergency, level: changeLevel, repoRoot, singlePr: isSinglePr });
147
171
  add('pr-type', pr.type === 'invalid' ? 'fail' : 'pass', `type=${pr.type} (${pr.reason})`);
@@ -157,7 +181,7 @@ export function runVerify(changeId, opts = {}) {
157
181
  const approvedSha = lastCommitTouching(repoRoot, branch, lockedPaths);
158
182
  if (effLevel?.tampered) {
159
183
  add('approved-spec', 'fail', 'governance level tampered: declared level is lower than history');
160
- } else if (isSinglePrLevel(changeLevel) || wasInitialSinglePr) {
184
+ } else if (isSinglePr) {
161
185
  add('approved-spec', 'pass', `${changeLevel || 'single-pr'} single-PR mode (spec approval co-located in implementation PR)`);
162
186
  } else if (!approvedSha) {
163
187
  add('approved-spec', 'fail', `no commit on locked paths is merged into ${branch} (not approved)`);
@@ -169,13 +193,13 @@ export function runVerify(changeId, opts = {}) {
169
193
 
170
194
  // Lightweight tamper guard: in a two-phase implementation PR, locked spec files MUST NOT be modified
171
195
  const lockedModified = changedFiles.filter((f) => matchesAny(f, policy?.locked_paths ?? DEFAULT_POLICY.locked_paths));
172
- if (!isSinglePrLevel(changeLevel) && !wasInitialSinglePr && pr.type === 'impl' && lockedModified.length > 0) {
196
+ if (!isSinglePr && pr.type === 'impl' && lockedModified.length > 0) {
173
197
  add('spec-tamper', 'fail', `${lockedModified.length} locked spec file(s) modified in implementation PR (${lockedModified.join(', ')})`);
174
198
  } else {
175
199
  add('spec-tamper', 'pass', 'locked spec paths unmodified');
176
200
  }
177
201
 
178
- if (isSinglePrLevel(changeLevel) || wasInitialSinglePr) {
202
+ if (isSinglePr) {
179
203
  add('flow-state', 'pass', `${changeLevel || 'single-pr'} single-PR mode (direct implementation)`);
180
204
  } else {
181
205
  add('flow-state', status === 'ready_for_impl' ? 'pass' : 'fail',
@@ -197,9 +221,12 @@ export function runVerify(changeId, opts = {}) {
197
221
  });
198
222
 
199
223
  const effectiveLevel = assessment.risk.level;
200
- const isEscalated = assessment.verdict === 'escalated' || (effLevel?.declaredLevel && effLevel.declaredLevel !== effectiveLevel && effectiveLevel !== 'L1');
224
+ const isEscalatedInImpl = Boolean(
225
+ (assessment.reason_codes || []).includes('ESCALATED_IN_IMPL') ||
226
+ (isSinglePr && !isSinglePrLevel(effectiveLevel))
227
+ );
201
228
 
202
- if (isEscalated) {
229
+ if (isEscalatedInImpl) {
203
230
  // Synchronize .openspec.yaml on in-place escalation (local runs only, avoid dirtying tree in CI)
204
231
  const metaPath = path.join(cdir, '.openspec.yaml');
205
232
  if (!isCI && !opts.openingPr && exists(metaPath)) {
@@ -3,9 +3,9 @@ import path from 'node:path';
3
3
  import { exists, readText, writeText } from './fs.js';
4
4
  import { headSha } from './git.js';
5
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.
6
+ // graphify builds a deterministic code-derived AST knowledge graph (no LLM key)
7
+ // used both to ground explore.md before spec authoring and to compute cross-file
8
+ // fan-in / blast-radius centrality in v3_topology risk assessment.
9
9
  //
10
10
  // The graph is a DERIVED CACHE bound to the current HEAD (graphify-out/), never
11
11
  // committed; refreshed when HEAD moves.
@@ -56,6 +56,70 @@ export function readRef(repoRoot) {
56
56
  return exists(p) ? readText(p).trim() : null;
57
57
  }
58
58
 
59
+ /**
60
+ * Loads the Graphify knowledge graph JSON.
61
+ * Returns null if missing or invalid.
62
+ */
63
+ export function loadGraphData(repoRoot) {
64
+ if (!repoRoot) return null;
65
+ const p = path.join(repoRoot, GRAPH_REL);
66
+ if (!exists(p)) return null;
67
+ try {
68
+ return JSON.parse(readText(p));
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ function isNonProdCaller(filePath = '') {
75
+ const norm = String(filePath).replace(/\\/g, '/');
76
+ return (
77
+ /(^|\/)(tests?|__tests__|testing|docs?)\//i.test(norm) ||
78
+ /\.(test|spec)\.[a-z0-9]+$/i.test(norm) ||
79
+ /_test\.go$/i.test(norm) ||
80
+ /(^|\/)test_[^/]+\.py$/i.test(norm) ||
81
+ /_test\.py$/i.test(norm) ||
82
+ /\.(md|txt)$/i.test(norm)
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Calculates cross-file fan-in (inbound dependency count) from Graphify AST.
88
+ * Excludes test/doc callers so test suites do not artificially inflate hub centrality.
89
+ */
90
+ export function getGraphTopologyMetrics(repoRoot) {
91
+ const graph = loadGraphData(repoRoot);
92
+ if (!graph || !Array.isArray(graph.nodes) || !Array.isArray(graph.links)) {
93
+ return { available: false, fileInDegree: {}, topHubs: [] };
94
+ }
95
+
96
+ const nodeToFile = {};
97
+ const fileInDegree = {};
98
+
99
+ for (const n of graph.nodes) {
100
+ if (n.source_file) {
101
+ nodeToFile[n.id] = String(n.source_file).replace(/\\/g, '/');
102
+ }
103
+ }
104
+
105
+ for (const link of graph.links) {
106
+ const targetFile = nodeToFile[link.target];
107
+ const sourceFile = nodeToFile[link.source];
108
+ if (targetFile && sourceFile && targetFile !== sourceFile && !isNonProdCaller(sourceFile)) {
109
+ fileInDegree[targetFile] = (fileInDegree[targetFile] || 0) + 1;
110
+ }
111
+ }
112
+
113
+ const sortedFiles = Object.entries(fileInDegree)
114
+ .sort((a, b) => b[1] - a[1]);
115
+
116
+ return {
117
+ available: true,
118
+ fileInDegree,
119
+ topHubs: sortedFiles.slice(0, 15)
120
+ };
121
+ }
122
+
59
123
  export function writeRef(repoRoot) {
60
124
  const sha = headSha(repoRoot);
61
125
  if (sha) writeText(path.join(repoRoot, REF_REL), sha);
package/src/lib/paths.js CHANGED
@@ -11,6 +11,7 @@ export const ciAssetDir = path.join(assetsDir, 'ci');
11
11
  export const githooksAssetDir = path.join(assetsDir, 'githooks');
12
12
  export const policyAssetFile = path.join(assetsDir, 'policy', 'policy.yaml');
13
13
  export const skillsAssetDir = path.join(assetsDir, 'skills');
14
+ export const commandsAssetDir = path.join(assetsDir, 'commands');
14
15
 
15
16
  // The BU-managed OpenSpec schema: installed ONCE per machine into OpenSpec's
16
17
  // global schemas dir. Repos carry NO copy and must not override it.
@@ -76,9 +76,10 @@ function scenarios(body) {
76
76
  function acceptanceCriteria(body) {
77
77
  const out = [];
78
78
  for (const line of body.split('\n')) {
79
- const m = line.match(/^\s*-\s*\[[ xX]\]\s*(AC\d+)\s*:\s*(.+)$/);
79
+ const trimmed = line.trimEnd();
80
+ const m = trimmed.match(/^\s*-\s*\[[ xX]\]\s*(AC\d+)\s*:\s*(.+)$/);
80
81
  if (!m) continue;
81
- const t = line.match(/\(test:\s*([^)]+?)\s*\)/i);
82
+ const t = trimmed.match(/\(test:\s*([^)]+?)\s*\)/i);
82
83
  out.push({ id: m[1], text: m[2].replace(/\(test:.*$/i, '').trim(), test: t ? t[1].trim() : null });
83
84
  }
84
85
  return out;
@@ -109,7 +110,8 @@ const DEFAULT_SEVERITY = {
109
110
  'R8-removed-reason': 'major',
110
111
  };
111
112
 
112
- export function lintSpecText(text, { requireGiven = true, repoRoot = null, rules = {} } = {}) {
113
+ export function lintSpecText(rawText, { requireGiven = true, repoRoot = null, rules = {} } = {}) {
114
+ const text = String(rawText || '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
113
115
  const findings = [];
114
116
  const add = (code, rawSeverity, message, location = '') => {
115
117
  const configured = rules[code] ?? DEFAULT_SEVERITY[code] ?? rawSeverity;
package/src/lib/tdd.js CHANGED
@@ -3,8 +3,12 @@
3
3
  export function isTestFile(file) {
4
4
  const normalized = String(file).replace(/\\/g, '/');
5
5
  return (
6
- /(?:^|\/)(?:tests?|__tests__|spec)\//i.test(normalized) ||
7
- /\.(?:test|spec)\.[a-zA-Z0-9]+$/i.test(normalized)
6
+ /(?:^|\/)(?:tests?|__tests__|testing|spec|fixtures?|mocks?)\//i.test(normalized) ||
7
+ /\.(?:test|spec)\.[a-zA-Z0-9]+$/i.test(normalized) ||
8
+ /_test\.go$/i.test(normalized) ||
9
+ /test_[^/]+\.py$/i.test(normalized) ||
10
+ /[^/]+_test\.py$/i.test(normalized) ||
11
+ /(?:^|\/).*(?:Test|Tests|TestCase|IT)\.(?:java|kt|scala)$/i.test(normalized)
8
12
  );
9
13
  }
10
14
 
@@ -0,0 +1,313 @@
1
+ import path from 'node:path';
2
+ import { exists, listDir, copyTree, ensureDir, readText, writeText } from './fs.js';
3
+ import { skillsAssetDir, commandsAssetDir } from './paths.js';
4
+ import { log } from './log.js';
5
+
6
+ export const TOOL_REGISTRY = {
7
+ claude: {
8
+ id: 'claude',
9
+ name: 'Claude Code',
10
+ tier: 1,
11
+ detectDir: '.claude',
12
+ skillsDir: '.claude/skills',
13
+ commandsDir: '.claude/commands',
14
+ commandExt: '.md',
15
+ commandFormat: 'markdown',
16
+ },
17
+ opencode: {
18
+ id: 'opencode',
19
+ name: 'OpenCode',
20
+ tier: 1,
21
+ detectDir: '.opencode',
22
+ skillsDir: '.opencode/skills',
23
+ commandsDir: '.opencode/commands',
24
+ commandExt: '.md',
25
+ commandFormat: 'markdown',
26
+ },
27
+ pi: {
28
+ id: 'pi',
29
+ name: 'Pi (oh-my-pi)',
30
+ tier: 1,
31
+ detectDir: '.pi',
32
+ skillsDir: '.pi/skills',
33
+ commandsDir: '.pi/prompts',
34
+ commandExt: '.md',
35
+ commandFormat: 'markdown',
36
+ },
37
+ antigravity: {
38
+ id: 'antigravity',
39
+ name: 'Google Antigravity',
40
+ tier: 1,
41
+ detectDir: '.agents',
42
+ detectAliases: ['.antigravity'],
43
+ skillsDir: '.agents/skills',
44
+ commandsDir: '.agents/workflows',
45
+ commandExt: '.md',
46
+ commandFormat: 'markdown',
47
+ },
48
+ 'github-copilot': {
49
+ id: 'github-copilot',
50
+ name: 'GitHub Copilot',
51
+ tier: 1,
52
+ detectDir: '.github',
53
+ skillsDir: '.github/skills',
54
+ commandsDir: '.github/prompts',
55
+ commandExt: '.prompt.md',
56
+ commandFormat: 'prompt-md',
57
+ },
58
+ cursor: {
59
+ id: 'cursor',
60
+ name: 'Cursor',
61
+ tier: 2,
62
+ detectDir: '.cursor',
63
+ skillsDir: '.cursor/skills',
64
+ commandsDir: '.cursor/commands',
65
+ commandExt: '.md',
66
+ commandFormat: 'markdown',
67
+ },
68
+ trae: {
69
+ id: 'trae',
70
+ name: 'Trae',
71
+ tier: 2,
72
+ detectDir: '.trae',
73
+ skillsDir: '.trae/skills',
74
+ commandsDir: '.trae/commands',
75
+ commandExt: '.md',
76
+ commandFormat: 'markdown',
77
+ },
78
+ windsurf: {
79
+ id: 'windsurf',
80
+ name: 'Windsurf / Devin Desktop',
81
+ tier: 2,
82
+ detectDir: '.windsurf',
83
+ detectAliases: ['.devin'],
84
+ skillsDir: '.windsurf/skills',
85
+ commandsDir: '.windsurf/workflows',
86
+ commandExt: '.md',
87
+ commandFormat: 'markdown',
88
+ },
89
+ gemini: {
90
+ id: 'gemini',
91
+ name: 'Gemini CLI',
92
+ tier: 2,
93
+ detectDir: '.gemini',
94
+ skillsDir: '.gemini/skills',
95
+ commandsDir: '.gemini/commands/asdlc',
96
+ commandExt: '.toml',
97
+ commandFormat: 'toml',
98
+ },
99
+ codex: {
100
+ id: 'codex',
101
+ name: 'Codex',
102
+ tier: 2,
103
+ detectDir: '.codex',
104
+ skillsDir: '.codex/skills',
105
+ commandsDir: '.codex/commands',
106
+ commandExt: '.md',
107
+ commandFormat: 'markdown',
108
+ },
109
+ zed: {
110
+ id: 'zed',
111
+ name: 'Zed',
112
+ tier: 2,
113
+ detectDir: '.zed',
114
+ skillsDir: '.zed/skills',
115
+ commandsDir: '.zed/commands',
116
+ commandExt: '.md',
117
+ commandFormat: 'markdown',
118
+ },
119
+ dsh: {
120
+ id: 'dsh',
121
+ name: 'DSH Agent',
122
+ tier: 2,
123
+ detectDir: '.dsh',
124
+ skillsDir: '.dsh/skills',
125
+ commandsDir: '.dsh/commands',
126
+ commandExt: '.md',
127
+ commandFormat: 'markdown',
128
+ },
129
+ agents: {
130
+ id: 'agents',
131
+ name: 'Generic Agents',
132
+ tier: 2,
133
+ detectDir: '.agents',
134
+ skillsDir: '.agents/skills',
135
+ commandsDir: '.agents/workflows',
136
+ commandExt: '.md',
137
+ commandFormat: 'markdown',
138
+ },
139
+ };
140
+
141
+ /**
142
+ * Detect AI agent tools configured in this repository
143
+ */
144
+ export function detectTools(repoRoot) {
145
+ const detected = new Set();
146
+ for (const tool of Object.values(TOOL_REGISTRY)) {
147
+ if (exists(path.join(repoRoot, tool.detectDir))) {
148
+ detected.add(tool.id);
149
+ }
150
+ if (tool.detectAliases) {
151
+ for (const alias of tool.detectAliases) {
152
+ if (exists(path.join(repoRoot, alias))) {
153
+ detected.add(tool.id);
154
+ }
155
+ }
156
+ }
157
+ }
158
+ return Array.from(detected);
159
+ }
160
+
161
+ /**
162
+ * Resolve tool definition by ID, alias, or directory name
163
+ */
164
+ export function getToolDefinition(toolIdentifier) {
165
+ if (!toolIdentifier) return null;
166
+ const clean = String(toolIdentifier).toLowerCase().replace(/^\./, '');
167
+ if (TOOL_REGISTRY[clean]) return TOOL_REGISTRY[clean];
168
+
169
+ for (const tool of Object.values(TOOL_REGISTRY)) {
170
+ if (tool.detectDir === `.${clean}` || (tool.detectAliases && tool.detectAliases.includes(`.${clean}`))) {
171
+ return tool;
172
+ }
173
+ }
174
+ return null;
175
+ }
176
+
177
+ /**
178
+ * Install bundled skills into all detected or specified agent tools
179
+ */
180
+ export function installSkills(repoRoot, tools = []) {
181
+ if (!exists(skillsAssetDir)) return;
182
+ const count = listDir(skillsAssetDir).filter((d) => d.isDirectory()).length;
183
+ const targetDirs = new Set(['.agents/skills']);
184
+
185
+ // If user has an explicit .antigravity folder, copy skills there too
186
+ if (exists(path.join(repoRoot, '.antigravity'))) {
187
+ targetDirs.add('.antigravity/skills');
188
+ }
189
+
190
+ for (const t of tools) {
191
+ const def = getToolDefinition(t);
192
+ if (def) {
193
+ targetDirs.add(def.skillsDir);
194
+ if (def.detectAliases) {
195
+ for (const alias of def.detectAliases) {
196
+ if (exists(path.join(repoRoot, alias))) {
197
+ targetDirs.add(path.join(alias, 'skills').replace(/\\/g, '/'));
198
+ }
199
+ }
200
+ }
201
+ } else {
202
+ const clean = String(t).toLowerCase().replace(/^\./, '');
203
+ if (clean) targetDirs.add(`.${clean}/skills`);
204
+ }
205
+ }
206
+
207
+ for (const dir of targetDirs) {
208
+ const dest = path.join(repoRoot, dir);
209
+ copyTree(skillsAssetDir, dest);
210
+ log.ok(`installed bundled skills (${count} skills) -> ${dir}/`);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Format markdown command template for a specific tool format
216
+ */
217
+ function formatCommandContent(baseContent, baseName, format) {
218
+ if (format === 'prompt-md') {
219
+ // GitHub Copilot uses .prompt.md with standard YAML frontmatter
220
+ return baseContent;
221
+ }
222
+ if (format === 'toml') {
223
+ // Gemini CLI uses TOML command definitions
224
+ const descMatch = baseContent.match(/^description:\s*["']?([\s\S]*?)["']?$/m);
225
+ const desc = descMatch ? descMatch[1].trim() : `Execute ${baseName}`;
226
+ const cleanBody = baseContent.replace(/^---[\s\S]*?---\r?\n/, '').trim();
227
+ return `description = "${desc.replace(/"/g, '\\"')}"\n\nprompt = """\n${cleanBody}\n"""\n`;
228
+ }
229
+ return baseContent;
230
+ }
231
+
232
+ /**
233
+ * Install slash commands and workflows across detected or specified tools
234
+ */
235
+ export function installCommands(repoRoot, tools = []) {
236
+ if (!exists(commandsAssetDir)) return;
237
+ const commandFiles = listDir(commandsAssetDir).filter((f) => !f.isDirectory() && f.name.endsWith('.md'));
238
+ if (commandFiles.length === 0) return;
239
+
240
+ const targetTools = new Set(['agents']);
241
+ for (const t of tools) {
242
+ const def = getToolDefinition(t);
243
+ if (def) targetTools.add(def.id);
244
+ }
245
+
246
+ // Also check if .antigravity exists on disk
247
+ const hasAntigravityAlias = exists(path.join(repoRoot, '.antigravity'));
248
+
249
+ for (const toolId of targetTools) {
250
+ const def = TOOL_REGISTRY[toolId];
251
+ if (!def) continue;
252
+
253
+ const destDir = path.join(repoRoot, def.commandsDir);
254
+ ensureDir(destDir);
255
+
256
+ for (const cmdFile of commandFiles) {
257
+ const baseName = cmdFile.name.replace(/\.md$/, '');
258
+ const rawContent = readText(path.join(commandsAssetDir, cmdFile.name));
259
+ const targetContent = formatCommandContent(rawContent, baseName, def.commandFormat);
260
+ const targetFileName = `${baseName}${def.commandExt}`;
261
+ writeText(path.join(destDir, targetFileName), targetContent);
262
+ }
263
+ log.ok(`installed slash commands (${commandFiles.length} commands) -> ${def.commandsDir}/`);
264
+
265
+ // If antigravity alias folder exists, mirror workflows there too
266
+ if (toolId === 'antigravity' && hasAntigravityAlias) {
267
+ const aliasDir = path.join(repoRoot, '.antigravity', 'workflows');
268
+ ensureDir(aliasDir);
269
+ for (const cmdFile of commandFiles) {
270
+ const rawContent = readText(path.join(commandsAssetDir, cmdFile.name));
271
+ writeText(path.join(aliasDir, cmdFile.name), rawContent);
272
+ }
273
+ log.ok(`installed slash commands (${commandFiles.length} commands) -> .antigravity/workflows/`);
274
+ }
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Audit tool health for asdlc doctor
280
+ */
281
+ export function checkToolHealth(repoRoot, toolId) {
282
+ const def = TOOL_REGISTRY[toolId];
283
+ if (!def) return null;
284
+
285
+ const skillsPath = path.join(repoRoot, def.skillsDir);
286
+ const commandsPath = path.join(repoRoot, def.commandsDir);
287
+
288
+ const skillsOk = exists(skillsPath) && listDir(skillsPath).length > 0;
289
+ const commandsOk = exists(commandsPath) && listDir(commandsPath).length > 0;
290
+
291
+ let status = 'pass';
292
+ let detail = `skills + commands installed (${def.commandsDir})`;
293
+
294
+ if (!skillsOk && !commandsOk) {
295
+ status = 'warn';
296
+ detail = 'missing skills and commands (run `asdlc init`)';
297
+ } else if (!skillsOk) {
298
+ status = 'warn';
299
+ detail = `missing skills in ${def.skillsDir} (run 'asdlc init')`;
300
+ } else if (!commandsOk) {
301
+ status = 'warn';
302
+ detail = `missing commands in ${def.commandsDir} (run 'asdlc init')`;
303
+ }
304
+
305
+ return {
306
+ id: def.id,
307
+ name: def.name,
308
+ status,
309
+ detail,
310
+ skillsOk,
311
+ commandsOk,
312
+ };
313
+ }