opencode-swarm 6.19.7 → 6.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.
@@ -0,0 +1,25 @@
1
+ /** Project Identity Management for opencode-swarm.
2
+ * Handles creation and retrieval of project identity files.
3
+ */
4
+ export interface ProjectIdentity {
5
+ projectHash: string;
6
+ projectName: string;
7
+ repoUrl?: string;
8
+ absolutePath: string;
9
+ createdAt: string;
10
+ swarmVersion: string;
11
+ }
12
+ /**
13
+ * Get identity file path for a project hash.
14
+ * Path: {platform-config-dir}/projects/{projectHash}/identity.json
15
+ */
16
+ export declare function resolveIdentityPath(projectHash: string): string;
17
+ /**
18
+ * Read existing identity.json or return null if it doesn't exist.
19
+ */
20
+ export declare function readProjectIdentity(projectHash: string): Promise<ProjectIdentity | null>;
21
+ /**
22
+ * Create or update identity.json for a project.
23
+ * Uses atomic write pattern (write to temp file, then rename).
24
+ */
25
+ export declare function writeProjectIdentity(directory: string, projectHash: string, projectName: string): Promise<ProjectIdentity>;
@@ -0,0 +1,2 @@
1
+ /** Knowledge system exports for opencode-swarm. */
2
+ export * from './identity.js';
@@ -0,0 +1,27 @@
1
+ export type AgentType = 'architect' | 'coder' | 'reviewer' | 'test_engineer' | 'explorer' | 'sme' | 'critic' | 'docs' | 'designer';
2
+ export type OutputType = 'review' | 'test' | 'research' | 'analysis' | 'summary';
3
+ export interface AgentOutputMetadata {
4
+ agent: AgentType;
5
+ type: OutputType;
6
+ taskId: string;
7
+ phase: number;
8
+ timestamp: string;
9
+ durationMs?: number;
10
+ success?: boolean;
11
+ }
12
+ /**
13
+ * Write agent output to persistent storage
14
+ * Output: .swarm/outputs/phase-N/task-N.M/{agent}-{type}-{timestamp}.md
15
+ */
16
+ export declare function writeAgentOutput(directory: string, metadata: AgentOutputMetadata, content: string): Promise<string>;
17
+ /**
18
+ * Read agent output from persistent storage
19
+ */
20
+ export declare function readAgentOutput(directory: string, phase: number, taskId: string): Promise<{
21
+ metadata: AgentOutputMetadata;
22
+ content: string;
23
+ }[]>;
24
+ /**
25
+ * List all agent outputs for a phase
26
+ */
27
+ export declare function listAgentOutputs(directory: string, phase?: number): Promise<AgentOutputMetadata[]>;
@@ -0,0 +1 @@
1
+ export { type AgentOutputMetadata, type AgentType, listAgentOutputs, type OutputType, readAgentOutput, writeAgentOutput, } from './agent-writer';
@@ -0,0 +1,34 @@
1
+ export interface TaskNode {
2
+ id: string;
3
+ phase: number;
4
+ description: string;
5
+ depends: string[];
6
+ dependents: string[];
7
+ status: 'pending' | 'in_progress' | 'complete' | 'blocked';
8
+ }
9
+ export interface DependencyGraph {
10
+ tasks: Map<string, TaskNode>;
11
+ phases: Map<number, string[]>;
12
+ roots: string[];
13
+ leaves: string[];
14
+ }
15
+ /**
16
+ * Parse plan.json and build dependency graph
17
+ */
18
+ export declare function parseDependencyGraph(planPath: string): DependencyGraph;
19
+ /**
20
+ * Get tasks that can run in parallel (no unresolved dependencies)
21
+ */
22
+ export declare function getRunnableTasks(graph: DependencyGraph): string[];
23
+ /**
24
+ * Check if a task is blocked (has incomplete dependencies)
25
+ */
26
+ export declare function isTaskBlocked(graph: DependencyGraph, taskId: string): boolean;
27
+ /**
28
+ * Get execution order (topological sort)
29
+ */
30
+ export declare function getExecutionOrder(graph: DependencyGraph): string[];
31
+ /**
32
+ * Find all paths from root to a task
33
+ */
34
+ export declare function getDependencyChain(graph: DependencyGraph, taskId: string): string[];
@@ -0,0 +1,33 @@
1
+ export interface FileLock {
2
+ filePath: string;
3
+ agent: string;
4
+ taskId: string;
5
+ timestamp: string;
6
+ expiresAt: number;
7
+ }
8
+ /**
9
+ * Try to acquire a lock on a file
10
+ */
11
+ export declare function tryAcquireLock(directory: string, filePath: string, agent: string, taskId: string): {
12
+ acquired: true;
13
+ lock: FileLock;
14
+ } | {
15
+ acquired: false;
16
+ existing?: FileLock;
17
+ };
18
+ /**
19
+ * Release a lock on a file
20
+ */
21
+ export declare function releaseLock(directory: string, filePath: string, taskId: string): boolean;
22
+ /**
23
+ * Check if a file is locked
24
+ */
25
+ export declare function isLocked(directory: string, filePath: string): FileLock | null;
26
+ /**
27
+ * Clean up expired locks
28
+ */
29
+ export declare function cleanupExpiredLocks(directory: string): number;
30
+ /**
31
+ * List all active locks
32
+ */
33
+ export declare function listActiveLocks(directory: string): FileLock[];
@@ -0,0 +1,4 @@
1
+ export { type DependencyGraph, getDependencyChain, getExecutionOrder, getRunnableTasks, isTaskBlocked, parseDependencyGraph, type TaskNode, } from './dependency-graph.js';
2
+ export { cleanupExpiredLocks, type FileLock, isLocked, listActiveLocks, releaseLock, tryAcquireLock, } from './file-locks.js';
3
+ export { extractMetaSummaries, getLatestTaskSummary, indexMetaSummaries, type MetaSummaryEntry, querySummaries, } from './meta-indexer.js';
4
+ export { type ComplexityMetrics, computeComplexity, type ReviewDepth, type ReviewRouting, routeReview, routeReviewForChanges, shouldParallelizeReview, } from './review-router.js';
@@ -0,0 +1,32 @@
1
+ export interface MetaSummaryEntry {
2
+ timestamp: string;
3
+ phase?: number;
4
+ taskId?: string;
5
+ agent?: string;
6
+ summary: string;
7
+ source?: string;
8
+ }
9
+ /**
10
+ * Extract meta.summary from event JSONL files
11
+ */
12
+ export declare function extractMetaSummaries(eventsPath: string): MetaSummaryEntry[];
13
+ /**
14
+ * Index meta summaries to external knowledge store
15
+ */
16
+ export declare function indexMetaSummaries(directory: string, externalKnowledgeDir?: string): Promise<{
17
+ indexed: number;
18
+ path: string;
19
+ }>;
20
+ /**
21
+ * Query indexed summaries
22
+ */
23
+ export declare function querySummaries(directory: string, options?: {
24
+ phase?: number;
25
+ taskId?: string;
26
+ agent?: string;
27
+ since?: string;
28
+ }): MetaSummaryEntry[];
29
+ /**
30
+ * Get latest summary for a task
31
+ */
32
+ export declare function getLatestTaskSummary(directory: string, taskId: string): MetaSummaryEntry | undefined;
@@ -0,0 +1,29 @@
1
+ export type ReviewDepth = 'single' | 'double';
2
+ export interface ReviewRouting {
3
+ reviewerCount: number;
4
+ testEngineerCount: number;
5
+ depth: ReviewDepth;
6
+ reason: string;
7
+ }
8
+ export interface ComplexityMetrics {
9
+ fileCount: number;
10
+ functionCount: number;
11
+ astChangeCount: number;
12
+ maxFileComplexity: number;
13
+ }
14
+ /**
15
+ * Compute complexity metrics for a set of files
16
+ */
17
+ export declare function computeComplexity(directory: string, changedFiles: string[]): Promise<ComplexityMetrics>;
18
+ /**
19
+ * Determine review routing based on complexity
20
+ */
21
+ export declare function routeReview(metrics: ComplexityMetrics): ReviewRouting;
22
+ /**
23
+ * Route review with full analysis
24
+ */
25
+ export declare function routeReviewForChanges(directory: string, changedFiles: string[]): Promise<ReviewRouting>;
26
+ /**
27
+ * Check if review should be parallelized
28
+ */
29
+ export declare function shouldParallelizeReview(routing: ReviewRouting): boolean;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Context Budget Service
3
+ *
4
+ * Provides context budget monitoring for swarm sessions.
5
+ * Tracks token usage across all context components and provides
6
+ * warnings when approaching budget limits.
7
+ */
8
+ /**
9
+ * Context budget report with detailed token breakdown
10
+ */
11
+ export interface ContextBudgetReport {
12
+ /** ISO timestamp when the report was generated */
13
+ timestamp: string;
14
+ /** Tokens used for the assembled system prompt */
15
+ systemPromptTokens: number;
16
+ /** Tokens used for the plan cursor */
17
+ planCursorTokens: number;
18
+ /** Tokens used for knowledge entries */
19
+ knowledgeTokens: number;
20
+ /** Tokens used for run memory */
21
+ runMemoryTokens: number;
22
+ /** Tokens used for handoff content */
23
+ handoffTokens: number;
24
+ /** Tokens used for context.md */
25
+ contextMdTokens: number;
26
+ /** Total swarm context tokens (sum of all components) */
27
+ swarmTotalTokens: number;
28
+ /** Estimated number of turns in this session */
29
+ estimatedTurnCount: number;
30
+ /** Estimated total tokens for the session */
31
+ estimatedSessionTokens: number;
32
+ /** Budget usage percentage */
33
+ budgetPct: number;
34
+ /** Current budget status */
35
+ status: 'ok' | 'warning' | 'critical';
36
+ /** Recommendation message if any */
37
+ recommendation: string | null;
38
+ }
39
+ /**
40
+ * Configuration for context budget monitoring
41
+ */
42
+ export interface ContextBudgetConfig {
43
+ /** Enable or disable budget monitoring */
44
+ enabled: boolean;
45
+ /** Maximum token budget (default: 40000) */
46
+ budgetTokens: number;
47
+ /** Warning threshold percentage (default: 70) */
48
+ warningPct: number;
49
+ /** Critical threshold percentage (default: 90) */
50
+ criticalPct: number;
51
+ /** Warning mode: 'once', 'every', or 'interval' */
52
+ warningMode: 'once' | 'every' | 'interval';
53
+ /** Interval for warning mode (default: 20 turns) */
54
+ warningIntervalTurns: number;
55
+ }
56
+ /**
57
+ * Budget state for tracking warning suppression
58
+ */
59
+ export interface BudgetState {
60
+ /** Turn number when warning was last fired */
61
+ warningFiredAtTurn: number | null;
62
+ /** Turn number when critical was last fired */
63
+ criticalFiredAtTurn: number | null;
64
+ /** Turn number when context was last injected */
65
+ lastInjectedAtTurn: number | null;
66
+ }
67
+ /**
68
+ * Default context budget configuration
69
+ */
70
+ export declare const DEFAULT_CONTEXT_BUDGET_CONFIG: ContextBudgetConfig;
71
+ /**
72
+ * Estimate token count for text using character-based approximation
73
+ *
74
+ * @param text - The text to estimate tokens for
75
+ * @returns Estimated token count (ceiling of chars / 3.5)
76
+ */
77
+ export declare function estimateTokens(text: string): number;
78
+ /**
79
+ * Get context budget report with detailed token breakdown
80
+ *
81
+ * @param directory - The swarm workspace directory
82
+ * @param assembledSystemPrompt - The fully assembled system prompt
83
+ * @param config - Budget configuration
84
+ * @returns Context budget report
85
+ */
86
+ export declare function getContextBudgetReport(directory: string, assembledSystemPrompt: string, config: ContextBudgetConfig): Promise<ContextBudgetReport>;
87
+ /**
88
+ * Format budget warning message based on report
89
+ *
90
+ * @param report - The context budget report
91
+ * @param directory - Directory for state persistence (required for suppression logic)
92
+ * @param config - Budget configuration for warning mode settings
93
+ * @returns Warning message string or null if suppressed/ok
94
+ */
95
+ export declare function formatBudgetWarning(report: ContextBudgetReport, directory: string, config: ContextBudgetConfig): Promise<string | null>;
96
+ /**
97
+ * Get default context budget config
98
+ *
99
+ * @returns Default configuration
100
+ */
101
+ export declare function getDefaultConfig(): ContextBudgetConfig;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Handoff Service
3
+ *
4
+ * Provides structured handoff data for agent transitions between swarm sessions.
5
+ * Reads from .swarm files to gather current state for context-efficient handoffs.
6
+ */
7
+ /**
8
+ * Pending QA state from agent sessions
9
+ */
10
+ export interface PendingQA {
11
+ taskId: string;
12
+ lastFailure: string | null;
13
+ }
14
+ /**
15
+ * Delegation chain entry
16
+ */
17
+ export interface DelegationEntry {
18
+ from: string;
19
+ to: string;
20
+ taskId: string;
21
+ timestamp: number;
22
+ }
23
+ /**
24
+ * Delegation state from session snapshot
25
+ */
26
+ export interface DelegationState {
27
+ activeChains: string[];
28
+ delegationDepth: number;
29
+ pendingHandoffs: string[];
30
+ }
31
+ /**
32
+ * Structured handoff data for agent transitions
33
+ */
34
+ export interface HandoffData {
35
+ /** ISO timestamp when data was generated */
36
+ generated: string;
37
+ /** Current phase number or name */
38
+ currentPhase: string | null;
39
+ /** Current task ID being worked on */
40
+ currentTask: string | null;
41
+ /** List of incomplete task IDs */
42
+ incompleteTasks: string[];
43
+ /** Pending QA state */
44
+ pendingQA: PendingQA | null;
45
+ /** Active agent name */
46
+ activeAgent: string | null;
47
+ /** Recent decisions from context.md */
48
+ recentDecisions: string[];
49
+ /** Delegation state */
50
+ delegationState: DelegationState | null;
51
+ }
52
+ /**
53
+ * Get handoff data from the swarm directory.
54
+ * Reads session state, plan, and context to build comprehensive handoff info.
55
+ */
56
+ export declare function getHandoffData(directory: string): Promise<HandoffData>;
57
+ /**
58
+ * Format handoff data as terse markdown for LLM consumption.
59
+ * Targets under 2K tokens for efficient context injection.
60
+ */
61
+ export declare function formatHandoffMarkdown(data: HandoffData): string;
@@ -1,9 +1,11 @@
1
1
  export { analyzeDecisionDrift, DEFAULT_DRIFT_CONFIG, type Decision, type DriftAnalysisResult, type DriftAnalyzerConfig, type DriftSeverity, type DriftSignal, extractDecisionsFromContext, findContradictions, formatDriftForContext, } from './decision-drift-analyzer';
