@cortexkit/opencode-antigravity-auth 3.0.36 → 3.0.38

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 (83) hide show
  1. package/dist/cli.js +12 -2
  2. package/dist/cli.js.map +2 -2
  3. package/dist/cli.meta.json +17 -17
  4. package/dist/index.js +20 -9
  5. package/dist/index.js.map +2 -2
  6. package/dist/index.meta.json +36 -20
  7. package/dist/server.js +243 -104
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/auth-method-labels.d.ts +2 -0
  11. package/dist/src/auth-method-labels.d.ts.map +1 -1
  12. package/dist/src/auth-method-labels.js +2 -0
  13. package/dist/src/auth-method-labels.js.map +1 -1
  14. package/dist/src/common-auth-embedded/claustrum/availability.d.ts +1 -0
  15. package/dist/src/common-auth-embedded/claustrum/availability.js +2 -0
  16. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  17. package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
  18. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +51 -0
  19. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +186 -0
  20. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +2 -1
  21. package/dist/src/common-auth-embedded/routing-accessor/index.js +1 -0
  22. package/dist/src/common-auth-embedded/source-output.json +41 -25
  23. package/dist/src/ga/server/auth.js +2 -2
  24. package/dist/src/ga/server/auth.js.map +1 -1
  25. package/dist/src/ga/server/index.js +1 -1
  26. package/dist/src/ga/server/index.js.map +1 -1
  27. package/dist/src/ga/server/pool-login.d.ts +9 -0
  28. package/dist/src/ga/server/pool-login.d.ts.map +1 -1
  29. package/dist/src/ga/server/pool-login.js +155 -73
  30. package/dist/src/ga/server/pool-login.js.map +1 -1
  31. package/dist/src/ga/tui/host-ga.d.ts +7 -0
  32. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  33. package/dist/src/ga/tui/host-ga.js +70 -1
  34. package/dist/src/ga/tui/host-ga.js.map +1 -1
  35. package/dist/src/logging/provider-key-policy.d.ts +2 -0
  36. package/dist/src/logging/provider-key-policy.d.ts.map +1 -1
  37. package/dist/src/logging/provider-key-policy.js +5 -1
  38. package/dist/src/logging/provider-key-policy.js.map +1 -1
  39. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  40. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  41. package/dist/src/plugin/ga-location-services.js +77 -12
  42. package/dist/src/plugin/ga-location-services.js.map +1 -1
  43. package/dist/src/plugin/logger.d.ts.map +1 -1
  44. package/dist/src/plugin/logger.js +2 -1
  45. package/dist/src/plugin/logger.js.map +1 -1
  46. package/dist/src/plugin/vault-custody.js +6 -6
  47. package/dist/src/plugin/vault-custody.js.map +1 -1
  48. package/dist/src/setup.js +1 -1
  49. package/dist/src/setup.js.map +1 -1
  50. package/dist/src/tui/file-logger.d.ts.map +1 -1
  51. package/dist/src/tui/file-logger.js +2 -1
  52. package/dist/src/tui/file-logger.js.map +1 -1
  53. package/dist/tui-build-map.json +9 -9
  54. package/dist/tui-ga-build-map.json +5 -5
  55. package/dist/types/src/auth-method-labels.d.ts +2 -0
  56. package/dist/types/src/auth-method-labels.d.ts.map +1 -1
  57. package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +1 -0
  58. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  59. package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +51 -0
  60. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +2 -1
  61. package/dist/types/src/ga/server/pool-login.d.ts +9 -0
  62. package/dist/types/src/ga/server/pool-login.d.ts.map +1 -1
  63. package/dist/types/src/logging/provider-key-policy.d.ts +2 -0
  64. package/dist/types/src/logging/provider-key-policy.d.ts.map +1 -1
  65. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  66. package/dist/types/src/plugin/logger.d.ts.map +1 -1
  67. package/package.json +4 -4
  68. package/src/common-auth-embedded/claustrum/availability.d.ts +1 -0
  69. package/src/common-auth-embedded/claustrum/availability.js +2 -0
  70. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  71. package/src/common-auth-embedded/claustrum/index.js +1 -1
  72. package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +51 -0
  73. package/src/common-auth-embedded/routing-accessor/cache-policy.js +186 -0
  74. package/src/common-auth-embedded/routing-accessor/index.d.ts +2 -1
  75. package/src/common-auth-embedded/routing-accessor/index.js +1 -0
  76. package/src/common-auth-embedded/source-output.json +41 -25
  77. package/src/tui/file-logger.ts +5 -1
  78. package/src/tui-compiled/logging/provider-key-policy.js +4 -1
  79. package/src/tui-compiled/tui/file-logger.js +5 -1
  80. package/src/tui-ga-compiled/host-ga.js +66 -1
  81. package/src/tui-ga-raw/host-ga.tsx +79 -1
  82. package/src/tui-raw/logging/provider-key-policy.js +4 -1
  83. package/src/tui-raw/tui/file-logger.js +5 -1
