opencode-swarm 6.43.2 → 6.44.1
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/dist/cli/index.js +783 -347
- package/dist/config/constants.d.ts +13 -0
- package/dist/index.js +1688 -1128
- package/dist/plan/checkpoint.d.ts +25 -0
- package/dist/plan/checkpoint.test.d.ts +1 -0
- package/dist/plan/ledger-integrity.test.d.ts +5 -0
- package/dist/plan/ledger-snapshot-adversarial.test.d.ts +1 -0
- package/dist/plan/ledger.d.ts +196 -0
- package/dist/plan/ledger.test.d.ts +1 -0
- package/dist/plan/manager.d.ts +9 -0
- package/dist/plan/manager.ledger-aware.test.d.ts +1 -0
- package/dist/tools/lint.d.ts +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Plan } from '../config/plan-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Write SWARM_PLAN.json and SWARM_PLAN.md to the project root directory.
|
|
4
|
+
* Non-blocking: logs a warning on failure but never throws.
|
|
5
|
+
* @param directory - The working directory (project root)
|
|
6
|
+
*/
|
|
7
|
+
export declare function writeCheckpoint(directory: string): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Result of an importCheckpoint operation.
|
|
10
|
+
*/
|
|
11
|
+
export interface ImportCheckpointResult {
|
|
12
|
+
success: boolean;
|
|
13
|
+
plan?: Plan;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Import a checkpoint from SWARM_PLAN.json at the project root.
|
|
18
|
+
* Validates the checkpoint against PlanSchema, persists it as the live plan
|
|
19
|
+
* via savePlan, and appends a 'plan_rebuilt' ledger event.
|
|
20
|
+
*
|
|
21
|
+
* @param directory - The working directory (project root)
|
|
22
|
+
* @param source - Optional source identifier for the ledger event (defaults to 'external_reseed')
|
|
23
|
+
* @returns ImportCheckpointResult indicating success or failure with error message
|
|
24
|
+
*/
|
|
25
|
+
export declare function importCheckpoint(directory: string, source?: string): Promise<ImportCheckpointResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append-only Plan Ledger
|
|
3
|
+
*
|
|
4
|
+
* Provides durable, immutable audit trail of plan evolution events.
|
|
5
|
+
* Each event is written as a JSON line to .swarm/plan-ledger.jsonl
|
|
6
|
+
*/
|
|
7
|
+
import type { Plan } from '../config/plan-schema';
|
|
8
|
+
/**
|
|
9
|
+
* Ledger schema version
|
|
10
|
+
*/
|
|
11
|
+
export declare const LEDGER_SCHEMA_VERSION = "1.0.0";
|
|
12
|
+
/**
|
|
13
|
+
* Valid ledger event types
|
|
14
|
+
*/
|
|
15
|
+
export declare const LEDGER_EVENT_TYPES: readonly ["plan_created", "task_added", "task_updated", "task_status_changed", "task_reordered", "phase_completed", "plan_rebuilt", "plan_exported", "plan_reset", "snapshot"];
|
|
16
|
+
export type LedgerEventType = (typeof LEDGER_EVENT_TYPES)[number];
|
|
17
|
+
/**
|
|
18
|
+
* A ledger event representing a plan mutation.
|
|
19
|
+
* All fields are required unless marked optional.
|
|
20
|
+
*/
|
|
21
|
+
export interface LedgerEvent {
|
|
22
|
+
/** Monotonically increasing sequence number (starts at 1) */
|
|
23
|
+
seq: number;
|
|
24
|
+
/** ISO 8601 timestamp when event was recorded */
|
|
25
|
+
timestamp: string;
|
|
26
|
+
/** Unique identifier for the plan */
|
|
27
|
+
plan_id: string;
|
|
28
|
+
/** Type of event that occurred */
|
|
29
|
+
event_type: LedgerEventType;
|
|
30
|
+
/** Task ID when event relates to a specific task */
|
|
31
|
+
task_id?: string;
|
|
32
|
+
/** Phase ID when event relates to a specific phase */
|
|
33
|
+
phase_id?: number;
|
|
34
|
+
/** Previous status (for status change events) */
|
|
35
|
+
from_status?: string;
|
|
36
|
+
/** New status (for status change events) */
|
|
37
|
+
to_status?: string;
|
|
38
|
+
/** What triggered this event */
|
|
39
|
+
source: string;
|
|
40
|
+
/** SHA-256 hash of plan state before this event */
|
|
41
|
+
plan_hash_before: string;
|
|
42
|
+
/** SHA-256 hash of plan state after this event */
|
|
43
|
+
plan_hash_after: string;
|
|
44
|
+
/** Schema version for this ledger entry */
|
|
45
|
+
schema_version: string;
|
|
46
|
+
/** Optional payload for events that carry additional data */
|
|
47
|
+
payload?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Input type for appendLedgerEvent (excludes auto-generated fields)
|
|
51
|
+
*/
|
|
52
|
+
export type LedgerEventInput = Omit<LedgerEvent, 'seq' | 'timestamp' | 'plan_hash_before' | 'plan_hash_after' | 'schema_version'>;
|
|
53
|
+
/**
|
|
54
|
+
* Payload for snapshot ledger events.
|
|
55
|
+
* Embeds the full Plan payload for ledger-only rebuild.
|
|
56
|
+
*/
|
|
57
|
+
export interface SnapshotEventPayload {
|
|
58
|
+
plan: Plan;
|
|
59
|
+
payload_hash: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Error thrown when a writer attempts to append to the ledger with stale state.
|
|
63
|
+
* Indicates another writer has modified the ledger since the caller last read it.
|
|
64
|
+
*/
|
|
65
|
+
export declare class LedgerStaleWriterError extends Error {
|
|
66
|
+
constructor(message: string);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Compute a SHA-256 hash of the plan state.
|
|
70
|
+
* Uses deterministic JSON serialization for consistent hashing.
|
|
71
|
+
*
|
|
72
|
+
* @param plan - The plan to hash
|
|
73
|
+
* @returns Hex-encoded SHA-256 hash
|
|
74
|
+
*/
|
|
75
|
+
export declare function computePlanHash(plan: Plan): string;
|
|
76
|
+
/**
|
|
77
|
+
* Read the current plan.json and compute its hash.
|
|
78
|
+
*
|
|
79
|
+
* @param directory - The working directory
|
|
80
|
+
* @returns Hash of current plan.json, or empty string if not found
|
|
81
|
+
*/
|
|
82
|
+
export declare function computeCurrentPlanHash(directory: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Check if the ledger file exists.
|
|
85
|
+
*
|
|
86
|
+
* @param directory - The working directory
|
|
87
|
+
* @returns true if ledger file exists
|
|
88
|
+
*/
|
|
89
|
+
export declare function ledgerExists(directory: string): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Get the latest sequence number in the ledger.
|
|
92
|
+
*
|
|
93
|
+
* @param directory - The working directory
|
|
94
|
+
* @returns Highest seq value, or 0 if ledger is empty/doesn't exist
|
|
95
|
+
*/
|
|
96
|
+
export declare function getLatestLedgerSeq(directory: string): Promise<number>;
|
|
97
|
+
/**
|
|
98
|
+
* Read all events from the ledger.
|
|
99
|
+
*
|
|
100
|
+
* @param directory - The working directory
|
|
101
|
+
* @returns Array of LedgerEvent sorted by seq
|
|
102
|
+
*/
|
|
103
|
+
export declare function readLedgerEvents(directory: string): Promise<LedgerEvent[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Initialize a new ledger with a plan_created event.
|
|
106
|
+
* Only call this if the ledger doesn't exist.
|
|
107
|
+
*
|
|
108
|
+
* @param directory - The working directory
|
|
109
|
+
* @param planId - Unique identifier for the plan
|
|
110
|
+
*/
|
|
111
|
+
export declare function initLedger(directory: string, planId: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Append a new event to the ledger.
|
|
114
|
+
* Uses atomic write: write to temp file then rename.
|
|
115
|
+
*
|
|
116
|
+
* @param directory - The working directory
|
|
117
|
+
* @param eventInput - Event data to append (without seq, timestamp, hashes)
|
|
118
|
+
* @param options - Optional concurrency control options
|
|
119
|
+
* @returns The full LedgerEvent that was written
|
|
120
|
+
*/
|
|
121
|
+
export declare function appendLedgerEvent(directory: string, eventInput: LedgerEventInput, options?: {
|
|
122
|
+
expectedSeq?: number;
|
|
123
|
+
expectedHash?: string;
|
|
124
|
+
planHashAfter?: string;
|
|
125
|
+
}): Promise<LedgerEvent>;
|
|
126
|
+
/**
|
|
127
|
+
* Take a snapshot event and append it to the ledger.
|
|
128
|
+
* The snapshot embeds the full Plan payload for ledger-only rebuild.
|
|
129
|
+
*
|
|
130
|
+
* @param directory - The working directory
|
|
131
|
+
* @param plan - The current plan state to snapshot
|
|
132
|
+
* @param options - Optional configuration
|
|
133
|
+
* @returns The LedgerEvent that was written
|
|
134
|
+
*/
|
|
135
|
+
export declare function takeSnapshotEvent(directory: string, plan: Plan, options?: {
|
|
136
|
+
planHashAfter?: string;
|
|
137
|
+
}): Promise<LedgerEvent>;
|
|
138
|
+
/**
|
|
139
|
+
* Options for replayFromLedger
|
|
140
|
+
*/
|
|
141
|
+
interface ReplayOptions {
|
|
142
|
+
/** If true, use the latest snapshot to speed up replay */
|
|
143
|
+
useSnapshot?: boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Replay ledger events to reconstruct plan state.
|
|
147
|
+
* Loads plan.json as the base state and applies ledger events in sequence.
|
|
148
|
+
*
|
|
149
|
+
* NOTE: This function requires plan.json to exist as the base state.
|
|
150
|
+
* The ledger only stores task_status_changed events, not the full plan payload.
|
|
151
|
+
* If plan.json is missing, replay cannot proceed — this is a known limitation.
|
|
152
|
+
* The fix would be to store the initial plan payload in the ledger, but that
|
|
153
|
+
* is a larger architectural change beyond the current scope.
|
|
154
|
+
*
|
|
155
|
+
* @param directory - The working directory
|
|
156
|
+
* @param options - Optional replay options
|
|
157
|
+
* @returns Reconstructed Plan from ledger events, or null if plan.json doesn't exist or ledger is empty
|
|
158
|
+
*/
|
|
159
|
+
export declare function replayFromLedger(directory: string, options?: ReplayOptions): Promise<Plan | null>;
|
|
160
|
+
/**
|
|
161
|
+
* Result type for readLedgerEventsWithIntegrity
|
|
162
|
+
*/
|
|
163
|
+
export interface LedgerIntegrityResult {
|
|
164
|
+
/** Valid events up to (but not including) the first malformed line */
|
|
165
|
+
events: LedgerEvent[];
|
|
166
|
+
/** True if a bad line was found and replay was stopped early */
|
|
167
|
+
truncated: boolean;
|
|
168
|
+
/** Raw content from the first bad line to end of file, for quarantine */
|
|
169
|
+
badSuffix: string | null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Read ledger events with integrity checking.
|
|
173
|
+
* Stops at the first malformed/unparseable line and returns the remainder for quarantine.
|
|
174
|
+
*
|
|
175
|
+
* @param directory - The working directory
|
|
176
|
+
* @returns LedgerIntegrityResult with events, truncated flag, and bad suffix
|
|
177
|
+
*/
|
|
178
|
+
export declare function readLedgerEventsWithIntegrity(directory: string): Promise<LedgerIntegrityResult>;
|
|
179
|
+
/**
|
|
180
|
+
* Quarantine a corrupted ledger suffix to a separate file.
|
|
181
|
+
* Does NOT modify the ledger file itself.
|
|
182
|
+
*
|
|
183
|
+
* @param directory - The working directory
|
|
184
|
+
* @param badSuffix - The corrupted content to quarantine
|
|
185
|
+
*/
|
|
186
|
+
export declare function quarantineLedgerSuffix(directory: string, badSuffix: string): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Replay ledger events with integrity checking.
|
|
189
|
+
* If corruption is detected, quarantines the bad suffix and falls back to snapshot+prefix replay.
|
|
190
|
+
* Never throws — all errors return null.
|
|
191
|
+
*
|
|
192
|
+
* @param directory - The working directory
|
|
193
|
+
* @returns Reconstructed Plan from ledger events, or null if replay fails
|
|
194
|
+
*/
|
|
195
|
+
export declare function replayWithIntegrity(directory: string): Promise<Plan | null>;
|
|
196
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/plan/manager.d.ts
CHANGED
|
@@ -26,6 +26,15 @@ export declare function loadPlan(directory: string): Promise<Plan | null>;
|
|
|
26
26
|
export declare function savePlan(directory: string, plan: Plan, options?: {
|
|
27
27
|
preserveCompletedStatuses?: boolean;
|
|
28
28
|
}): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Rebuild plan from ledger events.
|
|
31
|
+
* Replays the ledger to reconstruct plan state, then writes the result.
|
|
32
|
+
* Uses direct atomic writes to avoid circular ledger append (savePlan appends ledger events).
|
|
33
|
+
*
|
|
34
|
+
* @param directory - The working directory
|
|
35
|
+
* @returns Reconstructed Plan from ledger, or null if ledger is empty/missing
|
|
36
|
+
*/
|
|
37
|
+
export declare function rebuildPlan(directory: string, plan?: Plan): Promise<Plan | null>;
|
|
29
38
|
/**
|
|
30
39
|
* Load plan → find task by ID → update status → save → return updated plan.
|
|
31
40
|
* Throw if plan not found or task not found.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/tools/lint.d.ts
CHANGED
|
@@ -41,6 +41,14 @@ export declare function getAdditionalLinterCommand(linter: AdditionalLinter, mod
|
|
|
41
41
|
export declare function detectAdditionalLinter(cwd: string): 'ruff' | 'clippy' | 'golangci-lint' | 'checkstyle' | 'ktlint' | 'dotnet-format' | 'cppcheck' | 'swiftlint' | 'dart-analyze' | 'rubocop' | null;
|
|
42
42
|
/** Compute the local biome binary path for a given project directory. */
|
|
43
43
|
export declare function getBiomeBinPath(directory: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve the binary path for a linter, using the same hierarchy as detectAvailableLinter:
|
|
46
|
+
* 1. Local node_modules/.bin
|
|
47
|
+
* 2. Ancestor node_modules/.bin (monorepo)
|
|
48
|
+
* 3. process.env.PATH scan
|
|
49
|
+
* 4. Local path as fallback (may not exist)
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveLinterBinPath(linter: SupportedLinter, projectDir: string): string;
|
|
44
52
|
/** Compute the local eslint binary path for a given project directory. */
|
|
45
53
|
export declare function getEslintBinPath(directory: string): string;
|
|
46
54
|
export declare function detectAvailableLinter(directory?: string): Promise<SupportedLinter | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-swarm",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.44.1",
|
|
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",
|