opencode-swarm-plugin 0.23.6 → 0.25.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/index.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 = [];
@@ -27422,6 +27428,228 @@ var QuerySwarmContextsArgsSchema = exports_external.object({
27422
27428
  strategy: SwarmStrategySchema.optional(),
27423
27429
  has_errors: exports_external.boolean().optional()
27424
27430
  });
27431
+ // src/schemas/bead-events.ts
27432
+ init_zod();
27433
+ var BaseBeadEventSchema = exports_external.object({
27434
+ id: exports_external.number().optional(),
27435
+ type: exports_external.string(),
27436
+ project_key: exports_external.string(),
27437
+ timestamp: exports_external.number(),
27438
+ sequence: exports_external.number().optional()
27439
+ });
27440
+ var BeadCreatedEventSchema = BaseBeadEventSchema.extend({
27441
+ type: exports_external.literal("bead_created"),
27442
+ bead_id: exports_external.string(),
27443
+ title: exports_external.string(),
27444
+ description: exports_external.string().optional(),
27445
+ issue_type: BeadTypeSchema,
27446
+ priority: exports_external.number().int().min(0).max(3),
27447
+ parent_id: exports_external.string().optional(),
27448
+ created_by: exports_external.string().optional(),
27449
+ metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
27450
+ });
27451
+ var BeadUpdatedEventSchema = BaseBeadEventSchema.extend({
27452
+ type: exports_external.literal("bead_updated"),
27453
+ bead_id: exports_external.string(),
27454
+ updated_by: exports_external.string().optional(),
27455
+ changes: exports_external.object({
27456
+ title: exports_external.object({
27457
+ old: exports_external.string(),
27458
+ new: exports_external.string()
27459
+ }).optional(),
27460
+ description: exports_external.object({
27461
+ old: exports_external.string(),
27462
+ new: exports_external.string()
27463
+ }).optional(),
27464
+ priority: exports_external.object({
27465
+ old: exports_external.number(),
27466
+ new: exports_external.number()
27467
+ }).optional()
27468
+ })
27469
+ });
27470
+ var BeadStatusChangedEventSchema = BaseBeadEventSchema.extend({
27471
+ type: exports_external.literal("bead_status_changed"),
27472
+ bead_id: exports_external.string(),
27473
+ from_status: BeadStatusSchema,
27474
+ to_status: BeadStatusSchema,
27475
+ changed_by: exports_external.string().optional(),
27476
+ reason: exports_external.string().optional()
27477
+ });
27478
+ var BeadClosedEventSchema = BaseBeadEventSchema.extend({
27479
+ type: exports_external.literal("bead_closed"),
27480
+ bead_id: exports_external.string(),
27481
+ reason: exports_external.string(),
27482
+ closed_by: exports_external.string().optional(),
27483
+ files_touched: exports_external.array(exports_external.string()).optional(),
27484
+ duration_ms: exports_external.number().optional()
27485
+ });
27486
+ var BeadReopenedEventSchema = BaseBeadEventSchema.extend({
27487
+ type: exports_external.literal("bead_reopened"),
27488
+ bead_id: exports_external.string(),
27489
+ reason: exports_external.string().optional(),
27490
+ reopened_by: exports_external.string().optional()
27491
+ });
27492
+ var BeadDeletedEventSchema = BaseBeadEventSchema.extend({
27493
+ type: exports_external.literal("bead_deleted"),
27494
+ bead_id: exports_external.string(),
27495
+ reason: exports_external.string().optional(),
27496
+ deleted_by: exports_external.string().optional()
27497
+ });
27498
+ var BeadDependencyAddedEventSchema = BaseBeadEventSchema.extend({
27499
+ type: exports_external.literal("bead_dependency_added"),
27500
+ bead_id: exports_external.string(),
27501
+ dependency: BeadDependencySchema,
27502
+ added_by: exports_external.string().optional(),
27503
+ reason: exports_external.string().optional()
27504
+ });
27505
+ var BeadDependencyRemovedEventSchema = BaseBeadEventSchema.extend({
27506
+ type: exports_external.literal("bead_dependency_removed"),
27507
+ bead_id: exports_external.string(),
27508
+ dependency: BeadDependencySchema,
27509
+ removed_by: exports_external.string().optional(),
27510
+ reason: exports_external.string().optional()
27511
+ });
27512
+ var BeadLabelAddedEventSchema = BaseBeadEventSchema.extend({
27513
+ type: exports_external.literal("bead_label_added"),
27514
+ bead_id: exports_external.string(),
27515
+ label: exports_external.string(),
27516
+ added_by: exports_external.string().optional()
27517
+ });
27518
+ var BeadLabelRemovedEventSchema = BaseBeadEventSchema.extend({
27519
+ type: exports_external.literal("bead_label_removed"),
27520
+ bead_id: exports_external.string(),
27521
+ label: exports_external.string(),
27522
+ removed_by: exports_external.string().optional()
27523
+ });
27524
+ var BeadCommentAddedEventSchema = BaseBeadEventSchema.extend({
27525
+ type: exports_external.literal("bead_comment_added"),
27526
+ bead_id: exports_external.string(),
27527
+ comment_id: exports_external.number().optional(),
27528
+ author: exports_external.string(),
27529
+ body: exports_external.string(),
27530
+ parent_comment_id: exports_external.number().optional(),
27531
+ metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
27532
+ });
27533
+ var BeadCommentUpdatedEventSchema = BaseBeadEventSchema.extend({
27534
+ type: exports_external.literal("bead_comment_updated"),
27535
+ bead_id: exports_external.string(),
27536
+ comment_id: exports_external.number(),
27537
+ old_body: exports_external.string(),
27538
+ new_body: exports_external.string(),
27539
+ updated_by: exports_external.string()
27540
+ });
27541
+ var BeadCommentDeletedEventSchema = BaseBeadEventSchema.extend({
27542
+ type: exports_external.literal("bead_comment_deleted"),
27543
+ bead_id: exports_external.string(),
27544
+ comment_id: exports_external.number(),
27545
+ deleted_by: exports_external.string(),
27546
+ reason: exports_external.string().optional()
27547
+ });
27548
+ var BeadEpicChildAddedEventSchema = BaseBeadEventSchema.extend({
27549
+ type: exports_external.literal("bead_epic_child_added"),
27550
+ bead_id: exports_external.string(),
27551
+ child_id: exports_external.string(),
27552
+ child_index: exports_external.number().optional(),
27553
+ added_by: exports_external.string().optional()
27554
+ });
27555
+ var BeadEpicChildRemovedEventSchema = BaseBeadEventSchema.extend({
27556
+ type: exports_external.literal("bead_epic_child_removed"),
27557
+ bead_id: exports_external.string(),
27558
+ child_id: exports_external.string(),
27559
+ removed_by: exports_external.string().optional(),
27560
+ reason: exports_external.string().optional()
27561
+ });
27562
+ var BeadEpicClosureEligibleEventSchema = BaseBeadEventSchema.extend({
27563
+ type: exports_external.literal("bead_epic_closure_eligible"),
27564
+ bead_id: exports_external.string(),
27565
+ child_ids: exports_external.array(exports_external.string()),
27566
+ total_duration_ms: exports_external.number().optional(),
27567
+ all_files_touched: exports_external.array(exports_external.string()).optional()
27568
+ });
27569
+ var BeadAssignedEventSchema = BaseBeadEventSchema.extend({
27570
+ type: exports_external.literal("bead_assigned"),
27571
+ bead_id: exports_external.string(),
27572
+ agent_name: exports_external.string(),
27573
+ task_description: exports_external.string().optional()
27574
+ });
27575
+ var BeadWorkStartedEventSchema = BaseBeadEventSchema.extend({
27576
+ type: exports_external.literal("bead_work_started"),
27577
+ bead_id: exports_external.string(),
27578
+ agent_name: exports_external.string(),
27579
+ reserved_files: exports_external.array(exports_external.string()).optional()
27580
+ });
27581
+ var BeadCompactedEventSchema = BaseBeadEventSchema.extend({
27582
+ type: exports_external.literal("bead_compacted"),
27583
+ bead_id: exports_external.string(),
27584
+ events_archived: exports_external.number(),
27585
+ new_start_sequence: exports_external.number()
27586
+ });
27587
+ var BeadEventSchema = exports_external.discriminatedUnion("type", [
27588
+ BeadCreatedEventSchema,
27589
+ BeadUpdatedEventSchema,
27590
+ BeadStatusChangedEventSchema,
27591
+ BeadClosedEventSchema,
27592
+ BeadReopenedEventSchema,
27593
+ BeadDeletedEventSchema,
27594
+ BeadDependencyAddedEventSchema,
27595
+ BeadDependencyRemovedEventSchema,
27596
+ BeadLabelAddedEventSchema,
27597
+ BeadLabelRemovedEventSchema,
27598
+ BeadCommentAddedEventSchema,
27599
+ BeadCommentUpdatedEventSchema,
27600
+ BeadCommentDeletedEventSchema,
27601
+ BeadEpicChildAddedEventSchema,
27602
+ BeadEpicChildRemovedEventSchema,
27603
+ BeadEpicClosureEligibleEventSchema,
27604
+ BeadAssignedEventSchema,
27605
+ BeadWorkStartedEventSchema,
27606
+ BeadCompactedEventSchema
27607
+ ]);
27608
+ function createBeadEvent(type, data) {
27609
+ const event = {
27610
+ type,
27611
+ timestamp: Date.now(),
27612
+ ...data
27613
+ };
27614
+ const result = BeadEventSchema.safeParse(event);
27615
+ if (!result.success) {
27616
+ throw new Error(`Invalid bead event: ${result.error.message}`);
27617
+ }
27618
+ return result.data;
27619
+ }
27620
+ function isBeadEventType(event, type) {
27621
+ return event.type === type;
27622
+ }
27623
+ function getBeadIdFromEvent(event) {
27624
+ return event.bead_id;
27625
+ }
27626
+ function isStateTransitionEvent(event) {
27627
+ return event.type === "bead_status_changed" || event.type === "bead_closed" || event.type === "bead_reopened";
27628
+ }
27629
+ function isEpicEvent(event) {
27630
+ return event.type === "bead_epic_child_added" || event.type === "bead_epic_child_removed" || event.type === "bead_epic_closure_eligible";
27631
+ }
27632
+ function isAgentEvent(event) {
27633
+ if ("agent_name" in event)
27634
+ return true;
27635
+ const actorFields = [
27636
+ "created_by",
27637
+ "updated_by",
27638
+ "changed_by",
27639
+ "closed_by",
27640
+ "deleted_by",
27641
+ "added_by",
27642
+ "removed_by",
27643
+ "reopened_by"
27644
+ ];
27645
+ return actorFields.some((field) => {
27646
+ if (field in event) {
27647
+ const value = event[field];
27648
+ return typeof value === "string" && /^[a-z]+$/i.test(value);
27649
+ }
27650
+ return false;
27651
+ });
27652
+ }
27425
27653
  // src/beads.ts
