dsh-aurorix-agentbook 1.5.0 → 1.5.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.
Files changed (2) hide show
  1. package/lib/web.js +245 -143
  2. package/package.json +1 -1
package/lib/web.js CHANGED
@@ -10,174 +10,222 @@ 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
16
  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' }
17
+ ? { title:'记忆库', total:(n)=>`共 ${n} 条`, recall:'搜一条', recallPh:'关键词,回车或点右侧', vault:'保险箱', vaultPh:'按标识或用途筛选', write:'写一条', plane:'平面', wTitle:'标题', wBody:'正文', wRead:'读时机(什么时候该读这条)', save:'保存', detail:'详情', edit:'编辑', cancel:'取消', back:'返回', del:'删除', empty:'还没有记录', emptyHit:'没有匹配的记录', emptyVault:'保险箱是空的', loading:'读取中…', ok:'已保存', fail:'操作失败:', purpose:'用途', updated:'更新时间', id:'ID', bytes:'大小', verified:'校验' }
18
+ : { title:'Memory', total:(n)=>`${n} records`, recall:'Search', recallPh:'keyword, Enter to search', vault:'Vault', vaultPh:'filter by ident or purpose', write:'Write', plane:'Plane', wTitle:'Title', wBody:'Body', wRead:'Read when', save:'Save', detail:'Detail', edit:'Edit', cancel:'Cancel', back:'Back', del:'Delete', empty:'Nothing yet', emptyHit:'No match', emptyVault:'Vault is empty', loading:'Loading…', ok:'Saved', fail:'Failed: ', purpose:'Purpose', updated:'Updated', id:'ID', bytes:'Size', verified:'Verified' }
19
19
 
