dsh-aurorix-agentbook 1.8.0 → 1.8.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 (3) hide show
  1. package/README.md +8 -0
  2. package/lib/web.js +141 -28
  3. package/package.json +1 -1
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/web.js CHANGED
@@ -372,37 +372,31 @@ refreshVault();
372
372
 
373
373
  /** 往页面里塞一个侧边栏入口。等 SPA 把导航渲染出来再插,避免插到还没生成的容器里。 */
374
374
  /**
375
- * 网页端的入口:一个自绘的悬浮按钮 + 点开后的 iframe 弹层。
375
+ * 网页端的入口:插到页面右上角那组操作按钮里,点开是 iframe 弹层。
376
376
  *
377
- * 为什么不再往侧边栏塞一项:
378
- * 侧边栏是靠克隆宿主导航项、再替换文字和图标做出来的,依赖的是宿主每次构建都会变
379
- * 的类名和 DOM 结构——宿主一改版就错位,而且视觉上永远像"贴上去的"。改用自绘的
380
- * 悬浮按钮后,只依赖 document.body 和一段内联样式,宿主怎么改版都不影响;
381
- * 面板用 iframe 装,页面自己的样式和宿主的样式互不污染。
377
+ * 两步定位,都不依赖宿主每次构建都会变的类名:
378
+ * 1. **按几何位置找那组按钮**——在页面顶部高度范围内、水平靠右的 button,取最右的那个当锚点。
379
+ * 宿主改类名、改层级、改组件结构都不影响,只要"顶部右侧有操作按钮"这个事实还在。
380
+ * 2. **克隆锚点**——沿用宿主自己的 padding、圆角、hover 与图标尺寸,看起来就是原生的一个。
381
+ * 图标只换内容不动容器,所以尺寸和描边粗细自动对齐。
382
382
  *
383
- * 权限与宿主保持一致:页面本身仍然要求 Host/Origin 校验与已认证的身份,
384
- * 换个展现形式不放宽任何访问条件。
383
+ * 宿主重新渲染会把我们插进去的节点冲掉,所以用 MutationObserver 盯住,掉了就补回去;
384
+ * 同时留一个低频兜底轮询,防止观察器本身也被替换。找不到锚点时退回固定定位,
385
+ * 至少保证入口还在,不会因为宿主改版把功能整个弄丢。
385
386
  */
