@sema-agent/settings-schema 31.1.0 → 33.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +917 -0
  2. package/README.md +103 -19
  3. package/conformance/VERSION +1 -1
  4. package/conformance/cases/c97-roles-own-proto-key-entry-dropped/expected.json +105 -0
  5. package/conformance/cases/c97-roles-own-proto-key-entry-dropped/input.json +26 -0
  6. package/conformance/cases/c97-roles-own-proto-key-entry-dropped/meta.json +6 -0
  7. package/dist/api/auth.d.ts +1 -1
  8. package/dist/api/feedback.d.ts +3 -3
  9. package/dist/api/feedback.js +3 -2
  10. package/dist/center-refs.d.ts +1 -1
  11. package/dist/center-refs.js +1 -1
  12. package/dist/cli.d.ts +4 -1
  13. package/dist/cli.js +8 -3
  14. package/dist/config-dir-migration.d.ts +17 -1
  15. package/dist/config-dir-migration.js +89 -31
  16. package/dist/config-fns.d.ts +31 -4
  17. package/dist/config-fns.js +180 -24
  18. package/dist/config-root-documents.js +1 -1
  19. package/dist/conformance/contract-adapter.js +18 -1
  20. package/dist/conformance/warnings.d.ts +1 -1
  21. package/dist/conformance/warnings.js +8 -2
  22. package/dist/declared-capture.d.ts +1 -1
  23. package/dist/declared-capture.js +5 -1
  24. package/dist/device-lane-knobs.d.ts +57 -0
  25. package/dist/device-lane-knobs.js +127 -0
  26. package/dist/execution-lanes.d.ts +3 -1
  27. package/dist/execution-lanes.js +3 -1
  28. package/dist/fleet.d.ts +5 -5
  29. package/dist/fleet.js +4 -3
  30. package/dist/hooks-config.d.ts +47 -23
  31. package/dist/hooks-config.js +93 -134
  32. package/dist/hooks.d.ts +26 -22
  33. package/dist/hooks.js +17 -8
  34. package/dist/host-path.d.ts +9 -5
  35. package/dist/host-path.js +9 -20
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.js +2 -0
  38. package/dist/ip-address.d.ts +19 -0
  39. package/dist/ip-address.js +28 -0
  40. package/dist/loopback.d.ts +3 -11
  41. package/dist/loopback.js +11 -12
  42. package/dist/mcp-request-entry.js +4 -6
  43. package/dist/migration-receipt.d.ts +1 -1
  44. package/dist/migration-receipt.js +1 -1
  45. package/dist/one-time-migrations.d.ts +1 -1
  46. package/dist/one-time-migrations.js +257 -62
  47. package/dist/plain-json-object.d.ts +5 -8
  48. package/dist/plain-json-object.js +5 -8
  49. package/dist/read-sentences.d.ts +66 -0
  50. package/dist/read-sentences.js +85 -0
  51. package/dist/record-seat.d.ts +35 -0
  52. package/dist/record-seat.js +97 -0
  53. package/dist/reserved-member-name.d.ts +8 -3
  54. package/dist/reserved-member-name.js +10 -3
  55. package/dist/retired-envs.js +10 -0
  56. package/dist/retired-form.d.ts +2 -0
  57. package/dist/retired-form.js +4 -0
  58. package/dist/safety-merge-spec.d.ts +11 -3
  59. package/dist/safety-merge-spec.js +3 -2
  60. package/dist/types.d.ts +405 -113
  61. package/dist/types.js +135 -76
  62. package/docs/API-SURFACE.md +25 -6
  63. package/docs/CC-DIVERGENCE.md +11 -2
  64. package/docs/CONFORMANCE.md +4 -4
  65. package/docs/CONSUMER-INTEGRATION.md +185 -6
  66. package/llms-full.txt +35 -20
  67. package/llms.txt +15 -8
  68. package/package.json +7 -6
package/dist/hooks.d.ts CHANGED
@@ -14,8 +14,8 @@
14
14
  *
15
15
  * CONSUMERS
16
16
  * - service (the worker server): `TaskRequest.settings.hooks` wire face = `HooksConfig` (`./hooks-config`); the worker-side
17
- * hook-runner translates matching entries into core `TaskSpec.hooks` in-process callbacks. Single-user
18
- * gate first (requirePrincipal semantics, same as MCP injection ).
17
+ * hook-runner registers the entries of the engine-owned events on the engine's stations for them (in-process). Single-user
18
+ * gate first (requirePrincipal semantics, same as MCP injection).
19
19
  * - core (engine): per-event input/output shapes for the engine-owned events; `stoppedBy` on settle.
20
20
  * - shell (the first-party terminal client): fires the shell-owned events locally (utils/hooks.ts); its zod schemas
21
21
  * (src/entrypoints/sdk/coreSchemas.ts + src/schemas/hooks.ts) are the alignment reference for this
@@ -89,15 +89,18 @@ export type HookOwner = z.infer<typeof HookOwner>;
89
89
  * tool call refused by the engine's tool gate; the refusal is decided in the tool-execution chain, not in a dialog
90
90
  * - compaction (runs engine-side): PreCompact / PostCompact
91
91
  * - model-turn boundary (run-end is only known to the engine): Stop / StopFailure / UserPromptSubmit
92
+ * - subagent lifecycle (a delegated child starts and stops inside the engine's run): SubagentStart / SubagentStop (the reference
93
+ * implementation runs both where the child runs — the start before the child's first request, the stop as the child's Stop)
92
94
  * Everything else is shell-owned (UI / lifecycle: the permission dialog — PermissionRequest —, sessions, teams, worktrees,
93
95
  * files live in the shell). A shell that routes hooks by owner derives its table from this one (no second copy).
96
+ * The set only grows at its tail (a member's index never moves).
94
97
  *
95
98
  * FROM WHICH CONTRACT VERSION a member counts as engine-owned is data, not prose: {@link ENGINE_OWNED_HOOK_EVENT_SINCE} (one row
96
99
  * per member, a compile error when a member has no row), read through {@link engineOwnsHookEventAt} — a peer that embeds an older
97
100
  * 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
98
101
  * table of "which member joined at which version".
99
102
  */
100
- export declare const ENGINE_OWNED_HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "PostToolBatch", "PreCompact", "PostCompact", "Stop", "StopFailure", "UserPromptSubmit", "PermissionDenied"];
103
+ export declare const ENGINE_OWNED_HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "PostToolBatch", "PreCompact", "PostCompact", "Stop", "StopFailure", "UserPromptSubmit", "PermissionDenied", "SubagentStart", "SubagentStop"];
101
104
  /** owner per event — single owner; the non-owner side never fires it (dedup rule). */
102
105
  export declare const HOOK_EVENT_OWNER: Readonly<Record<HookEventName, HookOwner>>;
