agentbnb 4.0.1 → 4.0.4

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 (47) hide show
  1. package/README.md +33 -2
  2. package/dist/{card-4XH4AOTE.js → card-RNEWSAQ6.js} +1 -1
  3. package/dist/card-RSGDCHCV.js +88 -0
  4. package/dist/{chunk-MQKYGY5I.js → chunk-4P3EMGL4.js} +3 -3
  5. package/dist/{chunk-DVAS2443.js → chunk-5KFI5X7B.js} +1 -1
  6. package/dist/{chunk-Q7HRI666.js → chunk-5QGXARLJ.js} +8 -6
  7. package/dist/{chunk-3UKAVIMC.js → chunk-BH6WGYFB.js} +4 -4
  8. package/dist/{chunk-XQHN6ITI.js → chunk-DNWT5FZQ.js} +22 -2
  9. package/dist/chunk-EVBX22YU.js +68 -0
  10. package/dist/{chunk-QJEOCKVF.js → chunk-FF226TIV.js} +1 -1
  11. package/dist/{chunk-6K5WUVF3.js → chunk-GGYC5U2Z.js} +4 -4
  12. package/dist/{chunk-ODBGCCEH.js → chunk-HH24WMFN.js} +18 -3
  13. package/dist/chunk-JXEOE7HX.js +295 -0
  14. package/dist/{chunk-M3G5NR2Z.js → chunk-QITOPASZ.js} +8 -2
  15. package/dist/{chunk-TLU7ALCZ.js → chunk-T7NS2J2B.js} +1 -1
  16. package/dist/chunk-UB2NPFC7.js +165 -0
  17. package/dist/{chunk-FNKBHBYK.js → chunk-WGZ5AGOX.js} +37 -3
  18. package/dist/{chunk-KJG2UJV5.js → chunk-XND2DWTZ.js} +3 -2
  19. package/dist/cli/index.d.ts +1 -0
  20. package/dist/cli/index.js +406 -135
  21. package/dist/{client-BTPIFY7E.js → client-T5MTY3CS.js} +3 -3
  22. package/dist/conduct-GZQNFTRP.js +19 -0
  23. package/dist/{conduct-CW62HBPT.js → conduct-N52JX7RT.js} +9 -9
  24. package/dist/conductor-mode-ESGFZ6T5.js +739 -0
  25. package/dist/{conductor-mode-3JS4VWCR.js → conductor-mode-XUWGR4ZE.js} +7 -7
  26. package/dist/execute-QH6F54D7.js +10 -0
  27. package/dist/index.d.ts +151 -2
  28. package/dist/index.js +135 -67
  29. package/dist/peers-E4MKNNDN.js +12 -0
  30. package/dist/{request-CNZ3XIVX.js → request-4GQSSM4B.js} +8 -8
  31. package/dist/{serve-skill-SUOGUM7N.js → serve-skill-Q6NHX2RA.js} +5 -5
  32. package/dist/{server-2LWHL24P.js → server-B5E566CI.js} +10 -10
  33. package/dist/skills/agentbnb/bootstrap.js +2001 -0
  34. package/openclaw.plugin.json +54 -0
  35. package/package.json +9 -6
  36. package/skills/agentbnb/HEARTBEAT.rules.md +47 -0
  37. package/skills/agentbnb/SKILL.md +166 -0
  38. package/skills/agentbnb/auto-request.ts +14 -0
  39. package/skills/agentbnb/auto-share.ts +10 -0
  40. package/skills/agentbnb/bootstrap.test.ts +323 -0
  41. package/skills/agentbnb/bootstrap.ts +126 -0
  42. package/skills/agentbnb/credit-mgr.ts +11 -0
  43. package/skills/agentbnb/gateway.ts +12 -0
  44. package/skills/agentbnb/install.sh +210 -0
  45. package/dist/conduct-FXLVGKD5.js +0 -19
  46. package/dist/execute-EXOITLHN.js +0 -10
  47. package/dist/types-FGBUZ3QV.js +0 -18
