loopforge 1.12.0 → 2.0.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 (182) hide show
  1. package/README.md +172 -95
  2. package/dist/backends/interface.d.ts +3 -9
  3. package/dist/backends/interface.d.ts.map +1 -1
  4. package/dist/backends/interface.js +1 -5
  5. package/dist/backends/interface.js.map +1 -1
  6. package/dist/canonical-state.d.ts +53 -0
  7. package/dist/canonical-state.d.ts.map +1 -0
  8. package/dist/canonical-state.js +161 -0
  9. package/dist/canonical-state.js.map +1 -0
  10. package/dist/cli.d.ts +4 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +227 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/enforcement-gate.d.ts +44 -0
  15. package/dist/enforcement-gate.d.ts.map +1 -0
  16. package/dist/enforcement-gate.js +271 -0
  17. package/dist/enforcement-gate.js.map +1 -0
  18. package/dist/engine.d.ts +17 -7
  19. package/dist/engine.d.ts.map +1 -1
  20. package/dist/engine.js +158 -249
  21. package/dist/engine.js.map +1 -1
  22. package/dist/evidence-provider.d.ts +113 -0
  23. package/dist/evidence-provider.d.ts.map +1 -0
  24. package/dist/evidence-provider.js +419 -0
  25. package/dist/evidence-provider.js.map +1 -0
  26. package/dist/index.d.ts +19 -11
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +16 -10
  29. package/dist/index.js.map +1 -1
  30. package/dist/init.d.ts +15 -0
  31. package/dist/init.d.ts.map +1 -0
  32. package/dist/init.js +49 -0
  33. package/dist/init.js.map +1 -0
  34. package/dist/interop.d.ts +30 -0
  35. package/dist/interop.d.ts.map +1 -0
  36. package/dist/interop.js +29 -0
  37. package/dist/interop.js.map +1 -0
  38. package/dist/loop-compiler.d.ts +14 -64
  39. package/dist/loop-compiler.d.ts.map +1 -1
  40. package/dist/loop-compiler.js +307 -2001
  41. package/dist/loop-compiler.js.map +1 -1
  42. package/dist/loop-store.d.ts +82 -0
  43. package/dist/loop-store.d.ts.map +1 -0
  44. package/dist/loop-store.js +332 -0
  45. package/dist/loop-store.js.map +1 -0
  46. package/dist/mcp/server.d.ts +9 -6
  47. package/dist/mcp/server.d.ts.map +1 -1
  48. package/dist/mcp/server.js +109 -73
  49. package/dist/mcp/server.js.map +1 -1
  50. package/dist/mcp/session.d.ts +84 -20
  51. package/dist/mcp/session.d.ts.map +1 -1
  52. package/dist/mcp/session.js +718 -316
  53. package/dist/mcp/session.js.map +1 -1
  54. package/dist/mcp/tools.d.ts +18 -268
  55. package/dist/mcp/tools.d.ts.map +1 -1
  56. package/dist/mcp/tools.js +225 -12
  57. package/dist/mcp/tools.js.map +1 -1
  58. package/dist/observability.d.ts +36 -16
  59. package/dist/observability.d.ts.map +1 -1
  60. package/dist/observability.js +82 -23
  61. package/dist/observability.js.map +1 -1
  62. package/dist/policy-metrics.d.ts +46 -0
  63. package/dist/policy-metrics.d.ts.map +1 -0
  64. package/dist/policy-metrics.js +146 -0
  65. package/dist/policy-metrics.js.map +1 -0
  66. package/dist/policy.d.ts +58 -75
  67. package/dist/policy.d.ts.map +1 -1
  68. package/dist/policy.js +122 -93
  69. package/dist/policy.js.map +1 -1
  70. package/dist/prompt-assembler.d.ts +30 -0
  71. package/dist/prompt-assembler.d.ts.map +1 -0
  72. package/dist/prompt-assembler.js +257 -0
  73. package/dist/prompt-assembler.js.map +1 -0
  74. package/dist/prompt-policy.d.ts +29 -0
  75. package/dist/prompt-policy.d.ts.map +1 -0
  76. package/dist/prompt-policy.js +51 -0
  77. package/dist/prompt-policy.js.map +1 -0
  78. package/dist/protocol.d.ts +117 -91
  79. package/dist/protocol.d.ts.map +1 -1
  80. package/dist/protocol.js +40 -36
  81. package/dist/protocol.js.map +1 -1
  82. package/dist/replay.d.ts.map +1 -1
  83. package/dist/replay.js +1 -27
  84. package/dist/replay.js.map +1 -1
  85. package/dist/round-coordinator.d.ts +90 -0
  86. package/dist/round-coordinator.d.ts.map +1 -0
  87. package/dist/round-coordinator.js +186 -0
  88. package/dist/round-coordinator.js.map +1 -0
  89. package/dist/round-driver.d.ts +53 -0
  90. package/dist/round-driver.d.ts.map +1 -0
  91. package/dist/round-driver.js +101 -0
  92. package/dist/round-driver.js.map +1 -0
  93. package/dist/round-transaction.d.ts +70 -0
  94. package/dist/round-transaction.d.ts.map +1 -0
  95. package/dist/round-transaction.js +290 -0
  96. package/dist/round-transaction.js.map +1 -0
  97. package/dist/runtime.d.ts +35 -17
  98. package/dist/runtime.d.ts.map +1 -1
  99. package/dist/runtime.js +357 -344
  100. package/dist/runtime.js.map +1 -1
  101. package/dist/storage.d.ts +38 -0
  102. package/dist/storage.d.ts.map +1 -0
  103. package/dist/storage.js +201 -0
  104. package/dist/storage.js.map +1 -0
  105. package/dist/verification-gate.d.ts +39 -7
  106. package/dist/verification-gate.d.ts.map +1 -1
  107. package/dist/verification-gate.js +198 -9
  108. package/dist/verification-gate.js.map +1 -1
  109. package/loop_policy.json +26 -47
  110. package/package.json +13 -10
  111. package/skills/perception/SKILL.md +80 -249
  112. package/dist/backends/fs.d.ts +0 -36
  113. package/dist/backends/fs.d.ts.map +0 -1
  114. package/dist/backends/fs.js +0 -358
  115. package/dist/backends/fs.js.map +0 -1
  116. package/dist/builder.d.ts +0 -12
  117. package/dist/builder.d.ts.map +0 -1
  118. package/dist/builder.js +0 -259
  119. package/dist/builder.js.map +0 -1
  120. package/dist/mcp-server.d.ts +0 -12
  121. package/dist/mcp-server.d.ts.map +0 -1
  122. package/dist/mcp-server.js +0 -14
  123. package/dist/mcp-server.js.map +0 -1
  124. package/dist/memory-bridge.d.ts +0 -47
  125. package/dist/memory-bridge.d.ts.map +0 -1
  126. package/dist/memory-bridge.js +0 -290
  127. package/dist/memory-bridge.js.map +0 -1
  128. package/dist/tests/_helpers.d.ts +0 -25
  129. package/dist/tests/_helpers.d.ts.map +0 -1
  130. package/dist/tests/_helpers.js +0 -47
  131. package/dist/tests/_helpers.js.map +0 -1
  132. package/dist/tests/builder.test.d.ts +0 -2
  133. package/dist/tests/builder.test.d.ts.map +0 -1
  134. package/dist/tests/builder.test.js +0 -110
  135. package/dist/tests/builder.test.js.map +0 -1
  136. package/dist/tests/engine.test.d.ts +0 -2
  137. package/dist/tests/engine.test.d.ts.map +0 -1
  138. package/dist/tests/engine.test.js +0 -371
  139. package/dist/tests/engine.test.js.map +0 -1
  140. package/dist/tests/generate-schema.test.d.ts +0 -8
  141. package/dist/tests/generate-schema.test.d.ts.map +0 -1
  142. package/dist/tests/generate-schema.test.js +0 -199
  143. package/dist/tests/generate-schema.test.js.map +0 -1
  144. package/dist/tests/loop-compiler.test.d.ts +0 -2
  145. package/dist/tests/loop-compiler.test.d.ts.map +0 -1
  146. package/dist/tests/loop-compiler.test.js +0 -1051
  147. package/dist/tests/loop-compiler.test.js.map +0 -1
  148. package/dist/tests/mcp.test.d.ts +0 -7
  149. package/dist/tests/mcp.test.d.ts.map +0 -1
  150. package/dist/tests/mcp.test.js +0 -485
  151. package/dist/tests/mcp.test.js.map +0 -1
  152. package/dist/tests/memory-bridge.test.d.ts +0 -8
  153. package/dist/tests/memory-bridge.test.d.ts.map +0 -1
  154. package/dist/tests/memory-bridge.test.js +0 -383
  155. package/dist/tests/memory-bridge.test.js.map +0 -1
  156. package/dist/tests/policy.test.d.ts +0 -2
  157. package/dist/tests/policy.test.d.ts.map +0 -1
  158. package/dist/tests/policy.test.js +0 -49
  159. package/dist/tests/policy.test.js.map +0 -1
  160. package/dist/tests/protocol.test.d.ts +0 -2
  161. package/dist/tests/protocol.test.d.ts.map +0 -1
  162. package/dist/tests/protocol.test.js +0 -73
  163. package/dist/tests/protocol.test.js.map +0 -1
  164. package/dist/tests/replay.test.d.ts +0 -2
  165. package/dist/tests/replay.test.d.ts.map +0 -1
  166. package/dist/tests/replay.test.js +0 -222
  167. package/dist/tests/replay.test.js.map +0 -1
  168. package/dist/tests/runtime.test.d.ts +0 -7
  169. package/dist/tests/runtime.test.d.ts.map +0 -1
  170. package/dist/tests/runtime.test.js +0 -323
  171. package/dist/tests/runtime.test.js.map +0 -1
  172. package/dist/tests/verification-gate.test.d.ts +0 -2
  173. package/dist/tests/verification-gate.test.d.ts.map +0 -1
  174. package/dist/tests/verification-gate.test.js +0 -407
  175. package/dist/tests/verification-gate.test.js.map +0 -1
  176. package/skills/prompt-techniques/SKILL.md +0 -52
  177. package/skills/prompt-techniques/references/chain-of-thought.md +0 -207
  178. package/skills/prompt-techniques/references/few-shot.md +0 -174
  179. package/skills/prompt-techniques/references/least-to-most.md +0 -182
  180. package/skills/prompt-techniques/references/step-back.md +0 -160
  181. package/skills/prompt-techniques/references/tree-of-thought.md +0 -191
  182. package/skills/prompt-techniques/references/zero-shot.md +0 -97
