MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / emitFileSection

Method emitFileSection

src/mcp/tools.ts:6074–6169  ·  view source on GitHub ↗
(opts: {
        header: string;
        /** Deduped source. Empty ⇒ the agent already holds all of it. */
        body: string;
        /** Spans `body` covers. */
        ranges: ExploreLineRange[];
        /** Spans replaced by the back-reference. */
        covered: ExploreLineRange[];
        /**
         * Chars charged on top of the body by the ANTI-ABANDONMENT RESTORE path
         * only (it re-splices a section after the loop and needs one number for
         * it). The loop itself charges the real cost — see `sectionCost`.
         */
        overhead: number;
        mode: 'whole' | 'clusters' | 'focused' | 'skeleton';
        clipped: boolean;
        /**
         * The symbols this section set out to deliver. Any not covered by what
         * is sent (`ranges`, after the fold) plus `covered` marks the file
         * trimmed for the completeness note.
         */
        wanted: ReadonlyArray<ExploreWantedSpan>;
        /** The undeduped render, kept for the no-new-source fallback. */
        fullBody: string;
        fullRanges: ExploreLineRange[];
      })

Source from the content-addressed store, hash-verified

6072 * the agent has NOT seen, which is the whole point.
6073 */
6074 const emitFileSection = (opts: {
6075 header: string;
6076 /** Deduped source. Empty ⇒ the agent already holds all of it. */
6077 body: string;
6078 /** Spans `body` covers. */
6079 ranges: ExploreLineRange[];
6080 /** Spans replaced by the back-reference. */
6081 covered: ExploreLineRange[];
6082 /**
6083 * Chars charged on top of the body by the ANTI-ABANDONMENT RESTORE path
6084 * only (it re-splices a section after the loop and needs one number for
6085 * it). The loop itself charges the real cost — see `sectionCost`.
6086 */
6087 overhead: number;
6088 mode: 'whole' | 'clusters' | 'focused' | 'skeleton';
6089 clipped: boolean;
6090 /**
6091 * The symbols this section set out to deliver. Any not covered by what
6092 * is sent (`ranges`, after the fold) plus `covered` marks the file
6093 * trimmed for the completeness note.
6094 */
6095 wanted: ReadonlyArray<ExploreWantedSpan>;
6096 /** The undeduped render, kept for the no-new-source fallback. */
6097 fullBody: string;
6098 fullRanges: ExploreLineRange[];
6099 }): void => {
6100 // A remainder too small to be worth a fence is folded into the pointer
6101 // (see MIN_DELTA_CHARS). Its ranges are then NOT recorded — the record
6102 // must only ever claim source that was actually sent.
6103 const folded = opts.covered.length > 0 && opts.body.length < EXPLORE_DEDUP.MIN_DELTA_CHARS;
6104 const body = folded ? '' : opts.body;
6105 const ranges = folded ? [] : opts.ranges;
6106 // Judged on what this call sends plus what the agent already holds —
6107 // AFTER the fold, whose remainder is in neither.
6108 const elided = elidedWantedSpans(opts.wanted, [...ranges, ...opts.covered]);
6109 if (elided.length > 0) trimmedFiles.set(filePath, elided);
6110 const at = lines.length;
6111 lines.push(opts.header, '');
6112 // Charge what the section ACTUALLY costs, not a flat 200 (CG-26). A
6113 // header carries the path plus up to `maxSymbolsInFileHeader` symbol
6114 // names and routinely runs 300–500 chars, so the flat charge made the
6115 // loop believe it had room it did not have: okhttp rendered 26,601
6116 // chars against a 24,400 ceiling and the final truncation threw a
6117 // fully-rendered section away. Everything downstream is expressed in
6118 // these units — `headroom`, `fundedHeadroom`, every fit test — so an
6119 // under-count is not a rounding error, it funds a promise out of bytes
6120 // that do not exist and starves whoever the loop reaches last.
6121 totalChars += opts.header.length + 2;
6122 if (opts.covered.length > 0) {
6123 const pointer = formatBackReference(
6124 filePath,
6125 opts.covered,
6126 symbolsInSpans(group.nodes, opts.covered),
6127 { partial: body.length > 0 },
6128 );
6129 lines.push(pointer, '');
6130 totalChars += pointer.length + 2;
6131 backReferencedFiles.push(filePath);

Callers

nothing calls this directly

Calls 7

formatBackReferenceFunction · 0.90
symbolsInSpansFunction · 0.90
elidedWantedSpansFunction · 0.85
pushMethod · 0.80
recordRenderMethod · 0.80
recordDedupMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected