opencode-prompt-recorder 1.3.4 → 1.3.5

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 CHANGED
@@ -2,15 +2,25 @@
2
2
  import { mkdir, appendFile, readdir, writeFile, readFile } from "fs/promises";
3
3
  import { join, dirname } from "path";
4
4
  import { fileURLToPath } from "url";
5
- var __dirname2 = dirname(fileURLToPath(import.meta.url));
5
+ var __dirname = dirname(fileURLToPath(import.meta.url));
6
6
  async function getVersion() {
7
7
  try {
8
- const packageJson = JSON.parse(await readFile(join(__dirname2, "package.json"), "utf-8"));
8
+ const packageJson = JSON.parse(await readFile(join(__dirname, "package.json"), "utf-8"));
9
9
  return packageJson.version;
10
10
  } catch {
11
11
  return "unknown";
12
12
  }
13
13
  }
14
+ function getLastUpdateTime() {
15
+ const now = /* @__PURE__ */ new Date();
16
+ const yyyy = now.getFullYear();
17
+ const MM = String(now.getMonth() + 1).padStart(2, "0");
18
+ const dd = String(now.getDate()).padStart(2, "0");
19
+ const HH = String(now.getHours()).padStart(2, "0");
20
+ const mm = String(now.getMinutes()).padStart(2, "0");
21
+ const ss = String(now.getSeconds()).padStart(2, "0");
22
+ return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`;
23
+ }
14
24
  function sanitizeFilename(str) {
15
25
  return str.replace(/[<>:"/\\|?*\x00-\x1f]/g, "").substring(0, 50).trim();
16
26
  }
@@ -26,8 +36,7 @@ function formatTime(date) {
26
36
  return `${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`;
27
37
  }
28
38
  async function findExistingFile(directory, sessionId) {
29
- if (!sessionId)
30
- return null;
39
+ if (!sessionId) return null;
31
40
  const promptsBaseDir = join(directory, ".agent", "prompts");
32
41
  try {
33
42
  const years = await readdir(promptsBaseDir);
@@ -48,40 +57,46 @@ async function findExistingFile(directory, sessionId) {
48
57
  }
49
58
  }
50
59
  }
51
- } catch {}
60
+ } catch {
61
+ }
52
62
  return null;
53
63
  }
54
64
  var OpenCodePromptRecorder = async ({ directory, client: _client }) => {
55
65
  let lastUserMessage = "";
56
66
  let versionFileWritten = false;
57
67
  return {
68
+ // 使用 chat.message 事件监听用户消息(来自 SDK 类型定义)
58
69
  "chat.message": async (input, output) => {
59
70
  if (!versionFileWritten) {
60
71
  try {
61
72
  const version = await getVersion();
73
+ const lastUpdate = getLastUpdateTime();
62
74
  const readmeDir = join(directory, ".agent");
63
75
  const readmeFile = join(readmeDir, "opencode-prompt-recorder-readme.txt");
64
76
  const content = `# OpenCode Prompt Recorder
65
77
 
66
- 自动记录用户提示词到 .agent/prompts 目录的插件。
78
+ \u81EA\u52A8\u8BB0\u5F55\u7528\u6237\u63D0\u793A\u8BCD\u5230 .agent/prompts \u76EE\u5F55\u7684\u63D2\u4EF6\u3002
67
79
 
68
- 版本:${version}
69
- 作者:anarckk
70
- 项目地址:https://github.com/anarckk/opencode-prompt-recorder`;
80
+ \u7248\u672C\uFF1A${version}
81
+ \u6700\u540E\u66F4\u65B0\u65F6\u95F4\uFF1A${lastUpdate}
82
+ \u4F5C\u8005\uFF1Aanarckk
83
+ \u9879\u76EE\u5730\u5740\uFF1Ahttps://github.com/anarckk/opencode-prompt-recorder`;
71
84
  try {
72
85
  const existing = await readFile(readmeFile, "utf-8");
73
86
  if (existing === content) {
74
87
  versionFileWritten = true;
75
88
  return;
76
89
  }
77
- } catch {}
90
+ } catch {
91
+ }
78
92
  await mkdir(readmeDir, { recursive: true });
79
93
  await writeFile(readmeFile, content);
80
94
  versionFileWritten = true;
81
- } catch (e) {}
95
+ } catch (e) {
96
+ }
82
97
  }
83
98
  if (output.message.role === "user") {
84
- const now = new Date;
99
+ const now = /* @__PURE__ */ new Date();
85
100
  const text = output.parts.map((p) => p.type === "text" ? p.text : "").join("");
86
101
  const sessionId = input.sessionID;
87
102
  if (!sessionId) {
@@ -94,6 +109,7 @@ var OpenCodePromptRecorder = async ({ directory, client: _client }) => {
94
109
  await mkdir(promptDir, { recursive: true });
95
110
  const existingFile = await findExistingFile(directory, sessionId);
96
111
  const time = formatTime(now);
112
+ const dateStr = `${yyyy}${MM}${dd}`;
97
113
  const timeTitle = `============ ${time} ============`;
98
114
  const fileContent = existingFile ? `
99
115
 
@@ -105,7 +121,7 @@ ${text}`;
105
121
  if (existingFile) {
106
122
  await appendFile(existingFile, fileContent);
107
123
  } else {
108
- const filename = `${HH}${mm}-${sessionId}-${topic}.md`;
124
+ const filename = `${dateStr}-${HH}${mm}-${sessionId}-${topic}.md`;
109
125
  const filepath = join(promptDir, filename);
110
126
  await appendFile(filepath, fileContent);
111
127
  }
@@ -115,8 +131,8 @@ ${text}`;
115
131
  }
116
132
  };
117
133
  };
118
- var opencode_prompt_recorder_default = OpenCodePromptRecorder;
134
+ var index_default = OpenCodePromptRecorder;
119
135
  export {
120
- opencode_prompt_recorder_default as default,
121
- OpenCodePromptRecorder
136
+ OpenCodePromptRecorder,
137
+ index_default as default
122
138
  };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-prompt-recorder",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
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",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "build": "bun build index.ts --outdir dist --target node && cp package.json dist/",
21
- "prepublishOnly": "bun run build",
21
+ "prepublishOnly": "npx esbuild index.ts --bundle --platform=node --outdir=dist --format=esm && cp package.json dist/",
22
22
  "test": "npx tsx test/index.ts"
23
23
  },
24
24
  "keywords": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-prompt-recorder",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
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",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "build": "bun build index.ts --outdir dist --target node && cp package.json dist/",
21
- "prepublishOnly": "bun run build",
21
+ "prepublishOnly": "npx esbuild index.ts --bundle --platform=node --outdir=dist --format=esm && cp package.json dist/",
22
22
  "test": "npx tsx test/index.ts"
23
23
  },
24
24
  "keywords": [