@gridlock/orchestrator 0.1.0 → 0.2.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 (39) hide show
  1. package/dist/InteractionEvaluator.d.ts.map +1 -1
  2. package/dist/InteractionEvaluator.js +26 -0
  3. package/dist/InteractionEvaluator.js.map +1 -1
  4. package/dist/InteractionSeed.d.ts +43 -0
  5. package/dist/InteractionSeed.d.ts.map +1 -0
  6. package/dist/InteractionSeed.js +57 -0
  7. package/dist/InteractionSeed.js.map +1 -0
  8. package/dist/InventoryLedger.d.ts +58 -0
  9. package/dist/InventoryLedger.d.ts.map +1 -0
  10. package/dist/InventoryLedger.js +64 -0
  11. package/dist/InventoryLedger.js.map +1 -0
  12. package/dist/PlayerTurnLog.d.ts +78 -0
  13. package/dist/PlayerTurnLog.d.ts.map +1 -0
  14. package/dist/PlayerTurnLog.js +58 -0
  15. package/dist/PlayerTurnLog.js.map +1 -0
  16. package/dist/ReleaseConditions.d.ts +41 -0
  17. package/dist/ReleaseConditions.d.ts.map +1 -0
  18. package/dist/ReleaseConditions.js +86 -0
  19. package/dist/ReleaseConditions.js.map +1 -0
  20. package/dist/evaluation/Deadlines.d.ts +96 -0
  21. package/dist/evaluation/Deadlines.d.ts.map +1 -0
  22. package/dist/evaluation/Deadlines.js +94 -0
  23. package/dist/evaluation/Deadlines.js.map +1 -0
  24. package/dist/evaluation/index.d.ts +2 -0
  25. package/dist/evaluation/index.d.ts.map +1 -1
  26. package/dist/evaluation/index.js +1 -0
  27. package/dist/evaluation/index.js.map +1 -1
  28. package/dist/handlers/IntentInterpreter.d.ts +140 -0
  29. package/dist/handlers/IntentInterpreter.d.ts.map +1 -0
  30. package/dist/handlers/IntentInterpreter.js +90 -0
  31. package/dist/handlers/IntentInterpreter.js.map +1 -0
  32. package/dist/index.d.ts +10 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +11 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/types.d.ts +80 -1
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/types.js.map +1 -1
  39. package/package.json +6 -6
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Deadlines — wall-clock deadline definitions + pure schedule computation.
3
+ *
4
+ * Core-Configure split (same contract as EscalationClock):
5
+ * - Engine provides: the typed deadline shape, schedule computation,
6
+ * due-event selection, and stable fired-event keys.
7
+ * - Product provides: the authored definitions (offsets, messages,
8
+ * consequences), the wall-clock sweep that polls `dueDeadlineEvents`,
9
+ * and the delivery/consequence wiring.
10
+ *
11
+ * Why this is NOT part of the clock loop: the escalation clock is
12
+ * action-cost-based — it advances only inside command processing. Real
13
+ * time passing with zero player actions touches nothing in the engine.
14
+ * Wall-clock pressure therefore lives OUTSIDE the engine loop: a host
15
+ * process computes the schedule once from the session's start time and
16
+ * polls it on its own cadence. Everything here is pure and clock-free
17
+ * (callers pass `nowMs`), so hosts and tests control time explicitly.
18
+ *
19
+ * Deadlines are authored as OFFSETS from session start, never absolute
20
+ * times — scenarios are replayable, and an absolute authored time would
21
+ * be stale on every run after the first.
22
+ */
23
+ /** What happens when a deadline expires un-met. */
24
+ export type DeadlineConsequence =
25
+ /**
26
+ * Burn `units` off the action-cost clock — pressure escalates through
27
+ * the existing phase machinery, and evaluation-time grade impact falls
28
+ * out of the clock state as usual. No new truth vocabulary.
29
+ */
30
+ {
31
+ kind: 'advance-clock';
32
+ units: number;
33
+ }
34
+ /** Message-only escalation: the host delivers the expiry message, nothing mechanical changes. */
35
+ | {
36
+ kind: 'narrative-only';
37
+ };
38
+ /** One authored wall-clock deadline. */
39
+ export interface DeadlineDefinition {
40
+ /** Unique (per scenario) deadline identifier. */
41
+ id: string;
42
+ /** Minutes after session start when the deadline expires. Must be > 0. */
43
+ offsetMinutes: number;
44
+ /**
45
+ * Reminder lead times, in minutes before expiry. Each must be > 0 and
46
+ * < offsetMinutes (a reminder scheduled at or after expiry is dropped
47
+ * defensively by `computeDeadlineSchedule`).
48
+ */
49
+ reminderMinutesBefore: number[];
50
+ /** The pressure message delivered at reminders and expiry. */
51
+ message: string;
52
+ /** What expiry does. */
53
+ consequence: DeadlineConsequence;
54
+ }
55
+ /** One concrete scheduled firing derived from a definition. */
56
+ export interface DeadlineEvent {
57
+ deadlineId: string;
58
+ kind: 'reminder' | 'expiry';
59
+ /** Absolute wall-clock ms when this event is due. */
60
+ dueAtMs: number;
61
+ /** Reminder lead time (reminders only). */
62
+ minutesBefore?: number;
63
+ /** The authored message. */
64
+ message: string;
65
+ /** Present on expiry events only. */
66
+ consequence?: DeadlineConsequence;
67
+ }
68
+ /**
69
+ * Stable identity for a scheduled event, for at-most-once firing across
70
+ * host restarts: persist the keys of fired events and pass them back as
71
+ * `firedKeys`. Keys are derived from authored data only (never from
72
+ * wall-clock values), so a recomputed schedule after a restart yields
73
+ * identical keys.
74
+ */
75
+ export declare function deadlineEventKey(event: Pick<DeadlineEvent, 'deadlineId' | 'kind' | 'minutesBefore'>): string;
76
+ /**
77
+ * Expand definitions into the full firing schedule for one session,
78
+ * sorted by due time (ties: reminders before expiries, then definition
79
+ * order). Defensive drops, rather than throws, for authored data that
80
+ * validation should have caught: non-positive offsets drop the whole
81
+ * definition; reminders at/after expiry or non-positive drop that
82
+ * reminder; duplicate reminder lead times collapse to one.
83
+ */
84
+ export declare function computeDeadlineSchedule(definitions: readonly DeadlineDefinition[], sessionStartMs: number): DeadlineEvent[];
85
+ /**
86
+ * The events due at `nowMs` that have not fired yet. `firedKeys` is the
87
+ * host-persisted set of `deadlineEventKey` values — passing it back in
88
+ * makes the poll idempotent across sweeps AND restarts (the restart-safe
89
+ * at-most-once contract the host's durable store provides).
90
+ *
91
+ * Late events are still returned (a sweep that was down for an hour
92
+ * fires everything that came due meanwhile, in order) — the host decides
93
+ * whether stale reminders are worth sending; expiries always are.
94
+ */
95
+ export declare function dueDeadlineEvents(schedule: readonly DeadlineEvent[], nowMs: number, firedKeys: ReadonlySet<string>): DeadlineEvent[];
96
+ //# sourceM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GASG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,GAC7B,aAAa,EAAE,CAIjB"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Deadlines — wall-clock deadline definitions + pure schedule computation.
3
+ *
4
+ * Core-Configure split (same contract as EscalationClock):
5
+ * - Engine provides: the typed deadline shape, schedule computation,
6
+ * due-event selection, and stable fired-event keys.
7
+ * - Product provides: the authored definitions (offsets, messages,
8
+ * consequences), the wall-clock sweep that polls `dueDeadlineEvents`,
9
+ * and the delivery/consequence wiring.
10
+ *
11
+ * Why this is NOT part of the clock loop: the escalation clock is
12
+ * action-cost-based — it advances only inside command processing. Real
13
+ * time passing with zero player actions touches nothing in the engine.
14
+ * Wall-clock pressure therefore lives OUTSIDE the engine loop: a host
15
+ * process computes the schedule once from the session's start time and
16
+ * polls it on its own cadence. Everything here is pure and clock-free
17
+ * (callers pass `nowMs`), so hosts and tests control time explicitly.
18
+ *
19
+ * Deadlines are authored as OFFSETS from session start, never absolute
20
+ * times — scenarios are replayable, and an absolute authored time would
21
+ * be stale on every run after the first.
22
+ */
23
+ const MS_PER_MINUTE = 60_000;
24
+ /**
25
+ * Stable identity for a scheduled event, for at-most-once firing across
26
+ * host restarts: persist the keys of fired events and pass them back as
27
+ * `firedKeys`. Keys are derived from authored data only (never from
28
+ * wall-clock values), so a recomputed schedule after a restart yields
29
+ * identical keys.
30
+ */
31
+ export function deadlineEventKey(event) {
32
+ return event.kind === 'reminder'
33
+ ? `${event.deadlineId}:reminder:${event.minutesBefore}`
34
+ : `${event.deadlineId}:expiry`;
35
+ }
36
+ /**
37
+ * Expand definitions into the full firing schedule for one session,
38
+ * sorted by due time (ties: reminders before expiries, then definition
39
+ * order). Defensive drops, rather than throws, for authored data that
40
+ * validation should have caught: non-positive offsets drop the whole
41
+ * definition; reminders at/after expiry or non-positive drop that
42
+ * reminder; duplicate reminder lead times collapse to one.
43
+ */
44
+ export function computeDeadlineSchedule(definitions, sessionStartMs) {
45
+ const events = [];
46
+ for (const def of definitions) {
47
+ if (!Number.isFinite(def.offsetMinutes) || def.offsetMinutes <= 0)
48
+ continue;
49
+ const expiryAtMs = sessionStartMs + def.offsetMinutes * MS_PER_MINUTE;
50
+ const seenLeads = new Set();
51
+ for (const lead of def.reminderMinutesBefore) {
52
+ if (!Number.isFinite(lead) || lead <= 0 || lead >= def.offsetMinutes)
53
+ continue;
54
+ if (seenLeads.has(lead))
55
+ continue;
56
+ seenLeads.add(lead);
57
+ events.push({
58
+ deadlineId: def.id,
59
+ kind: 'reminder',
60
+ dueAtMs: expiryAtMs - lead * MS_PER_MINUTE,
61
+ minutesBefore: lead,
62
+ message: def.message,
63
+ });
64
+ }
65
+ events.push({
66
+ deadlineId: def.id,
67
+ kind: 'expiry',
68
+ dueAtMs: expiryAtMs,
69
+ message: def.message,
70
+ consequence: def.consequence,
71
+ });
72
+ }
73
+ return events.sort((a, b) => {
74
+ if (a.dueAtMs !== b.dueAtMs)
75
+ return a.dueAtMs - b.dueAtMs;
76
+ if (a.kind !== b.kind)
77
+ return a.kind === 'reminder' ? -1 : 1;
78
+ return 0;
79
+ });
80
+ }
81
+ /**
82
+ * The events due at `nowMs` that have not fired yet. `firedKeys` is the
83
+ * host-persisted set of `deadlineEventKey` values — passing it back in
84
+ * makes the poll idempotent across sweeps AND restarts (the restart-safe
85
+ * at-most-once contract the host's durable store provides).
86
+ *
87
+ * Late events are still returned (a sweep that was down for an hour
88
+ * fires everything that came due meanwhile, in order) — the host decides
89
+ * whether stale reminders are worth sending; expiries always are.
90
+ */
91
+ export function dueDeadlineEvents(schedule, nowMs, firedKeys) {
92
+ return schedule.filter((event) => event.dueAtMs <= nowMs && !firedKeys.has(deadlineEventKey(event)));
93
+ }
94
+ //# sourceMappingURL=Deadlines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Deadlines.js","sourceRoot":"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OAAO,EAAE,GAAG,CAAC,OAAO;aACrB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,CAAC,IAAI,CAAC;YACV,UAAU,EAAE,GAAG,CAAC,EAAE;YAClB,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,UAAU;YACnB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,WAAW,EAAE,GAAG,CAAC,WAAW;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1B,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO;YAAE,OAAO,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;QAC1D,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI;YAAE,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7D,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAAkC,EAClC,KAAa,EACb,SAA8B;IAE9B,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC"}
@@ -5,4 +5,6 @@ export { computeModifiers } from './WorldState.js';
5
5
  export type { WorldStateModifiers } from './WorldState.js';
