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

Method renderCluster

src/mcp/tools.ts:7402–7458  ·  view source on GitHub ↗
(
        c: ExploreCluster,
        cap: number,
        /**
         * Hard bound on the rendered result (CG-30). `cap` is what selection asks
         * for; this is how far a single oversize member is allowed to overshoot it
         * before being windowed. Always >= `cap`, so a cluster that already fits is
         * never touched.
         */
        ceiling: number = Infinity,
        /**
         * What this cluster's INCIDENTAL members may render into, when a cluster
         * ranked below it holds a member the query asked for — see the selection
         * loop.
         */
        incidentalCap?: number,
      )

Source from the content-addressed store, hash-verified

7400 * is not being sent — spending the file's budget on nothing.
7401 */
7402 const renderCluster = (
7403 c: ExploreCluster,
7404 cap: number,
7405 /**
7406 * Hard bound on the rendered result (CG-30). `cap` is what selection asks
7407 * for; this is how far a single oversize member is allowed to overshoot it
7408 * before being windowed. Always >= `cap`, so a cluster that already fits is
7409 * never touched.
7410 */
7411 ceiling: number = Infinity,
7412 /**
7413 * What this cluster's INCIDENTAL members may render into, when a cluster
7414 * ranked below it holds a member the query asked for — see the selection
7415 * loop.
7416 */
7417 incidentalCap?: number,
7418 ): { parts: SectionPart[]; covered: ExploreLineRange[]; shrunk: boolean } => {
7419 const base = dedupeSpans(buildSection(c));
7420 // In a cluster holding a member the query asked for, incidental members
7421 // are never kept past `ceiling` either. The member shrink estimates on raw
7422 // source, which runs well under the rendered size, so it kept helpers the
7423 // render then had no room for, and the window back to the ceiling cut in
7424 // source order — through the tail of a named body (gin's
7425 // `handleHTTPRequest` lost 10 of 71 lines to the helpers above it), or,
7426 // when its minimum windows overran a later cluster's room, costing that
7427 // cluster its place. Every re-render into an exact room is the same case.
7428 const guard = Number.isFinite(ceiling) && c.members.some(isProtectedMember)
7429 ? Math.min(incidentalCap ?? Infinity, ceiling)
7430 : incidentalCap;
7431 // A windowed spine method elides source even when nothing else is cut, so
7432 // it counts as shrunk: reported unclipped, the one-file-head-plus-a-call-
7433 // site render hid in the diagnostic as a complete section.
7434 const windowed = windowsSpineIn(c.start, c.end);
7435 const bound = (
7436 r: { parts: SectionPart[]; covered: ExploreLineRange[]; shrunk: boolean },
7437 ) => {
7438 if (!Number.isFinite(ceiling) || sectionText(r.parts).length <= ceiling) return r;
7439 // Windows are subsets of spans dedupeSpans already cleared, so the record
7440 // still only ever claims source that was actually sent.
7441 // A body the window cuts says so where it is cut, with the query for
7442 // the rest (#2486): the agent otherwise learns of the cut only from a
7443 // footer whose advice — ask for the symbol by name — returns this same
7444 // window.
7445 const focus = focusLinesOf(c);
7446 const parts = noteCutBodies(windowToCeiling(r.parts, ceiling, focus), r.parts, c, focus);
7447 return { parts, covered: r.covered, shrunk: true };
7448 };
7449 if (sectionText(base.parts).length <= Math.min(cap, guard ?? Infinity)) {
7450 return { parts: base.parts, covered: base.covered, shrunk: windowed };
7451 }
7452 const shrunk = shrinkCluster(c, cap, guard);
7453 if (shrunk === null) {
7454 return bound({ parts: base.parts, covered: base.covered, shrunk: windowed });
7455 }
7456 const dd = dedupeSpans(shrunk);
7457 return bound({ parts: dd.parts, covered: dd.covered, shrunk: true });
7458 };
7459

Callers

nothing calls this directly

Calls 1

boundFunction · 0.85

Tested by

no test coverage detected