import { type Api, type Model } from "@earendil-works/pi-ai/compat"; import type { ExtensionContext } from "@earendil-works/pi-coding-agent"; import type { PiAutocommitConfig } from "./config.js"; /** * Commit prompt module — the deep module owning prompt assembly, the LLM-call * adapter, response cleanup, and deterministic scope injection for commit * messages. * * Two interface methods: * - {@link completeSingleMessage} — single-commit generation, falls back to * the heuristic when the LLM is unavailable. * - {@link completeCommitGroups} — commit-group proposition; throws on * inference failure. * * Behind the seam: language switching rules, the COMMIT_TYPES reference, the * scope-mapping subject-format rule, the LLM adapter (statically imported by * default, injectable for tests), response cleanup, group parsing, scope * injection, and the heuristic fallback. */ /** * Adapter for the LLM completion call. * * Production: statically imported `completeSimple` from `@earendil-works/pi-ai/compat`. * Tests: an in-memory fake implementing the same shape. Accepting this as an * optional injected dependency keeps the seam real (two adapters) while * letting production callers omit it for zero ceremony. */ export type CompleteFn = (model: Model, context: { systemPrompt: string; messages: { role: "user"; content: string; timestamp: number; }[]; }) => Promise<{ content: Array<{ type: "string"; text?: string; }>; }>; /** Raw git materials for the single-commit path (the high-frequency caller). */ export interface SingleCommitInput { /** `git diff --cached` output. */ diff: string; /** `git diff --cached --name-status` output. Used for scope injection and heuristic. */ nameStatus: string; /** `git diff --cached --stat` output. Used by the heuristic fallback. */ stat: string; } /** Raw git materials for the commit-group proposition path. */ export interface GroupsInput { /** `git diff --cached` output. */ diff: string; /** Assistant reasoning from the agent loop (build via {@link extractAssistantContext}). */ reasoning: string; } /** One logical commit produced by the reorganiser. */ export interface CommitGroup { /** Full Conventional Commits message (subject + optional body/footer). */ message: string; /** Files that belong exclusively to this commit. */ files: string[]; } /** * Extract assistant reasoning text from agent-loop messages. * * Uses a structural type so the module does not import pi-coding-agent types; * `AgentEndEvent["messages"]` satisfies this shape and can be passed through * without conversion. Assistant messages are joined with a `---` separator so * the reorganiser can see the agent's intended reasoning across turns. */ export declare function extractAssistantContext(messages: ReadonlyArray): string; /** * Propose a split of the staged change set into logical commit groups. * * Invariants: * - Returns `CommitGroup[]` (maybe empty). Never null/undefined. * - Group count is decided by the LLM (no heuristic for groups). * - When a scope mapping is configured (ADR-0003), each group's message has * the scope injected deterministically from that group's files. * - `complete` omitted → lazily imports `completeSimple` for production. * * Error modes: throws on LLM response unparseable/empty or model * unavailable. The caller (reorganiser) catches and falls back to a single * commit via {@link completeSingleMessage} — so the silent double-LLM * roundtrip disappears as a consequence of depth. */ export declare function completeCommitGroups(ctx: ExtensionContext, config: PiAutocommitConfig, input: GroupsInput, complete?: CompleteFn): Promise; /** * Generate one Conventional Commits message for a staged change set. * * Invariants: * - Always returns a non-empty string — never throws on LLM failure. * - LLM unavailable or empty response → heuristic fallback. * - When a scope mapping is configured (ADR-0003), the scope is injected * deterministically from the changed paths after the LLM responds. * - `complete` omitted → lazily imports `completeSimple` for production. * * Error modes: no throw. LLM errors, empty responses, import failures all * fall through to the heuristic. */ export declare function completeSingleMessage(ctx: ExtensionContext, config: PiAutocommitConfig, input: SingleCommitInput, complete?: CompleteFn): Promise; //# sourceMappingURL=commit-prompt.d.ts.map