@hicaru/pi-rlm 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +12 -35
  2. package/README.ru.md +18 -23
  3. package/README.zh-CN.md +17 -28
  4. package/package.json +1 -1
  5. package/src/bridge/library.ts +61 -26
  6. package/src/bridge/subcall-handlers.ts +382 -0
  7. package/src/commands/rlm-config.ts +47 -18
  8. package/src/commands/rlm.ts +3 -152
  9. package/src/config/defaults.ts +7 -15
  10. package/src/config/settings.ts +8 -32
  11. package/src/context/library-context.ts +90 -17
  12. package/src/core/engine.ts +115 -360
  13. package/src/core/history.ts +1 -1
  14. package/src/core/limits.ts +5 -12
  15. package/src/core/resource-limits.ts +0 -2
  16. package/src/core/types.ts +3 -36
  17. package/src/index.ts +49 -10
  18. package/src/mode/llm-model.ts +54 -0
  19. package/src/mode/rlm-mode.ts +26 -57
  20. package/src/prompts/glossary.ts +287 -0
  21. package/src/prompts/native.ts +127 -0
  22. package/src/prompts/system.ts +14 -386
  23. package/src/sandbox/context-file.ts +154 -0
  24. package/src/sandbox/interrupts.ts +145 -0
  25. package/src/sandbox/protocol.ts +14 -69
  26. package/src/sandbox/py/guards.py +150 -0
  27. package/src/sandbox/py/retrieval.py +265 -0
  28. package/src/sandbox/py/tasks.py +116 -0
  29. package/src/sandbox/py/worker.py +836 -0
  30. package/src/sandbox/sandbox-manager.ts +33 -6
  31. package/src/sandbox/sandbox.ts +153 -182
  32. package/src/text/tokens.ts +29 -3
  33. package/src/tool/background-tasks.ts +95 -0
  34. package/src/tool/repl-details.ts +4 -2
  35. package/src/tool/repl-render.ts +58 -0
  36. package/src/tool/repl-result.ts +70 -0
  37. package/src/tool/repl-tool.ts +178 -216
  38. package/src/tool/rlm-aggregator.ts +2 -10
  39. package/src/tool/rlm-details.ts +0 -2
  40. package/src/tool/rlm-events.ts +10 -16
  41. package/src/tool/rlm-tool.ts +1 -12
  42. package/src/tool/subcall-render.ts +15 -3
  43. package/src/tool/subcall-store.ts +57 -1
  44. package/src/ui/config-panel.ts +4 -16
  45. package/src/ui/intro.ts +1 -2
  46. package/src/ui/model-picker.ts +34 -10
  47. package/src/ui/status.ts +3 -7
  48. package/src/util/concurrency.ts +91 -13
  49. package/src/util/trace.ts +42 -0
  50. package/src/bridge/fallback-todo.ts +0 -137
  51. package/src/bridge/interactive.ts +0 -65
  52. package/src/bridge/llm-query.ts +0 -156
  53. package/src/bridge/pi-interactive.ts +0 -41
  54. package/src/bridge/rlm-query.ts +0 -108
  55. package/src/core/artifacts.ts +0 -89
  56. package/src/core/critique.ts +0 -92
  57. package/src/core/gates.ts +0 -301
  58. package/src/core/pipeline-handlers.ts +0 -319
  59. package/src/core/pipeline.ts +0 -268
  60. package/src/prompts/phases.ts +0 -104
  61. package/src/sandbox/worker.py +0 -1078
  62. package/src/state/index.ts +0 -24
  63. package/src/state/internal.ts +0 -46
  64. package/src/state/paths.ts +0 -44
  65. package/src/state/reads.ts +0 -133
  66. package/src/state/resume.ts +0 -173
  67. package/src/state/rows.ts +0 -123
  68. package/src/state/writes.ts +0 -58
