@sema-agent/settings-schema 28.0.0 → 30.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.
- package/CHANGELOG.md +431 -0
- package/README.md +94 -14
- package/conformance/VERSION +1 -1
- package/conformance/cases/c01-entry-salvage-then-typo/expected.json +2 -2
- package/conformance/cases/c02-hosts-clamp-stacked/expected.json +1 -1
- package/conformance/cases/c03-literal-dotted-top-key/expected.json +1 -1
- package/conformance/cases/c04-all-bad-collection-not-salvaged/expected.json +1 -1
- package/conformance/cases/c07-hooks-is-not-a-config-domain/expected.json +1 -1
- package/conformance/cases/c08-limits-unknown-carried-64/expected.json +1 -1
- package/conformance/cases/c09-limits-unknown-carried-65/expected.json +1 -1
- package/conformance/cases/c10-record-key-secret-redacted-twice/expected.json +1 -1
- package/conformance/cases/c11-unicode-unknown-keys/expected.json +1 -1
- package/conformance/cases/c12-prototype-name-top-keys/expected.json +1 -1
- package/conformance/cases/c13-models-field-null/expected.json +1 -1
- package/conformance/cases/c14-models-field-empty-array/expected.json +1 -1
- package/conformance/cases/c15-models-field-number/expected.json +1 -1
- package/conformance/cases/c18-wire-envelope-not-an-object/expected.json +1 -1
- package/conformance/cases/c19-wire-envelope-no-version/expected.json +1 -1
- package/conformance/cases/c21-governance-empty-object-wins/expected.json +1 -1
- package/conformance/cases/c23-mixed-validity-models/expected.json +1 -1
- package/conformance/cases/c24-valid-entries-with-unknown-keys/expected.json +1 -1
- package/conformance/cases/c25-published-roundtrip-zero-warnings/expected.json +1 -1
- package/conformance/cases/c26-hosts-array-1024/expected.json +1 -1
- package/conformance/cases/c27-hosts-array-1025/expected.json +1 -1
- package/conformance/cases/c28-large-document-over-1mb/expected.json +1 -1
- package/conformance/cases/c29-salvage-then-domain-refine-fails/expected.json +1 -1
- package/conformance/cases/c30-version-triple-a-first/expected.json +1 -1
- package/conformance/cases/c31-version-triple-b-changed/expected.json +1 -1
- package/conformance/cases/c32-version-triple-a-restored/expected.json +1 -1
- package/conformance/cases/c33-limits-nested-carried-key/expected.json +1 -1
- package/conformance/cases/c34-skills-content-vs-manifest/expected.json +1 -1
- package/conformance/cases/c36-skills-entry-without-content/expected.json +1 -1
- package/conformance/cases/c38-remote-exec-is-a-non-domain-file/expected.json +1 -1
- package/conformance/cases/c39-hidden-file-in-config-d/expected.json +1 -1
- package/conformance/cases/c40-s712-identity-only-what-reads-out/expected.json +1 -1
- package/conformance/cases/c41-s792-encoded-pem-identity/expected.json +1 -1
- package/conformance/cases/c42-s792-unknown-key-secret-redacted/expected.json +1 -1
- package/conformance/cases/c43-s792-form-and-deep-encoded-pem/expected.json +1 -1
- package/conformance/cases/c44-s792-utf8-escape-glued-token/expected.json +1 -1
- package/conformance/cases/c45-s792-identity-bounds-and-decode-depth/expected.json +1 -1
- package/conformance/cases/c46-s811-host-name-url-userinfo-withheld/expected.json +1 -1
- package/conformance/cases/c47-s811-roles-key-url-userinfo-withheld/expected.json +1 -1
- package/conformance/cases/c48-s935-model-headers-transported/expected.json +1 -1
- package/conformance/cases/c49-s935-model-headers-secret-entry-dropped/expected.json +1 -1
- package/conformance/cases/c50-s784-lane-host-legal/expected.json +1 -1
- package/conformance/cases/c51-s784-lane-e2b-legal/expected.json +1 -1
- package/conformance/cases/c52-s784-lane-k8s-legal/expected.json +1 -1
- package/conformance/cases/c53-s784-lane-ssh-legal/expected.json +1 -1
- package/conformance/cases/c54-s784-lane-adb-legal/expected.json +1 -1
- package/conformance/cases/c55-s784-lane-local-docker-legal/expected.json +1 -1
- package/conformance/cases/c56-s784-lane-device-legal/expected.json +1 -1
- package/conformance/cases/c57-s784-g1-enabled-no-lane/expected.json +3 -3
- package/conformance/cases/c58-s784-g2-multitenant-host/expected.json +3 -3
- package/conformance/cases/c59-s784-g3-k8s-missing-image/expected.json +3 -3
- package/conformance/cases/c60-s784-g3-e2b-missing-key/expected.json +3 -3
- package/conformance/cases/c61-s784-g3-other-lane-key/expected.json +3 -3
- package/conformance/cases/c62-s784-g7a-session-tidb/expected.json +3 -3
- package/conformance/cases/c63-s784-host-two-replicas/expected.json +3 -3
- package/conformance/cases/c64-s784-multitenant-local-store/expected.json +3 -3
- package/conformance/cases/c65-s784-pg-without-db/expected.json +3 -3
- package/conformance/cases/c66-s784-memory-backend-mismatch/expected.json +3 -3
- package/conformance/cases/c67-s784-retired-field-loud/expected.json +3 -3
- package/conformance/cases/c68-s784-device-local-store/expected.json +3 -3
- package/conformance/cases/c69-deep-encoded-token-past-every-reading/expected.json +1 -1
- package/conformance/cases/c70-rewritten-token-in-front-of-encoded-pem-header/expected.json +1 -1
- package/conformance/cases/c71-one-scanner-write-reads-display-forms/expected.json +1 -1
- package/conformance/cases/c72-dangling-reference-write-seat-refuses/expected.json +1 -1
- package/conformance/cases/c73-projects-extended-registration-reads/expected.json +1 -1
- package/conformance/cases/c74-projects-over-bound-refused/expected.json +3 -72
- package/conformance/cases/c75-projects-patch-remote-uniqueness/expected.json +3 -72
- package/conformance/cases/c76-projects-entry-salvage-nested/expected.json +2 -2
- package/conformance/cases/c77-prompts-center-artifact-carried/expected.json +1 -1
- package/conformance/cases/c78-prompts-empty-bindings-refused/expected.json +2 -2
- package/conformance/cases/c78-prompts-empty-bindings-refused/meta.json +1 -1
- package/conformance/cases/c79-prompts-bad-worker-artifact-not-salvaged/expected.json +1 -1
- package/conformance/cases/c80-prompts-wire-v2-verbatim/expected.json +1 -1
- package/conformance/cases/c81-prompts-declaration-bindings-refused/expected.json +2 -2
- package/conformance/cases/c82-prompts-v1-catalog-refused/expected.json +2 -2
- package/conformance/cases/c83-prompts-bad-overlay-not-salvaged/expected.json +1 -1
- package/conformance/cases/c84-sandbox-git-block-carried-verbatim/expected.json +1 -1
- package/conformance/cases/c85-sandbox-git-refused-block-still-carried/expected.json +1 -1
- package/conformance/cases/c86-a2a-peers-legal/expected.json +1 -1
- package/conformance/cases/c87-a2a-credential-refs-not-partially-salvaged/expected.json +1 -1
- package/conformance/cases/c88-projects-content-attestation-carried/expected.json +1 -1
- package/conformance/cases/c89-projects-content-attestation-malformed/expected.json +1 -1
- package/conformance/cases/c90-mcp-assertion-credential-carried/expected.json +143 -0
- package/conformance/cases/c90-mcp-assertion-credential-carried/input.json +30 -0
- package/conformance/cases/c90-mcp-assertion-credential-carried/meta.json +6 -0
- package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/expected.json +105 -0
- package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/input.json +27 -0
- package/conformance/cases/c91-mcp-assertion-header-retired-entry-dropped/meta.json +6 -0
- package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/expected.json +105 -0
- package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/input.json +31 -0
- package/conformance/cases/c92-mcp-principal-header-with-assertion-dropped/meta.json +6 -0
- package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/expected.json +105 -0
- package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/input.json +33 -0
- package/conformance/cases/c93-mcp-header-refs-with-credentials-dropped/meta.json +6 -0
- package/conformance/cases/c94-mcp-credentials-env-kind-dropped/expected.json +105 -0
- package/conformance/cases/c94-mcp-credentials-env-kind-dropped/input.json +32 -0
- package/conformance/cases/c94-mcp-credentials-env-kind-dropped/meta.json +6 -0
- package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/expected.json +105 -0
- package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/input.json +30 -0
- package/conformance/cases/c95-mcp-credentials-audience-not-connector-id-dropped/meta.json +6 -0
- package/conformance/cases/c96-mcp-credentials-extra-member-dropped/expected.json +105 -0
- package/conformance/cases/c96-mcp-credentials-extra-member-dropped/input.json +31 -0
- package/conformance/cases/c96-mcp-credentials-extra-member-dropped/meta.json +6 -0
- package/conformance/cases/cc01-mcp-toolfaces-non-object/expected.json +1 -1
- package/conformance/cases/cc02-mcp-source-key-is-transported/expected.json +1 -1
- package/conformance/cases/cc03-model-compat-unknown-subkey/expected.json +1 -1
- package/conformance/cases/cli01-model-name-nfc-vs-nfd/expected.json +1 -1
- package/conformance/cases/cli02-control-and-zero-width-chars/expected.json +1 -1
- package/conformance/cases/cli03-credential-pasted-into-unknown-key/expected.json +1 -1
- package/conformance/cases/cli04-env-value-with-newline/expected.json +1 -1
- package/conformance/cases/cli04-env-value-with-newline/meta.json +1 -1
- package/conformance/cases/cli05-long-and-prefix-colliding-names/expected.json +1 -1
- package/conformance/cases/t01-absent-domain-key-not-null/expected.json +1 -1
- package/conformance/cases/t01-absent-domain-key-not-null/meta.json +1 -1
- package/conformance/cases/t03-prototype-name-key-not-swallowed/expected.json +1 -1
- package/conformance/cases/t04-secret-literal-never-in-warning-value/expected.json +1 -1
- package/conformance/cases/t04-secret-literal-never-in-warning-value/meta.json +1 -1
- package/conformance/cases/z01-every-domain-empty-object/expected.json +1 -1
- package/conformance/cases/z01-every-domain-empty-object/meta.json +1 -1
- package/conformance/cases/z02-every-domain-unknown-key/expected.json +1 -1
- package/dist/api/credentials.js +5 -7
- package/dist/api/lifecycle-events.d.ts +266 -0
- package/dist/api/lifecycle-events.js +169 -0
- package/dist/api/wire-scalars.d.ts +13 -0
- package/dist/api/wire-scalars.js +15 -0
- package/dist/atomic-write.d.ts +4 -0
- package/dist/atomic-write.js +26 -3
- package/dist/config-d-file.d.ts +1 -1
- package/dist/config-document-refusal.d.ts +4 -4
- package/dist/config-fns.d.ts +4 -2
- package/dist/config-fns.js +1 -1
- package/dist/config-root-documents.d.ts +1 -1
- package/dist/config-root-node.js +2 -1
- package/dist/conformance/corpus.d.ts +1 -1
- package/dist/conformance/derive.d.ts +13 -5
- package/dist/conformance/derive.js +37 -21
- package/dist/conformance/index.d.ts +1 -1
- package/dist/conformance/index.js +1 -1
- package/dist/conformance/run.js +8 -9
- package/dist/connector-authorize-url.d.ts +23 -0
- package/dist/connector-authorize-url.js +129 -0
- package/dist/connector-id.d.ts +23 -0
- package/dist/connector-id.js +27 -0
- package/dist/file-edit.d.ts +44 -0
- package/dist/file-edit.js +70 -1
- package/dist/file-store.d.ts +12 -7
- package/dist/file-store.js +72 -59
- package/dist/hooks.d.ts +15 -5
- package/dist/hooks.js +13 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -1
- package/dist/mcp-entry-credential.d.ts +47 -0
- package/dist/mcp-entry-credential.js +73 -0
- package/dist/mcp-request-entry.d.ts +32 -13
- package/dist/mcp-request-entry.js +104 -58
- package/dist/migration-receipt.d.ts +2 -2
- package/dist/migration-receipt.js +2 -2
- package/dist/one-time-migrations.d.ts +1 -1
- package/dist/one-time-migrations.js +68 -91
- package/dist/portable-domains.d.ts +18 -12
- package/dist/portable-domains.js +17 -12
- package/dist/retired-role-words.d.ts +1 -1
- package/dist/retired-role-words.js +4 -6
- package/dist/scheduler-store-node.d.ts +5 -2
- package/dist/scheduler-store-node.js +8 -5
- package/dist/sha256.d.ts +5 -0
- package/dist/sha256.js +7 -0
- package/dist/skills-manifest.js +2 -2
- package/dist/types.d.ts +80 -10
- package/dist/types.js +37 -44
- package/docs/API-SURFACE.md +47 -7
- package/docs/CONFORMANCE.md +6 -4
- package/docs/CONSUMER-INTEGRATION.md +147 -4
- package/llms-full.txt +45 -24
- package/llms.txt +27 -14
- package/package.json +3 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ```
|
|
5
5
|
* <根>/
|
|
6
|
-
* config.d/…
|
|
6
|
+
* config.d/… 域文档(本地读取域的文件;文件仓库只扫这一个目录)
|
|
7
7
|
* config.env-models.json env 模型表被目录顶替的部署决定 {"envModels":"replaced"|"kept"}
|
|
8
8
|
* config.migration.SS-M11.json 一次性迁移 SS-M11 的运行记录 {"migration":"SS-M11"}(按 id 一份)
|
|
9
9
|
* .env 秘密值(不归本包读)
|
package/dist/config-root-node.js
CHANGED
|
@@ -287,7 +287,8 @@ export async function migrateEnvModelsDecision(input) {
|
|
|
287
287
|
let createdRoot;
|
|
288
288
|
let created;
|
|
289
289
|
try {
|
|
290
|
-
|
|
290
|
+
// 一次操作一条路径串:建的目录是随后要写的那份文件的路径串的 dirname(原子写器的文件头「一次操作一条路径串」)—— 配置根下的文件一向是 `path.join(根, 文件名)`
|
|
291
|
+
createdRoot = (await io.ensureDirectory(path.dirname(file))) === "created";
|
|
291
292
|
created = await io.createDocument(migrationMarkerDocument("SS-M11"), file, configDDocumentText(migrationMarkerValue("SS-M11")));
|
|
292
293
|
}
|
|
293
294
|
catch (e) {
|
|
@@ -61,7 +61,7 @@ export interface ConformanceCase {
|
|
|
61
61
|
}
|
|
62
62
|
export interface Corpus {
|
|
63
63
|
version: string;
|
|
64
|
-
/** 空文档集的 effective(冻结的 golden
|
|
64
|
+
/** 空文档集的 effective(冻结的 golden;非本地读取域的那一格由它供给,见 derive.ts T3)。 */
|
|
65
65
|
baseline: Record<string, unknown>;
|
|
66
66
|
cases: readonly ConformanceCase[];
|
|
67
67
|
}
|
|
@@ -35,8 +35,8 @@ export declare const LEG_EXPECTATION: {
|
|
|
35
35
|
readonly why: "T3 / T4 / T5 / T6";
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
-
/**
|
|
39
|
-
export declare const
|
|
38
|
+
/** 非本地读取域(T3 的集合)—— 由 {@link LOCAL_READ_DOMAINS} 派生,零手抄:本地读腿(`loadLocalConfig`)不读它们的文件(报 `unread-config-file{not-a-local-read-domain}`),域取 schema 默认。 */
|
|
39
|
+
export declare const NON_LOCAL_READ_DOMAINS: readonly DomainName[];
|
|
40
40
|
/** 一份 `domains` 文档集里,**不是域名**的那些顶层键(T4 的触发面)。 */
|
|
41
41
|
export declare const foreignKeysOf: (docs: Readonly<Record<string, unknown>>) => string[];
|
|
42
42
|
/** T2 的**入参**半场:域形的 skills 文档 → wire 形的 manifest 文档。结构变换,不解析 —— 坏形原样传下去,
|
|
@@ -64,14 +64,22 @@ export type LegExpectation = {
|
|
|
64
64
|
path: ReadonlyArray<string | number>;
|
|
65
65
|
}>;
|
|
66
66
|
};
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* T1 + T2 + T4:`domains` 期望 → `wire` 期望。
|
|
69
|
+
*
|
|
70
|
+
* **T2 只许是恒等**(这只护栏住在这里,语料跑器与直接调用同一只判、同一句):skills 是变换表里唯一一条**算出新值**的变换(content → contentHash),
|
|
71
|
+
* 而派生 wire 入参({@link deriveWireInput})用的是同一只 {@link toManifestDoc} —— 期望也由它算,哈希算错就两侧同错、门照绿;域形条目自带字面 `contentHash` 时,
|
|
72
|
+
* 那个值还被派生算出的覆盖掉,派生期望与线上读数对不上。所以 `source.effective.skills` 上 T2 不是恒等(有一条 T2 会改写的条目 —— 与入参半场同一只判据 `t2Rewrites`)⇒ 抛,
|
|
73
|
+
* 这条腿要写显式期望(金样入库即冻结,哈希一改就红);恒等 ⇒ skills 原样进期望。其余三条变换只搬 / 只删、不铸新值。
|
|
74
|
+
* **先取快照、再对快照判、再用同一份快照派生**:调用方的 `source.effective` 只读一次(克隆那一次),护栏判的与派生用的是同一份 —— 访问器第二次答别的值也进不来。
|
|
75
|
+
*/
|
|
68
76
|
export declare function deriveWireExpectation(source: Extract<LegExpectation, {
|
|
69
77
|
outcome: "effective";
|
|
70
78
|
}>, docs: Readonly<Record<string, unknown>>): LegExpectation;
|
|
71
|
-
/** 纪元时刻 —— 一个 `config.d/`
|
|
79
|
+
/** 纪元时刻 —— 一个 `config.d/` 里没有任何**本地读取**域文件时 `updatedAt` 的取值(`#maxMtimeIso` 只 stat 本地读取域)。 */
|
|
72
80
|
export declare const EPOCH_ISO: string;
|
|
73
81
|
/** T3 + T4 + T5:`domains` 期望 → `local-root` 期望。`baseline` = 空文档集的 effective(语料里冻结的
|
|
74
|
-
* `conformance/baseline.json`)
|
|
82
|
+
* `conformance/baseline.json`),非本地读取域取它的那一格 —— 不现算,免得 schema 默认一改 golden 就跟着动。 */
|
|
75
83
|
export declare function deriveLocalExpectation(source: Extract<LegExpectation, {
|
|
76
84
|
outcome: "effective";
|
|
77
85
|
}>, docs: Readonly<Record<string, unknown>>, baseline: Readonly<Record<string, unknown>>, localVersion: number | undefined): LegExpectation;
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* 挂回(线上读口不编造生产方没发的域)—— 缺席进缺席出;在场时 `prompts` 是**未解析的原文档**,`a2a` 是域腿的读数。表由常量派生,不手抄域名。
|
|
13
13
|
* · **T2 skills 表示**(wire):域形带 `content`,wire 形带 `contentHash`(manifest)。判据 schema 随表示走;读法不随(24.0.0 起清单与域文档同一只读法、
|
|
14
14
|
* 同两张表,剥键扫描与告警同读 —— 此前清单不走剥键扫描,派生要把 skills 的剥键告警从 wire 期望里滤掉)。
|
|
15
|
-
* · **T3
|
|
16
|
-
* `unread-config-file{why:"
|
|
17
|
-
* 不手抄域名** —— 设计稿只点了 `hosts`
|
|
15
|
+
* · **T3 非本地读取域**(local-root):`config.d/` 只读 {@link LOCAL_READ_DOMAINS}(便携域集 + `projects`);其余域(workers / hosts / systems / entitlement)的文件在场则报
|
|
16
|
+
* `unread-config-file{why:"not-a-local-read-domain"}`,域本身取 schema 默认。**由 `LOCAL_READ_DOMAINS` 派生,
|
|
17
|
+
* 不手抄域名** —— 设计稿只点了 `hosts` 一个实例,类是「本地读取集之外的域」。29.0.0 以前这一格读的是便携域集(搬运义),`projects` 因此被算作「本地不读」;两个义拆开之后本格只问本地读取义。
|
|
18
18
|
* · **T4 未知顶层键**(wire + local-root):wire 是 open-world,不认识的顶层键**逐字承运**;`domains` 腿
|
|
19
19
|
* 只按域名取文档,多出来的键根本不会被问到(无声);local-root 报
|
|
20
20
|
* `unread-config-file{why:"not-a-domain"}`。三腿三样 —— 这条是本车对着真读数补登记的第四条。
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
* 就等于让 domains 金样的一处错同时改写两条腿的期望 —— 两条腿同错、门照绿。它的金样逐条显式入库、各自冻结。
|
|
36
36
|
*/
|
|
37
37
|
import { NON_DOMAIN_CONFIG_FILES } from "../file-store.js";
|
|
38
|
-
import {
|
|
38
|
+
import { LOCAL_READ_DOMAINS } from "../portable-domains.js";
|
|
39
39
|
import { isJsonArray, isPlainJsonObject } from "../plain-json-object.js";
|
|
40
40
|
import { skillContentHash } from "../skills-manifest.js";
|
|
41
41
|
import { DOMAINS, WIRE_CARRIED_DOMAINS, isDomainName } from "../types.js";
|
|
@@ -44,7 +44,7 @@ import { deepFreeze } from "../deep-freeze.js";
|
|
|
44
44
|
export const DERIVATION_TRANSFORMS = deepFreeze([
|
|
45
45
|
{ id: "T1-wire-carried-domains", legs: ["wire"], what: "buildEffective 恒物化每个域;wire 对 WIRE_CARRIED_DOMAINS(prompts / a2a)按在场性挂回(缺席进缺席出;在场时 prompts 是原文档、a2a 是域腿读数)" },
|
|
46
46
|
{ id: "T2-skills-representation", legs: ["wire"], what: "域形 content ↔ wire 形 contentHash(manifest),判据 schema 随表示走;读法与告警同一只" },
|
|
47
|
-
{ id: "T3-non-
|
|
47
|
+
{ id: "T3-non-local-read-domains", legs: ["localRoot"], what: "config.d/ 只读 LOCAL_READ_DOMAINS;其余域取默认 + unread-config-file{not-a-local-read-domain}" },
|
|
48
48
|
{ id: "T4-unknown-top-level-key", legs: ["wire", "localRoot"], what: "wire open-world 逐字承运;domains 腿按域名取文档故无声;local 报 unread-config-file{not-a-domain}" },
|
|
49
49
|
{ id: "T5-file-layer-first", legs: ["localRoot"], what: "config.d/<域>.json 必须是 JSON 对象(空/null/数组/标量 throw),这一层在域解析之前" },
|
|
50
50
|
{ id: "T6-file-name-classification", legs: ["localRoot"], what: "config.d/ 的文件分三类:域文件 / NON_DOMAIN_CONFIG_FILES(remote-exec.json 自带读取与校验路径)/ 隐藏文件与非 .json(忽略);只有剩下的才报 not-a-domain" },
|
|
@@ -66,10 +66,14 @@ export const LEG_EXPECTATION = deepFreeze({
|
|
|
66
66
|
wire: { source: "derivable", why: "T1 / T2 / T4" },
|
|
67
67
|
localRoot: { source: "derivable", why: "T3 / T4 / T5 / T6" },
|
|
68
68
|
});
|
|
69
|
-
/**
|
|
70
|
-
export const
|
|
69
|
+
/** 非本地读取域(T3 的集合)—— 由 {@link LOCAL_READ_DOMAINS} 派生,零手抄:本地读腿(`loadLocalConfig`)不读它们的文件(报 `unread-config-file{not-a-local-read-domain}`),域取 schema 默认。 */
|
|
70
|
+
export const NON_LOCAL_READ_DOMAINS = deepFreeze(DOMAINS.filter((d) => !LOCAL_READ_DOMAINS.includes(d)));
|
|
71
71
|
/** 一份 `domains` 文档集里,**不是域名**的那些顶层键(T4 的触发面)。 */
|
|
72
72
|
export const foreignKeysOf = (docs) => Object.keys(docs).filter((k) => !isDomainName(k));
|
|
73
|
+
/** T2 改写这一条吗 —— **唯一的判据**:入参半场 {@link toManifestDoc} 按它改写,期望半场的护栏({@link deriveWireExpectation})按它拒;条目是朴素对象且 `content` 是串。 */
|
|
74
|
+
const t2Rewrites = (entry) => isPlainJsonObject(entry) && typeof entry.content === "string";
|
|
75
|
+
/** T2 在这份 skills 文档上会不会改动任何东西:是朴素对象、`skills` 是数组、有一条 {@link t2Rewrites}。只问条目 —— 与 T2 无关的值不读、不序列化。 */
|
|
76
|
+
const t2Moves = (doc) => isPlainJsonObject(doc) && isJsonArray(doc.skills) && doc.skills.some(t2Rewrites);
|
|
73
77
|
/** T2 的**入参**半场:域形的 skills 文档 → wire 形的 manifest 文档。结构变换,不解析 —— 坏形原样传下去,
|
|
74
78
|
* 让 wire 腿自己的判据去裁(否则语料就没法喂一份坏 manifest 了)。 */
|
|
75
79
|
export function toManifestDoc(doc) {
|
|
@@ -78,7 +82,7 @@ export function toManifestDoc(doc) {
|
|
|
78
82
|
return {
|
|
79
83
|
...doc,
|
|
80
84
|
skills: doc.skills.map((entry) => {
|
|
81
|
-
if (!
|
|
85
|
+
if (!t2Rewrites(entry))
|
|
82
86
|
return entry;
|
|
83
87
|
const { content, ...rest } = entry;
|
|
84
88
|
return { ...rest, contentHash: skillContentHash(content) };
|
|
@@ -105,18 +109,30 @@ export function deriveLocalInput(docs, mtime) {
|
|
|
105
109
|
return { leg: "localRoot", files, mtime };
|
|
106
110
|
}
|
|
107
111
|
const clone = (v) => structuredClone(v);
|
|
108
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* T1 + T2 + T4:`domains` 期望 → `wire` 期望。
|
|
114
|
+
*
|
|
115
|
+
* **T2 只许是恒等**(这只护栏住在这里,语料跑器与直接调用同一只判、同一句):skills 是变换表里唯一一条**算出新值**的变换(content → contentHash),
|
|
116
|
+
* 而派生 wire 入参({@link deriveWireInput})用的是同一只 {@link toManifestDoc} —— 期望也由它算,哈希算错就两侧同错、门照绿;域形条目自带字面 `contentHash` 时,
|
|
117
|
+
* 那个值还被派生算出的覆盖掉,派生期望与线上读数对不上。所以 `source.effective.skills` 上 T2 不是恒等(有一条 T2 会改写的条目 —— 与入参半场同一只判据 `t2Rewrites`)⇒ 抛,
|
|
118
|
+
* 这条腿要写显式期望(金样入库即冻结,哈希一改就红);恒等 ⇒ skills 原样进期望。其余三条变换只搬 / 只删、不铸新值。
|
|
119
|
+
* **先取快照、再对快照判、再用同一份快照派生**:调用方的 `source.effective` 只读一次(克隆那一次),护栏判的与派生用的是同一份 —— 访问器第二次答别的值也进不来。
|
|
120
|
+
*/
|
|
109
121
|
export function deriveWireExpectation(source, docs) {
|
|
110
122
|
const base = clone(source.effective);
|
|
123
|
+
if (t2Moves(base.skills)) {
|
|
124
|
+
throw new Error("deriveWireExpectation: 这份期望的 skills 表示变换(T2)会**算出新值**(contentHash)—— 派生入参用的是同一只变换,哈希算错会两侧同错(域形条目自带的字面 `contentHash` 还会被覆盖);" +
|
|
125
|
+
"这条 wire 腿要写显式期望并写明 why(跑 `npm run conformance:bless` 填金样)");
|
|
126
|
+
}
|
|
111
127
|
// T1:承运表里的域缺席进缺席出;在场 = 自有键且值不是 undefined(与读口同一条律,这里独立写一遍 —— 派生不调被测读口;嵌入方调导出的派生时
|
|
112
128
|
// 文档集里可以有 undefined,JSON 语料没有);在场时 prompts 是**未解析的原文档**(wire 腿从不 parse prompts),其余是域腿读数。
|
|
113
|
-
// T2
|
|
129
|
+
// T2:上面的护栏放行 ⇒ 恒等,skills 原样。
|
|
114
130
|
// T4:open-world 顶层键逐字承运 —— 用 fromEntries 而不是逐键赋值,否则一个叫 `__proto__` 的顶层键
|
|
115
131
|
// 会变成一次原型改写(期望侧与实际侧被同样吃掉 = 比对器对这一类全盲,S-332 同族)。
|
|
116
132
|
const carried = WIRE_CARRIED_DOMAINS;
|
|
117
133
|
const effective = Object.fromEntries([
|
|
118
134
|
...Object.entries(base).filter(([k]) => !carried.includes(k) && k !== "skills"),
|
|
119
|
-
["skills",
|
|
135
|
+
["skills", base.skills],
|
|
120
136
|
...WIRE_CARRIED_DOMAINS.filter((d) => Object.prototype.hasOwnProperty.call(docs, d) && docs[d] !== undefined).map((d) => [d, d === "prompts" ? clone(docs.prompts) : base[d]]),
|
|
121
137
|
...foreignKeysOf(docs).map((k) => [k, clone(docs[k])]),
|
|
122
138
|
]);
|
|
@@ -127,22 +143,22 @@ export function deriveWireExpectation(source, docs) {
|
|
|
127
143
|
});
|
|
128
144
|
return { outcome: "effective", effective, warnings, metadata: { ...source.metadata } };
|
|
129
145
|
}
|
|
130
|
-
/** 纪元时刻 —— 一个 `config.d/`
|
|
146
|
+
/** 纪元时刻 —— 一个 `config.d/` 里没有任何**本地读取**域文件时 `updatedAt` 的取值(`#maxMtimeIso` 只 stat 本地读取域)。 */
|
|
131
147
|
export const EPOCH_ISO = new Date(0).toISOString();
|
|
132
148
|
/** T3 + T4 + T5:`domains` 期望 → `local-root` 期望。`baseline` = 空文档集的 effective(语料里冻结的
|
|
133
|
-
* `conformance/baseline.json`)
|
|
149
|
+
* `conformance/baseline.json`),非本地读取域取它的那一格 —— 不现算,免得 schema 默认一改 golden 就跟着动。 */
|
|
134
150
|
export function deriveLocalExpectation(source, docs, baseline, localVersion) {
|
|
135
|
-
// T5:文件层先判 ——
|
|
136
|
-
const badFile =
|
|
151
|
+
// T5:文件层先判 —— 任何一个**本地读取**域的文档不是 JSON 对象 ⇒ 整条腿在解析层被拒。
|
|
152
|
+
const badFile = LOCAL_READ_DOMAINS.find((d) => Object.prototype.hasOwnProperty.call(docs, d) && !isPlainJsonObject(docs[d]));
|
|
137
153
|
if (badFile !== undefined)
|
|
138
154
|
return { outcome: "rejected", stage: "parse" };
|
|
139
155
|
const effective = clone(source.effective);
|
|
140
|
-
for (const d of
|
|
156
|
+
for (const d of NON_LOCAL_READ_DOMAINS)
|
|
141
157
|
effective[d] = clone(baseline[d]);
|
|
142
|
-
const warnings = source.warnings.filter((w) => !("domain" in w && w.domain !== undefined &&
|
|
143
|
-
for (const d of
|
|
158
|
+
const warnings = source.warnings.filter((w) => !("domain" in w && w.domain !== undefined && NON_LOCAL_READ_DOMAINS.includes(w.domain)));
|
|
159
|
+
for (const d of NON_LOCAL_READ_DOMAINS) {
|
|
144
160
|
if (Object.prototype.hasOwnProperty.call(docs, d))
|
|
145
|
-
warnings.push({ kind: "unread-config-file", file: `${d}.json`, domain: d, why: "
|
|
161
|
+
warnings.push({ kind: "unread-config-file", file: `${d}.json`, domain: d, why: "not-a-local-read-domain" });
|
|
146
162
|
}
|
|
147
163
|
// T6:只有**既不是专用文件、也不是隐藏文件**的那些才报 not-a-domain(分类表从 file-store 派生,零手抄)。
|
|
148
164
|
for (const k of foreignKeysOf(docs)) {
|
|
@@ -151,11 +167,11 @@ export function deriveLocalExpectation(source, docs, baseline, localVersion) {
|
|
|
151
167
|
continue;
|
|
152
168
|
warnings.push({ kind: "unread-config-file", file, why: "not-a-domain" });
|
|
153
169
|
}
|
|
154
|
-
const
|
|
170
|
+
const anyLocalRead = LOCAL_READ_DOMAINS.some((d) => Object.prototype.hasOwnProperty.call(docs, d));
|
|
155
171
|
return {
|
|
156
172
|
outcome: "effective",
|
|
157
173
|
effective,
|
|
158
174
|
warnings,
|
|
159
|
-
metadata: { updatedAt:
|
|
175
|
+
metadata: { updatedAt: anyLocalRead ? source.metadata.updatedAt : EPOCH_ISO, ...(localVersion === undefined ? {} : { version: localVersion }) },
|
|
160
176
|
};
|
|
161
177
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
export { runConformance, materializeLocalRoot, resolveLegExpectation } from "./run.js";
|
|
18
18
|
export { createContractAdapter, type ContractAdapterOptions, type ContractModule } from "./contract-adapter.js";
|
|
19
19
|
export { loadCorpus, loadCase, kitIdentity, DEFAULT_CORPUS_DIR, PACKAGE_ROOT, type Corpus, type ConformanceCase, type CaseInput, type CaseMeta, type LegExpectationJson } from "./corpus.js";
|
|
20
|
-
export { DERIVATION_TRANSFORMS, LEG_EXPECTATION,
|
|
20
|
+
export { DERIVATION_TRANSFORMS, LEG_EXPECTATION, NON_LOCAL_READ_DOMAINS, EPOCH_ISO, deriveWireInput, deriveLocalInput, deriveWireExpectation, deriveLocalExpectation, foreignKeysOf, toManifestDoc, type DerivationTransform, type LegExpectation, } from "./derive.js";
|
|
21
21
|
export { canonicalize, deepEqual, diffJson, stableKey, type JsonPatchOp } from "./canonical.js";
|
|
22
22
|
export { WARNING_KINDS, projectWarning, normalizeProjection, projectionKey, projectionValue, diffWarningMultiset, findSecretLeaks, type WarningKind, type WarningProjection, } from "./warnings.js";
|
|
23
23
|
export { LEDGER_REF_RULE, LEG_DECLINE_REASONS, REF_INTEGRITY_REJECT_CODE, type RefIssueCoordinate, LEG_NAMES, REJECT_STAGES, type ConformanceAdapter, type ConformanceLeg, type DomainDocsInput, type LegDeclineReason, type LegDeclined, type LegStance, type ConformanceMode, type ConformanceNormalizer, type ConformanceOptions, type ConformanceProvenance, type ConformanceReport, type ConformanceResult, type ConformanceStatus, type KnownDivergence, type OutcomeDivergence, type PathDivergence, type LedgerRow, type LegEntry, type LegInput, type LegName, type LegOutcome, type RejectStage, } from "./types.js";
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
export { runConformance, materializeLocalRoot, resolveLegExpectation } from "./run.js";
|
|
18
18
|
export { createContractAdapter } from "./contract-adapter.js";
|
|
19
19
|
export { loadCorpus, loadCase, kitIdentity, DEFAULT_CORPUS_DIR, PACKAGE_ROOT } from "./corpus.js";
|
|
20
|
-
export { DERIVATION_TRANSFORMS, LEG_EXPECTATION,
|
|
20
|
+
export { DERIVATION_TRANSFORMS, LEG_EXPECTATION, NON_LOCAL_READ_DOMAINS, EPOCH_ISO, deriveWireInput, deriveLocalInput, deriveWireExpectation, deriveLocalExpectation, foreignKeysOf, toManifestDoc, } from "./derive.js";
|
|
21
21
|
export { canonicalize, deepEqual, diffJson, stableKey } from "./canonical.js";
|
|
22
22
|
export { WARNING_KINDS, projectWarning, normalizeProjection, projectionKey, projectionValue, diffWarningMultiset, findSecretLeaks, } from "./warnings.js";
|
|
23
23
|
export { LEDGER_REF_RULE, LEG_DECLINE_REASONS, REF_INTEGRITY_REJECT_CODE, LEG_NAMES, REJECT_STAGES, } from "./types.js";
|
package/dist/conformance/run.js
CHANGED
|
@@ -16,7 +16,7 @@ import { basename, extname, isAbsolute, join, resolve, sep } from "node:path";
|
|
|
16
16
|
import { isJsonArray, isPlainJsonObject, jsonShapeOf } from "../plain-json-object.js";
|
|
17
17
|
import { canonicalize, deepEqual, diffJson, stableKey } from "./canonical.js";
|
|
18
18
|
import { diffWarningMultiset, findSecretLeaks, projectWarning } from "./warnings.js";
|
|
19
|
-
import { deriveLocalExpectation, deriveLocalInput, deriveWireExpectation, deriveWireInput
|
|
19
|
+
import { deriveLocalExpectation, deriveLocalInput, deriveWireExpectation, deriveWireInput } from "./derive.js";
|
|
20
20
|
import { kitIdentity, loadCorpus } from "./corpus.js";
|
|
21
21
|
import { contractOwnedEntry, contractOwnedEntryWhy } from "./entry-origin.js";
|
|
22
22
|
import { mintLocalRoot, removeLocalRoot } from "./temp-roots.js";
|
|
@@ -109,15 +109,14 @@ export function resolveLegExpectation(c, leg, baseline) {
|
|
|
109
109
|
}
|
|
110
110
|
const from = { outcome: "effective", effective: source.effective, warnings: source.warnings, metadata: source.metadata };
|
|
111
111
|
if (leg === "wire") {
|
|
112
|
-
// **派生不许替被测 helper
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
// **派生不许替被测 helper 同时造输入与期望**:那只护栏(T2 不是恒等 ⇒ 拒)住在派生积木件自己身上 —— 跑器与直接调用同一只判、同一句;
|
|
113
|
+
// 这里只给它的拒句加上 case 坐标(语料作者要知道是哪一条)。
|
|
114
|
+
try {
|
|
115
|
+
return deriveWireExpectation(from, c.input.domains);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
throw new Error(`conformance corpus: ${c.id}/expected.json#wire cannot be derived — ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
119
119
|
}
|
|
120
|
-
return deriveWireExpectation(from, c.input.domains);
|
|
121
120
|
}
|
|
122
121
|
if (leg === "localRoot")
|
|
123
122
|
return deriveLocalExpectation(from, c.input.domains, baseline, spec.localVersion);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** 授权地址准入的查询参数名(闭集;起步只有 `intent`)。 */
|
|
2
|
+
export declare const CONNECTOR_AUTHORIZE_QUERY: readonly ["intent"];
|
|
3
|
+
export type ConnectorAuthorizeQueryName = (typeof CONNECTOR_AUTHORIZE_QUERY)[number];
|
|
4
|
+
/** 授权地址的瑕疵词(闭集;判序 = 本数组序)。 */
|
|
5
|
+
export declare const CONNECTOR_AUTHORIZE_URL_FLAWS: readonly ["not-http-url", "userinfo", "fragment", "not-https", "origin-mismatch", "path-not-start-route", "query-name-not-admitted", "query-name-repeated", "intent-missing"];
|
|
6
|
+
export type ConnectorAuthorizeUrlFlaw = (typeof CONNECTOR_AUTHORIZE_URL_FLAWS)[number];
|
|
7
|
+
/** 一台连接器的授权地址绑定的两件事:管理面的基址、被问的那一台连接器。 */
|
|
8
|
+
export interface ConnectorAuthorizeBinding {
|
|
9
|
+
readonly webUrl: string;
|
|
10
|
+
readonly connectorId: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 铸一台连接器的授权地址。`webUrl` = 管理面的 https 基址(无 userinfo / query / fragment;可带路径前缀;尾斜杠折掉);`connectorId` 过连接器 id 判官;
|
|
14
|
+
* `intent` 必填(非空、良构 UTF-16 的串,`encodeURIComponent` 编码;含孤立代理项 ⇒ 同为 `TypeError`)。坏输入一律抛 `TypeError`,不铸半截地址。产物对 {@link connectorAuthorizeUrlFlaws} 恒零瑕疵。
|
|
15
|
+
*/
|
|
16
|
+
export declare function connectorAuthorizeUrlOf(webUrl: string, connectorId: string, query: {
|
|
17
|
+
readonly intent: string;
|
|
18
|
+
}): string;
|
|
19
|
+
/**
|
|
20
|
+
* 判一个授权地址:`[]` = 零瑕疵;否则按判序交回瑕疵词(见文件头的律)。`binding` 是这一次被问的管理面与连接器 —— 它坏是调用方用错(抛 `TypeError`),不是地址坏。
|
|
21
|
+
* `raw` 不是串 ⇒ `["not-http-url"]`。
|
|
22
|
+
*/
|
|
23
|
+
export declare function connectorAuthorizeUrlFlaws(raw: string, binding: ConnectorAuthorizeBinding): readonly ConnectorAuthorizeUrlFlaw[];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 托管连接器的**授权地址**(29.0.0):拼装函数 {@link connectorAuthorizeUrlOf} 与它的瑕疵判官 {@link connectorAuthorizeUrlFlaws} —— 一处定义路由形与参数名
|
|
3
|
+
* (纯函数、零 I/O、浏览器安全)。地址形:
|
|
4
|
+
*
|
|
5
|
+
* <webUrl 去尾斜杠>/api/v1/connectors/<连接器 id>/oauth/start?intent=<intent>
|
|
6
|
+
*
|
|
7
|
+
* 路由属于管理面(它的 start 路由先验 `intent`,对不上就停在说明页);谁要给用户一个「去授权这台连接器」的地址 —— 铸口、对端座、文档 —— 调拼装函数,不按地址形手拼。
|
|
8
|
+
* 收到一个地址、要决定「能不能把它交给用户」的一方(对端座造「需授权」答复之前)问判官:它与拼装函数同包同源,拼装的产物恒零瑕疵。
|
|
9
|
+
*
|
|
10
|
+
* ## 判官的律(一条)
|
|
11
|
+
* **一个授权地址只在「是这一台连接器在这个管理面上的 start 路由、只带准入的参数、恰带一枚非空 `intent`」时零瑕疵。** 改写者能动的只剩 `intent` 的值。
|
|
12
|
+
* 瑕疵词闭集 {@link CONNECTOR_AUTHORIZE_URL_FLAWS},判序 = 表序:形(`not-http-url` / `userinfo` / `fragment`,问包内唯一的 URL 形判官)· `not-https` ·
|
|
13
|
+
* `origin-mismatch`(主机与端口 ≠ 管理面基址的;scheme 只由 `not-https` 说,一词一事)· `path-not-start-route`(路径 ≠ 这一台连接器的 start 路由,连接器 id 按字节比)· `query-name-not-admitted` /
|
|
14
|
+
* `query-name-repeated`(参数名闭集 {@link CONNECTOR_AUTHORIZE_QUERY})· `intent-missing`(缺席或空串)。形就不对(不是 http(s) URL)时只交形的词,其余不判。
|
|
15
|
+
* 答案只有词,不含值的任何片段(地址里的 `intent` 是一枚令牌)。
|
|
16
|
+
* 判官的绑定(`webUrl` / `connectorId`)与拼装的参数(`query.intent`)**只认自有键**({@link ownArgOf}):只靠继承可见的值当作没给 —— 被污染的原型给不出受信的绑定。
|
|
17
|
+
*/
|
|
18
|
+
import { CONNECTOR_ID_RULE, isConnectorId } from "./connector-id.js";
|
|
19
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
20
|
+
import { ownValueOf } from "./own-key-read.js";
|
|
21
|
+
import { jsonShapeOf } from "./plain-json-object.js";
|
|
22
|
+
import { httpUrlFlaws, httpUrlRule, pathBaseUrlFlaws } from "./url-shape.js";
|
|
23
|
+
/** 授权地址准入的查询参数名(闭集;起步只有 `intent`)。 */
|
|
24
|
+
export const CONNECTOR_AUTHORIZE_QUERY = deepFreeze(["intent"]);
|
|
25
|
+
/** 授权地址的瑕疵词(闭集;判序 = 本数组序)。 */
|
|
26
|
+
export const CONNECTOR_AUTHORIZE_URL_FLAWS = deepFreeze([
|
|
27
|
+
"not-http-url",
|
|
28
|
+
"userinfo",
|
|
29
|
+
"fragment",
|
|
30
|
+
"not-https",
|
|
31
|
+
"origin-mismatch",
|
|
32
|
+
"path-not-start-route",
|
|
33
|
+
"query-name-not-admitted",
|
|
34
|
+
"query-name-repeated",
|
|
35
|
+
"intent-missing",
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* 调用方交来的参数袋(判官的绑定、拼装的 `query`)上的一个成员 —— **只认自有键**(本包的自有键读法 `ownValueOf`):只靠继承可见(含 `Object.prototype` 被污染成数据值)、缺席、
|
|
39
|
+
* 读不出、袋本身不是对象 ⇒ 当作没给(`undefined`;随后的判法照常抛 `TypeError`)。被污染的原型因此不能替调用方给出一个「受信的」绑定。
|
|
40
|
+
*/
|
|
41
|
+
function ownArgOf(bag, key) {
|
|
42
|
+
const shape = jsonShapeOf(bag); // 形状只问座位(总、不抛);穷举 switch:座位加一个词这里编译红
|
|
43
|
+
switch (shape) {
|
|
44
|
+
case "plain":
|
|
45
|
+
case "non_plain_object":
|
|
46
|
+
case "array": {
|
|
47
|
+
const read = ownValueOf(bag, key);
|
|
48
|
+
return read.ok ? read.value : undefined;
|
|
49
|
+
}
|
|
50
|
+
case "null":
|
|
51
|
+
case "primitive":
|
|
52
|
+
case "uninspectable":
|
|
53
|
+
return undefined;
|
|
54
|
+
default: {
|
|
55
|
+
const unhandled = shape;
|
|
56
|
+
throw new Error(`ownArgOf: unhandled shape ${String(unhandled)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** 管理面基址 → 路由前缀(规范形,尾斜杠折掉)。基址必须是 https、可拼路径的干净基址(无 userinfo / query / fragment;可带路径前缀);否则抛(用错了,不是地址坏)。 */
|
|
61
|
+
function webBaseOf(fn, webUrl) {
|
|
62
|
+
if (typeof webUrl !== "string")
|
|
63
|
+
throw new TypeError(`${fn}: webUrl must be a string (an absolute https URL)`);
|
|
64
|
+
const flaws = pathBaseUrlFlaws(webUrl);
|
|
65
|
+
if (flaws.length > 0)
|
|
66
|
+
throw new TypeError(`${fn}: webUrl ${httpUrlRule(flaws[0])}`);
|
|
67
|
+
const base = new URL(webUrl);
|
|
68
|
+
if (base.protocol !== "https:")
|
|
69
|
+
throw new TypeError(`${fn}: webUrl must be an https URL (the authorization address is handed to a user's browser)`);
|
|
70
|
+
return base;
|
|
71
|
+
}
|
|
72
|
+
function connectorIdOf(fn, connectorId) {
|
|
73
|
+
if (!isConnectorId(connectorId))
|
|
74
|
+
throw new TypeError(`${fn}: connectorId ${CONNECTOR_ID_RULE}`);
|
|
75
|
+
return connectorId;
|
|
76
|
+
}
|
|
77
|
+
/** 这一台连接器的 start 路由路径(基址的路径前缀 + 路由;连接器 id 是 unreserved 字符,原样进路径段)。 */
|
|
78
|
+
function startRoutePath(base, connectorId) {
|
|
79
|
+
return `${base.pathname.replace(/\/+$/, "")}/api/v1/connectors/${connectorId}/oauth/start`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 铸一台连接器的授权地址。`webUrl` = 管理面的 https 基址(无 userinfo / query / fragment;可带路径前缀;尾斜杠折掉);`connectorId` 过连接器 id 判官;
|
|
83
|
+
* `intent` 必填(非空、良构 UTF-16 的串,`encodeURIComponent` 编码;含孤立代理项 ⇒ 同为 `TypeError`)。坏输入一律抛 `TypeError`,不铸半截地址。产物对 {@link connectorAuthorizeUrlFlaws} 恒零瑕疵。
|
|
84
|
+
*/
|
|
85
|
+
export function connectorAuthorizeUrlOf(webUrl, connectorId, query) {
|
|
86
|
+
const fn = "connectorAuthorizeUrlOf";
|
|
87
|
+
const base = webBaseOf(fn, webUrl);
|
|
88
|
+
const id = connectorIdOf(fn, connectorId);
|
|
89
|
+
const intent = ownArgOf(query, "intent");
|
|
90
|
+
if (typeof intent !== "string" || intent.length === 0)
|
|
91
|
+
throw new TypeError(`${fn}: intent is required (a non-empty string)`);
|
|
92
|
+
let encoded;
|
|
93
|
+
try {
|
|
94
|
+
encoded = encodeURIComponent(intent);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
throw new TypeError(`${fn}: intent must be well-formed text (it holds a lone surrogate)`);
|
|
98
|
+
}
|
|
99
|
+
return `${base.origin}${startRoutePath(base, id)}?intent=${encoded}`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 判一个授权地址:`[]` = 零瑕疵;否则按判序交回瑕疵词(见文件头的律)。`binding` 是这一次被问的管理面与连接器 —— 它坏是调用方用错(抛 `TypeError`),不是地址坏。
|
|
103
|
+
* `raw` 不是串 ⇒ `["not-http-url"]`。
|
|
104
|
+
*/
|
|
105
|
+
export function connectorAuthorizeUrlFlaws(raw, binding) {
|
|
106
|
+
const fn = "connectorAuthorizeUrlFlaws";
|
|
107
|
+
const base = webBaseOf(fn, ownArgOf(binding, "webUrl"));
|
|
108
|
+
const id = connectorIdOf(fn, ownArgOf(binding, "connectorId"));
|
|
109
|
+
if (typeof raw !== "string")
|
|
110
|
+
return ["not-http-url"];
|
|
111
|
+
const shape = httpUrlFlaws(raw, ["userinfo", "fragment"]);
|
|
112
|
+
if (shape.includes("not-http-url"))
|
|
113
|
+
return shape;
|
|
114
|
+
const u = new URL(raw);
|
|
115
|
+
const names = [...u.searchParams.keys()];
|
|
116
|
+
const intents = u.searchParams.getAll("intent");
|
|
117
|
+
const present = {
|
|
118
|
+
"not-http-url": false,
|
|
119
|
+
userinfo: shape.includes("userinfo"),
|
|
120
|
+
fragment: shape.includes("fragment"),
|
|
121
|
+
"not-https": u.protocol !== "https:",
|
|
122
|
+
"origin-mismatch": u.host !== base.host,
|
|
123
|
+
"path-not-start-route": u.pathname !== startRoutePath(base, id),
|
|
124
|
+
"query-name-not-admitted": names.some((n) => !CONNECTOR_AUTHORIZE_QUERY.includes(n)),
|
|
125
|
+
"query-name-repeated": new Set(names).size !== names.length,
|
|
126
|
+
"intent-missing": intents.length === 0 || (intents.length === 1 && intents[0] === ""),
|
|
127
|
+
};
|
|
128
|
+
return CONNECTOR_AUTHORIZE_URL_FLAWS.filter((flaw) => present[flaw]);
|
|
129
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 连接器 id(29.0.0)—— 一台托管连接器在部署登记册里的名字。纯函数、零 I/O、浏览器安全(外部的值依赖只有 zod;包内只用叶子模块 `./quoted-issue`)。
|
|
3
|
+
*
|
|
4
|
+
* ## 律(一条)
|
|
5
|
+
* **一个连接器 id 只有一种拼法、一只判官。** 同一个 id 同时是三处的值:MCP http 条目断言引用的 `audience`(断言的受众,原样使用、不翻译)、
|
|
6
|
+
* 授权地址路由里的连接器路径段(`./connector-authorize-url`)、部署登记册的行名 —— 三处都问 {@link isConnectorId},不各写一份形。
|
|
7
|
+
*
|
|
8
|
+
* ## 形
|
|
9
|
+
* DNS label:1–{@link CONNECTOR_ID_MAX} 个字符,只许小写 `a`–`z`、数字与 `-`,首尾必须是字母或数字(`a.b` / `a_b` / `a-` / `-a` / 大写 / 空串 / 64 字符都不是)。
|
|
10
|
+
* 比较按字节:这些字符都是 ASCII,且都在 RFC 3986 的 unreserved 集里 ⇒ `encodeURIComponent(id) === id`,放进路径段不变形、按字节比就是按值比。
|
|
11
|
+
* 不折大小写、不去空白、不做任何规范化 —— 判官拒掉的形在别处也不会被「修」成合法的 id。
|
|
12
|
+
* 「一个 id 删了不再复用」是登记册一方的不变式,本包只判形。
|
|
13
|
+
*/
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
/** 连接器 id 的最长长度(字符;DNS label 的上界)。 */
|
|
16
|
+
export declare const CONNECTOR_ID_MAX = 63;
|
|
17
|
+
/** 规则句(拒句里用;只说规则,不回显值)。 */
|
|
18
|
+
export declare const CONNECTOR_ID_RULE = "must be a connector id: a DNS label of 1-63 characters \u2014 lowercase a-z, digits and '-', starting and ending with a letter or digit";
|
|
19
|
+
/** 这是不是一个连接器 id(总:非串答 `false`,不抛)。 */
|
|
20
|
+
export declare function isConnectorId(v: unknown): v is string;
|
|
21
|
+
/** 连接器 id 的 zod 形:就是 {@link isConnectorId},拒句 = {@link CONNECTOR_ID_RULE}(固定句,铸点是包内唯一的 `buildQuotedIssue`:规则句整句进模板、没有值位)。 */
|
|
22
|
+
export declare const ConnectorId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
23
|
+
export type ConnectorId = z.infer<typeof ConnectorId>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 连接器 id(29.0.0)—— 一台托管连接器在部署登记册里的名字。纯函数、零 I/O、浏览器安全(外部的值依赖只有 zod;包内只用叶子模块 `./quoted-issue`)。
|
|
3
|
+
*
|
|
4
|
+
* ## 律(一条)
|
|
5
|
+
* **一个连接器 id 只有一种拼法、一只判官。** 同一个 id 同时是三处的值:MCP http 条目断言引用的 `audience`(断言的受众,原样使用、不翻译)、
|
|
6
|
+
* 授权地址路由里的连接器路径段(`./connector-authorize-url`)、部署登记册的行名 —— 三处都问 {@link isConnectorId},不各写一份形。
|
|
7
|
+
*
|
|
8
|
+
* ## 形
|
|
9
|
+
* DNS label:1–{@link CONNECTOR_ID_MAX} 个字符,只许小写 `a`–`z`、数字与 `-`,首尾必须是字母或数字(`a.b` / `a_b` / `a-` / `-a` / 大写 / 空串 / 64 字符都不是)。
|
|
10
|
+
* 比较按字节:这些字符都是 ASCII,且都在 RFC 3986 的 unreserved 集里 ⇒ `encodeURIComponent(id) === id`,放进路径段不变形、按字节比就是按值比。
|
|
11
|
+
* 不折大小写、不去空白、不做任何规范化 —— 判官拒掉的形在别处也不会被「修」成合法的 id。
|
|
12
|
+
* 「一个 id 删了不再复用」是登记册一方的不变式,本包只判形。
|
|
13
|
+
*/
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
import { buildQuotedIssue, fixed } from "./quoted-issue.js";
|
|
16
|
+
/** 连接器 id 的最长长度(字符;DNS label 的上界)。 */
|
|
17
|
+
export const CONNECTOR_ID_MAX = 63;
|
|
18
|
+
/** 形的唯一表示:由 {@link CONNECTOR_ID_MAX} 铸(首尾各一个字母数字,中间至多 `MAX - 2` 个)。 */
|
|
19
|
+
const CONNECTOR_ID_FORM = new RegExp(`^[a-z0-9](?:[a-z0-9-]{0,${CONNECTOR_ID_MAX - 2}}[a-z0-9])?$`);
|
|
20
|
+
/** 规则句(拒句里用;只说规则,不回显值)。 */
|
|
21
|
+
export const CONNECTOR_ID_RULE = `must be a connector id: a DNS label of 1-${CONNECTOR_ID_MAX} characters — lowercase a-z, digits and '-', starting and ending with a letter or digit`;
|
|
22
|
+
/** 这是不是一个连接器 id(总:非串答 `false`,不抛)。 */
|
|
23
|
+
export function isConnectorId(v) {
|
|
24
|
+
return typeof v === "string" && CONNECTOR_ID_FORM.test(v);
|
|
25
|
+
}
|
|
26
|
+
/** 连接器 id 的 zod 形:就是 {@link isConnectorId},拒句 = {@link CONNECTOR_ID_RULE}(固定句,铸点是包内唯一的 `buildQuotedIssue`:规则句整句进模板、没有值位)。 */
|
|
27
|
+
export const ConnectorId = z.string().refine(isConnectorId, buildQuotedIssue `${fixed(CONNECTOR_ID_RULE)}`);
|
package/dist/file-edit.d.ts
CHANGED
|
@@ -21,6 +21,50 @@ export declare function domainFilePath(root: string, domain: DomainName): string
|
|
|
21
21
|
* leaves a half-written config.d/<domain>.json; a new file takes the contract-document mode (0o644), an existing one keeps its own.
|
|
22
22
|
* VALIDATES first (throws on invalid — never persists garbage); persists the parsed + defaulted value so the file is canonical. */
|
|
23
23
|
export declare function writeDomainFile<K extends DomainName>(root: string, domain: K, value: unknown): Promise<DomainConfig[K]>;
|
|
24
|
+
/** The answer of {@link writeDomainFileIf} — a closed, discriminated union on `status` (switch over it exhaustively):
|
|
25
|
+
* · `written` — the file's bytes matched the expected digest and the new document was written; `value` is the parsed + defaulted document that was written, `digest` is the digest of the bytes now on disk
|
|
26
|
+
* (feed it straight back as the next call's `expected`, no re-read needed). `lockLeft` is present only when the write landed but the lock file could not be removed afterwards: it names that file
|
|
27
|
+
* (every later conditional write answers `locked` until it is deleted); a failed clean-up never replaces the outcome;
|
|
28
|
+
* · `stale` — the file's bytes did not match: nothing was written, not a byte of the file changed. `current` is the digest of the bytes on disk now, or `null` when the file is not there
|
|
29
|
+
* (re-read, re-apply the change on top of what is there, and call again);
|
|
30
|
+
* · `locked` — the lock file is held: nothing was written and the file was not read. `lock` is the lock file's absolute path. A lock left behind by a writer that crashed is never taken over
|
|
31
|
+
* (there is no safe way to tell it from a live holder): delete the file named by `lock` once no writer is running, its text is the holder's pid. */
|
|
32
|
+
export type ConditionalWriteResult<K extends DomainName> = {
|
|
33
|
+
readonly status: "written";
|
|
34
|
+
readonly value: DomainConfig[K];
|
|
35
|
+
readonly digest: string;
|
|
36
|
+
readonly lockLeft?: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly status: "stale";
|
|
39
|
+
readonly current: string | null;
|
|
40
|
+
} | {
|
|
41
|
+
readonly status: "locked";
|
|
42
|
+
readonly lock: string;
|
|
43
|
+
};
|
|
44
|
+
/** WRITE a domain file ATOMICALLY **only if it still holds what the caller read** — the compare-and-write form of {@link writeDomainFile}, for read-modify-write callers whose edit must not overwrite a change
|
|
45
|
+
* made after their read (a lost update).
|
|
46
|
+
*
|
|
47
|
+
* `expected` is the digest of the file's **bytes** as the caller read them — every byte, whatever it decodes to — in the package's one digest spelling (`sha256:<64 lowercase hex>`, minted by
|
|
48
|
+
* `contentDigest` from `@sema-agent/settings-schema/sha256`, which takes the `Buffer` that `readFile` returned), or `null` when the file was absent. Anything else is a `TypeError` (a malformed digest
|
|
49
|
+
* would never match and be mistaken for a concurrent change). Digest the bytes you PARSED — read the file once, digest that `Buffer` and parse `buffer.toString("utf8")` — never a second read.
|
|
50
|
+
* (For a file that is valid UTF-8 the digest of its decoded text is the same digest, so a caller that digests the text it read is right too; a text decoded from bytes that are not valid UTF-8 has lost
|
|
51
|
+
* those bytes — each bad sequence became U+FFFD — and digests differently from the file.)
|
|
52
|
+
*
|
|
53
|
+
* Order (the same checks as {@link writeDomainFile} come first, so a refused write never takes a lock or touches a byte): the name guard → the `expected` form → the whole-document verdict
|
|
54
|
+
* (`parseDomain`; throws on a value the contract refuses, the same sentence as the unconditional writer) → create `config.d` if it is missing → take the lock → re-read the file under the lock →
|
|
55
|
+
* compare digests → write atomically (the package's one atomic writer: same directory, same mode rules, a symbolic link is written through) → remove the lock. Removal is attempted on every path that
|
|
56
|
+
* took the lock, success or failure; a failure after the lock is thrown as it is, and a failure to remove the lock never replaces the outcome (see `lockLeft` in {@link ConditionalWriteResult}).
|
|
57
|
+
*
|
|
58
|
+
* The lock is the hidden file `.<file>.lock` beside the file that is actually written — for a plain `config.d/<domain>.json` that is `config.d/.<domain>.json.lock`; when the domain file is a symbolic
|
|
59
|
+
* link it sits beside the link's real target, so two roots whose links point at one real file share one lock. Created exclusively (the package's existing create-only-if-absent primitive — the same
|
|
60
|
+
* one the root-level decision document uses), holding the writer's pid. A held lock answers `locked` and nothing else happens; there is no wait and no retry, the caller decides. The hidden,
|
|
61
|
+
* non-`.json` name keeps it out of every `config.d` scan.
|
|
62
|
+
*
|
|
63
|
+
* What it does NOT do: the lock and the digest coordinate callers of THIS function. An unconditional {@link writeDomainFile}, `writeBundle`, the directory migration or a hand edit takes no lock and can still land between
|
|
64
|
+
* this call's re-read and its write; the only protection against those is that the compare happens under the lock, microseconds before the rename.
|
|
65
|
+
*
|
|
66
|
+
* Resolves `{ status: "written" | "stale" | "locked", … }` ({@link ConditionalWriteResult}); rejects on invalid input, an unreadable file and file-system failures. */
|
|
67
|
+
export declare function writeDomainFileIf<K extends DomainName>(root: string, domain: K, value: unknown, expected: string | null): Promise<ConditionalWriteResult<K>>;
|
|
24
68
|
export interface RequiredEnvName {
|
|
25
69
|
envName: string;
|
|
26
70
|
refs: {
|