agentbnb 4.0.4 → 5.1.0

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 (45) hide show
  1. package/dist/chunk-AUBHR7HH.js +25 -0
  2. package/dist/chunk-B5FTAGFN.js +393 -0
  3. package/dist/{chunk-GGYC5U2Z.js → chunk-BTTL24TZ.js} +29 -91
  4. package/dist/chunk-C6KPAFCC.js +387 -0
  5. package/dist/{chunk-JXEOE7HX.js → chunk-CRFCWD6V.js} +163 -92
  6. package/dist/chunk-CSATDXZC.js +89 -0
  7. package/dist/{chunk-T7NS2J2B.js → chunk-DFBX3BBD.js} +84 -1
  8. package/dist/{chunk-DNWT5FZQ.js → chunk-EANI2N2V.js} +98 -1
  9. package/dist/{chunk-HH24WMFN.js → chunk-FLY3WIQR.js} +1 -1
  10. package/dist/{chunk-EVBX22YU.js → chunk-HLUEOLSZ.js} +11 -17
  11. package/dist/chunk-IVOYM3WG.js +25 -0
  12. package/dist/chunk-LCAIAAG2.js +916 -0
  13. package/dist/chunk-MLS6IGGG.js +294 -0
  14. package/dist/{chunk-4P3EMGL4.js → chunk-MNO4COST.js} +5 -3
  15. package/dist/chunk-NH2FIERR.js +138 -0
  16. package/dist/chunk-UKT6H7YT.js +29 -0
  17. package/dist/{chunk-BH6WGYFB.js → chunk-VE3E4AMH.js} +8 -8
  18. package/dist/{chunk-5QGXARLJ.js → chunk-W5BZMKMF.js} +159 -27
  19. package/dist/{chunk-FF226TIV.js → chunk-ZX5623ER.js} +0 -57
  20. package/dist/cli/index.js +362 -4633
  21. package/dist/{conduct-N52JX7RT.js → conduct-KM6ZNJGE.js} +10 -8
  22. package/dist/{conduct-GZQNFTRP.js → conduct-WGTMQND5.js} +10 -8
  23. package/dist/{conductor-mode-XUWGR4ZE.js → conductor-mode-OL2FNOYY.js} +6 -4
  24. package/dist/{conductor-mode-ESGFZ6T5.js → conductor-mode-VRO7TYW2.js} +20 -167
  25. package/dist/execute-CPFSOOO3.js +13 -0
  26. package/dist/execute-IP2QHALV.js +10 -0
  27. package/dist/index.d.ts +14 -8
  28. package/dist/index.js +186 -35
  29. package/dist/{peers-E4MKNNDN.js → peers-CJ7T4RJO.js} +2 -1
  30. package/dist/process-guard-CC7CNRQJ.js +176 -0
  31. package/dist/{request-4GQSSM4B.js → request-YOWPXVLQ.js} +13 -10
  32. package/dist/schema-7BSSLZ4S.js +8 -0
  33. package/dist/{serve-skill-Q6NHX2RA.js → serve-skill-JHFNR7BW.js} +8 -7
  34. package/dist/{server-B5E566CI.js → server-HKJJWFRG.js} +10 -8
  35. package/dist/service-coordinator-5R4LQW6L.js +4917 -0
  36. package/dist/skills/agentbnb/bootstrap.js +5028 -848
  37. package/dist/websocket-client-WRN3HO73.js +6 -0
  38. package/package.json +4 -1
  39. package/skills/agentbnb/SKILL.md +87 -70
  40. package/skills/agentbnb/bootstrap.test.ts +142 -242
  41. package/skills/agentbnb/bootstrap.ts +88 -95
  42. package/skills/agentbnb/install.sh +97 -27
  43. package/dist/card-RNEWSAQ6.js +0 -88
  44. package/dist/chunk-UB2NPFC7.js +0 -165
  45. package/dist/execute-QH6F54D7.js +0 -10
package/dist/index.js CHANGED
@@ -212,6 +212,85 @@ function insertRequestLog(db, entry) {
212
212
  );
213
213
  }
214
214
 
