opencode-swarm 4.4.0 → 5.0.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.
@@ -0,0 +1 @@
1
+ export { derivePlanMarkdown, loadPlan, migrateLegacyPlan, savePlan, updateTaskStatus, } from './manager';
@@ -0,0 +1,33 @@
1
+ import { type Plan, type TaskStatus } from '../config/plan-schema';
2
+ /**
3
+ * Load plan.json ONLY without auto-migration from plan.md.
4
+ * Returns null if plan.json doesn't exist or is invalid.
5
+ * Use this when you want to check for structured plans without triggering migration.
6
+ */
7
+ export declare function loadPlanJsonOnly(directory: string): Promise<Plan | null>;
8
+ /**
9
+ * Load and validate plan from .swarm/plan.json with 4-step precedence:
10
+ * 1. .swarm/plan.json exists AND validates → return parsed Plan
11
+ * 2. .swarm/plan.json exists but FAILS validation → log warning, fall to step 3
12
+ * 3. .swarm/plan.md exists → call migrateLegacyPlan(), save result, return it
13
+ * 4. Neither exists → return null
14
+ */
15
+ export declare function loadPlan(directory: string): Promise<Plan | null>;
16
+ /**
17
+ * Validate against PlanSchema (throw on invalid), write to .swarm/plan.json via atomic temp+rename pattern,
18
+ * then derive and write .swarm/plan.md
19
+ */
20
+ export declare function savePlan(directory: string, plan: Plan): Promise<void>;
21
+ /**
22
+ * Load plan → find task by ID → update status → save → return updated plan.
23
+ * Throw if plan not found or task not found.
24
+ */
25
+ export declare function updateTaskStatus(directory: string, taskId: string, status: TaskStatus): Promise<Plan>;
26
+ /**
27
+ * Generate markdown view from plan object
28
+ */
29
+ export declare function derivePlanMarkdown(plan: Plan): string;
30
+ /**
31
+ * Convert existing plan.md to plan.json. PURE function — no I/O.
32
+ */
33
+ export declare function migrateLegacyPlan(planContent: string, swarmId?: string): Plan;
package/dist/state.d.ts CHANGED
@@ -33,6 +33,29 @@ export interface DelegationEntry {
33
33
  to: string;
34
34
  timestamp: number;
35
35
  }
36
+ /**
37
+ * Represents per-session state for guardrail tracking
38
+ */
39
+ export interface AgentSessionState {
40
+ /** Which agent this session belongs to */
41
+ agentName: string;
42
+ /** Date.now() when session started */
43
+ startTime: number;
44
+ /** Total tool calls in this session */
45
+ toolCallCount: number;
46
+ /** Consecutive errors (reset on success) */
47
+ consecutiveErrors: number;
48
+ /** Circular buffer of recent tool calls, max 20 entries */
49
+ recentToolCalls: Array<{
50
+ tool: string;
51
+ argsHash: number;
52
+ timestamp: number;
53
+ }>;
54
+ /** Whether a soft warning has been issued */
55
+ warningIssued: boolean;
56
+ /** Whether a hard limit has been triggered */
57
+ hardLimitHit: boolean;
58
+ }
36
59
  /**
37
60
  * Singleton state object for sharing data across hooks
38
61
  */
@@ -47,8 +70,29 @@ export declare const swarmState: {
47
70
  delegationChains: Map<string, DelegationEntry[]>;
48
71
  /** Number of events since last flush */
49
72
  pendingEvents: number;
73
+ /** Per-session guardrail state — keyed by sessionID */
74
+ agentSessions: Map<string, AgentSessionState>;
50
75
  };
51
76
  /**
52
77
  * Reset all state to initial values - useful for testing
53
78
  */
54
79
  export declare function resetSwarmState(): void;
80
+ /**
81
+ * Start a new agent session with initialized guardrail state.
82
+ * Also removes any stale sessions older than staleDurationMs.
83
+ * @param sessionId - The session identifier
84
+ * @param agentName - The agent associated with this session
85
+ * @param staleDurationMs - Age threshold for stale session eviction (default: 60 min)
86
+ */
87
+ export declare function startAgentSession(sessionId: string, agentName: string, staleDurationMs?: number): void;
88
+ /**
89
+ * End an agent session by removing it from the state.
90
+ * @param sessionId - The session identifier to remove
91
+ */
92
+ export declare function endAgentSession(sessionId: string): void;
93
+ /**
94
+ * Get an agent session state by session ID.
95
+ * @param sessionId - The session identifier
96
+ * @returns The AgentSessionState or undefined if not found
97
+ */
98
+ export declare function getAgentSession(sessionId: string): AgentSessionState | undefined;
package/dist/state.js ADDED
@@ -0,0 +1,48 @@
1
+ // src/state.ts
2
+ var swarmState = {
3
+ activeToolCalls: new Map,
4
+ toolAggregates: new Map,
5
+ activeAgent: new Map,
6
+ delegationChains: new Map,
7
+ pendingEvents: 0,
8
+ agentSessions: new Map
9
+ };
10
+ function resetSwarmState() {
11
+ swarmState.activeToolCalls.clear();
12
+ swarmState.toolAggregates.clear();
13
+ swarmState.activeAgent.clear();
14
+ swarmState.delegationChains.clear();
15
+ swarmState.pendingEvents = 0;
16
+ swarmState.agentSessions.clear();
17
+ }
18
+ function startAgentSession(sessionId, agentName, staleDurationMs = 3600000) {
19
+ const now = Date.now();
20
+ for (const [id, session] of swarmState.agentSessions) {
21
+ if (now - session.startTime > staleDurationMs) {
22
+ swarmState.agentSessions.delete(id);
23
+ }
24
+ }
25
+ const sessionState = {
26
+ agentName,
27
+ startTime: now,
28
+ toolCallCount: 0,
29
+ consecutiveErrors: 0,
30
+ recentToolCalls: [],
31
+ warningIssued: false,
32
+ hardLimitHit: false
33
+ };
34
+ swarmState.agentSessions.set(sessionId, sessionState);
35
+ }
36
+ function endAgentSession(sessionId) {
37
+ swarmState.agentSessions.delete(sessionId);
38
+ }
39
+ function getAgentSession(sessionId) {
40
+ return swarmState.agentSessions.get(sessionId);
41
+ }
42
+ export {
43
+ swarmState,
44
+ startAgentSession,
45
+ resetSwarmState,
46
+ getAgentSession,
47
+ endAgentSession
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-swarm",
3
- "version": "4.4.0",
3
+ "version": "5.0.0",
4
4
  "description": "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",