@sesamespace/hivemind 0.12.1 → 0.12.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.
@@ -0,0 +1,58 @@
1
+ {
2
+ "timestamp": "2026-03-10T00:00:00Z",
3
+ "summary": "Fixed stale PID reporting in `hivemind service status` by rewriting showStatus() to parse PIDs from `launchctl list` output instead of PID files. Added kickstart recovery for KeepAlive services (memory, watchdog). Removed hardcoded wrapper scripts from git tracking and added them to .gitignore since they are generated dynamically during `hivemind service install`.",
4
+ "decisions": [
5
+ {
6
+ "topic": "PID source",
7
+ "choice": "Parse PID from launchctl list output using regex",
8
+ "rationale": "launchctl is the authoritative source for launchd-managed process PIDs; PID files go stale when launchd restarts a crashed process",
9
+ "alternatives_considered": ["Keep PID file approach with periodic refresh", "Use ps/pgrep to find processes"]
10
+ },
11
+ {
12
+ "topic": "Stale service recovery",
13
+ "choice": "Auto-kickstart KeepAlive services (memory, watchdog) but not agent",
14
+ "rationale": "Agent is managed by watchdog, so kickstarting it from status would bypass watchdog's coordination",
15
+ "alternatives_considered": ["Kickstart all services", "Only report status without recovery"]
16
+ }
17
+ ],
18
+ "patterns": [
19
+ {
20
+ "pattern": "Wrapper scripts in bin/ are generated dynamically during `hivemind service install` with correct local paths — never commit them",
21
+ "scope": "project-wide"
22
+ }
23
+ ],
24
+ "gotchas": [
25
+ {
26
+ "issue": "Wrapper scripts had hardcoded paths from another developer's machine committed to git",
27
+ "resolution": "Removed from git tracking with `git rm --cached`, added bin/*-wrapper.sh to .gitignore",
28
+ "prevention": "The .gitignore entry will prevent future accidental commits"
29
+ }
30
+ ],
31
+ "files_changed": [
32
+ {
33
+ "path": "packages/cli/src/commands/service.ts",
34
+ "action": "modified",
35
+ "purpose": "Rewrote showStatus() to use launchctl as PID source with kickstart recovery"
36
+ },
37
+ {
38
+ "path": ".gitignore",
39
+ "action": "modified",
40
+ "purpose": "Added bin/*-wrapper.sh pattern"
41
+ },
42
+ {
43
+ "path": "bin/agent-wrapper.sh",
44
+ "action": "deleted",
45
+ "purpose": "Removed hardcoded wrapper script from git tracking"
46
+ },
47
+ {
48
+ "path": "bin/memory-wrapper.sh",
49
+ "action": "deleted",
50
+ "purpose": "Removed hardcoded wrapper script from git tracking"
51
+ },
52
+ {
53
+ "path": "bin/watchdog-wrapper.sh",
54
+ "action": "deleted",
55
+ "purpose": "Removed hardcoded wrapper script from git tracking"
56
+ }
57
+ ]
58
+ }
@@ -7,7 +7,7 @@ import {
7
7
  SesameClient2 as SesameClient,
8
8
  WORKER_ROUTES,
9
9
  createLogger
10
- } from "./chunk-7XXV5FKN.js";
10
+ } from "./chunk-TQYOGZIN.js";
11
11
 
12
12
  // packages/runtime/src/watchdog.ts
13
13
  import { execSync } from "child_process";
@@ -1095,4 +1095,4 @@ export {
1095
1095
  WorkerMemorySync,
1096
1096
  PrimaryMemorySync
1097
1097
  };
1098
- //# sourceMappingURL=chunk-6IAV6YAV.js.map
1098
+ //# sourceMappingURL=chunk-3SIWFXC7.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  FleetManager
3
- } from "./chunk-6IAV6YAV.js";
3
+ } from "./chunk-3SIWFXC7.js";
4
4
 
5
5
  // packages/cli/src/commands/fleet.ts
6
6
  function formatUptime(seconds) {
@@ -183,4 +183,4 @@ Commands:
183
183
  export {
184
184
  runFleetCommand
185
185
  };
186
- //# sourceMappingURL=chunk-AZ2ZKLN3.js.map
186
+ //# sourceMappingURL=chunk-6W56VBXG.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  startPipeline
3
- } from "./chunk-7XXV5FKN.js";
3
+ } from "./chunk-TQYOGZIN.js";
4
4
 
5
5
  // packages/cli/src/commands/start.ts
6
6
  import { resolve } from "path";
@@ -66,4 +66,4 @@ Options:
66
66
  export {
67
67
  runStartCommand
68
68
  };