215
+ // src/feedback/store.ts
216
+ import { randomUUID } from "crypto";
217
+ function initFeedbackTable(db) {
218
+ db.exec(`
219
+ CREATE TABLE IF NOT EXISTS feedback (
220
+ id TEXT PRIMARY KEY,
221
+ transaction_id TEXT NOT NULL,
222
+ provider_agent TEXT NOT NULL,
223
+ skill_id TEXT NOT NULL,
224
+ requester_agent TEXT NOT NULL,
225
+ rating INTEGER NOT NULL,
226
+ latency_ms INTEGER NOT NULL,
227
+ result_quality TEXT NOT NULL,
228
+ quality_details TEXT,
229
+ would_reuse INTEGER NOT NULL,
230
+ cost_value_ratio TEXT NOT NULL,
231
+ timestamp TEXT NOT NULL,
232
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
233
+ );
234
+
235
+ CREATE INDEX IF NOT EXISTS feedback_provider_idx ON feedback(provider_agent);
236
+ CREATE INDEX IF NOT EXISTS feedback_skill_idx ON feedback(skill_id);
237
+ `);
238
+ }
239
+ function getFeedbackForProvider(db, providerAgent, sinceDays) {
240
+ let rows;
241
+ if (sinceDays !== void 0) {
242
+ rows = db.prepare(`
243
+ SELECT * FROM feedback
244
+ WHERE provider_agent = ?
245
+ AND timestamp >= datetime('now', ? || ' days')
246
+ ORDER BY timestamp DESC
247
+ `).all(providerAgent, `-${sinceDays}`);
248
+ } else {
249
+ rows = db.prepare(`
250
+ SELECT * FROM feedback
251
+ WHERE provider_agent = ?
252
+ ORDER BY timestamp DESC
253
+ `).all(providerAgent);
254
+ }
255
+ return rows.map(rowToFeedback);
256
+ }
257
+ function rowToFeedback(row) {
258
+ return {
259
+ transaction_id: row["transaction_id"],
260
+ provider_agent: row["provider_agent"],
261
+ skill_id: row["skill_id"],
262
+ requester_agent: row["requester_agent"],
263
+ rating: row["rating"],
264
+ latency_ms: row["latency_ms"],
265
+ result_quality: row["result_quality"],
266
+ quality_details: row["quality_details"] ?? void 0,
267
+ would_reuse: row["would_reuse"] === 1,
268
+ cost_value_ratio: row["cost_value_ratio"],
269
+ timestamp: row["timestamp"]
270
+ };
271
+ }
272
+
273
+ // src/evolution/store.ts
274
+ import { randomUUID as randomUUID2 } from "crypto";
275
+ function initEvolutionTable(db) {
276
+ db.exec(`
277
+ CREATE TABLE IF NOT EXISTS evolution_versions (
278
+ id TEXT PRIMARY KEY,
279
+ template_name TEXT NOT NULL,
280
+ template_version TEXT NOT NULL,
281
+ publisher_agent TEXT NOT NULL,
282
+ changelog TEXT NOT NULL,
283
+ core_memory_snapshot TEXT NOT NULL,
284
+ fitness_improvement REAL NOT NULL,
285
+ timestamp TEXT NOT NULL,
286
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
287
+ );
288
+
289
+ CREATE INDEX IF NOT EXISTS evolution_template_idx
290
+ ON evolution_versions(template_name, created_at DESC);
291
+ `);
292
+ }
293
+
215
294
  // src/registry/store.ts
216
295
  var V2_FTS_TRIGGERS = `
217
296
  DROP TRIGGER IF EXISTS cards_ai;
@@ -366,6 +445,8 @@ function openDatabase(path = ":memory:") {
366
445
  );
367
446
  `);
368
447
  createRequestLogTable(db);
448
+ initFeedbackTable(db);
449
+ initEvolutionTable(db);
369
450
  runMigrations(db);
370
451
  return db;
371
452
  }
@@ -509,6 +590,52 @@ function listCards(db, owner) {
509
590
  return rows.map((row) => JSON.parse(row.data));
510
591
  }
511
592
 
