@webority/ensemble 0.2.1 → 0.2.3

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 (2) hide show
  1. package/lib/core.js +12 -5
  2. package/package.json +1 -1
package/lib/core.js CHANGED
@@ -169,11 +169,18 @@ function mergeClaudeHooks(file, busInvoke) {
169
169
  let s = {};
170
170
  try { if (fs.existsSync(file)) s = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (e) { s = {}; }
171
171
  s.hooks = s.hooks || {};
172
- const cmd = (ev) => ({ hooks: [{ type: 'command', command: `"${busInvoke}" hook ${ev} --engine claude 2>/dev/null || true` }] });
173
- s.hooks.SessionStart = [cmd('session-start')];
174
- s.hooks.UserPromptSubmit = [cmd('user-prompt')];
175
- s.hooks.Stop = [cmd('stop')];
176
- s.hooks.SessionEnd = [cmd('session-end')];
172
+ // APPEND our bus hook, never replace preserve the user's other hooks (config sync, etc.).
173
+ // Re-enroll is idempotent: strip any prior ensemble-bus hook first, then add the current one.
174
+ const events = { SessionStart: 'session-start', UserPromptSubmit: 'user-prompt', Stop: 'stop', SessionEnd: 'session-end' };
175
+ for (const [evt, ev] of Object.entries(events)) {
176
+ const command = `"${busInvoke}" hook ${ev} --engine claude 2>/dev/null || true`;
177
+ const groups = Array.isArray(s.hooks[evt]) ? s.hooks[evt] : [];
178
+ const kept = groups
179
+ .map((g) => ({ ...g, hooks: (g.hooks || []).filter((h) => !/ensemble-bus/i.test(h.command || '')) }))
180
+ .filter((g) => (g.hooks || []).length > 0);
181
+ kept.push({ hooks: [{ type: 'command', command }] });
182
+ s.hooks[evt] = kept;
183
+ }
177
184
  fs.writeFileSync(file, JSON.stringify(s, null, 2));
178
185
  }
179
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/ensemble",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Connect this machine to your Ensemble control plane — runs the local agent runner and wires the ensemble-bus session bus so your coding sessions talk (per-org, isolated).",
5
5
  "bin": {
6
6
  "ensemble": "bin/ensemble.js"