103
106
  /** One member of {@link ENGINE_OWNED_HOOK_EVENTS} (the events whose trigger lives in the engine half). */
@@ -110,6 +113,7 @@ export type EngineOwnedHookEvent = (typeof ENGINE_OWNED_HOOK_EVENTS)[number];
110
113
  * One row per member of {@link ENGINE_OWNED_HOOK_EVENTS}, no more, no fewer: a member added to that set without a row here, or a row for an event
111
114
  * that is not in the set, does not compile. Values were read from the release history (each tag's `src/hooks.ts`), not from memory:
112
115
  * - `PermissionDenied` — the tool gate's refusal — became engine-owned in 26.0.0 (the release before it owned nine events and listed it as shell-owned);
116
+ * - `SubagentStart` / `SubagentStop` — a delegated child's start and stop — became engine-owned in 32.0.0 (31.0.0 owned ten events and listed both as shell-owned);
113
117
  * - the other nine are `1.0.0`: the first version under this package's current name already listed them, in this order. They are older than
114
118
  * that (the set predates the rename), so `1.0.0` is the floor of what this package's name can report, not an introduction date — every peer that
115
119
  * reports a contract version of this package has it.
@@ -689,7 +693,7 @@ export declare const ElicitationHookInput: z.ZodObject<{
689
693
  }>>;
690
694
  url: z.ZodOptional<z.ZodString>;
691
695
  elicitation_id: z.ZodOptional<z.ZodString>;
692
- requested_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
696
+ requested_schema: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
693
697
  }, z.core.$strip>;
694
698
  /** After the user responds to an MCP elicitation; hooks can observe/override before it reaches the server. */
695
699
  export declare const ElicitationResultHookInput: z.ZodObject<{
@@ -711,7 +715,7 @@ export declare const ElicitationResultHookInput: z.ZodObject<{
711
715
  decline: "decline";
712
716
  cancel: "cancel";
713
717
  }>;
714
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
718
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
715
719
  }, z.core.$strip>;
716
720
  export declare const CONFIG_CHANGE_SOURCES: readonly ["user_settings", "project_settings", "local_settings", "policy_settings", "skills"];
