@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 +7 -0
- package/LICENSE +21 -0
- package/README.md +116 -0
- package/dist/builtin-CQ_e97VT.mjs +74 -0
- package/dist/cmd-agents-BJPx1vGG.mjs +38 -0
- package/dist/cmd-index-oyoHr0c4.mjs +33 -0
- package/dist/cmd-query-D3zXZu7K.mjs +12 -0
- package/dist/config-CsPgQWSX.mjs +885 -0
- package/dist/index.d.mts +198 -0
- package/dist/index.mjs +232 -0
- package/dist/parse-worker-core-DFFbs70b.mjs +67 -0
- package/dist/parse-worker-node.d.mts +2 -0
- package/dist/parse-worker-node.mjs +11 -0
- package/dist/parse-worker.d.mts +13 -0
- package/dist/parse-worker.mjs +9 -0
- package/dist/parsed-types-udxNyD9e.d.mts +108 -0
- package/dist/parser-VtP0EJiw.mjs +481 -0
- package/dist/run-index-DQD5afqQ.mjs +129 -0
- package/package.json +93 -0
- package/templates/agents/README.md +5 -0
- package/templates/agents/rules/agents-first-convention.mdc +37 -0
- package/templates/agents/rules/codemap.mdc +110 -0
- package/templates/agents/skills/codemap/SKILL.md +312 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
|
|
2
|
+
import { n as CodemapDatabase, t as ParsedFile } from "./parsed-types-udxNyD9e.mjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/application/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Row counts per table after an index run (mirrors CLI summary output).
|
|
8
|
+
*/
|
|
9
|
+
interface IndexTableStats extends Record<string, number> {
|
|
10
|
+
files: number;
|
|
11
|
+
symbols: number;
|
|
12
|
+
imports: number;
|
|
13
|
+
exports: number;
|
|
14
|
+
components: number;
|
|
15
|
+
dependencies: number;
|
|
16
|
+
markers: number;
|
|
17
|
+
css_vars: number;
|
|
18
|
+
css_classes: number;
|
|
19
|
+
css_keyframes: number;
|
|
20
|
+
}
|
|
21
|
+
/** Per-run counters; see {@link IndexResult} for the public shape returned from indexing APIs. */
|
|
22
|
+
interface IndexRunStats {
|
|
23
|
+
indexed: number;
|
|
24
|
+
skipped: number;
|
|
25
|
+
elapsedMs: number;
|
|
26
|
+
fullRebuild: boolean;
|
|
27
|
+
stats: IndexTableStats;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Outcome of `Codemap#index` or `runCodemapIndex` (CLI and programmatic index runs).
|
|
31
|
+
*/
|
|
32
|
+
interface IndexResult {
|
|
33
|
+
/** How the index was updated. */
|
|
34
|
+
mode: "full" | "incremental" | "files";
|
|
35
|
+
/** Files written or re-indexed in this run. */
|
|
36
|
+
indexed: number;
|
|
37
|
+
/** Files skipped (unchanged hash). */
|
|
38
|
+
skipped: number;
|
|
39
|
+
elapsedMs: number;
|
|
40
|
+
stats: IndexTableStats;
|
|
41
|
+
/**
|
|
42
|
+
* Set when no file bodies were indexed (already fresh, empty `files` list, or deletions-only pass).
|
|
43
|
+
*/
|
|
44
|
+
idle?: boolean;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/application/run-index.d.ts
|
|
48
|
+
/**
|
|
49
|
+
* - `incremental` — git-based diff vs last indexed commit (default).
|
|
50
|
+
* - `full` — re-glob and re-index everything.
|
|
51
|
+
* - `files` — only `options.files` (paths relative to project root).
|
|
52
|
+
*/
|
|
53
|
+
type IndexMode = "incremental" | "full" | "files";
|
|
54
|
+
interface RunIndexOptions {
|
|
55
|
+
/** Defaults to `incremental`. */
|
|
56
|
+
mode?: IndexMode;
|
|
57
|
+
/**
|
|
58
|
+
* Paths relative to the project root; used only when `mode === "files"`.
|
|
59
|
+
* Non-indexable extensions are filtered out.
|
|
60
|
+
*/
|
|
61
|
+
files?: string[];
|
|
62
|
+
/** Suppresses progress logs; parse failures may still be printed. Defaults to `false`. */
|
|
63
|
+
quiet?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Core indexing pipeline (CLI and `Codemap#index`).
|
|
67
|
+
*
|
|
68
|
+
* @param db - Open database; caller owns the connection lifecycle.
|
|
69
|
+
* @param options - Index mode, optional targeted paths, and logging.
|
|
70
|
+
* @returns Row counts and timing; see {@link IndexResult}.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Call `initCodemap()` and `configureResolver()` for this project before invoking (same as CLI bootstrap).
|
|
74
|
+
*/
|
|
75
|
+
declare function runCodemapIndex(db: CodemapDatabase, options?: RunIndexOptions): Promise<IndexResult>;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/config.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* Zod schema for user config (`codemap.config.*`, `defineConfig`, API).
|
|
80
|
+
* Unknown keys are rejected (`.strict()`).
|
|
81
|
+
*/
|
|
82
|
+
declare const codemapUserConfigSchema: z.ZodObject<{
|
|
83
|
+
root: z.ZodOptional<z.ZodString>;
|
|
84
|
+
databasePath: z.ZodOptional<z.ZodString>;
|
|
85
|
+
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
86
|
+
excludeDirNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
87
|
+
tsconfigPath: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
88
|
+
}, z.core.$strict>;
|
|
89
|
+
/** Inferred from {@link codemapUserConfigSchema}. */
|
|
90
|
+
type CodemapUserConfig = z.infer<typeof codemapUserConfigSchema>;
|
|
91
|
+
/**
|
|
92
|
+
* Fully resolved configuration after {@link resolveCodemapConfig}.
|
|
93
|
+
*/
|
|
94
|
+
interface ResolvedCodemapConfig {
|
|
95
|
+
readonly root: string;
|
|
96
|
+
readonly databasePath: string;
|
|
97
|
+
readonly include: readonly string[];
|
|
98
|
+
readonly excludeDirNames: ReadonlySet<string>;
|
|
99
|
+
readonly tsconfigPath: string | null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Runtime validation for {@link CodemapUserConfig} (from JSON, `defineConfig`, or API).
|
|
103
|
+
*
|
|
104
|
+
* @throws TypeError when the shape is invalid or unknown keys are present.
|
|
105
|
+
*/
|
|
106
|
+
declare function parseCodemapUserConfig(config: unknown): CodemapUserConfig;
|
|
107
|
+
/**
|
|
108
|
+
* Helper for `export default defineConfig({ ... })` in `codemap.config.ts`.
|
|
109
|
+
*/
|
|
110
|
+
declare function defineConfig(config: CodemapUserConfig): CodemapUserConfig;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/api.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* Options for {@link createCodemap}.
|
|
115
|
+
*
|
|
116
|
+
* @property root - Project root. When omitted: `CODEMAP_ROOT` or `CODEMAP_TEST_BENCH`, then `process.cwd()`.
|
|
117
|
+
* @property configFile - Explicit path to `codemap.config.ts` or `codemap.config.json` (same as CLI `--config`).
|
|
118
|
+
* @property config - Inline overrides merged on top of the file-based config from the project root.
|
|
119
|
+
*/
|
|
120
|
+
interface CodemapInitOptions {
|
|
121
|
+
root?: string;
|
|
122
|
+
configFile?: string;
|
|
123
|
+
config?: CodemapUserConfig;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Programmatic entry point: loads config, calls {@link initCodemap}, configures the import resolver,
|
|
127
|
+
* and returns a {@link Codemap} handle.
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* Only one Codemap project per process: `initCodemap` is global; the last `createCodemap()` wins.
|
|
131
|
+
*/
|
|
132
|
+
declare function createCodemap(options?: CodemapInitOptions): Promise<Codemap>;
|
|
133
|
+
/**
|
|
134
|
+
* Handle for SQL queries and index runs after {@link createCodemap}.
|
|
135
|
+
*
|
|
136
|
+
* Each {@link query} opens the database for that call; {@link index} manages its own open/close lifecycle.
|
|
137
|
+
*/
|
|
138
|
+
declare class Codemap {
|
|
139
|
+
/** Absolute project root (from resolved config). */
|
|
140
|
+
get root(): string;
|
|
141
|
+
/** Absolute path to the SQLite index file (e.g. `.codemap.db`). */
|
|
142
|
+
get databasePath(): string;
|
|
143
|
+
/**
|
|
144
|
+
* Run a read-only SQL statement against the index (same semantics as the CLI `query` subcommand).
|
|
145
|
+
*
|
|
146
|
+
* @param sql - Valid SQLite for the Codemap schema.
|
|
147
|
+
* @returns Result rows from `better-sqlite3`-style `.all()`.
|
|
148
|
+
* @throws On invalid SQL or database errors (same as `better-sqlite3`).
|
|
149
|
+
*/
|
|
150
|
+
query(sql: string): unknown[];
|
|
151
|
+
/**
|
|
152
|
+
* Refresh the index: incremental (git-based), full, or targeted file list.
|
|
153
|
+
*
|
|
154
|
+
* @param options - See {@link RunIndexOptions}.
|
|
155
|
+
*/
|
|
156
|
+
index(options?: RunIndexOptions): Promise<IndexResult>;
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/adapters/types.d.ts
|
|
160
|
+
/**
|
|
161
|
+
* Input for a {@link LanguageAdapter}. Paths are absolute / project-relative as noted.
|
|
162
|
+
*/
|
|
163
|
+
interface ParseContext {
|
|
164
|
+
/** Absolute path on disk (for parsers that need a real `filename`). */
|
|
165
|
+
absPath: string;
|
|
166
|
+
/** Path relative to project root (stored in DB rows). */
|
|
167
|
+
relPath: string;
|
|
168
|
+
source: string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Partial parse result merged into {@link ParsedFile} after `fileRow` is built.
|
|
172
|
+
* Set `parseError` when extraction fails but the file should still be indexed.
|
|
173
|
+
*/
|
|
174
|
+
type ParsedFilePayload = Pick<ParsedFile, "category" | "symbols" | "imports" | "exports" | "components" | "markers" | "cssVariables" | "cssClasses" | "cssKeyframes" | "cssImportSources" | "parseError">;
|
|
175
|
+
/**
|
|
176
|
+
* Pluggable extractor for a set of file extensions.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* Built-in adapters live in {@link ./builtin.ts}. Future optional packages can register
|
|
180
|
+
* additional adapters (or replace built-ins) once a public registration API exists.
|
|
181
|
+
*/
|
|
182
|
+
interface LanguageAdapter {
|
|
183
|
+
readonly id: string;
|
|
184
|
+
/** Extensions with leading dot, e.g. `.ts`, `.tsx`. */
|
|
185
|
+
readonly extensions: readonly string[];
|
|
186
|
+
parse(ctx: ParseContext): ParsedFilePayload;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/adapters/builtin.d.ts
|
|
190
|
+
/** Built-in adapters (oxc TS/JS, Lightning CSS, text/markers). Order matters for the first match. */
|
|
191
|
+
declare const BUILTIN_ADAPTERS: readonly LanguageAdapter[];
|
|
192
|
+
declare function getAdapterForExtension(ext: string, adapters?: readonly LanguageAdapter[]): LanguageAdapter | undefined;
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/version.d.ts
|
|
195
|
+
/** Package version from `package.json` (inlined at build time). */
|
|
196
|
+
declare const CODEMAP_VERSION: string;
|
|
197
|
+
//#endregion
|
|
198
|
+
export { BUILTIN_ADAPTERS, CODEMAP_VERSION, Codemap, type CodemapDatabase, CodemapInitOptions, type CodemapUserConfig, type RunIndexOptions as IndexOptions, type IndexResult, type IndexRunStats, type IndexTableStats, type LanguageAdapter, type ParseContext, type ParsedFile, type ParsedFilePayload, type ResolvedCodemapConfig, codemapUserConfigSchema, createCodemap, defineConfig, getAdapterForExtension, parseCodemapUserConfig, runCodemapIndex };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { C as getTsconfigPath, S as getProjectRoot, a as resolveCodemapConfig, g as closeDb, h as configureResolver, i as parseCodemapUserConfig, n as defineConfig, p as queryRows, r as loadUserConfig, t as codemapUserConfigSchema, w as initCodemap, x as getDatabasePath, y as openDb } from "./config-CsPgQWSX.mjs";
|
|
4
|
+
import { t as runCodemapIndex } from "./run-index-DQD5afqQ.mjs";
|
|
5
|
+
import { n as getAdapterForExtension, t as BUILTIN_ADAPTERS } from "./builtin-CQ_e97VT.mjs";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/version.ts
|
|
10
|
+
/** Package version from `package.json` (inlined at build time). */
|
|
11
|
+
const CODEMAP_VERSION = "0.1.0";
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/cli/bootstrap.ts
|
|
14
|
+
/** Printed for `codemap --help` / `-h` (must run before config or DB access). */
|
|
15
|
+
function printCliUsage() {
|
|
16
|
+
console.log(`Usage: codemap [options] [command]
|
|
17
|
+
|
|
18
|
+
Index (default): update .codemap.db for the project root (\`--root\` or cwd).
|
|
19
|
+
codemap [--root DIR] [--config FILE] [--full]
|
|
20
|
+
codemap [--root DIR] [--config FILE] --files <paths...>
|
|
21
|
+
|
|
22
|
+
Query:
|
|
23
|
+
codemap query "<SQL>"
|
|
24
|
+
|
|
25
|
+
Agents:
|
|
26
|
+
codemap agents init [--force]
|
|
27
|
+
|
|
28
|
+
Other:
|
|
29
|
+
codemap version
|
|
30
|
+
codemap --version, -V
|
|
31
|
+
|
|
32
|
+
Environment: CODEMAP_ROOT (same as --root)
|
|
33
|
+
|
|
34
|
+
Options:
|
|
35
|
+
--full Full rebuild
|
|
36
|
+
--help, -h Show this help
|
|
37
|
+
`);
|
|
38
|
+
}
|
|
39
|
+
function printVersion() {
|
|
40
|
+
console.log(CODEMAP_VERSION);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reject unknown flags/args for index mode before config or DB access.
|
|
44
|
+
* Prevents typos like `--versiond` from falling through to incremental index.
|
|
45
|
+
*/
|
|
46
|
+
function validateIndexModeArgs(rest) {
|
|
47
|
+
if (rest.length === 0) return;
|
|
48
|
+
if (rest[0] === "query") return;
|
|
49
|
+
if (rest[0] === "agents") {
|
|
50
|
+
if (rest[1] === "init") return;
|
|
51
|
+
console.error(`codemap: unknown agents command "${rest[1] ?? "(missing)"}". Expected: codemap agents init [--force]`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
let i = 0;
|
|
55
|
+
while (i < rest.length) {
|
|
56
|
+
const a = rest[i];
|
|
57
|
+
if (a === "--full") {
|
|
58
|
+
i++;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (a === "--files") {
|
|
62
|
+
i++;
|
|
63
|
+
while (i < rest.length && !rest[i].startsWith("-")) i++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (a.startsWith("-")) {
|
|
67
|
+
console.error(`codemap: unknown option "${a}"`);
|
|
68
|
+
console.error("Run codemap --help for usage.");
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
console.error(`codemap: unexpected argument "${a}"`);
|
|
72
|
+
console.error("Run codemap --help for usage.");
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function parseBootstrapArgs(argv) {
|
|
77
|
+
const envRoot = process.env.CODEMAP_ROOT ?? process.env.CODEMAP_TEST_BENCH;
|
|
78
|
+
let root = envRoot ? resolve(envRoot) : void 0;
|
|
79
|
+
let configFile;
|
|
80
|
+
const rest = [];
|
|
81
|
+
for (let i = 0; i < argv.length; i++) {
|
|
82
|
+
const a = argv[i];
|
|
83
|
+
if (a === "--root" && argv[i + 1]) {
|
|
84
|
+
root = resolve(argv[++i]);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (a === "--config" && argv[i + 1]) {
|
|
88
|
+
configFile = resolve(argv[++i]);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
rest.push(a);
|
|
92
|
+
}
|
|
93
|
+
if (!root) root = process.cwd();
|
|
94
|
+
return {
|
|
95
|
+
root,
|
|
96
|
+
configFile,
|
|
97
|
+
rest
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/cli/main.ts
|
|
102
|
+
/**
|
|
103
|
+
* CLI entry — only `./bootstrap` is loaded eagerly. Command bodies are
|
|
104
|
+
* dynamically imported so `codemap --help` / `version` / `agents init` avoid
|
|
105
|
+
* pulling in the indexer, parser, and workers.
|
|
106
|
+
*/
|
|
107
|
+
async function main() {
|
|
108
|
+
const { root, configFile, rest } = parseBootstrapArgs(process.argv.slice(2));
|
|
109
|
+
if (rest[0] === "--help" || rest[0] === "-h") {
|
|
110
|
+
printCliUsage();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (rest[0] === "--version" || rest[0] === "-V" || rest[0] === "version") {
|
|
114
|
+
printVersion();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (rest[0] === "agents" && rest[1] === "init") {
|
|
118
|
+
if (rest.includes("--help") || rest.includes("-h")) {
|
|
119
|
+
console.log(`Usage: codemap agents init [--force]
|
|
120
|
+
|
|
121
|
+
Copies bundled agent templates into .agents/ under the project root.
|
|
122
|
+
Use --force to overwrite an existing .agents/ directory.
|
|
123
|
+
`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const { runAgentsInitCmd } = await import("./cmd-agents-BJPx1vGG.mjs");
|
|
127
|
+
if (!runAgentsInitCmd({
|
|
128
|
+
projectRoot: root,
|
|
129
|
+
force: rest.includes("--force")
|
|
130
|
+
})) process.exit(1);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
validateIndexModeArgs(rest);
|
|
134
|
+
if (rest[0] === "query" && rest[1]) {
|
|
135
|
+
if (rest[1] === "--help" || rest[1] === "-h") {
|
|
136
|
+
console.log(`Usage: codemap query "<SQL>"
|
|
137
|
+
|
|
138
|
+
Runs read-only SQL against .codemap.db (after at least one successful index run).
|
|
139
|
+
Example: codemap query "SELECT name, file_path FROM symbols LIMIT 10"
|
|
140
|
+
`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const { runQueryCmd } = await import("./cmd-query-D3zXZu7K.mjs");
|
|
144
|
+
await runQueryCmd({
|
|
145
|
+
root,
|
|
146
|
+
configFile,
|
|
147
|
+
sql: rest.slice(1).join(" ")
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const { runIndexCmd } = await import("./cmd-index-oyoHr0c4.mjs");
|
|
152
|
+
await runIndexCmd({
|
|
153
|
+
root,
|
|
154
|
+
configFile,
|
|
155
|
+
rest
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/api.ts
|
|
160
|
+
/**
|
|
161
|
+
* Programmatic entry point: loads config, calls {@link initCodemap}, configures the import resolver,
|
|
162
|
+
* and returns a {@link Codemap} handle.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* Only one Codemap project per process: `initCodemap` is global; the last `createCodemap()` wins.
|
|
166
|
+
*/
|
|
167
|
+
async function createCodemap(options = {}) {
|
|
168
|
+
const envRoot = process.env.CODEMAP_ROOT ?? process.env.CODEMAP_TEST_BENCH;
|
|
169
|
+
const root = options.root !== void 0 ? resolve(options.root) : envRoot ? resolve(envRoot) : process.cwd();
|
|
170
|
+
initCodemap(resolveCodemapConfig(root, {
|
|
171
|
+
...await loadUserConfig(root, options.configFile),
|
|
172
|
+
...options.config
|
|
173
|
+
}));
|
|
174
|
+
configureResolver(getProjectRoot(), getTsconfigPath());
|
|
175
|
+
return new Codemap();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Handle for SQL queries and index runs after {@link createCodemap}.
|
|
179
|
+
*
|
|
180
|
+
* Each {@link query} opens the database for that call; {@link index} manages its own open/close lifecycle.
|
|
181
|
+
*/
|
|
182
|
+
var Codemap = class {
|
|
183
|
+
/** Absolute project root (from resolved config). */
|
|
184
|
+
get root() {
|
|
185
|
+
return getProjectRoot();
|
|
186
|
+
}
|
|
187
|
+
/** Absolute path to the SQLite index file (e.g. `.codemap.db`). */
|
|
188
|
+
get databasePath() {
|
|
189
|
+
return getDatabasePath();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Run a read-only SQL statement against the index (same semantics as the CLI `query` subcommand).
|
|
193
|
+
*
|
|
194
|
+
* @param sql - Valid SQLite for the Codemap schema.
|
|
195
|
+
* @returns Result rows from `better-sqlite3`-style `.all()`.
|
|
196
|
+
* @throws On invalid SQL or database errors (same as `better-sqlite3`).
|
|
197
|
+
*/
|
|
198
|
+
query(sql) {
|
|
199
|
+
return queryRows(sql);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Refresh the index: incremental (git-based), full, or targeted file list.
|
|
203
|
+
*
|
|
204
|
+
* @param options - See {@link RunIndexOptions}.
|
|
205
|
+
*/
|
|
206
|
+
async index(options = {}) {
|
|
207
|
+
const db = openDb();
|
|
208
|
+
try {
|
|
209
|
+
return await runCodemapIndex(db, options);
|
|
210
|
+
} finally {
|
|
211
|
+
closeDb(db);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/index.ts
|
|
217
|
+
function isMainModule() {
|
|
218
|
+
if (typeof import.meta !== "undefined" && import.meta.main) return true;
|
|
219
|
+
const arg1 = process.argv[1];
|
|
220
|
+
if (!arg1) return false;
|
|
221
|
+
try {
|
|
222
|
+
return fileURLToPath(import.meta.url) === resolve(arg1);
|
|
223
|
+
} catch {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (isMainModule()) main().catch((err) => {
|
|
228
|
+
console.error(err);
|
|
229
|
+
process.exit(1);
|
|
230
|
+
});
|
|
231
|
+
//#endregion
|
|
232
|
+
export { BUILTIN_ADAPTERS, CODEMAP_VERSION, Codemap, codemapUserConfigSchema, createCodemap, defineConfig, getAdapterForExtension, parseCodemapUserConfig, runCodemapIndex };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { a as LANG_MAP, i as extractMarkers, n as hashContent } from "./parser-VtP0EJiw.mjs";
|
|
4
|
+
import { n as getAdapterForExtension } from "./builtin-CQ_e97VT.mjs";
|
|
5
|
+
import { extname, join } from "node:path";
|
|
6
|
+
import { readFileSync, statSync } from "node:fs";
|
|
7
|
+
//#region src/parse-worker-core.ts
|
|
8
|
+
function parseAsTextFallback(source, relPath) {
|
|
9
|
+
return {
|
|
10
|
+
category: "text",
|
|
11
|
+
markers: extractMarkers(source, relPath)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function parseWorkerInput(input) {
|
|
15
|
+
const { files, projectRoot } = input;
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const relPath of files) {
|
|
18
|
+
const absPath = join(projectRoot, relPath);
|
|
19
|
+
let source;
|
|
20
|
+
try {
|
|
21
|
+
source = readFileSync(absPath, "utf-8");
|
|
22
|
+
} catch {
|
|
23
|
+
results.push({
|
|
24
|
+
relPath,
|
|
25
|
+
error: true,
|
|
26
|
+
fileRow: {},
|
|
27
|
+
category: "text"
|
|
28
|
+
});
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const hash = hashContent(source);
|
|
32
|
+
const stat = statSync(absPath);
|
|
33
|
+
let lineCount = 1;
|
|
34
|
+
for (let i = 0; i < source.length; i++) if (source.charCodeAt(i) === 10) lineCount++;
|
|
35
|
+
const ext = extname(relPath);
|
|
36
|
+
const language = LANG_MAP[ext] ?? "text";
|
|
37
|
+
const parsed = {
|
|
38
|
+
relPath,
|
|
39
|
+
fileRow: {
|
|
40
|
+
path: relPath,
|
|
41
|
+
content_hash: hash,
|
|
42
|
+
size: stat.size,
|
|
43
|
+
line_count: lineCount,
|
|
44
|
+
language,
|
|
45
|
+
last_modified: Math.floor(stat.mtimeMs),
|
|
46
|
+
indexed_at: Date.now()
|
|
47
|
+
},
|
|
48
|
+
category: "text"
|
|
49
|
+
};
|
|
50
|
+
const ctx = {
|
|
51
|
+
absPath,
|
|
52
|
+
relPath,
|
|
53
|
+
source
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const adapter = getAdapterForExtension(ext);
|
|
57
|
+
const payload = adapter ? adapter.parse(ctx) : parseAsTextFallback(source, relPath);
|
|
58
|
+
Object.assign(parsed, payload);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
parsed.parseError = err instanceof Error ? err.message : String(err);
|
|
61
|
+
}
|
|
62
|
+
results.push(parsed);
|
|
63
|
+
}
|
|
64
|
+
return { results };
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { parseWorkerInput as t };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { t as parseWorkerInput } from "./parse-worker-core-DFFbs70b.mjs";
|
|
4
|
+
import { parentPort } from "node:worker_threads";
|
|
5
|
+
//#region src/parse-worker-node.ts
|
|
6
|
+
if (!parentPort) throw new Error("parse-worker-node must run in a worker thread");
|
|
7
|
+
parentPort.on("message", (data) => {
|
|
8
|
+
parentPort.postMessage(parseWorkerInput(data));
|
|
9
|
+
});
|
|
10
|
+
//#endregion
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
import { t as ParsedFile } from "./parsed-types-udxNyD9e.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/parse-worker-core.d.ts
|
|
5
|
+
interface WorkerInput {
|
|
6
|
+
files: string[];
|
|
7
|
+
projectRoot: string;
|
|
8
|
+
}
|
|
9
|
+
interface WorkerOutput {
|
|
10
|
+
results: ParsedFile[];
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { type ParsedFile, type WorkerInput, type WorkerOutput };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/sqlite-db.d.ts
|
|
3
|
+
/** Values accepted by SQLite bindings for bound parameters. */
|
|
4
|
+
type BindValues = (string | number | null)[];
|
|
5
|
+
/**
|
|
6
|
+
* Minimal SQLite surface used by Codemap — implemented for `bun:sqlite` and
|
|
7
|
+
* `better-sqlite3` (sync APIs, transactions, PRAGMAs).
|
|
8
|
+
*/
|
|
9
|
+
interface CodemapDatabase {
|
|
10
|
+
run(sql: string, params?: BindValues): void;
|
|
11
|
+
query<T>(sql: string): {
|
|
12
|
+
get(...params: unknown[]): T | undefined;
|
|
13
|
+
all(...params: unknown[]): T[];
|
|
14
|
+
};
|
|
15
|
+
/** Returns a function that runs the transaction when invoked (Bun / better-sqlite3 semantics). */
|
|
16
|
+
transaction<T>(fn: () => T): () => T;
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/db.d.ts
|
|
21
|
+
interface FileRow {
|
|
22
|
+
path: string;
|
|
23
|
+
content_hash: string;
|
|
24
|
+
size: number;
|
|
25
|
+
line_count: number;
|
|
26
|
+
language: string;
|
|
27
|
+
last_modified: number;
|
|
28
|
+
indexed_at: number;
|
|
29
|
+
}
|
|
30
|
+
interface SymbolRow {
|
|
31
|
+
file_path: string;
|
|
32
|
+
name: string;
|
|
33
|
+
kind: string;
|
|
34
|
+
line_start: number;
|
|
35
|
+
line_end: number;
|
|
36
|
+
signature: string;
|
|
37
|
+
is_exported: number;
|
|
38
|
+
is_default_export: number;
|
|
39
|
+
}
|
|
40
|
+
interface ImportRow {
|
|
41
|
+
file_path: string;
|
|
42
|
+
source: string;
|
|
43
|
+
resolved_path: string | null;
|
|
44
|
+
specifiers: string;
|
|
45
|
+
is_type_only: number;
|
|
46
|
+
line_number: number;
|
|
47
|
+
}
|
|
48
|
+
interface ExportRow {
|
|
49
|
+
file_path: string;
|
|
50
|
+
name: string;
|
|
51
|
+
kind: string;
|
|
52
|
+
is_default: number;
|
|
53
|
+
re_export_source: string | null;
|
|
54
|
+
}
|
|
55
|
+
interface ComponentRow {
|
|
56
|
+
file_path: string;
|
|
57
|
+
name: string;
|
|
58
|
+
props_type: string | null;
|
|
59
|
+
hooks_used: string;
|
|
60
|
+
is_default_export: number;
|
|
61
|
+
}
|
|
62
|
+
interface MarkerRow {
|
|
63
|
+
file_path: string;
|
|
64
|
+
line_number: number;
|
|
65
|
+
kind: string;
|
|
66
|
+
content: string;
|
|
67
|
+
}
|
|
68
|
+
interface CssVariableRow {
|
|
69
|
+
file_path: string;
|
|
70
|
+
name: string;
|
|
71
|
+
value: string | null;
|
|
72
|
+
scope: string;
|
|
73
|
+
line_number: number;
|
|
74
|
+
}
|
|
75
|
+
interface CssClassRow {
|
|
76
|
+
file_path: string;
|
|
77
|
+
name: string;
|
|
78
|
+
is_module: number;
|
|
79
|
+
line_number: number;
|
|
80
|
+
}
|
|
81
|
+
interface CssKeyframeRow {
|
|
82
|
+
file_path: string;
|
|
83
|
+
name: string;
|
|
84
|
+
line_number: number;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/parsed-types.d.ts
|
|
88
|
+
/**
|
|
89
|
+
* One indexed file’s extracted data (workers return arrays of these).
|
|
90
|
+
*/
|
|
91
|
+
interface ParsedFile {
|
|
92
|
+
relPath: string;
|
|
93
|
+
error?: boolean;
|
|
94
|
+
parseError?: string;
|
|
95
|
+
fileRow: FileRow;
|
|
96
|
+
category: "ts" | "css" | "text";
|
|
97
|
+
symbols?: SymbolRow[];
|
|
98
|
+
imports?: ImportRow[];
|
|
99
|
+
exports?: ExportRow[];
|
|
100
|
+
components?: ComponentRow[];
|
|
101
|
+
markers?: MarkerRow[];
|
|
102
|
+
cssVariables?: CssVariableRow[];
|
|
103
|
+
cssClasses?: CssClassRow[];
|
|
104
|
+
cssKeyframes?: CssKeyframeRow[];
|
|
105
|
+
cssImportSources?: string[];
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { CodemapDatabase as n, ParsedFile as t };
|