diff --git a/.env.example b/.env.example index a134dad..da847c2 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,8 @@ GIT_REMOTE=ssh://git@git.example.invalid/your-team/knowledge.git GIT_BRANCH=main HINDSIGHT_PORT=8080 +# Pin a release instead of :latest, e.g. ghcr.io/drdroidlab/hindsight:0.1.0 +# HINDSIGHT_IMAGE=ghcr.io/drdroidlab/hindsight:latest SYNC_INTERVAL=60 STALE_AFTER_DAYS=90 READ_ONLY=false diff --git a/.github/workflows/release-image.yml b/.github/workflows/release-image.yml new file mode 100644 index 0000000..ed96aef --- /dev/null +++ b/.github/workflows/release-image.yml @@ -0,0 +1,71 @@ +name: release-image +# A v* tag pushes ghcr.io/drdroidlab/hindsight:, :. and :latest +# (latest is skipped for pre-releases). A manual run builds both platforms without pushing. +on: + push: + tags: ['v*'] + workflow_dispatch: +permissions: + contents: read +concurrency: + group: release-image-${{ github.ref }} + cancel-in-progress: false +env: + IMAGE: ghcr.io/drdroidlab/hindsight +jobs: + image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Check tag matches project version + if: github.ref_type == 'tag' + run: | + version="$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')" + if [ "v${version}" != "${GITHUB_REF_NAME}" ]; then + echo "::error::Tag ${GITHUB_REF_NAME} does not match pyproject.toml version ${version}" + exit 1 + fi + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE }} + tags: | + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} + type=sha,enable=${{ github.event_name == 'workflow_dispatch' }} + labels: | + org.opencontainers.image.title=Hindsight SRE + io.modelcontextprotocol.server.name=io.github.DrDroidLab/hindsight-sre + - name: Build amd64 image for the smoke test + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64 + load: true + tags: hindsight-sre:ci + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Run offline seeded demo smoke + run: python3 scripts/demo-smoke.py --image hindsight-sre:ci + - if: github.event_name == 'push' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build multi-arch image and push on tags + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name == 'push' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml new file mode 100644 index 0000000..c939b04 --- /dev/null +++ b/.github/workflows/release-pypi.yml @@ -0,0 +1,108 @@ +name: release-pypi +# A v* tag publishes hindsight-sre to PyPI and creates the GitHub release. +# A manual run publishes a .devN build of the current version to TestPyPI as a dry run. +on: + push: + tags: ['v*'] + workflow_dispatch: +permissions: + contents: read +concurrency: + group: release-pypi-${{ github.ref }} + cancel-in-progress: false +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Check tag matches project version + if: github.ref_type == 'tag' + run: | + version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')" + if [ "v${version}" != "${GITHUB_REF_NAME}" ]; then + echo "::error::Tag ${GITHUB_REF_NAME} does not match pyproject.toml version ${version}" + exit 1 + fi + if ! python -c 'import json, sys; s = json.load(open("server.json")); sys.exit(any(v != sys.argv[1] for v in [s["version"], *(p["version"] for p in s["packages"])]))' "${version}"; then + echo "::error::server.json versions do not match pyproject.toml version ${version}" + exit 1 + fi + - name: Use a unique dev version for the TestPyPI dry run + if: github.event_name == 'workflow_dispatch' + run: sed -i -E "s/^version = \"([^\"]+)\"/version = \"\1.dev${GITHUB_RUN_NUMBER}\"/" pyproject.toml + - run: pip install 'build>=1' 'twine>=6' + - run: python -m build + - run: twine check --strict dist/* + - name: Check wheel bundles the UI and sample knowledge + run: | + python - <<'EOF' + import glob, zipfile + names = zipfile.ZipFile(glob.glob("dist/*.whl")[0]).namelist() + required = ["hindsight/static/index.html", "hindsight/static/assets/app.js"] + missing = [n for n in required if n not in names] + if not any(n.startswith("hindsight/sample-knowledge/") for n in names): + missing.append("hindsight/sample-knowledge/") + if missing: + raise SystemExit(f"wheel is missing: {missing}") + EOF + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + if-no-files-found: error + + publish-testpypi: + if: github.event_name == 'workflow_dispatch' + needs: build + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://test.pypi.org/p/hindsight-sre + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + publish-pypi: + if: github.ref_type == 'tag' + needs: build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/hindsight-sre + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + if: github.ref_type == 'tag' + needs: publish-pypi + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + - name: Create GitHub release with the built distributions + env: + GH_TOKEN: ${{ github.token }} + run: >- + gh release create "$GITHUB_REF_NAME" dist/* + --repo "$GITHUB_REPOSITORY" --verify-tag --generate-notes + --title "$GITHUB_REF_NAME" diff --git a/Dockerfile b/Dockerfile index 0bb6ffe..d364825 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends git openssh-cli && mkdir -p /data /opt/hindsight \ && chown -R hindsight:hindsight /data /opt/hindsight COPY --from=python-build /install/ /usr/local/ +LABEL org.opencontainers.image.title="Hindsight SRE" \ + io.modelcontextprotocol.server.name="io.github.DrDroidLab/hindsight-sre" USER 10001:10001 WORKDIR /opt/hindsight ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 HINDSIGHT_DATA_DIR=/data DATA_DIR=/data diff --git a/README.md b/README.md index ff6c54c..5412b6a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ + +

