loopforge 3.0.0 → 3.2.1

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 (178) hide show
  1. package/README.md +128 -145
  2. package/dist/audit.d.ts +50 -0
  3. package/dist/audit.d.ts.map +1 -0
  4. package/dist/audit.js +158 -0
  5. package/dist/audit.js.map +1 -0
  6. package/dist/canonical-state.d.ts +28 -20
  7. package/dist/canonical-state.d.ts.map +1 -1
  8. package/dist/canonical-state.js +82 -173
  9. package/dist/canonical-state.js.map +1 -1
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +25 -16
  12. package/dist/cli.js.map +1 -1
  13. package/dist/cognitive-governance.d.ts +25 -33
  14. package/dist/cognitive-governance.d.ts.map +1 -1
  15. package/dist/cognitive-governance.js +38 -138
  16. package/dist/cognitive-governance.js.map +1 -1
  17. package/dist/enforcement-gate.d.ts +76 -0
  18. package/dist/enforcement-gate.d.ts.map +1 -0
  19. package/dist/enforcement-gate.js +1071 -0
  20. package/dist/enforcement-gate.js.map +1 -0
  21. package/dist/engine.d.ts +99 -0
  22. package/dist/engine.d.ts.map +1 -0
  23. package/dist/engine.js +839 -0
  24. package/dist/engine.js.map +1 -0
  25. package/dist/evidence-claims.d.ts +50 -0
  26. package/dist/evidence-claims.d.ts.map +1 -0
  27. package/dist/evidence-claims.js +134 -0
  28. package/dist/evidence-claims.js.map +1 -0
  29. package/dist/evidence-provider.d.ts +21 -23
  30. package/dist/evidence-provider.d.ts.map +1 -1
  31. package/dist/evidence-provider.js +74 -34
  32. package/dist/evidence-provider.js.map +1 -1
  33. package/dist/generate-schema.js +1 -84
  34. package/dist/generate-schema.js.map +1 -1
  35. package/dist/index.d.ts +19 -22
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +16 -15
  38. package/dist/index.js.map +1 -1
  39. package/dist/loop-compiler.d.ts +41 -3
  40. package/dist/loop-compiler.d.ts.map +1 -1
  41. package/dist/loop-compiler.js +632 -273
  42. package/dist/loop-compiler.js.map +1 -1
  43. package/dist/loop-extras-parser.d.ts +2 -2
  44. package/dist/loop-extras-parser.d.ts.map +1 -1
  45. package/dist/loop-extras-parser.js +2 -2
  46. package/dist/loop-extras-parser.js.map +1 -1
  47. package/dist/loop-projection.d.ts +26 -0
  48. package/dist/loop-projection.d.ts.map +1 -0
  49. package/dist/loop-projection.js +142 -0
  50. package/dist/loop-projection.js.map +1 -0
  51. package/dist/loop-store.d.ts +112 -24
  52. package/dist/loop-store.d.ts.map +1 -1
  53. package/dist/loop-store.js +365 -218
  54. package/dist/loop-store.js.map +1 -1
  55. package/dist/mcp/round-lifecycle.d.ts +216 -0
  56. package/dist/mcp/round-lifecycle.d.ts.map +1 -0
  57. package/dist/mcp/round-lifecycle.js +926 -0
  58. package/dist/mcp/round-lifecycle.js.map +1 -0
  59. package/dist/mcp/server.d.ts +2 -1
  60. package/dist/mcp/server.d.ts.map +1 -1
  61. package/dist/mcp/server.js +28 -42
  62. package/dist/mcp/server.js.map +1 -1
  63. package/dist/mcp/session.d.ts +53 -101
  64. package/dist/mcp/session.d.ts.map +1 -1
  65. package/dist/mcp/session.js +306 -1105
  66. package/dist/mcp/session.js.map +1 -1
  67. package/dist/mcp/tools.d.ts +13 -16
  68. package/dist/mcp/tools.d.ts.map +1 -1
  69. package/dist/mcp/tools.js +479 -413
  70. package/dist/mcp/tools.js.map +1 -1
  71. package/dist/policy-metrics.d.ts +12 -17
  72. package/dist/policy-metrics.d.ts.map +1 -1
  73. package/dist/policy-metrics.js +95 -161
  74. package/dist/policy-metrics.js.map +1 -1
  75. package/dist/policy.d.ts +44 -35
  76. package/dist/policy.d.ts.map +1 -1
  77. package/dist/policy.js +31 -115
  78. package/dist/policy.js.map +1 -1
  79. package/dist/prompt-assembler.d.ts +37 -6
  80. package/dist/prompt-assembler.d.ts.map +1 -1
  81. package/dist/prompt-assembler.js +389 -160
  82. package/dist/prompt-assembler.js.map +1 -1
  83. package/dist/prompt-policy.d.ts +1 -8
  84. package/dist/prompt-policy.d.ts.map +1 -1
  85. package/dist/prompt-policy.js +8 -26
  86. package/dist/prompt-policy.js.map +1 -1
  87. package/dist/protocol.d.ts +357 -229
  88. package/dist/protocol.d.ts.map +1 -1
  89. package/dist/protocol.js +139 -15
  90. package/dist/protocol.js.map +1 -1
  91. package/dist/replay.d.ts +5 -13
  92. package/dist/replay.d.ts.map +1 -1
  93. package/dist/replay.js +19 -55
  94. package/dist/replay.js.map +1 -1
  95. package/dist/round-coordinator.d.ts +20 -24
  96. package/dist/round-coordinator.d.ts.map +1 -1
  97. package/dist/round-coordinator.js +99 -92
  98. package/dist/round-coordinator.js.map +1 -1
  99. package/dist/round-driver.d.ts +14 -13
  100. package/dist/round-driver.d.ts.map +1 -1
  101. package/dist/round-driver.js +26 -14
  102. package/dist/round-driver.js.map +1 -1
  103. package/dist/round-transaction.d.ts +15 -18
  104. package/dist/round-transaction.d.ts.map +1 -1
  105. package/dist/round-transaction.js +38 -47
  106. package/dist/round-transaction.js.map +1 -1
  107. package/dist/self-eval.d.ts +53 -0
  108. package/dist/self-eval.d.ts.map +1 -0
  109. package/dist/self-eval.js +284 -0
  110. package/dist/self-eval.js.map +1 -0
  111. package/dist/storage.d.ts +9 -4
  112. package/dist/storage.d.ts.map +1 -1
  113. package/dist/storage.js +18 -6
  114. package/dist/storage.js.map +1 -1
  115. package/dist/token-utils.d.ts +15 -3
  116. package/dist/token-utils.d.ts.map +1 -1
  117. package/dist/token-utils.js +24 -5
  118. package/dist/token-utils.js.map +1 -1
  119. package/dist/verification-gate.d.ts +108 -0
  120. package/dist/verification-gate.d.ts.map +1 -0
  121. package/dist/verification-gate.js +971 -0
  122. package/dist/verification-gate.js.map +1 -0
  123. package/loop_policy.json +44 -15
  124. package/package.json +5 -10
  125. package/skills/perception/SKILL.md +182 -199
  126. package/dist/canonical-event-writer.d.ts +0 -20
  127. package/dist/canonical-event-writer.d.ts.map +0 -1
  128. package/dist/canonical-event-writer.js +0 -131
  129. package/dist/canonical-event-writer.js.map +0 -1
  130. package/dist/compiler-subgoals.d.ts +0 -7
  131. package/dist/compiler-subgoals.d.ts.map +0 -1
  132. package/dist/compiler-subgoals.js +0 -93
  133. package/dist/compiler-subgoals.js.map +0 -1
  134. package/dist/derive-id.d.ts +0 -12
  135. package/dist/derive-id.d.ts.map +0 -1
  136. package/dist/derive-id.js +0 -31
  137. package/dist/derive-id.js.map +0 -1
  138. package/dist/mcp/session-projection.d.ts +0 -5
  139. package/dist/mcp/session-projection.d.ts.map +0 -1
  140. package/dist/mcp/session-projection.js +0 -18
  141. package/dist/mcp/session-projection.js.map +0 -1
  142. package/dist/mcp/session-queue.d.ts +0 -3
  143. package/dist/mcp/session-queue.d.ts.map +0 -1
  144. package/dist/mcp/session-queue.js +0 -18
  145. package/dist/mcp/session-queue.js.map +0 -1
  146. package/dist/mcp/session-types.d.ts +0 -72
  147. package/dist/mcp/session-types.d.ts.map +0 -1
  148. package/dist/mcp/session-types.js +0 -2
  149. package/dist/mcp/session-types.js.map +0 -1
  150. package/dist/round-commit-store.d.ts +0 -12
  151. package/dist/round-commit-store.d.ts.map +0 -1
  152. package/dist/round-commit-store.js +0 -13
  153. package/dist/round-commit-store.js.map +0 -1
  154. package/dist/round-gate.d.ts +0 -31
  155. package/dist/round-gate.d.ts.map +0 -1
  156. package/dist/round-gate.js +0 -259
  157. package/dist/round-gate.js.map +0 -1
  158. package/dist/round-recovery.d.ts +0 -17
  159. package/dist/round-recovery.d.ts.map +0 -1
  160. package/dist/round-recovery.js +0 -117
  161. package/dist/round-recovery.js.map +0 -1
  162. package/dist/round-report.d.ts +0 -16
  163. package/dist/round-report.d.ts.map +0 -1
  164. package/dist/round-report.js +0 -401
  165. package/dist/round-report.js.map +0 -1
  166. package/dist/runtime-services.d.ts +0 -59
  167. package/dist/runtime-services.d.ts.map +0 -1
  168. package/dist/runtime-services.js +0 -460
  169. package/dist/runtime-services.js.map +0 -1
  170. package/dist/vault-format.d.ts +0 -4
  171. package/dist/vault-format.d.ts.map +0 -1
  172. package/dist/vault-format.js +0 -4
  173. package/dist/vault-format.js.map +0 -1
  174. package/dist/vault-types.d.ts +0 -24
  175. package/dist/vault-types.d.ts.map +0 -1
  176. package/dist/vault-types.js +0 -2
  177. package/dist/vault-types.js.map +0 -1
  178. package/loopforge-policy.json +0 -340
