dsh-aurorix-agentbook 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/web.js +346 -146
  2. package/package.json +1 -1
package/lib/web.js CHANGED
@@ -10,174 +10,320 @@ import { existsSync } from 'node:fs'
10
10
 
11
11
  const PAGE_TITLE = '记忆库'
12
12
 
13
- /** 页面 HTML。样式跟 dsh-go 原生面板对齐:青绿主色、卡片、等宽数字。 */
13
+ /** 页面 HTML。结构与 dsh-go 原生面板逐块对齐:插件内容 → 召回 → 存进记忆 → 保险箱 → 存进保险箱。 */
14
14
  export function pageHtml(locale = 'zh-CN') {
15
15
  const zh = !String(locale).toLowerCase().startsWith('en')
16
+ // 注意:这里只放字符串。函数塞进 JSON.stringify 会整个丢掉,之前 T.total 就是这么炸的。
16
17
  const t = zh
17
- ? { title: '记忆库', all: '全部', search: '搜一条', detail: '详情', edit: '编辑', save: '保存', cancel: '取消', back: '返回', vault: '保险箱', empty: '这里还没有记录', loading: '读取中…', ok: '已保存', fail: '操作失败:', titleField: '标题', bodyField: '正文', readWhen: '读时机', purpose: '用途', newRec: '写一条' }
18
- : { title: 'Memory', all: 'All', search: 'Search', detail: 'Detail', edit: 'Edit', save: 'Save', cancel: 'Cancel', back: 'Back', vault: 'Vault', empty: 'Nothing here yet', loading: 'Loading…', ok: 'Saved', fail: 'Failed: ', titleField: 'Title', bodyField: 'Body', readWhen: 'Read when', purpose: 'Purpose', newRec: 'Write' }
18
+ ? {
19
+ title:'记忆库', sect:'插件内容', memories:'普通记忆', planes:'平面', tblHead1:'写入平面', tblHead2:'条数 / 状态',
20
+ recall:'召回', keyword:'关键词', keywordPh:'输入关键词…', go:'查', none:'暂无数据', hits:(n,tot)=>`命中 ${n} 条(共 ${tot} 条)`,
21
+ saveMem:'存进记忆', saveVault:'存进保险箱',
22
+ vault:'保险箱', vaultSub:'凭据单独存放,不进普通记忆', filter:'筛选', filterPh:'标识或用途…', filterBtn:'筛',
23
+ vaultCount:(shown,total)=>`共 ${total} 条,显示 ${shown} 条`, vaultEmpty:'保险箱是空的',
24
+ plane:'平面', titleField:'标题', bodyField:'正文', readWhen:'读时机(什么时候该读这条)', purpose:'用途',
25
+ save:'保存', detail:'详情', edit:'编辑', cancel:'取消', back:'返回',
26
+ total:(n)=>`共 ${n} 条`, fail:'操作失败:', needBoth:'标题与正文都要填', required:'必填',
27
+ planes_:{soul:'自身原则',rules:'硬规则',profile:'用户画像',explicit:'明确要点',long_term:'长期事实',episodic:'事件记录'},
28
+ vaultRow:'独立保险箱',
29
+ }
30
+ : {
31
+ title:'Memory', sect:'Plugin content', memories:'Memories', planes:'Planes', tblHead1:'Plane', tblHead2:'Count / state',
32
+ recall:'Recall', keyword:'Keyword', keywordPh:'type a keyword…', go:'Search', none:'No data', hits:(n,tot)=>`${n} hits (of ${tot})`,
33
+ saveMem:'Save to memory', saveVault:'Save to vault',
34
+ vault:'Vault', vaultSub:'Secrets live apart from ordinary memory', filter:'Filter', filterPh:'ident or purpose…', filterBtn:'Filter',
35
+ vaultCount:(shown,total)=>`${total} total, ${shown} shown`, vaultEmpty:'Vault is empty',
36
+ plane:'Plane', titleField:'Title', bodyField:'Body', readWhen:'Read when', purpose:'Purpose',
37
+ save:'Save', detail:'Detail', edit:'Edit', cancel:'Cancel', back:'Back',
38
+ total:(n)=>`${n} records`, fail:'Failed: ', needBoth:'Title and body are required', required:'required',
39
+ planes_:{soul:'Principles',rules:'Rules',profile:'Profile',explicit:'Explicit',long_term:'Long-term',episodic:'Episodes'},
40
+ vaultRow:'Vault',
41
+ }
42
+ const plain = { ...t }
43
+ delete plain.total
44
+ delete plain.hits
45
+ delete plain.vaultCount
19
46
 
20
47
  return `<!doctype html>
21
48
  <html lang="${zh ? 'zh-CN' : 'en'}"><head>
22
- <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
49
+ <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
23
50
  <title>${t.title}</title>
24
51
  <style>
25
- :root{--bg:#f7f8f8;--card:#fff;--ink:#1b1f1e;--muted:#6b7674;--line:#e3e7e6;--accent:#0f766e;--accent-weak:#e6f4f1}
26
- @media (prefers-color-scheme:dark){:root{--bg:#141817;--card:#1b201f;--ink:#e8eceb;--muted:#98a3a1;--line:#2a3130;--accent:#4fd1c5;--accent-weak:#17302d}}
27
- *{box-sizing:border-box}
28
- body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.55 -apple-system,system-ui,"PingFang SC","Noto Sans CJK SC",sans-serif}
29
- .wrap{max-width:860px;margin:0 auto;padding:24px 18px 64px}
30
- h1{font-size:19px;margin:0 0 4px;font-weight:600}
31
- .sub{color:var(--muted);font-size:13px;margin-bottom:18px}
32
- .card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:14px 16px;margin-bottom:12px}
33
- .planes{display:flex;flex-wrap:wrap;gap:8px}
34
- .pill{background:var(--accent-weak);color:var(--accent);border-radius:999px;padding:4px 10px;font-size:13px;font-variant-numeric:tabular-nums}
35
- .row{display:flex;gap:10px;align-items:center}
36
- input,textarea,select{width:100%;background:var(--card);border:1px solid var(--line);border-radius:10px;padding:9px 11px;color:var(--ink);font:inherit}
37
- textarea{min-height:160px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}
38
- button{background:var(--accent);color:#fff;border:0;border-radius:10px;padding:9px 16px;font:inherit;cursor:pointer}
39
- button.plain{background:transparent;color:var(--accent);border:1px solid var(--line)}
52
+ :root{--bg:#0d1110;--panel:#141a19;--field:#1a2221;--ink:#e9efee;--muted:#899694;--line:#232c2b;--accent:#5fd3c6;--accent-ink:#04211e;--danger:#f97066}
53
+ @media (prefers-color-scheme:light){:root{--bg:#f4f7f6;--panel:#fff;--field:#f1f5f4;--ink:#121817;--muted:#65716f;--line:#e0e7e5;--accent:#0f766e;--accent-ink:#fff;--danger:#c0261d}}
54
+ *{box-sizing:border-box}html,body{margin:0;background:var(--bg);color:var(--ink)}
55
+ body{font:15px/1.6 -apple-system,system-ui,"PingFang SC","Noto Sans CJK SC",sans-serif;-webkit-font-smoothing:antialiased}
56
+ .wrap{max-width:760px;margin:0 auto;padding:18px 16px 72px}
57
+ h1{font-size:19px;font-weight:600;margin:0 0 4px}
58
+ .sub{color:var(--muted);font-size:13px;margin:0 0 18px}
59
+ section{margin-bottom:26px}
60
+ .sect{font-size:15px;font-weight:600;padding-bottom:10px;border-bottom:1px solid var(--line);margin-bottom:14px}
61
+ .lab{display:block;font-size:13px;color:var(--muted);margin-bottom:7px}
62
+ .rowline{display:flex;justify-content:space-between;align-items:baseline;padding:9px 0}
63
+ .rowline span{color:var(--muted);font-size:13.5px}
64
+ .big{font-size:34px;font-weight:600;line-height:1.1;font-variant-numeric:tabular-nums;color:var(--accent);letter-spacing:-.02em}
65
+ .big.sm{font-size:26px}
66
+ table{width:100%;border-collapse:collapse;margin-top:12px;font-size:13.5px}
67
+ th{text-align:left;color:var(--muted);font-weight:400;font-size:12.5px;padding:6px 0;border-bottom:1px solid var(--line)}
68
+ th:last-child,td:last-child{text-align:right}
69
+ td{padding:9px 0;border-bottom:1px solid var(--line);color:var(--ink)}
70
+ td:last-child{color:var(--muted);font-variant-numeric:tabular-nums}
71
+ tr:last-child td{border-bottom:0}
72
+ .fieldwrap{position:relative;margin-bottom:12px}
73
+ input,textarea,select{width:100%;background:var(--field);border:1px solid var(--line);border-radius:11px;padding:11px 13px;color:var(--ink);font:inherit;outline:none}
74
+ input:focus,textarea:focus,select:focus{border-color:var(--accent)}
75
+ textarea{min-height:130px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13.5px;line-height:1.65}
76
+ .cnt{position:absolute;right:11px;bottom:8px;font-size:11.5px;color:var(--muted);font-variant-numeric:tabular-nums;pointer-events:none}
77
+ button{background:var(--accent);color:var(--accent-ink);border:0;border-radius:11px;padding:11px 16px;font:inherit;font-weight:500;cursor:pointer}
78
+ button.wide{display:block;width:100%}
79
+ button.ghost{background:transparent;color:var(--accent);border:1px solid var(--line)}
40
80
  button:disabled{opacity:.5;cursor:default}
41
- .item{padding:11px 0;border-bottom:1px solid var(--line);cursor:pointer}
81
+ .hint{color:var(--muted);font-size:13.5px;padding:14px 0}
82
+ .err{color:var(--danger);font-size:13px;margin-top:10px}
83
+ .item{display:flex;align-items:center;gap:11px;padding:12px 10px;border-bottom:1px solid var(--line);cursor:pointer;border-radius:8px}
84
+ .item:hover{background:var(--panel)}
42
85
  .item:last-child{border-bottom:0}
43
- .item:hover{background:var(--accent-weak)}
44
- .item .t{font-weight:500}
45
- .item .m{color:var(--muted);font-size:13px}
46
- .meta{display:grid;grid-template-columns:auto 1fr;gap:4px 14px;font-size:13px;color:var(--muted);margin:10px 0 14px}
47
- .meta b{font-weight:500;color:var(--muted)}
48
- .body{white-space:pre-wrap;word-break:break-word;font-size:14px;line-height:1.7;margin-bottom:16px}
49
- .acts{display:flex;gap:8px;flex-wrap:wrap}
50
- .err{color:#b42318}
51
- .hide{display:none}
52
- </style></head><body><div class="wrap">
53
- <h1>${t.title}</h1>
54
- <div class="sub" id="sub"></div>
55
-
56
- <div class="card"><div class="planes" id="planes"></div></div>
57
-
58
- <div class="card">
59
- <div class="row"><input id="q" placeholder="${t.search}" autocomplete="off"><button id="go">${t.search}</button></div>
60
- </div>
86
+ .ico{width:22px;height:22px;flex:none;color:var(--muted)}
87
+ .txt{flex:1;min-width:0}
88
+ .t{font-size:14.5px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
89
+ .m{color:var(--muted);font-size:12.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:2px}
90
+ .bytes{color:var(--muted);font-size:12.5px;font-variant-numeric:tabular-nums;flex:none}
91
+ .chev{color:var(--muted);font-size:17px;flex:none;opacity:.6}
92
+ details{border:1px solid var(--line);border-radius:12px;padding:0 14px;margin-bottom:22px;background:var(--panel)}
93
+ summary{cursor:pointer;padding:13px 0;font-size:14.5px;list-style:none;display:flex;justify-content:space-between;align-items:center}
94
+ summary::-webkit-details-marker{display:none}
95
+ summary::after{content:"▾";color:var(--muted);font-size:12px}
96
+ details[open] summary::after{transform:rotate(180deg)}
97
+ details .inner{padding:4px 0 16px;border-top:1px solid var(--line)}
98
+ #detail{position:fixed;inset:0;background:var(--bg);overflow:auto;display:none;z-index:9}
99
+ #detail.on{display:block}
100
+ #detail .inner{max-width:760px;margin:0 auto;padding:18px 16px 72px}
101
+ .dtitle{font-size:18px;font-weight:600;line-height:1.45;margin-bottom:14px}
102
+ .meta{display:grid;grid-template-columns:auto 1fr;gap:7px 16px;font-size:13px;color:var(--muted);margin-bottom:16px;padding:12px 14px;background:var(--panel);border:1px solid var(--line);border-radius:12px}
103
+ .meta b{font-weight:500}
104
+ .body{white-space:pre-wrap;word-break:break-word;font-size:14.5px;line-height:1.75;background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:15px}
105
+ .acts{display:flex;gap:9px;flex-wrap:wrap;margin-top:18px}
106
+ </style></head><body>
61
107
 
62
- <div class="card" id="listCard"><div id="list"></div></div>
108
+ <div class="wrap">
109
+ <h1>${t.title}</h1>
110
+ <p class="sub" id="sub"></p>
63
111
 
64
- <div class="card hide" id="detailCard">
65
- <div id="detailView"></div>
66
- <div id="detailEdit" class="hide"></div>
67
- <div class="acts" style="margin-top:14px">
68
- <button class="plain" id="back">${t.back}</button>
69
- <button class="plain" id="edit">${t.edit}</button>
70
- <button class="hide" id="save">${t.save}</button>
71
- <button class="hide" id="cancel">${t.cancel}</button>
72
- </div>
73
- <div class="err" id="err"></div>
74
- </div>
112
+ <section>
113
+ <div class="sect">${t.memories === 'Memories' ? 'Plugin content' : '插件内容'}</div>
114
+ <div class="rowline"><span>${t.memories}</span><b class="big" id="total">0</b></div>
115
+ <div class="rowline"><span>${t.planes}</span><b class="big sm" id="planeCount">0</b></div>
116
+ <table><thead><tr><th>${t.tblHead1}</th><th>${t.tblHead2}</th></tr></thead><tbody id="ptable"></tbody></table>
117
+ </section>
118
+
119
+ <section>
120
+ <div class="sect">${t.recall}</div>
121
+ <label class="lab">${t.keyword}</label>
122
+ <div class="fieldwrap"><input id="q" maxlength="120" placeholder="${t.keywordPh}" autocomplete="off"><span class="cnt" id="qcnt">0/120</span></div>
123
+ <button class="wide" id="go">${t.go}</button>
124
+ <div id="results"><div class="hint">${t.none}</div></div>
125
+ </section>
126
+
127
+ <details><summary>${t.saveMem}</summary><div class="inner">
128
+ <label class="lab">${t.plane}</label>
129
+ <select id="wp"><option>soul</option><option>rules</option><option>profile</option><option selected>explicit</option><option>long_term</option><option>episodic</option></select>
130
+ <label class="lab" style="margin-top:12px">${t.titleField}</label><input id="wt">
131
+ <label class="lab" style="margin-top:12px">${t.bodyField}</label><textarea id="wb"></textarea>
132
+ <label class="lab" style="margin-top:12px">${t.readWhen}</label><input id="wr">
133
+ <button style="margin-top:14px" id="wsave">${t.save}</button>
134
+ <div class="err" id="werr"></div>
135
+ </div></details>
136
+
137
+ <section>
138
+ <div class="sect">${t.vault}</div>
139
+ <p class="sub">${t.vaultSub}</p>
140
+ <label class="lab">${t.filter}</label>
141
+ <div class="fieldwrap"><input id="vq" maxlength="120" placeholder="${t.filterPh}" autocomplete="off"><span class="cnt" id="vcnt">0/120</span></div>
142
+ <button class="wide ghost" id="vgo">${t.filterBtn}</button>
143
+ <div class="hint" id="vcount"></div>
144
+ <div id="vlist"></div>
145
+ </section>
146
+
147
+ <details><summary>${t.saveVault}</summary><div class="inner">
148
+ <label class="lab">标识</label><input id="vi">
149
+ <label class="lab" style="margin-top:12px">${t.purpose}</label><input id="vp">
150
+ <label class="lab" style="margin-top:12px">${t.bodyField}</label><textarea id="vb"></textarea>
151
+ <button style="margin-top:14px" id="vsave">${t.save}</button>
152
+ <div class="err" id="verr"></div>
153
+ </div></details>
75
154
  </div>
76
- <script>
77
- const T = ${JSON.stringify(t)};
78
- let S = { planes:{}, total:0, hits:[], detail:null, editing:false, draft:{} };
79
155
 
156
+ <div id="detail"><div class="inner">
157
+ <div class="dtitle" id="dt"></div>
158
+ <div class="meta" id="dm"></div>
159
+ <div class="body" id="db"></div>
160
+ <div id="de" style="display:none"></div>
161
+ <div class="acts">
162
+ <button class="ghost" id="dback">${t.back}</button>
163
+ <button class="ghost" id="dedit">${t.edit}</button>
164
+ <button id="dsave" style="display:none">${t.save}</button>
165
+ <button class="ghost" id="dcancel" style="display:none">${t.cancel}</button>
166
+ </div>
167
+ <div class="err" id="derr"></div>
168
+ </div></div>
169
+
170
+ <script>
171
+ const T = ${JSON.stringify(plain)};
172
+ const PLANE_NAMES = ${JSON.stringify(t.planes_)};
173
+ const ORDER = ['soul','rules','profile','explicit','long_term','episodic'];
80
174
  const $ = (id) => document.getElementById(id);
81
- const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]));
82
-
83
- async function api(path, body) {
84
- const r = await fetch('aurorix/api/' + path, body === undefined ? {} : {
85
- method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body),
86
- });
87
- if (!r.ok) throw new Error('HTTP ' + r.status + ' ' + (await r.text()).slice(0, 120));
88
- return await r.json();
175
+ const esc = (v) => String(v == null ? '' : v).replace(/[&<>"]/g, (c) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]));
176
+ const fmtTotal = (n) => ${JSON.stringify(zh ? '共 ' : '')} + n + ${JSON.stringify(zh ? ' 条' : ' records')};
177
+ const fmtHits = (n, tot) => ${JSON.stringify(zh ? '命中 ' : '')} + n + ${JSON.stringify(zh ? ' 条(共 ' : ' hits (of ')} + tot + ${JSON.stringify(zh ? ' 条)' : ')')};
178
+ const fmtVault = (shown, total) => ${JSON.stringify(zh ? '共 ' : '')} + total + ${JSON.stringify(zh ? ' 条,显示 ' : ' total, ')} + shown + ${JSON.stringify(zh ? ' 条' : ' shown')};
179
+
180
+ let D = null, EDITING = false, VAULT_ALL = [];
181
+
182
+ async function api(name, body) {
183
+ const opt = body === undefined ? {} : { method:'POST', headers:{'content-type':'application/json'}, body: JSON.stringify(body) };
184
+ const r = await fetch('api/' + name, opt);
185
+ const text = await r.text();
186
+ if (!r.ok) throw new Error('HTTP ' + r.status + ' ' + text.slice(0, 100));
187
+ return JSON.parse(text);
89
188
  }
90
189
 
91
- function renderPlanes() {
92
- const rows = Object.entries(S.planes || {}).map(([k, v]) => '<span class="pill">' + esc(k) + ' ' + esc(v) + '</span>');
93
- $('planes').innerHTML = rows.join('') || '<span class="pill">0</span>';
94
- $('sub').textContent = '共 ' + (S.total || 0) + ' 条';
190
+ function renderState(planes, total) {
191
+ $('total').textContent = total || 0;
192
+ const vals = ORDER.map((k) => planes[k] || 0);
193
+ $('planeCount').textContent = vals.filter((v) => v > 0).length;
194
+ const rows = ORDER.map((k) => '<tr><td>' + esc(PLANE_NAMES[k] || k) + '</td><td>' + (planes[k] || 0) + '</td></tr>');
195
+ rows.push('<tr><td>' + ${JSON.stringify(zh ? '凭据库' : 'Vault')} + '</td><td>' + ${JSON.stringify(zh ? '独立保险箱' : 'separate vault')} + '</td></tr>');
196
+ $('ptable').innerHTML = rows.join('');
197
+ $('sub').textContent = fmtTotal(total || 0);
95
198
  }
96
199
 
97
- function renderList() {
98
- const items = S.hits || [];
99
- if (items.length === 0) { $('list').innerHTML = '<div class="m" style="color:var(--muted)">' + T.empty + '</div>'; return; }
100
- $('list').innerHTML = items.map((h, i) =>
101
- '<div class="item" data-i="' + i + '"><div class="t">' + esc(h.title || '(无标题)') + '</div>' +
102
- '<div class="m">' + esc(h.plane || '') + ' · ' + esc((h.preview || '').slice(0, 80)) + '</div></div>').join('');
103
- [...document.querySelectorAll('.item')].forEach((el) => {
104
- el.onclick = () => openDetail((S.hits || [])[Number(el.dataset.i)]);
105
- });
200
+ const DOC = '<svg class="ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3.5h8l4 4V20a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4.5a1 1 0 0 1 1-1Z"/><path d="M14 3.5V8h4"/></svg>';
201
+
202
+ function renderMemoryList(el, rows, emptyText, onClick) {
203
+ if (!rows || rows.length === 0) { el.innerHTML = '<div class="hint">' + esc(emptyText) + '</div>'; return; }
204
+ el.innerHTML = rows.map((r, i) =>
205
+ '<div class="item" data-i="' + i + '">' + DOC +
206
+ '<div class="txt"><div class="t">' + esc(r.title || '(无标题)') + '</div><div class="m">' + esc((r.plane || '') + ' · ' + String(r.preview || '').slice(0, 90)) + '</div></div>' +
207
+ '<div class="chev">›</div></div>').join('');
208
+ [...el.querySelectorAll('.item')].forEach((n) => { n.onclick = () => onClick(rows[Number(n.dataset.i)]); });
106
209
  }
107
210
 
108
- function renderDetail() {
109
- const d = S.detail; if (!d) return;
110
- $('listCard').classList.add('hide');
111
- $('detailCard').classList.remove('hide');
112
- $('err').textContent = '';
113
- const isVault = d.kind === 'vault';
114
- const meta = isVault
115
- ? [['标识', d.id], [T.purpose, d.purpose || '—']]
116
- : [['平面', d.plane || '—'], ['更新时间', d.updated || '—'], ['ID', d.id]];
117
- const body = (d.blocks && d.blocks.length ? d.blocks.join('\\n\\n') : d.body) || '';
118
- $('detailView').innerHTML =
119
- '<div class="t" style="font-weight:600;font-size:17px">' + esc(d.title || '—') + '</div>' +
120
- '<div class="meta">' + meta.map(([k, v]) => '<b>' + esc(k) + '</b><span>' + esc(v) + '</span>').join('') + '</div>' +
121
- '<div class="body">' + esc(body) + '</div>';
122
-
123
- const fields = isVault
124
- ? '<div style="margin-bottom:10px"><div class="m">' + T.purpose + '</div><input id="f-purpose" value="' + esc(S.draft.purpose || '') + '"></div>' +
125
- '<div><div class="m">' + T.bodyField + '</div><textarea id="f-body">' + esc(S.draft.body || '') + '</textarea></div>'
126
- : '<div style="margin-bottom:10px"><div class="m">' + T.titleField + '</div><input id="f-title" value="' + esc(S.draft.title || '') + '"></div>' +
127
- '<div style="margin-bottom:10px"><div class="m">' + T.readWhen + '</div><input id="f-read" value="' + esc(S.draft.readWhen || '') + '"></div>' +
128
- '<div><div class="m">' + T.bodyField + '</div><textarea id="f-body">' + esc(S.draft.body || '') + '</textarea></div>';
129
- $('detailEdit').innerHTML = fields;
130
- $('detailEdit').classList.toggle('hide', !S.editing);
131
- $('detailView').classList.toggle('hide', S.editing);
132
- $('edit').classList.toggle('hide', S.editing);
133
- $('save').classList.toggle('hide', !S.editing);
134
- $('cancel').classList.toggle('hide', !S.editing);
211
+ function renderVaultList(rows) {
212
+ const el = $('vlist');
213
+ if (!rows || rows.length === 0) { el.innerHTML = '<div class="hint">' + esc(T.vaultEmpty) + '</div>'; return; }
214
+ el.innerHTML = rows.map((r, i) =>
215
+ '<div class="item" data-v="' + i + '">' + DOC +
216
+ '<div class="txt"><div class="t">' + esc(r.ident) + '</div><div class="m">' + esc(r.purpose || '') + '</div></div>' +
217
+ '<div class="bytes">' + (r.bytes || 0) + 'B</div><div class="chev">›</div></div>').join('');
218
+ [...el.querySelectorAll('.item')].forEach((n) => { n.onclick = () => openDetail(rows[Number(n.dataset.v)], 'vault'); });
135
219
  }
136
220
 
137
- async function openDetail(hit) {
221
+ async function boot() {
138
222
  try {
139
- const d = await api('detail', { id: hit.id, kind: hit.kind || 'memory' });
140
- S.detail = d.detail; S.draft = d.draft; S.editing = false; renderDetail();
141
- } catch (e) { $('err').textContent = T.fail + e.message; }
223
+ const s = await api('state');
224
+ renderState(s.planes, s.total);
225
+ renderMemoryList($('results'), s.hits, T.none, (row) => openDetail(row, 'memory'));
226
+ const v = await api('vault-list', {});
227
+ VAULT_ALL = v.items || [];
228
+ $('vcount').textContent = fmtVault(VAULT_ALL.length, VAULT_ALL.length);
229
+ renderVaultList(VAULT_ALL);
230
+ } catch (e) {
231
+ $('results').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>';
232
+ }
142
233
  }
143
234
 
144
- function back() {
145
- S.detail = null; S.editing = false;
146
- $('detailCard').classList.add('hide'); $('listCard').classList.remove('hide');
235
+ async function openDetail(row, kind) {
236
+ try {
237
+ const d = await api('detail', { id: row.id || row.ident, kind });
238
+ if (!d.ok) throw new Error(d.reason || 'read failed');
239
+ D = d.detail; EDITING = false; show(); $('detail').classList.add('on');
240
+ } catch (e) { alert(T.fail + e.message); }
147
241
  }
148
242
 
149
- $('back').onclick = back;
150
- $('edit').onclick = () => { S.editing = true; renderDetail(); };
151
- $('cancel').onclick = () => { S.editing = false; renderDetail(); };
152
- $('save').onclick = async () => {
153
- const isVault = S.detail.kind === 'vault';
154
- const payload = isVault
155
- ? { ident: S.detail.id, purpose: $('f-purpose').value, body: $('f-body').value }
156
- : { id: S.detail.id, title: $('f-title').value, readWhen: $('f-read').value, body: $('f-body').value };
243
+ function show() {
244
+ const isVault = D.kind === 'vault';
245
+ $('dt').textContent = D.title || '—';
246
+ const rows = isVault
247
+ ? [[${JSON.stringify(zh ? '标识' : 'Ident')}, D.id], [T.purpose, D.purpose || '—'], [${JSON.stringify(zh ? '大小' : 'Size')}, (D.bytes || 0) + ' B']]
248
+ : [[T.plane, D.plane || '—'], [${JSON.stringify(zh ? 'ID' : 'ID')}, D.id]];
249
+ $('dm').innerHTML = rows.map(([k, v]) => '<b>' + esc(k) + '</b><span>' + esc(v) + '</span>').join('');
250
+ $('db').textContent = D.body || '';
251
+ $('db').style.display = EDITING ? 'none' : '';
252
+ $('de').style.display = EDITING ? '' : 'none';
253
+ if (EDITING) {
254
+ $('de').innerHTML = isVault
255
+ ? '<label class="lab">' + T.purpose + '</label><input id="ep" value="' + esc(D.purpose || '') + '">' +
256
+ '<label class="lab" style="margin-top:12px">' + T.bodyField + '</label><textarea id="eb">' + esc(D.body || '') + '</textarea>'
257
+ : '<label class="lab">' + T.titleField + '</label><input id="et" value="' + esc(D.title || '') + '">' +
258
+ '<label class="lab" style="margin-top:12px">' + T.readWhen + '</label><input id="er" value="' + esc(D.readWhen || '') + '">' +
259
+ '<label class="lab" style="margin-top:12px">' + T.bodyField + '</label><textarea id="eb">' + esc(D.body || '') + '</textarea>';
260
+ }
261
+ $('dedit').style.display = EDITING ? 'none' : '';
262
+ $('dsave').style.display = EDITING ? '' : 'none';
263
+ $('dcancel').style.display = EDITING ? '' : 'none';
264
+ $('derr').textContent = '';
265
+ }
266
+
267
+ $('dback').onclick = () => { $('detail').classList.remove('on'); D = null; };
268
+ $('dedit').onclick = () => { EDITING = true; show(); };
269
+ $('dcancel').onclick = () => { EDITING = false; show(); };
270
+ $('dsave').onclick = async () => {
271
+ const isVault = D.kind === 'vault';
157
272
  try {
158
- const r = await api(isVault ? 'vault-save' : 'save', payload);
159
- if (!r.ok) { $('err').textContent = T.fail + (r.reason || ''); return; }
160
- S.detail = r.detail; S.draft = r.draft; S.editing = false; renderDetail(); reload();
161
- } catch (e) { $('err').textContent = T.fail + e.message; }
273
+ const r = isVault
274
+ ? await api('vault-save', { ident: D.id, purpose: $('ep').value, body: $('eb').value })
275
+ : await api('save', { id: D.id, title: $('et').value, readWhen: $('er').value, body: $('eb').value, revision: D.revision });
276
+ if (!r.ok) { $('derr').textContent = T.fail + (r.reason || ''); return; }
277
+ D = r.detail; EDITING = false; show(); boot();
278
+ } catch (e) { $('derr').textContent = T.fail + e.message; }
162
279
  };
163
280
 
164
- async function reload() {
165
- const s = await api('state');
166
- S.planes = s.planes; S.total = s.total; S.hits = s.hits;
167
- renderPlanes(); renderList();
168
- }
281
+ $('q').addEventListener('input', () => { $('qcnt').textContent = $('q').value.length + '/120'; });
282
+ $('vq').addEventListener('input', () => { $('vcnt').textContent = $('vq').value.length + '/120'; });
283
+
169
284
  $('go').onclick = async () => {
170
285
  const q = $('q').value.trim();
171
286
  try {
172
287
  const s = await api('search', { query: q });
173
- S.planes = s.planes; S.total = s.total; S.hits = s.hits;
174
- renderPlanes(); renderList();
175
- $('listCard').classList.remove('hide'); $('detailCard').classList.add('hide');
176
- } catch (e) { $('err').textContent = T.fail + e.message; }
288
+ renderState(s.planes, s.total);
289
+ if (q === '') { renderMemoryList($('results'), s.hits, T.none, (row) => openDetail(row, 'memory')); return; }
290
+ $('results').innerHTML = s.hits.length === 0 ? '<div class="hint">' + esc(T.none) + '</div>'
291
+ : '<div class="hint">' + fmtHits(s.hits.length, s.total) + '</div>' + s.hits.map((r, i) =>
292
+ '<div class="item" data-i="' + i + '">' + DOC + '<div class="txt"><div class="t">' + esc(r.title || '') +
293
+ '</div><div class="m">' + esc((r.plane || '') + ' · ' + String(r.preview || '').slice(0, 90)) + '</div></div><div class="chev">›</div></div>').join('');
294
+ [...$('results').querySelectorAll('.item')].forEach((n) => { n.onclick = () => openDetail(s.hits[Number(n.dataset.i)], 'memory'); });
295
+ } catch (e) { $('results').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>'; }
177
296
  };
178
297
  $('q').addEventListener('keydown', (e) => { if (e.key === 'Enter') $('go').click(); });
179
298
 
180
- reload().catch((e) => { $('sub').textContent = T.fail + e.message; });
299
+ $('vgo').onclick = async () => {
300
+ const q = $('vq').value.trim().toLowerCase();
301
+ const rows = q === '' ? VAULT_ALL : VAULT_ALL.filter((x) => ((x.ident || '') + ' ' + (x.purpose || '')).toLowerCase().includes(q));
302
+ $('vcount').textContent = fmtVault(rows.length, VAULT_ALL.length);
303
+ renderVaultList(rows);
304
+ };
305
+
306
+ $('wsave').onclick = async () => {
307
+ const title = $('wt').value.trim(), body = $('wb').value;
308
+ if (title === '' || body.trim() === '') { $('werr').textContent = T.fail + T.needBoth; return; }
309
+ try {
310
+ const r = await api('write', { plane: $('wp').value, title, body, readWhen: $('wr').value.trim() });
311
+ if (!r.ok) { $('werr').textContent = T.fail + (r.reason || ''); return; }
312
+ $('werr').textContent = ''; $('wt').value = ''; $('wb').value = ''; $('wr').value = ''; boot();
313
+ } catch (e) { $('werr').textContent = T.fail + e.message; }
314
+ };
315
+
316
+ $('vsave').onclick = async () => {
317
+ const ident = $('vi').value.trim(), body = $('vb').value;
318
+ if (ident === '' || body === '') { $('verr').textContent = T.fail + T.needBoth; return; }
319
+ try {
320
+ const r = await api('vault-save', { ident, purpose: $('vp').value.trim(), body });
321
+ if (!r.ok) { $('verr').textContent = T.fail + (r.reason || ''); return; }
322
+ $('verr').textContent = ''; $('vi').value = ''; $('vp').value = ''; $('vb').value = ''; boot();
323
+ } catch (e) { $('verr').textContent = T.fail + e.message; }
324
+ };
325
+
326
+ boot();
181
327
  </script></body></html>`
182
328
  }
