opencode-prompt-recorder 1.0.2 → 1.1.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
@@ -82,6 +82,7 @@ bun add -g opencode-prompt-recorder
82
82
  - 相同的会话 ID 追加到现有文件
83
83
  - 不同的会话 ID 创建新文件
84
84
  - 会话 ID 来自 `chat.message` 事件输入
85
+ - 跨天合并:无论何时,只要 sessionId 相同,都会追加到同一文件(自动搜索所有日期目录)
85
86
 
86
87
  ## 使用场景
87
88
 
package/dist/index.js CHANGED
@@ -15,15 +15,30 @@ function formatDate(date) {
15
15
  function formatTime(date) {
16
16
  return `${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`;
17
17
  }
18
- async function findExistingFile(promptDir, sessionId) {
18
+ async function findExistingFile(directory, sessionId) {
19
19
  if (!sessionId)
20
20
  return null;
21
- const files = await readdir(promptDir);
22
- for (const file of files) {
23
- if (file.includes(`-${sessionId}-`)) {
24
- return join(promptDir, file);
21
+ const promptsBaseDir = join(directory, ".agent", "prompts");
22
+ try {
23
+ const years = await readdir(promptsBaseDir);
24
+ for (const year of years) {
25
+ const yearPath = join(promptsBaseDir, year);
26
+ const months = await readdir(yearPath);
27
+ for (const month of months) {
28
+ const monthPath = join(yearPath, month);
29
+ const days = await readdir(monthPath);
30
+ for (const day of days) {
31
+ const dayPath = join(monthPath, day);
32
+ const files = await readdir(dayPath);
33
+ for (const file of files) {
34
+ if (file.includes(`-${sessionId}-`)) {
35
+ return join(dayPath, file);
36
+ }
37
+ }
38
+ }
39
+ }
25
40
  }
26
- }
41
+ } catch {}
27
42
  return null;
28
43
  }
29
44
  var OpenCodePromptRecorder = async ({ directory, client }) => {
@@ -41,7 +56,7 @@ var OpenCodePromptRecorder = async ({ directory, client }) => {
41
56
  const topic = sanitizeFilename(text);
42
57
  const promptDir = join(directory, ".agent", "prompts", yyyy, MM, dd);
43
58
  await mkdir(promptDir, { recursive: true });
44
- const existingFile = await findExistingFile(promptDir, sessionId);
59
+ const existingFile = await findExistingFile(directory, sessionId);
45
60
  const time = formatTime(new Date);
46
61
  const timeTitle = `============ ${time} ============`;
47
62
  const content = existingFile ? `
@@ -66,6 +81,7 @@ ${text}`;
66
81
  };
67
82
  var opencode_prompt_recorder_default = OpenCodePromptRecorder;
68
83
  export {
84
+ findExistingFile,
69
85
  opencode_prompt_recorder_default as default,
70
86
  OpenCodePromptRecorder
71
87
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-prompt-recorder",
3
- "version": "1.0.2",
3
+ "version": "1.1.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",
@@ -19,7 +19,7 @@
19
19
  "scripts": {
20
20
  "build": "bun build index.ts --outdir dist --target node",
21
21
  "prepublishOnly": "bun run build",
22
- "test": "bun test"
22
+ "test": "npx tsx test/index.ts"
23
23
  },
24
24
  "keywords": [
25
25
  "opencode",