codexmate 0.1.28 → 0.1.30

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.
Files changed (58) hide show
  1. package/README.md +53 -44
  2. package/README.vi.md +45 -36
  3. package/README.zh.md +51 -42
  4. package/cli/session-usage.js +2 -2
  5. package/cli/skills.js +33 -8
  6. package/cli.js +379 -19
  7. package/package.json +6 -1
  8. package/web-ui/app.js +12 -1
  9. package/web-ui/index.html +3 -2
  10. package/web-ui/logic.sessions.mjs +30 -4
  11. package/web-ui/modules/app.computed.dashboard.mjs +1 -1
  12. package/web-ui/modules/app.computed.session.mjs +52 -33
  13. package/web-ui/modules/app.methods.agents.mjs +36 -0
  14. package/web-ui/modules/app.methods.codex-config.mjs +3 -1
  15. package/web-ui/modules/app.methods.providers.mjs +12 -4
  16. package/web-ui/modules/app.methods.session-actions.mjs +10 -8
  17. package/web-ui/modules/app.methods.session-browser.mjs +8 -2
  18. package/web-ui/modules/app.methods.session-trash.mjs +16 -16
  19. package/web-ui/modules/app.methods.system-prompt.mjs +1 -8
  20. package/web-ui/modules/app.methods.theme.mjs +5 -4
  21. package/web-ui/modules/i18n/locales/en.mjs +80 -1
  22. package/web-ui/modules/i18n/locales/ja.mjs +80 -1
  23. package/web-ui/modules/i18n/locales/vi.mjs +80 -1
  24. package/web-ui/modules/i18n/locales/zh-tw.mjs +80 -1
  25. package/web-ui/modules/i18n/locales/zh.mjs +80 -1
  26. package/web-ui/modules/i18n.mjs +23 -0
  27. package/web-ui/modules/skills.computed.mjs +11 -0
  28. package/web-ui/modules/skills.methods.mjs +58 -8
  29. package/web-ui/partials/index/layout-footer.html +1 -1
  30. package/web-ui/partials/index/layout-header.html +32 -12
  31. package/web-ui/partials/index/modal-config-template-agents.html +1 -1
  32. package/web-ui/partials/index/modal-health-check.html +1 -1
  33. package/web-ui/partials/index/modal-openclaw-config.html +50 -50
  34. package/web-ui/partials/index/panel-dashboard.html +1 -1
  35. package/web-ui/partials/index/panel-market.html +23 -5
  36. package/web-ui/partials/index/panel-prompts.html +2 -2
  37. package/web-ui/partials/index/panel-sessions.html +52 -42
  38. package/web-ui/partials/index/panel-settings.html +6 -0
  39. package/web-ui/partials/index/panel-trash.html +3 -0
  40. package/web-ui/res/web-ui-render.precompiled.js +567 -439
  41. package/web-ui/session-helpers.mjs +3 -0
  42. package/web-ui/styles/base-theme.css +2 -2
  43. package/web-ui/styles/bridge-pool.css +1 -1
  44. package/web-ui/styles/feedback.css +26 -0
  45. package/web-ui/styles/layout-shell.css +66 -3
  46. package/web-ui/styles/navigation-panels.css +4 -10
  47. package/web-ui/styles/sessions-list.css +19 -1
  48. package/web-ui/styles/sessions-preview.css +88 -1
  49. package/web-ui/styles/sessions-toolbar-trash.css +2 -2
  50. package/web-ui/styles/settings-panel.css +1 -1
  51. package/web-ui/styles/skills-market.css +47 -0
  52. package/web-ui/styles/theme-dark-tokens.css +2 -2
  53. package/web-ui/styles/theme-dark.css +2 -2
  54. package/web-ui/styles/theme-ocean-tokens.css +88 -0
  55. package/web-ui/styles/theme-ocean.css +920 -0
  56. package/web-ui/styles/titles-cards.css +1 -1
  57. package/web-ui/styles/trash-panel.css +43 -6
  58. package/web-ui/styles.css +1 -0
package/cli.js CHANGED
@@ -7,6 +7,7 @@ const toml = require('@iarna/toml');
7
7
  const JSON5 = require('json5');
8
8
  const zipLib = require('zip-lib');
9
9
  const yauzl = require('yauzl');
10
+ const zlib = require('node:zlib');
10
11
  const { exec, execSync, execFileSync, spawn, spawnSync } = require('child_process');
11
12
  const http = require('http');
12
13
  const https = require('https');
@@ -148,6 +149,7 @@ const {
148
149
  importCodexSkillsFromZip,
149
150
  exportSkills,
150
151
  exportCodexSkills,
152
+ backupSkills,
151
153
  deleteSkills,
152
154
  deleteCodexSkills
153
155
  } = require('./cli/skills');
