opencode-prompt-recorder 1.3.7 → 1.3.8
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 +17 -9
- package/dist/package.json +1 -1
- package/package.json +1 -1
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.8",
|
|
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.8",
|
|
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",
|