@bonesofspring/ai-rules 0.2.84 → 0.2.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/docs/PRESET-CONTRIBUTION.md +19 -10
  3. package/docs/TEAM-DB.md +76 -3
  4. package/docs/openapi/team-db.v1.json +7069 -5895
  5. package/package.json +5 -2
  6. package/presets/_shared/ai-local/scripts/team-db-api.mjs +253 -15
  7. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +310 -4
  8. package/presets/_shared/ai-local/scripts/team-db-project.mjs +733 -8
  9. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +44 -0
  10. package/presets/_shared/ai-local/scripts/team-db.mjs +43 -3
  11. package/presets/claude/next/agents/build-verifier.md +2 -1
  12. package/presets/claude/next/agents/feature-developer.md +1 -1
  13. package/presets/cursor/next/agents/build-verifier.md +2 -1
  14. package/presets/cursor/next/agents/feature-developer.md +1 -1
  15. package/presets/mavis/next/adapter-map.json +1 -1
  16. package/presets/mavis/next/agents/build-verifier.md +2 -1
  17. package/presets/mavis/next/agents/feature-developer.md +1 -1
  18. package/presets/opencode/next/adapter-map.json +1 -1
  19. package/presets/opencode/next/agents/build-verifier.md +2 -1
  20. package/presets/opencode/next/agents/feature-developer.md +1 -1
  21. package/presets/opencode/plugins/task-status/README.md +1 -1
  22. package/presets/opencode/plugins/task-status/deepseek.ts +13 -3
  23. package/presets/opencode/plugins/task-status/task-view.ts +4 -1
  24. package/presets/opencode/plugins/task-status/tui.tsx +4 -6
  25. package/presets/opencode/plugins/task-status/types.ts +5 -1
  26. package/presets/zcode/next/adapter-map.json +1 -1
  27. package/presets/zcode/next/agents/build-verifier.md +2 -1
  28. package/presets/zcode/next/agents/feature-developer.md +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.86