6
6
  export { createClock, getActionCost, advanceClock, getClockStatusLabel, isOverrun, TIC_CLOCK_CONFIG } from './EscalationClock.js';
7
7
  export type { GameClock, EscalationPhase, ClockConfig, PhaseDefinition } from './EscalationClock.js';
8
+ export { computeDeadlineSchedule, dueDeadlineEvents, deadlineEventKey, } from './Deadlines.js';
9
+ export type { DeadlineConsequence, DeadlineDefinition, DeadlineEvent, } from './Deadlines.js';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evaluation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC1G,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC7G,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAClI,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evaluation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC1G,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC7G,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAClI,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrG,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,GACd,MAAM,gBAAgB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export { generatePerformanceReport, deriveGrade, TIC_EVALUATION_CONFIG } from './PerformanceEvaluator.js';
2
2
  export { computeModifiers } from './WorldState.js';
3
3
  export { createClock, getActionCost, advanceClock, getClockStatusLabel, isOverrun, TIC_CLOCK_CONFIG } from './EscalationClock.js';
4
+ export { computeDeadlineSchedule, dueDeadlineEvents, deadlineEventKey, } from './Deadlines.js';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/evaluation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAG1G,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/evaluation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAG1G,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAElI,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * IntentInterpreter — generic AI Assistant intent-classification primitive.
3
+ *
4
+ * An engine-level extension of the AI Assistant surface (alongside
5
+ * {@link AssistantCommandRegistry}). Products that host a natural-language
6
+ * assistant (e.g. TIC's SAGE) configure this primitive with a product-
7
+ * specific intent schema and a fallback regex ruleset; the engine owns
8
+ * the classification flow, LLM invocation, confidence threshold, and
9
+ * fallback ladder.
10
+ *
11
+ * Design rules:
12
+ * - Zero product vocabulary. The generic `TIntent` type is supplied by the
13
+ * product; the engine never looks inside it.
14
+ * - No zod dependency. Products plug in their own validator/parser.
15
+ * - Fallback ladder: LLM → regex rules → product-supplied clarify intent.
16
+ * - LLM output under the confidence threshold is treated as a failed
17
+ * classification and falls through to regex.
18
+ */
19
+ import type { LLMAdapter } from '../types.js';
20
+ /**
21
+ * Read-only context passed into every classification call. Engine-generic:
22
+ * just a roster of addressable entities (NPCs in TIC, whatever the product
23
+ * calls them) plus the last-addressed id for target inference.
24
+ */
25
+ export interface IntentContext {
26
+ /** Entities the player can address. Engine uses `id` + `displayName`/`aliases` for target resolution. */
27
+ readonly roster: ReadonlyArray<IntentRosterEntry>;
28
+ /** The most-recently-addressed entity id, or null. Used to infer targets for pronoun-style input ("push back on him"). */
29
+ readonly lastAddressedId: string | null;
30
+ /** Command names available to the assistant (surfaced in the prompt so the LLM sees the vocabulary). */
31
+ readonly availableCommands: ReadonlyArray<string>;
32
+ /** Optional tone/register hint for the prompt (e.g. 'noir', 'procedural'). */
33
+ readonly registerHint?: string;
34
+ }
35
+ export interface IntentRosterEntry {
36
+ readonly id: string;
37
+ readonly displayName: string;
38
+ readonly aliases?: ReadonlyArray<string>;
39
+ }
40
+ export type IntentSource = 'llm' | 'regex' | 'clarify';
41
+ export interface ClassifiedIntent<TIntent> {
42
+ readonly intent: TIntent;
43
+ /** 0..1. LLM classifiers produce a real confidence; regex rules default to 0.6 unless set. */
44
+ readonly confidence: number;
45
+ /** Which branch of the ladder produced the result. */
46
+ readonly source: IntentSource;
47
+ }
48
+ /**
49
+ * A regex rule in the fallback ladder. Rules are evaluated in order; the
50
+ * first match wins. `build` converts the match into the product's intent
51
+ * shape.
52
+ */
53
+ export interface RegexIntentRule<TIntent> {
54
+ readonly pattern: RegExp;
55
+ readonly build: (match: RegExpMatchArray, input: string, ctx: IntentContext) => TIntent;
56
+ /** Confidence emitted when this rule fires. Defaults to 0.6. */
57
+ readonly confidence?: number;
58
+ }
59
+ /**
60
+ * Parsed LLM classification result before confidence gating. Products
61
+ * implement `parseLlmResponse` to turn raw LLM text into this shape.
62
+ * Return `null` when the response is malformed or not parseable.
63
+ */
64
+ export interface ParsedLlmClassification<TIntent> {
65
+ readonly intent: TIntent;
66
+ /** 0..1 confidence the LLM self-reports. */
67
+ readonly confidence: number;
68
+ }
69
+ export interface IntentInterpreterOptions<TIntent> {
70
+ /**
71
+ * Build the LLM prompt string from the raw input + context. Product owns
72
+ * tone, schema description, and JSON-shape instructions.
73
+ */
74
+ readonly buildPrompt: (input: string, ctx: IntentContext) => string;
75
+ /**
76
+ * Parse raw LLM response text into a classification. Return null on
77
+ * malformed output; the interpreter falls through to regex.
78
+ */
79
+ readonly parseLlmResponse: (raw: string) => ParsedLlmClassification<TIntent> | null;
80
+ /**
81
+ * Ordered regex fallback rules. Evaluated after LLM failure / low
82
+ * confidence. First match wins.
83
+ */
84
+ readonly regexRules: ReadonlyArray<RegexIntentRule<TIntent>>;
85
+ /**
86
+ * Product constructor for the "I didn't understand, please clarify"
87
+ * intent. Invoked when no rule matches and the LLM is unavailable or
88
+ * failed. `reason` is a short machine-readable tag for telemetry.
89
+ */
90
+ readonly buildClarifyIntent: (reason: ClarifyReason, input: string, ctx: IntentContext) => TIntent;
91
+ /**
92
+ * Optional LLM adapter. When absent, the interpreter skips the LLM
93
+ * branch and goes straight to regex.
94
+ */
95
+ readonly llmAdapter?: LLMAdapter;
96
+ /**
97
+ * Confidence threshold below which LLM results are discarded and the
98
+ * regex ladder runs instead. Defaults to {@link DEFAULT_MIN_CONFIDENCE}.
99
+ */
100
+ readonly minConfidence?: number;
101
+ /**
102
+ * Optional agent definition / merged persona passed through to the LLM
103
+ * adapter's `execute` call. Products that wire through the full
104
+ * agent-orchestrator pipeline pass these; simple products can omit
105
+ * them (the adapter receives empty records).
106
+ */
107
+ readonly agentDefinition?: Record<string, unknown>;
108
+ readonly mergedPersona?: Record<string, unknown>;
109
+ }
110
+ /** Short tags for the {@link IntentInterpreterOptions.buildClarifyIntent} `reason` parameter. */
111
+ export type ClarifyReason = 'llm-unavailable' | 'llm-parse-failed' | 'llm-low-confidence' | 'llm-threw' | 'regex-no-match';
112
+ /** Fixed confidence threshold per the stack plan (#1263 generalisation). */
113
+ export declare const DEFAULT_MIN_CONFIDENCE = 0.7;
114
+ /** Default confidence emitted by regex-matched rules. */
115
+ export declare const DEFAULT_REGEX_CONFIDENCE = 0.6;
116
+ /**
117
+ * Engine-level intent interpreter. Instantiated once per product-specific
118
+ * assistant (TIC's SAGE, Gridlock's game-agnostic advisor, etc.) and reused
119
+ * across calls.
120
+ */
121
+ export declare class IntentInterpreter<TIntent> {
122
+ private readonly opts;
123
+ private readonly minConfidence;
124
+ constructor(opts: IntentInterpreterOptions<TIntent>);
125
+ /**
126
+ * Classify `input` against the product's intent schema. Runs the
127
+ * fallback ladder:
128
+ *
129
+ * 1. If an LLM adapter is configured, prompt it and parse the response.
130
+ * - Parse failure → fall to step 2.
131
+ * - Confidence >= threshold → return (source: 'llm').
132
+ * - Confidence < threshold → fall to step 2.
133
+ * 2. Walk regex rules in order. First match → return (source: 'regex').
134
+ * 3. No match → return the product-supplied clarify intent (source: 'clarify').
135
+ */
136
+ interpret(input: string, ctx: IntentContext): Promise<ClassifiedIntent<TIntent>>;
137
+ private tryLlm;
138
+ private tryRegex;
139
+ }
140
+ //# sourceMappingURL=IntentInterpreter.d.ts.map
@@ -0,0 +1 @@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;;;GAIG;AACH,qBAAa,iBAAiB,CAAC,OAAO;IAGxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAEV,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC;IAIpE;;;;;;;;;;OAUG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAoBxE,MAAM;IAgCpB,OAAO,CAAC,QAAQ;CAajB"}
@@ -0,0 +1,90 @@
1
+ // @engine — Generic NL-to-intent interpreter primitive. No product vocabulary;
2
+ // products supply the intent shape, prompt template, response parser, and
3
+ // regex fallback rules.
4
+ /** Fixed confidence threshold per the stack plan (#1263 generalisation). */
5
+ export const DEFAULT_MIN_CONFIDENCE = 0.7;
6
+ /** Default confidence emitted by regex-matched rules. */
7
+ export const DEFAULT_REGEX_CONFIDENCE = 0.6;
8
+ // ---------------------------------------------------------------------------
9
+ // Interpreter
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * Engine-level intent interpreter. Instantiated once per product-specific
13
+ * assistant (TIC's SAGE, Gridlock's game-agnostic advisor, etc.) and reused
14
+ * across calls.
15
+ */
16
+ export class IntentInterpreter {
17
+ opts;
18
+ minConfidence;
19
+ constructor(opts) {
20
+ this.opts = opts;
21
+ this.minConfidence = opts.minConfidence ?? DEFAULT_MIN_CONFIDENCE;
22
+ }
23
+ /**
24
+ * Classify `input` against the product's intent schema. Runs the
25
+ * fallback ladder:
26
+ *
27
+ * 1. If an LLM adapter is configured, prompt it and parse the response.
28
+ * - Parse failure → fall to step 2.
29
+ * - Confidence >= threshold → return (source: 'llm').
30
+ * - Confidence < threshold → fall to step 2.
31
+ * 2. Walk regex rules in order. First match → return (source: 'regex').
32
+ * 3. No match → return the product-supplied clarify intent (source: 'clarify').
33
+ */
34
+ async interpret(input, ctx) {
35
+ if (this.opts.llmAdapter) {
36
+ const llmResult = await this.tryLlm(input, ctx);
37
+ if (llmResult)
38
+ return llmResult;
39
+ }
40
+ const regexResult = this.tryRegex(input, ctx);
41
+ if (regexResult)
42
+ return regexResult;
43
+ return {
44
+ intent: this.opts.buildClarifyIntent(this.opts.llmAdapter ? 'regex-no-match' : 'llm-unavailable', input, ctx),
45
+ confidence: 0,
46
+ source: 'clarify',
47
+ };
48
+ }
49
+ async tryLlm(input, ctx) {
50
+ const prompt = this.opts.buildPrompt(input, ctx);
51
+ let raw;
52
+ try {
53
+ const result = await this.opts.llmAdapter.execute({
54
+ contextPackage: { input, prompt, roster: ctx.roster, lastAddressedId: ctx.lastAddressedId },
55
+ agentDefinition: this.opts.agentDefinition ?? {},
56
+ mergedPersona: this.opts.mergedPersona ?? {},
57
+ });
58
+ raw = result.responseText;
59
+ }
60
+ catch {
61
+ // LLM threw — fall through to regex. Clarify reason captured if
62
+ // the ladder exhausts.
63
+ return null;
64
+ }
65
+ const parsed = this.opts.parseLlmResponse(raw);
66
+ if (!parsed)
67
+ return null;
68
+ if (parsed.confidence < this.minConfidence)
69
+ return null;
70
+ return {
71
+ intent: parsed.intent,
72
+ confidence: parsed.confidence,
73
+ source: 'llm',
74
+ };
75
+ }
76
+ tryRegex(input, ctx) {
77
+ for (const rule of this.opts.regexRules) {
78
+ const match = input.match(rule.pattern);
79
+ if (match) {
80
+ return {
81
+ intent: rule.build(match, input, ctx),
82
+ confidence: rule.confidence ?? DEFAULT_REGEX_CONFIDENCE,
83
+ source: 'regex',
84
+ };
85
+ }
86
+ }
87
+ return null;
88
+ }
89
+ }
90
+ //# sourceMappingURL=IntentInterpreter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntentInterpreter.js","sourceRoot":"","sources":["../../src/handlers/IntentInterpreter.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,0EAA0E;AAC1E,wBAAwB;AA4IxB,4EAA4E;AAC5E,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC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from './EvidenceGraph.js';
39
39
  export { getEntityKnowledgeView } from './KnowledgeBoundary.js';
40
40
  export type { EntityKnowledgeView, AuthoredKnowledge, EntityFact, KnowledgeDisclosure, KnowledgeBoundaryInput, } from './KnowledgeBoundary.js';
41
41
  export { DisclosureEngine } from './DisclosureEngine.js';
42
+ export { isReleaseConditionMet, matchTopics, deriveTopicsFromLabel, } from './ReleaseConditions.js';
43
+ export type { ReleaseContext } from './ReleaseConditions.js';
42
44
  export type { VisibilityState, VisibilityTransition, RevealTrigger, RevealInstruction, DisclosureEngineConfig, TransitionNotifier, DisclosureSnapshot, } from './DisclosureEngine.js';
43
45
  export { evaluateInteraction, getSensitivityMultiplier, buildRiceProfile, UNBLOCK_BASELINE, MAX_PER_ACTION_GAIN, RICE_BASE_GAINS, } from './InteractionEvaluator.js';
44
46
  export type { CharacterRiceProfile, InteractionResult, } from './InteractionEvaluator.js';
47
+ export { applyInteractionSeed } from './InteractionSeed.js';
48
+ export type { InteractionSeed } from './InteractionSeed.js';
49
+ export { InMemoryPlayerTurnLog } from './PlayerTurnLog.js';
50
+ export type { PlayerTurnLog, PlayerTurnEntry, PlayerTurnEntryInput, } from './PlayerTurnLog.js';
51
+ export { InMemoryInventoryLedger } from './InventoryLedger.js';
52
+ export type { InventoryLedger } from './InventoryLedger.js';
45
53
  export { AssistantCommandRegistry, type AssistantCommand, type CommandTier, } from './handlers/AssistantCommandRegistry.js';
54
+ export { IntentInterpreter, DEFAULT_MIN_CONFIDENCE, DEFAULT_REGEX_CONFIDENCE, } from './handlers/IntentInterpreter.js';
55
+ export type { IntentContext, IntentRosterEntry, IntentSource, ClassifiedIntent, RegexIntentRule, ParsedLlmClassification, IntentInterpreterOptions, ClarifyReason, } from './handlers/IntentInterpreter.js';
46
56
  export * from './handlers/ResolutionGate.js';
47
57
  export * from './handlers/GameLifecycle.js';
48
58
  export { SourceTypeRegistry, sourceTypeRegistry, ingestFinding, } from './handlers/EvidenceIngestion.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGlE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGtF,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,GAChB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,oBAAoB,EACpB,iBAAiB,GACl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;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,GACd,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGzE,cAAc,uBAAuB,CAAC;AAGtC,cAAc,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -39,10 +39,21 @@ export * from './AgentRoute.js';
39
39
  export { EvidenceGraph } from './EvidenceGraph.js';
40
40
  export { getEntityKnowledgeView } from './KnowledgeBoundary.js';
41
41
  export { DisclosureEngine } from './DisclosureEngine.js';
42
+ export { isReleaseConditionMet, matchTopics, deriveTopicsFromLabel, } from './ReleaseConditions.js';
42
43
  // RICE interaction evaluator (step 5.3)
43
44
  export { evaluateInteraction, getSensitivityMultiplier, buildRiceProfile, UNBLOCK_BASELINE, MAX_PER_ACTION_GAIN, RICE_BASE_GAINS, } from './InteractionEvaluator.js';
45
+ // Interaction-state seed (Core-Configure seam for inter-case relationship state)
46
+ export { applyInteractionSeed } from './InteractionSeed.js';
47
+ // Per-session player-turn log (engine-generic capture seam for post-case
48
+ // craft scoring — TIC's Tradecraft Trainer is the first consumer)
49
+ export { InMemoryPlayerTurnLog } from './PlayerTurnLog.js';
50
+ // Per-player item inventory (engine-generic backing for the RICE-aligned
51
+ // `/gift` flow + #1874's `@gridlock/economy` `InventoryStore` shape).
52
+ // MS-27b #1872.
53
+ export { InMemoryInventoryLedger } from './InventoryLedger.js';
44
54
  // Engine handlers (step 5.4, 5.8)
45
55
  export { AssistantCommandRegistry, } from './handlers/AssistantCommandRegistry.js';
56
+ export { IntentInterpreter, DEFAULT_MIN_CONFIDENCE, DEFAULT_REGEX_CONFIDENCE, } from './handlers/IntentInterpreter.js';
46
57
  export * from './handlers/ResolutionGate.js';
47
58
  export * from './handlers/GameLifecycle.js';
48
59
  export { SourceTypeRegistry, sourceTypeRegistry, ingestFinding, } from './handlers/EvidenceIngestion.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AA0BH,kDAAkD;AAClD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAElE,mDAAmD;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,2CAA2C;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAQhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAWzD,wCAAwC;AACxC,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,GAChB,MAAM,2BAA2B,CAAC;AAMnC,kCAAkC;AAClC,OAAO,EACL,wBAAwB,GAGzB,MAAM,wCAAwC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,GACd,MAAM,iCAAiC,CAAC;AAKzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,mCAAmC;AACnC,cAAc,uBAAuB,CAAC;AAEtC,kDAAkD;AAClD,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AA0BH,kDAAkD;AAClD,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AAkD;AAClD,cAAc,0BAA0B,CAAC"}
package/dist/types.d.ts CHANGED
@@ -43,6 +43,14 @@ export interface InteractionSignal {
43
43
  intensity: number;
44
44
  targetCharacterId: string;
45
45
  timestamp: number;
46
+ /**
47
+ * Optional RICE-dimension override for item-aware gift signals
48
+ * (#1872, MS-27b). When `subtype === 'item_gift'`, the evaluator
49
+ * routes the gain to this dimension instead of the default
50
+ * `'incentive'` so a `riceDimension: 'ego'` shop-item produces an
51
+ * ego boost, etc. Other subtypes ignore this field.
52
+ */
53
+ riceDimensionOverride?: keyof RiceProgress;
46
54
  }
47
55
  /**
48
56
  * Per-dimension RICE progress scores (0–10).
@@ -134,8 +142,43 @@ export interface NarrativeDispatchHookInput {
134
142
  caseId?: string;
135
143
  recipientPlayerId: string;
136
144
  }
145
+ /**
146
+ * Engine-emitted typed event kinds (#1201, MS-25d). Names are engine-neutral;
147
+ * typed payload shapes live in product-layer packages. The engine itself
148
+ * passes `Record<string, unknown>` and the hook narrows.
149
+ */
150
+ export type NarrativeEventKind = 'sage.analysis' | 'investigation.findings' | 'investigation.fact-recorded' | 'clock.pressure' | 'milestone.progress' | 'resolution.report';
151
+ export interface NarrativeDispatchContext {
152
+ recipientPlayerId: string;
153
+ caseId?: string;
154
+ sourceCharacterId?: string | null;
155
+ sourceCharacterTier?: string;
156
+ }
157
+ /**
158
+ * Delivery receipt returned by a NarrativeDispatchHook (#1211, MS-25d).
159
+ *
160
+ * - `delivered` — transport accepted the message.
161
+ * - `deferred` — transient failure the adapter expects to recover from.
162
+ * - `failed` — permanent delivery failure; no retry will succeed.
163
+ */
164
+ export interface DeliveryReceipt {
165
+ status: 'delivered' | 'deferred' | 'failed';
166
+ providerMessageId?: string;
167
+ error?: {
168
+ code: string;
169
+ message: string;
170
+ };
171
+ }
172
+ export type DispatchReturn = void | DeliveryReceipt | Promise<DeliveryReceipt | void>;
137
173
  export interface NarrativeDispatchHook {
138
- onCharacterDialogue(input: NarrativeDispatchHookInput): void;
174
+ onCharacterDialogue(input: NarrativeDispatchHookInput): DispatchReturn;
175
+ /**
176
+ * Generic typed-event dispatch (#1201). Optional — implementations that
177
+ * only handle dialogue may omit this method. Callers MUST treat absence
178
+ * as a no-op. Implementations MUST NOT throw. A returned Promise is
179
+ * captured without awaiting on the hot path (#1211).
180
+ */
181
+ dispatch?(kind: NarrativeEventKind | string, payload: Record<string, unknown>, ctx: NarrativeDispatchContext): DispatchReturn;
139
182
  }
140
183
  /**
141
184
  * ScenarioLoader — abstraction for loading and parsing scenario data.
@@ -258,6 +301,19 @@ export interface EngineState {
258
301
  /** Findings produced by the evidence pipeline (facts → validators → findings). */
259
302
  findings: import('@gridlock/validators').Finding[];
260
303
  /** Core evidence graph structure. */
304
+ /**
305
+ * The authored case graph (#2395, Phase 0 of the progress unlock graph).
306
+ * Seeded verbatim from the scenario's evidenceGraph at load and treated
307
+ * as read-only world truth: unlock edges are evaluated against it, and
308
+ * NPC visibility BFS traverses it. Never mutated at runtime.
309
+ */
310
+ authoredGraph: import('./EvidenceGraph.js').EvidenceGraph;
311
+ /**
312
+ * The player-discovered graph (#2395). Starts EMPTY at load — runtime
313
+ * population (talk / examine / findings) writes here. Player-facing
314
+ * views (graph command, DiscoveryLayer) read this, so authored-but-
315
+ * unreached content can no longer leak at turn 0.
316
+ */
261
317
  discoveredGraph: import('./EvidenceGraph.js').EvidenceGraph;
262
318
  /** Objective evidence store (core truth layer). */
263
319
  factLedger: import('./investigation/FactLedger.js').FactLedger;
@@ -279,5 +335,28 @@ export interface EngineState {
279
335
  lastPerformanceReport?: import('./evaluation/index.js').PerformanceReport;
280
336
  /** World-state modifiers from evaluation. */
281
337
  appliedModifiers?: import('./evaluation/index.js').WorldStateModifiers;
338
+ /**
339
+ * Delivery receipts for outbound narrative dispatch (#1211, MS-25d).
340
+ *
341
+ * Populated asynchronously by the Orchestrator when a NarrativeDispatchHook
342
+ * returns (or resolves to) a DeliveryReceipt. Writes happen after the
343
+ * command return path so the hot path is never blocked. Consumers (notes,
344
+ * casefile, debug views) read this to annotate failed/deferred deliveries.
345
+ */
346
+ deliveryReceipts: DeliveryReceiptRecord[];
347
+ }
348
+ /**
349
+ * One observed dispatch outcome (#1211). Captured whether or not delivery
350
+ * succeeded; failures and deferrals surface to the player in notes/casefile.
351
+ */
352
+ export interface DeliveryReceiptRecord {
353
+ /** Engine event kind — 'dialogue.response' for character dialogue, or a NarrativeEventKind. */
354
+ kind: string;
355
+ /** Engine-side target identifier: characterId for dialogue, sourceCharacterId for typed events, or null for system-sourced events. */
356
+ targetId: string | null;
357
+ /** The dispatch receipt. */
358
+ receipt: DeliveryReceipt;
359
+ /** Wall-clock time when the receipt was recorded. */
360
+ recordedAt: Date;
282
361
  }
283
362
  //# sourceMappingURL=types.d.ts.map