@sixb/cli 0.1.16 → 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.
Files changed (57) hide show
  1. package/README.md +7 -3
  2. package/dist/commands/access-token-utils.d.ts +6 -0
  3. package/dist/commands/access-token-utils.d.ts.map +1 -1
  4. package/dist/commands/api.d.ts.map +1 -1
  5. package/dist/commands/app.d.ts.map +1 -1
  6. package/dist/commands/atlas.d.ts.map +1 -1
  7. package/dist/commands/db-migrate.d.ts.map +1 -1
  8. package/dist/commands/db-prepare.d.ts +4 -0
  9. package/dist/commands/db-prepare.d.ts.map +1 -0
  10. package/dist/commands/dev-runner.d.ts.map +1 -1
  11. package/dist/commands/orchestrator.d.ts.map +1 -1
  12. package/dist/commands/rules.d.ts.map +1 -1
  13. package/dist/commands/scheduler.d.ts.map +1 -1
  14. package/dist/commands/service-account.d.ts.map +1 -1
  15. package/dist/commands/token.d.ts.map +1 -1
  16. package/dist/commands/worker-group.d.ts.map +1 -1
  17. package/dist/commands/worker.d.ts.map +1 -1
  18. package/dist/lib/command-line.d.ts +1 -1
  19. package/dist/lib/command-line.d.ts.map +1 -1
  20. package/dist/lib/dev-watch.d.ts +2 -0
  21. package/dist/lib/dev-watch.d.ts.map +1 -1
  22. package/dist/lib/profiles.d.ts +2 -1
  23. package/dist/lib/profiles.d.ts.map +1 -1
  24. package/dist/lib/role-lifecycle.d.ts +3 -0
  25. package/dist/lib/role-lifecycle.d.ts.map +1 -0
  26. package/dist/lib/role-view.d.ts +22 -0
  27. package/dist/lib/role-view.d.ts.map +1 -0
  28. package/dist/lib/runtime.d.ts +34 -19
  29. package/dist/lib/runtime.d.ts.map +1 -1
  30. package/dist/lib/storage-migration.d.ts.map +1 -1
  31. package/dist/ui/index.d.ts +18 -0
  32. package/dist/ui/index.d.ts.map +1 -1
  33. package/package.json +17 -17
  34. package/src/commands/access-token-utils.ts +13 -0
  35. package/src/commands/api.tsx +2 -1
  36. package/src/commands/app.tsx +29 -29
  37. package/src/commands/atlas.tsx +23 -27
  38. package/src/commands/db-migrate.tsx +4 -1
  39. package/src/commands/db-prepare.ts +26 -0
  40. package/src/commands/dev-runner.tsx +22 -18
  41. package/src/commands/orchestrator.tsx +1 -2
  42. package/src/commands/rules.tsx +1 -2
  43. package/src/commands/scheduler.tsx +1 -2
  44. package/src/commands/service-account.tsx +4 -1
  45. package/src/commands/token.tsx +4 -1
  46. package/src/commands/worker-group.tsx +3 -6
  47. package/src/commands/worker.tsx +3 -6
  48. package/src/index.tsx +14 -11
  49. package/src/lib/command-line.ts +11 -1
  50. package/src/lib/dev-watch.ts +6 -2
  51. package/src/lib/github-ci.ts +16 -2
  52. package/src/lib/profiles.ts +3 -2
  53. package/src/lib/role-lifecycle.ts +34 -0
  54. package/src/lib/role-view.ts +50 -0
  55. package/src/lib/runtime.ts +57 -53
  56. package/src/lib/storage-migration.ts +12 -1
  57. package/src/ui/index.tsx +46 -0
@@ -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 type { LoadedSixbHost } from "../lib/loadSixb"
4
- import { builtAtlasOutdir, loadProductionSixb } from "../lib/production"
5
- import { runUntilSignal, stopQuietly, stopSixbProviders } from "../lib/runtime"
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 loaded = await loadProductionSixb({ entry: options.entry, role: "atlas" })
20
- const app = renderPersistent(
21
- <LoadingView title="Starting sixb atlas" subtitle={loaded.entry} status="Starting Atlas" />
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: sixb.auth.isEnabled(),
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(loaded.buildOutdir),
50
+ outdir: builtAtlasOutdir(buildOutdir),
46
51
  })
47
52
 
48
- app.rerender(
49
- <RoleView
50
- title="Sixb Atlas started"
51
- name={sixb.id}
52
- serviceName="Atlas"
53
- items={[{ label: "URL", value: servedUrl(topology) }]}
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
- if (sixb) {
70
- await stopSixbProviders(sixb)
71
- }
72
- await renderCliError(error)
68
+ await view.error(error)
73
69
  process.exit(1)
74
70
  }
75
71
  }
