@niracler/encore 0.3.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/README.md +41 -109
- package/README.zh-CN.md +41 -109
- package/bin/encore.mjs +9 -100
- package/package.json +2 -2
- package/player/encore-player.css +42 -43
- package/player/encore-player.js +145 -201
- package/schema/session.schema.json +1 -1
- package/skills/encore/SKILL.md +2 -2
- package/src/antigravity.mjs +162 -0
- package/src/common.mjs +5 -2
- package/src/detect.mjs +96 -51
- package/src/external-files.mjs +22 -5
- package/src/i18n.mjs +1 -3
- package/src/index.d.ts +5 -2
- package/src/index.mjs +17 -6
- package/src/player-runtime.mjs +95 -121
- package/src/render.mjs +35 -70
- package/src/session-picker.mjs +162 -0
- package/src/timeline.mjs +12 -5
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
4
|
+
import { readFile, realpath, stat } from 'node:fs/promises'
|
|
5
|
+
import { homedir } from 'node:os'
|
|
6
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
7
|
+
import { createTranscript, describeTool } from './common.mjs'
|
|
8
|
+
import { redactText } from './redact.mjs'
|
|
9
|
+
import { fileReferences, recordedText, within } from './external-files.mjs'
|
|
10
|
+
|
|
11
|
+
export const antigravityStores = () => ({
|
|
12
|
+
'antigravity-app': join(homedir(), '.gemini', 'antigravity', 'brain'),
|
|
13
|
+
'antigravity-cli': join(homedir(), '.gemini', 'antigravity-cli', 'brain'),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export function nativeAntigravityLog(file) {
|
|
17
|
+
const path = realpathSync.native(file)
|
|
18
|
+
for (const [tool, store] of Object.entries(antigravityStores())) {
|
|
19
|
+
if (!existsSync(store)) continue
|
|
20
|
+
const root = realpathSync.native(store)
|
|
21
|
+
const [id, system, logs, name, ...rest] = relative(root, path).split(sep)
|
|
22
|
+
if (id !== '..' && system === '.system_generated' && logs === 'logs' &&
|
|
23
|
+
/^transcript(?:_full)?\.jsonl$/.test(name) && !rest.length) {
|
|
24
|
+
return { tool, root: join(root, id), id }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Newer installations index conversation titles, activity, workspaces and App archives in SQLite.
|
|
30
|
+
export function antigravitySummaries(root) {
|
|
31
|
+
const path = join(dirname(root), 'conversation_summaries.db')
|
|
32
|
+
if (!existsSync(path)) return new Map()
|
|
33
|
+
let db
|
|
34
|
+
try {
|
|
35
|
+
const Database = process.getBuiltinModule?.('node:sqlite')?.DatabaseSync
|
|
36
|
+
db = Database && new Database(path, { readOnly: true })
|
|
37
|
+
function query(sql) {
|
|
38
|
+
if (db) return db.prepare(sql).all()
|
|
39
|
+
const result = spawnSync('sqlite3', ['-readonly', '-json', path, sql], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
|
|
40
|
+
if (result.error || result.status !== 0) throw result.error || new Error(result.stderr)
|
|
41
|
+
return JSON.parse(result.stdout || '[]')
|
|
42
|
+
}
|
|
43
|
+
const summaries = query('SELECT conversation_id, title, last_modified_time, workspace_uris FROM conversation_summaries')
|
|
44
|
+
const hasSearch = query("SELECT 1 FROM sqlite_master WHERE name = 'conversations_fts'").length
|
|
45
|
+
const archived = new Set(hasSearch ? query("SELECT DISTINCT conversation_id FROM conversations_fts WHERE archived IN (1, '1')").map(r => r.conversation_id) : [])
|
|
46
|
+
return new Map(summaries.map(row => {
|
|
47
|
+
const uris = JSON.parse(row.workspace_uris || '[]') || []
|
|
48
|
+
const workspaces = uris.filter(uri => typeof uri === 'string' && uri.startsWith('file:///')).map(uri => fileURLToPath(uri))
|
|
49
|
+
return [row.conversation_id, { title: row.title, workspaces, archived: archived.has(row.conversation_id),
|
|
50
|
+
updated: Date.parse(row.last_modified_time.replace(' ', 'T')) }]
|
|
51
|
+
}))
|
|
52
|
+
} catch {
|
|
53
|
+
// The index is optional on older installations. The transcript and annotations remain usable.
|
|
54
|
+
return new Map()
|
|
55
|
+
} finally {
|
|
56
|
+
db?.close()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function antigravityTitle(root, id) {
|
|
61
|
+
const path = join(dirname(root), 'annotations', id + '.pbtxt')
|
|
62
|
+
if (!existsSync(path)) return ''
|
|
63
|
+
const literal = readFileSync(path, 'utf8').match(/^title:\s*("(?:[^"\\]|\\.)*")/m)?.[1]
|
|
64
|
+
if (!literal) return ''
|
|
65
|
+
try { return JSON.parse(literal) } catch { return '' } // Unrecognized protobuf escape: use the first prompt.
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function antigravityPrompt(content = '') {
|
|
69
|
+
const request = content.match(/<USER_REQUEST>([\s\S]*?)(?:<\/USER_REQUEST>|$)/)?.[1] ?? content
|
|
70
|
+
return request.replace(/<external_system_instructions>[\s\S]*?(?:<\/external_system_instructions>|$)/g, '').trim()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function isAntigravityRecord(rec) {
|
|
74
|
+
return Number.isInteger(rec?.step_index) && typeof rec.created_at === 'string' &&
|
|
75
|
+
typeof rec.source === 'string' && typeof rec.type === 'string'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function loadMedia(media, logDir, roots, userSelected = false) {
|
|
79
|
+
const images = []
|
|
80
|
+
for (const { uri, mime_type: mime } of media || []) {
|
|
81
|
+
if (!mime?.startsWith('image/')) continue
|
|
82
|
+
const path = fileReferences([uri], logDir)[0]?.source?.path
|
|
83
|
+
if (!path) continue
|
|
84
|
+
try {
|
|
85
|
+
const actual = await realpath(path)
|
|
86
|
+
if ((userSelected || roots.some(root => within(actual, root))) && (await stat(actual)).isFile()) {
|
|
87
|
+
images.push({ mime, base64: (await readFile(actual)).toString('base64') })
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (!['ENOENT', 'ENOTDIR', 'EACCES', 'EPERM', 'ELOOP'].includes(error.code)) throw error
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return images
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function reviewedFiles(name, args, cwd) {
|
|
97
|
+
if (name === 'notify_user' && Array.isArray(args.PathsToReview)) return fileReferences(args.PathsToReview, cwd)
|
|
98
|
+
if (name === 'exit_plan_mode' && typeof args.plan === 'string' && args.plan.trim()) {
|
|
99
|
+
const plan = args.plan.trim()
|
|
100
|
+
if (/^(?:file:\/\/|\/|[A-Z]:[\\/])[^\n]*\.md$/i.test(plan)) return fileReferences([plan], cwd)
|
|
101
|
+
return [{ title: 'implementation_plan.md', [recordedText]: redactText(plan) }]
|
|
102
|
+
}
|
|
103
|
+
return []
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function readAntigravity(records, { file, tool, native, images, assetRoots }) {
|
|
107
|
+
const transcript = createTranscript()
|
|
108
|
+
const logDir = dirname(file)
|
|
109
|
+
const defaults = [process.cwd(), ...(native?.workspaces || []).filter(dir => existsSync(dir))]
|
|
110
|
+
const roots = await Promise.all((assetRoots?.length ? assetRoots : defaults).map(dir => realpath(resolve(dir))))
|
|
111
|
+
const cwd = native?.workspaces?.[0] || native?.root
|
|
112
|
+
// Native recordings own their media directory. A detached log only gets the caller's asset roots.
|
|
113
|
+
if (native) roots.push(await realpath(native.root))
|
|
114
|
+
const userSelected = Boolean(native?.workspaces?.length && !assetRoots)
|
|
115
|
+
let pending = []
|
|
116
|
+
let model
|
|
117
|
+
let tokens = 0
|
|
118
|
+
for (const record of records) {
|
|
119
|
+
const { type, created_at: time, content = '', step_index: step } = record
|
|
120
|
+
if (type === 'USER_INPUT') {
|
|
121
|
+
pending = []
|
|
122
|
+
transcript.user(antigravityPrompt(content), time, {
|
|
123
|
+
images: images ? await loadMedia(record.media, logDir, roots, userSelected) : [],
|
|
124
|
+
cwd,
|
|
125
|
+
})
|
|
126
|
+
} else if (type === 'PLANNER_RESPONSE') {
|
|
127
|
+
pending = []
|
|
128
|
+
model = record.model || model
|
|
129
|
+
const contextTokens = (record.input_tokens || 0) + (record.cache_read_tokens || 0)
|
|
130
|
+
tokens += contextTokens + (record.output_tokens || 0)
|
|
131
|
+
transcript.reasoning(record.thinking, time)
|
|
132
|
+
transcript.assistant(content, time, { cwd, ...(contextTokens && { contextTokens }) })
|
|
133
|
+
for (const [i, call] of (record.tool_calls || []).entries()) {
|
|
134
|
+
const id = step + '/' + i
|
|
135
|
+
const args = call.args || {}
|
|
136
|
+
const name = call.name || 'tool'
|
|
137
|
+
const base = name.replace(/^mcp_ide-tools_/, '')
|
|
138
|
+
const details = describeTool(base, {
|
|
139
|
+
...args,
|
|
140
|
+
...(args.CommandLine && { command: args.CommandLine }),
|
|
141
|
+
...(args.Path && { path: args.Path }),
|
|
142
|
+
})
|
|
143
|
+
const item = transcript.tool(id, { ...details, name }, time)
|
|
144
|
+
if (contextTokens) item.contextTokens = contextTokens
|
|
145
|
+
const files = reviewedFiles(base, args, cwd)
|
|
146
|
+
if (files.length) item.deliverables = files
|
|
147
|
+
pending.push(id)
|
|
148
|
+
}
|
|
149
|
+
} else if (type === 'GENERIC') {
|
|
150
|
+
// Each batch's result steps follow its tool calls in trajectory order.
|
|
151
|
+
const id = pending.shift()
|
|
152
|
+
const output = content.replace(/^(?:(?:Created At|Completed At):[^\n]*(?:\n|$))+/u, '').trim()
|
|
153
|
+
const done = content.match(/^Completed At:\s*([^\r\n]+)/m)?.[1] || time
|
|
154
|
+
if (id !== undefined) transcript.result(id, [output, record.error].filter(Boolean).join('\n'), done,
|
|
155
|
+
images ? await loadMedia(record.media, logDir, roots) : [], cwd)
|
|
156
|
+
} else if (type === 'ERROR_MESSAGE') {
|
|
157
|
+
transcript.assistant(record.error || content, time)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return transcript.finish({ tool, model, tokens: tokens || undefined,
|
|
161
|
+
title: native?.title || (native && antigravityTitle(dirname(native.root), native.id)) })
|
|
162
|
+
}
|
package/src/common.mjs
CHANGED
|
@@ -6,6 +6,9 @@ import { fileReferences, messageReferences } from './external-files.mjs'
|
|
|
6
6
|
export const tools = {
|
|
7
7
|
codex: 'Codex',
|
|
8
8
|
workbuddy: 'WorkBuddy',
|
|
9
|
+
antigravity: 'Antigravity',
|
|
10
|
+
'antigravity-app': 'Antigravity App',
|
|
11
|
+
'antigravity-cli': 'Antigravity CLI',
|
|
9
12
|
'claude-code': 'Claude Code',
|
|
10
13
|
'claude-ai': 'Claude',
|
|
11
14
|
}
|
|
@@ -187,9 +190,9 @@ const toolKinds = {
|
|
|
187
190
|
Bash: 'command', shell: 'command', exec_command: 'command', execute_command: 'command', run_command: 'command',
|
|
188
191
|
Read: 'read', read_file: 'read', view: 'read', Glob: 'find', Grep: 'find', LS: 'find', list_dir: 'find',
|
|
189
192
|
Write: 'edit', Edit: 'edit', MultiEdit: 'edit', NotebookEdit: 'edit', apply_patch: 'edit',
|
|
190
|
-
create_file: 'edit', write_file: 'edit', str_replace: 'edit', str_replace_based_edit_tool: 'edit',
|
|
193
|
+
create_file: 'edit', write_file: 'edit', edit_file: 'edit', str_replace: 'edit', str_replace_based_edit_tool: 'edit',
|
|
191
194
|
Agent: 'agent', Task: 'agent', Skill: 'skill', start_process: 'command', device_bash: 'command',
|
|
192
|
-
view_image: 'view',
|
|
195
|
+
view_image: 'view', webview_browser: 'view', search_web: 'search', invoke_subagent: 'agent',
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
const toolNames = {
|
package/src/detect.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createReadStream, existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
2
2
|
import { homedir } from 'node:os'
|
|
3
|
-
import { dirname, join, resolve } from 'node:path'
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { antigravityPrompt, antigravityStores, antigravitySummaries, antigravityTitle, isAntigravityRecord, nativeAntigravityLog } from './antigravity.mjs'
|
|
4
5
|
import { cleanPrompt } from './codex.mjs'
|
|
5
6
|
import { userText } from './claude-code.mjs'
|
|
6
7
|
import { lines, textOf, tools } from './common.mjs'
|
|
@@ -37,17 +38,18 @@ export async function detectInput(targetPath) {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export async function detectJsonlTool(filePath) {
|
|
40
|
-
const stream = createReadStream(filePath
|
|
41
|
+
const stream = createReadStream(filePath)
|
|
41
42
|
let count = 0
|
|
42
43
|
for await (const line of lines(stream)) {
|
|
43
44
|
const trimmed = line.trim()
|
|
44
45
|
if (!trimmed) continue
|
|
45
46
|
count++
|
|
46
|
-
if (count === 1 &&
|
|
47
|
+
if (count === 1 && trimmed.startsWith('[')) {
|
|
47
48
|
return 'claude-ai'
|
|
48
49
|
}
|
|
49
50
|
try {
|
|
50
51
|
const rec = JSON.parse(trimmed)
|
|
52
|
+
if (isAntigravityRecord(rec)) return nativeAntigravityLog(filePath)?.tool || 'antigravity'
|
|
51
53
|
if (rec.type === 'session_meta' || rec.type === 'turn_context' || rec.type === 'response_item' || rec.type === 'event_msg') {
|
|
52
54
|
return 'codex'
|
|
53
55
|
}
|
|
@@ -74,7 +76,7 @@ export async function detectJsonlTool(filePath) {
|
|
|
74
76
|
return 'claude-ai'
|
|
75
77
|
}
|
|
76
78
|
} catch {
|
|
77
|
-
//
|
|
79
|
+
// Skip malformed records while identifying a log.
|
|
78
80
|
}
|
|
79
81
|
if (count >= 40) break
|
|
80
82
|
}
|
|
@@ -98,7 +100,7 @@ function walkFiles(dir, matcher, results = [], maxDepth = 5, depth = 0) {
|
|
|
98
100
|
} else if (entry.isFile() && matcher(entry.name, full)) {
|
|
99
101
|
try {
|
|
100
102
|
const st = statSync(full)
|
|
101
|
-
if (st.size >
|
|
103
|
+
if (st.size > 0) {
|
|
102
104
|
results.push({ file: full, mtimeMs: st.mtimeMs, size: st.size })
|
|
103
105
|
}
|
|
104
106
|
} catch {
|
|
@@ -109,27 +111,21 @@ function walkFiles(dir, matcher, results = [], maxDepth = 5, depth = 0) {
|
|
|
109
111
|
return results
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
async function summarizeLogFile(file, toolHint) {
|
|
113
|
-
const stream = createReadStream(file
|
|
114
|
+
async function summarizeLogFile(file, toolHint, knownTitle) {
|
|
115
|
+
const stream = createReadStream(file)
|
|
114
116
|
let tool = toolHint
|
|
115
|
-
let title = ''
|
|
117
|
+
let title = knownTitle || ''
|
|
116
118
|
let firstPrompt = ''
|
|
117
|
-
let timestamp = ''
|
|
118
|
-
let lineCount = 0
|
|
119
|
-
|
|
120
119
|
for await (const line of lines(stream)) {
|
|
121
120
|
const trimmed = line.trim()
|
|
122
121
|
if (!trimmed) continue
|
|
123
|
-
|
|
122
|
+
|
|
124
123
|
let rec
|
|
125
124
|
try {
|
|
126
125
|
rec = JSON.parse(trimmed)
|
|
127
126
|
} catch {
|
|
128
127
|
continue
|
|
129
128
|
}
|
|
130
|
-
if (!timestamp && rec.timestamp) {
|
|
131
|
-
timestamp = typeof rec.timestamp === 'number' ? new Date(rec.timestamp).toISOString() : String(rec.timestamp)
|
|
132
|
-
}
|
|
133
129
|
if (rec.type === 'session_meta' || rec.type === 'response_item') tool = 'codex'
|
|
134
130
|
if (rec.providerData || rec.type === 'function_call_result') tool = 'workbuddy'
|
|
135
131
|
if (rec.type === 'custom-title' && rec.customTitle) title = rec.customTitle
|
|
@@ -137,7 +133,9 @@ async function summarizeLogFile(file, toolHint) {
|
|
|
137
133
|
if (rec.type === 'summary' && rec.summary && !title) title = rec.summary
|
|
138
134
|
|
|
139
135
|
if (!firstPrompt) {
|
|
140
|
-
if (tool
|
|
136
|
+
if (tool.startsWith('antigravity') && rec.type === 'USER_INPUT') {
|
|
137
|
+
firstPrompt = antigravityPrompt(rec.content) || (rec.media?.length ? '[图片]' : '')
|
|
138
|
+
} else if (tool === 'codex' && rec.type === 'response_item' && rec.payload?.type === 'message' && rec.payload?.role === 'user') {
|
|
141
139
|
const raw = textOf(rec.payload.content)
|
|
142
140
|
.replace(/^\s*<([a-z][\w-]*context)\b[^>]*>[\s\S]*?<\/\1>\s*/g, '')
|
|
143
141
|
.trim()
|
|
@@ -162,15 +160,14 @@ async function summarizeLogFile(file, toolHint) {
|
|
|
162
160
|
if (txt && txt !== '(中途打断)') firstPrompt = txt
|
|
163
161
|
}
|
|
164
162
|
}
|
|
165
|
-
if (
|
|
166
|
-
if (lineCount > 240 && firstPrompt) break
|
|
163
|
+
if (firstPrompt && (tool === 'codex' || tool.startsWith('antigravity'))) break
|
|
167
164
|
}
|
|
168
165
|
|
|
169
|
-
const rawPreview = (title || firstPrompt || '').replace(/\
|
|
166
|
+
const rawPreview = (title || firstPrompt || '').replace(/\s+/g, ' ').trim()
|
|
170
167
|
return {
|
|
171
168
|
tool,
|
|
169
|
+
title, firstPrompt,
|
|
172
170
|
preview: rawPreview ? (rawPreview.length > 58 ? `${rawPreview.slice(0, 57)}…` : rawPreview) : '',
|
|
173
|
-
timestamp,
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
173
|
|
|
@@ -180,46 +177,94 @@ function formatLocalTime(ms) {
|
|
|
180
177
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
|
181
178
|
}
|
|
182
179
|
|
|
183
|
-
|
|
180
|
+
function antigravityFiles(root, toolHint) {
|
|
181
|
+
if (!existsSync(root)) return []
|
|
182
|
+
const files = []
|
|
183
|
+
const summaries = antigravitySummaries(root)
|
|
184
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
185
|
+
if (!entry.isDirectory()) continue
|
|
186
|
+
const logs = join(root, entry.name, '.system_generated', 'logs')
|
|
187
|
+
for (const name of ['transcript_full.jsonl', 'transcript.jsonl']) {
|
|
188
|
+
const file = join(logs, name)
|
|
189
|
+
const st = statSync(file, { throwIfNoEntry: false })
|
|
190
|
+
if (!st?.isFile() || !st.size) continue
|
|
191
|
+
const summary = summaries.get(entry.name)
|
|
192
|
+
files.push({ file, mtimeMs: summary?.updated || st.mtimeMs, size: st.size, toolHint, id: entry.name, root,
|
|
193
|
+
title: summary?.title, archived: summary?.archived })
|
|
194
|
+
break
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return files
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function codexTitles(dir) {
|
|
201
|
+
const index = join(dirname(dir), 'session_index.jsonl')
|
|
202
|
+
const titles = new Map()
|
|
203
|
+
if (!existsSync(index)) return titles
|
|
204
|
+
for (const line of readFileSync(index, 'utf8').split('\n')) {
|
|
205
|
+
if (!line) continue
|
|
206
|
+
try {
|
|
207
|
+
const { id, thread_name } = JSON.parse(line)
|
|
208
|
+
if (thread_name) titles.set(id, thread_name)
|
|
209
|
+
} catch { /* A live index can end in an incomplete line. */ }
|
|
210
|
+
}
|
|
211
|
+
return titles
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function createSessionCatalog({
|
|
184
215
|
codexDir = join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'sessions'),
|
|
185
216
|
claudeDir = join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'), 'projects'),
|
|
186
217
|
workbuddyDir = join(process.env.WORKBUDDY_HOME || join(homedir(), '.workbuddy'), 'projects'),
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
antigravityAppDir = antigravityStores()['antigravity-app'],
|
|
219
|
+
antigravityCliDir = antigravityStores()['antigravity-cli'],
|
|
220
|
+
} = {}) {
|
|
221
|
+
const rollout = name => name.startsWith('rollout-') && name.endsWith('.jsonl')
|
|
222
|
+
const index = codexTitles(codexDir)
|
|
223
|
+
const codex = (dir, archived) => walkFiles(dir, rollout).map(item => ({
|
|
224
|
+
...item, toolHint: 'codex', archived,
|
|
225
|
+
title: index.get(basename(item.file, '.jsonl').slice(-36)),
|
|
226
|
+
}))
|
|
227
|
+
const candidates = [
|
|
228
|
+
...codex(codexDir, false),
|
|
229
|
+
...codex(join(dirname(codexDir), 'archived_sessions'), true),
|
|
230
|
+
...walkFiles(claudeDir, name => name.endsWith('.jsonl') && !name.startsWith('agent-')).map(item => ({ ...item, toolHint: 'claude-code' })),
|
|
231
|
+
...walkFiles(workbuddyDir, name => name.endsWith('.jsonl')).map(item => ({ ...item, toolHint: 'workbuddy' })),
|
|
232
|
+
...antigravityFiles(antigravityAppDir, 'antigravity-app'),
|
|
233
|
+
...antigravityFiles(antigravityCliDir, 'antigravity-cli'),
|
|
234
|
+
].sort((a, b) => b.mtimeMs - a.mtimeMs)
|
|
235
|
+
const summaries = new Map()
|
|
236
|
+
return async function* list({ group, query, signal } = {}) {
|
|
237
|
+
const term = query?.trim().toLowerCase()
|
|
238
|
+
for (const cand of candidates) {
|
|
239
|
+
if (signal?.aborted) return
|
|
240
|
+
if (cand.archived && query === undefined) continue
|
|
241
|
+
if (group && group !== (cand.toolHint.startsWith('antigravity') ? 'antigravity' : cand.toolHint)) continue
|
|
242
|
+
if (!summaries.has(cand.file)) {
|
|
243
|
+
const title = cand.title || (cand.id && antigravityTitle(cand.root, cand.id))
|
|
244
|
+
summaries.set(cand.file, summarizeLogFile(cand.file, cand.toolHint, title))
|
|
245
|
+
}
|
|
246
|
+
let info
|
|
247
|
+
try {
|
|
248
|
+
info = await summaries.get(cand.file)
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (error.code === 'ENOENT') continue
|
|
251
|
+
throw error
|
|
252
|
+
}
|
|
253
|
+
if (!info.preview || (term && ![info.title, info.firstPrompt].some(s => s.toLowerCase().includes(term)))) continue
|
|
254
|
+
yield {
|
|
255
|
+
tool: info.tool, toolLabel: tools[info.tool] || info.tool, file: cand.file,
|
|
256
|
+
mtimeMs: cand.mtimeMs, timeLabel: formatLocalTime(cand.mtimeMs),
|
|
257
|
+
sizeKB: Math.max(1, Math.round(cand.size / 1024)), preview: info.preview,
|
|
258
|
+
...(cand.archived && { archived: true }),
|
|
259
|
+
}
|
|
216
260
|
}
|
|
217
261
|
}
|
|
218
262
|
}
|
|
219
263
|
|
|
220
264
|
export async function scanRecentSessions({ limit = 12, ...directories } = {}) {
|
|
221
265
|
const results = []
|
|
222
|
-
|
|
266
|
+
if (limit <= 0) return results
|
|
267
|
+
for await (const session of createSessionCatalog(directories)()) {
|
|
223
268
|
results.push(session)
|
|
224
269
|
if (results.length >= limit) break
|
|
225
270
|
}
|
package/src/external-files.mjs
CHANGED
|
@@ -3,10 +3,12 @@ import { createReadStream, createWriteStream } from 'node:fs'
|
|
|
3
3
|
import { lstat, mkdir, mkdtemp, open, realpath, rename, rm, stat } from 'node:fs/promises'
|
|
4
4
|
import { homedir } from 'node:os'
|
|
5
5
|
import { basename, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
6
|
-
import { Transform } from 'node:stream'
|
|
6
|
+
import { Readable, Transform } from 'node:stream'
|
|
7
7
|
import { pipeline } from 'node:stream/promises'
|
|
8
8
|
import { fileURLToPath } from 'node:url'
|
|
9
9
|
|
|
10
|
+
export const recordedText = Symbol('recordedText')
|
|
11
|
+
|
|
10
12
|
function isLocal(path) {
|
|
11
13
|
return typeof path === 'string' && path && !path.startsWith('#') && !path.startsWith('//')
|
|
12
14
|
&& (!/^[a-z][\w+.-]*:/i.test(path) || isAbsolute(path) || path.startsWith('file:'))
|
|
@@ -50,7 +52,7 @@ export function messageReferences(text) {
|
|
|
50
52
|
|
|
51
53
|
const supportedInline = new Set(['.pdf', '.xlsx', '.png', '.jpg', '.jpeg', '.webp', '.gif', '.mp4', '.mov', '.webm', '.mp3', '.wav', '.ogg'])
|
|
52
54
|
const notFound = err => ['ENOENT', 'ENOTDIR'].includes(err.code)
|
|
53
|
-
const within = (path, root) => {
|
|
55
|
+
export const within = (path, root) => {
|
|
54
56
|
const rel = relative(root, path)
|
|
55
57
|
return rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel)
|
|
56
58
|
}
|
|
@@ -80,6 +82,14 @@ async function snapshot(path, target, roots, userSelected) {
|
|
|
80
82
|
if (['EPERM', 'EACCES', 'ELOOP'].includes(err.code)) return { availability: 'missing', unavailableReason: 'unreadable' }
|
|
81
83
|
throw err
|
|
82
84
|
}
|
|
85
|
+
try {
|
|
86
|
+
return await writeAttachment(handle.createReadStream(), path, target)
|
|
87
|
+
} finally {
|
|
88
|
+
await handle.close()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function writeAttachment(stream, path, target) {
|
|
83
93
|
let stage
|
|
84
94
|
try {
|
|
85
95
|
const dir = join(target, 'attachments')
|
|
@@ -89,20 +99,19 @@ async function snapshot(path, target, roots, userSelected) {
|
|
|
89
99
|
const temp = join(stage, 'file')
|
|
90
100
|
const hash = createHash('sha256')
|
|
91
101
|
const meter = new Transform({ transform(chunk, encoding, callback) { hash.update(chunk); callback(null, chunk) } })
|
|
92
|
-
await pipeline(
|
|
102
|
+
await pipeline(stream, meter, createWriteStream(temp, { flags: 'wx' }))
|
|
93
103
|
const digest = hash.digest('hex')
|
|
94
104
|
const ext = extname(path).toLowerCase()
|
|
95
105
|
const name = digest + (supportedInline.has(ext) ? ext : '.bin')
|
|
96
106
|
await rename(temp, join(dir, name))
|
|
97
107
|
return { href: 'attachments/' + name, digest }
|
|
98
108
|
} finally {
|
|
99
|
-
await handle.close()
|
|
100
109
|
if (stage) await rm(stage, { recursive: true, force: true })
|
|
101
110
|
}
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
// Consume explicit external sources once. Reopening a replay uses its own packaged files.
|
|
105
|
-
export async function collectExternalFiles(session, directory, assetRoots, nativeRoot) {
|
|
114
|
+
export async function collectExternalFiles(session, directory, assetRoots, nativeRoot, sessionRoots = []) {
|
|
106
115
|
const userFiles = new Set((session.items || []).filter(item => item.type === 'user').flatMap(item => item.deliverables || []))
|
|
107
116
|
const files = [...(session.deliverables || session.files || []), ...(session.items || []).flatMap(item => item.deliverables || [])]
|
|
108
117
|
if (!files.length) return false
|
|
@@ -112,9 +121,17 @@ export async function collectExternalFiles(session, directory, assetRoots, nativ
|
|
|
112
121
|
if (originalWorkspace) {
|
|
113
122
|
try { roots.push(await realpath(nativeRoot)) } catch (err) { if (!notFound(err)) throw err }
|
|
114
123
|
}
|
|
124
|
+
for (const root of sessionRoots) roots.push(await realpath(root))
|
|
115
125
|
const copies = new Map()
|
|
116
126
|
let changed = false
|
|
117
127
|
for (const file of files) {
|
|
128
|
+
if (file[recordedText] !== undefined) {
|
|
129
|
+
const copy = await writeAttachment(Readable.from([Buffer.from(file[recordedText])]), file.title, directory)
|
|
130
|
+
Object.assign(file, { href: copy.href, availability: 'export-copy' })
|
|
131
|
+
delete file[recordedText]
|
|
132
|
+
changed = true
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
118
135
|
if (!file.source && file.href && isLocal(file.href)) {
|
|
119
136
|
// Root-relative web URLs belong to the host site. Explicit file: URLs are local.
|
|
120
137
|
if (isAbsolute(file.href) && !within(file.href, homedir()) && !roots.some(root => within(file.href, root))) continue
|
package/src/i18n.mjs
CHANGED
|
@@ -49,7 +49,6 @@ export const DICTS = {
|
|
|
49
49
|
emptyHintEnd: ',体验完整对话与上下文生长',
|
|
50
50
|
activeContext: '上下文快照',
|
|
51
51
|
snapInitial: '初始上下文',
|
|
52
|
-
snapInspect: '回看:第 {step} / {total} 步',
|
|
53
52
|
snapCurrent: '第 {step} / {total} 步',
|
|
54
53
|
usedSuffix: '已用',
|
|
55
54
|
freeSpaceTitle: '剩余窗口 (Free Space)',
|
|
@@ -187,7 +186,6 @@ export const DICTS = {
|
|
|
187
186
|
emptyHintEnd: ' to replay the conversation and live context growth',
|
|
188
187
|
activeContext: 'Context Snapshot',
|
|
189
188
|
snapInitial: 'Initial Context',
|
|
190
|
-
snapInspect: 'Inspecting: Step {step} / {total}',
|
|
191
189
|
snapCurrent: 'Step {step} / {total}',
|
|
192
190
|
usedSuffix: 'used',
|
|
193
191
|
freeSpaceTitle: 'Free Context Space',
|
|
@@ -253,7 +251,7 @@ export const DICTS = {
|
|
|
253
251
|
tlControlsAria: 'Playback controls',
|
|
254
252
|
tlJumpAria: 'Jump to step {step}: {label}',
|
|
255
253
|
tlStepMeta: 'Step {step} · {time}',
|
|
256
|
-
tlCompressPin: '
|
|
254
|
+
tlCompressPin: 'Compaction #{seq}',
|
|
257
255
|
tlCompressTitle: '🗜 Compaction #{seq} (-{dropped}k)',
|
|
258
256
|
tlPromptTitle: '💬 Turn #{turn}: {summary}',
|
|
259
257
|
tlStepFallback: 'Step details',
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type AgentToolId = 'codex' | 'claude-code' | 'claude-ai' | 'workbuddy' | (string & {})
|
|
1
|
+
export type AgentToolId = 'codex' | 'claude-code' | 'claude-ai' | 'workbuddy' | 'antigravity' | 'antigravity-app' | 'antigravity-cli' | (string & {})
|
|
2
2
|
export type PlayerLang = 'zh' | 'en'
|
|
3
3
|
|
|
4
4
|
export interface ContextRecord {
|
|
@@ -142,6 +142,7 @@ export interface RecentSessionSummary {
|
|
|
142
142
|
tool: AgentToolId
|
|
143
143
|
toolLabel: string
|
|
144
144
|
file: string
|
|
145
|
+
archived?: boolean
|
|
145
146
|
mtimeMs: number
|
|
146
147
|
timeLabel: string
|
|
147
148
|
sizeKB: number
|
|
@@ -159,6 +160,8 @@ export function scanRecentSessions(options?: {
|
|
|
159
160
|
limit?: number
|
|
160
161
|
codexDir?: string
|
|
161
162
|
claudeDir?: string
|
|
163
|
+
antigravityAppDir?: string
|
|
164
|
+
antigravityCliDir?: string
|
|
162
165
|
workbuddyDir?: string
|
|
163
166
|
}): Promise<RecentSessionSummary[]>
|
|
164
167
|
|
|
@@ -222,7 +225,7 @@ export function attachPlayerController(
|
|
|
222
225
|
export function createEncorePlayer(
|
|
223
226
|
target: string | HTMLElement,
|
|
224
227
|
sourceOrSession?: string | EncoreSession,
|
|
225
|
-
options?: { baseUrl?: string; lang?: PlayerLang | 'auto'; initialStep?: number; showLangToggle?: boolean }
|
|
228
|
+
options?: { baseUrl?: string; lang?: PlayerLang | 'auto'; initialStep?: number; backHref?: string; backLabel?: string; showLangToggle?: boolean }
|
|
226
229
|
): Promise<{ setLang: (nextLang: PlayerLang) => void; getController: () => Record<string, any> | null }>
|
|
227
230
|
|
|
228
231
|
export function buildStandalonePlayerJs(options?: { write?: boolean }): string
|
package/src/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { tmpdir } from 'node:os'
|
|
3
|
-
import { basename, join, resolve } from 'node:path'
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { antigravitySummaries, nativeAntigravityLog, readAntigravity } from './antigravity.mjs'
|
|
4
5
|
import { readClaudeAi } from './claude-ai.mjs'
|
|
5
6
|
import { prepareAttachmentPreviews } from './attachment-previews.mjs'
|
|
6
7
|
import { collectExternalFiles, nativeSessionRoot } from './external-files.mjs'
|
|
@@ -54,14 +55,21 @@ export async function importRawSession(files, {
|
|
|
54
55
|
assetRoots,
|
|
55
56
|
} = {}) {
|
|
56
57
|
const fileList = [].concat(files).map(f => resolve(f))
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
let detectedTool = tool || (await detectInput(fileList[0])).tool || 'codex'
|
|
59
|
+
const isAntigravity = ['antigravity', 'antigravity-app', 'antigravity-cli'].includes(detectedTool)
|
|
60
|
+
const native = isAntigravity && nativeAntigravityLog(fileList[0])
|
|
61
|
+
if (native) Object.assign(native, antigravitySummaries(dirname(native.root)).get(native.id))
|
|
62
|
+
if (isAntigravity) detectedTool = native?.tool || 'antigravity'
|
|
63
|
+
if (!isAntigravity && !readers[detectedTool]) {
|
|
59
64
|
throw new Error(`Unsupported session format: ${detectedTool}`)
|
|
60
65
|
}
|
|
61
66
|
const window = { from, to }
|
|
62
67
|
const records = detectedTool === 'claude-ai' ? JSON.parse(readFileSync(fileList[0], 'utf8')) : await readJsonl(fileList, window)
|
|
63
|
-
const nativeRoot = await nativeSessionRoot(fileList[0], detectedTool, records)
|
|
64
|
-
const
|
|
68
|
+
const nativeRoot = isAntigravity ? native?.workspaces?.[0] : await nativeSessionRoot(fileList[0], detectedTool, records)
|
|
69
|
+
const sessionData = isAntigravity
|
|
70
|
+
? await readAntigravity(records, { file: fileList[0], tool: detectedTool, native, images, assetRoots })
|
|
71
|
+
: readers[detectedTool](records, { ...window, conversation, includeMemory })
|
|
72
|
+
const raw = cutSession(sessionData, window)
|
|
65
73
|
|
|
66
74
|
if (title) raw.title = title
|
|
67
75
|
if (description !== undefined) raw.description = description
|
|
@@ -86,7 +94,10 @@ export async function importRawSession(files, {
|
|
|
86
94
|
width: imageWidth,
|
|
87
95
|
lang: resolvedLang,
|
|
88
96
|
})
|
|
89
|
-
|
|
97
|
+
const sessionRoots = native && !assetRoots
|
|
98
|
+
? [native.root, ...(native.workspaces || []).slice(1).filter(dir => existsSync(dir))]
|
|
99
|
+
: []
|
|
100
|
+
await collectExternalFiles(withImages, targetDir, assetRoots, nativeRoot, sessionRoots)
|
|
90
101
|
const redacted = redactSession(withImages)
|
|
91
102
|
const limit = clip ? Number(clip) : undefined
|
|
92
103
|
const session = clipSession(redacted, limit ? { input: limit, output: limit } : undefined)
|