clawpowers 1.1.4 → 2.2.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/CHANGELOG.md +126 -0
- package/COMPATIBILITY.md +13 -0
- package/KNOWN_LIMITATIONS.md +19 -0
- package/LICENSE +44 -0
- package/LICENSING.md +10 -0
- package/README.md +378 -210
- package/SECURITY.md +52 -0
- package/dist/index.d.ts +1477 -0
- package/dist/index.js +3464 -0
- package/dist/index.js.map +1 -0
- 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 +71 -44
- 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/.claude-plugin/manifest.json +0 -19
- package/.codex/INSTALL.md +0 -36
- package/.cursor-plugin/manifest.json +0 -21
- package/.opencode/INSTALL.md +0 -52
- package/ARCHITECTURE.md +0 -69
- package/bin/clawpowers.js +0 -625
- package/bin/clawpowers.sh +0 -91
- package/docs/demo/clawpowers-demo.cast +0 -197
- package/docs/demo/clawpowers-demo.gif +0 -0
- package/docs/launch-images/25-skills-breakdown.jpg +0 -0
- package/docs/launch-images/clawpowers-vs-superpowers.jpg +0 -0
- package/docs/launch-images/economic-code-optimization.jpg +0 -0
- package/docs/launch-images/native-vs-bridge-2.jpg +0 -0
- package/docs/launch-images/native-vs-bridge.jpg +0 -0
- package/docs/launch-images/post1-hero-lobster.jpg +0 -0
- package/docs/launch-images/post2-dashboard.jpg +0 -0
- package/docs/launch-images/post3-superpowers.jpg +0 -0
- package/docs/launch-images/post4-before-after.jpg +0 -0
- package/docs/launch-images/post5-install-now.jpg +0 -0
- package/docs/launch-images/ultimate-stack.jpg +0 -0
- package/docs/launch-posts.md +0 -76
- package/docs/quickstart-first-transaction.md +0 -204
- package/gemini-extension.json +0 -32
- package/hooks/session-start +0 -205
- package/hooks/session-start.cmd +0 -43
- package/hooks/session-start.js +0 -163
- package/runtime/demo/README.md +0 -78
- package/runtime/demo/x402-mock-server.js +0 -230
- package/runtime/feedback/analyze.js +0 -621
- package/runtime/feedback/analyze.sh +0 -546
- package/runtime/init.js +0 -210
- package/runtime/init.sh +0 -178
- package/runtime/metrics/collector.js +0 -361
- package/runtime/metrics/collector.sh +0 -308
- package/runtime/payments/ledger.js +0 -305
- package/runtime/payments/ledger.sh +0 -262
- package/runtime/payments/pipeline.js +0 -455
- package/runtime/persistence/store.js +0 -433
- package/runtime/persistence/store.sh +0 -303
- package/skill.json +0 -106
- package/skills/agent-bounties/SKILL.md +0 -553
- package/skills/agent-payments/SKILL.md +0 -479
- package/skills/brainstorming/SKILL.md +0 -233
- package/skills/content-pipeline/SKILL.md +0 -282
- package/skills/cross-project-knowledge/SKILL.md +0 -345
- package/skills/dispatching-parallel-agents/SKILL.md +0 -305
- package/skills/economic-code-optimization/SKILL.md +0 -265
- package/skills/executing-plans/SKILL.md +0 -255
- package/skills/finishing-a-development-branch/SKILL.md +0 -260
- package/skills/formal-verification-lite/SKILL.md +0 -441
- package/skills/learn-how-to-learn/SKILL.md +0 -235
- package/skills/market-intelligence/SKILL.md +0 -323
- package/skills/meta-skill-evolution/SKILL.md +0 -325
- package/skills/prospecting/SKILL.md +0 -454
- package/skills/receiving-code-review/SKILL.md +0 -225
- package/skills/requesting-code-review/SKILL.md +0 -206
- package/skills/security-audit/SKILL.md +0 -353
- package/skills/self-healing-code/SKILL.md +0 -369
- package/skills/subagent-driven-development/SKILL.md +0 -244
- package/skills/systematic-debugging/SKILL.md +0 -355
- package/skills/test-driven-development/SKILL.md +0 -416
- package/skills/using-clawpowers/SKILL.md +0 -160
- package/skills/using-git-worktrees/SKILL.md +0 -261
- package/skills/validator/SKILL.md +0 -281
- package/skills/verification-before-completion/SKILL.md +0 -254
- package/skills/writing-plans/SKILL.md +0 -276
- package/skills/writing-skills/SKILL.md +0 -260
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1477 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawPowers Skills — Core Type System
|
|
3
|
+
* Zero `any` types. Discriminated unions for all status fields.
|
|
4
|
+
* Agent control-loop types (AgentStatus, AgentState, Goal, Plan, Step) removed —
|
|
5
|
+
* this is a skills library, not an agent runtime.
|
|
6
|
+
*/
|
|
7
|
+
type GoalSource = 'cli' | 'interactive' | 'resume';
|
|
8
|
+
interface Goal {
|
|
9
|
+
readonly taskId: string;
|
|
10
|
+
readonly description: string;
|
|
11
|
+
readonly constraints: readonly string[];
|
|
12
|
+
readonly successCriteria: readonly string[];
|
|
13
|
+
readonly createdAt: string;
|
|
14
|
+
readonly source: GoalSource;
|
|
15
|
+
}
|
|
16
|
+
type StepStatus = 'pending' | 'in-progress' | 'complete' | 'failed' | 'skipped';
|
|
17
|
+
interface Step {
|
|
18
|
+
readonly stepId: string;
|
|
19
|
+
readonly description: string;
|
|
20
|
+
readonly assignedSkills: readonly string[];
|
|
21
|
+
readonly status: StepStatus;
|
|
22
|
+
readonly dependsOn: readonly string[];
|
|
23
|
+
readonly output: string | null;
|
|
24
|
+
readonly retryCount: number;
|
|
25
|
+
readonly maxRetries: number;
|
|
26
|
+
}
|
|
27
|
+
type PlanStatus = 'draft' | 'approved' | 'executing' | 'complete' | 'failed';
|
|
28
|
+
interface Plan {
|
|
29
|
+
readonly taskId: string;
|
|
30
|
+
readonly steps: readonly Step[];
|
|
31
|
+
readonly status: PlanStatus;
|
|
32
|
+
readonly createdAt: string;
|
|
33
|
+
readonly approvedAt: string | null;
|
|
34
|
+
readonly parallelizable: boolean;
|
|
35
|
+
}
|
|
36
|
+
type AgentStatus = 'idle' | 'intake' | 'planning' | 'executing' | 'reviewing' | 'complete' | 'failed' | 'paused';
|
|
37
|
+
interface MemoryStats {
|
|
38
|
+
readonly workingCount: number;
|
|
39
|
+
readonly episodicCount: number;
|
|
40
|
+
readonly proceduralCount: number;
|
|
41
|
+
readonly lastCheckpoint: string | null;
|
|
42
|
+
readonly memoryBytes: number;
|
|
43
|
+
}
|
|
44
|
+
type MemoryOutcome = 'success' | 'failure' | 'partial';
|
|
45
|
+
interface MemoryEntry {
|
|
46
|
+
readonly taskId: string;
|
|
47
|
+
readonly timestamp: string;
|
|
48
|
+
readonly description: string;
|
|
49
|
+
readonly outcome: MemoryOutcome;
|
|
50
|
+
readonly lessonsLearned: readonly string[];
|
|
51
|
+
readonly skillsUsed: readonly string[];
|
|
52
|
+
readonly durationMs: number;
|
|
53
|
+
readonly tags: readonly string[];
|
|
54
|
+
}
|
|
55
|
+
type ProfileName = 'dev' | 'lead' | 'secure' | 'growth' | 'full';
|
|
56
|
+
interface Profile {
|
|
57
|
+
readonly name: ProfileName;
|
|
58
|
+
readonly description: string;
|
|
59
|
+
readonly skills: readonly string[];
|
|
60
|
+
readonly defaultModel: string;
|
|
61
|
+
readonly maxConcurrentAgents: number;
|
|
62
|
+
readonly paymentEnabled: boolean;
|
|
63
|
+
readonly rsiEnabled: boolean;
|
|
64
|
+
}
|
|
65
|
+
interface SkillRequirements {
|
|
66
|
+
readonly bins: readonly string[];
|
|
67
|
+
readonly env: readonly string[];
|
|
68
|
+
readonly config: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
interface SkillManifest {
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly description: string;
|
|
73
|
+
readonly path: string;
|
|
74
|
+
readonly requirements: SkillRequirements | null;
|
|
75
|
+
}
|
|
76
|
+
type RSITierMode = 'auto' | 'ask' | 'off';
|
|
77
|
+
type RSITierT4Mode = 'ask' | 'off';
|
|
78
|
+
interface RSITier {
|
|
79
|
+
readonly t1: RSITierMode;
|
|
80
|
+
readonly t2: RSITierMode;
|
|
81
|
+
readonly t3: RSITierMode;
|
|
82
|
+
readonly t4: RSITierT4Mode;
|
|
83
|
+
}
|
|
84
|
+
type RSIMutationStatus = 'active' | 'rolled-back';
|
|
85
|
+
interface RSIMutation {
|
|
86
|
+
readonly mutationId: string;
|
|
87
|
+
readonly appliedAt: string;
|
|
88
|
+
readonly delta: number;
|
|
89
|
+
readonly status: RSIMutationStatus;
|
|
90
|
+
}
|
|
91
|
+
type PaymentMode = 'human-first' | 'auto' | 'disabled';
|
|
92
|
+
interface PaymentConfig {
|
|
93
|
+
readonly mode: PaymentMode;
|
|
94
|
+
readonly dailyLimitUsd: number;
|
|
95
|
+
readonly weeklyLimitUsd: number;
|
|
96
|
+
readonly allowedDomains: readonly string[];
|
|
97
|
+
}
|
|
98
|
+
interface RSIConfig {
|
|
99
|
+
readonly enabled: boolean;
|
|
100
|
+
readonly tiers: RSITier;
|
|
101
|
+
}
|
|
102
|
+
interface LoggingConfig {
|
|
103
|
+
readonly level: 'debug' | 'info' | 'warn' | 'error';
|
|
104
|
+
readonly retentionDays: number;
|
|
105
|
+
}
|
|
106
|
+
interface ConfigFile {
|
|
107
|
+
readonly version: string;
|
|
108
|
+
readonly profile: ProfileName;
|
|
109
|
+
readonly rsi: RSIConfig;
|
|
110
|
+
readonly payments: PaymentConfig;
|
|
111
|
+
readonly logging: LoggingConfig;
|
|
112
|
+
readonly skillsDir: string;
|
|
113
|
+
readonly dataDir: string;
|
|
114
|
+
}
|
|
115
|
+
interface StepResult {
|
|
116
|
+
readonly stepId: string;
|
|
117
|
+
readonly status: 'success' | 'failure';
|
|
118
|
+
readonly output: string;
|
|
119
|
+
readonly durationMs: number;
|
|
120
|
+
readonly retriesUsed: number;
|
|
121
|
+
readonly error: string | null;
|
|
122
|
+
}
|
|
123
|
+
interface PlanResult {
|
|
124
|
+
readonly taskId: string;
|
|
125
|
+
readonly status: 'success' | 'failure' | 'partial';
|
|
126
|
+
readonly stepResults: readonly StepResult[];
|
|
127
|
+
readonly durationMs: number;
|
|
128
|
+
readonly completedSteps: number;
|
|
129
|
+
readonly failedSteps: number;
|
|
130
|
+
readonly skippedSteps: number;
|
|
131
|
+
}
|
|
132
|
+
interface CriterionResult {
|
|
133
|
+
readonly criterion: string;
|
|
134
|
+
readonly met: boolean;
|
|
135
|
+
readonly evidence: string;
|
|
136
|
+
}
|
|
137
|
+
interface ReviewResult {
|
|
138
|
+
readonly passed: boolean;
|
|
139
|
+
readonly criteria: readonly CriterionResult[];
|
|
140
|
+
readonly suggestions: readonly string[];
|
|
141
|
+
}
|
|
142
|
+
type TaskOutcome = 'success' | 'failure' | 'partial';
|
|
143
|
+
interface TaskCompletion {
|
|
144
|
+
readonly taskId: string;
|
|
145
|
+
readonly outcome: TaskOutcome;
|
|
146
|
+
readonly summary: string;
|
|
147
|
+
readonly durationMs: number;
|
|
148
|
+
readonly skillsUsed: readonly string[];
|
|
149
|
+
readonly lessonsLearned: readonly string[];
|
|
150
|
+
}
|
|
151
|
+
interface WorkingMemory {
|
|
152
|
+
readonly taskId: string;
|
|
153
|
+
readonly goal: Goal;
|
|
154
|
+
readonly plan: Plan;
|
|
155
|
+
readonly currentStepId: string | null;
|
|
156
|
+
readonly intermediateOutputs: Readonly<Record<string, string>>;
|
|
157
|
+
readonly contextWindow: readonly string[];
|
|
158
|
+
}
|
|
159
|
+
interface PaymentRequired {
|
|
160
|
+
readonly amount: number;
|
|
161
|
+
readonly currency: string;
|
|
162
|
+
readonly recipient: string;
|
|
163
|
+
readonly network: string;
|
|
164
|
+
readonly x402Headers: Readonly<Record<string, string>>;
|
|
165
|
+
}
|
|
166
|
+
interface PaymentRequest {
|
|
167
|
+
readonly amount: number;
|
|
168
|
+
readonly currency: string;
|
|
169
|
+
readonly recipient: string;
|
|
170
|
+
readonly x402Headers: Readonly<Record<string, string>>;
|
|
171
|
+
readonly domain: string;
|
|
172
|
+
}
|
|
173
|
+
interface PaymentResult {
|
|
174
|
+
readonly success: boolean;
|
|
175
|
+
readonly txHash?: string;
|
|
176
|
+
readonly error?: string;
|
|
177
|
+
}
|
|
178
|
+
interface SpendingDecision {
|
|
179
|
+
readonly allowed: boolean;
|
|
180
|
+
readonly reason: string;
|
|
181
|
+
readonly remainingDaily: number;
|
|
182
|
+
}
|
|
183
|
+
interface PaymentAuditEntry {
|
|
184
|
+
readonly timestamp: string;
|
|
185
|
+
readonly request: PaymentRequest;
|
|
186
|
+
readonly result: PaymentResult;
|
|
187
|
+
readonly spendingSnapshot: {
|
|
188
|
+
readonly dailySpent: number;
|
|
189
|
+
readonly dailyLimit: number;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
interface EpisodicEntry {
|
|
193
|
+
readonly taskId: string;
|
|
194
|
+
readonly timestamp: string;
|
|
195
|
+
readonly description: string;
|
|
196
|
+
readonly outcome: MemoryOutcome;
|
|
197
|
+
readonly lessonsLearned: readonly string[];
|
|
198
|
+
readonly skillsUsed: readonly string[];
|
|
199
|
+
readonly durationMs: number;
|
|
200
|
+
readonly tags: readonly string[];
|
|
201
|
+
}
|
|
202
|
+
interface MutationRecord {
|
|
203
|
+
readonly mutationId: string;
|
|
204
|
+
readonly description: string;
|
|
205
|
+
readonly appliedAt: string;
|
|
206
|
+
readonly revertedAt: string | null;
|
|
207
|
+
readonly status: 'active' | 'reverted';
|
|
208
|
+
}
|
|
209
|
+
interface ProceduralEntry {
|
|
210
|
+
readonly skillName: string;
|
|
211
|
+
readonly invocationCount: number;
|
|
212
|
+
readonly successRate: number;
|
|
213
|
+
readonly avgContribution: number;
|
|
214
|
+
readonly preferredContexts: readonly string[];
|
|
215
|
+
readonly lastUsed: string;
|
|
216
|
+
readonly mutations: readonly MutationRecord[];
|
|
217
|
+
}
|
|
218
|
+
interface CheckpointState {
|
|
219
|
+
readonly taskId: string;
|
|
220
|
+
readonly goal: Goal;
|
|
221
|
+
readonly plan: Plan;
|
|
222
|
+
readonly currentStepId: string | null;
|
|
223
|
+
readonly intermediateOutputs: Readonly<Record<string, string>>;
|
|
224
|
+
readonly workingMemory: WorkingMemory;
|
|
225
|
+
readonly savedAt: string;
|
|
226
|
+
readonly agentStatus: AgentStatus;
|
|
227
|
+
}
|
|
228
|
+
interface CheckpointInfo {
|
|
229
|
+
readonly taskId: string;
|
|
230
|
+
readonly description: string;
|
|
231
|
+
readonly savedAt: string;
|
|
232
|
+
readonly isStale: boolean;
|
|
233
|
+
}
|
|
234
|
+
interface TaskMetrics {
|
|
235
|
+
readonly taskId: string;
|
|
236
|
+
readonly timestamp: string;
|
|
237
|
+
readonly durationMs: number;
|
|
238
|
+
readonly stepCount: number;
|
|
239
|
+
readonly stepsCompleted: number;
|
|
240
|
+
readonly stepsFailed: number;
|
|
241
|
+
readonly retryCount: number;
|
|
242
|
+
readonly skillsUsed: readonly string[];
|
|
243
|
+
readonly outcome: TaskOutcome;
|
|
244
|
+
readonly memoryEntriesCreated: number;
|
|
245
|
+
}
|
|
246
|
+
interface SkillMetrics {
|
|
247
|
+
readonly skillName: string;
|
|
248
|
+
readonly timestamp: string;
|
|
249
|
+
readonly invoked: boolean;
|
|
250
|
+
readonly succeeded: boolean;
|
|
251
|
+
readonly durationMs: number;
|
|
252
|
+
readonly taskId: string;
|
|
253
|
+
readonly mutationActive: boolean;
|
|
254
|
+
}
|
|
255
|
+
type TrendDirection = 'improving' | 'declining' | 'stable';
|
|
256
|
+
interface SkillAggregateStats {
|
|
257
|
+
readonly skillName: string;
|
|
258
|
+
readonly totalInvocations: number;
|
|
259
|
+
readonly successRate: number;
|
|
260
|
+
readonly avgDurationMs: number;
|
|
261
|
+
readonly trendDirection: TrendDirection;
|
|
262
|
+
}
|
|
263
|
+
type RSITierLabel = 'T1' | 'T2' | 'T3' | 'T4';
|
|
264
|
+
interface RSIHypothesis {
|
|
265
|
+
readonly hypothesisId: string;
|
|
266
|
+
readonly skillName: string;
|
|
267
|
+
readonly description: string;
|
|
268
|
+
readonly expectedImprovement: number;
|
|
269
|
+
readonly tier: RSITierLabel;
|
|
270
|
+
readonly confidence: number;
|
|
271
|
+
readonly evidence: readonly string[];
|
|
272
|
+
}
|
|
273
|
+
type RSIMutationExtendedStatus = 'proposed' | 'applied' | 'reverted' | 'promoted';
|
|
274
|
+
interface RSIMutationExtended {
|
|
275
|
+
readonly mutationId: string;
|
|
276
|
+
readonly hypothesisId: string;
|
|
277
|
+
readonly skillName: string;
|
|
278
|
+
readonly tier: RSITierLabel;
|
|
279
|
+
readonly description: string;
|
|
280
|
+
readonly originalValue: string;
|
|
281
|
+
readonly mutatedValue: string;
|
|
282
|
+
readonly status: RSIMutationExtendedStatus;
|
|
283
|
+
readonly appliedAt: string | null;
|
|
284
|
+
readonly revertedAt: string | null;
|
|
285
|
+
}
|
|
286
|
+
type ABTestStatus = 'running' | 'completed' | 'cancelled';
|
|
287
|
+
type ABTestDecision = 'promote' | 'rollback' | 'continue';
|
|
288
|
+
interface ABTest {
|
|
289
|
+
readonly testId: string;
|
|
290
|
+
readonly mutationId: string;
|
|
291
|
+
readonly skillName: string;
|
|
292
|
+
readonly baselineStats: SkillAggregateStats;
|
|
293
|
+
readonly variantStats: SkillAggregateStats;
|
|
294
|
+
readonly sampleSize: number;
|
|
295
|
+
readonly minSampleSize: number;
|
|
296
|
+
readonly startedAt: string;
|
|
297
|
+
readonly status: ABTestStatus;
|
|
298
|
+
}
|
|
299
|
+
interface ABTestResult {
|
|
300
|
+
readonly testId: string;
|
|
301
|
+
readonly decision: ABTestDecision;
|
|
302
|
+
readonly improvement: number;
|
|
303
|
+
readonly confidence: number;
|
|
304
|
+
}
|
|
305
|
+
interface RSIAuditMetrics {
|
|
306
|
+
readonly baseline: number;
|
|
307
|
+
readonly current: number;
|
|
308
|
+
readonly delta: number;
|
|
309
|
+
}
|
|
310
|
+
interface RSIAuditEntry {
|
|
311
|
+
readonly timestamp: string;
|
|
312
|
+
readonly action: string;
|
|
313
|
+
readonly skillName: string;
|
|
314
|
+
readonly mutationId: string;
|
|
315
|
+
readonly hypothesis: string;
|
|
316
|
+
readonly metrics: RSIAuditMetrics;
|
|
317
|
+
readonly decision: string;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* ClawPowers Agent — Config Manager
|
|
322
|
+
* CRUD for ~/.clawpowers/config.json with Zod validation.
|
|
323
|
+
* T4 can never be set to "auto" — enforced at validation layer.
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
declare function loadConfig(configPath?: string): ConfigFile;
|
|
327
|
+
/**
|
|
328
|
+
* Safe config loader — returns defaults if file is missing or invalid.
|
|
329
|
+
* Used by CLI where crashing on stale config is bad UX.
|
|
330
|
+
*/
|
|
331
|
+
declare function loadConfigSafe(configPath?: string): ConfigFile;
|
|
332
|
+
declare function saveConfig(config: ConfigFile, configPath?: string): void;
|
|
333
|
+
declare function initConfig(configPath?: string): ConfigFile;
|
|
334
|
+
/**
|
|
335
|
+
* Get a value from config using dot notation (e.g., "rsi.tiers.t1")
|
|
336
|
+
*/
|
|
337
|
+
declare function getConfigValue(config: ConfigFile, key: string): unknown;
|
|
338
|
+
/**
|
|
339
|
+
* Set a value in config using dot notation. Returns the updated config.
|
|
340
|
+
* Validates the entire config after the set to ensure consistency.
|
|
341
|
+
* Throws on invalid values (e.g., T4 = "auto").
|
|
342
|
+
*/
|
|
343
|
+
declare function setConfigValue(config: ConfigFile, key: string, value: string): ConfigFile;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* ClawPowers Skills — Constants
|
|
347
|
+
* Default paths, version, config values, RSI tier boundaries.
|
|
348
|
+
*/
|
|
349
|
+
|
|
350
|
+
declare const VERSION = "2.2.0";
|
|
351
|
+
declare const PACKAGE_NAME = "clawpowers";
|
|
352
|
+
declare const CLAWPOWERS_HOME: string;
|
|
353
|
+
declare const DEFAULT_CONFIG: ConfigFile;
|
|
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
|
+
|
|
546
|
+
/**
|
|
547
|
+
* ClawPowers Agent — Payment Discovery
|
|
548
|
+
* Detects HTTP 402 Payment Required responses and parses x402 headers.
|
|
549
|
+
*/
|
|
550
|
+
|
|
551
|
+
interface HttpResponse {
|
|
552
|
+
readonly status: number;
|
|
553
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Detect a 402 Payment Required response and extract payment details from x402 headers.
|
|
557
|
+
* Returns null if the response is not a 402 or if required headers are missing.
|
|
558
|
+
*/
|
|
559
|
+
declare function detect402(response: HttpResponse): PaymentRequired | null;
|
|
560
|
+
/**
|
|
561
|
+
* Type guard to check if an error represents a 402 Payment Required response.
|
|
562
|
+
*/
|
|
563
|
+
declare function isPaymentRequired(error: unknown): boolean;
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* ClawPowers Agent — Spending Policy
|
|
567
|
+
* Enforces daily limits, per-transaction limits, and domain allowlists.
|
|
568
|
+
* Fail-closed: any policy error results in rejection.
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
interface SpendingRecord {
|
|
572
|
+
amount: number;
|
|
573
|
+
timestamp: number;
|
|
574
|
+
domain: string;
|
|
575
|
+
}
|
|
576
|
+
declare class SpendingPolicy {
|
|
577
|
+
readonly dailyLimit: number;
|
|
578
|
+
readonly transactionLimit: number;
|
|
579
|
+
readonly allowedDomains: readonly string[];
|
|
580
|
+
private spendingLog;
|
|
581
|
+
constructor(options: {
|
|
582
|
+
dailyLimit: number;
|
|
583
|
+
transactionLimit: number;
|
|
584
|
+
allowedDomains: readonly string[];
|
|
585
|
+
});
|
|
586
|
+
/**
|
|
587
|
+
* Get total spending for the current UTC day.
|
|
588
|
+
*/
|
|
589
|
+
getDailySpent(): number;
|
|
590
|
+
/**
|
|
591
|
+
* Check whether a transaction is allowed under the current policy.
|
|
592
|
+
* Fail-closed: any validation error results in rejection.
|
|
593
|
+
*/
|
|
594
|
+
checkTransaction(amount: number, domain: string): SpendingDecision;
|
|
595
|
+
/**
|
|
596
|
+
* Record a completed spending transaction.
|
|
597
|
+
*/
|
|
598
|
+
recordSpend(amount: number, domain: string): void;
|
|
599
|
+
/**
|
|
600
|
+
* Reset all spending records (used for testing).
|
|
601
|
+
*/
|
|
602
|
+
reset(): void;
|
|
603
|
+
/**
|
|
604
|
+
* Get the full spending log (for audit purposes).
|
|
605
|
+
*/
|
|
606
|
+
getSpendingLog(): readonly SpendingRecord[];
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* ClawPowers Agent — Payment Executor
|
|
611
|
+
* Executes payments via agentpay-mcp with spending policy enforcement.
|
|
612
|
+
* Never auto-retries failed payments (financial safety).
|
|
613
|
+
*/
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Interface for an MCP payment client.
|
|
617
|
+
* In production, this wraps agentpay-mcp; in tests, it can be substituted.
|
|
618
|
+
*/
|
|
619
|
+
interface MCPPaymentClient {
|
|
620
|
+
executePayment(params: {
|
|
621
|
+
amount: number;
|
|
622
|
+
currency: string;
|
|
623
|
+
recipient: string;
|
|
624
|
+
x402Headers: Readonly<Record<string, string>>;
|
|
625
|
+
}): Promise<{
|
|
626
|
+
txHash: string;
|
|
627
|
+
status: 'success' | 'failed';
|
|
628
|
+
}>;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Payment executor that enforces spending policy and logs all attempts.
|
|
632
|
+
*/
|
|
633
|
+
declare class PaymentExecutor {
|
|
634
|
+
private readonly policy;
|
|
635
|
+
private readonly client;
|
|
636
|
+
private readonly auditLog;
|
|
637
|
+
constructor(policy: SpendingPolicy, client: MCPPaymentClient);
|
|
638
|
+
/**
|
|
639
|
+
* Execute a payment request.
|
|
640
|
+
* 1. Check spending policy
|
|
641
|
+
* 2. If allowed, execute via MCP client
|
|
642
|
+
* 3. Log the result (success or failure)
|
|
643
|
+
* 4. Never auto-retry on failure
|
|
644
|
+
*/
|
|
645
|
+
executePayment(request: PaymentRequest): Promise<PaymentResult>;
|
|
646
|
+
/**
|
|
647
|
+
* Get the full payment audit log.
|
|
648
|
+
*/
|
|
649
|
+
getAuditLog(): readonly PaymentAuditEntry[];
|
|
650
|
+
/**
|
|
651
|
+
* Log a payment attempt to the audit trail.
|
|
652
|
+
*/
|
|
653
|
+
private logAudit;
|
|
654
|
+
}
|
|
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
|
+
|
|
687
|
+
/**
|
|
688
|
+
* ClawPowers Agent — Working Memory Manager
|
|
689
|
+
* In-process working memory with token budget enforcement.
|
|
690
|
+
*/
|
|
691
|
+
|
|
692
|
+
declare class WorkingMemoryManager {
|
|
693
|
+
private memory;
|
|
694
|
+
create(taskId: string, goal: Goal): WorkingMemory;
|
|
695
|
+
updateCurrentStep(stepId: string): void;
|
|
696
|
+
addIntermediateOutput(stepId: string, output: string): void;
|
|
697
|
+
/**
|
|
698
|
+
* Inject context entries into working memory, enforcing token budget.
|
|
699
|
+
* Entries are added until the budget is exhausted, then truncated.
|
|
700
|
+
*/
|
|
701
|
+
injectContext(entries: readonly string[]): void;
|
|
702
|
+
getSnapshot(): WorkingMemory;
|
|
703
|
+
clear(): void;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* ClawPowers Agent — Episodic Memory
|
|
708
|
+
* JSONL append-only storage for task episodes.
|
|
709
|
+
*/
|
|
710
|
+
|
|
711
|
+
declare class EpisodicMemory {
|
|
712
|
+
private readonly filePath;
|
|
713
|
+
constructor(filePath: string);
|
|
714
|
+
private ensureDir;
|
|
715
|
+
append(entry: EpisodicEntry): Promise<void>;
|
|
716
|
+
readAll(): Promise<EpisodicEntry[]>;
|
|
717
|
+
search(query: string, limit?: number): Promise<EpisodicEntry[]>;
|
|
718
|
+
readRecent(count: number): Promise<EpisodicEntry[]>;
|
|
719
|
+
recoverFromCorruption(): Promise<{
|
|
720
|
+
recovered: number;
|
|
721
|
+
lost: number;
|
|
722
|
+
}>;
|
|
723
|
+
private parseLines;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* ClawPowers Agent — Procedural Memory
|
|
728
|
+
* JSON-based skill effectiveness tracking with atomic writes.
|
|
729
|
+
*/
|
|
730
|
+
|
|
731
|
+
declare class ProceduralMemory {
|
|
732
|
+
private readonly filePath;
|
|
733
|
+
private cache;
|
|
734
|
+
constructor(filePath: string);
|
|
735
|
+
private ensureDir;
|
|
736
|
+
load(): Promise<ProceduralEntry[]>;
|
|
737
|
+
update(skillName: string, result: {
|
|
738
|
+
succeeded: boolean;
|
|
739
|
+
durationMs: number;
|
|
740
|
+
taskId: string;
|
|
741
|
+
}): Promise<void>;
|
|
742
|
+
getSkillScore(skillName: string): ProceduralEntry | null;
|
|
743
|
+
getTopSkills(context: string, limit: number): ProceduralEntry[];
|
|
744
|
+
recordMutation(skillName: string, mutation: MutationRecord): Promise<void>;
|
|
745
|
+
rollbackMutation(skillName: string, mutationId: string): Promise<void>;
|
|
746
|
+
private atomicWrite;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* ClawPowers Agent — Checkpoint Manager
|
|
751
|
+
* Crash recovery via atomic checkpoint files.
|
|
752
|
+
*/
|
|
753
|
+
|
|
754
|
+
declare class CheckpointManager {
|
|
755
|
+
private readonly dir;
|
|
756
|
+
constructor(dir: string);
|
|
757
|
+
private ensureDir;
|
|
758
|
+
private filePath;
|
|
759
|
+
save(taskId: string, state: CheckpointState): Promise<void>;
|
|
760
|
+
load(taskId: string): Promise<CheckpointState | null>;
|
|
761
|
+
remove(taskId: string): Promise<void>;
|
|
762
|
+
listIncomplete(): Promise<CheckpointInfo[]>;
|
|
763
|
+
isStale(checkpoint: CheckpointState, maxAgeMs?: number): boolean;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* ClawPowers Agent — Context Injector
|
|
768
|
+
* Selects and compresses relevant memories for working memory injection.
|
|
769
|
+
*/
|
|
770
|
+
|
|
771
|
+
declare class ContextInjector {
|
|
772
|
+
private readonly episodic;
|
|
773
|
+
private readonly procedural;
|
|
774
|
+
constructor(episodic: EpisodicMemory, procedural: ProceduralMemory);
|
|
775
|
+
inject(goal: Goal, maxTokens?: number): Promise<string[]>;
|
|
776
|
+
}
|
|
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
|
+
|
|
849
|
+
/**
|
|
850
|
+
* ClawPowers Agent — RSI Metrics Collector
|
|
851
|
+
* Per-task and per-skill metric collection in JSONL format.
|
|
852
|
+
*/
|
|
853
|
+
|
|
854
|
+
declare class MetricsCollector {
|
|
855
|
+
private readonly taskMetricsPath;
|
|
856
|
+
private readonly skillMetricsPath;
|
|
857
|
+
constructor(taskMetricsPath: string, skillMetricsPath: string);
|
|
858
|
+
private ensureDir;
|
|
859
|
+
recordTaskMetrics(task: TaskMetrics): Promise<void>;
|
|
860
|
+
recordSkillMetrics(skill: SkillMetrics): Promise<void>;
|
|
861
|
+
getTaskHistory(limit?: number): Promise<TaskMetrics[]>;
|
|
862
|
+
getSkillHistory(skillName: string, limit?: number): Promise<SkillMetrics[]>;
|
|
863
|
+
getAggregatedSkillStats(skillName: string): Promise<SkillAggregateStats>;
|
|
864
|
+
private calculateTrend;
|
|
865
|
+
private readJsonl;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* ClawPowers Agent — RSI Hypothesis Engine
|
|
870
|
+
* Analyzes skill stats and task history to generate improvement hypotheses.
|
|
871
|
+
*/
|
|
872
|
+
|
|
873
|
+
declare class HypothesisEngine {
|
|
874
|
+
analyze(skillStats: readonly SkillAggregateStats[], taskHistory: readonly TaskMetrics[]): RSIHypothesis[];
|
|
875
|
+
private detectLowSuccessRate;
|
|
876
|
+
private detectSlowSkills;
|
|
877
|
+
private detectFrequentlyPairedSkills;
|
|
878
|
+
private detectUnusedInSuccessful;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* ClawPowers Agent — RSI Mutation Engine
|
|
883
|
+
* Creates and manages mutations from hypotheses with tier enforcement.
|
|
884
|
+
*/
|
|
885
|
+
|
|
886
|
+
declare class MutationEngine {
|
|
887
|
+
private readonly historyPath;
|
|
888
|
+
constructor(historyPath: string);
|
|
889
|
+
private ensureDir;
|
|
890
|
+
createMutation(hypothesis: RSIHypothesis): RSIMutationExtended;
|
|
891
|
+
applyMutation(mutation: RSIMutationExtended): Promise<void>;
|
|
892
|
+
revertMutation(mutation: RSIMutationExtended): Promise<void>;
|
|
893
|
+
getMutationHistory(): Promise<RSIMutationExtended[]>;
|
|
894
|
+
private appendHistory;
|
|
895
|
+
private validateSafety;
|
|
896
|
+
private isSafetyInvariant;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* ClawPowers Agent — A/B Test Manager
|
|
901
|
+
* Orchestrates A/B tests for RSI mutations.
|
|
902
|
+
*/
|
|
903
|
+
|
|
904
|
+
declare class ABTestManager {
|
|
905
|
+
private readonly tests;
|
|
906
|
+
private readonly results;
|
|
907
|
+
startTest(mutation: RSIMutationExtended, baselineMetrics: SkillAggregateStats): ABTest;
|
|
908
|
+
recordResult(testId: string, taskMetrics: TaskMetrics): void;
|
|
909
|
+
evaluateTest(testId: string): ABTestResult;
|
|
910
|
+
getActiveTests(): ABTest[];
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* ClawPowers Agent — RSI Audit Log
|
|
915
|
+
* Append-only JSONL audit trail for all RSI actions.
|
|
916
|
+
*/
|
|
917
|
+
|
|
918
|
+
declare class RSIAuditLog {
|
|
919
|
+
private readonly filePath;
|
|
920
|
+
constructor(filePath: string);
|
|
921
|
+
private ensureDir;
|
|
922
|
+
log(entry: RSIAuditEntry): Promise<void>;
|
|
923
|
+
getHistory(limit?: number): Promise<RSIAuditEntry[]>;
|
|
924
|
+
getByMutation(mutationId: string): Promise<RSIAuditEntry[]>;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* ClawPowers Agent — RSI AutoResearch Module
|
|
929
|
+
*
|
|
930
|
+
* Runs BEFORE the mutation engine when T3 is triggered.
|
|
931
|
+
* Searches for solutions to task failures, tests candidates in sandbox,
|
|
932
|
+
* and promotes successful solutions to new skills.
|
|
933
|
+
*/
|
|
934
|
+
interface FailureTrace {
|
|
935
|
+
taskDescription: string;
|
|
936
|
+
error: string;
|
|
937
|
+
executionSteps: string[];
|
|
938
|
+
skillsUsed: string[];
|
|
939
|
+
attemptCount: number;
|
|
940
|
+
}
|
|
941
|
+
interface CandidateSolution {
|
|
942
|
+
source: 'web-search' | 'npm-registry' | 'skill-catalog';
|
|
943
|
+
description: string;
|
|
944
|
+
approach: string;
|
|
945
|
+
confidence: number;
|
|
946
|
+
}
|
|
947
|
+
interface TestResult {
|
|
948
|
+
passed: boolean;
|
|
949
|
+
output: string;
|
|
950
|
+
durationMs: number;
|
|
951
|
+
attempt: number;
|
|
952
|
+
}
|
|
953
|
+
interface SkillDefinition {
|
|
954
|
+
skillId: string;
|
|
955
|
+
name: string;
|
|
956
|
+
description: string;
|
|
957
|
+
approach: string;
|
|
958
|
+
source: CandidateSolution['source'];
|
|
959
|
+
promotedAt: string;
|
|
960
|
+
testResults: TestResult[];
|
|
961
|
+
}
|
|
962
|
+
interface TaskContext {
|
|
963
|
+
taskId: string;
|
|
964
|
+
description: string;
|
|
965
|
+
constraints: string[];
|
|
966
|
+
successCriteria: string[];
|
|
967
|
+
}
|
|
968
|
+
declare class AutoResearcher {
|
|
969
|
+
private readonly skillsDir;
|
|
970
|
+
constructor(skillsDir?: string);
|
|
971
|
+
/**
|
|
972
|
+
* Search for candidate solutions to a failure.
|
|
973
|
+
*
|
|
974
|
+
* Sources queried (in order of reliability):
|
|
975
|
+
* 1. skill-catalog — skills already available that match the error domain
|
|
976
|
+
* 2. npm-registry — packages that match the error keywords
|
|
977
|
+
* 3. web-search — constructs a query from the failure trace
|
|
978
|
+
*
|
|
979
|
+
* Returns candidates sorted by confidence (highest first).
|
|
980
|
+
*/
|
|
981
|
+
research(failure: FailureTrace): Promise<CandidateSolution[]>;
|
|
982
|
+
/**
|
|
983
|
+
* Test a candidate solution in an isolated sandbox.
|
|
984
|
+
* Runs the candidate's approach as a shell command in a temp directory.
|
|
985
|
+
* Returns a TestResult with pass/fail, output, and duration.
|
|
986
|
+
*/
|
|
987
|
+
testCandidate(candidate: CandidateSolution, task: TaskContext): Promise<TestResult>;
|
|
988
|
+
/**
|
|
989
|
+
* Run a candidate through REQUIRED_PASSING_RUNS sandbox tests.
|
|
990
|
+
* Returns all TestResult objects. If fewer than REQUIRED_PASSING_RUNS pass,
|
|
991
|
+
* the candidate is NOT promoted (caller must check).
|
|
992
|
+
*/
|
|
993
|
+
runSandboxTests(candidate: CandidateSolution, task: TaskContext): Promise<TestResult[]>;
|
|
994
|
+
/**
|
|
995
|
+
* Promote a candidate solution to a new skill definition.
|
|
996
|
+
* Writes a minimal SKILL.md to the skills directory and returns
|
|
997
|
+
* the SkillDefinition.
|
|
998
|
+
*/
|
|
999
|
+
promoteToSkill(candidate: CandidateSolution, testResults: TestResult[]): Promise<SkillDefinition>;
|
|
1000
|
+
private searchSkillCatalog;
|
|
1001
|
+
private searchNpmRegistry;
|
|
1002
|
+
private buildWebSearchCandidates;
|
|
1003
|
+
/**
|
|
1004
|
+
* Build a sandboxed test script for a candidate solution.
|
|
1005
|
+
* Validates the candidate's approach by checking its core prerequisites
|
|
1006
|
+
* (e.g. that a package is installed, or a command is available).
|
|
1007
|
+
*/
|
|
1008
|
+
private buildTestScript;
|
|
1009
|
+
private deriveSkillName;
|
|
1010
|
+
private renderSkillMd;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Run the full AutoResearch cycle for a failed task.
|
|
1014
|
+
* Returns the promoted SkillDefinition if a solution was found and promoted,
|
|
1015
|
+
* or null if no solution was found (caller should fall through to mutation).
|
|
1016
|
+
*/
|
|
1017
|
+
declare function runAutoResearch(failure: FailureTrace, task: TaskContext, skillsDir?: string): Promise<SkillDefinition | null>;
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* ClawPowers Agent — Skill Loader
|
|
1021
|
+
* Discovers skills from skill directories, validates SKILL.md frontmatter.
|
|
1022
|
+
*/
|
|
1023
|
+
|
|
1024
|
+
interface ParsedFrontmatter {
|
|
1025
|
+
name?: string;
|
|
1026
|
+
description?: string;
|
|
1027
|
+
metadata?: {
|
|
1028
|
+
openclaw?: {
|
|
1029
|
+
requires?: {
|
|
1030
|
+
bins?: string[];
|
|
1031
|
+
env?: string[];
|
|
1032
|
+
config?: string[];
|
|
1033
|
+
};
|
|
1034
|
+
};
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Parse YAML frontmatter from a SKILL.md file content.
|
|
1039
|
+
* Expects format: ---\n<yaml>\n---\n<content>
|
|
1040
|
+
*/
|
|
1041
|
+
declare function parseFrontmatter(content: string): ParsedFrontmatter;
|
|
1042
|
+
/**
|
|
1043
|
+
* Load a single skill manifest from a directory containing SKILL.md
|
|
1044
|
+
*/
|
|
1045
|
+
declare function loadSkillManifest(skillDir: string): SkillManifest | null;
|
|
1046
|
+
/**
|
|
1047
|
+
* Discover all skills in a directory. Each subdirectory with a valid SKILL.md
|
|
1048
|
+
* becomes a skill manifest.
|
|
1049
|
+
*/
|
|
1050
|
+
declare function discoverSkills(skillsDir: string): SkillManifest[];
|
|
1051
|
+
/**
|
|
1052
|
+
* Filter skills based on active profile.
|
|
1053
|
+
* Returns only skills that are listed in the profile's skill list.
|
|
1054
|
+
*/
|
|
1055
|
+
declare function getActiveSkills(allSkills: SkillManifest[], profile: Profile): SkillManifest[];
|
|
1056
|
+
/**
|
|
1057
|
+
* List skills with their active/inactive status for a given profile.
|
|
1058
|
+
*/
|
|
1059
|
+
declare function listSkillsWithStatus(allSkills: SkillManifest[], profile: Profile): Array<{
|
|
1060
|
+
skill: SkillManifest;
|
|
1061
|
+
active: boolean;
|
|
1062
|
+
}>;
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* ClawPowers Skills — Skill Executor
|
|
1066
|
+
* Execute skills and track outcomes in procedural memory.
|
|
1067
|
+
*/
|
|
1068
|
+
|
|
1069
|
+
interface SkillExecutionContext {
|
|
1070
|
+
readonly taskId: string;
|
|
1071
|
+
readonly input: string;
|
|
1072
|
+
readonly metadata?: Record<string, unknown>;
|
|
1073
|
+
}
|
|
1074
|
+
interface SkillExecutionResult {
|
|
1075
|
+
readonly success: boolean;
|
|
1076
|
+
readonly output: string;
|
|
1077
|
+
readonly durationMs: number;
|
|
1078
|
+
readonly error?: string;
|
|
1079
|
+
}
|
|
1080
|
+
declare class SkillExecutor {
|
|
1081
|
+
private readonly skillsDir;
|
|
1082
|
+
private readonly memory;
|
|
1083
|
+
constructor(skillsDir: string, memory: ProceduralMemory);
|
|
1084
|
+
execute(skillName: string, context: SkillExecutionContext): Promise<SkillExecutionResult>;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
interface WalletConfig {
|
|
1088
|
+
readonly chain: 'base' | 'ethereum' | 'polygon';
|
|
1089
|
+
readonly dataDir: string;
|
|
1090
|
+
}
|
|
1091
|
+
interface WalletInfo {
|
|
1092
|
+
readonly address: string;
|
|
1093
|
+
readonly chain: string;
|
|
1094
|
+
readonly createdAt: string;
|
|
1095
|
+
readonly keyFile: string;
|
|
1096
|
+
}
|
|
1097
|
+
interface SignedMessage {
|
|
1098
|
+
readonly message: string;
|
|
1099
|
+
readonly signature: string;
|
|
1100
|
+
readonly address: string;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* ClawPowers Skills — Wallet Manager
|
|
1105
|
+
* High-level wallet management: generate, import, sign, list.
|
|
1106
|
+
*/
|
|
1107
|
+
|
|
1108
|
+
declare class WalletManager {
|
|
1109
|
+
private readonly config;
|
|
1110
|
+
constructor(config: WalletConfig);
|
|
1111
|
+
generate(): Promise<WalletInfo>;
|
|
1112
|
+
import(privateKey: string): Promise<WalletInfo>;
|
|
1113
|
+
sign(message: string, walletInfo: WalletInfo, passphrase: string): Promise<string>;
|
|
1114
|
+
listWallets(): Promise<WalletInfo[]>;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* ClawPowers Skills — Wallet Crypto
|
|
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.
|
|
1122
|
+
*/
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Generate a new Ethereum-compatible wallet.
|
|
1126
|
+
* Private key is encrypted with a random passphrase and stored to disk.
|
|
1127
|
+
*/
|
|
1128
|
+
declare function generateWallet(config: WalletConfig): Promise<WalletInfo>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Import an existing wallet from a private key hex string.
|
|
1131
|
+
*/
|
|
1132
|
+
declare function importWallet(privateKeyHex: string, config: WalletConfig): Promise<WalletInfo>;
|
|
1133
|
+
/**
|
|
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.
|
|
1137
|
+
*/
|
|
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>;
|
|
1476
|
+
|
|
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 };
|