dsh-agy-link 0.6.24 → 0.6.26
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/CHANGELOG.md +26 -0
- package/dist/cli-image.mjs +8 -1
- package/dist/client.js +138 -100
- package/dist/index.js +69 -27
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.26 (2026-11-15)
|
|
4
|
+
|
|
5
|
+
### English
|
|
6
|
+
|
|
7
|
+
- **Fix(goal): only trust `<goal_complete>` on a user-role message (merges PR #111).** `isGoalToolContinuation()` matched the marker as a plain substring on every message role, so any tool result that merely *printed* the literal string (e.g. grepping this package's own `dist/index.js` doc comments) short-circuited the next request into a zero-content `finish(stop)` that DSH records as a normal completion — three silent replies in a row in the reported incident. The textual marker is now gated on `m.role === 'user'`; the genuine `source.kind === 'tool-goal'` notice still short-circuits. Regression test built from the real grep output plus an assistant echo. Thanks to @AlaIchhe for the diagnosis and RED-first test.
|
|
8
|
+
- **Fix(auth): imported Windows credentials no longer create a permanent 401 deadlock (fixes #112).** `/agy import` on a Windows primary account hand-built a token document without `expiry`; `getValidAccessTokenUncached()` read the missing expiry as "valid forever", so the stale access token was reused until Google rejected it, and every refresh path (`force:true` warmup/quota) reused the same judgment — a self-inflicted, unrecoverable loop. The import now uses `buildAgyCredentialDoc()` (the same single writer as the on-disk token file, always with an expiry or a bounded fallback), and a token with **no known expiry** is treated as needing refresh/validation rather than fresh.
|
|
9
|
+
- **Fix(warmup): terminal TOS bans are quarantined instead of probed every 5 minutes (fixes #112).** 403 `TOS_VIOLATION` responses were truncated to 160 characters (losing `appeal_url`) and returned as an ordinary failure, so `authRequired`/cooldowns stayed empty. Errors now keep up to 2000 characters plus an explicit `Appeal:` link; a `TOS_VIOLATION` marks the account `authRequired` and logs the full reason, stopping the scheduled loop. Pure classifier + injected-network regression tests cover both.
|
|
10
|
+
|
|
11
|
+
### 中文
|
|
12
|
+
|
|
13
|
+
- **修复(goal):`<goal_complete>` 仅信任 user 角色消息(合并 PR #111)。** `isGoalToolContinuation()` 此前把该标记当普通子串匹配所有角色;工具输出只要「打印」出这串字面量(例如 grep 本包 `dist/index.js` 的文档注释),下一轮请求就会被短路成零内容 `finish(stop)`,而 DSH 将其记为正常完成——报告里连续三轮空白回复。现文本标记限制在 `m.role === 'user'`,真正的 `source.kind === 'tool-goal'` 通知仍正常短路。回归测试用真实 grep 输出与 assistant 回声构造。感谢 @AlaIchhe 的定位与 RED-first 测试。
|
|
14
|
+
- **修复(认证):Windows 导入凭据不再造成永久 401 死锁(修复 #112)。** `/agy import` 在 Windows 主账号分支手工拼装了缺少 `expiry` 的 token 文档;`getValidAccessTokenUncached()` 把「缺失 expiry」当成永久有效,旧 access_token 一直复用到 Google 拒绝,而 `force:true` 的预热/额度刷新同样绕不过该判断——一次导入就自造不可逆死循环。现在导入复用 `buildAgyCredentialDoc()`(与磁盘 token 文件同一写入器,必带 expiry 或有界兜底),且**未知 expiry 一律视为需要刷新/校验**而非新鲜。
|
|
15
|
+
- **修复(预热):TOS 终态封禁改为隔离,不再每 5 分钟空转(修复 #112)。** 403 `TOS_VIOLATION` 此前被截到 160 字符(丢失 `appeal_url`)并按普通失败返回,`authRequired`/冷却一直为空。现在保留最多 2000 字符并显式附 `Appeal:` 链接;`TOS_VIOLATION` 会把账号标为 `authRequired` 并记录完整原因,停止定时探测。纯分类器 + 注入网络层的回归测试均已覆盖。
|
|
16
|
+
|
|
17
|
+
## 0.6.25 (2026-11-15)
|
|
18
|
+
|
|
19
|
+
### English
|
|
20
|
+
|
|
21
|
+
- **Perf(client): scope DOM scanning so streaming no longer sweeps the whole document (merges PR #110).** `scanAndEnhanceImages()` runs on a 100ms debounce for every DOM mutation; it previously re-queried every `a[href]` for three separate enhancers and walked every markdown container on each pass, even when nothing new existed. Links are now visited once (`data-agy-link-scanned`), image/video/file dispatch is a single pass, alt-span work exits early when no unenhanced spans remain, and origin rewrites skip already-processed images. Thanks to @Ronnoc for the profiling and patch.
|
|
22
|
+
- **Fix(client): a streaming markdown change re-evaluates previously skipped alt spans.** The perf pass stamps non-matching alt spans as scanned; without a guard, a span present before its `` link streamed in would be skipped forever. Containers now carry a short text fingerprint, and a changed fingerprint clears the stamps so the span is retried — the fast path stays a single attribute query. Regression test reproduces the two-chunk stream.
|
|
23
|
+
|
|
24
|
+
### 中文
|
|
25
|
+
|
|
26
|
+
- **性能(客户端):收敛 DOM 扫描范围,避免流式输出时全文档轮询(合并 PR #110)。** `scanAndEnhanceImages()` 在每次 DOM 变更的 100ms debounce 上执行,旧实现对全部 `a[href]` 跑三遍增强器、并遍历页面上每个 markdown 容器,即使没有新节点也重复解析。现在链接只访问一次(`data-agy-link-scanned`)、图片/视频/文件判断合并为单趟、无未处理 alt span 时快速返回、已改写的图片不再重复处理。感谢 @Ronnoc 的定位与补丁。
|
|
27
|
+
- **修复(客户端):markdown 文本变化后重新评估此前跳过的 alt span。** 性能优化会把「当前没有本地图片匹配」的 span 标记为已扫描;若 span 先于 `` 链接出现(流式分块),就会永久跳过。现为每个容器保存短文本指纹,指纹变化时清除标记并重试;快速路径仍只是一次属性查询。新增两段式流式回归测试。
|
|
28
|
+
|
|
3
29
|
## 0.6.24 (2026-11-14)
|
|
4
30
|
|
|
5
31
|
### English
|
package/dist/cli-image.mjs
CHANGED
|
@@ -1791,6 +1791,13 @@ function isHarnessInjectedUserText(text) {
|
|
|
1791
1791
|
* "anywhere" swallowed exactly that: a message sent right after a goal
|
|
1792
1792
|
* completed was finished as an empty turn without spawning agy
|
|
1793
1793
|
* (2026-10-17, "把相关的经验整理到agents.md" × 2).
|
|
1794
|
+
*
|
|
1795
|
+
* The TEXTUAL marker is only trustworthy on a user-role message (the `tool-goal`
|
|
1796
|
+
* notice). Reading it out of every message let the agent's own tool output
|
|
1797
|
+
* poison the scan: a `grep` over the built `dist/index.js` — whose doc comments
|
|
1798
|
+
* contain the literal marker — printed it into a tool result, and the very next
|
|
1799
|
+
* request was short-circuited into an EMPTY turn that was still recorded as
|
|
1800
|
+
* "completed" (2026-11-15, three silent replies in a row).
|
|
1794
1801
|
*/
|
|
1795
1802
|
function isGoalToolContinuation(messages) {
|
|
1796
1803
|
if (messages.length === 0) return false;
|
|
@@ -1803,7 +1810,7 @@ function isGoalToolContinuation(messages) {
|
|
|
1803
1810
|
const src = m.source;
|
|
1804
1811
|
if (src && typeof src === "object" && src.kind === "tool-goal") return true;
|
|
1805
1812
|
const text = extractText$1(m);
|
|
1806
|
-
if (text.includes("<goal_complete>")) return true;
|
|
1813
|
+
if (m.role === "user" && text.includes("<goal_complete>")) return true;
|
|
1807
1814
|
if (m.role === "user" && text.trim() !== "" && !isHarnessInjectedUserText(text)) return false;
|
|
1808
1815
|
}
|
|
1809
1816
|
return false;
|
package/dist/client.js
CHANGED
|
@@ -2622,24 +2622,67 @@ window.__ModuleLoader__.load({
|
|
|
2622
2622
|
}
|
|
2623
2623
|
function rewriteMediaOrigins(origin) {
|
|
2624
2624
|
if (!origin || origin.includes("127.0.0.1") || origin.includes("localhost")) return;
|
|
2625
|
-
const images = document.querySelectorAll("img[src*=\"/plugins/agy-link/media\"]");
|
|
2625
|
+
const images = document.querySelectorAll("img[src*=\"/plugins/agy-link/media\"]:not([data-agy-origin-rewritten])");
|
|
2626
2626
|
for (let i = 0; i < images.length; i++) {
|
|
2627
2627
|
const img = images[i];
|
|
2628
|
-
if (img
|
|
2628
|
+
if (!img) continue;
|
|
2629
|
+
if (img.src.includes("127.0.0.1")) {
|
|
2629
2630
|
const u = new URL(img.src);
|
|
2630
2631
|
img.src = `${origin}${u.pathname}${u.search}`;
|
|
2631
2632
|
}
|
|
2633
|
+
img.dataset.agyOriginRewritten = "true";
|
|
2632
2634
|
}
|
|
2633
2635
|
}
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2636
|
+
/**
|
|
2637
|
+
* PR #110 stamps non-matching alt spans as "scanned" so later passes can exit
|
|
2638
|
+
* early. Streaming markdown grows while tokens arrive, so a span skipped once
|
|
2639
|
+
* must be re-evaluated when its container's markdown text changes. Track a
|
|
2640
|
+
* short fingerprint on the container (never the whole text) and clear the
|
|
2641
|
+
* stamps only for containers whose text actually changed — the fast path stays
|
|
2642
|
+
* a single cheap attribute query.
|
|
2643
|
+
*/
|
|
2644
|
+
const ALT_MD_ATTR = "data-agy-alt-md";
|
|
2645
|
+
function markdownTextOf(container) {
|
|
2646
|
+
const props = getReactProps(container);
|
|
2647
|
+
return typeof props?.text === "string" ? props.text : "";
|
|
2648
|
+
}
|
|
2649
|
+
function altFingerprint(text) {
|
|
2650
|
+
let h = 5381;
|
|
2651
|
+
for (let i = 0; i < text.length; i++) h = (h << 5) + h + text.charCodeAt(i) | 0;
|
|
2652
|
+
return `${text.length}:${h}`;
|
|
2653
|
+
}
|
|
2654
|
+
function refreshChangedAltContainers() {
|
|
2655
|
+
const tracked = document.querySelectorAll(`[${ALT_MD_ATTR}]`);
|
|
2656
|
+
for (let i = 0; i < tracked.length; i++) {
|
|
2657
|
+
const container = tracked[i];
|
|
2638
2658
|
if (!container) continue;
|
|
2639
|
-
const
|
|
2640
|
-
if (
|
|
2641
|
-
|
|
2642
|
-
const
|
|
2659
|
+
const next = altFingerprint(markdownTextOf(container));
|
|
2660
|
+
if (container.getAttribute(ALT_MD_ATTR) === next) continue;
|
|
2661
|
+
container.setAttribute(ALT_MD_ATTR, next);
|
|
2662
|
+
const spans = container.querySelectorAll("span[class*=\"imageAlt\"], span[class*=\"_imageAlt_\"]");
|
|
2663
|
+
for (let j = 0; j < spans.length; j++) {
|
|
2664
|
+
const span = spans[j];
|
|
2665
|
+
if (span && span.dataset.agyEnhanced !== "true") delete span.dataset.agyAltScanned;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
function enhanceAltSpans() {
|
|
2670
|
+
refreshChangedAltContainers();
|
|
2671
|
+
const unenhancedSpans = document.querySelectorAll("span[class*=\"imageAlt\"]:not([data-agy-alt-scanned]):not([data-agy-enhanced]), span[class*=\"_imageAlt_\"]:not([data-agy-alt-scanned]):not([data-agy-enhanced])");
|
|
2672
|
+
if (unenhancedSpans.length === 0) return;
|
|
2673
|
+
const seenContainers = /* @__PURE__ */ new Set();
|
|
2674
|
+
for (let i = 0; i < unenhancedSpans.length; i++) {
|
|
2675
|
+
const span = unenhancedSpans[i];
|
|
2676
|
+
if (!span) continue;
|
|
2677
|
+
const container = span.closest("div[class*=\"_markdown_\"], [data-markdown-variant]");
|
|
2678
|
+
if (container) seenContainers.add(container);
|
|
2679
|
+
else span.dataset.agyAltScanned = "true";
|
|
2680
|
+
}
|
|
2681
|
+
for (const container of seenContainers) {
|
|
2682
|
+
const allSpans = container.querySelectorAll("span[class*=\"imageAlt\"], span[class*=\"_imageAlt_\"]");
|
|
2683
|
+
if (allSpans.length === 0) continue;
|
|
2684
|
+
const mdText = markdownTextOf(container);
|
|
2685
|
+
container.setAttribute(ALT_MD_ATTR, altFingerprint(mdText));
|
|
2643
2686
|
if (!mdText) continue;
|
|
2644
2687
|
const imgMatches = [];
|
|
2645
2688
|
const re = /!\[(.*?)\]\((file:\/\/\/[^\s)]+|file:\/\/[^\s)]+|[A-Za-z]:[\\/][^\s)]+|\/home\/[^\s)]+|\/mnt\/[a-zA-Z]\/[^\s)]+|\\\\wsl\.localhost\\[^\s)]+)\)/g;
|
|
@@ -2648,10 +2691,17 @@ window.__ModuleLoader__.load({
|
|
|
2648
2691
|
alt: m[1] ?? "",
|
|
2649
2692
|
target: m[2] ?? ""
|
|
2650
2693
|
});
|
|
2651
|
-
if (imgMatches.length === 0)
|
|
2652
|
-
|
|
2653
|
-
|
|
2694
|
+
if (imgMatches.length === 0) {
|
|
2695
|
+
for (let j = 0; j < allSpans.length; j++) {
|
|
2696
|
+
const span = allSpans[j];
|
|
2697
|
+
if (span) span.dataset.agyAltScanned = "true";
|
|
2698
|
+
}
|
|
2699
|
+
continue;
|
|
2700
|
+
}
|
|
2701
|
+
for (let j = 0; j < allSpans.length; j++) {
|
|
2702
|
+
const span = allSpans[j];
|
|
2654
2703
|
if (!span || span.dataset.agyEnhanced === "true") continue;
|
|
2704
|
+
span.dataset.agyAltScanned = "true";
|
|
2655
2705
|
const altText = (span.textContent ?? "").trim();
|
|
2656
2706
|
const match = imgMatches.find((im) => im.alt.trim() === altText) ?? imgMatches[j];
|
|
2657
2707
|
if (!match) continue;
|
|
@@ -2688,109 +2738,100 @@ window.__ModuleLoader__.load({
|
|
|
2688
2738
|
}
|
|
2689
2739
|
}
|
|
2690
2740
|
}
|
|
2691
|
-
function
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
if (
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2741
|
+
function enhanceImageLink(link, rawHref, resolvedHref) {
|
|
2742
|
+
link.dataset.agyLinkEnhanced = "true";
|
|
2743
|
+
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2744
|
+
const mediaUrl = buildMediaUrl(pathToUse);
|
|
2745
|
+
const linkText = (link.textContent ?? "Image").replace(/预览$/, "").trim();
|
|
2746
|
+
link.addEventListener("click", (e) => {
|
|
2747
|
+
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2748
|
+
e.preventDefault();
|
|
2749
|
+
e.stopPropagation();
|
|
2750
|
+
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2751
|
+
});
|
|
2752
|
+
if (!link.querySelector(".agy-image-link-icon")) {
|
|
2753
|
+
const badge = document.createElement("span");
|
|
2754
|
+
badge.className = "agy-image-link-chip agy-image-link-icon";
|
|
2755
|
+
badge.setAttribute("role", "button");
|
|
2756
|
+
badge.setAttribute("tabindex", "0");
|
|
2757
|
+
badge.title = `预览图片 / Preview (${linkText})`;
|
|
2758
|
+
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"vertical-align:-1px;display:inline-block;\"><path d=\"M1 8s3-5.5 7-5.5S15 8 15 8s-3 5.5-7 5.5S1 8 1 8z\"/><circle cx=\"8\" cy=\"8\" r=\"2.5\"/></svg></span><span class=\"agy-image-chip-text\">预览</span>";
|
|
2759
|
+
badge.onclick = (e) => {
|
|
2704
2760
|
e.preventDefault();
|
|
2705
2761
|
e.stopPropagation();
|
|
2706
2762
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2707
|
-
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
badge.className = "agy-image-link-chip agy-image-link-icon";
|
|
2711
|
-
badge.setAttribute("role", "button");
|
|
2712
|
-
badge.setAttribute("tabindex", "0");
|
|
2713
|
-
badge.title = `预览图片 / Preview (${linkText})`;
|
|
2714
|
-
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"vertical-align:-1px;display:inline-block;\"><path d=\"M1 8s3-5.5 7-5.5S15 8 15 8s-3 5.5-7 5.5S1 8 1 8z\"/><circle cx=\"8\" cy=\"8\" r=\"2.5\"/></svg></span><span class=\"agy-image-chip-text\">预览</span>";
|
|
2715
|
-
badge.onclick = (e) => {
|
|
2763
|
+
};
|
|
2764
|
+
badge.onkeydown = (e) => {
|
|
2765
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2716
2766
|
e.preventDefault();
|
|
2717
2767
|
e.stopPropagation();
|
|
2718
2768
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
e.preventDefault();
|
|
2723
|
-
e.stopPropagation();
|
|
2724
|
-
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2725
|
-
}
|
|
2726
|
-
};
|
|
2727
|
-
link.appendChild(badge);
|
|
2728
|
-
}
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
link.appendChild(badge);
|
|
2729
2772
|
}
|
|
2730
2773
|
}
|
|
2731
|
-
function
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
if (
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2774
|
+
function enhanceVideoLink(link, rawHref, resolvedHref) {
|
|
2775
|
+
link.dataset.agyVideoEnhanced = "true";
|
|
2776
|
+
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2777
|
+
const mediaUrl = buildMediaUrl(pathToUse);
|
|
2778
|
+
const linkText = (link.textContent ?? "Video").replace(/播放$/, "").trim();
|
|
2779
|
+
link.addEventListener("click", (e) => {
|
|
2780
|
+
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2781
|
+
e.preventDefault();
|
|
2782
|
+
e.stopPropagation();
|
|
2783
|
+
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2784
|
+
});
|
|
2785
|
+
if (!link.querySelector(".agy-video-link-icon")) {
|
|
2786
|
+
const badge = document.createElement("span");
|
|
2787
|
+
badge.className = "agy-image-link-chip agy-chip-video agy-video-link-icon";
|
|
2788
|
+
badge.setAttribute("role", "button");
|
|
2789
|
+
badge.setAttribute("tabindex", "0");
|
|
2790
|
+
badge.title = `播放视频 / Play Video (${linkText})`;
|
|
2791
|
+
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"10\" height=\"10\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><polygon points=\"5 3 19 12 5 21 5 3\"></polygon></svg></span><span class=\"agy-image-chip-text\">播放</span>";
|
|
2792
|
+
badge.onclick = (e) => {
|
|
2744
2793
|
e.preventDefault();
|
|
2745
2794
|
e.stopPropagation();
|
|
2746
2795
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
badge.className = "agy-image-link-chip agy-chip-video agy-video-link-icon";
|
|
2751
|
-
badge.setAttribute("role", "button");
|
|
2752
|
-
badge.setAttribute("tabindex", "0");
|
|
2753
|
-
badge.title = `播放视频 / Play Video (${linkText})`;
|
|
2754
|
-
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"10\" height=\"10\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><polygon points=\"5 3 19 12 5 21 5 3\"></polygon></svg></span><span class=\"agy-image-chip-text\">播放</span>";
|
|
2755
|
-
badge.onclick = (e) => {
|
|
2796
|
+
};
|
|
2797
|
+
badge.onkeydown = (e) => {
|
|
2798
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2756
2799
|
e.preventDefault();
|
|
2757
2800
|
e.stopPropagation();
|
|
2758
2801
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2759
|
-
}
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
e.preventDefault();
|
|
2763
|
-
e.stopPropagation();
|
|
2764
|
-
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2765
|
-
}
|
|
2766
|
-
};
|
|
2767
|
-
link.appendChild(badge);
|
|
2768
|
-
}
|
|
2802
|
+
}
|
|
2803
|
+
};
|
|
2804
|
+
link.appendChild(badge);
|
|
2769
2805
|
}
|
|
2770
2806
|
}
|
|
2771
|
-
function
|
|
2807
|
+
function enhanceFileLink(link, rawHref, resolvedHref) {
|
|
2808
|
+
link.dataset.agyFileEnhanced = "true";
|
|
2809
|
+
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2810
|
+
link.addEventListener("click", (e) => {
|
|
2811
|
+
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2812
|
+
e.preventDefault();
|
|
2813
|
+
e.stopPropagation();
|
|
2814
|
+
const fileName = pathToUse.split(/[/\\]/).pop() || pathToUse;
|
|
2815
|
+
if (openInRightSidebar(pathToUse)) {
|
|
2816
|
+
showToast(`已在原生边栏打开: ${fileName}`);
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2819
|
+
openInSystem(pathToUse, false).then((res) => {
|
|
2820
|
+
showToast(res.ok ? `已在系统程序中打开: ${fileName}` : `打开失败: ${res.error || "未找到文件"}`);
|
|
2821
|
+
});
|
|
2822
|
+
});
|
|
2823
|
+
}
|
|
2824
|
+
function enhanceLinks() {
|
|
2825
|
+
const links = document.querySelectorAll("a[href]:not([data-agy-link-scanned]):not([data-agy-link-enhanced]):not([data-agy-video-enhanced]):not([data-agy-file-enhanced])");
|
|
2772
2826
|
for (let i = 0; i < links.length; i++) {
|
|
2773
2827
|
const link = links[i];
|
|
2774
|
-
if (!link
|
|
2828
|
+
if (!link) continue;
|
|
2829
|
+
link.dataset.agyLinkScanned = "true";
|
|
2775
2830
|
const rawHref = link.getAttribute("href") ?? "";
|
|
2776
2831
|
const resolvedHref = link.href ?? "";
|
|
2777
|
-
if (isImageFile(rawHref) || isImageFile(resolvedHref)
|
|
2778
|
-
if (
|
|
2779
|
-
|
|
2780
|
-
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2781
|
-
link.addEventListener("click", (e) => {
|
|
2782
|
-
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2783
|
-
e.preventDefault();
|
|
2784
|
-
e.stopPropagation();
|
|
2785
|
-
const fileName = pathToUse.split(/[/\\]/).pop() || pathToUse;
|
|
2786
|
-
if (openInRightSidebar(pathToUse)) {
|
|
2787
|
-
showToast(`已在原生边栏打开: ${fileName}`);
|
|
2788
|
-
return;
|
|
2789
|
-
}
|
|
2790
|
-
openInSystem(pathToUse, false).then((res) => {
|
|
2791
|
-
showToast(res.ok ? `已在系统程序中打开: ${fileName}` : `打开失败: ${res.error || "未找到文件"}`);
|
|
2792
|
-
});
|
|
2793
|
-
});
|
|
2832
|
+
if (isImageFile(rawHref) || isImageFile(resolvedHref)) enhanceImageLink(link, rawHref, resolvedHref);
|
|
2833
|
+
else if (isVideoFile(rawHref) || isVideoFile(resolvedHref)) enhanceVideoLink(link, rawHref, resolvedHref);
|
|
2834
|
+
else if (rawHref.startsWith("file://") || resolvedHref.startsWith("file://") || isLocalFilePath(rawHref)) enhanceFileLink(link, rawHref, resolvedHref);
|
|
2794
2835
|
}
|
|
2795
2836
|
}
|
|
2796
2837
|
/**
|
|
@@ -2801,10 +2842,7 @@ window.__ModuleLoader__.load({
|
|
|
2801
2842
|
if (isInteractionLocked()) return;
|
|
2802
2843
|
rewriteMediaOrigins(getOrigin());
|
|
2803
2844
|
enhanceAltSpans();
|
|
2804
|
-
|
|
2805
|
-
enhanceImageLinks(links);
|
|
2806
|
-
enhanceVideoLinks(links);
|
|
2807
|
-
enhanceFileLinks(links);
|
|
2845
|
+
enhanceLinks();
|
|
2808
2846
|
}
|
|
2809
2847
|
let imageEnhancerDispose = null;
|
|
2810
2848
|
let imageScanTimer = null;
|
package/dist/index.js
CHANGED
|
@@ -3205,6 +3205,13 @@ function isHarnessInjectedUserText(text) {
|
|
|
3205
3205
|
* "anywhere" swallowed exactly that: a message sent right after a goal
|
|
3206
3206
|
* completed was finished as an empty turn without spawning agy
|
|
3207
3207
|
* (2026-10-17, "把相关的经验整理到agents.md" × 2).
|
|
3208
|
+
*
|
|
3209
|
+
* The TEXTUAL marker is only trustworthy on a user-role message (the `tool-goal`
|
|
3210
|
+
* notice). Reading it out of every message let the agent's own tool output
|
|
3211
|
+
* poison the scan: a `grep` over the built `dist/index.js` — whose doc comments
|
|
3212
|
+
* contain the literal marker — printed it into a tool result, and the very next
|
|
3213
|
+
* request was short-circuited into an EMPTY turn that was still recorded as
|
|
3214
|
+
* "completed" (2026-11-15, three silent replies in a row).
|
|
3208
3215
|
*/
|
|
3209
3216
|
function isGoalToolContinuation(messages) {
|
|
3210
3217
|
if (messages.length === 0) return false;
|
|
@@ -3217,7 +3224,7 @@ function isGoalToolContinuation(messages) {
|
|
|
3217
3224
|
const src = m.source;
|
|
3218
3225
|
if (src && typeof src === "object" && src.kind === "tool-goal") return true;
|
|
3219
3226
|
const text = extractText(m);
|
|
3220
|
-
if (text.includes("<goal_complete>")) return true;
|
|
3227
|
+
if (m.role === "user" && text.includes("<goal_complete>")) return true;
|
|
3221
3228
|
if (m.role === "user" && text.trim() !== "" && !isHarnessInjectedUserText(text)) return false;
|
|
3222
3229
|
}
|
|
3223
3230
|
return false;
|
|
@@ -32038,12 +32045,15 @@ async function fetchUserEmail(accessToken, proxyUrl) {
|
|
|
32038
32045
|
* {"token": {access_token, token_type, refresh_token, expiry}, "auth_method": "consumer"}
|
|
32039
32046
|
* where expiry is a local-time ISO-8601 string with timezone offset.
|
|
32040
32047
|
*/
|
|
32041
|
-
|
|
32042
|
-
|
|
32043
|
-
|
|
32044
|
-
|
|
32045
|
-
|
|
32046
|
-
|
|
32048
|
+
/**
|
|
32049
|
+
* Serialize a token set into agy's own credential document. This is the ONE
|
|
32050
|
+
* writer for both the on-disk token file and the Windows credential slot: an
|
|
32051
|
+
* import that hand-built the doc without `expiry` produced a token that was
|
|
32052
|
+
* treated as valid forever and then 401'd forever (issue #112).
|
|
32053
|
+
*/
|
|
32054
|
+
function buildAgyCredentialDoc(tokens, now = Date.now()) {
|
|
32055
|
+
const expiryIso = formatLocalIso(tokens.expiryMs ?? now + 36e5);
|
|
32056
|
+
return JSON.stringify({
|
|
32047
32057
|
token: {
|
|
32048
32058
|
access_token: tokens.access_token,
|
|
32049
32059
|
token_type: tokens.token_type ?? "Bearer",
|
|
@@ -32051,8 +32061,13 @@ function writeAgyTokenFile(homeDir, tokens) {
|
|
|
32051
32061
|
expiry: expiryIso
|
|
32052
32062
|
},
|
|
32053
32063
|
auth_method: "consumer"
|
|
32054
|
-
};
|
|
32055
|
-
|
|
32064
|
+
});
|
|
32065
|
+
}
|
|
32066
|
+
function writeAgyTokenFile(homeDir, tokens) {
|
|
32067
|
+
const dir = join(homeDir, ".gemini", "antigravity-cli");
|
|
32068
|
+
mkdirSync(dir, { recursive: true });
|
|
32069
|
+
const file = join(dir, "antigravity-oauth-token");
|
|
32070
|
+
writeFileSync(file, buildAgyCredentialDoc(tokens), {
|
|
32056
32071
|
encoding: "utf8",
|
|
32057
32072
|
mode: 384
|
|
32058
32073
|
});
|
|
@@ -37481,14 +37496,7 @@ var PoolAuthFlow = class {
|
|
|
37481
37496
|
if (existing) {
|
|
37482
37497
|
if (existing.dir && !existing.systemHome) saveCredentialBackup(writeAgyTokenFile(existing.dir, tokens));
|
|
37483
37498
|
else if (process.platform === "win32") try {
|
|
37484
|
-
const docStr =
|
|
37485
|
-
token: {
|
|
37486
|
-
access_token: tokens.access_token,
|
|
37487
|
-
token_type: tokens.token_type ?? "Bearer",
|
|
37488
|
-
refresh_token: tokens.refresh_token
|
|
37489
|
-
},
|
|
37490
|
-
auth_method: "consumer"
|
|
37491
|
-
});
|
|
37499
|
+
const docStr = buildAgyCredentialDoc(tokens);
|
|
37492
37500
|
writeWindowsCredentialRaw(docStr, "gemini:antigravity");
|
|
37493
37501
|
writePrimaryCredential({
|
|
37494
37502
|
raw: docStr,
|
|
@@ -38727,10 +38735,19 @@ async function getValidAccessToken(deps, account, tokenRefreshInFlight) {
|
|
|
38727
38735
|
tokenRefreshInFlight.set(account.id, attempt);
|
|
38728
38736
|
return attempt;
|
|
38729
38737
|
}
|
|
38738
|
+
/**
|
|
38739
|
+
* A token is fresh only when it has a KNOWN future expiry (60s buffer).
|
|
38740
|
+
* A missing expiry is not "valid forever": credentials written by older
|
|
38741
|
+
* imports must go through refresh/validation instead of being reused until
|
|
38742
|
+
* they 401 (issue #112).
|
|
38743
|
+
*/
|
|
38744
|
+
function isAccessTokenFresh(tok, now = Date.now()) {
|
|
38745
|
+
return !!tok.accessToken && typeof tok.expiryMs === "number" && tok.expiryMs > now + 6e4;
|
|
38746
|
+
}
|
|
38730
38747
|
async function getValidAccessTokenUncached(deps, account) {
|
|
38731
38748
|
const tok = await deps.getStoredToken(account);
|
|
38732
38749
|
if (!tok) return null;
|
|
38733
|
-
if (tok.accessToken && (
|
|
38750
|
+
if (tok.accessToken && isAccessTokenFresh(tok)) return tok.accessToken;
|
|
38734
38751
|
if (tok.refreshToken) try {
|
|
38735
38752
|
const refreshed = await refreshTokens(tok.refreshToken, deps.proxyFor(account));
|
|
38736
38753
|
if (!isCurrentAccountGrant(deps, account, tok.refreshToken)) return null;
|
|
@@ -39200,6 +39217,21 @@ function planWarmupTargets(params) {
|
|
|
39200
39217
|
targets
|
|
39201
39218
|
};
|
|
39202
39219
|
}
|
|
39220
|
+
/**
|
|
39221
|
+
* Keep the upstream error readable instead of slicing it to 160 characters.
|
|
39222
|
+
* A `TOS_VIOLATION` 403 is a terminal ban: the 5-minute scheduler must stop
|
|
39223
|
+
* hammering that account, and the appeal URL must reach the UI (issue #112).
|
|
39224
|
+
*/
|
|
39225
|
+
function describeWarmupError(status, body) {
|
|
39226
|
+
const detail = body.trim().slice(0, 2e3);
|
|
39227
|
+
const appealUrl = /"appeal_url"\s*:\s*"([^"]+)"/.exec(body)?.[1];
|
|
39228
|
+
const terminal = /TOS_VIOLATION/i.test(body);
|
|
39229
|
+
return {
|
|
39230
|
+
error: `HTTP ${status}: ${detail}${appealUrl ? ` Appeal: ${appealUrl}` : ""}`,
|
|
39231
|
+
terminal,
|
|
39232
|
+
...appealUrl ? { appealUrl } : {}
|
|
39233
|
+
};
|
|
39234
|
+
}
|
|
39203
39235
|
//#endregion
|
|
39204
39236
|
//#region src/features/warmup/history.ts
|
|
39205
39237
|
var WarmupHistoryStore = class {
|
|
@@ -39259,14 +39291,16 @@ var WarmupService = class {
|
|
|
39259
39291
|
agyVersion;
|
|
39260
39292
|
config;
|
|
39261
39293
|
log;
|
|
39294
|
+
fetchImpl;
|
|
39262
39295
|
history;
|
|
39263
|
-
constructor(pool, quota, globalProxy = () => "", agyVersion = () => null, config = () => ({}), log = () => void 0, historyStore) {
|
|
39296
|
+
constructor(pool, quota, globalProxy = () => "", agyVersion = () => null, config = () => ({}), log = () => void 0, historyStore, fetchImpl = agyFetch) {
|
|
39264
39297
|
this.pool = pool;
|
|
39265
39298
|
this.quota = quota;
|
|
39266
39299
|
this.globalProxy = globalProxy;
|
|
39267
39300
|
this.agyVersion = agyVersion;
|
|
39268
39301
|
this.config = config;
|
|
39269
39302
|
this.log = log;
|
|
39303
|
+
this.fetchImpl = fetchImpl;
|
|
39270
39304
|
this.history = historyStore ?? new WarmupHistoryStore();
|
|
39271
39305
|
}
|
|
39272
39306
|
proxyFor(account) {
|
|
@@ -39352,7 +39386,8 @@ var WarmupService = class {
|
|
|
39352
39386
|
let lastStatus = 0;
|
|
39353
39387
|
let lastError = "";
|
|
39354
39388
|
for (const attempt of attempts) for (const ep of endpoints) try {
|
|
39355
|
-
const
|
|
39389
|
+
const targetUrl = `${ep}/v1internal:${attempt.method}${attempt.query}`;
|
|
39390
|
+
const res = await this.fetchImpl(targetUrl, {
|
|
39356
39391
|
method: "POST",
|
|
39357
39392
|
headers,
|
|
39358
39393
|
body: reqBody
|
|
@@ -39379,13 +39414,20 @@ var WarmupService = class {
|
|
|
39379
39414
|
error: "Account requires browser validation (VALIDATION_REQUIRED)",
|
|
39380
39415
|
durationMs: Date.now() - start
|
|
39381
39416
|
};
|
|
39382
|
-
|
|
39383
|
-
|
|
39384
|
-
|
|
39385
|
-
|
|
39386
|
-
|
|
39387
|
-
|
|
39388
|
-
|
|
39417
|
+
const described = describeWarmupError(res.status, errBody);
|
|
39418
|
+
lastError = described.error;
|
|
39419
|
+
if (res.status === 401 || res.status === 403) {
|
|
39420
|
+
if (described.terminal) {
|
|
39421
|
+
this.pool.markAuthRequired(account.id, described.error);
|
|
39422
|
+
this.log(`[agy-link] warmup: ${account.alias || account.id} is terminal: ${described.error}`);
|
|
39423
|
+
}
|
|
39424
|
+
return {
|
|
39425
|
+
ok: false,
|
|
39426
|
+
status: res.status,
|
|
39427
|
+
error: described.error,
|
|
39428
|
+
durationMs: Date.now() - start
|
|
39429
|
+
};
|
|
39430
|
+
}
|
|
39389
39431
|
} catch (err) {
|
|
39390
39432
|
lastError = String(err);
|
|
39391
39433
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agy-link",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.26",
|
|
4
4
|
"description": "Google Antigravity (agy CLI) models for DeepSeek Harness — stream Gemini/Claude/GPT-OSS subscriptions into DSH with thinking, tool activity, token usage and in-GUI Google OAuth login.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|