593
+ // src/feedback/reputation.ts
594
+ var QUALITY_SCORES = {
595
+ excellent: 1,
596
+ good: 0.8,
597
+ acceptable: 0.6,
598
+ poor: 0.3,
599
+ failed: 0
600
+ };
601
+ var COST_VALUE_SCORES = {
602
+ great: 1,
603
+ fair: 0.6,
604
+ overpriced: 0.2
605
+ };
606
+ var DECAY_DAYS = 30;
607
+ var WEIGHTS = {
608
+ rating: 0.4,
609
+ quality: 0.3,
610
+ would_reuse: 0.2,
611
+ cost_value: 0.1
612
+ };
613
+ function computeReputation(feedbacks) {
614
+ if (feedbacks.length === 0) return 0.5;
615
+ const now = Date.now();
616
+ let weightedSum = 0;
617
+ let totalWeight = 0;
618
+ for (const fb of feedbacks) {
619
+ const feedbackDate = new Date(fb.timestamp).getTime();
620
+ const ageDays = Math.max(0, (now - feedbackDate) / (1e3 * 60 * 60 * 24));
621
+ const recencyWeight = Math.exp(-ageDays / DECAY_DAYS);
622
+ const ratingScore = (fb.rating - 1) / 4;
623
+ const qualityScore = QUALITY_SCORES[fb.result_quality];
624
+ const reuseScore = fb.would_reuse ? 1 : 0;
625
+ const costScore = COST_VALUE_SCORES[fb.cost_value_ratio];
626
+ const componentScore = WEIGHTS.rating * ratingScore + WEIGHTS.quality * qualityScore + WEIGHTS.would_reuse * reuseScore + WEIGHTS.cost_value * costScore;
627
+ weightedSum += recencyWeight * componentScore;
628
+ totalWeight += recencyWeight;
629
+ }
630
+ if (totalWeight === 0) return 0.5;
631
+ const raw = weightedSum / totalWeight;
632
+ return Math.max(0, Math.min(1, raw));
633
+ }
634
+ function getReputationScore(db, agentId) {
635
+ const feedbacks = getFeedbackForProvider(db, agentId);
636
+ return computeReputation(feedbacks);
637
+ }
638
+
512
639
  // src/registry/matcher.ts
