Skip to content
Merged
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
40 changes: 20 additions & 20 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ layer serializes them into the schema shape.

## Schema decisions

Decisions made with the user during the v1 → v2 migration design loop
Decisions made with the user in the schema design loop
(`designing-cldk-changes`), spine order. Each is a leaf-level addition to the shared
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`.
vocabulary (parity clause: add at the leaves, never rename shared names). The
committed spec is the full transcript: `docs/design/specs/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
- **`application.name`** [user, 2026-11-20; spec `docs/design/specs/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>/<Type>/<Member>` (see § Id member segments).
L3/L4 build ids on this unchanged.
- **Id member segments (spec `docs/design/specs/v2-go-ids.md`, issue #46)**: a type is
- **Id member segments (spec `docs/design/specs/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:
Expand All @@ -45,19 +45,19 @@ committed spec is the full transcript: `docs/design/specs/v2-l1-emission.md`.
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.
Spec: `docs/design/specs/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
- **`start_line` / `end_line`** [user, 2026-11-21; spec `docs/design/specs/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).

### `type` node
- **`kind`** ∈ `struct | interface | alias | defined` — Go's four type-declaration
shapes. Collapses v1's `is_interface` boolean. (`alias` = `type X = Y`;
`defined` = `type X Y` over a non-struct, e.g. `type Celsius float64`.)
shapes (`alias` = `type X = Y`; `defined` = `type X Y` over a non-struct, e.g.
`type Celsius float64`).
- **Methods** (declared outside the type in Go source) are resolved to their receiver
type and placed in that `type.callables{}`; receiver recorded as a field. The tree
reflects containment, not source location.
Expand All @@ -68,8 +68,8 @@ committed spec is the full transcript: `docs/design/specs/v2-l1-emission.md`.
### `callable` node
- **`error_channel[]`** populated from `error`-typed return values (Go's error idiom);
those returns remain in `return_type` too. Maps Go onto the shared field.
- **Closures / function literals** → nested `callables{}` on the enclosing callable
(replaces v1 `InnerCallables`); each closure gets its own `can://` id.
- **Closures / function literals** → nested `callables{}` on the enclosing callable;
each closure gets its own `can://` id.
- **`source_file`** (optional; added in the 2026-09-29 design loop): Go allows a method
to be declared in a *different file* than its receiver type. The method node stays
nested under its receiver type (containment-by-receiver, above), but its `span.bytes`
Expand All @@ -87,8 +87,8 @@ committed spec is the full transcript: `docs/design/specs/v2-l1-emission.md`.
shared keystone vocabulary when a second language needs it.

### `call` body node
- Typed **`is_goroutine`** and **`is_deferred`** boolean fields (`defer` is net-new vs
v1). `is_constructor_call` **dropped** — Go has no constructors.
- Typed **`is_goroutine`** and **`is_deferred`** boolean fields. No
`is_constructor_call`: Go has no constructors.
- `callee` is the sanctioned `null → id` refinement slot (null at L1, backfilled at L2).

### `external_symbols` (L2 library calls)
Expand All @@ -108,8 +108,8 @@ committed spec is the full transcript: `docs/design/specs/v2-l1-emission.md`.
- Mirrors the Python/Java precedent (library callees are leaf nodes at application scope);
on by default at L2, no flag.

### L3 body and edges (`-a 3`; spec `docs/design/specs/v2-l3-l4-dataflow.md`)
- **Body node `id`** = `<callable-id>@<key>` (`v2.GlobalOrdinal`) on **every** body node,
### L3 body and edges (`-a 3`; spec `docs/design/specs/l3-l4-dataflow.md`)
- **Body node `id`** = `<callable-id>@<key>` (`schema.GlobalOrdinal`) on **every** body node,
**from `-a 1` on** (not L3+ only) — Python parity (codeanalyzer-python stamps body ids at
L1). **`parent`** (L3 only) = the local key of the statement a satellite call sits in.
- **Body kinds: shared vocabulary only, no Go-specific kinds** — `if` → `branch`;
Expand All @@ -128,7 +128,7 @@ committed spec is the full transcript: `docs/design/specs/v2-l1-emission.md`.
- **`k_limit`** (envelope, L3+ only) = `--graph-field-depth` (default 3), the access-path
bound of the syntactic `ddg` (`x.f.g.h` → `x.f.g.*`); `ddg.prov` is `["ssa"]` (parity).

### L4 SDG (`-a 4`; spec `docs/design/specs/v2-l3-l4-dataflow.md` §4.6–§4.16, §6)
### L4 SDG (`-a 4`; spec `docs/design/specs/l3-l4-dataflow.md` §4.6–§4.16, §6)
Reuses Group A ids/spans and the L3 vocabulary unchanged; every L4 fact is an addition
(`-a 3` ⊆ `-a 4`, gated). Leaves:
- **Vertices** (body nodes, span-less, no `callee`): `@formal_in:<i>`, `@formal_out[:<i>]`,
Expand Down Expand Up @@ -162,20 +162,20 @@ Reuses Group A ids/spans and the L3 vocabulary unchanged; every L4 fact is an ad
- A Go-specific `select` cfg kind was not added (`select` is a `switch` with `switch_case`
edges).

### Repository-artifact decisions (spec `docs/design/specs/v2-artifacts.md`, branch `feat/artifacts`)
### Repository-artifact decisions (spec `docs/design/specs/artifacts.md`, branch `feat/artifacts`)
Made with the user in the 2026-11-19 design loop, anchored on `codeanalyzer-python`'s `PyArtifact` / `PyDependency`.
- **Placement:** `application.artifacts{<path>: artifact}` (map); `application.dependencies[]` (list).
- **Scope:** all non-`.go` project files [user, 2026-11-19]. Binaries are metadata only (`source:""`) [user]. Discovery skips what the Go analysis skips (`utils.IsVendored`: `vendor`, `testdata`, `.git`, also a `.git` file), and the tool's own outputs (the `-o` and `-c` directories whole unless they hold the project; `graph.cypher` in the working directory for `--emit neo4j` without `-o`). A symlinked file is followed only to a file inside the project.
- **Artifact id:** `can://<app>/artifact/<path>`, app-scoped (Python parity) [user]. The Go projector's `:Artifact` flips to `CanNode=true`.
- **Package id:** version-less `pkg:golang/<module-path>` [user]; version lives on the dependency edge.
- **Source text:** `--artifact-text`, on by default; `--no-artifact-text` drops it (Python and TypeScript parity) [user]. `config_keys` deferred [user].
- **Dependencies:** every `go.mod` require; `direct=false` on `// indirect`; `kind:"runtime"`; `go.sum` supplies `locked_version` only, `go.sum`-only entries excluded [user]. `locked_in` names the `go.sum` artifact that locked it; the projector reads it, and `v2.PackageID` is the one package-id builder. A `replace` keeps the dependency's `name` and `spec`, records `replaced_by` (`<path>@<version>` or a local directory, which also adds `"replace"` to `prov`), and takes `locked_version` from the replacement, by Go's replace rule.
- **Dependencies:** every `go.mod` require; `direct=false` on `// indirect`; `kind:"runtime"`; `go.sum` supplies `locked_version` only, `go.sum`-only entries excluded [user]. `locked_in` names the `go.sum` artifact that locked it; the projector reads it, and `schema.PackageID` is the one package-id builder. A `replace` keeps the dependency's `name` and `spec`, records `replaced_by` (`<path>@<version>` or a local directory, which also adds `"replace"` to `prov`), and takes `locked_version` from the replacement, by Go's replace rule.
- **`provides_imports`:** longest-prefix match against `go.mod` module paths [user]. A `-t` run reads every project package's imports with a light package load, so it matches a full run.
- **Level:** L1, every level, not gated [user].

## Neo4j-projection decisions

The graph projection (`--emit neo4j`) is a **second projection of the same v2 envelope**,
The graph projection (`--emit neo4j`) is a **second projection of the same envelope**,
keyed on the identical `can://` ids — JSON and graph join on one string, never recomposed.
These are the Go leaf decisions, made with the user in the 2026-10-04 design loop
(`designing-cldk-changes`), under the parity clause (add `GO_`/`Go` leaves; reuse the
Expand Down Expand Up @@ -257,7 +257,7 @@ shared neutral vocabulary verbatim; never rename a sibling's shared name). Spec:
### L3 overlay (live at `-a 3`)
- `GO_CFG_NEXT {kind}`, `GO_CDG`, `GO_DDG {var, prov}` are no longer reserved; the projector
emits one row per JSON `cfg[]`/`cdg[]`/`ddg[]` entry (cross-projection count gate).
Endpoints are `:GoBodyNode` **global ids** (`v2.GlobalOrdinal(callable-id, local-key)`),
Endpoints are `:GoBodyNode` **global ids** (`schema.GlobalOrdinal(callable-id, local-key)`),
never recomposed by hand. `prov` is a string-array prop.
- `:GoBodyNode` covers every body node incl. synthetic `@entry`/`@exit` (id
`<callable-id>@entry`, no `span_json`), each with `GO_HAS_BODY_NODE` from its callable.
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The binary is fully self-contained: a single static executable with no runtime d
dependencies for SDK users.
- **CLDK canonical schema** — output is spine-compatible with the Java/Python/TypeScript analyzers,
loadable directly by the Python SDK.
- **Neo4j projection** — the same v2 envelope projected into a property graph (`--emit neo4j`),
- **Neo4j projection** — the same envelope projected into a property graph (`--emit neo4j`),
either as a replayable `graph.cypher` snapshot or pushed live over Bolt, keyed on the identical
`can://` ids so JSON and graph join on one string.

Expand Down Expand Up @@ -248,7 +248,7 @@ cango -i /path/to/go/app -a 2 -o /path/to/output/
# → writes /path/to/output/analysis.json
```

> **Schema.** `cango` emits the **canonical CLDK v2** tree (the shape the Python SDK's v2
> **Schema.** `cango` emits the **canonical CLDK** tree (the shape the Python SDK's
> loader and the sections below describe). Omit `-o` to stream the JSON to stdout instead
> of writing a file.

Expand Down Expand Up @@ -354,10 +354,10 @@ subset of `-a 4` output, and `-j 1` and `-j N` output are byte-identical.

## Output schema

`cango` emits the **canonical CLDK v2** shape — the shape the v2 Python SDK loader consumes
`cango` emits the **canonical CLDK** shape — the shape the Python SDK loader consumes
and the [step-by-step section above](#generating-analysisjson-for-a-go-app) produces.

### Canonical v2 shape
### Canonical shape

The document is a manifest envelope wrapping one `application` containment tree. Every
node carries a `can://<namespace>/<app>/…` `id`, a `kind`, and a `span`:
Expand Down Expand Up @@ -431,7 +431,7 @@ node carries a `can://<namespace>/<app>/…` `id`, a `kind`, and a `span`:
}
```

Key v2 schema properties:
Key schema properties:
- **Envelope** — `schema_version` (`"2.0.0"`), `language` (`"go"`), `max_level` (1–4),
`k_limit` (L3+: the `--graph-field-depth` value), `degraded[]` (L4, only when something
degraded) and `analyzer{name,version}` wrap a single `application` node.
Expand All @@ -440,8 +440,8 @@ Key v2 schema properties:
- **`id`** — every node carries a durable `can://<namespace>/<app>/go/<file>/<type>/<signature>` id;
`<app>` is the `--app-name` anchor. A body node is keyed by `line:col` in its callable's `body`
map and carries `id` = `<callable-id>@<key>` at every level, from `-a 1` on.
- **`kind`** — `module` · `type` kinds `struct | interface | alias | defined` (collapses v1's
`is_interface`) · `callable` kinds `function | method | lambda` · body `call`.
- **`kind`** — `module` · `type` kinds `struct | interface | alias | defined` ·
`callable` kinds `function | method | lambda` · body `call`.
- **`base_types: []`** (type, optional) — embedded type ids (struct/interface embedding — the
explicit spine), as opposed to interfaces the type is *computed* to satisfy.
- **`span`** — `{start:[line,col], end:[line,col], bytes:[from,to]}`; `bytes` are **UTF-8 byte
Expand All @@ -468,7 +468,7 @@ Key v2 schema properties:
(`<callable-id>@<key>`).
A call nested in a statement carries `parent`, the statement's key. The callable gains
`cfg[] {src, dst, kind}`, `cdg[] {src, dst}` and `ddg[] {src, dst, var, prov}`, whose
endpoints are `body` keys. See `docs/design/specs/v2-schema-structure.md`.
endpoints are `body` keys. See `docs/design/specs/schema-structure.md`.
- **L4 (`-a 4`)** — `body` gains span-less vertices `@formal_in:<i>`, `@formal_out[:<i>]`,
`<call-key>/actual_in:<i>`, `<call-key>/actual_out[:<i>]`, each with `of` (the bound name:
a parameter or receiver name, `_<i>`, `_recv`, `<return>`, `<return>:<i>`,
Expand All @@ -481,7 +481,7 @@ Key v2 schema properties:

## Neo4j projection (`--emit neo4j`)

`--emit neo4j` projects the **same v2 envelope** into a Neo4j property graph. It is a *second
`--emit neo4j` projects the **same envelope** into a Neo4j property graph. It is a *second
projection of the identical analysis* — JSON nodes and graph nodes carry the same `can://<namespace>/<app>/…`
ids, so the two join on one string and are never recomposed. The graph vocabulary is `Go`-prefixed
labels (`:GoModule`, `:GoType`, `:GoCallable`, `:GoField`, `:GoBodyNode`, `:GoExternal`, plus the
Expand Down Expand Up @@ -533,7 +533,7 @@ What a re-emit replaces depends on the path:
> — symbol table, call graph, every callable's body nodes with `GO_CFG_NEXT` / `GO_CDG` /
> `GO_DDG`, and the SDG: vertex `:GoBodyNode`s with `var`, `GO_PARAM_IN` / `GO_PARAM_OUT {var}`,
> `GO_SUMMARY`, stand-in vertices under their `:GoExternal`, and `degraded_json` on
> `:GoApplication`) and canonical schema v2. Do **not** pass `-a`/`--analysis-level`
> `:GoApplication`) and the canonical schema. Do **not** pass `-a`/`--analysis-level`
> with it — an explicit level is a flag error (`--analysis-level does not apply to --emit neo4j`),
> because there is no shallower graph to ask for.

Expand Down
22 changes: 11 additions & 11 deletions cmd/codeanalyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

import (
"fmt"
v2 "github.com/codellm-devkit/codeanalyzer-go/internal/schema/v2"
"github.com/codellm-devkit/codeanalyzer-go/internal/schema"
"os"
"path/filepath"
"runtime"
Expand All @@ -17,7 +17,7 @@ import (
"github.com/codellm-devkit/codeanalyzer-go/internal/core"
"github.com/codellm-devkit/codeanalyzer-go/internal/neo4j"
"github.com/codellm-devkit/codeanalyzer-go/internal/options"
"github.com/codellm-devkit/codeanalyzer-go/internal/syntactic_analysis/v2emit"
"github.com/codellm-devkit/codeanalyzer-go/internal/syntactic_analysis/emit"
"github.com/codellm-devkit/codeanalyzer-go/internal/utils"
)

Expand All @@ -38,7 +38,7 @@ func rootCmd() *cobra.Command {
inputPath string
outputDir string
format string
emit string
projection string
appName string
namespace string
level int
Expand Down Expand Up @@ -80,7 +80,7 @@ via CLDK(language="go").analysis(project_path=...).`,
// analysis path below but is ALWAYS full-depth, so an explicit
// -a/--analysis-level alongside it is a flag error (the level gate
// applies to the JSON path only).
emitTarget := options.EmitTarget(emit)
emitTarget := options.EmitTarget(projection)
switch emitTarget {
case options.EmitJSON:
if err := validateAnalysisLevel(level); err != nil {
Expand All @@ -104,7 +104,7 @@ via CLDK(language="go").analysis(project_path=...).`,
}
// Force full depth: the graph carries every implemented
// level's facts in both projections. (Output is always the
// canonical v2 tree.) L4 is whole-program, so a targeted run
// canonical tree.) L4 is whole-program, so a targeted run
// projects at L3 and says so.
level = int(options.LevelSDG)
if len(targetFiles) > 0 {
Expand All @@ -123,7 +123,7 @@ via CLDK(language="go").analysis(project_path=...).`,
cmd.Println("wrote " + path)
return nil
default:
return fmt.Errorf("unsupported --emit target %q; supported: json, neo4j, schema", emit)
return fmt.Errorf("unsupported --emit target %q; supported: json, neo4j, schema", projection)
}

if inputPath == "" {
Expand Down Expand Up @@ -165,15 +165,15 @@ via CLDK(language="go").analysis(project_path=...).`,
if cmd.Flags().Changed("namespace") {
ns = &namespace
}
identity, err := v2.ResolveIdentity(appName, ns)
identity, err := schema.ResolveIdentity(appName, ns)
if err != nil {
return err
}
opts := options.AnalysisOptions{
InputPath: inputPath,
OutputDir: outputDir,
Format: format,
Emit: options.EmitTarget(emit),
Emit: options.EmitTarget(projection),
AppName: appName, Namespace: ns,
Level: options.AnalysisLevel(level),
Strict: strict,
Expand All @@ -200,12 +200,12 @@ via CLDK(language="go").analysis(project_path=...).`,
}
utils.LogMemory("analysis")

// Neo4j projection: stream the canonical v2 payload (the SAME modules
// Neo4j projection: stream the canonical payload (the SAME modules
// the JSON path emits) one module at a time into the projection, so
// the full tree is never held (#59). --neo4j-uri set → live Bolt push;
// absent → a graph.cypher snapshot in the output dir.
if emitTarget == options.EmitNeo4j {
src := v2emit.Open(app, identity, opts.InputPath, int(opts.Level), opts.AnalyzerVersion, core.KLimit(opts), analyzer.L3(), analyzer.L4())
src := emit.Open(app, identity, opts.InputPath, int(opts.Level), opts.AnalyzerVersion, core.KLimit(opts), analyzer.L3(), analyzer.L4())
boltCfg := neo4j.BoltConfig{
URI: opts.Neo4jURI,
User: opts.Neo4jUser,
Expand Down Expand Up @@ -239,7 +239,7 @@ via CLDK(language="go").analysis(project_path=...).`,
f.StringVarP(&inputPath, "input", "i", "", "Project root to analyze (required)")
f.StringVarP(&outputDir, "output", "o", "", "Output directory for analysis.json (default: stdout)")
f.StringVarP(&format, "format", "f", "json", "Output format: json|msgpack")
f.StringVar(&emit, "emit", "json", "Output projection: json|neo4j|schema")
f.StringVar(&projection, "emit", "json", "Output projection: json|neo4j|schema")
f.StringVar(&namespace, "namespace", "", "Identity namespace (default: application name)")
f.StringVar(&appName, "app-name", "",
"Application anchor name for can:// ids and Neo4j :Application (default: input dir name)")
Expand Down
Loading
Loading