@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
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EnvName } from "@sixb/core/env";
|
|
2
|
+
export declare function envPulledView(input: {
|
|
3
|
+
readonly count: number;
|
|
4
|
+
readonly env: EnvName;
|
|
5
|
+
}): string;
|
|
6
|
+
/** What a pull says when it leaves `.env` as it was. A deploy watches its output for this. */
|
|
7
|
+
export declare const ENV_KEPT_MESSAGE = "Kept the current .env";
|
|
8
|
+
/** A deploy kept the server's `.env`, because the source was down or the commit has none. */
|
|
9
|
+
export declare function envKeptView(input: {
|
|
10
|
+
readonly env: EnvName;
|
|
11
|
+
readonly reason: string;
|
|
12
|
+
}): string;
|
|
13
|
+
export declare function envSetView(input: {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly env: EnvName;
|
|
16
|
+
readonly declared: boolean;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function envInitView(input: {
|
|
19
|
+
readonly uploaded: readonly {
|
|
20
|
+
readonly env: EnvName;
|
|
21
|
+
readonly count: number;
|
|
22
|
+
}[];
|
|
23
|
+
readonly names: number;
|
|
24
|
+
}): string;
|
|
25
|
+
export interface EnvStatusRow {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly dev: EnvStatusCell;
|
|
28
|
+
readonly prod: EnvStatusCell;
|
|
29
|
+
readonly declared: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** `set` has a value; `missing` must have one; `unneeded` needs none; `unknown` can't be read. */
|
|
32
|
+
export type EnvStatusCell = "set" | "missing" | "unneeded" | "unknown";
|
|
33
|
+
export declare function envStatusView(input: {
|
|
34
|
+
readonly rows: readonly EnvStatusRow[];
|
|
35
|
+
readonly missing: number;
|
|
36
|
+
}): string;
|
|
37
|
+
//# sourceMappingURL=env-screens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-screens.d.ts","sourceRoot":"","sources":["../../src/ui/env-screens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAI7C,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAE9F;AAED,8FAA8F;AAC9F,eAAO,MAAM,gBAAgB,0BAA0B,CAAA;AAEvD,6FAA6F;AAC7F,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE7F;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B,GAAG,MAAM,CAOT;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE;IACjC,QAAQ,CAAC,QAAQ,EAAE,SAAS;QAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC/E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAQT;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;IAC5B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B;AAED,kGAAkG;AAClG,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAA;AAStE,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,QAAQ,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,CAAA;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,GAAG,MAAM,CAkBT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Command-line interface for Sixb projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -31,25 +31,27 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@opentui/core": "0.6.6",
|
|
33
33
|
"@opentui/react": "0.6.6",
|
|
34
|
-
"@sixb/agent
|
|
35
|
-
"@sixb/
|
|
36
|
-
"@sixb/
|
|
37
|
-
"@sixb/
|
|
38
|
-
"@sixb/
|
|
39
|
-
"@sixb/
|
|
40
|
-
"@sixb/
|
|
41
|
-
"@sixb/
|
|
42
|
-
"@sixb/
|
|
43
|
-
"@sixb/
|
|
44
|
-
"@sixb/
|
|
45
|
-
"@sixb/
|
|
46
|
-
"
|
|
34
|
+
"@sixb/agent": "0.2.0",
|
|
35
|
+
"@sixb/agent-worker": "0.2.0",
|
|
36
|
+
"@sixb/app": "^0.2.0",
|
|
37
|
+
"@sixb/client": "^0.2.0",
|
|
38
|
+
"@sixb/core": "0.2.0",
|
|
39
|
+
"@sixb/cli-core": "^0.2.0",
|
|
40
|
+
"@sixb/orchestrator": "0.2.0",
|
|
41
|
+
"@sixb/pipeline-worker": "0.2.0",
|
|
42
|
+
"@sixb/projection-worker": "0.2.0",
|
|
43
|
+
"@sixb/rules-worker": "0.2.0",
|
|
44
|
+
"@sixb/sandboxes-local": "^0.2.0",
|
|
45
|
+
"@sixb/server": "0.2.0",
|
|
46
|
+
"@sixb/sync-worker": "0.2.0",
|
|
47
|
+
"@sixb/workflow-worker": "0.2.0",
|
|
48
|
+
"create-sixb": "^0.2.0",
|
|
47
49
|
"react": "^19.2.0"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@sixb/deploy-ssh": "0.
|
|
51
|
-
"@sixb/desktop": "0.
|
|
52
|
-
"@sixb/ducklake": "0.
|
|
52
|
+
"@sixb/deploy-ssh": "0.2.0",
|
|
53
|
+
"@sixb/desktop": "0.2.0",
|
|
54
|
+
"@sixb/ducklake": "0.2.0",
|
|
53
55
|
"@types/bun": "latest",
|
|
54
56
|
"@types/react": "^19.0.0",
|
|
55
57
|
"typescript": "^5.7.0"
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises"
|
|
2
|
+
import { createInterface } from "node:readline/promises"
|
|
3
|
+
import {
|
|
4
|
+
type AgentRunStreamEvent,
|
|
5
|
+
createAgentRunSocket,
|
|
6
|
+
createAgentThread,
|
|
7
|
+
decideAgentApproval,
|
|
8
|
+
getAgentThread,
|
|
9
|
+
listAgentThreadApprovals,
|
|
10
|
+
listAgentThreadMessages,
|
|
11
|
+
listAgentThreadRuns,
|
|
12
|
+
listModels,
|
|
13
|
+
postAgentThreadMessage,
|
|
14
|
+
} from "@sixb/client"
|
|
15
|
+
import { thisComputer, thisComputerId } from "../tui/computer"
|
|
16
|
+
import { type Connection, connect } from "../tui/connection"
|
|
17
|
+
import { toolLine } from "../tui/format"
|
|
18
|
+
import { liveRun, reduceLive, shownMessage } from "../tui/parts"
|
|
19
|
+
import { LocalRunner } from "../tui/runner"
|
|
20
|
+
import {
|
|
21
|
+
APPROVAL_MODES,
|
|
22
|
+
type ApprovalMode,
|
|
23
|
+
approvalLabel,
|
|
24
|
+
loadSettings,
|
|
25
|
+
messageSelection,
|
|
26
|
+
placeLabel,
|
|
27
|
+
} from "../tui/settings"
|
|
28
|
+
import { glyph, paint, palette, tone } from "../ui/theme"
|
|
29
|
+
|
|
30
|
+
/** Exit status when the turn stopped on calls only the person can decide, and nobody could ask. */
|
|
31
|
+
const EXIT_WAITING = 4
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* `sixb agent "<message>"`: one message to the agent, answered in the terminal. The turn runs on
|
|
35
|
+
* this computer in the current folder, or in the cloud with `--cloud`; its steps go to stderr and
|
|
36
|
+
* its answer to stdout, so the answer can be piped.
|
|
37
|
+
*/
|
|
38
|
+
export async function runAgent(options: {
|
|
39
|
+
readonly text: readonly string[]
|
|
40
|
+
readonly thread?: string
|
|
41
|
+
readonly cloud: boolean
|
|
42
|
+
/** The turn's mode; without it, the person's in the thread applies, as for a message in the web. */
|
|
43
|
+
readonly approvalMode?: string
|
|
44
|
+
readonly json: boolean
|
|
45
|
+
readonly apiUrl?: string
|
|
46
|
+
readonly profile?: string
|
|
47
|
+
}): Promise<void> {
|
|
48
|
+
const approvalMode = parseApprovalMode(options.approvalMode)
|
|
49
|
+
const text = options.text.join(" ").trim() || (await readStdin())
|
|
50
|
+
if (!text) throw new Error('[SixbCLI] Give the agent a message: sixb agent "<message>".')
|
|
51
|
+
|
|
52
|
+
const connection = await connect(options)
|
|
53
|
+
if ("reason" in connection) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
connection.reason === "unreachable"
|
|
56
|
+
? `[SixbCLI] Sixb isn't answering at ${connection.apiUrl}.`
|
|
57
|
+
: `[SixbCLI] Sign in first: sixb login ${connection.apiUrl || "<api-url>"}.`
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
const { client } = connection
|
|
61
|
+
const settings = await loadSettings(process.cwd())
|
|
62
|
+
// As the project keeps it, and the local sandbox compares it: its real path.
|
|
63
|
+
const folder = await realpath(process.cwd())
|
|
64
|
+
const models = (await listModels({ client })).data?.language ?? []
|
|
65
|
+
|
|
66
|
+
const threadId =
|
|
67
|
+
options.thread ??
|
|
68
|
+
(
|
|
69
|
+
await createAgentThread({
|
|
70
|
+
client,
|
|
71
|
+
body: {
|
|
72
|
+
title: text.split("\n")[0]?.slice(0, 72) ?? "Conversation",
|
|
73
|
+
...(options.cloud
|
|
74
|
+
? {}
|
|
75
|
+
: { runsOn: "computer" as const, computer: { ...(await thisComputer()), folder } }),
|
|
76
|
+
},
|
|
77
|
+
throwOnError: true,
|
|
78
|
+
})
|
|
79
|
+
).data.thread.id
|
|
80
|
+
// Read as the person: it says the mode their turns run in there.
|
|
81
|
+
const { data: thread } = await getAgentThread({ client, path: { threadId }, throwOnError: true })
|
|
82
|
+
const onComputer = thread.runsOn === "computer"
|
|
83
|
+
if (onComputer) {
|
|
84
|
+
const place = thread.computer
|
|
85
|
+
const computerId = await thisComputerId()
|
|
86
|
+
if (place?.id !== computerId || place.folder !== folder) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
!place
|
|
89
|
+
? "[SixbCLI] This conversation has no folder yet: open it with sixb in its folder, and press ctrl+f."
|
|
90
|
+
: place.id === computerId
|
|
91
|
+
? `[SixbCLI] This conversation works in ${place.folder}: run sixb agent there.`
|
|
92
|
+
: `[SixbCLI] This conversation runs on ${place.name}: run sixb agent there.`
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const runner = onComputer
|
|
97
|
+
? new LocalRunner(connection, folder, (error) => step(tone.fail(errorText(error))))
|
|
98
|
+
: null
|
|
99
|
+
if (!options.json) {
|
|
100
|
+
const mode = approvalMode ?? thread.approvalMode
|
|
101
|
+
step(
|
|
102
|
+
`${tone.blue(glyph.mark)} ${tone.strong(placeLabel(onComputer ? "computer" : "cloud"))}` +
|
|
103
|
+
tone.faint(` · ${mode ? `${approvalLabel(mode)} · ` : ""}${thread.id}`)
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const stop = new AbortController()
|
|
108
|
+
process.once("SIGINT", () => stop.abort())
|
|
109
|
+
try {
|
|
110
|
+
const { data: posted } = await postAgentThreadMessage({
|
|
111
|
+
client,
|
|
112
|
+
path: { threadId: thread.id },
|
|
113
|
+
body: {
|
|
114
|
+
text,
|
|
115
|
+
...(approvalMode ? { approvalMode } : {}),
|
|
116
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
117
|
+
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
118
|
+
...messageSelection(models, settings),
|
|
119
|
+
},
|
|
120
|
+
throwOnError: true,
|
|
121
|
+
})
|
|
122
|
+
let runId: string | null = posted.run.id
|
|
123
|
+
let followed: Awaited<ReturnType<typeof follow>> = "finished"
|
|
124
|
+
while (runId) {
|
|
125
|
+
// A turn this computer could not claim would wait here for nobody.
|
|
126
|
+
const unclaimed = runner?.claim(runId).then((claimed) => !claimed)
|
|
127
|
+
followed = await follow(connection, runId, options.json, stop.signal, unclaimed)
|
|
128
|
+
if (followed === "unclaimed") {
|
|
129
|
+
process.exitCode = 1
|
|
130
|
+
step(
|
|
131
|
+
tone.fail("This computer couldn't claim the turn: another runner holds it, or it ended.")
|
|
132
|
+
)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
if (followed !== "finished") break
|
|
136
|
+
runId = await afterTurn(connection, thread.id, runId, options.json)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// A lost stream or Ctrl+C leaves a turn that may still run: its answer is not the turn's.
|
|
140
|
+
if (followed !== "finished") {
|
|
141
|
+
process.exitCode = 1
|
|
142
|
+
if (followed === "stopped") step(tone.fail(`Stopped waiting for the turn in ${thread.id}.`))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await printAnswer(connection, thread.id, options.json)
|
|
146
|
+
} finally {
|
|
147
|
+
await runner?.stop()
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Show a turn's steps as they finish, until it ends, the stream fails, the person stops waiting,
|
|
153
|
+
* or `unclaimed` says this computer could not run it.
|
|
154
|
+
*/
|
|
155
|
+
async function follow(
|
|
156
|
+
connection: Connection,
|
|
157
|
+
runId: string,
|
|
158
|
+
json: boolean,
|
|
159
|
+
signal: AbortSignal,
|
|
160
|
+
unclaimed?: Promise<boolean>
|
|
161
|
+
): Promise<"finished" | "stopped" | "failed" | "unclaimed"> {
|
|
162
|
+
let live = liveRun(runId)
|
|
163
|
+
const shown = new Set<string>()
|
|
164
|
+
return new Promise((resolve) => {
|
|
165
|
+
let settled = false
|
|
166
|
+
const settle = (outcome: "finished" | "stopped" | "failed" | "unclaimed") => {
|
|
167
|
+
if (settled) return
|
|
168
|
+
settled = true
|
|
169
|
+
socket.close()
|
|
170
|
+
signal.removeEventListener("abort", onAbort)
|
|
171
|
+
resolve(outcome)
|
|
172
|
+
}
|
|
173
|
+
const onAbort = () => settle("stopped")
|
|
174
|
+
const socket = createAgentRunSocket({
|
|
175
|
+
client: connection.client,
|
|
176
|
+
runId,
|
|
177
|
+
// A turn that ended before the stream opened: its snapshot says so.
|
|
178
|
+
onRunSnapshot: (run) => {
|
|
179
|
+
if (run.status !== "queued" && run.status !== "running") settle("finished")
|
|
180
|
+
},
|
|
181
|
+
onError: (message) => {
|
|
182
|
+
step(tone.fail(message))
|
|
183
|
+
settle("failed")
|
|
184
|
+
},
|
|
185
|
+
onEvent: (event: AgentRunStreamEvent) => {
|
|
186
|
+
live = reduceLive(live, event)
|
|
187
|
+
if (!json) {
|
|
188
|
+
for (const part of live.parts) {
|
|
189
|
+
if (part.kind !== "tool" || part.state === "running" || shown.has(part.id)) continue
|
|
190
|
+
shown.add(part.id)
|
|
191
|
+
const line = toolLine(part)
|
|
192
|
+
const mark = line.held
|
|
193
|
+
? tone.warn(glyph.live)
|
|
194
|
+
: line.failed || part.state === "error"
|
|
195
|
+
? tone.fail(glyph.live)
|
|
196
|
+
: tone.ok(glyph.live)
|
|
197
|
+
step(
|
|
198
|
+
`${mark} ${tone.strong(line.verb)} ${tone.muted(line.detail)}${line.note ? tone.faint(` ${line.note}`) : ""}`
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (event.type === "agent.run.finished") settle("finished")
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
signal.addEventListener("abort", onAbort)
|
|
206
|
+
void unclaimed?.then((refused) => {
|
|
207
|
+
if (refused) settle("unclaimed")
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* What follows a turn's end: the turn that resumes once its held calls are decided, asked here
|
|
214
|
+
* when a person is at the terminal. Null when nothing follows.
|
|
215
|
+
*/
|
|
216
|
+
async function afterTurn(
|
|
217
|
+
connection: Connection,
|
|
218
|
+
threadId: string,
|
|
219
|
+
runId: string,
|
|
220
|
+
json: boolean
|
|
221
|
+
): Promise<string | null> {
|
|
222
|
+
const { client } = connection
|
|
223
|
+
const { data: runs } = await listAgentThreadRuns({ client, path: { threadId } })
|
|
224
|
+
const run = runs?.runs.find((entry) => entry.id === runId)
|
|
225
|
+
if (run?.finishReason !== "awaiting_approval") return null
|
|
226
|
+
|
|
227
|
+
const { data } = await listAgentThreadApprovals({
|
|
228
|
+
client,
|
|
229
|
+
path: { threadId },
|
|
230
|
+
query: { status: "pending", runId },
|
|
231
|
+
})
|
|
232
|
+
const approvals = data?.approvals ?? []
|
|
233
|
+
if (approvals.length === 0 || json || !process.stdin.isTTY) {
|
|
234
|
+
for (const approval of approvals) step(tone.warn(`? ${describe(approval.call)}`))
|
|
235
|
+
step(tone.faint(`Decide in the app, or run sixb in this folder and open the conversation.`))
|
|
236
|
+
process.exitCode = EXIT_WAITING
|
|
237
|
+
return null
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const prompt = createInterface({ input: process.stdin, output: process.stderr })
|
|
241
|
+
try {
|
|
242
|
+
for (const approval of approvals) {
|
|
243
|
+
const answer = (
|
|
244
|
+
await prompt.question(
|
|
245
|
+
`${paint("?", { color: palette.amber })} ${tone.strong(describe(approval.call))} ${tone.muted("[y] allow [a] always in this thread [n] deny ")}`
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
.trim()
|
|
249
|
+
.toLowerCase()
|
|
250
|
+
await decideAgentApproval({
|
|
251
|
+
client,
|
|
252
|
+
path: { threadId, approvalId: approval.id },
|
|
253
|
+
body:
|
|
254
|
+
answer === "a"
|
|
255
|
+
? { decision: "approve", always: true }
|
|
256
|
+
: { decision: answer === "y" ? "approve" : "deny" },
|
|
257
|
+
throwOnError: true,
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
} finally {
|
|
261
|
+
prompt.close()
|
|
262
|
+
}
|
|
263
|
+
// Deciding the last one resumes the turn as a new run.
|
|
264
|
+
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
265
|
+
const { data: thread } = await getAgentThread({ client, path: { threadId } })
|
|
266
|
+
if (thread?.activeRunId && thread.activeRunId !== runId) return thread.activeRunId
|
|
267
|
+
await Bun.sleep(250)
|
|
268
|
+
}
|
|
269
|
+
return null
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** The turn's answer: its last message's text, or as JSON. */
|
|
273
|
+
async function printAnswer(connection: Connection, threadId: string, json: boolean) {
|
|
274
|
+
const { client } = connection
|
|
275
|
+
const [{ data: messages }, { data: runs }] = await Promise.all([
|
|
276
|
+
listAgentThreadMessages({ client, path: { threadId }, query: { order: "desc", limit: "1" } }),
|
|
277
|
+
listAgentThreadRuns({ client, path: { threadId }, query: { order: "desc", limit: "1" } }),
|
|
278
|
+
])
|
|
279
|
+
const last = messages?.messages[0]
|
|
280
|
+
const shown = last ? shownMessage(last) : null
|
|
281
|
+
const answer =
|
|
282
|
+
shown?.role === "assistant"
|
|
283
|
+
? shown.parts.flatMap((part) => (part.kind === "text" ? [part.text.trim()] : [])).join("\n\n")
|
|
284
|
+
: ""
|
|
285
|
+
const run = runs?.runs[0]
|
|
286
|
+
|
|
287
|
+
// Set before the JSON goes out: a script reads the code, not the status in the answer.
|
|
288
|
+
if (run?.status === "failed" || run?.status === "cancelled") process.exitCode = 1
|
|
289
|
+
|
|
290
|
+
if (json) {
|
|
291
|
+
process.stdout.write(
|
|
292
|
+
`${JSON.stringify({ threadId, runId: run?.id, status: run?.status, finishReason: run?.finishReason, text: answer })}\n`
|
|
293
|
+
)
|
|
294
|
+
return
|
|
295
|
+
}
|
|
296
|
+
if (answer) process.stdout.write(`\n${process.stdout.isTTY ? styled(answer) : answer}\n`)
|
|
297
|
+
if (run?.status === "failed") step(tone.fail(run.error?.message ?? "The turn failed."))
|
|
298
|
+
if (run?.status === "cancelled") step(tone.fail("The turn was stopped."))
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function parseApprovalMode(value: string | undefined): ApprovalMode | undefined {
|
|
302
|
+
if (value === undefined) return undefined
|
|
303
|
+
|
|
304
|
+
const mode = APPROVAL_MODES.find((entry) => entry.mode === value)?.mode
|
|
305
|
+
if (!mode) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`[SixbCLI] --approval-mode takes ${APPROVAL_MODES.map((entry) => entry.mode).join(", ")}; got '${value}'.`
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
return mode
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function describe(
|
|
314
|
+
call:
|
|
315
|
+
| { readonly kind: "action"; readonly actionId: string }
|
|
316
|
+
| { readonly kind: "workflow"; readonly workflowId: string }
|
|
317
|
+
): string {
|
|
318
|
+
return call.kind === "action" ? `Run ${call.actionId}?` : `Start the ${call.workflowId} workflow?`
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function step(line: string): void {
|
|
322
|
+
process.stderr.write(` ${line}\n`)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async function readStdin(): Promise<string> {
|
|
326
|
+
if (process.stdin.isTTY) return ""
|
|
327
|
+
let text = ""
|
|
328
|
+
for await (const chunk of process.stdin) text += chunk.toString()
|
|
329
|
+
return text.trim()
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function errorText(error: unknown): string {
|
|
333
|
+
return error instanceof Error ? error.message : String(error)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* The answer as a terminal shows it: bold and inline code styled, their markers gone. Piped, the
|
|
338
|
+
* answer stays the markdown it is.
|
|
339
|
+
*/
|
|
340
|
+
function styled(markdown: string): string {
|
|
341
|
+
return markdown
|
|
342
|
+
.replace(/\*\*([^*\n]+)\*\*/g, (_, text: string) => tone.strong(text))
|
|
343
|
+
.replace(/`([^`\n]+)`/g, (_, text: string) => tone.blue(text))
|
|
344
|
+
}
|
package/src/commands/api.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises"
|
|
2
2
|
import { resolve } from "node:path"
|
|
3
|
-
import { createSixbServer, type SixbServer } from "@sixb/server"
|
|
3
|
+
import { createSixbServer, requestTimingOptionsFromEnv, type SixbServer } from "@sixb/server"
|
|
4
4
|
import { apiDocsUrl, apiEventsUrl, apiUrl, resolveBrowserTopology } from "../lib/browser-topology"
|
|
5
5
|
import type { LoadedSixbHost } from "../lib/loadSixb"
|
|
6
6
|
import { builtAppOutdir, loadProductionSixb } from "../lib/production"
|
|
@@ -70,6 +70,7 @@ export async function runApi(options: ApiOptions = {}) {
|
|
|
70
70
|
},
|
|
71
71
|
...(hasAuthExperience ? { authExperience: { outdir: authExperienceOutdir } } : {}),
|
|
72
72
|
...(trustedProxies.length > 0 ? { trustedProxies } : {}),
|
|
73
|
+
timing: requestTimingOptionsFromEnv(),
|
|
73
74
|
})
|
|
74
75
|
await server.start()
|
|
75
76
|
|
package/src/commands/check.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { resolve } from "node:path"
|
|
1
|
+
import { dirname, resolve } from "node:path"
|
|
2
|
+
import { assertDeclaredEnv } from "../lib/env-config"
|
|
2
3
|
import { errorMessage } from "../lib/errors"
|
|
3
4
|
import { checkRuntimeHealth } from "../lib/health"
|
|
4
5
|
import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
|
|
@@ -16,6 +17,9 @@ export interface CheckOptions {
|
|
|
16
17
|
|
|
17
18
|
export async function runCheck(options: CheckOptions = {}) {
|
|
18
19
|
const entry = resolve(options.entry ?? "sixb.config.ts")
|
|
20
|
+
// First, so a missing variable is named instead of surfacing as whatever reading it breaks.
|
|
21
|
+
await assertDeclaredEnv(dirname(entry))
|
|
22
|
+
|
|
19
23
|
const sixb = await withTask("check", "Generating types", async (task) => {
|
|
20
24
|
await generateProjectTypes({ entry })
|
|
21
25
|
task.step("Loading project")
|
package/src/commands/deploy.ts
CHANGED
|
@@ -12,12 +12,14 @@ import type {
|
|
|
12
12
|
import { loadDeployConfig } from "../lib/deploy-config"
|
|
13
13
|
import { buildDeployRelease } from "../lib/deploy-release"
|
|
14
14
|
import {
|
|
15
|
+
commitHasProjectFile,
|
|
15
16
|
deployer,
|
|
16
17
|
packSource,
|
|
17
18
|
projectPathOf,
|
|
18
19
|
repoRootOf,
|
|
19
20
|
resolveBunVersion,
|
|
20
21
|
} from "../lib/deploy-source"
|
|
22
|
+
import { ENV_CONFIG_FILE, loadEnvConfig } from "../lib/env-config"
|
|
21
23
|
import { SixbCliError } from "../lib/errors"
|
|
22
24
|
import {
|
|
23
25
|
bunVersionFile,
|
|
@@ -45,6 +47,7 @@ import {
|
|
|
45
47
|
renderStatic,
|
|
46
48
|
withTask,
|
|
47
49
|
} from "../ui"
|
|
50
|
+
import { ENV_KEPT_MESSAGE } from "../ui/env-screens"
|
|
48
51
|
import { canRunLive } from "../ui/live/can-run-live"
|
|
49
52
|
|
|
50
53
|
export interface DeployOptions {
|
|
@@ -57,9 +60,13 @@ export interface DeployOptions {
|
|
|
57
60
|
export async function runDeploy(options: DeployOptions = {}): Promise<void> {
|
|
58
61
|
const cwd = options.cwd ?? process.cwd()
|
|
59
62
|
const { path, config } = await loadDeployConfig(cwd)
|
|
63
|
+
const envFromSource = Boolean((await loadEnvConfig(cwd))?.source)
|
|
60
64
|
|
|
61
65
|
if (options.dryRun) {
|
|
62
|
-
const release = buildDeployRelease(config, {
|
|
66
|
+
const release = buildDeployRelease(config, {
|
|
67
|
+
bunVersion: await resolveBunVersion(cwd),
|
|
68
|
+
envFromSource,
|
|
69
|
+
})
|
|
63
70
|
if (options.json) return writeJson(release)
|
|
64
71
|
await renderStatic(deployReleaseView({ release, configPath: relative(cwd, path) || path }))
|
|
65
72
|
return
|
|
@@ -70,6 +77,8 @@ export async function runDeploy(options: DeployOptions = {}): Promise<void> {
|
|
|
70
77
|
const source = await packSource(cwd, options.ref)
|
|
71
78
|
const release = buildDeployRelease(config, {
|
|
72
79
|
bunVersion: await resolveBunVersion(cwd, source),
|
|
80
|
+
// `--ref` can name a commit from before the project had one, which can't run the pull.
|
|
81
|
+
envFromSource: envFromSource && (await commitHasProjectFile(cwd, source, ENV_CONFIG_FILE)),
|
|
73
82
|
})
|
|
74
83
|
// Stop before uploading anything when the target already says the deploy cannot work.
|
|
75
84
|
task.step(`Checking ${location(config)}`)
|
|
@@ -108,6 +117,7 @@ export async function runDeploy(options: DeployOptions = {}): Promise<void> {
|
|
|
108
117
|
deployCompleteView({
|
|
109
118
|
release,
|
|
110
119
|
seconds: (Date.now() - deployStartedAt) / 1000,
|
|
120
|
+
keptEnv: progress.state.keptEnv,
|
|
111
121
|
})
|
|
112
122
|
)
|
|
113
123
|
}
|
|
@@ -115,7 +125,10 @@ export async function runDeploy(options: DeployOptions = {}): Promise<void> {
|
|
|
115
125
|
export async function runDeployCheck(options: { readonly json?: boolean; readonly cwd?: string }) {
|
|
116
126
|
const cwd = options.cwd ?? process.cwd()
|
|
117
127
|
const { config } = await loadDeployConfig(cwd)
|
|
118
|
-
const release = buildDeployRelease(config, {
|
|
128
|
+
const release = buildDeployRelease(config, {
|
|
129
|
+
bunVersion: await resolveBunVersion(cwd),
|
|
130
|
+
envFromSource: Boolean((await loadEnvConfig(cwd))?.source),
|
|
131
|
+
})
|
|
119
132
|
const projectPath = await projectPathOf(cwd)
|
|
120
133
|
const checks = await withTask("deploy check", `Checking ${location(config)}`, () =>
|
|
121
134
|
config.target.check(release, { name: config.name, projectPath })
|
|
@@ -133,7 +146,11 @@ export async function runDeploySetup(options: {
|
|
|
133
146
|
}) {
|
|
134
147
|
const cwd = options.cwd ?? process.cwd()
|
|
135
148
|
const { config } = await loadDeployConfig(cwd)
|
|
136
|
-
const
|
|
149
|
+
const source = (await loadEnvConfig(cwd))?.source
|
|
150
|
+
const release = buildDeployRelease(config, {
|
|
151
|
+
bunVersion: await resolveBunVersion(cwd),
|
|
152
|
+
envFromSource: Boolean(source),
|
|
153
|
+
})
|
|
137
154
|
const context = { name: config.name, projectPath: await projectPathOf(cwd) }
|
|
138
155
|
|
|
139
156
|
if (!config.target.setup) {
|
|
@@ -143,6 +160,12 @@ export async function runDeploySetup(options: {
|
|
|
143
160
|
...context,
|
|
144
161
|
...(options.admin ? { admin: options.admin } : {}),
|
|
145
162
|
...(options.key ? { key: options.key } : {}),
|
|
163
|
+
...(source
|
|
164
|
+
? {
|
|
165
|
+
createEnvToken: () =>
|
|
166
|
+
source.createServerToken("prod", `sixb-${config.name}-${new Date().toISOString()}`),
|
|
167
|
+
}
|
|
168
|
+
: {}),
|
|
146
169
|
write: (line) => console.log(line),
|
|
147
170
|
})
|
|
148
171
|
}
|
|
@@ -348,6 +371,8 @@ async function createProgress(
|
|
|
348
371
|
current: null as number | null,
|
|
349
372
|
/** The latest output lines of the step running now, kept when it fails. */
|
|
350
373
|
output: [] as string[],
|
|
374
|
+
/** The pull left `.env` as it was. A live view clears step output, so the result has to say. */
|
|
375
|
+
keptEnv: false,
|
|
351
376
|
}
|
|
352
377
|
const live = canRunLive()
|
|
353
378
|
? await (await import("../ui/live/deploy")).startLiveDeploy({
|
|
@@ -386,6 +411,7 @@ async function createProgress(
|
|
|
386
411
|
}
|
|
387
412
|
if (event.type === "output") {
|
|
388
413
|
state.output = [...state.output, event.line].slice(-12)
|
|
414
|
+
if (event.line.includes(ENV_KEPT_MESSAGE)) state.keptEnv = true
|
|
389
415
|
if (live) live.output(event.line)
|
|
390
416
|
else console.log(` ${event.line}`)
|
|
391
417
|
}
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
type CustomAppDevServer,
|
|
6
6
|
createCustomApp,
|
|
7
7
|
} from "@sixb/app/server"
|
|
8
|
-
import { createSixbServer } from "@sixb/server"
|
|
9
|
-
import { resolveAgentTurnTimeoutMs } from "../lib/agent-turn-timeout"
|
|
8
|
+
import { createSixbServer, requestTimingOptionsFromEnv } from "@sixb/server"
|
|
10
9
|
import {
|
|
11
10
|
apiDocsUrl,
|
|
12
11
|
apiEventsUrl,
|
|
@@ -40,7 +39,6 @@ export interface DevOptions {
|
|
|
40
39
|
apiHost?: string
|
|
41
40
|
apiPublicOrigin?: string
|
|
42
41
|
appPublicOrigin?: string
|
|
43
|
-
agentTurnTimeout?: string
|
|
44
42
|
concurrency?: readonly string[]
|
|
45
43
|
vectorConcurrency?: string
|
|
46
44
|
subagentConcurrency?: string
|
|
@@ -52,7 +50,6 @@ export interface DevOptions {
|
|
|
52
50
|
export async function runDevRuntime(options: DevOptions = {}) {
|
|
53
51
|
process.env.NODE_ENV = "development"
|
|
54
52
|
|
|
55
|
-
const agentTurnTimeoutMs = resolveAgentTurnTimeoutMs(options.agentTurnTimeout)
|
|
56
53
|
const workerConcurrency = resolveWorkerConcurrency(options.concurrency)
|
|
57
54
|
const vectorConcurrency = resolveVectorConcurrency(options.vectorConcurrency)
|
|
58
55
|
const subagents = resolveSubagentConcurrency({
|
|
@@ -121,6 +118,8 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
121
118
|
allowedOrigins: topology.allowedBrowserOrigins,
|
|
122
119
|
},
|
|
123
120
|
authExperience,
|
|
121
|
+
// Always on while developing, so a slow request can be read from the Network tab.
|
|
122
|
+
timing: { ...requestTimingOptionsFromEnv(), header: true },
|
|
124
123
|
})
|
|
125
124
|
runtimeOwnsProviders = true
|
|
126
125
|
// The runtime owns the server's lifecycle so agent turns run only while it listens.
|
|
@@ -134,7 +133,6 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
134
133
|
stop: () => server.stop(),
|
|
135
134
|
},
|
|
136
135
|
agentApiBaseUrl: topology.apiPublicOrigin,
|
|
137
|
-
agentTurnTimeoutMs,
|
|
138
136
|
workerConcurrency,
|
|
139
137
|
vectorConcurrency,
|
|
140
138
|
...subagents,
|
package/src/commands/dev.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { dirname, resolve } from "node:path"
|
|
1
2
|
import { runDevSupervisor } from "../lib/dev-supervisor"
|
|
2
3
|
import type { DevOptions } from "./dev-runner"
|
|
4
|
+
import { assertDevEnv } from "./env"
|
|
3
5
|
|
|
4
6
|
export type { DevOptions } from "./dev-runner"
|
|
5
7
|
|
|
@@ -29,5 +31,6 @@ export async function runDev(options: DevOptions = {}) {
|
|
|
29
31
|
}
|
|
30
32
|
process.exit(process.exitCode ?? 0)
|
|
31
33
|
}
|
|
34
|
+
await assertDevEnv(dirname(resolve(options.entry ?? "sixb.config.ts")))
|
|
32
35
|
await runDevSupervisor(options)
|
|
33
36
|
}
|