@sema-agent/settings-schema 33.1.0 → 34.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +414 -0
  2. package/README.md +118 -14
  3. package/conformance/VERSION +1 -1
  4. package/dist/atomic-write.d.ts +59 -0
  5. package/dist/atomic-write.js +303 -1
  6. package/dist/cli.d.ts +5 -2
  7. package/dist/cli.js +15 -3
  8. package/dist/config-dir-migration.d.ts +2 -1
  9. package/dist/config-dir-migration.js +34 -20
  10. package/dist/config-fns.d.ts +60 -14
  11. package/dist/config-fns.js +48 -13
  12. package/dist/conformance/index.d.ts +1 -0
  13. package/dist/conformance/index.js +2 -0
  14. package/dist/conformance/warnings.d.ts +1 -1
  15. package/dist/conformance/warnings.js +3 -3
  16. package/dist/conformance/web-admin-credential-lock.d.ts +17 -0
  17. package/dist/conformance/web-admin-credential-lock.js +346 -0
  18. package/dist/cross-session.d.ts +2 -2
  19. package/dist/fleet.d.ts +5 -5
  20. package/dist/hooks-config.d.ts +12 -4
  21. package/dist/hooks-config.js +28 -11
  22. package/dist/index.js +2 -2
  23. package/dist/local-load.d.ts +66 -1
  24. package/dist/local-load.js +123 -39
  25. package/dist/mcp-request-entry.d.ts +24 -5
  26. package/dist/mcp-request-entry.js +57 -17
  27. package/dist/node.d.ts +1 -0
  28. package/dist/node.js +2 -0
  29. package/dist/read-sentences.d.ts +14 -3
  30. package/dist/read-sentences.js +32 -11
  31. package/dist/safety-merge-spec.d.ts +5 -5
  32. package/dist/safety-merge-spec.js +5 -3
  33. package/dist/settings-units.d.ts +35 -1
  34. package/dist/settings-units.js +51 -16
  35. package/dist/types.d.ts +9 -9
  36. package/dist/types.js +27 -8
  37. package/dist/ui-language.d.ts +3 -1
  38. package/dist/ui-language.js +3 -1
  39. package/dist/web-admin-credential.d.ts +14 -1
  40. package/dist/web-admin-credential.js +15 -1
  41. package/docs/API-SURFACE.md +31 -4
  42. package/docs/CONFORMANCE.md +19 -2
  43. package/docs/CONSUMER-INTEGRATION.md +114 -10
  44. package/llms-full.txt +39 -10
  45. package/llms.txt +15 -7
  46. package/package.json +1 -1
