@cortexkit/opencode-openai-auth 1.17.0 → 1.18.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-CTIOw2EZ.d.ts} +322 -322
- package/dist/index-177kc3f1.js +64 -0
- package/dist/{index-k2f9vrcr.js → index-1r7zznds.js} +1 -1
- package/dist/{index-0mhdyzax.js → index-2ecf254a.js} +21 -21
- package/dist/index-5czcaan0.js +101 -0
- package/dist/index-5vh4jgb7.js +12 -0
- package/dist/index-96p0myg1.js +2 -0
- package/dist/{index-1m3vv9rh.js → index-9sh2xnwr.js} +2 -2
- package/dist/{index-d7bsrp0m.js → index-h7xxfm12.js} +1 -1
- package/dist/{index-vmcmpezd.js → index-hrv1msdb.js} +1 -1
- package/dist/index-m6sq5g7q.js +8 -0
- package/dist/{index-99c2fepe.js → index-nkgxq9a6.js} +1 -1
- package/dist/{index-fxqghceg.js → index-raj3tyyz.js} +1 -1
- package/dist/{index-6ts9w66n.js → index-rs8z3per.js} +1 -1
- package/dist/index-smekt6zv.js +2 -0
- 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-r3vbz9pw.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/0766d78c6f481f18-watcher.js +9 -2
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +1 -1
- package/src/tui-compiled/raw/shared/375d9cca2def037d-private-files.js +3 -1
- package/src/tui-compiled/raw/shared/44449e891fab9fbc-edit.js +48 -2
- package/src/tui-compiled/raw/shared/54eba94fd64c8c3c-index.js +1 -1
- package/src/tui-compiled/raw/shared/5f4bc45522ab9bc6-update.js +19 -18
- package/src/tui-compiled/raw/shared/6948d70969aa7a55-fs.js +1 -0
- 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 +57 -0
- package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +3 -0
- package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +9 -2
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +1 -1
- package/src/tui-compiled/runtime/shared/375d9cca2def037d-private-files.js +3 -1
- package/src/tui-compiled/runtime/shared/44449e891fab9fbc-edit.js +48 -2
- package/src/tui-compiled/runtime/shared/54eba94fd64c8c3c-index.js +1 -1
- package/src/tui-compiled/runtime/shared/5f4bc45522ab9bc6-update.js +19 -18
- package/src/tui-compiled/runtime/shared/6948d70969aa7a55-fs.js +1 -0
- 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 +57 -0
- package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +3 -0
- package/dist/index-3dv16qvb.js +0 -101
- package/dist/index-dqxk628t.js +0 -12
- package/dist/index-rm4zt5dv.js +0 -64
- package/dist/index-v9p38mg5.js +0 -2
- package/dist/index-xx2z6bs3.js +0 -2
- package/dist/index-ydtpn6ma.js +0 -8
- package/dist/token-util-vks3kgse.js +0 -1
|
@@ -37,7 +37,12 @@ function descriptorAtPath(descriptor, path) {
|
|
|
37
37
|
}
|
|
38
38
|
return current;
|
|
39
39
|
}
|
|
40
|
-
function destination(declaration, setting, value, { host, model }) {
|
|
40
|
+
function destination(declaration, setting, value, { host, model }, level) {
|
|
41
|
+
if (level !== undefined) {
|
|
42
|
+
return level === 'default' && !isJsonObject(value)
|
|
43
|
+
? [setting]
|
|
44
|
+
: [setting, level];
|
|
45
|
+
}
|
|
41
46
|
if (declaration.overrides !== undefined && isJsonObject(value)) {
|
|
42
47
|
if (declaration.overrides.model &&
|
|
43
48
|
model !== undefined &&
|
|
@@ -75,6 +80,20 @@ function checkPath(parsed, path) {
|
|
|
75
80
|
invalid();
|
|
76
81
|
}
|
|
77
82
|
}
|
|
83
|
+
function preservePlainDefault(parsed, setting) {
|
|
84
|
+
const node = parsed.tree && findNodeAtLocation(parsed.tree, [setting]);
|
|
85
|
+
if (!node)
|
|
86
|
+
invalid();
|
|
87
|
+
// Keep the original value text so comments inside a list survive promotion.
|
|
88
|
+
const value = parsed.text.slice(node.offset, node.offset + node.length);
|
|
89
|
+
return parseForEdit(applyEdits(parsed.text, [
|
|
90
|
+
{
|
|
91
|
+
offset: node.offset,
|
|
92
|
+
length: node.length,
|
|
93
|
+
content: `{ "default": ${value} }`,
|
|
94
|
+
},
|
|
95
|
+
]));
|
|
96
|
+
}
|
|
78
97
|
/** Remove only the member's own tokens; intervening comment lines belong to neither neighbor. */
|
|
79
98
|
function removeMember(text, tree, path) {
|
|
80
99
|
const property = tree && findNodeAtLocation(tree, path)?.parent;
|
|
@@ -157,6 +176,18 @@ export function applySettingsEdits(definition, source, edits, context) {
|
|
|
157
176
|
if (!Object.hasOwn(definition.settings, edit.setting))
|
|
158
177
|
invalid();
|
|
159
178
|
const declaration = definition.settings[edit.setting];
|
|
179
|
+
if (edit.level !== undefined) {
|
|
180
|
+
if (edit.path !== undefined)
|
|
181
|
+
invalid();
|
|
182
|
+
if (edit.level === 'default') {
|
|
183
|
+
if (declaration.overrides === undefined)
|
|
184
|
+
invalid();
|
|
185
|
+
}
|
|
186
|
+
else if ((edit.level !== 'opencode' && edit.level !== 'pi') ||
|
|
187
|
+
!declaration.overrides?.host) {
|
|
188
|
+
invalid();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
160
191
|
if (edit.path !== undefined &&
|
|
161
192
|
declaration.value.kind !== 'object' &&
|
|
162
193
|
declaration.value.kind !== 'record')
|
|
@@ -170,9 +201,24 @@ export function applySettingsEdits(definition, source, edits, context) {
|
|
|
170
201
|
const units = [];
|
|
171
202
|
for (const edit of edits) {
|
|
172
203
|
const declaration = definition.settings[edit.setting];
|
|
204
|
+
if (edit.level !== undefined &&
|
|
205
|
+
edit.level !== 'default' &&
|
|
206
|
+
!isJsonObject(working.value[edit.setting])) {
|
|
207
|
+
if (edit.remove === true)
|
|
208
|
+
continue;
|
|
209
|
+
if (Object.hasOwn(working.value, edit.setting)) {
|
|
210
|
+
working = preservePlainDefault(working, edit.setting);
|
|
211
|
+
}
|
|
212
|
+
// Earlier root edits now refer to the override's default, if it exists.
|
|
213
|
+
for (const unit of units) {
|
|
214
|
+
if (unit.path.length === 1 && unit.path[0] === edit.setting) {
|
|
215
|
+
unit.path.push('default');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
173
219
|
const base = edit.path !== undefined
|
|
174
220
|
? [edit.setting]
|
|
175
|
-
: destination(declaration, edit.setting, working.value[edit.setting], context);
|
|
221
|
+
: destination(declaration, edit.setting, working.value[edit.setting], context, edit.level);
|
|
176
222
|
const path = [...base, ...(edit.path ?? [])];
|
|
177
223
|
checkPath(working, path);
|
|
178
224
|
units.push(resolutionUnit(declaration.value, base, edit.path ?? []));
|
|
@@ -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";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { canonicalFilePath } from "./cf4c37f3975c3a8d-canonical-file-path.js";
|
|
2
3
|
import { ensurePrivateDirectory } from "./375d9cca2def037d-private-files.js";
|
|
3
4
|
import { withLock } from "./4825e03209d6ae3e-with-lock.js";
|
|
5
|
+
import { deepFreeze } from "./5803fadb30af0ec0-descriptors.js";
|
|
4
6
|
import { applySettingsEdits, } from "./44449e891fab9fbc-edit.js";
|
|
5
7
|
import { SettingsFs } from "./6948d70969aa7a55-fs.js";
|
|
6
8
|
import { rethrowSettingsLockError } from "./eac0bed49f3d4110-lock-errors.js";
|
|
@@ -18,25 +20,9 @@ function unavailable(file, cause) {
|
|
|
18
20
|
}
|
|
19
21
|
async function writeTarget(file) {
|
|
20
22
|
try {
|
|
21
|
-
return await
|
|
23
|
+
return await canonicalFilePath(file, SettingsFs);
|
|
22
24
|
}
|
|
23
25
|
catch (error) {
|
|
24
|
-
if (error.code !== 'ENOENT')
|
|
25
|
-
unavailable(file, error);
|
|
26
|
-
try {
|
|
27
|
-
await SettingsFs.lstat(file);
|
|
28
|
-
}
|
|
29
|
-
catch (lstatError) {
|
|
30
|
-
if (lstatError.code !== 'ENOENT')
|
|
31
|
-
unavailable(file, lstatError);
|
|
32
|
-
try {
|
|
33
|
-
return join(await SettingsFs.realpath(dirname(file)), basename(file));
|
|
34
|
-
}
|
|
35
|
-
catch (parentError) {
|
|
36
|
-
unavailable(file, parentError);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// A directory entry whose realpath is missing is a dangling symlink.
|
|
40
26
|
unavailable(file, error);
|
|
41
27
|
}
|
|
42
28
|
}
|
|
@@ -97,6 +83,21 @@ export async function updateSettings(definition, options, edits, context) {
|
|
|
97
83
|
if (Number.isInteger(version) && version > 1) {
|
|
98
84
|
throw new SettingsRefusal('settings-newer-version', 'Settings were written by a newer version');
|
|
99
85
|
}
|
|
86
|
+
if (typeof edits === 'function') {
|
|
87
|
+
const planned = edits(deepFreeze(missing
|
|
88
|
+
? { status: 'missing' }
|
|
89
|
+
: {
|
|
90
|
+
status: 'ready',
|
|
91
|
+
document: structuredClone(parsed.value),
|
|
92
|
+
}));
|
|
93
|
+
if (planned !== null &&
|
|
94
|
+
(typeof planned === 'object' || typeof planned === 'function') &&
|
|
95
|
+
'then' in planned &&
|
|
96
|
+
typeof planned.then === 'function') {
|
|
97
|
+
throw new SettingsRefusal('settings-invalid-value', 'Settings update plans must be synchronous');
|
|
98
|
+
}
|
|
99
|
+
edits = planned;
|
|
100
|
+
}
|
|
100
101
|
if (!parsed.tree) {
|
|
101
102
|
source = `${parsed.hasBom ? '\uFEFF' : ''}// ${definition.plugin} settings\n{\n "schema_version": 1\n}\n`;
|
|
102
103
|
}
|
|
@@ -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 = {}) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
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
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Canonical path of a file that other processes may replace by write-and-rename.
|
|
9
|
+
*
|
|
10
|
+
* On Linux, Bun's realpath on such a file can answer "<file> (deleted)" (Bun
|
|
11
|
+
* 1.3) or ENOENT (Bun 1.4) during the rename. So this resolves the folder with
|
|
12
|
+
* realpath and appends the name, then follows a file symlink one readlink hop at
|
|
13
|
+
* a time, at most 40 hops. A missing file resolves to its would-be path; a
|
|
14
|
+
* dangling link or a loop throws. Pass `node:fs/promises` (or a test double).
|
|
15
|
+
*/
|
|
16
|
+
export async function canonicalFilePath(file, fs) {
|
|
17
|
+
let target = file;
|
|
18
|
+
for (let hops = 0;; hops++) {
|
|
19
|
+
// Bun can report an unlinked inode's " (deleted)" name for realpath(file).
|
|
20
|
+
target = join(await fs.realpath(dirname(target)), basename(target));
|
|
21
|
+
let isSymlink;
|
|
22
|
+
try {
|
|
23
|
+
isSymlink = (await fs.lstat(target)).isSymbolicLink();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT' && hops === 0)
|
|
27
|
+
return target;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
if (!isSymlink)
|
|
31
|
+
return target;
|
|
32
|
+
if (hops >= maxSymlinkHops)
|
|
33
|
+
throw symlinkLoop(file);
|
|
34
|
+
target = resolve(dirname(target), await fs.readlink(target));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Synchronous counterpart of canonicalFilePath; pass `node:fs`. */
|
|
38
|
+
export function canonicalFilePathSync(file, fs) {
|
|
39
|
+
let target = file;
|
|
40
|
+
for (let hops = 0;; hops++) {
|
|
41
|
+
target = join(fs.realpathSync(dirname(target)), basename(target));
|
|
42
|
+
let isSymlink;
|
|
43
|
+
try {
|
|
44
|
+
isSymlink = fs.lstatSync(target).isSymbolicLink();
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.code === 'ENOENT' && hops === 0)
|
|
48
|
+
return target;
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
if (!isSymlink)
|
|
52
|
+
return target;
|
|
53
|
+
if (hops >= maxSymlinkHops)
|
|
54
|
+
throw symlinkLoop(file);
|
|
55
|
+
target = resolve(dirname(target), fs.readlinkSync(target));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { writeJsonAtomic } from "./7211cfec06a298bc-atomic-write.js";
|
|
2
|
+
// Canonical path of a file other processes may atomically replace: resolves
|
|
3
|
+
// the folder, never the file itself (see canonical-file-path.ts).
|
|
4
|
+
export { canonicalFilePath, canonicalFilePathSync, } from "./cf4c37f3975c3a8d-canonical-file-path.js";
|
|
2
5
|
export { WRITER_LOCK_CONSTANTS } from "./9b4da614c45f9cd0-lock-constants.js";
|
|
3
6
|
export { PrivateFileError } from "./375d9cca2def037d-private-files.js";
|
|
4
7
|
// The try-once lock underneath withLock, for callers that hold a lock across
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { readFileSync, realpathSync, statSync, watch, } from "node:fs";
|
|
1
|
+
import { lstatSync, readFileSync, readlinkSync, 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 { canonicalFilePathSync } from "./cf4c37f3975c3a8d-canonical-file-path.js";
|
|
5
6
|
import { PrivateFileError, readPrivateText, windowsPrivateFiles, } from "./375d9cca2def037d-private-files.js";
|
|
7
|
+
const pathFsDefaults = { lstatSync, readlinkSync, realpathSync };
|
|
8
|
+
const pathFs = { ...pathFsDefaults };
|
|
9
|
+
/** Internal test hook; omitted path operations use the native implementation. */
|
|
10
|
+
export function setTuiPreferencesPathFsForTest(overrides) {
|
|
11
|
+
Object.assign(pathFs, pathFsDefaults, overrides);
|
|
12
|
+
}
|
|
6
13
|
function canonicalPath(file) {
|
|
7
14
|
const path = resolve(file);
|
|
8
15
|
// Leave reparse points in the path for private-files' ancestor walk to reject;
|
|
@@ -10,7 +17,7 @@ function canonicalPath(file) {
|
|
|
10
17
|
if (windowsPrivateFiles)
|
|
11
18
|
return path;
|
|
12
19
|
try {
|
|
13
|
-
return
|
|
20
|
+
return canonicalFilePathSync(path, pathFs);
|
|
14
21
|
}
|
|
15
22
|
catch {
|
|
16
23
|
// Resolve existing ancestors even when the preferences file is not yet present.
|
|
@@ -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
|
});
|
|
@@ -37,7 +37,12 @@ function descriptorAtPath(descriptor, path) {
|
|
|
37
37
|
}
|
|
38
38
|
return current;
|
|
39
39
|
}
|
|
40
|
-
function destination(declaration, setting, value, { host, model }) {
|
|
40
|
+
function destination(declaration, setting, value, { host, model }, level) {
|
|
41
|
+
if (level !== undefined) {
|
|
42
|
+
return level === 'default' && !isJsonObject(value)
|
|
43
|
+
? [setting]
|
|
44
|
+
: [setting, level];
|
|
45
|
+
}
|
|
41
46
|
if (declaration.overrides !== undefined && isJsonObject(value)) {
|
|
42
47
|
if (declaration.overrides.model &&
|
|
43
48
|
model !== undefined &&
|
|
@@ -75,6 +80,20 @@ function checkPath(parsed, path) {
|
|
|
75
80
|
invalid();
|
|
76
81
|
}
|
|
77
82
|
}
|
|
83
|
+
function preservePlainDefault(parsed, setting) {
|
|
84
|
+
const node = parsed.tree && findNodeAtLocation(parsed.tree, [setting]);
|
|
85
|
+
if (!node)
|
|
86
|
+
invalid();
|
|
87
|
+
// Keep the original value text so comments inside a list survive promotion.
|
|
88
|
+
const value = parsed.text.slice(node.offset, node.offset + node.length);
|
|
89
|
+
return parseForEdit(applyEdits(parsed.text, [
|
|
90
|
+
{
|
|
91
|
+
offset: node.offset,
|
|
92
|
+
length: node.length,
|
|
93
|
+
content: `{ "default": ${value} }`,
|
|
94
|
+
},
|
|
95
|
+
]));
|
|
96
|
+
}
|
|
78
97
|
/** Remove only the member's own tokens; intervening comment lines belong to neither neighbor. */
|
|
79
98
|
function removeMember(text, tree, path) {
|
|
80
99
|
const property = tree && findNodeAtLocation(tree, path)?.parent;
|
|
@@ -157,6 +176,18 @@ export function applySettingsEdits(definition, source, edits, context) {
|
|
|
157
176
|
if (!Object.hasOwn(definition.settings, edit.setting))
|
|
158
177
|
invalid();
|
|
159
178
|
const declaration = definition.settings[edit.setting];
|
|
179
|
+
if (edit.level !== undefined) {
|
|
180
|
+
if (edit.path !== undefined)
|
|
181
|
+
invalid();
|
|
182
|
+
if (edit.level === 'default') {
|
|
183
|
+
if (declaration.overrides === undefined)
|
|
184
|
+
invalid();
|
|
185
|
+
}
|
|
186
|
+
else if ((edit.level !== 'opencode' && edit.level !== 'pi') ||
|
|
187
|
+
!declaration.overrides?.host) {
|
|
188
|
+
invalid();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
160
191
|
if (edit.path !== undefined &&
|
|
161
192
|
declaration.value.kind !== 'object' &&
|
|
162
193
|
declaration.value.kind !== 'record')
|
|
@@ -170,9 +201,24 @@ export function applySettingsEdits(definition, source, edits, context) {
|
|
|
170
201
|
const units = [];
|
|
171
202
|
for (const edit of edits) {
|
|
172
203
|
const declaration = definition.settings[edit.setting];
|
|
204
|
+
if (edit.level !== undefined &&
|
|
205
|
+
edit.level !== 'default' &&
|
|
206
|
+
!isJsonObject(working.value[edit.setting])) {
|
|
207
|
+
if (edit.remove === true)
|
|
208
|
+
continue;
|
|
209
|
+
if (Object.hasOwn(working.value, edit.setting)) {
|
|
210
|
+
working = preservePlainDefault(working, edit.setting);
|
|
211
|
+
}
|
|
212
|
+
// Earlier root edits now refer to the override's default, if it exists.
|
|
213
|
+
for (const unit of units) {
|
|
214
|
+
if (unit.path.length === 1 && unit.path[0] === edit.setting) {
|
|
215
|
+
unit.path.push('default');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
173
219
|
const base = edit.path !== undefined
|
|
174
220
|
? [edit.setting]
|
|
175
|
-
: destination(declaration, edit.setting, working.value[edit.setting], context);
|
|
221
|
+
: destination(declaration, edit.setting, working.value[edit.setting], context, edit.level);
|
|
176
222
|
const path = [...base, ...(edit.path ?? [])];
|
|
177
223
|
checkPath(working, path);
|
|
178
224
|
units.push(resolutionUnit(declaration.value, base, edit.path ?? []));
|
|
@@ -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";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { canonicalFilePath } from "./cf4c37f3975c3a8d-canonical-file-path.js";
|
|
2
3
|
import { ensurePrivateDirectory } from "./375d9cca2def037d-private-files.js";
|
|
3
4
|
import { withLock } from "./4825e03209d6ae3e-with-lock.js";
|
|
5
|
+
import { deepFreeze } from "./5803fadb30af0ec0-descriptors.js";
|
|
4
6
|
import { applySettingsEdits, } from "./44449e891fab9fbc-edit.js";
|
|
5
7
|
import { SettingsFs } from "./6948d70969aa7a55-fs.js";
|
|
6
8
|
import { rethrowSettingsLockError } from "./eac0bed49f3d4110-lock-errors.js";
|
|
@@ -18,25 +20,9 @@ function unavailable(file, cause) {
|
|
|
18
20
|
}
|
|
19
21
|
async function writeTarget(file) {
|
|
20
22
|
try {
|
|
21
|
-
return await
|
|
23
|
+
return await canonicalFilePath(file, SettingsFs);
|
|
22
24
|
}
|
|
23
25
|
catch (error) {
|
|
24
|
-
if (error.code !== 'ENOENT')
|
|
25
|
-
unavailable(file, error);
|
|
26
|
-
try {
|
|
27
|
-
await SettingsFs.lstat(file);
|
|
28
|
-
}
|
|
29
|
-
catch (lstatError) {
|
|
30
|
-
if (lstatError.code !== 'ENOENT')
|
|
31
|
-
unavailable(file, lstatError);
|
|
32
|
-
try {
|
|
33
|
-
return join(await SettingsFs.realpath(dirname(file)), basename(file));
|
|
34
|
-
}
|
|
35
|
-
catch (parentError) {
|
|
36
|
-
unavailable(file, parentError);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// A directory entry whose realpath is missing is a dangling symlink.
|
|
40
26
|
unavailable(file, error);
|
|
41
27
|
}
|
|
42
28
|
}
|
|
@@ -97,6 +83,21 @@ export async function updateSettings(definition, options, edits, context) {
|
|
|
97
83
|
if (Number.isInteger(version) && version > 1) {
|
|
98
84
|
throw new SettingsRefusal('settings-newer-version', 'Settings were written by a newer version');
|
|
99
85
|
}
|
|
86
|
+
if (typeof edits === 'function') {
|
|
87
|
+
const planned = edits(deepFreeze(missing
|
|
88
|
+
? { status: 'missing' }
|
|
89
|
+
: {
|
|
90
|
+
status: 'ready',
|
|
91
|
+
document: structuredClone(parsed.value),
|
|
92
|
+
}));
|
|
93
|
+
if (planned !== null &&
|
|
94
|
+
(typeof planned === 'object' || typeof planned === 'function') &&
|
|
95
|
+
'then' in planned &&
|
|
96
|
+
typeof planned.then === 'function') {
|
|
97
|
+
throw new SettingsRefusal('settings-invalid-value', 'Settings update plans must be synchronous');
|
|
98
|
+
}
|
|
99
|
+
edits = planned;
|
|
100
|
+
}
|
|
100
101
|
if (!parsed.tree) {
|
|
101
102
|
source = `${parsed.hasBom ? '\uFEFF' : ''}// ${definition.plugin} settings\n{\n "schema_version": 1\n}\n`;
|
|
102
103
|
}
|
|
@@ -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;
|