dsh-session-history 0.2.3 → 0.2.5

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 CHANGED
@@ -189,7 +189,7 @@ session-history refresh | status | setup | link all | unlink claude | config
189
189
  Git 子目录地址(不提供原生更新检查):
190
190
 
191
191
  ```text
192
- git+https://github.com/fujingzhai/youxia-dsh-plugins.git#dsh-session-history@0.2.3&path:/dsh-session-history
192
+ git+https://github.com/fujingzhai/youxia-dsh-plugins.git#dsh-session-history@0.2.5&path:/dsh-session-history
193
193
  ```
194
194
 
195
195
  ## 兼容与限制
@@ -22,6 +22,8 @@ const { allSources, byId, byFolder, enabled } = await import('../lib/agents.js')
22
22
  const { installSkill, logFolders, VERSION } = await import('../lib/skill.js');
23
23
  const { skillStatus, link, linkAll, unlink } = await import('../lib/links.js');
24
24
  const { tilde } = await import('../lib/files.js');
25
+ const { readdirSync } = await import('node:fs');
26
+ const { join } = await import('node:path');
25
27
 
26
28
  const HELP = `Session History ${VERSION} — 各 agent 的历史对话检索(不调用模型)
27
29
 
@@ -92,6 +94,7 @@ function withIndex(home, config, fn) {
92
94
  }
93
95
 
94
96
  function statusText(home) {
97
+ const logDaysOf = folder => { try { return readdirSync(join(layout(home).logs, folder)).filter(f => f.endsWith('-log.md')).length; } catch { return 0; } };
95
98
  const config = loadConfig(home);
96
99
  const last = readJson(layout(home).status, null);
97
100
  const { agents, targets, links } = skillStatus(home, config);
@@ -99,14 +102,16 @@ function statusText(home) {
99
102
  lines.push(last ? `最近整理 ${last.run}(${(last.ms / 1000).toFixed(1)} 秒)|索引 ${last.index?.sessions ?? '?'} 个会话、${last.index?.files ?? '?'} 份日志` : '尚未整理过:先跑 refresh');
100
103
  for (const a of agents.filter(x => x.installed || x.custom)) {
101
104
  const run = last?.agents?.[a.folder];
102
- const src = !a.installed ? '未检测到' : enabled(byId(a.id), config) ? (run ? (run.ok ? `已整理 ${run.files} 个会话文件` : `整理出错:${run.error}`) : '已启用,待整理') : '已检测到,未启用整理';
103
- const skill = { ready: `技能已生效(经 ${a.via})`, missing: '技能未生效', conflict: `技能冲突:${a.conflict?.path}`, nodir: '未设技能目录' }[a.state];
105
+ const src = !a.installed ? '未检测到' : enabled(byId(a.id), config) ? (run ? (run.ok ? `${run.files} 个会话文件 · 日志 ${logDaysOf(a.folder)} 天` : `整理出错:${run.error}`) : '已启用,待整理') : '已检测到,未启用整理';
106
+ const skill = { ready: `已接入(经 ${a.via})`, missing: '待接入', conflict: `冲突:${a.conflict?.path}`, nodir: '不接入(未设技能目录)' }[a.state];
104
107
  lines.push(` ${a.name.padEnd(12)} ${src}|${skill}`);
105
108
  }
106
- for (const t of targets) lines.push(` → 在 ${t.display} 建软链可让 ${t.agents.join('、')} 生效:session-history link all`);
109
+ for (const t of targets) lines.push(` → 在 ${t.display} 建软链,${t.agents.join('、')} 即可接入:session-history link all`);
107
110
  for (const l of links) lines.push(` 软链 ${l.entry} → 数据目录(${l.agents.join('、')})`);
108
- const legacy = logFolders(home).filter(f => !byFolder(f, config));
109
- if (legacy.length) lines.push(` 已停用来源的旧日志:${legacy.join('、')}`);
111
+ // 与插件页同一口径:日志文件夹对应的 agent 不在列表里(已卸载或不再支持)。
112
+ const listed = new Set(agents.filter(x => x.installed || x.custom).map(x => x.folder));
113
+ const legacy = logFolders(home).filter(f => !listed.has(f));
114
+ if (legacy.length) lines.push(` 另有旧日志:${legacy.join('、')}(对应的 agent 已不在,日志照常检索)`);
110
115
  return lines.join('\n');
111
116
  }
112
117
 
package/client.js CHANGED
@@ -127,7 +127,7 @@ window.__ModuleLoader__.load({
127
127
  a.experimental && !a.custom ? h('span', { className: 'yxsh-badge', title: '会话格式按其公开代码推断,尚未用真实会话验证' }, '实验性') : null),
128
128
  h('div', { className: 'yxsh-src' },
129
129
  !a.enabled ? h('div', null, '未收录') : !run_ ? h('div', null, '待整理')
130
- : run_.ok ? h('div', null, `${num(run_.files)} 个会话文件 · ${num(run_.days)} 天日志`) : h('div', { className: 'yxsh-error' }, `整理出错:${run_.error}`),
130
+ : run_.ok ? h('div', { title: run_.days < a.logDays ? `其中 ${num(a.logDays - run_.days)} 天的原始会话已不在,日志照常保留` : '' }, `${num(run_.files)} 个会话文件 · 日志 ${num(a.logDays)} 天`) : h('div', { className: 'yxsh-error' }, `整理出错:${run_.error}`),
131
131
  h('div', { className: 'yxsh-muted', title: a.sessions }, a.sessions)),
132
132
  h('label', { className: 'yxsh-switch yxsh-muted', title: '关闭后不再整理它的新会话,已有日志照常检索' },
133
133
  h('input', { type: 'checkbox', checked: a.enabled, disabled: !!pending, onChange: e => run({ op: 'enable', agent: a.id, enabled: e.target.checked }, 'enable') }), '收录'),
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // DSH 宿主半边:插件页的管理接口、DSH 运行期间的定时整理、启动时生成技能文件。
2
2
  // 数据目录(默认 ~/.session-history)与插件包分开:卸载、更新、重装插件都不动日志与设置。
3
3
  import { spawn } from 'node:child_process';
4
- import { existsSync, writeFileSync } from 'node:fs';
4
+ import { existsSync, writeFileSync, readdirSync } from 'node:fs';
5
5
  import { join } from 'node:path';
6
6
  import { resolveHome, loadConfig, saveConfig, layout, readJson } from './lib/config.js';
7
7
  import { SOURCES, FORMATS, enabled, byId, allSources, customSource, folderFor } from './lib/agents.js';
@@ -86,6 +86,7 @@ export function snapshot(home, runner) {
86
86
  const run = last?.agents?.[a.folder] || null;
87
87
  return { ...a, enabled: enabled(source, config), sessions: (roots => roots.filter(isDir).map(tilde).join('、') || tilde(roots[0]))(source.locate(process.env, config.agents?.[a.id] || {}).roots),
88
88
  run: run && { ok: run.ok, files: run.files, days: run.days, error: run.error || null },
89
+ logDays: logDays(home, a.folder),
89
90
  ...(a.custom ? { def: config.custom.find(c => c.id === a.id) } : {}) };
90
91
  });
91
92
  // 只剩旧日志:日志文件夹对应的 agent 不在列表里(已卸载,或来自不再支持的来源)。新用户一般没有。
@@ -101,6 +102,12 @@ export function snapshot(home, runner) {
101
102
  };
102
103
  }
103
104
 
105
+ /** 日志里实际有的天数(含来源已删、照常保留的旧日志)。 */
106
+ function logDays(home, folder) {
107
+ const dir = join(layout(home).logs, folder);
108
+ try { return readdirSync(dir).filter(f => f.endsWith('-log.md')).length; } catch { return 0; }
109
+ }
110
+
104
111
  /** 检查自定义 agent 的会话目录:存在与否、按所选格式能找到几个会话文件。 */
105
112
  export function probe(format, sessions) {
106
113
  if (!FORMATS[format]) throw invalid('未知的会话格式');
@@ -12,7 +12,7 @@ const MACHINERY = ['<recommended_plugins>', '# AGENTS.md instructions', '<enviro
12
12
  export function locate(env = process.env) {
13
13
  const base = env.CODEX_HOME ? expand(env.CODEX_HOME) : join(home(), '.codex');
14
14
  const agents = env.AGENTS_HOME ? expand(env.AGENTS_HOME) : join(home(), '.agents');
15
- return { base, sessions: join(base, 'sessions'), roots: [join(base, 'sessions')], skills: [join(agents, 'skills'), join(base, 'skills')] };
15
+ return { base, sessions: join(base, 'sessions'), archived: join(base, 'archived_sessions'), roots: [join(base, 'sessions')], skills: [join(agents, 'skills'), join(base, 'skills')] };
16
16
  }
17
17
 
18
18
  function rollouts(root) {
@@ -33,9 +33,12 @@ function rollouts(root) {
33
33
  return out;
34
34
  }
35
35
 
36
- /** 同一会话若明文与 .zst 并存(续聊时解压回明文的间隙),取明文。 */
36
+ /** 同一会话若明文与 .zst 并存(续聊时解压回明文的间隙),取明文;另收归档目录 archived_sessions(平铺)。 */
37
37
  export function files(paths) {
38
- const all = rollouts(paths.sessions);
38
+ const archivedDir = paths.archived || join(paths.base, 'archived_sessions');
39
+ const live = rollouts(paths.sessions), names = new Set(live.map(p => basename(p).replace(/\.zst$/, '')));
40
+ const archived = entries(archivedDir).filter(d => d.name.startsWith('rollout-') && !names.has(d.name.replace(/\.zst$/, ''))).map(d => join(archivedDir, d.name));
41
+ const all = [...live, ...archived];
39
42
  const plain = new Set(all.filter(p => p.endsWith('.jsonl')));
40
43
  const zst = all.filter(p => p.endsWith('.jsonl.zst') && !plain.has(p.slice(0, -4)));
41
44
  return sortPaths([...plain, ...zst]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-history",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "把各个 agent(Claude Code、Codex 等)的对话整理成可检索的原文日志,以一个共用技能提供给所有 agent;保留原话,不做摘要,不用向量,不调用模型。",
5
5
  "author": "youxia",
6
6
  "repository": {