Repository navigation
feat(sessions): improve export, search, and UI clarity #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,9 @@ | |
| 1. 按[快速开始](/guide/quick-start)启动,进入 Web UI 会话视图。 | ||
| 2. 在「会话来源」选择已有记录的工具,再按项目路径或时间缩小范围。可输入关键词并按回车检索;界面有检索入口不代表所有来源的记录格式都已经验证。 | ||
| 3. 打开会话,核对项目、时间和讨论内容。 | ||
| 4. 点击「导出记录」,打开下载的 Markdown,检查需要的文字是否完整,并留意截断提示。 | ||
| 4. 在「导出范围」选择最近 1000 条或全部可提取消息,再点击「导出记录」。打开下载的 Markdown 核对内容;截断说明会保留在当前会话预览中,可选择全部后重新导出。 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not promise the latest 1,000 messages until export keeps the tail. For generic JSONL sources,
|
||
|
|
||
| 没有记录时先确认原工具在本机保存过会话,再清除筛选条件并刷新。配置 Provider 不会生成历史会话。 | ||
| 关键词查询会显示实际扫描数与本次候选数。未完成时请缩小来源或项目范围;候选范围不等于全部历史记录。筛选无结果时可直接点击「清除筛选」。没有记录时先确认原工具在本机保存过会话,再刷新。配置 Provider 不会生成历史会话。 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Report the actual search scope in the coverage message. The default query scope is
|
||
|
|
||
| ## 来源与存储位置 | ||
|
|
||
|
|
@@ -26,7 +26,7 @@ | |
| | `opencode` | OpenCode | 数据目录中的 `opencode.db`,默认 `~/.local/share/opencode` | | ||
| | `zed` | Zed | Zed 数据目录下的 `threads/threads.db` | | ||
|
|
||
| OpenCode 导出分支存在尚未完成运行验证的兼容性疑点,请先用一条样例确认导出结果,不把来源出现在列表中视为导出成功保证。首次体验可先使用已有的 Codex 或 Claude Code 记录。 | ||
| OpenCode 导出的来源分支现已互斥,避免数据库读取结果被通用文件读取覆盖。各工具版本的存储格式仍可能不同,先用一条记录核对结果;来源出现在列表中不代表所有版本均已验证。 | ||
|
|
||
| ## CLI 导出 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { createCodexConfigMethods } from '../../web-ui/modules/app.methods.codex-config.mjs'; | ||
| import { execFileSync } from 'node:child_process'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| test('session backend export and search contracts', () => { | ||
| execFileSync(process.execPath, [fileURLToPath(new URL('./session-search-export.test.cjs', import.meta.url))], { timeout: 10000 }); | ||
| }); | ||
| test('session export range preserves default and clears truncation after full export', async () => { | ||
| const requests = [], downloads = []; | ||
| const methods = createCodexConfigMethods({ api: async (_, params) => { | ||
| requests.push(params); | ||
| return { content: 'message', truncated: params.maxMessages !== 'all', maxMessages: 1000 }; | ||
| } }); | ||
| const context = { sessionExporting: {}, sessionExportRange: 'default', getSessionExportKey: () => 's', | ||
| downloadTextFile: (_, text) => downloads.push(text), showMessage() {}, t: key => key }; | ||
| const session = { source: 'codex', sessionId: 's', filePath: '/sample' }; | ||
| await methods.exportSession.call(context, session); | ||
| assert.equal(Object.hasOwn(requests[0], 'maxMessages'), false); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a Node 14-compatible property check.
|
||
| assert.deepEqual(context.sessionExportNotice, { key: 's' }); | ||
| context.sessionExportRange = 'all'; | ||
| await methods.exportSession.call(context, session); | ||
| assert.equal(requests[1].maxMessages, 'all'); | ||
| assert.equal(context.sessionExportNotice, null); | ||
| assert.equal(context.sessionExporting.s, false); | ||
| assert.deepEqual(downloads, ['message', 'message']); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| const assert = require('node:assert/strict'), vm = require('node:vm'), fs = require('node:fs'); | ||
| const source = fs.readFileSync(require('node:path').join(__dirname, '../../cli.js'), 'utf8'); | ||
| const names = ['normalizeQueryMode','normalizeQueryScope','normalizeRoleFilter','buildSessionSummaryText','createSessionQueryScanState','consumeSessionQueryMessage','buildSessionQueryScanResult','scanSessionContentForQueryInRecords','scanSessionContentForQuery','applySessionQueryFilter','getSessionListCache','setSessionListCache','listSessionBrowse','exportSessionData']; | ||
| let generic = 0, specialized = 0; | ||
| const messages = [{ role: 'user', text: 'needle' }]; | ||
| const ctx = vm.createContext({ ...require('../../lib/cli-sessions'), ...require('../../lib/cli-session-utils'), Buffer, path: require('node:path'), readline: require('node:readline'), DEFAULT_CONTENT_SCAN_LIMIT: 10, MAX_EXPORT_MESSAGES: 100, SESSION_LIST_CACHE_TTL_MS: 1000, g_sessionListCache: new Map(), normalizeSessionSourceName: x => x, resolveSessionFilePath: () => '/memory', getSessionFileArg: () => '', queryOpencodeSessionMessages: () => { specialized++; return { messages: [...messages] }; }, extractMessagesFromFile: async () => { generic++; return { messages: [...messages] }; }, normalizeGeminiMessageRole: () => 'user', extractGeminiMessageText: x => x, getSessionSourceLabel: x => x, buildSessionMarkdown: x => x.messages.map(m => m.text).join(''), fs: { readFileSync: () => JSON.stringify({ messages: [{ type: 'user', content: 'needle' }] }), createReadStream: () => require('node:stream').Readable.from([JSON.stringify({ type: 'response_item', payload: { type: 'message', role: 'user', content: [{ type: 'input_text', text: 'needle' }] } }) + '\n']) } }); | ||
| vm.runInContext(names.map(name => { const m = source.match(new RegExp('^(?:async )?function ' + name + '\\([^]*?^}', 'm')); assert.ok(m, name); return m[0]; }).join('\n'), ctx); | ||
| (async () => { | ||
| for (const kind of ['opencode', 'codex', 'gemini']) assert.equal((await ctx.exportSessionData({ source: kind, sessionId: 's' })).content, 'needle'); | ||
| assert.equal(specialized, 1); assert.equal(generic, 1); | ||
| const sessions = [1, 2, 3].map(sessionId => ({ sessionId, source: 'codex', title: 'needle' })); | ||
| const result = await ctx.applySessionQueryFilter(sessions, { tokens: ['needle'], queryScope: 'content', contentScanLimit: 2 }); | ||
| assert.equal(result.length, 2); assert.equal(JSON.stringify(result.searchInfo), '{"scanned":2,"candidates":3,"complete":false}'); | ||
| const full = await ctx.applySessionQueryFilter(sessions, { tokens: ['needle'], queryScope: 'content', contentScanLimit: 3 }); | ||
| assert.equal(full.searchInfo.complete, true); assert.equal(full.searchInfo.scanned, 3); | ||
| const summary = await ctx.applySessionQueryFilter(sessions, { tokens: ['needle'], queryScope: 'summary' }); | ||
| assert.equal(summary.searchInfo.scanned, 0); assert.equal(summary.length, 3); | ||
| const all = await ctx.applySessionQueryFilter(sessions, { tokens: ['needle'], queryScope: 'all', contentScanLimit: 1 }); | ||
| assert.equal(all.searchInfo.complete, false); assert.equal(all.searchInfo.scanned, 1); | ||
| ctx.setSessionListCache('query', result); assert.equal(ctx.getSessionListCache('query'), result); assert.equal(ctx.getSessionListCache('query').searchInfo, result.searchInfo); | ||
| assert.equal(Object.keys(result).includes('searchInfo'), false); assert.ok(Array.isArray(result)); assert.equal(JSON.parse(JSON.stringify(result)).length, 2); | ||
| ctx.listAllSessions = async () => result; const browse = await ctx.listSessionBrowse(); assert.equal(browse.searchInfo, result.searchInfo); | ||
| const empty = await ctx.applySessionQueryFilter(result, { tokens: [] }); assert.equal(empty.searchInfo, null); assert.equal(empty.length, 2); | ||
| ctx.setSessionListCache('empty', empty); assert.equal(ctx.getSessionListCache('empty').searchInfo, null); | ||
| assert.equal(ctx.getSessionListCache('query', true), null); | ||
| console.log('通过:真实函数 VM 隔离;OpenCode/Codex/Gemini 导出;JSONL 实扫计数;早停完成性;摘要免扫描;缓存与浏览元数据;空查询及数组兼容。'); | ||
| })().catch(error => { console.error(error); process.exitCode = 1; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not mark capped OpenCode scans complete.
When an OpenCode session has more than 2,000 messages,
queryOpencodeSessionMessagesreads only the newest 2,000, even withmaxMessages: Infinity. It also reportstruncated: falsein that case. This line therefore marks a search complete when an older message could match the query. The new all-messages export choice can likewise omit messages without a truncation notice. Use the available total-message count to report the cap, or read the remaining messages, while preserving the existing API shape. Based on learnings, keep the correction within the existing design and avoid breaking API changes.Source: Learnings