@sema-agent/mods-kernel 7.57.0 → 7.59.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/README.md CHANGED
@@ -29,6 +29,9 @@ package version; it moves only when the chain semantics, the registration form,
29
29
  `side`) or the failure columns (failure, abort, pinned keys, an event's own budget ceiling, whether `$` may call it)
30
30
  change — once per release, however many of them change in it.
31
31
 
32
+ `@sema-agent/core` does not depend on this package: it compiles the same source into its own build, so a process that
33
+ installs both holds two copies. This package is for a host that runs its own bus; the engine does not need it installed.
34
+
32
35
  ## Which side raises an event
33
36
 
34
37
  Every name in `MOD_EVENT_TABLE` carries a `side` — `engine`, `surface` or `both`, the closed set `MOD_EVENT_SIDES` — and
@@ -48,6 +48,7 @@ export interface ModDispatchOptions {
48
48
  readonly frames?: readonly ModFrame[];
49
49
  readonly origin?: ModOrigin;
50
50
  readonly checkAnswer?: ModAnswerCheck;
51
+ readonly checkHandOn?: (payload: ModEventPayload) => string | undefined;
51
52
  readonly ranks?: ModAnswerRanks;
52
53
  readonly participant?: (p: ModParticipant) => boolean;
53
54
  }
package/dist/dispatch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CATCH_BUDGET_MS, createSelfBudget, POST_ABORT_GRACE_MS, RUNAWAY_AFTER_MS, unrefTimer, watchRunaway } from "./budget.js";
2
2
  import { expandOnSide, failureRefuses, isModEventName, MOD_SEATS, nextToRefusal, stationOn } from "./events.js";
3
3
  import { ENGINE_ORIGIN, modsInvalid, screenModSeats, } from "./registration.js";
4
- import { answerUpward, answerViolation, detachedCopy, engineObjectsOnce, handedOn, matcherMatches, matcherViolation, methodAnswerViolation, NEXT_IN_FLIGHT, receiveAnswer, receiveEvent, receivePayload, sealedObjects, } from "./site-rules.js";
4
+ import { answerUpward, answerViolation, detachedCopy, engineObjectsOnce, handedOn, handOnViolation, matcherMatches, matcherViolation, methodAnswerViolation, NEXT_IN_FLIGHT, receiveAnswer, receiveEvent, receivePayload, sealedObjects, } from "./site-rules.js";
5
5
  const TIER_RANK = { prepend: 0, user: 1, append: 2, builtin: 3, core: 4 };
6
6
  const bypassed = (floors, tier) => floors.some((f) => TIER_RANK[f.from] < TIER_RANK[tier] && TIER_RANK[tier] < TIER_RANK[f.to]);
7
7
  export async function admitMods(input) {
@@ -31,23 +31,22 @@ export async function admitMods(input) {
31
31
  });
32
32
  if (outcome.kind === "aborted")
33
33
  throw input.signal?.reason ?? new Error("admission aborted");
34
+ const whose = { name: cand.name, seat: cand.seat, tier: cand.tier, ...(cand.provenance !== undefined ? { provenance: cand.provenance } : {}) };
34
35
  if (outcome.kind === "failed") {
35
- records.push(Object.freeze({ name: cand.name, seat: cand.seat, tier: cand.tier, refusedBy: outcome.registration, reason: `${outcome.registration} failed: ${outcome.reason}` }));
36
+ records.push(Object.freeze({ ...whose, refusedBy: outcome.registration, reason: `${outcome.registration} failed: ${outcome.reason}` }));
36
37
  continue;
37
38
  }
38
39
  const refused = refusalOf(outcome.answer);
39
40
  if (refused !== undefined) {
40
- records.push(Object.freeze({ name: cand.name, seat: cand.seat, tier: cand.tier, refusedBy: outcome.answeredBy ?? "engine", reason: refused }));
41
+ records.push(Object.freeze({ ...whose, refusedBy: outcome.answeredBy ?? "engine", reason: refused }));
41
42
  continue;
42
43
  }
