refactor(tui): extract standalone package (#31193)

This commit is contained in:
Dax
2026-06-07 05:24:27 +00:00
committed by GitHub
parent 7a2c49e762
commit 106f8e94d6
84 changed files with 1148 additions and 1919 deletions
+5 -5
View File
@@ -2,7 +2,7 @@ import path from "path"
import { onMount } from "solid-js"
import { createStore } from "solid-js/store"
import { createSimpleContext } from "../context/helper"
import { useTuiEnvironment } from "../runtime"
import { useTuiPaths } from "../context/runtime"
import { appendText, readText, writeText } from "../util/persistence"
type FrecencyEntry = { path: string; frequency: number; lastOpen: number }
@@ -38,8 +38,8 @@ function calculateFrecency(entry?: { frequency: number; lastOpen: number }) {
export const { use: useFrecency, provider: FrecencyProvider } = createSimpleContext({
name: "Frecency",
init: () => {
const environment = useTuiEnvironment()
const frecencyPath = path.join(environment.paths.state, "frecency.jsonl")
const paths = useTuiPaths()
const frecencyPath = path.join(paths.state, "frecency.jsonl")
onMount(async () => {
const lines = parseFrecency(await readText(frecencyPath).catch(() => ""))
setStore(
@@ -55,7 +55,7 @@ export const { use: useFrecency, provider: FrecencyProvider } = createSimpleCont
const [store, setStore] = createStore({ data: {} as Record<string, { frequency: number; lastOpen: number }> })
function updateFrecency(filePath: string) {
const absolutePath = path.resolve(environment.cwd, filePath)
const absolutePath = path.resolve(paths.cwd, filePath)
const newEntry = { frequency: (store.data[absolutePath]?.frequency || 0) + 1, lastOpen: Date.now() }
setStore("data", absolutePath, newEntry)
appendText(frecencyPath, JSON.stringify({ path: absolutePath, ...newEntry }) + "\n").catch(() => {})
@@ -72,7 +72,7 @@ export const { use: useFrecency, provider: FrecencyProvider } = createSimpleCont
}
return {
getFrecency: (filePath: string) => calculateFrecency(store.data[path.resolve(environment.cwd, filePath)]),
getFrecency: (filePath: string) => calculateFrecency(store.data[path.resolve(paths.cwd, filePath)]),
updateFrecency,
data: () => store.data,
}
+3 -3
View File
@@ -3,7 +3,7 @@ import { onMount } from "solid-js"
import { createStore, produce, unwrap } from "solid-js/store"
import type { AgentPart, FilePart, TextPart } from "@opencode-ai/sdk/v2"
import { createSimpleContext } from "../context/helper"
import { useTuiEnvironment } from "../runtime"
import { useTuiPaths } from "../context/runtime"
import { appendText, readText, writeText } from "../util/persistence"
export type PromptInfo = {
@@ -49,8 +49,8 @@ export function isDuplicateEntry(previous: PromptInfo | undefined, next: PromptI
export const { use: usePromptHistory, provider: PromptHistoryProvider } = createSimpleContext({
name: "PromptHistory",
init: () => {
const environment = useTuiEnvironment()
const historyPath = path.join(environment.paths.state, "prompt-history.jsonl")
const paths = useTuiPaths()
const historyPath = path.join(paths.state, "prompt-history.jsonl")
onMount(async () => {
const lines = parsePromptHistory(await readText(historyPath).catch(() => ""))
setStore("history", lines)
+3 -3
View File
@@ -2,7 +2,7 @@ import path from "path"
import { onMount } from "solid-js"
import { createStore, produce, unwrap } from "solid-js/store"
import { createSimpleContext } from "../context/helper"
import { useTuiEnvironment } from "../runtime"
import { useTuiPaths } from "../context/runtime"
import { appendText, readText, writeText } from "../util/persistence"
import type { PromptInfo } from "./history"
@@ -32,8 +32,8 @@ export function parsePromptStash(text: string) {
export const { use: usePromptStash, provider: PromptStashProvider } = createSimpleContext({
name: "PromptStash",
init: () => {
const environment = useTuiEnvironment()
const stashPath = path.join(environment.paths.state, "prompt-stash.jsonl")
const paths = useTuiPaths()
const stashPath = path.join(paths.state, "prompt-stash.jsonl")
onMount(async () => {
const lines = parsePromptStash(await readText(stashPath).catch(() => ""))
setStore("entries", lines)