@sixb/cli 0.2.0 → 0.2.2
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/dist/commands/agent.d.ts +4 -1
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/connect.d.ts +13 -0
- package/dist/commands/connect.d.ts.map +1 -0
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/db-prepare.d.ts.map +1 -1
- package/dist/commands/desktop.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +11 -1
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/{tui → lib}/connection.d.ts +11 -1
- package/dist/{tui → lib}/connection.d.ts.map +1 -1
- package/dist/lib/desktop.d.ts +4 -0
- package/dist/lib/desktop.d.ts.map +1 -1
- package/dist/lib/dev-supervisor.d.ts.map +1 -1
- package/dist/lib/profiles.d.ts +5 -0
- package/dist/lib/profiles.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/runner/allowed-folders.d.ts +17 -0
- package/dist/runner/allowed-folders.d.ts.map +1 -0
- package/dist/runner/computer-connection.d.ts +70 -0
- package/dist/runner/computer-connection.d.ts.map +1 -0
- package/dist/runner/computer.d.ts.map +1 -0
- package/dist/runner/desktop-runner-main.d.ts +2 -0
- package/dist/runner/desktop-runner-main.d.ts.map +1 -0
- package/dist/runner/desktop-runner.d.ts +43 -0
- package/dist/runner/desktop-runner.d.ts.map +1 -0
- package/dist/runner/keep-awake.d.ts +11 -0
- package/dist/runner/keep-awake.d.ts.map +1 -0
- package/dist/runner/local-runner.d.ts +131 -0
- package/dist/runner/local-runner.d.ts.map +1 -0
- package/dist/tui/app.d.ts +2 -2
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/format.d.ts +29 -0
- package/dist/tui/format.d.ts.map +1 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/settings.d.ts +5 -8
- package/dist/tui/settings.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/commands/agent.ts +122 -39
- package/src/commands/connect.ts +197 -0
- package/src/commands/db-migrate.ts +1 -0
- package/src/commands/db-prepare.ts +1 -0
- package/src/commands/desktop.ts +2 -1
- package/src/index.tsx +13 -0
- package/src/lib/command-line.ts +22 -3
- package/src/{tui → lib}/connection.ts +64 -17
- package/src/lib/desktop.ts +8 -1
- package/src/lib/dev-supervisor.ts +7 -2
- package/src/lib/profiles.ts +15 -1
- package/src/lib/runtime.ts +1 -0
- package/src/lib/storage-migration.ts +1 -0
- package/src/runner/allowed-folders.ts +126 -0
- package/src/runner/computer-connection.ts +184 -0
- package/src/runner/desktop-runner-main.ts +9 -0
- package/src/runner/desktop-runner.ts +217 -0
- package/src/runner/keep-awake.ts +50 -0
- package/src/runner/local-runner.ts +427 -0
- package/src/tui/app.tsx +168 -12
- package/src/tui/format.ts +203 -6
- package/src/tui/index.tsx +14 -13
- package/src/tui/settings.ts +12 -44
- package/dist/tui/computer.d.ts.map +0 -1
- package/dist/tui/runner.d.ts +0 -75
- package/dist/tui/runner.d.ts.map +0 -1
- package/src/tui/runner.ts +0 -256
- /package/dist/{tui → runner}/computer.d.ts +0 -0
- /package/src/{tui → runner}/computer.ts +0 -0
package/dist/tui/settings.d.ts
CHANGED
|
@@ -18,9 +18,12 @@ export interface Settings {
|
|
|
18
18
|
/**
|
|
19
19
|
* Whether your messages from the web, or another device, run in this folder: while it is on,
|
|
20
20
|
* `sixb` tells the project it is open here, and runs the turns sent to its conversations here.
|
|
21
|
-
* Kept per folder, apart from the settings every `sixb` rewrites
|
|
21
|
+
* Kept per folder and project, apart from the settings every `sixb` rewrites, and read once
|
|
22
|
+
* connected, so it is off until then: `runner/allowed-folders.ts`.
|
|
22
23
|
*/
|
|
23
24
|
readonly continueFromWeb: boolean;
|
|
25
|
+
/** Whether a turn running on this computer keeps it from going to sleep. */
|
|
26
|
+
readonly keepAwake: boolean;
|
|
24
27
|
}
|
|
25
28
|
export declare const DEFAULT_SETTINGS: Settings;
|
|
26
29
|
export declare const APPROVAL_MODES: readonly {
|
|
@@ -32,13 +35,7 @@ export declare function approvalLabel(mode: ApprovalMode): string;
|
|
|
32
35
|
/** What this computer is called where the person picks where a conversation runs. */
|
|
33
36
|
export declare function computerName(): string;
|
|
34
37
|
export declare function placeLabel(place: Place): string;
|
|
35
|
-
|
|
36
|
-
* Keep the choice for this folder alone. Reads the file first, as another `sixb` may have written
|
|
37
|
-
* it, and refuses one it can't read rather than lose the other folders' choices. Written whole, so
|
|
38
|
-
* no reader ever finds half of it.
|
|
39
|
-
*/
|
|
40
|
-
export declare function rememberWebMessages(folder: string, on: boolean): Promise<void>;
|
|
41
|
-
export declare function loadSettings(folder: string): Promise<Settings>;
|
|
38
|
+
export declare function loadSettings(): Promise<Settings>;
|
|
42
39
|
export declare function saveSettings(settings: Settings): Promise<void>;
|
|
43
40
|
/** The model the next message runs on, as the composer names it. */
|
|
44
41
|
export declare function modelLabel(models: readonly LanguageModel[], settings: Settings): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/tui/settings.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAGvD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,cAAc,GAAG,MAAM,CAAA;AAC7D,MAAM,MAAM,KAAK,GAAG,UAAU,GAAG,OAAO,CAAA;AACxC,MAAM,MAAM,aAAa,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAA;AACxE,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAErE,qFAAqF;AACrF,MAAM,WAAW,QAAQ;IACvB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,sFAAsF;IACtF,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,gGAAgG;IAChG,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IACxE,QAAQ,CAAC,SAAS,CAAC,EAAE,cAAc,CAAA;IACnC
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/tui/settings.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAGvD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,cAAc,GAAG,MAAM,CAAA;AAC7D,MAAM,MAAM,KAAK,GAAG,UAAU,GAAG,OAAO,CAAA;AACxC,MAAM,MAAM,aAAa,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAA;AACxE,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAErE,qFAAqF;AACrF,MAAM,WAAW,QAAQ;IACvB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,sFAAsF;IACtF,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,gGAAgG;IAChG,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IACxE,QAAQ,CAAC,SAAS,CAAC,EAAE,cAAc,CAAA;IACnC;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAA;IACjC,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAC5B;AAED,eAAO,MAAM,gBAAgB,EAAE,QAK9B,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,SAAS;IACpC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,EAiBA,CAAA;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAExD;AAED,qFAAqF;AACrF,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAE/C;AAID,wBAAsB,YAAY,IAAI,OAAO,CAAC,QAAQ,CAAC,CAgBtD;AAED,wBAAsB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAKpE;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,QAAQ,EAAE,QAAQ,GACjB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAexD;AAED,sEAAsE;AACtE,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,QAAQ,EAAE,QAAQ,GACjB;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,cAAc,CAAA;CAAE,CAiBjG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Command-line interface for Sixb projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -25,33 +25,33 @@
|
|
|
25
25
|
"build": "bun ../../scripts/build-package.ts",
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
27
|
"test": "bun test",
|
|
28
|
-
"test:e2e": "bun test ./tests/build.e2e.ts && bun test ./tests/prod-roles.e2e.ts && bun test ./tests/worker-group.e2e.ts && bun test ./tests/dev-reload.e2e.ts && bun test ./tests/pipeline-markings.e2e.ts",
|
|
28
|
+
"test:e2e": "bun test ./tests/build.e2e.ts && bun test ./tests/prod-roles.e2e.ts && bun test ./tests/worker-group.e2e.ts && bun test ./tests/dev-reload.e2e.ts && bun test ./tests/pipeline-markings.e2e.ts && bun test ./tests/connect-signed-out.e2e.ts && bun test ./tests/desktop-runner.e2e.ts",
|
|
29
29
|
"prepack": "bun run build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@opentui/core": "0.6.6",
|
|
33
33
|
"@opentui/react": "0.6.6",
|
|
34
|
-
"@sixb/agent": "0.2.
|
|
35
|
-
"@sixb/agent-worker": "0.2.
|
|
36
|
-
"@sixb/app": "^0.2.
|
|
37
|
-
"@sixb/client": "^0.2.
|
|
38
|
-
"@sixb/core": "0.2.
|
|
39
|
-
"@sixb/cli-core": "^0.2.
|
|
40
|
-
"@sixb/orchestrator": "0.2.
|
|
41
|
-
"@sixb/pipeline-worker": "0.2.
|
|
42
|
-
"@sixb/projection-worker": "0.2.
|
|
43
|
-
"@sixb/rules-worker": "0.2.
|
|
34
|
+
"@sixb/agent": "0.2.2",
|
|
35
|
+
"@sixb/agent-worker": "0.2.2",
|
|
36
|
+
"@sixb/app": "^0.2.1",
|
|
37
|
+
"@sixb/client": "^0.2.1",
|
|
38
|
+
"@sixb/core": "0.2.2",
|
|
39
|
+
"@sixb/cli-core": "^0.2.1",
|
|
40
|
+
"@sixb/orchestrator": "0.2.2",
|
|
41
|
+
"@sixb/pipeline-worker": "0.2.2",
|
|
42
|
+
"@sixb/projection-worker": "0.2.2",
|
|
43
|
+
"@sixb/rules-worker": "0.2.2",
|
|
44
44
|
"@sixb/sandboxes-local": "^0.2.0",
|
|
45
|
-
"@sixb/server": "0.2.
|
|
46
|
-
"@sixb/sync-worker": "0.2.
|
|
47
|
-
"@sixb/workflow-worker": "0.2.
|
|
45
|
+
"@sixb/server": "0.2.2",
|
|
46
|
+
"@sixb/sync-worker": "0.2.2",
|
|
47
|
+
"@sixb/workflow-worker": "0.2.2",
|
|
48
48
|
"create-sixb": "^0.2.0",
|
|
49
49
|
"react": "^19.2.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@sixb/deploy-ssh": "0.2.0",
|
|
53
|
-
"@sixb/desktop": "0.2.
|
|
54
|
-
"@sixb/ducklake": "0.2.
|
|
53
|
+
"@sixb/desktop": "0.2.1",
|
|
54
|
+
"@sixb/ducklake": "0.2.2",
|
|
55
55
|
"@types/bun": "latest",
|
|
56
56
|
"@types/react": "^19.0.0",
|
|
57
57
|
"typescript": "^5.7.0"
|
package/src/commands/agent.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
createAgentRunSocket,
|
|
6
6
|
createAgentThread,
|
|
7
7
|
decideAgentApproval,
|
|
8
|
+
getAgentRun,
|
|
8
9
|
getAgentThread,
|
|
9
10
|
listAgentThreadApprovals,
|
|
10
11
|
listAgentThreadMessages,
|
|
@@ -12,11 +13,12 @@ import {
|
|
|
12
13
|
listModels,
|
|
13
14
|
postAgentThreadMessage,
|
|
14
15
|
} from "@sixb/client"
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
16
|
+
import { type Connection, connect } from "../lib/connection"
|
|
17
|
+
import { errorMessage } from "../lib/errors"
|
|
18
|
+
import { thisComputer, thisComputerId } from "../runner/computer"
|
|
19
|
+
import { LocalRunner } from "../runner/local-runner"
|
|
17
20
|
import { toolLine } from "../tui/format"
|
|
18
21
|
import { liveRun, reduceLive, shownMessage } from "../tui/parts"
|
|
19
|
-
import { LocalRunner } from "../tui/runner"
|
|
20
22
|
import {
|
|
21
23
|
APPROVAL_MODES,
|
|
22
24
|
type ApprovalMode,
|
|
@@ -29,11 +31,16 @@ import { glyph, paint, palette, tone } from "../ui/theme"
|
|
|
29
31
|
|
|
30
32
|
/** Exit status when the turn stopped on calls only the person can decide, and nobody could ask. */
|
|
31
33
|
const EXIT_WAITING = 4
|
|
34
|
+
/** Exit status when the turn waits for a computer that isn't connected. */
|
|
35
|
+
const EXIT_OFFLINE = 5
|
|
36
|
+
/** How often this checks that something still holds the folder of a turn it waits for. */
|
|
37
|
+
const HOLDER_CHECK_MS = 1_000
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* `sixb agent "<message>"`: one message to the agent, answered in the terminal. The turn runs on
|
|
35
41
|
* 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.
|
|
42
|
+
* its answer to stdout, so the answer can be piped. A conversation elsewhere, or a folder a
|
|
43
|
+
* connected sixb holds, runs there, and this follows it.
|
|
37
44
|
*/
|
|
38
45
|
export async function runAgent(options: {
|
|
39
46
|
readonly text: readonly string[]
|
|
@@ -42,6 +49,8 @@ export async function runAgent(options: {
|
|
|
42
49
|
/** The turn's mode; without it, the person's in the thread applies, as for a message in the web. */
|
|
43
50
|
readonly approvalMode?: string
|
|
44
51
|
readonly json: boolean
|
|
52
|
+
/** Send it and exit, without following the turn. */
|
|
53
|
+
readonly detach: boolean
|
|
45
54
|
readonly apiUrl?: string
|
|
46
55
|
readonly profile?: string
|
|
47
56
|
}): Promise<void> {
|
|
@@ -58,7 +67,7 @@ export async function runAgent(options: {
|
|
|
58
67
|
)
|
|
59
68
|
}
|
|
60
69
|
const { client } = connection
|
|
61
|
-
const settings = await loadSettings(
|
|
70
|
+
const settings = await loadSettings()
|
|
62
71
|
// As the project keeps it, and the local sandbox compares it: its real path.
|
|
63
72
|
const folder = await realpath(process.cwd())
|
|
64
73
|
const models = (await listModels({ client })).data?.language ?? []
|
|
@@ -80,22 +89,17 @@ export async function runAgent(options: {
|
|
|
80
89
|
// Read as the person: it says the mode their turns run in there.
|
|
81
90
|
const { data: thread } = await getAgentThread({ client, path: { threadId }, throwOnError: true })
|
|
82
91
|
const onComputer = thread.runsOn === "computer"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
}
|
|
92
|
+
const place = thread.computer
|
|
93
|
+
if (onComputer && !place) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
"[SixbCLI] This conversation has no folder yet: open it with sixb in its folder, and press ctrl+f."
|
|
96
|
+
)
|
|
95
97
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
+
const here = onComputer && place?.id === (await thisComputerId()) && place.folder === folder
|
|
99
|
+
const runner = here
|
|
100
|
+
? new LocalRunner(connection, folder, (error) => step(tone.fail(errorMessage(error))))
|
|
98
101
|
: null
|
|
102
|
+
if (runner) runner.keepsAwake = settings.keepAwake
|
|
99
103
|
if (!options.json) {
|
|
100
104
|
const mode = approvalMode ?? thread.approvalMode
|
|
101
105
|
step(
|
|
@@ -120,16 +124,33 @@ export async function runAgent(options: {
|
|
|
120
124
|
throwOnError: true,
|
|
121
125
|
})
|
|
122
126
|
let runId: string | null = posted.run.id
|
|
127
|
+
if (options.detach) {
|
|
128
|
+
if (onComputer && !thread.computer?.online) step(tone.faint(waitingNote(thread.computer)))
|
|
129
|
+
printSent(thread.id, runId, options.json)
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
123
133
|
let followed: Awaited<ReturnType<typeof follow>> = "finished"
|
|
124
134
|
while (runId) {
|
|
125
|
-
//
|
|
126
|
-
const
|
|
127
|
-
|
|
135
|
+
// Only while this follows: once it stops, nothing may start a turn nobody follows.
|
|
136
|
+
const watching = new AbortController()
|
|
137
|
+
const stopWatching = () => watching.abort()
|
|
138
|
+
stop.signal.addEventListener("abort", stopWatching, { once: true })
|
|
139
|
+
const nobody =
|
|
140
|
+
onComputer && runnerUntilHeld(connection, thread.id, runId, runner, watching.signal)
|
|
141
|
+
followed = await follow(connection, runId, options.json, stop.signal, nobody || undefined)
|
|
142
|
+
stopWatching()
|
|
143
|
+
stop.signal.removeEventListener("abort", stopWatching)
|
|
144
|
+
if (followed === "offline") {
|
|
145
|
+
const { data } = await getAgentThread({ client, path: { threadId: thread.id } })
|
|
146
|
+
step(tone.faint(waitingNote(data?.computer ?? thread.computer)))
|
|
147
|
+
printSent(thread.id, runId, options.json)
|
|
148
|
+
process.exitCode = EXIT_OFFLINE
|
|
149
|
+
return
|
|
150
|
+
}
|
|
128
151
|
if (followed === "unclaimed") {
|
|
129
152
|
process.exitCode = 1
|
|
130
|
-
step(
|
|
131
|
-
tone.fail("This computer couldn't claim the turn: another runner holds it, or it ended.")
|
|
132
|
-
)
|
|
153
|
+
step(tone.fail("This computer couldn't claim the turn."))
|
|
133
154
|
return
|
|
134
155
|
}
|
|
135
156
|
if (followed !== "finished") break
|
|
@@ -148,28 +169,91 @@ export async function runAgent(options: {
|
|
|
148
169
|
}
|
|
149
170
|
}
|
|
150
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Watch a queued turn until something runs it. While a sixb holds its folder that's whose it is, even
|
|
174
|
+
* if busy: it runs one at a time, and taking the turn would run two. Once nothing does, which a
|
|
175
|
+
* crashed sixb's session reaches within a minute, this computer runs it if it's the place to, and
|
|
176
|
+
* otherwise it waits for a computer nobody has open. Null when the turn left the queue by itself.
|
|
177
|
+
* Rejects with the API's answer once it refuses these reads for good.
|
|
178
|
+
*/
|
|
179
|
+
async function runnerUntilHeld(
|
|
180
|
+
connection: Connection,
|
|
181
|
+
threadId: string,
|
|
182
|
+
runId: string,
|
|
183
|
+
runner: LocalRunner | null,
|
|
184
|
+
signal: AbortSignal
|
|
185
|
+
): Promise<"unclaimed" | "offline" | null> {
|
|
186
|
+
const { client } = connection
|
|
187
|
+
const readRun = () => getAgentRun({ client, path: { runId } })
|
|
188
|
+
while (!signal.aborted) {
|
|
189
|
+
const [threadRead, runRead] = await Promise.all([
|
|
190
|
+
getAgentThread({ client, path: { threadId } }),
|
|
191
|
+
readRun(),
|
|
192
|
+
])
|
|
193
|
+
if (signal.aborted) return null
|
|
194
|
+
if (refusedForGood(threadRead)) throw threadRead.error
|
|
195
|
+
if (refusedForGood(runRead)) throw runRead.error
|
|
196
|
+
const thread = threadRead.data
|
|
197
|
+
const status = runRead.data?.status
|
|
198
|
+
// Any other read that failed says nothing about who holds the folder: only a later one can.
|
|
199
|
+
if (thread && status) {
|
|
200
|
+
if (status !== "queued") return null
|
|
201
|
+
if (!thread.computer?.online) {
|
|
202
|
+
if (!runner) return "offline"
|
|
203
|
+
if (await runner.claim(runId)) return null
|
|
204
|
+
// A read that fails here can't say it left the queue, and nothing else here will run it.
|
|
205
|
+
const after = (await readRun()).data?.status
|
|
206
|
+
return after === undefined || after === "queued" ? "unclaimed" : null
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
await Bun.sleep(HOLDER_CHECK_MS)
|
|
210
|
+
}
|
|
211
|
+
return null
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** An answer that won't change by asking again: signed out, no access, or nothing there now. */
|
|
215
|
+
function refusedForGood(read: { readonly response?: Response }): boolean {
|
|
216
|
+
return [401, 403, 404].includes(read.response?.status ?? 0)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Where a turn waits, for a person reading why nothing is happening yet. */
|
|
220
|
+
function waitingNote(computer: { readonly name: string; readonly folder: string } | undefined) {
|
|
221
|
+
return computer
|
|
222
|
+
? `It waits until ${computer.folder} is connected on ${computer.name}: sixb connect there, or sixb with messages from the web on.`
|
|
223
|
+
: "It waits for its computer."
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** A turn asked for and not followed: what a script needs to find it again. */
|
|
227
|
+
function printSent(threadId: string, runId: string, json: boolean): void {
|
|
228
|
+
process.stdout.write(
|
|
229
|
+
json ? `${JSON.stringify({ threadId, runId, status: "queued" })}\n` : `${threadId}\n`
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
151
233
|
/**
|
|
152
234
|
* Show a turn's steps as they finish, until it ends, the stream fails, the person stops waiting,
|
|
153
|
-
* or `
|
|
235
|
+
* or `nobody` says nothing will run it. Rejects when `nobody` does.
|
|
154
236
|
*/
|
|
155
237
|
async function follow(
|
|
156
238
|
connection: Connection,
|
|
157
239
|
runId: string,
|
|
158
240
|
json: boolean,
|
|
159
241
|
signal: AbortSignal,
|
|
160
|
-
|
|
161
|
-
): Promise<"finished" | "stopped" | "failed" | "unclaimed"> {
|
|
242
|
+
nobody?: Promise<"unclaimed" | "offline" | null>
|
|
243
|
+
): Promise<"finished" | "stopped" | "failed" | "unclaimed" | "offline"> {
|
|
162
244
|
let live = liveRun(runId)
|
|
163
245
|
const shown = new Set<string>()
|
|
164
|
-
return new Promise((resolve) => {
|
|
246
|
+
return new Promise((resolve, reject) => {
|
|
165
247
|
let settled = false
|
|
166
|
-
const
|
|
248
|
+
const end = (answer: () => void) => {
|
|
167
249
|
if (settled) return
|
|
168
250
|
settled = true
|
|
169
251
|
socket.close()
|
|
170
252
|
signal.removeEventListener("abort", onAbort)
|
|
171
|
-
|
|
253
|
+
answer()
|
|
172
254
|
}
|
|
255
|
+
const settle = (outcome: "finished" | "stopped" | "failed" | "unclaimed" | "offline") =>
|
|
256
|
+
end(() => resolve(outcome))
|
|
173
257
|
const onAbort = () => settle("stopped")
|
|
174
258
|
const socket = createAgentRunSocket({
|
|
175
259
|
client: connection.client,
|
|
@@ -203,9 +287,12 @@ async function follow(
|
|
|
203
287
|
},
|
|
204
288
|
})
|
|
205
289
|
signal.addEventListener("abort", onAbort)
|
|
206
|
-
void
|
|
207
|
-
|
|
208
|
-
|
|
290
|
+
void nobody?.then(
|
|
291
|
+
(outcome) => {
|
|
292
|
+
if (outcome) settle(outcome)
|
|
293
|
+
},
|
|
294
|
+
(error: unknown) => end(() => reject(error))
|
|
295
|
+
)
|
|
209
296
|
})
|
|
210
297
|
}
|
|
211
298
|
|
|
@@ -232,7 +319,7 @@ async function afterTurn(
|
|
|
232
319
|
const approvals = data?.approvals ?? []
|
|
233
320
|
if (approvals.length === 0 || json || !process.stdin.isTTY) {
|
|
234
321
|
for (const approval of approvals) step(tone.warn(`? ${describe(approval.call)}`))
|
|
235
|
-
step(tone.faint(
|
|
322
|
+
step(tone.faint("Decide in the app, or open the conversation with sixb in its folder."))
|
|
236
323
|
process.exitCode = EXIT_WAITING
|
|
237
324
|
return null
|
|
238
325
|
}
|
|
@@ -329,10 +416,6 @@ async function readStdin(): Promise<string> {
|
|
|
329
416
|
return text.trim()
|
|
330
417
|
}
|
|
331
418
|
|
|
332
|
-
function errorText(error: unknown): string {
|
|
333
|
-
return error instanceof Error ? error.message : String(error)
|
|
334
|
-
}
|
|
335
|
-
|
|
336
419
|
/**
|
|
337
420
|
* The answer as a terminal shows it: bold and inline code styled, their markers gone. Piped, the
|
|
338
421
|
* answer stays the markdown it is.
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { realpath, stat } from "node:fs/promises"
|
|
2
|
+
import { homedir } from "node:os"
|
|
3
|
+
import { resolve } from "node:path"
|
|
4
|
+
import { createInterface } from "node:readline/promises"
|
|
5
|
+
import { CliError } from "@sixb/cli-core"
|
|
6
|
+
import { type Connection, connect } from "../lib/connection"
|
|
7
|
+
import { readAllowedFolders, setFoldersAllowed } from "../runner/allowed-folders"
|
|
8
|
+
import { thisComputer } from "../runner/computer"
|
|
9
|
+
import {
|
|
10
|
+
ComputerConnection,
|
|
11
|
+
type ComputerEvent,
|
|
12
|
+
EXIT_SIGNED_OUT,
|
|
13
|
+
} from "../runner/computer-connection"
|
|
14
|
+
import { stopInTime, stopOnHangUp } from "../runner/local-runner"
|
|
15
|
+
import { shortPath } from "../tui/format"
|
|
16
|
+
import { loadSettings } from "../tui/settings"
|
|
17
|
+
import { glyph, tone } from "../ui/theme"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* `sixb connect [folder...]`: keep this computer available without `sixb` open. Turns sent from
|
|
21
|
+
* elsewhere to conversations in the allowed folders run here until this stops. It stays in the
|
|
22
|
+
* foreground: whatever should keep it running starts it, and sees what it prints.
|
|
23
|
+
*/
|
|
24
|
+
export async function runConnect(options: {
|
|
25
|
+
readonly folders: readonly string[]
|
|
26
|
+
readonly yes: boolean
|
|
27
|
+
readonly json: boolean
|
|
28
|
+
readonly apiUrl?: string
|
|
29
|
+
readonly profile?: string
|
|
30
|
+
}): Promise<void> {
|
|
31
|
+
const connection = await connect(options)
|
|
32
|
+
if ("reason" in connection) {
|
|
33
|
+
throw connection.reason === "unreachable"
|
|
34
|
+
? refusal(`[SixbCLI] Sixb isn't answering at ${connection.apiUrl}.`)
|
|
35
|
+
: refusal(
|
|
36
|
+
`[SixbCLI] Sign in first: sixb login ${connection.apiUrl || "<api-url>"}.`,
|
|
37
|
+
EXIT_SIGNED_OUT
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await allowFolders(connection, options)
|
|
42
|
+
|
|
43
|
+
const settings = await loadSettings()
|
|
44
|
+
const report = options.json ? printJson : printLine
|
|
45
|
+
let finish: (code: number) => void = () => {}
|
|
46
|
+
const finished = new Promise<number>((resolve) => {
|
|
47
|
+
finish = resolve
|
|
48
|
+
})
|
|
49
|
+
const computer = new ComputerConnection(
|
|
50
|
+
connection,
|
|
51
|
+
(event) => {
|
|
52
|
+
if (event.type === "signed-out") finish(EXIT_SIGNED_OUT)
|
|
53
|
+
report(event)
|
|
54
|
+
},
|
|
55
|
+
settings.keepAwake
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
const unhook = stopOnHangUp(
|
|
59
|
+
() => computer,
|
|
60
|
+
(signal) => finish(signal === "SIGHUP" ? 129 : 143)
|
|
61
|
+
)
|
|
62
|
+
// Ctrl+C is how this is meant to stop; a second one doesn't wait for a turn to record its end.
|
|
63
|
+
process.once("SIGINT", () => {
|
|
64
|
+
process.once("SIGINT", () => process.exit(130))
|
|
65
|
+
void stopInTime(computer).finally(() => finish(0))
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
if (!options.json) {
|
|
69
|
+
const { name } = await thisComputer()
|
|
70
|
+
say(
|
|
71
|
+
`${tone.blue(glyph.mark)} ${tone.strong(name)} ${tone.faint(`connected to ${connection.project.id}. ctrl+c to stop.`)}`
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
await computer.start()
|
|
75
|
+
|
|
76
|
+
const code = await finished
|
|
77
|
+
unhook()
|
|
78
|
+
if (code === EXIT_SIGNED_OUT) await stopInTime(computer)
|
|
79
|
+
process.exit(code)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Add what was named to the folders allowed for this project, asking first, or offer this one if
|
|
84
|
+
* there are none.
|
|
85
|
+
*/
|
|
86
|
+
async function allowFolders(
|
|
87
|
+
connection: Connection,
|
|
88
|
+
options: {
|
|
89
|
+
readonly folders: readonly string[]
|
|
90
|
+
readonly yes: boolean
|
|
91
|
+
readonly json: boolean
|
|
92
|
+
}
|
|
93
|
+
): Promise<void> {
|
|
94
|
+
const project = connection.project.id
|
|
95
|
+
const allowed = await readAllowedFolders(connection).catch((error: unknown) => {
|
|
96
|
+
throw refusal(
|
|
97
|
+
`[SixbCLI] Could not read your allowed folders. ${error instanceof Error ? error.message : ""}`
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
const named = [...new Set(await Promise.all(options.folders.map(realFolder)))]
|
|
101
|
+
const interactive = process.stdin.isTTY && !options.json
|
|
102
|
+
const newlyNamed = named.filter((folder) => !allowed.includes(folder))
|
|
103
|
+
|
|
104
|
+
if (newlyNamed.length > 0 && !options.yes && !interactive) {
|
|
105
|
+
throw refusal(
|
|
106
|
+
`[SixbCLI] ${newlyNamed.join(", ")} isn't allowed for ${project} yet: run sixb connect in a terminal to choose it, or pass --yes.`
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
const chosen: string[] = options.yes ? [...newlyNamed] : [...(await askEach(newlyNamed, project))]
|
|
110
|
+
// Nothing named and nothing allowed: this folder is the one to offer, to a person, never by --yes.
|
|
111
|
+
if (named.length === 0 && allowed.length === 0 && interactive) {
|
|
112
|
+
chosen.push(...(await askEach([await realFolder(".")], project)))
|
|
113
|
+
}
|
|
114
|
+
if (chosen.length > 0) await setFoldersAllowed(connection, chosen, true)
|
|
115
|
+
if (allowed.length + chosen.length === 0) {
|
|
116
|
+
throw refusal(
|
|
117
|
+
`[SixbCLI] No folders are allowed for ${project}, so nothing would run here. Choose one: sixb connect <folder>.`
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function askEach(folders: readonly string[], project: string): Promise<readonly string[]> {
|
|
123
|
+
if (folders.length === 0) return []
|
|
124
|
+
const prompt = createInterface({ input: process.stdin, output: process.stderr })
|
|
125
|
+
const chosen: string[] = []
|
|
126
|
+
try {
|
|
127
|
+
say(
|
|
128
|
+
tone.muted(
|
|
129
|
+
`Messages sent to ${project} from the web and your other devices will run in a folder you allow, on this computer, as you. The agent's commands run there without asking.`
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
for (const folder of folders) {
|
|
133
|
+
const answer = await prompt.question(
|
|
134
|
+
`Allow ${tone.strong(shown(folder))} for ${project}? [y/N] `
|
|
135
|
+
)
|
|
136
|
+
if (answer.trim().toLowerCase() === "y") chosen.push(folder)
|
|
137
|
+
}
|
|
138
|
+
} finally {
|
|
139
|
+
prompt.close()
|
|
140
|
+
}
|
|
141
|
+
return chosen
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** As the project keeps it, and the local sandbox compares it: its real path. */
|
|
145
|
+
async function realFolder(folder: string): Promise<string> {
|
|
146
|
+
const path = resolve(folder)
|
|
147
|
+
const entry = await stat(path).catch(() => null)
|
|
148
|
+
if (!entry?.isDirectory()) throw refusal(`[SixbCLI] ${path} isn't a folder.`)
|
|
149
|
+
return realpath(path)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function refusal(message: string, exitCode = 1): CliError {
|
|
153
|
+
return new CliError({ code: "connect", message }, exitCode)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function shown(folder: string): string {
|
|
157
|
+
return shortPath(folder, homedir(), 72) || folder
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function say(line: string): void {
|
|
161
|
+
process.stderr.write(`${line}\n`)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function printJson(event: ComputerEvent): void {
|
|
165
|
+
process.stdout.write(`${JSON.stringify(event)}\n`)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function printLine(event: ComputerEvent): void {
|
|
169
|
+
switch (event.type) {
|
|
170
|
+
case "folders":
|
|
171
|
+
say(
|
|
172
|
+
event.folders.length > 0
|
|
173
|
+
? ` ${tone.muted("Running messages from the web in")} ${event.folders.map(shown).join(", ")}`
|
|
174
|
+
: tone.warn(" No allowed folders exist now, so nothing runs here.")
|
|
175
|
+
)
|
|
176
|
+
return
|
|
177
|
+
case "turn.started":
|
|
178
|
+
say(` ${tone.blue(glyph.live)} ${shown(event.folder)} ${tone.faint(event.threadId)}`)
|
|
179
|
+
return
|
|
180
|
+
case "turn.ended":
|
|
181
|
+
say(
|
|
182
|
+
` ${event.ran ? tone.ok(glyph.ok) : tone.fail(glyph.fail)} ${shown(event.folder)} ${tone.faint(event.threadId)}`
|
|
183
|
+
)
|
|
184
|
+
return
|
|
185
|
+
case "session.lost":
|
|
186
|
+
say(` ${tone.warn(glyph.warn)} ${shown(event.folder)} ${tone.muted(event.message)}`)
|
|
187
|
+
return
|
|
188
|
+
case "session.back":
|
|
189
|
+
say(` ${tone.ok(glyph.ok)} ${shown(event.folder)} ${tone.muted("back online")}`)
|
|
190
|
+
return
|
|
191
|
+
case "signed-out":
|
|
192
|
+
say(tone.fail(" Your sign-in ended. Sign in again with sixb login, then reconnect."))
|
|
193
|
+
return
|
|
194
|
+
case "error":
|
|
195
|
+
say(` ${tone.fail(glyph.fail)} ${tone.muted(event.message)}`)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -14,6 +14,7 @@ export async function runDbPrepare(options: { entry?: string } = {}): Promise<vo
|
|
|
14
14
|
const result = await prepareObjectQueries({
|
|
15
15
|
projectId: sixb.id,
|
|
16
16
|
ontology: sixb.definitions.ontology,
|
|
17
|
+
security: sixb.definitions.security,
|
|
17
18
|
storage: sixb.storage,
|
|
18
19
|
})
|
|
19
20
|
console.info(
|
package/src/commands/desktop.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path"
|
|
2
2
|
import { DEPLOY_CONFIG_FILE, loadDeployConfig } from "../lib/deploy-config"
|
|
3
3
|
import { deployPublicOrigins } from "../lib/deploy-release"
|
|
4
|
-
import { loadDesktop } from "../lib/desktop"
|
|
4
|
+
import { DESKTOP_RUNNER_ENTRY, loadDesktop } from "../lib/desktop"
|
|
5
5
|
import { SixbCliError } from "../lib/errors"
|
|
6
6
|
import { configuredOrigin } from "../lib/public-origin"
|
|
7
7
|
import { keyValueResultView, renderStatic } from "../ui"
|
|
@@ -20,6 +20,7 @@ export async function runDesktopBuild(options: DesktopBuildOptions = {}): Promis
|
|
|
20
20
|
projectRoot,
|
|
21
21
|
appUrl: origins.app,
|
|
22
22
|
apiOrigin: origins.api,
|
|
23
|
+
runnerEntry: DESKTOP_RUNNER_ENTRY,
|
|
23
24
|
})
|
|
24
25
|
|
|
25
26
|
await renderStatic(
|
package/src/index.tsx
CHANGED
|
@@ -226,6 +226,19 @@ async function main(): Promise<void> {
|
|
|
226
226
|
cloud: hasFlag("cloud"),
|
|
227
227
|
approvalMode: getFlag("approval-mode"),
|
|
228
228
|
json: hasFlag("json"),
|
|
229
|
+
detach: hasFlag("detach"),
|
|
230
|
+
apiUrl: getFlag("api-url"),
|
|
231
|
+
profile: getFlag("profile"),
|
|
232
|
+
})
|
|
233
|
+
break
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
case "connect": {
|
|
237
|
+
const { runConnect } = await import("./commands/connect")
|
|
238
|
+
await runConnect({
|
|
239
|
+
folders: positionals,
|
|
240
|
+
yes: hasFlag("yes"),
|
|
241
|
+
json: hasFlag("json"),
|
|
229
242
|
apiUrl: getFlag("api-url"),
|
|
230
243
|
profile: getFlag("profile"),
|
|
231
244
|
})
|