archbyte 0.1.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 (142) hide show
  1. package/README.md +282 -0
  2. package/bin/archbyte.js +213 -0
  3. package/dist/agents/core/component-detector.d.ts +2 -0
  4. package/dist/agents/core/component-detector.js +57 -0
  5. package/dist/agents/core/connection-mapper.d.ts +2 -0
  6. package/dist/agents/core/connection-mapper.js +77 -0
  7. package/dist/agents/core/doc-parser.d.ts +2 -0
  8. package/dist/agents/core/doc-parser.js +64 -0
  9. package/dist/agents/core/env-detector.d.ts +2 -0
  10. package/dist/agents/core/env-detector.js +51 -0
  11. package/dist/agents/core/event-detector.d.ts +2 -0
  12. package/dist/agents/core/event-detector.js +59 -0
  13. package/dist/agents/core/infra-analyzer.d.ts +2 -0
  14. package/dist/agents/core/infra-analyzer.js +72 -0
  15. package/dist/agents/core/structure-scanner.d.ts +2 -0
  16. package/dist/agents/core/structure-scanner.js +55 -0
  17. package/dist/agents/core/validator.d.ts +2 -0
  18. package/dist/agents/core/validator.js +74 -0
  19. package/dist/agents/index.d.ts +24 -0
  20. package/dist/agents/index.js +73 -0
  21. package/dist/agents/llm/index.d.ts +8 -0
  22. package/dist/agents/llm/index.js +185 -0
  23. package/dist/agents/llm/prompt-builder.d.ts +3 -0
  24. package/dist/agents/llm/prompt-builder.js +251 -0
  25. package/dist/agents/llm/response-parser.d.ts +6 -0
  26. package/dist/agents/llm/response-parser.js +174 -0
  27. package/dist/agents/llm/types.d.ts +31 -0
  28. package/dist/agents/llm/types.js +2 -0
  29. package/dist/agents/pipeline/agents/component-identifier.d.ts +3 -0
  30. package/dist/agents/pipeline/agents/component-identifier.js +102 -0
  31. package/dist/agents/pipeline/agents/connection-mapper.d.ts +3 -0
  32. package/dist/agents/pipeline/agents/connection-mapper.js +126 -0
  33. package/dist/agents/pipeline/agents/flow-detector.d.ts +3 -0
  34. package/dist/agents/pipeline/agents/flow-detector.js +101 -0
  35. package/dist/agents/pipeline/agents/service-describer.d.ts +3 -0
  36. package/dist/agents/pipeline/agents/service-describer.js +100 -0
  37. package/dist/agents/pipeline/agents/validator.d.ts +3 -0
  38. package/dist/agents/pipeline/agents/validator.js +102 -0
  39. package/dist/agents/pipeline/index.d.ts +13 -0
  40. package/dist/agents/pipeline/index.js +128 -0
  41. package/dist/agents/pipeline/merger.d.ts +7 -0
  42. package/dist/agents/pipeline/merger.js +212 -0
  43. package/dist/agents/pipeline/response-parser.d.ts +5 -0
  44. package/dist/agents/pipeline/response-parser.js +43 -0
  45. package/dist/agents/pipeline/types.d.ts +92 -0
  46. package/dist/agents/pipeline/types.js +3 -0
  47. package/dist/agents/prompt-data.d.ts +1 -0
  48. package/dist/agents/prompt-data.js +15 -0
  49. package/dist/agents/prompts-encode.d.ts +9 -0
  50. package/dist/agents/prompts-encode.js +26 -0
  51. package/dist/agents/prompts.d.ts +12 -0
  52. package/dist/agents/prompts.js +30 -0
  53. package/dist/agents/providers/anthropic.d.ts +10 -0
  54. package/dist/agents/providers/anthropic.js +117 -0
  55. package/dist/agents/providers/google.d.ts +10 -0
  56. package/dist/agents/providers/google.js +136 -0
  57. package/dist/agents/providers/ollama.d.ts +9 -0
  58. package/dist/agents/providers/ollama.js +162 -0
  59. package/dist/agents/providers/openai.d.ts +9 -0
  60. package/dist/agents/providers/openai.js +142 -0
  61. package/dist/agents/providers/router.d.ts +7 -0
  62. package/dist/agents/providers/router.js +55 -0
  63. package/dist/agents/runtime/orchestrator.d.ts +34 -0
  64. package/dist/agents/runtime/orchestrator.js +193 -0
  65. package/dist/agents/runtime/registry.d.ts +23 -0
  66. package/dist/agents/runtime/registry.js +56 -0
  67. package/dist/agents/runtime/types.d.ts +117 -0
  68. package/dist/agents/runtime/types.js +29 -0
  69. package/dist/agents/static/code-sampler.d.ts +3 -0
  70. package/dist/agents/static/code-sampler.js +153 -0
  71. package/dist/agents/static/component-detector.d.ts +3 -0
  72. package/dist/agents/static/component-detector.js +404 -0
  73. package/dist/agents/static/connection-mapper.d.ts +3 -0
  74. package/dist/agents/static/connection-mapper.js +280 -0
  75. package/dist/agents/static/doc-parser.d.ts +3 -0
  76. package/dist/agents/static/doc-parser.js +358 -0
  77. package/dist/agents/static/env-detector.d.ts +3 -0
  78. package/dist/agents/static/env-detector.js +73 -0
  79. package/dist/agents/static/event-detector.d.ts +3 -0
  80. package/dist/agents/static/event-detector.js +70 -0
  81. package/dist/agents/static/file-tree-collector.d.ts +3 -0
  82. package/dist/agents/static/file-tree-collector.js +51 -0
  83. package/dist/agents/static/index.d.ts +19 -0
  84. package/dist/agents/static/index.js +307 -0
  85. package/dist/agents/static/infra-analyzer.d.ts +3 -0
  86. package/dist/agents/static/infra-analyzer.js +208 -0
  87. package/dist/agents/static/structure-scanner.d.ts +3 -0
  88. package/dist/agents/static/structure-scanner.js +195 -0
  89. package/dist/agents/static/types.d.ts +165 -0
  90. package/dist/agents/static/types.js +2 -0
  91. package/dist/agents/static/utils.d.ts +21 -0
  92. package/dist/agents/static/utils.js +146 -0
  93. package/dist/agents/static/validator.d.ts +2 -0
  94. package/dist/agents/static/validator.js +75 -0
  95. package/dist/agents/tools/claude-code.d.ts +38 -0
  96. package/dist/agents/tools/claude-code.js +129 -0
  97. package/dist/agents/tools/local-fs.d.ts +12 -0
  98. package/dist/agents/tools/local-fs.js +112 -0
  99. package/dist/agents/tools/tool-definitions.d.ts +6 -0
  100. package/dist/agents/tools/tool-definitions.js +66 -0
  101. package/dist/cli/analyze.d.ts +27 -0
  102. package/dist/cli/analyze.js +586 -0
  103. package/dist/cli/auth.d.ts +46 -0
  104. package/dist/cli/auth.js +397 -0
  105. package/dist/cli/config.d.ts +11 -0
  106. package/dist/cli/config.js +177 -0
  107. package/dist/cli/diff.d.ts +10 -0
  108. package/dist/cli/diff.js +144 -0
  109. package/dist/cli/export.d.ts +10 -0
  110. package/dist/cli/export.js +321 -0
  111. package/dist/cli/gate.d.ts +13 -0
  112. package/dist/cli/gate.js +131 -0
  113. package/dist/cli/generate.d.ts +10 -0
  114. package/dist/cli/generate.js +213 -0
  115. package/dist/cli/license-gate.d.ts +27 -0
  116. package/dist/cli/license-gate.js +121 -0
  117. package/dist/cli/patrol.d.ts +15 -0
  118. package/dist/cli/patrol.js +212 -0
  119. package/dist/cli/run.d.ts +11 -0
  120. package/dist/cli/run.js +24 -0
  121. package/dist/cli/serve.d.ts +9 -0
  122. package/dist/cli/serve.js +65 -0
  123. package/dist/cli/setup.d.ts +1 -0
  124. package/dist/cli/setup.js +233 -0
  125. package/dist/cli/shared.d.ts +68 -0
  126. package/dist/cli/shared.js +275 -0
  127. package/dist/cli/stats.d.ts +9 -0
  128. package/dist/cli/stats.js +158 -0
  129. package/dist/cli/ui.d.ts +18 -0
  130. package/dist/cli/ui.js +144 -0
  131. package/dist/cli/validate.d.ts +54 -0
  132. package/dist/cli/validate.js +315 -0
  133. package/dist/cli/workflow.d.ts +10 -0
  134. package/dist/cli/workflow.js +594 -0
  135. package/dist/server/src/generator/index.d.ts +123 -0
  136. package/dist/server/src/generator/index.js +254 -0
  137. package/dist/server/src/index.d.ts +8 -0
  138. package/dist/server/src/index.js +1311 -0
  139. package/package.json +62 -0
  140. package/ui/dist/assets/index-B66Til39.js +70 -0
  141. package/ui/dist/assets/index-BE2OWbzu.css +1 -0
  142. package/ui/dist/index.html +14 -0
