@sema-agent/settings-schema 34.0.0 → 34.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +250 -0
- package/README.md +23 -8
- package/conformance/VERSION +1 -1
- package/dist/api/credentials.d.ts +94 -14
- package/dist/api/credentials.js +33 -8
- package/dist/atomic-write.d.ts +9 -3
- package/dist/atomic-write.js +13 -5
- package/dist/config-d-file.d.ts +0 -3
- package/dist/config-d-file.js +1 -6
- package/dist/conformance/web-admin-credential-lock.js +3 -2
- package/dist/cross-session.d.ts +2 -2
- package/dist/fleet.d.ts +5 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp-request-entry.d.ts +19 -0
- package/dist/mcp-request-entry.js +15 -13
- package/dist/plugin-id-segment.d.ts +15 -0
- package/dist/plugin-id-segment.js +15 -0
- package/dist/plugin-settings.d.ts +61 -0
- package/dist/plugin-settings.js +111 -0
- package/dist/safety-merge-spec.d.ts +2 -2
- package/dist/types.d.ts +10 -3
- package/dist/types.js +10 -3
- package/docs/API-SURFACE.md +31 -3
- package/docs/CONFORMANCE.md +1 -1
- package/docs/CONSUMER-INTEGRATION.md +53 -3
- package/llms-full.txt +14 -8
- package/llms.txt +6 -4
- package/package.json +5 -1
package/dist/atomic-write.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConfigDocumentIoKind } from "./config-document-refusal.js";
|
|
1
2
|
/** 按文档类的模式表(闭集)。 */
|
|
2
3
|
export declare const ATOMIC_FILE_CLASSES: {
|
|
3
4
|
readonly "config-document": {
|
|
@@ -13,9 +14,10 @@ export type AtomicFileClass = keyof typeof ATOMIC_FILE_CLASSES;
|
|
|
13
14
|
/** 悬空符号链接的**唯一一句**(写器与目录迁移的读口抛同一句;不带 errno 码 —— 带了 `ENOENT` 的错会被「ENOENT = 缺席」的读者读成文件不在,
|
|
14
15
|
* 悬空链接恰恰不是缺席)。 */
|
|
15
16
|
export declare function danglingSymlinkSentence(link: string, pointsAt: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* `
|
|
18
|
-
|
|
17
|
+
/** `io` 拒的类词 —— **唯一铸点**(31.1.0;随凭据锁同读挪到本文件,与它判的悬空链接判官同处):抛出物是本包悬空链接判官抛的那只错(按对象身份问 {@link isDanglingSymlinkError})⇒ 悬空;其余一切抛出物(系统错、运行时自己抛的错、抛出的不是 `Error` 的值)⇒ `read_error` —— 这个词只说「读那一下抛了错、而且不是悬空判官抛的」,不说「是操作系统给的」。
|
|
18
|
+
* 按抛出物的**身份**判,不读句子(句子是给人看的,措辞可以改;句子一样的别的错也不算)。两处问它:读 `config.d` 文档的 `io` 拒(`./config-d-file`)与凭据锁在「解凭证路径」那一步失败的 `unreadable`({@link tryWebAdminCredentialFileLock})——
|
|
19
|
+
* 都对**原始抛出物**问(包装后的 {@link FsFailure} 不在悬空登记里,会被判成 `read_error`)。包内,不出任何子路径。 */
|
|
20
|
+
export declare function configDocumentIoKindOf(thrown: unknown): ConfigDocumentIoKind;
|
|
19
21
|
/** 读写的真目标 —— **一只判法**(写器与目录迁移的读口共用):`target` 是符号链接 ⇒ 解析到它指向的真文件(悬空 ⇒ 抛 {@link danglingSymlinkSentence} 那一句,并登记进 {@link DANGLING_SYMLINK_ERRORS});
|
|
20
22
|
* 不是链接或不存在 ⇒ 原样(不存在的由调用方的读 / 写照常报)。 */
|
|
21
23
|
export declare function resolveSymlinkTarget(target: string): string;
|
|
@@ -94,6 +96,9 @@ export interface WebAdminCredentialLockHeld {
|
|
|
94
96
|
* 之后的都答 `false`、没落 —— 写没写成由回调自己记下那两只方法的答案(放进 `value`),不要从 `lost` 推「没写成」。
|
|
95
97
|
* · `busy` —— 别人持着新鲜的锁(或 mtime 在未来),回调没跑。`heldForMs` = 那只锁的年龄(读到了且不在未来才有)。
|
|
96
98
|
* · `unreadable` —— 锁建不出 / 看不了 / 收不了,或锁内读不了真目标;回调没跑,什么都没写。`error.message` 是包里的文件系统失败句,errno 在 `error.code`。
|
|
99
|
+
* 可缺的诊断位 `ioKind`:**只在「解凭证路径」那一步失败时在场** —— 值按抛出物的身份铸({@link configDocumentIoKindOf},对原始抛出物问、不读句子):是本包悬空链接判官抛的 ⇒ `dangling_symlink`
|
|
100
|
+
* (凭证路径经软链到达、链接在而目标不在;出路 = 删掉悬空链接,或先重建目标),其余 ⇒ `read_error`(权限、成环的链接、路径上有一节不是目录 ……);别的 `unreadable`(锁建不出 / 锁名被占 /
|
|
101
|
+
* 锁内读不了真目标)不带这一键 —— 键不在场,不是 `undefined`。状态、回调跑不跑、文件副作用与有没有这一键无关。
|
|
97
102
|
*/
|
|
98
103
|
export type WebAdminCredentialLockOutcome<T> = {
|
|
99
104
|
readonly status: "acquired";
|
|
@@ -107,6 +112,7 @@ export type WebAdminCredentialLockOutcome<T> = {
|
|
|
107
112
|
} | {
|
|
108
113
|
readonly status: "unreadable";
|
|
109
114
|
readonly error: Error;
|
|
115
|
+
readonly ioKind?: ConfigDocumentIoKind;
|
|
110
116
|
};
|
|
111
117
|
/**
|
|
112
118
|
* 在 web-admin 凭证文件的单写者锁里跑一次「读 → 比较 → 写」(规则与锁的形见文件头同名一节)。只试一次,从不等待:忙 ⇒ `busy`,调用方按自己的退避再来。
|
package/dist/atomic-write.js
CHANGED
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
* 锁的形(全部同步,不循环):
|
|
54
54
|
* 1. 凭证路径按**真目标**解({@link resolveSymlinkTarget},与原子写器同一只判法:软链写穿、悬空链接响亮拒);锁 = 真目标所在目录的 `.<真文件名>.lock`。
|
|
55
55
|
* 已知限制:经软链到达的凭据文件,登出(删掉链接指向的真目标)之后链接悬空 ⇒ 再取锁答 `unreadable`(失败关闭:不建文件、不写;出路 = 删掉悬空链接,或先重建目标);
|
|
56
|
-
*
|
|
56
|
+
* 本版不解析悬空链接的落点:要做就得改原子写器对悬空链接的拒律(不替链接建它指向的文件),那是另一份设计、按大版本排。
|
|
57
|
+
* 这一步失败时结果多一个可缺的 `ioKind`({@link configDocumentIoKindOf} 对原始抛出物问:悬空链接判官抛的 ⇒ `dangling_symlink`,其余 ⇒ `read_error`),壳据它渲出路、不解析句子;别的 `unreadable` 不带这一键。
|
|
57
58
|
* 2. **取**:`open(锁, "wx")` 独占建;身份 = 这只 fd 的 `(dev, ino)`(与建立同一次拿到,不事后按路径 `stat`),**fd 开到放锁核完身份**:身份只是两个数,文件被删后
|
|
58
59
|
* inode 号可被新文件复用,钉住文件对象才让比对成立。撞 `EEXIST` ⇒ 先 `lstat` 锁路径:**不是普通文件**(命名管道 / 目录 / 任何符号链接,悬空与否)⇒ 答 `unreadable`(取锁那一刻看到的这种占位物:同码同句,
|
|
59
60
|
* 不打开它、不等待、不碰它);是普通文件 ⇒ 以非阻塞只读打开那只锁(同样钉住它,打开后再核一遍类型)读它的 mtime:不在了(持有者刚放)⇒ 再试一次;
|
|
@@ -85,16 +86,22 @@ export function danglingSymlinkSentence(link, pointsAt) {
|
|
|
85
86
|
return `${link} is a dangling symbolic link (it points at ${pointsAt}, which does not exist) — nothing is read or written through it; repair or remove the link`;
|
|
86
87
|
}
|
|
87
88
|
/**
|
|
88
|
-
* 悬空链接判官({@link resolveSymlinkTarget})抛过的错 —— **身份登记**(31.1.0)
|
|
89
|
+
* 悬空链接判官({@link resolveSymlinkTarget})抛过的错 —— **身份登记**(31.1.0):类词的唯一铸点 {@link configDocumentIoKindOf} 据它铸 `dangling_symlink`,
|
|
89
90
|
* 不在句子里找悬空句的那一段。登记的是对象身份,不改对象:抛出去的仍是一只普通的 `Error`(原型 `Error.prototype`、名字 `"Error"`、`message` 是 {@link danglingSymlinkSentence} 那一句、
|
|
90
91
|
* 不带 errno 码、`cause` 是内核的 `ENOENT`)—— 与此前逐位同,消费方看不出它被登记过。弱引用:错被丢掉,登记随之消失。包内,不出任何子路径。
|
|
91
92
|
*/
|
|
92
93
|
const DANGLING_SYMLINK_ERRORS = new WeakSet();
|
|
93
94
|
/** 一个抛出物是不是悬空链接判官抛的那只错(按对象身份问 {@link DANGLING_SYMLINK_ERRORS};句子一样的别的错不算)。不读抛出物的任何属性、不问形状:
|
|
94
|
-
* `WeakSet.prototype.has` 对不是对象的值答 `false`、不抛(撤销的 Proxy 也只按身份比)。 */
|
|
95
|
-
|
|
95
|
+
* `WeakSet.prototype.has` 对不是对象的值答 `false`、不抛(撤销的 Proxy 也只按身份比)。包内私有:它唯一的读者是下面的铸点 {@link configDocumentIoKindOf}。 */
|
|
96
|
+
function isDanglingSymlinkError(thrown) {
|
|
96
97
|
return DANGLING_SYMLINK_ERRORS.has(thrown);
|
|
97
98
|
}
|
|
99
|
+
/** `io` 拒的类词 —— **唯一铸点**(31.1.0;随凭据锁同读挪到本文件,与它判的悬空链接判官同处):抛出物是本包悬空链接判官抛的那只错(按对象身份问 {@link isDanglingSymlinkError})⇒ 悬空;其余一切抛出物(系统错、运行时自己抛的错、抛出的不是 `Error` 的值)⇒ `read_error` —— 这个词只说「读那一下抛了错、而且不是悬空判官抛的」,不说「是操作系统给的」。
|
|
100
|
+
* 按抛出物的**身份**判,不读句子(句子是给人看的,措辞可以改;句子一样的别的错也不算)。两处问它:读 `config.d` 文档的 `io` 拒(`./config-d-file`)与凭据锁在「解凭证路径」那一步失败的 `unreadable`({@link tryWebAdminCredentialFileLock})——
|
|
101
|
+
* 都对**原始抛出物**问(包装后的 {@link FsFailure} 不在悬空登记里,会被判成 `read_error`)。包内,不出任何子路径。 */
|
|
102
|
+
export function configDocumentIoKindOf(thrown) {
|
|
103
|
+
return isDanglingSymlinkError(thrown) ? "dangling_symlink" : "read_error";
|
|
104
|
+
}
|
|
98
105
|
/** 读写的真目标 —— **一只判法**(写器与目录迁移的读口共用):`target` 是符号链接 ⇒ 解析到它指向的真文件(悬空 ⇒ 抛 {@link danglingSymlinkSentence} 那一句,并登记进 {@link DANGLING_SYMLINK_ERRORS});
|
|
99
106
|
* 不是链接或不存在 ⇒ 原样(不存在的由调用方的读 / 写照常报)。 */
|
|
100
107
|
export function resolveSymlinkTarget(target) {
|
|
@@ -506,7 +513,8 @@ export function tryWebAdminCredentialFileLock(credentialPath, critical) {
|
|
|
506
513
|
target = resolveSymlinkTarget(credentialPath);
|
|
507
514
|
}
|
|
508
515
|
catch (e) {
|
|
509
|
-
|
|
516
|
+
// 类词对**原始抛出物** `e` 问:包装后的 FsFailure 不在悬空登记里,会被判成 `read_error`
|
|
517
|
+
return { status: "unreadable", error: new FsFailure({ landing: "read", of: "file", path: credentialPath }, e), ioKind: configDocumentIoKindOf(e) };
|
|
510
518
|
}
|
|
511
519
|
const lock = entryIn(path.dirname(target), webAdminCredentialLockName(path.basename(target)));
|
|
512
520
|
let attempt;
|
package/dist/config-d-file.d.ts
CHANGED
|
@@ -42,9 +42,6 @@ export type MintedConfigDRefused = (ConfigDRefused & {
|
|
|
42
42
|
});
|
|
43
43
|
/** 本包铸出的读数(被拒那一臂是 {@link MintedConfigDRefused})。 */
|
|
44
44
|
export type MintedConfigDReading = Exclude<ConfigDReading, ConfigDRefused> | MintedConfigDRefused;
|
|
45
|
-
/** `io` 拒的类词 —— **唯一铸点**(31.1.0):抛出物是本包悬空链接判官抛的那只错(按对象身份问 `isDanglingSymlinkError`,`./atomic-write`)⇒ 悬空;其余一切抛出物(系统错、运行时自己抛的错、抛出的不是 `Error` 的值)⇒ `read_error` —— 这个词只说「读那一下抛了错、而且不是悬空判官抛的」,不说「是操作系统给的」。
|
|
46
|
-
* 按抛出物的**身份**判,不读句子(句子是给人看的,措辞可以改;句子一样的别的错也不算)。 */
|
|
47
|
-
export declare function configDocumentIoKindOf(thrown: unknown): ConfigDocumentIoKind;
|
|
48
45
|
/** 一份被拒读数 → 拒单里的一条(`FileConfigStore.read()` 的拒单只经这一只渲染):`{ document, reason, error }`,`io` 的拒带读数的类词 `ioKind`。 */
|
|
49
46
|
export declare function configDocumentRefusalOf(document: ConfigDocumentName, reading: MintedConfigDRefused): ConfigDocumentRefusal;
|
|
50
47
|
/** 一个 `config.d/<名>.json` 在场时的**文本** → 读数(纯判,零 I/O;见文件头的律):一个 JSON 对象 ⇒ 在场;空 / 纯空白、坏 JSON、
|
package/dist/config-d-file.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* 句尾出路按文档类({@link documentWayOut}),从不回显文件原文。
|
|
17
17
|
*/
|
|
18
18
|
import path from "node:path";
|
|
19
|
-
import {
|
|
19
|
+
import { configDocumentIoKindOf, readTextIfPresent, readTextIfPresentSync } from "./atomic-write.js";
|
|
20
20
|
import { refuseRetiredDomain, sanitizeZodError } from "./config-fns.js";
|
|
21
21
|
import { MAX_HASH_DEPTH, stableHash } from "./hash.js";
|
|
22
22
|
import { UNINSPECTABLE, guardedSafeParse, ownElementsOf, ownEntriesOf } from "./own-key-read.js";
|
|
@@ -49,11 +49,6 @@ function documentWayOut(name) {
|
|
|
49
49
|
return name === REMOTE_EXEC_DOCUMENT ? "delete it for the host default, or write a valid remoteExec spec" : "delete it for the domain default, or write a valid object";
|
|
50
50
|
}
|
|
51
51
|
const messageOf = (thrown) => (thrown instanceof Error ? thrown.message : String(thrown));
|
|
52
|
-
/** `io` 拒的类词 —— **唯一铸点**(31.1.0):抛出物是本包悬空链接判官抛的那只错(按对象身份问 `isDanglingSymlinkError`,`./atomic-write`)⇒ 悬空;其余一切抛出物(系统错、运行时自己抛的错、抛出的不是 `Error` 的值)⇒ `read_error` —— 这个词只说「读那一下抛了错、而且不是悬空判官抛的」,不说「是操作系统给的」。
|
|
53
|
-
* 按抛出物的**身份**判,不读句子(句子是给人看的,措辞可以改;句子一样的别的错也不算)。 */
|
|
54
|
-
export function configDocumentIoKindOf(thrown) {
|
|
55
|
-
return isDanglingSymlinkError(thrown) ? "dangling_symlink" : "read_error";
|
|
56
|
-
}
|
|
57
52
|
/** 一份被拒读数 → 拒单里的一条(`FileConfigStore.read()` 的拒单只经这一只渲染):`{ document, reason, error }`,`io` 的拒带读数的类词 `ioKind`。 */
|
|
58
53
|
export function configDocumentRefusalOf(document, reading) {
|
|
59
54
|
return reading.reason === "io" ? { document, reason: "io", ioKind: reading.ioKind, error: reading.error } : { document, reason: reading.reason, error: reading.error };
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* 看不到的东西不判:只试一次的「次数」、收残留的交错、身份取自 fd 且 fd 钉到放锁 —— 这些要注入系统调用才能排出来,在本包自己的白盒钉里(黑盒里只量「忙时不等待」的耗时上界)。
|
|
11
11
|
* 「失锁」两格(锁被换成继任者)对一只不钉 fd 的实现是概率性的:继任者的锁恰好复用了持有者那只的 inode 号时,那样的实现会读成「仍是自己的」。
|
|
12
12
|
* 锁名被命名管道 / 悬空软链占着的两种形在本包自己的白盒钉里(命名管道要放进可超时终止的子进程,黑盒格里不造);黑盒里用目录代表「锁名上不是普通文件」那一类,答案是同一个。
|
|
13
|
-
* 悬空软链(链接在、目标不在 —— 经软链到达的凭据文件登出之后的样子)是**失败关闭**:`unreadable`、不建文件、不写。这是本版协议的答案,也是已知限制(登出后再登录写不进去;出路 = 删掉悬空链接或先重建目标)
|
|
14
|
-
*
|
|
13
|
+
* 悬空软链(链接在、目标不在 —— 经软链到达的凭据文件登出之后的样子)是**失败关闭**:`unreadable`、不建文件、不写。这是本版协议的答案,也是已知限制(登出后再登录写不进去;出路 = 删掉悬空链接或先重建目标):
|
|
14
|
+
* 本版不解析悬空链接的落点 —— 要做就得改原子写器对悬空链接的拒律(不替链接建它指向的文件),那是另一份设计、按大版本排。
|
|
15
|
+
* 本包原语对这一形答的 `unreadable` 多一个可缺的诊断位 `ioKind`(`dangling_symlink`),这份 kit 不判它:别的实现不带这一键也过。
|
|
15
16
|
* 已知范围:软链两格(写穿 · 悬空)要求宿主允许建符号链接(Windows 上普通用户默认不允许,那两格会以「建链接失败」红)。
|
|
16
17
|
*/
|
|
17
18
|
import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
|
package/dist/cross-session.d.ts
CHANGED
|
@@ -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
|
-
never: "never";
|
|
68
67
|
default: "default";
|
|
68
|
+
never: "never";
|
|
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
|
-
never: "never";
|
|
89
88
|
default: "default";
|
|
89
|
+
never: "never";
|
|
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
|
-
expired: "expired";
|
|
114
113
|
none: "none";
|
|
114
|
+
expired: "expired";
|
|
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
|
-
expired: "expired";
|
|
347
346
|
none: "none";
|
|
347
|
+
expired: "expired";
|
|
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
|
-
expired: "expired";
|
|
390
389
|
none: "none";
|
|
390
|
+
expired: "expired";
|
|
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
|
-
expired: "expired";
|
|
462
461
|
none: "none";
|
|
462
|
+
expired: "expired";
|
|
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
|
-
expired: "expired";
|
|
511
510
|
none: "none";
|
|
511
|
+
expired: "expired";
|
|
512
512
|
granted: "granted";
|
|
513
513
|
denied: "denied";
|
|
514
514
|
}>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./settings-units.js";
|
|
|
29
29
|
export * from "./scheduler-store.js";
|
|
30
30
|
export * from "./cross-session.js";
|
|
31
31
|
export * from "./hooks.js";
|
|
32
|
+
export * from "./plugin-settings.js";
|
|
32
33
|
export * from "./fleet.js";
|
|
33
34
|
export * from "./workers-rows.js";
|
|
34
35
|
export * from "./api/auth.js";
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./settings-units.js"; // 14.6.0: SETTINGS_UNITS — the settings-
|
|
|
29
29
|
export * from "./scheduler-store.js"; // R7 self-wake scheduler store CONTRACT (pure: type + parse/serialize + SchedulerStore interface; fs binding in ./node)
|
|
30
30
|
export * from "./cross-session.js"; // CC-parity `settings.json` cross-session keys (crossSessionInbound / dialogExpiry) — pure/browser-safe
|
|
31
31
|
export * from "./hooks.js"; // CC-parity hooks contract (33-event set + owner map + per-event input/output shapes + the config surface: classifyHooksConfig and its zod faces HooksConfig / HookEntry …) & stop attribution (stoppedBy) — pure/browser-safe
|
|
32
|
+
export * from "./plugin-settings.js"; // the three pure readings of the plugin settings values — readEnabledPluginsValue (one `enabledPlugins` value: on / off / versions / unreadable) + readPluginId (`<name>@<marketplace>`, exactly one `@`, both halves read the one segment grammar PLUGIN_ID_SEGMENT_REGEX, re-exported by ./types from a package-private zero-import leaf; the scoped npm source id `@<scope>/<pkg>@npm` is read too — its name carries `@` and `/`, so it is not a valid `PluginSpec.name`) + the four marketplace sentinel words PLUGIN_MARKETPLACE_SENTINELS / isPluginMarketplaceSentinel; values only — how the central layer and the settings layers combine is not here; the same function objects as on the `./plugin-settings` subpath, pure/browser-safe
|
|
32
33
|
export * from "./fleet.js"; // scheduling/fleet contract (drain protocol · instance discovery · dispatch policy · quota lease · usage report · quota reset event) — CONTROL-PLANE-SCHEDULING-DESIGN, pure/browser-safe
|
|
33
34
|
export * from "./workers-rows.js"; // 11.0.0 the workers domain's per-row verdict (readWorkersRows: a row that does not read is held, the rest read on) — permanent read semantics, pure
|
|
34
35
|
export * from "./api/auth.js"; // /api/v1/auth/* wire contract (RFC 8628 device flow + rotating refresh + logout + approve) — REGISTRY-REBUILD-DESIGN §2, M1 shipped shapes frozen, pure/browser-safe
|
|
@@ -71,6 +71,25 @@ export type McpRequestCredentialKind = McpRequestCredential["kind"];
|
|
|
71
71
|
* 读器对一个值的准入问的是同一只谓词,所以表与读器不会各说各的。表里每个种类都是 `own_entry`、引擎的 `own_entry` 种类都在表里,由测试两向对拍(引擎再认一种而判口不收 ⇒ 红,逼着有人表态 http 收不收)。
|
|
72
72
|
*/
|
|
73
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;
|
|
74
93
|
/**
|
|
75
94
|
* 请求面一条 MCP 条目的传输形。与引擎传输形的关系逐键一句(处置表,对拍 = 上游漂移门 ⑧):
|
|
76
95
|
* · `kind` / `command` / `args` / `url` / `principalHeader` —— 与引擎同键同型;
|
|
@@ -203,7 +203,7 @@ const ASSERTION_HEADER_RETIRED_ON_REQUEST = retiredFormSentence("transport.asser
|
|
|
203
203
|
const KIND_PROBE_ENTRY = "probe";
|
|
204
204
|
/**
|
|
205
205
|
* 请求面 **http** 传输收不收一个值 —— **准入的唯一一处合取**:判口 {@link readHookPluginOptionRef} 收它 ∧ 引擎准入表对请求面仍是 `own_entry`(引擎哪天收回某种类的准入,读器随它拒,读器表也随它空)。
|
|
206
|
-
* 收 ⇒ 判口新造的引用(尚未冻结);不收 ⇒ `undefined`。读器表({@link MCP_REQUEST_CREDENTIAL_KINDS})与读器({@link
|
|
206
|
+
* 收 ⇒ 判口新造的引用(尚未冻结);不收 ⇒ `undefined`。读器表({@link MCP_REQUEST_CREDENTIAL_KINDS})与读器({@link readRequestMcpCredentials})都问它,谁也不另写这个合取。
|
|
207
207
|
*/
|
|
208
208
|
function requestPlaneTakes(value) {
|
|
209
209
|
const ref = readHookPluginOptionRef(value);
|
|
@@ -215,28 +215,30 @@ function requestPlaneTakes(value) {
|
|
|
215
215
|
* 读器对一个值的准入问的是同一只谓词,所以表与读器不会各说各的。表里每个种类都是 `own_entry`、引擎的 `own_entry` 种类都在表里,由测试两向对拍(引擎再认一种而判口不收 ⇒ 红,逼着有人表态 http 收不收)。
|
|
216
216
|
*/
|
|
217
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 });
|
|
218
|
+
const CREDENTIALS_ABSENT = deepFreeze({ kind: "absent" });
|
|
219
|
+
const credentialsRefused = (reason) => deepFreeze({ kind: "refused", refusal: "credentials_not_carried", reason });
|
|
220
220
|
/** http 传输上「不是读器收的引用」的原因句:说清收什么(种类取自读器表),不回显值。 */
|
|
221
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
222
|
/** stdio 传输上一切 `credentials` 的原因句(它没有凭据引用的座位)。 */
|
|
223
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
224
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
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`);句子都不回显值。
|
|
228
230
|
*/
|
|
229
|
-
function
|
|
230
|
-
if (
|
|
231
|
+
export function readRequestMcpCredentials(transport, value) {
|
|
232
|
+
if (value === undefined)
|
|
231
233
|
return CREDENTIALS_ABSENT;
|
|
232
|
-
const read = readCredentialRef(
|
|
234
|
+
const read = readCredentialRef(value);
|
|
233
235
|
if (read.ok && CREDENTIAL_REF_TRUST[read.ref.kind].request === "refused") {
|
|
234
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`);
|
|
235
237
|
}
|
|
236
238
|
if (transport === "stdio")
|
|
237
239
|
return credentialsRefused(STDIO_CREDENTIALS_NO_SEAT);
|
|
238
240
|
const taken = read.ok ? requestPlaneTakes(read.ref) : undefined;
|
|
239
|
-
return taken !== undefined ? { kind: "taken", credential: deepFreeze(taken) } : credentialsRefused(HTTP_CREDENTIALS_NOT_TAKEN);
|
|
241
|
+
return taken !== undefined ? deepFreeze({ kind: "taken", credential: deepFreeze(taken) }) : credentialsRefused(HTTP_CREDENTIALS_NOT_TAKEN);
|
|
240
242
|
}
|
|
241
243
|
/** 点名拒的硬坏形(机读词在 `refusal`)。 */
|
|
242
244
|
const keyRefused = (path, reason, refusal) => ({ ok: false, issue: { path, reason, refusal } });
|
|
@@ -245,7 +247,7 @@ function refusedKeyOf(assertionHeader, credentials) {
|
|
|
245
247
|
if (assertionHeader !== undefined)
|
|
246
248
|
return keyRefused("transport.assertionHeader", ASSERTION_HEADER_RETIRED_ON_REQUEST, "key_retired");
|
|
247
249
|
if (credentials.kind === "refused")
|
|
248
|
-
return keyRefused("transport.credentials", credentials.reason,
|
|
250
|
+
return keyRefused("transport.credentials", credentials.reason, credentials.refusal);
|
|
249
251
|
return undefined;
|
|
250
252
|
}
|
|
251
253
|
const transportBad = (path, reason) => ({ ok: false, issue: { path, reason } });
|
|
@@ -363,7 +365,7 @@ function snapshotTransport(tr) {
|
|
|
363
365
|
const credentials = axis("credentials");
|
|
364
366
|
if (!credentials.ok)
|
|
365
367
|
return credentials;
|
|
366
|
-
const refused = refusedKeyOf(undefined,
|
|
368
|
+
const refused = refusedKeyOf(undefined, readRequestMcpCredentials("stdio", credentials.value));
|
|
367
369
|
if (refused !== undefined)
|
|
368
370
|
return { ok: true, value: { kind: "refused", read: refused } };
|
|
369
371
|
const fields = ownFieldsOf(tr, ["command", "args", "env"]);
|
|
@@ -379,7 +381,7 @@ function snapshotTransport(tr) {
|
|
|
379
381
|
if (!credentials.ok)
|
|
380
382
|
return credentials;
|
|
381
383
|
// 判序 = 读序:`assertionHeader` 在场 ⇒ 先答 `key_retired`,调用方交来的 `credentials` 值一个成员都不碰(不为一个注定要拒的条目多跑调用方的代码);不在场才判它
|
|
382
|
-
const verdict = assertionHeader.value === undefined ?
|
|
384
|
+
const verdict = assertionHeader.value === undefined ? readRequestMcpCredentials("http", credentials.value) : CREDENTIALS_ABSENT;
|
|
383
385
|
const refused = refusedKeyOf(assertionHeader.value, verdict);
|
|
384
386
|
if (refused !== undefined)
|
|
385
387
|
return { ok: true, value: { kind: "refused", read: refused } };
|
|
@@ -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;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件设置的三只纯读法:设置里 `enabledPlugins` 一个键的**值**怎么读({@link readEnabledPluginsValue})、插件 id `<名>@<市场>` 怎么拆({@link readPluginId})、
|
|
3
|
+
* id 市场位上的哨兵词是哪几个({@link PLUGIN_MARKETPLACE_SENTINELS} / {@link isPluginMarketplaceSentinel})。纯函数、零 `node:` 依赖、浏览器安全。
|
|
4
|
+
*
|
|
5
|
+
* ## 为什么在这里
|
|
6
|
+
* 插件创建面(共用库、终端)要读参照形的 `enabledPlugins` 值与插件 id,各宿主此前各写一份 —— 一个事实多个读者各自判。三只读法就是那一份:**只读值,不定合并**。
|
|
7
|
+
*
|
|
8
|
+
* ## 分工(消费方读法,不是新规则)
|
|
9
|
+
* - 中心层 `plugins[].enabled` 是部署层的供给闸;设置层的 `enabledPlugins` 是各设置源每一层各自的开关。**两层怎么组合不在本包。**
|
|
10
|
+
* 下面这句是给宿主的现行做法,不是本模块的行为(本模块不实现、不校验它,也不回答「最终启用与否」):
|
|
11
|
+
* 组合读法到货之前,同时读中心 `plugins` 与本机设置文件的宿主**只照中心层答**,不自己拼 —— 自己拼出来的是第二个来源。
|
|
12
|
+
* - 本模块不读任何文档、不碰合并顺序、不定缺席时的缺省(缺席的键根本到不了这里:读法的入参是一个值)。
|
|
13
|
+
* - 托管策略表(`strictKnownMarketplaces` / `blockedMarketplaces`)与它的哨兵臂、`pluginConfigs` / `extraKnownMarketplaces` 的条目形,都不在本模块;
|
|
14
|
+
* 策略读不出时的处置、`unreadable` / `undefined` 之后怎么办,也都是宿主的事。
|
|
15
|
+
*
|
|
16
|
+
* ## 参照
|
|
17
|
+
* 三只读法的形取自参照(CC 的设置读法)。那是**读自解出语料的线索、没有对真实二进制核**;每一条下面标了参照到哪一步。
|
|
18
|
+
* 参照读到哪一步、哪里没核,逐只写在各导出的 JSDoc 里。
|
|
19
|
+
*/
|
|
20
|
+
import { captureStringArray } from "./own-key-read.js";
|
|
21
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
22
|
+
import { PLUGIN_ID_SEGMENT_REGEX } from "./plugin-id-segment.js";
|
|
23
|
+
// ── 市场位上的哨兵词 ────────────────────────────────────────────────────────────────────────────────
|
|
24
|
+
/**
|
|
25
|
+
* 插件 id `<名>@<市场>` 的**市场位**上四个哨兵词(闭集):这些「市场」不是真有一份市场目录,而是标出这个插件**从哪儿来**。
|
|
26
|
+
* - `inline` —— 命令行指定目录载入的插件;
|
|
27
|
+
* - `skills-dir` —— 技能目录里的插件;
|
|
28
|
+
* - `synced` —— 从云端同步来的插件;
|
|
29
|
+
* - `builtin` —— 内置插件。
|
|
30
|
+
* `<名>@skills-dir` 是**合法 id**(名段、市场段都过名段文法,{@link readPluginId} 照常读出)。
|
|
31
|
+
* 参照读到哪一步:四词与「逐字严格相等比较」都读自参照(读码);词表不加不减。
|
|
32
|
+
* 注意:参照的托管策略表里另有一个同名的 `skills-dir` 策略哨兵 —— 那是**另一处**的词(策略来源的种类),不在本表、本版不读。
|
|
33
|
+
*/
|
|
34
|
+
export const PLUGIN_MARKETPLACE_SENTINELS = deepFreeze(["inline", "skills-dir", "synced", "builtin"]);
|
|
35
|
+
/** 一个值是不是四个哨兵词之一。逐字严格相等(区分大小写,不裁剪、不规范化);非串一律 `false`,不抛。 */
|
|
36
|
+
export function isPluginMarketplaceSentinel(v) {
|
|
37
|
+
return typeof v === "string" && PLUGIN_MARKETPLACE_SENTINELS.includes(v);
|
|
38
|
+
}
|
|
39
|
+
/** 来源类市场名里的 `npm`:id 市场位上是它时,名位可以是带 scope 的 npm 包名(见 {@link readPluginId})。它不是哨兵词,不在 {@link PLUGIN_MARKETPLACE_SENTINELS} 里。 */
|
|
40
|
+
const NPM_MARKETPLACE = "npm";
|
|
41
|
+
const NPM_ID_SUFFIX = `@${NPM_MARKETPLACE}`;
|
|
42
|
+
/** 一个名段是不是**全小写**的名段(npm 包名只收小写:名段文法本身不分大小写,这里再要求没有大写字母)。 */
|
|
43
|
+
const isLowercaseSegment = (part) => PLUGIN_ID_SEGMENT_REGEX.test(part) && part === part.toLowerCase();
|
|
44
|
+
/**
|
|
45
|
+
* 是不是**带 scope 的** npm 包名 `@<scope>/<名>`:`@`,一个全小写名段(scope),恰一个 `/`,一个全小写名段(包名);整串不含 `..`。
|
|
46
|
+
* 不带 scope 的 npm 包名没有单列:它本身就是一个名段,走 {@link readPluginId} 的一般文法(同一个答案)。
|
|
47
|
+
*/
|
|
48
|
+
function isScopedNpmPackageName(s) {
|
|
49
|
+
if (!s.startsWith("@") || s.includes(".."))
|
|
50
|
+
return false;
|
|
51
|
+
const slash = s.indexOf("/");
|
|
52
|
+
if (slash < 0 || s.indexOf("/", slash + 1) >= 0)
|
|
53
|
+
return false;
|
|
54
|
+
return isLowercaseSegment(s.slice(1, slash)) && isLowercaseSegment(s.slice(slash + 1));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 读一个插件 id。两条文法,答同一只形 `{ name, marketplace }`:
|
|
58
|
+
* ① **`<名>@<市场>`**:恰一个 `@`,两半各过名段文法 `PLUGIN_ID_SEGMENT_REGEX`(定义在包内私有的零 import 叶 `./plugin-id-segment`,`./types` 与包根原名转出;`PluginSpec.name` 与 `PluginSource` 的市场名读的是同一只对象);
|
|
59
|
+
* ② **`@<scope>/<包名>@npm`**(带 scope 的 npm 来源 id):名 = 整个带 scope 的包名(含开头的 `@` 与 `/`),市场 = `npm`。包名两段各是**全小写**名段、恰一个 `/`、整串不含 `..`。
|
|
60
|
+
* 不带 scope 的 npm 来源 id(`pkg@npm`)就是 ① 的一例(同一个答案),没有单列。
|
|
61
|
+
* 非串 / 两条文法都不过 ⇒ `undefined`(总:不抛,撤销的 Proxy 一类也只是非串)。不裁剪、不规范化(`@npm` 区分大小写)。
|
|
62
|
+
* 答案是**新造的、深冻的**。市场位上的哨兵词(`<名>@skills-dir` 等)照常读出,要不要当哨兵由调用方再问 {@link isPluginMarketplaceSentinel}。
|
|
63
|
+
*
|
|
64
|
+
* 参照读到哪一步(读自解出的语料 cli321.js 第 276223 行,行内列号为字符偏移,读码;没有对真实二进制核):
|
|
65
|
+
* - 参照的 id 判官 = 「`^ar@ar$` 或 `<npm 包名>@npm`」(列 56648 起);`ar` = `[A-Za-z0-9][-A-Za-z0-9._]*`,与 `PLUGIN_ID_SEGMENT_REGEX` 同一字符集;
|
|
66
|
+
* - npm 包名判官(列 24754 起):整串不含 `..` 与 `//`,且是带 scope 的 `@<小写名段>/<小写名段>` 或不带 scope 的 `<小写名段>`(小写名段 = `[a-z0-9][a-z0-9-._]*`);「`<npm 包名>@npm`」= 以 `@npm` 结尾且前半过它(`Cb = "npm"`,列 6859);
|
|
67
|
+
* - 参照把这样的 id 拆成 名 = 最后一个 `@` 之前的整段、市场 = `npm`(列 63291);
|
|
68
|
+
* - 本读法的 ② 与它逐格同判:不带 scope 的那一形被 ① 收下(答案一样),`//` 被「恰一个 `/`」挡掉。参照里 `pkg@pip` / `@github` 一类其他来源类市场名按 ① 读,不特判。
|
|
69
|
+
* 另:参照自己读 `enabledPlugins` 的键时不因 id 形坏而丢条目,本读法比参照读键更严 —— 读不出的 id 怎么处置由宿主定。
|
|
70
|
+
*/
|
|
71
|
+
export function readPluginId(v) {
|
|
72
|
+
if (typeof v !== "string")
|
|
73
|
+
return undefined;
|
|
74
|
+
if (v.endsWith(NPM_ID_SUFFIX)) {
|
|
75
|
+
const packageName = v.slice(0, v.length - NPM_ID_SUFFIX.length);
|
|
76
|
+
if (isScopedNpmPackageName(packageName))
|
|
77
|
+
return deepFreeze({ name: packageName, marketplace: NPM_MARKETPLACE });
|
|
78
|
+
}
|
|
79
|
+
const at = v.indexOf("@");
|
|
80
|
+
if (at < 0 || v.indexOf("@", at + 1) >= 0)
|
|
81
|
+
return undefined;
|
|
82
|
+
const name = v.slice(0, at);
|
|
83
|
+
const marketplace = v.slice(at + 1);
|
|
84
|
+
if (!PLUGIN_ID_SEGMENT_REGEX.test(name) || !PLUGIN_ID_SEGMENT_REGEX.test(marketplace))
|
|
85
|
+
return undefined;
|
|
86
|
+
return deepFreeze({ name, marketplace });
|
|
87
|
+
}
|
|
88
|
+
// ── `enabledPlugins` 的值 ──────────────────────────────────────────────────────────────────────────
|
|
89
|
+
/** {@link EnabledPluginsValue} 的判别词(闭集,四臂):`on` · `off` · `versions` · `unreadable`。 */
|
|
90
|
+
export const ENABLED_PLUGINS_VALUE_KINDS = deepFreeze(["on", "off", "versions", "unreadable"]);
|
|
91
|
+
/**
|
|
92
|
+
* 读 `enabledPlugins` 里**一个键的值**(键本身是 {@link readPluginId} 的事):
|
|
93
|
+
* - `true` ⇒ `{ kind: "on" }`;`false` ⇒ `{ kind: "off" }`;
|
|
94
|
+
* - 字符串数组 ⇒ `{ kind: "versions", constraints }`(`constraints` 是**新造的冻结副本**,事后改入参不影响答案);
|
|
95
|
+
* - 其余一切(串 `"true"`、`null`、`undefined`、数、对象、含非串元素的数组、读不出的对象 —— 撤销的 Proxy、访问器下标、稀疏数组)⇒ `{ kind: "unreadable" }`。
|
|
96
|
+
* 总(不抛),答案每次新造、深冻。**不定**与中心层 `plugins[].enabled` 的组合,**不定**缺席时的缺省 —— 入参就是一个值,缺席的键到不了这里。
|
|
97
|
+
*
|
|
98
|
+
* 参照读到哪一步:`true` / `false` / 字符串数组三形读自参照(读码;「数组」「字符串」两个构造器的身份按邻近用法推断,没有逐个追到定义)。参照的 schema 层对数组
|
|
99
|
+
* **不细判元素**:空数组、空串元素都收,不判每条是不是合法的版本范围。**本读法同读法** —— 数组只问「是不是字符串数组」,
|
|
100
|
+
* 每条约束怎么解释(范围 / 标签 / 精确版本)与「空数组算不算启用」是消费方的事;参照的更细判法(下游怎么用这些串)未核。
|
|
101
|
+
*/
|
|
102
|
+
export function readEnabledPluginsValue(v) {
|
|
103
|
+
if (v === true)
|
|
104
|
+
return deepFreeze({ kind: "on" });
|
|
105
|
+
if (v === false)
|
|
106
|
+
return deepFreeze({ kind: "off" });
|
|
107
|
+
const constraints = captureStringArray(v, "strict");
|
|
108
|
+
if (constraints !== undefined)
|
|
109
|
+
return deepFreeze({ kind: "versions", constraints });
|
|
110
|
+
return deepFreeze({ kind: "unreadable" });
|
|
111
|
+
}
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
import { z } from "zod";
|
|
69
69
|
/** How values from different layers/principals combine for a category. */
|
|
70
70
|
export declare const MergeShape: z.ZodEnum<{
|
|
71
|
-
replace: "replace";
|
|
72
71
|
concat: "concat";
|
|
72
|
+
replace: "replace";
|
|
73
73
|
denyFirst: "denyFirst";
|
|
74
74
|
runAll: "runAll";
|
|
75
75
|
overrideByName: "overrideByName";
|
|
@@ -262,8 +262,8 @@ export type TightenVerdict = (typeof TIGHTEN_VERDICTS)[number];
|
|
|
262
262
|
export declare function tightenVerdict(rule: TightenRule, existing: unknown, candidate: unknown): TightenVerdict;
|
|
263
263
|
export declare const MergeCategorySpec: z.ZodObject<{
|
|
264
264
|
mergeShape: z.ZodEnum<{
|
|
265
|
-
replace: "replace";
|
|
266
265
|
concat: "concat";
|
|
266
|
+
replace: "replace";
|
|
267
267
|
denyFirst: "denyFirst";
|
|
268
268
|
runAll: "runAll";
|
|
269
269
|
overrideByName: "overrideByName";
|