@0perator/operator 0.1.285 → 0.1.313

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 (98) hide show
  1. package/README.md +24 -2
  2. package/dist/acp/agent.js +2 -1
  3. package/dist/acp/config-options.js +3 -1
  4. package/dist/acp/tool-map.js +2 -1
  5. package/dist/auth/commands.js +69 -13
  6. package/dist/autonomy/agent-cli.js +304 -0
  7. package/dist/autonomy/cloud-agent.js +439 -0
  8. package/dist/autonomy/cron-lifecycle.js +78 -0
  9. package/dist/autonomy/cron-lock.js +121 -0
  10. package/dist/autonomy/cron.js +216 -43
  11. package/dist/autonomy/delegate.js +5 -1
  12. package/dist/autonomy/incidents.js +135 -0
  13. package/dist/autonomy/session-factory.js +25 -16
  14. package/dist/background/index.js +40 -0
  15. package/dist/bus/inbox.js +20 -0
  16. package/dist/classifier/config.js +47 -0
  17. package/dist/classifier/modes.js +41 -0
  18. package/dist/classifier/types.js +1 -0
  19. package/dist/cli.js +529 -53
  20. package/dist/config/features.js +69 -0
  21. package/dist/config/persona.js +118 -99
  22. package/dist/config/scaffold.js +15 -0
  23. package/dist/config/settings.js +96 -6
  24. package/dist/consolidation/sleep.js +73 -11
  25. package/dist/engine/agent.js +275 -18
  26. package/dist/engine/anthropic-chat.js +343 -0
  27. package/dist/engine/aurora.js +101 -13
  28. package/dist/engine/batch-scheduler.js +41 -9
  29. package/dist/engine/classifier.js +85 -0
  30. package/dist/engine/compaction.js +24 -5
  31. package/dist/engine/fast-start.js +25 -0
  32. package/dist/engine/loop-guard.js +448 -0
  33. package/dist/engine/net-error.js +24 -0
  34. package/dist/engine/repetition-guard.js +180 -0
  35. package/dist/engine/selfheal.js +8 -0
  36. package/dist/engine/toolcalls.js +51 -1
  37. package/dist/engine/verify-gate.js +2 -0
  38. package/dist/flywheel/processor.js +78 -31
  39. package/dist/flywheel/srft.js +13 -0
  40. package/dist/hooks/index.js +196 -0
  41. package/dist/mcp/config.js +21 -1
  42. package/dist/memory/index.js +0 -0
  43. package/dist/memory/providers.js +210 -0
  44. package/dist/memory/session-catalog.js +422 -0
  45. package/dist/memory/session-providers.js +121 -0
  46. package/dist/memory/session-sources.js +335 -0
  47. package/dist/memory/skylark.js +131 -0
  48. package/dist/models/bench.js +103 -0
  49. package/dist/models/registry.js +144 -0
  50. package/dist/models/switch.js +69 -0
  51. package/dist/observability/blackbox.js +37 -0
  52. package/dist/permissions/policy.js +31 -6
  53. package/dist/router/discovery.js +127 -0
  54. package/dist/router/models.js +107 -16
  55. package/dist/router/portal.js +100 -0
  56. package/dist/router/router.js +1 -1
  57. package/dist/services/preflight.js +55 -7
  58. package/dist/session.js +316 -46
  59. package/dist/tools/chauffeur.js +12 -0
  60. package/dist/tools/executor.js +19 -9
  61. package/dist/tools/find-files.js +483 -0
  62. package/dist/tools/git-pr.js +94 -0
  63. package/dist/tools/incident-tools.js +82 -0
  64. package/dist/tools/memory.js +12 -2
  65. package/dist/tools/registry.js +281 -85
  66. package/dist/tools/semantic-compress.js +124 -0
  67. package/dist/tools/shell-context.js +1 -0
  68. package/dist/tools/shell-jobs.js +160 -0
  69. package/dist/tools/shell-session.js +170 -4
  70. package/dist/tools/wave-tools.js +609 -0
  71. package/dist/tools/wave2-tools.js +411 -0
  72. package/dist/ui/App.js +15 -4
  73. package/dist/ui/BgPanel.js +30 -6
  74. package/dist/ui/Composer.js +11 -1
  75. package/dist/ui/QuestionPrompt.js +31 -11
  76. package/dist/ui/SessionPicker.js +86 -0
  77. package/dist/ui/StatusRule.js +5 -5
  78. package/dist/ui/ToolStep.js +2 -1
  79. package/dist/ui/Transcript.js +17 -1
  80. package/dist/ui/index.js +1 -1
  81. package/dist/ui/liveTools.js +21 -3
  82. package/dist/ui/slashCommands.js +2 -0
  83. package/dist/util/screenshots.js +74 -8
  84. package/dist/util/slash.js +2 -2
  85. package/package.json +8 -2
  86. package/dist/engine/cli.js +0 -1171
  87. package/dist/router/models.js.bak +0 -78
  88. package/dist/router/models.js.bak-1791259923 +0 -78
  89. package/dist/router/models.js.bak-pre-gateway +0 -78
  90. package/dist/router/models.js.bak-pre-patch2 +0 -78
  91. package/dist/router/models.js.bak2 +0 -78
  92. package/dist/services/model-autodetect.js +0 -240
  93. package/dist/tools/native-redirect.js +0 -140
  94. package/dist/tools/power-tools.js +0 -627
  95. package/dist/tools/registry.js.bak-1791259948 +0 -1914
  96. package/dist/tools/registry.js.bak-pre-plugins +0 -1914
  97. package/dist/ui/BusTray.js +0 -70
  98. package/dist/ui/resize.js +0 -160
