@possumtech/rummy.repo 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PossumTech Laboratories
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,64 @@
1
+ # rummy.repo
2
+
3
+ Symbol extraction plugin for [Rummy](https://github.com/possumtech/rummy). Turns source files into structured symbol maps using [antlrmap](https://github.com/possumtech/antlrmap) (formal ANTLR4 grammars) with [Universal Ctags](https://ctags.io/) as a fallback.
4
+
5
+ Antlrmap relies on ANTLR4's Grammar Zoo, mapping the symbol extraction process from formal EBNF grammars. More academically rigorous than tree-sitter heuristics, more accurate than ctags regex patterns, and more amenable to obscure and domain-specific languages. Don't like it? This is why symbol extraction is a plugin -- swap it out in 20 lines.
6
+
7
+ ## What It Does
8
+
9
+ When files change in a Rummy project, this plugin extracts their symbols (functions, classes, methods, fields) and returns them as structured data. Rummy stores the formatted symbol tree in file entry attributes, giving the model a compact map of the codebase without reading every file.
10
+
11
+ ## Supported Languages
12
+
13
+ Antlrmap provides grammar-based parsing for 36+ languages: JavaScript, TypeScript, Python, Rust, Go, Java, C, C++, Kotlin, PHP, Lua, SQL, Dart, Scala, Clojure, Elixir, Zig, R, Objective-C, Verilog, VHDL, Terraform, Fortran, Erlang, Thrift, GraphQL, AWK, JSON, TOML, Dockerfile, and more.
14
+
15
+ Files with unsupported extensions fall back to Universal Ctags (if installed).
16
+
17
+ ## Installation
18
+
19
+ Drop into your Rummy plugins directory:
20
+
21
+ ```bash
22
+ cd ~/.rummy/plugins
23
+ git clone https://github.com/possumtech/rummy.repo
24
+ cd rummy.repo/main
25
+ npm install
26
+ ```
27
+
28
+ Rummy loads plugins from `~/.rummy/plugins/` on startup. No configuration required.
29
+
30
+ ## Usage
31
+
32
+ The plugin registers automatically via the standard Rummy plugin contract. No manual setup needed.
33
+
34
+ ```js
35
+ // Rummy's plugin loader calls this automatically:
36
+ import RepoMapPlugin from "@possumtech/rummy.repo";
37
+ RepoMapPlugin.register(hooks);
38
+ ```
39
+
40
+ ### formatSymbols
41
+
42
+ The plugin exposes a `formatSymbols` helper for rendering symbol arrays as indented text:
43
+
44
+ ```js
45
+ import RepoMapPlugin from "@possumtech/rummy.repo";
46
+
47
+ const text = RepoMapPlugin.formatSymbols(symbols);
48
+ // class MyClass L1
49
+ // method doThing(a, b) L5
50
+ // field name L3
51
+ ```
52
+
53
+ ## Development
54
+
55
+ ```bash
56
+ npm test # lint + unit tests (80% coverage threshold)
57
+ npm run lint # biome check
58
+ ```
59
+
60
+ Requires Node.js >= 25.
61
+
62
+ ## License
63
+
64
+ MIT -- PossumTech Laboratories
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@possumtech/rummy.repo",
3
+ "version": "0.0.1",
4
+ "description": "Rummy plugin for symbol extraction via antlrmap and ctags",
5
+ "keywords": [
6
+ "rummy",
7
+ "repomap",
8
+ "symbols",
9
+ "antlrmap",
10
+ "ctags"
11
+ ],
12
+ "homepage": "https://github.com/possumtech/rummy.repo#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/possumtech/rummy.repo/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/possumtech/rummy.repo.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "@wikitopian",
22
+ "engines": {
23
+ "node": ">=25",
24
+ "npm": ">=11"
25
+ },
26
+ "type": "module",
27
+ "main": "src/rummy.repo.js",
28
+ "exports": {
29
+ ".": "./src/rummy.repo.js"
30
+ },
31
+ "files": [
32
+ "src/rummy.repo.js",
33
+ "src/CtagsExtractor.js",
34
+ "src/formatSymbols.js"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "lint": "biome check src --fix --unsafe",
41
+ "test": "npm run lint && npm run test:unit",
42
+ "test:unit": "node --experimental-test-coverage --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 --test-concurrency=1 --test $(find src -name '*.test.js')"
43
+ },
44
+ "devDependencies": {
45
+ "@biomejs/biome": "^2.4.6"
46
+ },
47
+ "dependencies": {
48
+ "@possumtech/antlrmap": "^0.0.8"
49
+ }
50
+ }
@@ -0,0 +1,71 @@
1
+ import { spawnSync as defaultSpawnSync } from "node:child_process";
2
+
3
+ export default class CtagsExtractor {
4
+ #root;
5
+ #spawnSync;
6
+
7
+ constructor(root, spawnSync = defaultSpawnSync) {
8
+ this.#root = root;
9
+ this.#spawnSync = spawnSync;
10
+ }
11
+
12
+ extract(paths) {
13
+ const result = this.#spawnSync(
14
+ "ctags",
15
+ ["--output-format=json", "--fields=+nS", "-f", "-", ...paths],
16
+ { cwd: this.#root, encoding: "utf8", maxBuffer: 10 * 1024 * 1024 },
17
+ );
18
+
19
+ if (result.error && result.error.code === "ENOENT") {
20
+ console.warn("[RUMMY.REPO] skipping ctags: not installed.");
21
+ return new Map(paths.map((p) => [p, []]));
22
+ }
23
+
24
+ if (result.status !== 0) {
25
+ console.warn(`[RUMMY.REPO] skipping ctags: failed (${result.stderr})`);
26
+ return new Map(paths.map((p) => [p, []]));
27
+ }
28
+
29
+ const tags = result.stdout
30
+ .split("\n")
31
+ .filter(Boolean)
32
+ .map((l) => JSON.parse(l));
33
+
34
+ const grouped = new Map();
35
+ for (const path of paths) grouped.set(path, []);
36
+
37
+ for (const tag of tags) {
38
+ const symbols = grouped.get(tag.path);
39
+ if (symbols) {
40
+ symbols.push(this.#processTag(tag));
41
+ }
42
+ }
43
+
44
+ return grouped;
45
+ }
46
+
47
+ #processTag(tag) {
48
+ let params = tag.signature || null;
49
+
50
+ // LUA HACK: ctags doesn't provide signatures for Lua, but they are in the pattern.
51
+ // Handles both 'function name(params)' and 'name = function(params)'
52
+ if (!params && tag.path.endsWith(".lua") && tag.pattern && tag.name) {
53
+ const escapedName = tag.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
54
+ const regex = new RegExp(
55
+ `${escapedName}\\s*(?:=\\s*function\\s*)?(\\(.*?\\))`,
56
+ );
57
+ const match = tag.pattern.match(regex);
58
+ if (match) {
59
+ params = match[1];
60
+ }
61
+ }
62
+
63
+ return {
64
+ name: tag.name,
65
+ type: tag.kind,
66
+ params,
67
+ line: tag.line,
68
+ source: "standard",
69
+ };
70
+ }
71
+ }
@@ -0,0 +1,20 @@
1
+ export default function formatSymbols(symbols) {
2
+ const sorted = symbols.toSorted((a, b) => (a.line || 0) - (b.line || 0));
3
+ const stack = [];
4
+ const lines = [];
5
+
6
+ for (const s of sorted) {
7
+ while (stack.length > 0 && s.line > stack.at(-1).endLine) stack.pop();
8
+ const depth = stack.length;
9
+ const indent = " ".repeat(depth);
10
+ const kind = s.kind ? `${s.kind} ` : "";
11
+ const line = s.line ? ` L${s.line}` : "";
12
+ const p = s.params
13
+ ? `(${Array.isArray(s.params) ? s.params.join(", ") : s.params})`
14
+ : "";
15
+ lines.push(`${indent}${kind}${s.name}${p}${line}`);
16
+ if (s.endLine && s.endLine > s.line) stack.push(s);
17
+ }
18
+
19
+ return lines.join("\n");
20
+ }
@@ -0,0 +1,59 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { extname, join } from "node:path";
3
+ import Antlrmap from "@possumtech/antlrmap";
4
+ import CtagsExtractor from "./CtagsExtractor.js";
5
+ import formatSymbols from "./formatSymbols.js";
6
+
7
+ const antlrmapSupported = new Set(Object.keys(Antlrmap.extensions));
8
+
9
+ /**
10
+ * RepoMapPlugin: symbol extraction via antlrmap (ANTLR4 grammars)
11
+ * with ctags fallback.
12
+ *
13
+ * Filter: hooks.file.symbols
14
+ * Input: Map (empty or partially populated)
15
+ * Context: { paths, projectPath }
16
+ * - paths: string[] of relative file paths that changed
17
+ * - projectPath: string, absolute project root
18
+ * Output: Map<string, symbol[]> where symbol = { name, kind?, params?, line?, endLine? }
19
+ */
20
+ export default class RepoMapPlugin {
21
+ static register(hooks) {
22
+ hooks.file.symbols.addFilter(async (symbolMap, { paths, projectPath }) => {
23
+ const result = symbolMap instanceof Map ? symbolMap : new Map();
24
+ const antlrmap = new Antlrmap();
25
+ const ctagsQueue = [];
26
+
27
+ for (const relPath of paths) {
28
+ if (result.has(relPath)) continue;
29
+ const ext = extname(relPath);
30
+
31
+ if (antlrmapSupported.has(ext)) {
32
+ try {
33
+ const content = readFileSync(join(projectPath, relPath), "utf8");
34
+ const symbols = await antlrmap.mapSource(content, ext);
35
+ if (symbols?.length > 0) {
36
+ result.set(relPath, symbols);
37
+ continue;
38
+ }
39
+ } catch {
40
+ // Fall through to ctags
41
+ }
42
+ }
43
+ ctagsQueue.push(relPath);
44
+ }
45
+
46
+ if (ctagsQueue.length > 0) {
47
+ const extractor = new CtagsExtractor(projectPath);
48
+ const ctagsResults = extractor.extract(ctagsQueue);
49
+ for (const [path, symbols] of ctagsResults) {
50
+ if (symbols.length > 0) result.set(path, symbols);
51
+ }
52
+ }
53
+
54
+ return result;
55
+ }, 50);
56
+ }
57
+
58
+ static formatSymbols = formatSymbols;
59
+ }