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