opencode-swarm 6.14.0 → 6.14.12

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/cli/index.js CHANGED
File without changes
@@ -99,6 +99,7 @@ export declare const ContextBudgetConfigSchema: z.ZodObject<{
99
99
  critical_threshold: z.ZodDefault<z.ZodNumber>;
100
100
  model_limits: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
101
101
  max_injection_tokens: z.ZodDefault<z.ZodNumber>;
102
+ tracked_agents: z.ZodDefault<z.ZodArray<z.ZodString>>;
102
103
  scoring: z.ZodOptional<z.ZodObject<{
103
104
  enabled: z.ZodDefault<z.ZodBoolean>;
104
105
  max_candidates: z.ZodDefault<z.ZodNumber>;
@@ -126,6 +127,12 @@ export declare const ContextBudgetConfigSchema: z.ZodObject<{
126
127
  json: z.ZodDefault<z.ZodNumber>;
127
128
  }, z.core.$strip>>;
128
129
  }, z.core.$strip>>;
130
+ enforce: z.ZodDefault<z.ZodBoolean>;
131
+ prune_target: z.ZodDefault<z.ZodNumber>;
132
+ preserve_last_n_turns: z.ZodDefault<z.ZodNumber>;
133
+ recent_window: z.ZodDefault<z.ZodNumber>;
134
+ enforce_on_agent_switch: z.ZodDefault<z.ZodBoolean>;
135
+ tool_output_mask_threshold: z.ZodDefault<z.ZodNumber>;
129
136
  }, z.core.$strip>;
130
137
  export type ContextBudgetConfig = z.infer<typeof ContextBudgetConfigSchema>;
