Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ opt-level = 2
# `TriggerCompletion` (Ctrl+Space) and has a menu opened that way follow its word as it grows
# (`handle_completion_trigger` in src/input/editor/lsp/completions.rs). It also makes `has_multiple_cursors`, `select_range`
# and `replace_range` public, which the line actions (src/app/line_actions.rs) edit through, and makes a drag that began
# with a double click select whole words (`snap_to_word_edge` in src/input/base/selection.rs).
# with a double click select whole words (`snap_to_word_edge` in src/input/base/selection.rs). `SelectableText::runs` lets
# a card's text keep its styling while selectable.
[patch.crates-io]
gpui-base = { path = "vendor/gpui-base" }

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Claudiu is a native desktop app, written in Rust with [GPUI](https://gpui.rs), t

Each session is your own `claude` process in a real pseudo-terminal, so Claude Code's keys, mouse and paste work unchanged. Claudiu has no API keys and never calls the Anthropic API. Sign-in stays with Claude Code. The first launch opens a setup window that checks for `claude` (required) and `gh` (optional), links to their install pages and installs nothing. Settings has a Check setup button to open it again. A sidebar lists your projects and sessions. Ended sessions resume through `claude --resume`, and sessions that were running come back at the next start.

Around the terminal, Claudiu adds an editor mode (Ctrl+Shift+E) with files, tabs, search, Git change marks and language-server diagnostics, definitions and completion. It also adds usage and context meters, a GitHub pane for issues and pull requests through your `gh` login, defaults for the model, effort and permission mode of new sessions, and extra Claude accounts that share one configuration. A session can move between git worktrees the way it switches branches, so several agents work on separate branches at once: the worktree button in the top bar switches the shown session into another worktree, or into a new one that Claudiu makes on a branch you name, and its conversation continues there. Its hover x removes a worktree, the branch button's x deletes a local branch after telling you which commits would be lost, and ending the last session in a worktree offers to remove it. Claudiu keeps the worktrees it makes in its own data folder, outside your repositories, so they never show up in `git status`; Settings has a Worktrees page that lists them to show in the file manager or remove. Settings lists the rest.
Around the terminal, Claudiu adds an editor mode (Ctrl+Shift+E) with files, tabs, search, Git change marks and language-server diagnostics, definitions and completion. It also adds usage and context meters, a GitHub pane for issues and pull requests through your `gh` login, defaults for the model, effort and permission mode of new sessions, and extra Claude accounts that share one configuration. When a reply needs a table, chart or diagram, Claude draws it as a card inside the terminal, under the tool call, and the card scrolls with the transcript. Cards can hold buttons that send a message for you, collapsible sections, tabs and charts, and they come back when you reopen a session. A session can move between git worktrees the way it switches branches, so several agents work on separate branches at once: the worktree button in the top bar switches the shown session into another worktree, or into a new one that Claudiu makes on a branch you name, and its conversation continues there. Its hover x removes a worktree, the branch button's x deletes a local branch after telling you which commits would be lost, and ending the last session in a worktree offers to remove it. Claudiu keeps the worktrees it makes in its own data folder, outside your repositories, so they never show up in `git status`; Settings has a Worktrees page that lists them to show in the file manager or remove. Settings lists the rest.

Ctrl+Shift (Cmd+Shift on macOS) plus a letter drives the app. Everything else reaches Claude Code. Editor mode finds `rust-analyzer`, `tsc --lsp` and `gleam` on your PATH and installs nothing.

Expand Down
92 changes: 67 additions & 25 deletions mod/hooks/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
// reference into Claude's input box; that is not done here.)
// - Usage and status: reports context, the 5-hour and 7-day limits, auto-compact, background compaction, advisor and
// the last command to `CLAUDIU_USAGE_DIR/<claude session id>.json`. No tokens are spent.
// - Visual panel: answers `show_visual` in-process and, while the model is still writing the call, streams its
// Markdown to `CLAUDIU_VISUAL_FILE` so the panel fills live.
// - Cards: answers `show_visual` in-process and, while the model is still writing the call, streams its Markdown to
// `CLAUDIU_VISUAL_PREFIX<call>.json`. Under each call it reserves rows, each with a link naming the call, and Claudiu
// paints the live card over them. Claudiu's measured height comes back in `CLAUDIU_VISUAL_PREFIX<call>.rows`.
// - One-shot completions: runs requests from `CLAUDIU_ASK_FILE` (commit messages, session titles) with
// `$.model.complete`, on this session's own client, so Claudiu needs no `claude -p`.

Expand All @@ -27,6 +28,7 @@ const MODELS = {
opus: 'claude-opus-5-5',
fable: 'claude-fable-5-1',
}
const CARD_ROWS = 6 // reserved for a card until Claudiu has measured it
const PROMPT_MAX = 20000 // characters of a message Claudiu asks the session to send (the editor's Ask Claude)
const EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max']
const ASK_MODELS = ['haiku', 'sonnet', 'opus']
Expand All @@ -46,6 +48,9 @@ let pendingAdvisor = null // an advisor change Claude Code refused (see setAdvis
let askPoll // watches CLAUDIU_ASK_FILE
let askSeen = null // id of the last request looked at
let asking = false // a completion is running; a poll that finds another request waits for it
const cardRows = new Map() // show_visual call id -> rows reserved for its card
const published = new Set() // call ids whose card file this process wrote from the transcript
let rowsPoll // watches the heights Claudiu measures
let visualChain = Promise.resolve() // visual writes in order, without holding up the stream
let lastVisual = null // id of the show_visual call being written, or last written

Expand Down Expand Up @@ -272,16 +277,10 @@ function partialString(json, key) {
return out
}

// Queues a write of the Visual panel's file. Writes run one after another, and a failed one is dropped.
function writeVisual($, file, call, title, content, done) {
const body = JSON.stringify({
call,
title: String(title ?? '').slice(0, 80),
content: String(content ?? '').slice(0, 200_000),
done,
at: Date.now(),
})
visualChain = visualChain.then(() => $.fs.write(file, body)).catch(() => {})
// Queues a write of a card's file. Writes run one after another, and a failed one is dropped.
function writeVisual($, prefix, call, content) {
const body = JSON.stringify({ call, content: String(content ?? '').slice(0, 200_000) })
visualChain = visualChain.then(() => $.fs.write(`${prefix}${call}.json`, body)).catch(() => {})
}

// ---- One-shot completions -----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -439,27 +438,27 @@ async function onSetModel($, e) {
}
}

