@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
package/dist/file-edit.js
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Validation uses the SAME zod schemas as the server's parseDomain → identical rules on both sides.
|
|
7
7
|
*/
|
|
8
|
+
import { unlinkSync } from "node:fs";
|
|
8
9
|
import { mkdir } from "node:fs/promises";
|
|
9
10
|
import path from "node:path";
|
|
10
|
-
import { writeFileAtomic } from "./atomic-write.js";
|
|
11
|
+
import { createFileExclusive, readBytesIfPresent, resolveSymlinkTarget, writeFileAtomic } from "./atomic-write.js";
|
|
11
12
|
import { emptyDocument, guardedSafeParse } from "./own-key-read.js";
|
|
12
13
|
import { collectEnvRefs } from "./secret-refs.js";
|
|
14
|
+
import { SHA256_DIGEST_RE, contentDigest } from "./sha256.js";
|
|
13
15
|
import { REMOTE_EXEC_DOCUMENT, RemoteExecSpec } from "./remote-exec.js";
|
|
14
16
|
import { configDDocumentText } from "./config-d-file.js";
|
|
15
17
|
import { buildQuotedIssue, fixed } from "./quoted-issue.js";
|
|
@@ -69,6 +71,73 @@ export async function writeDomainFile(root, domain, value) {
|
|
|
69
71
|
writeFileAtomic(path.join(dir, `${domain}.json`), configDDocumentText(parsed), "config-document");
|
|
70
72
|
return parsed;
|
|
71
73
|
}
|
|
74
|
+
/** Remove the lock this call created: `true` = it is gone (an already-missing lock counts — someone cleaned it), `false` = it could not be removed and is still there. Never throws: a clean-up failure
|
|
75
|
+
* must not replace the outcome it follows (a landed write, or the error that ended the call); a lock left behind is reported by the result (`lockLeft`) and by every later call (`locked`). */
|
|
76
|
+
function releaseLock(lock) {
|
|
77
|
+
try {
|
|
78
|
+
unlinkSync(lock);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
return e.code === "ENOENT";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** 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
|
|
86
|
+
* made after their read (a lost update).
|
|
87
|
+
*
|
|
88
|
+
* `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
|
|
89
|
+
* `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
|
|
90
|
+
* 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.
|
|
91
|
+
* (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
|
|
92
|
+
* those bytes — each bad sequence became U+FFFD — and digests differently from the file.)
|
|
93
|
+
*
|
|
94
|
+
* 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
|
|
95
|
+
* (`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 →
|
|
96
|
+
* 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
|
|
97
|
+
* 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}).
|
|
98
|
+
*
|
|
99
|
+
* 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
|
|
100
|
+
* 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
|
|
101
|
+
* 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,
|
|
102
|
+
* non-`.json` name keeps it out of every `config.d` scan.
|
|
103
|
+
*
|
|
104
|
+
* 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
|
|
105
|
+
* 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.
|
|
106
|
+
*
|
|
107
|
+
* Resolves `{ status: "written" | "stale" | "locked", … }` ({@link ConditionalWriteResult}); rejects on invalid input, an unreadable file and file-system failures. */
|
|
108
|
+
export async function writeDomainFileIf(root, domain, value, expected) {
|
|
109
|
+
assertDomainName(domain); // a stray non-domain key fails LOUD + clear, as in writeDomainFile
|
|
110
|
+
if (expected !== null && !(typeof expected === "string" && SHA256_DIGEST_RE.test(expected))) {
|
|
111
|
+
throw new TypeError(`writeDomainFileIf: \`expected\` must be null (the file was absent when read) or a "sha256:<64 lowercase hex>" digest of the text that was read, not ${expected === undefined ? "undefined" : typeof expected === "string" ? "another string" : `a ${typeof expected}`}`);
|
|
112
|
+
}
|
|
113
|
+
const parsed = parseDomain(domain, value); // the one whole-document verdict, before any lock or byte
|
|
114
|
+
const dir = path.join(root, "config.d");
|
|
115
|
+
const file = path.join(dir, `${domain}.json`);
|
|
116
|
+
await mkdir(dir, { recursive: true });
|
|
117
|
+
const real = resolveSymlinkTarget(file); // the file that is actually written (a link is followed; a dangling link throws the package's one sentence, before any lock)
|
|
118
|
+
const lock = path.join(path.dirname(real), `.${path.basename(real)}.lock`); // keyed by the real destination: aliases of one file share one lock
|
|
119
|
+
if (createFileExclusive(lock, `${process.pid}\n`, "config-document") === "present")
|
|
120
|
+
return { status: "locked", lock }; // not ours: never touched
|
|
121
|
+
let outcome;
|
|
122
|
+
try {
|
|
123
|
+
const present = await readBytesIfPresent(file, [dir]); // under the lock; the raw bytes (no decoding); the one absence rule (a dangling link is loud, not absent)
|
|
124
|
+
const current = present === undefined ? null : contentDigest(present);
|
|
125
|
+
if (current !== expected) {
|
|
126
|
+
outcome = { status: "stale", current };
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const text = configDDocumentText(parsed);
|
|
130
|
+
writeFileAtomic(file, text, "config-document");
|
|
131
|
+
outcome = { status: "written", value: parsed, digest: contentDigest(text) };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
const released = releaseLock(lock); // never throws: the error in flight (if any) stays the error
|
|
136
|
+
if (outcome?.status === "written" && !released)
|
|
137
|
+
outcome = { ...outcome, lockLeft: lock };
|
|
138
|
+
}
|
|
139
|
+
return outcome;
|
|
140
|
+
}
|
|
72
141
|
/** LIST every env-NAME the current local config requires (across models/workers/mcp/a2a + the
|
|
73
142
|
* remote-exec backend), marking which are MISSING from the resolved env — the TOC "you still need to set
|
|
74
143
|
* these secrets" panel. Reuses collectEnvRefs for the domain side, then appends the remoteExec secret refs. */
|
package/dist/file-store.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type EffectiveReadWarning } from "./config-fns.js";
|
|
|
2
2
|
import type { ConfigDocumentRefusal } from "./config-document-refusal.js";
|
|
3
3
|
import type { ConfigReader } from "./reader.js";
|
|
4
4
|
import { type DomainConfig, type DomainName, type EffectiveConfig, type RetiredDomainName } from "./types.js";
|
|
5
|
-
export { NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS, type PortableDomain } from "./portable-domains.js";
|
|
5
|
+
export { LOCAL_READ_DOMAINS, NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS, type LocalReadDomain, type PortableDomain } from "./portable-domains.js";
|
|
6
6
|
/** `config.d/` 里**合法存在但不是域文档**的文件名(不进 `"unread-config-file"` 告警)。`remote-exec`
|
|
7
7
|
* 不是 `DOMAIN_SCHEMAS` 成员(resolver 不读它),按 service 表决住在这个目录,由 loadRemoteExec 读
|
|
8
8
|
* ——**它有自己的校验路径**(读盘与域文档同一只 `config.d` 文档读法,值判是 `RemoteExecSpec`),所以既不是「未知文件」也不是「域文件」。
|
|
@@ -30,7 +30,7 @@ export type FileConfigRead =
|
|
|
30
30
|
readonly effective: EffectiveConfig;
|
|
31
31
|
readonly warnings: readonly EffectiveReadWarning[];
|
|
32
32
|
}
|
|
33
|
-
/** 至少一份文档在文件层被拒:`refusals` = 整棵目录的拒单(次序确定:retired
|
|
33
|
+
/** 至少一份文档在文件层被拒:`refusals` = 整棵目录的拒单(次序确定:retired 域文档在前,按墓碑表的声明次序;本地读取域按 `LOCAL_READ_DOMAINS` 的次序);
|
|
34
34
|
* `version` = 这一次读到的整棵目录的内容版本(被拒的文档以坏文档的指纹参与 —— 与宽容读的坏文件哨兵同一只:同样的坏内容同一个数、坏内容变了换数、
|
|
35
35
|
* 绝不与「文件缺席」同数);`warnings` = 没人读的文件(装配没有发生)。 */
|
|
36
36
|
| {
|
|
@@ -58,9 +58,10 @@ export declare class FileConfigStore implements ConfigReader {
|
|
|
58
58
|
* `has(domain) ? parse : undefined`. Only an ABSENT file (ENOENT with nothing at the path; a dangling symlink is not absence) is absence → undefined. A present `{}` IS a set
|
|
59
59
|
* domain → parsed with defaults. A present file that is empty or whitespace-only (a half-write) throws as a corrupt file,
|
|
60
60
|
* as do bad JSON, a non-object, an unreadable file and one nested too deep (the same reading as getEffective / readBundle).
|
|
61
|
-
* (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.)
|
|
61
|
+
* (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.)
|
|
62
|
+
* A per-domain single read: it does not consult {@link LOCAL_READ_DOMAINS} (the enumerating reads — `getEffective` / `read()` / `getVersion()` — do), so the bundle helpers put the portable-set gate in front of it. */
|
|
62
63
|
getDomain<K extends DomainName>(domain: K): Promise<DomainConfig[K] | undefined>;
|
|
63
|
-
/** All
|
|
64
|
+
/** All local-read domains → EffectiveConfig. The PAYLOAD and its `version` come from ONE raws snapshot (no
|
|
64
65
|
* re-read between them — else a concurrent atomic rename could pair payload A with version B and a consumer
|
|
65
66
|
* would skip the change). `updatedAt` = max file mtime (informational; the content-hash version is the
|
|
66
67
|
* authoritative change-detector).
|
|
@@ -81,14 +82,18 @@ export declare class FileConfigStore implements ConfigReader {
|
|
|
81
82
|
tolerant: true;
|
|
82
83
|
}): Promise<TolerantEffective>;
|
|
83
84
|
/** Stable version number for the current files: same files ⇒ same number ⇒ a consumer's "skip re-apply if
|
|
84
|
-
* version unchanged" works locally too.
|
|
85
|
+
* version unchanged" works locally too. It is the number `read()` carries for the same tree (one snapshot reading, {@link #snapshot}) ——
|
|
86
|
+
* answered for every tree, including one with a document refused at the file layer (29.0.0; it threw before): that document joins as its
|
|
87
|
+
* fingerprint sentinel, never as absence. Shape (schema) does not enter the version: a gated domain that reads but fails its schema has a
|
|
88
|
+
* version here while `read()` / `getEffective()` throw for it. */
|
|
85
89
|
getVersion(): Promise<number>;
|
|
86
90
|
/**
|
|
87
|
-
* **单读口**(16.0.0):一次读整棵 `config.d`(
|
|
91
|
+
* **单读口**(16.0.0):一次读整棵 `config.d`(全部本地读取域 + retired 域的墓碑文档,每份只读一次),交一个结局({@link FileConfigRead})——
|
|
88
92
|
* · 每份文档在文件层都读得进 ⇒ `effective`:与严读 `getEffective()` 逐位同;读侧告警交成数据(没人读的文件 + 装配告警,不经 `onWarning`);
|
|
89
93
|
* · 有文档在文件层被拒(空 / 坏 JSON / 不是对象 / 读不出 / 过深;带事实的 retired 域文档是墓碑拒,带迁移编号)⇒ `refused`:整棵目录的拒单与这一次读到的内容版本。
|
|
90
94
|
* 严读与 `readBundle` 读的是同一只文件读法(`./config-d-file` 的读数)—— 同一种坏形同一个词、同一句话;区别只在渲染:严读遇到第一份坏文档就抛,本方法把整个目录读完、逐份交出。
|
|
91
|
-
* 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 ——
|
|
95
|
+
* 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 —— 那是判形,不在拒单里;判形不进版本,那棵树的版本 `getVersion()` 照答。拒单、版本、effective、告警都出自这一次读到的字节:没有「先抛、再重探」的第二次读。
|
|
96
|
+
* 版本与 `getVersion()` 是同一个数(同一只快照读法 {@link #snapshot})。
|
|
92
97
|
*/
|
|
93
98
|
read(): Promise<FileConfigRead>;
|
|
94
99
|
}
|
package/dist/file-store.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* FileConfigStore — a local, single-machine config source for the TOC desktop/CLI. Reads the
|
|
2
|
+
* FileConfigStore — a local, single-machine config source for the TOC desktop/CLI. Reads the LOCAL-READ domains ({@link LOCAL_READ_DOMAINS})
|
|
3
3
|
* from `<root>/config.d/<domain>.json` (one file per domain, each = exactly that domain's zod object) and
|
|
4
4
|
* resolves them into an {@link EffectiveConfig} via the SAME pure `buildEffective`/`parseDomain` the server
|
|
5
5
|
* stores use. Implements ONLY the narrow {@link ConfigReader} (3 methods) — no publish/RBAC/worker-status.
|
|
6
6
|
*
|
|
7
7
|
* LOCAL FILE LAYOUT (the TOC owns the root, e.g. `~/.ai-agent/` or a project-local `.ai-agent/`):
|
|
8
|
-
* <root>/config.d/<domain>.json for every domain in {@link
|
|
8
|
+
* <root>/config.d/<domain>.json for every domain in {@link LOCAL_READ_DOMAINS} — that constant is the
|
|
9
9
|
* AUTHORITY; do NOT hand-copy the list here (the hand-written enumeration that used to sit
|
|
10
10
|
* on this line silently missed `prompts` for three releases — 对抗复审 复审 round2 F5).
|
|
11
|
+
* It is {@link PORTABLE_DOMAINS} plus `projects`: the local set answers "which documents does this store read",
|
|
12
|
+
* the portable set answers "which domains travel in a bundle" — two questions, two constants.
|
|
11
13
|
* <root>/.env secret VALUES (KEY=value) — the ONLY file holding secrets; gitignored, never read here.
|
|
12
14
|
*
|
|
13
15
|
* Rules:
|
|
@@ -17,25 +19,28 @@
|
|
|
17
19
|
* "absent/defaults" the file must be missing, not empty. A valid `{}` object IS a set domain (→ defaults).
|
|
18
20
|
* - `read()` (16.0.0) is the ONE read that answers both ways: the effective config + its read warnings as data when every
|
|
19
21
|
* document reads, or the typed refusal list of the whole directory + its version when one does not — every document read once.
|
|
20
|
-
* -
|
|
21
|
-
* etc.) — no stubbing needed. 逐域为什么被排除见 {@link NON_PORTABLE_DOMAIN_REASONS}(禁裸排除)。
|
|
22
|
+
* - Domains outside the local-read set (`workers` / `hosts` / `systems` / `entitlement`) are OMITTED on a single machine and resolve to their schema defaults (`{workers:[]}`
|
|
23
|
+
* etc.) — no stubbing needed; their files are named by an `"unread-config-file"` warning. 逐域为什么被排除见 {@link NON_PORTABLE_DOMAIN_REASONS}(禁裸排除)。
|
|
22
24
|
* - A RETIRED domain's file (`config.d/runtime.json`, see `RETIRED_DOMAINS`) is read only for its tombstone: carrying facts ⇒
|
|
23
25
|
* every read entry (`getDomain`, `getEffective` — and so `exportBundle`) throws `RetiredDomainError` (`refuseRetiredDomainFiles`, shared with `readBundle`) (the sentence names where the facts live today — `governance` and `limits`); `{}` carries nothing and is left alone. It is never an "unread file".
|
|
24
26
|
* - The JSON files only ever carry env-NAMEs (the ENV_NAME boundary holds locally too); `.env` holds values.
|
|
25
|
-
* - `getVersion()` = a stable content hash of all
|
|
26
|
-
* "skip re-apply if version unchanged" works locally. `
|
|
27
|
+
* - `getVersion()` = a stable content hash of all local-read files (and the retired domains' tombstone documents) → a u53 number, so a consumer's
|
|
28
|
+
* "skip re-apply if version unchanged" works locally. It is the one content version of the tree: `read()` carries the same number
|
|
29
|
+
* (one file-level snapshot; a refused document joins as its fingerprint, never as absence), and so does `getEffective().version`
|
|
30
|
+
* whenever that read returns. `getEffective().updatedAt` = the max file mtime,
|
|
27
31
|
* passed EXPLICITLY into buildEffective (the determinism refactor) so identical files ⇒ identical bytes.
|
|
28
32
|
*/
|
|
29
33
|
import { readdir, stat } from "node:fs/promises";
|
|
30
34
|
import path from "node:path";
|
|
31
35
|
import { RetiredDomainError, buildEffective, DOMAIN_READ_FALLBACK, parseDomainLoud, refuseRetiredDomain } from "./config-fns.js";
|
|
32
36
|
import { RETIRED_DOMAIN_NAMES, configDPath, configDVersionOf, corruptDocumentRaw, readConfigDFile, readConfigDFileReading, refuseRetiredDomainFiles } from "./config-d-file.js";
|
|
33
|
-
import {
|
|
37
|
+
import { LOCAL_READ_DOMAINS } from "./portable-domains.js";
|
|
34
38
|
import { REMOTE_EXEC_DOCUMENT } from "./remote-exec.js";
|
|
35
39
|
import { isDomainName, isRetiredDomainName } from "./types.js";
|
|
36
40
|
import { deepFreeze } from "./deep-freeze.js";
|
|
37
|
-
//
|
|
38
|
-
|
|
41
|
+
// 域集合表的定义住在纯叶 ./portable-domains.ts(14.6.0;零 node 依赖,主桶模块可 import);这里原名转出口,`./node` 子路径逐名不变。
|
|
42
|
+
// 便携域集(搬运义:bundle 的默认集)与本地读取域集(本地读取义:本文件读哪些域)是两只常量 —— 本文件里按「读」枚举的各处读后者,不读前者。
|
|
43
|
+
export { LOCAL_READ_DOMAINS, NON_PORTABLE_DOMAIN_REASONS, PORTABLE_DOMAINS } from "./portable-domains.js";
|
|
39
44
|
/** `config.d/` 里**合法存在但不是域文档**的文件名(不进 `"unread-config-file"` 告警)。`remote-exec`
|
|
40
45
|
* 不是 `DOMAIN_SCHEMAS` 成员(resolver 不读它),按 service 表决住在这个目录,由 loadRemoteExec 读
|
|
41
46
|
* ——**它有自己的校验路径**(读盘与域文档同一只 `config.d` 文档读法,值判是 `RemoteExecSpec`),所以既不是「未知文件」也不是「域文件」。
|
|
@@ -63,9 +68,9 @@ export class FileConfigStore {
|
|
|
63
68
|
* file (nothing at the path — ENOENT and not a dangling symlink) → undefined = the domain is ABSENT (the ONLY way to mean "use defaults"); a present file that is EMPTY/whitespace-only,
|
|
64
69
|
* or parses to anything but a JSON OBJECT, is CORRUPT → throw, FAIL CLOSED (an empty present file is a half-write/truncation, NOT
|
|
65
70
|
* "absent": treating it as absent would silently DROP a published domain — e.g. a truncated governance.json drops its
|
|
66
|
-
* commandPolicy/autonomy guardrails).
|
|
67
|
-
* `undefined` (absent) and `null` to the SAME bytes, so
|
|
68
|
-
*
|
|
71
|
+
* commandPolicy/autonomy guardrails). The version never reads a corrupt file as absence either: stableStringify collapses
|
|
72
|
+
* `undefined` (absent) and `null` to the SAME bytes, so the version snapshot ({@link #snapshot}) puts a refused document in as its
|
|
73
|
+
* fingerprint sentinel — a version-gated poller sees the change that getEffective/getDomain FAIL on. R17 + R(0.1.27 整体复审). */
|
|
69
74
|
async #readDomainRaw(domain) {
|
|
70
75
|
return readConfigDFile(this.root, domain); // the shared reader guards the name (configDPath)
|
|
71
76
|
}
|
|
@@ -77,7 +82,8 @@ export class FileConfigStore {
|
|
|
77
82
|
* 闭集 —— 文件在、进程跑、限额还是 env 老值,**零告警**(「域缺席」与「文件不存在」在下游逐字同形)。
|
|
78
83
|
* 修法方向是**响亮,不是收紧**:未登记文件照旧不读(拒收会让一个无害的散落文件打死整个部署),但必须
|
|
79
84
|
* 说出来。两类分开报,因为处置不同:`not-a-domain` = 名字打错 / 消费方开了本包还不认识的域(要来本包
|
|
80
|
-
* 登记);`
|
|
85
|
+
* 登记);`not-a-local-read-domain` = 域认识但本地读取集({@link LOCAL_READ_DOMAINS})刻意不含它(workers / hosts / systems / entitlement;`projects` 不在此列 —— 它在本地读取集里,被读)。
|
|
86
|
+
* 这四个域为什么不读,没有自己的理由表,借用搬运义的 {@link NON_PORTABLE_DOMAIN_REASONS}(它答的是「为什么不随 bundle 搬运」,键集含 `projects`、与本地读取集排除的四个不同)—— 借用,不是这个词的理由表。
|
|
81
87
|
*
|
|
82
88
|
* 只在挂了 `onWarning` 时才 readdir —— 没接通道的调用方不该为一条没人听的警告付 IO(诚实登记:
|
|
83
89
|
* 因此本门的响亮程度取决于消费方接不接这个座)。忽略:隐藏文件(含 file-edit 原子写的 `.<域>.json.*.tmp`
|
|
@@ -106,29 +112,58 @@ export class FileConfigStore {
|
|
|
106
112
|
if (name.startsWith(".") || !name.endsWith(".json") || NON_DOMAIN_CONFIG_FILES.has(name))
|
|
107
113
|
continue;
|
|
108
114
|
const base = name.slice(0, -".json".length);
|
|
109
|
-
if (
|
|
115
|
+
if (LOCAL_READ_DOMAINS.includes(base))
|
|
110
116
|
continue; // 真被读的域
|
|
111
117
|
if (isRetiredDomainName(base))
|
|
112
118
|
continue; // retired 域:由墓碑判(带事实 ⇒ getEffective 抛),不是「没人读的文件」
|
|
113
119
|
out.push(isDomainName(base)
|
|
114
|
-
? { kind: "unread-config-file", file: name, domain: base, why: "
|
|
120
|
+
? { kind: "unread-config-file", file: name, domain: base, why: "not-a-local-read-domain" }
|
|
115
121
|
: { kind: "unread-config-file", file: name, why: "not-a-domain" });
|
|
116
122
|
}
|
|
117
123
|
return out;
|
|
118
124
|
}
|
|
119
|
-
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
/**
|
|
126
|
+
* 整棵目录的**一次文件层读数**(retired 域的墓碑文档 + 全部本地读取域,每份只读一次)—— 内容版本的入参与拒单都出自它,`read()` 与 `getVersion()` 读这同一只:
|
|
127
|
+
* · 版本入参 `raws`:在场 ⇒ 原文解析后的值;缺席 ⇒ `undefined`;在文件层被拒 ⇒ 那份坏文档的指纹哨兵(`corruptDocumentRaw`:绝不与缺席同数,坏内容变了换数)。
|
|
128
|
+
* retired 域文档进版本:它出现 / 变了,读的结局就在拒与读之间翻,按版本轮询的消费方必须看得到。
|
|
129
|
+
* · `refusals`:文件层的拒(次序 = 读的次序:retired 域在前,本地读取域按 `LOCAL_READ_DOMAINS`)+ 带事实的墓碑。
|
|
130
|
+
*/
|
|
131
|
+
async #snapshot() {
|
|
132
|
+
const documents = [...RETIRED_DOMAIN_NAMES, ...LOCAL_READ_DOMAINS];
|
|
133
|
+
const readings = await Promise.all(documents.map((d) => readConfigDFileReading(this.root, d)));
|
|
134
|
+
const raws = {};
|
|
135
|
+
const refusals = [];
|
|
136
|
+
documents.forEach((document, i) => {
|
|
137
|
+
const reading = readings[i];
|
|
138
|
+
switch (reading.status) {
|
|
139
|
+
case "absent":
|
|
140
|
+
raws[document] = undefined;
|
|
141
|
+
return;
|
|
142
|
+
case "refused":
|
|
143
|
+
raws[document] = corruptDocumentRaw(reading);
|
|
144
|
+
refusals.push({ document, reason: reading.reason, error: reading.error });
|
|
145
|
+
return;
|
|
146
|
+
case "present":
|
|
147
|
+
raws[document] = reading.value;
|
|
148
|
+
if (isRetiredDomainName(document)) {
|
|
149
|
+
const tombstone = tombstoneOf(document, reading.value);
|
|
150
|
+
if (tombstone !== undefined)
|
|
151
|
+
refusals.push(tombstone);
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
default: {
|
|
155
|
+
const unhandled = reading;
|
|
156
|
+
throw new Error(`FileConfigStore: unhandled reading ${String(unhandled)}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return { raws, refusals };
|
|
126
161
|
}
|
|
127
|
-
/** The max mtime (ISO) across the present
|
|
162
|
+
/** The max mtime (ISO) across the present local-read files, or the epoch when none exist — so `updatedAt`
|
|
128
163
|
* is deterministic for a given set of files (not the wall clock). */
|
|
129
164
|
async #maxMtimeIso() {
|
|
130
165
|
let maxMs = 0;
|
|
131
|
-
await Promise.all(
|
|
166
|
+
await Promise.all(LOCAL_READ_DOMAINS.map(async (d) => {
|
|
132
167
|
try {
|
|
133
168
|
const s = await stat(this.domainPath(d));
|
|
134
169
|
if (s.mtimeMs > maxMs)
|
|
@@ -146,7 +181,8 @@ export class FileConfigStore {
|
|
|
146
181
|
* `has(domain) ? parse : undefined`. Only an ABSENT file (ENOENT with nothing at the path; a dangling symlink is not absence) is absence → undefined. A present `{}` IS a set
|
|
147
182
|
* domain → parsed with defaults. A present file that is empty or whitespace-only (a half-write) throws as a corrupt file,
|
|
148
183
|
* as do bad JSON, a non-object, an unreadable file and one nested too deep (the same reading as getEffective / readBundle).
|
|
149
|
-
* (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.)
|
|
184
|
+
* (getEffective still fills defaults for absent domains; getDomain is the per-domain "was this ever set?" probe.)
|
|
185
|
+
* A per-domain single read: it does not consult {@link LOCAL_READ_DOMAINS} (the enumerating reads — `getEffective` / `read()` / `getVersion()` — do), so the bundle helpers put the portable-set gate in front of it. */
|
|
150
186
|
async getDomain(domain) {
|
|
151
187
|
await refuseRetiredDomainFiles(this.root); // every read entry asks the tombstone first (exportBundle reads through here)
|
|
152
188
|
const raw = await this.#readDomainRaw(domain);
|
|
@@ -167,7 +203,7 @@ export class FileConfigStore {
|
|
|
167
203
|
if (opts?.tolerant !== true) {
|
|
168
204
|
const [retired] = await Promise.all([refuseRetiredDomainFiles(this.root), this.#warnUnreadFiles()]); // 两条读法同一门(0.19.0)
|
|
169
205
|
const raws = { ...retired };
|
|
170
|
-
await Promise.all(
|
|
206
|
+
await Promise.all(LOCAL_READ_DOMAINS.map(async (d) => { raws[d] = await this.#readDomainRaw(d); }));
|
|
171
207
|
const updatedAt = await this.#maxMtimeIso();
|
|
172
208
|
return buildEffective(this.#versionOf(raws), (d) => raws[d], updatedAt, this.opts.onWarning);
|
|
173
209
|
}
|
|
@@ -178,7 +214,7 @@ export class FileConfigStore {
|
|
|
178
214
|
const raws = { ...retired };
|
|
179
215
|
const hashRaws = { ...retired };
|
|
180
216
|
const domainErrors = [];
|
|
181
|
-
await Promise.all(
|
|
217
|
+
await Promise.all(LOCAL_READ_DOMAINS.map(async (d) => {
|
|
182
218
|
// 与严读同一只文件读法(读数):被拒的读数交 `thrown`(gate 域原样抛)或 `error` 句(其余域单列进 domainErrors)—— 坏文件的指纹就是这一次读到的字节,不是事后的第二次读。
|
|
183
219
|
const reading = await readConfigDFileReading(this.root, d);
|
|
184
220
|
if (reading.status !== "refused") {
|
|
@@ -198,46 +234,23 @@ export class FileConfigStore {
|
|
|
198
234
|
return { effective, domainErrors };
|
|
199
235
|
}
|
|
200
236
|
/** Stable version number for the current files: same files ⇒ same number ⇒ a consumer's "skip re-apply if
|
|
201
|
-
* version unchanged" works locally too.
|
|
237
|
+
* version unchanged" works locally too. It is the number `read()` carries for the same tree (one snapshot reading, {@link #snapshot}) ——
|
|
238
|
+
* answered for every tree, including one with a document refused at the file layer (29.0.0; it threw before): that document joins as its
|
|
239
|
+
* fingerprint sentinel, never as absence. Shape (schema) does not enter the version: a gated domain that reads but fails its schema has a
|
|
240
|
+
* version here while `read()` / `getEffective()` throw for it. */
|
|
202
241
|
async getVersion() {
|
|
203
|
-
return this.#versionOf(await this.#
|
|
242
|
+
return this.#versionOf((await this.#snapshot()).raws);
|
|
204
243
|
}
|
|
205
244
|
/**
|
|
206
|
-
* **单读口**(16.0.0):一次读整棵 `config.d`(
|
|
245
|
+
* **单读口**(16.0.0):一次读整棵 `config.d`(全部本地读取域 + retired 域的墓碑文档,每份只读一次),交一个结局({@link FileConfigRead})——
|
|
207
246
|
* · 每份文档在文件层都读得进 ⇒ `effective`:与严读 `getEffective()` 逐位同;读侧告警交成数据(没人读的文件 + 装配告警,不经 `onWarning`);
|
|
208
247
|
* · 有文档在文件层被拒(空 / 坏 JSON / 不是对象 / 读不出 / 过深;带事实的 retired 域文档是墓碑拒,带迁移编号)⇒ `refused`:整棵目录的拒单与这一次读到的内容版本。
|
|
209
248
|
* 严读与 `readBundle` 读的是同一只文件读法(`./config-d-file` 的读数)—— 同一种坏形同一个词、同一句话;区别只在渲染:严读遇到第一份坏文档就抛,本方法把整个目录读完、逐份交出。
|
|
210
|
-
* 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 ——
|
|
249
|
+
* 文件层之外的拒(读得出、过不了门控域的 schema)照严读抛 —— 那是判形,不在拒单里;判形不进版本,那棵树的版本 `getVersion()` 照答。拒单、版本、effective、告警都出自这一次读到的字节:没有「先抛、再重探」的第二次读。
|
|
250
|
+
* 版本与 `getVersion()` 是同一个数(同一只快照读法 {@link #snapshot})。
|
|
211
251
|
*/
|
|
212
252
|
async read() {
|
|
213
|
-
const
|
|
214
|
-
const [readings, unread] = await Promise.all([Promise.all(documents.map((d) => readConfigDFileReading(this.root, d))), this.#unreadFiles()]);
|
|
215
|
-
const raws = {};
|
|
216
|
-
const refusals = [];
|
|
217
|
-
documents.forEach((document, i) => {
|
|
218
|
-
const reading = readings[i];
|
|
219
|
-
switch (reading.status) {
|
|
220
|
-
case "absent":
|
|
221
|
-
raws[document] = undefined;
|
|
222
|
-
return;
|
|
223
|
-
case "refused":
|
|
224
|
-
raws[document] = corruptDocumentRaw(reading);
|
|
225
|
-
refusals.push({ document, reason: reading.reason, error: reading.error });
|
|
226
|
-
return;
|
|
227
|
-
case "present":
|
|
228
|
-
raws[document] = reading.value;
|
|
229
|
-
if (isRetiredDomainName(document)) {
|
|
230
|
-
const tombstone = tombstoneOf(document, reading.value);
|
|
231
|
-
if (tombstone !== undefined)
|
|
232
|
-
refusals.push(tombstone);
|
|
233
|
-
}
|
|
234
|
-
return;
|
|
235
|
-
default: {
|
|
236
|
-
const unhandled = reading;
|
|
237
|
-
throw new Error(`FileConfigStore.read: unhandled reading ${String(unhandled)}`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
253
|
+
const [{ raws, refusals }, unread] = await Promise.all([this.#snapshot(), this.#unreadFiles()]);
|
|
241
254
|
const version = this.#versionOf(raws);
|
|
242
255
|
if (refusals.length > 0)
|
|
243
256
|
return { kind: "refused", refusals, version, warnings: unread };
|
package/dist/hooks.d.ts
CHANGED
|
@@ -2193,14 +2193,23 @@ export type HookMatcherForm = "literal" | "regex" | "invalid";
|
|
|
2193
2193
|
* For a caller that must route matchers before evaluating them (run the literal ones inline, give the regex ones a deadline).
|
|
2194
2194
|
*/
|
|
2195
2195
|
export declare function hookMatcherForm(matcher: string | undefined): HookMatcherForm;
|
|
2196
|
-
/**
|
|
2196
|
+
/**
|
|
2197
|
+
* Why {@link interpolateHookEnvVars} expanded a reference to the empty string instead of a value (closed set; table order = the order the reading judges in):
|
|
2198
|
+
* · `"not-allowed"` —— the name is not in the hook's `allowedEnvVars` (its env value is not read);
|
|
2199
|
+
* · `"credential"` —— the name is a credential variable, which no list releases;
|
|
2200
|
+
* · `"unset"` —— the name is released, but `env` has no value for it (the entry is absent or `undefined`). An env value that is the empty string is a value: it expands to empty and is not listed.
|
|
2201
|
+
* A consumer that switches over the reason exhaustively gets a compile error when a word is added.
|
|
2202
|
+
*/
|
|
2203
|
+
export declare const HOOK_ENV_BLANK_REASONS: readonly ["not-allowed", "credential", "unset"];
|
|
2204
|
+
export type HookEnvBlankReason = (typeof HOOK_ENV_BLANK_REASONS)[number];
|
|
2205
|
+
/** One reference in a header value that {@link interpolateHookEnvVars} expanded to the empty string for want of a released value —— what the caller records. */
|
|
2197
2206
|
export interface HookEnvBlank {
|
|
2198
2207
|
/** The header (its name, as keyed in the input) whose value held the reference. */
|
|
2199
2208
|
readonly header: string;
|
|
2200
2209
|
/** The variable name as written in the reference. The value is never part of this record. */
|
|
2201
2210
|
readonly name: string;
|
|
2202
|
-
/**
|
|
2203
|
-
readonly reason:
|
|
2211
|
+
/** Why the reference expanded to the empty string ({@link HOOK_ENV_BLANK_REASONS}). */
|
|
2212
|
+
readonly reason: HookEnvBlankReason;
|
|
2204
2213
|
}
|
|
2205
2214
|
/** What {@link interpolateHookEnvVars} returns: the headers as they go on the wire + the references it blanked. */
|
|
2206
2215
|
export interface HookEnvInterpolation {
|
|
@@ -2214,12 +2223,13 @@ export interface HookEnvInterpolation {
|
|
|
2214
2223
|
*
|
|
2215
2224
|
* · only header **values** are read (header names are never touched);
|
|
2216
2225
|
* · a reference is `$NAME` or `${NAME}` with NAME = `[A-Z_][A-Z0-9_]*`; anything else (lower case, a digit first, `${}`, an unclosed `${`) is plain text;
|
|
2217
|
-
* · a name in `allowedEnvVars` ⇒ the env value
|
|
2226
|
+
* · a name in `allowedEnvVars` ⇒ the env value; `""` when `env` has none, listed in `blanked` (`reason: "unset"`) —— an env value that is `""` is a value, expanded and not listed;
|
|
2218
2227
|
* · a name **not** in `allowedEnvVars` ⇒ `""`, listed in `blanked` (`reason: "not-allowed"`); its env value is not read;
|
|
2219
2228
|
* · a credential variable ({@link HOOK_ENV_CREDENTIAL_NAMES}'s closed set) ⇒ `""` even when the list names it, listed in `blanked` (`reason: "credential"`);
|
|
2220
2229
|
* · CR / LF / NUL are removed from every resulting header value, references or not.
|
|
2230
|
+
* So `blanked` lists every reference that expanded to `""` for want of a released value, each with its reason; the header bytes do not depend on it.
|
|
2221
2231
|
*
|
|
2222
|
-
* The caller decides what to do with `blanked` (a debug line
|
|
2232
|
+
* The caller decides what to do with `blanked` (CC writes a debug line for a not-allowed or credential reference); the headers are final either way.
|
|
2223
2233
|
* Pure: no I/O, no logging, no global env —— `env` is the caller's view (`process.env` at the call site). Inputs are not modified.
|
|
2224
2234
|
*/
|
|
2225
2235
|
export declare function interpolateHookEnvVars(headers: Readonly<Record<string, string>>, allowedEnvVars: readonly string[], env: Readonly<Record<string, string | undefined>>): HookEnvInterpolation;
|
package/dist/hooks.js
CHANGED
|
@@ -742,6 +742,15 @@ export function hookMatcherForm(matcher) {
|
|
|
742
742
|
}
|
|
743
743
|
}
|
|
744
744
|
}
|
|
745
|
+
// ── http hook header env interpolation ───────────────────────────────────────────────────────────
|
|
746
|
+
/**
|
|
747
|
+
* Why {@link interpolateHookEnvVars} expanded a reference to the empty string instead of a value (closed set; table order = the order the reading judges in):
|
|
748
|
+
* · `"not-allowed"` —— the name is not in the hook's `allowedEnvVars` (its env value is not read);
|
|
749
|
+
* · `"credential"` —— the name is a credential variable, which no list releases;
|
|
750
|
+
* · `"unset"` —— the name is released, but `env` has no value for it (the entry is absent or `undefined`). An env value that is the empty string is a value: it expands to empty and is not listed.
|
|
751
|
+
* A consumer that switches over the reason exhaustively gets a compile error when a word is added.
|
|
752
|
+
*/
|
|
753
|
+
export const HOOK_ENV_BLANK_REASONS = deepFreeze(["not-allowed", "credential", "unset"]);
|
|
745
754
|
/** `${NAME}` or `$NAME`, NAME = `[A-Z_][A-Z0-9_]*` —— upper-case names only (lower-case and digit-led spellings are not references). */
|
|
746
755
|
const HOOK_ENV_REFERENCE = /\$\{([A-Z_][A-Z0-9_]*)\}|\$([A-Z_][A-Z0-9_]*)/g;
|
|
747
756
|
/** CR, LF and NUL never reach a header value (header injection through an env value or a configured template). */
|
|
@@ -790,12 +799,13 @@ const HOOK_ENV_CREDENTIAL_NAMES = new Set([
|
|
|
790
799
|
*
|
|
791
800
|
* · only header **values** are read (header names are never touched);
|
|
792
801
|
* · a reference is `$NAME` or `${NAME}` with NAME = `[A-Z_][A-Z0-9_]*`; anything else (lower case, a digit first, `${}`, an unclosed `${`) is plain text;
|
|
793
|
-
* · a name in `allowedEnvVars` ⇒ the env value
|
|
802
|
+
* · a name in `allowedEnvVars` ⇒ the env value; `""` when `env` has none, listed in `blanked` (`reason: "unset"`) —— an env value that is `""` is a value, expanded and not listed;
|
|
794
803
|
* · a name **not** in `allowedEnvVars` ⇒ `""`, listed in `blanked` (`reason: "not-allowed"`); its env value is not read;
|
|
795
804
|
* · a credential variable ({@link HOOK_ENV_CREDENTIAL_NAMES}'s closed set) ⇒ `""` even when the list names it, listed in `blanked` (`reason: "credential"`);
|
|
796
805
|
* · CR / LF / NUL are removed from every resulting header value, references or not.
|
|
806
|
+
* So `blanked` lists every reference that expanded to `""` for want of a released value, each with its reason; the header bytes do not depend on it.
|
|
797
807
|
*
|
|
798
|
-
* The caller decides what to do with `blanked` (a debug line
|
|
808
|
+
* The caller decides what to do with `blanked` (CC writes a debug line for a not-allowed or credential reference); the headers are final either way.
|
|
799
809
|
* Pure: no I/O, no logging, no global env —— `env` is the caller's view (`process.env` at the call site). Inputs are not modified.
|
|
800
810
|
*/
|
|
801
811
|
export function interpolateHookEnvVars(headers, allowedEnvVars, env) {
|
|
@@ -816,7 +826,7 @@ export function interpolateHookEnvVars(headers, allowedEnvVars, env) {
|
|
|
816
826
|
return blank(name, "not-allowed");
|
|
817
827
|
if (HOOK_ENV_CREDENTIAL_NAMES.has(name))
|
|
818
828
|
return blank(name, "credential");
|
|
819
|
-
return env[name] ?? "";
|
|
829
|
+
return env[name] ?? blank(name, "unset");
|
|
820
830
|
});
|
|
821
831
|
return [header, expanded.replace(HOOK_HEADER_FORBIDDEN, "")];
|
|
822
832
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export * from "./api/scopes.js";
|
|
|
35
35
|
export * from "./api/pull-token.js";
|
|
36
36
|
export * from "./api/feedback.js";
|
|
37
37
|
export * from "./api/credentials.js";
|
|
38
|
+
export * from "./api/lifecycle-events.js";
|
|
38
39
|
export * from "./sandbox-git.js";
|
|
39
40
|
export * from "./web-admin-env.js";
|
|
40
41
|
export * from "./web-admin-credential.js";
|
|
@@ -47,5 +48,8 @@ export * from "./mcp-server-policy.js";
|
|
|
47
48
|
export * from "./ui-language.js";
|
|
48
49
|
export * from "./control-and-bidi.js";
|
|
49
50
|
export * from "./mcp-request-entry.js";
|
|
51
|
+
export * from "./connector-id.js";
|
|
52
|
+
export * from "./mcp-entry-credential.js";
|
|
53
|
+
export * from "./connector-authorize-url.js";
|
|
50
54
|
export { REMOTE_MCP_SERVER_NAME_PREFIX } from "./mcp-server-name.js";
|
|
51
55
|
export * from "./center-refs.js";
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export * from "./api/scopes.js"; // multi-tenant scope contract: /api/v1/scopes*
|
|
|
35
35
|
export * from "./api/pull-token.js"; // scope-bound token FORM + minting rule (one rule, token families are data: WORKER_PULL_TOKEN) + claimed-binding reader + verifier (re-mint + constant-time compare), pure-JS HMAC-SHA256, browser-safe
|
|
36
36
|
export * from "./api/feedback.js"; // /bug report wire contract: FeedbackSubmitRequest (POST body) + FeedbackWire / FeedbackListResponse + the two caps, pure/browser-safe
|
|
37
37
|
export * from "./api/credentials.js"; // 14.7.0: the credential port's `sandbox_git` wire (barrel only, no subpath): SandboxGitCredentialRequest / CredentialHandleAnswer / CredentialResolveRequest / SandboxGitCredentialAnswer (per-origin SandboxGitOriginAnswer) / SandboxGitCredentialRefusal + the three word tables (SANDBOX_GIT_ORIGIN_VERDICTS → _STATES / _REASONS, SANDBOX_GIT_REFUSALS → _ERRORS, SANDBOX_GIT_PERMANENCE), pure/browser-safe
|
|
38
|
+
export * from "./api/lifecycle-events.js"; // 29.0.0: the user-lifecycle-event wire (barrel only, no subpath): PRINCIPAL_LIFECYCLE_EVENT_KINDS (five words) + PrincipalLifecycleEvent (unknown keys stripped, discriminated by `kind`; the two `membership.*` arms carry `scope`) + PrincipalLifecycleEventPage { events, head, next } + LIFECYCLE_PAGE_REFUSALS (four words → status; 410 bodies carry `head`) / LifecyclePageRefusal + the reconcile pair PrincipalReconcileRequest (1–PRINCIPAL_RECONCILE_MAX_ITEMS) / PrincipalReconcileAnswer (PrincipalStanding, discriminated by `standing`), pure/browser-safe
|
|
38
39
|
export * from "./sandbox-git.js"; // 14.7.0: the sandbox git plane's origin form (isSandboxGitOrigin — a string equal to its own WHATWG origin) + the `sandboxGit` effective-config block (SandboxGitConfig: origins ≤ 16, each { origin, connectUrl }), pure/browser-safe
|
|
39
40
|
export * from "./web-admin-env.js"; // WEB_ADMIN_ENV — every env name an engine reads to reach web-admin (one table; a leaf module), pure/browser-safe
|
|
40
41
|
export * from "./web-admin-credential.js"; // S-698 web-admin credential FILE contract: WebAdminCredentialEnvelope (user-session envelope, strict) + parseWebAdminCredentialFile (bare / envelope / unreadable — the one discrimination law) + judgeWebAdminCredentialDeclaration(env, credential) (pick-exactly-one over the credential's WEB_ADMIN_ENV pair; WEB_ADMIN_CREDENTIALS = access | assertion), pure/browser-safe
|
|
@@ -46,7 +47,10 @@ export * from "./http-hook-allowlists.js"; // 13.0.0 (U3): allowedHttpHookUrls /
|
|
|
46
47
|
export * from "./mcp-server-policy.js"; // 13.0.0 (U6): mcpServerPolicyVerdict → McpPolicyBlock{name, list, rule, target, written, sources} (structure, no sentence; target judged expanded, echoed only as written), pure/browser-safe
|
|
47
48
|
export * from "./ui-language.js"; // 13.0.0 (S-1592): the UI-language settings fragment (semaUiLanguage, en | zh, category ui, user settings) + readUiLanguage, pure/browser-safe
|
|
48
49
|
export * from "./control-and-bidi.js"; // the one-line echo strip set (C0 + DEL + the 12 Bidi_Control code points) — CONTROL_AND_BIDI_CHARS (the class, as regex source text) + stripControlAndBidi / hasControlOrBidi, pure/browser-safe
|
|
49
|
-
export * from "./mcp-request-entry.js"; // 14.0.0: the request-plane MCP entry judges (isUsableWireName / isContentOriginWord /
|
|
50
|
+
export * from "./mcp-request-entry.js"; // 14.0.0: the request-plane MCP entry judges (isUsableWireName / isContentOriginWord / readRequestMcpTransport + the value-shape describers; 29.0.0: the request keys it refuses by name, MCP_REQUEST_KEY_REFUSALS) — one reading for the service legs and the shell pre-check, pure/browser-safe
|
|
51
|
+
export * from "./connector-id.js"; // 29.0.0: the connector id (ConnectorId / isConnectorId / CONNECTOR_ID_MAX / CONNECTOR_ID_RULE — a DNS label, compared by bytes), pure/browser-safe
|
|
52
|
+
export * from "./mcp-entry-credential.js"; // 29.0.0: the MCP http entry's credential reference (McpEntryCredential / MCP_ENTRY_CREDENTIAL_KINDS — read once by the engine primitives' readCredentialRef), pure/browser-safe
|
|
53
|
+
export * from "./connector-authorize-url.js"; // 29.0.0: the hosted connector authorization address (connectorAuthorizeUrlOf / connectorAuthorizeUrlFlaws / CONNECTOR_AUTHORIZE_QUERY / CONNECTOR_AUTHORIZE_URL_FLAWS — one route form, the assembler and its judge in one module), pure/browser-safe
|
|
50
54
|
export { REMOTE_MCP_SERVER_NAME_PREFIX } from "./mcp-server-name.js"; // the MCP server-name prefix reserved for the remote MCP servers a device executor offers (mount name = prefix + the executor's server name); the predicate and its sentence stay package-private — the request plane's MCP name judges (isUsableMcpServerName / describeBadMcpServerName) read them; the config plane's McpServerSpec.name accepts the prefix (refusing it would be a validation tightening — a major), pure/browser-safe
|
|
51
55
|
export * from "./center-refs.js"; // resolveCenterRefs(refs, lookup) — THE center-roster reference resolver: one verdict word per member (missing_name / not_a_string / read_threw, CENTER_REF_FAULTS), one whole verdict (resolved / unresolved / refs_unreadable, CENTER_REFS_VERDICTS); the refs record is read by the public readPlainStringRecord, the lookup is the caller's, it reads no process.env; pure/browser-safe
|
|
52
56
|
// NOTE: the Node-fs-backed helpers (FileConfigStore + the file editor) are NOT in this barrel — they pull
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置面 MCP http 条目的凭据引用 `transport.credentials`(29.0.0)—— 纯函数、零 I/O、浏览器安全。
|
|
3
|
+
*
|
|
4
|
+
* ## 律(一条)
|
|
5
|
+
* **一条托管连接器条目「它是什么形」只有一个事实:`transport.credentials`。** 引用的合法性只有一只判官 —— 引擎原语包的 `readCredentialRef`
|
|
6
|
+
* (本包不自带第二份读法:读一次,沿用它交回的冻结副本);本包在它之上只加两格自己的事实:准入的种类(闭集 {@link MCP_ENTRY_CREDENTIAL_KINDS},
|
|
7
|
+
* 今天只有 `assertion`)与 `audience` 的取值域(连接器 id,`./connector-id`)。断言的头名归引擎(`MCP_ASSERTION_HEADER`),条目不说它。
|
|
8
|
+
*
|
|
9
|
+
* ## `audience` 的义
|
|
10
|
+
* 条目引用里的 `audience` 就是连接器 id,原样作断言的受众:铸断言的一方把它原样写进断言,托管连接器以同一个 id 启动(它做严格的串比较),
|
|
11
|
+
* 两边对的是同一个只有一种拼法的值。发往哪里归 `url`(必填,不变)。
|
|
12
|
+
*
|
|
13
|
+
* ## 拒句
|
|
14
|
+
* 按问题说形,不回显值:引用里的串(audience、成员名、种类词)都是调用方写的;句子只点名本包与原语包自己的词(种类闭集里的词、成员名表里的名)。
|
|
15
|
+
*/
|
|
16
|
+
import { type CredentialRef } from "@sema-agent/primitives";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
/** 配置面 MCP http 条目准入的凭据引用种类(闭集;原语包种类表的子集)。 */
|
|
19
|
+
export declare const MCP_ENTRY_CREDENTIAL_KINDS: readonly ["assertion"];
|
|
20
|
+
export type McpEntryCredentialKind = (typeof MCP_ENTRY_CREDENTIAL_KINDS)[number];
|
|
21
|
+
/** 一只准入的凭据引用 = 原语包引用里种类在 {@link MCP_ENTRY_CREDENTIAL_KINDS} 内的那几臂。 */
|
|
22
|
+
export type McpEntryCredential = Extract<CredentialRef, {
|
|
23
|
+
kind: McpEntryCredentialKind;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* `transport.credentials` 的 zod 形:输入与产物都是 {@link McpEntryCredential};判法就是 {@link readMcpEntryCredential}(原语包读一次 + 准入种类 + 连接器 id),
|
|
27
|
+
* 产物是原语包交回的冻结副本(不是调用方的对象)。
|
|
28
|
+
*/
|
|
29
|
+
export declare const McpEntryCredential: z.ZodPipe<z.ZodType<{
|
|
30
|
+
readonly kind: "assertion";
|
|
31
|
+
readonly audience: string;
|
|
32
|
+
}, {
|
|
33
|
+
readonly kind: "assertion";
|
|
34
|
+
readonly audience: string;
|
|
35
|
+
}, z.core.$ZodTypeInternals<{
|
|
36
|
+
readonly kind: "assertion";
|
|
37
|
+
readonly audience: string;
|
|
38
|
+
}, {
|
|
39
|
+
readonly kind: "assertion";
|
|
40
|
+
readonly audience: string;
|
|
41
|
+
}>>, z.ZodTransform<{
|
|
42
|
+
readonly kind: "assertion";
|
|
43
|
+
readonly audience: string;
|
|
44
|
+
}, {
|
|
45
|
+
readonly kind: "assertion";
|
|
46
|
+
readonly audience: string;
|
|
47
|
+
}>>;
|