717
721
  export declare const ConfigChangeHookInput: z.ZodObject<{
@@ -892,8 +896,8 @@ export declare const PostModelSwitchHookInput: z.ZodObject<{
892
896
  agent_id: z.ZodOptional<z.ZodString>;
893
897
  agent_type: z.ZodOptional<z.ZodString>;
894
898
  source: z.ZodEnum<{
895
- auto: "auto";
896
899
  command: "command";
900
+ auto: "auto";
897
901
  resume: "resume";
898
902
  picker: "picker";
899
903
  sdk: "sdk";
@@ -1285,7 +1289,7 @@ export declare const HookInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
1285
1289
  }>>;
1286
1290
  url: z.ZodOptional<z.ZodString>;
1287
1291
  elicitation_id: z.ZodOptional<z.ZodString>;
1288
- requested_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1292
+ requested_schema: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1289
1293
  }, z.core.$strip>, z.ZodObject<{
1290
1294
  session_id: z.ZodString;
1291
1295
  transcript_path: z.ZodString;
@@ -1305,7 +1309,7 @@ export declare const HookInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
1305
1309
  decline: "decline";
1306
1310
  cancel: "cancel";
1307
1311
  }>;
1308
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1312
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1309
1313
  }, z.core.$strip>, z.ZodObject<{
1310
1314
  session_id: z.ZodString;
1311
1315
  transcript_path: z.ZodString;
@@ -1451,8 +1455,8 @@ export declare const HookInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
1451
1455
  agent_id: z.ZodOptional<z.ZodString>;
1452
1456
  agent_type: z.ZodOptional<z.ZodString>;
1453
1457
  source: z.ZodEnum<{
1454
- auto: "auto";
1455
1458
  command: "command";
1459
+ auto: "auto";
1456
1460
  resume: "resume";
1457
1461
  picker: "picker";
1458
1462
  sdk: "sdk";
@@ -1484,7 +1488,7 @@ export type HookDecision = z.infer<typeof HookDecision>;
1484
1488
  /** PermissionRequest hook decision — mirrors CC PermissionResult (allow may rewrite input/permissions). */
1485
1489
  export declare const HookPermissionRequestDecision: z.ZodUnion<readonly [z.ZodObject<{
1486
1490
  behavior: z.ZodLiteral<"allow">;
1487
- updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1491
+ updatedInput: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1488
1492
  updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1489
1493
  type: z.ZodLiteral<"addRules">;
1490
1494
  rules: z.ZodArray<z.ZodObject<{
@@ -1591,7 +1595,7 @@ export declare const HookSpecificOutput: z.ZodUnion<readonly [z.ZodObject<{
1591
1595
  deny: "deny";
1592
1596
  }>>;
1593
1597
  permissionDecisionReason: z.ZodOptional<z.ZodString>;
1594
- updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1598
+ updatedInput: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1595
1599
  additionalContext: z.ZodOptional<z.ZodString>;
1596
1600
  }, z.core.$strip>, z.ZodObject<{
1597
1601
  hookEventName: z.ZodLiteral<"PostToolUse">;
@@ -1624,7 +1628,7 @@ export declare const HookSpecificOutput: z.ZodUnion<readonly [z.ZodObject<{
1624
1628
  hookEventName: z.ZodLiteral<"PermissionRequest">;
1625
1629
  decision: z.ZodUnion<readonly [z.ZodObject<{
1626
1630
  behavior: z.ZodLiteral<"allow">;
1627
- updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1631
+ updatedInput: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1628
1632
  updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1629
1633
  type: z.ZodLiteral<"addRules">;
1630
1634
  rules: z.ZodArray<z.ZodObject<{
@@ -1728,7 +1732,7 @@ export declare const HookSpecificOutput: z.ZodUnion<readonly [z.ZodObject<{
1728
1732
  decline: "decline";
1729
1733
  cancel: "cancel";
1730
1734
  }>>;
1731
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1735
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1732
1736
  }, z.core.$strip>, z.ZodObject<{
1733
1737
  hookEventName: z.ZodLiteral<"ElicitationResult">;
1734
1738
  action: z.ZodOptional<z.ZodEnum<{
@@ -1736,7 +1740,7 @@ export declare const HookSpecificOutput: z.ZodUnion<readonly [z.ZodObject<{
1736
1740
  decline: "decline";
1737
1741
  cancel: "cancel";
1738
1742
  }>>;
1739
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1743
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1740
1744
  }, z.core.$strip>, z.ZodObject<{
1741
1745
  hookEventName: z.ZodLiteral<"CwdChanged">;
1742
1746
  watchPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -1789,7 +1793,7 @@ export declare const SyncHookOutput: z.ZodObject<{
1789
1793
  deny: "deny";
1790
1794
  }>>;
1791
1795
  permissionDecisionReason: z.ZodOptional<z.ZodString>;
1792
- updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1796
+ updatedInput: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1793
1797
  additionalContext: z.ZodOptional<z.ZodString>;
1794
1798
  }, z.core.$strip>, z.ZodObject<{
1795
1799
  hookEventName: z.ZodLiteral<"PostToolUse">;
@@ -1822,7 +1826,7 @@ export declare const SyncHookOutput: z.ZodObject<{
1822
1826
  hookEventName: z.ZodLiteral<"PermissionRequest">;
1823
1827
  decision: z.ZodUnion<readonly [z.ZodObject<{
1824
1828
  behavior: z.ZodLiteral<"allow">;
1825
- updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1829
+ updatedInput: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1826
1830
  updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1827
1831
  type: z.ZodLiteral<"addRules">;
1828
1832
  rules: z.ZodArray<z.ZodObject<{
@@ -1926,7 +1930,7 @@ export declare const SyncHookOutput: z.ZodObject<{
1926
1930
  decline: "decline";
1927
1931
  cancel: "cancel";
1928
1932
  }>>;
1929
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1933
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1930
1934
  }, z.core.$strip>, z.ZodObject<{
1931
1935
  hookEventName: z.ZodLiteral<"ElicitationResult">;
1932
1936
  action: z.ZodOptional<z.ZodEnum<{
@@ -1934,7 +1938,7 @@ export declare const SyncHookOutput: z.ZodObject<{
1934
1938
  decline: "decline";
1935
1939
  cancel: "cancel";
1936
1940
  }>>;
1937
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1941
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1938
1942
  }, z.core.$strip>, z.ZodObject<{
1939
1943
  hookEventName: z.ZodLiteral<"CwdChanged">;
1940
1944
  watchPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -1985,7 +1989,7 @@ export declare const HookOutput: z.ZodUnion<readonly [z.ZodObject<{
1985
1989
  deny: "deny";
1986
1990
  }>>;
1987
1991
  permissionDecisionReason: z.ZodOptional<z.ZodString>;
1988
- updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1992
+ updatedInput: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
1989
1993
  additionalContext: z.ZodOptional<z.ZodString>;
1990
1994
  }, z.core.$strip>, z.ZodObject<{
1991
1995
  hookEventName: z.ZodLiteral<"PostToolUse">;
@@ -2018,7 +2022,7 @@ export declare const HookOutput: z.ZodUnion<readonly [z.ZodObject<{
2018
2022
  hookEventName: z.ZodLiteral<"PermissionRequest">;
2019
2023
  decision: z.ZodUnion<readonly [z.ZodObject<{
2020
2024
  behavior: z.ZodLiteral<"allow">;
2021
- updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
2025
+ updatedInput: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
2022
2026
  updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
2023
2027
  type: z.ZodLiteral<"addRules">;
2024
2028
  rules: z.ZodArray<z.ZodObject<{
@@ -2122,7 +2126,7 @@ export declare const HookOutput: z.ZodUnion<readonly [z.ZodObject<{
2122
2126
  decline: "decline";
2123
2127
  cancel: "cancel";
2124
2128
  }>>;
2125
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
2129
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
2126
2130
  }, z.core.$strip>, z.ZodObject<{
2127
2131
  hookEventName: z.ZodLiteral<"ElicitationResult">;
2128
2132
  action: z.ZodOptional<z.ZodEnum<{
@@ -2130,7 +2134,7 @@ export declare const HookOutput: z.ZodUnion<readonly [z.ZodObject<{
2130
2134
  decline: "decline";
2131
2135
  cancel: "cancel";
2132
2136
  }>>;
2133
- content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
2137
+ content: z.ZodOptional<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>>>;
2134
2138
  }, z.core.$strip>, z.ZodObject<{
2135
2139
  hookEventName: z.ZodLiteral<"CwdChanged">;
2136
2140
  watchPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
package/dist/hooks.js CHANGED
@@ -14,8 +14,8 @@
14
14
  *
15
15
  * CONSUMERS
16
16
  * - service (the worker server): `TaskRequest.settings.hooks` wire face = `HooksConfig` (`./hooks-config`); the worker-side
17
- * hook-runner translates matching entries into core `TaskSpec.hooks` in-process callbacks. Single-user
18
- * gate first (requirePrincipal semantics, same as MCP injection ).
17
+ * hook-runner registers the entries of the engine-owned events on the engine's stations for them (in-process). Single-user
18
+ * gate first (requirePrincipal semantics, same as MCP injection).
19
19
  * - core (engine): per-event input/output shapes for the engine-owned events; `stoppedBy` on settle.
20
20
  * - shell (the first-party terminal client): fires the shell-owned events locally (utils/hooks.ts); its zod schemas
21
21
  * (src/entrypoints/sdk/coreSchemas.ts + src/schemas/hooks.ts) are the alignment reference for this
@@ -43,6 +43,7 @@ import { z } from "zod";
43
43
  import { HOOK_EVENTS } from "./hooks-config.js";
44
44
  import { INTEGER } from "./integer.js";
45
45
  import { deepFreeze } from "./deep-freeze.js";
46
+ import { recordOf } from "./record-seat.js";
46
47
  export * from "./hooks-config.js";
47
48
  // ── event set ──────────────────────────────────────────────────────────────────────────────────────────
48
49
  // The ONE closed set of hook event names is {@link HOOK_EVENTS} (`./hooks-config`, re-exported above; drift-gated against CC).
@@ -56,8 +57,11 @@ export const HookOwner = z.enum(["engine", "shell"]);
56
57
  * tool call refused by the engine's tool gate; the refusal is decided in the tool-execution chain, not in a dialog
57
58
  * - compaction (runs engine-side): PreCompact / PostCompact
58
59
  * - model-turn boundary (run-end is only known to the engine): Stop / StopFailure / UserPromptSubmit
60
+ * - subagent lifecycle (a delegated child starts and stops inside the engine's run): SubagentStart / SubagentStop (the reference
61
+ * implementation runs both where the child runs — the start before the child's first request, the stop as the child's Stop)
59
62
  * Everything else is shell-owned (UI / lifecycle: the permission dialog — PermissionRequest —, sessions, teams, worktrees,
60
63
  * files live in the shell). A shell that routes hooks by owner derives its table from this one (no second copy).
64
+ * The set only grows at its tail (a member's index never moves).
61
65
  *
62
66
  * FROM WHICH CONTRACT VERSION a member counts as engine-owned is data, not prose: {@link ENGINE_OWNED_HOOK_EVENT_SINCE} (one row
63
67
  * per member, a compile error when a member has no row), read through {@link engineOwnsHookEventAt} — a peer that embeds an older
@@ -75,6 +79,8 @@ export const ENGINE_OWNED_HOOK_EVENTS = deepFreeze([
75
79
  "StopFailure",
76
80
  "UserPromptSubmit",
77
81
  "PermissionDenied",
82
+ "SubagentStart",
83
+ "SubagentStop",
78
84
  ]);
79
85
  /** owner per event — single owner; the non-owner side never fires it (dedup rule). */
80
86
  export const HOOK_EVENT_OWNER = deepFreeze(Object.fromEntries(HOOK_EVENTS.map((e) => [e, ENGINE_OWNED_HOOK_EVENTS.includes(e) ? "engine" : "shell"])));
@@ -86,6 +92,7 @@ export const HOOK_EVENT_OWNER = deepFreeze(Object.fromEntries(HOOK_EVENTS.map((e
86
92
  * One row per member of {@link ENGINE_OWNED_HOOK_EVENTS}, no more, no fewer: a member added to that set without a row here, or a row for an event
87
93
  * that is not in the set, does not compile. Values were read from the release history (each tag's `src/hooks.ts`), not from memory:
88
94
  * - `PermissionDenied` — the tool gate's refusal — became engine-owned in 26.0.0 (the release before it owned nine events and listed it as shell-owned);
95
+ * - `SubagentStart` / `SubagentStop` — a delegated child's start and stop — became engine-owned in 32.0.0 (31.0.0 owned ten events and listed both as shell-owned);
89
96
  * - the other nine are `1.0.0`: the first version under this package's current name already listed them, in this order. They are older than
90
97
  * that (the set predates the rename), so `1.0.0` is the floor of what this package's name can report, not an introduction date — every peer that
91
98
  * reports a contract version of this package has it.
@@ -103,6 +110,8 @@ export const ENGINE_OWNED_HOOK_EVENT_SINCE = deepFreeze({
103
110
  StopFailure: "1.0.0",
104
111
  UserPromptSubmit: "1.0.0",
105
112
  PermissionDenied: "26.0.0",
113
+ SubagentStart: "32.0.0",
114
+ SubagentStop: "32.0.0",
106
115
  });
107
116
  /** A complete `x.y.z`: three decimal numbers, no leading zeros (so numeric order is digit-count order, then digits), no pre-release / build part, no prefix. */
108
117
  const CONTRACT_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
@@ -378,7 +387,7 @@ export const ElicitationHookInput = BaseHookInput.extend({
378
387
  mode: z.enum(["form", "url"]).optional(),
379
388
  url: z.string().optional(),
380
389
  elicitation_id: z.string().optional(),
381
- requested_schema: z.record(z.string(), z.unknown()).optional(),
390
+ requested_schema: recordOf(z.string(), z.unknown()).optional(),
382
391
  });
383
392
  /** After the user responds to an MCP elicitation; hooks can observe/override before it reaches the server. */
384
393
  export const ElicitationResultHookInput = BaseHookInput.extend({
@@ -387,7 +396,7 @@ export const ElicitationResultHookInput = BaseHookInput.extend({
387
396
  elicitation_id: z.string().optional(),
388
397
  mode: z.enum(["form", "url"]).optional(),
389
398
  action: z.enum(["accept", "decline", "cancel"]),
390
- content: z.record(z.string(), z.unknown()).optional(),
399
+ content: recordOf(z.string(), z.unknown()).optional(),
391
400
  });
392
401
  export const CONFIG_CHANGE_SOURCES = deepFreeze(["user_settings", "project_settings", "local_settings", "policy_settings", "skills"]);
393
402
  export const ConfigChangeHookInput = BaseHookInput.extend({
@@ -544,7 +553,7 @@ export const HookDecision = z.enum(["approve", "block"]);
544
553
  export const HookPermissionRequestDecision = z.union([
545
554
  z.object({
546
555
  behavior: z.literal("allow"),
547
- updatedInput: z.record(z.string(), z.unknown()).optional(),
556
+ updatedInput: recordOf(z.string(), z.unknown()).optional(),
548
557
  updatedPermissions: z.array(PermissionUpdate).optional(),
549
558
  }),
550
559
  z.object({
@@ -561,7 +570,7 @@ export const HookSpecificOutput = z.union([
561
570
  permissionDecision: PermissionBehavior.optional(),
562
571
  permissionDecisionReason: z.string().optional(),
563
572
  /** Hook-rewritten tool input (CC updatedInput). */
564
- updatedInput: z.record(z.string(), z.unknown()).optional(),
573
+ updatedInput: recordOf(z.string(), z.unknown()).optional(),
565
574
  additionalContext: z.string().optional(),
566
575
  }),
567
576
  z.object({
@@ -587,12 +596,12 @@ export const HookSpecificOutput = z.union([
587
596
  z.object({
588
597
  hookEventName: z.literal("Elicitation"),
589
598
  action: z.enum(["accept", "decline", "cancel"]).optional(),
590
- content: z.record(z.string(), z.unknown()).optional(),
599
+ content: recordOf(z.string(), z.unknown()).optional(),
591
600
  }),
592
601
  z.object({
593
602
  hookEventName: z.literal("ElicitationResult"),
594
603
  action: z.enum(["accept", "decline", "cancel"]).optional(),
595
- content: z.record(z.string(), z.unknown()).optional(),
604
+ content: recordOf(z.string(), z.unknown()).optional(),
596
605
  }),
597
606
  z.object({ hookEventName: z.literal("CwdChanged"), watchPaths: z.array(z.string()).optional() }),
598
607
  z.object({ hookEventName: z.literal("FileChanged"), watchPaths: z.array(z.string()).optional() }),
@@ -1,10 +1,14 @@
1
1
  /**
2
- * 叶子模块(纯、浏览器安全):**一只**「主机绝对路径」形判 —— 任务请求的 `cwd`(服务器受理时判)与项目登记里 `folder` / `file`
3
- * 条目的值读同一只,不各写一份。只判形,不判存在(不碰文件系统)。
2
+ * 叶子模块(纯、浏览器安全):「主机绝对路径」形判的**一只**判官住在引擎原语包 `@sema-agent/primitives`(`isAbsoluteHostPath`、长度上界 `ABSOLUTE_HOST_PATH_MAX`),
3
+ * 本模块把它们**转出**(同一个函数对象、同一个常量,不是行为相同的另一份)并给它一个 zod 座位 —— 任务请求的 `cwd`(服务器受理时判)与项目登记里
4
+ * `folder` / `file` 条目的值读同一只,引擎的宿主文本也读同一只。只判形,不判存在(不碰文件系统)。
5
+ *
6
+ * 律(原语包的判官,这里不另写):字符串、非空、≤ {@link ABSOLUTE_HOST_PATH_MAX}、不含 NUL、三族绝对形之一(posix `/` 开头 · Windows 盘符 `X:\` / `X:/` ·
7
+ * UNC `\\server\share`)、没有 `..` 段(`/` 与 `\` 都算分隔符)。裸 `X:` 与 `X:rel` 不绝对;`\\server` 不够;Windows 设备命名空间 `\\.\` 与长路径前缀 `\\?\` 不是主机路径。
8
+ * 宿主是哪一族由壳决定,读方只拿「形合法」这一个事实,怎么解析归宿主那一族。
4
9
  */
5
10
  import { z } from "zod";
6
- /** 一条主机绝对路径的长度上界(字符数)。 */
7
- export declare const ABSOLUTE_HOST_PATH_MAX = 4096;
8
- export declare function isAbsoluteHostPath(p: unknown): p is string;
11
+ import { ABSOLUTE_HOST_PATH_MAX, isAbsoluteHostPath } from "@sema-agent/primitives";
12
+ export { ABSOLUTE_HOST_PATH_MAX, isAbsoluteHostPath };
9
13
  /** {@link isAbsoluteHostPath} 的 zod 座位(一条 issue,定句)。 */
10
14
  export declare const AbsoluteHostPath: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
package/dist/host-path.js CHANGED
@@ -1,27 +1,16 @@
1
1
  /**
2
- * 叶子模块(纯、浏览器安全):**一只**「主机绝对路径」形判 —— 任务请求的 `cwd`(服务器受理时判)与项目登记里 `folder` / `file`
3
- * 条目的值读同一只,不各写一份。只判形,不判存在(不碰文件系统)。
2
+ * 叶子模块(纯、浏览器安全):「主机绝对路径」形判的**一只**判官住在引擎原语包 `@sema-agent/primitives`(`isAbsoluteHostPath`、长度上界 `ABSOLUTE_HOST_PATH_MAX`),
3
+ * 本模块把它们**转出**(同一个函数对象、同一个常量,不是行为相同的另一份)并给它一个 zod 座位 —— 任务请求的 `cwd`(服务器受理时判)与项目登记里
4
+ * `folder` / `file` 条目的值读同一只,引擎的宿主文本也读同一只。只判形,不判存在(不碰文件系统)。
5
+ *
6
+ * 律(原语包的判官,这里不另写):字符串、非空、≤ {@link ABSOLUTE_HOST_PATH_MAX}、不含 NUL、三族绝对形之一(posix `/` 开头 · Windows 盘符 `X:\` / `X:/` ·
7
+ * UNC `\\server\share`)、没有 `..` 段(`/` 与 `\` 都算分隔符)。裸 `X:` 与 `X:rel` 不绝对;`\\server` 不够;Windows 设备命名空间 `\\.\` 与长路径前缀 `\\?\` 不是主机路径。
8
+ * 宿主是哪一族由壳决定,读方只拿「形合法」这一个事实,怎么解析归宿主那一族。
4
9
  */
5
10
  import { z } from "zod";
11
+ import { ABSOLUTE_HOST_PATH_MAX, isAbsoluteHostPath } from "@sema-agent/primitives";
6
12
  import { buildQuotedIssue, fixed } from "./quoted-issue.js";
7
- /** 一条主机绝对路径的长度上界(字符数)。 */
8
- export const ABSOLUTE_HOST_PATH_MAX = 4096;
9
- /**
10
- * `p` 是不是一条形上合法的**主机绝对路径**:字符串、非空、≤ {@link ABSOLUTE_HOST_PATH_MAX}、不含 NUL、三族绝对形之一(posix `/` 开头 · Windows 盘符 · UNC)、没有 `..` 段
11
- * (`/` 与 `\` 都算分隔符 —— `path.isAbsolute` 是语法判,`/a/../../etc` 也「绝对」,而读方 `path.resolve` 会把它解到别处;拒掉它,读到的就是写下的那一条)。
12
- *
13
- * 宿主是哪一族由壳决定(大脑在云、手在本机:Windows 壳按 CC 同形送 `C:\…`),所以三族绝对形同一只判官、同一条律:
14
- * posix(`/` 开头)· Windows 盘符(`X:\` / `X:/`;裸 `X:` 与 `X:rel` 不绝对)· UNC(`\\server\share`;`\\server` 不够)。
15
- * 读方只拿「形合法」这一个事实,怎么解析归宿主那一族 —— 这里不碰文件系统、不做族内归一。
16
- */
17
- const WIN_DRIVE_ABSOLUTE = /^[A-Za-z]:[\\/]/;
18
- // UNC 首段是主机名(字母数字起头,其后字母数字 . _ -):Windows 设备命名空间前缀 `\\.\` 与长路径前缀 `\\?\` 都不是主机路径,一律拒。
19
- const WIN_UNC_ABSOLUTE = /^\\\\[A-Za-z0-9][A-Za-z0-9._-]*[\\/][^\\/]+/;
20
- export function isAbsoluteHostPath(p) {
21
- return (typeof p === "string" && p.length > 0 && p.length <= ABSOLUTE_HOST_PATH_MAX && !p.includes("\0") &&
22
- (p.startsWith("/") || WIN_DRIVE_ABSOLUTE.test(p) || WIN_UNC_ABSOLUTE.test(p)) &&
23
- !p.split(/[/\\]/).includes(".."));
24
- }
13
+ export { ABSOLUTE_HOST_PATH_MAX, isAbsoluteHostPath };
25
14
  /** {@link isAbsoluteHostPath} 的 zod 座位(一条 issue,定句)。 */
26
15
  export const AbsoluteHostPath = z
27
16
  .string()
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export * from "./execution-lanes.js";
7
7
  export * from "./config-document-refusal.js";
8
8
  export * from "./url-shape.js";
9
9
  export * from "./device-relay.js";
10
+ export * from "./device-lane-knobs.js";
11
+ export { ipFamilyOf } from "./ip-address.js";
10
12
  export * from "./url-credential.js";
11
13
  export * from "./default-model.js";
12
14
  export { catalogManagesModelPlane, enabledEntryCount, isExplicitlyDisabledEntry } from "./catalog-manages.js";
package/dist/index.js CHANGED
@@ -7,6 +7,8 @@ export * from "./execution-lanes.js"; // 7.0.0 M-R2: the ONE lane / store vocabu
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 / too_deep / retired_domain; ConfigDocumentRefusal { document, reason, error }; its file-level arm carries an optional ioKind on io refusals — CONFIG_DOCUMENT_IO_KINDS = dangling_symlink / read_error, 31.1.0) — the reading is `FileConfigStore.read()` 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
10
+ export * from "./device-lane-knobs.js"; // THE value grammar of the device lane's two optional knobs (readDeviceMaxPreAuthPerRemote / readDeviceTrustedProxyCidrs → readings, their rule sentences and closed flaw sets), pure/browser-safe
11
+ export { ipFamilyOf } from "./ip-address.js"; // the package's one IP-address grammar (a zero-import leaf: the device lane's CIDR list and isLoopbackRouteHost read it), pure/browser-safe
10
12
  export * from "./url-credential.js"; // 14.5.0: THE "does this URL carry a credential" judge (findUrlCredential / findUrlUserinfo / URL_CREDENTIAL_REASONS / CREDENTIAL_PARAM_NAMES …), pure/browser-safe
11
13
  export * from "./default-model.js"; // 11.0.0: THE catalog-default resolver (roles.default → active tier ladder → fallback), pure/browser-safe
12
14
  export { catalogManagesModelPlane, enabledEntryCount, isExplicitlyDisabledEntry } from "./catalog-manages.js"; // THE "does this models document manage the model plane" judge (raw half: at least one entry not explicitly disabled) + the log count it is derived from + THE "is this one entry explicitly disabled" predicate they (and every per-entry consumer) read (the three-state `enabled` reading stays package-private), pure/browser-safe
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 包内私有叶子模块(零 import,浏览器安全:只用全局 `URL`;不进 `package.json` 的 exports,包根经它转出 `ipFamilyOf`):**什么是一个 IP 地址**的唯一文法。
3
+ *
4
+ * IPv4 = 四段十进制 0–255、不带前导零(与 Node `net.isIPv4` 同一个接受集)。IPv6 = WHATWG URL 的 IPv6 主机解析器认的文本 —— 先限字符集(十六进制位、`:`、`.`),
5
+ * 再交解析器:解析器会先删掉串里的制表符与换行、读到 `]` 之后的端口 / 路径 / 查询 / 片段就停、把 `@` 之前算作用户信息 —— 限了字符集,这几件就碰不到,
6
+ * 认下的就是写下的那一个地址。不收 zone id(`%…`)、方括号、端口、两侧空白。
7
+ *
8
+ * 读者(都读这一份,不另写正则或另包一次 URL):device 车道的 CIDR 名单(`./device-lane-knobs`)· 连接路由的「本机」(`./loopback`:它自己的宽读法 ——
9
+ * 两侧空白、大小写、方括号、FQDN 尾点、`localhost` —— 留在它那一层,剥完交这里判)。
10
+ */
11
+ /** 一段文本读成的 IP 地址:族 + 规范文本(IPv4 原样;IPv6 = WHATWG 压缩小写形,不带方括号)。 */
12
+ export interface IpAddress {
13
+ readonly family: 4 | 6;
14
+ readonly text: string;
15
+ }
16
+ /** 读一段文本:是 IP 地址 ⇒ 族与规范文本;不是(含带 zone id、带端口、带方括号、两侧有空白、字符集外的字符)⇒ `undefined`。 */
17
+ export declare function readIpAddress(text: string): IpAddress | undefined;
18
+ /** 一段文本是哪一族的 IP 地址:IPv4 ⇒ `4`,IPv6 ⇒ `6`,都不是 ⇒ `undefined`({@link readIpAddress} 的族)。 */
19
+ export declare function ipFamilyOf(text: string): 4 | 6 | undefined;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 包内私有叶子模块(零 import,浏览器安全:只用全局 `URL`;不进 `package.json` 的 exports,包根经它转出 `ipFamilyOf`):**什么是一个 IP 地址**的唯一文法。
3
+ *
4
+ * IPv4 = 四段十进制 0–255、不带前导零(与 Node `net.isIPv4` 同一个接受集)。IPv6 = WHATWG URL 的 IPv6 主机解析器认的文本 —— 先限字符集(十六进制位、`:`、`.`),
5
+ * 再交解析器:解析器会先删掉串里的制表符与换行、读到 `]` 之后的端口 / 路径 / 查询 / 片段就停、把 `@` 之前算作用户信息 —— 限了字符集,这几件就碰不到,
6
+ * 认下的就是写下的那一个地址。不收 zone id(`%…`)、方括号、端口、两侧空白。
7
+ *
8
+ * 读者(都读这一份,不另写正则或另包一次 URL):device 车道的 CIDR 名单(`./device-lane-knobs`)· 连接路由的「本机」(`./loopback`:它自己的宽读法 ——
9
+ * 两侧空白、大小写、方括号、FQDN 尾点、`localhost` —— 留在它那一层,剥完交这里判)。
10
+ */
11
+ /** 一段 IPv4 十进制(0–255,不带前导零)。 */
12
+ const IPV4_OCTET = "(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])";
13
+ const IPV4 = new RegExp(`^${IPV4_OCTET}(?:\\.${IPV4_OCTET}){3}$`);
14
+ /** 交给 IPv6 解析器之前的字符集:只让十六进制位、冒号与点进去。 */
15
+ const IPV6_TEXT = /^[0-9A-Fa-f:.]+$/;
16
+ /** 读一段文本:是 IP 地址 ⇒ 族与规范文本;不是(含带 zone id、带端口、带方括号、两侧有空白、字符集外的字符)⇒ `undefined`。 */
17
+ export function readIpAddress(text) {
18
+ if (IPV4.test(text))
19
+ return { family: 4, text };
20
+ if (!text.includes(":") || !IPV6_TEXT.test(text))
21
+ return undefined;
22
+ const href = `http://[${text}]/`;
23
+ return URL.canParse(href) ? { family: 6, text: new URL(href).hostname.slice(1, -1) } : undefined;
24
+ }
25
+ /** 一段文本是哪一族的 IP 地址:IPv4 ⇒ `4`,IPv6 ⇒ `6`,都不是 ⇒ `undefined`({@link readIpAddress} 的族)。 */
26
+ export function ipFamilyOf(text) {
27
+ return readIpAddress(text)?.family;
28
+ }
@@ -1,13 +1,3 @@
1
- /**
2
- * 「这是本机吗」—— **两个**问题,各一只具名谓词(11.0.0)。读者按自己问的是哪一个来选,不再各写一份字面表。
3
- *
4
- * · **鉴权放宽**({@link isLoopbackAuthHost},窄):要不要因为对端是本机而少要一样东西(免登录、允许明文 http 带凭据)。
5
- * 窄是安全方向 —— 认少了只会多要一次凭据;认多了就是把放宽送给一台不是本机的主机。只认字面。
6
- * · **连接路由**({@link isLoopbackRouteHost},宽):这条连接会不会落在本机(要不要绕开代理直连)。宽是正确方向 ——
7
- * 认少了,本机目标被送进代理,代理那头的 127.0.0.1 是代理自己。
8
- *
9
- * 两只都是纯函数,入参是 `URL.hostname`、socket 地址或裸主机名;不用 `node:net`(浏览器 / 客户端包可用)。
10
- */
11
1
  /**
12
2
  * 鉴权放宽问的「本机」:只认四个字面 `127.0.0.1` / `localhost` / `::1` / `[::1]`(`URL.hostname` 对 IPv6 带方括号,两写法都收),
13
3
  * 外加 socket 地址形 `::ffff:127.0.0.1`(双栈监听上 IPv4 回环连接的 `remoteAddress`)。大小写变体、尾点、127/8 的其它地址、
@@ -19,7 +9,9 @@ export declare function isLoopbackAuthHost(host: string): boolean;
19
9
  * · `localhost`(含 FQDN 尾点 `localhost.`);
20
10
  * · IPv4 `127.0.0.0/8` 整段与未指定地址 `0.0.0.0`(作为目的地址它在本机就是本机);
21
11
  * · IPv6 `::1`(带不带方括号、全写都算)与未指定地址 `::`;
22
- * · IPv4 映射 IPv6 的回环段 `::ffff:127.x.x.x` 与 `::ffff:0.0.0.0`(WHATWG 把它们规范成 `::ffff:7f00:1` 形,按规范形判)。
12
+ * · IPv4 映射 IPv6 的回环段 `::ffff:127.x.x.x` 与 `::ffff:0.0.0.0`(地址文法把它们规范成 `::ffff:7f00:1` 形,按规范形判)。
13
+ * 宽读法只在这一层:两侧空白、大小写、一对方括号、FQDN 尾点剥掉之后,地址交包里唯一那份地址文法判(`./ip-address`)—— 剥完还带别的字符
14
+ * (串里的制表符 / 换行、`]` 之后的端口 / 路径 / 查询、`@` 之前的用户信息……)就不是一个地址。
23
15
  * 刻意**不**认 `*.localhost` 子域(能否落到本机取决于系统解析器,不是地址本身的事实)、带区域 id 的 IPv6、简写 IPv4(`127.1`)。
24
16
  * 认不出的写法一律答 `false`(按远端处置)。
25
17
  */
package/dist/loopback.js CHANGED
@@ -6,8 +6,9 @@
6
6
  * · **连接路由**({@link isLoopbackRouteHost},宽):这条连接会不会落在本机(要不要绕开代理直连)。宽是正确方向 ——
7
7
  * 认少了,本机目标被送进代理,代理那头的 127.0.0.1 是代理自己。
8
8
  *
9
- * 两只都是纯函数,入参是 `URL.hostname`、socket 地址或裸主机名;不用 `node:net`(浏览器 / 客户端包可用)。
9
+ * 两只都是纯函数,入参是 `URL.hostname`、socket 地址或裸主机名;不用 `node:net`(浏览器 / 客户端包可用)。连接路由读包里唯一那份地址文法(`./ip-address`)。
10
10
  */
11
+ import { readIpAddress } from "./ip-address.js";
11
12
  /**
12
13
  * 鉴权放宽问的「本机」:只认四个字面 `127.0.0.1` / `localhost` / `::1` / `[::1]`(`URL.hostname` 对 IPv6 带方括号,两写法都收),
13
14
  * 外加 socket 地址形 `::ffff:127.0.0.1`(双栈监听上 IPv4 回环连接的 `remoteAddress`)。大小写变体、尾点、127/8 的其它地址、
@@ -16,14 +17,14 @@
16
17
  export function isLoopbackAuthHost(host) {
17
18
  return host === "127.0.0.1" || host === "localhost" || host === "::1" || host === "[::1]" || host === "::ffff:127.0.0.1";
18
19
  }
19
- /** 点分十进制 IPv4(每段 0–255、无前导零)—— 与 Node `net.isIPv4` 同一个接受集。 */
20
- const DOTTED_IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
21
20
  /**
22
21
  * 连接路由问的「本机」(大小写不敏感):
23
22
  * · `localhost`(含 FQDN 尾点 `localhost.`);
24
23
  * · IPv4 `127.0.0.0/8` 整段与未指定地址 `0.0.0.0`(作为目的地址它在本机就是本机);
25
24
  * · IPv6 `::1`(带不带方括号、全写都算)与未指定地址 `::`;
26
- * · IPv4 映射 IPv6 的回环段 `::ffff:127.x.x.x` 与 `::ffff:0.0.0.0`(WHATWG 把它们规范成 `::ffff:7f00:1` 形,按规范形判)。
25
+ * · IPv4 映射 IPv6 的回环段 `::ffff:127.x.x.x` 与 `::ffff:0.0.0.0`(地址文法把它们规范成 `::ffff:7f00:1` 形,按规范形判)。
26
+ * 宽读法只在这一层:两侧空白、大小写、一对方括号、FQDN 尾点剥掉之后,地址交包里唯一那份地址文法判(`./ip-address`)—— 剥完还带别的字符
27
+ * (串里的制表符 / 换行、`]` 之后的端口 / 路径 / 查询、`@` 之前的用户信息……)就不是一个地址。
27
28
  * 刻意**不**认 `*.localhost` 子域(能否落到本机取决于系统解析器,不是地址本身的事实)、带区域 id 的 IPv6、简写 IPv4(`127.1`)。
28
29
  * 认不出的写法一律答 `false`(按远端处置)。
29
30
  */
@@ -34,15 +35,13 @@ export function isLoopbackRouteHost(host) {
34
35
  h = h.replace(/\.+$/, ""); // FQDN 尾点:`localhost.` / `127.0.0.1.` 与不带点的是同一个目的地
35
36
  if (h === "localhost")
36
37
  return true;
37
- if (DOTTED_IPV4.test(h))
38
- return h.startsWith("127.") || h === "0.0.0.0";
39
- if (!h.includes(":"))
40
- return false;
41
- // IPv6:交给 WHATWG 规范化(全写 / 前导零 / 点分映射形收成同一种压缩写法)再比;解析不动(区域 id 等)⇒ 按远端处置。
42
- const bracketed = `http://[${h}]/`;
43
- if (!URL.canParse(bracketed))
38
+ const ip = readIpAddress(h);
39
+ if (ip === undefined)
44
40
  return false;
45
- const canon = new URL(bracketed).hostname.slice(1, -1);
41
+ if (ip.family === 4)
42
+ return h.startsWith("127.") || h === "0.0.0.0";
43
+ // IPv6:按规范形比(全写 / 前导零 / 点分映射形收成同一种压缩写法)。
44
+ const canon = ip.text;
46
45
  if (canon === "::1" || canon === "::")
47
46
  return true;
48
47
  const mapped = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/.exec(canon);
@@ -33,7 +33,7 @@ import { MCP_CONTENT_ORIGINS } from "./types.js";
33
33
  import { RESERVED_MCP_SERVER_NAME_REASON, isReservedMcpServerName } from "./mcp-server-name.js";
34
34
  import { startsWithHttpScheme } from "./url-shape.js";
35
35
  import { TOOL_WIRE_NAME_MAX_CHARS, hasEdgeWhitespace, isUsableWireName } from "./wire-name.js";
36
- import { isReservedMemberName } from "./reserved-member-name.js";
36
+ import { isReservedMemberName, reservedMemberSentence } from "./reserved-member-name.js";
37
37
  import { deepFreeze } from "./deep-freeze.js";
38
38
  import { CREDENTIAL_REF_TRUST, readCredentialRef } from "@sema-agent/primitives";
39
39
  import { retiredFormSentence } from "./retired-form.js";
@@ -116,7 +116,7 @@ function quotedCallerText(text) {
116
116
  // ── 申报名的线长界 ──────────────────────────────────────────────────────────────────────────────────
117
117
  // 判据住在零依赖叶子 `./wire-name`(18.0.0 搬过去:`./types` 的 `a2a` 对端名也问它,而本模块引 `./types` —— 留在这里会成环);公开名照旧经本模块转出,同一个函数对象。
118
118
  export { TOOL_WIRE_NAME_MAX_CHARS, isUsableWireName } from "./wire-name.js";
119
- export { RESERVED_MEMBER_NAMES, isReservedMemberName } from "./reserved-member-name.js"; // 18.0.0: the one reserved-member-name table (schema guard · this reader · the center-refs resolver)
119
+ export { RESERVED_MEMBER_NAMES, isReservedMemberName } from "./reserved-member-name.js"; // 18.0.0: the one reserved-member-name table (every record seat's guard · this reader · the center-refs resolver)
120
120
  /**
121
121
  * 坏名的**可打印**摘要(进拒句 / 告警元数据):种类、`empty`,或引号形的回显加原因 —— 绝不把任意长度的申报串原样回显。回显口径见 {@link quotedCallerText}
122
122
  * (剥控制与双向字符、截 64 字)。串的原因是:超界 ⇒ `N chars > 128`(N 是送来的原长度,不是剥完的);首尾带空白 ⇒ `leading or trailing whitespace`
@@ -357,8 +357,6 @@ function snapshotTransport(tr) {
357
357
  return { ok: true, value: { kind: "other", value: kind.value } };
358
358
  }
359
359
  // ── 「名 → 串」记录的读法(`env` / `headers`)────────────────────────────────────────────────────────
360
- /** 保留成员名的原因句(一个名一句;名字取自那一张表 {@link RESERVED_MEMBER_NAMES})。 */
361
- const reservedMemberFault = (name) => `no member of a declaration may be named "${name}"`;
362
360
  /**
363
361
  * 「名 → 串」记录读不交(或交时点名保留名)的**原因词**,闭集,三个词、一张表:
364
362
  * 整张一词(`not_plain_record`)· 成员级一词(`member_not_string`:值读成了别的种类,或读成员时抛了 —— 句子分说)· 名字级一词(`member_name_reserved`)。
@@ -421,7 +419,7 @@ export function readPlainStringRecord(v) {
421
419
  ok: false,
422
420
  fault,
423
421
  member: echoCallerText(name),
424
- detail: `its member "${echoCallerText(name)}" ${isReservedMemberName(name) ? `is not allowed (${reservedMemberFault(name)}) and its value ${valueFault}` : valueFault}`,
422
+ detail: `its member "${echoCallerText(name)}" ${isReservedMemberName(name) ? `is not allowed (${reservedMemberSentence(name)}) and its value ${valueFault}` : valueFault}`,
425
423
  };
426
424
  }
427
425
  if (!isReservedMemberName(name))
@@ -451,6 +449,6 @@ export function readRequestStringRecord(path, raw) {
451
449
  }
452
450
  return {
453
451
  record: read.record,
454
- issues: read.reservedMembers.map((name) => ({ path: `${path}.${name}`, reason: reservedMemberFault(name), member: name, fault: "member_name_reserved" })),
452
+ issues: read.reservedMembers.map((name) => ({ path: `${path}.${name}`, reason: reservedMemberSentence(name), member: name, fault: "member_name_reserved" })),
455
453
  };
456
454
  }
@@ -6,7 +6,7 @@
6
6
  import type { ENV_MODELS_DOCUMENT } from "./config-root-documents.js";
7
7
  import type { DomainName } from "./types.js";
8
8
  /** 本版登记的一次性迁移 id(闭集;每个 id 在 `ONE_TIME_MIGRATIONS` 登记表里恰一行)。收据只许这些 id。 */
9
- export declare const ONE_TIME_MIGRATION_IDS: readonly ["SS-M11", "SS-M12", "SS-M13"];
9
+ export declare const ONE_TIME_MIGRATION_IDS: readonly ["SS-M11", "SS-M12", "SS-M13", "SS-M14"];
10
10
  export type OneTimeMigrationId = (typeof ONE_TIME_MIGRATION_IDS)[number];
11
11
  /**
12
12
  * 一条收据说迁移**对一个坐标做了什么**(闭集,每词一义):
@@ -1,6 +1,6 @@
1
1
  import { deepFreeze } from "./deep-freeze.js";
2
2
  /** 本版登记的一次性迁移 id(闭集;每个 id 在 `ONE_TIME_MIGRATIONS` 登记表里恰一行)。收据只许这些 id。 */
3
- export const ONE_TIME_MIGRATION_IDS = deepFreeze(["SS-M11", "SS-M12", "SS-M13"]);
3
+ export const ONE_TIME_MIGRATION_IDS = deepFreeze(["SS-M11", "SS-M12", "SS-M13", "SS-M14"]);
4
4
  /**
5
5
  * 一条收据说迁移**对一个坐标做了什么**(闭集,每词一义):
6
6
  * - `moved` — 值搬到新位(`to`),义不变;
@@ -32,7 +32,7 @@ export type StoredDocuments = Readonly<Partial<Record<DomainName | RetiredDomain
32
32
  export interface StoredDocumentsMigration {
33
33
  /** 迁移后的文档集:没改的文档是**同一引用**;被移除的不在、新建的在(26.0.0 起没有一步移除或新建文档)。 */
34
34
  readonly docs: Readonly<Record<string, unknown>>;
35
- /** 逐条收据(步序 SS-M13〔mcp 条目〕→ workers 行步〔SS-M12 改写 → 一次终判〕:纯改写步在前,用新 schema 终判的 workers 行步最后;步内按坐标)。
35
+ /** 逐条收据(步序 SS-M13〔mcp 条目〕→ SS-M14〔entitlement 能力位座〕→ workers 行步〔SS-M12 改写 → 一次终判〕:纯改写步在前,用新 schema 终判的 workers 行步最后;步内按坐标)。
36
36
  * 只有 `refused` 的收据 = 什么都没改。 */
37
37
  readonly receipts: readonly MigrationReceipt[];
38
38
  }