/** * MCP handler: working_set_context (change: add-working-set-context-briefing). * * Second of three in SPEC-STORE-INTEGRATION.md. Given a configured spec-store * binding (add-spec-store-binding) and an active change, this assembles ONE * deterministic, token-budgeted structural briefing spanning the change's target * repositories — `orient`, generalized from a single repo to the change's targets. * * It composes existing pieces only and adds NO new relevance model and NO LLM * (north star `c6d1ad07`): * - `handleSpecStoreStatus` resolves + health-checks the binding (the single * source of truth for which targets are briefable); * - `handleOrient` runs task-scoped orientation against each indexed target, * keyed on the change's extracted intent; * - anchored-intent freshness is free: orient's `pendingDecisions` are the in-scope * authoritative decisions each carrying a freshness verdict, with orphaned anchors * already excluded — so the briefing flags drifted intent and withholds orphaned * by construction; * - the merged briefing is ranked by orient's score and bounded with the shared * `applyTokenBudget` / `omissionNote` helpers (add-trust-calibrated-context-economy). * * Read-only and conclusion-shaped: it returns a briefing an agent reads in full * (per-target attributed items + named intent), never a raw graph. It never throws * for a binding/change/index problem — every problem degrades to a finding. */ /** Stable finding codes — part of the agent-facing `--json` contract. */ export type WorkingSetFindingCode = 'no-binding' | 'binding-unsound' | 'change-unspecified' | 'change-not-found' | 'no-briefable-targets' | 'target-not-briefable' | 'orient-unavailable'; export type WorkingSetFindingSeverity = 'info' | 'warn' | 'error'; export interface WorkingSetFinding { code: WorkingSetFindingCode; severity: WorkingSetFindingSeverity; /** The store/target/change name the finding concerns. */ subject: string; /** What is wrong (or noted), in one line. */ message: string; /** A pasteable remediation. */ remediation: string; } /** One briefing item: a relevant symbol, attributed to its target repository. */ export interface WorkingSetItem { /** The target repository this symbol lives in (per-target attribution). */ target: string; name: string; filePath: string; score: number; /** Exact expansion handle — get_function_body(target-dir, filePath, name). */ expand: string; signature?: string; /** Internal callers of this symbol within its target (depth-1). */ callers: string[]; /** Spec domains governing this symbol's file in its target. */ specDomains: string[]; } /** Fresh, in-scope anchored intent for a target (from orient's governingDecisions). */ export interface AnchoredIntent { id: string; title: string; /** The decision's status (e.g. 'verified', 'approved'). An 'approved' entry may be * surfaced for sync-awareness rather than strict scope — see briefTargetFromOrient. */ status: string; /** 'current' = a fresh (or, without a graph view, not-yet-verifiable) anchor; * 'drifted' = the anchor has moved and should be re-checked. Orphaned anchors are * never surfaced (withheld upstream by orient). */ verdict: 'current' | 'drifted'; } export interface WorkingSetTargetBrief { target: string; /** True when orientation ran against this target's index. */ briefed: boolean; /** Why the target was skipped, when `briefed` is false. */ reason?: string; /** Top insertion-point candidates in this target for the change's scope. */ insertionPoints: Array<{ name: string; filePath: string; strategy: string; }>; /** Spec domains covering the in-scope code in this target. */ specDomains: string[]; /** In-scope anchored decisions/constraints with a freshness verdict. */ anchoredIntent: AnchoredIntent[]; } export interface WorkingSetContextReport { bound: boolean; store?: { name: string; path: string; }; change?: { id: string; /** The intent text (≤ MAX_QUERY_LENGTH) used to orient each target. */ intent: string; /** Spec-delta domains the change declares it touches, if any. */ declaredScope?: string[]; }; /** Per-target briefing status + insertion points + governing intent. */ targets: WorkingSetTargetBrief[]; /** Merged, budgeted, relevance-ranked, per-target-attributed briefing items. */ items: WorkingSetItem[]; /** Present when the budget dropped items — states what was omitted. */ omissionNote?: string; findings: WorkingSetFinding[]; /** True when the binding is sound and at least one target was briefed. */ ready: boolean; /** Conclusion-shaped headline. */ summary: string; } interface OrientFnView { name: string; filePath: string; score: number; expand: string; signature?: string; } export interface OrientView { error?: string; relevantFunctions?: OrientFnView[]; callPaths?: Array<{ function: string; filePath: string; callers?: Array<{ name: string; }>; }>; specDomains?: Array<{ domain: string; }>; insertionPoints?: Array<{ name: string; filePath: string; strategy: string; }>; pendingDecisions?: Array<{ id: string; title: string; status?: string; freshness?: string; verify?: boolean; }>; } /** * Project ONE target's orient result into briefing items (per-target attributed) * plus its target brief (insertion points, spec domains, anchored intent). Pure — * the testable core of the per-target transformation, no I/O. * * Anchored intent comes from orient's `pendingDecisions` — the task-relevant * authoritative decisions, each carrying a freshness verdict: a `drifted`/`verify` * decision is flagged `verdict: 'drifted'`, everything else is `current`. Orphaned * anchors never reach this set (orient routes them to `staleDecisions`), so the * spec's "orphaned intent SHALL be withheld" holds by construction. * * This set is in-scope by file/domain match, plus any `approved`-status decisions * orient always surfaces so the agent syncs them before committing — those carry * `status: 'approved'`, distinguishing a sync nudge from a strictly in-scope synced * decision. We do NOT intersect with orient's `governingDecisions`: that field is a * graph-projection join built at analyze time and is empty/stale for decisions * recorded since the last analyze, so intersecting would drop genuinely in-scope * intent (verified by dogfood — governingDecisions was empty while pendingDecisions * correctly carried the in-scope decisions). */ export declare function briefTargetFromOrient(targetName: string, orient: OrientView): { items: WorkingSetItem[]; brief: WorkingSetTargetBrief; }; /** * Rank merged items by structural relevance and bound them to a token budget. * Pure + deterministic: sort is total-ordered on (score desc, target, name, * filePath) so the truncation boundary is reproducible even for two same-named * symbols in different files of one target (no reliance on Array.sort stability). * Returns the kept items and how many were dropped. */ export declare function rankAndBudget(items: WorkingSetItem[], budget: number): { kept: WorkingSetItem[]; omitted: number; }; /** * Extract a concise orientation task (≤ MAX_QUERY_LENGTH) from a change proposal: * the title (first `# ` heading) plus the first paragraph of the `## Why` section * when present, else the proposal's opening prose. Deterministic; no LLM. */ export declare function extractIntent(proposalText: string, changeId: string): string; /** * Assemble the working-set context briefing for an active change across a bound * spec store's targets. Read-only; composes federation + orient only. Never throws * for a binding/change/index problem — every problem is a finding. */ export declare function handleWorkingSetContext(directory: string, changeId?: string, tokenBudget?: number, limit?: number): Promise; export {}; //# sourceMappingURL=working-set.d.ts.map