loopforge 1.3.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/backends/fs.d.ts +5 -0
  2. package/dist/backends/fs.d.ts.map +1 -1
  3. package/dist/backends/fs.js +66 -16
  4. package/dist/backends/fs.js.map +1 -1
  5. package/dist/builder.d.ts +0 -1
  6. package/dist/builder.d.ts.map +1 -1
  7. package/dist/builder.js +14 -25
  8. package/dist/builder.js.map +1 -1
  9. package/dist/engine.d.ts +14 -5
  10. package/dist/engine.d.ts.map +1 -1
  11. package/dist/engine.js +202 -105
  12. package/dist/engine.js.map +1 -1
  13. package/dist/index.d.ts +4 -8
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +4 -9
  16. package/dist/index.js.map +1 -1
  17. package/dist/loop-compiler.d.ts +5 -2
  18. package/dist/loop-compiler.d.ts.map +1 -1
  19. package/dist/loop-compiler.js +533 -19
  20. package/dist/loop-compiler.js.map +1 -1
  21. package/dist/mcp/session.d.ts +11 -3
  22. package/dist/mcp/session.d.ts.map +1 -1
  23. package/dist/mcp/session.js +106 -31
  24. package/dist/mcp/session.js.map +1 -1
  25. package/dist/mcp/tools.d.ts +133 -0
  26. package/dist/mcp/tools.d.ts.map +1 -1
  27. package/dist/mcp/tools.js +116 -6
  28. package/dist/mcp/tools.js.map +1 -1
  29. package/dist/observability.d.ts +23 -0
  30. package/dist/observability.d.ts.map +1 -0
  31. package/dist/observability.js +29 -0
  32. package/dist/observability.js.map +1 -0
  33. package/dist/policy.d.ts +15 -0
  34. package/dist/policy.d.ts.map +1 -1
  35. package/dist/policy.js +8 -0
  36. package/dist/policy.js.map +1 -1
  37. package/dist/protocol.d.ts +114 -5
  38. package/dist/protocol.d.ts.map +1 -1
  39. package/dist/protocol.js +44 -3
  40. package/dist/protocol.js.map +1 -1
  41. package/dist/runtime.d.ts +2 -0
  42. package/dist/runtime.d.ts.map +1 -1
  43. package/dist/runtime.js +51 -3
  44. package/dist/runtime.js.map +1 -1
  45. package/dist/tests/builder.test.js +1 -25
  46. package/dist/tests/builder.test.js.map +1 -1
  47. package/dist/tests/engine.test.js +213 -38
  48. package/dist/tests/engine.test.js.map +1 -1
  49. package/dist/tests/generate-schema.test.js +4 -4
  50. package/dist/tests/generate-schema.test.js.map +1 -1
  51. package/dist/tests/loop-compiler.test.js +191 -2
  52. package/dist/tests/loop-compiler.test.js.map +1 -1
  53. package/dist/tests/mcp.test.js +87 -0
  54. package/dist/tests/mcp.test.js.map +1 -1
  55. package/dist/tests/protocol.test.js +2 -4
  56. package/dist/tests/protocol.test.js.map +1 -1
  57. package/dist/tests/verification-gate.test.d.ts +2 -0
  58. package/dist/tests/verification-gate.test.d.ts.map +1 -0
  59. package/dist/tests/verification-gate.test.js +407 -0
  60. package/dist/tests/verification-gate.test.js.map +1 -0
  61. package/dist/verification-gate.d.ts +26 -0
  62. package/dist/verification-gate.d.ts.map +1 -0
  63. package/dist/verification-gate.js +232 -0
  64. package/dist/verification-gate.js.map +1 -0
  65. package/loop_policy.json +8 -0
  66. package/package.json +1 -2
  67. package/skills/perception/SKILL.md +95 -54
  68. package/dist/cli.d.ts +0 -7
  69. package/dist/cli.d.ts.map +0 -1
  70. package/dist/cli.js +0 -458
  71. package/dist/cli.js.map +0 -1
  72. package/dist/tests/adapter.test.js +0 -104
  73. package/dist/tests/adapter.test.js.map +0 -1
