ctxtop 0.0.0-stage → 4.0.0
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/.antigravity-plugin/plugin.json +36 -0
- package/.claude-plugin/plugin.json +18 -0
- package/CHECKSUMS.sha256 +149 -0
- package/LICENSE +27 -0
- package/README.md +330 -3
- package/SECURITY.md +22 -0
- package/agents/ah-flash-scout.md +25 -0
- package/assets/advanced_view_loaded_420px.png +0 -0
- package/assets/hero-demo.svg +188 -0
- package/assets/logo.svg +19 -0
- package/assets/simple_view_lean_420px.png +0 -0
- package/assets/simple_view_loaded_420px.png +0 -0
- package/assets/social-preview.svg +72 -0
- package/assets/zone_c_step3_shield_full.png +0 -0
- package/bin/ah-statusline.mjs +145 -0
- package/bin/cli.mjs +3 -0
- package/bin/ctxtop.mjs +1474 -0
- package/commands/cost-radar.md +11 -0
- package/commands/evolve.md +10 -0
- package/commands/handoff.md +10 -0
- package/commands/horizon.md +10 -0
- package/commands/inspect.md +10 -0
- package/commands/precheck.md +10 -0
- package/config/default_flightcheck.json +114 -0
- package/config/modelCatalog.json +620 -0
- package/config/platformQuirks.json +19 -0
- package/hooks/handlers/compact-lifecycle.mjs +262 -0
- package/hooks/handlers/hookIo.mjs +255 -0
- package/hooks/handlers/hookIpcClient.mjs +83 -0
- package/hooks/handlers/post-tool-use.mjs +265 -0
- package/hooks/handlers/pre-model-switch.mjs +249 -0
- package/hooks/handlers/pre-tool-use.mjs +365 -0
- package/hooks/handlers/stop-gate.mjs +240 -0
- package/hooks/handlers/user-prompt-submit.mjs +143 -0
- package/hooks/hooks.json +81 -0
- package/hooks/post_invocation.mjs +13 -0
- package/hooks/post_tool_use.mjs +17 -0
- package/hooks/pre_invocation.mjs +14 -0
- package/hooks/pre_tool_use.mjs +97 -0
- package/hooks/register.js +687 -0
- package/hooks/session_start.mjs +14 -0
- package/hooks/stop.mjs +13 -0
- package/hooks.json +56 -0
- package/package.json +103 -4
- package/packages/antigravity/package.json +14 -0
- package/packages/antigravity/src/index.mjs +1 -0
- package/packages/claude-code/package.json +14 -0
- package/packages/claude-code/src/index.mjs +2 -0
- package/packages/core/package.json +14 -0
- package/packages/core/src/index.mjs +1 -0
- package/packages/engine-node/package.json +14 -0
- package/packages/engine-node/src/index.mjs +1 -0
- package/packages/mcp/package.json +17 -0
- package/packages/mcp/src/server.mjs +396 -0
- package/packages/pro/LICENSE-COMMERCIAL.md +19 -0
- package/packages/pro/README-SIGNING.md +30 -0
- package/packages/pro/package.json +16 -0
- package/packages/pro/src/index.mjs +3 -0
- package/packages/pro/src/team_finops_pack.mjs +241 -0
- package/packages/pro/workers/polar_webhook_worker.mjs +215 -0
- package/plugin.json +36 -0
- package/rules/AGENTS.md +10 -0
- package/sidecars/horizon-daemon/ipcServer.mjs +24 -0
- package/sidecars/horizon-daemon/server.mjs +2002 -0
- package/sidecars/horizon-daemon/sidecar.json +19 -0
- package/skills/cost-radar/SKILL.md +21 -0
- package/skills/evolve/SKILL.md +21 -0
- package/skills/handoff/SKILL.md +42 -0
- package/skills/horizon/SKILL.md +17 -0
- package/skills/inspect/SKILL.md +18 -0
- package/skills/precheck/SKILL.md +44 -0
- package/src/adapters/antigravity/index.mjs +79 -0
- package/src/adapters/claude-code/index.mjs +155 -0
- package/src/cli/cost_radar.mjs +70 -0
- package/src/cli/doctor.mjs +351 -0
- package/src/cli/horizon_hud.mjs +686 -0
- package/src/cli/init.mjs +425 -0
- package/src/cli/postmortem.mjs +515 -0
- package/src/coach/cacheGravityRouter.mjs +12 -0
- package/src/config/modelCatalog.json +620 -0
- package/src/config/platformQuirks.json +19 -0
- package/src/core/action_queue.mjs +264 -0
- package/src/core/ag_bridge.mjs +346 -0
- package/src/core/atomic_io.mjs +124 -0
- package/src/core/baseline.mjs +607 -0
- package/src/core/blindspot_sensors.mjs +399 -0
- package/src/core/classifier.mjs +1757 -0
- package/src/core/coach/circuit_breakers.mjs +650 -0
- package/src/core/coach/contradiction_auditor.mjs +239 -0
- package/src/core/coach/effort_advisor.mjs +143 -0
- package/src/core/coach/handoff_hydrator.mjs +483 -0
- package/src/core/coach/progressive_checkpointer.mjs +551 -0
- package/src/core/coach/prompt_decomposer_coach.mjs +141 -0
- package/src/core/coach/reflector_queue.mjs +505 -0
- package/src/core/coach/saved_quota_ledger.mjs +615 -0
- package/src/core/coach/subagent_ipi_sanitizer.mjs +200 -0
- package/src/core/coach/subagent_phantom_auditor.mjs +261 -0
- package/src/core/coach/task_quota_router.mjs +955 -0
- package/src/core/coach/turn_zero_gate.mjs +574 -0
- package/src/core/compaction_coach.mjs +1126 -0
- package/src/core/config.mjs +214 -0
- package/src/core/constants.mjs +1800 -0
- package/src/core/detectors_det01_to_16.mjs +1474 -0
- package/src/core/episodic_memory.mjs +135 -0
- package/src/core/fts5_output_compressor.mjs +359 -0
- package/src/core/git_ledger.mjs +189 -0
- package/src/core/handoff_audit.mjs +558 -0
- package/src/core/history.mjs +221 -0
- package/src/core/hook_diagnostics.mjs +158 -0
- package/src/core/horizon_classifier.mjs +326 -0
- package/src/core/horizon_config.mjs +802 -0
- package/src/core/host_watchdog.mjs +200 -0
- package/src/core/layer5_hygiene.mjs +966 -0
- package/src/core/log_resolver.mjs +231 -0
- package/src/core/mcp_auditor.mjs +138 -0
- package/src/core/micro_skills_store.mjs +91 -0
- package/src/core/offenders.mjs +161 -0
- package/src/core/parser.mjs +1996 -0
- package/src/core/path_canonicalizer.mjs +73 -0
- package/src/core/paths.mjs +310 -0
- package/src/core/prefix_cache_shield.mjs +386 -0
- package/src/core/pro_license.mjs +385 -0
- package/src/core/prompt_rubric.mjs +518 -0
- package/src/core/pruner.mjs +433 -0
- package/src/core/quota.mjs +1860 -0
- package/src/core/rsi_instinct_engine.mjs +1197 -0
- package/src/core/sanitizer.mjs +121 -0
- package/src/core/session_forensics.mjs +303 -0
- package/src/core/session_timeline.mjs +358 -0
- package/src/core/settings.mjs +99 -0
- package/src/core/shared/detectors.mjs +1342 -0
- package/src/core/shared/fnv1a64.mjs +85 -0
- package/src/core/shared/handoff_schema.mjs +123 -0
- package/src/core/shared/index.mjs +5 -0
- package/src/core/shared/ipi_sanitizer.mjs +165 -0
- package/src/core/shared/micro_skills.mjs +1 -0
- package/src/core/shared/plugin_validator.mjs +202 -0
- package/src/core/shared/prompt_hygiene_governor.mjs +1 -0
- package/src/core/sidecar_store.mjs +302 -0
- package/src/core/sprint_metrics.mjs +366 -0
- package/src/core/sqlite_client.mjs +283 -0
- package/src/core/storage_doctor.mjs +358 -0
- package/src/core/subagents.mjs +609 -0
- package/src/core/swarm_topology.mjs +360 -0
- package/src/core/task_quota_router.mjs +1656 -0
- package/src/core/telemetry/cache_ttl_watchdog.mjs +284 -0
- package/src/core/telemetry/scope_lock_registry.mjs +578 -0
- package/src/core/telemetry/shadow_file_detector.mjs +291 -0
- package/src/core/telemetry/trajectory_watcher.mjs +259 -0
- package/src/core/timeline_svg.mjs +236 -0
- package/src/core/tool_surgeon.mjs +305 -0
- package/src/core/trajectory_stitcher.mjs +645 -0
- package/src/core/u_shaped_optimizer.mjs +789 -0
- package/src/core/wal_hygiene.mjs +233 -0
- package/src/core-isomorphic/catalog/detectorCatalog.mjs +558 -0
- package/src/core-isomorphic/catalog/index.mjs +1 -0
- package/src/core-isomorphic/coach/cacheGravityRouter.mjs +720 -0
- package/src/core-isomorphic/coach/microSkills.mjs +1 -0
- package/src/core-isomorphic/coach/promptHygieneGovernor.mjs +1 -0
- package/src/core-isomorphic/coach/repoCalibration.mjs +254 -0
- package/src/core-isomorphic/coach/savedQuotaLedger.mjs +527 -0
- package/src/core-isomorphic/coach/stateBatonHydrator.mjs +810 -0
- package/src/core-isomorphic/coach/ttlWatchdog.mjs +457 -0
- package/src/core-isomorphic/config/anthropicModelCatalog.json +203 -0
- package/src/core-isomorphic/config/catalogLoader.mjs +768 -0
- package/src/core-isomorphic/config/horizonConfig.mjs +1009 -0
- package/src/core-isomorphic/control/callTree.mjs +338 -0
- package/src/core-isomorphic/control/coachLatches.mjs +126 -0
- package/src/core-isomorphic/control/controlStateMachine.mjs +205 -0
- package/src/core-isomorphic/control/index.mjs +49 -0
- package/src/core-isomorphic/control/swarmWorktree.mjs +109 -0
- package/src/core-isomorphic/control/toolSuspension.mjs +197 -0
- package/src/core-isomorphic/diagnostics/drift_guard.mjs +382 -0
- package/src/core-isomorphic/diagnostics/index.mjs +9 -0
- package/src/core-isomorphic/diagnostics/micro_skills.mjs +471 -0
- package/src/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +622 -0
- package/src/core-isomorphic/economics/billingBlocks.mjs +251 -0
- package/src/core-isomorphic/economics/cacheGravity.mjs +351 -0
- package/src/core-isomorphic/economics/cliffBreaker.mjs +170 -0
- package/src/core-isomorphic/economics/driftLatency.mjs +319 -0
- package/src/core-isomorphic/economics/dualTtl.mjs +198 -0
- package/src/core-isomorphic/economics/index.mjs +47 -0
- package/src/core-isomorphic/economics/retentionRadar.mjs +348 -0
- package/src/core-isomorphic/guards/circuitBreakers.mjs +1202 -0
- package/src/core-isomorphic/guards/det01_03_shell_secret.mjs +1035 -0
- package/src/core-isomorphic/guards/det04_12_thrash_rot.mjs +480 -0
- package/src/core-isomorphic/guards/det13_20_mcp_scope.mjs +603 -0
- package/src/core-isomorphic/guards/losslessPostSanitizer.mjs +301 -0
- package/src/core-isomorphic/index.js +26 -0
- package/src/core-isomorphic/telemetry/otelExporter.mjs +187 -0
- package/src/core-isomorphic/telemetry/scopeLockRegistry.mjs +522 -0
- package/src/core-isomorphic/telemetry/sprintMetrics.mjs +327 -0
- package/src/core-isomorphic/telemetry/swarmTopology.mjs +152 -0
- package/src/core-isomorphic/telemetry/telemetryBridge.mjs +1132 -0
- package/src/core-isomorphic/ui/brailleSparkline.mjs +142 -0
- package/src/core-isomorphic/ui/costRadarSvg.mjs +276 -0
- package/src/core-isomorphic/ui/horizonGrid.mjs +475 -0
- package/src/core-isomorphic/ui/horizonPanelHtml.mjs +1181 -0
- package/src/core-isomorphic/ui/modViews.mjs +1478 -0
- package/src/core-isomorphic/ui/pdfReceiptGenerator.mjs +329 -0
- package/src/core-isomorphic/ustf/index.mjs +7 -0
- package/src/core-isomorphic/ustf/normalizer.mjs +512 -0
- package/src/core-isomorphic/ustf/schema.mjs +186 -0
- package/src/core-isomorphic/utils/runtime.mjs +962 -0
- package/src/demo/synthetic_states.mjs +661 -0
- package/src/diagnostics/bugReportGenerator.mjs +253 -0
- package/src/diagnostics/doctorEngine.mjs +203 -0
- package/src/engine-node/db/index.mjs +58 -0
- package/src/engine-node/db/jsonl_fallback.mjs +184 -0
- package/src/engine-node/db/probe.mjs +110 -0
- package/src/engine-node/db/sqlite_wrapper.mjs +122 -0
- package/src/engine-node/index.mjs +9 -0
- package/src/engine-node/ipc/client.mjs +447 -0
- package/src/engine-node/ipc/index.mjs +22 -0
- package/src/engine-node/ipc/protocol.mjs +177 -0
- package/src/engine-node/ipc/server.mjs +445 -0
- package/src/engine-node/offloader/index.mjs +6 -0
- package/src/engine-node/offloader/tool_offloader.mjs +241 -0
- package/src/engine-node/sensors/blindspots.mjs +369 -0
- package/src/engine-node/sensors/git_merge_tree.mjs +223 -0
- package/src/engine-node/sensors/index.mjs +7 -0
- package/src/hooks/portfolio_runtime.mjs +858 -0
- package/src/hooks/post_invocation.mjs +419 -0
- package/src/hooks/pre_invocation.mjs +1015 -0
- package/src/hooks/session_start.mjs +161 -0
- package/src/shims/agy_cli_compressor.mjs +705 -0
- package/src/shims/agy_git_guard.mjs +749 -0
- package/src/shims/ah_log_query.mjs +39 -0
- package/src/ui/costRadarSvg.mjs +6 -0
- package/src/ui/horizonGrid.mjs +1 -0
- package/src/ui/horizonPanelHtml.mjs +1 -0
- package/src/ui/horizon_panel.css +167 -0
- package/src/ui/horizon_panel.js +212 -0
- package/src/ui/modViews.mjs +1 -0
- package/src/utils/nodeIo.mjs +59 -0
- package/src/utils/runtime.mjs +1 -0
- package/src/webview/advanced_view.html +1808 -0
- package/src/webview/horizon_panel.html +11389 -0
- package/src/webview/registry.mjs +80 -0
- package/src/webview/simple_view.html +1370 -0
package/hooks/stop.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { handlePostInvocation, readStdinSafe } from '../src/hooks/post_invocation.mjs';
|
|
3
|
+
|
|
4
|
+
readStdinSafe({ maxTimeoutMs: 500, settleMs: 15 })
|
|
5
|
+
.then((input) => handlePostInvocation({ ...input, hook_event_name: 'Stop' }))
|
|
6
|
+
.then(() => {
|
|
7
|
+
process.stdout.write('{}\n');
|
|
8
|
+
process.exit(0);
|
|
9
|
+
})
|
|
10
|
+
.catch(() => {
|
|
11
|
+
process.stdout.write('{}\n');
|
|
12
|
+
process.exit(0);
|
|
13
|
+
});
|
package/hooks.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"type": "command",
|
|
6
|
+
"command": "node ./hooks/session_start.mjs",
|
|
7
|
+
"timeout": 5
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"PreInvocation": [
|
|
11
|
+
{
|
|
12
|
+
"type": "command",
|
|
13
|
+
"command": "node ./hooks/pre_invocation.mjs",
|
|
14
|
+
"timeout": 5
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"PostInvocation": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "node ./hooks/post_invocation.mjs",
|
|
21
|
+
"timeout": 5
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"Stop": [
|
|
25
|
+
{
|
|
26
|
+
"type": "command",
|
|
27
|
+
"command": "node ./hooks/stop.mjs",
|
|
28
|
+
"timeout": 5
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"PreToolUse": [
|
|
32
|
+
{
|
|
33
|
+
"matcher": "run_command|edit_file|write_file|write_to_file|replace_file_content|multi_replace_file_content|read_file|view_file|invoke_subagent|define_subagent|send_message|manage_subagents|swarm",
|
|
34
|
+
"hooks": [
|
|
35
|
+
{
|
|
36
|
+
"type": "command",
|
|
37
|
+
"command": "node ./hooks/pre_tool_use.mjs",
|
|
38
|
+
"timeout": 5
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"PostToolUse": [
|
|
44
|
+
{
|
|
45
|
+
"matcher": "run_command|edit_file|write_file|write_to_file|replace_file_content|multi_replace_file_content|invoke_subagent|define_subagent|send_message|manage_subagents|swarm",
|
|
46
|
+
"hooks": [
|
|
47
|
+
{
|
|
48
|
+
"type": "command",
|
|
49
|
+
"command": "node ./hooks/post_tool_use.mjs",
|
|
50
|
+
"timeout": 5
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,105 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctxtop",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"displayName": "Highbeam",
|
|
4
|
+
"version": "4.0.0",
|
|
5
|
+
"description": "Highbeam v4.0: Cross-platform AI Developer Assistant Extension for Google Antigravity and Claude Code: 40-cell context visualizer, KV-cache gravity router, and zero-token guardrails.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"workspaces": [
|
|
8
|
+
"packages/core",
|
|
9
|
+
"packages/engine-node",
|
|
10
|
+
"packages/antigravity",
|
|
11
|
+
"packages/claude-code",
|
|
12
|
+
"packages/pro",
|
|
13
|
+
"packages/mcp"
|
|
14
|
+
],
|
|
15
|
+
"bin": {
|
|
16
|
+
"ah": "bin/ctxtop.mjs",
|
|
17
|
+
"attention-horizon": "bin/ctxtop.mjs",
|
|
18
|
+
"ctxtop": "bin/ctxtop.mjs",
|
|
19
|
+
"ah-statusline": "bin/ah-statusline.mjs",
|
|
20
|
+
"attention-horizon-antigravity": "src/cli/init.mjs",
|
|
21
|
+
"ah-antigravity": "src/cli/init.mjs",
|
|
22
|
+
"attention-horizon-claude": "bin/ctxtop.mjs",
|
|
23
|
+
"ah-claude": "bin/ctxtop.mjs",
|
|
24
|
+
"agy-horizon": "src/cli/init.mjs",
|
|
25
|
+
"agy-horizon-flightcheck": "src/cli/init.mjs",
|
|
26
|
+
"ah-mcp": "packages/mcp/src/server.mjs",
|
|
27
|
+
"ctxtop-mcp": "packages/mcp/src/server.mjs"
|
|
28
|
+
},
|
|
29
|
+
"main": "./src/cli/horizon_hud.mjs",
|
|
30
|
+
"files": [
|
|
31
|
+
"README.md",
|
|
32
|
+
"SECURITY.md",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"CHECKSUMS.sha256",
|
|
35
|
+
"plugin.json",
|
|
36
|
+
".antigravity-plugin/",
|
|
37
|
+
".claude-plugin/",
|
|
38
|
+
"hooks.json",
|
|
39
|
+
"hooks/",
|
|
40
|
+
"bin/",
|
|
41
|
+
"commands/",
|
|
42
|
+
"agents/",
|
|
43
|
+
"config/",
|
|
44
|
+
"assets/",
|
|
45
|
+
"rules/",
|
|
46
|
+
"skills/",
|
|
47
|
+
"sidecars/",
|
|
48
|
+
"packages/",
|
|
49
|
+
"src/"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"start": "node --no-warnings src/cli/init.mjs --demo",
|
|
53
|
+
"demo": "node --no-warnings src/cli/init.mjs --demo-animate",
|
|
54
|
+
"dev": "node --no-warnings src/cli/init.mjs --serve",
|
|
55
|
+
"hud": "node --no-warnings src/cli/horizon_hud.mjs --demo",
|
|
56
|
+
"roast": "node --no-warnings src/cli/init.mjs --roast",
|
|
57
|
+
"postmortem": "node --no-warnings src/cli/init.mjs postmortem",
|
|
58
|
+
"doctor": "node --no-warnings src/cli/init.mjs doctor",
|
|
59
|
+
"install-plugin": "node --no-warnings src/cli/init.mjs init",
|
|
60
|
+
"build:bundles": "node scripts/build_evaluation_bundles.mjs",
|
|
61
|
+
"build:assets": "node --no-warnings scripts/generate_hero_svg.mjs && node --no-warnings scripts/build_demo_page.mjs",
|
|
62
|
+
"build:release": "node scripts/build_release_bundle.mjs",
|
|
63
|
+
"test": "npm run test:unit && npm run test:coach && npm run test:gates && npm run test:phases",
|
|
64
|
+
"test:unit": "node --test tests/test_router_and_sensors.mjs tests/test_wave1_wedge.mjs tests/test_wave2_wedge.mjs tests/test_wave3_wedge.mjs tests/test_carbon_swarm_patch.mjs tests/test_concurrency.mjs tests/test_postmortem_features.mjs tests/test_schema_drift.mjs tests/test_mirror_boot_smoke.mjs && node tests/test_regressions.cjs",
|
|
65
|
+
"test:coach": "node --test test/all.test.mjs",
|
|
66
|
+
"test:claude": "node --test test/claude-code/*.test.mjs",
|
|
67
|
+
"test:gates": "node --test tests/verify_gate_0.mjs tests/verify_gate_1.mjs tests/verify_gate_2.mjs tests/verify_gate_3.mjs tests/verify_gate_4.mjs tests/verify_gate_5.mjs tests/verify_gate_6.mjs",
|
|
68
|
+
"test:phases": "node tests/verify_phase_1.mjs && node tests/verify_phase_2.mjs && node tests/verify_phase_3.mjs && node tests/verify_phase_4.mjs && node tests/verify_phase_5.mjs && node tests/verify_phase_6.mjs && node tests/verify_phase_6_roadmap.mjs && node tests/verify_phase_7.mjs",
|
|
69
|
+
"test:e2e": "node tests/verify_e2e_context_memory.mjs",
|
|
70
|
+
"bench": "node tests/bench_latency.mjs",
|
|
71
|
+
"bench:scenario": "node --no-warnings tests/benchmark_context_scenario.mjs",
|
|
72
|
+
"bench:composite": "node scripts/run_composite_benchmarks.mjs"
|
|
73
|
+
},
|
|
74
|
+
"repository": {
|
|
75
|
+
"type": "git",
|
|
76
|
+
"url": "git+https://github.com/Gizzant/context-horizon.git"
|
|
77
|
+
},
|
|
78
|
+
"homepage": "https://gizzant.github.io/context-horizon/",
|
|
79
|
+
"bugs": {
|
|
80
|
+
"url": "https://github.com/Gizzant/context-horizon/issues"
|
|
81
|
+
},
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": ">=20.0.0"
|
|
84
|
+
},
|
|
85
|
+
"keywords": [
|
|
86
|
+
"ai-agents",
|
|
87
|
+
"context-window",
|
|
88
|
+
"llm-telemetry",
|
|
89
|
+
"antigravity",
|
|
90
|
+
"google-antigravity",
|
|
91
|
+
"mcp",
|
|
92
|
+
"sludge-tax",
|
|
93
|
+
"attention-horizon",
|
|
94
|
+
"ctxtop",
|
|
95
|
+
"developer-tools",
|
|
96
|
+
"tufte",
|
|
97
|
+
"cli"
|
|
98
|
+
],
|
|
99
|
+
"author": "Gizzant <frankmiller@gmail.com>",
|
|
100
|
+
"license": "MIT",
|
|
101
|
+
"commercialLicense": "SEE LICENSE IN packages/pro/LICENSE-COMMERCIAL.md",
|
|
102
|
+
"devDependencies": {
|
|
103
|
+
"jsdom": "^29.1.1"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ctxtop/antigravity",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Highbeam Google Antigravity host adapter, daemon, hooks, and WebView HUD",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.mjs"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20.0.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/adapters/antigravity/index.mjs';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ctxtop/claude-code",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Highbeam Claude Code in-process V8 Mod, Tier-2 CLI hooks, and terminal statusLine adapter",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.mjs"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20.0.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ctxtop/core",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Highbeam isomorphic pure-JS core (DET-01..32 catalog, circuit breakers, economics, coach, UI renderers)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.mjs"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20.0.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/core-isomorphic/index.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ctxtop/engine-node",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Highbeam Node.js >=20 runtime engine (SQLite + JSONL fallback, Micro-IPC, lossless offloader, git sensors)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.mjs"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20.0.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/engine-node/index.mjs';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ctxtop/mcp",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Highbeam Zero-Dependency MCP Stdio Server for Cursor, Windsurf, Claude Code & Antigravity",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/server.mjs",
|
|
8
|
+
"bin": {
|
|
9
|
+
"ctxtop-mcp": "./src/server.mjs"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/server.mjs"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @file packages/mcp/src/server.mjs
|
|
4
|
+
* Zero-dependency MCP stdio JSON-RPC 2.0 server (`@ctxtop/mcp`) for Cursor, Windsurf,
|
|
5
|
+
* Claude Code, and Google Antigravity.
|
|
6
|
+
*
|
|
7
|
+
* Supports both newline-delimited JSON-RPC and `Content-Length` framed stdio transport.
|
|
8
|
+
* Exposes 4 local, zero-network tools:
|
|
9
|
+
* 1. `horizon_status`
|
|
10
|
+
* 2. `cache_gravity_check`
|
|
11
|
+
* 3. `scope_lock_claim`
|
|
12
|
+
* 4. `export_receipt_pdf`
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { readLiveStateSnapshot } from '../../../src/core-isomorphic/telemetry/telemetryBridge.mjs';
|
|
19
|
+
import { getSavedQuotaReceiptSummary } from '../../../src/core-isomorphic/coach/savedQuotaLedger.mjs';
|
|
20
|
+
import { generateCorporateExpenseReceipt } from '../../../src/core-isomorphic/ui/pdfReceiptGenerator.mjs';
|
|
21
|
+
import { getProEntitlementStatus } from '../../../src/core/pro_license.mjs';
|
|
22
|
+
import { CacheGravityScorer } from '../../../src/core/task_quota_router.mjs';
|
|
23
|
+
import { ScopeLockRegistry, loadRegistry } from '../../../src/core/telemetry/scope_lock_registry.mjs';
|
|
24
|
+
|
|
25
|
+
export const MCP_SERVER_INFO = Object.freeze({
|
|
26
|
+
name: '@ctxtop/mcp',
|
|
27
|
+
version: '4.0.0',
|
|
28
|
+
protocolVersion: '2024-11-05'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const MCP_TOOLS = Object.freeze([
|
|
32
|
+
{
|
|
33
|
+
name: 'horizon_status',
|
|
34
|
+
description: 'Read local Highbeam live telemetry, 30-day saved quota ledger, and @ctxtop/pro license status (zero network calls).',
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
cwd: { type: 'string', description: 'Workspace directory path' },
|
|
39
|
+
sessionId: { type: 'string', description: 'Session or trajectory ID' }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'cache_gravity_check',
|
|
45
|
+
description: 'Evaluate warm KV-cache break-even gravity before switching models or downshifting tiers.',
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
required: ['currentModel', 'targetModel'],
|
|
49
|
+
properties: {
|
|
50
|
+
currentModel: { type: 'string', description: 'Current active model ID' },
|
|
51
|
+
targetModel: { type: 'string', description: 'Candidate target model ID' },
|
|
52
|
+
cachedTokens: { type: 'number', description: 'Current warm cached prefix tokens' },
|
|
53
|
+
ttlRemainingSeconds: { type: 'number', description: 'Remaining prompt-cache TTL in seconds' },
|
|
54
|
+
remainingExpectedTurns: { type: 'number', description: 'Remaining expected turns in this session' },
|
|
55
|
+
expectedOutputTokens: { type: 'number', description: 'Expected output tokens per turn' }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'scope_lock_claim',
|
|
61
|
+
description: 'Inspect active multi-agent scope locks or acquire a DET-20 file-scope lease for a workspace path set.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
workspaceDir: { type: 'string', description: 'Workspace root directory' },
|
|
66
|
+
sessionId: { type: 'string', description: 'Trajectory / session ID owning the lease' },
|
|
67
|
+
agentId: { type: 'string', description: 'Tool/agent identifier (e.g., cursor, windsurf, claude-code)' },
|
|
68
|
+
paths: { type: 'array', items: { type: 'string' }, description: 'Relative paths or globs to claim; omit for read-only inspection' },
|
|
69
|
+
ttlSeconds: { type: 'number', description: 'Lease TTL in seconds (default 900)' }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'export_receipt_pdf',
|
|
75
|
+
description: 'Generate a local SHA-256 verified Corporate PDF 1.4 Expense Receipt from 30-day saved-quota ledger telemetry.',
|
|
76
|
+
inputSchema: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
cwd: { type: 'string', description: 'Workspace root directory' },
|
|
80
|
+
sessionId: { type: 'string', description: 'Session ID' },
|
|
81
|
+
email: { type: 'string', description: 'Optional account email override' },
|
|
82
|
+
outPath: { type: 'string', description: 'Optional output .pdf file path' },
|
|
83
|
+
allowPreview: { type: 'boolean', description: 'Allow writing/previewing receipt when on Free tier (default false)' }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
function executeHorizonStatusTool(args = {}, options = {}) {
|
|
90
|
+
const cwd = args.cwd || options.cwd || process.cwd();
|
|
91
|
+
const sessionId = args.sessionId || options.sessionId || 'default';
|
|
92
|
+
const homeDir = args.homeDir || options.homeDir;
|
|
93
|
+
const licensePath = args.licensePath || options.licensePath;
|
|
94
|
+
const publicKeyPem = args.publicKeyPem || options.publicKeyPem;
|
|
95
|
+
|
|
96
|
+
const live = readLiveStateSnapshot(sessionId, { cwd, ...(homeDir ? { homeDir } : {}) });
|
|
97
|
+
const summary = getSavedQuotaReceiptSummary({ cwd, ...(homeDir ? { homeDir } : {}) });
|
|
98
|
+
const entitlement = getProEntitlementStatus({
|
|
99
|
+
...(homeDir ? { homeDir } : {}),
|
|
100
|
+
...(licensePath ? { licensePath } : {}),
|
|
101
|
+
...(publicKeyPem ? { publicKeyPem } : {})
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
ok: true,
|
|
106
|
+
cwd,
|
|
107
|
+
sessionId,
|
|
108
|
+
entitlement: {
|
|
109
|
+
entitled: Boolean(entitlement.entitled),
|
|
110
|
+
tier: entitlement.tier || 'free',
|
|
111
|
+
source: entitlement.source || 'free'
|
|
112
|
+
},
|
|
113
|
+
savedQuota: summary,
|
|
114
|
+
liveState: live || null
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function executeCacheGravityCheckTool(args = {}) {
|
|
119
|
+
const scorer = new CacheGravityScorer();
|
|
120
|
+
const cachedTokens = Number(args.cachedTokens || 0);
|
|
121
|
+
const ttlRemainingSeconds = Number(args.ttlRemainingSeconds ?? 240);
|
|
122
|
+
const expectedOutputTokens = Number(args.expectedOutputTokens ?? 1500);
|
|
123
|
+
const remainingExpectedTurns = Math.max(1, Number(args.remainingExpectedTurns || 1));
|
|
124
|
+
|
|
125
|
+
const verdict = scorer.computeBreakEven({
|
|
126
|
+
currentModel: args.currentModel || 'claude-opus-5-5',
|
|
127
|
+
targetModel: args.targetModel || 'claude-sonnet-5-5',
|
|
128
|
+
targetEffort: args.targetEffort || 'low',
|
|
129
|
+
cachedTokens,
|
|
130
|
+
ttlRemainingSeconds,
|
|
131
|
+
expectedOutputTokens
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
ok: true,
|
|
136
|
+
remainingExpectedTurns,
|
|
137
|
+
...verdict
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function executeScopeLockClaimTool(args = {}, options = {}) {
|
|
142
|
+
const workspaceDir = args.workspaceDir || args.cwd || options.cwd || process.cwd();
|
|
143
|
+
const sessionId = args.sessionId || args.trajectoryId || options.sessionId || 'mcp-session';
|
|
144
|
+
const toolName = args.agentId || args.tool || 'mcp';
|
|
145
|
+
const paths = Array.isArray(args.paths) ? args.paths.filter(Boolean) : [];
|
|
146
|
+
|
|
147
|
+
if (paths.length === 0) {
|
|
148
|
+
const reg = loadRegistry(workspaceDir);
|
|
149
|
+
return {
|
|
150
|
+
ok: true,
|
|
151
|
+
mode: 'inspect',
|
|
152
|
+
workspaceDir,
|
|
153
|
+
activeLeases: reg.leases,
|
|
154
|
+
leaseCount: reg.leases.length
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const registry = new ScopeLockRegistry({ workspaceDir, tool: toolName });
|
|
159
|
+
const res = registry.acquireOrRenewLease({
|
|
160
|
+
trajectoryId: sessionId,
|
|
161
|
+
claimedPaths: paths,
|
|
162
|
+
ttlSeconds: Number(args.ttlSeconds || 900)
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
mode: 'claim',
|
|
167
|
+
workspaceDir,
|
|
168
|
+
...res
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function executeExportReceiptPdfTool(args = {}, options = {}) {
|
|
173
|
+
const cwd = args.cwd || options.cwd || process.cwd();
|
|
174
|
+
const homeDir = args.homeDir || options.homeDir;
|
|
175
|
+
const licensePath = args.licensePath || options.licensePath;
|
|
176
|
+
const publicKeyPem = args.publicKeyPem || options.publicKeyPem;
|
|
177
|
+
|
|
178
|
+
const entitlement = getProEntitlementStatus({
|
|
179
|
+
...(homeDir ? { homeDir } : {}),
|
|
180
|
+
...(licensePath ? { licensePath } : {}),
|
|
181
|
+
...(publicKeyPem ? { publicKeyPem } : {})
|
|
182
|
+
});
|
|
183
|
+
const entitled = Boolean(entitlement.entitled);
|
|
184
|
+
const previewOnly = !entitled;
|
|
185
|
+
|
|
186
|
+
const summary = getSavedQuotaReceiptSummary({ cwd, ...(homeDir ? { homeDir } : {}) });
|
|
187
|
+
const receipt = generateCorporateExpenseReceipt(summary, {
|
|
188
|
+
email: args.email || entitlement.payload?.email || 'developer@workspace.local',
|
|
189
|
+
tierLabel: 'Highbeam Pro ($15.00/mo)',
|
|
190
|
+
subscriptionCostUSD: 15.0
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
let writtenPath = null;
|
|
194
|
+
if (args.outPath && (entitled || Boolean(args.allowPreview))) {
|
|
195
|
+
const resolvedOut = path.resolve(cwd, String(args.outPath));
|
|
196
|
+
fs.mkdirSync(path.dirname(resolvedOut), { recursive: true });
|
|
197
|
+
fs.writeFileSync(resolvedOut, Buffer.from(receipt.pdfBytes));
|
|
198
|
+
writtenPath = resolvedOut;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
ok: true,
|
|
203
|
+
entitled,
|
|
204
|
+
tier: entitlement.tier || 'free',
|
|
205
|
+
previewOnly,
|
|
206
|
+
receiptId: receipt.receiptId,
|
|
207
|
+
sha256: receipt.sha256,
|
|
208
|
+
pdfByteLength: receipt.pdfBytes.length,
|
|
209
|
+
writtenPath,
|
|
210
|
+
summary
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function handleMcpToolCall(name, args = {}, options = {}) {
|
|
215
|
+
switch (String(name || '')) {
|
|
216
|
+
case 'horizon_status':
|
|
217
|
+
return executeHorizonStatusTool(args, options);
|
|
218
|
+
case 'cache_gravity_check':
|
|
219
|
+
return executeCacheGravityCheckTool(args);
|
|
220
|
+
case 'scope_lock_claim':
|
|
221
|
+
return executeScopeLockClaimTool(args, options);
|
|
222
|
+
case 'export_receipt_pdf':
|
|
223
|
+
return executeExportReceiptPdfTool(args, options);
|
|
224
|
+
default: {
|
|
225
|
+
const err = new Error(`Unknown MCP tool: ${name}`);
|
|
226
|
+
err.code = -32601;
|
|
227
|
+
throw err;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function handleMcpJsonRpcRequest(request, options = {}) {
|
|
233
|
+
if (!request || typeof request !== 'object') {
|
|
234
|
+
return {
|
|
235
|
+
jsonrpc: '2.0',
|
|
236
|
+
id: null,
|
|
237
|
+
error: { code: -32600, message: 'Invalid Request' }
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const id = request.id ?? null;
|
|
242
|
+
const method = String(request.method || '');
|
|
243
|
+
const params = request.params || {};
|
|
244
|
+
|
|
245
|
+
if (method === 'notifications/initialized' || id === null && method.startsWith('notifications/')) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
if (method === 'initialize') {
|
|
251
|
+
return {
|
|
252
|
+
jsonrpc: '2.0',
|
|
253
|
+
id,
|
|
254
|
+
result: {
|
|
255
|
+
protocolVersion: params.protocolVersion || MCP_SERVER_INFO.protocolVersion,
|
|
256
|
+
capabilities: { tools: {} },
|
|
257
|
+
serverInfo: {
|
|
258
|
+
name: MCP_SERVER_INFO.name,
|
|
259
|
+
version: MCP_SERVER_INFO.version
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (method === 'ping') {
|
|
266
|
+
return { jsonrpc: '2.0', id, result: {} };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (method === 'tools/list') {
|
|
270
|
+
return {
|
|
271
|
+
jsonrpc: '2.0',
|
|
272
|
+
id,
|
|
273
|
+
result: { tools: MCP_TOOLS }
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (method === 'tools/call') {
|
|
278
|
+
const toolName = String(params.name || '');
|
|
279
|
+
try {
|
|
280
|
+
const result = await handleMcpToolCall(toolName, params.arguments || {}, options);
|
|
281
|
+
return {
|
|
282
|
+
jsonrpc: '2.0',
|
|
283
|
+
id,
|
|
284
|
+
result: {
|
|
285
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
286
|
+
structuredContent: result,
|
|
287
|
+
isError: false
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
} catch (toolErr) {
|
|
291
|
+
if (toolErr.code === -32601) {
|
|
292
|
+
return {
|
|
293
|
+
jsonrpc: '2.0',
|
|
294
|
+
id,
|
|
295
|
+
error: { code: -32601, message: toolErr.message }
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
jsonrpc: '2.0',
|
|
300
|
+
id,
|
|
301
|
+
result: {
|
|
302
|
+
content: [{ type: 'text', text: JSON.stringify({ ok: false, error: toolErr.message }) }],
|
|
303
|
+
isError: true
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
jsonrpc: '2.0',
|
|
311
|
+
id,
|
|
312
|
+
error: { code: -32601, message: `Method not found: ${method}` }
|
|
313
|
+
};
|
|
314
|
+
} catch (err) {
|
|
315
|
+
return {
|
|
316
|
+
jsonrpc: '2.0',
|
|
317
|
+
id,
|
|
318
|
+
error: { code: -32603, message: err?.message || 'Internal error' }
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function writeMcpMessage(stream, payload, useContentLength = false) {
|
|
324
|
+
const json = JSON.stringify(payload);
|
|
325
|
+
if (useContentLength) {
|
|
326
|
+
const byteLen = Buffer.byteLength(json, 'utf8');
|
|
327
|
+
stream.write(`Content-Length: ${byteLen}\r\n\r\n${json}`);
|
|
328
|
+
} else {
|
|
329
|
+
stream.write(`${json}\n`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function startMcpStdioServer(options = {}) {
|
|
334
|
+
const input = options.stdin || process.stdin;
|
|
335
|
+
const output = options.stdout || process.stdout;
|
|
336
|
+
let buffer = Buffer.alloc(0);
|
|
337
|
+
|
|
338
|
+
const processPayloadText = async (text, useContentLength) => {
|
|
339
|
+
const trimmed = String(text || '').trim();
|
|
340
|
+
if (!trimmed) return;
|
|
341
|
+
try {
|
|
342
|
+
const req = JSON.parse(trimmed);
|
|
343
|
+
const res = await handleMcpJsonRpcRequest(req, options);
|
|
344
|
+
if (res !== null && req.id !== undefined) {
|
|
345
|
+
writeMcpMessage(output, res, useContentLength);
|
|
346
|
+
}
|
|
347
|
+
} catch (err) {
|
|
348
|
+
writeMcpMessage(
|
|
349
|
+
output,
|
|
350
|
+
{ jsonrpc: '2.0', id: null, error: { code: -32700, message: `Parse error: ${err.message}` } },
|
|
351
|
+
useContentLength
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
input.on('data', async (chunk) => {
|
|
357
|
+
buffer = Buffer.concat([buffer, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, 'utf8')]);
|
|
358
|
+
while (buffer.length > 0) {
|
|
359
|
+
const asStr = buffer.toString('utf8');
|
|
360
|
+
if (/^Content-Length:\s*\d+/i.test(asStr)) {
|
|
361
|
+
const sepIdx = buffer.indexOf('\r\n\r\n');
|
|
362
|
+
const lfSepIdx = sepIdx === -1 ? buffer.indexOf('\n\n') : sepIdx;
|
|
363
|
+
const sepLen = sepIdx !== -1 ? 4 : 2;
|
|
364
|
+
if (lfSepIdx === -1) break;
|
|
365
|
+
const header = buffer.slice(0, lfSepIdx).toString('utf8');
|
|
366
|
+
const match = header.match(/Content-Length:\s*(\d+)/i);
|
|
367
|
+
const contentLength = match ? Number(match[1]) : 0;
|
|
368
|
+
const totalNeed = lfSepIdx + sepLen + contentLength;
|
|
369
|
+
if (buffer.length < totalNeed) break;
|
|
370
|
+
const body = buffer.slice(lfSepIdx + sepLen, totalNeed).toString('utf8');
|
|
371
|
+
buffer = buffer.slice(totalNeed);
|
|
372
|
+
await processPayloadText(body, true);
|
|
373
|
+
} else {
|
|
374
|
+
const nlIdx = buffer.indexOf('\n');
|
|
375
|
+
if (nlIdx === -1) break;
|
|
376
|
+
const line = buffer.slice(0, nlIdx).toString('utf8');
|
|
377
|
+
buffer = buffer.slice(nlIdx + 1);
|
|
378
|
+
await processPayloadText(line, false);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function isMainEntry(argv1 = process.argv[1], metaUrl = import.meta.url) {
|
|
385
|
+
if (!argv1) return false;
|
|
386
|
+
try {
|
|
387
|
+
return fs.realpathSync(argv1) === fs.realpathSync(fileURLToPath(metaUrl));
|
|
388
|
+
} catch (err) {
|
|
389
|
+
void err;
|
|
390
|
+
return path.resolve(argv1) === path.resolve(fileURLToPath(metaUrl));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (isMainEntry()) {
|
|
395
|
+
startMcpStdioServer();
|
|
396
|
+
}
|