Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .agents/scripts/memory/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,33 @@ EOF
db "$MEMORY_DB" "ALTER TABLE learning_access ADD COLUMN graduated_at TEXT DEFAULT NULL;" || echo "[WARN] Failed to add graduated_at column (may already exist)" >&2
fi

# Create pattern_metadata table if missing (t1095 migration)
# Companion table for pattern records — stores strategy, quality, failure_mode, tokens
local has_pattern_metadata
has_pattern_metadata=$(db "$MEMORY_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='pattern_metadata';" 2>/dev/null || echo "0")
if [[ "$has_pattern_metadata" == "0" ]]; then
log_info "Creating pattern_metadata table (t1095)..."
db "$MEMORY_DB" <<'EOF'
CREATE TABLE IF NOT EXISTS pattern_metadata (
id TEXT PRIMARY KEY,
strategy TEXT DEFAULT 'normal' CHECK(strategy IN ('normal', 'prompt-repeat', 'escalated')),
quality TEXT DEFAULT NULL CHECK(quality IS NULL OR quality IN ('ci-pass-first-try', 'ci-pass-after-fix', 'needs-human')),
failure_mode TEXT DEFAULT NULL CHECK(failure_mode IS NULL OR failure_mode IN ('hallucination', 'context-miss', 'incomplete', 'wrong-file', 'timeout')),
tokens_in INTEGER DEFAULT NULL,
tokens_out INTEGER DEFAULT NULL
);
EOF
# Backfill existing pattern records with default strategy='normal'
local pattern_types="$PATTERN_TYPES_SQL"
local backfill_count
backfill_count=$(db "$MEMORY_DB" "SELECT COUNT(*) FROM learnings WHERE type IN ($pattern_types);" 2>/dev/null || echo "0")
if [[ "$backfill_count" -gt 0 ]]; then
db "$MEMORY_DB" "INSERT OR IGNORE INTO pattern_metadata (id, strategy) SELECT id, 'normal' FROM learnings WHERE type IN ($pattern_types);"
log_success "Backfilled $backfill_count existing pattern records into pattern_metadata"
fi
log_success "pattern_metadata table created (t1095)"
fi

return 0
}

Expand Down Expand Up @@ -255,6 +282,17 @@ CREATE TABLE IF NOT EXISTS learning_relations (
relation_type TEXT CHECK(relation_type IN ('updates', 'extends', 'derives')),
created_at TEXT DEFAULT CURRENT_TIMESTAMP
);

-- Extended pattern metadata (t1095) — companion table for pattern records
-- Stores structured fields that can't go in FTS5 (strategy, quality, failure_mode, tokens)
CREATE TABLE IF NOT EXISTS pattern_metadata (
id TEXT PRIMARY KEY,
strategy TEXT DEFAULT 'normal' CHECK(strategy IN ('normal', 'prompt-repeat', 'escalated')),
quality TEXT DEFAULT NULL CHECK(quality IS NULL OR quality IN ('ci-pass-first-try', 'ci-pass-after-fix', 'needs-human')),
failure_mode TEXT DEFAULT NULL CHECK(failure_mode IS NULL OR failure_mode IN ('hallucination', 'context-miss', 'incomplete', 'wrong-file', 'timeout')),
tokens_in INTEGER DEFAULT NULL,
tokens_out INTEGER DEFAULT NULL
);
EOF
log_success "Database initialized with relational versioning support"
else
Expand Down
Loading
Loading