/** * Shared fetch helpers for MCP-managed gitops files. * * fetchCapCsvForEnv — pulls the rate cap CSV (engine safety floor): * `pipelines/run/receive/rate/caps.csv` * Used by commitment_report verify, services, and overflow_contents to * supply per-container byte caps for context. The engine reads no action * from cap rows (that lives in the sibling actions.csv); legacy rows with * a folded action token parse tolerantly — see cap-csv-parser.ts. * * fetchActionIntentForEnv — pulls the canonical per-pattern action plan: * `data/action-intent.json` * Used by services, overflow_contents, and estimate-savings to resolve * pattern→action attribution. Takes precedence over any legacy action * suffix that may still be in the cap CSV rows. * * Both helpers are best-effort: return undefined on any failure (no `gh` * available, no gitops repo configured, file not found, decode error). * Callers MUST treat undefined as "no data available — fall back to the * unattributed path" rather than throwing. * * Neither helper caches — the freshness of the action attribution matters * more than round-trip latency, and gh requests are sub-second on any * reasonable gitops repo. */ /** * Structured status for the cap-CSV / action-intent fetch. * * `kind` values: * not_configured — no gitops repo set for this env; fetch not attempted. * loaded — at least one of cap-CSV rows or action-intent entries * is populated. Action split is trustworthy. * configured_not_loaded — gitops repo is configured but the fetch produced no * usable data (empty CSV + empty action-intent). * lookup_failed — gitops repo is configured, fetch was attempted, but * every attempt threw or returned empty content (gh not * installed, repo 404, file not found, decode/parse error). * * `reason` is a plain-English one-liner for human/agent consumption. * `source` is where the data would come from (gitops repo path, or absent). * * Back-compat: callers that still read a flat string can branch on `.kind`. * The legacy `applied` / `unavailable` / `not_attempted` strings map as: * applied → kind: 'loaded' * unavailable → kind: 'lookup_failed' or 'configured_not_loaded' * not_attempted → kind: 'not_configured' */ export interface CapCsvStatus { kind: 'not_configured' | 'configured_not_loaded' | 'loaded' | 'lookup_failed'; reason: string; source: string | null; } /** * Build a CapCsvStatus from the fetch results. Extracted so both * overflow_contents and services build the same structured value * instead of copy-pasting the ternary. * * @param repo — env.gitops?.repo (null/undefined if not configured) * @param fetchAttempted — true when at least one gh call was made * @param fetchSucceeded — true when at least one call returned non-empty content * @param hasActionSource — true when actionIntentLookup.size > 0 OR parsedCsv.rows.length > 0 */ export declare function buildCapCsvStatus(repo: string | null | undefined, fetchAttempted: boolean, fetchSucceeded: boolean, hasActionSource: boolean): CapCsvStatus; import type { EnvConfig } from './environments.js'; import { type ActionIntentParseResult } from './action-intent-parser.js'; export type GitopsRepoSource = 'env' | 'env_var' | 'snapshot' | 'none'; export interface ResolvedGitopsRepo { /** Resolved owner/name, or undefined when no source produced a repo. */ repo: string | undefined; /** Optional lookup path override (only ever sourced from env.gitops). */ lookupPath: string | undefined; /** Which source the repo came from. `none` when unresolved. */ source: GitopsRepoSource; } /** * Resolve a gitops repo for an env using the same chain as * configure_engine / pattern_mitigate. Pure: does not mutate the env. */ export declare function resolveGitopsRepoForEnv(env: EnvConfig, opts?: { snapshotMaxAgeSeconds?: number; }): ResolvedGitopsRepo; /** * Return a shallow clone of `env` with `gitops.repo` populated from the * auto-discovery chain when the field was originally absent. Used by * fetchers that key off `env.gitops?.repo` so they pick up the env-var * and snapshot fallbacks without a signature change. */ export declare function envWithResolvedGitops(env: EnvConfig): EnvConfig; /** Fetch the rate cap CSV string from the gitops repo. */ export declare function fetchCapCsvForEnv(env: EnvConfig): Promise; /** * Fetch the engine's actions.csv (sibling of caps.csv) from the gitops * repo. Best-effort, undefined on any failure — configure_engine uses it * to MERGE the new per-service action rows over the repo's existing ones * so services outside the current run keep their actions. */ export declare function fetchActionsCsvForEnv(env: EnvConfig): Promise; /** * Fetch and parse the action-intent.json from the gitops repo. * * Returns undefined on any failure. On success, returns the full * ActionIntentParseResult so callers can use `by_pattern` directly * (the canonical pattern→action Map). * * Default path: `data/action-intent.json` */ export declare function fetchActionIntentForEnv(env: EnvConfig, path?: string): Promise; /** Fetch the cap-CSV from a kubectl_configmap delivery target. */ export declare function fetchCapCsvFromConfigMap(name: string, namespace: string): Promise; /** Fetch + parse action-intent.json from a kubectl_configmap delivery target. */ export declare function fetchActionIntentFromConfigMap(name: string, namespace: string): Promise; /** Result of a tagged cap-CSV fetch attempt. */ export interface TaggedFetchResult { csvContent: string | undefined; actionIntent: ActionIntentParseResult | undefined; /** True when a network call was made to the gitops repo (repo was configured). */ attempted: boolean; /** True when at least one of csvContent / actionIntent came back non-empty. */ succeeded: boolean; } /** * Fetch both cap-CSV and action-intent in parallel and return a tagged * result that lets the caller distinguish "not configured", "fetch failed", * "empty", and "loaded" without re-running the ternary logic. * * Replaces the copy-pasted parallel Promise.all + status ternary in * overflow_contents and services. */ export declare function fetchCapCsvTagged(env: EnvConfig): Promise;