@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.
- package/dist/runtime-v2/__tests__/architecture-regression.test.js +37 -73
- package/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js +4 -0
- package/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js.map +1 -1
- package/dist/runtime-v2/config/pd-config-types.d.ts +2 -0
- package/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
- package/dist/runtime-v2/config/pd-config-types.js.map +1 -1
- package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.d.ts +2 -0
- package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.js +45 -0
- package/dist/runtime-v2/diagnostician/__tests__/diag-distiller-output.test.js.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.d.ts +2 -0
- package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js +57 -0
- package/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.d.ts +2 -0
- package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.js +39 -0
- package/dist/runtime-v2/diagnostician/__tests__/distiller-prompt-builder.test.js.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.d.ts +2 -0
- package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js +34 -0
- package/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.d.ts +2 -0
- package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.js +57 -0
- package/dist/runtime-v2/diagnostician/__tests__/router-prompt-builder.test.js.map +1 -0
- package/dist/runtime-v2/diagnostician/diag-distiller-output.d.ts +80 -0
- package/dist/runtime-v2/diagnostician/diag-distiller-output.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/diag-distiller-output.js +103 -0
- package/dist/runtime-v2/diagnostician/diag-distiller-output.js.map +1 -0
- package/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts +115 -0
- package/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/diag-rootcause-output.js +166 -0
- package/dist/runtime-v2/diagnostician/diag-rootcause-output.js.map +1 -0
- package/dist/runtime-v2/diagnostician/distiller-prompt-builder.d.ts +134 -0
- package/dist/runtime-v2/diagnostician/distiller-prompt-builder.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/distiller-prompt-builder.js +156 -0
- package/dist/runtime-v2/diagnostician/distiller-prompt-builder.js.map +1 -0
- package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts +96 -0
- package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js +216 -0
- package/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js.map +1 -0
- package/dist/runtime-v2/diagnostician/router-prompt-builder.d.ts +127 -0
- package/dist/runtime-v2/diagnostician/router-prompt-builder.d.ts.map +1 -0
- package/dist/runtime-v2/diagnostician/router-prompt-builder.js +131 -0
- package/dist/runtime-v2/diagnostician/router-prompt-builder.js.map +1 -0
- package/dist/runtime-v2/index.d.ts +6 -3
- package/dist/runtime-v2/index.d.ts.map +1 -1
- package/dist/runtime-v2/index.js +1 -1
- package/dist/runtime-v2/index.js.map +1 -1
- package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.d.ts +25 -0
- package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.js +123 -0
- package/dist/runtime-v2/internalization/__tests__/__fixtures__/split-pipeline-mock-outputs.js.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.d.ts +2 -0
- package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js +731 -0
- package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.d.ts +2 -0
- package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.js +437 -0
- package/dist/runtime-v2/internalization/__tests__/diag-distiller-runner.test.js.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.d.ts +2 -0
- package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.js +336 -0
- package/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.js.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.d.ts +2 -0
- package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.js +437 -0
- package/dist/runtime-v2/internalization/__tests__/diag-router-runner.test.js.map +1 -0
- package/dist/runtime-v2/internalization/diag-distiller-runner.d.ts +83 -0
- package/dist/runtime-v2/internalization/diag-distiller-runner.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/diag-distiller-runner.js +274 -0
- package/dist/runtime-v2/internalization/diag-distiller-runner.js.map +1 -0
- package/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts +73 -0
- package/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/diag-rootcause-runner.js +229 -0
- package/dist/runtime-v2/internalization/diag-rootcause-runner.js.map +1 -0
- package/dist/runtime-v2/internalization/diag-router-runner.d.ts +85 -0
- package/dist/runtime-v2/internalization/diag-router-runner.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/diag-router-runner.js +353 -0
- package/dist/runtime-v2/internalization/diag-router-runner.js.map +1 -0
- package/dist/runtime-v2/internalization/evaluator-runner.d.ts +1 -1
- package/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
- package/dist/runtime-v2/internalization/evaluator-runner.js +1 -1
- package/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
- package/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts +66 -0
- package/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts.map +1 -0
- package/dist/runtime-v2/internalization/split-diagnostician-runner.js +172 -0
- package/dist/runtime-v2/internalization/split-diagnostician-runner.js.map +1 -0
- package/dist/runtime-v2/pain-signal-bridge.d.ts +22 -3
- package/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
- package/dist/runtime-v2/pain-signal-bridge.js +16 -7
- package/dist/runtime-v2/pain-signal-bridge.js.map +1 -1
- package/dist/runtime-v2/pain-signal-runtime-factory.d.ts +3 -0
- package/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
- package/dist/runtime-v2/pain-signal-runtime-factory.js +52 -24
- package/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
- package/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js +2 -2
- package/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js.map +1 -1
- package/dist/runtime-v2/runner/base-peer-runner.d.ts +3 -3
- package/dist/runtime-v2/runner/base-peer-runner.d.ts.map +1 -1
- package/dist/runtime-v2/runner/base-peer-runner.js +6 -6
- package/dist/runtime-v2/runner/base-peer-runner.js.map +1 -1
- package/dist/runtime-v2/runner/peer-runner-types.d.ts +3 -3
- package/dist/runtime-v2/runner/peer-runner-types.d.ts.map +1 -1
- package/dist/runtime-v2/store/candidate/sqlite-candidate-store.js +2 -2
- package/dist/runtime-v2/store/candidate/sqlite-candidate-store.js.map +1 -1
- package/dist/runtime-v2/types/principle-enums.d.ts +2 -2
- package/dist/runtime-v2/types/principle-enums.d.ts.map +1 -1
- package/dist/runtime-v2/types/principle-enums.js +1 -0
- package/dist/runtime-v2/types/principle-enums.js.map +1 -1
- package/dist/runtime-v2/types/principle-schema.d.ts +1 -1
- package/dist/runtime-v2/types/principle-tree-store.d.ts +1 -1
- package/dist/telemetry-event.d.ts +2 -2
- package/dist/telemetry-event.d.ts.map +1 -1
- package/dist/telemetry-event.js +1 -0
- package/dist/telemetry-event.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
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 { DefaultSchemaPromptAdapter } from '../adapter/schema-prompt-adapter.js';
|
|
19
|
+
import { DiagDistillerOutputV1Schema } from './diag-distiller-output.js';
|
|
20
|
+
import { CORE_PRINCIPLES } from '../core-principles/core-principle-registry.js';
|
|
21
|
+
import { buildLanguageDirective } from '../language-directive.js';
|
|
22
|
+
// ── Instruction builder ──────────────────────────────────────────────────────
|
|
23
|
+
/**
|
|
24
|
+
* Build the Stage B distiller protocol instruction.
|
|
25
|
+
*
|
|
26
|
+
* When `coreGrounding` is true, the Core Axioms section is included with
|
|
27
|
+
* the full T-01..T-10 list and a strict instruction prohibiting fabricated
|
|
28
|
+
* axiom IDs. When false or undefined, the section is omitted.
|
|
29
|
+
*
|
|
30
|
+
* @see PRI-372
|
|
31
|
+
*/
|
|
32
|
+
export function buildDistillerProtocolInstruction(opts = {}) {
|
|
33
|
+
const adapter = opts.adapter ?? new DefaultSchemaPromptAdapter();
|
|
34
|
+
const schema = opts.schema ?? DiagDistillerOutputV1Schema;
|
|
35
|
+
const { outputLanguage, coreGrounding } = opts;
|
|
36
|
+
const example = adapter.generateExample(schema);
|
|
37
|
+
const constraints = adapter.generateConstraints(schema);
|
|
38
|
+
const languageDirective = buildLanguageDirective(outputLanguage);
|
|
39
|
+
// Core Axioms section — only when coreGrounding is true
|
|
40
|
+
const coreAxiomsBlock = coreGrounding
|
|
41
|
+
? `
|
|
42
|
+
CORE AXIOMS:
|
|
43
|
+
The following core axioms are the system's foundational behavioral principles.
|
|
44
|
+
You MUST only reference axiom IDs from this list. Fabricating IDs not in this
|
|
45
|
+
list will cause validation failure.
|
|
46
|
+
|
|
47
|
+
${CORE_PRINCIPLES.map(p => `${p.id}: ${p.statement}`).join('\n')}
|
|
48
|
+
|
|
49
|
+
`
|
|
50
|
+
: '';
|
|
51
|
+
return `You are a principle distiller. Your job is to abstract a specific root cause into a general, cross-scenario principle.
|
|
52
|
+
|
|
53
|
+
INPUT:
|
|
54
|
+
You will receive the Stage A root cause output as structured data. This contains:
|
|
55
|
+
- summary: a concise description of the diagnosis
|
|
56
|
+
- causalChain: the 5-Whys causal chain
|
|
57
|
+
- rootCause: the classified root cause with category prefix
|
|
58
|
+
- rootCauseCategory: People | Design | Assumption | Tooling
|
|
59
|
+
- evidence: supporting evidence entries
|
|
60
|
+
- confidence: the Stage A confidence score
|
|
61
|
+
${coreAxiomsBlock}OUTPUT REQUIREMENTS:
|
|
62
|
+
Your output MUST match the following JSON schema exactly.
|
|
63
|
+
|
|
64
|
+
COMPLETE EXAMPLE OUTPUT (follow this exact structure):
|
|
65
|
+
${example}
|
|
66
|
+
|
|
67
|
+
Key fields:
|
|
68
|
+
- abstractedPrinciple: ≤200 chars, abstract, cross-scenario principle that grows from the root cause
|
|
69
|
+
- groundedOnCorePrincipleIds: subset of the provided axiom IDs above (empty array if none apply)
|
|
70
|
+
- sourceRootCauseArtifactId: MUST match the provided artifact ID exactly
|
|
71
|
+
- scope: 'general' | 'domain' | 'scenario'
|
|
72
|
+
- rationale: why this principle addresses the root cause
|
|
73
|
+
- confidence: 0-1 scale
|
|
74
|
+
|
|
75
|
+
QUALITY GUARD:
|
|
76
|
+
Your principle must be ABSTRACT, not rule-like. Avoid concrete trigger patterns,
|
|
77
|
+
specific tools, or implementation details. A principle is directional wisdom;
|
|
78
|
+
a rule is a boundary condition.
|
|
79
|
+
|
|
80
|
+
Examples:
|
|
81
|
+
- GOOD (abstract principle): "Prefer understanding the existing structure before modifying it"
|
|
82
|
+
- BAD (rule-like): "Always run grep before editing files" or "Never use as casts"
|
|
83
|
+
- GOOD (intent over technique): "Explicitly stated user constraints take precedence over inferred optimal paths"
|
|
84
|
+
- BAD (technique-specific): "Do not create project files in /tmp directory"
|
|
85
|
+
|
|
86
|
+
CONSTRAINTS:
|
|
87
|
+
- Output ONLY valid JSON — no markdown, no explanatory text, no code fences, no prose before or after
|
|
88
|
+
- Do NOT read files, call tools, or write to any database
|
|
89
|
+
- abstractedPrinciple MUST be ≤200 characters
|
|
90
|
+
- groundedOnCorePrincipleIds MUST only contain IDs from the provided axiom list${coreGrounding ? ' above' : ''}; fabricated IDs cause validation failure
|
|
91
|
+
- sourceRootCauseArtifactId MUST match the provided artifact ID
|
|
92
|
+
${constraints}${languageDirective}`;
|
|
93
|
+
}
|
|
94
|
+
// ── Prompt builder class ─────────────────────────────────────────────────────
|
|
95
|
+
/**
|
|
96
|
+
* DistillerPromptBuilder — Stage B prompt builder for the split diagnostician pipeline.
|
|
97
|
+
*
|
|
98
|
+
* Receives the Stage A root cause artifact as input and produces an abstracted
|
|
99
|
+
* principle grounded on core axioms (T-01..T-10).
|
|
100
|
+
*
|
|
101
|
+
* Uses an opts-object pattern for all methods to satisfy @typescript-eslint/max-params.
|
|
102
|
+
*
|
|
103
|
+
* @see PRI-372
|
|
104
|
+
*/
|
|
105
|
+
export class DistillerPromptBuilder {
|
|
106
|
+
adapter;
|
|
107
|
+
schema;
|
|
108
|
+
constructor(opts = {}) {
|
|
109
|
+
this.adapter = opts.adapter ?? new DefaultSchemaPromptAdapter();
|
|
110
|
+
this.schema = opts.schema ?? DiagDistillerOutputV1Schema;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Build the Stage B distiller protocol instruction.
|
|
114
|
+
*
|
|
115
|
+
* Contains the role definition, input description, core axioms section
|
|
116
|
+
* (when coreGrounding=true), output requirements, and quality guard.
|
|
117
|
+
*
|
|
118
|
+
* @see PRI-372
|
|
119
|
+
*/
|
|
120
|
+
buildDistillerInstruction(opts = {}) {
|
|
121
|
+
return buildDistillerProtocolInstruction({
|
|
122
|
+
adapter: opts.adapter ?? this.adapter,
|
|
123
|
+
schema: opts.schema ?? this.schema,
|
|
124
|
+
outputLanguage: opts.outputLanguage,
|
|
125
|
+
coreGrounding: opts.coreGrounding,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build the full prompt for Stage B.
|
|
130
|
+
*
|
|
131
|
+
* Constructs a DistillerPromptBuildResult containing the JSON message to pass
|
|
132
|
+
* as the --message argument to the LLM agent. The message includes the
|
|
133
|
+
* distiller instruction and the Stage A root cause context.
|
|
134
|
+
*
|
|
135
|
+
* Per DPB-02: Output is ONLY JSON — no markdown, no file ops, no tool calls.
|
|
136
|
+
* Per DPB-05: This method only builds the prompt; it does NOT commit to PD database.
|
|
137
|
+
*
|
|
138
|
+
* @see PRI-372
|
|
139
|
+
*/
|
|
140
|
+
buildPrompt(context, opts = {}) {
|
|
141
|
+
const { outputLanguage } = opts;
|
|
142
|
+
const coreGrounding = context.coreGrounding ?? opts.coreGrounding;
|
|
143
|
+
const distillerInstruction = this.buildDistillerInstruction({
|
|
144
|
+
outputLanguage,
|
|
145
|
+
coreGrounding,
|
|
146
|
+
});
|
|
147
|
+
const promptInput = {
|
|
148
|
+
rootCauseArtifactId: context.rootCauseArtifactId,
|
|
149
|
+
rootCauseOutput: context.rootCauseOutput,
|
|
150
|
+
distillerInstruction,
|
|
151
|
+
};
|
|
152
|
+
const message = JSON.stringify(promptInput);
|
|
153
|
+
return { message, promptInput };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=distiller-prompt-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distiller-prompt-builder.js","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician/distiller-prompt-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAEhF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AA6ElE,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,MAAM,UAAU,iCAAiC,CAC/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AO,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;YACrC,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;YAClC,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;OAWG;IACH,WAAW,CACT,OAA8B,EAC9B,OAA2B,EAAE;QAE7B,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QAChC,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC;QAElE,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CAAC;YAC1D,cAAc;YACd,aAAa;SACd,CAAC,CAAC;QAEH,MAAM,WAAW,GAAyB;YACxC,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;YAChD,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,oBAAoB;SACrB,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAE5C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RootCausePromptBuilder — Stage A prompt builder for the split diagnostician pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Constructs the prompt for the Root Cause stage (Stage A), 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
|
+
* ## Phases
|
|
9
|
+
*
|
|
10
|
+
* - PHASE 1 — Evidence Review
|
|
11
|
+
* - PHASE 2 — Causal Chain (5 Whys)
|
|
12
|
+
* - PHASE 3 — Root Cause Classification
|
|
13
|
+
* - PHASE 3.5 — Core Axiom Grounding (when coreGrounding=true, PRI-371)
|
|
14
|
+
*
|
|
15
|
+
* ## Output
|
|
16
|
+
*
|
|
17
|
+
* The prompt requires output matching DiagRootCauseOutputV1Schema.
|
|
18
|
+
*
|
|
19
|
+
* @see PRI-372
|
|
20
|
+
*/
|
|
21
|
+
import type { TSchema } from '@sinclair/typebox';
|
|
22
|
+
import type { SchemaPromptAdapter } from '../adapter/schema-prompt-adapter.js';
|
|
23
|
+
import type { DiagnosticianContextPayload } from '../context-payload.js';
|
|
24
|
+
import type { OutputLanguage } from '../language-directive.js';
|
|
25
|
+
import type { BuildPromptOptions, PromptBuildResult } from '../diagnostician-prompt-builder.js';
|
|
26
|
+
/**
|
|
27
|
+
* Options for RootCausePromptBuilder constructor and buildRootCauseInstruction.
|
|
28
|
+
*
|
|
29
|
+
* Uses an opts-object pattern to satisfy @typescript-eslint/max-params.
|
|
30
|
+
*
|
|
31
|
+
* @see PRI-372
|
|
32
|
+
*/
|
|
33
|
+
export interface RootCausePromptBuilderOptions {
|
|
34
|
+
/** Schema prompt adapter (default: DefaultSchemaPromptAdapter) */
|
|
35
|
+
adapter?: SchemaPromptAdapter;
|
|
36
|
+
/** TypeBox schema for output validation (default: DiagRootCauseOutputV1Schema) */
|
|
37
|
+
schema?: TSchema;
|
|
38
|
+
/** Output language directive (default: none) */
|
|
39
|
+
outputLanguage?: OutputLanguage;
|
|
40
|
+
/** T-E (PRI-371): Inject core axiom grounding as PHASE 3.5 (default: false) */
|
|
41
|
+
coreGrounding?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build the Stage A diagnostic protocol instruction (PHASE 1–3 + optional PHASE 3.5).
|
|
45
|
+
*
|
|
46
|
+
* Per DPB-02 (LOCKED): Output is ONLY JSON — no markdown, no file ops, no tool calls.
|
|
47
|
+
* Per DPB-04: LLM can only analyse the context provided in the prompt; it must NOT
|
|
48
|
+
* read files, call tools, or write to databases.
|
|
49
|
+
*
|
|
50
|
+
* When `coreGrounding` is true, PHASE 3.5 (Core Axiom Grounding) is inserted
|
|
51
|
+
* between PHASE 3 and the final output instruction. When false or undefined,
|
|
52
|
+
* a newline is inserted to preserve byte-identical output (EP-03: no silent fallback).
|
|
53
|
+
*
|
|
54
|
+
* @see PRI-372
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildRootCauseProtocolInstruction(opts?: RootCausePromptBuilderOptions): string;
|
|
57
|
+
/**
|
|
58
|
+
* RootCausePromptBuilder — Stage A prompt builder for the split diagnostician pipeline.
|
|
59
|
+
*
|
|
60
|
+
* Transforms DiagnosticianContextPayload into a PromptBuildResult for the
|
|
61
|
+
* Root Cause stage (Stage A). The output prompt requires the LLM to produce
|
|
62
|
+
* JSON matching DiagRootCauseOutputV1Schema.
|
|
63
|
+
*
|
|
64
|
+
* Uses an opts-object pattern for all methods to satisfy @typescript-eslint/max-params.
|
|
65
|
+
*
|
|
66
|
+
* @see PRI-372
|
|
67
|
+
*/
|
|
68
|
+
export declare class RootCausePromptBuilder {
|
|
69
|
+
private readonly adapter;
|
|
70
|
+
private readonly schema;
|
|
71
|
+
constructor(opts?: RootCausePromptBuilderOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Build the Stage A diagnostic protocol instruction.
|
|
74
|
+
*
|
|
75
|
+
* Contains PHASE 1 (evidence review), PHASE 2 (causal chain / 5-Whys),
|
|
76
|
+
* PHASE 3 (root cause classification), and optional PHASE 3.5 (core axiom
|
|
77
|
+
* grounding when coreGrounding=true).
|
|
78
|
+
*
|
|
79
|
+
* @see PRI-372
|
|
80
|
+
*/
|
|
81
|
+
buildRootCauseInstruction(opts?: RootCausePromptBuilderOptions): string;
|
|
82
|
+
/**
|
|
83
|
+
* Build the full prompt for Stage A.
|
|
84
|
+
*
|
|
85
|
+
* Transforms DiagnosticianContextPayload into a PromptBuildResult containing
|
|
86
|
+
* the JSON message to pass as the --message argument to the LLM agent.
|
|
87
|
+
*
|
|
88
|
+
* Per DPB-02: Output is ONLY JSON — no markdown, no file ops, no tool calls.
|
|
89
|
+
* Per DPB-05: This method only builds the prompt; it does NOT commit to PD database.
|
|
90
|
+
* Per DPB-07: NO extraSystemPrompt is added — agent profile is the source of truth.
|
|
91
|
+
*
|
|
92
|
+
* @see PRI-372
|
|
93
|
+
*/
|
|
94
|
+
buildPrompt(payload: DiagnosticianContextPayload, opts?: BuildPromptOptions): PromptBuildResult;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=rootcause-prompt-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rootcause-prompt-builder.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician/rootcause-prompt-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAG/E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,oCAAoC,CAAC;AAS5C;;;;;;GAMG;AACH,MAAM,WAAW,6BAA6B;IAC5C,kEAAkE;IAClE,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,kFAAkF;IAClF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,+EAA+E;IAC/E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,GAAE,6BAAkC,GACvC,MAAM,CAsER;AAID;;;;;;;;;;GAUG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;gBAErB,IAAI,GAAE,6BAAkC;IAKpD;;;;;;;;OAQG;IACH,yBAAyB,CAAC,IAAI,GAAE,6BAAkC,GAAG,MAAM;IAS3E;;;;;;;;;;;OAWG;IACH,WAAW,CACT,OAAO,EAAE,2BAA2B,EACpC,IAAI,GAAE,kBAAuB,GAC5B,iBAAiB;CAwErB"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RootCausePromptBuilder — Stage A prompt builder for the split diagnostician pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Constructs the prompt for the Root Cause stage (Stage A), 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
|
+
* ## Phases
|
|
9
|
+
*
|
|
10
|
+
* - PHASE 1 — Evidence Review
|
|
11
|
+
* - PHASE 2 — Causal Chain (5 Whys)
|
|
12
|
+
* - PHASE 3 — Root Cause Classification
|
|
13
|
+
* - PHASE 3.5 — Core Axiom Grounding (when coreGrounding=true, PRI-371)
|
|
14
|
+
*
|
|
15
|
+
* ## Output
|
|
16
|
+
*
|
|
17
|
+
* The prompt requires output matching DiagRootCauseOutputV1Schema.
|
|
18
|
+
*
|
|
19
|
+
* @see PRI-372
|
|
20
|
+
*/
|
|
21
|
+
import { DefaultSchemaPromptAdapter } from '../adapter/schema-prompt-adapter.js';
|
|
22
|
+
import { DiagRootCauseOutputV1Schema } from './diag-rootcause-output.js';
|
|
23
|
+
import { buildLanguageDirective } from '../language-directive.js';
|
|
24
|
+
import { CORE_PRINCIPLES } from '../core-principles/core-principle-registry.js';
|
|
25
|
+
import { DEFAULT_PROMPT_BUILDER_LIMITS, summarizeConversationWindow, } from '../diagnostician-prompt-builder.js';
|
|
26
|
+
// ── Instruction builder ──────────────────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* Build the Stage A diagnostic protocol instruction (PHASE 1–3 + optional PHASE 3.5).
|
|
29
|
+
*
|
|
30
|
+
* Per DPB-02 (LOCKED): Output is ONLY JSON — no markdown, no file ops, no tool calls.
|
|
31
|
+
* Per DPB-04: LLM can only analyse the context provided in the prompt; it must NOT
|
|
32
|
+
* read files, call tools, or write to databases.
|
|
33
|
+
*
|
|
34
|
+
* When `coreGrounding` is true, PHASE 3.5 (Core Axiom Grounding) is inserted
|
|
35
|
+
* between PHASE 3 and the final output instruction. When false or undefined,
|
|
36
|
+
* a newline is inserted to preserve byte-identical output (EP-03: no silent fallback).
|
|
37
|
+
*
|
|
38
|
+
* @see PRI-372
|
|
39
|
+
*/
|
|
40
|
+
export function buildRootCauseProtocolInstruction(opts = {}) {
|
|
41
|
+
const adapter = opts.adapter ?? new DefaultSchemaPromptAdapter();
|
|
42
|
+
const schema = opts.schema ?? DiagRootCauseOutputV1Schema;
|
|
43
|
+
const { outputLanguage, coreGrounding } = opts;
|
|
44
|
+
const example = adapter.generateExample(schema);
|
|
45
|
+
const constraints = adapter.generateConstraints(schema);
|
|
46
|
+
const languageDirective = buildLanguageDirective(outputLanguage);
|
|
47
|
+
// T-E (PRI-371): When coreGrounding is true, insert PHASE 3.5.
|
|
48
|
+
// When false or undefined, output is byte-identical to the original
|
|
49
|
+
// (EP-03: no silent fallback).
|
|
50
|
+
const phase35Block = coreGrounding
|
|
51
|
+
? `
|
|
52
|
+
PHASE 3.5 — Core Axiom Grounding:
|
|
53
|
+
The following core axioms are the system's foundational behavioral principles.
|
|
54
|
+
If the root cause relates to any of these axioms, note the axiom ID (e.g. T-01)
|
|
55
|
+
in the ambiguityNotes field of your output.
|
|
56
|
+
|
|
57
|
+
Core Axioms:
|
|
58
|
+
${CORE_PRINCIPLES.map(p => `${p.id}: ${p.statement}`).join('\n')}
|
|
59
|
+
|
|
60
|
+
`
|
|
61
|
+
: '\n';
|
|
62
|
+
return `You are a root cause analysis expert. Follow this protocol:
|
|
63
|
+
|
|
64
|
+
PHASE 1 — Evidence Review:
|
|
65
|
+
Review the provided sourceRefs, diagnosisTarget.evidence entries, and conversationWindow
|
|
66
|
+
entries from the context payload. Do NOT read any files or call any tools.
|
|
67
|
+
Record all evidence by referencing the sourceRef identifiers and conversation
|
|
68
|
+
entries already present in the context. Each evidence item must cite its source.
|
|
69
|
+
Pay special attention to diagnosisTarget.evidence — these are the primary behavioral
|
|
70
|
+
evidence (owner messages and agent actions) that the root cause analysis must address.
|
|
71
|
+
|
|
72
|
+
PHASE 2 — Causal Chain (5 Whys):
|
|
73
|
+
Build a Why-1 through Why-5 causal chain. Each Why MUST have at least one evidenceRefs entry referencing a sourceRef from Phase 1.
|
|
74
|
+
- If no evidence is available for a Why level, reference the closest available evidence and note the gap in ambiguityNotes.
|
|
75
|
+
- evidenceRefs MUST NOT be an empty array — every causal chain entry must cite at least one evidence source.
|
|
76
|
+
- Why 1: Surface phenomenon (visible error)
|
|
77
|
+
- Why 2: Direct cause (nearest trigger)
|
|
78
|
+
- Why 3: Process gap (missing check/gate)
|
|
79
|
+
- Why 4: Design flaw (why gap exists)
|
|
80
|
+
- Why 5: Root cause (systemic defect)
|
|
81
|
+
Stop early if you find a directly fixable problem.
|
|
82
|
+
|
|
83
|
+
PHASE 3 — Root Cause Classification:
|
|
84
|
+
Classify into ONE: People | Design | Assumption | Tooling
|
|
85
|
+
- People: capability blind spots, habit issues
|
|
86
|
+
- Design: architecture defects, missing gates, process gaps
|
|
87
|
+
- Assumption: wrong assumptions about env/versions/deps
|
|
88
|
+
- Tooling: tool misconfiguration, API changes
|
|
89
|
+
${phase35Block}CRITICAL: Your ENTIRE response must be ONLY the JSON object below. Do NOT include any text before or after the JSON. Do NOT wrap the JSON in markdown code fences. Do NOT add explanatory prose. Output the raw JSON object and nothing else.
|
|
90
|
+
|
|
91
|
+
COMPLETE EXAMPLE OUTPUT (follow this exact structure):
|
|
92
|
+
${example}
|
|
93
|
+
|
|
94
|
+
IMPORTANT: The example above is ILLUSTRATIVE ONLY. Your root cause analysis MUST be based on the actual evidence in this context — do not copy the example text verbatim.
|
|
95
|
+
|
|
96
|
+
CONSTRAINTS:
|
|
97
|
+
- Output ONLY valid JSON — no markdown, no explanatory text, no code fences, no prose before or after
|
|
98
|
+
- Do NOT read files, call tools, or write to any database
|
|
99
|
+
- rootCause MUST include category prefix: "People: ..." or "Design: ..." or "Assumption: ..." or "Tooling: ..."
|
|
100
|
+
- rootCauseCategory MUST match the category prefix in rootCause
|
|
101
|
+
- If diagnosisTarget.evidence is an empty array (length === 0), you MUST NOT fabricate evidence entries.
|
|
102
|
+
Output confidence < 0.3 and set ambiguityNotes to include "Insufficient evidence".
|
|
103
|
+
- evidence: list all evidence items that support your analysis. If sourceRefs or diagnosisTarget.evidence
|
|
104
|
+
were provided in the input, you MUST reference them here. Only leave empty if the input genuinely
|
|
105
|
+
contains no evidence at all.
|
|
106
|
+
${constraints}${languageDirective}`;
|
|
107
|
+
}
|
|
108
|
+
// ── Prompt builder class ─────────────────────────────────────────────────────
|
|
109
|
+
/**
|
|
110
|
+
* RootCausePromptBuilder — Stage A prompt builder for the split diagnostician pipeline.
|
|
111
|
+
*
|
|
112
|
+
* Transforms DiagnosticianContextPayload into a PromptBuildResult for the
|
|
113
|
+
* Root Cause stage (Stage A). The output prompt requires the LLM to produce
|
|
114
|
+
* JSON matching DiagRootCauseOutputV1Schema.
|
|
115
|
+
*
|
|
116
|
+
* Uses an opts-object pattern for all methods to satisfy @typescript-eslint/max-params.
|
|
117
|
+
*
|
|
118
|
+
* @see PRI-372
|
|
119
|
+
*/
|
|
120
|
+
export class RootCausePromptBuilder {
|
|
121
|
+
adapter;
|
|
122
|
+
schema;
|
|
123
|
+
constructor(opts = {}) {
|
|
124
|
+
this.adapter = opts.adapter ?? new DefaultSchemaPromptAdapter();
|
|
125
|
+
this.schema = opts.schema ?? DiagRootCauseOutputV1Schema;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Build the Stage A diagnostic protocol instruction.
|
|
129
|
+
*
|
|
130
|
+
* Contains PHASE 1 (evidence review), PHASE 2 (causal chain / 5-Whys),
|
|
131
|
+
* PHASE 3 (root cause classification), and optional PHASE 3.5 (core axiom
|
|
132
|
+
* grounding when coreGrounding=true).
|
|
133
|
+
*
|
|
134
|
+
* @see PRI-372
|
|
135
|
+
*/
|
|
136
|
+
buildRootCauseInstruction(opts = {}) {
|
|
137
|
+
return buildRootCauseProtocolInstruction({
|
|
138
|
+
adapter: opts.adapter ?? this.adapter,
|
|
139
|
+
schema: opts.schema ?? this.schema,
|
|
140
|
+
outputLanguage: opts.outputLanguage,
|
|
141
|
+
coreGrounding: opts.coreGrounding,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Build the full prompt for Stage A.
|
|
146
|
+
*
|
|
147
|
+
* Transforms DiagnosticianContextPayload into a PromptBuildResult containing
|
|
148
|
+
* the JSON message to pass as the --message argument to the LLM agent.
|
|
149
|
+
*
|
|
150
|
+
* Per DPB-02: Output is ONLY JSON — no markdown, no file ops, no tool calls.
|
|
151
|
+
* Per DPB-05: This method only builds the prompt; it does NOT commit to PD database.
|
|
152
|
+
* Per DPB-07: NO extraSystemPrompt is added — agent profile is the source of truth.
|
|
153
|
+
*
|
|
154
|
+
* @see PRI-372
|
|
155
|
+
*/
|
|
156
|
+
buildPrompt(payload, opts = {}) {
|
|
157
|
+
const limits = opts.limits ?? DEFAULT_PROMPT_BUILDER_LIMITS;
|
|
158
|
+
const { outputLanguage, coreGrounding } = opts;
|
|
159
|
+
const truncationWarnings = [];
|
|
160
|
+
// DPB-04: Apply truncation to conversationWindow to prevent token overflow
|
|
161
|
+
const rawWindow = summarizeConversationWindow(payload.conversationWindow);
|
|
162
|
+
const windowEntries = rawWindow.slice(0, limits.maxConversationEntries);
|
|
163
|
+
if (rawWindow.length > limits.maxConversationEntries) {
|
|
164
|
+
truncationWarnings.push(`conversationWindow truncated from ${rawWindow.length} to ${limits.maxConversationEntries} entries`);
|
|
165
|
+
}
|
|
166
|
+
// Truncate individual entry text
|
|
167
|
+
const conversationWindow = windowEntries.map((entry) => {
|
|
168
|
+
if (entry.text && entry.text.length > limits.maxEntryTextChars) {
|
|
169
|
+
return {
|
|
170
|
+
...entry,
|
|
171
|
+
text: entry.text.slice(0, limits.maxEntryTextChars) + '...[truncated]',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return entry;
|
|
175
|
+
});
|
|
176
|
+
// Build compact context — replace conversationWindow with truncated version
|
|
177
|
+
const compactContext = {
|
|
178
|
+
...payload,
|
|
179
|
+
conversationWindow,
|
|
180
|
+
};
|
|
181
|
+
const diagnosticInstruction = this.buildRootCauseInstruction({
|
|
182
|
+
outputLanguage,
|
|
183
|
+
coreGrounding,
|
|
184
|
+
});
|
|
185
|
+
// DPB-04: Explicit top-level fields at the prompt level
|
|
186
|
+
const promptInput = {
|
|
187
|
+
taskId: payload.taskId,
|
|
188
|
+
contextHash: payload.contextHash,
|
|
189
|
+
diagnosisTarget: payload.diagnosisTarget,
|
|
190
|
+
conversationWindow,
|
|
191
|
+
sourceRefs: payload.sourceRefs,
|
|
192
|
+
context: compactContext,
|
|
193
|
+
diagnosticInstruction,
|
|
194
|
+
...(truncationWarnings.length > 0 ? { truncationWarnings } : {}),
|
|
195
|
+
};
|
|
196
|
+
// DPB-02: Output is ONLY JSON — no markdown, no file ops, no tool calls
|
|
197
|
+
let message = JSON.stringify(promptInput);
|
|
198
|
+
// If message exceeds maxMessageChars, truncate the diagnostic instruction
|
|
199
|
+
if (message.length > limits.maxMessageChars) {
|
|
200
|
+
const surplus = message.length - limits.maxMessageChars;
|
|
201
|
+
const instruction = diagnosticInstruction;
|
|
202
|
+
// Keep at least the first 200 chars of the instruction + a note
|
|
203
|
+
const keepLength = Math.max(200, instruction.length - surplus - 100);
|
|
204
|
+
const truncatedInstruction = instruction.slice(0, keepLength) +
|
|
205
|
+
'\n\n[OUTPUT FORMAT section is REQUIRED; other sections may be summarized if needed]';
|
|
206
|
+
promptInput.diagnosticInstruction = truncatedInstruction;
|
|
207
|
+
promptInput.truncationWarnings = [
|
|
208
|
+
...truncationWarnings,
|
|
209
|
+
`diagnosticInstruction truncated due to size (${message.length} > ${limits.maxMessageChars})`,
|
|
210
|
+
];
|
|
211
|
+
message = JSON.stringify(promptInput);
|
|
212
|
+
}
|
|
213
|
+
return { message, promptInput };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=rootcause-prompt-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rootcause-prompt-builder.js","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician/rootcause-prompt-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAGzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAKhF,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,oCAAoC,CAAC;AAuB5C,gFAAgF;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iCAAiC,CAC/C,OAAsC,EAAE;IAExC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,0BAA0B,EAAE,CAAC;IACjE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,2BAA2B,CAAC;IAC1D,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IAE/C,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACxD,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,cAAc,CAAC,CAAC;IAEjE,+DAA+D;IAC/D,oEAAoE;IACpE,+BAA+B;IAC/B,MAAM,YAAY,GAAG,aA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E,CAAC;SACjE,CAAC;QAEF,wEAAwE;QACxE,IAAI,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAE1C,0EAA0E;QAC1E,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;YAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;YACxD,MAAM,WAAW,GAAG,qBAAqB,CAAC;YAE1C,gEAAgE;YAChE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,GAAG,OAAO,GAAG,GAAG,CAAC,CAAC;YACrE,MAAM,oBAAoB,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC;gBAC3D,qFAAqF,CAAC;YAExF,WAAW,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;YACzD,WAAW,CAAC,kBAAkB,GAAG;gBAC/B,GAAG,kBAAkB;gBACrB,gDAAgD,OAAO,CAAC,MAAM,MAAM,MAAM,CAAC,eAAe,GAAG;aAC9F,CAAC;YACF,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RouterPromptBuilder — Stage C prompt builder for the split diagnostician pipeline.
|
|
3
|
+
*
|
|
4
|
+
* The Router stage receives both Stage A (Root Cause) and Stage B (Distiller)
|
|
5
|
+
* artifacts and produces the final `DiagnosticianOutputV1` — the unchanged
|
|
6
|
+
* downstream contract consumed by the rest of the system.
|
|
7
|
+
*
|
|
8
|
+
* Unlike the monolithic DiagnosticianPromptBuilder which runs the full 5-phase
|
|
9
|
+
* protocol, the Router does NOT re-derive root causes or invent new principles.
|
|
10
|
+
* It routes what the distiller produced into the appropriate recommendation
|
|
11
|
+
* taxonomy kind(s).
|
|
12
|
+
*
|
|
13
|
+
* @see PRI-372 — Split diagnostician into Stage A (Root Cause) + Stage B (Distiller) + Stage C (Router)
|
|
14
|
+
*/
|
|
15
|
+
import type { TSchema } from '@sinclair/typebox';
|
|
16
|
+
import type { SchemaPromptAdapter } from '../adapter/schema-prompt-adapter.js';
|
|
17
|
+
import type { DiagRootCauseOutputV1 } from './diag-rootcause-output.js';
|
|
18
|
+
import type { DiagDistillerOutputV1 } from './diag-distiller-output.js';
|
|
19
|
+
import type { BuildPromptOptions } from '../diagnostician-prompt-builder.js';
|
|
20
|
+
import type { OutputLanguage } from '../language-directive.js';
|
|
21
|
+
/**
|
|
22
|
+
* Options for RouterPromptBuilder constructor and buildRouterInstruction().
|
|
23
|
+
*
|
|
24
|
+
* Uses opts-object pattern to stay within max-params limit and allow
|
|
25
|
+
* partial overrides at both construction and method-call time.
|
|
26
|
+
*
|
|
27
|
+
* @see PRI-372
|
|
28
|
+
*/
|
|
29
|
+
export interface RouterPromptBuilderOptions {
|
|
30
|
+
/** Schema prompt adapter (default: DefaultSchemaPromptAdapter) */
|
|
31
|
+
adapter?: SchemaPromptAdapter;
|
|
32
|
+
/** TypeBox schema for output validation (default: DiagnosticianOutputV1Schema) */
|
|
33
|
+
schema?: TSchema;
|
|
34
|
+
/** Output language directive (default: none) */
|
|
35
|
+
outputLanguage?: OutputLanguage;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Structured input for the Router stage, carrying both Stage A and Stage B
|
|
39
|
+
* artifacts with their IDs for lineage tracing.
|
|
40
|
+
*
|
|
41
|
+
* @see PRI-372
|
|
42
|
+
*/
|
|
43
|
+
export interface RouterContextInput {
|
|
44
|
+
/** Artifact ID of the Stage A (Root Cause) output */
|
|
45
|
+
rootCauseArtifactId: string;
|
|
46
|
+
/** Stage A output — the root cause analysis result */
|
|
47
|
+
rootCauseOutput: DiagRootCauseOutputV1;
|
|
48
|
+
/** Artifact ID of the Stage B (Distiller) output */
|
|
49
|
+
distillerArtifactId: string;
|
|
50
|
+
/** Stage B output — the distilled principle and grounding */
|
|
51
|
+
distillerOutput: DiagDistillerOutputV1;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Prompt input for the Router stage — the JSON message sent to the LLM.
|
|
55
|
+
*
|
|
56
|
+
* Unlike the monolithic DiagnosticianPromptBuilder's PromptInput, the router
|
|
57
|
+
* carries Stage A and Stage B artifacts directly rather than a full
|
|
58
|
+
* DiagnosticianContextPayload with conversation window and source refs.
|
|
59
|
+
*
|
|
60
|
+
* @see PRI-372
|
|
61
|
+
*/
|
|
62
|
+
export interface RouterPromptInput {
|
|
63
|
+
/** Task being diagnosed — from Stage A output */
|
|
64
|
+
taskId: string;
|
|
65
|
+
/** Artifact ID of the Stage A (Root Cause) output for lineage */
|
|
66
|
+
rootCauseArtifactId: string;
|
|
67
|
+
/** Stage A output — root cause analysis result */
|
|
68
|
+
rootCauseOutput: DiagRootCauseOutputV1;
|
|
69
|
+
/** Artifact ID of the Stage B (Distiller) output for lineage */
|
|
70
|
+
distillerArtifactId: string;
|
|
71
|
+
/** Stage B output — distilled principle and grounding */
|
|
72
|
+
distillerOutput: DiagDistillerOutputV1;
|
|
73
|
+
/** Router instruction — the system-level directive for the LLM */
|
|
74
|
+
routerInstruction: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build result for the Router stage — follows the same pattern as PromptBuildResult.
|
|
78
|
+
*
|
|
79
|
+
* @see PRI-372
|
|
80
|
+
*/
|
|
81
|
+
export interface RouterPromptBuildResult {
|
|
82
|
+
/** JSON string — the exact value to pass as openclaw agent --message argument */
|
|
83
|
+
readonly message: string;
|
|
84
|
+
/** The RouterPromptInput object that was serialized to JSON */
|
|
85
|
+
readonly promptInput: RouterPromptInput;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Prompt builder for Stage C (Router) of the split diagnostician pipeline.
|
|
89
|
+
*
|
|
90
|
+
* The Router takes the root cause from Stage A and the distilled principle
|
|
91
|
+
* from Stage B, then decides the concrete carrier(s) — the recommendation
|
|
92
|
+
* taxonomy kind(s) — and assembles the final `DiagnosticianOutputV1`.
|
|
93
|
+
*
|
|
94
|
+
* Key constraint: the Router MUST NOT re-derive the root cause or invent
|
|
95
|
+
* new principles. It routes what the distiller produced.
|
|
96
|
+
*
|
|
97
|
+
* @see PRI-372
|
|
98
|
+
*/
|
|
99
|
+
export declare class RouterPromptBuilder {
|
|
100
|
+
private readonly adapter;
|
|
101
|
+
private readonly schema;
|
|
102
|
+
constructor(opts?: RouterPromptBuilderOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Build the router instruction string — the system-level directive that
|
|
105
|
+
* tells the LLM its role, input format, routing rules, output requirements,
|
|
106
|
+
* and constraints.
|
|
107
|
+
*
|
|
108
|
+
* @param opts - Optional overrides for adapter, schema, and outputLanguage.
|
|
109
|
+
* When provided, these override the constructor defaults for this call only.
|
|
110
|
+
* @returns The router instruction string.
|
|
111
|
+
*
|
|
112
|
+
* @see PRI-372
|
|
113
|
+
*/
|
|
114
|
+
buildRouterInstruction(opts?: RouterPromptBuilderOptions): string;
|
|
115
|
+
/**
|
|
116
|
+
* Build the full prompt for the Router stage, combining the router
|
|
117
|
+
* instruction with the structured Stage A + Stage B context.
|
|
118
|
+
*
|
|
119
|
+
* @param context - Structured input carrying Stage A and Stage B artifacts.
|
|
120
|
+
* @param opts - Build options including outputLanguage.
|
|
121
|
+
* @returns RouterPromptBuildResult with JSON message and RouterPromptInput object.
|
|
122
|
+
*
|
|
123
|
+
* @see PRI-372
|
|
124
|
+
*/
|
|
125
|
+
buildPrompt(context: RouterContextInput, opts?: BuildPromptOptions): RouterPromptBuildResult;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=router-prompt-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-prompt-builder.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/diagnostician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