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,179 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { listFiles, toPosix } from '../util/fsx.mjs';
|
|
3
|
+
|
|
4
|
+
const FRAMEWORK_COPY_DIRS = ['src', 'assets', 'docs/aidf'];
|
|
5
|
+
const FRAMEWORK_COPY_FILES = ['package.json', 'README.md', 'LICENSE', 'INSTALLATION.md', 'UTILISATION.md', 'QODER.md', 'CHANGELOG.md'];
|
|
6
|
+
|
|
7
|
+
export function isSelfHosted(root, frameworkRoot) {
|
|
8
|
+
return path.resolve(frameworkRoot) === path.resolve(root, '.aidf', 'framework');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function planCore(root, options = {}) {
|
|
12
|
+
const frameworkRoot = path.resolve(options.frameworkRoot);
|
|
13
|
+
const actions = [];
|
|
14
|
+
const selfHosted = isSelfHosted(root, frameworkRoot);
|
|
15
|
+
|
|
16
|
+
if (!selfHosted) {
|
|
17
|
+
for (const dir of FRAMEWORK_COPY_DIRS) {
|
|
18
|
+
const files = await listFiles(path.join(frameworkRoot, dir), { ignore: [] });
|
|
19
|
+
for (const rel of files) {
|
|
20
|
+
actions.push({
|
|
21
|
+
kind: 'copy',
|
|
22
|
+
path: path.posix.join('.aidf', 'framework', dir, rel),
|
|
23
|
+
source: path.join(frameworkRoot, dir, rel),
|
|
24
|
+
category: 'framework',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const file of FRAMEWORK_COPY_FILES) {
|
|
29
|
+
actions.push({
|
|
30
|
+
kind: 'copy',
|
|
31
|
+
path: path.posix.join('.aidf', 'framework', file),
|
|
32
|
+
source: path.join(frameworkRoot, file),
|
|
33
|
+
category: 'framework',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
actions.push({
|
|
39
|
+
kind: 'write',
|
|
40
|
+
path: '.aidf/bin/aidf.mjs',
|
|
41
|
+
content: launcherSource(),
|
|
42
|
+
category: 'framework',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
actions.push({
|
|
46
|
+
kind: 'copy',
|
|
47
|
+
path: '.aidf/AIDF.md',
|
|
48
|
+
source: path.join(frameworkRoot, 'assets', 'core', 'AIDF.md'),
|
|
49
|
+
category: 'instructions',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const docFiles = await listFiles(path.join(frameworkRoot, 'assets', 'docs'));
|
|
53
|
+
for (const rel of docFiles) {
|
|
54
|
+
actions.push({
|
|
55
|
+
kind: 'copy',
|
|
56
|
+
path: path.posix.join('.aidf', 'docs', rel),
|
|
57
|
+
source: path.join(frameworkRoot, 'assets', 'docs', rel),
|
|
58
|
+
category: 'documents',
|
|
59
|
+
frozen: true,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (const registry of ['sources.yaml', 'activation-map.yaml', 'dependencies.yaml']) {
|
|
64
|
+
actions.push({
|
|
65
|
+
kind: 'copy',
|
|
66
|
+
path: path.posix.join('.aidf', 'registry', registry),
|
|
67
|
+
source: path.join(frameworkRoot, 'assets', 'registry', registry),
|
|
68
|
+
category: 'registry',
|
|
69
|
+
frozen: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const workflow of ['phases.yaml', 'gates.yaml']) {
|
|
74
|
+
actions.push({
|
|
75
|
+
kind: 'copy',
|
|
76
|
+
path: path.posix.join('.aidf', 'workflows', workflow),
|
|
77
|
+
source: path.join(frameworkRoot, 'assets', 'workflows', workflow),
|
|
78
|
+
category: 'workflows',
|
|
79
|
+
frozen: true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const knowledgeFiles = await listFiles(path.join(frameworkRoot, 'assets', 'knowledge'));
|
|
84
|
+
for (const rel of knowledgeFiles) {
|
|
85
|
+
actions.push({
|
|
86
|
+
kind: 'copy',
|
|
87
|
+
path: path.posix.join('.aidf', 'knowledge', rel),
|
|
88
|
+
source: path.join(frameworkRoot, 'assets', 'knowledge', rel),
|
|
89
|
+
category: 'knowledge',
|
|
90
|
+
frozen: true,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
actions.push({
|
|
95
|
+
kind: 'write',
|
|
96
|
+
path: '.aidf/.gitignore',
|
|
97
|
+
content: [
|
|
98
|
+
'# AIDF local-only state',
|
|
99
|
+
'cache/',
|
|
100
|
+
'logs/',
|
|
101
|
+
'backups/',
|
|
102
|
+
'state/context/',
|
|
103
|
+
'',
|
|
104
|
+
'# Evidence and documents are intentionally committed.',
|
|
105
|
+
'',
|
|
106
|
+
].join('\n'),
|
|
107
|
+
category: 'config',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
actions.push({
|
|
111
|
+
kind: 'mkdir',
|
|
112
|
+
path: '.aidf/evidence',
|
|
113
|
+
category: 'directories',
|
|
114
|
+
});
|
|
115
|
+
actions.push({
|
|
116
|
+
kind: 'mkdir',
|
|
117
|
+
path: '.aidf/state/context',
|
|
118
|
+
category: 'directories',
|
|
119
|
+
});
|
|
120
|
+
actions.push({
|
|
121
|
+
kind: 'mkdir',
|
|
122
|
+
path: '.aidf/skills/project-skills',
|
|
123
|
+
category: 'directories',
|
|
124
|
+
});
|
|
125
|
+
actions.push({
|
|
126
|
+
kind: 'mkdir',
|
|
127
|
+
path: '.aidf/reports',
|
|
128
|
+
category: 'directories',
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return { actions, selfHosted };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function launcherSource() {
|
|
135
|
+
return `#!/usr/bin/env node
|
|
136
|
+
import { main } from '../framework/src/cli.mjs';
|
|
137
|
+
|
|
138
|
+
main(process.argv.slice(2)).then((code) => {
|
|
139
|
+
process.exitCode = code;
|
|
140
|
+
}).catch((error) => {
|
|
141
|
+
process.stderr.write(\`aidf: fatal: \${error && error.message ? error.message : String(error)}\\n\`);
|
|
142
|
+
process.exitCode = 70;
|
|
143
|
+
});
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function renderInstallReport({ root, projectName, adapter, results, summary, version }) {
|
|
148
|
+
const lines = [];
|
|
149
|
+
lines.push('# AIDF Installation Report');
|
|
150
|
+
lines.push('');
|
|
151
|
+
lines.push(`- Project: ${projectName}`);
|
|
152
|
+
lines.push(`- Root: \`${toPosix(root)}\``);
|
|
153
|
+
lines.push(`- AIDF version: ${version}`);
|
|
154
|
+
lines.push(`- Adapter: ${adapter}`);
|
|
155
|
+
lines.push(`- Generated: ${new Date().toISOString()}`);
|
|
156
|
+
lines.push('');
|
|
157
|
+
lines.push('## Summary');
|
|
158
|
+
lines.push('');
|
|
159
|
+
lines.push(`- Created: ${summary.created}`);
|
|
160
|
+
lines.push(`- Updated: ${summary.updated}`);
|
|
161
|
+
lines.push(`- Unchanged: ${summary.unchanged}`);
|
|
162
|
+
lines.push(`- Conflicts: ${summary.conflicts}`);
|
|
163
|
+
lines.push(`- Failed: ${summary.failed}`);
|
|
164
|
+
lines.push('');
|
|
165
|
+
lines.push('## Conflicts and warnings');
|
|
166
|
+
lines.push('');
|
|
167
|
+
const conflicts = results.filter((r) => r.status === 'CONFLICT' || r.status === 'FAILED');
|
|
168
|
+
if (conflicts.length === 0) lines.push('_None._');
|
|
169
|
+
for (const c of conflicts) lines.push(`- \`${c.path}\` — ${c.status}: ${c.reason ?? ''}`);
|
|
170
|
+
lines.push('');
|
|
171
|
+
lines.push('## Next steps');
|
|
172
|
+
lines.push('');
|
|
173
|
+
lines.push('1. Run `node .aidf/bin/aidf.mjs doctor`.');
|
|
174
|
+
lines.push('2. Complete `.aidf/docs/constitution.md` and the eight reference documents from real project analysis.');
|
|
175
|
+
lines.push('3. Run `node .aidf/bin/aidf.mjs scan --record` and `node .aidf/bin/aidf.mjs skills validate`.');
|
|
176
|
+
lines.push('4. In Qoder, confirm the AIDF skills are listed with `/skills` and set the AIDF rules to **Always Apply**.');
|
|
177
|
+
lines.push('');
|
|
178
|
+
return `${lines.join('\n')}\n`;
|
|
179
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { aidfPaths, DOCUMENTS, DOC_STATUSES, AIDF_VERSION } from './paths.mjs';
|
|
2
|
+
|
|
3
|
+
import { readJson, writeJson, exists } from '../util/fsx.mjs';
|
|
4
|
+
|
|
5
|
+
export const CONFIG_SCHEMA_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export function defaultConfig(project = {}) {
|
|
8
|
+
const documents = {};
|
|
9
|
+
for (const doc of DOCUMENTS) {
|
|
10
|
+
documents[doc] = {
|
|
11
|
+
status: doc === 'constitution' ? 'DRAFT' : 'DRAFT',
|
|
12
|
+
validatedBy: null,
|
|
13
|
+
validatedAt: null,
|
|
14
|
+
note: 'Generated at installation. Must be completed from real project analysis.',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
schemaVersion: CONFIG_SCHEMA_VERSION,
|
|
19
|
+
project: {
|
|
20
|
+
name: project.name ?? 'unnamed-project',
|
|
21
|
+
slug: project.slug ?? 'unnamed-project',
|
|
22
|
+
description: project.description ?? '',
|
|
23
|
+
},
|
|
24
|
+
framework: {
|
|
25
|
+
name: 'aidf',
|
|
26
|
+
version: AIDF_VERSION,
|
|
27
|
+
channel: 'local',
|
|
28
|
+
},
|
|
29
|
+
adapter: project.adapter ?? 'generic',
|
|
30
|
+
commands: project.commands ?? {
|
|
31
|
+
test: null,
|
|
32
|
+
build: null,
|
|
33
|
+
lint: null,
|
|
34
|
+
securityAudit: null,
|
|
35
|
+
},
|
|
36
|
+
documents,
|
|
37
|
+
workflow: {
|
|
38
|
+
currentPhase: 'intake',
|
|
39
|
+
history: [],
|
|
40
|
+
},
|
|
41
|
+
skills: {
|
|
42
|
+
roots: [],
|
|
43
|
+
maxActive: 5,
|
|
44
|
+
},
|
|
45
|
+
context: {
|
|
46
|
+
maxDocuments: 8,
|
|
47
|
+
maxSkills: 5,
|
|
48
|
+
alwaysInclude: ['constitution', 'CONVENTIONS'],
|
|
49
|
+
},
|
|
50
|
+
security: {
|
|
51
|
+
allowCommandExecution: false,
|
|
52
|
+
allowedCommands: [],
|
|
53
|
+
allowNetwork: false,
|
|
54
|
+
allowedHosts: [],
|
|
55
|
+
protectSecrets: true,
|
|
56
|
+
requireHumanApprovalFor: ['security', 'release'],
|
|
57
|
+
// Declared approvals (--human --by) are recorded but not authenticated.
|
|
58
|
+
// Set to true to make gates reject declared-only approvals.
|
|
59
|
+
requireAuthenticatedApproval: false,
|
|
60
|
+
},
|
|
61
|
+
specKit: {
|
|
62
|
+
enabled: 'auto',
|
|
63
|
+
integration: 'qodercli',
|
|
64
|
+
constitutionSync: 'copy-with-hash',
|
|
65
|
+
},
|
|
66
|
+
evidence: {
|
|
67
|
+
directory: '.aidf/evidence',
|
|
68
|
+
retentionDays: 365,
|
|
69
|
+
},
|
|
70
|
+
createdAt: new Date().toISOString(),
|
|
71
|
+
updatedAt: new Date().toISOString(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function loadConfig(root) {
|
|
76
|
+
const paths = aidfPaths(root);
|
|
77
|
+
const config = await readJson(paths.config, null);
|
|
78
|
+
if (!config) throw new Error(`AIDF is not initialized in ${root} (missing .aidf/config.json).`);
|
|
79
|
+
return config;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function saveConfig(root, config) {
|
|
83
|
+
const paths = aidfPaths(root);
|
|
84
|
+
config.updatedAt = new Date().toISOString();
|
|
85
|
+
await writeJson(paths.config, config);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function configExists(root) {
|
|
89
|
+
return exists(aidfPaths(root).config);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function validateConfig(config) {
|
|
93
|
+
const errors = [];
|
|
94
|
+
if (!config || typeof config !== 'object') return ['config must be an object'];
|
|
95
|
+
if (config.schemaVersion !== CONFIG_SCHEMA_VERSION) errors.push(`unsupported schemaVersion: ${config.schemaVersion}`);
|
|
96
|
+
if (!config.project || typeof config.project.name !== 'string') errors.push('project.name is required');
|
|
97
|
+
if (!config.documents || typeof config.documents !== 'object') errors.push('documents is required');
|
|
98
|
+
for (const doc of DOCUMENTS) {
|
|
99
|
+
const entry = config.documents?.[doc];
|
|
100
|
+
if (!entry) errors.push(`missing document entry: ${doc}`);
|
|
101
|
+
else if (!DOC_STATUSES.includes(entry.status)) errors.push(`invalid status for ${doc}: ${entry.status}`);
|
|
102
|
+
}
|
|
103
|
+
if (!Array.isArray(config.security?.allowedCommands)) errors.push('security.allowedCommands must be an array');
|
|
104
|
+
if (config.security?.requireAuthenticatedApproval !== undefined
|
|
105
|
+
&& typeof config.security.requireAuthenticatedApproval !== 'boolean') {
|
|
106
|
+
errors.push('security.requireAuthenticatedApproval must be a boolean');
|
|
107
|
+
}
|
|
108
|
+
return errors;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function setDocumentStatus(config, doc, status, meta = {}) {
|
|
112
|
+
if (!DOCUMENTS.includes(doc)) throw new Error(`Unknown document: ${doc}`);
|
|
113
|
+
if (!DOC_STATUSES.includes(status)) throw new Error(`Invalid document status: ${status}`);
|
|
114
|
+
const current = config.documents[doc] ?? {};
|
|
115
|
+
config.documents[doc] = {
|
|
116
|
+
...current,
|
|
117
|
+
status,
|
|
118
|
+
validatedBy: meta.by ?? current.validatedBy ?? null,
|
|
119
|
+
validatedAt: meta.at ?? (status === 'VALIDATED' ? new Date().toISOString() : null),
|
|
120
|
+
note: meta.note ?? current.note ?? '',
|
|
121
|
+
};
|
|
122
|
+
return config.documents[doc];
|
|
123
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { aidfPaths } from './paths.mjs';
|
|
3
|
+
import { loadConfig } from './config.mjs';
|
|
4
|
+
import { loadActivationMap, loadSkillCatalog, buildSkillRegistry, loadProjectSkillRegistry } from './skills.mjs';
|
|
5
|
+
import { loadPhases, loadWorkflowState, phaseById } from './workflow.mjs';
|
|
6
|
+
import { writeAtomic, ensureDir } from '../util/fsx.mjs';
|
|
7
|
+
import { timestampSlug } from '../util/fsx.mjs';
|
|
8
|
+
|
|
9
|
+
function words(text) {
|
|
10
|
+
return String(text ?? '')
|
|
11
|
+
.toLowerCase()
|
|
12
|
+
.split(/[^a-z0-9\u00C0-\u024F]+/)
|
|
13
|
+
.filter((w) => w.length >= 3);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function matchesKeyword(taskLower, keyword) {
|
|
17
|
+
const k = String(keyword).toLowerCase();
|
|
18
|
+
if (k.includes(' ')) return taskLower.includes(k);
|
|
19
|
+
return new RegExp(`(^|[^a-z0-9])${k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}($|[^a-z0-9])`).test(taskLower);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function addCandidate(map, id, kind, reason, score = 1) {
|
|
23
|
+
const existing = map.get(id);
|
|
24
|
+
if (existing) {
|
|
25
|
+
existing.score += score;
|
|
26
|
+
if (!existing.reasons.includes(reason)) existing.reasons.push(reason);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
map.set(id, { id, kind, score, reasons: [reason] });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function assembleContext(root, task, options = {}) {
|
|
33
|
+
const config = options.config ?? (await loadConfig(root));
|
|
34
|
+
const activation = options.activation ?? (await loadActivationMap(options.frameworkRoot));
|
|
35
|
+
const phases = options.phases ?? (await loadPhases(options.frameworkRoot));
|
|
36
|
+
const state = options.state ?? (await loadWorkflowState(root));
|
|
37
|
+
const phase = phaseById(phases, state.currentPhase);
|
|
38
|
+
const taskLower = String(task ?? '').toLowerCase();
|
|
39
|
+
|
|
40
|
+
let registry = options.registry;
|
|
41
|
+
if (!registry) {
|
|
42
|
+
const saved = await loadProjectSkillRegistry(root);
|
|
43
|
+
registry = saved.skills?.length ? saved : await buildSkillRegistry(root, { adapter: config.adapter });
|
|
44
|
+
}
|
|
45
|
+
const skillById = new Map(registry.skills.map((s) => [s.id, s]));
|
|
46
|
+
const skillByName = new Map(registry.skills.map((s) => [s.name, s]));
|
|
47
|
+
|
|
48
|
+
const docCandidates = new Map();
|
|
49
|
+
const skillCandidates = new Map();
|
|
50
|
+
|
|
51
|
+
for (const doc of activation.always?.documents ?? []) addCandidate(docCandidates, doc, 'document', 'always-on');
|
|
52
|
+
for (const skill of activation.always?.skills ?? []) addCandidate(skillCandidates, skill, 'skill', 'always-on');
|
|
53
|
+
|
|
54
|
+
if (phase) {
|
|
55
|
+
for (const doc of phase.requiredDocuments ?? []) addCandidate(docCandidates, doc, 'document', `phase:${phase.id}`, 3);
|
|
56
|
+
for (const skill of phase.skills ?? []) addCandidate(skillCandidates, skill, 'skill', `phase:${phase.id}`, 3);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const rule of activation.byKeyword ?? []) {
|
|
60
|
+
const hit = (rule.keywords ?? []).some((k) => matchesKeyword(taskLower, k));
|
|
61
|
+
if (!hit) continue;
|
|
62
|
+
const matched = (rule.keywords ?? []).filter((k) => matchesKeyword(taskLower, k));
|
|
63
|
+
for (const doc of rule.documents ?? []) addCandidate(docCandidates, doc, 'document', `keyword:${matched.join('|')}`, 2);
|
|
64
|
+
for (const skill of rule.skills ?? []) addCandidate(skillCandidates, skill, 'skill', `keyword:${matched.join('|')}`, 2);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const doc of activation.contradictionSensitive ?? []) addCandidate(docCandidates, doc, 'document', 'contradiction-sensitive', 1);
|
|
68
|
+
|
|
69
|
+
const alwaysDocs = new Set(activation.always?.documents ?? []);
|
|
70
|
+
const sortedDocs = [...docCandidates.values()]
|
|
71
|
+
.sort((a, b) => (alwaysDocs.has(b.id) ? 1 : 0) - (alwaysDocs.has(a.id) ? 1 : 0) || b.score - a.score);
|
|
72
|
+
const maxDocs = config.context?.maxDocuments ?? 8;
|
|
73
|
+
const selectedDocs = [];
|
|
74
|
+
for (const candidate of sortedDocs) {
|
|
75
|
+
if (selectedDocs.length >= maxDocs && !alwaysDocs.has(candidate.id)) continue;
|
|
76
|
+
const entry = config.documents?.[candidate.id];
|
|
77
|
+
selectedDocs.push({
|
|
78
|
+
...candidate,
|
|
79
|
+
status: entry?.status ?? 'MISSING',
|
|
80
|
+
path: `.aidf/docs/${candidate.id}.md`,
|
|
81
|
+
exists: entry !== undefined,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const alwaysSkills = new Set(activation.always?.skills ?? []);
|
|
86
|
+
const sortedSkills = [...skillCandidates.values()]
|
|
87
|
+
.sort((a, b) => (alwaysSkills.has(b.id) ? 1 : 0) - (alwaysSkills.has(a.id) ? 1 : 0) || b.score - a.score);
|
|
88
|
+
const maxSkills = config.context?.maxSkills ?? config.skills?.maxActive ?? 5;
|
|
89
|
+
const selectedSkills = [];
|
|
90
|
+
for (const candidate of sortedSkills) {
|
|
91
|
+
if (selectedSkills.length >= maxSkills && !alwaysSkills.has(candidate.id)) continue;
|
|
92
|
+
const skill = skillById.get(candidate.id) ?? skillByName.get(candidate.id);
|
|
93
|
+
selectedSkills.push({
|
|
94
|
+
...candidate,
|
|
95
|
+
name: skill?.name ?? candidate.id,
|
|
96
|
+
status: skill?.status ?? 'MISSING',
|
|
97
|
+
path: skill?.path ?? null,
|
|
98
|
+
available: ['AVAILABLE', 'REGISTERED', 'VALIDATED'].includes(skill?.status),
|
|
99
|
+
description: skill?.description ?? '',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const contradictions = [];
|
|
104
|
+
for (const doc of activation.contradictionSensitive ?? []) {
|
|
105
|
+
const entry = config.documents?.[doc];
|
|
106
|
+
if (entry && ['BLOCKED', 'OUTDATED'].includes(entry.status)) {
|
|
107
|
+
contradictions.push({
|
|
108
|
+
document: doc,
|
|
109
|
+
status: entry.status,
|
|
110
|
+
effect: 'Decisions depending on this document are BLOCKED until resolved.',
|
|
111
|
+
note: entry.note ?? '',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const result = {
|
|
117
|
+
task,
|
|
118
|
+
phase: state.currentPhase,
|
|
119
|
+
phaseName: phase?.name ?? null,
|
|
120
|
+
generatedAt: new Date().toISOString(),
|
|
121
|
+
documents: selectedDocs,
|
|
122
|
+
skills: selectedSkills,
|
|
123
|
+
contradictions,
|
|
124
|
+
status: contradictions.length > 0 ? 'BLOCKED' : 'OK',
|
|
125
|
+
notes: [
|
|
126
|
+
'Read .aidf/AIDF.md and .aidf/docs/constitution.md first.',
|
|
127
|
+
'Load only the selected documents and skills.',
|
|
128
|
+
'A document marked BLOCKED or OUTDATED blocks decisions that depend on it.',
|
|
129
|
+
],
|
|
130
|
+
};
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function renderContextMarkdown(context, config) {
|
|
135
|
+
const lines = [];
|
|
136
|
+
lines.push(`# AIDF Context — ${context.phase}`);
|
|
137
|
+
lines.push('');
|
|
138
|
+
lines.push(`- Task: ${context.task || '(not provided)'}`);
|
|
139
|
+
lines.push(`- Phase: ${context.phase}${context.phaseName ? ` — ${context.phaseName}` : ''}`);
|
|
140
|
+
lines.push(`- Generated: ${context.generatedAt}`);
|
|
141
|
+
lines.push(`- Status: ${context.status}`);
|
|
142
|
+
lines.push('');
|
|
143
|
+
lines.push('## Read in this order');
|
|
144
|
+
lines.push('');
|
|
145
|
+
lines.push('1. `.aidf/AIDF.md`');
|
|
146
|
+
lines.push('2. `.aidf/docs/constitution.md`');
|
|
147
|
+
let docNumber = 3;
|
|
148
|
+
context.documents.forEach((doc) => {
|
|
149
|
+
if (doc.id === 'constitution') return;
|
|
150
|
+
lines.push(`${docNumber}. \`${doc.path}\` — ${doc.status} (${doc.reasons.join(', ')})`);
|
|
151
|
+
docNumber += 1;
|
|
152
|
+
});
|
|
153
|
+
lines.push('');
|
|
154
|
+
lines.push('## Selected skills');
|
|
155
|
+
lines.push('');
|
|
156
|
+
if (context.skills.length === 0) lines.push('_None._');
|
|
157
|
+
for (const skill of context.skills) {
|
|
158
|
+
lines.push(`- **${skill.name}** — ${skill.status}${skill.path ? ` — \`${skill.path}\`` : ''}`);
|
|
159
|
+
lines.push(` - Why: ${skill.reasons.join(', ')}`);
|
|
160
|
+
}
|
|
161
|
+
lines.push('');
|
|
162
|
+
lines.push('## Contradictions and blockers');
|
|
163
|
+
lines.push('');
|
|
164
|
+
if (context.contradictions.length === 0) lines.push('_None detected._');
|
|
165
|
+
for (const c of context.contradictions) {
|
|
166
|
+
lines.push(`- **${c.document}** is ${c.status}. ${c.effect}${c.note ? ` Note: ${c.note}` : ''}`);
|
|
167
|
+
}
|
|
168
|
+
lines.push('');
|
|
169
|
+
lines.push('## Operating reminders');
|
|
170
|
+
lines.push('');
|
|
171
|
+
for (const note of context.notes) lines.push(`- ${note}`);
|
|
172
|
+
lines.push(`- Security policy: command execution ${config.security?.allowCommandExecution ? 'ENABLED' : 'disabled by default'}; network ${config.security?.allowNetwork ? 'ENABLED' : 'disabled by default'}.`);
|
|
173
|
+
lines.push('');
|
|
174
|
+
return `${lines.join('\n')}\n`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function writeContext(root, context, config) {
|
|
178
|
+
const paths = aidfPaths(root);
|
|
179
|
+
await ensureDir(paths.context);
|
|
180
|
+
const markdown = renderContextMarkdown(context, config);
|
|
181
|
+
await writeAtomic(path.join(paths.context, 'latest.md'), markdown);
|
|
182
|
+
await writeAtomic(path.join(paths.context, `${timestampSlug()}.json`), `${JSON.stringify(context, null, 2)}\n`);
|
|
183
|
+
return {
|
|
184
|
+
markdownPath: '.aidf/state/context/latest.md',
|
|
185
|
+
markdown,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L3: Complexity Classification
|
|
3
|
+
* Determines design workflow based on project characteristics.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function classifyComplexity(context) {
|
|
7
|
+
const factors = {
|
|
8
|
+
projectSize: classifyByFeatureCount(context.featureCount || 0),
|
|
9
|
+
teamSize: classifyByTeamSize(context.teamSize || 1),
|
|
10
|
+
timeline: classifyByTimeline(context.timelineWeeks || 2),
|
|
11
|
+
budget: classifyByBudget(context.budget || 0)
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Determine overall complexity
|
|
15
|
+
const scores = Object.values(factors).map(f => f.score);
|
|
16
|
+
const avgScore = scores.reduce((a, b) => a + b, 0) / scores.length;
|
|
17
|
+
|
|
18
|
+
let complexity;
|
|
19
|
+
if (avgScore < 1.5) complexity = 'small';
|
|
20
|
+
else if (avgScore < 2.5) complexity = 'medium';
|
|
21
|
+
else if (avgScore < 3.5) complexity = 'large';
|
|
22
|
+
else complexity = 'enterprise';
|
|
23
|
+
|
|
24
|
+
// Check for emergency overrides
|
|
25
|
+
if (context.emergency || context.mvpMode || context.maintenance) {
|
|
26
|
+
complexity = 'small';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
complexity,
|
|
31
|
+
factors,
|
|
32
|
+
score: Math.round(avgScore * 100) / 100
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function classifyByFeatureCount(count) {
|
|
37
|
+
if (count < 5) return { level: 'small', score: 1 };
|
|
38
|
+
if (count < 15) return { level: 'medium', score: 2 };
|
|
39
|
+
if (count < 50) return { level: 'large', score: 3 };
|
|
40
|
+
return { level: 'enterprise', score: 4 };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function classifyByTeamSize(size) {
|
|
44
|
+
if (size <= 2) return { level: 'small', score: 1 };
|
|
45
|
+
if (size <= 5) return { level: 'medium', score: 2 };
|
|
46
|
+
if (size <= 15) return { level: 'large', score: 3 };
|
|
47
|
+
return { level: 'enterprise', score: 4 };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function classifyByTimeline(weeks) {
|
|
51
|
+
if (weeks < 2) return { level: 'quick', score: 1 };
|
|
52
|
+
if (weeks < 8) return { level: 'standard', score: 2 };
|
|
53
|
+
if (weeks < 16) return { level: 'extended', score: 3 };
|
|
54
|
+
return { level: 'enterprise', score: 4 };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function classifyByBudget(budget) {
|
|
58
|
+
if (budget < 10000) return { level: 'small', score: 1 };
|
|
59
|
+
if (budget < 50000) return { level: 'medium', score: 2 };
|
|
60
|
+
if (budget < 200000) return { level: 'large', score: 3 };
|
|
61
|
+
return { level: 'enterprise', score: 4 };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Select appropriate workflow based on complexity.
|
|
66
|
+
*/
|
|
67
|
+
export function getWorkflow(complexity) {
|
|
68
|
+
if (complexity === 'small' || complexity === 'quick' || complexity === 'mvp') {
|
|
69
|
+
return 'quick';
|
|
70
|
+
}
|
|
71
|
+
if (complexity === 'medium') {
|
|
72
|
+
return 'standard';
|
|
73
|
+
}
|
|
74
|
+
if (complexity === 'large' || complexity === 'enterprise') {
|
|
75
|
+
return 'extended';
|
|
76
|
+
}
|
|
77
|
+
return 'standard';
|
|
78
|
+
}
|