@sixb/cli 0.2.3 → 0.2.5

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.
@@ -0,0 +1,221 @@
1
+ import { readFile, stat } from "node:fs/promises"
2
+ import { isAbsolute, relative, resolve, sep } from "node:path"
3
+ import { createInterface } from "node:readline/promises"
4
+ import { pathToFileURL } from "node:url"
5
+ import { checkStorageSchema } from "@sixb/core"
6
+ import { listProjectModules } from "@sixb/core/internal/bootstrap"
7
+ import { bindScript } from "@sixb/core/internal/runtime"
8
+ import { loadDeployConfig } from "../lib/deploy-config"
9
+ import { headCommit } from "../lib/deploy-source"
10
+ import { SixbCliError } from "../lib/errors"
11
+ import { loadSixbFromEntry } from "../lib/loadSixb"
12
+ import { stopSixbProviders } from "../lib/runtime"
13
+ import { withTask } from "../ui"
14
+ import { glyph, tone } from "../ui/theme"
15
+
16
+ export interface RunScriptOptions {
17
+ readonly script: string
18
+ /** Everything after the script's path, passed to it untouched. */
19
+ readonly args: readonly string[]
20
+ readonly entry?: string
21
+ readonly deployed?: boolean
22
+ readonly yes?: boolean
23
+ readonly cwd?: string
24
+ }
25
+
26
+ /**
27
+ * `sixb run`: calls a script's default export with the project's SDK, here or, with `deployed`, on
28
+ * the deployment. Resolves with the exit code the command should end with.
29
+ */
30
+ export async function runScriptCommand(options: RunScriptOptions): Promise<number> {
31
+ const cwd = options.cwd ?? process.cwd()
32
+ if (options.deployed && options.entry) {
33
+ throw new SixbCliError("[SixbRun] --entry applies to a run here, not to a deployed one.", {
34
+ remediation: "The deployment runs with the configuration it was deployed with.",
35
+ })
36
+ }
37
+ const script = await projectScript(cwd, options.script)
38
+ return options.deployed ? runOnDeployment(cwd, script, options) : runHere(cwd, script, options)
39
+ }
40
+
41
+ interface ProjectScript {
42
+ readonly file: string
43
+ /** Relative to the project, with forward slashes: what the execution records. */
44
+ readonly path: string
45
+ }
46
+
47
+ async function projectScript(cwd: string, script: string): Promise<ProjectScript> {
48
+ const file = resolve(cwd, script)
49
+ const entry = await stat(file).catch(() => null)
50
+ if (!entry?.isFile()) throw new SixbCliError(`[SixbRun] No script at ${script}.`)
51
+
52
+ const path = relative(cwd, file)
53
+ if (path.startsWith("..") || isAbsolute(path)) {
54
+ throw new SixbCliError(`[SixbRun] ${script} is outside the project.`, {
55
+ remediation:
56
+ "Move it into the project, such as into scripts/, and run sixb run from the project's directory.",
57
+ })
58
+ }
59
+ const projectPath = path.split(sep).join("/")
60
+ // Sixb imports every module in these folders as a definition, and a script is not one.
61
+ const modules = await listProjectModules(cwd)
62
+ if (modules.some((module) => module.path.split(sep).join("/") === projectPath)) {
63
+ throw new SixbCliError(`[SixbRun] ${projectPath} is in a folder Sixb loads definitions from.`, {
64
+ remediation: "Move it outside the definition folders, such as into scripts/.",
65
+ })
66
+ }
67
+ return { file, path: projectPath }
68
+ }
69
+
70
+ async function runHere(
71
+ cwd: string,
72
+ script: ProjectScript,
73
+ options: RunScriptOptions
74
+ ): Promise<number> {
75
+ // The source entry, even where a build exists: the script imports the project's source modules,
76
+ // and loading the same files keeps one copy of each.
77
+ const entry = resolve(cwd, options.entry ?? "sixb.config.ts")
78
+ if (!(await Bun.file(entry).exists())) {
79
+ throw new SixbCliError(`[SixbRun] No ${relative(cwd, entry)} here.`, {
80
+ remediation: "Run sixb run from the project's directory, or pass --entry.",
81
+ })
82
+ }
83
+
84
+ const host = await loadSixbFromEntry(entry)
85
+ const stop = interruptOnSignals()
86
+ try {
87
+ // Before anything can fail: closing the host must not publish the running instance's events.
88
+ const bound = bindScript(host, script.path)
89
+
90
+ // Awaited here, as `sixb check` does: `checkReadiness()` serves a probe that polls, so its first
91
+ // answer only starts this check and reports it in progress.
92
+ const schema = await checkStorageSchema(host.storage)
93
+ if (!schema.ok) {
94
+ throw new SixbCliError(`[SixbRun] ${host.id}'s storage is not usable: ${schema.reason}`)
95
+ }
96
+
97
+ const module = (await import(pathToFileURL(script.file).href)) as { readonly default?: unknown }
98
+ if (typeof module.default !== "function") {
99
+ throw new SixbCliError(`[SixbRun] ${script.path} has no default export to run.`, {
100
+ remediation:
101
+ "Export a function: `export default async function ({ sixb, args, signal }: ScriptContext) { ... }`.",
102
+ })
103
+ }
104
+
105
+ if (stop.signal.aborted) return 130
106
+ say(`${tone.muted(glyph.prompt)} ${tone.strong(script.path)} ${tone.muted(`on ${host.id}`)}`)
107
+ const started = performance.now()
108
+ try {
109
+ await bound.run({ main: module.default, args: options.args, signal: stop.signal })
110
+ } catch (error) {
111
+ // A script that stops by throwing once its signal aborts, as `throwIfAborted()` does, was
112
+ // stopped; any other throw is its own failure, and its stack is what its author needs.
113
+ if (!stop.signal.aborted) {
114
+ console.error(error)
115
+ say(`${tone.fail(glyph.fail)} ${script.path} failed after ${seconds(started)}`)
116
+ return 1
117
+ }
118
+ }
119
+
120
+ if (stop.signal.aborted) {
121
+ say(`${tone.warn(glyph.warn)} ${script.path} stopped after ${seconds(started)}`)
122
+ return 130
123
+ }
124
+ say(`${tone.ok(glyph.ok)} ${script.path} finished in ${seconds(started)}`)
125
+ return 0
126
+ } finally {
127
+ stop.dispose()
128
+ await stopSixbProviders(host)
129
+ }
130
+ }
131
+
132
+ /**
133
+ * The first Ctrl-C or SIGTERM aborts the script's `signal`; a second one exits at once. A hangup,
134
+ * such as a closed SSH connection, exits at once: nobody is left to read the output or press
135
+ * Ctrl-C again. Either way, writes already committed stay committed.
136
+ */
137
+ function interruptOnSignals(): { readonly signal: AbortSignal; dispose(): void } {
138
+ const controller = new AbortController()
139
+ const signals = ["SIGINT", "SIGTERM", "SIGHUP"] as const
140
+ const onSignal = (signal: (typeof signals)[number]) => {
141
+ if (signal === "SIGHUP") process.exit(129)
142
+ if (controller.signal.aborted) process.exit(130)
143
+ say(tone.muted("Stopping the script. Press Ctrl-C again to exit at once."))
144
+ controller.abort(new Error(`[SixbRun] Stopped by ${signal}.`))
145
+ }
146
+ for (const signal of signals) process.on(signal, onSignal)
147
+ return {
148
+ signal: controller.signal,
149
+ dispose: () => {
150
+ for (const signal of signals) process.off(signal, onSignal)
151
+ },
152
+ }
153
+ }
154
+
155
+ async function runOnDeployment(
156
+ cwd: string,
157
+ script: ProjectScript,
158
+ options: RunScriptOptions
159
+ ): Promise<number> {
160
+ const { config } = await loadDeployConfig(cwd)
161
+ const { target } = config
162
+ if (!target.run) {
163
+ throw new SixbCliError(`[SixbRun] A ${target.kind} deployment cannot run scripts.`)
164
+ }
165
+
166
+ const status = await withTask("run", `Asking ${target.location}`, () =>
167
+ target.status({ name: config.name })
168
+ )
169
+ if (!status.release) {
170
+ throw new SixbCliError(
171
+ `[SixbRun] Nothing named ${config.name} is deployed on ${target.location} yet.`,
172
+ { remediation: "Deploy it first: sixb deploy." }
173
+ )
174
+ }
175
+
176
+ const deployed = status.release.commit
177
+ const head = await headCommit(cwd)
178
+ const question =
179
+ `Run ${tone.strong(script.path)} on ${tone.strong(config.name)} ${tone.muted(`(${target.kind} ${target.location})`)}?\n` +
180
+ tone.muted(
181
+ ` Its imports resolve against the deployed ${deployed.slice(0, 12)}` +
182
+ (head && head !== deployed ? `; your HEAD is ${head.slice(0, 12)}.` : ".")
183
+ )
184
+ if (!(await confirm(question, options.yes === true))) {
185
+ say(tone.muted("Not run."))
186
+ return 1
187
+ }
188
+
189
+ return target.run(
190
+ {
191
+ path: script.path,
192
+ source: new Uint8Array(await readFile(script.file)),
193
+ args: options.args,
194
+ },
195
+ { name: config.name }
196
+ )
197
+ }
198
+
199
+ /** Asks before a deployed run. Without a terminal there is nobody to ask, so only `--yes` proceeds. */
200
+ async function confirm(question: string, yes: boolean): Promise<boolean> {
201
+ if (yes) return true
202
+ if (!process.stdin.isTTY) {
203
+ throw new SixbCliError("[SixbRun] Running on the deployment needs a yes.", {
204
+ remediation: "Pass --yes to run without being asked.",
205
+ })
206
+ }
207
+
208
+ say(question)
209
+ const prompt = createInterface({ input: process.stdin, output: process.stderr })
210
+ const answer = await prompt.question("Run it? [y/N] ").finally(() => prompt.close())
211
+ return answer.trim().toLowerCase() === "y"
212
+ }
213
+
214
+ /** On standard error, so a script run here has standard output to itself. */
215
+ function say(line: string): void {
216
+ process.stderr.write(`${line}\n`)
217
+ }
218
+
219
+ function seconds(started: number): string {
220
+ return `${((performance.now() - started) / 1000).toFixed(1)}s`
221
+ }
package/src/index.tsx CHANGED
@@ -358,6 +358,20 @@ async function main(): Promise<void> {
358
358
  break
359
359
  }
