golem-kit 0.2.3 → 0.2.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.4
4
+
5
+ - Chat and builder no longer fight over one Stop hook: the turn-end relay asks tmux which window it ran in instead of trusting the key baked in when it was installed, so a chat message sent after the builder was opened gets its reply and the composer unlocks. `installHooks` also keeps exactly one entry for itself, matched by script name, so a source-pin change between releases replaces it instead of stacking another.
6
+
3
7
  ## 0.2.3
4
8
 
5
9
  - A model pin follows its agent: change `chat.agent` (or `agents.builder`) and the conversation saved on the old agent is retired on the next start instead of resumed with the new agent's pin. It stays readable in `.golem/conversations.json`, marked, and the next message opens a fresh conversation on the configured agent.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "golem-kit",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Starter kit and local CLI for Golem applications.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -161,18 +161,19 @@ async function installHooks(cwd, session, stateDir, callbackUrl) {
161
161
  const command = ['node', s.shellQuote(HOOK_SCRIPT), s.shellQuote(stateDir), s.shellQuote(session)]
162
162
  .concat(callbackUrl ? [s.shellQuote(callbackUrl)] : [])
163
163
  .join(' ');
164
+ const hookName = path.basename(HOOK_SCRIPT);
164
165
  mergeLocalSettings(cwd, (settings) => {
165
166
  if (!settings.hooks || typeof settings.hooks !== 'object') settings.hooks = {};
166
167
  if (!Array.isArray(settings.hooks.Stop)) settings.hooks.Stop = [];
167
- const ours = settings.hooks.Stop.some((m) =>
168
- Array.isArray(m.hooks) && m.hooks.some((h) => h.command === command));
169
- if (!ours) {
170
- // Drop stale bc hook entries (e.g. a previous session in this cwd) first.
171
- settings.hooks.Stop = settings.hooks.Stop.filter((m) =>
172
- !(Array.isArray(m.hooks) && m.hooks.some((h) =>
173
- typeof h.command === 'string' && h.command.includes(HOOK_SCRIPT))));
174
- settings.hooks.Stop.push({ hooks: [{ type: 'command', command }] });
175
- }
168
+ // Exactly ONE entry for our script, always. Matched on the basename, not the
169
+ // full path: a source pin (or an npx cache) moves the script between releases,
170
+ // and a path match let one entry per path pile up — every turn end then wrote
171
+ // every stale key's file. The hook resolves its own key at run time, so the
172
+ // single surviving entry serves every window in this cwd.
173
+ settings.hooks.Stop = settings.hooks.Stop.filter((m) =>
174
+ !(Array.isArray(m.hooks) && m.hooks.some((h) =>
175
+ typeof h.command === 'string' && h.command.includes(hookName))));
176
+ settings.hooks.Stop.push({ hooks: [{ type: 'command', command }] });
176
177
  });
177
178
  await excludeLocalSettings(cwd);
178
179
  }
@@ -22,18 +22,33 @@ const fs = require('node:fs');
22
22
  const path = require('node:path');
23
23
  const { execFileSync } = require('node:child_process');
24
24
 
25
- // The hook runs inside the agent's own pane, so its tmux session identifies
26
- // the session exactly (the server attributes lieutenant turn-ends by it).
25
+ // The hook runs inside the agent's own pane, so tmux identifies it exactly.
27
26
  // Empty when not under tmux; never fails the hook when tmux is absent.
28
- function tmuxSession() {
27
+ // golem: '#S:#W', and -t $TMUX_PANE, because a bare display-message answers for
28
+ // the session's ACTIVE window — from the builder's pane, while the chat window
29
+ // was current, it said ':chat'. The pane id is the only self-reference a hook
30
+ // running outside the active window can trust.
31
+ function tmuxPane() {
29
32
  if (!process.env.TMUX) return '';
33
+ const target = process.env.TMUX_PANE ? ['-t', process.env.TMUX_PANE] : [];
30
34
  try {
31
- return execFileSync('tmux', ['display-message', '-p', '#S'], { encoding: 'utf8' }).trim();
35
+ return execFileSync('tmux', ['display-message', '-p'].concat(target, ['#S:#W']), { encoding: 'utf8' }).trim();
32
36
  } catch {
33
37
  return '';
34
38
  }
35
39
  }
36
40
 
41
+ // golem: runtimeKey(argvKey) — which agent's turn just ended.
42
+ // Claude Code keeps ONE Stop hook per cwd, and window-granular agents (the
43
+ // builder and the chat) share a cwd: the key baked into argv at install time is
44
+ // whichever spawned last, so the other one's turn ends would land in the wrong
45
+ // file and its send() would wait forever. Ask tmux instead. Session-granular
46
+ // agents own their whole session (no ':' in their key) and keep the argv key.
47
+ function runtimeKey(argvKey) {
48
+ if (!argvKey.includes(':')) return argvKey;
49
+ return tmuxPane() || argvKey;
50
+ }
51
+
37
52
  function readStdin() {
38
53
  return new Promise((resolve) => {
39
54
  let data = '';
@@ -53,7 +68,7 @@ function readStdin() {
53
68
 
54
69
  async function main() {
55
70
  const stateDir = process.argv[2];
56
- const session = process.argv[3];
71
+ const session = runtimeKey(process.argv[3] || '');
57
72
  const url = process.argv[4] || process.env.BC_TURNEND_URL || '';
58
73
  if (!stateDir || !session) return;
59
74
 
@@ -70,7 +85,7 @@ async function main() {
70
85
  event: payload.hook_event_name || 'Stop',
71
86
  session_id: payload.session_id || null,
72
87
  cwd: payload.cwd || null,
73
- tmux_session: tmuxSession(),
88
+ tmux_session: tmuxPane().split(':')[0],
74
89
  };
75
90
  // What the agent last said, when the harness hands it over — the stall
76
91
  // alert quotes it so the board knows what a silent worker was waiting on.