Normalize agent instructions and workplan frontmatter (STATE-WP-0067)
Some checks are pending
CI / test (3.11) (push) Waiting to run
CI / test (3.12) (push) Waiting to run
CI / coverage (push) Blocked by required conditions

- Align agent files with on-disk workplan prefixes (infer from workplan ids)
- Set workplan domain to registered domain_slug; add topic_slug where applicable
- Repair frontmatter delimiter formatting; migrate legacy task status literals
- Regenerate AGENTS.md, CLAUDE.md, and .claude/rules from State Hub templates
This commit is contained in:
2026-06-22 23:16:27 +02:00
parent 37efe46a6e
commit cd8d1a3732
9 changed files with 238 additions and 355 deletions

219
AGENTS.md Normal file
View File

@@ -0,0 +1,219 @@
# marki-docx — Agent Instructions
## Repo Identity
**Purpose:** Markdown ↔ DOCX round-trip editing system. CLI + REST + MCP interfaces for controlled editorial workflows where Markdown is canonical and Word is the editorial projection.
**Domain:** communication
**Repo slug:** marki-docx
**Topic ID:** `36c7421b-c537-4723-bf75-42a3ebc6a1dc`
**Workplan prefix:** `MRKD-WP-`
---
## State Hub Integration
The Custodian State Hub tracks work across all domains. Interact via HTTP REST —
there is no MCP server for Codex agents.
| Context | URL |
|---------|-----|
| Local workstation | `http://127.0.0.1:8000` |
| Remote via tunnel | `http://127.0.0.1:18000` |
### Orient at session start
```bash
# Offline brief — works without hub connection
cat .custodian-brief.md
# Active workstreams for this domain
curl -s "http://127.0.0.1:8000/workstreams/?topic_id=36c7421b-c537-4723-bf75-42a3ebc6a1dc&status=active" \
| python3 -m json.tool
# Check inbox
curl -s "http://127.0.0.1:8000/messages/?to_agent=marki-docx&unread_only=true" \
| python3 -m json.tool
```
Mark a message read:
```bash
curl -s -X PATCH "http://127.0.0.1:8000/messages/<id>/read" \
-H "Content-Type: application/json" -d '{}'
```
### Log progress (required at session close)
```bash
curl -s -X POST http://127.0.0.1:8000/progress/ \
-H "Content-Type: application/json" \
-d '{
"summary": "what was done",
"event_type": "note",
"author": "codex",
"workstream_id": "<uuid>",
"task_id": "<uuid>"
}'
```
Omit `workstream_id` / `task_id` when not applicable.
### Update task status
```bash
curl -s -X PATCH "http://127.0.0.1:8000/tasks/<task_id>" \
-H "Content-Type: application/json" \
-d '{"status": "progress"}'
# values: wait | todo | progress | done | cancel
```
### Flag a task for human review
```bash
curl -s -X PATCH "http://127.0.0.1:8000/tasks/<task_id>" \
-H "Content-Type: application/json" \
-d '{"needs_human": true, "intervention_note": "reason"}'
```
---
## Session Protocol
**Start:**
1. `cat .custodian-brief.md` — domain goal and open workstreams (offline-safe)
2. Check inbox: `GET /messages/?to_agent=marki-docx&unread_only=true`; mark read
3. Scan workplans: `ls workplans/` — note `status: ready`, `active`, or `blocked` files and open tasks
4. Check human-needed tasks: `GET /tasks/?needs_human=true`
**During work:**
- Update task statuses in workplan files as tasks progress
- Record significant decisions via `POST /decisions/`
**Close:**
1. Update workplan file task statuses to reflect progress
2. Log: `POST /progress/` with a summary of what changed
3. Note for the custodian operator: after workplan file changes, run from
`~/state-hub`:
```bash
make fix-consistency REPO=marki-docx
```
This syncs task status from files into the hub DB.
---
## Credential and access routing
**Audience:** Codex, Claude Code, Grok, and custodian agents that call **llm-connect**
for inference. Run this check **before** requesting secrets, API keys, SSH access,
login tokens, or database passwords — in any repo, not only `ops-warden`.
ops-warden **issues SSH certificates only** (`warden sign`, `cert_command`). Every
other credential need belongs to another subsystem. **Do not** message
`ops-warden` on State Hub expecting a secret value; the reply is a pointer, not a key.
### Lookup (do this first)
```bash
warden route find "<describe your need>" --json
warden route show <catalog-id> --json
```
Requires the `warden` CLI from `~/ops-warden` (`uv tool install .` or `uv run warden`).
| Agent runtime | How to orient |
| --- | --- |
| **Codex / Grok** (shell, HTTP State Hub) | `warden route` commands above; inbox `to_agent=marki-docx` is for coordination, not secret vending |
| **Claude Code** (MCP when available) | `get_domain_summary("custodian")` for workstreams; **still** use `warden route` for credential ownership |
| **llm-connect** (inference service) | Never put secret retrieval in prompts; route custody to OpenBao/operator paths surfaced by `warden route` |
### Quick routing table
| I need… | Owner | ops-warden executes? |
| --- | --- | --- |
| SSH cert (`adm`/`agt`/`atm`) | ops-warden | **Yes** — `warden sign` |
| API key, DB password, provider token | OpenBao (`railiance-platform`) | No — route only |
| Login / OIDC / MFA | key-cape / Keycloak | No — route only |
| Authorization decision | flex-auth | No — route only |
| activity-core → issue-core emission | activity-core + issue-core | No — `warden route show activity-core-issue-sink` |
| SSH tunnel | ops-bridge (+ `cert_command` from warden) | No — route only |
### Anti-patterns (do not do these)
- `POST /messages/` to `ops-warden` asking for `ISSUE_CORE_API_KEY`, `OPENROUTER_API_KEY`, etc.
- Inventing `warden secret`, `warden login`, `warden bao`, `warden tunnel` — they do not exist
- Pasting secrets into Git, State Hub, workplans, logs, or chat
### Other capabilities (reuse-surface)
Non-credential capabilities are usually discovered through **reuse-surface** federation
(`reuse-surface` registry / `capability.*` indexes). Credential routing is inlined in
every repo's agent instructions because it is high-frequency, high-risk, and easy to
get wrong.
**Canon:** `~/ops-warden/wiki/CredentialRouting.md` · catalog `~/ops-warden/registry/routing/catalog.yaml`
<!-- REPO-AGENTS-EXTENSIONS -->
<!-- Append repo-specific agent instructions below this marker.
The state-hub template sync preserves content after this line. -->
---
## Workplan Convention (ADR-001)
Work items originate as files in this repo — not in the hub. The hub is a
read/cache/index layer that rebuilds from files.
**File location:** `workplans/MARKI-WP-NNNN-<slug>.md`
**Archived location:** finished workplans may move to
`workplans/archived/YYMMDD-MARKI-WP-NNNN-<slug>.md`. The `YYMMDD` prefix is
the completion/archive date; the frontmatter `id` does not change.
**Ad Hoc Tasks:** small opportunistic fixes discovered during a session use
`workplans/ADHOC-YYYY-MM-DD.md` with task ids `ADHOC-YYYY-MM-DD-T01`, etc. Use
this only for low-risk work completed directly; create a normal workplan for
anything needing analysis, design, approval, dependencies, or multiple phases.
**Frontmatter:**
```yaml
---
id: MARKI-WP-NNNN
type: workplan
title: "..."
domain: communication
repo: marki-docx
status: proposed | ready | active | blocked | backlog | finished | archived
owner: codex
topic_slug: ...
created: "YYYY-MM-DD"
updated: "YYYY-MM-DD"
state_hub_workstream_id: "<uuid>" # written by fix-consistency — do not edit
---
```
Use `proposed` for a new draft, `ready` after review against current repo
state, and `finished` after implementation. `stalled` and `needs_review` are
derived health labels, not frontmatter statuses.
**Task block format** (one per `##` section):
```
## Task Title
` ` `task
id: MARKI-WP-NNNN-T01
status: wait | todo | progress | done | cancel
priority: high | medium | low
state_hub_task_id: "<uuid>" # written by fix-consistency — do not edit
` ` `
Task description text.
```
Status progression: `todo` → `progress` → `done`; use `wait` for waiting/blocked work and `cancel` for stopped work.
To create a new workplan:
1. Write the file following the format above
2. Notify the custodian operator to run `make fix-consistency REPO=marki-docx`
(or send a message to the hub agent via `POST /messages/`)

