Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c8a1afc
docs(design): schema v2 id format for Go callables and types
lamwassi Nov 20, 2026
8b08451
feat(ids): Go callable and type ids use the bare member name (TS/Pyth…
lamwassi Nov 20, 2026
60f5fdd
test(v2emit): drop unused constants after the id-format change
lamwassi Nov 20, 2026
349fb84
scripts: add end-to-end eval (analysis.json -> Neo4j projection -> load)
lamwassi Nov 20, 2026
c52a7c0
scripts(eval_e2e): fix bash 3.2 unbound array and build outside the p…
lamwassi Nov 20, 2026
ed17de5
scripts(eval_e2e): add --json-only to write and check analysis.json only
lamwassi Nov 20, 2026
728748e
docs(design): cross-file method ids use the declaring file
lamwassi Nov 20, 2026
d9af418
feat(ids): cross-file methods get ids under their declaring file
lamwassi Nov 20, 2026
73f986e
docs(design): add application.name alongside application_name
lamwassi Nov 20, 2026
f9f28a1
feat(schema): add application.name alongside application_name
lamwassi Nov 20, 2026
a8b4b09
docs(design): start_line and end_line on Go span-bearing models
lamwassi Nov 21, 2026
ba30e09
feat(schema): start_line and end_line on Go span-bearing models
lamwassi Nov 21, 2026
49dbbe4
feat(schema): start_line and end_line on the JSON module
lamwassi Nov 21, 2026
07b5cdc
fix(symbol-table): keep every func init() in a file
lamwassi Nov 22, 2026
35e2cf2
fix(repository): resolve a symlinked project root before artifact dis…
lamwassi Nov 22, 2026
00ad4a6
fix(neo4j): a cross-file method belongs to the module that declares it
lamwassi Nov 22, 2026
d8234ab
fix(repository): keep artifact discovery running past unreadable file…
lamwassi Nov 22, 2026
c001e1d
fix(neo4j): stream each node row with the module that owns it (#46)
Nov 29, 2026
c679b76
fix(symbol-table): give a repeated init or _ its suffix before its cl…
Nov 29, 2026
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
43 changes: 38 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,45 @@ v2 vocabulary (parity clause: add at the leaves, never rename shared names). The
committed spec is the full transcript: `docs/design/specs/v2-l1-emission.md`.

### Identity & positioning (Group A — reused verbatim by L3/L4)
- **`application.name`** [user, 2026-11-20; spec `docs/design/specs/v2-application-name-field.md`]: an additive
field with the same value as `application_name`. `application_name` is kept unchanged (renaming a shared
field is forbidden), and `:GoApplication.name` carries the same value in Neo4j.
- **`application.id`** = `can://<app>` (app outermost, so a polyglot app shares one prefix),
where `<app>` is the **`--app-name`** value, defaulting to the input directory's base name
(per the CLI contract; the SDK's Neo4j backend must use the same anchor). Module ids are
`can://<app>/go/<file>`; externals are language-neutral `can://<app>/@external/<import-path>/<sig>`.
`can://<app>/go/<file>`; externals are language-neutral `can://<app>/@external/<import-path>/<Type>/<Member>` (see § Id member segments).
L3/L4 build ids on this unchanged.
- **Callable signature** = existing `signatureOf()` output as the last `can://` path
segment; receiver folded in for methods. One canonicalizer, unchanged from v1.
- **Id member segments (spec `docs/design/specs/v2-go-ids.md`, issue #46)**: a type is
`<module>/<Type>`; a method is `<module>/<Type>/<Method>`; a package-level function is
`<module>/<Name>` (a method declared in another file uses that file as `<module>`, see
§ Cross-file method ids below); a closure is `<enclosing>/closure_N`. The package import path is dropped:
the member segment is the signature's part after its last dot (Go names contain no dots).
Follows `codeanalyzer-typescript` `idFromSig` and `codeanalyzer-python` `child_id`
[user, 2026-11-20]. Externals: `<app>/@external/<import-path>/<Type>/<Member>` (import path
whole) [user, 2026-11-20].
- **Callable and type `signature`** = the full `signatureOf()` output (import-qualified), a
JSON field on both (types gained it, additive, for the Neo4j `:GoType.signature`) [user,
2026-11-20]. The id carries only the bare member name, so this field is where the package
path lives. One canonicalizer, unchanged from v1.
**Exception: duplicate `func init()` and `func _()`** (fix/init-collision, 2026-11-22; `_`
and closures #75/#76). Go allows many of each per file, all with signatureOf()
`<pkgpath>.init` or `<pkgpath>._`. The second and later ones in a file carry `:N` (N = 2,
3, ...), e.g. `<pkgpath>.init:2`, in `signature`, in the callable's id member (`init:2`),
as the call-graph source, in their closures' signatures (`<pkgpath>.init:2.closure_1`) and
in their L3 unit key. One function computes it (`fileDeclSignature`). The first keeps the bare name, so the
ids of files with one init are unchanged. The suffix is the only way to keep their ids and
edges distinct; a colon is not a Go identifier character, so it cannot collide with a
real function.
- **Cross-file method ids** [user, 2026-11-20]: a method declared in another file than its receiver
type gets `<declaring-module>/<Type>/<Method>`, e.g. `…/handlers.go/frontendServer/logoutHandler`.
The node stays in the receiver type's `callables{}`. `source_file` is kept for text recovery.
Neo4j adds `GO_DECLARES` from the declaring `:GoModule` to the method, beside `GO_HAS_METHOD`.
Spec: `docs/design/specs/v2-go-ids.md` § Amendment.
- **Generic types**: `signatureOf()` carries no type parameters, so a generic type or method
ids as `<module>/<Set>/<Add>`, with no `[T]` in the id.
- **`start_line` / `end_line`** [user, 2026-11-21; spec `docs/design/specs/v2-span-lines.md`]: top-level keys next
to `span` on `Module` (added 2026-11-21 so the JSON and Neo4j modules match), `Import`, `Parameter`, `Callable`, `Type`, `Field` and `BodyNode`, equal to `span.start[0]` and
`span.end[0]`. No `code_start_line`. Neo4j nodes carry the same two properties beside `span_json`.
- **`span.bytes`** = **UTF-8 byte offsets** into `module.source` (Go strings are
natively UTF-8; avoids the UTF-16/rune slicing mismatch TS hit in cants#179).

Expand Down Expand Up @@ -64,8 +96,9 @@ committed spec is the full transcript: `docs/design/specs/v2-l1-emission.md`.
`(*strings.Builder).WriteString`) is no longer dropped: the call node's `callee` and the
`call_graph` edge `dst` are the callee's `@external` id. Builtins, type conversions
(no longer minted as `<Type>.__new__`) and calls through function values stay `null`.
- **Id** = `can://<app>/@external/<import-path>/<sig>` where `<sig>` is the callee signature
minus the `<import-path>.` prefix (`Println`, `Builder.WriteString`); it may also name a
- **Id** = `can://<app>/@external/<import-path>/<Type>/<Member>` where `<sig>` is the callee signature
minus the `<import-path>.` prefix; its dots become segments (`Println` → `…/fmt/Println`,
`Builder.WriteString` → `…/strings/Builder/WriteString`); it may also name a
library *interface* method (`@external/io/Writer.Write`). Methods on generic library types
record the declared (origin) signature, not the instance. `@external` is
language-neutral (not `go/`), so a polyglot app shares one external namespace.
Expand Down
11 changes: 11 additions & 0 deletions docs/design/specs/2026-11-24-neo4j-streaming-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ At the end of each phase it flushes every buffer.
| 4 | Pass 2, for each module: push every edge. Then push `GO_CALLS`, the stand-in `GO_HAS_BODY_NODE` edges, `GO_PARAM_IN` and `GO_PARAM_OUT`. | Every node is in the DB before the first edge, so no edge `MATCH` fails. |
| 5 | `pruneVanishedModules` (full + eager only), with the module ids from the symbol table keys. | Same as today. |

Step 2 stages each node row with the module that owns it (`NodeRow.Module`), not with the module that is projected.
These are different for a cross-file method: it nests under its receiver's type, but its declaring file owns it and its id has that file's prefix.
If the writer staged the method with the receiver's module, two things would go wrong:

- An `--eager` push would write the method, and then the purge of the declaring module would delete it (#46).
- A lazy push would check the hash of the wrong module, so an edit to the declaring file would not upsert the method.

So pass 1 holds the rows of a module that has no stage yet, and adds them to that module's stage.
It sends the rows of a module that already has a stage to `owned`.
`owned` uses that module's change decision, and the purge of that module is already done.

A lazy push still upserts every edge, as it does today.
The push message reports the number of node rows and edge rows sent.

Expand Down
29 changes: 29 additions & 0 deletions docs/design/specs/v2-application-name-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Spec: `application.name` alongside `application_name` (codeanalyzer-go)

## Contract-Impact Triage

**Does this change schema v2 output?** Yes, additively. The v2 `application` node gains a
`name` field. No existing field is renamed or removed.

| Change type | Analyzers | SDKs | Docs |
| --- | --- | --- | --- |
| Additive schema field | **codeanalyzer-go** (schema, emit, Neo4j projector) | none now (python-sdk and codeanalyzer-python keep reading `application_name`) | `CLAUDE.md` § Schema decisions, this spec |

## Design-loop decisions

Made with the user on 2026-11-20.

1. **Field.** `application.name` is added to the v2 application node in `analysis.json`. Its
value is the same as `application_name`.
2. **Keep `application_name`.** Renaming it was rejected. The parity rule forbids renaming shared
fields, and `codeanalyzer-python` and `python-sdk` read `application_name`.
3. **Neo4j.** The `:GoApplication` node gets a `name` property with the same value as
`application_name`, so the two projections keep matching.
4. **Tracking.** One issue in `codeanalyzer-go`, one checklist. A PR on `fix-app-name`.
5. **Release.** One PR, one release. The python-sdk can read `name` later; nothing is required
of it now.

## Out of scope

- Removing or deprecating `application_name`. That is a later, separate schema change.
- Changing the python-sdk or codeanalyzer-python readers.
158 changes: 158 additions & 0 deletions docs/design/specs/v2-go-ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Spec: schema v2 id format for Go callables and types (codeanalyzer-go)

> **Cross-repo spec.** The python-sdk Go backend keys types and fields by the last id segment,
> so the canonical home is `codellm-devkit/.github → docs/design/specs/`, beside the
> coordinating record. Staged locally on `feat/v2-go-ids` until that repo is available (same
> precedent as `v2-l1-emission.md` and `v2-artifacts.md`). This is the design transcript of the
> datamodel loop, linked from the tracking issue, not pasted into it.

## Contract-Impact Triage

**Does this change schema v2 output?** Yes. It changes the id shape of `type`, method, and
function nodes, and of `external_symbols` keys. It does not change the module, field,
artifact, or ordinal-id shapes, and it adds no field.

| Change type | Analyzers | SDKs | Docs |
| --- | --- | --- | --- |
| Schema v2 id-format change | **codeanalyzer-go** (`internal/schema/v2/ids.go`, `v2emit`, Neo4j projector) | **python-sdk** Go backend (`cldk/analysis/go/neo4j/neo4j_backend.py` keys types and fields by last id segment; verify methods at the SDK rung) | `CLAUDE.md` § Schema decisions, `canonical-schema.md` references, this spec |

Convention anchor: `codeanalyzer-typescript/src/schema/ids.ts` (`idFromSig`: strip the module
prefix from the dotted signature, split the tail on `.`) and `codeanalyzer-python/codeanalyzer/schema/ids.py`
(`child_id`, `ordinal_id`, `external_id`, `artifact_id`).

## Problem

Go ids embed the full import-qualified signature as one segment. For a method this repeats the
package path twice:

```
can://boutique/frontend/go/middleware.go/github.com/GoogleCloudPlatform/microservices-demo/src/frontend.logHandler/github.com/GoogleCloudPlatform/microservices-demo/src/frontend.logHandler.ServeHTTP/github.com/GoogleCloudPlatform/microservices-demo/src/frontend.logHandler.ServeHTTP.closure_1@82:3/2/actual_out:2
```

The segment is not a path segment. A parser that splits on `/` (the Neo4j projector's
`lastSegment`) cannot recover a Go callable's name from its id, and the id is long and
unreadable.

## Design-loop decisions (the transcript)

Each decision was made with the user, one per question, in spine order.

### Module (unchanged)
`can://<namespace>/<app>/go/<file>`. Already the convention. No question was needed.

### Type
- **Tail = `<Type>`** (user decision, recommended). The Go package path is stripped from the
signature, then the type name is appended to the module: `<module>/logHandler`. Precedent:
TypeScript `idFromSig`, Python `child_id`. The package path is not repeated, since the module
already names the scope.
- The package path that is stripped is the `pkgPath` of the symbol's signature, which equals
the package's import path. It is the same for every symbol in one file.

### Callable
- **Function: `<module>/<Name>`**, e.g. `middleware.go/ensureSessionID`. No receiver.
- **Method: `<module>/<Type>/<Method>`** (user decision, recommended). A method nests under its
receiver type, matching containment (`type.callables`). Precedent: TypeScript split-on-dots,
Python `child_id`. Example: `middleware.go/logHandler/ServeHTTP`.
- **Closure: `<enclosing>/closure_N`** (user decision, recommended). N is the source-order index
within the enclosing callable, as the analyzer numbers them today. Example:
`middleware.go/logHandler/ServeHTTP/closure_1`. Position is not used, because the body
ordinal key already carries it.
- **Ordinal and synthetic keys are unchanged**: `<callable-id>@<line:col>`, `@entry`, `@exit`,
`@formal_in:<i>`, `@actual_in:<i>` / `@actual_out`, and the `/N` disambiguator for nested
calls at one position. Nothing in those changes.

### Field
`<type-id>/<field>`, already in this shape. No change.

### External symbols (decided earlier with the user)
`<app-id>/@external/<import-path>/<Type>/<Member>`, the TypeScript `<module>/<name>` form. The
import path stays whole, since it contains dots and slashes. A package-level function is
`<app-id>/@external/<import-path>/<Name>`.

### Call body node and call-graph edge
Unchanged in shape. A call node's `callee` and a call-graph edge's endpoints take the new
callable and external ids. No new field.

### Projector: signature property (user decision)
The Neo4j `signature` property on `:GoCallable` and `:GoType` is copied from the node's JSON
`signature` field, not derived from the id. Today the projector takes the last `/` or `@`
segment of the id (`lastSegment`), which yields `Type.Method` and loses the import-qualified
name the JSON carries. The id no longer needs to carry it.

## Consequences

- **Parsing**: a Go id splits cleanly on `/`: module, then type, then method. The `@` ordinal
suffix is unchanged.
- **Uniqueness**: ids are unique within a file. Go forbids duplicate package-scope identifiers,
and forbids a duplicate method name on one type. Two files in one package have distinct
module ids, so the stripped package path never causes a collision.
- **Cross-file methods** (amended 2026-11-20, see Amendment below): a method declared in another
file gets an id under the file that declares it, `<declaring-module>/<Type>/<Method>`. The
method node stays in its receiver type's `callables{}`, and `source_file` names the declaring
file for text recovery.
- **python-sdk**: `cldk/analysis/go/neo4j/neo4j_backend.py` keys types by `ty.id.split("/")[-1]`,
which still returns the type name, and fields by `fld.id.split("/")[-1]`, which is unchanged.
Callables keyed by a dotted sig will change meaning: the last segment is now the bare method
name. The SDK rung must verify this.

## Open items (flagged for review)

1. **Name collision inside a file**: a type `X` and a function `X` cannot share a file's package
scope, so the ids cannot collide. Confirm no other Go construct gives two nodes the same
`<module>/<Type>/<Method>` (a type's method set is unique by name). Expected: none.
2. **Generic types**: a generic type's signature includes type parameters. The `[...]` part is
not part of the segment name. Decide at implementation: strip the type parameters (default)
or keep them.
3. **Dot-free function names in `external_symbols` keys**: keys become `<import-path>/<Type>/<Member>`.
Confirm the key is still unique when two packages share a last path element.

## Tracking

One issue in `codeanalyzer-go`, rungs as checklist items (user decision). Base branch
`feat/artifacts`, since the artifact code is the base for this work (user decision). Analyzer
ships first; the python-sdk Go backend follows once the id shape is released.

## Implementation notes (2026-11-20)

- **Type signature field (amended)**: the spec said this change adds no field. The Neo4j
`:GoType.signature` needs the full name, which the type id no longer carries, so `Type`
gained a `signature` JSON field (the full `signatureOf()`), mirroring `Callable`. The
projector copies it. Decided with the user.
- **Member name rule**: implemented as "the part after the last dot of the signature". This
is the same as stripping the import path, since Go identifiers contain no dots.
- **Open item 2 (generics) resolved**: `signatureOf()` has no type parameters, so a generic
type `Set[T]` ids as `set/set.go/Set` and its method as `set/set.go/Set/Add`.
- **Open item 1 (collisions) resolved**: the generics fixture and the chi/init fixtures
produce distinct ids. `init` functions are distinct per file by module.

## Amendment (2026-11-20): cross-file method ids

Decided with the user in the design loop, after the id change landed.

**Problem.** A method is nested under its receiver type's module, so its id names the file
where the receiver lives, not the file where the method is declared. Example: `frontendServer.logoutHandler`
is declared in `handlers.go` but its id was `…/main.go/frontendServer/logoutHandler`. 22 methods in the
frontend app are affected (those with `source_file` set).

**Decisions.**

1. **Id.** A callable's id contains the file where it is declared:
`<declaring-module>/<Type>/<Method>`, e.g. `…/handlers.go/frontendServer/logoutHandler`. The type
segment stays. Rejected: `<declaring-module>/<Method>`, because a method and a package-level
function of the same name in one file would collide.
2. **JSON containment.** The node stays in its receiver type's `callables{}` (containment by
receiver is unchanged). Only its id changes. Moving it under the declaring module was rejected
because it changes containment for every consumer and hides which type the method belongs to.
3. **Text recovery.** `source_file` is kept. The id's module now equals `source_file`, but the
node still nests under the receiver's module, so its span still needs `source_file` to resolve.
4. **Neo4j.** `GO_HAS_METHOD` from the receiver `:GoType` is kept. A `GO_DECLARES` edge is added from
the declaring `:GoModule` to the method, so "which file declares this method" is one query. No
new relationship kind.

**Release.** Same PR and release as the id format (feat/v2-go-ids). Tracked in #46.

## Out of scope

- Module, field, artifact, and ordinal-id shapes.
- Any new node kind, edge kind, or field.
- Renaming the `signature` field (kept as-is).
40 changes: 40 additions & 0 deletions docs/design/specs/v2-span-lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Spec: start_line and end_line on Go span-bearing models

## Contract-Impact Triage

**Does this change schema v2 output?** Yes, additively. Six Go model types gain two integer
fields. No existing field changes.

| Change type | Analyzers | SDKs | Docs |
| --- | --- | --- | --- |
| Additive schema fields | **codeanalyzer-go** (schema, emit, Neo4j projector) | none now; python-sdk can read the keys later | `CLAUDE.md` § Schema decisions, this spec |

Anchor: `codeanalyzer-python/codeanalyzer/schema/py_schema.py`. Python puts `start_line` and
`end_line` next to `span` on imports, parameters, callables, classes, call sites and others.

## Design-loop decisions

Made with the user on 2026-11-21.

1. **Placement.** Top-level keys on each model, next to `span` (Python style), not inside `span`.
The values equal `span.start[0]` and `span.end[0]`.
2. **Scope.** All span-bearing Go models: `Import`, `Parameter`, `Callable`, `Type`, `Field`,
and `BodyNode`.
3. **`code_start_line`.** Not added. For Go the signature and the opening brace share a line in
practice, so the field would carry no information.
4. **Neo4j.** `start_line` and `end_line` are node properties beside `span_json`, on every
span-bearing node the projector writes. `Import` is an edge in Neo4j, not a node, so it gets
no property; its lines appear in the JSON only.
5. **Tracking.** One issue in codeanalyzer-go, one checklist. One PR on `add_startline_endline`.
6. **Release.** One PR, one release. The keys are additive, so existing consumers keep working.

## Amendment (2026-11-21): module

The Neo4j module node carries `start_line` and `end_line`, so the JSON module must too, or the
two projections differ. Decided with the user: the JSON `module` gains the keys, equal to its
whole-file `span.start[0]` and `span.end[0]`. The module is therefore a seventh model.

## Out of scope

- `code_start_line` (decision 3).
- Comments and variable declarations, which Python emits and v2 Go does not carry.
Loading