Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- New `codegraph list` and `codegraph stop` commands for managing the background daemon. `codegraph list` (alias `ps`) shows every running CodeGraph daemon — project, pid, version, uptime — with `--json` for scripting. `codegraph stop` stops the daemon for the current project (or `codegraph stop <path>`, or `codegraph stop --all` to stop every daemon on the machine). Previously the only way to shut a daemon down was to hunt for its pid and `kill` it by hand. (#845)
- The CodeGraph MCP server now self-heals if its main thread ever locks up. A lightweight watchdog notices when the process has stopped responding and stops it so a fresh one starts on your next request — it can no longer sit pinned at 100% CPU with no way to recover. Tune the detection window with `CODEGRAPH_WATCHDOG_TIMEOUT_MS`, or turn it off entirely with `CODEGRAPH_NO_WATCHDOG=1`. (#850)
- CodeGraph now indexes **Magik** (`.magik`) — the SmallWorld/GE Smallworld language used in GIS and asset management platforms. Exemplar definitions (`define_slotted_exemplar`, `define_mixin`, and related forms) are extracted as class nodes, `_method` declarations as methods with their exemplar as the receiver type, named `_proc` blocks as functions, `_package` declarations as namespaces, and inline `##` docstrings are preserved. Call edges are tracked across methods and procedures.

### Fixes

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ CodeGraph cuts **tokens, tool calls, and wall-clock time on every repo** — acr
| **Full-Text Search** | Find code by name instantly across your entire codebase, powered by FTS5 |
| **Impact Analysis** | Trace callers, callees, and the full impact radius of any symbol before making changes |
| **Always Fresh** | File watcher uses native OS events (FSEvents/inotify/ReadDirectoryChangesW) with debounced auto-sync — the graph stays current as you code, zero config |
| **20+ Languages** | TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Objective-C, Swift, Kotlin, Scala, Dart, Lua, Luau, R, Svelte, Vue, Astro, Liquid, Pascal/Delphi |
| **20+ Languages** | TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Objective-C, Swift, Kotlin, Scala, Dart, Lua, Luau, R, Svelte, Vue, Astro, Liquid, Pascal/Delphi, Magik |
| **Framework-aware Routes** | Recognizes web-framework routing files and links URL patterns to their handlers across 17 frameworks |
| **Mixed iOS / React Native / Expo** | Closes cross-language flows that static parsing misses: Swift ↔ ObjC bridging, React Native legacy bridge + TurboModules + Fabric view components, native → JS event emitters, Expo Modules |
| **100% Local** | No data leaves your machine. No API keys. No external services. SQLite database only |
Expand Down Expand Up @@ -673,6 +673,7 @@ is written):
| Lua | `.lua` | Full support (functions, methods with receivers, local variables, `require` imports, call edges) |
| R | `.R` `.r` | Full support (functions in every assignment form, S4/R5/R6 classes with methods, `library`/`require` imports, `source()` file references, call edges) |
| Luau | `.luau` | Full support (everything in Lua, plus `type`/`export type` aliases, typed signatures, and Roblox instance-path `require`) |
| Magik | `.magik` | Full support (exemplars as classes, methods with receiver types, named procedures, inline `##` docstrings, call edges) |

## Measured cross-file coverage

Expand Down
116 changes: 116 additions & 0 deletions __tests__/extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7161,3 +7161,119 @@ GeomPoint <- ggproto("GeomPoint", Geom,
});
});
});

// ─── Magik ──────────────────────────────────────────────────────────────────

