@cortexkit/opencode-openai-auth 1.0.2 → 1.0.4

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 (91) hide show
  1. package/README.md +12 -60
  2. package/dist/bin.js +13 -0
  3. package/dist/index-2hch7e8n.js +8 -0
  4. package/dist/{index-766sfrh5.js → index-45qgkb0m.js} +1 -1
  5. package/dist/index-5dg931q0.js +65 -0
  6. package/dist/index-99esnzg0.js +157 -0
  7. package/dist/index-9reyazwh.js +2 -0
  8. package/dist/index-bgq9d21h.js +2 -0
  9. package/dist/index-dryydk6b.js +2 -0
  10. package/dist/index-egrty6tz.js +12 -0
  11. package/dist/index-envpbt0k.js +3 -0
  12. package/dist/index-jye6vccc.js +2 -0
  13. package/dist/index-k4eacw7x.js +2 -0
  14. package/dist/{index-hy9030jh.js → index-yeyp8t0k.js} +1 -1
  15. package/dist/index-yf6arn5w.js +2 -0
  16. package/dist/index.d.ts +2 -56
  17. package/dist/index.js +1 -1
  18. package/dist/map-CCbSZIhT.d.ts +56 -0
  19. package/dist/{pool-lifecycle-DbDmgabd.d.ts → pool-lifecycle-DqKq8Eej.d.ts} +104 -790
  20. package/dist/{port-file-Do3lQIEk.d.ts → port-file-CZ9MIdy2.d.ts} +1 -1
  21. package/dist/{protocol-BOBdkqqm.d.ts → protocol-CSIDDBDf.d.ts} +1 -1
  22. package/dist/rpc/port-file.d.ts +1 -1
  23. package/dist/rpc/port-file.js +1 -1
  24. package/dist/rpc/protocol.d.ts +1 -1
  25. package/dist/rpc/protocol.js +1 -1
  26. package/dist/rpc/rpc-client.d.ts +3 -3
  27. package/dist/rpc/rpc-client.js +1 -1
  28. package/dist/rpc/rpc-dir.js +1 -1
  29. package/dist/{sidebar-state-D6cUKgkm.d.ts → sidebar-state-BCxFpH68.d.ts} +5 -3
  30. package/dist/sidebar-state.d.ts +1 -1
  31. package/dist/sidebar-state.js +1 -1
  32. package/dist/token-util-gmn5yaqc.js +1 -0
  33. package/dist/{token-ypk61xj0.js → token-vykm9bxh.js} +1 -1
  34. package/dist/tui-preferences.d.ts +2 -1
  35. package/dist/tui-preferences.js +3 -3
  36. package/dist/tui.d.ts +2 -2
  37. package/dist/v2/server.d.ts +1 -1
  38. package/dist/v2/server.js +3 -4
  39. package/package.json +13 -8
  40. package/src/tui-compiled/raw/logger.js +10 -2
  41. package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +2 -1
  42. package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +26 -10
  43. package/src/tui-compiled/raw/shared/375d9cca2def037d-private-files.js +302 -0
  44. package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +3 -1
  45. package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +5 -0
  46. package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +2 -2
  47. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +4 -0
  48. package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +21 -5
  49. package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +21 -0
  50. package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +36 -1
  51. package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +6 -4
  52. package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +30 -8
  53. package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +17 -8
  54. package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +3 -0
  55. package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +3 -2
  56. package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +1 -1
  57. package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +126 -11
  58. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +254 -37
  59. package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +1 -0
  60. package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +15 -1
  61. package/src/tui-compiled/raw/sidebar-state.js +3 -3
  62. package/src/tui-compiled/runtime/logger.js +10 -2
  63. package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +2 -1
  64. package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +26 -10
  65. package/src/tui-compiled/runtime/shared/375d9cca2def037d-private-files.js +302 -0
  66. package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +3 -1
  67. package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +5 -0
  68. package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +2 -2
  69. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +4 -0
  70. package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +21 -5
  71. package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +21 -0
  72. package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +36 -1
  73. package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +6 -4
  74. package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +30 -8
  75. package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +17 -8
  76. package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +3 -0
  77. package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +3 -2
  78. package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +1 -1
  79. package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +126 -11
  80. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +254 -37
  81. package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +1 -0
  82. package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +15 -1
  83. package/src/tui-compiled/runtime/sidebar-state.js +3 -3
  84. package/dist/index-8kj7sa1p.js +0 -12
  85. package/dist/index-b3q3j39x.js +0 -2
  86. package/dist/index-bmd7x5aq.js +0 -2
  87. package/dist/index-eqh53k8v.js +0 -2
  88. package/dist/index-jyr8y8k4.js +0 -7
  89. package/dist/index-m9d2bfkn.js +0 -222
  90. package/dist/index-rv08jmd4.js +0 -2
  91. package/dist/token-util-wdza526f.js +0 -1
