opencode-haimati 1.0.10 → 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 +42 -6
- package/dist/index.js +76 -73
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
- 🔍 多模式搜索:支持序号精确查询和关键字模糊搜索
|
|
11
11
|
- ✏️ 完整 CRUD:读取、写入、更新(部分替换)、删除、移动记忆
|
|
12
12
|
- 🔄 版本并发控制:基于 version 的乐观锁,防止多会话并发冲突
|
|
13
|
-
-
|
|
14
|
-
- 📋
|
|
13
|
+
- ✨ 自动增强首条提示词:支持在用户首条消息前自动添加前缀(默认关闭)
|
|
14
|
+
- 📋 日志追踪:完整的操作日志记录(按天覆盖)
|
|
15
15
|
- ⚡ 纯异步架构:所有文件操作非阻塞执行
|
|
16
16
|
|
|
17
17
|
## 安装
|
|
@@ -33,6 +33,21 @@ bun add -g opencode-haimati
|
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## 配置文件
|
|
37
|
+
|
|
38
|
+
在项目根目录创建 `opencode-haimati.conf` 配置文件:
|
|
39
|
+
|
|
40
|
+
```ini
|
|
41
|
+
# 海马体存储路径(可选,默认 .haimati)
|
|
42
|
+
haimati-path: .haimati
|
|
43
|
+
|
|
44
|
+
# 是否自动增强用户首条消息(默认 false)
|
|
45
|
+
AUTO_ENHANCE_FIRST_MESSAGE: true
|
|
46
|
+
|
|
47
|
+
# 自定义增强前缀文本(可选,不配则用默认值)
|
|
48
|
+
AUTO_ENHANCE_FIRST_MESSAGE_TEXT: 读取有关的海马体;再实现用户需求
|
|
49
|
+
```
|
|
50
|
+
|
|
36
51
|
## 海马体结构
|
|
37
52
|
|
|
38
53
|
```
|
|
@@ -53,12 +68,12 @@ bun add -g opencode-haimati
|
|
|
53
68
|
| 工具 | 说明 |
|
|
54
69
|
|------|------|
|
|
55
70
|
| `haimati_read` | 读取记忆内容(只支持序号查询,支持分页,返回带行号和版本号) |
|
|
56
|
-
| `haimati_write` |
|
|
57
|
-
| `haimati_search` |
|
|
71
|
+
| `haimati_write` | 写入新记忆(如果已存在相同分类和标题的记忆则报错,不允许覆盖) |
|
|
72
|
+
| `haimati_search` | 搜索记忆内容(标题、分类、序号、书页内容,match参数必填) |
|
|
58
73
|
| `haimati_edit` | 修改记忆内容(部分替换,行号范围 [offsetBegin, offsetEnd),offsetEnd 不包括) |
|
|
59
74
|
| `haimati_move` | 修改记忆的分类路径 |
|
|
60
|
-
| `haimati_delete` |
|
|
61
|
-
| `haimati_list` |
|
|
75
|
+
| `haimati_delete` | 删除记忆(支持序号或完整路径定位) |
|
|
76
|
+
| `haimati_list` | 列出记忆索引(支持递归遍历) |
|
|
62
77
|
|
|
63
78
|
## 海马体三大原则
|
|
64
79
|
|
|
@@ -81,6 +96,9 @@ haimati_write({
|
|
|
81
96
|
// 读取记忆(只支持序号查询)
|
|
82
97
|
haimati_read({ query: "086" })
|
|
83
98
|
|
|
99
|
+
// 分页读取
|
|
100
|
+
haimati_read({ query: "086", offset: 10, limit: 50 })
|
|
101
|
+
|
|
84
102
|
// 搜索记忆
|
|
85
103
|
haimati_search({ keyword: "WebSocket", match: "or", limit: 10 })
|
|
86
104
|
|
|
@@ -119,12 +137,30 @@ xxx项目/
|
|
|
119
137
|
└── 用户注册密码 - 033
|
|
120
138
|
```
|
|
121
139
|
|
|
140
|
+
## 书页文件格式
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
正文内容...
|
|
144
|
+
---
|
|
145
|
+
标题
|
|
146
|
+
创建时间 (ISO 8601)
|
|
147
|
+
version:1
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
最后4行是系统行:分隔符、标题、创建时间、版本号。
|
|
151
|
+
|
|
122
152
|
## 依赖要求
|
|
123
153
|
|
|
124
154
|
- OpenCode v0.15.0 或更高版本
|
|
125
155
|
- Node.js 或 Bun 运行时
|
|
126
156
|
- 项目目录的文件系统写入权限
|
|
127
157
|
|
|
158
|
+
## 日志
|
|
159
|
+
|
|
160
|
+
日志文件位于:`{系统临时目录}/haimati_logs/haimati.log`
|
|
161
|
+
|
|
162
|
+
日志按天覆盖,新的一天开始时清空旧日志。
|
|
163
|
+
|
|
128
164
|
## 许可证
|
|
129
165
|
|
|
130
166
|
MIT
|
package/dist/index.js
CHANGED
|
@@ -1,92 +1,95 @@
|
|
|
1
|
-
import{tool as
|
|
2
|
-
`);for(let e of a){let
|
|
3
|
-
`)
|
|
4
|
-
`)
|
|
5
|
-
`);if(e.
|
|
6
|
-
`);return{
|
|
7
|
-
`);return
|
|
1
|
+
import{tool as E}from"@opencode-ai/plugin";import P from"path";import Nt from"os";import M from"fs";var R=".haimati",at="\u7D22\u5F15.md";var ct="next-id.txt",lt="haimati.log";var W="opencode-haimati.conf",ft="haimati-path",ut="AUTO_ENHANCE_FIRST_MESSAGE",mt="AUTO_ENHANCE_FIRST_MESSAGE_TEXT";var dt="\u8BFB\u53D6\u6709\u5173\u7684\u6D77\u9A6C\u4F53\uFF1B\u518D\u5B9E\u73B0\u7528\u6237\u9700\u6C42";function vt(t){let o=P.join(t,W);if(!M.existsSync(o))return null;try{let a=M.readFileSync(o,"utf-8").split(`
|
|
2
|
+
`);for(let e of a){let i=e.trim();if(!i||i.startsWith("#"))continue;let r=i.match(/^([^:]+):\s*(.+)$/);if(r){let c=r[1].trim(),s=r[2].trim();if(c===ft&&s)return P.resolve(t,s)}}}catch(n){console.error("[haimati] \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6\u5931\u8D25:",n)}return null}function gt(t){let o=P.join(t,W);if(!M.existsSync(o))return null;try{let a=M.readFileSync(o,"utf-8").split(`
|
|
3
|
+
`);for(let e of a){let i=e.trim();if(!i||i.startsWith("#"))continue;let r=i.match(/^([^:]+):\s*(.+)$/);if(r){let c=r[1].trim(),s=r[2].trim().toLowerCase();if(c===ut)return s==="true"}}}catch(n){console.error("[haimati] \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6\u5931\u8D25:",n)}return null}function ht(t){let o=P.join(t,W);if(!M.existsSync(o))return null;try{let a=M.readFileSync(o,"utf-8").split(`
|
|
4
|
+
`);for(let e of a){let i=e.trim();if(!i||i.startsWith("#"))continue;let r=i.match(/^([^:]+):\s*(.+)$/);if(r){let c=r[1].trim(),s=r[2].trim();if(c===mt&&s)return s}}}catch(n){console.error("[haimati] \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6\u5931\u8D25:",n)}return null}function A(t){let o=vt(t);return o||P.join(t,R)}function S(t){return P.join(A(t),at)}function G(t){return P.join(A(t),ct)}function Y(t){return P.join(A(t),".lock")}function Q(t){return P.join(A(t),"\u4E66\u9875")}function F(t,o){let n=parseInt(o,10),a=Math.floor((n-1)/50)*50+1,e=a+50-1,i=`${String(a).padStart(3,"0")}-${String(e).padStart(3,"0")}`;return P.join(Q(t),i)}function q(t,o){let n=String(parseInt(o,10)).padStart(3,"0");return P.join(F(t,o),`${n}.md`)}function pt(){let t=Nt.tmpdir();return P.join(t,"haimati_logs",lt)}function C(t){return M.promises.mkdir(t,{recursive:!0}).then(()=>{})}function x(t){return M.promises.access(t).then(()=>!0).catch(()=>!1)}import yt from"fs";import Lt from"path";import{promisify as wt}from"util";var $t=wt(yt.readFile),jt=wt(yt.writeFile);function H(t){let o=0,n=0,a=t.length;for(;n<a;)if(t[n]==="\u2502"&&n+3<a&&t.slice(n+1,n+4)===" ")o++,n+=4;else if(t.slice(n,n+4)===" ")o++,n+=4;else{if((t[n]==="\u251C"||t[n]==="\u2514")&&n+3<a&&t.slice(n+1,n+4)==="\u2500\u2500 ")break;break}return o}function B(t){let n=t.trim().replace(/^[│├└─\s]+/,"").trim();return n==="/"?"/":!n.endsWith("/")||(n=n.slice(0,-1),!n)?null:n}function Ot(t){let o=[],n=t.split(`
|
|
5
|
+
`),a=[];for(let e of n){if(!e.trim())continue;let i=H(e),r=e.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/);if(r){let c=r[1].trim(),s=String(parseInt(r[2],10)),f=a.slice(0,i).filter(d=>d!=="").join("/");o.push({id:s,category:f,title:c})}else{let c=B(e);if(c)if(c==="/"){a[i]="";for(let s=i+1;s<a.length;s++)delete a[s]}else{a[i]=c;for(let s=i+1;s<a.length;s++)delete a[s]}}}return o}function L(t,o){return t.find(n=>n.id===o)||null}function U(t,o,n){return t.find(a=>a.category===o&&a.title===n)||null}function xt(t,o){return t.filter(n=>n.id!==o)}function Z(t){if(t.length===0)return"";let o={name:"/",children:[],entry:null};for(let e of t){let i=e.category.split("/"),r=o;for(let s=0;s<i.length;s++){let m=i[s];if(!m)continue;let f=r.children.find(d=>d.name===m);f||(f={name:m,children:[],entry:null},r.children.push(f)),r=f}let c={name:e.id,children:[],entry:e};r.children.push(c)}function n(e){e.children.sort((i,r)=>i.name.localeCompare(r.name,void 0,{sensitivity:"base"}));for(let i of e.children)n(i)}n(o);function a(e,i,r){let c=[],s=i+(r?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 "),m=e.name==="/"?"/":e.name+"/";c.push(`${s}${m}`),i=i+(r?" ":"\u2502 ");let f=e.children.filter(u=>u.entry===null),d=e.children.filter(u=>u.entry!==null),h=[...f,...d];for(let u=0;u<h.length;u++){let g=h[u],y=u===h.length-1;if(g.entry){let p=g.entry.id.padStart(3,"0"),_=i+(y?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ");c.push(`${_}${g.entry.title} - ${p}`)}else c.push(...a(g,i,y))}return c}return a(o,"",!0).join(`
|
|
6
|
+
`)}async function b(t){let o=S(t);if(!await x(o))return[];let n=await $t(o,"utf-8");return Ot(n)}async function j(t,o){let n=Lt.join(t,R);await x(n)||await C(n);let a=Z(o),e=S(t);await jt(e,a,"utf-8")}async function Et(t){let o=S(t);return await x(o)?$t(o,"utf-8"):""}import X from"fs";import{promisify as z}from"util";var Rt=z(X.readFile),Wt=z(X.writeFile),Gt=z(X.unlink),_t=z(X.mkdir);async function k(t,o){let n=q(t,o);if(!await x(n))return null;let e=(await Rt(n,"utf-8")).split(`
|
|
7
|
+
`);if(e.length<4)return null;let i=Math.max(0,e.length-5),r=-1;for(let h=e.length-1;h>=i;h--)if(e[h].trim()==="---"){r=h;break}if(r===-1){if(e.length>=3&&e[2].startsWith("version:")&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(e[1])){let y=e[0],p=e[1],_=parseInt(e[2].substring(8).trim(),10)||1,w=e.slice(3).join(`
|
|
8
|
+
`);return{title:y,createdAt:p,content:w,version:_}}let u=e[0],g=e.join(`
|
|
9
|
+
`);return{title:u,createdAt:"",content:g,version:1}}if(r+3>=e.length)return null;let c=e.slice(0,r).join(`
|
|
10
|
+
`),s=e[r+1],m=e[r+2],f=e[r+3],d=parseInt(f.substring(8).trim(),10)||1;return{title:s,createdAt:m,content:c,version:d}}async function O(t,o,n,a,e,i=1){let r=Q(t);await x(r)||await _t(r,{recursive:!0});let c=F(t,o);await x(c)||await _t(c,{recursive:!0});let s=q(t,o),m=`---
|
|
11
|
+
${n}
|
|
8
12
|
${a}
|
|
9
|
-
version:${
|
|
10
|
-
${e}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
${w
|
|
16
|
-
${w
|
|
17
|
-
|
|
18
|
-
${w($)}`),$}let h=L(n,c.id);await l("debug",`[haimati_read] \u8BFB\u53D6\u4E66\u9875: \u4E66\u9875/${h.split(/[\\/]/).pop()}/${c.id}.md, version=${s.version}`);let f=s.content.split(`
|
|
19
|
-
`),d=t.offset||1,p=t.limit||2e3,u=f.length,m=Math.max(0,d-1),y=Math.min(u,m+p),g=[];g.push(`version:${s.version}`);for(let $=m;$<y;$++)g.push(`${$+1}|${f[$]}`);let E=g.join(`
|
|
13
|
+
version:${i}`,f=e?`${e}
|
|
14
|
+
${m}`:m;await Wt(s,f,"utf-8")}async function It(t,o){let n=q(t,o);return await x(n)?(await Gt(n),!0):!1}async function K(t,o,n,a,e=!1){let i=o.toLowerCase().split(/\s+/).filter(c=>c.length>0);if(i.length===0)return[];let r=[];for(let c of t){let s=c.title.toLowerCase(),m=c.category.toLowerCase(),f=c.id.toLowerCase(),d=0,h=0;for(let g of i)(s.includes(g)||m.includes(g)||f.includes(g))&&d++;if(e&&a){let g=await k(a,c.id);if(g&&g.content){let y=g.content.toLowerCase();for(let p of i)y.includes(p)&&h++}}let u=d+h;n==="and"?u>=i.length&&r.push({entry:c,score:u}):(d>0||e&&h>0)&&r.push({entry:c,score:u})}return r.sort((c,s)=>s.score-c.score),r.map(c=>c.entry)}import Mt from"fs";import{promisify as At}from"util";import Pt from"fs";import{promisify as St}from"util";var Ht=St(Pt.writeFile),Bt=St(Pt.unlink);async function bt(t){let o=A(t);await x(o)||await C(o);let n=Y(t),a=Date.now(),e=50+Math.random()*20;for(;await x(n);){if(Date.now()-a>5e3)return!1;await new Promise(i=>setTimeout(i,e))}return await Ht(n,String(process.pid),"utf-8"),!0}async function Tt(t){let o=Y(t);await x(o)&&await Bt(o)}import et from"fs";import Ut from"path";import{promisify as nt}from"util";var Xt=nt(et.appendFile),zt=nt(et.writeFile),Kt=nt(et.stat);function $(t,o=500){if(t.length<=o)return t;let n=Math.floor((o-20)/2);return t.substring(0,n)+"...(\u7701\u7565"+(t.length-o)+"\u5B57\u7B26)..."+t.substring(t.length-n)}async function Vt(t){try{let o=new Date,n=o.toLocaleDateString("zh-CN"),a=o.toLocaleTimeString("zh-CN",{hour12:!1}),e=pt(),i=Ut.dirname(e);await x(i)||await C(i);let r=!1;await x(e)&&(await Kt(e)).mtime.toLocaleDateString("zh-CN")!==n&&(r=!0);let c=`[${a}] ${t}`;r?await zt(e,c+`
|
|
15
|
+
`,"utf-8"):await Xt(e,c+`
|
|
16
|
+
`,"utf-8")}catch(o){console.error("[haimati] \u5199\u5165\u65E5\u5FD7\u6587\u4EF6\u5931\u8D25:",o)}}async function l(t,o){await Vt(`[${t.toUpperCase()}] ${o}`)}var Jt=At(Mt.readFile),Yt=At(Mt.writeFile);async function Qt(t){let o=G(t);if(!await x(o))return 1;let a=(await Jt(o,"utf-8")).trim(),e=parseInt(a,10);return!isNaN(e)&&e>0?e:1}async function Zt(t){let o=G(t);if(await x(o))return;let n=await b(t),a=0;for(let e of n){let i=parseInt(e.id,10);i>a&&(a=i)}await Ct(t,a+1)}async function Ct(t,o){let n=A(t);await x(n)||await C(n);let a=G(t);await Yt(a,String(o),"utf-8")}async function kt(t,o,n,a,e,i=!1){if(/ - \d{3}$/.test(n))throw await l("warn",`[allocateIdWithLock] title \u683C\u5F0F\u4E0D\u5408\u89C4: "${n}", \u629B\u51FA\u9519\u8BEF`),new Error('\u6807\u9898\u4E0D\u80FD\u4EE5 " - \u5E8F\u53F7" \u683C\u5F0F\u7ED3\u5C3E\uFF0C\u5E8F\u53F7\u7531\u7CFB\u7EDF\u81EA\u52A8\u5206\u914D\uFF0C\u8BF7\u4FEE\u6539\u6807\u9898');if(await l("info",`[allocateIdWithLock] \u5F00\u59CB\u5206\u914D\u5E8F\u53F7: category="${o}", title="${n}"`),!await bt(t))return await l("warn",`[allocateIdWithLock] \u83B7\u53D6\u9501\u5931\u8D25: category="${o}", title="${n}"`),null;await l("debug",`[allocateIdWithLock] \u83B7\u53D6\u9501\u6210\u529F: category="${o}", title="${n}"`);try{await Zt(t);let r=await b(t),c=r.find(d=>d.category===o&&d.title===n);if(c){if(!i)throw new Error(`\u8BB0\u5FC6\u5DF2\u5B58\u5728: ${o}/${n}\uFF0C\u5982\u9700\u66F4\u65B0\u8BF7\u4F7F\u7528 haimati_edit \u5DE5\u5177`);let d=await k(t,c.id),h=d?d.createdAt:a,u=d?d.version+1:1;return await O(t,c.id,n,h,e,u),await l("info",`[allocateIdWithLock] \u66F4\u65B0\u5DF2\u6709\u6761\u76EE: #${c.id} ${o}/${n}, \u65B0\u7248\u672C: ${u}`),null}let s=await Qt(t),m=String(s).padStart(3,"0");await O(t,m,n,a,e,1);let f={id:m,category:o,title:n};return r.push(f),await j(t,r),await Ct(t,s+1),await l("info",`[allocateIdWithLock] \u5206\u914D\u5E8F\u53F7\u6210\u529F: #${m} ${o}/${n}`),m}catch(r){let c=r instanceof Error?r.message:String(r);if(await l("error",`[allocateIdWithLock] \u5206\u914D\u5E8F\u53F7\u5931\u8D25: ${c}`),c.includes("\u8BB0\u5FC6\u5DF2\u5B58\u5728"))throw r;return null}finally{await Tt(t)}}function Dt(){return{haimati_read:E({description:"\u4ECE\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u8BFB\u53D6\u5185\u5BB9\u3002\u901A\u8FC7\u5E8F\u53F7\uFF08\u5982 '086'\uFF09\u6765\u5B9A\u4F4D\u5E76\u8BFB\u53D6\u8BB0\u5FC6\u5185\u5BB9\u3002\u652F\u6301\u5206\u9875\u8BFB\u53D6\uFF08offset/limit\uFF09\uFF0C\u8FD4\u56DE\u5185\u5BB9\u5E26\u884C\u53F7\u548C\u7248\u672C\u53F7\u3002",args:{query:E.schema.string().describe("\u5E8F\u53F7\u3002\u4F8B\u5982\uFF1A'086'"),offset:E.schema.number().optional().default(1).describe("\u8D77\u59CB\u884C\u53F7\uFF08\u9ED8\u8BA4 1\uFF09"),limit:E.schema.number().optional().default(2e3).describe("\u6700\u5927\u8BFB\u53D6\u884C\u6570\uFF08\u9ED8\u8BA4 2000\uFF09")},async execute(t,o){let{directory:n}=o,a=S(n);if(await l("info",`[haimati_read] \u5165\u53C2: query="${t.query}", offset=${t.offset||1}, limit=${t.limit||2e3}`),!await x(a)){let e=`\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728\u4E8E ${a}`;return await l("warn",`[haimati_read] \u51FA\u53C2:
|
|
17
|
+
${$(e)}`),e}try{let e=await b(n);await l("debug",`[haimati_read] \u8BFB\u53D6\u7D22\u5F15: \u5171 ${e.length} \u6761\u8BB0\u5F55`);let i=t.query.trim();if(!/^\d+$/.test(i)){let w="\u9519\u8BEF\uFF1Aquery \u5FC5\u987B\u662F\u5E8F\u53F7\uFF0C\u53EA\u652F\u6301\u5E8F\u53F7\u67E5\u8BE2";return await l("warn",`[haimati_read] \u51FA\u53C2:
|
|
18
|
+
${$(w)}`),w}let r=String(parseInt(i,10)),c=L(e,r);if(await l("debug",`[haimati_read] \u5E8F\u53F7\u67E5\u8BE2 #${i}: ${c?"\u627E\u5230":"\u672A\u627E\u5230"}`),!c){let w=`\u672A\u627E\u5230\u8BB0\u5FC6: ${t.query}`;return await l("info",`[haimati_read] \u51FA\u53C2:
|
|
19
|
+
${$(w)}`),w}let s=await k(n,c.id);if(!s){let w=`\u672A\u627E\u5230\u4E66\u9875: #${c.id.padStart(3,"0")}`;return await l("error",`[haimati_read] \u51FA\u53C2:
|
|
20
|
+
${$(w)}`),w}let m=F(n,c.id);await l("debug",`[haimati_read] \u8BFB\u53D6\u4E66\u9875: \u4E66\u9875/${m.split(/[\\/]/).pop()}/${c.id}.md, version=${s.version}`);let f=s.content.split(`
|
|
21
|
+
`),d=t.offset||1,h=t.limit||2e3,u=f.length,g=Math.max(0,d-1),y=Math.min(u,g+h),p=[];p.push(`version:${s.version}`);for(let w=g;w<y;w++)p.push(`${w+1}|${f[w]}`);let _=p.join(`
|
|
20
22
|
`);return await l("info",`[haimati_read] \u51FA\u53C2:
|
|
21
|
-
${
|
|
22
|
-
\u5806\u6808: ${
|
|
23
|
-
${
|
|
24
|
-
`);try{let a=new Date().
|
|
23
|
+
${$(_)}`),_}catch(e){let i=e instanceof Error?e.message:String(e),r=e instanceof Error?e.stack:"";return await l("error",`[haimati_read] \u51FA\u53C2: \u9519\u8BEF: ${i}
|
|
24
|
+
\u5806\u6808: ${r}`),`\u9519\u8BEF: ${i}`}}}),haimati_write:E({description:"\u5C06\u65B0\u4FE1\u606F\u5199\u5165\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u3002\u9700\u8981\u63D0\u4F9B\u5206\u7C7B\u8DEF\u5F84\uFF08\u5982 'xxx\u9879\u76EE/\u7B7E\u7AE0'\uFF09\u3001\u6807\u9898\u548C\u5185\u5BB9\u3002\u5982\u679C\u76F8\u540C\u5206\u7C7B\u548C\u6807\u9898\u7684\u8BB0\u5FC6\u5DF2\u5B58\u5728\uFF0C\u5219\u4F1A\u62A5\u9519\u3002",args:{category:E.schema.string().describe("\u5206\u7C7B\u8DEF\u5F84\uFF0C\u5982 'xxx\u9879\u76EE/\u7B7E\u7AE0' \u6216 '\u901A\u7528'"),title:E.schema.string().describe("\u8BB0\u5FC6\u6807\u9898\uFF0C\u5982 '\u7B7E\u7AE0\u670D\u52A1WS\u901A\u4FE1\u673A\u5236'"),content:E.schema.string().describe("\u8981\u5199\u5165\u7684\u8BE6\u7EC6\u5185\u5BB9")},async execute(t,o){let{directory:n}=o;await l("info",`[haimati_write] \u5165\u53C2: category="${t.category}", title="${t.title}", content\u957F\u5EA6=${t.content.length}\u5B57\u7B26, content=
|
|
25
|
+
${$(t.content)}
|
|
26
|
+
`);try{let a=new Date().toLocaleString("zh-CN",{hour12:!1}),e=null;for(let s=0;s<3;s++)try{if(e=await kt(n,t.category,t.title,a,t.content,!1),e)break;await l("warn",`[haimati_write] \u9501\u83B7\u53D6\u5931\u8D25\uFF0C\u91CD\u8BD5\u7B2C ${s+1} \u6B21`)}catch(m){let f=m instanceof Error?m.message:String(m);if(f.includes("\u8BB0\u5FC6\u5DF2\u5B58\u5728"))throw m;await l("warn",`[haimati_write] \u83B7\u53D6\u9501\u5F02\u5E38: ${f}, \u91CD\u8BD5\u7B2C ${s+1} \u6B21`)}if(e){let s=F(n,e);await l("debug",`[haimati_write] \u5206\u914D\u65B0\u5E8F\u53F7: #${e}`),await l("debug",`[haimati_write] \u4E66\u9875\u548C\u7D22\u5F15\u5DF2\u66F4\u65B0: \u4E66\u9875/${s.split(/[\\/]/).pop()}/${e}.md`);let m=`\u5DF2\u5199\u5165\u6D77\u9A6C\u4F53 #${e}
|
|
25
27
|
\u8DEF\u5F84: ${t.category}/${t.title}
|
|
26
28
|
\u7248\u672C: 1`;return await l("info",`[haimati_write] \u51FA\u53C2:
|
|
27
|
-
${
|
|
28
|
-
${
|
|
29
|
-
${
|
|
30
|
-
\u5806\u6808: ${
|
|
31
|
-
${
|
|
32
|
-
${
|
|
33
|
-
`),u&&
|
|
34
|
-
`);for(let
|
|
35
|
-
`).filter(
|
|
29
|
+
${$(m)}`),m}let i=await b(n),r=U(i,t.category,t.title);if(r){let s=`\u9519\u8BEF\uFF1A\u8BB0\u5FC6\u5DF2\u5B58\u5728 #${r.id} (${t.category}/${t.title})\uFF0C\u5982\u9700\u66F4\u65B0\u8BF7\u4F7F\u7528 haimati_edit \u5DE5\u5177`;return await l("error",`[haimati_write] \u51FA\u53C2:
|
|
30
|
+
${$(s)}`),s}let c="\u9519\u8BEF\uFF1A\u65E0\u6CD5\u5206\u914D\u5E8F\u53F7\uFF08\u9501\u7B49\u5F85\u8D85\u65F6\uFF09";return await l("error",`[haimati_write] \u51FA\u53C2:
|
|
31
|
+
${$(c)}`),c}catch(a){let e=a instanceof Error?a.message:String(a),i=a instanceof Error?a.stack:"";return await l("error",`[haimati_write] \u51FA\u53C2: \u9519\u8BEF: ${e}
|
|
32
|
+
\u5806\u6808: ${i}`),`\u9519\u8BEF: ${e}`}}}),haimati_search:E({description:"\u641C\u7D22\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\uFF08\u652F\u6301\u591A\u5173\u952E\u5B57\uFF0C\u7528\u7A7A\u683C\u5206\u9694\uFF09\u3002\u641C\u7D22\u8303\u56F4\u5305\u62EC\uFF1A\u6807\u9898\u3001\u5206\u7C7B\u3001\u5E8F\u53F7\u3001\u4E66\u9875\u5185\u5BB9\u3002\u8F93\u5165\u5173\u952E\u8BCD\uFF0C\u8FD4\u56DE\u5339\u914D\u7684\u6761\u76EE\u5217\u8868\u548C\u5185\u5BB9\u7247\u6BB5\uFF0C\u652F\u6301\u5206\u9875\uFF08limit/offset\uFF09\u3002",args:{keyword:E.schema.string().describe("\u641C\u7D22\u5173\u952E\u8BCD\uFF08\u652F\u6301\u591A\u5173\u952E\u5B57\uFF0C\u7528\u7A7A\u683C\u5206\u9694\uFF09"),match:E.schema.string().describe("\u5339\u914D\u6A21\u5F0F\uFF1Aand=\u6240\u6709\u5173\u952E\u5B57\u90FD\u5339\u914D\uFF0Cor=\u4EFB\u610F\u5173\u952E\u5B57\u5339\u914D"),limit:E.schema.number().default(10).describe("\u8FD4\u56DE\u7ED3\u679C\u6570\u91CF\u9650\u5236"),offset:E.schema.number().default(0).describe("\u5206\u9875\u504F\u79FB\u91CF\uFF0C\u7528\u4E8E\u83B7\u53D6\u540E\u7EED\u9875\u9762")},async execute(t,o){let{directory:n}=o,a=S(n);if(await l("info",`[haimati_search] \u5165\u53C2: keyword="${t.keyword}", match="${t.match}", limit=${t.limit||10}, offset=${t.offset||0}`),!await x(a)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await l("warn",`[haimati_search] \u51FA\u53C2:
|
|
33
|
+
${$(e)}`),e}try{let e=await b(n),i=t.keyword.trim(),r=t.match,c=t.limit||10,s=t.offset||0,m=await K(e,i,r,n,!0),f=m.length,d=m.slice(s,s+c);if(d.length===0){let p=`\u672A\u627E\u5230\u5305\u542B '${i}' \u7684\u8BB0\u5FC6`;return await l("info",`[haimati_search] \u51FA\u53C2:
|
|
34
|
+
${$(p)}`),p}let h=[],u=s+d.length<f,g=u?`${s+1}-${s+d.length}/${f}`:`${s+1}-${s+d.length}/${f}`;h.push(`\u627E\u5230 ${g} \u6761\u5339\u914D\uFF1A
|
|
35
|
+
`),u&&h.push(`\uFF08\u5982\u9700\u83B7\u53D6\u66F4\u591A\uFF0C\u8BF7\u4F7F\u7528 offset=${s+c} \u7EE7\u7EED\u7FFB\u9875\uFF09
|
|
36
|
+
`);for(let p of d){let _=await k(n,p.id),w=`${p.category}/${p.title}`,T="";_&&(T=_.content.split(`
|
|
37
|
+
`).filter(V=>V.trim()).slice(0,3).join(" | ").substring(0,150),T.length===150&&(T+="...")),h.push(`## ${w} [${p.id}]`),T&&h.push(`> ${T}`),h.push("")}let y=h.join(`
|
|
36
38
|
`);return await l("info",`[haimati_search] \u51FA\u53C2:
|
|
37
|
-
${
|
|
38
|
-
\u5806\u6808: ${
|
|
39
|
-
${
|
|
40
|
-
`)
|
|
41
|
-
${
|
|
42
|
-
${
|
|
43
|
-
${
|
|
44
|
-
|
|
45
|
-
`)
|
|
46
|
-
${
|
|
47
|
-
|
|
48
|
-
`)
|
|
49
|
-
`)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
\u8DEF\u5F84: ${K}
|
|
39
|
+
${$(y)}`),y}catch(e){let i=e instanceof Error?e.message:String(e),r=e instanceof Error?e.stack:"";return await l("error",`[haimati_search] \u51FA\u53C2: \u9519\u8BEF: ${i}
|
|
40
|
+
\u5806\u6808: ${r}`),`\u9519\u8BEF: ${i}`}}}),haimati_edit:E({description:"\u4FEE\u6539\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7684\u90E8\u5206\u5185\u5BB9\u3002\u5C06\u6307\u5B9A\u884C\u53F7\u8303\u56F4 [offsetBegin, offsetEnd) \u7684\u5185\u5BB9\u66FF\u6362\u4E3A\u65B0 content\uFF0CoffsetEnd \u4E0D\u5305\u62EC\u6B64\u884C\u3002\u9700\u8981\u63D0\u4F9B read \u65F6\u8FD4\u56DE\u7684 version \u8FDB\u884C\u5E76\u53D1\u63A7\u5236\u3002",args:{query:E.schema.string().describe("\u5E8F\u53F7\uFF0C\u7528\u4E8E\u5B9A\u4F4D\u8981\u66F4\u65B0\u7684\u8BB0\u5FC6"),offsetBegin:E.schema.number().describe("\u8D77\u59CB\u884C\u53F7\uFF08\u5305\u62EC\uFF09"),offsetEnd:E.schema.number().describe("\u7ED3\u675F\u884C\u53F7\uFF08\u4E0D\u5305\u62EC\u6B64\u884C\uFF09"),content:E.schema.string().describe("\u66FF\u6362\u5185\u5BB9"),version:E.schema.number().describe("read \u65F6\u8FD4\u56DE\u7684 version\uFF0C\u7528\u4E8E\u5E76\u53D1\u63A7\u5236")},async execute(t,o){let{directory:n}=o,a=S(n);if(await l("info",`[haimati_edit] \u5165\u53C2: query="${t.query}", offsetBegin=${t.offsetBegin}, offsetEnd=${t.offsetEnd}, content\u957F\u5EA6=${t.content.length}\u5B57\u7B26, version=${t.version}, content=
|
|
41
|
+
${$(t.content)}`),!await x(a)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await l("warn",`[haimati_edit] \u51FA\u53C2:
|
|
42
|
+
${$(e)}`),e}try{let e=await b(n),i=t.query.trim();if(!/^\d+$/.test(i)){let I="\u9519\u8BEF\uFF1Aquery \u5FC5\u987B\u662F\u5E8F\u53F7\uFF0C\u53EA\u652F\u6301\u5E8F\u53F7\u67E5\u8BE2";return await l("warn",`[haimati_edit] \u51FA\u53C2:
|
|
43
|
+
${$(I)}`),I}let r=String(parseInt(i,10)),c=L(e,r);if(!c){let I=`\u672A\u627E\u5230\u4E0E '${i}' \u76F8\u5173\u7684\u8BB0\u5FC6`;return await l("info",`[haimati_edit] \u51FA\u53C2:
|
|
44
|
+
${$(I)}`),I}let s=await k(n,c.id);if(!s){let I=`\u672A\u627E\u5230\u4E66\u9875: #${c.id.padStart(3,"0")}`;return await l("error",`[haimati_edit] \u51FA\u53C2:
|
|
45
|
+
${$(I)}`),I}let m=t.offsetBegin,f=t.offsetEnd,d=s.content.split(`
|
|
46
|
+
`).length;if(m<1||m>=d+1||m>=f||f>d+1){let I=`\u9519\u8BEF\uFF1Aoffset \u975E\u6CD5\uFF0CoffsetBegin=${m}, offsetEnd=${f}, \u6587\u4EF6\u603B\u884C\u6570=${d}\uFF0C\u6709\u6548\u8303\u56F4 offsetBegin=[1, ${d+1}), offsetEnd=[offsetBegin+1, ${d+1}]`;return await l("warn",`[haimati_edit] \u51FA\u53C2:
|
|
47
|
+
${$(I)}`),I}if(s.version!==t.version){let I=`\u9519\u8BEF\uFF1A\u7248\u672C\u51B2\u7A81\uFF0C\u5F53\u524D version=${s.version}\uFF0C\u4F20\u5165 version=${t.version}\uFF0C\u8BF7\u91CD\u65B0\u8BFB\u53D6\u540E\u518D\u64CD\u4F5C`;return await l("warn",`[haimati_edit] \u51FA\u53C2:
|
|
48
|
+
${$(I)}`),I}let h=(I,ot)=>{if(ot===0)return 0;let st=1,v=0;for(;v<I.length;){if(I[v]===`
|
|
49
|
+
`){if(st===ot)return v+1;st++}v++}return v},u=h(s.content,m-1),g=h(s.content,f-1),y=s.content.substring(0,Math.min(100,s.content.length));await l("debug",`[haimati_edit] content\u957F\u5EA6=${s.content.length}, content\u524D100\u5B57\u7B26: ${JSON.stringify(y)}, offsetBegin=${m}, offsetEnd=${f}, beforeEndIndex=${u}, afterStartIndex=${g}`);let _=(g<s.content.length?s.content.substring(g):"").startsWith(`
|
|
50
|
+
`),w=g<s.content.length&&!t.content.endsWith(`
|
|
51
|
+
`)&&!_,T=s.content.substring(0,u)+t.content+(w?`
|
|
52
|
+
`:"")+s.content.substring(g),D=s.version+1;await O(n,c.id,c.title,s.createdAt,T,D);let V=`${c.category}/${c.title}`,it=`\u5DF2\u66F4\u65B0\u6D77\u9A6C\u4F53 #${c.id.padStart(3,"0")}
|
|
53
|
+
\u8DEF\u5F84: ${V}
|
|
53
54
|
\u65B0\u7248\u672C: ${D}`;return await l("info",`[haimati_edit] \u51FA\u53C2:
|
|
54
|
-
${
|
|
55
|
-
\u5806\u6808: ${
|
|
56
|
-
${
|
|
57
|
-
${d.slice(0,10).map(u=>` - ${u.category}/${u.title} [${u.id}]`).join(`
|
|
58
|
-
`)}`}}if(!
|
|
59
|
-
${
|
|
55
|
+
${$(it)}`),it}catch(e){let i=e instanceof Error?e.message:String(e),r=e instanceof Error?e.stack:"";return await l("error",`[haimati_edit] \u51FA\u53C2: \u9519\u8BEF: ${i}
|
|
56
|
+
\u5806\u6808: ${r}`),`\u9519\u8BEF: ${i}`}}}),haimati_delete:E({description:"\u5220\u9664\u6D77\u9A6C\u4F53\u4E2D\u7684\u8BB0\u5FC6\u3002\u901A\u8FC7\u5E8F\u53F7\uFF08\u5982 '086'\uFF09\u6216\u5B8C\u6574\u8DEF\u5F84\uFF08\u5982 'xxx\u9879\u76EE/\u7B7E\u7AE0/\u7B7E\u7AE0\u670D\u52A1WS\u901A\u4FE1\u673A\u5236'\uFF09\u6765\u5B9A\u4F4D\u8981\u5220\u9664\u7684\u8BB0\u5FC6\u3002",args:{query:E.schema.string().describe("\u5E8F\u53F7\u6216\u5B8C\u6574\u8DEF\u5F84\uFF0C\u7528\u4E8E\u5B9A\u4F4D\u8981\u5220\u9664\u7684\u8BB0\u5FC6")},async execute(t,o){let{directory:n}=o,a=S(n);if(await l("info",`[haimati_delete] \u5165\u53C2: query="${t.query}"`),!await x(a)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await l("warn",`[haimati_delete] \u51FA\u53C2:
|
|
57
|
+
${$(e)}`),e}try{let e=await b(n),i=t.query.trim(),r=null;if(/^\d+$/.test(i))r=L(e,String(parseInt(i,10)));else{let f=i.split("/").filter(Boolean);if(f.length>=2){let d=f.pop(),h=f.join("/");r=U(e,h,d)}else{let d=await K(e,i,"or",n);if(d.length===1)r=d[0];else if(d.length>1)return`\u627E\u5230\u591A\u6761\u5339\u914D\uFF0C\u8BF7\u4F7F\u7528\u5E8F\u53F7\u7CBE\u786E\u6307\u5B9A\uFF1A
|
|
58
|
+
${d.slice(0,10).map(u=>` - ${u.category}/${u.title} [${u.id.padStart(3,"0")}]`).join(`
|
|
59
|
+
`)}`}}if(!r){let f=`\u672A\u627E\u5230\u4E0E '${i}' \u76F8\u5173\u7684\u8BB0\u5FC6`;return await l("info",`[haimati_delete] \u51FA\u53C2:
|
|
60
|
+
${$(f)}`),f}await It(n,r.id);let c=xt(e,r.id);await j(n,c);let s=`${r.category}/${r.title}`,m=`\u5DF2\u5220\u9664\u6D77\u9A6C\u4F53 #${r.id.padStart(3,"0")}
|
|
60
61
|
\u8DEF\u5F84: ${s}`;return await l("info",`[haimati_delete] \u51FA\u53C2:
|
|
61
|
-
${
|
|
62
|
-
\u5806\u6808: ${
|
|
63
|
-
${
|
|
64
|
-
${
|
|
65
|
-
`)}`}}if(!
|
|
66
|
-
${
|
|
62
|
+
${$(m)}`),m}catch(e){let i=e instanceof Error?e.message:String(e),r=e instanceof Error?e.stack:"";return await l("error",`[haimati_delete] \u51FA\u53C2: \u9519\u8BEF: ${i}
|
|
63
|
+
\u5806\u6808: ${r}`),`\u9519\u8BEF: ${i}`}}}),haimati_move:E({description:"\u4FEE\u6539\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7684\u5206\u7C7B\u8DEF\u5F84\u3002\u901A\u8FC7\u5E8F\u53F7\u6216\u5B8C\u6574\u8DEF\u5F84\u5B9A\u4F4D\u8BB0\u5FC6\uFF0C\u7136\u540E\u5C06\u5176\u79FB\u52A8\u5230\u65B0\u7684\u5206\u7C7B\u3002",args:{query:E.schema.string().describe("\u5E8F\u53F7\u6216\u5B8C\u6574\u8DEF\u5F84\uFF0C\u7528\u4E8E\u5B9A\u4F4D\u8981\u79FB\u52A8\u7684\u8BB0\u5FC6"),newCategory:E.schema.string().describe("\u65B0\u7684\u5206\u7C7B\u8DEF\u5F84\uFF0C\u5982 'xxx\u9879\u76EE/\u5BA2\u6237\u7AEF' \u6216 '\u901A\u7528'")},async execute(t,o){let{directory:n}=o,a=S(n);if(await l("info",`[haimati_move] \u5165\u53C2: query="${t.query}", newCategory="${t.newCategory}"`),!await x(a)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await l("warn",`[haimati_move] \u51FA\u53C2:
|
|
64
|
+
${$(e)}`),e}try{let e=await b(n),i=t.query.trim(),r=null;if(/^\d+$/.test(i))r=L(e,String(parseInt(i,10)));else{let u=i.split("/").filter(Boolean);if(u.length>=2){let g=u.pop(),y=u.join("/");r=U(e,y,g)}else{let g=await K(e,i,"or",n);if(g.length===1)r=g[0];else if(g.length>1)return`\u627E\u5230\u591A\u6761\u5339\u914D\uFF0C\u8BF7\u4F7F\u7528\u5E8F\u53F7\u7CBE\u786E\u6307\u5B9A\uFF1A
|
|
65
|
+
${g.slice(0,10).map(p=>` - ${p.category}/${p.title} [${p.id.padStart(3,"0")}]`).join(`
|
|
66
|
+
`)}`}}if(!r){let u=`\u672A\u627E\u5230\u4E0E '${i}' \u76F8\u5173\u7684\u8BB0\u5FC6`;return await l("info",`[haimati_move] \u51FA\u53C2:
|
|
67
|
+
${$(u)}`),u}let s=`${r.category}/${r.title}`,m=t.newCategory,f=`${m}/${r.title}`,d=e.map(u=>u.id===r.id?{...u,category:m}:u);await j(n,d);let h=`\u5DF2\u79FB\u52A8\u6D77\u9A6C\u4F53 #${r.id}
|
|
67
68
|
\u65E7\u8DEF\u5F84: ${s}
|
|
68
69
|
\u65B0\u8DEF\u5F84: ${f}`;return await l("info",`[haimati_move] \u51FA\u53C2:
|
|
69
|
-
${
|
|
70
|
-
\u5806\u6808: ${
|
|
71
|
-
${
|
|
72
|
-
`),
|
|
70
|
+
${$(h)}`),h}catch(e){let i=e instanceof Error?e.message:String(e),r=e instanceof Error?e.stack:"";return await l("error",`[haimati_move] \u51FA\u53C2: \u9519\u8BEF: ${i}
|
|
71
|
+
\u5806\u6808: ${r}`),`\u9519\u8BEF: ${i}`}}}),haimati_list:E({description:"\u5217\u51FA\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u7684\u5B8C\u6574\u7D22\u5F15\u7ED3\u6784\u3002",args:{category:E.schema.string().optional().describe("\u53EF\u9009\u7684\u5206\u7C7B\u8DEF\u5F84\uFF0C\u5217\u51FA\u8BE5\u5206\u7C7B\u4E0B\u7684\u6761\u76EE"),recursive:E.schema.boolean().optional().default(!1).describe("\u662F\u5426\u9012\u5F52\u904D\u5386\u5B50\u5206\u7C7B\uFF0C\u9ED8\u8BA4false")},async execute(t,o){let{directory:n}=o,a=S(n);if(await l("info",`[haimati_list] \u5165\u53C2: category="${t.category||"(\u65E0)"}, recursive=${t.recursive}"`),!await x(a)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await l("warn",`[haimati_list] \u51FA\u53C2:
|
|
72
|
+
${$(e)}`),e}try{let e=await b(n);if(t.category){let s=(await Et(n)).split(`
|
|
73
|
+
`),m=0,f=[];for(let g of s){if(!g.trim())continue;let y=H(g);if(g.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/))continue;let _=B(g);if(_&&(_==="/"?f[y]="":f[y]=_,f=f.slice(0,y+1),f.filter(Boolean).join("/")===t.category)){m=y;break}}let d=[],h=[];f=[];for(let g of s){if(!g.trim())continue;let y=H(g),p=g.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/);if(p){let w=p[1].trim(),T=p[2];if(y===m+1){let D=f.slice(1,y).filter(Boolean).join("/");D===t.category&&h.push({category:D,title:w,id:T})}continue}let _=B(g);_&&(_==="/"?f[y]="":f[y]=_,f=f.slice(0,y+1),y===m+1&&f.filter(Boolean).join("/")===t.category&&d.push(_))}let u=`## ${t.category}
|
|
73
74
|
|
|
74
|
-
`;if(t.recursive){let
|
|
75
|
-
`,u+=
|
|
75
|
+
`;if(t.recursive){let g=e.filter(p=>p.category===t.category||p.category.startsWith(t.category+"/")),y=new Map;for(let p of g){let w=p.category.slice(t.category.length+1).split("/")[0]||"(\u76F4\u63A5)";y.has(w)||y.set(w,[]),y.get(w).push(p)}for(let[p,_]of y)u+=`### ${p}/
|
|
76
|
+
`,u+=_.map(w=>`- ${w.title} - ${w.id.padStart(3,"0")}`).join(`
|
|
76
77
|
`)+`
|
|
77
78
|
|
|
78
79
|
`}else d.length>0&&(u+=`**\u5B50\u5206\u7C7B\uFF1A**
|
|
79
|
-
`+d.map(
|
|
80
|
+
`+d.map(g=>`- ${g}/`).join(`
|
|
80
81
|
`)+`
|
|
81
82
|
|
|
82
|
-
`),
|
|
83
|
-
`+
|
|
83
|
+
`),h.length>0&&(u+=`**\u76F4\u63A5\u6761\u76EE\uFF1A**
|
|
84
|
+
`+h.map(g=>`- ${g.title} - ${g.id.padStart(3,"0")}`).join(`
|
|
84
85
|
`));return await l("info",`[haimati_list] \u51FA\u53C2:
|
|
85
|
-
${
|
|
86
|
+
${$(u)}`),u}let r=`## \u6D77\u9A6C\u4F53\u7D22\u5F15
|
|
87
|
+
|
|
88
|
+
${Z(e)||"(\u7A7A)"}`;return await l("info",`[haimati_list] \u51FA\u53C2:
|
|
89
|
+
${$(r)}`),r}catch(e){let i=e instanceof Error?e.message:String(e),r=e instanceof Error?e.stack:"";return await l("error",`[haimati_list] \u51FA\u53C2: \u9519\u8BEF: ${i}
|
|
90
|
+
\u5806\u6808: ${r}`),`\u9519\u8BEF: ${i}`}}})}}var rt=new Map,N=new Map,en=async t=>(await l("info","\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u63D2\u4EF6(\u6587\u4EF6\u7248)debug\u7248\u672C04091401\u5DF2\u52A0\u8F7D"),{tool:Dt(),"chat.message":async(n,a)=>{let{message:e,parts:i}=a,r=e.sessionID,c=e.id;await l("debug",`[chat.message] chat.message sessionID=${r}, sessionDirectories.size=${N.size}, keys: ${Array.from(N.keys()).join(",")}`);let s=N.get(r)||process.cwd(),m=gt(s),f=ht(s),d=f!==null?f:dt;if(await l("debug",`[chat.message] \u9879\u76EE\u76EE\u5F55: ${s}, AUTO_ENHANCE_FIRST_MESSAGE \u914D\u7F6E: ${m}, \u524D\u7F00\u6587\u672C: ${d}`),m===!0)try{if(rt.get(r)===c){await l("debug",`[chat.message] \u4F1A\u8BDD ${r} \u7684\u6D88\u606F ${c} \u5DF2\u589E\u5F3A\u8FC7\uFF0C\u8DF3\u8FC7`);return}let h=i.some(u=>u.type==="text"&&u.text);if(await l("debug",`[chat.message] sessionId=${r}, messageId=${c}, parts=${JSON.stringify(i)}, hasUserContent=${h}`),!h){await l("debug",`[chat.message] \u6D88\u606F ${c} \u4E0D\u5305\u542B\u7528\u6237\u5185\u5BB9\uFF0C\u8DF3\u8FC7`);return}if(rt.has(r)){await l("debug",`[chat.message] \u4F1A\u8BDD ${r} \u5DF2\u589E\u5F3A\u8FC7\uFF0C\u4E0D\u662F\u9996\u6761\u7528\u6237\u6D88\u606F\uFF0C\u8DF3\u8FC7`);return}await l("info",`[chat.message] \u589E\u5F3A\u4F1A\u8BDD ${r} \u7684\u9996\u6761\u7528\u6237\u6D88\u606F ${c}`);for(let u of i)u.type==="text"&&(u.text=d+`
|
|
86
91
|
|
|
87
|
-
${
|
|
88
|
-
${w(o)}`),o}catch(e){let r=e instanceof Error?e.message:String(e),o=e instanceof Error?e.stack:"";return await l("error",`[haimati_list] \u51FA\u53C2: \u9519\u8BEF: ${r}
|
|
89
|
-
\u5806\u6808: ${o}`),`\u9519\u8BEF: ${r}`}}})}}var Ke=async t=>(await l("info","\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u63D2\u4EF6(\u6587\u4EF6\u7248)debug\u7248\u672C04091356\u5DF2\u52A0\u8F7D"),{tool:bt(),event:async({event:n})=>{if(n.type==="session.created")try{let a=n.properties?.info?.id;if(!a){await l("warn","[session.created] \u65E0\u6CD5\u83B7\u53D6 sessionID\uFF0C\u8DF3\u8FC7\u6CE8\u5165");return}if(!!1){await l("info","[session.created] \u81EA\u52A8\u6CE8\u5165\u5DF2\u5173\u95ED\uFF0C\u8DF3\u8FC7\u6CE8\u5165 (AUTO_INJECT_CONTEXT=false)");return}await t.client.session.prompt({path:{id:a},body:{noReply:!0,parts:[{type:"text",text:`## \u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u4F7F\u7528\u89C4\u5219
|
|
92
|
+
`+u.text,await l("debug",`[chat.message] \u5DF2\u589E\u5F3A part ${u.id}\uFF0C\u524D\u7F00\u957F\u5EA6=${d.length}`));rt.set(r,c),await l("info",`[chat.message] \u5B8C\u6210\u9996\u6761\u6D88\u606F\u589E\u5F3A (sessionID: ${r}, messageID: ${c})`)}catch(h){let u=h instanceof Error?h.message:String(h);await l("error",`[chat.message] \u589E\u5F3A\u9996\u6761\u6D88\u606F\u5931\u8D25: ${u}`)}},event:async({event:n})=>{if(n.type==="session.created")try{await l("debug",`[session.created] \u4E8B\u4EF6\u5C5E\u6027: ${JSON.stringify(n.properties)}`);let a=n.properties?.info?.id,e=n.properties?.info?.directory;if(await l("debug",`[session.created] \u5C1D\u8BD5\u4FDD\u5B58\u4F1A\u8BDD\u76EE\u5F55: evt.properties.sessionID=${n.properties?.sessionID}, info.id=${a}, directory=${e}`),await l("debug",`[session.created] sessionDirectories.size=${N.size}, \u73B0\u6709key: ${Array.from(N.keys()).join(",")}`),e&&(N.set(a,e),await l("debug",`[session.created] \u4FDD\u5B58\u4F1A\u8BDD\u76EE\u5F55\u5B8C\u6210: sessionID=${a}, directory=${e}`)),!a){await l("warn","[session.created] \u65E0\u6CD5\u83B7\u53D6 sessionID\uFF0C\u8DF3\u8FC7\u6CE8\u5165");return}if(!!1){await l("info","[session.created] \u81EA\u52A8\u6CE8\u5165\u5DF2\u5173\u95ED\uFF0C\u8DF3\u8FC7\u6CE8\u5165 (AUTO_INJECT_CONTEXT=false)");return}await t.client.session.prompt({path:{id:a},body:{noReply:!0,parts:[{type:"text",text:`## \u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u4F7F\u7528\u89C4\u5219
|
|
90
93
|
|
|
91
94
|
\u4F60\u6709\u4E00\u4E2A\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u53EF\u7528\uFF0C\u7528\u4E8E\u5B58\u50A8\u548C\u68C0\u7D22\u8DE8\u4F1A\u8BDD\u7684\u77E5\u8BC6\u3002
|
|
92
95
|
|
|
@@ -120,4 +123,4 @@ ${w(o)}`),o}catch(e){let r=e instanceof Error?e.message:String(e),o=e instanceof
|
|
|
120
123
|
|
|
121
124
|
**\u4F1A\u8BDD\u5F00\u59CB\u524D**: \u4F7F\u7528 haimati_list \u6216 haimati_search \u8BFB\u53D6\u4E0E\u5F53\u524D\u4EFB\u52A1\u76F8\u5173\u7684\u8BB0\u5FC6\u5185\u5BB9\uFF0C\u518D\u5F00\u59CB\u5DE5\u4F5C\u3002
|
|
122
125
|
|
|
123
|
-
**\u4F1A\u8BDD\u7ED3\u675F\u540E**: \u4F7F\u7528 haimati_write \u5C06\u65B0\u83B7\u5F97\u7684\u77E5\u8BC6\u3001\u7ECF\u9A8C\u3001\u51B3\u7B56\u5199\u5165\u6D77\u9A6C\u4F53\uFF0C\u4FDD\u6301\u4FE1\u606F\u7684\u6301\u7EED\u79EF\u7D2F\u3002`}]}}),await l("info",`[session.created] \u6D77\u9A6C\u4F53\u89C4\u5219\u5DF2\u6CE8\u5165\u65B0\u4F1A\u8BDD (sessionID: ${a})`)}catch(a){let e=a instanceof Error?a.message:String(a);await l("error",`[session.created] \u6CE8\u5165\u6D77\u9A6C\u4F53\u89C4\u5219\u5931\u8D25: ${e}`)}}});export{
|
|
126
|
+
**\u4F1A\u8BDD\u7ED3\u675F\u540E**: \u4F7F\u7528 haimati_write \u5C06\u65B0\u83B7\u5F97\u7684\u77E5\u8BC6\u3001\u7ECF\u9A8C\u3001\u51B3\u7B56\u5199\u5165\u6D77\u9A6C\u4F53\uFF0C\u4FDD\u6301\u4FE1\u606F\u7684\u6301\u7EED\u79EF\u7D2F\u3002`}]}}),await l("info",`[session.created] \u6D77\u9A6C\u4F53\u89C4\u5219\u5DF2\u6CE8\u5165\u65B0\u4F1A\u8BDD (sessionID: ${a})`)}catch(a){let e=a instanceof Error?a.message:String(a);await l("error",`[session.created] \u6CE8\u5165\u6D77\u9A6C\u4F53\u89C4\u5219\u5931\u8D25: ${e}`)}}});export{en as HaimatiPlugin};
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-haimati",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "OpenCode plugin for a file-based memory system inspired by the hippocampus, providing long-term memory storage and retrieval across sessions.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-haimati",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "OpenCode plugin for a file-based memory system inspired by the hippocampus, providing long-term memory storage and retrieval across sessions.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|