Compare commits
5
Commits
main
...
bb9b68e361
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb9b68e361 | ||
|
|
00037993af | ||
|
|
95e2fcfd57 | ||
|
|
12ba97c8f1 | ||
|
|
552a76ba99 |
No files matched your search
@@ -0,0 +1,271 @@
|
|||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
OWNER: vhaudiquet
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Fast checks + release build of the Rust workspace.
|
||||||
|
checks:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
# Installs the toolchain pinned in rust-toolchain.toml.
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
|
||||||
|
# reqwest's default TLS links openssl; rusqlite's bundled SQLite
|
||||||
|
# needs a C compiler (present on the runner image, kept explicit
|
||||||
|
# next to the rest).
|
||||||
|
- name: Install native build dependencies
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
|
||||||
|
|
||||||
|
- name: Format
|
||||||
|
run: cargo fmt --all -- --check
|
||||||
|
|
||||||
|
- name: Clippy (warnings are errors)
|
||||||
|
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
|
- name: Build (release)
|
||||||
|
run: cargo build --release --workspace
|
||||||
|
|
||||||
|
- name: Upload the claw binary
|
||||||
|
uses: https://gitea.com/actions/gitea-upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: rhema-claw-linux-amd64
|
||||||
|
path: target/release/rhema-claw
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 14
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
|
||||||
|
- name: Install native build dependencies
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
|
||||||
|
|
||||||
|
# The offline-suite rule is load-bearing here: no test talks to the
|
||||||
|
# network, so the runner needs nothing beyond the toolchain.
|
||||||
|
- name: Test
|
||||||
|
run: cargo test --workspace --all-features
|
||||||
|
|
||||||
|
# The deploy chart: lint, render every supported shape, validate the
|
||||||
|
# result against the Kubernetes schemas — and prove the single-node
|
||||||
|
# invariant is enforced rather than hoped for.
|
||||||
|
chart:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install helm and kubeconform
|
||||||
|
run: |
|
||||||
|
curl -fsSL https://get.helm.sh/helm-v3.16.4-linux-amd64.tar.gz \
|
||||||
|
| tar -xz -C /tmp
|
||||||
|
sudo install /tmp/linux-amd64/helm /usr/local/bin/helm
|
||||||
|
curl -fsSL https://github.com/yannh/kubeconform/releases/download/v0.6.7/kubeconform-linux-amd64.tar.gz \
|
||||||
|
| tar -xz kubeconform
|
||||||
|
sudo install kubeconform /usr/local/bin/kubeconform
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: helm lint deploy/helm/rhema-claw --strict --set token=ci-render-token
|
||||||
|
|
||||||
|
- name: Render and validate
|
||||||
|
run: |
|
||||||
|
check() {
|
||||||
|
helm template test "$@" --set token=ci-render-token | kubeconform -strict -summary
|
||||||
|
}
|
||||||
|
# The shapes: defaults (persistent), the disposable one
|
||||||
|
# (emptyDir), the recommended secret path, and a seeded watch.
|
||||||
|
# The token rides every render: the daemon binds all interfaces
|
||||||
|
# in-cluster and refuses a non-loopback surface without one.
|
||||||
|
check deploy/helm/rhema-claw
|
||||||
|
check deploy/helm/rhema-claw --set persistence.enabled=false
|
||||||
|
check deploy/helm/rhema-claw --set secret.existingSecret=rhema-claw-secrets
|
||||||
|
check deploy/helm/rhema-claw --set config.watches[0].forge=github --set config.watches[0].repo=acme/widgets
|
||||||
|
|
||||||
|
# The state layout is pinned to the mounted volume regardless of
|
||||||
|
# values, and the listener must not be loopback inside a pod.
|
||||||
|
render=$(helm template test deploy/helm/rhema-claw --set token=ci-render-token)
|
||||||
|
grep -q "db: /data/claw.db" <<<"$render"
|
||||||
|
grep -q "workspace_root: /data/workspaces" <<<"$render"
|
||||||
|
grep -q "listen: 0.0.0.0:7799" <<<"$render"
|
||||||
|
|
||||||
|
# The token is a render-time failure: an unguarded daemon with a
|
||||||
|
# wide bind refuses to start, and the chart says so earlier.
|
||||||
|
if helm template test deploy/helm/rhema-claw \
|
||||||
|
> /dev/null 2>&1; then
|
||||||
|
echo "an empty token must not render"; exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The ingress shapes: host+class, host+TLS, and the two
|
||||||
|
# refusals — an enabled ingress without a host, and TLS without
|
||||||
|
# a certificate secret. Bearer tokens cross this ingress; neither
|
||||||
|
# may render silently.
|
||||||
|
check deploy/helm/rhema-claw --set ingress.enabled=true \
|
||||||
|
--set ingress.host=claw.example.com --set ingress.className=nginx
|
||||||
|
check deploy/helm/rhema-claw --set ingress.enabled=true \
|
||||||
|
--set ingress.host=claw.example.com --set ingress.tls.enabled=true \
|
||||||
|
--set ingress.tls.secretName=claw-tls
|
||||||
|
if helm template test deploy/helm/rhema-claw \
|
||||||
|
--set token=ci-render-token --set ingress.enabled=true > /dev/null 2>&1; then
|
||||||
|
echo "ingress without a host must not render"; exit 1
|
||||||
|
fi
|
||||||
|
if helm template test deploy/helm/rhema-claw \
|
||||||
|
--set token=ci-render-token --set ingress.enabled=true --set ingress.host=claw.example.com \
|
||||||
|
--set ingress.tls.enabled=true > /dev/null 2>&1; then
|
||||||
|
echo "tls without a secret must not render"; exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The invariant is a render-time failure: the claw is single-node
|
||||||
|
# by design (one SQLite store, one dispatcher), and the chart is
|
||||||
|
# where that is enforced.
|
||||||
|
if helm template test deploy/helm/rhema-claw \
|
||||||
|
--set replicaCount=2 --set token=ci-render-token > /dev/null 2>&1; then
|
||||||
|
echo "replicaCount 2 must not render"; exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The daemon's container image: build it, then prove the binary boots
|
||||||
|
# and serves /healthz inside it — config parsing, the state dirs, the
|
||||||
|
# keyless backend path, the dynamic linking. The image carries bash but
|
||||||
|
# no curl/wget, so the probe rides bash's /dev/tcp.
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build image
|
||||||
|
run: docker build -f deploy/docker/claw.Dockerfile -t rhema-claw:ci .
|
||||||
|
|
||||||
|
- name: Smoke test
|
||||||
|
run: |
|
||||||
|
docker rm -f rhema-claw || true
|
||||||
|
trap 'docker rm -f rhema-claw || true' EXIT
|
||||||
|
# The llama-cpp backend boots keyless: no credentials are needed
|
||||||
|
# to prove the daemon serves. All state goes to /tmp so the
|
||||||
|
# smoke never depends on volume ownership.
|
||||||
|
docker run -d --name rhema-claw \
|
||||||
|
-e XDG_STATE_HOME=/tmp/state \
|
||||||
|
--entrypoint /bin/bash rhema-claw:ci -c '
|
||||||
|
mkdir -p /tmp/ws /tmp/state
|
||||||
|
printf "provider: llama-cpp\ndb: /tmp/claw.db\nworkspace_root: /tmp/ws\nlisten: 127.0.0.1:7799\n" > /tmp/claw.yaml
|
||||||
|
exec /usr/local/bin/rhema-claw --config /tmp/claw.yaml'
|
||||||
|
ok=0
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
# The request needs the full header terminator, and the read
|
||||||
|
# needs its own timeout: an accepted-but-unanswered probe
|
||||||
|
# would hang the exec, not fail it.
|
||||||
|
if docker exec rhema-claw bash -c \
|
||||||
|
'exec 3<>/dev/tcp/127.0.0.1/7799 && printf "GET /healthz HTTP/1.0\r\n\r\n" >&3 && timeout 5 grep -q ok <&3'; then
|
||||||
|
ok=1; break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if [ "$ok" != 1 ]; then
|
||||||
|
docker logs rhema-claw
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
docker rm -f rhema-claw
|
||||||
|
|
||||||
|
# The web UI: install and produce the static bundle — the artifact an
|
||||||
|
# ingress serves next to /v1.
|
||||||
|
web:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Node
|
||||||
|
run: |
|
||||||
|
curl -fsSL https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-x64.tar.xz \
|
||||||
|
| sudo tar -xJ -C /usr/local --strip-components=1
|
||||||
|
node --version
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
working-directory: web/claw
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
working-directory: web/claw
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
# The edge channel: a main push that passed everything above ships
|
||||||
|
# the two deployable images as a rolling latest + sha pair. Release
|
||||||
|
# publishing (exact versions, the stable pin) lives in release.yaml.
|
||||||
|
# The claw image is rebuilt here for the registry even though the
|
||||||
|
# docker job above just built and smoked it: no artifact hand-off is
|
||||||
|
# worth the plumbing for a build this cheap.
|
||||||
|
publish-edge-images:
|
||||||
|
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
||||||
|
needs: [checks, test, chart, docker, web]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- dockerfile: deploy/docker/claw.Dockerfile
|
||||||
|
image: rhema-claw
|
||||||
|
- dockerfile: deploy/docker/ui.Dockerfile
|
||||||
|
image: rhema-claw-ui
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log in to container registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: https://git.vhaudiquet.fr
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.PACKAGES_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ${{ matrix.dockerfile }}
|
||||||
|
push: true
|
||||||
|
# The edge pair: rolling latest, and the sha pin the chart's
|
||||||
|
# appVersion resolves to.
|
||||||
|
tags: |
|
||||||
|
git.vhaudiquet.fr/${{ env.OWNER }}/${{ matrix.image }}:latest
|
||||||
|
git.vhaudiquet.fr/${{ env.OWNER }}/${{ matrix.image }}:${{ gitea.sha }}
|
||||||
|
|
||||||
|
# The edge chart lands only once its images are in the registry: the
|
||||||
|
# chart's default image tag is appVersion, and appVersion here is
|
||||||
|
# this exact commit. The version rides the base version + a timestamp
|
||||||
|
# (ordered; SemVer pre-release rules allow no dots).
|
||||||
|
publish-edge-chart:
|
||||||
|
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
||||||
|
needs: publish-edge-images
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Helm
|
||||||
|
uses: azure/setup-helm@v5
|
||||||
|
|
||||||
|
- name: Update Chart version and appVersion
|
||||||
|
run: |
|
||||||
|
BASE_VERSION=$(grep '^version:' deploy/helm/rhema-claw/Chart.yaml | awk '{print $2}')
|
||||||
|
TIMESTAMP=$(date -u +"%Y%m%d-%H%M%S")
|
||||||
|
sed -i "s/^version:.*/version: \"${BASE_VERSION}-${TIMESTAMP}\"/" deploy/helm/rhema-claw/Chart.yaml
|
||||||
|
sed -i "s/^appVersion:.*/appVersion: \"${{ gitea.sha }}\"/" deploy/helm/rhema-claw/Chart.yaml
|
||||||
|
|
||||||
|
- name: Lint Helm chart
|
||||||
|
run: helm lint deploy/helm/rhema-claw
|
||||||
|
|
||||||
|
- name: Package Helm chart
|
||||||
|
run: helm package deploy/helm/rhema-claw
|
||||||
|
|
||||||
|
- name: Push Helm chart to Gitea registry
|
||||||
|
run: |
|
||||||
|
TOKEN=$(echo -n "${{ secrets.PACKAGES_TOKEN }}" | tr -d '\n')
|
||||||
|
curl --fail --user "${{ gitea.actor }}:${TOKEN}" \
|
||||||
|
-X POST \
|
||||||
|
--upload-file rhema-claw-*.tgz \
|
||||||
|
"https://git.vhaudiquet.fr/api/packages/${{ env.OWNER }}/helm/api/charts"
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
# The release channel: a v* tag ships the exact-version images (plus
|
||||||
|
# the sha pin the chart's appVersion resolves to) and the exact-version
|
||||||
|
# chart. Edge publishing on every main push lives in ci.yml. Release
|
||||||
|
# candidates (a v* tag with a prerelease suffix, v0.2.0-rc1) publish
|
||||||
|
# nothing. The daemon crate itself is `publish = false`, so no
|
||||||
|
# crates.io leg runs here: the crates the claw pulls live in the rhema
|
||||||
|
# repository's release channel.
|
||||||
|
name: release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: git.vhaudiquet.fr
|
||||||
|
OWNER: vhaudiquet
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
verify-tag:
|
||||||
|
# cargo build ships whatever the manifest declares, regardless of
|
||||||
|
# the tag: a mismatch must fail loudly instead of shipping the
|
||||||
|
# wrong version under the release tag.
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check the tag matches the workspace version
|
||||||
|
run: |
|
||||||
|
crate_version="$(grep -m1 '^version =' Cargo.toml | awk -F'"' '{print $2}')"
|
||||||
|
tag_version="${GITHUB_REF_NAME#v}"
|
||||||
|
if [ "$crate_version" != "$tag_version" ]; then
|
||||||
|
echo "tag $GITHUB_REF_NAME does not match workspace version $crate_version" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
build-and-push-release-images:
|
||||||
|
# The same two deployable images as the edge channel, tagged for the
|
||||||
|
# release: the exact version, the rolling stable pin, and the sha
|
||||||
|
# the chart's appVersion resolves to.
|
||||||
|
if: ${{ !contains(gitea.ref_name, '-') }}
|
||||||
|
needs: verify-tag
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- dockerfile: deploy/docker/claw.Dockerfile
|
||||||
|
image: rhema-claw
|
||||||
|
- dockerfile: deploy/docker/ui.Dockerfile
|
||||||
|
image: rhema-claw-ui
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log in to container registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: https://git.vhaudiquet.fr
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.PACKAGES_TOKEN }}
|
||||||
|
|
||||||
|
- name: Compute the release version (the tag strips the v)
|
||||||
|
id: ver
|
||||||
|
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Build and push image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ${{ matrix.dockerfile }}
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
git.vhaudiquet.fr/${{ env.OWNER }}/${{ matrix.image }}:${{ steps.ver.outputs.version }}
|
||||||
|
git.vhaudiquet.fr/${{ env.OWNER }}/${{ matrix.image }}:stable
|
||||||
|
git.vhaudiquet.fr/${{ env.OWNER }}/${{ matrix.image }}:${{ gitea.sha }}
|
||||||
|
|
||||||
|
release-chart:
|
||||||
|
# The exact tag version ships as-is so deployments can pin
|
||||||
|
# `--version 0.1.0`; appVersion pins the exact commit the image was
|
||||||
|
# built from (the chart's default image tag is appVersion, so the
|
||||||
|
# sha image above must exist before this runs).
|
||||||
|
if: ${{ !contains(gitea.ref_name, '-') }}
|
||||||
|
needs: build-and-push-release-images
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Helm
|
||||||
|
uses: azure/setup-helm@v5
|
||||||
|
|
||||||
|
- name: Update Chart version and appVersion
|
||||||
|
run: |
|
||||||
|
sed -i "s/^version:.*/version: \"${GITHUB_REF_NAME#v}\"/" deploy/helm/rhema-claw/Chart.yaml
|
||||||
|
sed -i "s/^appVersion:.*/appVersion: \"${{ gitea.sha }}\"/" deploy/helm/rhema-claw/Chart.yaml
|
||||||
|
|
||||||
|
- name: Lint Helm chart
|
||||||
|
run: helm lint deploy/helm/rhema-claw
|
||||||
|
|
||||||
|
- name: Package Helm chart
|
||||||
|
run: helm package deploy/helm/rhema-claw
|
||||||
|
|
||||||
|
- name: Push Helm chart to Gitea registry
|
||||||
|
run: |
|
||||||
|
TOKEN=$(echo -n "${{ secrets.PACKAGES_TOKEN }}" | tr -d '\n')
|
||||||
|
curl --fail --user "${{ gitea.actor }}:${TOKEN}" \
|
||||||
|
-X POST \
|
||||||
|
--upload-file rhema-claw-*.tgz \
|
||||||
|
"https://git.vhaudiquet.fr/api/packages/${{ env.OWNER }}/helm/api/charts"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/target/
|
||||||
Generated
+3432
File diff suppressed because it is too large.
Load diff
+34
@@ -0,0 +1,34 @@
|
|||||||
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
|
members = ["crates/*", "integrations/*"]
|
||||||
|
|
||||||
|
[workspace.package]
|
||||||
|
version = "0.2.3"
|
||||||
|
edition = "2024"
|
||||||
|
rust-version = "1.89"
|
||||||
|
license = "MIT"
|
||||||
|
repository = "https://git.vhaudiquet.fr/vhaudiquet/rhema-claw"
|
||||||
|
authors = ["Valentin Haudiquet"]
|
||||||
|
|
||||||
|
[workspace.lints.rust]
|
||||||
|
missing_docs = "deny"
|
||||||
|
|
||||||
|
[workspace.dependencies]
|
||||||
|
# Serialization: session and message types must round-trip for checkpointing
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
# Typed library errors
|
||||||
|
thiserror = "2"
|
||||||
|
# Async traits must stay object-safe (dyn ModelProvider, dyn ToolResolver)
|
||||||
|
async-trait = "0.1"
|
||||||
|
# Config file format (flat scalar fields; see the rhema-config crate)
|
||||||
|
serde_yaml = "0.9"
|
||||||
|
# Test runtime
|
||||||
|
tokio = { version = "1", features = ["macros", "rt"] }
|
||||||
|
# The claw's HTTP surface: native routes plus SSE, and the OpenAI shim
|
||||||
|
axum = { version = "0.8", features = ["json"] }
|
||||||
|
tokio-stream = { version = "0.1", features = ["sync"] }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
strip = "symbols"
|
||||||
|
codegen-units = 1
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<div align="center">
|
||||||
|
<b>ῥῆμα, "the spoken word": words that do things.</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1 align="center">Rhema Claw</h1>
|
||||||
|
|
||||||
|
Rhema Claw is the resident tier of the Rhema agent framework: a
|
||||||
|
claw-shaped daemon that watches forges (GitHub, Gitea, GitLab) and
|
||||||
|
calendar feeds, dispatches work to its agents, and serves a chat
|
||||||
|
surface over HTTP — native routes plus an OpenAI-compatible shim,
|
||||||
|
with a web UI and an Android client talking to it.
|
||||||
|
|
||||||
|
The framework it embeds (the crates under `crates/` it pulls from
|
||||||
|
crates.io: `rhema-autonomous-agent`, `rhema-coding-agent`,
|
||||||
|
`rhema-rsd`, and friends) lives in the
|
||||||
|
[rhema repository](https://git.vhaudiquet.fr/vhaudiquet/rhema).
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
- [`crates/rhema-claw/`](./crates/rhema-claw) — the daemon: forge
|
||||||
|
watches, session dispatch, the chat surface, MCP wiring, and the
|
||||||
|
vision helper. See its
|
||||||
|
[README](./crates/rhema-claw/README.md).
|
||||||
|
- [`integrations/`](./integrations) — the feed adapters that
|
||||||
|
normalize forge and calendar activity into `rhema-rsd` dispatch.
|
||||||
|
- [`tools/`](./tools) — what runs on the *user's machine*: the
|
||||||
|
`rhema-claw-tools-contract` (the scoped agent-token allowlist the
|
||||||
|
auth middleware enforces), the shared thin-client code, and
|
||||||
|
`rhema-claw-tools-notify`.
|
||||||
|
- [`web/claw/`](./web/claw) — the Nuxt web UI.
|
||||||
|
- [`android/`](./android) — the Compose Android client.
|
||||||
|
- [`deploy/`](./deploy) — the Docker images and the Helm chart.
|
||||||
@@ -27,28 +27,28 @@ mock = ["rhema-core/mock"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
# The shared toolkit: the resident agent assembles its agent from the
|
# The shared toolkit: the resident agent assembles its agent from the
|
||||||
# shell, the approval seam, paste expansion, and revive-on-resume
|
# shell, the approval seam, paste expansion, and revive-on-resume
|
||||||
rhema-agent-tools = { path = "../rhema-agent-tools" }
|
rhema-agent-tools = "0.2.3"
|
||||||
rhema-autonomous-agent = { path = "../rhema-autonomous-agent" }
|
rhema-autonomous-agent = "0.2.3"
|
||||||
rhema-coding-agent = { path = "../rhema-coding-agent" }
|
rhema-coding-agent = "0.2.3"
|
||||||
rhema-config = { path = "../rhema-config" }
|
rhema-config = "0.2.3"
|
||||||
rhema-core = { path = "../rhema-core" }
|
rhema-core = "0.2.3"
|
||||||
# The bounded request view over the claw sessions, on by default here
|
# The bounded request view over the claw sessions, on by default here
|
||||||
rhema-transcript = { path = "../rhema-transcript" }
|
rhema-transcript = "0.2.3"
|
||||||
rhema-calendar-integration = { path = "../../integrations/rhema-calendar-integration" }
|
rhema-calendar-integration = { path = "../../integrations/rhema-calendar-integration" }
|
||||||
rhema-forge-integration = { path = "../../integrations/rhema-forge-integration" }
|
rhema-forge-integration = { path = "../../integrations/rhema-forge-integration" }
|
||||||
# The accounts layer: identities hold the forge tokens the watches poll
|
# The accounts layer: identities hold the forge tokens the watches poll
|
||||||
# with, and the identity tools manage them over chat
|
# with, and the identity tools manage them over chat
|
||||||
rhema-identity = { path = "../rhema-identity" }
|
rhema-identity = "0.2.3"
|
||||||
rhema-rsd = { path = "../rhema-rsd" }
|
rhema-rsd = "0.2.3"
|
||||||
# The tool contract: the agent-token allowlist and version the auth
|
# The tool contract: the agent-token allowlist and version the auth
|
||||||
# middleware enforces (rhema-tools spec). The arrow runs claw ->
|
# middleware enforces (rhema-tools spec). The arrow runs claw ->
|
||||||
# contract only — never the reverse.
|
# contract only — never the reverse.
|
||||||
rhema-claw-tools-contract = { path = "../../tools/contract" }
|
rhema-claw-tools-contract = { path = "../../tools/contract" }
|
||||||
# The resident tier's durable memory: its tools join the resolver chain
|
# The resident tier's durable memory: its tools join the resolver chain
|
||||||
rhema-memory = { path = "../rhema-memory" }
|
rhema-memory = "0.2.3"
|
||||||
# The shared ModelCard the backend registry's listings return
|
# The shared ModelCard the backend registry's listings return
|
||||||
rhema-provider = { path = "../rhema-provider" }
|
rhema-provider = "0.2.3"
|
||||||
rhema-provider-registry = { path = "../rhema-provider-registry", version = "0.2.3" }
|
rhema-provider-registry = "0.2.3"
|
||||||
# Args for the two-flag binary surface
|
# Args for the two-flag binary surface
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
@@ -71,7 +71,7 @@ time = { version = "0.3", default-features = false, features = ["parsing"] }
|
|||||||
# Inbound chat images ride base64; the dispatch decodes them into the
|
# Inbound chat images ride base64; the dispatch decodes them into the
|
||||||
# attachment store
|
# attachment store
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
rhema-mcp = { version = "0.2.3", path = "../rhema-mcp" }
|
rhema-mcp = "0.2.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
@@ -83,7 +83,7 @@ reqwest = { version = "0.12", features = ["json", "stream"] }
|
|||||||
bytes = "1"
|
bytes = "1"
|
||||||
# The scripted provider for turn-level tests; mirrors rhema-code's mock
|
# The scripted provider for turn-level tests; mirrors rhema-code's mock
|
||||||
# feature without a feature of our own — tests are the only consumer
|
# feature without a feature of our own — tests are the only consumer
|
||||||
rhema-core = { path = "../rhema-core", features = ["mock"] }
|
rhema-core = { version = "0.2.3", features = ["mock"] }
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync", "time"] }
|
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync", "time"] }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
|
|||||||
@@ -244,7 +244,21 @@ tool wakes with the account id, never the secret, and a denial or a
|
|||||||
15-minute silence comes back in-band so the turn can say so and move
|
15-minute silence comes back in-band so the turn can say so and move
|
||||||
on. A watch with no token of its own polls — and replies — as the
|
on. A watch with no token of its own polls — and replies — as the
|
||||||
matching saved account: the same forge, and on a self-hosted forge the
|
matching saved account: the same forge, and on a self-hosted forge the
|
||||||
same base URL. Acting with a stored account is `identity_exec`: it runs one shell
|
same base URL.
|
||||||
|
|
||||||
|
A repo watch is a feed, not an invitation. The daemon answers a thread
|
||||||
|
when somebody there addresses it — a comment whose body names the handle
|
||||||
|
its credential speaks as (`@kosmos`), written by anyone but itself — and
|
||||||
|
otherwise drains the news and runs nothing: no snapshot, no turn, no
|
||||||
|
comment on somebody else's conversation. (Its own replies quote the
|
||||||
|
mention they answer, so they never reopen the gate.) Notifications are
|
||||||
|
the other door and are adjudicated before they arrive — assigned, review
|
||||||
|
requested, @-mentioned — so those always run. The handle is the account
|
||||||
|
identity's when the token has one, and the forge's own `/user` answer
|
||||||
|
when it does not; a credential the forge will not name leaves the gate
|
||||||
|
open, with a warning in the log, rather than silently muting a watch.
|
||||||
|
|
||||||
|
Acting with a stored account is `identity_exec`: it runs one shell
|
||||||
command in the session workspace with the secret injected —
|
command in the session workspace with the secret injected —
|
||||||
`ACCOUNT_SECRET` plus the service's own `GITHUB_TOKEN`/`GITEA_TOKEN`/
|
`ACCOUNT_SECRET` plus the service's own `GITHUB_TOKEN`/`GITEA_TOKEN`/
|
||||||
`GITLAB_TOKEN`, and a git credential helper — so `git clone` and API
|
`GITLAB_TOKEN`, and a git credential helper — so `git clone` and API
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ use rhema_forge_integration::{
|
|||||||
};
|
};
|
||||||
use rhema_identity::IdentityStore;
|
use rhema_identity::IdentityStore;
|
||||||
use rhema_rsd::{InboxItem, Outcome, ResourceKey};
|
use rhema_rsd::{InboxItem, Outcome, ResourceKey};
|
||||||
|
use tokio::sync::OnceCell;
|
||||||
|
|
||||||
use crate::backends::BackendRegistry;
|
use crate::backends::BackendRegistry;
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ pub struct ClawHandler {
|
|||||||
/// agent shell: the daemon URL, the scoped agent token, the tools'
|
/// agent shell: the daemon URL, the scoped agent token, the tools'
|
||||||
/// bin dir on PATH. Empty when the config issues no agent token.
|
/// bin dir on PATH. Empty when the config issues no agent token.
|
||||||
tool_env: std::collections::BTreeMap<String, String>,
|
tool_env: std::collections::BTreeMap<String, String>,
|
||||||
clients: Mutex<HashMap<String, Arc<dyn Forge>>>,
|
clients: Mutex<HashMap<String, Arc<WatchClient>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClawHandler {
|
impl ClawHandler {
|
||||||
@@ -120,6 +121,18 @@ impl ClawHandler {
|
|||||||
key: &ResourceKey,
|
key: &ResourceKey,
|
||||||
as_account: Option<&str>,
|
as_account: Option<&str>,
|
||||||
) -> Result<Arc<dyn Forge>, String> {
|
) -> Result<Arc<dyn Forge>, String> {
|
||||||
|
Ok(self.watch_client(key, as_account)?.forge.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [`Self::watch_forge_as`] with the handle the credential speaks as
|
||||||
|
/// kept beside the client: the mention gate needs to recognize its own
|
||||||
|
/// name, and asking the forge is a request worth spending once per
|
||||||
|
/// credential, not once per dispatch.
|
||||||
|
fn watch_client(
|
||||||
|
&self,
|
||||||
|
key: &ResourceKey,
|
||||||
|
as_account: Option<&str>,
|
||||||
|
) -> Result<Arc<WatchClient>, String> {
|
||||||
let watch = watch_key(key)
|
let watch = watch_key(key)
|
||||||
.ok_or_else(|| format!("resource key {key} is not a forge thread key"))?;
|
.ok_or_else(|| format!("resource key {key} is not a forge thread key"))?;
|
||||||
let (forge, repo) = watch
|
let (forge, repo) = watch
|
||||||
@@ -192,7 +205,7 @@ impl ClawHandler {
|
|||||||
kind: ForgeKind,
|
kind: ForgeKind,
|
||||||
host: Option<&str>,
|
host: Option<&str>,
|
||||||
credential: &WatchCredential,
|
credential: &WatchCredential,
|
||||||
) -> Arc<dyn Forge> {
|
) -> Arc<WatchClient> {
|
||||||
// Everything that changes the client: the kind, its host, and the
|
// Everything that changes the client: the kind, its host, and the
|
||||||
// credential — the login included, since one value sent two ways
|
// credential — the login included, since one value sent two ways
|
||||||
// is two credentials.
|
// is two credentials.
|
||||||
@@ -206,7 +219,10 @@ impl ClawHandler {
|
|||||||
let mut clients = self.clients.lock().unwrap_or_else(PoisonError::into_inner);
|
let mut clients = self.clients.lock().unwrap_or_else(PoisonError::into_inner);
|
||||||
clients
|
clients
|
||||||
.entry(cache_key)
|
.entry(cache_key)
|
||||||
.or_insert_with(|| record_client(kind, host, credential))
|
.or_insert_with(|| {
|
||||||
|
let forge = record_client(kind, host, credential);
|
||||||
|
Arc::new(WatchClient::new(forge, credential.login.clone()))
|
||||||
|
})
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +240,22 @@ impl ClawHandler {
|
|||||||
// that account — a thread the account's feed delivered may have no
|
// that account — a thread the account's feed delivered may have no
|
||||||
// repo watch row at all.
|
// repo watch row at all.
|
||||||
let news = self.drain_news(ctx, &key).await?;
|
let news = self.drain_news(ctx, &key).await?;
|
||||||
let forge = self.watch_forge_as(&ctx.key, delivery_account(&news))?;
|
let client = self.watch_client(&ctx.key, delivery_account(&news))?;
|
||||||
|
|
||||||
|
// The mention gate, before anything is fetched or run: the news is
|
||||||
|
// already drained, and this decides whether it asks anything of
|
||||||
|
// the daemon at all.
|
||||||
|
let handle = client.handle().await;
|
||||||
|
if handle.is_none() && news.iter().any(|item| matches!(item, InboxNews::Event(_))) {
|
||||||
|
eprintln!(
|
||||||
|
"[claw] warning: {key}: the forge would not name this credential; \
|
||||||
|
every event on the watch dispatches"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if !addressed(&news, handle.as_deref()) {
|
||||||
|
return Ok(Outcome::Superseded);
|
||||||
|
}
|
||||||
|
let forge = client.forge.clone();
|
||||||
|
|
||||||
let snapshot = forge
|
let snapshot = forge
|
||||||
.snapshot(&repo, thread_kind, number)
|
.snapshot(&repo, thread_kind, number)
|
||||||
@@ -343,6 +374,45 @@ impl ClawHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One cached forge client, with the handle it speaks as.
|
||||||
|
///
|
||||||
|
/// The credential a watch resolves carries a login only when an account
|
||||||
|
/// identity supplied the token; a token pasted into the watch row, or a
|
||||||
|
/// forge environment variable, names nobody. The mention gate still has to
|
||||||
|
/// recognize the daemon's own name — to see an @-mention in a body, and to
|
||||||
|
/// leave its own replies alone — so the forge is asked who it is, once per
|
||||||
|
/// credential, the first time a dispatch needs to know.
|
||||||
|
struct WatchClient {
|
||||||
|
forge: Arc<dyn Forge>,
|
||||||
|
/// The login the credential itself carries.
|
||||||
|
login: Option<String>,
|
||||||
|
/// The forge's own answer, asked at most once.
|
||||||
|
viewer: OnceCell<Option<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WatchClient {
|
||||||
|
fn new(forge: Arc<dyn Forge>, login: Option<String>) -> Self {
|
||||||
|
Self {
|
||||||
|
forge,
|
||||||
|
login,
|
||||||
|
viewer: OnceCell::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The handle this client speaks as: the credential's when it has one,
|
||||||
|
/// else the forge's own answer. `None` when neither can name it — a
|
||||||
|
/// forge that is down, or a backend with no `/user`.
|
||||||
|
async fn handle(&self) -> Option<String> {
|
||||||
|
if let Some(login) = &self.login {
|
||||||
|
return Some(login.clone());
|
||||||
|
}
|
||||||
|
self.viewer
|
||||||
|
.get_or_init(|| async { self.forge.viewer_login().await.ok().flatten() })
|
||||||
|
.await
|
||||||
|
.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Handler for ClawHandler {
|
impl Handler for ClawHandler {
|
||||||
async fn handle(&self, ctx: &mut SessionContext) -> Outcome {
|
async fn handle(&self, ctx: &mut SessionContext) -> Outcome {
|
||||||
@@ -440,6 +510,60 @@ fn delivery_account(news: &[InboxNews]) -> Option<&str> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether `news` asks anything of the daemon — the mention gate.
|
||||||
|
///
|
||||||
|
/// A triaged notification answered this question on the way in: the
|
||||||
|
/// notifications feed handed the row over because it was assigned, a
|
||||||
|
/// review was requested, or someone @-mentioned the account, and
|
||||||
|
/// [`triage`](rhema_forge_integration::triage) let it through. It always
|
||||||
|
/// runs.
|
||||||
|
///
|
||||||
|
/// A plain repo event has been through nothing: a repo watch sees every
|
||||||
|
/// issue, pull request, review and comment on the repository. Running a
|
||||||
|
/// turn for each of them would burn a model call per comment and post an
|
||||||
|
/// unasked-for reply on threads nobody addressed the daemon in — the
|
||||||
|
/// difference between watching a repository and answering it. So a plain
|
||||||
|
/// event runs only when it addresses the daemon: a body that names the
|
||||||
|
/// handle we speak as, written by somebody else.
|
||||||
|
///
|
||||||
|
/// With no handle to look for, nothing is gated: a filter that silently
|
||||||
|
/// turns a watch off is worse than one that occasionally over-answers, and
|
||||||
|
/// the dispatch says so in the log.
|
||||||
|
fn addressed(news: &[InboxNews], handle: Option<&str>) -> bool {
|
||||||
|
if news
|
||||||
|
.iter()
|
||||||
|
.any(|news| matches!(news, InboxNews::Notified { .. }))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let Some(handle) = handle else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
news.iter().any(|news| match news {
|
||||||
|
InboxNews::Notified { .. } => true,
|
||||||
|
InboxNews::Event(event) => mentions(event, handle),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether `event` addresses `handle`: its body names `@handle`, and the
|
||||||
|
/// event is not the daemon's own writing. Our replies quote the mentions
|
||||||
|
/// they answer, so an event written by the handle counts as addressed by
|
||||||
|
/// nobody — otherwise every answer would feed the next turn.
|
||||||
|
fn mentions(event: &ForgeEvent, handle: &str) -> bool {
|
||||||
|
let own = event
|
||||||
|
.actor
|
||||||
|
.as_deref()
|
||||||
|
.is_some_and(|actor| actor.eq_ignore_ascii_case(handle));
|
||||||
|
if own {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let Some(body) = event.body.as_deref() else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let needle = format!("@{}", handle.to_lowercase());
|
||||||
|
body.to_lowercase().contains(&needle)
|
||||||
|
}
|
||||||
|
|
||||||
/// The batch's dominant role, for the prompt's persona framing:
|
/// The batch's dominant role, for the prompt's persona framing:
|
||||||
/// implementing subsumes reviewing — a batch that asks for both is a
|
/// implementing subsumes reviewing — a batch that asks for both is a
|
||||||
/// dispatch where the work is the point. Plain events imply no persona:
|
/// dispatch where the work is the point. Plain events imply no persona:
|
||||||
@@ -712,6 +836,80 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A plain comment that names nobody is the thread's own traffic: the
|
||||||
|
/// gate stays shut, no turn runs, and nothing is posted.
|
||||||
|
#[test]
|
||||||
|
fn a_comment_that_names_nobody_does_not_address_the_daemon() {
|
||||||
|
let news = [InboxNews::Event(event(
|
||||||
|
EventKind::Comment,
|
||||||
|
"dave",
|
||||||
|
Some("any progress on this?"),
|
||||||
|
))];
|
||||||
|
assert!(!addressed(&news, Some("kosmos")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Addressed by name, in any case, anywhere in the body — the point of
|
||||||
|
/// the feature is that the human types a sentence, not a protocol.
|
||||||
|
#[test]
|
||||||
|
fn a_comment_that_names_the_handle_addresses_it() {
|
||||||
|
for body in [
|
||||||
|
"hey @kosmos can you take a look?",
|
||||||
|
"@Kosmos, this one is yours",
|
||||||
|
"I think @kosmos should decide",
|
||||||
|
] {
|
||||||
|
let news = [InboxNews::Event(event(EventKind::Comment, "dave", Some(body)))];
|
||||||
|
assert!(addressed(&news, Some("kosmos")), "body: {body}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Our own replies quote the mention they answer, so they mention the
|
||||||
|
/// handle on every line — and must never feed the next turn.
|
||||||
|
#[test]
|
||||||
|
fn the_daemons_own_comments_never_address_it() {
|
||||||
|
let news = [InboxNews::Event(event(
|
||||||
|
EventKind::Comment,
|
||||||
|
"kosmos",
|
||||||
|
Some("> @kosmos can you take a look?\n\nDone, see the branch."),
|
||||||
|
))];
|
||||||
|
assert!(!addressed(&news, Some("kosmos")));
|
||||||
|
// Case is the forge's, not the body's: the actor check folds it.
|
||||||
|
let news = [InboxNews::Event(event(EventKind::Comment, "Kosmos", Some("@kosmos on it")))];
|
||||||
|
assert!(!addressed(&news, Some("kosmos")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Thread-level events carry no body, so a mention gate can never pass
|
||||||
|
/// them: an opened or closed issue is context, not a request.
|
||||||
|
#[test]
|
||||||
|
fn an_event_with_no_body_is_not_a_request() {
|
||||||
|
let news = [InboxNews::Event(event(EventKind::Closed, "dave", None))];
|
||||||
|
assert!(!addressed(&news, Some("kosmos")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A triaged notification was adjudicated on the way in — assigned, a
|
||||||
|
/// review requested, or a mention — so it runs regardless of bodies.
|
||||||
|
#[test]
|
||||||
|
fn a_triaged_notification_always_addresses_the_daemon() {
|
||||||
|
let notified = decode_news(&triaged_item(
|
||||||
|
Role::Implementer,
|
||||||
|
NotificationReason::Assigned,
|
||||||
|
))
|
||||||
|
.expect("the triaged payload decodes");
|
||||||
|
assert!(addressed(&[notified], Some("kosmos")));
|
||||||
|
assert!(addressed(&[notified], None), "a notification needs no handle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// With no handle to look for, the gate stays open: silently turning a
|
||||||
|
/// watch off is worse than over-answering, and the dispatch logs it.
|
||||||
|
#[test]
|
||||||
|
fn an_unnamed_credential_gates_nothing() {
|
||||||
|
let news = [InboxNews::Event(event(
|
||||||
|
EventKind::Comment,
|
||||||
|
"dave",
|
||||||
|
Some("any progress?"),
|
||||||
|
))];
|
||||||
|
assert!(addressed(&news, None));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn thread_level_events_carry_no_body_and_the_prompt_says_so() {
|
fn thread_level_events_carry_no_body_and_the_prompt_says_so() {
|
||||||
let prompt = build_prompt(
|
let prompt = build_prompt(
|
||||||
|
|||||||
@@ -0,0 +1,215 @@
|
|||||||
|
//! The mention gate, end to end: a comment that names the daemon runs a
|
||||||
|
//! turn and posts a reply; a comment that names nobody is drained and
|
||||||
|
//! ignored — no snapshot, no model call, no comment. Zero network.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use rhema_claw::{ClawConfig, run_once};
|
||||||
|
use rhema_core::{Message, MockProvider, ModelOutput, Role, StopReason, Usage};
|
||||||
|
use rhema_rsd::Outcome;
|
||||||
|
use serde_json::{Value, json};
|
||||||
|
use wiremock::matchers::{body_partial_json, method, path};
|
||||||
|
use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||||
|
|
||||||
|
/// The one issue the tests watch, updated inside the seeded cursor's
|
||||||
|
/// window so the pass sees it as news alongside the comment.
|
||||||
|
fn issue_row() -> Value {
|
||||||
|
json!({
|
||||||
|
"id": 1007,
|
||||||
|
"number": 7,
|
||||||
|
"state": "open",
|
||||||
|
"title": "crash on save",
|
||||||
|
"user": { "login": "alice" },
|
||||||
|
"labels": [],
|
||||||
|
"body": "steps to reproduce…",
|
||||||
|
"created_at": "2026-10-01T09:00:00Z",
|
||||||
|
"updated_at": "2026-10-02T10:00:00Z",
|
||||||
|
"closed_at": null,
|
||||||
|
"html_url": "https://github.com/acme/widgets/issues/7"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A comment on thread 7: the author and the body are the test's subject.
|
||||||
|
fn comment_row(author: &str, body: &str) -> Value {
|
||||||
|
json!({
|
||||||
|
"id": 8001,
|
||||||
|
"user": { "login": author },
|
||||||
|
"body": body,
|
||||||
|
"created_at": "2026-10-03T09:00:00Z",
|
||||||
|
"updated_at": "2026-10-03T09:00:00Z",
|
||||||
|
"issue_url": "https://api.github.com/repos/acme/widgets/issues/7",
|
||||||
|
"html_url": "https://github.com/acme/widgets/issues/7#issuecomment-8001"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reply(text: &str) -> ModelOutput {
|
||||||
|
ModelOutput {
|
||||||
|
message: Message::text(Role::Assistant, text),
|
||||||
|
stop_reason: StopReason::EndTurn,
|
||||||
|
usage: Usage::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn config(dir: &tempfile::TempDir) -> ClawConfig {
|
||||||
|
ClawConfig {
|
||||||
|
db: Some(dir.path().join("dispatch.db")),
|
||||||
|
workspace_root: Some(dir.path().join("workspaces")),
|
||||||
|
memory_root: None,
|
||||||
|
bootstrap_root: None,
|
||||||
|
poll_interval_secs: 60,
|
||||||
|
max_turn_steps: rhema_claw::config::DEFAULT_MAX_TURN_STEPS,
|
||||||
|
provider: Some("google".to_owned()),
|
||||||
|
model: Some("test-model".to_owned()),
|
||||||
|
listen: None,
|
||||||
|
token: None,
|
||||||
|
agent_token: None,
|
||||||
|
tools_bin: None,
|
||||||
|
transcript: None,
|
||||||
|
ingest_token: None,
|
||||||
|
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An established watch: the cursor is what makes the pass read the feed
|
||||||
|
/// as news rather than seeding a start line at *now*.
|
||||||
|
fn seed_watch(dir: &tempfile::TempDir, host: &str) {
|
||||||
|
let store = rhema_claw::ClawStore::open(dir.path().join("dispatch.db"))
|
||||||
|
.expect("the watch table opens");
|
||||||
|
store
|
||||||
|
.add("github", "acme/widgets", Some(host), "tok")
|
||||||
|
.expect("the seed row lands");
|
||||||
|
store
|
||||||
|
.set_cursor(rhema_claw::SCOPE_REPO, "github", "acme/widgets", "2026-10-01T00:00:00Z")
|
||||||
|
.expect("the cursor seeds");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The feeds every pass reads, plus the forge's answer to "who am I" —
|
||||||
|
/// the watch's token is a bare value that names nobody, so the mention
|
||||||
|
/// gate asks the forge rather than guess.
|
||||||
|
async fn mount_repo(server: &MockServer, author: &str, comment: &str) {
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/repos/acme/widgets/issues"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(json!([issue_row()])))
|
||||||
|
.mount(server)
|
||||||
|
.await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/repos/acme/widgets/issues/comments"))
|
||||||
|
.respond_with(
|
||||||
|
ResponseTemplate::new(200).set_body_json(json!([comment_row(author, comment)])),
|
||||||
|
)
|
||||||
|
.mount(server)
|
||||||
|
.await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/user"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "login": "kosmos" })))
|
||||||
|
.mount(server)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The orientation call the turn makes once the gate has opened.
|
||||||
|
async fn mount_snapshot(server: &MockServer) {
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/repos/acme/widgets/issues/7"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(issue_row()))
|
||||||
|
.mount(server)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The headline case: "hey @kosmos, can you take a look at this?" — one
|
||||||
|
/// comment addressed by name, one turn, one reply.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_comment_that_names_the_daemon_runs_a_turn() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
mount_repo(&server, "dave", "hey @kosmos can you take a look at this?").await;
|
||||||
|
mount_snapshot(&server).await;
|
||||||
|
let posted = Mock::given(method("POST"))
|
||||||
|
.and(path("/repos/acme/widgets/issues/7/comments"))
|
||||||
|
.and(body_partial_json(json!({ "body": "on it" })))
|
||||||
|
.respond_with(ResponseTemplate::new(201).set_body_json(json!({ "id": 43 })))
|
||||||
|
.expect(1)
|
||||||
|
.mount_as_scoped(&server)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
seed_watch(&dir, &server.uri());
|
||||||
|
let report = run_once(
|
||||||
|
&config(&dir),
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("the pass runs");
|
||||||
|
assert_eq!(report.outcomes, vec![Outcome::Handled]);
|
||||||
|
drop(posted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The gate's whole point: somebody else's conversation on a watched
|
||||||
|
/// repository is context, not a request. The news is drained and dropped
|
||||||
|
/// — and the snapshot is deliberately not mocked, so a dispatch that got
|
||||||
|
/// past the gate would fail loudly instead of posting quietly.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_comment_that_names_nobody_runs_nothing() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
mount_repo(&server, "dave", "any progress on this?").await;
|
||||||
|
let posted = Mock::given(method("POST"))
|
||||||
|
.and(path("/repos/acme/widgets/issues/7/comments"))
|
||||||
|
.respond_with(ResponseTemplate::new(201).set_body_json(json!({ "id": 43 })))
|
||||||
|
.expect(0)
|
||||||
|
.mount_as_scoped(&server)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
seed_watch(&dir, &server.uri());
|
||||||
|
let report = run_once(
|
||||||
|
&config(&dir),
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("the pass runs");
|
||||||
|
assert_eq!(
|
||||||
|
report.outcomes,
|
||||||
|
vec![Outcome::Superseded],
|
||||||
|
"nothing was asked, and nothing ran"
|
||||||
|
);
|
||||||
|
drop(posted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Our own replies are news too — and they quote the mention they answer.
|
||||||
|
/// Without the actor check, every answer would open the gate for the next
|
||||||
|
/// turn: the daemon talking to itself, forever.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_daemons_own_reply_does_not_reopen_the_gate() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
// Written by the daemon itself, quoting the mention it answers.
|
||||||
|
mount_repo(
|
||||||
|
&server,
|
||||||
|
"kosmos",
|
||||||
|
"> hey @kosmos can you take a look?\n\nDone — branch pushed.",
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
seed_watch(&dir, &server.uri());
|
||||||
|
let report = run_once(
|
||||||
|
&config(&dir),
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("the pass runs");
|
||||||
|
assert_eq!(
|
||||||
|
report.outcomes,
|
||||||
|
vec![Outcome::Superseded],
|
||||||
|
"the daemon answered itself"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A registry whose only backend is the scripted mock — the shape every
|
||||||
|
/// integration test runs on.
|
||||||
|
fn mock_registry(provider: Arc<dyn rhema_core::ModelProvider>) -> Arc<rhema_claw::BackendRegistry> {
|
||||||
|
Arc::new(
|
||||||
|
rhema_claw::BackendRegistry::new(
|
||||||
|
vec![rhema_claw::Backend::headless("mock", provider)],
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.expect("a single mock backend always constructs"),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -10,55 +10,14 @@ WORKDIR /build
|
|||||||
|
|
||||||
# Manifests first: the registry cache this populates survives source edits.
|
# Manifests first: the registry cache this populates survives source edits.
|
||||||
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
|
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
|
||||||
COPY crates/rhema-acp/Cargo.toml crates/rhema-acp/Cargo.toml
|
|
||||||
COPY crates/rhema-agent-tools/Cargo.toml crates/rhema-agent-tools/Cargo.toml
|
|
||||||
COPY crates/rhema-autonomous-agent/Cargo.toml crates/rhema-autonomous-agent/Cargo.toml
|
|
||||||
COPY crates/rhema-claw/Cargo.toml crates/rhema-claw/Cargo.toml
|
COPY crates/rhema-claw/Cargo.toml crates/rhema-claw/Cargo.toml
|
||||||
COPY crates/rhema-cloud-agent/Cargo.toml crates/rhema-cloud-agent/Cargo.toml
|
|
||||||
COPY crates/rhema-cloudflare-code/Cargo.toml crates/rhema-cloudflare-code/Cargo.toml
|
|
||||||
COPY crates/rhema-code/Cargo.toml crates/rhema-code/Cargo.toml
|
|
||||||
COPY crates/rhema-coding-agent/Cargo.toml crates/rhema-coding-agent/Cargo.toml
|
|
||||||
COPY crates/rhema-config/Cargo.toml crates/rhema-config/Cargo.toml
|
|
||||||
COPY crates/rhema-core/Cargo.toml crates/rhema-core/Cargo.toml
|
|
||||||
COPY crates/rhema-identity/Cargo.toml crates/rhema-identity/Cargo.toml
|
|
||||||
COPY crates/rhema-memory/Cargo.toml crates/rhema-memory/Cargo.toml
|
|
||||||
COPY crates/rhema-mcp/Cargo.toml crates/rhema-mcp/Cargo.toml
|
|
||||||
COPY crates/rhema-provider/Cargo.toml crates/rhema-provider/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-anthropic/Cargo.toml crates/rhema-provider-anthropic/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-chatgpt/Cargo.toml crates/rhema-provider-chatgpt/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-copilot/Cargo.toml crates/rhema-provider-copilot/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-google/Cargo.toml crates/rhema-provider-google/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-llama-cpp/Cargo.toml crates/rhema-provider-llama-cpp/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-openai-compatible/Cargo.toml crates/rhema-provider-openai-compatible/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-opencode/Cargo.toml crates/rhema-provider-opencode/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-openrouter/Cargo.toml crates/rhema-provider-openrouter/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-registry/Cargo.toml crates/rhema-provider-registry/Cargo.toml
|
|
||||||
COPY crates/rhema-rsd/Cargo.toml crates/rhema-rsd/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox/Cargo.toml crates/rhema-sandbox/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-docker/Cargo.toml crates/rhema-sandbox-docker/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-ecrou/Cargo.toml crates/rhema-sandbox-ecrou/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-http/Cargo.toml crates/rhema-sandbox-http/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-local/Cargo.toml crates/rhema-sandbox-local/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-lxd/Cargo.toml crates/rhema-sandbox-lxd/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-server/Cargo.toml crates/rhema-sandbox-server/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-ssh/Cargo.toml crates/rhema-sandbox-ssh/Cargo.toml
|
|
||||||
COPY crates/rhema-subagents/Cargo.toml crates/rhema-subagents/Cargo.toml
|
|
||||||
COPY crates/rhema-transcript/Cargo.toml crates/rhema-transcript/Cargo.toml
|
|
||||||
COPY integrations/rhema-calendar-integration/Cargo.toml integrations/rhema-calendar-integration/Cargo.toml
|
|
||||||
COPY integrations/rhema-forge-integration/Cargo.toml integrations/rhema-forge-integration/Cargo.toml
|
COPY integrations/rhema-forge-integration/Cargo.toml integrations/rhema-forge-integration/Cargo.toml
|
||||||
# rhema-claw path-depends on the tools contract, which lives in its own
|
COPY integrations/rhema-calendar-integration/Cargo.toml integrations/rhema-calendar-integration/Cargo.toml
|
||||||
# workspace: the member manifests inherit from that root, so the root
|
|
||||||
# rides along with them.
|
|
||||||
COPY tools/Cargo.toml tools/Cargo.toml
|
COPY tools/Cargo.toml tools/Cargo.toml
|
||||||
COPY tools/contract/Cargo.toml tools/contract/Cargo.toml
|
COPY tools/contract/Cargo.toml tools/contract/Cargo.toml
|
||||||
COPY tools/common/Cargo.toml tools/common/Cargo.toml
|
COPY tools/common/Cargo.toml tools/common/Cargo.toml
|
||||||
COPY tools/notify/Cargo.toml tools/notify/Cargo.toml
|
COPY tools/notify/Cargo.toml tools/notify/Cargo.toml
|
||||||
|
|
||||||
|
|
||||||
# Resolution reads the vendored crossterm (the root manifest path-patches
|
|
||||||
# to it) even though the image builds the daemon, which does not link it.
|
|
||||||
COPY vendor/ vendor/
|
|
||||||
|
|
||||||
# Cargo validates explicit target
|
# Cargo validates explicit target
|
||||||
# paths at manifest-parse time, so the fetch needs stub files at every
|
# paths at manifest-parse time, so the fetch needs stub files at every
|
||||||
# declared target path: src/ for every member, plus examples/tests/benches
|
# declared target path: src/ for every member, plus examples/tests/benches
|
||||||
|
|||||||
@@ -12,53 +12,16 @@ WORKDIR /build
|
|||||||
|
|
||||||
# Manifests first: the registry cache this populates survives source edits.
|
# Manifests first: the registry cache this populates survives source edits.
|
||||||
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
|
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
|
||||||
COPY crates/rhema-acp/Cargo.toml crates/rhema-acp/Cargo.toml
|
|
||||||
COPY crates/rhema-agent-tools/Cargo.toml crates/rhema-agent-tools/Cargo.toml
|
|
||||||
COPY crates/rhema-autonomous-agent/Cargo.toml crates/rhema-autonomous-agent/Cargo.toml
|
|
||||||
COPY crates/rhema-claw/Cargo.toml crates/rhema-claw/Cargo.toml
|
COPY crates/rhema-claw/Cargo.toml crates/rhema-claw/Cargo.toml
|
||||||
COPY crates/rhema-cloud-agent/Cargo.toml crates/rhema-cloud-agent/Cargo.toml
|
|
||||||
COPY crates/rhema-cloudflare-code/Cargo.toml crates/rhema-cloudflare-code/Cargo.toml
|
|
||||||
COPY crates/rhema-code/Cargo.toml crates/rhema-code/Cargo.toml
|
|
||||||
COPY crates/rhema-coding-agent/Cargo.toml crates/rhema-coding-agent/Cargo.toml
|
|
||||||
COPY crates/rhema-config/Cargo.toml crates/rhema-config/Cargo.toml
|
|
||||||
COPY crates/rhema-core/Cargo.toml crates/rhema-core/Cargo.toml
|
|
||||||
COPY crates/rhema-identity/Cargo.toml crates/rhema-identity/Cargo.toml
|
|
||||||
COPY crates/rhema-memory/Cargo.toml crates/rhema-memory/Cargo.toml
|
|
||||||
COPY crates/rhema-mcp/Cargo.toml crates/rhema-mcp/Cargo.toml
|
|
||||||
COPY crates/rhema-provider/Cargo.toml crates/rhema-provider/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-anthropic/Cargo.toml crates/rhema-provider-anthropic/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-chatgpt/Cargo.toml crates/rhema-provider-chatgpt/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-copilot/Cargo.toml crates/rhema-provider-copilot/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-google/Cargo.toml crates/rhema-provider-google/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-llama-cpp/Cargo.toml crates/rhema-provider-llama-cpp/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-openai-compatible/Cargo.toml crates/rhema-provider-openai-compatible/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-opencode/Cargo.toml crates/rhema-provider-opencode/Cargo.toml
|
|
||||||
COPY crates/rhema-provider-openrouter/Cargo.toml crates/rhema-provider-openrouter/Cargo.toml
|
|
||||||
COPY crates/rhema-rsd/Cargo.toml crates/rhema-rsd/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox/Cargo.toml crates/rhema-sandbox/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-docker/Cargo.toml crates/rhema-sandbox-docker/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-ecrou/Cargo.toml crates/rhema-sandbox-ecrou/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-http/Cargo.toml crates/rhema-sandbox-http/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-local/Cargo.toml crates/rhema-sandbox-local/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-lxd/Cargo.toml crates/rhema-sandbox-lxd/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-server/Cargo.toml crates/rhema-sandbox-server/Cargo.toml
|
|
||||||
COPY crates/rhema-sandbox-ssh/Cargo.toml crates/rhema-sandbox-ssh/Cargo.toml
|
|
||||||
COPY crates/rhema-subagents/Cargo.toml crates/rhema-subagents/Cargo.toml
|
|
||||||
COPY crates/rhema-transcript/Cargo.toml crates/rhema-transcript/Cargo.toml
|
|
||||||
COPY integrations/rhema-calendar-integration/Cargo.toml integrations/rhema-calendar-integration/Cargo.toml
|
|
||||||
COPY integrations/rhema-forge-integration/Cargo.toml integrations/rhema-forge-integration/Cargo.toml
|
COPY integrations/rhema-forge-integration/Cargo.toml integrations/rhema-forge-integration/Cargo.toml
|
||||||
# rhema-claw path-depends on the tools contract, which lives in its own
|
COPY integrations/rhema-calendar-integration/Cargo.toml integrations/rhema-calendar-integration/Cargo.toml
|
||||||
# workspace: the member manifests inherit from that root, so the root
|
|
||||||
# rides along with them.
|
|
||||||
COPY tools/Cargo.toml tools/Cargo.toml
|
COPY tools/Cargo.toml tools/Cargo.toml
|
||||||
COPY tools/contract/Cargo.toml tools/contract/Cargo.toml
|
COPY tools/contract/Cargo.toml tools/contract/Cargo.toml
|
||||||
COPY tools/common/Cargo.toml tools/common/Cargo.toml
|
COPY tools/common/Cargo.toml tools/common/Cargo.toml
|
||||||
COPY tools/notify/Cargo.toml tools/notify/Cargo.toml
|
COPY tools/notify/Cargo.toml tools/notify/Cargo.toml
|
||||||
|
# rhema-claw path-depends on the tools contract, which lives in its own
|
||||||
|
# workspace: the member manifests inherit from that root, so the root
|
||||||
# Resolution reads the vendored crossterm (the root manifest path-patches
|
# rides along with them.
|
||||||
# to it) even though the image builds the daemon, which does not link it.
|
|
||||||
COPY vendor/ vendor/
|
|
||||||
|
|
||||||
# Cargo validates explicit target
|
# Cargo validates explicit target
|
||||||
# paths at manifest-parse time, so the fetch needs stub files at every
|
# paths at manifest-parse time, so the fetch needs stub files at every
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ publish = false
|
|||||||
rusqlite = { version = "0.40", features = ["bundled"] }
|
rusqlite = { version = "0.40", features = ["bundled"] }
|
||||||
# The reminder source: one `Source` over the feeds, detect-pass shaped
|
# The reminder source: one `Source` over the feeds, detect-pass shaped
|
||||||
# like the task scheduler's
|
# like the task scheduler's
|
||||||
rhema-autonomous-agent = { path = "../../crates/rhema-autonomous-agent", version = "0.2.3" }
|
rhema-autonomous-agent = "0.2.3"
|
||||||
# The reminder source ingests its slots into a `Dispatcher`; the event
|
# The reminder source ingests its slots into a `Dispatcher`; the event
|
||||||
# and key-function shapes are the dispatcher's
|
# and key-function shapes are the dispatcher's
|
||||||
rhema-rsd = { path = "../../crates/rhema-rsd", version = "0.2.3" }
|
rhema-rsd = "0.2.3"
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ publish = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# The dispatch seam: watches ingest into a Dispatcher
|
# The dispatch seam: watches ingest into a Dispatcher
|
||||||
rhema-rsd = { path = "../../crates/rhema-rsd", version = "0.2.3" }
|
rhema-rsd = "0.2.3"
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|||||||
@@ -99,6 +99,19 @@ pub trait Forge: Send + Sync {
|
|||||||
&self,
|
&self,
|
||||||
since: Option<&Timestamp>,
|
since: Option<&Timestamp>,
|
||||||
) -> Result<NotificationPage, ForgeError>;
|
) -> Result<NotificationPage, ForgeError>;
|
||||||
|
|
||||||
|
/// The login this client authenticates as — the backend's own answer
|
||||||
|
/// to "who am I".
|
||||||
|
///
|
||||||
|
/// A consumer that must recognize its own handle (to see an @-mention
|
||||||
|
/// in a body, and to ignore its own replies) cannot always read it off
|
||||||
|
/// its credential: a token pasted into a watch row, or an environment
|
||||||
|
/// variable, names nobody. `None` is the honest default — a backend
|
||||||
|
/// with no such route simply cannot say who it is — and a backend that
|
||||||
|
/// can say answers with its `/user` row.
|
||||||
|
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -690,6 +690,11 @@ impl Forge for GiteaForge {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||||
|
let user: WireUser = decode(self.send(self.get("/user")).await?).await?;
|
||||||
|
Ok(user.login.filter(|login| !login.trim().is_empty()))
|
||||||
|
}
|
||||||
|
|
||||||
async fn snapshot(
|
async fn snapshot(
|
||||||
&self,
|
&self,
|
||||||
repo: &RepoRef,
|
repo: &RepoRef,
|
||||||
|
|||||||
@@ -646,6 +646,16 @@ impl Forge for GitHubForge {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||||
|
let response = self
|
||||||
|
.get("/user")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(ForgeError::network)?;
|
||||||
|
let user: WireUser = decode(response).await?;
|
||||||
|
Ok(user.login.filter(|login| !login.trim().is_empty()))
|
||||||
|
}
|
||||||
|
|
||||||
async fn snapshot(
|
async fn snapshot(
|
||||||
&self,
|
&self,
|
||||||
repo: &RepoRef,
|
repo: &RepoRef,
|
||||||
|
|||||||
@@ -523,6 +523,18 @@ impl Forge for GitLabForge {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn viewer_login(&self) -> Result<Option<String>, ForgeError> {
|
||||||
|
// GitLab spells the login `username`, like every author object it
|
||||||
|
// sends.
|
||||||
|
let response = self
|
||||||
|
.get("/user")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(ForgeError::network)?;
|
||||||
|
let user: WireAuthor = decode(response).await?;
|
||||||
|
Ok(user.username.filter(|login| !login.trim().is_empty()))
|
||||||
|
}
|
||||||
|
|
||||||
async fn snapshot(
|
async fn snapshot(
|
||||||
&self,
|
&self,
|
||||||
repo: &RepoRef,
|
repo: &RepoRef,
|
||||||
|
|||||||
@@ -557,3 +557,19 @@ async fn notifications_poll_maps_the_subject_feed() {
|
|||||||
assert_eq!(note.repo, RepoRef::new("acme", "widgets"));
|
assert_eq!(note.repo, RepoRef::new("acme", "widgets"));
|
||||||
assert_eq!(note.title.as_deref(), Some("Fix the gate"));
|
assert_eq!(note.title.as_deref(), Some("Fix the gate"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The mention gate asks the forge who the credential is, because a token
|
||||||
|
/// read from a watch row names nobody.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_viewer_login_is_the_instances_own_answer() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/api/v1/user"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "login": "kosmos" })))
|
||||||
|
.mount(&server)
|
||||||
|
.await;
|
||||||
|
assert_eq!(
|
||||||
|
forge(&server).viewer_login().await.expect("the call lands"),
|
||||||
|
Some("kosmos".to_owned())
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -532,3 +532,19 @@ async fn notifications_without_a_cursor_still_return_the_newest_seen() {
|
|||||||
Some(Timestamp::parse("2026-10-02T00:00:00Z").expect("parses"))
|
Some(Timestamp::parse("2026-10-02T00:00:00Z").expect("parses"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The mention gate asks the forge who the credential is, because a token
|
||||||
|
/// read from a watch row names nobody.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_viewer_login_is_the_instances_own_answer() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/user"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "login": "kosmos-ai-bot" })))
|
||||||
|
.mount(&server)
|
||||||
|
.await;
|
||||||
|
assert_eq!(
|
||||||
|
forge(&server).viewer_login().await.expect("the call lands"),
|
||||||
|
Some("kosmos-ai-bot".to_owned())
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -572,3 +572,20 @@ async fn todos_poll_maps_actions_targets_and_projects() {
|
|||||||
Some("https://gitlab.com/acme/widgets/-/merge_requests/12")
|
Some("https://gitlab.com/acme/widgets/-/merge_requests/12")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The mention gate asks the forge who the credential is, because a token
|
||||||
|
/// read from a watch row names nobody. GitLab spells the login
|
||||||
|
/// `username`.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_viewer_login_is_the_instances_own_answer() {
|
||||||
|
let server = MockServer::start().await;
|
||||||
|
Mock::given(method("GET"))
|
||||||
|
.and(path("/api/v4/user"))
|
||||||
|
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "username": "kosmos" })))
|
||||||
|
.mount(&server)
|
||||||
|
.await;
|
||||||
|
assert_eq!(
|
||||||
|
forge(&server).viewer_login().await.expect("the call lands"),
|
||||||
|
Some("kosmos".to_owned())
|
||||||
|
);
|
||||||
|
}
|
||||||
Executable
+92
@@ -0,0 +1,92 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Run the claw and the web UI together against scratch state — the quick
|
||||||
|
# debug loop. Nothing here touches your real rhema config or sessions:
|
||||||
|
# the daemon gets a throwaway config under $RHEMA_DEV_DIR (default
|
||||||
|
# /tmp/rhema-dev), persisted across runs so sessions survive a restart
|
||||||
|
# of the script; wipe the directory for a clean slate.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# scripts/dev.sh # real provider (CLAW_DEV_PROVIDER, key from
|
||||||
|
# # the provider's env var; default google)
|
||||||
|
# scripts/dev.sh --mock # zero credentials: canned streamed replies
|
||||||
|
#
|
||||||
|
# The UI proxies /v1 to the claw, so one URL matters:
|
||||||
|
# http://localhost:3000
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
SCRATCH="${RHEMA_DEV_DIR:-/tmp/rhema-dev}"
|
||||||
|
PROVIDER="${CLAW_DEV_PROVIDER:-google}"
|
||||||
|
|
||||||
|
MOCK=0
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--mock) MOCK=1 ;;
|
||||||
|
*) echo "unknown argument: $arg (supported: --mock)" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
mkdir -p "$SCRATCH/workspaces"
|
||||||
|
|
||||||
|
CONFIG="$SCRATCH/claw.yaml"
|
||||||
|
if [ "$MOCK" = 1 ]; then
|
||||||
|
cat > "$CONFIG" <<EOF
|
||||||
|
# Scratch debug config (scripts/dev.sh --mock): no model is called.
|
||||||
|
db: $SCRATCH/claw.db
|
||||||
|
workspace_root: $SCRATCH/workspaces
|
||||||
|
memory_root: $SCRATCH/memory
|
||||||
|
bootstrap_root: $SCRATCH/bootstrap
|
||||||
|
listen: 127.0.0.1:7799
|
||||||
|
poll_interval_secs: 60
|
||||||
|
EOF
|
||||||
|
FEATURES=(--features mock)
|
||||||
|
RUN_FLAGS=(--mock)
|
||||||
|
else
|
||||||
|
case "$PROVIDER" in
|
||||||
|
google) KEY_VAR=GOOGLE_API_KEY ;;
|
||||||
|
anthropic) KEY_VAR=ANTHROPIC_API_KEY ;;
|
||||||
|
openai) KEY_VAR=OPENAI_API_KEY ;;
|
||||||
|
openrouter) KEY_VAR=OPENROUTER_API_KEY ;;
|
||||||
|
llama-cpp) KEY_VAR="" ;;
|
||||||
|
*) echo "CLAW_DEV_PROVIDER must be google, anthropic, openai, openrouter, or llama-cpp" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
if [ -n "$KEY_VAR" ] && [ -z "${!KEY_VAR:-}" ]; then
|
||||||
|
echo "set $KEY_VAR first (or run scripts/dev.sh --mock for zero credentials)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
cat > "$CONFIG" <<EOF
|
||||||
|
# Scratch debug config (scripts/dev.sh): throwaway db and workspaces.
|
||||||
|
provider: $PROVIDER
|
||||||
|
db: $SCRATCH/claw.db
|
||||||
|
workspace_root: $SCRATCH/workspaces
|
||||||
|
memory_root: $SCRATCH/memory
|
||||||
|
bootstrap_root: $SCRATCH/bootstrap
|
||||||
|
listen: 127.0.0.1:7799
|
||||||
|
poll_interval_secs: 60
|
||||||
|
EOF
|
||||||
|
FEATURES=()
|
||||||
|
RUN_FLAGS=()
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[dev] claw config: $CONFIG"
|
||||||
|
cargo build -p rhema-claw "${FEATURES[@]}"
|
||||||
|
|
||||||
|
if [ ! -d "$ROOT/web/claw/node_modules" ]; then
|
||||||
|
echo "[dev] installing web/claw dependencies"
|
||||||
|
(cd "$ROOT/web/claw" && npm install)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# exec so the trap's kill reaches the servers, not a wrapper.
|
||||||
|
"$ROOT/target/debug/rhema-claw" --config "$CONFIG" "${RUN_FLAGS[@]}" &
|
||||||
|
CLAW_PID=$!
|
||||||
|
(cd "$ROOT/web/claw" && exec ./node_modules/.bin/nuxt dev) &
|
||||||
|
UI_PID=$!
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
kill "$CLAW_PID" "$UI_PID" 2>/dev/null || true
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
echo "[dev] claw: http://127.0.0.1:7799 (config: $CONFIG)"
|
||||||
|
echo "[dev] ui: http://localhost:3000 (ctrl-c stops both)"
|
||||||
|
wait "$CLAW_PID"
|
||||||
+1
-1
@@ -7,7 +7,7 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.85"
|
rust-version = "1.85"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/vhaudiquet/rhema"
|
repository = "https://git.vhaudiquet.fr/vhaudiquet/rhema-claw"
|
||||||
authors = ["Valentin Haudiquet"]
|
authors = ["Valentin Haudiquet"]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
|||||||
Reference in new issue
Block a user