0agent 1.0.45 → 1.0.46

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/dist/daemon.mjs +50 -26
  2. package/package.json +1 -1
package/dist/daemon.mjs CHANGED
@@ -2493,8 +2493,9 @@ var init_MemoryCapability = __esm({
2493
2493
  "use strict";
2494
2494
  init_src();
2495
2495
  MemoryCapability = class {
2496
- constructor(graph) {
2496
+ constructor(graph, onWrite) {
2497
2497
  this.graph = graph;
2498
+ this.onWrite = onWrite;
2498
2499
  }
2499
2500
  name = "memory_write";
2500
2501
  description = "Persist a discovered fact to long-term memory so it survives across sessions.";
@@ -2537,11 +2538,13 @@ var init_MemoryCapability = __esm({
2537
2538
  });
2538
2539
  this.graph.addNode(node);
2539
2540
  }
2540
- return {
2541
+ const result = {
2541
2542
  success: true,
2542
2543
  output: `Remembered: "${label}" = ${content.slice(0, 120)}${content.length > 120 ? "\u2026" : ""}`,
2543
2544
  duration_ms: Date.now() - start
2544
2545
  };
2546
+ this.onWrite?.();
2547
+ return result;
2545
2548
  } catch (err) {
2546
2549
  return {
2547
2550
  success: false,
@@ -2651,7 +2654,7 @@ var init_CapabilityRegistry = __esm({
2651
2654
  * task_type: browser_task). The main agent does NOT have direct access
2652
2655
  * to browser_open without going through a subagent spawn.
2653
2656
  */
2654
- constructor(codespaceManager, graph) {
2657
+ constructor(codespaceManager, graph, onMemoryWrite) {
2655
2658
  this.register(new WebSearchCapability());
2656
2659
  if (codespaceManager) {
2657
2660
  try {
@@ -2667,7 +2670,7 @@ var init_CapabilityRegistry = __esm({
2667
2670
  this.register(new ShellCapability());
2668
2671
  this.register(new FileCapability());
2669
2672
  if (graph) {
2670
- this.register(new MemoryCapability(graph));
2673
+ this.register(new MemoryCapability(graph, onMemoryWrite));
2671
2674
  }
2672
2675
  }
2673
2676
  register(cap) {
@@ -2734,7 +2737,7 @@ var init_AgentExecutor = __esm({
2734
2737
  this.maxIterations = config.max_iterations ?? 20;
2735
2738
  this.maxCommandMs = config.max_command_ms ?? 3e4;
2736
2739
  this.agentRoot = config.agent_root;
2737
- this.registry = new CapabilityRegistry(void 0, config.graph);
2740
+ this.registry = new CapabilityRegistry(void 0, config.graph, config.onMemoryWrite);
2738
2741
  }
2739
2742
  cwd;
2740
2743
  maxIterations;
@@ -4735,7 +4738,7 @@ var SessionManager = class {
4735
4738
  if (activeLLM?.isConfigured) {
4736
4739
  const executor = new AgentExecutor(
4737
4740
  activeLLM,
4738
- { cwd: this.cwd, agent_root: this.agentRoot, graph: this.graph },
4741
+ { cwd: this.cwd, agent_root: this.agentRoot, graph: this.graph, onMemoryWrite: this.onMemoryWritten },
4739
4742
  // step callback → emit session.step events
4740
4743
  (step) => this.addStep(sessionId, step),
4741
4744
  // token callback → emit session.token events
@@ -4901,33 +4904,48 @@ Current task:`;
4901
4904
  */
4902
4905
  async _extractAndPersistFacts(task, output, llm) {
4903
4906
  if (!this.graph || !llm.isConfigured) return;
4907
+ const combined = `${task} ${output}`;
4908
+ if (combined.trim().length < 20) return;
4904
4909
  const prompt = `Extract factual entities from this conversation that should be remembered long-term.
4905
- Return ONLY a JSON array, no other text, max 12 items.
4910
+ Return ONLY a valid JSON array (no markdown, no explanation), max 12 items.
4911
+ If nothing worth remembering, return [].
4906
4912
 
4907
4913
  Types: identity (name/role), project (apps/products), tech (stack/tools), preference, url, path, config, outcome
4908
4914
 
4909
- Format: [{"label":"snake_case_key","content":"value to remember","type":"type"}]
4915
+ Format: [{"label":"snake_case_key","content":"value","type":"type"}]
4910
4916
 
4911
4917
  Examples:
4912
- - User says "my name is Sahil" \u2192 {"label":"user_name","content":"Sahil","type":"identity"}
4913
- - User says "we have a telegram bot" \u2192 {"label":"project_telegram_bot","content":"user has a Telegram bot project","type":"project"}
4914
- - User says "I use React and Next.js" \u2192 {"label":"tech_stack","content":"React, Next.js","type":"tech"}
4918
+ - "my name is Sahil" \u2192 {"label":"user_name","content":"Sahil","type":"identity"}
4919
+ - "we have a telegram bot" \u2192 {"label":"project_telegram_bot","content":"user has a Telegram bot","type":"project"}
4920
+ - "I use React and Next.js" \u2192 {"label":"tech_stack","content":"React, Next.js","type":"tech"}
4921
+ - ngrok URL found \u2192 {"label":"ngrok_url","content":"https://abc.ngrok.io","type":"url"}
4915
4922
 
4916
4923
  Conversation:
4917
4924
  User: ${task.slice(0, 600)}
4918
- Agent: ${output.slice(0, 400)}`;
4925
+ Agent: ${output.slice(0, 500)}`;
4919
4926
  try {
4920
4927
  const resp = await llm.complete(
4921
4928
  [{ role: "user", content: prompt }],
4922
- "You are a concise memory extraction system. Extract only factual, durable information. Skip generic statements."
4929
+ "You are a memory extraction system. Be concise. Extract only factual, durable information. Return valid JSON only."
4923
4930
  );
4924
- const jsonMatch = resp.content.match(/\[[\s\S]*?\]/);
4925
- if (!jsonMatch) return;
4926
- const entities = JSON.parse(jsonMatch[0]);
4931
+ let entities = [];
4932
+ const raw = resp.content.trim();
4933
+ try {
4934
+ const parsed = JSON.parse(raw);
4935
+ if (Array.isArray(parsed)) entities = parsed;
4936
+ } catch {
4937
+ const match = raw.match(/\[\s*\{[\s\S]*?\}\s*\]/);
4938
+ if (match) {
4939
+ try {
4940
+ entities = JSON.parse(match[0]);
4941
+ } catch {
4942
+ }
4943
+ }
4944
+ }
4927
4945
  if (!Array.isArray(entities) || entities.length === 0) return;
4928
4946
  let wrote = 0;
4929
4947
  for (const e of entities.slice(0, 12)) {
4930
- if (!e.label?.trim() || !e.content?.trim()) continue;
4948
+ if (!e?.label?.trim() || !e?.content?.trim()) continue;
4931
4949
  const nodeId = `memory:${e.label.toLowerCase().replace(/[^a-z0-9_]/g, "_")}`;
4932
4950
  try {
4933
4951
  const existing = this.graph.getNode(nodeId);
@@ -4946,14 +4964,16 @@ Agent: ${output.slice(0, 400)}`;
4946
4964
  }));
4947
4965
  }
4948
4966
  wrote++;
4949
- } catch {
4967
+ } catch (err) {
4968
+ console.warn(`[0agent] Memory write failed for "${e.label}":`, err instanceof Error ? err.message : err);
4950
4969
  }
4951
4970
  }
4952
4971
  if (wrote > 0) {
4953
- console.log(`[0agent] Memory: extracted ${wrote} facts from session`);
4972
+ console.log(`[0agent] Memory: persisted ${wrote} facts \u2192 graph`);
4954
4973
  this.onMemoryWritten?.();
4955
4974
  }
4956
- } catch {
4975
+ } catch (err) {
4976
+ console.warn("[0agent] Memory extraction failed:", err instanceof Error ? err.message : String(err));
4957
4977
  }
4958
4978
  }
4959
4979
  /**
@@ -7303,20 +7323,24 @@ var ZeroAgentDaemon = class {
7303
7323
  adapter: this.adapter,
7304
7324
  agentRoot,
7305
7325
  // agent source path — self-improvement tasks read the right files
7306
- // Mark GitHub memory dirty immediately when facts are extracted pushes within 2min
7326
+ // Push to GitHub immediately when facts are extracted from a session
7307
7327
  onMemoryWritten: () => {
7308
7328
  this.githubMemorySync?.markDirty();
7329
+ if (this.githubMemorySync) {
7330
+ this.githubMemorySync.push("sync: new facts learned").then((r) => {
7331
+ if (r.pushed) console.log(`[0agent] Memory pushed: ${r.nodes_synced} nodes \u2192 github`);
7332
+ }).catch(() => {
7333
+ });
7334
+ }
7309
7335
  }
7310
7336
  });
7311
7337
  const teamSync = identity && teams.length > 0 ? new TeamSync(teamManager, this.adapter, identity.entity_node_id) : null;
7312
7338
  if (this.githubMemorySync) {
7313
7339
  const memSync = this.githubMemorySync;
7314
7340
  this.memorySyncTimer = setInterval(async () => {
7315
- if (memSync.hasPendingChanges()) {
7316
- const result = await memSync.push().catch(() => null);
7317
- if (result?.pushed) {
7318
- console.log(`[0agent] Memory auto-synced: ${result.nodes_synced} nodes`);
7319
- }
7341
+ const result = await memSync.push().catch(() => null);
7342
+ if (result?.pushed && result.nodes_synced > 0) {
7343
+ console.log(`[0agent] Memory synced: ${result.nodes_synced} nodes \u2192 github`);
7320
7344
  }
7321
7345
  }, 2 * 60 * 1e3);
7322
7346
  if (typeof this.memorySyncTimer === "object") this.memorySyncTimer.unref?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "0agent",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "description": "A persistent, learning AI agent that runs on your machine. An agent that learns.",
5
5
  "private": false,
6
6
  "license": "Apache-2.0",