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,349 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import {
|
|
5
|
+
copyFileSync,
|
|
6
|
+
cpSync,
|
|
7
|
+
existsSync,
|
|
8
|
+
lstatSync,
|
|
9
|
+
mkdirSync,
|
|
10
|
+
mkdtempSync,
|
|
11
|
+
readFileSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
} from 'node:fs';
|
|
15
|
+
import { dirname, join, resolve } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { tmpdir } from 'node:os';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
artifactPlan,
|
|
21
|
+
DISTRIBUTION_PRODUCT,
|
|
22
|
+
verifyBundle,
|
|
23
|
+
} from '../afyx-graph/engine/scripts/distribution-contract.mjs';
|
|
24
|
+
import { verifyReleaseReady } from '../afyx-graph/engine/scripts/release-readiness.mjs';
|
|
25
|
+
import { createDeterministicArchive } from '../afyx-graph/engine/scripts/deterministic-archive.mjs';
|
|
26
|
+
import { stampArtifact } from './afyx-graph-artifact.mjs';
|
|
27
|
+
import { resolveAndStageGitReleaseArtifacts } from './resolve-git-release-artifacts.mjs';
|
|
28
|
+
|
|
29
|
+
const expected = new Map([
|
|
30
|
+
['afyx-graph-win32-x64.zip', 'win32-x64'],
|
|
31
|
+
['afyx-graph-linux-x64.tar.gz', 'linux-x64'],
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export function buildGraphBundle({ root, target, revision, outputDir }) {
|
|
35
|
+
const engineRoot = join(root, 'afyx-graph', 'engine');
|
|
36
|
+
const plan = artifactPlan(target);
|
|
37
|
+
const bundleName = plan.bundleName;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
verifyReleaseReady(engineRoot);
|
|
41
|
+
} catch {
|
|
42
|
+
const tscPath = join(engineRoot, 'node_modules', 'typescript', 'bin', 'tsc');
|
|
43
|
+
if (!existsSync(tscPath)) {
|
|
44
|
+
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
45
|
+
execFileSync(npmCmd, ['ci'], {
|
|
46
|
+
cwd: engineRoot,
|
|
47
|
+
stdio: 'inherit',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
execFileSync(process.execPath, [join(engineRoot, 'scripts', 'build-release.mjs')], {
|
|
51
|
+
cwd: engineRoot,
|
|
52
|
+
stdio: 'inherit',
|
|
53
|
+
});
|
|
54
|
+
verifyReleaseReady(engineRoot);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const tmpRoot = mkdtempSync(join(tmpdir(), 'afyx-graph-bundle-'));
|
|
58
|
+
const stage = join(tmpRoot, bundleName);
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
mkdirSync(join(stage, 'lib'), { recursive: true });
|
|
62
|
+
mkdirSync(join(stage, 'bin'), { recursive: true });
|
|
63
|
+
|
|
64
|
+
// 1. Copy dist
|
|
65
|
+
cpSync(join(engineRoot, 'dist'), join(stage, 'lib', 'dist'), { recursive: true });
|
|
66
|
+
|
|
67
|
+
// 2. Copy package.json
|
|
68
|
+
copyFileSync(join(engineRoot, 'package.json'), join(stage, 'lib', 'package.json'));
|
|
69
|
+
|
|
70
|
+
// 3. Stage & stamp metadata.json
|
|
71
|
+
const metadataRaw = JSON.parse(readFileSync(join(root, 'afyx-graph', 'afyx-graph.json'), 'utf8'));
|
|
72
|
+
metadataRaw.release_channel = DISTRIBUTION_PRODUCT.releaseChannel;
|
|
73
|
+
|
|
74
|
+
let extractionVersion = 29;
|
|
75
|
+
const extractionVersionTs = join(engineRoot, 'src', 'extraction', 'extraction-version.ts');
|
|
76
|
+
if (existsSync(extractionVersionTs)) {
|
|
77
|
+
const match = readFileSync(extractionVersionTs, 'utf8').match(/EXTRACTION_VERSION\s*=\s*(\d+)/);
|
|
78
|
+
if (match) extractionVersion = parseInt(match[1], 10);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const stampedMetadata = stampArtifact(metadataRaw, {
|
|
82
|
+
target,
|
|
83
|
+
revision,
|
|
84
|
+
extractionVersion,
|
|
85
|
+
});
|
|
86
|
+
writeFileSync(join(stage, 'metadata.json'), `${JSON.stringify(stampedMetadata, null, 2)}\n`, 'utf8');
|
|
87
|
+
|
|
88
|
+
// 4. Legal files
|
|
89
|
+
for (const legal of plan.legalFiles) {
|
|
90
|
+
const destPath = join(stage, ...legal.bundlePath.split('/'));
|
|
91
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
92
|
+
copyFileSync(join(engineRoot, ...legal.source.split('/')), destPath);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 5. Launcher
|
|
96
|
+
if (plan.family === 'win32') {
|
|
97
|
+
const launcherContent = [
|
|
98
|
+
'@echo off\r\n',
|
|
99
|
+
'where node >nul 2>&1\r\n',
|
|
100
|
+
'if errorlevel 1 (\r\n',
|
|
101
|
+
' echo [Afyx Graph] Node.js was not found on PATH. Install Node.js 22.5.0 or newer: https://nodejs.org/ 1>&2\r\n',
|
|
102
|
+
' exit /b 1\r\n',
|
|
103
|
+
')\r\n',
|
|
104
|
+
'node --disable-warning=ExperimentalWarning "%~dp0..\\lib\\dist\\bin\\afyx-graph.js" %*\r\n',
|
|
105
|
+
'exit /b %ERRORLEVEL%\r\n',
|
|
106
|
+
].join('');
|
|
107
|
+
writeFileSync(join(stage, 'bin', 'afyx-graph.cmd'), launcherContent, 'utf8');
|
|
108
|
+
} else {
|
|
109
|
+
const launcherContent = [
|
|
110
|
+
'#!/bin/sh\n',
|
|
111
|
+
'if ! command -v node >/dev/null 2>&1; then\n',
|
|
112
|
+
' printf \'%s\\n\' \'[Afyx Graph] Node.js was not found on PATH. Install Node.js 22.5.0 or newer: https://nodejs.org/\' >&2\n',
|
|
113
|
+
' exit 1\n',
|
|
114
|
+
'fi\n',
|
|
115
|
+
'SELF="$0"\n',
|
|
116
|
+
'while [ -L "$SELF" ]; do\n',
|
|
117
|
+
' link="$(readlink "$SELF")"\n',
|
|
118
|
+
' case "$link" in /*) SELF="$link" ;; *) SELF="$(dirname "$SELF")/$link" ;; esac\n',
|
|
119
|
+
'done\n',
|
|
120
|
+
'BUNDLE_DIR="$(cd "$(dirname "$SELF")/.." && pwd)"\n',
|
|
121
|
+
'AFYX_GRAPH_HOST_PPID="${AFYX_GRAPH_HOST_PPID:-$PPID}"\n',
|
|
122
|
+
'export AFYX_GRAPH_HOST_PPID\n',
|
|
123
|
+
'exec node --disable-warning=ExperimentalWarning "$BUNDLE_DIR/lib/dist/bin/afyx-graph.js" "$@"\n',
|
|
124
|
+
].join('');
|
|
125
|
+
writeFileSync(join(stage, 'bin', 'afyx-graph'), launcherContent, { encoding: 'utf8', mode: 0o755 });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 6. Verify bundle
|
|
129
|
+
verifyBundle(stage, target);
|
|
130
|
+
|
|
131
|
+
// 7. Deterministic archive
|
|
132
|
+
const archiveName = plan.family === 'win32' ? `${bundleName}.zip` : `${bundleName}.tar.gz`;
|
|
133
|
+
const archivePath = join(outputDir, archiveName);
|
|
134
|
+
mkdirSync(outputDir, { recursive: true });
|
|
135
|
+
|
|
136
|
+
createDeterministicArchive({
|
|
137
|
+
source: stage,
|
|
138
|
+
target,
|
|
139
|
+
output: archivePath,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return archivePath;
|
|
143
|
+
} finally {
|
|
144
|
+
if (existsSync(tmpRoot)) {
|
|
145
|
+
rmSync(tmpRoot, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function buildGraphReleaseArtifacts(root, revision) {
|
|
151
|
+
const releaseDir = join(root, 'afyx-graph', 'engine', 'release');
|
|
152
|
+
mkdirSync(releaseDir, { recursive: true });
|
|
153
|
+
|
|
154
|
+
const winZip = buildGraphBundle({ root, target: 'win32-x64', revision, outputDir: releaseDir });
|
|
155
|
+
const linuxTar = buildGraphBundle({ root, target: 'linux-x64', revision, outputDir: releaseDir });
|
|
156
|
+
|
|
157
|
+
const winSum = createHash('sha256').update(readFileSync(winZip)).digest('hex');
|
|
158
|
+
const linuxSum = createHash('sha256').update(readFileSync(linuxTar)).digest('hex');
|
|
159
|
+
|
|
160
|
+
const sumsContent = `${linuxSum} afyx-graph-linux-x64.tar.gz\n${winSum} afyx-graph-win32-x64.zip\n`;
|
|
161
|
+
writeFileSync(join(releaseDir, 'SHA256SUMS'), sumsContent, 'utf8');
|
|
162
|
+
|
|
163
|
+
const graphVersion = JSON.parse(readFileSync(join(root, 'afyx-graph', 'engine', 'package.json'), 'utf8')).version;
|
|
164
|
+
const manifest = {
|
|
165
|
+
schema: 1,
|
|
166
|
+
product: 'Afyx Graph',
|
|
167
|
+
product_version: graphVersion,
|
|
168
|
+
release_tag: `afyx-graph-v${graphVersion}`,
|
|
169
|
+
source_revision: revision,
|
|
170
|
+
integrity_claim: 'sha256',
|
|
171
|
+
publisher_authenticity: 'requires-independent-attestation',
|
|
172
|
+
artifacts: [
|
|
173
|
+
{
|
|
174
|
+
file: 'afyx-graph-linux-x64.tar.gz',
|
|
175
|
+
target: 'linux-x64',
|
|
176
|
+
sha256: linuxSum,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
file: 'afyx-graph-win32-x64.zip',
|
|
180
|
+
target: 'win32-x64',
|
|
181
|
+
sha256: winSum,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
writeFileSync(join(releaseDir, 'RELEASE-MANIFEST.json'), `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function checkGraphReleaseValid(root, revision) {
|
|
189
|
+
const release = join(root, 'afyx-graph', 'engine', 'release');
|
|
190
|
+
const manifestPath = join(release, 'RELEASE-MANIFEST.json');
|
|
191
|
+
const sumsPath = join(release, 'SHA256SUMS');
|
|
192
|
+
const winZip = join(release, 'afyx-graph-win32-x64.zip');
|
|
193
|
+
const linuxTar = join(release, 'afyx-graph-linux-x64.tar.gz');
|
|
194
|
+
|
|
195
|
+
if (!existsSync(manifestPath) || !existsSync(sumsPath) || !existsSync(winZip) || !existsSync(linuxTar)) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
200
|
+
if (manifest.source_revision !== revision) return false;
|
|
201
|
+
const graphVersion = JSON.parse(readFileSync(join(root, 'afyx-graph', 'engine', 'package.json'), 'utf8')).version;
|
|
202
|
+
if (manifest.product_version !== graphVersion) return false;
|
|
203
|
+
for (const artifact of manifest.artifacts) {
|
|
204
|
+
const filePath = join(release, artifact.file);
|
|
205
|
+
if (!existsSync(filePath)) return false;
|
|
206
|
+
const digest = createHash('sha256').update(readFileSync(filePath)).digest('hex');
|
|
207
|
+
if (digest !== artifact.sha256) return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function prepareG6Package(root, revision, { autoBuild = false } = {}) {
|
|
216
|
+
if (!/^[0-9a-f]{40}$/.test(revision)) throw new Error('Git HEAD must be an exact commit SHA');
|
|
217
|
+
const release = join(root, 'afyx-graph', 'engine', 'release');
|
|
218
|
+
|
|
219
|
+
if (autoBuild && !checkGraphReleaseValid(root, revision)) {
|
|
220
|
+
buildGraphReleaseArtifacts(root, revision);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const manifest = JSON.parse(readFileSync(join(release, 'RELEASE-MANIFEST.json'), 'utf8'));
|
|
224
|
+
const graphVersion = JSON.parse(readFileSync(join(root, 'afyx-graph', 'engine', 'package.json'), 'utf8')).version;
|
|
225
|
+
if (manifest.schema !== 1 || manifest.product !== 'Afyx Graph' ||
|
|
226
|
+
manifest.source_revision !== revision || manifest.product_version !== graphVersion ||
|
|
227
|
+
!Array.isArray(manifest.artifacts) || manifest.artifacts.length !== expected.size) {
|
|
228
|
+
throw new Error('Graph release manifest does not match this source revision and product');
|
|
229
|
+
}
|
|
230
|
+
const sumLines = readFileSync(join(release, 'SHA256SUMS'), 'utf8').trim().split(/\r?\n/);
|
|
231
|
+
const sums = new Map(sumLines.map((line) => {
|
|
232
|
+
const match = /^([0-9a-f]{64}) (afyx-graph-(?:win32|linux)-x64\.(?:zip|tar\.gz))$/.exec(line);
|
|
233
|
+
if (!match) throw new Error('Malformed Graph SHA256SUMS');
|
|
234
|
+
return [match[2], match[1]];
|
|
235
|
+
}));
|
|
236
|
+
if (sumLines.length !== expected.size || sums.size !== expected.size) {
|
|
237
|
+
throw new Error('Graph SHA256SUMS has missing or duplicate targets');
|
|
238
|
+
}
|
|
239
|
+
const seen = new Set();
|
|
240
|
+
for (const artifact of manifest.artifacts) {
|
|
241
|
+
if (expected.get(artifact.file) !== artifact.target || seen.has(artifact.file)) {
|
|
242
|
+
throw new Error('Unexpected or duplicate Graph archive target');
|
|
243
|
+
}
|
|
244
|
+
seen.add(artifact.file);
|
|
245
|
+
const sumEntry = sums.get(artifact.file);
|
|
246
|
+
if (!sumEntry) {
|
|
247
|
+
throw new Error(`Missing SHA256SUMS entry: ${artifact.file}`);
|
|
248
|
+
}
|
|
249
|
+
const digest = createHash('sha256').update(readFileSync(join(release, artifact.file))).digest('hex');
|
|
250
|
+
if (digest !== artifact.sha256 || digest !== sumEntry) {
|
|
251
|
+
throw new Error(`SHA256SUMS mismatch: ${artifact.file}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const marker = join(root, '.afyx-source-revision');
|
|
255
|
+
if (existsSync(marker)) {
|
|
256
|
+
if (!lstatSync(marker).isFile()) {
|
|
257
|
+
throw new Error('Existing source revision marker is not a regular file');
|
|
258
|
+
}
|
|
259
|
+
if (readFileSync(marker, 'utf8').trim() !== revision) {
|
|
260
|
+
writeFileSync(marker, `${revision}\n`, 'utf8');
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
writeFileSync(marker, `${revision}\n`, { flag: 'wx' });
|
|
264
|
+
}
|
|
265
|
+
return revision;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
269
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
270
|
+
if (existsSync(join(root, '.git'))) {
|
|
271
|
+
throw new Error('Packing a Git checkout would stamp source files. Use scripts/stage-npm-release.mjs to pack an immutable commit snapshot.');
|
|
272
|
+
}
|
|
273
|
+
let revision = '';
|
|
274
|
+
|
|
275
|
+
// 1. In a Git repository, resolve Git HEAD first
|
|
276
|
+
try {
|
|
277
|
+
revision = execFileSync('git', ['-C', root, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
|
|
278
|
+
} catch {
|
|
279
|
+
// In WSL2 mounting a Windows git worktree, .git file contains Windows D:/ path
|
|
280
|
+
if (existsSync(join(root, '.git'))) {
|
|
281
|
+
try {
|
|
282
|
+
const gitContent = readFileSync(join(root, '.git'), 'utf8');
|
|
283
|
+
const gitDirMatch = gitContent.match(/gitdir:\s*([^\r\n]+)/);
|
|
284
|
+
if (gitDirMatch) {
|
|
285
|
+
let gitDir = gitDirMatch[1].trim();
|
|
286
|
+
if (process.platform === 'linux' && /^[a-zA-Z]:[\\/]/.test(gitDir)) {
|
|
287
|
+
const drive = gitDir[0].toLowerCase();
|
|
288
|
+
const rest = gitDir.slice(2).replace(/\\/g, '/');
|
|
289
|
+
gitDir = `/mnt/${drive}${rest}`;
|
|
290
|
+
}
|
|
291
|
+
revision = execFileSync('git', ['--git-dir', gitDir, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
|
|
292
|
+
}
|
|
293
|
+
} catch {
|
|
294
|
+
// ignore
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// 2. In an unpacked tarball without Git, fall back to .afyx-source-revision
|
|
300
|
+
if (!revision) {
|
|
301
|
+
const marker = join(root, '.afyx-source-revision');
|
|
302
|
+
if (existsSync(marker)) {
|
|
303
|
+
const raw = readFileSync(marker, 'utf8').trim();
|
|
304
|
+
if (/^[0-9a-f]{40}$/.test(raw)) revision = raw;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// 3. Fall back to npm gitHead or AFYX_SOURCE_REVISION
|
|
309
|
+
if (!revision) {
|
|
310
|
+
if (process.env.npm_package_gitHead && /^[0-9a-f]{40}$/.test(process.env.npm_package_gitHead)) {
|
|
311
|
+
revision = process.env.npm_package_gitHead;
|
|
312
|
+
} else if (process.env.AFYX_SOURCE_REVISION && /^[0-9a-f]{40}$/.test(process.env.AFYX_SOURCE_REVISION)) {
|
|
313
|
+
revision = process.env.AFYX_SOURCE_REVISION;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (!revision || !/^[0-9a-f]{40}$/.test(revision)) {
|
|
318
|
+
throw new Error('Exact Git source revision is required to prepare G6 package.');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// 3. Ensure Graph release artifacts exist and match current revision
|
|
322
|
+
if (!checkGraphReleaseValid(root, revision)) {
|
|
323
|
+
let resolvedFromRemote = false;
|
|
324
|
+
try {
|
|
325
|
+
console.error(`[G6 package] resolving precompiled Graph artifacts for revision ${revision}...`);
|
|
326
|
+
await resolveAndStageGitReleaseArtifacts(root, revision);
|
|
327
|
+
resolvedFromRemote = checkGraphReleaseValid(root, revision);
|
|
328
|
+
} catch (resolverErr) {
|
|
329
|
+
console.error(`[G6 package] remote artifact resolution notice: ${resolverErr.message}`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!resolvedFromRemote) {
|
|
333
|
+
// Maintainer build vs consumer failure
|
|
334
|
+
if (process.env.AFYX_BUILD_FROM_SOURCE === '1') {
|
|
335
|
+
console.error(`[G6 package] maintainer build: building Graph release artifacts for revision ${revision}...`);
|
|
336
|
+
buildGraphReleaseArtifacts(root, revision);
|
|
337
|
+
} else {
|
|
338
|
+
throw new Error(
|
|
339
|
+
`Graph release artifacts for revision ${revision} are missing or invalid.\n` +
|
|
340
|
+
`Official precompiled binaries could not be resolved from GitHub Releases.\n` +
|
|
341
|
+
`Consumer installations do not compile Graph from source.\n` +
|
|
342
|
+
`To build artifacts locally as a maintainer, set AFYX_BUILD_FROM_SOURCE=1.`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
console.error(`[G6 package] verified Graph archives and source revision ${prepareG6Package(root, revision)}`);
|
|
349
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AFYX Revision-Matched Binary Artifact Resolver
|
|
4
|
+
*
|
|
5
|
+
* Resolves precompiled Graph release archives matching the exact Git source revision
|
|
6
|
+
* from official GitHub releases/snapshots. Ensures consumer Git-based installations
|
|
7
|
+
* (e.g. npx github:a5zero7/afyx-engineering-kit#dev) obtain verified binaries without
|
|
8
|
+
* compiling Graph from TypeScript source on the consumer's machine.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { createHash } from 'node:crypto';
|
|
12
|
+
import { execFileSync } from 'node:child_process';
|
|
13
|
+
import {
|
|
14
|
+
copyFileSync,
|
|
15
|
+
existsSync,
|
|
16
|
+
mkdirSync,
|
|
17
|
+
mkdtempSync,
|
|
18
|
+
readFileSync,
|
|
19
|
+
rmSync,
|
|
20
|
+
writeFileSync,
|
|
21
|
+
} from 'node:fs';
|
|
22
|
+
import { dirname, join, resolve } from 'node:path';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
24
|
+
import { tmpdir } from 'node:os';
|
|
25
|
+
import { verifyGraphArchivePaths } from './verify-graph-archive.mjs';
|
|
26
|
+
|
|
27
|
+
const CANONICAL_REPO = 'a5zero7/afyx-engineering-kit';
|
|
28
|
+
const GITHUB_API_BASE = `https://api.github.com/repos/${CANONICAL_REPO}`;
|
|
29
|
+
const GITHUB_DOWNLOAD_BASE = `https://github.com/${CANONICAL_REPO}/releases/download`;
|
|
30
|
+
|
|
31
|
+
const REQUIRED_ARTIFACTS = Object.freeze([
|
|
32
|
+
'RELEASE-MANIFEST.json',
|
|
33
|
+
'SHA256SUMS',
|
|
34
|
+
'afyx-graph-win32-x64.zip',
|
|
35
|
+
'afyx-graph-linux-x64.tar.gz',
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
export function validateReleaseChecksums(manifest, sumsText, revision) {
|
|
39
|
+
const archives = REQUIRED_ARTIFACTS.filter((name) => name.endsWith('.zip') || name.endsWith('.tar.gz'));
|
|
40
|
+
if (manifest?.source_revision !== revision || !Array.isArray(manifest.artifacts) ||
|
|
41
|
+
manifest.artifacts.length !== archives.length) throw new Error('Incomplete or stale Graph release manifest');
|
|
42
|
+
const entries = new Map();
|
|
43
|
+
for (const artifact of manifest.artifacts) {
|
|
44
|
+
if (!archives.includes(artifact?.file) || entries.has(artifact.file) ||
|
|
45
|
+
!/^[0-9a-f]{64}$/i.test(artifact.sha256 || '')) {
|
|
46
|
+
throw new Error('Unsafe or duplicate Graph release manifest artifact');
|
|
47
|
+
}
|
|
48
|
+
entries.set(artifact.file, artifact.sha256.toLowerCase());
|
|
49
|
+
}
|
|
50
|
+
const sums = new Map();
|
|
51
|
+
for (const line of sumsText.trim().split(/\r?\n/)) {
|
|
52
|
+
const match = /^([0-9a-f]{64}) ([A-Za-z0-9._-]+)$/i.exec(line);
|
|
53
|
+
if (!match || !archives.includes(match[2]) || sums.has(match[2])) {
|
|
54
|
+
throw new Error('Unsafe, missing, or duplicate SHA256SUMS entry');
|
|
55
|
+
}
|
|
56
|
+
sums.set(match[2], match[1].toLowerCase());
|
|
57
|
+
}
|
|
58
|
+
for (const archive of archives) {
|
|
59
|
+
if (!entries.has(archive) || !sums.has(archive) || entries.get(archive) !== sums.get(archive)) {
|
|
60
|
+
throw new Error(`Missing or mismatched Graph checksum for ${archive}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return sums;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Downloads a URL to a buffer over HTTPS with timeout and bounded retries.
|
|
68
|
+
*/
|
|
69
|
+
async function fetchBuffer(url, { timeoutMs = 30000, maxAttempts = 2, headers = {} } = {}) {
|
|
70
|
+
let lastError = null;
|
|
71
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
72
|
+
const controller = new AbortController();
|
|
73
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(url, {
|
|
76
|
+
signal: controller.signal,
|
|
77
|
+
headers: {
|
|
78
|
+
'User-Agent': 'afyx-artifact-resolver/1.0',
|
|
79
|
+
...headers,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
throw new Error(`HTTP ${response.status} ${response.statusText} for ${url}`);
|
|
85
|
+
}
|
|
86
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
87
|
+
return Buffer.from(arrayBuffer);
|
|
88
|
+
} catch (err) {
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
lastError = err;
|
|
91
|
+
if (attempt < maxAttempts) {
|
|
92
|
+
await new Promise((r) => setTimeout(r, 1000 * attempt));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
throw lastError;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Resolves exact Git checkout revision SHA.
|
|
101
|
+
*/
|
|
102
|
+
export function resolveGitRevision(root) {
|
|
103
|
+
// 1. Try git rev-parse HEAD directly
|
|
104
|
+
try {
|
|
105
|
+
const out = execFileSync('git', ['-C', root, 'rev-parse', 'HEAD'], {
|
|
106
|
+
encoding: 'utf8',
|
|
107
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
108
|
+
}).trim();
|
|
109
|
+
if (/^[0-9a-f]{40}$/.test(out)) return out;
|
|
110
|
+
} catch {
|
|
111
|
+
// In WSL2 mounting Windows paths, check .git pointer
|
|
112
|
+
const gitPath = join(root, '.git');
|
|
113
|
+
if (existsSync(gitPath)) {
|
|
114
|
+
try {
|
|
115
|
+
const gitContent = readFileSync(gitPath, 'utf8');
|
|
116
|
+
const match = gitContent.match(/gitdir:\s*([^\r\n]+)/);
|
|
117
|
+
if (match) {
|
|
118
|
+
let gitDir = match[1].trim();
|
|
119
|
+
if (process.platform === 'linux' && /^[a-zA-Z]:[\\/]/.test(gitDir)) {
|
|
120
|
+
const drive = gitDir[0].toLowerCase();
|
|
121
|
+
const rest = gitDir.slice(2).replace(/\\/g, '/');
|
|
122
|
+
gitDir = `/mnt/${drive}${rest}`;
|
|
123
|
+
}
|
|
124
|
+
const out = execFileSync('git', ['--git-dir', gitDir, 'rev-parse', 'HEAD'], {
|
|
125
|
+
encoding: 'utf8',
|
|
126
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
127
|
+
}).trim();
|
|
128
|
+
if (/^[0-9a-f]{40}$/.test(out)) return out;
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// ignore
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 2. Fall back to stamped .afyx-source-revision
|
|
137
|
+
const marker = join(root, '.afyx-source-revision');
|
|
138
|
+
if (existsSync(marker)) {
|
|
139
|
+
const raw = readFileSync(marker, 'utf8').trim();
|
|
140
|
+
if (/^[0-9a-f]{40}$/.test(raw)) return raw;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 3. Fall back to npm lifecycle environment variable or explicit env
|
|
144
|
+
if (process.env.npm_package_gitHead && /^[0-9a-f]{40}$/.test(process.env.npm_package_gitHead)) {
|
|
145
|
+
return process.env.npm_package_gitHead;
|
|
146
|
+
}
|
|
147
|
+
if (process.env.AFYX_SOURCE_REVISION && /^[0-9a-f]{40}$/.test(process.env.AFYX_SOURCE_REVISION)) {
|
|
148
|
+
return process.env.AFYX_SOURCE_REVISION;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Resolves candidates tags for GitHub releases associated with a given commit SHA.
|
|
156
|
+
*/
|
|
157
|
+
export function getCandidateTagsForRevision(revision) {
|
|
158
|
+
const shortSha = revision.slice(0, 12);
|
|
159
|
+
return [
|
|
160
|
+
`afyx-dev-${revision}`,
|
|
161
|
+
`dev-${revision}`,
|
|
162
|
+
`afyx-dev-${shortSha}`,
|
|
163
|
+
`dev-${shortSha}`,
|
|
164
|
+
`afyx-dev-snapshot`,
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Downloads and verifies revision-matched release artifacts into afyx-graph/engine/release/.
|
|
170
|
+
*/
|
|
171
|
+
export async function resolveAndStageGitReleaseArtifacts(root, revision, options = {}) {
|
|
172
|
+
if (!revision || !/^[0-9a-f]{40}$/.test(revision)) {
|
|
173
|
+
throw new Error(`Valid 40-character Git commit SHA is required (got: "${revision}")`);
|
|
174
|
+
}
|
|
175
|
+
const fetchArtifact = options.fetchBuffer || fetchBuffer;
|
|
176
|
+
const apiBase = options.apiBase || GITHUB_API_BASE;
|
|
177
|
+
const downloadBase = options.downloadBase || GITHUB_DOWNLOAD_BASE;
|
|
178
|
+
const tagMatchesRevision = async (tag) => {
|
|
179
|
+
const raw = await fetchArtifact(`${apiBase}/commits/${encodeURIComponent(tag)}`,
|
|
180
|
+
{ timeoutMs: 10000, maxAttempts: 1 });
|
|
181
|
+
return JSON.parse(raw.toString('utf8'))?.sha === revision;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const releaseDir = join(root, 'afyx-graph', 'engine', 'release');
|
|
185
|
+
mkdirSync(releaseDir, { recursive: true });
|
|
186
|
+
|
|
187
|
+
const tempStage = mkdtempSync(join(tmpdir(), 'afyx-download-artifacts-'));
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
let resolvedTag = null;
|
|
191
|
+
let manifestBuffer = null;
|
|
192
|
+
let manifestObj = null;
|
|
193
|
+
|
|
194
|
+
// 1. Try candidate release tags directly
|
|
195
|
+
const candidateTags = getCandidateTagsForRevision(revision);
|
|
196
|
+
|
|
197
|
+
for (const tag of candidateTags) {
|
|
198
|
+
try {
|
|
199
|
+
const manifestUrl = `${downloadBase}/${tag}/RELEASE-MANIFEST.json`;
|
|
200
|
+
const buf = await fetchArtifact(manifestUrl, { timeoutMs: 10000, maxAttempts: 1 });
|
|
201
|
+
const parsed = JSON.parse(buf.toString('utf8'));
|
|
202
|
+
if (parsed?.source_revision === revision && await tagMatchesRevision(tag)) {
|
|
203
|
+
resolvedTag = tag;
|
|
204
|
+
manifestBuffer = buf;
|
|
205
|
+
manifestObj = parsed;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
} catch {
|
|
209
|
+
// Continue searching other candidate tags
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 2. Search release assets; target_commitish is not proof of the tag's target.
|
|
214
|
+
if (!resolvedTag) {
|
|
215
|
+
try {
|
|
216
|
+
const releasesBuf = await fetchArtifact(`${apiBase}/releases`, { timeoutMs: 15000, maxAttempts: 1 });
|
|
217
|
+
const releases = JSON.parse(releasesBuf.toString('utf8'));
|
|
218
|
+
if (Array.isArray(releases)) {
|
|
219
|
+
for (const rel of releases) {
|
|
220
|
+
if (rel.tag_name && await tagMatchesRevision(rel.tag_name)) {
|
|
221
|
+
const manifestAsset = (rel.assets || []).find((a) => a.name === 'RELEASE-MANIFEST.json');
|
|
222
|
+
if (manifestAsset) {
|
|
223
|
+
const buf = await fetchArtifact(manifestAsset.browser_download_url, { timeoutMs: 10000, maxAttempts: 1 });
|
|
224
|
+
const parsed = JSON.parse(buf.toString('utf8'));
|
|
225
|
+
if (parsed?.source_revision === revision) {
|
|
226
|
+
resolvedTag = rel.tag_name;
|
|
227
|
+
manifestBuffer = buf;
|
|
228
|
+
manifestObj = parsed;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
} catch {
|
|
236
|
+
// Releases API query failed or rate-limited
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (!resolvedTag || !manifestObj) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`No official precompiled Graph release artifacts found for Git revision ${revision}.\n` +
|
|
243
|
+
`Consumer installations require prebuilt binaries to prevent source compilation.\n` +
|
|
244
|
+
`To build artifacts locally as a maintainer, run with AFYX_BUILD_FROM_SOURCE=1.`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
writeFileSync(join(tempStage, 'RELEASE-MANIFEST.json'), manifestBuffer);
|
|
249
|
+
|
|
250
|
+
// 3. Download SHA256SUMS
|
|
251
|
+
const sumsUrl = `${downloadBase}/${resolvedTag}/SHA256SUMS`;
|
|
252
|
+
const sumsBuf = await fetchArtifact(sumsUrl);
|
|
253
|
+
writeFileSync(join(tempStage, 'SHA256SUMS'), sumsBuf);
|
|
254
|
+
|
|
255
|
+
const sumsContent = sumsBuf.toString('utf8').trim();
|
|
256
|
+
const expectedSums = validateReleaseChecksums(manifestObj, sumsContent, revision);
|
|
257
|
+
|
|
258
|
+
// 4. Download and verify each required archive
|
|
259
|
+
const archivesToDownload = ['afyx-graph-win32-x64.zip', 'afyx-graph-linux-x64.tar.gz'];
|
|
260
|
+
for (const archiveName of archivesToDownload) {
|
|
261
|
+
const archiveUrl = `${downloadBase}/${resolvedTag}/${archiveName}`;
|
|
262
|
+
const archiveBuf = await fetchArtifact(archiveUrl, { timeoutMs: 60000 });
|
|
263
|
+
verifyGraphArchivePaths(archiveBuf, archiveName);
|
|
264
|
+
|
|
265
|
+
// Verify SHA256 against SHA256SUMS and manifest
|
|
266
|
+
const computedSha = createHash('sha256').update(archiveBuf).digest('hex').toLowerCase();
|
|
267
|
+
const manifestEntry = (manifestObj.artifacts || []).find((a) => a.file === archiveName);
|
|
268
|
+
if (!manifestEntry) {
|
|
269
|
+
throw new Error(`Manifest missing artifact entry for ${archiveName}`);
|
|
270
|
+
}
|
|
271
|
+
if (computedSha !== manifestEntry.sha256.toLowerCase()) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`Checksum mismatch for ${archiveName} against manifest: expected ${manifestEntry.sha256}, got ${computedSha}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
const sumEntry = expectedSums.get(archiveName);
|
|
277
|
+
if (!sumEntry) {
|
|
278
|
+
throw new Error(`Missing SHA256SUMS entry: ${archiveName}`);
|
|
279
|
+
}
|
|
280
|
+
if (computedSha !== sumEntry) {
|
|
281
|
+
throw new Error(`SHA256SUMS mismatch: ${archiveName}`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
writeFileSync(join(tempStage, archiveName), archiveBuf);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 5. Atomically stage all verified artifacts to releaseDir
|
|
288
|
+
for (const file of REQUIRED_ARTIFACTS) {
|
|
289
|
+
copyFileSync(join(tempStage, file), join(releaseDir, file));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
success: true,
|
|
294
|
+
tag: resolvedTag,
|
|
295
|
+
revision,
|
|
296
|
+
artifacts: REQUIRED_ARTIFACTS,
|
|
297
|
+
};
|
|
298
|
+
} finally {
|
|
299
|
+
if (existsSync(tempStage)) {
|
|
300
|
+
rmSync(tempStage, { recursive: true, force: true });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
306
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
307
|
+
const revision = resolveGitRevision(root);
|
|
308
|
+
if (!revision) {
|
|
309
|
+
console.error('[artifact-resolver] ERROR: Could not determine Git revision.');
|
|
310
|
+
process.exit(1);
|
|
311
|
+
}
|
|
312
|
+
console.log(`[artifact-resolver] Resolving precompiled artifacts for revision ${revision}...`);
|
|
313
|
+
resolveAndStageGitReleaseArtifacts(root, revision)
|
|
314
|
+
.then((result) => {
|
|
315
|
+
console.log(`[artifact-resolver] Successfully staged artifacts from release tag ${result.tag}`);
|
|
316
|
+
})
|
|
317
|
+
.catch((err) => {
|
|
318
|
+
console.error(`[artifact-resolver] FAILED: ${err.message}`);
|
|
319
|
+
process.exit(1);
|
|
320
|
+
});
|
|
321
|
+
}
|