@sixb/cli 0.1.17 → 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/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/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/public-origin.d.ts +0 -7
- package/dist/lib/public-origin.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/ui/index.d.ts +18 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +16 -16
- 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/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 +2 -7
- package/src/commands/worker.tsx +2 -7
- package/src/index.tsx +8 -11
- package/src/lib/dev-watch.ts +6 -2
- package/src/lib/profiles.ts +3 -2
- package/src/lib/public-origin.ts +0 -13
- package/src/lib/role-lifecycle.ts +34 -0
- package/src/lib/role-view.ts +50 -0
- package/src/lib/runtime.ts +48 -50
- package/src/ui/index.tsx +46 -0
package/src/commands/atlas.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { basename } from "node:path"
|
|
1
2
|
import { type AtlasAppServer, createAtlasApp } from "@sixb/atlas"
|
|
2
3
|
import { resolveBrowserTopology, servedUrl } from "../lib/browser-topology"
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { LoadingView, RoleView, renderCliError, renderPersistent } from "../ui"
|
|
4
|
+
import { builtAtlasOutdir, resolveProductionPaths, resolveRuntimeEntry } from "../lib/production"
|
|
5
|
+
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
6
|
+
import { loadRoleView } from "../lib/role-view"
|
|
7
7
|
|
|
8
8
|
export interface AtlasOptions {
|
|
9
9
|
entry?: string
|
|
@@ -14,14 +14,18 @@ export interface AtlasOptions {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export async function runAtlas(options: AtlasOptions = {}) {
|
|
17
|
+
// Before NODE_ENV changes: see loadRoleView.
|
|
18
|
+
const view = await loadRoleView()
|
|
17
19
|
process.env.NODE_ENV = "production"
|
|
18
20
|
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const entry = await resolveRuntimeEntry({ entry: options.entry })
|
|
22
|
+
const { projectRoot, buildOutdir } = await resolveProductionPaths(entry)
|
|
23
|
+
const app = view.startup({
|
|
24
|
+
title: "Starting sixb atlas",
|
|
25
|
+
subtitle: entry,
|
|
26
|
+
status: "Starting Atlas",
|
|
27
|
+
})
|
|
23
28
|
|
|
24
|
-
let sixb: LoadedSixbHost | null = loaded.sixb
|
|
25
29
|
let atlasServer: AtlasAppServer | null = null
|
|
26
30
|
|
|
27
31
|
try {
|
|
@@ -36,40 +40,32 @@ export async function runAtlas(options: AtlasOptions = {}) {
|
|
|
36
40
|
const atlas = createAtlasApp({
|
|
37
41
|
apiBaseUrl: topology.apiPublicOrigin,
|
|
38
42
|
audience: "atlas",
|
|
39
|
-
authEnabled:
|
|
43
|
+
// No authEnabled: the page asks the API whether the project uses auth, so serving the
|
|
44
|
+
// bundle never loads the project.
|
|
40
45
|
})
|
|
41
46
|
atlasServer = await atlas.start({
|
|
42
47
|
host: topology.host,
|
|
43
48
|
port: topology.atlasPort,
|
|
44
49
|
development: false,
|
|
45
|
-
outdir: builtAtlasOutdir(
|
|
50
|
+
outdir: builtAtlasOutdir(buildOutdir),
|
|
46
51
|
})
|
|
47
52
|
|
|
48
|
-
app.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/>
|
|
55
|
-
)
|
|
53
|
+
app.started({
|
|
54
|
+
title: "Sixb Atlas started",
|
|
55
|
+
name: basename(projectRoot),
|
|
56
|
+
serviceName: "Atlas",
|
|
57
|
+
items: [{ label: "URL", value: servedUrl(topology) }],
|
|
58
|
+
})
|
|
56
59
|
|
|
57
60
|
await runUntilSignal(async () => {
|
|
58
61
|
app.unmount()
|
|
59
62
|
console.log("\nShutting down atlas...")
|
|
60
63
|
await stopQuietly(() => atlasServer?.stop() ?? Promise.resolve())
|
|
61
|
-
if (sixb) {
|
|
62
|
-
await stopSixbProviders(sixb)
|
|
63
|
-
}
|
|
64
|
-
sixb = null
|
|
65
64
|
})
|
|
66
65
|
} catch (error) {
|
|
67
66
|
app.unmount()
|
|
68
67
|
await stopQuietly(() => atlasServer?.stop() ?? Promise.resolve())
|
|
69
|
-
|
|
70
|
-
await stopSixbProviders(sixb)
|
|
71
|
-
}
|
|
72
|
-
await renderCliError(error)
|
|
68
|
+
await view.error(error)
|
|
73
69
|
process.exit(1)
|
|
74
70
|
}
|
|
75
71
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { dirname, resolve } from "node:path"
|
|
2
2
|
import { type CustomAppDevServer, createCustomApp } from "@sixb/app"
|
|
3
3
|
import { type AtlasAppServer, createAtlasApp } from "@sixb/atlas"
|
|
4
|
-
import { createSixbServer
|
|
4
|
+
import { createSixbServer } from "@sixb/server"
|
|
5
5
|
import { resolveAgentTurnTimeoutMs } from "../lib/agent-turn-timeout"
|
|
6
6
|
import { apiDocsUrl, apiEventsUrl, apiUrl, resolveBrowserTopology } from "../lib/browser-topology"
|
|
7
7
|
import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
|
|
8
|
-
import {
|
|
8
|
+
import { stopQuietly } from "../lib/role-lifecycle"
|
|
9
|
+
import { startSixbRuntime, stopSixbProviders } from "../lib/runtime"
|
|
9
10
|
import { generateProjectTypes } from "../lib/typegen"
|
|
10
11
|
import { resolveWorkerConcurrency } from "../lib/worker-concurrency"
|
|
11
12
|
import { DevView, LoadingView, renderCliError, renderPersistent } from "../ui"
|
|
@@ -34,7 +35,6 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
34
35
|
<LoadingView title="Starting sixb" subtitle={entry} status="Loading runtime" />
|
|
35
36
|
)
|
|
36
37
|
|
|
37
|
-
let server: SixbServer | null = null
|
|
38
38
|
let atlasServer: AtlasAppServer | null = null
|
|
39
39
|
let customAppServer: CustomAppDevServer | null = null
|
|
40
40
|
let sixb: LoadedSixbHost | null = null
|
|
@@ -82,19 +82,7 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
82
82
|
: null
|
|
83
83
|
|
|
84
84
|
abort.signal.throwIfAborted()
|
|
85
|
-
|
|
86
|
-
runtime = await startSixbRuntime(host, {
|
|
87
|
-
cohostWorkers: true,
|
|
88
|
-
agentApiBaseUrl: topology.apiPublicOrigin,
|
|
89
|
-
agentTurnTimeoutMs,
|
|
90
|
-
workerConcurrency,
|
|
91
|
-
})
|
|
92
|
-
abort.signal.throwIfAborted()
|
|
93
|
-
const authEnabled = host.auth.isEnabled()
|
|
94
|
-
|
|
95
|
-
app.rerender(<LoadingView title="Starting sixb" subtitle={entry} status="Starting server" />)
|
|
96
|
-
|
|
97
|
-
server = createSixbServer({
|
|
85
|
+
const server = createSixbServer({
|
|
98
86
|
host: sixb,
|
|
99
87
|
port: topology.apiPort,
|
|
100
88
|
hostname: topology.apiHost,
|
|
@@ -105,8 +93,25 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
105
93
|
},
|
|
106
94
|
...(authExperience ? { authExperience } : {}),
|
|
107
95
|
})
|
|
108
|
-
|
|
96
|
+
runtimeOwnsProviders = true
|
|
97
|
+
// The runtime owns the server's lifecycle so agent turns run only while it listens.
|
|
98
|
+
runtime = await startSixbRuntime(host, {
|
|
99
|
+
cohostWorkers: true,
|
|
100
|
+
api: {
|
|
101
|
+
start: () => {
|
|
102
|
+
app.rerender(
|
|
103
|
+
<LoadingView title="Starting sixb" subtitle={entry} status="Starting server" />
|
|
104
|
+
)
|
|
105
|
+
return server.start()
|
|
106
|
+
},
|
|
107
|
+
stop: () => server.stop(),
|
|
108
|
+
},
|
|
109
|
+
agentApiBaseUrl: topology.apiPublicOrigin,
|
|
110
|
+
agentTurnTimeoutMs,
|
|
111
|
+
workerConcurrency,
|
|
112
|
+
})
|
|
109
113
|
abort.signal.throwIfAborted()
|
|
114
|
+
const authEnabled = host.auth.isEnabled()
|
|
110
115
|
|
|
111
116
|
const atlas = createAtlasApp({
|
|
112
117
|
apiBaseUrl: topology.apiPublicOrigin,
|
|
@@ -172,7 +177,6 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
172
177
|
app.unmount()
|
|
173
178
|
await stopQuietly(() => customAppServer?.stop() ?? Promise.resolve())
|
|
174
179
|
await stopQuietly(() => atlasServer?.stop() ?? Promise.resolve())
|
|
175
|
-
await stopQuietly(() => server?.stop() ?? Promise.resolve())
|
|
176
180
|
await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
|
|
177
181
|
if (sixb && !runtimeOwnsProviders) await stopSixbProviders(sixb)
|
|
178
182
|
process.off("SIGINT", requestShutdown)
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { LoadedSixbHost } from "../lib/loadSixb"
|
|
2
2
|
import { loadProductionSixb } from "../lib/production"
|
|
3
|
+
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
3
4
|
import {
|
|
4
5
|
type RunningOrchestratorRuntime,
|
|
5
|
-
runUntilSignal,
|
|
6
6
|
startOrchestratorRuntime,
|
|
7
|
-
stopQuietly,
|
|
8
7
|
stopSixbProviders,
|
|
9
8
|
waitForWorkerFailure,
|
|
10
9
|
} from "../lib/runtime"
|
package/src/commands/rules.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { LoadedSixbHost } from "../lib/loadSixb"
|
|
2
2
|
import { loadProductionSixb } from "../lib/production"
|
|
3
|
+
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
3
4
|
import {
|
|
4
5
|
type RunningRulesRuntime,
|
|
5
|
-
runUntilSignal,
|
|
6
6
|
startRulesRuntime,
|
|
7
|
-
stopQuietly,
|
|
8
7
|
stopSixbProviders,
|
|
9
8
|
waitForWorkerFailure,
|
|
10
9
|
} from "../lib/runtime"
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { LoadedSixbHost } from "../lib/loadSixb"
|
|
2
2
|
import { loadProductionSixb } from "../lib/production"
|
|
3
|
+
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
3
4
|
import {
|
|
4
5
|
type RunningSchedulerRuntime,
|
|
5
|
-
runUntilSignal,
|
|
6
6
|
startSchedulerRuntime,
|
|
7
|
-
stopQuietly,
|
|
8
7
|
stopSixbProviders,
|
|
9
8
|
} from "../lib/runtime"
|
|
10
9
|
import { migrateStorageForRole } from "../lib/storage-migration"
|
|
@@ -12,6 +12,7 @@ import { createCliSixbClient, unwrapSixbApiResult } from "../lib/api-client"
|
|
|
12
12
|
import { resolveProfileApiClientConfig } from "../lib/profile-api-client"
|
|
13
13
|
import { KeyValueResultView, renderStatic, SecretResultView, TableResultView } from "../ui"
|
|
14
14
|
import {
|
|
15
|
+
assertSignedIn,
|
|
15
16
|
formatDate,
|
|
16
17
|
formatGroups,
|
|
17
18
|
normalizeGroupIds,
|
|
@@ -218,7 +219,9 @@ async function createServiceAccountToken(options: ServiceAccountCommandOptions)
|
|
|
218
219
|
|
|
219
220
|
const expiresAt = resolveExpiration(options)
|
|
220
221
|
const groupIds = normalizeGroupIds(options.groupIds)
|
|
221
|
-
const
|
|
222
|
+
const config = await resolveProfileApiClientConfig(options)
|
|
223
|
+
assertSignedIn(config)
|
|
224
|
+
const client = createCliSixbClient(config)
|
|
222
225
|
const result = unwrapSixbApiResult(
|
|
223
226
|
await createAuthServiceAccountAccessToken({
|
|
224
227
|
client,
|
package/src/commands/token.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { createCliSixbClient, unwrapSixbApiResult } from "../lib/api-client"
|
|
|
8
8
|
import { resolveProfileApiClientConfig } from "../lib/profile-api-client"
|
|
9
9
|
import { KeyValueResultView, renderStatic, SecretResultView, TableResultView } from "../ui"
|
|
10
10
|
import {
|
|
11
|
+
assertSignedIn,
|
|
11
12
|
formatDate,
|
|
12
13
|
formatGroups,
|
|
13
14
|
normalizeGroupIds,
|
|
@@ -83,7 +84,9 @@ async function createToken(options: TokenCommandOptions) {
|
|
|
83
84
|
|
|
84
85
|
const expiresAt = resolveExpiration(options)
|
|
85
86
|
const groupIds = normalizeGroupIds(options.groupIds)
|
|
86
|
-
const
|
|
87
|
+
const config = await resolveProfileApiClientConfig(options)
|
|
88
|
+
assertSignedIn(config)
|
|
89
|
+
const client = createCliSixbClient(config)
|
|
87
90
|
const result = unwrapSixbApiResult(
|
|
88
91
|
await createAuthPersonalAccessToken({
|
|
89
92
|
client,
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { resolveAgentTurnTimeoutMs } from "../lib/agent-turn-timeout"
|
|
2
2
|
import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
|
|
3
3
|
import { resolveRuntimeEntry } from "../lib/production"
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
runUntilSignal,
|
|
7
|
-
stopQuietly,
|
|
8
|
-
stopSixbProviders,
|
|
9
|
-
waitForWorkerFailure,
|
|
10
|
-
} from "../lib/runtime"
|
|
4
|
+
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
5
|
+
import { recordApiPublicOrigin, stopSixbProviders, waitForWorkerFailure } from "../lib/runtime"
|
|
11
6
|
import { assertShareableProviders } from "../lib/shareable-providers"
|
|
12
7
|
import { migrateStorageForRole } from "../lib/storage-migration"
|
|
13
8
|
import { resolveWorkerConcurrency } from "../lib/worker-concurrency"
|
package/src/commands/worker.tsx
CHANGED
|
@@ -2,13 +2,8 @@ import { resolveAgentTurnTimeoutMs } from "../lib/agent-turn-timeout"
|
|
|
2
2
|
import { SixbCliError } from "../lib/errors"
|
|
3
3
|
import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
|
|
4
4
|
import { resolveRuntimeEntry } from "../lib/production"
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
runUntilSignal,
|
|
8
|
-
stopQuietly,
|
|
9
|
-
stopSixbProviders,
|
|
10
|
-
waitForWorkerFailure,
|
|
11
|
-
} from "../lib/runtime"
|
|
5
|
+
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
6
|
+
import { recordApiPublicOrigin, stopSixbProviders, waitForWorkerFailure } from "../lib/runtime"
|
|
12
7
|
import { assertShareableProviders } from "../lib/shareable-providers"
|
|
13
8
|
import { migrateStorageForRole } from "../lib/storage-migration"
|
|
14
9
|
import { resolveSingleWorkerConcurrency } from "../lib/worker-concurrency"
|
package/src/index.tsx
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
wantsManagementJson,
|
|
13
13
|
} from "./lib/command-line"
|
|
14
14
|
import { errorMessage, SixbApiError } from "./lib/errors"
|
|
15
|
-
import { CommandHelpView, HelpView, renderCliError, renderStatic, VersionView } from "./ui"
|
|
16
15
|
|
|
17
16
|
const args = process.argv.slice(2)
|
|
18
17
|
|
|
@@ -73,12 +72,13 @@ async function readPackageVersion(): Promise<string> {
|
|
|
73
72
|
async function main(): Promise<void> {
|
|
74
73
|
const parsed = parseCliArgs(args)
|
|
75
74
|
if (parsed.kind === "version") {
|
|
76
|
-
|
|
75
|
+
const { renderVersion } = await import("./ui")
|
|
76
|
+
await renderVersion(VERSION)
|
|
77
77
|
return
|
|
78
78
|
}
|
|
79
79
|
if (parsed.kind === "help") {
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const { renderHelp } = await import("./ui")
|
|
81
|
+
await renderHelp(parsed.help)
|
|
82
82
|
return
|
|
83
83
|
}
|
|
84
84
|
if (parsed.kind === "instance") {
|
|
@@ -405,14 +405,11 @@ main().catch(async (error) => {
|
|
|
405
405
|
const exitCode = cliExitCode(error)
|
|
406
406
|
if (wantsManagementJson(args)) {
|
|
407
407
|
process.stderr.write(`${JSON.stringify({ error: cliErrorBody(error) })}\n`)
|
|
408
|
-
} else if (error instanceof CliUsageError) {
|
|
409
|
-
if (error.help.path.length === 0) {
|
|
410
|
-
await renderStatic(<HelpView errorMessage={error.message} />)
|
|
411
|
-
} else {
|
|
412
|
-
await renderStatic(<CommandHelpView help={error.help} errorMessage={error.message} />)
|
|
413
|
-
}
|
|
414
408
|
} else {
|
|
415
|
-
|
|
409
|
+
// Loaded on demand, and never through JSX here: see `renderHelp` in `./ui`.
|
|
410
|
+
const { renderCliError, renderHelp } = await import("./ui")
|
|
411
|
+
if (error instanceof CliUsageError) await renderHelp(error.help, error.message)
|
|
412
|
+
else await renderCliError(error)
|
|
416
413
|
}
|
|
417
414
|
process.exit(exitCode)
|
|
418
415
|
})
|
package/src/lib/dev-watch.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Dirent, watch } from "node:fs"
|
|
2
2
|
import { lstat, readdir } from "node:fs/promises"
|
|
3
3
|
import { join, resolve, sep } from "node:path"
|
|
4
|
+
import { isAgentContextPath } from "@sixb/core/internal/bootstrap"
|
|
4
5
|
|
|
5
6
|
const ignoredDirectories = new Set([
|
|
6
7
|
".sixb",
|
|
@@ -13,8 +14,11 @@ const ignoredDirectories = new Set([
|
|
|
13
14
|
".local",
|
|
14
15
|
])
|
|
15
16
|
const isAppSource = (path: string) => path.startsWith(`app${sep}`)
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
/** Project code, plus the non-code files the Agent reads (`SIXB.md`, `skills/`). */
|
|
18
|
+
export const isSource = (path: string) =>
|
|
19
|
+
/\.(?:[cm]?[jt]sx?|json|ya?ml|toml|css)$/.test(path) ||
|
|
20
|
+
path === "bun.lock" ||
|
|
21
|
+
isAgentContextPath(path.split(sep).join("/"))
|
|
18
22
|
const ignored = (path: string) => path.split(sep).some((part) => ignoredDirectories.has(part))
|
|
19
23
|
|
|
20
24
|
function missing(error: unknown): boolean {
|
package/src/lib/profiles.ts
CHANGED
|
@@ -52,7 +52,8 @@ export interface ResolvedProfile {
|
|
|
52
52
|
| "profile-environment"
|
|
53
53
|
| "current-profile"
|
|
54
54
|
| "default"
|
|
55
|
-
|
|
55
|
+
/** `"session"` is the sign-in `sixb login` saved on the profile; `"profile"`, a saved token. */
|
|
56
|
+
readonly tokenSource?: "--token" | "SIXB_API_TOKEN" | "SIXB_TOKEN" | "profile" | "session"
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
export function resolveConfigPath(options: ProfileStoreOptions = {}): string {
|
|
@@ -210,7 +211,7 @@ async function resolvedStoredProfile(
|
|
|
210
211
|
`[SixbCLI] The sign-in for profile '${profile}' has ended. Run \`sixb login ${stored.apiUrl} --profile ${profile}\` again.`
|
|
211
212
|
)
|
|
212
213
|
}
|
|
213
|
-
return { ...base, token, tokenSource: "
|
|
214
|
+
return { ...base, token, tokenSource: "session" }
|
|
214
215
|
}
|
|
215
216
|
return stored.token ? { ...base, tokenSource: "profile" } : base
|
|
216
217
|
}
|
package/src/lib/public-origin.ts
CHANGED
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
* worth removing — a bad origin should be refused once, by the first role that reads it.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
|
|
12
|
-
import type { LoadedSixbHost } from "./loadSixb"
|
|
13
|
-
|
|
14
11
|
/** An origin is scheme, host, and port, and nothing after them. */
|
|
15
12
|
export function normalizeOrigin(value: string, label: string): string {
|
|
16
13
|
let url: URL
|
|
@@ -44,16 +41,6 @@ export function configuredOrigin(
|
|
|
44
41
|
return configured === undefined ? null : normalizeOrigin(configured, label)
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
/**
|
|
48
|
-
* Tell a worker process's host where the API is reachable, so the code it runs can hand out URLs
|
|
49
|
-
* a third party will fetch (`blobs.createDownloadUrl()`). The API process needs no call: the
|
|
50
|
-
* server records the origin it serves. Without one, those calls fail and name the variable.
|
|
51
|
-
*/
|
|
52
|
-
export function recordApiPublicOrigin(sixb: LoadedSixbHost, value: string | undefined): void {
|
|
53
|
-
const origin = configuredOrigin(value, "SIXB_API_PUBLIC_ORIGIN", "API public origin")
|
|
54
|
-
if (origin) setApiPublicOrigin(sixb, origin)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
44
|
function nonblank(value: string | undefined): string | undefined {
|
|
58
45
|
return value?.trim() || undefined
|
|
59
46
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { appendFileSync } from "node:fs"
|
|
2
|
+
|
|
3
|
+
// Kept apart from `runtime.ts`, which imports every worker package: `atlas` and `app` serve static
|
|
4
|
+
// assets for as long as they run and must not hold that module graph to reuse these two helpers.
|
|
5
|
+
|
|
6
|
+
export async function stopQuietly(stopFn: (() => Promise<void>) | undefined | null): Promise<void> {
|
|
7
|
+
if (!stopFn) return
|
|
8
|
+
await stopFn().catch(() => {})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function runUntilSignal(onShutdown: () => Promise<void>): Promise<void> {
|
|
12
|
+
// Test-only readiness hook: e2e tests detect that a long-running role finished
|
|
13
|
+
// starting by watching for this marker. It avoids depending on Ink's rendered
|
|
14
|
+
// output, which is suppressed when stdout is not a TTY (e.g. under CI). Unset in
|
|
15
|
+
// production, so this is a no-op there.
|
|
16
|
+
const readyLog = process.env.SIXB_CLI_TEST_READY_LOG
|
|
17
|
+
if (readyLog) {
|
|
18
|
+
appendFileSync(readyLog, `${JSON.stringify({ type: "role:ready" })}\n`, "utf-8")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
await new Promise<void>((resolvePromise) => {
|
|
22
|
+
let shuttingDown = false
|
|
23
|
+
|
|
24
|
+
const shutdown = async () => {
|
|
25
|
+
if (shuttingDown) return
|
|
26
|
+
shuttingDown = true
|
|
27
|
+
await onShutdown()
|
|
28
|
+
resolvePromise()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
process.once("SIGINT", shutdown)
|
|
32
|
+
process.once("SIGTERM", shutdown)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RoleStartupPanel } from "../ui"
|
|
2
|
+
import { errorMessage, errorRemediation } from "./errors"
|
|
3
|
+
|
|
4
|
+
export interface RoleView {
|
|
5
|
+
startup(loading: {
|
|
6
|
+
readonly title: string
|
|
7
|
+
readonly subtitle: string
|
|
8
|
+
readonly status: string
|
|
9
|
+
}): RoleStartupPanel
|
|
10
|
+
error(error: unknown): Promise<void>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* How a long-running role reports itself: the Ink panels in a terminal, plain lines in a log.
|
|
15
|
+
*
|
|
16
|
+
* Ink's layout engine keeps about 45 MB for the life of the process once it is imported. `atlas`
|
|
17
|
+
* and `app` run under a supervisor and serve static files, so outside a terminal they never load
|
|
18
|
+
* it.
|
|
19
|
+
*
|
|
20
|
+
* Call this before the role sets NODE_ENV. Bun compiles JSX for the mode the process started in,
|
|
21
|
+
* and React loaded after the change cannot run it: the panels then render nothing, or throw. Ink
|
|
22
|
+
* stays out of logs for a second reason: its error panel could come out empty there.
|
|
23
|
+
*/
|
|
24
|
+
export async function loadRoleView(): Promise<RoleView> {
|
|
25
|
+
if (process.stdout.isTTY) {
|
|
26
|
+
const { renderCliError, renderRoleStartup } = await import("../ui")
|
|
27
|
+
return { startup: renderRoleStartup, error: renderCliError }
|
|
28
|
+
}
|
|
29
|
+
return { startup: printRoleStartup, error: printRoleError }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function printRoleStartup(loading: {
|
|
33
|
+
readonly title: string
|
|
34
|
+
readonly subtitle: string
|
|
35
|
+
}): RoleStartupPanel {
|
|
36
|
+
console.log(`${loading.title} (${loading.subtitle})`)
|
|
37
|
+
return {
|
|
38
|
+
started(view) {
|
|
39
|
+
const items = view.items.map((item) => `${item.label} ${item.value}`).join(", ")
|
|
40
|
+
console.log(`${view.title}: ${view.name}, ${view.serviceName} ${items}`)
|
|
41
|
+
},
|
|
42
|
+
unmount() {},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function printRoleError(error: unknown): Promise<void> {
|
|
47
|
+
console.error(errorMessage(error))
|
|
48
|
+
const remediation = errorRemediation(error)
|
|
49
|
+
if (remediation) console.error(remediation)
|
|
50
|
+
}
|
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,6 +84,16 @@ 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
98
|
await migrateStorage(sixb.storage, {
|
|
82
99
|
projectId: sixb.id,
|
|
@@ -187,25 +204,27 @@ export async function startOrchestratorRuntime(
|
|
|
187
204
|
* Startup order (consumers before producers):
|
|
188
205
|
* 1. RulesWorker (subscribes to ontology events)
|
|
189
206
|
* 2. ActionWorker (subscribes to events)
|
|
190
|
-
* 3.
|
|
191
|
-
* 4.
|
|
192
|
-
* 5.
|
|
193
|
-
* 6.
|
|
194
|
-
* 7.
|
|
195
|
-
* 8.
|
|
196
|
-
* 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)
|
|
197
215
|
*
|
|
198
216
|
* Shutdown order (producers before consumers):
|
|
199
|
-
* 1.
|
|
200
|
-
* 2.
|
|
201
|
-
* 3.
|
|
202
|
-
* 4.
|
|
203
|
-
* 5.
|
|
204
|
-
* 6.
|
|
205
|
-
* 7.
|
|
206
|
-
* 8.
|
|
207
|
-
* 9.
|
|
208
|
-
* 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)
|
|
209
228
|
*/
|
|
210
229
|
export async function startSixbRuntime(
|
|
211
230
|
sixb: LoadedSixbHost,
|
|
@@ -225,13 +244,14 @@ export async function startSixbRuntime(
|
|
|
225
244
|
const warnings: string[] = []
|
|
226
245
|
|
|
227
246
|
async function stop() {
|
|
247
|
+
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
248
|
+
await stopQuietly(() => options.api?.stop() ?? Promise.resolve())
|
|
228
249
|
await stopQuietly(() => schedulerRuntime?.stop() ?? Promise.resolve())
|
|
229
250
|
await stopQuietly(() => orchestratorRuntime?.stop() ?? Promise.resolve())
|
|
230
251
|
await stopQuietly(() => syncWorker?.stop() ?? Promise.resolve())
|
|
231
252
|
await stopQuietly(() => workflowWorker?.stop() ?? Promise.resolve())
|
|
232
253
|
await stopQuietly(() => pipelineWorker?.stop() ?? Promise.resolve())
|
|
233
254
|
await stopQuietly(() => projectionWorker?.stop() ?? Promise.resolve())
|
|
234
|
-
await stopQuietly(() => agentWorker?.stop() ?? Promise.resolve())
|
|
235
255
|
await stopQuietly(() => actionWorker?.stop() ?? Promise.resolve())
|
|
236
256
|
await stopQuietly(() => rulesRuntime?.stop() ?? Promise.resolve())
|
|
237
257
|
await stopSixbProviders(sixb)
|
|
@@ -250,6 +270,7 @@ export async function startSixbRuntime(
|
|
|
250
270
|
await actionWorker.start()
|
|
251
271
|
}
|
|
252
272
|
|
|
273
|
+
// Constructed here so a configuration error stops startup early; started last, below.
|
|
253
274
|
if (agentWorkerRequired(sixb)) {
|
|
254
275
|
agentWorker = new AgentWorker(sixb, {
|
|
255
276
|
apiBaseUrl: agentRuntimeRequired(sixb.definitions)
|
|
@@ -258,7 +279,6 @@ export async function startSixbRuntime(
|
|
|
258
279
|
concurrency: options.workerConcurrency?.agent,
|
|
259
280
|
turnTimeoutMs: options.agentTurnTimeoutMs,
|
|
260
281
|
})
|
|
261
|
-
await agentWorker.start()
|
|
262
282
|
}
|
|
263
283
|
|
|
264
284
|
const projectionCount = sixb.definitions.projections.list().length
|
|
@@ -294,6 +314,9 @@ export async function startSixbRuntime(
|
|
|
294
314
|
|
|
295
315
|
schedulerRuntime = await startSchedulerRuntime(sixb)
|
|
296
316
|
}
|
|
317
|
+
|
|
318
|
+
await options.api?.start()
|
|
319
|
+
await agentWorker?.start()
|
|
297
320
|
} catch (error) {
|
|
298
321
|
await stop()
|
|
299
322
|
throw error
|
|
@@ -345,28 +368,3 @@ function requireAgentApiBaseUrl(value: string | undefined): string {
|
|
|
345
368
|
}
|
|
346
369
|
return trimmed
|
|
347
370
|
}
|
|
348
|
-
|
|
349
|
-
export async function runUntilSignal(onShutdown: () => Promise<void>): Promise<void> {
|
|
350
|
-
// Test-only readiness hook: e2e tests detect that a long-running role finished
|
|
351
|
-
// starting by watching for this marker. It avoids depending on Ink's rendered
|
|
352
|
-
// output, which is suppressed when stdout is not a TTY (e.g. under CI). Unset in
|
|
353
|
-
// production, so this is a no-op there.
|
|
354
|
-
const readyLog = process.env.SIXB_CLI_TEST_READY_LOG
|
|
355
|
-
if (readyLog) {
|
|
356
|
-
appendFileSync(readyLog, `${JSON.stringify({ type: "role:ready" })}\n`, "utf-8")
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
await new Promise<void>((resolvePromise) => {
|
|
360
|
-
let shuttingDown = false
|
|
361
|
-
|
|
362
|
-
const shutdown = async () => {
|
|
363
|
-
if (shuttingDown) return
|
|
364
|
-
shuttingDown = true
|
|
365
|
-
await onShutdown()
|
|
366
|
-
resolvePromise()
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
process.once("SIGINT", shutdown)
|
|
370
|
-
process.once("SIGTERM", shutdown)
|
|
371
|
-
})
|
|
372
|
-
}
|