360
360
 
361
+ case "run": {
362
+ const { runScriptCommand } = await import("./commands/run")
363
+ const [script = "", ...scriptArgs] = positionals
364
+ const exitCode = await runScriptCommand({
365
+ script,
366
+ args: scriptArgs,
367
+ entry: getFlag("entry"),
368
+ deployed: hasFlag("deployed"),
369
+ yes: hasFlag("yes"),
370
+ })
371
+ // Whatever the script left running, such as a timer or a socket, must not keep it alive.
372
+ return process.exit(exitCode)
373
+ }
374
+
361
375
  case "db:prepare": {
362
376
  const { runDbPrepare } = await import("./commands/db-prepare")
363
377
  await runDbPrepare({ entry: getFlag("entry") })
@@ -126,7 +126,12 @@ export const CLI_OPTION_DEFINITIONS = {
126
126
  },
127
127
  yes: {
128
128
  syntax: "--yes",
129
- summary: "Allow the folders named without asking",
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" },
@@ -232,6 +237,7 @@ export type LocalCommandId =
232
237
  | "worker"
233
238
  | "worker-group"
234
239
  | "check"
240
+ | "run"
235
241
  | "typegen"
236
242
  | "build"
237
243
  | "desktop:build"
@@ -274,6 +280,8 @@ interface CommandNode {
274
280
  readonly positional: number
275
281
  }[]
276
282
  readonly rootHelpLabel?: string
283
+ /** Everything after the first positional is a positional too, passed on untouched. */
284
+ readonly passthrough?: boolean
277
285
  }
278
286
 
279
287
  const CONNECTION_OPTIONS = ["api-url", "token", "profile"] as const
@@ -535,6 +543,14 @@ const commandTree: readonly CommandNode[] = [
535
543
  rootHelpLabel: "worker-group [types...]",
536
544
  }),