// The model's show_visual call streams to the Visual panel while it is written. The call's arguments arrive as pieces
// of JSON; the Markdown read out of them so far goes to the file a few times a second at most. The tool.call hook
// writes the finished card.
// The model's show_visual call streams to its card while it is written. The call's arguments arrive as pieces of JSON;
// the Markdown read out of them so far goes to the file a few times a second at most. The tool.call hook writes the
// finished card.
async function onShowVisual($, e) {
const file = await $.env.get('CLAUDIU_VISUAL_FILE')
if (!file) {
return { result: "The Visual panel isn't available in this session (Claudiu's mod has no file for it).", isError: true }
const prefix = await $.env.get('CLAUDIU_VISUAL_PREFIX')
if (!prefix) {
return { result: "Visuals aren't available in this session (Claudiu's mod has no file for them).", isError: true }
}
if (typeof e.content !== 'string' || !e.content.trim()) return { result: 'content must be non-empty Markdown.', isError: true }
writeVisual($, file, e.tool_use_id ?? lastVisual ?? 'v' + Date.now(), e.title, e.content, true)
return { result: "Shown in Claudiu's Visual panel. Say the key facts in a short reply; don't repeat the content." }
writeVisual($, prefix, e.tool_use_id ?? lastVisual ?? 'v' + Date.now(), e.content)
return { result: "Shown inline in the terminal. Say the key facts in a short reply; don't repeat the content." }
}

// Applies the saved model and effort to this turn's steps, and streams a show_visual call to the Visual panel while
// the model writes it. Sub-agent steps are left alone.
// Applies the saved model and effort to this turn's steps, and streams a show_visual call to its card while the model
// writes it. Sub-agent steps are left alone.
async function* onTurnStep($, e, next) {
const step = !e.agentId && (want.model || want.effort)
? { ...e, model: want.model ?? e.model, effort: want.effort ?? e.effort }
: e
const file = e.agentId ? null : await $.env.get('CLAUDIU_VISUAL_FILE')
if (!file) return yield* next(step)
const prefix = e.agentId ? null : await $.env.get('CLAUDIU_VISUAL_PREFIX')
if (!prefix) return yield* next(step)

const open = new Map() // block index -> the show_visual call being written there
for await (const c of next(step)) {
Expand All @@ -471,13 +470,52 @@ async function* onTurnStep($, e, next) {
v.json += c.json
if (Date.now() - v.at >= 150) {
v.at = Date.now()
writeVisual($, file, v.id, partialString(v.json, 'title'), partialString(v.json, 'content'), false)
writeVisual($, prefix, v.id, partialString(v.json, 'content'))
}
}
yield c
}
}

// Draws a show_visual call as its title and the rows its card covers. Each row's link names the call and the row, which
// is how Claudiu finds them on screen, and the rows scroll and clip with the transcript. Drawing a call from an earlier
// process writes its card again from the transcript: that is what brings cards back after a restart.
async function onVisualRow($, e, next) {
if (e.props.tool !== VISUAL_TOOL || e.props.isErrored) return next(e)
const { Box, Link, Text } = $.ui.resolve(e)
const id = e.props.tool_use_id
if (!cardRows.has(id)) cardRows.set(id, CARD_ROWS)
if (!e.props.isRunning && !published.has(id) && e.props.input?.content) {
published.add(id)
const prefix = await $.env.get('CLAUDIU_VISUAL_PREFIX')
if (prefix) writeVisual($, prefix, id, e.props.input.content)
}
const links = Array.from({ length: cardRows.get(id) }, (_, i) =>
h(Link, { key: String(i), href: `claudiu://visual/${id}/${i}` }, ' '.repeat(16)))
return h(Box, { flexDirection: 'column' }, h(Text, { dimColor: true }, String(e.props.input?.title ?? 'Visual')), ...links)
}

// Claude Code folds MCP calls into one count line, which would hide a card's rows.
function onVisualGroup($, e, next) {
if (!e.props.calls.some(c => c.tool === VISUAL_TOOL)) return next(e)
return next({ ...e, props: { ...e.props, isExpanded: true } })
}

// Reserves the rows Claudiu measured for each card drawn in this process.
async function readCardRows($) {
const prefix = await $.env.get('CLAUDIU_VISUAL_PREFIX')
if (!prefix) return
let changed = false
for (const [id, rows] of [...cardRows]) {
const measured = parseInt(await $.fs.read(`${prefix}${id}.rows`).catch(() => ''), 10)
if (measured > 0 && measured !== rows) {
cardRows.set(id, measured)
changed = true
}
}
if (changed) $.ui.invalidate('ui.render')
}

async function onSessionStart($, e, next) {
const r = await next(e)
await report($)
Expand All @@ -487,6 +525,8 @@ async function onSessionStart($, e, next) {
ctlPoll = $.clock.every(1000, () => applyCtl($))
askPoll?.cancel()
askPoll = $.clock.every(500, () => answerAsk($))
rowsPoll?.cancel()
rowsPoll = $.clock.every(200, () => readCardRows($))
await watchSessionName($)
return r
}
Expand All @@ -498,6 +538,8 @@ export function register(on) {
on('session.compact', onSessionCompact)
on('tool.call', { tool: 'mcp__claudiu__set_model' }, onSetModel)
on('tool.call', { tool: VISUAL_TOOL }, onShowVisual)
on('ui.render', { component: 'ToolUse' }, onVisualRow)
on('ui.render', { component: 'ToolGroup' }, onVisualGroup)
on('turn.step', onTurnStep)
on('session.start', onSessionStart)
}
33 changes: 25 additions & 8 deletions mod/hooks/visual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const TOOL = 'mcp__claudiu__show_visual'
const STEP = { turnId: 't', index: 0, answer: '', toolUses: [], stopReason: 'tool_use' as const, usage: null }

test('streams the Markdown of a show_visual call while it is written, then writes the finished card', async ($, on) => {
mock.env(on, { CLAUDIU_VISUAL_FILE: 'visual/s.json' })
mock.env(on, { CLAUDIU_VISUAL_PREFIX: 'visual/s--' })
const writes: { path: string; card: any }[] = []
on('fs.write', (_$, e) => {
writes.push({ path: e.path, card: JSON.parse(e.text) })
Expand All @@ -24,26 +24,23 @@ test('streams the Markdown of a show_visual call while it is written, then write

expect(writes.length).toBeGreaterThanOrEqual(1)
const first = writes[0]!
expect(first.path.replace(/\\/g, '/').endsWith('visual/s.json')).toBe(true) // Windows paths use backslashes
expect(first.path.replace(/\\/g, '/').endsWith('visual/s--toolu_1.json')).toBe(true) // Windows paths use backslashes
expect(first.card.call).toBe('toolu_1')
expect(first.card.done).toBe(false)
expect(first.card.title).toBe('Pla')

const result = await $.tool.call({ tool: TOOL, tool_use_id: 'toolu_1', title: 'Plan', content: '# Hi\n\nsome **bold** é' })
expect(result.isError).toBeFalsy()
const last = writes.at(-1)!.card
expect(last).toMatchObject({ call: 'toolu_1', title: 'Plan', content: '# Hi\n\nsome **bold** é', done: true })
expect(writes.at(-1)!.card).toEqual({ call: 'toolu_1', content: '# Hi\n\nsome **bold** é' })
})

test('refuses an empty card and says so when Claudiu gave no file', async ($, on) => {
mock.env(on, { CLAUDIU_VISUAL_FILE: 'visual/s.json' })
mock.env(on, { CLAUDIU_VISUAL_PREFIX: 'visual/s--' })
on('fs.write', () => ({ value: undefined }))
const empty = await $.tool.call({ tool: TOOL, tool_use_id: 'x', content: ' ' })
expect(empty.isError).toBe(true)
})

test('other tools and subagents are not streamed', async ($, on) => {
mock.env(on, { CLAUDIU_VISUAL_FILE: 'visual/s.json' })
mock.env(on, { CLAUDIU_VISUAL_PREFIX: 'visual/s--' })
let writes = 0
on('fs.write', () => {
writes += 1
Expand All @@ -58,3 +55,23 @@ test('other tools and subagents are not streamed', async ($, on) => {
for await (const _ of $.turn.step({ turnId: 't', index: 0, model: 'm', messageCount: 1, agentId: 'sub' })) void _
expect(writes).toBe(0)
})

const ROW = { tool: TOOL, tool_use_id: 'toolu_9', input: { title: 'Plan', content: '# Old card' }, isRunning: false, isErrored: false, isInterrupted: false }
const MOUNT = { plugin: 'Claudiu', surface: 'terminal' as const, component: 'ToolUse' as const, requestId: 'toolu_9', props: ROW }

test('a drawn call reserves linked rows and writes its card back from the transcript', async ($, on) => {
mock.env(on, { CLAUDIU_VISUAL_PREFIX: 'visual/s--' })
const writes: { path: string; text: string }[] = []
on('fs.write', (_$, e) => {
writes.push({ path: e.path, text: e.text })
return { value: undefined }
})
const ui = await $.ui.mount(MOUNT)
const link = await ui.find({ type: 'Link' })
expect(link?.props?.href).toBe('claudiu://visual/toolu_9/0')
expect((await ui.find({ type: 'Text', text: /Plan/ }))?.text).toBe('Plan')
await ui.unmount()
await new Promise(done => setTimeout(done, 10))
const card = writes.find(w => w.path.includes('toolu_9'))
expect(JSON.parse(card!.text)).toEqual({ call: 'toolu_9', content: '# Old card' })
})
22 changes: 7 additions & 15 deletions src/app/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,15 @@ fn sessions_and_shell() {
assert_eq!(ws.left_width(700.0), SIDEBAR_MIN, "keeps room for the session in a small window");
ws.left_drag = None;
});
// The Visual panel: the first card a session's model draws opens it (wide, sharing GitHub's width), the same call
// keeps filling its card without reopening it, and a card for a session that is not shown only lists it.
// A card reaches the terminal of its session, and a card for a session that is not running is dropped.
let shown = ws.read_with(&cx, |ws, _| ws.active.clone().unwrap());
let stem = datadir::safe_file_stem(&shown);
let card = |content: &str, done: bool| crate::visual::Card { call: "c1".into(), title: "Plan".into(), content: content.into(), done };
assert!(ws.read_with(&cx, |ws, _| !ws.visual_shown()));
step(&mut cx, &|ws, _w, cx| ws.apply_visuals(vec![(stem.clone(), card("# Hi", false))], cx));
assert!(ws.read_with(&cx, |ws, _| ws.visual_shown() && ws.right_gh.is_none()), "a new card opens the panel");
assert_eq!(ws.read_with(&cx, |ws, _| ws.right_width(1600.0)), RIGHT_GH_W);
step(&mut cx, &|ws, _w, cx| ws.hide_visual(false, cx));
step(&mut cx, &|ws, _w, cx| ws.apply_visuals(vec![(stem.clone(), card("# Hi there", true))], cx));
assert!(ws.read_with(&cx, |ws, _| !ws.visual_shown() && ws.visual_cards().len() == 1 && ws.visual_cards()[0].done), "the same call updates its card and leaves the panel shut");
assert_eq!(ws.read_with(&cx, |ws, _| ws.right_width(1600.0)), RIGHT_MENU_W + 40.0);
step(&mut cx, &|ws, _w, cx| ws.show_visual(cx));
assert!(ws.read_with(&cx, |ws, _| ws.visual_shown()));
step(&mut cx, &|ws, _w, cx| ws.hide_visual(true, cx));
assert!(ws.read_with(&cx, |ws, _| ws.visual_cards().is_empty() && !ws.visual_shown()), "clearing forgets the cards");
let card = |call: &str| crate::visual::Card { call: call.into(), content: "# Hi".into() };
step(&mut cx, &|ws, _w, cx| ws.apply_visuals(vec![(stem.clone(), card("c1")), ("no-such-session".into(), card("c2"))], cx));
assert!(ws.read_with(&cx, |ws, cx| {
let view = ws.live_view(&shown).unwrap().read(cx);
view.has_card("c1") && !view.has_card("c2")
}));
step(&mut cx, &|ws, w, cx| ws.open_github(cwd.clone(), w, cx));
assert!(ws.read_with(&cx, |ws, _| ws.gh.len() == 1 && ws.right_gh.is_some()), "github shown in the right sidebar");
assert_eq!(ws.read_with(&cx, |ws, _| ws.right_width(1600.0)), RIGHT_GH_W, "GitHub keeps its own width");
Expand Down
4 changes: 2 additions & 2 deletions src/app/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl Workspace {
cx.notify();
}

/// GitHub and the Visual panel are read and written in, so they share one wider, resizable width.
/// GitHub is read and written in, so it gets a wider, resizable width.
fn right_wide(&self) -> bool {
self.right_gh.is_some() || self.visual_shown()
self.right_gh.is_some()
}

/// The right sidebar's current width: the remembered one for the menu or for GitHub, kept within bounds.
Expand Down
Loading
Loading