@@ -0,0 +1,186 @@
1
+ import { routingHandle } from './handle.js';
2
+ const warned = new Set();
3
+ // Inspect descriptors rather than values so warning deduplication cannot invoke
4
+ // a broken bridge's getters a second time. Do not print policy contents.
5
+ function shape(value, seen = new Set()) {
6
+ if (typeof value !== 'object' || value === null) {
7
+ return `${typeof value}:${String(value)}`;
8
+ }
9
+ if (seen.has(value))
10
+ return 'cycle';
11
+ seen.add(value);
12
+ return `${Array.isArray(value) ? 'array' : 'object'}:{${Object.entries(Object.getOwnPropertyDescriptors(value))
13
+ .sort(([a], [b]) => a.localeCompare(b))
14
+ .map(([key, descriptor]) => `${key}:${'value' in descriptor ? shape(descriptor.value, seen) : 'accessor'}`)
15
+ .join(',')}}`;
16
+ }
17
+ function invalid(kind, value) {
18
+ let fingerprint = 'unreadable';
19
+ try {
20
+ fingerprint = shape(value);
21
+ }
22
+ catch {
23
+ // Uninspectable proxies share one diagnostic shape, without invoking getters.
24
+ }
25
+ try {
26
+ const key = `${kind}:${fingerprint}`;
27
+ if (!warned.has(key)) {
28
+ warned.add(key);
29
+ console.warn(`[common-auth] Ignoring invalid session ${kind} policy`);
30
+ }
31
+ }
32
+ catch {
33
+ // A broken warning sink must not break a request either.
34
+ }
35
+ return null;
36
+ }
37
+ function record(value) {
38
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
39
+ }
40
+ function rejectAsync(value) {
41
+ if (typeof value.then !== 'function')
42
+ return false;
43
+ // Absorb a rejected promise from a bridge that broke the synchronous contract.
44
+ void Promise.resolve(value).catch(() => { });
45
+ return true;
46
+ }
47
+ function onlyKeys(value, keys) {
48
+ return Reflect.ownKeys(value).every((key) => typeof key === 'string' && keys.includes(key));
49
+ }
50
+ /**
51
+ * Read the session's current plan on every decision; never retain it across
52
+ * requests. Null means the plugin keeps its own settings. No I/O or exceptions.
53
+ */
54
+ export function sessionCachePolicy(sessionId) {
55
+ let answer;
56
+ try {
57
+ const handle = routingHandle(sessionId);
58
+ if (!handle)
59
+ return null;
60
+ const read = handle.cache;
61
+ if (typeof read !== 'function')
62
+ return null;
63
+ answer = read.call(handle);
64
+ if (answer === null)
65
+ return null;
66
+ if (!record(answer) || rejectAsync(answer))
67
+ return invalid('cache', answer);
68
+ const { ttl, keep_warm, hours } = answer;
69
+ if (!onlyKeys(answer, ['ttl', 'keep_warm', 'hours']) ||
70
+ (ttl !== undefined &&
71
+ ttl !== 'none' &&
72
+ ttl !== 'short' &&
73
+ ttl !== 'long') ||
74
+ (keep_warm !== undefined &&
75
+ keep_warm !== 'off' &&
76
+ keep_warm !== 'hours' &&
77
+ keep_warm !== 'always' &&
78
+ keep_warm !== 'auto') ||
79
+ (ttl === 'none' && keep_warm !== undefined && keep_warm !== 'off') ||
80
+ (keep_warm !== 'hours' && 'hours' in answer)) {
81
+ return invalid('cache', answer);
82
+ }
83
+ const policy = {
84
+ ...(ttl !== undefined ? { ttl } : {}),
85
+ ...(keep_warm !== undefined ? { keep_warm } : {}),
86
+ };
87
+ if (keep_warm === 'hours') {
88
+ if (!record(hours) || !onlyKeys(hours, ['from', 'to', 'tz'])) {
89
+ return invalid('cache', answer);
90
+ }
91
+ const { from, to, tz } = hours;
92
+ const time = /^(?:[01]\d|2[0-3]):[0-5]\d$/;
93
+ if (typeof from !== 'string' ||
94
+ !time.test(from) ||
95
+ typeof to !== 'string' ||
96
+ !time.test(to) ||
97
+ from === to ||
98
+ typeof tz !== 'string' ||
99
+ tz.length === 0) {
100
+ return invalid('cache', answer);
101
+ }
102
+ new Intl.DateTimeFormat('en', { timeZone: tz });
103
+ policy.hours = { from, to, tz };
104
+ }
105
+ return policy;
106
+ }
107
+ catch {
108
+ return invalid('cache', answer);
109
+ }
110
+ }
111
+ /** Read the oldest running plan tool afresh, without I/O or exceptions. */
112
+ export function sessionToolWait(sessionId) {
113
+ let answer;
114
+ try {
115
+ const handle = routingHandle(sessionId);
116
+ if (!handle)
117
+ return null;
118
+ const read = handle.tool_wait;
119
+ if (typeof read !== 'function')
120
+ return null;
121
+ answer = read.call(handle);
122
+ if (answer === null)
123
+ return null;
124
+ if (!record(answer) || rejectAsync(answer))
125
+ return invalid('tool_wait', answer);
126
+ const { since } = answer;
127
+ if (!onlyKeys(answer, ['since']) ||
128
+ typeof since !== 'number' ||
129
+ !Number.isSafeInteger(since) ||
130
+ since < 0) {
131
+ return invalid('tool_wait', answer);
132
+ }
133
+ return { since };
134
+ }
135
+ catch {
136
+ return invalid('tool_wait', answer);
137
+ }
138
+ }
139
+ function report(sessionId, payload) {
140
+ const handle = routingHandle(sessionId);
141
+ if (!handle)
142
+ return;
143
+ const send = handle.report;
144
+ if (typeof send !== 'function')
145
+ return;
146
+ const pending = send.call(handle, payload);
147
+ if (record(pending) && typeof pending.then === 'function') {
148
+ void Promise.resolve(pending).catch(() => { });
149
+ }
150
+ }
151
+ /**
152
+ * Call only after the reply has been handed to the host, never on the awaited
153
+ * request path. Synchronous fire-and-forget, with no retries; the bridge owns
154
+ * redelivery of the newest touch. Accessor and report failures are absorbed.
155
+ */
156
+ export function reportCacheTouch(sessionId, input) {
157
+ try {
158
+ const { at, ttlMs, source } = input;
159
+ if (!Number.isSafeInteger(at) ||
160
+ at < 0 ||
161
+ (ttlMs !== 'implicit' &&
162
+ (typeof ttlMs !== 'number' || !Number.isFinite(ttlMs) || ttlMs < 0)) ||
163
+ (source !== 'response' && source !== 'warm'))
164
+ return;
165
+ report(sessionId, { kind: 'cache_touch', at, ttl_ms: ttlMs, source });
166
+ }
167
+ catch {
168
+ // Optional reporting must never change the result of an auth request.
169
+ }
170
+ }
171
+ /**
172
+ * Call off the request path, after handing the reply to the host. Report only
173
+ * a session that actually warmed, never one that was off from the start.
174
+ * Synchronous fire-and-forget; failures are absorbed and never retried here.
175
+ */
176
+ export function reportCacheWarmStopped(sessionId, input) {
177
+ try {
178
+ const { at, reason } = input;
179
+ if (!Number.isSafeInteger(at) || at < 0 || typeof reason !== 'string')
180
+ return;
181
+ report(sessionId, { kind: 'cache_warm_stopped', at, reason });
182
+ }
183
+ catch {
184
+ // Optional reporting must never change the result of an auth request.
185
+ }
186
+ }
@@ -3,6 +3,8 @@
3
3
  * shaping. Account ids are vault account ids, not local pool rows. Nothing is
