instar 1.3.800 → 1.3.802

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 (83) hide show
  1. package/dashboard/index.html +25 -0
  2. package/dist/commands/server.d.ts.map +1 -1
  3. package/dist/commands/server.js +63 -1
  4. package/dist/commands/server.js.map +1 -1
  5. package/dist/core/BackupManager.d.ts.map +1 -1
  6. package/dist/core/BackupManager.js +8 -0
  7. package/dist/core/BackupManager.js.map +1 -1
  8. package/dist/core/PostUpdateMigrator.d.ts +8 -0
  9. package/dist/core/PostUpdateMigrator.d.ts.map +1 -1
  10. package/dist/core/PostUpdateMigrator.js +45 -0
  11. package/dist/core/PostUpdateMigrator.js.map +1 -1
  12. package/dist/core/ProactiveSwapMonitor.d.ts +10 -0
  13. package/dist/core/ProactiveSwapMonitor.d.ts.map +1 -1
  14. package/dist/core/ProactiveSwapMonitor.js +39 -0
  15. package/dist/core/ProactiveSwapMonitor.js.map +1 -1
  16. package/dist/core/SessionManager.d.ts +26 -4
  17. package/dist/core/SessionManager.d.ts.map +1 -1
  18. package/dist/core/SessionManager.js +76 -22
  19. package/dist/core/SessionManager.js.map +1 -1
  20. package/dist/core/machineCoherenceManifest.d.ts +10 -0
  21. package/dist/core/machineCoherenceManifest.d.ts.map +1 -1
  22. package/dist/core/machineCoherenceManifest.js +58 -0
  23. package/dist/core/machineCoherenceManifest.js.map +1 -1
  24. package/dist/core/types.d.ts +53 -0
  25. package/dist/core/types.d.ts.map +1 -1
  26. package/dist/core/types.js.map +1 -1
  27. package/dist/monitoring/ExternalHogScanTick.d.ts +9 -0
  28. package/dist/monitoring/ExternalHogScanTick.d.ts.map +1 -1
  29. package/dist/monitoring/ExternalHogScanTick.js +29 -0
  30. package/dist/monitoring/ExternalHogScanTick.js.map +1 -1
  31. package/dist/monitoring/PromiseBeacon.d.ts +6 -0
  32. package/dist/monitoring/PromiseBeacon.d.ts.map +1 -1
  33. package/dist/monitoring/PromiseBeacon.js +42 -6
  34. package/dist/monitoring/PromiseBeacon.js.map +1 -1
  35. package/dist/monitoring/guardManifest.d.ts.map +1 -1
  36. package/dist/monitoring/guardManifest.js +31 -0
  37. package/dist/monitoring/guardManifest.js.map +1 -1
  38. package/dist/monitoring/guardPosture.d.ts.map +1 -1
  39. package/dist/monitoring/guardPosture.js +22 -0
  40. package/dist/monitoring/guardPosture.js.map +1 -1
  41. package/dist/monitoring/selfaction/anchor.d.ts +82 -0
  42. package/dist/monitoring/selfaction/anchor.d.ts.map +1 -0
  43. package/dist/monitoring/selfaction/anchor.js +113 -0
  44. package/dist/monitoring/selfaction/anchor.js.map +1 -0
  45. package/dist/monitoring/selfaction/governor.d.ts +242 -0
  46. package/dist/monitoring/selfaction/governor.d.ts.map +1 -0
  47. package/dist/monitoring/selfaction/governor.js +1475 -0
  48. package/dist/monitoring/selfaction/governor.js.map +1 -0
  49. package/dist/monitoring/selfaction/policies.d.ts +86 -0
  50. package/dist/monitoring/selfaction/policies.d.ts.map +1 -0
  51. package/dist/monitoring/selfaction/policies.js +339 -0
  52. package/dist/monitoring/selfaction/policies.js.map +1 -0
  53. package/dist/monitoring/selfaction/types.d.ts +208 -0
  54. package/dist/monitoring/selfaction/types.d.ts.map +1 -0
  55. package/dist/monitoring/selfaction/types.js +11 -0
  56. package/dist/monitoring/selfaction/types.js.map +1 -0
  57. package/dist/scaffold/templates.d.ts.map +1 -1
  58. package/dist/scaffold/templates.js +8 -1
  59. package/dist/scaffold/templates.js.map +1 -1
  60. package/dist/server/AgentServer.d.ts.map +1 -1
  61. package/dist/server/AgentServer.js +6 -0
  62. package/dist/server/AgentServer.js.map +1 -1
  63. package/dist/server/CapabilityIndex.d.ts.map +1 -1
  64. package/dist/server/CapabilityIndex.js +9 -0
  65. package/dist/server/CapabilityIndex.js.map +1 -1
  66. package/dist/server/routes.d.ts +4 -0
  67. package/dist/server/routes.d.ts.map +1 -1
  68. package/dist/server/routes.js +271 -3
  69. package/dist/server/routes.js.map +1 -1
  70. package/dist/testing/selfActionRegistry.d.ts +16 -0
  71. package/dist/testing/selfActionRegistry.d.ts.map +1 -1
  72. package/dist/testing/selfActionRegistry.js +16 -0
  73. package/dist/testing/selfActionRegistry.js.map +1 -1
  74. package/package.json +2 -2
  75. package/scripts/lint-emit-without-admit.js +303 -0
  76. package/src/data/builtin-manifest.json +66 -66
  77. package/src/data/state-coherence-registry.json +1296 -1241
  78. package/src/scaffold/templates.ts +8 -1
  79. package/upgrades/1.3.801.md +38 -0
  80. package/upgrades/1.3.802.md +36 -0
  81. package/upgrades/session-listing-hygiene.eli16.md +26 -0
  82. package/upgrades/side-effects/self-action-governor.md +111 -0
  83. package/upgrades/side-effects/session-listing-hygiene.md +93 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * selfaction/anchor.ts — the PROCESS-GLOBAL anchor + single-mint registry
