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
5 changes: 5 additions & 0 deletions changelog.d/callers-two-copy-bind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Changed — `--callers` binds the source copy of a two-copy method and names the copy

`--callers=Owner.method` used to refuse when the name had two bodied definitions and one of them was a copy, such as vscode's `extensions/copilot/src/util/vs/…` tree, whose files open with "DO NOT modify, this file was COPIED". Now, when every definition left after the test-path and bodyless ones are dropped is a copy except ONE, the source one answers. A copy is a file under a CI or tool dot directory, a vendoring directory or the demo/generated tier, or a file whose head declares it generated or copied. The root carries `narrowed=` as before, plus `copy_p=` (each copy as `p:line`) and `copy_next=` (the callers call on the first copy). MCP `find_referencing_symbols` and the `callers` batch verb answer the same copy (`copy_p` / `copy_next` / `copy_note`). Two source definitions, or none, still refuse. `--for` is unchanged. New arms (d6)-(d9) and (e4) in `test/gvassemblycheck.sh`.

Versions: the session legend dictionary moves to `dictv=0d983acad983c50f entries=1322` (the `copy_p=` and `copy_next=` entries); docs/COMMANDS.md and the 2026-11-23 showcase capture record the new pair.
2 changes: 1 addition & 1 deletion docs/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4790,7 +4790,7 @@ _The session legend dictionary the MCP server serves as ripwire://legend-dict/fu

