@oscharko-dev/keiko-contracts 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 (227) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/bff-wire.d.ts +661 -0
  3. package/dist/bff-wire.d.ts.map +1 -0
  4. package/dist/bff-wire.js +102 -0
  5. package/dist/bug-investigation-events.d.ts +92 -0
  6. package/dist/bug-investigation-events.d.ts.map +1 -0
  7. package/dist/bug-investigation-events.js +18 -0
  8. package/dist/coding-context.d.ts +76 -0
  9. package/dist/coding-context.d.ts.map +1 -0
  10. package/dist/coding-context.js +158 -0
  11. package/dist/connected-context.d.ts +174 -0
  12. package/dist/connected-context.d.ts.map +1 -0
  13. package/dist/connected-context.js +636 -0
  14. package/dist/conversation-budget.d.ts +37 -0
  15. package/dist/conversation-budget.d.ts.map +1 -0
  16. package/dist/conversation-budget.js +97 -0
  17. package/dist/editor-agent.d.ts +131 -0
  18. package/dist/editor-agent.d.ts.map +1 -0
  19. package/dist/editor-agent.js +197 -0
  20. package/dist/editor-completion.d.ts +62 -0
  21. package/dist/editor-completion.d.ts.map +1 -0
  22. package/dist/editor-completion.js +147 -0
  23. package/dist/editor-dirty-close.d.ts +17 -0
  24. package/dist/editor-dirty-close.d.ts.map +1 -0
  25. package/dist/editor-dirty-close.js +8 -0
  26. package/dist/editor-hot-exit.d.ts +18 -0
  27. package/dist/editor-hot-exit.d.ts.map +1 -0
  28. package/dist/editor-hot-exit.js +42 -0
  29. package/dist/editor-inline-completion.d.ts +70 -0
  30. package/dist/editor-inline-completion.d.ts.map +1 -0
  31. package/dist/editor-inline-completion.js +215 -0
  32. package/dist/editor-layout.d.ts +105 -0
  33. package/dist/editor-layout.d.ts.map +1 -0
  34. package/dist/editor-layout.js +479 -0
  35. package/dist/editor-patch-apply.d.ts +77 -0
  36. package/dist/editor-patch-apply.d.ts.map +1 -0
  37. package/dist/editor-patch-apply.js +122 -0
  38. package/dist/editor-session.d.ts +31 -0
  39. package/dist/editor-session.d.ts.map +1 -0
  40. package/dist/editor-session.js +75 -0
  41. package/dist/editor-test-generation.d.ts +104 -0
  42. package/dist/editor-test-generation.d.ts.map +1 -0
  43. package/dist/editor-test-generation.js +211 -0
  44. package/dist/evaluations.d.ts +75 -0
  45. package/dist/evaluations.d.ts.map +1 -0
  46. package/dist/evaluations.js +16 -0
  47. package/dist/evidence.d.ts +297 -0
  48. package/dist/evidence.d.ts.map +1 -0
  49. package/dist/evidence.js +9 -0
  50. package/dist/gateway.d.ts +129 -0
  51. package/dist/gateway.d.ts.map +1 -0
  52. package/dist/gateway.js +66 -0
  53. package/dist/harness.d.ts +274 -0
  54. package/dist/harness.d.ts.map +1 -0
  55. package/dist/harness.js +38 -0
  56. package/dist/index.d.ts +101 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +83 -0
  59. package/dist/language-service.d.ts +145 -0
  60. package/dist/language-service.d.ts.map +1 -0
  61. package/dist/language-service.js +161 -0
  62. package/dist/local-knowledge-large-document-validation.d.ts +7 -0
  63. package/dist/local-knowledge-large-document-validation.d.ts.map +1 -0
  64. package/dist/local-knowledge-large-document-validation.js +161 -0
  65. package/dist/local-knowledge-large-document.d.ts +113 -0
  66. package/dist/local-knowledge-large-document.d.ts.map +1 -0
  67. package/dist/local-knowledge-large-document.js +142 -0
  68. package/dist/local-knowledge-paths.d.ts +3 -0
  69. package/dist/local-knowledge-paths.d.ts.map +1 -0
  70. package/dist/local-knowledge-paths.js +65 -0
  71. package/dist/local-knowledge-records.d.ts +190 -0
  72. package/dist/local-knowledge-records.d.ts.map +1 -0
  73. package/dist/local-knowledge-records.js +36 -0
  74. package/dist/local-knowledge-schema-validation.d.ts +19 -0
  75. package/dist/local-knowledge-schema-validation.d.ts.map +1 -0
  76. package/dist/local-knowledge-schema-validation.js +115 -0
  77. package/dist/local-knowledge-schema.d.ts +14 -0
  78. package/dist/local-knowledge-schema.d.ts.map +1 -0
  79. package/dist/local-knowledge-schema.js +715 -0
  80. package/dist/local-knowledge-validation.d.ts +20 -0
  81. package/dist/local-knowledge-validation.d.ts.map +1 -0
  82. package/dist/local-knowledge-validation.js +487 -0
  83. package/dist/local-knowledge.d.ts +158 -0
  84. package/dist/local-knowledge.d.ts.map +1 -0
  85. package/dist/local-knowledge.js +63 -0
  86. package/dist/memory-audit-events.d.ts +73 -0
  87. package/dist/memory-audit-events.d.ts.map +1 -0
  88. package/dist/memory-audit-events.js +44 -0
  89. package/dist/memory-audit-validation.d.ts +4 -0
  90. package/dist/memory-audit-validation.d.ts.map +1 -0
  91. package/dist/memory-audit-validation.js +151 -0
  92. package/dist/memory-barrel.d.ts +15 -0
  93. package/dist/memory-barrel.d.ts.map +1 -0
  94. package/dist/memory-barrel.js +20 -0
  95. package/dist/memory-internal.d.ts +26 -0
  96. package/dist/memory-internal.d.ts.map +1 -0
  97. package/dist/memory-internal.js +104 -0
  98. package/dist/memory-operations-validation.d.ts +12 -0
  99. package/dist/memory-operations-validation.d.ts.map +1 -0
  100. package/dist/memory-operations-validation.js +267 -0
  101. package/dist/memory-operations.d.ts +156 -0
  102. package/dist/memory-operations.d.ts.map +1 -0
  103. package/dist/memory-operations.js +29 -0
  104. package/dist/memory-record-validation.d.ts +10 -0
  105. package/dist/memory-record-validation.d.ts.map +1 -0
  106. package/dist/memory-record-validation.js +101 -0
  107. package/dist/memory-records.d.ts +66 -0
  108. package/dist/memory-records.d.ts.map +1 -0
  109. package/dist/memory-records.js +22 -0
  110. package/dist/memory-retrieval-validation.d.ts +6 -0
  111. package/dist/memory-retrieval-validation.d.ts.map +1 -0
  112. package/dist/memory-retrieval-validation.js +108 -0
  113. package/dist/memory-validation.d.ts +31 -0
  114. package/dist/memory-validation.d.ts.map +1 -0
  115. package/dist/memory-validation.js +318 -0
  116. package/dist/memory-workflow-port.d.ts +26 -0
  117. package/dist/memory-workflow-port.d.ts.map +1 -0
  118. package/dist/memory-workflow-port.js +13 -0
  119. package/dist/memory.d.ts +81 -0
  120. package/dist/memory.d.ts.map +1 -0
  121. package/dist/memory.js +104 -0
  122. package/dist/prompt-enhancer-analyzer.d.ts +7 -0
  123. package/dist/prompt-enhancer-analyzer.d.ts.map +1 -0
  124. package/dist/prompt-enhancer-analyzer.js +745 -0
  125. package/dist/prompt-enhancer-bff.d.ts +67 -0
  126. package/dist/prompt-enhancer-bff.d.ts.map +1 -0
  127. package/dist/prompt-enhancer-bff.js +156 -0
  128. package/dist/prompt-enhancer-critic.d.ts +46 -0
  129. package/dist/prompt-enhancer-critic.d.ts.map +1 -0
  130. package/dist/prompt-enhancer-critic.js +35 -0
  131. package/dist/prompt-enhancer-grounding.d.ts +19 -0
  132. package/dist/prompt-enhancer-grounding.d.ts.map +1 -0
  133. package/dist/prompt-enhancer-grounding.js +235 -0
  134. package/dist/prompt-enhancer-safety.d.ts +66 -0
  135. package/dist/prompt-enhancer-safety.d.ts.map +1 -0
  136. package/dist/prompt-enhancer-safety.js +446 -0
  137. package/dist/prompt-enhancer-validation.d.ts +28 -0
  138. package/dist/prompt-enhancer-validation.d.ts.map +1 -0
  139. package/dist/prompt-enhancer-validation.js +931 -0
  140. package/dist/prompt-enhancer.d.ts +184 -0
  141. package/dist/prompt-enhancer.d.ts.map +1 -0
  142. package/dist/prompt-enhancer.js +350 -0
  143. package/dist/qualityIntelligence/assertNever.d.ts +2 -0
  144. package/dist/qualityIntelligence/assertNever.d.ts.map +1 -0
  145. package/dist/qualityIntelligence/assertNever.js +7 -0
  146. package/dist/qualityIntelligence/auditSummary.d.ts +25 -0
  147. package/dist/qualityIntelligence/auditSummary.d.ts.map +1 -0
  148. package/dist/qualityIntelligence/auditSummary.js +7 -0
  149. package/dist/qualityIntelligence/bffWire.d.ts +356 -0
  150. package/dist/qualityIntelligence/bffWire.d.ts.map +1 -0
  151. package/dist/qualityIntelligence/bffWire.js +22 -0
  152. package/dist/qualityIntelligence/coverageMap.d.ts +21 -0
  153. package/dist/qualityIntelligence/coverageMap.d.ts.map +1 -0
  154. package/dist/qualityIntelligence/coverageMap.js +29 -0
  155. package/dist/qualityIntelligence/editableRevision.d.ts +21 -0
  156. package/dist/qualityIntelligence/editableRevision.d.ts.map +1 -0
  157. package/dist/qualityIntelligence/editableRevision.js +8 -0
  158. package/dist/qualityIntelligence/evidenceAtom.d.ts +35 -0
  159. package/dist/qualityIntelligence/evidenceAtom.d.ts.map +1 -0
  160. package/dist/qualityIntelligence/evidenceAtom.js +29 -0
  161. package/dist/qualityIntelligence/exportBundle.d.ts +28 -0
  162. package/dist/qualityIntelligence/exportBundle.d.ts.map +1 -0
  163. package/dist/qualityIntelligence/exportBundle.js +46 -0
  164. package/dist/qualityIntelligence/handoffEnvelope.d.ts +23 -0
  165. package/dist/qualityIntelligence/handoffEnvelope.d.ts.map +1 -0
  166. package/dist/qualityIntelligence/handoffEnvelope.js +8 -0
  167. package/dist/qualityIntelligence/ids.d.ts +58 -0
  168. package/dist/qualityIntelligence/ids.d.ts.map +1 -0
  169. package/dist/qualityIntelligence/ids.js +93 -0
  170. package/dist/qualityIntelligence/index.d.ts +29 -0
  171. package/dist/qualityIntelligence/index.d.ts.map +1 -0
  172. package/dist/qualityIntelligence/index.js +20 -0
  173. package/dist/qualityIntelligence/reviewRecord.d.ts +19 -0
  174. package/dist/qualityIntelligence/reviewRecord.d.ts.map +1 -0
  175. package/dist/qualityIntelligence/reviewRecord.js +20 -0
  176. package/dist/qualityIntelligence/runPlanAndEvents.d.ts +84 -0
  177. package/dist/qualityIntelligence/runPlanAndEvents.d.ts.map +1 -0
  178. package/dist/qualityIntelligence/runPlanAndEvents.js +51 -0
  179. package/dist/qualityIntelligence/sourceEnvelope.d.ts +77 -0
  180. package/dist/qualityIntelligence/sourceEnvelope.d.ts.map +1 -0
  181. package/dist/qualityIntelligence/sourceEnvelope.js +118 -0
  182. package/dist/qualityIntelligence/testCaseCandidate.d.ts +21 -0
  183. package/dist/qualityIntelligence/testCaseCandidate.d.ts.map +1 -0
  184. package/dist/qualityIntelligence/testCaseCandidate.js +21 -0
  185. package/dist/qualityIntelligence/testQualityRubric.d.ts +17 -0
  186. package/dist/qualityIntelligence/testQualityRubric.d.ts.map +1 -0
  187. package/dist/qualityIntelligence/testQualityRubric.js +32 -0
  188. package/dist/qualityIntelligence/validationFinding.d.ts +48 -0
  189. package/dist/qualityIntelligence/validationFinding.d.ts.map +1 -0
  190. package/dist/qualityIntelligence/validationFinding.js +36 -0
  191. package/dist/relationships-validation.d.ts +13 -0
  192. package/dist/relationships-validation.d.ts.map +1 -0
  193. package/dist/relationships-validation.js +422 -0
  194. package/dist/relationships.d.ts +79 -0
  195. package/dist/relationships.d.ts.map +1 -0
  196. package/dist/relationships.js +307 -0
  197. package/dist/text-safety.d.ts +7 -0
  198. package/dist/text-safety.d.ts.map +1 -0
  199. package/dist/text-safety.js +58 -0
  200. package/dist/tools.d.ts +153 -0
  201. package/dist/tools.d.ts.map +1 -0
  202. package/dist/tools.js +118 -0
  203. package/dist/unit-test-events.d.ts +87 -0
  204. package/dist/unit-test-events.d.ts.map +1 -0
  205. package/dist/unit-test-events.js +14 -0
  206. package/dist/verification-summary.d.ts +38 -0
  207. package/dist/verification-summary.d.ts.map +1 -0
  208. package/dist/verification-summary.js +5 -0
  209. package/dist/verification.d.ts +64 -0
  210. package/dist/verification.d.ts.map +1 -0
  211. package/dist/verification.js +13 -0
  212. package/dist/workflow-descriptor.d.ts +21 -0
  213. package/dist/workflow-descriptor.d.ts.map +1 -0
  214. package/dist/workflow-descriptor.js +8 -0
  215. package/dist/workflow-handoff.d.ts +69 -0
  216. package/dist/workflow-handoff.d.ts.map +1 -0
  217. package/dist/workflow-handoff.js +381 -0
  218. package/dist/workspace-descriptors.d.ts +21 -0
  219. package/dist/workspace-descriptors.d.ts.map +1 -0
  220. package/dist/workspace-descriptors.js +180 -0
  221. package/dist/workspace-ui.d.ts +119 -0
  222. package/dist/workspace-ui.d.ts.map +1 -0
  223. package/dist/workspace-ui.js +105 -0
  224. package/dist/workspace.d.ts +104 -0
  225. package/dist/workspace.d.ts.map +1 -0
  226. package/dist/workspace.js +27 -0
  227. package/package.json +71 -0
