@honcho-ai/claude-honcho 0.3.4 → 0.4.1

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.
Files changed (36) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +113 -333
  3. package/dist/hooks/save-user-message.js +1721 -1066
  4. package/dist/hooks/save-user-message.js.map +24 -19
  5. package/dist/hooks/session-end.js +556 -633
  6. package/dist/hooks/session-end.js.map +11 -9
  7. package/dist/hooks/session-start.js +1922 -1319
  8. package/dist/hooks/session-start.js.map +31 -22
  9. package/dist/hooks/stop.js +1742 -1160
  10. package/dist/hooks/stop.js.map +25 -20
  11. package/dist/hooks/user-prompt.js +689 -16616
  12. package/dist/hooks/user-prompt.js.map +13 -90
  13. package/dist/mcp-server.js +1595 -1612
  14. package/dist/mcp-server.js.map +23 -20
  15. package/dist/skills/backfill-runner.js +1816 -919
  16. package/dist/skills/backfill-runner.js.map +27 -21
  17. package/dist/skills/{setup-runner.js → pane-runner.js} +1902 -1030
  18. package/dist/{hooks/pre-compact.js.map → skills/pane-runner.js.map} +28 -24
  19. package/dist/skills/status-runner.js +1567 -761
  20. package/dist/skills/status-runner.js.map +23 -19
  21. package/hooks/hooks.json +4 -48
  22. package/hooks/register.tsx +576 -0
  23. package/package.json +1 -1
  24. package/skills/insights/SKILL.md +3 -7
  25. package/dist/hooks/post-tool-use.js +0 -16924
  26. package/dist/hooks/post-tool-use.js.map +0 -97
  27. package/dist/hooks/pre-compact.js +0 -17111
  28. package/dist/hooks/pre-tool-honcho.js +0 -869
  29. package/dist/hooks/pre-tool-honcho.js.map +0 -16
  30. package/dist/skills/setup-runner.js.map +0 -96
  31. package/scripts/honcho-statusline.sh +0 -101
  32. package/skills/briefing/SKILL.md +0 -20
  33. package/skills/config/SKILL.md +0 -288
  34. package/skills/import/SKILL.md +0 -73
  35. package/skills/setup/SKILL.md +0 -60
  36. package/skills/status/SKILL.md +0 -30
package/hooks/hooks.json CHANGED
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "description": "Honcho memory hooks for Claude Code sessions",
3
+ "modules": [
4
+ "./register.tsx"
5
+ ],
3
6
  "hooks": {
4
7
  "SessionStart": [
5
8
  {
@@ -28,38 +31,13 @@
28
31
  ]
29
32
  }
30
33
  ],
