@sema-agent/settings-schema 33.0.0 → 34.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 +525 -0
- package/README.md +151 -17
- package/conformance/VERSION +1 -1
- package/dist/api/wire-scalars.d.ts +3 -2
- package/dist/api/wire-scalars.js +3 -2
- package/dist/atomic-write.d.ts +59 -0
- package/dist/atomic-write.js +303 -1
- package/dist/cli.d.ts +6 -3
- package/dist/cli.js +16 -4
- package/dist/config-dir-migration.d.ts +4 -3
- package/dist/config-dir-migration.js +36 -21
- package/dist/config-fns.d.ts +60 -14
- package/dist/config-fns.js +48 -13
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/warnings.d.ts +1 -1
- package/dist/conformance/warnings.js +3 -3
- package/dist/conformance/web-admin-credential-lock.d.ts +17 -0
- package/dist/conformance/web-admin-credential-lock.js +346 -0
- package/dist/cross-session.d.ts +2 -2
- package/dist/declared-capture.js +1 -1
- package/dist/fleet.d.ts +125 -7
- package/dist/fleet.js +138 -3
- package/dist/hooks-config.d.ts +12 -4
- package/dist/hooks-config.js +28 -11
- package/dist/index.js +2 -2
- package/dist/local-load.d.ts +66 -1
- package/dist/local-load.js +123 -39
- package/dist/mcp-request-entry.d.ts +24 -5
- package/dist/mcp-request-entry.js +57 -17
- package/dist/node.d.ts +1 -0
- package/dist/node.js +2 -0
- package/dist/read-sentences.d.ts +16 -4
- package/dist/read-sentences.js +34 -12
- package/dist/safety-merge-spec.d.ts +5 -5
- package/dist/safety-merge-spec.js +5 -3
- package/dist/settings-units.d.ts +35 -1
- package/dist/settings-units.js +51 -16
- package/dist/types.d.ts +9 -9
- package/dist/types.js +27 -8
- package/dist/ui-language.d.ts +3 -1
- package/dist/ui-language.js +3 -1
- package/dist/web-admin-credential.d.ts +14 -1
- package/dist/web-admin-credential.js +15 -1
- package/docs/API-SURFACE.md +52 -5
- package/docs/CONFORMANCE.md +19 -2
- package/docs/CONSUMER-INTEGRATION.md +140 -11
- package/llms-full.txt +40 -10
- package/llms.txt +16 -7
- package/package.json +1 -1
package/dist/fleet.js
CHANGED
|
@@ -26,6 +26,7 @@ import { isPlainJsonObject } from "./plain-json-object.js";
|
|
|
26
26
|
import { buildQuotedIssue } from "./quoted-issue.js";
|
|
27
27
|
import { recordOf } from "./record-seat.js";
|
|
28
28
|
import { deepFreeze } from "./deep-freeze.js";
|
|
29
|
+
import { SafeCount } from "./api/wire-scalars.js";
|
|
29
30
|
// ── Web-admin's fleet endpoints (paths, one spelling) ─────────────────────────────────────────────────────
|
|
30
31
|
/**
|
|
31
32
|
* Web-admin's `/api/fleet/*` endpoints that are addressed from outside web-admin, relative to its origin. ONE spelling: whoever
|
|
@@ -209,7 +210,8 @@ function judgeSignalBody(body, pick, schema) {
|
|
|
209
210
|
* The reader behind every wire-shape read in this file that has no use for a reason: the engine-owned signals on /health
|
|
210
211
|
* ({@link readEngineSignal}, {@link readModelRefusals}) and the request / reply bodies of the
|
|
211
212
|
* fleet endpoints ({@link readServingLeaseRequest}, {@link readServingLeaseResponse}, {@link readDrainRequest},
|
|
212
|
-
* {@link
|
|
213
|
+
* {@link readCredentialDrainRequest}, {@link readDrainReceipt}, {@link readDrainConditionUnmet}; {@link readDrainRequestReading} composes
|
|
214
|
+
* two of them). Shape mismatch, a non-object body, even a throwing accessor ⇒ `undefined` — never throws.
|
|
213
215
|
*/
|
|
214
216
|
function readSignalBody(body, pick, schema) {
|
|
215
217
|
const judged = judgeSignalBody(body, pick, schema);
|
|
@@ -358,7 +360,9 @@ export function readModelRefusals(body) {
|
|
|
358
360
|
/**
|
|
359
361
|
* The engine's draining fact — ONE object wherever the engine says "I am draining": inside {@link EngineSignal}`.draining`
|
|
360
362
|
* and as the body of a {@link DrainReceipt}.
|
|
361
|
-
* - `actionId` — the action that put the engine into draining
|
|
363
|
+
* - `actionId` — the action that put the engine into draining: for a request of the identity form ({@link DrainRequest}) its `actionId`, the
|
|
364
|
+
* idempotency key; a request of the credential-named form ({@link CredentialDrainRequest}) carries none, and how the engine mints this one
|
|
365
|
+
* for it is the engine's to define (this package does not).
|
|
362
366
|
* - `since` — epoch ms when draining began; it does not move when the same action repeats.
|
|
363
367
|
* - `deadlineAt` — epoch ms by which the engine stops on its own.
|
|
364
368
|
*/
|
|
@@ -831,7 +835,8 @@ export const DrainRequest = z.object({
|
|
|
831
835
|
term: z.string().min(1).optional(),
|
|
832
836
|
});
|
|
833
837
|
/** What a drain request leaves the engine in: `draining` — this call put it into draining; `already_draining` — it already was
|
|
834
|
-
* (the same action repeated), and the receipt reports the first call's facts.
|
|
838
|
+
* (for the identity form: the same action repeated), and the receipt reports the first call's facts. For the credential-named form see
|
|
839
|
+
* {@link CredentialDrainRequest}. */
|
|
835
840
|
export const DRAIN_RECEIPT_STATES = deepFreeze(["draining", "already_draining"]);
|
|
836
841
|
export const DrainReceiptState = z.enum(DRAIN_RECEIPT_STATES);
|
|
837
842
|
/** The drain endpoint's answer: the engine's draining fact ({@link EngineDraining} — the same object {@link EngineSignal}
|
|
@@ -845,6 +850,136 @@ export function readDrainRequest(body) {
|
|
|
845
850
|
export function readDrainReceipt(body) {
|
|
846
851
|
return readSignalBody(body, WHOLE_BODY, DrainReceipt);
|
|
847
852
|
}
|
|
853
|
+
/**
|
|
854
|
+
* The two words of {@link CredentialDrainRequest}`.turns` — a CLOSED set, owned here (a reader that switches on it exhaustively is told
|
|
855
|
+
* by the compiler when a word is added): how the turns that are running at the moment the engine accepts the drain give way. This package
|
|
856
|
+
* fixes the words; what each word does is engine-side behaviour, described here and not verified by this package.
|
|
857
|
+
* - `yield` — the way a drain always stops them: a running turn parks at its next clean turn boundary, and what has not finished when the
|
|
858
|
+
* deadline passes is cut by the hard stop. An absent `turns` means `yield`.
|
|
859
|
+
* - `halt` — everything `yield` does, and in the same step the engine asks every running turn that has a turn surface to stop now — the
|
|
860
|
+
* cut a user's Esc makes in that window. The deadline does not move; a turn that does not take the cut in time is handled as under
|
|
861
|
+
* `yield`. The engine honours it only for a caller that holds the operator authority to halt any run; otherwise it refuses and changes nothing.
|
|
862
|
+
*/
|
|
863
|
+
export const DRAIN_TURNS = deepFreeze(["yield", "halt"]);
|
|
864
|
+
export const DrainTurns = z.enum(DRAIN_TURNS);
|
|
865
|
+
/** The member schemas of {@link CredentialDrainRequest} — the one place its keys are written: the schema is built from this very object, and the
|
|
866
|
+
* set of keys only that form has is read off it (a plain object, so reading its keys materializes nothing lazy inside the validator). */
|
|
867
|
+
const CREDENTIAL_DRAIN_SHAPE = {
|
|
868
|
+
instanceId: DrainRequest.shape.instanceId,
|
|
869
|
+
turns: DrainTurns.optional(),
|
|
870
|
+
attachedAtMost: SafeCount.optional(),
|
|
871
|
+
};
|
|
872
|
+
/**
|
|
873
|
+
* The drain endpoint's request in its CREDENTIAL-NAMED form: the sender (the side that sends the request) names the engine by the credential it
|
|
874
|
+
* presents (the one a launcher minted for this process), not by the identity quadruple of {@link DrainRequest} — so the body carries no action
|
|
875
|
+
* id, no worker, no deadline, only what is to be said about THIS call. A STRICT object: one key more, one word off, a negative / fractional /
|
|
876
|
+
* string / oversize count ⇒ the body is not this form (and a half-built {@link DrainRequest} is never read as a stop request). Every key is
|
|
877
|
+
* optional and the empty body `{}` is the whole default form. A reader never mints a key the sender did not write, and this package exports
|
|
878
|
+
* no default constant: the RECEIVING side applies the meaning of an absent key — an absent `turns` is `yield`, an absent `attachedAtMost`
|
|
879
|
+
* sets no condition.
|
|
880
|
+
* - `instanceId` — a non-empty string: the engine's own per-process identity ({@link InstanceHealth}`.instanceId`). When present the engine
|
|
881
|
+
* compares it with its own and refuses on a mismatch. The very schema of {@link DrainRequest}`.instanceId`, not a copy.
|
|
882
|
+
* - `turns` — how the turns running at acceptance give way ({@link DRAIN_TURNS}).
|
|
883
|
+
* - `attachedAtMost` — a non-negative safe integer: accept the drain only if at most this many streams are attached to the engine at the
|
|
884
|
+
* moment it judges the request; more ⇒ a refusal carrying {@link DrainConditionUnmet}, nothing changed. It bounds what was attached at that moment;
|
|
885
|
+
* it is not a promise about the streams and requests that arrive afterwards.
|
|
886
|
+
* The two forms of the endpoint's request share no body that is plain data (what JSON parsing yields): {@link DrainRequest} requires
|
|
887
|
+
* `actionId`, `worker` and `deadlineAt`, which this form refuses as unknown keys. `turns` and `attachedAtMost` belong to this form only —
|
|
888
|
+
* {@link DrainRequest} does not carry them; its single-form reader strips them like any unknown key, and the reader of the endpoint's body
|
|
889
|
+
* ({@link readDrainRequestReading}) reads an identity body that carries either of them as neither form. The answer is the same
|
|
890
|
+
* {@link DrainReceipt} shape for both forms. What the engine puts in it for this form — engine-side behaviour, which this package does not
|
|
891
|
+
* verify: `deadlineAt` is the engine's own drain window (the body names no deadline); a `halt` sent while the engine is already draining is
|
|
892
|
+
* answered `already_draining` with the first call's facts and cuts the turns running at that moment; while the hard stop is under way the
|
|
893
|
+
* receipt's `actionId` is `hard-stop` and neither `turns` nor `attachedAtMost` is read; the naming is judged before the condition (a naming
|
|
894
|
+
* mismatch is refused without the attached count), and the condition is judged even when the engine is already draining. How the engine
|
|
895
|
+
* mints the receipt's `actionId` for this form, and what it answers for other requests of this form sent while it is draining, is the
|
|
896
|
+
* engine's to define; this package does not.
|
|
897
|
+
*/
|
|
898
|
+
export const CredentialDrainRequest = z.object(CREDENTIAL_DRAIN_SHAPE).strict();
|
|
899
|
+
/** The keys only the credential-named form has: its keys minus the ones {@link DrainRequest} also declares (`instanceId` is shared).
|
|
900
|
+
* Derived from the two shapes, never spelled again — a key added to the credential-named form joins this set by construction. */
|
|
901
|
+
const CREDENTIAL_ONLY_DRAIN_KEYS = deepFreeze(Object.keys(CREDENTIAL_DRAIN_SHAPE).filter((key) => !Object.hasOwn(DrainRequest.shape, key)));
|
|
902
|
+
/**
|
|
903
|
+
* Engine side: the request body of the drain endpoint in its credential-named form. Shape mismatch / non-object / throwing accessor ⇒
|
|
904
|
+
* `undefined`, never throws. A body of the identity form ({@link DrainRequest}) reads `undefined` here and a body of this form reads
|
|
905
|
+
* `undefined` for {@link readDrainRequest}: no plain-data body is read by both (an object that shows two different key sets to the two
|
|
906
|
+
* readers — a Proxy whose `ownKeys` trap lies — is outside that promise; a body parsed from JSON never is one). A request with no bytes is
|
|
907
|
+
* the engine's to turn into `{}` before it calls this reader (`undefined` and `null` are not objects here).
|
|
908
|
+
* The result is an ordinary object, like every reader's in this file: the reader looks only at the body's own keys, but an optional key it
|
|
909
|
+
* did not read is absent only as an own key — test for it with `Object.hasOwn`, do not read it through the prototype chain.
|
|
910
|
+
*/
|
|
911
|
+
export function readCredentialDrainRequest(body) {
|
|
912
|
+
return readSignalBody(body, WHOLE_BODY, CredentialDrainRequest);
|
|
913
|
+
}
|
|
914
|
+
/** The form words of {@link DrainRequestReading}, in the order the reader tries them. `satisfies` bites a word the union does not have;
|
|
915
|
+
* the converse (a union arm missing from this list) is pinned by a test that compares the two. */
|
|
916
|
+
export const DRAIN_REQUEST_FORMS = deepFreeze(["identity", "credential"]);
|
|
917
|
+
/**
|
|
918
|
+
* Does `body` carry, as its own key, a key only the credential-named form has ({@link CREDENTIAL_ONLY_DRAIN_KEYS})? Asked by the descriptor law
|
|
919
|
+
* every reader in this file uses: an own key — plain data, or one that cannot be read as plain data (not enumerable, an accessor — never called)
|
|
920
|
+
* — or a descriptor that cannot be inspected counts as carrying it; a key the body only inherits, or does not have, does not. Never throws.
|
|
921
|
+
*/
|
|
922
|
+
function carriesCredentialOnlyDrainKey(body) {
|
|
923
|
+
return CREDENTIAL_ONLY_DRAIN_KEYS.some((key) => {
|
|
924
|
+
const read = readDeclaredKey(body, key);
|
|
925
|
+
switch (read.presence) {
|
|
926
|
+
case "inherited":
|
|
927
|
+
case "absent":
|
|
928
|
+
return false;
|
|
929
|
+
case "own":
|
|
930
|
+
case "hidden":
|
|
931
|
+
case "unreadable":
|
|
932
|
+
return true;
|
|
933
|
+
default: {
|
|
934
|
+
const unhandled = read;
|
|
935
|
+
throw new Error(`carriesCredentialOnlyDrainKey: unhandled presence ${String(unhandled.presence)}`);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Engine side: THE reader of the drain endpoint's request body — which form it is and the request in that form; neither ⇒ `undefined`.
|
|
942
|
+
* A body is one form or the other: a body that mixes the keys of the two forms is NEITHER — a body the identity reader reads that also
|
|
943
|
+
* carries, as its own key, a key only the credential-named form has (`turns`, `attachedAtMost`: that form's keys minus the shared
|
|
944
|
+
* `instanceId`) reads `undefined` here, whatever that key's value, so a condition or a turn policy sent on the identity form is refused
|
|
945
|
+
* instead of being stripped. It composes the two single-form readers and that one key check (no second schema): {@link readDrainRequest}
|
|
946
|
+
* first, then {@link readCredentialDrainRequest}; the `request` handed back is that reader's answer in this call. When this reader reads a
|
|
947
|
+
* body, its `request` equals the answer of that form's single-form reader; the converse does not hold: a mixed body that is plain data reads
|
|
948
|
+
* `undefined` here while {@link readDrainRequest} reads it (stripping the keys). For plain data the order changes nothing (no such body is
|
|
949
|
+
* read by both single-form readers). An object that shows the two single-form readers different key sets reads as the identity form only
|
|
950
|
+
* when the key check, which asks for each credential-only key's own descriptor, finds none of them; when it finds one the object is a mixed
|
|
951
|
+
* body and reads `undefined`. A proxy that changes itself while it is read may answer differently than when the credential reader is asked
|
|
952
|
+
* alone (the identity probe came first). Never throws. The single-form readers stay for a side that
|
|
953
|
+
* already knows which form it sent; {@link readDrainRequest} still strips the credential-named form's keys as it strips any unknown key.
|
|
954
|
+
*/
|
|
955
|
+
export function readDrainRequestReading(body) {
|
|
956
|
+
const identity = readDrainRequest(body);
|
|
957
|
+
if (identity !== undefined)
|
|
958
|
+
return carriesCredentialOnlyDrainKey(body) ? undefined : { form: "identity", request: identity };
|
|
959
|
+
const credential = readCredentialDrainRequest(body);
|
|
960
|
+
return credential === undefined ? undefined : { form: "credential", request: credential };
|
|
961
|
+
}
|
|
962
|
+
/** The machine code of the drain endpoint's refusal "the condition the request set is not met": the HTTP 409 whose body carries {@link DrainConditionUnmet}.
|
|
963
|
+
* One spelling — the engine mints the refusal with it, a caller branches on it. */
|
|
964
|
+
export const DRAIN_CONDITION_UNMET_CODE = "conflict.drain_condition_unmet";
|
|
965
|
+
/**
|
|
966
|
+
* The facts a {@link DRAIN_CONDITION_UNMET_CODE} refusal carries at the root of its body, beside the refusal's own `error` sentence and `errorCode`:
|
|
967
|
+
* - `attached` — how many streams were attached when the engine judged the request;
|
|
968
|
+
* - `attachedAtMost` — the bound the request set, echoed.
|
|
969
|
+
* A refused call changed nothing, and the engine answers this only when `attached` is above `attachedAtMost` (engine-side behaviour, not
|
|
970
|
+
* verified by this package); the reader judges the form of the
|
|
971
|
+
* two numbers (non-negative safe integers), not their relation. The refusal's own keys are stripped, so the reader takes the whole body.
|
|
972
|
+
*/
|
|
973
|
+
export const DrainConditionUnmet = z.object({ attached: SafeCount, attachedAtMost: SafeCount });
|
|
974
|
+
/**
|
|
975
|
+
* Caller side: the facts of a {@link DRAIN_CONDITION_UNMET_CODE} refusal. Compare the refusal's `errorCode` with {@link DRAIN_CONDITION_UNMET_CODE}
|
|
976
|
+
* first and read the two numbers with this only when they are equal: this reader does not judge the code, so any body that carries the two
|
|
977
|
+
* facts reads, whatever refusal it is. A body that does not carry both facts (another refusal of the same status, a receipt, a request) reads `undefined`.
|
|
978
|
+
* Shape mismatch / non-object / throwing accessor ⇒ `undefined`, never throws.
|
|
979
|
+
*/
|
|
980
|
+
export function readDrainConditionUnmet(body) {
|
|
981
|
+
return readSignalBody(body, WHOLE_BODY, DrainConditionUnmet);
|
|
982
|
+
}
|
|
848
983
|
// ── Domain 3: dispatch policy (traffic + failover + LB — three domains, one gateway) ──────────────────────
|
|
849
984
|
export const DISPATCH_STRATEGIES = deepFreeze(["round-robin", "least-inflight", "consistent-hash"]);
|
|
850
985
|
/** Per-worker dispatch policy (web-admin-configured; the gateway is OPTIONAL — D3: TOC/self-maintained TOB go
|
package/dist/hooks-config.d.ts
CHANGED
|
@@ -192,13 +192,16 @@ export declare const HOOK_COMMAND_SPAWN_REFUSAL_WORDS: readonly ["path_unset", "
|
|
|
192
192
|
/** One word of {@link HOOK_COMMAND_SPAWN_REFUSAL_WORDS}. */
|
|
193
193
|
export type HookCommandSpawnRefusalWord = (typeof HOOK_COMMAND_SPAWN_REFUSAL_WORDS)[number];
|
|
194
194
|
/** A refusal of {@link planHookCommandSpawn}: the word, and the path name or the option key (as written on the command line — user text: pass it through the consumer's echo rules,
|
|
195
|
-
* or use {@link hookCommandSpawnRefusalSentence}) it is about. Never a value.
|
|
195
|
+
* or use {@link hookCommandSpawnRefusalSentence}) it is about. Never a value. The three words about a plugin's options (`shell_form_user_config`, `user_config_unset`, `user_config_unresolved`)
|
|
196
|
+
* have one shape — the word, the option `key`, and `pluginName`: the name of the plugin whose option was named, taken from the entry's own `plugin.name` (user text too: the sentence passes
|
|
197
|
+
* it through the same echo as the key). */
|
|
196
198
|
export type HookCommandSpawnRefusal = {
|
|
197
199
|
readonly word: "path_unset";
|
|
198
200
|
readonly name: HookCommandPathName;
|
|
199
201
|
} | {
|
|
200
202
|
readonly word: Exclude<HookCommandSpawnRefusalWord, "path_unset">;
|
|
201
203
|
readonly key: string;
|
|
204
|
+
readonly pluginName: string;
|
|
202
205
|
};
|
|
203
206
|
/** What {@link planHookCommandSpawn} answers: the shell-form command as it is (`shell`), the exec-form copy a process starts from (`exec`), or why it cannot start (`refused`). */
|
|
204
207
|
export type HookCommandSpawnPlan = {
|
|
@@ -224,7 +227,7 @@ export type HookCommandSpawnPlan = {
|
|
|
224
227
|
*
|
|
225
228
|
* INPUT. `entry` — the command line, and whether a plugin brought it: exec form when `args` is present (`command` is the program, no shell), shell form when it is not (the same
|
|
226
229
|
* switch as the entry's own); a PLUGIN entry is one with a `plugin` member — the same reading the classifier and the `plugin` column make (a {@link CommandHookEntry} the classifier
|
|
227
|
-
* loaded is passed as it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
230
|
+
* loaded is passed as it is; its `plugin` is read for `options`, and for `name` — every refusal about an option says whose option it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
228
231
|
* like any other `${…}`, and a shell-form command is not refused for it (the reference implementation takes an option table only for a plugin's hook, and both its refusal and its
|
|
229
232
|
* substitution hang on that table). `paths` — each path name's value, all three stated: a string (the empty string included) is the value, `undefined` is no value. `resolved` —
|
|
230
233
|
* optional, a plugin entry's option table as the caller holds it after resolving (or, for a sender, the table it holds); left out, the table is the entry's own `plugin.options`, and
|
|
@@ -236,7 +239,8 @@ export type HookCommandSpawnPlan = {
|
|
|
236
239
|
* VERDICT, in the order of {@link HOOK_COMMAND_SPAWN_REFUSAL_WORDS} — a whole word is judged over the whole command line before the next word (any unset key beats any unresolved one,
|
|
237
240
|
* wherever each stands): a named path name without a value ⇒ `path_unset` (the first missing one in {@link HOOK_COMMAND_PATH_NAMES} order); shell form naming an option ⇒
|
|
238
241
|
* `shell_form_user_config`; exec form naming a key the table does not hold ⇒ `user_config_unset`; exec form naming a key whose value is a reference ⇒ `user_config_unresolved` (keys:
|
|
239
|
-
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry
|
|
242
|
+
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry; each of the three also carries `pluginName`, the entry's own `plugin.name` — read
|
|
243
|
+
* from the entry whichever table is judged, never from `resolved`). Otherwise shell form ⇒ `command` as it is (a shell expands path names from
|
|
240
244
|
* the environment; nothing is substituted in the text), exec form ⇒ `file` / `args` with every recognized placeholder replaced by its value in that same pass.
|
|
241
245
|
*
|
|
242
246
|
* CALL SHAPES. A runner passes the entry it loaded and its paths — `planHookCommandSpawn(entry, paths)` — and nothing else decides the namespace. A runner with steps of its own between
|
|
@@ -254,12 +258,16 @@ export declare function planHookCommandSpawn(entry: {
|
|
|
254
258
|
readonly command: string;
|
|
255
259
|
readonly args?: readonly string[];
|
|
256
260
|
readonly plugin?: {
|
|
261
|
+
readonly name: string;
|
|
257
262
|
readonly options?: Readonly<Record<string, string | HookPluginOptionRef>>;
|
|
258
263
|
};
|
|
259
264
|
}, paths: Readonly<Record<HookCommandPathName, string | undefined>>, resolved?: Readonly<Record<string, string | HookPluginOptionRef>>): HookCommandSpawnPlan;
|
|
260
265
|
/**
|
|
261
266
|
* The one sentence for a {@link HookCommandSpawnRefusal}: fixed words plus the path name, or the option key passed through this package's echo of caller text (control and
|
|
262
|
-
* bidirectional characters stripped, long keys cut)
|
|
267
|
+
* bidirectional characters stripped, long keys cut); the three option words open with one phrase that names both the option and its plugin (`pluginName`, through the same echo) —
|
|
268
|
+
* `hook command names option "<key>" of plugin "<plugin>"` — and go on with what each says: `, which is not set` / `, whose value is a stored reference that is not resolved here` /
|
|
269
|
+
* ` in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable
|
|
270
|
+
* CLAUDE_PLUGIN_OPTION_<KEY>`. Never a value — the refusal carries none. A runner and a sender show this sentence instead of writing their own.
|
|
263
271
|
*/
|
|
264
272
|
export declare function hookCommandSpawnRefusalSentence(refusal: HookCommandSpawnRefusal): string;
|
|
265
273
|
/** The cap on {@link measureHookPluginContext}'s count for one entry's plugin context, in UTF-16 code units (a literal type: the measure's own copy is tied to it at compile time). */
|
package/dist/hooks-config.js
CHANGED
|
@@ -219,7 +219,7 @@ export const HOOK_COMMAND_SPAWN_REFUSAL_WORDS = deepFreeze(["path_unset", "shell
|
|
|
219
219
|
*
|
|
220
220
|
* INPUT. `entry` — the command line, and whether a plugin brought it: exec form when `args` is present (`command` is the program, no shell), shell form when it is not (the same
|
|
221
221
|
* switch as the entry's own); a PLUGIN entry is one with a `plugin` member — the same reading the classifier and the `plugin` column make (a {@link CommandHookEntry} the classifier
|
|
222
|
-
* loaded is passed as it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
222
|
+
* loaded is passed as it is; its `plugin` is read for `options`, and for `name` — every refusal about an option says whose option it is). The `user_config` namespace belongs to plugin entries: on an entry with no `plugin`, `${user_config.…}` is no placeholder at all — it stays as written
|
|
223
223
|
* like any other `${…}`, and a shell-form command is not refused for it (the reference implementation takes an option table only for a plugin's hook, and both its refusal and its
|
|
224
224
|
* substitution hang on that table). `paths` — each path name's value, all three stated: a string (the empty string included) is the value, `undefined` is no value. `resolved` —
|
|
225
225
|
* optional, a plugin entry's option table as the caller holds it after resolving (or, for a sender, the table it holds); left out, the table is the entry's own `plugin.options`, and
|
|
@@ -231,7 +231,8 @@ export const HOOK_COMMAND_SPAWN_REFUSAL_WORDS = deepFreeze(["path_unset", "shell
|
|
|
231
231
|
* VERDICT, in the order of {@link HOOK_COMMAND_SPAWN_REFUSAL_WORDS} — a whole word is judged over the whole command line before the next word (any unset key beats any unresolved one,
|
|
232
232
|
* wherever each stands): a named path name without a value ⇒ `path_unset` (the first missing one in {@link HOOK_COMMAND_PATH_NAMES} order); shell form naming an option ⇒
|
|
233
233
|
* `shell_form_user_config`; exec form naming a key the table does not hold ⇒ `user_config_unset`; exec form naming a key whose value is a reference ⇒ `user_config_unresolved` (keys:
|
|
234
|
-
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry
|
|
234
|
+
* the first in pass order; the three option words only where options are recognized, i.e. on a plugin entry; each of the three also carries `pluginName`, the entry's own `plugin.name` — read
|
|
235
|
+
* from the entry whichever table is judged, never from `resolved`). Otherwise shell form ⇒ `command` as it is (a shell expands path names from
|
|
235
236
|
* the environment; nothing is substituted in the text), exec form ⇒ `file` / `args` with every recognized placeholder replaced by its value in that same pass.
|
|
236
237
|
*
|
|
237
238
|
* CALL SHAPES. A runner passes the entry it loaded and its paths — `planHookCommandSpawn(entry, paths)` — and nothing else decides the namespace. A runner with steps of its own between
|
|
@@ -319,18 +320,19 @@ export function planHookCommandSpawn(entry, paths, resolved) {
|
|
|
319
320
|
if ("key" in p)
|
|
320
321
|
keys.push(p.key);
|
|
321
322
|
if (entry.args === undefined) {
|
|
322
|
-
|
|
323
|
+
// An option placeholder is only collected on a plugin entry (the pass above), so `plugin` is the entry's own context wherever `keys` is not empty.
|
|
324
|
+
return keys.length > 0 ? { kind: "refused", refusal: { word: "shell_form_user_config", key: keys[0], pluginName: plugin.name } } : { kind: "shell", command: entry.command };
|
|
323
325
|
}
|
|
324
326
|
let unresolved;
|
|
325
327
|
for (const key of keys) {
|
|
326
|
-
// A key is recognized only on a plugin entry (the pass above), so `options` is a table wherever a key is read
|
|
328
|
+
// A key is recognized only on a plugin entry (the pass above), so `options` is a table — and `plugin` is the entry's own context — wherever a key is read: here and in `render`.
|
|
327
329
|
if (!Object.hasOwn(options, key))
|
|
328
|
-
return { kind: "refused", refusal: { word: "user_config_unset", key } };
|
|
330
|
+
return { kind: "refused", refusal: { word: "user_config_unset", key, pluginName: plugin.name } };
|
|
329
331
|
if (unresolved === undefined && typeof options[key] !== "string")
|
|
330
332
|
unresolved = key;
|
|
331
333
|
}
|
|
332
334
|
if (unresolved !== undefined)
|
|
333
|
-
return { kind: "refused", refusal: { word: "user_config_unresolved", key: unresolved } };
|
|
335
|
+
return { kind: "refused", refusal: { word: "user_config_unresolved", key: unresolved, pluginName: plugin.name } };
|
|
334
336
|
const render = (line) => {
|
|
335
337
|
let out = "";
|
|
336
338
|
for (const piece of line)
|
|
@@ -341,18 +343,33 @@ export function planHookCommandSpawn(entry, paths, resolved) {
|
|
|
341
343
|
}
|
|
342
344
|
/**
|
|
343
345
|
* The one sentence for a {@link HookCommandSpawnRefusal}: fixed words plus the path name, or the option key passed through this package's echo of caller text (control and
|
|
344
|
-
* bidirectional characters stripped, long keys cut)
|
|
346
|
+
* bidirectional characters stripped, long keys cut); the three option words open with one phrase that names both the option and its plugin (`pluginName`, through the same echo) —
|
|
347
|
+
* `hook command names option "<key>" of plugin "<plugin>"` — and go on with what each says: `, which is not set` / `, whose value is a stored reference that is not resolved here` /
|
|
348
|
+
* ` in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable
|
|
349
|
+
* CLAUDE_PLUGIN_OPTION_<KEY>`. Never a value — the refusal carries none. A runner and a sender show this sentence instead of writing their own.
|
|
345
350
|
*/
|
|
346
351
|
export function hookCommandSpawnRefusalSentence(refusal) {
|
|
347
352
|
switch (refusal.word) {
|
|
348
353
|
case "path_unset":
|
|
349
354
|
return `hook command names \${${refusal.name}}, which has no value for this hook (it comes from the hook's plugin context or from its environment; settings.env can set it)`;
|
|
350
355
|
case "shell_form_user_config":
|
|
351
|
-
return `hook command names \${user_config.${echoCallerText(refusal.key)}} in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable CLAUDE_PLUGIN_OPTION_<KEY>`;
|
|
352
356
|
case "user_config_unset":
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
357
|
+
case "user_config_unresolved": {
|
|
358
|
+
const option = `hook command names option "${echoCallerText(refusal.key)}" of plugin "${echoCallerText(refusal.pluginName)}"`;
|
|
359
|
+
const word = refusal.word; // switch on the copy: once its cases are exhausted TypeScript narrows `refusal` itself to `never`, and the `default` arm below must still name the word
|
|
360
|
+
switch (word) {
|
|
361
|
+
case "shell_form_user_config":
|
|
362
|
+
return `${option} in shell form, where the shell would parse the substituted value again — use exec form ("command" plus "args"), or read the option from the environment variable CLAUDE_PLUGIN_OPTION_<KEY>`;
|
|
363
|
+
case "user_config_unset":
|
|
364
|
+
return `${option}, which is not set`;
|
|
365
|
+
case "user_config_unresolved":
|
|
366
|
+
return `${option}, whose value is a stored reference that is not resolved here`;
|
|
367
|
+
default: {
|
|
368
|
+
const unknownWord = word;
|
|
369
|
+
throw new Error(`hookCommandSpawnRefusalSentence: unknown refusal word '${String(unknownWord)}'`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
356
373
|
default: {
|
|
357
374
|
const unknownWord = refusal;
|
|
358
375
|
throw new Error(`hookCommandSpawnRefusalSentence: unknown refusal word '${String(unknownWord.word)}'`);
|
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export * from "./reader.js";
|
|
|
25
25
|
export * from "./cross-domain.js"; // pure half only (no fleet placement)
|
|
26
26
|
export * from "./remote-exec.js";
|
|
27
27
|
export * from "./safety-merge-spec.js"; // #14 per-category safety merge-spec (settings resolver authority) + 14.6.0 THE comparator tightenVerdict / TIGHTEN_VERDICTS and the member comparator memberTighten / resolveMemberTighten (derived from a member row's value class)
|
|
28
|
-
export * from "./settings-units.js"; // 14.6.0: SETTINGS_UNITS — the settings-document unit table (path / category / addressing / reading) + unitTighten (a unit's comparator) + readSettingsUnit (a unit's raw-value reading; spellings normalized, everything else unreadable), pure/browser-safe
|
|
28
|
+
export * from "./settings-units.js"; // 14.6.0: SETTINGS_UNITS — the settings-document unit table (path / category / addressing / reading / reader — SETTINGS_UNIT_READERS = shell | engine; the eleventh unit is the UI-language key semaUiLanguage) + unitTighten (a unit's comparator) + readSettingsUnit (a unit's raw-value reading; spellings normalized, everything else unreadable), pure/browser-safe
|
|
29
29
|
export * from "./scheduler-store.js"; // R7 self-wake scheduler store CONTRACT (pure: type + parse/serialize + SchedulerStore interface; fs binding in ./node)
|
|
30
30
|
export * from "./cross-session.js"; // CC-parity `settings.json` cross-session keys (crossSessionInbound / dialogExpiry) — pure/browser-safe
|
|
31
31
|
export * from "./hooks.js"; // CC-parity hooks contract (33-event set + owner map + per-event input/output shapes + the config surface: classifyHooksConfig and its zod faces HooksConfig / HookEntry …) & stop attribution (stoppedBy) — pure/browser-safe
|
|
@@ -50,7 +50,7 @@ export * from "./mcp-server-policy.js"; // 13.0.0 (U6): mcpServerPolicyVerdict
|
|
|
50
50
|
export * from "./web-search-section.js"; // 30.1.0: WEB_SEARCH_SECTION_KEYS — the web search section's settings-document key (each key is also its category's name: SAFETY_MERGE_SPEC.webSearch), pure/browser-safe
|
|
51
51
|
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
|
|
52
52
|
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
|
|
53
|
-
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
|
|
53
|
+
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; the credential reference kinds an http transport takes, MCP_REQUEST_CREDENTIAL_KINDS) — one reading for the service legs and the shell pre-check, pure/browser-safe
|
|
54
54
|
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
|
|
55
55
|
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
|
|
56
56
|
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
|
package/dist/local-load.d.ts
CHANGED
|
@@ -17,12 +17,77 @@ export declare function loadRemoteExec(root: string): Promise<RemoteExecSpec | u
|
|
|
17
17
|
/** Validate + ATOMICALLY write `<root>/config.d/remote-exec.json` (the package's one atomic writer, `./atomic-write`; never a half file). The
|
|
18
18
|
* client's `config` editor writes the exec backend through this; the engine reads it via loadRemoteExec. */
|
|
19
19
|
export declare function writeRemoteExec(root: string, spec: unknown): Promise<RemoteExecSpec>;
|
|
20
|
+
/** The `.env` file path under a config root — the ONE builder: the reading step reads exactly this path, a caller that watches or trust-checks the file asks the same function. */
|
|
21
|
+
export declare function envFilePath(root: string): string;
|
|
22
|
+
/** Why a `.env` line is not an assignment (closed set; a comment or a blank line is not a fault — it is not meant to be one): `no_equals` = text with no `=` in it; `empty_name` = nothing before the `=`. */
|
|
23
|
+
export declare const ENV_FILE_LINE_FAULTS: readonly ["no_equals", "empty_name"];
|
|
24
|
+
export type EnvFileLineFault = (typeof ENV_FILE_LINE_FAULTS)[number];
|
|
25
|
+
/** Why a `file:` reference could not be resolved (closed set, one word per exit): `empty_path` = nothing after `file:`; `missing_file` = the target does not exist; `empty_file` = the target is empty or only
|
|
26
|
+
* whitespace; `unreadable` = the read failed for any other reason (the original error is the answer's `error`); `untrusted` = the caller's trust seat refused the target (or could not answer), so it was NOT read. */
|
|
27
|
+
export declare const ENV_FILE_REF_FAULTS: readonly ["empty_path", "missing_file", "empty_file", "unreadable", "untrusted"];
|
|
28
|
+
export type EnvFileRefFault = (typeof ENV_FILE_REF_FAULTS)[number];
|
|
29
|
+
/** One `NAME=value` line as written: `line` is 1-based, `written` is the value after the quotes and an inline ` #` comment are taken off — a `file:` reference stays the text it was (nothing is resolved at this step). */
|
|
30
|
+
export interface EnvFileAssignment {
|
|
31
|
+
readonly line: number;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly written: string;
|
|
34
|
+
}
|
|
35
|
+
/** A line that is not an assignment: its 1-based number and the closed-set fault. The line's text is NOT carried — text with no `=` in it may be a pasted secret. */
|
|
36
|
+
export interface EnvFileBadLine {
|
|
37
|
+
readonly line: number;
|
|
38
|
+
readonly fault: EnvFileLineFault;
|
|
39
|
+
}
|
|
40
|
+
/** The first step's answer: the config root it was read under (a relative `file:` target is resolved against it), every assignment in file order (a name written twice is two entries), and every bad line. */
|
|
41
|
+
export interface EnvFileReading {
|
|
42
|
+
readonly root: string;
|
|
43
|
+
readonly assignments: readonly EnvFileAssignment[];
|
|
44
|
+
readonly badLines: readonly EnvFileBadLine[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* STEP ONE of reading `<root>/.env`: parse its lines into `NAME → the text written`, and resolve NOTHING. No `file:` target is looked at, so a bad reference on a line the caller does not care about cannot
|
|
48
|
+
* make this read fail, and a line that is not an assignment is reported by number instead of being dropped without a word. Absent `.env` ⇒ an empty reading (absence is the one rule `readTextIfPresent`
|
|
49
|
+
* answers: no entry on the path; a DANGLING symbolic link is an entry that cannot be read, so it throws, with the same sentence as {@link loadEnvFile}). The reading does NOT carry `process.env` —
|
|
50
|
+
* merging the process environment under the file is {@link loadEnvFile}'s step, not this one's.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readEnvFileLines(root: string): Promise<EnvFileReading>;
|
|
53
|
+
/**
|
|
54
|
+
* The caller's TRUST SEAT for a `file:` target: asked with the target's absolute path BEFORE any byte of it is read; `undefined` = go ahead, a string = refuse (the string is the sentence). A seat that throws
|
|
55
|
+
* or rejects refuses too (fail closed). It may be asynchronous. This package judges no file's owner or mode itself: whose files may feed a credential is the caller's rule, and this is where the caller's rule is applied.
|
|
56
|
+
*/
|
|
57
|
+
export type EnvFileTrustSeat = (file: string) => string | undefined | Promise<string | undefined>;
|
|
58
|
+
/** Options of {@link resolveEnvFileAssignments}: `trust` = the seat above (absent ⇒ every `file:` target is read); `failFast` = stop at the FIRST refusal in file order — no later line is looked at, no later target is asked of the seat or
|
|
59
|
+
* opened — and answer with that one refusal (`values` then holds only what resolved before it). {@link loadEnvFile} is the no-seat, fail-fast call: it never reads past the line it throws for. */
|
|
60
|
+
export interface EnvFileResolveOptions {
|
|
61
|
+
readonly trust?: EnvFileTrustSeat;
|
|
62
|
+
readonly failFast?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** One name that could not be resolved: the name, the number of the FIRST line that failed for it, the closed-set fault, and the error — the same object {@link loadEnvFile} throws for that line (a read error is passed through unchanged). */
|
|
65
|
+
export interface EnvFileRefusal {
|
|
66
|
+
readonly name: string;
|
|
67
|
+
readonly line: number;
|
|
68
|
+
readonly fault: EnvFileRefFault;
|
|
69
|
+
readonly error: Error;
|
|
70
|
+
}
|
|
71
|
+
/** The second step's answer: `values` = the resolved value of each requested name that the file assigns (the last assignment wins), `refused` = the names that failed, in file order. A refused name is not in `values`. */
|
|
72
|
+
export interface EnvFileResolution {
|
|
73
|
+
readonly values: Readonly<Record<string, string>>;
|
|
74
|
+
readonly refused: readonly EnvFileRefusal[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* STEP TWO: resolve only the names the caller lists, from a {@link readEnvFileLines} reading — nothing else in the file is looked at, and nothing is read from disk but the `file:` targets of those names. A value
|
|
78
|
+
* that does not start with `file:` is itself; one that does is the trimmed content of that file, the target asked of the caller's trust seat first ({@link EnvFileTrustSeat}) and read only if it answers `undefined`.
|
|
79
|
+
* EVERY assignment of a listed name is resolved, the overridden ones too: an earlier line's bad reference is still a refusal of that name (a secret that cannot be resolved is not made fine by being written again later);
|
|
80
|
+
* once a name has a refusal its later lines are not looked at. A name the file does not assign appears nowhere in the answer. Never throws for a bad line or target: the answer says which names failed, how, and why.
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveEnvFileAssignments(reading: EnvFileReading, names: Iterable<string>, opts?: EnvFileResolveOptions): Promise<EnvFileResolution>;
|
|
20
83
|
/** Parse `<root>/.env` (KEY=VALUE, `#` comments, optional surrounding quotes) MERGED OVER process.env (the
|
|
21
84
|
* file wins). The ONLY place secret VALUES live — the contract files carry env-NAMEs only. A `KEY=` with an
|
|
22
85
|
* empty value IS present (the caller may treat empty as a weak warning). Absent .env → just process.env — absent
|
|
23
86
|
* means no entry on the path (the one absence rule, `readTextIfPresent`): a DANGLING symbolic link at `.env` is present and unreadable, so it throws.
|
|
24
87
|
* A `.env` value of `file:<path>` resolves to that file's trimmed content (file-NAME ref — key stays out of
|
|
25
|
-
* env, contract stays env-NAME-only). Schema still rejects pasted plaintext (the contract field is a NAME).
|
|
88
|
+
* env, contract stays env-NAME-only). Schema still rejects pasted plaintext (the contract field is a NAME).
|
|
89
|
+
* This is the two steps in one: {@link readEnvFileLines}, then {@link resolveEnvFileAssignments} for EVERY name the file assigns, no trust seat, fail-fast — so one bad `file:` reference anywhere in the file
|
|
90
|
+
* throws (the first one in file order, with the same error as ever, and nothing after that line is opened). A reader that wants only some names, or wants to judge each `file:` target before it is read, calls the two steps itself. */
|
|
26
91
|
export declare function loadEnvFile(root: string): Promise<Record<string, string>>;
|
|
27
92
|
export interface LocalConfig {
|
|
28
93
|
/** The resolved config the engine consumes — the FULL EffectiveConfig (skills carry full content; NOT the
|