agy-bar 1.1.0 → 1.1.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  All notable changes to **agy-bar** are documented here.
4
4
 
5
+ ## [1.1.1] - 2026-11-27
6
+
7
+ ### Fixed & Hardened (Windows)
8
+ - **Windows Credential Manager Size Limit, Persist & OpenSSH Fallback (`src/keyring.mjs`)**:
9
+ - Compacted Windows Credential Manager payloads (`compactWindowsCredentialPayload`) before `CredWriteW` (unwrapping `go-keyring-base64:`, deduplicating nested `token.id_token`, trimming optional oversized `id_token` for the CredMan blob copy while keeping the full payload in the mirror file / file vault, and falling back cleanly via `KEYRING_UNAVAILABLE` if a blob still exceeds Windows' 2,560-byte `CRED_MAX_CREDENTIAL_BLOB_SIZE` limit).
10
+ - Aligned Windows credential persistence with `CRED_PERSIST_ENTERPRISE = 3` (matching `agy` / `go-keyring`), explicitly forced UTF-8 stdin/stdout encoding in PowerShell 5.1 (preventing GBK/CP936 mojibake on non-UTF-8 Windows locales), and handled Win32 error `1312` (`ERROR_NO_SUCH_LOGON_SESSION`, e.g. Windows OpenSSH) by gracefully falling back to `0600` file storage.
11
+ - **Windows `.cmd`/`.bat` Shim Multi-Line Handoff Safety (`src/proxy.mjs`, `bin/agy-bar.mjs`)**:
12
+ - When launching `agy` through a `.cmd`/`.bat` shim (`shell: true`) on Windows, multi-line Markdown handoff prompts containing newlines or `cmd.exe` metacharacters (`&`, `|`, `>`, `<`, `%`, `"`) automatically switch to a single-line `cmd.exe`-safe pointer referencing the saved `~/.gemini/config/agy-bar/handoffs/latest.md` file, while native `agy.exe` (`shell: false`) keeps passing the full prompt directly.
13
+
5
14
  ## [1.1.0] - 2026-11-27
6
15
 
7
16
  ### Added
package/bin/agy-bar.mjs CHANGED
@@ -1270,6 +1270,7 @@ async function runManagedAgy(rawArgs) {
1270
1270
  return {
1271
1271
  resume: true,
1272
1272
  prompt: handoff.prompt,
1273
+ savedPath: handoff.savedPath,
1273
1274
  fromAlias: sw.fromAlias,
1274
1275
  toAlias: sw.toAlias,
1275
1276
  family: effectiveFamily,
@@ -1305,6 +1306,7 @@ async function runPostSwitchHandoff({ fromAlias, targetAlias, printOnly = false
1305
1306
  const res = await launchAgyWithProxy(['-i', handoff.prompt], {
1306
1307
  proxyConfig: cfg.proxy,
1307
1308
  syncAccount: syncActiveAccountBeforeLaunch,
1309
+ handoffSavedPath: handoff.savedPath,
1308
1310
  });
1309
1311
  if (res.exitCode) process.exitCode = res.exitCode;
1310
1312
  }
@@ -1372,6 +1374,7 @@ async function handleHandoffCommand(args) {
1372
1374
  const res = await launchAgyWithProxy(['-i', handoff.prompt], {
1373
1375
  proxyConfig: cfg.proxy,
1374
1376
  syncAccount: syncActiveAccountBeforeLaunch,
1377
+ handoffSavedPath: handoff.savedPath,
1375
1378
  });
1376
1379
  if (res.exitCode) process.exitCode = res.exitCode;
1377
1380
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agy-bar",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Zero-dependency terminal statusline, browser-free multi-account vault & lossless handoff, no-TUN proxy launcher, exact TTFT & tok/s speed, 5-min cache TTL countdown, live pricing cache, automatic tab titles, 52-week token heatmap, and multi-CLI monitor for Antigravity CLI (agy).",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/keyring.mjs CHANGED
@@ -8,6 +8,7 @@ export const AGY_KEYRING_SERVICE = 'gemini';
8
8
  export const AGY_KEYRING_ACCOUNT = 'antigravity';
9
9
  export const VAULT_KEYRING_SERVICE = 'agy-bar-account';
10
10
  export const AGY_FALLBACK_TOKEN_FILENAME = 'jetski-standalone-oauth-token';
11
+ export const WINDOWS_CRED_BLOB_LIMIT = 2560;
11
12
 
12
13
  const SAFE_IDENT_RE = /^[a-zA-Z0-9._:@/-]{1,128}$/;
13
14
 
@@ -62,9 +63,69 @@ export function buildMacAddGenericPasswordLine({ service, account, secret, updat
62
63
  return `${parts.join(' ')}\n`;
63
64
  }
64
65
 
66
+ export function compactWindowsCredentialPayload(rawSecret, { maxBytes = WINDOWS_CRED_BLOB_LIMIT } = {}) {
67
+ let str = String(rawSecret ?? '').trim();
68
+ const prefix = 'go-keyring-base64:';
69
+ if (str.startsWith(prefix)) {
70
+ try {
71
+ str = Buffer.from(str.slice(prefix.length), 'base64').toString('utf8').trim();
72
+ } catch {
73
+ // Keep original string if malformed base64.
74
+ }
75
+ }
76
+
77
+ let parsed = null;
78
+ try {
79
+ const candidate = JSON.parse(str);
80
+ if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
81
+ parsed = candidate;
82
+ }
83
+ } catch {
84
+ parsed = null;
85
+ }
86
+
87
+ if (!parsed) {
88
+ const byteLength = Buffer.byteLength(str, 'utf8');
89
+ return { value: str, byteLength, fits: byteLength <= maxBytes, trimmedIdToken: false };
90
+ }
91
+
92
+ // Promote nested token.id_token and drop duplicate to stay well under Windows' 2560-byte CredWriteW limit.
93
+ const copy = { ...parsed };
94
+ if (copy.token && typeof copy.token === 'object' && !Array.isArray(copy.token)) {
95
+ const nested = { ...copy.token };
96
+ if (typeof nested.id_token === 'string' && nested.id_token.trim()) {
97
+ copy.id_token = nested.id_token.trim();
98
+ delete nested.id_token;
99
+ }
100
+ copy.token = nested;
101
+ }
102
+
103
+ let compact = JSON.stringify(copy);
104
+ let byteLength = Buffer.byteLength(compact, 'utf8');
105
+ if (byteLength <= maxBytes) {
106
+ return { value: compact, byteLength, fits: true, trimmedIdToken: false };
107
+ }
108
+
109
+ // If a huge enterprise JWT id_token still pushes the blob over 2560 bytes, drop optional id_token
110
+ // for the Windows Credential Manager copy (mirror file & file vault retain the full payload).
111
+ if (typeof copy.id_token === 'string' && copy.id_token.length > 0) {
112
+ const withoutId = { ...copy };
113
+ delete withoutId.id_token;
114
+ const trimmed = JSON.stringify(withoutId);
115
+ const trimmedBytes = Buffer.byteLength(trimmed, 'utf8');
116
+ if (trimmedBytes <= maxBytes) {
117
+ return { value: trimmed, byteLength: trimmedBytes, fits: true, trimmedIdToken: true };
118
+ }
119
+ }
120
+
121
+ return { value: compact, byteLength, fits: false, trimmedIdToken: false };
122
+ }
123
+
65
124
  export function buildWindowsCredScript() {
66
125
  return [
67
126
  '$ErrorActionPreference = "Stop"',
127
+ '[Console]::InputEncoding = [System.Text.Encoding]::UTF8',
128
+ '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8',
68
129
  '$rawIn = [Console]::In.ReadToEnd()',
69
130
  'if (-not $rawIn) { throw "Missing stdin JSON payload" }',
70
131
  '$req = $rawIn | ConvertFrom-Json',
@@ -74,7 +135,7 @@ export function buildWindowsCredScript() {
74
135
  'using System.Runtime.InteropServices.ComTypes;',
75
136
  'public static class AgyBarWinCred {',
76
137
  ' public const uint CRED_TYPE_GENERIC = 1;',
77
- ' public const uint CRED_PERSIST_LOCAL_MACHINE = 2;',
138
+ ' public const uint CRED_PERSIST_ENTERPRISE = 3;',
78
139
  ' [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]',
79
140
  ' public struct CREDENTIAL {',
80
141
  ' public uint Flags;',
@@ -125,7 +186,7 @@ export function buildWindowsCredScript() {
125
186
  ' UserName = userName,',
126
187
  ' CredentialBlobSize = (uint)blob.Length,',
127
188
  ' CredentialBlob = ptr,',
128
- ' Persist = CRED_PERSIST_LOCAL_MACHINE',
189
+ ' Persist = CRED_PERSIST_ENTERPRISE',
129
190
  ' };',
130
191
  ' if (!CredWrite(ref cred, 0)) return Marshal.GetLastWin32Error();',
131
192
  ' return 0;',
@@ -160,7 +221,7 @@ export function buildWindowsCredScript() {
160
221
  ' @{ ok = $true } | ConvertTo-Json -Compress',
161
222
  '} elseif ($op -eq "delete") {',
162
223
  ' $err = [AgyBarWinCred]::DeleteTarget($target)',
163
- ' if ($err -eq 1168) { @{ ok = $true; deleted = $false } | ConvertTo-Json -Compress; exit 0 }',
224
+ ' if ($err -eq 1168 -or $err -eq 1312) { @{ ok = $true; deleted = $false } | ConvertTo-Json -Compress; exit 0 }',
164
225
  ' if ($err -ne 0) { @{ ok = $false; code = $err } | ConvertTo-Json -Compress; exit 1 }',
165
226
  ' @{ ok = $true; deleted = $true } | ConvertTo-Json -Compress',
166
227
  '} else {',
@@ -409,6 +470,14 @@ function createWindowsKeyring({ execFn = defaultExec, env = process.env } = {})
409
470
  cachedAvailable = true;
410
471
  return parsed;
411
472
  }
473
+ const winCode = Number(parsed?.code || 0);
474
+ if (winCode === 1312) {
475
+ // ERROR_NO_SUCH_LOGON_SESSION (e.g. headless Windows OpenSSH without interactive logon session).
476
+ cachedAvailable = false;
477
+ const err = new Error('Windows Credential Manager unavailable in this logon session (Win32 error 1312)');
478
+ err.code = 'KEYRING_UNAVAILABLE';
479
+ throw err;
480
+ }
412
481
  const detail = parsed?.code
413
482
  ? `Win32 error ${parsed.code}`
414
483
  : parsed?.error || res.stderr.trim() || `exit ${res.status}`;
@@ -444,11 +513,19 @@ function createWindowsKeyring({ execFn = defaultExec, env = process.env } = {})
444
513
  },
445
514
  set(service, account, secret) {
446
515
  const a = assertSafeCredentialIdentifier(account, 'account');
516
+ const compacted = compactWindowsCredentialPayload(secret);
517
+ if (!compacted.fits) {
518
+ const err = new Error(
519
+ `Credential exceeds Windows Credential Manager ${WINDOWS_CRED_BLOB_LIMIT}-byte limit (${compacted.byteLength} bytes)`,
520
+ );
521
+ err.code = 'KEYRING_UNAVAILABLE';
522
+ throw err;
523
+ }
447
524
  invoke({
448
525
  op: 'set',
449
526
  target: targetOf(service, account),
450
527
  user: a,
451
- secretB64: Buffer.from(String(secret ?? ''), 'utf8').toString('base64'),
528
+ secretB64: Buffer.from(compacted.value, 'utf8').toString('base64'),
452
529
  });
453
530
  },
454
531
  delete(service, account) {
package/src/proxy.mjs CHANGED
@@ -739,7 +739,24 @@ export function parseRunArgs(args = []) {
739
739
  return { options, agyArgs };
740
740
  }
741
741
 
742
- export function buildHandoffResumeArgs(originalAgyArgs = [], promptText) {
742
+ export function formatPromptArgForTarget(
743
+ promptText,
744
+ { target = null, savedHandoffPath = null, platform = process.platform } = {},
745
+ ) {
746
+ const raw = String(promptText ?? '');
747
+ if (platform === 'win32' && target?.shell === true && /[\r\n&|<>^%"]/.test(raw)) {
748
+ // Windows cmd.exe (.cmd/.bat shims) breaks on newlines and shell metacharacters.
749
+ // Point the incoming session at the already-written handoff Markdown file instead.
750
+ if (savedHandoffPath) {
751
+ const safePath = String(savedHandoffPath).replace(/\\/g, '/').replace(/["&|<>^%\r\n]/g, '');
752
+ return `Continue the ongoing task using the workspace handoff saved at ${safePath}. Read that file first, briefly confirm what is done vs remaining, and resume immediately.`;
753
+ }
754
+ return raw.replace(/[\r\n]+/g, ' ').replace(/[&|<>^%"]/g, ' ').replace(/\s+/g, ' ').trim();
755
+ }
756
+ return raw;
757
+ }
758
+
759
+ export function buildHandoffResumeArgs(originalAgyArgs = [], promptText, targetOpts = {}) {
743
760
  const preserved = [];
744
761
  const skipValueFlags = new Set(['-r', '--resume', '--conversation', '-i', '--prompt-interactive', '-p', '--print', '--prompt']);
745
762
  const skipBoolFlags = new Set(['-c', '--continue']);
@@ -753,7 +770,7 @@ export function buildHandoffResumeArgs(originalAgyArgs = [], promptText) {
753
770
  if ([...skipValueFlags].some((f) => arg.startsWith(`${f}=`))) continue;
754
771
  preserved.push(arg);
755
772
  }
756
- preserved.push('-i', promptText);
773
+ preserved.push('-i', formatPromptArgForTarget(promptText, targetOpts));
757
774
  return preserved;
758
775
  }
759
776
 
@@ -770,6 +787,7 @@ export async function launchAgyWithProxy(
770
787
  syncAccount = null,
771
788
  autoSwitchAccount = null,
772
789
  autoHandoffHook = null,
790
+ handoffSavedPath = null,
773
791
  minAutoHandoffRunMs = 3000,
774
792
  maxAutoHandoffHops = 5,
775
793
  } = {},
@@ -860,6 +878,17 @@ export async function launchAgyWithProxy(
860
878
  const target = resolveSpawnTarget(executable, { platform, env });
861
879
  const isPrintMode = agyArgs.some((a) => a === '-p' || a === '--print' || a === '--prompt' || a.startsWith('--print=') || a.startsWith('--prompt='));
862
880
 
881
+ const sanitizeArgsForWinShell = (argsList, savedPath) => {
882
+ if (platform !== 'win32' || target.shell !== true) return argsList;
883
+ const out = [...argsList];
884
+ for (let idx = 0; idx < out.length - 1; idx++) {
885
+ if (out[idx] === '-i' || out[idx] === '--prompt-interactive') {
886
+ out[idx + 1] = formatPromptArgForTarget(out[idx + 1], { target, savedHandoffPath: savedPath, platform });
887
+ }
888
+ }
889
+ return out;
890
+ };
891
+
863
892
  const spawnOnce = (currentArgs) =>
864
893
  new Promise((resolveChild, rejectChild) => {
865
894
  const child = spawnFn(target.command, currentArgs, {
@@ -917,7 +946,7 @@ export async function launchAgyWithProxy(
917
946
  });
918
947
  });
919
948
 
920
- let currentArgs = agyArgs;
949
+ let currentArgs = sanitizeArgsForWinShell(agyArgs, handoffSavedPath);
921
950
  let hops = 0;
922
951
 
923
952
  while (true) {
@@ -955,7 +984,11 @@ export async function launchAgyWithProxy(
955
984
  `agy-bar: "${nextHop.fromAlias}" hit ${nextHop.family || 'quota'} limit — switched -> "${nextHop.toAlias}" and resuming with handoff (${hops}/${maxAutoHandoffHops})...\n`,
956
985
  );
957
986
  }
958
- currentArgs = buildHandoffResumeArgs(agyArgs, nextHop.prompt);
987
+ currentArgs = buildHandoffResumeArgs(agyArgs, nextHop.prompt, {
988
+ target,
989
+ savedHandoffPath: nextHop.savedPath || handoffSavedPath,
990
+ platform,
991
+ });
959
992
  continue;
960
993
  }
961
994
  }