loopforge 3.0.0 → 3.6.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 (194) hide show
  1. package/README.md +126 -143
  2. package/dist/audit.d.ts +50 -0
  3. package/dist/audit.d.ts.map +1 -0
  4. package/dist/audit.js +131 -0
  5. package/dist/audit.js.map +1 -0
  6. package/dist/canonical-state.d.ts +98 -23
  7. package/dist/canonical-state.d.ts.map +1 -1
  8. package/dist/canonical-state.js +257 -181
  9. package/dist/canonical-state.js.map +1 -1
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +40 -33
  12. package/dist/cli.js.map +1 -1
  13. package/dist/cognitive-facts.d.ts +17 -0
  14. package/dist/cognitive-facts.d.ts.map +1 -0
  15. package/dist/cognitive-facts.js +99 -0
  16. package/dist/cognitive-facts.js.map +1 -0
  17. package/dist/cognitive-governance.d.ts +25 -33
  18. package/dist/cognitive-governance.d.ts.map +1 -1
  19. package/dist/cognitive-governance.js +38 -138
  20. package/dist/cognitive-governance.js.map +1 -1
  21. package/dist/committed-round.d.ts +59 -0
  22. package/dist/committed-round.d.ts.map +1 -0
  23. package/dist/committed-round.js +222 -0
  24. package/dist/committed-round.js.map +1 -0
  25. package/dist/enforcement-gate.d.ts +78 -0
  26. package/dist/enforcement-gate.d.ts.map +1 -0
  27. package/dist/enforcement-gate.js +1109 -0
  28. package/dist/enforcement-gate.js.map +1 -0
  29. package/dist/engine.d.ts +111 -0
  30. package/dist/engine.d.ts.map +1 -0
  31. package/dist/engine.js +887 -0
  32. package/dist/engine.js.map +1 -0
  33. package/dist/evidence-claims.d.ts +50 -0
  34. package/dist/evidence-claims.d.ts.map +1 -0
  35. package/dist/evidence-claims.js +116 -0
  36. package/dist/evidence-claims.js.map +1 -0
  37. package/dist/evidence-provider.d.ts +50 -23
  38. package/dist/evidence-provider.d.ts.map +1 -1
  39. package/dist/evidence-provider.js +167 -50
  40. package/dist/evidence-provider.js.map +1 -1
  41. package/dist/generate-schema.js +1 -84
  42. package/dist/generate-schema.js.map +1 -1
  43. package/dist/index.d.ts +19 -22
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +16 -15
  46. package/dist/index.js.map +1 -1
  47. package/dist/loop-compiler.d.ts +58 -3
  48. package/dist/loop-compiler.d.ts.map +1 -1
  49. package/dist/loop-compiler.js +841 -304
  50. package/dist/loop-compiler.js.map +1 -1
  51. package/dist/loop-extras-parser.d.ts +2 -2
  52. package/dist/loop-extras-parser.d.ts.map +1 -1
  53. package/dist/loop-extras-parser.js +2 -2
  54. package/dist/loop-extras-parser.js.map +1 -1
  55. package/dist/loop-projection.d.ts +6 -0
  56. package/dist/loop-projection.d.ts.map +1 -0
  57. package/dist/loop-projection.js +26 -0
  58. package/dist/loop-projection.js.map +1 -0
  59. package/dist/loop-store.d.ts +115 -24
  60. package/dist/loop-store.d.ts.map +1 -1
  61. package/dist/loop-store.js +365 -218
  62. package/dist/loop-store.js.map +1 -1
  63. package/dist/mcp/round-lifecycle.d.ts +214 -0
  64. package/dist/mcp/round-lifecycle.d.ts.map +1 -0
  65. package/dist/mcp/round-lifecycle.js +935 -0
  66. package/dist/mcp/round-lifecycle.js.map +1 -0
  67. package/dist/mcp/server.d.ts +2 -1
  68. package/dist/mcp/server.d.ts.map +1 -1
  69. package/dist/mcp/server.js +29 -43
  70. package/dist/mcp/server.js.map +1 -1
  71. package/dist/mcp/session.d.ts +64 -101
  72. package/dist/mcp/session.d.ts.map +1 -1
  73. package/dist/mcp/session.js +433 -1110
  74. package/dist/mcp/session.js.map +1 -1
  75. package/dist/mcp/tools.d.ts +20 -11
  76. package/dist/mcp/tools.d.ts.map +1 -1
  77. package/dist/mcp/tools.js +587 -413
  78. package/dist/mcp/tools.js.map +1 -1
  79. package/dist/policy-metrics.d.ts +12 -24
  80. package/dist/policy-metrics.d.ts.map +1 -1
  81. package/dist/policy-metrics.js +78 -184
  82. package/dist/policy-metrics.js.map +1 -1
  83. package/dist/policy.d.ts +61 -50
  84. package/dist/policy.d.ts.map +1 -1
  85. package/dist/policy.js +48 -146
  86. package/dist/policy.js.map +1 -1
  87. package/dist/prompt-assembler.d.ts +37 -6
  88. package/dist/prompt-assembler.d.ts.map +1 -1
  89. package/dist/prompt-assembler.js +487 -278
  90. package/dist/prompt-assembler.js.map +1 -1
  91. package/dist/prompt-policy.d.ts +1 -8
  92. package/dist/prompt-policy.d.ts.map +1 -1
  93. package/dist/prompt-policy.js +8 -26
  94. package/dist/prompt-policy.js.map +1 -1
  95. package/dist/protocol.d.ts +398 -236
  96. package/dist/protocol.d.ts.map +1 -1
  97. package/dist/protocol.js +147 -17
  98. package/dist/protocol.js.map +1 -1
  99. package/dist/replay.d.ts +5 -13
  100. package/dist/replay.d.ts.map +1 -1
  101. package/dist/replay.js +32 -69
  102. package/dist/replay.js.map +1 -1
  103. package/dist/round-contract.d.ts +64 -0
  104. package/dist/round-contract.d.ts.map +1 -0
  105. package/dist/round-contract.js +80 -0
  106. package/dist/round-contract.js.map +1 -0
  107. package/dist/round-coordinator.d.ts +23 -25
  108. package/dist/round-coordinator.d.ts.map +1 -1
  109. package/dist/round-coordinator.js +103 -92
  110. package/dist/round-coordinator.js.map +1 -1
  111. package/dist/round-driver.d.ts +13 -13
  112. package/dist/round-driver.d.ts.map +1 -1
  113. package/dist/round-driver.js +25 -14
  114. package/dist/round-driver.js.map +1 -1
  115. package/dist/round-transaction.d.ts +14 -18
  116. package/dist/round-transaction.d.ts.map +1 -1
  117. package/dist/round-transaction.js +37 -47
  118. package/dist/round-transaction.js.map +1 -1
  119. package/dist/self-eval.d.ts +48 -0
  120. package/dist/self-eval.d.ts.map +1 -0
  121. package/dist/self-eval.js +248 -0
  122. package/dist/self-eval.js.map +1 -0
  123. package/dist/storage.d.ts +9 -4
  124. package/dist/storage.d.ts.map +1 -1
  125. package/dist/storage.js +18 -6
  126. package/dist/storage.js.map +1 -1
  127. package/dist/token-utils.d.ts +15 -3
  128. package/dist/token-utils.d.ts.map +1 -1
  129. package/dist/token-utils.js +24 -5
  130. package/dist/token-utils.js.map +1 -1
  131. package/dist/verification-gate.d.ts +149 -0
  132. package/dist/verification-gate.d.ts.map +1 -0
  133. package/dist/verification-gate.js +1343 -0
  134. package/dist/verification-gate.js.map +1 -0
  135. package/dist/workspace.d.ts +29 -0
  136. package/dist/workspace.d.ts.map +1 -0
  137. package/dist/workspace.js +61 -0
  138. package/dist/workspace.js.map +1 -0
  139. package/loop_policy.json +37 -16
  140. package/package.json +5 -10
  141. package/skills/perception/SKILL.md +184 -202
  142. package/dist/canonical-event-writer.d.ts +0 -20
  143. package/dist/canonical-event-writer.d.ts.map +0 -1
  144. package/dist/canonical-event-writer.js +0 -131
  145. package/dist/canonical-event-writer.js.map +0 -1
  146. package/dist/compiler-subgoals.d.ts +0 -7
  147. package/dist/compiler-subgoals.d.ts.map +0 -1
  148. package/dist/compiler-subgoals.js +0 -93
  149. package/dist/compiler-subgoals.js.map +0 -1
  150. package/dist/derive-id.d.ts +0 -12
  151. package/dist/derive-id.d.ts.map +0 -1
  152. package/dist/derive-id.js +0 -31
  153. package/dist/derive-id.js.map +0 -1
  154. package/dist/mcp/session-projection.d.ts +0 -5
  155. package/dist/mcp/session-projection.d.ts.map +0 -1
  156. package/dist/mcp/session-projection.js +0 -18
  157. package/dist/mcp/session-projection.js.map +0 -1
  158. package/dist/mcp/session-queue.d.ts +0 -3
  159. package/dist/mcp/session-queue.d.ts.map +0 -1
  160. package/dist/mcp/session-queue.js +0 -18
  161. package/dist/mcp/session-queue.js.map +0 -1
  162. package/dist/mcp/session-types.d.ts +0 -72
  163. package/dist/mcp/session-types.d.ts.map +0 -1
  164. package/dist/mcp/session-types.js +0 -2
  165. package/dist/mcp/session-types.js.map +0 -1
  166. package/dist/round-commit-store.d.ts +0 -12
  167. package/dist/round-commit-store.d.ts.map +0 -1
  168. package/dist/round-commit-store.js +0 -13
  169. package/dist/round-commit-store.js.map +0 -1
  170. package/dist/round-gate.d.ts +0 -31
  171. package/dist/round-gate.d.ts.map +0 -1
  172. package/dist/round-gate.js +0 -259
  173. package/dist/round-gate.js.map +0 -1
  174. package/dist/round-recovery.d.ts +0 -17
  175. package/dist/round-recovery.d.ts.map +0 -1
  176. package/dist/round-recovery.js +0 -117
  177. package/dist/round-recovery.js.map +0 -1
  178. package/dist/round-report.d.ts +0 -16
  179. package/dist/round-report.d.ts.map +0 -1
  180. package/dist/round-report.js +0 -401
  181. package/dist/round-report.js.map +0 -1
  182. package/dist/runtime-services.d.ts +0 -59
  183. package/dist/runtime-services.d.ts.map +0 -1
  184. package/dist/runtime-services.js +0 -460
  185. package/dist/runtime-services.js.map +0 -1
  186. package/dist/vault-format.d.ts +0 -4
  187. package/dist/vault-format.d.ts.map +0 -1
  188. package/dist/vault-format.js +0 -4
  189. package/dist/vault-format.js.map +0 -1
  190. package/dist/vault-types.d.ts +0 -24
  191. package/dist/vault-types.d.ts.map +0 -1
  192. package/dist/vault-types.js +0 -2
  193. package/dist/vault-types.js.map +0 -1
  194. package/loopforge-policy.json +0 -340
