@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +664 -0
  2. package/README.md +138 -19
  3. package/conformance/VERSION +1 -1
  4. package/dist/api/credentials.d.ts +94 -14
  5. package/dist/api/credentials.js +33 -8
  6. package/dist/atomic-write.d.ts +68 -3
  7. package/dist/atomic-write.js +314 -4
  8. package/dist/cli.d.ts +5 -2
  9. package/dist/cli.js +15 -3
  10. package/dist/config-d-file.d.ts +0 -3
  11. package/dist/config-d-file.js +1 -6
  12. package/dist/config-dir-migration.d.ts +2 -1
  13. package/dist/config-dir-migration.js +34 -20
  14. package/dist/config-fns.d.ts +60 -14
  15. package/dist/config-fns.js +48 -13
  16. package/dist/conformance/index.d.ts +1 -0
  17. package/dist/conformance/index.js +2 -0
  18. package/dist/conformance/warnings.d.ts +1 -1
  19. package/dist/conformance/warnings.js +3 -3
  20. package/dist/conformance/web-admin-credential-lock.d.ts +17 -0
  21. package/dist/conformance/web-admin-credential-lock.js +347 -0
  22. package/dist/hooks-config.d.ts +12 -4
  23. package/dist/hooks-config.js +28 -11
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.js +3 -2
  26. package/dist/local-load.d.ts +66 -1
  27. package/dist/local-load.js +123 -39
  28. package/dist/mcp-request-entry.d.ts +43 -5
  29. package/dist/mcp-request-entry.js +60 -18
  30. package/dist/node.d.ts +1 -0
  31. package/dist/node.js +2 -0
  32. package/dist/plugin-id-segment.d.ts +15 -0
  33. package/dist/plugin-id-segment.js +15 -0
  34. package/dist/plugin-settings.d.ts +61 -0
  35. package/dist/plugin-settings.js +111 -0
  36. package/dist/read-sentences.d.ts +14 -3
  37. package/dist/read-sentences.js +32 -11
  38. package/dist/safety-merge-spec.d.ts +7 -7
  39. package/dist/safety-merge-spec.js +5 -3
  40. package/dist/settings-units.d.ts +35 -1
  41. package/dist/settings-units.js +51 -16
  42. package/dist/types.d.ts +13 -6
  43. package/dist/types.js +37 -11
  44. package/dist/ui-language.d.ts +3 -1
  45. package/dist/ui-language.js +3 -1
  46. package/dist/web-admin-credential.d.ts +14 -1
  47. package/dist/web-admin-credential.js +15 -1
  48. package/docs/API-SURFACE.md +60 -5
  49. package/docs/CONFORMANCE.md +19 -2
  50. package/docs/CONSUMER-INTEGRATION.md +165 -11
  51. package/llms-full.txt +51 -16
  52. package/llms.txt +18 -8
  53. package/package.json +5 -1
