@niracler/encore 0.2.0 → 0.4.0

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/src/render.mjs CHANGED
@@ -1,10 +1,14 @@
1
1
  import { createTranslator } from './i18n.mjs'
2
+ import { renderAttachment } from './attachment-reader.mjs'
2
3
  import { escapeHtml as escape, renderMarkdown } from './markdown.mjs'
3
4
  import { binSeconds, describeStats, minutes, sumStats, timeline } from './timeline.mjs'
4
5
 
5
6
  const toolLabels = {
6
7
  codex: 'Codex',
7
8
  workbuddy: 'WorkBuddy',
9
+ antigravity: 'Antigravity',
10
+ 'antigravity-app': 'Antigravity App',
11
+ 'antigravity-cli': 'Antigravity CLI',
8
12
  'claude-code': 'Claude Code',
9
13
  'claude-ai': 'Claude',
10
14
  }
@@ -83,7 +87,7 @@ function thumbs(names, baseUrl = '') {
83
87
  if (!names?.length) return ''
84
88
  return `<span class="session-thumbs">${names.map(name => {
85
89
  const url = escape(resolveAsset(name, baseUrl))
86
- return `<a href="${url}" target="_blank" rel="noopener noreferrer"><img src="${url}" alt="" width="96" loading="lazy"></a>`
90
+ return `<a href="${url}" data-lightbox-src="${url}" target="_blank" rel="noopener noreferrer"><img src="${url}" alt="" width="96" loading="lazy"></a>`
87
91
  }).join('')}</span>`
88
92
  }
89
93
 
