@sixb/cli 0.2.4 → 0.2.6
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 +2 -0
- package/dist/commands/agent.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/db-migrate.d.ts +2 -0
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/dev-runner.d.ts.map +1 -1
- package/dist/commands/run.d.ts +15 -0
- package/dist/commands/run.d.ts.map +1 -0
- 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 +12 -2
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-source.d.ts +2 -0
- package/dist/lib/deploy-source.d.ts.map +1 -1
- package/dist/lib/role-lifecycle.d.ts +8 -1
- package/dist/lib/role-lifecycle.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts +4 -2
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/storage-migration.d.ts +7 -0
- package/dist/lib/storage-migration.d.ts.map +1 -1
- package/dist/lib/worker-concurrency.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +4 -1
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/runner/computer-connection.d.ts.map +1 -1
- package/dist/tui/app.d.ts +2 -0
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/format.d.ts +7 -2
- package/dist/tui/format.d.ts.map +1 -1
- package/dist/tui/moves.d.ts +62 -0
- package/dist/tui/moves.d.ts.map +1 -0
- package/dist/tui/parts.d.ts.map +1 -1
- package/dist/tui/settings.d.ts +2 -0
- package/dist/tui/settings.d.ts.map +1 -1
- package/dist/tui/transcript.d.ts +13 -6
- package/dist/tui/transcript.d.ts.map +1 -1
- package/dist/ui/screens.d.ts +8 -0
- package/dist/ui/screens.d.ts.map +1 -1
- package/package.json +22 -21
- package/src/commands/agent.ts +17 -5
- package/src/commands/api.ts +20 -10
- package/src/commands/app.ts +15 -7
- package/src/commands/db-migrate.ts +25 -1
- package/src/commands/dev-runner.ts +2 -1
- package/src/commands/run.ts +221 -0
- package/src/commands/worker-group.ts +36 -9
- package/src/commands/worker.ts +27 -9
- package/src/index.tsx +15 -1
- package/src/lib/command-line.ts +41 -5
- package/src/lib/deploy-source.ts +5 -0
- package/src/lib/role-lifecycle.ts +48 -8
- package/src/lib/runtime.ts +19 -3
- package/src/lib/storage-migration.ts +33 -1
- package/src/lib/worker-concurrency.ts +1 -0
- package/src/lib/worker-registry.ts +35 -5
- package/src/runner/computer-connection.ts +7 -1
- package/src/tui/app.tsx +191 -43
- package/src/tui/format.ts +132 -7
- package/src/tui/moves.ts +221 -0
- package/src/tui/parts.ts +7 -0
- package/src/tui/settings.ts +5 -0
- package/src/tui/transcript.tsx +54 -15
- package/src/ui/screens.ts +23 -0
package/src/lib/command-line.ts
CHANGED
|
@@ -126,7 +126,12 @@ export const CLI_OPTION_DEFINITIONS = {
|
|
|
126
126
|
},
|
|
127
127
|
yes: {
|
|
128
128
|
syntax: "--yes",
|
|
129
|
-
summary: "
|
|
129
|
+
summary: "Go ahead without asking: allow the folders named, or run on the deployment",
|
|
130
|
+
kind: "boolean",
|
|
131
|
+
},
|
|
132
|
+
deployed: {
|
|
133
|
+
syntax: "--deployed",
|
|
134
|
+
summary: "Run on the deployment sixb.deploy.ts describes",
|
|
130
135
|
kind: "boolean",
|
|
131
136
|
},
|
|
132
137
|
outdir: { syntax: "--outdir <path>", summary: "Build output directory", kind: "string" },
|
|
@@ -181,6 +186,11 @@ export const CLI_OPTION_DEFINITIONS = {
|
|
|
181
186
|
summary: "Recent log lines to print (default: 100)",
|
|
182
187
|
kind: "string",
|
|
183
188
|
},
|
|
189
|
+
check: {
|
|
190
|
+
syntax: "--check",
|
|
191
|
+
summary: "Only report pending migrations, exiting with 3 when there are some",
|
|
192
|
+
kind: "boolean",
|
|
193
|
+
},
|
|
184
194
|
"dry-run": {
|
|
185
195
|
syntax: "--dry-run",
|
|
186
196
|
summary: "Show what would change without changing it",
|
|
@@ -232,6 +242,7 @@ export type LocalCommandId =
|
|
|
232
242
|
| "worker"
|
|
233
243
|
| "worker-group"
|
|
234
244
|
| "check"
|
|
245
|
+
| "run"
|
|
235
246
|
| "typegen"
|
|
236
247
|
| "build"
|
|
237
248
|
| "desktop:build"
|
|
@@ -274,6 +285,8 @@ interface CommandNode {
|
|
|
274
285
|
readonly positional: number
|
|
275
286
|
}[]
|
|
276
287
|
readonly rootHelpLabel?: string
|
|
288
|
+
/** Everything after the first positional is a positional too, passed on untouched. */
|
|
289
|
+
readonly passthrough?: boolean
|
|
277
290
|
}
|
|
278
291
|
|
|
279
292
|
const CONNECTION_OPTIONS = ["api-url", "token", "profile"] as const
|
|
@@ -535,6 +548,14 @@ const commandTree: readonly CommandNode[] = [
|
|
|
535
548
|
rootHelpLabel: "worker-group [types...]",
|
|
536
549
|
}),
|
|
537
550
|
command("check", "Validate project configuration and health", { options: ["entry"] }),
|
|
551
|
+
command("run", "Run a script against the project, here or in production", {
|
|
552
|
+
usage: "sixb run [--deployed] [--yes] [--entry <path>] <script> [args...]",
|
|
553
|
+
options: ["entry", "deployed", "yes"],
|
|
554
|
+
minimumPositionals: 1,
|
|
555
|
+
maximumPositionals: Number.POSITIVE_INFINITY,
|
|
556
|
+
passthrough: true,
|
|
557
|
+
rootHelpLabel: "run <script>",
|
|
558
|
+
}),
|
|
538
559
|
command("typegen", "Generate ontology types for typed queries", { options: ["entry"] }),
|
|
539
560
|
command("build", "Build the runtime and the app for production", {
|
|
540
561
|
options: ["entry", "outdir"],
|
|
@@ -567,7 +588,7 @@ const commandTree: readonly CommandNode[] = [
|
|
|
567
588
|
),
|
|
568
589
|
command("db:migrate", "Run database migrations ahead of a role", {
|
|
569
590
|
path: ["db", "migrate"],
|
|
570
|
-
options: ["entry"],
|
|
591
|
+
options: ["entry", "check"],
|
|
571
592
|
rootHelpLabel: "db migrate",
|
|
572
593
|
}),
|
|
573
594
|
],
|
|
@@ -751,7 +772,7 @@ const ROOT_HELP_GROUP_COMMANDS: readonly {
|
|
|
751
772
|
readonly compact?: boolean
|
|
752
773
|
}[] = [
|
|
753
774
|
{ title: "Agent", names: ["agent", "connect"] },
|
|
754
|
-
{ title: "Develop", names: ["init", "dev", "env", "check", "typegen", "build"] },
|
|
775
|
+
{ title: "Develop", names: ["init", "dev", "env", "check", "run", "typegen", "build"] },
|
|
755
776
|
{ title: "Deploy", names: ["deploy", "desktop"] },
|
|
756
777
|
{
|
|
757
778
|
title: "Run in production",
|
|
@@ -865,6 +886,7 @@ function command(
|
|
|
865
886
|
readonly positional: number
|
|
866
887
|
}[]
|
|
867
888
|
readonly rootHelpLabel?: string
|
|
889
|
+
readonly passthrough?: boolean
|
|
868
890
|
} = {}
|
|
869
891
|
): CommandNode {
|
|
870
892
|
const path = input.path ?? [id]
|
|
@@ -879,6 +901,7 @@ function command(
|
|
|
879
901
|
maximumPositionals: input.maximumPositionals ?? 0,
|
|
880
902
|
requiredInputs: input.requiredInputs,
|
|
881
903
|
rootHelpLabel: input.rootHelpLabel ?? (path.length === 1 ? path[0] : undefined),
|
|
904
|
+
...(input.passthrough ? { passthrough: true } : {}),
|
|
882
905
|
}
|
|
883
906
|
}
|
|
884
907
|
|
|
@@ -923,13 +946,24 @@ function parseLocalCommand(root: CommandNode, args: readonly string[]): ParsedCl
|
|
|
923
946
|
|
|
924
947
|
if (!node.id) throw new Error(`[SixbCLI] Command '${path.join(" ")}' has no handler.`)
|
|
925
948
|
const remaining = args.slice(index)
|
|
926
|
-
if (requestsHelp(remaining)) {
|
|
949
|
+
if (requestsHelp(node.passthrough ? remaining.slice(0, firstPositional(remaining)) : remaining)) {
|
|
927
950
|
return { kind: "help", help: helpFor(node, path) }
|
|
928
951
|
}
|
|
929
952
|
const { options, positionals } = parseOptions(node, path, remaining)
|
|
930
953
|
return { kind: "command", id: node.id, path, positionals, options }
|
|
931
954
|
}
|
|
932
955
|
|
|
956
|
+
/** Where the first positional is, past options and the values they take. */
|
|
957
|
+
function firstPositional(args: readonly string[]): number {
|
|
958
|
+
for (let index = 0; index < args.length; index++) {
|
|
959
|
+
const argument = args[index] ?? ""
|
|
960
|
+
if (argument === "--" || !argument.startsWith("-")) return index
|
|
961
|
+
const definition = CLI_OPTION_DEFINITIONS[argument.slice(2) as CliOptionName]
|
|
962
|
+
if (definition?.kind === "string") index++
|
|
963
|
+
}
|
|
964
|
+
return args.length
|
|
965
|
+
}
|
|
966
|
+
|
|
933
967
|
function requestsHelp(args: readonly string[]): boolean {
|
|
934
968
|
const separator = args.indexOf("--")
|
|
935
969
|
const options = separator < 0 ? args : args.slice(0, separator)
|
|
@@ -950,12 +984,14 @@ function parseOptions(
|
|
|
950
984
|
for (let index = 0; index < args.length; index++) {
|
|
951
985
|
const argument = args[index]
|
|
952
986
|
if (argument === undefined) continue
|
|
953
|
-
|
|
987
|
+
// A script's own `--` is one of its arguments.
|
|
988
|
+
if (argument === "--" && !(node.passthrough && positionalOnly)) {
|
|
954
989
|
positionalOnly = true
|
|
955
990
|
continue
|
|
956
991
|
}
|
|
957
992
|
if (positionalOnly || !argument.startsWith("-")) {
|
|
958
993
|
positionals.push(argument)
|
|
994
|
+
if (node.passthrough) positionalOnly = true
|
|
959
995
|
continue
|
|
960
996
|
}
|
|
961
997
|
if (!argument.startsWith("--")) {
|
package/src/lib/deploy-source.ts
CHANGED
|
@@ -104,6 +104,11 @@ export function repoRootOf(projectDir: string): Promise<string> {
|
|
|
104
104
|
return git(projectDir, ["rev-parse", "--show-toplevel"])
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/** The commit checked out where the project is, or null outside a git repository. */
|
|
108
|
+
export function headCommit(projectDir: string): Promise<string | null> {
|
|
109
|
+
return git(projectDir, ["rev-parse", "HEAD"]).catch(() => null)
|
|
110
|
+
}
|
|
111
|
+
|
|
107
112
|
/** Who deploys, recorded with the release. */
|
|
108
113
|
export async function deployer(projectDir: string): Promise<string> {
|
|
109
114
|
if (process.env.GITHUB_ACTIONS && process.env.GITHUB_ACTOR) {
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { appendFileSync } from "node:fs"
|
|
2
2
|
|
|
3
3
|
// Kept apart from `runtime.ts`, which imports every worker package: `app` serves static assets for
|
|
4
|
-
// as long as it runs and must not hold that module graph to reuse these
|
|
4
|
+
// as long as it runs and must not hold that module graph to reuse these helpers.
|
|
5
|
+
|
|
6
|
+
export type ShutdownSignal = "SIGINT" | "SIGTERM"
|
|
7
|
+
|
|
8
|
+
export interface RunUntilSignalOptions {
|
|
9
|
+
/** Called if `SIGINT` arrives while a `SIGTERM` drain is already in progress. */
|
|
10
|
+
readonly onInterrupt?: () => void
|
|
11
|
+
}
|
|
5
12
|
|
|
6
13
|
export async function stopQuietly(stopFn: (() => Promise<void>) | undefined | null): Promise<void> {
|
|
7
14
|
if (!stopFn) return
|
|
8
15
|
await stopFn().catch(() => {})
|
|
9
16
|
}
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
/** Reads an optional millisecond drain bound from `SIXB_DRAIN_TIMEOUT_MS`. */
|
|
19
|
+
export function resolveDrainTimeoutMs(fallbackMs: number): number {
|
|
20
|
+
const raw = process.env.SIXB_DRAIN_TIMEOUT_MS?.trim()
|
|
21
|
+
if (!raw) return fallbackMs
|
|
22
|
+
const parsed = Number(raw)
|
|
23
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
24
|
+
throw new Error("[SixbCLI] SIXB_DRAIN_TIMEOUT_MS must be a non-negative integer.")
|
|
25
|
+
}
|
|
26
|
+
return parsed
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function runUntilSignal(
|
|
30
|
+
onShutdown: (signal: ShutdownSignal) => Promise<void>,
|
|
31
|
+
options: RunUntilSignalOptions = {}
|
|
32
|
+
): Promise<void> {
|
|
12
33
|
// Test-only readiness hook: e2e tests detect that a long-running role finished
|
|
13
34
|
// starting by watching for this marker, rather than on the wording of what the
|
|
14
35
|
// role prints. Unset in production, so this is a no-op there.
|
|
@@ -20,14 +41,33 @@ export async function runUntilSignal(onShutdown: () => Promise<void>): Promise<v
|
|
|
20
41
|
await new Promise<void>((resolvePromise) => {
|
|
21
42
|
let shuttingDown = false
|
|
22
43
|
|
|
23
|
-
const
|
|
24
|
-
|
|
44
|
+
const handle = (signal: ShutdownSignal) => {
|
|
45
|
+
// The SIGTERM listener stays until the shutdown ends: without one, a repeated SIGTERM takes
|
|
46
|
+
// the default action and kills the role mid-drain. When a deployment stops, systemd and the
|
|
47
|
+
// deploy supervisor each send one.
|
|
48
|
+
if (shuttingDown) {
|
|
49
|
+
if (signal === "SIGINT") {
|
|
50
|
+
process.off("SIGINT", onSigint)
|
|
51
|
+
options.onInterrupt?.()
|
|
52
|
+
}
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
25
56
|
shuttingDown = true
|
|
26
|
-
|
|
27
|
-
|
|
57
|
+
if (signal === "SIGINT") process.off("SIGINT", onSigint)
|
|
58
|
+
|
|
59
|
+
void Promise.resolve()
|
|
60
|
+
.then(() => onShutdown(signal))
|
|
61
|
+
.finally(() => {
|
|
62
|
+
process.off("SIGINT", onSigint)
|
|
63
|
+
process.off("SIGTERM", onSigterm)
|
|
64
|
+
resolvePromise()
|
|
65
|
+
})
|
|
28
66
|
}
|
|
29
67
|
|
|
30
|
-
|
|
31
|
-
|
|
68
|
+
const onSigint = () => handle("SIGINT")
|
|
69
|
+
const onSigterm = () => handle("SIGTERM")
|
|
70
|
+
process.on("SIGINT", onSigint)
|
|
71
|
+
process.on("SIGTERM", onSigterm)
|
|
32
72
|
})
|
|
33
73
|
}
|
package/src/lib/runtime.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from "@sixb/orchestrator"
|
|
23
23
|
import { PipelineWorker } from "@sixb/pipeline-worker"
|
|
24
24
|
import { ProjectionWorker } from "@sixb/projection-worker"
|
|
25
|
+
import { RenderWorker } from "@sixb/render-worker"
|
|
25
26
|
import { RulesWorker } from "@sixb/rules-worker"
|
|
26
27
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
27
28
|
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
@@ -29,7 +30,12 @@ import type { LoadedSixbHost } from "./loadSixb"
|
|
|
29
30
|
import { configuredOrigin } from "./public-origin"
|
|
30
31
|
import { stopQuietly } from "./role-lifecycle"
|
|
31
32
|
import type { WorkerConcurrency } from "./worker-registry"
|
|
32
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
agentRuntimeRequired,
|
|
35
|
+
agentWorkerRequired,
|
|
36
|
+
lakeWorkerRequired,
|
|
37
|
+
renderWorkerRequired,
|
|
38
|
+
} from "./worker-registry"
|
|
33
39
|
|
|
34
40
|
export function waitForWorkerFailure(worker: Worker | null | undefined): Promise<never> {
|
|
35
41
|
return new Promise<never>((_resolve, reject) => {
|
|
@@ -45,6 +51,7 @@ export interface RunningSixbRuntime {
|
|
|
45
51
|
readonly rulesWorker: RulesWorker | null
|
|
46
52
|
readonly syncWorker: SyncWorker | null
|
|
47
53
|
readonly lakeWorker: LakeWorker | null
|
|
54
|
+
readonly renderWorker: RenderWorker | null
|
|
48
55
|
readonly agentWorker: AgentWorker | null
|
|
49
56
|
readonly projectionWorker: ProjectionWorker | null
|
|
50
57
|
readonly pipelineWorker: PipelineWorker | null
|
|
@@ -244,7 +251,7 @@ function hasRecoverableRuns({ definitions }: LoadedSixbHost): boolean {
|
|
|
244
251
|
* 3. PipelineWorker (claims from queues)
|
|
245
252
|
* 4. WorkflowWorker (claims from queues)
|
|
246
253
|
* 5. SyncWorker (claims from queues)
|
|
247
|
-
* 6. LakeWorker (
|
|
254
|
+
* 6. LakeWorker and RenderWorker (claim from queues)
|
|
248
255
|
* 7. Orchestrator (subscribes to events, enqueues jobs, runs cron and the maintenance loop)
|
|
249
256
|
* 8. API server, when this process serves it
|
|
250
257
|
* 9. AgentWorker (claims from queues; its turns call the API)
|
|
@@ -253,7 +260,7 @@ function hasRecoverableRuns({ definitions }: LoadedSixbHost): boolean {
|
|
|
253
260
|
* 1. AgentWorker (ends its turns while the API still answers them)
|
|
254
261
|
* 2. API server
|
|
255
262
|
* 3. Orchestrator (stops cron, drains pending dispatches)
|
|
256
|
-
* 4. LakeWorker
|
|
263
|
+
* 4. RenderWorker and LakeWorker
|
|
257
264
|
* 5. SyncWorker
|
|
258
265
|
* 6. WorkflowWorker
|
|
259
266
|
* 7. PipelineWorker
|
|
@@ -270,6 +277,7 @@ export async function startSixbRuntime(
|
|
|
270
277
|
let rulesWorker: RulesWorker | null = null
|
|
271
278
|
let syncWorker: SyncWorker | null = null
|
|
272
279
|
let lakeWorker: LakeWorker | null = null
|
|
280
|
+
let renderWorker: RenderWorker | null = null
|
|
273
281
|
let agentWorker: AgentWorker | null = null
|
|
274
282
|
let pipelineWorker: PipelineWorker | null = null
|
|
275
283
|
let workflowWorker: WorkflowWorker | null = null
|
|
@@ -281,6 +289,7 @@ export async function startSixbRuntime(
|
|
|
281
289
|
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
282
290
|
await stopQuietly(() => options.api?.stop() ?? Promise.resolve())
|
|
283
291
|
await stopQuietly(() => orchestratorRuntime?.stop() ?? Promise.resolve())
|
|
292
|
+
await stopQuietly(() => renderWorker?.stop() ?? Promise.resolve())
|
|
284
293
|
await stopQuietly(() => lakeWorker?.stop() ?? Promise.resolve())
|
|
285
294
|
await stopQuietly(() => syncWorker?.stop() ?? Promise.resolve())
|
|
286
295
|
await stopQuietly(() => workflowWorker?.stop() ?? Promise.resolve())
|
|
@@ -344,6 +353,11 @@ export async function startSixbRuntime(
|
|
|
344
353
|
await lakeWorker.start()
|
|
345
354
|
}
|
|
346
355
|
|
|
356
|
+
if (renderWorkerRequired(sixb)) {
|
|
357
|
+
renderWorker = new RenderWorker(sixb, { concurrency: options.workerConcurrency?.render })
|
|
358
|
+
await renderWorker.start()
|
|
359
|
+
}
|
|
360
|
+
|
|
347
361
|
orchestratorRuntime = await startOrchestratorRuntime(sixb)
|
|
348
362
|
orchestratorWorker = orchestratorRuntime.orchestratorWorker
|
|
349
363
|
warnings.push(...orchestratorRuntime.warnings)
|
|
@@ -361,6 +375,7 @@ export async function startSixbRuntime(
|
|
|
361
375
|
if (rulesWorker) workers.push(rulesWorker)
|
|
362
376
|
if (syncWorker) workers.push(syncWorker)
|
|
363
377
|
if (lakeWorker) workers.push(lakeWorker)
|
|
378
|
+
if (renderWorker) workers.push(renderWorker)
|
|
364
379
|
if (agentWorker) workers.push(agentWorker)
|
|
365
380
|
if (projectionWorker) workers.push(projectionWorker)
|
|
366
381
|
if (pipelineWorker) workers.push(pipelineWorker)
|
|
@@ -373,6 +388,7 @@ export async function startSixbRuntime(
|
|
|
373
388
|
rulesWorker,
|
|
374
389
|
syncWorker,
|
|
375
390
|
lakeWorker,
|
|
391
|
+
renderWorker,
|
|
376
392
|
agentWorker,
|
|
377
393
|
projectionWorker,
|
|
378
394
|
pipelineWorker,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isMigrationCapableStorage,
|
|
3
|
+
type MigrationStatus,
|
|
4
|
+
migrateStorage,
|
|
5
|
+
type Storage,
|
|
6
|
+
} from "@sixb/core"
|
|
2
7
|
import { SixbCliError } from "./errors"
|
|
3
8
|
import type { LoadedSixbHost } from "./loadSixb"
|
|
4
9
|
import type { StorageSchemaRole } from "./production-roles"
|
|
@@ -92,6 +97,33 @@ export async function migrateStorageForRole(
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
/**
|
|
101
|
+
* The storage adapters `sixb db migrate` would bring up to date, read without touching the
|
|
102
|
+
* schema. A state a migration does not resolve, such as a history this build does not know,
|
|
103
|
+
* throws: migrating would fail too.
|
|
104
|
+
*/
|
|
105
|
+
export async function findPendingMigrations(storage: Storage): Promise<readonly MigrationStatus[]> {
|
|
106
|
+
if (!isMigrationCapableStorage(storage)) return []
|
|
107
|
+
|
|
108
|
+
const statuses = await Promise.all(storage.migrators.map((migrator) => migrator.status()))
|
|
109
|
+
const pending: MigrationStatus[] = []
|
|
110
|
+
|
|
111
|
+
for (const status of statuses) {
|
|
112
|
+
if (status.state === "current") continue
|
|
113
|
+
|
|
114
|
+
if (status.state === "pending" || status.state === "uninitialized") {
|
|
115
|
+
pending.push(status)
|
|
116
|
+
continue
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
throw new SixbCliError(`[SixbCLI] ${status.adapterId} cannot be migrated: ${status.state}.`, {
|
|
120
|
+
remediation: status.reason,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return pending
|
|
125
|
+
}
|
|
126
|
+
|
|
95
127
|
async function runMigration(sixb: LoadedSixbHost, role: StorageSchemaRole) {
|
|
96
128
|
try {
|
|
97
129
|
return await migrateStorage(sixb.storage, {
|
|
@@ -8,6 +8,7 @@ const ENVIRONMENT_VARIABLES = {
|
|
|
8
8
|
projection: "SIXB_PROJECTION_WORKER_CONCURRENCY",
|
|
9
9
|
workflow: "SIXB_WORKFLOW_WORKER_CONCURRENCY",
|
|
10
10
|
lake: "SIXB_LAKE_WORKER_CONCURRENCY",
|
|
11
|
+
render: "SIXB_RENDER_WORKER_CONCURRENCY",
|
|
11
12
|
} as const satisfies Record<WorkerType, string>
|
|
12
13
|
|
|
13
14
|
/** Resolve the scalar concurrency accepted by `sixb worker <type>`. */
|
|
@@ -4,18 +4,30 @@ import type { Worker } from "@sixb/core/internal/workers"
|
|
|
4
4
|
import { LakeWorker } from "@sixb/lake-worker"
|
|
5
5
|
import { PipelineWorker } from "@sixb/pipeline-worker"
|
|
6
6
|
import { ProjectionWorker } from "@sixb/projection-worker"
|
|
7
|
+
import { RenderWorker } from "@sixb/render-worker"
|
|
7
8
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
8
9
|
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
9
10
|
import { SixbCliError } from "./errors"
|
|
10
11
|
import type { LoadedSixbHost } from "./loadSixb"
|
|
11
12
|
import { configuredOrigin } from "./public-origin"
|
|
12
13
|
|
|
13
|
-
export const WORKER_TYPES = [
|
|
14
|
+
export const WORKER_TYPES = [
|
|
15
|
+
"sync",
|
|
16
|
+
"agent",
|
|
17
|
+
"pipeline",
|
|
18
|
+
"projection",
|
|
19
|
+
"workflow",
|
|
20
|
+
"lake",
|
|
21
|
+
"render",
|
|
22
|
+
] as const
|
|
14
23
|
|
|
15
24
|
export type WorkerType = (typeof WORKER_TYPES)[number]
|
|
16
25
|
|
|
17
26
|
export type WorkerConcurrency = Readonly<Partial<Record<WorkerType, number>>>
|
|
18
|
-
export type QueueWorkerProcess = Worker & {
|
|
27
|
+
export type QueueWorkerProcess = Worker & {
|
|
28
|
+
readonly concurrency: number
|
|
29
|
+
drain(timeoutMs?: number): Promise<boolean>
|
|
30
|
+
}
|
|
19
31
|
|
|
20
32
|
export interface WorkerCreationOptions {
|
|
21
33
|
readonly agentApiBaseUrl?: string
|
|
@@ -80,6 +92,10 @@ const workerFactories: Record<WorkerType, WorkerFactory> = {
|
|
|
80
92
|
create: (sixb, options) =>
|
|
81
93
|
new LakeWorker(sixb, { concurrency: options.workerConcurrency?.lake }),
|
|
82
94
|
},
|
|
95
|
+
render: {
|
|
96
|
+
create: (sixb, options) =>
|
|
97
|
+
new RenderWorker(sixb, { concurrency: options.workerConcurrency?.render }),
|
|
98
|
+
},
|
|
83
99
|
}
|
|
84
100
|
|
|
85
101
|
export function createWorkerForType(
|
|
@@ -207,6 +223,10 @@ export function resolveRegisteredWorkerTypes(sixb: LoadedSixbHost): readonly Wor
|
|
|
207
223
|
workerTypes.push("lake")
|
|
208
224
|
}
|
|
209
225
|
|
|
226
|
+
if (renderWorkerRequired(sixb)) {
|
|
227
|
+
workerTypes.push("render")
|
|
228
|
+
}
|
|
229
|
+
|
|
210
230
|
return workerTypes
|
|
211
231
|
}
|
|
212
232
|
|
|
@@ -234,24 +254,34 @@ export function lakeWorkerRequired(sixb: LoadedSixbHost): boolean {
|
|
|
234
254
|
return getLakeRetentionRuntime(sixb).automatic || getDatasetIngestRuntime(sixb).enabled
|
|
235
255
|
}
|
|
236
256
|
|
|
257
|
+
/** Renders run in the project's sandboxes, so a project with none asks for none. */
|
|
258
|
+
export function renderWorkerRequired(sixb: LoadedSixbHost): boolean {
|
|
259
|
+
return sixb.sandboxes !== undefined
|
|
260
|
+
}
|
|
261
|
+
|
|
237
262
|
/** Requests stay queued while no worker claims them, which looks like an idle system. */
|
|
238
263
|
export function omittedWorkerWarnings(
|
|
239
264
|
sixb: LoadedSixbHost,
|
|
240
265
|
workerTypes: readonly string[]
|
|
241
266
|
): readonly string[] {
|
|
242
|
-
|
|
267
|
+
const omitted = (workerType: WorkerType) => !workerTypes.includes(workerType)
|
|
243
268
|
|
|
244
269
|
return [
|
|
245
|
-
...(getLakeRetentionRuntime(sixb).automatic
|
|
270
|
+
...(omitted("lake") && getLakeRetentionRuntime(sixb).automatic
|
|
246
271
|
? [
|
|
247
272
|
"Lake cleanup needs a lake worker and this group has none: run `sixb worker lake`, or the lake keeps growing.",
|
|
248
273
|
]
|
|
249
274
|
: []),
|
|
250
|
-
...(getDatasetIngestRuntime(sixb).enabled
|
|
275
|
+
...(omitted("lake") && getDatasetIngestRuntime(sixb).enabled
|
|
251
276
|
? [
|
|
252
277
|
"Ingested changes need a lake worker and this group has none: run `sixb worker lake`, or they wait and never reach their dataset.",
|
|
253
278
|
]
|
|
254
279
|
: []),
|
|
280
|
+
...(omitted("render") && renderWorkerRequired(sixb)
|
|
281
|
+
? [
|
|
282
|
+
"Documents print to PDF in a render worker and this group has none: run `sixb worker render`, or a PDF someone asks for never prints.",
|
|
283
|
+
]
|
|
284
|
+
: []),
|
|
255
285
|
]
|
|
256
286
|
}
|
|
257
287
|
|
|
@@ -74,6 +74,12 @@ export class ComputerConnection {
|
|
|
74
74
|
this.onEvent({ type: "error", message: errorMessage(error) })
|
|
75
75
|
)
|
|
76
76
|
},
|
|
77
|
+
// A conversation moved to a folder here with a turn waiting runs at once, not at renewal.
|
|
78
|
+
onThreadMoved: (event) => {
|
|
79
|
+
void this.route(event.threadId).catch((error: unknown) =>
|
|
80
|
+
this.onEvent({ type: "error", message: errorMessage(error) })
|
|
81
|
+
)
|
|
82
|
+
},
|
|
77
83
|
})
|
|
78
84
|
}
|
|
79
85
|
|
|
@@ -173,7 +179,7 @@ export class ComputerConnection {
|
|
|
173
179
|
}
|
|
174
180
|
|
|
175
181
|
/** Each folder's runner would read the thread to learn it isn't theirs: read it once. */
|
|
176
|
-
private async route(threadId: string, runId
|
|
182
|
+
private async route(threadId: string, runId?: string): Promise<void> {
|
|
177
183
|
const { data: thread } = await getAgentThread({
|
|
178
184
|
client: this.connection.client,
|
|
179
185
|
path: { threadId },
|