4
+
5
+ ### Project entity: registry, migration 0011, seven routes, derived task attribution
6
+
7
+ - **A project record groups repositories n:m.** `team/project-registry.json` (`{version: 1, projects[], links[]}`) is the local-only, git-ignored definition of record, mirroring the repository registry: deterministic serialization, `E_PROJECTS_PARSE` on an unknown key, a duplicate id, or a link naming an unknown endpoint, an absent file an empty valid store, and one lock-guarded verb family — `team-db.mjs projects put|delete|link|unlink|list|project` under `.project-registry.lock` (5 s, `E_PROJECTS_BUSY` → 503 `E_BUSY`), kill-switch-guarded except `list`. Membership rides the pair verbs and never moves the record `revision`. (ADR 0008; change-set `2026-11-23-project-entity-repository-links`.)
8
+ - **Migration `0011-project-registry`** adds `projects` and `project_repositories` (STRICT, `PRIMARY KEY (project_id, repository_id)`, both FKs `ON DELETE CASCADE`, no `CHECK` on `status`), moves `SCHEMA_VERSION` to 11, and keeps `0009`/`0010` byte-identical. The rebuild reproduces both tables from the file alone; `repositories delete` removes the deleted repository's project links in the same child (nested `.repositories.lock` → `.project-registry.lock`) and `RepositoryDeleteResult` gains required `membersRemoved` — the resurrection guard.
9
+ - **Seven operations on three paths.** `GET|POST /api/v1/projects`, `GET|PUT|DELETE /api/v1/projects/{id}`, `POST|DELETE /api/v1/projects/{id}/repositories/{repositoryId}`: reads answer `ProjectSummary` (record + ordered `repositories[]`), writes answer `Project`, membership returns the updated summary read from the projection in the same child, a project with N members refuses `DELETE` with `409 E_PROJECT_IN_USE` and `details.memberRepositories = N`, and `force` removes memberships only. The contract pin moves as one block: 60 operations, 45 paths, 90 schemas, 60 served routes, 22 mutating routes (`check-team-db-contract.mjs --write` regenerated the checked-in document).
10
+ - **Derived task attribution.** `GET /api/v1/tasks?project=<id>` mirrors `?repository=` through one `TASK_PROJECT_FILTER` EXISTS fragment at slot `?11`, included by `listTasks` and `countTasks` only: a task belongs to a project iff it is linked to a member repository; a repository in several projects lists its tasks on all of them; `unknown`/`ambiguous` verdict tasks appear on none; a well-shaped unknown id is an empty page.
11
+ - **Engine suites** `test-team-db-{schema,project,api,concurrency}` cover the migration from empty v0 and from a v10 fixture, registry round-trip/CAS/refusals, the delete guard 0/1/many + force, rebuild equality, all seven routes, the attribution cases (paging == count), lock serialization, the nested-lock cleanup and the dangling-link refusal.
12
+
13
+ ## 0.2.85
14
+
15
+ ### The structure composite keeps the preset checks; the tooling's own 80 suites get their own entry point
16
+
17
+ - **The composite stopped running its own regression suite.** `check-preset-structure.sh` interleaved two tiers: 54 preset checks and 80 `test-*` suites that guard the preset tooling. 93 % of the 1780.9 s release rung was the second tier. The composite now runs the 54 checks only — measured 66.8 s, 105.59 s and 120.24 s on one tree, so the 1780.9 s rung becomes roughly two minutes — and `--list` prints those 54 labels. The 80 blocks moved verbatim, in their original order, to `scripts/run-tooling-tests.sh` behind `yarn test:tooling` (80 suites, 1285.8 s, one exit code). Nothing was skipped or reordered: the two skip guards travel with their blocks, and `scripts/test-structure-tier-partition.mjs` pins the partition — 54 ⊎ 80 = the 134 labels the composite used to print, disjoint, with each label's tier fixed.
18
+ - **Known failures stay declared on the side that runs them.** All five entries in `scripts/_lib/structure-known-failures.json` are test-tier labels, so the composite matches none of them: it prints `Result: OK (all hard gates passed)` and one `NOTE: 5 allowlisted suite(s) belong to the test tier (yarn test:tooling)` instead of five false `no longer fails — remove it` warnings. The `Result: OK (… 5 known failure(s) allowlisted …)` line now comes from `yarn test:tooling`, which carries the same allowlist loader and the same aggregate. A row that is in neither tier is still warned about, so deleting a check-tier entry by mistake is not silent.
19
+ - **The release gate reports four phases.** `release-gate.sh` runs `preset-structure`, `tooling-tests`, `ai-local-tests` and `product-specs-strict`, each with its own `{label, exit, seconds}` row: a red tooling suite fails the release without hiding a green preset tier. `run_phase` and the report keys are unchanged, so older reports stay readable. `AI_RULES_SKIP_HOOK_TESTS` / `AI_RULES_SKIP_PACK_TESTS` still honoured by the runner and still refused in a release run.
20
+ - **The tooling tier is locked and PR-gated.** `test:tooling` runs through `run-locked.mjs` (`--label test:tooling`), the same `preset-tree-lock` the composite holds today, so a suite never reads `presets/**` while `fix:generated` rewrites it; a direct `bash scripts/run-tooling-tests.sh` now says out loud that it holds no lock. CI gains a `tooling-suites` job whose condition comes from `check-preset-delta.mjs` (`ci-tooling-tier-gate.sh`): it runs the 80 suites only when the change-set touches `preset-tooling`, `preset-generator`, `preset-install`, `preset-engine` or `team-db`. A prose-only `preset-content` change does not: the 54-check structure job covers that diff, and `yarn release:gate` still runs the 80 before a tag. A skip is written to the job summary instead of passing silently. The `check` job's inert `AI_RULES_SKIP_HOOK_TESTS` was dropped — the composite holds no hook blocks any more.
21
+ - **A preset-content edit names the gates that read the changed file.** `check-preset-delta.mjs` keeps a six-gate floor (twin map, twin drift, generated drift, token budget, leakage, frontmatter) and adds a path slice for agents, hooks, commands/skills, next rules, the router, plan, goal, language, or prompt. Semantic parity runs only when `feature-delivery-workflow` or `reference-features` changes. A hook edit also names hook-body-parity and the pause, stale-attempt, and resume-blocked suites. A checker edit runs that checker and its paired suite. `presets/cursor/next` and root `.cursor` name `check-dogfood-cursor`. `release:gate` is listed only for a `package.json` or `CHANGELOG.md` edit. This repository's app gates do not name `yarn test:e2e`. The structure composite drops the authoring-advisory and product-specs WARN rows (52 labels); strict product-specs stays on `yarn release:gate`. `validation-report.md` must contain `## AC evidence`. A hook edit also names chain-hook coverage and hook-token lock, a router edit names parallel-plan, and preset prose names hard i18n. `test-cli-init-clean` stays on install and generator changes. `check-task-repositories` runs when its script, its test, `repositories.json`, or a `pipeline.json` changes. `yarn preset:loop` is `fix:generated` then `check:classified`, which runs that list (or `check:fast` when it is empty) and does not run release or app gates. A stale allowlist row exits 1. `check:fast` includes twin map and leakage. `cli-mcp-merge` expects the shipped `.minimax` skills and hooks.
22
+
3
23
  ## 0.2.84