```
$ ./build/ripwire . --legend-dict
ripwire legend dictionary ripwire.dict/v1 dictv=6c4aa81a81163d18 entries=1320
ripwire legend dictionary ripwire.dict/v1 dictv=0d983acad983c50f entries=1322
<about legend="ref" dict= dictv=>: this LAST child is only the legend pointer; the root keeps every attribute it carries inline, unchanged (schema=, each count, cut and floor); rows follow it; legend="ref": a definition is sent once per session (this dictionary's core, or the first answer that needs … [line truncated: 80 more bytes on this line]
schema=ripwire.KEY/v1: the line ripwire.KEY/v1 below reads the answer's rows
window: shown= total= capped= has_more= next_offset= offset= limit= page a list (capped=1 cut; next_offset= pastes as offset=)
Expand Down
4 changes: 2 additions & 2 deletions docs/captures/COMMANDS_showcase_2026-11-23.md
Original file line number Diff line number Diff line change
Expand Up @@ -6325,7 +6325,7 @@ ripwire: --run-timeout=SECONDS modifies --run-trace — pass it too (e.g. ripwir
*The session legend dictionary the MCP server serves as ripwire://legend-dict/full — one definition per line, headed by its dictv= version; no corpus needed. =roster lists the completeness attributes it defines.*

`````
ripwire legend dictionary ripwire.dict/v1 dictv=6c4aa81a81163d18 entries=1320
ripwire legend dictionary ripwire.dict/v1 dictv=0d983acad983c50f entries=1322
<about legend="ref" dict= dictv=>: this LAST child is only the legend pointer; the root keeps every attribute it carries inline, unchanged (schema=, each count, cut and floor); rows follow it; legend="ref": a definition is sent once per session (this dictionary's core, or the first answer that needs … [line truncated: 80 more bytes on this line]
schema=ripwire.KEY/v1: the line ripwire.KEY/v1 below reads the answer's rows
window: shown= total= capped= has_more= next_offset= offset= limit= page a list (capped=1 cut; next_offset= pastes as offset=)
Expand Down Expand Up @@ -6355,7 +6355,7 @@ ripwire.pack-task/v1 <ctx>: one-call task bundle for task= under budget_tokens=:
ripwire.from-trace/v1 <ctx>: trace frames mapped to indexed symbols, innermost first; the innermost in-corpus body included
ripwire.exemplar/v1 <ctx>: the best-in-class instance of kind= for the task, chosen by role: <exemplar n= p= in= ccx= tested=>, <bodies><b> to imitate
ripwire.pack-task/v1 <ctx-partitions>: N minimally overlapping agent bundles carved along call-graph communities plus one shared core; each <bundle> wraps a <ctx>; bundle role=core|partition i= symbols= modules= bytes= tokens=: one agent's ctx, symbols= ids assigned, bytes= its size; tokens= = est_t … [line truncated: 503 more bytes on this line]
… [1297 more display lines; full output is 168197 bytes on 1321 raw line(s)]
… [1299 more display lines; full output is 168478 bytes on 1323 raw line(s)]
`````

## `./build/ripwire . --lint --lint-select=cache-`
Expand Down
5 changes: 4 additions & 1 deletion src/callhierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ struct CallHierarchyRows
// lane declined-sites (declinedsites.h): the records behind declinedCalls, in served order (callers file-first, callees
// file and line) — the <dc> rows, never in `rows` or any count above; uncut, declinedSites.size() == declinedCalls.
std::vector<std::uint32_t> declinedSites;
// GV-PATH-BIND (CLI --callers, src/verbs_navigate.h callHierarchyRowsNarrowed): the selector as typed when it bound nothing and the
// GV-PATH-BIND (CLI --callers, src/forgraphverb.h callHierarchyRowsNarrowed): the selector as typed when it bound nothing and the
// M1 rule narrowed it to one source definition, whose spelling these rows answer; empty otherwise (the root's narrowed=)
std::vector<std::string> narrowed;
// CALLERS-TWO-COPY-BIND (forgraphverb.h sourceCopyPick): beside `narrowed`, the copies of the bound definition the answer left out
// (the root's copy_p= / copy_next=); empty otherwise
std::vector<NodeId> copies;
// BODILESS-SEED (contractseed.h): callers only — the selector's contract seeds and the implementor bodies `matches` gained
// for them (the root's impls=; absent when contractSeeds is 0)
std::size_t contractSeeds = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/compactlegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,9 @@ inline constexpr CompactCompletenessTerm kCompactCompletenessTerms[] =
{ "anchor", "<c anchor=missing>: that markdown link named a heading this file does not have, so the edge is the file", true, "c", MapHeaderRead::No, "missing" },
// GV-PATH-BIND (src/forgraphverb.h kNarrowedVerbLegend), present-only: the callers selector the M1 rule narrowed
{ "narrowed", "narrowed=: the spelling as typed fits several definitions (refused as written); the test/fixture-path and bodyless ones dropped, the ONE source definition left answers by its own spelling", false, "callers", MapHeaderRead::No, {}, "callers" },
// CALLERS-TWO-COPY-BIND (src/forgraphverb.h kSourceCopyLegend), present-only: beside narrowed=, the copies the bind left out
{ "copy_p", "copy_p=: beside narrowed=, the other definitions the spelling fits are COPIES (CI/tool dot dir, vendoring dir, demo/generated tier, or a generated/copied banner), so the one source definition answers; p:line each, not counted", false, "callers", MapHeaderRead::No, {}, "callers" },
{ "copy_next", "copy_next=: the callers call on the first copy_p= copy", false, "callers", MapHeaderRead::No, {}, "callers" },
// CALLSITE-AT (2026-10-09): a callers row's call sites (editcheck.h rowCallSites); keyed to the callers schema, so the
// map's own <s> rows never read it. The columnar form names the same list as its sites_at column.
{ "sites_at", "<s sites_at=>: its leaf-name calls not proven elsewhere, as [file:]line (p=: def line, default file); not proof each binds", true, "s", MapHeaderRead::No, {}, "callers" },
Expand Down
22 changes: 22 additions & 0 deletions src/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,28 @@ inline bool isDemoOrGeneratedPath( std::string_view p ) noexcept
return isYarnPnpFileName( fileName ) || ( hasDirSegment( p, "migrations/" ) && isNumberedMigrationFileName( fileName ) );
}

// A CI, tool or vendored copy: under a dot directory (.github, .circleci, .yarn), a vendoring directory, or the demo/generated tier. Such
// a file can define the subject's symbol, even first in path order (a bundled .github action defined Angular's UrlSerializer), and it
// is never what the subject means. The --for subject anchor (subjectanchor.h sourceClassDef) and the --callers two-copy bind
// (forgraphverb.h definitionIsCopy) read this one rule; it moved here from subjectanchor.h so both can.
inline bool isToolOrVendoredPath( std::string_view p ) noexcept
{
if( isDemoOrGeneratedPath( p ) )
{
return true;
}
for( std::size_t start = 0, slash = p.find( '/' ); slash != std::string_view::npos; start = slash + 1, slash = p.find( '/', start ) )
{
const std::string_view dir = p.substr( start, slash - start );
const bool vendoring = dir == "vendor" || dir == "third_party" || dir == "node_modules" || dir == "bower_components";
if( vendoring || ( dir.size() > 1 && dir.front() == '.' && dir != ".." ) )
{
return true;
}
}
return false;
}

inline constexpr float kRankTierTestMul = 0.35f;
inline constexpr float kRankTierDemoMul = 0.35f;

Expand Down
160 changes: 146 additions & 14 deletions src/forgraphverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "pathgaps.h" // resolvePathEndpoint — the --path resolver
#include "pathpairs.h" // pathDefInTests — the --defs class="test" rule (M1)
#include "defattrib.h" // endpointDefinitionCount — from= binds one definition (M3)
#include "docparse.h" // hasGeneratedMarker / readWholeFile — a generated or copied file's banner (CALLERS-TWO-COPY-BIND)
#include "backhops.h" // DeclinedCrossRule — a builtin-spelled declined call is no crossing (M3)
#include "infra/emit.h" // emitTo — the met_bridge disclosure's stderr line
#include "serialize.h" // escapeXml
Expand Down Expand Up @@ -82,6 +83,22 @@ inline std::optional<std::string> soleDefinitionSpelling( const IngestResult& in
return std::nullopt;
}

// The M1 survivors of `spec`: its fitting definitions less the test/fixture-path, bodyless and doc-unit ones, in the resolver's order;
// nullopt when the spelling was not refused over two or more fitting definitions all placed (an unplaced one is never listed).
inline std::optional<std::vector<NodeId>> sourceOnlyKeptDefs( const IngestResult& ing, std::string_view spec )
{
std::size_t fitted = 0;
std::vector<NodeId> fits;
(void)resolveAllByWrittenSpelling( ing, spec, {}, &fitted, &fits );
if( fitted < 2 || fits.size() != fitted )
{
return std::nullopt;
}
std::erase_if( fits, [ & ]( NodeId id )
{ return id >= ing.symbols.size() || !isDefinitionNotDeclaration( ing.symbols[ id ] ) || pathDefInTests( ing, id ) || isDocUnit( ing.symbols[ id ] ); } );
return fits;
}

// GV-ASSEMBLY M1 ESRC (endpoint source-prefer; ORCH reports/s0-xh-1110.md, rule frozen there). A task spelling the resolver REFUSES
// because several definitions fit it (`ApplicationRef.tick` on angular: the source method plus two bodyless mocks under a tests/
// tree) leaves the graph question unasked, though only one of them is code the task can mean. On that refusal only, the fitting
Expand All @@ -92,26 +109,65 @@ inline std::optional<std::string> soleDefinitionSpelling( const IngestResult& in
// as before. The block discloses the narrowing (narrowed= on the open tag), so verb= is the one call that ran.
inline std::optional<std::string> sourceOnlyPickSpelling( const IngestResult& ing, std::string_view spec )
{
std::size_t fitted = 0;
std::vector<NodeId> fits;
(void)resolveAllByWrittenSpelling( ing, spec, {}, &fitted, &fits );
if( fitted < 2 || fits.size() != fitted )
const std::optional<std::vector<NodeId>> kept = sourceOnlyKeptDefs( ing, spec );
if( !kept || kept->size() != 1 )
{
return std::nullopt;
}
std::vector<NodeId> kept;
for( const NodeId id : fits )
return soleDefinitionSpelling( ing, kept->front() );
}

// CALLERS-TWO-COPY-BIND: is definition `id` a COPY of code that lives elsewhere: a file under a CI/tool dot directory, a vendoring
// directory or the demo/generated tier (filter.h isToolOrVendoredPath, the --for subject anchor's rule), or a file whose head
// declares it generated or copied (docparse.h hasGeneratedMarker: vscode's extensions/copilot/src/util/vs tree opens with
// "DO NOT modify, this file was COPIED"). An unreadable file is not called a copy.
inline bool definitionIsCopy( const IngestResult& ing, NodeId id )
{
const std::uint32_t f = ing.symbols[ id ].fileId;
if( isToolOrVendoredPath( rootRelPath( ing, f ) ) )
{
return true;
}
const std::optional<std::string> text = docparse::detail::readWholeFile( diskPath( ing, f ) );
return text && docparse::hasGeneratedMarker( *text );
}

// CALLERS-TWO-COPY-BIND (owner 11-17: "bind source, disclose"). A callers spelling M1 still refuses because two or more source-looking
// definitions survive it (sourceOnlyKeptDefs), where all but ONE are copies (definitionIsCopy): the answer is that one's own
// spelling, and `copies` names the copies the answer leaves out (resolver order), so the reader can ask for one. Two non-copies
// left, or none, → nullopt: refused as before.
struct SourceCopyPick
{
std::string spelling;
std::vector<NodeId> copies;
};
inline std::optional<SourceCopyPick> sourceCopyPick( const IngestResult& ing, std::string_view spec )
{
std::optional<std::vector<NodeId>> kept = sourceOnlyKeptDefs( ing, spec );
if( !kept || kept->size() < 2 )
{
return std::nullopt; // M1's own case (one left) or nothing left
}
SourceCopyPick pick;
NodeId source = kNoNode;
for( const NodeId id : *kept )
{
if( id < ing.symbols.size() && isDefinitionNotDeclaration( ing.symbols[ id ] ) && !pathDefInTests( ing, id ) && !isDocUnit( ing.symbols[ id ] ) )
if( definitionIsCopy( ing, id ) )
{
kept.push_back( id );
pick.copies.push_back( id );
}
else if( std::exchange( source, id ) != kNoNode )
{
return std::nullopt; // two source definitions: no pick
}
}
if( kept.size() != 1 )
std::optional<std::string> spelling = source == kNoNode ? std::nullopt : soleDefinitionSpelling( ing, source );
if( !spelling )
{
return std::nullopt;
}
return soleDefinitionSpelling( ing, kept.front() );
pick.spelling = std::move( *spelling );
return pick;
}

// Does the graph verb of `form` bind `spec` as written: the --path resolver (a glob included), the --callers one, the --connect one.
Expand Down Expand Up @@ -141,16 +197,36 @@ inline std::optional<std::string> narrowRefusedSpelling( const IngestResult& ing
return std::nullopt;
}

// The spelling a refused CALLERS selector binds instead: the M1 pick (narrowRefusedSpelling), else (CALLERS-TWO-COPY-BIND) the one
// source definition beside its copies (sourceCopyPick; `copies` receives them), each kept only when --callers binds it; nullopt =
// refused as before.
inline std::optional<std::string> callersRefusedPick( const IngestResult& ing, std::string_view sym, std::vector<NodeId>& copies )
{
if( std::optional<std::string> pick = narrowRefusedSpelling( ing, sym, GraphSubjectForm::Callers ) )
{
return pick;
}
std::optional<SourceCopyPick> two = sourceCopyPick( ing, sym );
if( !two || !graphFormResolves( ing, GraphSubjectForm::Callers, two->spelling ) )
{
return std::nullopt;
}
copies = std::move( two->copies );
return std::move( two->spelling );
}

// GV-PATH-BIND + CALLERS-TWO-COPY: the ONE binder of the one-hop rows every surface serves — the CLI --callers/--callees and MCP
// find_referencing_symbols / find_symbol / the callers verb. The rows of `sym`; for a CALLERS selector that binds nothing as typed and that
// the M1 rule narrows to one source definition (narrowRefusedSpelling), the rows of that definition's own spelling: `bound` holds it, `sym`
// is moved onto it and the rows' `narrowed` names the selector as typed. Otherwise the rows as typed (empty matches: the caller refuses as
// before). MCP used to call callHierarchyRows directly and refused the spelling the CLI answered.
// callersRefusedPick binds to one source definition, the rows of that definition's own spelling: `bound` holds it, `sym` is moved
// onto it, the rows' `narrowed` names the selector as typed and `copies` the copies left out (CALLERS-TWO-COPY-BIND). Otherwise the
// rows as typed (empty matches: the caller refuses as before). MCP used to call callHierarchyRows directly and refused the spelling
// the CLI answered.
inline CallHierarchyRows callHierarchyRowsNarrowed( const IngestResult& ing, const Graph& g, std::string_view& sym, bool wantCallers, std::string& bound,
const ValueRefIndex* valueIndex = nullptr ) // the MCP server passes its cached one
{
CallHierarchyRows rows = callHierarchyRows( ing, g, sym, wantCallers, valueIndex );
std::optional<std::string> pick = wantCallers && rows.matches.empty() ? narrowRefusedSpelling( ing, sym, GraphSubjectForm::Callers ) : std::nullopt;
std::vector<NodeId> copies;
std::optional<std::string> pick = wantCallers && rows.matches.empty() ? callersRefusedPick( ing, sym, copies ) : std::nullopt;
if( !pick )
{
return rows;
Expand All @@ -161,11 +237,67 @@ inline CallHierarchyRows callHierarchyRowsNarrowed( const IngestResult& ing, con
return rows;
}
narrowedRows.narrowed.emplace_back( sym );
narrowedRows.copies = std::move( copies );
bound = std::move( *pick );
sym = bound;
return narrowedRows;
}

// CALLERS-TWO-COPY-BIND: the disclosure of the copies a two-copy bind left out, every dialect from one place. copy_p= lists each copy
// as p:line (space-separated, resolver order); copy_next= is the callers call on the first, by the spelling that binds it alone
// (soleDefinitionSpelling; absent when none does). Empty with no copies (0 bytes).
struct SourceCopyDisclosure
{
std::string p; // "file:line file:line"
std::string next; // "--callers=file:name", or ""
};
inline SourceCopyDisclosure sourceCopyDisclosure( const IngestResult& ing, std::span<const NodeId> copies )
{
SourceCopyDisclosure out;
for( const NodeId id : copies )
{
const Symbol& s = ing.symbols[ id ];
out.p += ( out.p.empty() ? "" : " " ) + std::string( rootRelPath( ing, s.fileId ) ) + ":" + std::to_string( s.line );
}
if( !copies.empty() )
{
const std::optional<std::string> sel = soleDefinitionSpelling( ing, copies.front() );
out.next = sel ? nextFlag( "--callers=", *sel ) : std::string();
}
return out;
}
inline std::string sourceCopyAttrXml( const IngestResult& ing, std::span<const NodeId> copies )
{
if( copies.empty() )
{
return {};
}
const SourceCopyDisclosure d = sourceCopyDisclosure( ing, copies );
std::vector<char> esc;
std::string out = " copy_p=\"" + std::string( escapeXml( d.p, esc ) ) + "\"";
return out + nextAttrXml( d.next, "copy_next" ); // nextFlag's shell quotes stay raw (the one next= escaper); empty next => nothing
}
inline std::string sourceCopyKeysJson( const IngestResult& ing, std::span<const NodeId> copies )
{
if( copies.empty() )
{
return {};
}
const SourceCopyDisclosure d = sourceCopyDisclosure( ing, copies );
const std::string out = ",\"copy_p\":\"" + jsonStr( d.p ) + "\"";
return d.next.empty() ? out : out + ",\"copy_next\":\"" + jsonStr( d.next ) + "\"";
}

// The legend clause for copy_p= / copy_next= (present only with them; no period inside, so it reads as one sentence).
inline constexpr std::string_view kSourceCopyLegend =
"copy_p=: beside narrowed=, the other definitions the spelling fits are COPIES (under a CI/tool dot directory, a vendoring "
"directory or the demo/generated tier, or their file opens with a generated or copied banner), so the one source definition "
"answers and the copies (p:line each) are not counted; copy_next= is the callers call on the first copy. ";
inline std::string_view sourceCopyLegend( bool on ) noexcept
{
return on ? kSourceCopyLegend : std::string_view();
}

// ` narrowed="a b"`: the spellings as typed that M1 narrowed, space-separated; "" when none. The --for block's open tag and the direct
// verbs' roots spell it alike.
inline std::string narrowedAttrXml( std::span<const std::string> narrowed )
Expand Down
Loading
Loading