opencode-swarm-plugin 0.23.6 → 0.24.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/dist/plugin.js CHANGED
@@ -16973,7 +16973,7 @@ WD9f
16973
16973
 
16974
16974
  // ../../node_modules/.bun/ioredis@5.8.2/node_modules/ioredis/built/utils/index.js
16975
16975
  var require_utils2 = __commonJS((exports) => {
16976
- var __dirname = "/home/runner/work/opencode-swarm-plugin/opencode-swarm-plugin/node_modules/.bun/ioredis@5.8.2/node_modules/ioredis/built/utils";
16976
+ var __dirname = "/home/runner/work/swarm-tools/swarm-tools/node_modules/.bun/ioredis@5.8.2/node_modules/ioredis/built/utils";
16977
16977
  Object.defineProperty(exports, "__esModule", { value: true });
16978
16978
  exports.noop = exports.defaults = exports.Debug = exports.getPackageMeta = exports.zipMap = exports.CONNECTION_CLOSED_ERROR_MSG = exports.shuffle = exports.sample = exports.resolveTLSProfile = exports.parseURL = exports.optimizeErrorStack = exports.toArg = exports.convertMapToArray = exports.convertObjectToArray = exports.timeout = exports.packObject = exports.isInt = exports.wrapMultiResult = exports.convertBufferToString = undefined;
16979
16979
  var fs_1 = __require("fs");
@@ -17203,7 +17203,7 @@ var require_utils2 = __commonJS((exports) => {
17203
17203
 
17204
17204
  // ../../node_modules/.bun/ioredis@5.8.2/node_modules/ioredis/built/Command.js
17205
17205
  var require_Command = __commonJS((exports) => {
17206
- var __dirname = "/home/runner/work/opencode-swarm-plugin/opencode-swarm-plugin/node_modules/.bun/ioredis@5.8.2/node_modules/ioredis/built";
17206
+ var __dirname = "/home/runner/work/swarm-tools/swarm-tools/node_modules/.bun/ioredis@5.8.2/node_modules/ioredis/built";
17207
17207
  Object.defineProperty(exports, "__esModule", { value: true });
17208
17208
  var commands_1 = require_built();
17209
17209
  var calculateSlot = require_lib();
@@ -26174,6 +26174,7 @@ import {
26174
26174
  isAbsolute,
26175
26175
  sep
26176
26176
  } from "path";
26177
+ import { fileURLToPath } from "url";
26177
26178
  function setSkillsProjectDirectory(dir) {
26178
26179
  skillsProjectDirectory = dir;
26179
26180
  skillsCache = null;
@@ -26220,8 +26221,13 @@ function getClaudeGlobalSkillsDir() {
26220
26221
  return join4(home, ".claude", "skills");
26221
26222
  }
26222
26223
  function getPackageSkillsDir() {
26223
- const currentDir = new URL(".", import.meta.url).pathname;
26224
- return join4(currentDir, "..", "global-skills");
26224
+ try {
26225
+ const currentFilePath = fileURLToPath(import.meta.url);
26226
+ return join4(dirname2(currentFilePath), "..", "global-skills");
26227
+ } catch {
26228
+ const currentDir = decodeURIComponent(new URL(".", import.meta.url).pathname);
26229
+ return join4(currentDir, "..", "global-skills");
26230
+ }
26225
26231
  }
26226
26232
  async function findSkillFiles(baseDir) {
26227
26233
  const skillFiles = [];
@@ -27404,6 +27410,183 @@ var QuerySwarmContextsArgsSchema = exports_external.object({
27404
27410
  strategy: SwarmStrategySchema.optional(),
27405
27411
  has_errors: exports_external.boolean().optional()
27406
27412
  });
27413
+ // src/schemas/bead-events.ts
27414
+ init_zod();
27415
+ var BaseBeadEventSchema = exports_external.object({
27416
+ id: exports_external.number().optional(),
27417
+ type: exports_external.string(),
27418
+ project_key: exports_external.string(),
27419
+ timestamp: exports_external.number(),
27420
+ sequence: exports_external.number().optional()
27421
+ });
27422
+ var BeadCreatedEventSchema = BaseBeadEventSchema.extend({
27423
+ type: exports_external.literal("bead_created"),
27424
+ bead_id: exports_external.string(),
27425
+ title: exports_external.string(),
27426
+ description: exports_external.string().optional(),
27427
+ issue_type: BeadTypeSchema,
27428
+ priority: exports_external.number().int().min(0).max(3),
27429
+ parent_id: exports_external.string().optional(),
27430
+ created_by: exports_external.string().optional(),
27431
+ metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
27432
+ });
27433
+ var BeadUpdatedEventSchema = BaseBeadEventSchema.extend({
27434
+ type: exports_external.literal("bead_updated"),
27435
+ bead_id: exports_external.string(),
27436
+ updated_by: exports_external.string().optional(),
27437
+ changes: exports_external.object({
27438
+ title: exports_external.object({
27439
+ old: exports_external.string(),
27440
+ new: exports_external.string()
27441
+ }).optional(),
27442
+ description: exports_external.object({
27443
+ old: exports_external.string(),
27444
+ new: exports_external.string()
27445
+ }).optional(),
27446
+ priority: exports_external.object({
27447
+ old: exports_external.number(),
27448
+ new: exports_external.number()
27449
+ }).optional()
27450
+ })
27451
+ });
27452
+ var BeadStatusChangedEventSchema = BaseBeadEventSchema.extend({
27453
+ type: exports_external.literal("bead_status_changed"),
27454
+ bead_id: exports_external.string(),
27455
+ from_status: BeadStatusSchema,
27456
+ to_status: BeadStatusSchema,
27457
+ changed_by: exports_external.string().optional(),
27458
+ reason: exports_external.string().optional()
27459
+ });
27460
+ var BeadClosedEventSchema = BaseBeadEventSchema.extend({
27461
+ type: exports_external.literal("bead_closed"),
27462
+ bead_id: exports_external.string(),
27463
+ reason: exports_external.string(),
27464
+ closed_by: exports_external.string().optional(),
27465
+ files_touched: exports_external.array(exports_external.string()).optional(),
27466
+ duration_ms: exports_external.number().optional()
27467
+ });
27468
+ var BeadReopenedEventSchema = BaseBeadEventSchema.extend({
27469
+ type: exports_external.literal("bead_reopened"),
27470
+ bead_id: exports_external.string(),
27471
+ reason: exports_external.string().optional(),
27472
+ reopened_by: exports_external.string().optional()
27473
+ });
27474
+ var BeadDeletedEventSchema = BaseBeadEventSchema.extend({
27475
+ type: exports_external.literal("bead_deleted"),
27476
+ bead_id: exports_external.string(),
27477
+ reason: exports_external.string().optional(),
27478
+ deleted_by: exports_external.string().optional()
27479
+ });
27480
+ var BeadDependencyAddedEventSchema = BaseBeadEventSchema.extend({
27481
+ type: exports_external.literal("bead_dependency_added"),
27482
+ bead_id: exports_external.string(),
27483
+ dependency: BeadDependencySchema,
27484
+ added_by: exports_external.string().optional(),
27485
+ reason: exports_external.string().optional()
27486
+ });
27487
+ var BeadDependencyRemovedEventSchema = BaseBeadEventSchema.extend({
27488
+ type: exports_external.literal("bead_dependency_removed"),
27489
+ bead_id: exports_external.string(),
27490
+ dependency: BeadDependencySchema,
27491
+ removed_by: exports_external.string().optional(),
27492
+ reason: exports_external.string().optional()
27493
+ });
27494
+ var BeadLabelAddedEventSchema = BaseBeadEventSchema.extend({
27495
+ type: exports_external.literal("bead_label_added"),
27496
+ bead_id: exports_external.string(),
27497
+ label: exports_external.string(),
27498
+ added_by: exports_external.string().optional()
27499
+ });
27500
+ var BeadLabelRemovedEventSchema = BaseBeadEventSchema.extend({
27501
+ type: exports_external.literal("bead_label_removed"),
27502
+ bead_id: exports_external.string(),
27503
+ label: exports_external.string(),
27504
+ removed_by: exports_external.string().optional()
27505
+ });
27506
+ var BeadCommentAddedEventSchema = BaseBeadEventSchema.extend({
27507
+ type: exports_external.literal("bead_comment_added"),
27508
+ bead_id: exports_external.string(),
27509
+ comment_id: exports_external.number().optional(),
27510
+ author: exports_external.string(),
27511
+ body: exports_external.string(),
27512
+ parent_comment_id: exports_external.number().optional(),
27513
+ metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
27514
+ });
27515
+ var BeadCommentUpdatedEventSchema = BaseBeadEventSchema.extend({
27516
+ type: exports_external.literal("bead_comment_updated"),
27517
+ bead_id: exports_external.string(),
27518
+ comment_id: exports_external.number(),
27519
+ old_body: exports_external.string(),
27520
+ new_body: exports_external.string(),
27521
+ updated_by: exports_external.string()
27522
+ });
27523
+ var BeadCommentDeletedEventSchema = BaseBeadEventSchema.extend({
27524
+ type: exports_external.literal("bead_comment_deleted"),
27525
+ bead_id: exports_external.string(),
27526
+ comment_id: exports_external.number(),
27527
+ deleted_by: exports_external.string(),
27528
+ reason: exports_external.string().optional()
27529
+ });
27530
+ var BeadEpicChildAddedEventSchema = BaseBeadEventSchema.extend({
27531
+ type: exports_external.literal("bead_epic_child_added"),
27532
+ bead_id: exports_external.string(),
27533
+ child_id: exports_external.string(),
27534
+ child_index: exports_external.number().optional(),
27535
+ added_by: exports_external.string().optional()
27536
+ });
27537
+ var BeadEpicChildRemovedEventSchema = BaseBeadEventSchema.extend({
27538
+ type: exports_external.literal("bead_epic_child_removed"),
27539
+ bead_id: exports_external.string(),
27540
+ child_id: exports_external.string(),
27541
+ removed_by: exports_external.string().optional(),
27542
+ reason: exports_external.string().optional()
27543
+ });
27544
+ var BeadEpicClosureEligibleEventSchema = BaseBeadEventSchema.extend({
27545
+ type: exports_external.literal("bead_epic_closure_eligible"),
27546
+ bead_id: exports_external.string(),
27547
+ child_ids: exports_external.array(exports_external.string()),
27548
+ total_duration_ms: exports_external.number().optional(),
27549
+ all_files_touched: exports_external.array(exports_external.string()).optional()
27550
+ });
27551
+ var BeadAssignedEventSchema = BaseBeadEventSchema.extend({
27552
+ type: exports_external.literal("bead_assigned"),
27553
+ bead_id: exports_external.string(),
27554
+ agent_name: exports_external.string(),
27555
+ task_description: exports_external.string().optional()
27556
+ });
27557
+ var BeadWorkStartedEventSchema = BaseBeadEventSchema.extend({
27558
+ type: exports_external.literal("bead_work_started"),
27559
+ bead_id: exports_external.string(),
27560
+ agent_name: exports_external.string(),
27561
+ reserved_files: exports_external.array(exports_external.string()).optional()
27562
+ });
27563
+ var BeadCompactedEventSchema = BaseBeadEventSchema.extend({
27564
+ type: exports_external.literal("bead_compacted"),
27565
+ bead_id: exports_external.string(),
27566
+ events_archived: exports_external.number(),
27567
+ new_start_sequence: exports_external.number()
27568
+ });
27569
+ var BeadEventSchema = exports_external.discriminatedUnion("type", [
27570
+ BeadCreatedEventSchema,
27571
+ BeadUpdatedEventSchema,
27572
+ BeadStatusChangedEventSchema,
27573
+ BeadClosedEventSchema,
27574
+ BeadReopenedEventSchema,
27575
+ BeadDeletedEventSchema,
27576
+ BeadDependencyAddedEventSchema,
27577
+ BeadDependencyRemovedEventSchema,
27578
+ BeadLabelAddedEventSchema,
27579
+ BeadLabelRemovedEventSchema,
27580
+ BeadCommentAddedEventSchema,
27581
+ BeadCommentUpdatedEventSchema,
27582
+ BeadCommentDeletedEventSchema,
27583
+ BeadEpicChildAddedEventSchema,
27584
+ BeadEpicChildRemovedEventSchema,
27585
+ BeadEpicClosureEligibleEventSchema,
27586
+ BeadAssignedEventSchema,
27587
+ BeadWorkStartedEventSchema,
27588
+ BeadCompactedEventSchema
27589
+ ]);
27407
27590
  // src/beads.ts
27408
27591
  import { createEvent, appendEvent } from "swarm-mail";
27409
27592
  var beadsWorkingDirectory = null;
@@ -30530,10 +30713,222 @@ ${subagentInstructions}`;
30530
30713
  }, null, 2);
30531
30714
  }
30532
30715
  });
30716
+ var swarm_plan_interactive = tool({
30717
+ description: "Interactive planning phase with Socratic questioning before decomposition. Supports multiple modes from full interactive to auto-proceed.",
30718
+ args: {
30719
+ task: tool.schema.string().min(1).describe("The task to plan"),
30720
+ mode: tool.schema.enum(["socratic", "fast", "auto", "confirm-only"]).default("socratic").describe("Planning mode: socratic (full), fast (skip questions), auto (minimal), confirm-only (single yes/no)"),
30721
+ context: tool.schema.string().optional().describe("Optional additional context about the task"),
30722
+ user_response: tool.schema.string().optional().describe("User's response to a previous question (for multi-turn socratic mode)"),
30723
+ phase: tool.schema.enum(["questioning", "alternatives", "recommendation", "ready"]).optional().describe("Current planning phase (for resuming multi-turn interaction)")
30724
+ },
30725
+ async execute(args) {
30726
+ const { selectStrategy: selectStrategy2, formatStrategyGuidelines: formatStrategyGuidelines2, STRATEGIES: STRATEGIES2 } = await Promise.resolve().then(() => (init_swarm_strategies(), exports_swarm_strategies));
30727
+ const { formatMemoryQueryForDecomposition: formatMemoryQueryForDecomposition2 } = await Promise.resolve().then(() => (init_learning(), exports_learning));
30728
+ const currentPhase = args.phase || "questioning";
30729
+ const mode = args.mode || "socratic";
30730
+ let memoryContext = "";
30731
+ let codebaseContext = {};
30732
+ try {
30733
+ const memoryQuery = formatMemoryQueryForDecomposition2(args.task, 3);
30734
+ memoryContext = `[Memory Query Instruction]
30735
+ ${memoryQuery.instruction}
30736
+ Query: "${memoryQuery.query}"
30737
+ Limit: ${memoryQuery.limit}`;
30738
+ } catch (error45) {
30739
+ console.warn("[swarm_plan_interactive] Memory query formatting failed:", error45);
30740
+ }
30741
+ try {
30742
+ const gitResult = await Bun.$`git status --short`.quiet().nothrow();
30743
+ if (gitResult.exitCode === 0) {
30744
+ codebaseContext.git_status = gitResult.stdout.toString().trim();
30745
+ }
30746
+ } catch (error45) {}
30747
+ if (mode === "fast") {
30748
+ const strategyResult = selectStrategy2(args.task);
30749
+ const guidelines = formatStrategyGuidelines2(strategyResult.strategy);
30750
+ const output = {
30751
+ mode: "fast",
30752
+ phase: "ready",
30753
+ recommendation: {
30754
+ approach: strategyResult.strategy,
30755
+ reasoning: `${strategyResult.reasoning}
30756
+
30757
+ ${guidelines}`
30758
+ },
30759
+ memory_context: memoryContext || undefined,
30760
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30761
+ ready_to_decompose: true,
30762
+ next_action: "Proceed to swarm_decompose or swarm_delegate_planning"
30763
+ };
30764
+ return JSON.stringify(output, null, 2);
30765
+ }
30766
+ if (mode === "auto") {
30767
+ const strategyResult = selectStrategy2(args.task);
30768
+ const output = {
30769
+ mode: "auto",
30770
+ phase: "ready",
30771
+ recommendation: {
30772
+ approach: strategyResult.strategy,
30773
+ reasoning: `Auto-selected based on task keywords: ${strategyResult.reasoning}`
30774
+ },
30775
+ memory_context: memoryContext || undefined,
30776
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30777
+ ready_to_decompose: true,
30778
+ next_action: "Auto-proceeding to decomposition"
30779
+ };
30780
+ return JSON.stringify(output, null, 2);
30781
+ }
30782
+ if (mode === "confirm-only") {
30783
+ const output = {
30784
+ mode: "confirm-only",
30785
+ phase: "ready",
30786
+ recommendation: {
30787
+ approach: "Will generate decomposition for your review",
30788
+ reasoning: "Use swarm_delegate_planning to generate the plan, then present it for yes/no confirmation"
30789
+ },
30790
+ memory_context: memoryContext || undefined,
30791
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30792
+ ready_to_decompose: false,
30793
+ next_action: "Call swarm_delegate_planning, then show result and ask for confirmation"
30794
+ };
30795
+ return JSON.stringify(output, null, 2);
30796
+ }
30797
+ if (currentPhase === "questioning") {
30798
+ const taskLower = args.task.toLowerCase();
30799
+ const questions = [];
30800
+ const isVague = {
30801
+ noFiles: !taskLower.includes("src/") && !taskLower.includes("file"),
30802
+ vagueVerb: taskLower.includes("improve") || taskLower.includes("fix") || taskLower.includes("update") || taskLower.includes("make better"),
30803
+ noSuccessCriteria: !taskLower.includes("test") && !taskLower.includes("verify")
30804
+ };
30805
+ if (isVague.noFiles) {
30806
+ questions.push({
30807
+ question: "Which part of the codebase should this change affect?",
30808
+ options: [
30809
+ "Core functionality (src/)",
30810
+ "UI components (components/)",
30811
+ "API routes (app/api/)",
30812
+ "Configuration and tooling",
30813
+ "Tests"
30814
+ ]
30815
+ });
30816
+ } else if (isVague.vagueVerb) {
30817
+ questions.push({
30818
+ question: "What specific change are you looking for?",
30819
+ options: [
30820
+ "Add new functionality",
30821
+ "Modify existing behavior",
30822
+ "Remove/deprecate something",
30823
+ "Refactor without behavior change",
30824
+ "Fix a bug"
30825
+ ]
30826
+ });
30827
+ } else if (isVague.noSuccessCriteria) {
30828
+ questions.push({
30829
+ question: "How will we know this task is complete?",
30830
+ options: [
30831
+ "All tests pass",
30832
+ "Feature works as demonstrated",
30833
+ "Code review approved",
30834
+ "Documentation updated",
30835
+ "Performance target met"
30836
+ ]
30837
+ });
30838
+ }
30839
+ if (questions.length === 0) {
30840
+ const output2 = {
30841
+ mode: "socratic",
30842
+ phase: "alternatives",
30843
+ memory_context: memoryContext || undefined,
30844
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30845
+ ready_to_decompose: false,
30846
+ next_action: "Task is clear. Call again with phase=alternatives to explore approaches"
30847
+ };
30848
+ return JSON.stringify(output2, null, 2);
30849
+ }
30850
+ const output = {
30851
+ mode: "socratic",
30852
+ phase: "questioning",
30853
+ questions: [questions[0]],
30854
+ memory_context: memoryContext || undefined,
30855
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30856
+ ready_to_decompose: false,
30857
+ next_action: "User should answer this question, then call again with user_response"
30858
+ };
30859
+ return JSON.stringify(output, null, 2);
30860
+ }
30861
+ if (currentPhase === "alternatives") {
30862
+ const strategyResult = selectStrategy2(args.task);
30863
+ const alternatives = [];
30864
+ alternatives.push({
30865
+ name: strategyResult.strategy,
30866
+ description: strategyResult.reasoning,
30867
+ tradeoffs: `Confidence: ${(strategyResult.confidence * 100).toFixed(0)}%. ${STRATEGIES2[strategyResult.strategy].description}`
30868
+ });
30869
+ for (let i = 0;i < Math.min(2, strategyResult.alternatives.length); i++) {
30870
+ const alt = strategyResult.alternatives[i];
30871
+ alternatives.push({
30872
+ name: alt.strategy,
30873
+ description: STRATEGIES2[alt.strategy].description,
30874
+ tradeoffs: `Match score: ${alt.score}. ${STRATEGIES2[alt.strategy].antiPatterns[0] || "Consider trade-offs carefully"}`
30875
+ });
30876
+ }
30877
+ const output = {
30878
+ mode: "socratic",
30879
+ phase: "alternatives",
30880
+ alternatives,
30881
+ memory_context: memoryContext || undefined,
30882
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30883
+ ready_to_decompose: false,
30884
+ next_action: "User should choose an approach, then call again with phase=recommendation"
30885
+ };
30886
+ return JSON.stringify(output, null, 2);
30887
+ }
30888
+ if (currentPhase === "recommendation") {
30889
+ const strategyResult = selectStrategy2(args.task);
30890
+ const guidelines = formatStrategyGuidelines2(strategyResult.strategy);
30891
+ const output = {
30892
+ mode: "socratic",
30893
+ phase: "recommendation",
30894
+ recommendation: {
30895
+ approach: strategyResult.strategy,
30896
+ reasoning: `Based on your input and task analysis:
30897
+
30898
+ ${strategyResult.reasoning}
30899
+
30900
+ ${guidelines}`
30901
+ },
30902
+ memory_context: memoryContext || undefined,
30903
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30904
+ ready_to_decompose: false,
30905
+ next_action: "User should confirm to proceed. Then call again with phase=ready"
30906
+ };
30907
+ return JSON.stringify(output, null, 2);
30908
+ }
30909
+ if (currentPhase === "ready") {
30910
+ const output = {
30911
+ mode: "socratic",
30912
+ phase: "ready",
30913
+ recommendation: {
30914
+ approach: "Confirmed by user",
30915
+ reasoning: "Ready to proceed with decomposition"
30916
+ },
30917
+ memory_context: memoryContext || undefined,
30918
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30919
+ ready_to_decompose: true,
30920
+ next_action: "Proceed to swarm_decompose or swarm_delegate_planning"
30921
+ };
30922
+ return JSON.stringify(output, null, 2);
30923
+ }
30924
+ throw new Error(`Invalid planning phase: ${currentPhase}`);
30925
+ }
30926
+ });
30533
30927
  var decomposeTools = {
30534
30928
  swarm_decompose,
30535
30929
  swarm_validate_decomposition,
30536
- swarm_delegate_planning
30930
+ swarm_delegate_planning,
30931
+ swarm_plan_interactive
30537
30932
  };
30538
30933
  // src/swarm-prompts.ts
30539
30934
  init_dist();
@@ -30699,13 +31094,11 @@ Only modify these files. Need others? Message the coordinator.
30699
31094
 
30700
31095
  {error_context}
30701
31096
 
30702
- ## [MANDATORY: SWARM MAIL INITIALIZATION]
31097
+ ## [MANDATORY SURVIVAL CHECKLIST]
30703
31098
 
30704
- **CRITICAL: YOU MUST INITIALIZE SWARM MAIL BEFORE DOING ANY WORK.**
31099
+ **CRITICAL: Follow this checklist IN ORDER. Each step builds on the previous.**
30705
31100
 
30706
- This is your FIRST step - before reading files, before planning, before ANY other action.
30707
-
30708
- ### Step 1: Initialize (REQUIRED - DO THIS FIRST)
31101
+ ### Step 1: Initialize Coordination (REQUIRED - DO THIS FIRST)
30709
31102
  \`\`\`
30710
31103
  swarmmail_init(project_path="{project_path}", task_description="{bead_id}: {subtask_title}")
30711
31104
  \`\`\`
@@ -30718,26 +31111,124 @@ swarmmail_init(project_path="{project_path}", task_description="{bead_id}: {subt
30718
31111
 
30719
31112
  **If you skip this step, your work will not be tracked and swarm_complete will fail.**
30720
31113
 
30721
- ## [SWARM MAIL USAGE]
31114
+ ### Step 2: Query Past Learnings (BEFORE starting work)
31115
+ \`\`\`
31116
+ semantic-memory_find(query="<keywords from your task>", limit=5)
31117
+ \`\`\`
30722
31118
 
30723
- After initialization, use Swarm Mail for coordination:
31119
+ **Check if past agents solved similar problems.** Search for:
31120
+ - Error messages if debugging
31121
+ - Domain concepts (e.g., "authentication", "caching")
31122
+ - Technology stack (e.g., "Next.js", "React")
31123
+ - Patterns (e.g., "event sourcing", "validation")
30724
31124
 
30725
- ### Check Inbox Regularly
31125
+ **Past learnings save time and prevent repeating mistakes.**
31126
+
31127
+ ### Step 3: Load Relevant Skills (if available)
30726
31128
  \`\`\`
30727
- swarmmail_inbox() # Check for coordinator messages
30728
- swarmmail_read_message(message_id=N) # Read specific message
31129
+ skills_list() # See what skills exist
31130
+ skills_use(name="<relevant-skill>", context="<your task>") # Load skill
30729
31131
  \`\`\`
30730
31132
 
30731
- ### Report Progress (REQUIRED - don't work silently)
31133
+ **Common skill triggers:**
31134
+ - Writing tests? → \`skills_use(name="testing-patterns")\`
31135
+ - Breaking dependencies? → \`skills_use(name="testing-patterns")\`
31136
+ - Multi-agent coordination? → \`skills_use(name="swarm-coordination")\`
31137
+ - Building a CLI? → \`skills_use(name="cli-builder")\`
31138
+
31139
+ ### Step 4: Reserve Your Files (YOU reserve, not coordinator)
30732
31140
  \`\`\`
30733
- swarmmail_send(
30734
- to=["coordinator"],
30735
- subject="Progress: {bead_id}",
30736
- body="<what you did, blockers, questions>",
30737
- thread_id="{epic_id}"
31141
+ swarmmail_reserve(
31142
+ paths=[{file_list}],
31143
+ reason="{bead_id}: {subtask_title}",
31144
+ exclusive=true
30738
31145
  )
30739
31146
  \`\`\`
30740
31147
 
31148
+ **Workers reserve their own files.** This prevents edit conflicts with other agents.
31149
+
31150
+ ### Step 5: Do the Work
31151
+ - Read your assigned files
31152
+ - Implement changes
31153
+ - Verify (typecheck if applicable)
31154
+
31155
+ ### Step 6: Report Progress at Milestones
31156
+ \`\`\`
31157
+ swarm_progress(
31158
+ project_key="{project_path}",
31159
+ agent_name="<your-agent-name>",
31160
+ bead_id="{bead_id}",
31161
+ status="in_progress",
31162
+ progress_percent=25, # or 50, 75
31163
+ message="<what you just completed>"
31164
+ )
31165
+ \`\`\`
31166
+
31167
+ **Report at 25%, 50%, 75% completion.** This:
31168
+ - Triggers auto-checkpoint (saves context)
31169
+ - Keeps coordinator informed
31170
+ - Prevents silent failures
31171
+
31172
+ ### Step 7: Manual Checkpoint BEFORE Risky Operations
31173
+ \`\`\`
31174
+ swarm_checkpoint(
31175
+ project_key="{project_path}",
31176
+ agent_name="<your-agent-name>",
31177
+ bead_id="{bead_id}"
31178
+ )
31179
+ \`\`\`
31180
+
31181
+ **Call BEFORE:**
31182
+ - Large refactors
31183
+ - File deletions
31184
+ - Breaking API changes
31185
+ - Anything that might fail catastrophically
31186
+
31187
+ **Checkpoints preserve context so you can recover if things go wrong.**
31188
+
31189
+ ### Step 8: Store Learnings (if you discovered something)
31190
+ \`\`\`
31191
+ semantic-memory_store(
31192
+ information="<what you learned, WHY it matters, how to apply it>",
31193
+ metadata="<tags: domain, tech-stack, pattern-type>"
31194
+ )
31195
+ \`\`\`
31196
+
31197
+ **Store:**
31198
+ - Tricky bugs you solved (root cause + solution)
31199
+ - Project-specific patterns or domain rules
31200
+ - Tool/library gotchas and workarounds
31201
+ - Failed approaches (anti-patterns to avoid)
31202
+
31203
+ **Don't store generic knowledge.** Store the WHY, not just the WHAT.
31204
+
31205
+ ### Step 9: Complete (REQUIRED - releases reservations)
31206
+ \`\`\`
31207
+ swarm_complete(
31208
+ project_key="{project_path}",
31209
+ agent_name="<your-agent-name>",
31210
+ bead_id="{bead_id}",
31211
+ summary="<what you accomplished>",
31212
+ files_touched=["list", "of", "files"]
31213
+ )
31214
+ \`\`\`
31215
+
31216
+ **This automatically:**
31217
+ - Runs UBS bug scan
31218
+ - Releases file reservations
31219
+ - Records learning signals
31220
+ - Notifies coordinator
31221
+
31222
+ **DO NOT manually close the bead with beads_close.** Use swarm_complete.
31223
+
31224
+ ## [SWARM MAIL COMMUNICATION]
31225
+
31226
+ ### Check Inbox Regularly
31227
+ \`\`\`
31228
+ swarmmail_inbox() # Check for coordinator messages
31229
+ swarmmail_read_message(message_id=N) # Read specific message
31230
+ \`\`\`
31231
+
30741
31232
  ### When Blocked
30742
31233
  \`\`\`
30743
31234
  swarmmail_send(
@@ -30750,42 +31241,48 @@ swarmmail_send(
30750
31241
  beads_update(id="{bead_id}", status="blocked")
30751
31242
  \`\`\`
30752
31243
 
30753
- ### Release Files When Done
31244
+ ### Report Issues to Other Agents
31245
+ \`\`\`
31246
+ swarmmail_send(
31247
+ to=["OtherAgent", "coordinator"],
31248
+ subject="Issue in {bead_id}",
31249
+ body="<describe problem, don't fix their code>",
31250
+ thread_id="{epic_id}"
31251
+ )
31252
+ \`\`\`
31253
+
31254
+ ### Manual Release (if needed)
30754
31255
  \`\`\`
30755
- swarmmail_release() # Or let swarm_complete handle it
31256
+ swarmmail_release() # Manually release reservations
30756
31257
  \`\`\`
30757
31258
 
31259
+ **Note:** \`swarm_complete\` automatically releases reservations. Only use manual release if aborting work.
31260
+
30758
31261
  ## [OTHER TOOLS]
30759
31262
  ### Beads
30760
31263
  - beads_update(id, status) - Mark blocked if stuck
30761
31264
  - beads_create(title, type) - Log new bugs found
30762
31265
 
30763
- ### Skills (if available)
31266
+ ### Skills
30764
31267
  - skills_list() - Discover available skills
30765
31268
  - skills_use(name) - Activate skill for specialized guidance
31269
+ - skills_create(name) - Create new skill (if you found a reusable pattern)
31270
+
31271
+ ## [CRITICAL REQUIREMENTS]
31272
+
31273
+ **NON-NEGOTIABLE:**
31274
+ 1. Step 1 (swarmmail_init) MUST be first - do it before anything else
31275
+ 2. Step 2 (semantic-memory_find) MUST happen before starting work
31276
+ 3. Step 4 (swarmmail_reserve) - YOU reserve files, not coordinator
31277
+ 4. Step 6 (swarm_progress) - Report at milestones, don't work silently
31278
+ 5. Step 9 (swarm_complete) - Use this to close, NOT beads_close
30766
31279
 
30767
- ### Completion (REQUIRED)
30768
- - swarm_complete(project_key, agent_name, bead_id, summary, files_touched)
30769
-
30770
- ## [LEARNING]
30771
- As you work, note reusable patterns, best practices, or domain insights:
30772
- - If you discover something that would help future agents, consider creating a skill
30773
- - Use skills_create to codify patterns for the project
30774
- - Good skills have clear "when to use" descriptions with actionable instructions
30775
- - Skills make swarms smarter over time
30776
-
30777
- ## [WORKFLOW]
30778
- 1. **swarmmail_init** - Initialize session (MANDATORY FIRST STEP)
30779
- 2. Read assigned files
30780
- 3. Implement changes
30781
- 4. **swarmmail_send** - Report progress to coordinator
30782
- 5. Verify (typecheck)
30783
- 6. **swarm_complete** - Mark done, release reservations
30784
-
30785
- **CRITICAL REQUIREMENTS:**
30786
- - Step 1 (swarmmail_init) is NON-NEGOTIABLE - do it before anything else
30787
- - Never work silently - send progress updates via swarmmail_send every significant milestone
30788
- - If you complete without initializing, swarm_complete will detect this and warn/fail
31280
+ **If you skip these steps:**
31281
+ - Your work won't be tracked (swarm_complete will fail)
31282
+ - You'll waste time repeating solved problems (no semantic memory query)
31283
+ - Edit conflicts with other agents (no file reservation)
31284
+ - Lost work if you crash (no checkpoints)
31285
+ - Future agents repeat your mistakes (no learnings stored)
30789
31286
 
30790
31287
  Begin now.`;
30791
31288
  var EVALUATION_PROMPT = `Evaluate the work completed for this subtask.
@@ -31507,26 +32004,6 @@ var swarm_progress = tool({
31507
32004
  ...checkpoint
31508
32005
  });
31509
32006
  await appendEvent2(event, args.project_key);
31510
- const { getDatabase } = await import("swarm-mail");
31511
- const db = await getDatabase(args.project_key);
31512
- const now = Date.now();
31513
- await db.query(`INSERT INTO swarm_contexts (id, epic_id, bead_id, strategy, files, dependencies, directives, recovery, created_at, updated_at)
31514
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
31515
- ON CONFLICT (id) DO UPDATE SET
31516
- files = EXCLUDED.files,
31517
- recovery = EXCLUDED.recovery,
31518
- updated_at = EXCLUDED.updated_at`, [
31519
- args.bead_id,
31520
- epicId,
31521
- args.bead_id,
31522
- checkpoint.strategy,
31523
- JSON.stringify(checkpoint.files),
31524
- JSON.stringify(checkpoint.dependencies),
31525
- JSON.stringify(checkpoint.directives),
31526
- JSON.stringify(checkpoint.recovery),
31527
- now,
31528
- now
31529
- ]);
31530
32007
  checkpointCreated = true;
31531
32008
  } catch (error45) {
31532
32009
  console.warn(`[swarm_progress] Auto-checkpoint failed at ${args.progress_percent}%:`, error45);
@@ -32194,26 +32671,7 @@ var swarm_checkpoint = tool({
32194
32671
  recovery: checkpoint.recovery
32195
32672
  });
32196
32673
  await appendEvent2(event, args.project_key);
32197
- const { getDatabase } = await import("swarm-mail");
32198
- const db = await getDatabase(args.project_key);
32199
32674
  const now = Date.now();
32200
- await db.query(`INSERT INTO swarm_contexts (id, epic_id, bead_id, strategy, files, dependencies, directives, recovery, created_at, updated_at)
32201
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
32202
- ON CONFLICT (id) DO UPDATE SET
32203
- files = EXCLUDED.files,
32204
- recovery = EXCLUDED.recovery,
32205
- updated_at = EXCLUDED.updated_at`, [
32206
- args.bead_id,
32207
- args.epic_id,
32208
- args.bead_id,
32209
- checkpoint.strategy,
32210
- JSON.stringify(checkpoint.files),
32211
- JSON.stringify(checkpoint.dependencies),
32212
- JSON.stringify(checkpoint.directives),
32213
- JSON.stringify(checkpoint.recovery),
32214
- now,
32215
- now
32216
- ]);
32217
32675
  return JSON.stringify({
32218
32676
  success: true,
32219
32677
  checkpoint_timestamp: now,
@@ -32256,15 +32714,16 @@ var swarm_recover = tool({
32256
32714
  }, null, 2);
32257
32715
  }
32258
32716
  const row = result.rows[0];
32717
+ const parseIfString = (val) => typeof val === "string" ? JSON.parse(val) : val;
32259
32718
  const context = {
32260
32719
  id: row.id,
32261
32720
  epic_id: row.epic_id,
32262
32721
  bead_id: row.bead_id,
32263
32722
  strategy: row.strategy,
32264
- files: JSON.parse(row.files),
32265
- dependencies: JSON.parse(row.dependencies),
32266
- directives: JSON.parse(row.directives),
32267
- recovery: JSON.parse(row.recovery),
32723
+ files: parseIfString(row.files),
32724
+ dependencies: parseIfString(row.dependencies),
32725
+ directives: parseIfString(row.directives),
32726
+ recovery: parseIfString(row.recovery),
32268
32727
  created_at: row.created_at,
32269
32728
  updated_at: row.updated_at
32270
32729
  };