31
- "PostToolUse": [
32
- {
33
- "matcher": "Write|Edit|Bash|Task",
34
- "hooks": [
35
- {
36
- "type": "command",
37
- "command": "node \"${CLAUDE_PLUGIN_ROOT}/dist/hooks/post-tool-use.js\"",
38
- "timeout": 10,
39
- "async": true
40
- }
41
- ]
42
- }
43
- ],
44
- "PreToolUse": [
45
- {
46
- "matcher": "mcp__plugin_honcho_honcho__.*",
47
- "hooks": [
48
- {
49
- "type": "command",
50
- "command": "node \"${CLAUDE_PLUGIN_ROOT}/dist/hooks/pre-tool-honcho.js\"",
51
- "timeout": 4
52
- }
53
- ]
54
- }
55
- ],
56
34
  "UserPromptSubmit": [
57
35
  {
58
36
  "hooks": [
59
37
  {
60
38
  "type": "command",
61
39
  "command": "node \"${CLAUDE_PLUGIN_ROOT}/dist/hooks/user-prompt.js\"",
62
- "timeout": 125
40
+ "timeout": 10
63
41
  },
64
42
  {
65
43
  "type": "command",
@@ -70,28 +48,6 @@
70
48
  ]
71
49
  }
72
50
  ],
73
- "PreCompact": [
74
- {
75
- "matcher": "auto",
76
- "hooks": [
77
- {
78
- "type": "command",
79
- "command": "node \"${CLAUDE_PLUGIN_ROOT}/dist/hooks/pre-compact.js\"",
80
- "timeout": 20
81
- }
82
- ]
83
- },
84
- {
85
- "matcher": "manual",
86
- "hooks": [
87
- {
88
- "type": "command",
89
- "command": "node \"${CLAUDE_PLUGIN_ROOT}/dist/hooks/pre-compact.js\"",
90
- "timeout": 20
91
- }
92
- ]
93
- }
94
- ],
95
51
  "Stop": [
96
52
  {
97
53
  "hooks": [
@@ -0,0 +1,576 @@
1
+ import type { Register, EngineInterface, RenderChildren, UiPressArgument } from 'claude-code'
2
+
3
+ const PANE = 'honcho'
4
+ const HONCHO_TOOL = /^mcp__plugin_honcho_honcho__/
5
+ const VERBS: Record<string, string> = {
6
+ chat: 'asking', search: 'searching', create_conclusion: 'writing',
7
+ delete_conclusion: 'writing', list_conclusions: 'listing',
8
+ }
9
+
10
+ type Ref = { id: string; content: string | null; level?: string; status: string; removed_in_run?: string | null }
11
+ type Run = {
12
+ id: string; observer_id: string; observed_id: string; dream_type: string; trigger_reason: string
13
+ status: 'running' | 'completed' | 'failed' | 'interrupted'
14
+ created_count: number; removed_count: number; peer_card_updated: boolean
15
+ started_at: string; finished_at: string | null; pruned_at: string | null
16
+ }
17
+ type RunDetail = Run & {
18
+ created: { conclusion: Ref; sources: Ref[]; specialist?: string }[]
19
+ removed: { id: string; content: string | null; level?: string; replaced_by?: string | null }[]
20
+ peer_card: { before: string[] | null; after: string[] | null } | null
21
+ }
22
+ type Overview = {
23
+ session: string | null; sessionUrl: string | null; card: string[]
24
+ }
25
+ type Reply<T> = { ok: true; workspace: string; peer: string; origin: string; data: T } | { ok: false; status?: number; error: string }
26
+
27
+ // The running memory tool's verb, shown after the spinner word.
28
+ let activity: string | undefined
29
+ let noticeShown = false
30
+ let dreams: { loading: boolean; error?: string; runs: Run[]; peer?: string; workspace?: string; at?: number } = { loading: false, runs: [] }
31
+ let overview: { loading: boolean; error?: string; data?: Overview } = { loading: false }
32
+ // The Claude Code session the overview was loaded for; a new one (after /clear) reloads it.
33
+ let overviewFor: string | undefined
34
+ let detail: { loading: boolean; error?: string; run?: RunDetail } | undefined
35
+ let cardOpen = false
36
+
37
+ type SetupState = {
38
+ connected: boolean; canSignIn: boolean; auth: string | null
39
+ workspace: string | null; peer: string | null; transcripts: number
40
+ hasName: boolean; suggestedName: string; others: { host: string; peerName: string }[]
41
+ }
42
+ type SetupReply = { ok: boolean; error?: string; status?: string; url?: string; code?: string } & Partial<SetupState>
43
+ // Undefined until the first check at session start.
44
+ let connected: boolean | undefined
45
+ let setup: {
46
+ busy?: string; error?: string; state?: SetupState; done?: boolean
47
+ signIn?: { url: string; code: string }; askKey?: boolean; askName?: boolean
48
+ } | undefined
49
+ let poller: { cancel: () => void } | undefined
50
+ // Asked of the engine each time, never kept in a module variable: a reload resets
51
+ // module variables while the pane stays up, and the status-bar button, /honcho and
52
+ // the pane's own mark can each close it.
53
+ async function paneIsOpen($: EngineInterface): Promise<boolean> {
54
+ return (await $.ui.panes()).some((pane) => pane.id === PANE)
55
+ }
56
+
57
+ async function home($: EngineInterface): Promise<string> {
58
+ return (await $.env.get('HOME')) ?? ''
59
+ }
60
+
61
+ async function readJson<T>($: EngineInterface, path: string): Promise<T | undefined> {
62
+ try {
63
+ if (!(await $.fs.exists(path))) return undefined
64
+ const text = await $.fs.read(path)
65
+ return typeof text === 'string' ? (JSON.parse(text) as T) : undefined
66
+ } catch {
67
+ return undefined
68
+ }
69
+ }
70
+
71
+ // Written by the session hooks.
72
+ async function sessionInfo($: EngineInterface): Promise<{ name?: string; url?: string | null } | undefined> {
73
+ return readJson($, `${await home($)}/.honcho/session-${await $.session.id()}.json`)
74
+ }
75
+
76
+ // Runs one of src/skills/*-runner.ts: bundled JS when published, source in a checkout.
77
+ async function script($: EngineInterface, name: string, args: string[], timeoutMs: number, stdin?: string) {
78
+ const built = `${$.plugin.root}/dist/skills/${name}.js`
79
+ const argv = (await $.fs.exists(built))
80
+ ? ['node', built, ...args]
81
+ : ['bun', 'run', `${$.plugin.root}/src/skills/${name}.ts`, ...args]
82
+ return $.process.run(argv, { timeoutMs, stdin, env: { CLAUDE_CODE_SESSION_ID: await $.session.id() } })
83
+ }
84
+
85
+ async function runner($: EngineInterface, args: string[], stdin?: string): Promise<Reply<unknown>> {
86
+ try {
87
+ const { exitCode, stdout, stderr } = await script($, 'pane-runner', args, 30000, stdin)
88
+ if (exitCode !== 0) return { ok: false, error: (stderr || stdout).trim().slice(0, 300) }
89
+ return JSON.parse(stdout.trim().split('\n').pop() ?? '{}')
90
+ } catch (err) {
91
+ return { ok: false, error: String(err) }
92
+ }
93
+ }
94
+
95
+ function explain(r: { status?: number; error: string }): string {
96
+ if (r.status === 404) return 'Dream history is not available on this Honcho server yet.'
97
+ if (r.status === 401) return 'Honcho rejected your sign-in or API key. Run /honcho setup to connect again.'
98
+ if (r.status === 403) return 'Needs a workspace or admin key; peer-scoped keys are refused.'
99
+ let detail = r.error
100
+ try { detail = JSON.parse(r.error).detail ?? r.error } catch { /* not JSON */ }
101
+ if (r.status && r.status >= 500) return `Honcho server error (${r.status}): ${detail}. Try refresh in a minute.`
102
+ return detail
103
+ }
104
+
105
+ async function loadDreams($: EngineInterface): Promise<void> {
106
+ dreams = { ...dreams, loading: true, error: undefined }
107
+ $.ui.invalidate('ui.render')
108
+ const r = (await runner($, ['dreams-list'])) as Reply<{ items: Run[] }>
109
+ dreams = r.ok
110
+ ? { loading: false, runs: r.data?.items ?? [], peer: r.peer, workspace: r.workspace, at: Date.now() }
111
+ : { loading: false, runs: [], error: explain(r) }
112
+ $.ui.invalidate('ui.render')
113
+ }
114
+
115
+ async function loadOverview($: EngineInterface): Promise<void> {
116
+ overviewFor = await $.session.id()
117
+ overview = { ...overview, loading: true, error: undefined }
118
+ $.ui.invalidate('ui.render')
119
+ const r = (await runner($, ['overview'])) as { ok: boolean; status?: number; error?: string } & Overview
120
+ overview = r.ok ? { loading: false, data: r } : { loading: false, error: explain({ status: r.status, error: r.error ?? '' }) }
121
+ $.ui.invalidate('ui.render')
122
+ }
123
+
124
+ const loadAll = ($: EngineInterface) => Promise.all([loadOverview($), loadDreams($)])
125
+
126
+ async function loadDetail($: EngineInterface, id: string): Promise<void> {
127
+ detail = { loading: true }
128
+ $.ui.invalidate('ui.render')
129
+ const r = (await runner($, ['dreams-get', id])) as Reply<RunDetail>
130
+ detail = r.ok ? { loading: false, run: r.data } : { loading: false, error: explain(r) }
131
+ $.ui.invalidate('ui.render')
132
+ }
133
+
134
+ async function togglePane($: EngineInterface): Promise<string> {
135
+ if (await paneIsOpen($)) {
136
+ await $.ui.close({ id: PANE })
137
+ return 'Honcho pane closed.'
138
+ }
139
+ return openPane($)
140
+ }
141
+
142
+ async function openSetup($: EngineInterface): Promise<string> {
143
+ detail = undefined
144
+ cardOpen = false
145
+ setup = { busy: 'Checking your Honcho connection…' }
146
+ const opened = await $.ui.open({ id: PANE, title: 'Honcho setup' })
147
+ void (async () => {
148
+ const r = (await runner($, ['setup-state'])) as SetupReply
149
+ if (!r.ok) return setSetup($, { error: r.error })
150
+ const state = r as SetupState
151
+ if (!state.connected) return setSetup($, { state })
152
+ setSetup($, { busy: 'Checking your connection…', state })
153
+ finishSetup($, (await runner($, ['setup-connect'])) as SetupReply)
154
+ })()
155
+ return opened.isPlaced ? 'Honcho setup opened.' : `Honcho setup is waiting for room (${opened.reason}).`
156
+ }
157
+
158
+ function setSetup($: EngineInterface, next: NonNullable<typeof setup>): void {
159
+ setup = next
160
+ $.ui.invalidate('ui.render')
161
+ }
162
+
163
+ function finishSetup($: EngineInterface, r: SetupReply): void {
164
+ if (!r.ok) {
165
+ // The saved credential (or the one just entered) didn't work: offer the ways to connect again.
166
+ const state = setup?.state && { ...setup.state, connected: false }
167
+ return setSetup($, { ...setup, state, busy: undefined, signIn: undefined, error: r.error })
168
+ }
169
+ connected = true
170
+ const state = r as SetupState
171
+ if (state.hasName) return setSetup($, { state, done: true })
172
+ // First connection: ask what Honcho should call the user.
173
+ setSetup($, { state, askName: true })
174
+ void $.ui.open({ id: PANE, title: 'Honcho setup', focus: true })
175
+ .then(() => $.ui.focus({ requestId: PANE, key: 'name' })).catch(() => {})
176
+ }
177
+
178
+ async function saveName($: EngineInterface, name: string): Promise<void> {
179
+ setSetup($, { ...setup, busy: 'Saving…', error: undefined })
180
+ finishSetup($, (await runner($, ['setup-name'], name)) as SetupReply)
181
+ }
182
+
183
+ function otherNames(others: SetupState['others']): string {
184
+ const names = new Set(others.map((o) => o.peerName))
185
+ if (names.size !== 1) return others.map((o) => `${o.host} calls you ${o.peerName}`).join('; ') + '.'
186
+ const hosts = others.map((o) => o.host)
187
+ return `${hosts.length > 1 ? hosts.slice(0, -1).join(', ') + ' and ' + hosts[hosts.length - 1] : hosts[0]} ${hosts.length > 1 ? 'call' : 'calls'} you ${[...names][0]}.`
188
+ }
189
+
190
+ async function signIn($: EngineInterface): Promise<void> {
191
+ setSetup($, { ...setup, busy: 'Opening sign-in…', error: undefined })
192
+ const r = (await runner($, ['signin-start'])) as SetupReply
193
+ if (!r.ok || !r.url || !r.code) return setSetup($, { ...setup, busy: undefined, error: r.error })
194
+ setSetup($, { ...setup, busy: undefined, signIn: { url: r.url, code: r.code } })
195
+ // Each check waits up to 15s for approval; stop if the pane closed or was cancelled.
196
+ while (setup?.signIn) {
197
+ const c = (await runner($, ['signin-check'])) as SetupReply
198
+ if (!setup?.signIn) return
199
+ if (c.status === 'waiting') continue
200
+ if (c.status === 'error') { await $.clock.sleep(3000); continue }
201
+ if (c.status === 'approved') return finishSetup($, c)
202
+ return setSetup($, {
203
+ ...setup, signIn: undefined,
204
+ error: c.status === 'denied' ? 'Sign-in was denied.' : 'The sign-in code expired. Try again.',
205
+ })
206
+ }
207
+ }
208
+
209
+ // The pane must hold the keyboard, or typing lands in Claude's prompt.
210
+ async function askForKey($: EngineInterface): Promise<void> {
211
+ setSetup($, { ...setup, askKey: true, error: undefined })
212
+ await $.ui.open({ id: PANE, title: 'Honcho setup', focus: true })
213
+ await $.ui.focus({ requestId: PANE, key: 'key' }).catch(() => {})
214
+ }
215
+
216
+ async function saveKey($: EngineInterface, key: string): Promise<void> {
217
+ setSetup($, { ...setup, busy: 'Checking the key…', error: undefined })
218
+ finishSetup($, (await runner($, ['setup-key'], key)) as SetupReply)
219
+ }
220
+
221
+ async function openPane($: EngineInterface): Promise<string> {
222
+ if (connected === false) return openSetup($)
223
+ setup = undefined
224
+ detail = undefined
225
+ cardOpen = false
226
+ const opened = await $.ui.open({ id: PANE, title: 'Honcho' })
227
+ void loadAll($)
228
+ // Poll only while a run is in progress.
229
+ poller?.cancel()
230
+ poller = $.clock.every(15000, () => {
231
+ if (dreams.runs.some((r) => r.status === 'running')) void loadDreams($)
232
+ })
233
+ return opened.isPlaced ? 'Honcho pane opened.' : `Honcho pane is waiting for room (${opened.reason}).`
234
+ }
235
+
236
+ function ago(iso: string | null): string {
237
+ if (!iso) return ''
238
+ const s = Math.max(0, (Date.now() - Date.parse(iso)) / 1000)
239
+ if (s < 90) return `${Math.round(s)}s ago`
240
+ if (s < 5400) return `${Math.round(s / 60)}m ago`
241
+ if (s < 129600) return `${Math.round(s / 3600)}h ago`
242
+ return `${Math.round(s / 86400)}d ago`
243
+ }
244
+
245
+ const GLYPH: Record<Run['status'], string> = { running: '◐', completed: '●', failed: '✕', interrupted: '◌' }
246
+ const COLOR: Record<Run['status'], string> = { running: 'yellow', completed: 'green', failed: 'red', interrupted: 'gray' }
247
+
248
+ function clip(text: string | null | undefined, width: number): string {
249
+ const t = (text ?? '(unavailable)').replace(/\s+/g, ' ')
250
+ return t.length > width ? t.slice(0, width - 1) + '…' : t
251
+ }
252
+
253
+ async function tryOpen($: EngineInterface, url: string): Promise<boolean> {
254
+ for (const opener of ['open', 'xdg-open']) {
255
+ try {
256
+ if ((await $.process.run([opener, url])).exitCode === 0) return true
257
+ } catch { /* not on this platform */ }
258
+ }
259
+ return false
260
+ }
261
+
262
+ async function openUrl($: EngineInterface, url: string): Promise<void> {
263
+ if (!(await tryOpen($, url))) $.ui.toast(url)
264
+ }
265
+
266
+ // Opens the page and also copies the link, so it can be pasted elsewhere.
267
+ async function openSession($: EngineInterface, url: string, press: UiPressArgument): Promise<void> {
268
+ const [opened, copy] = await Promise.all([
269
+ tryOpen($, url),
270
+ $.ui.copy({ text: url, surface: press.surface }).catch(() => ({ isCopied: false })),
271
+ ])
272
+ $.ui.toast(
273
+ opened && copy.isCopied ? 'Opened in your browser; link copied.'
274
+ : opened ? 'Opened in your browser.'
275
+ : copy.isCopied ? 'Link copied.'
276
+ : url,
277
+ )
278
+ }
279
+
280
+ function textOf(result: { content: { type: string; text?: string }[] }): string {
281
+ return result.content.map((b) => b.text ?? '').join('\n')
282
+ }
283
+
284
+ async function mcp($: EngineInterface, tool: string, args?: Record<string, unknown>): Promise<string> {
285
+ const conn = await $.mcp.connect('honcho')
286
+ if (!('server' in conn) || !conn.server) return 'Honcho MCP server is not connected.'
287
+ return textOf(await $.mcp.call(conn.server, tool, args))
288
+ }
289
+
290
+ const ANSI = /\x1b\[[0-9;]*m/g
291
+
292
+ // .catch(next) on wrapping hooks: a failure here never blocks the hook or tool beneath.
293
+ export const register: Register = (on) => {
294
+ on('session.start', async ($, e, next) => {
295
+ await $.env.set('HONCHO_MOD_UI', '1')
296
+ await $.command.register({
297
+ name: 'honcho',
298
+ description: 'Open the Honcho pane, or setup | status | config | set | import',
299
+ argumentHint: '[setup | status | config | set <field> <value> | import [--days N] [--yes]]',
300
+ immediate: true,
301
+ })
302
+ void runner($, ['setup-state']).then((r) => {
303
+ if (r.ok) connected = (r as SetupReply).connected
304
+ $.ui.invalidate('ui.render')
305
+ })
306
+ return next(e)
307
+ })
308
+
309
+
310
+ on('ui.render', { component: 'SessionMode' }, async ($, e, next) => {
311
+ const { Box, Text, Button } = $.ui.resolve(e)
312
+ const button = (
313
+ <Button key="honcho" plain label="honcho" onPress={() => void togglePane($)}>
314
+ {connected === false
315
+ ? <Text color="yellow">○ honcho · set up</Text>
316
+ : <Text color="cyan">● honcho</Text>}
317
+ </Button>
318
+ )
319
+ if (e.props.modes.length === 0) return button
320
+ return (
321
+ <Box flexDirection="row" gap={2}>
322
+ {await next(e)}
323
+ {button}
324
+ </Box>
325
+ )
326
+ }).catch(($, e, next) => next(e))
327
+
328
+ // user-prompt.ts writes the version nag here when the mod is on.
329
+ on('classic.UserPromptSubmit', async ($, e, next) => {
330
+ const result = await next(e)
331
+ if (!noticeShown) {
332
+ const n = await readJson<{ text?: string }>($, `${await home($)}/.honcho/notice-${await $.session.id()}.json`)
333
+ if (n?.text) {
334
+ noticeShown = true
335
+ const v = n.text.match(/v(\S+) installed, v(\S+) available/)
336
+ $.ui.toast(v ? `v${v[2]} is out (you have v${v[1]}). Update in /plugins.` : n.text, { timeoutMs: 10000 })
337
+ }
338
+ }
339
+ return result
340
+ }).catch(($, e, next) => next(e))
341
+
342
+ on('tool.call', { tool: HONCHO_TOOL }, async ($, e, next) => {
343
+ const verb = String(e.tool).replace(HONCHO_TOOL, '')
344
+ activity = VERBS[verb] ?? verb
345
+ $.ui.invalidate('ui.render')
346
+ try {
347
+ return await next(e)
348
+ } finally {
349
+ activity = undefined
350
+ $.ui.invalidate('ui.render')
351
+ }
352
+ }).catch(($, e, next) => next(e))
353
+
354
+ on('ui.render', { component: 'Spinner' }, async ($, e, next) =>
355
+ activity
356
+ ? next({ ...e, props: { ...e.props, suffix: `${e.props.suffix ?? ''} · honcho ${activity}…` } })
357
+ : next(e),
358
+ )
359
+
360
+ on('command.run', { command: 'honcho' }, async ($, e) => {
361
+ const [sub = 'pane', field, ...value] = e.args.trim().split(/\s+/).filter(Boolean)
362
+ switch (sub) {
363
+ case 'status': {
364
+ const r = await script($, 'status-runner', [], 20000)
365
+ const s = await sessionInfo($)
366
+ const link = s?.url ? `\n View session: ${s.url}` : ''
367
+ return { text: (r.stdout || r.stderr).replace(ANSI, '').trim() + link }
368
+ }
369
+ case 'config': {
370
+ const raw = await mcp($, 'get_config')
371
+ try { return { text: JSON.parse(raw).card ?? raw } } catch { return { text: raw } }
372
+ }
373
+ case 'import': {
374
+ const rest = e.args.trim().split(/\s+/).slice(1)
375
+ const upload = rest.includes('--yes')
376
+ const r = await script($, 'backfill-runner', upload ? rest : [...rest, '--dry-run'], 600000)
377
+ const out = (r.stdout || r.stderr).replace(ANSI, '').trim()
378
+ return { text: upload ? out : `${out}\n\nRun /honcho import --yes to upload.` }
379
+ }
380
+ case 'set': {
381
+ if (!field || value.length === 0) return { text: 'Usage: /honcho set <field> <value>' }
382
+ const raw = value.join(' ')
383
+ let parsed: unknown = raw
384
+ try { parsed = JSON.parse(raw) } catch { /* plain string */ }
385
+ // The user typed the command, which is the confirmation set_config asks for.
386
+ return { text: await mcp($, 'set_config', { field, value: parsed, confirm: true }) }
387
+ }
388
+ case 'setup':
389
+ return { text: await openSetup($) }
390
+ case 'pane':
391
+ case 'dreams':
392
+ return { text: await togglePane($) }
393
+ default:
394
+ return { text: 'Usage: /honcho [setup | status | config | set <field> <value> | import [--days N] [--yes]]' }
395
+ }
396
+ })
397
+
398
+ on('ui.close', { id: PANE }, async ($, e, next) => {
399
+ poller?.cancel()
400
+ poller = undefined
401
+ setup = undefined
402
+ return next(e)
403
+ }).catch(($, e, next) => next(e))
404
+
405
+ on('turn.complete', async ($, e, next) => {
406
+ if ((await paneIsOpen($)) && (await $.session.id()) !== overviewFor) void loadOverview($)
407
+ return next(e)
408
+ })
409
+
410
+ on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
411
+ const { Box, Text, Button } = $.ui.resolve(e)
412
+ const width = Math.max(20, (e.props.bodyColumns ?? 60) - 4)
413
+
414
+ const back = () => { detail = undefined; cardOpen = false; $.ui.invalidate('ui.render') }
415
+
416
+ if (setup) {
417
+ const { Input } = $.ui.resolve(e)
418
+ const st = setup.state
419
+ const choosing = st && !st.connected && !setup.done && !setup.signIn && !setup.askKey && !setup.busy
420
+ return (
421
+ <Box flexDirection="column" gap={1}>
422
+ {setup.busy && <Text dimColor>{setup.busy}</Text>}
423
+ {setup.error && <Text color="red">{setup.error}</Text>}
424
+ {setup.done && st && (
425
+ <Box flexDirection="column" gap={1}>
426
+ <Text><Text color="green">● </Text>Connected to Honcho as {st.peer} in {st.workspace}.</Text>
427
+ <Text dimColor>{st.auth}. Memory loads from your next session (/clear or restart Claude Code).</Text>
428
+ {st.transcripts > 0 && (
429
+ <Text dimColor>You have {st.transcripts} past sessions from the last 30 days. Run /honcho import to add them.</Text>
430
+ )}
431
+ <Button key="done" label="done" onPress={() => { setup = undefined; void openPane($) }} />
432
+ </Box>
433
+ )}
434
+ {choosing && (
435
+ <Box flexDirection="column" gap={1}>
436
+ <Text>Connect Claude Code to Honcho so it remembers you across sessions.</Text>
437
+ <Box flexDirection="row" gap={2}>
438
+ {st.canSignIn && <Button key="signin" variant="primary" label="Sign in with your browser" onPress={() => void signIn($)} />}
439
+ <Button key="apikey" label="Use an API key" onPress={() => void askForKey($)} />
440
+ </Box>
441
+ </Box>
442
+ )}
443
+ {setup.signIn && (
444
+ <Box flexDirection="column" gap={1}>
445
+ <Text>Approve the sign-in in your browser. Check the code matches: <Text weight="semibold">{setup.signIn.code}</Text></Text>
446
+ <Box flexDirection="row" gap={2}>
447
+ <Button key="open" label="open sign-in page ↗" onPress={() => void openUrl($, setup!.signIn!.url)} />
448
+ <Button key="cancel" label="cancel" onPress={() => setSetup($, { state: st })} />
449
+ </Box>
450
+ <Text dimColor>Waiting for approval…</Text>
451
+ </Box>
452
+ )}
453
+ {setup.askName && st && !setup.busy && (
454
+ <Box flexDirection="column" gap={1}>
455
+ <Text><Text color="green">● </Text>Connected. What should Honcho call you?</Text>
456
+ <Input key="name" label="Your name in Honcho" value={st.suggestedName} submitLabel="save" autoFocus onSubmit={(v) => void saveName($, v)} />
457
+ {st.others.length > 0 && <Text dimColor>Your other Honcho plugins: {otherNames(st.others)}</Text>}
458
+ <Text dimColor>Use the same name everywhere you use Honcho, so it builds one picture of you.</Text>
459
+ </Box>
460
+ )}
461
+ {setup.askKey && !setup.busy && (
462
+ <Box flexDirection="column" gap={1}>
463
+ <Input key="key" label="API key" placeholder="from app.honcho.dev" submitLabel="save" autoFocus onSubmit={(v) => void saveKey($, v)} />
464
+ <Text dimColor>Get a key at app.honcho.dev. It is checked, then saved to ~/.honcho/config.json.</Text>
465
+ <Button key="cancel" label="cancel" onPress={() => setSetup($, { state: st })} />
466
+ </Box>
467
+ )}
468
+ </Box>
469
+ )
470
+ }
471
+
472
+ if (cardOpen && overview.data) {
473
+ const card = overview.data.card
474
+ return (
475
+ <Box flexDirection="column" gap={1}>
476
+ <Button label="← back" onPress={back} />
477
+ <Text weight="semibold">Peer card ({card.length})</Text>
478
+ <Box flexDirection="column">
479
+ {card.map((line) => <Text wrap="wrap">{line}</Text>)}
480
+ </Box>
481
+ </Box>
482
+ )
483
+ }
484
+
485
+ if (detail) {
486
+ const run = detail.run
487
+ return (
488
+ <Box flexDirection="column" gap={1}>
489
+ <Button label="← back" onPress={back} />
490
+ {detail.loading && <Text dimColor>Loading run…</Text>}
491
+ {detail.error && <Text color="red">{detail.error}</Text>}
492
+ {run && (
493
+ <Box flexDirection="column" gap={1}>
494
+ <Text>
495
+ <Text color={COLOR[run.status]}>{GLYPH[run.status]} {run.status}</Text>
496
+ <Text dimColor> {run.trigger_reason} · {run.observer_id} → {run.observed_id} · {ago(run.started_at)}</Text>
497
+ </Text>
498
+ {run.pruned_at && <Text dimColor>Pruned {ago(run.pruned_at)}: only conclusions that still exist are kept.</Text>}
499
+ <Box flexDirection="column">
500
+ <Text weight="semibold">Created ({run.created.length})</Text>
501
+ {run.created.length === 0 && <Text dimColor>none</Text>}
502
+ {run.created.map((c) => (
503
+ <Text wrap="wrap" dimColor={c.conclusion.status !== 'current'}>
504
+ + {c.conclusion.content ?? '(unavailable)'}
505
+ {c.conclusion.status === 'removed' ? ` (removed later)` : ''}
506
+ </Text>
507
+ ))}
508
+ </Box>
509
+ <Box flexDirection="column">
510
+ <Text weight="semibold">Removed ({run.removed.length})</Text>
511
+ {run.removed.length === 0 && <Text dimColor>none</Text>}
512
+ {run.removed.map((r) => <Text wrap="wrap" color="red">- {r.content ?? '(unavailable)'}</Text>)}
513
+ </Box>
514
+ {run.peer_card && (
515
+ <Box flexDirection="column">
516
+ <Text weight="semibold">Peer card {run.peer_card.before ? 'updated' : 'created'}</Text>
517
+ {(run.peer_card.after ?? [])
518
+ .filter((line) => !(run.peer_card?.before ?? []).includes(line))
519
+ .map((line) => <Text color="green">+ {clip(line, width - 4)}</Text>)}
520
+ {(run.peer_card.before ?? [])
521
+ .filter((line) => !(run.peer_card?.after ?? []).includes(line))
522
+ .map((line) => <Text color="red">- {clip(line, width - 4)}</Text>)}
523
+ </Box>
524
+ )}
525
+ </Box>
526
+ )}
527
+ </Box>
528
+ )
529
+ }
530
+
531
+ const o = overview.data
532
+ const Section = ({ title, children }: { title: string; children?: RenderChildren }) => (
533
+ <Box flexDirection="column">
534
+ <Text weight="semibold">{title}</Text>
535
+ {children}
536
+ </Box>
537
+ )
538
+ return (
539
+ <Box flexDirection="column" gap={1}>
540
+ <Box flexDirection="row" gap={1}>
541
+ <Text dimColor>
542
+ {dreams.peer ?? '…'} @ {dreams.workspace ?? '…'}
543
+ {dreams.at ? ` · updated ${ago(new Date(dreams.at).toISOString())}` : ''}
544
+ </Text>
545
+ {o?.sessionUrl && <Button key="open" label="open in Honcho" plain onPress={(press) => void openSession($, o.sessionUrl!, press)} />}
546
+ <Button key="refresh" label="refresh" plain onPress={() => void loadAll($)} />
547
+ </Box>
548
+ {overview.error && <Text color="red">{overview.error}</Text>}
549
+ {overview.loading && !o && <Text dimColor>Loading…</Text>}
550
+ <Section title="Dreams">
551
+ {dreams.loading && dreams.runs.length === 0 && <Text dimColor>Loading dreams…</Text>}
552
+ {dreams.error && <Text color="red">{dreams.error}</Text>}
553
+ {!dreams.loading && !dreams.error && dreams.runs.length === 0 && <Text dimColor>No dreams yet.</Text>}
554
+ {dreams.runs.slice(0, 5).map((run) => (
555
+ <Button key={run.id} label={`${run.status} ${run.id}`} onPress={() => void loadDetail($, run.id)}>
556
+ <Text color={COLOR[run.status]}>{GLYPH[run.status]} </Text>
557
+ {`${ago(run.started_at).padEnd(8)} +${run.created_count} −${run.removed_count}${run.peer_card_updated ? ' card' : ''} `}
558
+ <Text dimColor>{run.trigger_reason}</Text>
559
+ </Button>
560
+ ))}
561
+ </Section>
562
+ {o && (
563
+ <Section title="Peer card">
564
+ {o.card.length === 0 && <Text dimColor>Empty so far; it fills in as Honcho learns about you.</Text>}
565
+ {o.card.length > 0 && (
566
+ <Button key="card" label={`peer card, ${o.card.length} items`} onPress={() => { cardOpen = true; $.ui.invalidate('ui.render') }}>
567
+ {`${o.card.length} items `}
568
+ <Text dimColor>{clip(o.card[0], width - 16)}</Text>
569
+ </Button>
570
+ )}
571
+ </Section>
572
+ )}
573
+ </Box>
574
+ )
575
+ })
576
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honcho-ai/claude-honcho",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "Persistent memory for Claude Code sessions using Honcho by Plastic Labs",
6
6
  "author": "Plastic Labs <hello@plasticlabs.ai>",