opencode-prompt-recorder 1.3.6 → 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 +25 -2
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,6 +3,18 @@ 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 debugLog(directory, msg) {
|
|
7
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
8
|
+
const logLine = `[${time}] ${msg}
|
|
9
|
+
`;
|
|
10
|
+
try {
|
|
11
|
+
const logDir = join(directory, ".agent", "prompts-log");
|
|
12
|
+
await mkdir(logDir, { recursive: true });
|
|
13
|
+
await appendFile(join(logDir, "log.txt"), logLine);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
console.error("debugLog failed:", e);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
6
18
|
async function getVersion() {
|
|
7
19
|
try {
|
|
8
20
|
const packageJson = JSON.parse(await readFile(join(__dirname, "package.json"), "utf-8"));
|
|
@@ -56,6 +68,7 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
|
|
|
56
68
|
let versionFileWritten = false;
|
|
57
69
|
let lastProcessedMessageCount = 0;
|
|
58
70
|
const messageRoleMap = /* @__PURE__ */ new Map();
|
|
71
|
+
const processedMessageIds = /* @__PURE__ */ new Set();
|
|
59
72
|
return {
|
|
60
73
|
"event": async ({ event }) => {
|
|
61
74
|
if (event.type === "message.updated") {
|
|
@@ -81,10 +94,16 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
|
|
|
81
94
|
if (!role) {
|
|
82
95
|
role = event.properties.info?.message?.role;
|
|
83
96
|
}
|
|
84
|
-
if (role
|
|
97
|
+
if (!role) {
|
|
98
|
+
await debugLog(directory, `[prompt-recorder] WARNING: role not found, messageID=${messageID}, sessionID=${sessionID}, textPreview=${text2.substring(0, 30)}`);
|
|
99
|
+
} else if (role === "user" && text2 && sessionID) {
|
|
100
|
+
if (processedMessageIds.has(messageID)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
processedMessageIds.add(messageID);
|
|
104
|
+
await debugLog(directory, `[prompt-recorder] event=${event.type}, role=${role}, sessionID=${sessionID}, textLength=${text2.length}, textPreview=${text2.substring(0, 50)}`);
|
|
85
105
|
const now2 = /* @__PURE__ */ new Date();
|
|
86
106
|
const { yyyy: yyyy2, MM: MM2, dd: dd2, HH: HH2, mm: mm2 } = formatDate(now2);
|
|
87
|
-
const topic2 = sanitizeFilename(text2);
|
|
88
107
|
const promptDir2 = join(directory, ".agent", "prompts", yyyy2, MM2, dd2);
|
|
89
108
|
await mkdir(promptDir2, { recursive: true });
|
|
90
109
|
const existingFile2 = await findExistingFile(directory, sessionID);
|
|
@@ -101,6 +120,7 @@ ${text2}`;
|
|
|
101
120
|
if (existingFile2) {
|
|
102
121
|
await appendFile(existingFile2, fileContent2);
|
|
103
122
|
} else {
|
|
123
|
+
const topic2 = sanitizeFilename(text2);
|
|
104
124
|
const filename = `${dateStr2}-${HH2}${mm2}-${sessionID}-${topic2}.md`;
|
|
105
125
|
const filepath = join(promptDir2, filename);
|
|
106
126
|
await appendFile(filepath, fileContent2);
|
|
@@ -111,6 +131,9 @@ ${text2}`;
|
|
|
111
131
|
if (event.type !== "session.updated") {
|
|
112
132
|
return;
|
|
113
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
|
+
});
|
|
114
137
|
const messages = event.properties.info.messages;
|
|
115
138
|
const messageCount = messages.length;
|
|
116
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",
|