@sesamespace/hivemind 0.12.0 → 0.12.2

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.
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Watchdog
3
- } from "./chunk-YJW6OOEJ.js";
3
+ } from "./chunk-ZAPHLG7V.js";
4
4
  import {
5
5
  defaultSentinelConfig,
6
6
  loadConfig
7
- } from "./chunk-ZQ26EOYD.js";
7
+ } from "./chunk-R7RHYYOM.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-6JB4OAB6.js.map
79
+ //# sourceMappingURL=chunk-3F7M2BPR.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  FleetManager
3
- } from "./chunk-YJW6OOEJ.js";
3
+ } from "./chunk-ZAPHLG7V.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-G5LF3BSN.js.map
186
+ //# sourceMappingURL=chunk-EJM4KCCY.js.map
@@ -4226,8 +4226,8 @@ var LogWatcher = class extends BackgroundProcess {
4226
4226
  savePositions() {
4227
4227
  try {
4228
4228
  const { mkdirSync: mkdirSync16, writeFileSync: writeFileSync10 } = __require("fs");
4229
- const { dirname: dirname10 } = __require("path");
4230
- const dir = dirname10(this.positionsFile);
4229
+ const { dirname: dirname9 } = __require("path");
4230
+ const dir = dirname9(this.positionsFile);
4231
4231
  if (!existsSync7(dir)) mkdirSync16(dir, { recursive: true });
4232
4232
  const data = Object.fromEntries(this.tailPositions);
4233
4233
  writeFileSync10(this.positionsFile, JSON.stringify(data));
@@ -7806,7 +7806,7 @@ function truncate2(text) {
7806
7806
  }
7807
7807
 
7808
7808
  // packages/runtime/src/tools/coding-agent.ts
7809
- import { execSync as execSync9 } from "child_process";
7809
+ import { exec as exec2, execSync as execSync9 } from "child_process";
7810
7810
  import { resolve as resolve17 } from "path";
7811
7811
  var MAX_OUTPUT6 = 5e4;
7812
7812
  function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
@@ -7886,17 +7886,27 @@ function registerCodingAgentTools(registry, workspaceDir, contextBridge) {
7886
7886
  const escapedTask = task.replace(/'/g, "'\\''");
7887
7887
  const command = `claude --dangerously-skip-permissions -p '${escapedTask}'`;
7888
7888
  try {
7889
- const output = execSync9(command, {
7890
- cwd,
7891
- timeout: timeoutSeconds * 1e3,
7892
- encoding: "utf-8",
7893
- maxBuffer: 10 * 1024 * 1024,
7894
- // 10MB
7895
- shell: "/bin/sh",
7896
- env: {
7897
- ...process.env,
7898
- PATH: extendedPath
7899
- }
7889
+ const output = await new Promise((resolve21, reject) => {
7890
+ const child = exec2(command, {
7891
+ cwd,
7892
+ timeout: timeoutSeconds * 1e3,
7893
+ encoding: "utf-8",
7894
+ maxBuffer: 10 * 1024 * 1024,
7895
+ // 10MB
7896
+ env: {
7897
+ ...process.env,
7898
+ PATH: extendedPath
7899
+ }
7900
+ }, (error, stdout, stderr) => {
7901
+ if (error) {
7902
+ error.stdout = stdout;
7903
+ error.stderr = stderr;
7904
+ reject(error);
7905
+ } else {
7906
+ resolve21(stdout);
7907
+ }
7908
+ });
7909
+ child.stdin?.end();
7900
7910
  });
7901
7911
  const trimmed = output.length > MAX_OUTPUT6 ? output.slice(0, MAX_OUTPUT6) + `
7902
7912
  ... (truncated, ${output.length} total chars)` : output;
@@ -8578,13 +8588,13 @@ Path: ${skillDir}`;
8578
8588
  }
8579
8589
 
8580
8590
  // packages/runtime/src/pipeline.ts
8581
- import { readFileSync as readFileSync16, writeFileSync as writeFileSync9, unlinkSync as unlinkSync3 } from "fs";
8582
- import { resolve as resolve20, dirname as dirname9 } from "path";
8591
+ import { readFileSync as readFileSync15, writeFileSync as writeFileSync9, unlinkSync as unlinkSync3 } from "fs";
8592
+ import { resolve as resolve20, dirname as dirname8 } from "path";
8583
8593
  import { fileURLToPath as fileURLToPath3 } from "url";
8584
8594
 
8585
8595
  // packages/runtime/src/tools/context-bridge.ts
8586
- import { writeFileSync as writeFileSync8, readFileSync as readFileSync15, existsSync as existsSync20, mkdirSync as mkdirSync15, watchFile, unwatchFile } from "fs";
8587
- import { join as join8, dirname as dirname8 } from "path";
8596
+ import { writeFileSync as writeFileSync8, existsSync as existsSync20, mkdirSync as mkdirSync15, watchFile, unwatchFile, openSync, readSync, closeSync } from "fs";
8597
+ import { join as join8 } from "path";
8588
8598
  import { homedir } from "os";
8589
8599
  import { EventEmitter as EventEmitter2 } from "events";
8590
8600
  var ClaudeContextBridge = class extends EventEmitter2 {
@@ -8593,8 +8603,6 @@ var ClaudeContextBridge = class extends EventEmitter2 {
8593
8603
  logger;
8594
8604
  sessionLogPath;
8595
8605
  contextFilePath;
8596
- claudeSettingsPath;
8597
- logWatcher;
8598
8606
  constructor(config) {
8599
8607
  super();
8600
8608
  this.workspaceDir = config.workspaceDir;
@@ -8602,13 +8610,12 @@ var ClaudeContextBridge = class extends EventEmitter2 {
8602
8610
  this.logger = config.logger;
8603
8611
  this.sessionLogPath = join8(homedir(), ".claude", "session.log");
8604
8612
  this.contextFilePath = join8(this.workspaceDir, "CLAUDE_CONTEXT.md");
8605
- this.claudeSettingsPath = join8(homedir(), ".claude", "settings.json");
8606
8613
  }
8607
8614
  /**
8608
8615
  * Initialize the context bridge
8609
8616
  */
8610
8617
  async initialize() {
8611
- const claudeDir = dirname8(this.claudeSettingsPath);
8618
+ const claudeDir = join8(homedir(), ".claude");
8612
8619
  if (!existsSync20(claudeDir)) {
8613
8620
  mkdirSync15(claudeDir, { recursive: true });
8614
8621
  }
@@ -8617,32 +8624,23 @@ var ClaudeContextBridge = class extends EventEmitter2 {
8617
8624
  this.logger.info("Claude context bridge initialized");
8618
8625
  }
8619
8626
  /**
8620
- * Configure Claude Code to report insights
8627
+ * Configure Claude Code to report insights via workspace CLAUDE.md
8621
8628
  */
8622
8629
  async setupClaudeSettings() {
8623
- const customInstructions = `# Hivemind Context Bridge
8630
+ const instructions = `# Hivemind Context Bridge
8624
8631
 
8625
8632
  When working on tasks, please report significant findings by writing to the session log:
8626
8633
 
8627
8634
  - When you discover architecture/patterns: echo "DISCOVERY: [details]" >> ~/.claude/session.log
8628
- - When you need more context: echo "NEED: [what you need]" >> ~/.claude/session.log
8635
+ - When you need more context: echo "NEED: [what you need]" >> ~/.claude/session.log
8629
8636
  - When you complete major steps: echo "COMPLETE: [what you did]" >> ~/.claude/session.log
8630
8637
  - When you find reusable solutions: echo "PATTERN: [approach]" >> ~/.claude/session.log
8631
8638
  - When you encounter errors: echo "ERROR: [error details]" >> ~/.claude/session.log
8632
8639
 
8633
- Always check ~/hivemind/workspace/CLAUDE_CONTEXT.md for task context and requirements.`;
8634
- const settings = {
8635
- customInstructions,
8636
- alwaysIncludeFiles: [
8637
- this.contextFilePath,
8638
- join8(this.workspaceDir, "ARCHITECTURE.md"),
8639
- join8(this.workspaceDir, "TOOLS.md")
8640
- ],
8641
- // Enable verbose logging for better insights
8642
- verboseLogging: true
8643
- };
8644
- writeFileSync8(this.claudeSettingsPath, JSON.stringify(settings, null, 2));
8645
- this.logger.info("Claude settings configured for context bridge");
8640
+ Always check CLAUDE_CONTEXT.md in the workspace for task context and requirements.`;
8641
+ const claudeMdPath = join8(this.workspaceDir, "CLAUDE.md");
8642
+ writeFileSync8(claudeMdPath, instructions);
8643
+ this.logger.info("Claude workspace CLAUDE.md configured for context bridge");
8646
8644
  }
8647
8645
  /**
8648
8646
  * Prepare context for a Claude Code session
@@ -8705,9 +8703,14 @@ ${memories.join("\n\n")}
8705
8703
  */
8706
8704
  async getRelevantMemories(goal) {
8707
8705
  try {
8708
- const results = await this.memoryClient.search(goal, "global", 5);
8706
+ const results = await Promise.race([
8707
+ this.memoryClient.search(goal, "global", 5),
8708
+ new Promise(
8709
+ (_, reject) => setTimeout(() => reject(new Error("Memory search timeout")), 3e3)
8710
+ )
8711
+ ]);
8709
8712
  return results.map((r) => `- ${r.content}`);
8710
- } catch (err) {
8713
+ } catch {
8711
8714
  return [];
8712
8715
  }
8713
8716
  }
@@ -8719,14 +8722,20 @@ ${memories.join("\n\n")}
8719
8722
  writeFileSync8(this.sessionLogPath, "");
8720
8723
  }
8721
8724
  let lastSize = 0;
8722
- watchFile(this.sessionLogPath, { interval: 1e3 }, (curr, prev) => {
8725
+ watchFile(this.sessionLogPath, { interval: 2e3 }, (curr) => {
8723
8726
  if (curr.size > lastSize) {
8724
- const content = readFileSync15(this.sessionLogPath, "utf-8");
8725
- const newContent = content.slice(lastSize);
8726
- lastSize = curr.size;
8727
- const lines = newContent.split("\n").filter((line) => line.trim());
8728
- for (const line of lines) {
8729
- this.processLogLine(line);
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) });
8730
8739
  }
8731
8740
  }
8732
8741
  });
@@ -8747,7 +8756,9 @@ ${memories.join("\n\n")}
8747
8756
  const match = line.match(pattern);
8748
8757
  if (match) {
8749
8758
  const content = match[1];
8750
- this.handleInsight(type, content);
8759
+ this.handleInsight(type, content).catch((err) => {
8760
+ this.logger.warn("Failed to handle insight", { error: String(err) });
8761
+ });
8751
8762
  break;
8752
8763
  }
8753
8764
  }
@@ -8760,13 +8771,10 @@ ${memories.join("\n\n")}
8760
8771
  this.emit("insight", { type, content });
8761
8772
  if (["DISCOVERY", "PATTERN"].includes(type)) {
8762
8773
  try {
8763
- await this.memoryClient.store({
8764
- content: `Claude Code ${type}: ${content}`,
8765
- metadata: {
8766
- source: "claude-code",
8767
- type: type.toLowerCase(),
8768
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
8769
- }
8774
+ await this.memoryClient.storeEpisode({
8775
+ context_name: "claude-code",
8776
+ role: "system",
8777
+ content: `Claude Code ${type}: ${content}`
8770
8778
  });
8771
8779
  } catch (err) {
8772
8780
  this.logger.warn("Failed to store Claude insight in memory", err);
@@ -8794,8 +8802,8 @@ async function createContextBridge(config) {
8794
8802
  // packages/runtime/src/pipeline.ts
8795
8803
  var PACKAGE_VERSION = "unknown";
8796
8804
  try {
8797
- const __dirname2 = dirname9(fileURLToPath3(import.meta.url));
8798
- const pkg = JSON.parse(readFileSync16(resolve20(__dirname2, "../package.json"), "utf-8"));
8805
+ const __dirname2 = dirname8(fileURLToPath3(import.meta.url));
8806
+ const pkg = JSON.parse(readFileSync15(resolve20(__dirname2, "../package.json"), "utf-8"));
8799
8807
  PACKAGE_VERSION = pkg.version ?? "unknown";
8800
8808
  } catch {
8801
8809
  }
@@ -8878,7 +8886,7 @@ async function startPipeline(configPath) {
8878
8886
  console.log("[hivemind] Global context already exists in memory daemon");
8879
8887
  }
8880
8888
  }
8881
- const requestLogger = new RequestLogger(resolve20(dirname9(configPath), "data", "dashboard.db"));
8889
+ const requestLogger = new RequestLogger(resolve20(dirname8(configPath), "data", "dashboard.db"));
8882
8890
  const agent = new Agent(config);
8883
8891
  startDashboardServer(requestLogger, config.memory, () => agent.getConversationHistories());
8884
8892
  agent.setRequestLogger(requestLogger);
@@ -8897,6 +8905,9 @@ async function startPipeline(configPath) {
8897
8905
  console.warn("[hivemind] Failed to create Claude context bridge:", err);
8898
8906
  }
8899
8907
  }
8908
+ if (contextBridge) {
8909
+ process.on("exit", () => contextBridge.destroy());
8910
+ }
8900
8911
  const toolRegistry = registerAllTools(hivemindHome, {
8901
8912
  enabled: true,
8902
8913
  workspace: config.agent.workspace || "workspace",
@@ -9684,4 +9695,4 @@ smol-toml/dist/index.js:
9684
9695
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9685
9696
  *)
9686
9697
  */
9687
- //# sourceMappingURL=chunk-ZQ26EOYD.js.map
9698
+ //# sourceMappingURL=chunk-R7RHYYOM.js.map