@@ -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,57 @@ 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[];
74
+ /** {@link readRequestMcpCredentials} 的答案:缺席 / 收下(带判口新造的冻结副本)/ 拒(带机读词 `credentials_not_carried` 与原因句)。三臂均深冻结。 */
75
+ export type RequestMcpCredentialsVerdict = {
76
+ readonly kind: "absent";
77
+ } | {
78
+ readonly kind: "taken";
79
+ readonly credential: McpRequestCredential;
80
+ } | {
81
+ readonly kind: "refused";
82
+ readonly refusal: Extract<McpRequestKeyRefusal, "credentials_not_carried">;
83
+ readonly reason: string;
84
+ };
85
+ /**
86
+ * 请求面「这一个已读出的 `credentials` 值收不收」的**唯一判口**:传输读器 {@link readRequestMcpTransport} 调的就是这一只。
87
+ * **只判值**:「键只靠继承可见 ⇒ 不读、进 `lost`」与「`assertionHeader` 在场 ⇒ 整条先拒、不判 `credentials`」是读器读整条传输时的律,判口没有这些上下文 —— 两者在同一个已读出的值上同答,不在整条传输的读法与判序上同答。
88
+ * **调用方的值只读一次**(原语包读法 `readCredentialRef`,本模块的唯一调用处):读得出且准入表对请求面拒这个种类(`env` / `handle` / `assertion`)⇒ 拒,点名种类(两种传输同句);
89
+ * 否则 stdio ⇒ 拒(没有座位);http 上把读出的安全副本问判口 {@link readHookPluginOptionRef}(「是不是保险库类引用」整个包里只此一只判口),判口收且引擎准入表对请求面仍是 `own_entry` ⇒ 收下 —— 交出的是判口新造的冻结副本,不是调用方的对象;其余 ⇒ 拒(说清收什么)。
90
+ * 三臂答案均深冻结;拒臂的 `refusal` 与读器放进 `issue.refusal` 的是同一个机读词({@link MCP_REQUEST_KEY_REFUSALS} 的 `credentials_not_carried`);句子都不回显值。
91
+ */
92
+ export declare function readRequestMcpCredentials(transport: "stdio" | "http", value: unknown): RequestMcpCredentialsVerdict;
59
93
  /**
60
94
  * 请求面一条 MCP 条目的传输形。与引擎传输形的关系逐键一句(处置表,对拍 = 上游漂移门 ⑧):
61
95
  * · `kind` / `command` / `args` / `url` / `principalHeader` —— 与引擎同键同型;
62
96
  * · `env` / `headers` —— 请求带来的**字面件**:引擎的声明不带值(一台服务器的凭据头 / 子进程环境由部署的对端座每次发送时答),
63
97
  * 所以这两把键交给引擎之前由消费方从声明里拿走、按它自己的对端座答;
64
- * · 引擎的 `credentials`(不透明的凭据引用)—— 请求面不承载:在场 ⇒ 读器点名拒(`credentials_not_carried`,{@link MCP_REQUEST_KEY_REFUSALS})。
98
+ * · 引擎的 `credentials`(不透明的凭据引用)—— stdio 传输请求面不承载:在场 ⇒ 读器点名拒(`credentials_not_carried`,{@link MCP_REQUEST_KEY_REFUSALS});
99
+ * http 传输请求面**收窄**:只准入引擎引用种类里读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 的那几臂({@link McpRequestCredential},型恒等于引擎的型按这些种类取的那几臂,可选性同),
100
+ * 形合法就原样交出(本包不解析、不取值);表外的种类与坏形照旧点名拒。
65
101
  */