package/dist/cli.js ADDED
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env node
2
+ /** Unified LoopForge command line. */
3
+ import { accessSync, constants, existsSync, realpathSync, statSync } from "node:fs";
4
+ import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { spawnSync } from "node:child_process";
7
+ import { initializeClient } from "./init.js";
8
+ import { FileLoopStore } from "./loop-store.js";
9
+ import { getPolicy, validateLoopId, writeDefaultPolicy } from "./policy.js";
10
+ import { McpServer } from "./mcp/server.js";
11
+ const VERSION = "2.0.0-rc.1";
12
+ const HELP = `LoopForge ${VERSION}
13
+
14
+ Usage:
15
+ loopforge mcp
16
+ loopforge init --client claude|codex|generic [--target DIR] [--force]
17
+ loopforge doctor [--json]
18
+ loopforge inspect LOOP_ID [--round N] [--prompt] [--json]
19
+ loopforge migrate [--from PATH] [--json]
20
+ `;
21
+ function option(args, name) {
22
+ const index = args.indexOf(name);
23
+ return index >= 0 ? args[index + 1] : undefined;
24
+ }
25
+ function has(args, name) {
26
+ return args.includes(name);
27
+ }
28
+ function print(value, json) {
29
+ if (json)
30
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
31
+ else if (typeof value === "string")
32
+ process.stdout.write(`${value}\n`);
33
+ else
34
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
35
+ }
36
+ function withoutPrompts(value) {
37
+ if (Array.isArray(value))
38
+ return value.map(withoutPrompts);
39
+ if (!value || typeof value !== "object")
40
+ return value;
41
+ const result = {};
42
+ for (const [key, child] of Object.entries(value)) {
43
+ if (["promptArtifact", "renderedPrompt", "current_prompt", "full_prompt"].includes(key)) {
44
+ continue;
45
+ }
46
+ result[key] = withoutPrompts(child);
47
+ }
48
+ return result;
49
+ }
50
+ function ensureInsideWorkspace(configured) {
51
+ const workspace = realpathSync(process.cwd());
52
+ const lexical = resolve(workspace, configured);
53
+ const lexicalRelative = relative(workspace, lexical);
54
+ if (lexicalRelative === ".." || lexicalRelative.startsWith(`..${sep}`) ||
55
+ isAbsolute(lexicalRelative))
56
+ throw new Error("path leaves the workspace");
57
+ if (!existsSync(lexical))
58
+ return lexical;
59
+ const actual = realpathSync(lexical);
60
+ const actualRelative = relative(workspace, actual);
61
+ if (actualRelative === ".." || actualRelative.startsWith(`..${sep}`) ||
62
+ isAbsolute(actualRelative))
63
+ throw new Error("path resolves outside the workspace");
64
+ return actual;
65
+ }
66
+ function doctor(json) {
67
+ const policy = getPolicy();
68
+ const checks = [];
69
+ const nodeMajor = Number(process.versions.node.split(".")[0]);
70
+ checks.push({
71
+ name: "node",
72
+ ok: nodeMajor >= 18,
73
+ required: true,
74
+ detail: `Node ${process.versions.node} (requires >=18)`,
75
+ });
76
+ try {
77
+ const root = resolve(policy.backend.root_dir);
78
+ let writable = root;
79
+ while (!existsSync(writable))
80
+ writable = dirname(writable);
81
+ accessSync(writable, constants.W_OK);
82
+ checks.push({ name: "store", ok: true, required: true, detail: root });
83
+ }
84
+ catch (error) {
85
+ checks.push({ name: "store", ok: false, required: true, detail: String(error) });
86
+ }
87
+ const git = spawnSync("git", ["--version"], {
88
+ encoding: "utf8",
89
+ shell: false,
90
+ windowsHide: true,
91
+ });
92
+ checks.push({
93
+ name: "git",
94
+ ok: git.status === 0,
95
+ required: false,
96
+ detail: git.status === 0 ? git.stdout.trim() : "unavailable (git evidence will be skipped)",
97
+ });
98
+ for (const command of policy.evidence.commands) {
99
+ if (!command.enabled)
100
+ continue;
101
+ let ok = true;
102
+ let detail = `${command.executable} ${command.args.join(" ")}`.trim();
103
+ try {
104
+ if (!command.name || !command.executable)
105
+ throw new Error("name and executable are required");
106
+ if (!Array.isArray(command.args))
107
+ throw new Error("args must be an array");
108
+ if (command.cwd) {
109
+ const cwd = ensureInsideWorkspace(command.cwd);
110
+ if (existsSync(cwd) && !statSync(cwd).isDirectory())
111
+ throw new Error("cwd is not a directory");
112
+ }
113
+ }
114
+ catch (error) {
115
+ ok = false;
116
+ detail = String(error);
117
+ }
118
+ checks.push({
119
+ name: `command:${command.name || "unnamed"}`,
120
+ ok,
121
+ required: command.required,
122
+ detail,
123
+ });
124
+ }
125
+ const report = {
126
+ version: VERSION,
127
+ ok: checks.every((check) => check.ok || !check.required),
128
+ checks,
129
+ };
130
+ if (json)
131
+ print(report, true);
132
+ else {
133
+ process.stdout.write(`LoopForge doctor ${VERSION}\n`);
134
+ for (const check of checks) {
135
+ const status = check.ok ? "OK" : check.required ? "FAIL" : "WARN";
136
+ process.stdout.write(`${status} ${check.name}: ${check.detail}\n`);
137
+ }
138
+ }
139
+ return report.ok ? 0 : 1;
140
+ }
141
+ function inspect(args) {
142
+ const loopId = args.find((arg) => !arg.startsWith("-"));
143
+ if (!loopId)
144
+ throw new Error("inspect requires LOOP_ID");
145
+ validateLoopId(loopId);
146
+ const roundText = option(args, "--round");
147
+ const includePrompt = has(args, "--prompt");
148
+ const json = has(args, "--json");
149
+ const store = new FileLoopStore(getPolicy().backend.root_dir);
150
+ if (roundText !== undefined) {
151
+ const round = Number(roundText);
152
+ if (!Number.isInteger(round) || round < 1)
153
+ throw new Error("--round must be a positive integer");
154
+ const document = store.readRound(loopId, round);
155
+ if (!document)
156
+ throw new Error(`round not found: ${loopId}#${round}`);
157
+ const result = includePrompt ? document : withoutPrompts(document);
158
+ print(result, json);
159
+ return;
160
+ }
161
+ const rounds = [...new Set(store.listEntries(loopId).map((entry) => {
162
+ const value = entry.loop_lineage?.round;
163
+ return typeof value === "number" ? value : null;
164
+ }).filter((value) => value !== null))].sort((a, b) => a - b);
165
+ const summary = { loopId, session: store.readSession(loopId), rounds };
166
+ print(includePrompt ? summary : withoutPrompts(summary), json);
167
+ }
168
+ function init(args) {
169
+ const client = option(args, "--client");
170
+ if (!client || !["claude", "codex", "generic"].includes(client)) {
171
+ throw new Error("init requires --client claude|codex|generic");
172
+ }
173
+ const force = has(args, "--force") || has(args, "-f");
174
+ const target = option(args, "--target");
175
+ const result = initializeClient({ client, force, target });
176
+ process.stdout.write(`${result.installed ? "Installed" : "Already present"}: ${result.skillPath}\n`);
177
+ process.stdout.write("Register MCP with:\n");
178
+ print(result.registration, typeof result.registration !== "string");
179
+ // Write default loop_policy.json alongside the skill so users can
180
+ // discover and tune runtime behaviour without reading source code.
181
+ const policyDir = target ?? process.cwd();
182
+ const policyResult = writeDefaultPolicy(policyDir, force);
183
+ process.stdout.write(`${policyResult.created ? "Created" : "Already present"}: ${policyResult.path}\n`);
184
+ }
185
+ function migrate(args) {
186
+ const source = option(args, "--from") ?? ".promptcraft/prompt_vault.json";
187
+ const result = new FileLoopStore(getPolicy().backend.root_dir).migrateLegacyVault(source);
188
+ print(result, has(args, "--json"));
189
+ }
190
+ export function main(argv = process.argv.slice(2)) {
191
+ const [command, ...args] = argv;
192
+ if (!command || command === "help" || command === "--help" || command === "-h") {
193
+ process.stdout.write(HELP);
194
+ return;
195
+ }
196
+ if (command === "--version" || command === "-v") {
197
+ process.stdout.write(`${VERSION}\n`);
198
+ return;
199
+ }
200
+ if (command === "mcp") {
201
+ new McpServer().start();
202
+ return;
203
+ }
204
+ if (command === "init")
205
+ return init(args);
206
+ if (command === "doctor") {
207
+ process.exitCode = doctor(has(args, "--json"));
208
+ return;
209
+ }
210
+ if (command === "inspect")
211
+ return inspect(args);
212
+ if (command === "migrate")
213
+ return migrate(args);
214
+ throw new Error(`Unknown command: ${command}\n\n${HELP}`);
215
+ }
216
+ const invokedPath = process.argv[1] ? resolve(process.argv[1]) : "";
217
+ const modulePath = fileURLToPath(import.meta.url);
218
+ if (invokedPath === modulePath) {
219
+ try {
220
+ main();
221
+ }
222
+ catch (error) {
223
+ process.stderr.write(`loopforge: ${error instanceof Error ? error.message : String(error)}\n`);
224
+ process.exitCode = 1;
225
+ }
226
+ }
227
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAgB,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAClG,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,GAAG,YAAY,CAAC;AAE7B,MAAM,IAAI,GAAG,aAAa,OAAO;;;;;;;;CAQhC,CAAC;AAEF,SAAS,MAAM,CAAC,IAAc,EAAE,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CA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OAAO,OAAO,IAAI,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpE,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,IAAI,WAAW,KAAK,UAAU,EAAE,CAAC;IAC/B,IAAI,CAAC;QACH,IAAI,EAAE,CAAC;IACT,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/F,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ /** Enforcement Gate — Layer 2 round-boundary runtime enforcement (v1.13).
2
+ *
3
+ * Pure-function module. Receives the verification gate's findings plus
4
+ * round-level context and decides whether to accept the round, reject it
5
+ * (force the agent to redo), or terminate the loop.
6
+ *
7
+ * This is the "runtime" that prompt-only constraint systems lack.
8
+ * Verification gate detects WHAT is wrong; enforcement gate decides
9
+ * what to DO about it.
10
+ *
11
+ * Decision semantics:
12
+ * - accept: round passes all checks; advance to next round as normal.
13
+ * - reject: agent's self-evaluation or round output is invalid; the
14
+ * agent receives a rejection prompt and must redo the SAME
15
+ * round. Round counter does NOT increment.
16
+ * - terminate: loop has reached an unrecoverable state; stop immediately
17
+ * with stopReason "enforcement_terminated".
18
+ */
19
+ import type { VaultEntry } from "./backends/interface.js";
20
+ import type { EnforcementResult, SelfEvaluation, VerificationResult } from "./protocol.js";
21
+ /** Enforce round-boundary rules based on the verification gate's findings
22
+ * and the agent's self-evaluation integrity.
23
+ *
24
+ * Rules run in priority order (R1 → R5). The first rule that fires wins.
25
+ *
26
+ * @param selfEval The agent's self-evaluation for the current round.
27
+ * @param verifyResult The verification gate's output (from verifySelfEvaluation).
28
+ * @param currentRound Current round number (1-based, BEFORE increment).
29
+ * @param vaultEntries Vault entries for this loop (used for progress tracking).
30
+ * @param consecutiveRejections How many consecutive rounds have already been rejected.
31
+ * Starts at 0; increments on each reject; resets on accept.
32
+ */
33
+ export declare function enforceRound(selfEval: SelfEvaluation, verifyResult: VerificationResult, currentRound: number, vaultEntries: VaultEntry[], consecutiveRejections?: number): EnforcementResult;
34
+ /** Build a rejection prompt for the agent.
35
+ *
36
+ * The prompt clearly states the round was rejected, why, what the agent
37
+ * must fix, and that the agent must redo the SAME round (not advance).
38
+ *
39
+ * @param currentRound The round number that was rejected (NOT incremented).
40
+ * @param task The original loop task description.
41
+ * @param enforceResult The enforcement decision with reason and fix instructions.
42
+ */
43
+ export declare function buildRejectionPrompt(currentRound: number, task: string, enforceResult: EnforcementResult): string;
44
+ //# sourceMappingURL=enforcement-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enforcement-gate.d.ts","sourceRoot":"","sources":["../src/enforcement-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EAEd,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAgOvB;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,cAAc,EACxB,YAAY,EAAE,kBAAkB,EAChC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,UAAU,EAAE,EAC1B,qBAAqB,GAAE,MAAU,GAChC,iBAAiB,CAwBnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,iBAAiB,GAC/B,MAAM,CAuCR"}
@@ -0,0 +1,271 @@
1
+ /** Enforcement Gate — Layer 2 round-boundary runtime enforcement (v1.13).
2
+ *
3
+ * Pure-function module. Receives the verification gate's findings plus
4
+ * round-level context and decides whether to accept the round, reject it
5
+ * (force the agent to redo), or terminate the loop.
6
+ *
7
+ * This is the "runtime" that prompt-only constraint systems lack.
8
+ * Verification gate detects WHAT is wrong; enforcement gate decides
9
+ * what to DO about it.
10
+ *
11
+ * Decision semantics:
12
+ * - accept: round passes all checks; advance to next round as normal.
13
+ * - reject: agent's self-evaluation or round output is invalid; the
14
+ * agent receives a rejection prompt and must redo the SAME
15
+ * round. Round counter does NOT increment.
16
+ * - terminate: loop has reached an unrecoverable state; stop immediately
17
+ * with stopReason "enforcement_terminated".
18
+ */
19
+ import { makeEnforcementResult } from "./protocol.js";
20
+ import { entryRound } from "./verification-gate.js";
21
+ // ═══════════════════════════════════════════════════════════════════════════
22
+ // Helpers
23
+ // ═══════════════════════════════════════════════════════════════════════════
24
+ /** Extract progress_estimate from a vault entry's execution_evidence.
25
+ * Returns null if no execution evidence is available. */
26
+ function entryProgress(entry) {
27
+ const evidence = entry.execution_evidence;
28
+ if (!evidence)
29
+ return null;
30
+ const pe = evidence.progress_estimate;
31
+ return typeof pe === "number" ? pe : null;
32
+ }
33
+ // ═══════════════════════════════════════════════════════════════════════════
34
+ // Individual enforcement rules — each returns EnforcementResult | null
35
+ // Rules are ordered by priority. The first non-null result wins.
36
+ // ═══════════════════════════════════════════════════════════════════════════
37
+ /** R1: Agent claims success but success_criteria_remaining has items.
38
+ * This is a lie — the agent must either finish the criteria or
39
+ * set success=false honestly. Triggered by the verification gate's
40
+ * "success_with_remaining_criteria" error flag. */
41
+ function enforceSuccessWithRemainingCriteria(flags) {
42
+ const flag = flags.find((f) => f.check === "success_with_remaining_criteria" && f.severity === "error");
43
+ if (!flag)
44
+ return null;
45
+ return makeEnforcementResult({
46
+ action: "reject",
47
+ reason: flag.detail,
48
+ fix_instructions: "You set success=true but success criteria remain unmet. " +
49
+ "Either: (a) complete the remaining criteria and re-submit your self-evaluation, " +
50
+ "or (b) set success=false and honestly report what remains to be done.",
51
+ check: "success_with_remaining_criteria",
52
+ });
53
+ }
54
+ /** R2: Same constraint violation appears in 3 consecutive rounds.
55
+ * The agent is repeating the same mistake. Triggered by the verification
56
+ * gate's "recurring_violation" error flag. */
57
+ function enforceRecurringViolation(flags) {
58
+ const flag = flags.find((f) => f.check === "recurring_violation" && f.severity === "error");
59
+ if (!flag)
60
+ return null;
61
+ return makeEnforcementResult({
62
+ action: "reject",
63
+ reason: flag.detail,
64
+ fix_instructions: "The same constraint violation has appeared in 3 consecutive rounds. " +
65
+ "You must: (a) explain WHY this violation keeps occurring, " +
66
+ "and (b) propose a DIFFERENT approach than what you used in the last 3 rounds. " +
67
+ "Do NOT retry the same strategy — it has failed 3 times.",
68
+ check: "recurring_violation",
69
+ });
70
+ }
71
+ /** R3: Agent claims success but did nothing verifiable.
72
+ * v1.17: execution_evidence is now MANDATORY for structured self-evaluations.
73
+ * Missing evidence when success=true → reject (agent must provide evidence).
74
+ * Empty evidence (no files + no tests) when success=true → reject. */
75
+ function enforceEmptySuccess(selfEval, _flags) {
76
+ if (!selfEval.success)
77
+ return null;
78
+ const ev = selfEval.execution_evidence;
79
+ // v1.17: Missing evidence when claiming success → reject.
80
+ // The agent MUST provide execution_evidence to back up a success claim.
81
+ if (!ev) {
82
+ return makeEnforcementResult({
83
+ action: "reject",
84
+ reason: "Agent claims success but provided no execution_evidence. " +
85
+ "Every successful round MUST include execution_evidence with " +
86
+ "files_changed, test_results, and progress_estimate.",
87
+ fix_instructions: "You must provide execution_evidence in your self-evaluation: " +
88
+ "(a) list the files you changed in execution_evidence.files_changed, " +
89
+ "(b) run tests and report results in execution_evidence.test_results, " +
90
+ "(c) estimate your progress in execution_evidence.progress_estimate. " +
91
+ "If you genuinely completed the task without file changes or tests, " +
92
+ "explain why in detail in your output_summary.",
93
+ check: "empty_success",
94
+ });
95
+ }
96
+ const filesEmpty = ev.files_changed.length === 0;
97
+ const testsNotRun = ev.test_results === null;
98
+ if (!filesEmpty || !testsNotRun)
99
+ return null;
100
+ return makeEnforcementResult({
101
+ action: "reject",
102
+ reason: "Agent claims success but execution_evidence shows no files changed " +
103
+ "and no tests were run. There is no verifiable evidence of work.",
104
+ fix_instructions: "You must provide verifiable evidence: " +
105
+ "(a) list the files you changed in execution_evidence.files_changed, " +
106
+ "and (b) run tests and report results in execution_evidence.test_results. " +
107
+ "If you genuinely completed the task without file changes or tests, " +
108
+ "explain why in detail in your output_summary.",
109
+ check: "empty_success",
110
+ });
111
+ }
112
+ /** R4: Progress has stalled for 3+ consecutive rounds.
113
+ * Detected by checking progress_estimate deltas across vault entries.
114
+ * First occurrence → REJECT (agent must change approach).
115
+ * Second consecutive occurrence → TERMINATE (agent cannot recover). */
116
+ function enforceProgressStall(_selfEval, _flags, currentRound, vaultEntries, consecutiveRejections) {
117
+ // Need at least 3 rounds of history
118
+ if (currentRound < 3)
119
+ return null;
120
+ // Collect progress estimates for the last 3 completed rounds from vault
121
+ const progressByRound = new Map();
122
+ for (const entry of vaultEntries) {
123
+ const rnd = entryRound(entry);
124
+ // Only consider rounds before the current one
125
+ if (rnd < 1 || rnd >= currentRound)
126
+ continue;
127
+ const pe = entryProgress(entry);
128
+ if (pe !== null)
129
+ progressByRound.set(rnd, pe);
130
+ }
131
+ // Need at least 3 data points
132
+ if (progressByRound.size < 3)
133
+ return null;
134
+ // Get the three most recent rounds with progress data
135
+ const sortedRounds = [...progressByRound.keys()].sort((a, b) => a - b);
136
+ const last3 = sortedRounds.slice(-3);
137
+ if (last3.length < 3)
138
+ return null;
139
+ // Verify these are the actual last 3 rounds (contiguous with current)
140
+ // Accept rounds that are within [currentRound-3, currentRound-1]
141
+ const expectedMin = currentRound - 3;
142
+ const actualMin = last3[0];
143
+ // Allow up to 1 round gap (some rounds may not have progress data)
144
+ if (actualMin < expectedMin - 1 || last3[2] > currentRound - 1)
145
+ return null;
146
+ const p1 = progressByRound.get(last3[0]);
147
+ const p2 = progressByRound.get(last3[1]);
148
+ const p3 = progressByRound.get(last3[2]);
149
+ const stallThreshold = 0.05;
150
+ const delta12 = p2 - p1;
151
+ const delta23 = p3 - p2;
152
+ // Both deltas must be below threshold AND not near completion
153
+ const isStalling = delta12 < stallThreshold &&
154
+ delta23 < stallThreshold &&
155
+ p3 < 0.95;
156
+ if (!isStalling)
157
+ return null;
158
+ // If already rejected once for stall → escalate to terminate
159
+ if (consecutiveRejections >= 1) {
160
+ return makeEnforcementResult({
161
+ action: "terminate",
162
+ reason: `Progress stalled for 3+ rounds ` +
163
+ `(${(p1 * 100).toFixed(0)}% → ${(p2 * 100).toFixed(0)}% → ${(p3 * 100).toFixed(0)}%) ` +
164
+ `and agent did not resolve after previous rejection. Terminating loop.`,
165
+ check: "progress_stall",
166
+ });
167
+ }
168
+ return makeEnforcementResult({
169
+ action: "reject",
170
+ reason: `Progress has stalled: ${(p1 * 100).toFixed(0)}% → ` +
171
+ `${(p2 * 100).toFixed(0)}% → ${(p3 * 100).toFixed(0)}% over the ` +
172
+ `last 3 rounds (delta < ${(stallThreshold * 100).toFixed(0)}% each round).`,
173
+ fix_instructions: "Your progress has been flat for 3 rounds. You must: " +
174
+ "(a) explain what is blocking progress, " +
175
+ "(b) propose a DIFFERENT technique or task decomposition, and " +
176
+ "(c) set a concrete, verifiable goal for the redo of this round. " +
177
+ "Do NOT repeat the same approach — it has not moved progress forward.",
178
+ check: "progress_stall",
179
+ });
180
+ }
181
+ /** R5: Two consecutive rejections → terminate.
182
+ * The agent has been unable or unwilling to fix the identified issues
183
+ * across two consecutive enforcement rejections. */
184
+ function enforceMaxRejections(consecutiveRejections) {
185
+ if (consecutiveRejections < 2)
186
+ return null;
187
+ return makeEnforcementResult({
188
+ action: "terminate",
189
+ reason: `${consecutiveRejections} consecutive enforcement rejections for the ` +
190
+ `same issue without resolution. The agent has been unable to correct the identified issue.`,
191
+ check: "max_rejections",
192
+ });
193
+ }
194
+ // ═══════════════════════════════════════════════════════════════════════════
195
+ // Main entry point
196
+ // ═══════════════════════════════════════════════════════════════════════════
197
+ /** Enforce round-boundary rules based on the verification gate's findings
198
+ * and the agent's self-evaluation integrity.
199
+ *
200
+ * Rules run in priority order (R1 → R5). The first rule that fires wins.
201
+ *
202
+ * @param selfEval The agent's self-evaluation for the current round.
203
+ * @param verifyResult The verification gate's output (from verifySelfEvaluation).
204
+ * @param currentRound Current round number (1-based, BEFORE increment).
205
+ * @param vaultEntries Vault entries for this loop (used for progress tracking).
206
+ * @param consecutiveRejections How many consecutive rounds have already been rejected.
207
+ * Starts at 0; increments on each reject; resets on accept.
208
+ */
209
+ export function enforceRound(selfEval, verifyResult, currentRound, vaultEntries, consecutiveRejections = 0) {
210
+ const { flags } = verifyResult;
211
+ // Run enforcement rules in priority order.
212
+ // Earlier rules take higher precedence.
213
+ const rules = [
214
+ () => enforceSuccessWithRemainingCriteria(flags),
215
+ () => enforceRecurringViolation(flags),
216
+ () => enforceEmptySuccess(selfEval, flags),
217
+ () => enforceProgressStall(selfEval, flags, currentRound, vaultEntries, consecutiveRejections),
218
+ () => enforceMaxRejections(consecutiveRejections),
219
+ ];
220
+ for (const rule of rules) {
221
+ const result = rule();
222
+ if (result)
223
+ return result;
224
+ }
225
+ // All rules passed — accept the round
226
+ return makeEnforcementResult({
227
+ action: "accept",
228
+ reason: "",
229
+ fix_instructions: "",
230
+ });
231
+ }
232
+ /** Build a rejection prompt for the agent.
233
+ *
234
+ * The prompt clearly states the round was rejected, why, what the agent
235
+ * must fix, and that the agent must redo the SAME round (not advance).
236
+ *
237
+ * @param currentRound The round number that was rejected (NOT incremented).
238
+ * @param task The original loop task description.
239
+ * @param enforceResult The enforcement decision with reason and fix instructions.
240
+ */
241
+ export function buildRejectionPrompt(currentRound, task, enforceResult) {
242
+ const lines = [
243
+ "## ⛔ Round " + currentRound + " — REJECTED",
244
+ "",
245
+ "Your self-evaluation for Round " + currentRound +
246
+ " was **rejected** by the enforcement gate.",
247
+ "",
248
+ "### Reason",
249
+ "",
250
+ enforceResult.reason,
251
+ "",
252
+ ];
253
+ if (enforceResult.fix_instructions) {
254
+ lines.push("### Required Fix");
255
+ lines.push("");
256
+ lines.push(enforceResult.fix_instructions);
257
+ lines.push("");
258
+ }
259
+ lines.push("### Your Task (Round " + currentRound + " — Retry)");
260
+ lines.push("");
261
+ lines.push(task);
262
+ lines.push("");
263
+ lines.push("### Instructions");
264
+ lines.push("");
265
+ lines.push("1. Read and address each issue in **Required Fix** above.", "2. Re-execute **Round " + currentRound +
266
+ "** — do NOT advance to the next round.", "3. Submit a corrected self-evaluation via `loopforge_next`.", "4. Be honest in your self-evaluation — " +
267
+ "claiming success when criteria are unmet will be rejected again.", "5. If you believe this rejection is incorrect, " +
268
+ "explain why in your output_summary and the enforcement gate will re-evaluate.");
269
+ return lines.join("\n");
270
+ }
271
+ //# sourceMappingURL=enforcement-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enforcement-gate.js","sourceRoot":"","sources":["../src/enforcement-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;0DAC0D;AAC1D,SAAS,aAAa,CAAC,KAAiB;IACtC,MAAM,QAAQ,GAAG,KAAK,CAAC,kBAAyD,CAAC;IACjF,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,EAAE,GAAG,QAAQ,CAAC,iBAAiB,CAAC;IACtC,OAAO,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED,8EAA8E;AAC9E,uEAAuE;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,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAC3C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,uBAAuB,GAAG,YAAY,GAAG,WAAW,CAAC,CAAC;IACjE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CACR,2DAA2D,EAC3D,wBAAwB,GAAG,YAAY;QACvC,wCAAwC,EACxC,6DAA6D,EAC7D,yCAAyC;QACzC,kEAAkE,EAClE,iDAAiD;QACjD,+EAA+E,CAChF,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
package/dist/engine.d.ts CHANGED
@@ -6,7 +6,17 @@
6
6
  * EngineMetrics tracks silent-failure counters for observability.