@@ -0,0 +1,232 @@
1
+ /** Verification Gate — Layer 1 cross-round consistency checks.
2
+ *
3
+ * Pure-function module. Validates an agent's SelfEvaluation against the
4
+ * loop's own lineage before it enters the compiler.
5
+ *
6
+ * Verdict semantics:
7
+ * - trusted: all checks passed; flags are informational only.
8
+ * - suspect: one or more warn-level flags; flags become warnings in
9
+ * the next prompt so the agent can clarify.
10
+ * - contradicted: one or more error-level flags; the quality score for
11
+ * this round is excluded from the quality trend (NOT
12
+ * modified). Flags become hard constraints — the agent
13
+ * must respond in the next round.
14
+ */
15
+ import { makeVerificationFlag, makeVerificationResult } from "./protocol.js";
16
+ // ═══════════════════════════════════════════════════════════════════════════
17
+ // Helpers
18
+ // ═══════════════════════════════════════════════════════════════════════════
19
+ /** Extract the round number from a vault entry's loop_lineage.
20
+ * Returns 0 if the entry has no lineage or no round field.
21
+ * In practice, persistLoopLineage always writes round ≥ 1, so 0
22
+ * unambiguously means "not a valid round entry" in this context. */
23
+ function entryRound(entry) {
24
+ const lineage = (entry.loop_lineage ?? {});
25
+ return lineage.round ?? 0;
26
+ }
27
+ /** Read constraint_violations from a vault entry (entry-level, stored from
28
+ * the previous round's last_round_result at persist time). */
29
+ function entryViolations(entry) {
30
+ const viols = entry.constraint_violations;
31
+ if (Array.isArray(viols))
32
+ return viols.filter((v) => typeof v === "string");
33
+ return [];
34
+ }
35
+ // ═══════════════════════════════════════════════════════════════════════════
36
+ // Individual checks — each returns a VerificationFlag or null
37
+ // ═══════════════════════════════════════════════════════════════════════════
38
+ function checkProgressRegression(selfEval, prevSelfEval) {
39
+ if (!prevSelfEval?.execution_evidence)
40
+ return null;
41
+ if (!selfEval.execution_evidence)
42
+ return null;
43
+ const prevProgress = prevSelfEval.execution_evidence.progress_estimate;
44
+ const currProgress = selfEval.execution_evidence.progress_estimate;
45
+ if (typeof prevProgress !== "number" || typeof currProgress !== "number")
46
+ return null;
47
+ // Use delta with epsilon to avoid IEEE 754 rounding issues (0.8 - 0.2 > 0.6 in float)
48
+ if (prevProgress - currProgress <= 0.2 + 1e-10)
49
+ return null;
50
+ return makeVerificationFlag({
51
+ severity: "warn",
52
+ field: "progress_estimate",
53
+ check: "progress_regression",
54
+ detail: `Progress dropped from ${prevProgress.toFixed(2)} to ` +
55
+ `${currProgress.toFixed(2)} (delta: ${(currProgress - prevProgress).toFixed(2)})`,
56
+ });
57
+ }
58
+ function checkEmptyChangeWithPassing(selfEval) {
59
+ const ev = selfEval.execution_evidence;
60
+ if (!ev)
61
+ return null;
62
+ const filesEmpty = ev.files_changed.length === 0;
63
+ const testsAllPass = ev.test_results !== null &&
64
+ ev.test_results.failed === 0 &&
65
+ ev.test_results.passed > 0;
66
+ if (!filesEmpty || !testsAllPass || !selfEval.success)
67
+ return null;
68
+ return makeVerificationFlag({
69
+ severity: "warn",
70
+ field: "execution_evidence",
71
+ check: "empty_change_with_passing",
72
+ detail: "Agent claims success with no files changed and all tests passing — " +
73
+ "verify that work was actually performed",
74
+ });
75
+ }
76
+ function checkSuccessWithRemainingCriteria(selfEval) {
77
+ if (!selfEval.success)
78
+ return null;
79
+ const remaining = selfEval.execution_evidence?.success_criteria_remaining;
80
+ if (!remaining || remaining.length === 0)
81
+ return null;
82
+ return makeVerificationFlag({
83
+ severity: "error",
84
+ field: "success",
85
+ check: "success_with_remaining_criteria",
86
+ detail: `Agent claims success but ${remaining.length} criteria remain unmet: ` +
87
+ remaining.slice(0, 3).join("; "),
88
+ });
89
+ }
90
+ function checkDuplicateConstraintDiscovery(selfEval, prevSelfEval, olderViolations) {
91
+ const discovered = selfEval.discovered_constraints;
92
+ if (!discovered || discovered.length === 0)
93
+ return null;
94
+ // Collect all previously-known constraints
95
+ const known = new Set();
96
+ for (const v of olderViolations)
97
+ known.add(v.toLowerCase().trim());
98
+ if (prevSelfEval) {
99
+ for (const d of prevSelfEval.discovered_constraints ?? []) {
100
+ known.add(d.toLowerCase().trim());
101
+ }
102
+ // Also treat previous violations as implicitly discovered
103
+ for (const v of prevSelfEval.constraint_violations) {
104
+ known.add(v.toLowerCase().trim());
105
+ }
106
+ }
107
+ for (const d of discovered) {
108
+ if (known.has(d.toLowerCase().trim())) {
109
+ return makeVerificationFlag({
110
+ severity: "warn",
111
+ field: "discovered_constraints",
112
+ check: "duplicate_constraint_discovery",
113
+ detail: `Constraint "${d}" was already known from a previous round`,
114
+ });
115
+ }
116
+ }
117
+ return null;
118
+ }
119
+ function checkRecurringViolation(selfEval, prevSelfEval, vaultEntries, currentRound) {
120
+ const currViols = selfEval.constraint_violations;
121
+ if (!currViols || currViols.length === 0)
122
+ return null;
123
+ // Build the violation history: [round N-2, round N-1, round N]
124
+ const violationsByRound = [];
125
+ // Round N-2 violations come from the vault entry for round N-1
126
+ // (persistLoopLineage stores the PREVIOUS round's violations on each entry)
127
+ if (currentRound >= 3) {
128
+ const entryNMinus1 = vaultEntries.find((e) => entryRound(e) === currentRound - 1);
129
+ if (entryNMinus1) {
130
+ const viols = entryViolations(entryNMinus1);
131
+ if (viols.length)
132
+ violationsByRound.push(viols.map((v) => v.toLowerCase().trim()));
133
+ }
134
+ }
135
+ // Round N-1 violations from prevSelfEval
136
+ if (prevSelfEval) {
137
+ const prevViols = prevSelfEval.constraint_violations;
138
+ violationsByRound.push(prevViols.map((v) => v.toLowerCase().trim()));
139
+ }
140
+ // Round N violations from current selfEval
141
+ violationsByRound.push(currViols.map((v) => v.toLowerCase().trim()));
142
+ // Need at least 3 rounds of data
143
+ if (violationsByRound.length < 3)
144
+ return null;
145
+ // Check each current violation against the previous 2 rounds
146
+ const [rNMinus2, rNMinus1, rN] = violationsByRound.slice(-3);
147
+ for (const v of rN) {
148
+ if (rNMinus1.includes(v) && rNMinus2.includes(v)) {
149
+ return makeVerificationFlag({
150
+ severity: "error",
151
+ field: "constraint_violations",
152
+ check: "recurring_violation",
153
+ detail: `Constraint violation "${v}" has appeared in 3 consecutive rounds ` +
154
+ `(rounds ${currentRound - 2}–${currentRound}) without resolution`,
155
+ });
156
+ }
157
+ }
158
+ return null;
159
+ }
160
+ function checkRetractFreshConstraint(selfEval, prevSelfEval, currentRound) {
161
+ const retracted = selfEval.retracted_constraints;
162
+ if (!retracted || retracted.length === 0)
163
+ return null;
164
+ if (!prevSelfEval)
165
+ return null;
166
+ const lastRoundDiscoveries = new Set();
167
+ for (const d of prevSelfEval.discovered_constraints ?? []) {
168
+ lastRoundDiscoveries.add(d.toLowerCase().trim());
169
+ }
170
+ for (const r of retracted) {
171
+ if (lastRoundDiscoveries.has(r.toLowerCase().trim())) {
172
+ return makeVerificationFlag({
173
+ severity: "warn",
174
+ field: "retracted_constraints",
175
+ check: "retract_fresh_constraint",
176
+ detail: `Retracting constraint "${r}" that was just discovered in round ` +
177
+ `${currentRound - 1} — may indicate rapid flip-flopping`,
178
+ });
179
+ }
180
+ }
181
+ return null;
182
+ }
183
+ // ═══════════════════════════════════════════════════════════════════════════
184
+ // Main entry point
185
+ // ═══════════════════════════════════════════════════════════════════════════
186
+ /** Verify a SelfEvaluation against the loop's cross-round lineage.
187
+ *
188
+ * @param selfEval The agent's self-evaluation for the current round.
189
+ * @param currentRound The current round number (1-based).
190
+ * @param vaultEntries Vault entries for this loop (non-feedback only).
191
+ * @param prevSelfEval The agent's self-evaluation from the previous round
192
+ * (null for round 1).
193
+ */
194
+ export function verifySelfEvaluation(selfEval, currentRound, vaultEntries, prevSelfEval = null) {
195
+ const flags = [];
196
+ // Collect violations from all previous vault entries for duplicate-discovery
197
+ // and other checks that need deeper history.
198
+ const olderViolations = [];
199
+ for (const entry of vaultEntries) {
200
+ for (const v of entryViolations(entry))
201
+ olderViolations.push(v);
202
+ }
203
+ // Run all checks
204
+ const checks = [
205
+ () => checkProgressRegression(selfEval, prevSelfEval),
206
+ () => checkEmptyChangeWithPassing(selfEval),
207
+ () => checkSuccessWithRemainingCriteria(selfEval),
208
+ () => checkDuplicateConstraintDiscovery(selfEval, prevSelfEval, olderViolations),
209
+ () => checkRecurringViolation(selfEval, prevSelfEval, vaultEntries, currentRound),
210
+ () => checkRetractFreshConstraint(selfEval, prevSelfEval, currentRound),
211
+ ];
212
+ for (const run of checks) {
213
+ const flag = run();
214
+ if (flag)
215
+ flags.push(flag);
216
+ }
217
+ // Determine verdict from the most severe flag present
218
+ const hasError = flags.some((f) => f.severity === "error");
219
+ const hasWarn = flags.some((f) => f.severity === "warn");
220
+ let verdict;
221
+ if (hasError) {
222
+ verdict = "contradicted";
223
+ }
224
+ else if (hasWarn) {
225
+ verdict = "suspect";
226
+ }
227
+ else {
228
+ verdict = "trusted";
229
+ }
230
+ return makeVerificationResult({ verdict, flags });
231
+ }
232
+ //# sourceMappingURL=verification-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification-gate.js","sourceRoot":"","sources":["../src/verification-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE7E,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;qEAGqE;AACrE,SAAS,UAAU,CAAC,KAAiB;IACnC,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAA4B,CAAC;IACtE,OAAQ,OAAO,CAAC,KAAgB,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;+DAC+D;AAC/D,SAAS,eAAe,CAAC,KAAiB;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,qBAAqB,CAAC;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IACrF,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,8EAA8E;AAC9E,8DAA8D;AAC9D,8EAA8E;AAE9E,SAAS,uBAAuB,CAC9B,QAAwB,EACxB,YAAmC;IAEnC,IAAI,CAAC,YAAY,EAAE,kBAAkB;QAAE,OAAO,IAAI,CAAC;IACnD,IAAI,CAAC,QAAQ,CAAC,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAE9C,MAAM,YAAY,GAAG,YAAY,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;IACvE,MAAM,YAAY,GAAG,QAAQ,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;IAEnE,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,OAAO,YAAY,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACtF,sFAAsF;IACtF,IAAI,YAAY,GAAG,YAAY,IAA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,CAAC;QACjF,GAAG,EAAE,CAAC,2BAA2B,CAAC,QAAQ,EAAE,YAAY,EAAE,YAAY,CAAC;KACxE,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;QACnB,IAAI,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,sDAAsD;IACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC;IAEzD,IAAI,OAAsC,CAAC;IAC3C,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,GAAG,cAAc,CAAC;IAC3B,CAAC;SAAM,IAAI,OAAO,EAAE,CAAC;QACnB,OAAO,GAAG,SAAS,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,SAAS,CAAC;IACtB,CAAC;IAED,OAAO,sBAAsB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AACpD,CAAC"}
package/loop_policy.json CHANGED
@@ -47,5 +47,13 @@
47
47
  "backend": {
48
48
  "vault_path": ".promptcraft/prompt_vault.json",
49
49
  "global_vault_path": "~/.promptcraft/global_vault.json"
50
+ },
51
+ "evolution": {
52
+ "max_discovered_constraints_per_round": 5,
53
+ "max_active_constraints": 15,
54
+ "max_objective_versions": 10,
55
+ "progress_stall_threshold": 0.05,
56
+ "progress_stall_rounds": 2,
57
+ "progress_mismatch_threshold": 0.3
50
58
  }