@@ -15,7 +15,8 @@
15
15
  import { readFileSync, writeFileSync, existsSync, appendFileSync, mkdirSync } from "node:fs";
16
16
  import { dirname } from "node:path";
17
17
  import { operatorPath } from "../config/home.js";
18
- import { FlywheelProcessor } from "../flywheel/processor.js";
18
+ import { FlywheelProcessor, scoreThreshold } from "../flywheel/processor.js";
19
+ import { isPromotable } from "../flywheel/srft.js";
19
20
  const DEFAULTS = {
20
21
  enabled: false,
21
22
  idleThresholdSec: 30,
@@ -75,6 +76,13 @@ export function dedupMemoryFile(filepath) {
75
76
  // ---------------------------------------------------------------------------
76
77
  // Lesson extraction from flywheel trajectories
77
78
  // ---------------------------------------------------------------------------
79
+ /** Min repeated failures on one task CLASS before it becomes a candidate lesson. Lowered from the old
80
+ * `> 2 on a byte-identical input hash` (which real traffic never satisfied) to a bar a fuzzy task class
81
+ * can actually reach. Override with KODE_CONSOLIDATION_FAILURE_MIN. */
82
+ const REPEATED_FAILURE_MIN = (() => {
83
+ const n = Number(process.env.KODE_CONSOLIDATION_FAILURE_MIN);
84
+ return Number.isFinite(n) && n >= 1 ? n : 2;
85
+ })();
78
86
  /** Extract candidate lessons from graded flywheel trajectories.
79
87
  * Scans the flywheel JSONL for patterns that suggest a reusable lesson:
80
88
  * - Repeated failures on the same tool/command
@@ -95,28 +103,61 @@ export async function extractFlywheelLessons(flywheelDir) {
95
103
  const filepath = join(flywheelDir, file);
96
104
  const raw = readFileSync(filepath, "utf8");
97
105
  const lines = raw.split("\n").filter(Boolean);
106
+ // Mentor-pair lanes are already-distilled, human/teacher-VERIFIED lessons (chosen vs rejected with the
107
+ // reasoning attached) — the richest signal in the directory. Each valid pair IS a lesson; no counting
108
+ // bar applies. Before this path existed the extractor parsed these files as trajectories, found no
109
+ // graded/score fields, and dropped every row — the hand-curated lane contributed nothing.
110
+ if (file.startsWith("mentor-pairs")) {
111
+ for (const line of lines) {
112
+ try {
113
+ const pair = JSON.parse(line);
114
+ const chosen = typeof pair.chosen === "string" ? pair.chosen.trim() : "";
115
+ if (!chosen)
116
+ continue;
117
+ lessons.push({
118
+ type: "mentor_pair",
119
+ pattern: (pair.lens || "general").slice(0, 60),
120
+ count: 1,
121
+ total: 1,
122
+ source: filepath,
123
+ text: chosen,
124
+ });
125
+ }
126
+ catch { /* skip malformed rows */ }
127
+ }
128
+ continue;
129
+ }
98
130
  // Track per-task patterns
99
131
  const taskCounts = new Map();
