Detailed reference for contextd. CLAUDE.md links here for material that doesn't need to be in the agent's hot-path instructions.
agents/ ← ENGINE (stack-agnostic, every workspace)
system-prompt.md, coding-rules.md, constraints.md
pipeline/ ← intent → retrieval → filter → validate
templates/ ← ENGINE — skeletons (workspace.md, service.md, pack.yaml, ...)
.claude/commands/ ← ENGINE — slash commands
packs/ ← PACKS (stack-specific, opt-in per workspace)
pack-event-driven/ ← Kafka/MQTT/DLQ
pack-web-api/ ← REST/GraphQL/gRPC
pack-frontend-react/ ← React/Next.js
pack-ai-app/ ← LLM apps
pack-agentic/ ← agent loops, tool use, MCP
pack-claude-plugin-dev/ ← build Claude Code plugins
pack-security/ ← AppSec + pentest combined
pack-qc/ ← QA + performance optimization
pack-product/ ← briefs/OKR/roadmap
pack-solo-builder/ ← non-tech expert workflow
... (see packs/README.md)
workspaces/
{ws}/ ← resolved from <cwd>/.contextd/config.json.workspace
workspace.md ← metadata + ## Packs opt-in
patterns-index.md ← per-workspace pattern lookup
platform/
contracts/ ← topic formats, API schemas — highest priority
patterns/ ← canonical implementations to reuse
architecture/ ← system topology
infrastructure/
domains/{domain}/ ← business rules, state machines
projects/{project}/ ← per-service docs, local overrides, ADRs
runbooks/ ← incident handling
decisions/ ← workspace ADRs
agents/ ← OPTIONAL — workspace overrides
knowledge_root is the canonical root field.
Legacy wiki_root in .claude/wiki.json, .Codex/wiki.json, and legacy global configs is accepted only as a migration adapter.
## Understanding
{Restate the task — include workspace name}
## Knowledge Mapping
{Which contracts, patterns, domain docs in {ws}/ are applied}
## Design
{Flow description before any code}
## Implementation
{Code}
## Edge Cases
{Failure scenarios handled}
## Assumptions
{Anything not in {ws}/ that was assumed — NEVER taken from another workspace}
Pack rules are active only when the codebase resolves that pack. Do not copy a summary list into this reference: it becomes stale and can accidentally loosen the canonical rules. Resolve and read, in order:
packs/{name}/pack.yamlfor scope, audiences, task types and components.- For manifest v3,
knowledge.md#Global Principlesplus matched component sections; for v2, the declaredagents/compatibility rule files. - For manifest v3, selected
pack.yaml#retrievalrows; for v2, selected rows inagents/pipeline/retrieval-map.md. scripts/rules.pyand the version-appropriate canonical knowledge catalog for documented/executable Layer-1 parity.
The canonical catalog, maturity model and selection guide are in
packs/README.md. Validate them with
contextd pack-validate --all --format text; use contextd explain to verify
that a task loads only the intended pack components.
When code changes, update the wiki of the active workspace. Keep both in sync.
| Change | Update |
|---|---|
| New reusable pattern | {ws}/platform/patterns/ + {ws}/patterns-index.md |
| New MQTT type (pack-event-driven on) | {ws}/platform/contracts/mqtt-topic-contract.md |
| New project service | {ws}/projects/{project}/services/ + knowledge-map.md |
| Architecture decision | {ws}/decisions/ (workspace) or {ws}/projects/{p}/decisions/ (project) |
| Repeated agent mistake (workspace-local) | {ws}/agents/constraints.md + {ws}/agents/pipeline/validator-rules.md (prefix ws-) |
| Repeated agent mistake (stack-wide) | v3 packs/{name}/knowledge.md + scripts/rules.py when deterministic (v2 constraints/validator compatibility files), prefix pack-{name}- |
| Repeated agent mistake (engine-wide) | agents/constraints.md + agents/pipeline/validator-rules.md |
| Onboard new stack | python scripts/scaffold-pack.py pack-{name} → v3 manifest + canonical knowledge |
| Production incident | {ws}/runbooks/ |
| Raw evidence (MCP/API/paste) | {ws}/evidence/ via /evidence-{ingest,analyze,qa,apply}. Solo-builder workspaces auto-use domain-analysis-prompts.md + qa-batch-non-tech.md |
| Onboard codebase / refresh platform from code | /code-analyze → evidence pipeline (source_type=code) → CORE-CODE prompts → /evidence-qa → /evidence-apply |
Use templates in templates/.
Concept files trong workspace theo OKF v0.2: YAML frontmatter bắt buộc type, khuyến nghị title/description. Mục đích: metadata đồng nhất để agent/tool parse, provenance (ai tạo, verified bởi ai) traceable, diffable trong version control.
Type set hiện tại (lint warning nếu type ngoài set): Contract, Pattern, Decision, Evidence, Runbook, Report, Tool, Service, Domain, Reference, Recipe, Brief, Requirement, Design.
Field mapping contextd → OKF:
| contextd | OKF |
|---|---|
{ws}/platform/contracts/*.md |
type: Contract |
{ws}/platform/patterns/*.md |
type: Pattern |
{ws}/decisions/*.md |
type: Decision, status: stable khi ACCEPTED (OKF status = lifecycle; ADR Status trong body giữ nguyên) |
{ws}/runbooks/*.md |
type: Runbook |
{ws}/evidence/qa/*/... |
type: Evidence + generated: { by, at } |
agents/*.md (engine rules) |
type: Reference (khi áp dụng) |
patterns-index.md, README.md, INDEX.md, _index.md |
index role — KHÔNG cần frontmatter (OKF reserve index.md/log.md; project giữ tên riêng) |
Quy tắc:
status∈draft | stable | deprecated(absent ⇒stable). Tool-spec dùng lifecycle riêng (draft|specced|building|done|shelved— pack constraint, không đổi).- Provenance:
generated: { by: <actor>, at: <ISO> },verified: [{ by, at }], actor conventionhuman:<id>/process:<id>/<agent>/<version>. - Per-claim attribution: footnote
[^id]trong body,idjoin vàosources[].id;resourcebắt buộc mỗi entry,idoptional (entry chỉ córesource, hoặc id không được cite trong body, đều hợp lệ). - Consumers KHÔNG reject unknown keys/types — OKF "tolerate unknown" (lint chỉ warning).
Concept files may add node_id, freshness, review_by, lifecycle, and a
typed relations list. contextd synapse compiles these fields into a
workspace-scoped contextd_synapse.v1 index. Missing fields remain backward
compatible: path-derived ID, active lifecycle, and unknown freshness.
The generated graph is not canonical storage. Workspace files remain the long-term governed knowledge source; task artifacts contain a context projection, while session history/checkpoints remain runtime state.
Enforcement: scripts/lint-wiki.py check frontmatter parseable, type non-empty, type ∈ set, status ∈ enum, mỗi sources[] entry có resource, footnote [^id] khớp sources[].id (id không cite trong body là hợp lệ) — tất cả warning, exit 0 mặc định (CI-friendly; --strict → exit 2 nếu muốn warnings-as-errors). File ngoài concept (index/config) và .claude/** (harness schema riêng) không bị check.