@@ -154,77 +158,37 @@ function renderStepArtifacts(stepMeta, { skipImages = [], renderMd, t, baseUrl =
154
158
  return `<div class="session-frame-deck" data-frame-deck>${subagentHtml}${mediaRow}</div>`
155
159
  }
156
160
 
157
- function renderTimelineBar(line, t) {
161
+ export function renderTimelineBar(line, t) {
158
162
  const steps = line.steps || []
159
163
  const total = steps.length
160
- const rawPins = []
161
- steps.forEach((s, idx) => {
162
- const pct = total > 0 ? ((idx + 0.5) / total) * 100 : 0
163
- if (s.compactInfo) {
164
- const droppedK = ((s.compactInfo.droppedTokens || 0) / 1000).toFixed(0)
165
- rawPins.push({
166
- idx,
167
- pct,
168
- pinType: 'compress',
169
- label: `${t('tlCompressPin', { seq: s.compactInfo.seq })}${droppedK > 0 ? ` (-${droppedK}k)` : ''}`,
170
- turn: s.turn,
171
- })
172
- } else if (s.frames?.length) {
173
- const aiFrame = s.frames.find(f => f.who === 'ai') || s.frames[0]
174
- rawPins.push({ idx, pct, pinType: 'frame', label: aiFrame.label, turn: s.turn })
175
- } else if (s.docs?.length) {
176
- rawPins.push({ idx, pct, pinType: 'doc', label: s.docs[0].title, turn: s.turn })
177
- } else if (s.kind === 'prompt') {
178
- rawPins.push({ idx, pct, pinType: 'turn', label: `#${s.turn}`, turn: s.turn })
179
- }
180
- })
181
-
182
- const occupiedPcts = []
183
- const canShowText = pct => pct >= 5 && pct <= 95 && occupiedPcts.every(p => Math.abs(p - pct) >= 11)
184
- for (const pin of rawPins) {
185
- if (pin.pinType === 'compress' && canShowText(pin.pct)) {
186
- pin.showText = true
187
- occupiedPcts.push(pin.pct)
188
- }
189
- }
190
- for (const pin of rawPins) {
191
- if (pin.pinType === 'frame' && canShowText(pin.pct)) {
192
- pin.showText = true
193
- occupiedPcts.push(pin.pct)
194
- }
195
- }
196
- for (const pin of rawPins) {
197
- if (pin.pinType === 'doc' && canShowText(pin.pct)) {
198
- pin.showText = true
199
- occupiedPcts.push(pin.pct)
200
- }
201
- }
202
- if (rawPins.length <= 14) {
203
- for (const pin of rawPins) {
204
- if (pin.pinType === 'turn' && canShowText(pin.pct)) {
205
- pin.showText = true
206
- occupiedPcts.push(pin.pct)
207
- }
164
+ const pins = []
165
+ const cells = ['<span class="session-tl-cell"></span>']
166
+ for (const [idx, step] of steps.entries()) {
167
+ const frame = step.frames?.find(frame => frame.who === 'ai') || step.frames?.[0]
168
+ const doc = step.docs?.[0]
169
+ let kind = ''
170
+ let label = ''
171
+ let icon = ''
172
+ if (step.compactInfo) {
173
+ kind = 'compress'
174
+ label = t('tlCompressPin', { seq: step.compactInfo.seq })
175
+ icon = '🗜'
176
+ } else if (frame) {
177
+ kind = 'frame'
178
+ label = frame.label
179
+ icon = '🖼'
180
+ } else if (doc) {
181
+ kind = 'doc'
182
+ label = doc.title
183
+ icon = '📄'
184
+ } else if (step.kind === 'prompt') {
185
+ kind = 'turn'
186
+ label = t('tlPromptTitle', { turn: step.turn, summary: short(step.summary || '', 40) })
208
187
  }
188
+ cells.push(`<span class="session-tl-cell ${kind}"></span>`)
189
+ if (label) pins.push(`<button type="button" class="session-tl-pin" data-kind="${kind}" data-tl-jump="${idx}" aria-label="${escape(t('tlJumpAria', { step: idx + 1, label }))}"><span aria-hidden="true">${icon}</span><span class="session-tl-caption">${escape(label)}</span></button>`)
209
190
  }
210
191
 
211
- const pinsHtml = rawPins.map(pin => {
212
- const text = pin.pinType === 'compress'
213
- ? (pin.showText ? `🗜 ${escape(short(pin.label, 11))}` : '🗜')
214
- : pin.pinType === 'frame'
215
- ? (pin.showText ? `🖼 ${escape(short(pin.label, 8))}` : '🖼')
216
- : pin.pinType === 'doc'
217
- ? (pin.showText ? `📄 ${escape(short(pin.label, 8))}` : '📄')
218
- : (pin.showText ? `💬 #${pin.turn}` : '')
219
- const cls = `session-tl-pin is-${pin.pinType}${pin.showText ? ' has-label' : ' is-compact'}`
220
- return `<button type="button" class="${cls}" style="left:${pin.pct.toFixed(2)}%" data-tl-jump="${pin.idx}" data-tl-hover="${pin.idx}" aria-label="${escape(t('tlJumpAria', { step: pin.idx + 1, label: pin.label }))}">${text}</button>`
221
- }).join('')
222
-
223
- const segsHtml = steps.map((s, idx) => (
224
- `<div class="session-tl-seg${s.compactInfo ? ' has-compress' : s.frames?.length ? ' has-frame' : s.docs?.length ? ' has-doc' : ''}" data-tl-step="${idx}" data-tl-hover="${idx}"></div>`
225
- )).join('')
226
- const segGap = total > 360 ? '0px' : total > 160 ? '1px' : '2px'
227
-
228
192
  return `<footer class="session-timeline-bar" data-session-timeline aria-label="${escape(t('tlAria'))}">
229
193
  <div class="session-transport" role="group" aria-label="${escape(t('tlControlsAria'))}">
230
194
  <button type="button" class="session-nav-btn" data-session-prev disabled aria-label="${escape(t('prevStep'))}">◀</button>
@@ -233,10 +197,12 @@ function renderTimelineBar(line, t) {
233
197
  <span class="session-speed-badge" data-session-speed><b>0</b> / ${total} · 00:00</span>
234
198
  </div>
235
199
  <div class="session-tl-track-wrap" data-tl-track>
236
- <span class="session-composer-progress" data-session-progress aria-hidden="true"></span>
237
200
  <div class="session-tl-pop" data-tl-pop hidden></div>
238
- <div class="session-tl-pins" data-tl-pins>${pinsHtml}</div>
239
- <div class="session-tl-segs" style="--tl-gap:${segGap}" data-tl-segs>${segsHtml}</div>
201
+ ${pins.length ? `<div class="session-tl-pins">${pins.join('')}</div>` : ''}
202
+ <div class="session-tl-rail" style="--tl-count:${total + 1}">
203
+ <div class="session-tl-cells" aria-hidden="true">${cells.join('')}</div>
204
+ <input class="session-tl-range" data-tl-range type="range" min="0" max="${total}" step="1" value="0" aria-label="${escape(t('tlAria'))}"${total ? '' : ' disabled'}>
205
+ </div>
240
206
  </div>
241
207
  </footer>`
242
208
  }
@@ -326,12 +292,51 @@ function contextSidebar(line, t) {
326
292
  </aside>`
327
293
  }
328
294
 
295
+ function renderDeliverable(file, t, baseUrl) {
296
+ if (!file.availability) return renderFileContents(file, t, baseUrl)
297
+ if (file.availability === 'missing') {
298
+ const notice = { 'outside-root': 'fileOutsideRoot', unreadable: 'fileUnreadable' }[file.unavailableReason] || 'fileMissing'
299
+ return `<section class="session-file-missing" data-availability="missing"><strong>${escape(file.title)}</strong><small>${escape(t(notice))}</small></section>`
300
+ }
301
+ const notice = t(file.availability === 'verified' ? 'fileVerified' : file.sessionSha256 ? 'fileHashMismatch' : 'fileExportCopy')
302
+ return `<div class="session-file-copy" data-availability="${escape(file.availability)}"><small>${escape(notice)}</small>${renderFileContents(file, t, baseUrl)}</div>`
303
+ }
304
+
305
+ function renderFileContents(file, t, baseUrl) {
306
+ if (file.preview?.type === 'xlsx' || file.preview?.pages?.length && file.preview.type === 'pdf') {
307
+ return renderAttachment(file, t, src => resolveAsset(src, baseUrl))
308
+ }
309
+ const href = escape(resolveAsset(file.href, baseUrl))
310
+ const cover = escape(resolveAsset(file.cover, baseUrl))
311
+ const title = escape(file.title)
312
+ const caption = `<b>${title}</b>${file.meta ? `<small>${escape(file.meta)}</small>` : ''}`
313
+ if (!validVideo.test(file.href)) {
314
+ if (file.availability) return `<a class="session-file-download" href="${href}" download="${title}">${caption}</a>`
315
+ return `<a class="session-file" href="${href}" target="_blank" rel="noopener noreferrer">${cover ? `<img src="${cover}" alt="" width="56" height="79" loading="lazy">` : ''}<span>${caption}</span></a>`
316
+ }
317
+ const formats = file.portrait?.href ? `<div class="session-video-formats">
318
+ <button type="button" data-video-format="landscape" data-src="${href}" data-cover="${cover}" aria-pressed="true">${t('landscape')}</button>
319
+ <button type="button" data-video-format="portrait" data-src="${escape(resolveAsset(file.portrait.href, baseUrl))}" data-cover="${escape(resolveAsset(file.portrait.cover, baseUrl))}" aria-pressed="false">${t('portrait')}</button>
320
+ </div>` : ''
321
+ return `<figure class="session-video">
322
+ <figcaption><span>${caption}</span>${formats}</figcaption>
323
+ <video controls playsinline loading="lazy" preload="none" width="960" height="540" aria-label="${title}" src="${href}"${cover ? ` poster="${cover}"` : ''}></video>
324
+ </figure>`
325
+ }
326
+
329
327
  function renderLog(session, line, { t, baseUrl = '' }) {
330
328
  const tool = toolLabels[session.tool] || session.tool || 'Agent'
331
329
  const render = text => renderMarkdown(localLinks(text))
332
330
  const entries = []
333
331
  let shown = -Infinity
334
332
  let stepIndex = 0
333
+ let delivery = 0
334
+
335
+ function addFiles(files, step, time, atEnd = false, label = 'deliverablesTitle') {
336
+ if (!files?.length) return
337
+ const html = files.map(file => renderDeliverable(file, t, baseUrl)).join('')
338
+ entries.push(`<li class="session-entry session-ai session-files" data-delivery="${++delivery}"${atEnd ? ' data-final-files' : ''} data-for-step="${step}" data-t="${time}"><div class="session-bubble"><span class="session-who">${escape(t(label))}</span>${html}</div></li>`)
339
+ }
335
340
 
336
341
  const stamp = (seconds, forStep) => {
337
342
  if (seconds - shown < 300) return ''
@@ -387,7 +392,12 @@ function renderLog(session, line, { t, baseUrl = '' }) {
387
392
 
388
393
  for (const item of line.items) {
389
394
  if (item.type === 'tool' || item.type === 'reasoning') {
395
+ if (item.deliverables?.length) flush()
390
396
  work.push(item)
397
+ if (item.deliverables?.length) {
398
+ flush()
399
+ addFiles(item.deliverables, stepIndex - 1, item.t)
400
+ }
391
401
  continue
392
402
  }
393
403
  flush()
@@ -415,20 +425,10 @@ function renderLog(session, line, { t, baseUrl = '' }) {
415
425
  } else {
416
426
  entries.push(`${stamp(item.t, stepIndex - 1)}<li class="session-entry session-ai" data-step="${stepIndex - 1}" data-echo-cat="msg" data-kind="reply" data-t="${item.t}"><div class="session-bubble">${item.question ? `<span class="session-who">${escape(t('asksYou', { tool }))}</span>` : ''}<div class="session-ai-body">${render(item.text)}</div>${renderStepArtifacts(stepMeta, { renderMd: render, t, baseUrl })}</div></li>`)
417
427
  }
428
+ addFiles(item.deliverables, stepIndex - 1, item.t, false, item.type === 'user' ? 'inputFiles' : 'deliverablesTitle')
418
429
  }
419
430
  flush()
420
-
421
- const deliverables = session.deliverables || session.files || []
422
- const filesHtml = deliverables.map(file => {
423
- const href = escape(resolveAsset(file.href, baseUrl))
424
- const cover = file.cover ? escape(resolveAsset(file.cover, baseUrl)) : ''
425
- return validVideo.test(file.href)
426
- ? `<figure class="session-video"><video controls preload="none" playsinline width="960" height="540"${cover ? ` poster="${cover}"` : ''}><source src="${href}" type="video/mp4"></video><figcaption><b>${escape(file.title)}</b>${file.meta ? `<small>${escape(file.meta)}</small>` : ''}</figcaption></figure>`
427
- : `<a class="session-file" href="${href}" target="_blank" rel="noopener noreferrer">${cover ? `<img src="${cover}" alt="" width="56" height="79" loading="lazy">` : ''}<span><b>${escape(file.title)}</b>${file.meta ? `<small>${escape(file.meta)}</small>` : ''}</span></a>`
428
- }).join('')
429
- if (filesHtml) {
430
- entries.push(`<li class="session-entry session-ai session-files" data-for-step="${Math.max(0, line.steps.length - 1)}" data-t="${line.end}"><div class="session-bubble"><span class="session-who">${escape(t('deliverablesTitle'))}</span>${filesHtml}</div></li>`)
431
- }
431
+ addFiles(session.deliverables || session.files, Math.max(0, line.steps.length - 1), line.end, true)
432
432
  return `<ol class="session-log">${entries.join('')}</ol>`
433
433
  }
434
434
 
@@ -561,7 +561,7 @@ export function renderPlayerWidget(session, computedTimeline, {
561
561
  <div class="session-composer-bar">
562
562
  <span class="session-composer-left">
563
563
  <span class="session-composer-plus" aria-hidden="true">+</span>
564
- <span class="session-composer-perm" data-session-stage-badge>Workspace Write</span>
564
+ <span class="session-composer-perm" data-session-stage-badge>${escape(t('workspaceWrite'))}</span>
565
565
  </span>
566
566
  <span class="session-composer-right">
567
567
  <span class="session-composer-model">${escape(session.model || tool)}</span>
package/src/server.mjs CHANGED
@@ -9,6 +9,8 @@ const MIME_TYPES = {
9
9
  '.mjs': 'text/javascript; charset=utf-8',
10
10
  '.css': 'text/css; charset=utf-8',
11
11
  '.json': 'application/json; charset=utf-8',
12
+ '.pdf': 'application/pdf',
13
+ '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
12
14
  '.webp': 'image/webp',
13
15
  '.png': 'image/png',
14
16
  '.jpg': 'image/jpeg',
@@ -0,0 +1,162 @@
1
+ import readline from 'node:readline'
2
+ import { stripVTControlCharacters } from 'node:util'
3
+ import { createSessionCatalog } from './detect.mjs'
4
+ import { resolveLang } from './i18n.mjs'
5
+
6
+ const groups = [undefined, 'codex', 'claude-code', 'workbuddy', 'antigravity']
7
+
8
+ function oneLine(text) {
9
+ return stripVTControlCharacters(text).replace(/[\x00-\x1f\x7f-\x9f]/g, ' ')
10
+ }
11
+
12
+ function fit(text, columns) {
13
+ let width = 0
14
+ let out = ''
15
+ for (const ch of oneLine(text)) {
16
+ width += ch.codePointAt(0) > 0x1f00 ? 2 : 1
17
+ if (width > columns - 1) return out + '…'
18
+ out += ch
19
+ }
20
+ return out
21
+ }
22
+
23
+ export async function pickSession({ lang, input = process.stdin, output = process.stdout, list = createSessionCatalog() } = {}) {
24
+ const zh = resolveLang(lang) === 'zh'
25
+ const tabs = [zh ? '全部' : 'All', 'Codex', 'Claude Code', 'WorkBuddy', 'Antigravity']
26
+ const size = Math.max(1, Math.min(10, (output.rows || 24) - 6))
27
+ let tab = 0
28
+ let search
29
+ let rendered = 0
30
+ let closed = false
31
+ let fail
32
+ const views = new Map()
33
+
34
+ function newView(query) {
35
+ const controller = new AbortController()
36
+ return { query, controller, rows: [], selected: 0, done: false, loading: false,
37
+ iterator: list({ group: groups[tab], query, signal: controller.signal }) }
38
+ }
39
+
40
+ function active() {
41
+ if (search) return search
42
+ if (!views.has(tab)) views.set(tab, newView())
43
+ return views.get(tab)
44
+ }
45
+
46
+ function draw() {
47
+ if (closed) return
48
+ const view = active()
49
+ const start = Math.floor(view.selected / size) * size
50
+ const page = view.rows.slice(start, start + size)
51
+ const cols = Math.max(1, (output.columns || 80) - 1)
52
+ const headings = tabs.map((label, i) => i === tab ? '[' + label + ']' : label)
53
+ const bar = headings.join(' ')
54
+ const lines = [bar.length > cols ? headings[tab] : fit(bar, cols)]
55
+ if (search) lines.push(fit('/ ' + search.query, cols))
56
+ for (const [i, row] of page.entries()) {
57
+ const selected = start + i === view.selected
58
+ const source = groups[tab] === 'antigravity' ? row.toolLabel.replace(/^Antigravity /, '') : row.toolLabel
59
+ const archive = row.archived ? (zh ? ' [已归档]' : ' [Archived]') : ''
60
+ const line = fit((selected ? ' ❯ ' : ' ') + (i + 1) + '. ' + row.timeLabel + ' [' + source + ']' + archive + ' ' + row.preview, cols)
61
+ lines.push(selected ? '\x1b[1;36m' + line + '\x1b[0m' : line)
62
+ }
63
+ if (!page.length) lines.push(view.done ? (zh ? '没有匹配的会话' : 'No matching sessions') : (zh ? '正在读取会话…' : 'Loading sessions…'))
64
+ const help = search
65
+ ? (zh ? '↑↓ 选择 · ←→ 翻页 · Enter 打开 · Esc 返回' : '↑↓ move · ←→ page · Enter open · Esc back')
66
+ : (zh ? 'Tab 切换 · / 搜索 · ↑↓ 选择 · ←→ 翻页 · Enter 打开 · q 退出' : 'Tab switch · / search · ↑↓ move · ←→ page · Enter open · q quit')
67
+ lines.push(fit(help, cols))
68
+ if (rendered) {
69
+ readline.moveCursor(output, 0, -rendered)
70
+ readline.clearScreenDown(output)
71
+ }
72
+ output.write(lines.join('\n') + '\n')
73
+ rendered = lines.length
74
+ }
75
+
76
+ async function fill(view) {
77
+ if (view.loading || view.done) return
78
+ view.loading = true
79
+ try {
80
+ while (!closed && !view.controller.signal.aborted && view.rows.length <= (Math.floor(view.selected / size) + 1) * size) {
81
+ const { done, value } = await view.iterator.next()
82
+ if (done) {
83
+ view.done = true
84
+ break
85
+ }
86
+ view.rows.push(value)
87
+ if (view.rows.length === 1 && view === active()) draw()
88
+ }
89
+ } finally {
90
+ view.loading = false
91
+ }
92
+ if (!closed && view === active()) draw()
93
+ }
94
+
95
+ function refresh() {
96
+ draw()
97
+ fill(active()).catch(fail)
98
+ }
99
+
100
+ function stopSearch() {
101
+ search?.controller.abort()
102
+ search = undefined
103
+ }
104
+
105
+ function searchFor(query) {
106
+ stopSearch()
107
+ search = newView(query)
108
+ }
109
+
110
+ const wasRaw = input.isRaw
111
+ readline.emitKeypressEvents(input)
112
+ input.setRawMode(true)
113
+ let keypress
114
+ try {
115
+ return await new Promise((resolve, reject) => {
116
+ fail = reject
117
+ keypress = (str, key) => {
118
+ const view = active()
119
+ if (key.ctrl && key.name === 'c') return resolve(null)
120
+ if (key.name === 'escape') {
121
+ if (!search) return resolve(null)
122
+ stopSearch()
123
+ } else if (key.name === 'return' || key.name === 'enter') {
124
+ if (view.rows[view.selected]) return resolve(view.rows[view.selected])
125
+ } else if (key.name === 'tab') {
126
+ stopSearch()
127
+ tab = (tab + (key.shift ? -1 : 1) + tabs.length) % tabs.length
128
+ } else if (key.name === 'up' || (!search && key.name === 'k')) {
129
+ view.selected = Math.max(0, view.selected - 1)
130
+ } else if (key.name === 'down' || (!search && key.name === 'j')) {
131
+ view.selected = Math.max(0, Math.min(view.rows.length - 1, view.selected + 1))
132
+ } else if (key.name === 'left' || key.name === 'pageup') {
133
+ view.selected = Math.max(0, (Math.floor(view.selected / size) - 1) * size)
134
+ } else if (key.name === 'right' || key.name === 'pagedown') {
135
+ const next = (Math.floor(view.selected / size) + 1) * size
136
+ if (next < view.rows.length) view.selected = next
137
+ } else if (search && key.name === 'backspace') {
138
+ searchFor(Array.from(search.query).slice(0, -1).join(''))
139
+ } else if (search && str && !key.ctrl && !key.meta && !/[\x00-\x1f\x7f]/.test(str)) {
140
+ searchFor(search.query + str)
141
+ } else if (str === '/') {
142
+ searchFor('')
143
+ } else if (str === 'q') {
144
+ return resolve(null)
145
+ } else if (/^\d$/.test(str)) {
146
+ const pos = Math.floor(view.selected / size) * size + (Number(str) || 10) - 1
147
+ if (pos < view.rows.length) view.selected = pos
148
+ } else return
149
+ refresh()
150
+ }
151
+ input.on('keypress', keypress)
152
+ refresh()
153
+ })
154
+ } finally {
155
+ closed = true
156
+ stopSearch()
157
+ for (const view of views.values()) view.controller.abort()
158
+ input.off('keypress', keypress)
159
+ input.setRawMode(Boolean(wasRaw))
160
+ input.pause()
161
+ }
162
+ }
package/src/timeline.mjs CHANGED
@@ -162,7 +162,7 @@ function extractStepDocs(toolItems, stepIndex) {
162
162
  return [...byPath.values()]
163
163
  }
164
164
 
165
- function extractStepSubagents(toolItems, stepIndex) {
165
+ function extractStepSubagents(toolItems, stepIndex, t) {
166
166
  const list = []
167
167
  toolItems.forEach((item, idx) => {
168
168
  const rawSum = String(item.summary || '')
@@ -188,17 +188,17 @@ function extractStepSubagents(toolItems, stepIndex) {
188
188
  const combined = `${rawSum}\n${item.output || ''}`
189
189
  const isAsyncSpawn = /^(?:spawn_agent|collaboration__spawn_agent|followup_task|collaboration__followup_task)$/.test(item.name || '')
190
190
  let state = 'sent'
191
- let badge = '派出'
191
+ let badge = t('agentSent')
192
192
  let report = ''
193
193
  if (/was stopped|中途打断|已取消/i.test(combined)) {
194
194
  state = 'stopped'
195
- badge = '已叫停'
195
+ badge = t('agentStopped')
196
196
  } else if (/failed:|terminated early|rate_limit|hit your session limit|^Error:\s*Failed/im.test(combined)) {
197
197
  state = 'failed'
198
- badge = /limit|429/i.test(combined) ? '额度中断' : '失败'
198
+ badge = /limit|429/i.test(combined) ? t('agentRateLimited') : t('agentFailed')
199
199
  } else if (item.kind === 'reply' || item.stats?.reply || (!isAsyncSpawn && item.output && item.output.length > 80 && !item.output.trim().startsWith('{'))) {
200
200
  state = 'done'
201
- badge = '已交回'
201
+ badge = t('agentDone')
202
202
  if (item.output && item.output.length > 40 && !item.output.trim().startsWith('{')) {
203
203
  report = String(item.output).trim()
204
204
  }
@@ -462,7 +462,9 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
462
462
  }
463
463
  for (const item of items) {
464
464
  if (item.type === 'tool' || item.type === 'reasoning') {
465
+ if (item.deliverables?.length) flushWork()
465
466
  work.push(item)
467
+ if (item.deliverables?.length) flushWork()
466
468
  continue
467
469
  }
468
470
  flushWork()
@@ -485,16 +487,23 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
485
487
  return entry
486
488
  }
487
489
 
488
- const sysRecords = (initCtx.sys?.length ? initCtx.sys : defaultSystemPrompts(sessionTool)).map(r => registerRecord({ ...r, stepIndex: -1 }))
489
- const schemaRecords = (initCtx.schema?.length ? initCtx.schema : defaultToolSchemas(sessionTool)).map(r => registerRecord({ ...r, stepIndex: -1 }))
490
+ // Antigravity transcripts contain observed steps, with no initial prompt or tool inventory.
491
+ const observedOnly = sessionTool.startsWith('antigravity')
492
+ function initialRecords(key, defaults) {
493
+ const records = initCtx[key] || []
494
+ const entries = records.length || observedOnly ? records : defaults(sessionTool, sessionStart)
495
+ return entries.map(record => registerRecord({ ...record, stepIndex: -1 }))
496
+ }
497
+ const sysRecords = initialRecords('sys', defaultSystemPrompts)
498
+ const schemaRecords = initialRecords('schema', defaultToolSchemas)
490
499
  const schemaIdSet = new Set(schemaRecords.map(r => r.id))
491
500
  for (const r of schemaRecords) if (r.title) schemaIdSet.add(`schema-dyn-${String(r.title).replace(/[^a-zA-Z0-9_-]/g, '_')}`)
492
501
  const userRecords = []
493
502
  let toolRecords = []
494
- const skillRecords = (initCtx.skill?.length ? initCtx.skill : defaultSkillCatalog()).map(r => registerRecord({ ...r, stepIndex: -1 }))
503
+ const skillRecords = initialRecords('skill', defaultSkillCatalog)
495
504
  const knownSkillNames = new Set(skillRecords.map(r => r.title).filter(Boolean))
496
505
  const msgRecords = []
497
- const memRecords = (initCtx.mem?.length ? initCtx.mem : defaultInjectedContext(sessionTool, sessionStart)).map(r => registerRecord({ ...r, stepIndex: -1 }))
506
+ const memRecords = initialRecords('mem', defaultInjectedContext)
498
507
 
499
508
  const sumTokEst = list => list.reduce((acc, r) => acc + (r.tokEst || 600), 0)
500
509
  const sysTokens = sumTokEst(sysRecords)
@@ -509,7 +518,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
509
518
  let uncalibratedDelta = 0
510
519
  const allTools = []
511
520
  const allSkills = []
512
- const allMemories = ['AGENTS.md']
521
+ const allMemories = observedOnly ? [] : ['AGENTS.md']
513
522
  const allChanges = []
514
523
  let latestUserPrompt = ''
515
524
  let toolSeq = 0
@@ -572,7 +581,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
572
581
  name,
573
582
  color,
574
583
  itemCount: records.length,
575
- count: `${records.length} Items`,
584
+ count: t('itemCount', { n: records.length }),
576
585
  tok: `≈${(curTok / 1000).toFixed(1)}k`,
577
586
  pct: `${kindPct(curTok)}%`,
578
587
  delta: stepIdx >= 0 ? fmtCountDelta(records.length, prevCount) : '',
@@ -682,8 +691,8 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
682
691
  id: `user-${userSeq}`,
683
692
  stepIndex: index,
684
693
  tokEst: userTok,
685
- tag: `Turn #${turnCount}`,
686
- title: cleanPromptText.slice(0, 56) || 'User message',
694
+ tag: t('turnTag', { n: turnCount }),
695
+ title: cleanPromptText.slice(0, 56) || t('userMessage'),
687
696
  meta: `≈${(userTok / 1000).toFixed(1)}k · ${stepTime}s`,
688
697
  payload: String(first.text || ''),
689
698
  ...(first.images?.length ? { images: first.images } : {}),
@@ -700,7 +709,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
700
709
  tokEst: skTok,
701
710
  tag: 'SKILL.md',
702
711
  title: `${skill}/SKILL.md`,
703
- meta: `≈${(skTok / 1000).toFixed(1)}k · Turn #${turnCount}`,
712
+ meta: `≈${(skTok / 1000).toFixed(1)}k · ${t('turnTag', { n: turnCount })}`,
704
713
  payload: `# ${skill} (SKILL.md)\nLoaded into active context.`,
705
714
  }))
706
715
  }
@@ -709,10 +718,10 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
709
718
  primaryCat = 'user'
710
719
  speedLabel = '1.0×'
711
720
  dwellMs = 1500
712
- detailTitle = `Prompt #${turnCount}`
721
+ detailTitle = t('promptTitle', { n: turnCount })
713
722
  detailSnippet = (first.text || '').slice(0, 260)
714
- inBrief = 'User message appended to context'
715
- responseBrief = 'Waiting for Agent reasoning & tool calls'
723
+ inBrief = t('appendedPrompt')
724
+ responseBrief = t('waitingForTools')
716
725
  } else if (group.groupType === 'compact') {
717
726
  compactSeq++
718
727
  const cItem = first
@@ -765,10 +774,10 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
765
774
  speedLabel = '0.8×'
766
775
  dwellMs = 2100
767
776
  spotlight = 'context-compact'
768
- detailTitle = `Context Compaction #${compactInfo.seq}`
777
+ detailTitle = t('compactTitle', { seq: compactInfo.seq })
769
778
  detailSnippet = summaryText.slice(0, 260)
770
779
  inBrief = `${(preTokens / 1000).toFixed(1)}k → ${(postTokens / 1000).toFixed(1)}k`
771
- responseBrief = `Archived ${archivedTools} tool outputs (-${(droppedTokens / 1000).toFixed(1)}k tokens)`
780
+ responseBrief = t('archivedTools', { n: archivedTools, tokens: (droppedTokens / 1000).toFixed(1) })
772
781
  } else if (group.groupType === 'assistant') {
773
782
  msgSeq++
774
783
  const cleanReply = (first.text || '').replace(/\s+/g, ' ').trim()
@@ -779,8 +788,8 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
779
788
  id: `msg-${msgSeq}`,
780
789
  stepIndex: index,
781
790
  tokEst: msgTok,
782
- tag: `Reply #${msgSeq}`,
783
- title: cleanReply.slice(0, 56) || 'Assistant reply',
791
+ tag: t('replyTag', { n: msgSeq }),
792
+ title: cleanReply.slice(0, 56) || t('assistantReply'),
784
793
  meta: `≈${(msgTok / 1000).toFixed(1)}k · ${stepTime}s`,
785
794
  payload: String(first.text || ''),
786
795
  }))
