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

Method emitFileSection

src/mcp/tools.ts:6152–6247  ·  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

6150 * the agent has NOT seen, which is the whole point.
6151 */
6152 const emitFileSection = (opts: {
6153 header: string;
6154 /** Deduped source. Empty ⇒ the agent already holds all of it. */
6155 body: string;
6156 /** Spans `body` covers. */
6157 ranges: ExploreLineRange[];
6158 /** Spans replaced by the back-reference. */
6159 covered: ExploreLineRange[];
6160 /**
6161 * Chars charged on top of the body by the ANTI-ABANDONMENT RESTORE path
6162 * only (it re-splices a section after the loop and needs one number for
6163 * it). The loop itself charges the real cost — see `sectionCost`.
6164 */
6165 overhead: number;
6166 mode: 'whole' | 'clusters' | 'focused' | 'skeleton';
6167 clipped: boolean;
6168 /**
6169 * The symbols this section set out to deliver. Any not covered by what
6170 * is sent (`ranges`, after the fold) plus `covered` marks the file
6171 * trimmed for the completeness note.
6172 */
6173 wanted: ReadonlyArray<ExploreWantedSpan>;
6174 /** The undeduped render, kept for the no-new-source fallback. */
6175 fullBody: string;
6176 fullRanges: ExploreLineRange[];
6177 }): void => {
6178 // A remainder too small to be worth a fence is folded into the pointer
6179 // (see MIN_DELTA_CHARS). Its ranges are then NOT recorded — the record
6180 // must only ever claim source that was actually sent.
6181 const folded = opts.covered.length > 0 && opts.body.length < EXPLORE_DEDUP.MIN_DELTA_CHARS;
6182 const body = folded ? '' : opts.body;
6183 const ranges = folded ? [] : opts.ranges;
6184 // Judged on what this call sends plus what the agent already holds —
6185 // AFTER the fold, whose remainder is in neither.
6186 const elided = elidedWantedSpans(opts.wanted, [...ranges, ...opts.covered]);
6187 if (elided.length > 0) trimmedFiles.set(filePath, elided);
6188 const at = lines.length;
6189 lines.push(opts.header, '');
6190 // Charge what the section ACTUALLY costs, not a flat 200 (CG-26). A
6191 // header carries the path plus up to `maxSymbolsInFileHeader` symbol
6192 // names and routinely runs 300–500 chars, so the flat charge made the
6193 // loop believe it had room it did not have: okhttp rendered 26,601
6194 // chars against a 24,400 ceiling and the final truncation threw a
6195 // fully-rendered section away. Everything downstream is expressed in
6196 // these units — `headroom`, `fundedHeadroom`, every fit test — so an
6197 // under-count is not a rounding error, it funds a promise out of bytes
6198 // that do not exist and starves whoever the loop reaches last.
6199 totalChars += opts.header.length + 2;
6200 if (opts.covered.length > 0) {
6201 const pointer = formatBackReference(
6202 filePath,
6203 opts.covered,
6204 symbolsInSpans(group.nodes, opts.covered),
6205 { partial: body.length > 0 },
6206 );
6207 lines.push(pointer, '');
6208 totalChars += pointer.length + 2;
6209 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