@cortexkit/common-auth 0.14.2 → 0.16.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.
Files changed (64) hide show
  1. package/README.md +4 -4
  2. package/dist/claustrum/consumer.d.ts +33 -3
  3. package/dist/claustrum/consumer.js +96 -1
  4. package/dist/claustrum/custody.d.ts +4 -1
  5. package/dist/claustrum/enrollment.d.ts +3 -2
  6. package/dist/claustrum/enrollment.js +84 -42
  7. package/dist/claustrum/index.d.ts +2 -1
  8. package/dist/claustrum/index.js +5 -3
  9. package/dist/claustrum/insula.d.ts +69 -0
  10. package/dist/claustrum/insula.js +152 -0
  11. package/dist/claustrum/roster.d.ts +13 -0
  12. package/dist/claustrum/roster.js +28 -2
  13. package/dist/dump/index.d.ts +4 -3
  14. package/dist/dump/index.js +39 -12
  15. package/dist/fs/atomic-write.d.ts +5 -0
  16. package/dist/fs/atomic-write.js +21 -0
  17. package/dist/fs/index.d.ts +2 -0
  18. package/dist/fs/index.js +1 -0
  19. package/dist/fs/private-files.d.ts +66 -0
  20. package/dist/fs/private-files.js +302 -0
  21. package/dist/fs/refresh-file-lock.d.ts +1 -1
  22. package/dist/fs/refresh-file-lock.js +254 -37
  23. package/dist/fs/with-lock.d.ts +3 -0
  24. package/dist/fs/with-lock.js +4 -0
  25. package/dist/logger/engine.d.ts +6 -8
  26. package/dist/logger/engine.js +126 -11
  27. package/dist/pi-slot/slot.d.ts +2 -0
  28. package/dist/pi-slot/slot.js +34 -6
  29. package/dist/rpc/port-file.js +30 -8
  30. package/dist/rpc/rpc-client.js +15 -1
  31. package/dist/rpc/rpc-server.js +8 -3
  32. package/dist/setup/command-runner.d.ts +4 -0
  33. package/dist/setup/command-runner.js +49 -0
  34. package/dist/setup/command.d.ts +3 -0
  35. package/dist/setup/command.js +188 -0
  36. package/dist/setup/config-write.d.ts +11 -0
  37. package/dist/setup/config-write.js +60 -0
  38. package/dist/setup/detect.d.ts +6 -0
  39. package/dist/setup/detect.js +224 -0
  40. package/dist/setup/enroll.d.ts +4 -0
  41. package/dist/setup/enroll.js +70 -0
  42. package/dist/setup/index.d.ts +5 -0
  43. package/dist/setup/index.js +4 -0
  44. package/dist/setup/paths.d.ts +11 -0
  45. package/dist/setup/paths.js +33 -0
  46. package/dist/setup/process-fence.d.ts +41 -0
  47. package/dist/setup/process-fence.js +177 -0
  48. package/dist/setup/prompts.d.ts +4 -0
  49. package/dist/setup/prompts.js +26 -0
  50. package/dist/setup/register.d.ts +11 -0
  51. package/dist/setup/register.js +130 -0
  52. package/dist/setup/types.d.ts +93 -0
  53. package/dist/setup/types.js +1 -0
  54. package/dist/sidebar-file/sidebar-file.d.ts +5 -4
  55. package/dist/sidebar-file/sidebar-file.js +17 -8
  56. package/dist/store/mutate.js +2 -2
  57. package/dist/store/pool.d.ts +1 -0
  58. package/dist/store/pool.js +3 -0
  59. package/dist/store/refresh-lock.d.ts +4 -0
  60. package/dist/store/refresh-lock.js +5 -0
  61. package/dist/tui-prefs/tui-preferences.js +6 -4
  62. package/dist/tui-prefs/watcher.d.ts +3 -0
  63. package/dist/tui-prefs/watcher.js +26 -10
  64. package/package.json +14 -3
@@ -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.16.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": {
@@ -12,6 +12,10 @@
12
12
  "test/fixtures/*"
13
13
  ],
14
14
  "exports": {
15
+ "./setup": {
16
+ "types": "./dist/setup/index.d.ts",
17
+ "import": "./dist/setup/index.js"
18
+ },
15
19
  "./rpc": {
16
20
  "types": "./dist/rpc/index.d.ts",
17
21
  "import": "./dist/rpc/index.js"
@@ -89,7 +93,7 @@
89
93
  "dist/"
90
94
  ],
91
95
  "scripts": {
92
- "build": "bun scripts/check-local-deps.mjs && bun scripts/check-installed-ranges.mjs && tsc -p tsconfig.build.json",
96
+ "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
97
  "test": "bun test",
94
98
  "typecheck": "tsc --noEmit",
95
99
  "types": "bun run typecheck",
@@ -99,9 +103,11 @@
99
103
  "prepublishOnly": "bun run build",
100
104
  "check:ranges": "bun scripts/check-installed-ranges.mjs",
101
105
  "check:claustrum-floor": "bun scripts/check-claustrum-floor.mjs",
106
+ "check:insula-peer": "bun scripts/check-insula-peer.mjs",
102
107
  "check:opentui-0511": "bun scripts/check-opentui-0511.mjs"
103
108
  },
104
109
  "dependencies": {
110
+ "@cortexkit/private-files": "^0.2.1",
105
111
  "jsonc-parser": "^3.3.1"
106
112
  },
107
113
  "peerDependencies": {
@@ -109,6 +115,7 @@
109
115
  "@opentui/solid": ">=0.5.11",
110
116
  "solid-js": "1.9.12",
111
117
  "@cortexkit/claustrum-client": ">=0.6.2",
118
+ "@cortexkit/subc-client": "^0.16.0",
112
119
  "@opencode/plugin": ">=2.0.21"
113
120
  },
114
121
  "peerDependenciesMeta": {
@@ -124,13 +131,17 @@
124
131
  "@cortexkit/claustrum-client": {
125
132
  "optional": true
126
133
  },
134
+ "@cortexkit/subc-client": {
135
+ "optional": true
136
+ },
127
137
  "@opencode/plugin": {
128
138
  "optional": true
129
139
  }
130
140
  },
131
141
  "devDependencies": {
132
142
  "@biomejs/biome": "2.5.14",
133
- "@cortexkit/claustrum-client": "0.6.2",
143
+ "@cortexkit/claustrum-client": "0.9.0",
144
+ "@cortexkit/subc-client": "0.16.1",
134
145
  "@earendil-works/pi-coding-agent": "1.0.4",
135
146
  "@opencode/plugin": "2.0.21",
136
147
  "@opentui/core": ">=0.5.12",