@sixb/cli 0.1.16 → 0.1.18
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.
- package/README.md +7 -3
- package/dist/commands/access-token-utils.d.ts +6 -0
- package/dist/commands/access-token-utils.d.ts.map +1 -1
- package/dist/commands/api.d.ts.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/atlas.d.ts.map +1 -1
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/db-prepare.d.ts +4 -0
- package/dist/commands/db-prepare.d.ts.map +1 -0
- package/dist/commands/dev-runner.d.ts.map +1 -1
- package/dist/commands/orchestrator.d.ts.map +1 -1
- package/dist/commands/rules.d.ts.map +1 -1
- package/dist/commands/scheduler.d.ts.map +1 -1
- package/dist/commands/service-account.d.ts.map +1 -1
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +1 -1
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/dev-watch.d.ts +2 -0
- package/dist/lib/dev-watch.d.ts.map +1 -1
- package/dist/lib/profiles.d.ts +2 -1
- package/dist/lib/profiles.d.ts.map +1 -1
- package/dist/lib/role-lifecycle.d.ts +3 -0
- package/dist/lib/role-lifecycle.d.ts.map +1 -0
- package/dist/lib/role-view.d.ts +22 -0
- package/dist/lib/role-view.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts +34 -19
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/storage-migration.d.ts.map +1 -1
- package/dist/ui/index.d.ts +18 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/commands/access-token-utils.ts +13 -0
- package/src/commands/api.tsx +2 -1
- package/src/commands/app.tsx +29 -29
- package/src/commands/atlas.tsx +23 -27
- package/src/commands/db-migrate.tsx +4 -1
- package/src/commands/db-prepare.ts +26 -0
- package/src/commands/dev-runner.tsx +22 -18
- package/src/commands/orchestrator.tsx +1 -2
- package/src/commands/rules.tsx +1 -2
- package/src/commands/scheduler.tsx +1 -2
- package/src/commands/service-account.tsx +4 -1
- package/src/commands/token.tsx +4 -1
- package/src/commands/worker-group.tsx +3 -6
- package/src/commands/worker.tsx +3 -6
- package/src/index.tsx +14 -11
- package/src/lib/command-line.ts +11 -1
- package/src/lib/dev-watch.ts +6 -2
- package/src/lib/github-ci.ts +16 -2
- package/src/lib/profiles.ts +3 -2
- package/src/lib/role-lifecycle.ts +34 -0
- package/src/lib/role-view.ts +50 -0
- package/src/lib/runtime.ts +57 -53
- package/src/lib/storage-migration.ts +12 -1
- package/src/ui/index.tsx +46 -0
package/src/lib/runtime.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { appendFileSync } from "node:fs"
|
|
2
1
|
import { ActionWorker } from "@sixb/action-worker"
|
|
3
2
|
import { AgentWorker } from "@sixb/agent-worker"
|
|
4
3
|
import { migrateStorage } from "@sixb/core"
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
getProjectionDispatchDescriptors,
|
|
9
8
|
ProjectionRunDispatcher,
|
|
10
9
|
} from "@sixb/core/internal/projections"
|
|
10
|
+
import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
|
|
11
11
|
import { SyncRunDispatcher } from "@sixb/core/internal/syncs"
|
|
12
12
|
import type { Worker } from "@sixb/core/internal/workers"
|
|
13
13
|
import { WorkflowRunDispatcher } from "@sixb/core/internal/workflows"
|
|
@@ -23,6 +23,8 @@ import { RulesWorker } from "@sixb/rules-worker"
|
|
|
23
23
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
24
24
|
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
25
25
|
import type { LoadedSixbHost } from "./loadSixb"
|
|
26
|
+
import { configuredOrigin } from "./public-origin"
|
|
27
|
+
import { stopQuietly } from "./role-lifecycle"
|
|
26
28
|
import type { WorkerConcurrency } from "./worker-registry"
|
|
27
29
|
import { agentRuntimeRequired, agentWorkerRequired } from "./worker-registry"
|
|
28
30
|
|
|
@@ -32,11 +34,6 @@ export function waitForWorkerFailure(worker: Worker | null | undefined): Promise
|
|
|
32
34
|
})
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
export async function stopQuietly(stopFn: (() => Promise<void>) | undefined | null): Promise<void> {
|
|
36
|
-
if (!stopFn) return
|
|
37
|
-
await stopFn().catch(() => {})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
37
|
async function closeProvider(provider: { close?(): void | Promise<void> }): Promise<void> {
|
|
41
38
|
await provider.close?.()
|
|
42
39
|
}
|
|
@@ -57,11 +54,21 @@ export interface RunningSixbRuntime {
|
|
|
57
54
|
|
|
58
55
|
export interface StartSixbRuntimeOptions {
|
|
59
56
|
readonly cohostWorkers?: boolean
|
|
57
|
+
/**
|
|
58
|
+
* The API this process serves. Agent turns call it from their sandbox, so a co-hosted agent
|
|
59
|
+
* worker starts only once it listens and stops before it closes.
|
|
60
|
+
*/
|
|
61
|
+
readonly api?: RuntimeApiServer
|
|
60
62
|
readonly agentApiBaseUrl?: string
|
|
61
63
|
readonly agentTurnTimeoutMs?: number
|
|
62
64
|
readonly workerConcurrency?: WorkerConcurrency
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
export interface RuntimeApiServer {
|
|
68
|
+
start(): Promise<void>
|
|
69
|
+
stop(): Promise<void>
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
export interface RunningRulesRuntime {
|
|
66
73
|
readonly rulesWorker: RulesWorker | null
|
|
67
74
|
stop(): Promise<void>
|
|
@@ -77,8 +84,21 @@ export interface RunningOrchestratorRuntime {
|
|
|
77
84
|
stop(): Promise<void>
|
|
78
85
|
}
|
|
79
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Tell a worker process's host where the API is reachable, so the code it runs can hand out URLs
|
|
89
|
+
* a third party will fetch (`blobs.createDownloadUrl()`). The API process needs no call: the
|
|
90
|
+
* server records the origin it serves. Without one, those calls fail and name the variable.
|
|
91
|
+
*/
|
|
92
|
+
export function recordApiPublicOrigin(sixb: LoadedSixbHost, value: string | undefined): void {
|
|
93
|
+
const origin = configuredOrigin(value, "SIXB_API_PUBLIC_ORIGIN", "API public origin")
|
|
94
|
+
if (origin) setApiPublicOrigin(sixb, origin)
|
|
95
|
+
}
|
|
96
|
+
|
|
80
97
|
export async function migrateRuntimeStorage(sixb: LoadedSixbHost): Promise<void> {
|
|
81
|
-
await migrateStorage(sixb.storage
|
|
98
|
+
await migrateStorage(sixb.storage, {
|
|
99
|
+
projectId: sixb.id,
|
|
100
|
+
ontology: sixb.definitions.ontology,
|
|
101
|
+
})
|
|
82
102
|
}
|
|
83
103
|
|
|
84
104
|
export async function checkRuntimeLakeDefinitions(sixb: LoadedSixbHost): Promise<void> {
|
|
@@ -145,11 +165,14 @@ export async function startOrchestratorRuntime(
|
|
|
145
165
|
let orchestratorWorker: OrchestratorWorker | null = null
|
|
146
166
|
|
|
147
167
|
if (routes.size > 0) {
|
|
148
|
-
|
|
168
|
+
const projectionRuns = sixb.storage.projectionRuns
|
|
169
|
+
if (projections.length > 0 && !projectionRuns) {
|
|
149
170
|
throw new Error("[SixbCLI] Projection dispatch requires storage.projectionRuns.")
|
|
150
171
|
}
|
|
151
172
|
const projectionReconciliation =
|
|
152
|
-
projections.length > 0
|
|
173
|
+
projections.length > 0 && projectionRuns
|
|
174
|
+
? { lakeStorage: sixb.lakeStorage, projectionRuns }
|
|
175
|
+
: undefined
|
|
153
176
|
orchestratorWorker = new OrchestratorWorker({
|
|
154
177
|
projectId: sixb.id,
|
|
155
178
|
events: sixb.events,
|
|
@@ -181,25 +204,27 @@ export async function startOrchestratorRuntime(
|
|
|
181
204
|
* Startup order (consumers before producers):
|
|
182
205
|
* 1. RulesWorker (subscribes to ontology events)
|
|
183
206
|
* 2. ActionWorker (subscribes to events)
|
|
184
|
-
* 3.
|
|
185
|
-
* 4.
|
|
186
|
-
* 5.
|
|
187
|
-
* 6.
|
|
188
|
-
* 7.
|
|
189
|
-
* 8.
|
|
190
|
-
* 9.
|
|
207
|
+
* 3. ProjectionWorker (claims from queues)
|
|
208
|
+
* 4. PipelineWorker (claims from queues)
|
|
209
|
+
* 5. WorkflowWorker (claims from queues)
|
|
210
|
+
* 6. SyncWorker (claims from queues)
|
|
211
|
+
* 7. Orchestrator (subscribes to events and enqueues jobs)
|
|
212
|
+
* 8. Scheduler (emits schedule.triggered)
|
|
213
|
+
* 9. API server, when this process serves it
|
|
214
|
+
* 10. AgentWorker (claims from queues; its turns call the API)
|
|
191
215
|
*
|
|
192
216
|
* Shutdown order (producers before consumers):
|
|
193
|
-
* 1.
|
|
194
|
-
* 2.
|
|
195
|
-
* 3.
|
|
196
|
-
* 4.
|
|
197
|
-
* 5.
|
|
198
|
-
* 6.
|
|
199
|
-
* 7.
|
|
200
|
-
* 8.
|
|
201
|
-
* 9.
|
|
202
|
-
* 10.
|
|
217
|
+
* 1. AgentWorker (ends its turns while the API still answers them)
|
|
218
|
+
* 2. API server
|
|
219
|
+
* 3. Scheduler
|
|
220
|
+
* 4. Orchestrator (drains pending dispatches)
|
|
221
|
+
* 5. SyncWorker
|
|
222
|
+
* 6. WorkflowWorker
|
|
223
|
+
* 7. PipelineWorker
|
|
224
|
+
* 8. ProjectionWorker
|
|
225
|
+
* 9. ActionWorker
|
|
226
|
+
* 10. RulesWorker (drains pending evaluations)
|
|
227
|
+
* 11. Runtime providers (connectors, broker)
|
|
203
228
|
*/
|
|
204
229
|
export async function startSixbRuntime(
|
|
205
230
|
sixb: LoadedSixbHost,
|
|
@@ -219,13 +244,14 @@ export async function startSixbRuntime(
|
|
|
219
244
|
const warnings: string[] = []
|
|
220
245
|
|
|
221
246
|
async function stop() {
|
|
247
|
+
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
248
|
+
await stopQuietly(() => options.api?.stop() ?? Promise.resolve())
|
|
222
249
|
await stopQuietly(() => schedulerRuntime?.stop() ?? Promise.resolve())
|
|
223
250
|
await stopQuietly(() => orchestratorRuntime?.stop() ?? Promise.resolve())
|
|
224
251
|
await stopQuietly(() => syncWorker?.stop() ?? Promise.resolve())
|
|
225
252
|
await stopQuietly(() => workflowWorker?.stop() ?? Promise.resolve())
|
|
226
253
|
await stopQuietly(() => pipelineWorker?.stop() ?? Promise.resolve())
|
|
227
254
|
await stopQuietly(() => projectionWorker?.stop() ?? Promise.resolve())
|
|
228
|
-
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
229
255
|
await stopQuietly(() => actionWorker?.stop() ?? Promise.resolve())
|
|
230
256
|
await stopQuietly(() => rulesRuntime?.stop() ?? Promise.resolve())
|
|
231
257
|
await stopSixbProviders(sixb)
|
|
@@ -244,6 +270,7 @@ export async function startSixbRuntime(
|
|
|
244
270
|
await actionWorker.start()
|
|
245
271
|
}
|
|
246
272
|
|
|
273
|
+
// Constructed here so a configuration error stops startup early; started last, below.
|
|
247
274
|
if (agentWorkerRequired(sixb)) {
|
|
248
275
|
agentWorker = new AgentWorker(sixb, {
|
|
249
276
|
apiBaseUrl: agentRuntimeRequired(sixb.definitions)
|
|
@@ -252,7 +279,6 @@ export async function startSixbRuntime(
|
|
|
252
279
|
concurrency: options.workerConcurrency?.agent,
|
|
253
280
|
turnTimeoutMs: options.agentTurnTimeoutMs,
|
|
254
281
|
})
|
|
255
|
-
await agentWorker.start()
|
|
256
282
|
}
|
|
257
283
|
|
|
258
284
|
const projectionCount = sixb.definitions.projections.list().length
|
|
@@ -288,6 +314,9 @@ export async function startSixbRuntime(
|
|
|
288
314
|
|
|
289
315
|
schedulerRuntime = await startSchedulerRuntime(sixb)
|
|
290
316
|
}
|
|
317
|
+
|
|
318
|
+
await options.api?.start()
|
|
319
|
+
await agentWorker?.start()
|
|
291
320
|
} catch (error) {
|
|
292
321
|
await stop()
|
|
293
322
|
throw error
|
|
@@ -339,28 +368,3 @@ function requireAgentApiBaseUrl(value: string | undefined): string {
|
|
|
339
368
|
}
|
|
340
369
|
return trimmed
|
|
341
370
|
}
|
|
342
|
-
|
|
343
|
-
export async function runUntilSignal(onShutdown: () => Promise<void>): Promise<void> {
|
|
344
|
-
// Test-only readiness hook: e2e tests detect that a long-running role finished
|
|
345
|
-
// starting by watching for this marker. It avoids depending on Ink's rendered
|
|
346
|
-
// output, which is suppressed when stdout is not a TTY (e.g. under CI). Unset in
|
|
347
|
-
// production, so this is a no-op there.
|
|
348
|
-
const readyLog = process.env.SIXB_CLI_TEST_READY_LOG
|
|
349
|
-
if (readyLog) {
|
|
350
|
-
appendFileSync(readyLog, `${JSON.stringify({ type: "role:ready" })}\n`, "utf-8")
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
await new Promise<void>((resolvePromise) => {
|
|
354
|
-
let shuttingDown = false
|
|
355
|
-
|
|
356
|
-
const shutdown = async () => {
|
|
357
|
-
if (shuttingDown) return
|
|
358
|
-
shuttingDown = true
|
|
359
|
-
await onShutdown()
|
|
360
|
-
resolvePromise()
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
process.once("SIGINT", shutdown)
|
|
364
|
-
process.once("SIGTERM", shutdown)
|
|
365
|
-
})
|
|
366
|
-
}
|
|
@@ -73,6 +73,14 @@ export async function migrateStorageForRole(
|
|
|
73
73
|
|
|
74
74
|
const applied = result.reports.flatMap((report) => report.applied)
|
|
75
75
|
|
|
76
|
+
if (result.queries?.status === "prepared") {
|
|
77
|
+
return {
|
|
78
|
+
outcome: "migrated",
|
|
79
|
+
applied,
|
|
80
|
+
summary: `${applied.length ? `migrated: ${applied.join(", ")}; ` : ""}query indexes prepared`,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
76
84
|
if (applied.length === 0) {
|
|
77
85
|
return { outcome: "current", applied, summary: "schema up to date" }
|
|
78
86
|
}
|
|
@@ -86,7 +94,10 @@ export async function migrateStorageForRole(
|
|
|
86
94
|
|
|
87
95
|
async function runMigration(sixb: LoadedSixbHost, role: StorageSchemaRole) {
|
|
88
96
|
try {
|
|
89
|
-
return await migrateStorage(sixb.storage
|
|
97
|
+
return await migrateStorage(sixb.storage, {
|
|
98
|
+
projectId: sixb.id,
|
|
99
|
+
ontology: sixb.definitions.ontology,
|
|
100
|
+
})
|
|
90
101
|
} catch (error) {
|
|
91
102
|
throw isBusyDatabaseError(error) ? concurrentMigrationError(error, role) : error
|
|
92
103
|
}
|
package/src/ui/index.tsx
CHANGED
|
@@ -44,6 +44,52 @@ export async function renderCliError(
|
|
|
44
44
|
)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// The entrypoint and the browser roles render through these rather than JSX of their own: a module
|
|
48
|
+
// with JSX loads React as soon as it is evaluated, and `atlas` and `app` load neither React nor
|
|
49
|
+
// Ink outside a terminal.
|
|
50
|
+
|
|
51
|
+
export async function renderVersion(version: string): Promise<void> {
|
|
52
|
+
await renderStatic(<VersionView version={version} />)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Root or command help, after the usage error that led to it when there is one. */
|
|
56
|
+
export async function renderHelp(help: CliHelp, usageError?: string): Promise<void> {
|
|
57
|
+
await renderStatic(
|
|
58
|
+
help.path.length === 0 ? (
|
|
59
|
+
<HelpView errorMessage={usageError} />
|
|
60
|
+
) : (
|
|
61
|
+
<CommandHelpView help={help} errorMessage={usageError} />
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface RoleStartupPanel {
|
|
67
|
+
started(view: {
|
|
68
|
+
readonly title: string
|
|
69
|
+
readonly name: string
|
|
70
|
+
readonly serviceName: string
|
|
71
|
+
readonly items: KeyValueItem[]
|
|
72
|
+
}): void
|
|
73
|
+
unmount(): void
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A long-running role's loading panel, replaced by its started view. */
|
|
77
|
+
export function renderRoleStartup(loading: {
|
|
78
|
+
readonly title: string
|
|
79
|
+
readonly subtitle: string
|
|
80
|
+
readonly status: string
|
|
81
|
+
}): RoleStartupPanel {
|
|
82
|
+
const app = renderPersistent(<LoadingView {...loading} />)
|
|
83
|
+
return {
|
|
84
|
+
started(view) {
|
|
85
|
+
app.rerender(<RoleView {...view} />)
|
|
86
|
+
},
|
|
87
|
+
unmount() {
|
|
88
|
+
app.unmount()
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
47
93
|
function SectionTitle({ children }: { children: React.ReactNode }) {
|
|
48
94
|
return (
|
|
49
95
|
<Text color="cyan" bold>
|