Merge branch 'master' into fetch-failed-diagnostics

This commit is contained in:
Tianyi Cui
2026-07-20 20:08:29 +08:00
381 changed files with 8335 additions and 7566 deletions

View File

@@ -31,7 +31,7 @@ Each non-empty terminal line outside an active question becomes one text block,
#### Token effect
Submitted text is retained under the agent loop's normal session-history and compaction rules. The welcome banner, `> ` prompt, rendered transcript, and `[tool call]` / `[tool result]` terminal lines add no tokens.
Submitted text is retained under the agent loop's normal session-history and compaction rules. The welcome banner, `> ` prompt, rendered transcript, and `[tool call]` / `[tool result]` terminal lines add no tokens. A replacement `tool/result` remains model-visible through the session surface but is not rendered as a second execution; stdio keeps the original full-fidelity result line.
#### KV Cache effect

View File

@@ -152,6 +152,10 @@ export function createStdioChat(ctx: Context, config: Config, runtime: StdioRunt
inReasoning = false
output.write(`\n [tool call] ${toolName}(${args})`)
} else if (event.type === 'tool/result') {
// A surface replacement changes future model context; it is not another
// execution. Keep the original full-fidelity terminal presentation and
// suppress duplicate output during live delivery or log replay.
if (event.surfaceOp !== undefined && event.surfaceOp !== 'append') return
const { content } = event.data
const text = content.filter(block => block.type === 'text').map(block => block.text).join('')
output.write(`\n [tool result] ${text}\n `)
@@ -171,9 +175,9 @@ export function createStdioChat(ctx: Context, config: Config, runtime: StdioRunt
// immediately — no turn will ever start, so there is nothing to wait
// for. (Gating on an observed 'running' here would hang forever.)
// - If work WAS submitted, exit the next time the agent settles to idle
// AFTER having run. Two subtleties this handles: the loop batches
// several queued messages into ONE turn (one idle), so we don't count
// sends; and agent.send() does NOT synchronously flip status to
// AFTER having run. Later lines may steer the active turn, and consecutive
// queued turns can share one running interval, so we don't count inputs;
// agent.send() also does NOT synchronously flip status to
// 'running', so requiring an observed 'running' first (`sawRunning`)
// avoids exiting in the gap before the turn starts and dropping work.
let stdinClosed = false

View File

@@ -402,6 +402,43 @@ describe('createStdioChat rendering', () => {
expect(out.text()).toContain('[tool result] file.txt')
})
it('renders one full-fidelity result whether the event feed is live or replayed', async () => {
const { ctx, out } = await setup()
const session = makeSession('main')
const original = {
type: 'tool/result',
seq: 2,
time: 0,
data: {
turn: 1,
step: 1,
callId: 'c1',
content: [{ type: 'text', text: 'full terminal output' }],
isError: false,
meta: { terminal: { output: 'full terminal output' } },
},
surfaceOp: 'append',
} as SessionEvent
const replacement = {
...original,
seq: 3,
data: {
...original.data,
content: [{ type: 'text', text: '[... tool result middle pruned ...]' }],
},
surfaceOp: { op: 'replace', start: 2, end: 2 },
sourceEventSeqs: [2],
} as SessionEvent
// Stdio consumes the same session/event shape whether a host forwards a
// live append or replays a stored log through the rendering feed.
for (const event of [original, replacement]) ctx.emit('session/event', session, event)
expect(out.text().match(/\[tool result\]/g)).toHaveLength(1)
expect(out.text()).toContain('full terminal output')
expect(out.text()).not.toContain('tool result middle pruned')
})
it('renders a todo/write session event as a glyphed checklist', async () => {
const { ctx, out } = await setup()
const session = {} as Session