4
24
 
5
25
  ### A 25-minute gate that stops at the first failure, names known ones, and survives two runs at once
@@ -174,7 +174,7 @@ Summary:
174
174
  - [ ] Twin drift: after editing a Claude `commands/**` or `skills/**` file, `node scripts/check-preset-twin-drift.mjs` passes — mirror the change in the Cursor twin (delta and divergence unchanged) or record a deliberate divergence with `--update`. A deliberate divergence that **raises** an allowance needs `--update --widen`; dropping a baseline row needs `--update --prune`. A plain `--update` refuses both.
175
175
  - [ ] Generated trees regenerated (`generate-claude.mjs` + `generate-mavis.mjs` + `generate-opencode.mjs` + `generate-zcode.mjs`, or `yarn fix:generated`) and CLI goldens recaptured (`capture-cli-golden.mjs`) after any preset-installed file changes
176
176
 
177
- Validation: `yarn check:task <slug>` (or `yarn check:changed` on a clean tree) + the `preset-pr-checklist` rule; the full composite runs in `yarn release:gate`. CI workflows: `preset-structure.yml` (`check`, `hooks`, `ai-local-engine-tests`), `platform-smoke.yml` (3-OS smoke: `init multi`/`update`/`doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval), and `release-gate.yml` (manual `yarn release:gate` run + report artifact).
177
+ Validation: `yarn check:task <slug>` (or `yarn check:changed` on a clean tree) + the `preset-pr-checklist` rule; the full composite runs in `yarn release:gate`. CI workflows: `preset-structure.yml` (`classify`, `check`, `tooling-suites`, `hooks`, `ai-local-engine-tests`), `platform-smoke.yml` (3-OS smoke: `init multi`/`update`/`doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval), and `release-gate.yml` (manual `yarn release:gate` run + report artifact).
178
178
 
179
179
  ## Release order
180
180
 
@@ -406,6 +406,12 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
406
406
 
407
407
  ## Dogfood & structure scripts (this monorepo)
408
408
 
409
+ Every gate in this table renders through the green/red output contract: one `ok <unit> (…)` line on
410
+ stdout, or a pointer `FAIL <unit>: <file>[:<line>]: expected X, got Y` plus a capped list and a `re-run:`
411
+ line. `scripts/lib/gate-output.mjs` (node) and `scripts/lib/gate_output.py` (the five `python3` heredocs)
412
+ own the line and block shapes, pinned byte-for-byte by `scripts/lib/gate-output.golden.json`; a new gate
413
+ uses the carrier instead of printing.
414
+
409
415
  | Script / npm | Purpose |
410
416
  |--------------|---------|
411
417
  | `yarn fix:generated` | Regenerate every released generated platform and recapture the CLI goldens it owns (`cursor/next`, `claude/next`, and every Mavis/OpenCode/ZCode stack). Claude's stack set is the Cursor stack directories, not the OpenCode contract. Run after changing Cursor SoT, before fail-only checks. Capture a non-`next` Cursor/Claude golden explicitly with `node scripts/capture-cli-golden.mjs <cursor|claude> <stack>`; never hand-edit one. Dogfood sync remains separate. |
