@sema-agent/settings-schema 33.1.0 → 34.1.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/CHANGELOG.md +664 -0
- package/README.md +138 -19
- package/conformance/VERSION +1 -1
- package/dist/api/credentials.d.ts +94 -14
- package/dist/api/credentials.js +33 -8
- package/dist/atomic-write.d.ts +68 -3
- package/dist/atomic-write.js +314 -4
- package/dist/cli.d.ts +5 -2
- package/dist/cli.js +15 -3
- package/dist/config-d-file.d.ts +0 -3
- package/dist/config-d-file.js +1 -6
- package/dist/config-dir-migration.d.ts +2 -1
- package/dist/config-dir-migration.js +34 -20
- package/dist/config-fns.d.ts +60 -14
- package/dist/config-fns.js +48 -13
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/warnings.d.ts +1 -1
- package/dist/conformance/warnings.js +3 -3
- package/dist/conformance/web-admin-credential-lock.d.ts +17 -0
- package/dist/conformance/web-admin-credential-lock.js +347 -0
- package/dist/hooks-config.d.ts +12 -4
- package/dist/hooks-config.js +28 -11
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -2
- package/dist/local-load.d.ts +66 -1
- package/dist/local-load.js +123 -39
- package/dist/mcp-request-entry.d.ts +43 -5
- package/dist/mcp-request-entry.js +60 -18
- package/dist/node.d.ts +1 -0
- package/dist/node.js +2 -0
- package/dist/plugin-id-segment.d.ts +15 -0
- package/dist/plugin-id-segment.js +15 -0
- package/dist/plugin-settings.d.ts +61 -0
- package/dist/plugin-settings.js +111 -0
- package/dist/read-sentences.d.ts +14 -3
- package/dist/read-sentences.js +32 -11
- package/dist/safety-merge-spec.d.ts +7 -7
- package/dist/safety-merge-spec.js +5 -3
- package/dist/settings-units.d.ts +35 -1
- package/dist/settings-units.js +51 -16
- package/dist/types.d.ts +13 -6
- package/dist/types.js +37 -11
- package/dist/ui-language.d.ts +3 -1
- package/dist/ui-language.js +3 -1
- package/dist/web-admin-credential.d.ts +14 -1
- package/dist/web-admin-credential.js +15 -1
- package/docs/API-SURFACE.md +60 -5
- package/docs/CONFORMANCE.md +19 -2
- package/docs/CONSUMER-INTEGRATION.md +165 -11
- package/llms-full.txt +51 -16
- package/llms.txt +18 -8
- package/package.json +5 -1
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-admin 凭证文件单写者锁的**协议一致性测试**(随包、可被别的实现复用):一份协议、一份判据。
|
|
3
|
+
*
|
|
4
|
+
* 别的实现(壳若不调本包 `./node` 的 `tryWebAdminCredentialFileLock`、自己写一份)把它交给 {@link runWebAdminCredentialLockConformance}:签名必须与本包原语逐字同
|
|
5
|
+
* ({@link WebAdminCredentialLockImplementation}),kit 在私有临时根里逐格跑黑盒场景(只经文件系统观察:锁文件在哪、是谁、留没留残件、凭证文件的内容),答一份报告。
|
|
6
|
+
* 「两份实现各自声明合规」不算数 —— 过这份 kit 才算。
|
|
7
|
+
*
|
|
8
|
+
* 每格造一个新的临时根(与语料 kit 同一只铸点、同一套残留收口),格里的凭证文件在根下的 `c/` 里;格跑完根整个删掉。
|
|
9
|
+
* kit 扮「另一个写者」时只做协议里另一个写者会做的事:按协议建锁;接手 = 协议里的收残留(把锁**改名挪开**、删掉挪开件,再建自己的锁)—— 从不按路径删锁、不等待。
|
|
10
|
+
* 看不到的东西不判:只试一次的「次数」、收残留的交错、身份取自 fd 且 fd 钉到放锁 —— 这些要注入系统调用才能排出来,在本包自己的白盒钉里(黑盒里只量「忙时不等待」的耗时上界)。
|
|
11
|
+
* 「失锁」两格(锁被换成继任者)对一只不钉 fd 的实现是概率性的:继任者的锁恰好复用了持有者那只的 inode 号时,那样的实现会读成「仍是自己的」。
|
|
12
|
+
* 锁名被命名管道 / 悬空软链占着的两种形在本包自己的白盒钉里(命名管道要放进可超时终止的子进程,黑盒格里不造);黑盒里用目录代表「锁名上不是普通文件」那一类,答案是同一个。
|
|
13
|
+
* 悬空软链(链接在、目标不在 —— 经软链到达的凭据文件登出之后的样子)是**失败关闭**:`unreadable`、不建文件、不写。这是本版协议的答案,也是已知限制(登出后再登录写不进去;出路 = 删掉悬空链接或先重建目标):
|
|
14
|
+
* 本版不解析悬空链接的落点 —— 要做就得改原子写器对悬空链接的拒律(不替链接建它指向的文件),那是另一份设计、按大版本排。
|
|
15
|
+
* 本包原语对这一形答的 `unreadable` 多一个可缺的诊断位 `ioKind`(`dangling_symlink`),这份 kit 不判它:别的实现不带这一键也过。
|
|
16
|
+
* 已知范围:软链两格(写穿 · 悬空)要求宿主允许建符号链接(Windows 上普通用户默认不允许,那两格会以「建链接失败」红)。
|
|
17
|
+
*/
|
|
18
|
+
import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { basename, dirname, join } from "node:path";
|
|
20
|
+
import { performance } from "node:perf_hooks";
|
|
21
|
+
import { removeLockIf } from "../atomic-write.js";
|
|
22
|
+
import { WEB_ADMIN_CREDENTIAL_FILE_LOCK, webAdminCredentialLockName } from "../web-admin-credential.js";
|
|
23
|
+
import { mintLocalRoot, removeLocalRoot } from "./temp-roots.js";
|
|
24
|
+
const STALE = WEB_ADMIN_CREDENTIAL_FILE_LOCK.staleMs;
|
|
25
|
+
/** 「忙时不等待」的耗时上界(毫秒,单调钟):只为抓「先等一会儿再答」的实现,留足慢盘余量。一只正确的实现在调用期间被宿主调度停住超过它,这一格会红 —— 那是宿主读数,不是协议结论:重跑一次分得开。 */
|
|
26
|
+
const BUSY_ANSWER_BOUND_MS = 1000;
|
|
27
|
+
function check(cond, why) {
|
|
28
|
+
if (!cond)
|
|
29
|
+
throw new Error(why);
|
|
30
|
+
}
|
|
31
|
+
const lockOf = (file) => join(dirname(file), webAdminCredentialLockName(basename(file)));
|
|
32
|
+
const inoOf = (p) => statSync(p, { bigint: true }).ino;
|
|
33
|
+
const entries = (dir) => readdirSync(dir).sort().join(", ");
|
|
34
|
+
/** 按协议建一只别人的锁,mtime 拨到 `ageMs` 之前(负数 = 未来);返回它的 inode。 */
|
|
35
|
+
function plantLock(p, ageMs) {
|
|
36
|
+
closeSync(openSync(p, "wx"));
|
|
37
|
+
const t = (Date.now() - ageMs) / 1000;
|
|
38
|
+
utimesSync(p, t, t);
|
|
39
|
+
return inoOf(p);
|
|
40
|
+
}
|
|
41
|
+
/** 另一个写者接手 `target` 的锁:按协议收残留 —— 走包里收 / 放锁的**那一套动作**(`removeLockIf`:把锁改名挪开、核挪走的是不是此刻在路径上的那一只、删挪开件;从不按路径删锁)—— 再建自己的锁;返回它的 inode。 */
|
|
42
|
+
function takeOver(target) {
|
|
43
|
+
const lock = lockOf(target);
|
|
44
|
+
const held = statSync(lock, { bigint: true });
|
|
45
|
+
removeLockIf(lock, { dev: held.dev, ino: held.ino });
|
|
46
|
+
return plantLock(lock, 0);
|
|
47
|
+
}
|
|
48
|
+
function writeCredential(dir) {
|
|
49
|
+
const cred = join(dir, "credential");
|
|
50
|
+
writeFileSync(cred, "R1");
|
|
51
|
+
return cred;
|
|
52
|
+
}
|
|
53
|
+
function expectBusyUntouched(impl, dir, ageMs) {
|
|
54
|
+
const cred = writeCredential(dir);
|
|
55
|
+
const lock = lockOf(cred);
|
|
56
|
+
const ino = plantLock(lock, ageMs);
|
|
57
|
+
let ran = false;
|
|
58
|
+
const started = performance.now(); // 单调钟:墙钟被拨动不影响这只量
|
|
59
|
+
const r = impl(cred, () => {
|
|
60
|
+
ran = true;
|
|
61
|
+
});
|
|
62
|
+
const elapsed = Math.round(performance.now() - started);
|
|
63
|
+
check(r.status === "busy", `a lock aged ${ageMs} ms answered ${r.status}, expected busy`);
|
|
64
|
+
check(!ran, "the callback ran while another writer held the lock");
|
|
65
|
+
check(existsSync(lock) && inoOf(lock) === ino, "the other writer's lock was moved or replaced");
|
|
66
|
+
check(r.heldForMs === undefined || (r.heldForMs >= 0 && r.heldForMs <= STALE), `heldForMs ${String(r.heldForMs)} is outside 0..staleMs`);
|
|
67
|
+
check(elapsed < BUSY_ANSWER_BOUND_MS, `busy took ${elapsed} ms — the lock is tried once and never waited for`);
|
|
68
|
+
}
|
|
69
|
+
const CASES = [
|
|
70
|
+
[
|
|
71
|
+
"free-acquires",
|
|
72
|
+
(impl, _root, dir) => {
|
|
73
|
+
const cred = writeCredential(dir);
|
|
74
|
+
const r = impl(cred, (held) => ({ current: held.current, lockThere: existsSync(lockOf(held.target)), mine: held.stillMine(), same: realpathSync(held.target) === realpathSync(cred) }));
|
|
75
|
+
check(r.status === "acquired", `answered ${r.status}, expected acquired`);
|
|
76
|
+
check(r.value.current === "R1", "the callback did not get the credential text read under the lock");
|
|
77
|
+
check(r.value.lockThere, "no lock file named .<file>.lock beside the target while held");
|
|
78
|
+
check(r.value.mine, "stillMine() was false for an undisturbed holder");
|
|
79
|
+
check(r.value.same, "held.target is not the credential file");
|
|
80
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
["fresh-lock-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, 0)],
|
|
84
|
+
["future-mtime-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, -60_000)],
|
|
85
|
+
["young-lock-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, STALE / 2)],
|
|
86
|
+
[
|
|
87
|
+
"stale-lock-is-reclaimed",
|
|
88
|
+
(impl, _root, dir) => {
|
|
89
|
+
const cred = writeCredential(dir);
|
|
90
|
+
const lock = lockOf(cred);
|
|
91
|
+
const old = plantLock(lock, STALE + 5000);
|
|
92
|
+
const keepOld = openSync(lock, "r"); // 钉住残留那个文件对象:它被删后 inode 号不会被新锁复用,「不是同一只」的比对才成立
|
|
93
|
+
try {
|
|
94
|
+
const r = impl(cred, () => (existsSync(lock) ? inoOf(lock) : undefined));
|
|
95
|
+
check(r.status === "acquired", `a lock older than staleMs answered ${r.status}, expected acquired`);
|
|
96
|
+
check(r.value !== undefined && r.value !== old, "the holder did not hold a lock of its own");
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
closeSync(keepOld);
|
|
100
|
+
}
|
|
101
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"lost-when-replaced",
|
|
106
|
+
(impl, _root, dir) => {
|
|
107
|
+
const cred = writeCredential(dir);
|
|
108
|
+
const lock = lockOf(cred);
|
|
109
|
+
const tmp = join(dir, "kit-next.tmp");
|
|
110
|
+
const r = impl(cred, (held) => {
|
|
111
|
+
const successor = takeOver(held.target); // another writer took the lock over (the protocol's reclaim) and holds a lock of its own
|
|
112
|
+
const mine = held.stillMine();
|
|
113
|
+
writeFileSync(tmp, "R2");
|
|
114
|
+
return { successor, mine, wrote: held.replaceWith(tmp) };
|
|
115
|
+
});
|
|
116
|
+
check(r.status === "lost", `answered ${r.status}, expected lost`);
|
|
117
|
+
check(!r.value.mine, "stillMine() was true after the lock was replaced");
|
|
118
|
+
check(!r.value.wrote, "replaceWith() wrote after the lock was replaced");
|
|
119
|
+
check(readFileSync(cred, "utf8") === "R1", "the credential changed without the lock");
|
|
120
|
+
check(existsSync(tmp), "the caller's temporary file was consumed");
|
|
121
|
+
check(existsSync(lock) && inoOf(lock) === r.value.successor, "the successor's lock was removed or replaced on release");
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
"replace-after-loss-unchecked",
|
|
126
|
+
(impl, _root, dir) => {
|
|
127
|
+
const cred = writeCredential(dir);
|
|
128
|
+
const tmp = join(dir, "kit-next.tmp");
|
|
129
|
+
const r = impl(cred, (held) => {
|
|
130
|
+
takeOver(held.target); // another writer holds the lock now; the callback does not ask stillMine() first
|
|
131
|
+
writeFileSync(tmp, "R2");
|
|
132
|
+
return held.replaceWith(tmp);
|
|
133
|
+
});
|
|
134
|
+
check(r.status === "lost", `answered ${r.status}, expected lost`);
|
|
135
|
+
check(!r.value, "replaceWith() wrote without checking the lock itself");
|
|
136
|
+
check(readFileSync(cred, "utf8") === "R1", "the credential changed without the lock");
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
"remove-after-loss-unchecked",
|
|
141
|
+
(impl, _root, dir) => {
|
|
142
|
+
const cred = writeCredential(dir);
|
|
143
|
+
const r = impl(cred, (held) => {
|
|
144
|
+
takeOver(held.target); // another writer holds the lock now; the callback does not ask stillMine() first
|
|
145
|
+
return held.remove();
|
|
146
|
+
});
|
|
147
|
+
check(r.status === "lost", `answered ${r.status}, expected lost`);
|
|
148
|
+
check(!r.value, "remove() deleted without checking the lock itself");
|
|
149
|
+
check(existsSync(cred), "the credential was removed without the lock");
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
"replace-writes-through-link",
|
|
154
|
+
(impl, root, dir) => {
|
|
155
|
+
const d = join(root, "d");
|
|
156
|
+
mkdirSync(d);
|
|
157
|
+
const realFile = join(d, "real");
|
|
158
|
+
writeFileSync(realFile, "R1");
|
|
159
|
+
const link = join(dir, "credential");
|
|
160
|
+
symlinkSync(realFile, link);
|
|
161
|
+
const r = impl(link, (held) => {
|
|
162
|
+
const seen = {
|
|
163
|
+
besideTarget: existsSync(join(d, webAdminCredentialLockName("real"))),
|
|
164
|
+
besideLink: existsSync(join(dir, webAdminCredentialLockName("credential"))),
|
|
165
|
+
targetIsLink: lstatSync(held.target).isSymbolicLink(),
|
|
166
|
+
same: realpathSync(held.target) === realpathSync(realFile),
|
|
167
|
+
};
|
|
168
|
+
const tmp = join(dirname(held.target), "kit-next.tmp");
|
|
169
|
+
writeFileSync(tmp, "R2");
|
|
170
|
+
return { ...seen, wrote: held.replaceWith(tmp) };
|
|
171
|
+
});
|
|
172
|
+
check(r.status === "acquired", `answered ${r.status}, expected acquired`);
|
|
173
|
+
check(r.value.wrote, "replaceWith() did not land for an undisturbed holder");
|
|
174
|
+
check(r.value.besideTarget, "no lock beside the link's real target");
|
|
175
|
+
check(!r.value.besideLink, "a lock beside the link itself");
|
|
176
|
+
check(!r.value.targetIsLink && r.value.same, "held.target is not the link's real target");
|
|
177
|
+
check(lstatSync(link).isSymbolicLink(), "the link was replaced by a regular file");
|
|
178
|
+
check(readFileSync(realFile, "utf8") === "R2", "the real target was not written");
|
|
179
|
+
check(entries(dir) === "credential" && entries(d) === "real", `left behind: ${entries(dir)} | ${entries(d)}`);
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
[
|
|
183
|
+
"dangling-link-is-unreadable",
|
|
184
|
+
(impl, root, dir) => {
|
|
185
|
+
const link = join(dir, "credential");
|
|
186
|
+
symlinkSync(join(root, "gone"), link); // the link's target does not exist (what a logout through a link leaves behind): fail closed — nothing is created, nothing is written through it
|
|
187
|
+
let ran = false;
|
|
188
|
+
const r = impl(link, () => {
|
|
189
|
+
ran = true;
|
|
190
|
+
});
|
|
191
|
+
check(r.status === "unreadable", `a dangling link answered ${r.status}, expected unreadable`);
|
|
192
|
+
check(!ran, "the callback ran through a dangling link");
|
|
193
|
+
check(entries(dir) === "credential" && !existsSync(join(root, "gone")), `left behind: ${entries(dir)} | ${existsSync(join(root, "gone")) ? "a file at the link's target" : "nothing at the link's target"}`);
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
[
|
|
197
|
+
"remove-under-lock",
|
|
198
|
+
(impl, _root, dir) => {
|
|
199
|
+
const cred = writeCredential(dir);
|
|
200
|
+
const r = impl(cred, (held) => held.remove());
|
|
201
|
+
check(r.status === "acquired" && r.value, `answered ${r.status}, expected acquired with the removal landed`);
|
|
202
|
+
check(entries(dir) === "", `left behind: ${entries(dir)}`);
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
[
|
|
206
|
+
"absent-target-reads-undefined",
|
|
207
|
+
(impl, _root, dir) => {
|
|
208
|
+
const r = impl(join(dir, "credential"), (held) => held.current === undefined);
|
|
209
|
+
check(r.status === "acquired" && r.value, `answered ${r.status}; an absent target is read as undefined under the lock`);
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
[
|
|
213
|
+
"critical-throws-releases",
|
|
214
|
+
(impl, _root, dir) => {
|
|
215
|
+
const cred = writeCredential(dir);
|
|
216
|
+
const sentinel = new Error("kit sentinel");
|
|
217
|
+
let caught;
|
|
218
|
+
try {
|
|
219
|
+
impl(cred, () => {
|
|
220
|
+
throw sentinel;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
caught = e;
|
|
225
|
+
}
|
|
226
|
+
check(caught === sentinel, "the callback's error was not rethrown as it was");
|
|
227
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
[
|
|
231
|
+
"thenable-is-refused",
|
|
232
|
+
(impl, _root, dir) => {
|
|
233
|
+
const cred = writeCredential(dir);
|
|
234
|
+
const sneaky = () => Promise.resolve();
|
|
235
|
+
let caught;
|
|
236
|
+
try {
|
|
237
|
+
impl(cred, sneaky);
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
caught = e;
|
|
241
|
+
}
|
|
242
|
+
check(caught instanceof TypeError, "a callback that returned a promise was not refused with a TypeError");
|
|
243
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
"handle-expires-on-return",
|
|
248
|
+
(impl, _root, dir) => {
|
|
249
|
+
const cred = writeCredential(dir);
|
|
250
|
+
const r = impl(cred, (held) => held);
|
|
251
|
+
check(r.status === "acquired", `answered ${r.status}, expected acquired`);
|
|
252
|
+
const kept = r.value;
|
|
253
|
+
const tmp = join(dir, "kit-late.tmp");
|
|
254
|
+
writeFileSync(tmp, "R2");
|
|
255
|
+
const answers = ["stillMine", "replaceWith", "remove"].filter((method) => {
|
|
256
|
+
try {
|
|
257
|
+
if (method === "stillMine")
|
|
258
|
+
kept.stillMine();
|
|
259
|
+
else if (method === "replaceWith")
|
|
260
|
+
kept.replaceWith(tmp);
|
|
261
|
+
else
|
|
262
|
+
kept.remove();
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
check(answers.length === 0, `the handle still answered after the callback returned: ${answers.join(", ")}`);
|
|
270
|
+
check(readFileSync(cred, "utf8") === "R1", "a late call on the handle changed the credential");
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
[
|
|
274
|
+
"unreadable-target",
|
|
275
|
+
(impl, _root, dir) => {
|
|
276
|
+
mkdirSync(join(dir, "credential"));
|
|
277
|
+
let ran = false;
|
|
278
|
+
const r = impl(join(dir, "credential"), () => {
|
|
279
|
+
ran = true;
|
|
280
|
+
});
|
|
281
|
+
check(r.status === "unreadable", `a target that cannot be read answered ${r.status}, expected unreadable`);
|
|
282
|
+
check(!ran, "the callback ran without a readable target");
|
|
283
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
[
|
|
287
|
+
"non-file-lock-name-is-unreadable",
|
|
288
|
+
(impl, _root, dir) => {
|
|
289
|
+
const cred = writeCredential(dir);
|
|
290
|
+
const lock = lockOf(cred);
|
|
291
|
+
mkdirSync(lock); // something that is not a regular file holds the lock's name (a directory here — a named pipe or a link is the same answer, pinned beside the package's own implementation)
|
|
292
|
+
let ran = false;
|
|
293
|
+
const started = performance.now();
|
|
294
|
+
const r = impl(cred, () => {
|
|
295
|
+
ran = true;
|
|
296
|
+
});
|
|
297
|
+
const elapsed = Math.round(performance.now() - started);
|
|
298
|
+
check(r.status === "unreadable", `a lock name held by a directory answered ${r.status}, expected unreadable (it cannot be a lock: not busy, not stale, not waited for)`);
|
|
299
|
+
check(!ran, "the callback ran although the lock name is not a lock");
|
|
300
|
+
check(lstatSync(lock).isDirectory(), "the entry on the lock's name was moved or removed");
|
|
301
|
+
check(elapsed < BUSY_ANSWER_BOUND_MS, `the answer took ${elapsed} ms — never waited for`);
|
|
302
|
+
check(entries(dir) === ".credential.lock, credential", `left behind: ${entries(dir)}`);
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
"unreadable-lock-directory",
|
|
307
|
+
(impl, _root, dir) => {
|
|
308
|
+
let ran = false;
|
|
309
|
+
const r = impl(join(dir, "missing", "credential"), () => {
|
|
310
|
+
ran = true;
|
|
311
|
+
});
|
|
312
|
+
check(r.status === "unreadable", `a lock that cannot be created answered ${r.status}, expected unreadable`);
|
|
313
|
+
check(!ran, "the callback ran without the lock");
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
];
|
|
317
|
+
const describeThrown = (e) => {
|
|
318
|
+
try {
|
|
319
|
+
return e instanceof Error ? e.message : String(e);
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return "the case threw a value that cannot be described";
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* 跑整份协议一致性测试:`implementation` 是被测实现(本包自己的原语过它;壳自己写的实现也必须过它)。逐格造临时根、跑、删根;一格抛 ⇒ 那一格红,`why` 说哪一条没做到,别的格照跑。
|
|
327
|
+
* 返回 {@link WebAdminCredentialLockConformanceReport};断言 `report.ok`,红了读 `cases` 里 `ok: false` 的那几格。
|
|
328
|
+
*/
|
|
329
|
+
export async function runWebAdminCredentialLockConformance(implementation) {
|
|
330
|
+
const cases = [];
|
|
331
|
+
for (const [id, run] of CASES) {
|
|
332
|
+
const root = await mintLocalRoot();
|
|
333
|
+
try {
|
|
334
|
+
const dir = join(root, "c");
|
|
335
|
+
mkdirSync(dir);
|
|
336
|
+
run(implementation, root, dir);
|
|
337
|
+
cases.push({ id, ok: true });
|
|
338
|
+
}
|
|
339
|
+
catch (e) {
|
|
340
|
+
cases.push({ id, ok: false, why: describeThrown(e) });
|
|
341
|
+
}
|
|
342
|
+
finally {
|
|
343
|
+
await removeLocalRoot(root);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return { ok: cases.every((c) => c.ok), cases };
|
|
347
|
+
}
|
package/dist/hooks-config.d.ts
CHANGED
|
@@ -192,13 +192,16 @@ export declare const HOOK_COMMAND_SPAWN_REFUSAL_WORDS: readonly ["path_unset", "
|
|
|
192
192
|
/** One word of {@link HOOK_COMMAND_SPAWN_REFUSAL_WORDS}. */
|
|
193
193
|
export type HookCommandSpawnRefusalWord = (typeof HOOK_COMMAND_SPAWN_REFUSAL_WORDS)[number];
|
|
194
194
|
/** A refusal of {@link planHookCommandSpawn}: the word, and the path name or the option key (as written on the command line — user text: pass it through the consumer's echo rules,
|
|
195
|
-
* or use {@link hookCommandSpawnRefusalSentence}) it is about. Never a value.
|
|
195
|
+
* or use {@link hookCommandSpawnRefusalSentence}) it is about. Never a value. The three words about a plugin's options (`shell_form_user_config`, `user_config_unset`, `user_config_unresolved`)
|
|
196
|
+
* have one shape — the word, the option `key`, and `pluginName`: the name of the plugin whose option was named, taken from the entry's own `plugin.name` (user text too: the sentence passes
|
|
197
|
+
* it through the same echo as the key). */
|
|
196
198
|
export type HookCommandSpawnRefusal = {
|
|
197
199
|
readonly word: "path_unset";
|
|
198
200
|
readonly name: HookCommandPathName;
|
|
199
201
|
} | {
|
|
200
202
|
readonly word: Exclude<HookCommandSpawnRefusalWord, "path_unset">;
|
|
201
203
|
readonly key: string;
|
|
204
|
+
readonly pluginName: string;
|
|
202
205
|
};
|
|
203
206
|
/** What {@link planHookCommandSpawn} answers: the shell-form command as it is (`shell`), the exec-form copy a process starts from (`exec`), or why it cannot start (`refused`). */
|
|
204
207
|
export type HookCommandSpawnPlan = {
|
|
@@ -224,7 +227,7 @@ export type HookCommandSpawnPlan = {
|
|
|
224
227
|
*
|
|
225
228
|
* INPUT. `entry` — the command line, and whether a plugin brought it: exec form when `args` is present (`command` is the program, no shell), shell form when it is not (the same
|
|
226
229
|
* switch as the entry's own); a PLUGIN entry is one with a `plugin` member — the same reading the classifier and the `plugin` column make (a {@link CommandHookEntry} the classifier
|
|
227
|
-
* loaded is passed as it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
230
|
+
* loaded is passed as it is; its `plugin` is read for `options`, and for `name` — every refusal about an option says whose option it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
228
231
|
* like any other `${…}`, and a shell-form command is not refused for it (the reference implementation takes an option table only for a plugin's hook, and both its refusal and its
|
|
229
232
|
* substitution hang on that table). `paths` — each path name's value, all three stated: a string (the empty string included) is the value, `undefined` is no value. `resolved` —
|
|
230
233
|
* optional, a plugin entry's option table as the caller holds it after resolving (or, for a sender, the table it holds); left out, the table is the entry's own `plugin.options`, and
|
|
@@ -236,7 +239,8 @@ export type HookCommandSpawnPlan = {
|
|
|
236
239
|
* VERDICT, in the order of {@link HOOK_COMMAND_SPAWN_REFUSAL_WORDS} — a whole word is judged over the whole command line before the next word (any unset key beats any unresolved one,
|
|
237
240
|
* wherever each stands): a named path name without a value ⇒ `path_unset` (the first missing one in {@link HOOK_COMMAND_PATH_NAMES} order); shell form naming an option ⇒
|
|
238
241
|
* `shell_form_user_config`; exec form naming a key the table does not hold ⇒ `user_config_unset`; exec form naming a key whose value is a reference ⇒ `user_config_unresolved` (keys:
|
|
239
|
-
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry
|
|
242
|
+
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry; each of the three also carries `pluginName`, the entry's own `plugin.name` — read
|
|
243
|
+
* from the entry whichever table is judged, never from `resolved`). Otherwise shell form ⇒ `command` as it is (a shell expands path names from
|
|
240
244
|
* the environment; nothing is substituted in the text), exec form ⇒ `file` / `args` with every recognized placeholder replaced by its value in that same pass.
|
|
241
245
|
*
|
|
242
246
|
* CALL SHAPES. A runner passes the entry it loaded and its paths — `planHookCommandSpawn(entry, paths)` — and nothing else decides the namespace. A runner with steps of its own between
|
|
@@ -254,12 +258,16 @@ export declare function planHookCommandSpawn(entry: {
|
|
|
254
258
|
readonly command: string;
|
|
255
259
|
readonly args?: readonly string[];
|
|
256
260
|
readonly plugin?: {
|
|
261
|
+
readonly name: string;
|
|
257
262
|
readonly options?: Readonly<Record<string, string | HookPluginOptionRef>>;
|
|
258
263
|
};
|
|
259
264
|
}, paths: Readonly<Record<HookCommandPathName, string | undefined>>, resolved?: Readonly<Record<string, string | HookPluginOptionRef>>): HookCommandSpawnPlan;
|
|
260
265
|
/**
|
|
261
266
|
* The one sentence for a {@link HookCommandSpawnRefusal}: fixed words plus the path name, or the option key passed through this package's echo of caller text (control and
|
|
262
|
-
* bidirectional characters stripped, long keys cut)
|
|
267
|
+
* bidirectional characters stripped, long keys cut); the three option words open with one phrase that names both the option and its plugin (`pluginName`, through the same echo) —
|
|
268
|
+
* `hook command names option "<key>" of plugin "<plugin>"` — and go on with what each says: `, which is not set` / `, whose value is a stored reference that is not resolved here` /
|
|
269
|
+
* ` in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable
|
|
270
|
+
* CLAUDE_PLUGIN_OPTION_<KEY>`. Never a value — the refusal carries none. A runner and a sender show this sentence instead of writing their own.
|
|
263
271
|
*/
|
|
264
272
|
export declare function hookCommandSpawnRefusalSentence(refusal: HookCommandSpawnRefusal): string;
|
|
265
273
|
/** The cap on {@link measureHookPluginContext}'s count for one entry's plugin context, in UTF-16 code units (a literal type: the measure's own copy is tied to it at compile time). */
|
package/dist/hooks-config.js
CHANGED
|
@@ -219,7 +219,7 @@ export const HOOK_COMMAND_SPAWN_REFUSAL_WORDS = deepFreeze(["path_unset", "shell
|
|
|
219
219
|
*
|
|
220
220
|
* INPUT. `entry` — the command line, and whether a plugin brought it: exec form when `args` is present (`command` is the program, no shell), shell form when it is not (the same
|
|
221
221
|
* switch as the entry's own); a PLUGIN entry is one with a `plugin` member — the same reading the classifier and the `plugin` column make (a {@link CommandHookEntry} the classifier
|
|
222
|
-
* loaded is passed as it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
222
|
+
* loaded is passed as it is; its `plugin` is read for `options`, and for `name` — every refusal about an option says whose option it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
223
223
|
* like any other `${…}`, and a shell-form command is not refused for it (the reference implementation takes an option table only for a plugin's hook, and both its refusal and its
|
|
224
224
|
* substitution hang on that table). `paths` — each path name's value, all three stated: a string (the empty string included) is the value, `undefined` is no value. `resolved` —
|
|
225
225
|
* optional, a plugin entry's option table as the caller holds it after resolving (or, for a sender, the table it holds); left out, the table is the entry's own `plugin.options`, and
|
|
@@ -231,7 +231,8 @@ export const HOOK_COMMAND_SPAWN_REFUSAL_WORDS = deepFreeze(["path_unset", "shell
|
|
|
231
231
|
* VERDICT, in the order of {@link HOOK_COMMAND_SPAWN_REFUSAL_WORDS} — a whole word is judged over the whole command line before the next word (any unset key beats any unresolved one,
|
|
232
232
|
* wherever each stands): a named path name without a value ⇒ `path_unset` (the first missing one in {@link HOOK_COMMAND_PATH_NAMES} order); shell form naming an option ⇒
|
|
233
233
|
* `shell_form_user_config`; exec form naming a key the table does not hold ⇒ `user_config_unset`; exec form naming a key whose value is a reference ⇒ `user_config_unresolved` (keys:
|
|
234
|
-
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry
|
|
234
|
+
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry; each of the three also carries `pluginName`, the entry's own `plugin.name` — read
|
|
235
|
+
* from the entry whichever table is judged, never from `resolved`). Otherwise shell form ⇒ `command` as it is (a shell expands path names from
|
|
235
236
|
* the environment; nothing is substituted in the text), exec form ⇒ `file` / `args` with every recognized placeholder replaced by its value in that same pass.
|
|
236
237
|
*
|
|
237
238
|
* CALL SHAPES. A runner passes the entry it loaded and its paths — `planHookCommandSpawn(entry, paths)` — and nothing else decides the namespace. A runner with steps of its own between
|
|
@@ -319,18 +320,19 @@ export function planHookCommandSpawn(entry, paths, resolved) {
|
|
|
319
320
|
if ("key" in p)
|
|
320
321
|
keys.push(p.key);
|
|
321
322
|
if (entry.args === undefined) {
|
|
322
|
-
|
|
323
|
+
// An option placeholder is only collected on a plugin entry (the pass above), so `plugin` is the entry's own context wherever `keys` is not empty.
|
|
324
|
+
return keys.length > 0 ? { kind: "refused", refusal: { word: "shell_form_user_config", key: keys[0], pluginName: plugin.name } } : { kind: "shell", command: entry.command };
|
|
323
325
|
}
|
|
324
326
|
let unresolved;
|
|
325
327
|
for (const key of keys) {
|
|
326
|
-
// A key is recognized only on a plugin entry (the pass above), so `options` is a table wherever a key is read
|
|
328
|
+
// A key is recognized only on a plugin entry (the pass above), so `options` is a table — and `plugin` is the entry's own context — wherever a key is read: here and in `render`.
|
|
327
329
|
if (!Object.hasOwn(options, key))
|
|
328
|
-
return { kind: "refused", refusal: { word: "user_config_unset", key } };
|
|
330
|
+
return { kind: "refused", refusal: { word: "user_config_unset", key, pluginName: plugin.name } };
|
|
329
331
|
if (unresolved === undefined && typeof options[key] !== "string")
|
|
330
332
|
unresolved = key;
|
|
331
333
|
}
|
|
332
334
|
if (unresolved !== undefined)
|
|
333
|
-
return { kind: "refused", refusal: { word: "user_config_unresolved", key: unresolved } };
|
|
335
|
+
return { kind: "refused", refusal: { word: "user_config_unresolved", key: unresolved, pluginName: plugin.name } };
|
|
334
336
|
const render = (line) => {
|
|
335
337
|
let out = "";
|
|
336
338
|
for (const piece of line)
|
|
@@ -341,18 +343,33 @@ export function planHookCommandSpawn(entry, paths, resolved) {
|
|
|
341
343
|
}
|
|
342
344
|
/**
|
|
343
345
|
* The one sentence for a {@link HookCommandSpawnRefusal}: fixed words plus the path name, or the option key passed through this package's echo of caller text (control and
|
|
344
|
-
* bidirectional characters stripped, long keys cut)
|
|
346
|
+
* bidirectional characters stripped, long keys cut); the three option words open with one phrase that names both the option and its plugin (`pluginName`, through the same echo) —
|
|
347
|
+
* `hook command names option "<key>" of plugin "<plugin>"` — and go on with what each says: `, which is not set` / `, whose value is a stored reference that is not resolved here` /
|
|
348
|
+
* ` in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable
|
|
349
|
+
* CLAUDE_PLUGIN_OPTION_<KEY>`. Never a value — the refusal carries none. A runner and a sender show this sentence instead of writing their own.
|
|
345
350
|
*/
|
|
346
351
|
export function hookCommandSpawnRefusalSentence(refusal) {
|
|
347
352
|
switch (refusal.word) {
|
|
348
353
|
case "path_unset":
|
|
349
354
|
return `hook command names \${${refusal.name}}, which has no value for this hook (it comes from the hook's plugin context or from its environment; settings.env can set it)`;
|
|
350
355
|
case "shell_form_user_config":
|
|
351
|
-
return `hook command names \${user_config.${echoCallerText(refusal.key)}} in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable CLAUDE_PLUGIN_OPTION_<KEY>`;
|
|
352
356
|
case "user_config_unset":
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
357
|
+
case "user_config_unresolved": {
|
|
358
|
+
const option = `hook command names option "${echoCallerText(refusal.key)}" of plugin "${echoCallerText(refusal.pluginName)}"`;
|
|
359
|
+
const word = refusal.word; // switch on the copy: once its cases are exhausted TypeScript narrows `refusal` itself to `never`, and the `default` arm below must still name the word
|
|
360
|
+
switch (word) {
|
|
361
|
+
case "shell_form_user_config":
|
|
362
|
+
return `${option} in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable CLAUDE_PLUGIN_OPTION_<KEY>`;
|
|
363
|
+
case "user_config_unset":
|
|
364
|
+
return `${option}, which is not set`;
|
|
365
|
+
case "user_config_unresolved":
|
|
366
|
+
return `${option}, whose value is a stored reference that is not resolved here`;
|
|
367
|
+
default: {
|
|
368
|
+
const unknownWord = word;
|
|
369
|
+
throw new Error(`hookCommandSpawnRefusalSentence: unknown refusal word '${String(unknownWord)}'`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
356
373
|
default: {
|
|
357
374
|
const unknownWord = refusal;
|
|
358
375
|
throw new Error(`hookCommandSpawnRefusalSentence: unknown refusal word '${String(unknownWord.word)}'`);
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./settings-units.js";
|
|
|
29
29
|
export * from "./scheduler-store.js";
|
|
30
30
|
export * from "./cross-session.js";
|
|
31
31
|
export * from "./hooks.js";
|
|
32
|
+
export * from "./plugin-settings.js";
|
|
32
33
|
export * from "./fleet.js";
|
|
33
34
|
export * from "./workers-rows.js";
|
|
34
35
|
export * from "./api/auth.js";
|
package/dist/index.js
CHANGED
|
@@ -25,10 +25,11 @@ export * from "./reader.js";
|
|
|
25
25
|
export * from "./cross-domain.js"; // pure half only (no fleet placement)
|
|
26
26
|
export * from "./remote-exec.js";
|
|
27
27
|
export * from "./safety-merge-spec.js"; // #14 per-category safety merge-spec (settings resolver authority) + 14.6.0 THE comparator tightenVerdict / TIGHTEN_VERDICTS and the member comparator memberTighten / resolveMemberTighten (derived from a member row's value class)
|
|
28
|
-
export * from "./settings-units.js"; // 14.6.0: SETTINGS_UNITS — the settings-document unit table (path / category / addressing / reading) + unitTighten (a unit's comparator) + readSettingsUnit (a unit's raw-value reading; spellings normalized, everything else unreadable), pure/browser-safe
|
|
28
|
+
export * from "./settings-units.js"; // 14.6.0: SETTINGS_UNITS — the settings-document unit table (path / category / addressing / reading / reader — SETTINGS_UNIT_READERS = shell | engine; the eleventh unit is the UI-language key semaUiLanguage) + unitTighten (a unit's comparator) + readSettingsUnit (a unit's raw-value reading; spellings normalized, everything else unreadable), pure/browser-safe
|
|
29
29
|
export * from "./scheduler-store.js"; // R7 self-wake scheduler store CONTRACT (pure: type + parse/serialize + SchedulerStore interface; fs binding in ./node)
|
|
30
30
|
export * from "./cross-session.js"; // CC-parity `settings.json` cross-session keys (crossSessionInbound / dialogExpiry) — pure/browser-safe
|
|
31
31
|
export * from "./hooks.js"; // CC-parity hooks contract (33-event set + owner map + per-event input/output shapes + the config surface: classifyHooksConfig and its zod faces HooksConfig / HookEntry …) & stop attribution (stoppedBy) — pure/browser-safe
|
|
32
|
+
export * from "./plugin-settings.js"; // the three pure readings of the plugin settings values — readEnabledPluginsValue (one `enabledPlugins` value: on / off / versions / unreadable) + readPluginId (`<name>@<marketplace>`, exactly one `@`, both halves read the one segment grammar PLUGIN_ID_SEGMENT_REGEX, re-exported by ./types from a package-private zero-import leaf; the scoped npm source id `@<scope>/<pkg>@npm` is read too — its name carries `@` and `/`, so it is not a valid `PluginSpec.name`) + the four marketplace sentinel words PLUGIN_MARKETPLACE_SENTINELS / isPluginMarketplaceSentinel; values only — how the central layer and the settings layers combine is not here; the same function objects as on the `./plugin-settings` subpath, pure/browser-safe
|
|
32
33
|
export * from "./fleet.js"; // scheduling/fleet contract (drain protocol · instance discovery · dispatch policy · quota lease · usage report · quota reset event) — CONTROL-PLANE-SCHEDULING-DESIGN, pure/browser-safe
|
|
33
34
|
export * from "./workers-rows.js"; // 11.0.0 the workers domain's per-row verdict (readWorkersRows: a row that does not read is held, the rest read on) — permanent read semantics, pure
|
|
34
35
|
export * from "./api/auth.js"; // /api/v1/auth/* wire contract (RFC 8628 device flow + rotating refresh + logout + approve) — REGISTRY-REBUILD-DESIGN §2, M1 shipped shapes frozen, pure/browser-safe
|
|
@@ -50,7 +51,7 @@ export * from "./mcp-server-policy.js"; // 13.0.0 (U6): mcpServerPolicyVerdict
|
|
|
50
51
|
export * from "./web-search-section.js"; // 30.1.0: WEB_SEARCH_SECTION_KEYS — the web search section's settings-document key (each key is also its category's name: SAFETY_MERGE_SPEC.webSearch), pure/browser-safe
|
|
51
52
|
export * from "./ui-language.js"; // 13.0.0 (S-1592): the UI-language settings fragment (semaUiLanguage, en | zh, category ui, user settings) + readUiLanguage, pure/browser-safe
|
|
52
53
|
export * from "./control-and-bidi.js"; // the one-line echo strip set (C0 + DEL + the 12 Bidi_Control code points) — CONTROL_AND_BIDI_CHARS (the class, as regex source text) + stripControlAndBidi / hasControlOrBidi, pure/browser-safe
|
|
53
|
-
export * from "./mcp-request-entry.js"; // 14.0.0: the request-plane MCP entry judges (isUsableWireName / isContentOriginWord / readRequestMcpTransport + the value-shape describers; 29.0.0: the request keys it refuses by name, MCP_REQUEST_KEY_REFUSALS) — one reading for the service legs and the shell pre-check, pure/browser-safe
|
|
54
|
+
export * from "./mcp-request-entry.js"; // 14.0.0: the request-plane MCP entry judges (isUsableWireName / isContentOriginWord / readRequestMcpTransport + the value-shape describers; 29.0.0: the request keys it refuses by name, MCP_REQUEST_KEY_REFUSALS; the credential reference kinds an http transport takes, MCP_REQUEST_CREDENTIAL_KINDS) — one reading for the service legs and the shell pre-check, pure/browser-safe
|
|
54
55
|
export * from "./connector-id.js"; // 29.0.0: the connector id (ConnectorId / isConnectorId / CONNECTOR_ID_MAX / CONNECTOR_ID_RULE — a DNS label, compared by bytes), pure/browser-safe
|
|
55
56
|
export * from "./mcp-entry-credential.js"; // 29.0.0: the MCP http entry's credential reference (McpEntryCredential / MCP_ENTRY_CREDENTIAL_KINDS — read once by the engine primitives' readCredentialRef), pure/browser-safe
|
|
56
57
|
export * from "./connector-authorize-url.js"; // 29.0.0: the hosted connector authorization address (connectorAuthorizeUrlOf / connectorAuthorizeUrlFlaws / CONNECTOR_AUTHORIZE_QUERY / CONNECTOR_AUTHORIZE_URL_FLAWS — one route form, the assembler and its judge in one module), pure/browser-safe
|
package/dist/local-load.d.ts
CHANGED
|
@@ -17,12 +17,77 @@ export declare function loadRemoteExec(root: string): Promise<RemoteExecSpec | u
|
|
|
17
17
|
/** Validate + ATOMICALLY write `<root>/config.d/remote-exec.json` (the package's one atomic writer, `./atomic-write`; never a half file). The
|
|
18
18
|
* client's `config` editor writes the exec backend through this; the engine reads it via loadRemoteExec. */
|
|
19
19
|
export declare function writeRemoteExec(root: string, spec: unknown): Promise<RemoteExecSpec>;
|
|
20
|
+
/** The `.env` file path under a config root — the ONE builder: the reading step reads exactly this path, a caller that watches or trust-checks the file asks the same function. */
|
|
21
|
+
export declare function envFilePath(root: string): string;
|
|
22
|
+
/** Why a `.env` line is not an assignment (closed set; a comment or a blank line is not a fault — it is not meant to be one): `no_equals` = text with no `=` in it; `empty_name` = nothing before the `=`. */
|
|
23
|
+
export declare const ENV_FILE_LINE_FAULTS: readonly ["no_equals", "empty_name"];
|
|
24
|
+
export type EnvFileLineFault = (typeof ENV_FILE_LINE_FAULTS)[number];
|
|
25
|
+
/** Why a `file:` reference could not be resolved (closed set, one word per exit): `empty_path` = nothing after `file:`; `missing_file` = the target does not exist; `empty_file` = the target is empty or only
|
|
26
|
+
* whitespace; `unreadable` = the read failed for any other reason (the original error is the answer's `error`); `untrusted` = the caller's trust seat refused the target (or could not answer), so it was NOT read. */
|
|
27
|
+
export declare const ENV_FILE_REF_FAULTS: readonly ["empty_path", "missing_file", "empty_file", "unreadable", "untrusted"];
|
|
28
|
+
export type EnvFileRefFault = (typeof ENV_FILE_REF_FAULTS)[number];
|
|
29
|
+
/** One `NAME=value` line as written: `line` is 1-based, `written` is the value after the quotes and an inline ` #` comment are taken off — a `file:` reference stays the text it was (nothing is resolved at this step). */
|
|
30
|
+
export interface EnvFileAssignment {
|
|
31
|
+
readonly line: number;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly written: string;
|
|
34
|
+
}
|
|
35
|
+
/** A line that is not an assignment: its 1-based number and the closed-set fault. The line's text is NOT carried — text with no `=` in it may be a pasted secret. */
|
|
36
|
+
export interface EnvFileBadLine {
|
|
37
|
+
readonly line: number;
|
|
38
|
+
readonly fault: EnvFileLineFault;
|
|
39
|
+
}
|
|
40
|
+
/** The first step's answer: the config root it was read under (a relative `file:` target is resolved against it), every assignment in file order (a name written twice is two entries), and every bad line. */
|
|
41
|
+
export interface EnvFileReading {
|
|
42
|
+
readonly root: string;
|
|
43
|
+
readonly assignments: readonly EnvFileAssignment[];
|
|
44
|
+
readonly badLines: readonly EnvFileBadLine[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* STEP ONE of reading `<root>/.env`: parse its lines into `NAME → the text written`, and resolve NOTHING. No `file:` target is looked at, so a bad reference on a line the caller does not care about cannot
|
|
48
|
+
* make this read fail, and a line that is not an assignment is reported by number instead of being dropped without a word. Absent `.env` ⇒ an empty reading (absence is the one rule `readTextIfPresent`
|
|
49
|
+
* answers: no entry on the path; a DANGLING symbolic link is an entry that cannot be read, so it throws, with the same sentence as {@link loadEnvFile}). The reading does NOT carry `process.env` —
|
|
50
|
+
* merging the process environment under the file is {@link loadEnvFile}'s step, not this one's.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readEnvFileLines(root: string): Promise<EnvFileReading>;
|
|
53
|
+
/**
|
|
54
|
+
* The caller's TRUST SEAT for a `file:` target: asked with the target's absolute path BEFORE any byte of it is read; `undefined` = go ahead, a string = refuse (the string is the sentence). A seat that throws
|
|
55
|
+
* or rejects refuses too (fail closed). It may be asynchronous. This package judges no file's owner or mode itself: whose files may feed a credential is the caller's rule, and this is where the caller's rule is applied.
|
|
56
|
+
*/
|
|
57
|
+
export type EnvFileTrustSeat = (file: string) => string | undefined | Promise<string | undefined>;
|
|
58
|
+
/** Options of {@link resolveEnvFileAssignments}: `trust` = the seat above (absent ⇒ every `file:` target is read); `failFast` = stop at the FIRST refusal in file order — no later line is looked at, no later target is asked of the seat or
|
|
59
|
+
* opened — and answer with that one refusal (`values` then holds only what resolved before it). {@link loadEnvFile} is the no-seat, fail-fast call: it never reads past the line it throws for. */
|
|
60
|
+
export interface EnvFileResolveOptions {
|
|
61
|
+
readonly trust?: EnvFileTrustSeat;
|
|
62
|
+
readonly failFast?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** One name that could not be resolved: the name, the number of the FIRST line that failed for it, the closed-set fault, and the error — the same object {@link loadEnvFile} throws for that line (a read error is passed through unchanged). */
|
|
65
|
+
export interface EnvFileRefusal {
|
|
66
|
+
readonly name: string;
|
|
67
|
+
readonly line: number;
|
|
68
|
+
readonly fault: EnvFileRefFault;
|
|
69
|
+
readonly error: Error;
|
|
70
|
+
}
|
|
71
|
+
/** The second step's answer: `values` = the resolved value of each requested name that the file assigns (the last assignment wins), `refused` = the names that failed, in file order. A refused name is not in `values`. */
|
|
72
|
+
export interface EnvFileResolution {
|
|
73
|
+
readonly values: Readonly<Record<string, string>>;
|
|
74
|
+
readonly refused: readonly EnvFileRefusal[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* STEP TWO: resolve only the names the caller lists, from a {@link readEnvFileLines} reading — nothing else in the file is looked at, and nothing is read from disk but the `file:` targets of those names. A value
|
|
78
|
+
* that does not start with `file:` is itself; one that does is the trimmed content of that file, the target asked of the caller's trust seat first ({@link EnvFileTrustSeat}) and read only if it answers `undefined`.
|
|
79
|
+
* EVERY assignment of a listed name is resolved, the overridden ones too: an earlier line's bad reference is still a refusal of that name (a secret that cannot be resolved is not made fine by being written again later);
|
|
80
|
+
* once a name has a refusal its later lines are not looked at. A name the file does not assign appears nowhere in the answer. Never throws for a bad line or target: the answer says which names failed, how, and why.
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveEnvFileAssignments(reading: EnvFileReading, names: Iterable<string>, opts?: EnvFileResolveOptions): Promise<EnvFileResolution>;
|
|
20
83
|
/** Parse `<root>/.env` (KEY=VALUE, `#` comments, optional surrounding quotes) MERGED OVER process.env (the
|
|
21
84
|
* file wins). The ONLY place secret VALUES live — the contract files carry env-NAMEs only. A `KEY=` with an
|
|
22
85
|
* empty value IS present (the caller may treat empty as a weak warning). Absent .env → just process.env — absent
|
|
23
86
|
* means no entry on the path (the one absence rule, `readTextIfPresent`): a DANGLING symbolic link at `.env` is present and unreadable, so it throws.
|
|
24
87
|
* A `.env` value of `file:<path>` resolves to that file's trimmed content (file-NAME ref — key stays out of
|
|
25
|
-
* env, contract stays env-NAME-only). Schema still rejects pasted plaintext (the contract field is a NAME).
|
|
88
|
+
* env, contract stays env-NAME-only). Schema still rejects pasted plaintext (the contract field is a NAME).
|
|
89
|
+
* This is the two steps in one: {@link readEnvFileLines}, then {@link resolveEnvFileAssignments} for EVERY name the file assigns, no trust seat, fail-fast — so one bad `file:` reference anywhere in the file
|
|
90
|
+
* throws (the first one in file order, with the same error as ever, and nothing after that line is opened). A reader that wants only some names, or wants to judge each `file:` target before it is read, calls the two steps itself. */
|
|
26
91
|
export declare function loadEnvFile(root: string): Promise<Record<string, string>>;
|
|
27
92
|
export interface LocalConfig {
|
|
28
93
|
/** The resolved config the engine consumes — the FULL EffectiveConfig (skills carry full content; NOT the
|