MCPcopy Create free account
hub / github.com/anomalyco/opencode / useThinkingMode

Function useThinkingMode

packages/tui/src/context/thinking.ts:29–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29export function useThinkingMode() {
30 const kv = useKV()
31 // Capture pre-state before `kv.signal` seeds a default, so we can detect
32 // first-time users with a legacy `thinking_visibility` boolean and migrate.
33 // The KVProvider only renders children once kv.ready, so reads here are safe.
34 const hadStored = kv.get("thinking_mode") !== undefined
35 const legacy = kv.get("thinking_visibility")
36 const [stored, setStored] = kv.signal<ThinkingMode>("thinking_mode", "hide")
37
38 // The kv signal exposes its setter typed as `Setter<T>` which carries Solid's
39 // overload set; passing an updater fn through a property access loses the
40 // bivariance trick the existing `setX((prev) => ...)` callsites rely on.
41 // Wrap it in a sane shape so consumers can just call `set(next)` or pass
42 // an updater.
43 const set = (next: ThinkingMode | ((prev: ThinkingMode) => ThinkingMode)) => {
44 if (typeof next === "function") setStored(next as Setter<ThinkingMode>)
45 else setStored(() => next)
46 }
47
48 // Preserve previous experience for users who had explicitly toggled the
49 // legacy `thinking_visibility` boolean. First-time users (no legacy key)
50 // get the new "hide" default (collapsed thinking).
51 if (!hadStored) {
52 if (legacy === true) set("show")
53 else if (legacy === false) set("hide")
54 }
55
56 if ((stored() as string) === "minimal") set("hide")
57
58 const mode = createMemo<ThinkingMode>(() => {
59 const value = stored()
60 return isThinkingMode(value) ? value : "hide"
61 })
62
63 return {
64 mode,
65 set,
66 }
67}

Callers 1

SessionFunction · 0.90

Calls 4

isThinkingModeFunction · 0.85
setFunction · 0.70
getMethod · 0.65
storedFunction · 0.50

Tested by

no test coverage detected