import type { SandboxMode } from "./session-spawner.js"; export type BugfixPhase = "intake" | "analyze" | "fix" | "test" | "verify" | "review" | "commit" | "push" | "finish" | "done"; export type SplitSuggestion = "l1" | "l2"; export interface BugfixSplitInfo { files_changed: number; cross_submodules: boolean; submodule_count: number; has_tasks_jsonl: boolean; has_tasks_md: boolean; suggested: SplitSuggestion; } export interface RetryConfig { /** API 错误自动重试次数上限(默认 3) */ maxRetries?: number; /** 重试退避毫秒数(默认 5000) */ backoffMs?: number; /** 触发降级的错误类型关键字(默认 ["reasoning_content"]) */ downgradeOnType?: string[]; } export interface ProjectConfig { zentao_project_id?: number; zentao_base_url?: string; zentao_account?: string; /** API 重试/降级配置(全部可选,缺省有安全默认值) */ retry?: RetryConfig; } export declare function loadProjectConfig(root: string): Promise; export declare function saveProjectConfig(root: string, cfg: ProjectConfig): Promise; export declare const DEFAULT_RETRY_CONFIG: Required; export declare function resolveRetryConfig(cfg: ProjectConfig | null | undefined): Required; /** 从 .aiws/config.json 读取重试配置;缺省返回安全默认值。向后兼容:无 retry 字段不报错。 */ export declare function loadRetryConfig(root: string): Promise>; export type ApiErrorKind = "downgrade" | "retryable" | "business"; /** * 上游 AI/API 错误分类: * - downgrade: 消息含 `reasoning_content must be passed back`(400)→ 需降级 thinking-level 后重试 * - retryable: HTTP 4xx/5xx → 自动重试 * - business: 其余(认证失败等业务错误)→ failed */ export declare function classifyApiError(err: unknown): ApiErrorKind; /** 打印 API 错误重试/降级提示(pi 主 session 可据此降级 --thinking-level 或 --retry 恢复)。 */ export declare function printApiRetryHint(kind: ApiErrorKind, err: unknown, retry?: Required): void; /** * Sandbox options accepted by `aiws bugfix start` and forwarded into the * bugfix state so downstream spawners (fix-plan → change tasks execute, * batch per-bug pipelines) can honor them. All fields optional; unset means * the spawner default (sandbox=none, node:24-bookworm-slim, default network). */ export interface BugfixStartOptions { sandbox?: SandboxMode; sandboxImage?: string; sandboxNetwork?: "default" | "none"; } export declare function bugfixStartCommand(bugId: number, opts?: BugfixStartOptions): Promise; export declare function bugfixStatusCommand(changeId?: string): Promise; export declare function bugfixAdvanceCommand(changeId: string): Promise; /** * 统计 bugfix change 的 diff 改动并给出分层拆单建议(级1/级2)。 * * - 合并 diff:base...HEAD 已提交 + git diff HEAD 未提交 + git diff --cached staged(去重) * - 排除 test/spec/文档模式 * - 跨子模块:≥2 个不同子模块,或子模块内 + 仓库根部文件并存 */ export declare function analyzeBugfixSplit(root: string, changeId: string): Promise; /** * aiws bugfix fix-plan [--dry-run] * * 有 tasks/tasks.jsonl → 调 change tasks execute 逐任务派发; * 只有 tasks.md → 提示先 change tasks init;两者都无 → 提示级1/级2 判据。 */ export declare function bugfixFixPlanCommand(changeId: string, opts?: { dryRun?: boolean; parallel?: number; }): Promise; /** 子模块路径是否应归为 frontend 任务(web/frontend/ui 前缀)。 */ export declare function isFrontendSubmodulePath(submodulePath: string): boolean; /** 子模块路径是否应归为 backend 任务(backend/server/api 前缀)。 */ export declare function isBackendSubmodulePath(submodulePath: string): boolean; /** 将子模块路径 sanitize 成安全 task id 段。 */ export declare function sanitizeTaskSegment(submodulePath: string): string; /** * 为级2(跨 ≥2 子模块 或 ≥4 源文件)生成自动拆单计划。 * * 按 diff 源文件归属分组: * - web/frontend/ui 子模块 → `task-frontend`(scope 列该子模块下改动文件) * - backend/server/api 子模块 → `task-backend` * - 其余子模块 → `task-` * - 根/非子模块文件 → `task-root` * * @returns 任务分组(taskId → { title, files }),files 已排序去重 */ export declare function buildAutoSplitPlan(sourceFiles: string[], submodulePaths: string[]): Array<{ id: string; title: string; files: string[]; }>; /** 将自动拆单计划渲染为 tasks.md checkbox 文本。 */ export declare function renderAutoSplitTasksMd(plan: Array<{ id: string; title: string; files: string[]; }>): string; /** * aiws bugfix split-auto [--dry-run] [--parallel N] * * D2:级2 bugfix(跨 ≥2 子模块或 ≥4 源文件)自动拆单—— * 1. l1 → 打印无需拆单并 return; * 2. 已有 tasks/tasks.jsonl → 幂等短路并回指 fix-plan; * 3. l2 → 按 diff 子模块归属生成 tasks.md(task-frontend/task-backend/task-root)→ * 调用 change tasks init 生成任务栈 → 可选 --parallel 并行派发。 */ export declare function bugfixSplitAutoCommand(changeId: string, opts?: { dryRun?: boolean; parallel?: number; }): Promise; /** 读取 change 的 base_branch(缺省 main)。 */ export declare function splitBaseBranch(root: string, changeId: string): Promise; export type BatchBugStatus = "pending" | "vetting" | "vet_failed" | "building" | "build_failed" | "paroling" | "done" | "skipped" | "failed" | "needs_human"; export interface BatchBugItem { bug_id: number; title: string; severity: number; status: BatchBugStatus; change_id: string; started_at?: string; completed_at?: string; error?: string; retry_count?: number; evidence?: { build_log: string; test_log: string; }; } export interface BatchStats { total: number; done: number; skipped: number; failed: number; } export interface BatchState { batch_version: number; batch_id: string; project_id: string; status: "active" | "completed" | "paused"; current_bug_index: number; aiws_version?: string; bugs: BatchBugItem[]; processed_bug_ids: number[]; stats: BatchStats; created_at: string; updated_at: string; } /** * Map raw ZenTao API bug objects to `BatchBugItem[]`. * * Expected shape per item: `{ id: number, name?: string, title?: string, severity?: number }`. * Falls back: `name ?? title ?? ""` for title, `severity ?? 0` for severity. */ export declare function mapZenTaoBugsToBatchItems(raw: unknown[]): BatchBugItem[]; /** * Batch start command. When `opts.fetchBugs` is provided (testing), it is used * instead of creating a real ZenTao client. The fetch function receives the * project ID (as number) and must return an array of BatchBugItem or null * (treated as empty). A thrown error aborts the batch. */ export declare function bugfixBatchStartCommand(projectId?: string, opts?: { fetchBugs?: (projectIdNum: number) => Promise; }): Promise; export declare function bugfixBatchStatusCommand(batchId?: string): Promise; export declare function bugfixBatchAdvanceCommand(batchId: string): Promise; export declare function bugfixBatchCompleteCommand(batchId: string): Promise; export declare function recalcBatchStats(bugs: BatchBugItem[]): BatchStats; export declare function bugfixFinishCommand(changeId: string): Promise; export { bugfixFinishAutoCommand, type BugfixFinishAutoOptions, type BugfixFinishGateTier } from "./bugfix-finish-auto.js";