7
7
  */
8
8
  import type { VaultBackend } from "./backends/interface.js";
9
- import { type AgentLoopResult, type LoopForgeRequest, type SelfEvaluation, type SessionState } from "./protocol.js";
9
+ import type { LoopStore } from "./loop-store.js";
10
+ import { type AgentLoopResult, type CriterionRevision, type ExecutionEvidence, type LoopForgeRequest, type SelfEvaluation, type SessionState } from "./protocol.js";
11
+ /** Parse ExecutionEvidence from a raw JSON object. Shared by buildSelfEvaluation
12
+ * and invokeLoopCompile — both parse the same execution_evidence shape. */
13
+ export declare function parseExecutionEvidence(raw: Record<string, unknown> | undefined | null): ExecutionEvidence | undefined;
14
+ /** Parse CriterionRevision[] from a raw JSON array. Shared by buildSelfEvaluation
15
+ * and invokeLoopCompile — both parse the same revised_success_criteria shape. */
16
+ export declare function parseCriterionRevisions(raw: unknown): CriterionRevision[];
17
+ /** Parse WorkerResult[] from a raw JSON array. Shared by buildSelfEvaluation
18
+ * and invokeLoopCompile — both parse the same worker_results shape. */
19
+ export declare function parseWorkerResults(raw: unknown): import("./protocol.js").WorkerResult[];
10
20
  /** Extract a structured SelfEvaluation from agent output text.
11
21
  * Returns null if no valid self-eval block is found.
12
22
  * The agent is instructed to output JSON between the delimiters. */
