gentle-pi 0.11.3 → 0.12.0

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 (40) hide show
  1. package/README.md +12 -10
  2. package/assets/agents/jd-fix-agent.md +15 -0
  3. package/assets/agents/jd-judge-a.md +28 -0
  4. package/assets/agents/jd-judge-b.md +28 -0
  5. package/assets/agents/review-readability.md +29 -1
  6. package/assets/agents/review-reliability.md +29 -1
  7. package/assets/agents/review-resilience.md +29 -1
  8. package/assets/agents/review-risk.md +29 -1
  9. package/assets/chains/4r-review.chain.md +4 -4
  10. package/assets/orchestrator-delegation.md +183 -0
  11. package/assets/orchestrator-memory.md +32 -0
  12. package/assets/orchestrator-skills.md +49 -0
  13. package/assets/orchestrator.md +37 -228
  14. package/assets/sdd-orchestrator-workflow.md +2 -0
  15. package/extensions/gentle-ai.ts +27 -12
  16. package/extensions/pi-pretty.ts +14 -1
  17. package/extensions/quiet-tools.ts +218 -0
  18. package/lib/quiet-tools-config.ts +17 -0
  19. package/package.json +1 -1
  20. package/prompts/skill-creation.md +1 -1
  21. package/scripts/verify-package-files.mjs +4 -0
  22. package/skills/_shared/review-ledger-contract.md +98 -0
  23. package/skills/branch-pr/SKILL.md +1 -1
  24. package/skills/chained-pr/SKILL.md +1 -1
  25. package/skills/issue-creation/SKILL.md +1 -1
  26. package/skills/judgment-day/SKILL.md +27 -1
  27. package/skills/judgment-day/references/prompts-and-formats.md +38 -1
  28. package/skills/skill-creator/SKILL.md +1 -1
  29. package/skills/skill-improver/SKILL.md +2 -2
  30. package/tests/artifact-language.test.ts +10 -2
  31. package/tests/fixtures/measure-orchestrator-prompt.mjs +22 -0
  32. package/tests/fixtures/orchestrator.pre-diet.md +312 -0
  33. package/tests/gentle-ai.test.ts +8 -1
  34. package/tests/orchestrator-budget.test.ts +297 -0
  35. package/tests/package-manifest.test.ts +6 -0
  36. package/tests/persona-single-channel.test.ts +627 -0
  37. package/tests/quiet-tool-rendering.test.ts +249 -0
  38. package/tests/review-ledger-contract.test.ts +357 -0
  39. package/tests/runtime-harness.mjs +31 -4
  40. package/tests/skill-collision-prefixes.test.ts +56 -0
package/README.md CHANGED
@@ -55,7 +55,7 @@ Most coding-agent sessions fail for operational reasons, not model reasons:
55
55
  | **Reviewer protection** | Surfaces review workload risk before a task turns into an oversized PR. |
56
56
  | **Per-agent model assignment** | Pi-native modal for assigning stronger or cheaper models to specific SDD/custom agents. |
57
57
  | **Skill discovery registry** | Maintains `.atl/skill-registry.md` from project and user skills so review/comment/PR workflows do not silently miss the right skill. |
58
- | **Skill creation workflow** | Provides the `skill-creator`/`skill-improver` skills, `/skill-creation` prompt, and packaged style guide for LLM-first skills. |
58
+ | **Skill creation workflow** | Provides the `gentle-ai-skill-creator`/`gentle-ai-skill-improver` skills, `/skill-creation` prompt, and packaged style guide for LLM-first skills. |
59
59
  | **Delivery skills** | Includes issue-first PRs, chained PRs, work-unit commits, cognitive docs, comment writing, and Judgment Day review. |
60
60
  | **Runtime safety** | Blocks destructive shell commands, asks for confirmation for sensitive operations, and blocks direct read/write/edit access to sensitive paths. |
61
61
 
@@ -311,9 +311,11 @@ Behavior:
311
311
 
312
312
  Skill discovery is a guardrail, not a workflow router: it helps Pi load the right skill without forcing extra ceremony.
313
313
 
314
- `gentle-pi` also ships package-owned `skill-creator` and `skill-improver` skills plus the `/skill-creation` prompt for creating or updating project skills. Both skills use `docs/skill-style-guide.md` as their normative style contract. The workflow checks for duplicates, keeps `SKILL.md` concise, uses one-line trigger-rich frontmatter, and reminds maintainers to refresh the registry after skill changes.
314
+ `gentle-pi` also ships package-owned `gentle-ai-skill-creator` and `gentle-ai-skill-improver` skills plus the `/skill-creation` prompt for creating or updating project skills. Both skills use `docs/skill-style-guide.md` as their normative style contract. The workflow checks for duplicates, keeps `SKILL.md` concise, uses one-line trigger-rich frontmatter, and reminds maintainers to refresh the registry after skill changes.
315
315
 
316
- Packaged skills include `cognitive-doc-design`, `comment-writer`, `judgment-day`, `skill-creator`, `skill-improver`, and the other delivery/review skills under `skills/`. SDD init is installed as the packaged `sdd-init` runtime agent under `assets/agents/` and refreshed with the SDD assets.
316
+ Packaged skills include `cognitive-doc-design`, `comment-writer`, `gentle-ai-judgment-day`, `gentle-ai-skill-creator`, `gentle-ai-skill-improver`, and the other delivery/review skills under `skills/`. SDD init is installed as the packaged `sdd-init` runtime agent under `assets/agents/` and refreshed with the SDD assets.
317
+
318
+ Compatibility: the package keeps the existing skill folders (`skills/branch-pr`, `skills/judgment-day`, `skills/skill-creator`) but their exported frontmatter names are prefixed to avoid collisions with user/global skills. Treat former package names such as `branch-pr`, `judgment-day`, and `skill-creator` as legacy aliases in prose; runtime skill selection should use `gentle-ai-branch-pr`, `gentle-ai-judgment-day`, and `gentle-ai-skill-creator`.
317
319
 