69
- //# sourceMappingURL=chunk-DD7TRNOD.js.map
69
+ //# sourceMappingURL=chunk-7HOPTFRU.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Watchdog
3
- } from "./chunk-6IAV6YAV.js";
3
+ } from "./chunk-3SIWFXC7.js";
4
4
  import {
5
5
  defaultSentinelConfig,
6
6
  loadConfig
7
- } from "./chunk-7XXV5FKN.js";
7
+ } from "./chunk-TQYOGZIN.js";
8
8
 
9
9
  // packages/cli/src/commands/watchdog.ts
10
10
  import { resolve } from "path";
@@ -76,4 +76,4 @@ Options:
76
76
  export {
77
77
  runWatchdogCommand
78
78
  };
79
- //# sourceMappingURL=chunk-VAR7O4UE.js.map
79
+ //# sourceMappingURL=chunk-EDSK2CG6.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SesameClient,
3
3
  getClaudeCodeOAuthToken
4
- } from "./chunk-7XXV5FKN.js";
4
+ } from "./chunk-TQYOGZIN.js";
5
5
 
6
6
  // packages/cli/src/commands/init.ts
7
7
  import { resolve, dirname } from "path";
@@ -436,4 +436,4 @@ Options:
436
436
  export {
437
437
  runInitCommand
438
438
  };
439
- //# sourceMappingURL=chunk-Y2FWCQDX.js.map
439
+ //# sourceMappingURL=chunk-KOSNIWPS.js.map
@@ -7885,6 +7885,18 @@ function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
7885
7885
  }