@@ -794,17 +803,17 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
794
803
  primaryCat = 'msg'
795
804
  speedLabel = '1.0×'
796
805
  dwellMs = 1750
797
- detailTitle = 'Assistant Response'
806
+ detailTitle = t('assistantReply')
798
807
  detailSnippet = (first.text || '').slice(0, 260)
799
- inBrief = allTools.length ? `Synthesizing (${allTools.slice(-2).join(', ')})` : 'Direct response'
800
- responseBrief = cleanReply.slice(0, 96) || 'Completed response'
808
+ inBrief = allTools.length ? t('synthesizing', { tools: allTools.slice(-2).join(', ') }) : t('directResponse')
809
+ responseBrief = cleanReply.slice(0, 96) || t('completedResponse')
801
810
  } else {
802
811
  const toolItems = group.items.filter(item => item.type === 'tool')
803
812
  const reasoningItems = group.items.filter(item => item.type === 'reasoning')
804
813
  const stats = sumStats(toolItems)
805
814
  const extracted = extractFileChips(toolItems)
806
815
  stepDocs = extractStepDocs(toolItems, index)
807
- stepSubagents = extractStepSubagents(toolItems, index)
816
+ stepSubagents = extractStepSubagents(toolItems, index, t)
808
817
  stepAudios = extractStepAudios(toolItems, t)
809
818
  allTools.push(...extracted.tools)
810
819
  allChanges.push(...extracted.changes)
@@ -819,9 +828,9 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
819
828
  id: `mem-dyn-${memRecords.length + 1}`,
820
829
  stepIndex: index,
821
830
  tokEst: memTok,
822
- tag: 'Rule',
831
+ tag: t('rule'),
823
832
  title: `${memName}`,
824
- meta: `≈${(memTok / 1000).toFixed(1)}k · Step ${index + 1}`,
833
+ meta: `≈${(memTok / 1000).toFixed(1)}k · ${t('stepTag', { n: index + 1 })}`,
825
834
  payload: `# ${memName}\nLoaded into context during step ${index + 1}.`,
826
835
  }))
