opencode-haimati 1.1.5 → 1.2.1
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 +107 -99
- package/dist/index.js +73 -79
- package/dist/package.json +28 -27
- package/package.json +28 -27
package/README.md
CHANGED
|
@@ -1,99 +1,107 @@
|
|
|
1
|
-
# opencode-haimati
|
|
2
|
-
|
|
3
|
-
为 OpenCode 提供基于文件系统的长期记忆存储和检索功能。
|
|
4
|
-
|
|
5
|
-
## 功能特性
|
|
6
|
-
|
|
7
|
-
- 类海马体记忆机制:模拟人脑记忆系统的分类存储
|
|
8
|
-
- 树形索引结构 + 分组书页存储
|
|
9
|
-
- 多模式搜索:序号精确查询 + 关键字模糊搜索
|
|
10
|
-
- 完整 CRUD:读取、写入、更新、删除、移动
|
|
11
|
-
- 版本并发控制:基于 version 的乐观锁
|
|
12
|
-
- 自动增强首条提示词 + 会话空闲时自动提示记录
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
├──
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
|
54
|
-
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
-
|
|
99
|
-
|
|
1
|
+
# opencode-haimati
|
|
2
|
+
|
|
3
|
+
为 OpenCode 提供基于文件系统的长期记忆存储和检索功能。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- 类海马体记忆机制:模拟人脑记忆系统的分类存储
|
|
8
|
+
- 树形索引结构 + 分组书页存储
|
|
9
|
+
- 多模式搜索:序号精确查询 + 关键字模糊搜索
|
|
10
|
+
- 完整 CRUD:读取、写入、更新、删除、移动
|
|
11
|
+
- 版本并发控制:基于 version 的乐观锁
|
|
12
|
+
- 自动增强首条提示词 + 会话空闲时自动提示记录
|
|
13
|
+
- 文件锁机制:支持网络共享挂载多用户并发写入
|
|
14
|
+
- 用户停止检测:自动跳过已停止的会话
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g opencode-haimati
|
|
20
|
+
# 或
|
|
21
|
+
bun add -g opencode-haimati
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 配置
|
|
25
|
+
|
|
26
|
+
在 `opencode.json` 中添加插件:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"$schema": "https://opencode.ai/config.json",
|
|
31
|
+
"plugin": ["opencode-haimati"]
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
在项目根目录创建 `opencode-haimati.conf`(可选):
|
|
36
|
+
|
|
37
|
+
```ini
|
|
38
|
+
haimati-path: .haimati
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 目录结构
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
.haimati/
|
|
45
|
+
├── .lock # 文件锁(支持网络共享挂载多用户协调)
|
|
46
|
+
├── 索引.md # 树形索引
|
|
47
|
+
├── next-id.txt # 下一个序号
|
|
48
|
+
└── 书页/ # 记忆内容(每50个序号一分组)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 工具
|
|
52
|
+
|
|
53
|
+
| 工具 | 说明 |
|
|
54
|
+
|------|------|
|
|
55
|
+
| `haimati_read` | 读取记忆(序号查询,支持分页) |
|
|
56
|
+
| `haimati_write` | 写入记忆(不允许覆盖已存在) |
|
|
57
|
+
| `haimati_search` | 搜索(标题/分类/内容,match必填) |
|
|
58
|
+
| `haimati_edit` | 部分修改(需 version 并发控制) |
|
|
59
|
+
| `haimati_move` | 修改分类路径 |
|
|
60
|
+
| `haimati_delete` | 删除记忆 |
|
|
61
|
+
| `haimati_list` | 列出索引 |
|
|
62
|
+
|
|
63
|
+
## 使用示例
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// 写入(title 不能以 " - 序号" 结尾)
|
|
67
|
+
haimati_write({ category: "xxx项目/签章", title: "签章服务WS通信机制", content: "..." })
|
|
68
|
+
|
|
69
|
+
// 读取
|
|
70
|
+
haimati_read({ query: "086" })
|
|
71
|
+
|
|
72
|
+
// 搜索
|
|
73
|
+
haimati_search({ keyword: "WebSocket", match: "or" })
|
|
74
|
+
|
|
75
|
+
// 修改(先 read 获取 version)
|
|
76
|
+
haimati_edit({ query: "086", offsetBegin: 3, offsetEnd: 5, content: "新内容", version: 1 })
|
|
77
|
+
|
|
78
|
+
// 移动
|
|
79
|
+
haimati_move({ query: "086", newCategory: "xxx项目/客户端" })
|
|
80
|
+
|
|
81
|
+
// 删除
|
|
82
|
+
haimati_delete({ query: "086" })
|
|
83
|
+
|
|
84
|
+
// 列出
|
|
85
|
+
haimati_list({ category: "xxx项目", recursive: true })
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 海马体三大原则
|
|
89
|
+
|
|
90
|
+
1. **信息不丢失**: 完整保留所有有价值的信息
|
|
91
|
+
2. **错误信息修正**: 不再保留已被纠正的错误信息
|
|
92
|
+
3. **拒绝冗余**: 不要重复记录相同内容
|
|
93
|
+
|
|
94
|
+
## 日志
|
|
95
|
+
|
|
96
|
+
日志位于:`~/.opencode-haimati/log/{yyyy-MM-dd}.log`(按天轮转)
|
|
97
|
+
|
|
98
|
+
日志配置位于:`~/.opencode-haimati/log.conf`
|
|
99
|
+
```
|
|
100
|
+
level: info # 日志级别:debug、info、warn、error
|
|
101
|
+
log_retention_days: 180 # 日志保留天数
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 依赖
|
|
105
|
+
|
|
106
|
+
- OpenCode v0.15.0+
|
|
107
|
+
- Node.js 或 Bun
|
package/dist/index.js
CHANGED
|
@@ -1,90 +1,84 @@
|
|
|
1
|
-
import{tool as
|
|
2
|
-
`);for(let
|
|
3
|
-
`),
|
|
4
|
-
`),c=[];for(let
|
|
5
|
-
`)}async function M(
|
|
6
|
-
`);if(
|
|
7
|
-
`);return{title:h,createdAt:
|
|
8
|
-
`);return{title:m,createdAt:"",content:w,version:1}}if(o+3>=
|
|
9
|
-
`),u=
|
|
1
|
+
import{tool as x}from"@opencode-ai/plugin";import E from"path";import mt from"os";import A from"fs";var q=".haimati",lt="\u7D22\u5F15.md";var dt="next-id.txt",ft="log.conf";var ut="opencode-haimati.conf",gt="haimati-path";var N="/start-work";var W="/record-memory";function jt(t){let s=E.join(t,ut);if(!A.existsSync(s))return null;try{let c=A.readFileSync(s,"utf-8").split(`
|
|
2
|
+
`);for(let e of c){let r=e.trim();if(!r||r.startsWith("#"))continue;let a=r.match(/^([^:]+):\s*(.+)$/);if(a){let o=a[1].trim(),l=a[2].trim();if(o===gt&&l){let u=l.match(/^\$\{(\w+)\}$/);if(u){let d=process.env[u[1]];return d?E.resolve(t,d):(console.warn(`[haimati] \u73AF\u5883\u53D8\u91CF ${u[1]} \u672A\u5B9A\u4E49\u6216\u503C\u4E3A\u7A7A`),null)}return E.resolve(t,l)}}}}catch(n){console.error("[haimati] \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6\u5931\u8D25:",n)}return null}function L(t){let s=jt(t);return s||E.join(t,q)}function P(t){return E.join(L(t),lt)}function G(t){return E.join(L(t),dt)}function nt(t){return E.join(L(t),".lock")}function it(t){return E.join(L(t),"\u4E66\u9875")}function O(t,s){let n=parseInt(s,10),c=Math.floor((n-1)/50)*50+1,e=c+50-1,r=`${String(c).padStart(3,"0")}-${String(e).padStart(3,"0")}`;return E.join(it(t),r)}function B(t,s){let n=String(parseInt(s,10)).padStart(3,"0");return E.join(O(t,s),`${n}.md`)}function rt(){let t=mt.homedir();return E.join(t,".opencode-haimati","log")}function qt(){let t=mt.homedir();return E.join(t,".opencode-haimati",ft)}function st(){let t=qt(),s={level:"info",logRetentionDays:180};if(!A.existsSync(t))return s;try{let c=A.readFileSync(t,"utf-8").split(`
|
|
3
|
+
`),e=s.level,r=s.logRetentionDays;for(let a of c){let o=a.trim();if(!o||o.startsWith("#"))continue;let l=o.match(/^([^:]+):\s*(.+)$/);if(l){let u=l[1].trim(),d=l[2].trim();if(u==="level")["debug","info","warn","error"].includes(d)&&(e=d);else if(u==="log_retention_days"){let f=parseInt(d,10);!isNaN(f)&&f>0&&(r=f)}}}return{level:e,logRetentionDays:r}}catch(n){return console.error("[haimati] \u8BFB\u53D6\u65E5\u5FD7\u914D\u7F6E\u5931\u8D25:",n),s}}function v(t){return A.promises.mkdir(t,{recursive:!0}).then(()=>{})}function $(t){return A.promises.access(t).then(()=>!0).catch(()=>!1)}import ht from"fs";import Wt from"path";import{promisify as pt}from"util";var wt=pt(ht.readFile),Gt=pt(ht.writeFile);function H(t){let s=0,n=0,c=t.length;for(;n<c;)if(t[n]==="\u2502"&&n+3<c&&t.slice(n+1,n+4)===" ")s++,n+=4;else if(t.slice(n,n+4)===" ")s++,n+=4;else{if((t[n]==="\u251C"||t[n]==="\u2514")&&n+3<c&&t.slice(n+1,n+4)==="\u2500\u2500 ")break;break}return s}function J(t){let n=t.trim().replace(/^[│├└─\s]+/,"").trim();return n==="/"?"/":!n.endsWith("/")||(n=n.slice(0,-1),!n)?null:n}function Bt(t){let s=[],n=t.split(`
|
|
4
|
+
`),c=[];for(let e of n){if(!e.trim())continue;let r=H(e),a=e.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/);if(a){let o=a[1].trim(),l=String(parseInt(a[2],10)),d=c.slice(0,r).filter(f=>f!=="").join("/");s.push({id:l,category:d,title:o})}else{let o=J(e);if(o)if(o==="/"){c[r]="";for(let l=r+1;l<c.length;l++)delete c[l]}else{c[r]=o;for(let l=r+1;l<c.length;l++)delete c[l]}}}return s}function R(t,s){return t.find(n=>n.id===s)||null}function U(t,s,n){return t.find(c=>c.category===s&&c.title===n)||null}function yt(t,s){return t.filter(n=>n.id!==s)}function ot(t){if(t.length===0)return"";let s={name:"/",children:[],entry:null};for(let e of t){let r=e.category.split("/"),a=s;for(let l=0;l<r.length;l++){let u=r[l];if(!u)continue;let d=a.children.find(f=>f.name===u);d||(d={name:u,children:[],entry:null},a.children.push(d)),a=d}let o={name:e.id,children:[],entry:e};a.children.push(o)}function n(e){e.children.sort((r,a)=>r.name.localeCompare(a.name,void 0,{sensitivity:"base"}));for(let r of e.children)n(r)}n(s);function c(e,r,a){let o=[],l=r+(a?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 "),u=e.name==="/"?"/":e.name+"/";o.push(`${l}${u}`),r=r+(a?" ":"\u2502 ");let d=e.children.filter(g=>g.entry===null),f=e.children.filter(g=>g.entry!==null),p=[...d,...f];for(let g=0;g<p.length;g++){let m=p[g],w=g===p.length-1;if(m.entry){let h=m.entry.id.padStart(3,"0"),I=r+(w?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ");o.push(`${I}${m.entry.title} - ${h}`)}else o.push(...c(m,r,w))}return o}return c(s,"",!0).join(`
|
|
5
|
+
`)}async function M(t){let s=P(t);if(!await $(s))return[];let n=await wt(s,"utf-8");return Bt(n)}async function F(t,s){let n=Wt.join(t,q);await $(n)||await v(n);let c=ot(s),e=P(t);await Gt(e,c,"utf-8")}async function $t(t){let s=P(t);return await $(s)?wt(s,"utf-8"):""}import K from"fs";import{promisify as Y}from"util";var Ht=Y(K.readFile),Jt=Y(K.writeFile),Ut=Y(K.unlink),xt=Y(K.mkdir);async function C(t,s){let n=B(t,s);if(!await $(n))return null;let e=(await Ht(n,"utf-8")).split(`
|
|
6
|
+
`);if(e.length<4)return null;let r="------system------",a=Math.max(0,e.length-5),o=-1;for(let g=e.length-1;g>=a;g--)if(e[g].trim()===r){o=g;break}if(o===-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 h=e[0],I=e[1],y=parseInt(e[2].substring(8).trim(),10)||1,D=e.slice(3).join(`
|
|
7
|
+
`);return{title:h,createdAt:I,content:D,version:y}}let m=e[0],w=e.join(`
|
|
8
|
+
`);return{title:m,createdAt:"",content:w,version:1}}if(o+3>=e.length)return null;let l=e.slice(0,o).join(`
|
|
9
|
+
`),u=e[o+1],d=e[o+2],f=e[o+3],p=parseInt(f.substring(8).trim(),10)||1;return{title:u,createdAt:d,content:l,version:p}}async function j(t,s,n,c,e,r=1){let a=it(t);await $(a)||await xt(a,{recursive:!0});let o=O(t,s);await $(o)||await xt(o,{recursive:!0});let l=B(t,s),d=`------system------
|
|
10
10
|
${n}
|
|
11
11
|
${c}
|
|
12
|
-
version:${r}`,
|
|
13
|
-
${
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`),
|
|
20
|
-
`);return await
|
|
21
|
-
${
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
`);
|
|
25
|
-
\
|
|
26
|
-
\
|
|
27
|
-
${
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
\
|
|
31
|
-
${
|
|
32
|
-
${
|
|
33
|
-
`),
|
|
34
|
-
`)
|
|
35
|
-
|
|
36
|
-
`)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
${
|
|
42
|
-
${$
|
|
43
|
-
${
|
|
44
|
-
`).length;if(
|
|
45
|
-
|
|
46
|
-
${
|
|
47
|
-
|
|
48
|
-
`),x=
|
|
49
|
-
`)
|
|
50
|
-
|
|
51
|
-
\
|
|
52
|
-
\
|
|
53
|
-
${
|
|
54
|
-
|
|
55
|
-
${
|
|
56
|
-
${d.slice(0,10).map(
|
|
57
|
-
`)
|
|
58
|
-
${
|
|
59
|
-
\
|
|
60
|
-
|
|
61
|
-
\
|
|
62
|
-
${
|
|
63
|
-
${
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
\u65E7\u8DEF\u5F84: ${a}
|
|
67
|
-
\u65B0\u8DEF\u5F84: ${f}`;return await s("info",`[haimati_move] \u51FA\u53C2:
|
|
68
|
-
${$(p)}`),p}catch(t){let r=t instanceof Error?t.message:String(t),l=t instanceof Error?t.stack:"";return await s("error",`[haimati_move] \u51FA\u53C2: \u9519\u8BEF: ${r}
|
|
69
|
-
\u5806\u6808: ${l}`),`\u9519\u8BEF: ${r}`}}}),haimati_list:I({description:"\u5217\u51FA\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u7684\u5B8C\u6574\u7D22\u5F15\u7ED3\u6784\u3002",args:{category:I.schema.string().optional().describe("\u53EF\u9009\u7684\u5206\u7C7B\u8DEF\u5F84\uFF0C\u5217\u51FA\u8BE5\u5206\u7C7B\u4E0B\u7684\u6761\u76EE"),recursive:I.schema.boolean().optional().default(!1).describe("\u662F\u5426\u9012\u5F52\u904D\u5386\u5B50\u5206\u7C7B\uFF0C\u9ED8\u8BA4false")},async execute(e,i){let{directory:n}=i,c=L(n);if(await s("info",`[haimati_list] \u5165\u53C2: category="${e.category||"(\u65E0)"}, recursive=${e.recursive}"`),!await y(c)){let t="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await s("warn",`[haimati_list] \u51FA\u53C2:
|
|
70
|
-
${$(t)}`),t}try{let t=await M(n);if(e.category){let a=(await Tt(n)).split(`
|
|
71
|
-
`),u=0,f=[];for(let m of a){if(!m.trim())continue;let w=et(m);if(m.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/))continue;let S=nt(m);if(S&&(S==="/"?f[w]="":f[w]=S,f=f.slice(0,w+1),f.filter(Boolean).join("/")===e.category)){u=w;break}}let d=[],p=[];f=[];for(let m of a){if(!m.trim())continue;let w=et(m),h=m.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/);if(h){let x=h[1].trim(),D=h[2];if(w===u+1){let j=f.slice(1,w).filter(Boolean).join("/");j===e.category&&p.push({category:j,title:x,id:D})}continue}let S=nt(m);S&&(S==="/"?f[w]="":f[w]=S,f=f.slice(0,w+1),w===u+1&&f.filter(Boolean).join("/")===e.category&&d.push(S))}let g=`## ${e.category}
|
|
12
|
+
version:${r}`,f=e?`${e}
|
|
13
|
+
${d}`:d;await Jt(l,f,"utf-8")}async function It(t,s){let n=B(t,s);return await $(n)?(await Ut(n),!0):!1}function bt(t,s){if(s===0)return 0;let n=1,c=0;for(;c<t.length;){if(t[c]===`
|
|
14
|
+
`){if(n===s)return c+1;n++}c++}return c}function _t(t,s,n,c){let e=s===1?0:bt(t,s-1),r=bt(t,n),o=(r<t.length?t.substring(r):"").startsWith(`
|
|
15
|
+
`),l=r<t.length&&!c.endsWith(`
|
|
16
|
+
`)&&!o;return t.substring(0,e)+c+(l?`
|
|
17
|
+
`:"")+t.substring(r)}async function V(t,s,n,c,e=!1){let r=s.toLowerCase().split(/\s+/).filter(o=>o.length>0);if(r.length===0)return[];let a=[];for(let o of t){let l=o.title.toLowerCase(),u=o.category.toLowerCase(),d=o.id.toLowerCase(),f=0,p=0;for(let m of r)(l.includes(m)||u.includes(m)||d.includes(m))&&f++;if(e&&c){let m=await C(c,o.id);if(m&&m.content){let w=m.content.toLowerCase();for(let h of r)w.includes(h)&&p++}}let g=f+p;n==="and"?g>=r.length&&a.push({entry:o,score:g}):(f>0||e&&p>0)&&a.push({entry:o,score:g})}return a.sort((o,l)=>l.score-o.score),a.map(o=>o.entry)}import Ct from"fs";import{promisify as kt}from"util";import St from"fs";import{promisify as Et}from"util";var Yt=Et(St.writeFile),Vt=Et(St.unlink);async function Pt(t){let s=L(t);await $(s)||await v(s);let n=nt(t),c=Date.now(),e=50+Math.random()*20;for(;await $(n);){if(Date.now()-c>5e3)return!1;await new Promise(r=>setTimeout(r,e))}return await Yt(n,String(process.pid),"utf-8"),!0}async function Mt(t){let s=nt(t);await $(s)&&await Vt(s)}import X from"fs";import ct from"path";import{promisify as Q}from"util";var zt=Q(X.appendFile),Xt=Q(X.readdir),Qt=Q(X.unlink),Zt=Q(X.stat),Dt={debug:0,info:1,warn:2,error:3};function b(t,s=5e3){if(t.length<=s)return t;let n=Math.floor((s-20)/2);return t.substring(0,n)+"...(\u7701\u7565"+(t.length-s)+"\u5B57\u7B26)..."+t.substring(t.length-n)}function te(t){let s=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),c=String(t.getDate()).padStart(2,"0");return`${s}-${n}-${c}`}function ee(t){let s=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),c=String(t.getDate()).padStart(2,"0"),e=String(t.getHours()).padStart(2,"0"),r=String(t.getMinutes()).padStart(2,"0"),a=String(t.getSeconds()).padStart(2,"0");return`${s}-${n}-${c} ${e}:${r}:${a}`}function ne(){let t=te(new Date);return ct.join(rt(),`${t}.log`)}async function ie(t,s){try{let n=ct.dirname(t);await $(n)||await v(n),await zt(t,s+`
|
|
18
|
+
`,"utf-8")}catch(n){console.error("[haimati] \u5199\u5165\u65E5\u5FD7\u6587\u4EF6\u5931\u8D25:",n)}}async function Lt(){try{let t=st(),s=rt();if(!await $(s))return;let n=await Xt(s),e=new Date().getTime()-t.logRetentionDays*24*60*60*1e3;for(let r of n){if(!r.match(/^\d{4}-\d{2}-\d{2}\.log$/))continue;let a=ct.join(s,r);(await Zt(a)).mtime.getTime()<e&&await Qt(a)}}catch(t){console.error("[haimati] \u6E05\u7406\u5386\u53F2\u65E5\u5FD7\u5931\u8D25:",t)}}async function z(t,s,n){try{let c=st();if(Dt[t]<Dt[c.level])return;let r=ee(new Date),a=n?`[${n}] `:"",o=`[${r}] [${t.toUpperCase()}] ${a}${s}`,l=o.length>5e3?b(o):o;await ie(ne(),l),Lt().catch(u=>{console.error("[haimati] \u6E05\u7406\u5386\u53F2\u65E5\u5FD7\u5931\u8D25:",u)})}catch(c){console.error("[haimati] \u65E5\u5FD7\u8BB0\u5F55\u5931\u8D25:",c)}}var i={debug(t,s){return z("debug",t,s)},info(t,s){return z("info",t,s)},warn(t,s){return z("warn",t,s)},error(t,s){return z("error",t,s)}};async function vt(){await Lt()}var re=kt(Ct.readFile),se=kt(Ct.writeFile);async function oe(t){let s=G(t);if(!await $(s))return 1;let c=(await re(s,"utf-8")).trim(),e=parseInt(c,10);return!isNaN(e)&&e>0?e:1}async function ae(t){let s=G(t);if(await $(s))return;let n=await M(t),c=0;for(let e of n){let r=parseInt(e.id,10);r>c&&(c=r)}await Tt(t,c+1)}async function Tt(t,s){let n=L(t);await $(n)||await v(n);let c=G(t);await se(c,String(s),"utf-8")}async function Nt(t,s,n,c,e,r=!1){if(/ - \d{3}$/.test(n))throw await i.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 i.info(`[allocateIdWithLock] \u5F00\u59CB\u5206\u914D\u5E8F\u53F7: category="${s}", title="${n}"`),!await Pt(t))return await i.warn(`[allocateIdWithLock] \u83B7\u53D6\u9501\u5931\u8D25: category="${s}", title="${n}"`),null;await i.debug(`[allocateIdWithLock] \u83B7\u53D6\u9501\u6210\u529F: category="${s}", title="${n}"`);try{await ae(t);let a=await M(t),o=a.find(f=>f.category===s&&f.title===n);if(o){if(!r)throw new Error(`\u8BB0\u5FC6\u5DF2\u5B58\u5728: ${s}/${n}\uFF0C\u5982\u9700\u66F4\u65B0\u8BF7\u4F7F\u7528 haimati_edit \u5DE5\u5177`);let f=await C(t,o.id),p=f?f.createdAt:c,g=f?f.version+1:1;return await j(t,o.id,n,p,e,g),await i.info(`[allocateIdWithLock] \u66F4\u65B0\u5DF2\u6709\u6761\u76EE: #${o.id} ${s}/${n}, \u65B0\u7248\u672C: ${g}`),null}let l=await oe(t),u=String(l).padStart(3,"0");await j(t,u,n,c,e,1);let d={id:u,category:s,title:n};return a.push(d),await F(t,a),await Tt(t,l+1),await i.info(`[allocateIdWithLock] \u5206\u914D\u5E8F\u53F7\u6210\u529F: #${u} ${s}/${n}`),u}catch(a){let o=a instanceof Error?a.message:String(a);if(await i.error(`[allocateIdWithLock] \u5206\u914D\u5E8F\u53F7\u5931\u8D25: ${o}`),o.includes("\u8BB0\u5FC6\u5DF2\u5B58\u5728"))throw a;return null}finally{await Mt(t)}}function At(){return{haimati_read:x({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:x.schema.string().describe("\u5E8F\u53F7\u3002\u4F8B\u5982\uFF1A'086'"),offset:x.schema.number().optional().default(1).describe("\u8D77\u59CB\u884C\u53F7\uFF08\u9ED8\u8BA4 1\uFF09"),limit:x.schema.number().optional().default(2e3).describe("\u6700\u5927\u8BFB\u53D6\u884C\u6570\uFF08\u9ED8\u8BA4 2000\uFF09")},async execute(t,s){let{directory:n}=s,c=P(n);if(await i.info(`[haimati_read] \u5F00\u59CB\u8BFB\u53D6 #${t.query}`),await i.debug(`[haimati_read] \u5165\u53C2: query="${t.query}", offset=${t.offset||1}, limit=${t.limit||2e3}`),!await $(c)){let e=`\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728\u4E8E ${c}`;return await i.warn(`[haimati_read] \u51FA\u53C2:
|
|
19
|
+
${b(e)}`),e}try{let e=await M(n);await i.debug(`[haimati_read] \u8BFB\u53D6\u7D22\u5F15: \u5171 ${e.length} \u6761\u8BB0\u5F55`);let r=t.query.trim();if(!/^\d+$/.test(r)){let y="\u9519\u8BEF\uFF1Aquery \u5FC5\u987B\u662F\u5E8F\u53F7\uFF0C\u53EA\u652F\u6301\u5E8F\u53F7\u67E5\u8BE2";return await i.warn(`[haimati_read] \u51FA\u53C2:
|
|
20
|
+
${b(y)}`),y}let a=String(parseInt(r,10)),o=R(e,a);if(await i.debug(`[haimati_read] \u5E8F\u53F7\u67E5\u8BE2 #${r}: ${o?"\u627E\u5230":"\u672A\u627E\u5230"}`),!o){let y=`\u672A\u627E\u5230\u8BB0\u5FC6: ${t.query}`;return await i.debug(`[haimati_read] \u51FA\u53C2:
|
|
21
|
+
${b(y)}`),await i.info(`[haimati_read] \u8BFB\u53D6\u5931\u8D25: \u672A\u627E\u5230\u8BB0\u5FC6 #${t.query}`),y}let l=await C(n,o.id);if(!l){let y=`\u672A\u627E\u5230\u4E66\u9875: #${o.id.padStart(3,"0")}`;return await i.error(`[haimati_read] \u51FA\u53C2:
|
|
22
|
+
${b(y)}`),y}let u=O(n,o.id);await i.debug(`[haimati_read] \u8BFB\u53D6\u4E66\u9875: \u4E66\u9875/${u.split(/[\\/]/).pop()}/${o.id}.md, version=${l.version}`);let d=l.content.split(`
|
|
23
|
+
`),f=t.offset||1,p=t.limit||2e3,g=d.length,m=Math.max(0,f-1),w=Math.min(g,m+p),h=[];for(let y=m;y<w;y++)h.push(`${y+1}|${d[y]}`);h.push("------system------"),h.push(`\u6807\u9898:${o.title}`),h.push(`\u521B\u5EFA\u65F6\u95F4:${l.createdAt}`),h.push(`version:${l.version}`);let I=h.join(`
|
|
24
|
+
`);return await i.debug(`[haimati_read] \u51FA\u53C2:
|
|
25
|
+
${b(I)}`),await i.info(`[haimati_read] \u8BFB\u53D6\u6210\u529F: #${o.id} (${o.category}/${o.title}), version=${l.version}`),I}catch(e){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e.stack:"";return await i.error(`[haimati_read] \u51FA\u53C2: \u9519\u8BEF: ${r}
|
|
26
|
+
\u5806\u6808: ${a}`),`\u9519\u8BEF: ${r}`}}}),haimati_write:x({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:x.schema.string().describe("\u5206\u7C7B\u8DEF\u5F84\uFF0C\u5982 'xxx\u9879\u76EE/\u7B7E\u7AE0' \u6216 '\u901A\u7528'"),title:x.schema.string().describe("\u8BB0\u5FC6\u6807\u9898\uFF0C\u5982 '\u7B7E\u7AE0\u670D\u52A1WS\u901A\u4FE1\u673A\u5236'"),content:x.schema.string().describe("\u8981\u5199\u5165\u7684\u8BE6\u7EC6\u5185\u5BB9")},async execute(t,s){let{directory:n}=s;await i.info(`[haimati_write] \u5F00\u59CB\u5199\u5165 ${t.category}/${t.title}`),await i.debug(`[haimati_write] \u5165\u53C2: category="${t.category}", title="${t.title}", content\u957F\u5EA6=${t.content.length}\u5B57\u7B26, content=
|
|
27
|
+
${b(t.content)}
|
|
28
|
+
`);try{let c=new Date().toLocaleString("zh-CN",{hour12:!1}),e=null;for(let l=0;l<3;l++)try{if(e=await Nt(n,t.category,t.title,c,t.content,!1),e)break;await i.warn(`[haimati_write] \u9501\u83B7\u53D6\u5931\u8D25\uFF0C\u91CD\u8BD5\u7B2C ${l+1} \u6B21`)}catch(u){let d=u instanceof Error?u.message:String(u);if(d.includes("\u8BB0\u5FC6\u5DF2\u5B58\u5728"))throw u;await i.warn(`[haimati_write] \u83B7\u53D6\u9501\u5F02\u5E38: ${d}, \u91CD\u8BD5\u7B2C ${l+1} \u6B21`)}if(e){let l=O(n,e);await i.debug(`[haimati_write] \u5206\u914D\u65B0\u5E8F\u53F7: #${e}`),await i.debug(`[haimati_write] \u4E66\u9875\u548C\u7D22\u5F15\u5DF2\u66F4\u65B0: \u4E66\u9875/${l.split(/[\\/]/).pop()}/${e}.md`);let u=`\u5DF2\u5199\u5165\u6D77\u9A6C\u4F53 #${e}
|
|
29
|
+
\u8DEF\u5F84: ${t.category}/${t.title}
|
|
30
|
+
\u7248\u672C: 1`;return await i.debug(`[haimati_write] \u51FA\u53C2:
|
|
31
|
+
${b(u)}`),await i.info(`[haimati_write] \u5199\u5165\u6210\u529F: #${e} (${t.category}/${t.title})`),u}let r=await M(n),a=U(r,t.category,t.title);if(a){let l=`\u9519\u8BEF\uFF1A\u8BB0\u5FC6\u5DF2\u5B58\u5728 #${a.id} (${t.category}/${t.title})\uFF0C\u5982\u9700\u66F4\u65B0\u8BF7\u4F7F\u7528 haimati_edit \u5DE5\u5177`;return await i.error(`[haimati_write] \u51FA\u53C2:
|
|
32
|
+
${b(l)}`),l}let o="\u9519\u8BEF\uFF1A\u65E0\u6CD5\u5206\u914D\u5E8F\u53F7\uFF08\u9501\u7B49\u5F85\u8D85\u65F6\uFF09";return await i.error(`[haimati_write] \u51FA\u53C2:
|
|
33
|
+
${b(o)}`),o}catch(c){let e=c instanceof Error?c.message:String(c),r=c instanceof Error?c.stack:"";return await i.error(`[haimati_write] \u51FA\u53C2: \u9519\u8BEF: ${e}
|
|
34
|
+
\u5806\u6808: ${r}`),`\u9519\u8BEF: ${e}`}}}),haimati_search:x({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:x.schema.string().describe("\u641C\u7D22\u5173\u952E\u8BCD\uFF08\u652F\u6301\u591A\u5173\u952E\u5B57\uFF0C\u7528\u7A7A\u683C\u5206\u9694\uFF09"),match:x.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:x.schema.number().default(10).describe("\u8FD4\u56DE\u7ED3\u679C\u6570\u91CF\u9650\u5236"),offset:x.schema.number().default(0).describe("\u5206\u9875\u504F\u79FB\u91CF\uFF0C\u7528\u4E8E\u83B7\u53D6\u540E\u7EED\u9875\u9762")},async execute(t,s){let{directory:n}=s,c=P(n);if(await i.info(`[haimati_search] \u5F00\u59CB\u641C\u7D22 "${t.keyword}"`),await i.debug(`[haimati_search] \u5165\u53C2: keyword="${t.keyword}", match="${t.match}", limit=${t.limit||10}, offset=${t.offset||0}`),!await $(c)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await i.warn(`[haimati_search] \u51FA\u53C2:
|
|
35
|
+
${b(e)}`),await i.info("[haimati_search] \u641C\u7D22\u5931\u8D25: \u7D22\u5F15\u4E0D\u5B58\u5728"),e}try{let e=await M(n),r=t.keyword.trim(),a=t.match,o=t.limit||10,l=t.offset||0,u=await V(e,r,a,n,!0),d=u.length,f=u.slice(l,l+o);if(f.length===0){let h=`\u672A\u627E\u5230\u5305\u542B '${r}' \u7684\u8BB0\u5FC6`;return await i.debug(`[haimati_search] \u51FA\u53C2:
|
|
36
|
+
${b(h)}`),await i.info("[haimati_search] \u641C\u7D22\u5B8C\u6210: \u672A\u627E\u5230\u5339\u914D"),h}let p=[],g=l+f.length<d,m=g?`${l+1}-${l+f.length}/${d}`:`${l+1}-${l+f.length}/${d}`;p.push(`\u627E\u5230 ${m} \u6761\u5339\u914D\uFF1A
|
|
37
|
+
`),g&&p.push(`\uFF08\u5982\u9700\u83B7\u53D6\u66F4\u591A\uFF0C\u8BF7\u4F7F\u7528 offset=${l+o} \u7EE7\u7EED\u7FFB\u9875\uFF09
|
|
38
|
+
`);for(let h of f){let I=await C(n,h.id),y=`${h.category}/${h.title}`,D="";I&&(D=I.content.split(`
|
|
39
|
+
`).filter(Rt=>Rt.trim()).slice(0,3).join(" | ").substring(0,150),D.length===150&&(D+="...")),p.push(`## ${y} [${h.id}]`),D&&p.push(`> ${D}`),p.push("")}let w=p.join(`
|
|
40
|
+
`);return await i.debug(`[haimati_search] \u51FA\u53C2:
|
|
41
|
+
${b(w)}`),await i.info(`[haimati_search] \u641C\u7D22\u5B8C\u6210: \u627E\u5230 ${d} \u6761\u5339\u914D`),w}catch(e){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e.stack:"";return await i.error(`[haimati_search] \u51FA\u53C2: \u9519\u8BEF: ${r}
|
|
42
|
+
\u5806\u6808: ${a}`),await i.info(`[haimati_search] \u641C\u7D22\u5931\u8D25: ${r}`),`\u9519\u8BEF: ${r}`}}}),haimati_edit:x({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 \u5305\u62EC\u6B64\u884C\u3002\u9700\u8981\u63D0\u4F9B read \u65F6\u8FD4\u56DE\u7684 version \u8FDB\u884C\u5E76\u53D1\u63A7\u5236\u3002",args:{query:x.schema.string().describe("\u5E8F\u53F7\uFF0C\u7528\u4E8E\u5B9A\u4F4D\u8981\u66F4\u65B0\u7684\u8BB0\u5FC6"),offsetBegin:x.schema.number().describe("\u8D77\u59CB\u884C\u53F7\uFF08\u5305\u62EC\uFF09"),offsetEnd:x.schema.number().describe("\u7ED3\u675F\u884C\u53F7\uFF08\u5305\u62EC\u6B64\u884C\uFF09"),content:x.schema.string().describe("\u66FF\u6362\u5185\u5BB9"),version:x.schema.number().describe("read \u65F6\u8FD4\u56DE\u7684 version\uFF0C\u7528\u4E8E\u5E76\u53D1\u63A7\u5236")},async execute(t,s){let{directory:n}=s,c=P(n);if(await i.info(`[haimati_edit] \u5F00\u59CB\u7F16\u8F91 #${t.query}`),await i.debug(`[haimati_edit] \u5165\u53C2: query="${t.query}", offsetBegin=${t.offsetBegin}, offsetEnd=${t.offsetEnd}, content\u957F\u5EA6=${t.content.length}\u5B57\u7B26, version=${t.version}`),!await $(c))return await i.warn("[haimati_edit] \u51FA\u53C2: \u7D22\u5F15\u6587\u4EF6\u4E0D\u5B58\u5728"),"\u7D22\u5F15\u6587\u4EF6\u4E0D\u5B58\u5728";try{let e=await M(n),r=t.query.trim();if(!/^\d+$/.test(r))return await i.warn("[haimati_edit] \u51FA\u53C2: query\u65E0\u6548"),"\u9519\u8BEF\uFF1Aquery \u5FC5\u987B\u662F\u5E8F\u53F7\uFF0C\u53EA\u652F\u6301\u5E8F\u53F7\u67E5\u8BE2";let a=String(parseInt(r,10)),o=R(e,a);if(!o)return await i.debug(`[haimati_edit] \u51FA\u53C2:
|
|
43
|
+
\u672A\u627E\u5230`),await i.info("[haimati_edit] \u7F16\u8F91\u5931\u8D25: \u672A\u627E\u5230\u8BB0\u5FC6"),`\u672A\u627E\u5230\u4E0E '${r}' \u76F8\u5173\u7684\u8BB0\u5FC6`;let l=await C(n,o.id);if(!l)return await i.error("[haimati_edit] \u51FA\u53C2: \u4E66\u9875\u4E0D\u5B58\u5728"),`\u672A\uFFFD\uFFFD\u5230\u4E66\u9875: #${o.id.padStart(3,"0")}`;if(l.version!==t.version)return await i.warn("[haimati_edit] \u51FA\u53C2: \u7248\u672C\u51B2\u7A81"),`\u9519\u8BEF\uFF1A\u7248\u672C\u51B2\u7A81\uFF0C\u5F53\u524D version=${l.version}\uFF0C\u4F20\u5165 version=${t.version}\uFF0C\u8BF7\u91CD\u65B0\u8BFB\u53D6\u540E\u518D\u64CD\u4F5C`;let u=l.content.split(`
|
|
44
|
+
`).length,{offsetBegin:d,offsetEnd:f}=t;if(d<1||d>u||d>f||f>u)return await i.warn("[haimati_edit] \u51FA\u53C2: offset\u975E\u6CD5"),`\u9519\u8BEF\uFF1Aoffset \u975E\u6CD5\uFF0CoffsetBegin=${d}, offsetEnd=${f}, \u6587\u4EF6\u603B\u884C\u6570=${u}\uFF0C\u6709\u6548\u8303\u56F4 offsetBegin=[1, ${u}], offsetEnd=[offsetBegin, ${u}]`;let p=_t(l.content,d,f,t.content);await j(n,o.id,o.title,l.createdAt,p,l.version+1);let g=`${o.category}/${o.title}`,m=`\u5DF2\u66F4\u65B0\u6D77\u9A6C\u4F53 #${o.id.padStart(3,"0")}
|
|
45
|
+
\u8DEF\u5F84: ${g}
|
|
46
|
+
\u65B0\u7248\u672C: ${l.version+1}`;return await i.debug(`[haimati_edit] \u51FA\u53C2:
|
|
47
|
+
${b(m)}`),await i.info(`[haimati_edit] \u7F16\u8F91\u6210\u529F: #${o.id.padStart(3,"0")} -> v${l.version+1}`),m}catch(e){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e.stack:"";return await i.error(`[haimati_edit] \u51FA\u53C2: ${r}
|
|
48
|
+
\u5806\u6808: ${a}`),`\u9519\u8BEF: ${r}`}}}),haimati_delete:x({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:x.schema.string().describe("\u5E8F\u53F7\u6216\u5B8C\u6574\u8DEF\u5F84\uFF0C\u7528\u4E8E\u5B9A\u4F4D\u8981\u5220\u9664\u7684\u8BB0\u5FC6")},async execute(t,s){let{directory:n}=s,c=P(n);if(await i.info(`[haimati_delete] \u5F00\u59CB\u5220\u9664 ${t.query}`),await i.debug(`[haimati_delete] \u5165\u53C2: query="${t.query}"`),!await $(c)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await i.warn(`[haimati_delete] \u51FA\u53C2:
|
|
49
|
+
${b(e)}`),e}try{let e=await M(n),r=t.query.trim(),a=null;if(/^\d+$/.test(r))a=R(e,String(parseInt(r,10)));else{let d=r.split("/").filter(Boolean);if(d.length>=2){let f=d.pop(),p=d.join("/");a=U(e,p,f)}else{let f=await V(e,r,"or",n);if(f.length===1)a=f[0];else if(f.length>1){let p=f.slice(0,10).map(g=>` - ${g.category}/${g.title} [${g.id.padStart(3,"0")}]`).join(`
|
|
50
|
+
`);return await i.info(`[haimati_delete] \u5220\u9664\u5931\u8D25: \u591A\u6761\u5339\u914D (${f.length}\u6761)`),`\u627E\u5230\u591A\u6761\u5339\u914D\uFF0C\u8BF7\u4F7F\u7528\u5E8F\u53F7\u7CBE\u786E\u6307\u5B9A\uFF1A
|
|
51
|
+
${p}`}}}if(!a){let d=`\u672A\u627E\u5230\u4E0E '${r}' \u76F8\u5173\u7684\u8BB0\u5FC6`;return await i.debug(`[haimati_delete] \u51FA\u53C2:
|
|
52
|
+
${b(d)}`),await i.info("[haimati_delete] \u5220\u9664\u5931\u8D25: \u672A\u627E\u5230\u8BB0\u5FC6"),d}await It(n,a.id);let o=yt(e,a.id);await F(n,o);let l=`${a.category}/${a.title}`,u=`\u5DF2\u5220\u9664\u6D77\u9A6C\u4F53 #${a.id.padStart(3,"0")}
|
|
53
|
+
\u8DEF\u5F84: ${l}`;return await i.debug(`[haimati_delete] \u51FA\u53C2:
|
|
54
|
+
${b(u)}`),await i.info(`[haimati_delete] \u5220\u9664\u6210\u529F: #${a.id.padStart(3,"0")} (${l})`),u}catch(e){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e.stack:"";return await i.error(`[haimati_delete] \u51FA\u53C2: \u9519\u8BEF: ${r}
|
|
55
|
+
\u5806\u6808: ${a}`),await i.info(`[haimati_delete] \u5220\u9664\u5931\u8D25: ${r}`),`\u9519\u8BEF: ${r}`}}}),haimati_move:x({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:x.schema.string().describe("\u5E8F\u53F7\u6216\u5B8C\u6574\u8DEF\u5F84\uFF0C\u7528\u4E8E\u5B9A\u4F4D\u8981\u79FB\u52A8\u7684\u8BB0\u5FC6"),newCategory:x.schema.string().describe("\u65B0\u7684\u5206\u7C7B\u8DEF\u5F84\uFF0C\u5982 'xxx\u9879\u76EE/\u5BA2\u6237\u7AEF' \u6216 '\u901A\u7528'")},async execute(t,s){let{directory:n}=s,c=P(n);if(await i.info(`[haimati_move] \u5F00\u59CB\u79FB\u52A8 ${t.query} -> ${t.newCategory}`),await i.debug(`[haimati_move] \u5165\u53C2: query="${t.query}", newCategory="${t.newCategory}"`),!await $(c)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await i.warn(`[haimati_move] \u51FA\u53C2:
|
|
56
|
+
${b(e)}`),e}try{let e=await M(n),r=t.query.trim(),a=null;if(/^\d+$/.test(r))a=R(e,String(parseInt(r,10)));else{let g=r.split("/").filter(Boolean);if(g.length>=2){let m=g.pop(),w=g.join("/");a=U(e,w,m)}else{let m=await V(e,r,"or",n);if(m.length===1)a=m[0];else if(m.length>1){let w=m.slice(0,10).map(h=>` - ${h.category}/${h.title} [${h.id.padStart(3,"0")}]`).join(`
|
|
57
|
+
`);return await i.info(`[haimati_move] \u79FB\u52A8\u5931\u8D25: \u591A\u6761\u5339\u914D (${m.length}\u6761)`),`\u627E\u5230\u591A\u6761\u5339\u914D\uFF0C\u8BF7\u4F7F\u7528\u5E8F\u53F7\u7CBE\u786E\u6307\u5B9A\uFF1A
|
|
58
|
+
${w}`}}}if(!a){let g=`\u672A\u627E\u5230\u4E0E '${r}' \u76F8\u5173\u7684\u8BB0\u5FC6`;return await i.debug(`[haimati_move] \u51FA\u53C2:
|
|
59
|
+
${b(g)}`),await i.info("[haimati_move] \u79FB\u52A8\u5931\u8D25: \u672A\u627E\u5230\u8BB0\u5FC6"),g}let l=`${a.category}/${a.title}`,u=t.newCategory,d=`${u}/${a.title}`,f=e.map(g=>g.id===a.id?{...g,category:u}:g);await F(n,f);let p=`\u5DF2\u79FB\u52A8\u6D77\u9A6C\u4F53 #${a.id}
|
|
60
|
+
\u65E7\u8DEF\u5F84: ${l}
|
|
61
|
+
\u65B0\u8DEF\u5F84: ${d}`;return await i.debug(`[haimati_move] \u51FA\u53C2:
|
|
62
|
+
${b(p)}`),await i.info(`[haimati_move] \u79FB\u52A8\u6210\u529F: #${a.id} ${l} -> ${d}`),p}catch(e){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e.stack:"";return await i.error(`[haimati_move] \u51FA\u53C2: \u9519\u8BEF: ${r}
|
|
63
|
+
\u5806\u6808: ${a}`),`\u9519\u8BEF: ${r}`}}}),haimati_list:x({description:"\u5217\u51FA\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u7684\u5B8C\u6574\u7D22\u5F15\u7ED3\u6784\u3002",args:{category:x.schema.string().optional().describe("\u53EF\u9009\u7684\u5206\u7C7B\u8DEF\u5F84\uFF0C\u5217\u51FA\u8BE5\u5206\u7C7B\u4E0B\u7684\u6761\u76EE"),recursive:x.schema.boolean().optional().default(!1).describe("\u662F\u5426\u9012\u5F52\u904D\u5386\u5B50\u5206\u7C7B\uFF0C\u9ED8\u8BA4false")},async execute(t,s){let{directory:n}=s,c=P(n);if(await i.info(`[haimati_list] \u5F00\u59CB\u5217\u51FA${t.category?` ${t.category}`:" \u5168\u90E8"}`),await i.debug(`[haimati_list] \u5165\u53C2: category="${t.category||"(\u65E0)"}, recursive=${t.recursive}"`),!await $(c)){let e="\u9519\u8BEF\uFF1A\u6D77\u9A6C\u4F53\u7D22\u5F15\u4E0D\u5B58\u5728";return await i.warn(`[haimati_list] \u51FA\u53C2:
|
|
64
|
+
${b(e)}`),e}try{let e=await M(n);if(t.category){let l=(await $t(n)).split(`
|
|
65
|
+
`),u=0,d=[];for(let m of l){if(!m.trim())continue;let w=H(m);if(m.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/))continue;let I=J(m);if(I&&(I==="/"?d[w]="":d[w]=I,d=d.slice(0,w+1),d.filter(Boolean).join("/")===t.category)){u=w;break}}let f=[],p=[];d=[];for(let m of l){if(!m.trim())continue;let w=H(m),h=m.match(/^\s*[│├└─\s]*(.+?)\s*-\s*(\d+)\s*$/);if(h){let y=h[1].trim(),D=h[2];if(w===u+1){let tt=d.slice(1,w).filter(Boolean).join("/");tt===t.category&&p.push({category:tt,title:y,id:D})}continue}let I=J(m);I&&(I==="/"?d[w]="":d[w]=I,d=d.slice(0,w+1),w===u+1&&d.filter(Boolean).join("/")===t.category&&f.push(I))}let g=`## ${t.category}
|
|
72
66
|
|
|
73
|
-
`;if(
|
|
74
|
-
`,g+=
|
|
67
|
+
`;if(t.recursive){let m=e.filter(h=>h.category===t.category||h.category.startsWith(t.category+"/")),w=new Map;for(let h of m){let y=h.category.slice(t.category.length+1).split("/")[0]||"(\u76F4\u63A5)";w.has(y)||w.set(y,[]),w.get(y).push(h)}for(let[h,I]of w)g+=`### ${h}/
|
|
68
|
+
`,g+=I.map(y=>`- ${y.title} - ${y.id.padStart(3,"0")}`).join(`
|
|
75
69
|
`)+`
|
|
76
70
|
|
|
77
|
-
`}else
|
|
78
|
-
`+
|
|
71
|
+
`}else f.length>0&&(g+=`**\u5B50\u5206\u7C7B\uFF1A**
|
|
72
|
+
`+f.map(m=>`- ${m}/`).join(`
|
|
79
73
|
`)+`
|
|
80
74
|
|
|
81
75
|
`),p.length>0&&(g+=`**\u76F4\u63A5\u6761\u76EE\uFF1A**
|
|
82
76
|
`+p.map(m=>`- ${m.title} - ${m.id.padStart(3,"0")}`).join(`
|
|
83
|
-
`));return await
|
|
84
|
-
${
|
|
77
|
+
`));return await i.debug(`[haimati_list] \u51FA\u53C2:
|
|
78
|
+
${b(g)}`),await i.info(`[haimati_list] \u5217\u51FA\u6210\u529F: ${t.category||"(\u5168\u90E8)"}`),g}let a=`## \u6D77\u9A6C\u4F53\u7D22\u5F15
|
|
85
79
|
|
|
86
|
-
${
|
|
87
|
-
${
|
|
88
|
-
\u5806\u6808: ${
|
|
80
|
+
${ot(e)||"(\u7A7A)"}`;return await i.debug(`[haimati_list] \u51FA\u53C2:
|
|
81
|
+
${b(a)}`),await i.info("[haimati_list] \u5217\u51FA\u6210\u529F: \u5168\u90E8"),a}catch(e){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e.stack:"";return await i.error(`[haimati_list] \u51FA\u53C2: \u9519\u8BEF: ${r}
|
|
82
|
+
\u5806\u6808: ${a}`),`\u9519\u8BEF: ${r}`}}})}}var k=new Map,Z=new Map,T=new Set,_=new Set,S=new Set,Ot=new Map,cn=async t=>{await vt(),await i.debug("\u6D77\u9A6C\u4F53\u8BB0\u5FC6\u7CFB\u7EDF\u63D2\u4EF6(\u6587\u4EF6\u7248)debug\u7248\u672C04091402\u5DF2\u52A0\u8F7D");let{client:s}=t;return{tool:At(),"chat.message":async(c,e)=>{let{message:r,parts:a}=e,o=r.sessionID,l=r.id;if(await i.debug("[chat.message] ====== \u5F00\u59CB\u5904\u7406 ======"),await i.debug(`[chat.message] sessionId=${o}, messageId=${l}`),await i.debug(`[chat.message] enhancedSessions: ${JSON.stringify([...k.entries()])}`),k.get(o)===l){await i.debug(`[chat.message] \u4F1A\u8BDD ${o} \u7684\u6D88\u606F ${l} \u5DF2\u589E\u5F3A\u8FC7\uFF0C\u8DF3\u8FC7`);return}let u=a.some(f=>f.type==="text"&&f.text);if(await i.debug(`[chat.message] hasUserContent=${u}`),!u){await i.debug(`[chat.message] \u6D88\u606F ${l} \u4E0D\u5305\u542B\u7528\u6237\u5185\u5BB9\uFF0C\u8DF3\u8FC7`);return}if(k.has(o)){await i.debug(`[chat.message] \u4F1A\u8BDD ${o} \u5DF2\u589E\u5F3A\u8FC7\uFF0C\u4E0D\u662F\u9996\u6761\u7528\u6237\u6D88\u606F\uFF0C\u8DF3\u8FC7 | enhancedSessions.get=${k.get(o)}`);return}let d=null;try{let f=await s.command.list({});if(f.data){let g=f.data.find(m=>m.name===N.replace(/^\//,""));g&&g.template?(d=g.template,await i.debug(`[chat.message] \u627E\u5230 ${N} \u547D\u4EE4\u7684 template`)):await i.warn(`[chat.message] \u672A\u627E\u5230 ${N} \u547D\u4EE4\u7684 template`)}}catch(f){let p=f instanceof Error?f.message:String(f);await i.error(`[chat.message] \u67E5\u8BE2 ${N} \u547D\u4EE4 template \u5931\u8D25: ${p}`)}if(d===null){await i.debug(`[chat.message] \u4F1A\u8BDD ${o} \u672A\u627E\u5230 ${N} \u547D\u4EE4\u7684 template\uFF0C\u6807\u8BB0\u5E76\u8DF3\u8FC7`),k.set(o,l),await i.debug(`[chat.message] \u6807\u8BB0\u540E enhancedSessions: ${JSON.stringify([...k.entries()])}`);return}await i.debug(`[chat.message] \u589E\u5F3A\u4F1A\u8BDD ${o} \u7684\u9996\u6761\u7528\u6237\u6D88\u606F ${l}`);for(let f of a)f.type==="text"&&(f.text=d+`
|
|
89
83
|
|
|
90
|
-
`+
|
|
84
|
+
`+f.text,await i.debug(`[chat.message] \u5DF2\u589E\u5F3A part ${f.id}\uFF0Ctemplate \u957F\u5EA6=${d.length}`));k.set(o,l),await i.debug(`[chat.message] \u5B8C\u6210\u9996\u6761\u6D88\u606F\u589E\u5F3A (sessionID: ${o}, messageID: ${l})`),await i.debug(`[chat.message] \u6807\u8BB0\u540E enhancedSessions: ${JSON.stringify([...k.entries()])}`),await i.debug("[chat.message] ====== \u5904\u7406\u5B8C\u6210 ======")},event:async({event:c})=>{try{if(c.type==="session.created"){await i.debug(`[session.created] \u4E8B\u4EF6\u5C5E\u6027: ${JSON.stringify(c.properties)}`);let e=c.properties?.info?.id,r=c.properties?.info?.directory;if(await i.debug(`[session.created] \u5C1D\u8BD5\u4FDD\u5B58\u4F1A\u8BDD\u76EE\u5F55: (evt.properties as any).sessionID=${c.properties?.sessionID}, info.id=${e}, directory=${r}`),await i.debug(`[session.created] sessionDirectories.size=${Z.size}, \u73B0\u6709key: ${Array.from(Z.keys()).join(",")}`),r&&(Z.set(e,r),await i.debug(`[session.created] \u4FDD\u5B58\u4F1A\u8BDD\u76EE\u5F55\u5B8C\u6210: sessionID=${e}, directory=${r}`)),!e){await i.warn("[session.created] \u65E0\u6CD5\u83B7\u53D6 sessionID\uFF0C\u8DF3\u8FC7");return}return}if(c.type==="session.error"){let e=c.properties?.sessionID,r=c.properties?.error;await i.debug(`[session.error] \u4E8B\u4EF6\u5C5E\u6027: ${JSON.stringify(c.properties)}, sessionID=${e}, error=${JSON.stringify(r)}`),r&&r.name==="MessageAbortedError"&&e&&(S.add(e),await i.debug(`[session.error] \u68C0\u6D4B\u5230\u7528\u6237\u4E3B\u52A8\u505C\u6B62\u4F1A\u8BDD ${e}`));return}if(c.type==="session.idle"){let e=c.properties?.sessionID,r=(Ot.get(e)||0)+1;if(Ot.set(e,r),r===1&&await i.debug(`[session.idle] \u7B2C1\u6B21\u89E6\u53D1 | \u72B6\u6001: userStopped=${S.has(e)}, injected=${T.has(e)}, injecting=${_.has(e)}`),r>1&&(_.has(e)||T.has(e))){await i.debug(`[session.idle] \u7B2C${r}\u6B21\u89E6\u53D1\u91CD\u590D\uFF0C\u8DF3\u8FC7 | sessionId=${e}`);return}if(!e){await i.warn("[session.idle] \u65E0\u6CD5\u83B7\u53D6 sessionID\uFF0C\u8DF3\u8FC7");return}if(r===1&&await i.debug(`[session.idle] \u8BE6\u7EC6\u72B6\u6001: userStoppedSessions=${JSON.stringify([...S])}, injectedSessions=${JSON.stringify([...T])}, injectingSessions=${JSON.stringify([..._])}`),T.has(e)){await i.debug(`[session.idle] \u4F1A\u8BDD ${e} \u5DF2\u6CE8\u5165\u8FC7\u63D0\u793A\u8BCD\uFF0C\u8DF3\u8FC7`);return}if(_.has(e)){if(await i.debug(`[session.idle] \u4F1A\u8BDD ${e} \u6B63\u5728\u6CE8\u5165\u4E2D\uFF0C\u7B49\u5F85...`),await new Promise(o=>setTimeout(o,1e3)),S.has(e)){await i.debug(`[session.idle] \u7B49\u5F85\u540E\u68C0\u6D4B\u5230\u7528\u6237\u4E3B\u52A8\u505C\u6B62\uFF0C\u6E05\u7406\u5E76\u7ED3\u675F | sessionId=${e}`),S.delete(e),_.delete(e);return}if(T.has(e)){await i.debug(`[session.idle] \u7B49\u5F85\u540E\u786E\u8BA4\u5DF2\u6CE8\u5165\uFF0C\u8DF3\u8FC7 | sessionId=${e}`);return}if(!S.has(e)){await i.debug(`[session.idle] \u7B49\u5F85\u540E\u672A\u68C0\u6D4B\u5230\u7528\u6237\u505C\u6B62\uFF0C\u7531\u9996\u6B21\u89E6\u53D1\u5904\u7406 | sessionId=${e}`),_.delete(e);return}await i.warn(`[session.idle] \u4F1A\u8BDD ${e} \u7B49\u5F85\u540E\u4ECD\u672A\u6CE8\u5165\u4F46\u4ECD\u5728\u6CE8\u5165\u4E2D\uFF0C\u8DF3\u8FC7`);return}if(_.add(e),await i.debug(`[session.idle] \u4F1A\u8BDD ${e} \u5F00\u59CB\u6CE8\u5165\uFF0C\u6807\u8BB0\u4E3A\u6B63\u5728\u6CE8\u5165`),await new Promise(o=>setTimeout(o,500)),await i.debug(`[session.idle] \u7B49\u5F85500ms\u540E\u68C0\u67E5: userStopped=${S.has(e)}, sessionId=${e}`),S.has(e)){await i.debug(`[session.idle] \u7B49\u5F85\u540E\u68C0\u6D4B\u5230\u7528\u6237\u4E3B\u52A8\u505C\u6B62\uFF0C\u6E05\u7406\u5E76\u7ED3\u675F | sessionId=${e}`),S.delete(e),_.delete(e);return}let a=null;try{let o=await s.command.list({});if(o.data){let u=o.data.find(d=>d.name===W.replace(/^\//,""));u&&u.template?(a=u.template,await i.debug(`[session.idle] \u627E\u5230 ${W} \u547D\u4EE4\u7684 template`)):await i.warn(`[session.idle] \u672A\u627E\u5230 ${W} \u547D\u4EE4\u7684 template`)}}catch(o){let l=o instanceof Error?o.message:String(o);await i.error(`[session.idle] \u67E5\u8BE2\u547D\u4EE4 template \u5931\u8D25: ${l}`)}if(a===null){await i.debug(`[session.idle] \u4F1A\u8BDD ${e} \u672A\u627E\u5230 /record-memory \u547D\u4EE4\u7684 template\uFF0C\u6E05\u7406\u5E76\u7ED3\u675F`),_.delete(e);return}if(S.has(e)){await i.debug(`[session.idle] \u6CE8\u5165\u524D\u68C0\u6D4B\u5230\u7528\u6237\u4E3B\u52A8\u505C\u6B62\uFF0C\u6E05\u7406\u5E76\u7ED3\u675F | sessionId=${e}`),S.delete(e),_.delete(e);return}await i.debug(`[session.idle] \u5F00\u59CB\u6CE8\u5165\u63D0\u793A\u8BCD | sessionId=${e}, promptText=${a.substring(0,50)}...`);try{await s.session.prompt({path:{id:e},body:{parts:[{type:"text",text:a}],noReply:!1}}),await i.debug(`[session.idle] \u2705 \u6210\u529F\u6CE8\u5165\u63D0\u793A\u8BCD\u5230\u4F1A\u8BDD ${e}`),T.add(e),_.delete(e),await i.debug(`[session.idle] \u6CE8\u5165\u5B8C\u6210\uFF0C\u6E05\u7406\u72B6\u6001: injectedSessions=${JSON.stringify([...T])}, injectingSessions=${JSON.stringify([..._])}, userStoppedSessions=${JSON.stringify([...S])}`),Z.delete(e)}catch(o){let l=o instanceof Error?o.message:String(o);await i.error(`[session.idle] \u274C \u6CE8\u5165\u63D0\u793A\u8BCD\u5931\u8D25: ${l}`),_.delete(e),await i.debug(`[session.idle] \u6CE8\u5165\u5931\u8D25\uFF0C\u6E05\u7406\u72B6\u6001: injectingSessions=${JSON.stringify([..._])}, userStoppedSessions=${JSON.stringify([...S])}`)}return}}catch(e){let r=e instanceof Error?e.message:String(e);await i.error(`[event] \u5904\u7406\u4E8B\u4EF6 ${c.type} \u5931\u8D25: ${r}`)}}}};export{cn as HaimatiPlugin};
|
package/dist/package.json
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "opencode-haimati",
|
|
3
|
-
"version": "1.1
|
|
4
|
-
"description": "OpenCode plugin for a file-based memory system inspired by the hippocampus, providing long-term memory storage and retrieval across sessions.",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin --minify && cp package.json dist/",
|
|
13
|
-
"build:uncompressed": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin && cp package.json dist/",
|
|
14
|
-
"typecheck": "tsc --noEmit",
|
|
15
|
-
"prepublishOnly": "npm run build",
|
|
16
|
-
"test": "npx tsx test/index.ts"
|
|
17
|
-
},
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"@opencode-ai/plugin": ">=0.15.0",
|
|
20
|
-
"typescript": ">=5.0.0"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@opencode-ai/plugin": "^0.15.0",
|
|
24
|
-
"@types/bun": "^1.3.1",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-haimati",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "OpenCode plugin for a file-based memory system inspired by the hippocampus, providing long-term memory storage and retrieval across sessions.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin --minify && cp package.json dist/",
|
|
13
|
+
"build:uncompressed": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin && cp package.json dist/",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"test": "npx tsx test/index.ts"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@opencode-ai/plugin": ">=0.15.0",
|
|
20
|
+
"typescript": ">=5.0.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@opencode-ai/plugin": "^0.15.0",
|
|
24
|
+
"@types/bun": "^1.3.1",
|
|
25
|
+
"esbuild": "^0.28.0",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "opencode-haimati",
|
|
3
|
-
"version": "1.1
|
|
4
|
-
"description": "OpenCode plugin for a file-based memory system inspired by the hippocampus, providing long-term memory storage and retrieval across sessions.",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin --minify && cp package.json dist/",
|
|
13
|
-
"build:uncompressed": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin && cp package.json dist/",
|
|
14
|
-
"typecheck": "tsc --noEmit",
|
|
15
|
-
"prepublishOnly": "npm run build",
|
|
16
|
-
"test": "npx tsx test/index.ts"
|
|
17
|
-
},
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"@opencode-ai/plugin": ">=0.15.0",
|
|
20
|
-
"typescript": ">=5.0.0"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@opencode-ai/plugin": "^0.15.0",
|
|
24
|
-
"@types/bun": "^1.3.1",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-haimati",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "OpenCode plugin for a file-based memory system inspired by the hippocampus, providing long-term memory storage and retrieval across sessions.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin --minify && cp package.json dist/",
|
|
13
|
+
"build:uncompressed": "rm -rf dist && npx esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --external:@opencode-ai/plugin && cp package.json dist/",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"test": "npx tsx test/index.ts"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@opencode-ai/plugin": ">=0.15.0",
|
|
20
|
+
"typescript": ">=5.0.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@opencode-ai/plugin": "^0.15.0",
|
|
24
|
+
"@types/bun": "^1.3.1",
|
|
25
|
+
"esbuild": "^0.28.0",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
}
|
|
28
|
+
}
|