afyx-engineering-kit 0.0.0-stage → 0.1.0-alpha.3
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,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Safe global routing instructions for registered providers. No provider or model invocation. */
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, closeSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { TextDecoder } from 'node:util';
|
|
9
|
+
|
|
10
|
+
const registry = JSON.parse(readFileSync(fileURLToPath(new URL('./components.json', import.meta.url)), 'utf8'));
|
|
11
|
+
const SUPPORTED = Object.freeze(registry.providers.map(p => p.provider));
|
|
12
|
+
const DEFAULT_POLICY = fileURLToPath(new URL('./afyx-global-routing-policy.md', import.meta.url));
|
|
13
|
+
const START = '<!-- AFYX-ADAPTIVE-ROUTING:START v1 -->';
|
|
14
|
+
const END = '<!-- AFYX-ADAPTIVE-ROUTING:END v1 -->';
|
|
15
|
+
const LEGACY_NAME = ['code', 'graph'].join('');
|
|
16
|
+
const sha = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
17
|
+
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
18
|
+
|
|
19
|
+
function safeTarget(root, file) {
|
|
20
|
+
if (dirname(file) !== root) throw Error('PATH_OUTSIDE_PROVIDER_ROOT');
|
|
21
|
+
let cursor = file;
|
|
22
|
+
for (;;) {
|
|
23
|
+
if (existsSync(cursor) && lstatSync(cursor).isSymbolicLink()) throw Error('SYMLINK_OR_REPARSE_BLOCKED');
|
|
24
|
+
// The provider root is the caller-authorized boundary. macOS may have
|
|
25
|
+
// legitimate system symlinks above it (e.g. /var -> /private/var).
|
|
26
|
+
if (cursor === root) break;
|
|
27
|
+
const parent = dirname(cursor);
|
|
28
|
+
if (parent === cursor) throw Error('PATH_OUTSIDE_PROVIDER_ROOT');
|
|
29
|
+
cursor = parent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function providerTargets({home = homedir(), codexHome, geminiHome, claudeHome} = {}) {
|
|
33
|
+
function rooted(value, fallback) {
|
|
34
|
+
const path = value ?? fallback;
|
|
35
|
+
if (typeof path !== 'string' || !isAbsolute(path)) throw Error('GLOBAL_ROOT_MUST_BE_ABSOLUTE');
|
|
36
|
+
return resolve(path);
|
|
37
|
+
}
|
|
38
|
+
const base = rooted(home, homedir());
|
|
39
|
+
const codex = rooted(codexHome ?? process.env.CODEX_HOME, join(base, '.codex'));
|
|
40
|
+
const gemini = rooted(geminiHome, join(base, '.gemini'));
|
|
41
|
+
const claude = rooted(claudeHome ?? process.env.CLAUDE_CONFIG_DIR, join(base, '.claude'));
|
|
42
|
+
const override = join(codex, 'AGENTS.override.md');
|
|
43
|
+
safeTarget(codex, override);
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
codex: {root: codex, file: existsSync(override) && readFileSync(override).length ? override : join(codex, 'AGENTS.md')},
|
|
46
|
+
antigravity: {root: gemini, file: join(gemini, 'GEMINI.md')},
|
|
47
|
+
claude: {root: claude, file: join(claude, 'CLAUDE.md')},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function inspectFile(file, policy) {
|
|
51
|
+
const bytes = existsSync(file) ? readFileSync(file) : null;
|
|
52
|
+
let data = '';
|
|
53
|
+
if (bytes !== null) {
|
|
54
|
+
try { data = decoder.decode(bytes); }
|
|
55
|
+
catch { return {status:'BLOCKED_ENCODING', bytes, data:''}; }
|
|
56
|
+
}
|
|
57
|
+
const start = data.indexOf(START), end = data.indexOf(END);
|
|
58
|
+
if ((start < 0) !== (end < 0) ||
|
|
59
|
+
(start >= 0 && (start > end || data.lastIndexOf(START) !== start || data.lastIndexOf(END) !== end))) {
|
|
60
|
+
return {status:'BLOCKED_MARKER', bytes, data};
|
|
61
|
+
}
|
|
62
|
+
const owned = start >= 0;
|
|
63
|
+
const outside = owned ? data.slice(0,start) + data.slice(end + END.length) : data;
|
|
64
|
+
const legacy = new RegExp('\\b' + LEGACY_NAME + '\\b','iu');
|
|
65
|
+
const conflictLines = outside.split(/\r?\n/u)
|
|
66
|
+
.flatMap((line, n) => legacy.test(line) &&
|
|
67
|
+
/\b(must|always|before|first|prefer|required|mandatory|wajib|harus|priorit)/iu.test(line)
|
|
68
|
+
? [n+1] : []);
|
|
69
|
+
if (conflictLines.length) return {status:'BLOCKED_CONFLICT', bytes, data, conflictLines};
|
|
70
|
+
const wanted = START + '\n' + policy.trim() + '\n' + END;
|
|
71
|
+
if (!owned) return {status:bytes === null ? 'MISSING' : 'UNMANAGED', bytes, data, wanted};
|
|
72
|
+
const current = data.slice(start,end+END.length);
|
|
73
|
+
return {status:current.replace(/\r\n/gu,'\n') === wanted ? 'IN_SYNC' : 'DRIFTED_OWNED',
|
|
74
|
+
bytes, data, wanted, start, end};
|
|
75
|
+
}
|
|
76
|
+
function writeBlock(item) {
|
|
77
|
+
const eol = item.data.includes('\r\n') ? '\r\n' : '\n';
|
|
78
|
+
const wanted = item.wanted.replace(/\n/gu,eol);
|
|
79
|
+
if (item.start !== undefined) {
|
|
80
|
+
return Buffer.from(item.data.slice(0,item.start)+wanted+item.data.slice(item.end+END.length),'utf8');
|
|
81
|
+
}
|
|
82
|
+
return Buffer.from(item.data + (item.data && !item.data.endsWith('\n') ? eol : '') + wanted + eol,'utf8');
|
|
83
|
+
}
|
|
84
|
+
function removeBlock(item) {
|
|
85
|
+
if (item.start === undefined) throw Error('OWNED_BLOCK_NOT_FOUND');
|
|
86
|
+
const prefix = item.data.slice(0,item.start);
|
|
87
|
+
const suffix = item.data.slice(item.end+END.length);
|
|
88
|
+
return Buffer.from(prefix + suffix.replace(/^\r?\n/u,''),'utf8');
|
|
89
|
+
}
|
|
90
|
+
function backupOriginal(root, file, before) {
|
|
91
|
+
if (before === null) return;
|
|
92
|
+
const dir = join(root,'.afyx-global-routing-backups');
|
|
93
|
+
safeTarget(root,dir);
|
|
94
|
+
mkdirSync(dir,{recursive:true,mode:0o700});
|
|
95
|
+
if(lstatSync(dir).isSymbolicLink()) throw Error('UNSAFE_BACKUP_DIRECTORY');
|
|
96
|
+
const path = join(dir,basename(file)+'.'+sha(before)+'.'+Date.now()+'.bak');
|
|
97
|
+
let fd;
|
|
98
|
+
try { fd = openSync(path,'wx',0o600); writeFileSync(fd,before); }
|
|
99
|
+
finally { if(fd!==undefined) closeSync(fd); }
|
|
100
|
+
}
|
|
101
|
+
function atomicWrite(file, bytes) {
|
|
102
|
+
mkdirSync(dirname(file),{recursive:true});
|
|
103
|
+
const temp = file+'.afyx-'+process.pid+'-'+Date.now()+'.tmp';
|
|
104
|
+
try { writeFileSync(temp,bytes,{flag:'wx',mode:0o600}); renameSync(temp,file); }
|
|
105
|
+
finally { rmSync(temp,{force:true}); }
|
|
106
|
+
}
|
|
107
|
+
export function runGlobalRouting({operation='plan',providers=SUPPORTED,
|
|
108
|
+
policyFile=DEFAULT_POLICY,roots={},apply=false} = {}) {
|
|
109
|
+
if(!['plan','apply','verify','uninstall'].includes(operation)) throw Error('INVALID_OPERATION');
|
|
110
|
+
if(!Array.isArray(providers) || !providers.length ||
|
|
111
|
+
providers.some(p=>!SUPPORTED.includes(p))) throw Error('UNSUPPORTED_PROVIDER');
|
|
112
|
+
if((operation==='apply'||operation==='uninstall')&&!apply) throw Error('EXPLICIT_APPLY_REQUIRED');
|
|
113
|
+
const targets = providerTargets(roots);
|
|
114
|
+
const policy = readFileSync(policyFile,'utf8').replace(/\r\n/gu,'\n');
|
|
115
|
+
if (!policy.includes('Afyx adaptive tool routing') || policy.trim().length<100) throw Error('INVALID_POLICY');
|
|
116
|
+
const inspected = [...new Set(providers)].map(provider => {
|
|
117
|
+
const target=targets[provider];
|
|
118
|
+
if(!target) throw Error('PROVIDER_TARGET_UNSUPPORTED');
|
|
119
|
+
safeTarget(target.root,target.file);
|
|
120
|
+
return {provider,...target,...inspectFile(target.file,policy)};
|
|
121
|
+
});
|
|
122
|
+
const summary = inspected.map(({provider,file,status,conflictLines}) =>
|
|
123
|
+
({provider,path:file,status,conflictLines:conflictLines??[]}));
|
|
124
|
+
const blocked=inspected.some(i=>i.status.startsWith('BLOCKED'));
|
|
125
|
+
if(blocked) return {status:'BLOCKED',changed:false,providers:summary};
|
|
126
|
+
if(operation==='plan'||operation==='verify') return {status:'READ_ONLY',changed:false,providers:summary};
|
|
127
|
+
const changed=[];
|
|
128
|
+
try {
|
|
129
|
+
for(const item of inspected) {
|
|
130
|
+
if(operation==='apply' && item.status==='IN_SYNC') continue;
|
|
131
|
+
if(operation==='uninstall' && !['IN_SYNC','DRIFTED_OWNED'].includes(item.status)) continue;
|
|
132
|
+
if(operation==='apply' && !['MISSING','UNMANAGED','DRIFTED_OWNED'].includes(item.status)) throw Error('UNSAFE_STATE');
|
|
133
|
+
if(item.bytes!==null && sha(readFileSync(item.file))!==sha(item.bytes)) throw Error('CONCURRENT_OWNER_EDIT');
|
|
134
|
+
const next = operation==='apply'?writeBlock(item):removeBlock(item);
|
|
135
|
+
if(item.bytes!==null && sha(next)===sha(item.bytes)) continue;
|
|
136
|
+
backupOriginal(item.root,item.file,item.bytes);
|
|
137
|
+
atomicWrite(item.file,next);
|
|
138
|
+
changed.push({file:item.file,before:item.bytes,after:sha(next)});
|
|
139
|
+
}
|
|
140
|
+
} catch(error) {
|
|
141
|
+
let recovered=true;
|
|
142
|
+
for(const item of changed.reverse()) {
|
|
143
|
+
try {
|
|
144
|
+
if(sha(readFileSync(item.file))!==item.after){recovered=false;continue;}
|
|
145
|
+
if(item.before===null)rmSync(item.file,{force:true});
|
|
146
|
+
else atomicWrite(item.file,item.before);
|
|
147
|
+
} catch { recovered=false; }
|
|
148
|
+
}
|
|
149
|
+
return {status:recovered?'ROLLED_BACK':'ROLLBACK_INCOMPLETE',changed:!recovered,
|
|
150
|
+
reason:String(error.message),providers:summary};
|
|
151
|
+
}
|
|
152
|
+
return {status:'APPLIED',changed:changed.length>0,
|
|
153
|
+
providers:summary.map(v=>({...v,postState:operation==='apply'?'IN_SYNC':'UNMANAGED_OR_ABSENT'}))};
|
|
154
|
+
}
|
|
155
|
+
function argument(name){const i=process.argv.indexOf(name);return i>=0?process.argv[i+1]:undefined;}
|
|
156
|
+
if(process.argv[1] && resolve(process.argv[1])===fileURLToPath(import.meta.url)){
|
|
157
|
+
try{
|
|
158
|
+
const operation=process.argv.includes('--uninstall')?'uninstall':
|
|
159
|
+
process.argv.includes('--verify')?'verify':process.argv.includes('--apply')?'apply':'plan';
|
|
160
|
+
const raw=argument('--providers');
|
|
161
|
+
const providers=raw?raw.split(',').map(s=>s.trim()):SUPPORTED;
|
|
162
|
+
const result=runGlobalRouting({operation,apply:process.argv.includes('--apply'),providers,
|
|
163
|
+
roots:{codexHome:argument('--codex-home'),geminiHome:argument('--gemini-home'),
|
|
164
|
+
claudeHome:argument('--claude-home')}});
|
|
165
|
+
console.log(JSON.stringify(result,null,2));
|
|
166
|
+
if(['BLOCKED','ROLLED_BACK','ROLLBACK_INCOMPLETE'].includes(result.status))process.exitCode=2;
|
|
167
|
+
}catch(error){console.error(JSON.stringify({status:'BLOCKED',reason:error.message}));process.exitCode=2;}
|
|
168
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Canonical Afyx Graph artifact identity shared by Windows and POSIX lifecycle scripts. */
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
|
5
|
+
import { basename, join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const UNKNOWN = 'UNKNOWN';
|
|
9
|
+
|
|
10
|
+
function argument(name, fallback = '') {
|
|
11
|
+
const index = process.argv.indexOf(name);
|
|
12
|
+
return index >= 0 ? process.argv[index + 1] : fallback;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function revision(value) {
|
|
16
|
+
const normalized = String(value || '').trim().toLowerCase();
|
|
17
|
+
return /^[0-9a-f]{7,64}$/.test(normalized) ? normalized : UNKNOWN;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function integer(value) {
|
|
21
|
+
const parsed = Number.parseInt(String(value ?? ''), 10);
|
|
22
|
+
return Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function readMetadata(file) {
|
|
26
|
+
return JSON.parse(readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function writeMetadata(file, metadata) {
|
|
30
|
+
writeFileSync(file, `${JSON.stringify(metadata, null, 2)}\n`, 'utf8');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function artifactIdentity(metadata) {
|
|
34
|
+
return {
|
|
35
|
+
schema: integer(metadata.artifact_identity_schema),
|
|
36
|
+
productVersion: String(metadata.product_version || ''),
|
|
37
|
+
releaseChannel: String(metadata.release_channel || ''),
|
|
38
|
+
target: String(metadata.artifact_target || UNKNOWN),
|
|
39
|
+
sourceRevision: revision(metadata.source_revision),
|
|
40
|
+
buildIdentity: String(metadata.build_identity || UNKNOWN),
|
|
41
|
+
extractionVersion: integer(metadata.extraction_version),
|
|
42
|
+
provenance: String(metadata.artifact_provenance || UNKNOWN),
|
|
43
|
+
archiveSha256: /^[0-9a-f]{64}$/i.test(String(metadata.archive_sha256 || ''))
|
|
44
|
+
? String(metadata.archive_sha256).toLowerCase()
|
|
45
|
+
: UNKNOWN,
|
|
46
|
+
requestedCheckoutRevision: revision(metadata.requested_checkout_revision),
|
|
47
|
+
releaseManifestStatus: String(metadata.release_manifest_status || 'MISSING'),
|
|
48
|
+
publisherAuthenticity: String(metadata.publisher_authenticity || 'UNVERIFIED'),
|
|
49
|
+
buildProvenance: String(metadata.build_provenance || 'UNVERIFIED'),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function stampArtifact(metadata, fields) {
|
|
54
|
+
const sourceRevision = revision(fields.revision);
|
|
55
|
+
return {
|
|
56
|
+
...metadata,
|
|
57
|
+
artifact_identity_schema: 1,
|
|
58
|
+
artifact_target: fields.target,
|
|
59
|
+
source_revision: sourceRevision,
|
|
60
|
+
build_identity: sourceRevision === UNKNOWN ? UNKNOWN : `git:${sourceRevision}`,
|
|
61
|
+
extraction_version: integer(fields.extractionVersion),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function revisionStatus(identity, requested) {
|
|
66
|
+
const wanted = revision(requested);
|
|
67
|
+
if (wanted === UNKNOWN || identity.sourceRevision === UNKNOWN) return 'UNKNOWN';
|
|
68
|
+
return identity.sourceRevision === wanted ? 'MATCH' : 'REVISION_MISMATCH';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function sha256(file) {
|
|
72
|
+
return createHash('sha256').update(readFileSync(file)).digest('hex');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function requireValue(value, name) {
|
|
76
|
+
if (!value) throw new Error(`${name} is required`);
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function releaseManifest(directory, fields) {
|
|
81
|
+
const sourceRevision = revision(fields.revision);
|
|
82
|
+
if (sourceRevision === UNKNOWN) throw new Error('--revision must be a Git commit');
|
|
83
|
+
const artifacts = readdirSync(directory)
|
|
84
|
+
.filter((name) => /^afyx-graph-(?:win32|linux|darwin)-(?:x64|arm64)\.(?:zip|tar\.gz)$/.test(name))
|
|
85
|
+
.sort()
|
|
86
|
+
.map((name) => ({
|
|
87
|
+
file: name,
|
|
88
|
+
target: name.match(/^afyx-graph-(.+?)\.(?:zip|tar\.gz)$/)[1],
|
|
89
|
+
sha256: sha256(join(directory, name)),
|
|
90
|
+
}));
|
|
91
|
+
if (artifacts.length === 0) throw new Error('release directory has no Afyx Graph archives');
|
|
92
|
+
return {
|
|
93
|
+
schema: 1,
|
|
94
|
+
product: 'Afyx Graph',
|
|
95
|
+
product_version: requireValue(fields.version, '--version'),
|
|
96
|
+
release_tag: requireValue(fields.tag, '--tag'),
|
|
97
|
+
source_revision: sourceRevision,
|
|
98
|
+
integrity_claim: 'sha256',
|
|
99
|
+
publisher_authenticity: 'requires-independent-attestation',
|
|
100
|
+
artifacts,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function verifyReleaseManifest(manifestFile, archiveFile, metadataFile) {
|
|
105
|
+
const manifest = readMetadata(manifestFile);
|
|
106
|
+
const metadata = readMetadata(metadataFile);
|
|
107
|
+
const identity = artifactIdentity(metadata);
|
|
108
|
+
if (manifest.schema !== 1 || manifest.product !== 'Afyx Graph') throw new Error('release manifest schema or product mismatch');
|
|
109
|
+
const name = basename(archiveFile);
|
|
110
|
+
const entry = Array.isArray(manifest.artifacts) ? manifest.artifacts.find((item) => item.file === name) : null;
|
|
111
|
+
if (!entry || !/^[0-9a-f]{64}$/i.test(String(entry.sha256 || ''))) throw new Error(`release manifest has no valid entry for ${name}`);
|
|
112
|
+
if (sha256(archiveFile) !== String(entry.sha256).toLowerCase()) throw new Error('release manifest archive digest mismatch');
|
|
113
|
+
if (entry.target !== identity.target) throw new Error('release manifest target does not match artifact metadata');
|
|
114
|
+
if (revision(manifest.source_revision) === UNKNOWN || revision(manifest.source_revision) !== identity.sourceRevision) throw new Error('release manifest revision does not match artifact metadata');
|
|
115
|
+
if (String(manifest.product_version || '') !== identity.productVersion) throw new Error('release manifest version does not match artifact metadata');
|
|
116
|
+
return { status: 'VERIFIED', sourceRevision: identity.sourceRevision, target: identity.target, archiveSha256: entry.sha256 };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
120
|
+
try {
|
|
121
|
+
const command = process.argv[2];
|
|
122
|
+
const file = argument('--metadata');
|
|
123
|
+
if (command === 'create-release-manifest') {
|
|
124
|
+
const directory = requireValue(argument('--directory'), '--directory');
|
|
125
|
+
const output = requireValue(argument('--output'), '--output');
|
|
126
|
+
const manifest = releaseManifest(directory, {
|
|
127
|
+
revision: argument('--revision'), version: argument('--version'), tag: argument('--tag'),
|
|
128
|
+
});
|
|
129
|
+
writeMetadata(output, manifest);
|
|
130
|
+
console.log(JSON.stringify(manifest));
|
|
131
|
+
} else if (command === 'verify-release-manifest') {
|
|
132
|
+
console.log(JSON.stringify(verifyReleaseManifest(
|
|
133
|
+
requireValue(argument('--manifest'), '--manifest'),
|
|
134
|
+
requireValue(argument('--archive'), '--archive'),
|
|
135
|
+
requireValue(file, '--metadata'),
|
|
136
|
+
)));
|
|
137
|
+
} else if (command === 'stamp') {
|
|
138
|
+
const stamped = stampArtifact(readMetadata(file), {
|
|
139
|
+
target: requireValue(argument('--target'), '--target'),
|
|
140
|
+
revision: argument('--revision', UNKNOWN),
|
|
141
|
+
extractionVersion: requireValue(argument('--extraction-version'), '--extraction-version'),
|
|
142
|
+
});
|
|
143
|
+
writeMetadata(file, stamped);
|
|
144
|
+
console.log(JSON.stringify(artifactIdentity(stamped)));
|
|
145
|
+
} else if (command === 'inspect') {
|
|
146
|
+
const identity = artifactIdentity(readMetadata(file));
|
|
147
|
+
const requested = argument('--requested-revision', UNKNOWN);
|
|
148
|
+
console.log(JSON.stringify({ ...identity, revisionStatus: revisionStatus(identity, requested) }));
|
|
149
|
+
} else if (command === 'require-revision') {
|
|
150
|
+
const identity = artifactIdentity(readMetadata(file));
|
|
151
|
+
const requested = requireValue(argument('--requested-revision'), '--requested-revision');
|
|
152
|
+
const status = revisionStatus(identity, requested);
|
|
153
|
+
console.log(JSON.stringify({ ...identity, revisionStatus: status }));
|
|
154
|
+
if (status !== 'MATCH') process.exitCode = status === 'REVISION_MISMATCH' ? 3 : 4;
|
|
155
|
+
} else if (command === 'record-install') {
|
|
156
|
+
const metadata = readMetadata(file);
|
|
157
|
+
const archive = requireValue(argument('--archive'), '--archive');
|
|
158
|
+
const requested = argument('--requested-revision', UNKNOWN);
|
|
159
|
+
const updated = {
|
|
160
|
+
...metadata,
|
|
161
|
+
artifact_provenance: requireValue(argument('--provenance'), '--provenance'),
|
|
162
|
+
archive_sha256: sha256(archive),
|
|
163
|
+
requested_checkout_revision: revision(requested),
|
|
164
|
+
revision_status: revisionStatus(artifactIdentity(metadata), requested),
|
|
165
|
+
release_manifest_status: argument('--release-manifest-status', 'MISSING'),
|
|
166
|
+
publisher_authenticity: argument('--publisher-authenticity', 'UNVERIFIED'),
|
|
167
|
+
build_provenance: argument('--build-provenance', 'UNVERIFIED'),
|
|
168
|
+
};
|
|
169
|
+
writeMetadata(file, updated);
|
|
170
|
+
console.log(JSON.stringify(artifactIdentity(updated)));
|
|
171
|
+
} else {
|
|
172
|
+
throw new Error('usage: afyx-graph-artifact.mjs create-release-manifest|verify-release-manifest|stamp|inspect|require-revision|record-install [options]');
|
|
173
|
+
}
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error(`[artifact] ${error instanceof Error ? error.message : String(error)}`);
|
|
176
|
+
process.exitCode = 1;
|
|
177
|
+
}
|
|
178
|
+
}
|