mythos-router 1.7.1 → 1.12.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.
Files changed (99) hide show
  1. package/AGENTS.md +92 -0
  2. package/CHANGELOG.md +117 -2
  3. package/README.md +173 -20
  4. package/SECURITY.md +75 -0
  5. package/dist/ci/git.d.ts +6 -0
  6. package/dist/ci/git.d.ts.map +1 -0
  7. package/dist/ci/git.js +139 -0
  8. package/dist/ci/git.js.map +1 -0
  9. package/dist/ci/receipts.d.ts +11 -0
  10. package/dist/ci/receipts.d.ts.map +1 -0
  11. package/dist/ci/receipts.js +97 -0
  12. package/dist/ci/receipts.js.map +1 -0
  13. package/dist/ci/report.d.ts +5 -0
  14. package/dist/ci/report.d.ts.map +1 -0
  15. package/dist/ci/report.js +99 -0
  16. package/dist/ci/report.js.map +1 -0
  17. package/dist/ci/rules.d.ts +5 -0
  18. package/dist/ci/rules.d.ts.map +1 -0
  19. package/dist/ci/rules.js +249 -0
  20. package/dist/ci/rules.js.map +1 -0
  21. package/dist/ci/secrets.d.ts +3 -0
  22. package/dist/ci/secrets.d.ts.map +1 -0
  23. package/dist/ci/secrets.js +104 -0
  24. package/dist/ci/secrets.js.map +1 -0
  25. package/dist/ci/types.d.ts +57 -0
  26. package/dist/ci/types.d.ts.map +1 -0
  27. package/dist/ci/types.js +2 -0
  28. package/dist/ci/types.js.map +1 -0
  29. package/dist/ci/verify.d.ts +3 -0
  30. package/dist/ci/verify.d.ts.map +1 -0
  31. package/dist/ci/verify.js +38 -0
  32. package/dist/ci/verify.js.map +1 -0
  33. package/dist/cli.js +70 -4
  34. package/dist/cli.js.map +1 -1
  35. package/dist/client.d.ts.map +1 -1
  36. package/dist/client.js +14 -14
  37. package/dist/client.js.map +1 -1
  38. package/dist/commands/chat.d.ts +8 -0
  39. package/dist/commands/chat.d.ts.map +1 -1
  40. package/dist/commands/chat.js +371 -98
  41. package/dist/commands/chat.js.map +1 -1
  42. package/dist/commands/init.d.ts +1 -0
  43. package/dist/commands/init.d.ts.map +1 -1
  44. package/dist/commands/init.js +56 -15
  45. package/dist/commands/init.js.map +1 -1
  46. package/dist/commands/learn.d.ts +9 -0
  47. package/dist/commands/learn.d.ts.map +1 -0
  48. package/dist/commands/learn.js +97 -0
  49. package/dist/commands/learn.js.map +1 -0
  50. package/dist/commands/receipts.js +7 -0
  51. package/dist/commands/receipts.js.map +1 -1
  52. package/dist/commands/skills.d.ts +8 -0
  53. package/dist/commands/skills.d.ts.map +1 -0
  54. package/dist/commands/skills.js +168 -0
  55. package/dist/commands/skills.js.map +1 -0
  56. package/dist/commands/swd.d.ts +65 -0
  57. package/dist/commands/swd.d.ts.map +1 -0
  58. package/dist/commands/swd.js +351 -0
  59. package/dist/commands/swd.js.map +1 -0
  60. package/dist/commands/verify.d.ts +4 -0
  61. package/dist/commands/verify.d.ts.map +1 -1
  62. package/dist/commands/verify.js +27 -0
  63. package/dist/commands/verify.js.map +1 -1
  64. package/dist/config.d.ts +2 -0
  65. package/dist/config.d.ts.map +1 -1
  66. package/dist/config.js +30 -6
  67. package/dist/config.js.map +1 -1
  68. package/dist/git.d.ts +6 -4
  69. package/dist/git.d.ts.map +1 -1
  70. package/dist/git.js +20 -5
  71. package/dist/git.js.map +1 -1
  72. package/dist/index.d.ts +5 -2
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +6 -1
  75. package/dist/index.js.map +1 -1
  76. package/dist/learn.d.ts +38 -0
  77. package/dist/learn.d.ts.map +1 -0
  78. package/dist/learn.js +404 -0
  79. package/dist/learn.js.map +1 -0
  80. package/dist/receipts.d.ts +10 -0
  81. package/dist/receipts.d.ts.map +1 -1
  82. package/dist/receipts.js +44 -7
  83. package/dist/receipts.js.map +1 -1
  84. package/dist/security-policy.d.ts +23 -0
  85. package/dist/security-policy.d.ts.map +1 -0
  86. package/dist/security-policy.js +91 -0
  87. package/dist/security-policy.js.map +1 -0
  88. package/dist/skills.d.ts +42 -8
  89. package/dist/skills.d.ts.map +1 -1
  90. package/dist/skills.js +275 -92
  91. package/dist/skills.js.map +1 -1
  92. package/dist/swd.d.ts.map +1 -1
  93. package/dist/swd.js +5 -1
  94. package/dist/swd.js.map +1 -1
  95. package/dist/utils.d.ts +1 -1
  96. package/dist/utils.d.ts.map +1 -1
  97. package/dist/utils.js +21 -12
  98. package/dist/utils.js.map +1 -1
  99. package/package.json +12 -6
