@sixb/cli 0.2.4 → 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/README.md +2 -0
- package/dist/commands/agent.d.ts.map +1 -1
- 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/dev-runner.d.ts.map +1 -1
- package/dist/commands/run.d.ts +15 -0
- package/dist/commands/run.d.ts.map +1 -0
- 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 +12 -2
- package/dist/lib/command-line.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/role-lifecycle.d.ts +8 -1
- package/dist/lib/role-lifecycle.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts +4 -2
- package/dist/lib/runtime.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-concurrency.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +4 -1
- 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/format.d.ts +7 -2
- package/dist/tui/format.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 +22 -21
- package/src/commands/agent.ts +17 -5
- 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 +2 -1
- package/src/commands/run.ts +221 -0
- package/src/commands/worker-group.ts +36 -9
- package/src/commands/worker.ts +27 -9
- package/src/index.tsx +15 -1
- package/src/lib/command-line.ts +41 -5
- package/src/lib/deploy-source.ts +5 -0
- package/src/lib/role-lifecycle.ts +48 -8
- package/src/lib/runtime.ts +19 -3
- package/src/lib/storage-migration.ts +33 -1
- package/src/lib/worker-concurrency.ts +1 -0
- package/src/lib/worker-registry.ts +35 -5
- package/src/runner/computer-connection.ts +7 -1
- package/src/tui/app.tsx +191 -43
- package/src/tui/format.ts +132 -7
- 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 +54 -15
- package/src/ui/screens.ts +23 -0
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) => {
|
|
@@ -667,7 +673,7 @@ function Home(
|
|
|
667
673
|
},
|
|
668
674
|
throwOnError: true,
|
|
669
675
|
})
|
|
670
|
-
if (created.thread.runsOn === "computer") void runner.claim(posted.run.id)
|
|
676
|
+
if (created.thread.runsOn === "computer" && posted.run) void runner.claim(posted.run.id)
|
|
671
677
|
props.onOpen(created.thread.id)
|
|
672
678
|
return true
|
|
673
679
|
} catch (error) {
|
|
@@ -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,17 +868,133 @@ 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
|
+
|
|
882
899
|
void reload()
|
|
883
|
-
props.say(
|
|
900
|
+
props.say(moved)
|
|
884
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
|
+
|
|
908
|
+
void reload()
|
|
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()
|
|
966
|
+
}
|
|
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)
|
|
885
998
|
|
|
886
999
|
useEffect(() => {
|
|
887
1000
|
void reload()
|
|
@@ -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,11 +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+
|
|
1007
|
-
return false
|
|
1008
|
-
}
|
|
1009
|
-
if (activeRunId) {
|
|
1010
|
-
props.say("The agent is still working. Press esc twice to stop it.")
|
|
1117
|
+
props.say("It works in another folder: press ctrl+g twice to move it here first.")
|
|
1011
1118
|
return false
|
|
1012
1119
|
}
|
|
1013
1120
|
const { data, error } = await postAgentThreadMessage({
|
|
@@ -1021,12 +1128,19 @@ function ThreadView(
|
|
|
1021
1128
|
: {}),
|
|
1022
1129
|
...requesterSettings(),
|
|
1023
1130
|
...messageSelection(models, settings),
|
|
1131
|
+
// Enter steers the turn that runs; a message it cannot steer is refused with why.
|
|
1132
|
+
...(activeRunId ? { delivery: "steer" as const } : {}),
|
|
1024
1133
|
},
|
|
1025
1134
|
})
|
|
1026
1135
|
if (error || !data) {
|
|
1027
1136
|
props.say(errorText(error), "error")
|
|
1028
1137
|
return false
|
|
1029
1138
|
}
|
|
1139
|
+
// A message sent while a turn runs waits in the thread's inbox instead of starting one.
|
|
1140
|
+
if (!data.run) {
|
|
1141
|
+
void reload()
|
|
1142
|
+
return true
|
|
1143
|
+
}
|
|
1030
1144
|
if (runsHere) void runner.claim(data.run.id)
|
|
1031
1145
|
setLive(liveRun(data.run.id))
|
|
1032
1146
|
void reload()
|
|
@@ -1064,6 +1178,13 @@ function ThreadView(
|
|
|
1064
1178
|
: placeStatus
|
|
1065
1179
|
const runningSince = runs.find((run) => run.id === activeRunId)?.startedAt
|
|
1066
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
|
+
|
|
1067
1188
|
return (
|
|
1068
1189
|
<box flexDirection="column" flexGrow={1} paddingTop={1}>
|
|
1069
1190
|
<box
|
|
@@ -1103,7 +1224,8 @@ function ThreadView(
|
|
|
1103
1224
|
live={live}
|
|
1104
1225
|
approvals={approvals}
|
|
1105
1226
|
modelNames={modelNames}
|
|
1106
|
-
|
|
1227
|
+
thread={thread}
|
|
1228
|
+
names={names}
|
|
1107
1229
|
width={width}
|
|
1108
1230
|
approvalChoice={choice}
|
|
1109
1231
|
{...(onComputer ? { folder: runner.folder } : {})}
|
|
@@ -1125,6 +1247,7 @@ function ThreadView(
|
|
|
1125
1247
|
onComputer,
|
|
1126
1248
|
mine,
|
|
1127
1249
|
here,
|
|
1250
|
+
...(place ? { folder: folderName(place.folder) } : {}),
|
|
1128
1251
|
continueFromWeb,
|
|
1129
1252
|
runningHere: activeRunId !== null && runner.runs(activeRunId),
|
|
1130
1253
|
})
|
|
@@ -1148,9 +1271,9 @@ function ThreadView(
|
|
|
1148
1271
|
? `It runs on ${clip(place.name, 40)}.`
|
|
1149
1272
|
: `It works in ${shortPath(place.folder, homedir(), 48)}.`}
|
|
1150
1273
|
</span>
|
|
1151
|
-
<span fg={colors.muted}>{"
|
|
1152
|
-
<span fg={colors.text}>ctrl+
|
|
1153
|
-
<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>
|
|
1154
1277
|
</text>
|
|
1155
1278
|
) : null}
|
|
1156
1279
|
{runningBackground.length > 0 ? (
|
|
@@ -1172,10 +1295,27 @@ function ThreadView(
|
|
|
1172
1295
|
onSubmit={send}
|
|
1173
1296
|
/>
|
|
1174
1297
|
<box flexDirection="row" justifyContent="space-between" paddingTop={1}>
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
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}>
|
|
1179
1319
|
<span fg={colors.text}>ctrl+p</span>
|
|
1180
1320
|
<span fg={colors.muted}> commands</span>
|
|
1181
1321
|
</text>
|
|
@@ -1255,6 +1395,8 @@ export function activityLabel(
|
|
|
1255
1395
|
readonly onComputer: boolean
|
|
1256
1396
|
readonly mine: boolean
|
|
1257
1397
|
readonly here: boolean
|
|
1398
|
+
/** The name of the folder it works in, when it isn't this one. */
|
|
1399
|
+
readonly folder?: string
|
|
1258
1400
|
readonly continueFromWeb: boolean
|
|
1259
1401
|
readonly runningHere: boolean
|
|
1260
1402
|
}
|
|
@@ -1263,7 +1405,9 @@ export function activityLabel(
|
|
|
1263
1405
|
if (run?.status === "queued") {
|
|
1264
1406
|
if (!where.onComputer) return "Starting"
|
|
1265
1407
|
if (!where.mine) return "Waiting for its owner's computer"
|
|
1266
|
-
if (!where.here)
|
|
1408
|
+
if (!where.here) {
|
|
1409
|
+
return where.folder ? `Waiting for ${where.folder} to be available` : "Waiting for its folder"
|
|
1410
|
+
}
|
|
1267
1411
|
return where.continueFromWeb || where.runningHere
|
|
1268
1412
|
? "Starting"
|
|
1269
1413
|
: "Waiting: messages from the web are off"
|
|
@@ -1320,6 +1464,8 @@ function commandItems(input: {
|
|
|
1320
1464
|
readonly newConversation: () => void
|
|
1321
1465
|
readonly open: (dialog: Dialog) => void
|
|
1322
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
|
|
1323
1469
|
/** Whether your messages from the web, or another device, run in this folder. */
|
|
1324
1470
|
readonly toggleContinueFromWeb: () => void
|
|
1325
1471
|
readonly toggleKeepAwake: () => void
|
|
@@ -1366,16 +1512,18 @@ function commandItems(input: {
|
|
|
1366
1512
|
keys: "shift+tab",
|
|
1367
1513
|
run: () => input.open("permissions"),
|
|
1368
1514
|
},
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
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
|
+
]),
|
|
1379
1527
|
{
|
|
1380
1528
|
id: "continue-from-web",
|
|
1381
1529
|
group: "Agent",
|
package/src/tui/format.ts
CHANGED
|
@@ -17,16 +17,22 @@ export interface ToolLine {
|
|
|
17
17
|
readonly command?: string
|
|
18
18
|
/** The preview is diff lines, `+` added and `-` removed, colored as such. */
|
|
19
19
|
readonly diff?: boolean
|
|
20
|
+
/** The preview rows start with paths, shown as the person reads them. */
|
|
21
|
+
readonly paths?: boolean
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
const PREVIEW_LINES = 4
|
|
23
25
|
|
|
24
26
|
const NO_OUTCOMES: ReadonlyMap<string, ApprovalOutcome> = new Map()
|
|
25
27
|
|
|
26
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* `outcomes` says how the held calls ended, by approval id: a decided call is no longer held.
|
|
30
|
+
* `folder` is the one a computer's turns work in: a search names where it looked relative to it.
|
|
31
|
+
*/
|
|
27
32
|
export function toolLine(
|
|
28
33
|
part: ToolPart,
|
|
29
|
-
outcomes: ReadonlyMap<string, ApprovalOutcome> = NO_OUTCOMES
|
|
34
|
+
outcomes: ReadonlyMap<string, ApprovalOutcome> = NO_OUTCOMES,
|
|
35
|
+
folder?: string
|
|
30
36
|
): ToolLine {
|
|
31
37
|
const input = record(part.input) ?? partialInput(part.inputText)
|
|
32
38
|
const output = record(part.output)
|
|
@@ -167,6 +173,71 @@ export function toolLine(
|
|
|
167
173
|
...error,
|
|
168
174
|
}
|
|
169
175
|
}
|
|
176
|
+
case "glob": {
|
|
177
|
+
const files = Array.isArray(output?.files) ? output.files.map(text) : undefined
|
|
178
|
+
const found = files?.length ?? 0
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
verb: "glob",
|
|
182
|
+
detail: searchDetail(input, text(input?.pattern), folder),
|
|
183
|
+
...(files
|
|
184
|
+
? {
|
|
185
|
+
note: searchNote(
|
|
186
|
+
output,
|
|
187
|
+
found === 0
|
|
188
|
+
? "no files"
|
|
189
|
+
: output?.truncated === true
|
|
190
|
+
? `${found}+ files`
|
|
191
|
+
: plural(found, "file")
|
|
192
|
+
),
|
|
193
|
+
...(found > 0 ? { preview: limitedRows(files, "file", "files"), paths: true } : {}),
|
|
194
|
+
}
|
|
195
|
+
: {}),
|
|
196
|
+
...error,
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
case "grep": {
|
|
200
|
+
const matches = Array.isArray(output?.matches) ? output.matches.map(record) : undefined
|
|
201
|
+
const shown = matches?.length ?? 0
|
|
202
|
+
const counted = Object.values(record(output?.more) ?? {}).filter(
|
|
203
|
+
(count): count is number => typeof count === "number"
|
|
204
|
+
)
|
|
205
|
+
const total = counted.reduce((sum, count) => sum + count, shown)
|
|
206
|
+
|
|
207
|
+
const files = typeof output?.files === "number" ? output.files : 0
|
|
208
|
+
const found = `${total} ${total === 1 ? "match" : "matches"}`
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
verb: "grep",
|
|
212
|
+
detail: searchDetail(input, input?.pattern ? `"${text(input.pattern)}"` : "", folder),
|
|
213
|
+
...(matches
|
|
214
|
+
? {
|
|
215
|
+
note: searchNote(
|
|
216
|
+
output,
|
|
217
|
+
total === 0
|
|
218
|
+
? "no matches"
|
|
219
|
+
: output?.truncated === true
|
|
220
|
+
? `${total}+ matches`
|
|
221
|
+
: `${found} in ${plural(files, "file")}`
|
|
222
|
+
),
|
|
223
|
+
...(shown > 0
|
|
224
|
+
? {
|
|
225
|
+
preview: limitedRows(
|
|
226
|
+
matches.map(
|
|
227
|
+
(match) => `${text(match?.path)}:${match?.line} ${text(match?.text).trim()}`
|
|
228
|
+
),
|
|
229
|
+
"match",
|
|
230
|
+
"matches",
|
|
231
|
+
total
|
|
232
|
+
),
|
|
233
|
+
paths: true,
|
|
234
|
+
}
|
|
235
|
+
: {}),
|
|
236
|
+
}
|
|
237
|
+
: {}),
|
|
238
|
+
...error,
|
|
239
|
+
}
|
|
240
|
+
}
|
|
170
241
|
// Earlier threads hold calls to it.
|
|
171
242
|
case "view_file":
|
|
172
243
|
return { verb: "view", detail: text(input?.path), ...error }
|
|
@@ -435,11 +506,16 @@ function partialInput(inputText: string | undefined): Record<string, unknown> |
|
|
|
435
506
|
try {
|
|
436
507
|
return record(JSON.parse(inputText))
|
|
437
508
|
} catch {
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
509
|
+
const found = /"(command|path|task|key|query|url|pattern)"\s*:\s*"((?:[^"\\]|\\.)*)/.exec(
|
|
510
|
+
inputText
|
|
511
|
+
)
|
|
512
|
+
const [, key, value] = found ?? []
|
|
513
|
+
if (value === undefined) return undefined
|
|
514
|
+
|
|
515
|
+
// A search's pattern is only its pattern: it is no path its line would say it looked in.
|
|
516
|
+
if (key === "pattern") return { pattern: value }
|
|
517
|
+
|
|
518
|
+
return { command: value, path: value, task: value, query: value, url: value }
|
|
443
519
|
}
|
|
444
520
|
}
|
|
445
521
|
|
|
@@ -513,6 +589,55 @@ function limited(rows: readonly string[]): string[] {
|
|
|
513
589
|
: [...rows]
|
|
514
590
|
}
|
|
515
591
|
|
|
592
|
+
/**
|
|
593
|
+
* The first rows, then the rest counted by what they are: `… 8 more files`. `total` counts what
|
|
594
|
+
* the rows stand for when some were never listed, as a file's matches past the ones grep shows.
|
|
595
|
+
*/
|
|
596
|
+
function limitedRows(
|
|
597
|
+
rows: readonly string[],
|
|
598
|
+
one: string,
|
|
599
|
+
many: string,
|
|
600
|
+
total = rows.length
|
|
601
|
+
): string[] {
|
|
602
|
+
const shown = rows.slice(0, PREVIEW_LINES)
|
|
603
|
+
const left = total - shown.length
|
|
604
|
+
return left > 0 ? [...shown, `… ${left} more ${left === 1 ? one : many}`] : shown
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* A search as the call wrote it: its pattern, the files it was limited to, and where it looked, as
|
|
609
|
+
* the person reads it. The folder the agent works in goes unsaid, however the call named it.
|
|
610
|
+
*/
|
|
611
|
+
function searchDetail(
|
|
612
|
+
input: Record<string, unknown> | undefined,
|
|
613
|
+
pattern: string,
|
|
614
|
+
folder: string | undefined
|
|
615
|
+
): string {
|
|
616
|
+
const path = givenText(input?.path)
|
|
617
|
+
const include = givenText(input?.include)
|
|
618
|
+
const place = path.replace(/(.)\/+$/, "$1")
|
|
619
|
+
const working =
|
|
620
|
+
place === "." ||
|
|
621
|
+
(folder !== undefined && [folder, folder.replace(/^\/private/, "")].includes(place))
|
|
622
|
+
|
|
623
|
+
return [
|
|
624
|
+
...(pattern ? [pattern] : []),
|
|
625
|
+
...(include ? [include] : []),
|
|
626
|
+
...(path && !working ? [`in ${friendlyPath(path, folder)}`] : []),
|
|
627
|
+
].join(" ")
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** What a search found, and that it stopped early when it did. */
|
|
631
|
+
function searchNote(output: Record<string, unknown> | undefined, found: string): string {
|
|
632
|
+
return output?.incomplete === true ? `${found} · stopped early` : found
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** A string the call gave: models send `"null"` and `"undefined"` for nothing. */
|
|
636
|
+
function givenText(value: unknown): string {
|
|
637
|
+
const given = text(value).trim()
|
|
638
|
+
return given === "null" || given === "undefined" ? "" : given
|
|
639
|
+
}
|
|
640
|
+
|
|
516
641
|
function lines(value: string): string[] {
|
|
517
642
|
const all = value.replace(/\s+$/, "").split("\n")
|
|
518
643
|
return all.length > PREVIEW_LINES
|