4
4
  * persisted here; plugins on routes the runner does not serve get no turn notes.
5
5
  */
6
+ export type { CacheTouchInput, CacheWarmStoppedInput, CacheWarmStopReason, SessionCacheHours, SessionCachePolicy, SessionCacheTtl, SessionKeepWarmMode, SessionToolWait, } from './cache-policy.js';
7
+ export { reportCacheTouch, reportCacheWarmStopped, sessionCachePolicy, sessionToolWait, } from './cache-policy.js';
6
8
  /** An eligible vault route, not a local pool row. */
7
9
  export interface RoutingCandidate {
8
10
  /** Vault account id, not the plugin's route id. */
@@ -94,4 +96,3 @@ export declare function askRouting<Candidate extends RoutingCandidate>(input: As
94
96
  * or redacted here.
95
97
  */
96
98
  export declare function reportRouting(input: ReportRoutingInput): void;
97
- export {};
@@ -4,6 +4,7 @@
4
4
  * persisted here; plugins on routes the runner does not serve get no turn notes.
5
5
  */
6
6
  import { routingHandle } from './handle.js';
7
+ export { reportCacheTouch, reportCacheWarmStopped, sessionCachePolicy, sessionToolWait, } from './cache-policy.js';
7
8
  function isObject(value) {
8
9
  return typeof value === 'object' && value !== null;
9
10
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "package": "@cortexkit/common-auth",
4
- "version": "0.40.0",
4
+ "version": "0.42.0",
5
5
  "artifactStatus": "published",
6
6
  "publicRoots": {
7
7
  "./rpc": {
@@ -69,15 +69,15 @@
69
69
  "import": "./src/quota-sidebar/index.tsx"
70
70
  }
71
71
  },
72
- "input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.40.0.tgz",
73
- "tarballSha256": "c1346992a2f15355b9304e729ff2ff47de9bf07d578563b9f0c6f83b969253b4",
74
- "sri": "sha512-P0rfQ+fRXTBhAAG0rWkcP2CXkDb32Zplo37qpQx6TINHi78yzp8kNEnHSSwSeEReH5imh7hptg9L69AYCg4Jdw==",
75
- "canonicalFiles": 218,
76
- "canonicalBytes": 1365319,
72
+ "input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.42.0.tgz",
73
+ "tarballSha256": "c3f1c832fe8391529be331c1e2f5577b60eaa7a1c848e97f6668aca06118af04",
74
+ "sri": "sha512-LAZ67qRdJA+9SmglIyDRtEd2Wz+6X2dDRTC+qXt6HryQzir87LIiY+sWWllWT707agUA9rxOocCCP6e+mwoZyA==",
75
+ "canonicalFiles": 220,
76
+ "canonicalBytes": 1374785,
77
77
  "generator": {
78
78
  "path": "packages/opencode/scripts/embed-common-auth.ts",
79
79
  "version": 4,
80
- "sha256": "3d9e00d8b43c67a911c6b14648432aad4d43c85d210c9dc5a3e9524cf67aff3c"
80
+ "sha256": "225a77c54d91e241bbece24dc289ce479330d00c20304ff8508ceb59975728c4"
81
81
  },
82
82
  "files": [
83
83
  {
@@ -243,17 +243,17 @@
243
243
  {
244
244
  "source": "package/dist/claustrum/availability.d.ts",
245
245
  "output": "claustrum/availability.d.ts",
246
- "bytes": 3375,
247
- "sourceSha256": "eba8ff78abed434be6194715d214a53322f4414a28e6a7389fe14f8a52b772ac",
248
- "outputSha256": "eba8ff78abed434be6194715d214a53322f4414a28e6a7389fe14f8a52b772ac",
246
+ "bytes": 3406,
247
+ "sourceSha256": "a77a53ae0220230273b124b7793e2d8842ab3841bfab1d987309411752f7b80a",
248
+ "outputSha256": "a77a53ae0220230273b124b7793e2d8842ab3841bfab1d987309411752f7b80a",
249
249
  "transform": "verbatim"
250
250
  },
251
251
  {
252
252
  "source": "package/dist/claustrum/availability.js",
253
253
  "output": "claustrum/availability.js",
254
- "bytes": 4107,
255
- "sourceSha256": "4bfb03de131ed7d036631a6d6455cc6f465ab7a9ea61575a7378d2f447c7cf67",
256
- "outputSha256": "4bfb03de131ed7d036631a6d6455cc6f465ab7a9ea61575a7378d2f447c7cf67",
254
+ "bytes": 4219,
255
+ "sourceSha256": "07fe16b372bb3dbf5870725b4ea8e2b4c3e50e5d7394fa365de789f72ff01b04",
256
+ "outputSha256": "07fe16b372bb3dbf5870725b4ea8e2b4c3e50e5d7394fa365de789f72ff01b04",
257
257
  "transform": "verbatim"
258
258
  },
259
259
  {
@@ -371,17 +371,17 @@
371
371
  {
372
372
  "source": "package/dist/claustrum/index.d.ts",
373
373
  "output": "claustrum/index.d.ts",
374
- "bytes": 4923,
375
- "sourceSha256": "17fe239561e9a3c8769cef79b08ca279b6d359ab9946fe03e40f1f285edadf03",
376
- "outputSha256": "17fe239561e9a3c8769cef79b08ca279b6d359ab9946fe03e40f1f285edadf03",
374
+ "bytes": 4937,
375
+ "sourceSha256": "9270d05fd212b2e4b38afe6fc1021b0763ced055921de03943fec1992c871aa3",
376
+ "outputSha256": "9270d05fd212b2e4b38afe6fc1021b0763ced055921de03943fec1992c871aa3",
377
377
  "transform": "verbatim"
378
378
  },
379
379
  {
380
380
  "source": "package/dist/claustrum/index.js",
381
381
  "output": "claustrum/index.js",
382
- "bytes": 4048,
383
- "sourceSha256": "9f50749354dbcf643a3cddc9ff994824c603fac288f50015703ca6e1f730ca08",
384
- "outputSha256": "9f50749354dbcf643a3cddc9ff994824c603fac288f50015703ca6e1f730ca08",
382
+ "bytes": 4062,
383
+ "sourceSha256": "72f0f4bd7c17b82aa7abc3f196e1499d5a3d51173a456fbd7c3b72425ffaba48",
384
+ "outputSha256": "72f0f4bd7c17b82aa7abc3f196e1499d5a3d51173a456fbd7c3b72425ffaba48",
385
385
  "transform": "verbatim"
386
386
  },
387
387
  {
@@ -1800,6 +1800,22 @@
1800
1800
  "outputSha256": "f35e4fd7b218110756bd04357c5b8c4bbb64be5012aefc7d7a7c1ab303d483ae",
1801
1801
  "transform": "verbatim"
1802
1802
  },
1803
+ {
1804
+ "source": "package/dist/routing-accessor/cache-policy.d.ts",
1805
+ "output": "routing-accessor/cache-policy.d.ts",
1806
+ "bytes": 2177,
1807
+ "sourceSha256": "d9a938b7f5c688e398a8d67a74c5ad9d3fd1e2c72648f3bcae02acf9f8894ac2",
1808
+ "outputSha256": "d9a938b7f5c688e398a8d67a74c5ad9d3fd1e2c72648f3bcae02acf9f8894ac2",
1809
+ "transform": "verbatim"
1810
+ },
1811
+ {
1812
+ "source": "package/dist/routing-accessor/cache-policy.js",
1813
+ "output": "routing-accessor/cache-policy.js",
1814
+ "bytes": 6700,
1815
+ "sourceSha256": "3342f84975f498d36a44860b60263bb0e3a2d826faa9aff6fb24a58944d7b71b",
1816
+ "outputSha256": "3342f84975f498d36a44860b60263bb0e3a2d826faa9aff6fb24a58944d7b71b",
1817
+ "transform": "verbatim"
1818
+ },
1803
1819
  {
1804
1820
  "source": "package/dist/routing-accessor/handle.js",
1805
1821
  "output": "routing-accessor/handle.js",
@@ -1811,17 +1827,17 @@
1811
1827
  {
1812
1828
  "source": "package/dist/routing-accessor/index.d.ts",
1813
1829
  "output": "routing-accessor/index.d.ts",
1814
- "bytes": 3941,
1815
- "sourceSha256": "04f480934ab1cd05585abb816014ac37cca32ccf783e90a98dd101513edf7f04",
1816
- "outputSha256": "04f480934ab1cd05585abb816014ac37cca32ccf783e90a98dd101513edf7f04",
1830
+ "bytes": 4243,
1831
+ "sourceSha256": "f2dd26706a869322c9c31ccae1bc3612d5ce89e4f79b6c4fb999f6b50ae5f88e",
1832
+ "outputSha256": "f2dd26706a869322c9c31ccae1bc3612d5ce89e4f79b6c4fb999f6b50ae5f88e",
1817
1833
  "transform": "verbatim"
1818
1834
  },
1819
1835
  {
1820
1836
  "source": "package/dist/routing-accessor/index.js",
1821
1837
  "output": "routing-accessor/index.js",
1822
- "bytes": 8290,
1823
- "sourceSha256": "ea80ae669e1f65555e88e5c56383d6e1a5ee813de532ffade61011bb4eeea16d",
1824
- "outputSha256": "ea80ae669e1f65555e88e5c56383d6e1a5ee813de532ffade61011bb4eeea16d",
1838
+ "bytes": 8406,
1839
+ "sourceSha256": "83945bf1bcd2b6d7d5bfdd597b62211d5b00b8cdd75e29089c75478af7f6eafc",
1840
+ "outputSha256": "83945bf1bcd2b6d7d5bfdd597b62211d5b00b8cdd75e29089c75478af7f6eafc",
1825
1841
  "transform": "verbatim"
1826
1842
  }
1827
1843
  ],
@@ -24,7 +24,10 @@ import {
24
24
  import { homedir } from 'node:os'
25
25
  import { dirname, join } from 'node:path'
26
26
  import { createLoggerInstance } from '../common-auth-embedded/logger/index.js'
27
- import { isProviderSecretKey } from '../logging/provider-key-policy'
27
+ import {
28
+ isProviderSecretKey,
29
+ OAUTH_REDIRECT_VALUE_PATTERNS,
30
+ } from '../logging/provider-key-policy'
28
31
 
29
32
  export type TuiLogLevel = 'debug' | 'info' | 'warn' | 'error'
30
33
 
@@ -141,6 +144,7 @@ function createFileLogger(options: FileLoggerOptions): TuiLogger {
141
144
  const instance = createLoggerInstance({
142
145
  level: 'debug',
143
146
  extraSecretKeys: isProviderSecretKey,
147
+ extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
144
148
  captureSink: ({ level, message, data }) => {
145
149
  const extra =
146
150
  data !== null && typeof data === 'object' && !Array.isArray(data)
@@ -1,3 +1,6 @@
1
1
  export function isProviderSecretKey(normalizedKey) {
2
- return /token|refresh|access|project|fingerprint|deviceid|sessionid|sessiontoken|secret|password|apikey|clientsecret/.test(normalizedKey);
2
+ return /token|refresh|access|project|fingerprint|deviceid|sessionid|sessiontoken|secret|password|apikey|clientsecret|callback|redirecturl|authorizationcode/.test(normalizedKey);
3
3
  }
4
+ export const OAUTH_REDIRECT_VALUE_PATTERNS = [
5
+ /https?:\/\/[^\s<>"']*[?&](?:code|state)=[^\s<>"']*/gi
6
+ ];
@@ -10,7 +10,10 @@ import {
10
10
  import { homedir } from "node:os";
11
11
  import { dirname, join } from "node:path";
12
12
  import { createLoggerInstance } from "../common-auth-embedded/logger/index.js";
13
- import { isProviderSecretKey } from "../logging/provider-key-policy.js";
13
+ import {
14
+ isProviderSecretKey,
15
+ OAUTH_REDIRECT_VALUE_PATTERNS
16
+ } from "../logging/provider-key-policy.js";
14
17
  const LOG_PREFIX = "[opencode-antigravity-auth/tui]", DEFAULT_MAX_BYTES = 1e6, MAX_KEEP_LINES = 200, FILE_MODE = 384;
15
18
  export function resolveTuiLogPath() {
16
19
  const override = process.env.ANTIGRAVITY_AUTH_TUI_LOG_FILE;
@@ -58,6 +61,7 @@ function createFileLogger(options) {
58
61
  }, channel = createLoggerInstance({
59
62
  level: "debug",
60
63
  extraSecretKeys: isProviderSecretKey,
64
+ extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
61
65
  captureSink: ({ level, message, data }) => {
62
66
  const extra = data !== null && typeof data === "object" && !Array.isArray(data) ? Object.fromEntries(Object.entries(data)) : void 0;
63
67
  write(level === "trace" ? "debug" : level, message, extra);
@@ -805,6 +805,46 @@ export function presentGaMenu(snapshot, now, source) {
805
805
 
806
806
  // ── Dialogs ─────────────────────────────────────────────────────────────────
807
807
 
808
+ /** The drawer owns this prompt, so a browser callback can dismiss it. */
809
+ export async function runGaDrawerLogin(input) {
810
+ const started = await input.apply(input.request);
811
+ if (!started.ok) return started;
812
+ let promptOpen = true;
813
+ const completed = input.completed.then(ok => {
814
+ if (promptOpen) input.ui.clear();
815
+ return {
816
+ ...started,
817
+ ok,
818
+ text: ok ? 'Account added.' : 'The Antigravity pool login could not be completed.'
819
+ };
820
+ });
821
+ const answer = input.ui.prompt({
822
+ title: 'Add account',
823
+ description: started.text,
824
+ placeholder: "Paste the redirect URL from your browser's address bar"
825
+ }).then(value => ({
826
+ value
827
+ }));
828
+ const winner = await Promise.race([completed, answer]);
829
+ promptOpen = false;
830
+ if (!('value' in winner)) return winner;
831
+ if (winner.value === undefined) {
832
+ return input.apply({
833
+ ...input.request,
834
+ values: {
835
+ cancel: true
836
+ }
837
+ });
838
+ }
839
+ if (!winner.value.trim()) return completed;
840
+ return Promise.race([input.apply({
841
+ ...input.request,
842
+ values: {
843
+ callback: winner.value
844
+ }
845
+ }), completed]);
846
+ }
847
+
808
848
  /**
809
849
  * `MenuUi` over the GA dialog API. After `isActive()` turns false every call
810
850
  * is inert: a select resolves as dismissed and nothing is shown.
@@ -1086,7 +1126,7 @@ export function setupGaTui(context, options = {}) {
1086
1126
  } : {})
1087
1127
  });
1088
1128
  };
1089
- const applyChoice = async (scope, request, shown) => {
1129
+ const applyRequest = async (scope, request, shown) => {
1090
1130
  const refused = async (text, code) => ({
1091
1131
  command: ANTIGRAVITY_MENU_COMMAND,
1092
1132
  ok: false,
@@ -1113,9 +1153,33 @@ export function setupGaTui(context, options = {}) {
1113
1153
  await refresh(scope);
1114
1154
  return result;
1115
1155
  };
1156
+ let pendingLogin;
1157
+ const applyChoice = async (scope, request, shown) => {
1158
+ if (request.sectionId !== 'accounts' || request.actionId !== 'add' || request.itemId !== undefined) return applyRequest(scope, request, shown);
1159
+ const completed = Promise.withResolvers();
1160
+ const pending = {
1161
+ scope: scopeKey(scope),
1162
+ finish: completed.resolve
1163
+ };
1164
+ pendingLogin = pending;
1165
+ try {
1166
+ return await runGaDrawerLogin({
1167
+ ui,
1168
+ request,
1169
+ completed: completed.promise,
1170
+ apply: next => applyRequest(scope, next, shown)
1171
+ });
1172
+ } finally {
1173
+ if (pendingLogin === pending) pendingLogin = undefined;
1174
+ }
1175
+ };
1116
1176
  function onNotification(notification, scope) {
1117
1177
  const payload = notification.payload;
1118
1178
  if ('notify' in payload) {
1179
+ if (pendingLogin?.scope === scopeKey(scope) && ['Account added.', 'The Antigravity pool login could not be completed.'].includes(payload.notify.message)) {
1180
+ pendingLogin.finish(payload.notify.kind !== 'error');
1181
+ return;
1182
+ }
1119
1183
  ui.toast(payload.notify.message, payload.notify.kind);
1120
1184
  return;
1121
1185
  }
@@ -1167,6 +1231,7 @@ export function setupGaTui(context, options = {}) {
1167
1231
  return async () => {
1168
1232
  if (cleaned) return;
1169
1233
  cleaned = true;
1234
+ pendingLogin?.finish(false);
1170
1235
  stop();
1171
1236
  client.dispose();
1172
1237
  releaseSlot();
@@ -1302,6 +1302,46 @@ export function presentGaMenu(
1302
1302
 
1303
1303
  // ── Dialogs ─────────────────────────────────────────────────────────────────
1304
1304
 
1305
+ /** The drawer owns this prompt, so a browser callback can dismiss it. */
1306
+ export async function runGaDrawerLogin(input: {
1307
+ ui: MenuUi
1308
+ request: MenuApplyRequest
1309
+ apply(request: MenuApplyRequest): Promise<MenuApplyResult>
1310
+ completed: Promise<boolean>
1311
+ }): Promise<MenuApplyResult> {
1312
+ const started = await input.apply(input.request)
1313
+ if (!started.ok) return started
1314
+ let promptOpen = true
1315
+ const completed = input.completed.then((ok) => {
1316
+ if (promptOpen) input.ui.clear()
1317
+ return {
1318
+ ...started,
1319
+ ok,
1320
+ text: ok
1321
+ ? 'Account added.'
1322
+ : 'The Antigravity pool login could not be completed.',
1323
+ }
1324
+ })
1325
+ const answer = input.ui
1326
+ .prompt({
1327
+ title: 'Add account',
1328
+ description: started.text,
1329
+ placeholder: "Paste the redirect URL from your browser's address bar",
1330
+ })
1331
+ .then((value) => ({ value }))
1332
+ const winner = await Promise.race([completed, answer])
1333
+ promptOpen = false
1334
+ if (!('value' in winner)) return winner
1335
+ if (winner.value === undefined) {
1336
+ return input.apply({ ...input.request, values: { cancel: true } })
1337
+ }
1338
+ if (!winner.value.trim()) return completed
1339
+ return Promise.race([
1340
+ input.apply({ ...input.request, values: { callback: winner.value } }),
1341
+ completed,
1342
+ ])
1343
+ }
1344
+
1305
1345
  /**
1306
1346
  * `MenuUi` over the GA dialog API. After `isActive()` turns false every call
1307
1347
  * is inert: a select resolves as dismissed and nothing is shown.
@@ -1612,7 +1652,7 @@ export function setupGaTui(
1612
1652
  })
1613
1653
  }
1614
1654
 
1615
- const applyChoice = async (
1655
+ const applyRequest = async (
1616
1656
  scope: GaScope,
1617
1657
  request: MenuApplyRequest,
1618
1658
  shown: GaMenuPresentation,
@@ -1644,9 +1684,46 @@ export function setupGaTui(
1644
1684
  return result
1645
1685
  }
1646
1686
 
1687
+ let pendingLogin: { scope: string; finish(ok: boolean): void } | undefined
1688
+ const applyChoice = async (
1689
+ scope: GaScope,
1690
+ request: MenuApplyRequest,
1691
+ shown: GaMenuPresentation,
1692
+ ) => {
1693
+ if (
1694
+ request.sectionId !== 'accounts' ||
1695
+ request.actionId !== 'add' ||
1696
+ request.itemId !== undefined
1697
+ )
1698
+ return applyRequest(scope, request, shown)
1699
+ const completed = Promise.withResolvers<boolean>()
1700
+ const pending = { scope: scopeKey(scope), finish: completed.resolve }
1701
+ pendingLogin = pending
1702
+ try {
1703
+ return await runGaDrawerLogin({
1704
+ ui,
1705
+ request,
1706
+ completed: completed.promise,
1707
+ apply: (next) => applyRequest(scope, next, shown),
1708
+ })
1709
+ } finally {
1710
+ if (pendingLogin === pending) pendingLogin = undefined
1711
+ }
1712
+ }
1713
+
1647
1714
  function onNotification(notification: GaNotification, scope: GaScope) {
1648
1715
  const payload = notification.payload
1649
1716
  if ('notify' in payload) {
1717
+ if (
1718
+ pendingLogin?.scope === scopeKey(scope) &&
1719
+ [
1720
+ 'Account added.',
1721
+ 'The Antigravity pool login could not be completed.',
1722
+ ].includes(payload.notify.message)
1723
+ ) {
1724
+ pendingLogin.finish(payload.notify.kind !== 'error')
1725
+ return
1726
+ }
1650
1727
  ui.toast(payload.notify.message, payload.notify.kind)
1651
1728
  return
1652
1729
  }
@@ -1702,6 +1779,7 @@ export function setupGaTui(
1702
1779
  return async () => {
1703
1780
  if (cleaned) return
1704
1781
  cleaned = true
1782
+ pendingLogin?.finish(false)
1705
1783
  stop()
1706
1784
  client.dispose()
1707
1785
  releaseSlot()
@@ -1,3 +1,6 @@
1
1
  export function isProviderSecretKey(normalizedKey) {
2
- return /token|refresh|access|project|fingerprint|deviceid|sessionid|sessiontoken|secret|password|apikey|clientsecret/.test(normalizedKey);
2
+ return /token|refresh|access|project|fingerprint|deviceid|sessionid|sessiontoken|secret|password|apikey|clientsecret|callback|redirecturl|authorizationcode/.test(normalizedKey);
3
3
  }
4
+ export const OAUTH_REDIRECT_VALUE_PATTERNS = [
5
+ /https?:\/\/[^\s<>"']*[?&](?:code|state)=[^\s<>"']*/gi
6
+ ];
@@ -10,7 +10,10 @@ import {
10
10
  import { homedir } from "node:os";
11
11
  import { dirname, join } from "node:path";
12
12
  import { createLoggerInstance } from "../common-auth-embedded/logger/index.js";
13
- import { isProviderSecretKey } from "../logging/provider-key-policy.js";
13
+ import {
14
+ isProviderSecretKey,
15
+ OAUTH_REDIRECT_VALUE_PATTERNS
16
+ } from "../logging/provider-key-policy.js";
14
17
  const LOG_PREFIX = "[opencode-antigravity-auth/tui]", DEFAULT_MAX_BYTES = 1e6, MAX_KEEP_LINES = 200, FILE_MODE = 384;
15
18
  export function resolveTuiLogPath() {
16
19
  const override = process.env.ANTIGRAVITY_AUTH_TUI_LOG_FILE;
@@ -58,6 +61,7 @@ function createFileLogger(options) {
58
61
  }, channel = createLoggerInstance({
59
62
  level: "debug",
60
63
  extraSecretKeys: isProviderSecretKey,
64
+ extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
61
65
  captureSink: ({ level, message, data }) => {
62
66
  const extra = data !== null && typeof data === "object" && !Array.isArray(data) ? Object.fromEntries(Object.entries(data)) : void 0;
63
67
  write(level === "trace" ? "debug" : level, message, extra);