opencode-prompt-recorder 1.7.2 → 1.7.4
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 +3 -3
- package/dist/index.js +9 -9
- package/dist/package.json +2 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
- ✨ 自动捕获聊天对话中的用户提示词
|
|
8
8
|
- 📁 有组织的文件存储:`.agent/prompts/yyyy/MM/dd/` 目录结构
|
|
9
9
|
- 🔗 同一 session 的消息自动合并到同一个文件
|
|
10
|
-
- 📝 丰富的元数据:包含会话 ID
|
|
10
|
+
- 📝 丰富的元数据:包含会话 ID、日期时间戳和提示词主题
|
|
11
11
|
- 🛡️ 安全的文件名处理:清理文件名以防止文件系统错误
|
|
12
12
|
|
|
13
13
|
## 安装
|
|
@@ -62,11 +62,11 @@ bun add -g opencode-prompt-recorder
|
|
|
62
62
|
```markdown
|
|
63
63
|
============ SessionID: ses_xxxxx ============
|
|
64
64
|
|
|
65
|
-
============ 10:05 ============
|
|
65
|
+
============ 2026-06-05 10:05 ============
|
|
66
66
|
|
|
67
67
|
什么是 AI?
|
|
68
68
|
|
|
69
|
-
============ 10:50 ============
|
|
69
|
+
============ 2026-06-05 10:50 ============
|
|
70
70
|
|
|
71
71
|
如何编写 hello world 程序?
|
|
72
72
|
```
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import{mkdir as
|
|
2
|
-
`;try{let
|
|
3
|
-
`)[0].trim().replace(/<[^>]*>/g,"").replace(/\s+/g," ").trim().replace(
|
|
1
|
+
import{mkdir as S,appendFile as N,writeFile as _,readFile as U}from"fs/promises";import{join as g,dirname as X}from"path";import{fileURLToPath as ee}from"url";import{readFile as H,rm as J}from"fs/promises";import{basename as m,dirname as l,join as b}from"path";import{fileURLToPath as W}from"url";var G="opencode-prompt-recorder";function V(n){console.error(`[prompt-recorder][autoUpdate] ${n}`)}function L(n,e){if(!e)return;let r=new AbortController,s=setTimeout(()=>r.abort(),1e4);B(r.signal).then(t=>{t.updated&&(V(`\u53D1\u73B0\u65B0\u7248\u672C: ${t.current} \u2192 ${t.latest}`),setTimeout(()=>{n.client.tui.showToast({body:{title:"Prompt Recorder \u66F4\u65B0",message:`${t.name} \u5DF2\u4ECE ${t.current} \u66F4\u65B0\u5230 ${t.latest}\uFF0C\u91CD\u542F OpenCode \u5B8C\u6210\u66F4\u65B0`,variant:"info"}})},5e3))}).catch(()=>{}).finally(()=>clearTimeout(s))}async function B(n){let e=await K(G);if(!e)return{updated:!1};let r=await P(b(e,"package.json"));if(!r?.name||!r.version)return{updated:!1};let s=await q(r.name,n);if(!s||!Q(s,r.version))return{updated:!1};let t=await z(e,r.name);if(!t)return{updated:!1};try{await J(t,{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 K(n){let e=l(W(import.meta.url));for(;;){if((await P(b(e,"package.json")))?.name===n)return m(e)==="dist"?l(e):e;let s=l(e);if(s===e)return;e=s}}async function z(n,e){let r=l(n),s=m(r).startsWith("@")?l(r):r;if(m(s)!=="node_modules")return;let t=l(s),a=await P(b(t,"package.json")),i=Y(t,e)??a?.dependencies?.[e];if(!(!i||!Z(i)))return t}function Y(n,e){if(e.startsWith("@")){let[t,a]=e.split("/");if(!t||!a||m(l(n))!==t)return;let i=`${a}@`,d=m(n);return d.startsWith(i)?d.slice(i.length):void 0}let r=`${e}@`,s=m(n);return s.startsWith(r)?s.slice(r.length):void 0}function Z(n){let e=n.trim();return e?!!(e==="latest"||e==="*"||/^[~^]/.test(e)||/^(?:>=|>|<=|<)/.test(e)||/\s+(?:\|\||-|[<>=])\s+/.test(e)):!1}async function P(n){try{let e=JSON.parse(await H(n,"utf-8"));return e&&typeof e=="object"?e:void 0}catch{return}}async function q(n,e){try{let r=await fetch(`https://registry.npmjs.org/${encodeURIComponent(n)}/latest`,{signal:e});if(!r.ok)return;let s=await r.json();if(!s||typeof s!="object")return;let t=s.version;return typeof t=="string"?t:void 0}catch{return}}function Q(n,e){let r=A(n),s=A(e);if(!r||!s)return!1;for(let t=0;t<3;t++)if(r.parts[t]!==s.parts[t])return r.parts[t]>s.parts[t];if(!r.pre.length&&s.pre.length)return!0;if(r.pre.length&&!s.pre.length)return!1;for(let t=0;t<Math.max(r.pre.length,s.pre.length);t++){let a=r.pre[t],i=s.pre[t];if(a===void 0)return!1;if(i===void 0)return!0;if(a===i)continue;let d=/^\d+$/.test(a)?Number(a):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:a>i}return!1}function A(n){let e=n.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 te=X(ee(import.meta.url));async function j(n,e){if(process.env.PROMPT_RECORDER_DEBUG!=="1"&&process.env.PROMPT_RECORDER_DEBUG!=="true")return;let s=`[${new Date().toISOString()}] ${e}
|
|
2
|
+
`;try{let t=g(n,".agent","prompts-log");await S(t,{recursive:!0}),await N(g(t,"log.txt"),s)}catch(t){console.error("debugLog failed:",t)}}async function ne(){try{return JSON.parse(await U(g(te,"package.json"),"utf-8")).version}catch{return"unknown"}}var re=/[<>:"/\\|?*\x00-\x1f]/g;function se(n){return n.split(`
|
|
3
|
+
`)[0].trim().replace(/<[^>]*>/g,"").replace(/\s+/g," ").trim().replace(re,"").substring(0,40).trim()||"untitled"}function ie(n){let e=n.trimStart();return e.startsWith("<system-reminder>")||e.startsWith("<system>")}function oe(n){let e=n.getFullYear().toString(),r=String(n.getMonth()+1).padStart(2,"0"),s=String(n.getDate()).padStart(2,"0"),t=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0");return{yyyy:e,MM:r,dd:s,HH:t,mm:a}}var ae=async n=>{L(n,!0);let{directory:e,client:r}=n,s=!1,t=new Map,a=new Set,i=null,d=new Map;return{event:async({event:u})=>{if(u.type==="message.updated"){let o=u.properties.info,c=o?.role||o?.message?.role;o?.id&&c&&t.set(o.id,c)}if(u.type==="message.part.updated"){let o=u.properties.part;if(o?.type==="text"&&o?.text){if(o.synthetic||o.ignored)return;let c=o.sessionID,y=o.messageID,p=o.text,f=t.get(y);if(f||(f=o.message?.role),f||(f=u.properties.info?.role),f||(f=u.properties.info?.message?.role),f==="user"&&p&&c){if(ie(p)){await j(e,`[prompt-recorder] filtered system-injected: sessionID=${c}`);return}let D=`${y}:${p}`;if(a.has(D))return;a.add(D),await j(e,`[prompt-recorder] event=${u.type}, role=${f}, sessionID=${c}, textLength=${p.length}, textPreview=${p.substring(0,50)}`),i||(i=c);let E=new Date,{yyyy:$,MM:w,dd:k,HH:v,mm:x}=oe(E),R=g(e,".agent","prompts"),M=c!==i&&i!==null?g(R,"task",$,w,k):g(R,$,w,k);await S(M,{recursive:!0});let T=$.slice(-2),I=`============ ${$}-${w}-${k} ${v}:${x} ============`,h=d.get(c);if(h)await N(h,`
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${I}
|
|
6
6
|
|
|
7
|
-
${p}`);else{let
|
|
7
|
+
${p}`);else{let C=se(p),F=`${T}${w}${k}${v}${x}-${C}.md`;h=g(M,F);let O=`============ SessionID: ${c} ============`;await _(h,`${O}
|
|
8
8
|
|
|
9
|
-
${
|
|
9
|
+
${I}
|
|
10
10
|
|
|
11
|
-
${p}`),d.set(c,h)}}}}if(u.type==="session.updated"&&!s)try{let
|
|
11
|
+
${p}`),d.set(c,h)}}}}if(u.type==="session.updated"&&!s)try{let o=await ne(),c=g(e,".agent"),y=g(c,"opencode-prompt-recorder-readme.txt"),p=`# OpenCode Prompt Recorder
|
|
12
12
|
|
|
13
13
|
\u81EA\u52A8\u8BB0\u5F55\u7528\u6237\u63D0\u793A\u8BCD\u5230 .agent/prompts \u76EE\u5F55\u7684\u63D2\u4EF6\u3002
|
|
14
14
|
|
|
15
|
-
\u7248\u672C\uFF1A${
|
|
15
|
+
\u7248\u672C\uFF1A${o}
|
|
16
16
|
\u4F5C\u8005\uFF1Aanarckk
|
|
17
|
-
\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 U(y,"utf-8")===p){s=!0;return}}catch{}await S(c,{recursive:!0}),await _(y,p),s=!0}catch{}}}},he=ae;export{ae as OpenCodePromptRecorder,he 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.4",
|
|
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",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"build": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }; npx esbuild index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin --minify; Copy-Item package.json dist/",
|
|
21
21
|
"build:uncompressed": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }; npx esbuild index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin; Copy-Item package.json dist/",
|
|
22
22
|
"prepublishOnly": "npm run build",
|
|
23
|
+
"publish": "node scripts/publish-npmjs.js",
|
|
23
24
|
"test": "npx tsx test/index.ts"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-prompt-recorder",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
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",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"build": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }; npx esbuild index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin --minify; Copy-Item package.json dist/",
|
|
21
21
|
"build:uncompressed": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }; npx esbuild index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin; Copy-Item package.json dist/",
|
|
22
22
|
"prepublishOnly": "npm run build",
|
|
23
|
+
"publish": "node scripts/publish-npmjs.js",
|
|
23
24
|
"test": "npx tsx test/index.ts"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|