@stainless-code/codemap 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @stainless-code/codemap
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Initial release (**0.1.0**): structural SQLite index, CLI (`codemap`, `query`), programmatic API, Zod-validated `codemap.config`, Bun and Node support.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 stainless-code contributors
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,116 @@
1
+ # Codemap
2
+
3
+ **Query your codebase.** Codemap builds a **local SQLite index** of structural metadata (symbols, imports, exports, components, dependencies, CSS tokens, markers, and more) so **AI agents and tools** can answer “where / what / who” questions with **SQL** instead of scanning the whole tree.
4
+
5
+ - **Not** full-text search or grep on arbitrary strings — use those when you need raw file-body search.
6
+ - **Is** a fast, token-efficient way to navigate **structure**: definitions, imports, dependency direction, components, and other extracted facts.
7
+
8
+ **Documentation:** [docs/README.md](docs/README.md) is the index for technical docs (architecture, packaging, roadmap, benchmarks). **AI / editor agents:** [`.agents/rules/`](.agents/rules/), [`.agents/skills/codemap/SKILL.md`](.agents/skills/codemap/SKILL.md); Cursor uses `.cursor/` symlinks — [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md).
9
+
10
+ ---
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ bun add @stainless-code/codemap
16
+ # or: npm install @stainless-code/codemap
17
+ ```
18
+
19
+ **Engines:** Node **`^20.19.0 || >=22.12.0`** and/or Bun **`>=1.0.0`** — see `package.json` and [docs/packaging.md](docs/packaging.md).
20
+
21
+ ---
22
+
23
+ ## CLI
24
+
25
+ - **Installed package:** `codemap`, `bunx @stainless-code/codemap`, or `node node_modules/@stainless-code/codemap/dist/index.mjs`
26
+ - **This repo (dev):** `bun src/index.ts` (same flags)
27
+
28
+ ```bash
29
+ # Index project root (optional codemap.config.ts / codemap.config.json)
30
+ codemap
31
+
32
+ # Version (also: codemap --version, codemap -V)
33
+ codemap version
34
+
35
+ # Full rebuild
36
+ codemap --full
37
+
38
+ # SQL against the index (after at least one index run)
39
+ codemap query "SELECT name, file_path FROM symbols LIMIT 10"
40
+
41
+ # Another project
42
+ codemap --root /path/to/repo --full
43
+
44
+ # Explicit config
45
+ codemap --config /path/to/codemap.config.json --full
46
+
47
+ # Re-index only given paths (relative to project root)
48
+ codemap --files src/a.ts src/b.tsx
49
+
50
+ # Scaffold .agents/ rules and skills from bundled templates (see CONTRIBUTING)
51
+ codemap agents init
52
+ codemap agents init --force
53
+ ```
54
+
55
+ **Environment / flags:** `--root` overrides **`CODEMAP_ROOT`** / **`CODEMAP_TEST_BENCH`**, then **`process.cwd()`**. Indexing a project outside this clone: [docs/benchmark.md § Indexing another project](docs/benchmark.md#indexing-another-project).
56
+
57
+ **Configuration:** optional **`codemap.config.ts`** (default export object or async factory) or **`codemap.config.json`**. Shape: [codemap.config.example.json](codemap.config.example.json). Runtime validation (**Zod**, strict keys) and API surface: [docs/architecture.md § User config](docs/architecture.md#user-config). When developing inside this repo you can use `defineConfig` from `@stainless-code/codemap` or `./src/config`. If you set **`include`**, it **replaces** the default glob list entirely.
58
+
59
+ ---
60
+
61
+ ## Programmatic API (ESM)
62
+
63
+ ```ts
64
+ import { createCodemap } from "@stainless-code/codemap";
65
+
66
+ const cm = await createCodemap({ root: "/path/to/repo" });
67
+ await cm.index({ mode: "incremental" });
68
+ await cm.index({ mode: "full" });
69
+ await cm.index({ mode: "files", files: ["src/a.ts"] });
70
+ await cm.index({ quiet: true });
71
+
72
+ const rows = cm.query("SELECT name FROM symbols LIMIT 5");
73
+ ```
74
+
75
+ `createCodemap` configures a process-global runtime (`initCodemap`); only **one active project per process** is supported. Advanced: `runCodemapIndex` for an open DB handle. **Module layout:** [docs/architecture.md § Layering](docs/architecture.md#layering).
76
+
77
+ ---
78
+
79
+ ## Development
80
+
81
+ Tooling: **Oxfmt**, **Oxlint**, **tsgo** (`@typescript/native-preview`).
82
+
83
+ | Command | Purpose |
84
+ | ------------------------------------ | ---------------------------------------------------------------- |
85
+ | `bun run dev` | Run the CLI from source (same as `bun src/index.ts`) |
86
+ | `bun run check` | Build, format check, lint, tests, typecheck — run before pushing |
87
+ | `bun run fix` | Apply lint fixes, then format |
88
+ | `bun run test` / `bun run typecheck` | Focused checks |
89
+
90
+ ```bash
91
+ bun install
92
+ bun run check # build + format:check + lint + test + typecheck
93
+ bun run fix # oxlint --fix, then oxfmt
94
+ ```
95
+
96
+ **Readability & DX:** Prefer clear names and small functions; keep **JSDoc** on public exports. [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) has contributor workflow and conventions.
97
+
98
+ ---
99
+
100
+ ## Benchmark
101
+
102
+ ```bash
103
+ CODEMAP_ROOT=/path/to/indexed-repo bun src/benchmark.ts
104
+ ```
105
+
106
+ Details: [docs/benchmark.md](docs/benchmark.md).
107
+
108
+ ---
109
+
110
+ ## Organization
111
+
112
+ Developed under **[stainless-code](https://github.com/stainless-code)** on GitHub.
113
+
114
+ ## License
115
+
116
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { i as extractMarkers, r as extractCssData, t as extractFileData } from "./parser-VtP0EJiw.mjs";
4
+ //#region src/adapters/builtin.ts
5
+ const TS_JS_EXT = new Set([
6
+ ".ts",
7
+ ".tsx",
8
+ ".mts",
9
+ ".cts",
10
+ ".js",
11
+ ".jsx",
12
+ ".mjs",
13
+ ".cjs"
14
+ ]);
15
+ function parseTsJs(ctx) {
16
+ const data = extractFileData(ctx.absPath, ctx.source, ctx.relPath);
17
+ return {
18
+ category: "ts",
19
+ symbols: data.symbols,
20
+ imports: data.imports,
21
+ exports: data.exports,
22
+ components: data.components,
23
+ markers: data.markers
24
+ };
25
+ }
26
+ function parseCss(ctx) {
27
+ const cssData = extractCssData(ctx.absPath, ctx.source, ctx.relPath);
28
+ return {
29
+ category: "css",
30
+ cssVariables: cssData.variables,
31
+ cssClasses: cssData.classes,
32
+ cssKeyframes: cssData.keyframes,
33
+ markers: cssData.markers,
34
+ cssImportSources: cssData.importSources
35
+ };
36
+ }
37
+ function parseText(ctx) {
38
+ return {
39
+ category: "text",
40
+ markers: extractMarkers(ctx.source, ctx.relPath)
41
+ };
42
+ }
43
+ /** Built-in adapters (oxc TS/JS, Lightning CSS, text/markers). Order matters for the first match. */
44
+ const BUILTIN_ADAPTERS = [
45
+ {
46
+ id: "builtin.ts-js",
47
+ extensions: [...TS_JS_EXT],
48
+ parse: parseTsJs
49
+ },
50
+ {
51
+ id: "builtin.css",
52
+ extensions: [".css"],
53
+ parse: parseCss
54
+ },
55
+ {
56
+ id: "builtin.text",
57
+ extensions: [
58
+ ".md",
59
+ ".mdx",
60
+ ".mdc",
61
+ ".yml",
62
+ ".yaml",
63
+ ".txt",
64
+ ".json",
65
+ ".sh"
66
+ ],
67
+ parse: parseText
68
+ }
69
+ ];
70
+ function getAdapterForExtension(ext, adapters = BUILTIN_ADAPTERS) {
71
+ for (const a of adapters) if (a.extensions.includes(ext)) return a;
72
+ }
73
+ //#endregion
74
+ export { getAdapterForExtension as n, BUILTIN_ADAPTERS as t };
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { cpSync, existsSync, mkdirSync } from "node:fs";
6
+ //#region src/agents-init.ts
7
+ /**
8
+ * Directory containing `rules/` and `skills/` (next to `dist/` in published packages).
9
+ */
10
+ function resolveAgentsTemplateDir() {
11
+ return join(dirname(fileURLToPath(import.meta.url)), "..", "templates", "agents");
12
+ }
13
+ /**
14
+ * Copy bundled rules and skills into `<projectRoot>/.agents/`.
15
+ * @returns `false` when `.agents/` exists and `--force` was not used.
16
+ */
17
+ function runAgentsInit(options) {
18
+ const templateRoot = resolveAgentsTemplateDir();
19
+ if (!existsSync(templateRoot)) throw new Error(`Codemap: agent templates not found at ${templateRoot} (expected npm package layout: templates/agents next to dist/)`);
20
+ const destRoot = join(options.projectRoot, ".agents");
21
+ if (existsSync(destRoot) && !options.force) {
22
+ console.error(` .agents/ already exists at ${destRoot}. Re-run with --force to overwrite, or remove the directory.`);
23
+ return false;
24
+ }
25
+ mkdirSync(destRoot, { recursive: true });
26
+ cpSync(join(templateRoot, "rules"), join(destRoot, "rules"), { recursive: true });
27
+ cpSync(join(templateRoot, "skills"), join(destRoot, "skills"), { recursive: true });
28
+ console.log(` Wrote agent templates to ${destRoot}`);
29
+ console.log(` Symlink into .cursor/ if needed — see https://github.com/stainless-code/codemap/blob/main/.github/CONTRIBUTING.md`);
30
+ return true;
31
+ }
32
+ //#endregion
33
+ //#region src/cli/cmd-agents.ts
34
+ function runAgentsInitCmd(opts) {
35
+ return runAgentsInit(opts);
36
+ }
37
+ //#endregion
38
+ export { runAgentsInitCmd };
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { C as getTsconfigPath, S as getProjectRoot, a as resolveCodemapConfig, g as closeDb, h as configureResolver, o as VALID_EXTENSIONS, r as loadUserConfig, w as initCodemap, y as openDb } from "./config-CsPgQWSX.mjs";
4
+ import { t as runCodemapIndex } from "./run-index-DQD5afqQ.mjs";
5
+ import { extname } from "node:path";
6
+ //#region src/cli/cmd-index.ts
7
+ async function runIndexCmd(opts) {
8
+ const user = await loadUserConfig(opts.root, opts.configFile);
9
+ initCodemap(resolveCodemapConfig(opts.root, user));
10
+ configureResolver(getProjectRoot(), getTsconfigPath());
11
+ const args = opts.rest;
12
+ const db = openDb();
13
+ try {
14
+ if (args[0] === "--files" && args.length > 1) {
15
+ const targetFiles = args.slice(1).filter((f) => {
16
+ const ext = extname(f);
17
+ if (!VALID_EXTENSIONS.has(ext)) {
18
+ console.warn(` Skipping ${f}: unsupported extension "${ext}"`);
19
+ return false;
20
+ }
21
+ return true;
22
+ });
23
+ if (targetFiles.length > 0) await runCodemapIndex(db, {
24
+ mode: "files",
25
+ files: targetFiles
26
+ });
27
+ } else await runCodemapIndex(db, { mode: args.includes("--full") ? "full" : "incremental" });
28
+ } finally {
29
+ closeDb(db);
30
+ }
31
+ }
32
+ //#endregion
33
+ export { runIndexCmd };
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { C as getTsconfigPath, S as getProjectRoot, a as resolveCodemapConfig, f as printQueryResult, h as configureResolver, r as loadUserConfig, w as initCodemap } from "./config-CsPgQWSX.mjs";
4
+ //#region src/cli/cmd-query.ts
5
+ async function runQueryCmd(opts) {
6
+ const user = await loadUserConfig(opts.root, opts.configFile);
7
+ initCodemap(resolveCodemapConfig(opts.root, user));
8
+ configureResolver(getProjectRoot(), getTsconfigPath());
9
+ printQueryResult(opts.sql);
10
+ }
11
+ //#endregion
12
+ export { runQueryCmd };