Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .claude/hooks/docs-sync-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# Stop hook: block finishing a session that changed src/ but no documentation.
# See docs/agents/docs-map.md for which pages each source file affects.

input=$(cat)

# Prevent an infinite block loop: if we already blocked once this stop, let it through.
if echo "$input" | grep -q '"stop_hook_active":true'; then
exit 0
fi

cd "$(dirname "$0")/../.." || exit 0

changed=$(git status --porcelain 2>/dev/null | awk '{print $NF}')
src_changed=$(echo "$changed" | grep -c '^src/.*\.php$')
docs_changed=$(echo "$changed" | grep -cE '^(docs/|README\.md|llms\.txt|CONTEXT\.md)')

if [ "$src_changed" -gt 0 ] && [ "$docs_changed" -eq 0 ]; then
echo "Docs sync check: this session has uncommitted changes under src/ but none under docs/, README.md, or llms.txt. Consult docs/agents/docs-map.md for the pages affected by the changed files and update them, or state explicitly in your reply why no documentation is affected (e.g. pure refactor with no behavior/signature change). Then finish." >&2
exit 2
fi

exit 0
14 changes: 14 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR/.claude/hooks/docs-sync-check.sh\""
}
]
}
]
}
}
9 changes: 9 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ jobs:
with:
node-version: 20
- run: npm install
- name: Use archived Debian packages for the PHP 8.0 image
if: matrix.php == '8.0'
run: |
docker build --tag wordpress:php8.0 - <<'DOCKERFILE'
FROM wordpress:php8.0
RUN sed -i 's|http://deb.debian.org|https://archive.debian.org|g; s|http://security.debian.org|https://archive.debian.org|g; /bullseye-updates/d' /etc/apt/sources.list \
&& printf 'Acquire::Check-Valid-Until "false";\n' > /etc/apt/apt.conf.d/99archive \
&& apt-get update
DOCKERFILE
- run: npx wp-env start
- run: npx wp-env run tests-cli --env-cwd=wp-content/wpify-model composer install --no-interaction
- run: npx wp-env run tests-cli --env-cwd=wp-content/wpify-model vendor/bin/phpunit
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
.phpdoc
/wordpress/
.phpunit.result.cache

# Claude Code local state (committed: settings.json, hooks/)
/.claude/settings.local.json
/.claude/worktrees/
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CLAUDE.md

## Documentation

User documentation lives in `docs/` (index: `docs/README.md`; flat agent index with one-line descriptions: `llms.txt`). The glossary in `CONTEXT.md` defines the terminology both code and docs must use. When writing code that *uses* this library (examples, tests, consuming projects), treat `docs/` as the source of truth for conventions — start from `llms.txt`.

**Docs-sync rule (hard requirement):** any change under `src/` that alters behavior, signatures, properties, attributes, defaults, or error messages requires updating the documentation pages mapped to the changed files in `docs/agents/docs-map.md` — in the same commit. New source files and new docs pages get a row added to that map. If a `src/` change genuinely affects no docs (pure internal refactor), state that explicitly when finishing. A Stop hook enforces this check.

## Agent skills

### Issue tracker
Expand Down
26 changes: 26 additions & 0 deletions CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# wpify/model — domain context

Ubiquitous language for this library. Documentation, code, issues, and agent output must use these terms exactly as defined; don't drift to synonyms.

## The rule

**Models hold the data, repositories talk to WordPress, the Manager wires them together.**

## Glossary

- **model** — a data class extending `Wpify\Model\Model` that holds one entity's data (one post, one term, one table row). Public typed properties, resolved lazily on first read. Models never query WordPress themselves.
- **repository** — a class extending `Wpify\Model\Repository` that reads and writes models: `get()`, `find()`, `create()`, `save()`, `delete()`. All WordPress/WooCommerce I/O lives in repositories.
- **the Manager** — `Wpify\Model\Manager`, the registry that maps each model class to its repository. Registers the 18 built-in repositories in its constructor; custom repositories are added via constructor arguments or `register_repository()`. Always written "the Manager".
- **source object** — the underlying WordPress/WooCommerce object a model wraps (`WP_Post`, `WP_Term`, `WP_User`, `WP_Comment`, `WP_Site`, `WC_Product`, `WC_Order`, or a table row object). Accessed via `$model->source()`.
- **source attribute** — a PHP attribute implementing `SourceAttributeInterface` placed on a model property to declare where its value comes from: `#[SourceObject]`, `#[Meta]`, `#[AccessorObject]`, `#[AliasOf]`, `#[Column]`, and the relation attributes.
- **property resolution** — the lazy `__get` flow: cached value → `get_{prop}()` accessor → source attribute → type coercion → cache. Specified in `docs/concepts/property-resolution.md`.
- **relation attribute** — a source attribute that resolves other models (e.g. `#[PostTermsRelation]`, `#[ManyToOneRelation]`, `#[ChildPostsRelation]`). All are read-only views except `#[PostTermRelation]`/`#[PostTermsRelation]`, which persist through `PostRepository::save()`.
- **built-in models** — the model/repository pairs shipped with the library (Post, Page, Attachment, Category, PostTag, Term, User, Comment, Site, Menu, MenuItem, Product, ProductCat, Order and order items). Not "core models".
- **custom table model** — a model whose properties carry `#[Column]` attributes, served by a repository extending `CustomTableRepository`, stored in a dedicated database table. Not "database model".
- **accessor method** — the `get_{prop}` / `set_{prop}` / `persist_{prop}` naming conventions on models: computed reads, write normalization, and custom save behavior respectively.

## Pointers

- Architecture decisions: `docs/adr/`
- User documentation: `docs/` (index in `docs/README.md`, agent index in `llms.txt`)
- Docs↔source mapping for keeping docs in sync: `docs/agents/docs-map.md`
Loading
Loading