|
| 1 | +# context-kernel (v0.1.0) |
| 2 | + |
| 3 | +Platform-agnostic Context Kernel for agent runtimes. |
| 4 | + |
| 5 | +## What it does |
| 6 | + |
| 7 | +- Classifies input (`text` vs `multimodal`, task type) |
| 8 | +- Enforces token budget threshold and compression trigger (>10k by default) |
| 9 | +- Routes model choice via configurable route map + model registry |
| 10 | +- Applies policy guards (post-only, quiet-hours, no-secret guard) |
| 11 | +- Supports rule-based policy DSL (allowlist, quiet-hours, secret regex) |
| 12 | +- Extracts memory candidates with confidence/source/writeback hints |
| 13 | +- Emits deterministic audit events |
| 14 | +- Supports OpenClaw + generic HTTP envelope adapters |
| 15 | + |
| 16 | +## Install |
| 17 | + |
| 18 | +```bash |
| 19 | +npm install context-kernel |
| 20 | +``` |
| 21 | + |
| 22 | +## Quick start (library) |
| 23 | + |
| 24 | +```ts |
| 25 | +import { ContextKernel } from "context-kernel"; |
| 26 | + |
| 27 | +const kernel = new ContextKernel({ |
| 28 | + router: { |
| 29 | + tokenCompressionThreshold: 10000, |
| 30 | + allowPremiumEscalation: true, |
| 31 | + modelRegistry: { |
| 32 | + local_text: { provider: "ollama", model: "lfm2:latest" }, |
| 33 | + local_vision: { provider: "ollama", model: "qwen3-vl:latest" }, |
| 34 | + premium: { provider: "anthropic", model: "claude-sonnet-4-6" } |
| 35 | + }, |
| 36 | + routeMap: { |
| 37 | + textDefault: "local_text", |
| 38 | + multimodal: "local_vision", |
| 39 | + urgent: "premium", |
| 40 | + codeHighContext: "premium" |
| 41 | + } |
| 42 | + }, |
| 43 | + policy: { |
| 44 | + postOnlyMode: false, |
| 45 | + rules: [ |
| 46 | + { |
| 47 | + id: "safe-actions", |
| 48 | + kind: "action_allowlist", |
| 49 | + actions: ["send", "post", "tool_call"] |
| 50 | + } |
| 51 | + ] |
| 52 | + } |
| 53 | +}); |
| 54 | + |
| 55 | +const decision = await kernel.decide({ |
| 56 | + sessionId: "abc", |
| 57 | + timestamp: new Date().toISOString(), |
| 58 | + messages: [{ role: "user", content: "Help me refactor this repo" }], |
| 59 | + estimatedTokens: 12000 |
| 60 | +}); |
| 61 | +``` |
| 62 | + |
| 63 | +## Quick start (CLI) |
| 64 | + |
| 65 | +```bash |
| 66 | +context-kernel --config ./examples/kernel.config.json --input ./examples/input.json |
| 67 | +``` |
| 68 | + |
| 69 | +## Adapters |
| 70 | + |
| 71 | +- `context-kernel/adapters/openclaw` |
| 72 | +- `context-kernel/adapters/http` |
| 73 | + |
| 74 | +## Presets |
| 75 | + |
| 76 | +- `examples/preset.openclaw.json` |
| 77 | +- `examples/preset.generic.json` |
| 78 | + |
| 79 | +## Service naming map |
| 80 | + |
| 81 | +- `ContextKernel`, `RouteEngine`, `BudgetGuard`, `ContextCompactor` |
| 82 | +- `PolicyGate`, `MemorySignal`, `TraceLedger` |
| 83 | +- `BridgeOpenClaw`, `BridgeHTTP` |
| 84 | + |
| 85 | +## Output contract |
| 86 | + |
| 87 | +Main decision object includes: |
| 88 | + |
| 89 | +- `route` |
| 90 | +- `compress` |
| 91 | +- `policyVerdicts` |
| 92 | +- `memoryCandidates` |
| 93 | +- `actions` |
| 94 | + |
| 95 | +Audit events include: |
| 96 | + |
| 97 | +- `started`, `classified`, `guard_blocked`, `routed`, `compressed`, `completed`, `failed` |
| 98 | + |
| 99 | +## Policy DSL |
| 100 | + |
| 101 | +Rule kinds: |
| 102 | + |
| 103 | +- `action_allowlist` |
| 104 | +- `quiet_hours` |
| 105 | +- `secret_regex` |
| 106 | + |
| 107 | +Each rule has stable `id`, optional `reason`, optional `severity`. |
| 108 | + |
| 109 | +## Memory candidate contract |
| 110 | + |
| 111 | +Each candidate includes: |
| 112 | + |
| 113 | +- `summary` |
| 114 | +- `tags` |
| 115 | +- `priority` |
| 116 | +- `confidence` (`0..1`) |
| 117 | +- `source` (`messageIndexes`, extraction strategy) |
| 118 | +- optional `writebackHint` (namespace/upsert/ttl) |
| 119 | + |
| 120 | +## Development |
| 121 | + |
| 122 | +```bash |
| 123 | +npm install |
| 124 | +npm run build |
| 125 | +npm test |
| 126 | +``` |
| 127 | + |
| 128 | +## CI and release |
| 129 | + |
| 130 | +- CI workflow: `.github/workflows/ci.yml` |
| 131 | +- Release workflow: `.github/workflows/release.yml` |
| 132 | +- Add `NPM_TOKEN` secret in GitHub Actions |
| 133 | +- Tag and push: `git tag v0.1.0 && git push origin v0.1.0` |
0 commit comments