package/README.md ADDED
@@ -0,0 +1,282 @@
1
+ # Archbyte
2
+
3
+ AI-powered architecture visualization for your codebase. Analyzes code, generates interactive diagrams, enforces architectural fitness rules, and monitors for drift — all from Claude Code.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Install
9
+ npm install -g archbyte
10
+ # or from source
11
+ git clone https://github.com/diabhey/archbyte.git && cd archbyte && npm install && npm run build && npm link
12
+ ```
13
+
14
+ ### Setup with Claude Code
15
+
16
+ Slash commands are installed globally so they work in any project:
17
+
18
+ ```bash
19
+ mkdir -p ~/.claude/commands
20
+ cp commands/archbyte-*.md ~/.claude/commands/
21
+ ```
22
+
23
+ Run `/archbyte-help` in Claude Code to see all commands. Every command shows its flags and examples when run without arguments (e.g. `/archbyte-export -h`).
24
+
25
+ ## Usage (Claude Code slash commands)
26
+
27
+ | Command | What it does |
28
+ |---------|-------------|
29
+ | `/archbyte-analyze` | Scans your codebase and generates `.archbyte/analysis.json` |
30
+ | `/archbyte-generate` | Converts analysis into `.archbyte/architecture.json` with positioned nodes |
31
+ | `/archbyte-serve` | Opens interactive diagram UI at http://localhost:3847 |
32
+ | `/archbyte-validate` | Runs fitness rules against your architecture |
33
+ | `/archbyte-stats` | Shows architecture health dashboard |
34
+ | `/archbyte-export` | Exports diagram to Mermaid, Markdown, or other formats |
35
+ | `/archbyte-diff` | Compares architecture snapshots to detect drift |
36
+ | `/archbyte-patrol` | Starts continuous architecture health monitoring |
37
+ | `/archbyte-workflow` | Runs composable multi-step architecture pipelines |
38
+ | `/archbyte-init` | Initializes `archbyte.yaml` config for your project |
39
+ | `/archbyte-help` | Shows this command reference |
40
+
41
+ ### Typical workflow
42
+
43
+ ```
44
+ /archbyte-init # one-time: create config
45
+ /archbyte-analyze # AI scans your code
46
+ /archbyte-serve # view the diagram
47
+ ```
48
+
49
+ ## CLI Commands
50
+
51
+ ### `archbyte init`
52
+
53
+ Scaffold an `archbyte.yaml` config and `.archbyte/` directory.
54
+
55
+ ```bash
56
+ archbyte init
57
+ archbyte init --force # overwrite existing
58
+ ```
59
+
60
+ > **Why this matters:** Without a config, every team member picks their own rules and thresholds. `init` gives your project a single source of truth for architecture governance from day one.
61
+ >
62
+ > *Example:* You join a new monorepo and want to enforce "no direct DB calls from the frontend." Run `archbyte init`, edit the generated `archbyte.yaml` to add that custom rule, and commit it — now every contributor shares the same guardrails.
63
+
64
+ ### `archbyte generate`
65
+
66
+ Convert analysis JSON into an architecture diagram.
67
+
68
+ ```bash
69
+ archbyte generate
70
+ archbyte generate --input path/to/analysis.json --output path/to/arch.json
71
+ archbyte generate --verbose
72
+ ```
73
+
74
+ Merges with existing diagram to preserve user-adjusted node positions.
75
+
76
+ > **Why this matters:** Raw analysis JSON is data — a positioned architecture diagram is *understanding*. Generate turns a flat list of components and dependencies into a spatial map you can actually reason about.
77
+ >
78
+ > *Example:* After an AI analysis finds 40 components and 120 dependencies, `archbyte generate` lays them out by layer so you instantly see that your "AuthService" sits in the wrong tier. Re-running after code changes merges new nodes in without losing the positions you manually adjusted last sprint.
79
+
80
+ ### `archbyte serve`
81
+
82
+ Start the HTTP server with the interactive visualization UI.
83
+
84
+ ```bash
85
+ archbyte serve # default port 3847
86
+ archbyte serve --port 8080
87
+ archbyte serve --diagram path/to/architecture.json
88
+ ```
89
+
90
+ Features: real-time SSE updates, drag-and-drop nodes, environment filtering, flow animation, dependency highlighting, export to PNG/SVG.
91
+
92
+ > **Why this matters:** Architecture diagrams on a wiki go stale the moment they're drawn. A live, interactive diagram that updates in real-time means you're always looking at the truth, not a six-month-old Confluence page.
93
+ >
94
+ > *Example:* During an incident review, run `archbyte serve` and drag the failing service to the center. Click it to highlight all upstream dependencies — now the whole team can see which services are affected and trace the blast radius visually instead of grep-ing through YAML manifests.
95
+
96
+ ### `archbyte validate`
97
+
98
+ Run architecture fitness function rules.
99
+
100
+ ```bash
101
+ archbyte validate
102
+ archbyte validate --ci # JSON output, exit code 1 on errors
103
+ archbyte validate --watch # re-validate on file changes
104
+ ```
105
+
106
+ **Built-in rules:**
107
+
108
+ | Rule | Default | Description |
109
+ |------|---------|-------------|
110
+ | `no-layer-bypass` | error | Connections that skip layers (e.g. presentation -> data) |
111
+ | `max-connections` | warn (6) | Nodes exceeding connection threshold |
112
+ | `no-orphans` | warn | Nodes with zero connections |
113
+ | `no-circular-deps` | error | Cycles in the dependency graph |
114
+
115
+ Configure in `archbyte.yaml`:
116
+
117
+ ```yaml
118
+ rules:
119
+ no-layer-bypass: error
120
+ max-connections:
121
+ level: warn
122
+ threshold: 8
123
+ no-orphans: off
124
+ no-circular-deps: error
125
+ custom:
126
+ - name: "no-direct-db-from-frontend"
127
+ from: { layer: "presentation" }
128
+ to: { type: "database" }
129
+ level: error
130
+ ```
131
+
132
+ > **Why this matters:** Code review catches syntax and logic bugs, but architectural violations slip through because no human reviewer holds the entire dependency graph in their head. Validate acts as an automated architect that never misses a rule.
133
+ >
134
+ > *Example:* A junior developer adds a direct import from a React component to a Postgres client library. `archbyte validate --ci` in your GitHub Actions pipeline catches the layer bypass (`presentation -> data`) and fails the build *before* the PR is merged — no manual review needed.
135
+
136
+ ### `archbyte stats`
137
+
138
+ Architecture health dashboard.
139
+
140
+ ```bash
141
+ archbyte stats
142
+ archbyte stats --diagram path/to/architecture.json
143
+ ```
144
+
145
+ Shows: component counts, layer distribution, connection density, hub detection, orphan detection, layer violations.
146
+
147
+ > **Why this matters:** "How healthy is our architecture?" is usually answered with gut feelings. Stats turns that into numbers you can track over time and discuss objectively in sprint retros.
148
+ >
149
+ > *Example:* You run `archbyte stats` and discover your `ApiGateway` has 14 connections — more than double the threshold. That's a hub risk: if it goes down, 14 services are affected. You bring this to the team meeting with hard data instead of a hunch, and the team agrees to split it into domain-specific gateways.
150
+
151
+ ### `archbyte export`
152
+
153
+ Export to various formats.
154
+
155
+ ```bash
156
+ archbyte export # mermaid to stdout
157
+ archbyte export --format plantuml
158
+ archbyte export --format dot # Graphviz
159
+ archbyte export --format markdown
160
+ archbyte export --format json
161
+ archbyte export --output docs/architecture.mmd
162
+ ```
163
+
164
+ > **Why this matters:** Your architecture diagram shouldn't be locked inside one tool. Export lets you embed it in PRs, design docs, ADRs, or any toolchain your team already uses.
165
+ >
166
+ > *Example:* Before each release, you run `archbyte export --format mermaid --output docs/architecture.mmd` and commit it. GitHub renders the Mermaid diagram inline in your repo — anyone browsing the codebase sees an always-current architecture map without installing anything.
167
+
168
+ ### `archbyte diff`
169
+
170
+ Compare architecture snapshots and detect drift.
171
+
172
+ ```bash
173
+ archbyte diff --baseline .archbyte/baseline.json
174
+ archbyte diff --baseline old.json --current new.json
175
+ ```
176
+
177
+ Reports added/removed components, added/removed connections, density change, new/resolved violations. Exit code 1 on new errors.
178
+
179
+ > **Why this matters:** Architecture erosion happens one commit at a time. By the time someone notices, the codebase has drifted far from its intended design. Diff catches drift early by comparing snapshots and surfacing exactly what changed.
180
+ >
181
+ > *Example:* You save a baseline after your v2.0 release with `cp .archbyte/architecture.json .archbyte/baseline.json`. Two months later, run `archbyte diff --baseline .archbyte/baseline.json` and discover 3 new circular dependencies and a removed service boundary. You can now decide whether to accept the drift or fix it — before it compounds further.
182
+
183
+ ### `archbyte patrol`
184
+
185
+ Continuous architecture health monitoring — runs the validation pipeline on a repeating interval, diffs each cycle to detect new and resolved violations, and maintains a persistent health history.
186
+
187
+ Inspired by [Gastown's](https://github.com/steveyegge/gastown) patrol loop pattern.
188
+
189
+ ```bash
190
+ archbyte patrol # default 5m interval
191
+ archbyte patrol --interval 30s # 30 second cycles
192
+ archbyte patrol --interval 1h # hourly
193
+ archbyte patrol --on-violation json # JSON output for piping
194
+ archbyte patrol --history # view patrol history dashboard
195
+ ```
196
+
197
+ **Options:**
198
+
199
+ | Flag | Default | Description |
200
+ |------|---------|-------------|
201
+ | `--interval <duration>` | `5m` | Cycle interval: `30s`, `5m`, `1h` |
202
+ | `--on-violation <action>` | `log` | Action on new violations: `log` or `json` |
203
+ | `--history` | — | Show health sparkline, history table, health rate |
204
+
205
+ The patrol daemon:
206
+ - Reports **new** violations and **resolved** ones each cycle
207
+ - Persists history to `.archbyte/patrols/history.jsonl`
208
+ - `--history` shows a sparkline health chart and stats
209
+
210
+ > **Why this matters:** Validate catches violations at a point in time; Patrol catches them *over time*. Running continuously, it detects the moment a violation appears and tells you when violations get resolved — giving you a living health timeline for your architecture.
211
+ >
212
+ > *Example:* You start `archbyte patrol --interval 5m` in a tmux session during a refactoring sprint. Mid-afternoon, it flags a new circular dependency introduced in the latest commit. You fix it immediately instead of discovering it three weeks later in a failing CI pipeline. At the end of the sprint, `archbyte patrol --history` shows the team a sparkline proving architecture health improved from 72% to 95%.
213
+
214
+ ### `archbyte workflow`
215
+
216
+ Composable multi-step architecture pipelines with dependency tracking and resume-on-failure. Inspired by Gastown's MEOW (Molecular Expression of Work) system.
217
+
218
+ ```bash
219
+ archbyte workflow --list # list available workflows
220
+ archbyte workflow --run full-analysis # run a workflow
221
+ archbyte workflow --show ci-check # show step details
222
+ archbyte workflow --status # show progress bars
223
+ archbyte workflow --create "my-pipeline" # scaffold a custom workflow
224
+ archbyte workflow --reset # clear all state
225
+ ```
226
+
227
+ **Built-in workflows:**
228
+
229
+ | Workflow | Steps | Description |
230
+ |----------|-------|-------------|
231
+ | `full-analysis` | generate -> validate -> stats -> export | Complete pipeline |
232
+ | `ci-check` | validate (CI mode) | Lightweight CI gate |
233
+ | `drift-check` | snapshot -> generate -> diff | Detect drift |
234
+
235
+ **Custom workflows** — YAML files in `.archbyte/workflows/`:
236
+
237
+ ```yaml
238
+ id: my-pipeline
239
+ name: "My Custom Pipeline"
240
+ description: "Custom architecture workflow"
241
+
242
+ steps:
243
+ - id: generate
244
+ name: "Generate Diagram"
245
+ command: "archbyte generate"
246
+ needs: []
247
+
248
+ - id: validate
249
+ name: "Validate"
250
+ command: "archbyte validate --ci"
251
+ needs: [generate]
252
+
253
+ - id: export
254
+ name: "Export"
255
+ command: "archbyte export --format mermaid --output docs/arch.mmd"
256
+ needs: [generate]
257
+ ```
258
+
259
+ Workflows **resume on failure** — completed steps are skipped when you re-run. State persists in `.archbyte/workflows/.state/`.
260
+
261
+ > **Why this matters:** Running `generate`, then `validate`, then `stats`, then `export` manually is tedious and error-prone. Workflows chain them into a single reproducible pipeline — and if step 3 fails, you re-run and it skips the already-completed steps instead of starting from scratch.
262
+ >
263
+ > *Example:* You add a `ci-check` workflow to your GitHub Actions. On every PR, it runs `archbyte workflow --run ci-check`, which validates architecture rules in CI mode and exits non-zero on violations. No manual steps, no forgotten checks. For bigger releases, `archbyte workflow --run full-analysis` runs the entire generate-validate-stats-export pipeline in one command and produces a Mermaid diagram committed to `docs/`.
264
+
265
+ ## Keyboard Shortcuts (UI)
266
+
267
+ | Key | Action |
268
+ |-----|--------|
269
+ | `Ctrl/Cmd + F` | Search |
270
+ | `Ctrl/Cmd + S` | Save positions |
271
+ | `Ctrl/Cmd + E` | Export PNG |
272
+ | `Escape` | Clear search / close panel |
273
+ | `Delete` | Hide selected node |
274
+
275
+ ## Requirements
276
+
277
+ - Node.js >= 18
278
+ - Claude Code (for `/archbyte-analyze`)
279
+
280
+ ## License
281
+
282
+ MIT
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import { handleServe } from '../dist/cli/serve.js';
5
+ import { handleGenerate } from '../dist/cli/generate.js';
6
+ import { handleStats } from '../dist/cli/stats.js';
7
+ import { handleValidate } from '../dist/cli/validate.js';
8
+ import { handleExport } from '../dist/cli/export.js';
9
+ import { handleDiff } from '../dist/cli/diff.js';
10
+ import { handlePatrol } from '../dist/cli/patrol.js';
11
+ import { handleWorkflow } from '../dist/cli/workflow.js';
12
+ import { handleAnalyze } from '../dist/cli/analyze.js';
13
+ import { handleConfig } from '../dist/cli/config.js';
14
+ import { handleLogin, handleLoginWithToken, handleLogout, handleStatus } from '../dist/cli/auth.js';
15
+ import { handleRun } from '../dist/cli/run.js';
16
+ import { handleSetup } from '../dist/cli/setup.js';
17
+ import { requireLicense } from '../dist/cli/license-gate.js';
18
+
19
+ const program = new Command();
20
+
21
+ program
22
+ .name('archbyte')
23
+ .description('ArchByte - See what agents build. As they build it.')
24
+ .version('0.1.0')
25
+ .addHelpText('after', '\nFor more details visit https://archbyte.heartbyte.io');
26
+
27
+ // — Getting started —
28
+
29
+ program
30
+ .command('login')
31
+ .description('Sign in to ArchByte (required for scan/analyze/generate)')
32
+ .option('--token <jwt>', 'Login with a pre-existing JWT token')
33
+ .option('--github', 'Sign in with GitHub')
34
+ .option('--google', 'Sign in with Google')
35
+ .action(async (options) => {
36
+ if (options.token) {
37
+ await handleLoginWithToken(options.token);
38
+ } else {
39
+ const provider = options.google ? 'google' : 'github';
40
+ await handleLogin(provider);
41
+ }
42
+ });
43
+
44
+ program
45
+ .command('logout')
46
+ .description('Sign out of ArchByte')
47
+ .action(async () => {
48
+ await handleLogout();
49
+ });
50
+
51
+ program
52
+ .command('init')
53
+ .description('Configure model provider, API key, and project rules')
54
+ .action(async () => {
55
+ await handleSetup();
56
+ });
57
+
58
+ // — Core workflow —
59
+
60
+ program
61
+ .command('run')
62
+ .description('Analyze, generate, and serve - full pipeline in one shot')
63
+ .option('--static', 'Static-only analysis (no model, free)')
64
+ .option('--skip-llm', 'Alias for --static')
65
+ .option('--provider <name>', 'Model provider: anthropic, openai, google, ollama')
66
+ .option('--api-key <key>', 'Model API key (overrides config)')
67
+ .option('-p, --port <number>', 'UI server port (default: 3847)', parseInt)
68
+ .option('-v, --verbose', 'Show detailed output')
69
+ .option('--dry-run', 'Preview without running')
70
+ .action(async (options) => {
71
+ await requireLicense('analyze');
72
+ await handleRun(options);
73
+ });
74
+
75
+ program
76
+ .command('analyze')
77
+ .description('Run AI-powered architecture analysis (BYOK - uses your model API key)')
78
+ .option('-o, --output <path>', 'Output analysis path (default: .archbyte/analysis.json)')
79
+ .option('-v, --verbose', 'Show detailed output')
80
+ .option('--provider <name>', 'Model provider: anthropic, openai, google, ollama')
81
+ .option('--api-key <key>', 'Model API key (overrides config)')
82
+ .option('--premium-only', 'Run only premium agents (requires existing analysis)')
83
+ .option('--static', 'Static-only analysis (no model, free)')
84
+ .option('--skip-llm', 'Alias for --static')
85
+ .option('--dry-run', 'Preview without running')
86
+ .action(async (options) => {
87
+ await requireLicense('analyze');
88
+ await handleAnalyze(options);
89
+ });
90
+
91
+ program
92
+ .command('generate')
93
+ .description('Generate diagram from analysis JSON')
94
+ .option('-i, --input <path>', 'Input analysis JSON (default: .archbyte/analysis.json)')
95
+ .option('-o, --output <path>', 'Output diagram (default: .archbyte/architecture.json)')
96
+ .option('-v, --verbose', 'Show detailed output')
97
+ .action(async (options) => {
98
+ await requireLicense('generate');
99
+ await handleGenerate(options);
100
+ });
101
+
102
+ program
103
+ .command('serve')
104
+ .description('Start the visualization UI server')
105
+ .option('-p, --port <number>', 'Server port (default: 3847)', parseInt)
106
+ .option('-d, --diagram <path>', 'Path to architecture JSON (default: .archbyte/architecture.json)')
107
+ .action(async (options) => {
108
+ await handleServe(options);
109
+ });
110
+
111
+ // — Inspect & export —
112
+
113
+ program
114
+ .command('stats')
115
+ .description('Show architecture health dashboard')
116
+ .option('-d, --diagram <path>', 'Path to architecture JSON (default: .archbyte/architecture.json)')
117
+ .option('-c, --config <path>', 'Path to archbyte.yaml config')
118
+ .action(async (options) => {
119
+ await handleStats(options);
120
+ });
121
+
122
+ program
123
+ .command('validate')
124
+ .description('Run architecture fitness function rules')
125
+ .option('-d, --diagram <path>', 'Path to architecture JSON (default: .archbyte/architecture.json)')
126
+ .option('-c, --config <path>', 'Path to archbyte.yaml config')
127
+ .option('--ci', 'Machine-readable JSON output for CI pipelines')
128
+ .option('-w, --watch', 'Watch for changes and re-validate')
129
+ .action(async (options) => {
130
+ await requireLicense('analyze');
131
+ await handleValidate(options);
132
+ });
133
+
134
+ program
135
+ .command('diff')
136
+ .description('Compare architecture snapshots and detect drift')
137
+ .requiredOption('-b, --baseline <path>', 'Path to baseline architecture JSON')
138
+ .option('-c, --current <path>', 'Path to current architecture JSON (default: .archbyte/architecture.json)')
139
+ .option('--config <path>', 'Path to archbyte.yaml config')
140
+ .action(async (options) => {
141
+ await handleDiff(options);
142
+ });
143
+
144
+ program
145
+ .command('export')
146
+ .description('Export architecture to various formats')
147
+ .option('-d, --diagram <path>', 'Path to architecture JSON (default: .archbyte/architecture.json)')
148
+ .option('-f, --format <format>', 'Output format: mermaid, markdown, json, plantuml, dot (default: mermaid)')
149
+ .option('-o, --output <path>', 'Write to file instead of stdout')
150
+ .action(async (options) => {
151
+ await handleExport(options);
152
+ });
153
+
154
+ // — Advanced (Pro) —
155
+
156
+ program
157
+ .command('patrol')
158
+ .description('Run continuous architecture health monitoring (Gastown-inspired patrol loop)')
159
+ .option('-d, --diagram <path>', 'Path to architecture JSON (default: .archbyte/architecture.json)')
160
+ .option('-c, --config <path>', 'Path to archbyte.yaml config')
161
+ .option('-i, --interval <duration>', 'Patrol interval: 30s, 5m, 1h (default: 5m)')
162
+ .option('--on-violation <action>', 'Action on new violations: log, json (default: log)')
163
+ .option('--history', 'Show patrol history dashboard')
164
+ .action(async (options) => {
165
+ await requireLicense('analyze');
166
+ await handlePatrol(options);
167
+ });
168
+
169
+ program
170
+ .command('workflow')
171
+ .description('Run composable architecture workflows (MEOW-inspired pipeline system)')
172
+ .option('-r, --run <id>', 'Run a workflow by ID')
173
+ .option('-l, --list', 'List available workflows')
174
+ .option('-s, --show <id>', 'Show workflow details and step status')
175
+ .option('--status', 'Show status of active workflows')
176
+ .option('--reset', 'Reset all workflow state')
177
+ .option('--create <name>', 'Create a new custom workflow file')
178
+ .action(async (options) => {
179
+ await requireLicense('analyze');
180
+ await handleWorkflow(options);
181
+ });
182
+
183
+ // — Account —
184
+
185
+ program
186
+ .command('status')
187
+ .description('Show account status, tier, and usage')
188
+ .action(async () => {
189
+ await handleStatus();
190
+ });
191
+
192
+ program
193
+ .command('config')
194
+ .description('Manage ArchByte configuration (provider, API key)')
195
+ .argument('[action]', 'show, set, get, or path')
196
+ .argument('[key]', 'config key (provider, api-key, ollama-url)')
197
+ .argument('[value]', 'config value')
198
+ .action(async (action, key, value) => {
199
+ await handleConfig({ args: [action, key, value].filter(Boolean) });
200
+ });
201
+
202
+ // Default: show help
203
+ program
204
+ .action(() => {
205
+ program.help();
206
+ });
207
+
208
+ // Unknown commands: show help
209
+ program.on('command:*', () => {
210
+ program.help();
211
+ });
212
+
213
+ program.parse();
@@ -0,0 +1,2 @@
1
+ import type { ArchByteAgent } from "../runtime/types.js";
2
+ export declare const componentDetector: ArchByteAgent;
@@ -0,0 +1,57 @@
1
+ import { executeToolLoop } from "../runtime/orchestrator.js";
2
+ export const componentDetector = {
3
+ id: "component-detector",
4
+ name: "Component Detector",
5
+ description: "Detects architectural components, services, and DDD bounded contexts.",
6
+ tier: "free",
7
+ phase: "parallel",
8
+ modelTier: "standard",
9
+ requiredTools: ["glob", "read_file", "grep", "list_dir"],
10
+ systemPrompt: `You are an architectural component detection agent. Your job is to identify the major components, services, and modules in a software project.
11
+
12
+ Analyze the project and return a JSON object with this structure:
13
+ {
14
+ "components": [
15
+ {
16
+ "name": "string",
17
+ "type": "service | library | api | frontend | worker | database | gateway | queue | cache",
18
+ "layer": "presentation | application | data | external | deployment",
19
+ "path": "relative path to component root",
20
+ "description": "what this component does",
21
+ "technologies": ["list of key technologies"],
22
+ "boundedContext": "string or null (DDD bounded context name)"
23
+ }
24
+ ]
25
+ }
26
+
27
+ Instructions:
28
+ 1. Start by listing the root directory and key subdirectories
29
+ 2. Look for services, packages, apps, or modules
30
+ 3. Read key files (index.ts, main.py, app.go, etc.) to understand purpose
31
+ 4. Assign each component to an architectural layer:
32
+ - presentation: UI, frontend, CLI, API gateway
33
+ - application: business logic, services, controllers
34
+ - data: databases, repositories, ORMs, data access
35
+ - external: third-party integrations, external APIs
36
+ - deployment: Docker, K8s, CI/CD, infrastructure
37
+ 5. Identify DDD bounded contexts where applicable
38
+ 6. Return ONLY the JSON object, no other text`,
39
+ async run(context) {
40
+ const start = Date.now();
41
+ const output = await executeToolLoop(context, this.systemPrompt, "Detect all architectural components in this project. Start by exploring the directory structure, then read key files to understand each component's purpose.");
42
+ let data;
43
+ try {
44
+ const jsonMatch = output.match(/\{[\s\S]*\}/);
45
+ data = jsonMatch ? JSON.parse(jsonMatch[0]) : { raw: output };
46
+ }
47
+ catch {
48
+ data = { raw: output };
49
+ }
50
+ return {
51
+ agentId: this.id,
52
+ data,
53
+ confidence: data && typeof data === "object" && "components" in data ? 0.85 : 0.4,
54
+ duration: Date.now() - start,
55
+ };
56
+ },
57
+ };
@@ -0,0 +1,2 @@
1
+ import type { ArchByteAgent } from "../runtime/types.js";
2
+ export declare const connectionMapper: ArchByteAgent;
@@ -0,0 +1,77 @@
1
+ import { executeToolLoop } from "../runtime/orchestrator.js";
2
+ export const connectionMapper = {
3
+ id: "connection-mapper",
4
+ name: "Connection Mapper",
5
+ description: "Maps connections between components: HTTP calls, DB access, message flows, imports.",
6
+ tier: "free",
7
+ phase: "sequential",
8
+ modelTier: "standard",
9
+ requiredTools: ["glob", "read_file", "grep"],
10
+ systemPrompt: `You are an architectural connection mapping agent. Your job is to identify all connections and dependencies between the components discovered in the previous analysis phase.
11
+
12
+ You will receive prior results from other agents, including the component list. Use this to map connections.
13
+
14
+ Return a JSON object with this structure:
15
+ {
16
+ "connections": [
17
+ {
18
+ "source": "component name (from)",
19
+ "target": "component name (to)",
20
+ "type": "http | grpc | graphql | database | queue | import | file | event | websocket",
21
+ "label": "short description of the connection",
22
+ "style": "solid | dashed",
23
+ "bidirectional": false,
24
+ "evidence": "file:line where this connection was found"
25
+ }
26
+ ],
27
+ "flows": [
28
+ {
29
+ "name": "User Login Flow",
30
+ "steps": ["component1 → component2", "component2 → component3"]
31
+ }
32
+ ]
33
+ }
34
+
35
+ Instructions:
36
+ 1. Review the component list from prior results
37
+ 2. For each component, search for imports, HTTP calls, database connections, and message publishing
38
+ 3. Look for patterns: fetch/axios calls, DB queries, queue.publish, event.emit, import statements
39
+ 4. Map connections between identified components
40
+ 5. Identify common user flows (login, checkout, data pipeline, etc.)
41
+ 6. Use "dashed" style for event-driven/async connections, "solid" for synchronous
42
+ 7. Return ONLY the JSON object, no other text`,
43
+ async run(context) {
44
+ const start = Date.now();
45
+ // Build context from prior results
46
+ let priorContext = "";
47
+ if (context.priorResults) {
48
+ const components = context.priorResults["component-detector"]?.data;
49
+ if (components) {
50
+ priorContext += `\n\nPrior analysis - Components found:\n${JSON.stringify(components, null, 2)}`;
51
+ }
52
+ const structure = context.priorResults["structure-scanner"]?.data;
53
+ if (structure) {
54
+ priorContext += `\n\nPrior analysis - Project structure:\n${JSON.stringify(structure, null, 2)}`;
55
+ }
56
+ const infra = context.priorResults["infra-analyzer"]?.data;
57
+ if (infra) {
58
+ priorContext += `\n\nPrior analysis - Infrastructure:\n${JSON.stringify(infra, null, 2)}`;
59
+ }
60
+ }
61
+ const output = await executeToolLoop(context, this.systemPrompt, `Map all connections between components in this project. Search for HTTP calls, database connections, imports, message queues, and events.${priorContext}`);
62
+ let data;
63
+ try {
64
+ const jsonMatch = output.match(/\{[\s\S]*\}/);
65
+ data = jsonMatch ? JSON.parse(jsonMatch[0]) : { raw: output };
66
+ }
67
+ catch {
68
+ data = { raw: output };
69
+ }
70
+ return {
71
+ agentId: this.id,
72
+ data,
73
+ confidence: data && typeof data === "object" && "connections" in data ? 0.8 : 0.4,
74
+ duration: Date.now() - start,
75
+ };
76
+ },
77
+ };
@@ -0,0 +1,2 @@
1
+ import type { ArchByteAgent } from "../runtime/types.js";
2
+ export declare const docParser: ArchByteAgent;