513
640
  function searchCards(db, query, filters = {}) {
514
641
  const words = query.trim().split(/\s+/).map((w) => w.replace(/["*^{}():]/g, "")).filter((w) => w.length > 0);
@@ -537,19 +664,34 @@ function searchCards(db, query, filters = {}) {
537
664
  const stmt = db.prepare(sql);
538
665
  const rows = stmt.all(...params);
539
666
  const results = rows.map((row) => JSON.parse(row.data));
667
+ let filtered = results;
540
668
  if (filters.apis_used && filters.apis_used.length > 0) {
541
669
  const requiredApis = filters.apis_used;
542
- return results.filter((card) => {
670
+ filtered = filtered.filter((card) => {
543
671
  const cardApis = card.metadata?.apis_used ?? [];
544
672
  return requiredApis.every((api) => cardApis.includes(api));
545
673
  });
546
674
  }
547
- return results;
675
+ if (filters.min_reputation !== void 0 && filters.min_reputation > 0) {
676
+ filtered = applyReputationFilter(db, filtered, filters.min_reputation);
677
+ }
678
+ return filtered;
679
+ }
680
+ function applyReputationFilter(db, cards, minReputation) {
681
+ const owners = [...new Set(cards.map((c) => c.owner))];
682
+ const reputationMap = /* @__PURE__ */ new Map();
683
+ for (const owner of owners) {
684
+ reputationMap.set(owner, getReputationScore(db, owner));
685
+ }
686
+ return cards.filter((card) => {
687
+ const score = reputationMap.get(card.owner) ?? 0.5;
688
+ return score >= minReputation;
689
+ });
548
690
  }
549
691
 
550
692
  // src/credit/ledger.ts
551
693
  import Database2 from "better-sqlite3";
552
- import { randomUUID } from "crypto";
694
+ import { randomUUID as randomUUID3 } from "crypto";
553
695
  var CREDIT_SCHEMA = `
554
696
  CREATE TABLE IF NOT EXISTS credit_balances (
555
697
  owner TEXT PRIMARY KEY,
@@ -605,7 +747,7 @@ function recordEarning(db, owner, amount, _cardId, receiptNonce) {
605
747
  ).run(amount, now, owner);
606
748
  db.prepare(
607
749
  "INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
608
- ).run(randomUUID(), owner, amount, "remote_earning", receiptNonce, now);
750
+ ).run(randomUUID3(), owner, amount, "remote_earning", receiptNonce, now);
609
751
  })();
610
752
  }
611
753
 
@@ -613,12 +755,12 @@ function recordEarning(db, owner, amount, _cardId, receiptNonce) {
613
755
  import Fastify from "fastify";
614
756
 
615
757
  // src/gateway/execute.ts
616
- import { randomUUID as randomUUID3 } from "crypto";
758
+ import { randomUUID as randomUUID5 } from "crypto";
617
759
 
618
760
  // src/credit/escrow.ts
619
- import { randomUUID as randomUUID2 } from "crypto";
761
+ import { randomUUID as randomUUID4 } from "crypto";
620
762
  function holdEscrow(db, owner, amount, cardId) {
621
- const escrowId = randomUUID2();
763
+ const escrowId = randomUUID4();
622
764
  const now = (/* @__PURE__ */ new Date()).toISOString();
623
765
  const hold = db.transaction(() => {
624
766
  const row = db.prepare("SELECT balance FROM credit_balances WHERE owner = ?").get(owner);
@@ -633,7 +775,7 @@ function holdEscrow(db, owner, amount, cardId) {
633
775
  ).run(escrowId, owner, amount, cardId, "held", now);
634
776
  db.prepare(
635
777
  "INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
636
- ).run(randomUUID2(), owner, -amount, "escrow_hold", escrowId, now);
778
+ ).run(randomUUID4(), owner, -amount, "escrow_hold", escrowId, now);
637
779
  });
638
780
  hold();
639
781
  return escrowId;
@@ -662,7 +804,7 @@ function settleEscrow(db, escrowId, recipientOwner) {
662
804
  ).run("settled", now, escrowId);
663
805
  db.prepare(
664
806
  "INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
665
- ).run(randomUUID2(), recipientOwner, escrow.amount, "settlement", escrowId, now);
807
+ ).run(randomUUID4(), recipientOwner, escrow.amount, "settlement", escrowId, now);
666
808
  });
667
809
  settle();
668
810
  }
@@ -687,7 +829,7 @@ function releaseEscrow(db, escrowId) {
687
829
  ).run("released", now, escrowId);
688
830
  db.prepare(
689
831
  "INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
690
- ).run(randomUUID2(), escrow.owner, escrow.amount, "refund", escrowId, now);
832
+ ).run(randomUUID4(), escrow.owner, escrow.amount, "refund", escrowId, now);
691
833
  });
692
834
  release();
693
835
  }
@@ -709,7 +851,7 @@ function confirmEscrowDebit(db, escrowId) {
709
851
  ).run("settled", now, escrowId);
710
852
  db.prepare(
711
853
  "INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
712
- ).run(randomUUID2(), escrow.owner, 0, "remote_settlement_confirmed", escrowId, now);
854
+ ).run(randomUUID4(), escrow.owner, 0, "remote_settlement_confirmed", escrowId, now);
713
855
  });
714
856
  confirm();
715
857
  }
@@ -858,7 +1000,7 @@ async function executeCapabilityRequest(opts) {
858
1000
  updateReputation(registryDb, cardId, false, latencyMs);
859
1001
  try {
860
1002
  insertRequestLog(registryDb, {
861
- id: randomUUID3(),
1003
+ id: randomUUID5(),
862
1004
  card_id: cardId,
863
1005
  card_name: cardName,
864
1006
  skill_id: resolvedSkillId,
@@ -884,7 +1026,7 @@ async function executeCapabilityRequest(opts) {
884
1026
  updateReputation(registryDb, cardId, true, latencyMs);
885
1027
  try {
886
1028
  insertRequestLog(registryDb, {
887
- id: randomUUID3(),
1029
+ id: randomUUID5(),
888
1030
  card_id: cardId,
889
1031
  card_name: cardName,
890
1032
  skill_id: resolvedSkillId,
@@ -1842,7 +1984,7 @@ var CommandExecutor = class {
1842
1984
  };
1843
1985
 
1844
1986
  // src/conductor/task-decomposer.ts
1845
- import { randomUUID as randomUUID4 } from "crypto";
1987
+ import { randomUUID as randomUUID6 } from "crypto";
1846
1988
  var TEMPLATES = {
1847
1989
  "video-production": {
1848
1990
  keywords: ["video", "demo", "clip", "animation"],
@@ -1937,7 +2079,7 @@ function decompose(task, _availableCapabilities) {
1937
2079
  for (const template of Object.values(TEMPLATES)) {
1938
2080
  const matched = template.keywords.some((kw) => lower.includes(kw));
1939
2081
  if (!matched) continue;
1940
- const ids = template.steps.map(() => randomUUID4());
2082
+ const ids = template.steps.map(() => randomUUID6());
1941
2083
  return template.steps.map((step, i) => ({
1942
2084
  id: ids[i],
1943
2085
  description: step.description,
@@ -1951,10 +2093,10 @@ function decompose(task, _availableCapabilities) {
1951
2093
  }
1952
2094
 
1953
2095
  // src/gateway/client.ts
1954
- import { randomUUID as randomUUID5 } from "crypto";
2096
+ import { randomUUID as randomUUID7 } from "crypto";
1955
2097
  async function requestCapability(opts) {
1956
2098
  const { gatewayUrl, token, cardId, params = {}, timeoutMs = 3e5, escrowReceipt, identity } = opts;
1957
- const id = randomUUID5();
2099
+ const id = randomUUID7();
1958
2100
  const payload = {
1959
2101
  jsonrpc: "2.0",
1960
2102
  id,
@@ -2024,10 +2166,10 @@ async function requestViaRelay(relay, opts) {
2024
2166
  }
2025
2167
 
2026
2168
  // src/autonomy/tiers.ts
2027
- import { randomUUID as randomUUID6 } from "crypto";
2169
+ import { randomUUID as randomUUID8 } from "crypto";
2028
2170
 
2029
2171
  // src/autonomy/pending-requests.ts
2030
- import { randomUUID as randomUUID7 } from "crypto";
2172
+ import { randomUUID as randomUUID9 } from "crypto";
2031
2173
 
2032
2174
  // src/cli/peers.ts
2033
2175
  import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "fs";
@@ -2135,11 +2277,20 @@ function minMaxNormalize(values) {
2135
2277
  function scorePeers(candidates, selfOwner) {
2136
2278
  const eligible = candidates.filter((c) => c.card.owner !== selfOwner);
2137
2279
  if (eligible.length === 0) return [];
2138
- const successRates = eligible.map((c) => c.card.metadata?.success_rate ?? 0.5);
2280
+ const successRates = eligible.map((c) => {
2281
+ if (c.skillMetadata?.success_rate !== void 0) {
2282
+ return c.skillMetadata.success_rate;
2283
+ }
2284
+ return c.card.metadata?.success_rate ?? 0.5;
2285
+ });
2139
2286
  const costEfficiencies = eligible.map((c) => c.cost === 0 ? 1 : 1 / c.cost);
2140
2287
  const idleRates = eligible.map((c) => {
2288
+ if (c.skillInternal !== void 0) {
2289
+ const skillIdleRate = c.skillInternal["idle_rate"];
2290
+ if (typeof skillIdleRate === "number") return skillIdleRate;
2291
+ }
2141
2292
  const internal = c.card._internal;
2142
- const idleRate = internal?.idle_rate;
2293
+ const idleRate = internal?.["idle_rate"];
2143
2294
  return typeof idleRate === "number" ? idleRate : 1;
2144
2295
  });
2145
2296
  const normSuccess = minMaxNormalize(successRates);
@@ -2662,7 +2813,7 @@ var ConductorMode = class {
2662
2813
 
2663
2814
  // src/credit/escrow-receipt.ts
2664
2815
  import { z as z3 } from "zod";
2665
- import { randomUUID as randomUUID8 } from "crypto";
2816
+ import { randomUUID as randomUUID10 } from "crypto";
2666
2817
  var EscrowReceiptSchema = z3.object({
2667
2818
  requester_owner: z3.string().min(1),
2668
2819
  requester_public_key: z3.string().min(1),
@@ -2682,7 +2833,7 @@ function createSignedEscrowReceipt(db, privateKey, publicKey, opts) {
2682
2833
  card_id: opts.cardId,
2683
2834
  ...opts.skillId ? { skill_id: opts.skillId } : {},
2684
2835
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2685
- nonce: randomUUID8()
2836
+ nonce: randomUUID10()
2686
2837
  };
2687
2838
  const signature = signEscrowReceipt(receiptData, privateKey);
2688
2839
  const receipt = {
@@ -3053,7 +3204,7 @@ var AgentBnBProvider = class {
3053
3204
 
3054
3205
  // src/identity/guarantor.ts
3055
3206
  import { z as z5 } from "zod";
3056
- import { randomUUID as randomUUID9 } from "crypto";
3207
+ import { randomUUID as randomUUID11 } from "crypto";
3057
3208
  var MAX_AGENTS_PER_GUARANTOR = 10;
3058
3209
  var GUARANTOR_CREDIT_POOL = 50;
3059
3210
  var GuarantorRecordSchema = z5.object({
@@ -3092,7 +3243,7 @@ function registerGuarantor(db, githubLogin) {
3092
3243
  );
3093
3244
  }
3094
3245
  const record = {
3095
- id: randomUUID9(),
3246
+ id: randomUUID11(),
3096
3247
  github_login: githubLogin,
3097
3248
  agent_count: 0,
3098
3249
  credit_pool: GUARANTOR_CREDIT_POOL,
@@ -3166,7 +3317,7 @@ function getAgentGuarantor(db, agentId) {
3166
3317
  function initiateGithubAuth() {
3167
3318
  return {
3168
3319
  auth_url: "https://github.com/login/oauth/authorize?client_id=PLACEHOLDER&scope=read:user",
3169
- state: randomUUID9()
3320
+ state: randomUUID11()
3170
3321
  };
3171
3322
  }
3172
3323
 
@@ -3250,7 +3401,7 @@ var RelayMessageSchema = z6.discriminatedUnion("type", [
3250
3401
  ]);
3251
3402
 
3252
3403
  // src/relay/websocket-relay.ts
3253
- import { randomUUID as randomUUID12 } from "crypto";
3404
+ import { randomUUID as randomUUID14 } from "crypto";
3254
3405
 
3255
3406
  // src/relay/relay-credit.ts
3256
3407
  function lookupCardPrice(registryDb, cardId, skillId) {
@@ -3308,10 +3459,10 @@ function releaseForRelay(creditDb, escrowId) {
3308
3459
  }
3309
3460
 
3310
3461
  // src/hub-agent/relay-bridge.ts
3311
- import { randomUUID as randomUUID11 } from "crypto";
3462
+ import { randomUUID as randomUUID13 } from "crypto";
3312
3463
 
3313
3464
  // src/hub-agent/job-queue.ts
3314
- import { randomUUID as randomUUID10 } from "crypto";
3465
+ import { randomUUID as randomUUID12 } from "crypto";
3315
3466
  function updateJobStatus(db, jobId, status, result) {
3316
3467
  const now = (/* @__PURE__ */ new Date()).toISOString();
3317
3468
  if (result !== void 0) {
@@ -3432,7 +3583,7 @@ function registerWebSocketRelay(server, db, creditDb) {
3432
3583
  function logAgentJoined(owner, cardName, cardId) {
3433
3584
  try {
3434
3585
  insertRequestLog(db, {
3435
- id: randomUUID12(),
3586
+ id: randomUUID14(),
3436
3587
  card_id: cardId,
3437
3588
  card_name: cardName,
3438
3589
  requester: owner,
@@ -3774,7 +3925,7 @@ function registerWebSocketRelay(server, db, creditDb) {
3774
3925
 
3775
3926
  // src/relay/websocket-client.ts
3776
3927
  import WebSocket from "ws";
3777
- import { randomUUID as randomUUID13 } from "crypto";
3928
+ import { randomUUID as randomUUID15 } from "crypto";
3778
3929
  var RelayClient = class {
3779
3930
  ws = null;
3780
3931
  opts;
@@ -3871,7 +4022,7 @@ var RelayClient = class {
3871
4022
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN || !this.registered) {
3872
4023
  throw new Error("Not connected to registry relay");
3873
4024
  }
3874
- const id = randomUUID13();
4025
+ const id = randomUUID15();
3875
4026
  const timeoutMs = opts.timeoutMs ?? 3e5;
3876
4027
  return new Promise((resolve, reject) => {
3877
4028
  const timeout = setTimeout(() => {
@@ -4075,12 +4226,12 @@ var RelayClient = class {
4075
4226
  };
4076
4227
 
4077
4228
  // src/onboarding/index.ts
4078
- import { randomUUID as randomUUID15 } from "crypto";
4229
+ import { randomUUID as randomUUID17 } from "crypto";
4079
4230
  import { existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
4080
4231
  import { join as join5 } from "path";
4081
4232
 
4082
4233
  // src/cli/onboarding.ts
4083
- import { randomUUID as randomUUID14 } from "crypto";
4234
+ import { randomUUID as randomUUID16 } from "crypto";
4084
4235
  import { createConnection } from "net";
4085
4236
  var KNOWN_API_KEYS = [
4086
4237
  "OPENAI_API_KEY",
@@ -4222,7 +4373,7 @@ function capabilitiesToV2Card(capabilities, owner, agentName) {
4222
4373
  }));
4223
4374
  const card = {
4224
4375
  spec_version: "2.0",
4225
- id: randomUUID15(),
4376
+ id: randomUUID17(),
4226
4377
  owner,
4227
4378
  agent_name: agentName ?? owner,
4228
4379
  skills,
@@ -3,7 +3,8 @@ import {
3
3
  loadPeers,
4
4
  removePeer,
5
5
  savePeer
6
- } from "./chunk-EVBX22YU.js";
6
+ } from "./chunk-HLUEOLSZ.js";
7
+ import "./chunk-IVOYM3WG.js";
7
8
  export {
8
9
  findPeer,
9
10
  loadPeers,
@@ -0,0 +1,176 @@
1
+ import {
2
+ AgentBnBError
3
+ } from "./chunk-WGZ5AGOX.js";
4
+
5
+ // src/runtime/process-guard.ts
6
+ import { dirname, join } from "path";
7
+ import {
8
+ closeSync,
9
+ existsSync,
10
+ mkdirSync,
11
+ openSync,
12
+ readFileSync,
13
+ unlinkSync,
14
+ writeFileSync
15
+ } from "fs";
16
+ import { homedir } from "os";
17
+ var ProcessGuard = class {
18
+ pidFilePath;
19
+ /**
20
+ * Creates a ProcessGuard that controls single-process ownership via pid file.
21
+ *
22
+ * @param pidFilePath - Absolute path to pid file. Defaults to ~/.agentbnb/.pid.
23
+ */
24
+ constructor(pidFilePath) {
25
+ this.pidFilePath = pidFilePath ?? join(homedir(), ".agentbnb", ".pid");
26
+ }
27
+ /**
28
+ * Acquires process lock atomically.
29
+ *
30
+ * Uses fs open mode 'wx' so lock creation is a single atomic operation.
31
+ * If a pid file already exists, stale pids are cleaned automatically and
32
+ * acquisition is retried.
33
+ *
34
+ * @param meta - Lock metadata excluding pid (pid is always current process pid).
35
+ * @throws {AgentBnBError} PROCESS_ALREADY_RUNNING if another live process holds lock.
36
+ */
37
+ acquire(meta) {
38
+ mkdirSync(dirname(this.pidFilePath), { recursive: true });
39
+ const payload = {
40
+ pid: process.pid,
41
+ started_at: meta.started_at,
42
+ port: meta.port,
43
+ owner: meta.owner
44
+ };
45
+ for (let attempt = 0; attempt < 2; attempt++) {
46
+ let fd = null;
47
+ try {
48
+ fd = openSync(this.pidFilePath, "wx");
49
+ writeFileSync(fd, `${JSON.stringify(payload)}
50
+ `, "utf8");
51
+ return;
52
+ } catch (err) {
53
+ const fsErr = err;
54
+ if (fsErr.code !== "EEXIST") {
55
+ throw err;
56
+ }
57
+ const cleaned = this.cleanupStaleLock();
58
+ if (cleaned) {
59
+ continue;
60
+ }
61
+ const running = this.readPidFile();
62
+ const details = running ? `pid=${running.pid} owner=${running.owner} port=${running.port}` : `pid-file=${this.pidFilePath}`;
63
+ throw new AgentBnBError(
64
+ `AgentBnB process already running (${details})`,
65
+ "PROCESS_ALREADY_RUNNING"
66
+ );
67
+ } finally {
68
+ if (fd !== null) {
69
+ closeSync(fd);
70
+ }
71
+ }
72
+ }
73
+ throw new AgentBnBError(
74
+ `Failed to acquire process lock: ${this.pidFilePath}`,
75
+ "PROCESS_GUARD_ACQUIRE_FAILED"
76
+ );
77
+ }
78
+ /**
79
+ * Releases process lock.
80
+ *
81
+ * Removes pid file only when:
82
+ * - lock belongs to current process, or
83
+ * - lock holder pid is stale.
84
+ */
85
+ release() {
86
+ const current = this.readPidFile();
87
+ if (!current) return;
88
+ if (current.pid === process.pid || !this.isPidAlive(current.pid)) {
89
+ this.safeUnlink();
90
+ }
91
+ }
92
+ /**
93
+ * Returns running process metadata if lock holder pid is alive.
94
+ * Automatically clears stale pid files.
95
+ *
96
+ * @returns Running metadata or null when no live lock holder exists.
97
+ */
98
+ getRunningMeta() {
99
+ const meta = this.readPidFile();
100
+ if (!meta) return null;
101
+ if (!this.isPidAlive(meta.pid)) {
102
+ this.safeUnlink();
103
+ return null;
104
+ }
105
+ return meta;
106
+ }
107
+ /**
108
+ * Returns true when a live lock holder exists.
109
+ */
110
+ isRunning() {
111
+ return this.getRunningMeta() !== null;
112
+ }
113
+ readPidFile() {
114
+ if (!existsSync(this.pidFilePath)) {
115
+ return null;
116
+ }
117
+ try {
118
+ const raw = readFileSync(this.pidFilePath, "utf8");
119
+ const parsed = JSON.parse(raw);
120
+ if (!isPidFileContent(parsed)) {
121
+ return null;
122
+ }
123
+ return parsed;
124
+ } catch {
125
+ return null;
126
+ }
127
+ }
128
+ cleanupStaleLock() {
129
+ const existing = this.readPidFile();
130
+ if (!existing) {
131
+ return this.safeUnlink();
132
+ }
133
+ if (this.isPidAlive(existing.pid)) {
134
+ return false;
135
+ }
136
+ return this.safeUnlink();
137
+ }
138
+ safeUnlink() {
139
+ try {
140
+ unlinkSync(this.pidFilePath);
141
+ return true;
142
+ } catch (err) {
143
+ const fsErr = err;
144
+ if (fsErr.code === "ENOENT") {
145
+ return false;
146
+ }
147
+ throw err;
148
+ }
149
+ }
150
+ isPidAlive(pid) {
151
+ if (!Number.isInteger(pid) || pid <= 0) {
152
+ return false;
153
+ }
154
+ try {
155
+ process.kill(pid, 0);
156
+ return true;
157
+ } catch (err) {
158
+ const killErr = err;
159
+ if (killErr.code === "EPERM") {
160
+ return true;
161
+ }
162
+ if (killErr.code === "ESRCH") {
163
+ return false;
164
+ }
165
+ return false;
166
+ }
167
+ }
168
+ };
169
+ function isPidFileContent(value) {
170
+ if (value === null || typeof value !== "object") return false;
171
+ const record = value;
172
+ return Number.isInteger(record["pid"]) && typeof record["started_at"] === "string" && Number.isInteger(record["port"]) && typeof record["owner"] === "string";
173
+ }
174
+ export {
175
+ ProcessGuard
176
+ };
@@ -1,13 +1,20 @@
1
1
  import {
2
2
  createLedger
3
- } from "./chunk-HH24WMFN.js";
3
+ } from "./chunk-FLY3WIQR.js";
4
+ import {
5
+ RelayClient
6
+ } from "./chunk-JOY533UH.js";
7
+ import "./chunk-QT7TEVNV.js";
4
8
  import {
5
9
  AutoRequestor,
6
10
  BudgetManager,
7
- DEFAULT_AUTONOMY_CONFIG,
8
11
  DEFAULT_BUDGET_CONFIG
9
- } from "./chunk-GGYC5U2Z.js";
10
- import "./chunk-FF226TIV.js";
12
+ } from "./chunk-BTTL24TZ.js";
13
+ import {
14
+ DEFAULT_AUTONOMY_CONFIG
15
+ } from "./chunk-CSATDXZC.js";
16
+ import "./chunk-ZX5623ER.js";
17
+ import "./chunk-NH2FIERR.js";
11
18
  import {
12
19
  requestCapability
13
20
  } from "./chunk-XND2DWTZ.js";
@@ -15,18 +22,14 @@ import "./chunk-5AH3CMOX.js";
15
22
  import "./chunk-75OC6E4F.js";
16
23
  import {
17
24
  openDatabase
18
- } from "./chunk-T7NS2J2B.js";
25
+ } from "./chunk-DFBX3BBD.js";
19
26
  import {
20
27
  openCreditDb
21
- } from "./chunk-DNWT5FZQ.js";
28
+ } from "./chunk-EANI2N2V.js";
22
29
  import {
23
30
  loadKeyPair
24
31
  } from "./chunk-5KFI5X7B.js";
25
32
  import "./chunk-WGZ5AGOX.js";
26
- import {
27
- RelayClient
28
- } from "./chunk-JOY533UH.js";
29
- import "./chunk-QT7TEVNV.js";
30
33
 
31
34
  // src/mcp/tools/request.ts
32
35
  import { z } from "zod";
@@ -0,0 +1,8 @@
1
+ import {
2
+ FeedbackResponseSchema,
3
+ StructuredFeedbackSchema
4
+ } from "./chunk-AUBHR7HH.js";
5
+ export {
6
+ FeedbackResponseSchema,
7
+ StructuredFeedbackSchema
8
+ };