package/AGENTS.md ADDED
@@ -0,0 +1,92 @@
1
+ # AGENTS.md — mythos-router Project Standards
2
+
3
+ ## Project Identity
4
+ - **Name**: mythos-router
5
+ - **Type**: CLI power tool (local-first, zero-slop)
6
+ - **Stack**: TypeScript on Node.js 20+ (ESM, `tsx` for dev)
7
+
8
+ ## Architecture
9
+ - `src/cli.ts` — Commander.js entry point
10
+ - `src/config.ts` — Constants, system prompt, validation, budget defaults
11
+ - `src/client.ts` — Provider facade and Anthropic direct-client compatibility path
12
+ - `src/budget.ts` — Session budget limiter (token cap, turn cap, progress bar)
13
+ - `src/swd.ts` — SWD execution kernel (engine, types, parsing, snapshots, verification, rollback)
14
+ - `src/swd-cli.ts` — SWD terminal presentation layer (verification output, dry-run preview)
15
+ - `src/receipts.ts` — SWD trust receipts (creation, storage, drift verification)
16
+ - `src/memory.ts` — Self-healing MEMORY.md manager (SQLite FTS5 derivative index)
17
+ - `src/metrics.ts` — Global metrics store (persistent budget tracking)
18
+ - `src/diff.ts` — Myers' diff algorithm (zero-dependency, line-by-line)
19
+ - `src/git.ts` — Git operations (branching, committing, status)
20
+ - `src/utils.ts` — Terminal colors, spinner, formatting, badges, confirm prompt
21
+ - `src/index.ts` — Public SDK exports (SWDEngine, parseActions, etc.)
22
+ - `src/commands/chat.ts` — Interactive REPL and one-shot run orchestration (ChatSession + ChatUI abstraction)
23
+ - `src/commands/swd.ts` — Model-free external-agent SWD apply command (`mythos swd apply`)
24
+ - `src/commands/init.ts` — Project initialization (environment checks, provider detection, scaffolding)
25
+ - `src/commands/verify.ts` — Codebase ↔ Memory drift scanner (dry-run aware)
26
+ - `src/commands/receipts.ts` — SWD receipt list/show/verify command
27
+ - `src/commands/dream.ts` — Memory compression (dry-run aware)
28
+ - `src/commands/stats.ts` — Budget analytics reporter
29
+
30
+ ## Conventions
31
+ 1. **Zero external runtime deps** beyond `@anthropic-ai/sdk` and `commander`
32
+ 2. **No `chalk`, no `ink`** — all terminal formatting is vanilla ANSI
33
+ 3. **ESM only** — `"type": "module"` in package.json
34
+ 4. All file operations use `node:fs` (sync) for SWD determinism
35
+ 5. **SWD is non-negotiable** — every model or external-agent file action is verified against the filesystem
36
+ 6. **MEMORY.md is sacred** — never delete it, only append or compress via Dream
37
+ 7. The system prompt lives in `config.ts` — do NOT scatter prompt fragments
38
+ 8. **Budget defaults live in `config.ts`** — 500K tokens, 25 turns, 80% warning
39
+ 9. **Pricing constants live in `config.ts`** — update provider pricing there when model rates change
40
+ 10. **Dry-run mode** — all filesystem writes must check `dryRun` flag before mutating
41
+
42
+ ## File Operation Protocol
43
+ - Built-in model output and external agents must express file mutations as `[FILE_ACTION: path]...[/FILE_ACTION]` blocks or structured JSON actions.
44
+ - SWD parses these actions, validates paths, snapshots before/after state, verifies against actual filesystem state, and rolls back failed mutations when enabled.
45
+ - Max 2 correction retries before yielding to human in model-driven `chat`/`run` flows.
46
+ - In `--dry-run` mode, actions are previewed and must not mutate files or write receipts.
47
+
48
+ ## External Agent SWD Protocol
49
+ - `mythos swd apply --stdin --json` is the model-free integration point for external/autonomous agents.
50
+ - It must not require `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, or `DEEPSEEK_API_KEY`; the external agent brings its own model/key.
51
+ - External SWD input must fail closed: reject oversized input, malformed JSON/actions, path traversal, sensitive paths, and high-impact command-surface changes unless explicitly allowed.
52
+ - Sensitive files such as `.env`, `.npmrc`, private keys, wallet files, and `.git` internals must remain blocked by default.
53
+ - Receipts for external-agent applies should record the external agent/model identity without leaking secrets.
54
+
55
+ ## Budget Limiter Protocol
56
+ - `SessionBudget` tracks tokens + turns + estimated cost per session (not persisted across runs)
57
+ - Pre-check before every API call — **graceful save** at limit (progress → MEMORY.md)
58
+ - Warning at 80% consumption
59
+ - `--no-budget` disables for expert users
60
+ - Correction turns count toward the budget
61
+
62
+ ## Running
63
+ ```bash
64
+ # Dev mode (no build required)
65
+ npx tsx src/cli.ts chat
66
+ npx tsx src/cli.ts chat --dry-run --verbose
67
+ npx tsx src/cli.ts chat --max-tokens 100000 --max-turns 10
68
+ npx tsx src/cli.ts chat --no-budget
69
+ npx tsx src/cli.ts run "explain this repo architecture"
70
+ npx tsx src/cli.ts run --file TASK.md
71
+ npx tsx src/cli.ts run "fix the failing smoke test" --dry-run
72
+ your-agent --emit-file-actions | npx tsx src/cli.ts swd apply --stdin --json
73
+ npx tsx src/cli.ts verify
74
+ npx tsx src/cli.ts verify --dry-run
75
+ npx tsx src/cli.ts dream
76
+ npx tsx src/cli.ts dream --dry-run
77
+ npx tsx src/cli.ts stats
78
+ npx tsx src/cli.ts stats --days 7
79
+ npx tsx src/cli.ts receipts
80
+ npx tsx src/cli.ts receipts verify latest
81
+ npx tsx src/cli.ts init
82
+ npx tsx src/cli.ts init --check
83
+ npx tsx src/cli.ts init --force
84
+
85
+ # Or via npm scripts
86
+ npm run chat
87
+ npm run verify
88
+ npm run dream
89
+ npm run stats
90
+ npm run receipts
91
+ npm run init
92
+ ```
package/CHANGELOG.md CHANGED
@@ -7,15 +7,123 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [1.12.0] - 2026-05-24
11
+
12
+ ### Added
13
+ - **External Agent SWD Interface** - Added `mythos swd apply` so external agents can submit structured file actions to Mythos without calling a model provider or requiring an Anthropic key.
14
+ - **Model Free SWD Automation** - Added `--stdin`, `--file <path>`, and `--json` support for machine readable external agent workflows.
15
+ - **External Agent Receipt Metadata** - SWD receipts can now identify external agent/model sources for verified non-dry-run executions.
16
+
17
+ ### Changed
18
+ - **Provider Key Validation** - `mythos chat` and `mythos run` now require at least one configured provider key instead of requiring Anthropic specifically, preserving Anthropic as the recommended/default provider when present.
19
+ - **README and SDK Documentation** - Documented the agent neutral SWD execution flow, security defaults, BYOK provider selection, and receipt behavior for external agent use.
20
+
21
+ ### Security
22
+ - **Fail Closed External Actions** - External SWD input is size limited, schema validated, constrained to safe project relative paths, and reviewed before filesystem mutation.
23
+ - **Sensitive Path Protection** - External agent actions block `.env`, private keys, wallet files, `.git`, `.npmrc`, and secret-like paths by default. High impact command surface files and deletes require explicit `--allow-risky`.
24
+ - **No Model Execution Boundary** - `mythos swd apply` does not call Anthropic, OpenAI, DeepSeek, provider fallback, memory compression, or test-healing; it only applies and verifies supplied file actions through SWD.
25
+
26
+ ---
27
+
28
+ ## [1.11.0] - 2026-05-22
29
+
30
+ ### Added
31
+ - **`mythos learn` Command** - Added deterministic repo skill generation that creates `.mythos/skills/repo/SKILL.md` from local repo structure, docs, package scripts, CI workflows, public surfaces, and security-sensitive files without running project commands or calling a model.
32
+
33
+ ### Changed
34
+ - **Skill Onboarding** - Skills can now be bootstrapped from detected repository signals instead of requiring maintainers to write every rule pack from scratch.
35
+
36
+ ---
37
+
38
+ ## [1.10.0] - 2026-05-20
39
+
40
+ ### Added
41
+ - **`mythos skills` Command** - Added first-class skill pack management through `mythos skills`, `mythos skills show <name>`, `mythos skills new <name>`, and `mythos skills check`.
42
+ - **Project-Local Skill Packs** - Added `.mythos/skills/<name>/SKILL.md` support so repositories can ship their own Mythos operating rules without relying on a user's global setup.
43
+ - **Global Skill Packs** - Preserved reusable user-global skills in `~/.mythos-router/skills/<name>/SKILL.md`, with project-local skills taking precedence when names overlap.
44
+ - **Skill Receipt Metadata** - SWD receipts now record active skill ids, names, versions, and sources so verified edits can be reviewed with the rule packs that guided them.
45
+ - **Skill Documentation and Examples** - Added a dedicated skills guide plus example `repo` and `security-review` skill packs.
46
+ - **Skill SDK Helpers** - Exported skill loading, listing, validation, creation, and prompt-building helpers through the public SDK entry point.
47
+
48
+ ### Changed
49
+ - **Project Initialization** - `mythos init` now scaffolds and checks the project-local `.mythos/skills/` directory as part of repo onboarding.
50
+ - **Skill Validation** - Skill checks now validate numeric limits, parse frontmatter arrays more consistently, and detect incompatibilities by either skill id or skill name.
51
+ - **Receipt Privacy** - Receipt skill paths are stored only when they resolve inside the current project, avoiding accidental leakage of user-global or outside-project paths.
52
+
53
+ ---
54
+
55
+ ## [1.9.0] - 2026-05-19
56
+
57
+ ### Added
58
+ - **`mythos run` Command** - Added one-shot prompt execution for tasks that do not need the interactive REPL. The command accepts any prompt, runs it through Mythos once, and exits.
59
+ - **File and Stdin Prompt Sources** - `mythos run` can now read its prompt from a local file with `--file <path>` or from piped input with `--stdin`, making Mythos easier to use in scripts, task files, and editor workflows.
60
+ - **Shared Chat/SWD Pipeline** - `run` reuses the existing chat session initialization, provider routing, SWD verification, receipts, memory logging, budget tracking, skills, and branch sandboxing instead of introducing a separate execution path.
61
+ - **Bounded Run Defaults** - One-shot runs default to a smaller turn budget: one initial model turn, SWD correction turns, and optional test-healing turns only when `--test-cmd` is provided.
62
+ - **Resume-Safe Execution** - `run` records metrics as its own command but does not overwrite the resumable session used by `mythos chat --resume`.
63
+ - **`mythos init --check`** - Added a read-only setup check for environment, providers, `.mythosignore`, `MEMORY.md`, and the local skills directory without scaffolding or modifying files.
64
+
65
+ ### Changed
66
+ - **Command Help Coverage** - CLI smoke coverage now checks that built help output includes the `run` and `init` commands, verifies the `run --help` prompt-source options, and covers `init --check` as a no-write smoke path.
67
+
68
+ ---
69
+
70
+ ## [1.8.1] - 2026-05-17
71
+
72
+ ### Fixed
73
+ - **SWD Rollback Drift Protection** — Rollback now uses the cached post-verification snapshot, preventing Mythos from overwriting external file changes made after verification.
74
+
75
+ ### Changed
76
+ - **CI Verification Gate** — Added a GitHub Actions step to run `node dist/cli.js verify --ci` against the locally built CLI.
77
+ - **CI Hardening** — Tightened workflow permissions and install behavior.
78
+
79
+ ### Security
80
+ - **Local Data Disclosure** - Documented where Mythos stores local memory, receipts, resumable sessions, metrics, cache data, and skills so users can inspect or clear private project state.
81
+
82
+ ---
83
+
84
+ ## [1.8.0] — 2026-05-15
85
+
86
+ ### Added
87
+ - **CI Verification Mode** — Added `mythos verify --ci`, a read-only GitHub CI mode for reviewing PR/diff changes before merge
88
+ - **Generic PR Review** — `verify --ci` now works even when no Mythos receipts are present, checking high-impact repository changes in generic PR-review mode.
89
+ - **Receipt-Aware CI Checks** — When Mythos receipts are changed under `.mythos/receipts/`, CI verifies receipt integrity and changed-file coverage.
90
+ - **Execution-Surface Detection** — Added CI checks for `package.json` script changes, npm lifecycle hooks, GitHub Actions workflows, shell/deploy/Docker surfaces, `.env`/`.npmrc` paths, private-key-like files, and high-confidence secret patterns.
91
+ - **CI Output Options** — Added `--strict`, `--json`, and `--base <ref>` options for stricter CI policies, downstream tooling, and custom git base comparisons.
92
+ - **CI Documentation** — Added `docs/CI.md` with GitHub Actions setup, exit behavior, examples, and maintainer notes.
93
+
94
+ ### Changed
95
+ - **Verify Command Extension** — Extended `mythos verify` with a dedicated CI path while keeping normal local verification behavior unchanged.
96
+ - **Test-Healing Loop Refactor** — Refactored the test-healing loop in `src/commands/chat.ts` into smaller helper methods for maintainability, without changing existing chat/SWD behavior.
97
+
98
+ ### Security
99
+ - **No-AI CI Verification** — `verify --ci` does not call a model, use provider fallback, modify files, execute SWD actions, or write to `MEMORY.md`.
100
+ - **Lifecycle Hook Review** — Newly added npm install lifecycle hooks such as `preinstall`, `install`, and `postinstall` are treated as high-severity CI findings.
101
+ - **Execution-Surface Review** — Package scripts, workflows, shell/deploy files, and other high-impact repo surfaces are flagged for review before merge.
102
+ - **Sensitive File Checks** — Added high-confidence checks for sensitive paths, private-key-like files, and secret-like material.
103
+
104
+ ---
105
+
106
+ ## [1.7.1] — 2026-05-13
107
+
108
+ ### Added
109
+ - **Malformed Action Detection** — Mythos now warns when model output appears to include `[FILE_ACTION]` blocks but no valid actions can be parsed, making broken agent output easier to diagnose.
110
+ - **Safety Regression Coverage** — Added tests covering receipt redaction, dry-run wording, and oversized write blocking.
111
+
112
+ ### Changed
113
+ - **Safer Receipt Output** — Receipt test-output tails are now limited to 500 characters and redact obvious API keys, tokens, and secrets before being stored locally.
114
+
115
+ ### Fixed
116
+ - **Large Write Protection** — Oversized `CREATE` and `MODIFY` actions are now blocked before touching disk, reducing the risk of unsafe full-file rewrites.
117
+
118
+ ---
119
+
10
120
  ## [1.7.0] — 2026-05-11
11
121
 
12
122
  ### Added
13
123
  - **SWD Trust Receipts** — Added persistent receipts for SWD runs, recording verified file outcomes, request summaries, provider/model metadata, token usage, git context, test status, and an integrity hash for later audit.
14
124
  - **`mythos receipts` Command** — Added receipt listing, inspection, and drift verification through `mythos receipts`, `mythos receipts show <id|latest>`, and `mythos receipts verify <id|latest>`, with `--json` output for automation.
15
- - **Receipt Regression Coverage** — Added tests for receipt save/list/read/verify behavior, drift detection, symlinked project roots, built CLI receipt commands, and Node 20/24-compatible test discovery.
16
125
 
17
126
  ### Fixed
18
- - **Receipt Path Normalization** — Receipt snapshots now store stable project-relative paths even when CI temp directories resolve through platform-specific symlinks such as macOS `/var` and `/private/var`.
19
127
  - **Machine-Readable JSON Output** — Terminal cursor restoration no longer contaminates redirected stdout, keeping `--json` output parseable in CI and shell pipelines.
20
128
 
21
129
  ---
@@ -260,6 +368,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
260
368
  - **Correction Turns** — max 2 retries before yielding to human.
261
369
  - **Dream/Verify Commands** — memory compression and drift detection.
262
370
 
371
+ [1.12.0]: https://github.com/thewaltero/mythos-router/releases/tag/v1.11.0
372
+ [1.11.0]: https://github.com/thewaltero/mythos-router/releases/tag/v1.11.0
373
+ [1.10.0]: https://github.com/thewaltero/mythos-router/releases/tag/v1.10.0
374
+ [1.9.0]: https://github.com/thewaltero/mythos-router/releases/tag/v1.9.0
375
+ [1.8.1]: https://github.com/thewaltero/mythos-router/releases/tag/v1.8.1
376
+ [1.8.0]: https://github.com/thewaltero/mythos-router/releases/tag/v1.8.0
377
+ [1.7.1]: https://github.com/thewaltero/mythos-router/releases/tag/v1.7.1
263
378
  [1.7.0]: https://github.com/thewaltero/mythos-router/releases/tag/v1.7.0
264
379
  [1.6.1]: https://github.com/thewaltero/mythos-router/releases/tag/v1.6.1
265
380
  [1.6.0]: https://github.com/thewaltero/mythos-router/releases/tag/v1.6.0
package/README.md CHANGED
@@ -13,7 +13,6 @@
13
13
  ## Claude Opus 4.7 · Strict Write Discipline · Zero Slop
14
14
  **A local CLI power tool for verifiable AI-assisted coding.**
15
15
 
16
- <br />
17
16
 
18
17
  [What is this?](#what-is-this) • [Features](#features) • [Installation](#installation) • [Usage](#usage) • [Architecture](#architecture) • [Token Budget](#token-usage--budget) • [SDK](#-sdk-usage-for-agentic-systems) • [SWD Protocol](#the-swd-protocol)
19
18
 
@@ -53,17 +52,21 @@ Zero slop. Zero hallucinated state. Full adaptive thinking.
53
52
 
54
53
  | Feature | Description |
55
54
  |---------|-------------|
56
- | **mythos init** | Single-command project onboarding with environment validation and scaffolding |
57
- | **Multi-Provider Fallback** | Auto-routes between Anthropic, DeepSeek, and OpenAI with circuit breakers |
58
- | **Skills Protocol** | Inject modular expert plugins via YAML frontmatter (`-s mcp`, `-s react`) |
55
+ | **mythos init** | Single-command project onboarding with environment validation, read-only `--check`, and scaffolding |
56
+ | **mythos learn** | Generate a repo-local `SKILL.md` from detected project structure, scripts, docs, CI, and risk surfaces |
57
+ | **mythos run** | One-shot prompt mode with inline, file, stdin input, and optional `--provider` BYOK selection: same SWD, budget, skills, branch, and optional test-healing pipeline as chat |
58
+ | **Multi-Provider BYOK** | Auto-routes between configured Anthropic, DeepSeek, and OpenAI keys with circuit breakers; Anthropic is no longer required when another provider is configured |
59
+ | **Verified Skill Packs** | Load project-local or user-global `SKILL.md` rules with `-s <name>`; active skills are recorded in SWD receipts |
59
60
  | **Deterministic Caching** | SQLite-backed caching for reasoning (SDK only) *(Node 22+)* |
60
61
  | **Adaptive Thinking** | Opus 4.7 with configurable effort levels (high/medium/low) |
61
- | **Strict Write Discipline** | Pre/post filesystem snapshots verify every model claim |
62
- | **SWD Receipts** | Per-run trust receipts record touched files, hashes, provider, budget, git state, and verification result |
62
+ | **Strict Write Discipline** | Pre/post filesystem snapshots verify every model or external-agent file claim |
63
+ | **SWD Receipts** | Per-run trust receipts record touched files, hashes, provider/external-agent id, budget, git state, and verification result |
63
64
  | **Self-Healing Memory** | Authority-based logging with a rebuildable SQLite FTS5 search index *(Node 22+)* |
64
65
  | **Auto-Healing TDD** | Pass `--test-cmd` for bounded, error-driven autonomous repair loops |
65
66
  | **Correction Turns** | Model gets 2 retries to match filesystem reality, then yields |
66
67
  | **Integrity Gate** | `verify` command ensures referenced memory files still exist |
68
+ | **CI Verification** | `verify --ci` runs read-only PR checks for command-surface, sensitive-file, and receipt risks without an API key |
69
+ | **Bring Your Own Agent** | `mythos swd apply --stdin --json` lets any external agent route file actions through SWD without a Mythos model key |
67
70
  | **Token Limiter** | Budget cap with graceful save — progress saved to MEMORY.md, never lose work |
68
71
  | **Session Resume** | Pick up exactly where you left off after a crash or exit (`--resume`) |
69
72
  | **Dry-Run Mode** | Preview every file operation before it executes — full transparency |
@@ -106,14 +109,18 @@ As memory approaches capacity, the `dream` command delegates a compression phase
106
109
  # Install globally
107
110
  npm install -g mythos-router
108
111
 
109
- # Set your API keys (Anthropic is primary, others are fallbacks)
112
+ # Set at least one model key for mythos chat/run
113
+ # Anthropic remains the recommended default, but OpenAI/DeepSeek can be used standalone.
110
114
  export ANTHROPIC_API_KEY="sk-ant-..."
111
- export OPENAI_API_KEY="sk-proj-..."
112
- export DEEPSEEK_API_KEY="sk-..."
115
+ # export OPENAI_API_KEY="sk-proj-..."
116
+ # export DEEPSEEK_API_KEY="sk-..."
113
117
 
114
- # Initialize and start
118
+ # Initialize and start the built-in Mythos agent
115
119
  mythos init
116
120
  mythos chat
121
+
122
+ # Or use only the model-free SWD layer with your own external agent
123
+ your-agent --emit-file-actions | mythos swd apply --stdin --json
117
124
  ```
