refactor: remove self-learning and the optimizer package (P1.4)

Self-learning is excluded from the community edition (ADR-0004); the
project owner reworks it separately. Cost tracking stays.

- agent: delete behaviour evolution (evolve-schema, iterative GEPA,
  compose-evolution, evolution gates, orchestrator and deploy),
  improvement and correction detection, AgentLearning, the eval-dataset
  builder, optimization-capture and the agent_insights tool. Secret
  detection moves from eval-dataset to secret-patterns. The LLM wiring
  keeps only the Haiku adapter and judge call used by skill audit and
  hygiene, so @ax-llm/ax is now declared by agent instead of server.
- server: delete /api/evolution/*, the evolution and optimizer services,
  GEPA expansion of the first chat message, the prompt_optimization and
  monthly_assessment jobs, the idle-session reviewer and its
  session-reviewer persona, prompt injection of past corrections and
  thumbs-down recorded as correction signals. Existing job rows of the
  removed types are ignored, not deleted.
- core: delete OptimizationLogStore; stop re-exporting the improvement
  signal and evolution run stores.
- web: delete the Evolution screen and the two job types in the
  automation editor.
- delete packages/optimizer.

Also logs UF-027 (self-learning loops read data nothing collects) and
UF-028 (the Settings prompt-shape choice is ignored by chat).
This commit is contained in:
shumeiko.it
2026-10-20 00:54:58 +02:00
parent b734c1d3d2
commit 2e1999a3f6
112 changed files with 336 additions and 16165 deletions

View File

@@ -12,15 +12,13 @@ import type { MindDB } from '@waggle/hive-mind-core';
// ── Types ──────────────────────────────────────────────────────────────
export type CronJobType = 'agent_task' | 'memory_consolidation' | 'workspace_health' | 'proactive' | 'prompt_optimization' | 'monthly_assessment' | 'connector_fetch' | 'loop';
export type CronJobType = 'agent_task' | 'memory_consolidation' | 'workspace_health' | 'proactive' | 'connector_fetch' | 'loop';
export const VALID_JOB_TYPES: Set<string> = new Set([
'agent_task',
'memory_consolidation',
'workspace_health',
'proactive',
'prompt_optimization',
'monthly_assessment',
'connector_fetch',
// Loop v0: a stateful, memory-powered, report-only (L1) scheduled automation.
// Composes recall + maker (toolless LLM) + checker (LLMJudge) + memory write.

View File

@@ -12,7 +12,7 @@
// Waggle-specific (non-extracted) modules below the substrate re-exports stay
// in this package: config, multi-mind, workspace orchestration, vault, telemetry,
// install-audit, cron-store, skill-hashes, team-sync, file-store, file-indexer,
// memory-import, optimization-log.
// memory-import.
// ── Substrate re-exports from @waggle/hive-mind-core (Apache 2.0 OSS) ──
export {
@@ -58,15 +58,10 @@ export {
type EmbeddingProviderInstance, type EmbeddingQuotaStatus,
normalizeEntityName, findDuplicates, isNoiseName, isLikelyAcronym,
Ontology, validateEntity, type EntitySchema, type ValidationResult,
ImprovementSignalStore,
type ImprovementSignal, type ActionableSignal, type SignalCategory, type ActionableThresholds,
ExecutionTraceStore, EXECUTION_TRACES_TABLE_SQL,
type ExecutionTrace, type ParsedExecutionTrace, type TraceOutcome,
type TracePayload, type TraceToolCall, type TraceReasoningStep,
type StartTraceInput, type FinalizeTraceInput, type TraceQueryFilter,
EvolutionRunStore, EVOLUTION_RUNS_TABLE_SQL,
type EvolutionRun, type EvolutionRunStatus, type EvolutionRunTarget,
type CreateEvolutionRunInput, type EvolutionRunFilter,
reconcileIndexes, reconcileFtsIndex, reconcileVecIndex, cleanOrphanVectors, cleanOrphanFts,
type ReconcileResult,
ConceptTracker, CONCEPT_MASTERY_TABLE_SQL,
@@ -144,7 +139,3 @@ export { processImport, parseChatGPTExport, parseClaudeExport, extractKnowledge
export { createFileStore, LocalFileStore, LinkedDirStore, S3FileStore, isSensitiveFilePath, type FileStore, type FileEntry, type StorageInfo, type S3Config } from './file-store.js';
export { FileIndexer, MAX_CONTENT_BYTES, type FileIndexRow, type FileIndexResult } from './file-indexer.js';
export type { ImportSource, ImportResult, ExtractedKnowledge, ParsedConversation, ConversationMessage } from './memory-import.js';
export {
OptimizationLogStore, OPTIMIZATION_LOG_TABLE_SQL,
type OptimizationLogEntry, type CreateOptimizationLogInput,
} from './optimization-log.js';

View File

@@ -5,7 +5,7 @@
* failed) so there is a verifiable history of what was installed, when, why,
* and by whom.
*
* Follows the same pattern as ImprovementSignalStore — operates on the .mind DB.
* Operates on the .mind DB like the other stores in this package.
*/
import type { MindDB } from '@waggle/hive-mind-core';

View File

