agentbnb 8.4.4 → 8.4.7

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,3 +1,6 @@
1
+ import {
2
+ syncCreditsFromRegistry
3
+ } from "./chunk-RF4A5X5U.js";
1
4
  import {
2
5
  resolveTargetCapability
3
6
  } from "./chunk-2PP5MQPD.js";
@@ -134,6 +137,18 @@ async function executeCapabilityRequest(opts) {
134
137
  };
135
138
  }
136
139
  } else {
140
+ const cfg = loadConfig();
141
+ if (cfg?.registry) {
142
+ try {
143
+ await Promise.race([
144
+ syncCreditsFromRegistry(cfg, creditDb),
145
+ new Promise(
146
+ (_, reject) => setTimeout(() => reject(new Error("sync timeout")), 2e3)
147
+ )
148
+ ]);
149
+ } catch {
150
+ }
151
+ }
137
152
  try {
138
153
  const balance = getBalance(creditDb, requester);
139
154
  if (balance < creditsNeeded) {
@@ -2,7 +2,7 @@ import {
2
2
  requestCapability,
3
3
  requestCapabilityBatch,
4
4
  requestViaRelay
5
- } from "./chunk-R4F4XII4.js";
5
+ } from "./chunk-YKMBFQC2.js";
6
6
  import {
7
7
  RelayClient
8
8
  } from "./chunk-4NFJ3VYZ.js";
@@ -0,0 +1,62 @@
1
+ import {
2
+ createLedger,
3
+ loadOrRepairIdentity
4
+ } from "./chunk-WK2QSO4E.js";
5
+ import {
6
+ getBalance
7
+ } from "./chunk-HU46M4JA.js";
8
+ import {
9
+ canonicalizeCreditOwner
10
+ } from "./chunk-U6LP4KWN.js";
11
+ import {
12
+ getConfigDir
13
+ } from "./chunk-3XPBFF6H.js";
14
+
15
+ // src/credit/registry-sync.ts
16
+ async function syncCreditsFromRegistry(config, localDb) {
17
+ if (!config.registry) {
18
+ return { synced: false, error: "no registry configured" };
19
+ }
20
+ try {
21
+ const configDir = getConfigDir();
22
+ const { identity, keys } = loadOrRepairIdentity(configDir, config.owner);
23
+ const ledger = createLedger({
24
+ registryUrl: config.registry,
25
+ ownerPublicKey: identity.public_key,
26
+ privateKey: keys.privateKey
27
+ });
28
+ const [remoteBalance, remoteHistory] = await Promise.all([
29
+ ledger.getBalance(config.owner),
30
+ ledger.getHistory(config.owner, 50)
31
+ ]);
32
+ const localWas = getBalance(localDb, config.owner);
33
+ localDb.transaction(() => {
34
+ const now = (/* @__PURE__ */ new Date()).toISOString();
35
+ const canonicalOwner = canonicalizeCreditOwner(localDb, config.owner);
36
+ localDb.prepare(
37
+ "INSERT OR REPLACE INTO credit_balances (owner, balance, updated_at) VALUES (?, ?, ?)"
38
+ ).run(canonicalOwner, remoteBalance, now);
39
+ const insertTxn = localDb.prepare(
40
+ "INSERT OR IGNORE INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
41
+ );
42
+ for (const txn of remoteHistory) {
43
+ insertTxn.run(
44
+ txn.id,
45
+ txn.owner,
46
+ txn.amount,
47
+ txn.reason,
48
+ txn.reference_id,
49
+ txn.created_at
50
+ );
51
+ }
52
+ })();
53
+ return { synced: true, remoteBalance, localWas };
54
+ } catch (err) {
55
+ const message = err instanceof Error ? err.message : String(err);
56
+ return { synced: false, error: message };
57
+ }
58
+ }
59
+
60
+ export {
61
+ syncCreditsFromRegistry
62
+ };
package/dist/cli/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  injectHeartbeatSection,
6
6
  performInit,
7
7
  publishFromSoulV2
8
- } from "../chunk-PCQEHIGF.js";
8
+ } from "../chunk-UNXCKETK.js";
9
9
  import {
10
10
  AutoRequestor,
11
11
  requestViaTemporaryRelay
@@ -21,14 +21,17 @@ import {
21
21
  import {
22
22
  getPricingStats
23
23
  } from "../chunk-CFHCG5FE.js";
24
- import {
25
- createLedger,
26
- ensureIdentity
27
- } from "../chunk-WK2QSO4E.js";
28
24
  import "../chunk-MZSVVG55.js";
29
25
  import {
30
26
  DEFAULT_AUTONOMY_CONFIG
31
27
  } from "../chunk-G5WKW3ED.js";
28
+ import {
29
+ syncCreditsFromRegistry
30
+ } from "../chunk-RF4A5X5U.js";
31
+ import {
32
+ createLedger,
33
+ ensureIdentity
34
+ } from "../chunk-WK2QSO4E.js";
32
35
  import "../chunk-2PP5MQPD.js";
33
36
  import {
34
37
  fetchRemoteCards,
@@ -227,7 +230,7 @@ Skills: ${skills2.skillCount} skill(s) in ${skills2.path}`);
227
230
  if (!skipServe) {
228
231
  try {
229
232
  const { ProcessGuard } = await import("../process-guard-TNSUNHSR.js");
230
- const { ServiceCoordinator } = await import("../service-coordinator-2HDVHDFD.js");
233
+ const { ServiceCoordinator } = await import("../service-coordinator-RN7GOLLC.js");
231
234
  const guard = new ProcessGuard(join(initResult.configDir, ".pid"));
232
235
  const coordinator = new ServiceCoordinator(initResult.config, guard);
233
236
  const result = await coordinator.ensureRunning({
@@ -289,7 +292,7 @@ Skills: ${skills2.skillCount} skill(s) in ${skills2.path}`);
289
292
  }
290
293
 
291
294
  // src/cli/index.ts
292
- var VERSION = true ? "8.4.4" : "0.0.0-dev";
295
+ var VERSION = true ? "8.4.7" : "0.0.0-dev";
293
296
  function loadIdentityAuth(owner) {
294
297
  const configDir = getConfigDir();
295
298
  let keys;
@@ -748,6 +751,18 @@ program.command("request [card-id]").description("Request a capability from anot
748
751
  console.error("Error: not initialized. Run `agentbnb init` first.");
749
752
  process.exit(1);
750
753
  }
754
+ if (config.registry) {
755
+ const creditDb = openCreditDb(config.credit_db_path);
756
+ try {
757
+ const syncResult = await syncCreditsFromRegistry(config, creditDb);
758
+ if (syncResult.synced && syncResult.remoteBalance !== void 0) {
759
+ console.log(`Credits synced: ${syncResult.remoteBalance} [registry]`);
760
+ }
761
+ } catch {
762
+ } finally {
763
+ creditDb.close();
764
+ }
765
+ }
751
766
  if (opts.batch) {
752
767
  const registryUrl = config.registry;
753
768
  if (!registryUrl) {
@@ -1010,10 +1025,20 @@ program.command("status").description("Show credit balance and recent transactio
1010
1025
  process.exit(1);
1011
1026
  }
1012
1027
  const creditDb = openCreditDb(config.credit_db_path);
1013
- let balance;
1014
- let transactions;
1015
- let heldEscrows;
1016
- if (config.registry) {
1028
+ let localBalance = 0;
1029
+ let registryBalance = null;
1030
+ let registryUnavailable = false;
1031
+ let transactions = [];
1032
+ let heldEscrows = [];
1033
+ try {
1034
+ localBalance = getBalance(creditDb, config.owner);
1035
+ transactions = getTransactions(creditDb, config.owner, 5);
1036
+ heldEscrows = creditDb.prepare("SELECT id, amount, card_id, created_at FROM credit_escrow WHERE owner = ? AND status = ?").all(config.owner, "held");
1037
+ } finally {
1038
+ creditDb.close();
1039
+ }
1040
+ const hasRegistry = config.registry != null;
1041
+ if (hasRegistry) {
1017
1042
  const statusIdentityAuth = loadIdentityAuth(config.owner);
1018
1043
  const statusLedger = createLedger({
1019
1044
  registryUrl: config.registry,
@@ -1021,33 +1046,54 @@ program.command("status").description("Show credit balance and recent transactio
1021
1046
  privateKey: statusIdentityAuth.privateKey
1022
1047
  });
1023
1048
  try {
1024
- balance = await statusLedger.getBalance(config.owner);
1049
+ registryBalance = await statusLedger.getBalance(config.owner);
1025
1050
  transactions = await statusLedger.getHistory(config.owner, 5);
1026
- heldEscrows = creditDb.prepare("SELECT id, amount, card_id, created_at FROM credit_escrow WHERE owner = ? AND status = ?").all(config.owner, "held");
1027
1051
  } catch (err) {
1028
- balance = 0;
1029
- transactions = [];
1030
- heldEscrows = [];
1052
+ registryUnavailable = true;
1031
1053
  const msg = err instanceof Error ? err.message : String(err);
1032
- console.warn(`Note: could not fetch balance from registry (${msg}). Run \`agentbnb init\` if this is a new agent.`);
1033
- } finally {
1034
- creditDb.close();
1035
- }
1036
- } else {
1037
- try {
1038
- balance = getBalance(creditDb, config.owner);
1039
- transactions = getTransactions(creditDb, config.owner, 5);
1040
- heldEscrows = creditDb.prepare("SELECT id, amount, card_id, created_at FROM credit_escrow WHERE owner = ? AND status = ?").all(config.owner, "held");
1041
- } finally {
1042
- creditDb.close();
1054
+ if (!opts.json) {
1055
+ console.warn(`Note: could not fetch balance from registry (${msg}). Run \`agentbnb init\` if this is a new agent.`);
1056
+ }
1043
1057
  }
1044
1058
  }
1059
+ const syncNeeded = hasRegistry && !registryUnavailable && registryBalance !== null && Math.abs(registryBalance - localBalance) > 1;
1060
+ const displayBalance = registryBalance ?? localBalance;
1045
1061
  if (opts.json) {
1046
- console.log(JSON.stringify({ owner: config.owner, balance, held_escrows: heldEscrows, recent_transactions: transactions }, null, 2));
1062
+ const output = {
1063
+ owner: config.owner,
1064
+ balance: displayBalance,
1065
+ local_balance: localBalance,
1066
+ held_escrows: heldEscrows,
1067
+ recent_transactions: transactions
1068
+ };
1069
+ if (config.agent_id) output["agent_id"] = config.agent_id;
1070
+ if (hasRegistry) {
1071
+ output["registry_balance"] = registryBalance;
1072
+ output["sync_needed"] = syncNeeded;
1073
+ }
1074
+ console.log(JSON.stringify(output, null, 2));
1047
1075
  return;
1048
1076
  }
1049
- console.log(`Owner: ${config.owner}`);
1050
- console.log(`Balance: ${balance} credits`);
1077
+ console.log(`Owner: ${config.owner}`);
1078
+ if (config.agent_id) {
1079
+ console.log(`Agent ID: ${config.agent_id}`);
1080
+ }
1081
+ if (hasRegistry) {
1082
+ console.log(`Registry: ${config.registry}`);
1083
+ }
1084
+ if (!hasRegistry) {
1085
+ console.log(`Balance: ${localBalance} credits [local]`);
1086
+ } else if (registryUnavailable) {
1087
+ console.log(`Balance: ${localBalance} credits [local \u2014 registry unavailable]`);
1088
+ } else if (syncNeeded) {
1089
+ const diff = Math.abs(registryBalance - localBalance);
1090
+ console.log(`Balance: ${registryBalance} credits [registry]`);
1091
+ console.log(`Local: ${localBalance} credits [stale \u2014 run: agentbnb sync]`);
1092
+ console.log(`
1093
+ \u26A0 Local balance out of sync (off by ${diff} credits)`);
1094
+ } else {
1095
+ console.log(`Balance: ${displayBalance} credits [registry, in sync]`);
1096
+ }
1051
1097
  if (heldEscrows.length > 0) {
1052
1098
  console.log(`
1053
1099
  Active Escrows (${heldEscrows.length}):`);
@@ -1072,7 +1118,7 @@ program.command("serve").description("Start the AgentBnB gateway server").option
1072
1118
  process.exit(1);
1073
1119
  }
1074
1120
  const { ProcessGuard } = await import("../process-guard-TNSUNHSR.js");
1075
- const { ServiceCoordinator } = await import("../service-coordinator-2HDVHDFD.js");
1121
+ const { ServiceCoordinator } = await import("../service-coordinator-RN7GOLLC.js");
1076
1122
  const port = opts.port ? parseInt(opts.port, 10) : config.gateway_port;
1077
1123
  const registryPort = parseInt(opts.registryPort, 10);
1078
1124
  if (!Number.isFinite(port) || !Number.isFinite(registryPort)) {
@@ -1446,7 +1492,7 @@ openclaw.command("rules").description("Print HEARTBEAT.md rules block (or inject
1446
1492
  }
1447
1493
  });
1448
1494
  openclaw.command("setup").description("Interactive onboarding: connect an OpenClaw agent to AgentBnB").option("--agent <name>", "Agent name to set up (skip interactive selection)").option("--soul-path <path>", "Override SOUL.md path").option("-y, --yes", "Skip confirmation prompts").action(async (opts) => {
1449
- const { runOpenClawSetup } = await import("../openclaw-setup-LVSGMXDF.js");
1495
+ const { runOpenClawSetup } = await import("../openclaw-setup-5ZWWRVF3.js");
1450
1496
  await runOpenClawSetup(opts);
1451
1497
  });
1452
1498
  var skills = openclaw.command("skills").description("Manage shared skills on AgentBnB");
@@ -1585,7 +1631,7 @@ Feedback for skill: ${opts.skill} (${feedbacks.length} entries)
1585
1631
  });
1586
1632
  program.command("quickstart").alias("qs").description("One-command setup: init + skills.yaml + MCP registration + serve daemon").option("--owner <name>", "Agent owner name").option("--port <port>", "Gateway port", "7700").option("--no-serve", "Skip starting background daemon").option("--no-mcp", "Skip MCP registration with Claude Code").option("--json", "Output as JSON").action(runQuickstart);
1587
1633
  program.command("mcp-server").description("Start an MCP (Model Context Protocol) server for IDE integration").action(async () => {
1588
- const { startMcpServer } = await import("../server-ZUUJT5QC.js");
1634
+ const { startMcpServer } = await import("../server-XWTGBJHV.js");
1589
1635
  await startMcpServer();
1590
1636
  });
1591
1637
  await program.parseAsync(process.argv);
@@ -5,14 +5,15 @@ import {
5
5
  matchSubTasks,
6
6
  orchestrate,
7
7
  validateAndNormalizeSubtasks
8
- } from "./chunk-J46N2TCC.js";
8
+ } from "./chunk-OPRCWXD5.js";
9
9
  import {
10
10
  requestCapability
11
- } from "./chunk-R4F4XII4.js";
11
+ } from "./chunk-YKMBFQC2.js";
12
12
  import "./chunk-4NFJ3VYZ.js";
13
13
  import "./chunk-HLUEOLSZ.js";
14
14
  import "./chunk-NQANA6WH.js";
15
15
  import "./chunk-6QMDJVMS.js";
16
+ import "./chunk-GIEJVKZZ.js";
16
17
  import "./chunk-IVOYM3WG.js";
17
18
  import {
18
19
  getCardsByCapabilityType,
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  executeCapabilityBatch,
3
3
  executeCapabilityRequest
4
- } from "./chunk-6FZ4WYQL.js";
4
+ } from "./chunk-JDAFLPR7.js";
5
+ import "./chunk-RF4A5X5U.js";
6
+ import "./chunk-WK2QSO4E.js";
5
7
  import "./chunk-2PP5MQPD.js";
