@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
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,13 +49,13 @@ export const DICTS = {
|
|
|
49
49
|
emptyHintEnd: ',体验完整对话与上下文生长',
|
|
50
50
|
activeContext: '上下文快照',
|
|
51
51
|
snapInitial: '初始上下文',
|
|
52
|
-
|
|
52
|
+
initialUsageMissing: '初始用量未记录',
|
|
53
|
+
usageMissing: '用量未记录',
|
|
54
|
+
notRecorded: '未记录',
|
|
55
|
+
unknownCapacity: '上限未知',
|
|
53
56
|
snapCurrent: '第 {step} / {total} 步',
|
|
54
57
|
usedSuffix: '已用',
|
|
55
58
|
freeSpaceTitle: '剩余窗口 (Free Space)',
|
|
56
|
-
autoCompactTriggerTitle: '自动压缩触发线 (80%)',
|
|
57
|
-
headroomTitle: '压缩预留空间 (Autocompact Headroom)',
|
|
58
|
-
outputReserveTitle: '模型最大输出预留 (Max Output Reserve)',
|
|
59
59
|
legendSys: '系统提示词',
|
|
60
60
|
legendSchema: '工具定义',
|
|
61
61
|
legendUser: '用户消息',
|
|
@@ -187,13 +187,13 @@ export const DICTS = {
|
|
|
187
187
|
emptyHintEnd: ' to replay the conversation and live context growth',
|
|
188
188
|
activeContext: 'Context Snapshot',
|
|
189
189
|
snapInitial: 'Initial Context',
|
|
190
|
-
|
|
190
|
+
initialUsageMissing: 'Initial usage not recorded',
|
|
191
|
+
usageMissing: 'Usage not recorded',
|
|
192
|
+
notRecorded: 'Not recorded',
|
|
193
|
+
unknownCapacity: 'Unknown limit',
|
|
191
194
|
snapCurrent: 'Step {step} / {total}',
|
|
192
195
|
usedSuffix: 'used',
|
|
193
196
|
freeSpaceTitle: 'Free Context Space',
|
|
194
|
-
autoCompactTriggerTitle: 'Auto-compaction Trigger (80%)',
|
|
195
|
-
headroomTitle: 'Autocompact Headroom (12%)',
|
|
196
|
-
outputReserveTitle: 'Max Output Reserve (8%)',
|
|
197
197
|
legendSys: 'System Prompt',
|
|
198
198
|
legendSchema: 'Tool Schemas',
|
|
199
199
|
legendUser: 'User Messages',
|
|
@@ -253,7 +253,7 @@ export const DICTS = {
|
|
|
253
253
|
tlControlsAria: 'Playback controls',
|
|
254
254
|
tlJumpAria: 'Jump to step {step}: {label}',
|
|
255
255
|
tlStepMeta: 'Step {step} · {time}',
|
|
256
|
-
tlCompressPin: '
|
|
256
|
+
tlCompressPin: 'Compaction #{seq}',
|
|
257
257
|
tlCompressTitle: '🗜 Compaction #{seq} (-{dropped}k)',
|
|
258
258
|
tlPromptTitle: '💬 Turn #{turn}: {summary}',
|
|
259
259
|
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 {
|
|
@@ -13,6 +13,7 @@ export interface ContextRecord {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface InitialContext {
|
|
16
|
+
estimatedTokens?: number
|
|
16
17
|
sys?: ContextRecord[]
|
|
17
18
|
schema?: ContextRecord[]
|
|
18
19
|
mem?: ContextRecord[]
|
|
@@ -66,6 +67,8 @@ export interface SessionItem {
|
|
|
66
67
|
agent?: string
|
|
67
68
|
question?: boolean
|
|
68
69
|
answer?: boolean
|
|
70
|
+
contextWindow?: number
|
|
71
|
+
contextTokenEstimates?: Partial<Record<'sys' | 'schema' | 'mem' | 'skill', number>>
|
|
69
72
|
contextTokens?: number
|
|
70
73
|
images?: string[]
|
|
71
74
|
omittedImages?: number
|
|
@@ -142,6 +145,7 @@ export interface RecentSessionSummary {
|
|
|
142
145
|
tool: AgentToolId
|
|
143
146
|
toolLabel: string
|
|
144
147
|
file: string
|
|
148
|
+
archived?: boolean
|
|
145
149
|
mtimeMs: number
|
|
146
150
|
timeLabel: string
|
|
147
151
|
sizeKB: number
|
|
@@ -159,6 +163,8 @@ export function scanRecentSessions(options?: {
|
|
|
159
163
|
limit?: number
|
|
160
164
|
codexDir?: string
|
|
161
165
|
claudeDir?: string
|
|
166
|
+
antigravityAppDir?: string
|
|
167
|
+
antigravityCliDir?: string
|
|
162
168
|
workbuddyDir?: string
|
|
163
169
|
}): Promise<RecentSessionSummary[]>
|
|
164
170
|
|
|
@@ -222,7 +228,7 @@ export function attachPlayerController(
|
|
|
222
228
|
export function createEncorePlayer(
|
|
223
229
|
target: string | HTMLElement,
|
|
224
230
|
sourceOrSession?: string | EncoreSession,
|
|
225
|
-
options?: { baseUrl?: string; lang?: PlayerLang | 'auto'; initialStep?: number; showLangToggle?: boolean }
|
|
231
|
+
options?: { baseUrl?: string; lang?: PlayerLang | 'auto'; initialStep?: number; backHref?: string; backLabel?: string; showLangToggle?: boolean }
|
|
226
232
|
): Promise<{ setLang: (nextLang: PlayerLang) => void; getController: () => Record<string, any> | null }>
|
|
227
233
|
|
|
228
234
|
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, includeMemory })
|
|
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)
|