@sixb/cli 0.2.5 → 0.2.6
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/api.d.ts.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/db-migrate.d.ts +2 -0
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +5 -0
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/role-lifecycle.d.ts +8 -1
- package/dist/lib/role-lifecycle.d.ts.map +1 -1
- package/dist/lib/storage-migration.d.ts +7 -0
- package/dist/lib/storage-migration.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +1 -0
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/runner/computer-connection.d.ts.map +1 -1
- package/dist/tui/app.d.ts +2 -0
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/moves.d.ts +62 -0
- package/dist/tui/moves.d.ts.map +1 -0
- package/dist/tui/parts.d.ts.map +1 -1
- package/dist/tui/settings.d.ts +2 -0
- package/dist/tui/settings.d.ts.map +1 -1
- package/dist/tui/transcript.d.ts +13 -6
- package/dist/tui/transcript.d.ts.map +1 -1
- package/dist/ui/screens.d.ts +8 -0
- package/dist/ui/screens.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/commands/agent.ts +1 -1
- package/src/commands/api.ts +20 -10
- package/src/commands/app.ts +15 -7
- package/src/commands/db-migrate.ts +25 -1
- package/src/commands/dev-runner.ts +1 -1
- package/src/commands/worker-group.ts +36 -9
- package/src/commands/worker.ts +27 -9
- package/src/index.tsx +1 -1
- package/src/lib/command-line.ts +6 -1
- package/src/lib/role-lifecycle.ts +48 -8
- package/src/lib/storage-migration.ts +33 -1
- package/src/lib/worker-registry.ts +4 -1
- package/src/runner/computer-connection.ts +7 -1
- package/src/tui/app.tsx +183 -38
- package/src/tui/moves.ts +221 -0
- package/src/tui/parts.ts +7 -0
- package/src/tui/settings.ts +5 -0
- package/src/tui/transcript.tsx +50 -14
- package/src/ui/screens.ts +23 -0
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
|
|
2
2
|
import { resolveRuntimeEntry } from "../lib/production"
|
|
3
|
-
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
3
|
+
import { resolveDrainTimeoutMs, runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
4
|
+
|
|
5
|
+
// Leaves 10 s inside the default 70 s kill timeout for abort finalization and provider shutdown.
|
|
6
|
+
const DEFAULT_WORKER_DRAIN_TIMEOUT_MS = 60_000
|
|
7
|
+
|
|
4
8
|
import { recordApiPublicOrigin, stopSixbProviders, waitForWorkerFailure } from "../lib/runtime"
|
|
5
9
|
import { assertShareableProviders } from "../lib/shareable-providers"
|
|
6
10
|
import { migrateStorageForRole } from "../lib/storage-migration"
|
|
@@ -57,8 +61,18 @@ export async function runWorkerGroup(options: WorkerGroupOptions = {}) {
|
|
|
57
61
|
let sixb: LoadedSixbHost | null = null
|
|
58
62
|
let workers: QueueWorkerProcess[] = []
|
|
59
63
|
|
|
60
|
-
async function stopWorkersAndProviders() {
|
|
61
|
-
await Promise.all(
|
|
64
|
+
async function stopWorkersAndProviders(drainTimeoutMs?: number) {
|
|
65
|
+
await Promise.all(
|
|
66
|
+
workers.map((worker) =>
|
|
67
|
+
stopQuietly(async () => {
|
|
68
|
+
if (drainTimeoutMs !== undefined) {
|
|
69
|
+
await worker.drain(drainTimeoutMs)
|
|
70
|
+
} else {
|
|
71
|
+
await worker.stop()
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
)
|
|
62
76
|
if (sixb) {
|
|
63
77
|
await stopSixbProviders(sixb)
|
|
64
78
|
}
|
|
@@ -127,12 +141,25 @@ export async function runWorkerGroup(options: WorkerGroupOptions = {}) {
|
|
|
127
141
|
)
|
|
128
142
|
|
|
129
143
|
await Promise.race([
|
|
130
|
-
runUntilSignal(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
runUntilSignal(
|
|
145
|
+
async (signal) => {
|
|
146
|
+
app.stop()
|
|
147
|
+
printStopping("worker-group")
|
|
148
|
+
const drainTimeoutMs =
|
|
149
|
+
signal === "SIGTERM"
|
|
150
|
+
? resolveDrainTimeoutMs(DEFAULT_WORKER_DRAIN_TIMEOUT_MS)
|
|
151
|
+
: undefined
|
|
152
|
+
await stopWorkersAndProviders(drainTimeoutMs)
|
|
153
|
+
sixb = null
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
onInterrupt: () => {
|
|
157
|
+
for (const worker of workers) {
|
|
158
|
+
void stopQuietly(() => worker.stop())
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
),
|
|
136
163
|
...workers.map(waitForWorkerFailure),
|
|
137
164
|
])
|
|
138
165
|
} catch (error) {
|
package/src/commands/worker.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { SixbCliError } from "../lib/errors"
|
|
2
2
|
import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
|
|
3
3
|
import { resolveRuntimeEntry } from "../lib/production"
|
|
4
|
-
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
4
|
+
import { resolveDrainTimeoutMs, runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
5
|
+
|
|
6
|
+
// Leaves 10 s inside the default 70 s kill timeout for abort finalization and provider shutdown.
|
|
7
|
+
const DEFAULT_WORKER_DRAIN_TIMEOUT_MS = 60_000
|
|
8
|
+
|
|
5
9
|
import { recordApiPublicOrigin, stopSixbProviders, waitForWorkerFailure } from "../lib/runtime"
|
|
6
10
|
import { assertShareableProviders } from "../lib/shareable-providers"
|
|
7
11
|
import { migrateStorageForRole } from "../lib/storage-migration"
|
|
@@ -97,15 +101,29 @@ export async function runWorker(options: WorkerOptions = {}) {
|
|
|
97
101
|
)
|
|
98
102
|
|
|
99
103
|
await Promise.race([
|
|
100
|
-
runUntilSignal(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
runUntilSignal(
|
|
105
|
+
async (signal) => {
|
|
106
|
+
app.stop()
|
|
107
|
+
printStopping("worker")
|
|
108
|
+
if (signal === "SIGTERM") {
|
|
109
|
+
const timeoutMs = resolveDrainTimeoutMs(DEFAULT_WORKER_DRAIN_TIMEOUT_MS)
|
|
110
|
+
await stopQuietly(async () => {
|
|
111
|
+
await worker?.drain(timeoutMs)
|
|
112
|
+
})
|
|
113
|
+
} else {
|
|
114
|
+
await stopQuietly(() => worker?.stop() ?? Promise.resolve())
|
|
115
|
+
}
|
|
116
|
+
if (sixb) {
|
|
117
|
+
await stopSixbProviders(sixb)
|
|
118
|
+
}
|
|
119
|
+
sixb = null
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
onInterrupt: () => {
|
|
123
|
+
void stopQuietly(() => worker?.stop() ?? Promise.resolve())
|
|
124
|
+
},
|
|
106
125
|
}
|
|
107
|
-
|
|
108
|
-
}),
|
|
126
|
+
),
|
|
109
127
|
waitForWorkerFailure(worker),
|
|
110
128
|
])
|
|
111
129
|
} catch (error) {
|
package/src/index.tsx
CHANGED
|
@@ -380,7 +380,7 @@ async function main(): Promise<void> {
|
|
|
380
380
|
|
|
381
381
|
case "db:migrate": {
|
|
382
382
|
const { runDbMigrate } = await import("./commands/db-migrate")
|
|
383
|
-
await runDbMigrate({ entry: getFlag("entry") })
|
|
383
|
+
await runDbMigrate({ entry: getFlag("entry"), check: hasFlag("check") })
|
|
384
384
|
break
|
|
385
385
|
}
|
|
386
386
|
|
package/src/lib/command-line.ts
CHANGED
|
@@ -186,6 +186,11 @@ export const CLI_OPTION_DEFINITIONS = {
|
|
|
186
186
|
summary: "Recent log lines to print (default: 100)",
|
|
187
187
|
kind: "string",
|
|
188
188
|
},
|
|
189
|
+
check: {
|
|
190
|
+
syntax: "--check",
|
|
191
|
+
summary: "Only report pending migrations, exiting with 3 when there are some",
|
|
192
|
+
kind: "boolean",
|
|
193
|
+
},
|
|
189
194
|
"dry-run": {
|
|
190
195
|
syntax: "--dry-run",
|
|
191
196
|
summary: "Show what would change without changing it",
|
|
@@ -583,7 +588,7 @@ const commandTree: readonly CommandNode[] = [
|
|
|
583
588
|
),
|
|
584
589
|
command("db:migrate", "Run database migrations ahead of a role", {
|
|
585
590
|
path: ["db", "migrate"],
|
|
586
|
-
options: ["entry"],
|
|
591
|
+
options: ["entry", "check"],
|
|
587
592
|
rootHelpLabel: "db migrate",
|
|
588
593
|
}),
|
|
589
594
|
],
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { appendFileSync } from "node:fs"
|
|
2
2
|
|
|
3
3
|
// Kept apart from `runtime.ts`, which imports every worker package: `app` serves static assets for
|
|
4
|
-
// as long as it runs and must not hold that module graph to reuse these
|
|
4
|
+
// as long as it runs and must not hold that module graph to reuse these helpers.
|
|
5
|
+
|
|
6
|
+
export type ShutdownSignal = "SIGINT" | "SIGTERM"
|
|
7
|
+
|
|
8
|
+
export interface RunUntilSignalOptions {
|
|
9
|
+
/** Called if `SIGINT` arrives while a `SIGTERM` drain is already in progress. */
|
|
10
|
+
readonly onInterrupt?: () => void
|
|
11
|
+
}
|
|
5
12
|
|
|
6
13
|
export async function stopQuietly(stopFn: (() => Promise<void>) | undefined | null): Promise<void> {
|
|
7
14
|
if (!stopFn) return
|
|
8
15
|
await stopFn().catch(() => {})
|
|
9
16
|
}
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
/** Reads an optional millisecond drain bound from `SIXB_DRAIN_TIMEOUT_MS`. */
|
|
19
|
+
export function resolveDrainTimeoutMs(fallbackMs: number): number {
|
|
20
|
+
const raw = process.env.SIXB_DRAIN_TIMEOUT_MS?.trim()
|
|
21
|
+
if (!raw) return fallbackMs
|
|
22
|
+
const parsed = Number(raw)
|
|
23
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
24
|
+
throw new Error("[SixbCLI] SIXB_DRAIN_TIMEOUT_MS must be a non-negative integer.")
|
|
25
|
+
}
|
|
26
|
+
return parsed
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function runUntilSignal(
|
|
30
|
+
onShutdown: (signal: ShutdownSignal) => Promise<void>,
|
|
31
|
+
options: RunUntilSignalOptions = {}
|
|
32
|
+
): Promise<void> {
|
|
12
33
|
// Test-only readiness hook: e2e tests detect that a long-running role finished
|
|
13
34
|
// starting by watching for this marker, rather than on the wording of what the
|
|
14
35
|
// role prints. Unset in production, so this is a no-op there.
|
|
@@ -20,14 +41,33 @@ export async function runUntilSignal(onShutdown: () => Promise<void>): Promise<v
|
|
|
20
41
|
await new Promise<void>((resolvePromise) => {
|
|
21
42
|
let shuttingDown = false
|
|
22
43
|
|
|
23
|
-
const
|
|
24
|
-
|
|
44
|
+
const handle = (signal: ShutdownSignal) => {
|
|
45
|
+
// The SIGTERM listener stays until the shutdown ends: without one, a repeated SIGTERM takes
|
|
46
|
+
// the default action and kills the role mid-drain. When a deployment stops, systemd and the
|
|
47
|
+
// deploy supervisor each send one.
|
|
48
|
+
if (shuttingDown) {
|
|
49
|
+
if (signal === "SIGINT") {
|
|
50
|
+
process.off("SIGINT", onSigint)
|
|
51
|
+
options.onInterrupt?.()
|
|
52
|
+
}
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
25
56
|
shuttingDown = true
|
|
26
|
-
|
|
27
|
-
|
|
57
|
+
if (signal === "SIGINT") process.off("SIGINT", onSigint)
|
|
58
|
+
|
|
59
|
+
void Promise.resolve()
|
|
60
|
+
.then(() => onShutdown(signal))
|
|
61
|
+
.finally(() => {
|
|
62
|
+
process.off("SIGINT", onSigint)
|
|
63
|
+
process.off("SIGTERM", onSigterm)
|
|
64
|
+
resolvePromise()
|
|
65
|
+
})
|
|
28
66
|
}
|
|
29
67
|
|
|
30
|
-
|
|
31
|
-
|
|
68
|
+
const onSigint = () => handle("SIGINT")
|
|
69
|
+
const onSigterm = () => handle("SIGTERM")
|
|
70
|
+
process.on("SIGINT", onSigint)
|
|
71
|
+
process.on("SIGTERM", onSigterm)
|
|
32
72
|
})
|
|
33
73
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isMigrationCapableStorage,
|
|
3
|
+
type MigrationStatus,
|
|
4
|
+
migrateStorage,
|
|
5
|
+
type Storage,
|
|
6
|
+
} from "@sixb/core"
|
|
2
7
|
import { SixbCliError } from "./errors"
|
|
3
8
|
import type { LoadedSixbHost } from "./loadSixb"
|
|
4
9
|
import type { StorageSchemaRole } from "./production-roles"
|
|
@@ -92,6 +97,33 @@ export async function migrateStorageForRole(
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
/**
|
|
101
|
+
* The storage adapters `sixb db migrate` would bring up to date, read without touching the
|
|
102
|
+
* schema. A state a migration does not resolve, such as a history this build does not know,
|
|
103
|
+
* throws: migrating would fail too.
|
|
104
|
+
*/
|
|
105
|
+
export async function findPendingMigrations(storage: Storage): Promise<readonly MigrationStatus[]> {
|
|
106
|
+
if (!isMigrationCapableStorage(storage)) return []
|
|
107
|
+
|
|
108
|
+
const statuses = await Promise.all(storage.migrators.map((migrator) => migrator.status()))
|
|
109
|
+
const pending: MigrationStatus[] = []
|
|
110
|
+
|
|
111
|
+
for (const status of statuses) {
|
|
112
|
+
if (status.state === "current") continue
|
|
113
|
+
|
|
114
|
+
if (status.state === "pending" || status.state === "uninitialized") {
|
|
115
|
+
pending.push(status)
|
|
116
|
+
continue
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
throw new SixbCliError(`[SixbCLI] ${status.adapterId} cannot be migrated: ${status.state}.`, {
|
|
120
|
+
remediation: status.reason,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return pending
|
|
125
|
+
}
|
|
126
|
+
|
|
95
127
|
async function runMigration(sixb: LoadedSixbHost, role: StorageSchemaRole) {
|
|
96
128
|
try {
|
|
97
129
|
return await migrateStorage(sixb.storage, {
|
|
@@ -24,7 +24,10 @@ export const WORKER_TYPES = [
|
|
|
24
24
|
export type WorkerType = (typeof WORKER_TYPES)[number]
|
|
25
25
|
|
|
26
26
|
export type WorkerConcurrency = Readonly<Partial<Record<WorkerType, number>>>
|
|
27
|
-
export type QueueWorkerProcess = Worker & {
|
|
27
|
+
export type QueueWorkerProcess = Worker & {
|
|
28
|
+
readonly concurrency: number
|
|
29
|
+
drain(timeoutMs?: number): Promise<boolean>
|
|
30
|
+
}
|
|
28
31
|
|
|
29
32
|
export interface WorkerCreationOptions {
|
|
30
33
|
readonly agentApiBaseUrl?: string
|
|
@@ -74,6 +74,12 @@ export class ComputerConnection {
|
|
|
74
74
|
this.onEvent({ type: "error", message: errorMessage(error) })
|
|
75
75
|
)
|
|
76
76
|
},
|
|
77
|
+
// A conversation moved to a folder here with a turn waiting runs at once, not at renewal.
|
|
78
|
+
onThreadMoved: (event) => {
|
|
79
|
+
void this.route(event.threadId).catch((error: unknown) =>
|
|
80
|
+
this.onEvent({ type: "error", message: errorMessage(error) })
|
|
81
|
+
)
|
|
82
|
+
},
|
|
77
83
|
})
|
|
78
84
|
}
|
|
79
85
|
|
|
@@ -173,7 +179,7 @@ export class ComputerConnection {
|
|
|
173
179
|
}
|
|
174
180
|
|
|
175
181
|
/** Each folder's runner would read the thread to learn it isn't theirs: read it once. */
|
|
176
|
-
private async route(threadId: string, runId
|
|
182
|
+
private async route(threadId: string, runId?: string): Promise<void> {
|
|
177
183
|
const { data: thread } = await getAgentThread({
|
|
178
184
|
client: this.connection.client,
|
|
179
185
|
path: { threadId },
|
package/src/tui/app.tsx
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
listAgentThreadRuns,
|
|
22
22
|
listAgentThreads,
|
|
23
23
|
listModels,
|
|
24
|
+
moveAgentThreadToCloud,
|
|
24
25
|
moveAgentThreadToComputer,
|
|
25
26
|
postAgentThreadMessage,
|
|
26
27
|
setAgentThreadApprovalMode,
|
|
@@ -44,6 +45,7 @@ import {
|
|
|
44
45
|
pickedAnswer,
|
|
45
46
|
shortPath,
|
|
46
47
|
} from "./format"
|
|
48
|
+
import { folderName, movedNotice, placeNames } from "./moves"
|
|
47
49
|
import { Palette, type PaletteItem } from "./palette"
|
|
48
50
|
import { type LiveRun, liveRun, reduceLive, type ShownMessage, shownMessage } from "./parts"
|
|
49
51
|
import {
|
|
@@ -101,6 +103,8 @@ export function Workspace(props: WorkspaceProps) {
|
|
|
101
103
|
} | null>(null)
|
|
102
104
|
const [quitArmed, setQuitArmed] = useState(false)
|
|
103
105
|
const draft = useRef<(() => boolean) | null>(null)
|
|
106
|
+
// The open conversation's moves, which take the place of where new ones start in ctrl+p.
|
|
107
|
+
const threadMoves = useRef<readonly PaletteItem[] | null>(null)
|
|
104
108
|
|
|
105
109
|
const setSettings = useCallback((change: (current: Settings) => Settings) => {
|
|
106
110
|
setSettingsState((current) => {
|
|
@@ -389,6 +393,7 @@ export function Workspace(props: WorkspaceProps) {
|
|
|
389
393
|
threadId={screen.threadId}
|
|
390
394
|
approval={approval}
|
|
391
395
|
onThreadRead={readApproval}
|
|
396
|
+
paletteMoves={threadMoves}
|
|
392
397
|
/>
|
|
393
398
|
)}
|
|
394
399
|
{notice || quitArmed ? (
|
|
@@ -420,6 +425,7 @@ export function Workspace(props: WorkspaceProps) {
|
|
|
420
425
|
models,
|
|
421
426
|
newConversation: () => setScreen({ kind: "home" }),
|
|
422
427
|
open: setDialog,
|
|
428
|
+
threadMoves: openThreadId === null ? null : threadMoves.current,
|
|
423
429
|
setPlace: (place) => setSettings((current) => ({ ...current, place })),
|
|
424
430
|
toggleKeepAwake: () =>
|
|
425
431
|
setSettings((current) => {
|
|
@@ -754,6 +760,8 @@ function ThreadView(
|
|
|
754
760
|
readonly approval: ThreadApproval | null
|
|
755
761
|
/** The thread as read; `raised` after "always", which raised its mode there. */
|
|
756
762
|
readonly onThreadRead: (thread: Thread, raised: boolean) => void
|
|
763
|
+
/** Where it lists its moves for the ctrl+p palette while it is open. */
|
|
764
|
+
readonly paletteMoves: { current: readonly PaletteItem[] | null }
|
|
757
765
|
}
|
|
758
766
|
) {
|
|
759
767
|
const { connection, runner, colors, syntax, settings, models, threadId } = props
|
|
@@ -766,26 +774,15 @@ function ThreadView(
|
|
|
766
774
|
const [context, setContext] = useState<ContextUse | null>(null)
|
|
767
775
|
const [live, setLive] = useState<LiveRun | null>(null)
|
|
768
776
|
const [stopArmed, setStopArmed] = useState(false)
|
|
777
|
+
const [moveArmed, setMoveArmed] = useState(false)
|
|
769
778
|
const [typed, setTyped] = useState("")
|
|
770
779
|
const [contextOpen, setContextOpen] = useState(false)
|
|
771
780
|
const [stopOpen, setStopOpen] = useState(false)
|
|
772
|
-
// A conversation adds what only it can show: what it uses of its model's context.
|
|
773
|
-
const slashCommands = useMemo(
|
|
774
|
-
() => [
|
|
775
|
-
...props.slashCommands,
|
|
776
|
-
{
|
|
777
|
-
name: "context",
|
|
778
|
-
description: "What the conversation uses of the model's context",
|
|
779
|
-
run: () => setContextOpen(true),
|
|
780
|
-
},
|
|
781
|
-
],
|
|
782
|
-
[props.slashCommands]
|
|
783
|
-
)
|
|
784
|
-
const slash = useSlashMenu(slashCommands, typed)
|
|
785
781
|
const scroll = useRef<ScrollBoxRenderable>(null)
|
|
786
782
|
|
|
787
783
|
const mine = thread !== null && owns(connection, thread)
|
|
788
784
|
const onComputer = thread?.runsOn === "computer"
|
|
785
|
+
const names = placeNames({ thread, computerId: props.computerId, mine })
|
|
789
786
|
|
|
790
787
|
// The commands its turns left running here, ticking while they run.
|
|
791
788
|
const [background, setBackground] = useState<readonly BackgroundCommand[]>(() =>
|
|
@@ -871,18 +868,134 @@ function ThreadView(
|
|
|
871
868
|
if (activeRunId && runsHere && queued && continueFromWeb)
|
|
872
869
|
void runner.claimElsewhere(activeRunId)
|
|
873
870
|
}, [activeRunId, runsHere, queued, continueFromWeb, runner])
|
|
871
|
+
|
|
872
|
+
// A turn holds the conversation where it is: say what frees it, not the server's words.
|
|
873
|
+
const moveRefused = (error: unknown) => {
|
|
874
|
+
const busy =
|
|
875
|
+
typeof error === "object" &&
|
|
876
|
+
error !== null &&
|
|
877
|
+
"code" in error &&
|
|
878
|
+
error.code === "active_run_exists"
|
|
879
|
+
if (!busy) return props.say(errorText(error), "error")
|
|
880
|
+
|
|
881
|
+
props.say(
|
|
882
|
+
approvals.length > 0
|
|
883
|
+
? "A request waits for your approval: answer it, then press ctrl+g twice to move it."
|
|
884
|
+
: "A reply is running: press esc twice to stop it, then ctrl+g twice to move it.",
|
|
885
|
+
"error"
|
|
886
|
+
)
|
|
887
|
+
}
|
|
888
|
+
|
|
874
889
|
// Its turns move to this computer, which alone claims them from now on, and to this folder.
|
|
875
890
|
const moveHere = async () => {
|
|
891
|
+
const moved = movedNotice(names, runs, { id: props.computerId, folder: runner.folder })
|
|
876
892
|
const { error } = await moveAgentThreadToComputer({
|
|
877
893
|
client,
|
|
878
894
|
path: { threadId },
|
|
879
895
|
body: { computer: { ...(await thisComputer()), folder: runner.folder } },
|
|
880
896
|
})
|
|
881
|
-
if (error) return
|
|
897
|
+
if (error) return moveRefused(error)
|
|
898
|
+
|
|
899
|
+
void reload()
|
|
900
|
+
props.say(moved)
|
|
901
|
+
}
|
|
902
|
+
// And back to the cloud, from where they can move anywhere again.
|
|
903
|
+
const moveCloud = async () => {
|
|
904
|
+
const moved = movedNotice(names, runs, "cloud")
|
|
905
|
+
const { error } = await moveAgentThreadToCloud({ client, path: { threadId } })
|
|
906
|
+
if (error) return moveRefused(error)
|
|
907
|
+
|
|
882
908
|
void reload()
|
|
883
|
-
props.say(
|
|
909
|
+
props.say(moved)
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
const canMoveHere = mine && (!onComputer || !here)
|
|
913
|
+
const canMoveCloud = mine && onComputer
|
|
914
|
+
|
|
915
|
+
// In a conversation, /here and /cloud move it: they take the place of the home screen's, which
|
|
916
|
+
// choose where new conversations start. One that cannot move says why, and the word never
|
|
917
|
+
// reaches the agent.
|
|
918
|
+
const moveCommand = (
|
|
919
|
+
name: string,
|
|
920
|
+
to: string,
|
|
921
|
+
canMove: boolean,
|
|
922
|
+
move: () => Promise<void>
|
|
923
|
+
): SlashCommand => {
|
|
924
|
+
// Not read yet, it cannot tell where it runs or whose it is: it moves nothing until then.
|
|
925
|
+
if (thread === null) {
|
|
926
|
+
return {
|
|
927
|
+
name,
|
|
928
|
+
description: `Move this conversation to ${to}`,
|
|
929
|
+
run: () => props.say("Reading the conversation…"),
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const description = canMove
|
|
934
|
+
? `Move this conversation to ${to}`
|
|
935
|
+
: mine
|
|
936
|
+
? `This conversation runs in ${to}`
|
|
937
|
+
: "Only its owner can move this conversation"
|
|
938
|
+
|
|
939
|
+
return { name, description, run: () => (canMove ? void move() : props.say(description)) }
|
|
940
|
+
}
|
|
941
|
+
const hereCommand = moveCommand("here", "this folder", canMoveHere, moveHere)
|
|
942
|
+
const cloudCommand = moveCommand("cloud", "the cloud", canMoveCloud, moveCloud)
|
|
943
|
+
const moveCommands: Readonly<Record<string, SlashCommand>> = {
|
|
944
|
+
here: hereCommand,
|
|
945
|
+
cloud: cloudCommand,
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// ctrl+g moves it where its hint says: to this folder, else back to the cloud. Pressed twice, as
|
|
949
|
+
// esc stops a turn: leaving the cloud retires its paused sub-agents' workspaces there, which a
|
|
950
|
+
// stray key must not do. Not ctrl+f, which the composer reads as a step to the right.
|
|
951
|
+
const keyMove = canMoveHere
|
|
952
|
+
? { name: "here", to: "this folder", move: moveHere }
|
|
953
|
+
: canMoveCloud
|
|
954
|
+
? { name: "cloud", to: "the cloud", move: moveCloud }
|
|
955
|
+
: null
|
|
956
|
+
const moveByKey = () => {
|
|
957
|
+
if (!keyMove) return
|
|
958
|
+
if (!moveArmed) {
|
|
959
|
+
setMoveArmed(true)
|
|
960
|
+
setTimeout(() => setMoveArmed(false), 2_000)
|
|
961
|
+
return
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
setMoveArmed(false)
|
|
965
|
+
void keyMove.move()
|
|
884
966
|
}
|
|
885
967
|
|
|
968
|
+
// The ctrl+p palette lists the moves that can happen now, in the slash menu's words. Why the
|
|
969
|
+
// others can't is the slash menu's to say, where each command's name tells them apart.
|
|
970
|
+
const { paletteMoves } = props
|
|
971
|
+
useEffect(() => {
|
|
972
|
+
const possible = [
|
|
973
|
+
...(canMoveHere ? [hereCommand] : []),
|
|
974
|
+
...(canMoveCloud ? [cloudCommand] : []),
|
|
975
|
+
]
|
|
976
|
+
paletteMoves.current = possible.map((command) => ({
|
|
977
|
+
id: command.name,
|
|
978
|
+
group: "Agent",
|
|
979
|
+
label: command.description,
|
|
980
|
+
...(command.name === keyMove?.name ? { keys: "ctrl+g" } : {}),
|
|
981
|
+
run: command.run,
|
|
982
|
+
}))
|
|
983
|
+
return () => {
|
|
984
|
+
paletteMoves.current = null
|
|
985
|
+
}
|
|
986
|
+
})
|
|
987
|
+
|
|
988
|
+
// A conversation adds what only it can show: its context use.
|
|
989
|
+
const slashCommands = [
|
|
990
|
+
...props.slashCommands.map((command) => moveCommands[command.name] ?? command),
|
|
991
|
+
{
|
|
992
|
+
name: "context",
|
|
993
|
+
description: "What the conversation uses of the model's context",
|
|
994
|
+
run: () => setContextOpen(true),
|
|
995
|
+
},
|
|
996
|
+
]
|
|
997
|
+
const slash = useSlashMenu(slashCommands, typed)
|
|
998
|
+
|
|
886
999
|
useEffect(() => {
|
|
887
1000
|
void reload()
|
|
888
1001
|
const socket = createAgentActivitySocket({
|
|
@@ -992,9 +1105,7 @@ function ThreadView(
|
|
|
992
1105
|
if (key.name === "down" && slash.move(1)) return
|
|
993
1106
|
if (key.name === "escape") return void stop()
|
|
994
1107
|
if (key.ctrl && key.name === "x" && runningBackground.length > 0) return setStopOpen(true)
|
|
995
|
-
if (key.ctrl && key.name === "
|
|
996
|
-
return void moveHere()
|
|
997
|
-
}
|
|
1108
|
+
if (key.ctrl && key.name === "g") return moveByKey()
|
|
998
1109
|
if (key.name === "pageup") scroll.current?.scrollBy(-10)
|
|
999
1110
|
if (key.name === "pagedown") scroll.current?.scrollBy(10)
|
|
1000
1111
|
})
|
|
@@ -1003,7 +1114,7 @@ function ThreadView(
|
|
|
1003
1114
|
if (slash.run(text)) return true
|
|
1004
1115
|
if (!thread) return false
|
|
1005
1116
|
if (onComputer && mine && !here) {
|
|
1006
|
-
props.say("It works in another folder: press ctrl+
|
|
1117
|
+
props.say("It works in another folder: press ctrl+g twice to move it here first.")
|
|
1007
1118
|
return false
|
|
1008
1119
|
}
|
|
1009
1120
|
const { data, error } = await postAgentThreadMessage({
|
|
@@ -1067,6 +1178,13 @@ function ThreadView(
|
|
|
1067
1178
|
: placeStatus
|
|
1068
1179
|
const runningSince = runs.find((run) => run.id === activeRunId)?.startedAt
|
|
1069
1180
|
|
|
1181
|
+
// The footer names the move ctrl+g makes, in the room its folder leaves: the panel's padding,
|
|
1182
|
+
// the hint itself and `ctrl+p commands` take 46 columns. From another folder the notice above
|
|
1183
|
+
// the composer names it instead.
|
|
1184
|
+
const footerMove =
|
|
1185
|
+
width < 64 || !mine ? null : !onComputer ? "move here" : here ? "move to cloud" : null
|
|
1186
|
+
const footerFolder = footerMove ? Math.max(12, Math.min(36, width - 46)) : 36
|
|
1187
|
+
|
|
1070
1188
|
return (
|
|
1071
1189
|
<box flexDirection="column" flexGrow={1} paddingTop={1}>
|
|
1072
1190
|
<box
|
|
@@ -1106,7 +1224,8 @@ function ThreadView(
|
|
|
1106
1224
|
live={live}
|
|
1107
1225
|
approvals={approvals}
|
|
1108
1226
|
modelNames={modelNames}
|
|
1109
|
-
|
|
1227
|
+
thread={thread}
|
|
1228
|
+
names={names}
|
|
1110
1229
|
width={width}
|
|
1111
1230
|
approvalChoice={choice}
|
|
1112
1231
|
{...(onComputer ? { folder: runner.folder } : {})}
|
|
@@ -1128,6 +1247,7 @@ function ThreadView(
|
|
|
1128
1247
|
onComputer,
|
|
1129
1248
|
mine,
|
|
1130
1249
|
here,
|
|
1250
|
+
...(place ? { folder: folderName(place.folder) } : {}),
|
|
1131
1251
|
continueFromWeb,
|
|
1132
1252
|
runningHere: activeRunId !== null && runner.runs(activeRunId),
|
|
1133
1253
|
})
|
|
@@ -1151,9 +1271,9 @@ function ThreadView(
|
|
|
1151
1271
|
? `It runs on ${clip(place.name, 40)}.`
|
|
1152
1272
|
: `It works in ${shortPath(place.folder, homedir(), 48)}.`}
|
|
1153
1273
|
</span>
|
|
1154
|
-
<span fg={colors.muted}>{"
|
|
1155
|
-
<span fg={colors.text}>ctrl+
|
|
1156
|
-
<span fg={colors.muted}>
|
|
1274
|
+
<span fg={colors.muted}>{" Press "}</span>
|
|
1275
|
+
<span fg={colors.text}>ctrl+g</span>
|
|
1276
|
+
<span fg={colors.muted}> twice to move it to this folder.</span>
|
|
1157
1277
|
</text>
|
|
1158
1278
|
) : null}
|
|
1159
1279
|
{runningBackground.length > 0 ? (
|
|
@@ -1175,10 +1295,27 @@ function ThreadView(
|
|
|
1175
1295
|
onSubmit={send}
|
|
1176
1296
|
/>
|
|
1177
1297
|
<box flexDirection="row" justifyContent="space-between" paddingTop={1}>
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1298
|
+
{moveArmed && keyMove ? (
|
|
1299
|
+
<text wrapMode="none" flexShrink={1} fg={colors.amber}>
|
|
1300
|
+
{`Press ctrl+g again to move it to ${keyMove.to}`}
|
|
1301
|
+
</text>
|
|
1302
|
+
) : (
|
|
1303
|
+
<text wrapMode="none" flexShrink={1}>
|
|
1304
|
+
<span fg={colors.faint}>
|
|
1305
|
+
{onComputer
|
|
1306
|
+
? shortPath(runner.folder, homedir(), footerFolder)
|
|
1307
|
+
: "Runs in the cloud"}
|
|
1308
|
+
</span>
|
|
1309
|
+
{footerMove ? (
|
|
1310
|
+
<>
|
|
1311
|
+
<span fg={colors.faint}>{" · "}</span>
|
|
1312
|
+
<span fg={colors.text}>ctrl+g</span>
|
|
1313
|
+
<span fg={colors.muted}>{` ${footerMove}`}</span>
|
|
1314
|
+
</>
|
|
1315
|
+
) : null}
|
|
1316
|
+
</text>
|
|
1317
|
+
)}
|
|
1318
|
+
<text flexShrink={0}>
|
|
1182
1319
|
<span fg={colors.text}>ctrl+p</span>
|
|
1183
1320
|
<span fg={colors.muted}> commands</span>
|
|
1184
1321
|
</text>
|
|
@@ -1258,6 +1395,8 @@ export function activityLabel(
|
|
|
1258
1395
|
readonly onComputer: boolean
|
|
1259
1396
|
readonly mine: boolean
|
|
1260
1397
|
readonly here: boolean
|
|
1398
|
+
/** The name of the folder it works in, when it isn't this one. */
|
|
1399
|
+
readonly folder?: string
|
|
1261
1400
|
readonly continueFromWeb: boolean
|
|
1262
1401
|
readonly runningHere: boolean
|
|
1263
1402
|
}
|
|
@@ -1266,7 +1405,9 @@ export function activityLabel(
|
|
|
1266
1405
|
if (run?.status === "queued") {
|
|
1267
1406
|
if (!where.onComputer) return "Starting"
|
|
1268
1407
|
if (!where.mine) return "Waiting for its owner's computer"
|
|
1269
|
-
if (!where.here)
|
|
1408
|
+
if (!where.here) {
|
|
1409
|
+
return where.folder ? `Waiting for ${where.folder} to be available` : "Waiting for its folder"
|
|
1410
|
+
}
|
|
1270
1411
|
return where.continueFromWeb || where.runningHere
|
|
1271
1412
|
? "Starting"
|
|
1272
1413
|
: "Waiting: messages from the web are off"
|
|
@@ -1323,6 +1464,8 @@ function commandItems(input: {
|
|
|
1323
1464
|
readonly newConversation: () => void
|
|
1324
1465
|
readonly open: (dialog: Dialog) => void
|
|
1325
1466
|
readonly setPlace: (place: Settings["place"]) => void
|
|
1467
|
+
/** In a conversation, its moves, in place of where new conversations run. */
|
|
1468
|
+
readonly threadMoves: readonly PaletteItem[] | null
|
|
1326
1469
|
/** Whether your messages from the web, or another device, run in this folder. */
|
|
1327
1470
|
readonly toggleContinueFromWeb: () => void
|
|
1328
1471
|
readonly toggleKeepAwake: () => void
|
|
@@ -1369,16 +1512,18 @@ function commandItems(input: {
|
|
|
1369
1512
|
keys: "shift+tab",
|
|
1370
1513
|
run: () => input.open("permissions"),
|
|
1371
1514
|
},
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1515
|
+
...(input.threadMoves ?? [
|
|
1516
|
+
{
|
|
1517
|
+
id: "place",
|
|
1518
|
+
group: "Agent",
|
|
1519
|
+
label:
|
|
1520
|
+
settings.place === "computer"
|
|
1521
|
+
? "Run new conversations in the cloud"
|
|
1522
|
+
: `Run new conversations on ${placeLabel("computer")}`,
|
|
1523
|
+
keys: "tab",
|
|
1524
|
+
run: () => input.setPlace(settings.place === "computer" ? "cloud" : "computer"),
|
|
1525
|
+
},
|
|
1526
|
+
]),
|
|
1382
1527
|
{
|
|
1383
1528
|
id: "continue-from-web",
|
|
1384
1529
|
group: "Agent",
|