66
102
  export type RequestMcpTransport = {
67
103
  kind: "stdio";
@@ -73,6 +109,7 @@ export type RequestMcpTransport = {
73
109
  url: string;
74
110
  headers?: Record<string, string>;
75
111
  principalHeader?: string;
112
+ credentials?: McpRequestCredential;
76
113
  };
77
114
  /**
78
115
  * 条目内一处坏形:`path` = 条目内的键路径(`transport.url`),`reason` = 判官的原因句(只说形与词表,不回显值)。
@@ -105,6 +142,7 @@ export type RequestMcpTransportRead = {
105
142
  /**
106
143
  * 请求面 `transport` 的**唯一读器**:读器投影 transport 用它,发送前 / 受理时的判形读它报的 `lost` —— 同一只函数两个消费点,「读器丢了什么」与「门拒什么」不可能分岔。
107
144
  * · 硬坏形(`transport` 不是对象 / `kind` 出闭集 / 点名拒的键在场({@link MCP_REQUEST_KEY_REFUSALS},先于其余键判)/ stdio 缺 `command` / http 的 `url` 不是 http(s))⇒ `ok:false`,`path` 是读器点名的键路径;
145
+ * http 的 `credentials` 是读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 里的合形引用时**不是**点名拒:收下、(判口新造的冻结副本)进读后的传输,其余键照常往下读、照常判;
108
146
  * · 软坏形(`args` 不是串数组 / `env` `headers` 不是纯数据的串记录 / `principalHeader` 非串)⇒ 读器**丢这个键**(重放存量提交体时的升级前读法),并把它记进 `lost`
109
147
  * (受理新提交的门据它响亮拒);身份 / 凭据轴上的键({@link AXIS_KEYS}:`principalHeader` / `assertionHeader` / `credentials`)只靠继承可见 ⇒ 不读值、不拒、进 `lost` 点名;
110
148
  * · `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,55 @@ 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
- const read = readCredentialRef(raw);
202
+ /** 问判口「你收这一种吗」时递的条目名(任何合形的条目名都行,值不进任何出口)。 */
203
+ const KIND_PROBE_ENTRY = "probe";
204
+ /**
205
+ * 请求面 **http** 传输收不收一个值 —— **准入的唯一一处合取**:判口 {@link readHookPluginOptionRef} 收它 ∧ 引擎准入表对请求面仍是 `own_entry`(引擎哪天收回某种类的准入,读器随它拒,读器表也随它空)。
206
+ * 收 ⇒ 判口新造的引用(尚未冻结);不收 ⇒ `undefined`。读器表({@link MCP_REQUEST_CREDENTIAL_KINDS})与读器({@link readRequestMcpCredentials})都问它,谁也不另写这个合取。
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 = deepFreeze({ kind: "absent" });
219
+ const credentialsRefused = (reason) => deepFreeze({ kind: "refused", refusal: "credentials_not_carried", 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` 值收不收」的**唯一判口**:传输读器 {@link readRequestMcpTransport} 调的就是这一只。
226
+ * **只判值**:「键只靠继承可见 ⇒ 不读、进 `lost`」与「`assertionHeader` 在场 ⇒ 整条先拒、不判 `credentials`」是读器读整条传输时的律,判口没有这些上下文 —— 两者在同一个已读出的值上同答,不在整条传输的读法与判序上同答。
227
+ * **调用方的值只读一次**(原语包读法 `readCredentialRef`,本模块的唯一调用处):读得出且准入表对请求面拒这个种类(`env` / `handle` / `assertion`)⇒ 拒,点名种类(两种传输同句);
228
+ * 否则 stdio ⇒ 拒(没有座位);http 上把读出的安全副本问判口 {@link readHookPluginOptionRef}(「是不是保险库类引用」整个包里只此一只判口),判口收且引擎准入表对请求面仍是 `own_entry` ⇒ 收下 —— 交出的是判口新造的冻结副本,不是调用方的对象;其余 ⇒ 拒(说清收什么)。
229
+ * 三臂答案均深冻结;拒臂的 `refusal` 与读器放进 `issue.refusal` 的是同一个机读词({@link MCP_REQUEST_KEY_REFUSALS} 的 `credentials_not_carried`);句子都不回显值。
230
+ */
231
+ export function readRequestMcpCredentials(transport, value) {
232
+ if (value === undefined)
233
+ return CREDENTIALS_ABSENT;
234
+ const read = readCredentialRef(value);
203
235
  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`;
236
+ 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
237
  }
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";
238
+ if (transport === "stdio")
239
+ return credentialsRefused(STDIO_CREDENTIALS_NO_SEAT);
240
+ const taken = read.ok ? requestPlaneTakes(read.ref) : undefined;
241
+ return taken !== undefined ? deepFreeze({ kind: "taken", credential: deepFreeze(taken) }) : credentialsRefused(HTTP_CREDENTIALS_NOT_TAKEN);
207
242
  }
208
243
  /** 点名拒的硬坏形(机读词在 `refusal`)。 */
209
244
  const keyRefused = (path, reason, refusal) => ({ ok: false, issue: { path, reason, refusal } });
210
- /** 点名拒的第一把键(判序见 {@link MCP_REQUEST_KEY_REFUSALS});没有 ⇒ `undefined`。入参是已读出的自有值(stdio 没有 `assertionHeader` 这一格:调用方传 `undefined`)。 */
245
+ /** 点名拒的第一把键(判序见 {@link MCP_REQUEST_KEY_REFUSALS});没有 ⇒ `undefined`。入参是已读出的自有值与 `credentials` 的判(stdio 没有 `assertionHeader` 这一格:调用方传 `undefined`)。 */
211
246
  function refusedKeyOf(assertionHeader, credentials) {
212
247
  if (assertionHeader !== undefined)
213
248
  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");
249
+ if (credentials.kind === "refused")
250
+ return keyRefused("transport.credentials", credentials.reason, credentials.refusal);
216
251
  return undefined;
217
252
  }
218
253
  const transportBad = (path, reason) => ({ ok: false, issue: { path, reason } });
@@ -226,6 +261,7 @@ const inheritedAxisKeyIssues = (inherited) => AXIS_KEYS.filter((key) => inherite
226
261
  /**
227
262
  * 请求面 `transport` 的**唯一读器**:读器投影 transport 用它,发送前 / 受理时的判形读它报的 `lost` —— 同一只函数两个消费点,「读器丢了什么」与「门拒什么」不可能分岔。
228
263
  * · 硬坏形(`transport` 不是对象 / `kind` 出闭集 / 点名拒的键在场({@link MCP_REQUEST_KEY_REFUSALS},先于其余键判)/ stdio 缺 `command` / http 的 `url` 不是 http(s))⇒ `ok:false`,`path` 是读器点名的键路径;
264
+ * http 的 `credentials` 是读器表 {@link MCP_REQUEST_CREDENTIAL_KINDS} 里的合形引用时**不是**点名拒:收下、(判口新造的冻结副本)进读后的传输,其余键照常往下读、照常判;
229
265
  * · 软坏形(`args` 不是串数组 / `env` `headers` 不是纯数据的串记录 / `principalHeader` 非串)⇒ 读器**丢这个键**(重放存量提交体时的升级前读法),并把它记进 `lost`
230
266
  * (受理新提交的门据它响亮拒);身份 / 凭据轴上的键({@link AXIS_KEYS}:`principalHeader` / `assertionHeader` / `credentials`)只靠继承可见 ⇒ 不读值、不拒、进 `lost` 点名;
231
267
  * · `env` / `headers` 只收**纯数据**的记录({@link readPlainStringRecord}):必须是朴素 JSON 对象(`./plain-json-object` 的判据;`Map`、`Set`、类实例整张不收),每个自有成员的值都是串;
@@ -296,6 +332,7 @@ export function readRequestMcpTransport(t) {
296
332
  url: snap.url,
297
333
  ...(headers.record !== undefined ? { headers: headers.record } : {}),
298
334
  ...(principalHeader !== undefined ? { principalHeader } : {}),
335
+ ...(snap.credentials !== undefined ? { credentials: snap.credentials } : {}),
299
336
  },
300
337
  lost: issuesOf(...headers.issues, principalIssue, ...inheritedAxisKeyIssues(snap.inherited)),
301
338
  };
@@ -328,7 +365,7 @@ function snapshotTransport(tr) {
328
365
  const credentials = axis("credentials");
329
366
  if (!credentials.ok)
330
367
  return credentials;
331
- const refused = refusedKeyOf(undefined, credentials.value);
368
+ const refused = refusedKeyOf(undefined, readRequestMcpCredentials("stdio", credentials.value));
332
369
  if (refused !== undefined)
333
370
  return { ok: true, value: { kind: "refused", read: refused } };
334
371
  const fields = ownFieldsOf(tr, ["command", "args", "env"]);
@@ -343,7 +380,9 @@ function snapshotTransport(tr) {
343
380
  const credentials = axis("credentials");
344
381
  if (!credentials.ok)
345
382
  return credentials;
346
- const refused = refusedKeyOf(assertionHeader.value, credentials.value);
383
+ // 判序 = 读序:`assertionHeader` 在场 ⇒ 先答 `key_retired`,调用方交来的 `credentials` 值一个成员都不碰(不为一个注定要拒的条目多跑调用方的代码);不在场才判它
384
+ const verdict = assertionHeader.value === undefined ? readRequestMcpCredentials("http", credentials.value) : CREDENTIALS_ABSENT;
385
+ const refused = refusedKeyOf(assertionHeader.value, verdict);
347
386
  if (refused !== undefined)
348
387
  return { ok: true, value: { kind: "refused", read: refused } };
349
388
  const fields = ownFieldsOf(tr, ["url", "headers"]);
@@ -352,7 +391,10 @@ function snapshotTransport(tr) {
352
391
  const principalHeader = axis("principalHeader");
353
392
  if (!principalHeader.ok)
354
393
  return principalHeader;
355
- return { ok: true, value: { kind: "http", url: fields.value.url, headers: fields.value.headers, principalHeader: principalHeader.value, inherited } };
394
+ return {
395
+ ok: true,
396
+ value: { kind: "http", url: fields.value.url, headers: fields.value.headers, principalHeader: principalHeader.value, credentials: verdict.kind === "taken" ? verdict.credential : undefined, inherited },
397
+ };
356
398
  }
357
399
  return { ok: true, value: { kind: "other", value: kind.value } };
358
400
  }
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";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 包内私有(不进 exports 表、不进主桶):**插件 id 一段的文法** —— 全包唯一的定义,**零 import 的叶**。
3
+ *
4
+ * 一个插件 id `<名>@<市场>` 的两半(名、市场)读同一条文法:字母或数字起头,后接字母 / 数字 / `.` / `_` / `-`,不分大小写。
5
+ * 三处读它:`PluginSpec.name`、`PluginSource` 的 marketplace 臂(都在 `./types`),与插件 id 的读法 `readPluginId`(`./plugin-settings`)。
6
+ * 对 `readPluginId` 只有它的 ① 形(`<名>@<市场>`)是「两半各读同一条文法」;② 形(带 scope 的 npm 来源 id `@<scope>/<包名>@npm`)的名是整个带 scope 的包名(含 `@` 与 `/`),
7
+ * 它的两段读的是「全小写名段」判法(同一只正则再加「没有大写字母」;那只判法在 `./plugin-settings` 里,不在本文件)—— 所以 ② 形读出的名不是合法的 `PluginSpec.name`。
8
+ * 它住在叶上而不是 `./types` 里,是因为 `./plugin-settings` 是给宿主冷读设置用的纯读法子路径:为一只正则冷载入整张 zod 模式表,等于把「纯读法」说成半句。
9
+ * 公开名 `PLUGIN_ID_SEGMENT_REGEX` 经 `./types`(与包根)**原名转出**,转出的就是这一只对象;句子常量不出包。
10
+ *
11
+ * 正则无 `g` / `y` 标志:同一只对象被几处共用、被反复 `test`,不带 `lastIndex` 的记忆。
12
+ */
13
+ export declare const PLUGIN_ID_SEGMENT_REGEX: RegExp;
14
+ /** 一段不过 {@link PLUGIN_ID_SEGMENT_REGEX} 时 zod 拒句的那一句(`PluginSpec.name` 与 `PluginSource` 的 marketplace 臂读同一句,文字只在这里一处)。 */
15
+ export declare const PLUGIN_ID_SEGMENT_SENTENCE = "letters/digits/._- , no spaces";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 包内私有(不进 exports 表、不进主桶):**插件 id 一段的文法** —— 全包唯一的定义,**零 import 的叶**。
3
+ *
4
+ * 一个插件 id `<名>@<市场>` 的两半(名、市场)读同一条文法:字母或数字起头,后接字母 / 数字 / `.` / `_` / `-`,不分大小写。
5
+ * 三处读它:`PluginSpec.name`、`PluginSource` 的 marketplace 臂(都在 `./types`),与插件 id 的读法 `readPluginId`(`./plugin-settings`)。
6
+ * 对 `readPluginId` 只有它的 ① 形(`<名>@<市场>`)是「两半各读同一条文法」;② 形(带 scope 的 npm 来源 id `@<scope>/<包名>@npm`)的名是整个带 scope 的包名(含 `@` 与 `/`),
7
+ * 它的两段读的是「全小写名段」判法(同一只正则再加「没有大写字母」;那只判法在 `./plugin-settings` 里,不在本文件)—— 所以 ② 形读出的名不是合法的 `PluginSpec.name`。
8
+ * 它住在叶上而不是 `./types` 里,是因为 `./plugin-settings` 是给宿主冷读设置用的纯读法子路径:为一只正则冷载入整张 zod 模式表,等于把「纯读法」说成半句。
9
+ * 公开名 `PLUGIN_ID_SEGMENT_REGEX` 经 `./types`(与包根)**原名转出**,转出的就是这一只对象;句子常量不出包。
10
+ *
11
+ * 正则无 `g` / `y` 标志:同一只对象被几处共用、被反复 `test`,不带 `lastIndex` 的记忆。
12
+ */
13
+ export const PLUGIN_ID_SEGMENT_REGEX = /^[a-z0-9][a-z0-9._-]*$/i;
14
+ /** 一段不过 {@link PLUGIN_ID_SEGMENT_REGEX} 时 zod 拒句的那一句(`PluginSpec.name` 与 `PluginSource` 的 marketplace 臂读同一句,文字只在这里一处)。 */
15
+ export const PLUGIN_ID_SEGMENT_SENTENCE = "letters/digits/._- , no spaces";
@@ -0,0 +1,61 @@
1
+ /**
2
+ * 插件 id `<名>@<市场>` 的**市场位**上四个哨兵词(闭集):这些「市场」不是真有一份市场目录,而是标出这个插件**从哪儿来**。
3
+ * - `inline` —— 命令行指定目录载入的插件;
4
+ * - `skills-dir` —— 技能目录里的插件;
5
+ * - `synced` —— 从云端同步来的插件;
6
+ * - `builtin` —— 内置插件。
7
+ * `<名>@skills-dir` 是**合法 id**(名段、市场段都过名段文法,{@link readPluginId} 照常读出)。
8
+ * 参照读到哪一步:四词与「逐字严格相等比较」都读自参照(读码);词表不加不减。
9
+ * 注意:参照的托管策略表里另有一个同名的 `skills-dir` 策略哨兵 —— 那是**另一处**的词(策略来源的种类),不在本表、本版不读。
10
+ */
11
+ export declare const PLUGIN_MARKETPLACE_SENTINELS: readonly ["inline", "skills-dir", "synced", "builtin"];
12
+ export type PluginMarketplaceSentinel = (typeof PLUGIN_MARKETPLACE_SENTINELS)[number];
13
+ /** 一个值是不是四个哨兵词之一。逐字严格相等(区分大小写,不裁剪、不规范化);非串一律 `false`,不抛。 */
14
+ export declare function isPluginMarketplaceSentinel(v: unknown): v is PluginMarketplaceSentinel;
15
+ /** {@link readPluginId} 读出的 id:名与市场两半。 */
16
+ export interface PluginId {
17
+ readonly name: string;
18
+ readonly marketplace: string;
19
+ }
20
+ /**
21
+ * 读一个插件 id。两条文法,答同一只形 `{ name, marketplace }`:
22
+ * ① **`<名>@<市场>`**:恰一个 `@`,两半各过名段文法 `PLUGIN_ID_SEGMENT_REGEX`(定义在包内私有的零 import 叶 `./plugin-id-segment`,`./types` 与包根原名转出;`PluginSpec.name` 与 `PluginSource` 的市场名读的是同一只对象);
23
+ * ② **`@<scope>/<包名>@npm`**(带 scope 的 npm 来源 id):名 = 整个带 scope 的包名(含开头的 `@` 与 `/`),市场 = `npm`。包名两段各是**全小写**名段、恰一个 `/`、整串不含 `..`。
24
+ * 不带 scope 的 npm 来源 id(`pkg@npm`)就是 ① 的一例(同一个答案),没有单列。
25
+ * 非串 / 两条文法都不过 ⇒ `undefined`(总:不抛,撤销的 Proxy 一类也只是非串)。不裁剪、不规范化(`@npm` 区分大小写)。
26
+ * 答案是**新造的、深冻的**。市场位上的哨兵词(`<名>@skills-dir` 等)照常读出,要不要当哨兵由调用方再问 {@link isPluginMarketplaceSentinel}。
27
+ *
28
+ * 参照读到哪一步(读自解出的语料 cli321.js 第 276223 行,行内列号为字符偏移,读码;没有对真实二进制核):
29
+ * - 参照的 id 判官 = 「`^ar@ar$` 或 `<npm 包名>@npm`」(列 56648 起);`ar` = `[A-Za-z0-9][-A-Za-z0-9._]*`,与 `PLUGIN_ID_SEGMENT_REGEX` 同一字符集;
30
+ * - npm 包名判官(列 24754 起):整串不含 `..` 与 `//`,且是带 scope 的 `@<小写名段>/<小写名段>` 或不带 scope 的 `<小写名段>`(小写名段 = `[a-z0-9][a-z0-9-._]*`);「`<npm 包名>@npm`」= 以 `@npm` 结尾且前半过它(`Cb = "npm"`,列 6859);
31
+ * - 参照把这样的 id 拆成 名 = 最后一个 `@` 之前的整段、市场 = `npm`(列 63291);
32
+ * - 本读法的 ② 与它逐格同判:不带 scope 的那一形被 ① 收下(答案一样),`//` 被「恰一个 `/`」挡掉。参照里 `pkg@pip` / `@github` 一类其他来源类市场名按 ① 读,不特判。
33
+ * 另:参照自己读 `enabledPlugins` 的键时不因 id 形坏而丢条目,本读法比参照读键更严 —— 读不出的 id 怎么处置由宿主定。
34
+ */
35
+ export declare function readPluginId(v: unknown): PluginId | undefined;
36
+ /** {@link EnabledPluginsValue} 的判别词(闭集,四臂):`on` · `off` · `versions` · `unreadable`。 */
37
+ export declare const ENABLED_PLUGINS_VALUE_KINDS: readonly ["on", "off", "versions", "unreadable"];
38
+ export type EnabledPluginsValueKind = (typeof ENABLED_PLUGINS_VALUE_KINDS)[number];
39
+ /** {@link readEnabledPluginsValue} 的答案(判别键 `kind`,四臂)。 */
40
+ export type EnabledPluginsValue = {
41
+ readonly kind: "on";
42
+ } | {
43
+ readonly kind: "off";
44
+ } | {
45
+ readonly kind: "versions";
46
+ readonly constraints: readonly string[];
47
+ } | {
48
+ readonly kind: "unreadable";
49
+ };
50
+ /**
51
+ * 读 `enabledPlugins` 里**一个键的值**(键本身是 {@link readPluginId} 的事):
52
+ * - `true` ⇒ `{ kind: "on" }`;`false` ⇒ `{ kind: "off" }`;
53
+ * - 字符串数组 ⇒ `{ kind: "versions", constraints }`(`constraints` 是**新造的冻结副本**,事后改入参不影响答案);
54
+ * - 其余一切(串 `"true"`、`null`、`undefined`、数、对象、含非串元素的数组、读不出的对象 —— 撤销的 Proxy、访问器下标、稀疏数组)⇒ `{ kind: "unreadable" }`。
55
+ * 总(不抛),答案每次新造、深冻。**不定**与中心层 `plugins[].enabled` 的组合,**不定**缺席时的缺省 —— 入参就是一个值,缺席的键到不了这里。
56
+ *
57
+ * 参照读到哪一步:`true` / `false` / 字符串数组三形读自参照(读码;「数组」「字符串」两个构造器的身份按邻近用法推断,没有逐个追到定义)。参照的 schema 层对数组
58
+ * **不细判元素**:空数组、空串元素都收,不判每条是不是合法的版本范围。**本读法同读法** —— 数组只问「是不是字符串数组」,
59
+ * 每条约束怎么解释(范围 / 标签 / 精确版本)与「空数组算不算启用」是消费方的事;参照的更细判法(下游怎么用这些串)未核。
60
+ */
61
+ export declare function readEnabledPluginsValue(v: unknown): EnabledPluginsValue;