51
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopforge",
3
- "version": "1.3.1",
3
+ "version": "1.7.0",
4
4
  "description": "Loop-Time Intelligence Layer for AI coding agents — per-iteration prompt compiler with structured memory, constraint inheritance, and drift correction.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,6 @@
24
24
  }
25
25
  },
26
26
  "bin": {
27
- "loopforge": "./dist/cli.js",
28
27
  "loopforge-mcp": "./dist/mcp-server.js"
29
28
  },
30
29
  "files": [
@@ -16,7 +16,7 @@ beyond having `loopforge-mcp` registered as an MCP server.
16
16
  ## When to Activate
17
17
 
18
18
  Activate when the user says any of:
19
- - `/loop <task>` — start an autonomous multi-round loop
19
+ - `/perception <task>` — start an autonomous multi-round loop
20
20
  - "do this in a loop", "keep going until done", "iterate on this"
21
21
  - Any task that clearly needs 3+ rounds (audit, refactor, migrate, review-and-fix cycles)
22
22
 
@@ -26,20 +26,20 @@ round (e.g. "audit the entire codebase and fix every issue").
26
26
  ## Core Workflow
27
27
 
28
28
  ```
29
- ┌─────────────────────────────────────────────────────┐
30
- │ 1. loopforge_start(task, constraints, maxRounds) │
31
- │ → sessionId + Round 1 prompt │
32
- │ │
33
- │ 2. Execute the prompt (read, write, test, fix) │
34
- │ MUST include ---loopforge-eval block in output │
35
- │ │
36
- │ 3. loopforge_next(sessionId, output) │
37
- │ → if prompt: go to step 2 │
38
- │ → if prompt=null: loop ended, read stopReason │
39
- │ │
40
- │ After restart: loopforge_resume(loopId) │
41
- │ → picks up from last saved round │
42
- └─────────────────────────────────────────────────────┘
29
+ ┌──────────────────────────────────────────────────────────┐
30
+ │ 1. loopforge_start(task, constraints, maxRounds) │
31
+ │ → sessionId + Round 1 prompt │
32
+ │ │
33
+ │ 2. Execute the prompt (read, write, test, fix) │
34
+ │ Prepare a structured self-evaluation │
35
+ │ │
36
+ │ 3. loopforge_next(sessionId, evaluation, output?) │
37
+ │ → if prompt: go to step 2 │
38
+ │ → if prompt=null: loop ended, read stopReason │
39
+ │ │
40
+ │ After restart: loopforge_resume(loopId) │
41
+ │ → picks up from last saved round │
42
+ └──────────────────────────────────────────────────────────┘
43
43
  ```
44
44
 
45
45
  ### Step-by-step
@@ -60,18 +60,38 @@ Execute the compiled prompt exactly as you would any user task. Read files,
60
60
  write code, run tests, fix bugs. The prompt already contains the task scope,
61
61
  constraints, and quality expectations for this specific round.
62
62
 
63
- **CRITICAL: Every round's output MUST end with a self-evaluation block:**
64
- ```
65
- ---loopforge-eval
63
+ After executing, prepare a structured self-evaluation. Pass it as the
64
+ `evaluation` parameter to `loopforge_next` — do NOT embed it as a text block
65
+ in the output. The `evaluation` parameter is a typed object with the fields
66
+ described below.
67
+
68
+ **New (v1.7+): Pass evaluation as a structured tool parameter.**
69
+ ```json
66
70
  {
67
71
  "success": true,
68
72
  "output_summary": "Fixed 3 reentrancy bugs in withdraw() and deposit(). All 12 tests pass.",
69
73
  "constraint_violations": [],
70
- "should_continue": true
74
+ "should_continue": true,
75
+ "discovered_constraints": [],
76
+ "objective_refinement": "",
77
+ "emerged_subtasks": [],
78
+ "execution_evidence": {
79
+ "files_changed": ["contracts/Token.sol", "test/Token.test.ts"],
80
+ "test_results": {"passed": 24, "failed": 0, "skipped": 0},
81
+ "success_criteria_met": ["No reentrancy vectors remain"],
82
+ "success_criteria_remaining": ["Access control verified", "Overflow checks complete"],
83
+ "progress_estimate": 0.4
84
+ },
85
+ "retracted_constraints": [],
86
+ "revised_success_criteria": [],
87
+ "wrong_assumptions": []
71
88
  }
72
- ---end-loopforge-eval
73
89
  ```
74
90
 
91
+ **Legacy (still supported):** Embed a `---loopforge-eval` block in output text
92
+ when the agent cannot pass structured tool parameters. The new parameter form
93
+ is preferred — it's validated by the MCP client before reaching the server.
94
+
75
95
  **Field rules:**
76
96
 
77
97
  | Field | Type | Rule |
@@ -80,24 +100,36 @@ constraints, and quality expectations for this specific round.
80
100
  | `output_summary` | string | Specific, actionable. What was DONE this round — not what was attempted |
81
101
  | `constraint_violations` | string[] | Constraints the agent actually violated this round. Be honest — hiding violations corrupts the quality signal and defeats the circuit breaker |
82
102
  | `should_continue` | boolean | `false` ONLY when the ENTIRE task is complete. Partial progress = `true` |
83
-
84
- **Why this matters:** Without a valid `---loopforge-eval` block, extraction
85
- fails and the loop stops with `stopReason: stalled`. The circuit breaker
86
- uses `success` + `violations` to compute quality scores — lying here defeats
87
- the only mechanism that prevents infinite loops.
103
+ | `discovered_constraints` | string[] | **P0 (optional)** — New constraints discovered this round. They become active guardrails for future rounds. Example: `["All external calls must use SafeERC20"]`. Empty `[]` if none. |
104
+ | `objective_refinement` | string | **P1 (optional)** — If this round deepened your understanding of what the task is really about, describe the refinement. APPENDED to (never replaces) the original objective. Empty `""` if unchanged. |
105
+ | `emerged_subtasks` | string[] | **P2 (optional)** — Sub-problems that surfaced during execution and need separate attention. Feed into next-round task suggestions. Example: `["Audit upgrade proxy", "Verify timelock"]`. Empty `[]` if none. |
106
+ | `execution_evidence` | object | **P4 (recommended)** — Structured record of what actually happened. `files_changed` (string[]), `test_results` ({passed, failed, skipped} | null), `success_criteria_met` (string[]), `success_criteria_remaining` (string[]), `progress_estimate` (0.0–1.0). Use this to give LoopForge real visibility into your progress. |
107
+ | `retracted_constraints` | string[] | **P5 (optional)** — Constraints you now believe are wrong. Removed from active guardrails. Only retract with evidence. Empty `[]` if none. |
108
+ | `revised_success_criteria` | object[] | **P5 (optional)** — Success criteria that need reformulation. Array of `{old: string, new: string}`. Applied to Loop Objective. Empty `[]` if none. |
109
+ | `wrong_assumptions` | string[] | **P5 (optional)** — Assumptions from earlier rounds that turned out to be incorrect. Recorded as key lessons. Empty `[]` if none. |
110
+
111
+ **Why this matters:** The evaluation is validated by the MCP client before
112
+ reaching the server — a missing or malformed evaluation causes an immediate
113
+ error, not a silent stall. The circuit breaker uses `success` + `violations`
114
+ to compute quality scores — lying here defeats the only mechanism that
115
+ prevents infinite loops. The optional fields (P0–P5) enable cognitive
116
+ evolution: discovering constraints, deepening understanding, surfacing
117
+ sub-problems, tracking real progress, and correcting wrong assumptions as
118
+ the loop executes.
88
119
 
89
120
  **Step 3 — Advance to next round:**
90
121
  ```
91
122
  Call loopforge_next with:
92
- sessionId: from loopforge_start
93
- output: your FULL output from this round (including the eval block)
123
+ sessionId: from loopforge_start
124
+ evaluation: REQUIRED — structured self-evaluation object (see field table below)
125
+ output: OPTIONAL — raw output text for audit trail (can be omitted)
94
126
  ```
95
127
 
96
128
  If the result has `prompt: null`, the loop has ended. Read `stopReason`:
97
129
  - `task_complete` — you reported should_continue=false. Work is done.
98
130
  - `circuit_breaker` — quality flat or declining for 3+ rounds. Review your approach.
99
131
  - `max_rounds` — hit the round limit. Decide whether to extend or accept.
100
- - `stalled` — no valid self-eval block found. Check your output format.
132
+ - `stalled` — no valid self-evaluation provided. Check your evaluation parameter.
101
133
 
102
134
  If the result has a non-null `prompt`, execute it and repeat from Step 2.
103
135
 
@@ -138,7 +170,8 @@ The prompt changes between rounds based on your trajectory. Pay attention to:
138
170
 
139
171
  ## Rules
140
172
 
141
- 1. **Never skip the eval block.** No exceptions. If you forget, the loop stalls.
173
+ 1. **Always pass the evaluation parameter.** `loopforge_next` requires it.
174
+ If you omit it, the MCP client will reject the call with a schema error.
142
175
  2. **Be honest in self-evaluation.** Lying about success or hiding violations
143
176
  produces a false quality signal. The circuit breaker exists to stop bad
144
177
  loops — if you fake quality=5 every round, it fires anyway.
@@ -154,7 +187,7 @@ The prompt changes between rounds based on your trajectory. Pay attention to:
154
187
  ## Example
155
188
 
156
189
  ```
157
- User: /loop "Audit the ERC20 token in contracts/Token.sol for security issues"
190
+ User: /perception "Audit the ERC20 token in contracts/Token.sol for security issues"
158
191
 
159
192
  Agent:
160
193
  → loopforge_start({ task: "Audit ERC20 token in contracts/Token.sol for security issues",
@@ -162,33 +195,41 @@ Agent:
162
195
  constraints: ["must not break existing tests", "follow check-effects-interactions"] })
163
196
  ← { sessionId: "abc-123", round: 1, prompt: "## LoopForge Loop Compile — Round 1\n...", level: "l2" }
164
197
 
165
- [Executes prompt: reads Token.sol, identifies 4 issues, writes audit notes]
166
-
167
- Output ends with:
168
- ---loopforge-eval
169
- {"success":false,"output_summary":"Found 4 potential issues: 2 reentrancy, 1 overflow, 1 access control. Not yet fixed.","constraint_violations":[],"should_continue":true}
170
- ---end-loopforge-eval
198
+ [Executes prompt: reads Token.sol, identifies 4 issues, discovers a new constraint]
171
199
 
172
- → loopforge_next({ sessionId: "abc-123", output: <full output> })
200
+ → loopforge_next({ sessionId: "abc-123",
201
+ evaluation: {
202
+ success: false,
203
+ output_summary: "Found 4 potential issues: 2 reentrancy, 1 overflow, 1 access control. Not yet fixed.",
204
+ constraint_violations: [],
205
+ should_continue: true,
206
+ discovered_constraints: ["All _mint() calls must emit Transfer event per ERC20 spec"]
207
+ } })
173
208
  ← { sessionId: "abc-123", round: 2, prompt: "## LoopForge Loop Compile — Round 2\n...", level: "l1" }
174
209
 
175
- [Executes prompt: fixes 3 issues, 1 needs more investigation]
176
-
177
- ---loopforge-eval
178
- {"success":false,"output_summary":"Fixed reentrancy in withdraw() and overflow in calcReward(). Access control issue in setOwner() needs design discussion.","constraint_violations":[],"should_continue":true}
179
- ---end-loopforge-eval
180
-
181
- → loopforge_next({ sessionId: "abc-123", output: <full output> })
182
- ← { sessionId: "abc-123", round: 3, prompt: "## LoopForge Loop Compile — Round 3\n...", level: "l0" }
183
-
184
- [Executes prompt: documents access control issue for user decision, all fixes pass tests]
185
-
186
- ---loopforge-eval
187
- {"success":true,"output_summary":"All fixable issues resolved. 1 access control design question flagged for user. 24/24 tests pass.","constraint_violations":[],"should_continue":false}
188
- ---end-loopforge-eval
189
-
190
- → loopforge_next({ sessionId: "abc-123", output: <full output> })
210
+ [Executes prompt: fixes 3 issues, deepens understanding of access control problem]
211
+
212
+ → loopforge_next({ sessionId: "abc-123",
213
+ evaluation: {
214
+ success: false,
215
+ output_summary: "Fixed reentrancy in withdraw() and overflow in calcReward(). Access control in setOwner() needs design discussion — discovered it's part of a larger upgradeability concern.",
216
+ constraint_violations: [],
217
+ should_continue: true,
218
+ objective_refinement: "Access control audit scope expanded: setOwner() is unprotected because the contract follows an upgradeable proxy pattern where owner is set via initializer — need to verify the initializer guard and proxy admin separately",
219
+ emerged_subtasks: ["Audit upgrade proxy initialization flow", "Verify proxy admin is not renounced without recovery path"]
220
+ } })
221
+ ← { sessionId: "abc-123", round: 3, prompt: "## LoopForge Loop Compile — Round 3\n Suggested Next Task: Audit upgrade proxy initialization flow; Verify proxy admin is not renounced without recovery path\n...", level: "l0" }
222
+
223
+ [Executes prompt: audits proxy pattern, documents findings, all fixes pass tests]
224
+
225
+ → loopforge_next({ sessionId: "abc-123",
226
+ evaluation: {
227
+ success: true,
228
+ output_summary: "All fixable issues resolved. Proxy initialization verified — initializer modifier prevents double-init. Proxy admin held by multisig — low risk. 24/24 tests pass.",
229
+ constraint_violations: [],
230
+ should_continue: false
231
+ } })
191
232
  ← { sessionId: "abc-123", round: 3, prompt: null, stopReason: "task_complete", quality: 5 }
192
233
 
193
- Reports to user: "Audit complete in 3 rounds. 3 issues fixed, 1 design question flagged."
234
+ Reports to user: "Audit complete in 3 rounds. 3 issues fixed, 1 design question flagged. Discovered 1 new constraint during audit. Objective deepened to include proxy pattern verification."
194
235
  ```
package/dist/cli.d.ts DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- /** LoopForge CLI — command-line interface for the loop compiler.
3
- *
4
- * v1.2 — npm install loopforge
5
- */
6
- export {};
7
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG"}