537
545
  command("check", "Validate project configuration and health", { options: ["entry"] }),
546
+ command("run", "Run a script against the project, here or in production", {
547
+ usage: "sixb run [--deployed] [--yes] [--entry <path>] <script> [args...]",
548
+ options: ["entry", "deployed", "yes"],
549
+ minimumPositionals: 1,
550
+ maximumPositionals: Number.POSITIVE_INFINITY,
551
+ passthrough: true,
552
+ rootHelpLabel: "run <script>",
553
+ }),
538
554
  command("typegen", "Generate ontology types for typed queries", { options: ["entry"] }),
539
555
  command("build", "Build the runtime and the app for production", {
540
556
  options: ["entry", "outdir"],
@@ -751,7 +767,7 @@ const ROOT_HELP_GROUP_COMMANDS: readonly {
751
767
  readonly compact?: boolean
752
768
  }[] = [
753
769
  { title: "Agent", names: ["agent", "connect"] },
754
- { title: "Develop", names: ["init", "dev", "env", "check", "typegen", "build"] },
770
+ { title: "Develop", names: ["init", "dev", "env", "check", "run", "typegen", "build"] },
755
771
  { title: "Deploy", names: ["deploy", "desktop"] },
756
772
  {
757
773
  title: "Run in production",
@@ -865,6 +881,7 @@ function command(
865
881
  readonly positional: number
866
882
  }[]
867
883
  readonly rootHelpLabel?: string
884
+ readonly passthrough?: boolean
868
885
  } = {}
869
886
  ): CommandNode {
870
887
  const path = input.path ?? [id]
@@ -879,6 +896,7 @@ function command(
879
896
  maximumPositionals: input.maximumPositionals ?? 0,
880
897
  requiredInputs: input.requiredInputs,
881
898
  rootHelpLabel: input.rootHelpLabel ?? (path.length === 1 ? path[0] : undefined),
899
+ ...(input.passthrough ? { passthrough: true } : {}),
882
900
  }
883
901
  }
884
902
 
@@ -923,13 +941,24 @@ function parseLocalCommand(root: CommandNode, args: readonly string[]): ParsedCl
923
941
 
924
942
  if (!node.id) throw new Error(`[SixbCLI] Command '${path.join(" ")}' has no handler.`)
925
943
  const remaining = args.slice(index)
926
- if (requestsHelp(remaining)) {
944
+ if (requestsHelp(node.passthrough ? remaining.slice(0, firstPositional(remaining)) : remaining)) {
927
945
  return { kind: "help", help: helpFor(node, path) }
928
946
  }
929
947
  const { options, positionals } = parseOptions(node, path, remaining)
930
948
  return { kind: "command", id: node.id, path, positionals, options }
931
949
  }
932
950
 
951
+ /** Where the first positional is, past options and the values they take. */
952
+ function firstPositional(args: readonly string[]): number {
953
+ for (let index = 0; index < args.length; index++) {
954
+ const argument = args[index] ?? ""
955
+ if (argument === "--" || !argument.startsWith("-")) return index
956
+ const definition = CLI_OPTION_DEFINITIONS[argument.slice(2) as CliOptionName]
957
+ if (definition?.kind === "string") index++
958
+ }
959
+ return args.length
960
+ }
961
+
933
962
  function requestsHelp(args: readonly string[]): boolean {
934
963
  const separator = args.indexOf("--")
935
964
  const options = separator < 0 ? args : args.slice(0, separator)
@@ -950,12 +979,14 @@ function parseOptions(
950
979
  for (let index = 0; index < args.length; index++) {
951
980
  const argument = args[index]
952
981
  if (argument === undefined) continue
953
- if (argument === "--") {
982
+ // A script's own `--` is one of its arguments.
983
+ if (argument === "--" && !(node.passthrough && positionalOnly)) {
954
984
  positionalOnly = true
955
985
  continue
956
986
  }
957
987
  if (positionalOnly || !argument.startsWith("-")) {
958
988
  positionals.push(argument)
989
+ if (node.passthrough) positionalOnly = true
959
990
  continue
960
991
  }
961
992
  if (!argument.startsWith("--")) {
@@ -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) {
@@ -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 { agentRuntimeRequired, agentWorkerRequired, lakeWorkerRequired } from "./worker-registry"
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 (claims from queues)
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,
@@ -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,13 +4,22 @@ 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 = ["sync", "agent", "pipeline", "projection", "workflow", "lake"] as const
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
 
@@ -80,6 +89,10 @@ const workerFactories: Record<WorkerType, WorkerFactory> = {
80
89
  create: (sixb, options) =>
81
90
  new LakeWorker(sixb, { concurrency: options.workerConcurrency?.lake }),
82
91
  },
92
+ render: {
93
+ create: (sixb, options) =>
94
+ new RenderWorker(sixb, { concurrency: options.workerConcurrency?.render }),
95
+ },
83
96
  }
84
97
 
85
98
  export function createWorkerForType(
@@ -207,6 +220,10 @@ export function resolveRegisteredWorkerTypes(sixb: LoadedSixbHost): readonly Wor
207
220
  workerTypes.push("lake")
208
221
  }
209
222
 
223
+ if (renderWorkerRequired(sixb)) {
224
+ workerTypes.push("render")
225
+ }
226
+
210
227
  return workerTypes
211
228
  }
212
229
 
@@ -234,24 +251,34 @@ export function lakeWorkerRequired(sixb: LoadedSixbHost): boolean {
234
251
  return getLakeRetentionRuntime(sixb).automatic || getDatasetIngestRuntime(sixb).enabled
235
252
  }
236
253
 
254
+ /** Renders run in the project's sandboxes, so a project with none asks for none. */
255
+ export function renderWorkerRequired(sixb: LoadedSixbHost): boolean {
256
+ return sixb.sandboxes !== undefined
257
+ }
258
+
237
259
  /** Requests stay queued while no worker claims them, which looks like an idle system. */
238
260
  export function omittedWorkerWarnings(
239
261
  sixb: LoadedSixbHost,
240
262
  workerTypes: readonly string[]
241
263
  ): readonly string[] {
242
- if (workerTypes.includes("lake")) return []
264
+ const omitted = (workerType: WorkerType) => !workerTypes.includes(workerType)
243
265
 
244
266
  return [
245
- ...(getLakeRetentionRuntime(sixb).automatic
267
+ ...(omitted("lake") && getLakeRetentionRuntime(sixb).automatic
246
268
  ? [
247
269
  "Lake cleanup needs a lake worker and this group has none: run `sixb worker lake`, or the lake keeps growing.",
248
270
  ]
249
271
  : []),
250
- ...(getDatasetIngestRuntime(sixb).enabled
272
+ ...(omitted("lake") && getDatasetIngestRuntime(sixb).enabled
251
273
  ? [
252
274
  "Ingested changes need a lake worker and this group has none: run `sixb worker lake`, or they wait and never reach their dataset.",
253
275
  ]
254
276
  : []),
277
+ ...(omitted("render") && renderWorkerRequired(sixb)
278
+ ? [
279
+ "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.",
280
+ ]
281
+ : []),
255
282
  ]
256
283
  }
257
284
 
@@ -219,7 +219,7 @@ export class LocalRunner {
219
219
  }
220
220
 
221
221
  /**
222
- * Stop a background command, and everything it started, as the agent's `bash_stop` does. False
222
+ * Stop a background command, and everything it started, as the agent's `stop` does. False
223
223
  * when it ended already, or is not this `sixb`'s.
224
224
  */
225
225
  async stopBackground(ref: ComputerBackgroundCommandRef): Promise<boolean> {
package/src/tui/app.tsx CHANGED
@@ -41,6 +41,7 @@ import {
41
41
  contextStatus,
42
42
  elapsed,
43
43
  fittedContextText,
44
+ pickedAnswer,
44
45
  shortPath,
45
46
  } from "./format"
46
47
  import { Palette, type PaletteItem } from "./palette"
@@ -666,7 +667,7 @@ function Home(
666
667
  },
667
668
  throwOnError: true,
668
669
  })
669
- if (created.thread.runsOn === "computer") void runner.claim(posted.run.id)
670
+ if (created.thread.runsOn === "computer" && posted.run) void runner.claim(posted.run.id)
670
671
  props.onOpen(created.thread.id)
671
672
  return true
672
673
  } catch (error) {
@@ -1005,27 +1006,30 @@ function ThreadView(
1005
1006
  props.say("It works in another folder: press ctrl+f to move it here first.")
1006
1007
  return false
1007
1008
  }
1008
- if (activeRunId) {
1009
- props.say("The agent is still working. Press esc twice to stop it.")
1010
- return false
1011
- }
1012
1009
  const { data, error } = await postAgentThreadMessage({
1013
1010
  client,
1014
1011
  path: { threadId },
1015
1012
  body: {
1016
- text,
1013
+ text: pickedAnswer(messages, text),
1017
1014
  // The thread's mode applies, unless one chosen here has not reached it yet.
1018
1015
  ...(props.approval?.chosen && props.approval.mode
1019
1016
  ? { approvalMode: props.approval.mode }
1020
1017
  : {}),
1021
1018
  ...requesterSettings(),
1022
1019
  ...messageSelection(models, settings),
1020
+ // Enter steers the turn that runs; a message it cannot steer is refused with why.
1021
+ ...(activeRunId ? { delivery: "steer" as const } : {}),
1023
1022
  },
1024
1023
  })
1025
1024
  if (error || !data) {
1026
1025
  props.say(errorText(error), "error")
1027
1026
  return false
1028
1027
  }
1028
+ // A message sent while a turn runs waits in the thread's inbox instead of starting one.
1029
+ if (!data.run) {
1030
+ void reload()
1031
+ return true
1032
+ }
1029
1033
  if (runsHere) void runner.claim(data.run.id)
1030
1034
  setLive(liveRun(data.run.id))
1031
1035
  void reload()