opencode-swarm-plugin 0.18.0 → 0.20.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.
@@ -19,10 +19,15 @@ export const PatternKindSchema = z.enum(["pattern", "anti_pattern"]);
19
19
  export type PatternKind = z.infer<typeof PatternKindSchema>;
20
20
 
21
21
  /**
22
- * A decomposition pattern that has been observed
22
+ * Decomposition pattern with success/failure tracking.
23
23
  *
24
- * Patterns are extracted from successful/failed decompositions and
25
- * tracked over time to learn what works and what doesn't.
24
+ * Field relationships:
25
+ * - `kind`: Tracks pattern lifecycle ("pattern" "anti_pattern" when failure rate exceeds threshold)
26
+ * - `is_negative`: Derived boolean flag for quick filtering (true when kind === "anti_pattern")
27
+ *
28
+ * Both fields exist because:
29
+ * - `kind` is the source of truth for pattern status
30
+ * - `is_negative` enables efficient filtering without string comparison
26
31
  */
27
32
  export const DecompositionPatternSchema = z.object({
28
33
  /** Unique ID for this pattern */
@@ -69,6 +74,9 @@ export type PatternInversionResult = z.infer<
69
74
  // Configuration
70
75
  // ============================================================================
71
76
 
77
+ /** Maximum number of example beads to keep per pattern */
78
+ const MAX_EXAMPLE_BEADS = 10;
79
+
72
80
  /**
73
81
  * Configuration for anti-pattern detection
74
82
  */
@@ -186,7 +194,7 @@ export function recordPatternObservation(
186
194
  failure_count: success ? pattern.failure_count : pattern.failure_count + 1,
187
195
  updated_at: new Date().toISOString(),
188
196
  example_beads: beadId
189
- ? [...pattern.example_beads.slice(-9), beadId] // Keep last 10
197
+ ? [...pattern.example_beads.slice(-(MAX_EXAMPLE_BEADS - 1)), beadId]
190
198
  : pattern.example_beads,
191
199
  };
192
200
 
@@ -216,8 +224,16 @@ export function recordPatternObservation(
216
224
  export function extractPatternsFromDescription(description: string): string[] {
217
225
  const patterns: string[] = [];
218
226
 
219
- // Common decomposition strategies to detect
220
- const strategyPatterns = [
227
+ /**
228
+ * Regex patterns for detecting common decomposition strategies.
229
+ *
230
+ * Detection is keyword-based and not exhaustive - patterns can be
231
+ * manually created for novel strategies not covered here.
232
+ *
233
+ * Each pattern maps a regex to a strategy name that will be extracted
234
+ * from task descriptions during pattern observation.
235
+ */
236
+ const strategyPatterns: Array<{ regex: RegExp; pattern: string }> = [
221
237
  {
222
238
  regex: /split(?:ting)?\s+by\s+file\s+type/i,
223
239
  pattern: "Split by file type",
@@ -322,15 +338,17 @@ export function formatAntiPatternsForPrompt(
322
338
  }
323
339
 
324
340
  /**
325
- * Format successful patterns for inclusion in decomposition prompts
341
+ * Format successful patterns for inclusion in prompts.
326
342
  *
327
- * @param patterns - Patterns to format
328
- * @param minSuccessRate - Minimum success rate to include (0-1)
329
- * @returns Formatted string for prompt inclusion
343
+ * @param patterns - Array of decomposition patterns to filter and format
344
+ * @param minSuccessRate - Minimum success rate to include (default 0.7 = 70%).
345
+ * Chosen to filter out patterns with marginal track records - only patterns
346
+ * that succeed at least 70% of the time are recommended.
347
+ * @returns Formatted string of successful patterns for prompt injection
330
348
  */
331
349
  export function formatSuccessfulPatternsForPrompt(
332
350
  patterns: DecompositionPattern[],
333
- minSuccessRate: number = 0.7,
351
+ minSuccessRate = 0.7,
334
352
  ): string {
335
353
  const successful = patterns.filter((p) => {
336
354
  if (p.kind === "anti_pattern") return false;
package/src/index.ts CHANGED
@@ -301,6 +301,14 @@ export {
301
301
  type SwarmMailState,
302
302
  } from "./swarm-mail";
303
303
 
304
+ /**
305
+ * Re-export shared types from streams/events
306
+ *
307
+ * Includes:
308
+ * - MailSessionState - Shared session state type for Agent Mail and Swarm Mail
309
+ */
310
+ export { type MailSessionState } from "./streams/events";
311
+
304
312
  /**
305
313
  * Re-export structured module
306
314
  *