create-principles-disciple 1.149.0 → 1.150.2

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 (258) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/ingestion/ingestion.d.ts +9 -7
  3. package/codex-adapter/dist/ingestion/ingestion.js +68 -144
  4. package/codex-adapter/dist/ingestion/transcript-decoder.d.ts +35 -44
  5. package/codex-adapter/dist/ingestion/transcript-decoder.js +23 -84
  6. package/codex-adapter/dist/ingestion/transcript-source.d.ts +29 -0
  7. package/codex-adapter/dist/ingestion/transcript-source.js +65 -0
  8. package/codex-adapter/dist/pd-hook.d.ts +27 -1
  9. package/codex-adapter/dist/pd-hook.js +88 -7
  10. package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
  11. package/codex-adapter/dist/worker/workspace-worker.js +7 -36
  12. package/codex-adapter/package.json +1 -1
  13. package/console/dist/server/index.js +14 -0
  14. package/console/dist/server/models/ActivationsConsoleModel.d.ts +3 -17
  15. package/console/dist/server/models/ActivationsConsoleModel.js +5 -44
  16. package/console/dist/server/routes/diagnostician.d.ts +50 -0
  17. package/console/dist/server/routes/diagnostician.js +388 -0
  18. package/console/dist/server/routes/examiner-eligibility.d.ts +73 -0
  19. package/console/dist/server/routes/examiner-eligibility.js +326 -0
  20. package/console/dist/server/routes/examiner.js +66 -8
  21. package/console/dist/web/assets/app.css +40 -0
  22. package/console/dist/web/assets/app.js +30 -30
  23. package/core/dist/host/host-installer.d.ts +7 -0
  24. package/core/dist/host/host-installer.d.ts.map +1 -1
  25. package/core/dist/host/host-installer.js.map +1 -1
  26. package/core/dist/runtime/activation/index.d.ts +3 -3
  27. package/core/dist/runtime/activation/index.d.ts.map +1 -1
  28. package/core/dist/runtime/activation/index.js +1 -1
  29. package/core/dist/runtime/activation/index.js.map +1 -1
  30. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +25 -1
  31. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
  32. package/core/dist/runtime/activation/promotion-readiness-evaluator.js +58 -1
  33. package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
  34. package/core/dist/runtime/activation/promotion-readiness-reader.d.ts.map +1 -1
  35. package/core/dist/runtime/activation/promotion-readiness-reader.js +4 -2
  36. package/core/dist/runtime/activation/promotion-readiness-reader.js.map +1 -1
  37. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts +28 -0
  38. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
  39. package/core/dist/runtime/activation/rulecode-owner-decision-service.js +2 -0
  40. package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
  41. package/core/dist/runtime/admission-gate.d.ts +8 -1
  42. package/core/dist/runtime/admission-gate.d.ts.map +1 -1
  43. package/core/dist/runtime/admission-gate.js +2 -1
  44. package/core/dist/runtime/admission-gate.js.map +1 -1
  45. package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
  46. package/core/dist/runtime/config/pd-config-defaults.js +20 -2
  47. package/core/dist/runtime/config/pd-config-defaults.js.map +1 -1
  48. package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
  49. package/core/dist/runtime/config/pd-config-effective.js +5 -2
  50. package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
  51. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  52. package/core/dist/runtime/config/pd-config-validate.js +18 -0
  53. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  54. package/core/dist/runtime/context-payload.d.ts +48 -3
  55. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  56. package/core/dist/runtime/context-payload.js +38 -0
  57. package/core/dist/runtime/context-payload.js.map +1 -1
  58. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +8 -2
  59. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  60. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +28 -2
  61. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  62. package/core/dist/runtime/diagnostician-candidate.d.ts +24 -0
  63. package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -0
  64. package/core/dist/runtime/diagnostician-candidate.js +55 -0
  65. package/core/dist/runtime/diagnostician-candidate.js.map +1 -0
  66. package/core/dist/runtime/evidence-guards.d.ts +10 -4
  67. package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
  68. package/core/dist/runtime/evidence-guards.js +12 -5
  69. package/core/dist/runtime/evidence-guards.js.map +1 -1
  70. package/core/dist/runtime/evolution/evolution-types.d.ts +4 -4
  71. package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
  72. package/core/dist/runtime/evolution/evolution-types.js +1 -0
  73. package/core/dist/runtime/evolution/evolution-types.js.map +1 -1
  74. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  75. package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
  76. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  77. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  78. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +16 -0
  79. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  80. package/core/dist/runtime/index.d.ts +5 -2
  81. package/core/dist/runtime/index.d.ts.map +1 -1
  82. package/core/dist/runtime/index.js +6 -1
  83. package/core/dist/runtime/index.js.map +1 -1
  84. package/core/dist/runtime/internalization/index.d.ts +1 -0
  85. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  86. package/core/dist/runtime/internalization/index.js +2 -0
  87. package/core/dist/runtime/internalization/index.js.map +1 -1
  88. package/core/dist/runtime/internalization/rule-host-contracts.d.ts +10 -0
  89. package/core/dist/runtime/internalization/rule-host-contracts.d.ts.map +1 -1
  90. package/core/dist/runtime/internalization/rule-host-evaluator.js +10 -10
  91. package/core/dist/runtime/internalization/rule-host-evaluator.js.map +1 -1
  92. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +7 -6
  93. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  94. package/core/dist/runtime/internalization/rule-host-input-builder.js +6 -2
  95. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  96. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts +33 -0
  97. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts.map +1 -0
  98. package/core/dist/runtime/internalization/rule-host-result-normalizer.js +61 -0
  99. package/core/dist/runtime/internalization/rule-host-result-normalizer.js.map +1 -0
  100. package/core/dist/runtime/internalization/rule-host-validator.d.ts.map +1 -1
  101. package/core/dist/runtime/internalization/rule-host-validator.js +17 -0
  102. package/core/dist/runtime/internalization/rule-host-validator.js.map +1 -1
  103. package/core/dist/runtime/pain-ingress-payload.d.ts +27 -2
  104. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  105. package/core/dist/runtime/pain-ingress-payload.js +45 -3
  106. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  107. package/core/dist/runtime/pain-ingress.d.ts +4 -2
  108. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  109. package/core/dist/runtime/pain-ingress.js +23 -3
  110. package/core/dist/runtime/pain-ingress.js.map +1 -1
  111. package/core/dist/runtime/pain-severity.d.ts +14 -0
  112. package/core/dist/runtime/pain-severity.d.ts.map +1 -0
  113. package/core/dist/runtime/pain-severity.js +14 -0
  114. package/core/dist/runtime/pain-severity.js.map +1 -0
  115. package/core/dist/runtime/pain-signal-bridge.d.ts +17 -3
  116. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  117. package/core/dist/runtime/pain-signal-bridge.js +6 -0
  118. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  119. package/core/dist/runtime/pain-signal-observability.d.ts.map +1 -1
  120. package/core/dist/runtime/pain-signal-observability.js +3 -2
  121. package/core/dist/runtime/pain-signal-observability.js.map +1 -1
  122. package/core/dist/runtime/pain-submit-capability.d.ts +164 -0
  123. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -0
  124. package/core/dist/runtime/pain-submit-capability.js +442 -0
  125. package/core/dist/runtime/pain-submit-capability.js.map +1 -0
  126. package/core/dist/runtime/pain-to-principle-service.d.ts +4 -0
  127. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  128. package/core/dist/runtime/pain-to-principle-service.js +2 -0
  129. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  130. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts +56 -10
  131. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts.map +1 -1
  132. package/core/dist/runtime/stalled-diagnostician-task-read-model.js +80 -4
  133. package/core/dist/runtime/stalled-diagnostician-task-read-model.js.map +1 -1
  134. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  135. package/core/dist/runtime/store/context/sqlite-context-assembler.js +11 -0
  136. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  137. package/core/dist/runtime/store/run/memory-run-store.d.ts +10 -0
  138. package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
  139. package/core/dist/runtime/store/run/memory-run-store.js +21 -0
  140. package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
  141. package/core/dist/runtime/store/run/run-store.d.ts +12 -0
  142. package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
  143. package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -0
  144. package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
  145. package/core/dist/runtime/store/run/sqlite-run-store.js +14 -0
  146. package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
  147. package/core/dist/runtime/task-status.d.ts +9 -0
  148. package/core/dist/runtime/task-status.d.ts.map +1 -1
  149. package/core/dist/runtime/task-status.js +7 -1
  150. package/core/dist/runtime/task-status.js.map +1 -1
  151. package/core/dist/runtime/types/evidence-chain-contract.d.ts +18 -0
  152. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  153. package/core/dist/runtime/types/evidence-chain-contract.js +37 -7
  154. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  155. package/core/package.json +5 -1
  156. package/dist/install-summary.d.ts +7 -0
  157. package/dist/install-summary.d.ts.map +1 -1
  158. package/dist/install-summary.js +4 -0
  159. package/dist/install-summary.js.map +1 -1
  160. package/dist/installer.d.ts +34 -1
  161. package/dist/installer.d.ts.map +1 -1
  162. package/dist/installer.js +84 -4
  163. package/dist/installer.js.map +1 -1
  164. package/dist/installers/codex-host-installer.d.ts +88 -1
  165. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  166. package/dist/installers/codex-host-installer.js +370 -11
  167. package/dist/installers/codex-host-installer.js.map +1 -1
  168. package/dist/installers/index.d.ts +23 -0
  169. package/dist/installers/index.d.ts.map +1 -1
  170. package/dist/installers/index.js +38 -1
  171. package/dist/installers/index.js.map +1 -1
  172. package/dist/installers/legacy-workbuddy-skill.d.ts +59 -0
  173. package/dist/installers/legacy-workbuddy-skill.d.ts.map +1 -0
  174. package/dist/installers/legacy-workbuddy-skill.js +168 -0
  175. package/dist/installers/legacy-workbuddy-skill.js.map +1 -0
  176. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  177. package/dist/installers/workbuddy-host-installer.js +7 -0
  178. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  179. package/host-runtime/dist/adaptive-priority-provider.d.ts +101 -0
  180. package/host-runtime/dist/adaptive-priority-provider.js +194 -0
  181. package/host-runtime/dist/adaptive-selection.d.ts +164 -0
  182. package/host-runtime/dist/adaptive-selection.js +506 -0
  183. package/host-runtime/dist/adaptive-skip-decision.d.ts +61 -0
  184. package/host-runtime/dist/adaptive-skip-decision.js +114 -0
  185. package/host-runtime/dist/codex-ingestion-consent.d.ts +32 -95
  186. package/host-runtime/dist/codex-ingestion-consent.js +33 -205
  187. package/host-runtime/dist/conversation-ingestion/consent.d.ts +124 -0
  188. package/host-runtime/dist/conversation-ingestion/consent.js +531 -0
  189. package/host-runtime/dist/conversation-ingestion/index.d.ts +12 -0
  190. package/host-runtime/dist/conversation-ingestion/index.js +12 -0
  191. package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +101 -0
  192. package/host-runtime/dist/conversation-ingestion/pipeline.js +162 -0
  193. package/host-runtime/dist/conversation-ingestion/source.d.ts +172 -0
  194. package/host-runtime/dist/conversation-ingestion/source.js +111 -0
  195. package/host-runtime/dist/conversation-ingestion/text-policy.d.ts +51 -0
  196. package/host-runtime/dist/conversation-ingestion/text-policy.js +68 -0
  197. package/host-runtime/dist/diagnostician-auto-run.d.ts +28 -0
  198. package/host-runtime/dist/diagnostician-auto-run.js +100 -0
  199. package/host-runtime/dist/governance-observation-store.d.ts +9 -7
  200. package/host-runtime/dist/governance-observation-store.js +20 -4
  201. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +42 -1
  202. package/host-runtime/dist/host-tool-semantic-resolver.js +80 -14
  203. package/host-runtime/dist/index.d.ts +5 -0
  204. package/host-runtime/dist/index.js +12 -0
  205. package/host-runtime/dist/production-rulehost-gate.js +17 -17
  206. package/host-runtime/dist/rulecode-event-collection.d.ts +31 -0
  207. package/host-runtime/dist/rulecode-event-collection.js +62 -0
  208. package/host-runtime/package.json +1 -1
  209. package/package.json +3 -3
  210. package/pd-cli/dist/commands/diagnose.d.ts +30 -0
  211. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  212. package/pd-cli/dist/commands/diagnose.js +75 -0
  213. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  214. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  215. package/pd-cli/dist/commands/pain-record.js +5 -4
  216. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  217. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  218. package/pd-cli/dist/commands/pain-retry.js +2 -1
  219. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  220. package/pd-cli/dist/commands/runtime-activation.d.ts +6 -17
  221. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  222. package/pd-cli/dist/commands/runtime-activation.js +42 -48
  223. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  224. package/pd-cli/dist/index.js +1 -0
  225. package/pd-cli/dist/index.js.map +1 -1
  226. package/pd-cli/dist/services/delivery-surfaces.js +1 -1
  227. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  228. package/pd-cli/package.json +1 -1
  229. package/pd-mcp-server/dist/budget.d.ts +1 -1
  230. package/pd-mcp-server/dist/budget.js +2 -2
  231. package/pd-mcp-server/dist/envelope.d.ts +15 -0
  232. package/pd-mcp-server/dist/envelope.js +49 -1
  233. package/pd-mcp-server/dist/index.d.ts +2 -0
  234. package/pd-mcp-server/dist/index.js +6 -0
  235. package/pd-mcp-server/dist/server.d.ts +83 -14
  236. package/pd-mcp-server/dist/server.js +251 -4
  237. package/pd-mcp-server/dist/version.d.ts +1 -1
  238. package/pd-mcp-server/dist/version.js +1 -1
  239. package/pd-mcp-server/dist/workspace.d.ts +4 -2
  240. package/pd-mcp-server/dist/workspace.js +5 -2
  241. package/pd-mcp-server/package.json +1 -1
  242. package/plugin/dist/bundle.js +449 -437
  243. package/plugin/dist/core/evolution-reducer.d.ts +2 -2
  244. package/plugin/dist/hooks/hook-tool-semantics.d.ts +25 -0
  245. package/plugin/dist/hooks/pain-ingress-adapter.d.ts +1 -1
  246. package/plugin/dist/openclaw.plugin.json +1 -1
  247. package/plugin/dist/rulehost-evidence.js +1 -1
  248. package/plugin/openclaw.plugin.json +1 -1
  249. package/plugin/package.json +1 -1
  250. package/release-manager/dist/installer.js +84 -4
  251. package/release-manager/dist/installers/codex-host-installer.js +370 -11
  252. package/release-manager/dist/installers/index.js +38 -1
  253. package/release-manager/dist/installers/legacy-workbuddy-skill.js +168 -0
  254. package/release-manager/dist/installers/workbuddy-host-installer.js +7 -0
  255. package/release-manager/package.json +1 -1
  256. package/workbuddy-adapter/dist/pd-hook.js +20 -4
  257. package/workbuddy-adapter/package.json +1 -1
  258. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +123 -20
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Adaptive Activation — Codex host provider (default OFF).
3
+ *
4
+ * The provider is a thin, optional hook boundary:
5
+ * UserPromptSubmit → decoded HostEvent → this provider → shared assembly.
6
+ *
7
+ * It binds ONLY the host-supplied current-turn identity (`session_id`,
8
+ * `turn_id`) and prompt body. No markers, no manual principle ids, no scene
9
+ * mapping. Any missing identity/config/model keeps the Native path unchanged.
10
+ */
11
+ import type { HostEvent } from '@principles/core/host';
12
+ import type { PdConfig } from '@principles/core/runtime';
13
+ import { type AdaptiveSelectionModel } from './adaptive-selection.js';
14
+ /** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
15
+ export declare const ADAPTIVE_ACTIVATION_FLAG = "host.codex.adaptive_activation";
16
+ export interface AdaptivePrioritySelection {
17
+ readonly artifactId: string;
18
+ readonly activationId: string;
19
+ readonly additiveOnly: true;
20
+ readonly deadlineAt?: number;
21
+ readonly signal?: AbortSignal;
22
+ }
23
+ export type AdaptivePriorityProvider = (event: HostEvent) => Promise<AdaptivePrioritySelection | undefined>;
24
+ export interface AdaptiveActivationReadiness {
25
+ readonly readiness: 'ready' | 'disabled' | 'needs_setup';
26
+ readonly reason: string;
27
+ readonly nextAction: string;
28
+ }
29
+ export type AdaptiveModelResolution = {
30
+ readonly ok: true;
31
+ readonly model: AdaptiveSelectionModel;
32
+ readonly profileId: string;
33
+ } | {
34
+ readonly ok: false;
35
+ readonly reason: string;
36
+ readonly nextAction: string;
37
+ };
38
+ export declare function resolveAdaptiveSelectionModel(config: PdConfig, env: Record<string, string | undefined>): AdaptiveModelResolution;
39
+ export interface AdaptiveSelectionDiagnosticLine {
40
+ readonly status: string;
41
+ readonly reason: string;
42
+ readonly stage: string;
43
+ readonly sends: number;
44
+ readonly firstByteAt: number | null;
45
+ readonly generationEndedAt: number | null;
46
+ readonly cancelledAt: number | null;
47
+ readonly httpStatus: number | null;
48
+ readonly finishReason: string;
49
+ readonly failures: readonly string[];
50
+ }
51
+ export interface CreateAdaptivePriorityProviderOptions {
52
+ readonly workspaceDir: string;
53
+ readonly model: AdaptiveSelectionModel;
54
+ readonly firstByteTimeoutMs?: number;
55
+ readonly generationTimeoutMs?: number;
56
+ /**
57
+ * Absolute host deadline (Codex: the plugin hook window minus the Native
58
+ * reserve). Selection, revalidation and packing all share it: a selection
59
+ * that cannot finish inside the window is cancelled and never applied.
60
+ */
61
+ readonly outerDeadlineAt?: number;
62
+ /**
63
+ * PRI-1181: below this remaining budget the turn is skipped before the
64
+ * candidate read — no model request is sent at all. Defaults to the measured
65
+ * minimum (`ADAPTIVE_SKIP_LIMITS.minRemainingBudgetMs`); 0 disables the gate
66
+ * for scenarios that isolate transport cancellation.
67
+ */
68
+ readonly minRemainingBudgetMs?: number;
69
+ readonly maxTokens?: number;
70
+ readonly now?: () => number;
71
+ /** Test seam: production uses the global transport. */
72
+ readonly fetchImpl?: typeof fetch;
73
+ /**
74
+ * Observability seam (rc-9): one bounded line per turn, no prompt text,
75
+ * no raw response, no credentials.
76
+ */
77
+ readonly onDiagnostic?: (line: AdaptiveSelectionDiagnosticLine) => void;
78
+ }
79
+ export declare function createAdaptivePriorityProvider(options: CreateAdaptivePriorityProviderOptions): AdaptivePriorityProvider;
80
+ export type AdaptivePriorityProviderResolution = (AdaptiveActivationReadiness & {
81
+ readonly ok: true;
82
+ readonly readiness: 'ready';
83
+ readonly provider: AdaptivePriorityProvider;
84
+ readonly profileId: string;
85
+ }) | (AdaptiveActivationReadiness & {
86
+ readonly ok: false;
87
+ });
88
+ export interface CreateAdaptiveProviderFromConfigOptions extends Omit<CreateAdaptivePriorityProviderOptions, 'workspaceDir' | 'model'> {
89
+ readonly env?: Record<string, string | undefined>;
90
+ }
91
+ /**
92
+ * Config-first factory for hosts (Codex pd-hook) that already loaded the
93
+ * workspace config for the current turn.
94
+ */
95
+ export declare function createAdaptivePriorityProviderForConfig(config: PdConfig, workspaceDir: string, options?: CreateAdaptiveProviderFromConfigOptions): AdaptivePriorityProviderResolution;
96
+ /**
97
+ * Workspace-facing variant: mirrors the existing signal-classifier readiness
98
+ * contract (flag → profile → api key) so a misconfigured workspace degrades to
99
+ * Native with one observable reason instead of a silent model attempt.
100
+ */
101
+ export declare function createAdaptivePriorityProviderForWorkspace(workspaceDir: string, options?: CreateAdaptiveProviderFromConfigOptions): AdaptivePriorityProviderResolution;
@@ -0,0 +1,194 @@
1
+ import { loadPdConfigForPlugin } from './pd-config.js';
2
+ import { ADAPTIVE_SELECTION_LIMITS, runAdaptiveSelection, } from './adaptive-selection.js';
3
+ import { decideAdaptiveSkip } from './adaptive-skip-decision.js';
4
+ /** Independent switch. `features.host.codex.enabled` remains the whole-hook gate. */
5
+ export const ADAPTIVE_ACTIVATION_FLAG = 'host.codex.adaptive_activation';
6
+ export function resolveAdaptiveSelectionModel(config, env) {
7
+ const feature = config.features[ADAPTIVE_ACTIVATION_FLAG];
8
+ if (feature?.enabled !== true) {
9
+ return {
10
+ 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`,
22
+ };
23
+ }
24
+ if (profile.type !== 'pi-ai') {
25
+ return {
26
+ 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',
29
+ };
30
+ }
31
+ if (!profile.provider || !profile.model || !profile.apiKeyEnv) {
32
+ return {
33
+ ok: false,
34
+ reason: `pi-ai profile '${profileId}' missing provider/model/apiKeyEnv`,
35
+ nextAction: `Set provider, model and apiKeyEnv on runtime profile '${profileId}'`,
36
+ };
37
+ }
38
+ if (!Object.hasOwn(env, profile.apiKeyEnv) || !env[profile.apiKeyEnv]) {
39
+ return {
40
+ 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`,
43
+ };
44
+ }
45
+ return {
46
+ ok: true,
47
+ profileId,
48
+ model: {
49
+ provider: profile.provider,
50
+ model: profile.model,
51
+ apiKeyEnv: profile.apiKeyEnv,
52
+ ...(profile.baseUrl ? { baseUrl: profile.baseUrl } : {}),
53
+ },
54
+ };
55
+ }
56
+ export function createAdaptivePriorityProvider(options) {
57
+ 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) => {
61
+ if (event.kind !== 'before_prompt_build')
62
+ return undefined;
63
+ 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.
66
+ const skip = decideAdaptiveSkip({
67
+ kind: event.kind,
68
+ sessionId,
69
+ turnId,
70
+ prompt: promptContent ?? '',
71
+ ...(options.outerDeadlineAt === undefined
72
+ ? {}
73
+ : { remainingBudgetMs: options.outerDeadlineAt - now() }),
74
+ ...(options.minRemainingBudgetMs !== undefined
75
+ ? { minRemainingBudgetMs: options.minRemainingBudgetMs }
76
+ : {}),
77
+ });
78
+ if (skip.skip) {
79
+ options.onDiagnostic?.({
80
+ status: 'skipped',
81
+ reason: skip.reason,
82
+ stage: 'gate',
83
+ sends: 0,
84
+ firstByteAt: null,
85
+ generationEndedAt: null,
86
+ cancelledAt: null,
87
+ httpStatus: null,
88
+ finishReason: 'skipped',
89
+ failures: [],
90
+ });
91
+ return undefined;
92
+ }
93
+ // The gate already proved identity and a non-blank prompt (rc-3); the
94
+ // selector only needs the prompt body from here on.
95
+ 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);
108
+ const outcome = await runAdaptiveSelection({
109
+ workspaceDir: workspaceDir || options.workspaceDir,
110
+ currentPrompt: prompt,
111
+ admissionDeadlineAt,
112
+ model: options.model,
113
+ generationTimeoutMs: effectiveGenerationTimeoutMs,
114
+ ...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
115
+ ...(signal ? { signal } : {}),
116
+ ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
117
+ ...(options.now ? { now: options.now } : {}),
118
+ ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
119
+ });
120
+ options.onDiagnostic?.({
121
+ status: outcome.status,
122
+ reason: outcome.reason,
123
+ stage: outcome.diagnostics.stage,
124
+ sends: outcome.sends,
125
+ firstByteAt: outcome.diagnostics.firstByteAt,
126
+ generationEndedAt: outcome.diagnostics.generationEndedAt,
127
+ cancelledAt: outcome.diagnostics.cancelledAt,
128
+ httpStatus: outcome.diagnostics.httpStatus,
129
+ finishReason: outcome.diagnostics.finishReason,
130
+ failures: [...outcome.diagnostics.failures],
131
+ });
132
+ if (outcome.status !== 'selected' || !outcome.target)
133
+ return undefined;
134
+ return {
135
+ artifactId: outcome.target.artifactId,
136
+ activationId: outcome.target.activationId,
137
+ additiveOnly: true,
138
+ deadlineAt: options.outerDeadlineAt ?? admissionDeadlineAt + generationTimeoutMs,
139
+ ...(signal ? { signal } : {}),
140
+ };
141
+ };
142
+ }
143
+ /**
144
+ * Config-first factory for hosts (Codex pd-hook) that already loaded the
145
+ * workspace config for the current turn.
146
+ */
147
+ export function createAdaptivePriorityProviderForConfig(config, workspaceDir, options = {}) {
148
+ const resolved = resolveAdaptiveSelectionModel(config, options.env ?? process.env);
149
+ if (!resolved.ok) {
150
+ return {
151
+ ok: false,
152
+ readiness: 'disabled',
153
+ reason: resolved.reason,
154
+ nextAction: resolved.nextAction,
155
+ };
156
+ }
157
+ const provider = createAdaptivePriorityProvider({
158
+ workspaceDir,
159
+ model: resolved.model,
160
+ ...(options.firstByteTimeoutMs !== undefined ? { firstByteTimeoutMs: options.firstByteTimeoutMs } : {}),
161
+ ...(options.generationTimeoutMs !== undefined ? { generationTimeoutMs: options.generationTimeoutMs } : {}),
162
+ ...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
163
+ ...(options.minRemainingBudgetMs !== undefined ? { minRemainingBudgetMs: options.minRemainingBudgetMs } : {}),
164
+ ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
165
+ ...(options.now ? { now: options.now } : {}),
166
+ ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
167
+ ...(options.onDiagnostic ? { onDiagnostic: options.onDiagnostic } : {}),
168
+ });
169
+ return {
170
+ ok: true,
171
+ readiness: 'ready',
172
+ reason: `adaptive selection ready via runtime profile '${resolved.profileId}'`,
173
+ nextAction: 'none',
174
+ provider,
175
+ profileId: resolved.profileId,
176
+ };
177
+ }
178
+ /**
179
+ * Workspace-facing variant: mirrors the existing signal-classifier readiness
180
+ * contract (flag → profile → api key) so a misconfigured workspace degrades to
181
+ * Native with one observable reason instead of a silent model attempt.
182
+ */
183
+ export function createAdaptivePriorityProviderForWorkspace(workspaceDir, options = {}) {
184
+ const configResult = loadPdConfigForPlugin(workspaceDir);
185
+ if (!configResult.ok) {
186
+ return {
187
+ ok: false,
188
+ readiness: 'needs_setup',
189
+ reason: configResult.errors[0]?.reason ?? 'invalid .pd/config.yaml',
190
+ nextAction: configResult.errors[0]?.nextAction ?? 'Fix .pd/config.yaml and retry',
191
+ };
192
+ }
193
+ return createAdaptivePriorityProviderForConfig(configResult.effective.config, workspaceDir, options);
194
+ }
@@ -0,0 +1,164 @@
1
+ import { PiAiRuntimeAdapter, type ActivatedPrinciple } from '@principles/core/runtime';
2
+ export declare const ADAPTIVE_SELECTION_LIMITS: {
3
+ readonly maxCandidates: 12;
4
+ readonly maxCandidateChars: 600;
5
+ readonly maxPriorMessages: 4;
6
+ readonly maxPriorMessageChars: 1200;
7
+ 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;
13
+ };
14
+ export type AdaptiveSelectionModel = {
15
+ readonly provider: string;
16
+ readonly model: string;
17
+ 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;
22
+ };
23
+ export type AdaptiveCandidateSource = ActivatedPrinciple;
24
+ export interface AdaptiveCandidate {
25
+ readonly ref: string;
26
+ readonly text: string;
27
+ readonly digest: string;
28
+ readonly principle: AdaptiveCandidateSource;
29
+ }
30
+ export interface BoundedSelectionInput {
31
+ readonly payload: {
32
+ readonly currentInstruction: string;
33
+ readonly priorMessages: readonly {
34
+ readonly text: string;
35
+ readonly source: string;
36
+ readonly index: number;
37
+ }[];
38
+ /** `digest` is precomputed locally and only copied by the model. */
39
+ readonly candidates: readonly {
40
+ readonly ref: string;
41
+ readonly text: string;
42
+ readonly digest: string;
43
+ }[];
44
+ };
45
+ readonly entries: readonly AdaptiveCandidate[];
46
+ readonly priorDropped: number;
47
+ }
48
+ export type BuildBoundedInputResult = {
49
+ readonly ok: true;
50
+ readonly input: BoundedSelectionInput;
51
+ } | {
52
+ readonly ok: false;
53
+ readonly reason: string;
54
+ };
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' | 'SELECTION_AMBIGUOUS' | 'SELECTION_EXPIRED'
75
+ /** The host's outer hook window ended Adaptive; distinct from the model's own timeout. */
76
+ | 'TURN_DEADLINE_EXCEEDED' | 'TRANSPORT_NOT_SENT' | 'TRANSPORT_FAILED' | 'INPUT_REFUSED';
77
+ export type AdaptiveSelectionStage = 'idle' | 'admission' | 'generation' | 'validate' | 'revalidate' | 'done';
78
+ export interface AdaptiveSelectionDiagnostics {
79
+ stage: AdaptiveSelectionStage;
80
+ readonly admissionDeadlineAt: number;
81
+ completionDeadlineAt: number | null;
82
+ firstByteAt: number | null;
83
+ generationEndedAt: number | null;
84
+ cancelledAt: number | null;
85
+ httpStatus: number | null;
86
+ /** Server-reported finish reason, or 'unknown' when the transport does not expose one. */
87
+ finishReason: string;
88
+ usage: {
89
+ inputTokens: number | null;
90
+ outputTokens: number | null;
91
+ } | null;
92
+ failures: AdaptiveFailureCode[];
93
+ }
94
+ export declare function hash(value: string): string;
95
+ export declare const ADAPTIVE_SELECTOR_SYSTEM: string;
96
+ export declare function buildBoundedSelectionInput(input: {
97
+ readonly currentInput: string;
98
+ readonly priorMessages?: readonly {
99
+ readonly text: string;
100
+ readonly source?: string;
101
+ }[];
102
+ readonly candidates: readonly AdaptiveCandidateSource[];
103
+ }): BuildBoundedInputResult;
104
+ export declare function parseSelectionShape(value: unknown): {
105
+ readonly ok: true;
106
+ readonly selection: SelectionShape;
107
+ } | {
108
+ readonly ok: false;
109
+ readonly reason: string;
110
+ };
111
+ export declare function validateSelectionResult(value: unknown, entries: readonly AdaptiveCandidate[]): ValidateSelectionResult;
112
+ export declare function localFailureCode(reason: string): AdaptiveFailureCode;
113
+ export interface SingleModelSelectorOptions {
114
+ readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
115
+ readonly fetchImpl?: typeof fetch;
116
+ readonly now?: () => number;
117
+ /** Absolute deadline for the first byte of the model response. */
118
+ readonly admissionDeadlineAt: number;
119
+ readonly generationTimeoutMs?: number;
120
+ readonly model: AdaptiveSelectionModel;
121
+ readonly maxTokens?: number;
122
+ readonly signal?: AbortSignal;
123
+ /** Absolute host deadline. Reaching it is NOT the model's generation timeout. */
124
+ readonly outerDeadlineAt?: number;
125
+ }
126
+ export interface SingleModelSelector {
127
+ readonly select: (input: BoundedSelectionInput) => Promise<unknown>;
128
+ readonly report: () => {
129
+ readonly sends: number;
130
+ readonly status: 'not_sent' | 'sent' | 'failed';
131
+ readonly failure: AdaptiveFailureCode | null;
132
+ readonly diagnostics: AdaptiveSelectionDiagnostics;
133
+ };
134
+ }
135
+ export declare function createSingleModelSelector(options: SingleModelSelectorOptions): SingleModelSelector;
136
+ export interface RunAdaptiveSelectionOptions {
137
+ readonly workspaceDir: string;
138
+ readonly currentPrompt: string;
139
+ /** Absolute first-byte deadline for the incremental step. */
140
+ readonly admissionDeadlineAt: number;
141
+ readonly model: AdaptiveSelectionModel;
142
+ readonly generationTimeoutMs?: number;
143
+ readonly maxTokens?: number;
144
+ readonly signal?: AbortSignal;
145
+ /** Absolute host deadline shared by selection, revalidation and packing. */
146
+ readonly outerDeadlineAt?: number;
147
+ readonly now?: () => number;
148
+ readonly fetchImpl?: typeof fetch;
149
+ readonly PiAiRuntimeAdapterImpl?: typeof PiAiRuntimeAdapter;
150
+ }
151
+ export interface AdaptiveSelectionOutcome {
152
+ readonly status: 'selected' | 'none' | 'unavailable';
153
+ readonly target: ActivatedPrinciple | null;
154
+ readonly reason: string;
155
+ /** Real transport sends for this turn (0 or 1). */
156
+ readonly sends: number;
157
+ readonly diagnostics: AdaptiveSelectionDiagnostics;
158
+ }
159
+ /**
160
+ * Minimal host-facing selection step: read the current frozen candidates,
161
+ * make at most one bounded model call, verify ref+digest, then independently
162
+ * revalidate the chosen principle's content/revision/authorization.
163
+ */
164
+ export declare function runAdaptiveSelection(options: RunAdaptiveSelectionOptions): Promise<AdaptiveSelectionOutcome>;