@7h3/protocol 0.5.0 → 0.5.1
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/README.md +6 -1317
- package/agentAdapter.d.ts +26 -0
- package/auditLog.d.ts +54 -0
- package/capability.d.ts +67 -0
- package/cborCodec.d.ts +34 -0
- package/conformanceVectors.d.ts +20 -0
- package/encryption.d.ts +85 -0
- package/envelopeCbor.d.ts +33 -0
- package/frameworkAdapters.d.ts +72 -0
- package/gateway.d.ts +53 -0
- package/grpcBinding.d.ts +29 -0
- package/httpBinding.d.ts +50 -0
- package/index.d.ts +39 -0
- package/index.js +3662 -0
- package/keyInfra.d.ts +64 -0
- package/keyRegistry.d.ts +9 -0
- package/keyRotation.d.ts +20 -0
- package/mcpGateway.d.ts +37 -0
- package/mcpTransports.d.ts +62 -0
- package/mcpWrapper.d.ts +83 -0
- package/otel.d.ts +65 -0
- package/package.json +13 -121
- package/policyEnforcer.d.ts +50 -0
- package/policyTelemetryFeedback.d.ts +11 -0
- package/{src/protocol.d.ts → protocol.d.ts} +1 -2
- package/protocolAgent.d.ts +58 -0
- package/protocolBinary.d.ts +8 -0
- package/protocolCapabilities.d.ts +24 -0
- package/protocolReplay.d.ts +35 -0
- package/protocolTransport.d.ts +73 -0
- package/queueBinding.d.ts +43 -0
- package/rateLimiter.d.ts +18 -0
- package/{src/redisClient.ts → redisClient.d.ts} +25 -75
- package/replayStores.d.ts +98 -0
- package/revocation.d.ts +71 -0
- package/routePolicy.d.ts +30 -0
- package/runtimePolicy.d.ts +24 -0
- package/runtimePolicyManager.d.ts +15 -0
- package/runtimePolicyPresets.d.ts +11 -0
- package/signedResponse.d.ts +21 -0
- package/stream.d.ts +59 -0
- package/telemetry.d.ts +79 -0
- package/webhookBinding.d.ts +30 -0
- package/wsBinding.d.ts +52 -0
- package/.dockerignore +0 -19
- package/.github/dependabot.yml +0 -32
- package/.github/workflows/ci.yml +0 -31
- package/.github/workflows/publish.yml +0 -59
- package/.github/workflows/scorecard.yml +0 -37
- package/7h3.example.yaml +0 -125
- package/CHANGELOG.md +0 -152
- package/CONTRIBUTING.md +0 -82
- package/Dockerfile +0 -73
- package/GOVERNANCE.md +0 -62
- package/SECURITY.md +0 -70
- package/bench-results/replay-cache-full-1777891033256.json +0 -10
- package/bench-results/replay-cache-full-1777896317488.json +0 -10
- package/bench-results/replay-cache-full-1777900993184.json +0 -10
- package/bench-results/replay-cache-full-1777901019285.json +0 -10
- package/bench-results/replay-cache-quick-1777870170126.json +0 -10
- package/bench-results/signature-profiles-quick-1775875160079.json +0 -85
- package/bench-results/signature-profiles-quick-1775983539716.json +0 -85
- package/bench-results/signature-profiles-quick-1776237913190.json +0 -85
- package/bench-results/wire-codecs-full-1777891019803.json +0 -93
- package/bench-results/wire-codecs-full-1777896260964.json +0 -93
- package/bench-results/wire-codecs-full-1777901004247.json +0 -93
- package/bench-results/wire-codecs-quick-1775972879056.json +0 -93
- package/bench-results/wire-codecs-quick-1775983541111.json +0 -93
- package/bench-results/wire-codecs-quick-1776237914299.json +0 -93
- package/bench-results/wire-codecs-quick-1777841285236.json +0 -93
- package/bench-results/wire-codecs-quick-1777841321772.json +0 -93
- package/bench-results/wire-codecs-quick-1777841330408.json +0 -93
- package/bench-results/wire-codecs-quick-1777852886082.json +0 -93
- package/bench-results/wire-codecs-quick-1777852988773.json +0 -93
- package/bench-results/wire-codecs-quick-1777870188095.json +0 -93
- package/bench-results/wire-codecs-quick-1777870263918.json +0 -93
- package/bench-results/wire-codecs-quick-1777870455034.json +0 -93
- package/bench-results/wire-codecs-quick-1778816163081.json +0 -93
- package/bench-results/wire-codecs-quick-1778843936130.json +0 -93
- package/bin/7h3.ts +0 -406
- package/conformance/7h3_v0_1.json +0 -77
- package/conformance/7h3_v0_1_binary.json +0 -20
- package/conformance/aip_v0_1_binary.json +0 -20
- package/docker-compose.yaml +0 -77
- package/docs/ADOPTION_PLAN.md +0 -120
- package/docs/AGENTS.md +0 -77
- package/docs/AIP_RFC_v0.1.md +0 -97
- package/docs/AI_DECISION_CARD.md +0 -122
- package/docs/AI_RUNTIME_POLICY.json +0 -126
- package/docs/AI_RUNTIME_POLICY.yaml +0 -110
- package/docs/BACKPRESSURE_TUNING.md +0 -65
- package/docs/BENCHMARK_CLAIM_MATRIX.md +0 -42
- package/docs/BENCHMARK_REPORT_TEMPLATE.md +0 -169
- package/docs/BINARY_CODEC_BENCH.md +0 -23
- package/docs/CLEAN_CLONE_RUNBOOK.md +0 -36
- package/docs/CLOCK_SKEW_POLICY.md +0 -30
- package/docs/DISTRIBUTED_REPLAY.md +0 -142
- package/docs/FUZZ_CAMPAIGN.md +0 -121
- package/docs/GATEWAY.md +0 -195
- package/docs/KEY_MANAGEMENT_POLICY.md +0 -53
- package/docs/KEY_REVOCATION.md +0 -69
- package/docs/MCP_WRAPPER.md +0 -159
- package/docs/MIGRATION_GUIDE.md +0 -40
- package/docs/OPERATORS.md +0 -184
- package/docs/PERF_REGRESSION_POLICY.md +0 -34
- package/docs/PROJECT_EXAMINATION_2026-05-31.md +0 -219
- package/docs/RELEASE_BENCHMARK_REPORT_2026-05-15.md +0 -135
- package/docs/RELEASE_GATE.md +0 -25
- package/docs/RELEASE_NOTES_v0.1.0.md +0 -54
- package/docs/SECURITY_REVIEW_2026-06-05.md +0 -165
- package/docs/TELEMETRY.md +0 -41
- package/docs/THREAT_MODEL.md +0 -89
- package/docs/VERSIONING_POLICY.md +0 -30
- package/docs/assets/banner-github.png +0 -0
- package/docs/assets/banner.png +0 -0
- package/docs/assets/banner.svg +0 -123
- package/eslint.config.js +0 -15
- package/fuzz/ts/harness-decode.ts +0 -136
- package/fuzz/ts/harness-verify.ts +0 -121
- package/fuzz/ts/run.ts +0 -35
- package/mcp-server/README.md +0 -38
- package/mcp-server/package-lock.json +0 -1187
- package/mcp-server/package.json +0 -35
- package/mcp-server/src/index.ts +0 -236
- package/mcp-server/tsconfig.json +0 -14
- package/scripts/aip-framework-quickstart.ts +0 -110
- package/scripts/aip-mcp-gateway.ts +0 -38
- package/scripts/aip-mcp-wrap-demo.ts +0 -72
- package/scripts/aip-quickstart.ts +0 -60
- package/scripts/bench-diff.ts +0 -118
- package/scripts/bench-protocol-e2e.ts +0 -937
- package/scripts/bench-protocol-openloop.ts +0 -1397
- package/scripts/bench-replay-cache.ts +0 -76
- package/scripts/bench-signature-profiles.ts +0 -180
- package/scripts/bench-wire-codecs.ts +0 -161
- package/scripts/build-binary-conformance.ts +0 -36
- package/scripts/build-release-dashboard.ts +0 -175
- package/scripts/canary-rollout.ts +0 -38
- package/scripts/mcpGatewayCli.test.ts +0 -116
- package/scripts/prepare-aip-package.ts +0 -88
- package/scripts/regen-conformance-sigs.ts +0 -18
- package/scripts/release-gate.ts +0 -19
- package/scripts/validate-runtime-policy.ts +0 -18
- package/sdk/browser/index.test.ts +0 -162
- package/sdk/browser/index.ts +0 -257
- package/sdk/browser/package.json +0 -13
- package/sdk/go/cbor.go +0 -551
- package/sdk/go/cbor_test.go +0 -232
- package/sdk/go/encryption.go +0 -280
- package/sdk/go/encryption_test.go +0 -318
- package/sdk/go/go.mod +0 -7
- package/sdk/go/go.sum +0 -4
- package/sdk/go/http.go +0 -135
- package/sdk/go/protocol.go +0 -324
- package/sdk/go/protocol_test.go +0 -334
- package/sdk/go/replay.go +0 -121
- package/sdk/go/replay_test.go +0 -149
- package/sdk/go/webhook.go +0 -136
- package/sdk/pq/package-lock.json +0 -1358
- package/sdk/pq/package.json +0 -42
- package/sdk/pq/src/index.test.ts +0 -143
- package/sdk/pq/src/index.ts +0 -166
- package/sdk/pq/tsconfig.json +0 -14
- package/sdk/pq/vitest.config.ts +0 -7
- package/sdk/python/README.md +0 -18
- package/sdk/python/protocol_7h3/__init__.py +0 -46
- package/sdk/python/protocol_7h3/encryption.py +0 -252
- package/sdk/python/protocol_7h3/http.py +0 -212
- package/sdk/python/protocol_7h3/keys.py +0 -149
- package/sdk/python/protocol_7h3/pq.py +0 -244
- package/sdk/python/protocol_7h3/protocol.py +0 -525
- package/sdk/python/protocol_7h3/queue.py +0 -118
- package/sdk/python/protocol_7h3/replay.py +0 -98
- package/sdk/python/protocol_7h3/webhook.py +0 -116
- package/sdk/python/pyproject.toml +0 -40
- package/sdk/python/tests/test_conformance.py +0 -110
- package/sdk/python/tests/test_encryption.py +0 -206
- package/sdk/python/tests/test_http.py +0 -305
- package/sdk/python/tests/test_keys.py +0 -417
- package/sdk/python/tests/test_queue.py +0 -120
- package/sdk/python/tests/test_webhook.py +0 -345
- package/sdk/rust/Cargo.lock +0 -371
- package/sdk/rust/Cargo.toml +0 -25
- package/sdk/rust/README.md +0 -31
- package/sdk/rust/fuzz/Cargo.toml +0 -29
- package/sdk/rust/fuzz/fuzz_targets/fuzz_canonicalize.rs +0 -46
- package/sdk/rust/fuzz/fuzz_targets/fuzz_decode.rs +0 -11
- package/sdk/rust/src/bin/aip_mcp_gateway.rs +0 -59
- package/sdk/rust/src/http.rs +0 -145
- package/sdk/rust/src/keys.rs +0 -161
- package/sdk/rust/src/lib.rs +0 -688
- package/sdk/rust/src/queue.rs +0 -79
- package/sdk/rust/src/webhook.rs +0 -86
- package/sdk/rust/tests/conformance.rs +0 -148
- package/sdk/rust/tests/gateway.rs +0 -130
- package/sdk/rust/tests/http_webhook_queue.rs +0 -201
- package/sdk/rust/tests/keys.rs +0 -189
- package/sdk/threshold/index.d.ts +0 -68
- package/sdk/threshold/index.d.ts.map +0 -1
- package/sdk/threshold/index.js +0 -254
- package/sdk/threshold/package-lock.json +0 -1361
- package/sdk/threshold/package.json +0 -39
- package/sdk/threshold/src/index.d.ts +0 -68
- package/sdk/threshold/src/index.d.ts.map +0 -1
- package/sdk/threshold/src/index.js +0 -254
- package/sdk/threshold/src/index.test.ts +0 -238
- package/sdk/threshold/src/index.ts +0 -355
- package/sdk/threshold/tsconfig.json +0 -19
- package/sdk/threshold/vitest.config.ts +0 -12
- package/src/agentAdapter.test.ts +0 -48
- package/src/agentAdapter.ts +0 -56
- package/src/auditLog.test.ts +0 -145
- package/src/auditLog.ts +0 -147
- package/src/capability.test.ts +0 -504
- package/src/capability.ts +0 -380
- package/src/cborCodec.test.ts +0 -263
- package/src/cborCodec.ts +0 -339
- package/src/conformance.test.ts +0 -136
- package/src/conformanceVectors.ts +0 -99
- package/src/encryption.test.ts +0 -206
- package/src/encryption.ts +0 -245
- package/src/envelopeCbor.ts +0 -140
- package/src/frameworkAdapters.test.ts +0 -290
- package/src/frameworkAdapters.ts +0 -261
- package/src/gateway.test.ts +0 -343
- package/src/gateway.ts +0 -246
- package/src/grpcBinding.test.ts +0 -211
- package/src/grpcBinding.ts +0 -103
- package/src/httpBinding.test.ts +0 -376
- package/src/httpBinding.ts +0 -189
- package/src/index.ts +0 -39
- package/src/keyInfra.test.ts +0 -278
- package/src/keyInfra.ts +0 -228
- package/src/keyRegistry.ts +0 -59
- package/src/keyRotation.test.ts +0 -78
- package/src/keyRotation.ts +0 -72
- package/src/mcpGateway.test.ts +0 -129
- package/src/mcpGateway.ts +0 -250
- package/src/mcpTransports.test.ts +0 -92
- package/src/mcpTransports.ts +0 -169
- package/src/mcpWrapper.test.ts +0 -179
- package/src/mcpWrapper.ts +0 -206
- package/src/otel.ts +0 -136
- package/src/policyEnforcer.test.ts +0 -99
- package/src/policyEnforcer.ts +0 -169
- package/src/policyTelemetryFeedback.test.ts +0 -25
- package/src/policyTelemetryFeedback.ts +0 -38
- package/src/protocol.bench.ts +0 -37
- package/src/protocol.d.ts.map +0 -1
- package/src/protocol.js +0 -294
- package/src/protocol.test.ts +0 -155
- package/src/protocol.ts +0 -414
- package/src/protocolAgent.test.ts +0 -105
- package/src/protocolAgent.ts +0 -169
- package/src/protocolBinary.test.ts +0 -165
- package/src/protocolBinary.ts +0 -312
- package/src/protocolCapabilities.ts +0 -70
- package/src/protocolFuzz.advanced.test.ts +0 -235
- package/src/protocolFuzz.test.ts +0 -111
- package/src/protocolNegative.test.ts +0 -97
- package/src/protocolReplay.test.ts +0 -71
- package/src/protocolReplay.ts +0 -194
- package/src/protocolTransport.test.ts +0 -556
- package/src/protocolTransport.ts +0 -483
- package/src/queueBinding.test.ts +0 -130
- package/src/queueBinding.ts +0 -102
- package/src/rateLimiter.test.ts +0 -96
- package/src/rateLimiter.ts +0 -46
- package/src/redisIntegration.test.ts +0 -134
- package/src/replayStores.test.ts +0 -273
- package/src/replayStores.ts +0 -215
- package/src/revocation.test.ts +0 -98
- package/src/revocation.ts +0 -0
- package/src/routePolicy.test.ts +0 -87
- package/src/routePolicy.ts +0 -72
- package/src/runtimePolicy.test.ts +0 -49
- package/src/runtimePolicy.ts +0 -81
- package/src/runtimePolicyManager.test.ts +0 -29
- package/src/runtimePolicyManager.ts +0 -50
- package/src/runtimePolicyPresets.ts +0 -43
- package/src/signedResponse.test.ts +0 -111
- package/src/signedResponse.ts +0 -83
- package/src/stream.test.ts +0 -254
- package/src/stream.ts +0 -417
- package/src/telemetry.test.ts +0 -251
- package/src/telemetry.ts +0 -299
- package/src/webhookBinding.test.ts +0 -144
- package/src/webhookBinding.ts +0 -115
- package/src/wsBinding.test.ts +0 -221
- package/src/wsBinding.ts +0 -200
- package/tsconfig.json +0 -15
- package/tsconfig.lib.json +0 -23
- package/vite.lib.config.ts +0 -16
- package/vitest.config.ts +0 -11
package/mcp-server/package.json
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@7h3/protocol-mcp",
|
|
3
|
-
"version": "0.1.1",
|
|
4
|
-
"description": "MCP server for @7h3/protocol — install into Claude to generate AIP secrets, keypairs, and server boilerplate",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"aip-mcp": "./dist/index.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"README.md"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc",
|
|
15
|
-
"start": "node dist/index.js",
|
|
16
|
-
"prepublishOnly": "npm run build"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@7h3/protocol": "^0.1.0",
|
|
20
|
-
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
21
|
-
"zod": "^4.0.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"typescript": "^6.0.3"
|
|
25
|
-
},
|
|
26
|
-
"engines": {
|
|
27
|
-
"node": ">=20"
|
|
28
|
-
},
|
|
29
|
-
"license": "MIT",
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "https://github.com/IceMasterT/7h3-protocol-aip.git",
|
|
33
|
-
"directory": "mcp-server"
|
|
34
|
-
}
|
|
35
|
-
}
|
package/mcp-server/src/index.ts
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
4
|
-
import { z } from 'zod'
|
|
5
|
-
import {
|
|
6
|
-
generateEd25519KeypairBase64Url,
|
|
7
|
-
createEnvelope,
|
|
8
|
-
signEnvelopeHmac,
|
|
9
|
-
signEnvelopeEd25519,
|
|
10
|
-
verifyEnvelopeHmac,
|
|
11
|
-
verifyEnvelopeEd25519,
|
|
12
|
-
validateEnvelope,
|
|
13
|
-
} from '@7h3/protocol'
|
|
14
|
-
import { randomBytes } from 'node:crypto'
|
|
15
|
-
|
|
16
|
-
const server = new McpServer({ name: '@7h3/protocol-mcp', version: '0.1.0' })
|
|
17
|
-
|
|
18
|
-
// ── aip_generate_secret ───────────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
server.registerTool(
|
|
21
|
-
'aip_generate_secret',
|
|
22
|
-
{
|
|
23
|
-
description: 'Generate a cryptographically random 32-byte HMAC secret for AIP message signing. Returns the value to store as AIP_SECRET.',
|
|
24
|
-
},
|
|
25
|
-
async () => {
|
|
26
|
-
const secret = randomBytes(32).toString('base64url')
|
|
27
|
-
return {
|
|
28
|
-
content: [{
|
|
29
|
-
type: 'text',
|
|
30
|
-
text: JSON.stringify({
|
|
31
|
-
secret,
|
|
32
|
-
envVar: 'AIP_SECRET',
|
|
33
|
-
warning: 'Never commit this value. Add to .env and .gitignore.',
|
|
34
|
-
}, null, 2),
|
|
35
|
-
}],
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
// ── aip_generate_keypair ──────────────────────────────────────────────────────
|
|
41
|
-
|
|
42
|
-
server.registerTool(
|
|
43
|
-
'aip_generate_keypair',
|
|
44
|
-
{
|
|
45
|
-
description: 'Generate an Ed25519 keypair for AIP message signing. Returns publicKey (safe to share) and privateKey (keep secret).',
|
|
46
|
-
},
|
|
47
|
-
async () => {
|
|
48
|
-
const keypair = await generateEd25519KeypairBase64Url()
|
|
49
|
-
return {
|
|
50
|
-
content: [{
|
|
51
|
-
type: 'text',
|
|
52
|
-
text: JSON.stringify({
|
|
53
|
-
publicKey: keypair.publicKey,
|
|
54
|
-
privateKey: keypair.privateKey,
|
|
55
|
-
envVars: { privateKey: 'AIP_PRIVATE_KEY', publicKey: 'AIP_PUBLIC_KEY' },
|
|
56
|
-
warning: 'Never commit privateKey. Share publicKey with peers who need to verify your messages.',
|
|
57
|
-
}, null, 2),
|
|
58
|
-
}],
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
// ── aip_wrap_mcp_server ───────────────────────────────────────────────────────
|
|
64
|
-
|
|
65
|
-
server.registerTool(
|
|
66
|
-
'aip_wrap_mcp_server',
|
|
67
|
-
{
|
|
68
|
-
description: 'Generate ready-to-paste TypeScript boilerplate to wrap an existing MCP server handler with AIP signing and replay protection. Zero changes to your handler required.',
|
|
69
|
-
inputSchema: {
|
|
70
|
-
serverAgentId: z.string().describe('Unique ID for this server agent, e.g. "my-tool-server"'),
|
|
71
|
-
clientAgentId: z.string().optional().describe('Expected client agent ID for sender binding. Omit to accept any signed client.'),
|
|
72
|
-
transport: z.enum(['stdio', 'http']).optional().describe('Transport type. Default: stdio'),
|
|
73
|
-
signingMethod: z.enum(['hmac', 'ed25519']).optional().describe('Signing algorithm. hmac = shared secret (dev/trusted infra), ed25519 = keypair (recommended for production). Default: hmac'),
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
async ({ serverAgentId, clientAgentId, transport = 'stdio', signingMethod = 'hmac' }) => {
|
|
77
|
-
return {
|
|
78
|
-
content: [{ type: 'text', text: buildBoilerplate(serverAgentId, clientAgentId, transport, signingMethod) }],
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
// ── aip_sign ──────────────────────────────────────────────────────────────────
|
|
84
|
-
|
|
85
|
-
server.registerTool(
|
|
86
|
-
'aip_sign',
|
|
87
|
-
{
|
|
88
|
-
description: 'Sign a test AIP envelope. Useful for debugging or generating test fixtures.',
|
|
89
|
-
inputSchema: {
|
|
90
|
-
senderAgentId: z.string(),
|
|
91
|
-
content: z.string().describe('Message content — plain text or JSON string'),
|
|
92
|
-
signingMethod: z.enum(['hmac', 'ed25519']),
|
|
93
|
-
secret: z.string().optional().describe('HMAC secret — required when signingMethod=hmac'),
|
|
94
|
-
privateKey: z.string().optional().describe('Ed25519 private key base64url — required when signingMethod=ed25519'),
|
|
95
|
-
recipientAgentId: z.string().optional(),
|
|
96
|
-
keyId: z.string().optional().describe('Key identifier label. Default: k1'),
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
async ({ senderAgentId, content, signingMethod, secret, privateKey, recipientAgentId, keyId = 'k1' }) => {
|
|
100
|
-
try {
|
|
101
|
-
const envelope = createEnvelope({ sender: senderAgentId, recipient: recipientAgentId, intent: 'TASK', content })
|
|
102
|
-
let signed
|
|
103
|
-
if (signingMethod === 'hmac') {
|
|
104
|
-
if (!secret) throw new Error('secret is required for hmac signing')
|
|
105
|
-
signed = await signEnvelopeHmac(envelope, secret, keyId)
|
|
106
|
-
} else {
|
|
107
|
-
if (!privateKey) throw new Error('privateKey is required for ed25519 signing')
|
|
108
|
-
signed = await signEnvelopeEd25519(envelope, privateKey, keyId)
|
|
109
|
-
}
|
|
110
|
-
return { content: [{ type: 'text', text: JSON.stringify(signed, null, 2) }] }
|
|
111
|
-
} catch (err) {
|
|
112
|
-
return { content: [{ type: 'text', text: `Error: ${err instanceof Error ? err.message : String(err)}` }], isError: true }
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
// ── aip_verify ────────────────────────────────────────────────────────────────
|
|
118
|
-
|
|
119
|
-
server.registerTool(
|
|
120
|
-
'aip_verify',
|
|
121
|
-
{
|
|
122
|
-
description: 'Verify an AIP envelope signature and validate its shape, TTL, and version.',
|
|
123
|
-
inputSchema: {
|
|
124
|
-
envelopeJson: z.string().describe('JSON string of the AIP envelope to verify'),
|
|
125
|
-
signingMethod: z.enum(['hmac', 'ed25519']),
|
|
126
|
-
secret: z.string().optional().describe('HMAC secret — required when signingMethod=hmac'),
|
|
127
|
-
publicKey: z.string().optional().describe('Ed25519 public key base64url — required when signingMethod=ed25519'),
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
async ({ envelopeJson, signingMethod, secret, publicKey }) => {
|
|
131
|
-
try {
|
|
132
|
-
let envelope: unknown
|
|
133
|
-
try {
|
|
134
|
-
envelope = JSON.parse(envelopeJson)
|
|
135
|
-
} catch {
|
|
136
|
-
throw new Error('envelopeJson is not valid JSON')
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const validationErrors = validateEnvelope(envelope as Parameters<typeof validateEnvelope>[0])
|
|
140
|
-
let sigValid = false
|
|
141
|
-
|
|
142
|
-
if (signingMethod === 'hmac') {
|
|
143
|
-
if (!secret) throw new Error('secret is required for hmac verification')
|
|
144
|
-
sigValid = await verifyEnvelopeHmac(envelope as Parameters<typeof verifyEnvelopeHmac>[0], secret)
|
|
145
|
-
} else {
|
|
146
|
-
if (!publicKey) throw new Error('publicKey is required for ed25519 verification')
|
|
147
|
-
sigValid = await verifyEnvelopeEd25519(envelope as Parameters<typeof verifyEnvelopeEd25519>[0], publicKey)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
content: [{
|
|
152
|
-
type: 'text',
|
|
153
|
-
text: JSON.stringify({
|
|
154
|
-
signatureValid: sigValid,
|
|
155
|
-
validationErrors,
|
|
156
|
-
result: sigValid && validationErrors.length === 0 ? 'PASS' : 'FAIL',
|
|
157
|
-
}, null, 2),
|
|
158
|
-
}],
|
|
159
|
-
}
|
|
160
|
-
} catch (err) {
|
|
161
|
-
return { content: [{ type: 'text', text: `Error: ${err instanceof Error ? err.message : String(err)}` }], isError: true }
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
// ── boilerplate generator ─────────────────────────────────────────────────────
|
|
167
|
-
|
|
168
|
-
function buildBoilerplate(
|
|
169
|
-
serverAgentId: string,
|
|
170
|
-
clientAgentId: string | undefined,
|
|
171
|
-
transport: 'stdio' | 'http',
|
|
172
|
-
signingMethod: 'hmac' | 'ed25519',
|
|
173
|
-
): string {
|
|
174
|
-
const imports = signingMethod === 'hmac'
|
|
175
|
-
? `import { wrapMcpServer, serveMcpOverStdio, signEnvelopeHmac } from '@7h3/protocol'`
|
|
176
|
-
: `import { wrapMcpServer, serveMcpOverStdio, signEnvelopeEd25519 } from '@7h3/protocol'`
|
|
177
|
-
|
|
178
|
-
const envBlock = signingMethod === 'hmac'
|
|
179
|
-
? `const SECRET = process.env.AIP_SECRET ?? 'REPLACE_ME'`
|
|
180
|
-
: `const PRIVATE_KEY = process.env.AIP_PRIVATE_KEY ?? 'REPLACE_ME'
|
|
181
|
-
const CLIENT_PUBLIC_KEY = process.env.AIP_CLIENT_PUBLIC_KEY ?? 'REPLACE_ME'`
|
|
182
|
-
|
|
183
|
-
const signFn = signingMethod === 'hmac'
|
|
184
|
-
? `(e) => signEnvelopeHmac(e, SECRET, 'k1')`
|
|
185
|
-
: `(e) => signEnvelopeEd25519(e, PRIVATE_KEY, 'k1')`
|
|
186
|
-
|
|
187
|
-
const receiveBlock = signingMethod === 'hmac'
|
|
188
|
-
? `receive: { secretResolver: async () => SECRET }`
|
|
189
|
-
: `receive: {
|
|
190
|
-
signatureResolver: async (sig) =>
|
|
191
|
-
sig.alg === 'ED25519' ? { alg: 'ED25519' as const, publicKey: CLIENT_PUBLIC_KEY } : undefined,
|
|
192
|
-
}`
|
|
193
|
-
|
|
194
|
-
const peerLine = clientAgentId ? `\n peerAgentId: '${clientAgentId}',` : ''
|
|
195
|
-
|
|
196
|
-
const wrapCall = `wrapMcpServer(myHandler, {
|
|
197
|
-
selfAgentId: '${serverAgentId}',${peerLine}
|
|
198
|
-
sign: ${signFn},
|
|
199
|
-
${receiveBlock},
|
|
200
|
-
})`
|
|
201
|
-
|
|
202
|
-
const transportBlock = transport === 'stdio'
|
|
203
|
-
? `serveMcpOverStdio(${wrapCall})`
|
|
204
|
-
: `import { createHttpMcpHandler } from '@7h3/protocol'
|
|
205
|
-
import http from 'node:http'
|
|
206
|
-
|
|
207
|
-
const handler = createHttpMcpHandler(${wrapCall})
|
|
208
|
-
|
|
209
|
-
http.createServer((req, res) => {
|
|
210
|
-
if (req.method === 'POST' && req.url === '/mcp') return handler(req, res)
|
|
211
|
-
res.writeHead(404).end()
|
|
212
|
-
}).listen(3000)`
|
|
213
|
-
|
|
214
|
-
const productionNote = signingMethod === 'hmac'
|
|
215
|
-
? `// For production, use Ed25519 (run aip_generate_keypair and regenerate with signingMethod='ed25519')\n`
|
|
216
|
-
: ''
|
|
217
|
-
|
|
218
|
-
return `// AIP-hardened MCP server — generated by @7h3/protocol-mcp
|
|
219
|
-
// Install: npm install @7h3/protocol
|
|
220
|
-
${imports}
|
|
221
|
-
|
|
222
|
-
${productionNote}${envBlock}
|
|
223
|
-
|
|
224
|
-
// Your existing JSON-RPC handler — zero changes needed here
|
|
225
|
-
async function myHandler(request: unknown): Promise<unknown> {
|
|
226
|
-
throw new Error('Replace with your handler logic')
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
${transportBlock}
|
|
230
|
-
`
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// ── start ─────────────────────────────────────────────────────────────────────
|
|
234
|
-
|
|
235
|
-
const transport = new StdioServerTransport()
|
|
236
|
-
await server.connect(transport)
|
package/mcp-server/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src"]
|
|
14
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createAipAgentAdapter,
|
|
3
|
-
createRawTaskFromJsonRpc,
|
|
4
|
-
createRawTaskFromLangChain,
|
|
5
|
-
createRawTaskFromLlamaIndex,
|
|
6
|
-
toJsonRpcResponse,
|
|
7
|
-
toLangChainMessage,
|
|
8
|
-
toLlamaIndexMessage,
|
|
9
|
-
type JsonRpcRequestLike,
|
|
10
|
-
} from '../src'
|
|
11
|
-
|
|
12
|
-
function printSection(title: string): void {
|
|
13
|
-
console.log(`\n=== ${title} ===`)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function run(): Promise<void> {
|
|
17
|
-
const sharedSecret = 'framework-quickstart-secret'
|
|
18
|
-
|
|
19
|
-
const orchestrator = createAipAgentAdapter({
|
|
20
|
-
agentId: 'agent.orchestrator',
|
|
21
|
-
outboundSecret: sharedSecret,
|
|
22
|
-
sharedSecrets: { 'agent.worker': sharedSecret },
|
|
23
|
-
wireFormat: 'compact',
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const worker = createAipAgentAdapter({
|
|
27
|
-
agentId: 'agent.worker',
|
|
28
|
-
outboundSecret: sharedSecret,
|
|
29
|
-
sharedSecrets: { 'agent.orchestrator': sharedSecret },
|
|
30
|
-
wireFormat: 'compact',
|
|
31
|
-
onTask: async (envelope) => {
|
|
32
|
-
if (envelope.body.capability?.startsWith('mcp.')) {
|
|
33
|
-
return {
|
|
34
|
-
intent: 'RESULT',
|
|
35
|
-
content: JSON.stringify({ ok: true, capability: envelope.body.capability }),
|
|
36
|
-
capability: envelope.body.capability,
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
intent: 'RESULT',
|
|
42
|
-
content: `processed:${envelope.body.content}`,
|
|
43
|
-
capability: envelope.body.capability,
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
printSection('LangChain bridge')
|
|
49
|
-
const lcRaw = await createRawTaskFromLangChain(
|
|
50
|
-
orchestrator,
|
|
51
|
-
{ content: 'plan city route', name: 'human' },
|
|
52
|
-
{ recipient: 'agent.worker', capability: 'task.plan' },
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
let lcRawResponse = ''
|
|
56
|
-
await worker.handleRaw(lcRaw, async (rawResponse) => {
|
|
57
|
-
lcRawResponse = rawResponse
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
const lcVerified = await orchestrator.receiveRaw(lcRawResponse)
|
|
61
|
-
if (!lcVerified.ok || !lcVerified.received) {
|
|
62
|
-
throw new Error('LangChain bridge verification failed')
|
|
63
|
-
}
|
|
64
|
-
console.log(toLangChainMessage(lcVerified.received))
|
|
65
|
-
|
|
66
|
-
printSection('LlamaIndex bridge')
|
|
67
|
-
const liRaw = await createRawTaskFromLlamaIndex(
|
|
68
|
-
orchestrator,
|
|
69
|
-
{ role: 'user', content: 'summarize this transcript' },
|
|
70
|
-
{ recipient: 'agent.worker', capability: 'task.summarize' },
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
let liRawResponse = ''
|
|
74
|
-
await worker.handleRaw(liRaw, async (rawResponse) => {
|
|
75
|
-
liRawResponse = rawResponse
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
const liVerified = await orchestrator.receiveRaw(liRawResponse)
|
|
79
|
-
if (!liVerified.ok || !liVerified.received) {
|
|
80
|
-
throw new Error('LlamaIndex bridge verification failed')
|
|
81
|
-
}
|
|
82
|
-
console.log(toLlamaIndexMessage(liVerified.received))
|
|
83
|
-
|
|
84
|
-
printSection('JSON-RPC / MCP-like bridge')
|
|
85
|
-
const request: JsonRpcRequestLike = {
|
|
86
|
-
jsonrpc: '2.0',
|
|
87
|
-
id: 42,
|
|
88
|
-
method: 'tools/call',
|
|
89
|
-
params: { name: 'planner', input: 'optimize graph' },
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const mcpRaw = await createRawTaskFromJsonRpc(orchestrator, request, { recipient: 'agent.worker' })
|
|
93
|
-
|
|
94
|
-
let mcpRawResponse = ''
|
|
95
|
-
await worker.handleRaw(mcpRaw, async (rawResponse) => {
|
|
96
|
-
mcpRawResponse = rawResponse
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
const mcpVerified = await orchestrator.receiveRaw(mcpRawResponse)
|
|
100
|
-
if (!mcpVerified.ok || !mcpVerified.received) {
|
|
101
|
-
throw new Error('JSON-RPC bridge verification failed')
|
|
102
|
-
}
|
|
103
|
-
console.log(toJsonRpcResponse(mcpVerified.received, request.id))
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
run().catch((error: unknown) => {
|
|
107
|
-
const message = error instanceof Error ? error.stack ?? error.message : String(error)
|
|
108
|
-
console.error(message)
|
|
109
|
-
process.exitCode = 1
|
|
110
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import readline from 'node:readline'
|
|
2
|
-
import { createAipMcpGatewayRuntime } from '../src'
|
|
3
|
-
|
|
4
|
-
function parseAllowedMethodsFromEnv(): string[] {
|
|
5
|
-
const value = process.env.AIP_ALLOWED_METHODS
|
|
6
|
-
if (!value) return ['tools/call', 'resources/read', 'prompts/get']
|
|
7
|
-
|
|
8
|
-
return value
|
|
9
|
-
.split(',')
|
|
10
|
-
.map((part) => part.trim())
|
|
11
|
-
.filter((part) => part.length > 0)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function run(): Promise<void> {
|
|
15
|
-
const sharedSecret = process.env.AIP_SHARED_SECRET ?? 'mcp-gateway-secret'
|
|
16
|
-
const runtime = createAipMcpGatewayRuntime({
|
|
17
|
-
sharedSecret,
|
|
18
|
-
allowedMethods: parseAllowedMethodsFromEnv(),
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
const rl = readline.createInterface({
|
|
22
|
-
input: process.stdin,
|
|
23
|
-
crlfDelay: Infinity,
|
|
24
|
-
terminal: false,
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
for await (const line of rl) {
|
|
28
|
-
const responseLine = await runtime.handleLine(line)
|
|
29
|
-
if (responseLine === null) continue
|
|
30
|
-
process.stdout.write(`${responseLine}\n`)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
run().catch((error: unknown) => {
|
|
35
|
-
const message = error instanceof Error ? error.stack ?? error.message : String(error)
|
|
36
|
-
console.error(message)
|
|
37
|
-
process.exitCode = 1
|
|
38
|
-
})
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Demo: harden an existing MCP server with AIP in a few lines.
|
|
3
|
-
*
|
|
4
|
-
* The "real" MCP server below is an ordinary JSON-RPC handler — it is NOT aware
|
|
5
|
-
* of AIP. We wrap it with `wrapMcpServer`, drive it through `createMcpClientCodec`,
|
|
6
|
-
* and show that a clean call succeeds while a tampered or replayed message is
|
|
7
|
-
* rejected before the handler ever runs.
|
|
8
|
-
*
|
|
9
|
-
* npx tsx scripts/aip-mcp-wrap-demo.ts
|
|
10
|
-
*/
|
|
11
|
-
import { signEnvelopeHmac } from '../src/protocol'
|
|
12
|
-
import { InMemoryReplayCache } from '../src/protocolReplay'
|
|
13
|
-
import type { WireEnvelope } from '../src/protocolTransport'
|
|
14
|
-
import { createMcpClientCodec, wrapMcpServer, type JsonRpcRequest } from '../src/mcpWrapper'
|
|
15
|
-
|
|
16
|
-
const SECRET = 'demo-shared-secret'
|
|
17
|
-
|
|
18
|
-
// ── An existing MCP server. Plain JSON-RPC. No AIP awareness. ────────────────
|
|
19
|
-
async function realMcpServer(request: JsonRpcRequest) {
|
|
20
|
-
if (request.method === 'tools/call') {
|
|
21
|
-
const params = (request.params ?? {}) as { name?: string }
|
|
22
|
-
return { jsonrpc: '2.0' as const, id: request.id, result: { tool: params.name, output: `ran ${params.name}` } }
|
|
23
|
-
}
|
|
24
|
-
return { jsonrpc: '2.0' as const, id: request.id, error: { code: -32601, message: 'Method not found' } }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function main(): Promise<void> {
|
|
28
|
-
const replayCache = new InMemoryReplayCache()
|
|
29
|
-
|
|
30
|
-
// ── Wrap the server: every message is verified + signed on the wire. ───────
|
|
31
|
-
const securedServer = wrapMcpServer(realMcpServer, {
|
|
32
|
-
selfAgentId: 'agent.mcp-server',
|
|
33
|
-
sign: (envelope) => signEnvelopeHmac(envelope, SECRET, 'server-k1'),
|
|
34
|
-
receive: { secretResolver: async () => SECRET, replayCache },
|
|
35
|
-
wireFormat: 'json',
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const codec = createMcpClientCodec({
|
|
39
|
-
selfAgentId: 'agent.mcp-client',
|
|
40
|
-
peerAgentId: 'agent.mcp-server',
|
|
41
|
-
sign: (envelope) => signEnvelopeHmac(envelope, SECRET, 'client-k1'),
|
|
42
|
-
receive: { secretResolver: async () => SECRET },
|
|
43
|
-
wireFormat: 'json',
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// 1) Clean call ────────────────────────────────────────────────────────────
|
|
47
|
-
const clean = await codec.encodeRequest({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'planner' } })
|
|
48
|
-
const cleanResult = await codec.decodeResponse(await securedServer(clean.raw), { expectCorrelationId: clean.messageId })
|
|
49
|
-
console.log('[1] clean call ->', JSON.stringify(cleanResult))
|
|
50
|
-
|
|
51
|
-
// 2) Tampered call ───────────────────────────────────────────────────────── (attacker edits the signed body in flight)
|
|
52
|
-
const victim = await codec.encodeRequest({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'planner' } })
|
|
53
|
-
const tampered = ((): WireEnvelope => {
|
|
54
|
-
const env = JSON.parse(victim.raw as string)
|
|
55
|
-
env.body.content = env.body.content.replace('planner', 'rm -rf /') // swap the tool
|
|
56
|
-
return JSON.stringify(env)
|
|
57
|
-
})()
|
|
58
|
-
const tamperedResult = await codec.decodeResponse(await securedServer(tampered))
|
|
59
|
-
console.log('[2] tampered call ->', JSON.stringify(tamperedResult), '(rejected: signature no longer matches)')
|
|
60
|
-
|
|
61
|
-
// 3) Replayed call ──────────────────────────────────────────────────────── (attacker re-sends a previously valid message)
|
|
62
|
-
const once = await codec.encodeRequest({ jsonrpc: '2.0', id: 3, method: 'tools/call', params: { name: 'deploy' } })
|
|
63
|
-
const firstResult = await codec.decodeResponse(await securedServer(once.raw))
|
|
64
|
-
const replayResult = await codec.decodeResponse(await securedServer(once.raw))
|
|
65
|
-
console.log('[3] first delivery ->', JSON.stringify(firstResult))
|
|
66
|
-
console.log('[3] replayed delivery ->', JSON.stringify(replayResult), '(rejected: messageId/nonce already consumed)')
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
main().catch((error: unknown) => {
|
|
70
|
-
console.error(error instanceof Error ? error.stack ?? error.message : String(error))
|
|
71
|
-
process.exitCode = 1
|
|
72
|
-
})
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { AgentSession } from '../src/protocolAgent'
|
|
2
|
-
import { encodeEnvelope } from '../src/protocolTransport'
|
|
3
|
-
|
|
4
|
-
function printExchange(label: string, raw: string): void {
|
|
5
|
-
console.log(`\n[${label}]`)
|
|
6
|
-
console.log(raw)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async function run(): Promise<void> {
|
|
10
|
-
const sharedSecret = 'quickstart-shared-secret'
|
|
11
|
-
|
|
12
|
-
const coordinator = new AgentSession({
|
|
13
|
-
agentId: 'agent.coordinator',
|
|
14
|
-
outboundSecret: sharedSecret,
|
|
15
|
-
sharedSecrets: { 'agent.worker': sharedSecret },
|
|
16
|
-
capabilities: ['task.plan', 'caps'],
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const worker = new AgentSession({
|
|
20
|
-
agentId: 'agent.worker',
|
|
21
|
-
outboundSecret: sharedSecret,
|
|
22
|
-
sharedSecrets: { 'agent.coordinator': sharedSecret },
|
|
23
|
-
capabilities: ['task.plan', 'task.execute'],
|
|
24
|
-
onTask: async (envelope) => ({
|
|
25
|
-
intent: 'RESULT',
|
|
26
|
-
content: `processed:${envelope.body.content}`,
|
|
27
|
-
capability: envelope.body.capability,
|
|
28
|
-
}),
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const ping = await coordinator.createSignedIntent({ recipient: 'agent.worker', intent: 'PING', content: 'ping' })
|
|
32
|
-
printExchange('coordinator -> worker PING (compact)', encodeEnvelope(ping, 'compact'))
|
|
33
|
-
const pingReply = await worker.receiveAndRespond(ping)
|
|
34
|
-
if (!pingReply.response) throw new Error('Missing PING response')
|
|
35
|
-
printExchange('worker -> coordinator PONG (compact)', encodeEnvelope(pingReply.response, 'compact'))
|
|
36
|
-
|
|
37
|
-
const caps = await coordinator.createSignedIntent({ recipient: 'agent.worker', intent: 'CAPS', content: 'caps?' })
|
|
38
|
-
const capsReply = await worker.receiveAndRespond(caps)
|
|
39
|
-
if (!capsReply.response) throw new Error('Missing CAPS response')
|
|
40
|
-
console.log(`\n[worker CAPS payload] ${capsReply.response.body.content}`)
|
|
41
|
-
|
|
42
|
-
const task = await coordinator.createSignedIntent({
|
|
43
|
-
recipient: 'agent.worker',
|
|
44
|
-
intent: 'TASK',
|
|
45
|
-
content: 'build route graph',
|
|
46
|
-
capability: 'task.plan',
|
|
47
|
-
})
|
|
48
|
-
const taskReply = await worker.receiveAndRespond(task)
|
|
49
|
-
if (!taskReply.response) throw new Error('Missing TASK response')
|
|
50
|
-
console.log(`\n[worker TASK result] ${taskReply.response.body.content}`)
|
|
51
|
-
|
|
52
|
-
const verifiedAtCoordinator = await coordinator.receiveAndRespond(taskReply.response)
|
|
53
|
-
console.log(`\n[coordinator verification] ok=${verifiedAtCoordinator.ok}`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
run().catch((error: unknown) => {
|
|
57
|
-
const message = error instanceof Error ? error.stack ?? error.message : String(error)
|
|
58
|
-
console.error(message)
|
|
59
|
-
process.exitCode = 1
|
|
60
|
-
})
|
package/scripts/bench-diff.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
-
|
|
3
|
-
interface BenchRow {
|
|
4
|
-
mode: string
|
|
5
|
-
payloadBytes: number
|
|
6
|
-
concurrency: number
|
|
7
|
-
opsPerSecond: number
|
|
8
|
-
p99Ms: number
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface BenchPayload {
|
|
12
|
-
profile: string
|
|
13
|
-
results: BenchRow[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface DiffRow {
|
|
17
|
-
key: string
|
|
18
|
-
baselineOps: number
|
|
19
|
-
candidateOps: number
|
|
20
|
-
opsChangePct: number
|
|
21
|
-
baselineP99: number
|
|
22
|
-
candidateP99: number
|
|
23
|
-
p99ChangePct: number
|
|
24
|
-
regression: boolean
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function parseArg(flag: string, argv: string[]): string | null {
|
|
28
|
-
const index = argv.indexOf(flag)
|
|
29
|
-
if (index < 0) return null
|
|
30
|
-
return argv[index + 1] ?? null
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function keyOf(row: BenchRow): string {
|
|
34
|
-
return `${row.mode}|${row.payloadBytes}|${row.concurrency}`
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function round2(value: number): number {
|
|
38
|
-
return Number(value.toFixed(2))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function loadPayload(path: string): Promise<BenchPayload> {
|
|
42
|
-
const raw = await readFile(path, 'utf8')
|
|
43
|
-
const parsed = JSON.parse(raw) as BenchPayload
|
|
44
|
-
if (!Array.isArray(parsed.results)) {
|
|
45
|
-
throw new Error(`Invalid benchmark payload at ${path}`)
|
|
46
|
-
}
|
|
47
|
-
return parsed
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function renderMarkdown(rows: DiffRow[]): string {
|
|
51
|
-
const lines: string[] = []
|
|
52
|
-
lines.push('| case | baseline ops/s | candidate ops/s | ops Δ% | baseline p99 | candidate p99 | p99 Δ% | regressed |')
|
|
53
|
-
lines.push('| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |')
|
|
54
|
-
for (const row of rows) {
|
|
55
|
-
lines.push(
|
|
56
|
-
`| ${row.key} | ${row.baselineOps} | ${row.candidateOps} | ${row.opsChangePct} | ${row.baselineP99} | ${row.candidateP99} | ${row.p99ChangePct} | ${row.regression ? 'yes' : 'no'} |`,
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
return `${lines.join('\n')}\n`
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function main(): Promise<void> {
|
|
63
|
-
const baselinePath = parseArg('--baseline', process.argv)
|
|
64
|
-
const candidatePath = parseArg('--candidate', process.argv)
|
|
65
|
-
|
|
66
|
-
if (!baselinePath || !candidatePath) {
|
|
67
|
-
throw new Error('Usage: tsx scripts/bench-diff.ts --baseline <path> --candidate <path>')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const baseline = await loadPayload(baselinePath)
|
|
71
|
-
const candidate = await loadPayload(candidatePath)
|
|
72
|
-
|
|
73
|
-
const baselineMap = new Map<string, BenchRow>()
|
|
74
|
-
baseline.results.forEach((row) => baselineMap.set(keyOf(row), row))
|
|
75
|
-
|
|
76
|
-
const diffs: DiffRow[] = []
|
|
77
|
-
for (const row of candidate.results) {
|
|
78
|
-
const key = keyOf(row)
|
|
79
|
-
const previous = baselineMap.get(key)
|
|
80
|
-
if (!previous) continue
|
|
81
|
-
|
|
82
|
-
const opsChangePct = previous.opsPerSecond === 0 ? 0 : ((row.opsPerSecond - previous.opsPerSecond) / previous.opsPerSecond) * 100
|
|
83
|
-
const p99ChangePct = previous.p99Ms === 0 ? 0 : ((row.p99Ms - previous.p99Ms) / previous.p99Ms) * 100
|
|
84
|
-
const regression = opsChangePct < -5 || p99ChangePct > 10
|
|
85
|
-
|
|
86
|
-
diffs.push({
|
|
87
|
-
key,
|
|
88
|
-
baselineOps: round2(previous.opsPerSecond),
|
|
89
|
-
candidateOps: round2(row.opsPerSecond),
|
|
90
|
-
opsChangePct: round2(opsChangePct),
|
|
91
|
-
baselineP99: round2(previous.p99Ms),
|
|
92
|
-
candidateP99: round2(row.p99Ms),
|
|
93
|
-
p99ChangePct: round2(p99ChangePct),
|
|
94
|
-
regression,
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
diffs.sort((a, b) => {
|
|
99
|
-
if (a.regression !== b.regression) return a.regression ? -1 : 1
|
|
100
|
-
return a.key.localeCompare(b.key)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
const regressions = diffs.filter((row) => row.regression)
|
|
104
|
-
console.log(`Compared ${diffs.length} matching cases`)
|
|
105
|
-
console.log(`Regressions: ${regressions.length}`)
|
|
106
|
-
console.log('')
|
|
107
|
-
console.log(renderMarkdown(diffs))
|
|
108
|
-
|
|
109
|
-
if (regressions.length > 0) {
|
|
110
|
-
process.exitCode = 2
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
main().catch((error: unknown) => {
|
|
115
|
-
const message = error instanceof Error ? error.stack ?? error.message : String(error)
|
|
116
|
-
console.error(message)
|
|
117
|
-
process.exitCode = 1
|
|
118
|
-
})
|