opencode-prompt-recorder 1.3.9 → 1.5.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/dist/index.js +26 -77
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -64,11 +64,9 @@ async function findExistingFile(directory, sessionId) {
|
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
66
|
var OpenCodePromptRecorder = async ({ directory, client }) => {
|
|
67
|
-
let lastUserMessage = "";
|
|
68
67
|
let versionFileWritten = false;
|
|
69
|
-
let lastProcessedMessageCount = 0;
|
|
70
68
|
const messageRoleMap = /* @__PURE__ */ new Map();
|
|
71
|
-
const
|
|
69
|
+
const processedMessageKeys = /* @__PURE__ */ new Set();
|
|
72
70
|
return {
|
|
73
71
|
"event": async ({ event }) => {
|
|
74
72
|
if (event.type === "message.updated") {
|
|
@@ -83,7 +81,7 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
|
|
|
83
81
|
if (part?.type === "text" && part?.text) {
|
|
84
82
|
const sessionID = part.sessionID;
|
|
85
83
|
const messageID = part.messageID;
|
|
86
|
-
const
|
|
84
|
+
const text = part.text;
|
|
87
85
|
let role = messageRoleMap.get(messageID);
|
|
88
86
|
if (!role) {
|
|
89
87
|
role = part.message?.role;
|
|
@@ -94,49 +92,40 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
|
|
|
94
92
|
if (!role) {
|
|
95
93
|
role = event.properties.info?.message?.role;
|
|
96
94
|
}
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (processedMessageIds.has(messageID)) {
|
|
95
|
+
if (role === "user" && text && sessionID) {
|
|
96
|
+
const dedupeKey = `${messageID}:${text}`;
|
|
97
|
+
if (processedMessageKeys.has(dedupeKey)) {
|
|
101
98
|
return;
|
|
102
99
|
}
|
|
103
|
-
|
|
104
|
-
await debugLog(directory, `[prompt-recorder] event=${event.type}, role=${role}, sessionID=${sessionID}, textLength=${
|
|
105
|
-
const
|
|
106
|
-
const { yyyy
|
|
107
|
-
const
|
|
108
|
-
await mkdir(
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
100
|
+
processedMessageKeys.add(dedupeKey);
|
|
101
|
+
await debugLog(directory, `[prompt-recorder] event=${event.type}, role=${role}, sessionID=${sessionID}, textLength=${text.length}, textPreview=${text.substring(0, 50)}`);
|
|
102
|
+
const now = /* @__PURE__ */ new Date();
|
|
103
|
+
const { yyyy, MM, dd, HH, mm } = formatDate(now);
|
|
104
|
+
const promptDir = join(directory, ".agent", "prompts", yyyy, MM, dd);
|
|
105
|
+
await mkdir(promptDir, { recursive: true });
|
|
106
|
+
const existingFile = await findExistingFile(directory, sessionID);
|
|
107
|
+
const time = formatTime(now);
|
|
108
|
+
const dateStr = `${yyyy}${MM}${dd}`;
|
|
109
|
+
const timeTitle = `============ ${time} ============`;
|
|
110
|
+
const fileContent = existingFile ? `
|
|
114
111
|
|
|
115
|
-
${
|
|
112
|
+
${timeTitle}
|
|
116
113
|
|
|
117
|
-
${
|
|
114
|
+
${text}` : `${timeTitle}
|
|
118
115
|
|
|
119
|
-
${
|
|
120
|
-
if (
|
|
121
|
-
await appendFile(
|
|
116
|
+
${text}`;
|
|
117
|
+
if (existingFile) {
|
|
118
|
+
await appendFile(existingFile, fileContent);
|
|
122
119
|
} else {
|
|
123
|
-
const
|
|
124
|
-
const filename = `${
|
|
125
|
-
const filepath = join(
|
|
126
|
-
await appendFile(filepath,
|
|
120
|
+
const topic = sanitizeFilename(text);
|
|
121
|
+
const filename = `${dateStr}-${HH}${mm}-${sessionID}-${topic}.md`;
|
|
122
|
+
const filepath = join(promptDir, filename);
|
|
123
|
+
await appendFile(filepath, fileContent);
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
|
-
if (event.type
|
|
132
|
-
return;
|
|
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
|
-
});
|
|
137
|
-
const messages = event.properties.info.messages;
|
|
138
|
-
const messageCount = messages.length;
|
|
139
|
-
if (!versionFileWritten) {
|
|
128
|
+
if (event.type === "session.updated" && !versionFileWritten) {
|
|
140
129
|
try {
|
|
141
130
|
const version = await getVersion();
|
|
142
131
|
const readmeDir = join(directory, ".agent");
|
|
@@ -162,46 +151,6 @@ ${text2}`;
|
|
|
162
151
|
} catch (e) {
|
|
163
152
|
}
|
|
164
153
|
}
|
|
165
|
-
if (messageCount <= lastProcessedMessageCount) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const latestMessage = messages[messages.length - 1];
|
|
169
|
-
if (latestMessage?.role !== "user") {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const text = latestMessage.parts.map((p) => p.type === "text" ? p.text : "").join("");
|
|
173
|
-
const sessionId = event.properties.info.id;
|
|
174
|
-
if (!text || !sessionId) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (text === lastUserMessage) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const now = /* @__PURE__ */ new Date();
|
|
181
|
-
const { yyyy, MM, dd, HH, mm } = formatDate(now);
|
|
182
|
-
const topic = sanitizeFilename(text);
|
|
183
|
-
const promptDir = join(directory, ".agent", "prompts", yyyy, MM, dd);
|
|
184
|
-
await mkdir(promptDir, { recursive: true });
|
|
185
|
-
const existingFile = await findExistingFile(directory, sessionId);
|
|
186
|
-
const time = formatTime(now);
|
|
187
|
-
const dateStr = `${yyyy}${MM}${dd}`;
|
|
188
|
-
const timeTitle = `============ ${time} ============`;
|
|
189
|
-
const fileContent = existingFile ? `
|
|
190
|
-
|
|
191
|
-
${timeTitle}
|
|
192
|
-
|
|
193
|
-
${text}` : `${timeTitle}
|
|
194
|
-
|
|
195
|
-
${text}`;
|
|
196
|
-
if (existingFile) {
|
|
197
|
-
await appendFile(existingFile, fileContent);
|
|
198
|
-
} else {
|
|
199
|
-
const filename = `${dateStr}-${HH}${mm}-${sessionId}-${topic}.md`;
|
|
200
|
-
const filepath = join(promptDir, filename);
|
|
201
|
-
await appendFile(filepath, fileContent);
|
|
202
|
-
}
|
|
203
|
-
lastUserMessage = text;
|
|
204
|
-
lastProcessedMessageCount = messageCount;
|
|
205
154
|
}
|
|
206
155
|
};
|
|
207
156
|
};
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-prompt-recorder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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
|
+
"version": "1.5.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",
|