@@ -6,66 +6,238 @@
6
6
  * v1.15: 40 types — 4 enums + 35 interfaces + 1 type alias.
7
7
  */
8
8
  export declare enum Mode {
9
- LOOP_COMPILE = "loop_compile"
9
+ LOOP_COMPILE = "loop_compile",
10
+ FEEDBACK = "feedback"
10
11
  }
12
+ import type { PresentedStateSnapshot } from "./canonical-state.js";
11
13
  export declare enum AgentStatus {
12
14
  OK = "ok",
13
15
  ERROR = "error",
14
16
  STALLED = "stalled"
15
17
  }
16
- export type EvidenceStatus = "verified" | "claimed" | "contradicted" | "unavailable";
17
- export interface RoundCheckReport {
18
- name: string;
19
- status: "passed" | "failed" | "not_run";
20
- required?: boolean;
21
- summary?: string;
22
- counts?: {
18
+ export interface ExecutionFeedback {
19
+ output: string;
20
+ success: boolean;
21
+ constraint_violations: string[];
22
+ manual_fixes_needed: string;
23
+ }
24
+ export declare function makeExecutionFeedback(overrides?: Partial<ExecutionFeedback>): ExecutionFeedback;
25
+ /** P4: Structured execution evidence reported by the agent after each round.
26
+ * Gives LoopForge visibility into what actually happened — files changed,
27
+ * test results, success criteria met, and a subjective progress estimate.
28
+ * Enables the compiler to cross-validate agent claims and compute real progress. */
29
+ export interface ExecutionEvidence {
30
+ /** Files changed in this round. Empty if no files were modified. */
31
+ files_changed: string[];
32
+ /** Test results. null if no tests were run. */
33
+ test_results: {
23
34
  passed: number;
24
35
  failed: number;
25
36
  skipped: number;
26
- };
37
+ } | null;
38
+ /** Success criteria from the Loop Objective that were MET this round. */
39
+ success_criteria_met: string[];
40
+ /** Success criteria from the Loop Objective that REMAIN unmet. */
41
+ success_criteria_remaining: string[];
42
+ /** Agent's own estimate of overall progress (0.0 to 1.0). */
43
+ progress_estimate: number;
44
+ }
45
+ export declare function makeExecutionEvidence(overrides?: Partial<ExecutionEvidence>): ExecutionEvidence;
46
+ /** P5: A revision to a success criterion — the old form and the new form.
47
+ * The agent proposes this when it discovers the original criterion was
48
+ * wrong, unrealistic, or needs refinement. */
49
+ export interface CriterionRevision {
50
+ old: string;
51
+ new: string;
27
52
  }
28
- export interface RoundEvidenceClaim {
29
- id: string;
30
- targetId: string;
31
- evidenceRefs: string[];
32
- }
33
- export interface EvidenceProvenance {
34
- source: "agent" | "command" | "provider" | "verification";
35
- observedAt: string;
36
- status: EvidenceStatus;
37
- detail?: string;
38
- }
39
- export interface EvidenceEnvelope {
40
- files: string[];
41
- checks: RoundCheckReport[];
42
- claims: RoundEvidenceClaim[];
43
- provenance: Record<string, EvidenceProvenance>;
44
- noChangeReason?: string;
45
- }
46
- /** Runtime-derived evidence view. It is rebuilt from a RoundReport and
47
- * provider snapshots; it is never persisted as an independent fact. */
48
- export interface EvidenceDerivedView {
49
- reportedFiles: string[];
50
- observedFiles: string[];
51
- checks: RoundCheckReport[];
52
- verifiedClaims: string[];
53
- contradictedClaims: string[];
54
- unavailableClaims: string[];
55
- criteriaMet: string[];
56
- criteriaRemaining: string[];
57
- progressRatio: number | null;
58
- testCounts: {
59
- passed: number;
60
- failed: number;
61
- skipped: number;
53
+ /** Structured self-evaluation embedded in compiled prompts.
54
+ * The agent outputs this after completing each round.
55
+ * Every field is consumed by at least one downstream function.
56
+ *
57
+ * v1.4 (P0–P2): Three new optional fields enable cognitive evolution.
58
+ * v1.5 (P4–P5): Execution evidence, progress tracking, and self-correction. */
59
+ export interface SelfEvaluation {
60
+ /** true ONLY if all hard constraints were met and the task goal was achieved. */
61
+ success: boolean;
62
+ /** Specific, actionable summary of what was DONE this round.
63
+ * Feeds: buildRollingSummary (key_outcomes),
64
+ * computeConstraintRetirement (activity detection), vault lineage. */
65
+ output_summary: string;
66
+ /** Constraints the agent actually violated this round.
67
+ * Feeds: checkLoopHealth (constraint_integrity),
68
+ * buildRollingSummary (recurring_issues), computeConstraintRetirement. */
69
+ constraint_violations: string[];
70
+ /** false ONLY when the entire task is complete. Tells the autonomous
71
+ * runner to stop the loop. Not consumed by the compiler. */
72
+ should_continue: boolean;
73
+ /** P0: New constraints discovered during this round that were not
74
+ * known before. Merged into the active constraint set by the compiler.
75
+ * Omit or leave empty if none discovered. */
76
+ discovered_constraints?: string[];
77
+ /** P1: A refinement / deepening of the task objective based on this
78
+ * round's discoveries. Appended to (never replaces) the original
79
+ * objective. Omit if understanding is unchanged. */
80
+ objective_refinement?: string;
81
+ /** P2: Sub-problems that surfaced during execution and may need
82
+ * separate attention. Feed into the next-task suggestion.
83
+ * Omit or leave empty if none emerged. */
84
+ emerged_subtasks?: string[];
85
+ /** P4: Structured evidence of what was executed this round.
86
+ * Files changed, test results, criteria met/remaining, progress estimate.
87
+ * Enables the compiler to validate claims and compute real progress. */
88
+ execution_evidence?: ExecutionEvidence;
89
+ /** P5: Constraints that the agent now believes are wrong or irrelevant.
90
+ * Removed from the active constraint set by the compiler.
91
+ * Omit or leave empty if none. */
92
+ retracted_constraints?: string[];
93
+ /** P5: Success criteria that need revision. The agent discovered the
94
+ * original criterion was incorrect and proposes a new formulation.
95
+ * Applied to the Loop Objective by the compiler (version++). */
96
+ revised_success_criteria?: CriterionRevision[];
97
+ /** P5: Assumptions the agent made in earlier rounds that turned out to
98
+ * be wrong. Recorded in the rolling summary as key lessons.
99
+ * Omit or leave empty if none. */
100
+ wrong_assumptions?: string[];
101
+ /** v1.10: Agent declares a subtask boundary. When true, the compiler
102
+ * generates an agent_declared milestone. */
103
+ compression_checkpoint?: boolean;
104
+ /** v1.10: Human-readable label for this checkpoint (e.g. "数据模型层完成").
105
+ * Used as the checkpoint heading in subsequent prompts. */
106
+ checkpoint_label?: string;
107
+ /** Multi-agent: Results of sub-agent / Worker delegations this round.
108
+ * The main agent (or Coordinator) reports what it delegated.
109
+ * The engine automatically writes these to the delegation journal.
110
+ * Omit or leave empty if no delegations occurred. */
111
+ worker_results?: WorkerResult[];
112
+ /** v1.16: Agent's declared next action — what it plans to do in the
113
+ * following round. Stored as loop state and rendered in the next prompt
114
+ * so the agent's self-planning persists across rounds. Optional —
115
+ * no next_action means the compiler generates the next task as before. */
116
+ next_action?: string;
117
+ /** v2.2: Sub-tasks the agent completed this round. Each entry may be a
118
+ * sub-goal ID (e.g. "sg-a3f2b1c0" from the Sub-Goal Dashboard) for
119
+ * exact matching, or a natural-language description for Jaccard
120
+ * similarity fallback. Omit if none. */
121
+ completed_subtasks?: string[];
122
+ /** v2.2: Sub-tasks that are now blocked (cannot proceed). Same ID-or-
123
+ * description matching as completed_subtasks. Omit if none. */
124
+ blocked_subtasks?: string[];
125
+ /** v2.2: Sub-tasks the agent is canceling (no longer needed). Same ID-or-
126
+ * description matching as completed_subtasks. Omit if none. */
127
+ canceled_subtasks?: string[];
128
+ /** v2.5: Why the agent is stopping. Only meaningful when
129
+ * should_continue=false and success=false. Defaults to "gave_up"
130
+ * (current behavior) when absent. "blocked" means work cannot proceed
131
+ * under current constraints; "needs_human_input" requires intervention. */
132
+ stop_reason?: "gave_up" | "blocked" | "needs_human_input";
133
+ /** v2.12: Declared tri-state outcome. When absent, derived from success
134
+ * (true → "success", false → "failed"). "partial" and "blocked" can only
135
+ * be declared explicitly. A declared non-success outcome suppresses the
136
+ * success-class verification checks even when success=true (the boolean
137
+ * is kept for backward compatibility). */
138
+ outcome?: RoundOutcome;
139
+ /** v2.12: Flat blocker description, meaningful only when outcome==="blocked".
140
+ * Also feeds the user/agent gate classification (P2). ≤ 500 chars. */
141
+ blocker?: string;
142
+ /** v2.12: Retroactive claims that a PRIOR round satisfied a criterion.
143
+ * The runtime verifies these against the prior round's git evidence.
144
+ * Max 20 entries. */
145
+ retroactiveClaims?: {
146
+ round: number;
147
+ claim: string;
148
+ }[];
149
+ /** v2.12: Declared reason for claiming success with no machine-verifiable
150
+ * evidence (e.g. "no code changes required — documentation-only round").
151
+ * Downgrades the success_without_verified_evidence check from error to
152
+ * info. Flat string, ≤ 200 chars. */
153
+ no_change_reason?: string;
154
+ /** v2.8: When the previous round's verification flagged intent_drift or
155
+ * subgoal_drift, the agent explains why its actions diverged from its
156
+ * stated plan. Populated from the self-eval block when the prompt
157
+ * injected the field. Empty or absent when no drift was flagged.
158
+ * Used by the enforcement gate R7 to distinguish intentional pivots
159
+ * from unacknowledged drift. */
160
+ drift_clarification?: string;
161
+ /** v2.9: Model's information needs for the next round's prompt.
162
+ * Consumed by the Compiler — not durable across rounds.
163
+ * Omit or leave empty if the model has no specific requests. */
164
+ prompt_requests?: PromptRequests;
165
+ }
166
+ /** v2.12: Tri-state round outcome. Declared via SelfEvaluation.outcome;
167
+ * derived from `success` when absent. Shared by the dual gates, the stop
168
+ * mapping, and the audit view. */
169
+ export type RoundOutcome = "success" | "partial" | "failed" | "blocked";
170
+ /** v2.12: Typed cognitive state projection — runtime-derived facts shipped
171
+ * with advance/status outputs. All fields are derived, zero persistence.
172
+ * Consumers: advance output (main agent), status (human/tooling), resume
173
+ * handoff. The runtime provides facts; the agent decides actions. */
174
+ export interface LoopProjection {
175
+ /** Current focus — last non-failed round's output summary. */
176
+ focus: {
177
+ what: string;
178
+ since_round: number;
179
+ } | null;
180
+ /** Suggested next steps: agent-declared intent vs compiler-derived
181
+ * pending/blocked sub-goals. Non-authoritative. */
182
+ todo: Array<{
183
+ id: string;
184
+ item: string;
185
+ reason: string;
186
+ source: "derived" | "agent_intent";
187
+ priority: number;
188
+ }>;
189
+ /** Phase boundaries from milestone history. */
190
+ phase: {
191
+ current: string;
192
+ label: string;
193
+ boundaries: Array<{
194
+ label: string;
195
+ round: number;
196
+ }>;
62
197
  } | null;
63
- requiredCommandFailures: string[];
64
- /** Whether completion evidence came from a live provider. */
65
- providerStatus: "verified" | "unavailable" | "absent";
198
+ /** Record view of the main agent's reported delegation state — facts
199
+ * only, never a task book for sub-agents. */
200
+ delegation: {
201
+ pending: number;
202
+ last_results: Array<{
203
+ agentId: string;
204
+ outcome: string;
205
+ round: number;
206
+ summary: string;
207
+ }>;
208
+ };
209
+ /** Handoff capsule for resume / process handover. `verified` holds
210
+ * cr-IDs backed by the P0 provenance layer. */
211
+ handoff: {
212
+ summary: string;
213
+ verified: string[];
214
+ open_risks: string[];
215
+ };
216
+ }
217
+ export declare function makeLoopProjection(overrides?: Partial<LoopProjection>): LoopProjection;
218
+ /** v2.12: Structured high-risk action descriptor (internal — audit display
219
+ * and gate classification). The MCP surface uses a flat gate text instead. */
220
+ export interface GateActionDescriptor {
221
+ description: string;
222
+ scope: string[];
223
+ effects: Array<"workspace_write" | "production" | "credentials" | "data_migration" | "public_api" | "publish" | "payment" | "external_communication" | "network">;
224
+ reversibility: "reversible" | "recoverable" | "irreversible" | "unknown";
225
+ authorization: "agent_allowed" | "user_required" | "unknown";
66
226
  }
67
- /** Durable decision event for a derived user/agent gate. The gate itself is
68
- * rebuilt from canonical facts; only the decision is persisted. */
227
+ /** v2.12: Classified gate — user gates need human authorization, agent
228
+ * gates are resolved by the agent submitting verifiable evidence. */
229
+ export interface DerivedGate {
230
+ kind: "user" | "agent";
231
+ question?: string;
232
+ blockedScope?: string[];
233
+ allowedWork?: string[];
234
+ problem?: string;
235
+ requiredEvidence?: string[];
236
+ suggestedResolution?: string;
237
+ }
238
+ /** v2.12: A persisted user decision for a gate. The actionHash binds the
239
+ * approval to the exact canonicalized action — an edited action changes
240
+ * the hash, so stale approvals fail the gateId match automatically. */
69
241
  export interface GateDecision {
70
242
  gateId: string;
71
243
  kind: "user" | "agent";
@@ -73,141 +245,11 @@ export interface GateDecision {
73
245
  scope: string[];
74
246
  note: string;
75
247
  decidedAt: string;
76
- /** Stable hash of the structured action that was approved. */
77
248
  actionHash: string;
78
249
  }
79
- export interface RegressionObligation {
80
- id: string;
81
- description: string;
82
- sourceRound: number;
83
- evidenceRefs: string[];
84
- status: "open" | "satisfied" | "contradicted";
85
- }
86
- export type RoundOutcome = "success" | "partial" | "failed" | "blocked";
87
- export type RoundContinuation = "continue" | "stop";
88
- export interface GateActionDescriptor {
89
- description: string;
90
- scope: string[];
91
- effects: Array<"workspace_write" | "production" | "credentials" | "data_migration" | "public_api" | "publish" | "payment" | "external_communication" | "network">;
92
- reversibility: "reversible" | "recoverable" | "irreversible" | "unknown";
93
- authorization: "agent_allowed" | "user_required" | "unknown";
94
- }
95
- export interface RoundReport {
96
- format: "loopforge.round-report";
97
- outcome: RoundOutcome;
98
- continuation: RoundContinuation;
99
- summary: string;
100
- violations: string[];
101
- evidence?: EvidenceEnvelope;
102
- blocker?: {
103
- kind: "dependency" | "external" | "needs_human_input" | "agent";
104
- reason: string;
105
- references: string[];
106
- action?: GateActionDescriptor;
107
- };
108
- discoveries?: {
109
- wrongAssumptions: string[];
110
- emergedWork: string[];
111
- facts: string[];
112
- newConstraints: string[];
113
- };
114
- subGoalEvents?: {
115
- completed: string[];
116
- blocked: string[];
117
- canceled: string[];
118
- };
119
- /** Irreducible Constraint facts; unlike Focus/Todo these cannot be derived. */
120
- constraintEvents?: {
121
- retired: string[];
122
- };
123
- /** Irreducible Goal facts for correcting a criterion without replacing it silently. */
124
- criterionRevisions?: CriterionRevision[];
125
- objectiveRefinement?: string;
126
- phaseBoundaryProposal?: {
127
- label: string;
128
- reason: string;
129
- };
130
- contextRequest?: PromptRequests;
131
- /** Agent suggestion only. Runtime-derived focus and todo always win. */
132
- agentIntent?: string;
133
- /** Structured explanation used only when the runtime detects intent drift. */
134
- driftClarification?: {
135
- explanation: string;
136
- anchors: string[];
137
- };
138
- }
139
- export interface PhaseHistoryEntry {
140
- id: string;
141
- label: string;
142
- status: "active" | "completed" | "abandoned";
143
- enteredAtRound: number;
144
- closedAtRound?: number;
145
- outcome: string;
146
- evidenceRefs: string[];
147
- }
148
- export interface TodoProjection {
149
- id: string;
150
- sourceType: "verification" | "criterion" | "sub_goal" | "blocker";
151
- sourceId: string;
152
- action: string;
153
- completionSignal: string;
154
- evidenceRequirements: string[];
155
- gate: "none" | "agent" | "user";
156
- }
157
- export type DerivedGate = {
158
- kind: "user";
159
- question: string;
160
- blockedScope: string[];
161
- allowedWork: string[];
162
- } | {
163
- kind: "agent";
164
- problem: string;
165
- requiredEvidence: string[];
166
- suggestedResolution: string;
167
- };
168
- export interface HandoffProjection {
169
- goalId: string;
170
- roundId: string;
171
- phaseId?: string;
172
- focus: string;
173
- verifiedFacts: string[];
174
- unresolvedBlockers: string[];
175
- carriedConstraints: string[];
176
- failedAttempts: string[];
177
- wrongAssumptions: string[];
178
- evidenceRefs: string[];
179
- regressionObligations: RegressionObligation[];
180
- suggestedNextAction?: string;
181
- gate?: DerivedGate;
182
- }
183
- /** Narrow compiler input derived from a verified canonical report. */
184
- export interface CompilerRoundProjection {
185
- round: number;
186
- outcome: RoundOutcome;
187
- continuation: RoundContinuation;
188
- summary: string;
189
- violations: string[];
190
- evidence: EvidenceDerivedView;
191
- discoveries?: RoundReport["discoveries"];
192
- subGoalEvents?: RoundReport["subGoalEvents"];
193
- constraintEvents?: RoundReport["constraintEvents"];
194
- criterionRevisions?: RoundReport["criterionRevisions"];
195
- objectiveRefinement?: string;
196
- phaseBoundaryProposal?: RoundReport["phaseBoundaryProposal"];
197
- agentIntent?: string;
198
- /** v2.9: Model-expressed information needs carried from the report
199
- * into the next prompt compilation. Transient — never persisted. */
200
- contextRequest?: PromptRequests;
201
- }
202
- /** P5: A revision to a success criterion — the old form and the new form.
203
- * The agent proposes this when it discovers the original criterion was
204
- * wrong, unrealistic, or needs refinement. */
205
- export interface CriterionRevision {
206
- old: string;
207
- new: string;
208
- }
250
+ export declare function makeGateDecision(overrides?: Partial<GateDecision>): GateDecision;
209
251
  /** v2.9: Model-expressed information needs for the next round.
210
- * Submitted via RoundReport.contextRequest, consumed by the
252
+ * Submitted via SelfEvaluation.prompt_requests, consumed by the
211
253
  * Compiler when assembling the next prompt. Transient — each round's
212
254
  * requests apply to that round only. */
213
255
  export interface PromptRequests {
@@ -252,7 +294,7 @@ export interface MilestoneSummary {
252
294
  carried_constraints: string[];
253
295
  /** Constraints resolved during this phase. */
254
296
  resolved_constraints: string[];
255
- /** Runtime-derived verified progress at the milestone boundary. */
297
+ /** Agent's progress_estimate at the milestone boundary. */
256
298
  progress_at_boundary: number;
257
299
  /** How this milestone was created. */
258
300
  kind: "agent_declared" | "criteria_milestone" | "auto";
@@ -267,11 +309,18 @@ export interface WorkerResult {
267
309
  subTask: string;
268
310
  resultSummary: string;
269
311
  success: boolean;
312
+ /** v2.12: Declared worker outcome. When absent, derived from success
313
+ * (true → "success", false → "failed"). "partial" is explicit only. */
314
+ outcome?: "success" | "partial" | "failed";
270
315
  discoveredConstraints?: string[];
271
316
  }
317
+ export declare function makeSelfEvaluation(overrides?: Partial<SelfEvaluation>): SelfEvaluation;
318
+ /** Regex to extract a self-evaluation JSON block from agent output. */
319
+ export declare const SELF_EVAL_REGEX: RegExp;
272
320
  export interface LoopForgeRequest {
273
321
  task: string;
274
322
  mode: Mode;
323
+ feedback: ExecutionFeedback | null;
275
324
  skill_name: string | null;
276
325
  task_id: string | null;
277
326
  [key: string]: unknown;
@@ -289,6 +338,35 @@ export interface LoopObjective {
289
338
  * Each entry is the refinement text from a single round. */
290
339
  refinement_history?: string[];
291
340
  }
341
+ /** v3.2: Derived per-criterion status for the progress dashboard — the
342
+ * "goal → criteria → evidence" vertical view. Zero persistence: derived from
343
+ * vault entries each round (met/remaining reports + Jaccard sub-goal links). */
344
+ export interface CriterionStatus {
345
+ /** Stable ID derived from the criterion text (cr-XXXXXXXX). */
346
+ id: string;
347
+ /** The criterion text as declared in the objective. */
348
+ text: string;
349
+ status: "met" | "remaining" | "unknown";
350
+ /** Round when the criterion was first reported met (machine-backed). */
351
+ met_at_round?: number;
352
+ /** Sub-goals whose description matches this criterion (Jaccard). */
353
+ related_subgoal_ids: string[];
354
+ }
355
+ export declare function makeCriterionStatus(overrides?: Partial<CriterionStatus>): CriterionStatus;
356
+ /** v3.2: A deterministic "lesson learned" — a constraint or verification
357
+ * check that failed repeatedly across rounds. Rendered in the prompt to
358
+ * immunize the agent against repeating the same mistakes. Zero persistence:
359
+ * derived from vault entries each round; presentation only — never feeds
360
+ * the enforcement gate's decisions. */
361
+ export interface Lesson {
362
+ /** Constraint text or verification check name. */
363
+ text: string;
364
+ kind: "constraint_violation" | "verification_error" | "verification_warning";
365
+ /** How many rounds this lesson occurred in. */
366
+ count: number;
367
+ /** The rounds it occurred in, ascending. */
368
+ rounds: number[];
369
+ }
292
370
  export declare function makeLoopObjective(overrides?: Partial<LoopObjective>): LoopObjective;
293
371
  export interface LoopHealth {
294
372
  goal_alignment: number;
@@ -372,6 +450,61 @@ export interface TaskAlignment {
372
450
  escalation: string;
373
451
  }
374
452
  export declare function makeTaskAlignment(overrides?: Partial<TaskAlignment>): TaskAlignment;
453
+ export interface LoopRoundResult {
454
+ round: number;
455
+ success: boolean;
456
+ output_summary: string;
457
+ constraint_violations: string[];
458
+ manual_fixes_needed: string;
459
+ /** P0: Constraints discovered during this round. */
460
+ discovered_constraints?: string[];
461
+ /** P1: Objective refinement from this round. */
462
+ objective_refinement?: string;
463
+ /** P2: Sub-problems that emerged during this round. */
464
+ emerged_subtasks?: string[];
465
+ /** P4: Execution evidence from this round. */
466
+ execution_evidence?: ExecutionEvidence;
467
+ /** P5: Constraints retracted this round. */
468
+ retracted_constraints?: string[];
469
+ /** P5: Success criteria revised this round. */
470
+ revised_success_criteria?: CriterionRevision[];
471
+ /** P5: Wrong assumptions identified this round. */
472
+ wrong_assumptions?: string[];
473
+ /** Multi-agent: Delegation results from this round.
474
+ * Set from SelfEvaluation.worker_results during buildLoopRequest. */
475
+ worker_results?: WorkerResult[];
476
+ /** v1.10: Agent declared a subtask boundary in this round. */
477
+ compression_checkpoint?: boolean;
478
+ /** v1.10: Human-readable label for the checkpoint. */
479
+ checkpoint_label?: string;
480
+ /** v1.16: Agent's declared next action for the following round. */
481
+ next_action?: string;
482
+ /** v2.2: Sub-tasks completed this round. */
483
+ completed_subtasks?: string[];
484
+ /** v2.2: Sub-tasks blocked this round. */
485
+ blocked_subtasks?: string[];
486
+ /** v2.2: Sub-tasks canceled this round. */
487
+ canceled_subtasks?: string[];
488
+ /** v2.8: Agent's explanation for intent/subgoal drift detected in
489
+ * the previous round. Carried forward from SelfEvaluation. */
490
+ drift_clarification?: string;
491
+ /** v2.9: Model's information needs for the next round's prompt.
492
+ * Carried forward from SelfEvaluation. Consumed by the Compiler. */
493
+ prompt_requests?: PromptRequests;
494
+ /** v2.12: Declared tri-state outcome. Carried forward from SelfEvaluation. */
495
+ outcome?: RoundOutcome;
496
+ /** v2.12: Flat blocker description (outcome==="blocked" only). */
497
+ blocker?: string;
498
+ /** v2.12: Retroactive claims against prior rounds. */
499
+ retroactiveClaims?: {
500
+ round: number;
501
+ claim: string;
502
+ }[];
503
+ /** v2.12: Declared reason for success without machine evidence.
504
+ * Carried forward from SelfEvaluation. */
505
+ no_change_reason?: string;
506
+ }
507
+ export declare function makeLoopRoundResult(overrides?: Partial<LoopRoundResult>): LoopRoundResult;
375
508
  export interface LoopCompileRequest {
376
509
  mode: Mode;
377
510
  loop_id: string;
@@ -384,13 +517,14 @@ export interface LoopCompileRequest {
384
517
  plan_source: string | null;
385
518
  constraints_from_plan: string[];
386
519
  new_since_last_round: string;
387
- last_round_view: CompilerRoundProjection | null;
520
+ last_round_result: LoopRoundResult | null;
388
521
  force_level: string;
389
522
  health_check_interval: number;
390
523
  /** Optional context supplied explicitly by the embedding Agent. */
391
524
  external_context?: string;
392
525
  /** Maximum rounds for this loop. Used by the state file header to show
393
- * accurate progress (Round X / Y). */
526
+ * accurate progress (Round X / Y). Falls back to max_summary_rounds * 2
527
+ * when not provided (callers that don't track maxRounds). */
394
528
  max_rounds?: number;
395
529
  /** Verification findings from the previous attempt. Prompt compilation uses
396
530
  * these to select a rehydrate view and render the gate findings exactly
@@ -401,13 +535,13 @@ export interface LoopCompileRequest {
401
535
  attempt: number;
402
536
  /** Consecutive zero-commit enforcement rejections for this round. */
403
537
  consecutive_rejections: number;
404
- /** Structured enforcement guidance rendered into retry prompts. */
538
+ /** Structured enforcement feedback rendered into retry prompts. */
405
539
  rejection_notice: string;
406
540
  }
407
541
  export declare function makeLoopCompileRequest(overrides?: Partial<LoopCompileRequest>): LoopCompileRequest;
408
542
  /** Immutable record of the exact prompt delivered for one round attempt. */
409
543
  export interface PromptArtifact {
410
- format: "loopforge.prompt";
544
+ schemaVersion: 1;
411
545
  roundId: string;
412
546
  attempt: number;
413
547
  level: "l0" | "l1" | "l2";
@@ -417,19 +551,14 @@ export interface PromptArtifact {
417
551
  stateHash: string;
418
552
  basePromptVersion: string;
419
553
  includedSections: string[];
420
- omittedSections: string[];
421
554
  budgetChars: number;
422
555
  charCount: number;
423
556
  budgetExceeded: boolean;
424
- /** Vault-derived history (filled by the compiler from prior entries);
425
- * undefined when the compile path cannot resolve a value. */
426
- lastL2Round?: number;
427
- lastMeaningfulProgressRound?: number;
428
- stateAgeRounds?: number;
429
- phaseId?: string;
430
- focusId?: string;
431
- todoId?: string;
432
557
  generatedAt: number;
558
+ /** v3.2: What the rendered prompt actually presented (L1 only). Persisted
559
+ * on the lineage entry as the diff baseline for L1 collapse. Absent for
560
+ * L0/L2 compiles. */
561
+ presentedState?: PresentedStateSnapshot;
433
562
  }
434
563
  export interface LoopCompileResponse {
435
564
  status: AgentStatus;
@@ -461,40 +590,30 @@ export interface LoopCompileResponse {
461
590
  /** v2.5: Trust scores from the last 10 rounds, newest last. Empty for
462
591
  * round 1. Reconstructed from vault entries — zero new persistence. */
463
592
  agent_trust_trend?: number[];
464
- /** Rebuildable runtime projection. Kept together so derived fields cannot
465
- * be mistaken for independent response facts. */
466
- projection?: LoopCompileProjection;
593
+ /** v3.2: Derived per-criterion status (goal → criteria → evidence view).
594
+ * Zero persistence — re-derived from vault entries each round. */
595
+ criterion_statuses?: CriterionStatus[];
596
+ /** v3.2: Deterministic lessons learned (repeated violations / repeated
597
+ * verification failures). Presentation only — never feeds enforcement. */
598
+ lessons?: Lesson[];
599
+ suggested_next_task: string;
467
600
  plan_source: string | null;
468
601
  warnings: string[];
469
602
  error: string;
470
603
  /** v1.14: Content for the loop state file. Written by the caller
471
- * (SessionManager) to .loopforge/state/{loopId}-state.md.
472
- * Undefined for L0/L1 compilations — only L2 produces state file content. */
604
+ * (SessionManager or Runtime) to .loopforge/state/{loopId}-state.md.
605
+ * Present on every level when `state_file.enabled` (default true) —
606
+ * L0/L1/L2 all render it. Undefined only when the state file is
607
+ * disabled or the compile produced no prompt. */
473
608
  state_file_content?: string;
474
609
  /** Exact, hashed prompt record used by transaction replay and audit. */
475
610
  prompt_artifact?: PromptArtifact;
476
- /** Rebuildable canonical projection for status/replay consumers. */
477
- canonical_state?: Record<string, unknown>;
478
611
  }
479
612
  export declare function makeLoopCompileResponse(overrides?: Partial<LoopCompileResponse>): LoopCompileResponse;
480
- export interface LoopCompileProjection {
481
- suggestedNextAction: string;
482
- /** Accumulated, runtime-verified claim targets reconstructed from Vault. */
483
- verifiedFacts: string[];
484
- /** Evidence references supporting verifiedFacts. */
485
- verifiedEvidenceRefs: string[];
486
- /** Rebuildable regression checks accumulated from accepted evidence. */
487
- regressionObligations: RegressionObligation[];
488
- /** Claimed discoveries from the latest accepted RoundEvent. */
489
- discoveredFacts: string[];
490
- /** Current blocker facts from the latest accepted RoundEvent. */
491
- activeBlockers: string[];
492
- }
493
- export declare function makeLoopCompileProjection(overrides?: Partial<LoopCompileProjection>): LoopCompileProjection;
494
613
  /** Aggregated evidence snapshot for the state file Evidence section.
495
614
  * Four categories give the agent a clear picture of what's been confirmed,
496
615
  * what remains, what was wrong, and what's newly discovered — all derived
497
- * from accepted RoundReport events across rounds. */
616
+ * from accumulated SelfEvaluation data across rounds. */
498
617
  export interface EvidenceSnapshot {
499
618
  /** Criteria met + successful outcomes confirmed across rounds. */
500
619
  verified: string[];
@@ -516,26 +635,37 @@ export interface LoopForgeResponse {
516
635
  prompt_artifact?: PromptArtifact;
517
636
  /** Structured warnings from the compiler — preferred over parsing prompt text. */
518
637
  warnings?: string[];
519
- /** Rebuildable canonical projection for status consumers. */
520
- canonical_state?: Record<string, unknown>;
638
+ /** v2.12: Compiler-derived state passed through for typed projections
639
+ * (zero extra persistence — derived fresh each compile). */
640
+ rolling_summary?: RollingSummary | null;
641
+ sub_goals?: SubGoal[];
642
+ suggested_next_task?: string;
521
643
  }
522
644
  export interface SessionState {
523
645
  task_id: string;
646
+ call_count: number;
647
+ success_trend: boolean[];
648
+ current_version: string;
649
+ feedback_buffer: Record<string, unknown>[];
524
650
  }
525
651
  export declare function makeSessionState(taskId: string): SessionState;
526
652
  export interface AgentLoopResult {
527
653
  status: AgentStatus;
528
654
  response: LoopForgeResponse | null;
529
655
  }
530
- /** Why a loop stopped. Used by MCP session and vault persistence. */
656
+ /** Why a loop stopped. Used by MCP session and vault persistence.
657
+ * `completed` requires both success=true and should_continue=false.
658
+ * `failed` is success=false + should_continue=false (agent gave up).
659
+ * `cancelled` is manual stop via loopforge_stop.
660
+ * Legacy aliases (backward-compat): `task_complete` → `completed`, `stopped` → `cancelled`. */
531
661
  export type StopReason = "completed" | "failed" | "blocked" | "cancelled" | "max_rounds" | "circuit_breaker" | "stalled" | "executor_failure" | "enforcement_terminated"
532
662
  /** v1.18: Loop was paused by user or signal. */
533
- | "paused";
663
+ | "paused" | "task_complete" | "stopped";
534
664
  /** Result of round-boundary enforcement. Decides whether to accept the round,
535
665
  * reject it (force the agent to redo the SAME round), or terminate the loop.
536
666
  *
537
667
  * accept: round passes; proceed to next round as normal.
538
- * reject: agent's round report or output is invalid; the agent receives
668
+ * reject: agent's self-evaluation or output is invalid; the agent receives
539
669
  * a rejection prompt and must redo the same round. Round counter
540
670
  * does NOT increment.
541
671
  * terminate: loop has reached an unrecoverable state; stop immediately with
@@ -555,8 +685,6 @@ export interface EnforcementResult {
555
685
  * drift_clarification waiver (R7). The caller uses this to track
556
686
  * clarification streaks independently of rejection streaks. */
557
687
  clarification_accepted?: boolean;
558
- /** True when a terminal rule was converted into one final escalated reject. */
559
- escalation_issued?: boolean;
560
688
  }
561
689
  export declare function makeEnforcementResult(overrides?: Partial<EnforcementResult>): EnforcementResult;
562
690
  /** Context supplied to an embedding-owned provider before compilation. */
@@ -565,8 +693,8 @@ export interface ExternalContextRequest {
565
693
  round: number;
566
694
  task: string;
567
695
  domain: string;
568
- /** The previously accepted compiler view, when one exists. */
569
- lastRoundView?: CompilerRoundProjection;
696
+ /** The previously accepted evaluation, when one exists. */
697
+ lastEvaluation?: SelfEvaluation;
570
698
  }
571
699
  export type ExternalContextProvider = (request: ExternalContextRequest) => Promise<string>;
572
700
  export interface LoopTerminalEvent {
@@ -576,16 +704,16 @@ export interface LoopTerminalEvent {
576
704
  successTrajectory: boolean[];
577
705
  loopId: string;
578
706
  task: string;
579
- lastRoundView?: CompilerRoundProjection;
707
+ lastEvaluation?: SelfEvaluation;
580
708
  }
581
709
  export type LoopTerminalSink = (event: LoopTerminalEvent) => Promise<void> | void;
582
- /** A single flag raised during round report verification.
710
+ /** A single flag raised during self-evaluation verification.
583
711
  * Each flag identifies a specific inconsistency between the agent's
584
712
  * self-reported data and the loop's cross-round lineage. */
585
713
  export interface VerificationFlag {
586
714
  /** info | warn | error — determines how aggressively the compiler reacts. */
587
715
  severity: "info" | "warn" | "error";
588
- /** Stable report or evidence path that triggered this flag. */
716
+ /** Which SelfEvaluation field triggered this flag (e.g. "progress_estimate"). */
589
717
  field: string;
590
718
  /** Check name for debugging / audit (e.g. "progress_regression"). */
591
719
  check: string;
@@ -593,7 +721,7 @@ export interface VerificationFlag {
593
721
  detail: string;
594
722
  }
595
723
  export declare function makeVerificationFlag(overrides?: Partial<VerificationFlag>): VerificationFlag;
596
- /** Result of cross-round round report verification.
724
+ /** Result of cross-round self-evaluation verification.
597
725
  *
598
726
  * Verdict semantics:
599
727
  * - trusted: all checks passed; flags are informational only.