repo-context-center 0.1.3 → 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 CHANGED
@@ -4,6 +4,13 @@ A context layer for AI coding agents.
4
4
 
5
5
  `repo-context-center` installs a small set of repository instructions and context maps into a target repo so AI coding tools can find the right context faster and avoid rereading noisy files.
6
6
 
7
+ Measure estimated context token savings before using the repo.
8
+
9
+ ```sh
10
+ repo-context-center estimate --compare-naive
11
+ repo-context-center estimate --task "fix Cypress test" --mode compact
12
+ ```
13
+
7
14
  It is not an AI agent. It is not a code analyzer. It does not understand your project automatically yet. It gives agents a durable place to store routing notes, module maps, risk notes, token guidance, and lessons learned.
8
15
 
9
16
  It is designed to work with Codex, Claude Code, Cursor, Copilot-style agents, and other tools that read repository instructions.
@@ -120,13 +127,15 @@ Estimate context overhead:
120
127
 
121
128
  ```sh
122
129
  repo-context-center estimate --compare-naive
123
- repo-context-center estimate --mode investigation --task "fix auth bug" --json
130
+ repo-context-center estimate --task "fix Cypress test" --mode compact
124
131
  ```
125
132
 
126
133
  Token estimates use `ceil(characters / 4)`. They are rough planning numbers,
127
134
  not exact tokenizer output and not model billing estimates. The command is meant
128
135
  to help evaluate whether the context center is reducing broad repo reads enough
129
- to justify its own startup cost.
136
+ to justify its own startup cost. In an empty repo, startup context can be zero
137
+ until templates are installed; after `repo-context-center init`, default context
138
+ files should produce a realistic non-zero startup estimate.
130
139
 
131
140
  ## Recommended AI Agent Workflow
132
141
 
@@ -72,7 +72,7 @@ function formatReport(report) {
72
72
  }
73
73
  }
74
74
  if (report.taskEstimate) {
75
- lines.push("", "Task recommendation:", `- Task: ${report.taskEstimate.task}`, `- Recommended context: ${formatNumber(report.taskEstimate.recommendedContextTokens)} tokens`, `- Likely source: ${formatNumber(report.taskEstimate.likelySourceTokens)} tokens`, `- Likely tests: ${formatNumber(report.taskEstimate.likelyTestTokens)} tokens`);
75
+ lines.push("", "Task recommendation:", `- Task: ${report.taskEstimate.task}`, `- Recommended context: ${formatNumber(report.taskEstimate.recommendedContextTokens)} tokens`, `- Likely source: ${formatNumber(report.taskEstimate.likelySourceTokens)} tokens`, `- Likely tests: ${formatNumber(report.taskEstimate.likelyTestTokens)} tokens`, `- Likely context docs: ${formatNumber(report.taskEstimate.likelyContextTokens)} tokens`);
76
76
  }
77
77
  lines.push("", "Warnings:", ...report.warnings.map((warning) => `- ${warning}`));
78
78
  return `${lines.join("\n")}\n`;
package/dist/cli/index.js CHANGED
File without changes
@@ -9,9 +9,11 @@ export interface TaskTokenEstimate {
9
9
  recommendedContextTokens: number;
10
10
  likelySourceTokens: number;
11
11
  likelyTestTokens: number;
12
+ likelyContextTokens: number;
12
13
  recommendedContextFiles: FileTokenEstimate[];
13
14
  likelySourceFiles: FileTokenEstimate[];
14
15
  likelyTests: FileTokenEstimate[];
16
+ likelyContextFiles: FileTokenEstimate[];
15
17
  }