describe('Magik Extraction', () => {
describe('Language detection', () => {
it('detects .magik files', () => {
expect(detectLanguage('my_class.magik')).toBe('magik');
});
});

it('extracts an exemplar as a class node', () => {
const code = `
_package sw

define_slotted_exemplar(:my_class,
\t{:slot_a, _unset},
\t{})
$
`;
const result = extractFromSource('my_class.magik', code);
const cls = result.nodes.find((n) => n.kind === 'class');
expect(cls).toBeDefined();
expect(cls?.name).toBe('my_class');
// Namespace from _package declaration
const ns = result.nodes.find((n) => n.kind === 'namespace');
expect(ns?.name).toBe('sw');
expect(cls?.qualifiedName).toContain('my_class');
});

it('extracts methods with exemplar receiver', () => {
const code = `
_package sw

_method my_class.my_method(x, y)
\t## Adds two numbers.
\t_local z << x + y
\t_return z
_endmethod
$

_method my_class.init(a_name)
\t_return _self
_endmethod
$
`;
const result = extractFromSource('my_class.magik', code);
const methods = result.nodes.filter((n) => n.kind === 'method');
expect(methods.length).toBe(2);

const myMethod = methods.find((n) => n.name === 'my_method');
expect(myMethod).toBeDefined();
expect(myMethod?.qualifiedName).toBe('my_class::my_method');
expect(myMethod?.signature).toBe('(x, y)');
expect(myMethod?.docstring).toBe('Adds two numbers.');

const initMethod = methods.find((n) => n.name === 'init');
expect(initMethod).toBeDefined();
expect(initMethod?.qualifiedName).toBe('my_class::init');
expect(initMethod?.signature).toBe('(a_name)');
});

it('extracts a named procedure as a function', () => {
const code = `
_package sw

_proc @my_procedure(a, b)
\t## A standalone procedure.
\t_return a * b
_endproc
$
`;
const result = extractFromSource('utils.magik', code);
const fn = result.nodes.find((n) => n.kind === 'function');
expect(fn).toBeDefined();
expect(fn?.name).toBe('my_procedure');
expect(fn?.signature).toBe('(a, b)');
expect(fn?.docstring).toBe('A standalone procedure.');
expect(fn?.qualifiedName).toContain('my_procedure');
});

it('extracts call edges from method bodies', () => {
const code = `
_package sw

_method my_class.another_method()
\t_return _self.my_method(1, 2)
_endmethod
$
`;
const result = extractFromSource('my_class.magik', code);
const callRef = result.unresolvedReferences.find(
(r) => r.referenceKind === 'calls' && r.referenceName === 'my_method'
);
expect(callRef).toBeDefined();
});

it('extracts a private method', () => {
const code = `
_package sw

_method my_class.do_internal()
\t_return 42
_endmethod
$

_private _method my_class.secret()
\t_return _self.do_internal()
_endmethod
$
`;
const result = extractFromSource('my_class.magik', code);
const secretMethod = result.nodes.find((n) => n.name === 'secret');
expect(secretMethod).toBeDefined();
expect(secretMethod?.visibility).toBe('private');
});
});
5 changes: 4 additions & 1 deletion src/extraction/grammars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const WASM_GRAMMAR_FILES: Record<GrammarLanguage, string> = {
r: 'tree-sitter-r.wasm',
luau: 'tree-sitter-luau.wasm',
objc: 'tree-sitter-objc.wasm',
magik: 'tree-sitter-magik.wasm',
};

/**
Expand Down Expand Up @@ -108,6 +109,7 @@ export const EXTENSION_MAP: Record<string, Language> = {
'.luau': 'luau',
'.m': 'objc',
'.mm': 'objc',
'.magik': 'magik',
// XML: file-level tracking; the MyBatis extractor matches `<mapper namespace="...">`
// shape and emits SQL-statement nodes (other XML returns empty).
'.xml': 'xml',
Expand Down Expand Up @@ -216,7 +218,7 @@ export async function loadGrammarsForLanguages(languages: Language[]): Promise<v
// `class Foo(...)` as an ERROR that swallows the whole class (#237); we
// vendor the upstream ABI-15 tree-sitter-c-sharp 0.23.5 wasm, which parses
// primary constructors natively.
const wasmPath = (lang === 'pascal' || lang === 'scala' || lang === 'lua' || lang === 'luau' || lang === 'csharp' || lang === 'r')
const wasmPath = (lang === 'pascal' || lang === 'scala' || lang === 'lua' || lang === 'luau' || lang === 'csharp' || lang === 'r' || lang === 'magik')
? path.join(__dirname, 'wasm', wasmFile)
: require.resolve(`tree-sitter-wasms/out/${wasmFile}`);
const language = await WasmLanguage.load(wasmPath);
Expand Down Expand Up @@ -423,6 +425,7 @@ export function getLanguageDisplayName(language: Language): string {
lua: 'Lua',
luau: 'Luau',
objc: 'Objective-C',
magik: 'Magik',
yaml: 'YAML',
twig: 'Twig',
xml: 'XML',
Expand Down
2 changes: 2 additions & 0 deletions src/extraction/languages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { luaExtractor } from './lua';
import { rExtractor } from './r';
import { luauExtractor } from './luau';
import { objcExtractor } from './objc';
import { magikExtractor } from './magik';

export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
typescript: typescriptExtractor,
Expand All @@ -51,4 +52,5 @@ export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
r: rExtractor,
luau: luauExtractor,
objc: objcExtractor,
magik: magikExtractor,
};
Loading