118
125
 
119
126
  ### Or try without installing
@@ -139,17 +146,65 @@ npm run chat
139
146
 
140
147
  ```bash
141
148
  mythos init # Initialize mythos-router in the current project
149
+ mythos init --check # Check environment and project setup without writing files
142
150
  mythos init --force # Re-scaffold files even if they already exist
143
151
  ```
144
152
 
153
+ `init` prepares the local repo surface Mythos uses: `.mythosignore`, `MEMORY.md`, and the project-local `.mythos/skills/` directory.
154
+
155
+ ### `mythos learn` - Repo Skill Generation
156
+
157
+ ```bash
158
+ mythos learn # Generate .mythos/skills/repo/SKILL.md
159
+ mythos learn --dry-run # Preview the generated skill without writing files
160
+ mythos learn --force # Overwrite an existing repo skill
161
+ mythos learn --name backend # Generate .mythos/skills/backend/SKILL.md
162
+ ```
163
+
164
+ `learn` turns the current repo into a reviewable project skill. It scans local repo signals such as `README.md`, `package.json`, source directories, CI workflows, config files, docs, tests, package scripts, public exports, and security-sensitive paths. It does not run npm scripts, shell commands, tests, builds, or a model. The generated `SKILL.md` is a deterministic starting point that should be inspected and edited like any other project file.
165
+
166
+ ### `mythos skills` - Verified Skill Packs
167
+
168
+ ```bash
169
+ mythos skills # List project-local and user-global skills
170
+ mythos skills new repo # Create .mythos/skills/repo/SKILL.md
171
+ mythos skills new audit --global # Create ~/.mythos-router/skills/audit/SKILL.md
172
+ mythos skills show repo # Inspect metadata and instructions
173
+ mythos skills check # Validate all discovered skills
174
+ ```
175
+
176
+ Skill packs are repo operating manuals for Mythos. They encode project conventions, files to read first, files to avoid, review expectations, and verification rules without adding runtime code. Project-local skills live in `.mythos/skills/<name>/SKILL.md` and win over global skills with the same name. User-global skills live in `~/.mythos-router/skills/<name>/SKILL.md` for personal reuse across repositories.
177
+
178
+ ```bash
179
+ mythos run --file TASK.md -s repo
180
+ mythos chat -s repo -s security-review
181
+ ```
182
+
183
+ When a non-dry-run SWD operation creates a receipt, Mythos records the active skill ids and versions. That makes skill-guided changes auditable: reviewers can see which repo rules were loaded when the verified edit happened. See [`docs/skills.md`](docs/skills.md) for the format and examples.
184
+
185
+ ### `mythos run` — One-Shot Task
186
+
187
+ ```bash
188
+ mythos run "explain this repo architecture"
189
+ mythos run --file TASK.md
190
+ cat TASK.md | mythos run --stdin
191
+ mythos run --provider openai "explain this repo architecture"
192
+ mythos run "update the docs for verify --ci" --dry-run
193
+ mythos run "fix the failing smoke test" --test-cmd "npm test"
194
+ mythos run "refactor provider scoring" --branch provider-score
195
+ ```
196
+
197
+ `run` sends one prompt through the same Mythos pipeline as `chat`, including SWD verification, budget tracking, skills, branch sandboxing, receipts, and optional `--test-cmd` healing. The prompt can come from the command line, a local file, or piped stdin. It exits after that prompt instead of opening the interactive REPL, and it does not overwrite the resumable chat session used by `mythos chat --resume`.
198
+
145
199
  ### `mythos chat` — Interactive Session
