@cortexkit/opencode-openai-auth 1.17.2 → 1.19.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.
- package/dist/bin.js +8 -8
- package/dist/{codex-request-DYqSE0ti.d.ts → codex-request-Bj3F3fFg.d.ts} +324 -324
- package/dist/{index-emcf633z.js → index-12gxtre8.js} +1 -1
- package/dist/index-3b9e26wv.js +12 -0
- package/dist/index-6tgra34y.js +2 -0
- package/dist/index-7ztbemxe.js +64 -0
- package/dist/{index-qjh3h3wr.js → index-a4cgsngv.js} +3 -3
- package/dist/index-aew7mcfy.js +2 -0
- package/dist/{index-t09qaj5w.js → index-cawk490s.js} +2 -2
- package/dist/{index-srdm5a4d.js → index-gqnca0gh.js} +1 -1
- package/dist/{index-6pakkcrn.js → index-h7xxfm12.js} +1 -1
- package/dist/{index-vjk4wv2b.js → index-hnb97ydy.js} +1 -1
- package/dist/{index-b2pc3ze2.js → index-hrv1msdb.js} +1 -1
- package/dist/{index-y1b9ka54.js → index-r3vc66vz.js} +21 -21
- package/dist/{index-2dqwctzp.js → index-raj3tyyz.js} +1 -1
- package/dist/{index-7ea4dbe9.js → index-v2wvavef.js} +7 -7
- package/dist/index.d.ts +24 -24
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-6ya278eg.js → token-kdjmv82a.js} +1 -1
- package/dist/token-util-71r7z2vr.js +1 -0
- package/dist/tui-preferences.js +1 -1
- package/dist/tui.d.ts +1 -1
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +3 -2
- package/package.json +2 -2
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +1 -1
- package/src/tui-compiled/raw/shared/375d9cca2def037d-private-files.js +6 -2
- package/src/tui-compiled/raw/shared/54eba94fd64c8c3c-index.js +1 -1
- package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +14 -4
- package/src/tui-compiled/raw/shared/94f53cfd572ba4bb-availability.js +1 -1
- package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +55 -49
- package/src/tui-compiled/raw/shared/cf4c37f3975c3a8d-canonical-file-path.js +6 -2
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +1 -1
- package/src/tui-compiled/runtime/shared/375d9cca2def037d-private-files.js +6 -2
- package/src/tui-compiled/runtime/shared/54eba94fd64c8c3c-index.js +1 -1
- package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +14 -4
- package/src/tui-compiled/runtime/shared/94f53cfd572ba4bb-availability.js +1 -1
- package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +55 -49
- package/src/tui-compiled/runtime/shared/cf4c37f3975c3a8d-canonical-file-path.js +6 -2
- package/dist/index-4thkhwyp.js +0 -12
- package/dist/index-h8ychf80.js +0 -2
- package/dist/index-jmzh060w.js +0 -64
- package/dist/index-q7d43xxn.js +0 -2
- package/dist/token-util-ynanp4np.js +0 -1
|
@@ -94,9 +94,8 @@ async function removeCorruptPortFile(portFile, log) {
|
|
|
94
94
|
export async function writePortFile(dir, entry, options = {}) {
|
|
95
95
|
// The directory can be removed by another project's sweep between our
|
|
96
96
|
// mkdir and the first open/rename, so the whole create-then-rename
|
|
97
|
-
// unit
|
|
98
|
-
//
|
|
99
|
-
// the second attempt — failing fast beats an unbounded loop.
|
|
97
|
+
// unit gets up to five attempts on ENOENT. Each retry recreates the
|
|
98
|
+
// directory after a short delay, but persistent removal still surfaces.
|
|
100
99
|
const writeOnce = async () => {
|
|
101
100
|
const target = join(dir, `port-${entry.pid}.json`);
|
|
102
101
|
if (windowsPrivateFiles) {
|
|
@@ -136,14 +135,15 @@ export async function writePortFile(dir, entry, options = {}) {
|
|
|
136
135
|
}
|
|
137
136
|
return target;
|
|
138
137
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
if (error.code === 'ENOENT') {
|
|
138
|
+
for (let attempt = 1;; attempt += 1) {
|
|
139
|
+
try {
|
|
144
140
|
return await writeOnce();
|
|
145
141
|
}
|
|
146
|
-
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error.code !== 'ENOENT' || attempt === 5)
|
|
144
|
+
throw error;
|
|
145
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
146
|
+
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
export async function sweepRpcState(root, activeDir, isManagedDir, log, options = {}) {
|
|
@@ -163,52 +163,58 @@ export async function sweepRpcState(root, activeDir, isManagedDir, log, options
|
|
|
163
163
|
continue;
|
|
164
164
|
}
|
|
165
165
|
const dir = join(root, projectDir.name);
|
|
166
|
-
|
|
166
|
+
if (!(await sweepRpcDirectory(dir, log, options, cutoff)))
|
|
167
|
+
continue;
|
|
168
|
+
if (resolve(dir) !== active)
|
|
169
|
+
await rmdir(dir).catch(() => { });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Internal folder cleanup shared by full and throttled startup sweeps. */
|
|
173
|
+
export async function sweepRpcDirectory(dir, log, options = {}, cutoff = staleBefore(options)) {
|
|
174
|
+
let names;
|
|
175
|
+
try {
|
|
176
|
+
names = await readdir(dir);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (error.code === 'ENOENT')
|
|
180
|
+
return false;
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
for (const name of names) {
|
|
184
|
+
if (!name.startsWith('port-') || !name.endsWith('.json'))
|
|
185
|
+
continue;
|
|
186
|
+
const portFile = join(dir, name);
|
|
187
|
+
const info = await stat(portFile).catch(() => undefined);
|
|
188
|
+
let raw;
|
|
167
189
|
try {
|
|
168
|
-
|
|
190
|
+
raw = await readPrivateText(portFile);
|
|
169
191
|
}
|
|
170
192
|
catch (error) {
|
|
171
|
-
if (error.code
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
if (error instanceof PrivateFileError && error.code !== 'ENOENT')
|
|
194
|
+
throw error;
|
|
195
|
+
continue;
|
|
174
196
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let raw;
|
|
181
|
-
try {
|
|
182
|
-
raw = await readPrivateText(portFile);
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
if (error instanceof PrivateFileError && error.code !== 'ENOENT')
|
|
186
|
-
throw error;
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (raw === undefined)
|
|
190
|
-
continue;
|
|
191
|
-
let parsed;
|
|
192
|
-
try {
|
|
193
|
-
parsed = JSON.parse(raw);
|
|
194
|
-
}
|
|
195
|
-
catch {
|
|
196
|
-
await removeCorruptPortFile(portFile, log);
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
if (!isUsablePortFileEntry(parsed, name)) {
|
|
200
|
-
await removeCorruptPortFile(portFile, log);
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
const entry = parsed;
|
|
204
|
-
if (!pidAlive(entry.pid))
|
|
205
|
-
await unlink(portFile).catch(() => { });
|
|
206
|
-
else if (isStalePortFile(entry, info, cutoff))
|
|
207
|
-
await removeStalePortFile(portFile, raw, info, options.beforeRemove);
|
|
197
|
+
if (raw === undefined)
|
|
198
|
+
continue;
|
|
199
|
+
let parsed;
|
|
200
|
+
try {
|
|
201
|
+
parsed = JSON.parse(raw);
|
|
208
202
|
}
|
|
209
|
-
|
|
210
|
-
await
|
|
203
|
+
catch {
|
|
204
|
+
await removeCorruptPortFile(portFile, log);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (!isUsablePortFileEntry(parsed, name)) {
|
|
208
|
+
await removeCorruptPortFile(portFile, log);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const entry = parsed;
|
|
212
|
+
if (!pidAlive(entry.pid))
|
|
213
|
+
await unlink(portFile).catch(() => { });
|
|
214
|
+
else if (isStalePortFile(entry, info, cutoff))
|
|
215
|
+
await removeStalePortFile(portFile, raw, info, options.beforeRemove);
|
|
211
216
|
}
|
|
217
|
+
return true;
|
|
212
218
|
}
|
|
213
219
|
/** Internal cache validation: probe only the selected file and its PID. */
|
|
214
220
|
export async function portFileIdentity(dir, entry, options = {}) {
|
|
@@ -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
|
|
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
|
|
54
|
+
throw symlinkLoop(file);
|
|
51
55
|
target = resolve(dirname(target), fs.readlinkSync(target));
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -404,7 +404,7 @@ export class ClaustrumScopedCustody {
|
|
|
404
404
|
throw error;
|
|
405
405
|
if (classifyVaultFailure(error) === 'unreachable')
|
|
406
406
|
throw new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError ? error.reason : undefined);
|
|
407
|
-
throw new ClaustrumConsumerError('unavailable', 'Claustrum scoped operation
|
|
407
|
+
throw new ClaustrumConsumerError('unavailable', 'Claustrum scoped operation failed');
|
|
408
408
|
}
|
|
409
409
|
finally {
|
|
410
410
|
removeAbortListener?.();
|
|
@@ -24,7 +24,9 @@ export function setPrivateFilesBackendForTest(api) {
|
|
|
24
24
|
/** The fixed `reason` of a refusal because the Windows native addon did not load. */
|
|
25
25
|
export const PRIVATE_FILES_UNAVAILABLE_REASON = 'native-addon-unavailable';
|
|
26
26
|
function privateFilesUnavailable(cause) {
|
|
27
|
-
return Object.assign(new Error('Windows private-files native addon
|
|
27
|
+
return Object.assign(new Error('Windows private-files native addon could not be loaded', {
|
|
28
|
+
cause,
|
|
29
|
+
}), {
|
|
28
30
|
code: 'ERR_PRIVATE_FILES_UNAVAILABLE',
|
|
29
31
|
reason: PRIVATE_FILES_UNAVAILABLE_REASON,
|
|
30
32
|
});
|
|
@@ -83,7 +85,9 @@ export class PrivateFileError extends Error {
|
|
|
83
85
|
constructor(path, stage, cause) {
|
|
84
86
|
const detail = cause;
|
|
85
87
|
super(detail?.code === 'ERR_PRIVATE_FILES_UNAVAILABLE'
|
|
86
|
-
?
|
|
88
|
+
? // The reason stays on `.reason`: its word "unavailable" would make
|
|
89
|
+
// OpenCode 1 retry a plain error carrying this message.
|
|
90
|
+
`Private file refused at ${stage}: ${path}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.`
|
|
87
91
|
: `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? 'io-error'}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
|
|
88
92
|
this.path = path;
|
|
89
93
|
this.stage = stage;
|
|
@@ -4,4 +4,4 @@ export { openPoolStore } from "./c852a15cfe489d12-pool.js";
|
|
|
4
4
|
export { DECLINE_TRANSITION } from "./97484d9bb98c705b-provider-state.js";
|
|
5
5
|
export { POOL_LOCK_DEFAULTS } from "./43fc9e6b994519c7-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 "./cd94316a888b0a8e-schema.js";
|
|
7
|
-
export { POOL_OWNED_KEYS } from "./836fc615de6afbd9-settings.js";
|
|
7
|
+
export { POOL_OWNED_KEYS, readPoolSettingsAt } from "./836fc615de6afbd9-settings.js";
|
|
@@ -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
|
|
67
|
-
|
|
68
|
-
|
|
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([
|
|
86
|
+
: await settingsCache.read([configPath], read);
|
|
77
87
|
return structuredClone(result);
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
@@ -94,7 +94,7 @@ export class ClaustrumUnreachableError extends ClaustrumConsumerError {
|
|
|
94
94
|
*/
|
|
95
95
|
reason;
|
|
96
96
|
constructor(reason) {
|
|
97
|
-
super('unavailable', 'Claustrum
|
|
97
|
+
super('unavailable', 'Claustrum vault could not be reached');
|
|
98
98
|
this.name = 'ClaustrumUnreachableError';
|
|
99
99
|
if (reason === 'host-accessor-missing' || reason === 'host-accessor-failed')
|
|
100
100
|
this.reason = reason;
|
|
@@ -94,9 +94,8 @@ async function removeCorruptPortFile(portFile, log) {
|
|
|
94
94
|
export async function writePortFile(dir, entry, options = {}) {
|
|
95
95
|
// The directory can be removed by another project's sweep between our
|
|
96
96
|
// mkdir and the first open/rename, so the whole create-then-rename
|
|
97
|
-
// unit
|
|
98
|
-
//
|
|
99
|
-
// the second attempt — failing fast beats an unbounded loop.
|
|
97
|
+
// unit gets up to five attempts on ENOENT. Each retry recreates the
|
|
98
|
+
// directory after a short delay, but persistent removal still surfaces.
|
|
100
99
|
const writeOnce = async () => {
|
|
101
100
|
const target = join(dir, `port-${entry.pid}.json`);
|
|
102
101
|
if (windowsPrivateFiles) {
|
|
@@ -136,14 +135,15 @@ export async function writePortFile(dir, entry, options = {}) {
|
|
|
136
135
|
}
|
|
137
136
|
return target;
|
|
138
137
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
if (error.code === 'ENOENT') {
|
|
138
|
+
for (let attempt = 1;; attempt += 1) {
|
|
139
|
+
try {
|
|
144
140
|
return await writeOnce();
|
|
145
141
|
}
|
|
146
|
-
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error.code !== 'ENOENT' || attempt === 5)
|
|
144
|
+
throw error;
|
|
145
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
146
|
+
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
export async function sweepRpcState(root, activeDir, isManagedDir, log, options = {}) {
|
|
@@ -163,52 +163,58 @@ export async function sweepRpcState(root, activeDir, isManagedDir, log, options
|
|
|
163
163
|
continue;
|
|
164
164
|
}
|
|
165
165
|
const dir = join(root, projectDir.name);
|
|
166
|
-
|
|
166
|
+
if (!(await sweepRpcDirectory(dir, log, options, cutoff)))
|
|
167
|
+
continue;
|
|
168
|
+
if (resolve(dir) !== active)
|
|
169
|
+
await rmdir(dir).catch(() => { });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Internal folder cleanup shared by full and throttled startup sweeps. */
|
|
173
|
+
export async function sweepRpcDirectory(dir, log, options = {}, cutoff = staleBefore(options)) {
|
|
174
|
+
let names;
|
|
175
|
+
try {
|
|
176
|
+
names = await readdir(dir);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (error.code === 'ENOENT')
|
|
180
|
+
return false;
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
for (const name of names) {
|
|
184
|
+
if (!name.startsWith('port-') || !name.endsWith('.json'))
|
|
185
|
+
continue;
|
|
186
|
+
const portFile = join(dir, name);
|
|
187
|
+
const info = await stat(portFile).catch(() => undefined);
|
|
188
|
+
let raw;
|
|
167
189
|
try {
|
|
168
|
-
|
|
190
|
+
raw = await readPrivateText(portFile);
|
|
169
191
|
}
|
|
170
192
|
catch (error) {
|
|
171
|
-
if (error.code
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
if (error instanceof PrivateFileError && error.code !== 'ENOENT')
|
|
194
|
+
throw error;
|
|
195
|
+
continue;
|
|
174
196
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let raw;
|
|
181
|
-
try {
|
|
182
|
-
raw = await readPrivateText(portFile);
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
if (error instanceof PrivateFileError && error.code !== 'ENOENT')
|
|
186
|
-
throw error;
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (raw === undefined)
|
|
190
|
-
continue;
|
|
191
|
-
let parsed;
|
|
192
|
-
try {
|
|
193
|
-
parsed = JSON.parse(raw);
|
|
194
|
-
}
|
|
195
|
-
catch {
|
|
196
|
-
await removeCorruptPortFile(portFile, log);
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
if (!isUsablePortFileEntry(parsed, name)) {
|
|
200
|
-
await removeCorruptPortFile(portFile, log);
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
const entry = parsed;
|
|
204
|
-
if (!pidAlive(entry.pid))
|
|
205
|
-
await unlink(portFile).catch(() => { });
|
|
206
|
-
else if (isStalePortFile(entry, info, cutoff))
|
|
207
|
-
await removeStalePortFile(portFile, raw, info, options.beforeRemove);
|
|
197
|
+
if (raw === undefined)
|
|
198
|
+
continue;
|
|
199
|
+
let parsed;
|
|
200
|
+
try {
|
|
201
|
+
parsed = JSON.parse(raw);
|
|
208
202
|
}
|
|
209
|
-
|
|
210
|
-
await
|
|
203
|
+
catch {
|
|
204
|
+
await removeCorruptPortFile(portFile, log);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (!isUsablePortFileEntry(parsed, name)) {
|
|
208
|
+
await removeCorruptPortFile(portFile, log);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const entry = parsed;
|
|
212
|
+
if (!pidAlive(entry.pid))
|
|
213
|
+
await unlink(portFile).catch(() => { });
|
|
214
|
+
else if (isStalePortFile(entry, info, cutoff))
|
|
215
|
+
await removeStalePortFile(portFile, raw, info, options.beforeRemove);
|
|
211
216
|
}
|
|
217
|
+
return true;
|
|
212
218
|
}
|
|
213
219
|
/** Internal cache validation: probe only the selected file and its PID. */
|
|
214
220
|
export async function portFileIdentity(dir, entry, options = {}) {
|
|
@@ -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
|
|
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
|
|
54
|
+
throw symlinkLoop(file);
|
|
51
55
|
target = resolve(dirname(target), fs.readlinkSync(target));
|
|
52
56
|
}
|
|
53
57
|
}
|
package/dist/index-4thkhwyp.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{Lg as U,Mg as E,Qg as F,Rg as p,Sg as L,Wg as c}from"./index-q7d43xxn.js";import{createHash as Cz,randomUUID as y}from"node:crypto";import{chmod as zz,mkdir as Gz,open as Jz,readdir as b,rename as Kz,rmdir as Nz,stat as S,unlink as T}from"node:fs/promises";import{uptime as Qz}from"node:os";import{join as R,resolve as g}from"node:path";function x(z){return(z.now??Date.now)()-(z.uptime??Qz)()*1000-300000}function k(z,G,Q){let V=z.startedAt===void 0?G?.mtimeMs:z.startedAt;return typeof V==="number"&&Number.isFinite(V)&&V<Q}async function Vz(z,G,Q,V){if(!Q)return;await V?.(z);try{let J=await L(z),K=await S(z);if(J===G&&K.dev===Q.dev&&K.ino===Q.ino&&K.mtimeMs===Q.mtimeMs&&K.size===Q.size)await T(z).catch(()=>{})}catch(J){if(J instanceof E&&J.code!=="ENOENT")throw J}}function a(z){return typeof z==="number"&&Number.isSafeInteger(z)&&z>0}function u(z){if(!a(z))return!1;try{return process.kill(z,0),!0}catch(G){return G.code==="EPERM"}}function Uz(z){return(G)=>Wz(G,z)}function Wz(z,G){if(/^[0-9a-f]{16}$/.test(z))return!0;return z.startsWith(G)&&/^[0-9a-f]{16}$/.test(z.slice(G.length))}function Xz(z){let G=/^port-(\d+)\.json$/.exec(z);return G?Number(G[1]):void 0}function s(z,G){if(z===null||typeof z!=="object"||Array.isArray(z))return!1;let{pid:Q,port:V,token:J}=z;return a(Q)&&Xz(G)===Q&&typeof V==="number"&&Number.isInteger(V)&&V>=1&&V<=65535&&typeof J==="string"&&J.length>0}async function l(z,G){G?.debug("rpc corrupt port file",{pid:process.pid,portFile:z}),await T(z).catch(()=>{})}async function Ez(z,G,Q={}){let V=async()=>{let J=R(z,`port-${G.pid}.json`);if(U)return await p(z,Q.secureDir??!1),await Q.beforeWrite?.(),await c(J,JSON.stringify({...G,startedAt:Date.now()}),{stagePath:`${J}.${(Q.stageName??y)()}.tmp`}),J;if(await Gz(z,{recursive:!0,mode:Q.secureDir?448:void 0}),Q.secureDir)await zz(z,448);await Q.beforeWrite?.();let K={...G,startedAt:Date.now()},Y=`${J}.${(Q.stageName??y)()}.tmp`,W,N=!1;try{W=await Jz(Y,"wx",384),N=!0,await W.writeFile(JSON.stringify(K),"utf8"),await W.chmod(384),await W.close(),W=void 0,await Kz(Y,J),N=!1}finally{if(await W?.close().catch(()=>{}),N)await T(Y).catch(()=>{})}return J};try{return await V()}catch(J){if(J.code==="ENOENT")return await V();throw J}}async function Lz(z,G,Q,V,J={}){let K=x(J),Y;try{Y=await b(z,{withFileTypes:!0})}catch(N){if(N.code==="ENOENT")return;throw N}let W=g(G);for(let N of Y){if(!N.isDirectory()||!Q(N.name))continue;let X=R(z,N.name),Z;try{Z=await b(X)}catch($){if($.code==="ENOENT")continue;throw $}for(let $ of Z){if(!$.startsWith("port-")||!$.endsWith(".json"))continue;let H=R(X,$),C=await S(H).catch(()=>{return}),q;try{q=await L(H)}catch(O){if(O instanceof E&&O.code!=="ENOENT")throw O;continue}if(q===void 0)continue;let A;try{A=JSON.parse(q)}catch{await l(H,V);continue}if(!s(A,$)){await l(H,V);continue}let I=A;if(!u(I.pid))await T(H).catch(()=>{});else if(k(I,C,K))await Vz(H,q,C,J.beforeRemove)}if(g(X)!==W)await Nz(X).catch(()=>{})}}async function d(z,G,Q={}){let V=x(Q);if(!u(G.pid))return null;let J=R(g(z),`port-${G.pid}.json`);try{if(U)await F(J,"file");let K=await S(J);if(k(G,K,V))return null;return`${J}:${K.dev}:${K.ino}:${K.mtimeMs}:${K.size}`}catch(K){if(K instanceof E&&K.code!=="ENOENT")throw K;return null}}async function n(z,G,Q={}){let V=x(Q),J;try{if(U)await F(z,"directory");J=await b(z)}catch(X){if(X instanceof E&&X.code!=="ENOENT")throw X;return null}let K=[];for(let X of J){if(!X.startsWith("port-")||!X.endsWith(".json"))continue;try{let Z=JSON.parse(await L(R(z,X)));if(s(Z,X))if(u(Z.pid)){let $=Z.startedAt===void 0?await S(R(z,X)).catch(()=>{return}):void 0;if(!k(Z,$,V))K.push(Z)}else await T(R(z,X)).catch(()=>{})}catch(Z){if(Z instanceof E&&Z.code!=="ENOENT")throw Z}}if(K.length===0)return null;let Y=G!==void 0&&G>=1?K.filter((X)=>X.pid===G):[];if(Q.exactPid===!0&&Y.length===0)return null;let W=Y.length>0?Y:K,N=(X)=>typeof X.startedAt==="number"&&Number.isFinite(X.startedAt)?X.startedAt:-1/0;return W.sort((X,Z)=>N(Z)-N(X))[0]??null}import{open as Yz}from"node:fs/promises";import{connect as Zz}from"node:net";import{join as $z,resolve as t}from"node:path";var e=2000,_=new Map,B=new Map;async function Hz(z,G){let Q=$z(t(z),`port-${G.pid}.json`);if(U){let J=JSON.parse(await L(Q));if(J.pid!==G.pid||J.port!==G.port||J.token!==G.token)return null;return null}let V;try{V=await Yz(Q,"r");let J=await V.stat(),K=JSON.parse(await V.readFile("utf8"));if(K.pid!==G.pid||K.port!==G.port||K.token!==G.token)return null;return`${Q}:${J.dev}:${J.ino}:${J.mtimeMs}:${J.size}`}catch{return null}finally{await V?.close().catch(()=>{})}}async function i(z,G,Q,V){let J=_.get(z);if(!U&&J&&await d(G,J.entry)===J.identity)return J;_.delete(z);let K=B.get(z);if(K)return K;let Y=(async()=>{let W=await(V.discover??n)(G,Q,V);if(!W)return null;let N=await Hz(G,W);if(!N)return{entry:W,identity:""};let X={entry:W,identity:N};return _.set(z,X),X})();B.set(z,Y);try{return await Y}finally{if(B.get(z)===Y)B.delete(z)}}async function o(z,G,Q,V=e){return new Promise((J)=>{let K,Y=!1,W=!1,N=(Z,$=!1)=>{if(Y)return;Y=!0,clearTimeout(X),K?.destroy(),J({value:Z,stale:$})},X=setTimeout(()=>N(null),V);try{let Z=JSON.stringify(Q);K=Zz({host:"127.0.0.1",port:z.port}),K.on("connect",()=>{W=!0,K?.write(`POST /rpc/${G} HTTP/1.0\r
|
|
2
|
-
Host: 127.0.0.1:${z.port}\r
|
|
3
|
-
Connection: close\r
|
|
4
|
-
Content-Type: application/json\r
|
|
5
|
-
Content-Length: ${Buffer.byteLength(Z)}\r
|
|
6
|
-
Authorization: Bearer ${z.token}\r
|
|
7
|
-
\r
|
|
8
|
-
`+Z)});let $=[],H=0,C,q,A=Buffer.alloc(0),I=()=>{if(C===void 0)return N(null);try{let O=Buffer.concat($).subarray(C);N(JSON.parse(O.toString("utf8")))}catch{N(null)}};K.on("data",(O)=>{if(Y)return;if(H+=O.length,$.push(O),C===void 0){A=Buffer.concat([A,O]);let D=A.indexOf(`\r
|
|
9
|
-
\r
|
|
10
|
-
`);if(D>=0)C=D+4;if((C??A.length)>16384)return N(null);if(C!==void 0){let P=A.subarray(0,D).toString("latin1").split(`\r
|
|
11
|
-
`),f=/^HTTP\/1\.[01] (\d{3})(?: |$)/.exec(P[0]??"");if(!f)return N(null);let j=Number(f[1]);if(j<200||j>=300)return N(null,[401,403,404,410].includes(j));for(let w of P.slice(1)){let v=w.indexOf(":"),h=w.slice(0,v).toLowerCase(),m=w.slice(v+1).trim();if(h==="transfer-encoding")return N(null);if(h==="content-length"){if(q!==void 0||!/^\d+$/.test(m))return N(null);if(q=Number(m),!Number.isSafeInteger(q)||q>8388608)return N(null)}}A=Buffer.alloc(0)}}let M=H-(C??H);if(M>8388608)return N(null);if(q!==void 0){if(M>q)return N(null);if(M===q)I()}}),K.on("end",()=>{if(q!==void 0&&H-(C??0)!==q)return N(null);I()}),K.on("error",()=>N(null,!W)),K.on("close",()=>N(null))}catch{N(null,!W)}})}async function r(z,G,Q,V,J,K,Y=e){let W=JSON.stringify([t(z),G??null,Q.exactPid===!0]),N=await i(W,z,G,Q);if(V(N?.entry??null),!N)return null;let X=Date.now()+Y,Z=await o(N.entry,J,K,Y);if(!Z.stale)return Z.value;if(_.get(W)===N)_.delete(W);let $=await i(W,z,G,Q);if(!$||Date.now()>=X)return null;if($.entry.port===N.entry.port&&$.entry.pid===N.entry.pid&&$.entry.token===N.entry.token){if(_.get(W)===$)_.delete(W);return null}let H=await o($.entry,J,K,X-Date.now());if(H.stale&&_.get(W)===$)_.delete(W);return H.value}function jz(z,G,Q,V={}){let J={exactPid:V.exactPid,discover:V.discover},K=!1,Y=(W)=>{if(K)return;Q?.(W),K=!0};return{async pending(W,N,X){return(await r(z,G,J,Y,"pending-notifications",{lastReceivedId:W,sessionId:N},X))?.messages??[]},async apply(W,N){return await r(z,G,J,Y,"apply",{...W},N)??{text:"apply failed",knobs:{}}}}}
|
|
12
|
-
export{Uz as rg,Ez as sg,Lz as tg,n as ug,e as vg,jz as wg};
|
package/dist/index-h8ychf80.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{rg as w,sg as O,tg as k}from"./index-4thkhwyp.js";import{Mg as h,Sg as D}from"./index-q7d43xxn.js";import{Yg as j}from"./index-b2pc3ze2.js";class g extends Error{operation;constructor(f){super(`a ${f} on a strict notification scope needs a session id`);this.name="RpcSessionRequiredError",this.operation=f}}function M(f){return typeof f==="string"&&f.length>0}var U=new Map;function y(f){let x=JSON.stringify([f.rpcRoot,f.directoryPrefix,f.registrationSessionId,...f.requireSession===!0?["strict"]:[]]),z=U.get(x);if(!z)z={queue:[],nextId:1,lastDrainAtBySession:new Map,lastDrainAtAny:0},U.set(x,z);return z}var m=100,t=3000;function i(f,x,z){if(f.requireSession===!0&&!M(z))throw new g("push");let H=y(f);if(H.queue.push({id:H.nextId++,type:"open-dialog",payload:x,sessionId:z}),H.queue.length>m)H.queue=H.queue.slice(-m)}function n(f,x=0,z){if(f.requireSession===!0&&!M(z))throw new g("drain");let H=y(f),Y=Date.now();if(H.lastDrainAtAny=Y,z!==void 0)H.lastDrainAtBySession.set(z,Y);let Z=f.sessionlessDrain==="broadcast-only",L=(B)=>z===void 0?!Z||B.sessionId===void 0:B.sessionId===void 0||B.sessionId===z;if(x>0)H.queue=H.queue.filter((B)=>{if(B.id>x)return!0;if(z===void 0)return!Z||B.sessionId!==void 0;return B.sessionId!==z});return H.queue.filter((B)=>B.id>x&&L(B))}function a(f,x){let z=Date.now(),H=y(f),Y=x!==void 0?H.lastDrainAtBySession.get(x)??0:f.sessionlessDrain==="broadcast-only"?H.lastDrainAtAny:0;return Y>0&&z-Y<t}import{randomBytes as v,timingSafeEqual as q}from"node:crypto";import{unlink as u}from"node:fs/promises";import{createServer as I}from"node:http";import{join as l}from"node:path";class N extends Error{status;constructor(f,x){if(!Number.isInteger(f)||f<400||f>499)throw RangeError(`RpcRequestError status must be 4xx, got ${f}`);super(x);this.name="RpcRequestError",this.status=f}}var E=1e6;class _ extends Error{declaredOversize;constructor(f){super("body too large");this.declaredOversize=f}}function p(f){return new Promise((x,z)=>{let H=(B=!1)=>{f.removeAllListeners("data"),f.on("data",()=>{}),f.resume(),z(new _(B))},Y=Number(f.headers["content-length"]);if(Number.isFinite(Y)&&Y>E){H(!0);return}let Z=[],L=0;f.on("data",(B)=>{if(L+=B.length,L>E){H();return}Z.push(B)}),f.on("end",()=>x(Buffer.concat(Z).toString("utf8"))),f.on("error",z)})}class S extends Error{}async function c(f,x){let z,H=new Promise((Y,Z)=>{z=setTimeout(()=>Z(new S("apply deadline exceeded")),x),z.unref?.()});f.catch(()=>{});try{return await Promise.race([f,H])}finally{clearTimeout(z)}}function d(f,x){if(!f?.startsWith("Bearer "))return!1;let z=Buffer.from(f.slice(7)),H=Buffer.from(x);return z.length===H.length&&q(z,H)}async function Bf(f){if(typeof f.drain==="function"===(typeof f.drainAsync==="function"))throw TypeError("exactly one of drain or drainAsync must be provided");let x=f.log??{warn(){},debug(){}},z=v(32).toString("hex"),H=f.timeoutMs??90000,Y=f.receiptTimeoutMs??2000,Z=!1,L=new Set,B=I((V,J)=>{V.setTimeout(H,()=>{V.socket.destroy()}),T(V,J)});B.on("connection",(V)=>{L.add(V),V.once("close",()=>L.delete(V))}),B.requestTimeout=Y,B.headersTimeout=Y;async function T(V,J){let G=(X,b,C={})=>{if(J.headersSent||J.writableEnded||J.destroyed)return;J.writeHead(X,{"content-type":"application/json",...C}),J.end(JSON.stringify(b))};try{let X=new URL(V.url??"/","http://127.0.0.1").pathname;if(V.method==="GET"&&X==="/health")return G(200,{ok:!0});if(V.method!=="POST"||!X.startsWith("/rpc/"))return G(404,{error:"not found"});if(!d(V.headers.authorization,z))return G(401,{error:"unauthorized"});let b=X.slice(5),C;try{C=await p(V)}catch($){if(!($ instanceof _))throw $;let P=V.socket;if(J.once("finish",()=>{P.end();let A=setTimeout(()=>P.destroy(),2000);if(A.unref(),V.once("end",()=>P.destroy()),P.once("close",()=>clearTimeout(A)),V.complete)P.destroy()}),!$.declaredOversize&&!V.complete){if(J.headersSent||J.writableEnded||J.destroyed)return;let A=JSON.stringify({error:"body too large"});J.writeHead(413,{"content-type":"application/json","content-length":Buffer.byteLength(A),connection:"close"}),J.write(A),V.once("end",()=>J.end());return}return G(413,{error:"body too large"},{connection:"close"})}let F;try{F=JSON.parse(C||"{}")}catch{return G(400,{error:"invalid json"})}if(b==="pending-notifications"){let $;try{if(f.parsePending)$=f.parsePending(F);else{if(!F||typeof F!=="object"||Array.isArray(F))throw Error("invalid params");let K=F;if(f.requireSession===!0&&!M(K.sessionId))return G(400,{error:"session required"});if("lastReceivedId"in K&&(typeof K.lastReceivedId!=="number"||!Number.isSafeInteger(K.lastReceivedId)||K.lastReceivedId<0)||"sessionId"in K&&typeof K.sessionId!=="string")throw Error("invalid params");$={lastReceivedId:Number(K.lastReceivedId??0),sessionId:typeof K.sessionId==="string"?K.sessionId:void 0}}}catch(K){if(K instanceof N)throw K;return G(400,{error:"invalid params"})}let{lastReceivedId:P,sessionId:A}=$;if(f.requireSession===!0&&!M(A))return G(400,{error:"session required"});if(A===void 0&&!Z)Z=!0,x.warn("rpc notification drain missing session id",{pid:process.pid});let W;if(f.drainAsync)try{W=await f.drainAsync(P,A)}catch(K){return x.warn("rpc notification drain failed",{pid:process.pid,error:K instanceof Error?K.message:String(K)}),G(500,{error:"drain failed"})}else W=f.drain?.(P,A);return G(200,{messages:W})}if(b==="apply"){let $=Promise.resolve(f.apply(F)),P=f.applyDeadlineMs===void 0?await $:await c($,f.applyDeadlineMs);return G(200,P)}return G(404,{error:"unknown method"})}catch(X){if(X instanceof N)return x.debug("rpc request refused",{pid:process.pid,status:X.status}),G(X.status,{error:X.message});if(X instanceof S)return x.warn("rpc apply deadline exceeded",{pid:process.pid,deadlineMs:f.applyDeadlineMs}),G(504,{error:"handler deadline exceeded"});x.warn("rpc request failed",{pid:process.pid,error:X instanceof Error?X.message:String(X)}),G(500,{error:"internal error"})}}let Q=await new Promise((V,J)=>{B.on("error",J),B.listen(0,"127.0.0.1",()=>{let G=B.address();if(G&&typeof G==="object")V(G.port);else J(Error("no port"))})});if(B.unref(),f.sweepRoot)try{await k(f.sweepRoot,f.dir,f.isManagedDir,x)}catch(V){x.warn("rpc state sweep failed",{pid:process.pid,error:V instanceof Error?V.message:String(V)})}try{await O(f.dir,{port:Q,token:z,pid:process.pid},{secureDir:f.secureDir}),x.debug("rpc server pid",{pid:process.pid,rpcPort:Q})}catch(V){throw await new Promise((J)=>B.close(()=>J())),V}return{port:Q,token:z,async stop(){await new Promise((G)=>{B.closeAllConnections?.(),B.close(()=>G());for(let X of L)X.destroy()});let V=l(f.dir,`port-${process.pid}.json`),J=await D(V).then((G)=>JSON.parse(G)).catch((G)=>{if(G instanceof h&&G.code!=="ENOENT")throw G;return});if(J?.port===Q&&J.token===z)await u(V).catch(()=>{})}}}async function Hf(f,x,z){let H=globalThis,Y=Symbol.for(f),Z=H[Y]??{servers:new Map,pending:new Map};H[Y]=Z;let{servers:L,pending:B}=Z,T=B.get(x)??Promise.resolve(),Q,V=T.catch(()=>{}).then(async()=>{let G=L.get(x);if(G){if(await G.stop(),L.get(x)===G)L.delete(x)}Q=await z(),L.set(x,Q)});B.set(x,V);try{await V}finally{if(B.get(x)===V)B.delete(x)}let J=Q;if(!J)throw Error("RPC server failed to start");return{server:J,release:async()=>{if(L.get(x)!==J)return;if(await J.stop(),L.get(x)===J)L.delete(x)}}}var R="1.17.2";function bf(f,x,z){let H={...x,version:R};return O(f,H,z)}var Cf=w(j);
|
|
2
|
-
export{i as jg,n as kg,a as lg,Bf as mg,Hf as ng,R as og,bf as pg,Cf as qg};
|