Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(composer): richer message composer — taller input/queue + image & file attachments

Chaitanya Giri06bfc8a30b6c
diff --git a/src/main/index.ts b/src/main/index.ts
index fe9035d3..d96e3b49 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1727,6 +1727,43 @@ ipcMain.handle('kg:addFiles', async (evt) => {
return { ok: true as const, results };
});
+// ─── IPC: composer attachments (images + arbitrary files, attached by PATH) ──
+// The message queue pipes raw text into a Claude CLI PTY, so attachments travel
+// as a file PATH the agent reads with its Read tool (same convention as Slack).
+// Picker offers an Images group + All Files.
+ipcMain.handle('dialog:attachFiles', async (evt) => {
+ const win = BrowserWindow.fromWebContents(evt.sender);
+ if (!win) return { ok: false as const, error: 'no window' };
+ const res = await dialog.showOpenDialog(win, {
+ properties: ['openFile', 'multiSelections'],
+ title: 'Attach images or files',
+ filters: [
+ { name: 'Images', extensions: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg', 'heic', 'tiff', 'avif'] },
+ { name: 'All Files', extensions: ['*'] }
+ ]
+ });
+ if (res.canceled || res.filePaths.length === 0) return { ok: false as const, error: 'cancelled' };
+ return { ok: true as const, files: res.filePaths.map((p) => ({ path: p, name: basename(p) })) };
+});
+
+// Persist the current native clipboard image to a temp PNG so a pasted
+// screenshot can be attached by PATH. Returns an error result when the
+// clipboard holds no image (e.g. a normal text paste).
+ipcMain.handle('clipboard:saveImage', async () => {
+ try {
+ const img = clipboard.readImage();
+ if (img.isEmpty()) return { ok: false as const, error: 'no image in clipboard' };
+ const dir = join(app.getPath('temp'), 'cth-pastes');
+ mkdirSync(dir, { recursive: true });
+ const name = `paste-${Date.now()}.png`;
+ const dest = join(dir, name);
+ writeFileSync(dest, img.toPNG());
+ return { ok: true as const, file: { path: dest, name } };
+ } catch (e) {
+ return { ok: false as const, error: e instanceof Error ? e.message : String(e) };
+ }
+});
+
// ─── IPC: command history (SQLite — every prompt submitted to an agent) ──────
ipcMain.handle('history:add', (_evt, payload: unknown) => {
const p = (payload ?? {}) as { agentId?: unknown; cwd?: unknown; text?: unknown };
diff --git a/src/preload/index.ts b/src/preload/index.ts
index f596f8a7..57b1e3d2 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -1,4 +1,4 @@
-import { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron';
+import { contextBridge, ipcRenderer, webUtils, type IpcRendererEvent } from 'electron';
import type { AgentProvider } from '../shared/agentProvider';
// Injected at build time from package.json (see electron.vite.config.ts).
@@ -467,6 +467,18 @@ const api = {
kgIngestFiles: (paths: string[], tags?: string[]): Promise<KnowledgeIngestResult> =>
ipcRenderer.invoke('kg:ingestFiles', { paths, tags }),
+ // ─── Composer attachments (images + files, sent to agents by PATH) ─────────
+ /** Open an OS picker for images/files; returns chosen absolute paths + names. */
+ attachFiles: (): Promise<
+ { ok: true; files: { path: string; name: string }[] } | { ok: false; error: string }
+ > => ipcRenderer.invoke('dialog:attachFiles'),
+ /** Resolve a dropped File's absolute path (Electron 32 removed File.path). */
+ pathForFile: (file: File): string => webUtils.getPathForFile(file),
+ /** Write the current clipboard image to a temp PNG and return its path (paste-to-attach). */
+ saveClipboardImage: (): Promise<
+ { ok: true; file: { path: string; name: string } } | { ok: false; error: string }
+ > => ipcRenderer.invoke('clipboard:saveImage'),
+
// ─── Command history (SQLite — every prompt submitted to an agent) ─────────
/** Record one submitted prompt. Fire-and-forget from the prompt-detection hook. */
historyAdd: (entry: { agentId: string; cwd?: string; text: string }): Promise<{ ok: boolean; error?: string }> =>
diff --git a/src/renderer/src/components/MessageQueueComposer.tsx b/src/renderer/src/components/MessageQueueComposer.tsx
index b93f1945..5cca56d6 100644
--- a/src/renderer/src/components/MessageQueueComposer.tsx
+++ b/src/renderer/src/components/MessageQueueComposer.tsx
@@ -1,4 +1,4 @@
-import { KeyboardEvent, useState } from 'react';
+import { ClipboardEvent, DragEvent, KeyboardEvent, useState } from 'react';
import { PixelButton } from './PixelButton';
import { Icon } from './Icon';
import { useStore, type Agent, type QueuedMessage } from '@/store/store';
@@ -6,6 +6,12 @@ import { freeflowRecorder, useFreeflow } from '@/freeflow/recorder';
const EMPTY_QUEUE: QueuedMessage[] = [];
+/** A file/image attached to the draft. Travels to the agent as a PATH it Reads. */
+interface Attachment {
+ path: string;
+ name: string;
+}
+
// Prepended (only to the enqueued value, never the visible draft) when the
// god/Michael agent has the "Delegate to agents" toggle ON.
const DELEGATE_PREFIX =
@@ -53,11 +59,78 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {
// Only the god/Michael agent gets the delegation toggle. Default OFF.
const [delegate, setDelegate] = useState(false);
+ // Files/images staged for the next message. Component-local: switching agents
+ // remounts this component, so attachments are cleared on tab switch (drafts
+ // persist in the store, attachments deliberately don't carry over).
+ const [attachments, setAttachments] = useState<Attachment[]>([]);
+ const [dragOver, setDragOver] = useState(false);
+
+ const addAttachments = (incoming: Attachment[]) =>
+ setAttachments((prev) => {
+ const seen = new Set(prev.map((a) => a.path));
+ const fresh = incoming.filter((a) => a.path && !seen.has(a.path));
+ return fresh.length ? [...prev, ...fresh] : prev;
+ });
+
+ const removeAttachment = (path: string) =>
+ setAttachments((prev) => prev.filter((a) => a.path !== path));
+
+ // '+' button → OS picker (images group + all files).
+ const pickFiles = async () => {
+ const res = await window.cth.attachFiles();
+ if (res.ok) addAttachments(res.files);
+ };
+
+ // Drop files onto the composer → resolve each to its absolute path.
+ const onDrop = (e: DragEvent<HTMLDivElement>) => {
+ e.preventDefault();
+ setDragOver(false);
+ const dropped = Array.from(e.dataTransfer?.files ?? []);
+ if (!dropped.length) return;
+ const atts = dropped
+ .map((f) => ({ path: window.cth.pathForFile(f), name: f.name }))
+ .filter((a) => a.path);
+ if (atts.length) addAttachments(atts);
+ };
+
+ // Paste a screenshot (no path → persist the native clipboard image to a temp
+ // file) or paste files copied from the OS file manager (carry a real path).
+ const onPaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {
+ const items = Array.from(e.clipboardData?.items ?? []);
+ const hasImage = items.some((it) => it.kind === 'file' && it.type.startsWith('image/'));
+ if (hasImage) {
+ e.preventDefault();
+ const res = await window.cth.saveClipboardImage();
+ if (res.ok) addAttachments([res.file]);
+ return;
+ }
+ const files = Array.from(e.clipboardData?.files ?? []);
+ if (files.length) {
+ const atts = files
+ .map((f) => ({ path: window.cth.pathForFile(f), name: f.name }))
+ .filter((a) => a.path);
+ if (atts.length) {
+ e.preventDefault();
+ addAttachments(atts);
+ }
+ }
+ };
+
+ const canSend = !!text.trim() || attachments.length > 0;
+
const queueIt = () => {
- if (!text.trim()) return;
- const out = delegate ? DELEGATE_PREFIX + text : text;
+ if (!canSend) return;
+ // Prepend an "Attached files:" block using the same path-based convention as
+ // the Slack inbound path (useHive.ts) so agents Read the files directly.
+ const body = attachments.length
+ ? (text.trim()
+ ? `${text}\n\nAttached files:\n`
+ : 'Attached files:\n') + attachments.map((a) => `- ${a.path} (${a.name})`).join('\n')
+ : text;
+ const out = delegate ? DELEGATE_PREFIX + body : body;
enqueueMessage(agent.id, out);
setText('');
+ setAttachments([]);
};
const onKey = (e: KeyboardEvent<HTMLTextAreaElement>) => {
@@ -74,15 +147,30 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {
: `${agent.name} is busy — ${queue.length} queued`;
return (
- <div style={{
- flexShrink: 0,
- borderTop: '1px solid var(--cth-ink-700)',
- background: 'var(--cth-cream-100)',
- display: 'flex',
- flexDirection: 'column',
- gap: 6,
- padding: 8
- }}>
+ <div
+ onDragOver={(e) => { e.preventDefault(); if (!dragOver) setDragOver(true); }}
+ onDragLeave={(e) => {
+ // Only clear when the cursor actually leaves the composer, not on child enter.
+ if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;
+ setDragOver(false);
+ }}
+ onDrop={onDrop}
+ style={{
+ flexShrink: 0,
+ borderTop: '1px solid var(--cth-ink-700)',
+ background: 'var(--cth-cream-100)',
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 6,
+ padding: 8,
+ boxShadow: dragOver ? 'inset 0 0 0 2px var(--cth-lilac)' : undefined
+ }}>
+ {dragOver && (
+ <span style={{
+ fontFamily: 'var(--cth-font-display)', fontSize: 9, lineHeight: '12px',
+ color: 'var(--cth-ink-700)', textAlign: 'center'
+ }}>DROP TO ATTACH</span>
+ )}
{/* Header: label, count, status, clear-all */}
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<span style={{
@@ -123,7 +211,7 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {
{queue.length > 0 && (
<div style={{
display: 'flex', flexDirection: 'column', gap: 4,
- maxHeight: 132, overflowY: 'auto'
+ maxHeight: 280, overflowY: 'auto'
}}>
{queue.map((m, i) => (
<div key={m.id} style={{
@@ -172,17 +260,56 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {
}}>{ffHint}</span>
)}
+ {/* Attached files/images — chips with a remove 'x', above the textarea. */}
+ {attachments.length > 0 && (
+ <div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
+ {attachments.map((a) => (
+ <span
+ key={a.path}
+ title={a.path}
+ style={{
+ display: 'inline-flex', alignItems: 'center', gap: 4,
+ maxWidth: '100%',
+ padding: '2px 4px 2px 6px',
+ background: 'var(--cth-cream-200)',
+ boxShadow: 'inset 0 0 0 1px var(--cth-ink-700)',
+ fontFamily: 'var(--cth-font-mono)', fontSize: 12, lineHeight: '16px',
+ color: 'var(--cth-ink-900)'
+ }}
+ >
+ <Icon name="folder" />
+ <span style={{
+ overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', maxWidth: 180
+ }}>{a.name}</span>
+ <button
+ onClick={() => removeAttachment(a.path)}
+ title="Remove attachment"
+ style={{
+ flexShrink: 0, border: 'none', background: 'transparent', cursor: 'pointer',
+ color: 'var(--cth-ink-500)', padding: 0,
+ display: 'inline-flex', alignItems: 'center'
+ }}
+ >
+ <Icon name="x" />
+ </button>
+ </span>
+ ))}
+ </div>
+ )}
+
{/* Composer */}
<div style={{ display: 'flex', gap: 6, alignItems: 'flex-end' }}>
<textarea
value={text}
onChange={(e) => setText(e.target.value)}
onKeyDown={onKey}
- rows={2}
+ onPaste={onPaste}
+ rows={5}
placeholder={idle ? `Message ${agent.name}` : `${agent.name} is busy — queue a message`}
style={{
flex: 1,
- resize: 'none',
+ resize: 'vertical',
+ minHeight: 96, maxHeight: 320,
padding: '6px 8px',
background: 'var(--cth-paper-100)',
border: 'none',
@@ -193,13 +320,18 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {
outline: 'none'
}}
/>
- {/* Right column: Delegate toggle (god only) + Free Flow mic stacked ABOVE Send. */}
+ {/* Right column: Delegate toggle (god only) + Attach + Free Flow mic ABOVE Send. */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, alignItems: 'stretch' }}>
{agent.isGod && (
<DelegateSwitch on={delegate} onToggle={() => setDelegate((d) => !d)} />
)}
+ <PixelButton variant="secondary" size="md" onClick={pickFiles}>
+ <span style={{ display: 'inline-flex', gap: 6, alignItems: 'center' }}>
+ <Icon name="plus" /> files
+ </span>
+ </PixelButton>
{freeflowEnabled && <FreeFlowButton agentId={agent.id} />}
- <PixelButton variant="primary" size="md" onClick={queueIt} disabled={!text.trim()}>
+ <PixelButton variant="primary" size="md" onClick={queueIt} disabled={!canSend}>
<span style={{ display: 'inline-flex', gap: 6, alignItems: 'center' }}>
send <Icon name="arrow-right" />
</span>