dsh-session-history 0.1.0 → 0.2.0
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 +97 -53
- package/bin/session-history.js +22 -14
- package/client.js +207 -97
- package/icon.svg +5 -7
- package/index.js +55 -15
- package/lib/agents.js +61 -7
- package/lib/config.js +18 -3
- package/lib/links.js +105 -58
- package/lib/raw.js +15 -6
- package/lib/refresh.js +2 -2
- package/lib/skill.js +6 -6
- package/lib/sources/antigravity.js +3 -3
- package/lib/sources/claude.js +2 -2
- package/lib/sources/codex.js +2 -2
- package/lib/sources/dsh.js +2 -2
- package/lib/sources/lobsterai.js +142 -0
- package/lib/sources/pi.js +2 -2
- package/lib/sources/workbuddy.js +98 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// WorkBuddy(腾讯,内核是 CodeBuddy Code):~/.workbuddy/projects/<项目>/<会话>.jsonl。
|
|
2
|
+
// 实验性:格式按 CodeBuddy Code 公开发布的代码推断(OpenAI Agents 式的 message 条目、custom-title/ai-title 标题),
|
|
3
|
+
// 未用真实会话验证;时间戳缺失时沿用前后条目的时刻,不丢消息。同格式的 CodeBuddy Code 可作为自定义 agent 添加。
|
|
4
|
+
import { basename, join } from 'node:path';
|
|
5
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
6
|
+
import { home, expand, filesTwoDeep } from '../files.js';
|
|
7
|
+
import { jsonLines, parseJson, sortPaths, strip, isObject } from '../py.js';
|
|
8
|
+
import { tidy } from '../markdown.js';
|
|
9
|
+
import { renderDays, excluded, str } from './common.js';
|
|
10
|
+
import { toMs } from '../clock.js';
|
|
11
|
+
|
|
12
|
+
const INJECT = ['<system-reminder', '<turn_aborted>', '<command-', '<local-command-', 'Caveat:', '<user-memory', 'Base directory for this skill:'];
|
|
13
|
+
const machinery = text => !text || INJECT.some(p => text.startsWith(p)) || text.startsWith('[Request interrupted');
|
|
14
|
+
|
|
15
|
+
export function locate(env = process.env) {
|
|
16
|
+
const base = env.WORKBUDDY_HOME ? expand(env.WORKBUDDY_HOME) : join(home(), '.workbuddy');
|
|
17
|
+
return { base, projects: join(base, 'projects'), roots: [join(base, 'projects')], marks: [base], skills: [join(base, 'skills')] };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function files(paths) {
|
|
21
|
+
return sortPaths(filesTwoDeep(paths.projects, name => name.endsWith('.jsonl')));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 条目自身或 providerData 带的时刻;毫秒数或 ISO 都行。 */
|
|
25
|
+
function stamp(e) {
|
|
26
|
+
for (const v of [e.timestamp, e.createdAt, e.created_at, e.providerData?.timestamp]) {
|
|
27
|
+
const ms = toMs(v);
|
|
28
|
+
if (Number.isFinite(ms) && ms > 0) return ms;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const skipped = p => !!(p && (p.isMeta || p.skipRun || p.isCompactInternal || p.isCompacted || p.isSummary || typeof p.compactType === 'string' || p.teammateMessage));
|
|
34
|
+
|
|
35
|
+
function text(content, role) {
|
|
36
|
+
if (typeof content === 'string') return machinery(strip(content)) ? '' : strip(content);
|
|
37
|
+
if (!Array.isArray(content)) return '';
|
|
38
|
+
const pieces = [];
|
|
39
|
+
for (const b of content) {
|
|
40
|
+
if (!isObject(b)) continue;
|
|
41
|
+
if (['input_text', 'output_text', 'text'].includes(b.type)) { const t = strip(str(b.text)); if (!machinery(t)) pieces.push(t); }
|
|
42
|
+
else if (['input_image', 'image'].includes(b.type)) pieces.push(role === 'user' ? '[🖼️ 图片]' : '[🖼️ 已生成图片]');
|
|
43
|
+
else if (['input_file', 'file', 'document'].includes(b.type)) { const n = b.filename || b.name || ''; pieces.push(n ? `[📎 附件: ${n}]` : '[📎 附件]'); }
|
|
44
|
+
}
|
|
45
|
+
return pieces.join('\n\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function parse(path) {
|
|
49
|
+
const pending = [], stamps = [], turns = [];
|
|
50
|
+
let custom = null, ai = null, cwd = '', index = 0;
|
|
51
|
+
for (const line of jsonLines(readFileSync(path, 'utf8'))) {
|
|
52
|
+
if (!strip(line)) continue;
|
|
53
|
+
const e = parseJson(line);
|
|
54
|
+
if (!isObject(e)) continue;
|
|
55
|
+
index++;
|
|
56
|
+
if (!cwd && typeof e.cwd === 'string') cwd = e.cwd;
|
|
57
|
+
const ms = stamp(e);
|
|
58
|
+
if (ms) stamps.push([index, ms]);
|
|
59
|
+
if (e.type === 'custom-title' && e.customTitle) custom = e.customTitle;
|
|
60
|
+
if (e.type === 'ai-title' && e.aiTitle) ai = e.aiTitle;
|
|
61
|
+
if (e.type !== 'message' || !['user', 'assistant'].includes(e.role) || skipped(e.providerData)) continue;
|
|
62
|
+
const t = text(e.content, e.role);
|
|
63
|
+
if (t) pending.push([ms, e.role, t, index]);
|
|
64
|
+
}
|
|
65
|
+
// 没带时刻的条目:取其后最近一条(任何类型)的时刻;后面没有就取前面最近的;都没有用文件修改时间。
|
|
66
|
+
let mtime = null;
|
|
67
|
+
try { mtime = statSync(path).mtimeMs; } catch { /* 无 */ }
|
|
68
|
+
for (const p of pending) {
|
|
69
|
+
if (p[0]) continue;
|
|
70
|
+
const after = stamps.find(([i]) => i > p[3]);
|
|
71
|
+
const before = [...stamps].reverse().find(([i]) => i < p[3]);
|
|
72
|
+
p[0] = after?.[1] ?? before?.[1] ?? mtime;
|
|
73
|
+
}
|
|
74
|
+
for (const [ms, role, t] of pending) if (ms) turns.push([new Date(ms).toISOString(), role, t]);
|
|
75
|
+
return { sid: basename(path, '.jsonl').slice(0, 8), cwd, turns, custom, ai };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function build(entries, options = {}) {
|
|
79
|
+
const all = [], titles = {};
|
|
80
|
+
for (const { data } of entries) {
|
|
81
|
+
if (excluded(data.cwd, options.excludeCwds)) continue;
|
|
82
|
+
if (!data.turns.length) continue;
|
|
83
|
+
const title = tidy(data.custom) || tidy(data.ai);
|
|
84
|
+
if (title) titles[data.sid] = title;
|
|
85
|
+
for (const [ts, role, t] of data.turns) all.push([ts, role, t, data.sid]);
|
|
86
|
+
}
|
|
87
|
+
return { turns: all, titles, count: all.length };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function render(all, clock, userLabel, name = 'WorkBuddy') {
|
|
91
|
+
return renderDays(all, clock, { user: `🧑 ${userLabel}`, assistant: `🤖 ${name}` });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function rawFiles(paths, key) {
|
|
95
|
+
return files(paths).filter(p => basename(p).startsWith(key));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default { id: 'workbuddy', folder: 'WorkBuddy', name: 'WorkBuddy', experimental: true, version: 1, locate, files, parse, build, render, rawFiles };
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Session History",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "Turns conversations from your agents (Claude Code, Codex and others) into searchable verbatim logs, shared with every agent as one skill so each can look up what was said elsewhere. Original wording kept: no summaries, no embeddings, no model calls."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Session History",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "把各个 agent(Claude Code、Codex 等)的对话整理成可检索的原文日志,以一个共用技能提供给所有 agent,让它们能查到彼此聊过什么。保留原话,不做摘要,不用向量,不调用模型。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-history",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "把各个 agent(Claude Code、Codex 等)的对话整理成可检索的原文日志,以一个共用技能提供给所有 agent;保留原话,不做摘要,不用向量,不调用模型。",
|
|
5
5
|
"author": "youxia",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|