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.
- package/README.md +126 -143
- package/dist/audit.d.ts +50 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +131 -0
- package/dist/audit.js.map +1 -0
- package/dist/canonical-state.d.ts +98 -23
- package/dist/canonical-state.d.ts.map +1 -1
- package/dist/canonical-state.js +257 -181
- package/dist/canonical-state.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +40 -33
- package/dist/cli.js.map +1 -1
- package/dist/cognitive-facts.d.ts +17 -0
- package/dist/cognitive-facts.d.ts.map +1 -0
- package/dist/cognitive-facts.js +99 -0
- package/dist/cognitive-facts.js.map +1 -0
- package/dist/cognitive-governance.d.ts +25 -33
- package/dist/cognitive-governance.d.ts.map +1 -1
- package/dist/cognitive-governance.js +38 -138
- package/dist/cognitive-governance.js.map +1 -1
- package/dist/committed-round.d.ts +59 -0
- package/dist/committed-round.d.ts.map +1 -0
- package/dist/committed-round.js +222 -0
- package/dist/committed-round.js.map +1 -0
- package/dist/enforcement-gate.d.ts +78 -0
- package/dist/enforcement-gate.d.ts.map +1 -0
- package/dist/enforcement-gate.js +1109 -0
- package/dist/enforcement-gate.js.map +1 -0
- package/dist/engine.d.ts +111 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +887 -0
- package/dist/engine.js.map +1 -0
- package/dist/evidence-claims.d.ts +50 -0
- package/dist/evidence-claims.d.ts.map +1 -0
- package/dist/evidence-claims.js +116 -0
- package/dist/evidence-claims.js.map +1 -0
- package/dist/evidence-provider.d.ts +50 -23
- package/dist/evidence-provider.d.ts.map +1 -1
- package/dist/evidence-provider.js +167 -50
- package/dist/evidence-provider.js.map +1 -1
- package/dist/generate-schema.js +1 -84
- package/dist/generate-schema.js.map +1 -1
- package/dist/index.d.ts +19 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -15
- package/dist/index.js.map +1 -1
- package/dist/loop-compiler.d.ts +58 -3
- package/dist/loop-compiler.d.ts.map +1 -1
- package/dist/loop-compiler.js +841 -304
- package/dist/loop-compiler.js.map +1 -1
- package/dist/loop-extras-parser.d.ts +2 -2
- package/dist/loop-extras-parser.d.ts.map +1 -1
- package/dist/loop-extras-parser.js +2 -2
- package/dist/loop-extras-parser.js.map +1 -1
- package/dist/loop-projection.d.ts +6 -0
- package/dist/loop-projection.d.ts.map +1 -0
- package/dist/loop-projection.js +26 -0
- package/dist/loop-projection.js.map +1 -0
- package/dist/loop-store.d.ts +115 -24
- package/dist/loop-store.d.ts.map +1 -1
- package/dist/loop-store.js +365 -218
- package/dist/loop-store.js.map +1 -1
- package/dist/mcp/round-lifecycle.d.ts +214 -0
- package/dist/mcp/round-lifecycle.d.ts.map +1 -0
- package/dist/mcp/round-lifecycle.js +935 -0
- package/dist/mcp/round-lifecycle.js.map +1 -0
- package/dist/mcp/server.d.ts +2 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +29 -43
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +64 -101
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +433 -1110
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/tools.d.ts +20 -11
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +587 -413
- package/dist/mcp/tools.js.map +1 -1
- package/dist/policy-metrics.d.ts +12 -24
- package/dist/policy-metrics.d.ts.map +1 -1
- package/dist/policy-metrics.js +78 -184
- package/dist/policy-metrics.js.map +1 -1
- package/dist/policy.d.ts +61 -50
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +48 -146
- package/dist/policy.js.map +1 -1
- package/dist/prompt-assembler.d.ts +37 -6
- package/dist/prompt-assembler.d.ts.map +1 -1
- package/dist/prompt-assembler.js +487 -278
- package/dist/prompt-assembler.js.map +1 -1
- package/dist/prompt-policy.d.ts +1 -8
- package/dist/prompt-policy.d.ts.map +1 -1
- package/dist/prompt-policy.js +8 -26
- package/dist/prompt-policy.js.map +1 -1
- package/dist/protocol.d.ts +398 -236
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +147 -17
- package/dist/protocol.js.map +1 -1
- package/dist/replay.d.ts +5 -13
- package/dist/replay.d.ts.map +1 -1
- package/dist/replay.js +32 -69
- package/dist/replay.js.map +1 -1
- package/dist/round-contract.d.ts +64 -0
- package/dist/round-contract.d.ts.map +1 -0
- package/dist/round-contract.js +80 -0
- package/dist/round-contract.js.map +1 -0
- package/dist/round-coordinator.d.ts +23 -25
- package/dist/round-coordinator.d.ts.map +1 -1
- package/dist/round-coordinator.js +103 -92
- package/dist/round-coordinator.js.map +1 -1
- package/dist/round-driver.d.ts +13 -13
- package/dist/round-driver.d.ts.map +1 -1
- package/dist/round-driver.js +25 -14
- package/dist/round-driver.js.map +1 -1
- package/dist/round-transaction.d.ts +14 -18
- package/dist/round-transaction.d.ts.map +1 -1
- package/dist/round-transaction.js +37 -47
- package/dist/round-transaction.js.map +1 -1
- package/dist/self-eval.d.ts +48 -0
- package/dist/self-eval.d.ts.map +1 -0
- package/dist/self-eval.js +248 -0
- package/dist/self-eval.js.map +1 -0
- package/dist/storage.d.ts +9 -4
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +18 -6
- package/dist/storage.js.map +1 -1
- package/dist/token-utils.d.ts +15 -3
- package/dist/token-utils.d.ts.map +1 -1
- package/dist/token-utils.js +24 -5
- package/dist/token-utils.js.map +1 -1
- package/dist/verification-gate.d.ts +149 -0
- package/dist/verification-gate.d.ts.map +1 -0
- package/dist/verification-gate.js +1343 -0
- package/dist/verification-gate.js.map +1 -0
- package/dist/workspace.d.ts +29 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +61 -0
- package/dist/workspace.js.map +1 -0
- package/loop_policy.json +37 -16
- package/package.json +5 -10
- package/skills/perception/SKILL.md +184 -202
- package/dist/canonical-event-writer.d.ts +0 -20
- package/dist/canonical-event-writer.d.ts.map +0 -1
- package/dist/canonical-event-writer.js +0 -131
- package/dist/canonical-event-writer.js.map +0 -1
- package/dist/compiler-subgoals.d.ts +0 -7
- package/dist/compiler-subgoals.d.ts.map +0 -1
- package/dist/compiler-subgoals.js +0 -93
- package/dist/compiler-subgoals.js.map +0 -1
- package/dist/derive-id.d.ts +0 -12
- package/dist/derive-id.d.ts.map +0 -1
- package/dist/derive-id.js +0 -31
- package/dist/derive-id.js.map +0 -1
- package/dist/mcp/session-projection.d.ts +0 -5
- package/dist/mcp/session-projection.d.ts.map +0 -1
- package/dist/mcp/session-projection.js +0 -18
- package/dist/mcp/session-projection.js.map +0 -1
- package/dist/mcp/session-queue.d.ts +0 -3
- package/dist/mcp/session-queue.d.ts.map +0 -1
- package/dist/mcp/session-queue.js +0 -18
- package/dist/mcp/session-queue.js.map +0 -1
- package/dist/mcp/session-types.d.ts +0 -72
- package/dist/mcp/session-types.d.ts.map +0 -1
- package/dist/mcp/session-types.js +0 -2
- package/dist/mcp/session-types.js.map +0 -1
- package/dist/round-commit-store.d.ts +0 -12
- package/dist/round-commit-store.d.ts.map +0 -1
- package/dist/round-commit-store.js +0 -13
- package/dist/round-commit-store.js.map +0 -1
- package/dist/round-gate.d.ts +0 -31
- package/dist/round-gate.d.ts.map +0 -1
- package/dist/round-gate.js +0 -259
- package/dist/round-gate.js.map +0 -1
- package/dist/round-recovery.d.ts +0 -17
- package/dist/round-recovery.d.ts.map +0 -1
- package/dist/round-recovery.js +0 -117
- package/dist/round-recovery.js.map +0 -1
- package/dist/round-report.d.ts +0 -16
- package/dist/round-report.d.ts.map +0 -1
- package/dist/round-report.js +0 -401
- package/dist/round-report.js.map +0 -1
- package/dist/runtime-services.d.ts +0 -59
- package/dist/runtime-services.d.ts.map +0 -1
- package/dist/runtime-services.js +0 -460
- package/dist/runtime-services.js.map +0 -1
- package/dist/vault-format.d.ts +0 -4
- package/dist/vault-format.d.ts.map +0 -1
- package/dist/vault-format.js +0 -4
- package/dist/vault-format.js.map +0 -1
- package/dist/vault-types.d.ts +0 -24
- package/dist/vault-types.d.ts.map +0 -1
- package/dist/vault-types.js +0 -2
- package/dist/vault-types.js.map +0 -1
- package/loopforge-policy.json +0 -340
package/dist/policy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Externalized LoopForge runtime policy. */
|
|
2
2
|
export interface ConstraintsPolicy {
|
|
3
|
-
retire_window
|
|
3
|
+
retire_window: number;
|
|
4
4
|
}
|
|
5
5
|
export interface SummaryPolicy {
|
|
6
6
|
window: number;
|
|
@@ -12,15 +12,17 @@ export interface SummaryPolicy {
|
|
|
12
12
|
/** v2.1: Maximum number of milestone summaries to accumulate.
|
|
13
13
|
* Oldest milestones are evicted when the cap is exceeded. */
|
|
14
14
|
max_milestones: number;
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/** v3.0.1: L1 milestone sampling — when milestones exceed max_milestones,
|
|
16
|
+
* keep this many of the OLDEST milestones as history anchors. The same
|
|
17
|
+
* count of the NEWEST is always kept; the middle is sampled evenly. */
|
|
18
|
+
milestone_head_count: number;
|
|
19
|
+
/** v3.0.1: L1 milestone sampling — this many of the NEWEST milestones are
|
|
20
|
+
* always kept when the cap is exceeded. */
|
|
21
|
+
milestone_tail_count: number;
|
|
17
22
|
}
|
|
18
23
|
export interface EnginePolicy {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* circuit breaker. The breaker only counts committed rounds; rejected
|
|
22
|
-
* rounds are handled by max_rejections. Set to 0 to disable. Default: 3. */
|
|
23
|
-
max_circuit_breaker: number;
|
|
24
|
+
/** Number of committed rounds inspected for progress stalls. */
|
|
25
|
+
stall_lookback_rounds: number;
|
|
24
26
|
max_rounds: number;
|
|
25
27
|
/** v2.7: When true, enforcement rules that would terminate (R4 2nd strike,
|
|
26
28
|
* R5 flatline, R6 max rejections) instead issue one final escalated
|
|
@@ -48,20 +50,17 @@ export interface EnginePolicy {
|
|
|
48
50
|
* disable the streak limit (pre-v2.12 behavior — any ≥ 20 char
|
|
49
51
|
* clarification always waives). Default: 3. */
|
|
50
52
|
drift_clarification_max_streak: number;
|
|
51
|
-
/** v2.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
|
|
53
|
+
/** v2.13: When true, LoopForge automatically executes git stash + reset
|
|
54
|
+
* on backtrack to restore the workspace to the clean round's commit.
|
|
55
|
+
* DANGEROUS: mutates the working tree directly. Default: false.
|
|
56
|
+
* When false (default), the backtrack prompt instructs the agent to
|
|
57
|
+
* restore manually, and the verification gate enforces the check. */
|
|
58
|
+
backtrack_auto_restore: boolean;
|
|
56
59
|
}
|
|
57
60
|
/** Levels control state density only; reasoning strategy belongs to the Agent. */
|
|
58
61
|
export interface PromptPolicy {
|
|
59
62
|
injection_mode: "adaptive" | "full" | "pointer";
|
|
60
63
|
full_refresh_interval: number;
|
|
61
|
-
adaptive_refresh: boolean;
|
|
62
|
-
max_l1_streak: number;
|
|
63
|
-
stale_round_threshold: number;
|
|
64
|
-
min_meaningful_sections: number;
|
|
65
64
|
l0_max_chars: number;
|
|
66
65
|
l1_max_chars: number;
|
|
67
66
|
l2_max_chars: number;
|
|
@@ -82,15 +81,25 @@ export interface PromptPolicy {
|
|
|
82
81
|
* rendered. Default: true. Set to false to restore pre-v2.8 L2
|
|
83
82
|
* behavior. */
|
|
84
83
|
l2_pointer_enabled: boolean;
|
|
84
|
+
/** v3.2: Collapse unchanged L1 content (vs the previous round's persisted
|
|
85
|
+
* presentation) into one-line state-file pointers. Default: true.
|
|
86
|
+
* Set to false to restore pre-v3.2 full L1 rendering. */
|
|
87
|
+
l1_collapse_enabled: boolean;
|
|
88
|
+
/** v3.5: When true, L2 prompts whose Current Task is NOT a Round Contract
|
|
89
|
+
* append a short suggestion to declare one when the remaining work spans
|
|
90
|
+
* several rounds. L2-only prose in the eval template tail — never the
|
|
91
|
+
* JSON key name; L0/L1 prompts are unaffected (byte-identical to v3.4).
|
|
92
|
+
* Default: true. Set to false to restore pre-v3.5 L2 rendering. */
|
|
93
|
+
contract_nudge_on_l2: boolean;
|
|
85
94
|
/** v2.9: Max emphasize items when level is L2. Default: 5. */
|
|
86
95
|
max_emphasize_l2: number;
|
|
87
96
|
/** v2.9: Max emphasize items when level is L1. Default: 3. */
|
|
88
97
|
max_emphasize_l1: number;
|
|
89
|
-
/** v2.9: Max expand sections when level is L1. Default: 1. */
|
|
90
|
-
max_expand_l1: number;
|
|
91
98
|
/** v2.9: Max confusion points rendered. Default: 3. */
|
|
92
99
|
max_confusion_points: number;
|
|
93
|
-
|
|
100
|
+
/** v2.14: Jaccard threshold for pointing a confusion point at its
|
|
101
|
+
* best-matching state section. Default: 0.15 (15%). */
|
|
102
|
+
confusion_section_threshold: number;
|
|
94
103
|
}
|
|
95
104
|
export interface BackendPolicy {
|
|
96
105
|
/** Root for typed per-loop documents. */
|
|
@@ -100,13 +109,13 @@ export interface EvolutionPolicy {
|
|
|
100
109
|
max_discovered_constraints_per_round: number;
|
|
101
110
|
max_active_constraints: number;
|
|
102
111
|
max_objective_versions: number;
|
|
103
|
-
progress_stall_threshold
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
progress_stall_threshold: number;
|
|
113
|
+
progress_mismatch_threshold: number;
|
|
114
|
+
/** v2.14: Jaccard threshold for task continuity in checkLoopHealth —
|
|
115
|
+
* below this, the loop is considered drifting. Default: 0.2. */
|
|
116
|
+
task_continuity_threshold: number;
|
|
108
117
|
/** v2.1: Jaccard token similarity threshold for intent-action drift
|
|
109
|
-
* detection. When the previous round's
|
|
118
|
+
* detection. When the previous round's next_action and the current
|
|
110
119
|
* round's output_summary have similarity below this threshold, a
|
|
111
120
|
* verification flag is raised. Default: 0.15 (15%). */
|
|
112
121
|
intent_drift_threshold: number;
|
|
@@ -123,48 +132,45 @@ export interface EvolutionPolicy {
|
|
|
123
132
|
* (completed/blocked/canceled) to existing sub-goals. Default: 0.5. */
|
|
124
133
|
subgoal_match_threshold: number;
|
|
125
134
|
/** v2.5: Jaccard threshold for auto-promoting a pending sub-goal to
|
|
126
|
-
*
|
|
127
|
-
subgoal_auto_in_progress_threshold
|
|
135
|
+
* in_progress when next_action aligns. Default: 0.4. */
|
|
136
|
+
subgoal_auto_in_progress_threshold: number;
|
|
128
137
|
/** v2.5: Jaccard threshold for matching constraints during discovery
|
|
129
138
|
* and violation tracking. Default: 0.5. */
|
|
130
139
|
constraint_match_threshold: number;
|
|
131
|
-
/** v2.5: Jaccard threshold for checkSubGoalDrift —
|
|
140
|
+
/** v2.5: Jaccard threshold for checkSubGoalDrift — next_action must
|
|
132
141
|
* exceed this to be considered "aligned" with a pending sub-goal.
|
|
133
142
|
* Default: 0.3. */
|
|
134
143
|
subgoal_drift_alignment_threshold: number;
|
|
135
|
-
/** v2.2: Number of rounds a sub-goal can stay pending before
|
|
136
|
-
* being flagged as stale in prompts. Default: 10. */
|
|
137
|
-
subgoal_stale_rounds?: number;
|
|
138
|
-
/** v2.2: Maximum sub-goals to render in prompt. Default: 10. */
|
|
139
|
-
max_subgoals_in_prompt: number;
|
|
140
|
-
/** v2.2: Maximum completed sub-goals to render in prompt. Default: 5. */
|
|
141
|
-
max_done_subgoals_in_prompt: number;
|
|
142
144
|
/** v2.3: Number of rounds without violation before a discovered
|
|
143
145
|
* constraint is demoted to inactive. Hard/plan/criteria constraints
|
|
144
146
|
* are never auto-demoted. Default: 15. */
|
|
145
147
|
constraint_inactive_rounds: number;
|
|
146
148
|
/** v2.11: When true, constraints and criteria are assigned stable IDs
|
|
147
149
|
* (c-XXXXXXXX, cr-XXXXXXXX) rendered in prompts. The agent is encouraged
|
|
148
|
-
* to reference IDs for exact matching;
|
|
149
|
-
*
|
|
150
|
-
* pure-text + Jaccard behavior. Default: true. */
|
|
150
|
+
* to reference IDs for exact matching; natural-language references use
|
|
151
|
+
* Jaccard similarity. Default: true. */
|
|
151
152
|
constraint_id_enabled: boolean;
|
|
152
153
|
}
|
|
153
154
|
export interface CheckpointPolicy {
|
|
154
|
-
max_carried_constraints: number;
|
|
155
155
|
outcome_max_chars: number;
|
|
156
156
|
}
|
|
157
157
|
/** Human-readable derived state view. JSON LoopStore documents remain truth. */
|
|
158
158
|
export interface StateFilePolicy {
|
|
159
159
|
enabled: boolean;
|
|
160
160
|
directory: string;
|
|
161
|
-
max_checkpoints?: number;
|
|
162
|
-
max_summary_rounds?: number;
|
|
163
161
|
}
|
|
164
162
|
export interface EvidencePolicy {
|
|
165
163
|
providers: string[];
|
|
166
164
|
timeout_ms: number;
|
|
167
165
|
commands: CommandEvidencePolicy[];
|
|
166
|
+
/** v3.3: How a success claim with zero machine-backed evidence is treated.
|
|
167
|
+
* "required" (default): the runtime rejects/terminates via R8 — a success
|
|
168
|
+
* claim must be backed by a passed after-phase command (or a declared
|
|
169
|
+
* no_change_reason). "warn": the flag downgrades to warn — the round
|
|
170
|
+
* commits, but its success never enters the trajectory and trust drops.
|
|
171
|
+
* The machine-evidence tightening itself is unconditional; this switch
|
|
172
|
+
* only controls the rejection/tolerance policy. */
|
|
173
|
+
machine_backed_success: "required" | "warn";
|
|
168
174
|
}
|
|
169
175
|
export interface CommandEvidencePolicy {
|
|
170
176
|
name: string;
|
|
@@ -182,6 +188,11 @@ export interface McpPolicy {
|
|
|
182
188
|
session_lease_ms: number;
|
|
183
189
|
session_lease_renew_interval_ms: number;
|
|
184
190
|
}
|
|
191
|
+
/** v2.12: User/Agent gate governance. The gate is a record layer — it never
|
|
192
|
+
* blocks the verify→enforce→stop decision flow. */
|
|
193
|
+
export interface GatePolicy {
|
|
194
|
+
enabled: boolean;
|
|
195
|
+
}
|
|
185
196
|
export interface LoopPolicy {
|
|
186
197
|
version: string;
|
|
187
198
|
constraints: ConstraintsPolicy;
|
|
@@ -194,16 +205,9 @@ export interface LoopPolicy {
|
|
|
194
205
|
state_file: StateFilePolicy;
|
|
195
206
|
evidence: EvidencePolicy;
|
|
196
207
|
mcp: McpPolicy;
|
|
197
|
-
|
|
198
|
-
export interface PolicyDiagnostic {
|
|
199
|
-
severity: "warning" | "error";
|
|
200
|
-
kind: "unknown" | "deprecated" | "removed" | "type" | "parse";
|
|
201
|
-
path: string;
|
|
202
|
-
message: string;
|
|
208
|
+
gate: GatePolicy;
|
|
203
209
|
}
|
|
204
210
|
export declare const DEFAULT_POLICY: LoopPolicy;
|
|
205
|
-
export declare function diagnosePolicyDocument(value: unknown): PolicyDiagnostic[];
|
|
206
|
-
export declare function getPolicyDiagnostics(): PolicyDiagnostic[];
|
|
207
211
|
/** Write a full default `loop_policy.json` to the target directory.
|
|
208
212
|
*
|
|
209
213
|
* The written file contains every configurable key and its default value
|
|
@@ -219,6 +223,13 @@ export declare function writeDefaultPolicy(targetDir: string, force?: boolean):
|
|
|
219
223
|
export declare function loadPolicy(path?: string): LoopPolicy;
|
|
220
224
|
export declare function getPolicy(path?: string): LoopPolicy;
|
|
221
225
|
export declare function resetPolicy(): void;
|
|
226
|
+
/** v3.2: Test-only injection — mirrors resetPolicy so tests can exercise a
|
|
227
|
+
* specific policy configuration (e.g. l1_collapse_enabled=false). */
|
|
228
|
+
export declare function setPolicyForTest(next: LoopPolicy): void;
|
|
229
|
+
/** v3.3: Whether a command name is configured AND enabled in the current
|
|
230
|
+
* policy's evidence.commands. The machine-checkable predicate behind the
|
|
231
|
+
* round_contract verification_plan (round_unverifiable otherwise). */
|
|
232
|
+
export declare function isConfiguredCommand(name: string): boolean;
|
|
222
233
|
export declare function validateLoopId(loopId: string): void;
|
|
223
234
|
export declare function resolveStateDirectory(workspaceRoot: string, configuredDirectory: string): string;
|
|
224
235
|
export declare function writeStateFile(loopId: string, content: string | undefined): void;
|
package/dist/policy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAe7C,MAAM,WAAW,iBAAiB;IAChC,aAAa,
|
|
1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,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,eAAO,MAAM,cAAc,EAAE,UAwD5B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,KAAK,UAAQ,GACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAOpC;AA2BD,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAapD;AAID,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAMnD;AAED,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED;sEACsE;AACtE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEvD;AAED;;uEAEuE;AACvE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGzD;AAID,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAanD;AAED,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,mBAAmB,EAAE,MAAM,GAC1B,MAAM,CAOR;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAuBhF"}
|
package/dist/policy.js
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
1
|
/** Externalized LoopForge runtime policy. */
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
"engine.backtrack_auto_restore",
|
|
7
|
-
]);
|
|
8
|
-
const DEPRECATED_POLICY_KEYS = new Set([
|
|
9
|
-
"constraints.retire_window",
|
|
10
|
-
"engine.round_event_flush_interval",
|
|
11
|
-
"evolution.progress_stall_threshold",
|
|
12
|
-
"evolution.progress_stall_rounds",
|
|
13
|
-
"evolution.progress_mismatch_threshold",
|
|
14
|
-
"evolution.subgoal_auto_in_progress_threshold",
|
|
15
|
-
"evolution.subgoal_stale_rounds",
|
|
16
|
-
"state_file.max_checkpoints",
|
|
17
|
-
"state_file.max_summary_rounds",
|
|
18
|
-
]);
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { containInWorkspace } from "./workspace.js";
|
|
19
6
|
export const DEFAULT_POLICY = {
|
|
20
|
-
version: "
|
|
21
|
-
constraints: {},
|
|
22
|
-
summary: { window: 5, health_check_interval: 1, milestone_interval: 20, max_milestones: 10,
|
|
23
|
-
engine: {
|
|
7
|
+
version: "2",
|
|
8
|
+
constraints: { retire_window: 3 },
|
|
9
|
+
summary: { window: 5, health_check_interval: 1, milestone_interval: 20, max_milestones: 10, milestone_head_count: 3, milestone_tail_count: 3 },
|
|
10
|
+
engine: { stall_lookback_rounds: 3, max_rounds: 20, enforcement_escalation_enabled: true, backtrack_enabled: true, backtrack_max_depth: 3, backtrack_preserve_discoveries: true, drift_clarification_max_streak: 3, backtrack_auto_restore: false },
|
|
24
11
|
prompt: {
|
|
25
12
|
injection_mode: "adaptive",
|
|
26
13
|
full_refresh_interval: 0,
|
|
27
|
-
adaptive_refresh: true,
|
|
28
|
-
max_l1_streak: 6,
|
|
29
|
-
stale_round_threshold: 3,
|
|
30
|
-
min_meaningful_sections: 4,
|
|
31
14
|
l0_max_chars: 3000,
|
|
32
15
|
l1_max_chars: 7000,
|
|
33
16
|
l2_max_chars: 18000,
|
|
@@ -37,120 +20,46 @@ export const DEFAULT_POLICY = {
|
|
|
37
20
|
l2_adaptive_max_chars: 40000,
|
|
38
21
|
l2_adaptive_subgoal_factor: 100,
|
|
39
22
|
l2_pointer_enabled: true,
|
|
23
|
+
l1_collapse_enabled: true,
|
|
24
|
+
contract_nudge_on_l2: true,
|
|
40
25
|
max_emphasize_l2: 5,
|
|
41
26
|
max_emphasize_l1: 3,
|
|
42
|
-
max_expand_l1: 1,
|
|
43
27
|
max_confusion_points: 3,
|
|
44
|
-
|
|
28
|
+
confusion_section_threshold: 0.15,
|
|
45
29
|
},
|
|
46
30
|
backend: { root_dir: ".loopforge" },
|
|
47
31
|
evolution: {
|
|
48
32
|
max_discovered_constraints_per_round: 5,
|
|
49
33
|
max_active_constraints: 15,
|
|
50
34
|
max_objective_versions: 10,
|
|
51
|
-
|
|
35
|
+
progress_stall_threshold: 0.05,
|
|
36
|
+
progress_mismatch_threshold: 0.3,
|
|
37
|
+
task_continuity_threshold: 0.2,
|
|
52
38
|
intent_drift_threshold: 0.15,
|
|
53
39
|
criteria_dedup_threshold: 0.45,
|
|
54
40
|
subgoal_dedup_threshold: 0.6,
|
|
55
41
|
subgoal_match_threshold: 0.5,
|
|
42
|
+
subgoal_auto_in_progress_threshold: 0.4,
|
|
56
43
|
subgoal_auto_complete_threshold: 0.4,
|
|
57
44
|
constraint_match_threshold: 0.5,
|
|
58
45
|
subgoal_drift_alignment_threshold: 0.3,
|
|
59
|
-
max_subgoals_in_prompt: 10,
|
|
60
|
-
max_done_subgoals_in_prompt: 5,
|
|
61
46
|
constraint_inactive_rounds: 15,
|
|
62
47
|
constraint_id_enabled: true,
|
|
63
48
|
},
|
|
64
|
-
checkpoint: {
|
|
49
|
+
checkpoint: { outcome_max_chars: 200 },
|
|
65
50
|
state_file: {
|
|
66
51
|
enabled: true,
|
|
67
52
|
directory: ".loopforge/state",
|
|
68
53
|
},
|
|
69
|
-
evidence: { providers: ["git"], timeout_ms: 120_000, commands: [] },
|
|
54
|
+
evidence: { providers: ["git"], timeout_ms: 120_000, commands: [], machine_backed_success: "required" },
|
|
70
55
|
mcp: {
|
|
71
56
|
session_lease_ms: 30_000,
|
|
72
57
|
session_lease_renew_interval_ms: 10_000,
|
|
73
58
|
},
|
|
59
|
+
gate: {
|
|
60
|
+
enabled: true,
|
|
61
|
+
},
|
|
74
62
|
};
|
|
75
|
-
let lastPolicyDiagnostics = [];
|
|
76
|
-
function policyKind(value) {
|
|
77
|
-
if (Array.isArray(value))
|
|
78
|
-
return "array";
|
|
79
|
-
if (value === null)
|
|
80
|
-
return "null";
|
|
81
|
-
return typeof value;
|
|
82
|
-
}
|
|
83
|
-
function collectPolicyDiagnostics(value, defaults, path, diagnostics) {
|
|
84
|
-
if (value === null || value === undefined)
|
|
85
|
-
return;
|
|
86
|
-
if (typeof defaults !== "object" || defaults === null || Array.isArray(defaults)) {
|
|
87
|
-
if (policyKind(value) !== policyKind(defaults)) {
|
|
88
|
-
diagnostics.push({
|
|
89
|
-
severity: "error",
|
|
90
|
-
kind: "type",
|
|
91
|
-
path,
|
|
92
|
-
message: `Expected ${policyKind(defaults)}, received ${policyKind(value)}.`,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (typeof value !== "object" || Array.isArray(value)) {
|
|
98
|
-
diagnostics.push({
|
|
99
|
-
severity: "error",
|
|
100
|
-
kind: "type",
|
|
101
|
-
path,
|
|
102
|
-
message: `Expected object, received ${policyKind(value)}.`,
|
|
103
|
-
});
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const defaultRecord = defaults;
|
|
107
|
-
const valueRecord = value;
|
|
108
|
-
for (const key of Object.keys(valueRecord)) {
|
|
109
|
-
const childPath = path ? `${path}.${key}` : key;
|
|
110
|
-
if (REMOVED_POLICY_KEYS.has(childPath)) {
|
|
111
|
-
diagnostics.push({
|
|
112
|
-
severity: "error",
|
|
113
|
-
kind: "removed",
|
|
114
|
-
path: childPath,
|
|
115
|
-
message: "This policy key is removed and has never performed automatic workspace changes.",
|
|
116
|
-
});
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
if (DEPRECATED_POLICY_KEYS.has(childPath)) {
|
|
120
|
-
diagnostics.push({
|
|
121
|
-
severity: "warning",
|
|
122
|
-
kind: "deprecated",
|
|
123
|
-
path: childPath,
|
|
124
|
-
message: "This policy key is deprecated and has no effect in the stable runtime.",
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
if (!(key in defaultRecord)) {
|
|
128
|
-
const kind = REMOVED_POLICY_KEYS.has(childPath)
|
|
129
|
-
? "removed"
|
|
130
|
-
: DEPRECATED_POLICY_KEYS.has(childPath) ? "deprecated" : "unknown";
|
|
131
|
-
diagnostics.push({
|
|
132
|
-
severity: kind === "removed" ? "error" : "warning",
|
|
133
|
-
kind,
|
|
134
|
-
path: childPath,
|
|
135
|
-
message: kind === "removed"
|
|
136
|
-
? "This policy key is removed and has never performed automatic workspace changes."
|
|
137
|
-
: kind === "deprecated"
|
|
138
|
-
? "This policy key is deprecated and has no effect in the stable runtime."
|
|
139
|
-
: "Unknown policy key; it will be ignored.",
|
|
140
|
-
});
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
collectPolicyDiagnostics(valueRecord[key], defaultRecord[key], childPath, diagnostics);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
export function diagnosePolicyDocument(value) {
|
|
147
|
-
const diagnostics = [];
|
|
148
|
-
collectPolicyDiagnostics(value, DEFAULT_POLICY, "", diagnostics);
|
|
149
|
-
return diagnostics;
|
|
150
|
-
}
|
|
151
|
-
export function getPolicyDiagnostics() {
|
|
152
|
-
return lastPolicyDiagnostics.map((diagnostic) => ({ ...diagnostic }));
|
|
153
|
-
}
|
|
154
63
|
/** Write a full default `loop_policy.json` to the target directory.
|
|
155
64
|
*
|
|
156
65
|
* The written file contains every configurable key and its default value
|
|
@@ -177,32 +86,28 @@ function deepMerge(defaults, overrides) {
|
|
|
177
86
|
typeof incoming === "object" && !Array.isArray(incoming)) {
|
|
178
87
|
result[key] = deepMerge(current, incoming);
|
|
179
88
|
}
|
|
180
|
-
else if (key in result
|
|
89
|
+
else if (key in result) {
|
|
181
90
|
result[key] = incoming;
|
|
182
91
|
}
|
|
92
|
+
else {
|
|
93
|
+
// Warn on unknown keys — a typo like "max_round" instead of
|
|
94
|
+
// "max_rounds" would otherwise be silently ignored.
|
|
95
|
+
console.warn(`loopforge: ignoring unknown policy key "${key}". Check loop_policy.json for typos.`);
|
|
96
|
+
}
|
|
183
97
|
}
|
|
184
98
|
return result;
|
|
185
99
|
}
|
|
186
100
|
export function loadPolicy(path) {
|
|
187
|
-
lastPolicyDiagnostics = [];
|
|
188
101
|
const candidates = [path, "loop_policy.json"].filter(Boolean);
|
|
189
102
|
for (const candidate of candidates) {
|
|
190
103
|
try {
|
|
191
104
|
const raw = JSON.parse(readFileSync(resolve(candidate), "utf8"));
|
|
192
105
|
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
193
|
-
lastPolicyDiagnostics = diagnosePolicyDocument(raw);
|
|
194
106
|
return deepMerge(DEFAULT_POLICY, raw);
|
|
195
107
|
}
|
|
196
108
|
}
|
|
197
109
|
catch {
|
|
198
|
-
|
|
199
|
-
lastPolicyDiagnostics = [{
|
|
200
|
-
severity: "error",
|
|
201
|
-
kind: "parse",
|
|
202
|
-
path: candidate,
|
|
203
|
-
message: "Policy file is not valid JSON; defaults are active.",
|
|
204
|
-
}];
|
|
205
|
-
}
|
|
110
|
+
// Try the next candidate.
|
|
206
111
|
}
|
|
207
112
|
}
|
|
208
113
|
return structuredClone(DEFAULT_POLICY);
|
|
@@ -219,6 +124,18 @@ export function getPolicy(path) {
|
|
|
219
124
|
export function resetPolicy() {
|
|
220
125
|
policy = null;
|
|
221
126
|
}
|
|
127
|
+
/** v3.2: Test-only injection — mirrors resetPolicy so tests can exercise a
|
|
128
|
+
* specific policy configuration (e.g. l1_collapse_enabled=false). */
|
|
129
|
+
export function setPolicyForTest(next) {
|
|
130
|
+
policy = next;
|
|
131
|
+
}
|
|
132
|
+
/** v3.3: Whether a command name is configured AND enabled in the current
|
|
133
|
+
* policy's evidence.commands. The machine-checkable predicate behind the
|
|
134
|
+
* round_contract verification_plan (round_unverifiable otherwise). */
|
|
135
|
+
export function isConfiguredCommand(name) {
|
|
136
|
+
const commands = getPolicy().evidence?.commands ?? [];
|
|
137
|
+
return commands.some((c) => c.enabled && c.name === name);
|
|
138
|
+
}
|
|
222
139
|
const LOOP_ID_RE = /^[a-zA-Z0-9][-a-zA-Z0-9_:.]{0,127}$/;
|
|
223
140
|
export function validateLoopId(loopId) {
|
|
224
141
|
if (typeof loopId !== "string" || !loopId) {
|
|
@@ -234,28 +151,12 @@ export function validateLoopId(loopId) {
|
|
|
234
151
|
}
|
|
235
152
|
}
|
|
236
153
|
export function resolveStateDirectory(workspaceRoot, configuredDirectory) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
const realRoot = realpathSync(lexicalRoot);
|
|
245
|
-
let ancestor = lexicalTarget;
|
|
246
|
-
while (!existsSync(ancestor)) {
|
|
247
|
-
const parent = resolve(ancestor, "..");
|
|
248
|
-
if (parent === ancestor)
|
|
249
|
-
break;
|
|
250
|
-
ancestor = parent;
|
|
251
|
-
}
|
|
252
|
-
const projected = resolve(realpathSync(ancestor), relative(ancestor, lexicalTarget));
|
|
253
|
-
const realRelative = relative(realRoot, projected);
|
|
254
|
-
if (realRelative === ".." || realRelative.startsWith(`..${sep}`) ||
|
|
255
|
-
isAbsolute(realRelative)) {
|
|
256
|
-
throw new Error("State file directory resolves outside the workspace");
|
|
257
|
-
}
|
|
258
|
-
return lexicalTarget;
|
|
154
|
+
// v3.3.1: delegated to the single shared containment check (workspace.ts).
|
|
155
|
+
// Behavior note: an EXISTING configured directory now resolves through
|
|
156
|
+
// symlinks to its real location (the old implementation returned the
|
|
157
|
+
// lexical path) — writes can never land behind the workspace's back via a
|
|
158
|
+
// symlinked alias. Absent first-run directories keep the lexical path.
|
|
159
|
+
return containInWorkspace(workspaceRoot, configuredDirectory);
|
|
259
160
|
}
|
|
260
161
|
export function writeStateFile(loopId, content) {
|
|
261
162
|
if (!content)
|
|
@@ -266,12 +167,13 @@ export function writeStateFile(loopId, content) {
|
|
|
266
167
|
return;
|
|
267
168
|
const directory = resolveStateDirectory(process.cwd(), config.directory);
|
|
268
169
|
mkdirSync(directory, { recursive: true });
|
|
269
|
-
|
|
270
|
-
|
|
170
|
+
// v3.3.1: the double resolveStateDirectory call was redundant — the
|
|
171
|
+
// containment check is pure; one resolution serves mkdir, target, tmp.
|
|
172
|
+
const target = resolve(directory, `${loopId}-state.md`);
|
|
271
173
|
if (existsSync(target) && lstatSync(target).isSymbolicLink()) {
|
|
272
174
|
throw new Error("State file target must not be a symbolic link");
|
|
273
175
|
}
|
|
274
|
-
const temporary = resolve(
|
|
176
|
+
const temporary = resolve(directory, `.${loopId}-state.${process.pid}.${randomUUID()}.tmp`);
|
|
275
177
|
try {
|
|
276
178
|
writeFileSync(temporary, content, "utf8");
|
|
277
179
|
renameSync(temporary, target);
|
package/dist/policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,UAAU,EACV,MAAM,EACN,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AA+NpD,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC,OAAO,EAAE,GAAG;IACZ,WAAW,EAAE,EAAE,aAA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AC;QAC1C,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACzE,CAAC;AACH,CAAC"}
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* external Agent. Mandatory task, hard-constraint, and verification sections
|
|
5
5
|
* are never truncated; budgets are soft and overflow is recorded.
|
|
6
6
|
*/
|
|
7
|
-
import type { CanonicalLoopState } from "./canonical-state.js";
|
|
7
|
+
import type { CanonicalLoopState, PresentedStateSnapshot } from "./canonical-state.js";
|
|
8
8
|
import type { PromptArtifact, PromptRequests } from "./protocol.js";
|
|
9
|
+
import type { ConstraintMeta, MilestoneSummary, SubGoal } from "./protocol.js";
|
|
9
10
|
import type { PromptLevel, PromptLevelReason } from "./prompt-policy.js";
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const BASE_PROMPT_VERSION = "
|
|
11
|
+
export declare const PROMPT_ARTIFACT_SCHEMA_VERSION: 1;
|
|
12
|
+
export declare const BASE_PROMPT_VERSION = "2.0.0";
|
|
12
13
|
export type InjectionMode = "adaptive" | "full" | "pointer";
|
|
13
14
|
export interface PromptBudgets {
|
|
14
15
|
l0: number;
|
|
@@ -23,12 +24,42 @@ export interface PromptAssemblyInput {
|
|
|
23
24
|
mode?: InjectionMode;
|
|
24
25
|
budgets?: Partial<PromptBudgets>;
|
|
25
26
|
attempt?: number;
|
|
26
|
-
|
|
27
|
+
selfEvaluationBlock: string;
|
|
27
28
|
fullStateMarkdown?: string;
|
|
28
|
-
/** Previous Agent suggestion. Display-only; never part of canonical state. */
|
|
29
|
-
agentIntent?: string;
|
|
30
29
|
/** v2.9: Model's information needs for this prompt. L0: ignored. */
|
|
31
30
|
promptRequests?: PromptRequests;
|
|
31
|
+
/** v3.2: Previous round's L1 presentation (persisted diff baseline).
|
|
32
|
+
* When present, L1 collapses unchanged content against it. */
|
|
33
|
+
presentedBaseline?: PresentedStateSnapshot | null;
|
|
32
34
|
}
|
|
35
|
+
/** v3.2: The actionable instruction for a verification check. Exported for
|
|
36
|
+
* the coverage test (which imports the CHECK_* constants). */
|
|
37
|
+
export declare function verificationActionFor(check: string): string;
|
|
38
|
+
/** v3.2: Collapse only when at least this many items are unchanged — a tiny
|
|
39
|
+
* unchanged set renders in full (nothing worth saving). */
|
|
40
|
+
export declare const COLLAPSE_MIN_UNCHANGED = 3;
|
|
41
|
+
/** v3.2: Recent-rounds items kept in full when older ones collapse. */
|
|
42
|
+
export declare const KEEP_RECENT_ROUNDS = 3;
|
|
43
|
+
export interface ConstraintDiff {
|
|
44
|
+
/** Constraint texts to render in full (new or violated this round). */
|
|
45
|
+
changed: string[];
|
|
46
|
+
/** Same-ID items unchanged since the baseline. */
|
|
47
|
+
unchangedCount: number;
|
|
48
|
+
/** Baseline items absent now, excluding emphasized items (they were moved
|
|
49
|
+
* to Critical Context, not demoted). */
|
|
50
|
+
removedCount: number;
|
|
51
|
+
}
|
|
52
|
+
export declare function diffConstraints(baseline: PresentedStateSnapshot | null, activeTexts: string[], metadata: ConstraintMeta[], round: number, emphasized: Set<string>): ConstraintDiff;
|
|
53
|
+
export interface SubGoalDiff {
|
|
54
|
+
/** Sub-goals to render in full (new or status transition). */
|
|
55
|
+
changed: SubGoal[];
|
|
56
|
+
unchangedCount: number;
|
|
57
|
+
/** Baseline sub-goals no longer in the active set (done/canceled/blocked). */
|
|
58
|
+
removedCount: number;
|
|
59
|
+
}
|
|
60
|
+
export declare function diffSubGoals(baseline: PresentedStateSnapshot | null, activeSubs: SubGoal[]): SubGoalDiff;
|
|
61
|
+
/** v3.2: True when a milestone boundary was crossed since the baseline —
|
|
62
|
+
* the Recent Rounds section then renders in full (a phase ended). */
|
|
63
|
+
export declare function milestoneBoundaryChanged(baseline: PresentedStateSnapshot | null, milestones: MilestoneSummary[]): boolean;
|
|
33
64
|
export declare function assemblePromptArtifact(input: PromptAssemblyInput): PromptArtifact;
|
|
34
65
|
//# sourceMappingURL=prompt-assembler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-assembler.d.ts","sourceRoot":"","sources":["../src/prompt-assembler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"prompt-assembler.d.ts","sourceRoot":"","sources":["../src/prompt-assembler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEvF,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAI5B,eAAO,MAAM,8BAA8B,EAAG,CAAU,CAAC;AACzD,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,sBAAsB,EAAE,aAIpC,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,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