@@ -42,14 +52,12 @@ export interface EngineMetrics {
42
52
  sessionStart: number;
43
53
  }
44
54
  export declare class LoopForgeEngine {
45
- skillsDir: string;
46
55
  state: SessionState | null;
47
56
  private backend;
48
57
  private metrics;
49
58
  private feedbackWriteBuffer;
50
59
  lastTask: string | null;
51
- private seenConstraints;
52
- constructor(skillsDir?: string, backend?: VaultBackend);
60
+ constructor(storeOrBackend?: LoopStore | VaultBackend);
53
61
  private resolveBackend;
54
62
  /** Public accessor for the vault backend — used by runtime/verification gate. */
55
63
  getBackend(): VaultBackend;
@@ -71,9 +79,11 @@ export declare class LoopForgeEngine {
71
79
  * and emerged_subtasks for the compiler to consume next round.
72
80
  * Call this BEFORE invokeLoopCompile for the next round so that
73
81
  * hydrateLoopContext picks up the latest success flags. */
74
- autoFeedback(selfEval: SelfEvaluation, loopId: string, round: number, task: string): boolean;
75
- invokeLoopCompile(request: LoopForgeRequest, hydrateResults?: Record<string, unknown> | null): AgentLoopResult;
82
+ autoFeedback(selfEval: SelfEvaluation, loopId: string, round: number, task: string, roundTransaction?: Record<string, unknown>): boolean;
83
+ invokeLoopCompile(request: LoopForgeRequest, hydrateResults?: Record<string, unknown> | null, options?: {
84
+ persistLineage?: boolean;
85
+ }): AgentLoopResult;
76
86
  shouldBreak(): boolean;
77
87
  }
78
- export declare function createEngine(skillsDir?: string, backend?: VaultBackend): LoopForgeEngine;
88
+ export declare function createEngine(store?: LoopStore): LoopForg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