318
320
  Delegation contract:
319
321
 
@@ -413,7 +415,7 @@ Legacy string entries are still accepted and treated as `model`-only config.
413
415
  | `/gentle:install-sdd` | Repairs missing global SDD runtime assets without overwriting files. |
414
416
  | `/gentle:install-sdd --force` | Force-refreshes installed global SDD assets. |
415
417
  | `/skill-registry:refresh` | Regenerates `.atl/skill-registry.md`. |
416
- | `/skill-creation` | Creates or updates an LLM-first skill using the packaged `skill-creator` contract and style guide. |
418
+ | `/skill-creation` | Creates or updates an LLM-first skill using the packaged `gentle-ai-skill-creator` contract and style guide. |
417
419
 
418
420
  Package-owned global SDD runtime assets are also refreshed automatically on session start when `gentle-pi` changes. Project-local `.pi/agents` and `.pi/chains` remain manual overrides and are never overwritten by startup refresh.
419
421
 
@@ -430,15 +432,15 @@ Use it when you want skills available normally but do not want Gentle AI to refr
430
432
  ## Included skills
431
433
 
432
434
  - `gentle-ai` — harness discipline for controlled Pi work.
433
- - `branch-pr` — issue-first PR preparation.
434
- - `chained-pr` — split oversized changes into reviewable PR chains.
435
+ - `gentle-ai-branch-pr` — issue-first PR preparation.
436
+ - `gentle-ai-chained-pr` — split oversized changes into reviewable PR chains.
435
437
  - `work-unit-commits` — commits as reviewable work units.
436
- - `judgment-day` — blind dual review, fixes, and re-judgment.
438
+ - `gentle-ai-judgment-day` — blind dual review, fixes, and re-judgment.
437
439
  - `cognitive-doc-design` — documentation that reduces cognitive load.
438
440
  - `comment-writer` — concise, warm, postable collaboration comments.
439
- - `issue-creation` — issue workflow with checks before creation.
440
- - `skill-creator` — create LLM-first skills with valid frontmatter.
441
- - `skill-improver` — audit and upgrade existing LLM-first skills.
441
+ - `gentle-ai-issue-creation` — issue workflow with checks before creation.
442
+ - `gentle-ai-skill-creator` — create LLM-first skills with valid frontmatter.
443
+ - `gentle-ai-skill-improver` — audit and upgrade existing LLM-first skills.
442
444
 
443
445
  ## Memory
444
446
 
@@ -20,3 +20,18 @@ Rules:
20
20
  - Add or update focused tests when the fix changes behavior.
21
21
  - Run the relevant tests when practical and report exact results.
22
22
  - Clearly list what was fixed, what was verified, and any remaining risks.
23
+
24
+ ## Review ledger contract (fix agent role)
25
+
26
+ This agent does NOT run the exhaustive first-pass sweep and does NOT emit a findings ledger — that is the judge role's job, not this agent's.
27
+
28
+ **Read the persisted ledger.** Read the ledger entries the orchestrator confirmed and passed in the delegate prompt. Apply only those confirmed fixes.
29
+
30
+ **Update status, do not add rows.** After fixing a confirmed entry, set that entry's `status` to `fixed`. Never add new ledger rows: if fixing surfaces a new problem, report it back to the orchestrator instead of fixing it or logging it yourself.
31
+
32
+ Valid enum values (same as the judge ledger schema, for reference only — this agent never emits ledger rows itself):
33
+ - `severity`: BLOCKER \| CRITICAL \| WARNING \| SUGGESTION
34
+ - `status`: open \| fixed \| verified \| wont-fix \| info
35
+ - `lens`: risk \| readability \| reliability \| resilience \| judgment-day
36
+
37
+ Fix execution-mode: jd-fix-agent applies only confirmed ledger findings and hands control back to the orchestrator, which runs the scoped re-judge.
@@ -18,3 +18,31 @@ Rules:
18
18
  - Do not coordinate with judge B before producing your review.
19
19
  - Report concrete findings with file paths, evidence, severity, and suggested verification.
20
20
  - If you find no confirmed issues, say so clearly.
21
+
22
+ ## Review ledger contract
23
+
24
+ **Exhaustive first pass.** Loop until dry: sweep the diff repeatedly until N consecutive sweeps yield zero new findings, then stop; the loop MUST be finite. Default N = 2 consecutive dry sweeps. R2 Readability MAY use N = 1. Hard ceiling: 4 sweeps regardless of N.
25
+
26
+ **Findings ledger.** Emit a findings ledger with this schema for every entry:
27
+
28
+ | Field | Values |
29
+ |-------|--------|
30
+ | `id` | `{LENS}-{NNN}` (e.g. `R1-001`) |
31
+ | `lens` | risk \| readability \| reliability \| resilience \| judgment-day |
32
+ | `location` | `path/to/file.ext:line` or `:start-end` |
33
+ | `severity` | BLOCKER \| CRITICAL \| WARNING \| SUGGESTION |
34
+ | `status` | open \| fixed \| verified \| wont-fix \| info |
35
+ | `evidence` | why it matters |
36
+
37
+ If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
38
+
39
+ Persistence below is executed by the orchestrator after it merges your returned ledger rows; you never write ledger artifacts yourself.
40
+
41
+ **Ledger persistence honors the artifact store.**
42
+ - `openspec`: write `openspec/changes/{change-name}/review-ledger.md`.
43
+ - `engram`: upsert topic `sdd/{change-name}/review-ledger` (ad-hoc judgment-day without a change: `review/{target-slug}/ledger`, where `target-slug` = `pr-{number}` when reviewing a PR, else the current branch name kebab-cased, else a kebab-case slug of the user-stated review target). If the engram upsert fails or the memory tool is unavailable, fall back to keeping the ledger inline in the response and explicitly report the degradation — never continue as if persistence succeeded.
44
+ - `none`: keep the ledger inline in the response; do not write files or Engram artifacts — the ledger lives only in this conversation; complete the review → fix → re-review loop within the session because it is not persisted across compaction.
45
+
46
+ **Scoped re-review.** A re-review pass takes the persisted ledger and the fix diff as input. It MUST verify each ledger finding's resolution and MUST review only fix-touched lines; it MUST NOT re-read the full original diff. A finding on an untouched line MUST be logged with status `info` as a first-pass quality signal and MUST NOT by itself trigger another full round.
47
+
48
+ Subagent execution-mode: this agent runs its lens exhaustively as a dedicated Pi subagent and returns its own ledger rows in its Output; the orchestrator merges those ledger rows into the persisted ledger.
@@ -18,3 +18,31 @@ Rules:
18
18
  - Work independently from judge A and do not rely on judge A's conclusions.