@@ -1,154 +0,0 @@
/**
* Optimization Log Store — SQLite persistence for GEPA prompt optimization data.
*
* Captures agent interaction metadata (system prompts, tools used, turn counts,
* correction signals) for background analysis by the PromptOptimizer.
*
* Follows the same lazy-table pattern as CronStore and InstallAuditStore —
* operates on the .mind DB with auto-table creation.
*/
import type { MindDB } from '@waggle/hive-mind-core';
// ── Types ──────────────────────────────────────────────────────────────
export interface OptimizationLogEntry {
id: number;
session_id: string;
workspace_id: string;
system_prompt: string;
tools_used: string; // JSON array
turn_count: number;
was_correction: number; // SQLite integer boolean
input_tokens: number;
output_tokens: number;
timestamp: string;
}
export interface CreateOptimizationLogInput {
sessionId: string;
workspaceId: string;
systemPrompt: string;
toolsUsed: string[];
turnCount: number;
wasCorrection: boolean;
inputTokens?: number;
outputTokens?: number;
}
// ── Table DDL ──────────────────────────────────────────────────────────
export const OPTIMIZATION_LOG_TABLE_SQL = `
CREATE TABLE IF NOT EXISTS optimization_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL,
workspace_id TEXT NOT NULL,
system_prompt TEXT NOT NULL,
tools_used TEXT NOT NULL DEFAULT '[]',
turn_count INTEGER NOT NULL DEFAULT 0,
was_correction INTEGER NOT NULL DEFAULT 0,
input_tokens INTEGER NOT NULL DEFAULT 0,
output_tokens INTEGER NOT NULL DEFAULT 0,
timestamp TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_optlog_workspace ON optimization_log (workspace_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS idx_optlog_timestamp ON optimization_log (timestamp DESC);
`;
// ── Store ──────────────────────────────────────────────────────────────
export class OptimizationLogStore {
private db: MindDB;
constructor(db: MindDB) {
this.db = db;
this.ensureTable();
}
private ensureTable(): void {
const raw = this.db.getDatabase();
const exists = raw.prepare(
"SELECT name FROM sqlite_master WHERE type='table' AND name='optimization_log'",
).get();
if (!exists) {
raw.exec(OPTIMIZATION_LOG_TABLE_SQL);
}
}
/** Insert a new optimization log entry capturing an agent interaction. */
insert(input: CreateOptimizationLogInput): OptimizationLogEntry {
const raw = this.db.getDatabase();
const result = raw.prepare(`
INSERT INTO optimization_log (session_id, workspace_id, system_prompt, tools_used, turn_count, was_correction, input_tokens, output_tokens)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
`).run(
input.sessionId,
input.workspaceId,
input.systemPrompt,
JSON.stringify(input.toolsUsed),
input.turnCount,
input.wasCorrection ? 1 : 0,
input.inputTokens ?? 0,
input.outputTokens ?? 0,
);
return raw.prepare(
'SELECT * FROM optimization_log WHERE id = ?',
).get(result.lastInsertRowid) as OptimizationLogEntry;
}
/** Get recent optimization log entries, ordered by most recent first. */
getRecent(limit: number = 50): OptimizationLogEntry[] {
return this.db.getDatabase().prepare(
'SELECT * FROM optimization_log ORDER BY timestamp DESC, id DESC LIMIT ?',
).all(limit) as OptimizationLogEntry[];
}
/** Get log entries for a specific workspace. */
getByWorkspace(workspaceId: string, limit: number = 50): OptimizationLogEntry[] {
return this.db.getDatabase().prepare(
'SELECT * FROM optimization_log WHERE workspace_id = ? ORDER BY timestamp DESC, id DESC LIMIT ?',
).all(workspaceId, limit) as OptimizationLogEntry[];
}
/** Get aggregate stats: total entries, correction rate, avg turn count, total tokens. */
getStats(): { total: number; correctionRate: number; avgTurnCount: number; totalInputTokens: number; totalOutputTokens: number } {
const raw = this.db.getDatabase();
const row = raw.prepare(`
SELECT
COUNT(*) as total,
COALESCE(AVG(was_correction * 1.0), 0) as correction_rate,
COALESCE(AVG(turn_count), 0) as avg_turn_count,
COALESCE(SUM(input_tokens), 0) as total_input_tokens,
COALESCE(SUM(output_tokens), 0) as total_output_tokens
FROM optimization_log
`).get() as {
total: number;
correction_rate: number;
avg_turn_count: number;
total_input_tokens: number;
total_output_tokens: number;
};
return {
total: row.total,
correctionRate: row.correction_rate,
avgTurnCount: row.avg_turn_count,
totalInputTokens: row.total_input_tokens,
totalOutputTokens: row.total_output_tokens,
};
}
/** Delete entries older than the given number of days. */
pruneOlderThan(days: number): number {
const result = this.db.getDatabase().prepare(
`DELETE FROM optimization_log WHERE timestamp < datetime('now', '-' || ? || ' days')`,
).run(days);
return result.changes;
}
/** Clear all entries (for testing). */
clear(): void {
this.db.getDatabase().prepare('DELETE FROM optimization_log').run();
}
}