@@ -0,0 +1,126 @@
1
+ /**
2
+ * AgentBnB Bootstrap — single-call OpenClaw skill lifecycle entry point.
3
+ *
4
+ * Usage: `const ctx = await activate({ owner: 'alice', soulMdPath: './SOUL.md' });`
5
+ * Teardown: `await deactivate(ctx);`
6
+ */
7
+
8
+ import { existsSync, readFileSync } from 'node:fs';
9
+ import { randomUUID } from 'node:crypto';
10
+ import { homedir } from 'node:os';
11
+ import { join } from 'node:path';
12
+ import type { FastifyInstance } from 'fastify';
13
+
14
+ import { AgentRuntime } from '../../src/runtime/agent-runtime.js';
15
+ import { publishFromSoulV2 } from '../../src/openclaw/soul-sync.js';
16
+ import { createGatewayServer } from '../../src/gateway/server.js';
17
+ import { IdleMonitor } from '../../src/autonomy/idle-monitor.js';
18
+ import { DEFAULT_AUTONOMY_CONFIG } from '../../src/autonomy/tiers.js';
19
+ import { AgentBnBError } from '../../src/types/index.js';
20
+ import { ensureIdentity, type AgentIdentity } from '../../src/identity/identity.js';
21
+ import type { AutonomyConfig } from '../../src/autonomy/tiers.js';
22
+ import type { CapabilityCardV2 } from '../../src/types/index.js';
23
+
24
+ /** Configuration for bringing an AgentBnB agent online. */
25
+ export interface BootstrapConfig {
26
+ /** Agent owner identifier. */
27
+ owner: string;
28
+ /** Absolute path to SOUL.md. */
29
+ soulMdPath: string;
30
+ /** Registry DB path. Defaults to ~/.agentbnb/registry.db */
31
+ registryDbPath?: string;
32
+ /** Credit DB path. Defaults to ~/.agentbnb/credit.db */
33
+ creditDbPath?: string;
34
+ /** Gateway port. Defaults to 7700. */
35
+ gatewayPort?: number;
36
+ /** Bearer token for gateway auth. Defaults to a random UUID. */
37
+ gatewayToken?: string;
38
+ /** Handler URL for capability forwarding. Defaults to http://localhost:{gatewayPort}. */
39
+ handlerUrl?: string;
40
+ /** Autonomy tier config. Defaults to DEFAULT_AUTONOMY_CONFIG (Tier 3). */
41
+ autonomyConfig?: AutonomyConfig;
42
+ /** Suppress gateway logs. Defaults to false. */
43
+ silent?: boolean;
44
+ /** When true, ensures identity.json exists on activate. Defaults to true. */
45
+ identityRequired?: boolean;
46
+ }
47
+
48
+ /** Live handles returned by activate(). Pass to deactivate() for clean teardown. */
49
+ export interface BootstrapContext {
50
+ /** AgentRuntime managing DBs and background job lifecycle. */
51
+ runtime: AgentRuntime;
52
+ /** Fastify gateway HTTP server instance. */
53
+ gateway: FastifyInstance;
54
+ /** IdleMonitor background loop. */
55
+ idleMonitor: IdleMonitor;
56
+ /** Published CapabilityCard derived from SOUL.md. */
57
+ card: CapabilityCardV2;
58
+ /** Agent identity (created/loaded during activation). */
59
+ identity: AgentIdentity | null;
60
+ }
61
+
62
+ /**
63
+ * Brings an agent fully online: Runtime -> publishCard -> gateway.listen -> IdleMonitor.
64
+ * @throws {AgentBnBError} FILE_NOT_FOUND if SOUL.md does not exist.
65
+ */
66
+ export async function activate(config: BootstrapConfig): Promise<BootstrapContext> {
67
+ const {
68
+ owner,
69
+ soulMdPath,
70
+ registryDbPath = join(homedir(), '.agentbnb', 'registry.db'),
71
+ creditDbPath = join(homedir(), '.agentbnb', 'credit.db'),
72
+ gatewayPort = 7700,
73
+ gatewayToken = randomUUID(),
74
+ autonomyConfig = DEFAULT_AUTONOMY_CONFIG,
75
+ silent = false,
76
+ } = config;
77
+
78
+ const identityRequired = config.identityRequired ?? false;
79
+ const handlerUrl = config.handlerUrl ?? `http://localhost:${gatewayPort}`;
80
+
81
+ if (!existsSync(soulMdPath)) {
82
+ throw new AgentBnBError(`SOUL.md not found at path: ${soulMdPath}`, 'FILE_NOT_FOUND');
83
+ }
84
+ const soulContent = readFileSync(soulMdPath, 'utf8');
85
+
86
+ const runtime = new AgentRuntime({ registryDbPath, creditDbPath, owner });
87
+ await runtime.start();
88
+
89
+ // Ensure agent identity exists (idempotent — preserves existing identity)
90
+ let identity: AgentIdentity | null = null;
91
+ if (identityRequired) {
92
+ const configDir = join(homedir(), '.agentbnb');
93
+ identity = ensureIdentity(configDir, owner);
94
+ }
95
+
96
+ const card = publishFromSoulV2(runtime.registryDb, soulContent, owner);
97
+
98
+ const gateway = createGatewayServer({
99
+ port: gatewayPort,
100
+ registryDb: runtime.registryDb,
101
+ creditDb: runtime.creditDb,
102
+ tokens: [gatewayToken],
103
+ handlerUrl,
104
+ silent,
105
+ });
106
+ await gateway.listen({ port: gatewayPort, host: '0.0.0.0' });
107
+
108
+ const idleMonitor = new IdleMonitor({ owner, db: runtime.registryDb, autonomyConfig });
109
+ const idleJob = idleMonitor.start();
110
+ runtime.registerJob(idleJob);
111
+
112
+ return { runtime, gateway, idleMonitor, card, identity };
113
+ }
114
+
115
+ /**
116
+ * Tears down all active components: gateway.close() then runtime.shutdown().
117
+ * Idempotent — safe to call multiple times.
118
+ */
119
+ export async function deactivate(ctx: BootstrapContext): Promise<void> {
120
+ try {
121
+ await ctx.gateway.close();
122
+ await ctx.runtime.shutdown();
123
+ } catch {
124
+ // Swallow errors — idempotent teardown
125
+ }
126
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * AgentBnB Credit Management adapter for OpenClaw skill integration.
3
+ * Delegates to BudgetManager and getBalance from src/credit/.
4
+ * This is a thin re-export wrapper — no business logic lives here.
5
+ */
6
+ import { BudgetManager, DEFAULT_BUDGET_CONFIG } from '../../src/credit/budget.js';
7
+ import { getBalance } from '../../src/credit/ledger.js';
8
+ import type { BudgetConfig } from '../../src/credit/budget.js';
9
+
10
+ export { BudgetManager, DEFAULT_BUDGET_CONFIG, getBalance };
11
+ export type { BudgetConfig };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * AgentBnB Gateway adapter for OpenClaw skill integration.
3
+ * Delegates to AgentRuntime and createGatewayServer from src/.
4
+ * This is a thin re-export wrapper — no business logic lives here.
5
+ */
6
+ import { AgentRuntime } from '../../src/runtime/agent-runtime.js';
7
+ import { createGatewayServer } from '../../src/gateway/server.js';
8
+ import type { RuntimeOptions } from '../../src/runtime/agent-runtime.js';
9
+ import type { GatewayOptions } from '../../src/gateway/server.js';
10
+
11
+ export { AgentRuntime, createGatewayServer };
12
+ export type { RuntimeOptions, GatewayOptions };
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env bash
2
+ # install.sh — Post-install automation script for the AgentBnB OpenClaw skill
3
+ #
4
+ # This script is invoked automatically by OpenClaw after installing the agentbnb skill.
5
+ # It handles the full technical setup so a new agent can join the AgentBnB network
6
+ # without reading any documentation or performing any manual steps.
7
+ #
8
+ # Usage:
9
+ # bash install.sh
10
+ #
11
+ # What it does:
12
+ # 1. Checks Node.js >= 20 and pnpm are available
13
+ # 2. Installs the agentbnb CLI globally
14
+ # 3. Initializes the ~/.agentbnb/ config directory with defaults
15
+ # 4. Syncs capabilities from SOUL.md if one is found
16
+ # 5. Prints a success summary and next steps
17
+
18
+ set -euo pipefail
19
+
20
+ # ---------------------------------------------------------------------------
21
+ # Color helpers (graceful fallback for non-color terminals)
22
+ # ---------------------------------------------------------------------------
23
+ if [ -t 1 ] && command -v tput &>/dev/null && tput colors &>/dev/null 2>&1; then
24
+ GREEN=$(tput setaf 2)
25
+ YELLOW=$(tput setaf 3)
26
+ RED=$(tput setaf 1)
27
+ BOLD=$(tput bold)
28
+ RESET=$(tput sgr0)
29
+ else
30
+ GREEN=""
31
+ YELLOW=""
32
+ RED=""
33
+ BOLD=""
34
+ RESET=""
35
+ fi
36
+
37
+ ok() { echo "${GREEN}✓${RESET} $*"; }
38
+ warn() { echo "${YELLOW}⚠${RESET} $*"; }
39
+ err() { echo "${RED}✗${RESET} $*" >&2; }
40
+ step() { echo ""; echo "${BOLD}$*${RESET}"; }
41
+
42
+ # ---------------------------------------------------------------------------
43
+ # Step 1: Check prerequisites
44
+ # ---------------------------------------------------------------------------
45
+ step "Step 1/5 — Checking prerequisites"
46
+
47
+ # Node.js >= 20
48
+ if ! command -v node &>/dev/null; then
49
+ err "Node.js not found. Please install Node.js 20+ from https://nodejs.org"
50
+ exit 1
51
+ fi
52
+
53
+ NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
54
+ if [ "$NODE_VERSION" -lt 20 ]; then
55
+ err "Node.js >= 20 required (found v${NODE_VERSION}). Please upgrade: https://nodejs.org"
56
+ exit 1
57
+ fi
58
+
59
+ ok "Node.js $(node --version) found"
60
+
61
+ # pnpm (attempt install if missing)
62
+ if ! command -v pnpm &>/dev/null; then
63
+ warn "pnpm not found — attempting to install via npm"
64
+ if npm install -g pnpm 2>/dev/null; then
65
+ ok "pnpm installed via npm"
66
+ else
67
+ warn "Could not install pnpm — will fall back to npm for AgentBnB install"
68
+ fi
69
+ else
70
+ ok "pnpm $(pnpm --version) found"
71
+ fi
72
+
73
+ # ---------------------------------------------------------------------------
74
+ # Step 2: Install AgentBnB CLI
75
+ # ---------------------------------------------------------------------------
76
+ step "Step 2/5 — Installing AgentBnB CLI"
77
+
78
+ # Check if already installed (idempotent)
79
+ if command -v agentbnb &>/dev/null; then
80
+ ok "AgentBnB CLI already installed ($(agentbnb --version 2>/dev/null || echo 'version unknown'))"
81
+ else
82
+ INSTALL_OK=false
83
+
84
+ # Try pnpm global install first
85
+ if command -v pnpm &>/dev/null; then
86
+ if pnpm install -g agentbnb 2>/dev/null; then
87
+ INSTALL_OK=true
88
+ ok "AgentBnB CLI installed via pnpm"
89
+ else
90
+ warn "pnpm global install failed — trying npm"
91
+ fi
92
+ fi
93
+
94
+ # Fall back to npm global install
95
+ if [ "$INSTALL_OK" = false ]; then
96
+ if npm install -g agentbnb 2>/dev/null; then
97
+ INSTALL_OK=true
98
+ ok "AgentBnB CLI installed via npm"
99
+ else
100
+ err "Failed to install AgentBnB CLI via both pnpm and npm."
101
+ err "Please run manually: npm install -g agentbnb"
102
+ exit 1
103
+ fi
104
+ fi
105
+
106
+ # Verify the CLI is now callable
107
+ if ! command -v agentbnb &>/dev/null; then
108
+ err "agentbnb command not found after install. Check your PATH."
109
+ exit 1
110
+ fi
111
+
112
+ ok "Verified: agentbnb $(agentbnb --version 2>/dev/null || echo 'installed') is available"
113
+ fi
114
+
115
+ # ---------------------------------------------------------------------------
116
+ # Step 3: Initialize config + connect to public registry
117
+ # ---------------------------------------------------------------------------
118
+ step "Step 3/5 — Initializing AgentBnB config"
119
+
120
+ # agentbnb init is idempotent — safe to run on existing installs
121
+ if agentbnb init --yes 2>/dev/null; then
122
+ ok "Config initialized at ~/.agentbnb/"
123
+ else
124
+ # May already be initialized — check if directory exists
125
+ if [ -d "$HOME/.agentbnb" ]; then
126
+ ok "Config already exists at ~/.agentbnb/ (skipping re-init)"
127
+ else
128
+ err "Failed to initialize AgentBnB config. Run 'agentbnb init' manually."
129
+ exit 1
130
+ fi
131
+ fi
132
+
133
+ # Connect to the public AgentBnB registry (only if not already configured)
134
+ CURRENT_REGISTRY=$(agentbnb config get registry 2>/dev/null || echo "")
135
+ if [ -z "$CURRENT_REGISTRY" ]; then
136
+ if agentbnb config set registry https://hub.agentbnb.dev 2>/dev/null; then
137
+ ok "Connected to public registry: https://hub.agentbnb.dev"
138
+ ok "Registry grants 50 credits to new agents on first sync"
139
+ else
140
+ warn "Could not set registry — run manually: agentbnb config set registry https://hub.agentbnb.dev"
141
+ fi
142
+ else
143
+ ok "Registry already configured: $CURRENT_REGISTRY"
144
+ fi
145
+
146
+ # ---------------------------------------------------------------------------
147
+ # Step 4: Sync from SOUL.md
148
+ # ---------------------------------------------------------------------------
149
+ step "Step 4/5 — Syncing capabilities from SOUL.md"
150
+
151
+ SOUL_PATH=""
152
+ # Check current directory first, then parent directory
153
+ if [ -f "SOUL.md" ]; then
154
+ SOUL_PATH="SOUL.md"
155
+ elif [ -f "../SOUL.md" ]; then
156
+ SOUL_PATH="../SOUL.md"
157
+ fi
158
+
159
+ if [ -n "$SOUL_PATH" ]; then
160
+ ok "Found SOUL.md at: $SOUL_PATH"
161
+ if agentbnb openclaw sync 2>/dev/null; then
162
+ ok "Capability card published to AgentBnB network"
163
+ else
164
+ warn "Sync failed — your agent is not yet visible on the network."
165
+ warn "Retry with: agentbnb openclaw sync"
166
+ fi
167
+ else
168
+ warn "No SOUL.md found in current or parent directory."
169
+ warn "Run 'agentbnb openclaw sync' manually after creating your SOUL.md"
170
+ fi
171
+
172
+ # ---------------------------------------------------------------------------
173
+ # Step 5: Print success summary
174
+ # ---------------------------------------------------------------------------
175
+ step "Step 5/5 — Setup complete"
176
+
177
+ echo ""
178
+ echo "${GREEN}${BOLD}AgentBnB skill installed successfully!${RESET}"
179
+ echo ""
180
+ echo "What was set up:"
181
+ ok "AgentBnB CLI available as 'agentbnb'"
182
+ ok "Config directory: ~/.agentbnb/"
183
+ ok "Registry: https://hub.agentbnb.dev (public network)"
184
+ ok "Default autonomy tier: Tier 3 (ask before all transactions)"
185
+ ok "Default credit reserve: 20 credits"
186
+
187
+ # Verify identity.json was created (v4.0+ feature)
188
+ if [ -f "$HOME/.agentbnb/identity.json" ]; then
189
+ ok "Agent identity: ~/.agentbnb/identity.json"
190
+ else
191
+ warn "identity.json not found — will be created on next agentbnb init"
192
+ fi
193
+
194
+ if [ -n "$SOUL_PATH" ]; then
195
+ ok "Capability card synced from SOUL.md"
196
+ fi
197
+
198
+ echo ""
199
+ echo "Next steps:"
200
+ echo " 1. Run ${BOLD}agentbnb serve${RESET} to start accepting requests"
201
+ echo " 2. Run ${BOLD}agentbnb openclaw status${RESET} to see your sync state"
202
+ echo " 3. Run ${BOLD}agentbnb openclaw rules${RESET} to see your autonomy rules"
203
+ echo " 4. Paste the rules into your HEARTBEAT.md (or copy from HEARTBEAT.rules.md)"
204
+ echo ""
205
+ echo "Configure autonomy thresholds:"
206
+ echo " ${BOLD}agentbnb config set tier1 10${RESET} # auto-execute under 10 credits"
207
+ echo " ${BOLD}agentbnb config set tier2 50${RESET} # notify-after under 50 credits"
208
+ echo " ${BOLD}agentbnb config set reserve 20${RESET} # keep 20 credit reserve"
209
+ echo ""
210
+ ok "Welcome to the AgentBnB network."
@@ -1,19 +0,0 @@
1
- import {
2
- conductAction
3
- } from "./chunk-3UKAVIMC.js";
4
- import "./chunk-MQKYGY5I.js";
5
- import "./chunk-3MJT4PZG.js";
6
- import "./chunk-6K5WUVF3.js";
7
- import "./chunk-QJEOCKVF.js";
8
- import "./chunk-KJG2UJV5.js";
9
- import "./chunk-5AH3CMOX.js";
10
- import "./chunk-75OC6E4F.js";
11
- import "./chunk-TLU7ALCZ.js";
12
- import "./chunk-XQHN6ITI.js";
13
- import "./chunk-DVAS2443.js";
14
- import "./chunk-FNKBHBYK.js";
15
- import "./chunk-JOY533UH.js";
16
- import "./chunk-QT7TEVNV.js";
17
- export {
18
- conductAction
19
- };
@@ -1,10 +0,0 @@
1
- import {
2
- executeCapabilityRequest
3
- } from "./chunk-Q7HRI666.js";
4
- import "./chunk-TLU7ALCZ.js";
5
- import "./chunk-XQHN6ITI.js";
6
- import "./chunk-DVAS2443.js";
7
- import "./chunk-FNKBHBYK.js";
8
- export {
9
- executeCapabilityRequest
10
- };
@@ -1,18 +0,0 @@
1
- import {
2
- AgentBnBError,
3
- AnyCardSchema,
4
- CapabilityCardSchema,
5
- CapabilityCardV2Schema,
6
- IOSchemaSchema,
7
- PoweredBySchema,
8
- SkillSchema
9
- } from "./chunk-FNKBHBYK.js";
10
- export {
11
- AgentBnBError,
12
- AnyCardSchema,
13
- CapabilityCardSchema,
14
- CapabilityCardV2Schema,
15
- IOSchemaSchema,
16
- PoweredBySchema,
17
- SkillSchema
18
- };