@principles/core 1.123.0 → 1.124.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 (121) hide show
  1. package/dist/runtime-v2/__tests__/architecture-regression.test.js +37 -73
  2. package/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  3. package/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  4. package/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js +4 -0
  5. package/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js.map +1 -1
  6. package/dist/runtime-v2/config/pd-config-types.d.ts +2 -0
  7. package/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
  8. package/dist/runtime-v2/config/pd-config-types.js.map +1 -1
  9. package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.d.ts +2 -0
  10. package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.d.ts.map +1 -0
  11. package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.js +45 -0
  12. package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.js.map +1 -0
  13. package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.d.ts +2 -0
  14. package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.d.ts.map +1 -0
  15. package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js +57 -0
  16. package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js.map +1 -0
  17. package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.d.ts +2 -0
  18. package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.d.ts.map +1 -0
  19. package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.js +39 -0
  20. package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.js.map +1 -0
  21. package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.d.ts +2 -0
  22. package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.d.ts.map +1 -0
  23. package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js +34 -0
  24. package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js.map +1 -0
  25. package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.d.ts +2 -0
  26. package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.d.ts.map +1 -0
  27. package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.js +57 -0
  28. package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.js.map +1 -0
  29. package/dist/runtime-v2/diagnostician/diag-distiller-output.d.ts +80 -0
  30. package/dist/runtime-v2/diagnostician/diag-distiller-output.d.ts.map +1 -0
  31. package/dist/runtime-v2/diagnostician/diag-distiller-output.js +103 -0
  32. package/dist/runtime-v2/diagnostician/diag-distiller-output.js.map +1 -0
  33. package/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts +115 -0
  34. package/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts.map +1 -0
  35. package/dist/runtime-v2/diagnostician/diag-rootcause-output.js +166 -0
  36. package/dist/runtime-v2/diagnostician/diag-rootcause-output.js.map +1 -0
  37. package/dist/runtime-v2/diagnostician/distiller-prompt-builder.d.ts +134 -0
  38. package/dist/runtime-v2/diagnostician/distiller-prompt-builder.d.ts.map +1 -0
  39. package/dist/runtime-v2/diagnostician/distiller-prompt-builder.js +156 -0
  40. package/dist/runtime-v2/diagnostician/distiller-prompt-builder.js.map +1 -0
  41. package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts +96 -0
  42. package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts.map +1 -0
  43. package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js +216 -0
  44. package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js.map +1 -0
  45. package/dist/runtime-v2/diagnostician/router-prompt-builder.d.ts +127 -0
  46. package/dist/runtime-v2/diagnostician/router-prompt-builder.d.ts.map +1 -0
  47. package/dist/runtime-v2/diagnostician/router-prompt-builder.js +131 -0
  48. package/dist/runtime-v2/diagnostician/router-prompt-builder.js.map +1 -0
  49. package/dist/runtime-v2/index.d.ts +6 -3
  50. package/dist/runtime-v2/index.d.ts.map +1 -1
  51. package/dist/runtime-v2/index.js +1 -1
  52. package/dist/runtime-v2/index.js.map +1 -1
  53. package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.d.ts +25 -0
  54. package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.d.ts.map +1 -0
  55. package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.js +123 -0
  56. package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.js.map +1 -0
  57. package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.d.ts +2 -0
  58. package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.d.ts.map +1 -0
  59. package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js +731 -0
  60. package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js.map +1 -0
  61. package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.d.ts +2 -0
  62. package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.d.ts.map +1 -0
  63. package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.js +437 -0
  64. package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.js.map +1 -0
  65. package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.d.ts +2 -0
  66. package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.d.ts.map +1 -0
  67. package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.js +336 -0
  68. package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.js.map +1 -0
  69. package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.d.ts +2 -0
  70. package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.d.ts.map +1 -0
  71. package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.js +437 -0
  72. package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.js.map +1 -0
  73. package/dist/runtime-v2/internalization/diag-distiller-runner.d.ts +83 -0
  74. package/dist/runtime-v2/internalization/diag-distiller-runner.d.ts.map +1 -0
  75. package/dist/runtime-v2/internalization/diag-distiller-runner.js +274 -0
  76. package/dist/runtime-v2/internalization/diag-distiller-runner.js.map +1 -0
  77. package/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts +73 -0
  78. package/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts.map +1 -0
  79. package/dist/runtime-v2/internalization/diag-rootcause-runner.js +229 -0
  80. package/dist/runtime-v2/internalization/diag-rootcause-runner.js.map +1 -0
  81. package/dist/runtime-v2/internalization/diag-router-runner.d.ts +85 -0
  82. package/dist/runtime-v2/internalization/diag-router-runner.d.ts.map +1 -0
  83. package/dist/runtime-v2/internalization/diag-router-runner.js +353 -0
  84. package/dist/runtime-v2/internalization/diag-router-runner.js.map +1 -0
  85. package/dist/runtime-v2/internalization/evaluator-runner.d.ts +1 -1
  86. package/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
  87. package/dist/runtime-v2/internalization/evaluator-runner.js +1 -1
  88. package/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
  89. package/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts +66 -0
  90. package/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts.map +1 -0
  91. package/dist/runtime-v2/internalization/split-diagnostician-runner.js +172 -0
  92. package/dist/runtime-v2/internalization/split-diagnostician-runner.js.map +1 -0
  93. package/dist/runtime-v2/pain-signal-bridge.d.ts +22 -3
  94. package/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
  95. package/dist/runtime-v2/pain-signal-bridge.js +16 -7
  96. package/dist/runtime-v2/pain-signal-bridge.js.map +1 -1
  97. package/dist/runtime-v2/pain-signal-runtime-factory.d.ts +3 -0
  98. package/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
  99. package/dist/runtime-v2/pain-signal-runtime-factory.js +52 -24
  100. package/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
  101. package/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js +2 -2
  102. package/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js.map +1 -1
  103. package/dist/runtime-v2/runner/base-peer-runner.d.ts +3 -3
  104. package/dist/runtime-v2/runner/base-peer-runner.d.ts.map +1 -1
  105. package/dist/runtime-v2/runner/base-peer-runner.js +6 -6
  106. package/dist/runtime-v2/runner/base-peer-runner.js.map +1 -1
  107. package/dist/runtime-v2/runner/peer-runner-types.d.ts +3 -3
  108. package/dist/runtime-v2/runner/peer-runner-types.d.ts.map +1 -1
  109. package/dist/runtime-v2/store/candidate/sqlite-candidate-store.js +2 -2
  110. package/dist/runtime-v2/store/candidate/sqlite-candidate-store.js.map +1 -1
  111. package/dist/runtime-v2/types/principle-enums.d.ts +2 -2
  112. package/dist/runtime-v2/types/principle-enums.d.ts.map +1 -1
  113. package/dist/runtime-v2/types/principle-enums.js +1 -0
  114. package/dist/runtime-v2/types/principle-enums.js.map +1 -1
  115. package/dist/runtime-v2/types/principle-schema.d.ts +1 -1
  116. package/dist/runtime-v2/types/principle-tree-store.d.ts +1 -1
  117. package/dist/telemetry-event.d.ts +2 -2
  118. package/dist/telemetry-event.d.ts.map +1 -1
  119. package/dist/telemetry-event.js +1 -0
  120. package/dist/telemetry-event.js.map +1 -1
  121. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Stage B (Distiller) output schema for the split diagnostician pipeline.