146
200
 
147
201
  ```bash
148
202
  mythos chat # Full power (high effort, Opus 4.7)
149
- mythos chat -s react # Load the 'react' expert skill
203
+ mythos chat -s repo # Load a project-local skill pack
150
204
  mythos chat --test-cmd "npm test" # Enable autonomous test-driven self-healing
151
- mythos chat --effort low # Budget mode (Haiku 4.5)
152
- mythos chat --effort medium # Balanced (Sonnet 4.6)
205
+ mythos chat --provider openai # Force a configured BYOK provider
206
+ mythos chat --effort low # Budget mode (Haiku 4.5 when using Claude)
207
+ mythos chat --effort medium # Balanced (Sonnet 4.6 when using Claude)
153
208
  mythos chat --resume # Resume your previous session exactly where you left off
154
209
  mythos chat --dry-run # Preview all file changes before executing
155
210
  mythos chat --verbose # See full SWD traces and thinking
@@ -203,6 +258,62 @@ In dry-run mode, every file operation is previewed before execution:
203
258
  In-session commands:
204
259
  - `/exit`, `/q` or `quit` — End session (shows final budget summary)
205
260
 
261
+ ### `mythos swd apply` — Bring Your Own Agent
262
+
263
+ ```bash
264
+ # Pipe raw [FILE_ACTION] blocks from any external agent
265
+ your-agent --task "update docs" | mythos swd apply --stdin --json
266
+
267
+ # Or pass a JSON action envelope
268
+ cat actions.json | mythos swd apply --stdin --json --agent python-agent --model local-llama
269
+
270
+ # Preview without touching disk or writing receipts
271
+ cat actions.json | mythos swd apply --stdin --dry-run --json
272
+
273
+ # High-impact files such as package.json require explicit opt-in; sensitive files stay blocked
274
+ cat actions.json | mythos swd apply --stdin --allow-risky --json
275
+ ```
276
+
277
+ `swd apply` is the model-free external-agent interface. It does **not** call Anthropic, OpenAI, DeepSeek, or any other model provider. Your agent keeps its own model key and only hands Mythos structured file actions. Mythos then applies Strict Write Discipline: path validation, security-policy review, pre/post snapshots, hash verification, rollback on failed verification, and local SWD receipts for successful non-dry-run applies.
278
+
279
+ Accepted input formats:
280
+
281
+ ```text
282
+ [FILE_ACTION: src/example.ts]
283
+ OPERATION: CREATE | MODIFY | DELETE | READ
284
+ INTENT: MUTATE | NOOP | UNKNOWN
285
+ CONTENT_HASH: <optional sha256 of final content>
286
+ DESCRIPTION: <one-line summary>
287
+ CONTENT:
288
+ <full file content for CREATE/MODIFY>
289
+ [/FILE_ACTION]
290
+ ```
291
+
292
+ ```json
293
+ {
294
+ "request": "external agent task label",
295
+ "summary": "CREATE: src/example.ts",
296
+ "agent": { "id": "python-agent", "model": "custom-model" },
297
+ "actions": [
298
+ {
299
+ "path": "src/example.ts",
300
+ "operation": "CREATE",
301
+ "intent": "MUTATE",
302
+ "description": "Create example file",
303
+ "content": "export const ok = true;\n"
304
+ }
305
+ ]
306
+ }
307
+ ```
308
+
309
+ Security defaults:
310
+ - input is size-limited and schema-validated before execution
311
+ - external JSON paths must be safe project-relative paths
312
+ - `.env`, private keys, wallet files, `.git`, `.npmrc`, and secrets paths are blocked
313
+ - deletes and command-surface files require `--allow-risky`
314
+ - dry-runs do not write files or receipts
315
+ - receipts record the external agent/model as `external:<agent-id>`
316
+
206
317
  ### `mythos receipts` — SWD Trust Receipts
207
318
 
208
319
  ```bash