@@ -0,0 +1,67 @@
1
+ import type { CostClass } from "./gateway.js";
2
+ import { type EnhancedPrompt, type MissingInformationStrategy, type PromptEnhancementProfileId, type PromptTaskAnalysis, PROMPT_ENHANCER_SCHEMA_VERSION } from "./prompt-enhancer.js";
3
+ import type { PromptCandidateRejection, PromptCandidateScorecard } from "./prompt-enhancer-critic.js";
4
+ import type { PromptSafetyAssessment } from "./prompt-enhancer-safety.js";
5
+ import { type PromptEnhancerValidation } from "./prompt-enhancer-validation.js";
6
+ export declare const PROMPT_ENHANCEMENT_LOCALE_MAX_CHARS: 35;
7
+ export declare const PROMPT_ENHANCEMENT_MODEL_ID_MAX_CHARS: 200;
8
+ export declare const PROMPT_ENHANCEMENT_DEFAULT_CANDIDATE_COUNT: 3;
9
+ export declare const PROMPT_ENHANCEMENT_MAX_CANDIDATE_COUNT: 7;
10
+ export interface PromptEnhancementWireRequest {
11
+ readonly text: string;
12
+ readonly profilePreference?: PromptEnhancementProfileId;
13
+ readonly missingInformationStrategy?: MissingInformationStrategy;
14
+ readonly hasConnectedContext?: boolean;
15
+ readonly attachmentCount?: number;
16
+ readonly locale?: string;
17
+ readonly modelId?: string;
18
+ readonly candidateCount?: number;
19
+ }
20
+ export type PromptEnhancementModelAvailability = "available" | "unavailable" | "not-requested";
21
+ export declare const PROMPT_ENHANCEMENT_MODEL_AVAILABILITIES: readonly PromptEnhancementModelAvailability[];
22
+ export type PromptEnhancementModelRoutingReason = "no-model-requested" | "model-available" | "no-gateway-config" | "model-not-configured" | "model-not-chat-capable";
23
+ export interface PromptEnhancementModelRouting {
24
+ readonly availability: PromptEnhancementModelAvailability;
25
+ readonly reason: PromptEnhancementModelRoutingReason;
26
+ readonly requestedModelId?: string;
27
+ readonly resolvedModelId?: string;
28
+ readonly costClass?: CostClass;
29
+ }
30
+ export interface PromptEnhancementCandidateComparison {
31
+ readonly winnerCandidateId: string;
32
+ readonly scorecards: readonly PromptCandidateScorecard[];
33
+ readonly rejected: readonly PromptCandidateRejection[];
34
+ }
35
+ export type PromptEnhancementGroundingReadinessStatus = "not-required" | "ready" | "unavailable";
36
+ export type PromptEnhancementGroundingReadinessReason = "no-grounding-required" | "connected-context-present" | "missing-concrete-scope";
37
+ export interface PromptEnhancementGroundingReadiness {
38
+ readonly status: PromptEnhancementGroundingReadinessStatus;
39
+ readonly reason: PromptEnhancementGroundingReadinessReason;
40
+ readonly notice?: string;
41
+ }
42
+ export type PromptEnhancementEvidenceReferenceStatus = "recorded" | "not-recorded";
43
+ export type PromptEnhancementEvidenceReferenceReason = "evidence-recorded" | "evidence-store-not-configured";
44
+ export interface PromptEnhancementEvidenceReference {
45
+ readonly status: PromptEnhancementEvidenceReferenceStatus;
46
+ readonly reason: PromptEnhancementEvidenceReferenceReason;
47
+ readonly runId?: string;
48
+ readonly manifestUrl?: string;
49
+ readonly manifestLocation?: string;
50
+ readonly peEvidenceSchemaVersion?: number;
51
+ readonly recordIntegritySha256?: string;
52
+ }
53
+ export interface PromptEnhancementWireResponse {
54
+ readonly schemaVersion: typeof PROMPT_ENHANCER_SCHEMA_VERSION;
55
+ readonly promptId: string;
56
+ readonly inputFingerprintSha256: string;
57
+ readonly analysis: PromptTaskAnalysis;
58
+ readonly enhancedPrompt: EnhancedPrompt;
59
+ readonly renderedPrompt: string;
60
+ readonly candidates: PromptEnhancementCandidateComparison;
61
+ readonly safety: PromptSafetyAssessment;
62
+ readonly modelRouting: PromptEnhancementModelRouting;
63
+ readonly groundingReadiness: PromptEnhancementGroundingReadiness;
64
+ readonly evidence: PromptEnhancementEvidenceReference;
65
+ }
66
+ export declare function validatePromptEnhancementWireRequest(input: unknown): PromptEnhancerValidation<PromptEnhancementWireRequest>;
67
+ //# sourceMappingURL=prompt-enhancer-bff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-enhancer-bff.d.ts","sourceRoot":"","sources":["../src/prompt-en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IACnC,QAAQ,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAC1C,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CACzC;AASD,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,aAAa,EAAE,OAAO,8BAA8B,CAAC;IAE9D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IAGxC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IAGtC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAExC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,QAAQ,CAAC,UAAU,EAAE,oCAAoC,CAAC;IAG1D,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;IAExC,QAAQ,CAAC,YAAY,EAAE,6BAA6B,CAAC;IAErD,QAAQ,CAAC,kBAAkB,EAAE,mCAAmC,CAAC;IAEjE,QAAQ,CAAC,QAAQ,EAAE,kCAAkC,CAAC;CACvD;AA2JD,wBAAgB,oCAAoC,CAClD,KAAK,EAAE,OAAO,GACb,wBAAwB,CAAC,4BAA4B,CAAC,CAYxD"}
@@ -0,0 +1,156 @@
1
+ // Prompt Enhancer BFF wire contracts (Epic #1307, Issue #1314; governed by ADR-0044 §1 row "BFF
2
+ // /api/prompt-enhancer/* routes"). These shapes travel over the HTTP wire between the keiko-server
3
+ // BFF and the React UI / CLI surfaces, exactly like the entity wire types in `bff-wire.ts`.
4
+ //
5
+ // Scope discipline. #1314 is a SURFACE issue: it exposes the deterministic enhancer core (#1309 –
6
+ // #1313) through a governed API, CLI, and UI. This module therefore adds ONLY the request/response
7
+ // envelope and a pure request validator. It introduces no new domain behaviour and no model-execution
8
+ // parameters. The response composes the already content-light, provider-neutral artefacts produced by
9
+ // the existing pipeline (`PromptTaskAnalysis`, `EnhancedPrompt`, `PromptCandidateScorecard`,
10
+ // `PromptSafetyAssessment`) and adds a Model-Gateway readiness/routing descriptor (AC3).
11
+ //
12
+ // Trust boundary (ADR-0044 §5). Like every prompt-enhancer contract, these shapes carry no provider
13
+ // credential, hidden system prompt, or tool/secret/egress/patch authority grant. The wire request is
14
+ // the untrusted user draft plus bounded, validated metadata; the server mints the branded ids and runs
15
+ // the deterministic pipeline. Leaf-package rule (ADR-0019 direction 1): no `@oscharko-dev/keiko-*`
16
+ // import; same-package relative imports only.
17
+ import { stripUnsafeFormatChars } from "./text-safety.js";
18
+ import { MISSING_INFORMATION_STRATEGIES, PROMPT_ENHANCEMENT_PROFILE_IDS, PROMPT_ENHANCER_SCHEMA_VERSION, } from "./prompt-enhancer.js";
19
+ import { PROMPT_REQUEST_TEXT_MAX_CHARS, } from "./prompt-enhancer-validation.js";
20
+ // ─── Bounds ──────────────────────────────────────────────────────────────────────
21
+ // A BCP-47-ish locale tag is informational only; bound it to the same ceiling the domain validator
22
+ // uses. The candidate-count ceiling mirrors the profile-slate size (one candidate per profile); the
23
+ // server additionally clamps to the gateway's own `MAX_CANDIDATE_COUNT` so the wire never widens the
24
+ // optimization envelope.
25
+ export const PROMPT_ENHANCEMENT_LOCALE_MAX_CHARS = 35;
26
+ export const PROMPT_ENHANCEMENT_MODEL_ID_MAX_CHARS = 200;
27
+ export const PROMPT_ENHANCEMENT_DEFAULT_CANDIDATE_COUNT = 3;
28
+ export const PROMPT_ENHANCEMENT_MAX_CANDIDATE_COUNT = 7;
29
+ export const PROMPT_ENHANCEMENT_MODEL_AVAILABILITIES = ["available", "unavailable", "not-requested"];
30
+ // ─── Pure request validator ────────────────────────────────────────────────────────────
31
+ // Mirrors the discriminated-result discipline of `prompt-enhancer-validation.ts`: pure, never throws,
32
+ // one short machine-readable error per failed invariant, never echoes raw input.
33
+ const WIRE_REQUEST_KEYS = new Set([
34
+ "text",
35
+ "profilePreference",
36
+ "missingInformationStrategy",
37
+ "hasConnectedContext",
38
+ "attachmentCount",
39
+ "locale",
40
+ "modelId",
41
+ "candidateCount",
42
+ ]);
43
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
44
+ const isMember = (value, allowed) => typeof value === "string" && allowed.includes(value);
45
+ const isNonNegativeInteger = (value) => typeof value === "number" && Number.isInteger(value) && value >= 0;
46
+ const isBoundedSafeText = (value, max) => typeof value === "string" && value.length <= max && stripUnsafeFormatChars(value) === value;
47
+ const validateUnknownFields = (input, errors) => {
48
+ if (Object.keys(input).some((key) => !WIRE_REQUEST_KEYS.has(key))) {
49
+ errors.push("request must not contain unknown fields");
50
+ }
51
+ };
52
+ const validateTextField = (input, errors) => {
53
+ if (typeof input.text !== "string") {
54
+ errors.push("request.text must be a string");
55
+ }
56
+ else if (input.text.trim().length === 0) {
57
+ errors.push("request.text must not be empty or whitespace-only");
58
+ }
59
+ else if (input.text.length > PROMPT_REQUEST_TEXT_MAX_CHARS) {
60
+ errors.push(`request.text must be at most ${String(PROMPT_REQUEST_TEXT_MAX_CHARS)} characters`);
61
+ }
62
+ };
63
+ const validateProfileField = (input, errors) => {
64
+ if (input.profilePreference !== undefined &&
65
+ !isMember(input.profilePreference, PROMPT_ENHANCEMENT_PROFILE_IDS)) {
66
+ errors.push("request.profilePreference must be a known profile id when set");
67
+ }
68
+ };
69
+ const validateStrategyField = (input, errors) => {
70
+ if (input.missingInformationStrategy !== undefined &&
71
+ !isMember(input.missingInformationStrategy, MISSING_INFORMATION_STRATEGIES)) {
72
+ errors.push("request.missingInformationStrategy must be a known strategy when set");
73
+ }
74
+ };
75
+ const validateConnectedContextField = (input, errors) => {
76
+ if (input.hasConnectedContext !== undefined && typeof input.hasConnectedContext !== "boolean") {
77
+ errors.push("request.hasConnectedContext must be a boolean when set");
78
+ }
79
+ };
80
+ const validateAttachmentCountField = (input, errors) => {
81
+ if (input.attachmentCount !== undefined && !isNonNegativeInteger(input.attachmentCount)) {
82
+ errors.push("request.attachmentCount must be a non-negative integer when set");
83
+ }
84
+ };
85
+ const validateLocaleField = (input, errors) => {
86
+ if (input.locale !== undefined &&
87
+ !isBoundedSafeText(input.locale, PROMPT_ENHANCEMENT_LOCALE_MAX_CHARS)) {
88
+ errors.push(`request.locale must be safe text of at most ${String(PROMPT_ENHANCEMENT_LOCALE_MAX_CHARS)} characters when set`);
89
+ }
90
+ };
91
+ const validateModelIdField = (input, errors) => {
92
+ if (input.modelId !== undefined &&
93
+ (!isBoundedSafeText(input.modelId, PROMPT_ENHANCEMENT_MODEL_ID_MAX_CHARS) ||
94
+ input.modelId.trim().length === 0)) {
95
+ errors.push(`request.modelId must be non-empty safe text of at most ${String(PROMPT_ENHANCEMENT_MODEL_ID_MAX_CHARS)} characters when set`);
96
+ }
97
+ };
98
+ const validateCandidateCountField = (input, errors) => {
99
+ const value = input.candidateCount;
100
+ if (value !== undefined &&
101
+ (typeof value !== "number" ||
102
+ !Number.isInteger(value) ||
103
+ value < 1 ||
104
+ value > PROMPT_ENHANCEMENT_MAX_CANDIDATE_COUNT)) {
105
+ errors.push(`request.candidateCount must be an integer in [1, ${String(PROMPT_ENHANCEMENT_MAX_CANDIDATE_COUNT)}] when set`);
106
+ }
107
+ };
108
+ const WIRE_FIELD_VALIDATORS = [
109
+ validateUnknownFields,
110
+ validateTextField,
111
+ validateProfileField,
112
+ validateStrategyField,
113
+ validateConnectedContextField,
114
+ validateAttachmentCountField,
115
+ validateLocaleField,
116
+ validateModelIdField,
117
+ validateCandidateCountField,
118
+ ];
119
+ // Assemble the validated wire request, omitting absent optionals so exactOptionalPropertyTypes holds.
120
+ function buildWireRequestValue(input) {
121
+ return {
122
+ text: input.text,
123
+ ...(input.profilePreference === undefined
124
+ ? {}
125
+ : { profilePreference: input.profilePreference }),
126
+ ...(input.missingInformationStrategy === undefined
127
+ ? {}
128
+ : {
129
+ missingInformationStrategy: input.missingInformationStrategy,
130
+ }),
131
+ ...(input.hasConnectedContext === undefined
132
+ ? {}
133
+ : { hasConnectedContext: input.hasConnectedContext }),
134
+ ...(input.attachmentCount === undefined
135
+ ? {}
136
+ : { attachmentCount: input.attachmentCount }),
137
+ ...(input.locale === undefined ? {} : { locale: input.locale }),
138
+ ...(input.modelId === undefined ? {} : { modelId: input.modelId }),
139
+ ...(input.candidateCount === undefined
140
+ ? {}
141
+ : { candidateCount: input.candidateCount }),
142
+ };
143
+ }
144
+ export function validatePromptEnhancementWireRequest(input) {
145
+ if (!isRecord(input)) {
146
+ return { ok: false, errors: ["request must be an object"] };
147
+ }
148
+ const errors = [];
149
+ for (const validate of WIRE_FIELD_VALIDATORS) {
150
+ validate(input, errors);
151
+ }
152
+ if (errors.length > 0) {
153
+ return { ok: false, errors };
154
+ }
155
+ return { ok: true, value: buildWireRequestValue(input) };
156
+ }
@@ -0,0 +1,46 @@
1
+ import { PROMPT_ENHANCER_SCHEMA_VERSION, type EnhancedPrompt, type PromptEnhancementProfileId } from "./prompt-enhancer.js";
2
+ import type { PromptSafetyAssessment } from "./prompt-enhancer-safety.js";
3
+ export type PromptCriticDimension = "clarity" | "completeness" | "grounding-readiness" | "safety" | "output-controllability" | "token-efficiency";
4
+ export declare const PROMPT_CRITIC_DIMENSIONS: readonly PromptCriticDimension[];
5
+ export declare const isPromptCriticDimension: (value: unknown) => value is PromptCriticDimension;
6
+ export interface PromptCriticDimensionScore {
7
+ readonly dimension: PromptCriticDimension;
8
+ readonly score: number;
9
+ readonly rationale: string;
10
+ }
11
+ export interface PromptCandidateScorecard {
12
+ readonly schemaVersion: typeof PROMPT_ENHANCER_SCHEMA_VERSION;
13
+ readonly candidateId: string;
14
+ readonly profile: PromptEnhancementProfileId;
15
+ readonly dimensionScores: readonly PromptCriticDimensionScore[];
16
+ readonly aggregateScore: number;
17
+ readonly estimatedTokens: number;
18
+ }
19
+ export type PromptCandidateRejectionReason = "lower-aggregate-score" | "lower-tie-break-rank" | "exceeded-token-budget" | "duplicate-candidate" | "safety-floor-not-preserved" | "safety-validation-failed";
20
+ export declare const PROMPT_CANDIDATE_REJECTION_REASONS: readonly PromptCandidateRejectionReason[];
21
+ export declare const isPromptCandidateRejectionReason: (value: unknown) => value is PromptCandidateRejectionReason;
22
+ export interface PromptCandidateRejection {
23
+ readonly candidateId: string;
24
+ readonly profile: PromptEnhancementProfileId;
25
+ readonly aggregateScore: number | null;
26
+ readonly reason: PromptCandidateRejectionReason;
27
+ }
28
+ export interface PromptOptimizationBounds {
29
+ readonly candidateCount: number;
30
+ readonly tokenBudget: number;
31
+ readonly maxIterations: number;
32
+ }
33
+ export interface PromptCandidateSelection {
34
+ readonly schemaVersion: typeof PROMPT_ENHANCER_SCHEMA_VERSION;
35
+ readonly winner: PromptCandidateScorecard;
36
+ readonly ranked: readonly PromptCandidateScorecard[];
37
+ readonly rankedPrompts: readonly EnhancedPrompt[];
38
+ readonly winnerSafetyAssessment: PromptSafetyAssessment;
39
+ readonly rankedSafetyAssessments: readonly PromptSafetyAssessment[];
40
+ readonly rejected: readonly PromptCandidateRejection[];
41
+ readonly bounds: PromptOptimizationBounds;
42
+ readonly iterations: number;
43
+ readonly candidatesConsidered: number;
44
+ readonly tokensConsumed: number;
45
+ }
46
+ //# sourceMappingURL=prompt-enhancer-critic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-enhancer-critic.d.ts","sourceRoot":"","sources":["../src/prompt-enhancer-critic.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,8BAA8B,EAC9B,KAAK,cAAc,EACnB,KAAK,0BAA0B,EAChC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAM1E,MAAM,MAAM,qBAAqB,GAC7B,SAAS,GACT,cAAc,GACd,qBAAqB,GACrB,QAAQ,GACR,wBAAwB,GACxB,kBAAkB,CAAC;AAEvB,eAAO,MAAM,wBAAwB,EAAE,SAAS,qBAAqB,EAO3D,CAAC;AAEX,eAAO,MAAM,uBAAuB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,qBAC4B,CAAC;AAM/F,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,SAA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Q,CAAC,MAAM,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACrD,QAAQ,CAAC,aAAa,EAAE,SAAS,cAAc,EAAE,CAAC;IAClD,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,CAAC;IACxD,QAAQ,CAAC,uBAAuB,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACpE,QAAQ,CAAC,QAAQ,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACvD,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAE1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IAGtC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC"}
@@ -0,0 +1,35 @@
1
+ // Prompt Enhancer candidate-critic contract surface (Epic #1307, Issue #1312; ADR-0044 §1/§6).
2
+ //
3
+ // Wire-safe, provider-neutral type shapes for the deterministic PromptCritic: the scoring dimensions,
4
+ // a transparent per-candidate scorecard, the auditable selection result of the bounded optimization
5
+ // loop, and the configured optimization bounds. The deterministic scoring *logic* lives in the model
6
+ // gateway (`keiko-model-gateway/src/promptEnhancer/critic.ts`); this module owns only the contract
7
+ // shapes so the server (#1314) and offline evaluation suite (#1315) can transmit and render scorecards
8
+ // without re-deriving them.
9
+ //
10
+ // These dimensions are deliberately a distinct set from the agent-run-trajectory `EVALUATION_DIMENSIONS`
11
+ // (`evaluations.ts`): those score a completed workflow run pass/fail, whereas these score the *quality
12
+ // of an Enhanced Prompt artefact* on a continuous [0, 1] scale so candidates can be ranked.
13
+ //
14
+ // Determinism: pure value tables and types only. No IO, clock, randomness, or module-level side
15
+ // effects. Leaf-package rule (ADR-0019 direction 1): no `@oscharko-dev/keiko-*` imports.
16
+ import { PROMPT_ENHANCER_SCHEMA_VERSION, } from "./prompt-enhancer.js";
17
+ export const PROMPT_CRITIC_DIMENSIONS = [
18
+ "clarity",
19
+ "completeness",
20
+ "grounding-readiness",
21
+ "safety",
22
+ "output-controllability",
23
+ "token-efficiency",
24
+ ];
25
+ export const isPromptCriticDimension = (value) => typeof value === "string" && PROMPT_CRITIC_DIMENSIONS.includes(value);
26
+ export const PROMPT_CANDIDATE_REJECTION_REASONS = [
27
+ "lower-aggregate-score",
28
+ "lower-tie-break-rank",
29
+ "exceeded-token-budget",
30
+ "duplicate-candidate",
31
+ "safety-floor-not-preserved",
32
+ "safety-validation-failed",
33
+ ];
34
+ export const isPromptCandidateRejectionReason = (value) => typeof value === "string" &&
35
+ PROMPT_CANDIDATE_REJECTION_REASONS.includes(value);
@@ -0,0 +1,19 @@
1
+ import { type GroundingDirective, type GroundingPlan, type GroundingSourceKind, type GroundingSourcePolicy, type GroundingStrategy, type NoAnswerCondition, type PromptEnhancementProfileId, type PromptTaskAnalysis, type RagEvaluationDimension, type RetrievalMode } from "./prompt-enhancer.js";
2
+ export declare const SOURCE_PRIORITY_BY_STRATEGY: Readonly<Record<GroundingStrategy, readonly GroundingSourceKind[]>>;
3
+ export declare const RETRIEVAL_MODES_BY_STRATEGY: Readonly<Record<GroundingStrategy, readonly RetrievalMode[]>>;
4
+ export declare function buildSourcePriority(strategy: GroundingStrategy, required: boolean): readonly GroundingSourcePolicy[];
5
+ export declare const MULTI_SOURCE_STRATEGIES: ReadonlySet<GroundingStrategy>;
6
+ export declare const SCOPED_EVIDENCE_STRATEGIES: ReadonlySet<GroundingStrategy>;
7
+ export declare function buildNoAnswerConditions(strategy: GroundingStrategy, analysis: PromptTaskAnalysis): readonly NoAnswerCondition[];
8
+ export declare function buildDirectives(strategy: GroundingStrategy, required: boolean): readonly GroundingDirective[];
9
+ export declare const RAG_HINT_TEMPLATES: Readonly<Record<RagEvaluationDimension, string>>;
10
+ export interface PlanGroundingOptions {
11
+ readonly profile?: PromptEnhancementProfileId | undefined;
12
+ }
13
+ /**
14
+ * Build a deterministic `GroundingPlan` from a `PromptTaskAnalysis`. Pure: identical analyses/options
15
+ * always produce an identical plan. The plan is a provider-neutral source policy; it never performs or
16
+ * authorizes retrieval.
17
+ */
18
+ export declare function planGrounding(analysis: PromptTaskAnalysis, options?: PlanGroundingOptions): GroundingPlan;
19
+ //# sourceMappingURL=prompt-enhancer-grounding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-enhancer-grounding.d.ts","sourceRoot":"","sources":["../src/prompt-enhancer-grounding.ts"],"names":[],"mappings":"AAYA,OAAO,EAKL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EAEvB,KAAK,sBAAsB,EAG3B,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AA4D9B,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAChD,MAAM,CAAC,iBAAiB,EAAE,SAAS,mBAAmB,EAAE,CAAC,CAiB1D,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAChD,MAAM,CAAC,iBAAiB,EAAE,SAAS,aAAa,EAAE,CAAC,CAQpD,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,OAAO,GAChB,SAAS,qBAAqB,EAAE,CAQlC;AAwDD,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,iBAAiB,CAKjE,CAAC;AAEH,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,iBAAiB,CAIpE,CAAC;AAEH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,kBAAkB,GAC3B,SAAS,iBAAiB,EAAE,CAe9B;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,OAAO,GAChB,SAAS,kBAAkB,EAAE,CAoB/B;AAkBD,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAW/E,CAAC;AAgBF,MAAM,WAAW,oBAAoB;IAGnC,QAAQ,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;CAC3D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAkBf"}
@@ -0,0 +1,235 @@
1
+ // Deterministic Prompt Enhancer grounding planner (Issue #1311, ADR-0044 §1/§5 / blueprint §6).
2
+ //
3
+ // `planGrounding` turns a normalized `PromptTaskAnalysis` (#1309) into a structured `GroundingPlan`:
4
+ // a provider-neutral source POLICY (which sources, in what priority, with what citation/contradiction/
5
+ // uncertainty discipline and which RAG evaluation hints). It performs NO retrieval — actual grounding
6
+ // stays in the existing Keiko paths (Local Knowledge / repository context / hybrid RRF, ADR-0034/0036),
7
+ // bound to the plan by the server (#1314). The planner is pure: identical analyses always yield an
8
+ // identical plan; no model call, IO, clock read, or randomness; no raw input text is echoed.
9
+ //
10
+ // Leaf-package rule (ADR-0019 direction 1): no `@oscharko-dev/keiko-*` imports. Only the same-package
11
+ // contract surface in `./prompt-enhancer.js` is consumed.
12
+ import { PROMPT_ENHANCEMENT_PROFILES, RAG_EVALUATION_DIMENSIONS, } from "./prompt-enhancer.js";
13
+ // ─── Strategy selection ────────────────────────────────────────────────────────────
14
+ // The code-oriented task classes whose external-knowledge grounding is best served by the repository
15
+ // context rather than a document store.
16
+ const CODE_TASK_CLASSES = new Set([
17
+ "code-generation",
18
+ "code-debugging",
19
+ "code-architecture",
20
+ ]);
21
+ function selectExternalKnowledgeStrategy(analysis) {
22
+ if (analysis.taskClass === "rag-question-answering") {
23
+ return "local-knowledge";
24
+ }
25
+ if (analysis.domain === "software" || CODE_TASK_CLASSES.has(analysis.taskClass)) {
26
+ return "repository-context";
27
+ }
28
+ // Research, decision support, and other knowledge-intensive tasks combine the available sources.
29
+ return "hybrid";
30
+ }
31
+ // Map the analyzer's grounding-need kind to a concrete grounding strategy. The four need kinds map
32
+ // directly except `external-knowledge`, which is refined by task class / domain into the
33
+ // local-knowledge / repository-context / hybrid strategies.
34
+ function selectStrategy(analysis) {
35
+ switch (analysis.groundingNeed.kind) {
36
+ case "none":
37
+ return "no-grounding";
38
+ case "supplied-context":
39
+ return "supplied-context-only";
40
+ case "external-current":
41
+ return "external-research-required";
42
+ case "external-knowledge":
43
+ return selectExternalKnowledgeStrategy(analysis);
44
+ }
45
+ }
46
+ // Whether grounded evidence is required for an acceptable answer. Retrieval-bound strategies always
47
+ // require it; a hybrid plan requires it only when the profile mandates grounding or the user connected
48
+ // context; `no-grounding` never does (the model answers from stable knowledge under discipline).
49
+ function isGroundingRequired(strategy, groundingMandatory, connected) {
50
+ switch (strategy) {
51
+ case "no-grounding":
52
+ return false;
53
+ case "supplied-context-only":
54
+ case "local-knowledge":
55
+ case "repository-context":
56
+ case "external-research-required":
57
+ return true;
58
+ case "hybrid":
59
+ return groundingMandatory || connected;
60
+ }
61
+ }
62
+ // ─── Source priority + allowed retrieval modes ─────────────────────────────────────
63
+ export const SOURCE_PRIORITY_BY_STRATEGY = {
64
+ "no-grounding": ["model-parametric-knowledge"],
65
+ "supplied-context-only": ["supplied-context", "model-parametric-knowledge"],
66
+ "local-knowledge": ["local-knowledge", "supplied-context", "model-parametric-knowledge"],
67
+ "repository-context": ["repository-context", "supplied-context", "model-parametric-knowledge"],
68
+ hybrid: [
69
+ "supplied-context",
70
+ "local-knowledge",
71
+ "repository-context",
72
+ "model-parametric-knowledge",
73
+ ],
74
+ "external-research-required": [
75
+ "external-current",
76
+ "supplied-context",
77
+ "model-parametric-knowledge",
78
+ ],
79
+ };
80
+ export const RETRIEVAL_MODES_BY_STRATEGY = {
81
+ "no-grounding": ["none"],
82
+ "supplied-context-only": ["supplied-context"],
83
+ "local-knowledge": ["local-knowledge-retrieval", "supplied-context"],
84
+ "repository-context": ["repository-search", "supplied-context"],
85
+ hybrid: ["hybrid-fusion", "local-knowledge-retrieval", "repository-search", "supplied-context"],
86
+ "external-research-required": ["external-research", "supplied-context"],
87
+ };
88
+ export function buildSourcePriority(strategy, required) {
89
+ return SOURCE_PRIORITY_BY_STRATEGY[strategy].map((source, index) => ({
90
+ source,
91
+ priority: index + 1,
92
+ // Only the top non-parametric source is mandatory, and only when the plan requires grounding;
93
+ // parametric knowledge is always an optional fallback, never a required source.
94
+ required: required && index === 0 && source !== "model-parametric-knowledge",
95
+ }));
96
+ }
97
+ // ─── Citation, recency, contradiction ──────────────────────────────────────────────
98
+ function isSafetyCriticalAnalysis(analysis) {
99
+ return analysis.criticality === "critical" || analysis.taskClass === "safety-critical";
100
+ }
101
+ function buildCitationRequirement(strategy, analysis, required) {
102
+ if (strategy === "no-grounding") {
103
+ return { discipline: "not-required", granularity: "none" };
104
+ }
105
+ // Safety-critical and current-information answers must cite or explicitly state the absence of
106
+ // evidence — silence is not acceptable for high-stakes or volatile claims.
107
+ if (isSafetyCriticalAnalysis(analysis) || strategy === "external-research-required") {
108
+ return { discipline: "require-citations-or-state-no-evidence", granularity: "per-claim" };
109
+ }
110
+ if (required) {
111
+ return { discipline: "require-citations", granularity: "per-claim" };
112
+ }
113
+ return { discipline: "best-effort", granularity: "per-section" };
114
+ }
115
+ function buildRecency(analysis, strategy) {
116
+ const volatile = analysis.groundingNeed.volatile;
117
+ return {
118
+ volatile,
119
+ requireAsOfDate: volatile,
120
+ flagPotentiallyStale: volatile || strategy === "external-research-required",
121
+ };
122
+ }
123
+ function selectContradictionPolicy(strategy, analysis) {
124
+ if (isSafetyCriticalAnalysis(analysis)) {
125
+ return "disclose-and-defer";
126
+ }
127
+ if (strategy === "hybrid" ||
128
+ strategy === "external-research-required" ||
129
+ analysis.taskClass === "research") {
130
+ return "synthesize-with-caveats";
131
+ }
132
+ return "prefer-higher-priority";
133
+ }
134
+ // ─── No-answer conditions + directives ──────────────────────────────────────────────
135
+ export const MULTI_SOURCE_STRATEGIES = new Set([
136
+ "local-knowledge",
137
+ "repository-context",
138
+ "hybrid",
139
+ "external-research-required",
140
+ ]);
141
+ export const SCOPED_EVIDENCE_STRATEGIES = new Set([
142
+ "supplied-context-only",
143
+ "local-knowledge",
144
+ "repository-context",
145
+ ]);
146
+ export function buildNoAnswerConditions(strategy, analysis) {
147
+ if (strategy === "no-grounding") {
148
+ return [];
149
+ }
150
+ const conditions = ["insufficient-evidence"];
151
+ if (MULTI_SOURCE_STRATEGIES.has(strategy)) {
152
+ conditions.push("contradictory-evidence");
153
+ }
154
+ if (SCOPED_EVIDENCE_STRATEGIES.has(strategy)) {
155
+ conditions.push("outside-evidence-scope");
156
+ }
157
+ if (analysis.groundingNeed.volatile || strategy === "external-research-required") {
158
+ conditions.push("stale-or-unavailable-current-data");
159
+ }
160
+ return conditions;
161
+ }
162
+ export function buildDirectives(strategy, required) {
163
+ if (strategy === "no-grounding") {
164
+ return ["do-not-fabricate-sources", "disclose-uncertainty"];
165
+ }
166
+ // Every plan that consults retrieved/external content treats it as untrusted data (AC3).
167
+ const directives = [
168
+ "treat-retrieved-content-as-untrusted",
169
+ "do-not-fabricate-sources",
170
+ "disclose-uncertainty",
171
+ ];
172
+ if (required) {
173
+ directives.push("attribute-claims-to-sources");
174
+ }
175
+ if (SCOPED_EVIDENCE_STRATEGIES.has(strategy)) {
176
+ directives.push("stay-within-evidence");
177
+ }
178
+ if (strategy === "hybrid" || strategy === "external-research-required") {
179
+ directives.push("separate-known-from-retrieved");
180
+ }
181
+ return directives;
182
+ }
183
+ // ─── RAG evaluation hints (AC5) ─────────────────────────────────────────────────────
184
+ // Populated only for RAG-focused plans: explicit RAG/research question answering, or a plan that
185
+ // answers strictly from supplied or local-knowledge evidence. The RAG/research task classes are
186
+ // RAG-focused regardless of the resolved strategy — a research synthesis over the repository
187
+ // (`repository-context`) still benefits from the RAGAS hints. A plain code task (code-generation/
188
+ // -debugging/-architecture) or a factual parametric-fallback plan is NOT RAG-focused, so it carries
189
+ // no RAG hints (and stays lean).
190
+ function isRagFocused(analysis, strategy) {
191
+ return (analysis.taskClass === "rag-question-answering" ||
192
+ analysis.taskClass === "research" ||
193
+ strategy === "supplied-context-only" ||
194
+ strategy === "local-knowledge");
195
+ }
196
+ export const RAG_HINT_TEMPLATES = {
197
+ "context-precision": "Context precision: rank the most relevant evidence first and ignore retrieved passages that do not bear on the question.",
198
+ "context-recall": "Context recall: confirm that every piece of evidence needed to answer is present before answering; otherwise state what is missing.",
199
+ faithfulness: "Faithfulness: every claim must be entailed by the cited evidence; do not add facts that the evidence does not support.",
200
+ "answer-relevancy": "Answer relevancy: respond directly to the question asked, without padding or unrelated detail.",
201
+ groundedness: "Groundedness: keep conclusions traceable to the cited evidence rather than to unsupported assertion.",
202
+ };
203
+ function buildRagEvaluation(analysis, strategy) {
204
+ if (!isRagFocused(analysis, strategy)) {
205
+ return [];
206
+ }
207
+ return RAG_EVALUATION_DIMENSIONS.map((dimension) => ({
208
+ dimension,
209
+ instruction: RAG_HINT_TEMPLATES[dimension],
210
+ }));
211
+ }
212
+ /**
213
+ * Build a deterministic `GroundingPlan` from a `PromptTaskAnalysis`. Pure: identical analyses/options
214
+ * always produce an identical plan. The plan is a provider-neutral source policy; it never performs or
215
+ * authorizes retrieval.
216
+ */
217
+ export function planGrounding(analysis, options = {}) {
218
+ const profile = PROMPT_ENHANCEMENT_PROFILES[options.profile ?? analysis.recommendedProfile];
219
+ const connected = analysis.groundingNeed.signals.includes("supplied-context-reference");
220
+ const strategy = selectStrategy(analysis);
221
+ const required = isGroundingRequired(strategy, profile.groundingMandatory, connected);
222
+ return {
223
+ strategy,
224
+ required,
225
+ allowedRetrievalModes: [...RETRIEVAL_MODES_BY_STRATEGY[strategy]],
226
+ sourcePriority: buildSourcePriority(strategy, required),
227
+ citation: buildCitationRequirement(strategy, analysis, required),
228
+ recency: buildRecency(analysis, strategy),
229
+ contradictionPolicy: selectContradictionPolicy(strategy, analysis),
230
+ noAnswerConditions: buildNoAnswerConditions(strategy, analysis),
231
+ directives: buildDirectives(strategy, required),
232
+ ragEvaluation: buildRagEvaluation(analysis, strategy),
233
+ untrustedContent: true,
234
+ };
235
+ }
@@ -0,0 +1,66 @@
1
+ import { PROMPT_ENHANCER_SCHEMA_VERSION, type EnhancedPrompt, type EnhancedPromptId, type PromptTaskAnalysis } from "./prompt-enhancer.js";
2
+ import type { PromptEnhancerValidation } from "./prompt-enhancer-validation.js";
3
+ export type PromptSafetyRuleId = "trusted-untrusted-separation" | "untrusted-content-marked" | "no-authority-grant" | "no-secret-or-system-prompt-disclosure" | "human-review-for-risky-actions" | "least-privilege-tool-access" | "output-validation-required" | "no-manipulative-or-injected-instructions";
4
+ export declare const PROMPT_SAFETY_RULE_IDS: readonly PromptSafetyRuleId[];
5
+ export type PromptSafetyViolationCode = "missing-channel-separation" | "missing-untrusted-marker" | "missing-authority-restriction" | "missing-secrecy-rule" | "missing-human-review" | "missing-least-privilege" | "missing-output-validation" | "capability-grant-claim" | "secret-request" | "system-prompt-disclosure" | "untrusted-instruction-override" | "manipulative-instruction" | "hidden-assumption";
6
+ export declare const PROMPT_SAFETY_VIOLATION_CODES: readonly PromptSafetyViolationCode[];
7
+ export declare const isPromptSafetyViolationCode: (value: unknown) => value is PromptSafetyViolationCode;
8
+ export type PromptSafetySeverity = "info" | "warning" | "blocking";
9
+ export declare const PROMPT_SAFETY_SEVERITIES: readonly PromptSafetySeverity[];
10
+ export type LeastPrivilegeConstraint = "no-tool-execution" | "no-file-write" | "no-network-egress" | "no-secret-access" | "require-human-approval";
11
+ export declare const LEAST_PRIVILEGE_CONSTRAINTS: readonly LeastPrivilegeConstraint[];
12
+ export type PromptSafetyDecision = "accepted" | "requires-human-review" | "rejected";
13
+ export declare const PROMPT_SAFETY_DECISIONS: readonly PromptSafetyDecision[];
14
+ export type PromptSafetyVerificationStatus = "passed" | "passed-with-review" | "failed";
15
+ export declare const PROMPT_SAFETY_VERIFICATION_STATUSES: readonly PromptSafetyVerificationStatus[];
16
+ export interface PromptSafetyFinding {
17
+ readonly code: PromptSafetyViolationCode;
18
+ readonly ruleId: PromptSafetyRuleId;
19
+ readonly severity: PromptSafetySeverity;
20
+ readonly detail: string;
21
+ }
22
+ export interface PromptSafetyAssessment {
23
+ readonly schemaVersion: typeof PROMPT_ENHANCER_SCHEMA_VERSION;
24
+ readonly promptId: EnhancedPromptId;
25
+ readonly decision: PromptSafetyDecision;
26
+ readonly requiresHumanReview: boolean;
27
+ readonly verificationStatus: PromptSafetyVerificationStatus;
28
+ readonly findings: readonly PromptSafetyFinding[];
29
+ readonly leastPrivilege: readonly LeastPrivilegeConstraint[];
30
+ }
31
+ export declare const PROMPT_SAFETY_VIOLATION_DETAILS: Readonly<Record<PromptSafetyViolationCode, string>>;
32
+ /**
33
+ * Derive whether a task is risky enough to require human review before any side-effecting action
34
+ * (AC5). Pure. A task is risky when it is agentic, requests tool/egress authority, or is critical.
35
+ */
36
+ export declare function requiresHumanReviewForAnalysis(analysis: PromptTaskAnalysis): boolean;
37
+ /**
38
+ * Reduce a finding set and the human-review flag to the decision + verification status. Pure. Shared
39
+ * by the structural assessor and the gateway validate stage (which adds security findings first).
40
+ */
41
+ export declare function summarizePromptSafety(findings: readonly PromptSafetyFinding[], requiresHumanReview: boolean): {
42
+ readonly decision: PromptSafetyDecision;
43
+ readonly verificationStatus: PromptSafetyVerificationStatus;
44
+ };
45
+ /**
46
+ * Compute the least-privilege constraint set for a task. Pure. Always denies tool/file/egress/secret
47
+ * authority (least privilege by default); risky tasks additionally require human approval (AC5).
48
+ */
49
+ export declare function leastPrivilegeForAnalysis(analysis: PromptTaskAnalysis): readonly LeastPrivilegeConstraint[];
50
+ /**
51
+ * Deterministically assess the STRUCTURAL safety of an `EnhancedPrompt` against the validate-stage
52
+ * rule set. Pure. Confirms the required safeguards are present (AC1/AC2/AC5, no-authority,
53
+ * no-disclosure, output validation) and that the trusted sections carry no authority-grant, override,
54
+ * or disclosure claim (AC3 defense in depth). The authoritative text-level detection over untrusted
55
+ * input is layered on top by the gateway validate stage; this function never inspects raw input.
56
+ */
57
+ export declare function assessEnhancedPromptStructuralSafety(prompt: EnhancedPrompt, analysis: PromptTaskAnalysis): PromptSafetyAssessment;
58
+ /**
59
+ * Validate a `PromptSafetyAssessment`. Pure; returns a discriminated result and never throws. Checks
60
+ * structural well-formedness and the cross-field invariants that make the assessment trustworthy: the
61
+ * verification status matches the decision, a `rejected` decision carries at least one blocking
62
+ * finding, and a human-review requirement implies the `require-human-approval` least-privilege
63
+ * constraint.
64
+ */
65
+ export declare function validatePromptSafetyAssessment(input: unknown): PromptEnhancerValidation<PromptSafetyAssessment>;
66
+ //# sourceMappingURL=prompt-enhancer-safety.d.ts.map