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

Method emitFileSection

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

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