Skip to content
Back to skills

Cg

ASecurity

Trace code and assess change impact via the pre-built symbol, call-graph and co-edit index.

  • 49 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 2, 2026
ai-agentspythonrustgobashnextjsnodegitapidocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add Surething-io/cockpit --skill cg --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cg?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cg
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/surething-io-cockpit-2bff27d5/badge)](https://www.skillsdirectory.com/skills/surething-io-cockpit-2bff27d5)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cg
description: "Trace code and assess change impact via the pre-built symbol, call-graph and co-edit index."
---

Enter project graph exploration mode (CodeGraph).

CodeGraph = pre-built symbol + call-graph index + git co-edit view. One endpoint per class of question:

| Question | Endpoint |
|---|---|
| Where is X defined / which files share the name? | search?q=X |
| Export every function/method, optionally within a directory? | symbols?path=src |
| Who calls X? | callers?qname=X |
| What does X call? | callees?qname=X |
| Changing X affects which symbols? | impact?qname=X&depth=2 |
| What symbols does file F contain? | file?path=F |
| Which files are commonly edited alongside F? (conventional coupling / parallel registries) | coedit?filePath=F |
| What is near X — callers, callees and frequent co-edits, ranked? | related?qname=X |
| Which tests reach these files through imports? | affected?files=a,b |
| Imports, cross-file calls and per-function complexity under a directory? | edges?path=D |
| A directory's architecture, outside in — modules, entries, dependencies, public API, hotspots? | maps?path=D |
| Functions under a directory with nearly the same syntax shape? | clones?path=D |
| Complex and untested functions (complexity × coverage from an existing report)? | crap?path=D |

Test files are left out of search / symbols results by default, and every such response says how many in
`filtered.tests` — see **Test files** below before trusting an absence.

All responses are coordinates / file paths — never source bodies. (One exception: `search&includeLiterals=true` echoes each matched literal's own text in `value`.) More precise than grep's textual match, cheaper in tokens than Reading whole files.

## Graph endpoints ({{BASE_URL}})

```bash
# search: find symbols by name → hits carry the same node shape as every other
#   endpoint, so a hit's startLine/endLine feed Read directly.
# q is normalized for naming style: user_profile / userProfile / user-profile / USER_PROFILE are equivalent
# limit defaults to 50 per category and is capped at 500; use symbols for a full export.
# All eligible candidates are scanned. Ranking: raw exact name > normalized exact
# > normalized prefix > normalized substring; ties use path, qualifiedName, then line.
# path limits the directory (including descendants). Test files are left out of every category
# (excludeTests=false keeps them; see "Test files"). Small limits still find exact definitions after many fuzzy matches.
# Pass includeLiterals=true to also search identifier-shaped string literals (tool names, event names,
# config keys, route paths — the "looks like a name but isn't an identifier" strings). The response
# then carries an extra literals[] array with value / filePath / line / enclosingSymbol per hit.
curl -fsS "{{BASE_URL}}/api/projectGraph/search?cwd=$PWD&q=<NAME>"
curl -fsS "{{BASE_URL}}/api/projectGraph/search?cwd=$PWD&q=<NAME>&includeLiterals=true"
curl -fsSG "{{BASE_URL}}/api/projectGraph/search" --data-urlencode "cwd=$PWD" \
  --data-urlencode 'q=<NAME>' --data-urlencode 'path=apps/api/src/features' \
  --data-urlencode 'limit=5'

# Full export: defaults to function + method, including indexed nested symbols.
# path is a project-relative directory including descendants. Omit it for the whole project.
# kind accepts a comma-separated list or all (real symbols only).
# includeSynthetic=true also includes unknown UI blocks (__imports__, __code_*).
# Repeat exclude for POSIX globs rooted at cwd. Quote globs; dot paths require explicit dots.
# Start broad exploration with a summary; no result-count cap or export cache.
curl -fsSG "{{BASE_URL}}/api/projectGraph/symbols" --data-urlencode "cwd=$PWD" \
  --data-urlencode 'path=packages/feature' \
  --data-urlencode 'kind=all' --data-urlencode 'format=summary'

# Save full exports to disk, then print only a bounded selection of candidates.
curl -fsSG "{{BASE_URL}}/api/projectGraph/symbols" --data-urlencode "cwd=$PWD" \
  --data-urlencode 'path=src' \
  --data-urlencode 'exclude=**/generated/**' --data-urlencode 'exclude=**/*.spec.ts' \
  -o /tmp/cg-symbols.json

# callers / callees: 1-hop call relations
curl -fsS "{{BASE_URL}}/api/projectGraph/callers?cwd=$PWD&qname=<QNAME>"
curl -fsS "{{BASE_URL}}/api/projectGraph/callees?cwd=$PWD&qname=<QNAME>"

# impact: transitive callers BFS (depth 1-5, default 2; out-of-range is clamped
#   silently, not rejected). `truncated: true` = node ceiling hit, list is partial.
curl -fsS "{{BASE_URL}}/api/projectGraph/impact?cwd=$PWD&qname=<QNAME>&depth=2"

# file: file symbol tree (no source). Hierarchical: nested symbols live in
#   children[] — always an array, empty for leaves (never null / never absent).
curl -fsS "{{BASE_URL}}/api/projectGraph/file?cwd=$PWD&path=<REL_PATH>"

# coedit: files commonly edited alongside the target = git log history + current working-tree co-edits
#   catches "conventional coupling" the call-graph can't see (parallel registries / double-writes / sibling .md configs)
#   history[] entries may name PRE-RENAME paths (git --follow), so a path here need not exist today.
#   `cooccurrence` is a RAW COUNT; the ratio ships alongside as `probability`.
curl -fsS "{{BASE_URL}}/api/projectGraph/coedit?cwd=$PWD&filePath=<REL_PATH>"
```

## Response shapes

Every endpoint speaks ONE node shape (call it NODE):

`{ filePath, qualifiedName, name, kind, startLine, endLine, declLine, params?[] }`

`startLine` / `endLine` span the whole symbol INCLUDING the doc comment glued above
a top-level declaration and any Python decorators, so `startLine` can sit several
lines above the `function` / `def` / `class` keyword. `declLine` is the declaration line itself (equal to `startLine`
when there is no doc comment). Read with `startLine`..`endLine`; cite a symbol as
`filePath:declLine`.

`params` is OPTIONAL: absent for non-callables (class / interface / type / enum /
const) and for languages without a tree-sitter grammar. `params: []` is different —
it means "0 parameters", not "unknown".

```
search    { files[], symbols[], literals?[] }      # literals only with includeLiterals=true
            files[]    = { type:'file',    label, hint?, target: { filePath } }
            symbols[]  = { type:'symbol',  label, hint?, target: NODE }
            literals[] = { type:'literal', value, filePath, line, enclosingSymbol? }
            # narrow on the outer `type`
            # filtered = { tests, testFiles? } — tests that WOULD have matched
symbols   { revision, incomplete, total, symbols[]: NODE, excludedFiles[], filtered }
            # excludedFiles[] = { filePath, reason:"source-too-large", sizeBytes, limitBytes }
            #                 | { filePath, reason:"minified", sizeBytes }
            # exclusions cover the entire revision, before export filters
            # flat output; default kind=function,method; kind=all includes all real kinds
            # unknown display blocks require includeSynthetic=true
            # format=summary replaces symbols[] with files, byKind, byDirectory:
            # [{path, total, files, byKind}]; groups are immediate child directories
            # of path. Direct files use path or '.'. All export filters apply.
            # total is the count after filters; incomplete describes source-index coverage
file      { filePath, language, symbols[] }
            symbols[] = NODE plus { contentHash, children[] }
            # children[] is always an array, empty for leaves (never null / absent)
callers   { qname, target: NODE|null, callers[]: { caller: NODE, callLines[] }, ambiguousIn? }
callees   { qname, target: NODE|null, callees[]: { callee: NODE, callLines[] }, ambiguousIn? }
impact    { qname, target: NODE|null, nodes[]: { symbol: NODE, depth }, truncated, ambiguousIn? }
coedit    { target: string, totalCommits, uncommitted[],
            history[]: { filePath, cooccurrence, probability, lastCoEdit } }
            # probability = cooccurrence / totalCommits, precomputed. `cooccurrence`
            # alone is a RAW COUNT — never compare it against a ratio threshold.
related   { target, results[]: NODE + { score, relations[] }, coedit[], degraded, degradedReason?, ambiguousIn? }
affected  { testFiles[], byInput[]: { filePath, reachable, reachableTests[] },
            unresolved[], stats: { visited, bfsMs, truncated }, degraded }
```

## Related code and affected tests

Project graph endpoints share the base symbol/import/call index. Coedit reads Git on
request. There is no secondary analysis cache or warm-up phase.

Only Git working trees (including linked worktrees) are supported. Every
project-index query verifies Git membership and source content hashes, then
reuses unchanged parse facts and atomically publishes consistent relations.
Watcher events only record changes; they never trigger parsing by themselves.
Tracked `node_modules` files are excluded too. Tests remain indexed.

## Analysis endpoints — one directory at a time

```bash
B="{{BASE_URL}}/api/projectGraph"
# imports, cross-file calls (calls[].byName marks guesses), outside importers, complexity per function
curl -fsSG "$B/edges"  --data-urlencode "cwd=$PWD" --data-urlencode 'path=<DIR>'
# architecture, outside in; layers = the repo's declared layering (JSON), reach=true adds
# multi-hop entry → write paths (a lead: the call graph is incomplete)
curl -fsSG "$B/maps"   --data-urlencode "cwd=$PWD" --data-urlencode 'path=<DIR>' \
  [--data-urlencode 'layers=<json>'] --data-urlencode 'format=markdown'
# same-shape function groups (threshold=0.82, minLines=4, minNodes=20, limit=100) — leads, not merges
curl -fsSG "$B/clones" --data-urlencode "cwd=$PWD" --data-urlencode 'path=<DIR>'
# CRAP = CC² × (1 − coverage)³ + CC from reports that already exist (coverage=<file>, repeatable);
# never runs tests — no report → complexity only
curl -fsSG "$B/crap"   --data-urlencode "cwd=$PWD" --data-urlencode 'path=<DIR>'
```

These four are HTTP only: `cockpit codegraph` has no subcommand for them.

## Test files

One policy for every endpoint that filters (search, symbols, and the analysis endpoints
edges / maps / clones / crap) and for `affected`, which uses it to pick tests:

- **Convention** (heuristic): `*.test.*` / `*.spec.*` / `*.e2e.*` names, `test/` `tests/`
  `__tests__/` directories, Python `test_*.py`, Go `*_test.go`. A Next.js route / page under
  `app/**/test/` is a URL, not a test.
- **Default `excludeTests=true`**: filtering endpoints leave tests out and return
  `filtered: { tests: N }` (markdown outputs print one line). N counts files under `path`; for
  search, only tests that would have matched.
- **Look before trusting an absence**: `explainTests=true` adds
  `filtered.testFiles: [{ filePath, rule }]`, the rule being what matched
  (`directory tests/`, `name *.test|spec|e2e.*`, `test <glob>` …).
- **Correct it** per query with repeatable POSIX globs rooted at cwd: `notTest=<glob>` (never a
  test; wins) and `test=<glob>` (also a test, e.g. `e2e/**`). `affected` takes the same two, as
  query params or JSON arrays in the POST body. `excludeTests=false` keeps every test.
- `excludeTests`, `explainTests`, `includeLiterals`, `includeSynthetic` and `affected`'s
  `includeAll` accept `true` / `false` / `1` / `0` (in a POST body also as JSON booleans or
  numbers). Only an absent parameter or field takes the default; anything else, an empty value
  or JSON `null` included, is a 400.
- A left-out file is listed nowhere in a response — not as a result, not as the other end of an
  import or call (`edges` `imports` / `calls[].toFile`), not in counts derived from them — and
  `maps` never walks through one (route files, handler definitions, any function on a call chain,
  inside `path` or out). Files outside `path` are left out uncounted. Not query output, so still
  listed: `excludedFiles` (files the index itself skipped) and `crap` `reports`.

Worktrees sharing a canonical Git common directory reuse identical per-path
parse facts and lookup maps. Relations are resolved independently, then equal
whole-file relation bundles share read-only storage. File membership, timestamps,
configuration, revisions and failures remain worktree-local. Published roots own
the shared storage; eviction releases their references, and the memory budget
counts each shared block once.

Known Git operations in progress or paused on conflicts reject ordinary
queries. Finish the operation first; an explicit UI rebuild can inspect the
current workspace. Large changes rebuild all relations at 500 changed paths,
or at least 20 paths representing 20% of the larger old/new source count.
Manual force rebuild reparses all admitted sources. Symbol-only file previews
stay local. Opening the function call graph queries the project index on demand
and waits for its relations (`file-functions&relations=1`). Source/file caps are reported as incomplete
coverage (`X-Code-Index-Incomplete: 1` on project queries). Sources exceeding
512 KiB (524,288 actual input bytes) are excluded; exactly 512 KiB is admitted.
Minified bundles (`*.min.js` and the like, or 4 KiB+ sources averaging over
250 characters per line) are excluded too, but as policy, not as incomplete
coverage. The symbols response lists every excluded path, its reason and byte
size in `excludedFiles`, even when outside the export directory. Responses also
include `X-Code-Index-Revision`. Fingerprints do not make heuristic call
resolution exact.

```bash
# Related = direct callers, callees, and frequent coedit partners.
# include=structural skips Git; include=coedit skips direct call relations.
curl -fsS "{{BASE_URL}}/api/projectGraph/related?cwd=$PWD&qname=<QNAME>&topK=10&include=all"

# File-level reverse-import closure, with test-file recognition.
curl -fsS "{{BASE_URL}}/api/projectGraph/affected?cwd=$PWD&files=<a.ts,b.ts>&depth=10"

# For large input lists, cwd belongs in the JSON body.
curl -fsS -X POST "{{BASE_URL}}/api/projectGraph/affected" -H 'content-type: application/json' \
  -d '{"cwd":"'"$PWD"'","files":["a.ts","b.ts"],"depth":10}'

# Plain format emits test paths; diagnostics are returned in headers.
curl -fsS "{{BASE_URL}}/api/projectGraph/affected?cwd=$PWD&files=<a.ts>&format=plain"
```

`related.relations` contains `caller{callLines[]}`, `callee{callLines[]}`, or
`frequent-coedit{cooccurrence,totalCommits}`. Scores are ranking heuristics only:
0.4 per direct relation, plus 0.3 times the coedit probability. They are not risk
estimates. Coedit partners use their first real symbol as a navigation anchor;
the relation is evidence about the file, not evidence that this symbol changed.
The raw `coedit[]` includes non-code and historical paths and adds `totalCommits`
to each history row. Reuse it rather than calling `/coedit` again.

## Interpretation and limits

- Check `target !== null` before interpreting empty results. Unknown symbols
  return HTTP 200 with empty relations. Use `search` to locate the definition.
- Use `qualifiedName` verbatim (`Parent>Child`), and pass `filePath` to
  disambiguate. On ambiguity, `callers`, `callees`, `impact`, and `related`
  return HTTP 200 with target=null, empty relations and candidate paths in
  `ambiguousIn`. No target is auto-selected; no relations or coedit are computed.
  Retry with the intended filePath. The CLI exits 2 on ambiguity, including
  --json mode, while preserving the JSON response.
- For project/business overviews, query symbols with format=summary first,
  then narrow path/kind. Keep full exports on disk; never print every symbol
  into context. Read at most 30 selected coordinates per batch. Business
  ownership still requires module documentation and source confirmation.
- Static call resolution is incomplete. Exported singleton-instance methods,
  aliases such as `export const alias = original`, and dynamic dispatch can
  lack incoming edges. Empty callers or impact is not evidence of safety.
  Cross-check source/text search; `affected` offers a broader file-import view
  within the imports the index can resolve.
- TS/JS call edges are exact only when the source proves them: a plain or
  imported call no local binding shadows, `this.m()` where `this` belongs to a
  top-level class or object that has its own `m`, `imp.m()` on an unshadowed
  import. Every other call is matched to same-named methods in its file and is a
  guess, labelled `byName`: `this.x.m()`, `make().m()`, `super.m()`, `this.m()`
  whose class has no own `m` (it may be inherited — so a same-named method of an
  unrelated class can appear), and calls under `with` / `eval`. The label shows
  as `edges` `calls[].byName: true`. `maps` lists an entry's direct calls from
  exact edges only; its opt-in `reach=true` paths mark byName hops as
  `byNameHops` (JSON) / `~>`, walk exact calls first (a byName hop only when no
  exact path reaches that write), and mark such reaches where they are counted —
  `states[].entriesByName`, `~` after an entry, `(N by name only)`. Read a byName hop before relying on it. `callers`, `callees`,
  `impact` and `related` do not carry the label yet, so a TS/JS method edge there
  may be such a guess.
- `related.degradedReason` is `coedit-unavailable` when Git lookup fails, or
  `truncated` when the source index is capped. Empty successful Git history is
  a valid result. `degraded: false` does not establish complete call resolution.
- `affected` reports unresolved input paths and traversal truncation. Its test
  recognition is heuristic; returned tests do not prove behavioral coverage.
- Coedit history can contain pre-rename or non-code paths. These remain in
  `coedit[]` even when no indexed symbol is available to navigate to them.
- Read source using `startLine` / `endLine`; cite locations as `filePath:declLine`
  (`startLine` includes leading doc comments / decorators and will not match the declaration).
- `context` and `risk` have been removed. Use `search` + `related` to explore,
  and `impact` / `affected` / `coedit` to inspect change evidence.

Errors are `{ error, tag }`, including ValidationError (400), NotFoundError
(404), AppError (500), and InternalError (500).

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.