codex-token-saver 1.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/LICENSE +21 -0
- package/README.md +332 -0
- package/bin/codex-context-init.js +160 -0
- package/package.json +104 -0
- package/src/core/config.js +250 -0
- package/src/core/engine/doctor.js +1 -0
- package/src/core/engine/global.js +1 -0
- package/src/core/engine/index.js +19 -0
- package/src/core/engine/query.js +1 -0
- package/src/core/engine/sync.js +1 -0
- package/src/core/engine/upgrade.js +1 -0
- package/src/core/logger.js +1 -0
- package/src/core/parsers/genericParser.js +16 -0
- package/src/core/parsers/index.js +19 -0
- package/src/core/parsers/javascriptParser.js +41 -0
- package/src/core/parsers/jsonParser.js +17 -0
- package/src/core/parsers/markdownParser.js +13 -0
- package/src/core/parsers/pythonParser.js +24 -0
- package/src/core/parsers/typescriptParser.js +5 -0
- package/src/core/scoring/queryScorer.js +104 -0
- package/src/core/services/AgentService.js +16 -0
- package/src/core/services/ContextService.js +15 -0
- package/src/core/services/RepositoryService.js +19 -0
- package/src/core/utils/config.js +1 -0
- package/src/core/utils/fsSafe.js +28 -0
- package/src/core/utils/logger.js +49 -0
- package/src/core.js +881 -0
- package/src/extension/extension.cjs +163 -0
- package/src/extension.js +141 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thamizharasan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# Codex Token Saver
|
|
2
|
+
|
|
3
|
+
A local-first CLI + VS Code extension that prepares Codex with compressed repository context so it can search less, read fewer files, and start coding with better context.
|
|
4
|
+
|
|
5
|
+
Codex Token Saver is published as `codex-token-saver` and exposes the `codex-context-init` CLI command. It supports:
|
|
6
|
+
|
|
7
|
+
- CLI workflows
|
|
8
|
+
- VS Code extension commands
|
|
9
|
+
- Global Codex instructions in `~/.codex/AGENTS.md`
|
|
10
|
+
- Per-project `.codex/AGENTS.md`
|
|
11
|
+
- Precomputed `.codex/context` artifacts
|
|
12
|
+
- Deterministic query output in `.codex/context/relevant.md`
|
|
13
|
+
|
|
14
|
+
## Problem
|
|
15
|
+
|
|
16
|
+
AI coding agents often spend tokens rediscovering repository structure, reading unrelated files, and rebuilding context across sessions. That repeated exploration is useful, but it can be wasteful when the same project shape, files, symbols, dependencies, routes, and recent changes can be summarized ahead of time.
|
|
17
|
+
|
|
18
|
+
Codex Token Saver creates compact, local context files that Codex can read before doing broad repository search.
|
|
19
|
+
|
|
20
|
+
## Before
|
|
21
|
+
|
|
22
|
+
```mermaid
|
|
23
|
+
flowchart TD
|
|
24
|
+
A[User asks Codex for a change] --> B[Codex searches repository]
|
|
25
|
+
B --> C[Codex opens many files]
|
|
26
|
+
C --> D[Codex builds temporary context]
|
|
27
|
+
D --> E[Codex edits code]
|
|
28
|
+
E --> F[Context is lost after the session]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## After
|
|
32
|
+
|
|
33
|
+
```mermaid
|
|
34
|
+
flowchart TD
|
|
35
|
+
A[Run codex-context-init index] --> B[Generate .codex/context artifacts]
|
|
36
|
+
B --> C[Update .codex/AGENTS.md]
|
|
37
|
+
C --> D[User asks Codex for a change]
|
|
38
|
+
D --> E[Codex reads compact context first]
|
|
39
|
+
E --> F[Codex opens fewer, more relevant files]
|
|
40
|
+
F --> G[Codex edits code]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Architecture
|
|
44
|
+
|
|
45
|
+
```mermaid
|
|
46
|
+
flowchart LR
|
|
47
|
+
A[Repository] --> B[Context Engine]
|
|
48
|
+
B --> C[.codex/context]
|
|
49
|
+
C --> D[summary.md]
|
|
50
|
+
C --> E[files.md]
|
|
51
|
+
C --> F[symbols.md]
|
|
52
|
+
C --> G[dependencies.md]
|
|
53
|
+
C --> H[routes.md]
|
|
54
|
+
C --> I[index.json]
|
|
55
|
+
C --> J[recent_changes.md]
|
|
56
|
+
C --> M[relevant.md]
|
|
57
|
+
B --> K[.codex/AGENTS.md]
|
|
58
|
+
K --> L[Codex Agent]
|
|
59
|
+
C --> L
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Key Features
|
|
63
|
+
|
|
64
|
+
- Shared core engine used by both CLI and VS Code
|
|
65
|
+
- Structured logging in `.codex/logs/latest.log`
|
|
66
|
+
- Atomic writes for generated context artifacts
|
|
67
|
+
- Global Codex token-saving rules
|
|
68
|
+
- Project-level `AGENTS.md` setup
|
|
69
|
+
- Context indexing
|
|
70
|
+
- Deterministic importance scoring
|
|
71
|
+
- File inventory
|
|
72
|
+
- Symbol extraction
|
|
73
|
+
- Dependency summary
|
|
74
|
+
- Route hints
|
|
75
|
+
- Recent git changes
|
|
76
|
+
- Context doctor
|
|
77
|
+
- Context clean
|
|
78
|
+
- Context query with `.codex/context/relevant.md`
|
|
79
|
+
- Debug diagnostics
|
|
80
|
+
- CLI + VS Code extension
|
|
81
|
+
- Local-only indexing
|
|
82
|
+
- Cross-platform support: Windows, macOS, Linux
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
Install globally:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
npm install -g codex-token-saver
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Use locally during development:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
npm install
|
|
96
|
+
npm link
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Run the VS Code extension locally:
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
npm install
|
|
103
|
+
code .
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Press F5 and choose `Run Extension` if prompted. In the Extension Development Host, open a test folder, then run `Codex Context` commands from the Command Palette.
|
|
107
|
+
|
|
108
|
+
## Quick Start
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
codex-context-init global
|
|
112
|
+
codex-context-init sync
|
|
113
|
+
codex-context-init index
|
|
114
|
+
codex-context-init doctor
|
|
115
|
+
codex-context-init context doctor
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
For task-specific narrowing after indexing:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
codex-context-init query "what files handle authentication?"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Recommended Workflows
|
|
125
|
+
|
|
126
|
+
### First-Time New Project
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
codex-context-init global
|
|
130
|
+
codex-context-init new my-app
|
|
131
|
+
cd my-app
|
|
132
|
+
codex-context-init index
|
|
133
|
+
codex-context-init doctor
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Existing Project
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
cd existing-repo
|
|
140
|
+
codex-context-init sync
|
|
141
|
+
codex-context-init project upgrade
|
|
142
|
+
codex-context-init index
|
|
143
|
+
codex-context-init query "what files are relevant to the change?"
|
|
144
|
+
codex-context-init context doctor
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### VS Code
|
|
148
|
+
|
|
149
|
+
Run these from the Command Palette:
|
|
150
|
+
|
|
151
|
+
```txt
|
|
152
|
+
Codex Context: Setup Global Instructions
|
|
153
|
+
Codex Context: Sync Current Workspace
|
|
154
|
+
Codex Context: Index Current Workspace
|
|
155
|
+
Codex Context: Doctor Context Artifacts
|
|
156
|
+
Codex Context: Query Relevant Files
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Phase 1: Reliability Foundation
|
|
160
|
+
|
|
161
|
+
The CLI and VS Code extension are thin wrappers around shared core functions. Core logic returns structured result objects, while each surface decides how to display output.
|
|
162
|
+
|
|
163
|
+
Phase 1 includes:
|
|
164
|
+
|
|
165
|
+
- Shared engine modules for sync, index, doctor, upgrade, global setup, and query.
|
|
166
|
+
- Shared services for repository, context, and agent file operations.
|
|
167
|
+
- Shared logger with concise default output and verbose diagnostics.
|
|
168
|
+
- `.codex/logs/latest.log` for local troubleshooting.
|
|
169
|
+
- Atomic writes for generated context artifacts.
|
|
170
|
+
- Node built-in tests via `node --test`.
|
|
171
|
+
|
|
172
|
+
## Phase 2: Deterministic Indexing
|
|
173
|
+
|
|
174
|
+
The Context Engine uses deterministic heuristics only. It does not use embeddings, a vector database, or external APIs.
|
|
175
|
+
|
|
176
|
+
`index.json` includes:
|
|
177
|
+
|
|
178
|
+
- `schemaVersion`
|
|
179
|
+
- `generatedAt`
|
|
180
|
+
- `root`
|
|
181
|
+
- `fileCount`
|
|
182
|
+
- `languageCounts`
|
|
183
|
+
- `files`
|
|
184
|
+
- `importanceScore`
|
|
185
|
+
- `importanceReasons`
|
|
186
|
+
|
|
187
|
+
Each file entry can include:
|
|
188
|
+
|
|
189
|
+
- path, extension, size, and hash
|
|
190
|
+
- imports and exports
|
|
191
|
+
- symbols and headings
|
|
192
|
+
- route hints
|
|
193
|
+
- test hints
|
|
194
|
+
- parser metadata
|
|
195
|
+
|
|
196
|
+
The generated Markdown artifacts stay compact and are intended to guide Codex toward the smallest useful source file set.
|
|
197
|
+
|
|
198
|
+
## Phase 3: Context Query
|
|
199
|
+
|
|
200
|
+
After indexing, `codex-context-init query` reads only the existing `.codex/context/index.json`, applies deterministic scoring, and writes `.codex/context/relevant.md`.
|
|
201
|
+
|
|
202
|
+
`relevant.md` is a concise task-specific shortlist. It contains file paths, scores, reasons, and detected metadata such as symbols, routes, exports, and headings. It does not dump source code.
|
|
203
|
+
|
|
204
|
+
Example:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
codex-context-init query "where is authentication handled?"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Use this before a focused Codex task when you want Codex to inspect a narrower set of files first.
|
|
211
|
+
|
|
212
|
+
## Command Reference
|
|
213
|
+
|
|
214
|
+
| Command | What it does | When to use it | Overwrites files? | Example |
|
|
215
|
+
| --- | --- | --- | --- | --- |
|
|
216
|
+
| `codex-context-init global` | Creates or updates global Codex token-saving instructions. | Once per machine. | Only managed block in `~/.codex/AGENTS.md`; preserves user content. | `codex-context-init global` |
|
|
217
|
+
| `codex-context-init global doctor` | Checks global `AGENTS.md` and managed block. | Debug global setup. | No. | `codex-context-init global doctor` |
|
|
218
|
+
| `codex-context-init new <project-name> [--force]` | Creates a new project with Codex context files. | Starting a new repo. | Skips existing files unless `--force` is passed. | `codex-context-init new my-app` |
|
|
219
|
+
| `codex-context-init sync` | Creates missing project files in the current repo. | Existing repo setup. | No. | `codex-context-init sync` |
|
|
220
|
+
| `codex-context-init doctor` | Checks required project files. | Verify project setup. | No. | `codex-context-init doctor` |
|
|
221
|
+
| `codex-context-init upgrade` | Updates project `.codex/AGENTS.md`. | Refresh project instructions. | Only managed block; preserves user content. | `codex-context-init upgrade` |
|
|
222
|
+
| `codex-context-init project doctor` | Alias for project doctor. | Explicit project checks. | No. | `codex-context-init project doctor` |
|
|
223
|
+
| `codex-context-init project upgrade` | Alias for project upgrade. | Explicit project upgrade. | Only managed block; preserves user content. | `codex-context-init project upgrade` |
|
|
224
|
+
| `codex-context-init index` | Generates `.codex/context` artifacts and upgrades project instructions. | Before asking Codex for project work. | Rewrites generated context artifacts only when changed. | `codex-context-init index` |
|
|
225
|
+
| `codex-context-init index --watch` | Watches files and re-indexes after changes. | Active development. | Same as `index`. | `codex-context-init index --watch` |
|
|
226
|
+
| `codex-context-init context doctor` | Validates context artifacts, `index.json`, file count, timestamp, AGENTS reference, and secret exclusions. | Debug generated context. | No. | `codex-context-init context doctor` |
|
|
227
|
+
| `codex-context-init context clean` | Deletes only `.codex/context`. | Rebuild context from scratch. | Deletes generated context directory only. | `codex-context-init context clean` |
|
|
228
|
+
| `codex-context-init query "<question>" [--top 10]` | Uses only the generated `index.json` to write `.codex/context/relevant.md` with the most relevant files. | Before a focused Codex task. | Writes generated `relevant.md` only. | `codex-context-init query "what files handle authentication?"` |
|
|
229
|
+
| `codex-context-init debug` | Prints OS, Node, CLI, AGENTS, context, and log diagnostics. | Debug local setup. | No. | `codex-context-init debug` |
|
|
230
|
+
|
|
231
|
+
## Generated Files
|
|
232
|
+
|
|
233
|
+
| File | Purpose |
|
|
234
|
+
| --- | --- |
|
|
235
|
+
| `~/.codex/AGENTS.md` | Global Codex token-saving instructions. |
|
|
236
|
+
| `.codex/AGENTS.md` | Project instructions that tell Codex to read generated context first. |
|
|
237
|
+
| `.codex/context/index.json` | Machine-readable index with schema version, file metadata, hashes, imports, exports, symbols, routes, test hints, and importance scores. |
|
|
238
|
+
| `.codex/context/summary.md` | Compact project overview. |
|
|
239
|
+
| `.codex/context/files.md` | Human-readable file map grouped by top-level folder. |
|
|
240
|
+
| `.codex/context/symbols.md` | Detected functions, classes, components, exports, and headings. |
|
|
241
|
+
| `.codex/context/dependencies.md` | Dependency files, package scripts, and dependency names. |
|
|
242
|
+
| `.codex/context/routes.md` | Heuristic route hints from framework and router patterns. |
|
|
243
|
+
| `.codex/context/recent_changes.md` | `git status --short` output when git is available. |
|
|
244
|
+
| `.codex/context/relevant.md` | Optional query-specific shortlist generated from `index.json`. |
|
|
245
|
+
| `.codex/logs/latest.log` | Latest local diagnostic log from CLI or extension operations. |
|
|
246
|
+
| `project_context.md` | User-maintained project goals and scope. |
|
|
247
|
+
| `architecture.md` | User-maintained architecture notes. |
|
|
248
|
+
| `task.md` | User-maintained current task context. |
|
|
249
|
+
| `decision_log.md` | User-maintained durable technical decisions. |
|
|
250
|
+
|
|
251
|
+
## VS Code Commands
|
|
252
|
+
|
|
253
|
+
| Command Palette item | Uses shared core logic | Output |
|
|
254
|
+
| --- | --- | --- |
|
|
255
|
+
| `Codex Context: Setup Global Instructions` | Yes | Notification |
|
|
256
|
+
| `Codex Context: Sync Current Workspace` | Yes | Notification |
|
|
257
|
+
| `Codex Context: Index Current Workspace` | Yes | Output Channel + notification |
|
|
258
|
+
| `Codex Context: Doctor Current Workspace` | Yes | Output Channel |
|
|
259
|
+
| `Codex Context: Doctor Context Artifacts` | Yes | Output Channel |
|
|
260
|
+
| `Codex Context: Query Relevant Files` | Yes | Output Channel + notification |
|
|
261
|
+
| `Codex Context: Upgrade AGENTS.md` | Yes | Notification |
|
|
262
|
+
|
|
263
|
+
## Expected Token Usage Improvements
|
|
264
|
+
|
|
265
|
+
Token savings vary by repository size, task type, and agent behavior. The biggest savings usually come from reducing repeated repository exploration. Small repositories may see modest gains; large repositories and monorepos may see more meaningful gains.
|
|
266
|
+
|
|
267
|
+
Rough estimates, not guaranteed benchmarks:
|
|
268
|
+
|
|
269
|
+
| Repository size | Possible reduction in context/tool exploration |
|
|
270
|
+
| --- | --- |
|
|
271
|
+
| Small repo | 5-15% |
|
|
272
|
+
| Medium repo | 15-35% |
|
|
273
|
+
| Large repo / monorepo | 25-50%+ |
|
|
274
|
+
|
|
275
|
+
## Safety
|
|
276
|
+
|
|
277
|
+
- Local-only indexing.
|
|
278
|
+
- No external API calls.
|
|
279
|
+
- Secret files are ignored, including `.env`, `.env.*`, `*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `secrets.*`, and `credentials.*`.
|
|
280
|
+
- Large files are skipped.
|
|
281
|
+
- `sync` never overwrites existing files.
|
|
282
|
+
- Managed `AGENTS.md` blocks preserve user content outside markers.
|
|
283
|
+
- Query reads the generated `index.json` rather than scanning source files.
|
|
284
|
+
- Context artifacts are written atomically.
|
|
285
|
+
- `context clean` deletes only `.codex/context`.
|
|
286
|
+
|
|
287
|
+
## Limitations
|
|
288
|
+
|
|
289
|
+
- Heuristic parser.
|
|
290
|
+
- Not a vector database.
|
|
291
|
+
- No embeddings in v1.
|
|
292
|
+
- Not direct runtime injection into Codex.
|
|
293
|
+
- Source code remains source of truth.
|
|
294
|
+
- Generated context can become stale unless re-indexed.
|
|
295
|
+
- Query quality depends on the existing index and deterministic heuristic scoring.
|
|
296
|
+
|
|
297
|
+
## Troubleshooting
|
|
298
|
+
|
|
299
|
+
Check project setup:
|
|
300
|
+
|
|
301
|
+
```sh
|
|
302
|
+
codex-context-init doctor
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Check generated context:
|
|
306
|
+
|
|
307
|
+
```sh
|
|
308
|
+
codex-context-init context doctor
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Rebuild generated context:
|
|
312
|
+
|
|
313
|
+
```sh
|
|
314
|
+
codex-context-init context clean
|
|
315
|
+
codex-context-init index
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Use `codex-context-init debug` for local diagnostics. Use `--verbose` with CLI commands for stack traces when debugging command failures.
|
|
319
|
+
|
|
320
|
+
Inspect the latest local log:
|
|
321
|
+
|
|
322
|
+
PowerShell:
|
|
323
|
+
|
|
324
|
+
```powershell
|
|
325
|
+
type .codex\logs\latest.log
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
macOS/Linux:
|
|
329
|
+
|
|
330
|
+
```sh
|
|
331
|
+
cat .codex/logs/latest.log
|
|
332
|
+
```
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
getWatchDirs,
|
|
7
|
+
isIgnoredWorkspacePath,
|
|
8
|
+
runContextClean,
|
|
9
|
+
runContextDoctor,
|
|
10
|
+
runDebug,
|
|
11
|
+
runContextIndex,
|
|
12
|
+
runDoctor,
|
|
13
|
+
runGlobalDoctor,
|
|
14
|
+
runGlobalSetup,
|
|
15
|
+
runNew,
|
|
16
|
+
runProjectDoctor,
|
|
17
|
+
runProjectUpgrade,
|
|
18
|
+
runQuery,
|
|
19
|
+
runSync,
|
|
20
|
+
runUpgrade
|
|
21
|
+
} from "../src/core.js";
|
|
22
|
+
import { createLogger } from "../src/core/logger.js";
|
|
23
|
+
|
|
24
|
+
const rawArgs = process.argv.slice(2);
|
|
25
|
+
const verbose = rawArgs.includes("--verbose");
|
|
26
|
+
const args = rawArgs.filter((arg) => arg !== "--verbose");
|
|
27
|
+
const [command, subcommand, ...rest] = args;
|
|
28
|
+
const options = { force: rest.includes("--force") };
|
|
29
|
+
const logger = createLogger({ verbose });
|
|
30
|
+
|
|
31
|
+
if (!command || command === "--help" || command === "-h" || command === "help") usage(0);
|
|
32
|
+
|
|
33
|
+
function usage(code = 0) {
|
|
34
|
+
logger.info(`Usage:
|
|
35
|
+
codex-context-init new <project-name> [--force]
|
|
36
|
+
codex-context-init global [doctor]
|
|
37
|
+
codex-context-init project <upgrade|doctor>
|
|
38
|
+
codex-context-init index [--watch]
|
|
39
|
+
codex-context-init context <doctor|clean>
|
|
40
|
+
codex-context-init query "<question>" [--top 10]
|
|
41
|
+
codex-context-init sync
|
|
42
|
+
codex-context-init doctor
|
|
43
|
+
codex-context-init debug
|
|
44
|
+
codex-context-init upgrade`);
|
|
45
|
+
process.exit(code);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function printIndexResult(result) {
|
|
49
|
+
logger.info(`Indexed ${result.filesIndexed} file(s)`);
|
|
50
|
+
logger.info(`Wrote ${result.written} changed context artifact(s)`);
|
|
51
|
+
logger.info(`Skipped ${result.skippedLarge} large file(s)`);
|
|
52
|
+
logger.info(`Ignored ${result.ignored} file(s) or directories`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function runWatch() {
|
|
56
|
+
let timer;
|
|
57
|
+
const root = process.cwd();
|
|
58
|
+
const index = () => printIndexResult(runContextIndex());
|
|
59
|
+
index();
|
|
60
|
+
for (const dir of getWatchDirs()) {
|
|
61
|
+
fs.watch(dir, (_event, filename) => {
|
|
62
|
+
if (filename && isIgnoredWorkspacePath(root, path.join(dir, filename.toString()))) return;
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
timer = setTimeout(index, 1000);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
logger.info("Watching for changes. Press Ctrl+C to stop.");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
switch (command) {
|
|
72
|
+
case "new": {
|
|
73
|
+
const result = runNew(subcommand, options);
|
|
74
|
+
logger.info(`Created ${result.root}`);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case "global": {
|
|
78
|
+
if (subcommand === "doctor") {
|
|
79
|
+
const result = runGlobalDoctor();
|
|
80
|
+
for (const item of result.results) logger.info(item.line);
|
|
81
|
+
process.exit(result.ok ? 0 : 1);
|
|
82
|
+
}
|
|
83
|
+
if (subcommand) usage(1);
|
|
84
|
+
const result = runGlobalSetup();
|
|
85
|
+
logger.info(`${result.action === "created" ? "Created" : "Updated"} ~/.codex/AGENTS.md`);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "project": {
|
|
89
|
+
if (subcommand === "upgrade") {
|
|
90
|
+
const result = runProjectUpgrade();
|
|
91
|
+
logger.info(`${result.action === "created" ? "Created" : "Updated"} .codex/AGENTS.md`);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (subcommand === "doctor") {
|
|
95
|
+
const result = runProjectDoctor();
|
|
96
|
+
for (const item of result.results) logger.info(item.line);
|
|
97
|
+
process.exit(result.ok ? 0 : 1);
|
|
98
|
+
}
|
|
99
|
+
usage(1);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case "index": {
|
|
103
|
+
if (subcommand === "--watch" || rest.includes("--watch")) {
|
|
104
|
+
runWatch();
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
printIndexResult(runContextIndex());
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "context": {
|
|
111
|
+
if (subcommand === "doctor") {
|
|
112
|
+
const result = runContextDoctor();
|
|
113
|
+
for (const item of result.results) logger.info(item.line);
|
|
114
|
+
process.exit(result.ok ? 0 : 1);
|
|
115
|
+
}
|
|
116
|
+
if (subcommand === "clean") {
|
|
117
|
+
const result = runContextClean();
|
|
118
|
+
logger.info(`${result.removed ? "Removed" : "No context directory at"} .codex/context`);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
usage(1);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case "query": {
|
|
125
|
+
const topIndex = rest.indexOf("--top");
|
|
126
|
+
const top = topIndex >= 0 ? rest[topIndex + 1] : undefined;
|
|
127
|
+
const result = runQuery(process.cwd(), subcommand, { top });
|
|
128
|
+
logger.info(`Wrote ${result.relevantPath}`);
|
|
129
|
+
for (const match of result.matches) logger.info(`${match.score} ${match.path}`);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case "sync": {
|
|
133
|
+
const result = runSync();
|
|
134
|
+
logger.info(`Created ${result.created} missing file(s)`);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "doctor": {
|
|
138
|
+
const result = runDoctor();
|
|
139
|
+
for (const item of result.results) logger.info(item.line);
|
|
140
|
+
process.exit(result.ok ? 0 : 1);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case "debug": {
|
|
144
|
+
const result = runDebug();
|
|
145
|
+
for (const item of result.results) logger.info(item.line);
|
|
146
|
+
process.exit(result.ok ? 0 : 1);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "upgrade": {
|
|
150
|
+
const result = runUpgrade();
|
|
151
|
+
logger.info(`${result.action === "created" ? "Created" : "Updated"} .codex/AGENTS.md`);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
default:
|
|
155
|
+
usage(command ? 1 : 0);
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
logger.error(error);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "codex-token-saver",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Local-first Codex context engine for reducing repository exploration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"displayName": "Codex Token Saver",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"codex",
|
|
9
|
+
"cli",
|
|
10
|
+
"vscode-extension",
|
|
11
|
+
"context",
|
|
12
|
+
"developer-tools"
|
|
13
|
+
],
|
|
14
|
+
"author": "Thamizharasan",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/thamizharasan/codex-token-saver.git"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"bin/",
|
|
21
|
+
"src/",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"main": "./src/extension/extension.cjs",
|
|
26
|
+
"bin": {
|
|
27
|
+
"codex-context-init": "bin/codex-context-init.js"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"check": "node --check bin/codex-context-init.js && node --check src/core.js && node --check src/extension/extension.cjs",
|
|
31
|
+
"test": "node --test"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"vscode": "^1.80.0"
|
|
35
|
+
},
|
|
36
|
+
"categories": [
|
|
37
|
+
"Other"
|
|
38
|
+
],
|
|
39
|
+
"contributes": {
|
|
40
|
+
"commands": [
|
|
41
|
+
{
|
|
42
|
+
"command": "codexContext.newProject",
|
|
43
|
+
"title": "Codex Context: New Project"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"command": "codexContext.syncWorkspace",
|
|
47
|
+
"title": "Codex Context: Sync Current Workspace"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"command": "codexContext.doctorWorkspace",
|
|
51
|
+
"title": "Codex Context: Doctor Current Workspace"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"command": "codexContext.upgradeAgents",
|
|
55
|
+
"title": "Codex Context: Upgrade AGENTS.md"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"command": "codexContext.setupGlobal",
|
|
59
|
+
"title": "Codex Context: Setup Global Instructions"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"command": "codexContext.doctorGlobal",
|
|
63
|
+
"title": "Codex Context: Doctor Global Instructions"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"command": "codexContext.indexWorkspace",
|
|
67
|
+
"title": "Codex Context: Index Current Workspace"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"command": "codexContext.contextDoctor",
|
|
71
|
+
"title": "Codex Context: Doctor Context Artifacts"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"command": "codexContext.queryRelevant",
|
|
75
|
+
"title": "Codex Context: Query Relevant Files"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"configuration": {
|
|
79
|
+
"title": "Codex Context",
|
|
80
|
+
"properties": {
|
|
81
|
+
"codexContext.autoIndex": {
|
|
82
|
+
"type": "boolean",
|
|
83
|
+
"default": false,
|
|
84
|
+
"description": "Offer to index Codex context on activation for workspaces with fewer than 1000 eligible files."
|
|
85
|
+
},
|
|
86
|
+
"codexContext.watch": {
|
|
87
|
+
"type": "boolean",
|
|
88
|
+
"default": false,
|
|
89
|
+
"description": "Reserved for future context indexing watch mode."
|
|
90
|
+
},
|
|
91
|
+
"codexContext.maxFileSizeKb": {
|
|
92
|
+
"type": "number",
|
|
93
|
+
"default": 300,
|
|
94
|
+
"description": "Maximum file size, in KB, to include in Codex context indexing."
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"bugs": {
|
|
100
|
+
"url": "https://github.com/thamizharasan/codex-token-saver/issues"
|
|
101
|
+
},
|
|
102
|
+
"homepage": "https://github.com/thamizharasan/codex-token-saver#readme",
|
|
103
|
+
"license": "MIT"
|
|
104
|
+
}
|