@claude-flow/plugin-gastown-bridge 0.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.
- package/README.md +646 -0
- package/dist/bridges.cjs +2 -0
- package/dist/bridges.cjs.map +1 -0
- package/dist/bridges.d.cts +924 -0
- package/dist/bridges.d.ts +924 -0
- package/dist/bridges.js +2 -0
- package/dist/bridges.js.map +1 -0
- package/dist/chunk-HACN5YC7.js +14 -0
- package/dist/chunk-HACN5YC7.js.map +1 -0
- package/dist/chunk-JU7XR5TR.cjs +14 -0
- package/dist/chunk-JU7XR5TR.cjs.map +1 -0
- package/dist/index.cjs +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4688 -0
- package/dist/index.d.ts +4688 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/wasm-loader.js +11 -0
- package/dist/wasm-loader.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ChildProcess } from 'child_process';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gas Town CLI Bridge
|
|
6
|
+
*
|
|
7
|
+
* Provides a secure wrapper around the `gt` (Gas Town) CLI tool.
|
|
8
|
+
* Implements command execution with proper input sanitization,
|
|
9
|
+
* argument validation, and error handling.
|
|
10
|
+
*
|
|
11
|
+
* Security Features:
|
|
12
|
+
* - All inputs validated with Zod schemas
|
|
13
|
+
* - No shell execution (uses execFile)
|
|
14
|
+
* - Command allowlist enforcement
|
|
15
|
+
* - Argument sanitization
|
|
16
|
+
*
|
|
17
|
+
* @module v3/plugins/gastown-bridge/bridges/gt-bridge
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Safe string pattern - no shell metacharacters
|
|
22
|
+
*/
|
|
23
|
+
declare const SafeStringSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Safe identifier pattern - alphanumeric with underscore/hyphen
|
|
26
|
+
*/
|
|
27
|
+
declare const IdentifierSchema: z.ZodString;
|
|
28
|
+
/**
|
|
29
|
+
* Gas price schema
|
|
30
|
+
*/
|
|
31
|
+
declare const GasPriceSchema: z.ZodNumber;
|
|
32
|
+
/**
|
|
33
|
+
* Gas limit schema
|
|
34
|
+
*/
|
|
35
|
+
declare const GasLimitSchema: z.ZodNumber;
|
|
36
|
+
/**
|
|
37
|
+
* Transaction hash schema (0x prefixed hex)
|
|
38
|
+
*/
|
|
39
|
+
declare const TxHashSchema: z.ZodString;
|
|
40
|
+
/**
|
|
41
|
+
* Address schema (0x prefixed hex)
|
|
42
|
+
*/
|
|
43
|
+
declare const AddressSchema: z.ZodString;
|
|
44
|
+
/**
|
|
45
|
+
* Network schema
|
|
46
|
+
*/
|
|
47
|
+
declare const NetworkSchema: z.ZodEnum<["mainnet", "goerli", "sepolia", "polygon", "arbitrum", "optimism", "base", "local"]>;
|
|
48
|
+
/**
|
|
49
|
+
* GT command argument schema
|
|
50
|
+
*/
|
|
51
|
+
declare const GtArgumentSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Gas Town executor configuration
|
|
54
|
+
*/
|
|
55
|
+
interface GtBridgeConfig {
|
|
56
|
+
/**
|
|
57
|
+
* Path to gt executable
|
|
58
|
+
* Default: 'gt' (assumes in PATH)
|
|
59
|
+
*/
|
|
60
|
+
gtPath?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Working directory for execution
|
|
63
|
+
*/
|
|
64
|
+
cwd?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Execution timeout in milliseconds
|
|
67
|
+
* Default: 30000 (30 seconds)
|
|
68
|
+
*/
|
|
69
|
+
timeout?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Maximum buffer size for output
|
|
72
|
+
* Default: 10MB
|
|
73
|
+
*/
|
|
74
|
+
maxBuffer?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Environment variables
|
|
77
|
+
*/
|
|
78
|
+
env?: NodeJS.ProcessEnv;
|
|
79
|
+
/**
|
|
80
|
+
* Default network
|
|
81
|
+
*/
|
|
82
|
+
defaultNetwork?: z.infer<typeof NetworkSchema>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Gas estimation result
|
|
86
|
+
*/
|
|
87
|
+
interface GasEstimate {
|
|
88
|
+
gasLimit: number;
|
|
89
|
+
gasPrice: string;
|
|
90
|
+
maxFeePerGas?: string;
|
|
91
|
+
maxPriorityFeePerGas?: string;
|
|
92
|
+
estimatedCost: string;
|
|
93
|
+
estimatedCostUsd?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Transaction status
|
|
97
|
+
*/
|
|
98
|
+
interface TxStatus {
|
|
99
|
+
hash: string;
|
|
100
|
+
status: 'pending' | 'confirmed' | 'failed' | 'dropped';
|
|
101
|
+
blockNumber?: number;
|
|
102
|
+
confirmations?: number;
|
|
103
|
+
gasUsed?: number;
|
|
104
|
+
effectiveGasPrice?: string;
|
|
105
|
+
error?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Network status
|
|
109
|
+
*/
|
|
110
|
+
interface NetworkStatus {
|
|
111
|
+
network: string;
|
|
112
|
+
chainId: number;
|
|
113
|
+
blockNumber: number;
|
|
114
|
+
baseFee?: string;
|
|
115
|
+
gasPrice?: string;
|
|
116
|
+
connected: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* GT execution result
|
|
120
|
+
*/
|
|
121
|
+
interface GtResult<T = unknown> {
|
|
122
|
+
success: boolean;
|
|
123
|
+
data?: T;
|
|
124
|
+
error?: string;
|
|
125
|
+
command: string;
|
|
126
|
+
args: string[];
|
|
127
|
+
durationMs: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Logger interface
|
|
131
|
+
*/
|
|
132
|
+
interface GtLogger {
|
|
133
|
+
debug: (msg: string, meta?: Record<string, unknown>) => void;
|
|
134
|
+
info: (msg: string, meta?: Record<string, unknown>) => void;
|
|
135
|
+
warn: (msg: string, meta?: Record<string, unknown>) => void;
|
|
136
|
+
error: (msg: string, meta?: Record<string, unknown>) => void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Gas Town bridge error codes
|
|
140
|
+
*/
|
|
141
|
+
type GtErrorCode = 'COMMAND_NOT_FOUND' | 'EXECUTION_FAILED' | 'TIMEOUT' | 'INVALID_ARGUMENT' | 'INVALID_OUTPUT' | 'NETWORK_ERROR' | 'VALIDATION_ERROR';
|
|
142
|
+
/**
|
|
143
|
+
* Gas Town bridge error
|
|
144
|
+
*/
|
|
145
|
+
declare class GtBridgeError extends Error {
|
|
146
|
+
readonly code: GtErrorCode;
|
|
147
|
+
readonly command?: string | undefined;
|
|
148
|
+
readonly args?: string[] | undefined;
|
|
149
|
+
readonly cause?: Error | undefined;
|
|
150
|
+
constructor(message: string, code: GtErrorCode, command?: string | undefined, args?: string[] | undefined, cause?: Error | undefined);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Gas Town CLI Bridge
|
|
154
|
+
*
|
|
155
|
+
* Secure wrapper around the `gt` CLI tool for gas estimation
|
|
156
|
+
* and transaction management.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const gtBridge = new GtBridge({ gtPath: '/usr/local/bin/gt' });
|
|
161
|
+
* await gtBridge.initialize();
|
|
162
|
+
*
|
|
163
|
+
* const estimate = await gtBridge.estimateGas({
|
|
164
|
+
* to: '0x...',
|
|
165
|
+
* data: '0x...',
|
|
166
|
+
* network: 'mainnet',
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
declare class GtBridge {
|
|
171
|
+
private config;
|
|
172
|
+
private logger;
|
|
173
|
+
private initialized;
|
|
174
|
+
/** Commands that can be cached (read-only, no side effects) */
|
|
175
|
+
private static readonly CACHEABLE_COMMANDS;
|
|
176
|
+
/** Commands that should use longer cache (static data) */
|
|
177
|
+
private static readonly STATIC_COMMANDS;
|
|
178
|
+
constructor(config?: GtBridgeConfig, logger?: GtLogger);
|
|
179
|
+
/**
|
|
180
|
+
* Initialize the bridge and verify gt is available
|
|
181
|
+
*/
|
|
182
|
+
initialize(): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Execute a gt command with validated arguments
|
|
185
|
+
*
|
|
186
|
+
* @param args - Command arguments (validated and sanitized)
|
|
187
|
+
* @returns Command output
|
|
188
|
+
*/
|
|
189
|
+
execGt(args: string[], skipCache?: boolean): Promise<GtResult<string>>;
|
|
190
|
+
/**
|
|
191
|
+
* Parse JSON output from gt command
|
|
192
|
+
*
|
|
193
|
+
* @param output - Raw command output
|
|
194
|
+
* @returns Parsed JSON object
|
|
195
|
+
*/
|
|
196
|
+
parseGtOutput<T>(output: string): T;
|
|
197
|
+
/**
|
|
198
|
+
* Estimate gas for a transaction
|
|
199
|
+
*/
|
|
200
|
+
estimateGas(params: {
|
|
201
|
+
to: string;
|
|
202
|
+
data?: string;
|
|
203
|
+
value?: string;
|
|
204
|
+
from?: string;
|
|
205
|
+
network?: z.infer<typeof NetworkSchema>;
|
|
206
|
+
}): Promise<GasEstimate>;
|
|
207
|
+
/**
|
|
208
|
+
* Get transaction status
|
|
209
|
+
*/
|
|
210
|
+
getTxStatus(txHash: string, network?: z.infer<typeof NetworkSchema>): Promise<TxStatus>;
|
|
211
|
+
/**
|
|
212
|
+
* Get network status
|
|
213
|
+
*/
|
|
214
|
+
getNetworkStatus(network?: z.infer<typeof NetworkSchema>): Promise<NetworkStatus>;
|
|
215
|
+
/**
|
|
216
|
+
* Get current gas price
|
|
217
|
+
*/
|
|
218
|
+
getGasPrice(network?: z.infer<typeof NetworkSchema>): Promise<{
|
|
219
|
+
gasPrice: string;
|
|
220
|
+
maxFeePerGas?: string;
|
|
221
|
+
maxPriorityFeePerGas?: string;
|
|
222
|
+
baseFee?: string;
|
|
223
|
+
}>;
|
|
224
|
+
/**
|
|
225
|
+
* Simulate a transaction
|
|
226
|
+
*/
|
|
227
|
+
simulate(params: {
|
|
228
|
+
to: string;
|
|
229
|
+
data: string;
|
|
230
|
+
value?: string;
|
|
231
|
+
from?: string;
|
|
232
|
+
network?: z.infer<typeof NetworkSchema>;
|
|
233
|
+
blockNumber?: number;
|
|
234
|
+
}): Promise<{
|
|
235
|
+
success: boolean;
|
|
236
|
+
returnData?: string;
|
|
237
|
+
gasUsed?: number;
|
|
238
|
+
logs?: unknown[];
|
|
239
|
+
error?: string;
|
|
240
|
+
}>;
|
|
241
|
+
/**
|
|
242
|
+
* Decode transaction data
|
|
243
|
+
*/
|
|
244
|
+
decode(data: string, abi?: string): Promise<{
|
|
245
|
+
method: string;
|
|
246
|
+
args: unknown[];
|
|
247
|
+
signature: string;
|
|
248
|
+
}>;
|
|
249
|
+
/**
|
|
250
|
+
* Validate and sanitize command arguments
|
|
251
|
+
*/
|
|
252
|
+
private validateAndSanitizeArgs;
|
|
253
|
+
/**
|
|
254
|
+
* Ensure bridge is initialized
|
|
255
|
+
*/
|
|
256
|
+
private ensureInitialized;
|
|
257
|
+
/**
|
|
258
|
+
* Check if bridge is initialized
|
|
259
|
+
*/
|
|
260
|
+
isInitialized(): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Get current configuration
|
|
263
|
+
*/
|
|
264
|
+
getConfig(): Readonly<Required<GtBridgeConfig>>;
|
|
265
|
+
/**
|
|
266
|
+
* Get cache statistics for performance monitoring
|
|
267
|
+
*/
|
|
268
|
+
getCacheStats(): {
|
|
269
|
+
resultCache: {
|
|
270
|
+
entries: number;
|
|
271
|
+
sizeBytes: number;
|
|
272
|
+
};
|
|
273
|
+
staticCache: {
|
|
274
|
+
entries: number;
|
|
275
|
+
sizeBytes: number;
|
|
276
|
+
};
|
|
277
|
+
parsedCache: {
|
|
278
|
+
entries: number;
|
|
279
|
+
sizeBytes: number;
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Clear all caches (useful for testing or memory pressure)
|
|
284
|
+
*/
|
|
285
|
+
clearCaches(): void;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Create a new Gas Town bridge instance
|
|
289
|
+
*/
|
|
290
|
+
declare function createGtBridge(config?: GtBridgeConfig, logger?: GtLogger): GtBridge;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Beads CLI Bridge
|
|
294
|
+
*
|
|
295
|
+
* Provides a secure wrapper around the `bd` (Beads) CLI tool.
|
|
296
|
+
* Implements command execution with proper input sanitization,
|
|
297
|
+
* argument validation, JSONL parsing, and error handling.
|
|
298
|
+
*
|
|
299
|
+
* Security Features:
|
|
300
|
+
* - All inputs validated with Zod schemas
|
|
301
|
+
* - No shell execution (uses execFile)
|
|
302
|
+
* - Command allowlist enforcement
|
|
303
|
+
* - Argument sanitization
|
|
304
|
+
* - JSONL streaming support
|
|
305
|
+
*
|
|
306
|
+
* @module v3/plugins/gastown-bridge/bridges/bd-bridge
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Bead ID schema (UUID or custom format)
|
|
311
|
+
*/
|
|
312
|
+
declare const BeadIdSchema: z.ZodString;
|
|
313
|
+
/**
|
|
314
|
+
* Bead type schema
|
|
315
|
+
*/
|
|
316
|
+
declare const BeadTypeSchema: z.ZodEnum<["prompt", "response", "code", "context", "memory", "tool-call", "tool-result", "system", "error", "metadata"]>;
|
|
317
|
+
/**
|
|
318
|
+
* Bead schema
|
|
319
|
+
*/
|
|
320
|
+
declare const BeadSchema: z.ZodObject<{
|
|
321
|
+
id: z.ZodString;
|
|
322
|
+
type: z.ZodEnum<["prompt", "response", "code", "context", "memory", "tool-call", "tool-result", "system", "error", "metadata"]>;
|
|
323
|
+
content: z.ZodString;
|
|
324
|
+
timestamp: z.ZodOptional<z.ZodString>;
|
|
325
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
326
|
+
parentId: z.ZodOptional<z.ZodString>;
|
|
327
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
328
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
329
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
330
|
+
embedding: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
331
|
+
hash: z.ZodOptional<z.ZodString>;
|
|
332
|
+
}, "strip", z.ZodTypeAny, {
|
|
333
|
+
type: "error" | "metadata" | "code" | "prompt" | "response" | "context" | "memory" | "tool-call" | "tool-result" | "system";
|
|
334
|
+
id: string;
|
|
335
|
+
content: string;
|
|
336
|
+
metadata?: Record<string, unknown> | undefined;
|
|
337
|
+
embedding?: number[] | undefined;
|
|
338
|
+
parentId?: string | undefined;
|
|
339
|
+
timestamp?: string | undefined;
|
|
340
|
+
threadId?: string | undefined;
|
|
341
|
+
agentId?: string | undefined;
|
|
342
|
+
tags?: string[] | undefined;
|
|
343
|
+
hash?: string | undefined;
|
|
344
|
+
}, {
|
|
345
|
+
type: "error" | "metadata" | "code" | "prompt" | "response" | "context" | "memory" | "tool-call" | "tool-result" | "system";
|
|
346
|
+
id: string;
|
|
347
|
+
content: string;
|
|
348
|
+
metadata?: Record<string, unknown> | undefined;
|
|
349
|
+
embedding?: number[] | undefined;
|
|
350
|
+
parentId?: string | undefined;
|
|
351
|
+
timestamp?: string | undefined;
|
|
352
|
+
threadId?: string | undefined;
|
|
353
|
+
agentId?: string | undefined;
|
|
354
|
+
tags?: string[] | undefined;
|
|
355
|
+
hash?: string | undefined;
|
|
356
|
+
}>;
|
|
357
|
+
/**
|
|
358
|
+
* BD command argument schema
|
|
359
|
+
*/
|
|
360
|
+
declare const BdArgumentSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
361
|
+
/**
|
|
362
|
+
* Bead type (inferred from schema)
|
|
363
|
+
*/
|
|
364
|
+
type Bead = z.infer<typeof BeadSchema>;
|
|
365
|
+
/**
|
|
366
|
+
* Bead type enum
|
|
367
|
+
*/
|
|
368
|
+
type BeadType = z.infer<typeof BeadTypeSchema>;
|
|
369
|
+
/**
|
|
370
|
+
* Beads bridge configuration
|
|
371
|
+
*/
|
|
372
|
+
interface BdBridgeConfig {
|
|
373
|
+
/**
|
|
374
|
+
* Path to bd executable
|
|
375
|
+
* Default: 'bd' (assumes in PATH)
|
|
376
|
+
*/
|
|
377
|
+
bdPath?: string;
|
|
378
|
+
/**
|
|
379
|
+
* Working directory for execution
|
|
380
|
+
*/
|
|
381
|
+
cwd?: string;
|
|
382
|
+
/**
|
|
383
|
+
* Execution timeout in milliseconds
|
|
384
|
+
* Default: 60000 (60 seconds)
|
|
385
|
+
*/
|
|
386
|
+
timeout?: number;
|
|
387
|
+
/**
|
|
388
|
+
* Maximum buffer size for output
|
|
389
|
+
* Default: 50MB (beads can be large)
|
|
390
|
+
*/
|
|
391
|
+
maxBuffer?: number;
|
|
392
|
+
/**
|
|
393
|
+
* Environment variables
|
|
394
|
+
*/
|
|
395
|
+
env?: NodeJS.ProcessEnv;
|
|
396
|
+
/**
|
|
397
|
+
* Default storage path
|
|
398
|
+
*/
|
|
399
|
+
storagePath?: string;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Bead query parameters
|
|
403
|
+
*/
|
|
404
|
+
interface BeadQuery {
|
|
405
|
+
type?: BeadType | BeadType[];
|
|
406
|
+
threadId?: string;
|
|
407
|
+
agentId?: string;
|
|
408
|
+
tags?: string[];
|
|
409
|
+
after?: string;
|
|
410
|
+
before?: string;
|
|
411
|
+
limit?: number;
|
|
412
|
+
offset?: number;
|
|
413
|
+
sortBy?: 'timestamp' | 'id' | 'type';
|
|
414
|
+
sortOrder?: 'asc' | 'desc';
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Bead creation parameters
|
|
418
|
+
*/
|
|
419
|
+
interface CreateBeadParams {
|
|
420
|
+
type: BeadType;
|
|
421
|
+
content: string;
|
|
422
|
+
parentId?: string;
|
|
423
|
+
threadId?: string;
|
|
424
|
+
agentId?: string;
|
|
425
|
+
tags?: string[];
|
|
426
|
+
metadata?: Record<string, unknown>;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* BD execution result
|
|
430
|
+
*/
|
|
431
|
+
interface BdResult<T = unknown> {
|
|
432
|
+
success: boolean;
|
|
433
|
+
data?: T;
|
|
434
|
+
error?: string;
|
|
435
|
+
command: string;
|
|
436
|
+
args: string[];
|
|
437
|
+
durationMs: number;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Streaming execution result
|
|
441
|
+
*/
|
|
442
|
+
interface BdStreamResult {
|
|
443
|
+
process: ChildProcess;
|
|
444
|
+
stdout: NodeJS.ReadableStream | null;
|
|
445
|
+
stderr: NodeJS.ReadableStream | null;
|
|
446
|
+
promise: Promise<BdResult<string>>;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Logger interface
|
|
450
|
+
*/
|
|
451
|
+
interface BdLogger {
|
|
452
|
+
debug: (msg: string, meta?: Record<string, unknown>) => void;
|
|
453
|
+
info: (msg: string, meta?: Record<string, unknown>) => void;
|
|
454
|
+
warn: (msg: string, meta?: Record<string, unknown>) => void;
|
|
455
|
+
error: (msg: string, meta?: Record<string, unknown>) => void;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Beads bridge error codes
|
|
459
|
+
*/
|
|
460
|
+
type BdErrorCode = 'COMMAND_NOT_FOUND' | 'EXECUTION_FAILED' | 'TIMEOUT' | 'INVALID_ARGUMENT' | 'INVALID_OUTPUT' | 'PARSE_ERROR' | 'VALIDATION_ERROR' | 'BEAD_NOT_FOUND';
|
|
461
|
+
/**
|
|
462
|
+
* Beads bridge error
|
|
463
|
+
*/
|
|
464
|
+
declare class BdBridgeError extends Error {
|
|
465
|
+
readonly code: BdErrorCode;
|
|
466
|
+
readonly command?: string | undefined;
|
|
467
|
+
readonly args?: string[] | undefined;
|
|
468
|
+
readonly cause?: Error | undefined;
|
|
469
|
+
constructor(message: string, code: BdErrorCode, command?: string | undefined, args?: string[] | undefined, cause?: Error | undefined);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Beads CLI Bridge
|
|
473
|
+
*
|
|
474
|
+
* Secure wrapper around the `bd` CLI tool for bead management.
|
|
475
|
+
* Supports JSONL output parsing for streaming large datasets.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```typescript
|
|
479
|
+
* const bdBridge = new BdBridge({ bdPath: '/usr/local/bin/bd' });
|
|
480
|
+
* await bdBridge.initialize();
|
|
481
|
+
*
|
|
482
|
+
* const beads = await bdBridge.listBeads({ type: 'prompt', limit: 100 });
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
declare class BdBridge {
|
|
486
|
+
private config;
|
|
487
|
+
private logger;
|
|
488
|
+
private initialized;
|
|
489
|
+
/** Commands that can be cached (read-only, no side effects) */
|
|
490
|
+
private static readonly CACHEABLE_COMMANDS;
|
|
491
|
+
/** Commands that should use longer cache (static data) */
|
|
492
|
+
private static readonly STATIC_COMMANDS;
|
|
493
|
+
constructor(config?: BdBridgeConfig, logger?: BdLogger);
|
|
494
|
+
/**
|
|
495
|
+
* Initialize the bridge and verify bd is available
|
|
496
|
+
*/
|
|
497
|
+
initialize(): Promise<void>;
|
|
498
|
+
/**
|
|
499
|
+
* Execute a bd command with validated arguments
|
|
500
|
+
*
|
|
501
|
+
* @param args - Command arguments (validated and sanitized)
|
|
502
|
+
* @returns Command output
|
|
503
|
+
*/
|
|
504
|
+
execBd(args: string[], skipCache?: boolean): Promise<BdResult<string>>;
|
|
505
|
+
/**
|
|
506
|
+
* Execute bd command with streaming output
|
|
507
|
+
*/
|
|
508
|
+
execBdStreaming(args: string[]): BdStreamResult;
|
|
509
|
+
/**
|
|
510
|
+
* Parse JSONL output from bd command into Bead array
|
|
511
|
+
*
|
|
512
|
+
* @param output - JSONL formatted output
|
|
513
|
+
* @returns Array of parsed and validated beads
|
|
514
|
+
*/
|
|
515
|
+
parseBdOutput(output: string): Bead[];
|
|
516
|
+
/**
|
|
517
|
+
* Parse single bead from JSON output
|
|
518
|
+
*/
|
|
519
|
+
parseSingleBead(output: string): Bead;
|
|
520
|
+
/**
|
|
521
|
+
* List beads with optional query parameters
|
|
522
|
+
*/
|
|
523
|
+
listBeads(query?: BeadQuery): Promise<Bead[]>;
|
|
524
|
+
/**
|
|
525
|
+
* Get a single bead by ID
|
|
526
|
+
*/
|
|
527
|
+
getBead(beadId: string): Promise<Bead>;
|
|
528
|
+
/**
|
|
529
|
+
* Create a new bead
|
|
530
|
+
*/
|
|
531
|
+
createBead(params: CreateBeadParams): Promise<Bead>;
|
|
532
|
+
/**
|
|
533
|
+
* Search beads with semantic query
|
|
534
|
+
*/
|
|
535
|
+
searchBeads(query: string, options?: {
|
|
536
|
+
limit?: number;
|
|
537
|
+
threshold?: number;
|
|
538
|
+
type?: BeadType | BeadType[];
|
|
539
|
+
}): Promise<Bead[]>;
|
|
540
|
+
/**
|
|
541
|
+
* Export beads to JSONL format
|
|
542
|
+
*/
|
|
543
|
+
exportBeads(query?: BeadQuery): Promise<string>;
|
|
544
|
+
/**
|
|
545
|
+
* Get bead statistics
|
|
546
|
+
*/
|
|
547
|
+
getStats(): Promise<{
|
|
548
|
+
totalBeads: number;
|
|
549
|
+
beadsByType: Record<string, number>;
|
|
550
|
+
totalThreads: number;
|
|
551
|
+
oldestBead?: string;
|
|
552
|
+
newestBead?: string;
|
|
553
|
+
storageSize?: number;
|
|
554
|
+
}>;
|
|
555
|
+
/**
|
|
556
|
+
* Validate and sanitize command arguments
|
|
557
|
+
*/
|
|
558
|
+
private validateAndSanitizeArgs;
|
|
559
|
+
/**
|
|
560
|
+
* Ensure bridge is initialized
|
|
561
|
+
*/
|
|
562
|
+
private ensureInitialized;
|
|
563
|
+
/**
|
|
564
|
+
* Check if bridge is initialized
|
|
565
|
+
*/
|
|
566
|
+
isInitialized(): boolean;
|
|
567
|
+
/**
|
|
568
|
+
* Get current configuration
|
|
569
|
+
*/
|
|
570
|
+
getConfig(): Readonly<Required<BdBridgeConfig>>;
|
|
571
|
+
/**
|
|
572
|
+
* Get cache statistics for performance monitoring
|
|
573
|
+
*/
|
|
574
|
+
getCacheStats(): {
|
|
575
|
+
beadQueryCache: {
|
|
576
|
+
entries: number;
|
|
577
|
+
sizeBytes: number;
|
|
578
|
+
};
|
|
579
|
+
singleBeadCache: {
|
|
580
|
+
entries: number;
|
|
581
|
+
sizeBytes: number;
|
|
582
|
+
};
|
|
583
|
+
staticCache: {
|
|
584
|
+
entries: number;
|
|
585
|
+
sizeBytes: number;
|
|
586
|
+
};
|
|
587
|
+
parsedCache: {
|
|
588
|
+
entries: number;
|
|
589
|
+
sizeBytes: number;
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* Clear all caches (useful for testing or memory pressure)
|
|
594
|
+
*/
|
|
595
|
+
clearCaches(): void;
|
|
596
|
+
/**
|
|
597
|
+
* Invalidate cache for a specific bead (after create/update/delete)
|
|
598
|
+
*/
|
|
599
|
+
invalidateBeadCache(beadId: string): void;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Create a new Beads bridge instance
|
|
603
|
+
*/
|
|
604
|
+
declare function createBdBridge(config?: BdBridgeConfig, logger?: BdLogger): BdBridge;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Beads-AgentDB Sync Bridge
|
|
608
|
+
*
|
|
609
|
+
* Provides bidirectional synchronization between Beads (bd)
|
|
610
|
+
* and AgentDB. Implements conflict resolution strategies
|
|
611
|
+
* and maintains consistency between the two systems.
|
|
612
|
+
*
|
|
613
|
+
* Features:
|
|
614
|
+
* - Bidirectional sync (Beads <-> AgentDB)
|
|
615
|
+
* - Conflict resolution strategies
|
|
616
|
+
* - Incremental sync support
|
|
617
|
+
* - Transaction-safe operations
|
|
618
|
+
* - Embedding preservation
|
|
619
|
+
*
|
|
620
|
+
* @module v3/plugins/gastown-bridge/bridges/sync-bridge
|
|
621
|
+
*/
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Sync conflict resolution strategy
|
|
625
|
+
*/
|
|
626
|
+
declare const ConflictStrategySchema: z.ZodEnum<["beads-wins", "agentdb-wins", "newest-wins", "merge", "manual"]>;
|
|
627
|
+
/**
|
|
628
|
+
* Sync direction
|
|
629
|
+
*/
|
|
630
|
+
declare const SyncDirectionSchema: z.ZodEnum<["to-agentdb", "from-agentdb", "bidirectional"]>;
|
|
631
|
+
/**
|
|
632
|
+
* Sync status
|
|
633
|
+
*/
|
|
634
|
+
declare const SyncStatusSchema: z.ZodEnum<["pending", "in-progress", "completed", "failed", "conflict"]>;
|
|
635
|
+
/**
|
|
636
|
+
* AgentDB entry schema (compatible with claude-flow memory)
|
|
637
|
+
*/
|
|
638
|
+
declare const AgentDBEntrySchema: z.ZodObject<{
|
|
639
|
+
key: z.ZodString;
|
|
640
|
+
value: z.ZodUnknown;
|
|
641
|
+
namespace: z.ZodOptional<z.ZodString>;
|
|
642
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
643
|
+
embedding: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
644
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
645
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
646
|
+
version: z.ZodOptional<z.ZodNumber>;
|
|
647
|
+
}, "strip", z.ZodTypeAny, {
|
|
648
|
+
key: string;
|
|
649
|
+
namespace?: string | undefined;
|
|
650
|
+
version?: number | undefined;
|
|
651
|
+
metadata?: Record<string, unknown> | undefined;
|
|
652
|
+
value?: unknown;
|
|
653
|
+
embedding?: number[] | undefined;
|
|
654
|
+
createdAt?: string | undefined;
|
|
655
|
+
updatedAt?: string | undefined;
|
|
656
|
+
}, {
|
|
657
|
+
key: string;
|
|
658
|
+
namespace?: string | undefined;
|
|
659
|
+
version?: number | undefined;
|
|
660
|
+
metadata?: Record<string, unknown> | undefined;
|
|
661
|
+
value?: unknown;
|
|
662
|
+
embedding?: number[] | undefined;
|
|
663
|
+
createdAt?: string | undefined;
|
|
664
|
+
updatedAt?: string | undefined;
|
|
665
|
+
}>;
|
|
666
|
+
/**
|
|
667
|
+
* Conflict resolution strategy type
|
|
668
|
+
*/
|
|
669
|
+
type ConflictStrategy = z.infer<typeof ConflictStrategySchema>;
|
|
670
|
+
/**
|
|
671
|
+
* Sync direction type
|
|
672
|
+
*/
|
|
673
|
+
type SyncDirection = z.infer<typeof SyncDirectionSchema>;
|
|
674
|
+
/**
|
|
675
|
+
* Sync status type
|
|
676
|
+
*/
|
|
677
|
+
type SyncStatus = z.infer<typeof SyncStatusSchema>;
|
|
678
|
+
/**
|
|
679
|
+
* AgentDB entry type
|
|
680
|
+
*/
|
|
681
|
+
type AgentDBEntry = z.infer<typeof AgentDBEntrySchema>;
|
|
682
|
+
/**
|
|
683
|
+
* Sync bridge configuration
|
|
684
|
+
*/
|
|
685
|
+
interface SyncBridgeConfig {
|
|
686
|
+
/**
|
|
687
|
+
* Beads bridge configuration
|
|
688
|
+
*/
|
|
689
|
+
beadsBridge?: BdBridgeConfig;
|
|
690
|
+
/**
|
|
691
|
+
* AgentDB namespace for beads
|
|
692
|
+
* Default: 'beads'
|
|
693
|
+
*/
|
|
694
|
+
agentdbNamespace?: string;
|
|
695
|
+
/**
|
|
696
|
+
* Conflict resolution strategy
|
|
697
|
+
* Default: 'newest-wins'
|
|
698
|
+
*/
|
|
699
|
+
conflictStrategy?: ConflictStrategy;
|
|
700
|
+
/**
|
|
701
|
+
* Batch size for sync operations
|
|
702
|
+
* Default: 100
|
|
703
|
+
*/
|
|
704
|
+
batchSize?: number;
|
|
705
|
+
/**
|
|
706
|
+
* Whether to preserve embeddings during sync
|
|
707
|
+
* Default: true
|
|
708
|
+
*/
|
|
709
|
+
preserveEmbeddings?: boolean;
|
|
710
|
+
/**
|
|
711
|
+
* Whether to sync metadata
|
|
712
|
+
* Default: true
|
|
713
|
+
*/
|
|
714
|
+
syncMetadata?: boolean;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Sync operation result
|
|
718
|
+
*/
|
|
719
|
+
interface SyncResult {
|
|
720
|
+
success: boolean;
|
|
721
|
+
direction: SyncDirection;
|
|
722
|
+
synced: number;
|
|
723
|
+
created: number;
|
|
724
|
+
updated: number;
|
|
725
|
+
deleted: number;
|
|
726
|
+
conflicts: number;
|
|
727
|
+
errors: Array<{
|
|
728
|
+
id: string;
|
|
729
|
+
error: string;
|
|
730
|
+
}>;
|
|
731
|
+
durationMs: number;
|
|
732
|
+
timestamp: string;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Conflict record
|
|
736
|
+
*/
|
|
737
|
+
interface SyncConflict {
|
|
738
|
+
beadId: string;
|
|
739
|
+
beadData: Bead;
|
|
740
|
+
agentdbData: AgentDBEntry;
|
|
741
|
+
conflictType: 'update' | 'delete' | 'create';
|
|
742
|
+
resolution?: 'beads' | 'agentdb' | 'merged' | 'pending';
|
|
743
|
+
resolvedAt?: string;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Sync state for incremental sync
|
|
747
|
+
*/
|
|
748
|
+
interface SyncState {
|
|
749
|
+
lastSyncTime: string;
|
|
750
|
+
lastBeadId?: string;
|
|
751
|
+
lastAgentDBKey?: string;
|
|
752
|
+
pendingConflicts: string[];
|
|
753
|
+
version: number;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* AgentDB interface (to be provided by claude-flow)
|
|
757
|
+
*/
|
|
758
|
+
interface IAgentDBService {
|
|
759
|
+
store(key: string, value: unknown, namespace?: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
760
|
+
retrieve(key: string, namespace?: string): Promise<AgentDBEntry | null>;
|
|
761
|
+
search(query: string, namespace?: string, limit?: number): Promise<AgentDBEntry[]>;
|
|
762
|
+
list(namespace?: string, limit?: number, offset?: number): Promise<AgentDBEntry[]>;
|
|
763
|
+
delete(key: string, namespace?: string): Promise<void>;
|
|
764
|
+
getNamespaceStats(namespace: string): Promise<{
|
|
765
|
+
count: number;
|
|
766
|
+
lastUpdated?: string;
|
|
767
|
+
}>;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Logger interface
|
|
771
|
+
*/
|
|
772
|
+
interface SyncLogger {
|
|
773
|
+
debug: (msg: string, meta?: Record<string, unknown>) => void;
|
|
774
|
+
info: (msg: string, meta?: Record<string, unknown>) => void;
|
|
775
|
+
warn: (msg: string, meta?: Record<string, unknown>) => void;
|
|
776
|
+
error: (msg: string, meta?: Record<string, unknown>) => void;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Sync bridge error codes
|
|
780
|
+
*/
|
|
781
|
+
type SyncErrorCode = 'NOT_INITIALIZED' | 'SYNC_FAILED' | 'CONFLICT_UNRESOLVED' | 'AGENTDB_ERROR' | 'BEADS_ERROR' | 'VALIDATION_ERROR' | 'TRANSACTION_FAILED';
|
|
782
|
+
/**
|
|
783
|
+
* Sync bridge error
|
|
784
|
+
*/
|
|
785
|
+
declare class SyncBridgeError extends Error {
|
|
786
|
+
readonly code: SyncErrorCode;
|
|
787
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
788
|
+
readonly cause?: Error | undefined;
|
|
789
|
+
constructor(message: string, code: SyncErrorCode, details?: Record<string, unknown> | undefined, cause?: Error | undefined);
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Beads-AgentDB Sync Bridge
|
|
793
|
+
*
|
|
794
|
+
* Provides bidirectional synchronization between Beads and AgentDB
|
|
795
|
+
* with configurable conflict resolution.
|
|
796
|
+
*
|
|
797
|
+
* @example
|
|
798
|
+
* ```typescript
|
|
799
|
+
* const syncBridge = new SyncBridge(agentDB, {
|
|
800
|
+
* conflictStrategy: 'newest-wins',
|
|
801
|
+
* agentdbNamespace: 'conversation-beads',
|
|
802
|
+
* });
|
|
803
|
+
* await syncBridge.initialize();
|
|
804
|
+
*
|
|
805
|
+
* // Sync beads to AgentDB
|
|
806
|
+
* const result = await syncBridge.syncToAgentDB(beads);
|
|
807
|
+
*
|
|
808
|
+
* // Sync from AgentDB back to beads
|
|
809
|
+
* const beads = await syncBridge.syncFromAgentDB();
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
declare class SyncBridge {
|
|
813
|
+
private bdBridge;
|
|
814
|
+
private agentDB;
|
|
815
|
+
private config;
|
|
816
|
+
private logger;
|
|
817
|
+
private initialized;
|
|
818
|
+
private syncState;
|
|
819
|
+
private conflicts;
|
|
820
|
+
constructor(agentDB: IAgentDBService, config?: SyncBridgeConfig, logger?: SyncLogger);
|
|
821
|
+
/**
|
|
822
|
+
* Initialize the sync bridge
|
|
823
|
+
*/
|
|
824
|
+
initialize(): Promise<void>;
|
|
825
|
+
/**
|
|
826
|
+
* Sync beads to AgentDB
|
|
827
|
+
*/
|
|
828
|
+
syncToAgentDB(beads: Bead[]): Promise<SyncResult>;
|
|
829
|
+
/**
|
|
830
|
+
* Sync from AgentDB to Beads
|
|
831
|
+
*/
|
|
832
|
+
syncFromAgentDB(): Promise<Bead[]>;
|
|
833
|
+
/**
|
|
834
|
+
* Perform full bidirectional sync
|
|
835
|
+
*/
|
|
836
|
+
syncBidirectional(): Promise<{
|
|
837
|
+
toAgentDB: SyncResult;
|
|
838
|
+
fromAgentDB: Bead[];
|
|
839
|
+
}>;
|
|
840
|
+
/**
|
|
841
|
+
* Get pending conflicts
|
|
842
|
+
*/
|
|
843
|
+
getPendingConflicts(): SyncConflict[];
|
|
844
|
+
/**
|
|
845
|
+
* Resolve a specific conflict manually
|
|
846
|
+
*/
|
|
847
|
+
resolveConflictManually(beadId: string, resolution: 'beads' | 'agentdb' | 'merged', mergedData?: Partial<Bead>): Promise<void>;
|
|
848
|
+
/**
|
|
849
|
+
* Get sync state
|
|
850
|
+
*/
|
|
851
|
+
getSyncState(): Readonly<SyncState>;
|
|
852
|
+
/**
|
|
853
|
+
* Get sync statistics
|
|
854
|
+
*/
|
|
855
|
+
getSyncStats(): Promise<{
|
|
856
|
+
agentdbCount: number;
|
|
857
|
+
lastSyncTime: string;
|
|
858
|
+
pendingConflicts: number;
|
|
859
|
+
syncVersion: number;
|
|
860
|
+
}>;
|
|
861
|
+
/**
|
|
862
|
+
* Convert bead to AgentDB key
|
|
863
|
+
*/
|
|
864
|
+
private beadToKey;
|
|
865
|
+
/**
|
|
866
|
+
* Convert bead to AgentDB value
|
|
867
|
+
*/
|
|
868
|
+
private beadToAgentDBValue;
|
|
869
|
+
/**
|
|
870
|
+
* Build metadata for AgentDB entry
|
|
871
|
+
*/
|
|
872
|
+
private buildMetadata;
|
|
873
|
+
/**
|
|
874
|
+
* Convert AgentDB entry to Bead
|
|
875
|
+
*/
|
|
876
|
+
private agentDBToBead;
|
|
877
|
+
/**
|
|
878
|
+
* Detect if there's a conflict between bead and AgentDB entry
|
|
879
|
+
*/
|
|
880
|
+
private detectConflict;
|
|
881
|
+
/**
|
|
882
|
+
* Resolve conflict based on strategy
|
|
883
|
+
*/
|
|
884
|
+
private resolveConflict;
|
|
885
|
+
/**
|
|
886
|
+
* Save sync state to AgentDB
|
|
887
|
+
*/
|
|
888
|
+
private saveSyncState;
|
|
889
|
+
/**
|
|
890
|
+
* Ensure bridge is initialized
|
|
891
|
+
*/
|
|
892
|
+
private ensureInitialized;
|
|
893
|
+
/**
|
|
894
|
+
* Check if bridge is initialized
|
|
895
|
+
*/
|
|
896
|
+
isInitialized(): boolean;
|
|
897
|
+
/**
|
|
898
|
+
* Get beads bridge instance
|
|
899
|
+
*/
|
|
900
|
+
getBeadsBridge(): BdBridge;
|
|
901
|
+
/**
|
|
902
|
+
* Get cache statistics for performance monitoring
|
|
903
|
+
*/
|
|
904
|
+
getCacheStats(): {
|
|
905
|
+
agentDBLookupCache: {
|
|
906
|
+
entries: number;
|
|
907
|
+
sizeBytes: number;
|
|
908
|
+
};
|
|
909
|
+
conflictCache: {
|
|
910
|
+
entries: number;
|
|
911
|
+
sizeBytes: number;
|
|
912
|
+
};
|
|
913
|
+
};
|
|
914
|
+
/**
|
|
915
|
+
* Clear all sync caches
|
|
916
|
+
*/
|
|
917
|
+
clearCaches(): void;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Create a new sync bridge instance
|
|
921
|
+
*/
|
|
922
|
+
declare function createSyncBridge(agentDB: IAgentDBService, config?: SyncBridgeConfig, logger?: SyncLogger): SyncBridge;
|
|
923
|
+
|
|
924
|
+
export { AddressSchema, type AgentDBEntry, AgentDBEntrySchema, BdArgumentSchema, BdBridge, type BdBridgeConfig, BdBridgeError, type BdErrorCode, type BdLogger, type BdResult, type BdStreamResult, BeadIdSchema, type BeadQuery, type Bead as CliBead, BeadSchema as CliBeadSchema, type BeadType as CliBeadType, BeadTypeSchema as CliBeadTypeSchema, type SyncDirection as CliSyncDirection, SyncDirectionSchema as CliSyncDirectionSchema, type SyncResult as CliSyncResult, type ConflictStrategy, ConflictStrategySchema, type CreateBeadParams, type GasEstimate, GasLimitSchema, GasPriceSchema, GtArgumentSchema, GtBridge, type GtBridgeConfig, GtBridgeError, type GtErrorCode, IdentifierSchema as GtIdentifierSchema, type GtLogger, type GtResult, SafeStringSchema as GtSafeStringSchema, type IAgentDBService, NetworkSchema, type NetworkStatus, SyncBridge, type SyncBridgeConfig, SyncBridgeError, type SyncConflict, type SyncErrorCode, type SyncLogger, type SyncState, type SyncStatus, SyncStatusSchema, TxHashSchema, type TxStatus, createBdBridge, createGtBridge, createSyncBridge };
|