@marcusrbrown/infra 0.13.0 → 0.13.2

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 (108) hide show
  1. package/dist/cli.js +4977 -0
  2. package/package.json +7 -3
  3. package/src/__snapshots__/cli.test.ts.snap +0 -219
  4. package/src/__test__/mcp-ctx-fixture.test.ts +0 -108
  5. package/src/__test__/mcp-ctx-fixture.ts +0 -104
  6. package/src/cli.test.ts +0 -66
  7. package/src/cli.ts +0 -43
  8. package/src/commands/cliproxy/config.test.ts +0 -475
  9. package/src/commands/cliproxy/config.ts +0 -238
  10. package/src/commands/cliproxy/deploy.test.ts +0 -181
  11. package/src/commands/cliproxy/deploy.ts +0 -157
  12. package/src/commands/cliproxy/host.test.ts +0 -73
  13. package/src/commands/cliproxy/host.ts +0 -31
  14. package/src/commands/cliproxy/index.ts +0 -21
  15. package/src/commands/cliproxy/keys.test.ts +0 -326
  16. package/src/commands/cliproxy/keys.ts +0 -201
  17. package/src/commands/cliproxy/login.test.ts +0 -415
  18. package/src/commands/cliproxy/login.ts +0 -131
  19. package/src/commands/cliproxy/models.test.ts +0 -592
  20. package/src/commands/cliproxy/models.ts +0 -237
  21. package/src/commands/cliproxy/open.test.ts +0 -132
  22. package/src/commands/cliproxy/open.ts +0 -78
  23. package/src/commands/cliproxy/setup/gh.test.ts +0 -218
  24. package/src/commands/cliproxy/setup/gh.ts +0 -250
  25. package/src/commands/cliproxy/setup/preview.test.ts +0 -159
  26. package/src/commands/cliproxy/setup/preview.ts +0 -41
  27. package/src/commands/cliproxy/setup/prompts.test.ts +0 -58
  28. package/src/commands/cliproxy/setup/prompts.ts +0 -99
  29. package/src/commands/cliproxy/setup/providers.test.ts +0 -245
  30. package/src/commands/cliproxy/setup/providers.ts +0 -136
  31. package/src/commands/cliproxy/setup/smoke-test.test.ts +0 -821
  32. package/src/commands/cliproxy/setup/smoke-test.ts +0 -223
  33. package/src/commands/cliproxy/setup/templates.test.ts +0 -357
  34. package/src/commands/cliproxy/setup/templates.ts +0 -145
  35. package/src/commands/cliproxy/setup/validation.test.ts +0 -567
  36. package/src/commands/cliproxy/setup/validation.ts +0 -209
  37. package/src/commands/cliproxy/setup/workflow-analyzer.test.ts +0 -363
  38. package/src/commands/cliproxy/setup/workflow-analyzer.ts +0 -136
  39. package/src/commands/cliproxy/setup.test.ts +0 -2366
  40. package/src/commands/cliproxy/setup.ts +0 -809
  41. package/src/commands/cliproxy/shared.test.ts +0 -118
  42. package/src/commands/cliproxy/shared.ts +0 -84
  43. package/src/commands/cliproxy/status.test.ts +0 -1157
  44. package/src/commands/cliproxy/status.ts +0 -597
  45. package/src/commands/dashboard/deploy.test.ts +0 -215
  46. package/src/commands/dashboard/deploy.ts +0 -135
  47. package/src/commands/dashboard/host.test.ts +0 -79
  48. package/src/commands/dashboard/host.ts +0 -33
  49. package/src/commands/dashboard/index.ts +0 -13
  50. package/src/commands/dashboard/logs.test.ts +0 -317
  51. package/src/commands/dashboard/logs.ts +0 -180
  52. package/src/commands/dashboard/status.test.ts +0 -708
  53. package/src/commands/dashboard/status.ts +0 -293
  54. package/src/commands/gateway/backup.test.ts +0 -426
  55. package/src/commands/gateway/backup.ts +0 -205
  56. package/src/commands/gateway/deploy.test.ts +0 -491
  57. package/src/commands/gateway/deploy.ts +0 -173
  58. package/src/commands/gateway/host.test.ts +0 -89
  59. package/src/commands/gateway/host.ts +0 -33
  60. package/src/commands/gateway/index.ts +0 -17
  61. package/src/commands/gateway/logs.test.ts +0 -263
  62. package/src/commands/gateway/logs.ts +0 -160
  63. package/src/commands/gateway/restore.test.ts +0 -650
  64. package/src/commands/gateway/restore.ts +0 -308
  65. package/src/commands/gateway/status.test.ts +0 -755
  66. package/src/commands/gateway/status.ts +0 -255
  67. package/src/commands/keeweb/deploy.test.ts +0 -177
  68. package/src/commands/keeweb/deploy.ts +0 -191
  69. package/src/commands/keeweb/index.ts +0 -11
  70. package/src/commands/keeweb/open.test.ts +0 -54
  71. package/src/commands/keeweb/open.ts +0 -30
  72. package/src/commands/keeweb/status.test.ts +0 -509
  73. package/src/commands/keeweb/status.ts +0 -359
  74. package/src/commands/mcp.test.ts +0 -260
  75. package/src/commands/mcp.ts +0 -58
  76. package/src/commands/status.test.ts +0 -222
  77. package/src/commands/status.ts +0 -161
  78. package/src/commands/umami/deploy.test.ts +0 -202
  79. package/src/commands/umami/deploy.ts +0 -132
  80. package/src/commands/umami/host.test.ts +0 -79
  81. package/src/commands/umami/host.ts +0 -33
  82. package/src/commands/umami/index.ts +0 -13
  83. package/src/commands/umami/logs.test.ts +0 -191
  84. package/src/commands/umami/logs.ts +0 -163
  85. package/src/commands/umami/status.test.ts +0 -633
  86. package/src/commands/umami/status.ts +0 -285
  87. package/src/commands/vpn/client.test.ts +0 -949
  88. package/src/commands/vpn/client.ts +0 -467
  89. package/src/commands/vpn/deploy.test.ts +0 -208
  90. package/src/commands/vpn/deploy.ts +0 -143
  91. package/src/commands/vpn/host.test.ts +0 -89
  92. package/src/commands/vpn/host.ts +0 -36
  93. package/src/commands/vpn/index.ts +0 -15
  94. package/src/commands/vpn/logs.test.ts +0 -234
  95. package/src/commands/vpn/logs.ts +0 -136
  96. package/src/commands/vpn/peers.test.ts +0 -478
  97. package/src/commands/vpn/shared.test.ts +0 -454
  98. package/src/commands/vpn/shared.ts +0 -170
  99. package/src/commands/vpn/status.test.ts +0 -142
  100. package/src/commands/vpn/status.ts +0 -78
  101. package/src/conventions.test.ts +0 -1180
  102. package/src/lib/action-ctx.ts +0 -25
  103. package/src/lib/known-hosts.test.ts +0 -192
  104. package/src/lib/known-hosts.ts +0 -76
  105. package/src/lib/redact.ts +0 -21
  106. package/src/lib/ssh-identity.test.ts +0 -134
  107. package/src/lib/ssh-identity.ts +0 -76
  108. /package/{src/resources/known_hosts → dist/known_hosts-tk724cp0.} +0 -0
