@cortexkit/common-auth 0.49.2 → 0.50.0

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.
@@ -1,5 +1,9 @@
1
1
  import { basename, dirname, join, resolve } from 'node:path';
2
2
  const maxSymlinkHops = 40;
3
+ // Same shape as Node's realpath ELOOP, so callers that branch on `code` keep working.
4
+ function symlinkLoop(file) {
5
+ return Object.assign(new Error(`ELOOP: too many symbolic links encountered, realpath '${file}'`), { code: 'ELOOP', syscall: 'realpath', path: file });
6
+ }
3
7
  /**
4
8
  * Canonical path of a file that other processes may replace by write-and-rename.
5
9
  *
@@ -26,7 +30,7 @@ export async function canonicalFilePath(file, fs) {
26
30
  if (!isSymlink)
27
31
  return target;
28
32
  if (hops >= maxSymlinkHops)
29
- throw new Error('Too many file symlink hops');
33
+ throw symlinkLoop(file);
30
34
  target = resolve(dirname(target), await fs.readlink(target));
31
35
  }
32
36
  }
@@ -47,7 +51,7 @@ export function canonicalFilePathSync(file, fs) {
47
51
  if (!isSymlink)
48
52
  return target;
49
53
  if (hops >= maxSymlinkHops)
50
- throw new Error('Too many file symlink hops');
54
+ throw symlinkLoop(file);
51
55
  target = resolve(dirname(target), fs.readlinkSync(target));
52
56
  }
53
57
  }
@@ -92,7 +92,7 @@ export const confirmedAffinity = immutable({
92
92
  export const earliestPoolEngine = immutable({
93
93
  evidence: 'typed',
94
94
  markers: hosts(ANTIGRAVITY_FAILURE_LADDER),
95
- readingClearsCoveredScopes: 'off',
95
+ readingClearsCoveredScopes: 'on',
96
96
  successClearsCoveredScopes: 'off',
97
97
  unknown: hosts(reselect),
98
98
  shortLimit: {
@@ -19,4 +19,4 @@ export type { PullReason } from './runtime.js';
19
19
  export type { ApiKeyCredential, CredentialStampStatus, OAuthCredential, PoolCredential, PoolRow, ProviderStateCodec, ProviderStateDrop, ProviderStateReplacement, QuotaCodec, RotateCredential, StoredCredential, } from './schema.js';
20
20
  export { fingerprintOf, LEGACY_STORE_VERSION, POOL_KEY, POOL_ROWS_KEY, POOL_SCHEMA_VERSION, PROVIDER_STATE_KEY, REFRESH_STAMP_TOLERANCE_MS, rowLockKey, } from './schema.js';
21
21
  export type { PoolSettings, SettingsMutator, SettingsRead, UpdateSettingsOptions, UpdateSettingsResult, } from './settings.js';
22
- export { POOL_OWNED_KEYS } from './settings.js';
22
+ export { POOL_OWNED_KEYS, readPoolSettingsAt } from './settings.js';
@@ -4,4 +4,4 @@ export { openPoolStore } from './pool.js';
4
4
  export { DECLINE_TRANSITION } from './provider-state.js';
5
5
  export { POOL_LOCK_DEFAULTS } from './refresh-lock.js';
6
6
  export { fingerprintOf, LEGACY_STORE_VERSION, POOL_KEY, POOL_ROWS_KEY, POOL_SCHEMA_VERSION, PROVIDER_STATE_KEY, REFRESH_STAMP_TOLERANCE_MS, rowLockKey, } from './schema.js';
7
- export { POOL_OWNED_KEYS } from './settings.js';
7
+ export { POOL_OWNED_KEYS, readPoolSettingsAt } from './settings.js';
@@ -52,6 +52,14 @@ export type UpdateSettingsResult = {
52
52
  };
53
53
  /** Reads only the config's settings, without taking a lock or writing anything. */
54
54
  export declare function readPoolSettings(rt: StoreRuntime): Promise<SettingsRead>;
55
+ /**
56
+ * Reads the settings of the pool config at `configPath`, exactly as a store's
57
+ * `readSettings()` does, without opening a store. It reads only that file: no
58
+ * state file, lock, write or migration. A plugin that has already resolved
59
+ * which config file to trust (for example, after a location check) reads it
60
+ * here rather than opening a second store on it.
61
+ */
62
+ export declare function readPoolSettingsAt(configPath: string): Promise<SettingsRead>;
55
63
  /**
56
64
  * One locked read-modify-write of the plugin's settings in the config file
57
65
  * the pool lives in. The pool must be ready (a pending migration or a load
@@ -63,9 +63,19 @@ function settingsRefusal(message) {
63
63
  }
64
64
  const settingsCache = new FileReadCache();
65
65
  /** Reads only the config's settings, without taking a lock or writing anything. */
66
- export async function readPoolSettings(rt) {
67
- const read = async ([configPath = rt.ctx.configPath,] = []) => {
68
- const result = await readPoolConfig(configPath);
66
+ export function readPoolSettings(rt) {
67
+ return readPoolSettingsAt(rt.ctx.configPath);
68
+ }
69
+ /**
70
+ * Reads the settings of the pool config at `configPath`, exactly as a store's
71
+ * `readSettings()` does, without opening a store. It reads only that file: no
72
+ * state file, lock, write or migration. A plugin that has already resolved
73
+ * which config file to trust (for example, after a location check) reads it
74
+ * here rather than opening a second store on it.
75
+ */
76
+ export async function readPoolSettingsAt(configPath) {
77
+ const read = async ([path = configPath,] = []) => {
78
+ const result = await readPoolConfig(path);
69
79
  if (result.status === 'error')
70
80
  return { status: 'error', file: 'config', reason: result.reason };
71
81
  return { status: result.status, settings: settingsOf(result.config) };
@@ -73,7 +83,7 @@ export async function readPoolSettings(rt) {
73
83
  // Native Windows security checks cannot be replaced by a stat fingerprint.
74
84
  const result = windowsPrivateFiles
75
85
  ? await read()
76
- : await settingsCache.read([rt.ctx.configPath], read);
86
+ : await settingsCache.read([configPath], read);
77
87
  return structuredClone(result);
78
88
  }
79
89
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/common-auth",
3
- "version": "0.49.2",
3
+ "version": "0.50.0",
4
4
  "description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
5
5
  "license": "MIT",
6
6
  "repository": {