131
138
  export declare const EvidenceConfigSchema: z.ZodObject<{
@@ -451,6 +458,7 @@ export declare const PluginConfigSchema: z.ZodObject<{
451
458
  critical_threshold: z.ZodDefault<z.ZodNumber>;
452
459
  model_limits: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
453
460
  max_injection_tokens: z.ZodDefault<z.ZodNumber>;
461
+ tracked_agents: z.ZodDefault<z.ZodArray<z.ZodString>>;
454
462
  scoring: z.ZodOptional<z.ZodObject<{
455
463
  enabled: z.ZodDefault<z.ZodBoolean>;
456
464
  max_candidates: z.ZodDefault<z.ZodNumber>;
@@ -478,6 +486,12 @@ export declare const PluginConfigSchema: z.ZodObject<{
478
486
  json: z.ZodDefault<z.ZodNumber>;
479
487
  }, z.core.$strip>>;
480
488
  }, z.core.$strip>>;
489
+ enforce: z.ZodDefault<z.ZodBoolean>;
490
+ prune_target: z.ZodDefault<z.ZodNumber>;
491
+ preserve_last_n_turns: z.ZodDefault<z.ZodNumber>;
492
+ recent_window: z.ZodDefault<z.ZodNumber>;
493
+ enforce_on_agent_switch: z.ZodDefault<z.ZodBoolean>;
494
+ tool_output_mask_threshold: z.ZodDefault<z.ZodNumber>;
481
495
  }, z.core.$strip>>;
482
496
  guardrails: z.ZodOptional<z.ZodObject<{
483
497
  enabled: z.ZodDefault<z.ZodBoolean>;
@@ -10,6 +10,9 @@ interface MessageInfo {
10
10
  role: string;
11
11
  agent?: string;
12
12
  sessionID?: string;
13
+ modelID?: string;
14
+ providerID?: string;
15
+ [key: string]: unknown;
13
16
  }
14
17
  interface MessagePart {
15
18
  type: string;
@@ -5,7 +5,9 @@ export { createDelegationGateHook } from './delegation-gate';
5
5
  export { createDelegationTrackerHook } from './delegation-tracker';
6
6
  export { extractCurrentPhase, extractCurrentPhaseFromPlan, extractCurrentTask, extractCurrentTaskFromPlan, extractDecisions, extractIncompleteTasks, extractIncompleteTasksFromPlan, extractPatterns, } from './extractors';
7
7
  export { createGuardrailsHooks } from './guardrails';
8
+ export { classifyMessage, classifyMessages, containsPlanContent, isDuplicateToolRead, isStaleError, isToolResult, MessagePriority, type MessagePriorityType, type MessageWithParts, } from './message-priority';
8
9
  export { consolidateSystemMessages } from './messages-transform';
10
+ export { extractModelInfo, NATIVE_MODEL_LIMITS, PROVIDER_CAPS, resolveModelLimit, } from './model-limits';
9
11
  export { createPhaseMonitorHook } from './phase-monitor';
10
12
  export { createPipelineTrackerHook } from './pipeline-tracker';
11
13
  export { createSystemEnhancerHook } from './system-enhancer';
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Message Priority Classifier Hook
3
+ *
4
+ * Provides zero-cost message priority classification to enable intelligent
5
+ * context pruning. Messages are tagged with priority tiers (0-4) so that
6
+ * low-priority messages are removed first during context budget pressure.
7
+ *
8
+ * Priority tiers:
9
+ * - CRITICAL (0): System prompt, plan state, active instructions
10
+ * - HIGH (1): User messages, current task context, tool definitions
11
+ * - MEDIUM (2): Recent assistant responses, recent tool results
12
+ * - LOW (3): Old assistant responses, old tool results, confirmations
13
+ * - DISPOSABLE (4): Duplicate reads, superseded writes, stale errors
14
+ */
15
+ /**
16
+ * Message priority tiers for context pruning decisions.
17
+ * Lower values = higher priority (kept longer during pruning).
18
+ */
19
+ export declare const MessagePriority: {
20
+ /** System prompt, plan state, active instructions - never prune */
21
+ readonly CRITICAL: 0;
22
+ /** User messages, current task context, tool definitions */
23
+ readonly HIGH: 1;
24
+ /** Recent assistant responses, recent tool results (within recentWindowSize) */
25
+ readonly MEDIUM: 2;
26
+ /** Old assistant responses, old tool results */
27
+ readonly LOW: 3;
28
+ /** Duplicate reads, superseded writes, stale errors - prune first */
29
+ readonly DISPOSABLE: 4;
30
+ };
31
+ export type MessagePriorityType = (typeof MessagePriority)[keyof typeof MessagePriority];
32
+ /** Message structure matching the format from context-budget.ts */
33
+ interface MessageInfo {
34
+ role?: string;
35
+ agent?: string;
36
+ sessionID?: string;
37
+ modelID?: string;
38
+ providerID?: string;
39
+ toolName?: string;
40
+ toolArgs?: unknown;
41
+ [key: string]: unknown;
42
+ }
43
+ interface MessagePart {
44
+ type?: string;
45
+ text?: string;
46
+ [key: string]: unknown;
47
+ }
48
+ export interface MessageWithParts {
49
+ info?: MessageInfo;
50
+ parts?: MessagePart[];
51
+ }
52
+ /**
53
+ * Checks if text contains .swarm/plan or .swarm/context references
54
+ * indicating swarm state that should be preserved.
55
+ *
56
+ * @param text - The text content to check
57
+ * @returns true if the text contains plan/context references
58
+ */
59
+ export declare function containsPlanContent(text: string): boolean;
60
+ /**
61
+ * Checks if a message is a tool result (assistant message with tool call).
62
+ *
63
+ * @param message - The message to check
64
+ * @returns true if the message appears to be a tool result
65
+ */
66
+ export declare function isToolResult(message: MessageWithParts): boolean;
67
+ /**
68
+ * Checks if two consecutive tool read calls are duplicates
69
+ * (same tool with same first argument).
70
+ *
71
+ * @param current - The current message
72
+ * @param previous - The previous message
73
+ * @returns true if this is a duplicate tool read
74
+ */
75
+ export declare function isDuplicateToolRead(current: MessageWithParts, previous: MessageWithParts): boolean;
76
+ /**
77
+ * Checks if a message contains an error pattern and is stale
78
+ * (more than the specified number of turns old).
79
+ *
80
+ * @param text - The message text to check
81
+ * @param turnsAgo - How many turns ago the message was sent
82
+ * @returns true if the message is a stale error
83
+ */
84
+ export declare function isStaleError(text: string, turnsAgo: number): boolean;
85
+ /**
86
+ * Classifies a message by priority tier for intelligent pruning.
87
+ *
88
+ * @param message - The message to classify
89
+ * @param index - Position in messages array (0-indexed)
90
+ * @param totalMessages - Total number of messages
91
+ * @param recentWindowSize - Number of recent messages to consider MEDIUM (default 10)
92
+ * @returns Priority tier (0=CRITICAL, 1=HIGH, 2=MEDIUM, 3=LOW, 4=DISPOSABLE)
93
+ */
94
+ export declare function classifyMessage(message: MessageWithParts, index: number, totalMessages: number, recentWindowSize?: number): MessagePriorityType;
95
+ /**
96
+ * Classifies a batch of messages with duplicate detection.
97
+ * This function should be called in order (oldest to newest) to properly
98
+ * detect consecutive duplicate tool reads.
99
+ *
100
+ * @param messages - Array of messages to classify
101
+ * @param recentWindowSize - Number of recent messages to consider MEDIUM (default 10)
102
+ * @returns Array of priority classifications matching message order
103
+ */
104
+ export declare function classifyMessages(messages: MessageWithParts[], recentWindowSize?: number): MessagePriorityType[];
105
+ export {};
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Provider-Aware Model Limit Resolution
3
+ *
4
+ * Resolves context window limits based on the model and provider platform.
5
+ * The same model has different context limits depending on the provider:
6
+ * - Claude Sonnet 4.6: 200k native, 128k on Copilot
7
+ * - GPT-5: 400k native, 128k on Copilot
8
+ * - Copilot caps ALL models at 128k prompt, regardless of native limit
9
+ */
10
+ /**
11
+ * Native model context limits (in tokens) when used on their native platform.
12
+ */
13
+ export declare const NATIVE_MODEL_LIMITS: Record<string, number>;
14
+ /**
15
+ * Provider-specific context caps that override native limits.
16
+ * These are typically lower than native limits (e.g., Copilot caps at 128k).
17
+ */
18
+ export declare const PROVIDER_CAPS: Record<string, number>;
19
+ /**
20
+ * Message structure from experimental.chat.messages.transform hook.
21
+ */
22
+ interface MessageInfo {
23
+ role: string;
24
+ agent?: string;
25
+ sessionID?: string;
26
+ modelID?: string;
27
+ providerID?: string;
28
+ [key: string]: unknown;
29
+ }
30
+ interface MessagePart {
31
+ type: string;
32
+ text?: string;
33
+ [key: string]: unknown;
34
+ }
35
+ interface MessageWithParts {
36
+ info: MessageInfo;
37
+ parts: MessagePart[];
38
+ }
39
+ /**
40
+ * Extracts modelID and providerID from the most recent assistant message.
41
+ *
42
+ * @param messages - Array of messages from experimental.chat.messages.transform hook
43
+ * @returns Object containing modelID and/or providerID if found
44
+ *
45
+ * @example
46
+ * const info = extractModelInfo(messages);
47
+ * // Returns: { modelID: 'claude-sonnet-4-6', providerID: 'anthropic' }
48
+ * // Or: {} if no assistant messages or fields not found
49
+ */
50
+ export declare function extractModelInfo(messages: MessageWithParts[]): {
51
+ modelID?: string;
52
+ providerID?: string;
53
+ };
54
+ /**
55
+ * Resolves the context limit for a given model/provider combination.
56
+ *
57
+ * Resolution order (first match wins):
58
+ * 1. Check configOverrides["provider/model"] (e.g., "copilot/claude-sonnet-4-6": 200000)
59
+ * 2. Check configOverrides[modelID] (e.g., "claude-sonnet-4-6": 200000)
60
+ * 3. Check PROVIDER_CAPS[providerID] (e.g., copilot → 128000)
61
+ * 4. Check NATIVE_MODEL_LIMITS with prefix matching (e.g., "claude-sonnet-4" matches "claude-sonnet-4-6-20260301")
62
+ * 5. Check configOverrides.default
63
+ * 6. Fall back to 128000
64
+ *
65
+ * @param modelID - The model identifier (e.g., "claude-sonnet-4-6", "gpt-5")
66
+ * @param providerID - The provider identifier (e.g., "copilot", "anthropic")
67
+ * @param configOverrides - User configuration overrides
68
+ * @returns The resolved context limit in tokens
69
+ *
70
+ * @example
71
+ * // Provider cap (copilot)
72
+ * resolveModelLimit("claude-sonnet-4-6", "copilot", {})
73
+ * // Returns: 128000
74
+ *
75
+ * @example
76
+ * // Native limit (anthropic)
77
+ * resolveModelLimit("claude-sonnet-4-6", "anthropic", {})
78
+ * // Returns: 200000
79
+ *
80
+ * @example
81
+ * // Override beats cap
82
+ * resolveModelLimit("gpt-5", "copilot", { "copilot/gpt-5": 200000 })
83
+ * // Returns: 200000
84
+ *
85
+ * @example
86
+ * // Prefix match for model variants
87
+ * resolveModelLimit("claude-sonnet-4-6-20260301", "anthropic", {})
88
+ * // Returns: 200000
89
+ *
90
+ * @example
91
+ * // Full fallback
92
+ * resolveModelLimit(undefined, undefined, {})
93
+ * // Returns: 128000
94
+ */
95
+ export declare function resolveModelLimit(modelID?: string, providerID?: string, configOverrides?: Record<string, number>): number;
96
+ export {};