гих хук и сохранение изменений в контексте стори
This commit is contained in:
@@ -20,16 +20,15 @@ if [ -z "$STORY" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Run index (changed files only: previous commit -> HEAD)
|
||||
# Run index: all changes in the story (main..HEAD), not per-commit
|
||||
if command -v rag-agent >/dev/null 2>&1; then
|
||||
rag-agent index --changed --base-ref HEAD~1 --head-ref HEAD --story "$STORY"
|
||||
rag-agent index --changed --base-ref main --head-ref HEAD --story "$STORY"
|
||||
elif [ -n "${VIRTUAL_ENV}" ]; then
|
||||
rag-agent index --changed --base-ref HEAD~1 --head-ref HEAD --story "$STORY"
|
||||
rag-agent index --changed --base-ref main --head-ref HEAD --story "$STORY"
|
||||
else
|
||||
# Try repo venv or python -m
|
||||
if [ -f "venv/bin/rag-agent" ]; then
|
||||
venv/bin/rag-agent index --changed --base-ref HEAD~1 --head-ref HEAD --story "$STORY"
|
||||
venv/bin/rag-agent index --changed --base-ref main --head-ref HEAD --story "$STORY"
|
||||
else
|
||||
PYTHONPATH=src python -m rag_agent.cli index --changed --base-ref HEAD~1 --head-ref HEAD --story "$STORY" 2>/dev/null || true
|
||||
PYTHONPATH=src python -m rag_agent.cli index --changed --base-ref main --head-ref HEAD --story "$STORY" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
43
scripts/post-receive
Normal file
43
scripts/post-receive
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env sh
|
||||
# Server-side hook: index changed files after push. Install in bare repo: cp scripts/post-receive /path/to/repo.git/hooks/post-receive
|
||||
# Requires: RAG_REPO_PATH = path to a non-bare clone of this repo (worktree), updated by this hook to newrev.
|
||||
# RAG_DB_DSN, RAG_EMBEDDINGS_DIM; optionally GIGACHAT_CREDENTIALS.
|
||||
# Story is derived from ref name (e.g. refs/heads/main -> main).
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "${RAG_REPO_PATH}" ]; then
|
||||
echo "post-receive: RAG_REPO_PATH (path to clone worktree) is required. Skipping index."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Read refs from stdin (refname SP oldrev SP newrev LF)
|
||||
while read -r refname oldrev newrev; do
|
||||
# Skip branch deletions
|
||||
if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then
|
||||
continue
|
||||
fi
|
||||
# Branch name from ref (e.g. refs/heads/main -> main)
|
||||
branch="${refname#refs/heads/}"
|
||||
[ -z "$branch" ] && continue
|
||||
|
||||
# Update worktree to newrev so rag-agent can read files from disk
|
||||
if [ -d "${RAG_REPO_PATH}/.git" ]; then
|
||||
git -C "${RAG_REPO_PATH}" fetch origin 2>/dev/null || true
|
||||
git -C "${RAG_REPO_PATH}" checkout -f "${newrev}" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Index all commits in the story (main..newrev), not just this push
|
||||
export RAG_REPO_PATH
|
||||
if command -v rag-agent >/dev/null 2>&1; then
|
||||
rag-agent index --changed --base-ref main --head-ref "${newrev}" --story "${branch}"
|
||||
elif [ -f "${RAG_AGENT_VENV}/bin/rag-agent" ]; then
|
||||
"${RAG_AGENT_VENV}/bin/rag-agent" index --changed --base-ref main --head-ref "${newrev}" --story "${branch}"
|
||||
else
|
||||
if [ -n "${RAG_AGENT_SRC}" ]; then
|
||||
PYTHONPATH="${RAG_AGENT_SRC}/src" "${RAG_AGENT_PYTHON:-python3}" -m rag_agent.cli index --changed --base-ref main --head-ref "${newrev}" --story "${branch}" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -7,7 +7,10 @@ CREATE EXTENSION IF NOT EXISTS vector;
|
||||
CREATE TABLE IF NOT EXISTS stories (
|
||||
id SERIAL PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc')
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc'),
|
||||
indexed_base_ref TEXT,
|
||||
indexed_head_ref TEXT,
|
||||
indexed_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS documents (
|
||||
@@ -25,9 +28,15 @@ CREATE TABLE IF NOT EXISTS chunks (
|
||||
chunk_index INTEGER NOT NULL,
|
||||
hash TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
embedding vector(1536) NOT NULL
|
||||
embedding vector(1536) NOT NULL,
|
||||
start_line INTEGER,
|
||||
end_line INTEGER,
|
||||
change_type TEXT NOT NULL DEFAULT 'added'
|
||||
CHECK (change_type IN ('added', 'modified', 'unchanged')),
|
||||
previous_content TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_documents_story_id ON documents(story_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_document_id ON chunks(document_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_embedding ON chunks USING ivfflat (embedding vector_cosine_ops);
|
||||
CREATE INDEX IF NOT EXISTS idx_chunks_change_type ON chunks(change_type);
|
||||
|
||||
Reference in New Issue
Block a user