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
@@ -0,0 +1,80 @@
1
+ import { deriveItemId, jaccardSimilarity } from "./token-utils.js";
2
+ import { getPolicy } from "./policy.js";
3
+ // ── Criterion reference matching ──────────────────────────────────────────
4
+ // Mirrors criteriaMatch (loop-compiler.ts) without importing loop-compiler
5
+ // (round-contract is imported BY loop-compiler — importing back would be a
6
+ // cycle). Parity is locked by round-contract.test.ts.
7
+ const CRITERION_ID_RE = /^cr-[a-f0-9]{8}$/;
8
+ function isCriterionId(ref) {
9
+ return CRITERION_ID_RE.test(ref);
10
+ }
11
+ function deriveCriterionId(text) {
12
+ return "cr-" + deriveItemId(text);
13
+ }
14
+ /** Match two done_when / met-claim references for completion testing.
15
+ * cr-ID-aware + Jaccard fallback, identical to criteriaMatch. */
16
+ export function contractItemMatches(a, b) {
17
+ const aIsId = isCriterionId(a);
18
+ const bIsId = isCriterionId(b);
19
+ if (aIsId && bIsId)
20
+ return a === b;
21
+ if (aIsId)
22
+ return a === deriveCriterionId(b);
23
+ if (bIsId)
24
+ return deriveCriterionId(a) === b;
25
+ return jaccardSimilarity(a, b) >= getPolicy().evolution.criteria_dedup_threshold;
26
+ }
27
+ /** Whether every done_when item of `contract` matches a claim in `met`.
28
+ * Vacuous when done_when is empty (such contracts were already warned
29
+ * round_underspecified at declaration; they close at the first eval
30
+ * committed while active). */
31
+ export function contractDoneWhenSatisfied(contract, met) {
32
+ if (contract.done_when.length === 0)
33
+ return true;
34
+ return contract.done_when.every((item) => met.some((claim) => contractItemMatches(item, claim)));
35
+ }
36
+ /** Walk committed evals (ASCENDING by round; the caller already restricts
37
+ * them to rounds earlier than the compile/verify round) and return the
38
+ * ACTIVE contract for the round after the last committed one — null means
39
+ * the Current Task falls back to the original task text.
40
+ *
41
+ * State machine per committed eval r, with `active` the contract carried
42
+ * into r (null = whole-task round):
43
+ * - active && r.outcome === "blocked" → active = r.proposal
44
+ * - active && all done_when in r.met → active = r.proposal
45
+ * - active && neither → active unchanged (r's
46
+ * different proposal is a premature replacement and is ignored)
47
+ * - !active → active = r.proposal
48
+ * (a proposal never activates on its own declaration round — it becomes
49
+ * active only for the rounds that follow the commit). */
50
+ export function deriveActiveRoundContract(committed) {
51
+ let active = null;
52
+ for (const r of committed) {
53
+ if (active === null) {
54
+ active = r.proposal ?? null;
55
+ continue;
56
+ }
57
+ if (r.outcome === "blocked") {
58
+ active = r.proposal ?? null;
59
+ continue;
60
+ }
61
+ if (contractDoneWhenSatisfied(active, r.met)) {
62
+ active = r.proposal ?? null;
63
+ continue;
64
+ }
65
+ // active !== null and not closed — it continues; r's proposal (if any)
66
+ // is a premature replacement and is ignored.
67
+ }
68
+ return active;
69
+ }
70
+ /** Narrow the shared committed-round view to the contract state machine's
71
+ * inputs. Contract code never interprets persistence envelopes itself. */
72
+ export function contractRoundEvaluations(rounds) {
73
+ return rounds.map((view) => ({
74
+ round: view.round,
75
+ proposal: view.contractProposal,
76
+ outcome: view.outcome,
77
+ met: view.executionEvidence?.success_criteria_met ?? [],
78
+ }));
79
+ }
80
+ //# sourceMappingURL=round-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"round-contract.js","sourceRoot":"","sources":["../src/round-contract.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAaxC,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AAC3E,sDAAsD;AAEtD,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C,SAAS,aAAa,CAAC,GAAW;IAChC,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;kEACkE;AAClE,MAAM,UAAU,mBAAmB,CAAC,CAAS,EAAE,CAAS;IACtD,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,KAAK,IAAI,KAAK;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,KAAK;QAAE,OAAO,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC7C,IAAI,KAAK;QAAE,OAAO,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7C,OAAO,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC,SAAS,CAAC,wBAAwB,CAAC;AACnF,CAAC;AAED;;;+BAG+B;AAC/B,MAAM,UAAU,yBAAyB,CACvC,QAAuB,EACvB,GAAa;IAEb,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACjD,OAAO,QAAQ,CAA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oordinator is the single source of truth for this pipeline;
9
- * transport adapters only prepare input and route the resulting decision.
8
+ * Before this module, runtime.ts and session.ts each maintained their
9
+ * own copy of the pipeline (~60 lines each). Drift between the two
10
+ * paths (e.g. git verification only wired into one side) was a known
11
+ * risk. The RoundCoordinator is the single source of truth.
10
12
  *