@@ -0,0 +1,346 @@
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
+ * 已知范围:软链两格(写穿 · 悬空)要求宿主允许建符号链接(Windows 上普通用户默认不允许,那两格会以「建链接失败」红)。
16
+ */
17
+ import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
18
+ import { basename, dirname, join } from "node:path";
19
+ import { performance } from "node:perf_hooks";
20
+ import { removeLockIf } from "../atomic-write.js";
21
+ import { WEB_ADMIN_CREDENTIAL_FILE_LOCK, webAdminCredentialLockName } from "../web-admin-credential.js";
22
+ import { mintLocalRoot, removeLocalRoot } from "./temp-roots.js";
23
+ const STALE = WEB_ADMIN_CREDENTIAL_FILE_LOCK.staleMs;
24
+ /** 「忙时不等待」的耗时上界(毫秒,单调钟):只为抓「先等一会儿再答」的实现,留足慢盘余量。一只正确的实现在调用期间被宿主调度停住超过它,这一格会红 —— 那是宿主读数,不是协议结论:重跑一次分得开。 */
25
+ const BUSY_ANSWER_BOUND_MS = 1000;
26
+ function check(cond, why) {
27
+ if (!cond)
28
+ throw new Error(why);
29
+ }
30
+ const lockOf = (file) => join(dirname(file), webAdminCredentialLockName(basename(file)));
31
+ const inoOf = (p) => statSync(p, { bigint: true }).ino;
32
+ const entries = (dir) => readdirSync(dir).sort().join(", ");
33
+ /** 按协议建一只别人的锁,mtime 拨到 `ageMs` 之前(负数 = 未来);返回它的 inode。 */
34
+ function plantLock(p, ageMs) {
35
+ closeSync(openSync(p, "wx"));
36
+ const t = (Date.now() - ageMs) / 1000;
37
+ utimesSync(p, t, t);
38
+ return inoOf(p);
39
+ }
40
+ /** 另一个写者接手 `target` 的锁:按协议收残留 —— 走包里收 / 放锁的**那一套动作**(`removeLockIf`:把锁改名挪开、核挪走的是不是此刻在路径上的那一只、删挪开件;从不按路径删锁)—— 再建自己的锁;返回它的 inode。 */
41
+ function takeOver(target) {
42
+ const lock = lockOf(target);
43
+ const held = statSync(lock, { bigint: true });
44
+ removeLockIf(lock, { dev: held.dev, ino: held.ino });
45
+ return plantLock(lock, 0);
46
+ }
47
+ function writeCredential(dir) {
48
+ const cred = join(dir, "credential");
49
+ writeFileSync(cred, "R1");
50
+ return cred;
51
+ }
52
+ function expectBusyUntouched(impl, dir, ageMs) {
53
+ const cred = writeCredential(dir);
54
+ const lock = lockOf(cred);
55
+ const ino = plantLock(lock, ageMs);
56
+ let ran = false;
57
+ const started = performance.now(); // 单调钟:墙钟被拨动不影响这只量
58
+ const r = impl(cred, () => {
59
+ ran = true;
60
+ });
61
+ const elapsed = Math.round(performance.now() - started);
62
+ check(r.status === "busy", `a lock aged ${ageMs} ms answered ${r.status}, expected busy`);
63
+ check(!ran, "the callback ran while another writer held the lock");
64
+ check(existsSync(lock) && inoOf(lock) === ino, "the other writer's lock was moved or replaced");
65
+ check(r.heldForMs === undefined || (r.heldForMs >= 0 && r.heldForMs <= STALE), `heldForMs ${String(r.heldForMs)} is outside 0..staleMs`);
66
+ check(elapsed < BUSY_ANSWER_BOUND_MS, `busy took ${elapsed} ms — the lock is tried once and never waited for`);
67
+ }
68
+ const CASES = [
69
+ [
70
+ "free-acquires",
71
+ (impl, _root, dir) => {
72
+ const cred = writeCredential(dir);
73
+ const r = impl(cred, (held) => ({ current: held.current, lockThere: existsSync(lockOf(held.target)), mine: held.stillMine(), same: realpathSync(held.target) === realpathSync(cred) }));
74
+ check(r.status === "acquired", `answered ${r.status}, expected acquired`);
75
+ check(r.value.current === "R1", "the callback did not get the credential text read under the lock");
76
+ check(r.value.lockThere, "no lock file named .<file>.lock beside the target while held");
77
+ check(r.value.mine, "stillMine() was false for an undisturbed holder");
78
+ check(r.value.same, "held.target is not the credential file");
79
+ check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
80
+ },
81
+ ],
82
+ ["fresh-lock-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, 0)],
83
+ ["future-mtime-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, -60_000)],
84
+ ["young-lock-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, STALE / 2)],
85
+ [
86
+ "stale-lock-is-reclaimed",
87
+ (impl, _root, dir) => {
88
+ const cred = writeCredential(dir);
89
+ const lock = lockOf(cred);
90
+ const old = plantLock(lock, STALE + 5000);
91
+ const keepOld = openSync(lock, "r"); // 钉住残留那个文件对象:它被删后 inode 号不会被新锁复用,「不是同一只」的比对才成立
92
+ try {
93
+ const r = impl(cred, () => (existsSync(lock) ? inoOf(lock) : undefined));
94
+ check(r.status === "acquired", `a lock older than staleMs answered ${r.status}, expected acquired`);
95
+ check(r.value !== undefined && r.value !== old, "the holder did not hold a lock of its own");
96
+ }
97
+ finally {
98
+ closeSync(keepOld);
99
+ }
100
+ check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
101
+ },
102
+ ],
103
+ [
104
+ "lost-when-replaced",
105
+ (impl, _root, dir) => {
106
+ const cred = writeCredential(dir);
107
+ const lock = lockOf(cred);
108
+ const tmp = join(dir, "kit-next.tmp");
109
+ const r = impl(cred, (held) => {
110
+ const successor = takeOver(held.target); // another writer took the lock over (the protocol's reclaim) and holds a lock of its own
111
+ const mine = held.stillMine();
112
+ writeFileSync(tmp, "R2");
113
+ return { successor, mine, wrote: held.replaceWith(tmp) };
114
+ });
115
+ check(r.status === "lost", `answered ${r.status}, expected lost`);
116
+ check(!r.value.mine, "stillMine() was true after the lock was replaced");
117
+ check(!r.value.wrote, "replaceWith() wrote after the lock was replaced");
118
+ check(readFileSync(cred, "utf8") === "R1", "the credential changed without the lock");
119
+ check(existsSync(tmp), "the caller's temporary file was consumed");
120
+ check(existsSync(lock) && inoOf(lock) === r.value.successor, "the successor's lock was removed or replaced on release");
121
+ },
122
+ ],
123
+ [
124
+ "replace-after-loss-unchecked",
125
+ (impl, _root, dir) => {
126
+ const cred = writeCredential(dir);
127
+ const tmp = join(dir, "kit-next.tmp");
128
+ const r = impl(cred, (held) => {
129
+ takeOver(held.target); // another writer holds the lock now; the callback does not ask stillMine() first
130
+ writeFileSync(tmp, "R2");
131
+ return held.replaceWith(tmp);
132
+ });
133
+ check(r.status === "lost", `answered ${r.status}, expected lost`);
134
+ check(!r.value, "replaceWith() wrote without checking the lock itself");
135
+ check(readFileSync(cred, "utf8") === "R1", "the credential changed without the lock");
136
+ },
137
+ ],
138
+ [
139
+ "remove-after-loss-unchecked",
140
+ (impl, _root, dir) => {
141
+ const cred = writeCredential(dir);
142
+ const r = impl(cred, (held) => {
143
+ takeOver(held.target); // another writer holds the lock now; the callback does not ask stillMine() first
144
+ return held.remove();
145
+ });
146
+ check(r.status === "lost", `answered ${r.status}, expected lost`);
147
+ check(!r.value, "remove() deleted without checking the lock itself");
148
+ check(existsSync(cred), "the credential was removed without the lock");
149
+ },
150
+ ],
151
+ [
152
+ "replace-writes-through-link",
153
+ (impl, root, dir) => {
154
+ const d = join(root, "d");
155
+ mkdirSync(d);
156
+ const realFile = join(d, "real");
157
+ writeFileSync(realFile, "R1");
158
+ const link = join(dir, "credential");
159
+ symlinkSync(realFile, link);
160
+ const r = impl(link, (held) => {
161
+ const seen = {
162
+ besideTarget: existsSync(join(d, webAdminCredentialLockName("real"))),
163
+ besideLink: existsSync(join(dir, webAdminCredentialLockName("credential"))),
164
+ targetIsLink: lstatSync(held.target).isSymbolicLink(),
165
+ same: realpathSync(held.target) === realpathSync(realFile),
166
+ };
167
+ const tmp = join(dirname(held.target), "kit-next.tmp");
168
+ writeFileSync(tmp, "R2");
169
+ return { ...seen, wrote: held.replaceWith(tmp) };
170
+ });
171
+ check(r.status === "acquired", `answered ${r.status}, expected acquired`);
172
+ check(r.value.wrote, "replaceWith() did not land for an undisturbed holder");
173
+ check(r.value.besideTarget, "no lock beside the link's real target");
174
+ check(!r.value.besideLink, "a lock beside the link itself");
175
+ check(!r.value.targetIsLink && r.value.same, "held.target is not the link's real target");
176
+ check(lstatSync(link).isSymbolicLink(), "the link was replaced by a regular file");
177
+ check(readFileSync(realFile, "utf8") === "R2", "the real target was not written");
178
+ check(entries(dir) === "credential" && entries(d) === "real", `left behind: ${entries(dir)} | ${entries(d)}`);
179
+ },
180
+ ],
181
+ [
182
+ "dangling-link-is-unreadable",
183
+ (impl, root, dir) => {
184
+ const link = join(dir, "credential");
185
+ 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
186
+ let ran = false;
187
+ const r = impl(link, () => {
188
+ ran = true;
189
+ });
190
+ check(r.status === "unreadable", `a dangling link answered ${r.status}, expected unreadable`);
191
+ check(!ran, "the callback ran through a dangling link");
192
+ 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"}`);
193
+ },
194
+ ],
195
+ [
196
+ "remove-under-lock",
197
+ (impl, _root, dir) => {
198
+ const cred = writeCredential(dir);
199
+ const r = impl(cred, (held) => held.remove());
200
+ check(r.status === "acquired" && r.value, `answered ${r.status}, expected acquired with the removal landed`);
201
+ check(entries(dir) === "", `left behind: ${entries(dir)}`);
202
+ },
203
+ ],
204
+ [
205
+ "absent-target-reads-undefined",
206
+ (impl, _root, dir) => {
207
+ const r = impl(join(dir, "credential"), (held) => held.current === undefined);
208
+ check(r.status === "acquired" && r.value, `answered ${r.status}; an absent target is read as undefined under the lock`);
209
+ },
210
+ ],
211
+ [
212
+ "critical-throws-releases",
213
+ (impl, _root, dir) => {
214
+ const cred = writeCredential(dir);
215
+ const sentinel = new Error("kit sentinel");
216
+ let caught;
217
+ try {
218
+ impl(cred, () => {
219
+ throw sentinel;
220
+ });
221
+ }
222
+ catch (e) {
223
+ caught = e;
224
+ }
225
+ check(caught === sentinel, "the callback's error was not rethrown as it was");
226
+ check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
227
+ },
228
+ ],
229
+ [
230
+ "thenable-is-refused",
231
+ (impl, _root, dir) => {
232
+ const cred = writeCredential(dir);
233
+ const sneaky = () => Promise.resolve();
234
+ let caught;
235
+ try {
236
+ impl(cred, sneaky);
237
+ }
238
+ catch (e) {
239
+ caught = e;
240
+ }
241
+ check(caught instanceof TypeError, "a callback that returned a promise was not refused with a TypeError");
242
+ check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
243
+ },
244
+ ],
245
+ [
246
+ "handle-expires-on-return",
247
+ (impl, _root, dir) => {
248
+ const cred = writeCredential(dir);
249
+ const r = impl(cred, (held) => held);
250
+ check(r.status === "acquired", `answered ${r.status}, expected acquired`);
251
+ const kept = r.value;
252
+ const tmp = join(dir, "kit-late.tmp");
253
+ writeFileSync(tmp, "R2");
254
+ const answers = ["stillMine", "replaceWith", "remove"].filter((method) => {
255
+ try {
256
+ if (method === "stillMine")
257
+ kept.stillMine();
258
+ else if (method === "replaceWith")
259
+ kept.replaceWith(tmp);
260
+ else
261
+ kept.remove();
262
+ return true;
263
+ }
264
+ catch {
265
+ return false;
266
+ }
267
+ });
268
+ check(answers.length === 0, `the handle still answered after the callback returned: ${answers.join(", ")}`);
269
+ check(readFileSync(cred, "utf8") === "R1", "a late call on the handle changed the credential");
270
+ },
271
+ ],
272
+ [
273
+ "unreadable-target",
274
+ (impl, _root, dir) => {
275
+ mkdirSync(join(dir, "credential"));
276
+ let ran = false;
277
+ const r = impl(join(dir, "credential"), () => {
278
+ ran = true;
279
+ });
280
+ check(r.status === "unreadable", `a target that cannot be read answered ${r.status}, expected unreadable`);
281
+ check(!ran, "the callback ran without a readable target");
282
+ check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
283
+ },
284
+ ],
285
+ [
286
+ "non-file-lock-name-is-unreadable",
287
+ (impl, _root, dir) => {
288
+ const cred = writeCredential(dir);
289
+ const lock = lockOf(cred);
290
+ 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)
291
+ let ran = false;
292
+ const started = performance.now();
293
+ const r = impl(cred, () => {
294
+ ran = true;
295
+ });
296
+ const elapsed = Math.round(performance.now() - started);
297
+ 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)`);
298
+ check(!ran, "the callback ran although the lock name is not a lock");
299
+ check(lstatSync(lock).isDirectory(), "the entry on the lock's name was moved or removed");
300
+ check(elapsed < BUSY_ANSWER_BOUND_MS, `the answer took ${elapsed} ms — never waited for`);
301
+ check(entries(dir) === ".credential.lock, credential", `left behind: ${entries(dir)}`);
302
+ },
303
+ ],
304
+ [
305
+ "unreadable-lock-directory",
306
+ (impl, _root, dir) => {
307
+ let ran = false;
308
+ const r = impl(join(dir, "missing", "credential"), () => {
309
+ ran = true;
310
+ });
311
+ check(r.status === "unreadable", `a lock that cannot be created answered ${r.status}, expected unreadable`);
312
+ check(!ran, "the callback ran without the lock");
313
+ },
314
+ ],
315
+ ];
316
+ const describeThrown = (e) => {
317
+ try {
318
+ return e instanceof Error ? e.message : String(e);
319
+ }
320
+ catch {
321
+ return "the case threw a value that cannot be described";
322
+ }
323
+ };
324
+ /**
325
+ * 跑整份协议一致性测试:`implementation` 是被测实现(本包自己的原语过它;壳自己写的实现也必须过它)。逐格造临时根、跑、删根;一格抛 ⇒ 那一格红,`why` 说哪一条没做到,别的格照跑。
326
+ * 返回 {@link WebAdminCredentialLockConformanceReport};断言 `report.ok`,红了读 `cases` 里 `ok: false` 的那几格。
327
+ */
328
+ export async function runWebAdminCredentialLockConformance(implementation) {
329
+ const cases = [];
330
+ for (const [id, run] of CASES) {
331
+ const root = await mintLocalRoot();
332
+ try {
333
+ const dir = join(root, "c");
334
+ mkdirSync(dir);
335
+ run(implementation, root, dir);
336
+ cases.push({ id, ok: true });
337
+ }
338
+ catch (e) {
339
+ cases.push({ id, ok: false, why: describeThrown(e) });
340
+ }
341
+ finally {
342
+ await removeLocalRoot(root);
343
+ }
344
+ }
345
+ return { ok: cases.every((c) => c.ok), cases };
346
+ }
@@ -64,8 +64,8 @@ export type DialogExpiryValue = (typeof DIALOG_EXPIRY_VALUES)[number];
64
64
  export declare const DIALOG_EXPIRY_DEFAULT: DialogExpiryValue;
65
65
  /** 文件层受理面:四个值 + `"default"`(未设 ⇒ 落 {@link DIALOG_EXPIRY_DEFAULT})。 */
66
66
  export declare const DialogExpirySetting: z.ZodEnum<{
67
- default: "default";
68
67
  never: "never";
68
+ default: "default";
69
69
  "60s": "60s";
70
70
  "5m": "5m";
71
71
  "10m": "10m";
@@ -85,8 +85,8 @@ export declare const CrossSessionSettings: z.ZodObject<{
85
85
  hold: "hold";
86
86
  }>>;
87
87
  dialogExpiry: z.ZodOptional<z.ZodEnum<{
88
- default: "default";
89
88
  never: "never";
89
+ default: "default";
90
90
  "60s": "60s";
91
91
  "5m": "5m";
92
92
  "10m": "10m";
package/dist/fleet.d.ts CHANGED
@@ -110,8 +110,8 @@ export declare function compareGeneration(a: string, b: string): -1 | 0 | 1;
110
110
  */
111
111
  export declare const LEASE_STATES: readonly ["none", "granted", "expired", "denied"];
112
112
  export declare const LeaseState: z.ZodEnum<{
113
- none: "none";
114
113
  expired: "expired";
114
+ none: "none";
115
115
  granted: "granted";
116
116
  denied: "denied";
117
117
  }>;
@@ -343,8 +343,8 @@ export declare const EngineSignal: z.ZodObject<{
343
343
  }, z.core.$strip>>;
344
344
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
345
345
  leaseState: z.ZodOptional<z.ZodEnum<{
346
- none: "none";
347
346
  expired: "expired";
347
+ none: "none";
348
348
  granted: "granted";
349
349
  denied: "denied";
350
350
  }>>;
@@ -386,8 +386,8 @@ export declare const InstanceHealth: z.ZodObject<{
386
386
  }, z.core.$strip>>;
387
387
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
388
388
  leaseState: z.ZodOptional<z.ZodEnum<{
389
- none: "none";
390
389
  expired: "expired";
390
+ none: "none";
391
391
  granted: "granted";
392
392
  denied: "denied";
393
393
  }>>;
@@ -458,8 +458,8 @@ export declare const InstanceAnnouncement: z.ZodObject<{
458
458
  }, z.core.$strip>>;
459
459
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
460
460
  leaseState: z.ZodOptional<z.ZodEnum<{
461
- none: "none";
462
461
  expired: "expired";
462
+ none: "none";
463
463
  granted: "granted";
464
464
  denied: "denied";
465
465
  }>>;
@@ -507,8 +507,8 @@ export declare const InstanceRegistration: z.ZodObject<{
507
507
  }, z.core.$strip>>;
508
508
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
509
509
  leaseState: z.ZodOptional<z.ZodEnum<{
510
- none: "none";
511
510
  expired: "expired";
511
+ none: "none";
512
512
  granted: "granted";
513
513
  denied: "denied";
514
514
  }>>;
@@ -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). Otherwise shell form ⇒ `command` as it is (a shell expands path names from
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). Never a value — the refusal carries none. A runner and a sender show this sentence instead of writing their own.
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). */
@@ -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). Otherwise shell form ⇒ `command` as it is (a shell expands path names from
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
- return keys.length > 0 ? { kind: "refused", refusal: { word: "shell_form_user_config", key: keys[0] } } : { kind: "shell", command: entry.command };
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 — here and in `render`.
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). Never a value — the refusal carries none. A runner and a sender show this sentence instead of writing their own.
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
- return `hook command names plugin option "${echoCallerText(refusal.key)}", which is not set`;
354
- case "user_config_unresolved":
355
- return `hook command names plugin option "${echoCallerText(refusal.key)}", whose value is a stored reference that is not resolved here`;
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.js CHANGED
@@ -25,7 +25,7 @@ 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
@@ -50,7 +50,7 @@ export * from "./mcp-server-policy.js"; // 13.0.0 (U6): mcpServerPolicyVerdict
50
50
  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
51
  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
52
  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
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; 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
54
  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
55
  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
56
  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