@@ -1,12 +1,34 @@
1
+ /** v2.12: User/Agent gate classification and governance helpers.
2
+ *
3
+ * Ported from the 3.x line with the V2 flat-contract adaptation: the MCP
4
+ * surface works with a flat gate text (the agent's blocker description),
5
+ * while the structured GateActionDescriptor stays an internal type for
6
+ * audit display. Only decisions are persisted — gate state is always
7
+ * re-derivable via deriveGate, so the vault never holds a second truth.
8
+ */
1
9
  import { createHash } from "node:crypto";
2
- import { deriveCriterionId, deriveGateId, deriveTextHash } from "./derive-id.js";
3
- import { isRecord } from "./token-utils.js";
4
- import { entryRound } from "./token-utils.js";
10
+ import { computeGoalTextHash } from "./loop-compiler.js";
11
+ import { entryRound as sharedEntryRound } from "./token-utils.js";
12
+ export function entryRound(entry) {
13
+ return sharedEntryRound(entry);
14
+ }
15
+ /** Effects that always require human authorization. */
5
16
  const USER_EFFECTS = new Set([
6
17
  "production", "credentials", "data_migration", "public_api", "publish",
7
18
  "payment", "external_communication",
8
19
  ]);
20
+ /** High-risk markers, English + Chinese. */
9
21
  const USER_RISK = /production|prod\b|credential|secret|permission|publish|release|database migration|schema migration|public api break|rm\s+-rf|reset\s+--hard|send email|payment|生产|上线|凭据|密钥|权限|发布|数据迁移|破坏性/i;
