@0perator/operator 0.1.352 → 0.1.353
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/dist/acp/agent.js +2 -2
- package/dist/acp/tool-map.js +5 -4
- package/dist/autonomy/delegate.js +54 -1
- package/dist/autonomy/headless.js +2 -0
- package/dist/autonomy/session-factory.js +1 -0
- package/dist/background/index.js +86 -10
- package/dist/background/notices.js +16 -4
- package/dist/cli.js +1066 -175
- package/dist/config/home.js +6 -0
- package/dist/config/memory-sections.js +92 -0
- package/dist/config/persona.js +144 -26
- package/dist/config/settings.js +15 -4
- package/dist/consolidation/scheduler.js +9 -2
- package/dist/consolidation/sleep.js +39 -278
- package/dist/engine/agent.js +444 -76
- package/dist/engine/anthropic-chat.js +13 -2
- package/dist/engine/aurora.js +43 -19
- package/dist/engine/batch-scheduler.js +27 -3
- package/dist/engine/compaction.js +12 -5
- package/dist/engine/continuation.js +14 -12
- package/dist/engine/contract.js +1 -1
- package/dist/engine/decision-points.js +7 -1
- package/dist/engine/front-door.js +59 -0
- package/dist/engine/grandmaster.js +13 -1
- package/dist/engine/loop-guard.js +694 -0
- package/dist/engine/owner-act.js +52 -0
- package/dist/engine/verify-gate.js +52 -0
- package/dist/flywheel/processor.js +3 -1
- package/dist/flywheel/srft.js +8 -4
- package/dist/hooks/index.js +12 -8
- package/dist/mcp/index.js +9 -4
- package/dist/permissions/index.js +32 -11
- package/dist/permissions/modes.js +42 -0
- package/dist/permissions/plan-review.js +100 -0
- package/dist/permissions/policy.js +16 -5
- package/dist/permissions/signature.js +8 -3
- package/dist/remote/safe-commands.js +1 -1
- package/dist/router/read-rates.js +152 -0
- package/dist/selfimprove/backfill.js +174 -0
- package/dist/selfimprove/index.js +146 -57
- package/dist/selfimprove/lessons.js +429 -0
- package/dist/selfimprove/sync.js +58 -0
- package/dist/session.js +350 -30
- package/dist/skills/finder.js +219 -0
- package/dist/tools/deferred.js +28 -18
- package/dist/tools/executor.js +7 -3
- package/dist/tools/registry.js +34 -4
- package/dist/ui/ActivitySpinner.js +21 -12
- package/dist/ui/App.js +107 -30
- package/dist/ui/ApprovalPrompt.js +5 -3
- package/dist/ui/ArtifactPicker.js +3 -3
- package/dist/ui/BgPanel.js +105 -5
- package/dist/ui/Composer.js +85 -9
- package/dist/ui/PlanPane.js +72 -8
- package/dist/ui/QuestionPrompt.js +6 -4
- package/dist/ui/SecretPrompt.js +8 -3
- package/dist/ui/SessionPicker.js +2 -2
- package/dist/ui/SkillFinder.js +153 -0
- package/dist/ui/StatusRule.js +5 -2
- package/dist/ui/SummaryCard.js +3 -1
- package/dist/ui/ThinkingSpinner.js +11 -2
- package/dist/ui/ToolBatch.js +11 -2
- package/dist/ui/ToolStep.js +36 -13
- package/dist/ui/Transcript.js +13 -2
- package/dist/ui/actNow.js +61 -0
- package/dist/ui/batchLine.js +165 -0
- package/dist/ui/conversations.js +154 -0
- package/dist/ui/decodeHealth.js +77 -0
- package/dist/ui/expand.js +17 -0
- package/dist/ui/fit.js +40 -0
- package/dist/ui/fitTail.js +14 -0
- package/dist/ui/fold.js +149 -0
- package/dist/ui/format.js +46 -2
- package/dist/ui/liveTools.js +163 -13
- package/dist/ui/modelPicker.js +78 -6
- package/dist/ui/nextStep.js +103 -0
- package/dist/ui/pending.js +57 -0
- package/dist/ui/phase.js +105 -0
- package/dist/ui/planExit.js +0 -5
- package/dist/ui/progressbar.js +4 -26
- package/dist/ui/readForecast.js +44 -0
- package/dist/ui/readProgress.js +119 -0
- package/dist/ui/reportLine.js +62 -0
- package/dist/ui/slashCommands.js +1 -1
- package/dist/ui/theme.js +1 -0
- package/dist/ui/turnFlow.js +72 -0
- package/dist/ui/turnLedger.js +121 -0
- package/dist/ui/turnScope.js +11 -0
- package/dist/util/slash.js +18 -0
- package/package.json +1 -1
|
@@ -8,21 +8,21 @@
|
|
|
8
8
|
// 3. On idle detection (no active turn for > threshold, default 30s)
|
|
9
9
|
//
|
|
10
10
|
// What it does:
|
|
11
|
-
// -
|
|
12
|
-
//
|
|
13
|
-
// -
|
|
14
|
-
// -
|
|
15
|
-
import { readFileSync, writeFileSync, existsSync
|
|
16
|
-
import { dirname } from "node:path";
|
|
11
|
+
// - Folds what the flywheel and the reviewers taught into the global memories.md lessons — the same fold and the same
|
|
12
|
+
// curation `operator selfimprove backfill` and a live turn use (selfimprove/backfill.ts, selfimprove/lessons.ts)
|
|
13
|
+
// - Runs the flywheel processor (SRFT masking + the training export; looped rows never promote)
|
|
14
|
+
// - Counts the deduplicated Operator_Memory.jsonl notes
|
|
15
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
17
16
|
import { operatorPath } from "../config/home.js";
|
|
18
|
-
import { FlywheelProcessor
|
|
19
|
-
import {
|
|
17
|
+
import { FlywheelProcessor } from "../flywheel/processor.js";
|
|
18
|
+
import { curateLessons, MAX_LESSONS } from "../selfimprove/lessons.js";
|
|
19
|
+
import { foldLessons } from "../selfimprove/backfill.js";
|
|
20
20
|
const DEFAULTS = {
|
|
21
21
|
enabled: false,
|
|
22
22
|
idleThresholdSec: 30,
|
|
23
23
|
stepsBetweenPasses: 10,
|
|
24
24
|
modelTier: "fast",
|
|
25
|
-
maxLessonsPerFile:
|
|
25
|
+
maxLessonsPerFile: MAX_LESSONS,
|
|
26
26
|
};
|
|
27
27
|
/** Deduplicate a JSONL memory file. Returns the deduped notes. */
|
|
28
28
|
export function dedupMemoryFile(filepath) {
|
|
@@ -62,241 +62,20 @@ export function dedupMemoryFile(filepath) {
|
|
|
62
62
|
return result;
|
|
63
63
|
}
|
|
64
64
|
// ---------------------------------------------------------------------------
|
|
65
|
-
// Lesson extraction from flywheel trajectories
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
/** Min repeated failures on one task CLASS before it becomes a candidate lesson. Lowered from the old
|
|
68
|
-
* `> 2 on a byte-identical input hash` (which real traffic never satisfied) to a bar a fuzzy task class
|
|
69
|
-
* can actually reach. Override with KODE_CONSOLIDATION_FAILURE_MIN. */
|
|
70
|
-
const REPEATED_FAILURE_MIN = (() => {
|
|
71
|
-
const n = Number(process.env.KODE_CONSOLIDATION_FAILURE_MIN);
|
|
72
|
-
return Number.isFinite(n) && n >= 1 ? n : 2;
|
|
73
|
-
})();
|
|
74
|
-
/** Extract candidate lessons from graded flywheel trajectories.
|
|
75
|
-
* Scans the flywheel JSONL for patterns that suggest a reusable lesson:
|
|
76
|
-
* - Repeated failures on the same tool/command
|
|
77
|
-
* - Verification failures that were later fixed
|
|
78
|
-
* - Compaction events that freed significant context
|
|
79
|
-
* - Self-loop detections that required forced redirects
|
|
80
|
-
*/
|
|
81
|
-
export async function extractFlywheelLessons(flywheelDir) {
|
|
82
|
-
const { readdirSync, readFileSync, existsSync } = await import("node:fs");
|
|
83
|
-
const { join } = await import("node:path");
|
|
84
|
-
if (!existsSync(flywheelDir))
|
|
85
|
-
return [];
|
|
86
|
-
const lessons = [];
|
|
87
|
-
const files = readdirSync(flywheelDir).filter(f => f.endsWith(".jsonl"));
|
|
88
|
-
for (const file of files) {
|
|
89
|
-
if (!file.endsWith(".jsonl"))
|
|
90
|
-
continue;
|
|
91
|
-
const filepath = join(flywheelDir, file);
|
|
92
|
-
const raw = readFileSync(filepath, "utf8");
|
|
93
|
-
const lines = raw.split("\n").filter(Boolean);
|
|
94
|
-
// Mentor-pair lanes are already-distilled, human/teacher-VERIFIED lessons (chosen vs rejected with the
|
|
95
|
-
// reasoning attached) — the richest signal in the directory. Each valid pair IS a lesson; no counting
|
|
96
|
-
// bar applies. Before this path existed the extractor parsed these files as trajectories, found no
|
|
97
|
-
// graded/score fields, and dropped every row — the hand-curated lane contributed nothing.
|
|
98
|
-
if (file.startsWith("mentor-pairs")) {
|
|
99
|
-
for (const line of lines) {
|
|
100
|
-
try {
|
|
101
|
-
const pair = JSON.parse(line);
|
|
102
|
-
const chosen = typeof pair.chosen === "string" ? pair.chosen.trim() : "";
|
|
103
|
-
if (!chosen)
|
|
104
|
-
continue;
|
|
105
|
-
lessons.push({
|
|
106
|
-
type: "mentor_pair",
|
|
107
|
-
pattern: (pair.lens || "general").slice(0, 60),
|
|
108
|
-
count: 1,
|
|
109
|
-
total: 1,
|
|
110
|
-
source: filepath,
|
|
111
|
-
text: chosen,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
catch { /* skip malformed rows */ }
|
|
115
|
-
}
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
// Track per-task patterns
|
|
119
|
-
const taskCounts = new Map();
|
|
120
|
-
const threshold = scoreThreshold();
|
|
121
|
-
for (const line of lines) {
|
|
122
|
-
try {
|
|
123
|
-
const row = JSON.parse(line);
|
|
124
|
-
// Key by TASK CLASS (normalized first tokens), not a byte-exact input hash. Real prompts almost
|
|
125
|
-
// never repeat verbatim, so the old exact-hash grouping (hashInput) produced ~0 candidates on live
|
|
126
|
-
// traffic; collapsing near-identical prompts into a class is what lets a repeated failure MODE show.
|
|
127
|
-
const key = taskClassKey(row.input ?? "");
|
|
128
|
-
const count = taskCounts.get(key) ?? { total: 0, graded: 0, failed: 0 };
|
|
129
|
-
count.total++;
|
|
130
|
-
// Failure MINING is deliberately not gated on promotability: an unverified failure is almost never
|
|
131
|
-
// `graded:true`, so requiring isPromotable here meant count.failed could not increment on live
|
|
132
|
-
// traffic (verified 2026-10-22: 31/32 recent rows graded+verified, 0 unverified-promotable) — the
|
|
133
|
-
// structural reason every nightly pass logged extracted=0. The promotion gate still governs what
|
|
134
|
-
// the TRAINING pipeline exports (processor.ts); lesson mining wants the failures it excludes.
|
|
135
|
-
if (row.unverified) {
|
|
136
|
-
count.failed++;
|
|
137
|
-
}
|
|
138
|
-
if (isPromotable(row, threshold)) {
|
|
139
|
-
count.graded++;
|
|
140
|
-
}
|
|
141
|
-
taskCounts.set(key, count);
|
|
142
|
-
}
|
|
143
|
-
catch { /* skip malformed rows */ }
|
|
144
|
-
}
|
|
145
|
-
// Identify patterns worth distilling. A repeated failure on the same task CLASS (>=2) is the trigger —
|
|
146
|
-
// a real, attainable bar, unlike the old `>2 on an identical input hash` that live traffic never hit.
|
|
147
|
-
for (const [key, count] of taskCounts) {
|
|
148
|
-
if (count.failed >= REPEATED_FAILURE_MIN) {
|
|
149
|
-
lessons.push({
|
|
150
|
-
type: "repeated_failure",
|
|
151
|
-
pattern: key,
|
|
152
|
-
count: count.failed,
|
|
153
|
-
total: count.total,
|
|
154
|
-
source: filepath,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return lessons;
|
|
160
|
-
}
|
|
161
|
-
/** Merge candidate lessons into curated form.
|
|
162
|
-
* Groups candidates by type+pattern, extracts a distilled lesson text. */
|
|
163
|
-
export function curateLessons(candidates) {
|
|
164
|
-
// Group by type. Mentor pairs key on their distilled TEXT, not the lens: several pairs share one lens
|
|
165
|
-
// (e.g. chain-to-completion) but each carries a distinct rule — a lens-keyed group would collapse them
|
|
166
|
-
// into whichever rule happened to arrive first.
|
|
167
|
-
const groups = new Map();
|
|
168
|
-
for (const c of candidates) {
|
|
169
|
-
const key = c.type === "mentor_pair"
|
|
170
|
-
? `${c.type}:${(c.text ?? "").slice(0, 80)}`
|
|
171
|
-
: `${c.type}:${c.pattern.slice(0, 40)}`;
|
|
172
|
-
const existing = groups.get(key) ?? [];
|
|
173
|
-
existing.push(c);
|
|
174
|
-
groups.set(key, existing);
|
|
175
|
-
}
|
|
176
|
-
return [...groups.entries()].map(([, items]) => {
|
|
177
|
-
const type = items[0].type;
|
|
178
|
-
const count = items.reduce((s, i) => s + i.count, 0);
|
|
179
|
-
const total = items.reduce((s, i) => s + i.total, 0);
|
|
180
|
-
let text = "";
|
|
181
|
-
switch (type) {
|
|
182
|
-
case "repeated_failure":
|
|
183
|
-
text = `Pattern: repeated failures detected ${count} times across ${total} total attempts. ` +
|
|
184
|
-
`Lesson: this failure mode is systematic — check tool parser, template, or sandbox config.`;
|
|
185
|
-
break;
|
|
186
|
-
case "compaction_insight":
|
|
187
|
-
text = `Compaction freed significant context ${count} times. ` +
|
|
188
|
-
`Lesson: the evicted span often contains critical state — ensure summaries preserve verbatim identifiers.`;
|
|
189
|
-
break;
|
|
190
|
-
case "self_loop":
|
|
191
|
-
text = `Self-loop detected ${count} times. ` +
|
|
192
|
-
`Lesson: the model gets stuck on ${items[0].pattern.slice(0, 60)} — add explicit decomposition guidance.`;
|
|
193
|
-
break;
|
|
194
|
-
case "verify_gap":
|
|
195
|
-
text = `Verification gap: ${count} turns changed files without passing checks. ` +
|
|
196
|
-
`Lesson: the verify-before-done gate needs a nudge on this task type.`;
|
|
197
|
-
break;
|
|
198
|
-
case "mentor_pair":
|
|
199
|
-
// Already distilled and verified at capture time — carry the rule through verbatim (capped),
|
|
200
|
-
// prefixed with its lens so recall can match on the failure mode it addresses.
|
|
201
|
-
text = `Mentor rule [${items[0].pattern}]: ${(items[0].text ?? "").slice(0, 400)}`;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
ts: Date.now(),
|
|
206
|
-
text,
|
|
207
|
-
tags: type === "mentor_pair" ? [type, items[0].pattern] : [type, `count:${count}`],
|
|
208
|
-
source: items[0].source,
|
|
209
|
-
candidates: items.map(i => i.pattern),
|
|
210
|
-
};
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
// ---------------------------------------------------------------------------
|
|
214
|
-
// Persistence: write curated lessons back to Operator_Memory.jsonl
|
|
215
|
-
// ---------------------------------------------------------------------------
|
|
216
|
-
/** Write curated lessons to the memory file, appending new ones. */
|
|
217
|
-
export function persistLessons(memoryFile, lessons) {
|
|
218
|
-
try {
|
|
219
|
-
mkdirSync(dirname(memoryFile), { recursive: true });
|
|
220
|
-
// Read existing notes
|
|
221
|
-
let existing = [];
|
|
222
|
-
if (existsSync(memoryFile)) {
|
|
223
|
-
const raw = readFileSync(memoryFile, "utf8");
|
|
224
|
-
existing = raw.split("\n")
|
|
225
|
-
.filter(Boolean)
|
|
226
|
-
.map((l) => { try {
|
|
227
|
-
return JSON.parse(l);
|
|
228
|
-
}
|
|
229
|
-
catch {
|
|
230
|
-
return null;
|
|
231
|
-
} })
|
|
232
|
-
.filter((n) => !!n);
|
|
233
|
-
}
|
|
234
|
-
// Check for duplicates (by text prefix)
|
|
235
|
-
const seen = new Set();
|
|
236
|
-
for (const n of existing) {
|
|
237
|
-
seen.add(n.text.slice(0, 80));
|
|
238
|
-
}
|
|
239
|
-
// Append non-duplicate lessons
|
|
240
|
-
let wrote = 0;
|
|
241
|
-
for (const lesson of lessons) {
|
|
242
|
-
const key = lesson.text.slice(0, 80);
|
|
243
|
-
if (seen.has(key))
|
|
244
|
-
continue;
|
|
245
|
-
seen.add(key);
|
|
246
|
-
const note = {
|
|
247
|
-
ts: lesson.ts,
|
|
248
|
-
text: lesson.text,
|
|
249
|
-
tags: [...(lesson.tags ?? []), "consolidated"],
|
|
250
|
-
};
|
|
251
|
-
appendFileSync(memoryFile, JSON.stringify(note) + "\n", "utf8");
|
|
252
|
-
wrote++;
|
|
253
|
-
}
|
|
254
|
-
return wrote > 0;
|
|
255
|
-
}
|
|
256
|
-
catch {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
// ---------------------------------------------------------------------------
|
|
261
65
|
// Project memories curation
|
|
262
66
|
// ---------------------------------------------------------------------------
|
|
263
|
-
/** Curate a project's .operator/memories.md
|
|
67
|
+
/** Curate a project's .operator/memories.md through the one lessons curation (selfimprove/lessons.ts curateLessons):
|
|
68
|
+
* its older per-turn stuck lessons folded into one line per stop class, retired (superseded / OBSOLETE) lines dropped,
|
|
69
|
+
* the rest deduplicated, ordered and capped at maxLessons; everything outside the lessons section byte-for-byte. Until
|
|
70
|
+
* 2026-11-02 this had rules of its own (a raw tail cap, and every heading moved to the top of the file). */
|
|
264
71
|
export function curateProjectMemories(filepath, maxLessons) {
|
|
265
72
|
if (!existsSync(filepath))
|
|
266
73
|
return false;
|
|
267
74
|
try {
|
|
268
75
|
const raw = readFileSync(filepath, "utf8");
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const nonLessonLines = [];
|
|
273
|
-
for (const line of lines) {
|
|
274
|
-
if (line.startsWith("- [") || line.startsWith("## Lessons") || line.startsWith("# ")) {
|
|
275
|
-
if (line.startsWith("## Lessons") || line.startsWith("# ")) {
|
|
276
|
-
nonLessonLines.push(line);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
lessonLines.push(line);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
nonLessonLines.push(line);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
// Remove superseded lessons
|
|
287
|
-
const activeLessons = lessonLines.filter(l => !l.includes("superseded") && !l.includes("OBSOLETE"));
|
|
288
|
-
// Cap at max
|
|
289
|
-
const capped = activeLessons.slice(-maxLessons);
|
|
290
|
-
// Reconstruct
|
|
291
|
-
const header = nonLessonLines.filter(l => l.startsWith("# ") || l.startsWith("## "));
|
|
292
|
-
const body = nonLessonLines.filter(l => !l.startsWith("# ") && !l.startsWith("## "));
|
|
293
|
-
let result = header.join("\n") + "\n";
|
|
294
|
-
if (!result.includes("## Lessons")) {
|
|
295
|
-
result += "\n## Lessons (auto-captured)\n";
|
|
296
|
-
}
|
|
297
|
-
result += capped.join("\n") + "\n";
|
|
298
|
-
result += body.join("\n") + "\n";
|
|
299
|
-
writeFileSync(filepath, result, "utf8");
|
|
76
|
+
const { text } = curateLessons(raw, [], { cap: maxLessons });
|
|
77
|
+
if (text !== raw)
|
|
78
|
+
writeFileSync(filepath, text, "utf8");
|
|
300
79
|
return true;
|
|
301
80
|
}
|
|
302
81
|
catch {
|
|
@@ -317,13 +96,27 @@ export async function runConsolidationPass(opts = {}) {
|
|
|
317
96
|
return result;
|
|
318
97
|
}
|
|
319
98
|
try {
|
|
320
|
-
// 1.
|
|
99
|
+
// 1. Lessons: the same fold `operator selfimprove backfill` runs (selfimprove/backfill.ts) — looped flywheel rows and
|
|
100
|
+
// the reviewers' mentor pairs into the global memories.md through the one curation. Until 2026-11-02 this pass
|
|
101
|
+
// curated by rules of its own into Operator_Memory.jsonl, which the prompt reaches only through recall's six
|
|
102
|
+
// newest notes. Honors the memory sink's opt-out (KODE_SELFIMPROVE_MEMORY=0 → counted, not written).
|
|
321
103
|
const flywheelDir = merged.flywheelDir ?? operatorPath("flywheel");
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
104
|
+
const fold = await foldLessons({
|
|
105
|
+
dir: flywheelDir,
|
|
106
|
+
memoriesFile: merged.memoriesFile,
|
|
107
|
+
scoresFile: merged.scoresFile,
|
|
108
|
+
maxLessons: merged.maxLessonsPerFile,
|
|
109
|
+
dryRun: process.env.KODE_SELFIMPROVE_MEMORY === "0",
|
|
110
|
+
});
|
|
111
|
+
const actions = [...fold.flagged, ...fold.taught].map((f) => f.action);
|
|
112
|
+
result.lessonsExtracted = actions.length;
|
|
113
|
+
result.lessonsCurated = actions.filter((a) => a !== "unchanged").length;
|
|
114
|
+
result.lessonsPersisted = fold.wrote ? result.lessonsCurated : 0;
|
|
115
|
+
result.loopedRows = fold.flagged.map((f) => ({ ts: f.ts, input: f.input.slice(0, 80), score: f.score }));
|
|
116
|
+
result.scoreCandidates = fold.candidates.length;
|
|
117
|
+
// 2. Recursive self-improvement: run the full flywheel processor over graded trajectories — SRFT
|
|
118
|
+
// masking + a processed/ export the training pipeline consumes. Best-effort: a failure here must
|
|
119
|
+
// never sink the memory-consolidation pass. (Wired 0.1.177 — FlywheelProcessor was dead code.)
|
|
327
120
|
try {
|
|
328
121
|
const processed = await new FlywheelProcessor({
|
|
329
122
|
flywheelDir,
|
|
@@ -333,19 +126,10 @@ export async function runConsolidationPass(opts = {}) {
|
|
|
333
126
|
result.flywheelProcessed = processed.processed;
|
|
334
127
|
}
|
|
335
128
|
catch { /* flywheel processing is best-effort — never fail consolidation over it */ }
|
|
336
|
-
//
|
|
337
|
-
const curated = curateLessons(candidates);
|
|
338
|
-
result.lessonsPersisted = curated.length;
|
|
339
|
-
// 3. Persist to memory file
|
|
129
|
+
// 3. Dedup count of the recall store
|
|
340
130
|
const memFile = merged.memoryFile ?? operatorPath("Operator_Memory.jsonl");
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
persistLessons(memFile, curated);
|
|
344
|
-
}
|
|
345
|
-
// 4. Dedup the memory file
|
|
346
|
-
const deduped = dedupMemoryFile(memFile);
|
|
347
|
-
result.memoryDeduped = deduped.length;
|
|
348
|
-
// 5. Curate project memories (best-effort, all repos)
|
|
131
|
+
result.memoryDeduped = dedupMemoryFile(memFile).length;
|
|
132
|
+
// 4. Curate project memories (best-effort, all repos)
|
|
349
133
|
// This is done in a second pass — for now we return success
|
|
350
134
|
result.projectMemoriesCurated = 0;
|
|
351
135
|
return result;
|
|
@@ -355,26 +139,3 @@ export async function runConsolidationPass(opts = {}) {
|
|
|
355
139
|
return result;
|
|
356
140
|
}
|
|
357
141
|
}
|
|
358
|
-
/** Group near-identical prompts into one TASK CLASS. Normalizes case/whitespace, strips punctuation, and
|
|
359
|
-
* keeps the first few significant tokens — so "fix the login bug" and "fix the login bug please" land in
|
|
360
|
-
* the same class and a repeated failure MODE can surface, where an exact-hash key never would. */
|
|
361
|
-
function taskClassKey(input) {
|
|
362
|
-
const tokens = input
|
|
363
|
-
.toLowerCase()
|
|
364
|
-
.replace(/[^\p{L}\p{N}\s]+/gu, " ")
|
|
365
|
-
.split(/\s+/)
|
|
366
|
-
.filter(Boolean)
|
|
367
|
-
.slice(0, 8);
|
|
368
|
-
return tokens.length ? tokens.join(" ") : hashInput(input);
|
|
369
|
-
}
|
|
370
|
-
function hashInput(input) {
|
|
371
|
-
// Simple hash for grouping similar tasks
|
|
372
|
-
let hash = 0;
|
|
373
|
-
const normalized = input.trim().toLowerCase().slice(0, 200);
|
|
374
|
-
for (let i = 0; i < normalized.length; i++) {
|
|
375
|
-
const char = normalized.charCodeAt(i);
|
|
376
|
-
hash = ((hash << 5) - hash) + char;
|
|
377
|
-
hash = hash & hash; // Convert to 32bit integer
|
|
378
|
-
}
|
|
379
|
-
return hash.toString(36);
|
|
380
|
-
}
|