phase: 02-operations-maintenance
plan: 02
type: execute
wave: 2
depends_on: [02-01]
files_modified: [api.py]
autonomous: true
requirements: [OPS-01]

must_haves:
truths:
- "POST /admin/reset deletes all rows from the chunks table"
- "POST /admin/reset returns the count of deleted chunks"
- "After reset, query returns no results"
artifacts:
- path: "api.py"
provides: "POST /admin/reset endpoint"
contains: "admin/reset"
key_links:
- from: "api.py /admin/reset"
to: "psycopg2 DELETE FROM chunks"
via: "database query"
pattern: "DELETE FROM chunks"



Add POST /admin/reset endpoint that truncates the chunks table, allowing the crew to reinitialize the knowledge base without direct database access.

Purpose: OPS-01 requires clearing chunks without manual DB access. This gives the crew a single API call to wipe and restart.
Output: Updated api.py with /admin/reset route.


@$HOME/.claude/get-shit-done/workflows/execute-plan.md
@$HOME/.claude/get-shit-done/templates/summary.md


@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/02-operations-maintenance/02-01-SUMMARY.md

DB_URL = os.environ["DATABASE_URL"]
conn = psycopg2.connect(DB_URL)
class IngestResponse(BaseModel):
    inserted: int
    source: str
CREATE TABLE IF NOT EXISTS chunks (
    id         SERIAL PRIMARY KEY,
    source     TEXT        NOT NULL,
    content    TEXT        NOT NULL,
    embedding  vector(768) NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);



Task 1: Add POST /admin/reset endpoint
api.py
api.py, schema.sql

Add to api.py:

  1. A new Pydantic response model:
class ResetResponse(BaseModel):
    deleted: int
    message: str
  1. A new route after the existing /health endpoint:
@app.post("/admin/reset", response_model=ResetResponse)
def admin_reset():
    try:
        conn = psycopg2.connect(DB_URL)
        cur = conn.cursor()
        cur.execute("SELECT COUNT(*) FROM chunks")
        count = cur.fetchone()[0]
        cur.execute("DELETE FROM chunks")
        conn.commit()
        cur.close()
        conn.close()
        return ResetResponse(deleted=count, message=f"{count} Chunks geloescht.")
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Reset fehlgeschlagen: {e}")

Key implementation details:
- Use DELETE FROM (not TRUNCATE) because TRUNCATE requires elevated privileges and cannot be rolled back easily.
- First SELECT COUNT(*) to know how many were deleted, then DELETE FROM chunks.
- Wrap in try/except, return 500 with detail on failure.
- Connection is opened and closed within the handler (same pattern as query.py).
- Use DB_URL that was added in plan 02-01.


cd /Users/bmt/Documents/RKL-OZM-Chat-Hook-v.0.0 && python -c "import ast; ast.parse(open('api.py').read()); print('syntax ok')" && grep -q 'admin/reset' api.py && grep -q 'DELETE FROM chunks' api.py && grep -q 'ResetResponse' api.py && echo 'all checks passed'


- grep "admin/reset" api.py returns a match (route exists)
- grep "DELETE FROM chunks" api.py returns a match (deletion logic)
- grep "ResetResponse" api.py returns a match (response model)
- grep "deleted" api.py returns a match (count returned)
- python -c "import ast; ast.parse(open('api.py').read())" succeeds (valid Python)

POST /admin/reset deletes all chunks and returns the count. Crew can reinitialize knowledge base via API without touching the database directly.


- python -c "import ast; ast.parse(open('api.py').read())" succeeds
- api.py contains POST /admin/reset route
- Route uses DELETE FROM chunks and returns deleted count


POST /admin/reset clears the chunks table and returns {"deleted": N, "message": "N Chunks geloescht."}. No direct DB access needed by crew.

After completion, create `.planning/phases/02-operations-maintenance/02-02-SUMMARY.md`