@muthuishere/ctx-optimize 0.4.2 → 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 CHANGED
@@ -3,7 +3,7 @@
3
3
  [![CI](https://github.com/muthuishere/ctx-optimize/actions/workflows/ci.yml/badge.svg)](https://github.com/muthuishere/ctx-optimize/actions/workflows/ci.yml)
4
4
  [![Go Reference](https://pkg.go.dev/badge/github.com/muthuishere/ctx-optimize.svg)](https://pkg.go.dev/github.com/muthuishere/ctx-optimize)
5
5
  [![npm](https://img.shields.io/npm/v/@muthuishere/ctx-optimize?logo=npm)](https://www.npmjs.com/package/@muthuishere/ctx-optimize)
6
- [![benchmark](https://img.shields.io/badge/benchmark-run%20it%20yourself-4ade80)](https://muthuishere.github.io/ctx-optimize-site/proof/agent/)
6
+ [![benchmark](https://img.shields.io/badge/benchmark-run%20it%20yourself-4ade80)](proof/agent/)
7
7
  [![platforms](https://img.shields.io/badge/platforms-macOS%20%7C%20Linux%20%7C%20Windows-blue)](https://www.npmjs.com/package/@muthuishere/ctx-optimize)
8
8
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
9
9
 
@@ -36,6 +36,10 @@ already run.
36
36
  > learning loop, merge/export (json/dot/graphml/csv/obsidian), **scripted
37
37
  > remote push/pull**, and **multi-module monorepo support** (`scan` /
38
38
  > `init --scan` / parallel fan-out `add` / navigator + federated queries).
39
+ > New on main (unreleased): **native sources** — databases, buckets, queues,
40
+ > and external APIs enter the store by env-var name (`ctx-optimize add
41
+ > BILLING_DB_URL`); 9 wire-protocol connectors in a companion binary — see
42
+ > [Databases, buckets, queues, APIs](#databases-buckets-queues-apis--native-sources).
39
43
  > New in v0.4 (**breaking**): **the remote is your script** — the binary
40
44
  > ships no transport of its own; `remote push`/`pull` run the commands you
41
45
  > declare in the committed config (`remote init` and the built-in
@@ -56,7 +60,7 @@ already run.
56
60
  > packs (`routes add` / `manifests add`, name or GitHub URL) exactly like
57
61
  > grammar packs. Exact call edges (x/tools + LSP) are next — see `openspec/`.
58
62
 
59
- **Site, demos, benchmarks:** https://muthuishere.github.io/ctx-optimize-site/
63
+ **Demos, benchmarks, proof:** [`benchmarks/`](benchmarks/) · [`proof/`](proof/) — everything reproducible from this repo.
60
64
  — landing page, unedited demos, and the full proof write-up. Everything below
61
65
  is reproducible; see [Proof](#proof--reproducible-not-our-word).
62
66
 
@@ -134,8 +138,12 @@ ctx-optimize change-plan "RefundService"
134
138
  ctx-optimize sync
135
139
  ctx-optimize adapters run
136
140
 
137
- # feed ANY system through the universal adapter door (strictly validated)
138
- ./my-postgres-adapter | ctx-optimize add --json -
141
+ # native sources: a database/bucket/queue/API by env-var name the value
142
+ # is a URL, its scheme picks the connector; recorded, refreshed on every up
143
+ ctx-optimize add BILLING_DB_URL
144
+
145
+ # feed ANY other system through the universal adapter door (strictly validated)
146
+ ./my-exotic-adapter | ctx-optimize add --json -
139
147
 
140
148
  # combine module stores into one view; dump for other tools
141
149
  ctx-optimize merge api worker billing --into everything
@@ -198,6 +206,41 @@ Upgrading from v0.3: `remote init` and the built-in `file://`/`s3://`
198
206
  transports are gone. A legacy URL-shaped config still loads but is inert —
199
207
  `push`/`pull` print the migration pointer.
200
208
 
209
+ ## Databases, buckets, queues, APIs — native sources
210
+
211
+ **A source is an environment variable name. Its value is a URL. The URL
212
+ scheme picks the connector.** One command from zero to "refreshed on every
213
+ `up`":
214
+
215
+ ```sh
216
+ ctx-optimize adapters help postgres # setup card: value format, credential params, paste-ready commands
217
+ export BILLING_DB_URL='postgres://reader:$PG_PASS@db.internal:5432/billing' # or .ctxoptimize/.env (gitignored by construction)
218
+ ctx-optimize add BILLING_DB_URL # resolve → dial → capture → merge → recorded in config sources
219
+ ```
220
+
221
+ Nine wire-protocol-native connectors — **postgres, mysql, mongodb, redis,
222
+ kafka, nats, s3** (MinIO/R2 via endpoint hosts, bare AWS via the credential
223
+ chain), **mssql**, and **openapi** (http(s) URL or a spec file path) — no
224
+ pg_dump/atlas/tbls needed on any machine. Captures are the **logical shape**
225
+ a developer reasons about: system schemas skipped, a partitioned table is one
226
+ node with `partitions: N`, bounded samples with every cap reported. Measured:
227
+ a 100-table / 3-schema postgres captures in **31 ms** including connect
228
+ (pg_dump 101 ms, atlas 248 ms, tbls 1356 ms) — and where a 100-partition
229
+ table plus 500 Timescale chunks bloat other tools to 600–716 raw tables, it
230
+ emits **101 logical tables**.
231
+
232
+ Secret hygiene is structural: argv and committed config carry env-var
233
+ **names** only (a literal password in an entry is a hard error), values
234
+ resolve process env → `.ctxoptimize/.env` → root `.env` in memory at dial
235
+ time, stored ids are sanitized, and every output is scrubbed. A teammate
236
+ without the credentials still runs `up` cleanly — that source is a one-line
237
+ skip and the nodes arrive via `remote pull`; `--strict` turns skips into CI
238
+ failures. Recorded sources refresh on `up` under a 24h TTL
239
+ (`--sources=always|never`). The drivers live in a **companion binary**,
240
+ `ctx-optimize-adapters`, shipped beside the main one in every archive and
241
+ npm package — the main binary stays driver-free and exactly as fast, and
242
+ execs the sibling only when a source dials.
243
+
201
244
  ## Multi-module — monorepos get one graph per module, plus a navigator
202
245
 
203
246
  One giant graph for a 300-module monorepo helps nobody: people work in one
@@ -249,7 +292,7 @@ Two kinds of evidence, both runnable.
249
292
 
250
293
  **Speed vs graphify** (raw data in [`benchmarks/`](benchmarks/)): a 12k-file
251
294
  corpus gathered in **0.67s vs 8.88s**, queries **~4× faster**, a smaller
252
- store. Methodology on the site.
295
+ store. Methodology beside the raw data in [`benchmarks/`](benchmarks/).
253
296
 
254
297
  **What an agent actually saves.** A headless harness lets the *same* model
255
298
  answer a set of questions **three ways** over OpenRouter — plain shell,
@@ -279,16 +322,42 @@ bash proof/agent/run-bench.sh # defaults: gorilla/mux, openai/gpt-4o-m
279
322
 
280
323
  Or fork and click **Run workflow** — [`.github/workflows/benchmark.yml`](.github/workflows/benchmark.yml)
281
324
  runs it headless on a clean runner and publishes the table to the job summary.
282
- Harness + full write-up: https://muthuishere.github.io/ctx-optimize-site/proof/agent/
325
+ Harness + full write-up: [`proof/agent/`](proof/agent/)
326
+
327
+ **The model ladder** ([`benchmarks/agent-model-bench/`](benchmarks/agent-model-bench/)):
328
+ same prebuilt linux-kernel store (~274k nodes), same 8 block-layer questions,
329
+ one fresh agent session per model, answers judged blind against withheld
330
+ golden keys:
331
+
332
+ | model · harness | score /80 | avg s/question | tool calls (8 q) |
333
+ |---|---|---|---|
334
+ | Fable 5 · Claude Code | **80** | 24.6 | 23 |
335
+ | Sonnet 5 · Claude Code | **80** | 17.5 | 25 |
336
+ | Opus 4.8 · Claude Code | **79** | 19.0 | 22 |
337
+ | Haiku 4.5 · Claude Code | **72** | 13.6 | 18 |
338
+ | gpt-4o-mini · toolnexus, one-shot | **54** | 9.4 | 24 |
339
+
340
+ The store is model-portable: the cheapest Claude tier lands 90% of frontier
341
+ quality at half the wall time, and a $0.15/M-token model reaches ~70% — for
342
+ $0.015 total — when the mandatory protocol from the committed
343
+ `.ctxoptimize/instructions.md` card ("Small models & custom runtimes") is
344
+ pinned in its system prompt. Without that protocol the same small model
345
+ scored 23/80. One-shot per question beats a continuous loop: same score,
346
+ 7× cheaper, no cross-question bleed.
283
347
 
284
348
  ## .ctxoptimize/ — config that travels with the repo
285
349
 
286
350
  ```
287
351
  .ctxoptimize/
288
- config.json name + remote commands (+ modules[] in a monorepo)
352
+ config.json name + remote commands + sources[] (+ modules[] in a monorepo)
353
+ instructions.md the committed usage card agents read — managed block,
354
+ version-stamped, refreshed by `up` (upgrade-only; your
355
+ edits outside the markers are never touched)
289
356
  adapters/ drop scripts here — every .js/.py/.sh runs on `add`
290
357
  push.js / pull.js your transport scripts (init writes an inert *.sample pair)
291
358
  remote.example.md transport recipes: git lane, s3 lane, custom
359
+ .gitignore covers .env* by construction — put source URLs with
360
+ secrets in .ctxoptimize/.env, never in config
292
361
  ```
293
362
 
294
363
  `config.json`:
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher for the capture companion: resolves the platform sub-package
3
+ // installed via optionalDependencies and execs its ctx-optimize-adapters
4
+ // binary (shipped beside ctx-optimize in the same bin/). No postinstall.
5
+ "use strict";
6
+ const { spawn } = require("child_process");
7
+ const path = require("path");
8
+
9
+ const platformMap = {
10
+ "darwin-arm64": "@muthuishere/ctx-optimize-darwin-arm64",
11
+ "darwin-x64": "@muthuishere/ctx-optimize-darwin-x64",
12
+ "linux-arm64": "@muthuishere/ctx-optimize-linux-arm64",
13
+ "linux-x64": "@muthuishere/ctx-optimize-linux-x64",
14
+ "win32-x64": "@muthuishere/ctx-optimize-windows-x64",
15
+ };
16
+
17
+ const key = `${process.platform}-${process.arch}`;
18
+ const pkg = platformMap[key];
19
+ if (!pkg) {
20
+ console.error(`ctx-optimize-adapters: unsupported platform ${key}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ const exe =
25
+ process.platform === "win32" ? "ctx-optimize-adapters.exe" : "ctx-optimize-adapters";
26
+ let binPath;
27
+ try {
28
+ binPath = path.join(path.dirname(require.resolve(`${pkg}/package.json`)), "bin", exe);
29
+ } catch {
30
+ console.error(
31
+ `ctx-optimize-adapters: platform package ${pkg} is not installed.\n` +
32
+ `Your package manager skipped an optional dependency — reinstall with:\n` +
33
+ ` npm install -g @muthuishere/ctx-optimize`
34
+ );
35
+ process.exit(1);
36
+ }
37
+
38
+ const child = spawn(binPath, process.argv.slice(2), { stdio: "inherit" });
39
+ child.on("exit", (code, signal) => {
40
+ if (signal) process.kill(process.pid, signal);
41
+ process.exit(code === null ? 1 : code);
42
+ });
43
+ child.on("error", (err) => {
44
+ console.error(`ctx-optimize-adapters: failed to start binary: ${err.message}`);
45
+ process.exit(1);
46
+ });
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@muthuishere/ctx-optimize",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "description": "Gather a codebase (and its world) into one local knowledge store an AI agent answers from — deterministic, no LLM API, no DB.",
5
5
  "bin": {
6
- "ctx-optimize": "bin/ctx-optimize.js"
6
+ "ctx-optimize": "bin/ctx-optimize.js",
7
+ "ctx-optimize-adapters": "bin/ctx-optimize-adapters.js"
7
8
  },
8
9
  "files": [
9
10
  "bin/",
@@ -15,10 +16,10 @@
15
16
  "url": "git+https://github.com/muthuishere/ctx-optimize.git"
16
17
  },
17
18
  "optionalDependencies": {
18
- "@muthuishere/ctx-optimize-darwin-arm64": "0.4.2",
19
- "@muthuishere/ctx-optimize-darwin-x64": "0.4.2",
20
- "@muthuishere/ctx-optimize-linux-arm64": "0.4.2",
21
- "@muthuishere/ctx-optimize-linux-x64": "0.4.2",
22
- "@muthuishere/ctx-optimize-windows-x64": "0.4.2"
19
+ "@muthuishere/ctx-optimize-darwin-arm64": "0.5.1",
20
+ "@muthuishere/ctx-optimize-darwin-x64": "0.5.1",
21
+ "@muthuishere/ctx-optimize-linux-arm64": "0.5.1",
22
+ "@muthuishere/ctx-optimize-linux-x64": "0.5.1",
23
+ "@muthuishere/ctx-optimize-windows-x64": "0.5.1"
23
24
  }
24
25
  }