@@ -212,19 +323,48 @@ mythos receipts verify latest # Re-check current files against receipt hashes
212
323
  mythos receipts --json # Machine-readable output for tooling
213
324
  ```
214
325
 
215
- Every non-dry-run SWD file operation writes a local receipt to `.mythos/receipts/`. Receipts include the user request summary, provider/model, token usage, budget snapshot, git branch/commit, per-file before/after hashes, rollback status, and optional `--test-cmd` result. `verify` turns those receipts into a quick drift check for "did the files still match what SWD verified?" Receipts are local by default and gitignored by default. They may include prompts, file paths, provider metadata, test command names, and a short test output tail. Do not publish raw receipts from private repositories; force-add only when you intentionally want a shared audit trail.
326
+ Every non-dry-run SWD file operation writes a local receipt to `.mythos/receipts/`. Receipts include the request summary, provider or external-agent/model identity, git branch/commit, per-file before/after hashes, rollback status, and verification errors. Built-in `chat`/`run` receipts also include token usage, budget snapshot, active skill packs, and optional `--test-cmd` result. `verify` turns those receipts into a quick drift check for "did the files still match what SWD verified?" Receipts are local by default and gitignored by default. They may include prompts, file paths, provider metadata, skill names, test command names, and a short test output tail. Do not publish raw receipts from private repositories; force-add only when you intentionally want a shared audit trail.
216
327
 
217
- ### `mythos verify` — Codebase Memory Existence Scan
328
+ ### `mythos verify` — Local Memory Scan + CI Verification
218
329
 
219
330
  ```bash