@@ -1,104 +0,0 @@
1
- /**
2
- * Per-phase guidance for the gated RLM pipeline.
3
- * Injected at each phase boundary; the only channel between phases is durable
4
- * artifacts under .rlm/artifacts/.
5
- */
6
- import type { Phase } from "../core/pipeline.ts";
7
-
8
- const CLARIFY_GUIDANCE = Object.freeze([
9
- "## Clarify phase (intake interview)",
10
- "Interview the user until the task is understood. The engine COUNTS ask_user_question",
11
- "rounds it services — you cannot advance without having actually asked at least once.",
12
- "",
13
- "1. Intent first: ask ONE open-ended intent question (what problem, who hits it, what",
14
- " success looks like). Options are answer *shapes* (e.g. end user / maintainer / operator);",
15
- " do NOT mark a Recommended option. The automatic Other / free-text path carries the real framing.",
16
- " Up to 2 more intent rounds if the answer still cannot scope a narrow probe; then proceed",
17
- " with what you have.",
18
- "2. Probe before asking more: ground follow-ups in the REPL (deterministic search over",
19
- " context, a few llm_query reads) so questions cite real code as file:line.",
20
- "3. Confirm inferences, don't record them: batch inferred decisions into one call —",
21
- " \"From the code I inferred <behavior> (file:line). Keep or change?\" The user's answer",
22
- " is the Decision, not your inference.",
23
- "4. Scope / shape / detail rounds, one at a time: recommended option first; architecture",
24
- " (shape) options must state the tradeoff (\"optimizes X, costs Y\") — never one option",
25
- " masquerading as a choice; 2–4 independent detail questions may batch in one call.",
26
- "5. Classify answers: Decision → record; Correction → re-probe that seam, re-ask dependents;",
27
- " Defer → ## Open Questions.",
28
- "6. Terminate on depth, not politeness: stop when every raised branch has a Decision or a",
29
- " Deferral and ## Problem & Intent holds the user's own words verbatim. Do not pad the",
30
- " interview; do not ask a final \"looks good?\" rubber-stamp.",
31
- "7. Then save_artifact(\"clarification\", content) with frontmatter:",
32
- " status: ready",
33
- " decisions_count: N",
34
- " open_questions_count: M",
35
- " and body sections:",
36
- " ## Problem & Intent (user's words VERBATIM)",
37
- " ## Decisions (one '- ' bullet per decision)",
38
- " ## Open Questions (one '- ' bullet per deferral; may be empty with count 0)",
39
- " ## Non-Goals",
40
- ' Then advance_phase("research", summary).',
41
- ].join("\n"));
42
-
43
- const RESEARCH_GUIDANCE = Object.freeze([
44
- "## Research phase",
45
- "Read the clarifications artifact (if present) and honor recorded Decisions; do not silently",
46
- "resolve Open Questions.",
47
- "Probe the repository, delegate long reads via `llm_query_batched` / `llm_query_chunked`.",
48
- "Every factual claim about the code MUST be cited as `path/file.ext:LINE` (or `LINE-LINE`).",
49
- "The engine VERIFIES citations against the working tree — unbacked citations reject advance.",
50
- "When research is complete, write ONE research document with a `## Findings` section and call:",
51
- ' `save_artifact("research", content)` # frontmatter must include `status: ready`',
52
- ' `advance_phase("blueprint", summary)`',
53
- "Do not implement code in this phase.",
54
- ].join("\n"));
55
-
56
- const BLUEPRINT_GUIDANCE = Object.freeze([
57
- "## Blueprint phase",
58
- "Read the clarifications artifact (if present) and plan only within recorded Decisions;",
59
- "Open Questions that would block the design must be re-asked via ask_user_question, not assumed.",
60
- 'Produce ONE plan document and save it with `save_artifact("plan", content)`.',
61
- "This pipeline is read-only: it produces a plan a human or a native-mode agent executes;",
62
- "do not write source files here (sandbox write modes are blocked).",
63
- "Write changes as exact, copy-pasteable before/after code — never as prose instructions.",
64
- "The ENGINE derive-checks the document — these are hard gates, not suggestions:",
65
- "- frontmatter: `status: ready`, `phase_count: N`, `phases: [{n: 1, title: ...}, ...]`",
66
- "- `phases:` / `phase_count` MUST match the `## Phase N:` body headings exactly (fenced examples ignored)",
67
- "- every `file:line` citation MUST resolve against the working tree at this revision",
68
- "Each `## Phase N: <title>` section contains:",
69
- "- `### Changes Required` — per file: path + the exact intended change",
70
- "- `### Success Criteria` — `#### Automated Verification:` (runnable commands) and",
71
- " `#### Manual Verification:` checklists",
72
- "Phases must be independently implementable in order, each leaving the tree working.",
73
- 'When ready: `advance_phase("validate", summary)`.',
74
- ].join("\n"));
75
-
76
- const VALIDATE_GUIDANCE = Object.freeze([
77
- "## Validate phase (adversarial plan review)",
78
- "Nothing has been implemented — you are reviewing the PLAN, not a diff.",
79
- "Read the goal artifact (verbatim brief), the clarifications artifact (recorded Decisions),",
80
- "and the plan. For each plan phase check against the working tree:",
81
- "- every cited `file:line` still resolves and says what the plan claims",
82
- "- every file the phase edits exists (or is created by an earlier phase)",
83
- "- no phase contradicts a recorded Decision or silently resolves an Open Question",
84
- "- the Success Criteria are actually runnable and actually prove the change",
85
- "- phases are independently implementable in the stated order",
86
- "Write ONE review via `save_artifact(\"validation\", content)` with frontmatter:",
87
- "- `status: ready`",
88
- "- `blockers_count: <int >= 0>` # MEASURED — routing key; not prose",
89
- "- `verdict: pass | fail` # pass requires blockers_count === 0",
90
- "Each blocker needs a resolvable `file:line` citation.",
91
- "Then finalize: `answer[\"content\"] = <the reviewed plan + review summary>; answer[\"ready\"] = True`.",
92
- "If `blockers_count > 0`, the engine re-enters blueprint (bounded by maxBackwardJumps).",
93
- ].join("\n"));
94
-
95
- const GUIDANCE: Readonly<Record<Phase, string>> = Object.freeze({
96
- clarify: CLARIFY_GUIDANCE,
97
- research: RESEARCH_GUIDANCE,
98
- blueprint: BLUEPRINT_GUIDANCE,
99
- validate: VALIDATE_GUIDANCE,
100
- });
101
-
102
- export function phaseGuidance(phase: Phase): string {
103
- return GUIDANCE[phase];
104
- }