mythos-router 1.1.9 → 1.2.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [1.2.0] — 2026-04-23
11
+
12
+ ### Added
13
+ - **SWDEngine v1 API** — Transactional filesystem execution kernel with `Plan → Snapshot → Execute → Verify → Rollback` lifecycle. Single entry point: `engine.run(actions)`.
14
+ - **ChatUI Abstraction** — Decoupled chat session logic from the terminal via a `ChatUI` interface. `ChatSession` is now a pure orchestrator, fully testable and reusable outside the CLI.
15
+ - **TerminalUI Implementation** — CLI-specific `ChatUI` adapter wrapping the Spinner and ANSI output.
16
+ - **SWD Lifecycle Hooks** — Extensibility layer (`onAction`, `onVerify`, `onRollback`) allowing consumers to inject logging, telemetry, or custom UI into the engine.
17
+ - **Rollback Auditability** — `SWDRunResult.rollbackErrors` field captures and reports rollback failures instead of silently swallowing them.
18
+ - **`swd-cli.ts`** — Separated SWD terminal presentation (verification output, dry-run preview, verbose traces) from the pure execution kernel.
19
+ - **Git Sandbox** — `ChatSession.setupSandbox()` for automated `mythos/` branch creation with nested-sandboxing protection.
20
+
21
+ ### Changed
22
+ - **SWD Kernel is now I/O-free** — `swd.ts` contains zero `console.log` calls. All presentation lives in `swd-cli.ts`.
23
+ - **`validateApiKey()` throws instead of `process.exit(1)`** — library-safe error handling.
24
+ - **SDK exports (`index.ts`) fully updated** — removed dead symbols (`runSWD`, `parseFileActions`, `snapshotFiles`), added `SWDEngine`, `parseActions`, `SessionBudget`, `ChatUI`, and all v1 types.
25
+
26
+ ### Fixed
27
+ - **🔴 Snapshot memoization bug** — `InternalSessionContext.getSnapshot('after')` was returning stale cached state on multi-action same-file scenarios. After snapshots now always re-read disk state.
28
+ - **🔴 Broken `index.ts` exports** — SDK entry point was referencing pre-refactor symbols that no longer existed.
29
+
30
+ ---
31
+
10
32
  ## [1.1.9] — 2026-04-22
11
33
 
12
34
  ### Added
package/README.md CHANGED
@@ -220,24 +220,32 @@ Data is stored locally in `~/.mythos-router/metrics.json`.
220
220
  `mythos-router` exposes its Strict Write Discipline engine for programmatic use:
221
221
 
222
222
  ```typescript
223
- import { runSWD, snapshotFiles } from 'mythos-router';
223
+ import { SWDEngine, parseActions } from 'mythos-router';
224
224
 
225
- // 1. Snapshot the target directory before your agent executes
226
- const beforeState = snapshotFiles(['./src/components']);
225
+ // 1. Create an engine instance with your preferred options
226
+ const engine = new SWDEngine({
227
+ strict: true,
228
+ enableRollback: true,
229
+ onAction: (action) => console.log(`Executing: ${action.operation} ${action.path}`),
230
+ onVerify: (result) => console.log(`${result.status}: ${result.detail}`),
231
+ });
227
232
 
228
233
  // 2. Let your agent generate code (must output [FILE_ACTION] blocks)
229
- const agentOutput = await myAgent.generateCode();
234
+ const agentOutput = await myAgent.generateCode();
230
235
 
231
- // 3. Route through the Strict Write Discipline engine
232
- const result = runSWD(agentOutput, beforeState);
236
+ // 3. Parse the agent's output and route through the SWD engine
237
+ const actions = parseActions(agentOutput);
238
+ const result = await engine.run(actions);
233
239
 
234
- if (result.verified) {
240
+ if (result.success) {
235
241
  console.log('✅ Agent execution verified securely');
236
242
  } else {
237
- console.log('❌ Agent hallucinated a write. Stopping execution.');
243
+ console.log('❌ Agent hallucinated a write. Rolled back:', result.rolledBack);
244
+ console.log('Errors:', result.errors);
238
245
  }
239
246
  ```
240
247
 
248
+
241
249
  ---
242
250
 
243
251
  ## Architecture
@@ -246,15 +254,19 @@ if (result.verified) {
246
254
  mythos-router/
247
255
  ├── src/
248
256
  │ ├── cli.ts # Commander.js entry point
249
- │ ├── config.ts # System prompt + constants + budget defaults
250
- │ ├── client.ts # Anthropic SDK (adaptive thinking)
251
- │ ├── budget.ts # Session budget limiter (token cap, turn cap)
252
- │ ├── swd.ts # Strict Write Discipline + dry-run preview
253
- │ ├── memory.ts # MEMORY.md self-healing manager (dry-run aware)
257
+ │ ├── config.ts # System prompt + constants + budget defaults + validation
258
+ │ ├── client.ts # Anthropic SDK (adaptive thinking, streaming)
259
+ │ ├── budget.ts # Session budget limiter (token cap, turn cap, progress bar)
260
+ │ ├── swd.ts # SWD execution kernel (engine, types, parsing, snapshots)
261
+ │ ├── swd-cli.ts # SWD terminal presentation (verification output, dry-run)
262
+ │ ├── memory.ts # MEMORY.md self-healing manager (SQLite FTS5 index)
254
263
  │ ├── metrics.ts # Global metrics store (persistent budget tracking)
255
- │ ├── utils.ts # Terminal formatting, badges, prompts (zero-dep)
264
+ │ ├── diff.ts # Myers' diff algorithm (zero-dependency)
265
+ │ ├── git.ts # Git operations (branching, committing)
266
+ │ ├── utils.ts # Terminal formatting, badges, prompts (zero-dep ANSI)
267
+ │ ├── index.ts # Public SDK exports
256
268
  │ └── commands/
257
- │ ├── chat.ts # Interactive REPL (budget + dry-run + verbose)
269
+ │ ├── chat.ts # Interactive REPL (ChatSession + ChatUI abstraction)
258
270
  │ ├── verify.ts # Codebase ↔ Memory scanner (dry-run aware)
259
271
  │ ├── dream.ts # Memory compression (dry-run aware)
260
272
  │ └── stats.ts # Budget analytics reporter
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ program
14
14
  .name('mythos')
15
15
  .description('Capybara-tier CLI router — Claude Opus 4.7 with Adaptive Thinking, ' +
16
16
  'Strict Write Discipline, and Self-Healing Memory.')
17
- .version('1.1.9');
17
+ .version('1.2.0');
18
18
  // ── mythos chat ──────────────────────────────────────────────
19
19
  program
20
20
  .command('chat')
@@ -1,3 +1,14 @@
1
+ export interface ChatUI {
2
+ startLoading(msg: string): void;
3
+ updateLoading(msg: string): void;
4
+ stopLoading(msg?: string): void;
5
+ write(text: string): void;
6
+ log(msg: string): void;
7
+ warn(msg: string): void;
8
+ error(msg: string): void;
9
+ success(msg: string): void;
10
+ divider(): void;
11
+ }
1
12
  interface ChatOptions {
2
13
  effort?: string;
3
14
  maxTokens?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAiDA,UAAU,WAAW;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAwWrE"}
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,MAAM;IACrB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,IAAI,IAAI,CAAC;CACjB;AA2PD,UAAU,WAAW;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CrE"}