827
836
  }
@@ -837,9 +846,9 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
837
846
  id: `think-${msgSeq}`,
838
847
  stepIndex: index,
839
848
  tokEst: rTok,
840
- tag: 'Thinking',
849
+ tag: t('thinking'),
841
850
  title: rItem.text.replace(/\s+/g, ' ').trim().slice(0, 54),
842
- meta: `≈${(rTok / 1000).toFixed(1)}k · Reasoning`,
851
+ meta: `≈${(rTok / 1000).toFixed(1)}k · ${t('reasoning')}`,
843
852
  payload: String(rItem.text),
844
853
  }))
845
854
  }
@@ -865,7 +874,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
865
874
  tokEst: skTok,
866
875
  tag: 'SKILL.md',
867
876
  title: `${skill}/SKILL.md`,
868
- meta: `≈${(skTok / 1000).toFixed(1)}k · Step ${index + 1}`,
877
+ meta: `≈${(skTok / 1000).toFixed(1)}k · ${t('stepTag', { n: index + 1 })}`,
869
878
  payload: String(item.output || item.input || `# ${skill} (SKILL.md)`),
870
879
  }))
871
880
  }
@@ -905,7 +914,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
905
914
  toolRecords.push(registerRecord({
906
915
  id: `frame-${++toolSeq}`,
907
916
  stepIndex: index,
908
- tag: 'Preview',
917
+ tag: t('preview'),
909
918
  title: `${fr.label}`,
910
919
  meta: '≈1.2k tok',
911
920
  payload: `Preview frame: ${fr.label}`,
@@ -913,7 +922,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
913
922
  }))
