@hicaru/pi-rlm 0.1.8 → 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.
- package/README.md +22 -19
- package/package.json +2 -1
- package/src/bridge/library.ts +93 -15
- package/src/bridge/llm-query.ts +60 -36
- package/src/bridge/rlm-query.ts +63 -79
- package/src/commands/rlm-config.ts +8 -8
- package/src/commands/rlm.ts +48 -12
- package/src/config/settings.ts +33 -3
- package/src/context/library-context.ts +209 -22
- package/src/context/repomix-context.ts +7 -58
- package/src/core/answer.ts +5 -13
- package/src/core/artifacts.ts +4 -3
- package/src/core/critique.ts +92 -0
- package/src/core/engine.ts +94 -299
- package/src/core/gates.ts +33 -4
- package/src/core/limits.ts +19 -1
- package/src/core/pipeline-handlers.ts +319 -0
- package/src/core/pipeline.ts +40 -15
- package/src/core/types.ts +26 -30
- package/src/index.ts +36 -26
- package/src/mode/native-guards.ts +2 -2
- package/src/mode/rlm-mode.ts +8 -11
- package/src/prompts/phases.ts +18 -39
- package/src/prompts/system.ts +167 -64
- package/src/prompts/user.ts +1 -5
- package/src/sandbox/protocol.ts +5 -17
- package/src/sandbox/sandbox-manager.ts +5 -5
- package/src/sandbox/sandbox.ts +67 -27
- package/src/sandbox/worker.py +534 -48
- package/src/state/paths.ts +1 -1
- package/src/state/reads.ts +12 -4
- package/src/state/resume.ts +26 -25
- package/src/state/rows.ts +2 -2
- package/src/text/parsing.ts +0 -6
- package/src/text/tokens.ts +7 -1
- package/src/tool/repl-details.ts +2 -3
- package/src/tool/repl-tool.ts +132 -337
- package/src/tool/rlm-aggregator.ts +7 -7
- package/src/tool/rlm-details.ts +6 -13
- package/src/tool/rlm-events.ts +14 -11
- package/src/tool/rlm-tool.ts +20 -38
- package/src/tool/subcall-render.ts +61 -9
- package/src/tool/subcall-store.ts +4 -2
- package/src/ui/config-panel.ts +43 -23
- package/src/ui/intro.ts +2 -1
- package/src/ui/status.ts +8 -5
- package/src/ui/theme-adapter.ts +36 -0
- package/src/ui/theme.ts +0 -25
- package/src/mode/input-router.ts +0 -23
- package/src/registry/edit-registry.ts +0 -22
- package/src/text/edits.ts +0 -164
- package/src/tool/apply-edits-tool.ts +0 -295
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preflight critique for stage artifacts — port of codex-bais `model_critique`.
|
|
3
|
+
*
|
|
4
|
+
* Blocking truth comes from `stage.gate` (the same function `advance_phase` runs), so the
|
|
5
|
+
* two can never drift. `warnings` are advisory model-risk diagnostics that never block.
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
countBulletsUnderHeading,
|
|
9
|
+
phasesMissingSuccessCriteria,
|
|
10
|
+
sectionHasNonEmptyBody,
|
|
11
|
+
} from "./gates.ts";
|
|
12
|
+
import type { StageDef, StageGateData } from "./pipeline.ts";
|
|
13
|
+
|
|
14
|
+
export interface Critique {
|
|
15
|
+
/** Blocking — `advance_phase` will reject while non-empty. */
|
|
16
|
+
readonly issues: readonly string[];
|
|
17
|
+
/** Advisory — surfaced to the model, never blocking. */
|
|
18
|
+
readonly warnings: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* Convenience alias for `issues.length === 0` — do not set independently;
|
|
21
|
+
* always derive from `issues`.
|
|
22
|
+
*/
|
|
23
|
+
readonly canAdvance: boolean;
|
|
24
|
+
/** Gate payload when `canAdvance` — reused by advance_phase (no second gate run). */
|
|
25
|
+
readonly gateData?: StageGateData;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const NO_STRINGS: readonly string[] = Object.freeze([]);
|
|
29
|
+
|
|
30
|
+
/** Advisory checks per artifact kind. Pure; returns a frozen array. */
|
|
31
|
+
function advisoriesFor(stage: StageDef, content: string): readonly string[] {
|
|
32
|
+
switch (stage.artifactKind) {
|
|
33
|
+
case "plan": {
|
|
34
|
+
const missing = phasesMissingSuccessCriteria(content);
|
|
35
|
+
if (missing.length > 0) {
|
|
36
|
+
return Object.freeze([
|
|
37
|
+
`${missing.join(", ")} ${missing.length === 1 ? "has" : "have"} no `
|
|
38
|
+
+ "'### Success Criteria' — validate cannot check them",
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
return NO_STRINGS;
|
|
42
|
+
}
|
|
43
|
+
case "clarification": {
|
|
44
|
+
const open = countBulletsUnderHeading(content, "Open Questions");
|
|
45
|
+
if (open > 0) {
|
|
46
|
+
return Object.freeze([
|
|
47
|
+
`${open} Open Question(s) carried into blueprint — re-ask any that block the design`,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
return NO_STRINGS;
|
|
51
|
+
}
|
|
52
|
+
case "research": {
|
|
53
|
+
if (!sectionHasNonEmptyBody(content, "Findings")) {
|
|
54
|
+
return Object.freeze(["research artifact has no '## Findings' section"]);
|
|
55
|
+
}
|
|
56
|
+
return NO_STRINGS;
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return NO_STRINGS;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function critiqueArtifact(
|
|
64
|
+
stage: StageDef,
|
|
65
|
+
content: string,
|
|
66
|
+
path: string,
|
|
67
|
+
cwd: string,
|
|
68
|
+
): Critique {
|
|
69
|
+
const gate = stage.gate(content, path, cwd);
|
|
70
|
+
const issues = gate.ok ? NO_STRINGS : Object.freeze([gate.error]);
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
issues,
|
|
73
|
+
warnings: advisoriesFor(stage, content),
|
|
74
|
+
canAdvance: issues.length === 0,
|
|
75
|
+
gateData: gate.ok ? gate.value : undefined,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Human-readable renderer for the `save_artifact` return value. */
|
|
80
|
+
export function formatCritique(critique: Critique): string {
|
|
81
|
+
if (critique.issues.length === 0 && critique.warnings.length === 0) {
|
|
82
|
+
return "gate: clean — call advance_phase when ready.";
|
|
83
|
+
}
|
|
84
|
+
const lines = new Array<string>(critique.issues.length + critique.warnings.length);
|
|
85
|
+
let n = 0;
|
|
86
|
+
for (let i = 0; i < critique.issues.length; i++) lines[n++] = ` BLOCKER: ${critique.issues[i]}`;
|
|
87
|
+
for (let i = 0; i < critique.warnings.length; i++) lines[n++] = ` warning: ${critique.warnings[i]}`;
|
|
88
|
+
const head = critique.canAdvance
|
|
89
|
+
? "gate: passes, with advisories —"
|
|
90
|
+
: "gate: WOULD REJECT — fix before advance_phase:";
|
|
91
|
+
return `${head}\n${lines.join("\n")}`;
|
|
92
|
+
}
|