handmux 0.30.0 → 0.31.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.
Files changed (108) hide show
  1. package/dist/connectors/claude/index.js +33 -562
  2. package/dist/connectors/codebuddy/index.js +49 -0
  3. package/dist/connectors/hookBridge.js +560 -0
  4. package/dist/hooks/handmux-codebuddy-notify.sh +116 -0
  5. package/dist/hooks/handmux-notify.sh +2 -0
  6. package/dist/hooks/handmux-write.cjs +72 -5
  7. package/dist/package.json +7 -7
  8. package/dist/public/assets/{abnfDiagram-O67JEVCF-CmVVGJqt.js → abnfDiagram-O67JEVCF-BsRDIQEB.js} +1 -1
  9. package/dist/public/assets/{arc-aYtCI03A.js → arc-DLtLfMnX.js} +1 -1
  10. package/dist/public/assets/{architectureDiagram-NJMV4G6O-CyZZDTaL.js → architectureDiagram-NJMV4G6O-DoIXhWqZ.js} +1 -1
  11. package/dist/public/assets/{blockDiagram-BEXU5L5S-D_ODtFS0.js → blockDiagram-BEXU5L5S-W0HiOcVA.js} +1 -1
  12. package/dist/public/assets/{c4Diagram-YGBWAQC7-C8qZFFmC.js → c4Diagram-YGBWAQC7-72uAUMvX.js} +1 -1
  13. package/dist/public/assets/channel-CzALSnb0.js +1 -0
  14. package/dist/public/assets/{chunk-2Q5K7J3B-Bo85fSxI.js → chunk-2Q5K7J3B-B9wSRFQ0.js} +1 -1
  15. package/dist/public/assets/{chunk-3FUC2YCW-BnET3fKr.js → chunk-3FUC2YCW-ryphp4s0.js} +2 -2
  16. package/dist/public/assets/{chunk-5VM5RSS4-DDw_KNv1.js → chunk-5VM5RSS4-Cm4KeKby.js} +1 -1
  17. package/dist/public/assets/{chunk-GTNCS2PH-B_K2164R.js → chunk-GTNCS2PH-Du4_i7r3.js} +1 -1
  18. package/dist/public/assets/{chunk-GWA4HPMP-1GA2Su8A.js → chunk-GWA4HPMP-CL1biVIA.js} +1 -1
  19. package/dist/public/assets/{chunk-JWPE2WC7-Cfc-8kSE.js → chunk-JWPE2WC7-B8eAVfuB.js} +1 -1
  20. package/dist/public/assets/{chunk-NETBCI7D-C7zyDFCq.js → chunk-NETBCI7D-D273GzYg.js} +1 -1
  21. package/dist/public/assets/{chunk-WEXAMYUT-BI2Zijn_.js → chunk-WEXAMYUT-DipTfRbc.js} +1 -1
  22. package/dist/public/assets/{chunk-XXDRQBXY-Bl50fDL9.js → chunk-XXDRQBXY-D4SqXrQ8.js} +1 -1
  23. package/dist/public/assets/{classDiagram-v2-NBCMYWYE-BMWMChZ4.js → classDiagram-v2-NBCMYWYE-PrpnIXcA.js} +1 -1
  24. package/dist/public/assets/{cose-bilkent-JH36ORCC-B_HUrBN4.js → cose-bilkent-JH36ORCC-BfcYMYTa.js} +1 -1
  25. package/dist/public/assets/{cynefin-OW5HDTMX-2jTRe-JA.js → cynefin-OW5HDTMX-Du659bmz.js} +1 -1
  26. package/dist/public/assets/{cynefinDiagram-VND7K2PF-ClDtZNOK.js → cynefinDiagram-VND7K2PF-DR_2Copy.js} +1 -1
  27. package/dist/public/assets/{dagre-6A5THRUB-CJS3bbcm.js → dagre-6A5THRUB-COsChaV5.js} +1 -1
  28. package/dist/public/assets/{diagram-22UHCM2B-BpRgaKhU.js → diagram-22UHCM2B-Cx2T1HvL.js} +1 -1
  29. package/dist/public/assets/{diagram-3UASUU5V-BNwvXb9K.js → diagram-3UASUU5V-Cp04LOka.js} +1 -1
  30. package/dist/public/assets/{diagram-ATOU4E4O-DyphKhOl.js → diagram-ATOU4E4O-DlqFSshY.js} +1 -1
  31. package/dist/public/assets/{diagram-CDSNMT55-BRazAxS2.js → diagram-CDSNMT55-goq40ctA.js} +1 -1
  32. package/dist/public/assets/{diagram-MLGK6HIB-NN_P6wZp.js → diagram-MLGK6HIB-Bdzjsy4r.js} +1 -1
  33. package/dist/public/assets/{diagram-MPIPVDR6-DHBe5DA4.js → diagram-MPIPVDR6-DtU7cM6P.js} +1 -1
  34. package/dist/public/assets/{ebnfDiagram-ZINNZB2B-BCTHXp7J.js → ebnfDiagram-ZINNZB2B-XyVCfmED.js} +1 -1
  35. package/dist/public/assets/{elk-276RUBZZ-yXNwrgXQ.js → elk-276RUBZZ-aHVIw-2x.js} +1 -1
  36. package/dist/public/assets/{erDiagram-OPXOYQCR-YsAJcCqg.js → erDiagram-OPXOYQCR-Bq_PhTIL.js} +1 -1
  37. package/dist/public/assets/{flowDiagram-KWPJA3E3-CyX8qF-3.js → flowDiagram-KWPJA3E3-WuqnDSiF.js} +1 -1
  38. package/dist/public/assets/{ganttDiagram-FUAMR5RP-BMFOvdDK.js → ganttDiagram-FUAMR5RP-DZ4lXzkC.js} +1 -1
  39. package/dist/public/assets/{gitGraphDiagram-X574FWY7-D1sZiiWD.js → gitGraphDiagram-X574FWY7-t6l07b9g.js} +1 -1
  40. package/dist/public/assets/index-DiYff8oR.css +32 -0
  41. package/dist/public/assets/index-YZNK723o.js +203 -0
  42. package/dist/public/assets/{infoDiagram-VRGFBTTK-CiayIr0f.js → infoDiagram-VRGFBTTK-iUGqoOFp.js} +1 -1
  43. package/dist/public/assets/{ishikawaDiagram-OU5B5YK6-Bf4mzvKk.js → ishikawaDiagram-OU5B5YK6-B0TmoUOK.js} +1 -1
  44. package/dist/public/assets/{journeyDiagram-ZHPQQLJL-mvwzOMZ7.js → journeyDiagram-ZHPQQLJL-CQE61MCu.js} +1 -1
  45. package/dist/public/assets/{kanban-definition-PNTS6WVX-CMFYAtvx.js → kanban-definition-PNTS6WVX-D2MWCUyS.js} +1 -1
  46. package/dist/public/assets/{linear-BcK1QK3e.js → linear-WKGxVNP1.js} +1 -1
  47. package/dist/public/assets/{mermaid.core-BmCR7le1.js → mermaid.core-DPEwUsaj.js} +4 -4
  48. package/dist/public/assets/{mindmap-definition-NLK3R4M7-hvUFWkg7.js → mindmap-definition-NLK3R4M7-DsYEsBsI.js} +1 -1
  49. package/dist/public/assets/{pegDiagram-GJSIUBJH-B8FGnth6.js → pegDiagram-GJSIUBJH-BS52Fbxt.js} +1 -1
  50. package/dist/public/assets/{pieDiagram-5QR66LMP-BdhppGvz.js → pieDiagram-5QR66LMP-D4o8g7nW.js} +1 -1
  51. package/dist/public/assets/{quadrantDiagram-O4NWA36T-i6XjZJ8W.js → quadrantDiagram-O4NWA36T-DnYUxWll.js} +1 -1
  52. package/dist/public/assets/{railroadDiagram-XR7U4H2S-C7XoA5kk.js → railroadDiagram-XR7U4H2S-BKy_7ULV.js} +1 -1
  53. package/dist/public/assets/{requirementDiagram-PLB6GJNP-tq6onssc.js → requirementDiagram-PLB6GJNP-Ce5F4u8K.js} +1 -1
  54. package/dist/public/assets/{sankeyDiagram-IPEJSGJF-DRW13BH8.js → sankeyDiagram-IPEJSGJF-CCJDrut_.js} +1 -1
  55. package/dist/public/assets/{sequenceDiagram-PO4LG4MO-BJqhIpnw.js → sequenceDiagram-PO4LG4MO-D5E8ISM1.js} +1 -1
  56. package/dist/public/assets/{sizeCapture-INFHLROL-BCpyNpYK.js → sizeCapture-INFHLROL-BW3KmxDN.js} +1 -1
  57. package/dist/public/assets/{stateDiagram-v2-GCMORJYK-Da3aSdeG.js → stateDiagram-v2-GCMORJYK-Bw2ZzQOE.js} +1 -1
  58. package/dist/public/assets/{swimlanes-2SLR337P-oT62nN2e.js → swimlanes-2SLR337P-CLJ-6Ex_.js} +1 -1
  59. package/dist/public/assets/swimlanesDiagram-TC7HE7FX-BD8rQfV7.js +8 -0
  60. package/dist/public/assets/{timeline-definition-EJHVYXUP-CQ9Q15bt.js → timeline-definition-EJHVYXUP-C_lFJ-4W.js} +1 -1
  61. package/dist/public/assets/{usecaseDiagram-POWQR4AR-De1gJb8v.js → usecaseDiagram-POWQR4AR-DWXawL2A.js} +1 -1
  62. package/dist/public/assets/{vennDiagram-UO4OBE2U-BusPyTiq.js → vennDiagram-UO4OBE2U-D4O5oZal.js} +1 -1
  63. package/dist/public/assets/{wardleyDiagram-VNRHLVJA-D-vaN_gJ.js → wardleyDiagram-VNRHLVJA-B6HElk__.js} +1 -1
  64. package/dist/public/assets/{xychartDiagram-PMCCYNJV-BcOmOj-j.js → xychartDiagram-PMCCYNJV-C5OAXnJy.js} +1 -1
  65. package/dist/public/index.html +2 -2
  66. package/dist/src/agent-runtime/adapter.js +54 -10
  67. package/dist/src/agent-runtime/builtinRuntime.js +67 -6
  68. package/dist/src/agent-runtime/conversation.js +49 -9
  69. package/dist/src/agent-runtime/interaction.js +26 -12
  70. package/dist/src/agent-runtime/interactionLiveHub.js +4 -0
  71. package/dist/src/agent-runtime/runtime.js +83 -27
  72. package/dist/src/agent-runtime/tmuxRuntime.js +36 -6
  73. package/dist/src/agents/claude.js +2 -19
  74. package/dist/src/agents/claudeInteraction.js +2 -132
  75. package/dist/src/agents/claudePaneInput.js +22 -22
  76. package/dist/src/agents/codebuddy.js +100 -0
  77. package/dist/src/agents/codebuddyConversation.js +414 -0
  78. package/dist/src/agents/codebuddyInteraction.js +4 -0
  79. package/dist/src/agents/codebuddyNativeTail.js +206 -0
  80. package/dist/src/agents/codebuddyPaneInput.js +76 -0
  81. package/dist/src/agents/codebuddyTranscriptParse.js +178 -0
  82. package/dist/src/agents/hookEvents.js +143 -0
  83. package/dist/src/agents/hookInteraction.js +178 -0
  84. package/dist/src/agents/index.js +2 -1
  85. package/dist/src/claudeEvents.js +4 -5
  86. package/dist/src/cli/agentIntegration.js +31 -2
  87. package/dist/src/cli/codebuddyHooks.js +286 -0
  88. package/dist/src/cli/hookScaffold.js +25 -12
  89. package/dist/src/cli/i18n/en.js +1 -1
  90. package/dist/src/cli/i18n/zh.js +1 -1
  91. package/dist/src/cli/state.js +4 -0
  92. package/dist/src/cli/supervisor.js +2 -1
  93. package/dist/src/codebuddyEvents.js +151 -0
  94. package/dist/src/docs.js +17 -6
  95. package/dist/src/logDetail.js +27 -0
  96. package/dist/src/paneInput.js +107 -10
  97. package/dist/src/pendingPrompt.js +21 -5
  98. package/dist/src/routes/system.js +12 -2
  99. package/dist/src/server.js +69 -8
  100. package/dist/src/workspace/checkpointer.js +48 -4
  101. package/dist/src/workspace/lock.js +54 -10
  102. package/dist/src/workspace/runtime.js +23 -8
  103. package/dist/src/workspaceProtocol.js +1 -0
  104. package/package.json +3 -3
  105. package/dist/public/assets/channel-kkiOw5AC.js +0 -1
  106. package/dist/public/assets/index-DqCUBYR8.css +0 -32
  107. package/dist/public/assets/index-OW7snGiD.js +0 -362
  108. package/dist/public/assets/swimlanesDiagram-TC7HE7FX-YHG5AQi4.js +0 -8