7886
7886
  const escapedTask = task.replace(/'/g, "'\\''");
7887
7887
  const command = `claude --dangerously-skip-permissions -p '${escapedTask}'`;
7888
+ let needHandler;
7889
+ let errorHandler;
7890
+ if (contextBridge) {
7891
+ needHandler = (need) => {
7892
+ console.log(`[Claude needs context]: ${need}`);
7893
+ };
7894
+ contextBridge.on("context-request", needHandler);
7895
+ errorHandler = (error) => {
7896
+ console.log(`[Claude encountered error]: ${error}`);
7897
+ };
7898
+ contextBridge.on("error-encountered", errorHandler);
7899
+ }
7888
7900
  try {
7889
7901
  const output = await new Promise((resolve21, reject) => {
7890
7902
  const child = exec2(command, {
@@ -7893,7 +7905,6 @@ function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
7893
7905
  encoding: "utf-8",
7894
7906
  maxBuffer: 10 * 1024 * 1024,
7895
7907
  // 10MB
7896
- shell: "/bin/sh",
7897
7908
  env: {
7898
7909
  ...process.env,
7899
7910
  PATH: extendedPath
@@ -7909,9 +7920,35 @@ function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
7909
7920
  });
7910
7921
  child.stdin?.end();
7911
7922
  });
7923
+ let summaryText = "";
7924
+ if (contextBridge) {
7925
+ try {
7926
+ const summary = await contextBridge.getSessionSummary();
7927
+ if (summary.discoveries.length > 0) {
7928
+ summaryText += `
7929
+
7930
+ ## Discoveries Made:
7931
+ ${summary.discoveries.map((d) => `- ${d}`).join("\n")}`;
7932
+ }
7933
+ if (summary.patterns.length > 0) {
7934
+ summaryText += `
7935
+
7936
+ ## Patterns Found:
7937
+ ${summary.patterns.map((p) => `- ${p}`).join("\n")}`;
7938
+ }
7939
+ if (summary.errors.length > 0) {
7940
+ summaryText += `
7941
+
7942
+ ## Errors Encountered:
7943
+ ${summary.errors.map((e) => `- ${e}`).join("\n")}`;
7944
+ }
7945
+ } catch (err) {
7946
+ console.warn("Failed to get session summary:", err);
7947
+ }
7948
+ }
7912
7949
  const trimmed = output.length > MAX_OUTPUT6 ? output.slice(0, MAX_OUTPUT6) + `
7913
7950
  ... (truncated, ${output.length} total chars)` : output;
7914
- return trimmed || "(no output)";
7951
+ return (trimmed || "(no output)") + summaryText;
7915
7952
  } catch (err) {
7916
7953
  if (err.killed) {
7917
7954
  return `Error: Claude Code timed out after ${timeoutSeconds}s`;
@@ -7922,6 +7959,13 @@ function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
7922
7959
  const code = err.status ?? "unknown";
7923
7960
  return `Claude Code failed (exit code ${code}):
7924
7961
  ${output || err.message}`;
7962
+ } finally {
7963
+ if (contextBridge && needHandler) {
7964
+ contextBridge.off("context-request", needHandler);
7965
+ }
7966
+ if (contextBridge && errorHandler) {
7967
+ contextBridge.off("error-encountered", errorHandler);
7968
+ }
7925
7969
  }
7926
7970
  }
7927
7971
  );
@@ -8594,7 +8638,7 @@ import { resolve as resolve20, dirname as dirname8 } from "path";
8594
8638
  import { fileURLToPath as fileURLToPath3 } from "url";
8595
8639
 
8596
8640
  // packages/runtime/src/tools/context-bridge.ts
8597
- import { writeFileSync as writeFileSync8, existsSync as existsSync20, mkdirSync as mkdirSync15, watchFile, unwatchFile, openSync, readSync, closeSync } from "fs";
8641
+ import { writeFileSync as writeFileSync8, existsSync as existsSync20, mkdirSync as mkdirSync15, openSync, readSync, closeSync } from "fs";
8598
8642
  import { join as join8 } from "path";
8599
8643
  import { homedir } from "os";
8600
8644
  import { EventEmitter as EventEmitter2 } from "events";
@@ -8604,6 +8648,9 @@ var ClaudeContextBridge = class extends EventEmitter2 {
8604
8648
  logger;
8605
8649
  sessionLogPath;
8606
8650
  contextFilePath;
8651
+ watchInterval = null;
8652
+ lastLogSize = 0;
8653
+ seenPatterns = /* @__PURE__ */ new Set();
8607
8654
  constructor(config) {
8608
8655
  super();
8609
8656
  this.workspaceDir = config.workspaceDir;
@@ -8722,25 +8769,33 @@ ${memories.join("\n\n")}
8722
8769
  if (!existsSync20(this.sessionLogPath)) {
8723
8770
  writeFileSync8(this.sessionLogPath, "");
8724
8771
  }
8725
- let lastSize = 0;
8726
- watchFile(this.sessionLogPath, { interval: 2e3 }, (curr) => {
8727
- if (curr.size > lastSize) {
8728
- try {
8729
- const fd = openSync(this.sessionLogPath, "r");
8730
- const buf = Buffer.alloc(curr.size - lastSize);
8731
- readSync(fd, buf, 0, buf.length, lastSize);
8732
- closeSync(fd);
8733
- lastSize = curr.size;
8734
- const lines = buf.toString("utf-8").split("\n").filter((l) => l.trim());
8735
- for (const line of lines) {
8736
- this.processLogLine(line);
8737
- }
8738
- } catch (err) {
8739
- this.logger.warn("Failed to read session log", { error: String(err) });
8772
+ const stats = existsSync20(this.sessionLogPath) ? __require("fs").statSync(this.sessionLogPath) : { size: 0 };
8773
+ this.lastLogSize = stats.size;
8774
+ this.watchInterval = setInterval(() => {
8775
+ this.checkForLogUpdates();
8776
+ }, 500);
8777
+ this.logger.info("Started real-time monitoring of Claude session log");
8778
+ }
8779
+ /**
8780
+ * Check for new log entries
8781
+ */
8782
+ checkForLogUpdates() {
8783
+ try {
8784
+ const stats = __require("fs").statSync(this.sessionLogPath);
8785
+ if (stats.size > this.lastLogSize) {
8786
+ const fd = openSync(this.sessionLogPath, "r");
8787
+ const buf = Buffer.alloc(stats.size - this.lastLogSize);
8788
+ readSync(fd, buf, 0, buf.length, this.lastLogSize);
8789
+ closeSync(fd);
8790
+ this.lastLogSize = stats.size;
8791
+ const lines = buf.toString("utf-8").split("\n").filter((l) => l.trim());
8792
+ for (const line of lines) {
8793
+ this.processLogLine(line);
8740
8794
  }
8741
8795
  }
8742
- });
8743
- this.logger.info("Started monitoring Claude session log");
8796
+ } catch (err) {
8797
+ this.logger.warn("Failed to check session log", { error: String(err) });
8798
+ }
8744
8799
  }
8745
8800
  /**
8746
8801
  * Process a line from Claude's session log
@@ -8770,28 +8825,125 @@ ${memories.join("\n\n")}
8770
8825
  async handleInsight(type, content) {
8771
8826
  this.logger.info(`Claude insight: ${type}`, { content });
8772
8827
  this.emit("insight", { type, content });
8828
+ if (type === "PATTERN") {
8829
+ const patternHash = __require("crypto").createHash("md5").update(content).digest("hex");
8830
+ if (this.seenPatterns.has(patternHash)) {
8831
+ this.logger.debug("Skipping duplicate pattern", { content });
8832
+ return;
8833
+ }
8834
+ this.seenPatterns.add(patternHash);
8835
+ }
8773
8836
  if (["DISCOVERY", "PATTERN"].includes(type)) {
8774
8837
  try {
8775
8838
  await this.memoryClient.storeEpisode({
8776
- context_name: "claude-code",
8839
+ context_name: "claude-code-insights",
8777
8840
  role: "system",
8778
- content: `Claude Code ${type}: ${content}`
8841
+ content: `${type}: ${content}`,
8842
+ metadata: {
8843
+ type,
8844
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
8845
+ source: "claude-code"
8846
+ }
8779
8847
  });
8848
+ this.logger.info(`Stored ${type} in memory`, { content });
8780
8849
  } catch (err) {
8781
8850
  this.logger.warn("Failed to store Claude insight in memory", err);
8782
8851
  }
8783
8852
  }
8784
- if (type === "NEED") {
8785
- this.emit("context-request", content);
8853
+ switch (type) {
8854
+ case "NEED":
8855
+ this.emit("context-request", content);
8856
+ await this.tryProvideContext(content);
8857
+ break;
8858
+ case "ERROR":
8859
+ this.emit("error-encountered", content);
8860
+ break;
8861
+ case "COMPLETE":
8862
+ this.emit("task-complete", content);
8863
+ break;
8864
+ }
8865
+ }
8866
+ /**
8867
+ * Try to provide additional context when Claude needs it
8868
+ */
8869
+ async tryProvideContext(need) {
8870
+ try {
8871
+ const results = await this.memoryClient.search(need, "global", 3);
8872
+ if (results.length > 0) {
8873
+ let additionalContext = `
8874
+
8875
+ ## Additional Context (Requested: ${(/* @__PURE__ */ new Date()).toISOString()})
8876
+ `;
8877
+ additionalContext += `### You asked about: ${need}
8878
+
8879
+ `;
8880
+ additionalContext += results.map((r) => `- ${r.content}`).join("\n");
8881
+ const currentContext = __require("fs").readFileSync(this.contextFilePath, "utf-8");
8882
+ writeFileSync8(this.contextFilePath, currentContext + additionalContext);
8883
+ this.logger.info("Provided additional context to Claude", { need });
8884
+ }
8885
+ } catch (err) {
8886
+ this.logger.warn("Failed to provide additional context", err);
8887
+ }
8888
+ }
8889
+ /**
8890
+ * Get session insights summary
8891
+ */
8892
+ async getSessionSummary() {
8893
+ try {
8894
+ const results = await this.memoryClient.search("", "claude-code-insights", 50);
8895
+ const summary = {
8896
+ discoveries: [],
8897
+ patterns: [],
8898
+ needs: [],
8899
+ errors: [],
8900
+ completions: []
8901
+ };
8902
+ for (const result of results) {
8903
+ const match = result.content.match(/^(DISCOVERY|PATTERN|NEED|ERROR|COMPLETE):\s*(.+)$/);
8904
+ if (match) {
8905
+ const [, type, content] = match;
8906
+ switch (type) {
8907
+ case "DISCOVERY":
8908
+ summary.discoveries.push(content);
8909
+ break;
8910
+ case "PATTERN":
8911
+ summary.patterns.push(content);
8912
+ break;
8913
+ case "NEED":
8914
+ summary.needs.push(content);
8915
+ break;
8916
+ case "ERROR":
8917
+ summary.errors.push(content);
8918
+ break;
8919
+ case "COMPLETE":
8920
+ summary.completions.push(content);
8921
+ break;
8922
+ }
8923
+ }
8924
+ }
8925
+ return summary;
8926
+ } catch (err) {
8927
+ this.logger.warn("Failed to get session summary", err);
8928
+ return {
8929
+ discoveries: [],
8930
+ patterns: [],
8931
+ needs: [],
8932
+ errors: [],
8933
+ completions: []
8934
+ };
8786
8935
  }
8787
8936
  }
8788
8937
  /**
8789
8938
  * Clean up resources
8790
8939
  */
8791
8940
  destroy() {
8792
- if (this.sessionLogPath && existsSync20(this.sessionLogPath)) {
8793
- unwatchFile(this.sessionLogPath);
8941
+ if (this.watchInterval) {
8942
+ clearInterval(this.watchInterval);
8943
+ this.watchInterval = null;
8794
8944
  }
8945
+ this.seenPatterns.clear();
8946
+ this.removeAllListeners();
8795
8947
  }
8796
8948
  };
8797
8949
  async function createContextBridge(config) {
@@ -9696,4 +9848,4 @@ smol-toml/dist/index.js:
9696
9848
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9697
9849
  *)
9698
9850
  */
9699
- //# sourceMappingURL=chunk-7XXV5FKN.js.map
9851
+ //# sourceMappingURL=chunk-TQYOGZIN.js.map