Skip to content

The agent that grows with you

fix(artifacts): index files produced by the terminal tool

andyst-dev276f2247427b
diff --git a/apps/desktop/src/app/artifacts/artifact-utils.ts b/apps/desktop/src/app/artifacts/artifact-utils.ts
index ef822a16ac3..47477d94664 100644
--- a/apps/desktop/src/app/artifacts/artifact-utils.ts
+++ b/apps/desktop/src/app/artifacts/artifact-utils.ts
@@ -329,6 +329,16 @@ function isArtifactProducerTool(name: string): boolean {
return ARTIFACT_PRODUCER_TOOL_RE.test(name) || name.startsWith('bfl_flux3_')
}
+function isTerminalTool(name: string): boolean {
+ return name === 'terminal'
+}
+
+// Shell-style tools report produced files as free text under generic keys
+// (`output` / `stdout` / `path`). Their values are scanned as prose (MEDIA
+// tags, markdown links, URLs, absolute paths) instead of being treated as a
+// single path value.
+const SHELL_OUTPUT_KEY_RE = /^(?:output|stdout|path)$/i
+
function explicitToolArtifactKey(keyPath: string, producerTool: boolean): boolean {
return keyPath
.split('.')
@@ -368,9 +378,10 @@ function collectArtifactsFromMessage(message: SessionMessage, pushValue: PushVal
const name = toolName(message)
const producerTool = isArtifactProducerTool(name)
+ const terminalTool = isTerminalTool(name)
- if (text && producerTool) {
- collectMediaValues(text, pushValue)
+ if (text && (producerTool || terminalTool)) {
+ collectArtifactsFromText(text, pushValue)
}
if (name === 'browser_vision' && text) {
@@ -388,7 +399,23 @@ function collectArtifactsFromMessage(message: SessionMessage, pushValue: PushVal
for (const parsed of payloads) {
collectStringValues(parsed, 'tool_result', (value, keyPath) => {
- if (!explicitToolArtifactKey(keyPath, producerTool)) {
+ const segments = keyPath
+ .split('.')
+ .filter(segment => segment && !/^\d+$/.test(segment))
+ const shellOutput = terminalTool && segments.some(segment => SHELL_OUTPUT_KEY_RE.test(segment))
+
+ if (!shellOutput && !explicitToolArtifactKey(keyPath, producerTool)) {
+ return
+ }
+
+ if (shellOutput) {
+ // A shell result is free text: scan it for MEDIA tags, markdown
+ // references, URLs and absolute paths rather than treating the
+ // whole value as one path.
+ if (value) {
+ collectArtifactsFromText(value, pushValue)
+ }
+
return
}
diff --git a/apps/desktop/src/app/artifacts/index.test.ts b/apps/desktop/src/app/artifacts/index.test.ts
index b321b171d96..943b5ccf74b 100644
--- a/apps/desktop/src/app/artifacts/index.test.ts
+++ b/apps/desktop/src/app/artifacts/index.test.ts
@@ -85,6 +85,64 @@ describe('collectArtifactsForSession', () => {
expect(artifacts).toHaveLength(0)
})
+ it('indexes files reported in terminal output text', () => {
+ const artifacts = collectArtifactsForSession(makeSession({ id: 'terminal-session' }), [
+ {
+ content: JSON.stringify({
+ output: 'wrote: /home/example/project/figure_variance.png and /home/example/project/report.pdf',
+ exit_code: 0
+ }),
+ role: 'tool',
+ timestamp: 1_781_774_001,
+ tool_name: 'terminal'
+ }
+ ])
+
+ const values = artifacts.map(artifact => artifact.value)
+
+ expect(values).toContain('/home/example/project/figure_variance.png')
+ expect(values).toContain('/home/example/project/report.pdf')
+ })
+
+ it('indexes MEDIA-delivered files from terminal stdout', () => {
+ const artifacts = collectArtifactsForSession(makeSession({ id: 'terminal-media-session' }), [
+ {
+ content: JSON.stringify({ output: 'done\nMEDIA:/tmp/plot.png', exit_code: 0 }),
+ role: 'tool',
+ timestamp: 1_781_774_001,
+ tool_name: 'terminal'
+ }
+ ])
+
+ expect(artifacts.map(artifact => artifact.value)).toContain('/tmp/plot.png')
+ })
+
+ it('does not scan generic keys of non-terminal tools as shell output', () => {
+ const artifacts = collectArtifactsForSession(makeSession({ id: 'search-noise-session' }), [
+ {
+ content: JSON.stringify({ output: 'see /tmp/generated/figure.png for details', query: 'x' }),
+ role: 'tool',
+ timestamp: 1_781_774_001,
+ tool_name: 'web_search'
+ }
+ ])
+
+ expect(artifacts).toHaveLength(0)
+ })
+
+ it('indexes files under a path-only key from terminal output', () => {
+ const artifacts = collectArtifactsForSession(makeSession({ id: 'terminal-path-session' }), [
+ {
+ content: JSON.stringify({ path: '/tmp/generated/results.csv', exit_code: 0 }),
+ role: 'tool',
+ timestamp: 1_781_774_001,
+ tool_name: 'terminal'
+ }
+ ])
+
+ expect(artifacts.map(artifact => artifact.value)).toContain('/tmp/generated/results.csv')
+ })
+
it('keeps explicit generated artifacts from tool output', () => {
const artifacts = collectArtifactsForSession(makeSession({ id: 'generated-session' }), [
{