@@ -264,6 +266,20 @@ const PI_SESSIONS_DIR = path.join(PI_DIR, 'agent', 'sessions');
264
266
  const OPENCODE_DATA_DIR = path.join(process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share'), 'opencode');
265
267
  const OPENCODE_DB_VIRTUAL_ROOT = path.join(OPENCODE_DATA_DIR, 'sessions');
266
268
  const OPENCODE_DB_READ_LIMIT = 2000;
269
+ function resolveZedDataDir() {
270
+ if (process.env.ZED_DATA_DIR) return process.env.ZED_DATA_DIR;
271
+ if (process.platform === 'win32') {
272
+ return process.env.LOCALAPPDATA
273
+ ? path.join(process.env.LOCALAPPDATA, 'Zed')
274
+ : path.join(os.homedir(), 'AppData', 'Local', 'Zed');
275
+ }
276
+ if (process.platform === 'darwin') return path.join(os.homedir(), '.zed');
277
+ return path.join(process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share'), 'zed');
278
+ }
279
+ const ZED_DATA_DIR = resolveZedDataDir();
280
+ const ZED_THREADS_DB_FILE = path.join(ZED_DATA_DIR, 'threads', 'threads.db');
281
+ const ZED_DB_VIRTUAL_ROOT = path.join(ZED_DATA_DIR, 'threads', 'sessions');
282
+ const ZED_SESSION_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
267
283
  const RECENT_CONFIGS_FILE = path.join(CONFIG_DIR, 'recent-configs.json');
268
284
  const WORKFLOW_DEFINITIONS_FILE = path.join(CONFIG_DIR, 'codexmate-workflows.json');
269
285
  const WORKFLOW_RUNS_FILE = path.join(CONFIG_DIR, 'codexmate-workflow-runs.jsonl');
@@ -772,7 +788,8 @@ let g_sessionFileLookupCache = {
772
788
  gemini: new Map(),
773
789
  codebuddy: new Map(),
774
790
  workbuddy: new Map(),
775
- pi: new Map()
791
+ pi: new Map(),
792
+ zed: new Map()
776
793
  };
777
794
  let g_exactMessageCountCache = new Map();
778
795
  let g_modelsCache = new Map();
@@ -1041,7 +1058,8 @@ function normalizeSidebarCollapsedPreference(value) {
1041
1058
  }
1042
1059
 
1043
1060
  function normalizeThemePreference(value) {
1044
- return value === 'dark' ? 'dark' : 'light';
1061
+ const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
1062
+ return normalized === 'dark' || normalized === 'ocean' ? normalized : 'light';
1045
1063
  }
1046
1064
 
1047
1065
  function normalizeSessionFilterSourcePreference(value) {
@@ -2417,6 +2435,260 @@ function listOpencodeSessions(limit, options = {}) {
2417
2435
  }, []);
2418
2436
  }
2419
2437
 
2438
+
2439
+ function isZedThreadsDbAvailable() {
2440
+ const Database = getNodeSqliteDatabaseSync();
2441
+ return !!(Database && ZED_THREADS_DB_FILE && fs.existsSync(ZED_THREADS_DB_FILE));
2442
+ }
2443
+
2444
+ function withZedThreadsDb(callback, fallback = null) {
2445
+ const Database = getNodeSqliteDatabaseSync();
2446
+ if (!Database || !ZED_THREADS_DB_FILE || !fs.existsSync(ZED_THREADS_DB_FILE)) {
2447
+ return fallback;
2448
+ }
2449
+ let db;
2450
+ try {
2451
+ db = new Database(ZED_THREADS_DB_FILE, { readOnly: true });
2452
+ return callback(db);
2453
+ } catch (_) {
2454
+ return fallback;
2455
+ } finally {
2456
+ if (db) {
2457
+ try { db.close(); } catch (_) { }
2458
+ }
2459
+ }
2460
+ }
2461
+
2462
+ function buildZedVirtualSessionPath(sessionId) {
2463
+ const id = typeof sessionId === 'string' ? sessionId.trim() : '';
2464
+ if (!id) return '';
2465
+ return path.join(ZED_DB_VIRTUAL_ROOT, `${id}.zed.jsonl`);
2466
+ }
2467
+
2468
+ function parseZedVirtualSessionId(filePath) {
2469
+ const raw = typeof filePath === 'string' ? filePath.trim() : '';
2470
+ if (!raw) return '';
2471
+ const base = path.basename(raw, path.extname(raw));
2472
+ return ZED_SESSION_ID_RE.test(base) ? base.toLowerCase() : '';
2473
+ }
2474
+
2475
+ /* Zed 会话文档存于 threads.db 的 threads.data 列(zstd 压缩 JSON)。
2476
+ * 版本 0.3.0 结构:{ title, messages: [{User:{content:[{Text}]}} | {Agent:{content:[{Text}|{Thinking:{text}}], tool_results, reasoning_details}}],
2477
+ * model: {provider, model}, cumulative_token_usage, initial_project_snapshot } */
2478
+ function parseZedThreadDocument(row) {
2479
+ if (!row || typeof row !== 'object') return null;
2480
+ const dataType = typeof row.data_type === 'string' ? row.data_type.trim().toLowerCase() : '';
2481
+ let text = '';
2482
+ try {
2483
+ if (dataType === 'zstd') {
2484
+ text = zlib.zstdDecompressSync(Buffer.from(row.data)).toString('utf8');
2485
+ } else if (!dataType || dataType === 'json' || dataType === 'utf8' || dataType === 'text') {
2486
+ text = Buffer.from(row.data).toString('utf8');
2487
+ } else {
2488
+ return null;
2489
+ }
2490
+ const parsed = JSON.parse(text);
2491
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
2492
+ } catch (_) {
2493
+ return null;
2494
+ }
2495
+ }
2496
+
2497
+ function extractZedTextFromContentBlocks(blocks) {
2498
+ if (!Array.isArray(blocks)) return '';
2499
+ const parts = [];
2500
+ for (const block of blocks) {
2501
+ if (!block || typeof block !== 'object') continue;
2502
+ if (typeof block.Text === 'string' && block.Text.trim()) {
2503
+ parts.push(block.Text.trim());
2504
+ } else if (block.Thinking && typeof block.Thinking === 'object'
2505
+ && typeof block.Thinking.text === 'string' && block.Thinking.text.trim()) {
2506
+ parts.push(block.Thinking.text.trim());
2507
+ }
2508
+ }
2509
+ return parts.join('\n').trim();
2510
+ }
2511
+
2512
+ function readZedThreadModelInfo(doc) {
2513
+ const model = doc && doc.model && typeof doc.model === 'object' ? doc.model : null;
2514
+ return {
2515
+ model: model && typeof model.model === 'string' ? model.model.trim() : '',
2516
+ provider: model && typeof model.provider === 'string' && model.provider.trim() ? model.provider.trim() : 'zed'
2517
+ };
2518
+ }
2519
+
2520
+ function normalizeZedThreadMessage(entry, modelInfo) {
2521
+ if (!entry || typeof entry !== 'object') return null;
2522
+ if (entry.User && typeof entry.User === 'object') {
2523
+ const text = extractZedTextFromContentBlocks(entry.User.content);
2524
+ if (!text) return null;
2525
+ return { role: 'user', text, timestamp: '', model: modelInfo.model, provider: modelInfo.provider };
2526
+ }
2527
+ if (entry.Agent && typeof entry.Agent === 'object') {
2528
+ const text = extractZedTextFromContentBlocks(entry.Agent.content);
2529
+ if (!text) return null;
2530
+ return { role: 'assistant', text, timestamp: '', model: modelInfo.model, provider: modelInfo.provider };
2531
+ }
2532
+ return null;
2533
+ }
2534
+
2535
+ function countZedThreadMessages(doc, modelInfo) {
2536
+ const rawMessages = doc && Array.isArray(doc.messages) ? doc.messages : [];
2537
+ return rawMessages.map(entry => normalizeZedThreadMessage(entry, modelInfo)).filter(Boolean).length;
2538
+ }
2539
+
2540
+ function readZedThreadUsage(doc) {
2541
+ const usage = doc && doc.cumulative_token_usage && typeof doc.cumulative_token_usage === 'object'
2542
+ ? doc.cumulative_token_usage
2543
+ : {};
2544
+ const inputTokens = readNonNegativeInteger(usage.input_tokens) || 0;
2545
+ const cachedInputTokens = readNonNegativeInteger(usage.cache_read_input_tokens) || 0;
2546
+ const cacheCreationInputTokens = readNonNegativeInteger(usage.cache_creation_input_tokens) || 0;
2547
+ const outputTokens = readNonNegativeInteger(usage.output_tokens) || 0;
2548
+ const reasoningOutputTokens = readNonNegativeInteger(usage.reasoning_output_tokens) || 0;
2549
+ return {
2550
+ inputTokens,
2551
+ cachedInputTokens,
2552
+ cacheCreationInputTokens,
2553
+ outputTokens,
2554
+ reasoningOutputTokens,
2555
+ totalTokens: inputTokens + outputTokens + reasoningOutputTokens + cachedInputTokens + cacheCreationInputTokens
2556
+ };
2557
+ }
2558
+
2559
+ function readZedThreadCwd(row, doc) {
2560
+ const raw = typeof row.folder_paths === 'string' ? row.folder_paths.trim() : '';
2561
+ if (raw && !raw.startsWith('[')) {
2562
+ return raw;
2563
+ }
2564
+ if (raw.startsWith('[')) {
2565
+ try {
2566
+ const parsed = JSON.parse(raw);
2567
+ const first = Array.isArray(parsed) ? parsed.find(item => typeof item === 'string' && item.trim()) : null;
2568
+ if (first) return first;
2569
+ } catch (_) { }
2570
+ }
2571
+ const snapshot = doc && doc.initial_project_snapshot && Array.isArray(doc.initial_project_snapshot.worktree_snapshots)
2572
+ ? doc.initial_project_snapshot.worktree_snapshots.find(item => item && typeof item.worktree_path === 'string' && item.worktree_path.trim())
2573
+ : null;
2574
+ return snapshot ? snapshot.worktree_path : '';
2575
+ }
2576
+
2577
+ function queryZedSessionMessages(sessionId, options = {}) {
2578
+ const id = typeof sessionId === 'string' ? sessionId.trim().toLowerCase() : '';
2579
+ if (!id) return null;
2580
+ const maxMessages = resolveMaxMessagesValue(options.maxMessages, DEFAULT_SESSION_DETAIL_MESSAGES);
2581
+ return withZedThreadsDb((db) => {
2582
+ const row = db.prepare('select data, data_type, folder_paths, updated_at from threads where id = ?').get(id) || null;
2583
+ const doc = parseZedThreadDocument(row);
2584
+ const modelInfo = readZedThreadModelInfo(doc);
2585
+ const all = (doc && Array.isArray(doc.messages) ? doc.messages : [])
2586
+ .map(entry => normalizeZedThreadMessage(entry, modelInfo))
2587
+ .filter(Boolean);
2588
+ const totalMessages = all.length;
2589
+ const limit = maxMessages === Infinity
2590
+ ? totalMessages
2591
+ : Math.min(totalMessages, Math.max(1, Math.floor(maxMessages)));
2592
+ const messages = limit < totalMessages ? all.slice(totalMessages - limit) : all;
2593
+ return {
2594
+ sessionId: id,
2595
+ cwd: doc ? readZedThreadCwd(row, doc) : '',
2596
+ updatedAt: row ? toIsoTime(row.updated_at, '') : '',
2597
+ messages,
2598
+ totalMessages,
2599
+ clipped: maxMessages !== Infinity && totalMessages > messages.length,
2600
+ truncated: maxMessages !== Infinity && totalMessages > messages.length
2601
+ };
2602
+ }, null);
2603
+ }
2604
+
2605
+ function countZedMessages(sessionId) {
2606
+ const id = typeof sessionId === 'string' ? sessionId.trim().toLowerCase() : '';
2607
+ if (!id) return null;
2608
+ return withZedThreadsDb((db) => {
2609
+ const row = db.prepare('select data, data_type from threads where id = ?').get(id) || null;
2610
+ const doc = parseZedThreadDocument(row);
2611
+ if (!doc) return null;
2612
+ return countZedThreadMessages(doc, readZedThreadModelInfo(doc));
2613
+ }, null);
2614
+ }
2615
+
2616
+ function parseZedSessionSummaryRow(row) {
2617
+ if (!row || typeof row !== 'object') return null;
2618
+ const sessionId = typeof row.id === 'string' ? row.id.trim().toLowerCase() : '';
2619
+ if (!sessionId) return null;
2620
+ const doc = parseZedThreadDocument(row);
2621
+ if (!doc) return null;
2622
+ const modelInfo = readZedThreadModelInfo(doc);
2623
+ const usage = readZedThreadUsage(doc);
2624
+ let title = typeof row.summary === 'string' ? row.summary.trim() : '';
2625
+ if (!title && typeof doc.title === 'string') title = doc.title.trim();
2626
+ if (!title) {
2627
+ const firstUser = (Array.isArray(doc.messages) ? doc.messages : [])
2628
+ .map(entry => normalizeZedThreadMessage(entry, modelInfo))
2629
+ .find(item => item && item.role === 'user' && item.text);
2630
+ if (firstUser) title = truncateText(firstUser.text, 120);
2631
+ }
2632
+ if (!title) title = sessionId;
2633
+ return {
2634
+ source: 'zed',
2635
+ sourceLabel: 'Zed',
2636
+ provider: modelInfo.provider,
2637
+ model: modelInfo.model,
2638
+ models: modelInfo.model ? [modelInfo.model] : [],
2639
+ sessionId,
2640
+ title,
2641
+ cwd: readZedThreadCwd(row, doc),
2642
+ createdAt: toIsoTime(row.created_at, ''),
2643
+ updatedAt: toIsoTime(row.updated_at, ''),
2644
+ messageCount: countZedThreadMessages(doc, modelInfo),
2645
+ totalTokens: usage.totalTokens,
2646
+ contextWindow: 0,
2647
+ inputTokens: usage.inputTokens,
2648
+ cachedInputTokens: usage.cachedInputTokens,
2649
+ cacheCreationInputTokens: usage.cacheCreationInputTokens,
2650
+ outputTokens: usage.outputTokens,
2651
+ reasoningOutputTokens: usage.reasoningOutputTokens,
2652
+ __messageCountExact: true,
2653
+ filePath: buildZedVirtualSessionPath(sessionId),
2654
+ keywords: [],
2655
+ capabilities: { code: true }
2656
+ };
2657
+ }
2658
+
2659
+ function parseZedSessionSummary(sessionId) {
2660
+ const id = typeof sessionId === 'string' ? sessionId.trim().toLowerCase() : '';
2661
+ if (!id) return null;
2662
+ return withZedThreadsDb((db) => {
2663
+ const row = db.prepare(`
2664
+ select id, summary, folder_paths, created_at, updated_at, data, data_type
2665
+ from threads where id = ?
2666
+ `).get(id) || null;
2667
+ return parseZedSessionSummaryRow(row);
2668
+ }, null);
2669
+ }
2670
+
2671
+ function listZedSessions(limit, options = {}) {
2672
+ if (!isZedThreadsDbAvailable()) return [];
2673
+ const scanFactor = Number.isFinite(Number(options.scanFactor)) ? Math.max(1, Number(options.scanFactor)) : SESSION_SCAN_FACTOR;
2674
+ const targetCount = Number.isFinite(Number(options.targetCount)) ? Math.max(1, Math.floor(Number(options.targetCount))) : Math.max(1, Math.floor(limit * scanFactor));
2675
+ const scanCount = Number.isFinite(Number(options.scanCount)) ? Math.max(targetCount, Math.floor(Number(options.scanCount))) : Math.max(targetCount, Math.min(SESSION_SCAN_MIN_FILES, MAX_SESSION_LIST_SIZE * SESSION_SCAN_FACTOR));
2676
+ return withZedThreadsDb((db) => {
2677
+ const rows = db.prepare(`
2678
+ select id, summary, folder_paths, created_at, updated_at, data, data_type
2679
+ from threads
2680
+ order by updated_at desc
2681
+ limit ?
2682
+ `).all(Math.min(OPENCODE_DB_READ_LIMIT, Math.max(scanCount, targetCount)));
2683
+ const sessions = [];
2684
+ for (const row of rows) {
2685
+ const summary = parseZedSessionSummaryRow(row);
2686
+ if (summary) sessions.push(summary);
2687
+ if (sessions.length >= targetCount) break;
2688
+ }
2689
+ return mergeAndLimitSessions(sessions, limit);
2690
+ }, []);
2691
+ }
2420
2692
  function getCodexmateDerivedSessionsRoot(target) {
2421
2693
  if (target === 'claude') {
2422
2694
  return CODEXMATE_DERIVED_CLAUDE_DIR;
@@ -4689,7 +4961,7 @@ async function hydrateSessionItemsExactMessageCount(items) {
4689
4961
 
4690
4962
  function normalizeSessionSourceName(value, fallback = '') {
4691
4963
  const source = typeof value === 'string' ? value.trim().toLowerCase() : '';
4692
- if (source === 'codex' || source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'pi' || source === 'opencode') {
4964
+ if (source === 'codex' || source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'pi' || source === 'opencode' || source === 'zed') {
4693
4965
  return source;
4694
4966
  }
4695
4967
  return fallback;
@@ -4707,6 +4979,7 @@ function getSessionSourceLabel(source) {
4707
4979
  if (source === 'workbuddy') return 'WorkBuddy AI';
4708
4980
  if (source === 'pi') return 'Pi';
4709
4981
  if (source === 'opencode') return 'OpenCode';
4982
+ if (source === 'zed') return 'Zed';
4710
4983
  return 'Codex';
4711
4984
  }
4712
4985
 
@@ -4717,6 +4990,7 @@ function getSessionSourceProvider(source) {
4717
4990
  if (source === 'workbuddy') return 'workbuddy';
4718
4991
  if (source === 'pi') return 'pi';
4719
4992
  if (source === 'opencode') return 'opencode';
4993
+ if (source === 'zed') return 'zed';
4720
4994
  return 'codex';
4721
4995
  }
4722
4996
 
@@ -4746,6 +5020,9 @@ async function readSessionMessageCounts(params = {}) {
4746
5020
  if (source === 'opencode') {
4747
5021
  const opencodeSessionId = item.sessionId || parseOpencodeVirtualSessionId(filePath);
4748
5022
  exactMessageCount = countOpencodeMessages(opencodeSessionId);
5023
+ } else if (source === 'zed') {
5024
+ const zedSessionId = item.sessionId || parseZedVirtualSessionId(filePath);
5025
+ exactMessageCount = countZedMessages(zedSessionId);
4749
5026
  } else {
4750
5027
  if (!filePath || !fs.existsSync(filePath)) {
4751
5028
  return { key };
@@ -4896,6 +5173,7 @@ function createSessionQueryScanState(tokens, options = {}) {
4896
5173
  count: 0,
4897
5174
  snippets: [],
4898
5175
  positions: [],
5176
+ complete: true,
4899
5177
  leadingSystem: roleFilter !== 'system'
4900
5178
  };
4901
5179
  }
@@ -4934,11 +5212,13 @@ function consumeSessionQueryMessage(state, message) {
4934
5212
  timestamp: typeof message.timestamp === 'string' ? message.timestamp : ''
4935
5213
  });
4936
5214
  }
5215
+ if (state.count >= state.maxMatches) state.complete = false;
4937
5216
  return state.count >= state.maxMatches;
4938
5217
  }
4939
5218
 
4940
5219
  function buildSessionQueryScanResult(state) {
4941
5220
  return {
5221
+ complete: !!(state && state.complete),
4942
5222
  hit: !!(state && state.count > 0),
4943
5223
  count: state && Number.isFinite(state.count) ? state.count : 0,
4944
5224
  snippets: state && Array.isArray(state.snippets) ? state.snippets : [],
@@ -4983,6 +5263,7 @@ async function scanSessionContentForQuery(session, tokens, options = {}) {
4983
5263
  const state = createSessionQueryScanState(tokens, options);
4984
5264
  if (session.source === 'opencode') {
4985
5265
  const extracted = queryOpencodeSessionMessages(session.sessionId || parseOpencodeVirtualSessionId(filePath), { maxMessages: Infinity });
5266
+ state.complete = !!extracted && !extracted.truncated;
4986
5267
  const messages = extracted && Array.isArray(extracted.messages) ? extracted.messages : [];
4987
5268
  for (let i = 0; i < messages.length; i += 1) {
4988
5269
  const message = { ...messages[i], recordLineIndex: i };
@@ -4990,6 +5271,16 @@ async function scanSessionContentForQuery(session, tokens, options = {}) {
4990
5271
  }
4991
5272
  return buildSessionQueryScanResult(state);
4992
5273
  }
5274
+ if (session.source === 'zed') {
5275
+ const zedExtracted = queryZedSessionMessages(session.sessionId || parseZedVirtualSessionId(filePath), { maxMessages: Infinity });
5276
+ state.complete = !!zedExtracted && !zedExtracted.truncated;
5277
+ const zedMessages = zedExtracted && Array.isArray(zedExtracted.messages) ? zedExtracted.messages : [];
5278
+ for (let i = 0; i < zedMessages.length; i += 1) {
5279
+ const message = { ...zedMessages[i], recordLineIndex: i };
5280
+ if (consumeSessionQueryMessage(state, message)) break;
5281
+ }
5282
+ return buildSessionQueryScanResult(state);
5283
+ }
4993
5284
  if (session.source === 'gemini') {
4994
5285
  if (state.roleFilter !== 'all' || state.positionsLimit > 0) {
4995
5286
  let json;
@@ -4998,6 +5289,7 @@ async function scanSessionContentForQuery(session, tokens, options = {}) {
4998
5289
  } catch (_) {
4999
5290
  json = null;
5000
5291
  }
5292
+ state.complete = !!json;
5001
5293
  const rawMessages = json && Array.isArray(json.messages) ? json.messages : [];
5002
5294
  for (const entry of rawMessages) {
5003
5295
  if (!entry || typeof entry !== 'object') continue;
@@ -5025,12 +5317,14 @@ async function scanSessionContentForQuery(session, tokens, options = {}) {
5025
5317
  const buf = Buffer.alloc(targetBytes);
5026
5318
  const bytes = fs.readSync(fd, buf, 0, targetBytes, 0);
5027
5319
  fs.closeSync(fd);
5320
+ state.complete = bytes >= stat.size;
5028
5321
  text = bytes > 0 ? buf.slice(0, bytes).toString('utf-8') : '';
5029
5322
  } catch (_) {
5030
5323
  try {
5031
5324
  text = fs.readFileSync(filePath, 'utf-8');
5032
5325
  } catch (_) {
5033
5326
  text = '';
5327
+ state.complete = false;
5034
5328
  }
5035
5329
  }
5036
5330
 
@@ -5055,6 +5349,7 @@ async function scanSessionContentForQuery(session, tokens, options = {}) {
5055
5349
  const currentLineIndex = lineIndex;
5056
5350
  lineIndex += 1;
5057
5351
  if (maxBytes > 0 && bytesRead >= maxBytes) {
5352
+ state.complete = false;
5058
5353
  break;
5059
5354
  }
5060
5355
 
@@ -5084,6 +5379,7 @@ async function scanSessionContentForQuery(session, tokens, options = {}) {
5084
5379
 
5085
5380
  return buildSessionQueryScanResult(state);
5086
5381
  } catch (e) {
5382
+ state.complete = false;
5087
5383
  return scanSessionContentForQueryInRecords(readJsonlRecords(filePath), session.source, state);
5088
5384
  } finally {
5089
5385
  if (rl) {
@@ -5098,7 +5394,9 @@ async function scanSessionContentForQuery(session, tokens, options = {}) {
5098
5394
  async function applySessionQueryFilter(sessions, options = {}) {
5099
5395
  const tokens = Array.isArray(options.tokens) ? options.tokens : [];
5100
5396
  if (tokens.length === 0) {
5101
- return sessions;
5397
+ const result = sessions.slice();
5398
+ Object.defineProperty(result, 'searchInfo', { value: null });
5399
+ return result;
5102
5400
  }
5103
5401
 
5104
5402
  const mode = normalizeQueryMode(options.queryMode);
@@ -5112,10 +5410,12 @@ async function applySessionQueryFilter(sessions, options = {}) {
5112
5410
  : 0;
5113
5411
 
5114
5412
  let scanned = 0;
5413
+ let complete = true;
5115
5414
  const results = [];
5116
5415
 
5117
5416
  for (const session of sessions) {
5118
5417
  if (scope === 'content' && scanned >= contentScanLimit) {
5418
+ complete = false;
5119
5419
  break;
5120
5420
  }
5121
5421
 
@@ -5135,6 +5435,10 @@ async function applySessionQueryFilter(sessions, options = {}) {
5135
5435
  snippetLimit: 2
5136
5436
  });
5137
5437
  contentHit = contentInfo.hit;
5438
+ // 命中已完成候选的存在性判定,无需穷尽匹配或消息。
5439
+ if (!contentHit && !contentInfo.complete) complete = false;
5440
+ } else if (shouldScanContent) {
5441
+ complete = false;
5138
5442
  }
5139
5443
 
5140
5444
  const hit = scope === 'summary'
@@ -5156,6 +5460,9 @@ async function applySessionQueryFilter(sessions, options = {}) {
5156
5460
  results.push(session);
5157
5461
  }
5158
5462
 
5463
+ Object.defineProperty(results, 'searchInfo', {
5464
+ value: { scanned, candidates: sessions.length, complete }
5465
+ });
5159
5466
  return results;
5160
5467
  }
5161
5468
  function collectRecentJsonlFiles(rootDir, options = {}) {
@@ -5381,7 +5688,7 @@ function getSessionInventoryCache(cacheKey, forceRefresh = false) {
5381
5688
  }
5382
5689
 
5383
5690
  function registerSessionFileLookupEntries(source, sessions = []) {
5384
- const normalizedSource = source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'pi' || source === 'opencode'
5691
+ const normalizedSource = source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'pi' || source === 'opencode' || source === 'zed'
5385
5692
  ? source
5386
5693
  : 'codex';
5387
5694
  const store = g_sessionFileLookupCache[normalizedSource];
@@ -5422,7 +5729,7 @@ function setSessionInventoryCache(cacheKey, source, value) {
5422
5729
  }
5423
5730
 
5424
5731
  function listSessionInventoryBySource(source, limit, scanOptions = {}, options = {}) {
5425
- const normalizedSource = source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'pi' || source === 'opencode'
5732
+ const normalizedSource = source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'pi' || source === 'opencode' || source === 'zed'
5426
5733
  ? source
5427
5734
  : 'codex';
5428
5735
  const forceRefresh = !!options.forceRefresh;
@@ -5444,7 +5751,9 @@ function listSessionInventoryBySource(source, limit, scanOptions = {}, options =
5444
5751
  ? listPiSessions(limit, scanOptions)
5445
5752
  : (normalizedSource === 'opencode'
5446
5753
  ? listOpencodeSessions(limit, scanOptions)
5447
- : listCodexSessions(limit, scanOptions))))));
5754
+ : (normalizedSource === 'zed'
5755
+ ? listZedSessions(limit, scanOptions)
5756
+ : listCodexSessions(limit, scanOptions)))))));
5448
5757
  setSessionInventoryCache(cacheKey, normalizedSource, sessions);
5449
5758
  return sessions;
5450
5759
  }
@@ -5459,7 +5768,8 @@ function invalidateSessionListCache() {
5459
5768
  codebuddy: new Map(),
5460
5769
  workbuddy: new Map(),
5461
5770
  pi: new Map(),
5462
- opencode: new Map()
5771
+ opencode: new Map(),
5772
+ zed: new Map()
5463
5773
  };
5464
5774
  }
5465
5775
 
@@ -7325,6 +7635,9 @@ async function listAllSessions(params = {}) {
7325
7635
  if (source === 'all' || source === 'opencode') {
7326
7636
  sessions = sessions.concat(listSessionInventoryBySource('opencode', limit, scanOptions, { forceRefresh }));
7327
7637
  }
7638
+ if (source === 'all' || source === 'zed') {
7639
+ sessions = sessions.concat(listSessionInventoryBySource('zed', limit, scanOptions, { forceRefresh }));
7640
+ }
7328
7641
 
7329
7642
  if (hasPathFilter) {
7330
7643
  sessions = sessions.filter(item => matchesSessionPathFilter(item, normalizedPathFilter));
@@ -7341,7 +7654,9 @@ async function listAllSessions(params = {}) {
7341
7654
  contentScanBytes: params.contentScanBytes
7342
7655
  });
7343
7656
  }
7657
+ const searchInfo = hasQuery ? result.searchInfo : null;
7344
7658
  result = mergeAndLimitSessions(result, limit);
7659
+ Object.defineProperty(result, 'searchInfo', { value: searchInfo });
7345
7660
  setSessionListCache(cacheKey, result);
7346
7661
  return result;
7347
7662
  }
@@ -7374,6 +7689,7 @@ async function listAllSessionsData(params = {}) {
7374
7689
  delete normalized.__messageCountExact;
7375
7690
  return normalized;
7376
7691
  });
7692
+ Object.defineProperty(result, 'searchInfo', { value: sessions.searchInfo || null });
7377
7693
  if (!hasQuery) {
7378
7694
  setSessionListCache(cacheKey, result);
7379
7695
  }
@@ -7385,7 +7701,7 @@ async function listSessionBrowse(params = {}) {
7385
7701
  ...params,
7386
7702
  browseLightweight: true
7387
7703
  });
7388
- return Array.isArray(sessions)
7704
+ const result = Array.isArray(sessions)
7389
7705
  ? sessions.map((item) => {
7390
7706
  if (!item || typeof item !== 'object' || Array.isArray(item)) {
7391
7707
  return item;
@@ -7395,6 +7711,8 @@ async function listSessionBrowse(params = {}) {
7395
7711
  return normalized;
7396
7712
  })
7397
7713
  : [];
7714
+ Object.defineProperty(result, 'searchInfo', { value: sessions.searchInfo || null });
7715
+ return result;
7398
7716
  }
7399
7717
 
7400
7718
  async function listSessionUsage(params = {}) {
@@ -7466,6 +7784,9 @@ function listSessionPaths(params = {}) {
7466
7784
  if (validSource === 'all' || validSource === 'opencode') {
7467
7785
  sessions = sessions.concat(listSessionInventoryBySource('opencode', gatherLimit, scanOptions, { forceRefresh }));
7468
7786
  }
7787
+ if (validSource === 'all' || validSource === 'zed') {
7788
+ sessions = sessions.concat(listSessionInventoryBySource('zed', gatherLimit, scanOptions, { forceRefresh }));
7789
+ }
7469
7790
 
7470
7791
  const dedupedPaths = [];
7471
7792
  const seen = new Set();
@@ -7492,6 +7813,12 @@ function listSessionPaths(params = {}) {
7492
7813
 
7493
7814
  function resolveSessionFilePath(source, filePath, sessionId) {
7494
7815
  const normalizedSource = normalizeSessionSourceName(source, 'codex');
7816
+ if (normalizedSource === 'zed') {
7817
+ const zedId = typeof sessionId === 'string' && sessionId.trim()
7818
+ ? sessionId.trim()
7819
+ : parseZedVirtualSessionId(filePath);
7820
+ return zedId && parseZedSessionSummary(zedId) ? buildZedVirtualSessionPath(zedId) : '';
7821
+ }
7495
7822
  if (normalizedSource === 'opencode') {
7496
7823
  const id = typeof sessionId === 'string' && sessionId.trim()
7497
7824
  ? sessionId.trim()
@@ -8072,7 +8399,7 @@ function buildSessionSummaryFallback(source, filePath, sessionId = '') {
8072
8399
  contextWindow: 0,
8073
8400
  filePath,
8074
8401
  keywords: [],
8075
- capabilities: source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'opencode' ? { code: true } : {}
8402
+ capabilities: source === 'claude' || source === 'gemini' || source === 'codebuddy' || source === 'workbuddy' || source === 'opencode' || source === 'zed' ? { code: true } : {}
8076
8403
  };
8077
8404
  }
8078
8405
 
@@ -8659,6 +8986,9 @@ async function trashSessionData(params = {}) {
8659
8986
  if (source === 'opencode') {
8660
8987
  return { error: 'OpenCode DB-backed sessions cannot be deleted from CodexMate' };
8661
8988
  }
8989
+ if (source === 'zed') {
8990
+ return { error: 'Zed DB-backed sessions cannot be deleted from CodexMate' };
8991
+ }
8662
8992
 
8663
8993
  const filePath = resolveSessionFilePath(source, getSessionFileArg(params), params.sessionId);
8664
8994
  if (!filePath) {
@@ -8771,6 +9101,9 @@ async function deleteSessionData(params = {}) {
8771
9101
  if (source === 'opencode') {
8772
9102
  return { error: 'OpenCode DB-backed sessions cannot be deleted from CodexMate' };
8773
9103
  }
9104
+ if (source === 'zed') {
9105
+ return { error: 'Zed DB-backed sessions cannot be deleted from CodexMate' };
9106
+ }
8774
9107
 
8775
9108
  const filePath = resolveSessionFilePath(source, getSessionFileArg(params), params.sessionId);
8776
9109
  if (!filePath) {
@@ -9470,6 +9803,13 @@ async function readSessionDetail(params = {}) {
9470
9803
  if (!extracted) {
9471
9804
  return { error: 'Failed to parse session file' };
9472
9805
  }
9806
+ }
9807
+ if (source === 'zed') {
9808
+ const zedSessionId = params.sessionId || parseZedVirtualSessionId(filePath);
9809
+ extracted = queryZedSessionMessages(zedSessionId, { maxMessages: messageLimit });
9810
+ if (!extracted) {
9811
+ return { error: 'Failed to parse session file' };
9812
+ }
9473
9813
  } else if (source === 'gemini') {
9474
9814
  let json;
9475
9815
  try {
@@ -9604,6 +9944,13 @@ async function readSessionPlain(params = {}) {
9604
9944
  if (!extracted) {
9605
9945
  return { error: 'Failed to parse session file' };
9606
9946
  }
9947
+ }
9948
+ if (source === 'zed') {
9949
+ const zedSessionId = params.sessionId || parseZedVirtualSessionId(filePath);
9950
+ extracted = queryZedSessionMessages(zedSessionId, { maxMessages });
9951
+ if (!extracted) {
9952
+ return { error: 'Failed to parse session file' };
9953
+ }
9607
9954
  } else if (source === 'gemini') {
9608
9955
  let json;
9609
9956
  try {
@@ -9688,6 +10035,12 @@ async function exportSessionData(params = {}) {
9688
10035
  if (!extracted) {
9689
10036
  return { error: 'Failed to parse session file' };
9690
10037
  }
10038
+ } else if (source === 'zed') {
10039
+ const zedSessionId = params.sessionId || parseZedVirtualSessionId(filePath);
10040
+ extracted = queryZedSessionMessages(zedSessionId, { maxMessages });
10041
+ if (!extracted) {
10042
+ return { error: 'Failed to parse session file' };
10043
+ }
9691
10044
  } else if (source === 'gemini') {
9692
10045
  let json;
9693
10046
  try {
@@ -12929,7 +13282,7 @@ function resolveExportOutputPath(outputPath, defaultFileName) {
12929
13282
  }
12930
13283
 
12931
13284
  function printExportSessionUsage() {
12932
- console.log('\n用法: codexmate export-session --source <codex|claude|gemini|codebuddy|workbuddy|pi|opencode> (--session-id <ID>|--file <PATH>) [--output <PATH>] [--max-messages <N|all|Infinity>]');
13285
+ console.log('\n用法: codexmate export-session --source <codex|claude|gemini|codebuddy|workbuddy|pi|opencode|zed> (--session-id <ID>|--file <PATH>) [--output <PATH>] [--max-messages <N|all|Infinity>]');
12933
13286
  console.log('\n示例:');
12934
13287
  console.log(' codexmate export-session --source codex --session-id 123456');
12935
13288
  console.log(' codexmate export-session --source claude --file "~/.claude/projects/demo/session.jsonl"');
@@ -13002,7 +13355,7 @@ function parseExportSessionArgs(args = []) {
13002
13355
 
13003
13356
  const normalizedSource = options.source.trim().toLowerCase();
13004
13357
  if (normalizedSource && !isSessionSourceOrAll(normalizedSource)) {
13005
- errors.push('参数 --source 仅支持 codex、claude、gemini、codebuddy、workbuddy、pi 或 opencode');
13358
+ errors.push('参数 --source 仅支持 codex、claude、gemini、codebuddy、workbuddy、pi、opencode 或 zed');
13006
13359
  }
13007
13360
  options.source = normalizedSource;
13008
13361
 
@@ -14222,6 +14575,9 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
14222
14575
  case 'export-skills':
14223
14576
  result = await exportSkills(params || {});
14224
14577
  break;
14578
+ case 'backup-skills':
14579
+ result = await backupSkills(params || {});
14580
+ break;
14225
14581
  case 'list-codex-skills':
14226
14582
  result = listCodexSkills();
14227
14583
  break;
@@ -14433,9 +14789,11 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
14433
14789
  if (source && !isSessionSourceOrAll(source)) {
14434
14790
  result = { error: 'Invalid source. Must be codex, claude, gemini, codebuddy, workbuddy, pi, opencode, or all' };
14435
14791
  } else {
14792
+ const sessions = await listSessionBrowse(params);
14436
14793
  result = {
14437
- sessions: await listSessionBrowse(params),
14438
- source: source || 'all'
14794
+ sessions,
14795
+ source: source || 'all',
14796
+ searchInfo: sessions.searchInfo
14439
14797
  };
14440
14798
  }
14441
14799
  }
@@ -14876,10 +15234,12 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
14876
15234
  console.log(' 退出: Ctrl+C\n');
14877
15235
  if (isAnyAddressHost(host)) {
14878
15236
  const tokenEnabled = typeof process.env.CODEXMATE_HTTP_TOKEN === 'string' && process.env.CODEXMATE_HTTP_TOKEN.trim().length > 0;
14879
- console.warn(`! 安全提示: 当前监听所有网卡(${tokenEnabled ? '已启用鉴权' : '无鉴权'})。`);
14880
- if (!tokenEnabled) {
14881
- console.warn(' 建议仅在可信网络使用,或改用 --host 127.0.0.1。');
14882
- console.warn(' 如需远程访问,请设置 CODEXMATE_HTTP_TOKEN。');
15237
+ if (tokenEnabled) {
15238
+ console.warn('! 安全提示: 当前监听所有网卡,局域网访问需要访问令牌。');
15239
+ } else {
15240
+ console.warn('! 安全提示: 当前监听所有网卡,但未配置访问令牌,远程访问已禁用。');
15241
+ console.warn(' 如需局域网访问,请先设置 CODEXMATE_HTTP_TOKEN。');
15242
+ console.warn(' 如需仅限本机访问,请改用 --host 127.0.0.1。');
14883
15243
  }
14884
15244
  }
14885
15245
 
@@ -17374,7 +17734,7 @@ function printMainHelp() {
17374
17734
  console.log(' 注: follow-up 自动排队仅支持 linux/android/netbsd/openbsd/darwin/freebsd 且 stdin 必须是 TTY,其他平台会报错');
17375
17735
  console.log(' codexmate qwen [参数...] 等同于 qwen --yolo');
17376
17736
  console.log(' codexmate mcp [serve] [--transport stdio] [--allow-write|--read-only]');
17377
- console.log(' codexmate export-session --source <codex|claude|gemini|codebuddy|workbuddy|pi|opencode> (--session-id <ID>|--file <PATH>) [--output <PATH>] [--max-messages <N|all|Infinity>]');
17737
+ console.log(' codexmate export-session --source <codex|claude|gemini|codebuddy|workbuddy|pi|opencode|zed> (--session-id <ID>|--file <PATH>) [--output <PATH>] [--max-messages <N|all|Infinity>]');
17378
17738
  console.log(' codexmate convert-session --from <codex|claude> --to <codex|claude> (--session-id <ID>|--file <PATH>) [--output <PATH>] [--max-messages <N|all|Infinity>]');
17379
17739
  console.log(' codexmate zip <路径> [--max:级别] 压缩(系统 zip 优先,其次 zip-lib)');
17380
17740
  console.log(' codexmate unzip <zip文件> [输出目录] 解压(zip-lib)');