22
+ /** Stable gate ID from canonicalized gate text (gate- + sha256 slice 12). */
23
+ export function deriveGateId(text) {
24
+ return "gate-" + computeGoalTextHash(text).slice(0, 12);
25
+ }
26
+ /** Stable todo item ID (todo- + sha256 slice 8) for the LoopProjection. */
27
+ export function deriveTodoId(text) {
28
+ return "todo-" + computeGoalTextHash(text).slice(0, 8);
29
+ }
30
+ /** Canonical serialization — sorted scope/effects make the hash stable
31
+ * across field-order and whitespace differences. */
10
32
  export function canonicalizeGateAction(action) {
11
33
  return JSON.stringify({
12
34
  description: action.description.trim(),
@@ -16,9 +38,12 @@ export function canonicalizeGateAction(action) {
16
38
  authorization: action.authorization,
17
39
  });
18
40
  }
41
+ /** 16-hex hash binding an approval to the exact action text — an edited
42
+ * action produces a different hash, so old approvals expire automatically. */
19
43
  export function gateActionHash(action) {
20
44
  return createHash("sha256").update(canonicalizeGateAction(action)).digest("hex").slice(0, 16);
21
45
  }
46
+ /** Classify a structured action descriptor (internal use; audit display). */
22
47
  export function deriveStructuredGate(action) {
23
48
  const actionHash = gateActionHash(action);
24
49
  const highRisk = action.authorization === "user_required" ||
@@ -44,6 +69,9 @@ export function deriveStructuredGate(action) {
44
69
  },
45
70
  };
46
71
  }
72
+ /** Classify a flat gate text (MCP surface). The id embeds the canonicalized
73
+ * text hash, so a changed blocker text yields a different gate id and any
74
+ * previously recorded approval no longer matches. */
47
75
  export function deriveGate(action, scope = []) {
48
76
  if (typeof action !== "string")
49
77
  return deriveStructuredGate(action);
@@ -64,25 +92,15 @@ export function deriveGate(action, scope = []) {
64
92
  };
65
93
  return { id, gate };
66
94
  }