220
331
  mythos verify # Scan and log results to MEMORY.md
221
332
  mythos verify --dry-run # Scan without writing to MEMORY.md
333
+ mythos verify --ci # Read-only PR/diff verification for GitHub CI
334
+ mythos verify --ci --json # Machine-readable CI report
335
+ mythos verify --ci --strict # Fail CI on warnings as well as high findings
222
336
  ```
223
337
 
224
- Scans your project and cross-references against `MEMORY.md`:
338
+ Local mode scans your project and cross-references against `MEMORY.md`:
225
339
  - ✅ **Verified** — Memory logs are present and up to date
226
340
  - ❌ **Missing** — Memory references a file that doesn't exist
227
341
 
342
+ CI mode does not call a model and does not require an API key. It reviews the current PR/diff for high-impact repo changes such as package scripts, npm lifecycle hooks, GitHub Actions workflows, shell/deploy surfaces, `.env`/`.npmrc`, high-confidence secrets, and changed Mythos receipts.
343
+
344
+ GitHub Actions example:
345
+
346
+ ```yaml
347
+ name: Mythos Verify
348
+
349
+ on:
350
+ pull_request:
351
+ push:
352
+
353
+ jobs:
354
+ mythos-verify:
355
+ runs-on: ubuntu-latest
356
+ steps:
357
+ - uses: actions/checkout@v4
358
+ with:
359
+ fetch-depth: 0
360
+ - uses: actions/setup-node@v4
361
+ with:
362
+ node-version: 22
363
+ - run: npx mythos-router verify --ci
364
+ ```
365
+
366
+ See [`docs/CI.md`](docs/CI.md) for exit behavior, strict mode, JSON output, and examples.
367
+
228
368
  ### `mythos dream` — Memory Compression
229
369
 
230
370
  ```bash
