Skip to content

feat(doctor): #7 一键诊断修复 fixAction 框架 (warning 携带可调用 auto-fix) - #131

Merged
dahai80 merged 1 commit into
mainfrom
feat/item7-doctor-fix-action
Aug 22, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/item7-doctor-fix-action

Conversation

@dahai80

@dahai80 dahai80 commented Aug 22, 2026

Copy link
Copy Markdown
Owner

背景

enhance-0819.md #7: 一键诊断+修复。/doctor 的 warnings 当前仅含 fix: string (人类可读指令, 不可调用)。无 fixAction 字段 → 无确定性的可执行 auto-fix。

缺口 (surgical)

doctorDiagnostic.ts:69 类型 warnings: Array<{ issue: string; fix: string }> — fix 是指令字符串, 永不被调用。无 fixAction 字段。

方案

  • 扩展类型加 fixAction?: () => Promise<unknown> (返回结果透传给消费者)
  • 在确定性可自动修复的 warning 上 attach fixAction。首个落地 = MLX OOM (high/imminent): fixAction: requestMlxGC (POST /api/v1/gc, 同 adapter 已有, item 15 已验证安全)
  • env-conflict / MLX-start / model-load 非进程内确定性修复 (需 shell 重启 / 跨 CLI), 保留人类可读 fix 字符串, 不 attach fixAction (Rule 2 最小)
  • Doctor.tsx UI 交互 (按 f 触发) 涉及 React-compiler-optimized state ($[N] memo slots), 脆弱 → 独立 defer。本 PR 落框架 + 数据层可调用, UI 消费后续

改动

  • src/utils/doctorDiagnostic.ts — 类型 + 3 local array decl + 3 函数 return type 加 fixAction?: () => Promise<unknown>; 2 OOM case (imminent/high) attach fixAction: requestMlxGC
  • src/__tests__/utils/doctorMlxHealth.test.ts — 既有 2 OOM 测加 expect(typeof warnings[0].fixAction).toBe("function"); 新测 fixAction()→POST /api/v1/gc→{success:true,freed:5000}

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 408 pass
  • bun run build:dev — pass
  • bunx biome lint src/utils/doctorDiagnostic.ts — 0 error (pre-existing node:protocol infos)

关联

closes #130
enhance-0819.md #7 (§684)

doctorDiagnostic warnings 仅含 fix: string (人类可读指令, 不可调用),
无确定性可执行 auto-fix。扩展类型加 fixAction?: () => Promise<unknown>,
首个落地 = MLX OOM high/imminent attach fixAction: requestMlxGC
(POST /api/v1/gc, 同 adapter item 15 已验证安全)。env-conflict/MLX-start
/model-load 非进程内确定性 (需 shell 重启/跨 CLI), 保留人类可读 fix,
不 attach fixAction (Rule 2 最小)。Doctor.tsx UI 交互 (按 f 触发) 涉及
React-compiler-optimized state (\$[N] memo slots) 脆弱, 独立 defer。
本 PR 落框架 + 数据层可调用, UI 消费后续。

测试: doctorMlxHealth.test.ts 既有 2 OOM 测加 fixAction 函数断言,
新测 fixAction()→POST /api/v1/gc→{success:true,freed:5000}。
typecheck 0 errors, bun test src/__tests__/ 408 pass, build:dev pass,
biome lint src/utils/doctorDiagnostic.ts 0 error。

closes #130

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit b35d9f5 into main Aug 22, 2026
1 check passed
@dahai80
dahai80 deleted the feat/item7-doctor-fix-action branch August 22, 2026 14:15
dahai80 added a commit that referenced this pull request Aug 22, 2026
Patch release bundling 17 commits since v0.4.23:
- item 15(a) MLX OOM auto-recovery gc+retry (#129)
- #7 one-click diagnostic fixAction framework (#131)
- 维度5 background-default spawn FUSION_SUBAGENT_DEFAULT_BACKGROUND (#127)
- #4 proactive MLX OOM detection via /v1/health (#125)
- item 17 fullscreen pre-compact history + :598 synthetic decouple (#123)
- item 25B workflow stagger fan-out (#122)
- item 21 auto-mode local rule classifier test coverage (#120)
- item 23 archive plugin source + SHA-256 lock (#118)
- item 24 marketplace command source (#116)
- item 6 transcript disk trimming + crash-safe checkpoint (#114)
- item 5 normalizeMessages secondary normalize cache (#112)
- item 19 screen-reader plaintext render (#110)
- item 16 compact retry countdown + stall hint (#108)
- item 25A workflow execution runtime docs (#106)
- item 25A minimal workflow execution runtime (#105)
- item 12 subagent auto-background threshold (#103)
- item 20 vimInsertModeRemaps dual-key INSERT sequence (#101)

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 26, 2026
…fix) (#140)

PR #131 landed the fixAction framework in the data layer (warnings carry
an optional callable fixAction, e.g. requestMlxGC for MLX OOM), but the
Doctor.tsx UI only rendered the fix text — the callback was never
invokable. The prior session deferred the UI wiring because Doctor.tsx is
vendored React-Compiler output (_c/$[N] memo slots) and hand-editing the
slots is fragile.

Resolve by extracting the warnings render into a new hand-written child
component (DoctorWarnings.tsx) that owns its own useInput. The parent's
memo slot $[36] still depends only on the warnings array reference, so
the compiler output is untouched except for swapping the render call.
This neutralizes both defer reasons: (1) no hand-editing of memo slots,
(2) no shared Confirmation context in Doctor (requestMlxGC is an in-process
deterministic op needing no confirmation).

Behavior:
- Warnings render identically (Warning: <issue> / Fix: <fix>).
- When >=1 warning has a fixAction, show "Press f to run auto-fix." hint.
- Press f -> runAutoFix iterates actionable warnings, calls each fixAction,
  shows done/error feedback with per-warning results. Guards against
  double-trigger while running. No fixAction -> no hint, no useInput effect.
- Matches repo convention: raw useInput with eslint-disable for letter-key
  prompts (same class as y/n in DesktopHandoff).

Tests: 9 new (runAutoFix pure logic — all-success/singular wording,
all-fail/partial/non-Error throw/empty/no-fixAction-skip/running-first/
mock-once). Repo has no ink render tests; pure logic is unit-tested and
the Doctor.tsx wiring is typecheck-verified.

Gates: typecheck 0, 469 tests pass, biome clean on new files, build:dev
passes, default behavior byte-identical when no fixAction present.

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(doctor): #7 一键诊断修复 fixAction 框架 (warning 携带可调用 auto-fix)

1 participant