19
19
  - Report concrete findings with file paths, evidence, severity, and suggested verification.
20
20
  - If you find no confirmed issues, say so clearly.
21
+
22
+ ## Review ledger contract
23
+
24
+ **Exhaustive first pass.** Loop until dry: sweep the diff repeatedly until N consecutive sweeps yield zero new findings, then stop; the loop MUST be finite. Default N = 2 consecutive dry sweeps. R2 Readability MAY use N = 1. Hard ceiling: 4 sweeps regardless of N.
25
+
26
+ **Findings ledger.** Emit a findings ledger with this schema for every entry:
27
+
28
+ | Field | Values |
29
+ |-------|--------|
30
+ | `id` | `{LENS}-{NNN}` (e.g. `R1-001`) |
31
+ | `lens` | risk \| readability \| reliability \| resilience \| judgment-day |
32
+ | `location` | `path/to/file.ext:line` or `:start-end` |
33
+ | `severity` | BLOCKER \| CRITICAL \| WARNING \| SUGGESTION |
34
+ | `status` | open \| fixed \| verified \| wont-fix \| info |
35
+ | `evidence` | why it matters |
36
+
37
+ If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
38
+
39
+ Persistence below is executed by the orchestrator after it merges your returned ledger rows; you never write ledger artifacts yourself.
40
+
41
+ **Ledger persistence honors the artifact store.**
42
+ - `openspec`: write `openspec/changes/{change-name}/review-ledger.md`.
43
+ - `engram`: upsert topic `sdd/{change-name}/review-ledger` (ad-hoc judgment-day without a change: `review/{target-slug}/ledger`, where `target-slug` = `pr-{number}` when reviewing a PR, else the current branch name kebab-cased, else a kebab-case slug of the user-stated review target). If the engram upsert fails or the memory tool is unavailable, fall back to keeping the ledger inline in the response and explicitly report the degradation — never continue as if persistence succeeded.
44
+ - `none`: keep the ledger inline in the response; do not write files or Engram artifacts — the ledger lives only in this conversation; complete the review → fix → re-review loop within the session because it is not persisted across compaction.
45
+
46
+ **Scoped re-review.** A re-review pass takes the persisted ledger and the fix diff as input. It MUST verify each ledger finding's resolution and MUST review only fix-touched lines; it MUST NOT re-read the full original diff. A finding on an untouched line MUST be logged with status `info` as a first-pass quality signal and MUST NOT by itself trigger another full round.
47
+
48
+ Subagent execution-mode: this agent runs its lens exhaustively as a dedicated Pi subagent and returns its own ledger rows in its Output; the orchestrator merges those ledger rows into the persisted ledger.
@@ -25,4 +25,32 @@ Rule sources: ai-course-2 slides `05-code-smells.md`, `06-safe-refactoring.md`,
25
25
 
26
26
  ## Output contract
27
27
 