@@ -0,0 +1,178 @@
1
+ // The pending-interaction adapter shared by the Hook-driven Agents (Claude, CodeBuddy). Their TUIs are the
2
+ // same one-line-editor lineage, so the prompts they put on screen have the same shape — a cursor-marked
3
+ // numbered option list with a description row under an option — and they parse with the SAME
4
+ // `parsePendingPrompt`. What differs is the KEYSTROKE that picks an option, and that turns out to depend on
5
+ // the SCREEN rather than on the provider — so both bind one shared sender (paneInput.sendPaneMenuChoice):
6
+ //
7
+ // question menu a digit only MOVES the highlight. Measured live on CodeBuddy 2.156.0, whose picker
8
+ // ignores the digit outright (the highlight does not budge); and read out of Claude
9
+ // Code's own bundle (2.1.278), where `1`–`9` go through the same `nme` that ↑/↓ call
10
+ // while only the `return` branch commits. Answering therefore means walking to the
11
+ // option and pressing Enter — on both providers.
12
+ // permission gate the digit commits: measured on CodeBuddy, where a `1` approved a command that really
13
+ // ran. It is also the safer key there — it names the row instead of stepping to it, so a
14
+ // misread cursor cannot commit a different answer than the user tapped.
15
+ //
16
+ // A provider supplies its own naming (the ids the phone stores and the fallback wording a user reads);
17
+ // everything else is the shared contract. Where a provider's wording is NOT verifiable — a permission gate
18
+ // whose screen shows no options — the adapter emits a `local_only` prompt with no options rather than
19
+ // guessing what the buttons mean.
20
+ import { createHash } from 'node:crypto';
21
+ import { parsePendingPrompt } from '../pendingPrompt.js';
22
+ // A pane that is mid-turn says so on its own screen: both providers print the interrupt hint while the model
23
+ // or a tool is running — `✹ Buzzing… (esc to interrupt)`, measured on CodeBuddy 2.156.0, and Claude prints the
24
+ // same hint. A gate that is really up cannot be mid-turn; the pane is blocked ON the gate. So this is what
25
+ // keeps the no-options fallback quiet in the one window where its `permreq` row is stale by construction:
26
+ // CodeBuddy fires no Hook when a gate is answered, so an approved tool keeps its row (and the roster at 需要你)
27
+ // until the turn's next Hook — measured on pane %211, where an approved `sleep 90` said 需要你授权:Bash for the
28
+ // whole minute while the tool ran, and the fallback turned that into a 去终端 card nothing was waiting for.
29
+ const INTERRUPT_HINT_RE = /esc to interrupt/i;
30
+ function normalizedPrompt(text, provider, pendingKind) {
31
+ const prompt = parsePendingPrompt(text);
32
+ if (!prompt) {
33
+ if (pendingKind !== 'permission' || INTERRUPT_HINT_RE.test(text))
34
+ return null;
35
+ const tail = text.split('\n').map((line) => line.trim()).filter(Boolean).slice(-3).join('\n');
36
+ const promptText = tail.slice(0, 2_000) || `${provider.label} is waiting for permission in the terminal.`;
37
+ const id = `${provider.id}-permission:${createHash('sha256').update(promptText).digest('hex').slice(0, 24)}`;
38
+ return {
39
+ id, type: 'local_only', prompt: promptText,
40
+ };
41
+ }
42
+ // The card must survive a re-render. The parse carries two volatile pieces: `cursor`, which moves whenever
43
+ // anyone navigates the menu, and the lead-in prose above the question, which the turn retypes as it streams.
44
+ // Hashing the whole parse therefore minted a NEW card whenever either changed, retiring the live one as
45
+ // "resolved" while its gate was still on screen — so an answer could be swallowed AND its card taken away
46
+ // (measured: a user's answer to a live question was accepted by the server and never reached the pane).
47
+ // Identify the gate by what IS the gate: the menu kind, its own question line, and the options offered.
48
+ //
49
+ // The price of a shape-named id is that two DIFFERENT gates of the same shape carry the same id — every
50
+ // review screen, for one. That is Core's problem to tell apart, and it does: a shape that comes back after
51
+ // its card was settled is published as a new interaction with a new id and token, never silently dropped.
52
+ // So this id must stay shape-stable within one occurrence and must NOT try to encode an instance number,
53
+ // which this adapter cannot know (a fresh observation has no memory of what it saw before).
54
+ const signature = JSON.stringify({
55
+ kind: prompt.kind,
56
+ question: prompt.title.split(' — ').at(-1) ?? prompt.title,
57
+ options: prompt.options.map((option) => option.label),
58
+ submit: prompt.submit === true,
59
+ });
60
+ const id = `${provider.id}-prompt:${createHash('sha256').update(signature).digest('hex').slice(0, 24)}`;
61
+ return {
62
+ id,
63
+ type: 'select',
64
+ prompt: prompt.leadIn ? `${prompt.leadIn}\n${prompt.title}` : prompt.title,
65
+ options: prompt.options.map((option) => ({
66
+ id: `choice:${option.n}`,
67
+ label: option.description ? `${option.label} — ${option.description}` : option.label,
68
+ })),
69
+ };
70
+ }
71
+ export function createHookInteractionAdapter(control, provider, pollMs = 750, reportHealth = () => { }) {
72
+ if (!control || typeof control.capturePlain !== 'function'
73
+ || typeof control.sendChoice !== 'function' || !Number.isFinite(pollMs) || pollMs <= 0) {
74
+ throw new TypeError('Interaction adapter requires pane capture and choice control');
75
+ }
76
+ const active = new Map();
77
+ return {
78
+ apiVersion: 1,
79
+ async observeNative(run, sink) {
80
+ let closed = false;
81
+ let cursor = 0;
82
+ let pending = normalizedPrompt(await control.capturePlain(run.ref.paneId), provider, control.pendingKind?.(run.ref.paneId));
83
+ let timer;
84
+ let tail = Promise.resolve();
85
+ let failures = 0;
86
+ const binding = { run, pending };
87
+ active.set(run.ref.runId, binding);
88
+ const close = () => {
89
+ closed = true;
90
+ if (timer)
91
+ clearTimeout(timer);
92
+ timer = undefined;
93
+ if (active.get(run.ref.runId) === binding)
94
+ active.delete(run.ref.runId);
95
+ };
96
+ const schedule = (delay = pollMs) => {
97
+ if (closed || run.signal.aborted)
98
+ return;
99
+ timer = setTimeout(() => {
100
+ tail = tail.then(async () => {
101
+ if (closed || run.signal.aborted)
102
+ return;
103
+ const next = normalizedPrompt(await control.capturePlain(run.ref.paneId), provider, control.pendingKind?.(run.ref.paneId));
104
+ if (failures > 0)
105
+ reportHealth('ready');
106
+ failures = 0;
107
+ if (pending?.id === next?.id)
108
+ return;
109
+ if (pending)
110
+ await sink({
111
+ type: 'resolved', sourceCursor: `${provider.id}-interaction:${++cursor}`,
112
+ interactionId: pending.id,
113
+ });
114
+ pending = next;
115
+ binding.pending = next;
116
+ if (next)
117
+ await sink({
118
+ type: 'opened', sourceCursor: `${provider.id}-interaction:${++cursor}`, interaction: next,
119
+ });
120
+ }).catch(async () => {
121
+ failures += 1;
122
+ if (failures >= 2) {
123
+ reportHealth('degraded', 'Interaction polling is temporarily unavailable');
124
+ if (pending) {
125
+ const abandoned = pending;
126
+ pending = null;
127
+ binding.pending = null;
128
+ await Promise.resolve(sink({
129
+ type: 'cancelled', sourceCursor: `${provider.id}-interaction:${++cursor}`,
130
+ interactionId: abandoned.id, reason: 'temporarily_unavailable',
131
+ })).catch(close);
132
+ }
133
+ }
134
+ }).finally(() => schedule(Math.min(10_000, pollMs * (2 ** Math.min(failures, 4)))));
135
+ }, delay);
136
+ timer.unref?.();
137
+ };
138
+ const onAbort = () => close();
139
+ run.signal.addEventListener('abort', onAbort, { once: true });
140
+ schedule();
141
+ return {
142
+ checkpoint: {
143
+ sourceCursor: `${provider.id}-interaction:${cursor}`,
144
+ pending: pending ? [pending] : [],
145
+ },
146
+ close() {
147
+ run.signal.removeEventListener('abort', onAbort);
148
+ close();
149
+ },
150
+ };
151
+ },
152
+ async dispatchResponse(run, request) {
153
+ const binding = active.get(run.ref.runId);
154
+ if (!binding || binding.run !== run || run.signal.aborted)
155
+ return { status: 'stale_run' };
156
+ if (!binding.pending || binding.pending.id !== request.interactionId) {
157
+ return { status: 'already_resolved' };
158
+ }
159
+ const optionIds = request.value.type === 'selection' ? request.value.optionIds
160
+ : request.value.type === 'approval' ? [request.value.optionId] : [];
161
+ if (optionIds.length !== 1) {
162
+ return { status: 'rejected', reason: 'invalid_value' };
163
+ }
164
+ const optionId = optionIds[0];
165
+ const match = optionId.match(/^choice:(\d+)$/);
166
+ if (!match || !binding.pending.options?.some((option) => option.id === optionId)) {
167
+ return { status: 'rejected', reason: 'invalid_value' };
168
+ }
169
+ try {
170
+ await control.sendChoice(run.ref.paneId, match[1]);
171
+ return { status: 'accepted' };
172
+ }
173
+ catch {
174
+ return { status: 'unknown', reason: 'temporarily_unavailable' };
175
+ }
176
+ },
177
+ };
178
+ }
@@ -1,10 +1,11 @@
1
1
  // The single built-in Agent registry. Runtime consumes the root AgentAdapter contract; legacy