11
13
  * State transitions:
12
14
  * RoundStarted → EvidenceCaptured → EvaluationSubmitted
@@ -17,17 +19,17 @@
17
19
  */
18
20
  import type { LoopStore } from "./loop-store.js";
19
21
  import type { ProviderSnapshot } from "./evidence-provider.js";
20
- import type { CompilerRoundProjection, RoundReport, StopReason, VerificationFlag } from "./protocol.js";
22
+ import type { SelfEvaluation, StopReason, VerificationFlag } from "./protocol.js";
21
23
  /** Input to a single round processing step. */
22
24
  export interface RoundProcessInput {
23
25
  loopId: string;
24
26
  task: string;
25
27
  currentRound: number;
26
28
  maxRounds: number;
27
- /** The normalized Agent report for this round. */
28
- roundReport: RoundReport;
29
- /** Previous accepted compiler projection (null for round 1). */
30
- previousProjection?: CompilerRoundProjection;
29
+ /** The agent's self-evaluation for this round. */
30
+ selfEval: SelfEvaluation;
31
+ /** The previous round's validated SelfEvaluation (null for round 1). */
32
+ lastSelfEval?: SelfEvaluation;
31
33
  /** How many consecutive rounds have been rejected by enforcement. */
32
34
  consecutiveRejections: number;
33
35
  /** v1.18: Evidence snapshots from configured providers. */
@@ -37,15 +39,9 @@ export interface RoundProcessInput {
37
39
  /** v2.13: Files from skipped backtrack rounds. Passed to verification
38
40
  * gate for post-backtrack workspace restore check. */
39
41
  backtrackSkippedFiles?: string[];
40
- /** v2.13: Git HEAD of the active backtrack restore point. Passed to the
41
- * verification gate; the post-backtrack round must match it. */
42
+ /** v2.12: Git HEAD of the backtrack restore point. The verification gate
43
+ * checks the workspace returns to this commit before accepting work. */
42
44
  backtrackTargetGitHead?: string;
43
- /** Runtime-derived action from the prompt being completed. */
44
- expectedAction?: string;
45
- /** Terminal enforcement checks that already consumed their guided retry. */
46
- escalatedRejectionChecks?: string[];
47
- /** Criteria still open when the report was compiled. */
48
- remainingCriteria?: string[];
49
45
  }
50
46
  /** Result of processing a round through the coordinator. */
51
47
  export interface RoundProcessResult {
@@ -69,7 +65,7 @@ export interface RoundProcessResult {
69
65
  enforcementAction?: "accept" | "reject" | "terminate" | "backtrack";
70
66
  /** Enforcement reason (set when rejected or terminated). */
71
67
  enforcementReason?: string;
72
- /** Whether this round was successful according to the canonical report. */
68
+ /** Whether this round was successful (from selfEval.success). */
73
69
  roundSuccess: boolean;
74
70
  /** Whether the verification gate returned "contradicted". */
75
71
  gateContradicted: boolean;
@@ -78,17 +74,19 @@ export interface RoundProcessResult {
78
74
  /** Which enforcement check fired (set when action is "reject" or "terminate").
79
75
  * Used by callers to track per-rule rejection counters. */
80
76
  rejectionCheck?: string;
81
- /** The compiler view to store as lastRoundView for the next round
77
+ /** The selfEval to store as lastSelfEval for the next round
82
78
  * (undefined when action is "reject" — caller should NOT update). */
83
- newRoundProjection?: CompilerRoundProjection;
79
+ newLastSelfEval?: SelfEvaluation;
84
80
  /** Whether the caller should push roundSuccess onto the success trajectory.
85
81
  * false when gateContradicted or when action is "reject". */
86
82
  shouldPushSuccessTrajectory: boolean;
87
83
  /** v2.12: True when this round's intent_drift was waived via substantive
88
- * drift_clarification. The caller uses this to track clarification streaks. */
84
+ * drift_clarification. The caller uses this to track clarification streaks.
85
+ * v3.3.1: false when R7 itself rejected/terminated on a weak or missing
86
+ * clarification (the caller increments the streak); undefined when R7 did
87
+ * not participate in the decision — a higher-priority rule's rejection
88
+ * must never touch the streak. */
89
89
  clarificationAccepted?: boolean;
90
- /** True when a terminal enforcement rule was converted into one final reject. */
91
- escalationIssued?: boolean;
92
90
  /** v2.13: Git HEAD commit hash of the backtrack target round.
93
91
  * Set when action is "backtrack". The verification gate uses this
94
92
  * to check that the agent restored the workspace before working. */
@@ -99,9 +97,9 @@ export interface RoundProcessResult {
99
97
  backtrackSkippedFiles?: string[];
100
98
  }
101
99
  export declare class RoundCoordinator {
102
- private backend;
103
- constructor(backend?: LoopStore);
104
- /** Process a single round's round report through the decision pipeline:
100
+ private store;
101
+ constructor(store?: LoopStore);
102
+ /** Process a single round's self-evaluation through the decision pipeline:
105
103
  * verify → enforce → stop decision.
106
104
  *
107
105
  * This is the single entry point called by SessionManager.
@@ -109,7 +107,7 @@ export declare class RoundCoordinator {
109
107
  * - Compiling the next prompt (if action is "continue")
110
108
  * - Managing heartbeat / signal handlers (runtime only)
111
109
  * - Memory injection (both paths, before calling processRound)
112
- * - Transactional round-event commit (accepted rounds only)
110
+ * - Transactional feedback commit (accepted rounds only)
113
111
  * - State file I/O (both paths, after compiling)
114
112
  *
115
113
  * @param driftClarificationStreak v2.12: Current clarification streak
@@ -1 +1 @@
1
- {"version":3,"file":"round-coordinator.d.ts","sourceRoot":"","sources":["../src/round-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EACV,uBAAuB,EAEvB,WAAW,EACX,UAAU,EACV,gBAAgB,EAEjB,MAAM,eAAe,CAAC;AAiBvB,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,WAAW,EAAE,WAAW,CAAC;IACzB,gEAAgE;IAChE,kBAAkB,CAAC,EAAE,uBAAuB,CAAC;IAC7C,qEAAqE;IACrE,qBAAqB,EAAE,MAAM,CAAC;IAC9B,2DAA2D;IAC3D,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACvC,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,OAAO,EAAE,CAAC;IAC9B;2DACuD;IACvD,q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KAAK,CAAC,EAAE,SAAS;IAI7B;;;;;;;;;;;;gFAY4E;IAC5E,YAAY,CACV,KAAK,EAAE,iBAAiB,EACxB,wBAAwB,GAAE,MAAU,GACnC,kBAAkB;CAsRtB"}
@@ -5,8 +5,10 @@
5
5
  *
6
6
  * verify → enforce → stop decision
7
7
  *
8
- * The RoundCoordinator is the single source of truth for this pipeline;
9
- * transport adapters only prepare input and route the resulting decision.
8
+ * Before this module, runtime.ts and session.ts each maintained their
9
+ * own copy of the pipeline (~60 lines each). Drift between the two
10
+ * paths (e.g. git verification only wired into one side) was a known
11
+ * risk. The RoundCoordinator is the single source of truth.
10
12
  *
11
13
  * State transitions:
12
14
  * RoundStarted → EvidenceCaptured → EvaluationSubmitted
@@ -15,18 +17,31 @@
15
17
  * Persistence is owned by round-transaction.ts so reject paths remain
16
18
  * side-effect free and accepted decisions can be replayed idempotently.
17
19
  */
18
- import { makeRoundGateContext, verifyRoundReport, enforceRoundReport } from "./round-gate.js";
19
- import { buildRejectionPrompt, collectSkippedRoundFiles, findSafeRestorePoint, buildBacktrackPrompt, findBacktrackTargetGitHead, } from "./round-recovery.js";
20
+ import { queryLoopEntries } from "./loop-store.js";
21
+ import { CHECK_SUCCESS_WITHOUT_VERIFIED_EVIDENCE, verifySelfEvaluation, entryRound } from "./verification-gate.js";
22
+ import { effectiveSuccess } from "./self-eval.js";
23
+ import { enforceRound, buildRejectionPrompt, findSafeRestorePoint, buildBacktrackPrompt, findBacktrackTargetGitHead, } from "./enforcement-gate.js";
20
24
  import { logEvent } from "./observability.js";
21
25
  import { getPolicy } from "./policy.js";
22
- import { deriveCompilerProjection } from "./round-report.js";
26
+ /** v3.2/v3.6: Whether a round's success enters the success trajectory.
27
+ * Excluded when the gate contradicted the round, or when the success claim
28
+ * carries no machine-verified observation — the merged R8 check fires a
29
+ * warn under machine_backed_success "warn" (v3.6: success_unverified merged
30
+ * into R8; its warn-level trajectory exclusion moved with it) — an
31
+ * accepted-but-unverified round is not evidence of progress. */
32
+ function shouldPushSuccess(gateContradicted, verificationFlags) {
33
+ if (gateContradicted)
34
+ return false;
35
+ return !verificationFlags.some((flag) => flag.severity === "warn" &&
36
+ flag.check === CHECK_SUCCESS_WITHOUT_VERIFIED_EVIDENCE);
37
+ }
23
38
  // ── RoundCoordinator ───────────────────────────────────────────────────────
24
39
  export class RoundCoordinator {
25
- backend;
26
- constructor(backend) {
27
- this.backend = backend;
40
+ store;
41
+ constructor(store) {
42
+ this.store = store;
28
43
  }
29
- /** Process a single round's round report through the decision pipeline:
44
+ /** Process a single round's self-evaluation through the decision pipeline:
30
45
  * verify → enforce → stop decision.
31
46
  *
32
47
  * This is the single entry point called by SessionManager.
@@ -34,36 +49,30 @@ export class RoundCoordinator {
34
49
  * - Compiling the next prompt (if action is "continue")
35
50
  * - Managing heartbeat / signal handlers (runtime only)
36
51
  * - Memory injection (both paths, before calling processRound)
37
- * - Transactional round-event commit (accepted rounds only)
52
+ * - Transactional feedback commit (accepted rounds only)
38
53
  * - State file I/O (both paths, after compiling)
39
54
  *
40
55
  * @param driftClarificationStreak v2.12: Current clarification streak
41
56
  * from session state. Passed through to enforceRound for R7 escalation. */
42
57
  processRound(input, driftClarificationStreak = 0) {
43
- const { loopId, task, currentRound, maxRounds, roundReport: suppliedReport, previousProjection, consecutiveRejections, evidenceSnapshots, } = input;
44
- const roundReport = suppliedReport;
45
- const roundSuccess = roundReport.outcome === "success";
58
+ const { loopId, task, currentRound, maxRounds, selfEval, lastSelfEval, consecutiveRejections, evidenceSnapshots, } = input;
59
+ const roundSuccess = selfEval.success ?? false;
46
60
  // ── 1. Query vault entries ──────────────────────────────────────────
47
- // Merge lineage and canonical RoundEvent entries for replayable checks.
61
+ // Lineage entries (constraint violations, output summaries) and feedback
62
+ // entries (execution_evidence, progress estimates) are both needed by
63
+ // the enforcement gate. queryLoopEntries excludes feedback by default,
64
+ // so we issue a second query and merge both result sets.
48
65
  const prefix = `loop:${loopId}:r`;
49
- const vaultEntries = this.backend
50
- ? this.backend.queryLoopEvents(loopId).filter((entry) => String(entry.task_id ?? "").startsWith(prefix))
66
+ const vaultEntries = this.store
67
+ ? [
68
+ ...queryLoopEntries(this.store, loopId, { prefix }),
69
+ ...queryLoopEntries(this.store, loopId, { prefix, feedbackOnly: true }),
70
+ ]
51
71
  : [];
52
72
  // ── 2. Verification gate ────────────────────────────────────────────
53
- const gateContext = makeRoundGateContext(roundReport, currentRound, vaultEntries, evidenceSnapshots ?? [], input.remainingCriteria ?? [], {
54
- previous: previousProjection ?? null,
55
- expectedAction: input.expectedAction,
56
- backtrackSkippedFiles: input.backtrackSkippedFiles,
57
- backtrackTargetGitHead: input.backtrackTargetGitHead,
58
- consecutiveRejections,
59
- driftClarificationStreak,
60
- escalatedRejectionChecks: input.escalatedRejectionChecks,
61
- });
62
- const currentProjection = deriveCompilerProjection(roundReport, currentRound, input.remainingCriteria ?? [], evidenceSnapshots ?? []);
63
- const verifyResult = verifyRoundReport(gateContext);
73
+ const verifyResult = verifySelfEvaluation(selfEval, currentRound, vaultEntries, lastSelfEval ?? null, evidenceSnapshots ?? [], input.backtrackSkippedFiles ?? [], input.backtrackTargetGitHead);
64
74
  const verificationFlags = verifyResult.flags;
65
75
  const gateContradicted = verifyResult.verdict === "contradicted";
66
- const clarificationAccepted = verificationFlags.some((item) => item.check === "intent_drift" && item.severity === "warn");
67
76
  if (gateContradicted) {
68
77
  logEvent("gate_contradicted", {
69
78
  loopId,
@@ -72,8 +81,12 @@ export class RoundCoordinator {
72
81
  });
73
82
  }
74
83
  // ── 3. Enforcement gate ──────────────────────────────────────────
75
- // Enforcement consumes the same normalized Gate context as verification.
76
- const enforceResult = enforceRoundReport(gateContext, verifyResult);
84
+ // v3.3.1: extraction failures stall the round upstream (round-lifecycle,
85
+ // v2.6 design — the runtime never guesses state from text), so every
86
+ // transaction reaches enforcement with a fully extracted self-evaluation.
87
+ // The old v2.5 "heuristic partial enforcement" plumbing (extractionSucceeded
88
+ // flag, enforcement skipEvidenceRules mode) was removed as unreachable.
89
+ const enforceResult = enforceRound(selfEval, verifyResult, currentRound, vaultEntries, consecutiveRejections, driftClarificationStreak);
77
90
  if (enforceResult.action === "reject") {
78
91
  const newRejections = consecutiveRejections + 1;
79
92
  const rejectionPrompt = buildRejectionPrompt(currentRound, task, enforceResult, verificationFlags);
@@ -91,13 +104,22 @@ export class RoundCoordinator {
91
104
  enforcementAction: "reject",
92
105
  enforcementReason: enforceResult.reason,
93
106
  rejectionCheck: enforceResult.check,
107
+ // v3.3.1: an R7-participated reject (weak or missing
108
+ // drift_clarification) echoes clarificationAccepted: false so the
109
+ // caller's streak tracking increments — without this the
110
+ // drift_clarification_max_streak terminate ladder was unreachable
111
+ // (the increment branch required the field, and only the continue
112
+ // path ever set it). Higher-priority rules' rejects keep it
113
+ // undefined, preserving the v3.2.1 "R7-only streak" semantics.
114
+ ...(enforceResult.check === "intent_drift"
115
+ ? { clarificationAccepted: false }
116
+ : {}),
94
117
  roundSuccess,
95
118
  gateContradicted,
96
119
  newConsecutiveRejections: newRejections,
97
- // Don't update lastRoundView on reject — the agent redoes the same round
98
- newRoundProjection: undefined,
120
+ // Don't update lastSelfEval on reject — the agent redoes the same round
121
+ newLastSelfEval: undefined,
99
122
  shouldPushSuccessTrajectory: false,
100
- escalationIssued: enforceResult.escalation_issued ?? false,
101
123
  };
102
124
  }
103
125
  if (enforceResult.action === "terminate") {
@@ -113,10 +135,16 @@ export class RoundCoordinator {
113
135
  enforcementAction: "terminate",
114
136
  enforcementReason: enforceResult.reason,
115
137
  rejectionCheck: enforceResult.check,
138
+ // v3.3.1: same echo as the reject branch — R7-participated
139
+ // terminates keep the streak contract consistent for the
140
+ // snapshot/audit record (harmless: the session is ending).
141
+ ...(enforceResult.check === "intent_drift"
142
+ ? { clarificationAccepted: false }
143
+ : {}),
116
144
  roundSuccess,
117
145
  gateContradicted,
118
146
  newConsecutiveRejections: 0,
119
- newRoundProjection: currentProjection,
147
+ newLastSelfEval: selfEval,
120
148
  shouldPushSuccessTrajectory: false,
121
149
  };
122
150
  }
@@ -141,18 +169,34 @@ export class RoundCoordinator {
141
169
  roundSuccess,
142
170
  gateContradicted,
143
171
  newConsecutiveRejections: 0,
144
- newRoundProjection: currentProjection,
172
+ newLastSelfEval: selfEval,
145
173
  shouldPushSuccessTrajectory: false,
146
174
  };
147
175
  }
148
- // Collect files changed in skipped rounds for the restore prompt.
149
- const skippedFiles = collectSkippedRoundFiles(restorePoint.round, currentRound, vaultEntries);
150
- // v2.13: Git HEAD the workspace must be restored to. Taken from the
151
- // restore round's committed transaction snapshot.
152
- const backtrackTargetGitHead = findBacktrackTargetGitHead(restorePoint.round, vaultEntries);
176
+ // v2.13: Collect files changed in skipped rounds for the restore prompt
177
+ const skippedFiles = [];
178
+ for (let r = restorePoint.round + 1; r < currentRound; r++) {
179
+ // v3.2.1: match the feedback entry (execution_evidence lives there) —
180
+ // the compile-time lineage entry for the same round precedes it in
181
+ // the flat view and carries no evidence.
182
+ const entry = vaultEntries.find((e) => entryRound(e) === r && e.task_type !== "loop_lineage");
183
+ if (entry?.execution_evidence) {
184
+ const ev = entry.execution_evidence;
185
+ const files = Array.isArray(ev.files_changed)
186
+ ? ev.files_changed.filter((f) => typeof f === "string")
187
+ : [];
188
+ for (const f of files) {
189
+ if (!skippedFiles.includes(f))
190
+ skippedFiles.push(f);
191
+ }
192
+ }
193
+ }
194
+ // v2.12: Capture the restore point's git HEAD so the next round's
195
+ // verification can confirm the workspace returned to this commit.
196
+ const targetGitHead = findBacktrackTargetGitHead(restorePoint.round, vaultEntries);
153
197
  const backtrackPrompt = buildBacktrackPrompt(currentRound, restorePoint.round, enforceResult.check ?? "progress_stall", getPolicy().engine.backtrack_preserve_discoveries
154
198
  ? restorePoint.skippedDiscoveries
155
- : [], skippedFiles);
199
+ : [], skippedFiles, targetGitHead ?? undefined);
156
200
  logEvent("enforcement_backtrack", {
157
201
  loopId,
158
202
  round: currentRound,
@@ -165,11 +209,11 @@ export class RoundCoordinator {
165
209
  action: "backtrack",
166
210
  backtrackPrompt,
167
211
  backtrackTarget: restorePoint.round,
168
- backtrackTargetGitHead,
169
212
  backtrackSkippedDiscoveries: getPolicy().engine.backtrack_preserve_discoveries
170
213
  ? restorePoint.skippedDiscoveries
171
214
  : [],
172
215
  backtrackSkippedFiles: skippedFiles,
216
+ backtrackTargetGitHead: targetGitHead ?? undefined,
173
217
  backtrackTriggerRule: enforceResult.check,
174
218
  verificationFlags,
175
219
  enforcementAction: "backtrack",
@@ -178,22 +222,22 @@ export class RoundCoordinator {
178
222
  roundSuccess,
179
223
  gateContradicted,
180
224
  newConsecutiveRejections: 0, // reset — fresh start
181
- newRoundProjection: undefined,
225
+ newLastSelfEval: undefined,
182
226
  shouldPushSuccessTrajectory: false,
183
227
  };
184
228
  }
185
229
  // Accept: reset rejection counter
186
230
  // (consecutiveRejections reset to 0 — caller persists)
187
- // ── 4. Canonical round-report commit (AFTER enforcement) ────────────
231
+ // ── 4. Auto-feedback (AFTER enforcement, only if accepted) ──────────
188
232
  // ── 5. Stop condition checks ────────────────────────────────────────
189
- // 5a. The Agent requests a stop. Runtime evidence and gate checks have
190
- // already decided whether that stop can be accepted as completion.
191
- if (roundReport.continuation === "stop") {
233
+ // 5b. Agent says stop
234
+ if (!selfEval.should_continue) {
192
235
  let reason;
193
- if (roundSuccess) {
236
+ if (effectiveSuccess(selfEval)) {
194
237
  reason = "completed";
195
238
  }
196
- else if (roundReport.outcome === "blocked") {
239
+ else if (selfEval.outcome === "blocked" ||
240
+ selfEval.stop_reason === "blocked" || selfEval.stop_reason === "needs_human_input") {
197
241
  reason = "blocked";
198
242
  }
199
243
  else {
@@ -206,47 +250,14 @@ export class RoundCoordinator {
206
250
  roundSuccess,
207
251
  gateContradicted,
208
252
  newConsecutiveRejections: 0,
209
- newRoundProjection: currentProjection,
210
- clarificationAccepted,
211
- shouldPushSuccessTrajectory: !gateContradicted,
253
+ newLastSelfEval: selfEval,
254
+ shouldPushSuccessTrajectory: shouldPushSuccess(gateContradicted, verificationFlags),
212
255
  };
213
256
  }
214
- // 5b. Circuit breaker — max consecutive failed rounds.
215
- //
216
- // When the last N accepted rounds (including this one) all reported
217
- // failure with no recovery, the loop is failing faster than it can
218
- // self-correct. Stop before errors compound (p^N). The trajectory only
219
- // contains committed, non-contradicted rounds, so this never fires on
220
- // an enforcement-rejected round (those never reach this point).
221
- const breakerMax = getPolicy().engine.max_circuit_breaker;
222
- if (breakerMax > 0) {
223
- const breakerWindow = [...(input.successTrajectory ?? []), roundSuccess]
224
- .slice(-breakerMax);
225
- if (breakerWindow.length === breakerMax &&
226
- breakerWindow.every((value) => value === false)) {
227
- logEvent("session_end", {
228
- loopId,
229
- stopReason: "circuit_breaker",
230
- round: currentRound,
231
- });
232
- return {
233
- action: "stop",
234
- stopReason: "circuit_breaker",
235
- verificationFlags,
236
- roundSuccess,
237
- gateContradicted,
238
- newConsecutiveRejections: 0,
239
- newRoundProjection: currentProjection,
240
- clarificationAccepted,
241
- shouldPushSuccessTrajectory: false,
242
- };
243
- }
244
- }
245
257
  // 5c. Max rounds reached
246
258
  //
247
- // Genuine agent stalls are detected by the enforcement gate. The
248
- // coordinator deliberately does not infer completion from a binary
249
- // success flag or from an agent-supplied progress estimate.
259
+ // Progress stalls are handled before this point by the R4 delta tier and
260
+ // R5 flatline tier. Max rounds is an independent hard boundary.
250
261
  if (currentRound >= maxRounds) {
251
262
  return {
252
263
  action: "stop",
@@ -255,9 +266,8 @@ export class RoundCoordinator {
255
266
  roundSuccess,
256
267
  gateContradicted,
257
268
  newConsecutiveRejections: 0,
258
- newRoundProjection: currentProjection,
259
- clarificationAccepted,
260
- shouldPushSuccessTrajectory: !gateContradicted,
269
+ newLastSelfEval: selfEval,
270
+ shouldPushSuccessTrajectory: shouldPushSuccess(gateContradicted, verificationFlags),
261
271
  };
262
272
  }
263
273
  // ── 6. Continue — caller compiles next round ────────────────────────
@@ -268,9 +278,10 @@ export class RoundCoordinator {
268
278
  roundSuccess,
269
279
  gateContradicted,
270
280
  newConsecutiveRejections: 0,
271
- newRoundProjection: currentProjection,
272
- shouldPushSuccessTrajectory: !gateContradicted,
273
- clarificationAccepted,
281
+ newLastSelfEval: selfEval,
282
+ shouldPushSuccessTrajectory: shouldPushSuccess(gateContradicted, verificationFlags),
283
+ // v2.12: Propagate clarification acceptance signal for streak tracking
284
+ clarificationAccepted: enforceResult.clarification_accepted ?? false,
274
285
  };
275
286
  }
276
287
  }
@@ -1 +1 @@
1
- {"version":3,"file":"round-coordinator.js","sourceRoot":"","sources":["../src/round-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAcH,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAwC,MAAM,mBAAmB,CAAC;AAuFnG,8EAA8E;AAE9E,MAAM,OAAO,gBAAgB;IACnB,OAAO,CAAwB;IAEvC,YAAY,OAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;gFAY4E;IAC5E,YAAY,CACV,KAAwB,EACxB,2BAAmC,CAAC;QAEpC,MAAM,EACJ,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EACrC,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,qBAAqB,EACtE,iBAAiB,GAClB,GAAG,KAAK,CAAC;QAEV,MAAM,WAAW,GAAG,cAAc,CAAC;QACnC,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,KAAK,SAAS,CAAC;QAEvD,uEAAuE;QACvE,wEAAwE;QACxE,MAAM,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AAE,CAAC;YAC9B,OAAO;gBACL,MAAM,EAAE,MAAM;gBACd,UAAU,EAAE,YAAY;gBACxB,iBAAiB;gBACjB,YAAY;gBACZ,gBAAgB;gBAChB,wBAAwB,EAAE,CAAC;gBAC3B,eAAe,EAAE,QAAQ;gBACzB,2BAA2B,EAAE,iBAAiB,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;aACpF,CAAC;QACJ,CAAC;QAED,uEAAuE;QACvE,OAAO;YACL,MAAM,EAAE,UAAU;YAClB,iBAAiB;YACjB,iBAAiB,EAAE,QAAQ;YAC3B,YAAY;YACZ,gBAAgB;YAChB,wBAAwB,EAAE,CAAC;YAC3B,eAAe,EAAE,QAAQ;YACzB,2BAA2B,EAAE,iBAAiB,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;YACnF,uEAAuE;YACvE,qBAAqB,EAAE,aAAa,CAAC,sBAAsB,IAAI,KAAK;SACrE,CAAC;IACJ,CAAC;CACF"}
@@ -6,9 +6,9 @@
6
6
  * in their adapters.
7
7
  */
8
8
  import type { LoopStore } from "./loop-store.js";
9
- import { RuntimeServices } from "./runtime-services.js";
9
+ import { LoopForgeEngine } from "./engine.js";
10
10
  import type { ProviderSnapshot } from "./evidence-provider.js";
11
- import type { CompilerRoundProjection, LoopForgeRequest, PromptArtifact, RoundReport } from "./protocol.js";
11
+ import type { LoopForgeRequest, LoopForgeResponse, PromptArtifact, SelfEvaluation } from "./protocol.js";
12
12
  import type { RoundTransactionOutcome, RoundTransactionSnapshot } from "./round-transaction.js";
13
13
  export interface PreparedRound {
14
14
  prompt: string;
@@ -18,28 +18,25 @@ export interface PreparedRound {
18
18
  snapshot: RoundTransactionSnapshot;
19
19
  stateFileContent?: string;
20
20
  warnings?: string[];
21
- canonicalState?: unknown;
21
+ /** v3.0.1: The full compile response. Callers may cache it (e.g. for the
22
+ * typed projection) instead of recompiling for derived views. */
23
+ compileResponse?: LoopForgeResponse;
22
24
  }
23
25
  export interface CompleteRoundInput {
24
26
  snapshot: RoundTransactionSnapshot;
25
27
  loopId: string;
26
28
  task: string;
27
29
  maxRounds: number;
28
- roundReport: RoundReport;
29
- previousProjection?: CompilerRoundProjection;
30
+ selfEval: SelfEvaluation;
31
+ lastSelfEval?: SelfEvaluation;
30
32
  consecutiveRejections: number;
31
33
  successTrajectory: boolean[];
32
34
  /** v2.12: Current clarification streak for R7 escalation. */
33
35
  driftClarificationStreak?: number;
34
- /** Terminal enforcement checks that already consumed their guided retry. */
35
- escalatedRejectionChecks?: string[];
36
36
  /** v2.13: Files from skipped backtrack rounds for restore check. */
37
37
  backtrackSkippedFiles?: string[];
38
- /** v2.13: Git HEAD of the active backtrack restore point. Passed to the
39
- * verification gate; the post-backtrack round must match it. */
38
+ /** v2.12: Git HEAD of the backtrack restore point (workspace restore check). */
40
39
  backtrackTargetGitHead?: string;
41
- expectedAction?: string;
42
- remainingCriteria?: string[];
43
40
  }
44
41
  export interface CompletedRound {
45
42
  outcome: RoundTransactionOutcome;
@@ -47,9 +44,12 @@ export interface CompletedRound {
47
44
  }
48
45
  export declare class RoundDriver {
49
46
  private readonly engine;
50
- private readonly backend;
51
- constructor(engine: RuntimeServices, backend?: LoopStore);
47
+ private readonly store;
48
+ constructor(engine: LoopForgeEngine, store?: LoopStore);
52
49
  prepare(request: LoopForgeRequest, loopId: string, round: number): Promise<PreparedRound | null>;
50
+ /** Synchronous fallback for legacy embedding APIs. Async evidence providers
51
+ * are deliberately skipped by EvidenceCollector.collect(). */
52
+ prepareSync(request: LoopForgeRequest, loopId: string, round: number): PreparedRound | null;
53
53
  private compile;
54
54
  /** Compile a fresh prompt for a zero-commit enforcement retry. The logical
55
55
  * round ID and before-evidence snapshot remain stable; only attempt changes. */