@sixb/app 0.2.0 → 0.2.1
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/assets/connector-icons/README.md +1 -0
- package/assets/connector-icons/fleetio.ico +0 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/background/background-card.d.ts +10 -0
- package/dist/agent/background/background-card.d.ts.map +1 -0
- package/dist/agent/background/background-tool-row.d.ts +9 -0
- package/dist/agent/background/background-tool-row.d.ts.map +1 -0
- package/dist/agent/background/context.d.ts +23 -0
- package/dist/agent/background/context.d.ts.map +1 -0
- package/dist/agent/background/interpret.d.ts +116 -0
- package/dist/agent/background/interpret.d.ts.map +1 -0
- package/dist/agent/bash/bash-tool-view.d.ts.map +1 -1
- package/dist/agent/bash/interpret.d.ts +4 -0
- package/dist/agent/bash/interpret.d.ts.map +1 -1
- package/dist/agent/components/composer-menu.d.ts +3 -1
- package/dist/agent/components/composer-menu.d.ts.map +1 -1
- package/dist/agent/components/composer-place.d.ts +11 -0
- package/dist/agent/components/composer-place.d.ts.map +1 -0
- package/dist/agent/components/composer.d.ts +4 -1
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/computer-place.d.ts +3 -1
- package/dist/agent/components/computer-place.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts +6 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/components/web-fetch-tool-view.d.ts.map +1 -1
- package/dist/agent/delegation/child-parts.d.ts +2 -0
- package/dist/agent/delegation/child-parts.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts +15 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-new-thread-place.d.ts +48 -0
- package/dist/agent/hooks/use-new-thread-place.d.ts.map +1 -0
- package/dist/agent/hooks/use-thread-lists.d.ts +40 -0
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +60 -0
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +106 -0
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/observed-conversation.d.ts.map +1 -1
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/utils/web-fetch.d.ts +33 -1
- package/dist/agent/utils/web-fetch.d.ts.map +1 -1
- package/dist/agent/utils/web-search.d.ts +14 -2
- package/dist/agent/utils/web-search.d.ts.map +1 -1
- package/dist/{chunk-zxthr2q5.js → chunk-4j3c3p72.js} +1 -1
- package/dist/{chunk-km25essq.js → chunk-7fj9cfkw.js} +1 -1
- package/dist/{chunk-j9653e83.js → chunk-j8g956dt.js} +1 -1
- package/dist/{chunk-fw2bm6dq.js → chunk-ytadd0b5.js} +3095 -1994
- package/dist/{chunk-fw2bm6dq.js.map → chunk-ytadd0b5.js.map} +25 -19
- package/dist/index.js +1 -1
- package/dist/pages/console/data/shared.d.ts.map +1 -1
- package/dist/pages/settings/usage/messages.d.ts +2 -0
- package/dist/pages/settings/usage/messages.d.ts.map +1 -1
- package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
- package/dist/pages.js +13 -6
- package/dist/pages.js.map +6 -6
- package/package.json +3 -3
- package/src/agent/activity-label.ts +6 -2
- package/src/agent/agent.css +18 -0
- package/src/agent/background/background-card.tsx +308 -0
- package/src/agent/background/background-tool-row.tsx +58 -0
- package/src/agent/background/context.ts +26 -0
- package/src/agent/background/interpret.ts +356 -0
- package/src/agent/bash/bash-tool-view.tsx +9 -4
- package/src/agent/bash/interpret.ts +21 -3
- package/src/agent/components/composer-menu.tsx +4 -1
- package/src/agent/components/composer-place.tsx +144 -0
- package/src/agent/components/composer.tsx +13 -0
- package/src/agent/components/computer-place.tsx +18 -1
- package/src/agent/components/transcript.tsx +33 -1
- package/src/agent/components/web-fetch-tool-view.tsx +94 -29
- package/src/agent/delegation/child-parts.tsx +1 -1
- package/src/agent/hooks/use-agent-conversation.ts +68 -6
- package/src/agent/hooks/use-new-thread-place.ts +170 -0
- package/src/agent/i18n/en.ts +56 -3
- package/src/agent/i18n/fr.ts +58 -3
- package/src/agent/observed-conversation.tsx +3 -0
- package/src/agent/tool-views/built-in.tsx +26 -11
- package/src/agent/utils/web-fetch.ts +89 -10
- package/src/agent/utils/web-search.ts +67 -28
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/settings/usage/messages.ts +2 -0
- package/src/pages/settings/usage/spend-model.ts +1 -0
- /package/dist/{chunk-zxthr2q5.js.map → chunk-4j3c3p72.js.map} +0 -0
- /package/dist/{chunk-km25essq.js.map → chunk-7fj9cfkw.js.map} +0 -0
- /package/dist/{chunk-j9653e83.js.map → chunk-j8g956dt.js.map} +0 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import type { AgentConversationMessage } from "../conversation"
|
|
2
|
+
import type { AgentMessages } from "../i18n/en"
|
|
3
|
+
import type { NormalizedTool } from "../parts"
|
|
4
|
+
import { toolResultValue } from "../parts"
|
|
5
|
+
|
|
6
|
+
// A command the agent runs in the background outlives the call that started it: later calls read
|
|
7
|
+
// it (`bash_output`) or stop it (`bash_stop`), maybe turns later, and on the owner's computer the
|
|
8
|
+
// open `sixb` reports how it stands between turns. The chat shows it as one card in the work's
|
|
9
|
+
// steps, in place of its start, merging all of these: only a reader who opens the steps sees it.
|
|
10
|
+
|
|
11
|
+
export type BackgroundCommandStatus = "running" | "exited" | "stopped"
|
|
12
|
+
|
|
13
|
+
/** The tools that start, read and stop a background command. */
|
|
14
|
+
export const BACKGROUND_TOOLS: ReadonlySet<string> = new Set(["bash", "bash_output", "bash_stop"])
|
|
15
|
+
|
|
16
|
+
/** How much of what the agent read of a command the card keeps: its newest characters. */
|
|
17
|
+
const OUTPUT_TAIL_CHARS = 8_000
|
|
18
|
+
|
|
19
|
+
/** A background command by its start: an id is unique to its run, its start to the thread. */
|
|
20
|
+
export function backgroundKey(command: { readonly id: string; readonly startedAt: string }) {
|
|
21
|
+
return `${command.id}@${command.startedAt}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A command a work group started, which its card stands for under the work. */
|
|
25
|
+
export type BackgroundStart =
|
|
26
|
+
/** The call is on its way: the command does not run yet. */
|
|
27
|
+
| { readonly kind: "starting"; readonly key: string; readonly command: string }
|
|
28
|
+
| {
|
|
29
|
+
readonly kind: "started"
|
|
30
|
+
readonly key: string
|
|
31
|
+
readonly id: string
|
|
32
|
+
readonly startedAt: string
|
|
33
|
+
readonly command: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What the conversation's calls say of a command, oldest to newest. */
|
|
37
|
+
export interface CommandFromCalls {
|
|
38
|
+
readonly id: string
|
|
39
|
+
readonly command: string
|
|
40
|
+
readonly startedAt: string
|
|
41
|
+
readonly status: BackgroundCommandStatus
|
|
42
|
+
readonly exitCode?: number
|
|
43
|
+
readonly endedAt?: string
|
|
44
|
+
readonly outputPath?: string
|
|
45
|
+
/** The turn that started it. */
|
|
46
|
+
readonly runId: string | null
|
|
47
|
+
/** What the agent read of its output, newest last; `truncated` when more came before. */
|
|
48
|
+
readonly output: string
|
|
49
|
+
readonly truncated: boolean
|
|
50
|
+
/** A call naming it is on its way: the agent reads it, waits for it, or stops it. */
|
|
51
|
+
readonly pending?: "reading" | "waiting" | "stopping"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The thread's background commands as its calls tell them, by {@link backgroundKey}. */
|
|
55
|
+
export interface ThreadBackground {
|
|
56
|
+
readonly commands: ReadonlyMap<string, CommandFromCalls>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A command as the computer's `sixb` reports it to its owner, between turns too. */
|
|
60
|
+
export interface LiveBackgroundCommand {
|
|
61
|
+
readonly id: string
|
|
62
|
+
readonly command: string
|
|
63
|
+
readonly status: BackgroundCommandStatus
|
|
64
|
+
readonly exitCode?: number
|
|
65
|
+
readonly startedAt: string
|
|
66
|
+
readonly endedAt?: string
|
|
67
|
+
/** A stop its owner asked for is on its way to it. */
|
|
68
|
+
readonly stopping?: boolean
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Where the thread's commands run, and what is known of them now. */
|
|
72
|
+
export interface BackgroundSource {
|
|
73
|
+
/** The thread runs on its owner's computer, where a command outlives its turn. */
|
|
74
|
+
readonly onComputer: boolean
|
|
75
|
+
/**
|
|
76
|
+
* What the computer reports, to its owner alone: null for anyone else, and in the cloud. Empty
|
|
77
|
+
* when `sixb` is closed there, which stopped them.
|
|
78
|
+
*/
|
|
79
|
+
readonly live: readonly LiveBackgroundCommand[] | null
|
|
80
|
+
/** `sixb` is open in the thread's folder. */
|
|
81
|
+
readonly online: boolean
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** How the card shows a command now. */
|
|
85
|
+
export interface BackgroundCardState {
|
|
86
|
+
readonly status: "starting" | BackgroundCommandStatus | "unknown"
|
|
87
|
+
readonly command: string
|
|
88
|
+
readonly startedAt?: string
|
|
89
|
+
readonly endedAt?: string
|
|
90
|
+
readonly exitCode?: number
|
|
91
|
+
/** Why a command its calls last saw running is gone: its turn, or its `sixb`, ended. */
|
|
92
|
+
readonly endedWith?: "turn" | "sixb"
|
|
93
|
+
/** Unknown as its owner's `sixb` does not answer there: closed, or offline. */
|
|
94
|
+
readonly unreachable?: boolean
|
|
95
|
+
/** A stop is on its way: the agent's, or one its owner asked for. */
|
|
96
|
+
readonly stopping: boolean
|
|
97
|
+
/** The agent waits for it, or reads it, now. */
|
|
98
|
+
readonly pending?: "reading" | "waiting"
|
|
99
|
+
/** Its owner can stop it from the card: it runs on their open `sixb`. */
|
|
100
|
+
readonly canStop: boolean
|
|
101
|
+
readonly output: string
|
|
102
|
+
readonly truncated: boolean
|
|
103
|
+
readonly outputPath?: string
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The command a background start stands for, by its call: on its way, or started with its id. Null
|
|
108
|
+
* for one that could not start, which is a failed call like any other.
|
|
109
|
+
*/
|
|
110
|
+
export function backgroundStartOf(tool: NormalizedTool): BackgroundStart | null {
|
|
111
|
+
if (!isBackgroundStart(tool)) return null
|
|
112
|
+
|
|
113
|
+
const command = commandOf(tool)
|
|
114
|
+
if (tool.state === "input-streaming" || tool.state === "input-available") {
|
|
115
|
+
return { kind: "starting", key: "starting", command }
|
|
116
|
+
}
|
|
117
|
+
const state = tool.state === "output-available" ? commandState(tool.output) : null
|
|
118
|
+
if (!state) return null
|
|
119
|
+
return {
|
|
120
|
+
kind: "started",
|
|
121
|
+
key: backgroundKey(state),
|
|
122
|
+
id: state.id,
|
|
123
|
+
startedAt: state.startedAt,
|
|
124
|
+
command: command || state.command,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Whether a call starts a command in the background. */
|
|
129
|
+
export function isBackgroundStart(tool: NormalizedTool): boolean {
|
|
130
|
+
return tool.toolName === "bash" && isRecord(tool.input) && tool.input.run_in_background === true
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Read the thread's background commands from its turns, oldest first, the one streaming last. */
|
|
134
|
+
export function readThreadBackground(
|
|
135
|
+
messages: readonly Pick<AgentConversationMessage, "role" | "runId" | "parts">[]
|
|
136
|
+
): ThreadBackground {
|
|
137
|
+
const commands = new Map<string, CommandFromCalls>()
|
|
138
|
+
// The newest command by id: a call on its way names one by id alone.
|
|
139
|
+
const byId = new Map<string, string>()
|
|
140
|
+
|
|
141
|
+
const merge = (key: string, change: Partial<CommandFromCalls>) => {
|
|
142
|
+
const current = commands.get(key)
|
|
143
|
+
if (current) commands.set(key, { ...current, ...change })
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
for (const message of messages) {
|
|
147
|
+
if (message.role !== "assistant") continue
|
|
148
|
+
|
|
149
|
+
for (const part of message.parts) {
|
|
150
|
+
if (part.type !== "tool" || !BACKGROUND_TOOLS.has(part.toolName)) continue
|
|
151
|
+
const tool = part as NormalizedTool
|
|
152
|
+
|
|
153
|
+
if (tool.toolName === "bash") {
|
|
154
|
+
const state =
|
|
155
|
+
isBackgroundStart(tool) && tool.state === "output-available"
|
|
156
|
+
? commandState(tool.output)
|
|
157
|
+
: null
|
|
158
|
+
if (!state) continue
|
|
159
|
+
|
|
160
|
+
const key = backgroundKey(state)
|
|
161
|
+
commands.set(key, {
|
|
162
|
+
...state,
|
|
163
|
+
command: commandOf(tool) || state.command,
|
|
164
|
+
runId: message.runId,
|
|
165
|
+
output: "",
|
|
166
|
+
truncated: false,
|
|
167
|
+
})
|
|
168
|
+
byId.set(state.id, key)
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// A read or a stop on its way names the command it is for.
|
|
173
|
+
if (tool.state === "input-streaming" || tool.state === "input-available") {
|
|
174
|
+
const input = isRecord(tool.input) ? tool.input : {}
|
|
175
|
+
const key = typeof input.id === "string" ? byId.get(input.id) : undefined
|
|
176
|
+
if (!key) continue
|
|
177
|
+
const pending =
|
|
178
|
+
tool.toolName === "bash_stop"
|
|
179
|
+
? "stopping"
|
|
180
|
+
: typeof input.wait === "number" && input.wait > 0
|
|
181
|
+
? "waiting"
|
|
182
|
+
: "reading"
|
|
183
|
+
merge(key, { pending })
|
|
184
|
+
continue
|
|
185
|
+
}
|
|
186
|
+
if (tool.state !== "output-available") continue
|
|
187
|
+
|
|
188
|
+
const read = commandState(tool.output)
|
|
189
|
+
if (!read) continue
|
|
190
|
+
const key = backgroundKey(read)
|
|
191
|
+
const known = commands.get(key)
|
|
192
|
+
// Its start is beyond what the conversation shows: the read stands for it.
|
|
193
|
+
const current: CommandFromCalls = known ?? {
|
|
194
|
+
...read,
|
|
195
|
+
runId: message.runId,
|
|
196
|
+
output: "",
|
|
197
|
+
truncated: false,
|
|
198
|
+
}
|
|
199
|
+
byId.set(read.id, key)
|
|
200
|
+
|
|
201
|
+
const written =
|
|
202
|
+
typeof outputOf(tool.output)?.output === "string" ? outputOf(tool.output)?.output : ""
|
|
203
|
+
const skipped = Number(outputOf(tool.output)?.skippedBytes ?? 0) > 0
|
|
204
|
+
const joined = current.output + (written ?? "")
|
|
205
|
+
// An end is final: a later read never says it runs again.
|
|
206
|
+
const ended = current.status !== "running" ? current : read
|
|
207
|
+
const { pending: _pending, ...rest } = current
|
|
208
|
+
commands.set(key, {
|
|
209
|
+
...rest,
|
|
210
|
+
status: ended.status,
|
|
211
|
+
...(ended.exitCode === undefined ? {} : { exitCode: ended.exitCode }),
|
|
212
|
+
...(ended.endedAt === undefined ? {} : { endedAt: ended.endedAt }),
|
|
213
|
+
output: joined.slice(-OUTPUT_TAIL_CHARS),
|
|
214
|
+
truncated: current.truncated || skipped || joined.length > OUTPUT_TAIL_CHARS,
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return { commands }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* How a command's card reads now: its calls, what its `sixb` reports, and whether its turn still
|
|
224
|
+
* works. Whatever says it ended wins; a command its calls last saw running is gone once nothing can
|
|
225
|
+
* still run it: its turn ended in the cloud, or its `sixb` closed or no longer reports it.
|
|
226
|
+
*/
|
|
227
|
+
export function backgroundCardState(input: {
|
|
228
|
+
readonly start: BackgroundStart
|
|
229
|
+
readonly calls?: CommandFromCalls
|
|
230
|
+
readonly source: BackgroundSource
|
|
231
|
+
/** The turn streaming now, if any. */
|
|
232
|
+
readonly liveRunId: string | null
|
|
233
|
+
/** A stop the reader asked for here, until the computer reports it. */
|
|
234
|
+
readonly stopAsked?: boolean
|
|
235
|
+
}): BackgroundCardState {
|
|
236
|
+
const { start, calls, source } = input
|
|
237
|
+
const empty = { output: "", truncated: false, stopping: false, canStop: false }
|
|
238
|
+
if (start.kind === "starting") return { ...empty, status: "starting", command: start.command }
|
|
239
|
+
|
|
240
|
+
const live = source.live?.find((command) => backgroundKey(command) === start.key)
|
|
241
|
+
const base = {
|
|
242
|
+
command: start.command,
|
|
243
|
+
startedAt: start.startedAt,
|
|
244
|
+
output: calls?.output ?? "",
|
|
245
|
+
truncated: calls?.truncated ?? false,
|
|
246
|
+
...(calls?.outputPath ? { outputPath: calls.outputPath } : {}),
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const ended = [calls, live].find((each) => each !== undefined && each.status !== "running")
|
|
250
|
+
if (ended) {
|
|
251
|
+
return {
|
|
252
|
+
...base,
|
|
253
|
+
status: ended.status,
|
|
254
|
+
...(ended.exitCode === undefined ? {} : { exitCode: ended.exitCode }),
|
|
255
|
+
...(ended.endedAt === undefined ? {} : { endedAt: ended.endedAt }),
|
|
256
|
+
stopping: false,
|
|
257
|
+
canStop: false,
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const agentStopping = calls?.pending === "stopping"
|
|
262
|
+
const pending =
|
|
263
|
+
calls?.pending === "reading" || calls?.pending === "waiting" ? calls.pending : undefined
|
|
264
|
+
const running = {
|
|
265
|
+
...base,
|
|
266
|
+
status: "running" as const,
|
|
267
|
+
...(pending ? { pending } : {}),
|
|
268
|
+
}
|
|
269
|
+
if (live) {
|
|
270
|
+
const stopping = agentStopping || live.stopping === true || input.stopAsked === true
|
|
271
|
+
return { ...running, stopping, canStop: !stopping }
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Its turn still works: the command runs, and `sixb` has not reported it yet.
|
|
275
|
+
const turnWorks =
|
|
276
|
+
calls?.runId !== null && calls?.runId !== undefined && calls.runId === input.liveRunId
|
|
277
|
+
if (turnWorks || (!calls && input.liveRunId !== null)) {
|
|
278
|
+
return { ...running, stopping: agentStopping, canStop: false }
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const gone = { ...base, status: "stopped" as const, stopping: false, canStop: false }
|
|
282
|
+
// In the cloud, a turn's commands stop as it ends.
|
|
283
|
+
if (!source.onComputer) return { ...gone, endedWith: "turn" }
|
|
284
|
+
// Its open sixb no longer runs it: it restarted, and stopped it as it quit.
|
|
285
|
+
if (source.live !== null && source.online) return { ...gone, endedWith: "sixb" }
|
|
286
|
+
// sixb is closed there, or keeps its commands from the web, or the computer is someone else's:
|
|
287
|
+
// nothing says how it stands now.
|
|
288
|
+
return {
|
|
289
|
+
...base,
|
|
290
|
+
status: "unknown",
|
|
291
|
+
...(source.live !== null ? { unreachable: true } : {}),
|
|
292
|
+
stopping: false,
|
|
293
|
+
canStop: false,
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** What a background call reads as, in the work and as the live label of a turn at work. */
|
|
298
|
+
export function backgroundRowLabel(tool: NormalizedTool, messages: AgentMessages): string {
|
|
299
|
+
const rows = messages.background.rows
|
|
300
|
+
const input = isRecord(tool.input) ? tool.input : {}
|
|
301
|
+
const row =
|
|
302
|
+
tool.toolName === "bash_stop"
|
|
303
|
+
? rows.stop
|
|
304
|
+
: tool.toolName === "bash_output"
|
|
305
|
+
? typeof input.wait === "number" && input.wait > 0
|
|
306
|
+
? rows.wait
|
|
307
|
+
: rows.read
|
|
308
|
+
: rows.start
|
|
309
|
+
return tool.state === "input-streaming" || tool.state === "input-available"
|
|
310
|
+
? row.running
|
|
311
|
+
: row.title
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** The command a call names in its input, as the model wrote it. */
|
|
315
|
+
function commandOf(tool: NormalizedTool): string {
|
|
316
|
+
const input = isRecord(tool.input) ? tool.input : {}
|
|
317
|
+
if (typeof input.command === "string") return input.command
|
|
318
|
+
const partial = /"command"\s*:\s*"((?:[^"\\]|\\.)*)/.exec(tool.inputText ?? "")
|
|
319
|
+
return partial?.[1] ? partial[1].replace(/\\n/g, "\n").replace(/\\"/g, '"') : ""
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** A command's state, as its tools return it. */
|
|
323
|
+
function commandState(output: unknown): {
|
|
324
|
+
readonly id: string
|
|
325
|
+
readonly command: string
|
|
326
|
+
readonly startedAt: string
|
|
327
|
+
readonly status: BackgroundCommandStatus
|
|
328
|
+
readonly exitCode?: number
|
|
329
|
+
readonly endedAt?: string
|
|
330
|
+
readonly outputPath?: string
|
|
331
|
+
} | null {
|
|
332
|
+
const value = outputOf(output)
|
|
333
|
+
if (!value) return null
|
|
334
|
+
const { id, command, startedAt, status, exitCode, endedAt, outputPath } = value
|
|
335
|
+
if (typeof id !== "string" || typeof startedAt !== "string") return null
|
|
336
|
+
if (status !== "running" && status !== "exited" && status !== "stopped") return null
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
id,
|
|
340
|
+
command: typeof command === "string" ? command : "",
|
|
341
|
+
startedAt,
|
|
342
|
+
status,
|
|
343
|
+
...(typeof exitCode === "number" ? { exitCode } : {}),
|
|
344
|
+
...(typeof endedAt === "string" ? { endedAt } : {}),
|
|
345
|
+
...(typeof outputPath === "string" ? { outputPath } : {}),
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function outputOf(output: unknown): Record<string, unknown> | null {
|
|
350
|
+
const value = toolResultValue(output)
|
|
351
|
+
return isRecord(value) ? value : null
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
355
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
356
|
+
}
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
coerceBashInput,
|
|
31
31
|
coerceBashOutput,
|
|
32
32
|
commandPreview,
|
|
33
|
+
commandTimeout,
|
|
33
34
|
describeBash,
|
|
34
35
|
humanize,
|
|
35
36
|
type ModelMedia,
|
|
@@ -118,15 +119,19 @@ export function BashToolView({ tool }: { tool: BashTool }) {
|
|
|
118
119
|
// users can still expand and debug it. (Exploratory commands often fail and the agent recovers;
|
|
119
120
|
// surfacing that in red just makes a working run look broken.)
|
|
120
121
|
if (isError && !running) {
|
|
122
|
+
// A timed-out command exits as its signal does (137): say what happened, not the code.
|
|
123
|
+
const detail = parsed?.timedOut
|
|
124
|
+
? [description.detail, messages.bash.timedOut(commandTimeout(input))]
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.join(" · ")
|
|
127
|
+
: description.detail
|
|
121
128
|
return (
|
|
122
129
|
<Collapsible>
|
|
123
130
|
<CollapsibleTrigger className="group flex w-fit max-w-full items-center gap-1.5 text-[13px] leading-normal text-muted-foreground transition-colors hover:text-foreground">
|
|
124
131
|
<Icon className="size-3.5 shrink-0" />
|
|
125
132
|
<span className="min-w-0 truncate font-medium">{label}</span>
|
|
126
|
-
{
|
|
127
|
-
<span className="min-w-0 shrink truncate text-muted-foreground/60">
|
|
128
|
-
{description.detail}
|
|
129
|
-
</span>
|
|
133
|
+
{detail ? (
|
|
134
|
+
<span className="min-w-0 shrink truncate text-muted-foreground/60">{detail}</span>
|
|
130
135
|
) : null}
|
|
131
136
|
<ChevronRight className="size-3.5 shrink-0 opacity-0 transition-all group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[state=open]:rotate-90 group-data-[state=open]:opacity-100" />
|
|
132
137
|
</CollapsibleTrigger>
|
|
@@ -79,6 +79,8 @@ export interface ParsedBashOutput {
|
|
|
79
79
|
readonly stderr: string
|
|
80
80
|
readonly durationMs: number
|
|
81
81
|
readonly truncated: boolean
|
|
82
|
+
/** The command was stopped at its timeout: its exit code is the signal's, not its verdict. */
|
|
83
|
+
readonly timedOut: boolean
|
|
82
84
|
/** Decoded stdout when it parsed as JSON, otherwise undefined. */
|
|
83
85
|
readonly json: unknown
|
|
84
86
|
}
|
|
@@ -97,19 +99,35 @@ export function coerceBashInput(input: unknown): BashInput | null {
|
|
|
97
99
|
export function coerceBashOutput(output: unknown): ParsedBashOutput | null {
|
|
98
100
|
if (!isRecord(output)) return null
|
|
99
101
|
const stdout = typeof output.stdout === "string" ? output.stdout : ""
|
|
100
|
-
const
|
|
102
|
+
const timedOut = output.timedOut === true
|
|
103
|
+
const rawStderr = typeof output.stderr === "string" ? output.stderr : ""
|
|
104
|
+
// The line the bash tool adds for the model (how long it had, how to ask for more) is not for
|
|
105
|
+
// people: the step's line says it in their words.
|
|
106
|
+
const stderr = timedOut ? rawStderr.replace(/(^|\n)\[SixbAgent\] [^\n]*$/, "") : rawStderr
|
|
101
107
|
const exitCode = typeof output.exitCode === "number" ? output.exitCode : 0
|
|
102
108
|
return {
|
|
103
|
-
ok: exitCode === 0,
|
|
109
|
+
ok: exitCode === 0 && !timedOut,
|
|
104
110
|
exitCode,
|
|
105
111
|
stdout,
|
|
106
112
|
stderr,
|
|
107
113
|
durationMs: typeof output.durationMs === "number" ? output.durationMs : 0,
|
|
108
114
|
truncated: output.stdoutTruncated === true || output.stderrTruncated === true,
|
|
109
|
-
|
|
115
|
+
timedOut,
|
|
116
|
+
json: exitCode === 0 && !timedOut ? tryParseJson(stdout) : undefined,
|
|
110
117
|
}
|
|
111
118
|
}
|
|
112
119
|
|
|
120
|
+
/** How long a command had, as the bash tool gives it: 2 minutes unless it asked, 10 at most. */
|
|
121
|
+
export function commandTimeout(input: BashInput | null): string {
|
|
122
|
+
const asked = input?.timeoutMs
|
|
123
|
+
const ms =
|
|
124
|
+
asked !== undefined && Number.isFinite(asked) && asked > 0
|
|
125
|
+
? Math.min(Math.floor(asked), 10 * 60_000)
|
|
126
|
+
: 2 * 60_000
|
|
127
|
+
if (ms % 60_000 === 0) return `${ms / 60_000} min`
|
|
128
|
+
return ms % 1000 === 0 ? `${ms / 1000} s` : `${ms} ms`
|
|
129
|
+
}
|
|
130
|
+
|
|
113
131
|
// --- Command classification ------------------------------------------------
|
|
114
132
|
|
|
115
133
|
export function classifyCommand(command: string): BashIntent {
|
|
@@ -78,6 +78,7 @@ export function ComposerMenu({
|
|
|
78
78
|
trigger,
|
|
79
79
|
title,
|
|
80
80
|
align,
|
|
81
|
+
side = "top",
|
|
81
82
|
className,
|
|
82
83
|
onCloseAutoFocus,
|
|
83
84
|
children,
|
|
@@ -88,6 +89,8 @@ export function ComposerMenu({
|
|
|
88
89
|
/** Names the menu to assistive technology. */
|
|
89
90
|
readonly title: string
|
|
90
91
|
readonly align: "start" | "end"
|
|
92
|
+
/** Which way it opens, room allowing. By default, up, over what's above the composer. */
|
|
93
|
+
readonly side?: "top" | "bottom"
|
|
91
94
|
readonly className?: string
|
|
92
95
|
/** Where the focus goes once the menu closes; the trigger unless prevented. */
|
|
93
96
|
readonly onCloseAutoFocus?: (event: Event) => void
|
|
@@ -115,7 +118,7 @@ export function ComposerMenu({
|
|
|
115
118
|
<PopoverTrigger asChild>{trigger}</PopoverTrigger>
|
|
116
119
|
<PopoverContent
|
|
117
120
|
align={align}
|
|
118
|
-
side=
|
|
121
|
+
side={side}
|
|
119
122
|
sideOffset={10}
|
|
120
123
|
collisionPadding={12}
|
|
121
124
|
aria-label={title}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { cn } from "@sixb/ui/lib/utils"
|
|
2
|
+
import { ChevronDown, Cloud, Folder, FolderPlus, Laptop, X } from "lucide-react"
|
|
3
|
+
import { useState } from "react"
|
|
4
|
+
import type { NewThreadPlace } from "../hooks/use-new-thread-place"
|
|
5
|
+
import { useAgentMessages } from "../i18n"
|
|
6
|
+
import {
|
|
7
|
+
COMPOSER_MENU_ROW_CLASS_NAME,
|
|
8
|
+
COMPOSER_MENU_ROW_SELECTED_CLASS_NAME,
|
|
9
|
+
ComposerMenu,
|
|
10
|
+
ComposerMenuDivider,
|
|
11
|
+
ComposerMenuHeader,
|
|
12
|
+
ComposerMenuScroll,
|
|
13
|
+
} from "./composer-menu"
|
|
14
|
+
import { shownFolder } from "./computer-place"
|
|
15
|
+
|
|
16
|
+
/** A folder's last name: what tells it apart in a chip. */
|
|
17
|
+
function folderName(folder: string): string {
|
|
18
|
+
return folder.split("/").filter(Boolean).at(-1) ?? folder
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Where a new conversation runs, as a quiet line under the input: set once for the conversation, and
|
|
23
|
+
* the thing a person most needs to see before sending, so it isn't among the per-message settings.
|
|
24
|
+
* Its menu holds the folders chosen before, a way to choose another, and the cloud.
|
|
25
|
+
*/
|
|
26
|
+
export function ComposerPlace({
|
|
27
|
+
place,
|
|
28
|
+
disabled,
|
|
29
|
+
}: {
|
|
30
|
+
readonly place: NewThreadPlace
|
|
31
|
+
readonly disabled?: boolean
|
|
32
|
+
}) {
|
|
33
|
+
const messages = useAgentMessages().computer
|
|
34
|
+
const [open, setOpen] = useState(false)
|
|
35
|
+
const { cloud, folder, folders } = place
|
|
36
|
+
const name = cloud ? messages.cloud : folder ? folderName(folder) : messages.chooseFolderShort
|
|
37
|
+
const Icon = cloud ? Cloud : Laptop
|
|
38
|
+
const path = !cloud && folder ? shownFolder(folder) : null
|
|
39
|
+
const described = path ?? name
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<ComposerMenu
|
|
43
|
+
open={open}
|
|
44
|
+
onOpenChange={(next) => {
|
|
45
|
+
if (next) place.refreshFolders()
|
|
46
|
+
setOpen(next)
|
|
47
|
+
}}
|
|
48
|
+
title={messages.placeTitle}
|
|
49
|
+
align="start"
|
|
50
|
+
side="bottom"
|
|
51
|
+
className="w-[22rem]"
|
|
52
|
+
trigger={
|
|
53
|
+
<button
|
|
54
|
+
type="button"
|
|
55
|
+
disabled={disabled}
|
|
56
|
+
aria-label={messages.placeChip(described)}
|
|
57
|
+
aria-haspopup="dialog"
|
|
58
|
+
aria-expanded={open}
|
|
59
|
+
title={described}
|
|
60
|
+
className="group/place -ml-1.5 flex h-7 min-w-0 items-center gap-1.5 rounded-full pr-2 pl-1.5 text-[12.5px] font-medium text-muted-foreground outline-none transition-colors hover:bg-black/[0.05] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 disabled:opacity-50 aria-expanded:bg-black/[0.05] aria-expanded:text-foreground dark:hover:bg-white/[0.08] dark:aria-expanded:bg-white/[0.08]"
|
|
61
|
+
>
|
|
62
|
+
<Icon className="size-3.5 shrink-0" strokeWidth={1.9} aria-hidden="true" />
|
|
63
|
+
<span className="max-w-[12rem] shrink-0 truncate">{name}</span>
|
|
64
|
+
{path ? (
|
|
65
|
+
<span className="min-w-0 truncate font-normal text-muted-foreground/70 max-sm:hidden">
|
|
66
|
+
{path}
|
|
67
|
+
</span>
|
|
68
|
+
) : null}
|
|
69
|
+
<ChevronDown
|
|
70
|
+
className="size-3 shrink-0 opacity-70 transition-transform group-aria-expanded/place:rotate-180"
|
|
71
|
+
strokeWidth={2.6}
|
|
72
|
+
aria-hidden="true"
|
|
73
|
+
/>
|
|
74
|
+
</button>
|
|
75
|
+
}
|
|
76
|
+
>
|
|
77
|
+
<ComposerMenuScroll>
|
|
78
|
+
{place.computerName ? <ComposerMenuHeader>{place.computerName}</ComposerMenuHeader> : null}
|
|
79
|
+
{folders.map((known) => (
|
|
80
|
+
<div key={known} className="group/row relative">
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
className={cn(
|
|
84
|
+
COMPOSER_MENU_ROW_CLASS_NAME,
|
|
85
|
+
"pr-9",
|
|
86
|
+
!cloud && known === folder && COMPOSER_MENU_ROW_SELECTED_CLASS_NAME
|
|
87
|
+
)}
|
|
88
|
+
title={shownFolder(known)}
|
|
89
|
+
onClick={() => {
|
|
90
|
+
place.chooseFolder(known)
|
|
91
|
+
setOpen(false)
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
<Folder className="size-4 shrink-0" strokeWidth={1.9} aria-hidden="true" />
|
|
95
|
+
<span className="flex min-w-0 flex-1 flex-col gap-px">
|
|
96
|
+
<span className="truncate font-medium text-foreground">{folderName(known)}</span>
|
|
97
|
+
<span className="truncate text-xs leading-4 text-muted-foreground">
|
|
98
|
+
{shownFolder(known)}
|
|
99
|
+
</span>
|
|
100
|
+
</span>
|
|
101
|
+
</button>
|
|
102
|
+
<button
|
|
103
|
+
type="button"
|
|
104
|
+
aria-label={messages.forgetFolder(shownFolder(known))}
|
|
105
|
+
title={messages.forgetFolder(shownFolder(known))}
|
|
106
|
+
className="absolute top-1/2 right-1.5 flex size-7 -translate-y-1/2 items-center justify-center rounded-full text-muted-foreground opacity-0 outline-none transition-opacity hover:bg-black/[0.05] focus-visible:opacity-100 group-hover/row:opacity-100 dark:hover:bg-white/[0.08]"
|
|
107
|
+
onClick={() => place.forgetFolder(known)}
|
|
108
|
+
>
|
|
109
|
+
<X className="size-3.5" strokeWidth={2.2} aria-hidden="true" />
|
|
110
|
+
</button>
|
|
111
|
+
</div>
|
|
112
|
+
))}
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
className={COMPOSER_MENU_ROW_CLASS_NAME}
|
|
116
|
+
onClick={() => {
|
|
117
|
+
setOpen(false)
|
|
118
|
+
void place.pickFolder()
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<FolderPlus className="size-4 shrink-0" strokeWidth={1.9} aria-hidden="true" />
|
|
122
|
+
<span className="min-w-0 flex-1 font-medium text-foreground">
|
|
123
|
+
{messages.chooseFolder}
|
|
124
|
+
</span>
|
|
125
|
+
</button>
|
|
126
|
+
<ComposerMenuDivider strong />
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
className={cn(
|
|
130
|
+
COMPOSER_MENU_ROW_CLASS_NAME,
|
|
131
|
+
cloud && COMPOSER_MENU_ROW_SELECTED_CLASS_NAME
|
|
132
|
+
)}
|
|
133
|
+
onClick={() => {
|
|
134
|
+
place.chooseCloud()
|
|
135
|
+
setOpen(false)
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<Cloud className="size-4 shrink-0" strokeWidth={1.9} aria-hidden="true" />
|
|
139
|
+
<span className="min-w-0 flex-1 font-medium text-foreground">{messages.cloud}</span>
|
|
140
|
+
</button>
|
|
141
|
+
</ComposerMenuScroll>
|
|
142
|
+
</ComposerMenu>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
} from "react"
|
|
44
44
|
import { createPortal } from "react-dom"
|
|
45
45
|
import { type AgentApprovalMode, toggledApprovalMode } from "../approvals"
|
|
46
|
+
import type { NewThreadPlace } from "../hooks/use-new-thread-place"
|
|
46
47
|
import { useAgentMessages } from "../i18n"
|
|
47
48
|
import type { AgentFileRef, LanguageModel } from "../types"
|
|
48
49
|
import { agentContextLabel, mergeAgentContext } from "../utils/context-display"
|
|
@@ -59,6 +60,7 @@ import {
|
|
|
59
60
|
commandQuery,
|
|
60
61
|
matchCommands,
|
|
61
62
|
} from "./composer-commands"
|
|
63
|
+
import { ComposerPlace } from "./composer-place"
|
|
62
64
|
import { ComposerSettings } from "./composer-settings"
|
|
63
65
|
import {
|
|
64
66
|
COMPOSER_CHIP_CLASS_NAME,
|
|
@@ -142,6 +144,8 @@ export interface ComposerProps {
|
|
|
142
144
|
readonly commands?: readonly ComposerCommand[]
|
|
143
145
|
/** How much of its model's limit the conversation uses: a ring beside the model. */
|
|
144
146
|
readonly contextMeter?: ContextMeterProps
|
|
147
|
+
/** Where a new conversation runs, where there's a choice; "waiting" until that's known. */
|
|
148
|
+
readonly newThreadPlace?: NewThreadPlace | "waiting"
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
type ComposerAttachment =
|
|
@@ -221,6 +225,7 @@ export function Composer({
|
|
|
221
225
|
dictation,
|
|
222
226
|
commands = [],
|
|
223
227
|
contextMeter,
|
|
228
|
+
newThreadPlace,
|
|
224
229
|
}: ComposerProps) {
|
|
225
230
|
const agentMessages = useAgentMessages()
|
|
226
231
|
const messages = agentMessages.composer
|
|
@@ -1004,6 +1009,14 @@ export function Composer({
|
|
|
1004
1009
|
)}
|
|
1005
1010
|
</div>
|
|
1006
1011
|
</div>
|
|
1012
|
+
{newThreadPlace ? (
|
|
1013
|
+
// Its height held from the first render: the composer doesn't move when the place arrives.
|
|
1014
|
+
<div data-slot="composer-place" className="mt-1.5 flex h-7 min-w-0 items-center pl-3.5">
|
|
1015
|
+
{newThreadPlace === "waiting" ? null : (
|
|
1016
|
+
<ComposerPlace place={newThreadPlace} disabled={disabled || pending} />
|
|
1017
|
+
)}
|
|
1018
|
+
</div>
|
|
1019
|
+
) : null}
|
|
1007
1020
|
<span className="sr-only" aria-live="polite">
|
|
1008
1021
|
{modeAnnouncement}
|
|
1009
1022
|
</span>
|