mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-11-15 03:08:20 +08:00
fix(context): call paths label synthesized hops like explore, not as events (#2428)
Two surfaces label a synthesized (dynamic-dispatch) `calls` hop:
codegraph_explore's Flow and dynamic-dispatch links plus the
codegraph_node trail (`dynamic: interface → impl @file:line`), and
ContextBuilder's "## Call paths", which `codegraph context` prints
(`→[…]`). Each kept its own list. The call paths' list stopped at
callback, react-render, jsx-render, vue-handler, http-client, queue-job
and socket messages, so every other synthesizer fell through to
`event ${m.event ?? ''}`: an interface-impl hop read
`→[event @src/pdf-exporter.ts:5]`, and so did a C++ override, a redux
thunk, a gin middleware chain or a closure collection.
The wording now lives once, in src/graph/synthesized-hop.ts
(`describeSynthesizedHop`: a summary, the detail only the call paths
print, and the wiring site), as AGENTS.md asks of a derivation two
surfaces render. ToolHandler renders `dynamic: <summary> @site`, the
call paths `<summary><detail> @site`. Explore and the node trail print
exactly what they printed before; the call paths keep their wording for
the kinds they already labelled, including the queue name, a socket's
direction and the HTTP clause, and now name the rest the way explore
does. A bus event reads `bus event` there too, and the section's
footnote no longer says hops are marked `[callback/event …]`.
The helper also holds the wording #2414 gives a Go method a struct gets
by embedding (`metadata.promotedInto`), so that arm moves here too. The
unused long `label` form of ToolHandler.synthEdgeNote (last read by the
removed codegraph_trace) is dropped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b635dd467f
commit
cd97bb37d2
+15
-130
@@ -53,6 +53,7 @@ import { clamp, validatePathWithinRoot, validateProjectPath, isConfigLeafNode, C
|
||||
import { guardLabel, guardsForFileSync, siteKey, supportsBranchGuards, warmBranchGuardGrammars } from '../graph/branch-guards';
|
||||
import { findDynamicBoundaries, type BoundarySite } from '../graph/dynamic-boundary-report';
|
||||
import { countImplementers } from '../graph/type-hierarchy';
|
||||
import { describeSynthesizedHop } from '../graph/synthesized-hop';
|
||||
import { isCopybookInclude, MAX_COPYBOOK_INCLUDES, type NamedCopybook } from '../graph/cobol-copybooks';
|
||||
import {
|
||||
findAllSymbols,
|
||||
@@ -3304,12 +3305,6 @@ export class ToolHandler {
|
||||
return this.answerResult(cg, this.truncateOutput(sections.join('\n') + filterNote), answerPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe a synthesized (dynamic-dispatch) edge for human output: how the
|
||||
* callback was wired up — the bridge static parsing can't see. Returns null
|
||||
* for ordinary static edges. Used by trace + the node trail so a synthesized
|
||||
* hop reads as "registered via onUpdate at App.tsx:3148", not a bare arrow.
|
||||
*/
|
||||
/**
|
||||
* The branch conditions a flow hop's call site runs under, read from the
|
||||
* caller's source now (`graph/branch-guards.ts`); '' when unconditional,
|
||||
@@ -3333,125 +3328,17 @@ export class ToolHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private synthEdgeNote(edge: Edge | null): { label: string; compact: string; registeredAt?: string } | null {
|
||||
if (!edge || edge.provenance !== 'heuristic') return null;
|
||||
const m = edge.metadata as Record<string, unknown> | undefined;
|
||||
const registeredAt = typeof m?.registeredAt === 'string' ? m.registeredAt : undefined;
|
||||
const at = registeredAt ? ` @${registeredAt}` : '';
|
||||
if (m?.synthesizedBy === 'callback') {
|
||||
const via = m.via ? `\`${String(m.via)}\`` : 'a registrar';
|
||||
const field = m.field ? ` on .${String(m.field)}` : '';
|
||||
return {
|
||||
label: `callback — registered via ${via}${field} (dynamic dispatch)`,
|
||||
compact: `dynamic: callback via ${via}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'http-client') {
|
||||
const req = `${String(m.method ?? 'GET')} ${String(m.href ?? '')}`.trim();
|
||||
return {
|
||||
label: `HTTP request \`${req}\` — the client's call onto its own route (cross-tier)`,
|
||||
compact: `dynamic: HTTP ${req}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'queue-job') {
|
||||
const job = m.event ? `\`${String(m.event)}\`` : 'a job';
|
||||
const queue = m.queue ? ` on queue \`${String(m.queue)}\`` : '';
|
||||
return {
|
||||
label: `queue job ${job}${queue} — producer → consumer (cross-tier)`,
|
||||
compact: `dynamic: queue job ${job}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'event-bus') {
|
||||
const ev = m.event ? `\`${String(m.event)}\`` : 'an event';
|
||||
const what = m.channel === 'socket' ? 'socket message' : 'bus event';
|
||||
const dir = m.tier === 'client→server' ? ', client → server' : m.tier === 'server→client' ? ', server → client' : '';
|
||||
return {
|
||||
label: `${what} ${ev} — emit → handler${dir} (dynamic dispatch)`,
|
||||
compact: `dynamic: ${what} ${ev}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'event-emitter') {
|
||||
const ev = m.event ? `\`${String(m.event)}\`` : 'an event';
|
||||
return {
|
||||
label: `event ${ev} — emit → handler (dynamic dispatch)`,
|
||||
compact: `dynamic: event ${ev}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'react-render') {
|
||||
return {
|
||||
label: `React re-render — \`setState\` re-runs render() (dynamic dispatch)`,
|
||||
compact: `dynamic: React re-render via setState${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'jsx-render') {
|
||||
const child = m.via ? `<${String(m.via)}>` : 'a child component';
|
||||
return {
|
||||
label: `renders ${child} (JSX child — dynamic dispatch)`,
|
||||
compact: `dynamic: renders ${child}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'vue-handler') {
|
||||
const ev = m.event ? `@${String(m.event)}` : 'a template event';
|
||||
return {
|
||||
label: `Vue template handler — bound to ${ev} (dynamic dispatch)`,
|
||||
compact: `dynamic: Vue ${ev} handler`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'interface-impl' && typeof m.promotedInto === 'string') {
|
||||
// Go: the implementing struct gets this method from a type it embeds.
|
||||
return {
|
||||
label: `interface dispatch — runs the method \`${m.promotedInto}\` gets by embedding (dynamic dispatch)`,
|
||||
compact: `dynamic: interface → method promoted into ${m.promotedInto}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'interface-impl') {
|
||||
return {
|
||||
label: `interface/abstract dispatch — runs the implementation override (dynamic dispatch)`,
|
||||
compact: `dynamic: interface → impl${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'closure-collection') {
|
||||
const field = m.field ? `\`${String(m.field)}\`` : 'a collection';
|
||||
return {
|
||||
label: `closure collection — runs handlers appended to ${field} (dynamic dispatch)`,
|
||||
compact: `dynamic: runs ${field} handlers${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'fn-pointer-dispatch') {
|
||||
const via = m.via ? `\`${String(m.via)}\`` : 'a function pointer';
|
||||
return {
|
||||
label: `function-pointer dispatch via ${via} (dynamic dispatch)`,
|
||||
compact: `dynamic: fn-pointer ${m.via ? String(m.via) : ''}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
if (m?.synthesizedBy === 'goframe-route') {
|
||||
const route = m.route ? `\`${String(m.route)}\`` : 'a route';
|
||||
return {
|
||||
label: `GoFrame route ${route} — reflective Bind → controller method (dynamic dispatch)`,
|
||||
compact: `dynamic: GoFrame route ${m.route ? String(m.route) : ''}${at}`,
|
||||
registeredAt,
|
||||
};
|
||||
}
|
||||
// Generic fallback for any other synthesizer (redux-thunk, gin-middleware-chain,
|
||||
// flutter-build, …): a synthesized hop must never read as a bare static `calls`.
|
||||
// It's a dynamic-dispatch bridge — label it as one and keep its wiring site.
|
||||
if (typeof m?.synthesizedBy === 'string') {
|
||||
const kind = m.synthesizedBy.replace(/-/g, ' ');
|
||||
return { label: `${kind} (dynamic dispatch)`, compact: `dynamic: ${kind}${at}`, registeredAt };
|
||||
}
|
||||
return null;
|
||||
/**
|
||||
* The tag a synthesized (dynamic-dispatch) hop carries in explore's Flow and
|
||||
* dynamic-dispatch links and in the codegraph_node trail, so it reads as
|
||||
* "dynamic: callback via `onUpdate` @App.tsx:3148", not a bare arrow. Null
|
||||
* for an ordinary static edge. The wording is `graph/synthesized-hop.ts`'s,
|
||||
* shared with ContextBuilder's call paths.
|
||||
*/
|
||||
private synthEdgeNote(edge: Edge | null): string | null {
|
||||
const hop = describeSynthesizedHop(edge);
|
||||
if (!hop) return null;
|
||||
return `dynamic: ${hop.summary}${hop.registeredAt ? ` @${hop.registeredAt}` : ''}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3506,8 +3393,7 @@ export class ToolHandler {
|
||||
const key = `${src.name}>${tgt.name}`;
|
||||
if (synthSeen.has(key)) continue;
|
||||
synthSeen.add(key);
|
||||
const note = this.synthEdgeNote(edge);
|
||||
synthLines.push(`- ${src.name} → ${tgt.name} [${note ? note.compact : edge.kind}]`);
|
||||
synthLines.push(`- ${src.name} → ${tgt.name} [${this.synthEdgeNote(edge) ?? edge.kind}]`);
|
||||
}
|
||||
}
|
||||
return synthLines;
|
||||
@@ -3640,9 +3526,8 @@ export class ToolHandler {
|
||||
for (let i = 0; i < best!.length; i++) {
|
||||
const step = best![i]!;
|
||||
if (step.edge) {
|
||||
const sy = this.synthEdgeNote(step.edge);
|
||||
const when = i > 0 ? this.whenLabel(cg, best![i - 1]!.node, step.edge) : '';
|
||||
out.push(` ↓ ${sy ? sy.compact : step.edge.kind}${when ? ` (when ${when})` : ''}`);
|
||||
out.push(` ↓ ${this.synthEdgeNote(step.edge) ?? step.edge.kind}${when ? ` (when ${when})` : ''}`);
|
||||
}
|
||||
out.push(`${i + 1}. ${step.node.name} (${step.node.filePath}:${step.node.startLine})`);
|
||||
}
|
||||
@@ -8042,7 +7927,7 @@ export class ToolHandler {
|
||||
const fmt = (e: { node: Node; edge: Edge }) => {
|
||||
const base = `${e.node.name} (${e.node.filePath}:${e.node.startLine})`;
|
||||
const synth = this.synthEdgeNote(e.edge);
|
||||
return synth ? `${base} [${synth.compact}]` : base;
|
||||
return synth ? `${base} [${synth}]` : base;
|
||||
};
|
||||
const collect = (edges: Array<{ node: Node; edge: Edge }>): Array<{ node: Node; edge: Edge }> => {
|
||||
const seen = new Set<string>([node.id]);
|
||||
|
||||
Reference in New Issue
Block a user