6
8
  import "./chunk-PIPCGRCR.js";
7
9
  import "./chunk-HU46M4JA.js";
10
+ import "./chunk-GIEJVKZZ.js";
8
11
  import "./chunk-U6LP4KWN.js";
9
12
  import "./chunk-3XPBFF6H.js";
10
13
  import "./chunk-COA2D7QM.js";
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  executeCapabilityBatch,
3
3
  executeCapabilityRequest
4
- } from "./chunk-PMRTQ2RL.js";
4
+ } from "./chunk-5SIGMKOD.js";
5
5
  import "./chunk-NQANA6WH.js";
6
6
  import "./chunk-6QMDJVMS.js";
7
+ import "./chunk-GIEJVKZZ.js";
7
8
  import "./chunk-IVOYM3WG.js";
8
9
  import "./chunk-ZU2TP7CN.js";
9
10
  import "./chunk-EE3V3DXK.js";
package/dist/index.d.ts CHANGED
@@ -3989,8 +3989,8 @@ declare const RelayMessageSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3989
3989
  escrow_id: string;
3990
3990
  public_key?: string | undefined;
3991
3991
  failure_reason?: "timeout" | "bad_execution" | "overload" | "auth_error" | "not_found" | undefined;
3992
- consumer_agent_id?: string | undefined;
3993
3992
  signature?: string | undefined;