27426
27654
  import { createEvent, appendEvent } from "swarm-mail";
27427
27655
  var beadsWorkingDirectory = null;
@@ -30694,10 +30922,222 @@ class DecompositionError extends SwarmError {
30694
30922
  this.zodError = zodError;
30695
30923
  }
30696
30924
  }
30925
+ var swarm_plan_interactive = tool({
30926
+ description: "Interactive planning phase with Socratic questioning before decomposition. Supports multiple modes from full interactive to auto-proceed.",
30927
+ args: {
30928
+ task: tool.schema.string().min(1).describe("The task to plan"),
30929
+ 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)"),
30930
+ context: tool.schema.string().optional().describe("Optional additional context about the task"),
30931
+ user_response: tool.schema.string().optional().describe("User's response to a previous question (for multi-turn socratic mode)"),
30932
+ phase: tool.schema.enum(["questioning", "alternatives", "recommendation", "ready"]).optional().describe("Current planning phase (for resuming multi-turn interaction)")
30933
+ },
30934
+ async execute(args) {
30935
+ const { selectStrategy: selectStrategy2, formatStrategyGuidelines: formatStrategyGuidelines2, STRATEGIES: STRATEGIES2 } = await Promise.resolve().then(() => (init_swarm_strategies(), exports_swarm_strategies));
30936
+ const { formatMemoryQueryForDecomposition: formatMemoryQueryForDecomposition2 } = await Promise.resolve().then(() => (init_learning(), exports_learning));
30937
+ const currentPhase = args.phase || "questioning";
30938
+ const mode = args.mode || "socratic";
30939
+ let memoryContext = "";
30940
+ let codebaseContext = {};
30941
+ try {
30942
+ const memoryQuery = formatMemoryQueryForDecomposition2(args.task, 3);
30943
+ memoryContext = `[Memory Query Instruction]
30944
+ ${memoryQuery.instruction}
30945
+ Query: "${memoryQuery.query}"
30946
+ Limit: ${memoryQuery.limit}`;
30947
+ } catch (error45) {
30948
+ console.warn("[swarm_plan_interactive] Memory query formatting failed:", error45);
30949
+ }
30950
+ try {
30951
+ const gitResult = await Bun.$`git status --short`.quiet().nothrow();
30952
+ if (gitResult.exitCode === 0) {
30953
+ codebaseContext.git_status = gitResult.stdout.toString().trim();
30954
+ }
30955
+ } catch (error45) {}
30956
+ if (mode === "fast") {
30957
+ const strategyResult = selectStrategy2(args.task);
30958
+ const guidelines = formatStrategyGuidelines2(strategyResult.strategy);
30959
+ const output = {
30960
+ mode: "fast",
30961
+ phase: "ready",
30962
+ recommendation: {
30963
+ approach: strategyResult.strategy,
30964
+ reasoning: `${strategyResult.reasoning}
30965
+
30966
+ ${guidelines}`
30967
+ },
30968
+ memory_context: memoryContext || undefined,
30969
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30970
+ ready_to_decompose: true,
30971
+ next_action: "Proceed to swarm_decompose or swarm_delegate_planning"
30972
+ };
30973
+ return JSON.stringify(output, null, 2);
30974
+ }
30975
+ if (mode === "auto") {
30976
+ const strategyResult = selectStrategy2(args.task);
30977
+ const output = {
30978
+ mode: "auto",
30979
+ phase: "ready",
30980
+ recommendation: {
30981
+ approach: strategyResult.strategy,
30982
+ reasoning: `Auto-selected based on task keywords: ${strategyResult.reasoning}`
30983
+ },
30984
+ memory_context: memoryContext || undefined,
30985
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
30986
+ ready_to_decompose: true,
30987
+ next_action: "Auto-proceeding to decomposition"
30988
+ };
30989
+ return JSON.stringify(output, null, 2);
30990
+ }
30991
+ if (mode === "confirm-only") {
30992
+ const output = {
30993
+ mode: "confirm-only",
30994
+ phase: "ready",
30995
+ recommendation: {
30996
+ approach: "Will generate decomposition for your review",
30997
+ reasoning: "Use swarm_delegate_planning to generate the plan, then present it for yes/no confirmation"
30998
+ },
30999
+ memory_context: memoryContext || undefined,
31000
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
31001
+ ready_to_decompose: false,
31002
+ next_action: "Call swarm_delegate_planning, then show result and ask for confirmation"
31003
+ };
31004
+ return JSON.stringify(output, null, 2);
31005
+ }
31006
+ if (currentPhase === "questioning") {
31007
+ const taskLower = args.task.toLowerCase();
31008
+ const questions = [];
31009
+ const isVague = {
31010
+ noFiles: !taskLower.includes("src/") && !taskLower.includes("file"),
31011
+ vagueVerb: taskLower.includes("improve") || taskLower.includes("fix") || taskLower.includes("update") || taskLower.includes("make better"),
31012
+ noSuccessCriteria: !taskLower.includes("test") && !taskLower.includes("verify")
31013
+ };
31014
+ if (isVague.noFiles) {
31015
+ questions.push({
31016
+ question: "Which part of the codebase should this change affect?",
31017
+ options: [
31018
+ "Core functionality (src/)",
31019
+ "UI components (components/)",
31020
+ "API routes (app/api/)",
31021
+ "Configuration and tooling",
31022
+ "Tests"
31023
+ ]
31024
+ });
31025
+ } else if (isVague.vagueVerb) {
31026
+ questions.push({
31027
+ question: "What specific change are you looking for?",
31028
+ options: [
31029
+ "Add new functionality",
31030
+ "Modify existing behavior",
31031
+ "Remove/deprecate something",
31032
+ "Refactor without behavior change",
31033
+ "Fix a bug"
31034
+ ]
31035
+ });
31036
+ } else if (isVague.noSuccessCriteria) {
31037
+ questions.push({
31038
+ question: "How will we know this task is complete?",
31039
+ options: [
31040
+ "All tests pass",
31041
+ "Feature works as demonstrated",
31042
+ "Code review approved",
31043
+ "Documentation updated",
31044
+ "Performance target met"
31045
+ ]
31046
+ });
31047
+ }
31048
+ if (questions.length === 0) {
31049
+ const output2 = {
31050
+ mode: "socratic",
31051
+ phase: "alternatives",
31052
+ memory_context: memoryContext || undefined,
31053
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
31054
+ ready_to_decompose: false,
31055
+ next_action: "Task is clear. Call again with phase=alternatives to explore approaches"
31056
+ };
31057
+ return JSON.stringify(output2, null, 2);
31058
+ }
31059
+ const output = {
31060
+ mode: "socratic",
31061
+ phase: "questioning",
31062
+ questions: [questions[0]],
31063
+ memory_context: memoryContext || undefined,
31064
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
31065
+ ready_to_decompose: false,
31066
+ next_action: "User should answer this question, then call again with user_response"
31067
+ };
31068
+ return JSON.stringify(output, null, 2);
31069
+ }
31070
+ if (currentPhase === "alternatives") {
31071
+ const strategyResult = selectStrategy2(args.task);
31072
+ const alternatives = [];
31073
+ alternatives.push({
31074
+ name: strategyResult.strategy,
31075
+ description: strategyResult.reasoning,
31076
+ tradeoffs: `Confidence: ${(strategyResult.confidence * 100).toFixed(0)}%. ${STRATEGIES2[strategyResult.strategy].description}`
31077
+ });
31078
+ for (let i = 0;i < Math.min(2, strategyResult.alternatives.length); i++) {
31079
+ const alt = strategyResult.alternatives[i];
31080
+ alternatives.push({
31081
+ name: alt.strategy,
31082
+ description: STRATEGIES2[alt.strategy].description,
31083
+ tradeoffs: `Match score: ${alt.score}. ${STRATEGIES2[alt.strategy].antiPatterns[0] || "Consider trade-offs carefully"}`
31084
+ });
31085
+ }
31086
+ const output = {
31087
+ mode: "socratic",
31088
+ phase: "alternatives",
31089
+ alternatives,
31090
+ memory_context: memoryContext || undefined,
31091
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
31092
+ ready_to_decompose: false,
31093
+ next_action: "User should choose an approach, then call again with phase=recommendation"
31094
+ };
31095
+ return JSON.stringify(output, null, 2);
31096
+ }
31097
+ if (currentPhase === "recommendation") {
31098
+ const strategyResult = selectStrategy2(args.task);
31099
+ const guidelines = formatStrategyGuidelines2(strategyResult.strategy);
31100
+ const output = {
31101
+ mode: "socratic",
31102
+ phase: "recommendation",
31103
+ recommendation: {
31104
+ approach: strategyResult.strategy,
31105
+ reasoning: `Based on your input and task analysis:
31106
+
31107
+ ${strategyResult.reasoning}
31108
+
31109
+ ${guidelines}`
31110
+ },
31111
+ memory_context: memoryContext || undefined,
31112
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
31113
+ ready_to_decompose: false,
31114
+ next_action: "User should confirm to proceed. Then call again with phase=ready"
31115
+ };
31116
+ return JSON.stringify(output, null, 2);
31117
+ }
31118
+ if (currentPhase === "ready") {
31119
+ const output = {
31120
+ mode: "socratic",
31121
+ phase: "ready",
31122
+ recommendation: {
31123
+ approach: "Confirmed by user",
31124
+ reasoning: "Ready to proceed with decomposition"
31125
+ },
31126
+ memory_context: memoryContext || undefined,
31127
+ codebase_context: Object.keys(codebaseContext).length > 0 ? codebaseContext : undefined,
31128
+ ready_to_decompose: true,
31129
+ next_action: "Proceed to swarm_decompose or swarm_delegate_planning"
31130
+ };
31131
+ return JSON.stringify(output, null, 2);
31132
+ }
31133
+ throw new Error(`Invalid planning phase: ${currentPhase}`);
31134
+ }
31135
+ });
30697
31136
  var decomposeTools = {
30698
31137
  swarm_decompose,
30699
31138
  swarm_validate_decomposition,
30700
- swarm_delegate_planning
31139
+ swarm_delegate_planning,
31140
+ swarm_plan_interactive
30701
31141
  };
