-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtools.js
More file actions
688 lines (658 loc) · 27.3 KB
/
tools.js
File metadata and controls
688 lines (658 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
// mcp-server/lib/tools.js
/**
* DashClaw MCP tool definitions and handlers.
* Tool definitions follow JSON Schema (for both MCP registerTool and JSON-RPC).
* Handlers are pure functions that call DashClawClient and return text content.
*
* This file is HAND-CURATED on purpose. Every MCP tool has a semantically
* precise description and custom handler logic (e.g., dashclaw_wait_for_approval
* polls until status changes) that can't be auto-generated from route metadata.
*
* For the live API surface, see `routes-inventory.generated.json` (regenerated
* by `npm run livingcode:refresh`). When adding a new route that agents should
* invoke, diff the inventory against TOOL_DEFINITIONS below to decide whether
* a new tool wrapper is warranted.
*/
export const TOOL_DEFINITIONS = [
{
name: 'dashclaw_guard',
description:
'Evaluate DashClaw governance policies before taking a risky action. Call this BEFORE ' +
'any action that modifies external systems, deploys code, sends messages, or touches ' +
'production data. Returns a decision: "allow" (proceed), "warn" (proceed with caution), ' +
'"block" (stop), or "require_approval" (wait for human in Mission Control). If the ' +
'decision is "block", do NOT proceed with the action.',
inputSchema: {
type: 'object',
properties: {
action_type: { type: 'string', description: 'Category of action (e.g., deploy, send_email, database_write, api_call)' },
declared_goal: { type: 'string', description: 'What you intend to do, in plain language' },
risk_score: { type: 'integer', description: 'Estimated risk 0-100. Use 70+ for production systems.' },
agent_id: { type: 'string', description: 'Override default agent ID' },
systems_touched: { type: 'array', items: { type: 'string' }, description: 'Systems affected (e.g., production, database, email)' },
reversible: { type: 'boolean', description: 'Whether the action can be undone' },
},
required: ['action_type', 'declared_goal', 'risk_score'],
},
},
{
name: 'dashclaw_record',
description:
'Record a governed action in DashClaw\'s audit trail. Use this to log significant ' +
'decisions, completed tasks, or notable outcomes. Every important action the agent takes ' +
'should be recorded for governance visibility in Mission Control and the Decisions ledger.',
inputSchema: {
type: 'object',
properties: {
action_type: { type: 'string', description: 'Category (e.g., research, analysis, code_change, deploy)' },
declared_goal: { type: 'string', description: 'What was accomplished' },
status: { type: 'string', enum: ['running', 'completed', 'failed', 'pending_approval'], description: 'Outcome status' },
risk_score: { type: 'integer', description: 'Risk level 0-100 (default 30)' },
agent_id: { type: 'string', description: 'Override default agent ID' },
reasoning: { type: 'string', description: 'Why this action was chosen' },
confidence: { type: 'integer', description: 'Confidence 0-100' },
systems_touched: { type: 'array', items: { type: 'string' }, description: 'Systems affected' },
reversible: { type: 'boolean', description: 'Whether the action can be undone' },
output_summary: { type: 'string', description: 'Brief summary of what was produced' },
tokens_in: { type: 'integer', description: 'Input tokens consumed' },
tokens_out: { type: 'integer', description: 'Output tokens produced' },
model: { type: 'string', description: 'Model used' },
cost_estimate: { type: 'number', description: 'Estimated cost in USD' },
},
required: ['action_type', 'declared_goal', 'status'],
},
},
{
name: 'dashclaw_invoke',
description:
'Invoke a DashClaw-governed capability (external API). The capability is guarded ' +
'(policy check), executed (HTTP call), and recorded (audit trail) automatically. Use ' +
'this instead of making direct HTTP calls when the target API is registered as a DashClaw ' +
'capability. Call dashclaw_capabilities_list first to discover available capability IDs.',
inputSchema: {
type: 'object',
properties: {
capability_id: { type: 'string', description: 'The capability ID (e.g., cap_abc123)' },
declared_goal: { type: 'string', description: 'What you\'re trying to accomplish' },
agent_id: { type: 'string', description: 'Override default agent ID' },
payload: { type: 'object', description: 'Request payload for the capability' },
},
required: ['capability_id', 'declared_goal'],
},
},
{
name: 'dashclaw_capabilities_list',
description:
'List available capabilities registered in DashClaw. Use this to discover what external ' +
'APIs and tools are available before invoking them. Returns capability IDs, names, health ' +
'status, and risk levels. Filter by category, risk level, or search term.',
inputSchema: {
type: 'object',
properties: {
category: { type: 'string', description: 'Filter by category: external_api, webhook, function' },
risk_level: { type: 'string', description: 'Filter: low, medium, high, critical' },
search: { type: 'string', description: 'Search by name or description' },
},
},
},
{
name: 'dashclaw_policies_list',
description:
'List active governance policies. Use this to understand what rules govern your actions ' +
'before taking them. Helps calibrate risk scores and know which action types require ' +
'approval. Optionally filter to policies applying to a specific agent.',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string', description: 'Filter to policies applying to a specific agent' },
},
},
},
{
name: 'dashclaw_wait_for_approval',
description:
'Wait for a human to approve or deny a pending action in DashClaw Mission Control. ' +
'Call this after a guard decision returns "require_approval" or after recording an ' +
'action with status "pending_approval". Polls the action status until it changes. ' +
'Default timeout is 300 seconds (5 minutes).',
inputSchema: {
type: 'object',
properties: {
action_id: { type: 'string', description: 'The action ID to wait on (e.g., act_abc123)' },
timeout_seconds: { type: 'number', description: 'Max wait time (default 300)' },
poll_interval_seconds: { type: 'number', description: 'Polling frequency (default 3)' },
},
required: ['action_id'],
},
},
{
name: 'dashclaw_session_start',
description:
'Register this agent session with DashClaw. Creates a session record that groups all ' +
'subsequent actions for tracking and observability. Call this at the beginning of a task ' +
'to establish a governance boundary.',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string', description: 'Agent identifier (required)' },
workspace: { type: 'string', description: 'Workspace or project context' },
branch: { type: 'string', description: 'Git branch or task branch' },
},
required: ['agent_id'],
},
},
{
name: 'dashclaw_session_end',
description:
'Close a DashClaw session and update its status. Call this when the task is complete ' +
'or if the session needs to be marked as failed. Provides a clean lifecycle boundary ' +
'for governance reporting in Mission Control.',
inputSchema: {
type: 'object',
properties: {
session_id: { type: 'string', description: 'Session ID from dashclaw_session_start' },
status: { type: 'string', enum: ['completed', 'failed', 'cancelled'], description: 'Final session status' },
summary: { type: 'string', description: 'Brief description of what was accomplished' },
},
required: ['session_id', 'status'],
},
},
// --- Code Sessions: Optimal Files (Phase 6) ------------------------------
{
name: 'dashclaw_optimal_files_preview',
description:
'Preview the Optimal Files bundle DashClaw Code Sessions would generate for a given session. Returns the per-file plan with confidence, secret-scan, and overwrite-risk flags. Read-only — does NOT write to disk; pair with dashclaw_optimal_files_manifest to persist a chosen subset.',
inputSchema: {
type: 'object',
properties: {
session_id: { type: 'string', description: 'Code session id (cs_*) from /api/code-sessions/sessions/...' },
},
required: ['session_id'],
},
},
{
name: 'dashclaw_optimal_files_manifest',
description:
'Persist a write plan for selected Optimal Files entries. Returns { manifest_id, expires_at, apply_command }. The local CLI invokes `dashclaw code apply <manifest_id>` to apply the plan to disk. Manifest expires after 24h.',
inputSchema: {
type: 'object',
properties: {
session_id: { type: 'string', description: 'Code session id (cs_*)' },
selections: {
type: 'array',
description: 'Subset of paths from the preview to write. Each item: { path, mode?: "skip"|"side_by_side"|"merge"|"overwrite", overwrite?, acceptedHeadings?, acceptedBullets? }',
items: { type: 'object' },
},
},
required: ['session_id', 'selections'],
},
},
{
name: 'dashclaw_handoff_create',
description:
'Create a session handoff bundle for the next session of this agent to consume on start. ' +
'Call this when wrapping up — include a 1-2 sentence summary, any open loops, decisions made, ' +
'and freeform state you want the next session to see.',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string', description: 'Agent ID (override default)' },
project_id: { type: 'string', description: 'Optional project ID — handoff is project-scoped' },
bundle: {
type: 'object',
description: 'Handoff content: { summary, open_loops, decisions_made, state_snapshot, generated_at }',
},
},
required: ['bundle'],
},
},
{
name: 'dashclaw_handoff_latest',
description:
'Fetch the latest unconsumed session handoff for this agent (+ project, optional). ' +
'Call this on session start to pick up where the last session left off. Returns null if ' +
'no handoff is waiting.',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string' },
project_id: { type: 'string' },
},
},
},
{
name: 'dashclaw_handoff_consume',
description:
'Mark a handoff as consumed. Call after dashclaw_handoff_latest returns a bundle and you ' +
'have processed it. Idempotent.',
inputSchema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Handoff id (hf_*) from handoff_latest' },
session_id: { type: 'string', description: 'Optional current session id for provenance' },
},
required: ['id'],
},
},
{
name: 'dashclaw_secret_list',
description:
'List tracked secrets (metadata only — no values). Returns each entry with name, rotation ' +
'interval, last_rotated_at, and computed next_rotation_due.',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string', description: 'Optional — scope to this agent' },
},
},
},
{
name: 'dashclaw_secret_due',
description:
'List secrets coming due for rotation. Call this BEFORE acting on credentials. If a ' +
'credential you would use is in the result, flag the operator rather than proceeding.',
inputSchema: {
type: 'object',
properties: {
within_days: { type: 'integer', description: 'Lookahead window in days (default 14)' },
agent_id: { type: 'string' },
},
},
},
{
name: 'dashclaw_secret_mark_rotated',
description:
'Mark a tracked secret as rotated (sets last_rotated_at = now). Agents only call this if ' +
'the operator instructs; secret registration is an operator task.',
inputSchema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Secret id (sec_*)' },
},
required: ['id'],
},
},
{
name: 'dashclaw_skill_scan',
description:
'Run a static safety scan against the contents of an untrusted skill before loading it. ' +
'Returns findings (severity, file, line) and a passed boolean. If passed=false, do NOT load ' +
'the skill — show the findings to the operator.',
inputSchema: {
type: 'object',
properties: {
skill_name: { type: 'string' },
files: {
type: 'object',
description: 'Map of filename -> file content (string)',
},
},
required: ['skill_name', 'files'],
},
},
{
name: 'dashclaw_loop_add',
description:
'Register an open loop on a parent action — a commitment made in conversation that needs ' +
'follow-up. Use when you say "I will X later" so the loop is tracked outside of context. ' +
'Loops are action-scoped; action_id is required.',
inputSchema: {
type: 'object',
properties: {
action_id: { type: 'string', description: 'Parent action id (act_*) the loop attaches to' },
loop_type: { type: 'string', description: 'Category (e.g., follow_up, blocker, decision_pending)' },
description: { type: 'string' },
priority: { type: 'string', enum: ['low', 'medium', 'high', 'critical'], description: 'Priority (default medium)' },
owner: { type: 'string', description: 'Optional owner (agent or human handle)' },
},
required: ['action_id', 'loop_type', 'description'],
},
},
{
name: 'dashclaw_loop_list',
description:
'List open (or resolved) loops with optional filters. Use on session start to remember ' +
'what you promised to follow up on.',
inputSchema: {
type: 'object',
properties: {
action_id: { type: 'string', description: 'Filter by parent action' },
status: { type: 'string', enum: ['open', 'resolved', 'cancelled'] },
priority: { type: 'string', enum: ['low', 'medium', 'high', 'critical'] },
agent_id: { type: 'string', description: 'Filter by agent (joined via parent action)' },
from: { type: 'string', description: 'ISO timestamp lower bound (reserved)' },
to: { type: 'string', description: 'ISO timestamp upper bound (reserved)' },
},
},
},
{
name: 'dashclaw_loop_close',
description:
'Resolve an open loop. Call when the followed-up-on item is complete. Requires the loop_id ' +
'and a short resolution note.',
inputSchema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Loop id (loop_*)' },
resolution: { type: 'string', description: 'Short note describing how the loop was closed' },
},
required: ['id'],
},
},
{
name: 'dashclaw_learning_log',
description:
'Log a decision + outcome to the learning database. Use after making a non-obvious decision ' +
'so future sessions can recall the reasoning and outcome.',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string' },
decision: { type: 'string', description: 'What was decided' },
context: { type: 'string', description: 'Why this decision was made' },
outcome: { type: 'string', description: 'What happened (optional, can be updated later)' },
},
required: ['decision'],
},
},
{
name: 'dashclaw_learning_query',
description:
'Query the learning database for prior decisions and lessons. Use BEFORE making a decision ' +
'similar to one you might have made before.',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string' },
query: { type: 'string', description: 'Search text (matches decision/context)' },
limit: { type: 'integer', description: 'Max results (default 10)' },
},
},
},
{
name: 'dashclaw_decisions_recent',
description:
'Query the guardrail decisions ledger for recent governed actions. Filter by agent, action ' +
'type, decision verdict, or time window. Use for in-session retrospection — "what have I done ' +
'recently?"',
inputSchema: {
type: 'object',
properties: {
agent_id: { type: 'string' },
action_type: { type: 'string' },
decision: { type: 'string', enum: ['allow', 'warn', 'block', 'require_approval'] },
since: { type: 'string', description: 'ISO timestamp lower bound' },
limit: { type: 'integer', description: 'Max results (default 20)' },
},
},
},
];
/**
* Create tool handler functions bound to a DashClawClient instance.
* Each handler accepts input args and returns a JSON string (MCP text content).
* @param {import('./client.js').DashClawClient} client
* @returns {Object<string, function>}
*/
export function createToolHandlers(client) {
// Priority: server-configured agent_id (DASHCLAW_AGENT_ID / --agent-id /
// auto-derived from MCP clientInfo) wins over anything the LLM passes in the
// tool call. This is deliberate: agent identity is a governance primitive,
// and letting the LLM pick its own agent_id based on prompt context (e.g.
// it sees "smoke test" and picks "claude-mcp-smoketest") breaks attribution
// and lets a single misbehaving prompt impersonate a different agent. The
// input.agent_id field is preserved only as a last-resort fallback for
// configurations that intentionally run without a server-level default.
const agentId = (input) => client.agentId || input.agent_id;
return {
async dashclaw_optimal_files_preview(input) {
const result = await client.post(`/api/code-sessions/sessions/${encodeURIComponent(input.session_id)}/optimal-files/preview`, {}, { timeout: 20000 });
return JSON.stringify(result);
},
async dashclaw_optimal_files_manifest(input) {
const result = await client.post(`/api/code-sessions/sessions/${encodeURIComponent(input.session_id)}/optimal-files/manifest`,
{ selections: input.selections || [] }, { timeout: 20000 });
return JSON.stringify(result);
},
async dashclaw_guard(input) {
const result = await client.post('/api/guard', {
action_type: input.action_type,
declared_goal: input.declared_goal,
risk_score: input.risk_score,
agent_id: agentId(input),
systems_touched: input.systems_touched,
reversible: input.reversible,
}, { timeout: 10000 });
return JSON.stringify(result);
},
async dashclaw_record(input) {
const body = {
action_type: input.action_type,
declared_goal: input.declared_goal,
status: input.status,
risk_score: input.risk_score ?? 30,
agent_id: agentId(input),
reasoning: input.reasoning,
confidence: input.confidence,
systems_touched: input.systems_touched,
reversible: input.reversible,
output_summary: input.output_summary,
tokens_in: input.tokens_in,
tokens_out: input.tokens_out,
model: input.model,
cost_estimate: input.cost_estimate,
};
const result = await client.post('/api/actions', body, { timeout: 10000 });
return JSON.stringify(result);
},
async dashclaw_invoke(input) {
const result = await client.post(`/api/capabilities/${input.capability_id}/invoke`, {
agent_id: agentId(input),
declared_goal: input.declared_goal,
payload: input.payload,
}, { timeout: 30000 });
return JSON.stringify(result);
},
async dashclaw_capabilities_list(input) {
const result = await client.get('/api/capabilities', {
category: input.category,
risk_level: input.risk_level,
search: input.search,
}, { timeout: 10000 });
return JSON.stringify(result);
},
async dashclaw_policies_list(input) {
const result = await client.get('/api/policies', {
agent_id: input.agent_id,
}, { timeout: 10000 });
return JSON.stringify(result);
},
async dashclaw_wait_for_approval(input) {
const timeout = (input.timeout_seconds ?? 300) * 1000;
const interval = (input.poll_interval_seconds ?? 3) * 1000;
const start = Date.now();
while (Date.now() - start < timeout) {
const result = await client.get(`/api/actions/${input.action_id}`, {}, { timeout: 10000 });
const status = result?.action?.status;
if (status && status !== 'pending_approval') {
const approved = status === 'completed';
// Distinguish explicit operator denial (failed/cancelled) from
// a genuine approval. The JS and Python SDKs throw on denial;
// MCP can't throw through the tool channel, so surface a
// clear `denied:true` + reason instead of returning
// approved:false with no further signal.
const denied = !approved && (status === 'failed' || status === 'cancelled');
return JSON.stringify({
approved,
denied,
denial_reason: denied
? (result?.action?.error_message || `Operator marked action as ${status}`)
: null,
action: result.action,
waited_seconds: Math.round((Date.now() - start) / 1000),
});
}
await new Promise((r) => setTimeout(r, interval));
}
return JSON.stringify({
approved: false,
timed_out: true,
action: { status: 'pending_approval' },
waited_seconds: Math.round((Date.now() - start) / 1000),
});
},
async dashclaw_session_start(input) {
const result = await client.post('/api/sessions', {
agent_id: input.agent_id,
workspace: input.workspace,
branch: input.branch,
}, { timeout: 10000 });
return JSON.stringify(result);
},
async dashclaw_session_end(input) {
const result = await client.patch(`/api/sessions/${input.session_id}`, {
status: input.status,
summary: input.summary,
}, { timeout: 10000 });
return JSON.stringify(result);
},
async dashclaw_handoff_create(args) {
const res = await client.fetch('/api/handoffs', {
method: 'POST',
body: JSON.stringify({
agent_id: agentId(args),
project_id: args.project_id,
bundle: args.bundle,
}),
});
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_handoff_latest(args) {
const params = new URLSearchParams();
const aid = agentId(args);
if (aid) params.set('agent_id', aid);
if (args.project_id) params.set('project_id', args.project_id);
const res = await client.fetch(`/api/handoffs/latest?${params}`);
if (res.status === 404) return JSON.stringify(null);
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_handoff_consume(args) {
const res = await client.fetch(`/api/handoffs/${encodeURIComponent(args.id)}/consume`, {
method: 'POST',
body: JSON.stringify({ session_id: args.session_id }),
});
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_secret_list(args) {
const params = new URLSearchParams();
const aid = agentId(args);
if (aid) params.set('agent_id', aid);
const res = await client.fetch(`/api/secrets?${params}`);
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_secret_due(args) {
const params = new URLSearchParams();
if (args.within_days != null) params.set('within_days', String(args.within_days));
const aid = agentId(args);
if (aid) params.set('agent_id', aid);
const res = await client.fetch(`/api/secrets/rotation-due?${params}`);
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_secret_mark_rotated(args) {
const res = await client.fetch(`/api/secrets/${encodeURIComponent(args.id)}`, {
method: 'PATCH',
body: JSON.stringify({ last_rotated_at: new Date().toISOString() }),
});
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_skill_scan(args) {
const res = await client.fetch('/api/skills/scan', {
method: 'POST',
body: JSON.stringify({
skill_name: args.skill_name,
files: args.files,
}),
});
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_loop_add(args) {
const res = await client.fetch('/api/actions/loops', {
method: 'POST',
body: JSON.stringify({
action_id: args.action_id,
loop_type: args.loop_type,
description: args.description,
priority: args.priority,
owner: args.owner,
}),
});
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_loop_list(args) {
const params = new URLSearchParams();
if (args.action_id) params.set('action_id', args.action_id);
if (args.status) params.set('status', args.status);
if (args.priority) params.set('priority', args.priority);
const aid = agentId(args);
if (aid) params.set('agent_id', aid);
if (args.from) params.set('from', args.from);
if (args.to) params.set('to', args.to);
const res = await client.fetch(`/api/actions/loops?${params}`);
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_loop_close(args) {
const res = await client.fetch(`/api/actions/loops/${encodeURIComponent(args.id)}`, {
method: 'PATCH',
body: JSON.stringify({
status: 'resolved',
resolution: args.resolution || 'Closed by agent via dashclaw_loop_close',
}),
});
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_learning_log(args) {
const res = await client.fetch('/api/learning', {
method: 'POST',
body: JSON.stringify({
agent_id: agentId(args),
decision: args.decision,
context: args.context,
outcome: args.outcome,
}),
});
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_learning_query(args) {
const params = new URLSearchParams();
const aid = agentId(args);
if (aid) params.set('agent_id', aid);
if (args.query) params.set('q', args.query);
if (args.limit) params.set('limit', String(args.limit));
const res = await client.fetch(`/api/learning/lessons?${params}`);
const data = await res.json();
return JSON.stringify(data);
},
async dashclaw_decisions_recent(args) {
const params = new URLSearchParams();
const aid = agentId(args);
if (aid) params.set('agent_id', aid);
if (args.action_type) params.set('action_type', args.action_type);
if (args.decision) params.set('decision', args.decision);
if (args.since) params.set('since', args.since);
if (args.limit) params.set('limit', String(args.limit));
const res = await client.fetch(`/api/guard/decisions?${params}`);
const data = await res.json();
return JSON.stringify(data);
},
};
}