@actwith-ai/mcp-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/ACTWITH.md +152 -0
  2. package/README.md +290 -0
  3. package/dist/client.d.ts +866 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +959 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/index.d.ts +20 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +247 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/init.d.ts +10 -0
  12. package/dist/init.d.ts.map +1 -0
  13. package/dist/init.js +222 -0
  14. package/dist/init.js.map +1 -0
  15. package/dist/resources/index.d.ts +35 -0
  16. package/dist/resources/index.d.ts.map +1 -0
  17. package/dist/resources/index.js +292 -0
  18. package/dist/resources/index.js.map +1 -0
  19. package/dist/tools/artifacts.d.ts +12 -0
  20. package/dist/tools/artifacts.d.ts.map +1 -0
  21. package/dist/tools/artifacts.js +462 -0
  22. package/dist/tools/artifacts.js.map +1 -0
  23. package/dist/tools/contexts.d.ts +15 -0
  24. package/dist/tools/contexts.d.ts.map +1 -0
  25. package/dist/tools/contexts.js +188 -0
  26. package/dist/tools/contexts.js.map +1 -0
  27. package/dist/tools/discovery.d.ts +11 -0
  28. package/dist/tools/discovery.d.ts.map +1 -0
  29. package/dist/tools/discovery.js +249 -0
  30. package/dist/tools/discovery.js.map +1 -0
  31. package/dist/tools/identity.d.ts +15 -0
  32. package/dist/tools/identity.d.ts.map +1 -0
  33. package/dist/tools/identity.js +237 -0
  34. package/dist/tools/identity.js.map +1 -0
  35. package/dist/tools/index.d.ts +29 -0
  36. package/dist/tools/index.d.ts.map +1 -0
  37. package/dist/tools/index.js +228 -0
  38. package/dist/tools/index.js.map +1 -0
  39. package/dist/tools/memory.d.ts +11 -0
  40. package/dist/tools/memory.d.ts.map +1 -0
  41. package/dist/tools/memory.js +349 -0
  42. package/dist/tools/memory.js.map +1 -0
  43. package/dist/tools/patterns.d.ts +17 -0
  44. package/dist/tools/patterns.d.ts.map +1 -0
  45. package/dist/tools/patterns.js +874 -0
  46. package/dist/tools/patterns.js.map +1 -0
  47. package/dist/tools/reputation.d.ts +11 -0
  48. package/dist/tools/reputation.d.ts.map +1 -0
  49. package/dist/tools/reputation.js +175 -0
  50. package/dist/tools/reputation.js.map +1 -0
  51. package/dist/tools/tasks.d.ts +11 -0
  52. package/dist/tools/tasks.d.ts.map +1 -0
  53. package/dist/tools/tasks.js +549 -0
  54. package/dist/tools/tasks.js.map +1 -0
  55. package/dist/tools/topics.d.ts +13 -0
  56. package/dist/tools/topics.d.ts.map +1 -0
  57. package/dist/tools/topics.js +561 -0
  58. package/dist/tools/topics.js.map +1 -0
  59. package/dist/tools/workspace.d.ts +10 -0
  60. package/dist/tools/workspace.d.ts.map +1 -0
  61. package/dist/tools/workspace.js +183 -0
  62. package/dist/tools/workspace.js.map +1 -0
  63. package/package.json +59 -0
