@neurocode-ai/tui 1.18.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bunfig.toml +4 -0
- package/package.json +72 -0
- package/src/app.tsx +1134 -0
- package/src/attention.ts +260 -0
- package/src/audio.d.ts +9 -0
- package/src/audio.ts +53 -0
- package/src/clipboard.ts +124 -0
- package/src/component/bg-pulse-render.ts +436 -0
- package/src/component/bg-pulse.tsx +99 -0
- package/src/component/command-palette.tsx +79 -0
- package/src/component/dialog-agent.tsx +31 -0
- package/src/component/dialog-console-org.tsx +135 -0
- package/src/component/dialog-debug.tsx +90 -0
- package/src/component/dialog-mcp.tsx +85 -0
- package/src/component/dialog-model.tsx +197 -0
- package/src/component/dialog-move-session.tsx +353 -0
- package/src/component/dialog-provider.tsx +469 -0
- package/src/component/dialog-retry-action.tsx +160 -0
- package/src/component/dialog-session-delete-failed.tsx +99 -0
- package/src/component/dialog-session-list.tsx +364 -0
- package/src/component/dialog-session-rename.tsx +31 -0
- package/src/component/dialog-skill.tsx +70 -0
- package/src/component/dialog-stash.tsx +87 -0
- package/src/component/dialog-status.tsx +168 -0
- package/src/component/dialog-tag.tsx +47 -0
- package/src/component/dialog-theme-list.tsx +50 -0
- package/src/component/dialog-variant.tsx +39 -0
- package/src/component/dialog-workspace-create.tsx +308 -0
- package/src/component/dialog-workspace-file-changes.tsx +144 -0
- package/src/component/dialog-workspace-list.tsx +112 -0
- package/src/component/dialog-workspace-unavailable.tsx +69 -0
- package/src/component/error-component.tsx +240 -0
- package/src/component/logo.tsx +61 -0
- package/src/component/plugin-route-missing.tsx +14 -0
- package/src/component/prompt/autocomplete.tsx +781 -0
- package/src/component/prompt/cwd.ts +0 -0
- package/src/component/prompt/frecency.tsx +1 -0
- package/src/component/prompt/history.tsx +1 -0
- package/src/component/prompt/index.tsx +1713 -0
- package/src/component/prompt/local-attachment.ts +48 -0
- package/src/component/prompt/move.tsx +205 -0
- package/src/component/prompt/stash.tsx +1 -0
- package/src/component/prompt/workspace.tsx +137 -0
- package/src/component/register-spinner.ts +6 -0
- package/src/component/spinner.tsx +26 -0
- package/src/component/startup-loading.tsx +63 -0
- package/src/component/todo-item.tsx +32 -0
- package/src/component/use-connected.tsx +12 -0
- package/src/component/workspace-label.tsx +19 -0
- package/src/config/index.tsx +129 -0
- package/src/config/keybind.ts +471 -0
- package/src/context/args.tsx +16 -0
- package/src/context/clipboard.tsx +18 -0
- package/src/context/data.tsx +569 -0
- package/src/context/directory.ts +17 -0
- package/src/context/editor.ts +408 -0
- package/src/context/epilogue.tsx +6 -0
- package/src/context/event.ts +36 -0
- package/src/context/exit.tsx +8 -0
- package/src/context/helper.tsx +26 -0
- package/src/context/kv.tsx +66 -0
- package/src/context/local.tsx +542 -0
- package/src/context/location.tsx +14 -0
- package/src/context/path-format.tsx +24 -0
- package/src/context/permission.tsx +26 -0
- package/src/context/project.tsx +115 -0
- package/src/context/prompt.tsx +18 -0
- package/src/context/route.tsx +60 -0
- package/src/context/runtime.tsx +62 -0
- package/src/context/sdk.tsx +151 -0
- package/src/context/sync.tsx +666 -0
- package/src/context/theme.tsx +332 -0
- package/src/context/thinking.ts +67 -0
- package/src/editor-zed.ts +286 -0
- package/src/editor.ts +101 -0
- package/src/feature-plugins/builtins.ts +36 -0
- package/src/feature-plugins/home/footer.tsx +100 -0
- package/src/feature-plugins/home/tips-view.tsx +287 -0
- package/src/feature-plugins/home/tips.tsx +59 -0
- package/src/feature-plugins/sidebar/context.tsx +65 -0
- package/src/feature-plugins/sidebar/files.tsx +70 -0
- package/src/feature-plugins/sidebar/footer.tsx +98 -0
- package/src/feature-plugins/sidebar/lsp.tsx +65 -0
- package/src/feature-plugins/sidebar/mcp.tsx +97 -0
- package/src/feature-plugins/sidebar/todo.tsx +49 -0
- package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +232 -0
- package/src/feature-plugins/system/diff-viewer-file-tree.tsx +162 -0
- package/src/feature-plugins/system/diff-viewer-ui.tsx +103 -0
- package/src/feature-plugins/system/diff-viewer.tsx +1077 -0
- package/src/feature-plugins/system/notifications.ts +94 -0
- package/src/feature-plugins/system/plugins.tsx +269 -0
- package/src/feature-plugins/system/which-key.tsx +608 -0
- package/src/index.tsx +1 -0
- package/src/keymap.tsx +290 -0
- package/src/logo.ts +11 -0
- package/src/parsers-config.ts +386 -0
- package/src/plugin/adapters.tsx +355 -0
- package/src/plugin/api.ts +52 -0
- package/src/plugin/command-shim.ts +109 -0
- package/src/plugin/runtime.tsx +81 -0
- package/src/plugin/slots.tsx +65 -0
- package/src/prompt/display.ts +48 -0
- package/src/prompt/frecency.tsx +80 -0
- package/src/prompt/history.tsx +111 -0
- package/src/prompt/part.ts +29 -0
- package/src/prompt/stash.tsx +89 -0
- package/src/prompt/traits.ts +29 -0
- package/src/routes/home/session-destination.tsx +41 -0
- package/src/routes/home.tsx +95 -0
- package/src/routes/session/dialog-fork-from-timeline.tsx +76 -0
- package/src/routes/session/dialog-message.tsx +109 -0
- package/src/routes/session/dialog-subagent.tsx +26 -0
- package/src/routes/session/dialog-timeline.tsx +47 -0
- package/src/routes/session/footer.tsx +91 -0
- package/src/routes/session/index.tsx +2710 -0
- package/src/routes/session/permission.tsx +718 -0
- package/src/routes/session/question.tsx +514 -0
- package/src/routes/session/sidebar.tsx +103 -0
- package/src/routes/session/subagent-footer.tsx +132 -0
- package/src/runtime.tsx +9 -0
- package/src/terminal-win32.ts +130 -0
- package/src/theme/assets/aura.json +69 -0
- package/src/theme/assets/ayu.json +80 -0
- package/src/theme/assets/carbonfox.json +248 -0
- package/src/theme/assets/catppuccin-frappe.json +230 -0
- package/src/theme/assets/catppuccin-macchiato.json +230 -0
- package/src/theme/assets/catppuccin.json +112 -0
- package/src/theme/assets/cobalt2.json +225 -0
- package/src/theme/assets/cursor.json +249 -0
- package/src/theme/assets/dracula.json +219 -0
- package/src/theme/assets/everforest.json +241 -0
- package/src/theme/assets/flexoki.json +237 -0
- package/src/theme/assets/github.json +233 -0
- package/src/theme/assets/gruvbox.json +242 -0
- package/src/theme/assets/kanagawa.json +77 -0
- package/src/theme/assets/lucent-orng.json +234 -0
- package/src/theme/assets/material.json +235 -0
- package/src/theme/assets/matrix.json +77 -0
- package/src/theme/assets/mercury.json +252 -0
- package/src/theme/assets/monokai.json +221 -0
- package/src/theme/assets/nightowl.json +221 -0
- package/src/theme/assets/nord.json +223 -0
- package/src/theme/assets/one-dark.json +84 -0
- package/src/theme/assets/opencode.json +245 -0
- package/src/theme/assets/orng.json +249 -0
- package/src/theme/assets/osaka-jade.json +93 -0
- package/src/theme/assets/palenight.json +222 -0
- package/src/theme/assets/rosepine.json +234 -0
- package/src/theme/assets/solarized.json +223 -0
- package/src/theme/assets/synthwave84.json +226 -0
- package/src/theme/assets/tokyonight.json +243 -0
- package/src/theme/assets/vercel.json +245 -0
- package/src/theme/assets/vesper.json +218 -0
- package/src/theme/assets/zenburn.json +223 -0
- package/src/theme/index.ts +1089 -0
- package/src/ui/border.ts +21 -0
- package/src/ui/dialog-alert.tsx +66 -0
- package/src/ui/dialog-confirm.tsx +108 -0
- package/src/ui/dialog-export-options.tsx +217 -0
- package/src/ui/dialog-help.tsx +40 -0
- package/src/ui/dialog-prompt.tsx +126 -0
- package/src/ui/dialog-select.tsx +790 -0
- package/src/ui/dialog.tsx +231 -0
- package/src/ui/link.tsx +34 -0
- package/src/ui/spinner.ts +368 -0
- package/src/ui/toast.tsx +102 -0
- package/src/util/collapse-tool-output.ts +19 -0
- package/src/util/error.ts +182 -0
- package/src/util/filetype.ts +130 -0
- package/src/util/format.ts +20 -0
- package/src/util/layout.ts +25 -0
- package/src/util/locale.ts +86 -0
- package/src/util/model.ts +28 -0
- package/src/util/path.ts +12 -0
- package/src/util/persistence.ts +33 -0
- package/src/util/presentation.ts +38 -0
- package/src/util/provider-origin.ts +7 -0
- package/src/util/record.ts +3 -0
- package/src/util/renderer.ts +7 -0
- package/src/util/revert-diff.ts +18 -0
- package/src/util/scroll.ts +27 -0
- package/src/util/selection.ts +79 -0
- package/src/util/session.ts +3 -0
- package/src/util/signal.ts +51 -0
- package/src/util/system.ts +20 -0
- package/src/util/tool-display.ts +13 -0
- package/src/util/transcript.ts +112 -0
- package/sst-env.d.ts +10 -0
- package/test/app-lifecycle.test.tsx +128 -0
- package/test/cli/cmd/tui/dialog-workspace-create.test.ts +28 -0
- package/test/cli/cmd/tui/model-options.test.ts +32 -0
- package/test/cli/cmd/tui/notifications.test.ts +267 -0
- package/test/cli/cmd/tui/provider-options.test.ts +41 -0
- package/test/cli/cmd/tui/sync-fixture.tsx +70 -0
- package/test/cli/cmd/tui/sync-live-hydration.test.tsx +262 -0
- package/test/cli/cmd/tui/sync-undefined-messages.test.tsx +43 -0
- package/test/cli/cmd/tui/sync.test.tsx +65 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +92 -0
- package/test/cli/tui/data.test.tsx +486 -0
- package/test/cli/tui/dialog-prompt.test.tsx +147 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +200 -0
- package/test/cli/tui/diff-viewer.test.tsx +268 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +351 -0
- package/test/cli/tui/prompt-submit-race.test.ts +98 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/use-event.test.tsx +148 -0
- package/test/clipboard.test.ts +19 -0
- package/test/component/dialog-session-list.test.ts +46 -0
- package/test/config.test.tsx +127 -0
- package/test/context/local.test.ts +22 -0
- package/test/editor.test.ts +32 -0
- package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +323 -0
- package/test/fixture/fixture.ts +13 -0
- package/test/fixture/tui-environment.tsx +32 -0
- package/test/fixture/tui-plugin.ts +36 -0
- package/test/fixture/tui-runtime.ts +12 -0
- package/test/fixture/tui-sdk.ts +109 -0
- package/test/index.test.tsx +6 -0
- package/test/keymap.test.tsx +141 -0
- package/test/plugin/runtime.test.ts +50 -0
- package/test/plugin/slots.test.tsx +38 -0
- package/test/prompt/display.test.ts +33 -0
- package/test/prompt/history.test.ts +39 -0
- package/test/prompt/jsonl.test.ts +24 -0
- package/test/prompt/local-attachment.test.ts +43 -0
- package/test/prompt/part.test.ts +53 -0
- package/test/prompt/persistence.test.ts +23 -0
- package/test/prompt/traits.test.ts +25 -0
- package/test/runtime.test.tsx +37 -0
- package/test/theme.test.ts +81 -0
- package/test/util/error.test.ts +49 -0
- package/test/util/filetype.test.ts +16 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/model.test.ts +9 -0
- package/test/util/presentation.test.ts +8 -0
- package/test/util/renderer.test.ts +30 -0
- package/test/util/revert-diff.test.ts +35 -0
- package/test/util/session.test.ts +10 -0
- package/test/util/tool-display.test.ts +40 -0
- package/test/util/transcript.test.ts +421 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import type { TerminalColors } from "@opentui/core"
|
|
5
|
+
import { DEFAULT_THEMES, addTheme, allThemes, hasTheme, resolveTheme, terminalMode } from "../src/theme"
|
|
6
|
+
import { discoverThemes } from "../src/context/theme"
|
|
7
|
+
import { tmpdir } from "./fixture/fixture"
|
|
8
|
+
|
|
9
|
+
test("addTheme writes into module theme store", () => {
|
|
10
|
+
const name = `plugin-theme-${Date.now()}`
|
|
11
|
+
expect(addTheme(name, DEFAULT_THEMES.opencode)).toBe(true)
|
|
12
|
+
expect(allThemes()[name]).toBeDefined()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test("addTheme keeps first theme for duplicate names", () => {
|
|
16
|
+
const name = `plugin-theme-keep-${Date.now()}`
|
|
17
|
+
const one = structuredClone(DEFAULT_THEMES.opencode)
|
|
18
|
+
const two = structuredClone(DEFAULT_THEMES.opencode)
|
|
19
|
+
one.theme.primary = "#101010"
|
|
20
|
+
two.theme.primary = "#fefefe"
|
|
21
|
+
|
|
22
|
+
expect(addTheme(name, one)).toBe(true)
|
|
23
|
+
expect(addTheme(name, two)).toBe(false)
|
|
24
|
+
expect(allThemes()[name]!.theme.primary).toBe("#101010")
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("addTheme ignores entries without a theme object", () => {
|
|
28
|
+
const name = `plugin-theme-invalid-${Date.now()}`
|
|
29
|
+
expect(addTheme(name, { defs: { a: "#ffffff" } })).toBe(false)
|
|
30
|
+
expect(allThemes()[name]).toBeUndefined()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test("hasTheme checks theme presence", () => {
|
|
34
|
+
const name = `plugin-theme-has-${Date.now()}`
|
|
35
|
+
expect(hasTheme(name)).toBe(false)
|
|
36
|
+
expect(addTheme(name, DEFAULT_THEMES.opencode)).toBe(true)
|
|
37
|
+
expect(hasTheme(name)).toBe(true)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test("resolveTheme rejects circular color refs", () => {
|
|
41
|
+
const item = structuredClone(DEFAULT_THEMES.opencode)
|
|
42
|
+
item.defs = { ...item.defs, one: "two", two: "one" }
|
|
43
|
+
item.theme.primary = "one"
|
|
44
|
+
expect(() => resolveTheme(item, "dark")).toThrow("Circular color reference")
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
function terminalColors(defaultBackground: string | null, palette: Array<string | null> = []): TerminalColors {
|
|
48
|
+
return {
|
|
49
|
+
palette,
|
|
50
|
+
defaultForeground: null,
|
|
51
|
+
defaultBackground,
|
|
52
|
+
cursorColor: null,
|
|
53
|
+
mouseForeground: null,
|
|
54
|
+
mouseBackground: null,
|
|
55
|
+
tekForeground: null,
|
|
56
|
+
tekBackground: null,
|
|
57
|
+
highlightBackground: null,
|
|
58
|
+
highlightForeground: null,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
test("terminalMode derives mode from refreshed background", () => {
|
|
63
|
+
expect(terminalMode(terminalColors("#fbf1c7"))).toBe("light")
|
|
64
|
+
expect(terminalMode(terminalColors("#1a1b26"))).toBe("dark")
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test("terminalMode does not derive mode from ANSI slot zero", () => {
|
|
68
|
+
expect(terminalMode(terminalColors(null, ["#000000"]))).toBeUndefined()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test("custom theme precedence follows directory order", async () => {
|
|
72
|
+
await using tmp = await tmpdir()
|
|
73
|
+
const global = path.join(tmp.path, "global")
|
|
74
|
+
const project = path.join(tmp.path, "project")
|
|
75
|
+
await mkdir(path.join(global, "themes"), { recursive: true })
|
|
76
|
+
await mkdir(path.join(project, "themes"), { recursive: true })
|
|
77
|
+
await writeFile(path.join(global, "themes", "custom.json"), JSON.stringify({ source: "global" }))
|
|
78
|
+
await writeFile(path.join(project, "themes", "custom.json"), JSON.stringify({ source: "project" }))
|
|
79
|
+
|
|
80
|
+
await expect(discoverThemes([global, project])).resolves.toEqual({ custom: { source: "project" } })
|
|
81
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { errorData, errorFormat, errorMessage } from "../../src/util/error"
|
|
3
|
+
|
|
4
|
+
describe("util.error", () => {
|
|
5
|
+
test("formats native Error instances", () => {
|
|
6
|
+
const err = new Error("boom")
|
|
7
|
+
expect(errorMessage(err)).toBe("boom")
|
|
8
|
+
expect(errorFormat(err)).toContain("boom")
|
|
9
|
+
|
|
10
|
+
const data = errorData(err)
|
|
11
|
+
expect(data.type).toBe("Error")
|
|
12
|
+
expect(data.message).toBe("boom")
|
|
13
|
+
expect(String(data.formatted)).toContain("boom")
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test("extracts message from record-like values", () => {
|
|
17
|
+
const err = { message: "bad input", code: "E_BAD" }
|
|
18
|
+
expect(errorMessage(err)).toBe("bad input")
|
|
19
|
+
|
|
20
|
+
const data = errorData(err)
|
|
21
|
+
expect(data.message).toBe("bad input")
|
|
22
|
+
expect(data.code).toBe("E_BAD")
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test("never returns bare {} for opaque object errors", () => {
|
|
26
|
+
expect(errorFormat({})).not.toBe("{}")
|
|
27
|
+
expect(errorFormat({})).toContain("no message")
|
|
28
|
+
|
|
29
|
+
class OpaqueError {}
|
|
30
|
+
const opaque = new OpaqueError()
|
|
31
|
+
Object.defineProperty(opaque, "secret", { value: "hidden", enumerable: false })
|
|
32
|
+
expect(errorFormat(opaque)).not.toBe("{}")
|
|
33
|
+
expect(errorFormat(opaque)).toContain("OpaqueError")
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test("handles opaque throwables with custom toString", () => {
|
|
37
|
+
const err = {
|
|
38
|
+
toString() {
|
|
39
|
+
return "ResolveMessage: Cannot resolve module"
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
expect(errorMessage(err)).toBe("ResolveMessage: Cannot resolve module")
|
|
44
|
+
|
|
45
|
+
const data = errorData(err)
|
|
46
|
+
expect(data.message).toBe("ResolveMessage: Cannot resolve module")
|
|
47
|
+
expect(String(data.formatted)).toContain("ResolveMessage")
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { filetype } from "../../src/util/filetype"
|
|
3
|
+
|
|
4
|
+
describe("util.filetype", () => {
|
|
5
|
+
test("maps filenames to presentation languages", () => {
|
|
6
|
+
expect(filetype("component.tsx")).toBe("typescript")
|
|
7
|
+
expect(filetype("script.js")).toBe("typescript")
|
|
8
|
+
expect(filetype("main.py")).toBe("python")
|
|
9
|
+
expect(filetype("README.unknown")).toBeUndefined()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test("uses none for missing filenames", () => {
|
|
13
|
+
expect(filetype()).toBe("none")
|
|
14
|
+
expect(filetype("")).toBe("none")
|
|
15
|
+
})
|
|
16
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { formatDuration } from "../../src/util/format"
|
|
3
|
+
|
|
4
|
+
describe("util.format", () => {
|
|
5
|
+
describe("formatDuration", () => {
|
|
6
|
+
test("returns empty string for zero or negative values", () => {
|
|
7
|
+
expect(formatDuration(0)).toBe("")
|
|
8
|
+
expect(formatDuration(-1)).toBe("")
|
|
9
|
+
expect(formatDuration(-100)).toBe("")
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test("formats seconds under a minute", () => {
|
|
13
|
+
expect(formatDuration(1)).toBe("1s")
|
|
14
|
+
expect(formatDuration(30)).toBe("30s")
|
|
15
|
+
expect(formatDuration(59)).toBe("59s")
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test("formats minutes under an hour", () => {
|
|
19
|
+
expect(formatDuration(60)).toBe("1m")
|
|
20
|
+
expect(formatDuration(61)).toBe("1m 1s")
|
|
21
|
+
expect(formatDuration(90)).toBe("1m 30s")
|
|
22
|
+
expect(formatDuration(120)).toBe("2m")
|
|
23
|
+
expect(formatDuration(330)).toBe("5m 30s")
|
|
24
|
+
expect(formatDuration(3599)).toBe("59m 59s")
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("formats hours under a day", () => {
|
|
28
|
+
expect(formatDuration(3600)).toBe("1h")
|
|
29
|
+
expect(formatDuration(3660)).toBe("1h 1m")
|
|
30
|
+
expect(formatDuration(7200)).toBe("2h")
|
|
31
|
+
expect(formatDuration(8100)).toBe("2h 15m")
|
|
32
|
+
expect(formatDuration(86399)).toBe("23h 59m")
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test("formats days under a week", () => {
|
|
36
|
+
expect(formatDuration(86400)).toBe("~1 day")
|
|
37
|
+
expect(formatDuration(172800)).toBe("~2 days")
|
|
38
|
+
expect(formatDuration(259200)).toBe("~3 days")
|
|
39
|
+
expect(formatDuration(604799)).toBe("~6 days")
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test("formats weeks", () => {
|
|
43
|
+
expect(formatDuration(604800)).toBe("~1 week")
|
|
44
|
+
expect(formatDuration(1209600)).toBe("~2 weeks")
|
|
45
|
+
expect(formatDuration(1609200)).toBe("~2 weeks")
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("handles boundary values correctly", () => {
|
|
49
|
+
expect(formatDuration(59)).toBe("59s")
|
|
50
|
+
expect(formatDuration(60)).toBe("1m")
|
|
51
|
+
expect(formatDuration(3599)).toBe("59m 59s")
|
|
52
|
+
expect(formatDuration(3600)).toBe("1h")
|
|
53
|
+
expect(formatDuration(86399)).toBe("23h 59m")
|
|
54
|
+
expect(formatDuration(86400)).toBe("~1 day")
|
|
55
|
+
expect(formatDuration(604799)).toBe("~6 days")
|
|
56
|
+
expect(formatDuration(604800)).toBe("~1 week")
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { parse } from "../../src/util/model"
|
|
3
|
+
|
|
4
|
+
describe("util.model", () => {
|
|
5
|
+
test("splits provider from a nested model identifier", () => {
|
|
6
|
+
expect(parse("provider/org/model")).toEqual({ providerID: "provider", modelID: "org/model" })
|
|
7
|
+
expect(parse("invalid")).toEqual({ providerID: "invalid", modelID: "" })
|
|
8
|
+
})
|
|
9
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { sessionEpilogue } from "../../src/util/presentation"
|
|
3
|
+
|
|
4
|
+
test("formats session continuation summary", () => {
|
|
5
|
+
const epilogue = sessionEpilogue({ title: "A session", sessionID: "ses_123" })
|
|
6
|
+
expect(epilogue).toContain("A session")
|
|
7
|
+
expect(epilogue).toContain("neurocode -s ses_123")
|
|
8
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { destroyRenderer } from "../../src/util/renderer"
|
|
3
|
+
|
|
4
|
+
test("clears the terminal title before destroying the renderer", () => {
|
|
5
|
+
const calls: string[] = []
|
|
6
|
+
destroyRenderer({
|
|
7
|
+
isDestroyed: false,
|
|
8
|
+
setTerminalTitle(title) {
|
|
9
|
+
calls.push(`title:${title}`)
|
|
10
|
+
},
|
|
11
|
+
destroy() {
|
|
12
|
+
calls.push("destroy")
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
expect(calls).toEqual(["title:", "destroy"])
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test("still clears the title after renderer destruction", () => {
|
|
19
|
+
const calls: string[] = []
|
|
20
|
+
destroyRenderer({
|
|
21
|
+
isDestroyed: true,
|
|
22
|
+
setTerminalTitle(title) {
|
|
23
|
+
calls.push(`title:${title}`)
|
|
24
|
+
},
|
|
25
|
+
destroy() {
|
|
26
|
+
calls.push("destroy")
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
expect(calls).toEqual(["title:"])
|
|
30
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { getRevertDiffFiles } from "../../src/util/revert-diff"
|
|
3
|
+
|
|
4
|
+
describe("revert diff", () => {
|
|
5
|
+
test("prefers the actual file path over /dev/null for added and deleted files", () => {
|
|
6
|
+
const files = getRevertDiffFiles(`diff --git a/new.txt b/new.txt
|
|
7
|
+
new file mode 100644
|
|
8
|
+
index 0000000..3b18e51
|
|
9
|
+
--- /dev/null
|
|
10
|
+
+++ b/new.txt
|
|
11
|
+
@@ -0,0 +1 @@
|
|
12
|
+
+new content
|
|
13
|
+
diff --git a/old.txt b/old.txt
|
|
14
|
+
deleted file mode 100644
|
|
15
|
+
index 3b18e51..0000000
|
|
16
|
+
--- a/old.txt
|
|
17
|
+
+++ /dev/null
|
|
18
|
+
@@ -1 +0,0 @@
|
|
19
|
+
-old content
|
|
20
|
+
`)
|
|
21
|
+
|
|
22
|
+
expect(files).toEqual([
|
|
23
|
+
{
|
|
24
|
+
filename: "new.txt",
|
|
25
|
+
additions: 1,
|
|
26
|
+
deletions: 0,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
filename: "old.txt",
|
|
30
|
+
additions: 0,
|
|
31
|
+
deletions: 1,
|
|
32
|
+
},
|
|
33
|
+
])
|
|
34
|
+
})
|
|
35
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { isDefaultTitle } from "../../src/util/session"
|
|
3
|
+
|
|
4
|
+
describe("util.session", () => {
|
|
5
|
+
test("recognizes generated parent and child titles", () => {
|
|
6
|
+
expect(isDefaultTitle("New session - 2026-06-06T12:34:56.789Z")).toBeTrue()
|
|
7
|
+
expect(isDefaultTitle("Child session - 2026-06-06T12:34:56.789Z")).toBeTrue()
|
|
8
|
+
expect(isDefaultTitle("New session - custom")).toBeFalse()
|
|
9
|
+
})
|
|
10
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { toolDisplayMetadata, webSearchProviderLabel } from "../../src/util/tool-display"
|
|
3
|
+
|
|
4
|
+
describe("webSearchProviderLabel", () => {
|
|
5
|
+
test("labels known providers", () => {
|
|
6
|
+
expect(webSearchProviderLabel("parallel")).toBe("Parallel Web Search")
|
|
7
|
+
expect(webSearchProviderLabel("exa")).toBe("Exa Web Search")
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
for (const [name, provider] of [
|
|
11
|
+
["undefined", undefined],
|
|
12
|
+
["null", null],
|
|
13
|
+
["an object", {}],
|
|
14
|
+
["an array", []],
|
|
15
|
+
["a number", 1],
|
|
16
|
+
["an unexpected string", "other"],
|
|
17
|
+
] as const) {
|
|
18
|
+
test(`uses the generic label for ${name}`, () => {
|
|
19
|
+
expect(webSearchProviderLabel(provider)).toBe("Web Search")
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe("toolDisplayMetadata", () => {
|
|
25
|
+
test("returns structured metadata for non-pending states", () => {
|
|
26
|
+
const structured = { provider: "parallel", numResults: 3 }
|
|
27
|
+
|
|
28
|
+
expect(toolDisplayMetadata({ status: "running", structured })).toBe(structured)
|
|
29
|
+
expect(toolDisplayMetadata({ status: "completed", structured })).toBe(structured)
|
|
30
|
+
expect(toolDisplayMetadata({ status: "error", structured })).toBe(structured)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test("does not expose pending or malformed metadata", () => {
|
|
34
|
+
expect(toolDisplayMetadata({ status: "pending", structured: { provider: "exa" } })).toEqual({})
|
|
35
|
+
expect(toolDisplayMetadata({ status: "completed" })).toEqual({})
|
|
36
|
+
expect(toolDisplayMetadata({ status: "completed", structured: null })).toEqual({})
|
|
37
|
+
expect(toolDisplayMetadata({ status: "completed", structured: [] })).toEqual({})
|
|
38
|
+
expect(toolDisplayMetadata(undefined)).toEqual({})
|
|
39
|
+
})
|
|
40
|
+
})
|