2
2
  export { applySafeAutoFixes, type ConfigBackup, type ConfigDoctorResult, type ConfigFinding, type ConfigFix, createConfigBackup, type FindingSeverity, getConfigPaths, runConfigDoctor, runConfigDoctorWithFixes, shouldRunOnStartup, writeBackupArtifact, writeDoctorArtifact, } from './config-doctor';
3
+ export { type BudgetState, type ContextBudgetConfig, type ContextBudgetReport, DEFAULT_CONTEXT_BUDGET_CONFIG, estimateTokens, formatBudgetWarning, getContextBudgetReport, getDefaultConfig, } from './context-budget-service';
3
4
  export { type DiagnoseData, formatDiagnoseMarkdown, getDiagnoseData, type HealthCheck, handleDiagnoseCommand, } from './diagnose-service';
4
5
  export { type EvidenceEntryData, type EvidenceListData, formatEvidenceListMarkdown, formatTaskEvidenceMarkdown, getEvidenceListData, getTaskEvidenceData, getVerdictEmoji, handleEvidenceCommand, type TaskEvidenceData, } from './evidence-service';
5
6
  export { buildEvidenceSummary, EVIDENCE_SUMMARY_VERSION, type EvidenceSummaryArtifact, isAutoSummaryEnabled, type PhaseBlocker, type PhaseEvidenceSummary, REQUIRED_EVIDENCE_TYPES, type TaskEvidenceSummary, } from './evidence-summary-service';
