dsh-session-history 0.2.4 → 0.2.6
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 +2 -1
- package/bin/session-history.js +4 -1
- package/client.js +1 -1
- package/index.js +8 -1
- package/lib/skill.js +6 -4
- package/lib/sources/codex.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,6 +88,7 @@ dsh plugin --profile desktop add dsh-session-history
|
|
|
88
88
|
所有 agent 读的是同一份 `~/.session-history/SKILL.md`,由插件自动生成,手改会被覆盖。
|
|
89
89
|
|
|
90
90
|
- **通用部分**(每个人都一样):怎么检索(先找会话,再有限度地读原文,必要时查原始记录)、查询怎么写、一次回忆读多少、证据纪律。
|
|
91
|
+
- **一次回忆是一轮检索**:可以包含搜索、收窄与读取原文,通常合计控制在 3000 字符内;原文示例使用 `--budget 2000`,按剩余预算调整。索引故障时,兜底命令搜索日志目录内各来源、全部日期的 `*-log.md`。
|
|
91
92
|
- **按你的电脑生成的部分**:列出的 agent 名单(检测到的,以及只剩旧日志的)、入口的实际路径(Windows 上同时给出 PowerShell/cmd 与 Git Bash 两种写法)、`--agent` 可选的名字、是否提 Claude Code 记忆提示、Pi 的分支说明、检索前补整理的时长,以及兜底搜索用的日志路径。
|
|
92
93
|
- **什么时候更新**:插件启动时、每次整理之后(定时、检索前补整理、立即整理都算)、打开插件页时、改设置或增删 agent 时。内容没变就不写盘。建软链不会改它——软链只决定哪些 agent 能读到这份文件。
|
|
93
94
|
|
|
@@ -189,7 +190,7 @@ session-history refresh | status | setup | link all | unlink claude | config
|
|
|
189
190
|
Git 子目录地址(不提供原生更新检查):
|
|
190
191
|
|
|
191
192
|
```text
|
|
192
|
-
git+https://github.com/fujingzhai/youxia-dsh-plugins.git#dsh-session-history@0.2.
|
|
193
|
+
git+https://github.com/fujingzhai/youxia-dsh-plugins.git#dsh-session-history@0.2.6&path:/dsh-session-history
|
|
193
194
|
```
|
|
194
195
|
|
|
195
196
|
## 兼容与限制
|
package/bin/session-history.js
CHANGED
|
@@ -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,7 +102,7 @@ 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 ?
|
|
105
|
+
const src = !a.installed ? '未检测到' : enabled(byId(a.id), config) ? (run ? (run.ok ? `${run.files} 个会话文件 · 日志 ${logDaysOf(a.folder)} 天` : `整理出错:${run.error}`) : '已启用,待整理') : '已检测到,未启用整理';
|
|
103
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
|
}
|
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',
|
|
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('未知的会话格式');
|
package/lib/skill.js
CHANGED
|
@@ -53,6 +53,8 @@ export function skillMarkdown(home, { config = loadConfig(home), platform = proc
|
|
|
53
53
|
const names = active.map(s => s.name);
|
|
54
54
|
const has = id => active.some(s => s.id === id);
|
|
55
55
|
const first = active[0]?.folder || folders[0] || 'Claude';
|
|
56
|
+
const logs = layout(home).logs;
|
|
57
|
+
const fallbackRoot = platform === 'win32' ? `"${logs.replaceAll('\\', '/')}"` : shq(logs);
|
|
56
58
|
const scope = names.length
|
|
57
59
|
? `${list(names)}${legacy.length ? `,以及已停用的 ${list(legacy)}(旧日志照常检索)` : ''}`
|
|
58
60
|
: legacy.length ? `已停用的 ${list(legacy)}(只剩旧日志)` : '各 agent(尚未检测到会话来源)';
|
|
@@ -60,7 +62,7 @@ export function skillMarkdown(home, { config = loadConfig(home), platform = proc
|
|
|
60
62
|
const lines = [
|
|
61
63
|
'---',
|
|
62
64
|
`name: ${SKILL_NAME}`,
|
|
63
|
-
`description: 查各 agent(${list(names.length ? names : legacy) || '各家'}
|
|
65
|
+
`description: 查各 agent(${list(names.length ? names : legacy) || '各家'})的历史对话。用户提起过往,或提到你不清楚来由的事时使用;上下文和记忆里能找到就不查,同一件事每个会话一般只回忆一轮。`,
|
|
64
66
|
'---',
|
|
65
67
|
'',
|
|
66
68
|
'# Session History',
|
|
@@ -69,7 +71,7 @@ export function skillMarkdown(home, { config = loadConfig(home), platform = proc
|
|
|
69
71
|
'',
|
|
70
72
|
'## 先定位会话,再有限度地读',
|
|
71
73
|
'',
|
|
72
|
-
'一次回忆一般 **2–3 次调用、合计 ≤3000
|
|
74
|
+
'一次回忆一般 **2–3 次调用、合计 ≤3000 字符**。不要一上来调大 `--budget` 或加 `--snippets`,不要逐个 get 碰运气,不要 rg 扫日志或整读日志文件(索引报错除外)。',
|
|
73
75
|
'',
|
|
74
76
|
`**1. search 找会话**:查询词=**主体词+事件词**,如 \`${cmd} search 插件 更新失败\`、\`${cmd} search "VPN|openconnect" 断线 --agent ${first} --since 08-01\`;只给主体词必然过宽。`,
|
|
75
77
|
'',
|
|
@@ -80,7 +82,7 @@ export function skillMarkdown(home, { config = loadConfig(home), platform = proc
|
|
|
80
82
|
'',
|
|
81
83
|
`**2. 会话内定位**:\`${cmd} search 更新失败 --session 01a06cc6\` 按时间列该会话命中块;或 \`${cmd} outline 01a06cc6\` 看用户每条发言+末轮回复(\`--all\` 含助手发言)。会话 ID 给前缀即可,outline 也收块 ID。`,
|
|
82
84
|
'',
|
|
83
|
-
`**3. 读原文**:\`${cmd} get 2ddbae3eed --context 1\`,块 ID 至少 6
|
|
85
|
+
`**3. 读原文**:\`${cmd} get 2ddbae3eed --context 1 --budget 2000\`,块 ID 至少 6 位;按剩余预算调整 \`--budget\`(命令默认 4000 字符)。仍不够就按首行路径和行号局部读日志文件。`,
|
|
84
86
|
'',
|
|
85
87
|
`**4. 查原始记录**:接口名、参数、命令、报错原文多只在工具调用与返回里,日志搜不到。在日志里搜两次仍无,就对候选会话 \`${cmd} raw 5f3c92de "base_url|api.example"\`(含思考与工具往来,默认 2000 字符),别再换词连搜。只有${names.length ? `在用的 ${list(names)} ` : '在用的来源'}有原始记录${legacy.length ? ',已停用的没有' : ''}。`,
|
|
86
88
|
'',
|
|
@@ -97,7 +99,7 @@ export function skillMarkdown(home, { config = loadConfig(home), platform = proc
|
|
|
97
99
|
'',
|
|
98
100
|
'## 索引与兜底',
|
|
99
101
|
'',
|
|
100
|
-
`每次命令自动增量更新索引${config.staleMinutes ? `;距上次整理超过 ${config.staleMinutes} 分钟会先补整理(只重读变过的会话,通常几秒)` : ''}。要查刚刚的对话可先跑一次 \`${cmd} refresh
|
|
102
|
+
`每次命令自动增量更新索引${config.staleMinutes ? `;距上次整理超过 ${config.staleMinutes} 分钟会先补整理(只重读变过的会话,通常几秒)` : ''}。要查刚刚的对话可先跑一次 \`${cmd} refresh\`,别反复跑。依赖或索引报错时别当无命中:先报告,再按日志路径兜底(兼顾繁简,覆盖各 agent、全部日期的日志):\`rg -n -m 5 -g "*-log.md" "关键词|關鍵詞" ${fallbackRoot}\``,
|
|
101
103
|
'',
|
|
102
104
|
'除非用户要求维护本技能,不改日志正文。本文件由 Session History 按检测到的 agent 自动生成,手改会被覆盖。',
|
|
103
105
|
'',
|
package/lib/sources/codex.js
CHANGED
|
@@ -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
|
|
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]);
|