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 @@ -16,6 +16,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Java `static final` constants, C# `const` / `static readonly` constants, Scala `object` vals, and Kotlin top-level / `object` / `companion object` `val`s are now classified as constants rather than generic fields, so they participate in the constant-reader impact analysis above — change a `public static final` table, a `const string`, a Scala `object Config { val Timeout = … }`, or a Kotlin `companion object { const val … }` and the methods that read it now show up as affected. (Per-object Java `final` / C# `readonly` / Scala & Kotlin `class` instance properties are unchanged.) Kotlin constants were previously not indexed as their own symbols at all, so they now also appear in `codegraph search`.
- Swift top-level `let`s and `static let` constants (including those namespaced in an `enum`/`struct`, the common Swift pattern) are now indexed as constants and participate in the constant-reader impact analysis above — change a `static let defaultRetryLimit` or an `enum Constants { static let … }` and the same-file code that reads it shows up as affected. Computed properties and per-instance `let`s are not treated as constants.
- Dart top-level `const`/`final` and class `static const`/`static final` constants are now indexed as constants and participate in the constant-reader impact analysis above. Instance fields, `var`s, and locals are not treated as constants. (Generated Dart code with the standard `.g.dart`/`.freezed.dart`/`.pb.dart` suffixes is already skipped.)
- CodeGraph now indexes PowerShell scripts and modules (`.ps1`, `.psm1`, and `.psd1`), including functions, classes, methods, properties, enums, module imports, dot-sourced scripts, and command calls, so agents can explore PowerShell automation without reading every script by hand.

### Fixes

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,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, PowerShell, Svelte, Vue, Astro, Liquid, Pascal/Delphi |
| **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 @@ -679,6 +679,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`) |
| PowerShell | `.ps1`, `.psm1`, `.psd1` | Full support (functions, classes, methods, properties, enums, module/script imports, and command call edges) |

## Measured cross-file coverage

Expand Down
102 changes: 102 additions & 0 deletions __tests__/extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ describe('Language Detection', () => {
expect(detectLanguage('stdio.h', '#ifndef STDIO_H\nvoid printf();\n#endif\n')).toBe('c');
});

it('should detect PowerShell files', () => {
expect(detectLanguage('install.ps1')).toBe('powershell');
expect(detectLanguage('Modules/Widgets.psm1')).toBe('powershell');
expect(detectLanguage('Widgets.psd1')).toBe('powershell');
expect(isSourceFile('install.ps1')).toBe(true);
});

it('should return unknown for unsupported extensions', () => {
expect(detectLanguage('styles.css')).toBe('unknown');
expect(detectLanguage('data.json')).toBe('unknown');
Expand Down Expand Up @@ -129,6 +136,101 @@ describe('Language Support', () => {
expect(languages).toContain('swift');
expect(languages).toContain('kotlin');
expect(languages).toContain('dart');
expect(languages).toContain('powershell');
});
});

describe('PowerShell Extraction', () => {
it('extracts functions, classes, members, enums, imports, and command calls', () => {
const code = `
using module ./Private/Helpers.psm1

$ModuleRoot = $PSScriptRoot

function Get-Widget {
[CmdletBinding()]
param(
[string]$Name,
[int]$Limit = 10
)

Import-Module ./Private/Helpers.psm1
$items = Find-Widget -Name $Name | Where-Object { Test-Widget $_ }
foreach ($item in $items) {
Write-Output (Convert-Widget $item)
}
}

class WidgetRunner : BaseRunner {
[string]$Name

WidgetRunner([string]$name) {
$this.Name = $name
}

[void] Run() {
Get-Widget -Name $this.Name
}
}