3993
+ consumer_agent_id?: string | undefined;
3994
3994
  result_hash?: string | undefined;
3995
3995
  }, {
3996
3996
  type: "escrow_settle";
@@ -3999,8 +3999,8 @@ declare const RelayMessageSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3999
3999
  escrow_id: string;
4000
4000
  public_key?: string | undefined;
4001
4001
  failure_reason?: "timeout" | "bad_execution" | "overload" | "auth_error" | "not_found" | undefined;
4002
- consumer_agent_id?: string | undefined;
4003
4002
  signature?: string | undefined;
4003
+ consumer_agent_id?: string | undefined;
4004
4004
  result_hash?: string | undefined;
4005
4005
  }>, z.ZodObject<{
4006
4006
  type: z.ZodLiteral<"escrow_settled">;
@@ -4465,9 +4465,9 @@ declare const EscrowReceiptSchema: z.ZodObject<{
4465
4465
  signature: z.ZodString;
4466
4466
  }, "strip", z.ZodTypeAny, {
4467
4467
  timestamp: string;
4468
+ signature: string;
4468
4469
  card_id: string;
4469
4470
  amount: number;
4470
- signature: string;
4471
4471
  requester_owner: string;
4472
4472
  requester_public_key: string;
4473
4473
  nonce: string;
@@ -4475,9 +4475,9 @@ declare const EscrowReceiptSchema: z.ZodObject<{
4475
4475
  requester_agent_id?: string | undefined;
4476
4476
  }, {
4477
4477
  timestamp: string;
4478
+ signature: string;
4478
4479
  card_id: string;
4479
4480
  amount: number;
4480
- signature: string;
4481
4481
  requester_owner: string;
4482
4482
  requester_public_key: string;
4483
4483
  nonce: string;
@@ -4652,7 +4652,6 @@ declare const AgentCertificateSchema: z.ZodObject<{
4652
4652
  /** Base64url Ed25519 signature over { identity, issued_at, expires_at, issuer_public_key }. */
4653
4653
  signature: z.ZodString;
4654
4654
  }, "strip", z.ZodTypeAny, {
4655
- signature: string;
4656
4655
  identity: {
4657
4656
  owner: string;
4658
4657
  agent_id: string;
@@ -4666,8 +4665,8 @@ declare const AgentCertificateSchema: z.ZodObject<{
4666
4665
  issued_at: string;
4667
4666
  expires_at: string;
4668
4667
  issuer_public_key: string;
4669
- }, {
4670
4668
  signature: string;
4669
+ }, {
4671
4670
  identity: {
4672
4671
  owner: string;
4673
4672
  agent_id: string;
@@ -4681,6 +4680,7 @@ declare const AgentCertificateSchema: z.ZodObject<{
4681
4680
  issued_at: string;
4682
4681
  expires_at: string;
4683
4682
  issuer_public_key: string;
4683
+ signature: string;
4684
4684
  }>;
4685
4685
  type AgentCertificate = z.infer<typeof AgentCertificateSchema>;
4686
4686
  /**