@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
@@ -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
@@ -11,6 +11,7 @@ import { mkdir, readFile } from "node:fs/promises";
11
11
  import { homedir } from "node:os";
12
12
  import path from "node:path";
13
13
  import { readTextIfPresent, writeFileAtomic } from "./atomic-write.js";
14
+ import { deepFreeze } from "./deep-freeze.js";
14
15
  import { FileConfigStore } from "./file-store.js";
15
16
  import { listRequiredEnvNames } from "./file-edit.js";
16
17
  import {} from "./config-fns.js";
@@ -42,73 +43,156 @@ export async function writeRemoteExec(root, spec) {
42
43
  writeFileAtomic(remoteExecPath(root), configDDocumentText(parsed), "config-document");
43
44
  return parsed;
44
45
  }
46
+ // ── `.env`: two steps — read the lines, then resolve the names a caller asks for ─────────────────────────────────────
47
+ /** 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. */
48
+ export function envFilePath(root) {
49
+ return path.join(root, ".env");
50
+ }
51
+ /** 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 `=`. */
52
+ export const ENV_FILE_LINE_FAULTS = deepFreeze(["no_equals", "empty_name"]);
53
+ /** 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
54
+ * 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. */
55
+ export const ENV_FILE_REF_FAULTS = deepFreeze(["empty_path", "missing_file", "empty_file", "unreadable", "untrusted"]);
56
+ /** One line of `.env` → an assignment, a bad line, or nothing (blank / comment). The dotenv rules: an `export ` prefix on the name is dropped; a value in matching quotes is taken between them, an unquoted value loses an inline ` #` comment. */
57
+ function parseEnvLine(raw) {
58
+ const line = raw.trim();
59
+ if (!line || line.startsWith("#"))
60
+ return { kind: "skip" };
61
+ const eq = line.indexOf("=");
62
+ if (eq < 0)
63
+ return { kind: "bad", fault: "no_equals" };
64
+ if (eq === 0)
65
+ return { kind: "bad", fault: "empty_name" };
66
+ let key = line.slice(0, eq).trim();
67
+ if (key.startsWith("export "))
68
+ key = key.slice("export ".length).trim(); // dotenv: strip the `export ` prefix
69
+ if (!key)
70
+ return { kind: "bad", fault: "empty_name" };
71
+ let val = line.slice(eq + 1).trim();
72
+ const quoted = (val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"));
73
+ if (quoted) {
74
+ val = val.slice(1, -1);
75
+ }
76
+ else {
77
+ const hash = val.indexOf(" #"); // dotenv: strip an inline ` #...` comment from an UNQUOTED value
78
+ if (hash >= 0)
79
+ val = val.slice(0, hash).trimEnd();
80
+ }
81
+ return { kind: "assignment", name: key, written: val };
82
+ }
83
+ /**
84
+ * 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
85
+ * 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`
86
+ * 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` —
87
+ * merging the process environment under the file is {@link loadEnvFile}'s step, not this one's.
88
+ */
89
+ export async function readEnvFileLines(root) {
90
+ const text = await readTextIfPresent(envFilePath(root));
91
+ const assignments = [];
92
+ const badLines = [];
93
+ if (text === undefined)
94
+ return { root, assignments, badLines };
95
+ text.split("\n").forEach((raw, i) => {
96
+ const parsed = parseEnvLine(raw);
97
+ if (parsed.kind === "assignment")
98
+ assignments.push({ line: i + 1, name: parsed.name, written: parsed.written });
99
+ else if (parsed.kind === "bad")
100
+ badLines.push({ line: i + 1, fault: parsed.fault });
101
+ });
102
+ return { root, assignments, badLines };
103
+ }
104
+ const refusedRef = (fault, error) => ({ ok: false, fault, error });
45
105
  /** Resolve a `file:<path>` .env VALUE → the file's trimmed content (the file-NAME secret ref, config-research
46
106
  * §5 #4). Keeps the env-NAME-only CONTRACT intact — the schema field is still a NAME (e.g. `apiKeyEnv`), only
47
107
  * the VALUE in `.env` may say "read me from a file" (the key in `~/.ssh/…`, not in env). `~/` → homedir; a
48
- * relative path is under the config root; missing file THROWS (fail-closed — never resolve a secret to ""). */
49
- async function resolveFileRef(spec, root) {
108
+ * relative path is under the config root; a missing file is a refusal (fail-closed — never resolve a secret to ""). The trust seat, when given, is asked first. */
109
+ async function resolveFileRef(spec, root, trust) {
50
110
  let p = spec.trim();
51
111
  if (!p)
52
- throw new Error(`.env "file:" ref has an empty path`);
112
+ return refusedRef("empty_path", new Error(`.env "file:" ref has an empty path`));
53
113
  if (p === "~" || p.startsWith("~/"))
54
114
  p = path.join(homedir(), p.slice(1));
55
- const abs = path.isAbsolute(p) ? p : path.join(root, p);
115
+ const shown = path.isAbsolute(p) ? p : path.join(root, p); // the path as the sentences have always shown it
116
+ // With a seat, the path it judges AND the read opens is ONE ABSOLUTE string (a relative config root is anchored at the working directory once, here): the path judged is the path opened, even if the working
117
+ // directory changes while the seat is thinking (what the kernel finds behind that path between the judgement and the read — a link swapped in — is not seen by any path-based check). Anchored by concatenation,
118
+ // not `path.resolve`: no lexical `..` collapse, so the kernel resolves the path exactly as it did when the read took the relative path. With NO seat nothing is judged, so there is nothing to keep equal and the
119
+ // path is opened as written (`shown`), exactly as the read did before the seat existed: a native read error (`ENOTDIR`, `EACCES`, …) carries the same `path` and message as ever, relative root or not.
120
+ const abs = path.isAbsolute(shown) ? shown : `${process.cwd()}${path.sep}${shown}`;
121
+ if (trust !== undefined) {
122
+ let answer;
123
+ try {
124
+ answer = await trust(abs);
125
+ }
126
+ catch (cause) {
127
+ return refusedRef("untrusted", new Error(`the trust check for ${abs} could not be completed, so the file is not read (fail-closed)`, { cause }));
128
+ }
129
+ if (answer !== undefined)
130
+ return refusedRef("untrusted", new Error(typeof answer === "string" ? answer : `the trust check for ${abs} answered with something that is not a sentence, so the file is not read (fail-closed)`));
131
+ }
56
132
  let content;
57
133
  try {
58
- content = (await readFile(abs, "utf8")).trim();
134
+ content = (await readFile(trust === undefined ? shown : abs, "utf8")).trim();
59
135
  }
60
136
  catch (e) {
61
137
  if (e.code === "ENOENT")
62
- throw new Error(`.env "file:" ref points to a missing file: ${abs}`);
63
- throw e;
138
+ return refusedRef("missing_file", new Error(`.env "file:" ref points to a missing file: ${shown}`));
139
+ return refusedRef("unreadable", e); // the original error object, whatever realm made it (a read never rejects with a non-error)
64
140
  }
65
141
  // FAIL-CLOSED on an empty/whitespace file (same discipline as loadRemoteExec): otherwise the secret resolves
66
142
  // to "" and listRequiredEnvNames marks it present (resolvedEnv[k] !== undefined) — the "set these secrets"
67
143
  // panel goes green while the worker boots with an EMPTY credential. A secret file must be non-empty.
68
144
  if (!content)
69
- throw new Error(`.env "file:" ref resolved to an EMPTY file: ${abs} — a secret must not be empty (fail-closed, like a missing file)`);
70
- return content;
145
+ return refusedRef("empty_file", new Error(`.env "file:" ref resolved to an EMPTY file: ${shown} — a secret must not be empty (fail-closed, like a missing file)`));
146
+ return { ok: true, value: content };
147
+ }
148
+ /**
149
+ * 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
150
+ * 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`.
151
+ * 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);
152
+ * 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.
153
+ */
154
+ export async function resolveEnvFileAssignments(reading, names, opts = {}) {
155
+ const wanted = new Set(names);
156
+ // accumulate in Maps and define the answer's members at the end: an own `__proto__` / `constructor` name is data in the answer (defined, not assigned), never the object's prototype
157
+ const resolved = new Map();
158
+ const refusedBy = new Map();
159
+ for (const a of reading.assignments) {
160
+ if (!wanted.has(a.name) || refusedBy.has(a.name))
161
+ continue;
162
+ const outcome = a.written.startsWith("file:") ? await resolveFileRef(a.written.slice("file:".length), reading.root, opts.trust) : { ok: true, value: a.written };
163
+ if (outcome.ok)
164
+ resolved.set(a.name, outcome.value);
165
+ else {
166
+ refusedBy.set(a.name, { name: a.name, line: a.line, fault: outcome.fault, error: outcome.error });
167
+ if (opts.failFast === true)
168
+ break;
169
+ }
170
+ }
171
+ const values = {};
172
+ for (const [name, value] of resolved)
173
+ if (!refusedBy.has(name))
174
+ Object.defineProperty(values, name, { value, enumerable: true, writable: true, configurable: true });
175
+ return { values, refused: [...refusedBy.values()] };
71
176
  }
72
177
  /** Parse `<root>/.env` (KEY=VALUE, `#` comments, optional surrounding quotes) MERGED OVER process.env (the
73
178
  * file wins). The ONLY place secret VALUES live — the contract files carry env-NAMEs only. A `KEY=` with an
74
179
  * empty value IS present (the caller may treat empty as a weak warning). Absent .env → just process.env — absent
75
180
  * means no entry on the path (the one absence rule, `readTextIfPresent`): a DANGLING symbolic link at `.env` is present and unreadable, so it throws.
76
181
  * A `.env` value of `file:<path>` resolves to that file's trimmed content (file-NAME ref — key stays out of
77
- * env, contract stays env-NAME-only). Schema still rejects pasted plaintext (the contract field is a NAME). */
182
+ * env, contract stays env-NAME-only). Schema still rejects pasted plaintext (the contract field is a NAME).
183
+ * 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
184
+ * 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. */
78
185
  export async function loadEnvFile(root) {
79
186
  const merged = {};
80
187
  for (const [k, v] of Object.entries(process.env))
81
188
  if (v !== undefined)
82
189
  merged[k] = v;
83
- const text = await readTextIfPresent(path.join(root, ".env"));
84
- if (text === undefined)
85
- return merged;
86
- for (const raw of text.split("\n")) {
87
- const line = raw.trim();
88
- if (!line || line.startsWith("#"))
89
- continue;
90
- const eq = line.indexOf("=");
91
- if (eq <= 0)
92
- continue;
93
- let key = line.slice(0, eq).trim();
94
- if (key.startsWith("export "))
95
- key = key.slice("export ".length).trim(); // dotenv: strip the `export ` prefix
96
- if (!key)
97
- continue;
98
- let val = line.slice(eq + 1).trim();
99
- const quoted = (val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"));
100
- if (quoted) {
101
- val = val.slice(1, -1);
102
- }
103
- else {
104
- const hash = val.indexOf(" #"); // dotenv: strip an inline ` #...` comment from an UNQUOTED value
105
- if (hash >= 0)
106
- val = val.slice(0, hash).trimEnd();
107
- }
108
- if (val.startsWith("file:"))
109
- val = await resolveFileRef(val.slice("file:".length), root); // file-NAME secret ref
110
- merged[key] = val;
111
- }
190
+ const reading = await readEnvFileLines(root);
191
+ const { values, refused } = await resolveEnvFileAssignments(reading, reading.assignments.map((a) => a.name), { failFast: true });
192
+ if (refused[0] !== undefined)
193
+ throw refused[0].error;
194
+ for (const [k, v] of Object.entries(values))
195
+ merged[k] = v;
112
196
  return merged;
113
197
  }
114
198
  /** The ONE canonical local load — the service engine and the client CLI/desktop both call this so they cannot
@@ -1,5 +1,6 @@
1
1
  import { type McpContentOrigin } from "./types.js";
2
2
  import { type ReservedMemberName } from "./reserved-member-name.js";
3
+ import { type HookPluginOptionRef } from "./hooks-config.js";
3
4
  /** 值的**种类**(不回显值本身)。总(不抛):形状只问座位,读不出的对象说全包唯一的「检视不了」那一句。 */
4
5
  export declare function describeValueShape(v: unknown): string;
5
6
  /** 「不是字符串数组」的种类:数组里混了非串元素说那一句,否则回落到 {@link describeValueShape}。总(不抛):`isJsonArray` 是座位的总版。 */
@@ -46,22 +47,38 @@ export declare function describeBadContentOrigin(v: unknown): string;
46
47
  /**
47
48
  * 请求面读器**点名拒**的键的**原因词**(闭集,29.0.0)—— 与「表外未知键」分得开的那一类:读器认得这把键,知道它为什么不在请求面上。
48
49
  * · `key_retired`:`transport.assertionHeader`(http)—— 29.0.0 退役:托管连接器的断言是部署的声明(配置面的 `transport.credentials`),头名归引擎,请求不说它;
49
- * · `credentials_not_carried`:`transport.credentials`(两种传输)—— 请求面的 MCP 条目不承载凭据引用:引擎原语包的准入表(`CREDENTIAL_REF_TRUST`)对请求面拒 `env` / `handle` / `assertion`,
50
- * 其余种类(`vault`)在 MCP 传输上也没有座位;MCP 服务器的凭据是部署一侧的声明。请求面上 vault 引用唯一的座位是 hook command 条目的 `plugin.options` 的值(31.0.0 起,
51
- * `./hooks-config` 的 `HookPluginOptionRef`),与这里无关。
52
- * 读到这两把键之一(自有键、值不是 `undefined`)⇒ 硬坏形({@link RequestMcpTransportRead} 的 `ok:false`),`issue.refusal` = 这里的词、`issue.path` 点名那把键、`issue.reason` 是原因句(不回显值)。
50
+ * · `credentials_not_carried`:`transport.credentials` 这一个值请求面不收 —— stdio 传输上一切值(它没有凭据引用的座位);http 传输上读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 之外的一切:
51
+ * 引擎原语包的准入表(`CREDENTIAL_REF_TRUST`)对请求面拒的种类(`env` / `handle` / `assertion`)与各种坏形 —— 这些是部署一侧的声明,不由请求给。
52
+ * 请求面上 vault 引用的座位有两处:http 传输的 `credentials`(收下、不解析)与 hook command 条目的 `plugin.options` 的值(`./hooks-config` 的 `HookPluginOptionRef`)。
53
+ * 读到这两把键之一(自有键、值不是 `undefined`;`credentials` 在 http 上是读器表里的合形引用的除外)⇒ 硬坏形({@link RequestMcpTransportRead} 的 `ok:false`),`issue.refusal` = 这里的词、`issue.path` 点名那把键、`issue.reason` 是原因句(不回显值)。
53
54
  * 只靠继承可见 ⇒ 不读、不拒,进 `lost` 点名 —— 与身份头同一条律({@link axisKeyOf})。
54
55
  * 判序 = 读序:`kind` 之后先读这两把键(其余键一个都还没读)—— 一条带着点名拒的键的条目,不论别处坏不坏、读不读得出,都读成这一类;两把都在 ⇒ `assertionHeader` 先。
55
56
  * 消费方按词分派、不读句子;多一个词而穷尽 `switch` 不补 ⇒ 编译红。
56
57
  */
57
58
  export declare const MCP_REQUEST_KEY_REFUSALS: readonly ["key_retired", "credentials_not_carried"];
58
59
  export type McpRequestKeyRefusal = (typeof MCP_REQUEST_KEY_REFUSALS)[number];
60
+ /**
61
+ * 请求面 **http** 传输收下的凭据引用 = 本包「是不是保险库类引用」的**那一只判口** {@link readHookPluginOptionRef} 收的那一类(`./hooks-config`:钩子条目的插件选项值与这里是同一个问题 —— 提交者自己店里的条目,
62
+ * 别的种类从来不从请求面收);型就是它的 {@link HookPluginOptionRef}。这里不另判、不另写种类字。**本包只判形、不解析、不取值**:引用说的是哪一条目、条目在谁的店里、令牌从哪来、
63
+ * 与同条目里写死的 `Authorization` 头同在时怎么判,都是消费方的事。
64
+ */
65
+ export type McpRequestCredential = HookPluginOptionRef;
66
+ /** 请求面 http 传输收的引用的种类词(型)。 */
67
+ export type McpRequestCredentialKind = McpRequestCredential["kind"];
68
+ /**
69
+ * 请求面 **http** 传输的 `credentials` 收的引用**种类**(深冻结;stdio 传输一种都不收)。这是读器唯一的准入表:能力面派生的「请求面凭据引用种类」读它、文书点名它,不另抄一份。
70
+ * 表不是写下来的,是**向准入谓词 {@link requestPlaneTakes} 问出来的**:引擎原语包的每个种类,以判口读得出的形(`{ kind, entry }`)递给它问一次,它收,就在表里 —— 今天只有一种。
71
+ * 读器对一个值的准入问的是同一只谓词,所以表与读器不会各说各的。表里每个种类都是 `own_entry`、引擎的 `own_entry` 种类都在表里,由测试两向对拍(引擎再认一种而判口不收 ⇒ 红,逼着有人表态 http 收不收)。
72
+ */
73
+ export declare const MCP_REQUEST_CREDENTIAL_KINDS: readonly McpRequestCredentialKind[];
59
74
  /**
60
75
  * 请求面一条 MCP 条目的传输形。与引擎传输形的关系逐键一句(处置表,对拍 = 上游漂移门 ⑧):
61
76
  * · `kind` / `command` / `args` / `url` / `principalHeader` —— 与引擎同键同型;
62
77
  * · `env` / `headers` —— 请求带来的**字面件**:引擎的声明不带值(一台服务器的凭据头 / 子进程环境由部署的对端座每次发送时答),
63
78
  * 所以这两把键交给引擎之前由消费方从声明里拿走、按它自己的对端座答;
64
- * · 引擎的 `credentials`(不透明的凭据引用)—— 请求面不承载:在场 ⇒ 读器点名拒(`credentials_not_carried`,{@link MCP_REQUEST_KEY_REFUSALS})。
79
+ * · 引擎的 `credentials`(不透明的凭据引用)—— stdio 传输请求面不承载:在场 ⇒ 读器点名拒(`credentials_not_carried`,{@link MCP_REQUEST_KEY_REFUSALS});
80
+ * http 传输请求面**收窄**:只准入引擎引用种类里读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 的那几臂({@link McpRequestCredential},型恒等于引擎的型按这些种类取的那几臂,可选性同),
81
+ * 形合法就原样交出(本包不解析、不取值);表外的种类与坏形照旧点名拒。
65
82
  */
66
83
  export type RequestMcpTransport = {
67
84
  kind: "stdio";
@@ -73,6 +90,7 @@ export type RequestMcpTransport = {
73
90
  url: string;
74
91
  headers?: Record<string, string>;
75
92
  principalHeader?: string;
93
+ credentials?: McpRequestCredential;
76
94
  };
77
95
  /**
78
96
  * 条目内一处坏形:`path` = 条目内的键路径(`transport.url`),`reason` = 判官的原因句(只说形与词表,不回显值)。
@@ -105,6 +123,7 @@ export type RequestMcpTransportRead = {
105
123
  /**
106
124
  * 请求面 `transport` 的**唯一读器**:读器投影 transport 用它,发送前 / 受理时的判形读它报的 `lost` —— 同一只函数两个消费点,「读器丢了什么」与「门拒什么」不可能分岔。
107
125
  * · 硬坏形(`transport` 不是对象 / `kind` 出闭集 / 点名拒的键在场({@link MCP_REQUEST_KEY_REFUSALS},先于其余键判)/ stdio 缺 `command` / http 的 `url` 不是 http(s))⇒ `ok:false`,`path` 是读器点名的键路径;
126
+ * http 的 `credentials` 是读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 里的合形引用时**不是**点名拒:收下、(判口新造的冻结副本)进读后的传输,其余键照常往下读、照常判;
108
127
  * · 软坏形(`args` 不是串数组 / `env` `headers` 不是纯数据的串记录 / `principalHeader` 非串)⇒ 读器**丢这个键**(重放存量提交体时的升级前读法),并把它记进 `lost`
109
128
  * (受理新提交的门据它响亮拒);身份 / 凭据轴上的键({@link AXIS_KEYS}:`principalHeader` / `assertionHeader` / `credentials`)只靠继承可见 ⇒ 不读值、不拒、进 `lost` 点名;
110
129
  * · `env` / `headers` 只收**纯数据**的记录({@link readPlainStringRecord}):必须是朴素 JSON 对象(`./plain-json-object` 的判据;`Map`、`Set`、类实例整张不收),每个自有成员的值都是串;
@@ -16,7 +16,8 @@
16
16
  * · 申报名的线长界 {@link TOOL_WIRE_NAME_MAX_CHARS} = 引擎同名常量(值级对拍:上游漂移门 ⑧);
17
17
  * · 请求面传输形 {@link RequestMcpTransport} 对引擎 MCP 条目的传输形是一张处置表,两边每个键恰好一行(编译期两向对拍:门 ⑧)——
18
18
  * `kind` / `command` / `args` / `url` / `principalHeader` 与引擎同键同型;`env` / `headers` 是请求带来的字面件(引擎的声明不带值);
19
- * 引擎的 `credentials`(不透明的凭据引用)请求面不承载 —— 在场 ⇒ 读器点名拒({@link MCP_REQUEST_KEY_REFUSALS} 的 `credentials_not_carried`);
19
+ * 引擎的 `credentials`(不透明的凭据引用):stdio 传输请求面不承载 —— 在场 ⇒ 读器点名拒({@link MCP_REQUEST_KEY_REFUSALS} 的 `credentials_not_carried`);http 传输只收读器表
20
+ * {@link MCP_REQUEST_CREDENTIAL_KINDS} 里的种类(今天只有 `vault`),形合法就收下、原样交出 —— **本包不解析、不取值**,引用的意义归消费方;读器表外的种类与一切坏形照旧点名拒(「是不是引用」的判官是引擎原语包的读法、读自有可枚举键:请求体的多余成员它都看得见而拒,程序构造的对象才带得出的不可枚举 / Symbol 键的多余成员它读不到);
20
21
  * · 请求面点名拒的键(本包一份判法,消费方只做处置):`assertionHeader`(29.0.0 退役)与 `credentials`,见 {@link MCP_REQUEST_KEY_REFUSALS};
21
22
  * · 内容出处词表 = {@link MCP_CONTENT_ORIGINS}(已有的镜像,门 ⑥);
22
23
  * · url 前缀守卫 = `./url-shape` 的 `startsWithHttpScheme`(本包判 URL 的正则只在那一个模块)。它只看前缀,不是形判官 —— 同一个串两口可以答得不同,两张分歧表与收口形(S-2106)写在 `./url-shape` 头注「第二个答案」。
@@ -35,7 +36,8 @@ import { startsWithHttpScheme } from "./url-shape.js";
35
36
  import { TOOL_WIRE_NAME_MAX_CHARS, hasEdgeWhitespace, isUsableWireName } from "./wire-name.js";
36
37
  import { isReservedMemberName, reservedMemberSentence } from "./reserved-member-name.js";
37
38
  import { deepFreeze } from "./deep-freeze.js";
38
- import { CREDENTIAL_REF_TRUST, readCredentialRef } from "@sema-agent/primitives";
39
+ import { CREDENTIAL_REF_KINDS, CREDENTIAL_REF_TRUST, readCredentialRef } from "@sema-agent/primitives";
40
+ import { readHookPluginOptionRef } from "./hooks-config.js";
39
41
  import { retiredFormSentence } from "./retired-form.js";
40
42
  // ── 值的种类描述(拒句只说「你写的是什么形」,不回显值:值可能带凭据、可能任意长)──────────────────────────────────────
41
43
  /** 值的**种类词**(不回显值本身):`null` / `array` / `typeof` 词(`object` / `function` / `string` …);读不出的对象 ⇒ 全包唯一的那一句。形状只问座位(总,不抛):两只坏值描述器共用这一只。 */
@@ -165,7 +167,7 @@ export function describeBadContentOrigin(v) {
165
167
  }
166
168
  // ── 身份 / 凭据轴上的键 ─────────────────────────────────────────────────────────────────────────────
167
169
  /**
168
- * 传输上**身份 / 凭据轴**的键(闭集;也是 `lost` 里点名它们的次序):身份头 `principalHeader`,与点名拒的两把键 `assertionHeader` / `credentials`({@link MCP_REQUEST_KEY_REFUSALS})。
170
+ * 传输上**身份 / 凭据轴**的键(闭集;也是 `lost` 里点名它们的次序):身份头 `principalHeader`,与 `assertionHeader`(点名拒)/ `credentials`(stdio 上点名拒,http 上收读器表里的种类)({@link MCP_REQUEST_KEY_REFUSALS})。
169
171
  * 一条律、一只读法({@link axisKeyOf}):只认自有键;只靠继承可见 ⇒ 不读、进 `lost` 点名({@link inheritedAxisKeyIssue})。
170
172
  */
171
173
  const AXIS_KEYS = ["principalHeader", "assertionHeader", "credentials"];
@@ -183,10 +185,10 @@ function axisKeyOf(record, key) {
183
185
  /**
184
186
  * 请求面读器**点名拒**的键的**原因词**(闭集,29.0.0)—— 与「表外未知键」分得开的那一类:读器认得这把键,知道它为什么不在请求面上。
185
187
  * · `key_retired`:`transport.assertionHeader`(http)—— 29.0.0 退役:托管连接器的断言是部署的声明(配置面的 `transport.credentials`),头名归引擎,请求不说它;
186
- * · `credentials_not_carried`:`transport.credentials`(两种传输)—— 请求面的 MCP 条目不承载凭据引用:引擎原语包的准入表(`CREDENTIAL_REF_TRUST`)对请求面拒 `env` / `handle` / `assertion`,
187
- * 其余种类(`vault`)在 MCP 传输上也没有座位;MCP 服务器的凭据是部署一侧的声明。请求面上 vault 引用唯一的座位是 hook command 条目的 `plugin.options` 的值(31.0.0 起,
188
- * `./hooks-config` 的 `HookPluginOptionRef`),与这里无关。
189
- * 读到这两把键之一(自有键、值不是 `undefined`)⇒ 硬坏形({@link RequestMcpTransportRead} 的 `ok:false`),`issue.refusal` = 这里的词、`issue.path` 点名那把键、`issue.reason` 是原因句(不回显值)。
188
+ * · `credentials_not_carried`:`transport.credentials` 这一个值请求面不收 —— stdio 传输上一切值(它没有凭据引用的座位);http 传输上读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 之外的一切:
189
+ * 引擎原语包的准入表(`CREDENTIAL_REF_TRUST`)对请求面拒的种类(`env` / `handle` / `assertion`)与各种坏形 —— 这些是部署一侧的声明,不由请求给。
190
+ * 请求面上 vault 引用的座位有两处:http 传输的 `credentials`(收下、不解析)与 hook command 条目的 `plugin.options` 的值(`./hooks-config` 的 `HookPluginOptionRef`)。
191
+ * 读到这两把键之一(自有键、值不是 `undefined`;`credentials` 在 http 上是读器表里的合形引用的除外)⇒ 硬坏形({@link RequestMcpTransportRead} 的 `ok:false`),`issue.refusal` = 这里的词、`issue.path` 点名那把键、`issue.reason` 是原因句(不回显值)。
190
192
  * 只靠继承可见 ⇒ 不读、不拒,进 `lost` 点名 —— 与身份头同一条律({@link axisKeyOf})。
191
193
  * 判序 = 读序:`kind` 之后先读这两把键(其余键一个都还没读)—— 一条带着点名拒的键的条目,不论别处坏不坏、读不读得出,都读成这一类;两把都在 ⇒ `assertionHeader` 先。
192
194
  * 消费方按词分派、不读句子;多一个词而穷尽 `switch` 不补 ⇒ 编译红。
@@ -197,22 +199,53 @@ const ASSERTION_HEADER_RETIRED_ON_REQUEST = retiredFormSentence("transport.asser
197
199
  retiredIn: "29.0.0",
198
200
  now: "no request names it: a hosted connector's assertion is declared by the deployment (transport.credentials in its settings) and its header is the engine's — remove the key from the request",
199
201
  });
200
- /** 请求里出现的 `credentials` 为什么不收:原语包读得出且准入表对请求面拒这个种类 ⇒ 点名种类(闭集词);否则 ⇒ 请求面的 MCP 传输没有凭据引用的座位。两句都不回显值。 */
201
- function credentialsNotCarriedReason(raw) {
202
+ /** 问判口「你收这一种吗」时递的条目名(任何合形的条目名都行,值不进任何出口)。 */
203
+ const KIND_PROBE_ENTRY = "probe";
204
+ /**
205
+ * 请求面 **http** 传输收不收一个值 —— **准入的唯一一处合取**:判口 {@link readHookPluginOptionRef} 收它 ∧ 引擎准入表对请求面仍是 `own_entry`(引擎哪天收回某种类的准入,读器随它拒,读器表也随它空)。
206
+ * 收 ⇒ 判口新造的引用(尚未冻结);不收 ⇒ `undefined`。读器表({@link MCP_REQUEST_CREDENTIAL_KINDS})与读器({@link judgeCredentials})都问它,谁也不另写这个合取。
207
+ */
208
+ function requestPlaneTakes(value) {
209
+ const ref = readHookPluginOptionRef(value);
210
+ return ref !== undefined && CREDENTIAL_REF_TRUST[ref.kind].request === "own_entry" ? ref : undefined;
211
+ }
212
+ /**
213
+ * 请求面 **http** 传输的 `credentials` 收的引用**种类**(深冻结;stdio 传输一种都不收)。这是读器唯一的准入表:能力面派生的「请求面凭据引用种类」读它、文书点名它,不另抄一份。
214
+ * 表不是写下来的,是**向准入谓词 {@link requestPlaneTakes} 问出来的**:引擎原语包的每个种类,以判口读得出的形(`{ kind, entry }`)递给它问一次,它收,就在表里 —— 今天只有一种。
215
+ * 读器对一个值的准入问的是同一只谓词,所以表与读器不会各说各的。表里每个种类都是 `own_entry`、引擎的 `own_entry` 种类都在表里,由测试两向对拍(引擎再认一种而判口不收 ⇒ 红,逼着有人表态 http 收不收)。
216
+ */
217
+ export const MCP_REQUEST_CREDENTIAL_KINDS = deepFreeze(CREDENTIAL_REF_KINDS.filter((kind) => requestPlaneTakes({ kind, entry: KIND_PROBE_ENTRY }) !== undefined));
218
+ const CREDENTIALS_ABSENT = { kind: "absent" };
219
+ const credentialsRefused = (reason) => ({ kind: "refused", reason });
220
+ /** http 传输上「不是读器收的引用」的原因句:说清收什么(种类取自读器表),不回显值。 */
221
+ const HTTP_CREDENTIALS_NOT_TAKEN = `an MCP http entry in a request takes a credential reference of kind ${MCP_REQUEST_CREDENTIAL_KINDS.map((k) => `"${k}"`).join(" or ")} only — this value is not one (every other kind is declared by the deployment); correct transport.credentials or remove it from the request`;
222
+ /** stdio 传输上一切 `credentials` 的原因句(它没有凭据引用的座位)。 */
223
+ const STDIO_CREDENTIALS_NO_SEAT = "an MCP server entry in a request carries no credential reference (its transport has no seat for one; the deployment declares it) — remove transport.credentials from the request";
224
+ /**
225
+ * 请求里一个 `credentials` 值(自有键、已读出)的判。**调用方的值只读一次**(原语包读法 `readCredentialRef`,本模块的唯一调用处):读得出且准入表对请求面拒这个种类(`env` / `handle` / `assertion`)⇒ 拒,点名种类(两种传输同句);
226
+ * 否则 stdio ⇒ 拒(没有座位);http 上把读出的安全副本问判口 {@link readHookPluginOptionRef}(「是不是保险库类引用」整个包里只此一只判口),判口收且引擎准入表对请求面仍是 `own_entry` ⇒ 收下 —— 交出的是判口新造的冻结副本,
227
+ * 不是调用方的对象;其余 ⇒ 拒(说清收什么)。句子都不回显值。
228
+ */
229
+ function judgeCredentials(transport, raw) {
230
+ if (raw === undefined)
231
+ return CREDENTIALS_ABSENT;
202
232
  const read = readCredentialRef(raw);
203
233
  if (read.ok && CREDENTIAL_REF_TRUST[read.ref.kind].request === "refused") {
204
- return `a credential reference of kind "${read.ref.kind}" is never taken from a request (the deployment declares it for this server) — remove transport.credentials from the request`;
234
+ return credentialsRefused(`a credential reference of kind "${read.ref.kind}" is never taken from a request (the deployment declares it for this server) — remove transport.credentials from the request`);
205
235
  }
206
- return "an MCP server entry in a request carries no credential reference (its transport has no seat for one; the deployment declares it) — remove transport.credentials from the request";
236
+ if (transport === "stdio")
237
+ return credentialsRefused(STDIO_CREDENTIALS_NO_SEAT);
238
+ const taken = read.ok ? requestPlaneTakes(read.ref) : undefined;
239
+ return taken !== undefined ? { kind: "taken", credential: deepFreeze(taken) } : credentialsRefused(HTTP_CREDENTIALS_NOT_TAKEN);
207
240
  }
208
241
  /** 点名拒的硬坏形(机读词在 `refusal`)。 */
209
242
  const keyRefused = (path, reason, refusal) => ({ ok: false, issue: { path, reason, refusal } });
210
- /** 点名拒的第一把键(判序见 {@link MCP_REQUEST_KEY_REFUSALS});没有 ⇒ `undefined`。入参是已读出的自有值(stdio 没有 `assertionHeader` 这一格:调用方传 `undefined`)。 */
243
+ /** 点名拒的第一把键(判序见 {@link MCP_REQUEST_KEY_REFUSALS});没有 ⇒ `undefined`。入参是已读出的自有值与 `credentials` 的判(stdio 没有 `assertionHeader` 这一格:调用方传 `undefined`)。 */
211
244
  function refusedKeyOf(assertionHeader, credentials) {
212
245
  if (assertionHeader !== undefined)
213
246
  return keyRefused("transport.assertionHeader", ASSERTION_HEADER_RETIRED_ON_REQUEST, "key_retired");
214
- if (credentials !== undefined)
215
- return keyRefused("transport.credentials", credentialsNotCarriedReason(credentials), "credentials_not_carried");
247
+ if (credentials.kind === "refused")
248
+ return keyRefused("transport.credentials", credentials.reason, "credentials_not_carried");
216
249
  return undefined;
217
250
  }
218
251
  const transportBad = (path, reason) => ({ ok: false, issue: { path, reason } });
@@ -226,6 +259,7 @@ const inheritedAxisKeyIssues = (inherited) => AXIS_KEYS.filter((key) => inherite
226
259
  /**
227
260
  * 请求面 `transport` 的**唯一读器**:读器投影 transport 用它,发送前 / 受理时的判形读它报的 `lost` —— 同一只函数两个消费点,「读器丢了什么」与「门拒什么」不可能分岔。
228
261
  * · 硬坏形(`transport` 不是对象 / `kind` 出闭集 / 点名拒的键在场({@link MCP_REQUEST_KEY_REFUSALS},先于其余键判)/ stdio 缺 `command` / http 的 `url` 不是 http(s))⇒ `ok:false`,`path` 是读器点名的键路径;
262
+ * http 的 `credentials` 是读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 里的合形引用时**不是**点名拒:收下、(判口新造的冻结副本)进读后的传输,其余键照常往下读、照常判;
229
263
  * · 软坏形(`args` 不是串数组 / `env` `headers` 不是纯数据的串记录 / `principalHeader` 非串)⇒ 读器**丢这个键**(重放存量提交体时的升级前读法),并把它记进 `lost`
230
264
  * (受理新提交的门据它响亮拒);身份 / 凭据轴上的键({@link AXIS_KEYS}:`principalHeader` / `assertionHeader` / `credentials`)只靠继承可见 ⇒ 不读值、不拒、进 `lost` 点名;
231
265
  * · `env` / `headers` 只收**纯数据**的记录({@link readPlainStringRecord}):必须是朴素 JSON 对象(`./plain-json-object` 的判据;`Map`、`Set`、类实例整张不收),每个自有成员的值都是串;
@@ -296,6 +330,7 @@ export function readRequestMcpTransport(t) {
296
330
  url: snap.url,
297
331
  ...(headers.record !== undefined ? { headers: headers.record } : {}),
298
332
  ...(principalHeader !== undefined ? { principalHeader } : {}),
333
+ ...(snap.credentials !== undefined ? { credentials: snap.credentials } : {}),
299
334
  },
300
335
  lost: issuesOf(...headers.issues, principalIssue, ...inheritedAxisKeyIssues(snap.inherited)),
301
336
  };
@@ -328,7 +363,7 @@ function snapshotTransport(tr) {
328
363
  const credentials = axis("credentials");
329
364
  if (!credentials.ok)
330
365
  return credentials;
331
- const refused = refusedKeyOf(undefined, credentials.value);
366
+ const refused = refusedKeyOf(undefined, judgeCredentials("stdio", credentials.value));
332
367
  if (refused !== undefined)
333
368
  return { ok: true, value: { kind: "refused", read: refused } };
334
369
  const fields = ownFieldsOf(tr, ["command", "args", "env"]);
@@ -343,7 +378,9 @@ function snapshotTransport(tr) {
343
378
  const credentials = axis("credentials");
344
379
  if (!credentials.ok)
345
380
  return credentials;
346
- const refused = refusedKeyOf(assertionHeader.value, credentials.value);
381
+ // 判序 = 读序:`assertionHeader` 在场 ⇒ 先答 `key_retired`,调用方交来的 `credentials` 值一个成员都不碰(不为一个注定要拒的条目多跑调用方的代码);不在场才判它
382
+ const verdict = assertionHeader.value === undefined ? judgeCredentials("http", credentials.value) : CREDENTIALS_ABSENT;
383
+ const refused = refusedKeyOf(assertionHeader.value, verdict);
347
384
  if (refused !== undefined)
348
385
  return { ok: true, value: { kind: "refused", read: refused } };
349
386
  const fields = ownFieldsOf(tr, ["url", "headers"]);
@@ -352,7 +389,10 @@ function snapshotTransport(tr) {
352
389
  const principalHeader = axis("principalHeader");
353
390
  if (!principalHeader.ok)
354
391
  return principalHeader;
355
- return { ok: true, value: { kind: "http", url: fields.value.url, headers: fields.value.headers, principalHeader: principalHeader.value, inherited } };
392
+ return {
393
+ ok: true,
394
+ value: { kind: "http", url: fields.value.url, headers: fields.value.headers, principalHeader: principalHeader.value, credentials: verdict.kind === "taken" ? verdict.credential : undefined, inherited },
395
+ };
356
396
  }
357
397
  return { ok: true, value: { kind: "other", value: kind.value } };
358
398
  }
package/dist/node.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./bundle.js";
10
10
  export * from "./local-load.js";
11
11
  export { readConfigDFileReadingSync, type ConfigDDocumentName, type ConfigDFileReason, type ConfigDReading, type ConfigDRefused } from "./config-d-file.js";
12
12
  export * from "./scheduler-store-node.js";
13
+ export { tryWebAdminCredentialFileLock, type WebAdminCredentialLockHeld, type WebAdminCredentialLockOutcome } from "./atomic-write.js";
13
14
  export { migrateConfigDirectory, migrateConfigDocuments, // 14.5.0:同一段「迁 → 整域终判」的同步口(入参是已有的存量文档,无 io)—— 目录形调的就是它的内核
14
15
  type ConfigDirectoryDocument, type ConfigDirectoryIo, type ConfigDirectoryMigration, type ConfigDirectoryRefusal, type ConfigDocumentsMigration, type MigrateConfigDirectoryOptions, type MigrateConfigDocumentsOptions, } from "./config-dir-migration.js";
15
16
  export { nodeConfigDirectoryIo } from "./config-dir-io.js";
package/dist/node.js CHANGED
@@ -11,6 +11,8 @@ export * from "./local-load.js";
11
11
  // 一份 `config.d/<名>.json` 的读数(缺席 / 在场 / 被拒)的**同步读口**:与包内异步读口同一只纯判、同一个缺席尾(壳在同步具名锁里读 `config.d` 文档用它,不自读文本);纯判本身与异步读口不出门。显式列名。
12
12
  export { readConfigDFileReadingSync } from "./config-d-file.js";
13
13
  export * from "./scheduler-store-node.js"; // R7 self-wake scheduler store — fs binding of the ./scheduler-store contract
14
+ // web-admin 凭证文件的单写者锁(协议常量与锁名在包根):取锁 → 锁内读真目标 → 回调「比较再写」→ 核身份后落 → 放锁。实现与原子写器同在写盘原语层;显式列名,该层的包内件不外泄。
15
+ export { tryWebAdminCredentialFileLock } from "./atomic-write.js";
14
16
  // 目录形的一次性迁移(读目录 → 迁 → 整域终判 → 原子写;从不删文件)—— 语义只此一处,命令行是它的渲染器、引擎起服调同一只。显式列名:该模块的包内私有件(出门形/拼路径)不外泄。
15
17
  export { migrateConfigDirectory, migrateConfigDocuments, // 14.5.0:同一段「迁 → 整域终判」的同步口(入参是已有的存量文档,无 io)—— 目录形调的就是它的内核
16
18
  } from "./config-dir-migration.js";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 读腿读不进一份文档(或一条条目)时的**诊断句措辞** —— 包内私有(不进主桶),纯字符串函数,只 import 两只零 import 的叶(形状座位、一行回显的剥除集),所以谁都能调、不成环;句子**不含换行与双向控制符**(回显进来的键名 / 值 / 别人的句子都过 `stripControlAndBidi`)。
3
3
  *
4
- * 在这里铸的(照实):读腿两条告警的一句话({@link droppedEntrySentence} / {@link defaultedDomainSentence})、issue 的一句话({@link issueSentence})、
4
+ * 在这里铸的(照实):读腿两条告警与域读拒的一句话({@link droppedEntrySentence} / {@link defaultedDomainSentence} / {@link refusedDomainSentence})、issue 的一句话({@link issueSentence})、
5
5
  * 条目身份与原因的小段字,以及「读腿会怎么处置一份读不进的域文档」的后果句({@link readConsequenceSentence} —— 命令行 `migrate` 对在场文档的拒句取它)。
6
6
  * 不在这里铸的:retired 域的墓碑句与它的出路(`./retired-form`,读写两面同一句)、命令行 `migrate` 拒句里 retired 域 / `remote-exec` 的后果、
7
7
  * 「在 `<文件>` 里手改」那一截与整份 `why`(`./config-dir-migration`)。句子**一句一行**(不含换行):它们被日志、终端、网页端、管理台逐字渲染,
@@ -23,10 +23,13 @@ export interface IssueLike {
23
23
  readonly message: string;
24
24
  readonly code?: string;
25
25
  readonly errors?: unknown;
26
+ readonly issues?: unknown;
26
27
  }
27
28
  /**
28
- * 一条 zod issue 的**一句话**(不含换行):联合(`invalid_union`)自己只说 `Invalid input`,真正的拒句在各选项的 issue 里 —— 取各选项第一条的句子(去重,至多三条,用 ` / ` 连);
29
- * 别的 issue 就是它自己的 `message`(换行折成空格)。出门前这些句子已经过本包唯一的脱敏器(`sanitizeZodError` 递归进联合的 `errors`),这里只读不改。
29
+ * 一条 zod issue 的**一句话**(不含换行):zod 把真正的拒句嵌在 issue 里面,外层自己只说一句泛话 —— 联合(`invalid_union`)说 `Invalid input`、真正的拒句在各选项的 issue 里
30
+ * (取各选项第一条的句子,去重,至多三条,用 ` / ` 连);记录的坏键(`invalid_key`)说 `Invalid key in record`、键自己那张 schema 的拒句在它的 `issues` 里(同样读进去:
31
+ * 所有条目的坏键都在这里读,命令行 `migrate` 的拒因、读腿告警、域读拒与逐条丢弃那条告警里「坏键」说的是同一句);`invalid_element` 同形。
32
+ * 别的 issue 就是它自己的 `message`(换行折成空格)。出门前这些句子已经过本包唯一的脱敏器(`sanitizeZodError` 递归进这三处嵌套),这里只读不改。
30
33
  */
31
34
  export declare function issueSentence(issue: IssueLike, depth?: number): string;
32
35
  /** 一条 issue 的坐标(出门形的串,空串 = 在文档 / 条目的根上)与它的一句话。 */
@@ -62,6 +65,14 @@ export declare function defaultedDomainSentence(a: {
62
65
  readonly cause: string;
63
66
  readonly culprit: string | undefined;
64
67
  }): string;
68
+ /**
69
+ * 域读拒(`DomainReadRefusedError`)的一句话:哪个域读不进 · 为什么(触发的坐标与原因,每条 `<坐标>: <句子>`)。`cause` 是 {@link causeText} 的答案(与上面两句同一只原因段);读不出原因 ⇒ 只剩点名域的前半句。
70
+ * 句子只有这一行:坐标在原因段的开头、紧跟点名域的前半句 —— 下游把一行截到定长(运维行的 `err` 字段)时,坐标留在被保留的那一头(原拒的 JSON 文本里坐标排在很后面)。
71
+ */
72
+ export declare function refusedDomainSentence(a: {
73
+ readonly domain: string;
74
+ readonly cause: string;
75
+ }): string;
65
76
  /** 读腿对「这个域的文档读不进」的处置,一句话(不含换行;`domain` 是闭集里的域名)。两张表各答一半、各自穷举:`fallback` 说整域读不进时怎么办,
66
77
  * `salvage` 说先不先丢那一条 —— 两半拼成一句,四种组合各有自己的话(「整域拒 + 逐条丢」的域两半都说)。 */
67
78
  export declare function readConsequenceSentence(domain: string, stance: ReadStanceWords): string;