3
+ * (companion §5.3, spec ADV8-1/ADV9-1).
4
+ *
5
+ * The mint registry AND the admission-state anchor live behind ONE
6
+ * `Symbol.for('instar.selfActionGovernor')` key on `globalThis`, storing a
7
+ * MINIMAL claim surface (never raw mutable maps). An accidental
8
+ * dual-package/duplicated-dist load duplicates the whole module graph — a
9
+ * module-scoped registry would see one clean claim per copy and guard nothing
10
+ * in exactly its named case; the global key makes cross-copy claims COLLIDE
11
+ * and shares ONE admission state so two copies can never run independent
12
+ * full-budget counters or clobber the durable snapshot as uncoordinated
13
+ * writers.
14
+ *
15
+ * Lifecycle: INIT-ONCE — the first claimant initializes, rehydrates, and owns
16
+ * the single flush loop; a later claimant ATTACHES read-write, never
17
+ * re-initializes, never starts a second flusher. A duplicate
18
+ * `governor.for(id)` mint fails LOUDLY: controller-scoped errored posture
19
+ * (never process-fatal) + a `mint-collision` audit row; the losing claimant's
20
+ * dead handles resolve through the per-class fail direction.
21
+ *
22
+ * Test lifecycle (SC9-1): under vitest each module graph gets a graph-LOCAL
23
+ * anchor by default (so unrelated test files never collide on a worker-shared
24
+ * globalThis), and the mandated bounce/dual-load fixtures OPT IN to a shared
25
+ * key via the key-salt override so they can exercise the collision + attach
26
+ * cases within one process.
27
+ */
28
+ /** Test fixtures set `(globalThis as any)[Symbol.for(KEY_SALT_OVERRIDE)] = 'salt'`
29
+ * to force two freshly-imported module copies onto ONE shared anchor. */
30
+ export declare const KEY_SALT_OVERRIDE = "instar.selfActionGovernor.keySaltOverride";
31
+ /**
32
+ * The MINIMAL claim surface stored behind the global key. Deliberately not the
33
+ * governor's raw maps: the anchor exposes claim/attach/mint bookkeeping plus
34
+ * ONE opaque shared-state slot the initializing claimant owns.
35
+ */
36
+ export interface GovernorAnchor {
37
+ /** Monotonic claim generation (attach epochs). */
38
+ generation: number;
39
+ /** Whether an initializing claimant exists (owns rehydrate + flush loop). */
40
+ initialized: boolean;
41
+ /** Set of controller ids already minted (single-mint registry). */
42
+ mintedControllerIds: Set<string>;
43
+ /** Controller ids whose duplicate mint collided (dead-handle posture). */
44
+ collidedControllerIds: Set<string>;
45
+ /** The shared runtime state slot (owned by the first claimant; attached
46
+ * read-write by later claimants). Opaque here by design. */
47
+ sharedState: unknown;
48
+ /** Collision callback (installed by the initializing claimant so a losing
49
+ * mint from ANY copy lands one audit row). */
50
+ onMintCollision?: (controllerId: string) => void;
51
+ }
52
+ /** Get-or-create the anchor behind the process-global key. */
53
+ export declare function getAnchor(): GovernorAnchor;
54
+ export type MintResult = {
55
+ ok: true;
56
+ } | {
57
+ ok: false;
58
+ reason: 'mint-collision';
59
+ };
60
+ /**
61
+ * Single-mint per controller id, process-global. A second mint of the SAME id
62
+ * (dual-load, copy-pasted marker file) COLLIDES: the second claimant's handle
63
+ * is DEAD (controller-scoped errored posture — never process-fatal).
64
+ */
65
+ export declare function mintController(controllerId: string): MintResult;
66
+ /**
67
+ * Claim the shared-state slot. INIT-ONCE: the first claimant provides the
68
+ * initializer and OWNS the flush loop; later claimants ATTACH to the existing
69
+ * state (never re-initialize, never start a second flusher).
70
+ */
71
+ export declare function claimSharedState<T>(init: () => T): {
72
+ state: T;
73
+ role: 'initialized' | 'attached';
74
+ };
75
+ /**
76
+ * Test-only dispose/reset (SC9-1). Releases the anchor (mints + shared state)
77
+ * so fixtures can re-instantiate within one process. Refuses outside a test
78
+ * environment unless `force` — production code must never reset the anchor
79
+ * (that would hand a runaway loop a fresh mint + budget surface).
80
+ */
81
+ export declare function resetAnchorForTest(force?: boolean): void;
82
+ //# sourceMappingURL=anchor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../../src/monitoring/selfaction/anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH;0EAC0E;AAC1E,eAAO,MAAM,iBAAiB,8CAA8C,CAAC;AAkB7E;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,WAAW,EAAE,OAAO,CAAC;IACrB,mEAAmE;IACnE,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,0EAA0E;IAC1E,qBAAqB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnC;iEAC6D;IAC7D,WAAW,EAAE,OAAO,CAAC;IACrB;mDAC+C;IAC/C,eAAe,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD;AAED,8DAA8D;AAC9D,wBAAgB,SAAS,IAAI,cAAc,CAe1C;AAED,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAEhF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,CAa/D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,aAAa,GAAG,UAAU,CAAA;CAAE,CAUjG;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,UAAQ,GAAG,IAAI,CAOtD"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * selfaction/anchor.ts — the PROCESS-GLOBAL anchor + single-mint registry
3
+ * (companion §5.3, spec ADV8-1/ADV9-1).
4
+ *
5
+ * The mint registry AND the admission-state anchor live behind ONE
6
+ * `Symbol.for('instar.selfActionGovernor')` key on `globalThis`, storing a
7
+ * MINIMAL claim surface (never raw mutable maps). An accidental
8
+ * dual-package/duplicated-dist load duplicates the whole module graph — a
9
+ * module-scoped registry would see one clean claim per copy and guard nothing
10
+ * in exactly its named case; the global key makes cross-copy claims COLLIDE
11
+ * and shares ONE admission state so two copies can never run independent
12
+ * full-budget counters or clobber the durable snapshot as uncoordinated
13
+ * writers.
14
+ *
15
+ * Lifecycle: INIT-ONCE — the first claimant initializes, rehydrates, and owns
16
+ * the single flush loop; a later claimant ATTACHES read-write, never
17
+ * re-initializes, never starts a second flusher. A duplicate
18
+ * `governor.for(id)` mint fails LOUDLY: controller-scoped errored posture
19
+ * (never process-fatal) + a `mint-collision` audit row; the losing claimant's
20
+ * dead handles resolve through the per-class fail direction.
21
+ *
22
+ * Test lifecycle (SC9-1): under vitest each module graph gets a graph-LOCAL
23
+ * anchor by default (so unrelated test files never collide on a worker-shared
24
+ * globalThis), and the mandated bounce/dual-load fixtures OPT IN to a shared
25
+ * key via the key-salt override so they can exercise the collision + attach
26
+ * cases within one process.
27
+ */
28
+ const GLOBAL_KEY = 'instar.selfActionGovernor';
29
+ /** Test fixtures set `(globalThis as any)[Symbol.for(KEY_SALT_OVERRIDE)] = 'salt'`
30
+ * to force two freshly-imported module copies onto ONE shared anchor. */
31
+ export const KEY_SALT_OVERRIDE = 'instar.selfActionGovernor.keySaltOverride';
32
+ /** Module-LOCAL fallback symbol — unique per module graph (test isolation). */
33
+ const MODULE_LOCAL_KEY = Symbol('instar.selfActionGovernor.moduleLocal');
34
+ function isTestEnv() {
35
+ return Boolean(process.env.VITEST || process.env.NODE_ENV === 'test');
36
+ }
37
+ function anchorKey() {
38
+ const salt = globalThis[Symbol.for(KEY_SALT_OVERRIDE)];
39
+ if (typeof salt === 'string' && salt.length > 0) {
40
+ return Symbol.for(`${GLOBAL_KEY}:${salt}`);
41
+ }
42
+ if (isTestEnv())
43
+ return MODULE_LOCAL_KEY;
44
+ return Symbol.for(GLOBAL_KEY);
45
+ }
46
+ /** Get-or-create the anchor behind the process-global key. */
47
+ export function getAnchor() {
48
+ const key = anchorKey();
49
+ const g = globalThis;
50
+ let anchor = g[key];
51
+ if (!anchor) {
52
+ anchor = {
53
+ generation: 0,
54
+ initialized: false,
55
+ mintedControllerIds: new Set(),
56
+ collidedControllerIds: new Set(),
57
+ sharedState: null,
58
+ };
59
+ g[key] = anchor;
60
+ }
61
+ return anchor;
62
+ }
63
+ /**
64
+ * Single-mint per controller id, process-global. A second mint of the SAME id
65
+ * (dual-load, copy-pasted marker file) COLLIDES: the second claimant's handle
66
+ * is DEAD (controller-scoped errored posture — never process-fatal).
67
+ */
68
+ export function mintController(controllerId) {
69
+ const anchor = getAnchor();
70
+ if (anchor.mintedControllerIds.has(controllerId)) {
71
+ anchor.collidedControllerIds.add(controllerId);
72
+ try {
73
+ anchor.onMintCollision?.(controllerId);
74
+ }
75
+ catch {
76
+ /* collision reporting must never throw into a module-scope mint */
77
+ }
78
+ return { ok: false, reason: 'mint-collision' };
79
+ }
80
+ anchor.mintedControllerIds.add(controllerId);
81
+ return { ok: true };
82
+ }
83
+ /**
84
+ * Claim the shared-state slot. INIT-ONCE: the first claimant provides the
85
+ * initializer and OWNS the flush loop; later claimants ATTACH to the existing
86
+ * state (never re-initialize, never start a second flusher).
87
+ */
88
+ export function claimSharedState(init) {
89
+ const anchor = getAnchor();
90
+ anchor.generation += 1;
91
+ if (anchor.initialized && anchor.sharedState !== null) {
92
+ return { state: anchor.sharedState, role: 'attached' };
93
+ }
94
+ const state = init();
95
+ anchor.sharedState = state;
96
+ anchor.initialized = true;
97
+ return { state, role: 'initialized' };
98
+ }
99
+ /**
100
+ * Test-only dispose/reset (SC9-1). Releases the anchor (mints + shared state)
101
+ * so fixtures can re-instantiate within one process. Refuses outside a test
102
+ * environment unless `force` — production code must never reset the anchor
103
+ * (that would hand a runaway loop a fresh mint + budget surface).
104
+ */
105
+ export function resetAnchorForTest(force = false) {
106
+ if (!isTestEnv() && !force) {
107
+ throw new Error('resetAnchorForTest is test-only (set force to override deliberately)');
108
+ }
109
+ const key = anchorKey();
110
+ const g = globalThis;
111
+ delete g[key];
112
+ }
113
+ //# sourceMappingURL=anchor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor.js","sourceRoot":"","sources":["../../../src/monitoring/selfaction/anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,MAAM,UAAU,GAAG,2BAA2B,CAAC;AAC/C;0EAC0E;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,2CAA2C,CAAC;AAE7E,+EAA+E;AAC/E,MAAM,gBAAgB,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAEzE,SAAS,SAAS;IAChB,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,SAAS;IAChB,MAAM,IAAI,GAAI,UAAsC,CAAC,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACpF,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,IAAI,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,SAAS,EAAE;QAAE,OAAO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,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;IACvB,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;QACtD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,WAAgB,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IAC9D,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC;IACrB,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAK,GAAG,KAAK;IAC9C,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;IAC1F,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * selfaction/governor.ts — the SelfActionGovernor runtime primitive
3
+ * (Increment B of docs/specs/unified-self-action-backpressure.md; the
4
+ * normative companion `unified-self-action-backpressure.companion.md` is the
5
+ * implementation authority).
6
+ *
7
+ * ONE in-process chokepoint every self-triggered, cost- or disruption-bearing
8
+ * action passes through to acquire permission to fire, keyed on a controller
9
+ * id. Ships OBSERVE-ONLY on every class, fleet-dark per the FD1 ladder: in
10
+ * observe mode admit() records would-verdicts and ALWAYS allows; no
11
+ * enforcement behavior is live by default. The enforce flip is the operator's
12
+ * per-class action later (FD8), gated by FD12 — and for pool-shared classes
13
+ * additionally by FD9/FD15 (this increment never enforces pool-shared with
14
+ * registered machine count > 1).
15
+ *
16
+ * This IS the governor module — it rides the usage-scan lint's SELF-SCOPE
17
+ * allowlist (companion INT9-2), never a controller marker.
18
+ */
19
+ import type { ActionRef, Admission, AdmissionToken, AdmitOpts, DerivedTarget, GovernorAttentionItem, GovernorClassMode, GovernorClassPosture, PressureReading, PrincipalSurface, TransitionRow, TransitionRowType } from './types.js';
20
+ export interface SelfActionGovernorDeps {
21
+ /** Agent state dir (durable snapshot + aggregates live under it). */
22
+ stateDir: string;
23
+ /** LIVE read of `intelligence.selfActionGovernor.emergencyDisable` — an
24
+ * in-memory read (the PATCH /config route updates the runtime config), so
25
+ * admitSync stays zero-I/O. */
26
+ readEmergencyDisable: () => boolean;
27
+ /** LIVE read of the sparse per-class overrides block (`...classes`). Read
28
+ * once at init + on the slow tick — never per-admit. */
29
+ readClassesConfig: () => unknown;
30
+ /** Governor-owned census source — INDEPENDENT of any governed controller's
31
+ * candidate enumeration (spec SC6-1(iii)). Sampled OFF the hot path. */
32
+ readCensus?: () => PressureReading | null;
33
+ /** Configured session cap (censusAbsoluteMax tighten input). */
34
+ configuredSessionCap?: () => number | undefined;
35
+ /** REGISTERED machine count (FD9 level gate) — re-evaluated on the slow
36
+ * tick, never per-admit. */
37
+ registeredMachineCount?: () => number;
38
+ /** P17 funnel seam — the ONLY path for operator notices. */
39
+ emitAttention?: (item: GovernorAttentionItem) => void | Promise<void>;
40
+ now?: () => number;
41
+ /** Flush cadence (default 60s). */
42
+ flushIntervalMs?: number;
43
+ /** Token TTL (default 60s). */
44
+ tokenTtlMs?: number;
45
+ }
46
+ export declare class SelfActionGovernorCore {
47
+ private readonly state;
48
+ readonly role: 'initialized' | 'attached';
49
+ constructor();
50
+ /**
51
+ * INIT-ONCE (companion §5.3): the FIRST initializer rehydrates the durable
52
+ * snapshot and owns the single flush loop; a later init call ATTACHES —
53
+ * never re-initializes, never starts a second flusher.
54
+ */
55
+ init(deps: SelfActionGovernorDeps): 'initialized' | 'attached';
56
+ /** Graceful shutdown — flush + stop the flusher (FD14 graceful-shutdown flush). */
57
+ dispose(): void;
58
+ private now;
59
+ private nowIso;
60
+ private loadPolicies;
61
+ /** FD9 level gate: a pool-shared class may not ENFORCE when the REGISTERED
62
+ * machine count > 1 (no pool-wide ceiling in this increment). Evaluated on
63
+ * the slow tick / registration change — never per-admit. */
64
+ private applyPoolShareGate;
65
+ /**
66
+ * Mint the per-controller handle — module scope, once per controller file.
67
+ * A duplicate mint (dual-load / copy-pasted marker) yields a DEAD handle
68
+ * whose admits resolve through the per-class fail direction, loudly.
69
+ */
70
+ for(controllerId: string): SelfActionHandle;
71
+ /** Cache guard so a per-admit live read can never become per-admit I/O
72
+ * (the injected reader may consult a disk-backed liveConfig). */
73
+ private disableReadCache;
74
+ private emergencyDisabled;
75
+ private onDisableFlip;
76
+ admitFor(controllerId: string, dead: boolean, target: DerivedTarget, opts?: AdmitOpts): Admission;
77
+ private classFor;
78
+ /** Test seam: force the NEXT evaluations for a controller to throw (the
79
+ * fail-matrix fixtures need a genuinely-throwing admit path). */
80
+ private readonly throwOnAdmit;
81
+ setThrowOnAdmitForTest(controllerId: string, on: boolean): void;
82
+ /** The policy evaluation — the WOULD-verdict machinery (all modes). */
83
+ private evaluate;
84
+ /** Map a policy deny to the three-way disposition per mode + class shape. */
85
+ private nonAllow;
86
+ /** Fail matrix (companion §6): the disposition when admit() itself THROWS. */
87
+ private failDisposition;
88
+ private enqueue;
89
+ /** Failure-minimal enqueue (spec SC5-3): no policy evaluation, no I/O; a
90
+ * double failure is an AUDITED drop folded into the dead-letter notice as
91
+ * the `enqueue-drop` class. */
92
+ private minimalEnqueue;
93
+ private retryAfter;
94
+ /**
95
+ * Drain: re-admit + re-project + re-run the controller's eligibility
96
+ * predicate + incarnation-fence check. BOTH-unavailable = audited drop.
97
+ * Fairness: interactive before jobs, FIFO within (age-based promotion).
98
+ */
99
+ drainQueues(nowMs?: number): void;
100
+ /** Drain-time fence check used by retrofit sites that re-derive targets. */
101
+ fenceMatches(queued: string | undefined, current: string | undefined): boolean;
102
+ private recordShed;
103
+ private allow;
104
+ /**
105
+ * Runtime consume-once at the protected sink — the AUTHORITY (FD6/CX4).
106
+ * The sink pins its expected controllerId module-side; a token minted for
107
+ * any other controller is rejected. In OBSERVE mode a rejection is recorded
108
+ * but the sink PROCEEDS (signal-only — observe never blocks); in ENFORCE
109
+ * mode `proceed: false`.
110
+ */
111
+ consumeToken(token: AdmissionToken | null | undefined, expectedControllerId: string, opts?: {
112
+ targetKey?: string;
113
+ nowMs?: number;
114
+ }): {
115
+ proceed: boolean;
116
+ valid: boolean;
117
+ reason?: string;
118
+ };
119
+ /**
120
+ * Privileged, SEPARATE API — importable ONLY by the enumerated
121
+ * provenance-setting modules (lint-enforced). ALWAYS allow + per-admit
122
+ * audit row (the ONE deliberate per-event carve-out); NEVER paced — exempt
123
+ * from ceilings, the errored path, and the last-resort floor. A throwing
124
+ * principalAdmit resolves OPEN.
125
+ */
126
+ principalAdmit(surface: PrincipalSurface, action: ActionRef): Admission;
127
+ private countPrincipal;
128
+ private rollWindow;
129
+ private windowCount;
130
+ private recordAdmit;
131
+ /** Evict ONLY settled/expired per-target entries (never an active
132
+ * at-ceiling entry — spec SC-m3). Returns true when a slot was freed. */
133
+ private evictSettled;
134
+ private refillRate;
135
+ private safeProjection;
136
+ /** Sample the census OFF the hot path (slow tick / window roll consumer). */
137
+ sampleCensus(nowMs?: number): void;
138
+ private recomputeReliefCeiling;
139
+ private safeSessionCap;
140
+ private openErroredEpisode;
141
+ private closeErroredEpisode;
142
+ /** Rate-bounded errored audit: first-N verbatim per episode, then aggregated. */
143
+ private auditErrored;
144
+ /** Latched relief demote (rate-relaxation loss). Alarm ONLY on heal
145
+ * EXHAUSTION (N failed clean cooldowns) — transient cycles are audit-only. */
146
+ demoteReliefClass(controllerId: string, nowMs?: number): void;
147
+ /** Clean-cooldown re-promotion — the self-heal; audit-only (P22). */
148
+ repromoteReliefClass(controllerId: string, nowMs?: number): void;
149
+ private checkObserveLimbo;
150
+ private bump;
151
+ private audit;
152
+ auditRow(type: TransitionRowType, controllerId?: string, detail?: string): void;
153
+ private notify;
154
+ private snapshotPath;
155
+ private aggregatesPath;
156
+ private auditPath;
157
+ private eagerFlush;
158
+ /** The flush BARRIER for governor-process-killing actions (FD14). */
159
+ flushBarrier(): void;
160
+ flushSnapshot(clean: boolean): void;
161
+ flushAudit(): void;
162
+ private rehydrate;
163
+ private applyConservativePosture;
164
+ private slowTick;
165
+ /** Test seam: run one slow tick deterministically. */
166
+ runSlowTickForTest(): void;
167
+ /** Scrubbed, LOCK-FREE posture read (no target identities, no absolute
168
+ * quota values — spec SEC6; the /test-runner-limiter PURE-read precedent). */
169
+ getPosture(): {
170
+ emergencyDisable: boolean;
171
+ initialized: boolean;
172
+ classes: GovernorClassPosture[];
173
+ };
174
+ /** Coherence-advert accessor (companion §10b): per-class scalar mode for
175
+ * pool-shared classes, read LIVE from governor runtime state. */
176
+ getClassMode(controllerId: string): GovernorClassMode;
177
+ /** GuardRegistry runtime getter (enabled = emergencyDisable !== true).
178
+ * Deliberately does NOT report observe-only as `dryRun`: the governor's
179
+ * guard job — registration + measurement + kill-switch visibility — IS
180
+ * live in observe mode; per-class enforce is the separate FD8/FD12 ladder
181
+ * with its own observe-limbo loop-closer, so painting the whole guard
182
+ * on-dry-run would manufacture a permanent loadBearingGap against the
183
+ * spec's designed observe-first rollout. */
184
+ guardRuntimeStatus(): {
185
+ enabled: boolean;
186
+ lastTickAt: number;
187
+ };
188
+ /** Test seam: set a class's mode directly (enforce-path coverage — an
189
+ * observe soak cannot certify machinery it never exercises; spec A7). */
190
+ setModeForTest(controllerId: string, mode: GovernorClassMode): void;
191
+ /** Test seam: force a breaker open. */
192
+ openBreakerForTest(controllerId: string, untilMs: number): void;
193
+ /** Read the buffered (unflushed) audit rows — test/inspection seam. */
194
+ peekAuditBuffer(): readonly TransitionRow[];
195
+ /** Test seam: ALL audit rows — the in-memory buffer PLUS any flushed file
196
+ * rows (a slow tick flushes the buffer; assertions must not race that). */
197
+ readAllAuditRowsForTest(): TransitionRow[];
198
+ }
199
+ /**
200
+ * Per-controller handle minted once at registration. Ordinary handles CANNOT
201
+ * express `origin: 'principal'` — they stamp 'self' unconditionally (the
202
+ * privileged lane is `governor.principalAdmit`, a separate API).
203
+ */
204
+ export declare class SelfActionHandle {
205
+ private readonly core;
206
+ readonly controllerId: string;
207
+ private readonly dead;
208
+ constructor(core: SelfActionGovernorCore, controllerId: string, dead: boolean);
209
+ /** Async admission (classes that may touch cross-process CAS later). */
210
+ admit(target: DerivedTarget, opts?: AdmitOpts): Promise<Admission>;
211
+ /** Zero-I/O synchronous admission (notify/age-kill-class hot paths). */
212
+ admitSync(target: DerivedTarget, opts?: AdmitOpts): Admission;
213
+ /** True when this handle lost a mint collision (dead-handle posture). */
214
+ isDead(): boolean;
215
+ }
216
+ /**
217
+ * The governor module surface. Emit sites hold `const gov = governor.for(id)`
218
+ * at module scope (raw string admit at emit sites is LINT-FORBIDDEN).
219
+ */
220
+ export declare const governor: {
221
+ for(controllerId: string): SelfActionHandle;
222
+ /** Privileged principal lane — import-restricted by the usage-scan lint. */
223
+ principalAdmit(surface: PrincipalSurface, action: ActionRef): Admission;
224
+ };
225
+ /** Server-boot initialization (INIT-ONCE; later callers attach). */
226
+ export declare function initSelfActionGovernor(deps: SelfActionGovernorDeps): SelfActionGovernorCore;
227
+ /** The live core (route/advert/guard read surfaces). */
228
+ export declare function getSelfActionGovernor(): SelfActionGovernorCore;
229
+ /** Sink-side consume (FD6 — the runtime authority). Sinks pin their expected
230
+ * controllerId module-side. */
231
+ export declare function consumeAdmissionToken(token: AdmissionToken | null | undefined, expectedControllerId: string, opts?: {
232
+ targetKey?: string;
233
+ nowMs?: number;
234
+ }): {
235
+ proceed: boolean;
236
+ valid: boolean;
237
+ reason?: string;
238
+ };
239
+ /** Test-only: drop the module-level core so a fixture can re-instantiate
240
+ * (pairs with anchor.resetAnchorForTest — SC9-1). */
241
+ export declare function resetSelfActionGovernorModuleForTest(): void;
242
+ //# sourceMappingURL=governor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"governor.d.ts","sourceRoot":"","sources":["../../../src/monitoring/selfaction/governor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA+BH,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,SAAS,EAET,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAEhB,aAAa,EACb,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAMpB,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB;;oCAEgC;IAChC,oBAAoB,EAAE,MAAM,OAAO,CAAC;IACpC;6DACyD;IACzD,iBAAiB,EAAE,MAAM,OAAO,CAAC;IACjC;6EACyE;IACzE,UAAU,CAAC,EAAE,MAAM,eAAe,GAAG,IAAI,CAAC;IAC1C,gEAAgE;IAChE,oBAAoB,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IAChD;iCAC6B;IAC7B,sBAAsB,CAAC,EAAE,MAAM,MAAM,CAAC;IACtC,4DAA4D;IAC5D,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,mCAAmC;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAgMD,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,CAAC;;IAqC1C;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,sBAAsB,GAAG,aAAa,GAAG,UAAU;IAgB9D,mFAAmF;IACnF,OAAO,IAAI,IAAI;IAgBf,OAAO,CAAC,GAAG;I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