@sixb/cli 0.1.25 → 0.2.0
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 +5 -5
- package/dist/commands/agent.d.ts +16 -0
- package/dist/commands/agent.d.ts.map +1 -0
- 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 +0 -1
- package/dist/commands/dev-runner.d.ts.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/env.d.ts +31 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/worker-group.d.ts +0 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts +0 -1
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +41 -6
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.d.ts +2 -0
- package/dist/lib/deploy-release.d.ts.map +1 -1
- package/dist/lib/deploy-source.d.ts +2 -0
- package/dist/lib/deploy-source.d.ts.map +1 -1
- package/dist/lib/env-config.d.ts +17 -0
- package/dist/lib/env-config.d.ts.map +1 -0
- package/dist/lib/env-file.d.ts +16 -0
- package/dist/lib/env-file.d.ts.map +1 -0
- package/dist/lib/github-ci.d.ts.map +1 -1
- package/dist/lib/hidden-prompt.d.ts +19 -0
- package/dist/lib/hidden-prompt.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts +0 -1
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +0 -1
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/tui/app.d.ts +27 -0
- package/dist/tui/app.d.ts.map +1 -0
- package/dist/tui/brand.d.ts +7 -0
- package/dist/tui/brand.d.ts.map +1 -0
- package/dist/tui/computer.d.ts +8 -0
- package/dist/tui/computer.d.ts.map +1 -0
- package/dist/tui/connection.d.ts +45 -0
- package/dist/tui/connection.d.ts.map +1 -0
- package/dist/tui/context.d.ts +13 -0
- package/dist/tui/context.d.ts.map +1 -0
- package/dist/tui/format.d.ts +118 -0
- package/dist/tui/format.d.ts.map +1 -0
- package/dist/tui/index.d.ts +12 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/markdown.d.ts +18 -0
- package/dist/tui/markdown.d.ts.map +1 -0
- package/dist/tui/palette.d.ts +25 -0
- package/dist/tui/palette.d.ts.map +1 -0
- package/dist/tui/parts.d.ts +74 -0
- package/dist/tui/parts.d.ts.map +1 -0
- package/dist/tui/runner.d.ts +75 -0
- package/dist/tui/runner.d.ts.map +1 -0
- package/dist/tui/settings.d.ts +56 -0
- package/dist/tui/settings.d.ts.map +1 -0
- package/dist/tui/slash.d.ts +14 -0
- package/dist/tui/slash.d.ts.map +1 -0
- package/dist/tui/theme.d.ts +39 -0
- package/dist/tui/theme.d.ts.map +1 -0
- package/dist/tui/transcript.d.ts +52 -0
- package/dist/tui/transcript.d.ts.map +1 -0
- package/dist/tui/ui.d.ts +42 -0
- package/dist/tui/ui.d.ts.map +1 -0
- package/dist/ui/deploy-screens.d.ts +3 -1
- package/dist/ui/deploy-screens.d.ts.map +1 -1
- package/dist/ui/env-screens.d.ts +37 -0
- package/dist/ui/env-screens.d.ts.map +1 -0
- package/package.json +19 -17
- package/src/commands/agent.ts +344 -0
- package/src/commands/api.ts +2 -1
- package/src/commands/check.ts +5 -1
- package/src/commands/deploy.ts +29 -3
- package/src/commands/dev-runner.ts +3 -5
- package/src/commands/dev.ts +3 -0
- package/src/commands/env.ts +422 -0
- package/src/commands/worker-group.ts +0 -4
- package/src/commands/worker.ts +0 -4
- package/src/index.tsx +95 -5
- package/src/lib/command-line.ts +111 -16
- package/src/lib/deploy-release.ts +3 -11
- package/src/lib/deploy-source.ts +10 -0
- package/src/lib/env-config.ts +96 -0
- package/src/lib/env-file.ts +104 -0
- package/src/lib/github-ci.ts +3 -1
- package/src/lib/hidden-prompt.ts +97 -0
- package/src/lib/runtime.ts +0 -2
- package/src/lib/worker-registry.ts +0 -2
- package/src/tui/app.tsx +1334 -0
- package/src/tui/brand.tsx +51 -0
- package/src/tui/computer.ts +91 -0
- package/src/tui/connection.ts +149 -0
- package/src/tui/context.tsx +149 -0
- package/src/tui/format.ts +477 -0
- package/src/tui/index.tsx +364 -0
- package/src/tui/markdown.ts +91 -0
- package/src/tui/palette.tsx +183 -0
- package/src/tui/parts.ts +274 -0
- package/src/tui/runner.ts +256 -0
- package/src/tui/settings.ts +176 -0
- package/src/tui/slash.ts +32 -0
- package/src/tui/theme.ts +111 -0
- package/src/tui/transcript.tsx +637 -0
- package/src/tui/ui.tsx +177 -0
- package/src/ui/deploy-screens.ts +12 -1
- package/src/ui/env-screens.ts +81 -0
- package/dist/lib/agent-turn-timeout.d.ts +0 -8
- package/dist/lib/agent-turn-timeout.d.ts.map +0 -1
- package/src/lib/agent-turn-timeout.ts +0 -46
package/src/lib/command-line.ts
CHANGED
|
@@ -34,11 +34,6 @@ export const CLI_OPTION_DEFINITIONS = {
|
|
|
34
34
|
summary: "Public API origin",
|
|
35
35
|
kind: "string",
|
|
36
36
|
},
|
|
37
|
-
"agent-turn-timeout": {
|
|
38
|
-
syntax: "--agent-turn-timeout <duration>",
|
|
39
|
-
summary: "Agent turn wall-clock budget (default: 10m)",
|
|
40
|
-
kind: "string",
|
|
41
|
-
},
|
|
42
37
|
concurrency: {
|
|
43
38
|
syntax: "--concurrency <value>",
|
|
44
39
|
summary: "Concurrent jobs: count for worker; repeat type=count for dev/worker-group",
|
|
@@ -109,6 +104,21 @@ export const CLI_OPTION_DEFINITIONS = {
|
|
|
109
104
|
},
|
|
110
105
|
group: { syntax: "--group <id>", summary: "Assignable token group; may repeat", kind: "string" },
|
|
111
106
|
json: { syntax: "--json", summary: "Print JSON instead of formatted output", kind: "boolean" },
|
|
107
|
+
thread: {
|
|
108
|
+
syntax: "--thread <id>",
|
|
109
|
+
summary: "Continue this conversation instead of starting one",
|
|
110
|
+
kind: "string",
|
|
111
|
+
},
|
|
112
|
+
cloud: {
|
|
113
|
+
syntax: "--cloud",
|
|
114
|
+
summary: "Run a new conversation in the cloud, not on this computer",
|
|
115
|
+
kind: "boolean",
|
|
116
|
+
},
|
|
117
|
+
"approval-mode": {
|
|
118
|
+
syntax: "--approval-mode <manual|accept-edits|auto>",
|
|
119
|
+
summary: "What this turn may do without asking (default: your mode in the conversation)",
|
|
120
|
+
kind: "string",
|
|
121
|
+
},
|
|
112
122
|
outdir: { syntax: "--outdir <path>", summary: "Build output directory", kind: "string" },
|
|
113
123
|
ref: {
|
|
114
124
|
syntax: "--ref <ref>",
|
|
@@ -116,6 +126,31 @@ export const CLI_OPTION_DEFINITIONS = {
|
|
|
116
126
|
kind: "string",
|
|
117
127
|
},
|
|
118
128
|
follow: { syntax: "--follow", summary: "Keep printing new log lines", kind: "boolean" },
|
|
129
|
+
env: {
|
|
130
|
+
syntax: "--env <dev|prod>",
|
|
131
|
+
summary: "Environment (default for pull: dev)",
|
|
132
|
+
kind: "string",
|
|
133
|
+
},
|
|
134
|
+
dev: {
|
|
135
|
+
syntax: "--dev <file>",
|
|
136
|
+
summary: "The file holding the current dev values",
|
|
137
|
+
kind: "string",
|
|
138
|
+
},
|
|
139
|
+
prod: {
|
|
140
|
+
syntax: "--prod <file>",
|
|
141
|
+
summary: "The file holding the current prod values",
|
|
142
|
+
kind: "string",
|
|
143
|
+
},
|
|
144
|
+
"token-file": {
|
|
145
|
+
syntax: "--token-file <path>",
|
|
146
|
+
summary: "Read the source's token from this file, as a server does",
|
|
147
|
+
kind: "string",
|
|
148
|
+
},
|
|
149
|
+
force: {
|
|
150
|
+
syntax: "--force",
|
|
151
|
+
summary: "Replace a hand-written .env, losing what the source doesn't have",
|
|
152
|
+
kind: "boolean",
|
|
153
|
+
},
|
|
119
154
|
admin: {
|
|
120
155
|
syntax: "--admin <login>",
|
|
121
156
|
summary: "Login with sudo that prepares the server (default: root)",
|
|
@@ -155,6 +190,7 @@ export const CLI_OPTION_DEFINITIONS = {
|
|
|
155
190
|
|
|
156
191
|
export type CliOptionName = keyof typeof CLI_OPTION_DEFINITIONS
|
|
157
192
|
export type LocalCommandId =
|
|
193
|
+
| "agent"
|
|
158
194
|
| "dev"
|
|
159
195
|
| "api"
|
|
160
196
|
| "app"
|
|
@@ -198,6 +234,10 @@ export type LocalCommandId =
|
|
|
198
234
|
| "deploy:access:list"
|
|
199
235
|
| "deploy:access:add"
|
|
200
236
|
| "deploy:access:remove"
|
|
237
|
+
| "env:init"
|
|
238
|
+
| "env:pull"
|
|
239
|
+
| "env:set"
|
|
240
|
+
| "env:status"
|
|
201
241
|
| "init"
|
|
202
242
|
|
|
203
243
|
interface CommandNode {
|
|
@@ -250,6 +290,11 @@ const INSTANCE_SUMMARIES = {
|
|
|
250
290
|
"workflow-runs": "Inspect workflow execution history",
|
|
251
291
|
users: "List and search project members",
|
|
252
292
|
models: "List the project's models and their prices",
|
|
293
|
+
datasets: "Read datasets, their versions and rows",
|
|
294
|
+
syncs: "List the syncs you may run",
|
|
295
|
+
"sync-runs": "Inspect sync run history",
|
|
296
|
+
pipelines: "List the pipelines you may run",
|
|
297
|
+
"pipeline-runs": "Inspect pipeline runs and their steps",
|
|
253
298
|
} as const satisfies Record<InstanceCommand, string>
|
|
254
299
|
|
|
255
300
|
const instanceNodes: readonly CommandNode[] = INSTANCE_COMMANDS.map((name) => ({
|
|
@@ -270,7 +315,6 @@ const commandTree: readonly CommandNode[] = [
|
|
|
270
315
|
"api-port",
|
|
271
316
|
"api-host",
|
|
272
317
|
"api-public-origin",
|
|
273
|
-
"agent-turn-timeout",
|
|
274
318
|
"concurrency",
|
|
275
319
|
"vector-concurrency",
|
|
276
320
|
"subagent-concurrency",
|
|
@@ -307,6 +351,15 @@ const commandTree: readonly CommandNode[] = [
|
|
|
307
351
|
command("status", "Check the current profile's connection", {
|
|
308
352
|
options: [...CONNECTION_OPTIONS, "json"],
|
|
309
353
|
}),
|
|
354
|
+
command("agent", "Ask the agent; it works in this folder", {
|
|
355
|
+
usage: 'sixb agent "<message>" [--thread <id>] [--cloud] [--approval-mode <mode>] [--json]',
|
|
356
|
+
// No --token: a command the agent runs could read it from this one's arguments. A token comes
|
|
357
|
+
// from a profile or SIXB_API_TOKEN.
|
|
358
|
+
options: ["api-url", "profile", "thread", "cloud", "approval-mode", "json"],
|
|
359
|
+
// The message, quoted or not; standard input when there is none.
|
|
360
|
+
maximumPositionals: Number.POSITIVE_INFINITY,
|
|
361
|
+
rootHelpLabel: 'agent "<message>"',
|
|
362
|
+
}),
|
|
310
363
|
{
|
|
311
364
|
name: "profile",
|
|
312
365
|
summary: "List, show, or switch saved profiles",
|
|
@@ -431,7 +484,6 @@ const commandTree: readonly CommandNode[] = [
|
|
|
431
484
|
"entry",
|
|
432
485
|
"no-migrate",
|
|
433
486
|
"api-public-origin",
|
|
434
|
-
"agent-turn-timeout",
|
|
435
487
|
"concurrency",
|
|
436
488
|
"vector-concurrency",
|
|
437
489
|
"subagent-concurrency",
|
|
@@ -447,7 +499,6 @@ const commandTree: readonly CommandNode[] = [
|
|
|
447
499
|
"entry",
|
|
448
500
|
"no-migrate",
|
|
449
501
|
"api-public-origin",
|
|
450
|
-
"agent-turn-timeout",
|
|
451
502
|
"concurrency",
|
|
452
503
|
"vector-concurrency",
|
|
453
504
|
"subagent-concurrency",
|
|
@@ -573,6 +624,35 @@ const commandTree: readonly CommandNode[] = [
|
|
|
573
624
|
},
|
|
574
625
|
],
|
|
575
626
|
},
|
|
627
|
+
{
|
|
628
|
+
name: "env",
|
|
629
|
+
summary: "Keep the project's environment variables in one place",
|
|
630
|
+
usage: "sixb env <init|pull|set|status>",
|
|
631
|
+
rootHelpLabel: "env ...",
|
|
632
|
+
children: [
|
|
633
|
+
command("env:init", "Move a project's values to its source and write sixb.env.ts", {
|
|
634
|
+
path: ["env", "init"],
|
|
635
|
+
usage: "sixb env init <project> [--dev <file>] [--prod <file>]",
|
|
636
|
+
options: ["dev", "prod"],
|
|
637
|
+
minimumPositionals: 1,
|
|
638
|
+
maximumPositionals: 1,
|
|
639
|
+
}),
|
|
640
|
+
command("env:pull", "Write .env from the project's source", {
|
|
641
|
+
path: ["env", "pull"],
|
|
642
|
+
options: ["env", "token-file", "force"],
|
|
643
|
+
}),
|
|
644
|
+
command("env:set", "Set one value in the project's source", {
|
|
645
|
+
path: ["env", "set"],
|
|
646
|
+
usage: "sixb env set <name> --env <dev|prod>",
|
|
647
|
+
options: ["env"],
|
|
648
|
+
minimumPositionals: 1,
|
|
649
|
+
maximumPositionals: 1,
|
|
650
|
+
}),
|
|
651
|
+
command("env:status", "Show which variables have values, without showing them", {
|
|
652
|
+
path: ["env", "status"],
|
|
653
|
+
}),
|
|
654
|
+
],
|
|
655
|
+
},
|
|
576
656
|
command("init", "Create a Sixb project in a directory", {
|
|
577
657
|
usage: "sixb init [dir]",
|
|
578
658
|
maximumPositionals: 1,
|
|
@@ -622,7 +702,7 @@ export class CliUsageError extends Error {
|
|
|
622
702
|
|
|
623
703
|
export const ROOT_HELP: CliHelp = {
|
|
624
704
|
path: [],
|
|
625
|
-
usage: "sixb
|
|
705
|
+
usage: "sixb [command] [options]",
|
|
626
706
|
summary: "Real-time digital twin framework",
|
|
627
707
|
commands: rootHelpItems(commandTree),
|
|
628
708
|
// Each command lists its own options; the root names the ones most commands share. Its last
|
|
@@ -640,7 +720,8 @@ const ROOT_HELP_GROUP_COMMANDS: readonly {
|
|
|
640
720
|
/** Listed by name only: each has its own help. */
|
|
641
721
|
readonly compact?: boolean
|
|
642
722
|
}[] = [
|
|
643
|
-
{ title: "
|
|
723
|
+
{ title: "Agent", names: ["agent"] },
|
|
724
|
+
{ title: "Develop", names: ["init", "dev", "env", "check", "typegen", "build"] },
|
|
644
725
|
{ title: "Deploy", names: ["deploy", "desktop"] },
|
|
645
726
|
{
|
|
646
727
|
title: "Run in production",
|
|
@@ -664,9 +745,15 @@ export const ROOT_HELP_GROUPS: readonly {
|
|
|
664
745
|
const groups = ROOT_HELP_GROUP_COMMANDS.map((group) => ({
|
|
665
746
|
title: group.title,
|
|
666
747
|
...(group.compact ? { compact: true } : {}),
|
|
667
|
-
items:
|
|
668
|
-
|
|
669
|
-
|
|
748
|
+
items: [
|
|
749
|
+
// `sixb` alone is no command, but it is how most people meet the agent.
|
|
750
|
+
...(group.title === "Agent"
|
|
751
|
+
? [{ label: "(no command)", value: "Open Sixb here: talk to the agent in this folder" }]
|
|
752
|
+
: []),
|
|
753
|
+
...rootHelpItems(
|
|
754
|
+
group.names.flatMap((name) => commandTree.filter((node) => node.name === name))
|
|
755
|
+
),
|
|
756
|
+
],
|
|
670
757
|
}))
|
|
671
758
|
// A command added without a group still shows up.
|
|
672
759
|
return ungrouped.length > 0
|
|
@@ -717,9 +804,17 @@ export function repeatedOption(options: ParsedCliOptions, name: CliOptionName):
|
|
|
717
804
|
|
|
718
805
|
export function wantsManagementJson(args: readonly string[]): boolean {
|
|
719
806
|
return (
|
|
720
|
-
[
|
|
721
|
-
|
|
722
|
-
|
|
807
|
+
[
|
|
808
|
+
"login",
|
|
809
|
+
"logout",
|
|
810
|
+
"status",
|
|
811
|
+
"profile",
|
|
812
|
+
"token",
|
|
813
|
+
"service-account",
|
|
814
|
+
"deploy",
|
|
815
|
+
"agent",
|
|
816
|
+
].includes(args[0] ?? "") &&
|
|
817
|
+
args.some((argument) => argument === "--json" || argument.startsWith("--json="))
|
|
723
818
|
)
|
|
724
819
|
}
|
|
725
820
|
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
isDeployHttpService,
|
|
18
18
|
isDeploySingletonService,
|
|
19
19
|
} from "@sixb/core/internal/deploy"
|
|
20
|
-
import { parseAgentTurnTimeoutMs } from "./agent-turn-timeout"
|
|
21
20
|
import { SixbCliError } from "./errors"
|
|
22
21
|
import { type ProductionRole, productionRoleFacts } from "./production-roles"
|
|
23
22
|
|
|
@@ -75,6 +74,8 @@ const ACTION_HOST_SERVICES: ReadonlySet<DeployServiceName> = new Set(["api", "wo
|
|
|
75
74
|
export interface DeployReleaseOptions {
|
|
76
75
|
/** The Bun version the project runs on, from its `packageManager` or the running Bun. */
|
|
77
76
|
readonly bunVersion: string
|
|
77
|
+
/** Whether a deploy writes the target's `.env` from the project's source. */
|
|
78
|
+
readonly envFromSource?: boolean
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
export function buildDeployRelease(
|
|
@@ -99,6 +100,7 @@ export function buildDeployRelease(
|
|
|
99
100
|
bunVersion: options.bunVersion,
|
|
100
101
|
env,
|
|
101
102
|
steps: {
|
|
103
|
+
...(options.envFromSource ? { env: sixb("env", "pull", "--env", "prod") } : {}),
|
|
102
104
|
build: [sixb("build")],
|
|
103
105
|
// The order `docs/deployment` gives. `check` probes every provider, so a broker or queue
|
|
104
106
|
// the services cannot reach fails the deploy instead of passing for healthy; it needs the
|
|
@@ -170,16 +172,6 @@ function workerGroupArgs(options: DeployWorkersConfig): string[] {
|
|
|
170
172
|
const types = options.types === undefined || options.types === "all" ? [] : options.types
|
|
171
173
|
const args = ["worker-group", ...types]
|
|
172
174
|
|
|
173
|
-
if (options.agentTurnTimeout !== undefined) {
|
|
174
|
-
if (parseAgentTurnTimeoutMs(options.agentTurnTimeout) === null) {
|
|
175
|
-
throw new SixbCliError(
|
|
176
|
-
`[SixbDeploy] services.workers.agentTurnTimeout '${options.agentTurnTimeout}' is not a ` +
|
|
177
|
-
"duration.",
|
|
178
|
-
{ remediation: 'Use a positive duration such as "30s", "10m", or "1h".' }
|
|
179
|
-
)
|
|
180
|
-
}
|
|
181
|
-
args.push("--agent-turn-timeout", options.agentTurnTimeout)
|
|
182
|
-
}
|
|
183
175
|
for (const [workerType, concurrency] of Object.entries(options.concurrency ?? {})) {
|
|
184
176
|
args.push("--concurrency", `${workerType}=${concurrency}`)
|
|
185
177
|
}
|
package/src/lib/deploy-source.ts
CHANGED
|
@@ -171,6 +171,16 @@ function archive(repo: string, commit: string): ReadableStream<Uint8Array> {
|
|
|
171
171
|
})
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
/** Whether a commit being deployed has this file in the project's directory. */
|
|
175
|
+
export async function commitHasProjectFile(
|
|
176
|
+
projectDir: string,
|
|
177
|
+
source: Pick<DeploySource, "commit" | "projectPath">,
|
|
178
|
+
file: string
|
|
179
|
+
): Promise<boolean> {
|
|
180
|
+
const root = await git(projectDir, ["rev-parse", "--show-toplevel"])
|
|
181
|
+
return isFile(root, source.commit, posix.join(source.projectPath, file))
|
|
182
|
+
}
|
|
183
|
+
|
|
174
184
|
async function isFile(root: string, commit: string, path: string): Promise<boolean> {
|
|
175
185
|
return git(root, ["cat-file", "-e", `${commit}:${path}`])
|
|
176
186
|
.then(() => true)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { resolve } from "node:path"
|
|
2
|
+
import { pathToFileURL } from "node:url"
|
|
3
|
+
import type { EnvConfig, EnvName, EnvVarRule } from "@sixb/core/env"
|
|
4
|
+
import { SixbCliError } from "./errors"
|
|
5
|
+
|
|
6
|
+
export const ENV_CONFIG_FILE = "sixb.env.ts"
|
|
7
|
+
|
|
8
|
+
export const VAR_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/
|
|
9
|
+
const VAR_RULES: ReadonlySet<unknown> = new Set(["required", "prod", "optional"])
|
|
10
|
+
|
|
11
|
+
/** Loads `sixb.env.ts` from the project directory. A project without one has no declared names. */
|
|
12
|
+
export async function loadEnvConfig(cwd = process.cwd()): Promise<EnvConfig | null> {
|
|
13
|
+
const path = resolve(cwd, ENV_CONFIG_FILE)
|
|
14
|
+
if (!(await Bun.file(path).exists())) return null
|
|
15
|
+
|
|
16
|
+
const module = (await import(pathToFileURL(path).href)) as { readonly default?: unknown }
|
|
17
|
+
if (module.default === undefined) {
|
|
18
|
+
throw new SixbCliError(`[SixbEnv] ${path} has no default export.`, {
|
|
19
|
+
remediation: "Export the variables: `export default defineEnv({ vars: { ... } })`.",
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
return validateEnvConfig(module.default)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function validateEnvConfig(value: unknown): EnvConfig {
|
|
26
|
+
const { source, vars } = (value ?? {}) as { readonly source?: unknown; readonly vars?: unknown }
|
|
27
|
+
if (typeof vars !== "object" || vars === null || Array.isArray(vars)) {
|
|
28
|
+
throw new SixbCliError(`[SixbEnv] ${ENV_CONFIG_FILE} must set \`vars\`.`, {
|
|
29
|
+
remediation: 'Name each variable with a rule: `vars: { DATABASE_URL: "required" }`.',
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const [name, rule] of Object.entries(vars)) {
|
|
34
|
+
if (!VAR_NAME_PATTERN.test(name)) {
|
|
35
|
+
throw new SixbCliError(`[SixbEnv] "${name}" in ${ENV_CONFIG_FILE} is not a variable name.`)
|
|
36
|
+
}
|
|
37
|
+
if (!VAR_RULES.has(rule)) {
|
|
38
|
+
throw new SixbCliError(
|
|
39
|
+
`[SixbEnv] ${name} in ${ENV_CONFIG_FILE} must be "required", "prod", or "optional".`
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (source !== undefined && !isEnvSource(source)) {
|
|
44
|
+
throw new SixbCliError(`[SixbEnv] \`source\` in ${ENV_CONFIG_FILE} is not a source.`, {
|
|
45
|
+
remediation: 'Use a source, such as `doppler({ project: "shop" })` from @sixb/env-doppler.',
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
return value as EnvConfig
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isEnvSource(value: unknown): boolean {
|
|
52
|
+
const candidate = value as Record<string, unknown> | null
|
|
53
|
+
return ["names", "read", "write", "createServerToken"].every(
|
|
54
|
+
(method) => typeof candidate?.[method] === "function"
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The names `env` must have a value for and doesn't. An empty value counts as none. */
|
|
59
|
+
export function missingEnvVars(
|
|
60
|
+
config: EnvConfig,
|
|
61
|
+
values: Readonly<Record<string, string | undefined>>,
|
|
62
|
+
env: EnvName
|
|
63
|
+
): string[] {
|
|
64
|
+
return Object.entries(config.vars)
|
|
65
|
+
.filter(([name, rule]) => envVarNeeded(rule, env) && !values[name])
|
|
66
|
+
.map(([name]) => name)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Whether a variable with this rule must have a value in `env`. */
|
|
70
|
+
export function envVarNeeded(rule: EnvVarRule, env: EnvName): boolean {
|
|
71
|
+
return rule === "required" || (rule === "prod" && env === "prod")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The sentence every command uses to name what is missing. */
|
|
75
|
+
export function missingEnvSentence(names: readonly string[]): string {
|
|
76
|
+
return `Missing ${names.join(", ")}, which ${ENV_CONFIG_FILE} requires.`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Stops a command that is about to run the project without a variable it declares. */
|
|
80
|
+
export async function assertDeclaredEnv(cwd: string): Promise<void> {
|
|
81
|
+
const config = await loadEnvConfig(cwd)
|
|
82
|
+
if (!config) return
|
|
83
|
+
|
|
84
|
+
const env = process.env.NODE_ENV === "production" ? "prod" : "dev"
|
|
85
|
+
const missing = missingEnvVars(config, process.env, env)
|
|
86
|
+
if (missing.length > 0) throw missingEnvError(config, missing)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The failure for a project about to run without these variables, and what fixes it. */
|
|
90
|
+
export function missingEnvError(config: EnvConfig, names: readonly string[]): SixbCliError {
|
|
91
|
+
return new SixbCliError(`[SixbEnv] ${missingEnvSentence(names)}`, {
|
|
92
|
+
remediation: config.source
|
|
93
|
+
? "Run `sixb env pull`. If the source doesn't have the value, set it with `sixb env set`."
|
|
94
|
+
: "Add what's missing to the project's .env.",
|
|
95
|
+
})
|
|
96
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { access, constants, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises"
|
|
2
|
+
import { tmpdir } from "node:os"
|
|
3
|
+
import { join, resolve } from "node:path"
|
|
4
|
+
import type { EnvName } from "@sixb/core/env"
|
|
5
|
+
import { SixbCliError } from "./errors"
|
|
6
|
+
|
|
7
|
+
const GENERATED_MARK = "# Generated by sixb env pull"
|
|
8
|
+
const READ_TIMEOUT_MS = 10_000
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* What Bun reads from a `.env` file, by asking Bun: a second parser would disagree with the one the
|
|
12
|
+
* app runs on. The child has an empty environment and an empty directory, so the result holds this
|
|
13
|
+
* file's values and nothing else. A `$NAME` in the file sees only that file.
|
|
14
|
+
*/
|
|
15
|
+
export async function readEnvFile(path: string): Promise<Record<string, string>> {
|
|
16
|
+
// Bun reads a file it can't open as an empty one, which would read as having nothing to lose.
|
|
17
|
+
await access(path, constants.R_OK).catch(() => {
|
|
18
|
+
throw new SixbCliError(`[SixbEnv] Could not read ${path}.`)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const directory = await mkdtemp(join(tmpdir(), "sixb-env-read-"))
|
|
22
|
+
try {
|
|
23
|
+
const child = Bun.spawn(
|
|
24
|
+
[
|
|
25
|
+
process.execPath,
|
|
26
|
+
`--env-file=${resolve(path)}`,
|
|
27
|
+
"-e",
|
|
28
|
+
"process.stdout.write(JSON.stringify(process.env))",
|
|
29
|
+
],
|
|
30
|
+
{
|
|
31
|
+
cwd: directory,
|
|
32
|
+
env: {},
|
|
33
|
+
stdin: "ignore",
|
|
34
|
+
stdout: "pipe",
|
|
35
|
+
stderr: "ignore",
|
|
36
|
+
timeout: READ_TIMEOUT_MS,
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
const [output, code] = await Promise.all([new Response(child.stdout).text(), child.exited])
|
|
40
|
+
// Never quote the output: it holds the file's values.
|
|
41
|
+
if (code !== 0) throw new SixbCliError(`[SixbEnv] Could not read ${path}.`)
|
|
42
|
+
return JSON.parse(output) as Record<string, string>
|
|
43
|
+
} finally {
|
|
44
|
+
await rm(directory, { recursive: true, force: true })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Whether this `.env` came from `sixb env pull`, so overwriting it loses nothing. */
|
|
49
|
+
export async function isGeneratedEnvFile(path: string): Promise<boolean> {
|
|
50
|
+
const text = await readFile(path, "utf8").catch(() => "")
|
|
51
|
+
return text.startsWith(GENERATED_MARK)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Writes `.env` readable only by its owner, or not at all. The new file is read back through Bun
|
|
56
|
+
* before it replaces the old one, because Bun's `.env` format can't hold every value: a trailing
|
|
57
|
+
* backslash swallows the closing quote and the next line, and a carriage return becomes a newline.
|
|
58
|
+
*/
|
|
59
|
+
export async function writeEnvFile(
|
|
60
|
+
path: string,
|
|
61
|
+
values: Readonly<Record<string, string>>,
|
|
62
|
+
env: EnvName
|
|
63
|
+
): Promise<void> {
|
|
64
|
+
// One fixed name, so a pull that was killed leaves no copy of the values behind for long.
|
|
65
|
+
const temporary = `${path}.pull.tmp`
|
|
66
|
+
try {
|
|
67
|
+
await rm(temporary, { force: true })
|
|
68
|
+
await writeFile(temporary, renderEnvFile(values, env), { mode: 0o600, flag: "wx" })
|
|
69
|
+
|
|
70
|
+
const written = await readEnvFile(temporary)
|
|
71
|
+
const names = new Set([...Object.keys(values), ...Object.keys(written)])
|
|
72
|
+
const unreadable = [...names].filter((name) => written[name] !== values[name]).sort()
|
|
73
|
+
if (unreadable.length > 0) {
|
|
74
|
+
throw new SixbCliError(
|
|
75
|
+
`[SixbEnv] A .env file can't hold the value of ${unreadable.join(", ")}.`,
|
|
76
|
+
{
|
|
77
|
+
remediation:
|
|
78
|
+
"Change the value so it has no carriage return and doesn't end in a backslash, and doesn't use all of ' \" and `.",
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await rename(temporary, path)
|
|
84
|
+
} finally {
|
|
85
|
+
await rm(temporary, { force: true })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function renderEnvFile(values: Readonly<Record<string, string>>, env: EnvName): string {
|
|
90
|
+
const lines = Object.entries(values)
|
|
91
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
92
|
+
.map(([name, value]) => `${name}=${quoted(value)}`)
|
|
93
|
+
const header = `${GENERATED_MARK} (${env}). Edits are overwritten: use .env.local for your own.`
|
|
94
|
+
return `${[header, ...lines].join("\n")}\n`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Bun expands `$` in every quote style, so it's always escaped. Single quotes and backticks keep
|
|
99
|
+
* everything else as written; double quotes also turn `\n` into a newline, so they come last.
|
|
100
|
+
*/
|
|
101
|
+
function quoted(value: string): string {
|
|
102
|
+
const quote = ["'", "`", '"'].find((candidate) => !value.includes(candidate)) ?? "'"
|
|
103
|
+
return `${quote}${value.replaceAll("$", "\\$")}${quote}`
|
|
104
|
+
}
|
package/src/lib/github-ci.ts
CHANGED
|
@@ -95,7 +95,9 @@ export function renderWorkflow(input: WorkflowInput): string {
|
|
|
95
95
|
? [" with:", ` bun-version-file: ${input.bunVersionFile}`]
|
|
96
96
|
: []),
|
|
97
97
|
" - name: Install dependencies",
|
|
98
|
-
|
|
98
|
+
// `sixb deploy` only loads `sixb.deploy.ts` and uploads the source; the server installs again
|
|
99
|
+
// with lifecycle scripts. Skipping them here skips downloads such as a Playwright browser.
|
|
100
|
+
" run: bun install --frozen-lockfile --ignore-scripts",
|
|
99
101
|
...workingDirectory,
|
|
100
102
|
" - name: Install the deploy key",
|
|
101
103
|
" env:",
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const CTRL_C = "\u0003"
|
|
2
|
+
const CTRL_D = "\u0004"
|
|
3
|
+
const BACKSPACE = "\u007f"
|
|
4
|
+
const PASTE_START = "\u001b[200~"
|
|
5
|
+
const PASTE_END = "\u001b[201~"
|
|
6
|
+
/** Keys such as the arrows, which are not part of a value. */
|
|
7
|
+
const ESCAPE_SEQUENCE = /^\u001b\[[0-9;]*[A-Za-z~]/
|
|
8
|
+
/** A long value still shows that something arrived, without filling the screen. */
|
|
9
|
+
const MOST_DOTS = 40
|
|
10
|
+
|
|
11
|
+
export interface HiddenInput {
|
|
12
|
+
readonly value: string
|
|
13
|
+
/** The start of a paste that hasn't finished arriving. */
|
|
14
|
+
readonly pending: string
|
|
15
|
+
/** `refused`: lines arrived that this terminal didn't mark as one paste. */
|
|
16
|
+
readonly outcome?: "done" | "cancelled" | "refused"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Applies what the terminal sent. A terminal that supports it marks a paste, so a multi-line value
|
|
21
|
+
* stays whole. Without the marks, a newline with more behind it is refused: keeping only the first
|
|
22
|
+
* line would store a broken value, and "Set" would still print.
|
|
23
|
+
*/
|
|
24
|
+
export function readHiddenKeys(input: HiddenInput, text: string): HiddenInput {
|
|
25
|
+
let { value } = input
|
|
26
|
+
let rest = input.pending + text
|
|
27
|
+
|
|
28
|
+
while (rest.length > 0) {
|
|
29
|
+
if (rest.startsWith(PASTE_START)) {
|
|
30
|
+
const end = rest.indexOf(PASTE_END)
|
|
31
|
+
if (end === -1) return { value, pending: rest }
|
|
32
|
+
value += rest.slice(PASTE_START.length, end).replace(/\r\n?/g, "\n").replace(/\n$/, "")
|
|
33
|
+
rest = rest.slice(end + PASTE_END.length)
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sequence = ESCAPE_SEQUENCE.exec(rest)
|
|
38
|
+
if (sequence) {
|
|
39
|
+
rest = rest.slice(sequence[0].length)
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const character = String.fromCodePoint(rest.codePointAt(0) ?? 0)
|
|
44
|
+
rest = rest.slice(character.length)
|
|
45
|
+
|
|
46
|
+
if (character === CTRL_C) return { value, pending: "", outcome: "cancelled" }
|
|
47
|
+
if (character === CTRL_D) return { value, pending: "", outcome: "done" }
|
|
48
|
+
if (character === "\r" || character === "\n") {
|
|
49
|
+
const outcome = rest.trim() === "" ? "done" : "refused"
|
|
50
|
+
return { value, pending: "", outcome }
|
|
51
|
+
}
|
|
52
|
+
if (character === BACKSPACE) value = [...value].slice(0, -1).join("")
|
|
53
|
+
else if (character >= " ") value += character
|
|
54
|
+
}
|
|
55
|
+
return { value, pending: "" }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Reads a value from a terminal without showing it. It never joins the scrollback or the shell's
|
|
60
|
+
* history.
|
|
61
|
+
*/
|
|
62
|
+
export function promptHidden(label: string): Promise<string> {
|
|
63
|
+
const { stdin, stderr } = process
|
|
64
|
+
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
let input: HiddenInput = { value: "", pending: "" }
|
|
67
|
+
let dots = 0
|
|
68
|
+
|
|
69
|
+
const onData = (chunk: Buffer) => {
|
|
70
|
+
input = readHiddenKeys(input, chunk.toString("utf8"))
|
|
71
|
+
|
|
72
|
+
const shown = Math.min([...input.value].length, MOST_DOTS)
|
|
73
|
+
stderr.write(shown > dots ? "•".repeat(shown - dots) : "\b \b".repeat(dots - shown))
|
|
74
|
+
dots = shown
|
|
75
|
+
|
|
76
|
+
if (input.outcome === undefined) return
|
|
77
|
+
stdin.off("data", onData)
|
|
78
|
+
stdin.setRawMode(false)
|
|
79
|
+
stdin.pause()
|
|
80
|
+
stderr.write("\u001b[?2004l\n")
|
|
81
|
+
|
|
82
|
+
if (input.outcome === "done") resolve(input.value)
|
|
83
|
+
else if (input.outcome === "refused") {
|
|
84
|
+
reject(new Error("[SixbEnv] A value with several lines has to come from standard input."))
|
|
85
|
+
} else {
|
|
86
|
+
void import("../ui/live/prompt").then(({ PromptCancelledError }) =>
|
|
87
|
+
reject(new PromptCancelledError())
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
stderr.write(`${label} \u001b[?2004h`)
|
|
93
|
+
stdin.setRawMode(true)
|
|
94
|
+
stdin.resume()
|
|
95
|
+
stdin.on("data", onData)
|
|
96
|
+
})
|
|
97
|
+
}
|
package/src/lib/runtime.ts
CHANGED
|
@@ -60,7 +60,6 @@ export interface StartSixbRuntimeOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
readonly api?: RuntimeApiServer
|
|
62
62
|
readonly agentApiBaseUrl?: string
|
|
63
|
-
readonly agentTurnTimeoutMs?: number
|
|
64
63
|
readonly workerConcurrency?: WorkerConcurrency
|
|
65
64
|
readonly vectorConcurrency?: number
|
|
66
65
|
readonly subagentConcurrency?: number
|
|
@@ -292,7 +291,6 @@ export async function startSixbRuntime(
|
|
|
292
291
|
? requireAgentApiBaseUrl(options.agentApiBaseUrl)
|
|
293
292
|
: undefined,
|
|
294
293
|
concurrency: options.workerConcurrency?.agent,
|
|
295
|
-
turnTimeoutMs: options.agentTurnTimeoutMs,
|
|
296
294
|
subagentConcurrency: options.subagentConcurrency,
|
|
297
295
|
subagentConcurrencyPerRun: options.subagentConcurrencyPerRun,
|
|
298
296
|
})
|
|
@@ -17,7 +17,6 @@ export type QueueWorkerProcess = Worker & { readonly concurrency: number }
|
|
|
17
17
|
|
|
18
18
|
export interface WorkerCreationOptions {
|
|
19
19
|
readonly agentApiBaseUrl?: string
|
|
20
|
-
readonly agentTurnTimeoutMs?: number
|
|
21
20
|
readonly workerConcurrency?: WorkerConcurrency
|
|
22
21
|
readonly vectorConcurrency?: number
|
|
23
22
|
readonly subagentConcurrency?: number
|
|
@@ -54,7 +53,6 @@ const workerFactories: Record<WorkerType, WorkerFactory> = {
|
|
|
54
53
|
? resolveAgentApiBaseUrl(options.agentApiBaseUrl)
|
|
55
54
|
: undefined,
|
|
56
55
|
concurrency: options.workerConcurrency?.agent,
|
|
57
|
-
turnTimeoutMs: options.agentTurnTimeoutMs,
|
|
58
56
|
subagentConcurrency: options.subagentConcurrency,
|
|
59
57
|
subagentConcurrencyPerRun: options.subagentConcurrencyPerRun,
|
|
60
58
|
}),
|