183
329
 
@@ -185,22 +331,56 @@ reload().catch((e) => { $('sub').textContent = T.fail + e.message; });
185
331
  export function sidebarScript(prefix, title) {
186
332
  return `(function(){
187
333
  if (window.__AURORIX_ENTRY__) return; window.__AURORIX_ENTRY__ = true;
188
- var HREF = ${JSON.stringify(prefix)}, NAME = ${JSON.stringify(title)};
334
+ var HREF = ${JSON.stringify(prefix + '/')}, NAME = ${JSON.stringify(title)};
335
+
336
+ // 记忆库图标(书本 + 书签),24×24,跟宿主图标同规格
337
+ var ICON = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5.5A1.5 1.5 0 0 1 5.5 4H10a2 2 0 0 1 2 2v14a1.5 1.5 0 0 0-1.5-1.5H5.5A1.5 1.5 0 0 1 4 17V5.5Z"/><path d="M20 5.5A1.5 1.5 0 0 0 18.5 4H14a2 2 0 0 0-2 2v14a1.5 1.5 0 0 1 1.5-1.5h5A1.5 1.5 0 0 0 20 17V5.5Z"/></svg>';
338
+
339
+ function setText(el, text){
340
+ var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
341
+ var node, hit = false;
342
+ while ((node = walker.nextNode())) {
343
+ if (node.textContent.trim() === '') continue;
344
+ node.textContent = text; hit = true; break;
345
+ }
346
+ if (!hit) el.appendChild(document.createTextNode(text));
347
+ }
348
+
189
349
  function insert(){
190
- var nav = document.querySelector('nav[aria-label],aside nav,nav');
191
- if (!nav || nav.querySelector('[data-aurorix-entry]')) return false;
192
- var a = document.createElement('a');
193
- a.setAttribute('data-aurorix-entry','');
194
- a.href = HREF; a.target = '_blank'; a.rel = 'noopener';
195
- a.textContent = NAME;
196
- a.style.cssText = 'display:block;padding:8px 12px;margin:4px 8px;border-radius:8px;text-decoration:none;color:inherit;font-size:14px;opacity:.85';
197
- nav.appendChild(a);
350
+ if (document.querySelector('[data-aurorix-entry]')) return true;
351
+ var nav = document.querySelector('nav[aria-label], aside nav, nav, [role="navigation"]');
352
+ if (!nav) return false;
353
+
354
+ // 拿一个真实的导航项当样板,克隆它的 class 和层级,样式就不会割裂。
355
+ var sample = Array.prototype.find.call(nav.querySelectorAll('a,button'), function(el){
356
+ var t = (el.textContent || '').trim();
357
+ return t.length > 0 && t.length <= 8 && !el.querySelector('input');
358
+ });
359
+
360
+ if (!sample) return false;
361
+ var el = sample.cloneNode(true);
362
+ el.setAttribute('data-aurorix-entry','');
363
+ if (el.tagName === 'A') { el.href = HREF; el.target = '_blank'; el.rel = 'noopener'; }
364
+ else { el.onclick = function(){ window.open(HREF, '_blank', 'noopener'); }; }
365
+ el.removeAttribute('aria-current');
366
+ el.removeAttribute('data-active');
367
+ if (el.className && typeof el.className === 'string') el.className = el.className.replace(/\bactive\b/g, '').trim();
368
+
369
+ // 换图标:保留宿主图标的容器与尺寸,只换内容。
370
+ var svg = el.querySelector('svg');
371
+ if (svg) { var box = document.createElementNS('http://www.w3.org/2000/svg','svg'); box.innerHTML = ICON; svg.replaceWith(box.firstChild); }
372
+ setText(el, NAME);
373
+
374
+ sample.parentNode.insertBefore(el, sample.nextSibling);
198
375
  return true;
199
376
  }
377
+
200
378
  var tries = 0;
201
- var t = setInterval(function(){
202
- if (insert() || ++tries > 40) clearInterval(t);
203
- }, 500);
379
+ var timer = setInterval(function(){
380
+ var ok = false;
381
+ try { ok = insert(); } catch (e) { ok = true; }
382
+ if (ok || ++tries > 60) clearInterval(timer);
383
+ }, 400);
204
384
  })();`
205
385
  }
