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.
- package/CHANGELOG.md +174 -0
- package/INSTALLATION.md +140 -0
- package/LICENSE +21 -0
- package/QODER.md +88 -0
- package/README.md +142 -2
- package/UTILISATION.md +188 -0
- package/assets/adapters/qoder/agents/aidf-orchestrator.md +30 -0
- package/assets/adapters/qoder/rules/00-core.md +28 -0
- package/assets/adapters/qoder/rules/10-security.md +33 -0
- package/assets/adapters/qoder/rules/20-context.md +39 -0
- package/assets/core/AGENTS.fragment.md +18 -0
- package/assets/core/AIDF.md +107 -0
- package/assets/docs/APPFLOW.md +66 -0
- package/assets/docs/BACKEND.md +71 -0
- package/assets/docs/CHANGELOG.md +25 -0
- package/assets/docs/CONVENTIONS.md +95 -0
- package/assets/docs/DECISIONS.md +60 -0
- package/assets/docs/PLAN.md +53 -0
- package/assets/docs/PRD.md +88 -0
- package/assets/docs/SECURITY.md +94 -0
- package/assets/docs/TRD.md +78 -0
- package/assets/docs/UI-UX.md +71 -0
- package/assets/docs/constitution.md +86 -0
- package/assets/hooks/audit.mjs +45 -0
- package/assets/hooks/session-context.mjs +53 -0
- package/assets/integrations/spec-kit/mapping.yaml +92 -0
- package/assets/knowledge/best-practices/testing.md +53 -0
- package/assets/knowledge/best-practices/web-dev-baseline.md +39 -0
- package/assets/knowledge/rules/api.md +45 -0
- package/assets/knowledge/rules/sql.md +44 -0
- package/assets/knowledge/rules/typescript.md +50 -0
- package/assets/knowledge/security-references/owasp-baseline.md +58 -0
- package/assets/registry/activation-map.yaml +83 -0
- package/assets/registry/dependencies.yaml +35 -0
- package/assets/registry/skills.yaml +541 -0
- package/assets/registry/sources.yaml +396 -0
- package/assets/schemas/architecture/v1.json +110 -0
- package/assets/schemas/constraints/v1.json +93 -0
- package/assets/schemas/decision/v1.json +106 -0
- package/assets/schemas/discovery/v1.json +91 -0
- package/assets/schemas/requirement/v1.json +136 -0
- package/assets/schemas/security/threat-model/v1.json +127 -0
- package/assets/schemas/test-plan/v1.json +108 -0
- package/assets/skills/aidf-architecture-review/SKILL.md +49 -0
- package/assets/skills/aidf-backend-implementation/SKILL.md +47 -0
- package/assets/skills/aidf-database-design/SKILL.md +48 -0
- package/assets/skills/aidf-devops-engineering/SKILL.md +41 -0
- package/assets/skills/aidf-documentation-maintenance/SKILL.md +41 -0
- package/assets/skills/aidf-frontend-implementation/SKILL.md +44 -0
- package/assets/skills/aidf-phase-transition/SKILL.md +48 -0
- package/assets/skills/aidf-product-analysis/SKILL.md +47 -0
- package/assets/skills/aidf-project-context/SKILL.md +57 -0
- package/assets/skills/aidf-requirements-engineering/SKILL.md +52 -0
- package/assets/skills/aidf-security-review/SKILL.md +57 -0
- package/assets/skills/aidf-testing-validation/SKILL.md +48 -0
- package/assets/skills/aidf-ui-ux-implementation/SKILL.md +43 -0
- package/assets/workflows/gates.yaml +232 -0
- package/assets/workflows/phases.yaml +161 -0
- package/bin/aidf.mjs +12 -0
- package/demo/run-demo.mjs +97 -0
- package/docs/aidf/ADR-001-artefacts-architectur.md +126 -0
- package/docs/aidf/ADR-002-requirements-registry.md +145 -0
- package/docs/aidf/ADR-003-traceability-chain.md +145 -0
- package/docs/aidf/ADR-004-markdown-generation.md +134 -0
- package/docs/aidf/ADR-005-validation-and-tests.md +170 -0
- package/docs/aidf/ADR-006-cli-commands.md +189 -0
- package/docs/aidf/ADR-007-compatibility-and-migration.md +119 -0
- package/docs/aidf/ADR-008-schema-versioning.md +115 -0
- package/docs/aidf/ADR-009-artefacts-scope.md +84 -0
- package/docs/aidf/ARCHITECTURE.md +137 -0
- package/docs/aidf/COMPATIBILITY.md +90 -0
- package/docs/aidf/DECISIONS.md +200 -0
- package/docs/aidf/FRAMEWORK.md +38 -0
- package/docs/aidf/IDE-QODER.md +61 -0
- package/docs/aidf/INSTALL.md +99 -0
- package/docs/aidf/INVENTORY.md +72 -0
- package/docs/aidf/L1-ARCHITECTURE-RAPPORT.md +353 -0
- package/docs/aidf/LIMITATIONS.md +69 -0
- package/docs/aidf/MATRICE-0.1.0-vers-0.2.0.md +155 -0
- package/docs/aidf/SECURITY.md +86 -0
- package/docs/aidf/SKILLS.md +78 -0
- package/docs/aidf/SPECKIT.md +67 -0
- package/docs/aidf/USAGE.md +113 -0
- package/docs/aidf/VALIDATION.md +55 -0
- package/package.json +37 -4
- package/src/cli.mjs +148 -0
- package/src/commands/artefacts.mjs +129 -0
- package/src/commands/config.mjs +130 -0
- package/src/commands/context.mjs +55 -0
- package/src/commands/decision.mjs +142 -0
- package/src/commands/design.mjs +141 -0
- package/src/commands/docs.mjs +133 -0
- package/src/commands/doctor.mjs +210 -0
- package/src/commands/evidence.mjs +178 -0
- package/src/commands/install.mjs +154 -0
- package/src/commands/release.mjs +214 -0
- package/src/commands/requirements.mjs +196 -0
- package/src/commands/resources.mjs +181 -0
- package/src/commands/scan.mjs +139 -0
- package/src/commands/security.mjs +97 -0
- package/src/commands/setup.mjs +68 -0
- package/src/commands/skills.mjs +204 -0
- package/src/commands/speckit.mjs +78 -0
- package/src/commands/tests.mjs +81 -0
- package/src/commands/traceability.mjs +116 -0
- package/src/commands/uninstall.mjs +238 -0
- package/src/commands/validate.mjs +84 -0
- package/src/commands/workflow.mjs +137 -0
- package/src/core/adapters/base.mjs +32 -0
- package/src/core/adapters/generic.mjs +70 -0
- package/src/core/adapters/index.mjs +24 -0
- package/src/core/adapters/opencode.mjs +115 -0
- package/src/core/adapters/qoder.mjs +228 -0
- package/src/core/artefacts/index.mjs +1 -0
- package/src/core/artefacts/validation.mjs +161 -0
- package/src/core/bootstrap.mjs +179 -0
- package/src/core/config.mjs +123 -0
- package/src/core/context.mjs +187 -0
- package/src/core/design-engineering/complexity-classifier.mjs +78 -0
- package/src/core/design-engineering/engine.mjs +197 -0
- package/src/core/design-engineering/fallback/mockups.mjs +221 -0
- package/src/core/design-engineering/fallback/wireframes.mjs +114 -0
- package/src/core/design-engineering/figma/validators.mjs +178 -0
- package/src/core/design-engineering/index.mjs +9 -0
- package/src/core/design-engineering/visual-parity/capture.mjs +172 -0
- package/src/core/detect.mjs +220 -0
- package/src/core/docsgen.mjs +175 -0
- package/src/core/evidence.mjs +210 -0
- package/src/core/installer.mjs +377 -0
- package/src/core/manifest.mjs +53 -0
- package/src/core/paths.mjs +94 -0
- package/src/core/requirements/index.mjs +13 -0
- package/src/core/requirements/registry.mjs +234 -0
- package/src/core/resource-inventory.mjs +434 -0
- package/src/core/resources.mjs +280 -0
- package/src/core/security/threat-model.mjs +235 -0
- package/src/core/skills.mjs +353 -0
- package/src/core/source-skills.mjs +213 -0
- package/src/core/speckit.mjs +195 -0
- package/src/core/technology-decision/analyzer-deterministic.mjs +240 -0
- package/src/core/technology-decision/engine.mjs +157 -0
- package/src/core/technology-decision/generator.mjs +204 -0
- package/src/core/technology-decision/index.mjs +17 -0
- package/src/core/technology-decision/options/index.mjs +10 -0
- package/src/core/testplan.mjs +176 -0
- package/src/core/traceability/chain.mjs +488 -0
- package/src/core/traceability/index.mjs +12 -0
- package/src/core/workflow.mjs +471 -0
- package/src/util/args.mjs +69 -0
- package/src/util/frontmatter.mjs +26 -0
- package/src/util/fsx.mjs +208 -0
- package/src/util/logger.mjs +74 -0
- package/src/util/text.mjs +66 -0
- package/src/util/yaml.mjs +379 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { aidfPaths, AIDF_VERSION } from '../paths.mjs';
|
|
2
|
+
import { readJson, writeJson, exists, readDirSafe } from '../../util/fsx.mjs';
|
|
3
|
+
|
|
4
|
+
export const LINK_TYPES = ['implements', 'designed-by', 'implemented-by', 'verified-by', 'evidenced-by'];
|
|
5
|
+
|
|
6
|
+
export const TRACEABILITY_TYPES = {
|
|
7
|
+
requirement: 'requirement',
|
|
8
|
+
design: 'design',
|
|
9
|
+
implementation: 'implementation',
|
|
10
|
+
test: 'test',
|
|
11
|
+
evidence: 'evidence'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Recursively collect artefact JSON files under the artefacts directory.
|
|
16
|
+
* Returns [{ id, path, body }] for every parseable file exposing an `id`.
|
|
17
|
+
*/
|
|
18
|
+
export async function collectArtefactFiles(root) {
|
|
19
|
+
const found = [];
|
|
20
|
+
const artefactsDir = aidfPaths(root).artefacts.dir;
|
|
21
|
+
if (!await exists(artefactsDir)) {
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function walk(dir) {
|
|
26
|
+
const entries = await readDirSafe(dir);
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
const full = `${dir}/${entry.name}`;
|
|
29
|
+
if (entry.isDirectory()) {
|
|
30
|
+
await walk(full);
|
|
31
|
+
} else if (entry.isFile() && entry.name.endsWith('.json') && entry.name !== 'index.json') {
|
|
32
|
+
try {
|
|
33
|
+
const body = await readJson(full, null);
|
|
34
|
+
if (body && body.id) {
|
|
35
|
+
found.push({ id: body.id, path: full, body });
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// Skip malformed files
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await walk(artefactsDir);
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Load all artefacts from the artefacts directory.
|
|
50
|
+
*/
|
|
51
|
+
export async function loadAllArtefacts(root) {
|
|
52
|
+
const artefacts = new Map();
|
|
53
|
+
for (const { id, body } of await collectArtefactFiles(root)) {
|
|
54
|
+
artefacts.set(id, body);
|
|
55
|
+
}
|
|
56
|
+
return artefacts;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Resolve the on-disk path of an artefact by ID.
|
|
61
|
+
*/
|
|
62
|
+
export async function artefactFilePath(root, artefactId) {
|
|
63
|
+
const files = await collectArtefactFiles(root);
|
|
64
|
+
const hit = files.find((f) => f.id === artefactId);
|
|
65
|
+
return hit ? hit.path : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Load a specific artefact by ID.
|
|
70
|
+
*/
|
|
71
|
+
export async function loadArtefact(root, artefactId) {
|
|
72
|
+
const artefacts = await loadAllArtefacts(root);
|
|
73
|
+
return artefacts.get(artefactId) || null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Resolve a link to its target artefact.
|
|
78
|
+
*/
|
|
79
|
+
export async function resolveLink(root, targetId) {
|
|
80
|
+
const artefacts = await loadAllArtefacts(root);
|
|
81
|
+
return artefacts.get(targetId) || null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Create a link between two artefacts.
|
|
86
|
+
*/
|
|
87
|
+
export async function createLink(root, sourceId, targetType, targetId, options = {}) {
|
|
88
|
+
const artefacts = await loadAllArtefacts(root);
|
|
89
|
+
|
|
90
|
+
const source = artefacts.get(sourceId);
|
|
91
|
+
if (!source) {
|
|
92
|
+
throw new Error(`Source artefact not found: ${sourceId}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const target = artefacts.get(targetId);
|
|
96
|
+
if (!target) {
|
|
97
|
+
throw new Error(`Target artefact not found: ${targetId}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Determine link type based on target type
|
|
101
|
+
const linkType = getLinkType(targetType, source.type);
|
|
102
|
+
if (!linkType) {
|
|
103
|
+
throw new Error(`Invalid link: ${source.type} -> ${targetType}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Add link to source
|
|
107
|
+
if (!source.links) {
|
|
108
|
+
source.links = {};
|
|
109
|
+
}
|
|
110
|
+
if (!source.links[linkType]) {
|
|
111
|
+
source.links[linkType] = [];
|
|
112
|
+
}
|
|
113
|
+
if (!source.links[linkType].includes(targetId)) {
|
|
114
|
+
source.links[linkType].push(targetId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Add reverse link to target
|
|
118
|
+
const reverseLinkType = getReverseLinkType(linkType);
|
|
119
|
+
if (!target.links) {
|
|
120
|
+
target.links = {};
|
|
121
|
+
}
|
|
122
|
+
if (!target.links[reverseLinkType]) {
|
|
123
|
+
target.links[reverseLinkType] = [];
|
|
124
|
+
}
|
|
125
|
+
if (!target.links[reverseLinkType].includes(sourceId)) {
|
|
126
|
+
target.links[reverseLinkType].push(sourceId);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Update both artefacts
|
|
130
|
+
const sourcePath = await artefactFilePath(root, sourceId);
|
|
131
|
+
const targetPath = await artefactFilePath(root, targetId);
|
|
132
|
+
if (!sourcePath || !targetPath) {
|
|
133
|
+
throw new Error('Artefact file path could not be resolved.');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
await writeJson(sourcePath, source);
|
|
137
|
+
await writeJson(targetPath, target);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
source,
|
|
141
|
+
target,
|
|
142
|
+
linkType,
|
|
143
|
+
reverseLinkType
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Get the link type for a forward connection.
|
|
149
|
+
*/
|
|
150
|
+
function getLinkType(targetType, sourceType) {
|
|
151
|
+
const linkMap = {
|
|
152
|
+
requirement: {
|
|
153
|
+
design: 'designed-by',
|
|
154
|
+
implementation: 'implemented-by',
|
|
155
|
+
test: 'verified-by',
|
|
156
|
+
evidence: 'evidenced-by'
|
|
157
|
+
},
|
|
158
|
+
design: {
|
|
159
|
+
requirement: 'implements',
|
|
160
|
+
implementation: 'implemented-by',
|
|
161
|
+
test: 'verified-by'
|
|
162
|
+
},
|
|
163
|
+
implementation: {
|
|
164
|
+
requirement: 'implements',
|
|
165
|
+
design: 'designed-by',
|
|
166
|
+
test: 'verified-by'
|
|
167
|
+
},
|
|
168
|
+
test: {
|
|
169
|
+
requirement: 'verifies',
|
|
170
|
+
design: 'designs',
|
|
171
|
+
implementation: 'implements'
|
|
172
|
+
},
|
|
173
|
+
evidence: {
|
|
174
|
+
test: 'evidences',
|
|
175
|
+
requirement: 'evidences'
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return linkMap[targetType]?.[sourceType] || null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get the reverse link type.
|
|
184
|
+
*/
|
|
185
|
+
function getReverseLinkType(linkType) {
|
|
186
|
+
const reverseMap = {
|
|
187
|
+
'implements': 'implemented-by',
|
|
188
|
+
'designed-by': 'designs',
|
|
189
|
+
'implemented-by': 'implements',
|
|
190
|
+
'verified-by': 'verifies',
|
|
191
|
+
'evidenced-by': 'evidences',
|
|
192
|
+
'verifies': 'verified-by',
|
|
193
|
+
'designs': 'designed-by',
|
|
194
|
+
'evidences': 'evidenced-by'
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return reverseMap[linkType] || null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Verify a traceability chain for a given artefact.
|
|
202
|
+
* Returns { ok, path, brokenLinks, coverage }
|
|
203
|
+
*/
|
|
204
|
+
export async function verifyChain(root, artefactId, options = {}) {
|
|
205
|
+
const artefacts = await loadAllArtefacts(root);
|
|
206
|
+
const start = artefacts.get(artefactId);
|
|
207
|
+
|
|
208
|
+
if (!start) {
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
artefactId,
|
|
212
|
+
brokenLinks: [`Artefact not found: ${artefactId}`],
|
|
213
|
+
coverage: null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const path = [artefactId];
|
|
218
|
+
const brokenLinks = [];
|
|
219
|
+
|
|
220
|
+
// Follow links of type: requirement -> design -> implementation -> test -> evidence
|
|
221
|
+
let current = start;
|
|
222
|
+
let maxDepth = options.maxDepth || 5;
|
|
223
|
+
let depth = 0;
|
|
224
|
+
|
|
225
|
+
while (depth < maxDepth && current.links) {
|
|
226
|
+
// Try to find the next link type
|
|
227
|
+
const nextId = current.links.implementedBy?.[0] ||
|
|
228
|
+
current.links.verifiedBy?.[0] ||
|
|
229
|
+
current.links.evidencedBy?.[0] ||
|
|
230
|
+
current.links.designedBy?.[0] ||
|
|
231
|
+
current.links.implements?.[0];
|
|
232
|
+
|
|
233
|
+
if (!nextId) break;
|
|
234
|
+
|
|
235
|
+
const next = await resolveLink(root, nextId);
|
|
236
|
+
if (!next) {
|
|
237
|
+
brokenLinks.push(`Missing link: ${current.id} -> ${nextId}`);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
path.push(nextId);
|
|
242
|
+
current = next;
|
|
243
|
+
depth++;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Calculate coverage based on path
|
|
247
|
+
const coverage = calculateCoverage(path, artefacts);
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
ok: brokenLinks.length === 0,
|
|
251
|
+
artefactId,
|
|
252
|
+
path,
|
|
253
|
+
brokenLinks,
|
|
254
|
+
coverage
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Find all broken links in the artefacts directory.
|
|
260
|
+
*/
|
|
261
|
+
export async function findBrokenLinks(root, options = {}) {
|
|
262
|
+
const artefacts = await loadAllArtefacts(root);
|
|
263
|
+
const broken = [];
|
|
264
|
+
|
|
265
|
+
for (const [id, artefact] of artefacts) {
|
|
266
|
+
if (!artefact.links) continue;
|
|
267
|
+
|
|
268
|
+
const linkTypes = ['implements', 'designedBy', 'implementedBy', 'verifiedBy', 'evidencedBy'];
|
|
269
|
+
for (const linkType of linkTypes) {
|
|
270
|
+
const targetIds = artefact.links[linkType];
|
|
271
|
+
if (!targetIds || !Array.isArray(targetIds)) continue;
|
|
272
|
+
|
|
273
|
+
for (const targetId of targetIds) {
|
|
274
|
+
if (!artefacts.has(targetId)) {
|
|
275
|
+
broken.push({
|
|
276
|
+
sourceId: id,
|
|
277
|
+
linkType,
|
|
278
|
+
targetId,
|
|
279
|
+
reason: `Target artefact not found: ${targetId}`
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return broken;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Find artefacts without a specific type of link.
|
|
291
|
+
*/
|
|
292
|
+
const TYPE_ID_PREFIX = {
|
|
293
|
+
requirement: 'REQ-',
|
|
294
|
+
design: 'DES-',
|
|
295
|
+
implementation: 'BACKEND-',
|
|
296
|
+
test: 'TEST-',
|
|
297
|
+
evidence: 'EVID-',
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
function artefactMatchesType(artefact, type) {
|
|
301
|
+
if (!artefact) return false;
|
|
302
|
+
if (artefact.type === type) return true;
|
|
303
|
+
const prefix = TYPE_ID_PREFIX[type];
|
|
304
|
+
return Boolean(prefix && typeof artefact.id === 'string' && artefact.id.startsWith(prefix));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export async function findMissingLinks(root, options = {}) {
|
|
308
|
+
const artefacts = await loadAllArtefacts(root);
|
|
309
|
+
const missing = [];
|
|
310
|
+
|
|
311
|
+
const targetType = options.type;
|
|
312
|
+
if (!targetType) {
|
|
313
|
+
throw new Error('Missing --type option (requirement, design, implementation, test, evidence)');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
for (const [id, artefact] of artefacts) {
|
|
317
|
+
const links = artefact.links || {};
|
|
318
|
+
let hasLink = false;
|
|
319
|
+
for (const targetIds of Object.values(links)) {
|
|
320
|
+
if (!Array.isArray(targetIds)) continue;
|
|
321
|
+
for (const targetId of targetIds) {
|
|
322
|
+
if (artefactMatchesType(artefacts.get(targetId), targetType)) {
|
|
323
|
+
hasLink = true;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (hasLink) break;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (!hasLink) {
|
|
331
|
+
missing.push({
|
|
332
|
+
id,
|
|
333
|
+
type: artefact.type || 'unknown',
|
|
334
|
+
missing: targetType
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return missing;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Calculate coverage for a path of artefacts.
|
|
344
|
+
*/
|
|
345
|
+
function calculateCoverage(path, artefacts) {
|
|
346
|
+
if (path.length === 0) return null;
|
|
347
|
+
|
|
348
|
+
const start = artefacts.get(path[0]);
|
|
349
|
+
if (!start || start.type !== 'requirement') return null;
|
|
350
|
+
|
|
351
|
+
const criteriaCount = start.acceptanceCriteria?.length || 0;
|
|
352
|
+
const hasTest = path.some(id => artefacts.get(id)?.type === 'test');
|
|
353
|
+
const hasEvidence = path.some(id => artefacts.get(id)?.type === 'evidence');
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
requirementId: path[0],
|
|
357
|
+
acceptanceCriteria: criteriaCount,
|
|
358
|
+
hasImplementation: path.some(id => artefacts.get(id)?.type === 'implementation'),
|
|
359
|
+
hasTest,
|
|
360
|
+
hasEvidence,
|
|
361
|
+
isFullyTraced: criteriaCount > 0 && hasTest && hasEvidence
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Generate a traceability report for a project.
|
|
367
|
+
* Returns comprehensive coverage metrics and visualizations.
|
|
368
|
+
*/
|
|
369
|
+
export async function generateTraceabilityReport(root, options = {}) {
|
|
370
|
+
const artefacts = await loadAllArtefacts(root);
|
|
371
|
+
const report = {
|
|
372
|
+
summary: {
|
|
373
|
+
totalArtefacts: artefacts.size,
|
|
374
|
+
byType: {},
|
|
375
|
+
byStatus: {}
|
|
376
|
+
},
|
|
377
|
+
coverage: {
|
|
378
|
+
requirements: [],
|
|
379
|
+
overall: {
|
|
380
|
+
totalRequirements: 0,
|
|
381
|
+
fullyTraced: 0,
|
|
382
|
+
partiallyTraced: 0,
|
|
383
|
+
notTraced: 0,
|
|
384
|
+
coveragePercentage: 0
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
links: {
|
|
388
|
+
total: 0,
|
|
389
|
+
byType: {}
|
|
390
|
+
},
|
|
391
|
+
broken: await findBrokenLinks(root),
|
|
392
|
+
missing: await findMissingLinks(root, { type: 'test' })
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// Count by type and status
|
|
396
|
+
for (const artefact of artefacts.values()) {
|
|
397
|
+
const type = artefact.type || 'unknown';
|
|
398
|
+
const status = artefact.status || 'DRAFT';
|
|
399
|
+
|
|
400
|
+
report.summary.byType[type] = (report.summary.byType[type] || 0) + 1;
|
|
401
|
+
report.summary.byStatus[status] = (report.summary.byStatus[status] || 0) + 1;
|
|
402
|
+
|
|
403
|
+
// Count links
|
|
404
|
+
if (artefact.links) {
|
|
405
|
+
for (const [linkType, targets] of Object.entries(artefact.links)) {
|
|
406
|
+
if (Array.isArray(targets)) {
|
|
407
|
+
report.links.total += targets.length;
|
|
408
|
+
report.links.byType[linkType] = (report.links.byType[linkType] || 0) + targets.length;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Calculate requirement coverage
|
|
415
|
+
let totalRequirements = 0;
|
|
416
|
+
let fullyTraced = 0;
|
|
417
|
+
let partiallyTraced = 0;
|
|
418
|
+
let notTraced = 0;
|
|
419
|
+
|
|
420
|
+
for (const [id, artefact] of artefacts) {
|
|
421
|
+
if (artefact.type === 'requirement') {
|
|
422
|
+
totalRequirements++;
|
|
423
|
+
|
|
424
|
+
const path = [id];
|
|
425
|
+
let current = artefact;
|
|
426
|
+
let depth = 0;
|
|
427
|
+
let hasTest = false;
|
|
428
|
+
let hasEvidence = false;
|
|
429
|
+
|
|
430
|
+
while (depth < 5 && current.links) {
|
|
431
|
+
const nextId = current.links.implementedBy?.[0] ||
|
|
432
|
+
current.links.verifiedBy?.[0] ||
|
|
433
|
+
current.links.evidencedBy?.[0];
|
|
434
|
+
|
|
435
|
+
if (!nextId) break;
|
|
436
|
+
|
|
437
|
+
const next = artefacts.get(nextId);
|
|
438
|
+
if (!next) break;
|
|
439
|
+
|
|
440
|
+
path.push(nextId);
|
|
441
|
+
if (next.type === 'test') hasTest = true;
|
|
442
|
+
if (next.type === 'evidence') hasEvidence = true;
|
|
443
|
+
|
|
444
|
+
current = next;
|
|
445
|
+
depth++;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const criteriaCount = artefact.acceptanceCriteria?.length || 0;
|
|
449
|
+
const isFullyTraced = criteriaCount > 0 && hasTest && hasEvidence;
|
|
450
|
+
const isTraced = hasTest || hasEvidence;
|
|
451
|
+
|
|
452
|
+
if (isFullyTraced) fullyTraced++;
|
|
453
|
+
else if (isTraced) partiallyTraced++;
|
|
454
|
+
else notTraced++;
|
|
455
|
+
|
|
456
|
+
report.coverage.requirements.push({
|
|
457
|
+
requirementId: id,
|
|
458
|
+
acceptanceCriteria: criteriaCount,
|
|
459
|
+
path,
|
|
460
|
+
hasTest,
|
|
461
|
+
hasEvidence,
|
|
462
|
+
isFullyTraced
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
report.coverage.overall = {
|
|
468
|
+
totalRequirements,
|
|
469
|
+
fullyTraced,
|
|
470
|
+
partiallyTraced,
|
|
471
|
+
notTraced,
|
|
472
|
+
coveragePercentage: totalRequirements > 0 ? Math.round((fullyTraced / totalRequirements) * 100) : 0
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// Add recommendations
|
|
476
|
+
report.recommendations = [];
|
|
477
|
+
if (report.coverage.overall.notTraced > 0) {
|
|
478
|
+
report.recommendations.push(`Add tests and evidence for ${report.coverage.overall.notTraced} untraced requirement(s).`);
|
|
479
|
+
}
|
|
480
|
+
if (report.links.total === 0) {
|
|
481
|
+
report.recommendations.push('Add link relationships between artefacts to enable traceability.');
|
|
482
|
+
}
|
|
483
|
+
if (report.broken.length > 0) {
|
|
484
|
+
report.recommendations.push(`Fix ${report.broken.length} broken link(s) to ensure complete traceability.`);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return report;
|
|
488
|
+
}
|