16
18
  export interface TokenEstimateOptions {
17
19
  cwd: string;
@@ -176,6 +176,111 @@ async function estimateRecommendedFiles(cwd, files, maxFiles) {
176
176
  const limitedFiles = uniqueSorted(files).slice(0, maxFiles);
177
177
  return Promise.all(limitedFiles.map((file) => estimateBySize(cwd, file)));
178
178
  }
179
+ function isContextPath(filePath) {
180
+ const normalized = filePath.replace(/\\/g, "/").replace(/^\.\//, "");
181
+ return normalized === "AGENTS.md"
182
+ || normalized.startsWith("docs/ai-context/")
183
+ || normalized.startsWith(".project-brain/");
184
+ }
185
+ function isTestPath(filePath) {
186
+ const normalized = filePath.replace(/\\/g, "/");
187
+ const parts = normalized.split("/");
188
+ return normalized.startsWith("tests/")
189
+ || normalized.startsWith("cypress/")
190
+ || parts.some((part) => part.toLowerCase().includes("tests"))
191
+ || /\.(spec|test)\.[^.]+$/i.test(normalized);
192
+ }
193
+ function classifyRecommendedPath(filePath) {
194
+ if (isContextPath(filePath)) {
195
+ return "context";
196
+ }
197
+ if (isTestPath(filePath)) {
198
+ return "test";
199
+ }
200
+ return "source";
201
+ }
202
+ async function collectRecommendedFiles(cwd, filePath, excludedPaths, files, maxFiles) {
203
+ if (files.length >= maxFiles) {
204
+ return;
205
+ }
206
+ const normalizedPath = filePath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/$/, "");
207
+ let fileStat;
208
+ try {
209
+ fileStat = await (0, promises_1.stat)(node_path_1.default.join(cwd, normalizedPath));
210
+ }
211
+ catch {
212
+ return;
213
+ }
214
+ if (fileStat.isFile()) {
215
+ if (isSourceOrDocFile(normalizedPath)) {
216
+ files.push(normalizedPath);
217
+ }
218
+ return;
219
+ }
220
+ if (!fileStat.isDirectory()) {
221
+ return;
222
+ }
223
+ let entries;
224
+ try {
225
+ entries = await (0, promises_1.readdir)(node_path_1.default.join(cwd, normalizedPath), { withFileTypes: true });
226
+ }
227
+ catch {
228
+ return;
229
+ }
230
+ entries.sort((left, right) => left.name.localeCompare(right.name));
231
+ for (const entry of entries) {
232
+ if (files.length >= maxFiles) {
233
+ return;
234
+ }
235
+ const relativePath = `${normalizedPath}/${entry.name}`;
236
+ if (entry.name === ".git" || isExcluded(relativePath, excludedPaths)) {
237
+ continue;
238
+ }
239
+ if (entry.isDirectory()) {
240
+ await collectRecommendedFiles(cwd, relativePath, excludedPaths, files, maxFiles);
241
+ }
242
+ else if (entry.isFile() && isSourceOrDocFile(relativePath)) {
243
+ files.push(relativePath);
244
+ }
245
+ }
246
+ }
247
+ async function resolveRecommendedFiles(cwd, paths, maxFiles) {
248
+ const excludedPaths = await readExcludedPaths(cwd);
249
+ const files = [];
250
+ for (const filePath of uniqueSorted(paths)) {
251
+ if (files.length >= maxFiles) {
252
+ break;
253
+ }
254
+ await collectRecommendedFiles(cwd, filePath, excludedPaths, files, maxFiles);
255
+ }
256
+ return uniqueSorted(files).slice(0, maxFiles);
257
+ }
258
+ async function estimateTaskRecommendation(cwd, task, maxFiles) {
259
+ const suggestion = await (0, suggester_1.suggestContext)(cwd, task);
260
+ const recommendedPaths = [
261
+ ...suggestion.contextFiles,
262
+ ...suggestion.likelySourceFiles,
263
+ ...suggestion.likelyTests
264
+ ];
265
+ const resolvedFiles = await resolveRecommendedFiles(cwd, recommendedPaths, maxFiles);
266
+ const sourcePaths = resolvedFiles.filter((file) => classifyRecommendedPath(file) === "source");
267
+ const testPaths = resolvedFiles.filter((file) => classifyRecommendedPath(file) === "test");
268
+ const contextPaths = resolvedFiles.filter((file) => classifyRecommendedPath(file) === "context");
269
+ const recommendedContextFiles = await estimateRecommendedFiles(cwd, contextPaths, maxFiles);
270
+ const likelySourceFiles = await estimateRecommendedFiles(cwd, sourcePaths, maxFiles);
271
+ const likelyTests = await estimateRecommendedFiles(cwd, testPaths, maxFiles);
272
+ return {
273
+ task,
274
+ recommendedContextTokens: sumTokens(recommendedContextFiles),
275
+ likelySourceTokens: sumTokens(likelySourceFiles),
276
+ likelyTestTokens: sumTokens(likelyTests),
277
+ likelyContextTokens: sumTokens(recommendedContextFiles),
278
+ recommendedContextFiles,
279
+ likelySourceFiles,
280
+ likelyTests,
281
+ likelyContextFiles: recommendedContextFiles
282
+ };
283
+ }
179
284
  function modeFiles(mode, startupFiles, onDemandFiles, historyFiles) {
180
285
  if (mode === "compact") {
181
286
  return startupFiles;
@@ -267,19 +372,7 @@ async function estimateTokenCost(options) {
267
372
  }
268
373
  if (options.task) {
269
374
  try {
270
- const suggestion = await (0, suggester_1.suggestContext)(options.cwd, options.task);
271
- const recommendedContextFiles = await Promise.all(suggestion.contextFiles.map((file) => estimateTextFile(options.cwd, file)));
272
- const likelySourceFiles = await estimateRecommendedFiles(options.cwd, suggestion.likelySourceFiles, options.maxFiles);
273
- const likelyTests = await estimateRecommendedFiles(options.cwd, suggestion.likelyTests, options.maxFiles);
274
- report.taskEstimate = {
275
- task: options.task,
276
- recommendedContextTokens: sumTokens(recommendedContextFiles),
277
- likelySourceTokens: sumTokens(likelySourceFiles),
278
- likelyTestTokens: sumTokens(likelyTests),
279
- recommendedContextFiles,
280
- likelySourceFiles,
281
- likelyTests
282
- };
375
+ report.taskEstimate = await estimateTaskRecommendation(options.cwd, options.task, options.maxFiles);
283
376
  }
284
377
  catch {
285
378
  warnings.push("Task-specific suggestion failed; estimate excludes task recommendations.");
@@ -1,30 +1,49 @@
1
1
  # AGENTS.md
2
2
 
3
- Repository Context Center startup guide for AI coding agents.
4
-
5
- Start here:
6
- - Read `docs/ai-context/COMMUNICATION_MODE.md`.
7
- - Read `docs/ai-context/TASK_ROUTING.md`.
8
- - Read `docs/ai-context/TOKEN_BUDGET.md`.
9
- - Read `docs/ai-context/DO_NOT_READ.md`.
10
- - Use `TASK_ROUTING.md` before scanning the repo.
11
-
12
- Context loading:
13
- - Default to Compact Mode.
14
- - Use Investigation Mode for security, auth, production, migration, release, or high-risk bug tasks.
15
- - Use Detailed Mode only when explicitly requested.
16
- - Load these only on demand: `MODULE_INDEX.md`, `PROJECT_MAP.md`, `DEPENDENCY_MAP.md`, `RISK_REGISTER.md`, `HOTSPOTS.md`, `SYMBOL_MAP.md`, `LESSONS_LEARNED.md`.
17
-
18
- Do not read by default:
19
- - `docs/ai-context/archive/*`.
20
- - Generated folders listed in `docs/ai-context/DO_NOT_READ.md`.
21
- - `.repo-context-center/config.json` unless debugging repo-context-center installation.
22
-
23
- Work rules:
24
- - Verify source code before changing behavior.
25
- - Treat context files as guidance, not source of truth.
26
- - Trust source code when context and code disagree.
27
- - Keep changes focused.
28
- - Run the smallest useful verification.
29
- - Avoid unnecessary repository-wide scans.
30
- - Update context files only when the task creates durable repo knowledge.
3
+ Repo Context Center startup.
4
+
5
+ ## Startup
6
+
7
+ Read:
8
+ 1. `docs/ai-context/COMMUNICATION_MODE.md`
9
+ 2. `docs/ai-context/TASK_ROUTING.md`
10
+ 3. `docs/ai-context/TOKEN_BUDGET.md`
11
+ 4. `docs/ai-context/DO_NOT_READ.md`
12
+
13
+ Use `TASK_ROUTING.md` before opening repo files.
14
+
15
+ ## Modes
16
+
17
+ Default: Compact
18
+
19
+ Investigation:
20
+ - security/auth
21
+ - production/release
22
+ - migrations
23
+ - high-risk bugs
24
+
25
+ Detailed: explicit request only.
26
+
27
+ On demand:
28
+ - `MODULE_INDEX.md`
29
+ - `PROJECT_MAP.md`
30
+ - `DEPENDENCY_MAP.md`
31
+ - `RISK_REGISTER.md`
32
+ - `HOTSPOTS.md`
33
+ - `SYMBOL_MAP.md`
34
+ - `LESSONS_LEARNED.md`
35
+
36
+ ## Skip
37
+
38
+ - `docs/ai-context/archive/*`
39
+ - paths in `DO_NOT_READ.md`
40
+ - `.repo-context-center/config.json` unless debugging install
41
+
42
+ ## Rules
43
+
44
+ - Code is source of truth.
45
+ - Context guides navigation.
46
+ - Verify before behavior changes.
47
+ - Keep changes small.
48
+ - Run smallest useful check.
49
+ - Update context only for durable repo knowledge.
@@ -1,15 +1,12 @@
1
1
  # Change Log
2
2
 
3
- Record context-center changes, not every code change.
4
-
5
- Format:
3
+ Record context edits only.
6
4
 
7
5
  | Date | Change | Reason |
8
6
  | --- | --- | --- |
9
- | YYYY-MM-DD | File or section updated | Why context changed |
7
+ | YYYY-MM-DD | file/section | why |
10
8
 
11
- Use when:
12
- - A template is installed.
13
- - A context map is corrected.
14
- - Routing guidance changes.
15
- - A stale note is removed.
9
+ Record:
10
+ - install/update/remove context files
11
+ - routing/map corrections
12
+ - stale context removed
@@ -1,14 +1,10 @@
1
1
  # Communication Mode
2
2
 
3
- Purpose: align the agent's working style with the current task.
4
-
5
- Default mode:
3
+ Use:
6
4
  - Read first, then act.
7
- - Share assumptions when context is incomplete.
8
- - Ask only when a wrong assumption would be costly.
9
- - Keep updates concise and tied to observable progress.
10
-
11
- When editing:
12
- - Name the files being changed.
5
+ - State risky assumptions.
6
+ - Ask only when guessing is costly.
7
+ - Keep updates short.
8
+ - Name changed files.
13
9
  - Preserve user changes.
14
- - Report tests run and failures clearly.
10
+ - Report checks run.
@@ -1,16 +1,12 @@
1
1
  # Dependency Map
2
2
 
3
- Record important internal and external dependencies.
4
-
5
- Format:
3
+ Record dependencies that change blast radius.
6
4
 
7
5
  | From | Depends On | Why It Matters |
8
6
  | --- | --- | --- |
9
- | `module` | `module/package` | Runtime, API, build, or test impact |
10
-
11
- Use this to avoid surprise blast radius.
7
+ | `module` | `module/package` | impact |
12
8
 
13
- Update when:
14
- - A shared dependency changes.
15
- - A module boundary shifts.
16
- - A new external package is added.
9
+ Update:
10
+ - shared dependency changes
11
+ - module boundary shifts
12
+ - package added/removed
@@ -1,8 +1,6 @@
1
1
  # Do Not Read
2
2
 
3
- Skip these unless the task explicitly requires them.
4
-
5
- Common examples:
3
+ Skip:
6
4
  - `node_modules/`
7
5
  - `dist/`
8
6
  - `build/`
@@ -15,4 +13,4 @@ Common examples:
15
13
  - Vendored code
16
14
  - Minified bundles
17
15
 
18
- When an excluded file is required, explain why and read the smallest useful section.
16
+ If required, explain why and read the smallest slice.
@@ -1,18 +1,13 @@
1
1
  # Hotspots
2
2
 
3
- Track files or flows that often cause bugs.
4
-
5
- Format:
3
+ Record fragile files/flows.
6
4
 
7
5
  | Hotspot | Why | Safer Move |
8
6
  | --- | --- | --- |
9
- | `path/or/flow` | Failure pattern | Test, review, or constraint |
10
-
11
- Use for:
12
- - Complex state.
13
- - Concurrency.
14
- - Auth or permissions.
15
- - Serialization.
16
- - Boundary adapters.
7
+ | `path/or/flow` | failure pattern | check |
17
8
 
18
- Remove entries when they stop being true.
9
+ Use:
10
+ - state/concurrency
11
+ - auth/permissions
12
+ - serialization
13
+ - boundary adapters
@@ -1,19 +1,12 @@
1
1
  # Lessons Learned
2
2
 
3
- Capture durable facts discovered during work.
4
-
5
- Format:
3
+ Record durable repo facts only.
6
4
 
7
5
  | Date | Lesson | Source |
8
6
  | --- | --- | --- |
9
- | YYYY-MM-DD | Short factual note | PR, issue, test, or file |
10
-
11
- Good entries:
12
- - Save future investigation.
13
- - Explain non-obvious constraints.
14
- - Point to evidence.
7
+ | YYYY-MM-DD | fact | PR/issue/test/file |
15
8
 
16
- Avoid:
17
- - Opinions without proof.
18
- - Temporary task notes.
19
- - Long narratives.
9
+ Skip:
10
+ - opinions
11
+ - temporary task notes
12
+ - long narratives
@@ -1,16 +1,12 @@
1
1
  # Module Index
2
2
 
3
- List important modules and their responsibilities.
4
-
5
- Format:
3
+ Record stable module boundaries.
6
4
 
7
5
  | Path | Owns | Read When |
8
6
  | --- | --- | --- |
9
- | `src/...` | Main behavior or boundary | Task touches this area |
10
-
11
- Keep entries short. Prefer stable boundaries over file-by-file detail.
7
+ | `src/...` | boundary | task touches area |
12
8
 
13
- Update when:
14
- - A module is added, removed, or renamed.
15
- - Ownership changes.
16
- - A task repeatedly requires the same context.
9
+ Update:
10
+ - module added/renamed/removed
11
+ - ownership changes
12
+ - repeated task needs same context
@@ -1,17 +1,15 @@
1
1
  # Project Map
2
2
 
3
- Describe the repository at a glance.
4
-
5
3
  Fill in:
6
- - Primary language/runtime:
4
+ - Runtime:
7
5
  - Package manager:
8
- - Build command:
9
- - Test command:
10
- - Main entrypoints:
11
- - Generated or vendored paths:
12
- - Important conventions:
6
+ - Build:
7
+ - Test:
8
+ - Entrypoints:
9
+ - Generated/vendored:
10
+ - Conventions:
13
11
 
14
- Agent notes:
15
- - Keep this file factual.
16
- - Link to files instead of restating long docs.
17
- - Update when commands or entrypoints change.
12
+ Rules:
13
+ - factual only
14
+ - link, do not restate
15
+ - update commands/entrypoints promptly
@@ -1,18 +1,14 @@
1
1
  # Risk Register
2
2
 
3
- Track areas where changes need extra care.
4
-
5
- Format:
3
+ Record high-care areas.
6
4
 
7
5
  | Area | Risk | Check |
8
6
  | --- | --- | --- |
9
- | `path/or/system` | What can break | Test or review needed |
7
+ | `path/or/system` | what breaks | check |
10
8
 
11
9
  Include:
12
- - Security-sensitive code.
13
- - Data migrations.
14
- - Public APIs.
15
- - Cross-cutting utilities.
16
- - Flaky or expensive tests.
17
-
18
- Keep risks current and specific.
10
+ - security
11
+ - migrations
12
+ - public APIs
13
+ - shared utilities
14
+ - flaky/expensive tests
@@ -1,26 +1,15 @@
1
1
  # Symbol Map
2
2
 
3
- Track high-value names agents should find quickly.
4
-
5
- Format:
3
+ Record high-value symbols only.
6
4
 
7
5
  ## src/example/module.ts
8
6
 
9
- Important symbols:
7
+ Symbols:
10
8
  - exportedFunction
11
9
  - ExportedClass
12
10
  - PublicType
13
11
 
14
- Common tests:
12
+ Tests:
15
13
  - tests/example/module.test.ts
16
14
 
17
- Risk:
18
- low
19
-
20
- Include:
21
- - Public APIs.
22
- - Main classes/functions.
23
- - Config objects.
24
- - Cross-module types.
25
-
26
- Do not list every symbol. Keep this navigational.
15
+ Risk: low
@@ -1,18 +1,9 @@
1
1
  # Task Routing
2
2
 
3
- Use this map to choose the smallest useful context set.
3
+ Read:
4
+ - Bug: `PROJECT_MAP.md`, `MODULE_INDEX.md`, `HOTSPOTS.md`, related tests.
5
+ - Feature: `PROJECT_MAP.md`, `MODULE_INDEX.md`, `DEPENDENCY_MAP.md`, examples.
6
+ - Refactor: `DEPENDENCY_MAP.md`, `SYMBOL_MAP.md`, callers.
7
+ - Docs/config: `PROJECT_MAP.md`, target files.
4
8
 
5
- Bug fix:
6
- - Read `PROJECT_MAP.md`, `MODULE_INDEX.md`, `HOTSPOTS.md`, and related tests.
7
-
8
- Feature:
9
- - Read `PROJECT_MAP.md`, `MODULE_INDEX.md`, `DEPENDENCY_MAP.md`, and nearby examples.
10
-
11
- Refactor:
12
- - Read `DEPENDENCY_MAP.md`, `SYMBOL_MAP.md`, and affected callers.
13
-
14
- Docs/config:
15
- - Read `PROJECT_MAP.md` and the target files.
16
-
17
- Before broad search:
18
- - Check `DO_NOT_READ.md`.
9
+ Before broad search: check `DO_NOT_READ.md`.
@@ -1,16 +1,12 @@
1
1
  # Token Budget
2
2
 
3
- Use context deliberately.
4
-
5
3
  Compact Mode:
6
- - Read routing, the target file, and the nearest test only.
7
- - Use when the task is narrow or low risk.
4
+ - routing + target file + nearest test
8
5
 
9
6
  Investigation Mode:
10
- - Add maps, related callers, and failure evidence.
11
- - Use when behavior, ownership, or blast radius is unclear.
7
+ - add maps, callers, failure evidence
12
8
 
13
- Default read order:
9
+ Read:
14
10
  1. `AGENTS.md`
15
11
  2. `TASK_ROUTING.md`
16
12
  3. Relevant map files
@@ -18,12 +14,12 @@ Default read order:
18
14
 
19
15
  Estimate overhead:
20
16
  - Run `repo-context-center estimate`.
21
- - Use `--compare-naive` to compare startup context with a broad repo pass.
22
- - Treat results as approximate, not billing data.
17
+ - `--compare-naive` compares startup vs broad pass.
18
+ - Approximate, not billing data.
23
19
 
24
- Avoid:
25
- - Generated output.
26
- - Lockfiles unless dependency state matters.
27
- - Large snapshots or fixtures unless failing behavior depends on them.
20
+ Skip:
21
+ - generated output
22
+ - lockfiles unless dependency state matters
23
+ - large snapshots unless failure depends on them
28
24
 
29
- Escalate context only when the first pass leaves a concrete unknown.
25
+ Escalate only for concrete unknowns.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-context-center",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A ContextOps toolkit for AI coding agents.",
5
5
  "keywords": [
6
6
  "ai",