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,210 @@
1
+ import path from 'node:path';
2
+ import { parseArgs } from '../util/args.mjs';
3
+ import { resolveProjectRoot, isInitialized, aidfPaths } from '../core/paths.mjs';
4
+ import { loadConfig, validateConfig } from '../core/config.mjs';
5
+ import { loadManifest } from '../core/manifest.mjs';
6
+ import { buildSkillRegistry } from '../core/skills.mjs';
7
+ import { specKitStatus } from '../core/speckit.mjs';
8
+ import { loadEvidenceIndex, verifyEvidenceChain } from '../core/evidence.mjs';
9
+ import { loadWorkflowState } from '../core/workflow.mjs';
10
+ import { getAdapter } from '../core/adapters/index.mjs';
11
+ import { detectEnvironment } from '../core/detect.mjs';
12
+ import { exists, readText } from '../util/fsx.mjs';
13
+ import { attachLogFile } from '../util/logger.mjs';
14
+
15
+ export function doctorArgSpec() {
16
+ return {
17
+ booleans: ['json', 'help'],
18
+ aliases: { h: 'help', t: 'target' },
19
+ };
20
+ }
21
+
22
+ export async function doctorCommand(argv, ctx) {
23
+ const args = parseArgs(argv, doctorArgSpec());
24
+ if (args.help) {
25
+ ctx.logger.info('Usage: aidf doctor [--target <dir>] [--json]');
26
+ return 0;
27
+ }
28
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
29
+ if (!isInitialized(root)) {
30
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
31
+ return 1;
32
+ }
33
+ await attachLogFile(ctx.logger, root).catch(() => null);
34
+ const env = await detectEnvironment();
35
+ const checks = [];
36
+ const nodeMajor = Number(process.versions.node.split('.')[0]);
37
+ checks.push({
38
+ id: 'node-version',
39
+ status: nodeMajor >= 20 ? 'PASS' : 'FAIL',
40
+ detail: `Node ${process.versions.node}`,
41
+ });
42
+
43
+ let config = null;
44
+ let configError = null;
45
+ try {
46
+ config = await loadConfig(root);
47
+ const errors = validateConfig(config);
48
+ if (errors.length > 0) configError = errors.join('; ');
49
+ } catch (error) {
50
+ configError = error.message;
51
+ }
52
+ checks.push({
53
+ id: 'config',
54
+ status: configError ? 'FAIL' : 'PASS',
55
+ detail: configError ?? `.aidf/config.json (adapter=${config.adapter})`,
56
+ });
57
+
58
+ let manifest = null;
59
+ try {
60
+ manifest = await loadManifest(root);
61
+ const missing = [];
62
+ for (const rel of Object.keys(manifest.files)) {
63
+ if (!(await exists(path.join(root, rel)))) missing.push(rel);
64
+ }
65
+ checks.push({
66
+ id: 'manifest',
67
+ status: missing.length === 0 ? 'PASS' : 'FAIL',
68
+ detail: missing.length === 0
69
+ ? `${Object.keys(manifest.files).length} managed files present`
70
+ : `${missing.length} managed file(s) missing: ${missing.slice(0, 5).join(', ')}`,
71
+ });
72
+ } catch (error) {
73
+ checks.push({ id: 'manifest', status: 'FAIL', detail: error.message });
74
+ }
75
+
76
+ if (config) {
77
+ const docs = Object.entries(config.documents);
78
+ const counts = {};
79
+ for (const [, entry] of docs) counts[entry.status] = (counts[entry.status] ?? 0) + 1;
80
+ // Cross-check config statuses against the real document frontmatter:
81
+ // a config saying VALIDATED while the file says DRAFT (template without
82
+ // content) is a genuine FAIL, not a PASS.
83
+ const { splitFrontmatter } = await import('../util/frontmatter.mjs');
84
+ const mismatches = [];
85
+ for (const [doc, entry] of docs) {
86
+ const file = path.join(root, '.aidf', 'docs', `${doc}.md`);
87
+ if (!(await exists(file))) continue;
88
+ try {
89
+ const fm = splitFrontmatter(await readText(file)).frontmatter;
90
+ const fileStatus = fm && typeof fm === 'object' ? fm.status : null;
91
+ if (fileStatus && fileStatus !== entry.status) {
92
+ mismatches.push(`${doc}: file=${fileStatus} config=${entry.status}`);
93
+ }
94
+ } catch {
95
+ mismatches.push(`${doc}: unreadable document file`);
96
+ }
97
+ }
98
+ checks.push({
99
+ id: 'documents',
100
+ status: mismatches.length > 0 ? 'FAIL' : counts.VALIDATED > 0 ? 'PASS' : 'WARN',
101
+ detail:
102
+ (Object.entries(counts).map(([k, v]) => `${k}=${v}`).join(' '))
103
+ + (mismatches.length > 0 ? ` | status mismatch: ${mismatches.slice(0, 5).join('; ')}` : ''),
104
+ problems: mismatches,
105
+ });
106
+ const missingDocs = [];
107
+ for (const doc of Object.keys(config.documents)) {
108
+ if (!(await exists(path.join(root, '.aidf', 'docs', `${doc}.md`)))) missingDocs.push(doc);
109
+ }
110
+ checks.push({
111
+ id: 'document-files',
112
+ status: missingDocs.length === 0 ? 'PASS' : 'FAIL',
113
+ detail: missingDocs.length === 0 ? 'all document files present' : `missing: ${missingDocs.join(', ')}`,
114
+ });
115
+
116
+ const adapter = getAdapter(config.adapter);
117
+ const verification = await adapter.verify({
118
+ root,
119
+ frameworkRoot: ctx.frameworkRoot,
120
+ config,
121
+ env,
122
+ withHooks: Boolean(manifest?.files?.['.aidf/hooks/audit.mjs']),
123
+ });
124
+ checks.push({
125
+ id: `adapter-${config.adapter}`,
126
+ status: verification.status === 'FAIL' ? 'FAIL' : verification.status === 'NOT_PROVEN' ? 'NOT_PROVEN' : 'PASS',
127
+ detail: `${verification.status}: ${verification.checks.filter((c) => c.status === 'PASS').length}/${verification.checks.length} checks PASS`,
128
+ checks: verification.checks,
129
+ limitations: verification.limitations,
130
+ });
131
+ }
132
+
133
+ const registry = await buildSkillRegistry(root, { adapter: config?.adapter ?? 'qoder', frameworkRoot: ctx.frameworkRoot });
134
+ const builtinBad = registry.skills.filter((s) => s.source === 'builtin' && s.status !== 'AVAILABLE');
135
+ checks.push({
136
+ id: 'skills',
137
+ status: builtinBad.length === 0 ? 'PASS' : 'FAIL',
138
+ detail: `${registry.summary.AVAILABLE ?? 0} available, ${registry.summary.BLOCKED ?? 0} blocked, ${registry.summary.INCOMPATIBLE ?? 0} incompatible`,
139
+ problems: builtinBad.map((s) => `${s.id}: ${s.status}`),
140
+ });
141
+
142
+ const speckit = await specKitStatus(root, { frameworkRoot: ctx.frameworkRoot, specifyPath: env.specKit.cliPath });
143
+ checks.push({
144
+ id: 'spec-kit',
145
+ status: speckit.present ? (speckit.integrationConfigured ? 'PASS' : 'WARN') : 'NOT_APPLICABLE',
146
+ detail: speckit.present
147
+ ? `.specify present; integration skills=${speckit.integrationSkills.length}; constitution=${speckit.constitutionSync}`
148
+ : '.specify absent',
149
+ });
150
+
151
+ const evidenceIndex = await loadEvidenceIndex(root);
152
+ const chain = await verifyEvidenceChain(root);
153
+ checks.push({
154
+ id: 'evidence-integrity',
155
+ status: chain.ok ? 'PASS' : 'FAIL',
156
+ detail: chain.ok
157
+ ? `${chain.checked} evidence record(s) verified (hash + previous links + index)`
158
+ : `${chain.problems.length} chain problem(s): ${chain.problems.slice(0, 5).map((p) => `${p.code}${p.file ? ` (${p.file})` : ''}`).join('; ')}`,
159
+ problems: chain.problems.map((p) => `${p.code}: ${p.file ?? 'index'} — ${p.reason}`),
160
+ });
161
+
162
+ const declaredOnly = evidenceIndex.entries.filter((e) => e.humanApproval && !e.authenticatedApproval);
163
+ checks.push({
164
+ id: 'approvals',
165
+ status: declaredOnly.length > 0 ? 'WARN' : 'PASS',
166
+ detail: declaredOnly.length > 0
167
+ ? `${declaredOnly.length} declared approval(s) are not authenticated (requireAuthenticatedApproval=${config?.security?.requireAuthenticatedApproval === true}).`
168
+ : 'no declared-only approval recorded',
169
+ });
170
+
171
+ const state = await loadWorkflowState(root);
172
+ checks.push({
173
+ id: 'workflow',
174
+ status: 'PASS',
175
+ detail: `phase=${state.currentPhase}${state.completed ? ' (completed)' : ''}`,
176
+ });
177
+
178
+ if (config) {
179
+ checks.push({
180
+ id: 'security-policy',
181
+ status: 'PASS',
182
+ detail: `commandExecution=${config.security.allowCommandExecution} network=${config.security.allowNetwork} approvals=${(config.security.requireHumanApprovalFor ?? []).join(',')} authenticatedApprovalRequired=${config.security.requireAuthenticatedApproval === true}`,
183
+ });
184
+ }
185
+
186
+ if (ctx.json) {
187
+ process.stdout.write(`${JSON.stringify({ root, checks, skills: registry.summary, specKit: speckit }, null, 2)}\n`);
188
+ } else {
189
+ ctx.logger.info(`AIDF doctor — ${root}`);
190
+ ctx.logger.table(
191
+ checks.map((c) => ({ id: c.id, status: c.status, detail: c.detail })),
192
+ [
193
+ { key: 'id', label: 'Check' },
194
+ { key: 'status', label: 'Status' },
195
+ { key: 'detail', label: 'Detail' },
196
+ ],
197
+ );
198
+ const failed = checks.filter((c) => c.status === 'FAIL');
199
+ const notProven = checks.filter((c) => c.status === 'NOT_PROVEN');
200
+ if (failed.length > 0) ctx.logger.error(`${failed.length} check(s) failed.`);
201
+ if (notProven.length > 0) ctx.logger.warn(`${notProven.length} check(s) NOT_PROVEN; see adapter checks.`);
202
+ const adapterCheck = checks.find((c) => c.id.startsWith('adapter-'));
203
+ if (adapterCheck?.checks) {
204
+ for (const c of adapterCheck.checks.filter((x) => x.status === 'NOT_PROVEN')) {
205
+ ctx.logger.warn(`${c.id}: ${c.limitation ?? 'not proven'}`);
206
+ }
207
+ }
208
+ }
209
+ return checks.some((c) => c.status === 'FAIL') ? 1 : 0;
210
+ }
@@ -0,0 +1,178 @@
1
+ import { parseArgs } from '../util/args.mjs';
2
+ import { resolveProjectRoot, isInitialized } from '../core/paths.mjs';
3
+ import { loadConfig } from '../core/config.mjs';
4
+ import {
5
+ recordEvidence, listEvidence, verifyEvidenceChain, captureFiles,
6
+ } from '../core/evidence.mjs';
7
+ import { attachLogFile } from '../util/logger.mjs';
8
+
9
+ export function evidenceArgSpec() {
10
+ return {
11
+ booleans: ['json', 'human', 'help', 'verify'],
12
+ aliases: { h: 'help', t: 'target' },
13
+ };
14
+ }
15
+
16
+ export async function evidenceCommand(argv, ctx) {
17
+ const args = parseArgs(argv, evidenceArgSpec());
18
+ const sub = args._[0] ?? 'list';
19
+ if (args.help) {
20
+ ctx.logger.info('Usage: aidf evidence <list|show|capture|add|verify> [options]');
21
+ ctx.logger.info(' add --type <type> --note "..." [--human --by <name>]');
22
+ ctx.logger.info(' capture --type implementation-change --note "..."');
23
+ return 0;
24
+ }
25
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
26
+ if (!isInitialized(root)) {
27
+ ctx.logger.error(`AIDF is not initialized in ${root}. Run "aidf install" first.`);
28
+ return 1;
29
+ }
30
+ await attachLogFile(ctx.logger, root).catch(() => null);
31
+ const config = await loadConfig(root);
32
+
33
+ if (sub === 'list') {
34
+ const entries = await listEvidence(root, { type: args.type, status: args.status, gate: args.gate });
35
+ if (ctx.json) process.stdout.write(`${JSON.stringify(entries, null, 2)}\n`);
36
+ else {
37
+ ctx.logger.info(`Evidence (${entries.length})`);
38
+ ctx.logger.table(
39
+ entries.map((e) => ({
40
+ id: e.id.slice(0, 22),
41
+ type: e.type,
42
+ status: e.status,
43
+ human: e.humanApproval ? 'yes' : 'no',
44
+ created: e.createdAt,
45
+ })),
46
+ [
47
+ { key: 'id', label: 'ID' },
48
+ { key: 'type', label: 'Type' },
49
+ { key: 'status', label: 'Status' },
50
+ { key: 'human', label: 'Human' },
51
+ { key: 'created', label: 'Created' },
52
+ ],
53
+ );
54
+ }
55
+ return 0;
56
+ }
57
+
58
+ if (sub === 'verify') {
59
+ const chain = await verifyEvidenceChain(root);
60
+ const bad = chain.problems.map((p) => ({
61
+ file: p.file,
62
+ reason: `${p.code}: ${p.reason}`,
63
+ }));
64
+ if (ctx.json) {
65
+ process.stdout.write(`${JSON.stringify({
66
+ ok: chain.ok,
67
+ checked: chain.checked,
68
+ problems: chain.problems,
69
+ bad,
70
+ }, null, 2)}\n`);
71
+ } else {
72
+ ctx.logger.info(`Verified ${chain.checked} evidence record(s) and the chain.`);
73
+ for (const item of bad) ctx.logger.error(`${item.file ?? 'index'}: ${item.reason}`);
74
+ }
75
+ return chain.ok ? 0 : 1;
76
+ }
77
+
78
+ if (sub === 'show') {
79
+ const id = args._[1];
80
+ const entries = await listEvidence(root);
81
+ const entry = entries.find((e) => e.id === id || e.id.startsWith(id ?? ''));
82
+ if (!entry) {
83
+ ctx.logger.error(`Unknown evidence: ${id}`);
84
+ return 1;
85
+ }
86
+ const { readJson } = await import('../util/fsx.mjs');
87
+ const body = await readJson(`${root}/${entry.file}`, null);
88
+ process.stdout.write(`${JSON.stringify(body, null, 2)}\n`);
89
+ return 0;
90
+ }
91
+
92
+ if (sub === 'capture') {
93
+ const type = args.type;
94
+ if (!type) {
95
+ ctx.logger.error('Missing --type (for example implementation-change).');
96
+ return 1;
97
+ }
98
+ const captured = await captureFiles(root, { since: args.since });
99
+ if (captured.files.length === 0) {
100
+ ctx.logger.warn('No changed files detected. Evidence was not recorded (NOT_PROVEN).');
101
+ return 1;
102
+ }
103
+ const evidence = await recordEvidence(root, {
104
+ type,
105
+ status: args.status ?? 'PASS',
106
+ summary: args.note ?? `${captured.files.length} changed file(s) captured from ${captured.source}.`,
107
+ note: args.note ?? '',
108
+ createdBy: args.human ? 'human' : 'aidf',
109
+ humanApproval: Boolean(args.human),
110
+ approvedBy: args.by ?? null,
111
+ approval: args.human
112
+ ? {
113
+ declaredBy: args.by ?? null,
114
+ declaredAt: new Date().toISOString(),
115
+ authenticated: false,
116
+ method: 'declared',
117
+ keyId: null,
118
+ }
119
+ : { declaredBy: null, declaredAt: null, authenticated: false, method: 'none', keyId: null },
120
+ files: captured.files,
121
+ checks: [{
122
+ id: 'files-captured',
123
+ status: 'PASS',
124
+ reason: `${captured.files.length} file(s) from ${captured.source}`,
125
+ }],
126
+ limitations: ['File list is not a review of the content or quality of the change.'],
127
+ });
128
+ ctx.logger.info(`Evidence recorded: ${evidence.file}`);
129
+ return 0;
130
+ }
131
+
132
+ if (sub === 'add') {
133
+ const type = args.type;
134
+ if (!type) {
135
+ ctx.logger.error('Missing --type.');
136
+ return 1;
137
+ }
138
+ if (args.human && !args.by) {
139
+ ctx.logger.error('Human evidence requires --by "<name>" for accountability.');
140
+ return 1;
141
+ }
142
+ if (args.human && config.security?.requireHumanApprovalFor?.length) {
143
+ // human approval is allowed for any type; the gate decides which types require it
144
+ }
145
+ const evidence = await recordEvidence(root, {
146
+ type,
147
+ status: args.status ?? 'PASS',
148
+ summary: args.note ?? `${type} recorded manually.`,
149
+ note: args.note ?? '',
150
+ createdBy: args.human ? 'human' : 'agent',
151
+ humanApproval: Boolean(args.human),
152
+ approvedBy: args.by ?? null,
153
+ approval: args.human
154
+ ? {
155
+ declaredBy: args.by ?? null,
156
+ declaredAt: new Date().toISOString(),
157
+ authenticated: false,
158
+ method: 'declared',
159
+ keyId: null,
160
+ }
161
+ : { declaredBy: null, declaredAt: null, authenticated: false, method: 'none', keyId: null },
162
+ files: [],
163
+ checks: [{
164
+ id: 'manual-record',
165
+ status: args.human ? 'PASS' : 'NOT_PROVEN',
166
+ reason: args.human ? `Approved by ${args.by}` : 'Agent declaration only; not a human approval.',
167
+ }],
168
+ limitations: args.human
169
+ ? ['Declared approval is not authenticated: it records intent, not proof that a human performed the action.']
170
+ : ['Agent-declared evidence is not human approval.'],
171
+ });
172
+ ctx.logger.info(`Evidence recorded: ${evidence.file}`);
173
+ return 0;
174
+ }
175
+
176
+ ctx.logger.error(`Unknown evidence subcommand: ${sub}`);
177
+ return 1;
178
+ }
@@ -0,0 +1,154 @@
1
+ import path from 'node:path';
2
+ import fsp from 'node:fs/promises';
3
+ import { parseArgs, assertEnum } from '../util/args.mjs';
4
+ import { slugify } from '../util/text.mjs';
5
+ import { ensureDir, exists, writeJson, readJson } from '../util/fsx.mjs';
6
+ import { resolveProjectRoot, aidfPaths, AIDF_VERSION } from '../core/paths.mjs';
7
+ import { defaultConfig, loadConfig, saveConfig } from '../core/config.mjs';
8
+ import { emptyManifest, loadManifest, saveManifest, appendHistory } from '../core/manifest.mjs';
9
+ import { planCore, renderInstallReport } from '../core/bootstrap.mjs';
10
+ import { Installer, summarizeResults } from '../core/installer.mjs';
11
+ import { getAdapter, ADAPTER_KEYS } from '../core/adapters/index.mjs';
12
+ import { detectEnvironment, detectProject } from '../core/detect.mjs';
13
+ import { buildSkillRegistry, saveProjectSkillRegistry } from '../core/skills.mjs';
14
+ import { attachLogFile } from '../util/logger.mjs';
15
+
16
+ export function installArgSpec() {
17
+ return {
18
+ booleans: ['dry-run', 'force', 'yes', 'json', 'with-hooks', 'update', 'help'],
19
+ aliases: { h: 'help', n: 'name', a: 'adapter', t: 'target' },
20
+ };
21
+ }
22
+
23
+ export async function installCommand(argv, ctx) {
24
+ const args = parseArgs(argv, installArgSpec());
25
+ if (args.help) {
26
+ ctx.logger.info('Usage: aidf install [--target <dir>] [--adapter qoder|opencode|generic] [--name <name>] [--with-hooks] [--dry-run] [--force]');
27
+ return 0;
28
+ }
29
+ const adapterKey = assertEnum(args.adapter, ADAPTER_KEYS, 'adapter') ?? 'qoder';
30
+ const root = resolveProjectRoot({ target: args.target, cwd: process.cwd() });
31
+ if (!(await exists(root))) {
32
+ if (!args.dryRun) await ensureDir(root);
33
+ }
34
+ // Dry-run must not create any project file, including logs.
35
+ if (!args['dry-run']) await attachLogFile(ctx.logger, root).catch(() => null);
36
+ const env = await detectEnvironment();
37
+ const project = await detectProject(root);
38
+ const adapter = getAdapter(adapterKey);
39
+
40
+ const paths = aidfPaths(root);
41
+ let config = await readJson(paths.config, null);
42
+ const projectName = args.name ?? project.packageJson?.name ?? path.basename(root);
43
+ if (!config) {
44
+ config = defaultConfig({
45
+ name: projectName,
46
+ slug: slugify(projectName),
47
+ adapter: adapterKey,
48
+ commands: {
49
+ test: project.packageJson?.scripts?.test ?? null,
50
+ build: project.packageJson?.scripts?.build ?? null,
51
+ lint: project.packageJson?.scripts?.lint ?? null,
52
+ securityAudit: null,
53
+ },
54
+ });
55
+ } else {
56
+ config.adapter = adapterKey;
57
+ config.framework.version = AIDF_VERSION;
58
+ if (args.name) {
59
+ config.project.name = args.name;
60
+ config.project.slug = slugify(args.name);
61
+ }
62
+ if (!config.commands) {
63
+ config.commands = {
64
+ test: project.packageJson?.scripts?.test ?? null,
65
+ build: project.packageJson?.scripts?.build ?? null,
66
+ lint: project.packageJson?.scripts?.lint ?? null,
67
+ securityAudit: null,
68
+ };
69
+ }
70
+ }
71
+
72
+ let manifest = await readJson(paths.manifest, null);
73
+ if (!manifest) manifest = emptyManifest({ name: config.project.name, slug: config.project.slug, adapter: adapterKey });
74
+ manifest.adapter = adapterKey;
75
+ manifest.framework.version = AIDF_VERSION;
76
+
77
+ const { actions } = await planCore(root, { frameworkRoot: ctx.frameworkRoot });
78
+ const adapterActions = await adapter.plan({
79
+ root,
80
+ frameworkRoot: ctx.frameworkRoot,
81
+ config,
82
+ withHooks: Boolean(args['with-hooks']),
83
+ env,
84
+ });
85
+ const allActions = [...actions, ...adapterActions];
86
+
87
+ const installer = new Installer({
88
+ root,
89
+ manifest,
90
+ logger: ctx.logger,
91
+ dryRun: Boolean(args['dry-run']),
92
+ force: Boolean(args.force),
93
+ });
94
+ const results = await installer.apply(allActions);
95
+ const summary = summarizeResults(results);
96
+
97
+ if (!args['dry-run']) {
98
+ await ensureDir(paths.registry);
99
+ await saveConfig(root, config);
100
+ appendHistory(manifest, {
101
+ event: 'install',
102
+ version: AIDF_VERSION,
103
+ adapter: adapterKey,
104
+ summary,
105
+ });
106
+ await saveManifest(root, manifest);
107
+
108
+ const registry = await buildSkillRegistry(root, { adapter: adapterKey, frameworkRoot: ctx.frameworkRoot });
109
+ await saveProjectSkillRegistry(root, registry);
110
+
111
+ const report = renderInstallReport({
112
+ root,
113
+ projectName: config.project.name,
114
+ adapter: adapterKey,
115
+ results,
116
+ summary,
117
+ version: AIDF_VERSION,
118
+ });
119
+ await fsp.mkdir(paths.reports, { recursive: true });
120
+ await fsp.writeFile(path.join(paths.reports, 'install.md'), report, 'utf8');
121
+ }
122
+
123
+ if (ctx.json) {
124
+ process.stdout.write(`${JSON.stringify({ root, adapter: adapterKey, summary, results }, null, 2)}\n`);
125
+ } else {
126
+ ctx.logger.info(`${args['dry-run'] ? '[dry-run] ' : ''}AIDF ${args.update ? 'update' : 'install'} — ${config.project.name} (${adapterKey})`);
127
+ ctx.logger.info(`created=${summary.created} updated=${summary.updated} unchanged=${summary.unchanged} conflicts=${summary.conflicts} failed=${summary.failed} would=${summary.would}`);
128
+ for (const result of results.filter((r) => r.status === 'CONFLICT' || r.status === 'FAILED')) {
129
+ ctx.logger.warn(`${result.status} ${result.path}: ${result.reason ?? ''}`);
130
+ }
131
+ if (summary.conflicts > 0) {
132
+ ctx.logger.warn('Existing files were preserved. Review conflicts, then merge or use --force only for AIDF-managed files.');
133
+ }
134
+ ctx.logger.info('Next: node .aidf/bin/aidf.mjs doctor');
135
+ }
136
+ return summary.failed > 0 ? 1 : summary.conflicts > 0 ? 2 : 0;
137
+ }
138
+
139
+ export async function initCommand(argv, ctx) {
140
+ const args = parseArgs(argv, installArgSpec());
141
+ const positional = args._[0];
142
+ if (positional && !args.target) {
143
+ const index = argv.indexOf(positional);
144
+ const next = [...argv.slice(0, index), '--target', positional, ...argv.slice(index + 1)];
145
+ return installCommand(next, ctx);
146
+ }
147
+ return installCommand(argv, ctx);
148
+ }
149
+
150
+ export async function updateCommand(argv, ctx) {
151
+ const args = parseArgs(argv, installArgSpec());
152
+ args.update = true;
153
+ return installCommand(argv, ctx);
154
+ }