Hindsight logo

@@ -41,12 +43,12 @@ Everything is typed Markdown in a git remote you control, every commit carries t ## Quickstart -Requires Docker with Compose v2 and git. The demo runs offline with a seeded sample repo, no model provider and no git credentials. +Requires Docker with Compose v2. The demo pulls the published image (`ghcr.io/drdroidlab/hindsight`) and runs offline with a seeded sample repo, no model provider and no git credentials. ```sh -git clone https://github.com/DrDroidLab/hindsight.git -cd hindsight -docker compose -f compose.yaml -f compose.demo.yaml up --build -d +mkdir hindsight && cd hindsight +curl -fsSLO https://raw.githubusercontent.com/DrDroidLab/hindsight/main/compose.yaml -O https://raw.githubusercontent.com/DrDroidLab/hindsight/main/compose.demo.yaml +docker compose -f compose.yaml -f compose.demo.yaml up -d docker compose exec hindsight hindsight admin bootstrap ``` @@ -54,9 +56,10 @@ Open , paste the enrollment token, save the API key ### Connect your agent +Each engineer installs the `hindsight-sre` CLI from PyPI (`pipx install hindsight-sre` works too): + ```sh -python3.12 -m venv .venv && . .venv/bin/activate -pip install . +uv tool install hindsight-sre hindsight login --server http://localhost:8080 --scope shared hindsight install claude --server http://localhost:8080 # or cursor, codex, gemini ``` @@ -92,6 +95,8 @@ Early-stage, v0.1. The automated suite (Python, frontend, and an offline Docker ## Development +Working from a clone, `docker compose up --build` builds the image from your checkout instead of pulling it. + ```sh pip install -e '.[dev]' npm ci --prefix web && npm run build --prefix web diff --git a/compose.yaml b/compose.yaml index 592b504..1b7a88b 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,6 +1,8 @@ +# Pulls the published image. From a clone, `docker compose up --build` builds this checkout instead; +# set HINDSIGHT_IMAGE to pin a release, e.g. ghcr.io/drdroidlab/hindsight:0.1.0. services: hindsight: - image: hindsight-sre:local + image: ${HINDSIGHT_IMAGE:-ghcr.io/drdroidlab/hindsight:latest} build: . restart: unless-stopped init: true diff --git a/docs/getting-started.md b/docs/getting-started.md index 6b30739..0d8dcc4 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1,7 +1,7 @@ --- seo_title: "Quickstart: install Hindsight with Docker and connect your coding agent" description: >- - Install Hindsight with Docker Compose, run the offline demo, connect Claude + Install Hindsight with Docker Compose and the hindsight-sre CLI, run the offline demo, connect Claude Code, Cursor, Codex or Gemini CLI over MCP, and deploy against your own git remote. --- @@ -12,26 +12,28 @@ This page gets you from nothing to an agent recalling reviewed knowledge. The [d ## Prerequisites -- Docker with Compose v2 -- git +- Docker with Compose v2 (team lead, to run the server) - A browser - A free loopback port. The default is 8080; set `HINDSIGHT_PORT` to use another. -- Python 3.12+ for the client CLI that connects agents +- [uv](https://docs.astral.sh/uv/) or [pipx](https://pipx.pypa.io/) for the client CLI that connects agents (each engineer). It needs Python 3.12+, which uv installs for you if it is missing. -The first image build needs network access for dependencies. The running demo needs no remote git, no model provider and no production access. +Pulling the image needs network access. The running demo needs no remote git, no model provider and no production access. ## 1. Run the demo server ```sh -git clone https://github.com/DrDroidLab/hindsight.git -cd hindsight -docker compose -f compose.yaml -f compose.demo.yaml up --build -d +mkdir hindsight && cd hindsight +curl -fsSLO https://raw.githubusercontent.com/DrDroidLab/hindsight/main/compose.yaml -O https://raw.githubusercontent.com/DrDroidLab/hindsight/main/compose.demo.yaml +docker compose -f compose.yaml -f compose.demo.yaml up -d docker compose exec hindsight hindsight admin bootstrap ``` -If port 8080 is taken, prefix the `up` command with `HINDSIGHT_PORT=8091` (or any free port) and use that port below. +Compose pulls `ghcr.io/drdroidlab/hindsight:latest`. To pin a release, set `HINDSIGHT_IMAGE=ghcr.io/drdroidlab/hindsight:`. If port 8080 is taken, prefix the `up` command with `HINDSIGHT_PORT=8091` (or any free port) and use that port below. -The demo creates a local bare git remote at `/data/demo-remote.git` from `examples/sample-knowledge/`. It holds seven fictional documents: the `payments-api` service, a CrashLoopBackOff runbook, an approved clue, an unreviewed clue, a skill, a resolved incident and an outcome. Running it again does not overwrite an existing remote. +!!! tip "Running from a clone" + In a checkout of the repository, `docker compose -f compose.yaml -f compose.demo.yaml up --build -d` builds the image from your working tree instead of pulling it. + +The demo creates a local bare git remote at `/data/demo-remote.git` from the sample knowledge bundled in the image (`examples/sample-knowledge/` in the repository). It holds seven fictional documents: the `payments-api` service, a CrashLoopBackOff runbook, an approved clue, an unreviewed clue, a skill, a resolved incident and an outcome. Running it again does not overwrite an existing remote. ## 2. Enroll and review @@ -48,12 +50,10 @@ Approval and promotion are two separate git commits, both authored by you. ## 3. Connect an agent -Install the client CLI in a virtual environment, log in, and install the integration for your agent: +Each engineer installs the `hindsight-sre` CLI from PyPI, logs in, and installs the integration for their agent: ```sh -python3.12 -m venv .venv -. .venv/bin/activate -pip install . +uv tool install hindsight-sre # or: pipx install hindsight-sre hindsight login --server http://localhost:8080 --scope shared hindsight install claude --server http://localhost:8080 --dry-run hindsight install claude --server http://localhost:8080 @@ -77,12 +77,16 @@ hindsight review --status proposed ## 4. Deploy with your own knowledge remote ```sh -cp .env.example .env +mkdir hindsight-server && cd hindsight-server +curl -fsSLO https://raw.githubusercontent.com/DrDroidLab/hindsight/main/compose.yaml +curl -fsSL https://raw.githubusercontent.com/DrDroidLab/hindsight/main/.env.example -o .env # Set GIT_REMOTE to a dedicated, sanitized repository and configure git credentials privately. -docker compose up --build -d +docker compose up -d docker compose exec hindsight hindsight admin bootstrap ``` +Use a different directory from the demo: Compose names the data volume after the directory, so this keeps demo data out of your deployment. Pin `HINDSIGHT_IMAGE` in `.env` to a released version rather than `latest`. + `GIT_REMOTE` is the only required setting. Everything else is optional and unlocks one feature each: | Setting | Unlocks | Without it | diff --git a/docs/index.md b/docs/index.md index c9a770b..d00d287 100644 --- a/docs/index.md +++ b/docs/index.md @@ -78,13 +78,13 @@ Capture, review and full-text recall work with no LLM key. Optional extraction a ## Try it locally ```sh -git clone https://github.com/DrDroidLab/hindsight.git -cd hindsight -docker compose -f compose.yaml -f compose.demo.yaml up --build -d +mkdir hindsight && cd hindsight +curl -fsSLO https://raw.githubusercontent.com/DrDroidLab/hindsight/main/compose.yaml -O https://raw.githubusercontent.com/DrDroidLab/hindsight/main/compose.demo.yaml +docker compose -f compose.yaml -f compose.demo.yaml up -d docker compose exec hindsight hindsight admin bootstrap ``` -Open `http://localhost:8080/setup`, paste the enrollment token, and review the seeded sample clue. The demo needs no git credentials, no model provider and no network once the image is built. See the [quickstart](getting-started.md) for connecting your agent. +Open `http://localhost:8080/setup`, paste the enrollment token, and review the seeded sample clue. The demo needs no git credentials, no model provider and no network once the image is pulled. See the [quickstart](getting-started.md) for connecting your agent. ## What Hindsight is not diff --git a/docs/operations.md b/docs/operations.md index 6ff4e74..4527083 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -81,4 +81,4 @@ There are no built-in hosting-provider PR creation/merge APIs or provider tokens ## Updating -Back up first, stop the old writer, build a new image, and restart with the same persistent volume. Do not run old and new writers against it concurrently. Check release schema notes and test restore; no automatic cross-version migration guarantee is promised. Keep client hooks and provider settings independently versioned and verify `install --check` after client upgrades. +Back up first, stop the old writer, pull the new image (`docker compose pull`, or set `HINDSIGHT_IMAGE` to the new version), and restart with the same persistent volume. Do not run old and new writers against it concurrently. Check release schema notes and test restore; no automatic cross-version migration guarantee is promised. Keep client hooks and provider settings independently versioned and verify `install --check` after client upgrades. diff --git a/pyproject.toml b/pyproject.toml index 75ea90e..c6dcfb6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,8 @@ Issues = "https://github.com/DrDroidLab/hindsight/issues" [project.scripts] hindsight = "hindsight.cli:main" +# Alias matching the package name, so `uvx hindsight-sre mcp-proxy` works (MCP Registry entry). +hindsight-sre = "hindsight.cli:main" [tool.hatch.build.targets.wheel] packages = ["src/hindsight"] diff --git a/server.json b/server.json new file mode 100644 index 0000000..8fa6f8a --- /dev/null +++ b/server.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "io.github.DrDroidLab/hindsight-sre", + "title": "Hindsight SRE", + "description": "Self-hosted, git-backed runbooks and reviewed incident learnings for coding agents.", + "version": "0.1.0", + "websiteUrl": "https://drdroidlab.github.io/hindsight/", + "repository": { + "url": "https://github.com/DrDroidLab/hindsight", + "source": "github" + }, + "packages": [ + { + "registryType": "pypi", + "registryBaseUrl": "https://pypi.org", + "identifier": "hindsight-sre", + "version": "0.1.0", + "runtimeHint": "uvx", + "transport": { + "type": "stdio" + }, + "packageArguments": [ + { + "type": "positional", + "value": "mcp-proxy" + } + ], + "environmentVariables": [ + { + "name": "HINDSIGHT_SERVER", + "description": "URL of your team's Hindsight server. Defaults to the server saved by `hindsight login`.", + "format": "string", + "placeholder": "https://hindsight.example.com" + }, + { + "name": "HINDSIGHT_API_KEY", + "description": "Personal API key. Defaults to the private credential file written by `hindsight login`, which is preferred.", + "format": "string", + "isSecret": true + }, + { + "name": "HINDSIGHT_SCOPE", + "description": "Knowledge scope to read and write.", + "format": "string", + "default": "shared" + } + ] + } + ] +}