28
- Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, say exactly: `No findings.`
28
+ Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, return an empty findings ledger (a ledger record with zero rows) — never skip the ledger.
29
+
30
+ ## Review ledger contract
31
+
32
+ **Exhaustive first pass.** Loop until dry: sweep the diff repeatedly until N consecutive sweeps yield zero new findings, then stop; the loop MUST be finite. Default N = 2 consecutive dry sweeps. R2 Readability MAY use N = 1. Hard ceiling: 4 sweeps regardless of N.
33
+
34
+ **Findings ledger.** Emit a findings ledger with this schema for every entry:
35
+
36
+ | Field | Values |
37
+ |-------|--------|
38
+ | `id` | `{LENS}-{NNN}` (e.g. `R1-001`) |
39
+ | `lens` | risk \| readability \| reliability \| resilience \| judgment-day |
40
+ | `location` | `path/to/file.ext:line` or `:start-end` |
41
+ | `severity` | BLOCKER \| CRITICAL \| WARNING \| SUGGESTION |
42
+ | `status` | open \| fixed \| verified \| wont-fix \| info |
43
+ | `evidence` | why it matters |
44
+
45
+ If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
46
+
47
+ Persistence below is executed by the orchestrator after it merges your returned ledger rows; you never write ledger artifacts yourself.
48
+
49
+ **Ledger persistence honors the artifact store.**
50
+ - `openspec`: write `openspec/changes/{change-name}/review-ledger.md`.
51
+ - `engram`: upsert topic `sdd/{change-name}/review-ledger` (ad-hoc judgment-day without a change: `review/{target-slug}/ledger`, where `target-slug` = `pr-{number}` when reviewing a PR, else the current branch name kebab-cased, else a kebab-case slug of the user-stated review target). If the engram upsert fails or the memory tool is unavailable, fall back to keeping the ledger inline in the response and explicitly report the degradation — never continue as if persistence succeeded.
52
+ - `none`: keep the ledger inline in the response; do not write files or Engram artifacts — the ledger lives only in this conversation; complete the review → fix → re-review loop within the session because it is not persisted across compaction.
53
+
54
+ **Scoped re-review.** A re-review pass takes the persisted ledger and the fix diff as input. It MUST verify each ledger finding's resolution and MUST review only fix-touched lines; it MUST NOT re-read the full original diff. A finding on an untouched line MUST be logged with status `info` as a first-pass quality signal and MUST NOT by itself trigger another full round.
55
+
56
+ Subagent execution-mode: this agent runs its lens exhaustively as a dedicated Pi subagent and returns its own ledger rows in its Output; the orchestrator merges those ledger rows into the persisted ledger.
@@ -26,4 +26,32 @@ Rule sources: ai-course-2 slides `01-testing-setup.md`, `02-tdd-implementation.m
26
26
 
27
27
  ## Output contract
28
28
 
29
- Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, say exactly: `No findings.`
29
+ Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, return an empty findings ledger (a ledger record with zero rows) — never skip the ledger.
30
+
31
+ ## Review ledger contract
32
+
33
+ **Exhaustive first pass.** Loop until dry: sweep the diff repeatedly until N consecutive sweeps yield zero new findings, then stop; the loop MUST be finite. Default N = 2 consecutive dry sweeps. R2 Readability MAY use N = 1. Hard ceiling: 4 sweeps regardless of N.
34
+
35
+ **Findings ledger.** Emit a findings ledger with this schema for every entry:
36
+
37
+ | Field | Values |
38
+ |-------|--------|
39
+ | `id` | `{LENS}-{NNN}` (e.g. `R1-001`) |
40
+ | `lens` | risk \| readability \| reliability \| resilience \| judgment-day |
41
+ | `location` | `path/to/file.ext:line` or `:start-end` |
42
+ | `severity` | BLOCKER \| CRITICAL \| WARNING \| SUGGESTION |
43
+ | `status` | open \| fixed \| verified \| wont-fix \| info |
44
+ | `evidence` | why it matters |
45
+
46
+ If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
47
+
48
+ Persistence below is executed by the orchestrator after it merges your returned ledger rows; you never write ledger artifacts yourself.
49
+
50
+ **Ledger persistence honors the artifact store.**
51
+ - `openspec`: write `openspec/changes/{change-name}/review-ledger.md`.
52
+ - `engram`: upsert topic `sdd/{change-name}/review-ledger` (ad-hoc judgment-day without a change: `review/{target-slug}/ledger`, where `target-slug` = `pr-{number}` when reviewing a PR, else the current branch name kebab-cased, else a kebab-case slug of the user-stated review target). If the engram upsert fails or the memory tool is unavailable, fall back to keeping the ledger inline in the response and explicitly report the degradation — never continue as if persistence succeeded.
53
+ - `none`: keep the ledger inline in the response; do not write files or Engram artifacts — the ledger lives only in this conversation; complete the review → fix → re-review loop within the session because it is not persisted across compaction.
54
+
55
+ **Scoped re-review.** A re-review pass takes the persisted ledger and the fix diff as input. It MUST verify each ledger finding's resolution and MUST review only fix-touched lines; it MUST NOT re-read the full original diff. A finding on an untouched line MUST be logged with status `info` as a first-pass quality signal and MUST NOT by itself trigger another full round.
56
+
57
+ Subagent execution-mode: this agent runs its lens exhaustively as a dedicated Pi subagent and returns its own ledger rows in its Output; the orchestrator merges those ledger rows into the persisted ledger.
@@ -25,4 +25,32 @@ Rule sources: ai-course-2 slides `09-essential-metrics.md`, `13-observability-st
25
25
 
26
26
  ## Output contract
27
27
 
