ghost-dragon 4.2.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.
Files changed (226) hide show
  1. package/.github/workflows/ci.yml +23 -0
  2. package/CHANGELOG.md +96 -0
  3. package/README.md +193 -0
  4. package/bootstrap.ps1 +83 -0
  5. package/bootstrap.sh +71 -0
  6. package/dist/agent/loop.d.ts +68 -0
  7. package/dist/agent/loop.d.ts.map +1 -0
  8. package/dist/agent/loop.js +135 -0
  9. package/dist/agent/mcp.d.ts +33 -0
  10. package/dist/agent/mcp.d.ts.map +1 -0
  11. package/dist/agent/mcp.js +107 -0
  12. package/dist/agent/session.d.ts +16 -0
  13. package/dist/agent/session.d.ts.map +1 -0
  14. package/dist/agent/session.js +55 -0
  15. package/dist/agent/skills.d.ts +36 -0
  16. package/dist/agent/skills.d.ts.map +1 -0
  17. package/dist/agent/skills.js +153 -0
  18. package/dist/agent/stack.d.ts +21 -0
  19. package/dist/agent/stack.d.ts.map +1 -0
  20. package/dist/agent/stack.js +158 -0
  21. package/dist/agent/task.d.ts +21 -0
  22. package/dist/agent/task.d.ts.map +1 -0
  23. package/dist/agent/task.js +45 -0
  24. package/dist/agent/tools.d.ts +44 -0
  25. package/dist/agent/tools.d.ts.map +1 -0
  26. package/dist/agent/tools.js +262 -0
  27. package/dist/agent/trace.d.ts +34 -0
  28. package/dist/agent/trace.d.ts.map +1 -0
  29. package/dist/agent/trace.js +72 -0
  30. package/dist/agent.d.ts +46 -0
  31. package/dist/agent.d.ts.map +1 -0
  32. package/dist/agent.js +103 -0
  33. package/dist/auth.d.ts +74 -0
  34. package/dist/auth.d.ts.map +1 -0
  35. package/dist/auth.js +116 -0
  36. package/dist/brain/anthropic.d.ts +19 -0
  37. package/dist/brain/anthropic.d.ts.map +1 -0
  38. package/dist/brain/anthropic.js +74 -0
  39. package/dist/brain/claude-cli.d.ts +20 -0
  40. package/dist/brain/claude-cli.d.ts.map +1 -0
  41. package/dist/brain/claude-cli.js +79 -0
  42. package/dist/brain/ghost-ember.d.ts +28 -0
  43. package/dist/brain/ghost-ember.d.ts.map +1 -0
  44. package/dist/brain/ghost-ember.js +97 -0
  45. package/dist/brain/index.d.ts +22 -0
  46. package/dist/brain/index.d.ts.map +1 -0
  47. package/dist/brain/index.js +95 -0
  48. package/dist/brain/openai-compat.d.ts +21 -0
  49. package/dist/brain/openai-compat.d.ts.map +1 -0
  50. package/dist/brain/openai-compat.js +119 -0
  51. package/dist/brain/router/classify.d.ts +23 -0
  52. package/dist/brain/router/classify.d.ts.map +1 -0
  53. package/dist/brain/router/classify.js +160 -0
  54. package/dist/brain/router/execute.d.ts +23 -0
  55. package/dist/brain/router/execute.d.ts.map +1 -0
  56. package/dist/brain/router/execute.js +84 -0
  57. package/dist/brain/router/index.d.ts +26 -0
  58. package/dist/brain/router/index.d.ts.map +1 -0
  59. package/dist/brain/router/index.js +118 -0
  60. package/dist/brain/router/routing-memory.d.ts +27 -0
  61. package/dist/brain/router/routing-memory.d.ts.map +1 -0
  62. package/dist/brain/router/routing-memory.js +77 -0
  63. package/dist/brain/router/select.d.ts +32 -0
  64. package/dist/brain/router/select.d.ts.map +1 -0
  65. package/dist/brain/router/select.js +146 -0
  66. package/dist/brain/router/two-hop.d.ts +23 -0
  67. package/dist/brain/router/two-hop.d.ts.map +1 -0
  68. package/dist/brain/router/two-hop.js +39 -0
  69. package/dist/brain/router/verify.d.ts +37 -0
  70. package/dist/brain/router/verify.d.ts.map +1 -0
  71. package/dist/brain/router/verify.js +111 -0
  72. package/dist/brain/types.d.ts +55 -0
  73. package/dist/brain/types.d.ts.map +1 -0
  74. package/dist/brain/types.js +16 -0
  75. package/dist/brain/worker.d.ts +27 -0
  76. package/dist/brain/worker.d.ts.map +1 -0
  77. package/dist/brain/worker.js +71 -0
  78. package/dist/commands/ai.d.ts +24 -0
  79. package/dist/commands/ai.d.ts.map +1 -0
  80. package/dist/commands/ai.js +137 -0
  81. package/dist/commands/alerts.d.ts +19 -0
  82. package/dist/commands/alerts.d.ts.map +1 -0
  83. package/dist/commands/alerts.js +114 -0
  84. package/dist/commands/billing.d.ts +13 -0
  85. package/dist/commands/billing.d.ts.map +1 -0
  86. package/dist/commands/billing.js +55 -0
  87. package/dist/commands/chat.d.ts +22 -0
  88. package/dist/commands/chat.d.ts.map +1 -0
  89. package/dist/commands/chat.js +422 -0
  90. package/dist/commands/config.d.ts +18 -0
  91. package/dist/commands/config.d.ts.map +1 -0
  92. package/dist/commands/config.js +136 -0
  93. package/dist/commands/doctor.d.ts +11 -0
  94. package/dist/commands/doctor.d.ts.map +1 -0
  95. package/dist/commands/doctor.js +73 -0
  96. package/dist/commands/global.d.ts +11 -0
  97. package/dist/commands/global.d.ts.map +1 -0
  98. package/dist/commands/global.js +253 -0
  99. package/dist/commands/keep.d.ts +12 -0
  100. package/dist/commands/keep.d.ts.map +1 -0
  101. package/dist/commands/keep.js +58 -0
  102. package/dist/commands/lifecycle.d.ts +17 -0
  103. package/dist/commands/lifecycle.d.ts.map +1 -0
  104. package/dist/commands/lifecycle.js +267 -0
  105. package/dist/commands/login.d.ts +16 -0
  106. package/dist/commands/login.d.ts.map +1 -0
  107. package/dist/commands/login.js +234 -0
  108. package/dist/commands/maintenance.d.ts +12 -0
  109. package/dist/commands/maintenance.d.ts.map +1 -0
  110. package/dist/commands/maintenance.js +76 -0
  111. package/dist/commands/mcp.d.ts +16 -0
  112. package/dist/commands/mcp.d.ts.map +1 -0
  113. package/dist/commands/mcp.js +56 -0
  114. package/dist/commands/memory.d.ts +13 -0
  115. package/dist/commands/memory.d.ts.map +1 -0
  116. package/dist/commands/memory.js +218 -0
  117. package/dist/commands/osint.d.ts +14 -0
  118. package/dist/commands/osint.d.ts.map +1 -0
  119. package/dist/commands/osint.js +161 -0
  120. package/dist/commands/pentest.d.ts +13 -0
  121. package/dist/commands/pentest.d.ts.map +1 -0
  122. package/dist/commands/pentest.js +131 -0
  123. package/dist/commands/scale.d.ts +14 -0
  124. package/dist/commands/scale.d.ts.map +1 -0
  125. package/dist/commands/scale.js +191 -0
  126. package/dist/commands/serve.d.ts +16 -0
  127. package/dist/commands/serve.d.ts.map +1 -0
  128. package/dist/commands/serve.js +167 -0
  129. package/dist/commands/tui.d.ts +17 -0
  130. package/dist/commands/tui.d.ts.map +1 -0
  131. package/dist/commands/tui.js +138 -0
  132. package/dist/commands/wyrm.d.ts +20 -0
  133. package/dist/commands/wyrm.d.ts.map +1 -0
  134. package/dist/commands/wyrm.js +274 -0
  135. package/dist/config.d.ts +67 -0
  136. package/dist/config.d.ts.map +1 -0
  137. package/dist/config.js +54 -0
  138. package/dist/index.d.ts +16 -0
  139. package/dist/index.d.ts.map +1 -0
  140. package/dist/index.js +85 -0
  141. package/dist/manifest.d.ts +31 -0
  142. package/dist/manifest.d.ts.map +1 -0
  143. package/dist/manifest.js +83 -0
  144. package/dist/ui.d.ts +57 -0
  145. package/dist/ui.d.ts.map +1 -0
  146. package/dist/ui.js +174 -0
  147. package/dist/utils.d.ts +33 -0
  148. package/dist/utils.d.ts.map +1 -0
  149. package/dist/utils.js +155 -0
  150. package/dist/wyrm/mcp.d.ts +37 -0
  151. package/dist/wyrm/mcp.d.ts.map +1 -0
  152. package/dist/wyrm/mcp.js +137 -0
  153. package/docs/SYSTEM-PREMORTEM.md +397 -0
  154. package/dragon-manifest.toml +241 -0
  155. package/dragon.py +177 -0
  156. package/install/launchd/lk.ghosts.dragonkeep.plist +57 -0
  157. package/install/systemd/dragonkeep.service +40 -0
  158. package/media/dragon-silver-lockup.svg +931 -0
  159. package/media/dragon-silver-mark.svg +931 -0
  160. package/media/dragon-silver.png +0 -0
  161. package/package.json +45 -0
  162. package/specs/001-godmode/constitution.md +54 -0
  163. package/specs/001-godmode/plan.md +30 -0
  164. package/specs/001-godmode/spec.md +64 -0
  165. package/specs/001-godmode/tasks.md +35 -0
  166. package/specs/002-premortem-positioning/premortem.md +211 -0
  167. package/src/agent/loop.ts +165 -0
  168. package/src/agent/mcp.ts +92 -0
  169. package/src/agent/session.ts +48 -0
  170. package/src/agent/skills.ts +138 -0
  171. package/src/agent/stack.ts +154 -0
  172. package/src/agent/task.ts +55 -0
  173. package/src/agent/tools.ts +255 -0
  174. package/src/agent/trace.ts +76 -0
  175. package/src/agent.ts +114 -0
  176. package/src/auth.ts +133 -0
  177. package/src/brain/anthropic.ts +83 -0
  178. package/src/brain/claude-cli.ts +78 -0
  179. package/src/brain/ghost-ember.ts +94 -0
  180. package/src/brain/index.ts +99 -0
  181. package/src/brain/openai-compat.ts +115 -0
  182. package/src/brain/router/classify.ts +167 -0
  183. package/src/brain/router/execute.ts +80 -0
  184. package/src/brain/router/index.ts +125 -0
  185. package/src/brain/router/routing-memory.ts +71 -0
  186. package/src/brain/router/select.ts +156 -0
  187. package/src/brain/router/two-hop.ts +62 -0
  188. package/src/brain/router/verify.ts +123 -0
  189. package/src/brain/types.ts +61 -0
  190. package/src/brain/worker.ts +72 -0
  191. package/src/commands/ai.ts +144 -0
  192. package/src/commands/alerts.ts +131 -0
  193. package/src/commands/billing.ts +59 -0
  194. package/src/commands/chat.ts +318 -0
  195. package/src/commands/config.ts +137 -0
  196. package/src/commands/doctor.ts +71 -0
  197. package/src/commands/global.ts +256 -0
  198. package/src/commands/keep.ts +67 -0
  199. package/src/commands/lifecycle.ts +273 -0
  200. package/src/commands/login.ts +184 -0
  201. package/src/commands/maintenance.ts +54 -0
  202. package/src/commands/mcp.ts +57 -0
  203. package/src/commands/memory.ts +229 -0
  204. package/src/commands/osint.ts +171 -0
  205. package/src/commands/pentest.ts +140 -0
  206. package/src/commands/scale.ts +185 -0
  207. package/src/commands/serve.ts +171 -0
  208. package/src/commands/tui.ts +126 -0
  209. package/src/commands/wyrm.ts +269 -0
  210. package/src/config.ts +93 -0
  211. package/src/index.ts +92 -0
  212. package/src/manifest.ts +104 -0
  213. package/src/ui.ts +188 -0
  214. package/src/utils.ts +153 -0
  215. package/src/wyrm/mcp.ts +130 -0
  216. package/test/auth.test.ts +70 -0
  217. package/test/brain.test.ts +39 -0
  218. package/test/security.test.ts +104 -0
  219. package/test/skills.test.ts +38 -0
  220. package/test/ui.test.ts +46 -0
  221. package/tsconfig.json +19 -0
  222. package/worker/package-lock.json +1527 -0
  223. package/worker/package.json +17 -0
  224. package/worker/src/index.ts +76 -0
  225. package/worker/tsconfig.json +15 -0
  226. package/worker/wrangler.toml +26 -0
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ build-test:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: actions/setup-node@v4
14
+ with:
15
+ node-version: '22'
16
+ cache: npm
17
+ - run: npm ci
18
+ - name: Build
19
+ run: npm run build
20
+ - name: Typecheck (no dead code)
21
+ run: npm run typecheck
22
+ - name: Tests (security + pure logic)
23
+ run: npx vitest run
package/CHANGELOG.md ADDED
@@ -0,0 +1,96 @@
1
+ # Changelog
2
+
3
+ ## 4.2.1 (2026-06-04)
4
+
5
+ Positioning + hardening pass from the premortem & competitive teardown
6
+ (`specs/002-premortem-positioning/premortem.md`, methodology captured as the
7
+ `agentic-cli-premortem` skill). No new features — breadth is deliberately frozen.
8
+
9
+ - **README reframed** from the stale v1.0.0 "product manager" framing to what Dragon
10
+ actually is: the **sovereign operator console for the Ghost Protocol stack**. Leads with
11
+ the three wedges the incumbents can't follow (sovereignty, owned cross-session memory,
12
+ stack-fusion), an honest three-way matrix vs Claude Code / Copilot CLI, and a Positioning
13
+ note (bundled/internal, not a public coding-CLI). DragonSpark/`ghost` reframed as optional
14
+ R&D upside, not a dependency.
15
+ - **Closed the "untested authed / single-machine path" gap.** Extracted pure, injectable
16
+ cores so the previously machine-dependent paths are deterministically tested:
17
+ `resolveAuthFrom(env, cfg)` in `auth.ts` (token > session > none precedence, env > config,
18
+ origin self-heal, header-injection rejection) and `normalizeWorkerTurn(data)` in
19
+ `brain/worker.ts` (tolerant of the flaky fp8 tool-caller — string/object/missing args,
20
+ nameless tool_calls, empty response). +14 tests (`test/auth.test.ts`, `test/brain.test.ts`).
21
+ - Corrected stale `auth.ts` doc comment (device-flow shipped; token is the primary path).
22
+
23
+ ## 4.2.0 (2026-06-04)
24
+
25
+ `dragon tui` rebuilt into an operator command-center, in the ghosts.lk visual language
26
+ (near-black depth, brushed-chrome, a whisper of emerald), using advanced/obscure
27
+ terminal-graphics craft (now captured as the `advanced-tui-design` +
28
+ `terminal-subcell-graphics` skills):
29
+
30
+ - **Flicker-free**: runs on the alternate screen buffer (htop-style; restores your
31
+ scrollback), hides the cursor, and paints each frame inside **synchronized output
32
+ (DEC ?2026)** with per-line clear-to-EOL — atomic, tear-free frames.
33
+ - **Hero**: chrome-gradient phantom sigil + letter-spaced wordmark + eyebrow + tagline.
34
+ - **Live panels**: two-column SYSTEM · SIGNAL with status dots, a **disk gauge**
35
+ (eighth-cell precision, green→amber→red) and a **traces-per-hour sparkline**
36
+ (`▁▂▃▄▅▆▇█`), plus a pulsing emerald OPSEC bar with a heartbeat.
37
+ - New `ui.ts` primitives: `sparkline()`, `gauge()`, `joinColumns()`, `chromeRule()`,
38
+ `emerald`. Width-aware (wide columns / narrow stacked); graceful color downsampling.
39
+
40
+ ## 4.1.0 (2026-06-04)
41
+
42
+ Structured stack-action tools — closes the last godmode item. Contracts mapped by
43
+ parallel investigation agents, one per product.
44
+
45
+ - **`stack_pentest`** — runs a PhantomDragon web scan against a URL (authorized
46
+ targets only; `dangerous`, always prompts) and returns structured findings
47
+ (severity, category, CVSS, confirmed, remediation) + risk summary, parsed from
48
+ the scanner's native `findings.json`.
49
+ - **`stack_keep`** — runs a DragonKeep system-security scan (read-only) via
50
+ `--format json` and returns structured findings (severity, CVSS, fix) + summary.
51
+ stdout/stderr kept separate so progress never corrupts the parsed JSON.
52
+ - **OSINT/DragonNet** needs no bespoke tool — it ships an MCP server; wire it with
53
+ `dragon mcp add dragonnet …` and the MCP hub exposes its 5 tools.
54
+
55
+ ## 4.0.0 — "Godmode" (2026-06-04)
56
+
57
+ Dragon becomes a flagship operator toolkit: a Claude-Code-style coding **and** ops
58
+ agent that runs on any brain, remembers across sessions, and is hardened like we'd
59
+ pentest a client. (Major bump — the CLI is fundamentally an agent now.)
60
+
61
+ ### Agent
62
+ - Client-side model↔tool loop with local coding tools: read / write / edit / list /
63
+ glob / grep / bash.
64
+ - **Pluggable brain** with graceful fallback + first-run picker: `claude` (default) ·
65
+ `worker` (free Cloudflare Workers AI, zero-key) · `local` (Ollama) · `ghost`
66
+ (DragonSpark) · `openai` · `custom` (any OpenAI-compatible endpoint).
67
+ - **Deep Wyrm memory** by default — recall + capture across sessions; primes project context.
68
+ - **Skills-as-tools** — search + apply the 200+ Ghost Protocol skill library mid-task.
69
+ - **Stack-fused** — `stack_status` / `stack_run` drive the whole dragon stack.
70
+ - **Sub-agents** — a `task` tool spawns focused read-only investigators.
71
+ - **MCP hub** — `dragon mcp add` wires in any MCP server's tools.
72
+ - Hosted account assistant available as the `portal_ask` tool.
73
+
74
+ ### Auth
75
+ - `dragon login` browser device-code flow (90-day bearer tokens); `--session`/`--token` fallbacks.
76
+
77
+ ### Safety (DEF-CON self-pentest → fixed)
78
+ - File tools confined to the working dir (symlink-aware); credential paths blocked.
79
+ - `bash` is always-prompt (never auto-run); catastrophic-command flagging; full command shown.
80
+ - `--sandbox` runs shell in a bwrap jail (cwd writable, rest read-only, secrets masked).
81
+ - Secrets 0600 (config + traces); broad redaction; credential header-injection guard;
82
+ SSRF / restricted-port URL guard; global crash handler (`--debug` for stacks).
83
+
84
+ ### Modes & QoL
85
+ - `--auto` (safe in-cwd writes) · `--plan` (read-only) · `--sovereign` (local brain + Wyrm only).
86
+ - `dragon doctor` (health panel) · `dragon brains` (model picker) · `dragon tui` (live dashboard)
87
+ · `dragon mcp` · `dragon completions` (bash/zsh/fish) · `dragon upgrade` (self-update).
88
+ - Session resume (`--resume`) + transcript export (`/save`). Trace flywheel → DragonSpark.
89
+
90
+ ### Brand & quality
91
+ - Stealth-silver "ops console" theme across every surface.
92
+ - 21 adversarial/unit tests + GitHub Actions CI (build + no-unused + tests).
93
+
94
+ ### Companions
95
+ - DragonSpark (our nano-LLM, the `ghost` brain) scaffolded; DragonBrain appliance now
96
+ bundles the agent for sovereign on-box operation.
package/README.md ADDED
@@ -0,0 +1,193 @@
1
+ <p align="center">
2
+ <img src="media/dragon-silver.png" alt="Ghost Protocol Dragon" width="190" />
3
+ </p>
4
+
5
+ <h1 align="center">Dragon CLI</h1>
6
+
7
+ **The sovereign operator console for the Ghost Protocol stack.** A Claude-Code-style
8
+ agentic coding **and** ops CLI that runs on any brain — including fully on-host or free —
9
+ remembers across every project, drives Ghost Protocol's own security tooling, and is
10
+ hardened like we'd pentest a client.
11
+
12
+ ```
13
+ ▄▄▄▄▄
14
+ ▟█████▙ G H O S T P R O T O C O L
15
+ █ ▘ ▘ █ ▌ OPERATOR CONSOLE // DRAGON v4.2.1
16
+ ▜█████▛ on-host coding + ops agent · sovereign-capable · ghosts.lk
17
+ ▘▘ ▘▘
18
+ ```
19
+
20
+ > Proprietary © 2026 Ghost Protocol (Pvt) Ltd. Internal + bundled tooling — not a public,
21
+ > general-purpose coding CLI. See **[Positioning](#positioning)** for why that's deliberate.
22
+
23
+ ---
24
+
25
+ ## Why this exists (and why it isn't trying to be "Claude Code, but ours")
26
+
27
+ Claude Code (Anthropic) and Copilot CLI (GitHub) are excellent, better-resourced, and own
28
+ the model frontier. Dragon does **not** try to out-quality them on raw model output — that's
29
+ a losing axis. It wins on the three things neither incumbent can structurally follow:
30
+
31
+ | | **Dragon** | Claude Code | Copilot CLI |
32
+ |---|---|---|---|
33
+ | **Sovereignty** — runs fully on-host or free | ✅ `--sovereign` (local + Wyrm, zero cloud) · free `worker` brain | ❌ cloud-only | ❌ cloud-only |
34
+ | **Memory you own** — cross-session, cross-project | ✅ Wyrm by default | partial (vendor-side) | ❌ cloud-tied |
35
+ | **Stack-fusion** — drives our own security tools | ✅ `stack_pentest` · `stack_keep` | ❌ | ❌ |
36
+ | Cost floor | **~$0** (local/worker) | $$$ | $$ (premium requests) |
37
+ | Hardening | built + self-pentested by us | OS sandbox | `/sandbox` |
38
+ | Model quality | rents the best (Claude default) | **owns it** | rents Claude |
39
+
40
+ It rents the best model when quality matters (Claude is the default brain) and falls back to
41
+ free or fully-local brains when sovereignty or cost matters more. **Use the right tool for the
42
+ job** — Dragon is the one wired into *our* stack and memory.
43
+
44
+ ---
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ git clone https://github.com/ghosts-lk/dragon-cli.git
50
+ cd dragon-cli
51
+ npm install && npm run build && npm link # → `dragon` on your PATH
52
+ # or run from source without linking:
53
+ npx tsx src/index.ts --help
54
+ ```
55
+
56
+ Requires **Node.js 18+**. On first `dragon chat` with no brain configured you'll get a model
57
+ picker; or sign in for the free brain with `dragon login`.
58
+
59
+ ---
60
+
61
+ ## Quick start
62
+
63
+ ```bash
64
+ dragon login # browser device-code sign-in → free Cloudflare brain, no API key
65
+ dragon chat # interactive agent REPL (coding + ops)
66
+ dragon ask "what changed in src today?" # one-shot, read-only by default
67
+ dragon doctor # health panel: brain, auth, memory, skills, stack
68
+ dragon tui # live operator command-center (press q to quit)
69
+ ```
70
+
71
+ In `chat`: `/brain` switch model · `/tools` list · `/memory <q>` recall · `/auto` arm safe
72
+ writes · `/plan` read-only · `@path` attach a file · `/save` export transcript · Ctrl-C aborts
73
+ the turn.
74
+
75
+ ---
76
+
77
+ ## Brains (pluggable model, with graceful fallback)
78
+
79
+ Tools always execute **locally**; the brain only does inference. Pick per-invocation with
80
+ `--brain <id>`, or set a default with `dragon brains` / `dragon config brain <id>`.
81
+
82
+ | Brain | What it is | Needs |
83
+ |---|---|---|
84
+ | `claude` *(default)* | Anthropic Claude (`claude-sonnet-4-6`) — best quality | `ANTHROPIC_API_KEY` |
85
+ | `worker` | **Free**, zero-key — our Cloudflare Workers AI (Llama 3.3 70B) | just `dragon login` |
86
+ | `local` | Ollama / any OpenAI-compatible local server — sovereign, $0 | Ollama running |
87
+ | `ghost` | **DragonSpark**, our own nano-LLM *(optional R&D upside — not required)* | DragonSpark served |
88
+ | `openai` | OpenAI models | `OPENAI_API_KEY` |
89
+ | `custom` | Any OpenAI-compatible endpoint (OpenRouter, vLLM, LM Studio…) | `DRAGON_OPENAI_BASE` |
90
+
91
+ A configured brain that can't run (e.g. `claude` with no key) **auto-falls back** to `worker`
92
+ (if signed in) and then `local`, so the CLI always does *something* useful.
93
+
94
+ ---
95
+
96
+ ## What the agent can do (tool surface)
97
+
98
+ - **Code** — read / write / edit / list / glob / grep / bash (local files, ripgrep-backed).
99
+ - **Remember** — deep **Wyrm** memory by default: recalls + captures across sessions, primes
100
+ project context into the system prompt.
101
+ - **Apply skills** — searches + reads the 200+ Ghost Protocol skill library mid-task
102
+ (`skill_search` / `skill_read`).
103
+ - **Drive the stack** — `stack_status` / `stack_run` (any `dragon` subcommand),
104
+ `stack_pentest` (PhantomDragon web scan → structured findings),
105
+ `stack_keep` (DragonKeep system scan → structured findings).
106
+ - **Delegate** — a read-only `task` sub-agent for focused investigation.
107
+ - **Extend** — an **MCP hub**: `dragon mcp add <name> …` wires any MCP server's tools in.
108
+ - **Ask the portal** — `portal_ask` hits the hosted account.ghosts.lk assistant (when signed in).
109
+
110
+ ### Modes
111
+
112
+ ```bash
113
+ dragon chat --auto # allow safe, in-cwd file writes without prompting
114
+ dragon ask --plan # read-only profile (no writes, no bash mutations)
115
+ dragon chat --sovereign # local brain + Wyrm only — no cloud, no portal
116
+ dragon chat --sandbox # run bash inside a bubblewrap jail (cwd writable, rest read-only,
117
+ # ~/.ssh /.aws /.gnupg /.dragon masked via tmpfs)
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Security (built + self-pentested by the team that sells pentests)
123
+
124
+ This is both the biggest liability of an agent that can touch your machine **and** the point.
125
+ The hardening must never regress:
126
+
127
+ - **Working-dir confinement** — file tools are sandboxed to the cwd (realpath/symlink-aware);
128
+ reads outside need approval; **credential paths are blocked outright**
129
+ (`.ssh`, `.aws`, `.gnupg`, `.dragon`, `.env`, `*.pem`).
130
+ - **`bash` is always-prompt** — never auto-run, the full command is shown, catastrophic
131
+ patterns are flagged. `--sandbox` adds a bubblewrap jail.
132
+ - **Secrets at rest 0600** — config + traces; broad redaction of key/cookie/JWT shapes in
133
+ traces and logs.
134
+ - **Network guards** — restricted-port / SSRF URL guard; HTTP-header-injection guard on all
135
+ credentials (no CRLF smuggling).
136
+ - **Fail safe** — global crash handler (`--debug` for stacks); a slow/broken brain or Wyrm
137
+ degrades gracefully instead of hanging.
138
+
139
+ Verified by an adversarial unit suite (`npm test`) + GitHub Actions CI (build · typecheck ·
140
+ tests). The auth-resolution and worker-brain paths are pure-function-tested so they're
141
+ deterministic on any machine — not just the author's.
142
+
143
+ ---
144
+
145
+ ## Commands
146
+
147
+ ```bash
148
+ dragon chat | ask # the agent (interactive REPL | one-shot)
149
+ dragon login # browser device-code sign-in (--paste for headless boxes)
150
+ dragon brains # interactive model picker / set default brain
151
+ dragon config <...> # brain | model | key | custom-url | show
152
+ dragon doctor # health panel · dragon contract (config contract test)
153
+ dragon tui # live operator command-center
154
+ dragon mcp add|list|remove # MCP server hub
155
+ dragon completions <shell> # bash | zsh | fish completions
156
+ dragon upgrade # git-pull self-update
157
+ dragon --help # everything, incl. the per-product stack commands
158
+ ```
159
+
160
+ Stack commands (`dragon scale | wyrm | pentest | keep | osint | …`) drive the individual
161
+ Ghost Protocol products; the agent reaches them via `stack_run`. See `dragon --help`.
162
+
163
+ ---
164
+
165
+ ## Configuration
166
+
167
+ Stored at `~/.dragon/config.json` (mode **0600** — it may hold a token). Holds the active
168
+ brain + model, product paths, MCP servers, and auth. Env vars always override config:
169
+ `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `DRAGON_BRAIN`, `DRAGON_MODEL`, `DRAGON_TOKEN`,
170
+ `DRAGON_SESSION`, `DRAGON_API`, `DRAGON_LOCAL_URL`, `DRAGON_GHOST_URL`, `DRAGON_OPENAI_BASE`,
171
+ `DRAGON_NO_TRACE`.
172
+
173
+ The trace flywheel logs each settled turn (secret-redacted) to `~/.dragon/traces/<date>.jsonl`
174
+ → training data for DragonSpark. Disable with `--no-trace` / `DRAGON_NO_TRACE`.
175
+
176
+ ---
177
+
178
+ ## Tech stack
179
+
180
+ Node 18+ · TypeScript (ESM) · Commander · `@anthropic-ai/sdk` · `@modelcontextprotocol/sdk` ·
181
+ chalk · boxen · conf · vitest. DragonBrain bundles the agent for sovereign on-box operation.
182
+
183
+ ## Positioning
184
+
185
+ Dragon is **bundled and internal**, not a public coding-CLI vying for mindshare against
186
+ Anthropic and GitHub. Its job is to (a) make Ghost Protocol's solo operator faster across the
187
+ portfolio, and (b) ship as the sovereign agent inside DragonBrain / the PTaaS offering, where
188
+ the buyer is already acquired. The deep analysis behind this is in
189
+ [`specs/002-premortem-positioning/premortem.md`](specs/002-premortem-positioning/premortem.md).
190
+
191
+ ## License
192
+
193
+ Proprietary © 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved · [ghosts.lk](https://ghosts.lk)
package/bootstrap.ps1 ADDED
@@ -0,0 +1,83 @@
1
+ # Ghost Protocol · Dragon Stack Bootstrap · Windows PowerShell
2
+ # Pipe into PowerShell on a fresh Windows machine:
3
+ # iwr -useb https://raw.githubusercontent.com/ghosts-lk/dragon-cli/main/bootstrap.ps1 | iex
4
+ #
5
+ # Spec: dragon-platform/specs/009-bootstrap-cross-os
6
+ # Copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
7
+
8
+ $ErrorActionPreference = "Stop"
9
+ $Esc = [char]27
10
+ function Green($t) { Write-Host "$Esc[32m$t$Esc[0m" }
11
+ function Dim($t) { Write-Host "$Esc[2m$t$Esc[0m" }
12
+ function Warn($t) { Write-Host "$Esc[33m! $t$Esc[0m" }
13
+ function Fail($t) { Write-Host "$Esc[31mx $t$Esc[0m"; exit 1 }
14
+
15
+ Green "[Dragon Stack Bootstrap · Windows] Ghost Protocol · ghosts.lk"
16
+ Write-Host ""
17
+
18
+ # 1. Sanity checks
19
+ foreach ($cmd in @("git", "node", "npm")) {
20
+ if (-not (Get-Command $cmd -ErrorAction SilentlyContinue)) {
21
+ Fail "Missing required tool: $cmd · install Node 22+ (https://nodejs.org) and Git, then re-run"
22
+ }
23
+ }
24
+
25
+ # 2. Recommended tools
26
+ if (-not (Get-Command python -ErrorAction SilentlyContinue) -and
27
+ -not (Get-Command python3 -ErrorAction SilentlyContinue)) {
28
+ Warn "python not found · Phantom Memory + DragonChronicle will be skipped"
29
+ }
30
+ if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {
31
+ Warn "cargo not found · DragonKeep build will be skipped (https://rustup.rs)"
32
+ }
33
+ if (-not (Get-Command pnpm -ErrorAction SilentlyContinue)) {
34
+ Warn "pnpm not found · npm install -g pnpm recommended"
35
+ }
36
+
37
+ # 3. Resolve install root
38
+ $Root = if ($env:DRAGON_ROOT) { $env:DRAGON_ROOT } else { Join-Path $HOME "GitProjects" }
39
+ New-Item -ItemType Directory -Force -Path $Root | Out-Null
40
+ Green "Install root: $Root"
41
+
42
+ # 4. Clone dragon-cli
43
+ $CliDir = Join-Path $Root "dragon-cli"
44
+ if (Test-Path $CliDir) {
45
+ Dim " ~ dragon-cli already present · pulling latest"
46
+ Push-Location $CliDir
47
+ git pull --quiet
48
+ Pop-Location
49
+ } else {
50
+ Green " + cloning dragon-cli"
51
+ git clone --quiet https://github.com/ghosts-lk/dragon-cli.git $CliDir
52
+ }
53
+
54
+ # 5. Build dragon-cli
55
+ Push-Location $CliDir
56
+ Green " + npm install + build"
57
+ npm install --silent
58
+ npm run build --silent
59
+ Pop-Location
60
+
61
+ # 6. Add `dragon` to PATH via a Scripts shim
62
+ $ShimDir = Join-Path $env:LOCALAPPDATA "Dragon\bin"
63
+ New-Item -ItemType Directory -Force -Path $ShimDir | Out-Null
64
+ $ShimPath = Join-Path $ShimDir "dragon.cmd"
65
+ $NodePath = (Get-Command node).Source
66
+ $EntryJs = Join-Path $CliDir "dist\index.js"
67
+ @"
68
+ @echo off
69
+ "$NodePath" "$EntryJs" %*
70
+ "@ | Set-Content -Encoding ASCII $ShimPath
71
+
72
+ # 7. Persist PATH (user scope)
73
+ $userPath = [Environment]::GetEnvironmentVariable("Path", "User")
74
+ if ($userPath -notlike "*$ShimDir*") {
75
+ [Environment]::SetEnvironmentVariable("Path", "$userPath;$ShimDir", "User")
76
+ Green " + added $ShimDir to user PATH (restart shell to pick up)"
77
+ }
78
+
79
+ # 8. Optional: register dragonkeep as a Windows Service (admin only)
80
+ Write-Host ""
81
+ Green "[Dragon] bootstrap complete · run 'dragon list' to see installable modules"
82
+ Dim "[Dragon] Windows ETW path: 'dragonkeep monitor --etw' (run elevated)"
83
+ Dim "[Dragon] open Dragon Console: 'dragon up dragon-console' then http://localhost:4090"
package/bootstrap.sh ADDED
@@ -0,0 +1,71 @@
1
+ #!/bin/sh
2
+ # Ghost Protocol · Dragon Stack Bootstrap
3
+ # Pipe into shell on a fresh machine:
4
+ # curl -fsSL https://raw.githubusercontent.com/ghosts-lk/dragon-cli/main/bootstrap.sh | sh
5
+ #
6
+ # Copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
7
+
8
+ set -e
9
+
10
+ GREEN='\033[0;32m'
11
+ DIM='\033[2m'
12
+ RESET='\033[0m'
13
+
14
+ echo "${GREEN}[Dragon Stack Bootstrap]${RESET} Ghost Protocol · ghosts.lk"
15
+ echo ""
16
+
17
+ # 1. Sanity checks
18
+ for cmd in git node npm; do
19
+ if ! command -v "$cmd" >/dev/null 2>&1; then
20
+ echo "✗ Missing required tool: $cmd"
21
+ echo " Install Node 18+ (https://nodejs.org) and git, then re-run."
22
+ exit 1
23
+ fi
24
+ done
25
+
26
+ # 2. Check Python (recommended)
27
+ if ! command -v python3 >/dev/null 2>&1; then
28
+ echo "⚠ python3 not found — Python tools (Phantom Memory, MCP servers, DragonChronicle) will be skipped"
29
+ fi
30
+
31
+ # 3. Check pnpm (recommended)
32
+ if ! command -v pnpm >/dev/null 2>&1; then
33
+ echo "⚠ pnpm not found — npm install -g pnpm recommended for monorepo products"
34
+ fi
35
+
36
+ # 4. Check Rust (DragonKeep)
37
+ if ! command -v cargo >/dev/null 2>&1; then
38
+ echo "⚠ cargo not found — DragonKeep build will be skipped (https://rustup.rs)"
39
+ fi
40
+
41
+ # 5. Clone dragon-cli if not present
42
+ DRAGON_HOME="${DRAGON_HOME:-$HOME/Git Projects/dragon-cli}"
43
+ if [ ! -d "$DRAGON_HOME/.git" ]; then
44
+ echo "${DIM}Cloning dragon-cli to $DRAGON_HOME${RESET}"
45
+ mkdir -p "$(dirname "$DRAGON_HOME")"
46
+ git clone https://github.com/ghosts-lk/dragon-cli.git "$DRAGON_HOME"
47
+ fi
48
+
49
+ # 6. Build + link dragon
50
+ echo "${DIM}Installing dragon-cli...${RESET}"
51
+ cd "$DRAGON_HOME"
52
+ npm install --silent
53
+ npm run build
54
+ npm link
55
+
56
+ # 7. Run the full stack bootstrap
57
+ echo ""
58
+ echo "${GREEN}[dragon up]${RESET} bringing up the rest of the stack..."
59
+ echo ""
60
+ dragon up
61
+
62
+ echo ""
63
+ echo "${GREEN}✓ Dragon stack bootstrap complete.${RESET}"
64
+ echo ""
65
+ echo "Next steps:"
66
+ echo " dragon list — see installed products"
67
+ echo " dragon serve — start the daemons"
68
+ echo " dragon status — verify everything is online"
69
+ echo " dragon ai mcp-config — wire Claude Desktop to the MCP servers"
70
+ echo ""
71
+ echo "Documentation: https://ghosts.lk"
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The agent loop — Dragon's engine. Runs the model↔tool cycle entirely
3
+ * client-side so tools touch THIS machine:
4
+ *
5
+ * user → brain.turn(tools) → [tool calls?] → execute locally → feed back → repeat
6
+ * └ no calls → final answer, done
7
+ *
8
+ * Tools come from three sources, routed by name: local coding tools (read/edit/
9
+ * bash/grep…), the curated Wyrm memory tools (`wyrm_*` → MCP), and the optional
10
+ * hosted Dragon portal (`portal_ask`). Wyrm is wired by default and the system
11
+ * prompt tells the model to use it as long-term memory.
12
+ *
13
+ * Copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
14
+ */
15
+ import type { Brain, BrainMessage, ToolSpec } from '../brain/types.js';
16
+ import { type ToolContext } from './tools.js';
17
+ import type { Wyrm } from '../wyrm/mcp.js';
18
+ import type { SkillLibrary } from './skills.js';
19
+ import type { StackTools } from './stack.js';
20
+ import type { McpHub } from './mcp.js';
21
+ import type { TaskTool } from './task.js';
22
+ export interface PortalTool {
23
+ spec: ToolSpec;
24
+ call(args: Record<string, unknown>): Promise<string>;
25
+ }
26
+ export interface AgentRender {
27
+ /** First text delta of an assistant segment (print the ◆ prefix etc). */
28
+ onAssistantStart(): void;
29
+ onDelta(s: string): void;
30
+ onToolStart(summary: string): void;
31
+ onToolEnd(summary: string, resultPreview: string, ok: boolean): void;
32
+ }
33
+ export interface AgentDeps {
34
+ brain: Brain;
35
+ wyrm: Wyrm | null;
36
+ portal: PortalTool | null;
37
+ skills: SkillLibrary | null;
38
+ stack: StackTools | null;
39
+ mcp: McpHub | null;
40
+ task: TaskTool | null;
41
+ cwd: string;
42
+ system: string;
43
+ toolCtx: ToolContext;
44
+ messages: BrainMessage[];
45
+ }
46
+ export declare function buildSystemPrompt(opts: {
47
+ cwd: string;
48
+ wyrm: boolean;
49
+ portal: boolean;
50
+ brainId: string;
51
+ skills?: number;
52
+ primed?: string | null;
53
+ }): string;
54
+ /** Build the full tool surface handed to the brain this session. */
55
+ export declare function buildToolSpecs(deps: {
56
+ wyrm: Wyrm | null;
57
+ portal: PortalTool | null;
58
+ skills: SkillLibrary | null;
59
+ stack: StackTools | null;
60
+ mcp: McpHub | null;
61
+ task: TaskTool | null;
62
+ }): ToolSpec[];
63
+ /**
64
+ * Run one user message to completion (through any number of tool steps).
65
+ * Mutates deps.messages so the conversation persists across calls.
66
+ */
67
+ export declare function runAgent(deps: AgentDeps, userText: string, render: AgentRender, signal: AbortSignal): Promise<void>;
68
+ //# sourceMappingURL=loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/agent/loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAY,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,EAAgC,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AAC3E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAIzC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,gBAAgB,IAAI,IAAI,CAAA;IACxB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAAA;CACrE;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IACjB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;IACzB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B,KAAK,EAAE,UAAU,GAAG,IAAI,CAAA;IACxB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAA;IACrB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,WAAW,CAAA;IACpB,QAAQ,EAAE,YAAY,EAAE,CAAA;CACzB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,CA+BzJ;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,GAAG,QAAQ,EAAE,CAUnM;AAoCD;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA4BzH"}