360
CLAUDE.md
View File

@@ -1,348 +1,12 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## What This Repo Is
**marki-docx** (markidocx) is a Markdown ↔ DOCX round-trip editing system.
- Markdown is the **canonical structured source**
- Word documents are **editorial projections** — generated for review, not authoritative
- Conversion must be deterministic, inspectable, and semantically stable across cycles
- Interfaces: CLI, REST service, MCP tools
Key artefacts already in this repo:
- `specs/MarkiDocxProductRequirementsDocument_v0.1.md` — PRD (implementation-independent)
- `specs/MarkiDocxFunctionalRequirementsSpecification_v0.2.md` — FRS (binding functional contract)
- `specs/MarkiDocxUseCaseCatalog_v0.1.md` — use case catalogue
---
## Planned Architecture
markidocx is a **conversion pipeline** with three delivery interfaces over a shared functional core.
### Interfaces
| Interface | Purpose |
|-----------|---------|
| CLI | Local document workflows (`markidocx build`, `import`, `validate`, `compare`) |
| REST service | Automation / pipeline integration |
| MCP tools | Agent-accessible operations (same functional surface as CLI/REST) |
All three interfaces expose the same functional model — no interface-specific logic should live outside its adapter layer.
### Core Functional Domains (from FRS)
| FR group | Domain |
|----------|--------|
| FR-100 | Project & manifest management |
| FR-200 | Build / export (Markdown → DOCX) |
| FR-300 | Import / round-trip (DOCX → Markdown) |
| FR-400 | Multi-file composition & redistribution |
| FR-500 | Feature-level enforcement (LEVEL1 / LEVEL3) |
| FR-600 | Template & style family management |
| FR-700 | Validation & drift analysis |
| FR-1100 | Test & regression |
| FR-1300 | Composite workflow orchestration |
| FR-1400 | Evidence & report assembly |
### Key Concepts
- **Project manifest** — declares source files, feature level, and template/style family; drives all operations
- **Feature levels** — LEVEL1 (headings, lists, tables, footnotes, images, links); LEVEL3 adds cross-refs, numbered figures, auto-diagrams, bibliography
- **Document families** — three built-in: `article`, `book`, `website`; extensible via registration
- **Source mapping** — multi-file imports must redistribute content back to origin files; fallback produces a merged single file
- **Drift detection** — structural diff between original Markdown and re-imported result; reported as inspectable evidence
### Round-trip data flow
```
manifest + Markdown sources
↓ FR-100 (resolve project)
↓ FR-200 (compose + export → DOCX)
[Word editorial review]
↓ FR-300 (import DOCX → Markdown)
↓ FR-400 (redistribute to source files)
↓ FR-700 (validate + drift report)
evidence artefacts
```
### Implementation State
| Module | Status | FR coverage |
|--------|--------|-------------|
| `cli.py` | implemented — all commands wired (`build`, `import`, `compare`, `validate`, `serve`, `workflow`, `mcp`, `template`) | all |
| `manifest.py` | implemented | FR-100 |
| `builder.py` | implemented — LEVEL1 + LEVEL3 (xrefs, figures, diagrams, citations) | FR-200, FR-531539 |
| `importer.py` | implemented — LEVEL1 + LEVEL3 round-trip | FR-300/400, FR-531536 |
| `differ.py` | implemented — LEVEL1 + LEVEL3 drift detection | FR-700, FR-540542 |
| `templates.py` | implemented | FR-600 |
| `evidence.py` | implemented | FR-1400 |
| `workflows.py` | implemented (`single-file-roundtrip`, `multi-file-roundtrip`, `release-regression`, `family-switch-build`) | FR-1300 |
| `rest.py` | implemented — FastAPI app, all endpoints; structured warning records | FR-900, FR-1208 |
| `mcp_server.py` | implemented — FastMCP server, all tools and resources; structured warnings | FR-1000, FR-1208 |
| `errors.py` | implemented — `WarningRecord`, `FailureRecord`, `OutputState` | FR-12011210 |
| `level3.py` | implemented — LEVEL3 support detection, capability disclosure | FR-537539 |
| `xref.py` | implemented — cross-reference round-trip helpers | FR-531, FR-540 |
| `figures.py` | implemented — numbered figure round-trip helpers | FR-532, FR-541 |
| `diagrams.py` | implemented — auto-diagram source-only + renderer path | FR-533, FR-534 |
| `bibliography.py` | implemented — citation and references section round-trip | FR-535, FR-536, FR-542 |
`tests/conftest.py` provides shared fixtures. WP-0001, WP-0002, and WP-0003 complete — 259 tests passing. Full LEVEL1 + LEVEL3 feature coverage. All interfaces (CLI, REST, MCP) implemented and parity-tested.
---
## Development Commands
```bash
# Install in editable mode
pip install -e ".[dev]"
# Run tests
pytest
# Run a single test file
pytest tests/path/to/test_file.py
# Lint
ruff check .
# Type-check
mypy src/
# Start REST service (dev mode)
markidocx serve --dev
# CLI: build a document project
markidocx build <manifest.yaml>
# CLI: import an edited DOCX
markidocx import <manifest.yaml> <edited.docx>
# CLI: compare baseline vs re-import
markidocx compare <manifest.yaml> <edited.docx>
# CLI: run end-to-end regression
markidocx test
```
---
## Custodian State Hub Integration
This project is tracked as the **markitect** domain in the Custodian State Hub.
| Key | Value |
|-----|-------|
| Domain | `markitect` |
| Topic ID | `5571d954-0d30-4950-980d-7bcaaad8e3e2` |
| Repo ID | `75d31180-acf5-4d47-aea8-2a5b1e71e6a9` |
| Repo slug | `marki-docx` |
Hub API: `http://127.0.0.1:18001` — if offline: `cd ~/the-custodian/state-hub && make api`
---
## Session Protocol (MANDATORY)
### On session start — before writing any response text:
**Step 1 — Orient via State Hub**
```
get_domain_summary("markitect")
```
Note: active workstreams, blocking decisions, recent progress, SBOM status.
**Step 1b — Check the agent inbox**
```
get_messages(to_agent="marki-docx", unread_only=True)
```
Mark messages read with `mark_message_read(message_id)`. Act on any coordination requests before proceeding.
**Step 2 — Scan local workplans**
```bash
ls workplans/ # or Glob(pattern="workplans/**/*.md")
```
For each file with `status: active`, extract pending `todo` / `in_progress` tasks.
**Step 3 — Present orientation**
Output a concise brief:
1. **Active workstreams** for `markitect` domain — title, task counts, blocking decisions
2. **Pending tasks** — from local `workplans/` + state hub tasks with `[repo:marki-docx]`
3. **Goal guidance** — if `goal_guidance` is present in the summary:
- `needs_workplan`: surface as top suggested action — create workplan file + workstream
- `alignment_warnings`: name the misaligned workstream and flag it
4. **Suggested next action** — highest-priority open item
5. **SBOM status**`last_sbom_at` set? If not, note it as a gap
If no workstreams exist → follow **First Session Protocol** below.
### During work:
- `record_decision()` — any decision affecting direction or dependencies
- `add_progress_event()` — milestones, blockers, insights
- `resolve_decision()` — once a decision is made
### On session end:
```python
add_progress_event(
summary="<what was accomplished or decided>",
event_type="note|milestone|blocker",
topic_id="5571d954-0d30-4950-980d-7bcaaad8e3e2",
workstream_id="<id if applicable>"
)
```
> **Design boundary:** The State Hub is a *read model*. Two write operations are
> permanently sanctioned: **Resolving Decisions** and **Suggesting Next Steps**.
> Bootstrap tools (`create_workstream`, `create_task`) are First Session Protocol only.
> Work items originate as files in this repo (ADR-001), not in the hub alone.
---
## Repo Boundary Rule
This agent is responsible for files **in this repo only**.
- Do **not** write files or commit in any other repository
- Work identified for another repo → create a state hub task with `[repo:<slug>]` in the title
- Work identified for an upstream package → create a contribution artefact in `contrib/`
---
## First Session Protocol
Triggered when `get_domain_summary("markitect")` shows **no workstreams** linked to `marki-docx`.
**Step 1 — Read the specs**
- `specs/MarkiDocxProductRequirementsDocument_v0.1.md`
- `specs/MarkiDocxFunctionalRequirementsSpecification_v0.2.md`
- `specs/MarkiDocxUseCaseCatalog_v0.1.md`
- Scan the repo root for any existing code or further docs
**Step 2 — Survey the canon**
- `~/the-custodian/canon/projects/markitect/project_charter_v0.1.md`
- `~/the-custodian/canon/projects/markitect/roadmap_v0.1.md`
**Step 3 — Propose workstreams to Bernd**
Propose 13 workstreams — coherent strands of work lasting weeks to months, anchored
to a roadmap phase. **Wait for approval before creating anything.**
**Step 4 — Create workplan file first, then DB record (ADR-001)**
```
workplans/MRKD-WP-0001-<slug>.md ← write this first
```
Then register:
```python
create_workstream(
topic_id="5571d954-0d30-4950-980d-7bcaaad8e3e2",
title="...", owner="marki-docx", description="..."
)
create_task(workstream_id="<id>", title="...", priority="high|medium|low")
```
**Step 5 — Record the setup**
```python
add_progress_event(
summary="First session: structured marki-docx work into N workstreams, M tasks",
event_type="milestone",
topic_id="5571d954-0d30-4950-980d-7bcaaad8e3e2",
detail={"workstreams": [...], "tasks_created": M}
)
```
---
## Workplan Convention (ADR-001)
Work items MUST originate as files in this repo before being registered in the hub.
**File location:** `workplans/MRKD-WP-NNNN-<slug>.md`
**Required frontmatter:**
```yaml
---
id: MRKD-WP-NNNN
type: workplan
domain: markitect
repo: marki-docx
status: active|done|paused
state_hub_workstream_id: <uuid>
created: YYYY-MM-DD
updated: YYYY-MM-DD
---
```
**Task blocks (embedded in the workplan file):**
```markdown
## Task Title
```task
id: MRKD-WP-NNNN-T01
status: todo
priority: high
state_hub_task_id: <uuid>
```
```
After writing or modifying workplan files, run:
```bash
cd ~/the-custodian/state-hub && make fix-consistency REPO=marki-docx
```
This syncs task blocks → DB. Without it, the dashboard shows 0 progress.
---
## Contribution Tracking
Track upstream contributions in `contrib/`:
```
contrib/
bug-reports/ # br-YYYY-MM-DD--org--repo--slug.md
feature-requests/ # fr-YYYY-MM-DD--org--repo--slug.md
extension-points/ # EP-MRKD-NNN--org--repo--slug.md
upstream-prs/ # upr-YYYY-MM-DD--org--repo--slug.md
```
Templates: `~/the-custodian/canon/standards/contrib-templates/`
---
## SBOM
Re-run the SBOM after any dependency change (new package added/removed/upgraded in `pyproject.toml`).
The ops-bridge `ingest_sbom_tool` requires the lockfile to be accessible from the bridge machine.
Use a `requirements.txt` generated via:
```bash
pip list --format=freeze | grep -E "^(python-docx|PyYAML|typer|rich|mistune|fastapi|uvicorn|mcp|pytest|pytest-cov|ruff|mypy|types-PyYAML|httpx|pydantic|click|starlette|anyio|httpcore|certifi|h11|sniffio|idna)=" | sort > requirements.txt
```
Then either:
- Run locally if API is accessible: `cd ~/the-custodian/state-hub && make ingest-sbom REPO=marki-docx SCAN=1 REPO_PATH=/home/tegwick/marki-docx`
- Or via MCP `ingest_sbom_tool` once `host_paths` mapping is configured for `marki-docx` in the custodian
---
## Ralph Loop — Workplan-Tied Usage
**Rule: always use `/ralph-workplan` instead of `/ralph-loop` directly.**
```
/ralph-workplan workplans/<ID>-<slug>.md [--max-iterations 20]
```
This skill guards against runaway loops:
1. **Refuses to start** if the workplan `status` is already `done`
2. **Self-retires** — re-reads the workplan file each iteration; outputs `<promise>HEUREKA</promise>` the moment all tasks are `done`
3. Always sets `--completion-promise HEUREKA` and a bounded iteration count
**Never** start a ralph loop with a raw static implementation prompt. A static prompt
has no completion awareness and will loop forever even after the work is done.
---
## Quick Reference
- MCP tool reference: `~/the-custodian/state-hub/mcp_server/TOOLS.md`
- ADR-001 (workplan convention): `~/the-custodian/canon/architecture/adr-001-workplans-as-repo-artefacts.md`
- Contribution convention: `~/the-custodian/canon/standards/contribution-convention_v0.1.md`
- Release process: `docs/release-process.md`
- Changelog: `CHANGELOG.md`
# marki-docx — Claude Code Instructions
@SCOPE.md
@.claude/rules/repo-identity.md
@.claude/rules/session-protocol.md
@.claude/rules/first-session.md
@.claude/rules/workplan-convention.md
@.claude/rules/stack-and-commands.md
@.claude/rules/architecture.md
@.claude/rules/repo-boundary.md
@.claude/rules/credential-routing.md
@.claude/rules/agents.md

