@niracler/encore 0.3.0 → 0.4.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/README.md +42 -108
- package/README.zh-CN.md +42 -108
- package/bin/encore.mjs +9 -100
- package/package.json +3 -2
- package/player/encore-player.css +44 -48
- package/player/encore-player.js +293 -313
- package/schema/session.schema.json +10 -2
- package/skills/encore/SKILL.md +2 -2
- package/src/antigravity-context.mjs +122 -0
- package/src/antigravity-context.proto +43 -0
- package/src/antigravity.mjs +160 -0
- package/src/common.mjs +7 -4
- package/src/detect.mjs +96 -51
- package/src/external-files.mjs +22 -5
- package/src/i18n.mjs +9 -9
- package/src/index.d.ts +8 -2
- package/src/index.mjs +17 -6
- package/src/player-runtime.mjs +109 -128
- package/src/render.mjs +54 -87
- package/src/session-picker.mjs +163 -0
- package/src/timeline.mjs +117 -85
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"tool": {
|
|
14
14
|
"type": "string",
|
|
15
|
-
"enum": ["codex", "claude-code", "claude-ai", "workbuddy"],
|
|
15
|
+
"enum": ["codex", "claude-code", "claude-ai", "workbuddy", "antigravity", "antigravity-app", "antigravity-cli"],
|
|
16
16
|
"description": "Source AI agent environment identifier."
|
|
17
17
|
},
|
|
18
18
|
"model": {
|
|
@@ -51,12 +51,13 @@
|
|
|
51
51
|
"contextWindow": {
|
|
52
52
|
"type": "integer",
|
|
53
53
|
"minimum": 1,
|
|
54
|
-
"description": "
|
|
54
|
+
"description": "Initial context window capacity in tokens. A request can override it when the limit changes."
|
|
55
55
|
},
|
|
56
56
|
"initialContext": {
|
|
57
57
|
"type": "object",
|
|
58
58
|
"description": "Initial mounted context records captured from the session preamble.",
|
|
59
59
|
"properties": {
|
|
60
|
+
"estimatedTokens": { "type": "integer", "minimum": 0, "description": "Estimated tokens loaded before user input, from a recorded baseline breakdown." },
|
|
60
61
|
"sys": {
|
|
61
62
|
"type": "array",
|
|
62
63
|
"items": { "$ref": "#/$defs/contextRecord" }
|
|
@@ -234,6 +235,13 @@
|
|
|
234
235
|
"agent": { "type": "string" },
|
|
235
236
|
"question": { "type": "boolean" },
|
|
236
237
|
"answer": { "type": "boolean" },
|
|
238
|
+
"contextWindow": { "type": "integer", "minimum": 0, "description": "Window capacity for this request if it varies within the session. Zero marks an unknown capacity." },
|
|
239
|
+
"contextTokenEstimates": {
|
|
240
|
+
"type": "object",
|
|
241
|
+
"description": "Category estimates recorded for this model request.",
|
|
242
|
+
"propertyNames": { "enum": ["sys", "schema", "mem", "skill"] },
|
|
243
|
+
"additionalProperties": { "type": "integer", "minimum": 0 }
|
|
244
|
+
},
|
|
237
245
|
"contextTokens": { "type": "integer", "minimum": 0 },
|
|
238
246
|
"images": {
|
|
239
247
|
"type": "array",
|
package/skills/encore/SKILL.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: encore
|
|
3
3
|
description: >
|
|
4
|
-
Export, curate, and rebuild portable AI Agent replays (Codex, Claude Code, Claude.ai, WorkBuddy) with Encore.
|
|
4
|
+
Export, curate, and rebuild portable AI Agent replays (Codex, Claude Code, Claude.ai, WorkBuddy, Antigravity App and CLI) with Encore.
|
|
5
5
|
Use when the user asks to export a Raw Log into a Replay, curate `session.json`, select and label `.webp` Frames, review packaged Attachments or Deliverables, write a title and opening description, or redact residual sensitive details before publishing.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Encore — Session Replay & Curation Skill
|
|
9
9
|
|
|
10
|
-
Encore turns a Raw Log from **Codex**, **Claude Code**, **Claude.ai**, or **
|
|
10
|
+
Encore turns a Raw Log from **Codex**, **Claude Code**, **Claude.ai**, **WorkBuddy**, or **Antigravity** into a portable **Replay** rendered by the standalone **Player** (**Left**: Turns, Tool calls, Sub-agents, Attachments, Deliverables, and Frames; **Right**: live Context Snapshot inspector and Compaction boundaries; **Bottom**: Step timeline).
|
|
11
11
|
|
|
12
12
|
While `npx @niracler/encore@latest` builds an immediately playable Replay, this skill guides **Curation** before publishing.
|
|
13
13
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { createRequire } from 'node:module'
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
|
|
9
|
+
export function readAntigravityDatabase(path, read) {
|
|
10
|
+
if (!existsSync(path)) return
|
|
11
|
+
let db
|
|
12
|
+
try {
|
|
13
|
+
const Database = process.getBuiltinModule?.('node:sqlite')?.DatabaseSync
|
|
14
|
+
db = Database && new Database(path, { readOnly: true })
|
|
15
|
+
const query = sql => {
|
|
16
|
+
if (db) return db.prepare(sql).all()
|
|
17
|
+
const result = spawnSync('sqlite3', ['-readonly', '-json', path, sql], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 })
|
|
18
|
+
if (result.error || result.status !== 0) throw result.error || new Error(result.stderr)
|
|
19
|
+
return JSON.parse(result.stdout || '[]')
|
|
20
|
+
}
|
|
21
|
+
return read(query, !!db)
|
|
22
|
+
} catch {
|
|
23
|
+
// Older versions, unavailable SQLite readers and incomplete native metadata
|
|
24
|
+
// can still export a Replay directly from the transcript.
|
|
25
|
+
return undefined
|
|
26
|
+
} finally {
|
|
27
|
+
db?.close()
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let generationType
|
|
32
|
+
const categoryFor = type => ({ 2: 'schema', 3: 'mem', 4: 'schema', 5: 'skill' })[type] || 'sys'
|
|
33
|
+
|
|
34
|
+
function openingContext(chat, breakdown, includeMemory) {
|
|
35
|
+
const context = {}
|
|
36
|
+
const sections = new Map(chat.promptSections.map(section => [section.title, section]))
|
|
37
|
+
const tools = new Map(chat.tools.map(tool => [tool.name, tool]))
|
|
38
|
+
let nextId = 0
|
|
39
|
+
function add(category, title, payload, tokEst) {
|
|
40
|
+
// A monolithic prompt can inline cross-session memory alongside system rules.
|
|
41
|
+
const sensitive = category === 'mem' || /user_information|user_rules|MEMORY_SUMMARY|<conversation_history>/i.test(title + '\n' + payload)
|
|
42
|
+
const record = { id: 'agy-init-' + nextId++, title,
|
|
43
|
+
payload: sensitive && !includeMemory ? '[Private context omitted · --include-memory]' : payload }
|
|
44
|
+
if (tokEst !== undefined) record.tokEst = tokEst
|
|
45
|
+
context[category] ||= []
|
|
46
|
+
context[category].push(record)
|
|
47
|
+
}
|
|
48
|
+
function addNamed(category, name, count) {
|
|
49
|
+
const tool = category === 'schema' && tools.get(name)
|
|
50
|
+
const section = sections.get(name)
|
|
51
|
+
if (tool) {
|
|
52
|
+
add(category, name, [tool.description, tool.jsonSchemaString].filter(Boolean).join('\n\n'), count)
|
|
53
|
+
tools.delete(name)
|
|
54
|
+
} else {
|
|
55
|
+
add(category, name, section?.content || '', count)
|
|
56
|
+
sections.delete(name)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (breakdown?.groups.length) {
|
|
60
|
+
// TOKEN_SOURCE_SYSTEM (1) identifies mounted input. Chat Messages (7)
|
|
61
|
+
// include the first user turn and never belong to the opening baseline.
|
|
62
|
+
const mounted = breakdown.groups.filter(group => group.source === 1 && group.type !== 7)
|
|
63
|
+
if (mounted.length && breakdown.groups.reduce((n, group) => n + group.numTokens, 0) === breakdown.totalTokens) {
|
|
64
|
+
context.estimatedTokens = mounted.reduce((n, group) => n + group.numTokens, 0)
|
|
65
|
+
}
|
|
66
|
+
for (const group of mounted) {
|
|
67
|
+
const category = categoryFor(group.type)
|
|
68
|
+
if (group.children.length) {
|
|
69
|
+
for (const child of group.children) addNamed(category, child.name, child.numTokens)
|
|
70
|
+
} else addNamed(category, group.name, group.numTokens)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const section of sections.values()) add(categoryFor(section.tokenType), section.title, section.content)
|
|
74
|
+
for (const tool of tools.values()) addNamed('schema', tool.name)
|
|
75
|
+
if (!chat.promptSections.length && chat.systemPrompt) add('sys', 'System Prompt', chat.systemPrompt)
|
|
76
|
+
return Object.keys(context).length ? context : undefined
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function readAntigravityContext(native, records, includeMemory) {
|
|
80
|
+
const requests = records.filter(row => row.type === 'PLANNER_RESPONSE').map(row => row.step_index)
|
|
81
|
+
if (!native || !requests.length) return
|
|
82
|
+
const dbPath = join(native.root, '..', '..', 'conversations', native.id + '.db')
|
|
83
|
+
return readAntigravityDatabase(dbPath, (query, binary) => {
|
|
84
|
+
generationType ||= require('protobufjs').loadSync(fileURLToPath(new URL('./antigravity-context.proto', import.meta.url))).lookupType('CortexStepGeneratorMetadata')
|
|
85
|
+
const windows = new Map()
|
|
86
|
+
const breakdowns = new Map()
|
|
87
|
+
let initialContext
|
|
88
|
+
let cursor = -1
|
|
89
|
+
for (;;) {
|
|
90
|
+
const rows = query('SELECT idx, ' + (binary ? 'data' : 'hex(data)') + ' AS payload FROM gen_metadata WHERE idx > ' + cursor + ' ORDER BY idx LIMIT 16')
|
|
91
|
+
if (!rows.length) break
|
|
92
|
+
for (const row of rows) {
|
|
93
|
+
cursor = row.idx
|
|
94
|
+
const bytes = binary ? row.payload : Buffer.from(row.payload, 'hex')
|
|
95
|
+
let generation
|
|
96
|
+
try {
|
|
97
|
+
generation = generationType.decode(bytes)
|
|
98
|
+
} catch {
|
|
99
|
+
// A damaged generation must not discard valid measurements from its neighbours.
|
|
100
|
+
continue
|
|
101
|
+
}
|
|
102
|
+
const { chatModel: chat, stepIndices } = generation
|
|
103
|
+
const window = chat?.chatStartMetadata?.contextWindowMetadata
|
|
104
|
+
if (window?.tokenBreakdown?.groups.length) {
|
|
105
|
+
const estimates = {}
|
|
106
|
+
for (const group of window.tokenBreakdown.groups) {
|
|
107
|
+
if (group.source !== 1 || group.type === 7) continue
|
|
108
|
+
const category = categoryFor(group.type)
|
|
109
|
+
estimates[category] = (estimates[category] || 0) + group.numTokens
|
|
110
|
+
}
|
|
111
|
+
for (const step of stepIndices) breakdowns.set(step, estimates)
|
|
112
|
+
}
|
|
113
|
+
if (window?.maxContextTokens > 0) for (const step of stepIndices) windows.set(step, window.maxContextTokens)
|
|
114
|
+
if (row.idx === 0 && chat && stepIndices.includes(requests[0]) && records[0]?.step_index === 0) {
|
|
115
|
+
initialContext = openingContext(chat, window?.tokenBreakdown, includeMemory)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const limits = new Set(requests.map(step => windows.get(step)))
|
|
120
|
+
return { initialContext, contextWindow: windows.get(requests[0]), variableWindows: limits.size > 1, windows, breakdowns }
|
|
121
|
+
})
|
|
122
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Read-only projection of Antigravity's gen_metadata.data. Keep native field
|
|
2
|
+
// numbers; message history and tool results are intentionally outside this view.
|
|
3
|
+
syntax = "proto3";
|
|
4
|
+
message CortexStepGeneratorMetadata {
|
|
5
|
+
ChatModelMetadata chat_model = 1;
|
|
6
|
+
repeated int32 step_indices = 2;
|
|
7
|
+
}
|
|
8
|
+
message ChatModelMetadata {
|
|
9
|
+
string system_prompt = 1;
|
|
10
|
+
repeated ChatToolDefinition tools = 8;
|
|
11
|
+
ChatStartMetadata chat_start_metadata = 9;
|
|
12
|
+
repeated PromptSection prompt_sections = 16;
|
|
13
|
+
}
|
|
14
|
+
message ChatToolDefinition {
|
|
15
|
+
string name = 1;
|
|
16
|
+
string description = 2;
|
|
17
|
+
string json_schema_string = 3;
|
|
18
|
+
}
|
|
19
|
+
message PromptSection {
|
|
20
|
+
string title = 1;
|
|
21
|
+
string content = 2;
|
|
22
|
+
int32 token_type = 6;
|
|
23
|
+
}
|
|
24
|
+
message ChatStartMetadata { ContextWindowMetadata context_window_metadata = 10; }
|
|
25
|
+
message ContextWindowMetadata {
|
|
26
|
+
TokenBreakdown token_breakdown = 3;
|
|
27
|
+
int32 max_context_tokens = 4;
|
|
28
|
+
}
|
|
29
|
+
message TokenBreakdown {
|
|
30
|
+
repeated TopLevelTokenGroup groups = 1;
|
|
31
|
+
int32 total_tokens = 2;
|
|
32
|
+
}
|
|
33
|
+
message TopLevelTokenGroup {
|
|
34
|
+
string name = 1;
|
|
35
|
+
int32 type = 2;
|
|
36
|
+
int32 source = 3;
|
|
37
|
+
int32 num_tokens = 4;
|
|
38
|
+
repeated TokenGroup children = 5;
|
|
39
|
+
}
|
|
40
|
+
message TokenGroup {
|
|
41
|
+
string name = 1;
|
|
42
|
+
int32 num_tokens = 3;
|
|
43
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { readAntigravityDatabase, readAntigravityContext } from './antigravity-context.mjs'
|
|
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
|
+
return readAntigravityDatabase(path, query => {
|
|
33
|
+
const summaries = query('SELECT conversation_id, title, last_modified_time, workspace_uris FROM conversation_summaries')
|
|
34
|
+
const hasSearch = query("SELECT 1 FROM sqlite_master WHERE name = 'conversations_fts'").length
|
|
35
|
+
const archived = new Set(hasSearch ? query("SELECT DISTINCT conversation_id FROM conversations_fts WHERE archived IN (1, '1')").map(r => r.conversation_id) : [])
|
|
36
|
+
return new Map(summaries.map(row => {
|
|
37
|
+
const uris = JSON.parse(row.workspace_uris || '[]') || []
|
|
38
|
+
const workspaces = uris.filter(uri => typeof uri === 'string' && uri.startsWith('file:///')).map(uri => fileURLToPath(uri))
|
|
39
|
+
return [row.conversation_id, { title: row.title, workspaces, archived: archived.has(row.conversation_id),
|
|
40
|
+
updated: Date.parse(row.last_modified_time.replace(' ', 'T')) }]
|
|
41
|
+
}))
|
|
42
|
+
}) || new Map()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function antigravityTitle(root, id) {
|
|
46
|
+
const path = join(dirname(root), 'annotations', id + '.pbtxt')
|
|
47
|
+
if (!existsSync(path)) return ''
|
|
48
|
+
const literal = readFileSync(path, 'utf8').match(/^title:\s*("(?:[^"\\]|\\.)*")/m)?.[1]
|
|
49
|
+
if (!literal) return ''
|
|
50
|
+
try { return JSON.parse(literal) } catch { return '' } // Unrecognized protobuf escape: use the first prompt.
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function antigravityPrompt(content = '') {
|
|
54
|
+
const request = content.match(/<USER_REQUEST>([\s\S]*?)(?:<\/USER_REQUEST>|$)/)?.[1] ?? content
|
|
55
|
+
return request.replace(/<external_system_instructions>[\s\S]*?(?:<\/external_system_instructions>|$)/g, '').trim()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isAntigravityRecord(rec) {
|
|
59
|
+
return Number.isInteger(rec?.step_index) && typeof rec.created_at === 'string' &&
|
|
60
|
+
typeof rec.source === 'string' && typeof rec.type === 'string'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function loadMedia(media, logDir, roots, userSelected = false) {
|
|
64
|
+
const images = []
|
|
65
|
+
for (const { uri, mime_type: mime } of media || []) {
|
|
66
|
+
if (!mime?.startsWith('image/')) continue
|
|
67
|
+
const path = fileReferences([uri], logDir)[0]?.source?.path
|
|
68
|
+
if (!path) continue
|
|
69
|
+
try {
|
|
70
|
+
const actual = await realpath(path)
|
|
71
|
+
if ((userSelected || roots.some(root => within(actual, root))) && (await stat(actual)).isFile()) {
|
|
72
|
+
images.push({ mime, base64: (await readFile(actual)).toString('base64') })
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (!['ENOENT', 'ENOTDIR', 'EACCES', 'EPERM', 'ELOOP'].includes(error.code)) throw error
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return images
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function reviewedFiles(name, args, cwd) {
|
|
82
|
+
if (name === 'notify_user' && Array.isArray(args.PathsToReview)) return fileReferences(args.PathsToReview, cwd)
|
|
83
|
+
if (name === 'exit_plan_mode' && typeof args.plan === 'string' && args.plan.trim()) {
|
|
84
|
+
const plan = args.plan.trim()
|
|
85
|
+
if (/^(?:file:\/\/|\/|[A-Z]:[\\/])[^\n]*\.md$/i.test(plan)) return fileReferences([plan], cwd)
|
|
86
|
+
return [{ title: 'implementation_plan.md', [recordedText]: redactText(plan) }]
|
|
87
|
+
}
|
|
88
|
+
return []
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function readAntigravity(records, { file, tool, native, images, assetRoots, includeMemory }) {
|
|
92
|
+
const transcript = createTranscript()
|
|
93
|
+
const metadata = readAntigravityContext(native, records, includeMemory)
|
|
94
|
+
const logDir = dirname(file)
|
|
95
|
+
const defaults = [process.cwd(), ...(native?.workspaces || []).filter(dir => existsSync(dir))]
|
|
96
|
+
const roots = await Promise.all((assetRoots?.length ? assetRoots : defaults).map(dir => realpath(resolve(dir))))
|
|
97
|
+
const cwd = native?.workspaces?.[0] || native?.root
|
|
98
|
+
// Native recordings own their media directory. A detached log only gets the caller's asset roots.
|
|
99
|
+
if (native) roots.push(await realpath(native.root))
|
|
100
|
+
const userSelected = Boolean(native?.workspaces?.length && !assetRoots)
|
|
101
|
+
let pending = []
|
|
102
|
+
let model
|
|
103
|
+
let tokens = 0
|
|
104
|
+
for (const record of records) {
|
|
105
|
+
const { type, created_at: time, content = '', step_index: step } = record
|
|
106
|
+
if (type === 'USER_INPUT') {
|
|
107
|
+
pending = []
|
|
108
|
+
transcript.user(antigravityPrompt(content), time, {
|
|
109
|
+
images: images ? await loadMedia(record.media, logDir, roots, userSelected) : [],
|
|
110
|
+
cwd,
|
|
111
|
+
})
|
|
112
|
+
} else if (type === 'PLANNER_RESPONSE') {
|
|
113
|
+
pending = []
|
|
114
|
+
model = record.model || model
|
|
115
|
+
const usage = {}
|
|
116
|
+
if (Number.isInteger(record.input_tokens) || Number.isInteger(record.cache_read_tokens)) {
|
|
117
|
+
usage.contextTokens = (record.input_tokens || 0) + (record.cache_read_tokens || 0)
|
|
118
|
+
}
|
|
119
|
+
const estimates = metadata?.breakdowns.get(step)
|
|
120
|
+
if (estimates) usage.contextTokenEstimates = estimates
|
|
121
|
+
if (metadata?.variableWindows) usage.contextWindow = metadata.windows.get(step) || 0
|
|
122
|
+
tokens += (usage.contextTokens || 0) + (record.output_tokens || 0)
|
|
123
|
+
transcript.reasoning(record.thinking, time, usage)
|
|
124
|
+
transcript.assistant(content, time, { cwd, ...usage })
|
|
125
|
+
for (const [i, call] of (record.tool_calls || []).entries()) {
|
|
126
|
+
const id = step + '/' + i
|
|
127
|
+
const args = call.args || {}
|
|
128
|
+
const name = call.name || 'tool'
|
|
129
|
+
const base = name.replace(/^mcp_ide-tools_/, '')
|
|
130
|
+
const details = describeTool(base, {
|
|
131
|
+
...args,
|
|
132
|
+
...(args.CommandLine && { command: args.CommandLine }),
|
|
133
|
+
...(args.Path && { path: args.Path }),
|
|
134
|
+
})
|
|
135
|
+
const item = transcript.tool(id, { ...details, name, ...usage }, time)
|
|
136
|
+
const files = reviewedFiles(base, args, cwd)
|
|
137
|
+
if (files.length) item.deliverables = files
|
|
138
|
+
pending.push(id)
|
|
139
|
+
}
|
|
140
|
+
} else if (type === 'GENERIC') {
|
|
141
|
+
// Each batch's result steps follow its tool calls in trajectory order.
|
|
142
|
+
const id = pending.shift()
|
|
143
|
+
const output = content.replace(/^(?:(?:Created At|Completed At):[^\n]*(?:\n|$))+/u, '').trim()
|
|
144
|
+
const done = content.match(/^Completed At:\s*([^\r\n]+)/m)?.[1] || time
|
|
145
|
+
if (id !== undefined) transcript.result(id, [output, record.error].filter(Boolean).join('\n'), done,
|
|
146
|
+
images ? await loadMedia(record.media, logDir, roots) : [], cwd)
|
|
147
|
+
} else if (type === 'CHECKPOINT' && record.status === 'DONE' && !record.error) {
|
|
148
|
+
const summary = content.match(/<summary>([\s\S]*?)<\/summary>/i)?.[1]?.trim()
|
|
149
|
+
const text = summary && !includeMemory
|
|
150
|
+
? summary.replace(/<external_system_instructions>[\s\S]*?(?:<\/external_system_instructions>|$)|========= MEMORY_SUMMARY BEGINS =========[\s\S]*?(?:========= MEMORY_SUMMARY ENDS =========|$)/gi, '[Private context omitted]')
|
|
151
|
+
: summary
|
|
152
|
+
transcript.compact(text ? { text } : {}, time)
|
|
153
|
+
} else if (type === 'ERROR_MESSAGE') {
|
|
154
|
+
transcript.assistant(record.error || content, time)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return transcript.finish({ tool, model, tokens: tokens || undefined,
|
|
158
|
+
contextWindow: metadata?.contextWindow, initialContext: metadata?.initialContext,
|
|
159
|
+
title: native?.title || (native && antigravityTitle(dirname(native.root), native.id)) })
|
|
160
|
+
}
|
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 = {
|
|
@@ -308,9 +311,9 @@ export function createTranscript() {
|
|
|
308
311
|
}
|
|
309
312
|
else add({ type: 'assistant', text, time, key, ...extra })
|
|
310
313
|
},
|
|
311
|
-
reasoning(text, time) {
|
|
314
|
+
reasoning(text, time, extra) {
|
|
312
315
|
text = String(text ?? '').trim()
|
|
313
|
-
if (text) add({ type: 'reasoning', text, time })
|
|
316
|
+
if (text) add({ type: 'reasoning', text, time, ...extra })
|
|
314
317
|
},
|
|
315
318
|
tool(id, tool, time) {
|
|
316
319
|
const item = add({ type: 'tool', ...tool, time })
|
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
|
}
|