@sixb/cli 0.2.2 → 0.2.4
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 +25 -22
- package/dist/commands/access-token-utils.d.ts.map +1 -1
- package/dist/commands/agent.d.ts +5 -0
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/api.d.ts.map +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/dev-runner.d.ts.map +1 -1
- package/dist/commands/env.d.ts +6 -1
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/lake-cleanup.d.ts +2 -12
- package/dist/commands/lake-cleanup.d.ts.map +1 -1
- package/dist/commands/lake-rejected.d.ts +10 -0
- package/dist/commands/lake-rejected.d.ts.map +1 -0
- package/dist/commands/orchestrator.d.ts.map +1 -1
- package/dist/commands/scheduler.d.ts +2 -5
- package/dist/commands/scheduler.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +12 -7
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.d.ts +7 -1
- package/dist/lib/deploy-release.d.ts.map +1 -1
- package/dist/lib/duration.d.ts +3 -0
- package/dist/lib/duration.d.ts.map +1 -0
- package/dist/lib/loadSixb.d.ts.map +1 -1
- package/dist/lib/production-roles.d.ts +0 -4
- package/dist/lib/production-roles.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts +7 -9
- package/dist/lib/runtime.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/local-runner.d.ts +1 -1
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/format.d.ts +20 -0
- package/dist/tui/format.d.ts.map +1 -1
- package/dist/tui/transcript.d.ts.map +1 -1
- package/dist/ui/deploy-screens.d.ts +4 -2
- package/dist/ui/deploy-screens.d.ts.map +1 -1
- package/dist/ui/env-screens.d.ts +14 -1
- package/dist/ui/env-screens.d.ts.map +1 -1
- package/dist/ui/screens.d.ts +5 -11
- package/dist/ui/screens.d.ts.map +1 -1
- package/package.json +20 -16
- package/src/commands/access-token-utils.ts +2 -20
- package/src/commands/agent.ts +54 -8
- package/src/commands/api.ts +7 -0
- package/src/commands/check.ts +75 -1
- package/src/commands/deploy.ts +15 -3
- package/src/commands/dev-runner.ts +5 -0
- package/src/commands/env.ts +99 -20
- package/src/commands/lake-cleanup.ts +25 -48
- package/src/commands/lake-rejected.ts +36 -0
- package/src/commands/orchestrator.ts +2 -7
- package/src/commands/scheduler.ts +11 -61
- package/src/commands/worker-group.ts +6 -3
- package/src/index.tsx +10 -4
- package/src/lib/command-line.ts +25 -12
- package/src/lib/deploy-release.ts +42 -2
- package/src/lib/duration.ts +11 -0
- package/src/lib/loadSixb.ts +3 -4
- package/src/lib/production-roles.ts +0 -1
- package/src/lib/runtime.ts +62 -43
- package/src/lib/shareable-providers.ts +2 -2
- package/src/lib/worker-concurrency.ts +1 -0
- package/src/lib/worker-registry.ts +36 -1
- package/src/runner/local-runner.ts +1 -1
- package/src/tui/app.tsx +2 -1
- package/src/tui/format.ts +190 -3
- package/src/tui/transcript.tsx +8 -1
- package/src/ui/deploy-screens.ts +8 -1
- package/src/ui/env-screens.ts +39 -5
- package/src/ui/screens.ts +21 -20
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { parseDuration } from "@sixb/core/internal/runtime"
|
|
2
|
+
|
|
3
|
+
/** A duration flag such as 30m, 12h, 7d, 4w or 1y, in milliseconds. */
|
|
4
|
+
export function parseDurationMs(value: string, flag: string): number {
|
|
5
|
+
const durationMs = parseDuration(value)
|
|
6
|
+
if (durationMs === null) {
|
|
7
|
+
throw new Error(`[SixbCLI] Use ${flag} like 30d, 12h, 4w, or 1y.`)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return durationMs
|
|
11
|
+
}
|
package/src/lib/loadSixb.ts
CHANGED
|
@@ -17,13 +17,14 @@ const REQUIRED_HOST_PROPERTIES = [
|
|
|
17
17
|
"blobStorage",
|
|
18
18
|
"queues",
|
|
19
19
|
"auth",
|
|
20
|
-
"scheduler",
|
|
21
20
|
] as const
|
|
22
21
|
|
|
23
22
|
const REQUIRED_LIFECYCLE_METHODS = [
|
|
24
23
|
"withScope",
|
|
24
|
+
"startMaintenance",
|
|
25
25
|
"startOntologyMaintenance",
|
|
26
26
|
"getOntologyOperationalStatus",
|
|
27
|
+
"prepareReadiness",
|
|
27
28
|
"checkReadiness",
|
|
28
29
|
"closeLogger",
|
|
29
30
|
"closeConnectors",
|
|
@@ -103,9 +104,7 @@ function isSixbHost(value: unknown): value is LoadedSixbHost {
|
|
|
103
104
|
isRecord(value.logging) &&
|
|
104
105
|
hasMethods(value.logging, ["startExecution", "read", "tail"]) &&
|
|
105
106
|
isRecord(value.blobStorage) &&
|
|
106
|
-
hasMethods(value.blobStorage, ["put", "open", "stat"])
|
|
107
|
-
isRecord(value.scheduler) &&
|
|
108
|
-
hasMethods(value.scheduler, ["start", "stop"])
|
|
107
|
+
hasMethods(value.blobStorage, ["put", "open", "stat"])
|
|
109
108
|
)
|
|
110
109
|
}
|
|
111
110
|
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
const PRODUCTION_ROLES = {
|
|
8
8
|
api: { onEventPlane: true, usesStorageSchema: true },
|
|
9
9
|
rules: { onEventPlane: true, usesStorageSchema: true },
|
|
10
|
-
scheduler: { onEventPlane: true, usesStorageSchema: true },
|
|
11
10
|
orchestrator: { onEventPlane: true, usesStorageSchema: true },
|
|
12
11
|
worker: { onEventPlane: true, usesStorageSchema: true },
|
|
13
12
|
"worker-group": { onEventPlane: true, usesStorageSchema: true },
|
package/src/lib/runtime.ts
CHANGED
|
@@ -7,15 +7,17 @@ import {
|
|
|
7
7
|
getProjectionDispatchDescriptors,
|
|
8
8
|
ProjectionRunDispatcher,
|
|
9
9
|
} from "@sixb/core/internal/projections"
|
|
10
|
-
import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
|
|
10
|
+
import { getDatasetIngestRuntime, setApiPublicOrigin } from "@sixb/core/internal/runtime"
|
|
11
11
|
import { checkPipelineMarkings, getAppliedMarkings } from "@sixb/core/internal/security"
|
|
12
12
|
import { SyncRunDispatcher } from "@sixb/core/internal/syncs"
|
|
13
13
|
import type { Worker } from "@sixb/core/internal/workers"
|
|
14
14
|
import { WorkflowRunDispatcher } from "@sixb/core/internal/workflows"
|
|
15
15
|
import { assertLakeDatasetDefinitionsCompatible } from "@sixb/core/lake-storage"
|
|
16
|
+
import { LakeWorker } from "@sixb/lake-worker"
|
|
16
17
|
import {
|
|
17
18
|
type CompileRoutesDiagnostic,
|
|
18
19
|
compileRoutesWithDiagnostics,
|
|
20
|
+
createMaintenancePasses,
|
|
19
21
|
OrchestratorWorker,
|
|
20
22
|
} from "@sixb/orchestrator"
|
|
21
23
|
import { PipelineWorker } from "@sixb/pipeline-worker"
|
|
@@ -27,7 +29,7 @@ import type { LoadedSixbHost } from "./loadSixb"
|
|
|
27
29
|
import { configuredOrigin } from "./public-origin"
|
|
28
30
|
import { stopQuietly } from "./role-lifecycle"
|
|
29
31
|
import type { WorkerConcurrency } from "./worker-registry"
|
|
30
|
-
import { agentRuntimeRequired, agentWorkerRequired } from "./worker-registry"
|
|
32
|
+
import { agentRuntimeRequired, agentWorkerRequired, lakeWorkerRequired } from "./worker-registry"
|
|
31
33
|
|
|
32
34
|
export function waitForWorkerFailure(worker: Worker | null | undefined): Promise<never> {
|
|
33
35
|
return new Promise<never>((_resolve, reject) => {
|
|
@@ -42,6 +44,7 @@ async function closeProvider(provider: { close?(): void | Promise<void> }): Prom
|
|
|
42
44
|
export interface RunningSixbRuntime {
|
|
43
45
|
readonly rulesWorker: RulesWorker | null
|
|
44
46
|
readonly syncWorker: SyncWorker | null
|
|
47
|
+
readonly lakeWorker: LakeWorker | null
|
|
45
48
|
readonly agentWorker: AgentWorker | null
|
|
46
49
|
readonly projectionWorker: ProjectionWorker | null
|
|
47
50
|
readonly pipelineWorker: PipelineWorker | null
|
|
@@ -76,10 +79,6 @@ export interface RunningRulesRuntime {
|
|
|
76
79
|
stop(): Promise<void>
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
export interface RunningSchedulerRuntime {
|
|
80
|
-
stop(): Promise<void>
|
|
81
|
-
}
|
|
82
|
-
|
|
83
82
|
export interface RunningOrchestratorRuntime {
|
|
84
83
|
readonly orchestratorWorker: OrchestratorWorker | null
|
|
85
84
|
readonly warnings: readonly string[]
|
|
@@ -161,18 +160,6 @@ export async function startRulesRuntime(sixb: LoadedSixbHost): Promise<RunningRu
|
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
162
|
|
|
164
|
-
export async function startSchedulerRuntime(
|
|
165
|
-
sixb: LoadedSixbHost
|
|
166
|
-
): Promise<RunningSchedulerRuntime> {
|
|
167
|
-
await sixb.scheduler.start()
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
async stop() {
|
|
171
|
-
await stopQuietly(() => sixb.scheduler.stop())
|
|
172
|
-
},
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
163
|
export async function startOrchestratorRuntime(
|
|
177
164
|
sixb: LoadedSixbHost
|
|
178
165
|
): Promise<RunningOrchestratorRuntime> {
|
|
@@ -185,42 +172,69 @@ export async function startOrchestratorRuntime(
|
|
|
185
172
|
workflows: sixb.definitions.workflows.list(),
|
|
186
173
|
})
|
|
187
174
|
const warnings = diagnostics.map(formatRouteDiagnosticWarning)
|
|
188
|
-
|
|
175
|
+
const dispatchers = {
|
|
176
|
+
syncs: new SyncRunDispatcher(sixb),
|
|
177
|
+
pipelines: new PipelineRunDispatcher(sixb),
|
|
178
|
+
projections: new ProjectionRunDispatcher(sixb),
|
|
179
|
+
workflows: new WorkflowRunDispatcher(sixb),
|
|
180
|
+
}
|
|
189
181
|
|
|
182
|
+
const { projectionRuns, pipelineRuns, datasetIngest } = sixb.storage
|
|
183
|
+
if (projections.length > 0 && !projectionRuns) {
|
|
184
|
+
throw new Error("[SixbCLI] Projection dispatch requires storage.projectionRuns.")
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let orchestratorWorker: OrchestratorWorker | null = null
|
|
190
188
|
if (routes.size > 0) {
|
|
191
|
-
const projectionRuns = sixb.storage.projectionRuns
|
|
192
|
-
if (projections.length > 0 && !projectionRuns) {
|
|
193
|
-
throw new Error("[SixbCLI] Projection dispatch requires storage.projectionRuns.")
|
|
194
|
-
}
|
|
195
|
-
const projectionReconciliation =
|
|
196
|
-
projections.length > 0 && projectionRuns
|
|
197
|
-
? { lakeStorage: sixb.lakeStorage, projectionRuns }
|
|
198
|
-
: undefined
|
|
199
189
|
orchestratorWorker = new OrchestratorWorker({
|
|
200
190
|
projectId: sixb.id,
|
|
201
191
|
events: sixb.events,
|
|
202
192
|
queues: sixb.queues,
|
|
203
193
|
routes,
|
|
204
|
-
dispatchers
|
|
205
|
-
|
|
206
|
-
pipelines: new PipelineRunDispatcher(sixb),
|
|
207
|
-
projections: new ProjectionRunDispatcher(sixb),
|
|
208
|
-
workflows: new WorkflowRunDispatcher(sixb),
|
|
209
|
-
},
|
|
210
|
-
...(projectionReconciliation ? { projectionReconciliation } : {}),
|
|
194
|
+
dispatchers,
|
|
195
|
+
reporter: sixb,
|
|
211
196
|
})
|
|
212
197
|
await orchestratorWorker.start()
|
|
213
198
|
}
|
|
214
199
|
|
|
200
|
+
// Runs with or without routes: every project commits events, and cron emits what routes consume.
|
|
201
|
+
const maintenance = sixb.startMaintenance(
|
|
202
|
+
createMaintenancePasses({
|
|
203
|
+
projectId: sixb.id,
|
|
204
|
+
routes,
|
|
205
|
+
dispatchers,
|
|
206
|
+
lakeStorage: sixb.lakeStorage,
|
|
207
|
+
...(projectionRuns ? { projectionRuns } : {}),
|
|
208
|
+
...(pipelineRuns ? { pipelineRuns } : {}),
|
|
209
|
+
...(datasetIngest && getDatasetIngestRuntime(sixb).enabled
|
|
210
|
+
? { ingest: { inbox: datasetIngest, queue: sixb.queues.lake, reporter: sixb } }
|
|
211
|
+
: {}),
|
|
212
|
+
...(hasRecoverableRuns(sixb)
|
|
213
|
+
? { runs: { storage: sixb.storage, queues: sixb.queues, events: sixb.events } }
|
|
214
|
+
: {}),
|
|
215
|
+
})
|
|
216
|
+
)
|
|
217
|
+
|
|
215
218
|
return {
|
|
216
219
|
orchestratorWorker,
|
|
217
220
|
warnings,
|
|
218
221
|
async stop() {
|
|
222
|
+
await stopQuietly(() => maintenance.stop())
|
|
219
223
|
await stopQuietly(() => orchestratorWorker?.stop() ?? Promise.resolve())
|
|
220
224
|
},
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
|
|
228
|
+
/** A project with none of these has no run a worker can lose, and pays for no look at them. */
|
|
229
|
+
function hasRecoverableRuns({ definitions }: LoadedSixbHost): boolean {
|
|
230
|
+
return [
|
|
231
|
+
definitions.syncs,
|
|
232
|
+
definitions.pipelines,
|
|
233
|
+
definitions.workflows,
|
|
234
|
+
definitions.projections,
|
|
235
|
+
].some((registry) => registry.list().length > 0)
|
|
236
|
+
}
|
|
237
|
+
|
|
224
238
|
/**
|
|
225
239
|
* Starts the background runtimes owned by the CLI host.
|
|
226
240
|
*
|
|
@@ -230,32 +244,32 @@ export async function startOrchestratorRuntime(
|
|
|
230
244
|
* 3. PipelineWorker (claims from queues)
|
|
231
245
|
* 4. WorkflowWorker (claims from queues)
|
|
232
246
|
* 5. SyncWorker (claims from queues)
|
|
233
|
-
* 6.
|
|
234
|
-
* 7.
|
|
247
|
+
* 6. LakeWorker (claims from queues)
|
|
248
|
+
* 7. Orchestrator (subscribes to events, enqueues jobs, runs cron and the maintenance loop)
|
|
235
249
|
* 8. API server, when this process serves it
|
|
236
250
|
* 9. AgentWorker (claims from queues; its turns call the API)
|
|
237
251
|
*
|
|
238
252
|
* Shutdown order (producers before consumers):
|
|
239
253
|
* 1. AgentWorker (ends its turns while the API still answers them)
|
|
240
254
|
* 2. API server
|
|
241
|
-
* 3.
|
|
242
|
-
* 4.
|
|
255
|
+
* 3. Orchestrator (stops cron, drains pending dispatches)
|
|
256
|
+
* 4. LakeWorker
|
|
243
257
|
* 5. SyncWorker
|
|
244
258
|
* 6. WorkflowWorker
|
|
245
259
|
* 7. PipelineWorker
|
|
246
260
|
* 8. ProjectionWorker
|
|
247
261
|
* 9. RulesWorker (drains pending evaluations)
|
|
248
|
-
*
|
|
262
|
+
* 10. Runtime providers (connectors, broker)
|
|
249
263
|
*/
|
|
250
264
|
export async function startSixbRuntime(
|
|
251
265
|
sixb: LoadedSixbHost,
|
|
252
266
|
options: StartSixbRuntimeOptions = {}
|
|
253
267
|
): Promise<RunningSixbRuntime> {
|
|
254
268
|
let rulesRuntime: RunningRulesRuntime | null = null
|
|
255
|
-
let schedulerRuntime: RunningSchedulerRuntime | null = null
|
|
256
269
|
let orchestratorRuntime: RunningOrchestratorRuntime | null = null
|
|
257
270
|
let rulesWorker: RulesWorker | null = null
|
|
258
271
|
let syncWorker: SyncWorker | null = null
|
|
272
|
+
let lakeWorker: LakeWorker | null = null
|
|
259
273
|
let agentWorker: AgentWorker | null = null
|
|
260
274
|
let pipelineWorker: PipelineWorker | null = null
|
|
261
275
|
let workflowWorker: WorkflowWorker | null = null
|
|
@@ -266,8 +280,8 @@ export async function startSixbRuntime(
|
|
|
266
280
|
async function stop() {
|
|
267
281
|
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
268
282
|
await stopQuietly(() => options.api?.stop() ?? Promise.resolve())
|
|
269
|
-
await stopQuietly(() => schedulerRuntime?.stop() ?? Promise.resolve())
|
|
270
283
|
await stopQuietly(() => orchestratorRuntime?.stop() ?? Promise.resolve())
|
|
284
|
+
await stopQuietly(() => lakeWorker?.stop() ?? Promise.resolve())
|
|
271
285
|
await stopQuietly(() => syncWorker?.stop() ?? Promise.resolve())
|
|
272
286
|
await stopQuietly(() => workflowWorker?.stop() ?? Promise.resolve())
|
|
273
287
|
await stopQuietly(() => pipelineWorker?.stop() ?? Promise.resolve())
|
|
@@ -325,11 +339,14 @@ export async function startSixbRuntime(
|
|
|
325
339
|
await syncWorker.start()
|
|
326
340
|
}
|
|
327
341
|
|
|
342
|
+
if (lakeWorkerRequired(sixb)) {
|
|
343
|
+
lakeWorker = new LakeWorker(sixb, { concurrency: options.workerConcurrency?.lake })
|
|
344
|
+
await lakeWorker.start()
|
|
345
|
+
}
|
|
346
|
+
|
|
328
347
|
orchestratorRuntime = await startOrchestratorRuntime(sixb)
|
|
329
348
|
orchestratorWorker = orchestratorRuntime.orchestratorWorker
|
|
330
349
|
warnings.push(...orchestratorRuntime.warnings)
|
|
331
|
-
|
|
332
|
-
schedulerRuntime = await startSchedulerRuntime(sixb)
|
|
333
350
|
}
|
|
334
351
|
|
|
335
352
|
await options.api?.start()
|
|
@@ -343,6 +360,7 @@ export async function startSixbRuntime(
|
|
|
343
360
|
const workers: Worker[] = []
|
|
344
361
|
if (rulesWorker) workers.push(rulesWorker)
|
|
345
362
|
if (syncWorker) workers.push(syncWorker)
|
|
363
|
+
if (lakeWorker) workers.push(lakeWorker)
|
|
346
364
|
if (agentWorker) workers.push(agentWorker)
|
|
347
365
|
if (projectionWorker) workers.push(projectionWorker)
|
|
348
366
|
if (pipelineWorker) workers.push(pipelineWorker)
|
|
@@ -354,6 +372,7 @@ export async function startSixbRuntime(
|
|
|
354
372
|
return {
|
|
355
373
|
rulesWorker,
|
|
356
374
|
syncWorker,
|
|
375
|
+
lakeWorker,
|
|
357
376
|
agentWorker,
|
|
358
377
|
projectionWorker,
|
|
359
378
|
pipelineWorker,
|
|
@@ -14,12 +14,12 @@ const SLOTS = [
|
|
|
14
14
|
{
|
|
15
15
|
name: "queues",
|
|
16
16
|
get: (sixb: LoadedSixbHost): Broker | Queues => sixb.queues,
|
|
17
|
-
replacements: "@sixb/bullmq",
|
|
17
|
+
replacements: "@sixb/queues-bullmq",
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
name: "broker",
|
|
21
21
|
get: (sixb: LoadedSixbHost): Broker | Queues => sixb.broker,
|
|
22
|
-
replacements: "@sixb/redis or @sixb/nats",
|
|
22
|
+
replacements: "@sixb/broker-redis or @sixb/broker-nats",
|
|
23
23
|
},
|
|
24
24
|
] as const
|
|
25
25
|
|
|
@@ -7,6 +7,7 @@ const ENVIRONMENT_VARIABLES = {
|
|
|
7
7
|
pipeline: "SIXB_PIPELINE_WORKER_CONCURRENCY",
|
|
8
8
|
projection: "SIXB_PROJECTION_WORKER_CONCURRENCY",
|
|
9
9
|
workflow: "SIXB_WORKFLOW_WORKER_CONCURRENCY",
|
|
10
|
+
lake: "SIXB_LAKE_WORKER_CONCURRENCY",
|
|
10
11
|
} as const satisfies Record<WorkerType, string>
|
|
11
12
|
|
|
12
13
|
/** Resolve the scalar concurrency accepted by `sixb worker <type>`. */
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AgentWorker } from "@sixb/agent-worker"
|
|
2
|
+
import { getDatasetIngestRuntime, getLakeRetentionRuntime } from "@sixb/core/internal/runtime"
|
|
2
3
|
import type { Worker } from "@sixb/core/internal/workers"
|
|
4
|
+
import { LakeWorker } from "@sixb/lake-worker"
|
|
3
5
|
import { PipelineWorker } from "@sixb/pipeline-worker"
|
|
4
6
|
import { ProjectionWorker } from "@sixb/projection-worker"
|
|
5
7
|
import { SyncWorker } from "@sixb/sync-worker"
|
|
@@ -8,7 +10,7 @@ import { SixbCliError } from "./errors"
|
|
|
8
10
|
import type { LoadedSixbHost } from "./loadSixb"
|
|
9
11
|
import { configuredOrigin } from "./public-origin"
|
|
10
12
|
|
|
11
|
-
export const WORKER_TYPES = ["sync", "agent", "pipeline", "projection", "workflow"] as const
|
|
13
|
+
export const WORKER_TYPES = ["sync", "agent", "pipeline", "projection", "workflow", "lake"] as const
|
|
12
14
|
|
|
13
15
|
export type WorkerType = (typeof WORKER_TYPES)[number]
|
|
14
16
|
|
|
@@ -74,6 +76,10 @@ const workerFactories: Record<WorkerType, WorkerFactory> = {
|
|
|
74
76
|
create: (sixb, options) =>
|
|
75
77
|
new WorkflowWorker(sixb, { concurrency: options.workerConcurrency?.workflow }),
|
|
76
78
|
},
|
|
79
|
+
lake: {
|
|
80
|
+
create: (sixb, options) =>
|
|
81
|
+
new LakeWorker(sixb, { concurrency: options.workerConcurrency?.lake }),
|
|
82
|
+
},
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
export function createWorkerForType(
|
|
@@ -197,6 +203,10 @@ export function resolveRegisteredWorkerTypes(sixb: LoadedSixbHost): readonly Wor
|
|
|
197
203
|
workerTypes.push("workflow")
|
|
198
204
|
}
|
|
199
205
|
|
|
206
|
+
if (lakeWorkerRequired(sixb)) {
|
|
207
|
+
workerTypes.push("lake")
|
|
208
|
+
}
|
|
209
|
+
|
|
200
210
|
return workerTypes
|
|
201
211
|
}
|
|
202
212
|
|
|
@@ -220,6 +230,31 @@ function resolveAgentApiBaseUrl(value: string | undefined): string {
|
|
|
220
230
|
return apiBaseUrl
|
|
221
231
|
}
|
|
222
232
|
|
|
233
|
+
export function lakeWorkerRequired(sixb: LoadedSixbHost): boolean {
|
|
234
|
+
return getLakeRetentionRuntime(sixb).automatic || getDatasetIngestRuntime(sixb).enabled
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Requests stay queued while no worker claims them, which looks like an idle system. */
|
|
238
|
+
export function omittedWorkerWarnings(
|
|
239
|
+
sixb: LoadedSixbHost,
|
|
240
|
+
workerTypes: readonly string[]
|
|
241
|
+
): readonly string[] {
|
|
242
|
+
if (workerTypes.includes("lake")) return []
|
|
243
|
+
|
|
244
|
+
return [
|
|
245
|
+
...(getLakeRetentionRuntime(sixb).automatic
|
|
246
|
+
? [
|
|
247
|
+
"Lake cleanup needs a lake worker and this group has none: run `sixb worker lake`, or the lake keeps growing.",
|
|
248
|
+
]
|
|
249
|
+
: []),
|
|
250
|
+
...(getDatasetIngestRuntime(sixb).enabled
|
|
251
|
+
? [
|
|
252
|
+
"Ingested changes need a lake worker and this group has none: run `sixb worker lake`, or they wait and never reach their dataset.",
|
|
253
|
+
]
|
|
254
|
+
: []),
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
|
|
223
258
|
/** Explicit model calls can enqueue accounting recovery without a model catalog. */
|
|
224
259
|
export function agentWorkerRequired(sixb: LoadedSixbHost): boolean {
|
|
225
260
|
const { storage } = sixb
|
|
@@ -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 `
|
|
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"
|
|
@@ -1013,7 +1014,7 @@ function ThreadView(
|
|
|
1013
1014
|
client,
|
|
1014
1015
|
path: { threadId },
|
|
1015
1016
|
body: {
|
|
1016
|
-
text,
|
|
1017
|
+
text: pickedAnswer(messages, text),
|
|
1017
1018
|
// The thread's mode applies, unless one chosen here has not reached it yet.
|
|
1018
1019
|
...(props.approval?.chosen && props.approval.mode
|
|
1019
1020
|
? { approvalMode: props.approval.mode }
|
package/src/tui/format.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface ToolLine {
|
|
|
15
15
|
readonly held?: boolean
|
|
16
16
|
/** A shell command, shown whole as the call's panel. */
|
|
17
17
|
readonly command?: string
|
|
18
|
+
/** The preview is diff lines, `+` added and `-` removed, colored as such. */
|
|
19
|
+
readonly diff?: boolean
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
const PREVIEW_LINES = 4
|
|
@@ -70,6 +72,31 @@ export function toolLine(
|
|
|
70
72
|
...error,
|
|
71
73
|
}
|
|
72
74
|
}
|
|
75
|
+
case "wait":
|
|
76
|
+
case "stop": {
|
|
77
|
+
// Background commands by their id, sub-agents by their key; with a sub-agent, the result is
|
|
78
|
+
// rich, its JSON in its text.
|
|
79
|
+
const ids = Array.isArray(input?.ids) ? input.ids.map(text) : [text(input?.id)]
|
|
80
|
+
const value = record(richValue(output))
|
|
81
|
+
const commands = Array.isArray(value?.commands) ? value.commands.map(record) : []
|
|
82
|
+
const results = Array.isArray(value?.results) ? value.results.map(record) : []
|
|
83
|
+
const [command] = commands
|
|
84
|
+
const one = commands.length + results.length === 1
|
|
85
|
+
const written = one ? text(command?.output) : ""
|
|
86
|
+
const childStatus = one && !command ? text(results[0]?.status) : ""
|
|
87
|
+
return {
|
|
88
|
+
verb: part.name,
|
|
89
|
+
// One command reads as bash_output's did: its id, then what it runs.
|
|
90
|
+
detail: [...ids, one && command ? firstLine(text(command.command)) : ""]
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.join(" "),
|
|
93
|
+
...(written.trim() ? { preview: lines(written) } : {}),
|
|
94
|
+
...(one && command ? backgroundNote(text(command.status), command.exitCode) : {}),
|
|
95
|
+
...(childStatus ? childNote(childStatus) : {}),
|
|
96
|
+
...error,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// What `wait` and `stop` were called for a background command: earlier threads hold them.
|
|
73
100
|
case "bash_output":
|
|
74
101
|
case "bash_stop": {
|
|
75
102
|
const output_ = text(output?.output)
|
|
@@ -83,6 +110,19 @@ export function toolLine(
|
|
|
83
110
|
}
|
|
84
111
|
}
|
|
85
112
|
case "read": {
|
|
113
|
+
// A file shown as itself, an image or a PDF, reads as view_file did.
|
|
114
|
+
if (output?.kind === "agentToolResult") {
|
|
115
|
+
return { verb: "view", detail: text(input?.path), ...error }
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(output?.entries)) {
|
|
118
|
+
const entries = `${output.entries.length} ${output.entries.length === 1 ? "entry" : "entries"}`
|
|
119
|
+
return {
|
|
120
|
+
verb: "list",
|
|
121
|
+
detail: text(input?.path),
|
|
122
|
+
note: output.truncated === true ? `${entries}+` : entries,
|
|
123
|
+
...error,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
86
126
|
const lineCount = typeof output?.endLine === "number" && typeof output.startLine === "number"
|
|
87
127
|
return {
|
|
88
128
|
verb: "read",
|
|
@@ -93,6 +133,41 @@ export function toolLine(
|
|
|
93
133
|
...error,
|
|
94
134
|
}
|
|
95
135
|
}
|
|
136
|
+
case "edit": {
|
|
137
|
+
const changed = text(output?.diff)
|
|
138
|
+
.split("\n")
|
|
139
|
+
.filter((line) => /^[+-]/.test(line))
|
|
140
|
+
|
|
141
|
+
// The diff is cut on a large edit, so the edit counts its lines; an output stored before it
|
|
142
|
+
// did carries only the diff.
|
|
143
|
+
const added =
|
|
144
|
+
typeof output?.added === "number"
|
|
145
|
+
? output.added
|
|
146
|
+
: changed.filter((line) => line.startsWith("+")).length
|
|
147
|
+
const removed =
|
|
148
|
+
typeof output?.removed === "number"
|
|
149
|
+
? output.removed
|
|
150
|
+
: changed.filter((line) => line.startsWith("-")).length
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
verb: "edit",
|
|
154
|
+
detail: text(input?.path),
|
|
155
|
+
...(output?.diff !== undefined
|
|
156
|
+
? { note: `+${added} −${removed}`, diff: true, preview: limited(changed) }
|
|
157
|
+
: {}),
|
|
158
|
+
...error,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
case "write": {
|
|
162
|
+
const linesWritten = typeof output?.lines === "number" ? output.lines : undefined
|
|
163
|
+
return {
|
|
164
|
+
verb: output?.created === false ? "rewrite" : "write",
|
|
165
|
+
detail: text(input?.path),
|
|
166
|
+
...(linesWritten !== undefined ? { note: plural(linesWritten, "line") } : {}),
|
|
167
|
+
...error,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Earlier threads hold calls to it.
|
|
96
171
|
case "view_file":
|
|
97
172
|
return { verb: "view", detail: text(input?.path), ...error }
|
|
98
173
|
case "web_search": {
|
|
@@ -112,19 +187,32 @@ export function toolLine(
|
|
|
112
187
|
...(failed ? fetchFailure(part.error) : {}),
|
|
113
188
|
}
|
|
114
189
|
case "publish_artifact":
|
|
190
|
+
// What `publish_artifact` with an id was called: earlier threads hold calls to them.
|
|
191
|
+
case "update_artifact":
|
|
115
192
|
case "publish_artifact_version":
|
|
116
193
|
return {
|
|
117
|
-
verb:
|
|
194
|
+
verb:
|
|
195
|
+
part.name === "publish_artifact" && !text(input?.id).startsWith("art_")
|
|
196
|
+
? "publish"
|
|
197
|
+
: "update",
|
|
118
198
|
detail: text(input?.title) || text(input?.path) || text(input?.artifactId),
|
|
119
199
|
...(output?.artifactId ? { note: `artifact:${text(output.artifactId)}` } : {}),
|
|
120
200
|
...error,
|
|
121
201
|
}
|
|
202
|
+
case "open_artifact":
|
|
203
|
+
return {
|
|
204
|
+
verb: "open",
|
|
205
|
+
detail: text(output?.title) || text(input?.id),
|
|
206
|
+
...(output?.artifactId ? { note: `artifact:${text(output.artifactId)}` } : {}),
|
|
207
|
+
...error,
|
|
208
|
+
}
|
|
122
209
|
case "spawn_agent":
|
|
123
210
|
return {
|
|
124
211
|
verb: "agent",
|
|
125
212
|
detail: [text(input?.key), firstLine(text(input?.task))].filter(Boolean).join(" "),
|
|
126
213
|
...error,
|
|
127
214
|
}
|
|
215
|
+
// What `wait` was called for sub-agents: earlier threads hold calls to it.
|
|
128
216
|
case "wait_agent": {
|
|
129
217
|
const runIds = Array.isArray(input?.runIds) ? input.runIds.length : 0
|
|
130
218
|
return {
|
|
@@ -139,12 +227,32 @@ export function toolLine(
|
|
|
139
227
|
detail: [text(input?.key), firstLine(text(input?.text))].filter(Boolean).join(" "),
|
|
140
228
|
...error,
|
|
141
229
|
}
|
|
142
|
-
case "
|
|
230
|
+
case "ask":
|
|
231
|
+
// What `ask` was called for a sub-agent: earlier threads hold calls to it.
|
|
232
|
+
case "ask_parent": {
|
|
233
|
+
const questions = askedQuestions(input)
|
|
234
|
+
// One question reads on the line; several, each with its choices numbered, under it. A row's
|
|
235
|
+
// runs of spaces collapse to one, so the choices are kept apart by a dot.
|
|
236
|
+
const [first] = questions
|
|
143
237
|
return {
|
|
144
238
|
verb: "ask",
|
|
145
|
-
detail:
|
|
239
|
+
detail:
|
|
240
|
+
questions.length === 1 && first ? first.question : plural(questions.length, "question"),
|
|
241
|
+
...(questions.length > 1 || first?.choices.length
|
|
242
|
+
? {
|
|
243
|
+
preview: questions.map((question) =>
|
|
244
|
+
[
|
|
245
|
+
...(questions.length > 1 ? [question.question] : []),
|
|
246
|
+
question.choices.map((choice, index) => `${index + 1}. ${choice}`).join(" · "),
|
|
247
|
+
]
|
|
248
|
+
.filter(Boolean)
|
|
249
|
+
.join(" ")
|
|
250
|
+
),
|
|
251
|
+
}
|
|
252
|
+
: {}),
|
|
146
253
|
...error,
|
|
147
254
|
}
|
|
255
|
+
}
|
|
148
256
|
default:
|
|
149
257
|
return {
|
|
150
258
|
verb: part.name,
|
|
@@ -253,6 +361,14 @@ function backgroundNote(status: string, exitCode: unknown): Pick<ToolLine, "note
|
|
|
253
361
|
return exitCode === 0 ? { note: "exit 0" } : { note: `exit ${exitCode}`, failed: true }
|
|
254
362
|
}
|
|
255
363
|
|
|
364
|
+
/** How a sub-agent a `wait` or a `stop` named stands, beside its line. */
|
|
365
|
+
function childNote(status: string): Pick<ToolLine, "note" | "failed"> {
|
|
366
|
+
if (status === "succeeded") return { note: "done" }
|
|
367
|
+
if (status === "cancelled") return { note: "stopped" }
|
|
368
|
+
if (status === "failed") return { note: "failed", failed: true }
|
|
369
|
+
return { note: status.replaceAll("_", " ") }
|
|
370
|
+
}
|
|
371
|
+
|
|
256
372
|
/** How decided calls ended, as the web chat's approval card names it. */
|
|
257
373
|
function decidedLine(outcomes: readonly ApprovalOutcome[]): Pick<ToolLine, "note" | "failed"> {
|
|
258
374
|
const ended = outcomes.map(outcomeNote)
|
|
@@ -294,6 +410,19 @@ function parseJson(value: string): unknown {
|
|
|
294
410
|
}
|
|
295
411
|
}
|
|
296
412
|
|
|
413
|
+
/** A rich result's value, its JSON text parsed; any other output as it is. */
|
|
414
|
+
function richValue(output: Record<string, unknown> | undefined): unknown {
|
|
415
|
+
if (output?.kind !== "agentToolResult" || !Array.isArray(output.content)) return output
|
|
416
|
+
const [first] = output.content
|
|
417
|
+
const textPart = record(first)
|
|
418
|
+
if (typeof textPart?.text !== "string") return undefined
|
|
419
|
+
try {
|
|
420
|
+
return JSON.parse(textPart.text)
|
|
421
|
+
} catch {
|
|
422
|
+
return undefined
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
297
426
|
function record(value: unknown): Record<string, unknown> | undefined {
|
|
298
427
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
299
428
|
? (value as Record<string, unknown>)
|
|
@@ -326,6 +455,64 @@ function firstLine(value: string): string {
|
|
|
326
455
|
return value.trim().split("\n")[0]?.trim() ?? ""
|
|
327
456
|
}
|
|
328
457
|
|
|
458
|
+
export interface AskedQuestion {
|
|
459
|
+
readonly question: string
|
|
460
|
+
readonly choices: readonly string[]
|
|
461
|
+
readonly multiple: boolean
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** The questions of an `ask` call, or of an earlier `ask_parent` call's one question. */
|
|
465
|
+
function askedQuestions(input: Record<string, unknown> | undefined): AskedQuestion[] {
|
|
466
|
+
if (typeof input?.question === "string") {
|
|
467
|
+
return [{ question: input.question.trim(), choices: [], multiple: false }]
|
|
468
|
+
}
|
|
469
|
+
if (!Array.isArray(input?.questions)) return []
|
|
470
|
+
return input.questions.flatMap((value) => {
|
|
471
|
+
const question = record(value)
|
|
472
|
+
if (typeof question?.question !== "string") return []
|
|
473
|
+
const choices = Array.isArray(question.choices)
|
|
474
|
+
? question.choices.filter((choice): choice is string => typeof choice === "string")
|
|
475
|
+
: []
|
|
476
|
+
return [{ question: question.question.trim(), choices, multiple: question.multiple === true }]
|
|
477
|
+
})
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** What a reply asked the user with its last `ask`: its questions, or none. */
|
|
481
|
+
export function askedInReply(
|
|
482
|
+
message: { readonly role: string; readonly parts: readonly Part[] } | null | undefined
|
|
483
|
+
): readonly AskedQuestion[] {
|
|
484
|
+
if (message?.role !== "assistant") return []
|
|
485
|
+
const asked = [...message.parts]
|
|
486
|
+
.reverse()
|
|
487
|
+
.find(
|
|
488
|
+
(part): part is ToolPart =>
|
|
489
|
+
part.kind === "tool" && part.name === "ask" && part.state === "done"
|
|
490
|
+
)
|
|
491
|
+
return askedQuestions(record(asked?.input))
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* A reply of a number to the Agent's question, its last reply's one question with choices, is the
|
|
496
|
+
* choice under that number: "2" answers "2026". Anything else is sent as typed.
|
|
497
|
+
*/
|
|
498
|
+
export function pickedAnswer(
|
|
499
|
+
messages: readonly { readonly role: string; readonly parts: readonly Part[] }[],
|
|
500
|
+
text: string
|
|
501
|
+
): string {
|
|
502
|
+
const number = text.trim()
|
|
503
|
+
if (!/^\d+$/.test(number)) return text
|
|
504
|
+
const questions = askedInReply(messages.at(-1))
|
|
505
|
+
if (questions.length !== 1) return text
|
|
506
|
+
return questions[0]?.choices[Number(number) - 1] ?? text
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** At most a few rows, with how many more there were. */
|
|
510
|
+
function limited(rows: readonly string[]): string[] {
|
|
511
|
+
return rows.length > PREVIEW_LINES
|
|
512
|
+
? [...rows.slice(0, PREVIEW_LINES), `… ${plural(rows.length - PREVIEW_LINES, "more line")}`]
|
|
513
|
+
: [...rows]
|
|
514
|
+
}
|
|
515
|
+
|
|
329
516
|
function lines(value: string): string[] {
|
|
330
517
|
const all = value.replace(/\s+$/, "").split("\n")
|
|
331
518
|
return all.length > PREVIEW_LINES
|