@@ -1,6 +1,7 @@
1
- import { chmod, mkdir, readFile } from "node:fs/promises";
1
+ import { chmod, mkdir } from "node:fs/promises";
2
2
  import { dirname } from "node:path";
3
3
  import { LockContentionError, LockOwnershipError, WRITER_LOCK_CONSTANTS, withLock, writeJsonAtomic, } from "./ec971142548df90e-index.js";
4
+ import { ensurePrivateDirectory, PrivateFileError, readPrivateText, windowsPrivateFiles, } from "./375d9cca2def037d-private-files.js";
4
5
  /** Binds generic persistence to a caller's path and normalization policy. */
5
6
  export function createSidebarFile(options) {
6
7
  const { path, defaultValue, normalize } = options;
@@ -17,7 +18,9 @@ export function createSidebarFile(options) {
17
18
  };
18
19
  const readRaw = async () => {
19
20
  try {
20
- return await readFile(path, 'utf8');
21
+ if (windowsPrivateFiles)
22
+ await ensurePrivateDirectory(dirname(path), options.secureDir ?? true);
23
+ return await readPrivateText(path, windowsPrivateFiles);
21
24
  }
22
25
  catch (error) {
23
26
  if (error.code === 'ENOENT')
@@ -29,7 +32,9 @@ export function createSidebarFile(options) {
29
32
  try {
30
33
  return parse(await readRaw());
31
34
  }
32
- catch {
35
+ catch (error) {
36
+ if (error instanceof PrivateFileError)
37
+ throw error;
33
38
  return defaultValue;
34
39
  }
35
40
  };
@@ -109,11 +114,15 @@ export function createSidebarFile(options) {
109
114
  const hooks = writeOptions;
110
115
  const parent = dirname(path);
111
116
  const secureDir = options.secureDir ?? true;
112
- await mkdir(parent, { recursive: true, mode: 0o700 });
113
- if (secureDir) {
114
- await chmod(parent, 0o700).catch((error) => {
115
- options.logger?.warn('sidebar directory permission remediation failed', { error: error instanceof Error ? error.message : String(error) });
116
- });
117
+ if (windowsPrivateFiles)
118
+ await ensurePrivateDirectory(parent, secureDir);
119
+ else {
120
+ await mkdir(parent, { recursive: true, mode: 0o700 });
121
+ if (secureDir) {
122
+ await chmod(parent, 0o700).catch((error) => {
123
+ options.logger?.warn('sidebar directory permission remediation failed', { error: error instanceof Error ? error.message : String(error) });
124
+ });
125
+ }
117
126
  }
118
127
  const committed = await withLock(path, lockOptions, async (lock) => {
119
128
  const commit = async (value) => ({
@@ -60,6 +60,9 @@ export function openPoolStore(options) {
60
60
  now: options.now ?? Date.now,
61
61
  ...(options.onLockEvent ? { onLockEvent: options.onLockEvent } : {}),
62
62
  ...(options.onLockStep ? { onLockStep: options.onLockStep } : {}),
63
+ ...(options.onRenewalTimer
64
+ ? { onRenewalTimer: options.onRenewalTimer }
65
+ : {}),
63
66
  },
64
67
  removedIds: memory.removedIds,
65
68
  requireCredentialStamps: options.requireCredentialStamps === true,
@@ -420,7 +420,8 @@ function parseEntry(raw, codec) {
420
420
  return undefined;
421
421
  if ('disabledReason' in raw && typeof raw.disabledReason !== 'string')
422
422
  return undefined;
423
- if ('quota' in raw && !codec.validate(raw.quota))
423
+ const quota = 'quota' in raw && codec.decode ? codec.decode(raw.quota) : raw.quota;
424
+ if ('quota' in raw && !codec.validate(quota))
424
425
  return undefined;
425
426
  if ('staged' in raw && !parseReservation(raw.staged))
426
427
  return undefined;
@@ -430,7 +431,7 @@ function parseEntry(raw, codec) {
430
431
  ...(typeof raw.disabledReason === 'string'
431
432
  ? { disabledReason: raw.disabledReason }
432
433
  : {}),
433
- ...('quota' in raw ? { quota: raw.quota } : {}),
434
+ ...('quota' in raw ? { quota } : {}),
434
435
  };
435
436
  }
436
437
  function credentialFor(raw, stateEntry) {
@@ -1,5 +1,5 @@
1
1
  export { quotaCodec } from "./053cc17b5419261e-codec.js";
2
2
  export { formatQuota, NO_LIMITS_REPORTED, NO_QUOTA_READING, QUOTA_STALE_AFTER_MS, quotaTextParts, quotaWindowName, } from "./0332701351b3eeec-format.js";
3
- export { ALL_SCOPE, DEFAULT_REQUIRED_LABELS, emptyQuotaMap, isQuotaMap, } from "./905bffc0220f43d0-map.js";
3
+ export { ALL_SCOPE, DEFAULT_REQUIRED_LABELS, decodeQuotaMap, emptyQuotaMap, isQuotaMap, } from "./905bffc0220f43d0-map.js";
4
4
  export { isQuotaObservation, mergeQuotaObservation, QuotaCodecError, } from "./4f36d333d081d040-merge.js";
5
5
  export { budgetExhaustedResetAt, futureResetAt, projectQuota, readsExhausted, } from "./39c3cb05738fcf6d-projection.js";
@@ -1,4 +1,7 @@
1
1
  import { appendFileSync, chmodSync, existsSync, renameSync, statSync, } from "node:fs";
2
+ import { open } from "node:fs/promises";
3
+ import { dirname, resolve } from "node:path";
4
+ import { createPrivateBytes, ensurePrivateDirectory, privateOperation, replaceWindowsFile, verifyPrivate, windowsPrivateFiles, } from "./375d9cca2def037d-private-files.js";
2
5
  import { createRedactor } from "./d319517e3ea6ad70-redact.js";
3
6
  const ORDER = {
4
7
  error: 0,
@@ -36,6 +39,75 @@ function rotateIfNeeded(f) {
36
39
  /* never throw */
37
40
  }
38
41
  }
42
+ async function closeWindowsFile(sink) {
43
+ const { file, handle } = sink;
44
+ sink.file = undefined;
45
+ sink.handle = undefined;
46
+ if (file && handle)
47
+ await privateOperation(file, 'log-close', () => handle.close());
48
+ }
49
+ async function openWindowsFile(sink, file) {
50
+ await ensurePrivateDirectory(dirname(file));
51
+ try {
52
+ await verifyPrivate(file, 'file', true);
53
+ }
54
+ catch (error) {
55
+ if (error.code !== 'ENOENT')
56
+ throw error;
57
+ try {
58
+ await createPrivateBytes(file, '');
59
+ }
60
+ catch (creationError) {
61
+ if (creationError.code !== 'EEXIST')
62
+ throw creationError;
63
+ await verifyPrivate(file, 'file', true);
64
+ }
65
+ }
66
+ // The safe-parent policy denies other ordinary users the ability to create, replace or link entries between verification and fs.open.
67
+ // This protects against other ordinary users, not the owner or administrators, whose ability to change that namespace is outside our threat model.
68
+ sink.handle = await privateOperation(file, 'log-open', () => open(file, 'a'));
69
+ sink.file = file;
70
+ return sink.handle;
71
+ }
72
+ async function flushWindowsFile(sink, file, text) {
73
+ file = resolve(file);
74
+ try {
75
+ if (sink.file !== file)
76
+ await closeWindowsFile(sink);
77
+ let handle = sink.handle ?? (await openWindowsFile(sink, file));
78
+ const info = await privateOperation(file, 'log-stat', () => handle.stat());
79
+ if (info.size >= MAX_BYTES) {
80
+ await closeWindowsFile(sink);
81
+ for (let i = ROTATE_KEEP - 1; i >= 0; i--) {
82
+ const source = i === 0 ? file : `${file}.${i}`;
83
+ const target = `${file}.${i + 1}`;
84
+ try {
85
+ await verifyPrivate(source, 'file', true);
86
+ }
87
+ catch (error) {
88
+ if (error.code === 'ENOENT')
89
+ continue;
90
+ throw error;
91
+ }
92
+ try {
93
+ await verifyPrivate(target, 'file', true);
94
+ }
95
+ catch (error) {
96
+ if (error.code !== 'ENOENT')
97
+ throw error;
98
+ }
99
+ await replaceWindowsFile(source, target);
100
+ await verifyPrivate(target, 'file');
101
+ }
102
+ handle = await openWindowsFile(sink, file);
103
+ }
104
+ await privateOperation(file, 'log-append', () => handle.appendFile(text, 'utf8'));
105
+ }
106
+ catch (error) {
107
+ await closeWindowsFile(sink).catch(() => { });
108
+ throw error;
109
+ }
110
+ }
39
111
  function safeSerialize(data) {
40
112
  try {
41
113
  return ` ${JSON.stringify(data)}`;
@@ -63,7 +135,19 @@ function createEngine(options) {
63
135
  let captureSink;
64
136
  let buffer = [];
65
137
  let timer;
138
+ let orderedSink = Promise.resolve();
139
+ let sinkError;
140
+ const windowsFile = {};
141
+ function queueWindows(operation) {
142
+ const next = orderedSink.then(operation);
143
+ orderedSink = next.catch((error) => {
144
+ sinkError = error;
145
+ });
146
+ return next;
147
+ }
66
148
  function configure(next) {
149
+ if (windowsPrivateFiles && next.file !== logFileSource)
150
+ void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => { });
67
151
  logFileSource = next.file;
68
152
  initLevelSource = next.level;
69
153
  redactor = createRedactor(next);
@@ -89,25 +173,49 @@ function createEngine(options) {
89
173
  return floor;
90
174
  return 'info';
91
175
  }
92
- function flushLogs() {
176
+ function flushLogs(close = true) {
93
177
  if (timer) {
94
178
  clearTimeout(timer);
95
179
  timer = undefined;
96
180
  }
97
- if (!buffer.length)
181
+ if (!buffer.length) {
182
+ if (windowsPrivateFiles)
183
+ return queueWindows(async () => {
184
+ if (close)
185
+ await closeWindowsFile(windowsFile);
186
+ if (sinkError)
187
+ throw sinkError;
188
+ });
98
189
  return;
190
+ }
99
191
  let file;
100
192
  try {
101
193
  file = logFilePath();
102
194
  }
103
195
  catch {
104
196
  buffer = [];
197
+ if (windowsPrivateFiles && close)
198
+ return queueWindows(() => closeWindowsFile(windowsFile));
105
199
  return;
106
200
  }
107
201
  const text = buffer.join('');
108
202
  buffer = [];
109
- if (!file)
203
+ if (!file) {
204
+ if (windowsPrivateFiles && close)
205
+ return queueWindows(() => closeWindowsFile(windowsFile));
110
206
  return;
207
+ }
208
+ if (windowsPrivateFiles) {
209
+ return queueWindows(async () => {
210
+ try {
211
+ await flushWindowsFile(windowsFile, file, text);
212
+ }
213
+ finally {
214
+ if (close)
215
+ await closeWindowsFile(windowsFile);
216
+ }
217
+ });
218
+ }
111
219
  try {
112
220
  rotateIfNeeded(file);
113
221
  if (existsSync(file))
@@ -122,7 +230,9 @@ function createEngine(options) {
122
230
  if (!timer)
123
231
  timer = setTimeout(() => {
124
232
  timer = undefined;
125
- flushLogs();
233
+ const flushed = flushLogs(false);
234
+ if (flushed instanceof Promise)
235
+ void flushed.catch(() => { });
126
236
  }, 500);
127
237
  }
128
238
  function emit(channel, level, message, data) {
@@ -157,8 +267,11 @@ function createEngine(options) {
157
267
  if (logFileSource === undefined)
158
268
  return;
159
269
  buffer.push(line);
160
- if (buffer.length >= 50)
161
- flushLogs();
270
+ if (buffer.length >= 50) {
271
+ const flushed = flushLogs(false);
272
+ if (flushed instanceof Promise)
273
+ void flushed.catch(() => { });
274
+ }
162
275
  else
163
276
  schedule();
164
277
  }
@@ -176,6 +289,9 @@ function createEngine(options) {
176
289
  };
177
290
  }
178
291
  function reset() {
292
+ if (windowsPrivateFiles)
293
+ void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => { });
294
+ sinkError = undefined;
179
295
  buffer = [];
180
296
  if (timer) {
181
297
  clearTimeout(timer);
@@ -222,18 +338,17 @@ export function setLogLevel(l) {
222
338
  defaultEngine.setLogLevel(l);
223
339
  }
224
340
  /**
225
- * Write whatever the default logger has buffered. Safe to call synchronously
226
- * from a process-exit handler, which is how each host drains the buffer on
227
- * shutdown.
341
+ * Write whatever the default logger has buffered. On Windows await the
342
+ * promise before shutdown; POSIX keeps synchronous process-exit flushing.
228
343
  */
229
344
  export function flushLogs() {
230
- defaultEngine.flushLogs();
345
+ return defaultEngine.flushLogs();
231
346
  }
232
347
  export function createLogger(channel) {
233
348
  return defaultEngine.createLogger(channel);
234
349
  }
235
350
  export async function flushForTest() {
236
- defaultEngine.flushLogs();
351
+ return defaultEngine.flushLogs();
237
352
  }
238
353
  /**
239
354
  * Return the default logger to its uninitialised state. Only a test needs