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

Method renderCluster

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

7322 * is not being sent — spending the file's budget on nothing.
7323 */
7324 const renderCluster = (
7325 c: ExploreCluster,
7326 cap: number,
7327 /**
7328 * Hard bound on the rendered result (CG-30). `cap` is what selection asks
7329 * for; this is how far a single oversize member is allowed to overshoot it
7330 * before being windowed. Always >= `cap`, so a cluster that already fits is
7331 * never touched.
7332 */
7333 ceiling: number = Infinity,
7334 /**
7335 * What this cluster's INCIDENTAL members may render into, when a cluster
7336 * ranked below it holds a member the query asked for — see the selection
7337 * loop.
7338 */
7339 incidentalCap?: number,
7340 ): { parts: SectionPart[]; covered: ExploreLineRange[]; shrunk: boolean } => {
7341 const base = dedupeSpans(buildSection(c));
7342 // In a cluster holding a member the query asked for, incidental members
7343 // are never kept past `ceiling` either. The member shrink estimates on raw
7344 // source, which runs well under the rendered size, so it kept helpers the
7345 // render then had no room for, and the window back to the ceiling cut in
7346 // source order — through the tail of a named body (gin's
7347 // `handleHTTPRequest` lost 10 of 71 lines to the helpers above it), or,
7348 // when its minimum windows overran a later cluster's room, costing that
7349 // cluster its place. Every re-render into an exact room is the same case.
7350 const guard = Number.isFinite(ceiling) && c.members.some(isProtectedMember)
7351 ? Math.min(incidentalCap ?? Infinity, ceiling)
7352 : incidentalCap;
7353 // A windowed spine method elides source even when nothing else is cut, so
7354 // it counts as shrunk: reported unclipped, the one-file-head-plus-a-call-
7355 // site render hid in the diagnostic as a complete section.
7356 const windowed = windowsSpineIn(c.start, c.end);
7357 const bound = (
7358 r: { parts: SectionPart[]; covered: ExploreLineRange[]; shrunk: boolean },
7359 ) => {
7360 if (!Number.isFinite(ceiling) || sectionText(r.parts).length <= ceiling) return r;
7361 // Windows are subsets of spans dedupeSpans already cleared, so the record
7362 // still only ever claims source that was actually sent.
7363 // A body the window cuts says so where it is cut, with the query for
7364 // the rest (#2486): the agent otherwise learns of the cut only from a
7365 // footer whose advice — ask for the symbol by name — returns this same
7366 // window.
7367 const focus = focusLinesOf(c);
7368 const parts = noteCutBodies(windowToCeiling(r.parts, ceiling, focus), r.parts, c, focus);
7369 return { parts, covered: r.covered, shrunk: true };
7370 };
7371 if (sectionText(base.parts).length <= Math.min(cap, guard ?? Infinity)) {
7372 return { parts: base.parts, covered: base.covered, shrunk: windowed };
7373 }
7374 const shrunk = shrinkCluster(c, cap, guard);
7375 if (shrunk === null) {
7376 return bound({ parts: base.parts, covered: base.covered, shrunk: windowed });
7377 }
7378 const dd = dedupeSpans(shrunk);
7379 return bound({ parts: dd.parts, covered: dd.covered, shrunk: true });
7380 };
7381

Callers

nothing calls this directly

Calls 1

boundFunction · 0.85

Tested by

no test coverage detected