opencode-prompt-recorder 1.3.8 → 1.4.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 CHANGED
@@ -30,43 +30,41 @@ bun add -g opencode-prompt-recorder
30
30
  }
31
31
  ```
32
32
 
33
- ## 工作原理
34
-
35
- 1. 插件监听 OpenCode 聊天事件(`chat.message`)
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
- └── 02/
49
- └── 22/
50
- ├── 1005-abc123-什么是AI.md
51
- ├── 1050-def456-如何编程.md
52
- └── 1120-ghi789-复制README.md
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
- ============ 10:50 ============
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 来自 `chat.message` 事件输入
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
@@ -68,7 +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
+ const processedMessageKeys = /* @__PURE__ */ new Set();
72
72
  return {
73
73
  "event": async ({ event }) => {
74
74
  if (event.type === "message.updated") {
@@ -80,6 +80,8 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
80
80
  }
81
81
  if (event.type === "message.part.updated") {
82
82
  const part = event.properties.part;
83
+ const props = event.properties;
84
+ await debugLog(directory, `[prompt-recorder] message.part.updated: type=${part?.type}, messageID=${part?.messageID}, sessionID=${part?.sessionID}, info.role=${props.info?.role}, info.message.role=${props.info?.message?.role}`);
83
85
  if (part?.type === "text" && part?.text) {
84
86
  const sessionID = part.sessionID;
85
87
  const messageID = part.messageID;
@@ -97,10 +99,11 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
97
99
  if (!role) {
98
100
  await debugLog(directory, `[prompt-recorder] WARNING: role not found, messageID=${messageID}, sessionID=${sessionID}, textPreview=${text2.substring(0, 30)}`);
99
101
  } else if (role === "user" && text2 && sessionID) {
100
- if (processedMessageIds.has(messageID)) {
102
+ const dedupeKey = `${messageID}:${text2}`;
103
+ if (processedMessageKeys.has(dedupeKey)) {
101
104
  return;
102
105
  }
103
- processedMessageIds.add(messageID);
106
+ processedMessageKeys.add(dedupeKey);
104
107
  await debugLog(directory, `[prompt-recorder] event=${event.type}, role=${role}, sessionID=${sessionID}, textLength=${text2.length}, textPreview=${text2.substring(0, 50)}`);
105
108
  const now2 = /* @__PURE__ */ new Date();
106
109
  const { yyyy: yyyy2, MM: MM2, dd: dd2, HH: HH2, mm: mm2 } = formatDate(now2);
@@ -131,11 +134,11 @@ ${text2}`;
131
134
  if (event.type !== "session.updated") {
132
135
  return;
133
136
  }
134
- await client?.app?.log?.({
135
- body: { service: "prompt-recorder", level: "debug", message: "\u6536\u5230 session.updated \u4E8B\u4EF6", extra: { eventType: event.type } }
136
- });
137
- const messages = event.properties.info.messages;
137
+ const sessionInfo = event.properties.info;
138
+ const sessionId = sessionInfo?.id;
139
+ const messages = sessionInfo?.messages || [];
138
140
  const messageCount = messages.length;
141
+ await debugLog(directory, `[prompt-recorder] session.updated: sessionId=${sessionId}, messageCount=${messageCount}, lastProcessed=${lastProcessedMessageCount}`);
139
142
  if (!versionFileWritten) {
140
143
  try {
141
144
  const version = await getVersion();
@@ -170,7 +173,6 @@ ${text2}`;
170
173
  return;
171
174
  }
172
175
  const text = latestMessage.parts.map((p) => p.type === "text" ? p.text : "").join("");
173
- const sessionId = event.properties.info.id;
174
176
  if (!text || !sessionId) {
175
177
  return;
176
178
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-prompt-recorder",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
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.8",
3
+ "version": "1.4.0",
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",