framework-aidf 0.0.0-stage → 0.2.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 (154) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/INSTALLATION.md +140 -0
  3. package/LICENSE +21 -0
  4. package/QODER.md +88 -0
  5. package/README.md +142 -2
  6. package/UTILISATION.md +188 -0
  7. package/assets/adapters/qoder/agents/aidf-orchestrator.md +30 -0
  8. package/assets/adapters/qoder/rules/00-core.md +28 -0
  9. package/assets/adapters/qoder/rules/10-security.md +33 -0
  10. package/assets/adapters/qoder/rules/20-context.md +39 -0
  11. package/assets/core/AGENTS.fragment.md +18 -0
  12. package/assets/core/AIDF.md +107 -0
  13. package/assets/docs/APPFLOW.md +66 -0
  14. package/assets/docs/BACKEND.md +71 -0
  15. package/assets/docs/CHANGELOG.md +25 -0
  16. package/assets/docs/CONVENTIONS.md +95 -0
  17. package/assets/docs/DECISIONS.md +60 -0
  18. package/assets/docs/PLAN.md +53 -0
  19. package/assets/docs/PRD.md +88 -0
  20. package/assets/docs/SECURITY.md +94 -0
  21. package/assets/docs/TRD.md +78 -0
  22. package/assets/docs/UI-UX.md +71 -0
  23. package/assets/docs/constitution.md +86 -0
  24. package/assets/hooks/audit.mjs +45 -0
  25. package/assets/hooks/session-context.mjs +53 -0
  26. package/assets/integrations/spec-kit/mapping.yaml +92 -0
  27. package/assets/knowledge/best-practices/testing.md +53 -0
  28. package/assets/knowledge/best-practices/web-dev-baseline.md +39 -0
  29. package/assets/knowledge/rules/api.md +45 -0
  30. package/assets/knowledge/rules/sql.md +44 -0
  31. package/assets/knowledge/rules/typescript.md +50 -0
  32. package/assets/knowledge/security-references/owasp-baseline.md +58 -0
  33. package/assets/registry/activation-map.yaml +83 -0
  34. package/assets/registry/dependencies.yaml +35 -0
  35. package/assets/registry/skills.yaml +541 -0
  36. package/assets/registry/sources.yaml +396 -0
  37. package/assets/schemas/architecture/v1.json +110 -0
  38. package/assets/schemas/constraints/v1.json +93 -0
  39. package/assets/schemas/decision/v1.json +106 -0
  40. package/assets/schemas/discovery/v1.json +91 -0
  41. package/assets/schemas/requirement/v1.json +136 -0
  42. package/assets/schemas/security/threat-model/v1.json +127 -0
  43. package/assets/schemas/test-plan/v1.json +108 -0
  44. package/assets/skills/aidf-architecture-review/SKILL.md +49 -0
  45. package/assets/skills/aidf-backend-implementation/SKILL.md +47 -0
  46. package/assets/skills/aidf-database-design/SKILL.md +48 -0
  47. package/assets/skills/aidf-devops-engineering/SKILL.md +41 -0
  48. package/assets/skills/aidf-documentation-maintenance/SKILL.md +41 -0
  49. package/assets/skills/aidf-frontend-implementation/SKILL.md +44 -0
  50. package/assets/skills/aidf-phase-transition/SKILL.md +48 -0
  51. package/assets/skills/aidf-product-analysis/SKILL.md +47 -0
  52. package/assets/skills/aidf-project-context/SKILL.md +57 -0
  53. package/assets/skills/aidf-requirements-engineering/SKILL.md +52 -0
  54. package/assets/skills/aidf-security-review/SKILL.md +57 -0
  55. package/assets/skills/aidf-testing-validation/SKILL.md +48 -0
  56. package/assets/skills/aidf-ui-ux-implementation/SKILL.md +43 -0
  57. package/assets/workflows/gates.yaml +232 -0
  58. package/assets/workflows/phases.yaml +161 -0
  59. package/bin/aidf.mjs +12 -0
  60. package/demo/run-demo.mjs +97 -0
  61. package/docs/aidf/ADR-001-artefacts-architectur.md +126 -0
  62. package/docs/aidf/ADR-002-requirements-registry.md +145 -0
  63. package/docs/aidf/ADR-003-traceability-chain.md +145 -0
  64. package/docs/aidf/ADR-004-markdown-generation.md +134 -0
  65. package/docs/aidf/ADR-005-validation-and-tests.md +170 -0
  66. package/docs/aidf/ADR-006-cli-commands.md +189 -0
  67. package/docs/aidf/ADR-007-compatibility-and-migration.md +119 -0
  68. package/docs/aidf/ADR-008-schema-versioning.md +115 -0
  69. package/docs/aidf/ADR-009-artefacts-scope.md +84 -0
  70. package/docs/aidf/ARCHITECTURE.md +137 -0
  71. package/docs/aidf/COMPATIBILITY.md +90 -0
  72. package/docs/aidf/DECISIONS.md +200 -0
  73. package/docs/aidf/FRAMEWORK.md +38 -0
  74. package/docs/aidf/IDE-QODER.md +61 -0
  75. package/docs/aidf/INSTALL.md +99 -0
  76. package/docs/aidf/INVENTORY.md +72 -0
  77. package/docs/aidf/L1-ARCHITECTURE-RAPPORT.md +353 -0
  78. package/docs/aidf/LIMITATIONS.md +69 -0
  79. package/docs/aidf/MATRICE-0.1.0-vers-0.2.0.md +155 -0
  80. package/docs/aidf/SECURITY.md +86 -0
  81. package/docs/aidf/SKILLS.md +78 -0
  82. package/docs/aidf/SPECKIT.md +67 -0
  83. package/docs/aidf/USAGE.md +113 -0
  84. package/docs/aidf/VALIDATION.md +55 -0
  85. package/package.json +37 -4
  86. package/src/cli.mjs +148 -0
  87. package/src/commands/artefacts.mjs +129 -0
  88. package/src/commands/config.mjs +130 -0
  89. package/src/commands/context.mjs +55 -0
  90. package/src/commands/decision.mjs +142 -0
  91. package/src/commands/design.mjs +141 -0
  92. package/src/commands/docs.mjs +133 -0
  93. package/src/commands/doctor.mjs +210 -0
  94. package/src/commands/evidence.mjs +178 -0
  95. package/src/commands/install.mjs +154 -0
  96. package/src/commands/release.mjs +214 -0
  97. package/src/commands/requirements.mjs +196 -0
  98. package/src/commands/resources.mjs +181 -0
  99. package/src/commands/scan.mjs +139 -0
  100. package/src/commands/security.mjs +97 -0
  101. package/src/commands/setup.mjs +68 -0
  102. package/src/commands/skills.mjs +204 -0
  103. package/src/commands/speckit.mjs +78 -0
  104. package/src/commands/tests.mjs +81 -0
  105. package/src/commands/traceability.mjs +116 -0
  106. package/src/commands/uninstall.mjs +238 -0
  107. package/src/commands/validate.mjs +84 -0
  108. package/src/commands/workflow.mjs +137 -0
  109. package/src/core/adapters/base.mjs +32 -0
  110. package/src/core/adapters/generic.mjs +70 -0
  111. package/src/core/adapters/index.mjs +24 -0
  112. package/src/core/adapters/opencode.mjs +115 -0
  113. package/src/core/adapters/qoder.mjs +228 -0
  114. package/src/core/artefacts/index.mjs +1 -0
  115. package/src/core/artefacts/validation.mjs +161 -0
  116. package/src/core/bootstrap.mjs +179 -0
  117. package/src/core/config.mjs +123 -0
  118. package/src/core/context.mjs +187 -0
  119. package/src/core/design-engineering/complexity-classifier.mjs +78 -0
  120. package/src/core/design-engineering/engine.mjs +197 -0
  121. package/src/core/design-engineering/fallback/mockups.mjs +221 -0
  122. package/src/core/design-engineering/fallback/wireframes.mjs +114 -0
  123. package/src/core/design-engineering/figma/validators.mjs +178 -0
  124. package/src/core/design-engineering/index.mjs +9 -0
  125. package/src/core/design-engineering/visual-parity/capture.mjs +172 -0
  126. package/src/core/detect.mjs +220 -0
  127. package/src/core/docsgen.mjs +175 -0
  128. package/src/core/evidence.mjs +210 -0
  129. package/src/core/installer.mjs +377 -0
  130. package/src/core/manifest.mjs +53 -0
  131. package/src/core/paths.mjs +94 -0
  132. package/src/core/requirements/index.mjs +13 -0
  133. package/src/core/requirements/registry.mjs +234 -0
  134. package/src/core/resource-inventory.mjs +434 -0
  135. package/src/core/resources.mjs +280 -0
  136. package/src/core/security/threat-model.mjs +235 -0
  137. package/src/core/skills.mjs +353 -0
  138. package/src/core/source-skills.mjs +213 -0
  139. package/src/core/speckit.mjs +195 -0
  140. package/src/core/technology-decision/analyzer-deterministic.mjs +240 -0
  141. package/src/core/technology-decision/engine.mjs +157 -0
  142. package/src/core/technology-decision/generator.mjs +204 -0
  143. package/src/core/technology-decision/index.mjs +17 -0
  144. package/src/core/technology-decision/options/index.mjs +10 -0
  145. package/src/core/testplan.mjs +176 -0
  146. package/src/core/traceability/chain.mjs +488 -0
  147. package/src/core/traceability/index.mjs +12 -0
  148. package/src/core/workflow.mjs +471 -0
  149. package/src/util/args.mjs +69 -0
  150. package/src/util/frontmatter.mjs +26 -0
  151. package/src/util/fsx.mjs +208 -0
  152. package/src/util/logger.mjs +74 -0
  153. package/src/util/text.mjs +66 -0
  154. package/src/util/yaml.mjs +379 -0
