DevState is a lightweight HTTP service that manages the project state (.trae/state.json) and audit history (.trae/history.json), enforces No-Drift, and verifies an HMAC chain of operations. It is designed to support development consistency across IDEs and CI/CD pipelines.
TRAE IDE
- Website: https://www.trae.ai/
- DevState integrates with TRAE as the source-of-truth validator for
.trae/state.jsonand.trae/history.json.
- Read/write state and history with verification of HMAC digest chain.
- Import/Export helpers for JSON ⇄ memory/DB workflows.
- Health endpoint for monitoring (
/health). - Standalone Docker Compose stack for isolated validation.
server/— Node.js HTTP server and domain logic.docs/— service documentation and usage guides.scripts/— CLI utilities for import/export/verify.sql/— initialization scripts (Postgres schema).docker-compose.yml— standalone DevState stack (HTTP 3180, Postgres 55432).metadata.json— service metadata (ports, artifacts, usage).
Prerequisites: Docker, Docker Compose.
- Start standalone stack:
make devstate-up- Check health:
curl http://localhost:3180/health
- Use CLI utilities:
- Import:
bash devstate/scripts/devstate.sh import - Export:
bash devstate/scripts/devstate.sh export - Verify:
bash devstate/scripts/devstate.sh verify
- Import:
- Stop the stack when done:
make devstate-down
Trae IDE Integration
- Trae IDE uses
.trae/state.jsonand.trae/history.jsonas sources of truth. - DevState validates and exports these files to keep multiple IDEs consistent.
- Recommended: add
bash devstate/scripts/devstate_verify.shto pre-commit/pre-push.
Installation & Usage
- No Docker:
npm installindevstate/server, then runnode devstate/server/http-server.jswith env vars. - Docker:
make devstate-upto run isolated HTTP3180and Postgres55432. - Scripts:
devstate/scripts/*provide import/export/verify helpers.
GitHub Publication (devstat)
- Create a new repository
rustkas/devstat. - Put the contents of this
devstate/directory at the repository root. - Ensure
LICENSEis MIT and present at the root. - Ensure this
README.mdis at the root and references TRAE. - Initial commit and push:
git init && git add . && git commit -m "DevState initial release (MIT)"git branch -M main && git remote add origin git@github.com:rustkas/devstate.gitgit push -u origin main
GitHub Actions
- Not required for publication.
- Optional (if needed later): add a single workflow to run
devstate/scripts/devstate_verify.shon push/PR to validate.trae/state.jsonand HMAC chain.
Environment variables (Compose):
DEVSTATE_HTTP_PORT— internal HTTP port (default3080).HMAC_SECRET— HMAC secret for audit verification (default dev-only value).DATABASE_URL— Postgres connection string (see compose).PGHOST,DB_SCHEMA— Postgres host and schema. Security:- Set
DEVSTATE_API_TOKENto protect mutating endpoints (Bearer token).
- Bearer token
- Generate a strong token and set
DEVSTATE_API_TOKENon the server; clients passAuthorization: Bearer <token>. - Store tokens in secret managers; avoid committing tokens to code or configs.
- Generate a strong token and set
- HMAC rotation
- Use
/v1/devstate/keys/rotateto publish a new active key; recordkidin history metadata. - Schedule rotation (e.g., monthly/quarterly); verify chain with
/v1/devstate/verifyafter rotation.
- Use
- Rate-limit
- Default limiter: 120 req/min for mutating endpoints; adjust per environment.
- Recommended:
state/history≤ 120 rpm,verify≤ 600 rpm.
- Best practices
- Protect API behind reverse proxy with TLS/mTLS in production.
- Monitor
append_fail_total,state_update_fail_total, and success rate per route. - Audit: all changes append to
history_entrieswith HMAC chain; export.trae/*for cross‑IDE sync.
- Verify workflow:
.github/workflows/devstate-verify.yml(compose up → health → verify → export). - No‑Drift deny:
.github/workflows/no-drift-deny.yml(blocks PR if.trae/*tracked). - OpenAPI release and clients: TS/Go/Python workflows publish artifacts on tags.
- Prometheus scrape example:
docs/prometheus_scrape.yml(targetslocalhost:3180, path/metrics). - Grafana dashboard example:
docs/grafana_dashboard.json(p95 verify, failure counts, rate‑limited, locks). - Grafana extended dashboard:
docs/grafana_dashboard_extended.json(latency percentiles, throughput, error metrics). - Real-time updates: Prometheus pulls
/metrics; ensure scrape interval ≤15sand Grafana dashboard refresh set to5s.
- Commands:
docker compose -f docs/compose-prometheus.yml up -ddocker compose -f docs/compose-grafana.yml up -d- Import dashboards in Grafana (URL:
http://localhost:3000/, passwordadmin).
- Prometheus: start with scrape config above; validate targets state.
- Grafana: import JSON dashboards via UI; set refresh to
5s. - Production monitoring: set alerts for p95 latency, success rate < 95%, and append/state failures increase; configure dashboards per tenant if multi-tenant.
GET /health— returns service status.
- Index:
devstate/docs/README.md - Overview:
devstate/docs/DEVSTATE_OVERVIEW.md - MCP usage:
devstate/docs/MCP_USAGE.md - Historical note:
devstate/docs/BEAMLINE_STORE_TZ.md - Scripts:
devstate/scripts/README.md
- Health check fails: verify that
docker composestarted DB and server; check logs withdocker compose logs. - Verify returns 500: on empty history chain server returns
{ ok: true }; ensure DB is initialized andHMAC_SECRETset. - Import/Export .trae:
- Import errors: validate
.trae/state.jsonagainstdocs/STATE.schema.json; ensure HMAC chain in.trae/history.jsonis consistent. - Export issues: verify write permissions to
.trae/; check resulting file checksums.
- Import errors: validate
- HTTP codes:
- 200: success for verify/state/history operations.
- 400: validation failure (state schema, append payload); check error message.
- 429: rate-limited; reduce request rate or increase limits.
- 500: server errors; inspect logs and metrics.
- Metrics analysis:
- Latency histograms:
devstate_*_duration_secondsexpose buckets; use Grafana panels for p95/p99. - Success rate: computed via
devstate_request_total{status='200'}over total per route. - Fail counters:
devstate_append_fail_total,devstate_state_update_fail_totalfor error tracking.
- Latency histograms:
- Bearer token required: set
DEVSTATE_API_TOKENin server env and passAuthorization: Bearer <token>. - k6 append errors: check
DEVSTATE_API_TOKENis provided in workflow or removerequireAuthfor tests.
- TypeScript:
npm install @rustkas/devstate-client→ seeclients/typescript/README.mdfor usage. - Python:
pip install devstate-client(after publish) → seeclients/python/USAGE.md. - Go:
go get github.com/rustkas/devstate/clients/go@client-go-vX.Y.Z.
MIT. See LICENSE.
Package compliance: server/package.json declares MIT.
- AIGROUP / Beamline Constructor platform team.