@sixb/cli 0.0.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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +275 -0
  3. package/dist/commands/access-token-utils.d.ts +9 -0
  4. package/dist/commands/access-token-utils.d.ts.map +1 -0
  5. package/dist/commands/api.d.ts +13 -0
  6. package/dist/commands/api.d.ts.map +1 -0
  7. package/dist/commands/app.d.ts +9 -0
  8. package/dist/commands/app.d.ts.map +1 -0
  9. package/dist/commands/atlas.d.ts +9 -0
  10. package/dist/commands/atlas.d.ts.map +1 -0
  11. package/dist/commands/auth.d.ts +8 -0
  12. package/dist/commands/auth.d.ts.map +1 -0
  13. package/dist/commands/build.d.ts +6 -0
  14. package/dist/commands/build.d.ts.map +1 -0
  15. package/dist/commands/check.d.ts +5 -0
  16. package/dist/commands/check.d.ts.map +1 -0
  17. package/dist/commands/db-migrate.d.ts +5 -0
  18. package/dist/commands/db-migrate.d.ts.map +1 -0
  19. package/dist/commands/dev.d.ts +12 -0
  20. package/dist/commands/dev.d.ts.map +1 -0
  21. package/dist/commands/init.d.ts +3 -0
  22. package/dist/commands/init.d.ts.map +1 -0
  23. package/dist/commands/lake-check.d.ts +5 -0
  24. package/dist/commands/lake-check.d.ts.map +1 -0
  25. package/dist/commands/lake-cleanup.d.ts +16 -0
  26. package/dist/commands/lake-cleanup.d.ts.map +1 -0
  27. package/dist/commands/orchestrator.d.ts +6 -0
  28. package/dist/commands/orchestrator.d.ts.map +1 -0
  29. package/dist/commands/rules.d.ts +6 -0
  30. package/dist/commands/rules.d.ts.map +1 -0
  31. package/dist/commands/scheduler.d.ts +6 -0
  32. package/dist/commands/scheduler.d.ts.map +1 -0
  33. package/dist/commands/service-account.d.ts +14 -0
  34. package/dist/commands/service-account.d.ts.map +1 -0
  35. package/dist/commands/token.d.ts +14 -0
  36. package/dist/commands/token.d.ts.map +1 -0
  37. package/dist/commands/typegen.d.ts +5 -0
  38. package/dist/commands/typegen.d.ts.map +1 -0
  39. package/dist/commands/worker-group.d.ts +8 -0
  40. package/dist/commands/worker-group.d.ts.map +1 -0
  41. package/dist/commands/worker.d.ts +8 -0
  42. package/dist/commands/worker.d.ts.map +1 -0
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/lib/api-client.d.ts +26 -0
  46. package/dist/lib/api-client.d.ts.map +1 -0
  47. package/dist/lib/browser-topology.d.ts +62 -0
  48. package/dist/lib/browser-topology.d.ts.map +1 -0
  49. package/dist/lib/errors.d.ts +19 -0
  50. package/dist/lib/errors.d.ts.map +1 -0
  51. package/dist/lib/health.d.ts +25 -0
  52. package/dist/lib/health.d.ts.map +1 -0
  53. package/dist/lib/loadSixb.d.ts +49 -0
  54. package/dist/lib/loadSixb.d.ts.map +1 -0
  55. package/dist/lib/production-roles.d.ts +65 -0
  56. package/dist/lib/production-roles.d.ts.map +1 -0
  57. package/dist/lib/production.d.ts +29 -0
  58. package/dist/lib/production.d.ts.map +1 -0
  59. package/dist/lib/public-origin.d.ts +17 -0
  60. package/dist/lib/public-origin.d.ts.map +1 -0
  61. package/dist/lib/runtime.d.ts +76 -0
  62. package/dist/lib/runtime.d.ts.map +1 -0
  63. package/dist/lib/shareable-providers.d.ts +20 -0
  64. package/dist/lib/shareable-providers.d.ts.map +1 -0
  65. package/dist/lib/storage-migration.d.ts +40 -0
  66. package/dist/lib/storage-migration.d.ts.map +1 -0
  67. package/dist/lib/typegen.d.ts +5 -0
  68. package/dist/lib/typegen.d.ts.map +1 -0
  69. package/dist/lib/worker-registry.d.ts +30 -0
  70. package/dist/lib/worker-registry.d.ts.map +1 -0
  71. package/dist/tsconfig.json +5 -0
  72. package/dist/ui/index.d.ts +164 -0
  73. package/dist/ui/index.d.ts.map +1 -0
  74. package/package.json +68 -0
  75. package/src/commands/access-token-utils.ts +63 -0
  76. package/src/commands/api.tsx +111 -0
  77. package/src/commands/app.tsx +91 -0
  78. package/src/commands/atlas.tsx +75 -0
  79. package/src/commands/auth.tsx +96 -0
  80. package/src/commands/build.tsx +90 -0
  81. package/src/commands/check.tsx +58 -0
  82. package/src/commands/db-migrate.tsx +27 -0
  83. package/src/commands/dev.tsx +141 -0
  84. package/src/commands/init.tsx +18 -0
  85. package/src/commands/lake-check.tsx +20 -0
  86. package/src/commands/lake-cleanup.tsx +63 -0
  87. package/src/commands/orchestrator.tsx +87 -0
  88. package/src/commands/rules.tsx +81 -0
  89. package/src/commands/scheduler.tsx +77 -0
  90. package/src/commands/service-account.tsx +304 -0
  91. package/src/commands/token.tsx +143 -0
  92. package/src/commands/typegen.tsx +18 -0
  93. package/src/commands/worker-group.tsx +120 -0
  94. package/src/commands/worker.tsx +96 -0
  95. package/src/index.tsx +390 -0
  96. package/src/lib/api-client.ts +132 -0
  97. package/src/lib/browser-topology.ts +292 -0
  98. package/src/lib/errors.ts +40 -0
  99. package/src/lib/health.ts +138 -0
  100. package/src/lib/loadSixb.ts +175 -0
  101. package/src/lib/production-roles.ts +48 -0
  102. package/src/lib/production.ts +104 -0
  103. package/src/lib/public-origin.ts +46 -0
  104. package/src/lib/runtime.ts +346 -0
  105. package/src/lib/shareable-providers.ts +67 -0
  106. package/src/lib/storage-migration.ts +120 -0
  107. package/src/lib/typegen.ts +12 -0
  108. package/src/lib/worker-registry.ts +191 -0
  109. package/src/ui/index.tsx +953 -0