28
- Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, say exactly: `No findings.`
28
+ Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, return an empty findings ledger (a ledger record with zero rows) — never skip the ledger.
29
+
30
+ ## Review ledger contract
31
+
32
+ **Exhaustive first pass.** Loop until dry: sweep the diff repeatedly until N consecutive sweeps yield zero new findings, then stop; the loop MUST be finite. Default N = 2 consecutive dry sweeps. R2 Readability MAY use N = 1. Hard ceiling: 4 sweeps regardless of N.
33
+
34
+ **Findings ledger.** Emit a findings ledger with this schema for every entry:
35
+
36
+ | Field | Values |
37
+ |-------|--------|
38
+ | `id` | `{LENS}-{NNN}` (e.g. `R1-001`) |
39
+ | `lens` | risk \| readability \| reliability \| resilience \| judgment-day |
40
+ | `location` | `path/to/file.ext:line` or `:start-end` |
41
+ | `severity` | BLOCKER \| CRITICAL \| WARNING \| SUGGESTION |
42
+ | `status` | open \| fixed \| verified \| wont-fix \| info |
43
+ | `evidence` | why it matters |
44
+
45
+ If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
46
+
47
+ Persistence below is executed by the orchestrator after it merges your returned ledger rows; you never write ledger artifacts yourself.
48
+
49
+ **Ledger persistence honors the artifact store.**
50
+ - `openspec`: write `openspec/changes/{change-name}/review-ledger.md`.
51
+ - `engram`: upsert topic `sdd/{change-name}/review-ledger` (ad-hoc judgment-day without a change: `review/{target-slug}/ledger`, where `target-slug` = `pr-{number}` when reviewing a PR, else the current branch name kebab-cased, else a kebab-case slug of the user-stated review target). If the engram upsert fails or the memory tool is unavailable, fall back to keeping the ledger inline in the response and explicitly report the degradation — never continue as if persistence succeeded.
52
+ - `none`: keep the ledger inline in the response; do not write files or Engram artifacts — the ledger lives only in this conversation; complete the review → fix → re-review loop within the session because it is not persisted across compaction.
53
+
54
+ **Scoped re-review.** A re-review pass takes the persisted ledger and the fix diff as input. It MUST verify each ledger finding's resolution and MUST review only fix-touched lines; it MUST NOT re-read the full original diff. A finding on an untouched line MUST be logged with status `info` as a first-pass quality signal and MUST NOT by itself trigger another full round.
55
+
56
+ Subagent execution-mode: this agent runs its lens exhaustively as a dedicated Pi subagent and returns its own ledger rows in its Output; the orchestrator merges those ledger rows into the persisted ledger.
@@ -25,4 +25,32 @@ Rule sources: ai-course-2 slides `18-env-secrets.md`, `19-web-security.md`, `20-
25
25
 
26
26
  ## Output contract
27
27
 
28
- Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, say exactly: `No findings.`
28
+ Report findings only. Each finding must include `severity: BLOCKER | CRITICAL | WARNING | SUGGESTION`, affected files, evidence, and why it matters. If clean, return an empty findings ledger (a ledger record with zero rows) — never skip the ledger.
29
+
30
+ ## Review ledger contract
31
+
32
+ **Exhaustive first pass.** Loop until dry: sweep the diff repeatedly until N consecutive sweeps yield zero new findings, then stop; the loop MUST be finite. Default N = 2 consecutive dry sweeps. R2 Readability MAY use N = 1. Hard ceiling: 4 sweeps regardless of N.
33
+
34
+ **Findings ledger.** Emit a findings ledger with this schema for every entry:
35
+
36
+ | Field | Values |
37
+ |-------|--------|
38
+ | `id` | `{LENS}-{NNN}` (e.g. `R1-001`) |
39
+ | `lens` | risk \| readability \| reliability \| resilience \| judgment-day |
40
+ | `location` | `path/to/file.ext:line` or `:start-end` |
41
+ | `severity` | BLOCKER \| CRITICAL \| WARNING \| SUGGESTION |
42
+ | `status` | open \| fixed \| verified \| wont-fix \| info |
43
+ | `evidence` | why it matters |
44
+
45
+ If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
46
+
47
+ Persistence below is executed by the orchestrator after it merges your returned ledger rows; you never write ledger artifacts yourself.
48
+
49
+ **Ledger persistence honors the artifact store.**
50
+ - `openspec`: write `openspec/changes/{change-name}/review-ledger.md`.
51
+ - `engram`: upsert topic `sdd/{change-name}/review-ledger` (ad-hoc judgment-day without a change: `review/{target-slug}/ledger`, where `target-slug` = `pr-{number}` when reviewing a PR, else the current branch name kebab-cased, else a kebab-case slug of the user-stated review target). If the engram upsert fails or the memory tool is unavailable, fall back to keeping the ledger inline in the response and explicitly report the degradation — never continue as if persistence succeeded.
52
+ - `none`: keep the ledger inline in the response; do not write files or Engram artifacts — the ledger lives only in this conversation; complete the review → fix → re-review loop within the session because it is not persisted across compaction.
53
+
54
+ **Scoped re-review.** A re-review pass takes the persisted ledger and the fix diff as input. It MUST verify each ledger finding's resolution and MUST review only fix-touched lines; it MUST NOT re-read the full original diff. A finding on an untouched line MUST be logged with status `info` as a first-pass quality signal and MUST NOT by itself trigger another full round.
55
+
56
+ Subagent execution-mode: this agent runs its lens exhaustively as a dedicated Pi subagent and returns its own ledger rows in its Output; the orchestrator merges those ledger rows into the persisted ledger.
@@ -9,7 +9,7 @@ output: review-risk-report.md
9
9
  outputMode: file-only
10
10
  progress: true
11
11
 
12
- Run R1 Risk review on the current diff. Report security, privilege boundary, data exposure, dependency, and merge-blocking vulnerability findings. If clean, say exactly: `No findings.`
12
+ Run R1 Risk review on the current diff. Report security, privilege boundary, data exposure, dependency, and merge-blocking vulnerability findings. If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
13
13
 
14
14
  ## review-readability
15
15
 
@@ -18,7 +18,7 @@ output: review-readability-report.md
18
18
  outputMode: file-only
19
19
  progress: true
20
20
 
21
- Run R2 Readability review on the current diff. Report naming, complexity, intention, maintainability, review size, and context clarity findings. If clean, say exactly: `No findings.`
21
+ Run R2 Readability review on the current diff. Report naming, complexity, intention, maintainability, review size, and context clarity findings. If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
22
22
 
23
23
  ## review-reliability
24
24
 
@@ -27,7 +27,7 @@ output: review-reliability-report.md
27
27
  outputMode: file-only
28
28
  progress: true
29
29
 
30
- Run R3 Reliability review on the current diff. Report behavior-first test coverage, edge case, determinism, contract, and regression findings. If clean, say exactly: `No findings.`
30
+ Run R3 Reliability review on the current diff. Report behavior-first test coverage, edge case, determinism, contract, and regression findings. If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
31
31
 
32
32
  ## review-resilience
33
33
 
@@ -36,4 +36,4 @@ output: review-resilience-report.md
36
36
  outputMode: file-only
37
37
  progress: true
38
38
 
39
- Run R4 Resilience review on the current diff. Report fallback, retry/backoff, graceful degradation, observability, load, rollback, and SLO risk findings. If clean, say exactly: `No findings.`
39
+ Run R4 Resilience review on the current diff. Report fallback, retry/backoff, graceful degradation, observability, load, rollback, and SLO risk findings. If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
@@ -0,0 +1,183 @@
1
+ # Orchestrator — Delegation Detail (lazy-loaded)
2
+
3
+ Bind this to the parent Pi session only, on delegation/routing/review triggers. Not always-on; loaded on demand from `assets/orchestrator.md`'s `## Work Routing Ladder`, `## Delegation Rules`, `## Language Boundary`, and `## 4R Review Triggers` pointers.
4
+
5
+ ## Language Boundary — subagent-facing English + exceptions
6
+
7
+ Subagent-facing prompts should be written in English by default, even when the user speaks Spanish. Translate the user's request into concise English before delegation. This keeps token usage lower and gives built-in/project subagents a consistent operating language without changing the user-facing persona.
8
+
9
+ Exceptions:
10
+
11
+ - Preserve exact user quotes, UI copy, error messages, filenames, commands, and domain terms in their original language when they are evidence.
12
+ - Ask a subagent to produce Spanish only when its output is intended to be pasted directly to the user, a PR/comment/reply in Spanish, or Spanish-language product/documentation text.
13
+ - SDD/OpenSpec artifact content may follow the project's established language, but phase task instructions to subagents should still be English.
14
+
15
+ ## Work Routing Ladder
16
+
17
+ Route work through the smallest harness that is safe. "Smallest" means minimal safe coordination, not zero delegation by default.
18
+
19
+ ### 1. Inline Direct
20
+
21
+ Use inline execution when the task is small, mechanical, and the parent already has enough context.
22
+
23
+ Examples:
24
+
25
+ - typo, rename, one-file mechanical edit;
26
+ - small known bug with clear location;
27
+ - focused verification over 1-3 files;
28
+ - bash for state, e.g. `git status` or `gh issue view`.
29
+
30
+ Do not add SDD ceremony. Do not delegate just to look sophisticated. But do not use this exception to avoid delegation after the task stops being small.
31
+
32
+ ### 2. Simple Delegation
33
+
34
+ Delegate when the work would inflate parent context or requires focused exploration, validation, or multi-file implementation, but does not yet need a full SDD lifecycle.
35
+
36
+ Examples:
37
+
38
+ - understand an unfamiliar module;
39
+ - inspect 4+ files;
40
+ - investigate a failing test;
41
+ - implement a bounded multi-file change;
42
+ - run tests/builds and summarize results;
43
+ - fresh-context review.
44
+
45
+ Use the configured subagent runtime when available. Prefer the `subagent_*` tools (`subagent_run`, status/result helpers) when the Pi Subagents extension is installed, because they run the user's configured project/global subagent definitions and preserve history/background behavior.
46
+
47
+ Choose subagent mode by orchestration dependency, not by task length:
48
+
49
+ - Use `mode: "task"` when the parent must consume the result and continue the workflow, including SDD phases, implementation batches, verification, review gates, and any delegated work whose output determines the next action.
50
+ - Use `mode: "background"` only for independent work where automatic parent continuation is not required. Background completion may notify the user and preserve history, but it is not a guarantee that the parent model will resume orchestration.
51
+
52
+ If `subagent_*` tools are unavailable, fall back to Pi's native `Agent` tool or another available delegation mechanism. The delegation trigger remains mandatory; the fallback changes the runtime, not the requirement to delegate. If no delegation mechanism is available, stop the complex work and explain the blocker instead of silently continuing inline.
53
+
54
+ ### Pi Subagent Model Routing
55
+
56
+ For generic Pi subagents (`delegate`, `worker`, `scout`, review lens agents, `context-builder`, `oracle`, `planner`, `researcher`, or other non-SDD agents), do not pass the `model` parameter by default. Let `pi-subagents` resolve model and thinking from `.pi/settings.json`, `.pi/subagents.json`, global subagent config, and runtime defaults.
57
+
58
+ SDD model assignment tables apply only to SDD/Judgment-Day phase agents. They must not be used for generic Pi delegation.
59
+
60
+ Only pass `model` for generic subagents when the user explicitly requests a model override for that launch.
61
+
62
+ Default balanced pattern for bounded implementation:
63
+
64
+ ```text
65
+ parent clarifies and checks git → scout/context-builder when context-heavy → one worker writes → selected review lens audits diff → parent validates and reports
66
+ ```
67
+
68
+ Do not make every task SDD. Do make non-trivial tasks multi-agent at the narrowest useful point.
69
+
70
+ ### 3. SDD
71
+
72
+ Use SDD for large, ambiguous, architectural, product-facing, multi-area, or high-review-risk work.
73
+
74
+ Triggers:
75
+
76
+ - unclear requirements or acceptance criteria;
77
+ - architectural/product decisions;
78
+ - cross-cutting behavior changes;
79
+ - expected large diff or reviewer burden;
80
+ - need for specs/design/tasks before safe implementation;
81
+ - user explicitly asks to use SDD, or invokes `/sdd-new`, `/sdd-ff`, or `/sdd-continue`.
82
+
83
+ If the request is large enough for SDD, do not jump directly to implementation. Calibrate context, create artifacts, and ask for approval at the appropriate gates.
84
+
85
+ ## Delegation Rules
86
+
87
+ Core question: does this inflate parent context without need?
88
+
89
+ | Action | Inline | Delegate |
90
+ | ---------------------------------------------------- | -----: | ----------------------: |
91
+ | Read to decide/verify 1-3 files | yes | no |
92
+ | Read to explore/understand 4+ files | no | yes |
93
+ | Read as preparation for multi-file writing | no | yes |
94
+ | Write atomic one-file mechanical change | yes | no |
95
+ | Write with analysis across multiple files | no | yes |
96
+ | Bash for state, e.g. git status | yes | no |
97
+ | Bash for execution, e.g. tests/builds | no | yes |
98
+ | Commit, push, or open PR after code changes | no | yes, fresh review first |
99
+ | Recover from wrong cwd/worktree/git/tooling incident | no | yes, fresh audit first |
100
+
101
+ ### Mandatory Delegation Triggers
102
+
103
+ These are parent-orchestrator stop rules. Once any trigger fires, the parent MUST delegate through the best available subagent runtime. Prefer `subagent_run` when present; otherwise use Pi's native `Agent` or another available delegation mechanism. Do not replace a required delegation with inline execution. Do not inject these as child-agent permission to spawn subagents; children receive concrete role work and must not orchestrate.
104
+
105
+ 1. **4-file rule**: if understanding requires reading 4+ files, launch `scout`, `context-builder`, or the closest read-only mapping subagent with fresh context and a narrow mapping task. State the fallback agent/runtime if the preferred one is unavailable.
106
+ 2. **Multi-file write rule**: if implementation will touch 2+ non-trivial files, delegate one writer; inline writing is allowed only for trivial/mechanical edits or when the parent explicitly records why no delegation runtime is available. A fresh review still follows delegated implementation.
107
+ 3. **PR rule**: before commit/push/PR for code changes, select a fresh-context review lens unless the diff is trivial docs/text-only.
108
+ 4. **Incident rule**: after wrong `cwd`, accidental repo/worktree mutation, failed merge recovery, confusing test command, or environment workaround, stop and run a fresh audit through the relevant review lens before continuing.
109
+ 5. **Long-session rule**: if accumulating work is no longer clearly local — roughly 20 tool calls, 5 exploratory file reads, or 2 non-mechanical edits without delegation — pause and delegate the remaining work instead of silently continuing monolithically.
110
+ 6. **Fresh review rule**: use fresh-context review lens subagents for adversarial review of diffs, conflicts, PR readiness, and incidents. Use continuity-oriented workers only for implementation work that needs inherited state.
111
+
112
+ ### Cost and Context Balance
113
+
114
+ Prefer delegation when fresh context improves correctness more than token savings:
115
+
116
+ - Use `scout`/`context-builder` to compress broad repo exploration into a short handoff instead of loading many files into the parent.
117
+ - Use a single `worker` for one writer thread; do not run parallel writers unless isolated worktrees are explicitly approved.
118
+ - Use fresh concrete review lens agents after implementation, conflict resolution, or incidents because their value is independence from the parent's assumptions. Do not call a generic `reviewer` subagent; choose from `review-risk`, `review-reliability`, `review-resilience`, `review-readability`, or the full 4R set.
119
+ - Use `outputMode: "file-only"` for large child reports and summarize only decisions, blockers, and paths in the parent thread.
120
+ - Avoid delegation for truly local one-file fixes, quick state checks, and already-understood mechanical edits.
121
+
122
+ ### Canonical Lightweight Workflows
123
+
124
+ Bugfix with unfamiliar flow:
125
+
126
+ ```text
127
+ parent git/status + clarify → scout fresh maps flow/files → parent decides → worker fork implements + tests → selected review lens audits diff → parent validates
128
+ ```
129
+
130
+ Conflict or dependency-marker cleanup:
131
+
132
+ ```text
133
+ parent reproduces/checks conflict → parent or worker resolves → selected review lens checks markers, package/lock consistency, and repo cleanliness → parent reports/pushes
134
+ ```
135
+
136
+ After tooling/worktree incident:
137
+
138
+ ```text
139
+ stop writes → parent captures git status → selected review lens audits affected repos/worktrees with no edits → parent applies only confirmed recovery steps
140
+ ```
141
+
142
+ ### Review Lens Selection
143
+
144
+ `reviewer` is an intent, not an installed subagent name. The parent must select concrete review agents by risk profile:
145
+
146
+ | Context | Review lens |
147
+ | --- | --- |
148
+ | Clear naming, structure, maintainability, small refactors | `review-readability` |
149
+ | Behavior, state, tests, determinism, regressions | `review-reliability` |
150
+ | Shell/process integration, partial failures, recovery, degraded dependencies | `review-resilience` |
151
+ | Security, permissions, data exposure/loss, architecture, dependencies | `review-risk` |
152
+ | Large PR, hot path, or >400 changed lines | Full 4R: `review-risk`, `review-resilience`, `review-readability`, `review-reliability` |
153
+
154
+ If multiple rows match, run the narrow set that covers the risk. Example: shell integration that mutates live state should use `review-reliability` plus `review-resilience`, not `review-readability` by default.
155
+
156
+ ## 4R Review Triggers
157
+
158
+ The extension (`extensions/gentle-ai.ts`) gates `bash` tool calls that look like git/gh workflow events. Gate semantics:
159
+
160
+ - **pre-commit** (`git commit`): advisory only. The extension notifies the user to consider running `review-readability` but does NOT block. No orchestrator action needed.
161
+ - **pre-push** (`git push`): advisory only. Same as pre-commit — notify, do not block.
162
+ - **pre-pr** (`gh pr create`): **strong gate**. The extension blocks when any of these hold:
163
+ - Changed paths match hot globs: `**/auth/**`, `**/update/**`, `**/security/**`, `**/payments/**`
164
+ - Diff exceeds 400 changed lines (added + deleted)
165
+ - When blocked, the reason names all four agents to run first.
166
+ - **post-sdd-phase** (design, apply): **strong gate** for the packaged `gentle-ai-judgment-day` skill. Handled separately by SDD phase orchestration, not this diff-based hook.
167
+
168
+ When the extension blocks a `gh pr create` command, the orchestrator must launch the `4r-review` chain (or run the four agents individually) and wait for their reports before the user retries the PR command.
169
+
170
+ Prohibition: do NOT configure the full 4R fan-out on `pre-commit` or `pre-push` with `always: true`. Everyday events must use a single advisory lens to keep development-loop cost low (spec G token-budget rule). The `validateTriggerRuleSet` function in `lib/review-triggers.ts` enforces this at config load time.
171
+
172
+ ### Review Execution Contract
173
+
174
+ **Ledger persistence honors the artifact store.**
175
+ - `openspec`: write `openspec/changes/{change-name}/review-ledger.md`.
176
+ - `engram`: upsert topic `sdd/{change-name}/review-ledger` (ad-hoc judgment-day without a change: `review/{target-slug}/ledger`, where `target-slug` = `pr-{number}` when reviewing a PR, else the current branch name kebab-cased, else a kebab-case slug of the user-stated review target). If the engram upsert fails or the memory tool is unavailable, fall back to keeping the ledger inline in the response and explicitly report the degradation — never continue as if persistence succeeded.
177
+ - `none`: keep the ledger inline in the response; do not write files or Engram artifacts — the ledger lives only in this conversation; complete the review → fix → re-review loop within the session because it is not persisted across compaction.
178
+
179
+ If the first pass finds nothing, persist an empty ledger record rather than skip persistence.
180
+
181
+ Subagent execution-mode: this agent runs its lens exhaustively as a dedicated Pi subagent and returns its own ledger rows in its Output; the orchestrator merges those ledger rows into the persisted ledger.
182
+
183
+ Fix execution-mode: jd-fix-agent applies only confirmed ledger findings and hands control back to the orchestrator, which runs the scoped re-judge.
@@ -0,0 +1,32 @@
1
+ # Orchestrator — Memory Detail (lazy-loaded)
2
+
3
+ Bind this to the parent Pi session only, on SDD phase memory reads/writes. Not always-on; loaded on demand from `assets/orchestrator.md`'s `## Memory Contract` pointer.
4
+
5
+ ### SDD phases
6
+
7
+ Each SDD phase subagent reads its own required inputs directly from the active backend; the parent passes artifact references (topic keys or file paths), NOT the content itself. Phase subagents persist their artifact before returning.
8
+
9
+ | Phase | Reads | Writes |
10
+ | -------------- | ------------------------------------------------------- | ---------------- |
11
+ | `sdd-explore` | nothing | `explore` |
12
+ | `sdd-proposal` | exploration (optional) | `proposal` |
13
+ | `sdd-spec` | proposal (required) | `spec` |
14
+ | `sdd-design` | proposal (required) | `design` |
15
+ | `sdd-tasks` | spec + design (required) | `tasks` |
16
+ | `sdd-apply` | tasks + spec + design + `apply-progress` (if it exists) | `apply-progress` |
17
+ | `sdd-verify` | spec + tasks + `apply-progress` | `verify-report` |
18
+ | `sdd-sync` | proposal + spec + design + tasks + `verify-report` | `sync-report` |
19
+ | `sdd-archive` | all artifacts | `archive-report` |
20
+ | `sdd-status` | change artifacts (read-only) | nothing |
21
+
22
+ - SDD artifact keys: in memory/hybrid mode, phase artifacts use stable topic keys such as `sdd/<change>/proposal`, `sdd/<change>/spec`, `sdd/<change>/design`, `sdd/<change>/tasks`, `sdd/<change>/apply-progress`, `sdd/<change>/verify-report`, `sdd/<change>/sync-report`, and `sdd/<change>/archive-report`.
23
+ - If memory tools are unavailable, do not pretend persistence exists; return artifacts inline and/or write OpenSpec files.
24
+
25
+ Memory lifecycle rule (when Engram exposes lifecycle metadata/tooling):
26
+
27
+ - At session start or before architecture-sensitive work, call the injected Engram review tool with action `list` for the current project when the tool is available.
28
+ - If the injected Engram review tool is unavailable, do not fail the task. Continue with the injected Engram context/search tools, and still apply lifecycle metadata from any returned observations when present.
29
+ - `active` memories may be used normally.
30
+ - `needs_review` memories are stale context, not trusted facts.
31
+ - When a retrieved memory is marked `needs_review`, surface that stale context to the user and verify it against current evidence before relying on it.
32
+ - Do NOT call the injected Engram review tool with action `mark_reviewed` automatically. Only call `mark_reviewed` after explicit user confirmation or through a dedicated memory maintenance command.
@@ -0,0 +1,49 @@
1
+ # Orchestrator — Skills Detail (lazy-loaded)
2
+
3
+ Bind this to the parent Pi session only, on skill resolution/discovery. Not always-on; loaded on demand from `assets/orchestrator.md`'s `## Skill Registry Protocol` and `## Intent-Driven Skill Discovery` pointers.
4
+
5
+ ## Skill Registry Protocol
6
+
7
+ The parent resolves skills once per session or before first delegation:
8
+
9
+ 1. Read `.atl/skill-registry.md` if present.
10
+ 2. Match task context and target files against the `Trigger / description` column.
11
+ 3. Pass only matching `Path` values to subagents under `## Skills to load before work`.
12
+ 4. Tell subagents to read those exact `SKILL.md` files before reading, writing, reviewing, testing, or creating artifacts.
13
+ 5. If the registry is absent, continue but mention that project-specific skill paths were unavailable.
14
+
15
+ Subagents should receive exact indexed paths. They should not have to rediscover the registry.
16
+
17
+ Important distinction: SDD subagents still use their assigned executor/phase skill (for example `sdd-apply`, `sdd-design`, or `sdd-verify`). What they should not do during normal runtime is independently discover additional project/user `SKILL.md` files or the registry. The parent passes selected project/user skill paths explicitly.
18
+
19
+ If a subagent reports `skill_resolution`, interpret it as project/user skill resolution:
20
+
21
+ - `paths-injected`: parent supplied `## Skills to load before work` with exact `SKILL.md` paths.
22
+ - `fallback-registry`: subagent self-loaded skill paths from the registry because parent paths were missing; degraded but auditable.
23
+ - `fallback-path`: subagent loaded explicit skill paths because parent paths were missing; degraded but auditable.
24
+ - `none`: no project/user skills were loaded.
25
+
26
+ If any subagent reports a fallback instead of `paths-injected`, treat it as an orchestration gap and correct future delegations by passing exact indexed paths directly.
27
+
28
+ ## Intent-Driven Skill Discovery
29
+
30
+ For skill-shaped requests, do not treat injected `<available_skills>` as complete. Use the registry and filesystem only as a discovery aid; do not let a trigger table override the user's concrete request or turn a small request into a larger workflow.
31
+
32
+ Discovery order:
33
+
34
+ 1. Read `.atl/skill-registry.md` when present.
35
+ 2. If the registry suggests a specific skill, load the indexed `SKILL.md` path before acting.
36
+ 3. If the expected skill is absent from the registry but the request clearly names a known workflow, search common project/user skill dirs such as `./skills`, `.pi/skills`, `.agents/skills`, `~/.config/opencode/skills`, `~/.claude/skills`, and other configured skill roots.
37
+ 4. Prefer the most specific project skill over a global skill with the same intent.
38
+ 5. If no matching skill exists, continue with the smallest safe fallback and say which expected skill was unavailable.
39
+
40
+ Common intent hints, not hard routing:
41
+
42
+ | User intent | Skill to check |
43
+ | -------------------------- | -------------------------------------- |
44
+ | PR review / GitHub PR URL | project review skill, then `pr-review` |
45
+ | Post-ready review comments | `comment-writer` |
46
+ | Create/open/prepare PR | `gentle-ai-branch-pr` |
47
+ | Split/stack/large PR | `gentle-ai-chained-pr` |
48
+
49
+ Keep this lightweight: loading a skill should improve the immediate task, not force extra ceremony.