@sesamespace/hivemind 0.12.2 → 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.
@@ -7,7 +7,7 @@ import {
7
7
  SesameClient2 as SesameClient,
8
8
  WORKER_ROUTES,
9
9
  createLogger
10
- } from "./chunk-R7RHYYOM.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-ZAPHLG7V.js.map
1098
+ //# sourceMappingURL=chunk-3SIWFXC7.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  FleetManager
3
- } from "./chunk-ZAPHLG7V.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-EJM4KCCY.js.map
186
+ //# sourceMappingURL=chunk-6W56VBXG.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  startPipeline
3
- } from "./chunk-R7RHYYOM.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-SNW6Z2W4.js.map
69
+ //# sourceMappingURL=chunk-7HOPTFRU.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Watchdog
3
- } from "./chunk-ZAPHLG7V.js";
3
+ } from "./chunk-3SIWFXC7.js";
4
4
  import {
5
5
  defaultSentinelConfig,
6
6
  loadConfig
7
- } from "./chunk-R7RHYYOM.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-3F7M2BPR.js.map
79
+ //# sourceMappingURL=chunk-EDSK2CG6.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SesameClient,
3
3
  getClaudeCodeOAuthToken
4
- } from "./chunk-R7RHYYOM.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-ZI4AN7GT.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, {
@@ -7908,9 +7920,35 @@ function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
7908
7920
  });
7909
7921
  child.stdin?.end();
7910
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
+ }
7911
7949
  const trimmed = output.length > MAX_OUTPUT6 ? output.slice(0, MAX_OUTPUT6) + `
7912
7950
  ... (truncated, ${output.length} total chars)` : output;
7913
- return trimmed || "(no output)";
7951
+ return (trimmed || "(no output)") + summaryText;
7914
7952
  } catch (err) {
7915
7953
  if (err.killed) {
7916
7954
  return `Error: Claude Code timed out after ${timeoutSeconds}s`;
@@ -7921,6 +7959,13 @@ function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
7921
7959
  const code = err.status ?? "unknown";
7922
7960
  return `Claude Code failed (exit code ${code}):
7923
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
+ }
7924
7969
  }
7925
7970
  }
7926
7971
  );
@@ -8593,7 +8638,7 @@ import { resolve as resolve20, dirname as dirname8 } from "path";
8593
8638
  import { fileURLToPath as fileURLToPath3 } from "url";
8594
8639
 
8595
8640
  // packages/runtime/src/tools/context-bridge.ts
8596
- 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";
8597
8642
  import { join as join8 } from "path";
8598
8643
  import { homedir } from "os";
8599
8644
  import { EventEmitter as EventEmitter2 } from "events";
@@ -8603,6 +8648,9 @@ var ClaudeContextBridge = class extends EventEmitter2 {
8603
8648
  logger;
8604
8649
  sessionLogPath;
8605
8650
  contextFilePath;
8651
+ watchInterval = null;
8652
+ lastLogSize = 0;
8653
+ seenPatterns = /* @__PURE__ */ new Set();
8606
8654
  constructor(config) {
8607
8655
  super();
8608
8656
  this.workspaceDir = config.workspaceDir;
@@ -8721,25 +8769,33 @@ ${memories.join("\n\n")}
8721
8769
  if (!existsSync20(this.sessionLogPath)) {
8722
8770
  writeFileSync8(this.sessionLogPath, "");
8723
8771
  }
8724
- let lastSize = 0;
8725
- watchFile(this.sessionLogPath, { interval: 2e3 }, (curr) => {
8726
- if (curr.size > lastSize) {
8727
- try {
8728
- const fd = openSync(this.sessionLogPath, "r");
8729
- const buf = Buffer.alloc(curr.size - lastSize);
8730
- readSync(fd, buf, 0, buf.length, lastSize);
8731
- closeSync(fd);
8732
- lastSize = curr.size;
8733
- const lines = buf.toString("utf-8").split("\n").filter((l) => l.trim());
8734
- for (const line of lines) {
8735
- this.processLogLine(line);
8736
- }
8737
- } catch (err) {
8738
- 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);
8739
8794
  }
8740
8795
  }
8741
- });
8742
- this.logger.info("Started monitoring Claude session log");
8796
+ } catch (err) {
8797
+ this.logger.warn("Failed to check session log", { error: String(err) });
8798
+ }
8743
8799
  }
8744
8800
  /**
8745
8801
  * Process a line from Claude's session log
@@ -8769,28 +8825,125 @@ ${memories.join("\n\n")}
8769
8825
  async handleInsight(type, content) {
8770
8826
  this.logger.info(`Claude insight: ${type}`, { content });
8771
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
+ }
8772
8836
  if (["DISCOVERY", "PATTERN"].includes(type)) {
8773
8837
  try {
8774
8838
  await this.memoryClient.storeEpisode({
8775
- context_name: "claude-code",
8839
+ context_name: "claude-code-insights",
8776
8840
  role: "system",
8777
- content: `Claude Code ${type}: ${content}`
8841
+ content: `${type}: ${content}`,
8842
+ metadata: {
8843
+ type,
8844
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
8845
+ source: "claude-code"
8846
+ }
8778
8847
  });
8848
+ this.logger.info(`Stored ${type} in memory`, { content });
8779
8849
  } catch (err) {
8780
8850
  this.logger.warn("Failed to store Claude insight in memory", err);
8781
8851
  }
8782
8852
  }
8783
- if (type === "NEED") {
8784
- 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
+ };
8785
8935
  }
8786
8936
  }
8787
8937
  /**
8788
8938
  * Clean up resources
8789
8939
  */
8790
8940
  destroy() {
8791
- if (this.sessionLogPath && existsSync20(this.sessionLogPath)) {
8792
- unwatchFile(this.sessionLogPath);
8941
+ if (this.watchInterval) {
8942
+ clearInterval(this.watchInterval);
8943
+ this.watchInterval = null;
8793
8944
  }
8945
+ this.seenPatterns.clear();
8946
+ this.removeAllListeners();
8794
8947
  }
8795
8948
  };
8796
8949
  async function createContextBridge(config) {
@@ -9695,4 +9848,4 @@ smol-toml/dist/index.js:
9695
9848
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9696
9849
  *)
9697
9850
  */
9698
- //# sourceMappingURL=chunk-R7RHYYOM.js.map
9851
+ //# sourceMappingURL=chunk-TQYOGZIN.js.map