386
387
  export function floatButtonScript(prefix, title) {
387
388
  return `(function(){
388
389
  if (window.__AURORIX_ENTRY__) return; window.__AURORIX_ENTRY__ = true;
389
390
  var HREF = ${JSON.stringify(prefix + '/')}, NAME = ${JSON.stringify(title)};
390
391
 
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>';
392
+ 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
393
  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
394
 
394
395
  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
396
  + '.ax-mask{position:fixed;inset:0;z-index:2147483001;background:rgba(0,0,0,.42);display:none}'
402
397
  + '.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);'
398
+ + '.ax-panel{position:fixed;z-index:2147483002;display:none;overflow:hidden;'
399
+ + 'border-radius:14px;background:var(--dsl-alias-bg-l1,#0d1110);'
406
400
  + 'border:1px solid var(--dsl-alias-border-l2,rgba(127,127,127,.28));box-shadow:0 24px 64px rgba(0,0,0,.45)}'
407
401
  + '.ax-panel.ax-on{display:flex;flex-direction:column}'
408
402
  + '.ax-head{display:flex;align-items:center;justify-content:space-between;gap:10px;'
@@ -412,10 +406,18 @@ export function floatButtonScript(prefix, title) {
412
406
  + 'border:0;background:transparent;color:inherit;cursor:pointer;opacity:.7}'
413
407
  + '.ax-x:hover{opacity:1;background:rgba(127,127,127,.14)}'
414
408
  + '.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)}}';
409
+ // 找不到宿主锚点时的退路:固定贴在右上角,样式尽量贴近宿主按钮
410
+ + '.ax-fab-fallback{position:fixed;top:12px;right:64px;z-index:2147483000;display:flex;align-items:center;'
411
+ + 'justify-content:center;width:32px;height:32px;padding:0;border-radius:8px;border:0;cursor:pointer;'
412
+ + 'background:transparent;color:var(--dsl-alias-text-l1,#e9efee);opacity:.72}'
413
+ + '.ax-fab-fallback:hover{opacity:1;background:rgba(127,127,127,.14)}'
414
+ + '.ax-fab-fallback svg{width:18px;height:18px}';
416
415
 
417
416
  function boot(){
417
+ if (document.querySelector('[data-aurorix-entry]')) return;
418
+
418
419
  var style = document.createElement('style');
420
+ style.setAttribute('data-aurorix-style','');
419
421
  style.textContent = CSS;
420
422
  document.head.appendChild(style);
421
423
 
@@ -430,31 +432,142 @@ export function floatButtonScript(prefix, title) {
430
432
  head.appendChild(ttl); head.appendChild(x);
431
433
  var frame = document.createElement('iframe'); frame.className = 'ax-frame'; frame.title = NAME;
432
434
  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));
435
+ document.body.appendChild(mask);
436
+ document.body.appendChild(panel);
436
437
 
437
438
  var loaded = false;
439
+ function place(){
440
+ // 面板贴着触发按钮的右上角展开,宽度不超过视口
441
+ var vw = window.innerWidth || document.documentElement.clientWidth || 0;
442
+ var r = entry ? entry.getBoundingClientRect() : { right: vw - 64, bottom: 44, top: 0 };
443
+ var vh = window.innerHeight || document.documentElement.clientHeight || 0;
444
+ var w = Math.min(560, vw - 36);
445
+ var h = Math.min(760, vh - 140);
446
+ var left = Math.max(12, Math.min(r.right - w, vw - w - 12));
447
+ panel.style.width = w + 'px';
448
+ panel.style.height = h + 'px';
449
+ panel.style.left = left + 'px';
450
+ panel.style.top = Math.max(12, r.bottom + 8) + 'px';
451
+ }
438
452
  function open(){
439
- // 首次打开才建 iframe:不打开就不发请求,也不占内存
440
453
  if (!loaded) { frame.src = HREF; loaded = true; }
454
+ place();
441
455
  mask.classList.add('ax-on'); panel.classList.add('ax-on');
442
456
  x.focus();
443
457
  }
444
458
  function close(){
445
459
  mask.classList.remove('ax-on'); panel.classList.remove('ax-on');
446
- fab.focus();
460
+ if (entry) entry.focus();
447
461
  }
448
- fab.onclick = open;
449
462
  x.onclick = close;
450
463
  mask.onclick = close;
451
464
  document.addEventListener('keydown', function(e){
452
465
  if (e.key === 'Escape' && panel.classList.contains('ax-on')) close();
453
466
  });
467
+ addEventListener('resize', function(){ if (panel.classList.contains('ax-on')) place(); });
468
+
469
+ var entry = null;
470
+
471
+ // 在页面顶部、水平靠右的按钮里找最右那个当锚点。用几何位置而不是类名:
472
+ // 宿主每次构建都会把类名换成新的哈希,位置关系却一直成立。
473
+ function findAnchor(){
474
+ var best = null, bestRight = -1;
475
+ var all = document.querySelectorAll('button, [role="button"], a[role="button"]');
476
+ for (var i = 0; i < all.length; i++) {
477
+ var el = all[i];
478
+ if (el.hasAttribute('data-aurorix-entry')) continue;
479
+ if (el.closest && el.closest('.ax-panel, .ax-mask')) continue;
480
+ var r = el.getBoundingClientRect();
481
+ if (r.width <= 0 || r.height <= 0) continue;
482
+ if (r.top > 90) continue; // 只要顶部那一条
483
+ if (r.left < (window.innerWidth || 0) * 0.5) continue; // 只要右半边
484
+ if (r.right > bestRight) { bestRight = r.right; best = el; }
485
+ }
486
+ return best;
487
+ }
454
488
 
455
- document.body.appendChild(mask);
456
- document.body.appendChild(panel);
457
- document.body.appendChild(fab);
489
+ function makeEntry(anchor){
490
+ // 先试着沿用宿主那个按钮的壳(尺寸、圆角、hover 全部对齐)。
491
+ // 克隆可能失败——宿主控件也可能不是普通 DOM——失败就退回自绘按钮,
492
+ // 入口不能因为"长得不像宿主"就整个不见。
493
+ var el = null;
494
+ if (anchor) {
495
+ try { el = anchor.cloneNode(true); } catch (err) { el = null; }
496
+ }
497
+ if (el) {
498
+ el.removeAttribute('aria-current');
499
+ el.removeAttribute('data-active');
500
+ el.removeAttribute('data-state');
501
+ if (el.className && typeof el.className === 'string') {
502
+ el.className = el.className.replace(/\b(active|selected|open)\b/g, '').trim();
503
+ }
504
+ } else {
505
+ el = document.createElement('button');
506
+ el.className = 'ax-fab-fallback';
507
+ }
508
+
509
+ try {
510
+ el.setAttribute('data-aurorix-entry','');
511
+ el.setAttribute('type','button');
512
+ el.setAttribute('aria-label', NAME);
513
+ el.setAttribute('title', NAME);
514
+
515
+ // 图标只换内容不动容器,尺寸与描边自动跟宿主对齐
516
+ var svg = el.querySelector('svg');
517
+ if (svg) {
518
+ var box = document.createElementNS('http://www.w3.org/2000/svg','svg');
519
+ box.innerHTML = ICON;
520
+ var next = box.firstChild;
521
+ for (var i = 0; i < svg.attributes.length; i++) {
522
+ var a = svg.attributes[i];
523
+ if (a.name !== 'viewBox') next.setAttribute(a.name, a.value);
524
+ }
525
+ svg.replaceWith(next);
526
+ } else {
527
+ el.innerHTML = ICON;
528
+ }
529
+
530
+ // 文字标签留给屏幕阅读器(aria-label),视觉上只显示图标,和宿主那组按钮一致
531
+ var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
532
+ var node;
533
+ while ((node = walker.nextNode())) {
534
+ if (node.textContent.trim() === '') continue;
535
+ node.textContent = '';
536
+ }
537
+ } catch (err) {
538
+ // 改壳失败:整块换成一个干净的自绘按钮
539
+ el = document.createElement('button');
540
+ el.className = 'ax-fab-fallback';
541
+ el.setAttribute('data-aurorix-entry','');
542
+ el.setAttribute('aria-label', NAME);
543
+ el.setAttribute('title', NAME);
544
+ el.innerHTML = ICON;
545
+ }
546
+
547
+ el.onclick = function(e){ e.preventDefault(); e.stopPropagation(); open(); };
548
+ return el;
549
+ }
550
+
551
+ function mount(){
552
+ if (entry && document.contains(entry)) return true;
553
+ var anchor = findAnchor();
554
+ entry = makeEntry(anchor);
555
+ // 放在最右那个按钮之后,成为这一组的最后一个,和宿主自己的排列一致
556
+ if (anchor && anchor.parentNode) anchor.parentNode.insertBefore(entry, anchor.nextSibling || null);
557
+ else document.body.appendChild(entry);
558
+ return true;
559
+ }
560
+
561
+ mount();
562
+ // 宿主重渲染会冲掉我们的节点:盯着 DOM,掉了立刻补回去。
563
+ try {
564
+ new MutationObserver(function(){ mount(); }).observe(document.body, { childList: true, subtree: true });
565
+ } catch (e) {}
566
+ var tries = 0;
567
+ var timer = setInterval(function(){
568
+ mount();
569
+ if (++tries > 150) clearInterval(timer); // 兜底轮询,防观察器被替换
570
+ }, 400);
458
571
  }
459
572
 
460
573
  if (document.body) boot();
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.1",
4
4
  "description": "dsh-aurorix-agentbook:给 dsh-go 接通 Aurorix 记忆库——原生界面(状态条/胶囊/菜单/面板/保险箱)加宿主侧提示词注入、分层快照与四个工具。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",