@@ -289,11 +429,14 @@ mythos-router/
289
429
  ├── src/
290
430
  │ ├── cli.ts # Commander.js entry point
291
431
  │ ├── config.ts # System prompt + constants + budget defaults + validation
292
- │ ├── client.ts # Anthropic SDK (adaptive thinking, streaming)
432
+ │ ├── client.ts # Provider facade (Anthropic/OpenAI/DeepSeek BYOK routing)
293
433
  │ ├── budget.ts # Session budget limiter (token cap, turn cap, progress bar)
294
434
  │ ├── swd.ts # SWD execution kernel (engine, types, parsing, snapshots)
295
435
  │ ├── swd-cli.ts # SWD terminal presentation (verification output, dry-run)
296
436
  │ ├── receipts.ts # SWD trust receipt creation, storage, and verification
437
+ │ ├── skills.ts # Project-local and user-global SKILL.md packs
438
+ │ ├── learn.ts # Deterministic repo skill generator
439
+ │ ├── ci/ # Read-only CI verification for PR/diff risk review
297
440
  │ ├── memory.ts # MEMORY.md self-healing manager (SQLite FTS5 index)
298
441
  │ ├── metrics.ts # Global metrics store (persistent budget tracking)
299
442
  │ ├── diff.ts # Myers' diff algorithm (zero-dependency)
@@ -302,8 +445,12 @@ mythos-router/
302
445
  │ ├── index.ts # Public SDK exports
303
446
  │ └── commands/
304
447
  │ ├── chat.ts # Interactive REPL (ChatSession + ChatUI abstraction)
448
+ │ ├── init.ts # Project onboarding and read-only setup checks
305
449
  │ ├── verify.ts # Codebase ↔ Memory scanner (dry-run aware)
450
+ │ ├── swd.ts # External-agent SWD apply command
306
451
  │ ├── receipts.ts # SWD receipt list/show/verify command
452
+ │ ├── skills.ts # Skill pack list/show/new/check command
453
+ │ ├── learn.ts # Repo skill generation command
307
454
  │ ├── dream.ts # Memory compression (dry-run aware)