20
20
  return `<!doctype html>
21
21
  <html lang="${zh ? 'zh-CN' : 'en'}"><head>
22
- <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
22
+ <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
23
23
  <title>${t.title}</title>
24
24
  <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}}
25
+ :root{
26
+ --bg:#0f1312;--card:#161c1b;--card2:#1c2423;--ink:#e9efee;--muted:#8d9c99;--line:#26302e;
27
+ --accent:#5fd3c6;--accent-ink:#06201d;--accent-weak:#14302c;--danger:#f97066;
28
+ }
29
+ @media (prefers-color-scheme:light){:root{
30
+ --bg:#f6f8f7;--card:#fff;--card2:#f2f5f4;--ink:#141a19;--muted:#66716f;--line:#e2e8e6;
31
+ --accent:#0f766e;--accent-ink:#fff;--accent-weak:#e4f3f0;--danger:#c0261d;
32
+ }}
27
33
  *{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)}
34
+ html,body{margin:0;background:var(--bg);color:var(--ink)}
35
+ body{font:15px/1.6 -apple-system,system-ui,"PingFang SC","Noto Sans CJK SC",sans-serif;-webkit-font-smoothing:antialiased}
36
+ .wrap{max-width:820px;margin:0 auto;padding:20px 16px 80px}
37
+ header{display:flex;align-items:baseline;gap:10px;margin-bottom:16px}
38
+ h1{font-size:20px;font-weight:600;margin:0;letter-spacing:.01em}
39
+ .total{color:var(--muted);font-size:13px;font-variant-numeric:tabular-nums}
40
+ h2{font-size:14px;font-weight:600;margin:0 0 12px;color:var(--muted);letter-spacing:.02em}
41
+ .card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:16px;margin-bottom:14px}
42
+ .planes{display:flex;flex-wrap:wrap;gap:7px;margin-bottom:14px}
43
+ .pill{background:var(--card);border:1px solid var(--line);border-radius:999px;padding:5px 11px;font-size:12.5px;color:var(--muted);font-variant-numeric:tabular-nums}
44
+ .pill b{color:var(--ink);font-weight:600;margin-left:5px}
45
+ .row{display:flex;gap:9px}
46
+ input,textarea,select{width:100%;background:var(--card2);border:1px solid var(--line);border-radius:10px;padding:10px 12px;color:var(--ink);font:inherit;outline:none}
47
+ input:focus,textarea:focus,select:focus{border-color:var(--accent)}
48
+ textarea{min-height:140px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13.5px;line-height:1.65}
49
+ button{background:var(--accent);color:var(--accent-ink);border:0;border-radius:10px;padding:10px 16px;font:inherit;font-weight:500;cursor:pointer;white-space:nowrap}
50
+ button.ghost{background:transparent;color:var(--accent);border:1px solid var(--line)}
40
51
  button:disabled{opacity:.5;cursor:default}
41
- .item{padding:11px 0;border-bottom:1px solid var(--line);cursor:pointer}
42
- .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>
52
+ .field{margin-bottom:12px}
53
+ .label{font-size:12.5px;color:var(--muted);margin-bottom:6px}
54
+ .list{margin-top:12px}
55
+ .item{padding:11px 12px;border-radius:10px;cursor:pointer;border:1px solid transparent}
56
+ .item:hover{background:var(--card2);border-color:var(--line)}
57
+ .item .t{font-weight:500;font-size:14.5px}
58
+ .item .m{color:var(--muted);font-size:12.5px;margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
59
+ .hint{color:var(--muted);font-size:13px;padding:8px 0}
60
+ .err{color:var(--danger);font-size:13px;margin-top:10px}
61
+ #detail{position:fixed;inset:0;background:var(--bg);overflow:auto;display:none;z-index:9}
62
+ #detail.on{display:block}
63
+ #detail .inner{max-width:820px;margin:0 auto;padding:20px 16px 80px}
64
+ .dtitle{font-size:19px;font-weight:600;line-height:1.4;margin-bottom:14px}
65
+ .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(--card);border:1px solid var(--line);border-radius:12px}
66
+ .meta b{font-weight:500}
67
+ .body{white-space:pre-wrap;word-break:break-word;font-size:14.5px;line-height:1.75;background:var(--card);border:1px solid var(--line);border-radius:12px;padding:16px}
68
+ .acts{display:flex;gap:9px;flex-wrap:wrap;margin-top:18px}
69
+ </style></head><body>
61
70
 
62
- <div class="card" id="listCard"><div id="list"></div></div>
71
+ <div class="wrap">
72
+ <header><h1>${t.title}</h1><span class="total" id="total"></span></header>
73
+ <div class="planes" id="planes"></div>
63
74
 
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>
75
+ <section class="card">
76
+ <div class="row"><input id="q" placeholder="${t.recallPh}" autocomplete="off"><button id="go">${t.recall}</button></div>
77
+ <div class="list" id="results"></div>
78
+ </section>
79
+
80
+ <section class="card">
81
+ <h2>${t.vault}</h2>
82
+ <div class="row"><input id="vq" placeholder="${t.vaultPh}" autocomplete="off"><button class="ghost" id="vgo">${t.recall}</button></div>
83
+ <div class="list" id="vlist"></div>
84
+ </section>
85
+
86
+ <section class="card">
87
+ <h2>${t.write}</h2>
88
+ <div class="field"><div class="label">${t.plane}</div>
89
+ <select id="wp"><option value="explicit">explicit</option><option value="long_term">long_term</option><option value="episodic">episodic</option><option value="rules">rules</option><option value="profile">profile</option><option value="soul">soul</option></select></div>
90
+ <div class="field"><div class="label">${t.wTitle}</div><input id="wt"></div>
91
+ <div class="field"><div class="label">${t.wBody}</div><textarea id="wb"></textarea></div>
92
+ <div class="field"><div class="label">${t.wRead}</div><input id="wr"></div>
93
+ <button id="wsave">${t.save}</button>
94
+ <div class="err" id="werr"></div>
95
+ </section>
75
96
  </div>
97
+
98
+ <div id="detail"><div class="inner">
99
+ <div class="dtitle" id="dt"></div>
100
+ <div class="meta" id="dm"></div>
101
+ <div class="body" id="db"></div>
102
+ <div id="de" style="display:none"></div>
103
+ <div class="acts">
104
+ <button class="ghost" id="dback">${t.back}</button>
105
+ <button class="ghost" id="dedit">${t.edit}</button>
106
+ <button id="dsave" style="display:none">${t.save}</button>
107
+ <button class="ghost" id="dcancel" style="display:none">${t.cancel}</button>
108
+ </div>
109
+ <div class="err" id="derr"></div>
110
+ </div></div>
111
+
76
112
  <script>
77
113
  const T = ${JSON.stringify(t)};
78
- let S = { planes:{}, total:0, hits:[], detail:null, editing:false, draft:{} };
79
-
80
114
  const $ = (id) => document.getElementById(id);
81
- const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]));
115
+ const esc = (v) => String(v == null ? '' : v).replace(/[&<>"]/g, (c) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]));
116
+ let D = null; // 当前详情
117
+ let EDITING = false;
82
118
 
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();
119
+ async function api(name, body) {
120
+ const opt = body === undefined ? {} : { method:'POST', headers:{'content-type':'application/json'}, body: JSON.stringify(body) };
121
+ const r = await fetch('api/' + name, opt);
122
+ const text = await r.text();
123
+ if (!r.ok) throw new Error('HTTP ' + r.status + ' ' + text.slice(0, 100));
124
+ return JSON.parse(text);
89
125
  }
90
126
 
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) + ' 条';
127
+ function renderPlanes(planes, total) {
128
+ const order = ['soul','rules','profile','explicit','long_term','episodic'];
129
+ $('planes').innerHTML = order.map((k) => '<span class="pill">' + k + '<b>' + (planes[k] || 0) + '</b></span>').join('');
130
+ $('total').textContent = T.total(total || 0);
95
131
  }
96
132
 
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)]);
133
+ function renderItems(el, rows, kind, emptyText) {
134
+ if (!rows || rows.length === 0) { el.innerHTML = '<div class="hint">' + esc(emptyText) + '</div>'; return; }
135
+ el.innerHTML = rows.map((r, i) => '<div class="item" data-i="' + i + '"><div class="t">' + esc(r.title || r.ident || '(无标题)') +
136
+ '</div><div class="m">' + esc((r.plane ? r.plane + ' · ' : '') + String(r.preview || r.purpose || '').slice(0, 90)) + '</div></div>').join('');
137
+ [...el.querySelectorAll('.item')].forEach((node) => {
138
+ node.onclick = () => openDetail(rows[Number(node.dataset.i)], kind);
105
139
  });
106
140
  }
107
141
 
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);
142
+ async function boot() {
143
+ try {
144
+ const s = await api('state');
145
+ renderPlanes(s.planes, s.total);
146
+ renderItems($('results'), s.hits, 'memory', T.empty);
147
+ const v = await api('vault-list', {});
148
+ renderItems($('vlist'), v.items, 'vault', T.emptyVault);
149
+ } catch (e) { $('results').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>'; }
135
150
  }
136
151
 
137
- async function openDetail(hit) {
152
+ async function openDetail(row, kind) {
138
153
  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; }
154
+ const d = await api('detail', { id: row.id || row.ident, kind });
155
+ if (!d.ok) throw new Error(d.reason || 'read failed');
156
+ D = d.detail; EDITING = false;
157
+ show();
158
+ $('detail').classList.add('on');
159
+ } catch (e) { alert(T.fail + e.message); }
142
160
  }
143
161
 
144
- function back() {
145
- S.detail = null; S.editing = false;
146
- $('detailCard').classList.add('hide'); $('listCard').classList.remove('hide');
162
+ function show() {
163
+ const isVault = D.kind === 'vault';
164
+ $('dt').textContent = D.title || '—';
165
+ const rows = isVault
166
+ ? [[T.id, D.id], [T.purpose, D.purpose || '—'], [T.bytes, (D.bytes || 0) + ' B']]
167
+ : [[T.plane, D.plane || '—'], [T.updated, D.updated || '—'], [T.id, D.id]];
168
+ $('dm').innerHTML = rows.map(([k, v]) => '<b>' + esc(k) + '</b><span>' + esc(v) + '</span>').join('');
169
+ $('db').textContent = D.body || '';
170
+ $('db').style.display = EDITING ? 'none' : '';
171
+ $('de').style.display = EDITING ? '' : 'none';
172
+ if (EDITING) {
173
+ $('de').innerHTML = isVault
174
+ ? '<div class="field"><div class="label">' + T.purpose + '</div><input id="ep" value="' + esc(D.purpose || '') + '"></div>' +
175
+ '<div class="field"><div class="label">' + T.wBody + '</div><textarea id="eb">' + esc(D.body || '') + '</textarea></div>'
176
+ : '<div class="field"><div class="label">' + T.wTitle + '</div><input id="et" value="' + esc(D.title || '') + '"></div>' +
177
+ '<div class="field"><div class="label">' + T.wRead + '</div><input id="er" value="' + esc(D.readWhen || '') + '"></div>' +
178
+ '<div class="field"><div class="label">' + T.wBody + '</div><textarea id="eb">' + esc(D.body || '') + '</textarea></div>';
179
+ }
180
+ $('dedit').style.display = EDITING ? 'none' : '';
181
+ $('dsave').style.display = EDITING ? '' : 'none';
182
+ $('dcancel').style.display = EDITING ? '' : 'none';
183
+ $('derr').textContent = '';
147
184
  }
148
185
 
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 };
186
+ $('dback').onclick = () => { $('detail').classList.remove('on'); D = null; };
187
+ $('dedit').onclick = () => { EDITING = true; show(); };
188
+ $('dcancel').onclick = () => { EDITING = false; show(); };
189
+ $('dsave').onclick = async () => {
190
+ const isVault = D.kind === 'vault';
157
191
  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; }
192
+ const r = isVault
193
+ ? await api('vault-save', { ident: D.id, purpose: $('ep').value, body: $('eb').value })
194
+ : await api('save', { id: D.id, title: $('et').value, readWhen: $('er').value, body: $('eb').value, revision: D.revision });
195
+ if (!r.ok) { $('derr').textContent = T.fail + (r.reason || ''); return; }
196
+ D = r.detail; EDITING = false; show(); boot();
197
+ } catch (e) { $('derr').textContent = T.fail + e.message; }
162
198
  };
163
199
 
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
- }
169
200
  $('go').onclick = async () => {
170
201
  const q = $('q').value.trim();
171
202
  try {
172
203
  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; }
204
+ renderPlanes(s.planes, s.total);
205
+ renderItems($('results'), s.hits, 'memory', q === '' ? T.empty : T.emptyHit);
206
+ } catch (e) { $('results').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>'; }
177
207
  };
178
208
  $('q').addEventListener('keydown', (e) => { if (e.key === 'Enter') $('go').click(); });
179
209
 
180
- reload().catch((e) => { $('sub').textContent = T.fail + e.message; });
210
+ $('vgo').onclick = async () => {
211
+ try {
212
+ const v = await api('vault-list', { query: $('vq').value.trim() });
213
+ renderItems($('vlist'), v.items, 'vault', T.emptyVault);
214
+ } catch (e) { $('vlist').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>'; }
215
+ };
216
+
217
+ $('wsave').onclick = async () => {
218
+ const title = $('wt').value.trim(), body = $('wb').value;
219
+ if (title === '' || body.trim() === '') { $('werr').textContent = T.fail + '标题与正文都要填'; return; }
220
+ try {
221
+ const r = await api('write', { plane: $('wp').value, title, body, readWhen: $('wr').value.trim() });
222
+ if (!r.ok) { $('werr').textContent = T.fail + (r.reason || ''); return; }
223
+ $('werr').textContent = ''; $('wt').value = ''; $('wb').value = ''; $('wr').value = '';
224
+ boot();
225
+ } catch (e) { $('werr').textContent = T.fail + e.message; }
226
+ };
227
+
228
+ boot();
181
229
  </script></body></html>`