2
2
  // orphan/transcript code sees a filtered projection of the same objects until those services migrate.
3
3
  import { claude } from './claude.js';
4
+ import { codebuddy } from './codebuddy.js';
4
5
  import { codex } from './codex.js';
5
6
  import { piAgentAdapter } from './pi.js';
6
7
  import { validateAgentAdapters } from '../agent-runtime/adapter.js';
7
- export const BUILTIN_AGENT_ADAPTERS = [claude, codex, piAgentAdapter];
8
+ export const BUILTIN_AGENT_ADAPTERS = [claude, codex, piAgentAdapter, codebuddy];
8
9
  export const BUILTIN_AGENT_ADAPTER_VALIDATION = validateAgentAdapters(BUILTIN_AGENT_ADAPTERS);
9
10
  function isLegacyDriver(adapter) {
10
11
  const candidate = adapter;
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { getAgent, agentForProc } from './agents/index.js';
5
+ import { hookEventKind } from './agents/hookEvents.js';
5
6
  import { resolveVersionedComms } from './agents/claude.js';
6
7
  import { resolveCodexComms } from './agents/codex.js';
7
8
  import { defaultRun } from './agents/scanUtils.js';
@@ -14,14 +15,12 @@ const here = path.dirname(fileURLToPath(import.meta.url));
14
15
  export const DEFAULT_STATE_FILE = process.env.CLAUDE_STATE_FILE || path.resolve(here, '../data/claude-state.json');
15
16
  // Classify a Claude hook event → inbox kind. Re-exported because tests and callers import this path.
16
17
  export const classifyEvent = claude.classify;
17
- const EVENT_KINDS = new Set([
18
- 'done', 'working', 'permission', 'compacting', 'error', 'end', 'idle',
19
- ]);
20
18
  const VIEW_LABEL = { needs: '需要你', done: '已完成' };
21
19
  const recordOf = (value) => value && typeof value === 'object' && !Array.isArray(value)
22
20
  ? value : null;
23
- const eventKind = (value) => typeof value === 'string' && EVENT_KINDS.has(value)
24
- ? value : null;
21
+ // The kind vocabulary itself is shared with every other Hook-driven provider; only Claude's own
22
+ // classification decisions live in agents/claude.ts.
23
+ const eventKind = hookEventKind;
25
24
  const pushView = (kind) => kind === 'permission' ? 'needs' : kind === 'done' ? 'done' : null;
26
25
  // The dedup key for a pane's current push view. `needs` is view-only: Claude signals one permission gate via
27
26
  // TWO hooks (permreq then permission_prompt) at different ts, and both must collapse to a SINGLE 需要你. But
@@ -3,8 +3,10 @@ import path from 'node:path';
3
3
  import { homedir } from 'node:os';
4
4
  import { installPiExtension, PiExtensionInstallError, piExtensionStatus, uninstallPiExtension, } from './piExtension.js';
5
5
  import { hooksHealthStatus, hooksStatus, installHooks, uninstallHooks } from './claudeHooks.js';
6
+ import { codebuddyStatePath } from './state.js';
7
+ import { hooksHealthStatus as codebuddyHooksHealthStatus, hooksStatus as codebuddyHooksStatus, installHooks as installCodebuddyHooks, uninstallHooks as uninstallCodebuddyHooks, } from './codebuddyHooks.js';
6
8
  import { statusLineStatus, uninstallStatusLine } from './statusLine.js';
7
- export const AGENT_NAMES = ['codex', 'pi', 'claude'];
9
+ export const AGENT_NAMES = ['codex', 'pi', 'claude', 'codebuddy'];
8
10
  const AGENT_NAME_SET = new Set(AGENT_NAMES);
9
11
  export function agentName(value) {
10
12
  return typeof value === 'string' && AGENT_NAME_SET.has(value) ? value : null;
@@ -37,12 +39,13 @@ export function executableOnPath(command, env = process.env, platform = process.
37
39
  }
38
40
  return false;
39
41
  }
40
- export function defaultAgentIntegrationContext({ home = homedir(), piEntryFile, hooksSrcDir, claudeStateFile, }) {
42
+ export function defaultAgentIntegrationContext({ home = homedir(), piEntryFile, hooksSrcDir, claudeStateFile, codebuddyStateFile, }) {
41
43
  return {
42
44
  home,
43
45
  piEntryFile,
44
46
  hooksSrcDir,
45
47
  claudeStateFile,
48
+ codebuddyStateFile: codebuddyStateFile ?? codebuddyStatePath(home),
46
49
  executableAvailable: (command) => executableOnPath(command),
47
50
  };
48
51
  }
@@ -61,6 +64,16 @@ export function agentIntegrationStatus(name, context) {
61
64
  return 'needs-repair';
62
65
  return status === 'installed' ? 'ready' : 'not-enabled';
63
66
  }
67
+ if (name === 'codebuddy') {
68
+ // Same rule as Claude: PATH decides whether CodeBuddy exists, but its first run creates ~/.codebuddy.
69
+ // Until that directory exists the integration is not enableable, and installHooks must never create it.
70
+ const status = codebuddyHooksHealthStatus(context.home);
71
+ if (status === 'no-codebuddy')
72
+ return 'not-enabled';
73
+ if (status === 'stale')
74
+ return 'needs-repair';
75
+ return status === 'installed' ? 'ready' : 'not-enabled';
76
+ }
64
77
  let status;
65
78
  try {
66
79
  status = piExtensionStatus(context.home, { entryFile: context.piEntryFile });
@@ -97,6 +110,15 @@ export function enableAgentIntegration(name, context) {
97
110
  const status = agentIntegrationStatus(name, context);
98
111
  return { name, status, changed: installed.status === 'installed' && before !== 'ready' };
99
112
  }
113
+ if (name === 'codebuddy') {
114
+ // The same script bundle and the same state-file contract as Claude, deployed into ~/.codebuddy/hooks.
115
+ const installed = installCodebuddyHooks(context.home, {
116
+ srcDir: context.hooksSrcDir,
117
+ stateFile: context.codebuddyStateFile ?? codebuddyStatePath(context.home),
118
+ });
119
+ const status = agentIntegrationStatus(name, context);
120
+ return { name, status, changed: installed.status === 'installed' && before !== 'ready' };
121
+ }
100
122
  try {
101
123
  const result = installPiExtension(context.home, { entryFile: context.piEntryFile });
102
124
  return { name, status: 'ready', changed: result.changed };
@@ -118,6 +140,13 @@ export function disableAgentIntegration(name, context) {
118
140
  uninstallStatusLine(context.home);
119
141
  return { name, status: 'not-enabled', changed };
120
142
  }
143
+ if (name === 'codebuddy') {
144
+ // CodeBuddy has no statusLine equivalent, so only its own hooks are removed — never another product's
145
+ // config, and never ~/.codebuddy itself.
146
+ const changed = codebuddyHooksStatus(context.home) === 'installed';
147
+ uninstallCodebuddyHooks(context.home);
148
+ return { name, status: 'not-enabled', changed };
149
+ }
121
150
  try {
122
151
  const result = uninstallPiExtension(context.home);
123
152
  return { name, status: 'not-enabled', changed: result.changed };
@@ -0,0 +1,286 @@
1
+ // Install/uninstall the CodeBuddy Code lifecycle hooks that feed the handmux inbox. Structurally this is
2
+ // claudeHooks.ts again — CodeBuddy's hooks follow the Claude Code settings schema — but it is a separate
3
+ // module on purpose: it writes another tool's config in another tool's directory, so it owns its own marker,
4
+ // its own settings file and its own script set. One installer must never edit two products' configs.
5
+ //
6
+ // Iron rule: only ever touch ~/.handmux/ and — after explicit opt-in — ~/.codebuddy/. If ~/.codebuddy is
7
+ // absent (no CodeBuddy), skip and report 'no-codebuddy'; never create it.
8
+ import { spawnSync } from 'node:child_process';
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { homedir } from 'node:os';
12
+ import { CODEBUDDY_HOOK_SET, deployHookScripts, removeHookScripts, shellWord, writeJsonAtomic, } from './hookScaffold.js';
13
+ const NOTIFY_SCRIPT = CODEBUDDY_HOOK_SET.notify;
14
+ const ENV_FILE = `${NOTIFY_SCRIPT.replace(/\.sh$/, '')}.env`;
15
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
16
+ const settingsOf = (value) => isRecord(value) ? { ...value } : {};
17
+ const readSettings = (home) => {
18
+ try {
19
+ return settingsOf(JSON.parse(fs.readFileSync(settingsPath(home), 'utf8')));
20
+ }
21
+ catch {
22
+ return {};
23
+ }
24
+ };
25
+ // The five events the inbox reads on CodeBuddy (verified against 2.155.0). src is the argument passed to
26
+ // handmux-codebuddy-notify.sh. No matcher: none of these are tool-scoped, so no per-tool-call hot path is
27
+ // added — the hook only ever fires at a session/turn boundary.
28
+ // SessionStart binds the pane→session mapping the instant a session begins. It is also the only payload
29
+ // carrying CodeBuddy's transcript_path, so without it the conversation page has no session to open.
30
+ // Keep this table in sync with ../../hooks/handmux-codebuddy-notify.sh.
31
+ export const HOOK_EVENTS = [
32
+ { event: 'Stop', src: 'stop' },
33
+ { event: 'Notification', src: 'notify' },
34
+ { event: 'UserPromptSubmit', src: 'prompt' },
35
+ { event: 'SessionStart', src: 'start' },
36
+ { event: 'SessionEnd', src: 'end' },
37
+ // The pair that owns "需要你": PermissionRequest lights it the moment the dialog appears, and PostToolUse on
38
+ // the two interaction tools clears it the moment the user answers — the same events Claude installs. Without
39
+ // them the state stays lit after the user replies, until the turn happens to end.
40
+ { event: 'PostToolUse', src: 'resume', matcher: 'AskUserQuestion|ExitPlanMode' },
41
+ { event: 'PermissionRequest', src: 'permreq' },
42
+ ];
43
+ // Version-gated events, mirroring Claude's: written only for a CLI new enough to emit them, pruned otherwise
44
+ // (fail-closed when the version cannot be read). Each closes a state we would otherwise light and never turn
45
+ // off:
46
+ // PreCompact → 压缩中 while compaction runs.
47
+ // PostCompact → clears it the instant compaction finishes.
48
+ // StopFailure → a turn that died on an API error (rate limit / overload / …) fires NO Stop, so without this
49
+ // the pane sticks at 进行中 forever; maps to an 'error' state.
50
+ // `pairWith` welds the invariant "never light a state you cannot turn off": PreCompact installs only together
51
+ // with its clearer PostCompact. minVersion is the version these were verified to exist in (2.155.0); lower it
52
+ // only after test-firing an older build.
53
+ const COMPACT_MIN = '2.155.0';
54
+ export const HOOK_EVENTS_EXT = [
55
+ { event: 'PostCompact', src: 'compact', minVersion: COMPACT_MIN },
56
+ { event: 'PreCompact', src: 'compacting', minVersion: COMPACT_MIN, pairWith: 'PostCompact' },
57
+ { event: 'StopFailure', src: 'stopfail', minVersion: COMPACT_MIN },
58
+ ];
59
+ const defaultVersionExec = (command, args, options) => {
60
+ const r = spawnSync(command, [...args], options);
61
+ return { status: r.status, stdout: r.stdout };
62
+ };
63
+ // Parse `codebuddy --version` output ("2.155.0") → { major, minor, patch } | null.
64
+ export function parseCodeBuddyVersion(out) {
65
+ const m = /(\d+)\.(\d+)\.(\d+)/.exec(String(out || ''));
66
+ return m ? { major: Number(m[1] ?? 0), minor: Number(m[2] ?? 0), patch: Number(m[3] ?? 0) } : null;
67
+ }
68
+ // v >= min ("X.Y.Z"); an unknown version is always below → the gate fails closed.
69
+ export function codeBuddyVersionAtLeast(v, minStr) {
70
+ if (!v)
71
+ return false;
72
+ const [a = 0, b = 0, c = 0] = String(minStr).split('.').map(Number);
73
+ if (v.major !== a)
74
+ return v.major > a;
75
+ if (v.minor !== b)
76
+ return v.minor > b;
77
+ return v.patch >= c;
78
+ }
79
+ // Detect the installed CodeBuddy version, or null when it cannot be run/parsed (→ ext events are skipped).
80
+ export function detectCodeBuddyVersion(exec = defaultVersionExec) {
81
+ try {
82
+ for (const command of ['codebuddy', 'cbc']) {
83
+ const r = exec(command, ['--version'], { encoding: 'utf8', timeout: 4000 });
84
+ if (r && r.status === 0 && r.stdout) {
85
+ const parsed = parseCodeBuddyVersion(r.stdout);
86
+ if (parsed)
87
+ return parsed;
88
+ }
89
+ }
90
+ return null;
91
+ }
92
+ catch {
93
+ return null;
94
+ }
95
+ }
96
+ // Identifies OUR hooks among the user's own. Distinct from Claude's marker, so neither installer can mistake
97
+ // the other's entries for its own even if a config directory is ever shared.
98
+ const HOOK_MARK = NOTIFY_SCRIPT;
99
+ const isOurHook = (value) => {
100
+ const hook = isRecord(value) ? value : null;
101
+ return typeof hook?.command === 'string' && hook.command.includes(HOOK_MARK);
102
+ };
103
+ const cleanGroup = (value) => {
104
+ if (!isRecord(value) || !Array.isArray(value.hooks))
105
+ return value;
106
+ return { ...value, hooks: value.hooks.filter((hook) => !isOurHook(hook)) };
107
+ };
108
+ const nonEmptyGroup = (value) => (!isRecord(value) || !Array.isArray(value.hooks) || value.hooks.length > 0);
109
+ function dropOurHook(hooks, event) {
110
+ if (!Array.isArray(hooks[event]))
111
+ return;
112
+ const kept = hooks[event].map(cleanGroup).filter(nonEmptyGroup);
113
+ if (kept.length)
114
+ hooks[event] = kept;
115
+ else
116
+ delete hooks[event];
117
+ }
118
+ function alreadyHas(hooks, event) {
119
+ const groups = hooks[event];
120
+ return Array.isArray(groups) && groups.some((group) => (isRecord(group) && Array.isArray(group.hooks) && group.hooks.some(isOurHook)));
121
+ }
122
+ function ownedHookCount(hooks, event) {
123
+ const groups = hooks[event];
124
+ if (!Array.isArray(groups))
125
+ return 0;
126
+ return groups.reduce((count, group) => (count + (isRecord(group) && Array.isArray(group.hooks)
127
+ ? group.hooks.filter(isOurHook).length : 0)), 0);
128
+ }
129
+ function hasExpectedHook(hooks, event, dest) {
130
+ const groups = hooks[event.event];
131
+ const command = `${shellWord(dest)} ${event.src}`;
132
+ return Array.isArray(groups) && groups.some((group) => (isRecord(group)
133
+ && group.matcher === (event.matcher ?? '')
134
+ && Array.isArray(group.hooks)
135
+ && group.hooks.some((hook) => (isRecord(hook)
136
+ && hook.type === 'command'
137
+ && hook.command === command
138
+ && hook.async === true
139
+ && hook.timeout === 5))));
140
+ }
141
+ // Merge one event's hook group into `hooks` (mutates), idempotently: first remove Handmux-owned entries for
142
+ // this event, then append the canonical destination. This repairs wrappers left by moved package installs
143
+ // without touching any user/third-party hook that does not carry our marker.
144
+ function addHook(hooks, e, dest) {
145
+ if (ownedHookCount(hooks, e.event) === 1 && hasExpectedHook(hooks, e, dest))
146
+ return;
147
+ dropOurHook(hooks, e.event);
148
+ const existing = hooks[e.event];
149
+ const groups = hooks[e.event] = Array.isArray(existing) ? [...existing] : [];
150
+ groups.push({
151
+ matcher: e.matcher ?? '',
152
+ hooks: [{ type: 'command', command: `${shellWord(dest)} ${e.src}`, async: true, timeout: 5 }],
153
+ });
154
+ }
155
+ // Pure: return a NEW settings object with our hooks merged into settings.hooks, idempotently, leaving
156
+ // the user's own hooks and other keys untouched. `dest` is the absolute path to the copied notify script.
157
+ export function mergeHooks(settings, dest, codebuddyVersion = null) {
158
+ const s = settingsOf(settings);
159
+ const hooks = isRecord(s.hooks) ? { ...s.hooks } : {};
160
+ for (const e of HOOK_EVENTS)
161
+ addHook(hooks, e, dest);
162
+ // Extension events: only for a CLI that emits them, and only with their clearer installed too.
163
+ const enabled = new Set();
164
+ for (const e of HOOK_EVENTS_EXT) {
165
+ const ok = !!e.minVersion
166
+ && codeBuddyVersionAtLeast(codebuddyVersion, e.minVersion)
167
+ && (!e.pairWith || enabled.has(e.pairWith));
168
+ if (ok) {
169
+ enabled.add(e.event);
170
+ addHook(hooks, e, dest);
171
+ }
172
+ else
173
+ dropOurHook(hooks, e.event);
174
+ }
175
+ s.hooks = hooks;
176
+ return s;
177
+ }
178
+ // Pure: return a NEW settings object with all of OUR hooks removed (uninstall). An event group that ends up
179
+ // empty is dropped; the user's own hooks and other keys are untouched.
180
+ export function stripHooks(settings) {
181
+ const s = settingsOf(settings);
182
+ if (!isRecord(s.hooks))
183
+ return s;
184
+ const hooks = {};
185
+ for (const [event, groups] of Object.entries(s.hooks)) {
186
+ if (!Array.isArray(groups)) {
187
+ hooks[event] = groups;
188
+ continue;
189
+ }
190
+ const kept = groups.map(cleanGroup).filter(nonEmptyGroup);
191
+ if (kept.length)
192
+ hooks[event] = kept;
193
+ }
194
+ s.hooks = hooks;
195
+ return s;
196
+ }
197
+ function codebuddyDir(home = homedir()) { return path.join(home, '.codebuddy'); }
198
+ function settingsPath(home = homedir()) {
199
+ return path.join(codebuddyDir(home), 'settings.json');
200
+ }
201
+ function notifyDest(home = homedir()) {
202
+ return path.join(codebuddyDir(home), 'hooks', NOTIFY_SCRIPT);
203
+ }
204
+ // 'no-codebuddy' → ~/.codebuddy absent (don't prompt to enable). 'installed' → our hooks present. 'absent' →
205
+ // CodeBuddy is here but our hooks aren't (offer to enable).
206
+ export function hooksStatus(home = homedir()) {
207
+ if (!fs.existsSync(codebuddyDir(home)))
208
+ return 'no-codebuddy';
209
+ const settings = readSettings(home);
210
+ const hooks = isRecord(settings.hooks) ? settings.hooks : {};
211
+ return Object.keys(hooks).some((ev) => alreadyHas(hooks, ev)) ? 'installed' : 'absent';
212
+ }
213
+ function regularFile(file) {
214
+ try {
215
+ return fs.statSync(file).isFile();
216
+ }
217
+ catch {
218
+ return false;
219
+ }
220
+ }
221
+ // Stronger diagnostic used by `handmux agent`: any partial/old registration is repairable, not ready. Every
222
+ // registered event and every deployed runtime file is required.
223
+ export function hooksHealthStatus(home = homedir()) {
224
+ const status = hooksStatus(home);
225
+ if (status !== 'installed')
226
+ return status;
227
+ const hooksDir = path.join(codebuddyDir(home), 'hooks');
228
+ const dest = notifyDest(home);
229
+ const settings = readSettings(home);
230
+ const hooks = isRecord(settings.hooks) ? settings.hooks : {};
231
+ if (!HOOK_EVENTS.every((event) => (ownedHookCount(hooks, event.event) === 1 && hasExpectedHook(hooks, event, dest))))
232
+ return 'stale';
233
+ if (![dest, path.join(hooksDir, 'handmux-write.cjs'), path.join(hooksDir, ENV_FILE)].every(regularFile)) {
234
+ return 'stale';
235
+ }
236
+ return 'installed';
237
+ }
238
+ // Install (opt-in): copy the bundled hook scripts to ~/.codebuddy/hooks/, write the env pointing at the state
239
+ // file, and merge our hooks into settings.json. NEVER creates ~/.codebuddy — if it's absent the user
240
+ // doesn't run CodeBuddy, so we report 'no-codebuddy' and do nothing.
241
+ // srcDir = the bundled hooks dir (server/hooks)
242
+ // stateFile = the unified ~/.handmux/codebuddy-state.json path the hook writes and the server reads
243
+ export function installHooks(home = homedir(), { srcDir, stateFile, codebuddyVersion } = {}) {
244
+ if (!fs.existsSync(codebuddyDir(home)))
245
+ return { status: 'no-codebuddy' };
246
+ if (!srcDir || !stateFile)
247
+ throw new Error('hook srcDir and stateFile are required');
248
+ deployHookScripts(path.join(codebuddyDir(home), 'hooks'), srcDir, stateFile, CODEBUDDY_HOOK_SET);
249
+ const settings = readSettings(home);
250
+ const version = codebuddyVersion !== undefined ? codebuddyVersion : detectCodeBuddyVersion();
251
+ writeJsonAtomic(settingsPath(home), mergeHooks(settings, notifyDest(home), version));
252
+ return { status: 'installed' };
253
+ }
254
+ // Keep an ALREADY-installed user's hooks in step with this handmux version on every server start, so a plain
255
+ // `./deploy.sh` (restart) rolls out newly-added lifecycle events and refreshed hook scripts — no phone
256
+ // re-enable needed. Strictly opt-in-preserving: a NO-OP unless our hooks are already present ('installed').
257
+ // It never enables hooks for a user who hasn't opted in ('absent') and never creates ~/.codebuddy
258
+ // ('no-codebuddy'). settings.json is rewritten only when the merge actually changes it, so a steady state
259
+ // writes nothing.
260
+ export function syncHooks(home = homedir(), { srcDir, stateFile } = {}) {
261
+ const status = hooksStatus(home);
262
+ if (status !== 'installed')
263
+ return { status, changed: false };
264
+ if (!srcDir || !stateFile)
265
+ throw new Error('hook srcDir and stateFile are required');
266
+ deployHookScripts(path.join(codebuddyDir(home), 'hooks'), srcDir, stateFile, CODEBUDDY_HOOK_SET);
267
+ const dest = notifyDest(home);
268
+ const settings = readSettings(home);
269
+ const hooks = isRecord(settings.hooks) ? { ...settings.hooks } : {};
270
+ const before = JSON.stringify(hooks);
271
+ for (const e of HOOK_EVENTS)
272
+ addHook(hooks, e, dest); // add only MISSING events
273
+ const changed = JSON.stringify(hooks) !== before;
274
+ if (changed)
275
+ writeJsonAtomic(settingsPath(home), { ...settings, hooks });
276
+ return { status: 'installed', changed };
277
+ }
278
+ // Uninstall: strip our hooks from settings.json and remove the copied scripts/env. Best-effort on the file
279
+ // deletes (a missing file is fine). Leaves ~/.codebuddy and the user's own hooks intact.
280
+ export function uninstallHooks(home = homedir()) {
281
+ const settings = readSettings(home);
282
+ if (fs.existsSync(settingsPath(home)))
283
+ writeJsonAtomic(settingsPath(home), stripHooks(settings));
284
+ removeHookScripts(path.join(codebuddyDir(home), 'hooks'), CODEBUDDY_HOOK_SET);
285
+ return { status: 'absent' };
286
+ }
@@ -1,8 +1,19 @@
1
- // Shared IO scaffolding for the Claude Code hook installer and statusLine capturer.
1
+ // Shared IO scaffolding for the Agent hook installers and statusLine capturer.
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
- export const HOOK_SCRIPTS = ['handmux-notify.sh', 'handmux-write.cjs'];
5
- const LEGACY_HOOK_SCRIPTS = ['handmux-codex-usage.cjs'];
4
+ // The writer is shared by every Agent: the spool/state protocol is the Agent-independent half.
5
+ const WRITER_SCRIPT = 'handmux-write.cjs';
6
+ export const CLAUDE_HOOK_SET = {
7
+ notify: 'handmux-notify.sh',
8
+ eventsVar: 'HANDMUX_CLAUDE_EVENTS',
9
+ legacy: ['handmux-codex-usage.cjs'],
10
+ };
11
+ export const CODEBUDDY_HOOK_SET = {
12
+ notify: 'handmux-codebuddy-notify.sh',
13
+ eventsVar: 'HANDMUX_CODEBUDDY_EVENTS',
14
+ };
15
+ // `handmux-notify.sh` → `handmux-notify.env`, alongside the script so `<dir>/<name>.env` is what sh sources.
16
+ const hookEnvName = (hookSet) => `${hookSet.notify.replace(/\.sh$/, '')}.env`;
6
17
  // Env files are sourced by /bin/sh; settings commands use the same shell word syntax.
7
18
  export const shellWord = (value) => /^[a-zA-Z0-9_./-]+$/.test(value)
8
19
  ? value : `'${value.replace(/'/g, `'"'"'`)}'`;
@@ -14,27 +25,29 @@ export function writeFileAtomic(file, text) {
14
25
  fs.renameSync(tmp, file);
15
26
  }
16
27
  export const writeJsonAtomic = (file, value) => (writeFileAtomic(file, JSON.stringify(value, null, 2)));
17
- // Deploy the Claude notify/write scripts into `hooksDir` and point their env at the shared state file.
18
- export function deployHookScripts(hooksDir, srcDir, stateFile) {
28
+ // Deploy an Agent's notify/write scripts into `hooksDir` and point their env at the shared state file.
29
+ export function deployHookScripts(hooksDir, srcDir, stateFile, hookSet = CLAUDE_HOOK_SET) {
19
30
  fs.mkdirSync(hooksDir, { recursive: true });
20
- for (const f of HOOK_SCRIPTS)
31
+ for (const f of [hookSet.notify, WRITER_SCRIPT]) {
21
32
  fs.copyFileSync(path.join(srcDir, f), path.join(hooksDir, f));
22
- for (const f of LEGACY_HOOK_SCRIPTS) {
33
+ }
34
+ for (const f of hookSet.legacy ?? []) {
23
35
  try {
24
36
  fs.unlinkSync(path.join(hooksDir, f));
25
37
  }
26
38
  catch { /* absent */ }
27
39
  }
28
- fs.chmodSync(path.join(hooksDir, 'handmux-notify.sh'), 0o755);
29
- fs.writeFileSync(path.join(hooksDir, 'handmux-notify.env'), [
40
+ fs.chmodSync(path.join(hooksDir, hookSet.notify), 0o755);
41
+ fs.writeFileSync(path.join(hooksDir, hookEnvName(hookSet)), [
30
42
  `HANDMUX_STATE=${shellWord(stateFile)}`,
31
- `HANDMUX_CLAUDE_EVENTS=${shellWord(`${stateFile}.events`)}`,
43
+ `${hookSet.eventsVar}=${shellWord(`${stateFile}.events`)}`,
32
44
  '',
33
45
  ].join('\n'), { mode: 0o600 });
34
46
  }
35
47
  // Remove the deployed scripts + env (uninstall). Best-effort: a missing file is fine.
36
- export function removeHookScripts(hooksDir) {
37
- for (const f of [...HOOK_SCRIPTS, ...LEGACY_HOOK_SCRIPTS, 'handmux-notify.env']) {
48
+ export function removeHookScripts(hooksDir, hookSet = CLAUDE_HOOK_SET) {
49
+ const files = [hookSet.notify, WRITER_SCRIPT, hookEnvName(hookSet), ...(hookSet.legacy ?? [])];
50
+ for (const f of files) {
38
51
  try {
39
52
  fs.unlinkSync(path.join(hooksDir, f));
40
53
  }
@@ -180,7 +180,7 @@ export default {
180
180
  'agent.codexBuiltIn': '= Codex integration is built in and already ready.',
181
181
  'agent.codexDisable': 'Codex integration is built in and cannot be disabled. Run native `codex` directly to bypass Handmux.',
182
182
  'agent.unknown': 'unknown Agent: {name}',
183
- 'agent.usage': 'usage: handmux agent [list] | handmux agent status|enable|disable <codex|pi|claude>',
183
+ 'agent.usage': 'usage: handmux agent [list] | handmux agent status|enable|disable <codex|pi|claude|codebuddy>',
184
184
  // Pi Extension
185
185
  'piExtension.confirmEnable': 'Enable the Pi integration with Handmux?',
186
186
  'piExtension.installed': '✓ Pi integration enabled.',