308
455
  │ └── stats.ts # Budget analytics reporter
309
456
  ├── src/providers/ # Multi-Provider Orchestration Engine
@@ -359,14 +506,20 @@ If you prefer to keep it private, add `MEMORY.md` to your `.gitignore`.
359
506
 
360
507
  | Env Variable | Required | Description |
361
508
  |-------------|----------|-------------|
362
- | `ANTHROPIC_API_KEY` | | Your Anthropic API key (Primary Provider) |
363
- | `OPENAI_API_KEY` | | OpenAI API Key (Fallback Provider) |
364
- | `DEEPSEEK_API_KEY` | | DeepSeek API Key (Fallback Provider, reasoning capable) |
509
+ | `ANTHROPIC_API_KEY` | Optional* | Anthropic/Claude key; recommended default provider for `chat`/`run` |
510
+ | `OPENAI_API_KEY` | Optional* | OpenAI API key; can be used as the only configured provider or fallback |
511
+ | `DEEPSEEK_API_KEY` | Optional* | DeepSeek API key; can be used as the only configured provider or fallback |
512
+
513
+ \* `mythos chat` and `mythos run` need at least one model provider key. `mythos swd apply` needs no model key because an external agent brings its own model/key and Mythos only verifies file actions.
365
514
 
366
515
  | File | Purpose |
367
516
  |------|---------|
368
517
  | `.mythosignore` | Patterns to exclude from SWD scanning |
518
+ | `.mythos/skills/` | Optional project-local skill packs that can be committed with a repo |
519
+ | `.mythos/receipts/` | Local SWD receipts, gitignored by default because they may include prompts and file paths |
369
520
  | `MEMORY.md` | Auto-generated agentic memory log |
521
+ | `~/.mythos-router/skills/` | User-global skill packs available across projects |
522
+ | `~/.mythos-router/sessions/` | Resumable chat session state |
370
523
 
371
524
  ---
372
525
 
package/SECURITY.md ADDED
@@ -0,0 +1,75 @@
1
+ # Security Policy
2
+
3
+ ## Philosophy
4
+
5
+ mythos-router follows a **zero-trust AI model**.
6
+
7
+ AI outputs are never trusted by default.
8
+ All file operations are verified against the actual filesystem before being accepted.
9
+
10
+ ---
11
+
12
+ ## Safe Execution
13
+
14
+ * AI-proposed file writes are routed through Strict Write Discipline (SWD) and verified against filesystem state.
15
+ * Normal SWD file operations do not execute shell commands.
16
+ * Git sandboxing uses fixed `git` subcommands with argument arrays.
17
+ * `--test-cmd` is an explicit user-supplied escape hatch. It runs the provided command through the local shell for test-healing workflows, so only pass commands you trust.
18
+ * There is no hidden shell lockdown mode; omit `--test-cmd` if you want model-driven sessions to avoid arbitrary shell execution.
19
+
20
+ ---
21
+
22
+ ## Environment Variables
23
+
24
+ * Sensitive values (e.g. API keys) require explicit configuration
25
+ * No implicit defaults are used for security-critical settings
26
+
27
+ ---
28
+
29
+ ## Local Data
30
+
31
+ mythos-router stores local state in predictable locations:
32
+
33
+ * `MEMORY.md` in the project root stores the human-readable agentic memory log.
34
+ * `memory.db`, `memory.db-wal`, and `memory.db-shm` in the project root are derivative SQLite indexes rebuilt from `MEMORY.md`.
35
+ * `.mythos/receipts/` stores local SWD receipts. These may include prompts, file paths, hashes, provider metadata, budget data, test command names, and a short redacted test output tail. This directory is gitignored by default.
36
+ * `~/.mythos-router/sessions/latest.json` stores the latest resumable conversation history and budget state.
37
+ * `~/.mythos-router/metrics.json` stores local token, cost, duration, command, and project metrics for `mythos stats`.
38
+ * `~/.mythos-router/cache.db` may store SDK response-cache entries when the cache API is used. Responses containing tool calls or SWD file actions are not cached.
39
+ * `~/.mythos-router/skills/` stores user-provided skill instructions loaded only when selected.
40
+
41
+ Treat session files, receipts, memory, and cache files as private project data. Delete the relevant file or directory to clear that local state.
42
+
43
+ ---
44
+
45
+ ## Scope
46
+
47
+ This tool is designed for **local execution only**.
48
+
49
+ Users are responsible for:
50
+
51
+ * reviewing AI-generated actions
52
+ * validating changes before applying in production environments
53
+
54
+ ---
55
+
56
+ ## Reporting a Vulnerability
57
+
58
+ If you discover a security vulnerability, please report it responsibly:
59
+
60
+ * X: **[@thewaltero](https://www.x.com/thewaltero)** *(recommended)*
61
+ * Or open a private security advisory on GitHub
62
+
63
+ Please avoid public disclosure until the issue has been reviewed.
64
+
65
+ ---
66
+
67
+ ## Supported Versions
68
+
69
+ Currently supported:
70
+
71
+ * Latest version on `main`
72
+
73
+ Older versions may not receive security updates.
74
+
75
+ ---
@@ -0,0 +1,6 @@
1
+ import type { DiffInfo } from './types.js';
2
+ export declare function assertGitRepository(cwd: string): void;
3
+ export declare function getDiffInfo(cwd: string, base?: string): DiffInfo;
4
+ export declare function readFileAtRef(cwd: string, ref: string, filePath: string): string | null;
5
+ export declare function readPackageJsonBeforeChange(diff: DiffInfo): string | null;
6
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/ci/git.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,YAAY,CAAC;AAgBxD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAKrD;AAoGD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAoBhE;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEvF;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAGzE"}