@sema-agent/settings-schema 27.2.0 → 29.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 +753 -0
- package/README.md +88 -12
- package/conformance/VERSION +1 -1
- package/conformance/cases/c01-entry-salvage-then-typo/expected.json +1 -1
- 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 +1 -1
- package/conformance/cases/c58-s784-g2-multitenant-host/expected.json +1 -1
- package/conformance/cases/c59-s784-g3-k8s-missing-image/expected.json +1 -1
- package/conformance/cases/c60-s784-g3-e2b-missing-key/expected.json +1 -1
- package/conformance/cases/c61-s784-g3-other-lane-key/expected.json +1 -1
- package/conformance/cases/c62-s784-g7a-session-tidb/expected.json +1 -1
- package/conformance/cases/c63-s784-host-two-replicas/expected.json +1 -1
- package/conformance/cases/c64-s784-multitenant-local-store/expected.json +1 -1
- package/conformance/cases/c65-s784-pg-without-db/expected.json +1 -1
- package/conformance/cases/c66-s784-memory-backend-mismatch/expected.json +1 -1
- package/conformance/cases/c67-s784-retired-field-loud/expected.json +1 -1
- package/conformance/cases/c68-s784-device-local-store/expected.json +1 -1
- 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 +1 -1
- package/conformance/cases/c77-prompts-center-artifact-carried/expected.json +1 -1
- package/conformance/cases/c78-prompts-empty-bindings-refused/expected.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 +1 -1
- package/conformance/cases/c82-prompts-v1-catalog-refused/expected.json +1 -1
- 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/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/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/z01-every-domain-empty-object/expected.json +1 -1
- package/conformance/cases/z02-every-domain-unknown-key/expected.json +1 -1
- package/dist/api/auth-bridge.js +4 -3
- package/dist/api/auth.js +6 -5
- package/dist/api/credentials.js +14 -15
- package/dist/api/lifecycle-events.d.ts +266 -0
- package/dist/api/lifecycle-events.js +169 -0
- package/dist/api/pull-token.js +2 -1
- package/dist/api/scopes.js +5 -4
- 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/center-refs.js +3 -2
- package/dist/config-d-file.d.ts +1 -1
- package/dist/config-dir-io.d.ts +1 -1
- package/dist/config-dir-io.js +3 -2
- package/dist/config-document-refusal.d.ts +5 -5
- package/dist/config-document-refusal.js +2 -1
- package/dist/config-fns.d.ts +5 -5
- package/dist/config-fns.js +17 -16
- package/dist/config-root-documents.d.ts +1 -1
- package/dist/config-root-documents.js +4 -3
- package/dist/config-root-node.d.ts +1 -1
- package/dist/config-root-node.js +5 -3
- package/dist/conformance/corpus.d.ts +1 -1
- package/dist/conformance/derive.d.ts +16 -8
- package/dist/conformance/derive.js +41 -24
- package/dist/conformance/index.d.ts +1 -1
- package/dist/conformance/index.js +1 -1
- package/dist/conformance/run.js +8 -9
- package/dist/conformance/types.js +4 -3
- 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/cross-domain.js +6 -5
- package/dist/cross-session.js +3 -2
- package/dist/deep-freeze.d.ts +26 -0
- package/dist/deep-freeze.js +69 -0
- package/dist/default-model.js +2 -1
- package/dist/device-relay.d.ts +1 -1
- package/dist/device-relay.js +1 -1
- package/dist/env-model-table.js +2 -1
- package/dist/execution-lane-index.d.ts +1 -1
- package/dist/execution-lane-index.js +5 -4
- package/dist/execution-lanes.d.ts +2 -2
- package/dist/execution-lanes.js +18 -17
- 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/fleet.js +14 -13
- package/dist/hooks-config.d.ts +12 -12
- package/dist/hooks-config.js +16 -15
- package/dist/hooks.d.ts +20 -10
- package/dist/hooks.js +30 -19
- package/dist/http-hook-allowlists.js +2 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -2
- 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 +106 -59
- package/dist/mcp-server-policy.js +3 -2
- package/dist/migration-receipt.d.ts +3 -3
- package/dist/migration-receipt.js +4 -3
- package/dist/one-time-migrations.d.ts +2 -2
- package/dist/one-time-migrations.js +75 -57
- package/dist/own-key-read.d.ts +3 -1
- package/dist/plain-json-object.d.ts +6 -3
- package/dist/plain-json-object.js +6 -3
- package/dist/portable-domains.d.ts +18 -12
- package/dist/portable-domains.js +21 -15
- package/dist/reserved-member-name.d.ts +1 -1
- package/dist/reserved-member-name.js +3 -2
- package/dist/resolve-roster.js +3 -2
- package/dist/retired-envs.js +3 -6
- package/dist/retired-role-words.d.ts +1 -1
- package/dist/retired-role-words.js +4 -6
- package/dist/safety-merge-spec.d.ts +11 -4
- package/dist/safety-merge-spec.js +5 -4
- package/dist/scheduler-store-node.d.ts +5 -2
- package/dist/scheduler-store-node.js +8 -5
- package/dist/secret-scan.js +1 -1
- package/dist/settings-sources.js +6 -5
- package/dist/settings-units.js +3 -2
- 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 +89 -19
- package/dist/types.js +57 -65
- package/dist/ui-language.js +4 -3
- package/dist/url-credential.js +4 -3
- package/dist/url-shape.d.ts +1 -1
- package/dist/url-shape.js +5 -4
- package/dist/web-admin-credential.js +2 -1
- package/dist/web-admin-env.d.ts +1 -1
- package/dist/web-admin-env.js +4 -3
- package/docs/API-SURFACE.md +47 -7
- package/docs/CONFORMANCE.md +6 -4
- package/docs/CONSUMER-INTEGRATION.md +131 -6
- package/llms-full.txt +46 -24
- package/llms.txt +27 -13
- package/package.json +3 -2
package/dist/hooks-config.js
CHANGED
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
import { z } from "zod";
|
|
52
52
|
import { isPlainJsonObject } from "./plain-json-object.js";
|
|
53
53
|
import { buildQuotedIssue, fixed } from "./quoted-issue.js";
|
|
54
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
54
55
|
// ── event vocabulary ───────────────────────────────────────────────────────────────────────────────────────
|
|
55
56
|
// The two halves below are where each word came from (CC 2.1.198's own table, then the later additions) — provenance for the
|
|
56
57
|
// reader of this file, not a contract: they are module-private, and the ONE exported closed set is {@link HOOK_EVENTS}.
|
|
@@ -97,7 +98,7 @@ const CC_198_HOOK_EVENTS = [
|
|
|
97
98
|
*/
|
|
98
99
|
const POST_198_HOOK_EVENTS = ["CwdChanged", "FileChanged", "MessageDisplay", "DirectoryAdded", "PreModelSwitch", "PostModelSwitch"];
|
|
99
100
|
/** The full 33-event contract set = CC 198's 27 + the 6 post-198 events — the one exported closed set of hook event names. */
|
|
100
|
-
export const HOOK_EVENTS = [...CC_198_HOOK_EVENTS, ...POST_198_HOOK_EVENTS];
|
|
101
|
+
export const HOOK_EVENTS = deepFreeze([...CC_198_HOOK_EVENTS, ...POST_198_HOOK_EVENTS]);
|
|
101
102
|
/** The guard events (CC 2.1.296 `SV`): their hooks may guard the permissions declared beside them — see the file header. */
|
|
102
103
|
const HOOK_GUARD_EVENTS = ["PreToolUse", "PermissionRequest"];
|
|
103
104
|
// ── entry vocabulary and the one field table ───────────────────────────────────────────────────────────────
|
|
@@ -107,7 +108,7 @@ const HOOK_GUARD_EVENTS = ["PreToolUse", "PermissionRequest"];
|
|
|
107
108
|
* `mcp_tool` (call a tool on an already-configured MCP server). An entry of another type is a bad piece — and in a guard event that rejects
|
|
108
109
|
* the whole document, which is why `test/upstream-drift.test.ts` ①b holds this set against the CC anchor snapshot.
|
|
109
110
|
*/
|
|
110
|
-
export const HOOK_ENTRY_TYPES = ["command", "prompt", "agent", "http", "mcp_tool"];
|
|
111
|
+
export const HOOK_ENTRY_TYPES = deepFreeze(["command", "prompt", "agent", "http", "mcp_tool"]);
|
|
111
112
|
/**
|
|
112
113
|
* The `onFailure` closed set (CC `cli309.js:252382`, `onFailure:At()`): what a FAILURE of the hook does — it could not start (a missing script), timed out, exited with a code other
|
|
113
114
|
* than 0 or 2, or printed JSON that is invalid or fails validation. `continue` (CC's default when the key is absent; this package does not fill it in — an absent key stays absent): the
|
|
@@ -115,7 +116,7 @@ export const HOOK_ENTRY_TYPES = ["command", "prompt", "agent", "http", "mcp_tool
|
|
|
115
116
|
* CARRIED, not executed here: a consumer that reads `block` executes it or refuses it — ignoring it makes a guard that cannot start let the action through.
|
|
116
117
|
* The classifier reads this set through a closure-private projection that the compiler ties to it in both directions.
|
|
117
118
|
*/
|
|
118
|
-
export const HOOK_ON_FAILURE_WORDS = ["continue", "block"];
|
|
119
|
+
export const HOOK_ON_FAILURE_WORDS = deepFreeze(["continue", "block"]);
|
|
119
120
|
/**
|
|
120
121
|
* The words CC gives `cloud` (CC `cli309.js:252382`, `cloud:B(["device","skip"]).optional().catch("skip")`, marked `@internal` there): where this hook may run when a cloud session is driven from the
|
|
121
122
|
* machine that holds the settings. `device`: offer it to the cloud session and run it on the device even when its script sits where the cloud session can write; `skip`: never offer it to cloud
|
|
@@ -124,7 +125,7 @@ export const HOOK_ON_FAILURE_WORDS = ["continue", "block"];
|
|
|
124
125
|
* value — {@link classifyHooksConfig} carries whatever is written, as written (it neither judges it, nor folds it to `skip`, nor strips it), and folding to `skip` is the reader's. Carried by `command` and
|
|
125
126
|
* `http` entries. CARRIED, not executed here.
|
|
126
127
|
*/
|
|
127
|
-
export const HOOK_CLOUD_WORDS = ["device", "skip"];
|
|
128
|
+
export const HOOK_CLOUD_WORDS = deepFreeze(["device", "skip"]);
|
|
128
129
|
/** `shell` values: 'bash' = the user's $SHELL family; 'powershell' = pwsh. Default bash. */
|
|
129
130
|
const HOOK_SHELLS = ["bash", "powershell"];
|
|
130
131
|
/** The classifier's reading of {@link HOOK_ON_FAILURE_WORDS}. The classifier is copied as source by consumers' generators, so its closure cannot read an exported name (its one free name
|
|
@@ -159,8 +160,8 @@ const HOOK_ENTRY_COMMON_FIELDS = { if: "string?", timeout: "seconds?", statusMes
|
|
|
159
160
|
* The row order also decides which field an already-bad entry names (the first wrong one), so a column added later goes at the TAIL of its row (after the shared fields): adding one never
|
|
160
161
|
* moves an answer the table already gave.
|
|
161
162
|
*/
|
|
162
|
-
export const HOOK_ENTRY_FIELDS =
|
|
163
|
-
command:
|
|
163
|
+
export const HOOK_ENTRY_FIELDS = deepFreeze({
|
|
164
|
+
command: {
|
|
164
165
|
command: "text",
|
|
165
166
|
args: "argv?",
|
|
166
167
|
shell: "shell?",
|
|
@@ -171,11 +172,11 @@ export const HOOK_ENTRY_FIELDS = Object.freeze({
|
|
|
171
172
|
rewakeMessage: "nonEmpty?",
|
|
172
173
|
rewakeSummary: "nonEmpty?",
|
|
173
174
|
cloud: "any?",
|
|
174
|
-
}
|
|
175
|
-
prompt:
|
|
176
|
-
agent:
|
|
177
|
-
http:
|
|
178
|
-
mcp_tool:
|
|
175
|
+
},
|
|
176
|
+
prompt: { prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS, continueOnBlock: "boolean?" },
|
|
177
|
+
agent: { prompt: "text", model: "string?", ...HOOK_ENTRY_COMMON_FIELDS },
|
|
178
|
+
http: { url: "text", headers: "stringRecord?", allowedEnvVars: "stringList?", onFailure: "onFailure?", ...HOOK_ENTRY_COMMON_FIELDS, cloud: "any?" },
|
|
179
|
+
mcp_tool: { server: "string", tool: "string", input: "record?", ...HOOK_ENTRY_COMMON_FIELDS },
|
|
179
180
|
});
|
|
180
181
|
/** The classifier's reading of {@link HOOK_ENTRY_FIELDS}. Same reason and same form as {@link HOOK_ON_FAILURE_ACCEPTED}: the classifier closure cannot read the exported table, so this
|
|
181
182
|
* is its closure-private projection, spelled out in full (no shared piece with the exported table) and annotated with the exported table's type — a row, a field or a field kind that
|
|
@@ -204,7 +205,7 @@ const HOOK_ENTRY_FIELDS_READ = {
|
|
|
204
205
|
};
|
|
205
206
|
// ── classification vocabulary ──────────────────────────────────────────────────────────────────────────────
|
|
206
207
|
/** What happened to a document's hooks: all loaded / loaded with pieces dropped / the document rejected (nothing in it applies). */
|
|
207
|
-
export const HOOKS_CLASSIFICATION_OUTCOMES = ["loaded", "loaded-partial", "rejected"];
|
|
208
|
+
export const HOOKS_CLASSIFICATION_OUTCOMES = deepFreeze(["loaded", "loaded-partial", "rejected"]);
|
|
208
209
|
/**
|
|
209
210
|
* Why a piece was DROPPED (closed; one word per level of piece, no `other`):
|
|
210
211
|
* · `hooks-not-object` — `hooks` is null / a scalar / an array holding only scalars ⇒ the whole `hooks` key goes;
|
|
@@ -213,7 +214,7 @@ export const HOOKS_CLASSIFICATION_OUTCOMES = ["loaded", "loaded-partial", "rejec
|
|
|
213
214
|
* · `matcher-invalid` — a matcher that is not an object, whose `matcher` is not a string or whose `hooks` is not an array (non-guard event);
|
|
214
215
|
* · `entry-invalid` — an entry that is not an object, has no / an unknown `type`, or a field outside its kind (non-guard event).
|
|
215
216
|
*/
|
|
216
|
-
export const HOOKS_DROPPED_PIECE_CODES = ["hooks-not-object", "unknown-event", "event-not-array", "matcher-invalid", "entry-invalid"];
|
|
217
|
+
export const HOOKS_DROPPED_PIECE_CODES = deepFreeze(["hooks-not-object", "unknown-event", "event-not-array", "matcher-invalid", "entry-invalid"]);
|
|
217
218
|
/**
|
|
218
219
|
* Why the document was REJECTED (closed; each is "a guard may be in this piece"):
|
|
219
220
|
* · `guard-outside-hooks` — a guard sign outside `hooks` (top level, under another key, or the document itself matcher-shaped), or the document could not be read at all (path `[]`);
|
|
@@ -223,14 +224,14 @@ export const HOOKS_DROPPED_PIECE_CODES = ["hooks-not-object", "unknown-event", "
|
|
|
223
224
|
* · `guard-matcher-invalid` — a bad matcher in a guard event, or a matcher holding a sign (in any event);
|
|
224
225
|
* · `guard-entry-invalid` — a bad entry in a guard event, or an entry holding a sign (in any event).
|
|
225
226
|
*/
|
|
226
|
-
export const HOOKS_REJECTION_CODES = [
|
|
227
|
+
export const HOOKS_REJECTION_CODES = deepFreeze([
|
|
227
228
|
"guard-outside-hooks",
|
|
228
229
|
"hooks-is-matcher",
|
|
229
230
|
"guard-under-unknown-event",
|
|
230
231
|
"guard-event-not-array",
|
|
231
232
|
"guard-matcher-invalid",
|
|
232
233
|
"guard-entry-invalid",
|
|
233
|
-
];
|
|
234
|
+
]);
|
|
234
235
|
/** The value's shape — six words: `plain` is a JSON object (not null, not an array, prototype null or a prototype whose own prototype is null: any realm's `Object.prototype`),
|
|
235
236
|
* `uninspectable` is a value whose shape cannot be read at all (a proxy that has been revoked, a throwing `getPrototypeOf` trap). This function IS `./plain-json-object`'s `jsonShapeOf`, character for
|
|
236
237
|
* character: the classifier is copied as source by consumers' generators, so its closure cannot import — the package has this one second copy, and the test is what keeps it from drifting. */
|
package/dist/hooks.d.ts
CHANGED
|
@@ -268,8 +268,8 @@ export type AssistantTurnError = z.infer<typeof AssistantTurnError>;
|
|
|
268
268
|
/** SessionEnd `reason` values (CC EXIT_REASONS). */
|
|
269
269
|
export declare const SESSION_EXIT_REASONS: readonly ["clear", "resume", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"];
|
|
270
270
|
export declare const SessionExitReason: z.ZodEnum<{
|
|
271
|
-
other: "other";
|
|
272
271
|
clear: "clear";
|
|
272
|
+
other: "other";
|
|
273
273
|
resume: "resume";
|
|
274
274
|
logout: "logout";
|
|
275
275
|
prompt_input_exit: "prompt_input_exit";
|
|
@@ -417,8 +417,8 @@ export declare const SessionEndHookInput: z.ZodObject<{
|
|
|
417
417
|
agent_type: z.ZodOptional<z.ZodString>;
|
|
418
418
|
hook_event_name: z.ZodLiteral<"SessionEnd">;
|
|
419
419
|
reason: z.ZodEnum<{
|
|
420
|
-
other: "other";
|
|
421
420
|
clear: "clear";
|
|
421
|
+
other: "other";
|
|
422
422
|
resume: "resume";
|
|
423
423
|
logout: "logout";
|
|
424
424
|
prompt_input_exit: "prompt_input_exit";
|
|
@@ -800,8 +800,8 @@ export declare const FileChangedHookInput: z.ZodObject<{
|
|
|
800
800
|
hook_event_name: z.ZodLiteral<"FileChanged">;
|
|
801
801
|
file_path: z.ZodString;
|
|
802
802
|
event: z.ZodEnum<{
|
|
803
|
-
change: "change";
|
|
804
803
|
add: "add";
|
|
804
|
+
change: "change";
|
|
805
805
|
unlink: "unlink";
|
|
806
806
|
}>;
|
|
807
807
|
}, z.core.$strip>;
|
|
@@ -1027,8 +1027,8 @@ export declare const HookInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1027
1027
|
agent_type: z.ZodOptional<z.ZodString>;
|
|
1028
1028
|
hook_event_name: z.ZodLiteral<"SessionEnd">;
|
|
1029
1029
|
reason: z.ZodEnum<{
|
|
1030
|
-
other: "other";
|
|
1031
1030
|
clear: "clear";
|
|
1031
|
+
other: "other";
|
|
1032
1032
|
resume: "resume";
|
|
1033
1033
|
logout: "logout";
|
|
1034
1034
|
prompt_input_exit: "prompt_input_exit";
|
|
@@ -1385,8 +1385,8 @@ export declare const HookInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1385
1385
|
hook_event_name: z.ZodLiteral<"FileChanged">;
|
|
1386
1386
|
file_path: z.ZodString;
|
|
1387
1387
|
event: z.ZodEnum<{
|
|
1388
|
-
change: "change";
|
|
1389
1388
|
add: "add";
|
|
1389
|
+
change: "change";
|
|
1390
1390
|
unlink: "unlink";
|
|
1391
1391
|
}>;
|
|
1392
1392
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -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
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
import { z } from "zod";
|
|
43
43
|
import { HOOK_EVENTS } from "./hooks-config.js";
|
|
44
44
|
import { INTEGER } from "./integer.js";
|
|
45
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
45
46
|
export * from "./hooks-config.js";
|
|
46
47
|
// ── event set ──────────────────────────────────────────────────────────────────────────────────────────
|
|
47
48
|
// The ONE closed set of hook event names is {@link HOOK_EVENTS} (`./hooks-config`, re-exported above; drift-gated against CC).
|
|
@@ -63,7 +64,7 @@ export const HookOwner = z.enum(["engine", "shell"]);
|
|
|
63
64
|
* contract than a member's row does not know the member is engine-owned. A consumer that routes by this set must not keep its own
|
|
64
65
|
* table of "which member joined at which version".
|
|
65
66
|
*/
|
|
66
|
-
export const ENGINE_OWNED_HOOK_EVENTS = [
|
|
67
|
+
export const ENGINE_OWNED_HOOK_EVENTS = deepFreeze([
|
|
67
68
|
"PreToolUse",
|
|
68
69
|
"PostToolUse",
|
|
69
70
|
"PostToolUseFailure",
|
|
@@ -74,9 +75,9 @@ export const ENGINE_OWNED_HOOK_EVENTS = [
|
|
|
74
75
|
"StopFailure",
|
|
75
76
|
"UserPromptSubmit",
|
|
76
77
|
"PermissionDenied",
|
|
77
|
-
];
|
|
78
|
+
]);
|
|
78
79
|
/** owner per event — single owner; the non-owner side never fires it (dedup rule). */
|
|
79
|
-
export const HOOK_EVENT_OWNER = Object.fromEntries(HOOK_EVENTS.map((e) => [e, ENGINE_OWNED_HOOK_EVENTS.includes(e) ? "engine" : "shell"]));
|
|
80
|
+
export const HOOK_EVENT_OWNER = deepFreeze(Object.fromEntries(HOOK_EVENTS.map((e) => [e, ENGINE_OWNED_HOOK_EVENTS.includes(e) ? "engine" : "shell"])));
|
|
80
81
|
/**
|
|
81
82
|
* The first version of THIS package whose {@link ENGINE_OWNED_HOOK_EVENTS} carried each member — the contract version from which a peer that
|
|
82
83
|
* embeds this package treats the event as engine-owned (the server reports its embedded version as `settingsContract.version` on
|
|
@@ -91,7 +92,7 @@ export const HOOK_EVENT_OWNER = Object.fromEntries(HOOK_EVENTS.map((e) => [e, EN
|
|
|
91
92
|
*
|
|
92
93
|
* Frozen: every reader in a process shares it. Read it through {@link engineOwnsHookEventAt}; do not compare against it by hand.
|
|
93
94
|
*/
|
|
94
|
-
export const ENGINE_OWNED_HOOK_EVENT_SINCE =
|
|
95
|
+
export const ENGINE_OWNED_HOOK_EVENT_SINCE = deepFreeze({
|
|
95
96
|
PreToolUse: "1.0.0",
|
|
96
97
|
PostToolUse: "1.0.0",
|
|
97
98
|
PostToolUseFailure: "1.0.0",
|
|
@@ -138,7 +139,7 @@ export function engineOwnsHookEventAt(event, contractVersion) {
|
|
|
138
139
|
* ignored for the event; every entry matches). Ported from the shell's getMatchingHooks switch. HOW the matcher is read
|
|
139
140
|
* against that field is {@link hookMatcherSelects} (the one reading).
|
|
140
141
|
*/
|
|
141
|
-
export const HOOK_EVENT_MATCHER_FIELD = {
|
|
142
|
+
export const HOOK_EVENT_MATCHER_FIELD = deepFreeze({
|
|
142
143
|
PreToolUse: "tool_name",
|
|
143
144
|
PostToolUse: "tool_name",
|
|
144
145
|
PostToolUseFailure: "tool_name",
|
|
@@ -174,7 +175,7 @@ export const HOOK_EVENT_MATCHER_FIELD = {
|
|
|
174
175
|
// matcher can scope a hook to "only when switching TO this model".
|
|
175
176
|
PreModelSwitch: "to_model",
|
|
176
177
|
PostModelSwitch: "to_model",
|
|
177
|
-
};
|
|
178
|
+
});
|
|
178
179
|
// ── shared enums (CC-verbatim) ─────────────────────────────────────────────────────────────────────────
|
|
179
180
|
export const PermissionBehavior = z.enum(["allow", "deny", "ask"]);
|
|
180
181
|
export const PermissionMode = z.enum(["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk"]);
|
|
@@ -209,14 +210,14 @@ export const AssistantTurnError = z.enum([
|
|
|
209
210
|
"max_output_tokens",
|
|
210
211
|
]);
|
|
211
212
|
/** SessionEnd `reason` values (CC EXIT_REASONS). */
|
|
212
|
-
export const SESSION_EXIT_REASONS = [
|
|
213
|
+
export const SESSION_EXIT_REASONS = deepFreeze([
|
|
213
214
|
"clear",
|
|
214
215
|
"resume",
|
|
215
216
|
"logout",
|
|
216
217
|
"prompt_input_exit",
|
|
217
218
|
"other",
|
|
218
219
|
"bypass_permissions_disabled",
|
|
219
|
-
];
|
|
220
|
+
]);
|
|
220
221
|
export const SessionExitReason = z.enum(SESSION_EXIT_REASONS);
|
|
221
222
|
// ── per-event input payloads (CC-verbatim field names: hook_event_name / session_id / cwd + extras) ────
|
|
222
223
|
/**
|
|
@@ -388,7 +389,7 @@ export const ElicitationResultHookInput = BaseHookInput.extend({
|
|
|
388
389
|
action: z.enum(["accept", "decline", "cancel"]),
|
|
389
390
|
content: z.record(z.string(), z.unknown()).optional(),
|
|
390
391
|
});
|
|
391
|
-
export const CONFIG_CHANGE_SOURCES = ["user_settings", "project_settings", "local_settings", "policy_settings", "skills"];
|
|
392
|
+
export const CONFIG_CHANGE_SOURCES = deepFreeze(["user_settings", "project_settings", "local_settings", "policy_settings", "skills"]);
|
|
392
393
|
export const ConfigChangeHookInput = BaseHookInput.extend({
|
|
393
394
|
hook_event_name: z.literal("ConfigChange"),
|
|
394
395
|
source: z.enum(CONFIG_CHANGE_SOURCES),
|
|
@@ -402,8 +403,8 @@ export const WorktreeRemoveHookInput = BaseHookInput.extend({
|
|
|
402
403
|
hook_event_name: z.literal("WorktreeRemove"),
|
|
403
404
|
worktree_path: z.string(),
|
|
404
405
|
});
|
|
405
|
-
export const INSTRUCTIONS_LOAD_REASONS = ["session_start", "nested_traversal", "path_glob_match", "include", "compact"];
|
|
406
|
-
export const INSTRUCTIONS_MEMORY_TYPES = ["User", "Project", "Local", "Managed"];
|
|
406
|
+
export const INSTRUCTIONS_LOAD_REASONS = deepFreeze(["session_start", "nested_traversal", "path_glob_match", "include", "compact"]);
|
|
407
|
+
export const INSTRUCTIONS_MEMORY_TYPES = deepFreeze(["User", "Project", "Local", "Managed"]);
|
|
407
408
|
export const InstructionsLoadedHookInput = BaseHookInput.extend({
|
|
408
409
|
hook_event_name: z.literal("InstructionsLoaded"),
|
|
409
410
|
file_path: z.string(),
|
|
@@ -438,7 +439,7 @@ export const MessageDisplayHookInput = BaseHookInput.extend({
|
|
|
438
439
|
delta: z.string(),
|
|
439
440
|
});
|
|
440
441
|
/** How a directory joined the session working set: the `/add-dir` slash command or repo-root registration. */
|
|
441
|
-
export const DIRECTORY_ADDED_SOURCES = ["slash_command", "register_repo_root"];
|
|
442
|
+
export const DIRECTORY_ADDED_SOURCES = deepFreeze(["slash_command", "register_repo_root"]);
|
|
442
443
|
/**
|
|
443
444
|
* Fired after a directory joins the session's working set (CC 2.1.219; agent-types hooks.d.ts:582-586 —
|
|
444
445
|
* `directory` is the absolute path). Shell-owned; matcher ignored; no hookSpecificOutput arm upstream.
|
|
@@ -454,10 +455,10 @@ export const DirectoryAddedHookInput = BaseHookInput.extend({
|
|
|
454
455
|
* set_model), while `PostModelSwitch` also reports changes nobody requested (`auto` = automatic fallback,
|
|
455
456
|
* `resume` = model restored while resuming a session) — those have no "before" to gate.
|
|
456
457
|
*/
|
|
457
|
-
export const MODEL_SWITCH_SOURCES = {
|
|
458
|
+
export const MODEL_SWITCH_SOURCES = deepFreeze({
|
|
458
459
|
pre: ["command", "picker", "sdk"],
|
|
459
460
|
post: ["command", "picker", "sdk", "auto", "resume"],
|
|
460
|
-
};
|
|
461
|
+
});
|
|
461
462
|
/** The fields both model-switch events carry (CC-verbatim): the models, what was asked for, and the
|
|
462
463
|
* cache-forfeit estimate a hook needs to decide whether the switch is worth it. */
|
|
463
464
|
const ModelSwitchFields = {
|
|
@@ -648,12 +649,12 @@ export const HookOutput = z.union([AsyncHookOutput, SyncHookOutput]);
|
|
|
648
649
|
// `prompt` / `agent` / `http` / `mcp_tool` hook types are part of the config contract (`HOOK_ENTRY_TYPES`); a runner
|
|
649
650
|
// may phase them in after `command` — config validity is not phased (`classifyHooksConfig` is the one reading of it).
|
|
650
651
|
/** Env names the hook runner injects into a command hook's environment (CC-parity). */
|
|
651
|
-
export const HOOK_INJECTED_ENV = [
|
|
652
|
+
export const HOOK_INJECTED_ENV = deepFreeze([
|
|
652
653
|
/** Absolute path of the project/workspace root. */
|
|
653
654
|
"CLAUDE_PROJECT_DIR",
|
|
654
655
|
/** SessionStart only: file a hook may append `KEY=value` lines to, persisted into the session env. */
|
|
655
656
|
"CLAUDE_ENV_FILE",
|
|
656
|
-
];
|
|
657
|
+
]);
|
|
657
658
|
/** Default per-hook timeout when an entry does not set one (seconds; CC default). */
|
|
658
659
|
export const DEFAULT_HOOK_TIMEOUT_SECONDS = 60;
|
|
659
660
|
/** The characters a matcher may consist of to be read as a NAME LIST rather than a regex. */
|
|
@@ -741,6 +742,15 @@ export function hookMatcherForm(matcher) {
|
|
|
741
742
|
}
|
|
742
743
|
}
|
|
743
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"]);
|
|
744
754
|
/** `${NAME}` or `$NAME`, NAME = `[A-Z_][A-Z0-9_]*` —— upper-case names only (lower-case and digit-led spellings are not references). */
|
|
745
755
|
const HOOK_ENV_REFERENCE = /\$\{([A-Z_][A-Z0-9_]*)\}|\$([A-Z_][A-Z0-9_]*)/g;
|
|
746
756
|
/** CR, LF and NUL never reach a header value (header injection through an env value or a configured template). */
|
|
@@ -789,12 +799,13 @@ const HOOK_ENV_CREDENTIAL_NAMES = new Set([
|
|
|
789
799
|
*
|
|
790
800
|
* · only header **values** are read (header names are never touched);
|
|
791
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;
|
|
792
|
-
* · 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;
|
|
793
803
|
* · a name **not** in `allowedEnvVars` ⇒ `""`, listed in `blanked` (`reason: "not-allowed"`); its env value is not read;
|
|
794
804
|
* · a credential variable ({@link HOOK_ENV_CREDENTIAL_NAMES}'s closed set) ⇒ `""` even when the list names it, listed in `blanked` (`reason: "credential"`);
|
|
795
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.
|
|
796
807
|
*
|
|
797
|
-
* 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.
|
|
798
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.
|
|
799
810
|
*/
|
|
800
811
|
export function interpolateHookEnvVars(headers, allowedEnvVars, env) {
|
|
@@ -815,7 +826,7 @@ export function interpolateHookEnvVars(headers, allowedEnvVars, env) {
|
|
|
815
826
|
return blank(name, "not-allowed");
|
|
816
827
|
if (HOOK_ENV_CREDENTIAL_NAMES.has(name))
|
|
817
828
|
return blank(name, "credential");
|
|
818
|
-
return env[name] ?? "";
|
|
829
|
+
return env[name] ?? blank(name, "unset");
|
|
819
830
|
});
|
|
820
831
|
return [header, expanded.replace(HOOK_HEADER_FORBIDDEN, "")];
|
|
821
832
|
});
|
|
@@ -19,8 +19,9 @@ import { captureDenseArray, inspect, isStringEntry, readKey } from "./own-key-re
|
|
|
19
19
|
import { isJsonArray, isPlainJsonArray, jsonShapeOf } from "./plain-json-object.js";
|
|
20
20
|
import { layerAdmission } from "./settings-sources.js";
|
|
21
21
|
import { urlAllowPatternMatches } from "./url-pattern.js";
|
|
22
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
22
23
|
/** 两键(闭集,声明序)。 */
|
|
23
|
-
export const HTTP_HOOK_ALLOWLIST_KEYS = ["allowedHttpHookUrls", "httpHookAllowedEnvVars"];
|
|
24
|
+
export const HTTP_HOOK_ALLOWLIST_KEYS = deepFreeze(["allowedHttpHookUrls", "httpHookAllowedEnvVars"]);
|
|
24
25
|
/**
|
|
25
26
|
* 整份 `settings.json` 里本片段负责的两键:在场则必须是字符串数组。刻意 `passthrough`(与 `CrossSessionSettings` 同姿势):本片段不是整份
|
|
26
27
|
* 设置的闭集门。它是**写侧**的形门;读侧坏形不拒整份,按 {@link readHttpHookAllowlistLayer} 读成空名单(fail-closed)。
|
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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* web-admin, the worker service, and the TOC desktop/CLI.
|
|
4
4
|
*/
|
|
5
5
|
export * from "./types.js";
|
|
6
|
-
export * from "./execution-lanes.js"; // 7.0.0 M-R2: the ONE lane / store vocabulary (EXECUTION_LANE_WORDS / EXECUTION_LANES / STORE_BACKENDS / SESSION_BACKENDS / MEMORY_ENGINE_BACKENDS) + THE lane-coordinate blank judge isBlankCoordinate (empty or whitespace-only = absent; the write gate and every consumer ask this one function; whether a key is set, and whether an optional key may be empty, stays the caller's call; the same function object as on the `./execution-lanes` subpath) — a zero-import
|
|
6
|
+
export * from "./execution-lanes.js"; // 7.0.0 M-R2: the ONE lane / store vocabulary (EXECUTION_LANE_WORDS / EXECUTION_LANES / STORE_BACKENDS / SESSION_BACKENDS / MEMORY_ENGINE_BACKENDS) + THE lane-coordinate blank judge isBlankCoordinate (empty or whitespace-only = absent; the write gate and every consumer ask this one function; whether a key is set, and whether an optional key may be empty, stays the caller's call; the same function object as on the `./execution-lanes` subpath) — a leaf whose only import is the package-private zero-import freezer, pure/browser-safe
|
|
7
7
|
export * from "./config-document-refusal.js"; // 15.2.0: the typed refusal of one config.d document (CONFIG_DOCUMENT_REFUSAL_REASONS = empty / invalid_json / not_object / io / retired_domain; ConfigDocumentRefusal { document, reason, error } + the tombstone arm's migration) — the reading is `inspectBundle` in ./node; pure/browser-safe
|
|
8
8
|
export * from "./url-shape.js"; // 11.0.0: THE URL shape judge (httpUrlFlaws / httpUrlRule / isHierarchicalUrl; 16.0.0 + wsUrlFlaws), pure/browser-safe
|
|
9
9
|
export * from "./device-relay.js"; // 16.0.0: THE value grammar of the device lane's DEVICE_RELAY_URL (DEVICE_RELAY_NONE / deviceRelayFlaws / DEVICE_RELAY_RULE), pure/browser-safe
|
|
@@ -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
|
+
}>>;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 { readCredentialRef } from "@sema-agent/primitives";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import { CONNECTOR_ID_RULE, isConnectorId } from "./connector-id.js";
|
|
19
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
20
|
+
import { buildQuotedIssue, fixed } from "./quoted-issue.js";
|
|
21
|
+
/** 配置面 MCP http 条目准入的凭据引用种类(闭集;原语包种类表的子集)。 */
|
|
22
|
+
export const MCP_ENTRY_CREDENTIAL_KINDS = deepFreeze(["assertion"]);
|
|
23
|
+
/** 原语包读法的一处问题 → 句子(只点名原语包自己的成员名与种类词;调用方写的种类 / 多余成员名不回显)。穷举:原语包加一个问题词而这里不补 ⇒ 编译红。 */
|
|
24
|
+
function problemSentence(p) {
|
|
25
|
+
switch (p.reason) {
|
|
26
|
+
case "not_a_record":
|
|
27
|
+
return 'must be a credential reference: a plain object with a "kind" member';
|
|
28
|
+
case "unknown_kind":
|
|
29
|
+
return 'names a "kind" that is not a credential reference kind';
|
|
30
|
+
case "missing_field":
|
|
31
|
+
return `is missing its "${p.field}" member${p.kind === undefined ? "" : ` (a "${p.kind}" reference)`}`;
|
|
32
|
+
case "extra_field":
|
|
33
|
+
return `carries a member a "${p.kind}" reference does not have`;
|
|
34
|
+
case "bad_value":
|
|
35
|
+
return `has a "${p.field}" member of the wrong form (a non-empty data string, no control characters, no leading or trailing whitespace)`;
|
|
36
|
+
default: {
|
|
37
|
+
const unhandled = p;
|
|
38
|
+
throw new Error(`problemSentence: unhandled credential reference problem ${String(unhandled.reason)}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const isAdmittedKind = (kind) => MCP_ENTRY_CREDENTIAL_KINDS.includes(kind);
|
|
43
|
+
/**
|
|
44
|
+
* 读一只条目凭据引用:原语包读一次,种类过准入闭集,断言臂的 `audience` 过连接器 id 判官;交回的是原语包的冻结副本。从不抛。
|
|
45
|
+
* 拒句经 `buildQuotedIssue` 铸(包内 custom issue 的唯一铸点):句子里的每个词都是本包与原语包自己的(种类词、成员名、规则句),整句进模板、没有值位;调用方写的值一个不进句子。
|
|
46
|
+
*/
|
|
47
|
+
function readMcpEntryCredential(value) {
|
|
48
|
+
const read = readCredentialRef(value);
|
|
49
|
+
if (!read.ok)
|
|
50
|
+
return { ok: false, issue: buildQuotedIssue `transport.credentials ${fixed(problemSentence(read.problem))}` };
|
|
51
|
+
const ref = read.ref;
|
|
52
|
+
if (!isAdmittedKind(ref.kind)) {
|
|
53
|
+
const admitted = MCP_ENTRY_CREDENTIAL_KINDS.map((k) => `"${k}"`).join(", ");
|
|
54
|
+
return { ok: false, issue: buildQuotedIssue `transport.credentials of kind "${fixed(ref.kind)}" is not admitted on an MCP http entry — the admitted kind is ${fixed(admitted)}` };
|
|
55
|
+
}
|
|
56
|
+
const credential = ref;
|
|
57
|
+
if (!isConnectorId(credential.audience))
|
|
58
|
+
return { ok: false, issue: buildQuotedIssue `transport.credentials.audience ${fixed(CONNECTOR_ID_RULE)}` };
|
|
59
|
+
return { ok: true, credential };
|
|
60
|
+
}
|
|
61
|
+
/** `transport.credentials` 的输入位:不跑任何检查的类型化 any(输入与产物同型 {@link McpEntryCredential});判法全在它后面的 transform(原语包读一次)。 */
|
|
62
|
+
const CREDENTIAL_INPUT = z.any();
|
|
63
|
+
/**
|
|
64
|
+
* `transport.credentials` 的 zod 形:输入与产物都是 {@link McpEntryCredential};判法就是 {@link readMcpEntryCredential}(原语包读一次 + 准入种类 + 连接器 id),
|
|
65
|
+
* 产物是原语包交回的冻结副本(不是调用方的对象)。
|
|
66
|
+
*/
|
|
67
|
+
export const McpEntryCredential = CREDENTIAL_INPUT.transform((value, ctx) => {
|
|
68
|
+
const read = readMcpEntryCredential(value);
|
|
69
|
+
if (read.ok)
|
|
70
|
+
return read.credential;
|
|
71
|
+
ctx.addIssue({ code: "custom", ...read.issue });
|
|
72
|
+
return z.NEVER;
|
|
73
|
+
});
|