@@ -0,0 +1,90 @@
1
+ import { mkdir } from "node:fs/promises"
2
+ import { dirname, join, resolve } from "node:path"
3
+ import { createCustomApp } from "@sixb/app"
4
+ import { buildAtlasAssets } from "@sixb/atlas"
5
+ import { generateProjectTypes } from "../lib/typegen"
6
+ import { BuildView, ErrorView, renderStatic } from "../ui"
7
+
8
+ export interface BuildOptions {
9
+ entry?: string
10
+ outdir?: string
11
+ }
12
+
13
+ export async function runBuild(options: BuildOptions = {}) {
14
+ const entry = resolve(options.entry ?? "sixb.config.ts")
15
+ const outdir = resolve(options.outdir ?? ".sixb/dist")
16
+ const projectRoot = dirname(entry)
17
+
18
+ await generateProjectTypes({ entry })
19
+ await mkdir(outdir, { recursive: true })
20
+
21
+ // Build sixb.config.ts
22
+ const result = await Bun.build({
23
+ entrypoints: [entry],
24
+ outdir,
25
+ target: "bun",
26
+ sourcemap: "external",
27
+ minify: false,
28
+ packages: "external",
29
+ external: ["@sixb/*"],
30
+ })
31
+
32
+ if (!result.success) {
33
+ const details = result.logs.map(String)
34
+ await renderStatic(
35
+ <ErrorView title="Build failed" message="Compilation errors" details={details} />
36
+ )
37
+ process.exit(1)
38
+ }
39
+
40
+ const customApp = await createCustomApp({
41
+ rootDir: projectRoot,
42
+ // Keep production build inputs separate from the files watched by `sixb dev`.
43
+ // Sharing `.sixb/generated` lets this command replace the dev app's injected
44
+ // API origin and HTML bundle, causing Bun to hot-reload a same-origin client.
45
+ generatedDir: join(".sixb", "build", "app"),
46
+ })
47
+
48
+ if (await customApp.hasRoutes()) {
49
+ try {
50
+ const appResult = await customApp.build({
51
+ outdir: resolve(outdir, "app"),
52
+ })
53
+
54
+ if (!appResult.success) {
55
+ await renderStatic(
56
+ <ErrorView
57
+ title="App build failed"
58
+ message="Failed to build the app"
59
+ details={appResult.logs ?? []}
60
+ />
61
+ )
62
+ process.exit(1)
63
+ }
64
+ } catch (error) {
65
+ // e.g. the app/globals.css Tailwind compile failed — surface the labeled
66
+ // message instead of an unhandled stack trace.
67
+ const message = error instanceof Error ? error.message : String(error)
68
+ await renderStatic(
69
+ <ErrorView title="App build failed" message="Failed to build the app" details={[message]} />
70
+ )
71
+ process.exit(1)
72
+ }
73
+ }
74
+
75
+ try {
76
+ await buildAtlasAssets({ outdir: resolve(outdir, "atlas") })
77
+ } catch (error) {
78
+ const message = error instanceof Error ? error.message : String(error)
79
+ await renderStatic(
80
+ <ErrorView
81
+ title="Built-in UI build failed"
82
+ message="Failed to build production UI assets"
83
+ details={[message]}
84
+ />
85
+ )
86
+ process.exit(1)
87
+ }
88
+
89
+ await renderStatic(<BuildView entry={entry} outdir={outdir} />)
90
+ }
@@ -0,0 +1,58 @@
1
+ import { resolve } from "node:path"
2
+ import { checkRuntimeHealth } from "../lib/health"
3
+ import { loadSixbFromEntry } from "../lib/loadSixb"
4
+ import { stopSixbProviders } from "../lib/runtime"
5
+ import { generateProjectTypes } from "../lib/typegen"
6
+ import { CheckView, renderStatic } from "../ui"
7
+
8
+ export interface CheckOptions {
9
+ entry?: string
10
+ }
11
+
12
+ export async function runCheck(options: CheckOptions = {}) {
13
+ const entry = resolve(options.entry ?? "sixb.config.ts")
14
+ await generateProjectTypes({ entry })
15
+ const sixb = await loadSixbFromEntry(entry)
16
+
17
+ try {
18
+ const objectTypes = sixb.listObjectTypes()
19
+ const health = await checkRuntimeHealth(sixb)
20
+
21
+ const projectValidation =
22
+ objectTypes.length > 0
23
+ ? { ok: true, message: `${objectTypes.length} object type(s)` }
24
+ : { ok: false, message: "No object types loaded" }
25
+
26
+ await renderStatic(
27
+ <CheckView
28
+ projectId={sixb.id}
29
+ storage={health.storage}
30
+ timeseries={health.timeseries}
31
+ broker={health.broker}
32
+ queues={health.queues}
33
+ projectValidation={projectValidation}
34
+ ontology={{
35
+ enabled: true,
36
+ source: entry,
37
+ errors: objectTypes.length > 0 ? 0 : 1,
38
+ // Ontology warnings, which nothing produces yet. The provider warnings below
39
+ // are a different thing and counting them here read as ontology drift.
40
+ warnings: 0,
41
+ }}
42
+ warnings={health.warnings}
43
+ />
44
+ )
45
+
46
+ // A failing probe exits non-zero so `sixb check` can gate a deploy. `exitCode`, not
47
+ // `exit()`: `process.exit()` terminates immediately and the `finally` below never runs, so
48
+ // the providers this command opened were left unclosed on the one path where that matters.
49
+ const failed = [health.storage, health.timeseries, health.broker, health.queues].some(
50
+ (check) => !check.ok
51
+ )
52
+ if (objectTypes.length === 0 || failed) process.exitCode = 1
53
+ } finally {
54
+ // Tear down runtime providers (broker, queues, storage, connectors) so the
55
+ // process can exit instead of hanging on open connections. Mirrors lake-check.
56
+ await stopSixbProviders(sixb)
57
+ }
58
+ }
@@ -0,0 +1,27 @@
1
+ import { migrateStorage } from "@sixb/core"
2
+ import { loadSixbFromEntry } from "../lib/loadSixb"
3
+ import { resolveRuntimeEntry } from "../lib/production"
4
+ import { stopSixbProviders } from "../lib/runtime"
5
+ import { DbMigrateView, renderStatic } from "../ui"
6
+
7
+ export interface DbMigrateOptions {
8
+ entry?: string
9
+ }
10
+
11
+ export async function runDbMigrate(options: DbMigrateOptions = {}) {
12
+ const entry = await resolveRuntimeEntry({ entry: options.entry })
13
+ const sixb = await loadSixbFromEntry(entry)
14
+
15
+ try {
16
+ const result = await migrateStorage(sixb.storage)
17
+ await renderStatic(
18
+ <DbMigrateView
19
+ projectId={sixb.id}
20
+ status={result.status}
21
+ applied={result.reports.flatMap((report) => report.applied)}
22
+ />
23
+ )
24
+ } finally {
25
+ await stopSixbProviders(sixb)
26
+ }
27
+ }
@@ -0,0 +1,141 @@
1
+ import { dirname, resolve } from "node:path"
2
+ import { type CustomAppDevServer, createCustomApp } from "@sixb/app"
3
+ import { type AtlasAppServer, createAtlasApp } from "@sixb/atlas"
4
+ import { createSixbServer, type SixbServer } from "@sixb/server"
5
+ import { apiDocsUrl, apiEventsUrl, apiUrl, resolveBrowserTopology } from "../lib/browser-topology"
6
+ import { type LoadedSixb, loadSixbFromEntry } from "../lib/loadSixb"
7
+ import { runUntilSignal, startSixbRuntime, stopQuietly } from "../lib/runtime"
8
+ import { generateProjectTypes } from "../lib/typegen"
9
+ import { DevView, LoadingView, renderCliError, renderPersistent } from "../ui"
10
+
11
+ export interface DevOptions {
12
+ entry?: string
13
+ port?: string
14
+ host?: string
15
+ apiPort?: string
16
+ apiHost?: string
17
+ apiPublicOrigin?: string
18
+ atlasPublicOrigin?: string
19
+ appPublicOrigin?: string
20
+ }
21
+
22
+ export async function runDev(options: DevOptions = {}) {
23
+ process.env.NODE_ENV = "development"
24
+
25
+ const entry = resolve(options.entry ?? "sixb.config.ts")
26
+
27
+ const app = renderPersistent(
28
+ <LoadingView title="Starting sixb" subtitle={entry} status="Loading runtime" />
29
+ )
30
+
31
+ let server: SixbServer | null = null
32
+ let atlasServer: AtlasAppServer | null = null
33
+ let customAppServer: CustomAppDevServer | null = null
34
+ let sixb: LoadedSixb | null = null
35
+ let runtime: Awaited<ReturnType<typeof startSixbRuntime>> | null = null
36
+
37
+ try {
38
+ await generateProjectTypes({ entry })
39
+ sixb = await loadSixbFromEntry(entry)
40
+ const projectRoot = dirname(resolve(entry))
41
+
42
+ const customAppProbe = await createCustomApp({ rootDir: projectRoot })
43
+ const hasCustomApp = await customAppProbe.hasRoutes()
44
+ const topology = resolveBrowserTopology({
45
+ role: "dev",
46
+ host: options.host,
47
+ apiHost: options.apiHost,
48
+ port: options.port,
49
+ apiPort: options.apiPort,
50
+ apiPublicOrigin: options.apiPublicOrigin,
51
+ atlasPublicOrigin: options.atlasPublicOrigin,
52
+ appPublicOrigin: options.appPublicOrigin,
53
+ hasCustomApp,
54
+ })
55
+
56
+ runtime = await startSixbRuntime(sixb, {
57
+ cohostWorkers: true,
58
+ agentApiBaseUrl: topology.apiPublicOrigin,
59
+ })
60
+ const authEnabled = sixb.auth.isEnabled()
61
+
62
+ app.rerender(<LoadingView title="Starting sixb" subtitle={entry} status="Starting server" />)
63
+
64
+ server = createSixbServer({
65
+ sixb: sixb as unknown as never,
66
+ port: topology.apiPort,
67
+ host: topology.apiHost,
68
+ quiet: true,
69
+ browser: {
70
+ publicOrigin: topology.apiPublicOrigin,
71
+ allowedOrigins: topology.allowedBrowserOrigins,
72
+ },
73
+ })
74
+ await server.start()
75
+
76
+ const atlas = createAtlasApp({
77
+ apiBaseUrl: topology.apiPublicOrigin,
78
+ audience: "atlas",
79
+ authEnabled,
80
+ })
81
+ atlasServer = await atlas.start({
82
+ host: topology.host,
83
+ port: topology.atlasPort,
84
+ development: true,
85
+ })
86
+
87
+ const customApp = await createCustomApp({
88
+ rootDir: projectRoot,
89
+ apiBaseUrl: topology.apiPublicOrigin,
90
+ audience: "app",
91
+ authEnabled,
92
+ })
93
+
94
+ let appUrl: string | null = null
95
+ if (hasCustomApp) {
96
+ app.rerender(
97
+ <LoadingView title="Starting sixb" subtitle={entry} status="Starting custom app" />
98
+ )
99
+
100
+ customAppServer = await customApp.dev({
101
+ host: topology.host,
102
+ port: topology.appPort,
103
+ })
104
+ appUrl = topology.appPublicOrigin
105
+ }
106
+
107
+ app.rerender(
108
+ <DevView
109
+ name={sixb.id}
110
+ apiUrl={apiUrl(topology)}
111
+ apiDocsUrl={apiDocsUrl(topology)}
112
+ wsUrl={apiEventsUrl(topology)}
113
+ uiUrl={topology.atlasPublicOrigin}
114
+ uiStatus={null}
115
+ appUrl={appUrl}
116
+ mqttUrl={null}
117
+ warnings={runtime.warnings}
118
+ />
119
+ )
120
+
121
+ await Promise.race([
122
+ runUntilSignal(async () => {
123
+ app.unmount()
124
+ console.log("\nShutting down...")
125
+ await stopQuietly(() => customAppServer?.stop() ?? Promise.resolve())
126
+ await stopQuietly(() => atlasServer?.stop() ?? Promise.resolve())
127
+ await stopQuietly(() => server?.stop() ?? Promise.resolve())
128
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
129
+ }),
130
+ runtime.waitForWorkerFailure(),
131
+ ])
132
+ } catch (error) {
133
+ app.unmount()
134
+ await stopQuietly(() => customAppServer?.stop() ?? Promise.resolve())
135
+ await stopQuietly(() => atlasServer?.stop() ?? Promise.resolve())
136
+ await stopQuietly(() => server?.stop() ?? Promise.resolve())
137
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
138
+ await renderCliError(error)
139
+ process.exit(1)
140
+ }
141
+ }
@@ -0,0 +1,18 @@
1
+ import { scaffoldProject } from "create-sixb/scaffold"
2
+ import { InitView, renderStatic } from "../ui"
3
+
4
+ export async function runInit(dir?: string): Promise<void> {
5
+ const result = await scaffoldProject(dir ?? ".", { allowExisting: true })
6
+
7
+ await renderStatic(
8
+ <InitView name={result.name} targetDir={result.targetDir} files={result.files} />
9
+ )
10
+ }
11
+
12
+ export async function runCreate(name: string): Promise<void> {
13
+ const result = await scaffoldProject(name)
14
+
15
+ await renderStatic(
16
+ <InitView name={result.name} targetDir={result.targetDir} files={result.files} />
17
+ )
18
+ }
@@ -0,0 +1,20 @@
1
+ import { loadSixbFromEntry } from "../lib/loadSixb"
2
+ import { resolveRuntimeEntry } from "../lib/production"
3
+ import { checkRuntimeLakeDefinitions, stopSixbProviders } from "../lib/runtime"
4
+ import { LakeCheckView, renderStatic } from "../ui"
5
+
6
+ export interface LakeCheckOptions {
7
+ entry?: string
8
+ }
9
+
10
+ export async function runLakeCheck(options: LakeCheckOptions = {}) {
11
+ const entry = await resolveRuntimeEntry({ entry: options.entry })
12
+ const sixb = await loadSixbFromEntry(entry)
13
+
14
+ try {
15
+ await checkRuntimeLakeDefinitions(sixb)
16
+ await renderStatic(<LakeCheckView projectId={sixb.id} status="ok" />)
17
+ } finally {
18
+ await stopSixbProviders(sixb)
19
+ }
20
+ }
@@ -0,0 +1,63 @@
1
+ import { loadSixbFromEntry } from "../lib/loadSixb"
2
+ import { resolveRuntimeEntry } from "../lib/production"
3
+ import { stopSixbProviders } from "../lib/runtime"
4
+ import { LakeCleanupView, renderStatic } from "../ui"
5
+
6
+ const DEFAULT_RETENTION = "7 days"
7
+
8
+ export interface LakeCleanupOptions {
9
+ entry?: string
10
+ dryRun?: boolean
11
+ expireOlderThan?: string
12
+ deleteOlderThan?: string
13
+ }
14
+
15
+ interface LakeMaintenanceOptions {
16
+ readonly dryRun?: boolean
17
+ readonly expireOlderThan?: string
18
+ readonly deleteOlderThan?: string
19
+ }
20
+
21
+ export interface LakeMaintenanceReport {
22
+ readonly dryRun: boolean
23
+ readonly expireOlderThan: string
24
+ readonly deleteOlderThan: string
25
+ readonly snapshots: number
26
+ readonly oldFiles: number
27
+ readonly orphanedFiles: number
28
+ }
29
+
30
+ interface LakeMaintenanceProvider {
31
+ runMaintenance(options?: LakeMaintenanceOptions): Promise<LakeMaintenanceReport>
32
+ }
33
+
34
+ export async function runLakeCleanup(options: LakeCleanupOptions = {}) {
35
+ const entry = await resolveRuntimeEntry({ entry: options.entry })
36
+ const sixb = await loadSixbFromEntry(entry)
37
+
38
+ try {
39
+ const lakeStorage = sixb.lakeStorage
40
+ if (!isLakeMaintenanceProvider(lakeStorage)) {
41
+ throw new Error("Configured lake storage does not support maintenance cleanup.")
42
+ }
43
+
44
+ const expireOlderThan = options.expireOlderThan ?? DEFAULT_RETENTION
45
+ const deleteOlderThan = options.deleteOlderThan ?? expireOlderThan
46
+ const report = await lakeStorage.runMaintenance({
47
+ dryRun: options.dryRun ?? false,
48
+ expireOlderThan,
49
+ deleteOlderThan,
50
+ })
51
+ await renderStatic(<LakeCleanupView projectId={sixb.id} report={report} />)
52
+ } finally {
53
+ await stopSixbProviders(sixb)
54
+ }
55
+ }
56
+
57
+ function isLakeMaintenanceProvider(value: unknown): value is LakeMaintenanceProvider {
58
+ return (
59
+ typeof value === "object" &&
60
+ value !== null &&
61
+ typeof (value as { runMaintenance?: unknown }).runMaintenance === "function"
62
+ )
63
+ }
@@ -0,0 +1,87 @@
1
+ import type { LoadedSixb } from "../lib/loadSixb"
2
+ import { loadProductionSixb } from "../lib/production"
3
+ import {
4
+ type RunningOrchestratorRuntime,
5
+ runUntilSignal,
6
+ startOrchestratorRuntime,
7
+ stopQuietly,
8
+ stopSixbProviders,
9
+ waitForWorkerFailure,
10
+ } from "../lib/runtime"
11
+ import { migrateStorageForRole } from "../lib/storage-migration"
12
+ import { LoadingView, RoleView, renderCliError, renderPersistent } from "../ui"
13
+
14
+ export interface OrchestratorOptions {
15
+ entry?: string
16
+ noMigrate?: boolean
17
+ }
18
+
19
+ export async function runOrchestrator(options: OrchestratorOptions = {}) {
20
+ process.env.NODE_ENV = "production"
21
+
22
+ const loaded = await loadProductionSixb({ entry: options.entry, role: "orchestrator" })
23
+ const app = renderPersistent(
24
+ <LoadingView
25
+ title="Starting sixb orchestrator"
26
+ subtitle={loaded.entry}
27
+ status="Starting orchestrator"
28
+ />
29
+ )
30
+
31
+ let sixb: LoadedSixb | null = loaded.sixb
32
+ let runtime: RunningOrchestratorRuntime | null = null
33
+
34
+ try {
35
+ const migration = await migrateStorageForRole(sixb, {
36
+ role: "orchestrator",
37
+ noMigrate: options.noMigrate,
38
+ onStart: () =>
39
+ app.rerender(
40
+ <LoadingView
41
+ title="Starting sixb orchestrator"
42
+ subtitle={loaded.entry}
43
+ status="Migrating storage"
44
+ />
45
+ ),
46
+ })
47
+
48
+ runtime = await startOrchestratorRuntime(sixb)
49
+
50
+ const warnings = [...runtime.warnings]
51
+ if (runtime.orchestratorWorker === null) {
52
+ warnings.push("No orchestrator routes are registered; the orchestrator process is idle.")
53
+ }
54
+
55
+ app.rerender(
56
+ <RoleView
57
+ title="Sixb orchestrator started"
58
+ name={sixb.id}
59
+ serviceName="Orchestrator"
60
+ items={[{ label: "Role", value: "event-to-queue dispatcher" }]}
61
+ storage={migration.summary}
62
+ warnings={warnings}
63
+ />
64
+ )
65
+
66
+ await Promise.race([
67
+ runUntilSignal(async () => {
68
+ app.unmount()
69
+ console.log("\nShutting down orchestrator...")
70
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
71
+ if (sixb) {
72
+ await stopSixbProviders(sixb)
73
+ }
74
+ sixb = null
75
+ }),
76
+ waitForWorkerFailure(runtime.orchestratorWorker),
77
+ ])
78
+ } catch (error) {
79
+ app.unmount()
80
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
81
+ if (sixb) {
82
+ await stopSixbProviders(sixb)
83
+ }
84
+ await renderCliError(error)
85
+ process.exit(1)
86
+ }
87
+ }
@@ -0,0 +1,81 @@
1
+ import type { LoadedSixb } from "../lib/loadSixb"
2
+ import { loadProductionSixb } from "../lib/production"
3
+ import {
4
+ type RunningRulesRuntime,
5
+ runUntilSignal,
6
+ startRulesRuntime,
7
+ stopQuietly,
8
+ stopSixbProviders,
9
+ waitForWorkerFailure,
10
+ } from "../lib/runtime"
11
+ import { migrateStorageForRole } from "../lib/storage-migration"
12
+ import { LoadingView, RoleView, renderCliError, renderPersistent } from "../ui"
13
+
14
+ export interface RulesOptions {
15
+ entry?: string
16
+ noMigrate?: boolean
17
+ }
18
+
19
+ export async function runRules(options: RulesOptions = {}) {
20
+ process.env.NODE_ENV = "production"
21
+
22
+ const loaded = await loadProductionSixb({ entry: options.entry, role: "rules" })
23
+ const app = renderPersistent(
24
+ <LoadingView title="Starting sixb rules" subtitle={loaded.entry} status="Starting rules" />
25
+ )
26
+
27
+ let sixb: LoadedSixb | null = loaded.sixb
28
+ let runtime: RunningRulesRuntime | null = null
29
+
30
+ try {
31
+ const migration = await migrateStorageForRole(sixb, {
32
+ role: "rules",
33
+ noMigrate: options.noMigrate,
34
+ onStart: () =>
35
+ app.rerender(
36
+ <LoadingView
37
+ title="Starting sixb rules"
38
+ subtitle={loaded.entry}
39
+ status="Migrating storage"
40
+ />
41
+ ),
42
+ })
43
+
44
+ runtime = await startRulesRuntime(sixb)
45
+
46
+ const warnings =
47
+ runtime.rulesWorker === null ? ["No rules are registered; the rules process is idle."] : []
48
+
49
+ app.rerender(
50
+ <RoleView
51
+ title="Sixb rules started"
52
+ name={sixb.id}
53
+ serviceName="Rules"
54
+ items={[{ label: "Role", value: "rules evaluation" }]}
55
+ storage={migration.summary}
56
+ warnings={warnings}
57
+ />
58
+ )
59
+
60
+ await Promise.race([
61
+ runUntilSignal(async () => {
62
+ app.unmount()
63
+ console.log("\nShutting down rules...")
64
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
65
+ if (sixb) {
66
+ await stopSixbProviders(sixb)
67
+ }
68
+ sixb = null
69
+ }),
70
+ waitForWorkerFailure(runtime.rulesWorker),
71
+ ])
72
+ } catch (error) {
73
+ app.unmount()
74
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
75
+ if (sixb) {
76
+ await stopSixbProviders(sixb)
77
+ }
78
+ await renderCliError(error)
79
+ process.exit(1)
80
+ }
81
+ }
@@ -0,0 +1,77 @@
1
+ import type { LoadedSixb } from "../lib/loadSixb"
2
+ import { loadProductionSixb } from "../lib/production"
3
+ import {
4
+ type RunningSchedulerRuntime,
5
+ runUntilSignal,
6
+ startSchedulerRuntime,
7
+ stopQuietly,
8
+ stopSixbProviders,
9
+ } from "../lib/runtime"
10
+ import { migrateStorageForRole } from "../lib/storage-migration"
11
+ import { LoadingView, RoleView, renderCliError, renderPersistent } from "../ui"
12
+
13
+ export interface SchedulerOptions {
14
+ entry?: string
15
+ noMigrate?: boolean
16
+ }
17
+
18
+ export async function runScheduler(options: SchedulerOptions = {}) {
19
+ process.env.NODE_ENV = "production"
20
+
21
+ const loaded = await loadProductionSixb({ entry: options.entry, role: "scheduler" })
22
+ const app = renderPersistent(
23
+ <LoadingView
24
+ title="Starting sixb scheduler"
25
+ subtitle={loaded.entry}
26
+ status="Starting scheduler"
27
+ />
28
+ )
29
+
30
+ let sixb: LoadedSixb | null = loaded.sixb
31
+ let runtime: RunningSchedulerRuntime | null = null
32
+
33
+ try {
34
+ const migration = await migrateStorageForRole(sixb, {
35
+ role: "scheduler",
36
+ noMigrate: options.noMigrate,
37
+ onStart: () =>
38
+ app.rerender(
39
+ <LoadingView
40
+ title="Starting sixb scheduler"
41
+ subtitle={loaded.entry}
42
+ status="Migrating storage"
43
+ />
44
+ ),
45
+ })
46
+
47
+ runtime = await startSchedulerRuntime(sixb)
48
+
49
+ app.rerender(
50
+ <RoleView
51
+ title="Sixb scheduler started"
52
+ name={sixb.id}
53
+ serviceName="Scheduler"
54
+ items={[{ label: "Role", value: "schedule event producer" }]}
55
+ storage={migration.summary}
56
+ />
57
+ )
58
+
59
+ await runUntilSignal(async () => {
60
+ app.unmount()
61
+ console.log("\nShutting down scheduler...")
62
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
63
+ if (sixb) {
64
+ await stopSixbProviders(sixb)
65
+ }
66
+ sixb = null
67
+ })
68
+ } catch (error) {
69
+ app.unmount()
70
+ await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
71
+ if (sixb) {
72
+ await stopSixbProviders(sixb)
73
+ }
74
+ await renderCliError(error)
75
+ process.exit(1)
76
+ }
77
+ }