30702
31142
  // src/swarm-prompts.ts
30703
31143
  init_dist();
@@ -30863,13 +31303,11 @@ Only modify these files. Need others? Message the coordinator.
30863
31303
 
30864
31304
  {error_context}
30865
31305
 
30866
- ## [MANDATORY: SWARM MAIL INITIALIZATION]
30867
-
30868
- **CRITICAL: YOU MUST INITIALIZE SWARM MAIL BEFORE DOING ANY WORK.**
31306
+ ## [MANDATORY SURVIVAL CHECKLIST]
30869
31307
 
30870
- This is your FIRST step - before reading files, before planning, before ANY other action.
31308
+ **CRITICAL: Follow this checklist IN ORDER. Each step builds on the previous.**
30871
31309
 
30872
- ### Step 1: Initialize (REQUIRED - DO THIS FIRST)
31310
+ ### Step 1: Initialize Coordination (REQUIRED - DO THIS FIRST)
30873
31311
  \`\`\`
30874
31312
  swarmmail_init(project_path="{project_path}", task_description="{bead_id}: {subtask_title}")
30875
31313
  \`\`\`
@@ -30882,26 +31320,124 @@ swarmmail_init(project_path="{project_path}", task_description="{bead_id}: {subt
30882
31320
 
30883
31321
  **If you skip this step, your work will not be tracked and swarm_complete will fail.**
30884
31322
 
30885
- ## [SWARM MAIL USAGE]
31323
+ ### Step 2: Query Past Learnings (BEFORE starting work)
31324
+ \`\`\`
31325
+ semantic-memory_find(query="<keywords from your task>", limit=5)
31326
+ \`\`\`
30886
31327
 
30887
- After initialization, use Swarm Mail for coordination:
31328
+ **Check if past agents solved similar problems.** Search for:
31329
+ - Error messages if debugging
31330
+ - Domain concepts (e.g., "authentication", "caching")
31331
+ - Technology stack (e.g., "Next.js", "React")
31332
+ - Patterns (e.g., "event sourcing", "validation")
30888
31333
 
30889
- ### Check Inbox Regularly
31334
+ **Past learnings save time and prevent repeating mistakes.**
31335
+
31336
+ ### Step 3: Load Relevant Skills (if available)
30890
31337
  \`\`\`
30891
- swarmmail_inbox() # Check for coordinator messages
30892
- swarmmail_read_message(message_id=N) # Read specific message
31338
+ skills_list() # See what skills exist
31339
+ skills_use(name="<relevant-skill>", context="<your task>") # Load skill
30893
31340
  \`\`\`
30894
31341
 
30895
- ### Report Progress (REQUIRED - don't work silently)
31342
+ **Common skill triggers:**
31343
+ - Writing tests? → \`skills_use(name="testing-patterns")\`
31344
+ - Breaking dependencies? → \`skills_use(name="testing-patterns")\`
31345
+ - Multi-agent coordination? → \`skills_use(name="swarm-coordination")\`
31346
+ - Building a CLI? → \`skills_use(name="cli-builder")\`
31347
+
31348
+ ### Step 4: Reserve Your Files (YOU reserve, not coordinator)
30896
31349
  \`\`\`
30897
- swarmmail_send(
30898
- to=["coordinator"],
30899
- subject="Progress: {bead_id}",
30900
- body="<what you did, blockers, questions>",
30901
- thread_id="{epic_id}"
31350
+ swarmmail_reserve(
31351
+ paths=[{file_list}],
31352
+ reason="{bead_id}: {subtask_title}",
31353
+ exclusive=true
31354
+ )
31355
+ \`\`\`
31356
+
31357
+ **Workers reserve their own files.** This prevents edit conflicts with other agents.
31358
+
31359
+ ### Step 5: Do the Work
31360
+ - Read your assigned files
31361
+ - Implement changes
31362
+ - Verify (typecheck if applicable)
31363
+
31364
+ ### Step 6: Report Progress at Milestones
31365
+ \`\`\`
31366
+ swarm_progress(
31367
+ project_key="{project_path}",
31368
+ agent_name="<your-agent-name>",
31369
+ bead_id="{bead_id}",
31370
+ status="in_progress",
31371
+ progress_percent=25, # or 50, 75
31372
+ message="<what you just completed>"
31373
+ )
31374
+ \`\`\`
31375
+
31376
+ **Report at 25%, 50%, 75% completion.** This:
31377
+ - Triggers auto-checkpoint (saves context)
31378
+ - Keeps coordinator informed
31379
+ - Prevents silent failures
31380
+
31381
+ ### Step 7: Manual Checkpoint BEFORE Risky Operations
31382
+ \`\`\`
31383
+ swarm_checkpoint(
31384
+ project_key="{project_path}",
31385
+ agent_name="<your-agent-name>",
31386
+ bead_id="{bead_id}"
31387
+ )
31388
+ \`\`\`
31389
+
31390
+ **Call BEFORE:**
31391
+ - Large refactors
31392
+ - File deletions
31393
+ - Breaking API changes
31394
+ - Anything that might fail catastrophically
31395
+
31396
+ **Checkpoints preserve context so you can recover if things go wrong.**
31397
+
31398
+ ### Step 8: Store Learnings (if you discovered something)
31399
+ \`\`\`
31400
+ semantic-memory_store(
31401
+ information="<what you learned, WHY it matters, how to apply it>",
31402
+ metadata="<tags: domain, tech-stack, pattern-type>"
31403
+ )
31404
+ \`\`\`
31405
+
31406
+ **Store:**
31407
+ - Tricky bugs you solved (root cause + solution)
31408
+ - Project-specific patterns or domain rules
31409
+ - Tool/library gotchas and workarounds
31410
+ - Failed approaches (anti-patterns to avoid)
31411
+
31412
+ **Don't store generic knowledge.** Store the WHY, not just the WHAT.
31413
+
31414
+ ### Step 9: Complete (REQUIRED - releases reservations)
31415
+ \`\`\`
31416
+ swarm_complete(
31417
+ project_key="{project_path}",
31418
+ agent_name="<your-agent-name>",
31419
+ bead_id="{bead_id}",
31420
+ summary="<what you accomplished>",
31421
+ files_touched=["list", "of", "files"]
30902
31422
  )
30903
31423
  \`\`\`
30904
31424
 
31425
+ **This automatically:**
31426
+ - Runs UBS bug scan
31427
+ - Releases file reservations
31428
+ - Records learning signals
31429
+ - Notifies coordinator
31430
+
31431
+ **DO NOT manually close the bead with beads_close.** Use swarm_complete.
31432
+
31433
+ ## [SWARM MAIL COMMUNICATION]
31434
+
31435
+ ### Check Inbox Regularly
31436
+ \`\`\`
31437
+ swarmmail_inbox() # Check for coordinator messages
31438
+ swarmmail_read_message(message_id=N) # Read specific message
31439
+ \`\`\`
31440
+
30905
31441
  ### When Blocked
30906
31442
  \`\`\`
30907
31443
  swarmmail_send(
@@ -30914,42 +31450,48 @@ swarmmail_send(
30914
31450
  beads_update(id="{bead_id}", status="blocked")
30915
31451
  \`\`\`
30916
31452
 
30917
- ### Release Files When Done
31453
+ ### Report Issues to Other Agents
31454
+ \`\`\`
31455
+ swarmmail_send(
31456
+ to=["OtherAgent", "coordinator"],
31457
+ subject="Issue in {bead_id}",
31458
+ body="<describe problem, don't fix their code>",
31459
+ thread_id="{epic_id}"
31460
+ )
31461
+ \`\`\`
31462
+
31463
+ ### Manual Release (if needed)
30918
31464
  \`\`\`
30919
- swarmmail_release() # Or let swarm_complete handle it
31465
+ swarmmail_release() # Manually release reservations
30920
31466
  \`\`\`
30921
31467
 
31468
+ **Note:** \`swarm_complete\` automatically releases reservations. Only use manual release if aborting work.
31469
+
30922
31470
  ## [OTHER TOOLS]
30923
31471
  ### Beads
30924
31472
  - beads_update(id, status) - Mark blocked if stuck
30925
31473
  - beads_create(title, type) - Log new bugs found
30926
31474
 
30927
- ### Skills (if available)
31475
+ ### Skills
30928
31476
  - skills_list() - Discover available skills
30929
31477
  - skills_use(name) - Activate skill for specialized guidance
31478
+ - skills_create(name) - Create new skill (if you found a reusable pattern)
31479
+
31480
+ ## [CRITICAL REQUIREMENTS]
30930
31481
 
30931
- ### Completion (REQUIRED)
30932
- - swarm_complete(project_key, agent_name, bead_id, summary, files_touched)
30933
-
30934
- ## [LEARNING]
30935
- As you work, note reusable patterns, best practices, or domain insights:
30936
- - If you discover something that would help future agents, consider creating a skill
30937
- - Use skills_create to codify patterns for the project
30938
- - Good skills have clear "when to use" descriptions with actionable instructions
30939
- - Skills make swarms smarter over time
30940
-
30941
- ## [WORKFLOW]
30942
- 1. **swarmmail_init** - Initialize session (MANDATORY FIRST STEP)
30943
- 2. Read assigned files
30944
- 3. Implement changes
30945
- 4. **swarmmail_send** - Report progress to coordinator
30946
- 5. Verify (typecheck)
30947
- 6. **swarm_complete** - Mark done, release reservations
30948
-
30949
- **CRITICAL REQUIREMENTS:**
30950
- - Step 1 (swarmmail_init) is NON-NEGOTIABLE - do it before anything else
30951
- - Never work silently - send progress updates via swarmmail_send every significant milestone
30952
- - If you complete without initializing, swarm_complete will detect this and warn/fail
31482
+ **NON-NEGOTIABLE:**
31483
+ 1. Step 1 (swarmmail_init) MUST be first - do it before anything else
31484
+ 2. Step 2 (semantic-memory_find) MUST happen before starting work
31485
+ 3. Step 4 (swarmmail_reserve) - YOU reserve files, not coordinator
31486
+ 4. Step 6 (swarm_progress) - Report at milestones, don't work silently
31487
+ 5. Step 9 (swarm_complete) - Use this to close, NOT beads_close
31488
+
31489
+ **If you skip these steps:**
31490
+ - Your work won't be tracked (swarm_complete will fail)
31491
+ - You'll waste time repeating solved problems (no semantic memory query)
31492
+ - Edit conflicts with other agents (no file reservation)
31493
+ - Lost work if you crash (no checkpoints)
31494
+ - Future agents repeat your mistakes (no learnings stored)
30953
31495
 
30954
31496
  Begin now.`;