182
230
  }
183
231
 
@@ -185,22 +233,56 @@ reload().catch((e) => { $('sub').textContent = T.fail + e.message; });
185
233
  export function sidebarScript(prefix, title) {
186
234
  return `(function(){
187
235
  if (window.__AURORIX_ENTRY__) return; window.__AURORIX_ENTRY__ = true;
188
- var HREF = ${JSON.stringify(prefix)}, NAME = ${JSON.stringify(title)};
236
+ var HREF = ${JSON.stringify(prefix + '/')}, NAME = ${JSON.stringify(title)};
237
+
238
+ // 记忆库图标(书本 + 书签),24×24,跟宿主图标同规格
239
+ 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>';
240
+
241
+ function setText(el, text){
242
+ var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
243
+ var node, hit = false;
244
+ while ((node = walker.nextNode())) {
245
+ if (node.textContent.trim() === '') continue;
246
+ node.textContent = text; hit = true; break;
247
+ }
248
+ if (!hit) el.appendChild(document.createTextNode(text));
249
+ }
250
+
189
251
  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);
252
+ if (document.querySelector('[data-aurorix-entry]')) return true;
253
+ var nav = document.querySelector('nav[aria-label], aside nav, nav, [role="navigation"]');
254
+ if (!nav) return false;
255
+
256
+ // 拿一个真实的导航项当样板,克隆它的 class 和层级,样式就不会割裂。
257
+ var sample = Array.prototype.find.call(nav.querySelectorAll('a,button'), function(el){
258
+ var t = (el.textContent || '').trim();
259
+ return t.length > 0 && t.length <= 8 && !el.querySelector('input');
260
+ });
261
+
262
+ if (!sample) return false;
263
+ var el = sample.cloneNode(true);
264
+ el.setAttribute('data-aurorix-entry','');
265
+ if (el.tagName === 'A') { el.href = HREF; el.target = '_blank'; el.rel = 'noopener'; }
266
+ else { el.onclick = function(){ window.open(HREF, '_blank', 'noopener'); }; }
267
+ el.removeAttribute('aria-current');
268
+ el.removeAttribute('data-active');
269
+ if (el.className && typeof el.className === 'string') el.className = el.className.replace(/\bactive\b/g, '').trim();
270
+
271
+ // 换图标:保留宿主图标的容器与尺寸,只换内容。
272
+ var svg = el.querySelector('svg');
273
+ if (svg) { var box = document.createElementNS('http://www.w3.org/2000/svg','svg'); box.innerHTML = ICON; svg.replaceWith(box.firstChild); }
274
+ setText(el, NAME);
275
+
276
+ sample.parentNode.insertBefore(el, sample.nextSibling);
198
277
  return true;
199
278
  }
279
+
200
280
  var tries = 0;
201
- var t = setInterval(function(){
202
- if (insert() || ++tries > 40) clearInterval(t);
203
- }, 500);
281
+ var timer = setInterval(function(){
282
+ var ok = false;
283
+ try { ok = insert(); } catch (e) { ok = true; }
284
+ if (ok || ++tries > 60) clearInterval(timer);
285
+ }, 400);
204
286
  })();`
205
287
  }
