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,451 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Afyx Modular Runtime Integration & Intelligent Capability Activation (v1)
|
|
4
|
+
*
|
|
5
|
+
* Governing Principle:
|
|
6
|
+
* "Standalone by Design, Integrated by Contract, Activated by Need."
|
|
7
|
+
*
|
|
8
|
+
* Connects the accepted deterministic capability-planning foundation (K01)
|
|
9
|
+
* to live Afyx engineering and provider integration surfaces.
|
|
10
|
+
*
|
|
11
|
+
* Explicit 5-layer separation:
|
|
12
|
+
* 1. Deterministic capability planning (resolveModularCapabilityPlan)
|
|
13
|
+
* 2. Capability eligibility and single domain authority
|
|
14
|
+
* 3. Runtime readiness and authorization checks
|
|
15
|
+
* 4. Provider-mediated capability preparation and surface mapping
|
|
16
|
+
* 5. Bounded, sanitized runtime observability and execution prep
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
20
|
+
import { resolve } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
AFYX_MODULAR_INTEGRATION_CONTRACT,
|
|
25
|
+
PRODUCT_INVENTORY,
|
|
26
|
+
resolveModularCapabilityPlan,
|
|
27
|
+
} from './afyx-modular-integration.mjs';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
resolveAfyxToolFamilyRoute,
|
|
31
|
+
} from './afyx-tool-family-routing.mjs';
|
|
32
|
+
|
|
33
|
+
export const AFYX_MODULAR_RUNTIME_CONTRACT = 'AfyxModularRuntimeActivation/v1';
|
|
34
|
+
|
|
35
|
+
// Load accepted providers directly from the authoritative component registry
|
|
36
|
+
const REGISTRY = JSON.parse(readFileSync(new URL('./components.json', import.meta.url), 'utf8'));
|
|
37
|
+
export const ACCEPTED_PROVIDERS = Object.freeze(REGISTRY.providers.map((p) => p.provider));
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Domain authorities map: exactly one primary authority per capability domain.
|
|
41
|
+
*/
|
|
42
|
+
export const DOMAIN_AUTHORITY_MATRIX = Object.freeze({
|
|
43
|
+
'odoo-framework-authority': {
|
|
44
|
+
primaryOwner: 'odoo-engineering',
|
|
45
|
+
description: 'Odoo models, ORM, views, release compatibility, and security rules.',
|
|
46
|
+
},
|
|
47
|
+
'focused-coding-discipline': {
|
|
48
|
+
primaryOwner: 'efficient-coding',
|
|
49
|
+
description: 'Proportional implementation, quality-first workflow, and scoped changes.',
|
|
50
|
+
},
|
|
51
|
+
'cross-disciplinary-expertise': {
|
|
52
|
+
primaryOwner: 'afyx-engineering-expert',
|
|
53
|
+
description: 'Multi-disciplinary architecture, system-level trade-offs, and workflow selection.',
|
|
54
|
+
},
|
|
55
|
+
'repository-graph-evidence': {
|
|
56
|
+
primaryOwner: 'afyx-graph',
|
|
57
|
+
description: 'Relational repository structure, dependency graph, and cross-asset impact.',
|
|
58
|
+
},
|
|
59
|
+
'bounded-context-optimization': {
|
|
60
|
+
primaryOwner: 'afyx-context',
|
|
61
|
+
description: 'Bounded context optimization, exact recovery, and fallback token conservation.',
|
|
62
|
+
},
|
|
63
|
+
'codex-usage-telemetry': {
|
|
64
|
+
primaryOwner: 'codex-usage-tracking',
|
|
65
|
+
description: 'Codex-specific session telemetry and local event observation.',
|
|
66
|
+
},
|
|
67
|
+
'adaptive-engineering-policy': {
|
|
68
|
+
primaryOwner: 'afyx-forge',
|
|
69
|
+
description: 'Adaptive engineering execution policy (Gated pending formal A8 acceptance).',
|
|
70
|
+
},
|
|
71
|
+
'skill-authoring-lifecycle': {
|
|
72
|
+
primaryOwner: 'afyx-skill-engineering',
|
|
73
|
+
description: 'Skill authoring, validation, packaging, review and installation.',
|
|
74
|
+
},
|
|
75
|
+
'credential-use-authorization': {
|
|
76
|
+
primaryOwner: 'afyx-credential-broker',
|
|
77
|
+
description: 'Host-scoped credential use authorization without secret disclosure.',
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Capabilities supported by provider surfaces.
|
|
83
|
+
*/
|
|
84
|
+
export const PROVIDER_CAPABILITY_SUPPORT = Object.freeze({
|
|
85
|
+
codex: Object.freeze({
|
|
86
|
+
supportedCapabilities: Object.freeze([
|
|
87
|
+
'repository-graph-evidence',
|
|
88
|
+
'bounded-context-optimization',
|
|
89
|
+
'cross-disciplinary-expertise',
|
|
90
|
+
'odoo-framework-authority',
|
|
91
|
+
'focused-coding-discipline',
|
|
92
|
+
'codex-usage-telemetry',
|
|
93
|
+
]),
|
|
94
|
+
surfaces: Object.freeze({
|
|
95
|
+
'afyx-graph': { surface: 'mcp', serverName: 'afyx_graph' },
|
|
96
|
+
'afyx-context': { surface: 'cli', wrapper: 'afyx-context' },
|
|
97
|
+
'afyx-engineering-expert': { surface: 'instructions', reference: 'skills/afyx-engineering-expert' },
|
|
98
|
+
'odoo-engineering': { surface: 'instructions', reference: 'skills/odoo-engineering' },
|
|
99
|
+
'efficient-coding': { surface: 'instructions', reference: 'skills/efficient-coding' },
|
|
100
|
+
'codex-usage-tracking': { surface: 'telemetry', command: 'afyx-codex-tracker' },
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
103
|
+
antigravity: Object.freeze({
|
|
104
|
+
supportedCapabilities: Object.freeze([
|
|
105
|
+
'repository-graph-evidence',
|
|
106
|
+
'bounded-context-optimization',
|
|
107
|
+
'cross-disciplinary-expertise',
|
|
108
|
+
'odoo-framework-authority',
|
|
109
|
+
'focused-coding-discipline',
|
|
110
|
+
]),
|
|
111
|
+
surfaces: Object.freeze({
|
|
112
|
+
'afyx-graph': { surface: 'mcp', serverName: 'afyx_graph' },
|
|
113
|
+
'afyx-context': { surface: 'instructions', reference: 'skills/afyx-context' },
|
|
114
|
+
'afyx-engineering-expert': { surface: 'skills', skillName: 'afyx-engineering-expert' },
|
|
115
|
+
'odoo-engineering': { surface: 'skills', skillName: 'odoo-engineering' },
|
|
116
|
+
'efficient-coding': { surface: 'skills', skillName: 'efficient-coding' },
|
|
117
|
+
}),
|
|
118
|
+
}),
|
|
119
|
+
claude: Object.freeze({
|
|
120
|
+
supportedCapabilities: Object.freeze([
|
|
121
|
+
'repository-graph-evidence',
|
|
122
|
+
'bounded-context-optimization',
|
|
123
|
+
'cross-disciplinary-expertise',
|
|
124
|
+
'odoo-framework-authority',
|
|
125
|
+
'focused-coding-discipline',
|
|
126
|
+
]),
|
|
127
|
+
surfaces: Object.freeze({
|
|
128
|
+
'afyx-graph': { surface: 'mcp', serverName: 'afyx_graph' },
|
|
129
|
+
'afyx-context': { surface: 'instructions', reference: 'CLAUDE.md' },
|
|
130
|
+
'afyx-engineering-expert': { surface: 'skills', skillName: 'afyx-engineering-expert' },
|
|
131
|
+
'odoo-engineering': { surface: 'skills', skillName: 'odoo-engineering' },
|
|
132
|
+
'efficient-coding': { surface: 'skills', skillName: 'efficient-coding' },
|
|
133
|
+
}),
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Resolves modular runtime capability preparation, enforcing host authorizations,
|
|
139
|
+
* provider mediation, and non-redundant capability execution.
|
|
140
|
+
*
|
|
141
|
+
* @param {Object} options
|
|
142
|
+
* @param {Object} options.task - Engineering task specification
|
|
143
|
+
* @param {string} [options.provider] - Target provider: 'codex', 'antigravity', 'claude', or null/omitted
|
|
144
|
+
* @param {Object} [options.installedComponents] - Installed component states
|
|
145
|
+
* @param {Object} [options.userPreferences] - Explicit user preferences / overrides
|
|
146
|
+
* @param {Object} [options.hostAuthorizations] - Host authorization parameters
|
|
147
|
+
* @param {Array} [options.toolCandidates] - Optional tool candidates for tool family routing
|
|
148
|
+
* @returns {Object} Runtime activation plan
|
|
149
|
+
*/
|
|
150
|
+
export function resolveModularRuntimeActivation(options = {}) {
|
|
151
|
+
const {
|
|
152
|
+
task = {},
|
|
153
|
+
provider = null,
|
|
154
|
+
installedComponents = {},
|
|
155
|
+
userPreferences = {},
|
|
156
|
+
hostAuthorizations = {},
|
|
157
|
+
toolCandidates = null,
|
|
158
|
+
} = options;
|
|
159
|
+
|
|
160
|
+
const taskId = task.id || `task-${Date.now()}`;
|
|
161
|
+
const targetProvider = typeof provider === 'string' ? provider.toLowerCase() : null;
|
|
162
|
+
|
|
163
|
+
// 1. Layer 1 & 2: Deterministic capability planning
|
|
164
|
+
const deterministicPlan = resolveModularCapabilityPlan(task, installedComponents, userPreferences);
|
|
165
|
+
|
|
166
|
+
// 2. Layer 3: Runtime readiness & authorization checks
|
|
167
|
+
const diagnostics = [];
|
|
168
|
+
const degradations = [...deterministicPlan.degradations];
|
|
169
|
+
const suppressedRedundancies = [...deterministicPlan.suppressedRedundancies];
|
|
170
|
+
const preparedCapabilities = [];
|
|
171
|
+
const domainAuthorities = {};
|
|
172
|
+
let runtimeStatus = 'READY';
|
|
173
|
+
|
|
174
|
+
// Unknown Provider Check: Fail closed immediately
|
|
175
|
+
if (targetProvider !== null && !ACCEPTED_PROVIDERS.includes(targetProvider)) {
|
|
176
|
+
runtimeStatus = 'BLOCKED';
|
|
177
|
+
diagnostics.push({
|
|
178
|
+
code: 'UNKNOWN_PROVIDER_REFUSED',
|
|
179
|
+
severity: 'ERROR',
|
|
180
|
+
message: `Target provider '${targetProvider}' is unknown. Supported providers: ${ACCEPTED_PROVIDERS.join(', ')}. Failed closed without mutation or execution.`,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Disabled Provider Check: Fail closed if provider is explicitly unauthorized or disabled by host
|
|
185
|
+
const isProviderDisabled = targetProvider !== null && (
|
|
186
|
+
hostAuthorizations[targetProvider] === false ||
|
|
187
|
+
hostAuthorizations.providers?.[targetProvider] === false ||
|
|
188
|
+
hostAuthorizations.enabledProviders?.[targetProvider] === false
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
if (isProviderDisabled) {
|
|
192
|
+
runtimeStatus = 'BLOCKED';
|
|
193
|
+
diagnostics.push({
|
|
194
|
+
code: 'HOST_NOT_AUTHORIZED',
|
|
195
|
+
severity: 'ERROR',
|
|
196
|
+
message: `Target provider '${targetProvider}' is explicitly disabled or not authorized by the host. Failed closed without mutation or execution.`,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Forge production gating enforcement (A8)
|
|
201
|
+
const isForgeRequested = task.taskType === 'forge-evaluation' ||
|
|
202
|
+
task.requestedComponent === 'afyx-forge' ||
|
|
203
|
+
(typeof task.intent === 'string' && /\bafyx-forge\b/i.test(task.intent));
|
|
204
|
+
|
|
205
|
+
if (isForgeRequested) {
|
|
206
|
+
runtimeStatus = 'BLOCKED';
|
|
207
|
+
diagnostics.push({
|
|
208
|
+
code: 'FORGE_GATED_PENDING_A8',
|
|
209
|
+
severity: 'ERROR',
|
|
210
|
+
message: 'Afyx Forge runtime activation is strictly blocked pending formal A8 acceptance gate.',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Host MCP / CLI bypass safeguard:
|
|
215
|
+
// "Disabled MCP never implies permission to call an external CLI or wrapper."
|
|
216
|
+
const mcpExplicitlyDisabled = hostAuthorizations.mcpEnabled === false;
|
|
217
|
+
const attemptedCliBypass = Boolean(hostAuthorizations.attemptedCliBypass);
|
|
218
|
+
const cliBypassAllowed = Boolean(hostAuthorizations.cliBypassAllowed);
|
|
219
|
+
|
|
220
|
+
if (mcpExplicitlyDisabled && attemptedCliBypass && !cliBypassAllowed) {
|
|
221
|
+
diagnostics.push({
|
|
222
|
+
code: 'CLI_BYPASS_REFUSED',
|
|
223
|
+
severity: 'ERROR',
|
|
224
|
+
message: 'Disabled MCP never implies permission to call an external CLI or wrapper without independent authorization.',
|
|
225
|
+
});
|
|
226
|
+
runtimeStatus = 'BLOCKED';
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Automatic background indexing & freshness safeguard:
|
|
230
|
+
// Missing evidence is treated as UNKNOWN, never implicitly ready.
|
|
231
|
+
// Never automatically trigger background reindexing or daemonic builds.
|
|
232
|
+
if (deterministicPlan.selectedComponents.includes('afyx-graph')) {
|
|
233
|
+
const graphInstalled = installedComponents['afyx-graph'];
|
|
234
|
+
const isFresh = graphInstalled?.indexFresh === true;
|
|
235
|
+
const isReady = graphInstalled?.indexReady === true;
|
|
236
|
+
const isFreshnessUnknown = graphInstalled?.indexFresh === undefined || graphInstalled?.indexReady === undefined;
|
|
237
|
+
|
|
238
|
+
if (!isReady || !isFresh || isFreshnessUnknown) {
|
|
239
|
+
if (hostAuthorizations.allowAutomaticIndexing) {
|
|
240
|
+
// Only if caller explicitly authorized indexing
|
|
241
|
+
diagnostics.push({
|
|
242
|
+
code: 'GRAPH_INDEXING_AUTHORIZED',
|
|
243
|
+
severity: 'INFO',
|
|
244
|
+
message: 'Caller explicitly authorized repository indexing.',
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
const reasonCode = isFreshnessUnknown ? 'INDEX_FRESHNESS_UNKNOWN' : 'INDEX_NOT_READY_OR_STALE';
|
|
248
|
+
degradations.push({
|
|
249
|
+
component: 'afyx-graph',
|
|
250
|
+
fallback: 'DIRECT_SOURCE',
|
|
251
|
+
reason: reasonCode,
|
|
252
|
+
});
|
|
253
|
+
diagnostics.push({
|
|
254
|
+
code: isFreshnessUnknown ? 'GRAPH_FRESHNESS_UNKNOWN' : 'AUTOMATIC_INDEXING_REFUSED',
|
|
255
|
+
severity: 'WARNING',
|
|
256
|
+
message: isFreshnessUnknown
|
|
257
|
+
? 'Graph repository index readiness/freshness evidence is missing or unverified; treated as UNKNOWN. Automatic background indexing refused; falling back to direct source.'
|
|
258
|
+
: 'Graph repository index not ready or stale; automatic background reindexing refused. Falling back to direct source.',
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 3. Layer 4: Provider-mediated capability preparation & surface mapping
|
|
265
|
+
const providerMeta = targetProvider ? PROVIDER_CAPABILITY_SUPPORT[targetProvider] : null;
|
|
266
|
+
|
|
267
|
+
// Only prepare capabilities if provider is valid
|
|
268
|
+
if (runtimeStatus !== 'BLOCKED') {
|
|
269
|
+
for (const componentId of deterministicPlan.selectedComponents) {
|
|
270
|
+
// If component degraded (e.g. Graph due to stale/unknown index), do not prepare for invocation
|
|
271
|
+
const isDegraded = degradations.some((d) => d.component === componentId);
|
|
272
|
+
if (isDegraded) continue;
|
|
273
|
+
|
|
274
|
+
const compInfo = PRODUCT_INVENTORY[componentId];
|
|
275
|
+
if (!compInfo) continue;
|
|
276
|
+
|
|
277
|
+
const primaryCap = compInfo.primaryCapability;
|
|
278
|
+
const authority = DOMAIN_AUTHORITY_MATRIX[primaryCap];
|
|
279
|
+
|
|
280
|
+
if (authority) {
|
|
281
|
+
domainAuthorities[primaryCap] = authority.primaryOwner;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Check provider capability support
|
|
285
|
+
if (providerMeta) {
|
|
286
|
+
const isSupported = providerMeta.supportedCapabilities.includes(primaryCap);
|
|
287
|
+
if (!isSupported) {
|
|
288
|
+
degradations.push({
|
|
289
|
+
component: componentId,
|
|
290
|
+
fallback: 'UNSUPPORTED_ON_PROVIDER',
|
|
291
|
+
reason: `Component ${componentId} capability ${primaryCap} is not supported on provider ${targetProvider}.`,
|
|
292
|
+
});
|
|
293
|
+
diagnostics.push({
|
|
294
|
+
code: 'CAPABILITY_UNSUPPORTED_ON_PROVIDER',
|
|
295
|
+
severity: 'WARNING',
|
|
296
|
+
message: `Provider '${targetProvider}' does not support '${primaryCap}'. Graceful degradation applied.`,
|
|
297
|
+
});
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const surfaceMapping = providerMeta.surfaces[componentId];
|
|
302
|
+
preparedCapabilities.push({
|
|
303
|
+
componentId,
|
|
304
|
+
capability: primaryCap,
|
|
305
|
+
provider: targetProvider,
|
|
306
|
+
surface: surfaceMapping?.surface || 'generic',
|
|
307
|
+
surfaceDetails: surfaceMapping || {},
|
|
308
|
+
ownership: compInfo.ownershipClass,
|
|
309
|
+
lifecycleState: 'PREPARED', // Explicit lifecycle: prepared for session, not claimed live executed
|
|
310
|
+
executionStatus: 'NOT_RUN',
|
|
311
|
+
observationSource: hostAuthorizations.trustedInspection ? 'HOST_INSPECTED' : 'CALLER_DECLARED',
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
// Provider-neutral preparation
|
|
315
|
+
preparedCapabilities.push({
|
|
316
|
+
componentId,
|
|
317
|
+
capability: primaryCap,
|
|
318
|
+
provider: 'neutral',
|
|
319
|
+
surface: compInfo.type === 'runtime' ? 'mcp' : 'skills',
|
|
320
|
+
surfaceDetails: { type: compInfo.type },
|
|
321
|
+
ownership: compInfo.ownershipClass,
|
|
322
|
+
lifecycleState: 'PREPARED',
|
|
323
|
+
executionStatus: 'NOT_RUN',
|
|
324
|
+
observationSource: hostAuthorizations.trustedInspection ? 'HOST_INSPECTED' : 'CALLER_DECLARED',
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 4. Tool Family Routing (Optional caller-provided candidates)
|
|
331
|
+
let toolFamilyRoute = null;
|
|
332
|
+
if (Array.isArray(toolCandidates) && toolCandidates.length > 0) {
|
|
333
|
+
const routeConfig = {
|
|
334
|
+
intent: task.intent === 'exact-source' || userPreferences.forceDirectSource ? 'exact-source' : 'capability',
|
|
335
|
+
capability: task.requiredToolCapability || 'repository-graph-evidence',
|
|
336
|
+
candidates: toolCandidates,
|
|
337
|
+
allowExternalFallback: Boolean(userPreferences.allowExternalFallback),
|
|
338
|
+
};
|
|
339
|
+
try {
|
|
340
|
+
toolFamilyRoute = resolveAfyxToolFamilyRoute(routeConfig);
|
|
341
|
+
} catch (routeError) {
|
|
342
|
+
diagnostics.push({
|
|
343
|
+
code: 'TOOL_FAMILY_ROUTING_ERROR',
|
|
344
|
+
severity: 'WARNING',
|
|
345
|
+
message: routeError instanceof Error ? routeError.message : String(routeError),
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// 5. Final Status Calculation
|
|
351
|
+
if (runtimeStatus !== 'BLOCKED') {
|
|
352
|
+
runtimeStatus = degradations.length > 0 ? 'DEGRADED' : 'READY';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 6. Layer 5: Bounded, Sanitized Runtime Telemetry
|
|
356
|
+
const telemetry = {
|
|
357
|
+
taskId,
|
|
358
|
+
provider: targetProvider || 'neutral',
|
|
359
|
+
plannedCapabilitiesCount: deterministicPlan.selectedComponents.length,
|
|
360
|
+
preparedCapabilitiesCount: preparedCapabilities.length,
|
|
361
|
+
activatedCapabilitiesCount: preparedCapabilities.length, // Retained for compatibility
|
|
362
|
+
suppressedInvocationsCount: suppressedRedundancies.length,
|
|
363
|
+
degradationsCount: degradations.length,
|
|
364
|
+
claimVerification: 'No speculative token savings claimed without measured provider counters.',
|
|
365
|
+
liveExecutionEvidence: false,
|
|
366
|
+
actualTokenSavingsClaimed: false,
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
return Object.freeze({
|
|
370
|
+
contract: AFYX_MODULAR_RUNTIME_CONTRACT,
|
|
371
|
+
taskId,
|
|
372
|
+
provider: targetProvider,
|
|
373
|
+
status: runtimeStatus,
|
|
374
|
+
executionStatus: 'NOT_RUN', // Distinguishes prepared activation plan from actual model invocation
|
|
375
|
+
actualExecutionClaimed: false,
|
|
376
|
+
governingPrinciple: deterministicPlan.governingPrinciple,
|
|
377
|
+
plannedComponents: deterministicPlan.selectedComponents,
|
|
378
|
+
preparedCapabilities: Object.freeze(preparedCapabilities),
|
|
379
|
+
activatedCapabilities: Object.freeze(preparedCapabilities), // Backward-compatible alias with explicit PREPARED state
|
|
380
|
+
domainAuthorities: Object.freeze(domainAuthorities),
|
|
381
|
+
componentStates: deterministicPlan.componentStates,
|
|
382
|
+
suppressedRedundancies: Object.freeze(suppressedRedundancies),
|
|
383
|
+
degradations: Object.freeze(degradations),
|
|
384
|
+
diagnostics: Object.freeze(diagnostics),
|
|
385
|
+
toolFamilyRoute,
|
|
386
|
+
telemetry: Object.freeze(telemetry),
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// -----------------------------------------------------------------------------
|
|
391
|
+
// CLI Runner Entrypoint
|
|
392
|
+
// -----------------------------------------------------------------------------
|
|
393
|
+
|
|
394
|
+
function parseArg(flag, fallback = '') {
|
|
395
|
+
const index = process.argv.indexOf(flag);
|
|
396
|
+
return index >= 0 && index + 1 < process.argv.length ? process.argv[index + 1] : fallback;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function parseJsonArg(flag, fallback = null) {
|
|
400
|
+
const val = parseArg(flag);
|
|
401
|
+
if (!val) return fallback;
|
|
402
|
+
try {
|
|
403
|
+
return JSON.parse(val);
|
|
404
|
+
} catch {
|
|
405
|
+
try {
|
|
406
|
+
// Handle Windows shell escaped quotes (e.g. {\"key\":\"val\"})
|
|
407
|
+
const cleaned = val.replace(/\\"/g, '"');
|
|
408
|
+
return JSON.parse(cleaned);
|
|
409
|
+
} catch {
|
|
410
|
+
return fallback;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function parseJsonFileOrArg(jsonFlag, fileFlag, fallback = null) {
|
|
416
|
+
const fileVal = parseArg(fileFlag);
|
|
417
|
+
if (fileVal && existsSync(fileVal)) {
|
|
418
|
+
try {
|
|
419
|
+
return JSON.parse(readFileSync(fileVal, 'utf8'));
|
|
420
|
+
} catch (e) {
|
|
421
|
+
console.error(`[afyx-modular-runtime] Failed to read ${fileFlag}: ${e.message}`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return parseJsonArg(jsonFlag, fallback);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
|
|
428
|
+
const task = parseJsonFileOrArg('--task-json', '--task-file', {}) || {};
|
|
429
|
+
const provider = parseArg('--provider', 'codex');
|
|
430
|
+
const installedComponents = parseJsonFileOrArg('--installed-json', '--installed-file', {}) || {};
|
|
431
|
+
const userPreferences = parseJsonFileOrArg('--user-prefs-json', '--user-prefs-file', {}) || {};
|
|
432
|
+
const hostAuthorizations = parseJsonFileOrArg('--host-auth-json', '--host-auth-file', {}) || {};
|
|
433
|
+
const toolCandidates = parseJsonFileOrArg('--tool-candidates-json', '--tool-candidates-file', null);
|
|
434
|
+
|
|
435
|
+
const activation = resolveModularRuntimeActivation({
|
|
436
|
+
task,
|
|
437
|
+
provider,
|
|
438
|
+
installedComponents,
|
|
439
|
+
userPreferences,
|
|
440
|
+
hostAuthorizations,
|
|
441
|
+
toolCandidates,
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
console.log(JSON.stringify(activation, null, 2));
|
|
445
|
+
|
|
446
|
+
if (activation.status === 'BLOCKED') {
|
|
447
|
+
process.exit(2);
|
|
448
|
+
} else {
|
|
449
|
+
process.exit(0);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AFYX native skill capability for a trusted, in-process provider host.
|
|
3
|
+
* An agent task can SELECT this adapter but cannot define its write plan,
|
|
4
|
+
* choose the target root, or grant host approval.
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { existsSync, lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
8
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
|
+
import {
|
|
10
|
+
createSkill, packageSkill, previewSkillInstall, applySkillInstall,
|
|
11
|
+
verifySkillInstall, negotiateSkillProvider,
|
|
12
|
+
} from './afyx-skill-engineering.mjs';
|
|
13
|
+
|
|
14
|
+
export const AFYX_NATIVE_SKILL_HOST_CONTRACT = 'AfyxNativeSkillHost/v1';
|
|
15
|
+
const CAPABILITY = 'skill-authoring-lifecycle';
|
|
16
|
+
const NAME = /^[a-z][a-z0-9-]{1,63}$/;
|
|
17
|
+
const claimedHostPlans = new WeakSet();
|
|
18
|
+
|
|
19
|
+
const digest = (value) => createHash('sha256').update(value).digest('hex');
|
|
20
|
+
const beneath = (parent, child) => {
|
|
21
|
+
const rest = relative(parent, child);
|
|
22
|
+
return rest === '' || (rest !== '..' && !rest.startsWith('..' + sep) && !isAbsolute(rest));
|
|
23
|
+
};
|
|
24
|
+
const denied = (reason) => ({ status: 'FAILED', reason, output: null });
|
|
25
|
+
|
|
26
|
+
function trustedRoot(path) {
|
|
27
|
+
if (typeof path !== 'string' || !isAbsolute(path) || !existsSync(path)) {
|
|
28
|
+
throw new Error('TRUSTED_ROOT_REQUIRED');
|
|
29
|
+
}
|
|
30
|
+
const root = resolve(path);
|
|
31
|
+
const stat = lstatSync(root);
|
|
32
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || realpathSync(root) !== root) {
|
|
33
|
+
throw new Error('TRUSTED_ROOT_UNSAFE');
|
|
34
|
+
}
|
|
35
|
+
return root;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The host supplies every option directly from trusted application state.
|
|
40
|
+
* Never pass task JSON or MCP tool arguments into this factory.
|
|
41
|
+
* Approval is synchronous because the underlying atomic install API is synchronous.
|
|
42
|
+
*/
|
|
43
|
+
export function createNativeSkillHostAdapter(config = {}) {
|
|
44
|
+
const { provider, scope = 'workspace', draftsRoot, skillsRoot, spec,
|
|
45
|
+
peerRoots = [], authorize } = config;
|
|
46
|
+
if (negotiateSkillProvider(provider, scope).status !== 'SUPPORTED'
|
|
47
|
+
|| typeof authorize !== 'function'
|
|
48
|
+
|| !spec || typeof spec !== 'object' || typeof spec.name !== 'string' || !NAME.test(spec.name)
|
|
49
|
+
|| typeof spec.description !== 'string'
|
|
50
|
+
|| typeof spec.body !== 'string'
|
|
51
|
+
|| !Array.isArray(spec.triggers)
|
|
52
|
+
|| spec.triggers.some((trigger) => typeof trigger !== 'string')
|
|
53
|
+
|| !Array.isArray(peerRoots)) {
|
|
54
|
+
throw new Error('TRUSTED_SKILL_HOST_CONFIG_INVALID');
|
|
55
|
+
}
|
|
56
|
+
const draftRoot = trustedRoot(draftsRoot);
|
|
57
|
+
const installRoot = trustedRoot(skillsRoot);
|
|
58
|
+
if (beneath(draftRoot, installRoot) || beneath(installRoot, draftRoot)) {
|
|
59
|
+
throw new Error('TRUSTED_SKILL_ROOTS_OVERLAP');
|
|
60
|
+
}
|
|
61
|
+
const peers = Object.freeze(peerRoots.map(trustedRoot));
|
|
62
|
+
const skillSpec = Object.freeze({
|
|
63
|
+
name: spec.name, description: spec.description,
|
|
64
|
+
triggers: Object.freeze([...spec.triggers]), body: spec.body,
|
|
65
|
+
});
|
|
66
|
+
const planDigest = digest(JSON.stringify(skillSpec));
|
|
67
|
+
const sourceIdentity = 'sha256:' + digest(Buffer.concat([
|
|
68
|
+
readFileSync(new URL(import.meta.url)),
|
|
69
|
+
readFileSync(new URL('./afyx-skill-engineering.mjs', import.meta.url)),
|
|
70
|
+
]));
|
|
71
|
+
let consumed = false;
|
|
72
|
+
|
|
73
|
+
const adapter = async (request) => {
|
|
74
|
+
if (request?.targetComponentId !== 'afyx-skill-engineering'
|
|
75
|
+
|| request.capability !== CAPABILITY
|
|
76
|
+
|| request.permissions?.authorized !== true
|
|
77
|
+
|| !Array.isArray(request.candidateProviders)
|
|
78
|
+
|| !request.candidateProviders.includes(provider)
|
|
79
|
+
|| request.sourceIdentity !== sourceIdentity) {
|
|
80
|
+
return denied('TRUSTED_HOST_REQUEST_DENIED');
|
|
81
|
+
}
|
|
82
|
+
// One approved plan may be executed only once per host adapter instance.
|
|
83
|
+
// Consume before touching disk, including denied and failed attempts.
|
|
84
|
+
if (consumed || claimedHostPlans.has(config)) return denied('TRUSTED_SKILL_PLAN_CONSUMED');
|
|
85
|
+
consumed = true;
|
|
86
|
+
claimedHostPlans.add(config);
|
|
87
|
+
|
|
88
|
+
const proposal = Object.freeze({
|
|
89
|
+
contract: AFYX_NATIVE_SKILL_HOST_CONTRACT,
|
|
90
|
+
action: 'CREATE_DRAFT',
|
|
91
|
+
provider, scope, skillName: skillSpec.name, planDigest,
|
|
92
|
+
draftsRoot: draftRoot, skillsRoot: installRoot,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
if (authorize(proposal) !== true) return denied('HOST_APPROVAL_REQUIRED');
|
|
96
|
+
const draft = join(draftRoot, skillSpec.name);
|
|
97
|
+
createSkill(draft, skillSpec);
|
|
98
|
+
const packageBytes = packageSkill(draft);
|
|
99
|
+
const preview = previewSkillInstall(packageBytes, {
|
|
100
|
+
provider, scope, skillsRoot: installRoot, peerRoots: peers,
|
|
101
|
+
});
|
|
102
|
+
if (preview.action !== 'INSTALL') return denied('EXISTING_SKILL_PROTECTED');
|
|
103
|
+
// A separate trusted host authorization is required for the exact install preview.
|
|
104
|
+
const installed = applySkillInstall(packageBytes, preview, { authorize });
|
|
105
|
+
const verification = verifySkillInstall({ provider, skillsRoot: installRoot, name: skillSpec.name });
|
|
106
|
+
if (installed.status !== 'VERIFIED' || verification.status !== 'VERIFIED') {
|
|
107
|
+
return denied('NATIVE_SKILL_INSTALL_UNVERIFIED');
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
status: 'SUCCESS',
|
|
111
|
+
output: Object.freeze({
|
|
112
|
+
contract: AFYX_NATIVE_SKILL_HOST_CONTRACT,
|
|
113
|
+
provider, scope, name: skillSpec.name,
|
|
114
|
+
digest: verification.digest, status: 'VERIFIED',
|
|
115
|
+
}),
|
|
116
|
+
evidence: Object.freeze([{ kind: 'native-skill-verified', digest: verification.digest }]),
|
|
117
|
+
};
|
|
118
|
+
} catch {
|
|
119
|
+
// Never return OS paths, proposal bodies, adapter errors or credential-like data.
|
|
120
|
+
return denied('NATIVE_SKILL_HOST_OPERATION_FAILED');
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return Object.freeze({ sourceIdentity, adapter });
|
|
124
|
+
}
|