@@ -0,0 +1,139 @@
1
+ import path from 'node:path';
2
+ import fsp from 'node:fs/promises';
3
+ import { parseArgs } from '../util/args.mjs';
4
+ import { resolveProjectRoot, isInitialized, aidfPaths } from '../core/paths.mjs';
5
+ import { detectEnvironment, detectProject } from '../core/detect.mjs';
6
+ import { ensureDir, writeJson, writeAtomic } from '../util/fsx.mjs';
7
+ import { recordEvidence } from '../core/evidence.mjs';
8
+ import { attachLogFile } from '../util/logger.mjs';
9
+
10
+ export function scanArgSpec() {
11
+ return {
12
+ booleans: ['json', 'record', 'help'],
13
+ aliases: { h: 'help', t: 'target' },
14
+ };
15
+ }
16
+
17
+ export async function scanCommand(argv, ctx) {
18
+ const args = parseArgs(argv, scanArgSpec());
19
+ if (args.help) {
20
+ ctx.logger.info('Usage: aidf scan [--target <dir>] [--record] [--json]');
21
+ return 0;
22
+ }
23
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
24
+ if (!isInitialized(root)) {
25
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
26
+ return 1;
27
+ }
28
+ await attachLogFile(ctx.logger, root).catch(() => null);
29
+ const env = await detectEnvironment();
30
+ const project = await detectProject(root);
31
+ const scan = {
32
+ schemaVersion: 1,
33
+ generatedAt: new Date().toISOString(),
34
+ root,
35
+ environment: env,
36
+ project,
37
+ secretFiles: await listSecretFileNames(root),
38
+ };
39
+ const paths = aidfPaths(root);
40
+ await ensureDir(paths.reports);
41
+ await writeJson(path.join(paths.reports, 'scan.json'), scan);
42
+ await writeAtomic(path.join(paths.reports, 'SCAN.md'), renderScan(scan));
43
+ let evidence = null;
44
+ if (args.record) {
45
+ evidence = await recordEvidence(root, {
46
+ type: 'project-scan',
47
+ status: 'PASS',
48
+ summary: `Project scan: ${project.languages.map((l) => l.language).join(', ') || 'unknown stack'}; ${project.tests.runners.join(', ') || 'no test runner detected'}.`,
49
+ createdBy: 'aidf',
50
+ files: [...new Set([
51
+ ...project.languages.map((l) => l.marker),
52
+ ...(project.packageJson ? ['package.json'] : []),
53
+ ])],
54
+ checks: [
55
+ { id: 'languages', status: project.languages.length ? 'PASS' : 'NOT_PROVEN', reason: project.languages.map((l) => l.marker).join(', ') },
56
+ { id: 'tests', status: project.tests.runners.length ? 'PASS' : 'NOT_PROVEN', reason: project.tests.runners.join(', ') },
57
+ { id: 'secrets', status: scan.secretFiles.length ? 'BLOCKED' : 'PASS', reason: scan.secretFiles.length ? `${scan.secretFiles.length} secret file(s) present; content not read.` : 'No secret files detected at the scanned depth.' },
58
+ ],
59
+ limitations: [
60
+ 'Detection is based on known marker files and manifests; absence is not proof that a technology is unused.',
61
+ 'Secret detection reports file names only and is not exhaustive.',
62
+ ],
63
+ });
64
+ }
65
+ if (ctx.json) {
66
+ process.stdout.write(`${JSON.stringify({ scan, evidence }, null, 2)}\n`);
67
+ } else {
68
+ ctx.logger.info(`Project: ${root}`);
69
+ ctx.logger.info(`Languages: ${project.languages.map((l) => `${l.language} (${l.marker})`).join(', ') || 'none detected'}`);
70
+ ctx.logger.info(`Frameworks: ${project.frameworks.join(', ') || 'none detected'}`);
71
+ ctx.logger.info(`Test runners: ${project.tests.runners.join(', ') || 'none detected'}`);
72
+ ctx.logger.info(`Git: ${project.git.repository ? `${project.git.branch} @ ${project.git.head}${project.git.dirty ? ` (${project.git.dirty} changed)` : ''}` : 'not a git repository'}`);
73
+ ctx.logger.info(`AI config: ${Object.entries(project.aiConfig).filter(([, v]) => v).map(([k]) => k).join(', ') || 'none'}`);
74
+ if (scan.secretFiles.length > 0) {
75
+ ctx.logger.warn(`Secret-like files present (content NOT read): ${scan.secretFiles.join(', ')}`);
76
+ }
77
+ if (evidence) ctx.logger.info(`Evidence recorded: ${evidence.file}`);
78
+ ctx.logger.info('Report: .aidf/reports/SCAN.md');
79
+ }
80
+ return 0;
81
+ }
82
+
83
+ async function listSecretFileNames(root) {
84
+ const names = [];
85
+ const candidates = ['.env', '.env.local', '.env.production', '.env.development', 'id_rsa', 'id_ed25519', '.npmrc', '.pypirc'];
86
+ for (const name of candidates) {
87
+ try {
88
+ await fsp.access(path.join(root, name));
89
+ names.push(name);
90
+ } catch {
91
+ // absent
92
+ }
93
+ }
94
+ return names;
95
+ }
96
+
97
+ function renderScan(scan) {
98
+ const p = scan.project;
99
+ const lines = [];
100
+ lines.push('# AIDF Project Scan');
101
+ lines.push('');
102
+ lines.push(`- Root: \`${scan.root}\``);
103
+ lines.push(`- Generated: ${scan.generatedAt}`);
104
+ lines.push(`- OS: ${scan.environment.os.platform} ${scan.environment.os.release} (${scan.environment.os.arch})`);
105
+ lines.push(`- Node: ${scan.environment.node.version}`);
106
+ lines.push('');
107
+ lines.push('## Stack');
108
+ lines.push('');
109
+ lines.push('| Language | Ecosystem | Evidence |');
110
+ lines.push('|---|---|---|');
111
+ for (const lang of p.languages) lines.push(`| ${lang.language} | ${lang.ecosystem} | \`${lang.marker}\` |`);
112
+ if (p.languages.length === 0) lines.push('| _none detected_ | - | - |');
113
+ lines.push('');
114
+ lines.push(`Frameworks: ${p.frameworks.join(', ') || '_none detected_'}`);
115
+ lines.push('');
116
+ lines.push('## Tests');
117
+ lines.push('');
118
+ lines.push(`- Runners: ${p.tests.runners.join(', ') || '_none detected_'}`);
119
+ lines.push(`- Directories: ${p.tests.directories.join(', ') || '_none detected_'}`);
120
+ lines.push(`- Scripts: ${Object.keys(p.tests.scripts).join(', ') || '_none_'}`);
121
+ lines.push('');
122
+ lines.push('## Git');
123
+ lines.push('');
124
+ lines.push(p.git.repository
125
+ ? `- Branch: ${p.git.branch}\n- HEAD: ${p.git.head}\n- Changed files: ${p.git.dirty}`
126
+ : '- Not a git repository.');
127
+ lines.push('');
128
+ lines.push('## Existing AI configuration');
129
+ lines.push('');
130
+ for (const [key, value] of Object.entries(p.aiConfig)) lines.push(`- ${key}: ${value ? 'PRESENT' : 'ABSENT'}`);
131
+ lines.push('');
132
+ lines.push('## Secret-like files (names only)');
133
+ lines.push('');
134
+ lines.push(scan.secretFiles.length ? scan.secretFiles.map((f) => `- \`${f}\``).join('\n') : '_None detected._');
135
+ lines.push('');
136
+ lines.push('> Detection is not exhaustive and absence is not proof. No secret content was read.');
137
+ lines.push('');
138
+ return `${lines.join('\n')}\n`;
139
+ }
@@ -0,0 +1,97 @@
1
+ import path from 'node:path';
2
+ import { parseArgs } from '../util/args.mjs';
3
+ import { resolveProjectRoot, isInitialized, aidfPaths } from '../core/paths.mjs';
4
+ import { attachLogFile } from '../util/logger.mjs';
5
+ import { writeAtomic, ensureDir, resolveInside, toPosix } from '../util/fsx.mjs';
6
+ import {
7
+ generateThreatModel, saveThreatModel, loadThreatModel, renderThreatModelMarkdown,
8
+ } from '../core/security/threat-model.mjs';
9
+ import { validateArtefact } from '../core/artefacts/index.mjs';
10
+
11
+ export function securityArgSpec() {
12
+ return {
13
+ booleans: ['json', 'help', 'write', 'markdown'],
14
+ aliases: { h: 'help', t: 'target' },
15
+ };
16
+ }
17
+
18
+ function printSummary(ctx, tm) {
19
+ const open = (tm.threats ?? []).filter((t) => t.status === 'open');
20
+ const mitigated = (tm.threats ?? []).filter((t) => t.status === 'mitigated');
21
+ ctx.logger.info(`Threat model ${tm.id} — ${tm.threats?.length ?? 0} threats (${open.length} open, ${mitigated.length} mitigated)`);
22
+ for (const t of tm.threats ?? []) {
23
+ ctx.logger.info(` [${t.status}] ${t.id} ${t.name} (${t.stride})`);
24
+ }
25
+ if (open.length > 0) ctx.logger.warn('Open threats require mitigation or explicit human acceptance.');
26
+ ctx.logger.warn('Generated model is DRAFT; human review required before VALIDATED.');
27
+ }
28
+
29
+ export async function securityCommand(argv, ctx) {
30
+ const args = parseArgs(argv, securityArgSpec());
31
+ const sub = args._[0] ?? 'analyze';
32
+ if (args.help || sub === 'help') {
33
+ ctx.logger.info('Usage: aidf security <analyze|show> [--write] [--markdown] [--out <file>] [--json]');
34
+ return 0;
35
+ }
36
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
37
+ if (!isInitialized(root)) {
38
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
39
+ return 1;
40
+ }
41
+ await attachLogFile(ctx.logger, root).catch(() => null);
42
+
43
+ if (sub === 'show') {
44
+ const tm = await loadThreatModel(root);
45
+ if (!tm) {
46
+ ctx.logger.error('No threat model found. Run "aidf security analyze --write" first.');
47
+ return 1;
48
+ }
49
+ if (ctx.json) {
50
+ process.stdout.write(`${JSON.stringify(tm, null, 2)}\n`);
51
+ } else {
52
+ printSummary(ctx, tm);
53
+ }
54
+ return 0;
55
+ }
56
+
57
+ if (sub !== 'analyze') {
58
+ ctx.logger.error(`Unknown security subcommand: ${sub}`);
59
+ return 1;
60
+ }
61
+
62
+ const tm = await generateThreatModel(root);
63
+ const validation = await validateArtefact(tm);
64
+ if (!validation.valid) {
65
+ ctx.logger.error(`Generated threat model failed validation: ${validation.errors.join('; ')}`);
66
+ return 1;
67
+ }
68
+
69
+ let artefactPath = null;
70
+ if (args.write) {
71
+ artefactPath = await saveThreatModel(root, tm);
72
+ }
73
+
74
+ if (args.out || args.markdown) {
75
+ try {
76
+ const abs = args.out
77
+ ? (path.isAbsolute(args.out) ? args.out : resolveInside(root, args.out))
78
+ : path.join(aidfPaths(root).reports, 'THREAT-MODEL.md');
79
+ await ensureDir(path.dirname(abs));
80
+ await writeAtomic(abs, renderThreatModelMarkdown(tm));
81
+ if (!args.out) ctx.logger.info(`Markdown report: ${toPosix(abs)}`);
82
+ } catch (error) {
83
+ ctx.logger.error(`Cannot write markdown: ${error.message}`);
84
+ return 1;
85
+ }
86
+ }
87
+
88
+ if (ctx.json) {
89
+ process.stdout.write(`${JSON.stringify({ threatModel: tm, artefact: artefactPath ? toPosix(artefactPath) : null }, null, 2)}\n`);
90
+ return 0;
91
+ }
92
+
93
+ printSummary(ctx, tm);
94
+ if (artefactPath) ctx.logger.info(`Artefact: ${toPosix(artefactPath)}`);
95
+ else ctx.logger.info('Not persisted. Re-run with --write to store under .aidf/artefacts/security/.');
96
+ return 0;
97
+ }
@@ -0,0 +1,68 @@
1
+ import path from 'node:path';
2
+ import { parseArgs } from '../util/args.mjs';
3
+ import { resolveProjectRoot, isInitialized } from '../core/paths.mjs';
4
+ import { loadConfig } from '../core/config.mjs';
5
+ import { setupResources, loadSources } from '../core/resources.mjs';
6
+ import { attachLogFile } from '../util/logger.mjs';
7
+
8
+ export function setupArgSpec() {
9
+ return {
10
+ booleans: ['dry-run', 'json', 'yes', 'allow-network', 'help'],
11
+ aliases: { h: 'help', t: 'target' },
12
+ };
13
+ }
14
+
15
+ export async function setupCommand(argv, ctx) {
16
+ const args = parseArgs(argv, setupArgSpec());
17
+ if (args.help) {
18
+ ctx.logger.info('Usage: aidf setup [resources] [--target <dir>] [--dry-run] [--allow-network]');
19
+ return 0;
20
+ }
21
+ const sub = args._[0];
22
+ if (sub && sub !== 'resources') {
23
+ ctx.logger.error(`Unknown setup target "${sub}". Available: resources`);
24
+ return 1;
25
+ }
26
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
27
+ if (!isInitialized(root)) {
28
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
29
+ return 1;
30
+ }
31
+ // A dry-run must not write anything, including logs.
32
+ if (!args['dry-run']) await attachLogFile(ctx.logger, root).catch(() => null);
33
+ const config = await loadConfig(root);
34
+ if (args['allow-network']) {
35
+ config.security.allowNetwork = true;
36
+ }
37
+ const { results, lock } = await setupResources(root, {
38
+ dryRun: Boolean(args['dry-run']),
39
+ frameworkRoot: ctx.frameworkRoot,
40
+ });
41
+ if (ctx.json) {
42
+ process.stdout.write(`${JSON.stringify({ results, lock }, null, 2)}\n`);
43
+ } else {
44
+ ctx.logger.info(`${args['dry-run'] ? '[dry-run] ' : ''}AIDF resources`);
45
+ ctx.logger.table(
46
+ results.map((r) => ({
47
+ id: r.id,
48
+ status: r.status,
49
+ kind: r.kind,
50
+ license: r.license,
51
+ path: r.path ?? '-',
52
+ })),
53
+ [
54
+ { key: 'id', label: 'Resource' },
55
+ { key: 'status', label: 'Status' },
56
+ { key: 'kind', label: 'Kind' },
57
+ { key: 'license', label: 'Licence' },
58
+ { key: 'path', label: 'Path' },
59
+ ],
60
+ );
61
+ const blocked = results.filter((r) => ['BLOCKED', 'ABSENT'].includes(r.status));
62
+ if (blocked.length > 0) {
63
+ ctx.logger.warn(`${blocked.length} resource(s) are not usable: ${blocked.map((r) => r.id).join(', ')}`);
64
+ }
65
+ ctx.logger.info('Lock written to .aidf/registry/resources.lock.json (unless dry-run).');
66
+ }
67
+ return 0;
68
+ }
@@ -0,0 +1,204 @@
1
+ import { parseArgs, assertEnum } from '../util/args.mjs';
2
+ import { resolveProjectRoot, isInitialized } from '../core/paths.mjs';
3
+ import { loadConfig } from '../core/config.mjs';
4
+ import {
5
+ buildSkillRegistry, saveProjectSkillRegistry, loadDependencies, validateRegistry,
6
+ linkSkill, SKILL_STATUSES,
7
+ } from '../core/skills.mjs';
8
+ import { loadManifest, saveManifest } from '../core/manifest.mjs';
9
+ import { readInventory } from '../core/resource-inventory.mjs';
10
+ import {
11
+ catalogSourceSkills, summarizeSourceSkills, saveSourceSkillCatalog,
12
+ copySourceSkill, skillInstallTarget,
13
+ } from '../core/source-skills.mjs';
14
+ import { attachLogFile } from '../util/logger.mjs';
15
+
16
+ export function skillsArgSpec() {
17
+ return {
18
+ booleans: ['json', 'dry-run', 'help', 'allow-scripts'],
19
+ aliases: { h: 'help', t: 'target' },
20
+ };
21
+ }
22
+
23
+ export async function skillsCommand(argv, ctx) {
24
+ const args = parseArgs(argv, skillsArgSpec());
25
+ const sub = args._[0] ?? 'list';
26
+ if (args.help) {
27
+ ctx.logger.info('Usage: aidf skills <list|validate|refresh|show|link> [id] [--status <status>] [--json]');
28
+ return 0;
29
+ }
30
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
31
+ if (!isInitialized(root)) {
32
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
33
+ return 1;
34
+ }
35
+ await attachLogFile(ctx.logger, root).catch(() => null);
36
+ const config = await loadConfig(root);
37
+ const registry = await buildSkillRegistry(root, { adapter: config.adapter, frameworkRoot: ctx.frameworkRoot });
38
+
39
+ if (sub === 'list') {
40
+ const status = assertEnum(args.status, SKILL_STATUSES, 'status');
41
+ const skills = registry.skills.filter((s) => !status || s.status === status);
42
+ if (ctx.json) {
43
+ process.stdout.write(`${JSON.stringify({ skills, summary: registry.summary }, null, 2)}\n`);
44
+ } else {
45
+ ctx.logger.info(`Skills (${skills.length}) — ${JSON.stringify(registry.summary)}`);
46
+ ctx.logger.table(
47
+ skills.map((s) => ({
48
+ id: s.id,
49
+ status: s.status,
50
+ source: s.source,
51
+ path: s.path ?? '-',
52
+ })),
53
+ [
54
+ { key: 'id', label: 'Skill' },
55
+ { key: 'status', label: 'Status' },
56
+ { key: 'source', label: 'Source' },
57
+ { key: 'path', label: 'Path' },
58
+ ],
59
+ );
60
+ }
61
+ return 0;
62
+ }
63
+
64
+ if (sub === 'refresh' || sub === 'index') {
65
+ if (!args['dry-run']) await saveProjectSkillRegistry(root, registry);
66
+ ctx.logger.info(`${args['dry-run'] ? '[dry-run] ' : ''}Skill registry refreshed: ${registry.summary.AVAILABLE ?? 0} available, ${registry.summary.BLOCKED ?? 0} blocked.`);
67
+ return 0;
68
+ }
69
+
70
+ if (sub === 'validate') {
71
+ const deps = await loadDependencies(ctx.frameworkRoot);
72
+ const validation = await validateRegistry(root, registry, deps);
73
+ if (ctx.json) {
74
+ process.stdout.write(`${JSON.stringify({ validation, registry }, null, 2)}\n`);
75
+ } else {
76
+ ctx.logger.info(`Skill validation: ${validation.valid ? 'PASS' : 'FAIL'}`);
77
+ for (const error of validation.errors) ctx.logger.error(error);
78
+ for (const warning of validation.warnings) ctx.logger.warn(warning);
79
+ if (validation.cycles.length > 0) {
80
+ for (const cycle of validation.cycles) ctx.logger.error(`Cycle: ${cycle.join(' -> ')}`);
81
+ }
82
+ const external = registry.skills.filter((s) => s.source === 'external');
83
+ ctx.logger.info(`External skills discovered: ${external.length} (indexed, not copied).`);
84
+ }
85
+ return validation.valid ? 0 : 1;
86
+ }
87
+
88
+ if (sub === 'show') {
89
+ const id = args._[1];
90
+ const skill = registry.skills.find((s) => s.id === id || s.name === id);
91
+ if (!skill) {
92
+ ctx.logger.error(`Unknown skill: ${id}`);
93
+ return 1;
94
+ }
95
+ if (ctx.json) {
96
+ process.stdout.write(`${JSON.stringify(skill, null, 2)}\n`);
97
+ } else {
98
+ ctx.logger.info(`${skill.name} (${skill.id}) — ${skill.status}`);
99
+ ctx.logger.info(`Source: ${skill.source}`);
100
+ ctx.logger.info(`Path: ${skill.path ?? '-'}`);
101
+ ctx.logger.info(`Phases: ${(skill.phases ?? []).join(', ') || '-'}`);
102
+ ctx.logger.info(`Documents: ${(skill.documents ?? []).join(', ') || '-'}`);
103
+ ctx.logger.info(`Description: ${skill.description}`);
104
+ if (skill.errors?.length) ctx.logger.warn(`Errors: ${skill.errors.join('; ')}`);
105
+ if (skill.warnings?.length) ctx.logger.warn(`Warnings: ${skill.warnings.join('; ')}`);
106
+ }
107
+ return 0;
108
+ }
109
+
110
+ if (sub === 'link') {
111
+ const id = args._[1];
112
+ if (!id) {
113
+ ctx.logger.error('Usage: aidf skills link <skill-id>');
114
+ return 1;
115
+ }
116
+ try {
117
+ const result = await linkSkill(root, registry, id, { dryRun: Boolean(args['dry-run']) });
118
+ if (result.status === 'LINKED' && !args['dry-run']) {
119
+ const manifest = await loadManifest(root);
120
+ manifest.links[result.path] = { target: result.target, ts: new Date().toISOString() };
121
+ await saveManifest(root, manifest);
122
+ }
123
+ ctx.logger.info(`${result.status}: ${result.path} -> ${result.target}`);
124
+ return 0;
125
+ } catch (error) {
126
+ ctx.logger.error(error.message);
127
+ return 1;
128
+ }
129
+ }
130
+
131
+ if (sub === 'sources' || sub === 'catalog') {
132
+ const manifest = await readInventory(root);
133
+ if (!manifest) {
134
+ ctx.logger.error('No resources manifest found. Run `aidf resources inventory --write` first.');
135
+ return 1;
136
+ }
137
+ const entries = catalogSourceSkills(manifest.resources ?? []);
138
+ const summary = summarizeSourceSkills(entries);
139
+ if (!args['dry-run']) await saveSourceSkillCatalog(root, entries);
140
+ if (ctx.json) {
141
+ process.stdout.write(`${JSON.stringify({ summary, skills: entries }, null, 2)}\n`);
142
+ } else {
143
+ ctx.logger.info(
144
+ `Source skills (${summary.total} files, ${summary.unique} unique) — ${JSON.stringify(summary)}`,
145
+ );
146
+ ctx.logger.table(
147
+ entries.map((s) => ({
148
+ id: s.id,
149
+ status: s.status,
150
+ license: s.license,
151
+ resource: s.resource,
152
+ path: s.path,
153
+ })),
154
+ [
155
+ { key: 'id', label: 'Skill' },
156
+ { key: 'status', label: 'Status' },
157
+ { key: 'license', label: 'Licence' },
158
+ { key: 'resource', label: 'Resource' },
159
+ { key: 'path', label: 'Path' },
160
+ ],
161
+ );
162
+ }
163
+ return 0;
164
+ }
165
+
166
+ if (sub === 'enable') {
167
+ const id = args._[1];
168
+ if (!id) {
169
+ ctx.logger.error('Usage: aidf skills enable <skill-id> [--allow-scripts] [--dry-run]');
170
+ return 1;
171
+ }
172
+ const manifest = await readInventory(root);
173
+ if (!manifest) {
174
+ ctx.logger.error('No resources manifest found. Run `aidf resources inventory --write` first.');
175
+ return 1;
176
+ }
177
+ const entries = catalogSourceSkills(manifest.resources ?? []);
178
+ const entry = entries.find((s) => s.id === id && s.canonical !== false) ?? entries.find((s) => s.id === id);
179
+ if (!entry) {
180
+ ctx.logger.error(`Unknown source skill: ${id}`);
181
+ return 1;
182
+ }
183
+ const target = skillInstallTarget(root, config.adapter, id);
184
+ if (args['dry-run']) {
185
+ ctx.logger.info(`[dry-run] Would copy ${entry.resource}:${entry.path} -> ${target}`);
186
+ return 0;
187
+ }
188
+ const result = await copySourceSkill(entry, manifest, target, {
189
+ allowScripts: Boolean(args['allow-scripts']),
190
+ });
191
+ if (result.status !== 'COPIED') {
192
+ ctx.logger.error(`${result.status}: ${result.reason}`);
193
+ return 1;
194
+ }
195
+ ctx.logger.info(`Copied ${result.files} file(s) to ${result.target} (licence ${entry.license}).`);
196
+ if (result.skipped.length > 0) {
197
+ ctx.logger.warn(`Skipped ${result.skipped.length} file(s): executables or secrets.`);
198
+ }
199
+ return 0;
200
+ }
201
+
202
+ ctx.logger.error(`Unknown skills subcommand: ${sub}`);
203
+ return 1;
204
+ }
@@ -0,0 +1,78 @@
1
+ import { parseArgs } from '../util/args.mjs';
2
+ import { resolveProjectRoot, isInitialized } from '../core/paths.mjs';
3
+ import { specKitStatus, initSpecKit, syncSpecKit } from '../core/speckit.mjs';
4
+ import { detectEnvironment } from '../core/detect.mjs';
5
+ import { attachLogFile } from '../util/logger.mjs';
6
+
7
+ export function speckitArgSpec() {
8
+ return {
9
+ booleans: ['json', 'dry-run', 'allow-exec', 'adopt', 'specify-force', 'help'],
10
+ aliases: { h: 'help', t: 'target' },
11
+ };
12
+ }
13
+
14
+ export async function speckitCommand(argv, ctx) {
15
+ const args = parseArgs(argv, speckitArgSpec());
16
+ const sub = args._[0] ?? 'status';
17
+ if (args.help) {
18
+ ctx.logger.info('Usage: aidf speckit <status|init|sync> [--dry-run] [--allow-exec] [--specify-force] [--adopt] [--json]');
19
+ return 0;
20
+ }
21
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
22
+ if (!isInitialized(root)) {
23
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
24
+ return 1;
25
+ }
26
+ await attachLogFile(ctx.logger, root).catch(() => null);
27
+ const env = await detectEnvironment();
28
+ const options = {
29
+ frameworkRoot: ctx.frameworkRoot,
30
+ specifyPath: env.specKit.cliPath ?? 'specify',
31
+ integration: args.integration ?? 'qodercli',
32
+ dryRun: Boolean(args['dry-run']),
33
+ allowExec: Boolean(args['allow-exec']),
34
+ adopt: Boolean(args.adopt),
35
+ specifyForce: Boolean(args['specify-force']),
36
+ };
37
+
38
+ if (sub === 'status') {
39
+ const status = await specKitStatus(root, options);
40
+ if (ctx.json) {
41
+ process.stdout.write(`${JSON.stringify(status, null, 2)}\n`);
42
+ } else {
43
+ ctx.logger.info(`Spec Kit: ${status.status}`);
44
+ ctx.logger.info(`- .specify present: ${status.present}`);
45
+ ctx.logger.info(`- templates: ${status.templates}`);
46
+ ctx.logger.info(`- constitution: ${status.constitutionPresent ? status.constitutionSync : 'absent'}`);
47
+ ctx.logger.info(`- integration skills: ${status.integrationSkills.join(', ') || 'none'}`);
48
+ ctx.logger.info(`- CLI: ${status.cli.available ? `${status.cli.path} (${status.cli.version})` : 'not available'}`);
49
+ if (!status.present) ctx.logger.info('Run `aidf speckit init --allow-exec` to initialise Spec Kit in this project.');
50
+ }
51
+ return 0;
52
+ }
53
+
54
+ if (sub === 'init') {
55
+ const result = await initSpecKit(root, options);
56
+ if (ctx.json) process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
57
+ else {
58
+ ctx.logger.info(`${result.status}: ${result.reason ?? result.command ?? ''}`);
59
+ if (result.status === 'CREATED') ctx.logger.info('Spec Kit initialised. Run `aidf speckit sync --adopt` to publish the AIDF constitution.');
60
+ }
61
+ return result.status === 'FAILED' || result.status === 'BLOCKED' ? 1 : 0;
62
+ }
63
+
64
+ if (sub === 'sync') {
65
+ const result = await syncSpecKit(root, options);
66
+ if (ctx.json) process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
67
+ else {
68
+ ctx.logger.info(`Spec Kit sync: ${result.status}`);
69
+ for (const row of result.results) {
70
+ ctx.logger.info(`${row.status} ${row.path}${row.reason ? ` — ${row.reason}` : ''}`);
71
+ }
72
+ }
73
+ return result.status === 'CONFLICT' ? 2 : 0;
74
+ }
75
+
76
+ ctx.logger.error(`Unknown speckit subcommand: ${sub}`);
77
+ return 1;
78
+ }
@@ -0,0 +1,81 @@
1
+ import { parseArgs } from '../util/args.mjs';
2
+ import { resolveProjectRoot, isInitialized } from '../core/paths.mjs';
3
+ import { attachLogFile } from '../util/logger.mjs';
4
+ import { toPosix } from '../util/fsx.mjs';
5
+ import {
6
+ generateTestPlan, saveTestPlan, loadTestPlan, testCoverage,
7
+ } from '../core/testplan.mjs';
8
+ import { validateArtefact } from '../core/artefacts/index.mjs';
9
+
10
+ export function testsArgSpec() {
11
+ return {
12
+ booleans: ['json', 'help', 'write', 'all'],
13
+ aliases: { h: 'help', t: 'target', type: 'type' },
14
+ };
15
+ }
16
+
17
+ export async function testsCommand(argv, ctx) {
18
+ const args = parseArgs(argv, testsArgSpec());
19
+ const sub = args._[0] ?? 'plan';
20
+ if (args.help || sub === 'help') {
21
+ ctx.logger.info('Usage: aidf tests <plan|coverage> [--write] [--type <unit|integration|api|e2e|security|accessibility|performance>] [--json]');
22
+ return 0;
23
+ }
24
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
25
+ if (!isInitialized(root)) {
26
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
27
+ return 1;
28
+ }
29
+ await attachLogFile(ctx.logger, root).catch(() => null);
30
+
31
+ if (sub === 'coverage') {
32
+ const coverage = await testCoverage(root);
33
+ if (ctx.json) {
34
+ process.stdout.write(`${JSON.stringify(coverage, null, 2)}\n`);
35
+ } else {
36
+ ctx.logger.info(
37
+ `Test coverage: ${coverage.covered}/${coverage.total} requirement(s) covered`
38
+ + (coverage.testPlan ? ` (plan ${coverage.testPlan})` : ' (no test plan)'),
39
+ );
40
+ for (const d of coverage.details) {
41
+ ctx.logger.info(` ${d.covered ? 'COVERED ' : 'UNCOVERED'} ${d.requirement} — ${d.acceptanceCriteria} criterion/criteria, ${d.plannedCases.length} planned case(s)`);
42
+ }
43
+ if (coverage.uncovered.length > 0) {
44
+ ctx.logger.warn(`${coverage.uncovered.length} requirement(s) without any planned or artefact test.`);
45
+ }
46
+ }
47
+ return 0;
48
+ }
49
+
50
+ if (sub !== 'plan') {
51
+ ctx.logger.error(`Unknown tests subcommand: ${sub}`);
52
+ return 1;
53
+ }
54
+
55
+ const plan = await generateTestPlan(root, { type: args.type ?? null });
56
+ const validation = await validateArtefact(plan);
57
+ if (!validation.valid) {
58
+ ctx.logger.error(`Generated test plan failed validation: ${validation.errors.join('; ')}`);
59
+ return 1;
60
+ }
61
+
62
+ let artefactPath = null;
63
+ if (args.write) {
64
+ artefactPath = await saveTestPlan(root, plan);
65
+ }
66
+
67
+ if (ctx.json) {
68
+ process.stdout.write(`${JSON.stringify({ testPlan: plan, artefact: artefactPath ? toPosix(artefactPath) : null }, null, 2)}\n`);
69
+ return 0;
70
+ }
71
+
72
+ ctx.logger.info(`Test plan ${plan.id} — ${plan.testCases.length} planned case(s) covering ${plan.links.covers.length} requirement(s)`);
73
+ for (const tc of plan.testCases.slice(0, 20)) {
74
+ ctx.logger.info(` ${tc.id} [${tc.type}/${tc.status}] ${tc.name}`);
75
+ }
76
+ if (plan.testCases.length > 20) ctx.logger.info(` … ${plan.testCases.length - 20} more`);
77
+ for (const w of plan.validation.warnings) ctx.logger.warn(`warning: ${w}`);
78
+ if (artefactPath) ctx.logger.info(`Artefact: ${toPosix(artefactPath)}`);
79
+ else ctx.logger.info('Not persisted. Re-run with --write to store .aidf/artefacts/test-plan.json.');
80
+ return 0;
81
+ }