code-moniker-core 0.5.0

Core symbol-graph types and per-language extractors for code-moniker.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/logo-dark.svg">
    <img src="docs/logo-light.svg" alt="code-moniker" width="300">
  </picture>
</p>

# code-moniker

[![CI](https://github.com/ng-galien/code-moniker/actions/workflows/ci.yml/badge.svg)](https://github.com/ng-galien/code-moniker/actions/workflows/ci.yml)
[![crates.io](https://img.shields.io/crates/v/code-moniker.svg?label=code-moniker)](https://crates.io/crates/code-moniker)
[![crates.io](https://img.shields.io/crates/v/code-moniker-core.svg?label=code-moniker-core)](https://crates.io/crates/code-moniker-core)
[![License: MIT or Apache 2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue)](#license)
[![Rust](https://img.shields.io/badge/rust-1.86%2B-orange)](https://www.rust-lang.org)

`code-moniker` extracts a symbol graph from source code.

It turns source files into stable symbol identities for inspecting code and
enforcing architecture rules in hooks or CI.

Supported languages: TypeScript / JavaScript / TSX / JSX, Rust, Java,
Python, Go, C, C#, SQL, and PL/pgSQL.

Extractor maturity is uneven by design. `code-moniker` is a fast symbol graph
extractor, not a replacement for each language compiler or type checker.

| Language | Maturity | Honest limit |
| -------- | -------- | ------------ |
| TypeScript / JavaScript | Good | No TypeScript compiler type-checking. |
| Java | Good | No `javac` semantic model. |
| Rust | Good | No macro expansion or rustc name resolution. |
| C# | Usable | No Roslyn semantic model. |
| Python | Usable | Dynamic runtime behaviour is best-effort. |
| Go | Usable | No `go/types` semantic pass. |
| SQL / PLpgSQL | Focused | Narrow dialect and no catalog-aware planner semantics. |
| C | Planned | Not extracted today. |

## At a glance

```mermaid
flowchart LR
  subgraph Input["Inputs"]
    S["Source code<br/>TS, Rust, Java, Python,<br/>Go, C, C#, SQL"]
    M["Build manifests<br/>Cargo.toml, package.json,<br/>pom.xml, pyproject.toml,<br/>go.mod, csproj"]
  end

  subgraph Model["Extraction model"]
    E["Language extractors"]
    G["Code graph<br/>defs, refs, monikers,<br/>positions, attributes"]
    D["Dependency rows<br/>package monikers"]
  end

  subgraph Tools["Tools"]
    C["CLI & services<br/>extract, check, rules,<br/>ui, manifest, mcp/daemon"]
    V["VS Code extension<br/>rules, catalog, symbols,<br/>daemon-backed checks"]
  end

  subgraph Uses["Uses"]
    I["Inspection<br/>tree, json, tsv"]
    R["Architecture rules<br/>hooks, CI, agent harnesses"]
    N["Interactive navigation<br/>TUI, MCP, daemon query"]
  end

  S --> E --> G
  M --> D
  G --> C
  D --> C
  C --> V
  C --> I
  C --> R
  C --> N
  V --> R
  V --> N

  classDef input fill:#eef6ff,stroke:#2f6f9f,color:#0b253a
  classDef model fill:#f1f8f4,stroke:#3a7d4f,color:#0f2a18
  classDef tool fill:#fff6e5,stroke:#9a6b12,color:#332100
  classDef use fill:#f7f1ff,stroke:#6f4aa1,color:#211232
  class S,M input
  class E,G,D model
  class C,V tool
  class I,R,N use
```

First useful commands:

```sh
code-moniker extract src/order.ts --format tree
code-moniker rules show .
code-moniker ui . --cache .code-moniker-cache
code-moniker check src/ --report
code-moniker manifest .
```

## What it is for

Use `code-moniker` when text search is too weak because the question is
about symbols and relationships:

- Which definitions live under `src/domain/`?
- Does domain code import infrastructure code?
- Which classes implement a port?
- Which refs point at a symbol family, even when the final segment kind
  differs across import and definition sites?
- Can this rule run after every edit, before commit, or in CI?

## Agentic development

### Challenge

Agentic development needs a stable contract between the repository and
the model. In practice, that contract is usually carried as prose:
`AGENTS.md`, prompt reminders, review comments, architecture notes, or
grep snippets. The agent must read it, keep it in context, and spend
extra turns validating boundaries that the repository could enforce
directly.

That approach breaks down in predictable ways: prompts can be missed,
grep only matches text, and review passes surface violations after the
diff already exists. In modular monorepos, agents may widen their write
scope while trying to be useful. In code bodies, they may leave narrative
comments about micro-decisions, temporary reasoning, or AI-generated
provenance, turning the code itself into noisy context for future
sessions.

### Executable contract

`code-moniker check` encodes that contract as rules over symbols, refs,
paths, and comments. Run it after writes, before commit, or in CI, and a
failure becomes a concrete repair target before the agent treats the task
as done.

| Agent overhead | Executable guardrail |
| -------------- | -------------------- |
| Long prompt rules | keep repository invariants in `.code-moniker.toml` |
| Grep-based sanity checks | evaluate symbol and reference relationships |
| Review agents for known rules | fail fast in the edit hook |
| Repeated inspect-then-fix turns | return concrete violations after each write |
| Unbounded monorepo edits | enforce write scope by module, package, or owner boundary |
| Architecture drift | block forbidden refs, imports, and layer crossings |
| Ownership ambiguity | require symbols to live under the expected path |
| Agent prose in code | reject low-value comments, temporary reasoning traces, or `AI generated` text |

This removes whole sanity-check flows: review agents, grep probes,
repeated prompt instructions, and inspect-then-fix turns. Tokens go to
the actual change instead of revalidating invariants the repository
already knows. The same contract applies to humans, agents, hooks, and
CI.

See [Agent harness](docs/cli/agent-harness.md) for Codex, Claude Code,
and Gemini CLI hooks.

## How extraction works

The unit of identity is a `moniker`: a URI-like path made of typed
segments. Each segment says what the name means, not only where text was
found.

For this file:

```ts
// src/domain/order.ts
export class OrderEntity {
  total() {
    return computeTotal();
  }
}

function computeTotal() {
  return 42;
}
```

`extract` emits definitions such as:

```text
code+moniker://./lang:ts/dir:src/dir:domain/module:order/class:OrderEntity
code+moniker://./lang:ts/dir:src/dir:domain/module:order/function:computeTotal()
```

It also emits refs between those definitions. The call inside
`OrderEntity.total()` points at the `function:computeTotal()` moniker,
so rules and queries can reason over relationships instead of strings.

Common ref kinds include calls, imports, inheritance, implemented
interfaces, type usage, annotations, and language-specific edges. In
project scans, file paths are anchored relative to the scanned root:
`code-moniker extract src/` sees `src/domain/order.ts` as
`dir:domain/module:order`.

## Install

Code Moniker 0.5 supports macOS and Linux. Its workspace daemon is currently
Unix-only, so Windows packages are not published yet.

Install the CLI. Every binary includes the embedded agent skill:

```sh
cargo install code-moniker
```

Install the agent integration for a client. With the core binary, this
materializes the versioned skill in the user's client directory:

```sh
code-moniker agent install --client codex
code-moniker agent doctor --client codex
```

Install the binary with MCP support when the integration should also register
a project-owned stdio MCP. The same `agent install` command detects that
capability and installs both components:

```sh
cargo install code-moniker --features mcp
code-moniker agent install --client codex
```

Hooks remain an explicit project policy and select no check profile by
default:

```sh
code-moniker agent install --client codex --components hooks
```

The integration has an explicit lifecycle:

```sh
code-moniker agent status --client codex
code-moniker agent doctor --client codex
code-moniker agent update --client codex
code-moniker agent uninstall --client codex
```

`code-moniker harness codex|claude|gemini` remains available as the
compatibility command for installing hooks only. New installations can use
`agent install --components hooks`, which records the component for later
diagnosis, update, and safe removal. See
[Agent integration, harness, hooks, and CI](docs/cli/agent-harness.md) for the
component matrix and exact ownership behavior.

Or install the latest `main` with the terminal UI:

```sh
cargo install --git https://github.com/ng-galien/code-moniker code-moniker --features tui,mcp
```

From a local checkout:

```sh
cargo install --path crates/cli --features tui,mcp
```

### Features

- `pretty` (default) — colored output.
- `tui` — the `ui` terminal explorer (implies `pretty`).
- `mcp` — the `mcp` server and agent MCP installation.

The default core binary remains light — `extract`, `check`, `rules`, the
embedded skill installer and hooks, but no terminal UI or MCP server:

```sh
cargo install code-moniker
```

## VS Code extension (beta)

The repository also ships a beta VS Code extension for day-to-day rule work:
workspace rule files, daemon-backed symbols, check diagnostics, and bundled
`.cm.md` learning scenarios are available from the **Code Moniker** activity
bar. The extension evolves independently from the CLI; use the platform-specific
VSIX that embeds a compatible `code-moniker` binary. Its beta releases use
separate `extension-v<version>` GitHub tags; the CLI `v<version>` releases only
contain the standalone binary archives. The current beta is available for
macOS and Linux; Windows support depends on porting the workspace daemon.

For source development, build the CLI, package the extension, and install the
generated `.vsix`:

```sh
cargo install --path crates/cli --features tui,mcp
cd vscode-extension
npm ci
npm run package
code --install-extension code-moniker-0.5.0.vsix
```

See [VS Code extension](docs/vscode-extension.md) for requirements, settings,
source installation, and development workflow.

## First CLI run

Inspect a file:

```sh
code-moniker extract src/order.ts --format tree
```

Inspect a directory:

```sh
code-moniker extract src/
```

Filter by kind or shape:

```sh
code-moniker extract src/ --shape callable
code-moniker extract src/ --kind class,interface
```

Run the linter:

```sh
code-moniker check src/
```

Open the read-only terminal explorer:

```sh
code-moniker ui . --cache .code-moniker-cache
```

Exit codes:

| Code | Meaning |
| ---- | ------- |
| `0`  | no violations |
| `1`  | at least one violation |
| `2`  | usage or configuration error |

## Configure rules

`code-moniker check` loads embedded defaults first. If a
`.code-moniker.toml` file exists, it is merged on top. Command-line
overlays can add or replace rules for one run without changing the repo:

```sh
code-moniker check src/ --rules-inline '
default_rules = false

[[ts.function.where]]
id      = "no-helper"
expr    = "name != '\''helper'\''"
message = "Pick a function name that describes the behavior."
'
```

The merge order is defaults, project rules, discovered fragments, then each
`--rules-inline` overlay in command-line order. `--default-rules on|off`
still wins over `default_rules` in files or inline TOML.

```toml
[[refs.where]]
id      = "domain-no-infra"
expr    = "source ~ '**/dir:domain/**' => NOT target ~ '**/dir:infrastructure/**'"
message = "Domain code must not depend on infrastructure."

[[ts.class.where]]
id      = "no-god-class"
expr    = "count(method) <= 20 AND all(method, lines <= 60)"
message = "Class `{name}` exceeds the class budget."

[[ts.interface.where]]
id   = "repository-lives-in-domain"
expr = "name =~ Repository$ => moniker ~ '**/dir:domain/**'"
```

Rules evaluate symbols and refs, not source text. The path pattern must
match the moniker encoding produced by the extractor. Check one file when
in doubt:

```sh
code-moniker extract src/order.ts --format json
```

## Documentation

Start with the page that matches the task:

| Task | Page |
| ---- | ---- |
| Inspect symbols from the CLI | [Extract]docs/cli/extract.md |
| Browse a graph interactively | [UI and MCP]docs/cli/ui.md |
| Measure extraction coverage and scan time | [Stats]docs/cli/stats.md |
| List manifest dependencies | [Manifest]docs/cli/manifest.md |
| Lint a repository with rules | [Check]docs/cli/check.md |
| Write rule expressions | [Rule DSL]docs/cli/check-dsl.md |
| Use the VS Code workbench extension | [VS Code extension]docs/vscode-extension.md |
| Wire checks into agent hooks or CI | [Agent harness]docs/cli/agent-harness.md |
| Run or query resident workspaces | [Daemon]docs/daemon.md |
| Understand moniker URI syntax | [Moniker URI]docs/design/moniker-uri.md |
| Build or contribute | [Contributing]CONTRIBUTING.md |

Full index: [docs/](docs/README.md).

## Performance

The CLI is designed for hooks and CI. Project scans are parallel; per-file
checks are bounded enough for edit hooks. Measurements and reproduction
commands are in [Performance](docs/perf.md).

## License

Dual-licensed under [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE),
at your option. Contributions are accepted under the same terms.