3
+ *
4
+ * The Distiller takes the root-cause artifact from Stage A and produces
5
+ * an abstracted, cross-scenario principle grounded on the T-01..T-10
6
+ * core axiom registry.
7
+ *
8
+ * @see PRI-372 — Split diagnostician into Stage A (Root Cause) + Stage B (Distiller)
9
+ */
10
+ import { type Static } from '@sinclair/typebox';
11
+ export declare const DiagDistillerScopeSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"general">, import("@sinclair/typebox").TLiteral<"domain">, import("@sinclair/typebox").TLiteral<"scenario">]>;
12
+ /** Scope classification for a distilled principle. */
13
+ export type DiagDistillerScope = Static<typeof DiagDistillerScopeSchema>;
14
+ /**
15
+ * TypeBox schema for Stage B (Distiller) output.
16
+ *
17
+ * Lineage consistency: `sourceRootCauseArtifactId` must match the artifact
18
+ * produced by Stage A so that the pipeline can trace every distilled
19
+ * principle back to its root-cause diagnosis.
20
+ *
21
+ * `groundedOnCorePrincipleIds` is validated against the T-01..T-10
22
+ * registry at runtime — fabricated IDs cause validation failure.
23
+ *
24
+ * @see PRI-372
25
+ */
26
+ export declare const DiagDistillerOutputV1Schema: import("@sinclair/typebox").TObject<{
27
+ valid: import("@sinclair/typebox").TBoolean;
28
+ taskId: import("@sinclair/typebox").TString;
29
+ sourceRootCauseArtifactId: import("@sinclair/typebox").TString;
30
+ abstractedPrinciple: import("@sinclair/typebox").TString;
31
+ rationale: import("@sinclair/typebox").TString;
32
+ groundedOnCorePrincipleIds: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
33
+ scope: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"general">, import("@sinclair/typebox").TLiteral<"domain">, import("@sinclair/typebox").TLiteral<"scenario">]>;
34
+ confidence: import("@sinclair/typebox").TNumber;
35
+ ambiguityNotes: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
36
+ }>;
37
+ /** Inferred TypeScript type for Stage B (Distiller) output. */
38
+ export type DiagDistillerOutputV1 = Static<typeof DiagDistillerOutputV1Schema>;
39
+ /**
40
+ * Validator interface for DiagDistillerOutputV1.
41
+ *
42
+ * Accepts `unknown` input — implementations must perform runtime checks (ERR-001).
43
+ *
44
+ * @see PRI-372
45
+ */
46
+ export interface DiagDistillerValidator {
47
+ /**
48
+ * Validate untrusted distiller stage output.
49
+ *
50
+ * @param output - Raw output to validate (treated as unknown — ERR-001)
51
+ * @param taskId - Expected taskId for lineage verification (ERR-008)
52
+ * @returns Validation result with valid flag, errors, and optional error category
53
+ */
54
+ validate(output: unknown, taskId: string): Promise<{
55
+ valid: boolean;
56
+ errors: string[];
57
+ errorCategory?: string;
58
+ }>;
59
+ }
60
+ /**
61
+ * Default validator for DiagDistillerOutputV1 using TypeBox Value.Check / Value.Errors.
62
+ *
63
+ * Validates:
64
+ * 1. Structural correctness via TypeBox schema
65
+ * 2. taskId lineage match (ERR-008)
66
+ * 3. Core principle registry membership — every id in
67
+ * groundedOnCorePrincipleIds must pass isCorePrincipleId().
68
+ * Fabricated IDs (e.g. T-99) produce a validation failure with
69
+ * errorCategory 'output_invalid'.
70
+ *
71
+ * @see PRI-372
72
+ */
73
+ export declare class DefaultDiagDistillerValidator implements DiagDistillerValidator {
74
+ validate(output: unknown, taskId: string): Promise<{
75
+ valid: boolean;
76
+ errors: string[];
77
+ errorCategory?: string;
78
+ }>;
79
+ }
80
+ //# sourceMappingURL=diag-distiller-output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diag-distiller-output.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician/diag-distiller-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAMtD,eAAO,MAAM,wBAAwB,yLAInC,CAAC;AAEH,sDAAsD;AACtD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAIzE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;EAuBtC,CAAC;AAEH,+DAA+D;AAC/D,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAI/E;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;OAMG;IACH,QAAQ,CACN,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1E;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,6BAA8B,YAAW,sBAAsB;IAEpE,QAAQ,CACZ,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAuCzE"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Stage B (Distiller) output schema for the split diagnostician pipeline.
3
+ *
4
+ * The Distiller takes the root-cause artifact from Stage A and produces
5
+ * an abstracted, cross-scenario principle grounded on the T-01..T-10
6
+ * core axiom registry.
7
+ *
8
+ * @see PRI-372 — Split diagnostician into Stage A (Root Cause) + Stage B (Distiller)
9
+ */
10
+ import { Type } from '@sinclair/typebox';
11
+ import { Value } from '@sinclair/typebox/value';
12
+ import { isCorePrincipleId } from '../core-principles/core-principle-registry.js';
13
+ // ── Scope literal ─────────────────────────────────────────────────────────
14
+ export const DiagDistillerScopeSchema = Type.Union([
15
+ Type.Literal('general'),
16
+ Type.Literal('domain'),
17
+ Type.Literal('scenario'),
18
+ ]);
19
+ // ── Distiller Output V1 ──────────────────────────────────────────────────
20
+ /**
21
+ * TypeBox schema for Stage B (Distiller) output.
22
+ *
23
+ * Lineage consistency: `sourceRootCauseArtifactId` must match the artifact
24
+ * produced by Stage A so that the pipeline can trace every distilled
25
+ * principle back to its root-cause diagnosis.
26
+ *
27
+ * `groundedOnCorePrincipleIds` is validated against the T-01..T-10
28
+ * registry at runtime — fabricated IDs cause validation failure.
29
+ *
30
+ * @see PRI-372
31
+ */
32
+ export const DiagDistillerOutputV1Schema = Type.Object({
33
+ valid: Type.Boolean(),
34
+ taskId: Type.String({ minLength: 1 }),
35
+ sourceRootCauseArtifactId: Type.String({
36
+ minLength: 1,
37
+ description: 'Lineage consistency check — must match the artifact ID from Stage A',
38
+ }),
39
+ abstractedPrinciple: Type.String({
40
+ minLength: 1,
41
+ maxLength: 200,
42
+ description: 'Highly abstracted, cross-scenario principle (≤200 chars)',
43
+ }),
44
+ rationale: Type.String({
45
+ minLength: 1,
46
+ description: 'Why this principle addresses the root cause',
47
+ }),
48
+ groundedOnCorePrincipleIds: Type.Array(Type.String({ minLength: 1 }), {
49
+ description: 'Subset of T-01..T-10. Validated against registry — fabricated IDs cause validation failure.',
50
+ }),
51
+ scope: DiagDistillerScopeSchema,
52
+ confidence: Type.Number({ minimum: 0, maximum: 1 }),
53
+ ambiguityNotes: Type.Optional(Type.Array(Type.String())),
54
+ });
55
+ /**
56
+ * Default validator for DiagDistillerOutputV1 using TypeBox Value.Check / Value.Errors.
57
+ *
58
+ * Validates:
59
+ * 1. Structural correctness via TypeBox schema
60
+ * 2. taskId lineage match (ERR-008)
61
+ * 3. Core principle registry membership — every id in
62
+ * groundedOnCorePrincipleIds must pass isCorePrincipleId().
63
+ * Fabricated IDs (e.g. T-99) produce a validation failure with
64
+ * errorCategory 'output_invalid'.
65
+ *
66
+ * @see PRI-372
67
+ */
68
+ export class DefaultDiagDistillerValidator {
69
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
70
+ async validate(output, taskId) {
71
+ const errors = [];
72
+ // ── Step 1: Object guard ────────────────────────────────────────────────
73
+ if (typeof output !== 'object' || output === null) {
74
+ return { valid: false, errors: ['Output is not an object'], errorCategory: 'output_invalid' };
75
+ }
76
+ // Narrow to Record for property access — all fields still treated as untrusted.
77
+ const record = output;
78
+ // ── Step 2: taskId lineage check (ERR-008) ──────────────────────────────
79
+ if (typeof record.taskId !== 'string' || record.taskId !== taskId) {
80
+ errors.push(`taskId mismatch: expected ${taskId}, got ${String(record.taskId)}`);
81
+ }
82
+ // ── Step 3: TypeBox schema validation ───────────────────────────────────
83
+ if (!Value.Check(DiagDistillerOutputV1Schema, output)) {
84
+ const schemaErrors = [...Value.Errors(DiagDistillerOutputV1Schema, output)];
85
+ const messages = schemaErrors.map((e) => `${e.path}: ${e.message}`);
86
+ errors.push(...messages);
87
+ }
88
+ // ── Step 4: Core principle registry validation ──────────────────────────
89
+ // This constraint cannot be expressed in a TypeBox schema alone.
90
+ if (Array.isArray(record.groundedOnCorePrincipleIds)) {
91
+ for (const id of record.groundedOnCorePrincipleIds) {
92
+ if (typeof id === 'string' && !isCorePrincipleId(id)) {
93
+ errors.push(`Fabricated axiom ID ${id} not in core principle registry`);
94
+ }
95
+ }
96
+ }
97
+ if (errors.length > 0) {
98
+ return { valid: false, errors, errorCategory: 'output_invalid' };
99
+ }
100
+ return { valid: true, errors: [] };
101
+ }
102
+ }
103
+ //# sourceMappingURL=diag-distiller-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diag-distiller-output.js","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician/diag-distiller-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAElF,6EAA6E;AAE7E,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC,KAAK,CAAC;IACjD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACtB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;CACzB,CAAC,CAAC;AAKH,4EAA4E;AAE5E;;;;;;;;;;;GAWG;AACH,M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AC;QACnE,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Root Cause stage (Stage A) output schema for the split diagnostician pipeline.
3
+ *
4
+ * This schema defines the output of the Root Cause stage, which identifies
5
+ * the underlying cause of a pain signal using a 5-Whys causal chain and
6
+ * categorises it into one of four root-cause categories.
7
+ *
8
+ * The taskId field is lineage data re-injected by the runner if stripped
9
+ * by the adapter before LLM validation (ERR-008).
10
+ *
11
+ * @see PRI-372
12
+ */
13
+ import { type Static } from '@sinclair/typebox';
14
+ /**
15
+ * Root-cause category literal union.
16
+ *
17
+ * Every root cause MUST be classified into exactly one of these four
18
+ * categories. The category prefix in `rootCause` must match this value.
19
+ *
20
+ * @see PRI-372
21
+ */
22
+ export declare const RootCauseCategorySchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"People">, import("@sinclair/typebox").TLiteral<"Design">, import("@sinclair/typebox").TLiteral<"Assumption">, import("@sinclair/typebox").TLiteral<"Tooling">]>;
23
+ /** Root-cause category: People | Design | Assumption | Tooling */
24
+ export type RootCauseCategory = Static<typeof RootCauseCategorySchema>;
25
+ /**
26
+ * A single entry in the 5-Whys causal chain.
27
+ *
28
+ * `why` is 1-indexed (1 = shallowest, 5 = deepest).
29
+ */
30
+ export declare const CausalChainEntrySchema: import("@sinclair/typebox").TObject<{
31
+ why: import("@sinclair/typebox").TNumber;
32
+ statement: import("@sinclair/typebox").TString;
33
+ evidenceRefs: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
34
+ }>;
35
+ /** A single entry in the 5-Whys causal chain. */
36
+ export type CausalChainEntry = Static<typeof CausalChainEntrySchema>;
37
+ /**
38
+ * Evidence entry linking a source reference to an explanatory note.
39
+ */
40
+ export declare const DiagRootCauseEvidenceSchema: import("@sinclair/typebox").TObject<{
41
+ sourceRef: import("@sinclair/typebox").TString;
42
+ note: import("@sinclair/typebox").TString;
43
+ }>;
44
+ /** Evidence entry linking a source reference to an explanatory note. */
45
+ export type DiagRootCauseEvidence = Static<typeof DiagRootCauseEvidenceSchema>;
46
+ /**
47
+ * TypeBox schema for the Root Cause stage (Stage A) output.
48
+ *
49
+ * Consumed by the next pipeline stage and stored as a RunRecord output.
50
+ * The host layer (runner) is responsible for re-injecting `taskId` if
51
+ * the adapter strips lineage fields before LLM invocation (ERR-008).
52
+ *
53
+ * @see PRI-372
54
+ */
55
+ export declare const DiagRootCauseOutputV1Schema: import("@sinclair/typebox").TObject<{
56
+ valid: import("@sinclair/typebox").TBoolean;
57
+ diagnosisId: import("@sinclair/typebox").TString;
58
+ taskId: import("@sinclair/typebox").TString;
59
+ summary: import("@sinclair/typebox").TString;
60
+ causalChain: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
61
+ why: import("@sinclair/typebox").TNumber;
62
+ statement: import("@sinclair/typebox").TString;
63
+ evidenceRefs: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
64
+ }>>;
65
+ rootCause: import("@sinclair/typebox").TString;
66
+ rootCauseCategory: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"People">, import("@sinclair/typebox").TLiteral<"Design">, import("@sinclair/typebox").TLiteral<"Assumption">, import("@sinclair/typebox").TLiteral<"Tooling">]>;
67
+ evidence: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
68
+ sourceRef: import("@sinclair/typebox").TString;
69
+ note: import("@sinclair/typebox").TString;
70
+ }>>;
71
+ confidence: import("@sinclair/typebox").TNumber;
72
+ ambiguityNotes: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
73
+ }>;
74
+ /** Typed output of the Root Cause stage (Stage A). */
75
+ export type DiagRootCauseOutputV1 = Static<typeof DiagRootCauseOutputV1Schema>;
76
+ /**
77
+ * Validator interface for DiagRootCauseOutputV1.
78
+ *
79
+ * Accepts `unknown` input — implementations must perform runtime checks (ERR-001).
80
+ *
81
+ * @see PRI-372
82
+ */
83
+ export interface DiagRootCauseValidator {
84
+ /**
85
+ * Validate untrusted root-cause stage output.
86
+ *
87
+ * @param output - Raw output to validate (treated as unknown — ERR-001)
88
+ * @param taskId - Expected taskId for lineage verification (ERR-008)
89
+ * @returns Validation result with valid flag, errors, and optional error category
90
+ */
91
+ validate(output: unknown, taskId: string): Promise<{
92
+ valid: boolean;
93
+ errors: string[];
94
+ errorCategory?: string;
95
+ }>;
96
+ }
97
+ /**
98
+ * Default validator for DiagRootCauseOutputV1 using TypeBox Value.Check / Value.Errors.
99
+ *
100
+ * Validates:
101
+ * 1. Structural correctness via TypeBox schema
102
+ * 2. taskId lineage match (ERR-008)
103
+ * 3. rootCauseCategory consistency with rootCause prefix
104
+ * 4. causalChain entry ordering (why field 1-5)
105
+ *
106
+ * @see PRI-372
107
+ */
108
+ export declare class DefaultDiagRootCauseValidator implements DiagRootCauseValidator {
109
+ validate(output: unknown, taskId: string): Promise<{
110
+ valid: boolean;
111
+ errors: string[];
112
+ errorCategory?: string;
113
+ }>;
114
+ }
115
+ //# sourceMappingURL=diag-rootcause-output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diag-rootcause-output.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician/diag-rootcause-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAKtD;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,2OAKlC,CAAC;AAEH,kEAAkE;AAClE,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;;EAIjC,CAAC;AAEH,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAErE;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;EAGtC,CAAC;AAEH,wEAAwE;AACxE,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAI/E;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;EActC,CAAC;AAEH,sDAAsD;AACtD,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAM/E;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClH;AAED;;;;;;;;;;GAUG;AACH,qBAAa,6BAA8B,YAAW,sBAAsB;IAEpE,QAAQ,CACZ,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CA0FzE"}
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Root Cause stage (Stage A) output schema for the split diagnostician pipeline.
3
+ *
4
+ * This schema defines the output of the Root Cause stage, which identifies
5
+ * the underlying cause of a pain signal using a 5-Whys causal chain and
6
+ * categorises it into one of four root-cause categories.
7
+ *
8
+ * The taskId field is lineage data re-injected by the runner if stripped
9
+ * by the adapter before LLM validation (ERR-008).
10
+ *
11
+ * @see PRI-372
12
+ */
13
+ import { Type } from '@sinclair/typebox';
14
+ import { Value } from '@sinclair/typebox/value';
15
+ // ── Sub-schemas ──────────────────────────────────────────────────────────────
16
+ /**
17
+ * Root-cause category literal union.
18
+ *
19
+ * Every root cause MUST be classified into exactly one of these four
20
+ * categories. The category prefix in `rootCause` must match this value.
21
+ *
22
+ * @see PRI-372
23
+ */
24
+ export const RootCauseCategorySchema = Type.Union([
25
+ Type.Literal('People'),
26
+ Type.Literal('Design'),
27
+ Type.Literal('Assumption'),
28
+ Type.Literal('Tooling'),
29
+ ]);
30
+ /**
31
+ * A single entry in the 5-Whys causal chain.
32
+ *
33
+ * `why` is 1-indexed (1 = shallowest, 5 = deepest).
34
+ */
35
+ export const CausalChainEntrySchema = Type.Object({
36
+ why: Type.Number({ minimum: 1, maximum: 5 }),
37
+ statement: Type.String({ minLength: 1 }),
38
+ evidenceRefs: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
39
+ });
40
+ /**
41
+ * Evidence entry linking a source reference to an explanatory note.
42
+ */
43
+ export const DiagRootCauseEvidenceSchema = Type.Object({
44
+ sourceRef: Type.String({ minLength: 1 }),
45
+ note: Type.String({ minLength: 1 }),
46
+ });
47
+ // ── Main output schema ───────────────────────────────────────────────────────
48
+ /**
49
+ * TypeBox schema for the Root Cause stage (Stage A) output.
50
+ *
51
+ * Consumed by the next pipeline stage and stored as a RunRecord output.
52
+ * The host layer (runner) is responsible for re-injecting `taskId` if
53
+ * the adapter strips lineage fields before LLM invocation (ERR-008).
54
+ *
55
+ * @see PRI-372
56
+ */
57
+ export const DiagRootCauseOutputV1Schema = Type.Object({
58
+ valid: Type.Boolean(),
59
+ diagnosisId: Type.String({ minLength: 1 }),
60
+ taskId: Type.String({ minLength: 1, description: 'Lineage — re-injected if stripped; ERR-008' }),
61
+ summary: Type.String({ minLength: 1 }),
62
+ causalChain: Type.Array(CausalChainEntrySchema),
63
+ rootCause: Type.String({
64
+ minLength: 1,
65
+ description: 'MUST include category prefix: "People: ..." or "Design: ..." or "Assumption: ..." or "Tooling: ..."',
66
+ }),
67
+ rootCauseCategory: RootCauseCategorySchema,
68
+ evidence: Type.Array(DiagRootCauseEvidenceSchema),
69
+ confidence: Type.Number({ minimum: 0, maximum: 1 }),
70
+ ambiguityNotes: Type.Optional(Type.Array(Type.String())),
71
+ });
72
+ // ── Validator ────────────────────────────────────────────────────────────────
73
+ const VALID_ROOT_CAUSE_CATEGORIES = new Set(['People', 'Design', 'Assumption', 'Tooling']);
74
+ /**
75
+ * Default validator for DiagRootCauseOutputV1 using TypeBox Value.Check / Value.Errors.
76
+ *
77
+ * Validates:
78
+ * 1. Structural correctness via TypeBox schema
79
+ * 2. taskId lineage match (ERR-008)
80
+ * 3. rootCauseCategory consistency with rootCause prefix
81
+ * 4. causalChain entry ordering (why field 1-5)
82
+ *
83
+ * @see PRI-372
84
+ */
85
+ export class DefaultDiagRootCauseValidator {
86
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
87
+ async validate(output, taskId) {
88
+ const errors = [];
89
+ // ── Step 1: Object guard ────────────────────────────────────────────────
90
+ if (typeof output !== 'object' || output === null) {
91
+ return { valid: false, errors: ['Output is not an object'], errorCategory: 'output_invalid' };
92
+ }
93
+ // Narrow to Record for property access — all fields still treated as untrusted.
94
+ const record = output;
95
+ // ── Step 2: taskId lineage check (ERR-008) ──────────────────────────────
96
+ if (typeof record.taskId !== 'string' || record.taskId !== taskId) {
97
+ errors.push(`taskId mismatch: expected ${taskId}, got ${String(record.taskId)}`);
98
+ }
99
+ // ── Step 3: valid flag must be true ─────────────────────────────────────
100
+ if (record.valid !== true) {
101
+ errors.push('output.valid must be true');
102
+ }
103
+ // ── Step 4: rootCauseCategory semantic check ────────────────────────────
104
+ if (typeof record.rootCauseCategory !== 'string' || !VALID_ROOT_CAUSE_CATEGORIES.has(record.rootCauseCategory)) {
105
+ errors.push(`rootCauseCategory must be one of People|Design|Assumption|Tooling, got ${String(record.rootCauseCategory)}`);
106
+ }
107
+ // ── Step 4b: rootCause prefix must match rootCauseCategory ──────────────
108
+ if (typeof record.rootCause === 'string'
109
+ && typeof record.rootCauseCategory === 'string'
110
+ && VALID_ROOT_CAUSE_CATEGORIES.has(record.rootCauseCategory)) {
111
+ const expectedPrefix = `${record.rootCauseCategory}: `;
112
+ if (!record.rootCause.startsWith(expectedPrefix)) {
113
+ errors.push(`rootCause must start with "${expectedPrefix}" (matching rootCauseCategory "${record.rootCauseCategory}"), got: "${record.rootCause.slice(0, 40)}${record.rootCause.length > 40 ? '...' : ''}"`);
114
+ }
115
+ }
116
+ // ── Step 5: causalChain entry-level checks ──────────────────────────────
117
+ if (Array.isArray(record.causalChain)) {
118
+ for (let i = 0; i < record.causalChain.length; i++) {
119
+ const entry = record.causalChain[i];
120
+ if (!entry || typeof entry !== 'object') {
121
+ errors.push(`causalChain[${i}] must be an object`);
122
+ continue;
123
+ }
124
+ if (typeof entry.why !== 'number' || entry.why < 1 || entry.why > 5) {
125
+ errors.push(`causalChain[${i}].why must be a number in [1, 5]`);
126
+ }
127
+ if (typeof entry.statement !== 'string' || entry.statement.trim() === '') {
128
+ errors.push(`causalChain[${i}].statement must be a non-empty string`);
129
+ }
130
+ if (!Array.isArray(entry.evidenceRefs)) {
131
+ errors.push(`causalChain[${i}].evidenceRefs must be an array`);
132
+ }
133
+ else if (entry.evidenceRefs.length === 0) {
134
+ errors.push(`causalChain[${i}].evidenceRefs must have at least 1 item`);
135
+ }
136
+ }
137
+ }
138
+ // ── Step 6: evidence entry-level checks ─────────────────────────────────
139
+ if (Array.isArray(record.evidence)) {
140
+ for (let i = 0; i < record.evidence.length; i++) {
141
+ const ev = record.evidence[i];
142
+ if (!ev || typeof ev !== 'object') {
143
+ errors.push(`evidence[${i}] must be an object`);
144
+ continue;
145
+ }
146
+ if (typeof ev.sourceRef !== 'string' || ev.sourceRef.trim() === '') {
147
+ errors.push(`evidence[${i}].sourceRef must be a non-empty string`);
148
+ }
149
+ if (typeof ev.note !== 'string' || ev.note.trim() === '') {
150
+ errors.push(`evidence[${i}].note must be a non-empty string`);
151
+ }
152
+ }
153
+ }
154
+ // ── Step 7: TypeBox schema validation as fallback ───────────────────────
155
+ if (!Value.Check(DiagRootCauseOutputV1Schema, output)) {
156
+ const schemaErrors = [...Value.Errors(DiagRootCauseOutputV1Schema, output)];
157
+ const messages = schemaErrors.map((e) => `${e.path}: ${e.message}`);
158
+ errors.push(...messages);
159
+ }
160
+ if (errors.length > 0) {
161
+ return { valid: false, errors, errorCategory: 'output_invalid' };
162
+ }
163
+ return { valid: true, errors: [] };
164
+ }
165
+ }
166
+ //# sourceMappingURL=diag-rootcause-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diag-rootcause-output.js","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician/diag-rootcause-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,KAAK,CAAC;IAChD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACtB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACtB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;IAC1B,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;CACxB,CAAC,CAAC;AAKH;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAC;IAChD,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IAC5C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACxC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;CACzE,CAAC,CAAC;AAKH;;GAEG;AACH,MAAM,CAAC,MA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EAAE,CAAC;YACtD,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC,CAAC;YAC5E,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACpE,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC;QACnE,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * DistillerPromptBuilder — Stage B prompt builder for the split diagnostician pipeline.
3
+ *
4
+ * Constructs the prompt for the Distiller stage (Stage B). It receives the
5
+ * Stage A root cause artifact as input and produces an abstracted principle
6
+ * grounded on core axioms (T-01..T-10).
7
+ *
8
+ * ## Prompt Sections
9
+ *
10
+ * 1. Role — principle distiller identity
11
+ * 2. Input — Stage A root cause output (structured data)
12
+ * 3. Core Axioms — T-01..T-10 list (when coreGrounding=true)
13
+ * 4. Output Requirements — DiagDistillerOutputV1Schema
14
+ * 5. Quality Guard — abstract vs rule-like distinction
15
+ *
16
+ * @see PRI-372
17
+ */
18
+ import type { TSchema } from '@sinclair/typebox';
19
+ import type { SchemaPromptAdapter } from '../adapter/schema-prompt-adapter.js';
20
+ import type { DiagRootCauseOutputV1 } from './diag-rootcause-output.js';
21
+ import type { OutputLanguage } from '../language-directive.js';
22
+ import type { BuildPromptOptions } from '../diagnostician-prompt-builder.js';
23
+ /**
24
+ * Options for DistillerPromptBuilder constructor and buildDistillerInstruction.
25
+ *
26
+ * Uses an opts-object pattern to satisfy @typescript-eslint/max-params.
27
+ *
28
+ * @see PRI-372
29
+ */
30
+ export interface DistillerPromptBuilderOptions {
31
+ /** Schema prompt adapter (default: DefaultSchemaPromptAdapter) */
32
+ adapter?: SchemaPromptAdapter;
33
+ /** TypeBox schema for output validation (default: DiagDistillerOutputV1Schema) */
34
+ schema?: TSchema;
35
+ /** Output language directive (default: none) */
36
+ outputLanguage?: OutputLanguage;
37
+ /** Inject core axiom grounding section (default: false) */
38
+ coreGrounding?: boolean;
39
+ }
40
+ /**
41
+ * Input context for the Distiller stage (Stage B).
42
+ *
43
+ * Contains the Stage A root cause artifact ID and output, plus an optional
44
+ * coreGrounding flag that overrides the builder-level default.
45
+ *
46
+ * @see PRI-372
47
+ */
48
+ export interface DistillerContextInput {
49
+ /** Artifact ID of the Stage A root cause output — used for lineage tracing */
50
+ rootCauseArtifactId: string;
51
+ /** Stage A root cause output — the structured data to abstract from */
52
+ rootCauseOutput: DiagRootCauseOutputV1;
53
+ /** Override builder-level coreGrounding for this specific invocation */
54
+ coreGrounding?: boolean;
55
+ }
56
+ /**
57
+ * PromptInput for the Distiller stage (Stage B).
58
+ *
59
+ * Unlike Stage A (which uses the full DiagnosticianContextPayload),
60
+ * Stage B receives only the Stage A root cause artifact and the
61
+ * distiller instruction.
62
+ *
63
+ * @see PRI-372
64
+ */
65
+ export interface DistillerPromptInput {
66
+ /** Artifact ID of the Stage A root cause output — for lineage tracing */
67
+ rootCauseArtifactId: string;
68
+ /** Stage A root cause output — the structured data to abstract from */
69
+ rootCauseOutput: DiagRootCauseOutputV1;
70
+ /** Distiller protocol instruction for the LLM */
71
+ distillerInstruction: string;
72
+ }
73
+ /**
74
+ * Build result for the Distiller stage (Stage B).
75
+ *
76
+ * Follows the same contract as PromptBuildResult but with a
77
+ * DistillerPromptInput shape specific to Stage B.
78
+ *
79
+ * @see PRI-372
80
+ */
81
+ export interface DistillerPromptBuildResult {
82
+ /** JSON string — the exact value to pass as openclaw agent --message argument */
83
+ readonly message: string;
84
+ /** The DistillerPromptInput object that was serialized to JSON */
85
+ readonly promptInput: DistillerPromptInput;
86
+ }
87
+ /**
88
+ * Build the Stage B distiller protocol instruction.
89
+ *
90
+ * When `coreGrounding` is true, the Core Axioms section is included with
91
+ * the full T-01..T-10 list and a strict instruction prohibiting fabricated
92
+ * axiom IDs. When false or undefined, the section is omitted.
93
+ *
94
+ * @see PRI-372
95
+ */
96
+ export declare function buildDistillerProtocolInstruction(opts?: DistillerPromptBuilderOptions): string;
97
+ /**
98
+ * DistillerPromptBuilder — Stage B prompt builder for the split diagnostician pipeline.
99
+ *
100
+ * Receives the Stage A root cause artifact as input and produces an abstracted
101
+ * principle grounded on core axioms (T-01..T-10).
102
+ *
103
+ * Uses an opts-object pattern for all methods to satisfy @typescript-eslint/max-params.
104
+ *
105
+ * @see PRI-372
106
+ */
107
+ export declare class DistillerPromptBuilder {
108
+ private readonly adapter;
109
+ private readonly schema;
110
+ constructor(opts?: DistillerPromptBuilderOptions);
111
+ /**
112
+ * Build the Stage B distiller protocol instruction.
113
+ *
114
+ * Contains the role definition, input description, core axioms section
115
+ * (when coreGrounding=true), output requirements, and quality guard.
116
+ *
117
+ * @see PRI-372
118
+ */
119
+ buildDistillerInstruction(opts?: DistillerPromptBuilderOptions): string;
120
+ /**
121
+ * Build the full prompt for Stage B.
122
+ *
123
+ * Constructs a DistillerPromptBuildResult containing the JSON message to pass
124
+ * as the --message argument to the LLM agent. The message includes the
125
+ * distiller instruction and the Stage A root cause context.
126
+ *
127
+ * Per DPB-02: Output is ONLY JSON — no markdown, no file ops, no tool calls.
128
+ * Per DPB-05: This method only builds the prompt; it does NOT commit to PD database.
129
+ *
130
+ * @see PRI-372
131
+ */
132
+ buildPrompt(context: DistillerContextInput, opts?: BuildPromptOptions): DistillerPromptBuildResult;
133
+ }
134
+ //# sourceMappingURL=distiller-prompt-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distiller-prompt-builder.d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