dsh-aurorix-agentbook 1.8.0 → 1.8.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.
package/README.md CHANGED
@@ -18,6 +18,14 @@
18
18
  | 命令 `/memory` `/remember` `/recall` | 手动查状态、存一句话、检索 |
19
19
  | 工具 `aurorix_abook` | 跑 abook 的全部子命令;`["capability"]` 取按用途分组的能力地图 |
20
20
 
21
+ ## 网页版
22
+
23
+ Harness Web 上,顶部右侧那组操作按钮里会多一个记忆库按钮,点开是浮层里的面板。
24
+
25
+ 入口按**几何位置**找锚点(页面顶部、右半边、最右的按钮),再克隆它的样式——不依赖宿主每次构建都会变的类名,宿主改版也不会错位。宿主重渲染把节点冲掉时,观察器会补回去;万一找不到锚点,退回固定定位的按钮,入口不会消失。
26
+
27
+ 面板用 iframe 装:页面自己的样式和宿主的互不污染。页面本身允许同源 framing,接口仍然是 `frame-ancestors 'none'`。
28
+
21
29
  ## 每轮自动带上的东西
22
30
 
23
31
  插件会往提示词里注入两段:
package/lib/view.js CHANGED
@@ -94,17 +94,16 @@ export function memoryView(state, caps = {}) {
94
94
  type: 'stack',
95
95
  title: w.title,
96
96
  accent: 'teal',
97
- style: { gap: 'L' },
97
+ style: { gap: 'M' },
98
98
  children: [
99
99
  // 一、分层计数
100
- { type: 'row', children: [
101
- { type: 'metric', label: w.total, value: b('total'), tone: 'info' },
102
- { type: 'metric', label: w.planes, value: b('planeCount') },
103
- ] },
104
- { type: 'table', columns: [w.writePlane, w.countOrStatus], rows: { $: 'data.planeRows' } },
100
+ // 一块就够:总数当主数字,平面数做说明;原来两个 metric 各占一整行
101
+ { type: 'metric', label: w.total, value: b('total'), caption: b('planeSummary'), tone: 'info' },
102
+ // 平面计数两列并排:7 行压到 4 行,省下的正是面板最容易铺张的那一段
103
+ { type: 'table', columns: [w.writePlane, w.countOrStatus, w.writePlane, w.countOrStatus], rows: { $: 'data.planeGrid' } },
105
104
 
106
105
  // 二、召回:关键词 + 结果,点一条进详情
107
- { type: 'divider' },
106
+ { type: 'divider', size: 'S' },
108
107
  { type: 'form', label: w.recall, submit: 'recall', submitLabel: w.recallBtn, children: [
109
108
  { type: 'textField', label: w.queryLabel, bind: 'data.query', placeholder: w.recallPlaceholder, maxLength: 120 },
110
109
  ] },
@@ -112,7 +111,7 @@ export function memoryView(state, caps = {}) {
112
111
  { type: 'list', items: { $: 'data.hits' } },
113
112
 
114
113
  // 三、写入普通记忆(默认收起,避免面板太长)
115
- { type: 'divider' },
114
+ { type: 'divider', size: 'S' },
116
115
  { type: 'collapsible', label: w.save, expanded: false, children: [
117
116
  { type: 'form', submit: 'save', submitLabel: w.save, children: [
118
117
  { type: 'select', label: w.writePlane, bind: 'data.draft.plane', options: [
@@ -131,7 +130,7 @@ export function memoryView(state, caps = {}) {
131
130
  { type: 'text', text: b('draftNote'), tone: 'muted' },
132
131
 
133
132
  // 四、保险箱:独立平面,列表只带标识与用途,正文点开才解密
134
- { type: 'divider' },
133
+ { type: 'divider', size: 'S' },
135
134
  { type: 'text', text: w.vaultTitle, style: { size: 'subtitle', weight: 'semibold' } },
136
135
  { type: 'text', text: w.vaultHint, tone: 'muted' },
137
136
  { type: 'form', submit: 'vault-filter', submitLabel: w.vaultFilterBtn, children: [
@@ -218,11 +217,12 @@ function detailView(state, caps) {
218
217
 
219
218
  // 阅读态一律看已落库的正文;草稿只在编辑态出现在输入框里。
220
219
  const shown = pageSlice(d.body ?? '', state.detailPage)
220
+ // 原来先一行「普通记忆」再一行标题,两行说的是同一件事。标题本身够表意,
221
+ // 平面信息已经在下面的元信息表里,这里不再单占一行。
221
222
  const children = [
222
- { type: 'text', text: isVault ? w.detailVaultKind : w.detailMemoryKind, tone: 'muted' },
223
223
  { type: 'text', text: clip(d.title === '' ? '—' : d.title, 200), style: { size: 'title', weight: 'semibold' } },
224
224
  { type: 'keyValue', items: meta },
225
- { type: 'divider' },
225
+ { type: 'divider', size: 'S' },
226
226
  ]
227
227
  if (shown.text === '') children.push({ type: 'callout', text: w.bodyEmpty, tone: 'warn' })
228
228
  else children.push({ type: 'text', text: shown.text })
@@ -260,6 +260,16 @@ export function memoryData(state, caps = {}) {
260
260
  const planeRows = PLANES.map((plane) => [planeLabel(plane, caps?.locale), String(planes[plane] ?? 0)])
261
261
  if (state.hasCredentialPlane === true) planeRows.push([w.credentialPlane, w.credentialStatus])
262
262
  const total = Number(state.total) || 0
263
+ // 两列并排:把 [平面, 条数] 两两配成一行四格,纵向直接砍半。
264
+ // 单数时右半格留空,不补假数据。
265
+ const planeGrid = []
266
+ for (let i = 0; i < planeRows.length; i += 2) {
267
+ const left = planeRows[i]
268
+ const right = planeRows[i + 1]
269
+ planeGrid.push(right === undefined
270
+ ? [left[0], left[1], '', '']
271
+ : [left[0], left[1], right[0], right[1]])
272
+ }
263
273
 
264
274
  const hits = (state.hits ?? []).map((hit) => ({
265
275
  title: clip(hit.title === undefined || hit.title === null ? '' : hit.title, 80),
@@ -301,6 +311,9 @@ export function memoryData(state, caps = {}) {
301
311
  total,
302
312
  planeCount: overviewPlaneCount(state),
303
313
  planeRows,
314
+ planeGrid,
315
+ // 原来单独占一行的「平面数」,现在作为总数的说明文字,信息不减、行数减一
316
+ planeSummary: `${overviewPlaneCount(state)} ${w.planesUnit}`,
304
317
  planePairs: planeRows.map(([label, value]) => ({ label, value })),
305
318
  query: state.query ?? '',
306
319
  hits,
package/lib/web.js CHANGED
@@ -64,15 +64,21 @@ export function pageHtml(locale = 'zh-CN', scriptNonce = randomBytes(18).toStrin
64
64
  body{font:15px/1.6 -apple-system,system-ui,"PingFang SC","Noto Sans CJK SC",sans-serif;-webkit-font-smoothing:antialiased}
65
65
  .wrap{max-width:760px;margin:0 auto;padding:18px 16px 72px}
66
66
  h1{font-size:19px;font-weight:600;margin:0 0 4px}
67
- .sub{color:var(--muted);font-size:13px;margin:0 0 18px}
68
- section{margin-bottom:26px}
67
+ .sub{color:var(--muted);font-size:13px;margin:0 0 14px}
68
+ section{margin-bottom:20px}
69
69
  .hidden{display:none!important}
70
70
  .field-spaced{margin-top:12px}
71
71
  .button-spaced{margin-top:14px}
72
- .sect{font-size:15px;font-weight:600;padding-bottom:10px;border-bottom:1px solid var(--line);margin-bottom:14px}
72
+ .sect{font-size:14.5px;font-weight:600;padding-bottom:8px;border-bottom:1px solid var(--line);margin-bottom:12px}
73
73
  .lab{display:block;font-size:13px;color:var(--muted);margin-bottom:7px}
74
- .rowline{display:flex;justify-content:space-between;align-items:baseline;padding:9px 0}
75
- .rowline span{color:var(--muted);font-size:13.5px}
74
+ .stat{display:flex;align-items:baseline;gap:9px;padding:2px 0 12px}
75
+ .stat .cap{color:var(--muted);font-size:12.5px}
76
+ table.planes{font-size:13px}
77
+ table.planes td{padding:7px 0;border-bottom:1px solid var(--line)}
78
+ table.planes tr:last-child td{border-bottom:0}
79
+ table.planes td.pn{color:var(--muted);width:22%}
80
+ table.planes td.pv{color:var(--ink);text-align:left;width:28%;font-variant-numeric:tabular-nums}
81
+ table.planes td.pn+td.pv{padding-right:14px}
76
82
  .big{font-size:34px;font-weight:600;line-height:1.1;font-variant-numeric:tabular-nums;color:var(--accent);letter-spacing:-.02em}
77
83
  .big.sm{font-size:26px}
78
84
  table{width:100%;border-collapse:collapse;margin-top:12px;font-size:13.5px}
@@ -81,8 +87,8 @@ th:last-child,td:last-child{text-align:right}
81
87
  td{padding:9px 0;border-bottom:1px solid var(--line);color:var(--ink)}
82
88
  td:last-child{color:var(--muted);font-variant-numeric:tabular-nums}
83
89
  tr:last-child td{border-bottom:0}
84
- .fieldwrap{position:relative;margin-bottom:12px}
85
- 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}
90
+ .fieldwrap{position:relative;margin-bottom:10px}
91
+ input,textarea,select{width:100%;background:var(--field);border:1px solid var(--line);border-radius:11px;padding:9px 12px;color:var(--ink);font:inherit;outline:none}
86
92
  input:focus,textarea:focus,select:focus{border-color:var(--accent)}
87
93
  textarea{min-height:130px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13.5px;line-height:1.65}
88
94
  .cnt{position:absolute;right:11px;bottom:8px;font-size:11.5px;color:var(--muted);font-variant-numeric:tabular-nums;pointer-events:none}
@@ -101,8 +107,8 @@ button:disabled{opacity:.5;cursor:default}
101
107
  .m{color:var(--muted);font-size:12.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:2px}
102
108
  .bytes{color:var(--muted);font-size:12.5px;font-variant-numeric:tabular-nums;flex:none}
103
109
  .chev{color:var(--muted);font-size:17px;flex:none;opacity:.6}
104
- details{border:1px solid var(--line);border-radius:12px;padding:0 14px;margin-bottom:22px;background:var(--panel)}
105
- summary{cursor:pointer;padding:13px 0;font-size:14.5px;list-style:none;display:flex;justify-content:space-between;align-items:center}
110
+ details{border:1px solid var(--line);border-radius:12px;padding:0 14px;margin-bottom:16px;background:var(--panel)}
111
+ summary{cursor:pointer;padding:11px 0;font-size:14.5px;list-style:none;display:flex;justify-content:space-between;align-items:center}
106
112
  summary::-webkit-details-marker{display:none}
107
113
  summary::after{content:"▾";color:var(--muted);font-size:12px}
108
114
  details[open] summary::after{transform:rotate(180deg)}
@@ -123,9 +129,8 @@ details .inner{padding:4px 0 16px;border-top:1px solid var(--line)}
123
129
 
124
130
  <section>
125
131
  <div class="sect">${t.memories === 'Memories' ? 'Plugin content' : '插件内容'}</div>
126
- <div class="rowline"><span>${t.memories}</span><b class="big" id="total">0</b></div>
127
- <div class="rowline"><span>${t.planes}</span><b class="big sm" id="planeCount">0</b></div>
128
- <table><thead><tr><th>${t.tblHead1}</th><th>${t.tblHead2}</th></tr></thead><tbody id="ptable"></tbody></table>
132
+ <div class="stat"><b class="big" id="total">0</b><span class="cap" id="planeCount"></span></div>
133
+ <table class="planes"><tbody id="ptable"></tbody></table>
129
134
  </section>
130
135
 
131
136
  <section>
@@ -207,9 +212,16 @@ function renderState(planes, total, statsError, hasVault) {
207
212
  planes = planes && typeof planes === 'object' && !Array.isArray(planes) ? planes : {};
208
213
  const count = Number.isFinite(Number(total)) ? Number(total) : 0;
209
214
  $('total').textContent = statsError ? '—' : count;
210
- $('planeCount').textContent = statsError ? '—' : ORDER.length + (hasVault ? 1 : 0);
211
- const rows = ORDER.map((k) => '<tr><td>' + esc(PLANE_NAMES[k] || k) + '</td><td>' + (statsError ? '—' : Number(planes[k]) || 0) + '</td></tr>');
212
- if (hasVault) rows.push('<tr><td>' + ${JSON.stringify(zh ? '凭据库' : 'Vault')} + '</td><td>' + ${JSON.stringify(zh ? '独立保险箱' : 'separate vault')} + '</td></tr>');
215
+ $('planeCount').textContent = statsError ? '' : (ORDER.length + (hasVault ? 1 : 0)) + ${JSON.stringify(zh ? ' 个平面' : ' planes')};
216
+ // 两列并排:一对平面占一行,纵向直接砍半;单数时右半格留空,不补假数据
217
+ const cells = ORDER.map((k) => [esc(PLANE_NAMES[k] || k), statsError ? '—' : String(Number(planes[k]) || 0)]);
218
+ if (hasVault) cells.push([${JSON.stringify(zh ? '凭据库' : 'Vault')}, ${JSON.stringify(zh ? '独立保险箱' : 'separate vault')}]);
219
+ const rows = [];
220
+ for (let i = 0; i < cells.length; i += 2) {
221
+ const a = cells[i], b = cells[i + 1] || ['', ''];
222
+ rows.push('<tr><td class="pn">' + a[0] + '</td><td class="pv">' + a[1] + '</td>'
223
+ + '<td class="pn">' + b[0] + '</td><td class="pv">' + b[1] + '</td></tr>');
224
+ }
213
225
  $('ptable').innerHTML = rows.join('');
214
226
  $('sub').textContent = statsError ? T.fail + statsError : fmtTotal(count);
215
227
  }
@@ -372,37 +384,31 @@ refreshVault();
372
384
 
373
385
  /** 往页面里塞一个侧边栏入口。等 SPA 把导航渲染出来再插,避免插到还没生成的容器里。 */
374
386
  /**
375
- * 网页端的入口:一个自绘的悬浮按钮 + 点开后的 iframe 弹层。
387
+ * 网页端的入口:插到页面右上角那组操作按钮里,点开是 iframe 弹层。
376
388
  *
377
- * 为什么不再往侧边栏塞一项:
378
- * 侧边栏是靠克隆宿主导航项、再替换文字和图标做出来的,依赖的是宿主每次构建都会变
379
- * 的类名和 DOM 结构——宿主一改版就错位,而且视觉上永远像"贴上去的"。改用自绘的
380
- * 悬浮按钮后,只依赖 document.body 和一段内联样式,宿主怎么改版都不影响;
381
- * 面板用 iframe 装,页面自己的样式和宿主的样式互不污染。
389
+ * 两步定位,都不依赖宿主每次构建都会变的类名:
390
+ * 1. **按几何位置找那组按钮**——在页面顶部高度范围内、水平靠右的 button,取最右的那个当锚点。
391
+ * 宿主改类名、改层级、改组件结构都不影响,只要"顶部右侧有操作按钮"这个事实还在。
392
+ * 2. **克隆锚点**——沿用宿主自己的 padding、圆角、hover 与图标尺寸,看起来就是原生的一个。
393
+ * 图标只换内容不动容器,所以尺寸和描边粗细自动对齐。
382
394
  *
383
- * 权限与宿主保持一致:页面本身仍然要求 Host/Origin 校验与已认证的身份,
384
- * 换个展现形式不放宽任何访问条件。
395
+ * 宿主重新渲染会把我们插进去的节点冲掉,所以用 MutationObserver 盯住,掉了就补回去;
396
+ * 同时留一个低频兜底轮询,防止观察器本身也被替换。找不到锚点时退回固定定位,
397
+ * 至少保证入口还在,不会因为宿主改版把功能整个弄丢。
385
398
  */
386
399
  export function floatButtonScript(prefix, title) {
387
400
  return `(function(){
388
401
  if (window.__AURORIX_ENTRY__) return; window.__AURORIX_ENTRY__ = true;
389
402
  var HREF = ${JSON.stringify(prefix + '/')}, NAME = ${JSON.stringify(title)};
390
403
 
391
- 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>';
404
+ var ICON = '<svg 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>';
392
405
  var CLOSE = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>';
393
406
 
394
407
  var CSS = ''
395
- + '.ax-fab{position:fixed;right:18px;bottom:18px;z-index:2147483000;display:flex;align-items:center;gap:7px;'
396
- + 'padding:9px 14px;border-radius:999px;border:1px solid var(--dsl-alias-border-l2,rgba(127,127,127,.28));'
397
- + 'background:var(--dsl-alias-bg-l2,#1b1f1e);color:var(--dsl-alias-text-l1,#e9efee);'
398
- + 'font:13px/1 -apple-system,system-ui,"PingFang SC","Noto Sans CJK SC",sans-serif;cursor:pointer;'
399
- + 'box-shadow:0 6px 24px rgba(0,0,0,.28);transition:transform .12s,box-shadow .12s}'
400
- + '.ax-fab:hover{transform:translateY(-1px);box-shadow:0 10px 30px rgba(0,0,0,.34)}'
401
408
  + '.ax-mask{position:fixed;inset:0;z-index:2147483001;background:rgba(0,0,0,.42);display:none}'
402
409
  + '.ax-mask.ax-on{display:block}'
403
- + '.ax-panel{position:fixed;right:18px;bottom:74px;z-index:2147483002;display:none;'
404
- + 'width:min(560px,calc(100vw - 36px));height:min(760px,calc(100vh - 140px));'
405
- + 'border-radius:14px;overflow:hidden;background:var(--dsl-alias-bg-l1,#0d1110);'
410
+ + '.ax-panel{position:fixed;z-index:2147483002;display:none;overflow:hidden;'
411
+ + 'border-radius:14px;background:var(--dsl-alias-bg-l1,#0d1110);'
406
412
  + 'border:1px solid var(--dsl-alias-border-l2,rgba(127,127,127,.28));box-shadow:0 24px 64px rgba(0,0,0,.45)}'
407
413
  + '.ax-panel.ax-on{display:flex;flex-direction:column}'
408
414
  + '.ax-head{display:flex;align-items:center;justify-content:space-between;gap:10px;'
@@ -412,10 +418,18 @@ export function floatButtonScript(prefix, title) {
412
418
  + 'border:0;background:transparent;color:inherit;cursor:pointer;opacity:.7}'
413
419
  + '.ax-x:hover{opacity:1;background:rgba(127,127,127,.14)}'
414
420
  + '.ax-frame{flex:1 1 auto;width:100%;border:0;background:transparent}'
415
- + '@media (max-width:700px){.ax-panel{right:8px;left:8px;bottom:66px;width:auto;height:calc(100vh - 120px)}}';
421
+ // 找不到宿主锚点时的退路:固定贴在右上角,样式尽量贴近宿主按钮
422
+ + '.ax-fab-fallback{position:fixed;top:12px;right:64px;z-index:2147483000;display:flex;align-items:center;'
423
+ + 'justify-content:center;width:32px;height:32px;padding:0;border-radius:8px;border:0;cursor:pointer;'
424
+ + 'background:transparent;color:var(--dsl-alias-text-l1,#e9efee);opacity:.72}'
425
+ + '.ax-fab-fallback:hover{opacity:1;background:rgba(127,127,127,.14)}'
426
+ + '.ax-fab-fallback svg{width:18px;height:18px}';
416
427
 
417
428
  function boot(){
429
+ if (document.querySelector('[data-aurorix-entry]')) return;
430
+
418
431
  var style = document.createElement('style');
432
+ style.setAttribute('data-aurorix-style','');
419
433
  style.textContent = CSS;
420
434
  document.head.appendChild(style);
421
435
 
@@ -430,31 +444,142 @@ export function floatButtonScript(prefix, title) {
430
444
  head.appendChild(ttl); head.appendChild(x);
431
445
  var frame = document.createElement('iframe'); frame.className = 'ax-frame'; frame.title = NAME;
432
446
  panel.appendChild(head); panel.appendChild(frame);
433
-
434
- var fab = document.createElement('button'); fab.className = 'ax-fab'; fab.type = 'button';
435
- fab.innerHTML = ICON; fab.appendChild(document.createTextNode(NAME));
447
+ document.body.appendChild(mask);
448
+ document.body.appendChild(panel);
436
449
 
437
450
  var loaded = false;
451
+ function place(){
452
+ // 面板贴着触发按钮的右上角展开,宽度不超过视口
453
+ var vw = window.innerWidth || document.documentElement.clientWidth || 0;
454
+ var r = entry ? entry.getBoundingClientRect() : { right: vw - 64, bottom: 44, top: 0 };
455
+ var vh = window.innerHeight || document.documentElement.clientHeight || 0;
456
+ var w = Math.min(560, vw - 36);
457
+ var h = Math.min(760, vh - 140);
458
+ var left = Math.max(12, Math.min(r.right - w, vw - w - 12));
459
+ panel.style.width = w + 'px';
460
+ panel.style.height = h + 'px';
461
+ panel.style.left = left + 'px';
462
+ panel.style.top = Math.max(12, r.bottom + 8) + 'px';
463
+ }
438
464
  function open(){
439
- // 首次打开才建 iframe:不打开就不发请求,也不占内存
440
465
  if (!loaded) { frame.src = HREF; loaded = true; }
466
+ place();
441
467
  mask.classList.add('ax-on'); panel.classList.add('ax-on');
442
468
  x.focus();
443
469
  }
444
470
  function close(){
445
471
  mask.classList.remove('ax-on'); panel.classList.remove('ax-on');
446
- fab.focus();
472
+ if (entry) entry.focus();
447
473
  }
448
- fab.onclick = open;
449
474
  x.onclick = close;
450
475
  mask.onclick = close;
451
476
  document.addEventListener('keydown', function(e){
452
477
  if (e.key === 'Escape' && panel.classList.contains('ax-on')) close();
453
478
  });
479
+ addEventListener('resize', function(){ if (panel.classList.contains('ax-on')) place(); });
480
+
481
+ var entry = null;
482
+
483
+ // 在页面顶部、水平靠右的按钮里找最右那个当锚点。用几何位置而不是类名:
484
+ // 宿主每次构建都会把类名换成新的哈希,位置关系却一直成立。
485
+ function findAnchor(){
486
+ var best = null, bestRight = -1;
487
+ var all = document.querySelectorAll('button, [role="button"], a[role="button"]');
488
+ for (var i = 0; i < all.length; i++) {
489
+ var el = all[i];
490
+ if (el.hasAttribute('data-aurorix-entry')) continue;
491
+ if (el.closest && el.closest('.ax-panel, .ax-mask')) continue;
492
+ var r = el.getBoundingClientRect();
493
+ if (r.width <= 0 || r.height <= 0) continue;
494
+ if (r.top > 90) continue; // 只要顶部那一条
495
+ if (r.left < (window.innerWidth || 0) * 0.5) continue; // 只要右半边
496
+ if (r.right > bestRight) { bestRight = r.right; best = el; }
497
+ }
498
+ return best;
499
+ }
454
500
 
455
- document.body.appendChild(mask);
456
- document.body.appendChild(panel);
457
- document.body.appendChild(fab);
501
+ function makeEntry(anchor){
502
+ // 先试着沿用宿主那个按钮的壳(尺寸、圆角、hover 全部对齐)。
503
+ // 克隆可能失败——宿主控件也可能不是普通 DOM——失败就退回自绘按钮,
504
+ // 入口不能因为"长得不像宿主"就整个不见。
505
+ var el = null;
506
+ if (anchor) {
507
+ try { el = anchor.cloneNode(true); } catch (err) { el = null; }
508
+ }
509
+ if (el) {
510
+ el.removeAttribute('aria-current');
511
+ el.removeAttribute('data-active');
512
+ el.removeAttribute('data-state');
513
+ if (el.className && typeof el.className === 'string') {
514
+ el.className = el.className.replace(/\b(active|selected|open)\b/g, '').trim();
515
+ }
516
+ } else {
517
+ el = document.createElement('button');
518
+ el.className = 'ax-fab-fallback';
519
+ }
520
+
521
+ try {
522
+ el.setAttribute('data-aurorix-entry','');
523
+ el.setAttribute('type','button');
524
+ el.setAttribute('aria-label', NAME);
525
+ el.setAttribute('title', NAME);
526
+
527
+ // 图标只换内容不动容器,尺寸与描边自动跟宿主对齐
528
+ var svg = el.querySelector('svg');
529
+ if (svg) {
530
+ var box = document.createElementNS('http://www.w3.org/2000/svg','svg');
531
+ box.innerHTML = ICON;
532
+ var next = box.firstChild;
533
+ for (var i = 0; i < svg.attributes.length; i++) {
534
+ var a = svg.attributes[i];
535
+ if (a.name !== 'viewBox') next.setAttribute(a.name, a.value);
536
+ }
537
+ svg.replaceWith(next);
538
+ } else {
539
+ el.innerHTML = ICON;
540
+ }
541
+
542
+ // 文字标签留给屏幕阅读器(aria-label),视觉上只显示图标,和宿主那组按钮一致
543
+ var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
544
+ var node;
545
+ while ((node = walker.nextNode())) {
546
+ if (node.textContent.trim() === '') continue;
547
+ node.textContent = '';
548
+ }
549
+ } catch (err) {
550
+ // 改壳失败:整块换成一个干净的自绘按钮
551
+ el = document.createElement('button');
552
+ el.className = 'ax-fab-fallback';
553
+ el.setAttribute('data-aurorix-entry','');
554
+ el.setAttribute('aria-label', NAME);
555
+ el.setAttribute('title', NAME);
556
+ el.innerHTML = ICON;
557
+ }
558
+
559
+ el.onclick = function(e){ e.preventDefault(); e.stopPropagation(); open(); };
560
+ return el;
561
+ }
562
+
563
+ function mount(){
564
+ if (entry && document.contains(entry)) return true;
565
+ var anchor = findAnchor();
566
+ entry = makeEntry(anchor);
567
+ // 放在最右那个按钮之后,成为这一组的最后一个,和宿主自己的排列一致
568
+ if (anchor && anchor.parentNode) anchor.parentNode.insertBefore(entry, anchor.nextSibling || null);
569
+ else document.body.appendChild(entry);
570
+ return true;
571
+ }
572
+
573
+ mount();
574
+ // 宿主重渲染会冲掉我们的节点:盯着 DOM,掉了立刻补回去。
575
+ try {
576
+ new MutationObserver(function(){ mount(); }).observe(document.body, { childList: true, subtree: true });
577
+ } catch (e) {}
578
+ var tries = 0;
579
+ var timer = setInterval(function(){
580
+ mount();
581
+ if (++tries > 150) clearInterval(timer); // 兜底轮询,防观察器被替换
582
+ }, 400);
458
583
  }
459
584
 
460
585
  if (document.body) boot();
package/lib/words.js CHANGED
@@ -3,6 +3,7 @@ export const WORDS = {
3
3
  zh: {
4
4
  title: '记忆库',
5
5
  planes: '平面',
6
+ planesUnit: '个平面',
6
7
  total: '普通记忆',
7
8
  countOrStatus: '条数 / 状态',
8
9
  credentialPlane: '凭据库',
@@ -113,6 +114,7 @@ export const WORDS = {
113
114
  en: {
114
115
  title: 'Memory',
115
116
  planes: 'planes',
117
+ planesUnit: 'planes',
116
118
  total: 'Ordinary records',
117
119
  countOrStatus: 'Count / status',
118
120
  credentialPlane: 'Credentials',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aurorix-agentbook",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "dsh-aurorix-agentbook:给 dsh-go 接通 Aurorix 记忆库——原生界面(状态条/胶囊/菜单/面板/保险箱)加宿主侧提示词注入、分层快照与四个工具。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",