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,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": 1,
|
|
3
|
+
"product_name": "Afyx Context Engine",
|
|
4
|
+
"product_version": "0.1.0",
|
|
5
|
+
"cli": "afyx-context",
|
|
6
|
+
"runtime": "node",
|
|
7
|
+
"ownership_class": "AFYX",
|
|
8
|
+
"standalone": true,
|
|
9
|
+
"integration_contract": "ace.integration/v1",
|
|
10
|
+
"optional_consumers": {
|
|
11
|
+
"graph": {
|
|
12
|
+
"contract": "graph.ace.consumer/v1",
|
|
13
|
+
"default_enabled": false,
|
|
14
|
+
"execution": "local-terminable-worker"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"local_coordination": {
|
|
18
|
+
"contract_version": 1,
|
|
19
|
+
"scope": "state-root-exclusive",
|
|
20
|
+
"default_timeout_ms": 5000,
|
|
21
|
+
"recovery": "same-host-pid-absence-fail-closed"
|
|
22
|
+
},
|
|
23
|
+
"kit_management": {
|
|
24
|
+
"contract_version": 1,
|
|
25
|
+
"lifecycle_integration": "managed-optional",
|
|
26
|
+
"default_presets": [
|
|
27
|
+
"full"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://afyx.dev/contracts/ace.integration.v1.schema.json",
|
|
4
|
+
"title": "Afyx Context Engine Optional Integration v1",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["contract", "component", "stateDir", "ownerId", "sessionId", "segments"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"contract": { "const": "ace.integration/v1" },
|
|
10
|
+
"component": { "enum": ["graph", "engineering-expert", "forge", "kit"] },
|
|
11
|
+
"stateDir": { "type": "string", "minLength": 1, "maxLength": 32767 },
|
|
12
|
+
"ownerId": { "type": "string", "minLength": 1, "maxLength": 512 },
|
|
13
|
+
"sessionId": { "type": "string", "minLength": 1, "maxLength": 512 },
|
|
14
|
+
"budgetChars": { "type": "integer", "minimum": 1 },
|
|
15
|
+
"segments": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"minItems": 1,
|
|
18
|
+
"maxItems": 1024,
|
|
19
|
+
"items": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"additionalProperties": false,
|
|
22
|
+
"required": ["id", "content"],
|
|
23
|
+
"properties": {
|
|
24
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 512, "pattern": "^[^\\u0000-\\u001f\\u007f]+$" },
|
|
25
|
+
"content": { "type": "string", "maxLength": 1048576 },
|
|
26
|
+
"classification": {
|
|
27
|
+
"enum": ["normal", "diagnostic", "security", "source-evidence"]
|
|
28
|
+
},
|
|
29
|
+
"provenance": { "type": "object" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a5zero7/afyx-context",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "@a5zero7/afyx-context",
|
|
9
|
+
"version": "0.1.0",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bin": {
|
|
12
|
+
"afyx-context": "dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"js-tiktoken": "1.0.21"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22.5.0"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"node_modules/base64-js": {
|
|
22
|
+
"version": "1.5.1",
|
|
23
|
+
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
|
24
|
+
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
|
25
|
+
"dev": true,
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/feross"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "patreon",
|
|
33
|
+
"url": "https://www.patreon.com/feross"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"type": "consulting",
|
|
37
|
+
"url": "https://feross.org/support"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"license": "MIT"
|
|
41
|
+
},
|
|
42
|
+
"node_modules/js-tiktoken": {
|
|
43
|
+
"version": "1.0.21",
|
|
44
|
+
"resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.21.tgz",
|
|
45
|
+
"integrity": "sha512-biOj/6M5qdgx5TKjDnFT1ymSpM5tbd3ylwDtrQvFQSu0Z7bBYko2dF+W/aUkXUPuk6IVpRxk/3Q2sHOzGlS36g==",
|
|
46
|
+
"dev": true,
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"base64-js": "^1.5.1"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a5zero7/afyx-context",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Afyx-owned standalone context reduction and recovery engine.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"exports": "./dist/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"afyx-context": "./dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"contracts",
|
|
14
|
+
"afyx-context.json",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "node scripts/build.mjs",
|
|
20
|
+
"build:clean": "node scripts/build.mjs --clean",
|
|
21
|
+
"test": "node --test",
|
|
22
|
+
"test:benchmark": "node scripts/benchmark.mjs",
|
|
23
|
+
"test:comparative": "node scripts/comparative-benchmark.mjs",
|
|
24
|
+
"test:graph-integration": "node scripts/graph-integration-e2e.mjs",
|
|
25
|
+
"test:integrated-dogfood": "node scripts/integrated-dogfood.mjs"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"js-tiktoken": "1.0.21"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.5.0"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT"
|
|
34
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { performance } from 'node:perf_hooks';
|
|
5
|
+
import { AfyxContextEngine } from '../src/index.js';
|
|
6
|
+
|
|
7
|
+
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'afyx-context-benchmark-'));
|
|
8
|
+
try {
|
|
9
|
+
const repeated = [
|
|
10
|
+
'Synthetic repository inventory follows.',
|
|
11
|
+
...Array.from({ length: 80 }, (_, index) => `owned/module-${index + 1}.js synthetic entry`),
|
|
12
|
+
].join('\n');
|
|
13
|
+
const segments = [
|
|
14
|
+
{ id: 'diagnostic', classification: 'diagnostic', content: 'SECURITY: retain the exact failure code E_BOUNDARY.' },
|
|
15
|
+
...Array.from({ length: 12 }, (_, index) => ({ id: `log-${index + 1}`, content: repeated, provenance: { fixture: 'synthetic-repeat-v1' } })),
|
|
16
|
+
];
|
|
17
|
+
const started = performance.now();
|
|
18
|
+
const engine = new AfyxContextEngine({ stateDir, ownerId: 'benchmark-owner', sessionId: 'benchmark-session' });
|
|
19
|
+
const result = engine.reduce({ segments, budgetChars: 100_000 });
|
|
20
|
+
const elapsedMs = performance.now() - started;
|
|
21
|
+
for (const item of result.items) {
|
|
22
|
+
if (item.disposition === 'reference' && engine.retrieve(item.reference) !== repeated) {
|
|
23
|
+
throw new Error(`recovery mismatch for ${item.id}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
process.stdout.write(`${JSON.stringify({
|
|
27
|
+
fixture: 'synthetic-repeat-v1',
|
|
28
|
+
rawBaselineChars: result.metrics.rawChars,
|
|
29
|
+
nativeAceChars: result.metrics.outputChars,
|
|
30
|
+
savedChars: result.metrics.savedChars,
|
|
31
|
+
reductionRatio: result.metrics.reductionRatio,
|
|
32
|
+
elapsedMs,
|
|
33
|
+
processRssBytes: process.memoryUsage().rss,
|
|
34
|
+
recovery: 'PASS',
|
|
35
|
+
headroomComparison: 'NOT_RUN',
|
|
36
|
+
}, null, 2)}\n`);
|
|
37
|
+
} finally {
|
|
38
|
+
fs.rmSync(stateDir, { recursive: true, force: true });
|
|
39
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
6
|
+
const source = path.join(root, 'src');
|
|
7
|
+
const target = path.join(root, 'dist');
|
|
8
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
9
|
+
fs.mkdirSync(target, { recursive: true });
|
|
10
|
+
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
|
|
11
|
+
if (!entry.isFile() || !entry.name.endsWith('.js')) continue;
|
|
12
|
+
fs.copyFileSync(path.join(source, entry.name), path.join(target, entry.name));
|
|
13
|
+
}
|
|
14
|
+
fs.chmodSync(path.join(target, 'cli.js'), 0o755);
|
|
15
|
+
process.stdout.write(`Built ${fs.readdirSync(target).length} ACE runtime files.\n`);
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { performance } from 'node:perf_hooks';
|
|
8
|
+
import { getEncoding } from 'js-tiktoken';
|
|
9
|
+
import { BENCHMARK_FIXTURES, rawContext } from '../benchmark/fixtures.mjs';
|
|
10
|
+
import { ACE_INTEGRATION_CONTRACT, AceError, AfyxContextEngine, createOptionalIntegrationAdapter } from '../src/index.js';
|
|
11
|
+
|
|
12
|
+
const SOURCE_SHA = '594452d4722d4135ef04643639c1ad16c2c5e681';
|
|
13
|
+
const DEFAULT_SAMPLE_COUNT = 7;
|
|
14
|
+
const TOKENIZER = Object.freeze({ package: 'js-tiktoken', version: '1.0.21', encoding: 'o200k_base', license: 'MIT' });
|
|
15
|
+
const encoder = getEncoding(TOKENIZER.encoding);
|
|
16
|
+
|
|
17
|
+
function sha256(value) {
|
|
18
|
+
return crypto.createHash('sha256').update(value).digest('hex');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function utf8Bytes(value) {
|
|
22
|
+
return Buffer.byteLength(value, 'utf8');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function tokens(value) {
|
|
26
|
+
return encoder.encode(value).length;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parseOptions(args) {
|
|
30
|
+
const options = { output: null, sampleCount: DEFAULT_SAMPLE_COUNT, summaryOnly: false };
|
|
31
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
32
|
+
const argument = args[index];
|
|
33
|
+
if (argument === '--output') options.output = args[++index];
|
|
34
|
+
else if (argument === '--samples') options.sampleCount = Number(args[++index]);
|
|
35
|
+
else if (argument === '--summary') options.summaryOnly = true;
|
|
36
|
+
else if (!argument.startsWith('-') && options.output === null) options.output = argument;
|
|
37
|
+
else throw new Error(`unknown benchmark argument: ${argument}`);
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isSafeInteger(options.sampleCount) || options.sampleCount < 1 || options.sampleCount > 20) {
|
|
40
|
+
throw new Error('--samples must be a safe integer from 1 to 20');
|
|
41
|
+
}
|
|
42
|
+
if (options.output !== null && (typeof options.output !== 'string' || options.output.length === 0)) {
|
|
43
|
+
throw new Error('--output requires a path');
|
|
44
|
+
}
|
|
45
|
+
return options;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function metric(value) {
|
|
49
|
+
return { chars: value.length, utf8Bytes: utf8Bytes(value), tokens: tokens(value) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function median(values) {
|
|
53
|
+
const ordered = [...values].sort((left, right) => left - right);
|
|
54
|
+
const middle = Math.floor(ordered.length / 2);
|
|
55
|
+
return ordered.length % 2 === 0 ? (ordered[middle - 1] + ordered[middle]) / 2 : ordered[middle];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function aggregate(values) {
|
|
59
|
+
return { min: Math.min(...values), median: median(values), max: Math.max(...values) };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function cpuSnapshot() {
|
|
63
|
+
return os.cpus().reduce((totals, cpu) => {
|
|
64
|
+
const total = Object.values(cpu.times).reduce((sum, value) => sum + value, 0);
|
|
65
|
+
return { idle: totals.idle + cpu.times.idle, total: totals.total + total };
|
|
66
|
+
}, { idle: 0, total: 0 });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function sampleHostLoad(sampleCount = 5, intervalMs = 250) {
|
|
70
|
+
const samples = [];
|
|
71
|
+
for (let index = 0; index < sampleCount; index += 1) {
|
|
72
|
+
const before = cpuSnapshot();
|
|
73
|
+
const startedAt = new Date().toISOString();
|
|
74
|
+
const started = performance.now();
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
76
|
+
const after = cpuSnapshot();
|
|
77
|
+
const actualCadenceMs = performance.now() - started;
|
|
78
|
+
const totalDelta = after.total - before.total;
|
|
79
|
+
const idleDelta = after.idle - before.idle;
|
|
80
|
+
samples.push({
|
|
81
|
+
startedAt,
|
|
82
|
+
actualCadenceMs,
|
|
83
|
+
utilizationPercent: totalDelta === 0 ? 0 : ((totalDelta - idleDelta) / totalDelta) * 100,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
requestedSampleCount: sampleCount,
|
|
88
|
+
requestedIntervalMs: intervalMs,
|
|
89
|
+
samples,
|
|
90
|
+
meanUtilizationPercent: samples.reduce((sum, sample) => sum + sample.utilizationPercent, 0) / samples.length,
|
|
91
|
+
freeMemoryBytes: os.freemem(),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function runWorker(fixtureId, mode) {
|
|
96
|
+
const started = performance.now();
|
|
97
|
+
const child = spawnSync(process.execPath, [path.join(import.meta.dirname, 'comparative-worker.mjs')], {
|
|
98
|
+
input: JSON.stringify({ fixtureId, mode }),
|
|
99
|
+
encoding: 'utf8',
|
|
100
|
+
windowsHide: true,
|
|
101
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
102
|
+
});
|
|
103
|
+
const processWallMs = performance.now() - started;
|
|
104
|
+
if (child.status !== 0) throw new Error(`worker failed for ${fixtureId}/${mode}: ${child.stderr || child.stdout}`);
|
|
105
|
+
return { ...JSON.parse(child.stdout), processWallMs };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function accounting(fixture, worker) {
|
|
109
|
+
const raw = rawContext(fixture);
|
|
110
|
+
const rendered = worker.result.renderedContext;
|
|
111
|
+
const recoveryExchange = worker.recoveries.map((recovery) => {
|
|
112
|
+
const request = JSON.stringify({ operation: 'ace.get/v1', reference: recovery.reference });
|
|
113
|
+
const response = recovery.content;
|
|
114
|
+
return { id: recovery.id, reference: recovery.reference, digest: recovery.digest, request: metric(request), response: metric(response) };
|
|
115
|
+
});
|
|
116
|
+
const recoveryText = recoveryExchange.map((entry, index) => {
|
|
117
|
+
const recovery = worker.recoveries[index];
|
|
118
|
+
return `${JSON.stringify({ operation: 'ace.get/v1', reference: entry.reference })}\n${recovery.content}`;
|
|
119
|
+
}).join('\n');
|
|
120
|
+
const net = `${rendered}${recoveryText.length > 0 ? `\n${recoveryText}` : ''}`;
|
|
121
|
+
const rawMetric = metric(raw);
|
|
122
|
+
const aceMetric = metric(rendered);
|
|
123
|
+
const netMetric = metric(net);
|
|
124
|
+
return {
|
|
125
|
+
raw: rawMetric,
|
|
126
|
+
aceGross: aceMetric,
|
|
127
|
+
recovery: {
|
|
128
|
+
count: recoveryExchange.length,
|
|
129
|
+
requestTokens: recoveryExchange.reduce((total, entry) => total + entry.request.tokens, 0),
|
|
130
|
+
responseTokens: recoveryExchange.reduce((total, entry) => total + entry.response.tokens, 0),
|
|
131
|
+
exchanges: recoveryExchange,
|
|
132
|
+
},
|
|
133
|
+
aceNetAfterRecovery: netMetric,
|
|
134
|
+
grossSavedTokens: rawMetric.tokens - aceMetric.tokens,
|
|
135
|
+
netSavedTokens: rawMetric.tokens - netMetric.tokens,
|
|
136
|
+
grossReductionRatio: rawMetric.tokens === 0 ? 0 : (rawMetric.tokens - aceMetric.tokens) / rawMetric.tokens,
|
|
137
|
+
netReductionRatio: rawMetric.tokens === 0 ? 0 : (rawMetric.tokens - netMetric.tokens) / rawMetric.tokens,
|
|
138
|
+
serialization: {
|
|
139
|
+
request: metric(JSON.stringify({ segments: fixture.segments, budgetChars: fixture.budgetChars })),
|
|
140
|
+
result: metric(JSON.stringify(worker.result)),
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function expectAceError(action, code) {
|
|
146
|
+
try {
|
|
147
|
+
action();
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (error instanceof AceError && error.code === code) return 'PASS';
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`expected ${code}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function validateCallerFallback(result) {
|
|
156
|
+
if (result.status !== 'fallback') return result.renderedContext;
|
|
157
|
+
if (result.originalComplete) return result.renderedContext;
|
|
158
|
+
if (Array.isArray(result.originalInput) && result.originalInput.every((item) => item && typeof item === 'object' && typeof item.content === 'string')) {
|
|
159
|
+
return result.originalInput;
|
|
160
|
+
}
|
|
161
|
+
throw new AceError('INCOMPLETE_ORIGINAL', 'caller cannot safely reconstruct incomplete fallback');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function correctnessChecks() {
|
|
165
|
+
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'afyx-291-correctness-'));
|
|
166
|
+
try {
|
|
167
|
+
const fixture = BENCHMARK_FIXTURES.find((candidate) => candidate.id === 'repeat-heavy-v1');
|
|
168
|
+
const engine = new AfyxContextEngine({ stateDir, ownerId: 'correctness-owner', sessionId: 'session-a' });
|
|
169
|
+
const result = engine.reduce({ segments: fixture.segments, budgetChars: fixture.budgetChars });
|
|
170
|
+
const references = result.items.filter((item) => item.disposition === 'reference');
|
|
171
|
+
if (references.length === 0) throw new Error('correctness fixture emitted no references');
|
|
172
|
+
for (const item of references) {
|
|
173
|
+
const expected = fixture.segments.find((segment) => segment.id === item.id).content;
|
|
174
|
+
if (engine.retrieve(item.reference) !== expected) throw new Error(`incorrect recovery for ${item.id}`);
|
|
175
|
+
}
|
|
176
|
+
const protectedItem = result.items.find((item) => item.classification === 'diagnostic');
|
|
177
|
+
if (protectedItem?.disposition !== 'original' || !result.renderedContext.includes('E_REPEAT_BOUNDARY')) {
|
|
178
|
+
throw new Error('protected diagnostic was not preserved');
|
|
179
|
+
}
|
|
180
|
+
const otherSession = new AfyxContextEngine({ stateDir, ownerId: 'correctness-owner', sessionId: 'session-b' });
|
|
181
|
+
const crossSession = expectAceError(() => otherSession.retrieve(references[0].reference), 'REFERENCE_BOUNDARY');
|
|
182
|
+
const foreignOwner = expectAceError(
|
|
183
|
+
() => new AfyxContextEngine({ stateDir, ownerId: 'foreign-owner', sessionId: 'session-a' }),
|
|
184
|
+
'FOREIGN_STATE',
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const adapter = createOptionalIntegrationAdapter({ component: 'graph' });
|
|
188
|
+
const validOversized = Array.from({ length: 9 }, (_, index) => ({ id: `large-${index}`, content: 'x'.repeat(1_048_576) }));
|
|
189
|
+
const retained = adapter.process({
|
|
190
|
+
contract: ACE_INTEGRATION_CONTRACT,
|
|
191
|
+
component: 'graph',
|
|
192
|
+
segments: validOversized,
|
|
193
|
+
});
|
|
194
|
+
if (retained.originalComplete !== false || validateCallerFallback(retained) !== validOversized) {
|
|
195
|
+
throw new Error('caller did not retain valid originalInput when rendered fallback was incomplete');
|
|
196
|
+
}
|
|
197
|
+
const malformed = adapter.process({
|
|
198
|
+
contract: ACE_INTEGRATION_CONTRACT,
|
|
199
|
+
component: 'graph',
|
|
200
|
+
segments: [null, { id: 'valid', content: 'retained synthetic content' }],
|
|
201
|
+
});
|
|
202
|
+
const malformedFailClosed = expectAceError(() => validateCallerFallback(malformed), 'INCOMPLETE_ORIGINAL');
|
|
203
|
+
const passthroughFixture = BENCHMARK_FIXTURES.find((candidate) => candidate.id === 'protected-passthrough-v1');
|
|
204
|
+
const passthroughState = fs.mkdtempSync(path.join(os.tmpdir(), 'afyx-291-passthrough-'));
|
|
205
|
+
try {
|
|
206
|
+
const passthroughEngine = new AfyxContextEngine({ stateDir: passthroughState, ownerId: 'passthrough-owner', sessionId: 'passthrough' });
|
|
207
|
+
const passthrough = passthroughEngine.reduce({ segments: passthroughFixture.segments, budgetChars: passthroughFixture.budgetChars });
|
|
208
|
+
if (passthrough.mode !== 'passthrough' || passthrough.renderedContext !== rawContext(passthroughFixture)) {
|
|
209
|
+
throw new Error('passthrough was not byte-complete');
|
|
210
|
+
}
|
|
211
|
+
} finally {
|
|
212
|
+
fs.rmSync(passthroughState, { recursive: true, force: true });
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
exactOriginalRecovery: 'PASS',
|
|
216
|
+
protectedContentPreservation: 'PASS',
|
|
217
|
+
crossSessionRejection: crossSession,
|
|
218
|
+
foreignOwnerRejection: foreignOwner,
|
|
219
|
+
incompleteFallbackRetainsValidOriginalInput: 'PASS',
|
|
220
|
+
malformedIncompleteFallbackFailsClosed: malformedFailClosed,
|
|
221
|
+
passthroughCompleteness: 'PASS',
|
|
222
|
+
};
|
|
223
|
+
} finally {
|
|
224
|
+
fs.rmSync(stateDir, { recursive: true, force: true });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function summarize(samples) {
|
|
229
|
+
return {
|
|
230
|
+
constructionMs: aggregate(samples.map((sample) => sample.timing.constructionMs)),
|
|
231
|
+
reduceMs: aggregate(samples.map((sample) => sample.timing.reduceMs)),
|
|
232
|
+
recoveryMs: aggregate(samples.map((sample) => sample.timing.recoveryMs)),
|
|
233
|
+
processWallMs: aggregate(samples.map((sample) => sample.processWallMs)),
|
|
234
|
+
rssTwoPointObservedMaxBytes: aggregate(samples.map((sample) => sample.process.rssTwoPointObservedMaxBytes)),
|
|
235
|
+
rssDeltaBytes: aggregate(samples.map((sample) => sample.process.rssAfterBytes - sample.process.rssBeforeBytes)),
|
|
236
|
+
cpuUserMicroseconds: aggregate(samples.map((sample) => sample.process.cpuUserMicroseconds)),
|
|
237
|
+
cpuSystemMicroseconds: aggregate(samples.map((sample) => sample.process.cpuSystemMicroseconds)),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const options = parseOptions(process.argv.slice(2));
|
|
242
|
+
const hostLoadBefore = await sampleHostLoad();
|
|
243
|
+
const toolingFiles = [
|
|
244
|
+
path.join(import.meta.dirname, 'comparative-benchmark.mjs'),
|
|
245
|
+
path.join(import.meta.dirname, 'comparative-worker.mjs'),
|
|
246
|
+
path.join(import.meta.dirname, '..', 'benchmark', 'fixtures.mjs'),
|
|
247
|
+
];
|
|
248
|
+
const toolingIdentity = sha256(toolingFiles.map((file) => `${path.basename(file)}\0${fs.readFileSync(file)}`).join('\0'));
|
|
249
|
+
const fixtureResults = [];
|
|
250
|
+
for (const fixture of BENCHMARK_FIXTURES) {
|
|
251
|
+
const fixtureIdentity = sha256(JSON.stringify(fixture));
|
|
252
|
+
const modes = {};
|
|
253
|
+
for (const mode of ['cold', 'warm']) {
|
|
254
|
+
const rawSamples = Array.from({ length: options.sampleCount }, () => runWorker(fixture.id, mode));
|
|
255
|
+
const samples = rawSamples.map((sample, index) => ({
|
|
256
|
+
sample: index + 1,
|
|
257
|
+
mode,
|
|
258
|
+
resultMode: sample.result.mode,
|
|
259
|
+
resultReason: sample.result.reason ?? null,
|
|
260
|
+
accounting: accounting(fixture, sample),
|
|
261
|
+
timing: sample.timing,
|
|
262
|
+
process: sample.process,
|
|
263
|
+
processWallMs: sample.processWallMs,
|
|
264
|
+
outputIdentity: sha256(JSON.stringify({ renderedContext: sample.result.renderedContext, items: sample.result.items })),
|
|
265
|
+
}));
|
|
266
|
+
if (new Set(samples.map((sample) => sample.outputIdentity)).size !== 1) {
|
|
267
|
+
throw new Error(`non-deterministic ${fixture.id}/${mode} output`);
|
|
268
|
+
}
|
|
269
|
+
modes[mode] = { samples, aggregate: summarize(rawSamples) };
|
|
270
|
+
}
|
|
271
|
+
fixtureResults.push({
|
|
272
|
+
id: fixture.id,
|
|
273
|
+
description: fixture.description,
|
|
274
|
+
fixtureIdentity,
|
|
275
|
+
budgetChars: fixture.budgetChars,
|
|
276
|
+
recoveryPolicy: fixture.recovery,
|
|
277
|
+
coldAccounting: modes.cold.samples[0].accounting,
|
|
278
|
+
warmAccounting: modes.warm.samples[0].accounting,
|
|
279
|
+
modes,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const evidence = {
|
|
284
|
+
schema: 'afyx.ace.comparative-benchmark/v1',
|
|
285
|
+
generatedAt: new Date().toISOString(),
|
|
286
|
+
foundationSourceSha: SOURCE_SHA,
|
|
287
|
+
benchmarkToolingIdentity: toolingIdentity,
|
|
288
|
+
aceVersion: '0.1.0',
|
|
289
|
+
methodology: {
|
|
290
|
+
pairedPaths: ['raw-context', 'native-ace'],
|
|
291
|
+
sampleCountPerFixtureMode: options.sampleCount,
|
|
292
|
+
modes: {
|
|
293
|
+
cold: 'fresh process, fresh state, one measured reduce',
|
|
294
|
+
warm: 'fresh process and state, one unmeasured warm-up reduce, then one measured reduce',
|
|
295
|
+
},
|
|
296
|
+
tokenizer: TOKENIZER,
|
|
297
|
+
tokenDisclaimer: 'Tokenizer counts are o200k_base encoding counts, not provider-billed usage, cache savings, or model/network cost.',
|
|
298
|
+
resourceDisclaimer: 'RSS maximum is the larger of before/after observations, not a continuously sampled instantaneous peak or incremental ACE-only allocation.',
|
|
299
|
+
serializationDisclaimer: 'Serialized request/result metrics are operational protocol overhead and are reported separately from model-context accounting.',
|
|
300
|
+
},
|
|
301
|
+
environment: {
|
|
302
|
+
platform: os.platform(),
|
|
303
|
+
release: os.release(),
|
|
304
|
+
arch: os.arch(),
|
|
305
|
+
node: process.version,
|
|
306
|
+
cpuModel: os.cpus()[0]?.model ?? null,
|
|
307
|
+
logicalCpuCount: os.cpus().length,
|
|
308
|
+
totalMemoryBytes: os.totalmem(),
|
|
309
|
+
hostLoadBefore,
|
|
310
|
+
},
|
|
311
|
+
correctness: correctnessChecks(),
|
|
312
|
+
fixtures: fixtureResults,
|
|
313
|
+
headroom: {
|
|
314
|
+
version: '0.37.0',
|
|
315
|
+
status: 'NOT_RUN',
|
|
316
|
+
comparability: 'BLOCKED',
|
|
317
|
+
reason: 'The installed interface exposes a provider proxy and evaluation commands over LLM or recorded-session workflows, not a standalone equivalent context transform. A run would require new proxy/upstream routing, credentials or a non-equivalent dummy protocol and could touch external model/cache state. Existing configured routing and private sessions were intentionally not used.',
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
evidence.environment.hostLoadAfter = await sampleHostLoad();
|
|
321
|
+
evidence.evidenceIdentity = sha256(JSON.stringify({ ...evidence, generatedAt: null, environment: { ...evidence.environment, totalMemoryBytes: null } }));
|
|
322
|
+
const serialized = `${JSON.stringify(evidence, null, 2)}\n`;
|
|
323
|
+
const summary = JSON.stringify({
|
|
324
|
+
schema: evidence.schema,
|
|
325
|
+
foundationSourceSha: evidence.foundationSourceSha,
|
|
326
|
+
benchmarkToolingIdentity: evidence.benchmarkToolingIdentity,
|
|
327
|
+
fixtureCount: evidence.fixtures.length,
|
|
328
|
+
sampleCount: evidence.fixtures.length * 2 * options.sampleCount,
|
|
329
|
+
correctness: [...new Set(Object.values(evidence.correctness))],
|
|
330
|
+
headroomComparability: evidence.headroom.comparability,
|
|
331
|
+
evidenceIdentity: evidence.evidenceIdentity,
|
|
332
|
+
});
|
|
333
|
+
if (options.output) {
|
|
334
|
+
fs.mkdirSync(path.dirname(path.resolve(options.output)), { recursive: true });
|
|
335
|
+
fs.writeFileSync(options.output, serialized, { encoding: 'utf8', flag: 'wx' });
|
|
336
|
+
process.stdout.write(`${summary}\n`);
|
|
337
|
+
} else if (options.summaryOnly) {
|
|
338
|
+
process.stdout.write(`${summary}\n`);
|
|
339
|
+
} else {
|
|
340
|
+
process.stdout.write(serialized);
|
|
341
|
+
}
|
|
342
|
+
encoder.free?.();
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { performance } from 'node:perf_hooks';
|
|
6
|
+
import { fixtureById } from '../benchmark/fixtures.mjs';
|
|
7
|
+
import { AfyxContextEngine } from '../src/index.js';
|
|
8
|
+
|
|
9
|
+
function readRequest() {
|
|
10
|
+
const source = fs.readFileSync(0, 'utf8');
|
|
11
|
+
const request = JSON.parse(source);
|
|
12
|
+
if (!['cold', 'warm'].includes(request.mode)) throw new Error(`invalid worker mode: ${request.mode}`);
|
|
13
|
+
return request;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function selectRecoveryItems(fixture, items) {
|
|
17
|
+
const references = items.filter((item) => item.disposition === 'reference');
|
|
18
|
+
if (fixture.recovery === 'all-references') return references;
|
|
19
|
+
if (fixture.recovery === 'first-reference') return references.slice(0, 1);
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const request = readRequest();
|
|
24
|
+
const fixture = fixtureById(request.fixtureId);
|
|
25
|
+
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'afyx-291-worker-'));
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const ownerId = 'afyx-291-benchmark-owner';
|
|
29
|
+
const sessionId = `${fixture.id}-${request.mode}`;
|
|
30
|
+
const rssBefore = process.memoryUsage().rss;
|
|
31
|
+
const heapBefore = process.memoryUsage().heapUsed;
|
|
32
|
+
const cpuBefore = process.cpuUsage();
|
|
33
|
+
const constructStarted = performance.now();
|
|
34
|
+
const engine = new AfyxContextEngine({ stateDir, ownerId, sessionId });
|
|
35
|
+
const constructionMs = performance.now() - constructStarted;
|
|
36
|
+
const reduceRequest = { segments: fixture.segments, budgetChars: fixture.budgetChars };
|
|
37
|
+
if (request.mode === 'warm') engine.reduce(reduceRequest);
|
|
38
|
+
const reduceStarted = performance.now();
|
|
39
|
+
const result = engine.reduce(reduceRequest);
|
|
40
|
+
const reduceMs = performance.now() - reduceStarted;
|
|
41
|
+
const recoveryStarted = performance.now();
|
|
42
|
+
const recoveries = selectRecoveryItems(fixture, result.items).map((item) => {
|
|
43
|
+
const content = engine.retrieve(item.reference);
|
|
44
|
+
const expected = fixture.segments.find((segment) => segment.id === item.id)?.content;
|
|
45
|
+
if (content !== expected) throw new Error(`recovery mismatch for ${fixture.id}/${item.id}`);
|
|
46
|
+
return {
|
|
47
|
+
id: item.id,
|
|
48
|
+
reference: item.reference,
|
|
49
|
+
content,
|
|
50
|
+
digest: crypto.createHash('sha256').update(content).digest('hex'),
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
const recoveryMs = performance.now() - recoveryStarted;
|
|
54
|
+
const cpu = process.cpuUsage(cpuBefore);
|
|
55
|
+
const memoryAfter = process.memoryUsage();
|
|
56
|
+
process.stdout.write(JSON.stringify({
|
|
57
|
+
fixtureId: fixture.id,
|
|
58
|
+
mode: request.mode,
|
|
59
|
+
result,
|
|
60
|
+
recoveries,
|
|
61
|
+
timing: { constructionMs, reduceMs, recoveryMs },
|
|
62
|
+
process: {
|
|
63
|
+
rssBeforeBytes: rssBefore,
|
|
64
|
+
rssAfterBytes: memoryAfter.rss,
|
|
65
|
+
rssTwoPointObservedMaxBytes: Math.max(rssBefore, memoryAfter.rss),
|
|
66
|
+
heapUsedBeforeBytes: heapBefore,
|
|
67
|
+
heapUsedAfterBytes: memoryAfter.heapUsed,
|
|
68
|
+
cpuUserMicroseconds: cpu.user,
|
|
69
|
+
cpuSystemMicroseconds: cpu.system,
|
|
70
|
+
},
|
|
71
|
+
}));
|
|
72
|
+
} finally {
|
|
73
|
+
fs.rmSync(stateDir, { recursive: true, force: true });
|
|
74
|
+
}
|