@principles/host-runtime 3.4.1 → 4.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 (32) hide show
  1. package/dist/active-principle-prompt.d.ts +13 -0
  2. package/dist/active-principle-prompt.js +87 -10
  3. package/dist/adaptive-decision-protocol.d.ts +129 -0
  4. package/dist/adaptive-decision-protocol.js +176 -0
  5. package/dist/adaptive-priority-provider.d.ts +38 -13
  6. package/dist/adaptive-priority-provider.js +70 -66
  7. package/dist/adaptive-selection.d.ts +71 -64
  8. package/dist/adaptive-selection.js +220 -329
  9. package/dist/adaptive-skip-decision.d.ts +26 -14
  10. package/dist/adaptive-skip-decision.js +33 -29
  11. package/dist/codex-disclosure.d.ts +12 -7
  12. package/dist/codex-disclosure.js +12 -7
  13. package/dist/codex-rule-context-provider.js +4 -1
  14. package/dist/conversation-ingestion/pipeline.d.ts +8 -0
  15. package/dist/conversation-ingestion/pipeline.js +6 -1
  16. package/dist/conversation-ingestion/text-policy.d.ts +3 -4
  17. package/dist/conversation-ingestion/text-policy.js +3 -4
  18. package/dist/governance-observation-store.d.ts +73 -1
  19. package/dist/governance-observation-store.js +251 -14
  20. package/dist/governance-signal-admission.d.ts +19 -3
  21. package/dist/governance-signal-admission.js +12 -4
  22. package/dist/host-tool-declaration.d.ts +18 -2
  23. package/dist/host-tool-declaration.js +67 -11
  24. package/dist/host-tool-semantic-resolver.d.ts +7 -0
  25. package/dist/host-tool-semantic-resolver.js +22 -2
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.js +17 -0
  28. package/dist/production-rulehost-gate.d.ts +36 -1
  29. package/dist/production-rulehost-gate.js +106 -4
  30. package/dist/trajectory-retention.d.ts +147 -0
  31. package/dist/trajectory-retention.js +907 -0
  32. package/package.json +4 -4
@@ -3,89 +3,103 @@ import { ADAPTIVE_SELECTION_LIMITS, runAdaptiveSelection, } from './adaptive-sel
3
3
  import { decideAdaptiveSkip } from './adaptive-skip-decision.js';
