@deltrace/cli 0.1.2 → 0.1.4
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 +82 -15
- package/dist/cli.js +39 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,33 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# compression-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The chunking engine, AI proxy, and user API for Deltrace. Parses source files with tree-sitter, stores semantic code chunks in RDS via S3, and injects compressed codebase context into every Claude or Codex request.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
Before every prompt, a `UserPromptSubmit` hook runs `sync.ts`. It walks the current working directory, hashes each file, and POSTs changed files to the **chunker**. The chunker parses each file with tree-sitter into semantic `CodeChunk[]` objects and stores them in RDS (keyed by content hash — unchanged files are skipped). When a Claude Code or Codex request arrives at the **proxy**, it creates a job in the `jobs` table, pushes it to SQS, and a **Minions inference worker** (Qwen2.5-Coder-14B on a GPU box) pulls the message, runs the MinionS protocol against all workspace chunks, and writes a compressed codebase summary back. The proxy polls the row, injects the summary as `<codebase_context>` into the system prompt, and forwards to `api.anthropic.com` or `api.openai.com` with the user's own API key. If the worker doesn't finish in time, the proxy degrades gracefully and forwards without context.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Processes
|
|
14
|
+
|
|
15
|
+
Three PM2 processes, each on its own port. nginx terminates TLS on 443 and routes by path prefix — ports 3000/3001/3002 are never exposed to the internet.
|
|
16
|
+
|
|
17
|
+
| Process | Port | Handles |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `proxy` | 3000 | `/ws/:id/v1/*` — AI request forwarding, pure I/O |
|
|
20
|
+
| `chunker` | 3001 | `/upload`, `/auth/activate` — file ingestion, tree-sitter |
|
|
21
|
+
| `api` | 3002 | `/api/*` — user auth, API keys, repos, usage stats |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Codebase structure
|
|
6
26
|
|
|
7
|
-
```bash
|
|
8
|
-
npm install -g @deltrace/cli
|
|
9
27
|
```
|
|
28
|
+
src/
|
|
29
|
+
├── proxy.ts — Port 3000. AI proxy routes.
|
|
30
|
+
├── chunker-server.ts — Port 3001. File ingestion.
|
|
31
|
+
├── api-server.ts — Port 3002. User-facing API server.
|
|
32
|
+
├── userApi.ts — Route handlers for api-server (me, keys, repos, usage).
|
|
33
|
+
├── store.ts — All PostgreSQL access. Fetches DB credentials from AWS
|
|
34
|
+
│ Secrets Manager at startup — no DATABASE_URL needed in env.
|
|
35
|
+
├── session.ts — Redis session store. Falls back to in-memory Map in dev.
|
|
36
|
+
├── s3.ts — Chunk blob storage helpers.
|
|
37
|
+
├── sqs.ts — SQS helpers for Minions job dispatch.
|
|
38
|
+
├── chunker.ts — AST-based semantic chunking via tree-sitter.
|
|
39
|
+
├── treeSitter.ts — WASM tree-sitter init and language loading.
|
|
40
|
+
├── languageMap.ts — File extension → language + WASM mapping.
|
|
41
|
+
├── tokenizer.ts — Token estimation and overlap splitting.
|
|
42
|
+
├── types.ts — Shared types (CodeChunk, CompressedChunk, etc.)
|
|
43
|
+
├── sync.ts — Pre-prompt hook: walks cwd, uploads changed files.
|
|
44
|
+
├── login.ts — OAuth setup for Claude Code.
|
|
45
|
+
├── login-codex.ts — OAuth setup for Codex.
|
|
46
|
+
└── cli.ts — deltrace help entry point.
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Infrastructure
|
|
52
|
+
|
|
53
|
+
| Component | Details |
|
|
54
|
+
|---|---|
|
|
55
|
+
| EC2 | t3.medium — proxy + chunker + api as PM2 processes |
|
|
56
|
+
| Database | RDS PostgreSQL — credentials auto-rotated via Secrets Manager |
|
|
57
|
+
| Credentials | EC2 IAM role — no API keys in env |
|
|
58
|
+
| Session state | ElastiCache Redis (in-memory fallback for dev) |
|
|
59
|
+
| Chunk storage | S3 |
|
|
60
|
+
| Job queue | SQS → Minions GPU worker |
|
|
61
|
+
| TLS | nginx + Let's Encrypt |
|
|
62
|
+
| Process manager | PM2 |
|
|
63
|
+
|
|
64
|
+
---
|
|
10
65
|
|
|
11
|
-
##
|
|
66
|
+
## Commands
|
|
12
67
|
|
|
13
|
-
**Claude Code:**
|
|
14
68
|
```bash
|
|
15
|
-
|
|
69
|
+
npm run dev # run with ts-node
|
|
70
|
+
npm run build # compile TypeScript → dist/
|
|
71
|
+
npm start # run compiled output
|
|
72
|
+
|
|
73
|
+
npm run compressor:claude # OAuth setup for Claude Code
|
|
74
|
+
npm run compressor:codex # OAuth setup for Codex
|
|
75
|
+
npm run teardown:claude # undo Claude Code setup
|
|
76
|
+
npm run teardown:codex # undo Codex setup
|
|
77
|
+
npm run sync # manually upload cwd to server
|
|
16
78
|
```
|
|
17
79
|
|
|
18
|
-
|
|
80
|
+
## Deploy (EC2)
|
|
81
|
+
|
|
19
82
|
```bash
|
|
20
|
-
|
|
83
|
+
git pull && npm run build && pm2 restart all
|
|
21
84
|
```
|
|
22
85
|
|
|
23
|
-
|
|
86
|
+
## Migrations
|
|
24
87
|
|
|
25
|
-
|
|
88
|
+
Run once against RDS when deploying schema changes:
|
|
26
89
|
|
|
27
90
|
```bash
|
|
28
|
-
|
|
91
|
+
psql $DATABASE_URL -f migrations/001_compression_tables.sql
|
|
92
|
+
psql $DATABASE_URL -f migrations/002_invite.sql
|
|
29
93
|
```
|
|
30
94
|
|
|
31
|
-
##
|
|
95
|
+
## Publishing the CLI
|
|
32
96
|
|
|
33
|
-
|
|
97
|
+
```bash
|
|
98
|
+
npm version patch --no-git-tag-version
|
|
99
|
+
npm publish --access public
|
|
100
|
+
```
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const [cmd, sub] = process.argv.slice(2);
|
|
4
|
+
const help = `
|
|
5
|
+
Deltrace — codebase context compression for AI coding agents
|
|
6
|
+
|
|
7
|
+
Commands:
|
|
8
|
+
deltrace setup claude Set up Claude Code (writes ~/.claude/settings.json)
|
|
9
|
+
deltrace setup codex Set up Codex (writes ~/.codex/config.toml)
|
|
10
|
+
deltrace teardown Remove Deltrace config and hooks from this machine
|
|
11
|
+
|
|
12
|
+
Sync runs automatically before every prompt once set up.
|
|
13
|
+
Your API keys are forwarded directly and never stored.
|
|
14
|
+
|
|
15
|
+
docs: deltrace.com
|
|
16
|
+
`;
|
|
17
|
+
if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') {
|
|
18
|
+
console.log(help);
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
if (cmd === 'setup') {
|
|
22
|
+
if (sub === 'claude') {
|
|
23
|
+
require('./login');
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
if (sub === 'codex') {
|
|
27
|
+
require('./login-codex');
|
|
28
|
+
process.exit(0);
|
|
29
|
+
}
|
|
30
|
+
console.error(` Unknown agent: ${sub ?? '(none)'}\n Usage: deltrace setup claude|codex`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
if (cmd === 'teardown') {
|
|
34
|
+
require('./teardown');
|
|
35
|
+
require('./teardown-codex');
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
console.error(` Unknown command: ${cmd}\n${help}`);
|
|
39
|
+
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deltrace/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Codebase context compression for AI coding agents",
|
|
5
5
|
"files": [
|
|
6
|
+
"dist/cli.js",
|
|
6
7
|
"dist/login.js",
|
|
7
8
|
"dist/login-codex.js",
|
|
8
9
|
"dist/sync.js",
|
|
@@ -10,10 +11,8 @@
|
|
|
10
11
|
"dist/teardown-codex.js"
|
|
11
12
|
],
|
|
12
13
|
"bin": {
|
|
13
|
-
"deltrace
|
|
14
|
-
"deltrace-
|
|
15
|
-
"deltrace-sync": "dist/sync.js",
|
|
16
|
-
"deltrace-teardown": "dist/teardown.js"
|
|
14
|
+
"deltrace": "dist/cli.js",
|
|
15
|
+
"deltrace-sync": "dist/sync.js"
|
|
17
16
|
},
|
|
18
17
|
"scripts": {
|
|
19
18
|
"dev": "ts-node src/index.ts",
|
|
@@ -32,6 +31,7 @@
|
|
|
32
31
|
"dependencies": {
|
|
33
32
|
"@aws-sdk/client-s3": "^3.1042.0",
|
|
34
33
|
"@aws-sdk/client-secrets-manager": "^3.1043.0",
|
|
34
|
+
"@aws-sdk/client-sesv2": "^3.1044.0",
|
|
35
35
|
"@aws-sdk/client-sqs": "^3.0.0",
|
|
36
36
|
"aws-jwt-verify": "^5.1.1",
|
|
37
37
|
"ioredis": "^5.3.0",
|