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

Method emitFileSection

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

6357 * the agent has NOT seen, which is the whole point.
6358 */
6359 const emitFileSection = (opts: {
6360 header: string;
6361 /** Deduped source. Empty ⇒ the agent already holds all of it. */
6362 body: string;
6363 /** Spans `body` covers. */
6364 ranges: ExploreLineRange[];
6365 /** Spans replaced by the back-reference. */
6366 covered: ExploreLineRange[];
6367 /**
6368 * Chars charged on top of the body by the ANTI-ABANDONMENT RESTORE path
6369 * only (it re-splices a section after the loop and needs one number for
6370 * it). The loop itself charges the real cost — see `sectionCost`.
6371 */
6372 overhead: number;
6373 mode: 'whole' | 'clusters' | 'focused' | 'skeleton';
6374 clipped: boolean;
6375 /**
6376 * The symbols this section set out to deliver. Any not covered by what
6377 * is sent (`ranges`, after the fold) plus `covered` marks the file
6378 * trimmed for the completeness note.
6379 */
6380 wanted: ReadonlyArray<ExploreWantedSpan>;
6381 /** The undeduped render, kept for the no-new-source fallback. */
6382 fullBody: string;
6383 fullRanges: ExploreLineRange[];
6384 }): void => {
6385 // A remainder too small to be worth a fence is folded into the pointer
6386 // (see MIN_DELTA_CHARS). Its ranges are then NOT recorded — the record
6387 // must only ever claim source that was actually sent.
6388 const folded = opts.covered.length > 0 && opts.body.length < EXPLORE_DEDUP.MIN_DELTA_CHARS;
6389 const body = folded ? '' : opts.body;
6390 const ranges = folded ? [] : opts.ranges;
6391 // Judged on what this call sends plus what the agent already holds —
6392 // AFTER the fold, whose remainder is in neither.
6393 const elided = elidedWantedSpans(opts.wanted, [...ranges, ...opts.covered]);
6394 if (elided.length > 0) trimmedFiles.set(filePath, elided);
6395 const at = lines.length;
6396 lines.push(opts.header, '');
6397 // Charge what the section ACTUALLY costs, not a flat 200 (CG-26). A
6398 // header carries the path plus up to `maxSymbolsInFileHeader` symbol
6399 // names and routinely runs 300–500 chars, so the flat charge made the
6400 // loop believe it had room it did not have: okhttp rendered 26,601
6401 // chars against a 24,400 ceiling and the final truncation threw a
6402 // fully-rendered section away. Everything downstream is expressed in
6403 // these units — `headroom`, `fundedHeadroom`, every fit test — so an
6404 // under-count is not a rounding error, it funds a promise out of bytes
6405 // that do not exist and starves whoever the loop reaches last.
6406 totalChars += opts.header.length + 2;
6407 if (opts.covered.length > 0) {
6408 const pointer = formatBackReference(
6409 filePath,
6410 opts.covered,
6411 symbolsInSpans(group.nodes, opts.covered),
6412 { partial: body.length > 0 },
6413 );
6414 lines.push(pointer, '');
6415 totalChars += pointer.length + 2;
6416 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