@cortexkit/common-auth 0.14.2 → 0.15.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.
@@ -2,8 +2,13 @@ import { readFileSync, realpathSync, statSync, watch, } from 'node:fs';
2
2
  import { readFile, stat } from 'node:fs/promises';
3
3
  import { basename, dirname, join, resolve } from 'node:path';
4
4
  import { clearTimeout, setTimeout } from 'node:timers';
5
+ import { PrivateFileError, readPrivateText, windowsPrivateFiles, } from '../fs/private-files.js';
5
6
  function canonicalPath(file) {
6
7
  const path = resolve(file);
8
+ // Leave reparse points in the path for private-files' ancestor walk to reject;
9
+ // realpath would follow them before the security backend saw the original path.
10
+ if (windowsPrivateFiles)
11
+ return path;
7
12
  try {
8
13
  return realpathSync(path);
9
14
  }
@@ -34,7 +39,9 @@ export function watchTuiPreferences(file, onChange, options = {}) {
34
39
  if (shared)
35
40
  return shared.subscribe(onChange);
36
41
  const name = basename(path);
37
- const read = options.fs?.readFile ?? ((file) => readFile(file, 'utf8'));
42
+ const read = windowsPrivateFiles
43
+ ? (file) => readPrivateText(file)
44
+ : (options.fs?.readFile ?? ((file) => readFile(file, 'utf8')));
38
45
  const probe = options.fs?.stat ?? stat;
39
46
  let timer = null;
40
47
  let pollTimer = null;
@@ -43,14 +50,15 @@ export function watchTuiPreferences(file, onChange, options = {}) {
43
50
  // Seed synchronously so an immediate write cannot be absorbed as the baseline.
44
51
  // The metadata is recorded only together with contents that were read, as in
45
52
  // the probe below: if the first read fails, the probe keeps trying.
46
- try {
47
- const metadata = identity((options.fs?.statSync ?? statSync)(path));
48
- lastSeen = (options.fs?.readFileSync ?? ((file) => readFileSync(file, 'utf8')))(path);
49
- lastMetadata = metadata;
50
- }
51
- catch {
52
- // Missing or unreadable files are picked up by the probe later.
53
- }
53
+ if (!windowsPrivateFiles)
54
+ try {
55
+ const metadata = identity((options.fs?.statSync ?? statSync)(path));
56
+ lastSeen = (options.fs?.readFileSync ?? ((file) => readFileSync(file, 'utf8')))(path);
57
+ lastMetadata = metadata;
58
+ }
59
+ catch {
60
+ // Missing or unreadable files are picked up by the probe later.
61
+ }
54
62
  let disposed = false;
55
63
  const subscribers = new Set();
56
64
  let checking = Promise.resolve();
@@ -68,7 +76,15 @@ export function watchTuiPreferences(file, onChange, options = {}) {
68
76
  lastMetadata = null;
69
77
  return;
70
78
  }
71
- const text = await read(path).catch(() => null);
79
+ const text = await read(path).catch((error) => {
80
+ if (error instanceof PrivateFileError && error.code !== 'ENOENT') {
81
+ if (options.onError)
82
+ options.onError(error);
83
+ else
84
+ process.emitWarning(error.message, error.name);
85
+ }
86
+ return null;
87
+ });
72
88
  if (disposed)
73
89
  return;
74
90
  // Record the metadata only once its contents were read. A failed read
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/common-auth",
3
- "version": "0.14.2",
3
+ "version": "0.15.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": {
@@ -89,7 +89,7 @@
89
89
  "dist/"
90
90
  ],
91
91
  "scripts": {
92
- "build": "bun scripts/check-local-deps.mjs && bun scripts/check-installed-ranges.mjs && tsc -p tsconfig.build.json",
92
+ "build": "bun scripts/check-local-deps.mjs && bun scripts/check-installed-ranges.mjs && tsc -p tsconfig.build.json && bun scripts/check-private-files-external.ts",
93
93
  "test": "bun test",
94
94
  "typecheck": "tsc --noEmit",
95
95
  "types": "bun run typecheck",
@@ -102,6 +102,7 @@
102
102
  "check:opentui-0511": "bun scripts/check-opentui-0511.mjs"
103
103
  },
104
104
  "dependencies": {
105
+ "@cortexkit/private-files": "^0.2.1",
105
106
  "jsonc-parser": "^3.3.1"
106
107
  },
107
108
  "peerDependencies": {
@@ -130,7 +131,7 @@
130
131
  },
131
132
  "devDependencies": {
132
133
  "@biomejs/biome": "2.5.14",
133
- "@cortexkit/claustrum-client": "0.6.2",
134
+ "@cortexkit/claustrum-client": "0.9.0",
134
135
  "@earendil-works/pi-coding-agent": "1.0.4",
135
136
  "@opencode/plugin": "2.0.21",
136
137
  "@opentui/core": ">=0.5.12",