feat(workbench): Knowledge Workbench — new React/TS frontend + supporting backend#188
Closed
KylinMountain wants to merge 87 commits into
Closed
feat(workbench): Knowledge Workbench — new React/TS frontend + supporting backend#188KylinMountain wants to merge 87 commits into
KylinMountain wants to merge 87 commits into
Conversation
…ion cluster, theme toggle Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…ve and tagline footer Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…rtifact preview
Migrate ChatInput, ChatSession, and ArtifactCard off hardcoded
bg-white/bg-blue-*/border-black/text-neutral-* colors onto the Apple
token layer (.glass/.glass-2, border-[hsl(var(--glass-border))],
bg-accent-brand, text-foreground/text-muted-foreground). Fixes the
shared ChatInput box + slash-command menu rendering white against the
dark shell (flagged in Task 4). Source chips gain active:scale-[0.97]
+ transition duration-fast ease-out-apple press feedback.
Wrap the deck preview panel in motion AnimatePresence + a critically-
damped spring (bounce:0, 0.24s), degrading to an opacity-only cross-fade
under prefers-reduced-motion via useReducedMotion. The sandboxed iframe
(sandbox=allow-scripts, src={previewUrl} blob URL) and its blob-URL
revocation lifecycle are unchanged; the spring only wraps the panel.
Slash-command logic, streaming, citations, and session handling are
untouched. Semantic deck/skill/graph accent colors are preserved.
Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…tion + press feedback Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
KbDetail kept light-only semantic status colors (bg-*-50 / text-*-500 / text-*-600) with no dark: pair, so red error cards and emerald/red status pills rendered as bright light patches in dark mode. Add dark: variants only (no light-mode, layout, or logic changes), matching the app-wide pattern from ChatSession.tsx (red) and ArtifactCard.tsx StatusBadge (emerald): dark:bg-red-500/10 dark:border-red-500/25 dark:text-red-400 and dark:bg-emerald-500/10 dark:text-emerald-400. Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…ize listeners on unmount
…lear the theme pill (+ room for i18n) Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…ials removed) Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…key whitelist parity Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…el labeled region
KbSettingsSheet (modal): compose @radix-ui/react-dialog around the existing
motion.aside via asChild + forceMount so AnimatePresence keeps the D-era spring
and reduced-motion. Radix supplies focus trap, initial focus, and Escape-close;
add aria-modal + aria-labelledby (Dialog.Title on the heading) explicitly, and
drive focus return to the opening gear via on{Open,Close}AutoFocus (we open from
external state, so Radix's own triggerRef is null and would drop focus to body).
Scrim/backdrop-dismiss, config inherit/override, watch/recompile/lint, threshold
validation and all i18n preserved.
ArtifactPanel (non-modal docked): add role=complementary + aria-label (active
artifact label), aria-label on the header controls, and a one-time initial focus
to the panel on open. No focus trap and no background inert — Tab still flows out
to the chat. iframe/blob/new-tab/download, switcher, motion and i18n preserved.
Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
The KB list page had two "New knowledge base" controls (top-right button + in-grid dashed card) and NEITHER had an onClick — the frontend never wired KB creation. The sidebar's "+" was a third dead trigger. - add createKb() -> POST /api/v1/init (api/kb.ts) - new CreateKbDialog: Radix modal (Dialog.Trigger asChild for focus-trap/Escape/ focus-return), name-only field (model/creds inherit global defaults), inline backend-error surfacing, success -> navigate to the new KB - KbList: remove the dashed card; wire the single top-right button as the trigger - AppSidebar: wire the "+" to the same dialog Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
Previously all streamed delta text (planning narration + the answer) was concatenated into one blob and tool reads showed only as separate chips. - chat.ts: fold SSE events into an ordered TurnStep[] preserving arrival order (text segments interleaved with tool steps); tool_call marks the prior read done; final reconciles the trailing text with the authoritative answer. The flat `answer`/`sources`/`reading` fields are retained for restore/consumers. - ChatSession.tsx: render steps in order — narration via MarkdownView, each read as a status line (spinner -> green check), page reads stay click-through. - drop `/compile` from the slash palette (runTurn never had a compile branch; recompile lives on the KB gear) and remove its now-unused icon import + keys. Chat is for Q&A + generation; KB-lifecycle actions live on the KB surface. Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…guage picker Settings global config surface: - backend: GET/PATCH /api/v1/config now also read/write global default credentials (LLM_API_KEY / OPENAI_API_BASE) in ~/.config/openkb/.env, mirroring the per-KB .env write (0o600, atomic, RFC-7386 null-removal, key value never returned/ logged), under the existing global-config lock. GlobalConfigResponse gains openai_api_base + has_api_key; GlobalConfigPatchRequest gains api_key (SecretStr) + openai_api_base. +6 tests. - Settings.tsx: add a Default credentials section (masked key, set/unset hint, deferred clear, API base) folded into the merge-patch save; remove the dead brand/privacy footer card + its i18n key. Wiki output language now offers the six official UN languages as a datalist combobox (still free-text, so e.g. 日本語 works) in both the global Settings and the per-KB gear. Also a one-line LanguageToggle doc-comment fix. Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…p the trace Revisiting a saved session collapsed the interleaved trace back to one text block, because only the flat answer was persisted. Now the ordered trace (narration text + tool reads) is stored per turn and rebuilt on restore. Backend: - ChatSession gains `assistant_traces` (parallel to assistant_texts, 1:1 by index); to_dict/load_session round-trip it; record_turn accepts a `trace` and back-fills empty traces for older turns so a pre-existing session that gets a new turn stays index-aligned. Old files without the key load as [] (no crash). - iter_chat_turn_events accumulates the trace from delta/tool_call events (same order the frontend folds live) and persists it via record_turn. - ChatSessionLoadResponse returns assistant_traces (new ChatTraceStep model). Frontend: - loadSession exposes assistant_traces; ChatSession restore rebuilds steps via stepsFromTrace (tool steps re-derived through the same read-only whitelist), falling back to a single text step for trace-less (old / CLI) turns. - fix a latent live bug: on `final`, do NOT overwrite the trailing text step with final.answer (which is the full narration+answer concatenation) — that duplicated narration once tool reads split the text; keep the streamed trace and only inject the answer when nothing streamed. Backward compatible: only sessions created after this change carry a trace; older ones render their saved text as before. Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
Review follow-up. The trace recorded every tool_call, including write_file, whose `arguments` carries the entire generated file `content`. That bloated the session JSON and was shipped to the browser on restore only to be dropped by the frontend's read-only whitelist. Gate recording to _TRACE_READ_TOOLS (read_file / get_page_content) — the only tools the UI renders — which also fixes a live-vs-restore text-grouping divergence a dropped write_file caused. Plus a tidy-up of the languages.ts doc comment (drop raw CJK). Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
…n MarkdownView Answers that contain LaTeX (\[ … \] block, \( … \) inline) and `---` rules showed the raw delimiters/dashes as literal text. Add math + horizontal-rule support to the hand-rolled MarkdownView: block/inline math render via KaTeX (bundled + self-contained, no CDN; malformed TeX falls back to a code box), and a `---`/`***`/`___` line renders an <hr>. Adds katex (pinned exact, matching the mermaid/motion convention) + @types/katex. Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
The About tab linked a "Website openkb.ai" that does not exist yet; remove the link entry and its i18n key (both locales). The Globe icon stays (still used by the Vectify AI company link). Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
| """ | ||
|
|
||
| def test_query_resolves_model_from_global_config(self, kb_dir, monkeypatch, tmp_path): | ||
| import openkb.cli as cli_mod |
| import asyncio | ||
|
|
||
| import openkb.agent.query as q | ||
| import openkb.config as cfg |
|
|
||
| # Single source of truth for the writable config keys (derived from the model | ||
| # above so the two never drift). | ||
| _KB_CONFIG_WRITABLE_KEYS = set(_KbConfigWritable.model_fields) |
… / junk) GET /api/v1/page serves pages verbatim, so every concept/entity/summary page's OKF `--- … ---` frontmatter leaked into the reader as junk metadata lines — and, now that MarkdownView renders `---` as an <hr>, as a horizontal rule at the very top. Strip a leading frontmatter block before rendering (reader only; chat answers carry no frontmatter and are untouched). Second-review follow-up. Claude-Session: https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG
Collaborator
Author
|
Superseded by #189 — the branch was renamed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
Replaces the shipped plain-CSS/JSX Workbench (
frontend/) with a React 18 + TypeScript + Vite + Tailwind + shadcn/Radix single-page app, wired to the real OpenKB REST API, with an Apple-design material/motion pass, light-default / dark-auto theming, and 中文 / English i18n. Adds the backend endpoints and runtime-config plumbing the new UI needs.86 commits · 170 files · +21k / −4k. Squash-merge intended.
Frontend
/deck/skill/visualize), KB list with a real create-KB flow, KB detail (card-nav Overview: Index / Concepts / Entities / Summaries / Reports / Documents; opensindex.mdlike a real wiki), per-KB settings gear.output/**.htmlopen in a sandboxed-iframe side panel (blob URL + bearer, never a token in a URL); chat shows compact "open" cards.[[wikilink|alias]], LaTeX math via KaTeX (bundled / self-contained), and---rules.motion),prefers-reduced-motion/-transparency, size-specific typography; a11y (Radix modal semantics for the settings sheet, labeled complementary region for the panel).check-i18n.mjs) that fails on leftover UI CJK or zh/en key-set drift.Backend
entitiesadded toGET /api/v1/list(+get_kb_list).GET /api/v1/graph/html(self-contained graph),GET /api/v1/output(path-guarded,output/-only HTML sink),GET/PATCH /api/v1/config(global defaults + credentials).resolve_effective_config(kb_dir)layers defaults →~/.config/openkb/global.yaml→ KB.openkb/config.yamlfor the global scalars, migrated across theload_configcall-sites; RFC-7386 merge-patch with null-removal that preserves inheritance.artifactSSE event on awrite_fileofoutput/**.html); per-turn trace persistence (ChatSession.assistant_traces), recording only read-tool calls so large generated file contents never hit the session JSON or the restore wire.~/.config/openkb/.env(0o600, atomic, under the global-config lock; the API key value is never returned by GET nor logged).Testing
uv run pytest -q→ 1175 passed;ruff check/ruff formatclean.npm run build(tsc + vite) + thei18n:checkguard green.---rules, settings credentials, artifact panel).Notes
global.yaml/ per-KBconfig.yaml/.env), not startup input.OPENKB_API_TOKEN) — intended for local use.https://claude.ai/code/session_01XMxbhmAkxxVV8CFWCZDBaG