opencode-swarm 6.19.7 → 6.19.8
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/README.md +113 -0
- package/dist/cli/index.js +707 -3377
- package/dist/commands/handoff.d.ts +1 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/index.js +1068 -348
- package/dist/services/context-budget-service.d.ts +101 -0
- package/dist/services/handoff-service.d.ts +61 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/run-memory.d.ts +66 -0
- package/package.json +1 -1
|
@@ -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;
|
package/dist/services/index.d.ts
CHANGED
|
@@ -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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-swarm",
|
|
3
|
-
"version": "6.19.
|
|
3
|
+
"version": "6.19.8",
|
|
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",
|