opencode-prompt-recorder 1.3.7 → 1.3.9
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 +32 -34
- package/dist/index.js +17 -9
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,43 +30,41 @@ bun add -g opencode-prompt-recorder
|
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
## 工作原理
|
|
34
|
-
|
|
35
|
-
1. 插件监听 OpenCode
|
|
36
|
-
2. 每次用户消息时,提取提示词文本和会话 ID
|
|
37
|
-
3. 提示词保存到 `.agent/prompts/` 目录,按日期组织
|
|
38
|
-
4. 每个提示词保存为带有时间戳和会话信息的 markdown 文件
|
|
33
|
+
## 工作原理
|
|
34
|
+
|
|
35
|
+
1. 插件监听 OpenCode 消息事件(`message.updated` 和 `message.part.updated`)
|
|
36
|
+
2. 每次用户消息时,提取提示词文本和会话 ID
|
|
37
|
+
3. 提示词保存到 `.agent/prompts/` 目录,按日期组织
|
|
38
|
+
4. 每个提示词保存为带有时间戳和会话信息的 markdown 文件
|
|
39
39
|
|
|
40
40
|
## 文件结构
|
|
41
41
|
|
|
42
42
|
插件创建有组织的目录结构:
|
|
43
43
|
|
|
44
|
-
```
|
|
45
|
-
.agent/
|
|
46
|
-
└── prompts/
|
|
47
|
-
└── 2026/
|
|
48
|
-
└──
|
|
49
|
-
└──
|
|
50
|
-
├──
|
|
51
|
-
├──
|
|
52
|
-
└── 1120-
|
|
53
|
-
```
|
|
44
|
+
```
|
|
45
|
+
.agent/
|
|
46
|
+
└── prompts/
|
|
47
|
+
└── 2026/
|
|
48
|
+
└── 03/
|
|
49
|
+
└── 04/
|
|
50
|
+
├── 20260304-0943-ses_abc123-什么是AI.md
|
|
51
|
+
├── 20260304-1005-ses_def456-如何编程.md
|
|
52
|
+
└── 20260304-1120-ses_ghi789-复制README.md
|
|
53
|
+
```
|
|
54
54
|
|
|
55
55
|
## 文件格式
|
|
56
56
|
|
|
57
57
|
每个提示词文件遵循以下格式:
|
|
58
58
|
|
|
59
|
-
```markdown
|
|
60
|
-
============ 10:05 ============
|
|
61
|
-
|
|
62
|
-
什么是 AI?
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
如何编写 hello world 程序?
|
|
69
|
-
```
|
|
59
|
+
```markdown
|
|
60
|
+
============ 10:05 ============
|
|
61
|
+
|
|
62
|
+
什么是 AI?
|
|
63
|
+
|
|
64
|
+
============ 10:50 ============
|
|
65
|
+
|
|
66
|
+
如何编写 hello world 程序?
|
|
67
|
+
```
|
|
70
68
|
|
|
71
69
|
## 配置
|
|
72
70
|
|
|
@@ -76,13 +74,13 @@ bun add -g opencode-prompt-recorder
|
|
|
76
74
|
- 使用当前工作目录作为基础路径
|
|
77
75
|
- 根据需要创建目录
|
|
78
76
|
|
|
79
|
-
## 会话管理
|
|
80
|
-
|
|
81
|
-
- 每个唯一的 `sessionId` 获得自己的文件
|
|
82
|
-
- 相同的会话 ID 追加到现有文件
|
|
83
|
-
- 不同的会话 ID 创建新文件
|
|
84
|
-
- 会话 ID 来自 `
|
|
85
|
-
- 跨天合并:无论何时,只要 sessionId 相同,都会追加到同一文件(自动搜索所有日期目录)
|
|
77
|
+
## 会话管理
|
|
78
|
+
|
|
79
|
+
- 每个唯一的 `sessionId` 获得自己的文件
|
|
80
|
+
- 相同的会话 ID 追加到现有文件
|
|
81
|
+
- 不同的会话 ID 创建新文件
|
|
82
|
+
- 会话 ID 来自 `message.part.updated` 事件输入
|
|
83
|
+
- 跨天合并:无论何时,只要 sessionId 相同,都会追加到同一文件(自动搜索所有日期目录)
|
|
86
84
|
|
|
87
85
|
## 使用场景
|
|
88
86
|
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,6 @@ import { mkdir, appendFile, readdir, writeFile, readFile } from "fs/promises";
|
|
|
3
3
|
import { join, dirname } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
-
async function getVersion() {
|
|
7
|
-
try {
|
|
8
|
-
const packageJson = JSON.parse(await readFile(join(__dirname, "package.json"), "utf-8"));
|
|
9
|
-
return packageJson.version;
|
|
10
|
-
} catch {
|
|
11
|
-
return "unknown";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
6
|
async function debugLog(directory, msg) {
|
|
15
7
|
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
16
8
|
const logLine = `[${time}] ${msg}
|
|
@@ -23,6 +15,14 @@ async function debugLog(directory, msg) {
|
|
|
23
15
|
console.error("debugLog failed:", e);
|
|
24
16
|
}
|
|
25
17
|
}
|
|
18
|
+
async function getVersion() {
|
|
19
|
+
try {
|
|
20
|
+
const packageJson = JSON.parse(await readFile(join(__dirname, "package.json"), "utf-8"));
|
|
21
|
+
return packageJson.version;
|
|
22
|
+
} catch {
|
|
23
|
+
return "unknown";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
26
|
function sanitizeFilename(str) {
|
|
27
27
|
return str.replace(/[<>:"/\\|?*\x00-\x1f]/g, "").substring(0, 50).trim();
|
|
28
28
|
}
|
|
@@ -68,6 +68,7 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
|
|
|
68
68
|
let versionFileWritten = false;
|
|
69
69
|
let lastProcessedMessageCount = 0;
|
|
70
70
|
const messageRoleMap = /* @__PURE__ */ new Map();
|
|
71
|
+
const processedMessageIds = /* @__PURE__ */ new Set();
|
|
71
72
|
return {
|
|
72
73
|
"event": async ({ event }) => {
|
|
73
74
|
if (event.type === "message.updated") {
|
|
@@ -96,10 +97,13 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
|
|
|
96
97
|
if (!role) {
|
|
97
98
|
await debugLog(directory, `[prompt-recorder] WARNING: role not found, messageID=${messageID}, sessionID=${sessionID}, textPreview=${text2.substring(0, 30)}`);
|
|
98
99
|
} else if (role === "user" && text2 && sessionID) {
|
|
100
|
+
if (processedMessageIds.has(messageID)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
processedMessageIds.add(messageID);
|
|
99
104
|
await debugLog(directory, `[prompt-recorder] event=${event.type}, role=${role}, sessionID=${sessionID}, textLength=${text2.length}, textPreview=${text2.substring(0, 50)}`);
|
|
100
105
|
const now2 = /* @__PURE__ */ new Date();
|
|
101
106
|
const { yyyy: yyyy2, MM: MM2, dd: dd2, HH: HH2, mm: mm2 } = formatDate(now2);
|
|
102
|
-
const topic2 = sanitizeFilename(text2);
|
|
103
107
|
const promptDir2 = join(directory, ".agent", "prompts", yyyy2, MM2, dd2);
|
|
104
108
|
await mkdir(promptDir2, { recursive: true });
|
|
105
109
|
const existingFile2 = await findExistingFile(directory, sessionID);
|
|
@@ -116,6 +120,7 @@ ${text2}`;
|
|
|
116
120
|
if (existingFile2) {
|
|
117
121
|
await appendFile(existingFile2, fileContent2);
|
|
118
122
|
} else {
|
|
123
|
+
const topic2 = sanitizeFilename(text2);
|
|
119
124
|
const filename = `${dateStr2}-${HH2}${mm2}-${sessionID}-${topic2}.md`;
|
|
120
125
|
const filepath = join(promptDir2, filename);
|
|
121
126
|
await appendFile(filepath, fileContent2);
|
|
@@ -126,6 +131,9 @@ ${text2}`;
|
|
|
126
131
|
if (event.type !== "session.updated") {
|
|
127
132
|
return;
|
|
128
133
|
}
|
|
134
|
+
await client?.app?.log?.({
|
|
135
|
+
body: { service: "prompt-recorder", level: "debug", message: "\u6536\u5230 session.updated \u4E8B\u4EF6", extra: { eventType: event.type } }
|
|
136
|
+
});
|
|
129
137
|
const messages = event.properties.info.messages;
|
|
130
138
|
const messageCount = messages.length;
|
|
131
139
|
if (!versionFileWritten) {
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-prompt-recorder",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "OpenCode plugin for recording user prompts. Automatically saves user messages to a local file system with organized directory structure.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-prompt-recorder",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "OpenCode plugin for recording user prompts. Automatically saves user messages to a local file system with organized directory structure.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|