30955
31497
  var EVALUATION_PROMPT = `Evaluate the work completed for this subtask.
@@ -31671,26 +32213,6 @@ var swarm_progress = tool({
31671
32213
  ...checkpoint
31672
32214
  });
31673
32215
  await appendEvent2(event, args.project_key);
31674
- const { getDatabase } = await import("swarm-mail");
31675
- const db = await getDatabase(args.project_key);
31676
- const now = Date.now();
31677
- await db.query(`INSERT INTO swarm_contexts (id, epic_id, bead_id, strategy, files, dependencies, directives, recovery, created_at, updated_at)
31678
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
31679
- ON CONFLICT (id) DO UPDATE SET
31680
- files = EXCLUDED.files,
31681
- recovery = EXCLUDED.recovery,
31682
- updated_at = EXCLUDED.updated_at`, [
31683
- args.bead_id,
31684
- epicId,
31685
- args.bead_id,
31686
- checkpoint.strategy,
31687
- JSON.stringify(checkpoint.files),
31688
- JSON.stringify(checkpoint.dependencies),
31689
- JSON.stringify(checkpoint.directives),
31690
- JSON.stringify(checkpoint.recovery),
31691
- now,
31692
- now
31693
- ]);
31694
32216
  checkpointCreated = true;
31695
32217
  } catch (error45) {
31696
32218
  console.warn(`[swarm_progress] Auto-checkpoint failed at ${args.progress_percent}%:`, error45);
@@ -32358,26 +32880,7 @@ var swarm_checkpoint = tool({
32358
32880
  recovery: checkpoint.recovery
32359
32881
  });
32360
32882
  await appendEvent2(event, args.project_key);
32361
- const { getDatabase } = await import("swarm-mail");
32362
- const db = await getDatabase(args.project_key);
32363
32883
  const now = Date.now();
32364
- await db.query(`INSERT INTO swarm_contexts (id, epic_id, bead_id, strategy, files, dependencies, directives, recovery, created_at, updated_at)
32365
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
32366
- ON CONFLICT (id) DO UPDATE SET
32367
- files = EXCLUDED.files,
32368
- recovery = EXCLUDED.recovery,
32369
- updated_at = EXCLUDED.updated_at`, [
32370
- args.bead_id,
32371
- args.epic_id,
32372
- args.bead_id,
32373
- checkpoint.strategy,
32374
- JSON.stringify(checkpoint.files),
32375
- JSON.stringify(checkpoint.dependencies),
32376
- JSON.stringify(checkpoint.directives),
32377
- JSON.stringify(checkpoint.recovery),
32378
- now,
32379
- now
32380
- ]);
32381
32884
  return JSON.stringify({
32382
32885
  success: true,
32383
32886
  checkpoint_timestamp: now,
@@ -32420,15 +32923,16 @@ var swarm_recover = tool({
32420
32923
  }, null, 2);
32421
32924
  }
32422
32925
  const row = result.rows[0];
32926
+ const parseIfString = (val) => typeof val === "string" ? JSON.parse(val) : val;
32423
32927
  const context = {
32424
32928
  id: row.id,
32425
32929
  epic_id: row.epic_id,
32426
32930
  bead_id: row.bead_id,
32427
32931
  strategy: row.strategy,
32428
- files: JSON.parse(row.files),
32429
- dependencies: JSON.parse(row.dependencies),
32430
- directives: JSON.parse(row.directives),
32431
- recovery: JSON.parse(row.recovery),
32932
+ files: parseIfString(row.files),
32933
+ dependencies: parseIfString(row.dependencies),
32934
+ directives: parseIfString(row.directives),
32935
+ recovery: parseIfString(row.recovery),
32432
32936
  created_at: row.created_at,
32433
32937
  updated_at: row.updated_at
32434
32938
  };
@@ -34456,9 +34960,13 @@ export {
34456
34960
  mandateSchemas,
34457
34961
  listSkills,
34458
34962
  isToolAvailable,
34963
+ isStateTransitionEvent,
34459
34964
  isSemanticMemoryAvailable,
34460
34965
  isProjectNotFoundError,
34966
+ isEpicEvent,
34967
+ isBeadEventType,
34461
34968
  isAgentNotFoundError,
34969
+ isAgentEvent,
34462
34970
  invalidateSkillsCache,
34463
34971
  ifToolAvailable,
34464
34972
  guardrailOutput,
@@ -34472,6 +34980,7 @@ export {
34472
34980
  getSchemaByName,
34473
34981
  getMandateStorage,
34474
34982
  getBeadsWorkingDirectory,
34983
+ getBeadIdFromEvent,
34475
34984
  getAgentMailProjectDirectory,
34476
34985
  formatZodErrors,
34477
34986
  formatToolAvailability,
@@ -34490,6 +34999,7 @@ export {
34490
34999
  createStorage,
34491
35000
  createMetrics,
34492
35001
  createMandateStorage,
35002
+ createBeadEvent,
34493
35003
  createAgentMailError,
34494
35004
  clearSessionState,
34495
35005
  checkTool,
@@ -34559,17 +35069,38 @@ export {
34559
35069
  CreateSwarmContextArgsSchema,
34560
35070
  CreateMandateArgsSchema,
34561
35071
  CastVoteArgsSchema,
35072
+ BeadWorkStartedEventSchema,
34562
35073
  BeadValidationError,
35074
+ BeadUpdatedEventSchema,
34563
35075
  BeadUpdateArgsSchema,
34564
35076
  BeadTypeSchema,
34565
35077
  BeadTreeSchema,
34566
35078
  BeadStatusSchema,
35079
+ BeadStatusChangedEventSchema,
34567
35080
  BeadSchema,
35081
+ BeadReopenedEventSchema,
34568
35082
  BeadQueryArgsSchema,
35083
+ BeadLabelRemovedEventSchema,
35084
+ BeadLabelAddedEventSchema,
35085
+ BeadEventSchema,
34569
35086
  BeadError,
35087
+ BeadEpicClosureEligibleEventSchema,
35088
+ BeadEpicChildRemovedEventSchema,
35089
+ BeadEpicChildAddedEventSchema,
34570
35090
  BeadDependencySchema,
35091
+ BeadDependencyRemovedEventSchema,
35092
+ BeadDependencyAddedEventSchema,
35093
+ BeadDeletedEventSchema,
35094
+ BeadCreatedEventSchema,
34571
35095
  BeadCreateArgsSchema,
35096
+ BeadCompactedEventSchema,
35097
+ BeadCommentUpdatedEventSchema,
35098
+ BeadCommentDeletedEventSchema,
35099
+ BeadCommentAddedEventSchema,
35100
+ BeadClosedEventSchema,
34572
35101
  BeadCloseArgsSchema,
35102
+ BeadAssignedEventSchema,
35103
+ BaseBeadEventSchema,
34573
35104
  AgentProgressSchema,
34574
35105
  AgentMailNotInitializedError,
34575
35106
  AgentMailError