6
7
  export { type ExportData, formatExportMarkdown, getExportData, handleExportCommand, } from './export-service';
8
+ export { type DelegationState, formatHandoffMarkdown, getHandoffData, type HandoffData, type PendingQA, } from './handoff-service';
7
9
  export { formatHistoryMarkdown, getHistoryData, type HistoryData, handleHistoryCommand, type PhaseHistoryData, } from './history-service';
8
10
  export { formatPlanMarkdown, getPlanData, handlePlanCommand, type PlanData, } from './plan-service';
9
11
  export { createPreflightIntegration, type PreflightIntegrationConfig, runManualPreflight, } from './preflight-integration';
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Run Memory Service
3
+ *
4
+ * Provides append-only per-task outcome logging for tracking task execution
5
+ * results across swarm sessions. Used to avoid repeating known failure patterns.
6
+ */
7
+ /**
8
+ * Represents a single task execution outcome entry
9
+ */
10
+ export interface RunMemoryEntry {
11
+ /** ISO timestamp when the entry was recorded */
12
+ timestamp: string;
13
+ /** Plan.json task ID (e.g. "3.2") */
14
+ taskId: string;
15
+ /** SHA256 hash of taskId + sorted file targets, first 8 chars */
16
+ taskFingerprint: string;
17
+ /** Which agent executed the task (e.g. "mega_coder") */
18
+ agent: string;
19
+ /** Outcome of the task execution */
20
+ outcome: 'pass' | 'fail' | 'retry' | 'skip';
21
+ /** 1-indexed attempt number */
22
+ attemptNumber: number;
23
+ /** One-line failure reason (only for fail/retry outcomes) */
24
+ failureReason?: string;
25
+ /** Files that were modified during this attempt */
26
+ filesModified?: string[];
27
+ /** Wall-clock time in milliseconds */
28
+ durationMs?: number;
29
+ }
30
+ /**
31
+ * Generate a task fingerprint from taskId and file targets
32
+ *
33
+ * @param taskId - The task identifier
34
+ * @param fileTargets - Array of file paths that were targeted
35
+ * @returns First 8 characters of SHA256 hash
36
+ */
37
+ export declare function generateTaskFingerprint(taskId: string, fileTargets: string[]): string;
38
+ /**
39
+ * Append a task outcome entry to the run memory log
40
+ *
41
+ * @param directory - The swarm workspace directory
42
+ * @param entry - The outcome entry to record
43
+ */
44
+ export declare function recordOutcome(directory: string, entry: RunMemoryEntry): Promise<void>;
45
+ /**
46
+ * Get all entries for a specific task ID
47
+ *
48
+ * @param directory - The swarm workspace directory
49
+ * @param taskId - The task identifier to filter by
50
+ * @returns Array of matching entries
51
+ */
52
+ export declare function getTaskHistory(directory: string, taskId: string): Promise<RunMemoryEntry[]>;
53
+ /**
54
+ * Get all failure and retry entries
55
+ *
56
+ * @param directory - The swarm workspace directory
57
+ * @returns Array of fail/retry entries
58
+ */
59
+ export declare function getFailures(directory: string): Promise<RunMemoryEntry[]>;
60
+ /**
61
+ * Generate a compact summary of task failures for context injection
62
+ *
63
+ * @param directory - The swarm workspace directory
64
+ * @returns Formatted summary string (≤500 tokens) or null if no failures
65
+ */
66
+ export declare function getRunMemorySummary(directory: string): Promise<string | null>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Skill definition with versioning and per-agent overlays
3
+ */
4
+ export interface AgentOverlay {
5
+ agent: string;
6
+ prompt?: string;
7
+ model?: string;
8
+ }
9
+ export interface SkillDefinition {
10
+ id: string;
11
+ name: string;
12
+ description: string;
13
+ SKILL_VERSION: number;
14
+ basePrompt?: string;
15
+ agents?: AgentOverlay[];
16
+ }
17
+ export declare const skills: SkillDefinition[];
18
+ export declare const AGENT_OVERLAYS: Record<string, AgentOverlay[]>;
19
+ /**
20
+ * Get skill by ID
21
+ */
22
+ export declare function getSkill(id: string): SkillDefinition | undefined;
23
+ /**
24
+ * Get agent overlay for a skill
25
+ */
26
+ export declare function getAgentOverlay(skillId: string, agent: string): AgentOverlay | undefined;
27
+ /**
28
+ * Resolve effective prompt for an agent on a skill
29
+ */
30
+ export declare function resolveAgentPrompt(skillId: string, agent: string, defaultPrompt: string): string;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Delegation Envelope Types
3
+ * Interface for passing delegated tasks between agents
4
+ */
5
+ export interface DelegationEnvelope {
6
+ taskId: string;
7
+ targetAgent: string;
8
+ action: string;
9
+ commandType: 'task' | 'slash_command';
10
+ files: string[];
11
+ acceptanceCriteria: string[];
12
+ technicalContext: string;
13
+ errorStrategy?: 'FAIL_FAST' | 'BEST_EFFORT';
14
+ platformNotes?: string;
15
+ }
16
+ /**
17
+ * Validation result types
18
+ */
19
+ export type EnvelopeValidationResult = {
20
+ valid: true;
21
+ } | {
22
+ valid: false;
23
+ reason: string;
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-swarm",
3
- "version": "6.19.7",
3
+ "version": "6.20.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",