instar 1.3.660 → 1.3.662

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.
@@ -53,7 +53,72 @@ export interface ToneReviewResult {
53
53
  * tone authority could not run under capacity pressure.
54
54
  */
55
55
  capacityUnavailable?: boolean;
56
+ /**
57
+ * True when the gate HELD the message (pass=false) because a gating-LLM
58
+ * call dropped its verdict — a provider-exhaustion error, an unparseable
59
+ * response (after one retry), or the route-budget timeout elapsing with no
60
+ * verdict. Fail-CLOSED is the safe direction for a gating decision
61
+ * (No Silent Degradation). Distinct from capacityUnavailable (spawn-cap shed)
62
+ * and failedOpen (legacy permissive drop, now only on the invalid-rule
63
+ * re-prompt's benign branches). Spec: gate-prompts-judge-by-meaning §Design 6.
64
+ */
65
+ failedClosed?: boolean;
66
+ }
67
+ export declare const VALID_RULES: Set<string>;
68
+ /**
69
+ * Rule-class taxonomy (spec: gate-prompts-judge-by-meaning-not-literal-lists §Design 7).
70
+ *
71
+ * The boundary between rules whose prompt may LITERAL-match a deterministic
72
+ * artifact (`deterministic-detection`) and rules that must judge by MEANING
73
+ * (`behavioral-judgment`) is made STRUCTURAL here — a machine-readable source
74
+ * registry, NOT a `//` comment inside the prompt template literal (those would
75
+ * render into the prompt sent to the model). The forward ratchet
76
+ * (tests/unit/gate-prompts-judge-by-meaning.test.ts) keys off this map.
77
+ *
78
+ * Constitution standard: "Intelligent Prompts — An LLM Gate Must Not
79
+ * String-Match" (docs/STANDARDS-REGISTRY.md).
80
+ */
81
+ export type GateRuleClass = 'deterministic-detection' | 'signal-driven' | 'style' | 'health-alert' | 'behavioral-judgment' | 'parked-on-user';
82
+ export declare const RULE_CLASSES: Record<string, GateRuleClass>;
83
+ /** Phase-2 migration debt (CMT-1793): B1–B7 still literal-match in-prompt. */
84
+ export declare const PHASE2_MIGRATION_DEBT: {
85
+ rules: readonly ["B1_CLI_COMMAND", "B2_FILE_PATH", "B3_CONFIG_KEY", "B4_COPY_PASTE_CODE", "B5_API_ENDPOINT", "B6_ENV_VAR", "B7_CRON_OR_SLUG"];
86
+ commitment: string;
87
+ };
88
+ /** Deferred availability-aware kind-routing refinement (CMT-1794). Gate is fail-closed-compliant now. */
89
+ export declare const DEFERRED_REFINEMENT: {
90
+ paths: readonly ["provider-exhaustion", "json-parse", "route-budget-timeout"];
91
+ commitment: string;
92
+ };
93
+ /**
94
+ * The §Design 1 structured-intermediate the model emits for a self-stop (B15)
95
+ * judgment. The block/allow VERDICT is derived from these fields, which makes
96
+ * the decision testable and far less dependent on prose interpretation (the
97
+ * answer to the "prompt jurisprudence" concern). Optional — absent on a normal
98
+ * non-B15 verdict, in which case the legacy {pass,rule,issue,suggestion} path
99
+ * is used unchanged.
100
+ */
101
+ export interface StructuredVerdict {
102
+ proposed_stop: boolean;
103
+ deferred_items: string[];
104
+ stop_reason_kind: 'agent-state' | 'external-blocker' | 'design-fork' | 'completion' | 'operator-stop' | 'none' | string;
105
+ agent_state_reason_present: boolean;
106
+ external_blocker_present: boolean;
107
+ }
108
+ export interface ParsedToneResponse {
109
+ pass: boolean;
110
+ rule: string;
111
+ issue: string;
112
+ suggestion: string;
113
+ structured?: StructuredVerdict;
56
114
  }