914
923
  }
915
924
  rawMontage.push({
916
- tag: 'Preview',
925
+ tag: t('preview'),
917
926
  title: `${fr.label}`,
918
927
  isSpot: true,
919
928
  speed: '🖼',
@@ -921,7 +930,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
921
930
  }
922
931
  for (const doc of stepDocs) {
923
932
  rawMontage.push({
924
- tag: 'Draft',
933
+ tag: t('draft'),
925
934
  title: `${doc.title}`,
926
935
  isSpot: true,
927
936
  speed: '📄',
@@ -968,7 +977,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
968
977
  dwellMs = 1100
969
978
  }
970
979
  if (toolItems.length) {
971
- detailTitle = `Tool Call × ${toolItems.length}`
980
+ detailTitle = t('toolCalls', { n: toolItems.length })
972
981
  detailSnippet = toolItems.slice(0, 3).map(item => item.summary).join('\n')
973
982
  const primaryTool = toolItems[0]?.name || 'tool'
974
983
  inBrief = `${primaryTool} · ${toolItems.slice(0, 2).map(i => i.summary).join(';')}`
@@ -1059,7 +1068,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
1059
1068
  snippet: detailSnippet,
1060
1069
  },
1061
1070
  brief: {
1062
- user: latestUserPrompt || 'Session Start',
1071
+ user: latestUserPrompt || t('sessionStart'),
1063
1072
  in: inBrief,
1064
1073
  response: responseBrief,
1065
1074
  },