67
- function report(entry) {
68
- return isRecord(entry.round_report) ? entry.round_report : null;
69
- }
70
- /**
71
- * Replay events in a deterministic logical order. Backends are allowed to
72
- * return entries in different physical orders, so insertion order cannot be
73
- * used to decide which gate decision or verification result wins.
74
- * Shared with the policy-metrics replay path, which must fold events in the
75
- * same order as the audit.
76
- */
95
+ /** Deterministic replay order for audit — backends may return entries in
96
+ * different physical orders, so insertion order can never decide which
97
+ * gate decision or verification result wins. */
77
98
  export function auditOrder(entries) {
78
99
  return entries
79
100
  .map((entry, index) => ({ entry, index }))
80
101
  .sort((left, right) => {
81
- const leftSequence = left.entry.event_sequence;
82
- const rightSequence = right.entry.event_sequence;
83
- if (typeof leftSequence === "number" && typeof rightSequence === "number" && leftSequence !== rightSequence) {
84
- return leftSequence - rightSequence;
85
- }
102
+ // v2.14: the event_sequence sort layer was removed — no entry in the
103
+ // codebase ever writes that field, so the branch was unreachable.
86
104
  const roundDiff = entryRound(left.entry) - entryRound(right.entry);
87
105
  if (roundDiff !== 0)
88
106
  return roundDiff;
@@ -90,9 +108,8 @@ export function auditOrder(entries) {
90
108
  const timeRight = Date.parse(right.entry.timestamp ?? "");
91
109
  const validLeft = Number.isFinite(timeLeft);
92
110
  const validRight = Number.isFinite(timeRight);
93
- if (validLeft && validRight && timeLeft !== timeRight) {
111
+ if (validLeft && validRight && timeLeft !== timeRight)
94
112
  return timeLeft - timeRight;
95
- }
96
113
  if (validLeft !== validRight)
97
114
  return validLeft ? -1 : 1;
98
115
  const key = (entry) => [
@@ -100,127 +117,10 @@ export function auditOrder(entries) {
100
117
  entry.task_id ?? entry.id ?? "",
101
118
  entry.gate_id ?? "",
102
119
  entry.approved === true ? "1" : entry.approved === false ? "0" : "",
103
- ].join("\u0000");
120
+ ].join("\0");
104
121
  const keyDiff = key(left.entry).localeCompare(key(right.entry));
105
122
  return keyDiff !== 0 ? keyDiff : left.index - right.index;
106
123
  })
107
124
  .map(({ entry }) => entry);
108
125
  }
109
- /** Read-only, replayable audit derived from accepted vault events. */
110
- export function auditEntries(loopId, entries) {
111
- const orderedEntries = auditOrder(entries);
112
- const objectiveEntry = [...orderedEntries].reverse().find((entry) => isRecord(entry.loop_objective));
113
- const objective = objectiveEntry && isRecord(objectiveEntry.loop_objective)
114
- ? objectiveEntry.loop_objective
115
- : null;
116
- const declared = objective && Array.isArray(objective.success_criteria)
117
- ? objective.success_criteria.filter((value) => typeof value === "string")
118
- : [];
119
- const evidenced = new Set();
120
- const passed = new Set();
121
- const failed = new Set();
122
- const unavailable = new Set();
123
- const evidenceRefs = new Set();
124
- const gateState = new Map();
125
- const obligations = new Map();
126
- const criterionByTarget = new Map();
127
- for (const criterion of declared) {
128
- const normalized = criterion.trim().replace(/\s+/g, " ").toLowerCase();
129
- criterionByTarget.set(normalized, criterion);
130
- criterionByTarget.set(deriveCriterionId(normalized), criterion);
131
- }
132
- for (const entry of orderedEntries) {
133
- if (entry.task_type === "gate_decision" && typeof entry.gate_id === "string") {
134
- gateState.set(entry.gate_id, entry.approved === true);
135
- }
136
- if (entry.task_type === "gate_opened" && typeof entry.gate_id === "string") {
137
- if (!gateState.has(entry.gate_id))
138
- gateState.set(entry.gate_id, false);
139
- }
140
- const value = report(entry);
141
- const evidence = value && isRecord(value.evidence) ? value.evidence : null;
142
- if (value && isRecord(value.blocker) && typeof value.blocker.reason === "string") {
143
- const refs = Array.isArray(value.blocker.references)
144
- ? value.blocker.references.filter((ref) => typeof ref === "string")
145
- : [];
146
- const derived = isRecord(value.blocker.action)
147
- ? deriveStructuredGate(value.blocker.action)
148
- : deriveGate(value.blocker.reason, refs);
149
- if (derived.gate.kind === "user" && !gateState.has(derived.id)) {
150
- gateState.set(derived.id, false);
151
- }
152
- }
153
- if (!evidence)
154
- continue;
155
- const provenance = isRecord(evidence.provenance) ? evidence.provenance : {};
156
- if (Array.isArray(evidence.claims)) {
157
- for (const raw of evidence.claims) {
158
- if (!isRecord(raw) || typeof raw.targetId !== "string" || !Array.isArray(raw.evidenceRefs) || raw.evidenceRefs.length === 0)
159
- continue;
160
- const refs = raw.evidenceRefs.filter((ref) => typeof ref === "string");
161
- const verified = refs.some((ref) => isRecord(provenance[ref]) &&
162
- provenance[ref].status === "verified" && provenance[ref].source !== "agent");
163
- if (verified) {
164
- const normalizedTarget = raw.targetId.trim().replace(/\s+/g, " ").toLowerCase();
165
- evidenced.add(criterionByTarget.get(normalizedTarget) ?? raw.targetId.trim());
166
- }
167
- for (const ref of refs)
168
- evidenceRefs.add(ref);
169
- }
170
- }
171
- if (Array.isArray(evidence.checks)) {
172
- for (const raw of evidence.checks) {
173
- if (!isRecord(raw) || typeof raw.name !== "string")
174
- continue;
175
- const checkProvenance = provenance[`check:${raw.name}`];
176
- const evidenceStatus = isRecord(checkProvenance)
177
- ? checkProvenance.status
178
- : "unavailable";
179
- const id = `reg-${deriveTextHash(raw.name, 12)}`;
180
- const sourceRound = entryRound(entry);
181
- if (raw.status === "passed" && evidenceStatus === "verified") {
182
- passed.add(raw.name);
183
- failed.delete(raw.name);
184
- unavailable.delete(raw.name);
185
- obligations.set(raw.name, { id, check: raw.name, sourceRound, status: "satisfied" });
186
- }
187
- else if (raw.status === "failed" || evidenceStatus === "contradicted") {
188
- failed.add(raw.name);
189
- passed.delete(raw.name);
190
- unavailable.delete(raw.name);
191
- obligations.set(raw.name, { id, check: raw.name, sourceRound, status: "contradicted" });
192
- }
193
- else {
194
- unavailable.add(raw.name);
195
- passed.delete(raw.name);
196
- obligations.set(raw.name, { id, check: raw.name, sourceRound, status: "open" });
197
- }
198
- }
199
- }
200
- }
201
- const missing = declared.filter((criterion) => !evidenced.has(criterion));
202
- const unresolvedUserGates = [...gateState].filter(([, approved]) => !approved).map(([id]) => id);
203
- const verdict = failed.size > 0 ? "contradicted"
204
- : missing.length || unresolvedUserGates.length || unavailable.size ? "incomplete"
205
- : "passed";
206
- const sequences = entries.map((entry) => entry.event_sequence);
207
- const sequenceValues = sequences.filter((value) => typeof value === "number" && Number.isInteger(value) && value > 0);
208
- const sequenceSet = new Set(sequenceValues);
209
- const sequenceComplete = entries.length === 0
210
- || (sequenceValues.length === entries.length
211
- && sequenceSet.size === entries.length
212
- && Math.min(...sequenceValues) === 1
213
- && Math.max(...sequenceValues) === entries.length
214
- && entries.every((entry) => entry.loop_id === undefined || entry.loop_id === loopId));
215
- return {
216
- loopId,
217
- verdict,
218
- criteria: { declared, evidenced: [...evidenced].sort(), missing },
219
- checks: { passed: [...passed].sort(), failed: [...failed].sort(), unavailable: [...unavailable].sort() },
220
- unresolvedUserGates,
221
- sequenceComplete,
222
- evidenceRefs: [...evidenceRefs].sort(),
223
- regressionObligations: [...obligations.values()].sort((a, b) => a.check.localeCompare(b.check)),
224
- };
225
- }
226
126
  //# sourceMappingURL=cognitive-governance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cognitive-governance.js","sourceRoot":"","sources":["../src/cognitive-governance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGjF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,YAAY,GAAG,IAAI,GAAG,CAA0C;IACpE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,SAAS;IACtE,SAAS,EAAE,wBAAwB;CACpC,CAAC,CAAC;AACH,MAAM,SAAS,GAAG,4LAA4L,CAAC;AAE/M,MAAM,UAAU,sBAAsB,CAAC,MAA4B;IACjE,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE;QACtC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE;QAC5E,OAAO,EAAE,CAAC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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAChE,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC5D,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,59 @@
1
+ /** Canonical read model for committed rounds.
2
+ *
3
+ * Durable documents remain the source of truth. This module is the only
4
+ * place that interprets their transaction envelope or the compiler's merged
5
+ * lineage representation. Consumers receive one stable, read-only view.
6
+ */
7
+ import type { ProviderSnapshot } from "./evidence-provider.js";
8
+ import type { VaultEntry } from "./loop-store.js";
9
+ import type { ExecutionEvidence, PromptArtifact, RoundContract, RoundOutcome, SelfEvaluation, VerificationFlag } from "./protocol.js";
10
+ import type { RoundProcessResult } from "./round-coordinator.js";
11
+ export type CommittedAction = "continue" | "stop" | "backtrack";
12
+ export interface CommittedRoundView {
13
+ readonly source: "feedback" | "merged";
14
+ readonly sourceEntry: VaultEntry | Record<string, unknown>;
15
+ readonly loopId: string;
16
+ readonly round: number;
17
+ readonly roundId: string;
18
+ readonly sequence?: number;
19
+ readonly attempt: number;
20
+ readonly promptArtifact: PromptArtifact | null;
21
+ readonly evaluation: SelfEvaluation | null;
22
+ readonly executionEvidence: ExecutionEvidence | null;
23
+ readonly verificationFlags: VerificationFlag[];
24
+ readonly result: RoundProcessResult | null;
25
+ readonly action: CommittedAction;
26
+ readonly success: boolean;
27
+ readonly outcome: RoundOutcome | null;
28
+ readonly contractProposal: RoundContract | null;
29
+ readonly beforeEvidence: ProviderSnapshot[];
30
+ readonly afterEvidence: ProviderSnapshot[];
31
+ readonly roundEvidence: ProviderSnapshot[];
32
+ /** Normalized round-level declarations used by compiler projections. */
33
+ readonly outputSummary?: string;
34
+ readonly constraintViolations?: string[];
35
+ readonly discoveredConstraints?: string[];
36
+ readonly activeConstraints?: string[];
37
+ readonly retractedConstraints?: string[];
38
+ readonly emergedSubtasks?: string[];
39
+ readonly completedSubtasks?: string[];
40
+ readonly blockedSubtasks?: string[];
41
+ readonly canceledSubtasks?: string[];
42
+ }
43
+ /** Decode a durable :feedback entry. Reject/terminate/in-flight envelopes are
44
+ * not committed history and therefore do not produce a view. */
45
+ export declare function decodeCommittedRound(entry: VaultEntry): CommittedRoundView | null;
46
+ /** Decode an in-memory lineage entry after the engine merged its committed
47
+ * feedback. The merged shape is intentionally accepted only when stamped
48
+ * with committed_action. */
49
+ export declare function decodeMergedRound(entry: unknown): CommittedRoundView | null;
50
+ /** Normalize committed history: rollback directives disappear, later records
51
+ * replace earlier records for the same logical round, and output is ascending. */
52
+ export declare function historyRounds(views: Iterable<CommittedRoundView | null>, beforeRound?: number): CommittedRoundView[];
53
+ export declare function committedRoundsFromEntries(entries: VaultEntry[], beforeRound?: number): CommittedRoundView[];
54
+ export declare function mergedRoundsFromEntries(entries: unknown[], beforeRound?: number): CommittedRoundView[];
55
+ /** Machine-observed git motion for the most recent contiguous window.
56
+ * Consumers must decode durable or hydrated entries before calling this;
57
+ * transaction-envelope interpretation stays confined to this module. */
58
+ export declare function machineGitMotionSeries(rounds: ReadonlyArray<CommittedRoundView>, currentRound: number, lookback: number): boolean[] | null;
59
+ //# sourceMappingURL=committed-round.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"committed-round.d.ts","sourceRoot":"","sources":["../src/committed-round.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,gBAAgB,EACj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+ *
3
+ * Durable documents remain the source of truth. This module is the only
4
+ * place that interprets their transaction envelope or the compiler's merged
5
+ * lineage representation. Consumers receive one stable, read-only view.
6
+ */
7
+ import { parseRoundTransactionSnapshot } from "./round-transaction.js";
8
+ import { effectiveOutcome, parseRoundContract } from "./self-eval.js";
9
+ import { entryRound, isRecord } from "./token-utils.js";
10
+ function committedAction(value) {
11
+ return value === "continue" || value === "stop" || value === "backtrack"
12
+ ? value
13
+ : null;
14
+ }
15
+ function snapshots(value) {
16
+ return Array.isArray(value) ? value : [];
17
+ }
18
+ function flags(value) {
19
+ return Array.isArray(value) ? value : [];
20
+ }
21
+ function roundOutcome(value) {
22
+ return value === "success" || value === "partial" ||
23
+ value === "failed" || value === "blocked"
24
+ ? value
25
+ : null;
26
+ }
27
+ function strings(value) {
28
+ return Array.isArray(value)
29
+ ? value.filter((item) => typeof item === "string")
30
+ : [];
31
+ }
32
+ /** Decode a durable :feedback entry. Reject/terminate/in-flight envelopes are
33
+ * not committed history and therefore do not produce a view. */
34
+ export function decodeCommittedRound(entry) {
35
+ if (!String(entry.task_id ?? "").endsWith(":feedback"))
36
+ return null;
37
+ const lineage = isRecord(entry.loop_lineage) ? entry.loop_lineage : null;
38
+ const transaction = lineage && isRecord(lineage.round_transaction)
39
+ ? lineage.round_transaction
40
+ : null;
41
+ if (!transaction)
42
+ return null;
43
+ const snapshot = parseRoundTransactionSnapshot(transaction.snapshot);
44
+ if (snapshot && snapshot.phase !== "committed")
45
+ return null;
46
+ const resultValue = isRecord(transaction.result)
47
+ ? transaction.result
48
+ : snapshot?.result;
49
+ if (!isRecord(resultValue))
50
+ return null;
51
+ const action = committedAction(resultValue.action);
52
+ if (!action)
53
+ return null;
54
+ const result = resultValue;
55
+ const round = snapshot?.round ?? entryRound(entry);
56
+ const loopId = snapshot?.loopId ?? String(entry.loop_id ?? lineage?.loop_id ?? "");
57
+ if (round < 1 || !loopId)
58
+ return null;
59
+ const evaluation = snapshot?.evaluation ?? null;
60
+ const outcome = evaluation ? effectiveOutcome(evaluation) : null;
61
+ const sequence = typeof entry.sequence === "number" ? entry.sequence : undefined;
62
+ return {
63
+ source: "feedback",
64
+ sourceEntry: entry,
65
+ loopId,
66
+ round,
67
+ roundId: snapshot?.roundId ?? String(transaction.round_id ?? `loop:${loopId}:round:${round}`),
68
+ sequence,
69
+ attempt: snapshot?.attempt ?? 1,
70
+ promptArtifact: snapshot?.promptArtifact ?? null,
71
+ evaluation,
72
+ executionEvidence: evaluation?.execution_evidence ?? null,
73
+ verificationFlags: flags(result.verificationFlags),
74
+ result,
75
+ action,
76
+ success: result.roundSuccess === true,
77
+ outcome,
78
+ contractProposal: evaluation?.round_contract
79
+ ? parseRoundContract(evaluation.round_contract) ?? null
80
+ : null,
81
+ beforeEvidence: snapshots(snapshot?.beforeEvidence),
82
+ afterEvidence: snapshots(snapshot?.afterEvidence),
83
+ roundEvidence: snapshots(snapshot?.roundEvidence),
84
+ outputSummary: evaluation?.output_summary,
85
+ constraintViolations: strings(evaluation?.constraint_violations),
86
+ discoveredConstraints: strings(evaluation?.discovered_constraints),
87
+ activeConstraints: strings(lineage?.constraints_active),
88
+ retractedConstraints: strings(evaluation?.retracted_constraints),
89
+ emergedSubtasks: strings(evaluation?.emerged_subtasks),
90
+ completedSubtasks: strings(evaluation?.completed_subtasks),
91
+ blockedSubtasks: strings(evaluation?.blocked_subtasks),
92
+ canceledSubtasks: strings(evaluation?.canceled_subtasks),
93
+ };
94
+ }
95
+ /** Decode an in-memory lineage entry after the engine merged its committed
96
+ * feedback. The merged shape is intentionally accepted only when stamped
97
+ * with committed_action. */
98
+ export function decodeMergedRound(entry) {
99
+ if (!isRecord(entry))
100
+ return null;
101
+ const raw = entry;
102
+ const lineageValue = raw.loop_lineage ?? raw.lineage;
103
+ const lineage = isRecord(lineageValue) ? lineageValue : {};
104
+ const action = committedAction(lineage.committed_action ?? raw.committed_action);
105
+ if (!action)
106
+ return null;
107
+ const round = entryRound(raw);
108
+ if (round < 1)
109
+ return null;
110
+ const loopId = typeof raw.loop_id === "string"
111
+ ? raw.loop_id
112
+ : typeof lineage.loop_id === "string" ? lineage.loop_id : "";
113
+ const roundId = typeof lineage.round_id === "string"
114
+ ? lineage.round_id
115
+ : `loop:${loopId}:round:${round}`;
116
+ const evaluationRaw = {};
117
+ const evaluationKeys = [
118
+ "success", "output_summary", "constraint_violations", "should_continue",
119
+ "discovered_constraints", "objective_refinement", "emerged_subtasks",
120
+ "execution_evidence", "retracted_constraints", "revised_success_criteria",
121
+ "wrong_assumptions", "worker_results", "compression_checkpoint",
122
+ "checkpoint_label", "next_action", "completed_subtasks", "blocked_subtasks",
123
+ "canceled_subtasks", "stop_reason", "outcome", "blocker",
124
+ "retroactiveClaims", "no_change_reason", "drift_clarification",
125
+ "prompt_requests", "round_contract",
126
+ ];
127
+ let hasEvaluation = false;
128
+ for (const key of evaluationKeys) {
129
+ const value = raw[key] ?? lineage[key];
130
+ if (value !== undefined) {
131
+ evaluationRaw[key] = value;
132
+ hasEvaluation = true;
133
+ }
134
+ }
135
+ const evaluation = hasEvaluation
136
+ ? evaluationRaw
137
+ : null;
138
+ const resultRaw = isRecord(lineage.result) ? lineage.result : null;
139
+ const result = resultRaw ? resultRaw : null;
140
+ const outcome = roundOutcome(evaluationRaw.outcome) ??
141
+ (typeof evaluationRaw.success === "boolean"
142
+ ? evaluationRaw.success ? "success" : "failed"
143
+ : null);
144
+ const proposal = parseRoundContract(evaluationRaw.round_contract) ?? null;
145
+ const executionEvidence = isRecord(evaluationRaw.execution_evidence)
146
+ ? evaluationRaw.execution_evidence
147
+ : null;
148
+ return {
149
+ source: "merged",
150
+ sourceEntry: raw,
151
+ loopId,
152
+ round,
153
+ roundId,
154
+ sequence: typeof lineage.sequence === "number" ? lineage.sequence : undefined,
155
+ attempt: typeof lineage.attempt === "number" ? lineage.attempt : 1,
156
+ promptArtifact: isRecord(lineage.prompt_artifact)
157
+ ? lineage.prompt_artifact
158
+ : null,
159
+ evaluation,
160
+ executionEvidence,
161
+ verificationFlags: flags(raw.verification_flags ?? lineage.verification_flags),
162
+ result,
163
+ action,
164
+ success: typeof raw.success === "boolean"
165
+ ? raw.success
166
+ : typeof lineage.success === "boolean" ? lineage.success : false,
167
+ outcome,
168
+ contractProposal: proposal,
169
+ beforeEvidence: snapshots(lineage.before_evidence),
170
+ afterEvidence: snapshots(lineage.after_evidence),
171
+ roundEvidence: snapshots(lineage.round_evidence),
172
+ outputSummary: typeof evaluationRaw.output_summary === "string"
173
+ ? evaluationRaw.output_summary
174
+ : undefined,
175
+ constraintViolations: strings(evaluationRaw.constraint_violations),
176
+ discoveredConstraints: strings(evaluationRaw.discovered_constraints),
177
+ activeConstraints: strings(raw.constraints_active ?? lineage.constraints_active),
178
+ retractedConstraints: strings(evaluationRaw.retracted_constraints),
179
+ emergedSubtasks: strings(evaluationRaw.emerged_subtasks),
180
+ completedSubtasks: strings(evaluationRaw.completed_subtasks),
181
+ blockedSubtasks: strings(evaluationRaw.blocked_subtasks),
182
+ canceledSubtasks: strings(evaluationRaw.canceled_subtasks),
183
+ };
184
+ }
185
+ /** Normalize committed history: rollback directives disappear, later records
186
+ * replace earlier records for the same logical round, and output is ascending. */
187
+ export function historyRounds(views, beforeRound = Number.POSITIVE_INFINITY) {
188
+ const byRound = new Map();
189
+ for (const view of views) {
190
+ if (!view || view.action === "backtrack" || view.round >= beforeRound)
191
+ continue;
192
+ byRound.set(view.round, view);
193
+ }
194
+ return [...byRound.values()].sort((a, b) => a.round - b.round);
195
+ }
196
+ export function committedRoundsFromEntries(entries, beforeRound = Number.POSITIVE_INFINITY) {
197
+ return historyRounds(entries.map(decodeCommittedRound), beforeRound);
198
+ }
199
+ export function mergedRoundsFromEntries(entries, beforeRound = Number.POSITIVE_INFINITY) {
200
+ return historyRounds(entries.map(decodeMergedRound), beforeRound);
201
+ }
202
+ /** Machine-observed git motion for the most recent contiguous window.
203
+ * Consumers must decode durable or hydrated entries before calling this;
204
+ * transaction-envelope interpretation stays confined to this module. */
205
+ export function machineGitMotionSeries(rounds, currentRound, lookback) {
206
+ const byRound = new Map();
207
+ for (const round of rounds) {
208
+ if (round.round < 1 || round.round >= currentRound)
209
+ continue;
210
+ const git = round.roundEvidence.find((snapshot) => snapshot.provider === "git");
211
+ if (!git)
212
+ continue;
213
+ byRound.set(round.round, Array.isArray(git.files) && git.files.length > 0);
214
+ }
215
+ if (byRound.size < lookback)
216
+ return null;
217
+ const recent = [...byRound.keys()].sort((a, b) => a - b).slice(-lookback);
218
+ if (recent[0] < currentRound - lookback)
219
+ return null;
220
+ return recent.map((round) => byRound.get(round));
221
+ }
222
+ //# sourceMappingURL=committed-round.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"committed-round.js","sourceRoot":"","sources":["../src/committed-round.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAoCxD,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,WAAW;QACtE,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAA2B,CAAC,CAAC,CAAC,EAAE,CAAC;AACjE,CAAC;AAED,SAAS,KAAK,CAAC,KAAc;IAC3B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAA2B,CAAC,CAAC,CAAC,EAAE,CAAC;AACjE,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAA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AAE,CAAC,QAAQ,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC;QAChF,IAAI,CAAC,GAAG;YAAE,SAAS;QACnB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7E,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,GAAG,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,MAAM,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC1E,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,QAAQ;QAAE,OAAO,IAAI,CAAC;IACrD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,78 @@
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 "./loop-store.js";
20
+ import type { EnforcementResult, SelfEvaluation, VerificationFlag, VerificationResult } from "./protocol.js";
21
+ /** Scan backwards from currentRound to find the most recent clean round.
22
+ * Collects discovered_constraints from skipped rounds along the way.
23
+ * Returns null when no clean round is found within maxDepth. */
24
+ export declare function findSafeRestorePoint(currentRound: number, vaultEntries: VaultEntry[], maxDepth: number): {
25
+ round: number;
26
+ skippedDiscoveries: string[];
27
+ } | null;
28
+ /** v2.12: Git HEAD commit hash at the restore point. Read from the restore
29
+ * round's committed transaction snapshot (after evidence preferred, before
30
+ * evidence as fallback). Returns null when the round has no git snapshot
31
+ * or no committed feedback entry. */
32
+ export declare function findBacktrackTargetGitHead(restoreRound: number, vaultEntries: VaultEntry[]): string | null;
33
+ /** Build the backtrack prompt injected at the top of the restored round.
34
+ *
35
+ * v2.13: Includes concrete workspace restore instructions with affected
36
+ * file lists from skipped rounds. The agent must restore the working tree
37
+ * to the clean round's state before proceeding. */
38
+ export declare function buildBacktrackPrompt(fromRound: number, toRound: number, triggerRule: string, skippedDiscoveries: string[],
39
+ /** v2.13: Files changed in the skipped rounds (from evidence snapshots).
40
+ * Used to show the agent exactly what needs to be reverted. */
41
+ skippedFiles?: string[],
42
+ /** v2.12: Git HEAD commit hash at the backtrack point (current HEAD).
43
+ * The agent must discard work back to the clean round's state. */
44
+ gitHead?: string): string;
45
+ /** Enforce round-boundary rules based on the verification gate's findings
46
+ * and the agent's self-evaluation integrity.
47
+ *
48
+ * Rules run in priority order — the rules array below IS the priority
49
+ * order; numeric IDs (R1–R9, R-EVID) reflect insertion history, not
50
+ * priority. The first rule that fires wins.
51
+ *
52
+ * @param selfEval The agent's self-evaluation for the current round.
53
+ * @param verifyResult The verification gate's output (from verifySelfEvaluation).
54
+ * @param currentRound Current round number (1-based, BEFORE increment).
55
+ * @param vaultEntries Vault entries for this loop (used for progress tracking).
56
+ * @param consecutiveRejections How many consecutive rounds have already been rejected.
57
+ * Starts at 0; increments on each reject; resets on accept.
58
+ */
59
+ export declare function enforceRound(selfEval: SelfEvaluation, verifyResult: VerificationResult, currentRound: number, vaultEntries: VaultEntry[], consecutiveRejections?: number,
60
+ /** v2.12: Current clarification streak for R7 escalation. */
61
+ driftClarificationStreak?: number): EnforcementResult;
62
+ /** Build a rejection prompt for the agent.
63
+ *
64
+ * The prompt clearly states the round was rejected, why, what the agent
65
+ * must fix, and that the agent must redo the SAME round (not advance).
66
+ *
67
+ * v2.7: Accepts verificationFlags to render a diagnostic "Evidence Gap"
68
+ * section. Each error/warn flag becomes a concrete claim-vs-evidence
69
+ * mismatch statement so the agent knows exactly what to correct rather
70
+ * than retrying blindly.
71
+ *
72
+ * @param currentRound The round number that was rejected (NOT incremented).
73
+ * @param task The original loop task description.
74
+ * @param enforceResult The enforcement decision with reason and fix instructions.
75
+ * @param verificationFlags The verification gate's findings for this round.
76
+ * Used to build the Evidence Gap section. */
77
+ export declare function buildRejectionPrompt(currentRound: number, task: string, enforceResult: EnforcementResult, verificationFlags?: VerificationFlag[]): string;
78
+ //# sourceMappingURL=enforcement-gate.d.ts.map