115
+ /**
116
+ * A structured verdict is internally contradictory (a model-output-discipline
117
+ * failure) when its fields disagree — e.g. "no stop proposed" yet items are
118
+ * deferred, or "agent-state reason present" yet the stop is classified as a
119
+ * completion / none. Contradiction → re-prompt once → fail-closed (§Design 6).
120
+ */
121
+ export declare function structuredContradiction(s: StructuredVerdict): boolean;
57
122
  export interface ToneReviewContextMessage {
58
123
  role: 'user' | 'agent';
59
124
  text: string;
@@ -222,16 +287,74 @@ export interface ToneReviewContext {
222
287
  * scheduled-task sends (stamped by the scheduler env, not the model).
223
288
  */
224
289
  messageKind?: MessageKind;
290
+ /**
291
+ * Deterministic agent-state signal (spec §Design 1a). Detected OUTSIDE the
292
+ * prompt (in-process `readSessionClocks` at the route seam) and fed in as
293
+ * ground truth so B15 can judge a "near the limit" claim against reality
294
+ * instead of the agent's self-assessed prose. SCOPE: time-box claims only —
295
+ * it does NOT ground context-window / fatigue / clarity claims (no signal
296
+ * for those yet; CMT-1793). Absent → B15 falls back to meaning-only (the
297
+ * signal sharpens the verdict, it is never a necessary condition). Rendered
298
+ * in its own per-call boundary, treated as untrusted data.
299
+ */
300
+ agentState?: {
301
+ sessionElapsedMs: number;
302
+ sessionRemainingMs: number | null;
303
+ isTimeBoxed: boolean;
304
+ };
305
+ }
306
+ /** Tune knobs read live from InstarConfig.messaging.toneGate (spec §Design 6). */
307
+ export interface ToneGateConfig {
308
+ /**
309
+ * When true (DEFAULT), the provider-exhaustion and route-budget-timeout paths
310
+ * fail CLOSED (hold). Operator kill-switch: set false to revert THOSE two
311
+ * availability-sensitive paths to fail-open without a deploy (read live). The
312
+ * invalid-rule and JSON-parse fail-closeds are NOT switched (no availability
313
+ * cost — they fire only on a model that already decided to block / emitted
314
+ * unparseable output).
315
+ */
316
+ failClosedOnExhaustion?: boolean;
225
317
  }
226
318
  export declare class MessagingToneGate {
227
319
  private provider;
228
- constructor(provider: IntelligenceProvider);
320
+ private configOrGetter;
321
+ constructor(provider: IntelligenceProvider, config?: ToneGateConfig | (() => ToneGateConfig));
322
+ /** Resolve config live each review so the kill-switch is honored without a restart. */
323
+ private getConfig;
229
324
  review(text: string, context: ToneReviewContext): Promise<ToneReviewResult>;
325
+ /** Fail-CLOSED disposition (hold) — mirrors the capacity-shed sibling. */
326
+ private failClosed;
327
+ /**
328
+ * Turn a parsed response into a verdict OR signal that one re-prompt is
329
+ * warranted. `null` parsed = unparseable. Applies the §Design 1
330
+ * structured-intermediate: a contradictory structured verdict re-prompts,
331
+ * and a B15 stop the model's OWN structured reasoning flags
332
+ * (proposed_stop ∧ agent_state_reason_present) is derived to BLOCK even if
333
+ * the model set pass:true (the structured fields are the ground truth of its
334
+ * reasoning). Back-compat: when no structured block is present, behavior is
335
+ * exactly the legacy {pass,rule,issue,suggestion} path.
336
+ */
337
+ private interpret;
230
338
  private buildPrompt;
231
339
  private renderMessageKind;
232
340
  private renderSignals;
233
341
  private renderTargetStyle;
234
342
  private renderRecentMessages;
343
+ /**
344
+ * §Design 1a: the deterministic agent-state signal (session clock), rendered
345
+ * in its own per-call boundary as untrusted data. Grounds B15 TIME-BOX
346
+ * claims only. Absent → omitted (B15 falls back to meaning-only).
347
+ */
348
+ private renderAgentState;
349
+ /**
350
+ * Parse the model's JSON. Returns `null` on unparseable / malformed output
351
+ * (NOT a permissive fail-open) — review() treats null as a re-prompt → then
352
+ * fail-closed, so a model emitting garbage can never silently deliver an
353
+ * unreviewed message (No Silent Degradation §Design 6). The optional
354
+ * `structured` block (§Design 1) is type-clamped on the way in; the issue/
355
+ * suggestion are length-bounded (1–2 sentences) since they may be re-fed to
356
+ * the agent's rephrase loop as untrusted data (§Design 5).
357
+ */
235
358
  private parseResponse;
236
359
  }
237
360
  //# sourceMappingURL=MessagingToneGate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MessagingToneGate.d.ts","sourceRoot":"","sources":["../../src/core/MessagingToneGate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAUvD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uFAAuF;IACvF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CA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