import { type ChildProcess, type SpawnOptions } from "node:child_process"; import { type AuditState, type CodingEngine } from "./codingPolicy.js"; /** 2: checks may name a folder of the worktree (`server: npm run typecheck`). */ export declare const EXCOM_CODING_VERSION = 2; export declare const SWEEP_AFTER_MS: number; export interface StartPayload { sessionId: string; repo: string; baseBranch: string; branch: string; goal: string; runbookText?: string | null; /** Structured evidence of the error to fix (server-redacted, capped): numbered items E1..En. */ evidence?: string | null; engine: CodingEngine; model?: string | null; provider?: string | null; maxMinutes: number; maxTurns: number; checks?: string[]; allowedRepos: string[]; allowedRemotes: string[]; } export type StartAck = { ok: true; worktree: string; baseSha: string; remotes: Array<{ name: string; url: string; }>; } | { ok: false; error: string; }; export interface PushPayload { sessionId: string; target: "branch" | "base"; remote: string; baseBranch?: string; allowedRemotes: string[]; } export type PushAck = { ok: true; pushed: "branch" | "base"; ref: string; sha: string; merged?: boolean; } | { ok: false; error: string; }; export type SessionStatus = "running" | "done" | "failed" | "timed_out" | "canceled" | "discarded"; export interface CodingResult { summary: string; diffStat: { files: number; insertions: number; deletions: number; text: string; }; commits: Array<{ sha: string; subject: string; }>; checks: Array<{ command: string; ok: boolean; exitCode: number | null; tail: string; }>; commandsRun: number; violations: string[]; notes: string[]; engine: CodingEngine; engineModel: string | null; worktree: string; branch: string; baseSha: string; headSha: string; error?: string; } export interface SessionState { sessionId: string; repo: string; branch: string; baseBranch: string; baseSha: string; worktree: string; engine: CodingEngine; provider: string | null; model: string | null; status: SessionStatus; createdAt: number; finishedAt: number | null; mainHead: { sha: string; branch: string | null; }; result: CodingResult | null; doneAcked: boolean; doneSends: number; pushState: "none" | "branch" | "base"; progress: string[]; } export interface GitOut { code: number; stdout: string; stderr: string; } export interface CodingDeps { /** Where worktrees and session files live (default ~/.melaya-runner/worktrees). */ root: string; git: (args: string[], cwd: string, opts?: { env?: NodeJS.ProcessEnv; timeoutMs?: number; }) => Promise; spawn: (command: string, args: string[], opts: SpawnOptions) => ChildProcess; terminate: (child: ChildProcess) => Promise; now: () => number; /** socket.emit; `ack` is called when the server acknowledges. */ emit: (event: string, payload: unknown, ack?: (reply: unknown) => void) => void; /** The engines this computer has (codingEngines()). */ detected: () => Promise; /** The native loop's interpreter, env and host script (null: unavailable). */ python?: (provider: string | null, model: string | null) => Promise<{ python: string; env: Record; hostScript: string; } | null>; /** Absolute path of dist/codingGuard.js and the node binary that runs it. */ guardScript: string; nodePath: string; /** The options the installed `claude` accepts (null: unknown, all assumed). */ claudeFlags?: () => Promise | null>; /** Resolve a program on PATH (full path, or null). */ which?: (name: string) => string | null; log?: (msg: string) => void; progressIntervalMs?: number; checkTimeoutMs?: number; /** Process env the engine environment is derived from. */ env?: NodeJS.ProcessEnv; } export declare function defaultRoot(): string; export declare function runGit(args: string[], cwd: string, opts?: { env?: NodeJS.ProcessEnv; timeoutMs?: number; }): Promise; /** A program on PATH (with the Windows extensions), else null. */ export declare function findOnPath(name: string, envPath?: string): string | null; /** The coding engines of this computer (cached 10 minutes): the CLIs on PATH, * and "native" when git, the native host and a runner model are present. */ export declare function codingEngines(i: { hostScriptPresent: boolean; runnerModels: number; force?: boolean; }): Promise<{ engines: string[]; git: string | null; }>; /** The options `claude --help` lists (and "dontAsk" when that mode exists). */ export declare function detectClaudeFlags(): Promise | null>; export declare function scrubEnv(env: NodeJS.ProcessEnv, engine: CodingEngine): Record; /** git configuration through the environment (every git the engine runs): the * session's hooks (pre-push refuses) and no credential helper. */ export declare function gitEnvConfig(hooksDir: string): Record; /** The session's hooks: pre-push refuses; commit hooks run the repo's own. */ export declare function writeHooks(dir: string, originalHooksDir: string | null): void; export declare function validBranchName(b: string, prefixRequired?: boolean): boolean; export declare function normalizeRepoPath(p: string): string; /** A remote URL without its .git suffix or trailing slash, lower case host. */ export declare function normalizeRemoteUrl(u: string): string; export declare function remoteAllowed(name: string, url: string, allowed: readonly string[]): boolean; export interface CodingManager { init(): Promise; start(p: StartPayload): Promise; push(p: PushPayload): Promise; discard(sessionId: string): Promise<{ ok: boolean; error?: string; }>; cancel(sessionId: string): Promise<{ ok: boolean; error?: string; }>; info(sessionId: string): { ok: boolean; session?: PublicSession; error?: string; }; resendPending(): number; sweep(maxAgeMs?: number): Promise; /** Tests: wait until a session's engine run and finalisation ended. */ settled(sessionId: string): Promise; state(sessionId: string): SessionState | null; } export type PublicSession = Omit; export declare function createCodingManager(deps: CodingDeps): CodingManager; export declare function parseShortstat(s: string): { files: number; insertions: number; deletions: number; }; export declare function parseRemotes(s: string): Array<{ name: string; url: string; }>; /** The production dependencies (git, the process tree, PATH). */ export declare function productionDeps(i: Omit & { root?: string; }): Promise; export type { AuditState }; /** The engine prompt: rules, repository, goal, the evidence of the error to * fix (when given) and the runbook. Pure; exported for tests. */ export declare function codingPrompt(s: Pick, p: Pick): string;