132
+ const threshold = scoreThreshold();
100
133
  for (const line of lines) {
101
134
  try {
102
135
  const row = JSON.parse(line);
103
- if (!row.graded)
104
- continue;
105
- // Key by task signature (input hash)
106
- const key = hashInput(row.input ?? "");
136
+ // Key by TASK CLASS (normalized first tokens), not a byte-exact input hash. Real prompts almost
137
+ // never repeat verbatim, so the old exact-hash grouping (hashInput) produced ~0 candidates on live
138
+ // traffic; collapsing near-identical prompts into a class is what lets a repeated failure MODE show.
139
+ const key = taskClassKey(row.input ?? "");
107
140
  const count = taskCounts.get(key) ?? { total: 0, graded: 0, failed: 0 };
108
141
  count.total++;
142
+ // Failure MINING is deliberately not gated on promotability: an unverified failure is almost never
143
+ // `graded:true`, so requiring isPromotable here meant count.failed could not increment on live
144
+ // traffic (verified 2026-10-22: 31/32 recent rows graded+verified, 0 unverified-promotable) — the
145
+ // structural reason every nightly pass logged extracted=0. The promotion gate still governs what
146
+ // the TRAINING pipeline exports (processor.ts); lesson mining wants the failures it excludes.
109
147
  if (row.unverified) {
110
148
  count.failed++;
111
149
  }
112
- count.graded++;
150
+ if (isPromotable(row, threshold)) {
151
+ count.graded++;
152
+ }
113
153
  taskCounts.set(key, count);
114
154
  }
115
155
  catch { /* skip malformed rows */ }
116
156
  }
117
- // Identify patterns worth distilling
157
+ // Identify patterns worth distilling. A repeated failure on the same task CLASS (>=2) is the trigger —
158
+ // a real, attainable bar, unlike the old `>2 on an identical input hash` that live traffic never hit.
118
159
  for (const [key, count] of taskCounts) {
119
- if (count.failed > 2) {
160
+ if (count.failed >= REPEATED_FAILURE_MIN) {
120
161
  lessons.push({
121
162
  type: "repeated_failure",
122
163
  pattern: key,
@@ -132,10 +173,14 @@ export async function extractFlywheelLessons(flywheelDir) {
132
173
  /** Merge candidate lessons into curated form.
133
174
  * Groups candidates by type+pattern, extracts a distilled lesson text. */
134
175
  export function curateLessons(candidates) {
135
- // Group by type
176
+ // Group by type. Mentor pairs key on their distilled TEXT, not the lens: several pairs share one lens
177
+ // (e.g. chain-to-completion) but each carries a distinct rule — a lens-keyed group would collapse them
178
+ // into whichever rule happened to arrive first.
136
179
  const groups = new Map();
137
180
  for (const c of candidates) {
138
- const key = `${c.type}:${c.pattern.slice(0, 40)}`;
181
+ const key = c.type === "mentor_pair"
182
+ ? `${c.type}:${(c.text ?? "").slice(0, 80)}`
183
+ : `${c.type}:${c.pattern.slice(0, 40)}`;
139
184
  const existing = groups.get(key) ?? [];
140
185
  existing.push(c);
141
186
  groups.set(key, existing);
@@ -162,11 +207,16 @@ export function curateLessons(candidates) {
162
207
  text = `Verification gap: ${count} turns changed files without passing checks. ` +
163
208
  `Lesson: the verify-before-done gate needs a nudge on this task type.`;
164
209
  break;
210
+ case "mentor_pair":
211
+ // Already distilled and verified at capture time — carry the rule through verbatim (capped),
212
+ // prefixed with its lens so recall can match on the failure mode it addresses.
213
+ text = `Mentor rule [${items[0].pattern}]: ${(items[0].text ?? "").slice(0, 400)}`;
214
+ break;
165
215
  }
166
216
  return {
167
217
  ts: Date.now(),
168
218
  text,
169
- tags: [type, `count:${count}`],
219
+ tags: type === "mentor_pair" ? [type, items[0].pattern] : [type, `count:${count}`],
170
220
  source: items[0].source,
171
221
  candidates: items.map(i => i.pattern),
172
222
  };
@@ -317,6 +367,18 @@ export async function runConsolidationPass(opts = {}) {
317
367
  return result;
318
368
  }
319
369
  }
370
+ /** Group near-identical prompts into one TASK CLASS. Normalizes case/whitespace, strips punctuation, and
371
+ * keeps the first few significant tokens — so "fix the login bug" and "fix the login bug please" land in
372
+ * the same class and a repeated failure MODE can surface, where an exact-hash key never would. */
373
+ function taskClassKey(input) {
374
+ const tokens = input
375
+ .toLowerCase()
376
+ .replace(/[^\p{L}\p{N}\s]+/gu, " ")
377
+ .split(/\s+/)
378
+ .filter(Boolean)
379
+ .slice(0, 8);
380
+ return tokens.length ? tokens.join(" ") : hashInput(input);
381
+ }
320
382
  function hashInput(input) {
321
383
  // Simple hash for grouping similar tasks
322
384
  let hash = 0;