clawpowers 2.0.0 → 2.2.1
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/CHANGELOG.md +32 -0
- package/COMPATIBILITY.md +13 -0
- package/KNOWN_LIMITATIONS.md +19 -0
- package/LICENSING.md +10 -0
- package/README.md +201 -9
- package/SECURITY.md +33 -53
- package/dist/index.d.ts +638 -5
- package/dist/index.js +986 -58
- package/dist/index.js.map +1 -1
- package/native/Cargo.lock +4863 -0
- package/native/Cargo.toml +73 -0
- package/native/crates/canonical/Cargo.toml +24 -0
- package/native/crates/canonical/src/lib.rs +673 -0
- package/native/crates/compression/Cargo.toml +20 -0
- package/native/crates/compression/benches/compression_bench.rs +42 -0
- package/native/crates/compression/src/lib.rs +393 -0
- package/native/crates/evm-eth/Cargo.toml +13 -0
- package/native/crates/evm-eth/src/lib.rs +105 -0
- package/native/crates/fee/Cargo.toml +15 -0
- package/native/crates/fee/src/lib.rs +281 -0
- package/native/crates/index/Cargo.toml +16 -0
- package/native/crates/index/src/lib.rs +277 -0
- package/native/crates/policy/Cargo.toml +17 -0
- package/native/crates/policy/src/lib.rs +614 -0
- package/native/crates/security/Cargo.toml +22 -0
- package/native/crates/security/src/lib.rs +478 -0
- package/native/crates/tokens/Cargo.toml +13 -0
- package/native/crates/tokens/src/lib.rs +534 -0
- package/native/crates/verification/Cargo.toml +23 -0
- package/native/crates/verification/src/lib.rs +333 -0
- package/native/crates/wallet/Cargo.toml +20 -0
- package/native/crates/wallet/src/lib.rs +261 -0
- package/native/crates/x402/Cargo.toml +30 -0
- package/native/crates/x402/src/lib.rs +423 -0
- package/native/ffi/Cargo.toml +34 -0
- package/native/ffi/build.rs +4 -0
- package/native/ffi/index.node +0 -0
- package/native/ffi/src/lib.rs +352 -0
- package/native/ffi/tests/integration.rs +354 -0
- package/native/pyo3/Cargo.toml +26 -0
- package/native/pyo3/pyproject.toml +16 -0
- package/native/pyo3/src/lib.rs +407 -0
- package/native/pyo3/tests/test_smoke.py +180 -0
- package/native/wasm/Cargo.toml +44 -0
- package/native/wasm/pkg/.gitignore +6 -0
- package/native/wasm/pkg/clawpowers_wasm.d.ts +208 -0
- package/native/wasm/pkg/clawpowers_wasm.js +872 -0
- package/native/wasm/pkg/clawpowers_wasm_bg.wasm +0 -0
- package/native/wasm/pkg/clawpowers_wasm_bg.wasm.d.ts +40 -0
- package/native/wasm/pkg/package.json +17 -0
- package/native/wasm/pkg-node/.gitignore +6 -0
- package/native/wasm/pkg-node/clawpowers_wasm.d.ts +143 -0
- package/native/wasm/pkg-node/clawpowers_wasm.js +798 -0
- package/native/wasm/pkg-node/clawpowers_wasm_bg.wasm +0 -0
- package/native/wasm/pkg-node/clawpowers_wasm_bg.wasm.d.ts +40 -0
- package/native/wasm/pkg-node/package.json +13 -0
- package/native/wasm/src/lib.rs +433 -0
- package/package.json +24 -3
- package/src/skills/catalog.ts +435 -0
- package/src/skills/executor.ts +56 -0
- package/src/skills/index.ts +3 -0
- package/src/skills/itp/SKILL.md +112 -0
- package/src/skills/loader.ts +193 -0
package/dist/index.d.ts
CHANGED
|
@@ -347,11 +347,202 @@ declare function setConfigValue(config: ConfigFile, key: string, value: string):
|
|
|
347
347
|
* Default paths, version, config values, RSI tier boundaries.
|
|
348
348
|
*/
|
|
349
349
|
|
|
350
|
-
declare const VERSION = "2.
|
|
350
|
+
declare const VERSION = "2.2.0";
|
|
351
351
|
declare const PACKAGE_NAME = "clawpowers";
|
|
352
352
|
declare const CLAWPOWERS_HOME: string;
|
|
353
353
|
declare const DEFAULT_CONFIG: ConfigFile;
|
|
354
354
|
|
|
355
|
+
interface NativeWallet {
|
|
356
|
+
address(): string;
|
|
357
|
+
signMessage(msg: Buffer): string;
|
|
358
|
+
}
|
|
359
|
+
interface NativeWalletConstructor {
|
|
360
|
+
generate(): NativeWallet;
|
|
361
|
+
fromPrivateKey(hex: string): NativeWallet;
|
|
362
|
+
}
|
|
363
|
+
interface NativeFeeSchedule {
|
|
364
|
+
calculate(amount: number, decimals: number, feeType: string): string;
|
|
365
|
+
}
|
|
366
|
+
interface NativeFeeScheduleConstructor {
|
|
367
|
+
withDefaults(): NativeFeeSchedule;
|
|
368
|
+
new (txBps: number, swapBps: number, recipientHex: string): NativeFeeSchedule;
|
|
369
|
+
}
|
|
370
|
+
interface NativeX402Client {
|
|
371
|
+
createPaymentHeader(paymentJson: string, signature: string): string;
|
|
372
|
+
}
|
|
373
|
+
interface NativeX402ClientConstructor {
|
|
374
|
+
new (): NativeX402Client;
|
|
375
|
+
}
|
|
376
|
+
interface NativeCanonicalStore {
|
|
377
|
+
insert(recordJson: string): string;
|
|
378
|
+
get(id: string): string | null;
|
|
379
|
+
verifyIntegrity(id: string): boolean;
|
|
380
|
+
}
|
|
381
|
+
interface NativeCanonicalStoreConstructor {
|
|
382
|
+
open(path: string): NativeCanonicalStore;
|
|
383
|
+
inMemory(): NativeCanonicalStore;
|
|
384
|
+
}
|
|
385
|
+
interface NativeTurboCompressor {
|
|
386
|
+
compress(vector: Float32Array): string;
|
|
387
|
+
decompress(compressedJson: string): Float32Array;
|
|
388
|
+
}
|
|
389
|
+
interface NativeTurboCompressorConstructor {
|
|
390
|
+
new (dimensions: number, bits: number): NativeTurboCompressor;
|
|
391
|
+
}
|
|
392
|
+
interface NativeWriteFirewall {
|
|
393
|
+
evaluate(requestJson: string): string;
|
|
394
|
+
}
|
|
395
|
+
interface NativeWriteFirewallConstructor {
|
|
396
|
+
new (configJson: string): NativeWriteFirewall;
|
|
397
|
+
}
|
|
398
|
+
interface NativeModule {
|
|
399
|
+
JsAgentWallet: NativeWalletConstructor;
|
|
400
|
+
JsFeeSchedule: NativeFeeScheduleConstructor;
|
|
401
|
+
JsX402Client: NativeX402ClientConstructor;
|
|
402
|
+
JsCanonicalStore: NativeCanonicalStoreConstructor;
|
|
403
|
+
JsTurboCompressor: NativeTurboCompressorConstructor;
|
|
404
|
+
JsWriteFirewall: NativeWriteFirewallConstructor;
|
|
405
|
+
/** Present when `clawpowers-ffi` was built with keccak helper (ClawPowers-Skills ≥2.1.0). */
|
|
406
|
+
keccak256Bytes?: (data: Buffer) => string;
|
|
407
|
+
/** secp256k1 + Keccak address (ClawPowers-Skills ≥2.2.0). */
|
|
408
|
+
deriveEthereumAddress?: (privateKey: Buffer) => string;
|
|
409
|
+
derivePublicKey?: (privateKey: Buffer) => Buffer;
|
|
410
|
+
signEcdsa?: (privateKey: Buffer, messageHash: Buffer) => Buffer;
|
|
411
|
+
verifyEcdsa?: (publicKey: Buffer, messageHash: Buffer, signature: Buffer) => boolean;
|
|
412
|
+
}
|
|
413
|
+
interface WasmModule {
|
|
414
|
+
tokenAmountFromHuman(human: number, decimals: number): string;
|
|
415
|
+
tokenAmountToHuman(json: string): number;
|
|
416
|
+
tokenAmountAdd(aJson: string, bJson: string): string;
|
|
417
|
+
tokenAmountSub(aJson: string, bJson: string): string;
|
|
418
|
+
tokenAmountMulBps(json: string, bps: bigint): string;
|
|
419
|
+
getDefaultTokenRegistry(): string;
|
|
420
|
+
calculateFee(amountJson: string, feeType: string, txFeeBps?: bigint, swapFeeBps?: bigint): string;
|
|
421
|
+
compressVector(vectorJson: string, dimensions: number): string;
|
|
422
|
+
decompressVector(compressedJson: string, dimensions: number): string;
|
|
423
|
+
approximateDistance(aJson: string, bJson: string, dimensions: number): number;
|
|
424
|
+
WasmCanonicalStore: {
|
|
425
|
+
new (): WasmCanonicalStoreInstance;
|
|
426
|
+
};
|
|
427
|
+
evaluateWriteFirewall(json: string): string;
|
|
428
|
+
computeSha256(content: string): string;
|
|
429
|
+
/** Keccak-256 over raw bytes (`0x` + 64 hex). Present in wasm builds from ClawPowers-Skills ≥2.1.0. */
|
|
430
|
+
computeKeccak256?(bytes: Uint8Array): string;
|
|
431
|
+
/** secp256k1 Ethereum address (ClawPowers-Skills ≥2.2.0). */
|
|
432
|
+
deriveEthereumAddress?(privateKey: Uint8Array): string;
|
|
433
|
+
derivePublicKey?(privateKey: Uint8Array): Uint8Array;
|
|
434
|
+
signEcdsa?(privateKey: Uint8Array, messageHash: Uint8Array): Uint8Array;
|
|
435
|
+
verifyEcdsa?(publicKey: Uint8Array, messageHash: Uint8Array, signature: Uint8Array): boolean;
|
|
436
|
+
getVersion(): string;
|
|
437
|
+
getAvailableModules(): string;
|
|
438
|
+
}
|
|
439
|
+
interface WasmCanonicalStoreInstance {
|
|
440
|
+
insert(json: string): string;
|
|
441
|
+
get(id: string): string | null;
|
|
442
|
+
getByHash(hash: string): string | null;
|
|
443
|
+
queryNamespace(namespace: string, limit: number): string;
|
|
444
|
+
softDelete(id: string): boolean;
|
|
445
|
+
verifyIntegrity(id: string): boolean;
|
|
446
|
+
exportJson(): string;
|
|
447
|
+
importJson(json: string): number;
|
|
448
|
+
}
|
|
449
|
+
type LoadTier = 'native' | 'wasm' | 'typescript';
|
|
450
|
+
/**
|
|
451
|
+
* Get the native .node module, or null if unavailable.
|
|
452
|
+
*/
|
|
453
|
+
declare function getNative(): NativeModule | null;
|
|
454
|
+
/**
|
|
455
|
+
* Get the WASM module, or null if unavailable.
|
|
456
|
+
*/
|
|
457
|
+
declare function getWasm(): WasmModule | null;
|
|
458
|
+
/**
|
|
459
|
+
* Returns true if the native Rust addon was loaded successfully.
|
|
460
|
+
*/
|
|
461
|
+
declare function isNativeAvailable(): boolean;
|
|
462
|
+
/**
|
|
463
|
+
* Returns true if the WASM module was loaded successfully.
|
|
464
|
+
*/
|
|
465
|
+
declare function isWasmAvailable(): boolean;
|
|
466
|
+
/**
|
|
467
|
+
* Returns the active loading tier.
|
|
468
|
+
*/
|
|
469
|
+
declare function getActiveTier(): LoadTier;
|
|
470
|
+
/**
|
|
471
|
+
* Returns a summary of available modules per tier.
|
|
472
|
+
*/
|
|
473
|
+
declare function getCapabilitySummary(): {
|
|
474
|
+
tier: LoadTier;
|
|
475
|
+
nativeModules: string[];
|
|
476
|
+
wasmModules: string[];
|
|
477
|
+
typescriptFallback: string[];
|
|
478
|
+
};
|
|
479
|
+
/**
|
|
480
|
+
* Compute SHA-256 hash, using the fastest available backend.
|
|
481
|
+
*/
|
|
482
|
+
declare function computeSha256(content: string): string;
|
|
483
|
+
/**
|
|
484
|
+
* 32-byte digest as `0x` + 64 hex chars for wallet address derivation (last 20 bytes used as address).
|
|
485
|
+
*
|
|
486
|
+
* Tier 1: native `keccak256Bytes` when the `.node` addon includes it (custom `cargo build` of ffi).
|
|
487
|
+
* Tier 2: WASM `computeKeccak256` (pre-built `pkg-node` ships with the npm package).
|
|
488
|
+
* Tier 3: SHA-256 via Node.js `crypto` (legacy; use native/WASM for keccak256 parity).
|
|
489
|
+
*/
|
|
490
|
+
declare function digestForWalletAddress(keyMaterial: Buffer): string;
|
|
491
|
+
/**
|
|
492
|
+
* Keccak-256 digest of raw bytes as a 32-byte `Buffer`.
|
|
493
|
+
* Tier 1: native `keccak256Bytes`; Tier 2: WASM `computeKeccak256`; Tier 3: `null`.
|
|
494
|
+
*/
|
|
495
|
+
declare function keccak256Digest(data: Buffer): Buffer | null;
|
|
496
|
+
/**
|
|
497
|
+
* Ethereum address from 32-byte secp256k1 private key (EIP-55). Tier 1 → Tier 2 → `null`.
|
|
498
|
+
*/
|
|
499
|
+
declare function deriveEthereumAddress(privateKey: Buffer): string | null;
|
|
500
|
+
/**
|
|
501
|
+
* Uncompressed public key (64 bytes, no `0x04` prefix). Tier 1 → Tier 2 → `null`.
|
|
502
|
+
*/
|
|
503
|
+
declare function derivePublicKey(privateKey: Buffer): Buffer | null;
|
|
504
|
+
/**
|
|
505
|
+
* ECDSA sign a 32-byte message hash (65 bytes: r‖s‖recovery_id). Tier 1 → Tier 2 → `null`.
|
|
506
|
+
*/
|
|
507
|
+
declare function signEcdsa(privateKey: Buffer, messageHash: Buffer): Buffer | null;
|
|
508
|
+
/**
|
|
509
|
+
* Verify ECDSA over a 32-byte prehash. Tier 1 → Tier 2; otherwise `false`.
|
|
510
|
+
*/
|
|
511
|
+
declare function verifyEcdsa(publicKey: Buffer, messageHash: Buffer, signature: Buffer): boolean;
|
|
512
|
+
/**
|
|
513
|
+
* Create a token amount from a human-readable number.
|
|
514
|
+
* Routes to WASM if available, otherwise pure TypeScript.
|
|
515
|
+
*/
|
|
516
|
+
declare function tokenAmountFromHuman(human: number, decimals: number): {
|
|
517
|
+
raw: string;
|
|
518
|
+
decimals: number;
|
|
519
|
+
};
|
|
520
|
+
/**
|
|
521
|
+
* Calculate a fee, routing to the best available backend.
|
|
522
|
+
*/
|
|
523
|
+
declare function calculateFee(amountHuman: number, decimals: number, feeType: 'transaction' | 'swap' | string, txFeeBps?: number, swapFeeBps?: number): {
|
|
524
|
+
gross_amount: number;
|
|
525
|
+
fee_amount: number;
|
|
526
|
+
net_amount: number;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Evaluate a write request against the security firewall.
|
|
530
|
+
* Routes to WASM if available, otherwise TypeScript.
|
|
531
|
+
*/
|
|
532
|
+
declare function evaluateWriteFirewall(request: {
|
|
533
|
+
namespace: string;
|
|
534
|
+
content: string;
|
|
535
|
+
trust_level: string;
|
|
536
|
+
source: string;
|
|
537
|
+
allowed_namespaces?: string[];
|
|
538
|
+
blocked_patterns?: string[];
|
|
539
|
+
max_content_length?: number;
|
|
540
|
+
}): {
|
|
541
|
+
decision: 'allow' | 'deny' | 'sanitize';
|
|
542
|
+
reason?: string;
|
|
543
|
+
sanitized?: string;
|
|
544
|
+
};
|
|
545
|
+
|
|
355
546
|
/**
|
|
356
547
|
* ClawPowers Agent — Payment Discovery
|
|
357
548
|
* Detects HTTP 402 Payment Required responses and parses x402 headers.
|
|
@@ -462,6 +653,37 @@ declare class PaymentExecutor {
|
|
|
462
653
|
private logAudit;
|
|
463
654
|
}
|
|
464
655
|
|
|
656
|
+
interface FeeCalculation {
|
|
657
|
+
gross: number;
|
|
658
|
+
fee: number;
|
|
659
|
+
net: number;
|
|
660
|
+
feeRecipient: string;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Calculate transaction fee using the best available backend.
|
|
664
|
+
*
|
|
665
|
+
* Tier 1: Native Rust fee crate (JsFeeSchedule.withDefaults, 77 bps)
|
|
666
|
+
* Tier 2: WASM fee crate (calculateFee via index.ts helper)
|
|
667
|
+
* Tier 3: Pure TypeScript 77 bps calculation
|
|
668
|
+
*/
|
|
669
|
+
declare function calculateTransactionFee(amount: number, decimals?: number): FeeCalculation;
|
|
670
|
+
/**
|
|
671
|
+
* Build an X-Payment header.
|
|
672
|
+
*
|
|
673
|
+
* Tier 1: Native Rust x402 crate (JsX402Client)
|
|
674
|
+
* Tier 2: Not available in WASM (wallet/x402 excluded from wasm crate)
|
|
675
|
+
* Tier 3: Base64-encoded JSON representation
|
|
676
|
+
*/
|
|
677
|
+
declare function createPaymentHeader(paymentJson: string, signature: string): string;
|
|
678
|
+
/**
|
|
679
|
+
* Generate a new EVM agent wallet address.
|
|
680
|
+
*
|
|
681
|
+
* Tier 1: Native Rust wallet crate (JsAgentWallet.generate)
|
|
682
|
+
* Tier 2: WASM secp256k1 + Keccak derivation via the shared loader
|
|
683
|
+
* Tier 3: throws, because returning a fake zero address would be misleading
|
|
684
|
+
*/
|
|
685
|
+
declare function generateWalletAddress(): string;
|
|
686
|
+
|
|
465
687
|
/**
|
|
466
688
|
* ClawPowers Agent — Working Memory Manager
|
|
467
689
|
* In-process working memory with token budget enforcement.
|
|
@@ -553,6 +775,77 @@ declare class ContextInjector {
|
|
|
553
775
|
inject(goal: Goal, maxTokens?: number): Promise<string[]>;
|
|
554
776
|
}
|
|
555
777
|
|
|
778
|
+
/**
|
|
779
|
+
* Native acceleration bridge for memory storage.
|
|
780
|
+
*
|
|
781
|
+
* Tier 1: Native Rust .node addon (canonical store, TurboQuant compressor, write firewall)
|
|
782
|
+
* Tier 2: WASM module (WasmCanonicalStore, compressVector, evaluateWriteFirewall)
|
|
783
|
+
* Tier 3: Pure TypeScript fallback (null returns / fail-open defaults)
|
|
784
|
+
*
|
|
785
|
+
* Note: Wallet and x402 are excluded from the WASM build; memory functions
|
|
786
|
+
* (canonical store, compression, security, verification) are all available in WASM.
|
|
787
|
+
*/
|
|
788
|
+
|
|
789
|
+
/** Get a native persistent canonical store, or null if unavailable. */
|
|
790
|
+
declare function getNativeCanonicalStore(dbPath: string): NativeCanonicalStore | null;
|
|
791
|
+
/** Get an in-memory native canonical store for testing, or null if unavailable. */
|
|
792
|
+
declare function getNativeCanonicalStoreInMemory(): NativeCanonicalStore | null;
|
|
793
|
+
/**
|
|
794
|
+
* Get an in-memory WASM canonical store, or null if WASM is unavailable.
|
|
795
|
+
* This is the Tier 2 alternative to getNativeCanonicalStoreInMemory().
|
|
796
|
+
*/
|
|
797
|
+
declare function getWasmCanonicalStore(): WasmCanonicalStoreInstance | null;
|
|
798
|
+
/**
|
|
799
|
+
* Get the best available in-memory canonical store.
|
|
800
|
+
* Returns a unified interface regardless of which tier is active.
|
|
801
|
+
*
|
|
802
|
+
* Tier 1: Native canonical store (SQLite-backed in-memory)
|
|
803
|
+
* Tier 2: WASM canonical store (in-memory HashMap)
|
|
804
|
+
* Tier 3: null (caller must handle)
|
|
805
|
+
*/
|
|
806
|
+
declare function getBestCanonicalStore(): NativeCanonicalStore | WasmCanonicalStoreInstance | null;
|
|
807
|
+
interface CompressionResult {
|
|
808
|
+
compressed: string;
|
|
809
|
+
originalSize: number;
|
|
810
|
+
compressedSize: number;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Compress a float32 vector using the best available backend.
|
|
814
|
+
*
|
|
815
|
+
* Tier 1: Native TurboQuant compressor (JsTurboCompressor)
|
|
816
|
+
* Tier 2: WASM vector compression (compressVector)
|
|
817
|
+
* Tier 3: null (no compression available)
|
|
818
|
+
*/
|
|
819
|
+
declare function compressVector(vector: Float32Array, bits?: number): CompressionResult | null;
|
|
820
|
+
/**
|
|
821
|
+
* Decompress a previously compressed vector using the best available backend.
|
|
822
|
+
*
|
|
823
|
+
* Tier 1: Native TurboQuant decompressor
|
|
824
|
+
* Tier 2: WASM vector decompressor
|
|
825
|
+
* Tier 3: null (no decompression available)
|
|
826
|
+
*/
|
|
827
|
+
declare function decompressVector(compressedJson: string, dimensions: number, bits?: number): Float32Array | null;
|
|
828
|
+
/**
|
|
829
|
+
* Compute approximate distance between two compressed vectors.
|
|
830
|
+
*
|
|
831
|
+
* Tier 1: Not exposed on native JsTurboCompressor directly
|
|
832
|
+
* Tier 2: WASM approximateDistance
|
|
833
|
+
* Tier 3: null
|
|
834
|
+
*/
|
|
835
|
+
declare function approximateDistance(aJson: string, bJson: string, dimensions: number): number | null;
|
|
836
|
+
/**
|
|
837
|
+
* Evaluate a write request through the security firewall.
|
|
838
|
+
* Fail-open: returns allowed:true if no backend is available.
|
|
839
|
+
*
|
|
840
|
+
* Tier 1: Native JsWriteFirewall
|
|
841
|
+
* Tier 2: WASM evaluateWriteFirewall (via index.ts unified helper)
|
|
842
|
+
* Tier 3: Basic TypeScript checks (via index.ts unified helper)
|
|
843
|
+
*/
|
|
844
|
+
declare function evaluateWriteSecurity(namespace: string, content: string, allowedNamespaces: string[], source?: string, trustLevel?: string): {
|
|
845
|
+
allowed: boolean;
|
|
846
|
+
reason?: string;
|
|
847
|
+
};
|
|
848
|
+
|
|
556
849
|
/**
|
|
557
850
|
* ClawPowers Agent — RSI Metrics Collector
|
|
558
851
|
* Per-task and per-skill metric collection in JSONL format.
|
|
@@ -823,8 +1116,9 @@ declare class WalletManager {
|
|
|
823
1116
|
|
|
824
1117
|
/**
|
|
825
1118
|
* ClawPowers Skills — Wallet Crypto
|
|
826
|
-
* Ethereum-
|
|
827
|
-
*
|
|
1119
|
+
* Ethereum-oriented wallet generation, import, and signing.
|
|
1120
|
+
* Address derivation: secp256k1 public key → Keccak-256 → last 20 bytes (MetaMask-compatible)
|
|
1121
|
+
* when Tier 1 (native) or Tier 2 (WASM) is available; legacy hash-of-key digest only on Tier 3.
|
|
828
1122
|
*/
|
|
829
1123
|
|
|
830
1124
|
/**
|
|
@@ -837,8 +1131,347 @@ declare function generateWallet(config: WalletConfig): Promise<WalletInfo>;
|
|
|
837
1131
|
*/
|
|
838
1132
|
declare function importWallet(privateKeyHex: string, config: WalletConfig): Promise<WalletInfo>;
|
|
839
1133
|
/**
|
|
840
|
-
* Sign a message using an encrypted key file and passphrase.
|
|
1134
|
+
* Sign a message using an encrypted key file and passphrase (returns structured result).
|
|
1135
|
+
* Uses secp256k1 ECDSA over Keccak-256(UTF-8 message) when native/WASM tiers provide it;
|
|
1136
|
+
* otherwise falls back to HMAC-SHA256 for backward compatibility.
|
|
841
1137
|
*/
|
|
842
1138
|
declare function signMessage(message: string, keyFile: string, passphrase: string): Promise<SignedMessage>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Sign a message with a raw hex private key. Returns 65-byte ECDSA signature (r‖s‖v) as hex.
|
|
1141
|
+
* Requires Tier 1 or Tier 2 (Keccak + secp256k1).
|
|
1142
|
+
*/
|
|
1143
|
+
declare function signMessage(privateKeyHex: string, message: string): Promise<string>;
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* ITP TypeScript Client — Identical Twins Protocol
|
|
1147
|
+
*
|
|
1148
|
+
* Wraps the Python ITP server HTTP API (http://localhost:8100).
|
|
1149
|
+
* Provides encode(), decode(), healthCheck() utilities.
|
|
1150
|
+
* Falls back gracefully if server not running (returns original message).
|
|
1151
|
+
*/
|
|
1152
|
+
interface EncodeResult {
|
|
1153
|
+
encoded: string;
|
|
1154
|
+
wasCompressed: boolean;
|
|
1155
|
+
savingsPct: number;
|
|
1156
|
+
}
|
|
1157
|
+
interface DecodeResult {
|
|
1158
|
+
decoded: string;
|
|
1159
|
+
wasItp: boolean;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Encode a natural language message using the ITP codebook.
|
|
1163
|
+
* If the server is unreachable, returns the original message unchanged.
|
|
1164
|
+
*/
|
|
1165
|
+
declare function encode(message: string, sourceAgent?: string): Promise<EncodeResult>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Decode an ITP-encoded message back to natural language.
|
|
1168
|
+
* If the server is unreachable, returns the original message unchanged.
|
|
1169
|
+
*/
|
|
1170
|
+
declare function decode(message: string): Promise<DecodeResult>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Check if the ITP server is running and healthy.
|
|
1173
|
+
*/
|
|
1174
|
+
declare function healthCheck(): Promise<boolean>;
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Parallel Swarm Types
|
|
1178
|
+
*
|
|
1179
|
+
* Type definitions for the parallel swarm execution module.
|
|
1180
|
+
* Mirrors the Python a0-parallel-swarm-plugin API surface.
|
|
1181
|
+
*/
|
|
1182
|
+
type ModelComplexity = 'simple' | 'moderate' | 'complex';
|
|
1183
|
+
type TaskStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
1184
|
+
interface SwarmTask {
|
|
1185
|
+
/** Unique task identifier. Auto-generated if omitted. */
|
|
1186
|
+
id: string;
|
|
1187
|
+
/** Human-readable description of the task. */
|
|
1188
|
+
description: string;
|
|
1189
|
+
/** The message/prompt to send to the agent. */
|
|
1190
|
+
message: string;
|
|
1191
|
+
/** Task complexity for model routing. Defaults to 'moderate'. */
|
|
1192
|
+
complexity?: ModelComplexity;
|
|
1193
|
+
/** Optional profile/persona for the agent. */
|
|
1194
|
+
profile?: string;
|
|
1195
|
+
/** Priority within an execution level (lower = higher priority). */
|
|
1196
|
+
priority?: number;
|
|
1197
|
+
/** Task IDs this task depends on. Forms a DAG. */
|
|
1198
|
+
depends_on?: string[];
|
|
1199
|
+
/** Token budget override for this specific task. */
|
|
1200
|
+
token_budget?: number;
|
|
1201
|
+
/** Arbitrary metadata attached to the task. */
|
|
1202
|
+
metadata?: Record<string, unknown>;
|
|
1203
|
+
}
|
|
1204
|
+
interface SwarmResult {
|
|
1205
|
+
/** The task ID this result belongs to. */
|
|
1206
|
+
task_id: string;
|
|
1207
|
+
/** Task description (copied from input). */
|
|
1208
|
+
description: string;
|
|
1209
|
+
/** Final status. */
|
|
1210
|
+
status: TaskStatus;
|
|
1211
|
+
/** The result string on success. */
|
|
1212
|
+
result: string | null;
|
|
1213
|
+
/** Error message on failure. */
|
|
1214
|
+
error: string | null;
|
|
1215
|
+
/** Resolved complexity used for model routing. */
|
|
1216
|
+
complexity: ModelComplexity;
|
|
1217
|
+
/** Tokens consumed by this task. */
|
|
1218
|
+
tokens_used: number;
|
|
1219
|
+
/** Token budget allocated to this task. */
|
|
1220
|
+
token_budget: number;
|
|
1221
|
+
/** ISO timestamp when the task started. */
|
|
1222
|
+
started_at: string | null;
|
|
1223
|
+
/** ISO timestamp when the task completed. */
|
|
1224
|
+
completed_at: string | null;
|
|
1225
|
+
/** Duration in milliseconds. */
|
|
1226
|
+
duration_ms: number;
|
|
1227
|
+
}
|
|
1228
|
+
interface SwarmConfig {
|
|
1229
|
+
/** Maximum parallel tasks. 1–20, default 5. */
|
|
1230
|
+
max_concurrency?: number;
|
|
1231
|
+
/** Total token budget across all tasks. Default 100_000. */
|
|
1232
|
+
token_budget?: number;
|
|
1233
|
+
/** Per-task token budget default. Default 20_000. */
|
|
1234
|
+
per_task_budget?: number;
|
|
1235
|
+
/** Whether to auto-classify task complexity. Default true. */
|
|
1236
|
+
auto_classify?: boolean;
|
|
1237
|
+
/** Model overrides by complexity tier. */
|
|
1238
|
+
models?: {
|
|
1239
|
+
simple?: string;
|
|
1240
|
+
moderate?: string;
|
|
1241
|
+
complex?: string;
|
|
1242
|
+
};
|
|
1243
|
+
/** Backpressure threshold (0–1). Default 0.8. */
|
|
1244
|
+
backpressure_threshold?: number;
|
|
1245
|
+
}
|
|
1246
|
+
interface SwarmMemoryEntry {
|
|
1247
|
+
/** ID of the agent that shared this finding. */
|
|
1248
|
+
agent_id: string;
|
|
1249
|
+
/** Unique key for the finding. */
|
|
1250
|
+
key: string;
|
|
1251
|
+
/** The finding value. */
|
|
1252
|
+
value: string;
|
|
1253
|
+
/** Tags for querying. */
|
|
1254
|
+
tags: string[];
|
|
1255
|
+
/** ISO timestamp when stored. */
|
|
1256
|
+
timestamp: string;
|
|
1257
|
+
}
|
|
1258
|
+
/** Subset of SwarmMemory exposed to task executors. */
|
|
1259
|
+
interface SwarmMemoryHandle {
|
|
1260
|
+
share(agentId: string, key: string, value: string, tags?: string[]): void;
|
|
1261
|
+
get(key: string): SwarmMemoryEntry | undefined;
|
|
1262
|
+
query(options?: {
|
|
1263
|
+
tags?: string[];
|
|
1264
|
+
keyword?: string;
|
|
1265
|
+
}): SwarmMemoryEntry[];
|
|
1266
|
+
getAll(): SwarmMemoryEntry[];
|
|
1267
|
+
}
|
|
1268
|
+
interface TokenAllocation {
|
|
1269
|
+
task_id: string;
|
|
1270
|
+
budget: number;
|
|
1271
|
+
consumed: number;
|
|
1272
|
+
allocated_at: number;
|
|
1273
|
+
}
|
|
1274
|
+
interface TokenUsageReport {
|
|
1275
|
+
total_budget: number;
|
|
1276
|
+
total_allocated: number;
|
|
1277
|
+
total_consumed: number;
|
|
1278
|
+
total_remaining: number;
|
|
1279
|
+
tasks: Record<string, {
|
|
1280
|
+
budget: number;
|
|
1281
|
+
consumed: number;
|
|
1282
|
+
remaining: number;
|
|
1283
|
+
over_budget: boolean;
|
|
1284
|
+
}>;
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Represents a complete swarm execution run — the top-level result
|
|
1288
|
+
* returned after all tasks in a swarm have completed or failed.
|
|
1289
|
+
*/
|
|
1290
|
+
interface SwarmRun {
|
|
1291
|
+
/** ISO timestamp when the run started. */
|
|
1292
|
+
started_at: string;
|
|
1293
|
+
/** ISO timestamp when the run completed. */
|
|
1294
|
+
completed_at: string;
|
|
1295
|
+
/** Total duration in milliseconds. */
|
|
1296
|
+
duration_ms: number;
|
|
1297
|
+
/** Results keyed by task ID. */
|
|
1298
|
+
results: Record<string, SwarmResult>;
|
|
1299
|
+
/** Token usage summary for the entire run. */
|
|
1300
|
+
token_usage: TokenUsageReport;
|
|
1301
|
+
/** Whether the run was cancelled. */
|
|
1302
|
+
cancelled: boolean;
|
|
1303
|
+
/** Count of successful tasks. */
|
|
1304
|
+
success_count: number;
|
|
1305
|
+
/** Count of failed tasks. */
|
|
1306
|
+
failure_count: number;
|
|
1307
|
+
/** Total tasks submitted. */
|
|
1308
|
+
total_count: number;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* ITP ↔ Swarm Integration Bridge
|
|
1313
|
+
*
|
|
1314
|
+
* Compresses SwarmTask descriptions before fan-out and
|
|
1315
|
+
* decodes SwarmResult content after collection.
|
|
1316
|
+
* Graceful fallback — if ITP is unavailable, tasks/results pass through unchanged.
|
|
1317
|
+
*/
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* Encode the task description and message before fan-out to sub-agents.
|
|
1321
|
+
* Returns a new SwarmTask with compressed fields (original task is not mutated).
|
|
1322
|
+
*/
|
|
1323
|
+
declare function encodeTaskDescription(task: SwarmTask): Promise<SwarmTask>;
|
|
1324
|
+
/**
|
|
1325
|
+
* Decode the result content returned from a sub-agent.
|
|
1326
|
+
* Returns a new SwarmResult with decoded fields (original result is not mutated).
|
|
1327
|
+
*/
|
|
1328
|
+
declare function decodeSwarmResult(result: SwarmResult): Promise<SwarmResult>;
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* ConcurrencyManager — Bounded parallelism with adaptive throttling.
|
|
1332
|
+
*
|
|
1333
|
+
* Promise-based semaphore that limits concurrent swarm task execution.
|
|
1334
|
+
* Mirrors the Python a0-parallel-swarm-plugin ConcurrencyManager.
|
|
1335
|
+
*/
|
|
1336
|
+
declare class ConcurrencyManager {
|
|
1337
|
+
private readonly maxConcurrency;
|
|
1338
|
+
private readonly backpressureThreshold;
|
|
1339
|
+
private activeCount;
|
|
1340
|
+
private throttleDelayMs;
|
|
1341
|
+
private lastErrorTime;
|
|
1342
|
+
private readonly queue;
|
|
1343
|
+
constructor(maxConcurrency?: number, backpressureThreshold?: number);
|
|
1344
|
+
/**
|
|
1345
|
+
* Acquire a concurrency slot. Resolves when a slot is available.
|
|
1346
|
+
* Applies throttle delay if rate limits have been hit recently.
|
|
1347
|
+
*/
|
|
1348
|
+
acquire(): Promise<void>;
|
|
1349
|
+
/**
|
|
1350
|
+
* Release a concurrency slot. Unblocks next queued waiter if any.
|
|
1351
|
+
*/
|
|
1352
|
+
release(): void;
|
|
1353
|
+
/**
|
|
1354
|
+
* Number of currently active tasks.
|
|
1355
|
+
*/
|
|
1356
|
+
get active(): number;
|
|
1357
|
+
/**
|
|
1358
|
+
* Number of tasks waiting for a slot.
|
|
1359
|
+
*/
|
|
1360
|
+
get pending(): number;
|
|
1361
|
+
/**
|
|
1362
|
+
* Whether system has capacity for another task.
|
|
1363
|
+
*/
|
|
1364
|
+
hasCapacity(): boolean;
|
|
1365
|
+
/**
|
|
1366
|
+
* Increase throttle delay on rate-limit / transient errors.
|
|
1367
|
+
* Multiple errors in quick succession cause exponential backoff.
|
|
1368
|
+
*/
|
|
1369
|
+
adaptiveThrottle(_errorType?: string): void;
|
|
1370
|
+
/**
|
|
1371
|
+
* Gradually reduce throttle delay after a successful operation.
|
|
1372
|
+
*/
|
|
1373
|
+
resetThrottle(): void;
|
|
1374
|
+
/**
|
|
1375
|
+
* Check if system is above backpressure threshold.
|
|
1376
|
+
*/
|
|
1377
|
+
isUnderPressure(): boolean;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* TokenPool — Centralized token budget manager for swarm parallel execution.
|
|
1382
|
+
*
|
|
1383
|
+
* Enforces a total token budget across all parallel agents via pre-allocation.
|
|
1384
|
+
* Single-threaded JS means no locking needed — operations are synchronous.
|
|
1385
|
+
*
|
|
1386
|
+
* Mirrors the Python a0-parallel-swarm-plugin TokenPool.
|
|
1387
|
+
*/
|
|
1388
|
+
|
|
1389
|
+
declare class TokenPool {
|
|
1390
|
+
readonly totalBudget: number;
|
|
1391
|
+
readonly perTaskDefault: number;
|
|
1392
|
+
private readonly allocations;
|
|
1393
|
+
constructor(totalBudget?: number, perTaskDefault?: number);
|
|
1394
|
+
/**
|
|
1395
|
+
* Reserve tokens for a task.
|
|
1396
|
+
* Returns false if the pool doesn't have enough remaining budget.
|
|
1397
|
+
*/
|
|
1398
|
+
allocate(taskId: string, budget?: number): boolean;
|
|
1399
|
+
/**
|
|
1400
|
+
* Record actual token usage for a task (cumulative).
|
|
1401
|
+
*/
|
|
1402
|
+
consume(taskId: string, tokens: number): void;
|
|
1403
|
+
/**
|
|
1404
|
+
* Free the allocation when a task completes.
|
|
1405
|
+
* Returns tokens consumed by that task.
|
|
1406
|
+
*/
|
|
1407
|
+
release(taskId: string): number;
|
|
1408
|
+
/**
|
|
1409
|
+
* Total remaining budget (total - allocated).
|
|
1410
|
+
*/
|
|
1411
|
+
remaining(): number;
|
|
1412
|
+
/**
|
|
1413
|
+
* Total tokens consumed across all active tasks.
|
|
1414
|
+
*/
|
|
1415
|
+
consumed(): number;
|
|
1416
|
+
/**
|
|
1417
|
+
* Total tokens currently allocated (reserved but not necessarily consumed).
|
|
1418
|
+
*/
|
|
1419
|
+
totalAllocated(): number;
|
|
1420
|
+
/**
|
|
1421
|
+
* Check if a specific task has exceeded its allocation.
|
|
1422
|
+
*/
|
|
1423
|
+
isTaskOverBudget(taskId: string): boolean;
|
|
1424
|
+
/**
|
|
1425
|
+
* Remaining budget for a specific task.
|
|
1426
|
+
*/
|
|
1427
|
+
taskBudgetRemaining(taskId: string): number;
|
|
1428
|
+
/**
|
|
1429
|
+
* Per-task token consumption summary for observability.
|
|
1430
|
+
*/
|
|
1431
|
+
usageReport(): TokenUsageReport;
|
|
1432
|
+
/**
|
|
1433
|
+
* Clear all allocations (reset between runs).
|
|
1434
|
+
*/
|
|
1435
|
+
reset(): void;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* ModelRouter — Complexity classification and model routing for swarm tasks.
|
|
1440
|
+
*
|
|
1441
|
+
* Provides heuristic-based task complexity classification (no LLM required)
|
|
1442
|
+
* and maps complexity tiers to model IDs.
|
|
1443
|
+
*
|
|
1444
|
+
* Mirrors the Python a0-parallel-swarm-plugin model_router helpers.
|
|
1445
|
+
*/
|
|
1446
|
+
|
|
1447
|
+
/**
|
|
1448
|
+
* Classify task complexity using keyword heuristics and description length.
|
|
1449
|
+
* Fast — no LLM call required.
|
|
1450
|
+
*
|
|
1451
|
+
* @param description - Task description to classify
|
|
1452
|
+
* @returns ModelComplexity: 'simple' | 'moderate' | 'complex'
|
|
1453
|
+
*/
|
|
1454
|
+
declare function classifyHeuristic(description: string): ModelComplexity;
|
|
1455
|
+
/**
|
|
1456
|
+
* Select the model ID for a given complexity tier.
|
|
1457
|
+
* Falls back to default model map if no override is configured.
|
|
1458
|
+
*
|
|
1459
|
+
* @param complexity - Task complexity tier
|
|
1460
|
+
* @param config - Optional SwarmConfig with model overrides
|
|
1461
|
+
* @returns Model ID string
|
|
1462
|
+
*/
|
|
1463
|
+
declare function selectModel(complexity: ModelComplexity, config?: SwarmConfig): string;
|
|
1464
|
+
/**
|
|
1465
|
+
* Auto-classify a list of tasks, assigning complexity if not explicitly set.
|
|
1466
|
+
* Tasks with an existing complexity value are left unchanged.
|
|
1467
|
+
*
|
|
1468
|
+
* @param tasks - Array of tasks with optional complexity fields
|
|
1469
|
+
* @returns Map from task ID to resolved complexity
|
|
1470
|
+
*/
|
|
1471
|
+
declare function classifyTasks(tasks: Array<{
|
|
1472
|
+
id: string;
|
|
1473
|
+
description: string;
|
|
1474
|
+
complexity?: ModelComplexity;
|
|
1475
|
+
}>): Map<string, ModelComplexity>;
|
|
843
1476
|
|
|
844
|
-
export { type ABTest, type ABTestDecision, ABTestManager, type ABTestResult, type ABTestStatus, type AgentStatus, AutoResearcher, CLAWPOWERS_HOME, type CheckpointInfo, CheckpointManager, type CheckpointState, type ConfigFile, ContextInjector, type CriterionResult, DEFAULT_CONFIG, type EpisodicEntry, EpisodicMemory, type Goal, type GoalSource, HypothesisEngine, type LoggingConfig, type MCPPaymentClient, type MemoryEntry, type MemoryOutcome, type MemoryStats, MetricsCollector, MutationEngine, type MutationRecord, PACKAGE_NAME, type PaymentAuditEntry, type PaymentConfig, PaymentExecutor, type PaymentMode, type PaymentRequest, type PaymentRequired, type PaymentResult, type Plan, type PlanResult, type PlanStatus, type ProceduralEntry, ProceduralMemory, type Profile, type ProfileName, type RSIAuditEntry, RSIAuditLog, type RSIAuditMetrics, type RSIConfig, type RSIHypothesis, type RSIMutation, type RSIMutationExtended, type RSIMutationExtendedStatus, type RSIMutationStatus, type RSITier, type RSITierLabel, type RSITierMode, type RSITierT4Mode, type ReviewResult, type SignedMessage, type SkillAggregateStats, type SkillExecutionContext, type SkillExecutionResult, SkillExecutor, type SkillManifest, type SkillMetrics, type SkillRequirements, type SpendingDecision, SpendingPolicy, type Step, type StepResult, type StepStatus, type TaskCompletion, type TaskMetrics, type TaskOutcome, type TrendDirection, VERSION, type WalletConfig, type WalletInfo, WalletManager, type WorkingMemory, WorkingMemoryManager, detect402, discoverSkills, generateWallet, getActiveSkills, getConfigValue, importWallet, initConfig, isPaymentRequired, listSkillsWithStatus, loadConfig, loadConfigSafe, loadSkillManifest, parseFrontmatter, runAutoResearch, saveConfig, setConfigValue, signMessage };
|
|
1477
|
+
export { type ABTest, type ABTestDecision, ABTestManager, type ABTestResult, type ABTestStatus, type AgentStatus, AutoResearcher, CLAWPOWERS_HOME, type CheckpointInfo, CheckpointManager, type CheckpointState, type CompressionResult, ConcurrencyManager, type ConfigFile, ContextInjector, type CriterionResult, DEFAULT_CONFIG, type EpisodicEntry, EpisodicMemory, type Goal, type GoalSource, HypothesisEngine, type DecodeResult as ItpDecodeResult, type EncodeResult as ItpEncodeResult, type LoadTier, type LoggingConfig, type MCPPaymentClient, type MemoryEntry, type MemoryOutcome, type MemoryStats, MetricsCollector, type ModelComplexity, MutationEngine, type MutationRecord, type NativeModule, PACKAGE_NAME, type PaymentAuditEntry, type PaymentConfig, PaymentExecutor, type PaymentMode, type PaymentRequest, type PaymentRequired, type PaymentResult, type Plan, type PlanResult, type PlanStatus, type ProceduralEntry, ProceduralMemory, type Profile, type ProfileName, type RSIAuditEntry, RSIAuditLog, type RSIAuditMetrics, type RSIConfig, type RSIHypothesis, type RSIMutation, type RSIMutationExtended, type RSIMutationExtendedStatus, type RSIMutationStatus, type RSITier, type RSITierLabel, type RSITierMode, type RSITierT4Mode, type ReviewResult, type SignedMessage, type SkillAggregateStats, type SkillExecutionContext, type SkillExecutionResult, SkillExecutor, type SkillManifest, type SkillMetrics, type SkillRequirements, type SpendingDecision, SpendingPolicy, type Step, type StepResult, type StepStatus, type SwarmConfig, type SwarmMemoryEntry, type SwarmMemoryHandle, type SwarmResult, type SwarmRun, type SwarmTask, type TaskCompletion, type TaskMetrics, type TaskOutcome, type TaskStatus, type TokenAllocation, TokenPool, type TokenUsageReport, type TrendDirection, VERSION, type WalletConfig, type WalletInfo, WalletManager, type WasmModule, type WorkingMemory, WorkingMemoryManager, approximateDistance, calculateFee, calculateTransactionFee, classifyHeuristic, classifyTasks, compressVector, computeSha256, createPaymentHeader, decodeSwarmResult, decompressVector, deriveEthereumAddress, derivePublicKey, detect402, digestForWalletAddress, discoverSkills, encodeTaskDescription, evaluateWriteFirewall, evaluateWriteSecurity, generateWallet, generateWalletAddress, getActiveSkills, getActiveTier, getBestCanonicalStore, getCapabilitySummary, getConfigValue, getNative, getNativeCanonicalStore, getNativeCanonicalStoreInMemory, getWasm, getWasmCanonicalStore, importWallet, initConfig, isNativeAvailable, isPaymentRequired, isWasmAvailable, decode as itpDecode, encode as itpEncode, healthCheck as itpHealthCheck, keccak256Digest, listSkillsWithStatus, loadConfig, loadConfigSafe, loadSkillManifest, parseFrontmatter, runAutoResearch, saveConfig, selectModel, setConfigValue, signEcdsa, signMessage, tokenAmountFromHuman, verifyEcdsa };
|