opencode-prompt-recorder 1.7.0 → 1.7.2
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 +15 -13
- package/dist/index.js +12 -6
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
- ✨ 自动捕获聊天对话中的用户提示词
|
|
8
8
|
- 📁 有组织的文件存储:`.agent/prompts/yyyy/MM/dd/` 目录结构
|
|
9
|
-
-
|
|
9
|
+
- 🔗 同一 session 的消息自动合并到同一个文件
|
|
10
|
+
- 📝 丰富的元数据:包含会话 ID、时间戳和提示词主题
|
|
10
11
|
- 🛡️ 安全的文件名处理:清理文件名以防止文件系统错误
|
|
11
12
|
|
|
12
13
|
## 安装
|
|
@@ -32,8 +33,8 @@ bun add -g opencode-prompt-recorder
|
|
|
32
33
|
|
|
33
34
|
1. 插件监听 OpenCode 消息事件(`message.updated` 和 `message.part.updated`)
|
|
34
35
|
2. 每次用户消息时,提取提示词文本和会话 ID
|
|
35
|
-
3.
|
|
36
|
-
4.
|
|
36
|
+
3. 同一 session 的消息合并到同一个文件,按日期组织存储
|
|
37
|
+
4. 文件首行记录 SessionID,每条消息带有时间戳
|
|
37
38
|
|
|
38
39
|
## 文件结构
|
|
39
40
|
|
|
@@ -43,23 +44,24 @@ bun add -g opencode-prompt-recorder
|
|
|
43
44
|
.agent/
|
|
44
45
|
└── prompts/
|
|
45
46
|
└── 2026/
|
|
46
|
-
└──
|
|
47
|
-
└──
|
|
48
|
-
├──
|
|
49
|
-
|
|
50
|
-
└── 260304-1120-复制README.md
|
|
47
|
+
└── 06/
|
|
48
|
+
└── 05/
|
|
49
|
+
├── 2606050943-什么是AI.md
|
|
50
|
+
└── 2606051120-复制README.md
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
## 文件名格式
|
|
54
54
|
|
|
55
55
|
每个提示词文件遵循以下格式:`yyMMddHHmm-{提示词主题}.md`
|
|
56
56
|
|
|
57
|
-
- `yyMMddHHmm` -
|
|
58
|
-
- `{提示词主题}` -
|
|
57
|
+
- `yyMMddHHmm` - 首条消息的创建时间(年-月-日-时-分)
|
|
58
|
+
- `{提示词主题}` - 首条提示词的前 40 个字符(已净化)
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
同一 session 的消息合并到同一个文件,文件内容格式:
|
|
61
61
|
|
|
62
62
|
```markdown
|
|
63
|
+
============ SessionID: ses_xxxxx ============
|
|
64
|
+
|
|
63
65
|
============ 10:05 ============
|
|
64
66
|
|
|
65
67
|
什么是 AI?
|
|
@@ -79,10 +81,10 @@ bun add -g opencode-prompt-recorder
|
|
|
79
81
|
|
|
80
82
|
## 文件命名
|
|
81
83
|
|
|
82
|
-
-
|
|
84
|
+
- 提示词主题从首条用户消息的第一行提取
|
|
85
|
+
- 同一 session 的后续消息追加到同一文件,文件名不变
|
|
83
86
|
- 文件名中的特殊字符会被自动清理(移除 `<>:"/\|?*` 及控制字符)
|
|
84
87
|
- 文件名截断至最多 40 个字符
|
|
85
|
-
- 如果提示词过长,文件名只使用前 40 个字符
|
|
86
88
|
|
|
87
89
|
## 使用场景
|
|
88
90
|
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import{mkdir as
|
|
2
|
-
`;try{let
|
|
3
|
-
`)[0].trim().replace(/<[^>]*>/g,"").replace(/\s+/g," ").trim().replace(
|
|
1
|
+
import{mkdir as P,appendFile as j,writeFile as L,readFile as N}from"fs/promises";import{join as g,dirname as ee}from"path";import{fileURLToPath as te}from"url";import{readFile as J,rm as W}from"fs/promises";import{basename as m,dirname as l,join as S}from"path";import{fileURLToPath as G}from"url";var V="opencode-prompt-recorder";function B(t){console.error(`[prompt-recorder][autoUpdate] ${t}`)}function A(t,e){if(!e)return;let r=new AbortController,s=setTimeout(()=>r.abort(),1e4);K(r.signal).then(n=>{n.updated&&(B(`\u53D1\u73B0\u65B0\u7248\u672C: ${n.current} \u2192 ${n.latest}`),setTimeout(()=>{t.client.tui.showToast({body:{title:"Prompt Recorder \u66F4\u65B0",message:`${n.name} \u5DF2\u4ECE ${n.current} \u66F4\u65B0\u5230 ${n.latest}\uFF0C\u91CD\u542F OpenCode \u5B8C\u6210\u66F4\u65B0`,variant:"info"}})},5e3))}).catch(()=>{}).finally(()=>clearTimeout(s))}async function K(t){let e=await z(V);if(!e)return{updated:!1};let r=await b(S(e,"package.json"));if(!r?.name||!r.version)return{updated:!1};let s=await Q(r.name,t);if(!s||!X(s,r.version))return{updated:!1};let n=await Y(e,r.name);if(!n)return{updated:!1};try{await W(n,{recursive:!0,force:!0})}catch{return{updated:!1,error:"remove_failed",name:r.name,current:r.version,latest:s}}return{updated:!0,name:r.name,current:r.version,latest:s}}async function z(t){let e=l(G(import.meta.url));for(;;){if((await b(S(e,"package.json")))?.name===t)return m(e)==="dist"?l(e):e;let s=l(e);if(s===e)return;e=s}}async function Y(t,e){let r=l(t),s=m(r).startsWith("@")?l(r):r;if(m(s)!=="node_modules")return;let n=l(s),o=await b(S(n,"package.json")),i=Z(n,e)??o?.dependencies?.[e];if(!(!i||!q(i)))return n}function Z(t,e){if(e.startsWith("@")){let[n,o]=e.split("/");if(!n||!o||m(l(t))!==n)return;let i=`${o}@`,d=m(t);return d.startsWith(i)?d.slice(i.length):void 0}let r=`${e}@`,s=m(t);return s.startsWith(r)?s.slice(r.length):void 0}function q(t){let e=t.trim();return e?!!(e==="latest"||e==="*"||/^[~^]/.test(e)||/^(?:>=|>|<=|<)/.test(e)||/\s+(?:\|\||-|[<>=])\s+/.test(e)):!1}async function b(t){try{let e=JSON.parse(await J(t,"utf-8"));return e&&typeof e=="object"?e:void 0}catch{return}}async function Q(t,e){try{let r=await fetch(`https://registry.npmjs.org/${encodeURIComponent(t)}/latest`,{signal:e});if(!r.ok)return;let s=await r.json();if(!s||typeof s!="object")return;let n=s.version;return typeof n=="string"?n:void 0}catch{return}}function X(t,e){let r=I(t),s=I(e);if(!r||!s)return!1;for(let n=0;n<3;n++)if(r.parts[n]!==s.parts[n])return r.parts[n]>s.parts[n];if(!r.pre.length&&s.pre.length)return!0;if(r.pre.length&&!s.pre.length)return!1;for(let n=0;n<Math.max(r.pre.length,s.pre.length);n++){let o=r.pre[n],i=s.pre[n];if(o===void 0)return!1;if(i===void 0)return!0;if(o===i)continue;let d=/^\d+$/.test(o)?Number(o):void 0,u=/^\d+$/.test(i)?Number(i):void 0;return d!==void 0&&u!==void 0?d>u:d!==void 0?!1:u!==void 0?!0:o>i}return!1}function I(t){let e=t.match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.+)?$/);if(e)return{parts:[Number(e[1]),Number(e[2]),Number(e[3])],pre:e[4]?.split(".")??[]}}var ne=ee(te(import.meta.url));async function _(t,e){if(process.env.PROMPT_RECORDER_DEBUG!=="1"&&process.env.PROMPT_RECORDER_DEBUG!=="true")return;let s=`[${new Date().toISOString()}] ${e}
|
|
2
|
+
`;try{let n=g(t,".agent","prompts-log");await P(n,{recursive:!0}),await j(g(n,"log.txt"),s)}catch(n){console.error("debugLog failed:",n)}}async function re(){try{return JSON.parse(await N(g(ne,"package.json"),"utf-8")).version}catch{return"unknown"}}var se=/[<>:"/\\|?*\x00-\x1f]/g;function ie(t){return t.split(`
|
|
3
|
+
`)[0].trim().replace(/<[^>]*>/g,"").replace(/\s+/g," ").trim().replace(se,"").substring(0,40).trim()||"untitled"}function oe(t){let e=t.trimStart();return e.startsWith("<system-reminder>")||e.startsWith("<system>")}function ae(t){let e=t.getFullYear().toString(),r=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0"),n=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return{yyyy:e,MM:r,dd:s,HH:n,mm:o}}function ce(t){return`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}`}var ue=async t=>{A(t,!0);let{directory:e,client:r}=t,s=!1,n=new Map,o=new Set,i=null,d=new Map;return{event:async({event:u})=>{if(u.type==="message.updated"){let a=u.properties.info,c=a?.role||a?.message?.role;a?.id&&c&&n.set(a.id,c)}if(u.type==="message.part.updated"){let a=u.properties.part;if(a?.type==="text"&&a?.text){if(a.synthetic)return;let c=a.sessionID,y=a.messageID,p=a.text,f=n.get(y);if(f||(f=a.message?.role),f||(f=u.properties.info?.role),f||(f=u.properties.info?.message?.role),f==="user"&&p&&c){if(oe(p)){await _(e,`[prompt-recorder] filtered system-injected: sessionID=${c}`);return}let D=`${y}:${p}`;if(o.has(D))return;o.add(D),await _(e,`[prompt-recorder] event=${u.type}, role=${f}, sessionID=${c}, textLength=${p.length}, textPreview=${p.substring(0,50)}`),i||(i=c);let v=new Date,{yyyy:$,MM:w,dd:k,HH:T,mm:U}=ae(v),x=g(e,".agent","prompts"),R=c!==i&&i!==null?g(x,"task",$,w,k):g(x,$,w,k);await P(R,{recursive:!0});let E=ce(v),C=$.slice(-2),M=`============ ${E} ============`,h=d.get(c);if(h)await j(h,`
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${M}
|
|
6
|
+
|
|
7
|
+
${p}`);else{let F=ie(p),H=`${C}${w}${k}${T}${U}-${F}.md`;h=g(R,H);let O=`============ SessionID: ${c} ============`;await L(h,`${O}
|
|
8
|
+
|
|
9
|
+
${M}
|
|
10
|
+
|
|
11
|
+
${p}`),d.set(c,h)}}}}if(u.type==="session.updated"&&!s)try{let a=await re(),c=g(e,".agent"),y=g(c,"opencode-prompt-recorder-readme.txt"),p=`# OpenCode Prompt Recorder
|
|
6
12
|
|
|
7
13
|
\u81EA\u52A8\u8BB0\u5F55\u7528\u6237\u63D0\u793A\u8BCD\u5230 .agent/prompts \u76EE\u5F55\u7684\u63D2\u4EF6\u3002
|
|
8
14
|
|
|
9
|
-
\u7248\u672C\uFF1A${
|
|
15
|
+
\u7248\u672C\uFF1A${a}
|
|
10
16
|
\u4F5C\u8005\uFF1Aanarckk
|
|
11
|
-
\u9879\u76EE\u5730\u5740\uFF1Ahttps://github.com/anarckk/opencode-prompt-recorder`;try{if(await
|
|
17
|
+
\u9879\u76EE\u5730\u5740\uFF1Ahttps://github.com/anarckk/opencode-prompt-recorder`;try{if(await N(y,"utf-8")===p){s=!0;return}}catch{}await P(c,{recursive:!0}),await L(y,p),s=!0}catch{}}}},we=ue;export{ue as OpenCodePromptRecorder,we as default};
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-prompt-recorder",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
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.7.
|
|
3
|
+
"version": "1.7.2",
|
|
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",
|