4
4
  /** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
5
5
  export const ADAPTIVE_ACTIVATION_FLAG = 'host.codex.adaptive_activation';
6
- export function resolveAdaptiveSelectionModel(config, env) {
7
- const feature = config.features[ADAPTIVE_ACTIVATION_FLAG];
6
+ /**
7
+ * PRI-1182 §2: time kept back from the host window for the principle assembly
8
+ * and the hook's own output. Selection never spends the reserve.
9
+ */
10
+ export const ADAPTIVE_OUTPUT_RESERVE_MS = 200;
11
+ export function resolveAdaptiveSelectionModel(config, env, flag = ADAPTIVE_ACTIVATION_FLAG) {
12
+ const feature = config.features[flag];
8
13
  if (feature?.enabled !== true) {
9
14
  return {
10
15
  ok: false,
11
- reason: `${ADAPTIVE_ACTIVATION_FLAG} is disabled in .pd/config.yaml`,
12
- nextAction: `Enable it explicitly with ${ADAPTIVE_ACTIVATION_FLAG}: {enabled: true}`,
13
- };
14
- }
15
- const profileId = config.internalAgents.defaultRuntime;
16
- const profile = config.runtimeProfiles[profileId];
17
- if (!profile) {
18
- return {
19
- ok: false,
20
- reason: `Runtime profile '${profileId}' not found`,
21
- nextAction: `Add runtime profile '${profileId}' to runtimeProfiles`,
16
+ readiness: 'disabled',
17
+ reason: `${flag} is disabled in .pd/config.yaml`,
18
+ nextAction: `Enable it explicitly with ${flag}: {enabled: true}`,
22
19
  };
23
20
  }
24
- if (profile.type !== 'pi-ai') {
21
+ // PRI-1182: the Adaptive path has its OWN endpoint + model + credential
22
+ // reference. It no longer borrows a pi-ai runtime profile, because the
23
+ // Decisions protocol is a single scoring endpoint, not a chat completion.
24
+ const section = config.adaptiveActivation;
25
+ if (!section) {
25
26
  return {
26
27
  ok: false,
27
- reason: `Runtime profile '${profileId}' is '${profile.type}', not pi-ai`,
28
- nextAction: 'ADR-0029 requires a pi-ai runtime profile for adaptive selection',
28
+ readiness: 'needs_setup',
29
+ reason: 'adaptiveActivation is not configured in .pd/config.yaml',
30
+ nextAction: 'Add adaptiveActivation: {endpoint, model, apiKeyEnv} to .pd/config.yaml',
29
31
  };
30
32
  }
31
- if (!profile.provider || !profile.model || !profile.apiKeyEnv) {
33
+ if (!section.endpoint || !section.model || !section.apiKeyEnv) {
32
34
  return {
33
35
  ok: false,
34
- reason: `pi-ai profile '${profileId}' missing provider/model/apiKeyEnv`,
35
- nextAction: `Set provider, model and apiKeyEnv on runtime profile '${profileId}'`,
36
+ readiness: 'needs_setup',
37
+ reason: 'adaptiveActivation is missing endpoint/model/apiKeyEnv',
38
+ nextAction: 'Set endpoint (https URL), model and apiKeyEnv on adaptiveActivation',
36
39
  };
37
40
  }
38
- if (!Object.hasOwn(env, profile.apiKeyEnv) || !env[profile.apiKeyEnv]) {
41
+ if (!Object.hasOwn(env, section.apiKeyEnv) || !env[section.apiKeyEnv]) {
39
42
  return {
40
43
  ok: false,
41
- reason: `Environment variable '${profile.apiKeyEnv}' is not set or empty`,
42
- nextAction: `Set the environment variable '${profile.apiKeyEnv}' with a valid API key`,
44
+ readiness: 'needs_setup',
45
+ reason: `Environment variable '${section.apiKeyEnv}' is not set or empty`,
46
+ nextAction: `Set the environment variable '${section.apiKeyEnv}' with a valid API key`,
43
47
  };
44
48
  }
45
49
  return {
46
50
  ok: true,
47
- profileId,
48
51
  model: {
49
- provider: profile.provider,
50
- model: profile.model,
51
- apiKeyEnv: profile.apiKeyEnv,
52
- ...(profile.baseUrl ? { baseUrl: profile.baseUrl } : {}),
52
+ endpoint: section.endpoint,
53
+ model: section.model,
54
+ apiKeyEnv: section.apiKeyEnv,
55
+ ...(section.provider ? { provider: section.provider } : {}),
56
+ ...(section.responseModels && section.responseModels.length > 0
57
+ ? { allowedResponseModels: section.responseModels }
58
+ : {}),
53
59
  },
54
60
  };
55
61
  }
56
62
  export function createAdaptivePriorityProvider(options) {
57
63
  const now = options.now ?? Date.now;
58
- const firstByteTimeoutMs = options.firstByteTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.firstByteTimeoutMs;
59
- const generationTimeoutMs = options.generationTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.generationTimeoutMs;
60
- return async (event) => {
64
+ const requestTimeoutMs = options.requestTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.requestTimeoutMs;
65
+ const outputReserveMs = options.outputReserveMs ?? ADAPTIVE_OUTPUT_RESERVE_MS;
66
+ return async (event, candidates, { excludedByBudget, replacementByActivationId }) => {
61
67
  if (event.kind !== 'before_prompt_build')
62
68
  return undefined;
63
69
  const { sessionId, turnId, promptContent, workspaceDir } = event.context;
64
- // PRI-1181: deterministic gate BEFORE the candidate read. A skipped turn
65
- // costs zero reads and zero sends; the Native body is untouched.
70
+ // The host budget starts before selection; the request budget starts at send.
71
+ const nowMs = now();
72
+ const hostDeadlineAt = options.outerDeadlineAt === undefined
73
+ ? undefined
74
+ : options.outerDeadlineAt - outputReserveMs;
75
+ // PRI-1181: the deterministic gate runs before any model request.
76
+ // Native has already been assembled, even when Adaptive skips.
66
77
  const skip = decideAdaptiveSkip({
67
78
  kind: event.kind,
68
79
  sessionId,
69
80
  turnId,
70
81
  prompt: promptContent ?? '',
71
- ...(options.outerDeadlineAt === undefined
72
- ? {}
73
- : { remainingBudgetMs: options.outerDeadlineAt - now() }),
74
- ...(options.minRemainingBudgetMs !== undefined
75
- ? { minRemainingBudgetMs: options.minRemainingBudgetMs }
82
+ remainingBudgetMs: Math.max(0, Math.min(requestTimeoutMs, (hostDeadlineAt ?? Infinity) - nowMs)),
83
+ ...(options.minExecutableBudgetMs !== undefined
84
+ ? { minExecutableBudgetMs: options.minExecutableBudgetMs }
76
85
  : {}),
77
86
  });
78
- if (skip.skip) {
87
+ if (skip.skip || (candidates.length === 0 && excludedByBudget)) {
79
88
  options.onDiagnostic?.({
80
89
  status: 'skipped',
81
- reason: skip.reason,
90
+ reason: skip.skip ? skip.reason : 'no_appendable_gap',
82
91
  stage: 'gate',
83
92
  sends: 0,
93
+ requestSentAt: null,
84
94
  firstByteAt: null,
85
95
  generationEndedAt: null,
96
+ validatedAt: null,
86
97
  cancelledAt: null,
87
98
  httpStatus: null,
88
99
  finishReason: 'skipped',
100
+ modelObserved: null,
101
+ providerObserved: null,
102
+ decision: null,
89
103
  failures: [],
90
104
  });
91
105
  return undefined;
@@ -93,27 +107,15 @@ export function createAdaptivePriorityProvider(options) {
93
107
  // The gate already proved identity and a non-blank prompt (rc-3); the
94
108
  // selector only needs the prompt body from here on.
95
109
  const prompt = promptContent ?? '';
96
- const admissionDeadlineAt = options.outerDeadlineAt === undefined
97
- ? now() + firstByteTimeoutMs
98
- : Math.min(now() + firstByteTimeoutMs, options.outerDeadlineAt);
99
- const remainingBudgetMs = options.outerDeadlineAt === undefined
100
- ? firstByteTimeoutMs
101
- : Math.max(1, options.outerDeadlineAt - now());
102
- const effectiveGenerationTimeoutMs = options.outerDeadlineAt === undefined
103
- ? generationTimeoutMs
104
- : Math.min(generationTimeoutMs, remainingBudgetMs);
105
- // Reuse the selector's AbortSignal seam instead of a second timer: it is
106
- // combined with the first-byte and request signals inside the transport.
107
- const signal = options.outerDeadlineAt === undefined ? undefined : AbortSignal.timeout(remainingBudgetMs);
110
+ const signal = hostDeadlineAt === undefined ? undefined : AbortSignal.timeout(Math.max(1, hostDeadlineAt - now()));
108
111
  const outcome = await runAdaptiveSelection({
109
112
  workspaceDir: workspaceDir || options.workspaceDir,
110
113
  currentPrompt: prompt,
111
- admissionDeadlineAt,
114
+ candidates,
115
+ replacementByActivationId,
112
116
  model: options.model,
113
- generationTimeoutMs: effectiveGenerationTimeoutMs,
114
- ...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
115
- ...(signal ? { signal } : {}),
116
- ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
117
+ requestTimeoutMs,
118
+ ...(hostDeadlineAt !== undefined ? { outerDeadlineAt: hostDeadlineAt, signal } : {}),
117
119
  ...(options.now ? { now: options.now } : {}),
118
120
  ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
119
121
  });
@@ -122,11 +124,16 @@ export function createAdaptivePriorityProvider(options) {
122
124
  reason: outcome.reason,
123
125
  stage: outcome.diagnostics.stage,
124
126
  sends: outcome.sends,
127
+ requestSentAt: outcome.diagnostics.requestSentAt,
125
128
  firstByteAt: outcome.diagnostics.firstByteAt,
126
129
  generationEndedAt: outcome.diagnostics.generationEndedAt,
130
+ validatedAt: outcome.diagnostics.validatedAt,
127
131
  cancelledAt: outcome.diagnostics.cancelledAt,
128
132
  httpStatus: outcome.diagnostics.httpStatus,
129
133
  finishReason: outcome.diagnostics.finishReason,
134
+ modelObserved: outcome.diagnostics.modelObserved,
135
+ providerObserved: outcome.diagnostics.providerObserved,
136
+ decision: outcome.diagnostics.decision,
130
137
  failures: [...outcome.diagnostics.failures],
131
138
  });
132
139
  if (outcome.status !== 'selected' || !outcome.target)
@@ -135,8 +142,7 @@ export function createAdaptivePriorityProvider(options) {
135
142
  artifactId: outcome.target.artifactId,
136
143
  activationId: outcome.target.activationId,
137
144
  additiveOnly: true,
138
- deadlineAt: options.outerDeadlineAt ?? admissionDeadlineAt + generationTimeoutMs,
139
- ...(signal ? { signal } : {}),
145
+ ...(hostDeadlineAt !== undefined ? { deadlineAt: hostDeadlineAt, signal } : {}),
140
146
  };
141
147
  };
142
148
  }
@@ -145,11 +151,11 @@ export function createAdaptivePriorityProvider(options) {
145
151
  * workspace config for the current turn.
146
152
  */
147
153
  export function createAdaptivePriorityProviderForConfig(config, workspaceDir, options = {}) {
148
- const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env);
154
+ const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env, options.flag);
149
155
  if (!resolved.ok) {
150
156
  return {
151
157
  ok: false,
152
- readiness: 'disabled',
158
+ readiness: resolved.readiness,
153
159
  reason: resolved.reason,
154
160
  nextAction: resolved.nextAction,
155
161
  };
@@ -157,11 +163,10 @@ export function createAdaptivePriorityProviderForConfig(config, workspaceDir, op
157
163
  const provider = createAdaptivePriorityProvider({
158
164
  workspaceDir,
159
165
  model: resolved.model,
160
- ...(options.firstByteTimeoutMs !== undefined ? { firstByteTimeoutMs: options.firstByteTimeoutMs } : {}),
161
- ...(options.generationTimeoutMs !== undefined ? { generationTimeoutMs: options.generationTimeoutMs } : {}),
166
+ ...(options.requestTimeoutMs !== undefined ? { requestTimeoutMs: options.requestTimeoutMs } : {}),
162
167
  ...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
163
- ...(options.minRemainingBudgetMs !== undefined ? { minRemainingBudgetMs: options.minRemainingBudgetMs } : {}),
164
- ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
168
+ ...(options.outputReserveMs !== undefined ? { outputReserveMs: options.outputReserveMs } : {}),
169
+ ...(options.minExecutableBudgetMs !== undefined ? { minExecutableBudgetMs: options.minExecutableBudgetMs } : {}),
165
170
  ...(options.now ? { now: options.now } : {}),
166
171
  ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
167
172
  ...(options.onDiagnostic ? { onDiagnostic: options.onDiagnostic } : {}),
@@ -169,10 +174,9 @@ export function createAdaptivePriorityProviderForConfig(config, workspaceDir, op
169
174
  return {
170
175
  ok: true,
171
176
  readiness: 'ready',
172
- reason: `adaptive selection ready via runtime profile '${resolved.profileId}'`,
177
+ reason: `adaptive decision ready at '${resolved.model.endpoint}' (model '${resolved.model.model}')`,
173
178
  nextAction: 'none',
174
179
  provider,
175
- profileId: resolved.profileId,
176
180
  };
177
181
  }
178
182
  /**
@@ -1,30 +1,38 @@
1
- import { PiAiRuntimeAdapter, type ActivatedPrinciple } from '@principles/core/runtime';
1
+ import type { ActivatedPrinciple } from '@principles/core/runtime';
2
+ import { type DecisionOutcome, type DecisionProtocolError, type DecisionRequestEnvelope } from './adaptive-decision-protocol.js';
2
3
  export declare const ADAPTIVE_SELECTION_LIMITS: {
3
4
  readonly maxCandidates: 12;
4
5
  readonly maxCandidateChars: 600;
5
6
  readonly maxPriorMessages: 4;
6
7
  readonly maxPriorMessageChars: 1200;
7
8
  readonly maxInputChars: 6000;
8
- /** Admission (time-to-first-byte) deadline for the incremental step. */
9
- readonly firstByteTimeoutMs: 10000;
10
- /** Bounded completion window once the endpoint has started answering. */
11
- readonly generationTimeoutMs: 10000;
12
- readonly maxOutputTokens: 512;
9
+ /** Total time from sending a decision request to validating the full response. */
10
+ readonly requestTimeoutMs: 2000;
11
+ /** Bounded outbound payload (current instruction + candidate snapshot + conditions). */
12
+ readonly maxPayloadChars: 20000;
13
+ /** Bounded response body; a Decisions answer table is a few KB at most. */
14
+ readonly maxResponseBytes: 65536;
13
15
  };
14
16
  export type AdaptiveSelectionModel = {
15
- readonly provider: string;
17
+ /** Exact Decisions endpoint (for example https://openrouter.ai/api/alpha/decisions). */
18
+ readonly endpoint: string;
16
19
  readonly model: string;
17
20
  readonly apiKeyEnv: string;
18
- /** Exact request URL when the caller already knows it (lab). */
19
- readonly url?: string;
20
- /** Outbound allowlist prefix when only a base URL is known (production). */
21
- readonly baseUrl?: string;
21
+ /** Optional provider allowlist label (for example Respan). */
22
+ readonly provider?: string;
23
+ /**
24
+ * Frozen exact response-model allowlist for the acceptance batch. When set,
25
+ * a response whose `model` is not one of these strings is rejected — a
26
+ * same-prefix slug with an unregistered date does not pass.
27
+ */
28
+ readonly allowedResponseModels?: readonly string[];
22
29
  };
23
30
  export type AdaptiveCandidateSource = ActivatedPrinciple;
24
31
  export interface AdaptiveCandidate {
25
32
  readonly ref: string;
26
33
  readonly text: string;
27
34
  readonly digest: string;
35
+ readonly replaces?: string;
28
36
  readonly principle: AdaptiveCandidateSource;
29
37
  }
30
38
  export interface BoundedSelectionInput {
@@ -35,11 +43,11 @@ export interface BoundedSelectionInput {
35
43
  readonly source: string;
36
44
  readonly index: number;
37
45
  }[];
38
- /** `digest` is precomputed locally and only copied by the model. */
39
46
  readonly candidates: readonly {
40
47
  readonly ref: string;
41
48
  readonly text: string;
42
49
  readonly digest: string;
50
+ readonly replaces?: string;
43
51
  }[];
44
52
  };
45
53
  readonly entries: readonly AdaptiveCandidate[];
@@ -52,49 +60,53 @@ export type BuildBoundedInputResult = {
52
60
  readonly ok: false;
53
61
  readonly reason: string;
54
62
  };
55
- export type SelectionShape = {
56
- readonly status: 'selected';
57
- readonly id: string;
58
- readonly digest: string;
59
- } | {
60
- readonly status: 'none_applicable' | 'uncertain';
61
- readonly id: null;
62
- readonly digest: null;
63
- };
64
- export type ValidateSelectionResult = {
65
- readonly ok: true;
66
- readonly selected: AdaptiveCandidate | null;
67
- readonly outcome: 'selected' | 'no_increment' | 'uncertain';
68
- } | {
69
- readonly ok: false;
70
- readonly reason: string;
71
- readonly refValid: boolean | null;
72
- readonly digestValid: boolean | null;
73
- };
74
- export type AdaptiveFailureCode = 'SELECTION_REFERENCE_INVALID' | 'SELECTION_DIGEST_INVALID' | 'SELECTION_OUTPUT_INVALID'
75
- /** The selector's schema ref is not in the adapter registry (configuration fault). */
76
- | 'SELECTION_SCHEMA_UNAVAILABLE' | 'SELECTION_AMBIGUOUS' | 'SELECTION_EXPIRED'
63
+ export type AdaptiveFailureCode = 'SELECTION_OUTPUT_INVALID' | DecisionProtocolError
77
64
  /** The host's outer hook window ended Adaptive; distinct from the model's own timeout. */
78
- | 'TURN_DEADLINE_EXCEEDED' | 'TRANSPORT_NOT_SENT' | 'TRANSPORT_FAILED' | 'INPUT_REFUSED';
65
+ | 'TURN_DEADLINE_EXCEEDED'
66
+ /** The request's own short admission/completion window ended. */
67
+ | 'SELECTION_EXPIRED'
68
+ /**
69
+ * Configuration fault: the credential named by `apiKeyEnv` is absent at send
70
+ * time. Deliberately NOT in the TRANSPORT_* family — an operator must be able
71
+ * to tell "we never had a key" apart from "the network broke".
72
+ */
73
+ | 'DECISION_CREDENTIAL_MISSING' | 'TRANSPORT_NOT_SENT' | 'TRANSPORT_FAILED' | 'TRANSPORT_HTTP_ERROR';
79
74
  export type AdaptiveSelectionStage = 'idle' | 'admission' | 'generation' | 'validate' | 'revalidate' | 'done';
80
75
  export interface AdaptiveSelectionDiagnostics {
81
76
  stage: AdaptiveSelectionStage;
82
- readonly admissionDeadlineAt: number;
77
+ readonly requestDeadlineAt: number | null;
78
+ /** Epoch ms at which the single POST was actually issued (null = never sent). */
79
+ requestSentAt: number | null;
83
80
  completionDeadlineAt: number | null;
84
81
  firstByteAt: number | null;
85
82
  generationEndedAt: number | null;
83
+ /** Epoch ms at which the WHOLE answer table passed validation (null = never). */
84
+ validatedAt: number | null;
86
85
  cancelledAt: number | null;
87
86
  httpStatus: number | null;
88
- /** Server-reported finish reason, or 'unknown' when the transport does not expose one. */
87
+ /** `decisions` once a valid answer table was read; `unknown` otherwise. */
89
88
  finishReason: string;
89
+ /** Exact response model observed (null until a body was parsed). */
90
+ modelObserved: string | null;
91
+ /** Response provider label observed; null both before parsing and when absent. */
92
+ providerObserved: string | null;
90
93
  usage: {
91
94
  inputTokens: number | null;
92
95
  outputTokens: number | null;
93
96
  } | null;
97
+ /**
98
+ * Local adjudication of the independent condition scores. Bounded: question
99
+ * ids are `c1..cN` plus `insufficient_context`, never prompt text.
100
+ */
101
+ decision: {
102
+ status: string;
103
+ ref: string | null;
104
+ reason: string;
105
+ scores: Readonly<Record<string, number>>;
106
+ } | null;
94
107
  failures: AdaptiveFailureCode[];
95
108
  }
96
109
  export declare function hash(value: string): string;
97
- export declare const ADAPTIVE_SELECTOR_SYSTEM: string;
98
110
  export declare function buildBoundedSelectionInput(input: {
99
111
  readonly currentInput: string;
100
112
  readonly priorMessages?: readonly {
@@ -102,31 +114,24 @@ export declare function buildBoundedSelectionInput(input: {
102
114
  readonly source?: string;
103
115
  }[];
104
116
  readonly candidates: readonly AdaptiveCandidateSource[];
117
+ readonly replacementByActivationId?: ReadonlyMap<string, ActivatedPrinciple> | undefined;
105
118
  }): BuildBoundedInputResult;
106
- export declare function parseSelectionShape(value: unknown): {
107
- readonly ok: true;
108
- readonly selection: SelectionShape;
109
- } | {
110
- readonly ok: false;
111
- readonly reason: string;
112
- };
113
- export declare function validateSelectionResult(value: unknown, entries: readonly AdaptiveCandidate[]): ValidateSelectionResult;
114
- export declare function localFailureCode(reason: string): AdaptiveFailureCode;
115
- export interface SingleModelSelectorOptions {
116
- readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
119
+ export interface DecisionSelectorOptions {
117
120
  readonly fetchImpl?: typeof fetch;
118
121
  readonly now?: () => number;
119
- /** Absolute deadline for the first byte of the model response. */
120
- readonly admissionDeadlineAt: number;
121
- readonly generationTimeoutMs?: number;
122
+ readonly requestTimeoutMs?: number;
122
123
  readonly model: AdaptiveSelectionModel;
123
- readonly maxTokens?: number;
124
124
  readonly signal?: AbortSignal;
125
125
  /** Absolute host deadline. Reaching it is NOT the model's generation timeout. */
126
126
  readonly outerDeadlineAt?: number;
127
127
  }
128
- export interface SingleModelSelector {
129
- readonly select: (input: BoundedSelectionInput) => Promise<unknown>;
128
+ export interface DecisionSelectorInput {
129
+ readonly body: DecisionRequestEnvelope;
130
+ readonly questionIds: readonly string[];
131
+ readonly candidates: readonly AdaptiveCandidate[];
132
+ }
133
+ export interface DecisionSelector {
134
+ readonly select: (input: DecisionSelectorInput) => Promise<DecisionOutcome>;
130
135
  readonly report: () => {
131
136
  readonly sends: number;
132
137
  readonly status: 'not_sent' | 'sent' | 'failed';
@@ -134,21 +139,23 @@ export interface SingleModelSelector {
134
139
  readonly diagnostics: AdaptiveSelectionDiagnostics;
135
140
  };
136
141
  }
137
- export declare function createSingleModelSelector(options: SingleModelSelectorOptions): SingleModelSelector;
142
+ /**
143
+ * One Decisions POST per turn. Every failure is classified at the transport
144
+ * edge; the caller never sees provider text, headers or credentials.
145
+ */
146
+ export declare function createDecisionSelector(options: DecisionSelectorOptions): DecisionSelector;
138
147
  export interface RunAdaptiveSelectionOptions {
139
148
  readonly workspaceDir: string;
140
149
  readonly currentPrompt: string;
141
- /** Absolute first-byte deadline for the incremental step. */
142
- readonly admissionDeadlineAt: number;
150
+ readonly candidates: readonly ActivatedPrinciple[];
151
+ readonly replacementByActivationId?: ReadonlyMap<string, ActivatedPrinciple> | undefined;
143
152
  readonly model: AdaptiveSelectionModel;
144
- readonly generationTimeoutMs?: number;
145
- readonly maxTokens?: number;
153
+ readonly requestTimeoutMs?: number;
146
154
  readonly signal?: AbortSignal;
147
155
  /** Absolute host deadline shared by selection, revalidation and packing. */
148
156
  readonly outerDeadlineAt?: number;
149
157
  readonly now?: () => number;
150
158
  readonly fetchImpl?: typeof fetch;
151
- readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
152
159
  }
153
160
  export interface AdaptiveSelectionOutcome {
154
161
  readonly status: 'selected' | 'none' | 'unavailable';
@@ -159,8 +166,8 @@ export interface AdaptiveSelectionOutcome {
159
166
  readonly diagnostics: AdaptiveSelectionDiagnostics;
160
167
  }
161
168
  /**
162
- * Minimal host-facing selection step: read the current frozen candidates,
163
- * make at most one bounded model call, verify ref+digest, then independently
164
- * revalidate the chosen principle's content/revision/authorization.
169
+ * Minimal host-facing selection step: use the current frozen Native gap,
170
+ * make at most one bounded Decisions request, adjudicate locally, then
171
+ * independently revalidate the chosen principle's content/revision/authorization.
165
172
  */
166
173
  export declare function runAdaptiveSelection(options: RunAdaptiveSelectionOptions): Promise<AdaptiveSelectionOutcome>;