afyx-engineering-kit 0.0.0-stage → 0.1.0-alpha.4
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/.afyx-source-revision +1 -0
- package/LICENSE +21 -0
- package/README.md +377 -2
- package/SECURITY.md +74 -0
- package/afyx-context/LICENSE +21 -0
- package/afyx-context/README.md +155 -0
- package/afyx-context/afyx-context.json +30 -0
- package/afyx-context/contracts/integration-v1.schema.json +34 -0
- package/afyx-context/package-lock.json +53 -0
- package/afyx-context/package.json +34 -0
- package/afyx-context/scripts/benchmark.mjs +39 -0
- package/afyx-context/scripts/build.mjs +15 -0
- package/afyx-context/scripts/comparative-benchmark.mjs +342 -0
- package/afyx-context/scripts/comparative-worker.mjs +74 -0
- package/afyx-context/scripts/graph-integration-e2e.mjs +188 -0
- package/afyx-context/scripts/integrated-dogfood.mjs +309 -0
- package/afyx-context/src/budget.js +166 -0
- package/afyx-context/src/cli.js +110 -0
- package/afyx-context/src/coordination.js +343 -0
- package/afyx-context/src/engine.js +198 -0
- package/afyx-context/src/errors.js +14 -0
- package/afyx-context/src/graph-integration-worker.js +70 -0
- package/afyx-context/src/graph-integration.js +373 -0
- package/afyx-context/src/graph-mcp-bridge.js +103 -0
- package/afyx-context/src/index.js +25 -0
- package/afyx-context/src/integrations.js +87 -0
- package/afyx-context/src/memory.js +255 -0
- package/afyx-context/src/storage.js +364 -0
- package/afyx-context/test-fixtures/coordination-worker.mjs +52 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__init__.py +1 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__manifest__.py +4 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/__init__.py +1 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/sale_order.py +5 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__init__.py +1 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__manifest__.py +10 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/__init__.py +2 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order.py +20 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order_audit.py +11 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/security/ir.model.access.csv +2 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/views/sale_order_views.xml +14 -0
- package/afyx-forge/LICENSE +55 -0
- package/afyx-forge/README.md +126 -0
- package/afyx-forge/afyx-forge.json +28 -0
- package/afyx-forge/bin/afyx-forge +4 -0
- package/afyx-forge/bin/afyx-forge.cmd +3 -0
- package/afyx-forge/bin/afyx-forge.js +16 -0
- package/afyx-forge/contracts/forge-plan-v1.schema.json +172 -0
- package/afyx-forge/package.json +26 -0
- package/afyx-forge/src/classifier.js +190 -0
- package/afyx-forge/src/cli.js +111 -0
- package/afyx-forge/src/doctor.js +105 -0
- package/afyx-forge/src/guidance.js +120 -0
- package/afyx-forge/src/index.js +273 -0
- package/afyx-forge/src/planning.js +107 -0
- package/afyx-forge/src/policy.js +109 -0
- package/afyx-forge/src/workflow-refiner.js +151 -0
- package/afyx-graph/afyx-graph.json +20 -0
- package/afyx-graph/engine/LICENSE +21 -0
- package/afyx-graph/engine/README.md +104 -0
- package/afyx-graph/engine/release/RELEASE-MANIFEST.json +21 -0
- package/afyx-graph/engine/release/SHA256SUMS +2 -0
- package/afyx-graph/engine/release/afyx-graph-linux-x64.tar.gz +0 -0
- package/afyx-graph/engine/release/afyx-graph-win32-x64.zip +0 -0
- package/afyx-graph/engine/scripts/distribution-contract.mjs +212 -0
- package/afyx-graph/engine/scripts/distribution-product.json +33 -0
- package/bin/afyx-engineering-kit.mjs +61 -0
- package/install.ps1 +1053 -0
- package/install.sh +617 -0
- package/package.json +66 -4
- package/scripts/afyx-capability-orchestrator.mjs +752 -0
- package/scripts/afyx-claude-integration.mjs +547 -0
- package/scripts/afyx-context-artifact.mjs +105 -0
- package/scripts/afyx-credential-broker.mjs +75 -0
- package/scripts/afyx-doctor.ps1 +152 -0
- package/scripts/afyx-doctor.sh +146 -0
- package/scripts/afyx-forge-artifact.mjs +183 -0
- package/scripts/afyx-global-routing-policy.md +12 -0
- package/scripts/afyx-global-routing.mjs +168 -0
- package/scripts/afyx-graph-artifact.mjs +178 -0
- package/scripts/afyx-host-adapters.mjs +543 -0
- package/scripts/afyx-host-bridge-lifecycle.mjs +174 -0
- package/scripts/afyx-host-bridge.mjs +288 -0
- package/scripts/afyx-integration-contracts.mjs +825 -0
- package/scripts/afyx-mcp-integration.mjs +528 -0
- package/scripts/afyx-modular-integration.mjs +361 -0
- package/scripts/afyx-modular-runtime.mjs +451 -0
- package/scripts/afyx-native-skill-host.mjs +124 -0
- package/scripts/afyx-npm-installer.mjs +486 -0
- package/scripts/afyx-project.ps1 +205 -0
- package/scripts/afyx-project.sh +207 -0
- package/scripts/afyx-provider-backup.mjs +1206 -0
- package/scripts/afyx-provider-integration.mjs +724 -0
- package/scripts/afyx-provider-inventory.mjs +147 -0
- package/scripts/afyx-security-auditor.mjs +224 -0
- package/scripts/afyx-skill-engineering.mjs +354 -0
- package/scripts/afyx-tool-family-routing.mjs +64 -0
- package/scripts/afyx-universal-runtime.mjs +530 -0
- package/scripts/alpha_acceptance_preflight.py +240 -0
- package/scripts/benchmark-graph-memory.mjs +96 -0
- package/scripts/benchmark_capability_orchestrator.mjs +64 -0
- package/scripts/build-windows-installer.ps1 +259 -0
- package/scripts/build_forge_synthetic_image.py +328 -0
- package/scripts/check-reference-staleness.py +71 -0
- package/scripts/components.json +254 -0
- package/scripts/contracts/afyx-capability-request-v1.schema.json +189 -0
- package/scripts/contracts/afyx-capability-result-v1.schema.json +32 -0
- package/scripts/dogfood_engineering_comparison.mjs +303 -0
- package/scripts/engineering-assurance.json +28 -0
- package/scripts/install-afyx-context.ps1 +142 -0
- package/scripts/install-afyx-context.sh +126 -0
- package/scripts/install-afyx-forge.ps1 +265 -0
- package/scripts/install-afyx-forge.sh +273 -0
- package/scripts/install-afyx-graph.ps1 +571 -0
- package/scripts/install-afyx-graph.sh +438 -0
- package/scripts/install-codex-usage-tracker.ps1 +172 -0
- package/scripts/lib/AfyxComponents.psm1 +399 -0
- package/scripts/lib/AfyxSkillLifecycle.psm1 +289 -0
- package/scripts/lib/AfyxTerminal.psm1 +838 -0
- package/scripts/lib/afyx-components.sh +256 -0
- package/scripts/lib/afyx-skill-lifecycle.sh +271 -0
- package/scripts/link-global-dev.ps1 +193 -0
- package/scripts/link-global-dev.sh +130 -0
- package/scripts/phase8-paired-evidence.mjs +195 -0
- package/scripts/phase8-representative-workload.mjs +771 -0
- package/scripts/phase8-session-recorder.mjs +157 -0
- package/scripts/phase8_event_ledger.py +248 -0
- package/scripts/phase8_evidence_discovery.py +189 -0
- package/scripts/prepare-g6-package.mjs +349 -0
- package/scripts/resolve-git-release-artifacts.mjs +321 -0
- package/scripts/stage-npm-release.mjs +94 -0
- package/scripts/validate-afyx-graph.py +203 -0
- package/scripts/validate-components.py +194 -0
- package/scripts/validate-engineering-assurance.py +281 -0
- package/scripts/verify-graph-archive.mjs +64 -0
- package/skills/afyx-context/SKILL.md +26 -0
- package/skills/afyx-engineering-expert/README.md +42 -0
- package/skills/afyx-engineering-expert/SKILL.md +70 -0
- package/skills/afyx-engineering-expert/assets/result-template.md +15 -0
- package/skills/afyx-engineering-expert/references/ai-ml-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/business-analyst.md +17 -0
- package/skills/afyx-engineering-expert/references/clean-code-engineer.md +26 -0
- package/skills/afyx-engineering-expert/references/code-reviewer.md +24 -0
- package/skills/afyx-engineering-expert/references/cybersecurity-devsecops.md +17 -0
- package/skills/afyx-engineering-expert/references/data-analyst-bi.md +24 -0
- package/skills/afyx-engineering-expert/references/data-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/database-administrator.md +17 -0
- package/skills/afyx-engineering-expert/references/debugging-specialist.md +24 -0
- package/skills/afyx-engineering-expert/references/embedded-iot-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/erp-technical-specialist.md +17 -0
- package/skills/afyx-engineering-expert/references/hardware-diagnostics-auditor.md +24 -0
- package/skills/afyx-engineering-expert/references/hardware-electronics-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/integration-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/legacy-modernization-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/llmops-prompt-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/network-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/performance-benchmark-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/platform-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/product-manager.md +17 -0
- package/skills/afyx-engineering-expert/references/qa-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/site-reliability-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/software-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/solutions-architect.md +17 -0
- package/skills/afyx-engineering-expert/references/specialists-index.md +33 -0
- package/skills/afyx-engineering-expert/references/subject-matter-expert.md +17 -0
- package/skills/afyx-engineering-expert/references/system-analyst.md +17 -0
- package/skills/afyx-engineering-expert/references/technical-project-manager.md +24 -0
- package/skills/afyx-engineering-expert/references/technical-writer.md +24 -0
- package/skills/afyx-engineering-expert/references/ui-ux-designer.md +17 -0
- package/skills/afyx-engineering-expert/workflows/ai-data-erp.md +20 -0
- package/skills/afyx-engineering-expert/workflows/debugging.md +10 -0
- package/skills/afyx-engineering-expert/workflows/discovery-design.md +11 -0
- package/skills/afyx-engineering-expert/workflows/implementation.md +12 -0
- package/skills/afyx-engineering-expert/workflows/incident-reliability.md +12 -0
- package/skills/afyx-engineering-expert/workflows/review-audit.md +13 -0
- package/skills/afyx-forge/SKILL.md +43 -0
- package/skills/afyx-forge/references/adaptive-policy.md +19 -0
- package/skills/efficient-coding/SKILL.md +33 -0
- package/skills/efficient-coding/references/investigation.md +27 -0
- package/skills/efficient-coding/references/token-efficiency.md +25 -0
- package/skills/efficient-coding/references/tool-routing.md +13 -0
- package/skills/odoo-engineering/SKILL.md +33 -0
- package/skills/odoo-engineering/references/common.md +9 -0
- package/skills/odoo-engineering/references/odoo-10.md +32 -0
- package/skills/odoo-engineering/references/odoo-11.md +26 -0
- package/skills/odoo-engineering/references/odoo-12.md +31 -0
- package/skills/odoo-engineering/references/odoo-13.md +27 -0
- package/skills/odoo-engineering/references/odoo-14.md +31 -0
- package/skills/odoo-engineering/references/odoo-15.md +34 -0
- package/skills/odoo-engineering/references/odoo-16.md +37 -0
- package/skills/odoo-engineering/references/odoo-17.md +37 -0
- package/skills/odoo-engineering/references/odoo-18.md +48 -0
- package/skills/odoo-engineering/references/odoo-19.md +43 -0
- package/skills/odoo-engineering/references/odoo-20.md +39 -0
- package/skills/odoo-engineering/references/reference-schema.md +16 -0
- package/skills/odoo-engineering/references/version-detection.md +13 -0
- package/tools/codex-usage/CodexUsage.psm1 +496 -0
- package/tools/codex-usage/codex-usage-doctor.ps1 +150 -0
- package/tools/codex-usage/codex-usage-pricing.json +25 -0
- package/tools/codex-usage/codex-usage-stop.ps1 +167 -0
- package/tools/codex-usage/codex-usage-watch.ps1 +250 -0
- package/tools/codex-usage/vscode-user-task.json +31 -0
- package/tools/windows-setup/SetupBootstrapper.cs +258 -0
- package/uninstall.ps1 +189 -0
- package/uninstall.sh +167 -0
- package/update.ps1 +95 -0
- package/update.sh +67 -0
- package/verify.ps1 +411 -0
- package/verify.sh +265 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Afyx Forge Core — Main Programmatic Entrypoint
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { classifyTask } from './classifier.js';
|
|
8
|
+
import { deriveAdaptivePolicy } from './policy.js';
|
|
9
|
+
import { generateGuidance } from './guidance.js';
|
|
10
|
+
import { runDoctor } from './doctor.js';
|
|
11
|
+
import { extractRequirementIntelligence, buildExecutionPlan, recommendExecutionBudget } from './planning.js';
|
|
12
|
+
|
|
13
|
+
export const FORGE_CORE_VERSION = '0.1.0';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates an actionable engineering plan from a task description or task file.
|
|
17
|
+
*
|
|
18
|
+
* @param {object} options
|
|
19
|
+
* @param {string} [options.taskText]
|
|
20
|
+
* @param {string} [options.taskFile]
|
|
21
|
+
* @param {string} [options.format='json'] 'json' | 'markdown'
|
|
22
|
+
* @param {object} [options.environment]
|
|
23
|
+
* @param {string} [options.timestamp] Fixed timestamp for reproducible output
|
|
24
|
+
* @returns {object|string} The plan according to the requested format
|
|
25
|
+
*/
|
|
26
|
+
export function createForgePlan(options = {}) {
|
|
27
|
+
if (options.taskText !== undefined && typeof options.taskText !== 'string') {
|
|
28
|
+
throw new TypeError('taskText must be a string.');
|
|
29
|
+
}
|
|
30
|
+
if (options.timestamp !== undefined && (typeof options.timestamp !== 'string' || !Number.isFinite(Date.parse(options.timestamp)))) {
|
|
31
|
+
throw new TypeError('timestamp must be an ISO-compatible date string.');
|
|
32
|
+
}
|
|
33
|
+
let content = options.taskText || '';
|
|
34
|
+
let taskTitle = 'Engineering Task';
|
|
35
|
+
|
|
36
|
+
if (options.taskFile) {
|
|
37
|
+
const resolvedPath = path.resolve(options.taskFile);
|
|
38
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
39
|
+
throw new Error(`Task file not found: ${resolvedPath}`);
|
|
40
|
+
}
|
|
41
|
+
content = fs.readFileSync(resolvedPath, 'utf8');
|
|
42
|
+
taskTitle = path.basename(resolvedPath);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!content.trim()) {
|
|
46
|
+
throw new Error('Task content cannot be empty. Provide taskText or a valid taskFile.');
|
|
47
|
+
}
|
|
48
|
+
if (content.length > 65_536) throw new Error('Task content exceeds the bounded 65536-character limit.');
|
|
49
|
+
|
|
50
|
+
// Extract a brief title from the first non-empty line
|
|
51
|
+
const firstLine = content.trim().split(/\r?\n/)[0].replace(/^[#\s\-_*]+/, '').trim();
|
|
52
|
+
if (firstLine && firstLine.length < 80) {
|
|
53
|
+
taskTitle = firstLine;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Caller-supplied capability facts avoid a redundant host scan. Unknown
|
|
57
|
+
// capabilities are still discovered through the existing doctor.
|
|
58
|
+
const supplied = options.environment ?? {};
|
|
59
|
+
for (const key of ['hasGraph', 'hasContext', 'contextOptIn', 'graphOptIn', 'expertOptIn', 'providerSupported']) {
|
|
60
|
+
if (supplied[key] !== undefined && typeof supplied[key] !== 'boolean') {
|
|
61
|
+
throw new TypeError(`environment.${key} must be boolean.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const doc = supplied.hasGraph === undefined || supplied.hasContext === undefined ? runDoctor() : null;
|
|
65
|
+
const env = {
|
|
66
|
+
hasGraph: doc?.afyxComponents.afyxGraph === 'HEALTHY',
|
|
67
|
+
hasContext: doc?.afyxComponents.afyxContext.startsWith('HEALTHY'),
|
|
68
|
+
contextOptIn: process.env.AFYX_CONTEXT_OPT_IN !== '0',
|
|
69
|
+
...supplied,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const classification = classifyTask(content);
|
|
73
|
+
const requirements = extractRequirementIntelligence(content, classification);
|
|
74
|
+
const timestamp = options.timestamp ?? new Date().toISOString();
|
|
75
|
+
|
|
76
|
+
// If safety check fails, return refused plan
|
|
77
|
+
if (classification.status === 'REFUSED_UNSAFE') {
|
|
78
|
+
const refusedResult = {
|
|
79
|
+
contract: 'afyx-forge-plan/v1',
|
|
80
|
+
version: FORGE_CORE_VERSION,
|
|
81
|
+
timestamp,
|
|
82
|
+
taskSummary: {
|
|
83
|
+
title: taskTitle,
|
|
84
|
+
observedComplexity: classification.observedComplexity,
|
|
85
|
+
domainContext: 'Security / Safety Boundary Violation',
|
|
86
|
+
relevantFiles: classification.referencedFiles,
|
|
87
|
+
},
|
|
88
|
+
classification: {
|
|
89
|
+
primaryCategory: classification.primaryCategory,
|
|
90
|
+
riskLevel: classification.riskLevel,
|
|
91
|
+
frameworks: classification.frameworks,
|
|
92
|
+
confidence: classification.confidence,
|
|
93
|
+
},
|
|
94
|
+
adaptivePolicy: {
|
|
95
|
+
executionMode: 'SECURITY_DEFENSE_IN_DEPTH',
|
|
96
|
+
executionDirective: 'HIGH_RISK',
|
|
97
|
+
graphRouting: 'BYPASS',
|
|
98
|
+
graphRoutingReason: 'Task refused due to unsafe directive; no tooling invoked.',
|
|
99
|
+
contextEngine: 'BYPASS_TASK_REFUSED',
|
|
100
|
+
expertEngagement: 'Refusal Enforced',
|
|
101
|
+
},
|
|
102
|
+
guidance: {
|
|
103
|
+
investigationPriorities: ['Halt execution immediately: request contains unsafe or destructive actions.'],
|
|
104
|
+
toolRecommendations: { preferred: [], avoided: ['All autonomous execution'] },
|
|
105
|
+
validationScope: ['Verify user intent and obtain explicit owner authorization.'],
|
|
106
|
+
completionCriteria: ['Refusal report delivered to user.'],
|
|
107
|
+
},
|
|
108
|
+
boundedExecution: {
|
|
109
|
+
autonomousCodeExecution: false,
|
|
110
|
+
uncontrolledModelInvocation: false,
|
|
111
|
+
privilegeElevationAllowed: false,
|
|
112
|
+
governanceGateA8: 'GO_OWNER_APPROVED_LOCAL_SCOPE (formal 0/36 WAIVED_NOT_RUN)',
|
|
113
|
+
},
|
|
114
|
+
requirements,
|
|
115
|
+
executionPlan: { status: 'REFUSED_NOT_EXECUTED', steps: [], completionCriteria: [], stoppingCondition: 'Unsafe request refused.' },
|
|
116
|
+
executionBudget: { status: 'REFUSED_NOT_EXECUTED', observedToolCalls: 0, observedProviderTokens: null },
|
|
117
|
+
status: 'REFUSED_UNSAFE',
|
|
118
|
+
refusalReason: classification.refusalReason,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (options.format === 'markdown') {
|
|
122
|
+
return formatPlanAsMarkdown(refusedResult);
|
|
123
|
+
}
|
|
124
|
+
return refusedResult;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const policy = deriveAdaptivePolicy(classification, env);
|
|
128
|
+
const guidance = generateGuidance(classification, policy, content);
|
|
129
|
+
const executionPlan = buildExecutionPlan(requirements, classification, policy);
|
|
130
|
+
const executionBudget = recommendExecutionBudget(policy);
|
|
131
|
+
|
|
132
|
+
const planResult = {
|
|
133
|
+
contract: 'afyx-forge-plan/v1',
|
|
134
|
+
version: FORGE_CORE_VERSION,
|
|
135
|
+
timestamp,
|
|
136
|
+
taskSummary: {
|
|
137
|
+
title: taskTitle,
|
|
138
|
+
observedComplexity: classification.observedComplexity,
|
|
139
|
+
domainContext: classification.frameworks.length ? classification.frameworks.join(', ') : 'Standard Software Engineering',
|
|
140
|
+
relevantFiles: classification.referencedFiles,
|
|
141
|
+
},
|
|
142
|
+
classification: {
|
|
143
|
+
primaryCategory: classification.primaryCategory,
|
|
144
|
+
riskLevel: classification.riskLevel,
|
|
145
|
+
frameworks: classification.frameworks,
|
|
146
|
+
confidence: classification.confidence,
|
|
147
|
+
},
|
|
148
|
+
adaptivePolicy: {
|
|
149
|
+
executionMode: policy.executionMode,
|
|
150
|
+
executionDirective: policy.executionDirective,
|
|
151
|
+
graphRouting: policy.graphRouting,
|
|
152
|
+
graphRoutingReason: policy.graphRoutingReason,
|
|
153
|
+
contextEngine: policy.contextEngine,
|
|
154
|
+
expertEngagement: policy.expertEngagement,
|
|
155
|
+
},
|
|
156
|
+
guidance: {
|
|
157
|
+
investigationPriorities: guidance.investigationPriorities,
|
|
158
|
+
toolRecommendations: guidance.toolRecommendations,
|
|
159
|
+
validationScope: guidance.validationScope,
|
|
160
|
+
completionCriteria: guidance.completionCriteria,
|
|
161
|
+
},
|
|
162
|
+
requirements,
|
|
163
|
+
executionPlan,
|
|
164
|
+
executionBudget,
|
|
165
|
+
boundedExecution: {
|
|
166
|
+
autonomousCodeExecution: false,
|
|
167
|
+
uncontrolledModelInvocation: false,
|
|
168
|
+
privilegeElevationAllowed: false,
|
|
169
|
+
governanceGateA8: 'GO_OWNER_APPROVED_LOCAL_SCOPE (formal 0/36 WAIVED_NOT_RUN)',
|
|
170
|
+
},
|
|
171
|
+
status: 'PLANNED',
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
if (options.format === 'markdown') {
|
|
175
|
+
return formatPlanAsMarkdown(planResult);
|
|
176
|
+
}
|
|
177
|
+
return planResult;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Formats a structured plan object into human-readable GitHub-flavored markdown.
|
|
182
|
+
* @param {object} plan
|
|
183
|
+
* @returns {string} Markdown representation
|
|
184
|
+
*/
|
|
185
|
+
export function formatPlanAsMarkdown(plan) {
|
|
186
|
+
const isRefused = plan.status === 'REFUSED_UNSAFE';
|
|
187
|
+
|
|
188
|
+
let md = `# Afyx Forge Engineering Plan: ${plan.taskSummary.title}\n\n`;
|
|
189
|
+
md += `**Contract:** \`${plan.contract}\` | **Version:** \`${plan.version}\` | **Status:** **${plan.status}**\n\n`;
|
|
190
|
+
|
|
191
|
+
if (isRefused) {
|
|
192
|
+
md += `> [!CAUTION]\n`;
|
|
193
|
+
md += `> **Execution Refused:** ${plan.refusalReason}\n`;
|
|
194
|
+
md += `> Forge Core enforces bounded execution: destructive operations, credential leakage, and unauthorized push/commit actions are strictly prohibited.\n\n`;
|
|
195
|
+
return md;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
md += `## 1. Task Assessment\n`;
|
|
199
|
+
md += `- **Primary Category:** \`${plan.classification.primaryCategory}\`\n`;
|
|
200
|
+
md += `- **Risk Level:** **${plan.classification.riskLevel}**\n`;
|
|
201
|
+
md += `- **Observed Complexity:** ${plan.taskSummary.observedComplexity}\n`;
|
|
202
|
+
md += `- **Domain / Frameworks:** ${plan.taskSummary.domainContext}\n`;
|
|
203
|
+
if (plan.taskSummary.relevantFiles.length > 0) {
|
|
204
|
+
md += `- **Referenced Files:** ${plan.taskSummary.relevantFiles.map((f) => `\`${f}\``).join(', ')}\n`;
|
|
205
|
+
}
|
|
206
|
+
md += `\n`;
|
|
207
|
+
|
|
208
|
+
md += `## 2. Adaptive Engineering Policy\n`;
|
|
209
|
+
md += `- **Execution Mode:** \`${plan.adaptivePolicy.executionMode}\`\n`;
|
|
210
|
+
md += `- **Afyx Graph Routing:** \`${plan.adaptivePolicy.graphRouting}\`\n`;
|
|
211
|
+
md += ` - *Reason:* ${plan.adaptivePolicy.graphRoutingReason}\n`;
|
|
212
|
+
md += `- **Context Engine:** \`${plan.adaptivePolicy.contextEngine}\` (available by default when installed; execution remains on demand)\n`;
|
|
213
|
+
md += `- **Specialist Guidance:** ${plan.adaptivePolicy.expertEngagement}\n\n`;
|
|
214
|
+
|
|
215
|
+
md += `## 3. Actionable Engineering Guidance\n\n`;
|
|
216
|
+
md += `### Investigation Priorities\n`;
|
|
217
|
+
for (const step of plan.guidance.investigationPriorities) {
|
|
218
|
+
md += `- ${step}\n`;
|
|
219
|
+
}
|
|
220
|
+
md += `\n`;
|
|
221
|
+
|
|
222
|
+
md += `### Tool Recommendations\n`;
|
|
223
|
+
md += `**Preferred Tools:**\n`;
|
|
224
|
+
for (const tool of plan.guidance.toolRecommendations.preferred) {
|
|
225
|
+
md += `- :white_check_mark: ${tool}\n`;
|
|
226
|
+
}
|
|
227
|
+
md += `\n**Avoided Tools (Lowest-cost discipline):**\n`;
|
|
228
|
+
for (const tool of plan.guidance.toolRecommendations.avoided) {
|
|
229
|
+
md += `- :x: ${tool}\n`;
|
|
230
|
+
}
|
|
231
|
+
md += `\n`;
|
|
232
|
+
|
|
233
|
+
md += `### Validation Scope\n`;
|
|
234
|
+
for (const item of plan.guidance.validationScope) {
|
|
235
|
+
md += `- [ ] ${item}\n`;
|
|
236
|
+
}
|
|
237
|
+
md += `\n`;
|
|
238
|
+
|
|
239
|
+
md += `### Explicit Completion Criteria\n`;
|
|
240
|
+
for (const item of plan.guidance.completionCriteria) {
|
|
241
|
+
md += `- [ ] ${item}\n`;
|
|
242
|
+
}
|
|
243
|
+
md += `\n`;
|
|
244
|
+
|
|
245
|
+
md += `## 4. Request-grounded Requirements\n`;
|
|
246
|
+
md += `- **Objective:** ${plan.requirements.objective || 'Not explicitly stated'}\n`;
|
|
247
|
+
for (const item of plan.requirements.functionalRequirements) md += `- **Requirement:** ${item}\n`;
|
|
248
|
+
for (const item of plan.requirements.constraints) md += `- **Constraint:** ${item}\n`;
|
|
249
|
+
for (const item of plan.requirements.acceptanceCriteria) md += `- **Acceptance:** ${item}\n`;
|
|
250
|
+
md += `\n## 5. Proposed Execution Plan\n`;
|
|
251
|
+
for (const step of plan.executionPlan.steps) md += `- **${step.id}:** ${step.action}\n`;
|
|
252
|
+
md += `- **Stop:** ${plan.executionPlan.stoppingCondition}\n`;
|
|
253
|
+
md += `\n## 6. Recommended Budget\n`;
|
|
254
|
+
md += `- **Tool-call ceiling:** ${plan.executionBudget.toolCallCeiling}; **retry ceiling:** ${plan.executionBudget.retryCeiling}\n`;
|
|
255
|
+
md += `- **Investigation depth:** ${plan.executionBudget.investigationDepth}; **validation:** ${plan.executionBudget.validationIntensity}\n`;
|
|
256
|
+
md += `- **Status:** ${plan.executionBudget.status}; provider tokens not measured\n\n`;
|
|
257
|
+
md += `## 7. Governance & Trust Boundary\n`;
|
|
258
|
+
md += `- **Autonomous Code Execution:** \`${plan.boundedExecution.autonomousCodeExecution}\`\n`;
|
|
259
|
+
md += `- **Uncontrolled Model Invocation:** \`${plan.boundedExecution.uncontrolledModelInvocation}\`\n`;
|
|
260
|
+
md += `- **Campaign Governance:** \`${plan.boundedExecution.governanceGateA8}\`\n`;
|
|
261
|
+
|
|
262
|
+
return md;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export { runDoctor } from './doctor.js';
|
|
266
|
+
export {
|
|
267
|
+
WORKFLOW_REFINER_CONTRACT,
|
|
268
|
+
stripInstructionBoilerplate,
|
|
269
|
+
extractStructuredCriteria,
|
|
270
|
+
refineTaskDirective,
|
|
271
|
+
evaluateTaskCompletion,
|
|
272
|
+
} from './workflow-refiner.js';
|
|
273
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** Bounded, deterministic planning facts. No source edit or tool execution occurs here. */
|
|
2
|
+
|
|
3
|
+
const MAX_ITEMS = 12;
|
|
4
|
+
const MAX_LINE = 300;
|
|
5
|
+
const SECTIONS = new Map([
|
|
6
|
+
['objective', 'objective'], ['goal', 'objective'],
|
|
7
|
+
['requirements', 'functionalRequirements'], ['functional requirements', 'functionalRequirements'],
|
|
8
|
+
['constraints', 'constraints'], ['dependencies', 'dependencies'],
|
|
9
|
+
['acceptance', 'acceptanceCriteria'], ['acceptance criteria', 'acceptanceCriteria'],
|
|
10
|
+
['assumptions', 'assumptions'], ['unknowns', 'unknownAssumptions'],
|
|
11
|
+
['scope', 'scopeBoundaries'], ['out of scope', 'scopeBoundaries'],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
function addUnique(items, value) {
|
|
15
|
+
const item = value.replace(/^(?:[-*]\s+|\d+[.)]\s+)/, '').trim().slice(0, MAX_LINE);
|
|
16
|
+
if (item && items.length < MAX_ITEMS && !items.includes(item)) items.push(item);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Extract only statements actually present in the request. */
|
|
20
|
+
export function extractRequirementIntelligence(taskText, classification) {
|
|
21
|
+
const facts = {
|
|
22
|
+
objective: '', functionalRequirements: [], affectedFiles: [...classification.referencedFiles],
|
|
23
|
+
affectedComponents: [], constraints: [], dependencies: [], assumptions: [], unknownAssumptions: [],
|
|
24
|
+
acceptanceCriteria: [], scopeBoundaries: [], riskLevel: classification.riskLevel,
|
|
25
|
+
evidenceStatus: 'REQUEST_TEXT_ONLY',
|
|
26
|
+
};
|
|
27
|
+
for (const component of ['Afyx Graph', 'Afyx Context', 'Afyx Forge', 'Afyx Engineering Expert', 'Odoo Engineering']) {
|
|
28
|
+
if (taskText.toLowerCase().includes(component.toLowerCase())) facts.affectedComponents.push(component);
|
|
29
|
+
}
|
|
30
|
+
let section = '';
|
|
31
|
+
for (const raw of taskText.split(/\r?\n/).slice(0, 500)) {
|
|
32
|
+
const line = raw.trim();
|
|
33
|
+
if (!line) continue;
|
|
34
|
+
const heading = /^(?:#{1,4}\s*)?(objective|goal|functional requirements?|requirements?|constraints?|dependencies?|acceptance criteria|acceptance|assumptions?|unknowns?|out of scope|scope)\s*:?(?:\s+(.+))?$/i.exec(line);
|
|
35
|
+
if (heading) {
|
|
36
|
+
const name = heading[1].toLowerCase();
|
|
37
|
+
section = SECTIONS.get(name) ?? SECTIONS.get(`${name}s`) ?? '';
|
|
38
|
+
if (heading[2]) {
|
|
39
|
+
if (section === 'objective') facts.objective = heading[2].slice(0, MAX_LINE);
|
|
40
|
+
else if (section) addUnique(facts[section], heading[2]);
|
|
41
|
+
}
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (line.startsWith('#')) { section = ''; continue; }
|
|
45
|
+
if (section === 'objective' && !facts.objective) facts.objective = line.slice(0, MAX_LINE);
|
|
46
|
+
else if (section && section !== 'objective') addUnique(facts[section], line);
|
|
47
|
+
else if (!facts.objective && !line.startsWith('#')) facts.objective = line.slice(0, MAX_LINE);
|
|
48
|
+
if (!section && /^(?:acceptance|expected)\s*:/i.test(line)) {
|
|
49
|
+
addUnique(facts.acceptanceCriteria, line.replace(/^[^:]+:\s*/, ''));
|
|
50
|
+
}
|
|
51
|
+
if (!section && /^(?:depends on|requires)\b/i.test(line)) addUnique(facts.dependencies, line);
|
|
52
|
+
if (/\b(?:must not|do not|never|without)\b/i.test(line)) addUnique(facts.constraints, line);
|
|
53
|
+
}
|
|
54
|
+
return facts;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const BUDGETS = Object.freeze({
|
|
58
|
+
DIRECT_MINIMAL: [1, 6, 1, 120_000, 'focused'],
|
|
59
|
+
FOCUSED_INVESTIGATION: [2, 14, 2, 300_000, 'focused-plus-regression'],
|
|
60
|
+
STRUCTURAL_GRAPH_AWARE: [3, 22, 2, 600_000, 'affected-components'],
|
|
61
|
+
DOMAIN_SPECIALIST: [3, 22, 2, 600_000, 'domain-contracts'],
|
|
62
|
+
SECURITY_DEFENSE_IN_DEPTH: [4, 28, 1, 900_000, 'positive-negative-regression'],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** Recommendations are ceilings for a proposed plan, not observed usage. */
|
|
66
|
+
export function recommendExecutionBudget(policy) {
|
|
67
|
+
const [investigationDepth, toolCallCeiling, retryCeiling, elapsedTimeCeilingMs, validationIntensity] =
|
|
68
|
+
BUDGETS[policy.executionMode] ?? BUDGETS.FOCUSED_INVESTIGATION;
|
|
69
|
+
return {
|
|
70
|
+
status: 'RECOMMENDED_NOT_ENFORCED', investigationDepth, toolCallCeiling,
|
|
71
|
+
retryCeiling, elapsedTimeCeilingMs, validationIntensity,
|
|
72
|
+
contextGuideline: 'Read only relevant source; use Context for genuinely large output when enabled.',
|
|
73
|
+
observedToolCalls: null, observedProviderTokens: null,
|
|
74
|
+
escalation: policy.executionMode === 'SECURITY_DEFENSE_IN_DEPTH'
|
|
75
|
+
? 'Stop at an authorization or integrity boundary; require owner decision.'
|
|
76
|
+
: 'Stop when evidence is insufficient or the retry ceiling is reached.',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Four ordered, minimal phases; each item is explicitly a proposal. */
|
|
81
|
+
export function buildExecutionPlan(requirements, classification, policy) {
|
|
82
|
+
const target = requirements.affectedFiles.length
|
|
83
|
+
? ` in ${requirements.affectedFiles.slice(0, 3).join(', ')}` : ' in the smallest verified scope';
|
|
84
|
+
const investigation = policy.executionMode === 'DIRECT_MINIMAL'
|
|
85
|
+
? `Inspect the named source${target} and its nearest test.`
|
|
86
|
+
: policy.executionMode === 'SECURITY_DEFENSE_IN_DEPTH'
|
|
87
|
+
? 'Map trust boundaries and reproduce the unsafe or failing case before editing.'
|
|
88
|
+
: policy.executionMode === 'STRUCTURAL_GRAPH_AWARE'
|
|
89
|
+
? 'Map affected interfaces and dependencies with available, authorized evidence.'
|
|
90
|
+
: 'Reproduce the symptom and isolate the smallest supported root cause.';
|
|
91
|
+
const validation = policy.executionMode === 'SECURITY_DEFENSE_IN_DEPTH'
|
|
92
|
+
? 'Run positive, negative, and regression tests for the affected security boundary.'
|
|
93
|
+
: `Run focused tests${target} and the required affected regression gate.`;
|
|
94
|
+
return {
|
|
95
|
+
status: 'PROPOSED_NOT_EXECUTED',
|
|
96
|
+
steps: [
|
|
97
|
+
{ id: 'analysis', dependsOn: [], action: investigation },
|
|
98
|
+
{ id: 'implementation', dependsOn: ['analysis'], action: `Apply the smallest justified change${target}.` },
|
|
99
|
+
{ id: 'validation', dependsOn: ['implementation'], action: validation },
|
|
100
|
+
{ id: 'delivery', dependsOn: ['validation'], action: 'Review the diff and report actual evidence and unresolved risks.' },
|
|
101
|
+
],
|
|
102
|
+
completionCriteria: requirements.acceptanceCriteria.length
|
|
103
|
+
? requirements.acceptanceCriteria
|
|
104
|
+
: ['Explicit acceptance criteria are missing; confirm them before declaring completion.'],
|
|
105
|
+
stoppingCondition: 'Stop at an unresolved safety boundary or when required evidence is unavailable.',
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Afyx Forge Core — Adaptive Engineering Policy Engine
|
|
3
|
+
* Determines proportional execution mode, Graph-aware routing,
|
|
4
|
+
* and component cooperation according to Afyx Adaptive Tool Routing principles.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { TASK_CATEGORIES, RISK_LEVELS } from './classifier.js';
|
|
8
|
+
|
|
9
|
+
export const EXECUTION_MODES = Object.freeze({
|
|
10
|
+
DIRECT_MINIMAL: 'DIRECT_MINIMAL',
|
|
11
|
+
FOCUSED_INVESTIGATION: 'FOCUSED_INVESTIGATION',
|
|
12
|
+
STRUCTURAL_GRAPH_AWARE: 'STRUCTURAL_GRAPH_AWARE',
|
|
13
|
+
DOMAIN_SPECIALIST: 'DOMAIN_SPECIALIST',
|
|
14
|
+
SECURITY_DEFENSE_IN_DEPTH: 'SECURITY_DEFENSE_IN_DEPTH',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Derives the proportional adaptive policy from task classification and environment context.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} classification
|
|
21
|
+
* @param {object} [environment={}]
|
|
22
|
+
* @param {boolean} [environment.hasGraph=false]
|
|
23
|
+
* @param {boolean} [environment.hasContext=false]
|
|
24
|
+
* @param {boolean} [environment.contextOptIn=true] - Explicit false disables the installed Context Engine
|
|
25
|
+
* @returns {object} Adaptive policy object
|
|
26
|
+
*/
|
|
27
|
+
export function deriveAdaptivePolicy(classification, environment = {}) {
|
|
28
|
+
const { primaryCategory, riskLevel, frameworks = [], referencedFiles = [] } = classification;
|
|
29
|
+
const { hasGraph = false, hasContext = false, contextOptIn = true,
|
|
30
|
+
graphOptIn = true, expertOptIn = true, providerSupported = true } = environment;
|
|
31
|
+
|
|
32
|
+
// 1. Determine Execution Mode
|
|
33
|
+
let executionMode = EXECUTION_MODES.DIRECT_MINIMAL;
|
|
34
|
+
if (primaryCategory === TASK_CATEGORIES.SECURITY_SENSITIVE || riskLevel === RISK_LEVELS.CRITICAL) {
|
|
35
|
+
executionMode = EXECUTION_MODES.SECURITY_DEFENSE_IN_DEPTH;
|
|
36
|
+
} else if (frameworks.includes('Odoo') || primaryCategory === TASK_CATEGORIES.DATA_RELIABILITY) {
|
|
37
|
+
executionMode = EXECUTION_MODES.DOMAIN_SPECIALIST;
|
|
38
|
+
} else if (primaryCategory === TASK_CATEGORIES.CROSS_MODULE_CHANGE) {
|
|
39
|
+
executionMode = EXECUTION_MODES.STRUCTURAL_GRAPH_AWARE;
|
|
40
|
+
} else if (primaryCategory === TASK_CATEGORIES.UNKNOWN_DEFECT_DIAGNOSIS) {
|
|
41
|
+
executionMode = EXECUTION_MODES.FOCUSED_INVESTIGATION;
|
|
42
|
+
} else {
|
|
43
|
+
executionMode = EXECUTION_MODES.DIRECT_MINIMAL;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 2. Graph-Aware Routing (Afyx Adaptive Routing Rule)
|
|
47
|
+
// Principle: Lowest-cost reliable evidence. Avoid Graph for known-file, simple edit, config lookup.
|
|
48
|
+
// Prefer Graph ONLY when cross-file relationships, inheritance, or multi-module impact materially help.
|
|
49
|
+
let graphRouting = 'BYPASS';
|
|
50
|
+
let graphRoutingReason = 'Direct-source reading, ripgrep, or targeted tests are sufficient; Graph is bypassed for minimal cost.';
|
|
51
|
+
|
|
52
|
+
const isCrossModuleOrInheritance =
|
|
53
|
+
primaryCategory === TASK_CATEGORIES.CROSS_MODULE_CHANGE ||
|
|
54
|
+
(frameworks.includes('Odoo') && referencedFiles.length > 1) ||
|
|
55
|
+
referencedFiles.length >= 3;
|
|
56
|
+
|
|
57
|
+
if (isCrossModuleOrInheritance) {
|
|
58
|
+
if (providerSupported === false) {
|
|
59
|
+
graphRouting = 'BYPASS_PROVIDER_UNSUPPORTED';
|
|
60
|
+
graphRoutingReason = 'The selected provider does not support the required Afyx Graph surface.';
|
|
61
|
+
} else if (graphOptIn === false) {
|
|
62
|
+
graphRouting = 'BYPASS_USER_DISABLED';
|
|
63
|
+
graphRoutingReason = 'Afyx Graph explicitly disabled by the user.';
|
|
64
|
+
} else if (hasGraph) {
|
|
65
|
+
graphRouting = 'RECOMMENDED';
|
|
66
|
+
graphRoutingReason = 'Cross-module relationships or framework inheritance identified; Afyx Graph exploration recommended.';
|
|
67
|
+
} else {
|
|
68
|
+
graphRouting = 'NOT_AVAILABLE';
|
|
69
|
+
graphRoutingReason = 'Cross-module analysis identified, but Afyx Graph is not installed; falling back to direct-source reading.';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 3. Context Engine Cooperation
|
|
74
|
+
// Available by default when installed and healthy. This is a planning status,
|
|
75
|
+
// not evidence that a Context operation was executed for this task.
|
|
76
|
+
let contextEngine = 'NOT_AVAILABLE';
|
|
77
|
+
if (contextOptIn === false) contextEngine = 'BYPASS_USER_DISABLED';
|
|
78
|
+
else if (providerSupported === false) contextEngine = 'BYPASS_PROVIDER_UNSUPPORTED';
|
|
79
|
+
else if (hasContext) contextEngine = 'ACTIVE';
|
|
80
|
+
|
|
81
|
+
// 4. Expert Cooperation
|
|
82
|
+
let expertEngagement = 'NONE';
|
|
83
|
+
if (frameworks.includes('Odoo')) {
|
|
84
|
+
expertEngagement = 'Odoo Engineering Skill (Version-aware schema & ORM guidance)';
|
|
85
|
+
} else if (primaryCategory === TASK_CATEGORIES.SECURITY_SENSITIVE) {
|
|
86
|
+
expertEngagement = 'Afyx Engineering Expert: Cybersecurity / DevSecOps role';
|
|
87
|
+
} else if (primaryCategory === TASK_CATEGORIES.DATA_RELIABILITY) {
|
|
88
|
+
expertEngagement = 'Afyx Engineering Expert: Database Administrator role';
|
|
89
|
+
} else if (executionMode === EXECUTION_MODES.STRUCTURAL_GRAPH_AWARE) {
|
|
90
|
+
expertEngagement = 'Afyx Engineering Expert: Solutions Architect role';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (expertOptIn === false) expertEngagement = 'BYPASS_USER_DISABLED';
|
|
94
|
+
else if (providerSupported === false) expertEngagement = 'BYPASS_PROVIDER_UNSUPPORTED';
|
|
95
|
+
const executionDirective = executionMode === EXECUTION_MODES.DIRECT_MINIMAL
|
|
96
|
+
? (primaryCategory === TASK_CATEGORIES.KNOWN_FILE_BUG ? 'SURGICAL_KNOWN_FILE' : 'DIRECT_SIMPLE')
|
|
97
|
+
: executionMode === EXECUTION_MODES.FOCUSED_INVESTIGATION ? 'FOCUSED_DIAGNOSIS'
|
|
98
|
+
: executionMode === EXECUTION_MODES.STRUCTURAL_GRAPH_AWARE ? 'CROSS_FILE'
|
|
99
|
+
: executionMode === EXECUTION_MODES.DOMAIN_SPECIALIST ? 'DOMAIN_AWARE' : 'HIGH_RISK';
|
|
100
|
+
return {
|
|
101
|
+
executionMode,
|
|
102
|
+
executionDirective,
|
|
103
|
+
graphRouting,
|
|
104
|
+
graphRoutingReason,
|
|
105
|
+
contextEngine,
|
|
106
|
+
expertEngagement,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AFYX Forge Core - Workflow Intelligence & Instruction Refiner
|
|
3
|
+
*
|
|
4
|
+
* Distills raw task instructions into bounded, high-signal engineering directives.
|
|
5
|
+
* Eliminates redundant LLM prompt boilerplate ('slop'), structures concrete
|
|
6
|
+
* acceptance criteria, and enforces rigorous completion verification without
|
|
7
|
+
* introducing autonomous execution authority.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const WORKFLOW_REFINER_CONTRACT = 'afyx-forge-refiner-v1';
|
|
11
|
+
|
|
12
|
+
const BOILERPLATE_PATTERNS = [
|
|
13
|
+
/^\s*(?:Please\s+)?(?:act\s+as|you\s+are)\s+(?:an?\s+)?(?:senior|principal|expert|lead|staff)\s+[^.\n]+[.\n]?/gim,
|
|
14
|
+
/^\s*(?:Please\s+)?make\s+sure\s+you\s+(?:think\s+step\s+by\s+step|are\s+very\s+careful)[.\n]?/gim,
|
|
15
|
+
/^\s*(?:Remember\s+to\s+)?always\s+follow\s+best\s+practices[.\n]?/gim,
|
|
16
|
+
/^\s*(?:In\s+this\s+task,\s+)?we\s+need\s+to\s+carefully[.\n]?/gim,
|
|
17
|
+
/^\s*(?:Note\s+that\s+)?quality\s+is\s+of\s+utmost\s+importance[.\n]?/gim,
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Strips superficial prompt boilerplate and filler text.
|
|
22
|
+
*/
|
|
23
|
+
export function stripInstructionBoilerplate(text) {
|
|
24
|
+
if (!text || typeof text !== 'string') return '';
|
|
25
|
+
let cleaned = text;
|
|
26
|
+
for (const pattern of BOILERPLATE_PATTERNS) {
|
|
27
|
+
cleaned = cleaned.replace(pattern, '');
|
|
28
|
+
}
|
|
29
|
+
return cleaned.trim();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Extracts structured acceptance criteria and constraints from an instruction string.
|
|
34
|
+
*/
|
|
35
|
+
export function extractStructuredCriteria(taskText) {
|
|
36
|
+
const lines = taskText.split(/\r?\n/);
|
|
37
|
+
const objectives = [];
|
|
38
|
+
const criteria = [];
|
|
39
|
+
const constraints = [];
|
|
40
|
+
|
|
41
|
+
let currentSection = 'general';
|
|
42
|
+
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
const trimmed = line.trim();
|
|
45
|
+
if (!trimmed) continue;
|
|
46
|
+
|
|
47
|
+
// Detect section headers
|
|
48
|
+
if (/^(?:#+\s*)?(?:acceptance\s+criteria|requirements|kriteria\s+penerimaan)/i.test(trimmed)) {
|
|
49
|
+
currentSection = 'criteria';
|
|
50
|
+
continue;
|
|
51
|
+
} else if (/^(?:#+\s*)?(?:constraints|restrictions|batasan|larangan)/i.test(trimmed)) {
|
|
52
|
+
currentSection = 'constraints';
|
|
53
|
+
continue;
|
|
54
|
+
} else if (/^(?:#+\s*)?(?:objective|goals|tujuan|mission)/i.test(trimmed)) {
|
|
55
|
+
currentSection = 'objective';
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Bullet points / numbered lists
|
|
60
|
+
const isBullet = /^[-*•]\s+|^\[[ xX]\]\s+|^\d+\.\s+/.test(trimmed);
|
|
61
|
+
const content = trimmed.replace(/^[-*•]\s+|^\[[ xX]\]\s+|^\d+\.\s+/, '').trim();
|
|
62
|
+
|
|
63
|
+
if (isBullet) {
|
|
64
|
+
if (currentSection === 'criteria') {
|
|
65
|
+
criteria.push({ id: `AC-${criteria.length + 1}`, text: content });
|
|
66
|
+
} else if (currentSection === 'constraints') {
|
|
67
|
+
constraints.push({ id: `CONST-${constraints.length + 1}`, text: content });
|
|
68
|
+
} else if (currentSection === 'objective') {
|
|
69
|
+
objectives.push(content);
|
|
70
|
+
} else {
|
|
71
|
+
// Infer from keywords
|
|
72
|
+
if (/\b(?:must\s+not|never|no\s+|larang|jangan)\b/i.test(content)) {
|
|
73
|
+
constraints.push({ id: `CONST-${constraints.length + 1}`, text: content });
|
|
74
|
+
} else if (/\b(?:must|shall|verify|test|prove|harus|pastikan)\b/i.test(content)) {
|
|
75
|
+
criteria.push({ id: `AC-${criteria.length + 1}`, text: content });
|
|
76
|
+
} else {
|
|
77
|
+
objectives.push(content);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else if (!trimmed.startsWith('#')) {
|
|
81
|
+
if (currentSection === 'objective' || currentSection === 'general') {
|
|
82
|
+
if (objectives.length < 3) objectives.push(trimmed);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Ensure default criteria if none parsed
|
|
88
|
+
if (criteria.length === 0) {
|
|
89
|
+
criteria.push({ id: 'AC-1', text: 'Implementation passes automated tests and regression checks' });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
objectives: objectives.slice(0, 5),
|
|
94
|
+
criteria,
|
|
95
|
+
constraints,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Refines a raw task directive into high-signal engineering specifications.
|
|
101
|
+
*/
|
|
102
|
+
export function refineTaskDirective(rawTaskText) {
|
|
103
|
+
const stripped = stripInstructionBoilerplate(rawTaskText);
|
|
104
|
+
const structured = extractStructuredCriteria(stripped);
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
contract: WORKFLOW_REFINER_CONTRACT,
|
|
108
|
+
originalLength: rawTaskText.length,
|
|
109
|
+
refinedLength: stripped.length,
|
|
110
|
+
characterSavings: Math.max(0, rawTaskText.length - stripped.length),
|
|
111
|
+
objectives: structured.objectives,
|
|
112
|
+
acceptanceCriteria: structured.criteria,
|
|
113
|
+
constraints: structured.constraints,
|
|
114
|
+
definitionOfDone: [
|
|
115
|
+
'All source changes match native architecture contracts',
|
|
116
|
+
'No third-party proprietary implementation files imported',
|
|
117
|
+
'Positive and negative unit/integration tests verified',
|
|
118
|
+
'Pre-push and workspace hygiene self-tests pass',
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Validates task completion against refined acceptance criteria.
|
|
125
|
+
*/
|
|
126
|
+
export function evaluateTaskCompletion(criteriaList, verifiedEvidence = []) {
|
|
127
|
+
const evidenceText = verifiedEvidence.join(' ').toLowerCase();
|
|
128
|
+
const evaluation = criteriaList.map((criterion) => {
|
|
129
|
+
// Check key terms from criterion in verified evidence
|
|
130
|
+
const words = criterion.text.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
|
|
131
|
+
const matchedWords = words.filter((w) => evidenceText.includes(w));
|
|
132
|
+
const satisfied = matchedWords.length >= Math.ceil(words.length * 0.5);
|
|
133
|
+
return {
|
|
134
|
+
id: criterion.id,
|
|
135
|
+
text: criterion.text,
|
|
136
|
+
satisfied,
|
|
137
|
+
matchedTerms: matchedWords,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const satisfiedCount = evaluation.filter((e) => e.satisfied).length;
|
|
142
|
+
const score = criteriaList.length > 0 ? satisfiedCount / criteriaList.length : 1.0;
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
isComplete: score >= 1.0,
|
|
146
|
+
completionScore: Number(score.toFixed(2)),
|
|
147
|
+
totalCriteria: criteriaList.length,
|
|
148
|
+
satisfiedCriteriaCount: satisfiedCount,
|
|
149
|
+
details: evaluation,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"product_name": "Afyx Graph",
|
|
3
|
+
"product_version": "1.0.0",
|
|
4
|
+
"package": "@a5zero7/afyx-graph",
|
|
5
|
+
"repository": "https://github.com/a5zero7/afyx-engineering-kit",
|
|
6
|
+
"cli": "afyx-graph",
|
|
7
|
+
"runtime_path": "~/.afyx/graph",
|
|
8
|
+
"state_directory": ".afyx-graph",
|
|
9
|
+
"database_filename": "afyx-graph.db",
|
|
10
|
+
"mcp_server": "afyx_graph",
|
|
11
|
+
"supported_platforms": [
|
|
12
|
+
"win32-x64",
|
|
13
|
+
"win32-arm64",
|
|
14
|
+
"linux-x64",
|
|
15
|
+
"linux-arm64",
|
|
16
|
+
"darwin-x64",
|
|
17
|
+
"darwin-arm64"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT"
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Afyx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|