dsh-agy-link 0.6.25 → 0.6.27

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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.27 (2026-11-15)
4
+
5
+ ### English
6
+
7
+ - **Fix(security): DSH plan mode is now read-only at the agy layer (issue #113, part 2).** `permissionMode` was always taken from the static config (default `skip` → `--dangerously-skip-permissions`), so during a plan-mode turn agy could still write files and the `exit_plan_mode` approval card only constrained the prompt. A new `effectivePermissionMode()` forces `--mode plan` when the host is in plan mode, using the presence of the `exit_plan_mode` tool as a **current-turn** signal so exiting plan mode immediately restores the configured mode; auxiliary calls keep their existing read-only policy. Pure decision matrix + real-spawn argv regression tests.
8
+ - **Not planned: interactive `ask_question` / `/grill-me` (issue #113, part 1).** This is not a filter bug: agy's `-p` / `--input-format stream-json` print mode is one-way and auto-answers `ask_question` with `User Skipped`. Making it interactive requires replacing the bridge's transport with ACP (`agy acp`, stdio JSON-RPC) — a different session lifecycle, streaming protocol and tool-mirroring path, i.e. a separate architectural project, not a patch. The question card rendering already exists; it appears after the turn because print mode cannot pause. Tracked in the issue reply, not shipped here.
9
+
10
+ ### 中文
11
+
12
+ - **修复(安全):DSH plan mode 在 agy 层也强制只读(issue #113 第 2 项)。** `permissionMode` 此前只取静态配置(缺省 `skip` → `--dangerously-skip-permissions`),所以规划轮次里 agy 仍能直接写文件,`exit_plan_mode` 审批卡只约束了提示词。新增 `effectivePermissionMode()`:当宿主处于 plan mode 时强制 `--mode plan`,并以「本轮提供了 `exit_plan_mode` 工具」作为当前轮次信号(避免历史里的 plan 提示词让会话永久只读),退出 plan mode 立即恢复配置值;辅助调用沿用既有只读策略。纯函数矩阵 + 真实 spawn argv 双重回归测试。
13
+ - **暂不实现:交互式 `ask_question` / `/grill-me`(issue #113 第 1 项)。** 这不是过滤逻辑缺陷:agy 的 `-p` / `--input-format stream-json` 是单向 print 模式,会把 `ask_question` 自动回填 `User Skipped`。要真正交互必须把桥接层传输协议换成 ACP(`agy acp`,stdio JSON-RPC),涉及完全不同的会话生命周期、流式协议与工具镜像链路,属于独立架构项目而非补丁。问题卡片渲染已存在,只是因为 print 模式无法暂停而出现在轮次结束之后。已在 issue 回复中说明,本版本不发布该能力。
14
+
15
+ ## 0.6.26 (2026-11-15)
16
+
17
+ ### English
18
+
19
+ - **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.
20
+ - **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.
21
+ - **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.
22
+
23
+ ### 中文
24
+
25
+ - **修复(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 测试。
26
+ - **修复(认证):Windows 导入凭据不再造成永久 401 死锁(修复 #112)。** `/agy import` 在 Windows 主账号分支手工拼装了缺少 `expiry` 的 token 文档;`getValidAccessTokenUncached()` 把「缺失 expiry」当成永久有效,旧 access_token 一直复用到 Google 拒绝,而 `force:true` 的预热/额度刷新同样绕不过该判断——一次导入就自造不可逆死循环。现在导入复用 `buildAgyCredentialDoc()`(与磁盘 token 文件同一写入器,必带 expiry 或有界兜底),且**未知 expiry 一律视为需要刷新/校验**而非新鲜。
27
+ - **修复(预热):TOS 终态封禁改为隔离,不再每 5 分钟空转(修复 #112)。** 403 `TOS_VIOLATION` 此前被截到 160 字符(丢失 `appeal_url`)并按普通失败返回,`authRequired`/冷却一直为空。现在保留最多 2000 字符并显式附 `Appeal:` 链接;`TOS_VIOLATION` 会把账号标为 `authRequired` 并记录完整原因,停止定时探测。纯分类器 + 注入网络层的回归测试均已覆盖。
28
+
3
29
  ## 0.6.25 (2026-11-15)
4
30
 
5
31
  ### English
@@ -1502,6 +1502,20 @@ function defaultPoolData() {
1502
1502
  }
1503
1503
  //#endregion
1504
1504
  //#region src/provider/call-context.ts
1505
+ /**
1506
+ * Effective agy permission mode for one turn.
1507
+ *
1508
+ * DSH plan mode is a READ-ONLY contract. `cfg.permissionMode` is static and
1509
+ * defaults to `skip` (`--dangerously-skip-permissions`); without this override
1510
+ * agy can write files while the host believes it is only planning (issue #113).
1511
+ * The caller supplies `dshPlanMode` from a CURRENT-turn signal (the host only
1512
+ * exposes `exit_plan_mode` while plan mode is active), never from stale
1513
+ * history, so exiting plan mode restores the configured mode immediately.
1514
+ * Auxiliary calls already have their own read-only policy.
1515
+ */
1516
+ function effectivePermissionMode(configured, dshPlanMode, isAux) {
1517
+ return dshPlanMode && !isAux ? "plan" : configured;
1518
+ }
1505
1519
  function resolveCallContext(input) {
1506
1520
  const { options, cfg, bin } = input;
1507
1521
  if (!bin) throw new LlmError("agy binary not found on PATH — install it via https://antigravity.google/docs/cli/install", Err.AGY_NOT_INSTALLED);
@@ -1791,6 +1805,13 @@ function isHarnessInjectedUserText(text) {
1791
1805
  * "anywhere" swallowed exactly that: a message sent right after a goal
1792
1806
  * completed was finished as an empty turn without spawning agy
1793
1807
  * (2026-10-17, "把相关的经验整理到agents.md" × 2).
1808
+ *
1809
+ * The TEXTUAL marker is only trustworthy on a user-role message (the `tool-goal`
1810
+ * notice). Reading it out of every message let the agent's own tool output
1811
+ * poison the scan: a `grep` over the built `dist/index.js` — whose doc comments
1812
+ * contain the literal marker — printed it into a tool result, and the very next
1813
+ * request was short-circuited into an EMPTY turn that was still recorded as
1814
+ * "completed" (2026-11-15, three silent replies in a row).
1794
1815
  */
1795
1816
  function isGoalToolContinuation(messages) {
1796
1817
  if (messages.length === 0) return false;
@@ -1803,7 +1824,7 @@ function isGoalToolContinuation(messages) {
1803
1824
  const src = m.source;
1804
1825
  if (src && typeof src === "object" && src.kind === "tool-goal") return true;
1805
1826
  const text = extractText$1(m);
1806
- if (text.includes("<goal_complete>")) return true;
1827
+ if (m.role === "user" && text.includes("<goal_complete>")) return true;
1807
1828
  if (m.role === "user" && text.trim() !== "" && !isHarnessInjectedUserText(text)) return false;
1808
1829
  }
1809
1830
  return false;
@@ -34023,6 +34044,7 @@ var AgyAdapter = class extends LlmAdapter {
34023
34044
  const goalContext = resolveGoalContext(options.messages, liveGoal);
34024
34045
  const supportsGoalUpdate = Boolean(options.tools?.some((t) => t.name === "update_goal"));
34025
34046
  const supportsPlanExit = Boolean(options.tools?.some((t) => t.name === "exit_plan_mode")) && isPlanMode(options.messages);
34047
+ const agyPermissionMode = effectivePermissionMode(permissionMode, supportsPlanExit, isAux);
34026
34048
  const continuation = detectContinuation(options.messages);
34027
34049
  if (continuation !== null) {
34028
34050
  const rec = this.deps.runs.get(continuation.runId);
@@ -34202,7 +34224,7 @@ var AgyAdapter = class extends LlmAdapter {
34202
34224
  }, {
34203
34225
  cfg,
34204
34226
  bin,
34205
- permissionMode,
34227
+ permissionMode: agyPermissionMode,
34206
34228
  sessionKey,
34207
34229
  workspaceRoot,
34208
34230
  isAux,
package/dist/index.js CHANGED
@@ -2916,6 +2916,20 @@ async function runAgyOnce(deps, req) {
2916
2916
  }
2917
2917
  //#endregion
2918
2918
  //#region src/provider/call-context.ts
2919
+ /**
2920
+ * Effective agy permission mode for one turn.
2921
+ *
2922
+ * DSH plan mode is a READ-ONLY contract. `cfg.permissionMode` is static and
2923
+ * defaults to `skip` (`--dangerously-skip-permissions`); without this override
2924
+ * agy can write files while the host believes it is only planning (issue #113).
2925
+ * The caller supplies `dshPlanMode` from a CURRENT-turn signal (the host only
2926
+ * exposes `exit_plan_mode` while plan mode is active), never from stale
2927
+ * history, so exiting plan mode restores the configured mode immediately.
2928
+ * Auxiliary calls already have their own read-only policy.
2929
+ */
2930
+ function effectivePermissionMode(configured, dshPlanMode, isAux) {
2931
+ return dshPlanMode && !isAux ? "plan" : configured;
2932
+ }
2919
2933
  function resolveCallContext(input) {
2920
2934
  const { options, cfg, bin } = input;
2921
2935
  if (!bin) throw new LlmError("agy binary not found on PATH — install it via https://antigravity.google/docs/cli/install", Err.AGY_NOT_INSTALLED);
@@ -3205,6 +3219,13 @@ function isHarnessInjectedUserText(text) {
3205
3219
  * "anywhere" swallowed exactly that: a message sent right after a goal
3206
3220
  * completed was finished as an empty turn without spawning agy
3207
3221
  * (2026-10-17, "把相关的经验整理到agents.md" × 2).
3222
+ *
3223
+ * The TEXTUAL marker is only trustworthy on a user-role message (the `tool-goal`
3224
+ * notice). Reading it out of every message let the agent's own tool output
3225
+ * poison the scan: a `grep` over the built `dist/index.js` — whose doc comments
3226
+ * contain the literal marker — printed it into a tool result, and the very next
3227
+ * request was short-circuited into an EMPTY turn that was still recorded as
3228
+ * "completed" (2026-11-15, three silent replies in a row).
3208
3229
  */
3209
3230
  function isGoalToolContinuation(messages) {
3210
3231
  if (messages.length === 0) return false;
@@ -3217,7 +3238,7 @@ function isGoalToolContinuation(messages) {
3217
3238
  const src = m.source;
3218
3239
  if (src && typeof src === "object" && src.kind === "tool-goal") return true;
3219
3240
  const text = extractText(m);
3220
- if (text.includes("<goal_complete>")) return true;
3241
+ if (m.role === "user" && text.includes("<goal_complete>")) return true;
3221
3242
  if (m.role === "user" && text.trim() !== "" && !isHarnessInjectedUserText(text)) return false;
3222
3243
  }
3223
3244
  return false;
@@ -32038,12 +32059,15 @@ async function fetchUserEmail(accessToken, proxyUrl) {
32038
32059
  * {"token": {access_token, token_type, refresh_token, expiry}, "auth_method": "consumer"}
32039
32060
  * where expiry is a local-time ISO-8601 string with timezone offset.
32040
32061
  */
32041
- function writeAgyTokenFile(homeDir, tokens) {
32042
- const dir = join(homeDir, ".gemini", "antigravity-cli");
32043
- mkdirSync(dir, { recursive: true });
32044
- const file = join(dir, "antigravity-oauth-token");
32045
- const expiryIso = tokens.expiryMs ? formatLocalIso(tokens.expiryMs) : formatLocalIso(Date.now() + 36e5);
32046
- const doc = {
32062
+ /**
32063
+ * Serialize a token set into agy's own credential document. This is the ONE
32064
+ * writer for both the on-disk token file and the Windows credential slot: an
32065
+ * import that hand-built the doc without `expiry` produced a token that was
32066
+ * treated as valid forever and then 401'd forever (issue #112).
32067
+ */
32068
+ function buildAgyCredentialDoc(tokens, now = Date.now()) {
32069
+ const expiryIso = formatLocalIso(tokens.expiryMs ?? now + 36e5);
32070
+ return JSON.stringify({
32047
32071
  token: {
32048
32072
  access_token: tokens.access_token,
32049
32073
  token_type: tokens.token_type ?? "Bearer",
@@ -32051,8 +32075,13 @@ function writeAgyTokenFile(homeDir, tokens) {
32051
32075
  expiry: expiryIso
32052
32076
  },
32053
32077
  auth_method: "consumer"
32054
- };
32055
- writeFileSync(file, JSON.stringify(doc), {
32078
+ });
32079
+ }
32080
+ function writeAgyTokenFile(homeDir, tokens) {
32081
+ const dir = join(homeDir, ".gemini", "antigravity-cli");
32082
+ mkdirSync(dir, { recursive: true });
32083
+ const file = join(dir, "antigravity-oauth-token");
32084
+ writeFileSync(file, buildAgyCredentialDoc(tokens), {
32056
32085
  encoding: "utf8",
32057
32086
  mode: 384
32058
32087
  });
@@ -34534,6 +34563,7 @@ var AgyAdapter = class extends LlmAdapter {
34534
34563
  const goalContext = resolveGoalContext(options.messages, liveGoal);
34535
34564
  const supportsGoalUpdate = Boolean(options.tools?.some((t) => t.name === "update_goal"));
34536
34565
  const supportsPlanExit = Boolean(options.tools?.some((t) => t.name === "exit_plan_mode")) && isPlanMode(options.messages);
34566
+ const agyPermissionMode = effectivePermissionMode(permissionMode, supportsPlanExit, isAux);
34537
34567
  const continuation = detectContinuation(options.messages);
34538
34568
  if (continuation !== null) {
34539
34569
  const rec = this.deps.runs.get(continuation.runId);
@@ -34713,7 +34743,7 @@ var AgyAdapter = class extends LlmAdapter {
34713
34743
  }, {
34714
34744
  cfg,
34715
34745
  bin,
34716
- permissionMode,
34746
+ permissionMode: agyPermissionMode,
34717
34747
  sessionKey,
34718
34748
  workspaceRoot,
34719
34749
  isAux,
@@ -37481,14 +37511,7 @@ var PoolAuthFlow = class {
37481
37511
  if (existing) {
37482
37512
  if (existing.dir && !existing.systemHome) saveCredentialBackup(writeAgyTokenFile(existing.dir, tokens));
37483
37513
  else if (process.platform === "win32") try {
37484
- const docStr = JSON.stringify({
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
- });
37514
+ const docStr = buildAgyCredentialDoc(tokens);
37492
37515
  writeWindowsCredentialRaw(docStr, "gemini:antigravity");
37493
37516
  writePrimaryCredential({
37494
37517
  raw: docStr,
@@ -38727,10 +38750,19 @@ async function getValidAccessToken(deps, account, tokenRefreshInFlight) {
38727
38750
  tokenRefreshInFlight.set(account.id, attempt);
38728
38751
  return attempt;
38729
38752
  }
38753
+ /**
38754
+ * A token is fresh only when it has a KNOWN future expiry (60s buffer).
38755
+ * A missing expiry is not "valid forever": credentials written by older
38756
+ * imports must go through refresh/validation instead of being reused until
38757
+ * they 401 (issue #112).
38758
+ */
38759
+ function isAccessTokenFresh(tok, now = Date.now()) {
38760
+ return !!tok.accessToken && typeof tok.expiryMs === "number" && tok.expiryMs > now + 6e4;
38761
+ }
38730
38762
  async function getValidAccessTokenUncached(deps, account) {
38731
38763
  const tok = await deps.getStoredToken(account);
38732
38764
  if (!tok) return null;
38733
- if (tok.accessToken && (!tok.expiryMs || tok.expiryMs > Date.now() + 6e4)) return tok.accessToken;
38765
+ if (tok.accessToken && isAccessTokenFresh(tok)) return tok.accessToken;
38734
38766
  if (tok.refreshToken) try {
38735
38767
  const refreshed = await refreshTokens(tok.refreshToken, deps.proxyFor(account));
38736
38768
  if (!isCurrentAccountGrant(deps, account, tok.refreshToken)) return null;
@@ -39200,6 +39232,21 @@ function planWarmupTargets(params) {
39200
39232
  targets
39201
39233
  };
39202
39234
  }
39235
+ /**
39236
+ * Keep the upstream error readable instead of slicing it to 160 characters.
39237
+ * A `TOS_VIOLATION` 403 is a terminal ban: the 5-minute scheduler must stop
39238
+ * hammering that account, and the appeal URL must reach the UI (issue #112).
39239
+ */
39240
+ function describeWarmupError(status, body) {
39241
+ const detail = body.trim().slice(0, 2e3);
39242
+ const appealUrl = /"appeal_url"\s*:\s*"([^"]+)"/.exec(body)?.[1];
39243
+ const terminal = /TOS_VIOLATION/i.test(body);
39244
+ return {
39245
+ error: `HTTP ${status}: ${detail}${appealUrl ? ` Appeal: ${appealUrl}` : ""}`,
39246
+ terminal,
39247
+ ...appealUrl ? { appealUrl } : {}
39248
+ };
39249
+ }
39203
39250
  //#endregion
39204
39251
  //#region src/features/warmup/history.ts
39205
39252
  var WarmupHistoryStore = class {
@@ -39259,14 +39306,16 @@ var WarmupService = class {
39259
39306
  agyVersion;
39260
39307
  config;
39261
39308
  log;
39309
+ fetchImpl;
39262
39310
  history;
39263
- constructor(pool, quota, globalProxy = () => "", agyVersion = () => null, config = () => ({}), log = () => void 0, historyStore) {
39311
+ constructor(pool, quota, globalProxy = () => "", agyVersion = () => null, config = () => ({}), log = () => void 0, historyStore, fetchImpl = agyFetch) {
39264
39312
  this.pool = pool;
39265
39313
  this.quota = quota;
39266
39314
  this.globalProxy = globalProxy;
39267
39315
  this.agyVersion = agyVersion;
39268
39316
  this.config = config;
39269
39317
  this.log = log;
39318
+ this.fetchImpl = fetchImpl;
39270
39319
  this.history = historyStore ?? new WarmupHistoryStore();
39271
39320
  }
39272
39321
  proxyFor(account) {
@@ -39352,7 +39401,8 @@ var WarmupService = class {
39352
39401
  let lastStatus = 0;
39353
39402
  let lastError = "";
39354
39403
  for (const attempt of attempts) for (const ep of endpoints) try {
39355
- const res = await agyFetch(`${ep}/v1internal:${attempt.method}${attempt.query}`, {
39404
+ const targetUrl = `${ep}/v1internal:${attempt.method}${attempt.query}`;
39405
+ const res = await this.fetchImpl(targetUrl, {
39356
39406
  method: "POST",
39357
39407
  headers,
39358
39408
  body: reqBody
@@ -39379,13 +39429,20 @@ var WarmupService = class {
39379
39429
  error: "Account requires browser validation (VALIDATION_REQUIRED)",
39380
39430
  durationMs: Date.now() - start
39381
39431
  };
39382
- lastError = `HTTP ${res.status}: ${errBody.slice(0, 160)}`;
39383
- if (res.status === 401 || res.status === 403) return {
39384
- ok: false,
39385
- status: res.status,
39386
- error: lastError,
39387
- durationMs: Date.now() - start
39388
- };
39432
+ const described = describeWarmupError(res.status, errBody);
39433
+ lastError = described.error;
39434
+ if (res.status === 401 || res.status === 403) {
39435
+ if (described.terminal) {
39436
+ this.pool.markAuthRequired(account.id, described.error);
39437
+ this.log(`[agy-link] warmup: ${account.alias || account.id} is terminal: ${described.error}`);
39438
+ }
39439
+ return {
39440
+ ok: false,
39441
+ status: res.status,
39442
+ error: described.error,
39443
+ durationMs: Date.now() - start
39444
+ };
39445
+ }
39389
39446
  } catch (err) {
39390
39447
  lastError = String(err);
39391
39448
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agy-link",
3
- "version": "0.6.25",
3
+ "version": "0.6.27",
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",