Skip to content

Commit eb0e20d

Browse files
edyedy
authored andcommitted
fix(tui): per-file polish round 9 — kv/data context
KV read rejected with ENOENT on first launch (no kv.json yet), logging a misleading "Failed to read KV state" error; check existence first and return an empty map so genuine read/parse failures still surface. The data context's event-driven catalog/reference/integration refreshes were voided with no rejection handler, producing unhandled rejections on a transient failure; attach .catch(console.error) to match the allSettled+console.error initial-load path.
1 parent b341fe8 commit eb0e20d

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

MERGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ fork 与上游改了同一处(常见于 TUI 视觉/UX、core 加固逻辑)
204204
| 逐文件打磨轮6:`feature-plugins/system/diff-viewer-ui.tsx``routes/session/{dialog-timeline,permission,dialog-fork-from-timeline,subagent-footer,question}.tsx`+`routes/home*.tsx`+`feature-plugins/{system/*,home/*}` 已审计) || 保留 bug 修复:`Panel` `borderProps.borderColor` 由 setup 期快照改 getter(`theme.border` 随对象展开保持响应式,原主题切换后 diff 查看器面板边框色冻结,`Separator` 已用 `() =>` 正确);fork `.data!.id` 无守卫(与 `dialog-message.tsx` fork 同款上游模式)择要跳过;`diff-viewer-file-tree-utils.moveFileTreeSelectionToFile` 仅测试引用但恐留待键位,暂不删(上游若已做可取上游版本) |
205205
| 逐文件打磨轮7:`component/dialog-model.tsx``dialog-{agent,move-session,theme-list,variant,session-delete-failed,session-list,skill,stash,workspace-file-changes,workspace-list}.tsx`+`command-palette.tsx` 已审计) || 保留 bug 修复:收藏/最近模型选项由可选的 `model.id` 改用可靠的映射键 `item.modelID``id?: string` 缺省时 `model.id.includes("-nano")` 抛错、选中项 modelID 变 undefined;并与 providerOptions 分支用键一致);`dialog-theme-list` `theme.all()` setup 期快照(需订阅 `subscribeThemes` 才能修,`all()` 非响应式且启动后基本不变)择要跳过(上游若已做可取上游版本) |
206206
| 逐文件打磨轮8:`prompt/{part.ts,frecency.tsx}` + `test/prompt/part.test.ts``prompt/{display,history,stash,traits}` + `component/prompt/{history,frecency,stash}` 再导出壳已审计) || 保留 bug 修复:`expandPastedTextPlaceholders``String.replace(needle, part.text)` 改函数替换 `() => part.text`(粘贴含 `$&`/`$'`/`$$`/`$n` 的文本经 open-editor/copy 路径被当替换模式解释而损坏,补回归测试);`frecency` 剪枝 `setStore("data", obj)``reconcile(obj)`(Solid store 合并语义使被剪路径永不删除,会话内 map 无限增长、每次 update 全量重写 jsonl)(上游若已做可取上游版本) |
207+
| 逐文件打磨轮9:`context/{kv,data}.tsx``context/{permission,prompt,clipboard,editor,path-format,thinking,directory,location}` 已审计) || 保留 bug 修复:`kv` 读取前先 `Bun.file(file).exists()`,缺文件返回 `{}`(首次启动 `kv.json` 不存在时不再打印误导性的 "Failed to read KV state",保留真实读/解析错误日志);`data` 事件驱动的 `catalog/reference/integration.updated` 三处 `void refresh()``.catch(console.error)``throwOnError` 下瞬时失败原为未处理 rejection,与初始加载 allSettled+console.error 一致);`editor.ts` Zed 轮询代际/`enabled()` 非响应式属自我纠正边角,按审计建议暂缓(上游若已做可取上游版本) |
207208

208209
### 其他
209210

packages/tui/src/context/data.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
127127
void Promise.all([
128128
result.location.model.refresh(event.location),
129129
result.location.provider.refresh(event.location),
130-
])
130+
]).catch((error) => console.error("Failed to refresh catalog", error))
131131
break
132132
case "session.next.agent.switched":
133133
message.update(event.data.sessionID, (draft) => {
@@ -390,14 +390,14 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
390390
})
391391
break
392392
case "reference.updated":
393-
void result.location.reference.refresh()
393+
void result.location.reference.refresh().catch((error) => console.error("Failed to refresh references", error))
394394
break
395395
case "integration.updated":
396396
void Promise.all([
397397
result.location.integration.refresh(event.location),
398398
result.location.model.refresh(event.location),
399399
result.location.provider.refresh(event.location),
400-
])
400+
]).catch((error) => console.error("Failed to refresh integrations", error))
401401
break
402402
}
403403
}

packages/tui/src/context/kv.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
1919
// Queue same-process writes so rapid updates persist in order.
2020
let write = Promise.resolve()
2121

22-
Flock.withLock(lock, () => readJson<Record<string, unknown>>(file))
22+
Flock.withLock(lock, async () => {
23+
if (!(await Bun.file(file).exists())) return {}
24+
return readJson<Record<string, unknown>>(file)
25+
})
2326
.then((x) => {
2427
setStore(x)
2528
})

0 commit comments

Comments
 (0)