@sixb/cli 0.1.17 → 0.1.19
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 -4
- 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/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.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 +31 -20
- 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 +2 -31
- package/dist/lib/worker-registry.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 +15 -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 -19
- 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/command-line.ts +7 -11
- package/src/lib/deploy-release.ts +21 -4
- 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 +51 -60
- package/src/lib/worker-concurrency.ts +15 -38
- package/src/lib/worker-registry.ts +11 -35
- package/src/ui/index.tsx +46 -0
package/src/commands/app.tsx
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { basename } from "node:path"
|
|
1
2
|
import { type CustomAppDevServer, createCustomApp } from "@sixb/app"
|
|
2
3
|
import { resolveBrowserTopology, servedUrl } from "../lib/browser-topology"
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
builtAppOutdir,
|
|
6
|
+
hasBuiltCustomApp,
|
|
7
|
+
resolveProductionPaths,
|
|
8
|
+
resolveRuntimeEntry,
|
|
9
|
+
} from "../lib/production"
|
|
10
|
+
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
11
|
+
import { loadRoleView } from "../lib/role-view"
|
|
7
12
|
|
|
8
13
|
export interface AppOptions {
|
|
9
14
|
entry?: string
|
|
@@ -14,18 +19,22 @@ export interface AppOptions {
|
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
export async function runApp(options: AppOptions = {}) {
|
|
22
|
+
// Before NODE_ENV changes: see loadRoleView.
|
|
23
|
+
const view = await loadRoleView()
|
|
17
24
|
process.env.NODE_ENV = "production"
|
|
18
25
|
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
const entry = await resolveRuntimeEntry({ entry: options.entry })
|
|
27
|
+
const { projectRoot, buildOutdir } = await resolveProductionPaths(entry)
|
|
28
|
+
const app = view.startup({
|
|
29
|
+
title: "Starting sixb app",
|
|
30
|
+
subtitle: entry,
|
|
31
|
+
status: "Starting app",
|
|
32
|
+
})
|
|
23
33
|
|
|
24
|
-
let sixb: LoadedSixbHost | null = loaded.sixb
|
|
25
34
|
let customAppServer: CustomAppDevServer | null = null
|
|
26
35
|
|
|
27
36
|
try {
|
|
28
|
-
const appOutdir = builtAppOutdir(
|
|
37
|
+
const appOutdir = builtAppOutdir(buildOutdir)
|
|
29
38
|
if (!(await hasBuiltCustomApp(appOutdir))) {
|
|
30
39
|
throw new Error(
|
|
31
40
|
`[SixbCustomApp] No built app found in ${appOutdir}. Run \`sixb build\` before \`sixb app\`.`
|
|
@@ -41,10 +50,11 @@ export async function runApp(options: AppOptions = {}) {
|
|
|
41
50
|
})
|
|
42
51
|
|
|
43
52
|
const customApp = await createCustomApp({
|
|
44
|
-
rootDir:
|
|
53
|
+
rootDir: projectRoot,
|
|
45
54
|
apiBaseUrl: topology.apiPublicOrigin,
|
|
46
55
|
audience: "app",
|
|
47
|
-
authEnabled:
|
|
56
|
+
// No authEnabled: the page asks the API whether the project uses auth, so serving the
|
|
57
|
+
// bundle never loads the project.
|
|
48
58
|
})
|
|
49
59
|
customAppServer = await customApp.start({
|
|
50
60
|
host: topology.host,
|
|
@@ -52,34 +62,24 @@ export async function runApp(options: AppOptions = {}) {
|
|
|
52
62
|
outdir: appOutdir,
|
|
53
63
|
apiBaseUrl: topology.apiPublicOrigin,
|
|
54
64
|
audience: "app",
|
|
55
|
-
authEnabled: sixb.auth.isEnabled(),
|
|
56
65
|
})
|
|
57
66
|
|
|
58
|
-
app.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/>
|
|
65
|
-
)
|
|
67
|
+
app.started({
|
|
68
|
+
title: "Sixb app started",
|
|
69
|
+
name: basename(projectRoot),
|
|
70
|
+
serviceName: "Custom app",
|
|
71
|
+
items: [{ label: "URL", value: servedUrl(topology) }],
|
|
72
|
+
})
|
|
66
73
|
|
|
67
74
|
await runUntilSignal(async () => {
|
|
68
75
|
app.unmount()
|
|
69
76
|
console.log("\nShutting down app...")
|
|
70
77
|
await stopQuietly(() => customAppServer?.stop() ?? Promise.resolve())
|
|
71
|
-
if (sixb) {
|
|
72
|
-
await stopSixbProviders(sixb)
|
|
73
|
-
}
|
|
74
|
-
sixb = null
|
|
75
78
|
})
|
|
76
79
|
} catch (error) {
|
|
77
80
|
app.unmount()
|
|
78
81
|
await stopQuietly(() => customAppServer?.stop() ?? Promise.resolve())
|
|
79
|
-
|
|
80
|
-
await stopSixbProviders(sixb)
|
|
81
|
-
}
|
|
82
|
-
await renderCliError(error)
|
|
82
|
+
await view.error(error)
|
|
83
83
|
process.exit(1)
|
|
84
84
|
}
|
|
85
85
|
}
|
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,
|
|
@@ -143,7 +148,6 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
143
148
|
uiUrl={topology.atlasPublicOrigin}
|
|
144
149
|
appUrl={appUrl}
|
|
145
150
|
workers={[
|
|
146
|
-
{ type: "action", worker: runtime.actionWorker },
|
|
147
151
|
{ type: "agent", worker: runtime.agentWorker },
|
|
148
152
|
{ type: "projection", worker: runtime.projectionWorker },
|
|
149
153
|
{ type: "pipeline", worker: runtime.pipelineWorker },
|
|
@@ -172,7 +176,6 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
172
176
|
app.unmount()
|
|
173
177
|
await stopQuietly(() => customAppServer?.stop() ?? Promise.resolve())
|
|
174
178
|
await stopQuietly(() => atlasServer?.stop() ?? Promise.resolve())
|
|
175
|
-
await stopQuietly(() => server?.stop() ?? Promise.resolve())
|
|
176
179
|
await stopQuietly(() => runtime?.stop() ?? Promise.resolve())
|
|
177
180
|
if (sixb && !runtimeOwnsProviders) await stopSixbProviders(sixb)
|
|
178
181
|
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/command-line.ts
CHANGED
|
@@ -414,17 +414,13 @@ const commandTree: readonly CommandNode[] = [
|
|
|
414
414
|
options: ["entry", "no-migrate"],
|
|
415
415
|
}),
|
|
416
416
|
command("rules", "Start production rules runtime", { options: ["entry", "no-migrate"] }),
|
|
417
|
-
command(
|
|
418
|
-
"worker",
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
maximumPositionals: 1,
|
|
425
|
-
rootHelpLabel: "worker <type>",
|
|
426
|
-
}
|
|
427
|
-
),
|
|
417
|
+
command("worker", "Start production queue worker: sync, agent, pipeline, projection, workflow", {
|
|
418
|
+
usage: "sixb worker <sync|agent|pipeline|projection|workflow> [options]",
|
|
419
|
+
options: ["entry", "no-migrate", "api-public-origin", "agent-turn-timeout", "concurrency"],
|
|
420
|
+
minimumPositionals: 1,
|
|
421
|
+
maximumPositionals: 1,
|
|
422
|
+
rootHelpLabel: "worker <type>",
|
|
423
|
+
}),
|
|
428
424
|
command("worker-group", "Co-host multiple queue workers in one process (constrained resources)", {
|
|
429
425
|
usage: "sixb worker-group [types...] [options]",
|
|
430
426
|
options: ["entry", "no-migrate", "api-public-origin", "agent-turn-timeout", "concurrency"],
|
|
@@ -65,6 +65,16 @@ const API_READINESS_PATH = "/ready"
|
|
|
65
65
|
const DEFAULT_KILL_TIMEOUT_MS = 10_000
|
|
66
66
|
const DEFAULT_RESTART_DELAY_MS = 1_000
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The API and the workers run Actions in process: the API for the requests it serves, the workers
|
|
70
|
+
* for workflow action nodes. Stopping, each first waits up to 65 s for the Actions it is running
|
|
71
|
+
* and their effects (`ACTION_RUN_DRAIN_TIMEOUT_MS` in core), so a graceful restart must not kill it
|
|
72
|
+
* before. A literal keeps the runtime out of the deploy command; `deploy.test.ts` holds the two
|
|
73
|
+
* together.
|
|
74
|
+
*/
|
|
75
|
+
const ACTION_HOST_KILL_TIMEOUT_MS = 70_000
|
|
76
|
+
const ACTION_HOST_SERVICES: ReadonlySet<DeployServiceName> = new Set(["api", "workers"])
|
|
77
|
+
|
|
68
78
|
export interface DeployReleaseOptions {
|
|
69
79
|
/** The Bun version the project runs on, from its `packageManager` or the running Bun. */
|
|
70
80
|
readonly bunVersion: string
|
|
@@ -135,7 +145,11 @@ function sixbService(
|
|
|
135
145
|
env: { ...env, ...options.env },
|
|
136
146
|
instances: processOptions.instances ?? 1,
|
|
137
147
|
...(address ? { http: address } : {}),
|
|
138
|
-
process: releaseProcess(processOptions
|
|
148
|
+
process: releaseProcess(processOptions, {
|
|
149
|
+
killTimeoutMs: ACTION_HOST_SERVICES.has(service)
|
|
150
|
+
? ACTION_HOST_KILL_TIMEOUT_MS
|
|
151
|
+
: DEFAULT_KILL_TIMEOUT_MS,
|
|
152
|
+
}),
|
|
139
153
|
}
|
|
140
154
|
}
|
|
141
155
|
|
|
@@ -171,7 +185,7 @@ function projectProcess(
|
|
|
171
185
|
command: { program: "bun", args: [definition.entrypoint, ...(definition.args ?? [])] },
|
|
172
186
|
env: { ...env, ...definition.env },
|
|
173
187
|
instances: processOptions.instances ?? 1,
|
|
174
|
-
process: releaseProcess(processOptions),
|
|
188
|
+
process: releaseProcess(processOptions, { killTimeoutMs: DEFAULT_KILL_TIMEOUT_MS }),
|
|
175
189
|
}
|
|
176
190
|
}
|
|
177
191
|
|
|
@@ -237,9 +251,12 @@ function defaultDomain(config: DeployConfig, service: DeployHttpServiceName): st
|
|
|
237
251
|
return `${label}.${config.domain}`
|
|
238
252
|
}
|
|
239
253
|
|
|
240
|
-
function releaseProcess(
|
|
254
|
+
function releaseProcess(
|
|
255
|
+
options: DeployScalableProcessOptions,
|
|
256
|
+
defaults: { readonly killTimeoutMs: number }
|
|
257
|
+
): DeployReleaseProcess {
|
|
241
258
|
return {
|
|
242
|
-
killTimeoutMs: options.killTimeoutMs ??
|
|
259
|
+
killTimeoutMs: options.killTimeoutMs ?? defaults.killTimeoutMs,
|
|
243
260
|
restartDelayMs: options.restartDelayMs ?? DEFAULT_RESTART_DELAY_MS,
|
|
244
261
|
...(options.maxMemory === undefined ? {} : { maxMemory: options.maxMemory.trim() }),
|
|
245
262
|
}
|
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
|
+
}
|