43
44
  const own = mountOne(cand, input.side, describe);
44
45
  mounted.push(...own);
45
46
  const events = unique(own.map((h) => h.pattern));
46
- const observe = unique(own.filter((h) => h.observe).map((h) => h.pattern));
47
+ const observe = Object.freeze(events.filter((p) => own.every((h) => h.pattern !== p || h.observe)));
47
48
  records.push(Object.freeze({
48
- name: cand.name,
49
- seat: cand.seat,
50
- tier: cand.tier,
49
+ ...whose,
51
50
  events,
52
51
  ...(observe.length > 0 ? { observe } : {}),
53
52
  ...(outcome.skipped.length > 0 ? { skipped: outcome.skipped } : {}),
@@ -376,7 +375,10 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
376
375
  if (passed === e0)
377
376
  return { snap: e0 };
378
377
  const handed = handedOn(st.pinned, e0, passed, engines(), isProxy);
379
- return "violation" in handed ? handed : { snap: handed.payload };
378
+ if ("violation" in handed)
379
+ return handed;
380
+ const why = handOnViolation(handed.payload, options.checkHandOn);
381
+ return why !== undefined ? { violation: why } : { snap: handed.payload };
380
382
  };
381
383
  const trustFloors = new Map();
382
384
  const NO_FLOOR = Object.freeze(MOD_SEATS.map(() => 0));
@@ -582,7 +584,8 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
582
584
  if (caught !== undefined && "answer" in caught) {
583
585
  if (failure.cause !== "violation" && failure.cause !== "reentry")
584
586
  report(new Error(`${name}: ${event}: ${failure.reason}; its .catch answered`));
585
- producers.set(caught.answer, name);
587
+ if (!(typeof caught.answer === "object" && caught.answer !== null && producers.has(caught.answer)))
588
+ producers.set(caught.answer, name);
586
589
  traceOf(sink, i, name, h.reg.tier, "caught", ms);
587
590
  return caught.answer;
588
591
  }
package/dist/events.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const KERNEL_CONTRACT_VERSION = 3;
1
+ export declare const KERNEL_CONTRACT_VERSION = 5;
2
2
  export declare const MOD_TIERS: readonly ["prepend", "user", "append", "builtin", "core"];
3
3
  export type ModTier = (typeof MOD_TIERS)[number];
4
4
  export type ModRegistrationTier = Exclude<ModTier, "builtin" | "core">;
package/dist/events.js CHANGED
@@ -1,4 +1,4 @@
1
- export const KERNEL_CONTRACT_VERSION = 3;
1
+ export const KERNEL_CONTRACT_VERSION = 5;
2
2
  export const MOD_TIERS = Object.freeze(["prepend", "user", "append", "builtin", "core"]);
3
3
  export const MOD_SEATS = Object.freeze(["deployment", "task"]);
4
4
  export const MOD_EVENT_SIDES = Object.freeze(["engine", "surface", "both"]);
@@ -55,7 +55,7 @@ export const MOD_EVENT_TABLE = Object.freeze({
55
55
  "classic.SessionEnd": engine(),
56
56
  "classic.Stop": engine(station("skip", "immediate")),
57
57
  "classic.StopFailure": engine(station("skip", "grace")),
58
- "classic.SubagentStart": engine(),
58
+ "classic.SubagentStart": engine(station("skip", "immediate", ["agentId", "agentType"])),
59
59
  "classic.SubagentStop": engine(station("skip", "immediate")),
60
60
  "classic.PreCompact": engine(station("skip", "grace")),
61
61
  "classic.PostCompact": engine(station("skip", "grace")),
@@ -12,6 +12,7 @@ export interface ModOrigin {
12
12
  readonly tier: ModTier;
13
13
  }
14
14
  export declare const ENGINE_ORIGIN: ModOrigin;
15
+ export declare function namedRegistration(registration: string | undefined): string | undefined;
15
16
  export interface ModPluginFacts {
16
17
  readonly name: string;
17
18
  }
@@ -88,6 +89,7 @@ export type ModAdmissionRecord = {
88
89
  readonly name: string;
89
90
  readonly seat: ModSeat;
90
91
  readonly tier: ModTier;
92
+ readonly provenance?: string;
91
93
  readonly events: readonly string[];
92
94
  readonly observe?: readonly string[];
93
95
  readonly skipped?: readonly ModSkip[];
@@ -95,6 +97,7 @@ export type ModAdmissionRecord = {
95
97
  readonly name: string;
96
98
  readonly seat: ModSeat;
97
99
  readonly tier: ModTier;
100
+ readonly provenance?: string;
98
101
  readonly refusedBy: string;
99
102
  readonly reason: string;
100
103
  };
@@ -3,6 +3,9 @@ import { resolveModBudgetMs } from "./budget.js";
3
3
  export const MODS_INVALID_CODE = "config.mods_invalid";
4
4
  export const MODS_REGISTRATION_REFUSED_CODE = "mods.registration_refused";
5
5
  export const ENGINE_ORIGIN = Object.freeze({ plugin: "engine", tier: "core" });
6
+ export function namedRegistration(registration) {
7
+ return registration === undefined || registration === ENGINE_ORIGIN.plugin ? undefined : registration;
8
+ }
6
9
  export const MOD_TRACE_OUTCOMES = Object.freeze(["returned", "passed", "rejected", "caught", "expired", "kept", "skipped", "bypassed"]);
7
10
  export function modsInvalid(message) {
8
11
  return Object.assign(new Error(message), { code: MODS_INVALID_CODE });
@@ -44,6 +44,7 @@ export declare function pinnedHandOn(pinned: readonly string[], held: ModEventPa
44
44
  readonly violation: string;
45
45
  };
46
46
  export declare function answerViolation(answer: unknown, check: ModAnswerCheck | undefined, e: ModEventPayload, by: ModAnswerer, below: readonly unknown[], run: ModDispatchRun): string | undefined;
47
+ export declare function handOnViolation(payload: ModEventPayload, check: ((payload: ModEventPayload) => string | undefined) | undefined): string | undefined;
47
48
  export declare function methodAnswerViolation(answer: unknown, _e?: ModEventPayload, _by?: ModAnswerer, below?: readonly unknown[]): string | undefined;
48
49
  export declare function matcherViolation(m: unknown): string | undefined;
49
50
  export declare function matcherMatches(m: ModMatcher | undefined, e: ModEventPayload): boolean;
@@ -203,6 +203,16 @@ export function answerViolation(answer, check, e, by, below, run) {
203
203
  return "returned an answer the station cannot read";
204
204
  }
205
205
  }
206
+ export function handOnViolation(payload, check) {
207
+ if (check === undefined)
208
+ return undefined;
209
+ try {
210
+ return check(payload);
211
+ }
212
+ catch {
213
+ return "handed on an event the station cannot read";
214
+ }
215
+ }
206
216
  const denyOf = (a) => (typeof a === "object" && a !== null && Object.prototype.hasOwnProperty.call(a, "deny") ? Reflect.get(a, "deny") : undefined);
207
217
  export function methodAnswerViolation(answer, _e, _by, below = []) {
208
218
  if (!isPlainRecord(answer))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/mods-kernel",
3
- "version": "7.57.0",
3
+ "version": "7.59.0",
4
4
  "private": false,
5
5
  "description": "The sema mods kernel: one extension bus (registration, admission, chain, failure and budget law) shared by the engine and the shell. Zero dependencies.",
6
6
  "type": "module",
@@ -31,5 +31,5 @@
31
31
  "scripts": {
32
32
  "build": "tsc -p tsconfig.json"
33
33
  },
34
- "gitHead": "84be0e09dcdd8e157f88f083241ceafedc0f33aa"
34
+ "gitHead": "66b1845c9644930fa7f43fd7c388316c3b060ee1"
35
35
  }