@@ -1,285 +0,0 @@
1
- import type {goke} from 'goke'
2
- import type {ActionCtx} from '../../lib/action-ctx'
3
- import type {StatusSummary} from '../status'
4
- import {z} from 'zod'
5
-
6
- import {buildKnownHostsArgs} from '../../lib/known-hosts'
7
- import {redactHost} from '../../lib/redact'
8
- import {buildIdentityArgs} from '../../lib/ssh-identity'
9
- import {validateUmamiHost} from './host'
10
-
11
- declare const process: {
12
- env: Record<string, string | undefined>
13
- exitCode?: number
14
- }
15
-
16
- const COMPOSE_PROJECT_DIR = '/opt/umami'
17
-
18
- // ─── Types ───────────────────────────────────────────────────────────────────
19
-
20
- export interface ComposePsEntry {
21
- Name: string
22
- State: string
23
- Health: string
24
- }
25
-
26
- export type HealthStatus = 'healthy' | 'unhealthy' | 'starting' | 'n-a'
27
-
28
- export interface ServiceRow {
29
- service: string
30
- state: string
31
- health: HealthStatus
32
- }
33
-
34
- export interface UmamiStatusResult {
35
- ok: boolean
36
- services: ServiceRow[]
37
- error?: string
38
- }
39
-
40
- export type SpawnFn = (
41
- cmd: string[],
42
- opts: {env: Record<string, string>; stdout: 'pipe'; stderr: 'pipe'},
43
- ) => {
44
- stdout: ReadableStream<Uint8Array>
45
- stderr: ReadableStream<Uint8Array>
46
- exited: Promise<number>
47
- }
48
-
49
- // ─── Pure helpers ─────────────────────────────────────────────────────────────
50
-
51
- export function parseComposePsOutput(stdoutText: string): ComposePsEntry[] {
52
- const trimmed = stdoutText.trim()
53
- if (trimmed.length === 0) return []
54
-
55
- // Legacy compose may emit a single JSON array; current versions emit NDJSON.
56
- if (trimmed.startsWith('[')) {
57
- const parsed: unknown = JSON.parse(trimmed)
58
- return Array.isArray(parsed) ? (parsed as ComposePsEntry[]) : []
59
- }
60
-
61
- // NDJSON: one JSON object per non-empty line.
62
- return trimmed
63
- .split('\n')
64
- .map(line => line.trim())
65
- .filter(line => line.length > 0)
66
- .map(line => JSON.parse(line) as ComposePsEntry)
67
- }
68
-
69
- function normalizeHealth(raw: string): HealthStatus {
70
- if (raw === 'healthy' || raw === 'unhealthy' || raw === 'starting') {
71
- return raw
72
- }
73
-
74
- return 'n-a'
75
- }
76
-
77
- export function parseComposePs(entries: ComposePsEntry[]): ServiceRow[] {
78
- return entries.map(entry => ({
79
- service: entry.Name,
80
- state: entry.State,
81
- health: normalizeHealth(entry.Health),
82
- }))
83
- }
84
-
85
- export function isAllRunning(rows: ServiceRow[]): boolean {
86
- return rows.every(row => row.state === 'running' && (row.health === 'healthy' || row.health === 'n-a'))
87
- }
88
-
89
- // ─── SSH-backed status fetch ──────────────────────────────────────────────────
90
-
91
- function defaultSpawn(
92
- cmd: string[],
93
- opts: {env: Record<string, string>; stdout: 'pipe'; stderr: 'pipe'},
94
- ): ReturnType<SpawnFn> {
95
- return Bun.spawn(cmd, opts) as ReturnType<SpawnFn>
96
- }
97
-
98
- export async function getUmamiComposeStatus(host: string, spawn: SpawnFn = defaultSpawn): Promise<UmamiStatusResult> {
99
- validateUmamiHost(host)
100
-
101
- const knownHostsArgs = buildKnownHostsArgs()
102
- const {args: identityArgs, cleanup} = buildIdentityArgs(process.env.UMAMI_SSH_KEY)
103
-
104
- const sshCmd = [
105
- 'ssh',
106
- '-o',
107
- 'BatchMode=yes',
108
- '-o',
109
- 'StrictHostKeyChecking=yes',
110
- ...knownHostsArgs,
111
- ...identityArgs,
112
- `root@${host}`,
113
- `docker compose --project-directory ${COMPOSE_PROJECT_DIR} ps --format json`,
114
- ]
115
-
116
- const env: Record<string, string> = {
117
- PATH: process.env.PATH ?? '/usr/bin:/bin',
118
- HOME: process.env.HOME ?? '/tmp',
119
- ...(process.env.SSH_AUTH_SOCK ? {SSH_AUTH_SOCK: process.env.SSH_AUTH_SOCK} : {}),
120
- }
121
-
122
- let stdoutText: string
123
- let stderrText: string
124
- let exitCode: number
125
-
126
- try {
127
- const child = spawn(sshCmd, {env, stdout: 'pipe', stderr: 'pipe'})
128
- ;[stdoutText, stderrText, exitCode] = await Promise.all([
129
- new Response(child.stdout).text(),
130
- new Response(child.stderr).text(),
131
- child.exited,
132
- ])
133
- } finally {
134
- cleanup()
135
- }
136
-
137
- if (exitCode !== 0) {
138
- return {
139
- ok: false,
140
- services: [],
141
- error: `SSH command failed (exit ${exitCode}): ${redactHost(stderrText.trim(), host) || 'unknown error'}`,
142
- }
143
- }
144
-
145
- let entries: ComposePsEntry[]
146
-
147
- try {
148
- entries = parseComposePsOutput(stdoutText)
149
- } catch {
150
- return {
151
- ok: false,
152
- services: [],
153
- error: `Failed to parse docker compose ps output: ${redactHost(stdoutText.slice(0, 200), host)}`,
154
- }
155
- }
156
-
157
- const services = parseComposePs(entries)
158
- const ok = isAllRunning(services)
159
-
160
- return {ok, services}
161
- }
162
-
163
- // ─── Unified status aggregator export ────────────────────────────────────────
164
-
165
- export async function getUmamiStatusSummary(host: string, spawn?: SpawnFn): Promise<StatusSummary> {
166
- let result: UmamiStatusResult
167
-
168
- try {
169
- result = await getUmamiComposeStatus(host, spawn)
170
- } catch (error) {
171
- const errorMsg = error instanceof Error ? error.message : String(error)
172
- return {
173
- app: 'umami',
174
- http: `ERROR: ${errorMsg}`,
175
- lastDeploy: '—',
176
- version: '—',
177
- contentHash: '—',
178
- usageStats: '—',
179
- }
180
- }
181
-
182
- // Three-way split: no services → ERROR, services present but degraded → DEGRADED, all healthy → OK
183
- if (result.services.length === 0) {
184
- const errorMsg = result.error ?? 'No services reported'
185
- return {
186
- app: 'umami',
187
- http: `ERROR: ${errorMsg}`,
188
- lastDeploy: '—',
189
- version: '—',
190
- contentHash: '—',
191
- usageStats: '—',
192
- }
193
- }
194
-
195
- const rows = result.services.map(s => `${s.service}:${s.state}/${s.health}`).join(', ')
196
-
197
- if (!result.ok) {
198
- return {
199
- app: 'umami',
200
- http: `DEGRADED: ${rows}`,
201
- lastDeploy: '—',
202
- version: '—',
203
- contentHash: '—',
204
- usageStats: '—',
205
- }
206
- }
207
-
208
- return {
209
- app: 'umami',
210
- http: `OK: ${rows}`,
211
- lastDeploy: '—',
212
- version: '—',
213
- contentHash: '—',
214
- usageStats: '—',
215
- }
216
- }
217
-
218
- // ─── Action (exported for direct testing) ────────────────────────────────────
219
-
220
- export async function umamiStatusAction(
221
- options: {key?: string | undefined},
222
- ctx: ActionCtx,
223
- spawn?: SpawnFn,
224
- ): Promise<void> {
225
- const hostEnvKey = options.key ?? 'UMAMI_DOMAIN'
226
- const host = process.env[hostEnvKey]
227
-
228
- if (!host) {
229
- ctx.console.error('Umami host not set. Export UMAMI_DOMAIN or pass --key <env-name> pointing to a set variable.')
230
- ctx.process.exit(1)
231
- return
232
- }
233
-
234
- ctx.console.log('Umami status')
235
- ctx.console.log('')
236
-
237
- let result: UmamiStatusResult
238
-
239
- try {
240
- result = await getUmamiComposeStatus(host, spawn)
241
- } catch (error) {
242
- ctx.console.error(`Error: ${error instanceof Error ? error.message : String(error)}`)
243
- ctx.process.exit(1)
244
- return
245
- }
246
-
247
- if (result.services.length === 0) {
248
- ctx.console.error(`Error: No services reported by docker compose ps`)
249
- ctx.process.exit(1)
250
- return
251
- }
252
-
253
- ctx.console.log('Service State Health')
254
- ctx.console.log('─────────────────────────────────────')
255
-
256
- for (const row of result.services) {
257
- const svc = row.service.padEnd(16)
258
- const state = row.state.padEnd(10)
259
- ctx.console.log(`${svc} ${state} ${row.health}`)
260
- }
261
-
262
- ctx.console.log('')
263
-
264
- if (result.ok) {
265
- ctx.console.log('Status: OK')
266
- } else {
267
- ctx.console.log('Status: DEGRADED (one or more services not running)')
268
- ctx.process.exit(1)
269
- }
270
- }
271
-
272
- // ─── Command registration ─────────────────────────────────────────────────────
273
-
274
- export function registerUmamiStatus(cli: ReturnType<typeof goke>): void {
275
- cli
276
- .command('umami status', 'Show operational health of the Umami analytics deployment via docker compose ps.')
277
- .option(
278
- '--key [key]',
279
- z
280
- .string()
281
- .optional()
282
- .describe('Environment variable name holding the SSH host. Falls back to UMAMI_DOMAIN when omitted.'),
283
- )
284
- .action((options, ctx) => umamiStatusAction(options, ctx))
285
- }