@@ -13,7 +13,10 @@ export async function runDbMigrate(options: DbMigrateOptions = {}) {
13
13
  const sixb = await loadSixbFromEntry(entry)
14
14
 
15
15
  try {
16
- const result = await migrateStorage(sixb.storage)
16
+ const result = await migrateStorage(sixb.storage, {
17
+ projectId: sixb.id,
18
+ ontology: sixb.definitions.ontology,
19
+ })
17
20
  await renderStatic(
18
21
  <DbMigrateView
19
22
  projectId={sixb.id}
@@ -0,0 +1,26 @@
1
+ import { migrateStorage, prepareObjectQueries } from "@sixb/core"
2
+ import { loadSixbFromEntry } from "../lib/loadSixb"
3
+ import { resolveRuntimeEntry } from "../lib/production"
4
+ import { stopSixbProviders } from "../lib/runtime"
5
+
6
+ export async function runDbPrepare(options: { entry?: string } = {}): Promise<void> {
7
+ const entry = await resolveRuntimeEntry(options)
8
+ const sixb = await loadSixbFromEntry(entry)
9
+ try {
10
+ console.info(
11
+ "[SixbCLI] Preparing ontology query indexes; backfills may temporarily block object writes."
12
+ )
13
+ await migrateStorage(sixb.storage)
14
+ const result = await prepareObjectQueries({
15
+ projectId: sixb.id,
16
+ ontology: sixb.definitions.ontology,
17
+ storage: sixb.storage,
18
+ })
19
+ console.info(
20
+ `[SixbCLI] Prepared ${result.objectTypes} object types and ${result.indexes} query indexes.`
21
+ )
22
+ for (const warning of result.warnings) console.warn(`[SixbCLI] ${warning}`)
23
+ } finally {
24
+ await stopSixbProviders(sixb)
25
+ }
26
+ }
@@ -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, type SixbServer } from "@sixb/server"
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 { startSixbRuntime, stopQuietly, stopSixbProviders } from "../lib/runtime"
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
- runtimeOwnsProviders = true
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
- await server.start()
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"
@@ -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 client = createCliSixbClient(await resolveProfileApiClientConfig(options))
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,
@@ -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 client = createCliSixbClient(await resolveProfileApiClientConfig(options))
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,12 +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
- runUntilSignal,
6
- stopQuietly,
7
- stopSixbProviders,
8
- waitForWorkerFailure,
9
- } from "../lib/runtime"
4
+ import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
5
+ import { recordApiPublicOrigin, stopSixbProviders, waitForWorkerFailure } from "../lib/runtime"
10
6
  import { assertShareableProviders } from "../lib/shareable-providers"
11
7
  import { migrateStorageForRole } from "../lib/storage-migration"
12
8
  import { resolveWorkerConcurrency } from "../lib/worker-concurrency"
@@ -55,6 +51,7 @@ export async function runWorkerGroup(options: WorkerGroupOptions = {}) {
55
51
 
56
52
  try {
57
53
  sixb = await loadSixbFromEntry(entry)
54
+ recordApiPublicOrigin(sixb, options.apiPublicOrigin)
58
55
 
59
56
  assertShareableProviders(sixb, "worker-group")
60
57
 
@@ -2,12 +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
- runUntilSignal,
7
- stopQuietly,
8
- stopSixbProviders,
9
- waitForWorkerFailure,
10
- } from "../lib/runtime"
5
+ import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
6
+ import { recordApiPublicOrigin, stopSixbProviders, waitForWorkerFailure } from "../lib/runtime"
11
7
  import { assertShareableProviders } from "../lib/shareable-providers"
12
8
  import { migrateStorageForRole } from "../lib/storage-migration"
13
9
  import { resolveSingleWorkerConcurrency } from "../lib/worker-concurrency"
@@ -46,6 +42,7 @@ export async function runWorker(options: WorkerOptions = {}) {
46
42
 
47
43
  try {
48
44
  sixb = await loadSixbFromEntry(entry)
45
+ recordApiPublicOrigin(sixb, options.apiPublicOrigin)
49
46
 
50
47
  assertShareableProviders(sixb, "worker")
51
48
 
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
- await renderStatic(<VersionView version={VERSION} />)
75
+ const { renderVersion } = await import("./ui")
76
+ await renderVersion(VERSION)
77
77
  return
78
78
  }
79
79
  if (parsed.kind === "help") {
80
- if (parsed.help.path.length === 0) await renderStatic(<HelpView />)
81
- else await renderStatic(<CommandHelpView help={parsed.help} />)
80
+ const { renderHelp } = await import("./ui")
81
+ await renderHelp(parsed.help)
82
82
  return
83
83
  }
84
84
  if (parsed.kind === "instance") {
@@ -298,6 +298,12 @@ async function main(): Promise<void> {
298
298
  break
299
299
  }
300
300
 
301
+ case "db:prepare": {
302
+ const { runDbPrepare } = await import("./commands/db-prepare")
303
+ await runDbPrepare({ entry: getFlag("entry") })
304
+ break
305
+ }
306
+
301
307
  case "db:migrate": {
302
308
  const { runDbMigrate } = await import("./commands/db-migrate")
303
309
  await runDbMigrate({ entry: getFlag("entry") })
@@ -399,14 +405,11 @@ main().catch(async (error) => {
399
405
  const exitCode = cliExitCode(error)
400
406
  if (wantsManagementJson(args)) {
401
407
  process.stderr.write(`${JSON.stringify({ error: cliErrorBody(error) })}\n`)
402
- } else if (error instanceof CliUsageError) {
403
- if (error.help.path.length === 0) {
404
- await renderStatic(<HelpView errorMessage={error.message} />)
405
- } else {
406
- await renderStatic(<CommandHelpView help={error.help} errorMessage={error.message} />)
407
- }
408
408
  } else {
409
- await renderCliError(error)
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)
410
413
  }
411
414
  process.exit(exitCode)
412
415
  })
@@ -168,6 +168,7 @@ export type LocalCommandId =
168
168
  | "typegen"
169
169
  | "build"
170
170
  | "db:migrate"
171
+ | "db:prepare"
171
172
  | "lake:check"
172
173
  | "lake:cleanup"
173
174
  | "deploy"
@@ -437,8 +438,17 @@ const commandTree: readonly CommandNode[] = [
437
438
  {
438
439
  name: "db",
439
440
  summary: "Manage runtime storage",
440
- usage: "sixb db <migrate>",
441
+ usage: "sixb db <migrate|prepare>",
441
442
  children: [
443
+ command(
444
+ "db:prepare",
445
+ "Prepare ontology query indexes and exact aggregates (may block writes)",
446
+ {
447
+ path: ["db", "prepare"],
448
+ options: ["entry"],
449
+ rootHelpLabel: "db prepare",
450
+ }
451
+ ),
442
452
  command("db:migrate", "Run adapter-owned database migrations ahead of a role", {
443
453
  path: ["db", "migrate"],
444
454
  options: ["entry"],
@@ -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
- const isSource = (path: string) =>
17
- /\.(?:[cm]?[jt]sx?|json|ya?ml|toml|css)$/.test(path) || path === "bun.lock"
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 {
@@ -215,7 +215,7 @@ async function gh(
215
215
  options: { readonly cwd?: string; readonly input?: string } = {}
216
216
  ): Promise<string> {
217
217
  try {
218
- return await run(["gh", ...args], options)
218
+ return await run(["gh", ...args], { ...options, env: ghEnvironment() })
219
219
  } catch (error) {
220
220
  const reason = error instanceof Error ? error.message : String(error)
221
221
  throw new SixbCliError(`[SixbDeploy] gh ${args.slice(0, 2).join(" ")} failed: ${reason}`, {
@@ -226,12 +226,26 @@ async function gh(
226
226
  }
227
227
  }
228
228
 
229
+ /**
230
+ * Bun loads the project's `.env` into this process, and a connector's `GITHUB_TOKEN` there would
231
+ * take precedence over the user's `gh auth login`. `GH_TOKEN` stays: it is gh's explicit override.
232
+ */
233
+ function ghEnvironment(): Record<string, string | undefined> {
234
+ const { GITHUB_TOKEN: _projectToken, ...env } = process.env
235
+ return env
236
+ }
237
+
229
238
  async function run(
230
239
  command: readonly string[],
231
- options: { readonly cwd?: string; readonly input?: string }
240
+ options: {
241
+ readonly cwd?: string
242
+ readonly input?: string
243
+ readonly env?: Record<string, string | undefined>
244
+ }
232
245
  ): Promise<string> {
233
246
  const child = Bun.spawn([...command], {
234
247
  cwd: options.cwd,
248
+ ...(options.env === undefined ? {} : { env: options.env }),
235
249
  stdin: options.input === undefined ? "ignore" : new Blob([options.input]),
236
250
  stdout: "pipe",
237
251
  stderr: "pipe",
@@ -52,7 +52,8 @@ export interface ResolvedProfile {
52
52
  | "profile-environment"
53
53
  | "current-profile"
54
54
  | "default"
55
- readonly tokenSource?: "--token" | "SIXB_API_TOKEN" | "SIXB_TOKEN" | "profile"
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: "profile" }
214
+ return { ...base, token, tokenSource: "session" }
214
215
  }
215
216
  return stored.token ? { ...base, tokenSource: "profile" } : base
216
217
  }
@@ -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
+ }