206
386
 
@@ -208,7 +388,9 @@ export function sidebarScript(prefix, title) {
208
388
  * 把 Web 面板挂进 web 载体。拿不到 webServer 就安静跳过——dsh-go 手机上本来就没有它。
209
389
  */
210
390
  export function attachWeb(ctx, { backend, root }) {
211
- const prefix = '/aurorix/'
391
+ // prefix 不能带尾斜杠:匹配逻辑是 pathname.startsWith(prefix + '/'),
392
+ // 写成 '/aurorix/' 会变成 '/aurorix//',子路径全部 404。
393
+ const prefix = '/aurorix'
212
394
  ctx.inject(['webServer'], (webCtx) => {
213
395
  const json = (res, code, value) => {
214
396
  res.writeHead(code, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
@@ -230,14 +412,14 @@ export function attachWeb(ctx, { backend, root }) {
230
412
  const url = new URL(req.url ?? '/', 'http://localhost')
231
413
  const path = url.pathname
232
414
 
233
- if (path === prefix || path === prefix.slice(0, -1)) {
415
+ if (path === prefix || path === prefix + '/') {
234
416
  res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
235
417
  res.end(pageHtml(url.searchParams.get('lang') ?? 'zh-CN'))
236
418
  return
237
419
  }
238
- if (!path.startsWith(prefix + 'api/')) { json(res, 404, { ok: false, reason: 'not found' }); return }
420
+ if (!path.startsWith(prefix + '/api/')) { json(res, 404, { ok: false, reason: 'not found' }); return }
239
421
 
240
- const action = path.slice((prefix + 'api/').length)
422
+ const action = path.slice((prefix + '/api/').length)
241
423
  const ok = (value) => json(res, 200, value)
242
424
  try {
243
425
  if (action === 'state' && req.method === 'GET') {
@@ -258,6 +440,24 @@ export function attachWeb(ctx, { backend, root }) {
258
440
  ok({ planes: c.planes ?? {}, total: c.total ?? 0, hits: (list.items ?? []).map((x) => ({ id: x.id, title: x.title, plane: x.plane, preview: x.preview ?? '' })) })
259
441
  return
260
442
  }
443
+ if (action === 'vault-list') {
444
+ const q = String(body.query ?? '').trim().toLowerCase()
445
+ const r = await backend.vaultList()
446
+ if (!r.ok) { ok({ ok: false, items: [], reason: r.reason }); return }
447
+ const items = (r.items ?? []).filter((x) => q === '' || (x.ident + ' ' + x.purpose).toLowerCase().includes(q))
448
+ ok({ ok: true, items })
449
+ return
450
+ }
451
+ if (action === 'write') {
452
+ const plane = String(body.plane ?? 'explicit')
453
+ const title = String(body.title ?? '').trim()
454
+ const text = String(body.body ?? '')
455
+ if (title === '' || text.trim() === '') { ok({ ok: false, reason: '标题与正文都要填' }); return }
456
+ const r = await backend.write({ plane, title, body: text, readWhen: String(body.readWhen ?? '') })
457
+ if (!r.ok) { ok({ ok: false, reason: r.reason }); return }
458
+ ok({ ok: true, record: r.record })
459
+ return
460
+ }
261
461
  if (action === 'detail') {
262
462
  const isVault = String(body.kind ?? '') === 'vault'
263
463
  if (isVault) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aurorix-agentbook",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "dsh-aurorix-agentbook:给 dsh-go 接通 Aurorix 记忆库——原生界面(状态条/胶囊/菜单/面板/保险箱)加宿主侧提示词注入、分层快照与四个工具。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",