@@ -427,7 +433,8 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
427
433
  | `scripts/check-preset-self-review-contract.sh` / `yarn check:preset-structure` | **FAIL** if the producer-side self-review / context-hygiene contract is absent: the core `_shared/core/quality/self-review-and-context-hygiene.md` tokens (G0 non-vacuous guard), the `<!-- shared-core: quality/self-review-and-context-hygiene.md -->` marker on `task-analyst` / `feature-developer` / `build-verifier` (×10) and on `debugger` / `code-reviewer` where present (skip-if-absent → `mcp-ts`), the `Self-review` + `re-anchor` tokens on every orchestrator rule, `Self-review` in `team/README.md` + `commands/task.md`, and leakage-free core + docs; **refuses vacuous PASS** when the iteration set is empty. Also holds two prose contracts: the canonical self-learning-loop sentence must not be followed by unsanctioned prose (an allowlist of sanctioned clauses; the tail is bounded by the carrier's **section**, not by a blank line, so prose moved one paragraph down still fails — a tail in a later `## ` section is out of scope), and every retro carrier (command, skill, rule) must state `finding_category`. Wired into `check-preset-structure.sh` next to `goal-contract`; fixture `test-preset-self-review-contract-fixtures.mjs`. |
428
434
  | `scripts/check-anti-hallucination-coverage.mjs` | **FAIL** when the shared contract, a Cursor load-line embed, a writer stack floor, or a generated Rules-to-load stem is missing. Writer roles are `implementer`, `unit-test`, `e2e`, `qa`, and `reviewer` (`code-reviewer` loads `STACK_FLOOR_STEMS` plus the contract). `/task` and the orchestrator must not name a floor stem. Does not scan consumer `app/**` and does not call Context7. Fixture `test-anti-hallucination-coverage.mjs` deletes `anti-hallucination-contract` from `next.reviewer` in memory and expects FAIL mentioning `next` and `reviewer`. Wired into `check-preset-structure.sh` immediately after `check-claude-agent-blocks.mjs`. |
429
435
  | `presets/_shared/ai-local/scripts/check-write-scope.mjs` | Read-only post-step audit: compares the actual changed paths with the current `pipeline.json` step's `writeScopes` and labels each path `declared`, `derived` (task folder, engine mirror, generated platform tree/golden/hook, dogfood tree, adapter map), or `out-of-scope`, with the source named. Shipped to consumers as `.ai.local/scripts/check-write-scope.mjs` (`ENGINE_SCRIPTS`). `--slug <slug> [--step <id>] [--base <ref>] [--root <project>] [--paths a,b] [--save-baseline] [--json]`. Baseline resolution: `--paths`, then `--base <ref>`, then the step baseline written by `--step <id> --save-baseline` (every dirty path with its content hash, plus the files its declared `writeScopes` cover — passed as `--paths` — so a step armed on a clean tree still owns its surface), then `HEAD` (whole uncommitted change-set, reported with a notice). Exit `1` for an out-of-scope path on an implementation step, `0` for a reviewer/verifier step (advisory), `2` on a usage/config error, `3` (SKIP) when the pipeline predates step ids or `writeScopes` and is therefore not auditable. Fixture `test-write-scope.mjs`; wired into the build-verifier and code-reviewer prompts, never a hook. |
430
- | `scripts/check-preset-structure.sh` / `yarn check:preset-structure` | Low-level orchestrator: twin-map + token-budget + leakage + shared-core drift + anti-hallucination coverage + rule-eval (**all hard**; drift via `AI_RULES_DRIFT_FAIL=1`). Invoked by `yarn release:gate` and CI; not a feature-task gate. |
436
+ | `scripts/check-preset-structure.sh` / `yarn check:preset-structure` | Low-level orchestrator: twin-map + token-budget + leakage + shared-core drift + anti-hallucination coverage + rule-eval (**all hard**; drift via `AI_RULES_DRIFT_FAIL=1`). Runs the 54 preset checks only (~2 min); `--list` prints their labels. Invoked by `yarn release:gate` and CI; not a feature-task gate. |
437
+ | `scripts/run-tooling-tests.sh` / `yarn test:tooling` | The tooling self-test tier: the 81 `test-*` suites that guard the preset tooling itself (preset fixtures, CLI install, team-db, hook lifecycle, contract guards, tooling core). One command, one exit code, ~21 min; `--list` prints the 81 labels. Reached through `run-locked.mjs --label test:tooling`, so it holds the same `preset-tree-lock` as the composite; a direct `bash` run warns that it holds none. Its failures are downgraded only by `scripts/_lib/structure-known-failures.json`, and it is the second phase of `yarn release:gate`. CI runs it from the `tooling-suites` job when the change-set touches the tooling domains (`ci-tooling-tier-gate.sh`). |
431
438
  | `scripts/check-product-specs.sh` / `yarn check:product-specs` | Opt-in consumer tree check: frontmatter v1 keys + required body headings on `docs/specs/**` (bash; does **not** run JSON Schema). Ships in the npm package `files` (`scripts/`). **WARN** by default; **`--strict`** exits non-zero. |
432
439
  | `yarn check:product-specs:dogfood` | Same script against monorepo `dogfood/mcp-ts-sample`. Soft WARN inside the composite + CI step (`continue-on-error`); the release gate runs `--strict`; not a hard consumer CI gate. |
433
440
  | `scripts/check-rule-eval.mjs` / `yarn check:rule-eval` | **Hard gate** inside `check-preset-structure.sh`: validates Incorrect/Correct pairs + `impact:` on **next-only** golden stems (`eval/next/manifest.json`). Backend / ios / php-hexagonal / php-laravel stems are out of scope until a stack adds `eval/<stack>/`. |
@@ -439,12 +446,12 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
439
446
 
440
447
  The ladder, one composite run per change-set:
441
448
 
442
- 1. **Targeted (seconds):** `node scripts/check-preset-twin-drift.mjs`, `check-claude-agent-parity.mjs`, `test-cli-init-clean.mjs`, `test-generated-cache.mjs` — a source edit that is not mirrored in the Claude twin fails here, not 25 minutes later.
449
+ 1. **Targeted (seconds):** `node scripts/check-preset-twin-drift.mjs`, `check-claude-agent-parity.mjs`, `test-cli-init-clean.mjs`, `test-generated-cache.mjs` — a source edit that is not mirrored in the Claude twin fails here, not after the ~2-minute composite, and not 21 minutes into `yarn test:tooling`.
443
450
  2. **Regenerate:** `yarn fix:generated` after a source or generator edit; it rewrites every platform stack and the CLI goldens.
444
451
  3. **Classified:** `yarn check:changed` — the classifier names the gates the change-set affects.
445
- 4. **Composite, once:** `bash scripts/check-preset-structure.sh` after the last edit. `--fail-fast` stops at the first failure the allowlist does not declare (a known one is printed and the sweep continues), `--list` prints all 134 labels, and a single gate is its own script under `scripts/` — run that directly rather than filtering the composite.
452
+ 4. **Composite, once:** `bash scripts/check-preset-structure.sh` after the last edit. `--fail-fast` stops at the first failure the allowlist does not declare (a known one is printed and the sweep continues), `--list` prints the 54 preset checks, and a single gate is its own script under `scripts/` — run that directly rather than filtering the composite. The 81 tooling self-test suites (`test-*`) run from `yarn test:tooling` (~23 min, one command, one exit code); `--list` on `scripts/run-tooling-tests.sh` prints those 81 labels. The union of the two label sets is the 135 the two entry points now carry (134 before `structure-output-contract fixtures` was added), pinned by `test-structure-tier-partition.mjs`.
446
453
 
447
- The composite exits 0 when every failure is already listed in `scripts/_lib/structure-known-failures.json` (each entry carries owner, reason, and date); a known failure that starts passing prints a stale-entry warning. A malformed allowlist exits 2. Two runs may fill the same cache key at once — `generated-cache.mjs` publishes with one rename — while the preset-tree lock still keeps a gate away from a running `fix:generated`.
454
+ The composite exits 0 when every failure is already listed in `scripts/_lib/structure-known-failures.json` (each entry carries owner, reason, and date). A known failure that starts passing prints a stale-entry warning and the aggregate exits 1, so the row cannot hide the next regression. Both entry points read that file, but each tier reports only its own labels: the composite prints one `NOTE:` line for an allowlisted suite that belongs to the tooling tier, and `yarn test:tooling` owns the stale-entry warning for its 81. A malformed allowlist exits 2. Two runs may fill the same cache key at once — `generated-cache.mjs` publishes with one rename — while the preset-tree lock still keeps a gate away from a running `fix:generated`.
448
455
 
449
456
  Run from `packages/ai-rules/`:
450
457
 
@@ -457,19 +464,21 @@ yarn check:changed
457
464
  yarn check:fast
458
465
  # release only, from the repo root:
459
466
  yarn release:gate
467
+ # release only, the tooling self-test tier on its own:
468
+ yarn test:tooling
460
469
  ```
461
470
 
462
471
  Iteration versus release:
463
472
 
464
473
  - **`yarn check:task <slug>`** — the task-scoped classifier (`check-preset-delta.mjs --since-task <slug>`). It reads `.ai.local/team/.write-scope/<slug>/*.json`, unions the step baselines, and returns only this task's change-set; `--save-baseline` snapshots an inline task before its first write. A missing baseline falls back to `--base HEAD` with a warning.
465
474
  - **`yarn check:changed`** — the repo-wide classifier (`check-preset-delta.mjs --base HEAD`, or `--paths a,b`). Use it on a clean tree or pass the task paths explicitly; otherwise earlier uncommitted batches are attributed to this task. It prints `affected loop gates` and a separate `release-only gates` line.
466
- - **`yarn check:fast`** — the ~50-second fallback gate (`check-preset-fast.sh`: generated drift, twin drift, token budget, frontmatter, consumer links, next attached budget, OpenCode platform contract self-test); run it only when the classifier names no gate. `test-cli-init-clean` stays in the delta gates and CI.
467
- - **`yarn release:gate`** — the full release gate: `check-preset-structure.sh` with the hook suites, `test:ai-local`, and the strict product-specs dogfood. Run it alone on the release commit before a tag.
468
- - **`yarn check:preset-structure`** — the low-level composite; CI and `release:gate` call it. Do not run it in a feature task.
475
+ - **`yarn check:fast`** — the fallback gate (`check-preset-fast.sh`: the content floor — twin map, twin drift, generated drift, semantic parity, token budget, leakage, frontmatter — plus frontmatter dogfood, consumer links, next attached budget, and the OpenCode platform-contract self-test). Run it only when the classifier names no gate. A `preset-content` diff names that floor plus the path slice for the file that changed: hooks also name chain-hook coverage and hook-token lock, a router edit names parallel-plan, and preset prose names hard i18n. `test-cli-init-clean` stays on `preset-install` / `preset-generator` and in `yarn test:tooling`, not on a rule edit.
476
+ - **`yarn release:gate`** — the full release gate, four phases: `preset-structure` (the 54 preset checks), `tooling-tests` (`yarn test:tooling`, the 81 tooling suites — `AI_RULES_SKIP_HOOK_TESTS` / `AI_RULES_SKIP_PACK_TESTS` are refused), `test:ai-local`, and the strict product-specs dogfood. Each phase writes its own `exit`, so a red tooling suite fails the release without hiding a green preset tier. Run it alone on the release commit before a tag.
477
+ - **`yarn check:preset-structure`** — the low-level composite; CI and `release:gate` call it. It runs the preset tier only. Do not run it in a feature task.
469
478
 
470
479
  `check-generated-drift` caches generated trees in the OS temp directory, keyed by a digest of the Cursor/`_shared` sources and the generator libraries. A source or generator edit misses the cache and regenerates; the cache is disposable and never hides drift.
471
480
 
472
- CI: [`.github/workflows/preset-structure.yml`](../../../.github/workflows/preset-structure.yml) runs the orchestrator on PRs touching `packages/ai-rules/**`. The other workflows in `.github/workflows/`: `platform-smoke.yml` (3-OS smoke: `init multi`, `update`, `doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval via `scripts/check-rule-eval.mjs`), and `release-gate.yml` (manual `yarn release:gate` run on a chosen ref; uploads the `.release-gate/` report as an artifact).
481
+ CI: [`.github/workflows/preset-structure.yml`](../../../.github/workflows/preset-structure.yml) runs the 54 preset checks on PRs touching `packages/ai-rules/**`; its `classify` job reads the change-set domains from `check-preset-delta.mjs` and the `tooling-suites` job runs `yarn test:tooling` only when they touch `preset-tooling`, `preset-generator`, `preset-install`, `preset-engine`, or `team-db` (a prose-only `preset-content` change stays on the 54-check job; a skip is announced in the job summary). The other workflows in `.github/workflows/`: `platform-smoke.yml` (3-OS smoke: `init multi`, `update`, `doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval via `scripts/check-rule-eval.mjs`), `team-tasks-ui.yml` (lint, type-check, and unit tests for `apps/team-tasks-ui`; no e2e), and `release-gate.yml` (`yarn release:gate` on a `v*` tag or a chosen ref; uploads the `.release-gate/` report as an artifact).
473
482
 
474
483
  ---
475
484
 
@@ -478,7 +487,7 @@ CI: [`.github/workflows/preset-structure.yml`](../../../.github/workflows/preset
478
487
  `yarn fix:generated` deletes and rebuilds every platform stack, so the writer and every gate that reads `presets/**` take one exclusive lock (`scripts/lib/preset-tree-lock.mjs`; lock directory `.preset-tree-lock/` with `owner.json` pid + token). From `packages/ai-rules/`:
479
488
 
480
489
  ```bash
481
- yarn preset:loop # fix:generated && check:changed && check:fast, in series
490
+ yarn preset:loop # fix:generated && check:classified, in series
482
491
  yarn fix:generated --wait 600000 # opt in to waiting for a live holder
483
492
  ```
484
493
 
package/docs/TEAM-DB.md CHANGED
@@ -45,7 +45,8 @@ is excluded from the published tarball, and a consumer install skips it without
45
45
  envelope, or one stderr line on the CLI.
46
46
  - **Bounded mutations.** `POST /api/v1/sync` re-runs the projector and `DELETE
47
47
  /api/v1/tasks/{slug}` deletes one confirmed task (the folder first, then the rows); every
48
- other route is `GET`/`HEAD` apart from the four job writes and the three repository writes.
48
+ other route is `GET`/`HEAD` apart from the four job writes, the three repository writes and
49
+ the five project writes (create, update, delete and the two membership pairs).
49
50
  Each mutation runs as an asynchronous child process — the server never opens a writable
50
51
  connection, and the kill switch answers before a child is spawned. Job writes carry
51
52
  `application/json` and at most 64 KiB, run-now an absent body or `{}`; repository writes
@@ -481,6 +482,76 @@ cutoff is counted as legacy — the chain hook rewrites `status.json` on every s
481
482
  rewritten status never makes a legacy folder new. The slug named by `active-task.json` is
482
483
  excluded and printed, because its intake is still in flight; it is judged once the task closes.
483
484
 
485
+ ## Project registry
486
+
487
+ `team/project-registry.json` is **local-only and git-ignored**; it is the definition of record
488
+ for the project records and their n:m memberships:
489
+
490
+ ```json
491
+ {
492
+ "version": 1,
493
+ "projects": [ { "id": "emedcard", "name": "Медкарта", "description": null,
494
+ "status": "active", "revision": 1,
495
+ "createdAt": "…", "updatedAt": "…" } ],
496
+ "links": [ { "projectId": "emedcard", "repositoryId": "emedcard-web", "addedAt": "…" } ]
497
+ }
498
+ ```
499
+
500
+ `version` must be `1`; an unknown top-level key, an unknown record key, two records with one
501
+ id, a duplicate `(projectId, repositoryId)` pair, or a link naming an unknown project or
502
+ repository is a parse error (`E_PROJECTS_PARSE`) and the caller never writes over it. An
503
+ absent file is an empty valid store — `init` seeds nothing and nothing backfills from
504
+ `repositories.json`; an operator may hand-edit the file, and the reader is strict about
505
+ shapes and permissive about the `status` vocabulary. The writer serializes deterministically
506
+ (declared key order, projects by `id`, links by `(projectId, repositoryId)`, two-space indent,
507
+ one trailing newline); an unchanged rewrite performs no write.
508
+
509
+ One lock-guarded verb family serves the writes:
510
+
511
+ ```bash
512
+ node .ai.local/scripts/team-db.mjs projects put --file <path|-> [--dry-run]
513
+ node .ai.local/scripts/team-db.mjs projects delete <id> [--force] [--revision <n>]
514
+ node .ai.local/scripts/team-db.mjs projects link|unlink <projectId> <repositoryId>
515
+ node .ai.local/scripts/team-db.mjs projects list [--json]
516
+ node .ai.local/scripts/team-db.mjs projects project [--json]
517
+ ```
518
+
519
+ The order is kill switch (`list` still reads) → `.project-registry.lock` (5 s,
520
+ `E_PROJECTS_BUSY` / 503 `E_BUSY`) → read → validate and CAS → file write by temp file plus
521
+ rename → projection of the touched rows → release in `finally`. `status` is validated on
522
+ write (`active | archived`, 422 with `parameter: "status"`) and is not a SQL `CHECK`.
523
+ Membership never moves the record `revision`: the CAS token belongs to the record, and a
524
+ membership is one idempotent pair write under the lock. A project linked to N member
525
+ repositories answers `409 E_PROJECT_IN_USE` with `details.memberRepositories = N`;
526
+ `force=true` removes the record and only its membership rows in the same write and reports
527
+ `membersRemoved` — the member repositories and their tasks stay.
528
+
529
+ **Repository-delete cleanup.** Deleting a repository also removes its project links in the
530
+ same child: `repositories delete` holds `.repositories.lock` first and takes
531
+ `.project-registry.lock` second (always that nested order; project verbs never take the
532
+ repositories lock), filters the links, writes both files and projects both scopes, and
533
+ reports `membersRemoved` on `RepositoryDeleteResult`. This is the resurrection guard:
534
+ re-registering a deleted repository id never silently resurrects stale memberships.
535
+
536
+ The projection adds two tables through migration `0011-project-registry`: `projects` (the
537
+ record plus the inventory columns) and `project_repositories` (`PRIMARY KEY (project_id,
538
+ repository_id)`, both foreign keys `ON DELETE CASCADE`). A malformed file records its error
539
+ and tombstones nothing; `rm team.db* && node .ai.local/scripts/team-db.mjs init --rebuild`
540
+ reproduces both tables from the file alone.
541
+
542
+ Seven operations, three paths: `GET|POST /api/v1/projects`,
543
+ `GET|PUT|DELETE /api/v1/projects/{id}`, and
544
+ `POST|DELETE /api/v1/projects/{id}/repositories/{repositoryId}`. Reads answer
545
+ `ProjectSummary` — the record plus `repositories[]`, the member refs ordered
546
+ `name COLLATE NOCASE, id` (the count is `repositories.length`; nothing counts twice) —
547
+ writes answer `Project`, and both membership routes return the updated `ProjectSummary` so
548
+ the UI updates the section in place. The task list accepts `?project=<id>` mirroring
549
+ `?repository=`: a task belongs to a project iff it is linked to at least one member
550
+ repository (the derived attribution — no task field exists). A repository in several
551
+ projects lists its tasks on every such project page; tasks whose repository verdict is
552
+ `unknown`/`ambiguous` appear on no project page; a well-shaped unknown project id answers an
553
+ empty page, and an invalid shape is 422.
554
+
484
555
  ## Start or restart
485
556
 
486
557
  `/rr-scheduler-start` runs `node .ai.local/scripts/rr-scheduler-start.mjs`. `init` seeds that
@@ -770,8 +841,10 @@ document chunks at 1 MiB, exports at 5 MiB, parameterized SQL only, and no outbo
770
841
  `--allow-remote` also exposes the four job mutations — `POST /api/v1/jobs`,
771
842
  `PUT /api/v1/jobs/{id}`, `DELETE /api/v1/jobs/{id}`, and `POST /api/v1/jobs/{id}/run` —
772
843
  the three repository writes (`POST /api/v1/repositories`, `PUT /api/v1/repositories/{id}`,
773
- `DELETE /api/v1/repositories/{id}`), the confirmed task delete and the rescan to the named
774
- interface without authentication.
844
+ `DELETE /api/v1/repositories/{id}`), the five project writes (`POST /api/v1/projects`,
845
+ `PUT /api/v1/projects/{id}`, `DELETE /api/v1/projects/{id}`,
846
+ `POST|DELETE /api/v1/projects/{id}/repositories/{repositoryId}`), the confirmed task delete
847
+ and the rescan to the named interface without authentication.
775
848
  A job definition carries arbitrary `argv` and run-now enqueues it, so that surface
776
849
  executes operator-supplied commands as the API user; see `## Scheduled jobs`.
777
850