enum WidgetState {
Ready = 1
Disabled = 2
}
`;

const result = extractFromSource('Widgets.psm1', code);
expect(result.errors).toHaveLength(0);

const symbol = (name: string, kind: string) => result.nodes.find((n) => n.name === name && n.kind === kind);
expect(symbol('Get-Widget', 'function')).toMatchObject({ kind: 'function', language: 'powershell' });
expect(symbol('WidgetRunner', 'class')).toMatchObject({ kind: 'class', language: 'powershell' });
expect(symbol('Run', 'method')).toMatchObject({ kind: 'method', language: 'powershell' });
expect(symbol('Name', 'property')).toMatchObject({ kind: 'property', language: 'powershell' });
expect(symbol('WidgetState', 'enum')).toMatchObject({ kind: 'enum', language: 'powershell' });
expect(symbol('Ready', 'enum_member')).toMatchObject({ kind: 'enum_member', language: 'powershell' });
expect(symbol('ModuleRoot', 'variable')).toMatchObject({ kind: 'variable', language: 'powershell' });

const refs = result.unresolvedReferences.map((r) => ({ name: r.referenceName, kind: r.referenceKind }));
expect(refs).toContainEqual({ name: './Private/Helpers.psm1', kind: 'imports' });
expect(refs).toContainEqual({ name: 'Find-Widget', kind: 'calls' });
expect(refs).toContainEqual({ name: 'Test-Widget', kind: 'calls' });
expect(refs).toContainEqual({ name: 'Convert-Widget', kind: 'calls' });
expect(refs).toContainEqual({ name: 'Get-Widget', kind: 'calls' });
expect(refs).toContainEqual({ name: 'BaseRunner', kind: 'extends' });
});

it('resolves PowerShell module imports and case-insensitive command calls', async () => {
const tempDir = createTempDir();
let cg: CodeGraph | null = null;
try {
fs.mkdirSync(path.join(tempDir, 'Private'), { recursive: true });
fs.writeFileSync(
path.join(tempDir, 'Private', 'Helpers.psm1'),
`function Find-Widget { param([string]$Name) Write-Output $Name }\n`
);
fs.writeFileSync(
path.join(tempDir, 'Widgets.psm1'),
`using module ./Private/Helpers.psm1\nfunction Get-Widget { find-widget -Name "demo" }\n`
);

cg = CodeGraph.initSync(tempDir);
await cg.indexAll();
cg.resolveReferences();

const findWidget = cg.getNodesByKind('function').find((n) => n.name === 'Find-Widget');
expect(findWidget).toBeDefined();
const callers = cg.getCallers(findWidget!.id).map((entry) => entry.node.name);
expect(callers).toContain('Get-Widget');

const helperFile = cg.getNodesByKind('file').find((n) => n.filePath.endsWith('Private/Helpers.psm1'));
expect(helperFile).toBeDefined();
const helperDependents = cg.getImpactRadius(helperFile!.id, 2).nodes;
expect([...helperDependents.values()].some((n) => n.filePath.endsWith('Widgets.psm1'))).toBe(true);
} finally {
cg?.close();
cleanupTempDir(tempDir);
}
});
});

Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"22": "^0.0.0",
"@clack/prompts": "^1.3.0",
"commander": "^14.0.2",
"fast-string-width": "^3.0.2",
Expand Down
7 changes: 6 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',
powershell: 'tree-sitter-powershell.wasm',
};

/**
Expand Down Expand Up @@ -108,6 +109,9 @@ export const EXTENSION_MAP: Record<string, Language> = {
'.luau': 'luau',
'.m': 'objc',
'.mm': 'objc',
'.ps1': 'powershell',
'.psm1': 'powershell',
'.psd1': 'powershell',
// 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 +220,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 === 'powershell')
? path.join(__dirname, 'wasm', wasmFile)
: require.resolve(`tree-sitter-wasms/out/${wasmFile}`);
const language = await WasmLanguage.load(wasmPath);
Expand Down Expand Up @@ -427,6 +431,7 @@ export function getLanguageDisplayName(language: Language): string {
twig: 'Twig',
xml: 'XML',
properties: 'Java properties',
powershell: 'PowerShell',
unknown: 'Unknown',
};
return names[language] || language;
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 { powershellExtractor } from './powershell';

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,
powershell: powershellExtractor,
};
Loading