View File

@@ -1,7 +1,7 @@
---
id: MRKD-WP-0001
type: workplan
domain: markitect
domain: communication
repo: marki-docx
status: done
state_hub_workstream_id: de855681-7ce0-4ace-b283-ec61f7557066

View File

@@ -1,7 +1,7 @@
---
id: MRKD-WP-0002
type: workplan
domain: markitect
domain: communication
repo: marki-docx
status: done
state_hub_workstream_id: 6a7b5627-7593-4713-8e56-94c4ab3ff838

View File

@@ -1,7 +1,7 @@
---
id: MRKD-WP-0003
type: workplan
domain: markitect
domain: communication
repo: marki-docx
status: done
state_hub_workstream_id: b04fe706-6e4e-48a8-b6c1-194d9e308215

View File

@@ -1,7 +1,7 @@
---
id: MRKD-WP-0004
type: workplan
domain: markitect
domain: communication
repo: marki-docx
status: done
state_hub_workstream_id: 91d06c92-caa8-42fc-b6d4-82340f1bed4f

View File

@@ -1,7 +1,7 @@
---
id: MRKD-WP-0005
type: workplan
domain: markitect
domain: communication
repo: marki-docx
status: done
state_hub_workstream_id: 2ef47f11-d828-436d-8955-c58e13c50752

View File

@@ -1,7 +1,7 @@
---
id: MRKD-WP-0006
type: workplan
domain: markitect
domain: communication
repo: marki-docx
status: done
state_hub_workstream_id: 7e255145-8d18-4f22-b1ca-31f02944b890

View File

@@ -1,7 +1,7 @@
---
id: MRKD-WP-0007
type: workplan
domain: markitect
domain: communication
repo: marki-docx
status: done
state_hub_workstream_id: 61701224-0813-4258-9308-025bcec41780