206
288
 
@@ -208,7 +290,9 @@ export function sidebarScript(prefix, title) {
208
290
  * 把 Web 面板挂进 web 载体。拿不到 webServer 就安静跳过——dsh-go 手机上本来就没有它。
209
291
  */
210
292
  export function attachWeb(ctx, { backend, root }) {
211
- const prefix = '/aurorix/'
293
+ // prefix 不能带尾斜杠:匹配逻辑是 pathname.startsWith(prefix + '/'),
294
+ // 写成 '/aurorix/' 会变成 '/aurorix//',子路径全部 404。
295
+ const prefix = '/aurorix'
212
296
  ctx.inject(['webServer'], (webCtx) => {
213
297
  const json = (res, code, value) => {
214
298
  res.writeHead(code, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
@@ -230,14 +314,14 @@ export function attachWeb(ctx, { backend, root }) {
230
314
  const url = new URL(req.url ?? '/', 'http://localhost')
231
315
  const path = url.pathname
232
316
 
233
- if (path === prefix || path === prefix.slice(0, -1)) {
317
+ if (path === prefix || path === prefix + '/') {
234
318
  res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
235
319
  res.end(pageHtml(url.searchParams.get('lang') ?? 'zh-CN'))
236
320
  return
237
321
  }
238
- if (!path.startsWith(prefix + 'api/')) { json(res, 404, { ok: false, reason: 'not found' }); return }
322
+ if (!path.startsWith(prefix + '/api/')) { json(res, 404, { ok: false, reason: 'not found' }); return }
239
323
 
240
- const action = path.slice((prefix + 'api/').length)
324
+ const action = path.slice((prefix + '/api/').length)
241
325
  const ok = (value) => json(res, 200, value)
242
326
  try {
243
327
  if (action === 'state' && req.method === 'GET') {
@@ -258,6 +342,24 @@ export function attachWeb(ctx, { backend, root }) {
258
342
  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
343
  return
260
344
  }
345
+ if (action === 'vault-list') {
346
+ const q = String(body.query ?? '').trim().toLowerCase()
347
+ const r = await backend.vaultList()
348
+ if (!r.ok) { ok({ ok: false, items: [], reason: r.reason }); return }
349
+ const items = (r.items ?? []).filter((x) => q === '' || (x.ident + ' ' + x.purpose).toLowerCase().includes(q))
350
+ ok({ ok: true, items })
351
+ return
352
+ }
353
+ if (action === 'write') {
354
+ const plane = String(body.plane ?? 'explicit')
355
+ const title = String(body.title ?? '').trim()
356
+ const text = String(body.body ?? '')
357
+ if (title === '' || text.trim() === '') { ok({ ok: false, reason: '标题与正文都要填' }); return }
358
+ const r = await backend.write({ plane, title, body: text, readWhen: String(body.readWhen ?? '') })
359
+ if (!r.ok) { ok({ ok: false, reason: r.reason }); return }
360
+ ok({ ok: true, record: r.record })
361
+ return
362
+ }
261
363
  if (action === 'detail') {
262
364
  const isVault = String(body.kind ?? '') === 'vault'
263
365
  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.1",
4
4
  "description": "dsh-aurorix-agentbook:给 dsh-go 接通 Aurorix 记忆库——原生界面(状态条/胶囊/菜单/面板/保险箱)加宿主侧提示词注入、分层快照与四个工具。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",