@@ -0,0 +1,874 @@
1
+ /**
2
+ * Pattern Tools
3
+ *
4
+ * MCP tools for work patterns:
5
+ * - list_patterns: List available patterns in space
6
+ * - start_pattern: Start a pattern instance
7
+ * - pattern_status: Check instance progress
8
+ * - join_pattern: Join as participant
9
+ * - advance_pattern: Move to next stage + submit handoff
10
+ * - handoff: Submit handoff for task
11
+ */
12
+ // Pattern tools
13
+ export const patternTools = [
14
+ {
15
+ name: "list_patterns",
16
+ description: "List available work patterns in the current space. Patterns are reusable templates for multi-agent coordination (Pipeline, Parallel, etc.).",
17
+ inputSchema: {
18
+ type: "object",
19
+ properties: {
20
+ type: {
21
+ type: "string",
22
+ description: "Filter by pattern type: pipeline, parallel, swarm, supervisor, or consensus",
23
+ enum: ["pipeline", "parallel", "swarm", "supervisor", "consensus"],
24
+ },
25
+ },
26
+ },
27
+ },
28
+ {
29
+ name: "start_pattern",
30
+ description: "Start a new instance of a work pattern. Creates tasks and sets up the coordination flow based on the pattern type.",
31
+ inputSchema: {
32
+ type: "object",
33
+ properties: {
34
+ pattern_id: {
35
+ type: "string",
36
+ description: "The ID of the pattern to start",
37
+ },
38
+ root_task_id: {
39
+ type: "string",
40
+ description: "Optional: Link this instance to an existing task",
41
+ },
42
+ initial_state: {
43
+ type: "object",
44
+ description: "Optional: Initial state/context for the instance",
45
+ },
46
+ deadline_at: {
47
+ type: "number",
48
+ description: "Optional: Unix timestamp deadline for time awareness (pattern will track elapsed time)",
49
+ },
50
+ },
51
+ required: ["pattern_id"],
52
+ },
53
+ },
54
+ {
55
+ name: "pattern_context",
56
+ description: "Get the accumulated stage context for a pattern instance. Shows completed stages, key decisions made, artifacts created, and any warnings. Use this to understand prior work before starting your stage.",
57
+ inputSchema: {
58
+ type: "object",
59
+ properties: {
60
+ instance_id: {
61
+ type: "string",
62
+ description: "The ID of the pattern instance",
63
+ },
64
+ },
65
+ required: ["instance_id"],
66
+ },
67
+ },
68
+ {
69
+ name: "pattern_status",
70
+ description: "Get the current status of a pattern instance, including progress, participants, and handoffs.",
71
+ inputSchema: {
72
+ type: "object",
73
+ properties: {
74
+ instance_id: {
75
+ type: "string",
76
+ description: "The ID of the pattern instance",
77
+ },
78
+ },
79
+ required: ["instance_id"],
80
+ },
81
+ },
82
+ {
83
+ name: "join_pattern",
84
+ description: "Join a pattern instance as a participant. Use auto_assign=true to automatically claim the current stage if eligible.",
85
+ inputSchema: {
86
+ type: "object",
87
+ properties: {
88
+ instance_id: {
89
+ type: "string",
90
+ description: "The ID of the pattern instance to join",
91
+ },
92
+ role: {
93
+ type: "string",
94
+ description: "Your role: worker (default), lead, or reviewer",
95
+ enum: ["worker", "lead", "reviewer"],
96
+ },
97
+ assigned_stage: {
98
+ type: "string",
99
+ description: "Optional: Request assignment to a specific stage (pipeline patterns)",
100
+ },
101
+ auto_assign: {
102
+ type: "boolean",
103
+ description: "Optional: Automatically claim the current stage if eligible (default: true)",
104
+ },
105
+ },
106
+ required: ["instance_id"],
107
+ },
108
+ },
109
+ {
110
+ name: "declare_capabilities",
111
+ description: "Declare your capabilities for capability-based stage assignment. Some stages require specific capabilities.",
112
+ inputSchema: {
113
+ type: "object",
114
+ properties: {
115
+ capabilities: {
116
+ type: "array",
117
+ items: { type: "string" },
118
+ description: "List of capabilities (e.g., 'code_review', 'testing', 'documentation', 'security_audit')",
119
+ },
120
+ },
121
+ required: ["capabilities"],
122
+ },
123
+ },
124
+ {
125
+ name: "claim_stage",
126
+ description: "Claim a specific stage in a pattern instance. Claims have a TTL and expire if not completed.",
127
+ inputSchema: {
128
+ type: "object",
129
+ properties: {
130
+ instance_id: {
131
+ type: "string",
132
+ description: "The ID of the pattern instance",
133
+ },
134
+ stage_name: {
135
+ type: "string",
136
+ description: "The name of the stage to claim",
137
+ },
138
+ },
139
+ required: ["instance_id", "stage_name"],
140
+ },
141
+ },
142
+ {
143
+ name: "available_stages",
144
+ description: "Get stages available for you to work on, showing which you can claim based on capabilities and current claims.",
145
+ inputSchema: {
146
+ type: "object",
147
+ properties: {
148
+ instance_id: {
149
+ type: "string",
150
+ description: "The ID of the pattern instance",
151
+ },
152
+ },
153
+ required: ["instance_id"],
154
+ },
155
+ },
156
+ {
157
+ name: "verify_stage",
158
+ description: "Verify stage completion criteria. Some stages require verification before advancement.",
159
+ inputSchema: {
160
+ type: "object",
161
+ properties: {
162
+ instance_id: {
163
+ type: "string",
164
+ description: "The ID of the pattern instance",
165
+ },
166
+ stage_name: {
167
+ type: "string",
168
+ description: "The name of the stage to verify",
169
+ },
170
+ test_output: {
171
+ type: "string",
172
+ description: "Optional: Output from automated tests",
173
+ },
174
+ comparison_output: {
175
+ type: "string",
176
+ description: "Optional: Output to compare against reference",
177
+ },
178
+ },
179
+ required: ["instance_id", "stage_name"],
180
+ },
181
+ },
182
+ {
183
+ name: "advance_pattern",
184
+ description: "Advance a pipeline pattern to its next stage. Include a handoff to provide context for the next participant.",
185
+ inputSchema: {
186
+ type: "object",
187
+ properties: {
188
+ instance_id: {
189
+ type: "string",
190
+ description: "The ID of the pattern instance",
191
+ },
192
+ task_id: {
193
+ type: "string",
194
+ description: "The task ID you completed for this stage",
195
+ },
196
+ handoff: {
197
+ type: "object",
198
+ description: "Handoff content for the next participant",
199
+ properties: {
200
+ summary: {
201
+ type: "string",
202
+ description: "Brief summary of what was accomplished",
203
+ },
204
+ status: {
205
+ type: "string",
206
+ description: "Status: completed, partial, or blocked",
207
+ enum: ["completed", "partial", "blocked"],
208
+ },
209
+ completed: {
210
+ type: "array",
211
+ items: { type: "string" },
212
+ description: "List of completed items/tasks",
213
+ },
214
+ next_steps: {
215
+ type: "array",
216
+ items: { type: "string" },
217
+ description: "Recommended next steps for the next participant",
218
+ },
219
+ blockers: {
220
+ type: "array",
221
+ items: { type: "string" },
222
+ description: "Optional: Any blockers or issues to address",
223
+ },
224
+ artifacts: {
225
+ type: "array",
226
+ items: { type: "string" },
227
+ description: "Optional: IDs of artifacts created",
228
+ },
229
+ context_links: {
230
+ type: "array",
231
+ items: { type: "string" },
232
+ description: "Optional: URLs/paths to relevant documentation",
233
+ },
234
+ relevant_files: {
235
+ type: "array",
236
+ items: { type: "string" },
237
+ description: "Optional: Files touched or created",
238
+ },
239
+ prior_decisions: {
240
+ type: "array",
241
+ items: {
242
+ type: "object",
243
+ properties: {
244
+ decision: { type: "string" },
245
+ rationale: { type: "string" },
246
+ },
247
+ },
248
+ description: "Optional: Key decisions made and their rationale",
249
+ },
250
+ change_impact_scope: {
251
+ type: "string",
252
+ description: "Optional: Scope of changes - which prior work might be affected",
253
+ },
254
+ },
255
+ required: ["summary", "status", "completed", "next_steps"],
256
+ },
257
+ },
258
+ required: ["instance_id", "handoff"],
259
+ },
260
+ },
261
+ {
262
+ name: "handoff",
263
+ description: "Submit a handoff for a task. Handoffs provide context and status when transferring work to another agent.",
264
+ inputSchema: {
265
+ type: "object",
266
+ properties: {
267
+ task_id: {
268
+ type: "string",
269
+ description: "The task ID this handoff is for",
270
+ },
271
+ instance_id: {
272
+ type: "string",
273
+ description: "Optional: Pattern instance ID if part of a pattern",
274
+ },
275
+ from_stage: {
276
+ type: "string",
277
+ description: "Optional: Stage this handoff is from",
278
+ },
279
+ to_stage: {
280
+ type: "string",
281
+ description: "Optional: Stage this handoff is to",
282
+ },
283
+ summary: {
284
+ type: "string",
285
+ description: "Brief summary of what was accomplished",
286
+ },
287
+ status: {
288
+ type: "string",
289
+ description: "Status: completed, partial, or blocked",
290
+ enum: ["completed", "partial", "blocked"],
291
+ },
292
+ completed: {
293
+ type: "array",
294
+ items: { type: "string" },
295
+ description: "List of completed items/tasks",
296
+ },
297
+ next_steps: {
298
+ type: "array",
299
+ items: { type: "string" },
300
+ description: "Recommended next steps",
301
+ },
302
+ blockers: {
303
+ type: "array",
304
+ items: { type: "string" },
305
+ description: "Optional: Any blockers or issues",
306
+ },
307
+ },
308
+ required: ["task_id", "summary", "status", "completed", "next_steps"],
309
+ },
310
+ },
311
+ // Tier 3: Parallel Work Quality
312
+ {
313
+ name: "compare_output",
314
+ description: "Compare your subtask output against the reference (oracle comparison). Use this to verify your work matches expectations before completing.",
315
+ inputSchema: {
316
+ type: "object",
317
+ properties: {
318
+ subtask_id: {
319
+ type: "string",
320
+ description: "The ID of the subtask to compare",
321
+ },
322
+ output: {
323
+ type: "string",
324
+ description: "Your output to compare against the reference",
325
+ },
326
+ },
327
+ required: ["subtask_id", "output"],
328
+ },
329
+ },
330
+ {
331
+ name: "get_comparisons",
332
+ description: "Get all subtask comparison results for an instance. Useful during aggregation to see which outputs matched and which had discrepancies.",
333
+ inputSchema: {
334
+ type: "object",
335
+ properties: {
336
+ instance_id: {
337
+ type: "string",
338
+ description: "The ID of the pattern instance",
339
+ },
340
+ },
341
+ required: ["instance_id"],
342
+ },
343
+ },
344
+ {
345
+ name: "get_golden_example",
346
+ description: "Get the golden example for a pattern. Shows sample input, expected output, and success criteria to guide your work.",
347
+ inputSchema: {
348
+ type: "object",
349
+ properties: {
350
+ pattern_id: {
351
+ type: "string",
352
+ description: "The ID of the pattern",
353
+ },
354
+ },
355
+ required: ["pattern_id"],
356
+ },
357
+ },
358
+ // Tier 4: Context & Regression Management
359
+ {
360
+ name: "check_time",
361
+ description: "Check time awareness for a pattern instance. Shows elapsed time, deadline proximity, stage timeout status, and any time-related warnings.",
362
+ inputSchema: {
363
+ type: "object",
364
+ properties: {
365
+ instance_id: {
366
+ type: "string",
367
+ description: "The ID of the pattern instance",
368
+ },
369
+ },
370
+ required: ["instance_id"],
371
+ },
372
+ },
373
+ {
374
+ name: "run_regression_tests",
375
+ description: "Run regression tests for a stage before advancing. Some stages require tests to pass before advancement.",
376
+ inputSchema: {
377
+ type: "object",
378
+ properties: {
379
+ instance_id: {
380
+ type: "string",
381
+ description: "The ID of the pattern instance",
382
+ },
383
+ stage_name: {
384
+ type: "string",
385
+ description: "The name of the stage to test",
386
+ },
387
+ test_outputs: {
388
+ type: "object",
389
+ description: "Map of test name to result: { 'test_name': { passed: true, output: '...' } }",
390
+ },
391
+ },
392
+ required: ["instance_id", "stage_name"],
393
+ },
394
+ },
395
+ {
396
+ name: "check_constraints",
397
+ description: "Check all advancement constraints (time limits, regression tests) before advancing a stage. Use this before advance_pattern to see if you're blocked.",
398
+ inputSchema: {
399
+ type: "object",
400
+ properties: {
401
+ instance_id: {
402
+ type: "string",
403
+ description: "The ID of the pattern instance",
404
+ },
405
+ stage_name: {
406
+ type: "string",
407
+ description: "The name of the stage to check",
408
+ },
409
+ test_outputs: {
410
+ type: "object",
411
+ description: "Optional: Test outputs if regression tests are defined",
412
+ },
413
+ },
414
+ required: ["instance_id", "stage_name"],
415
+ },
416
+ },
417
+ ];
418
+ // Tool name set for routing
419
+ export const PATTERN_TOOLS = new Set([
420
+ "list_patterns",
421
+ "start_pattern",
422
+ "pattern_context",
423
+ "pattern_status",
424
+ "join_pattern",
425
+ "declare_capabilities",
426
+ "claim_stage",
427
+ "available_stages",
428
+ "verify_stage",
429
+ "advance_pattern",
430
+ "handoff",
431
+ // Tier 3
432
+ "compare_output",
433
+ "get_comparisons",
434
+ "get_golden_example",
435
+ // Tier 4
436
+ "check_time",
437
+ "run_regression_tests",
438
+ "check_constraints",
439
+ ]);
440
+ // Tool handler
441
+ export async function handlePatternTool(client, name, args) {
442
+ switch (name) {
443
+ case "list_patterns": {
444
+ const result = await client.listPatterns(args.type);
445
+ return {
446
+ success: true,
447
+ count: result.length,
448
+ patterns: result.map((p) => ({
449
+ id: p.id,
450
+ name: p.name,
451
+ type: p.patternType,
452
+ usageCount: p.usageCount,
453
+ description: getPatternDescription(p.patternType),
454
+ })),
455
+ hint: result.length === 0
456
+ ? "No patterns found. Create one using the API or ask the space owner to set up patterns."
457
+ : `Use start_pattern with a pattern_id to start a new instance.`,
458
+ };
459
+ }
460
+ case "start_pattern": {
461
+ const patternId = args.pattern_id;
462
+ if (!patternId) {
463
+ throw new Error("pattern_id is required");
464
+ }
465
+ const result = await client.startPattern(patternId, args.root_task_id, args.initial_state, args.deadline_at);
466
+ return {
467
+ success: true,
468
+ instanceId: result.instanceId,
469
+ status: result.status,
470
+ currentStage: result.currentStage,
471
+ patternTopic: result.patternTopic,
472
+ tasks: result.tasks,
473
+ message: `Pattern instance started. ${result.tasks.length} task(s) created.`,
474
+ hint: `Use 'listen' with topic '${result.patternTopic}' to follow progress updates.`,
475
+ };
476
+ }
477
+ case "pattern_context": {
478
+ const instanceId = args.instance_id;
479
+ if (!instanceId) {
480
+ throw new Error("instance_id is required");
481
+ }
482
+ const result = await client.getPatternContext(instanceId);
483
+ return {
484
+ success: true,
485
+ instanceId,
486
+ patternTopic: result.patternTopic,
487
+ currentStage: result.currentStage,
488
+ deadlineAt: result.deadlineAt,
489
+ stageContext: {
490
+ completedStages: result.stageContext.completedStages,
491
+ keyDecisions: result.stageContext.keyDecisions,
492
+ artifacts: result.stageContext.artifacts,
493
+ warnings: result.stageContext.warnings,
494
+ },
495
+ hint: result.stageContext.completedStages.length > 0
496
+ ? `${result.stageContext.completedStages.length} stage(s) completed. Review the summaries and decisions before starting your work.`
497
+ : "No stages completed yet. You're working on the first stage.",
498
+ };
499
+ }
500
+ case "pattern_status": {
501
+ const instanceId = args.instance_id;
502
+ if (!instanceId) {
503
+ throw new Error("instance_id is required");
504
+ }
505
+ const result = await client.getPatternStatus(instanceId);
506
+ return {
507
+ success: true,
508
+ instance: {
509
+ id: result.instance.id,
510
+ status: result.instance.status,
511
+ currentStage: result.instance.currentStage,
512
+ currentStageIndex: result.instance.currentStageIndex,
513
+ startedAt: result.instance.startedAt,
514
+ completedAt: result.instance.completedAt,
515
+ },
516
+ pattern: {
517
+ id: result.pattern.id,
518
+ name: result.pattern.name,
519
+ type: result.pattern.patternType,
520
+ },
521
+ stages: result.stages?.map((s) => ({
522
+ name: s.name,
523
+ index: s.stageIndex,
524
+ description: s.description,
525
+ requiresApproval: s.requiresApproval,
526
+ })),
527
+ participants: result.participants,
528
+ subtasks: result.subtasks?.map((s) => ({
529
+ taskId: s.taskId,
530
+ type: s.subtaskType,
531
+ status: s.status,
532
+ })),
533
+ handoffs: result.handoffs.map((h) => ({
534
+ id: h.id,
535
+ fromStage: h.fromStage,
536
+ toStage: h.toStage,
537
+ summary: h.content.summary,
538
+ status: h.content.status,
539
+ })),
540
+ };
541
+ }
542
+ case "join_pattern": {
543
+ const instanceId = args.instance_id;
544
+ if (!instanceId) {
545
+ throw new Error("instance_id is required");
546
+ }
547
+ const agentId = await client.getAgentId();
548
+ const autoAssign = args.auto_assign !== false; // Default to true
549
+ const result = await client.joinPattern(instanceId, {
550
+ participantId: agentId,
551
+ participantType: "agent",
552
+ role: args.role,
553
+ assignedStage: args.assigned_stage,
554
+ autoAssign,
555
+ });
556
+ if (result.assignedStage) {
557
+ return {
558
+ success: true,
559
+ message: `Joined and claimed stage: ${result.assignedStage}`,
560
+ participantId: result.participantId,
561
+ assignedStage: result.assignedStage,
562
+ claimExpiresAt: result.claimExpiresAt,
563
+ capabilitiesMatched: result.capabilitiesMatched,
564
+ hint: `Stage claimed until ${result.claimExpiresAt ? new Date(result.claimExpiresAt * 1000).toISOString() : "unknown"}. Complete your work and use advance_pattern.`,
565
+ };
566
+ }
567
+ return {
568
+ success: true,
569
+ message: "Joined pattern instance",
570
+ participantId: result.participantId,
571
+ hint: "Use available_stages to see what you can work on, or claim_stage to claim a specific stage.",
572
+ };
573
+ }
574
+ case "declare_capabilities": {
575
+ const capabilities = args.capabilities;
576
+ if (!capabilities || !Array.isArray(capabilities)) {
577
+ throw new Error("capabilities array is required");
578
+ }
579
+ const agentId = await client.getAgentId();
580
+ await client.declareCapabilities(agentId, capabilities);
581
+ return {
582
+ success: true,
583
+ message: "Capabilities declared",
584
+ capabilities,
585
+ hint: "You can now join patterns that require these capabilities.",
586
+ };
587
+ }
588
+ case "claim_stage": {
589
+ const instanceId = args.instance_id;
590
+ const stageName = args.stage_name;
591
+ if (!instanceId || !stageName) {
592
+ throw new Error("instance_id and stage_name are required");
593
+ }
594
+ const agentId = await client.getAgentId();
595
+ const result = await client.claimStage(instanceId, agentId, stageName);
596
+ return {
597
+ success: true,
598
+ message: `Claimed stage: ${stageName}`,
599
+ stageName: result.stageName,
600
+ claimExpiresAt: result.claimExpiresAt,
601
+ hint: `Claim expires at ${new Date(result.claimExpiresAt * 1000).toISOString()}. Complete your work before then.`,
602
+ };
603
+ }
604
+ case "available_stages": {
605
+ const instanceId = args.instance_id;
606
+ if (!instanceId) {
607
+ throw new Error("instance_id is required");
608
+ }
609
+ const agentId = await client.getAgentId();
610
+ const result = await client.getAvailableStages(instanceId, agentId);
611
+ const claimableStages = result.stages.filter((s) => s.canClaim);
612
+ return {
613
+ success: true,
614
+ currentStage: result.currentStage,
615
+ stages: result.stages.map((s) => ({
616
+ name: s.stageName,
617
+ index: s.stageIndex,
618
+ isCurrent: s.isCurrent,
619
+ canClaim: s.canClaim,
620
+ missingCapabilities: s.missingCapabilities,
621
+ })),
622
+ hint: claimableStages.length > 0
623
+ ? `You can claim: ${claimableStages.map((s) => s.stageName).join(", ")}`
624
+ : "No stages available to claim. Check if you have the required capabilities.",
625
+ };
626
+ }
627
+ case "verify_stage": {
628
+ const instanceId = args.instance_id;
629
+ const stageName = args.stage_name;
630
+ if (!instanceId || !stageName) {
631
+ throw new Error("instance_id and stage_name are required");
632
+ }
633
+ const result = await client.verifyStage(instanceId, stageName, {
634
+ testOutput: args.test_output,
635
+ comparisonOutput: args.comparison_output,
636
+ });
637
+ return {
638
+ success: true,
639
+ passed: result.passed,
640
+ verificationType: result.verificationType,
641
+ details: result.details,
642
+ failureReason: result.failureReason,
643
+ hint: result.passed
644
+ ? "Verification passed. You can now advance the pattern."
645
+ : `Verification failed: ${result.failureReason}`,
646
+ };
647
+ }
648
+ case "advance_pattern": {
649
+ const instanceId = args.instance_id;
650
+ if (!instanceId) {
651
+ throw new Error("instance_id is required");
652
+ }
653
+ const handoffInput = args.handoff;
654
+ if (!handoffInput) {
655
+ throw new Error("handoff is required");
656
+ }
657
+ const agentId = await client.getAgentId();
658
+ const result = await client.advancePattern(instanceId, {
659
+ agentId,
660
+ taskId: args.task_id,
661
+ handoff: {
662
+ summary: handoffInput.summary,
663
+ status: handoffInput.status,
664
+ completed: handoffInput.completed,
665
+ nextSteps: handoffInput.next_steps,
666
+ blockers: handoffInput.blockers,
667
+ artifacts: handoffInput.artifacts,
668
+ contextLinks: handoffInput.context_links,
669
+ relevantFiles: handoffInput.relevant_files,
670
+ priorDecisions: handoffInput.prior_decisions,
671
+ changeImpactScope: handoffInput.change_impact_scope,
672
+ },
673
+ });
674
+ if (result.completed) {
675
+ return {
676
+ success: true,
677
+ message: "Pattern completed!",
678
+ completed: true,
679
+ };
680
+ }
681
+ if (result.requiresApproval) {
682
+ return {
683
+ success: true,
684
+ message: "Stage completed, awaiting approval from space owner/admin before advancing.",
685
+ requiresApproval: true,
686
+ };
687
+ }
688
+ return {
689
+ success: true,
690
+ message: `Advanced to next stage: ${result.nextStage}`,
691
+ nextStage: result.nextStage,
692
+ advanced: true,
693
+ };
694
+ }
695
+ case "handoff": {
696
+ const taskId = args.task_id;
697
+ if (!taskId) {
698
+ throw new Error("task_id is required");
699
+ }
700
+ const agentId = await client.getAgentId();
701
+ const result = await client.submitHandoff({
702
+ taskId,
703
+ instanceId: args.instance_id,
704
+ fromStage: args.from_stage,
705
+ toStage: args.to_stage,
706
+ agentId,
707
+ content: {
708
+ summary: args.summary,
709
+ status: args.status,
710
+ completed: args.completed,
711
+ nextSteps: args.next_steps,
712
+ blockers: args.blockers,
713
+ },
714
+ });
715
+ return {
716
+ success: true,
717
+ handoffId: result.id,
718
+ message: "Handoff submitted successfully",
719
+ hint: "The next agent can see this handoff when they claim the task.",
720
+ };
721
+ }
722
+ // Tier 3: Parallel Work Quality
723
+ case "compare_output": {
724
+ const subtaskId = args.subtask_id;
725
+ const output = args.output;
726
+ if (!subtaskId || !output) {
727
+ throw new Error("subtask_id and output are required");
728
+ }
729
+ const result = await client.compareSubtaskOutput(subtaskId, output);
730
+ return {
731
+ success: true,
732
+ matches: result.matches,
733
+ comparisonMode: result.comparisonMode,
734
+ discrepancies: result.discrepancies,
735
+ similarity: result.similarity,
736
+ hint: result.matches
737
+ ? "Output matches reference. You can complete this subtask."
738
+ : `Output does not match: ${result.discrepancies?.join(", ")}`,
739
+ };
740
+ }
741
+ case "get_comparisons": {
742
+ const instanceId = args.instance_id;
743
+ if (!instanceId) {
744
+ throw new Error("instance_id is required");
745
+ }
746
+ const result = await client.getSubtaskComparisons(instanceId);
747
+ const passedCount = result.comparisons.filter((c) => !c.comparisonResult || c.comparisonResult.matches).length;
748
+ return {
749
+ success: true,
750
+ allPassed: result.allPassed,
751
+ comparisons: result.comparisons.map((c) => ({
752
+ subtaskId: c.subtaskId,
753
+ status: c.status,
754
+ matches: c.comparisonResult?.matches,
755
+ discrepancies: c.comparisonResult?.discrepancies,
756
+ })),
757
+ boundaryWarnings: result.boundaryWarnings,
758
+ summary: `${passedCount}/${result.comparisons.length} subtasks passed comparison`,
759
+ };
760
+ }
761
+ case "get_golden_example": {
762
+ const patternId = args.pattern_id;
763
+ if (!patternId) {
764
+ throw new Error("pattern_id is required");
765
+ }
766
+ const result = await client.getGoldenExample(patternId);
767
+ if (!result.goldenExample) {
768
+ return {
769
+ success: true,
770
+ message: "No golden example defined for this pattern",
771
+ decompositionGuidance: result.decompositionGuidance,
772
+ };
773
+ }
774
+ return {
775
+ success: true,
776
+ goldenExample: result.goldenExample,
777
+ decompositionGuidance: result.decompositionGuidance,
778
+ hint: "Use this as a reference for expected input/output format and success criteria.",
779
+ };
780
+ }
781
+ // Tier 4: Context & Regression Management
782
+ case "check_time": {
783
+ const instanceId = args.instance_id;
784
+ if (!instanceId) {
785
+ throw new Error("instance_id is required");
786
+ }
787
+ const result = await client.getTimeAwareness(instanceId);
788
+ const formatTime = (seconds) => {
789
+ if (seconds < 60)
790
+ return `${seconds}s`;
791
+ if (seconds < 3600)
792
+ return `${Math.floor(seconds / 60)}m`;
793
+ return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
794
+ };
795
+ return {
796
+ success: true,
797
+ elapsed: formatTime(result.elapsedSeconds),
798
+ remaining: result.remainingSeconds
799
+ ? formatTime(result.remainingSeconds)
800
+ : undefined,
801
+ isOverdue: result.isOverdue,
802
+ isStageTimedOut: result.isStageTimedOut,
803
+ warnings: result.warnings,
804
+ hint: result.warnings.length > 0
805
+ ? `Time warnings: ${result.warnings.join("; ")}`
806
+ : "No time constraints exceeded.",
807
+ };
808
+ }
809
+ case "run_regression_tests": {
810
+ const instanceId = args.instance_id;
811
+ const stageName = args.stage_name;
812
+ if (!instanceId || !stageName) {
813
+ throw new Error("instance_id and stage_name are required");
814
+ }
815
+ const result = await client.runRegressionTests(instanceId, stageName, args.test_outputs);
816
+ return {
817
+ success: true,
818
+ passed: result.passed,
819
+ testsRun: result.testsRun,
820
+ testsPassed: result.testsPassed,
821
+ testsFailed: result.testsFailed,
822
+ results: result.results,
823
+ hint: result.passed
824
+ ? result.testsRun > 0
825
+ ? `All ${result.testsRun} tests passed. You can advance.`
826
+ : "No regression tests defined for this stage."
827
+ : `${result.testsFailed} test(s) failed. Fix issues before advancing.`,
828
+ };
829
+ }
830
+ case "check_constraints": {
831
+ const instanceId = args.instance_id;
832
+ const stageName = args.stage_name;
833
+ if (!instanceId || !stageName) {
834
+ throw new Error("instance_id and stage_name are required");
835
+ }
836
+ const result = await client.checkAdvancementConstraints(instanceId, stageName, args.test_outputs);
837
+ return {
838
+ success: true,
839
+ canAdvance: result.canAdvance,
840
+ blockedBy: result.blockedBy,
841
+ timeWarnings: result.timeAwareness.warnings,
842
+ regressionTests: result.regressionTests
843
+ ? {
844
+ passed: result.regressionTests.passed,
845
+ summary: `${result.regressionTests.testsPassed}/${result.regressionTests.testsRun} passed`,
846
+ }
847
+ : undefined,
848
+ hint: result.canAdvance
849
+ ? "All constraints passed. You can use advance_pattern."
850
+ : `Blocked: ${result.blockedBy.join("; ")}`,
851
+ };
852
+ }
853
+ default:
854
+ throw new Error(`Unknown pattern tool: ${name}`);
855
+ }
856
+ }
857
+ // Helper function for pattern descriptions
858
+ function getPatternDescription(type) {
859
+ switch (type) {
860
+ case "pipeline":
861
+ return "Sequential stages: each stage completes before the next begins";
862
+ case "parallel":
863
+ return "Concurrent subtasks: multiple tasks run simultaneously, then aggregate";
864
+ case "swarm":
865
+ return "Open collaboration: agents freely claim and contribute";
866
+ case "supervisor":
867
+ return "Delegated work: a lead agent distributes and reviews work";
868
+ case "consensus":
869
+ return "Group decision: multiple agents must agree before proceeding";
870
+ default:
871
+ return "Multi-agent coordination pattern";
872
+ }
873
+ }
874
+ //# sourceMappingURL=patterns.js.map