@cratis/pi 7.47.1 → 7.48.2
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.
- package/package/corpus/harnesses/copilot/instructions/application-profile.instructions.md +1 -1
- package/package/corpus/harnesses/copilot/instructions/local-work-artifacts.instructions.md +6 -2
- package/package/corpus/harnesses/copilot/instructions/vertical-slices.instructions.md +1 -1
- package/package/corpus/hooks/README.md +11 -5
- package/package/corpus/hooks/scripts/cratis-cleanup-worktrees.sh +44 -4
- package/package/corpus/prompts/ship-changes.prompt.md +4 -1
- package/package/corpus/rules/application-profile.md +1 -1
- package/package/corpus/rules/local-work-artifacts.md +6 -2
- package/package/corpus/rules/vertical-slices.md +1 -1
- package/package/corpus/skills/cratis-arc-command/SKILL.md +7 -6
- package/package/corpus/skills/cratis-arc-command/references/decisions-and-routing.md +41 -11
- package/package/corpus/skills/cratis-arc-command/references/read-model-injection.md +2 -1
- package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +18 -4
- package/package/corpus/skills/cratis-chronicle-decision-reads/SKILL.md +41 -6
- package/package/corpus/skills/cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md +213 -0
- package/package/corpus/skills/cratis-chronicle-event-constraints/SKILL.md +17 -4
- package/package/corpus/skills/cratis-chronicle-event-modeling/SKILL.md +3 -1
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +12 -3
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +6 -2
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/SKILL.md +2 -1
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/SKILL.md +110 -167
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +74 -170
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/case-tables-and-whole-numbers.md +15 -35
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/choosing-generation.md +4 -6
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/render-example.md +23 -27
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/rendered-application.md +21 -33
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/sandbox-and-specrunner.md +61 -92
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/scene-runtime.md +4 -12
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/verification.json +10 -14
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ Pick exactly one type per slice folder — determined by what the slice *does*.
|
|
|
18
18
|
|
|
19
19
|
| Type | What it does | Contents |
|
|
20
20
|
| --- | --- | --- |
|
|
21
|
-
| **State Change** | Accepts a command, appends events | Command + validator + event(s); optional `[Passive]` read
|
|
21
|
+
| **State Change** | Accepts a command, appends events | Command + validator + event(s); optional `[Passive]` for a current read; a rule that must hold under concurrency needs a decision read or constraint (see the `cratis-chronicle-decision-reads` skill, `references/choosing-how-a-rule-holds.md`) |
|
|
22
22
|
| **State View** | Projects events into a queryable read model | `[ReadModel]` + model-bound projection + static query method(s) |
|
|
23
23
|
| **Automation** | Reacts to events, calls external systems / `ICommandPipeline`, or returns follow-up commands/events (including to another stream) | Reactor only |
|
|
24
24
|
| **Translation** | Takes data from outside our own facts (an external system or another service) and records it as our facts | An adapter at the boundary, often a reactor |
|
|
@@ -43,8 +43,12 @@ dumps, and similar coordination files. These are **work records, not documentati
|
|
|
43
43
|
main checkout when a pull request merges or you finish a task (hooks also run it after
|
|
44
44
|
`gh pr merge` and at session start where the harness supports them, and **ship-changes**
|
|
45
45
|
ends with it). It removes a worktree and its branch only on evidence the work reached the
|
|
46
|
-
default branch — pushed is not merged — and never forces
|
|
47
|
-
|
|
46
|
+
default branch — pushed is not merged — and never forces. Worktrees with non-empty `.ai-work/`
|
|
47
|
+
directories are kept by default as "has untracked work records (.ai-work/)". Manual
|
|
48
|
+
`--include-work-records` permits deleting those records after you preserve what you need;
|
|
49
|
+
automatic hooks never opt in. Pin a long-lived worktree with `git worktree lock <path>`;
|
|
50
|
+
locked worktrees are always kept, even with opt-in. Other ignored files such as `.env` files
|
|
51
|
+
and local databases can still be deleted with a removed worktree, so move anything you
|
|
48
52
|
still need out first. Do not hand-remove worktrees or `git branch -D` a delivered branch
|
|
49
53
|
when the script can; and `gh pr merge --delete-branch` from inside a worktree leaves the
|
|
50
54
|
worktree and branch behind, which is why the script exists. If the branch must outlive the
|
|
@@ -391,7 +391,7 @@ Redaction is a system-event request that removes payload availability from the e
|
|
|
391
391
|
|
|
392
392
|
## Cross-slice patterns **[convention]**
|
|
393
393
|
|
|
394
|
-
Cross-slice access is **read-only and goes through Chronicle** — inject another slice's read model (validator/`Provide()`/`Handle()`), read by explicit key with `IReadModels.GetInstanceById`, mark a `[Passive]` projection for
|
|
394
|
+
Cross-slice access is **read-only and goes through Chronicle** — inject another slice's read model (validator/`Provide()`/`Handle()`), read by explicit key with `IReadModels.GetInstanceById`, mark a `[Passive]` projection for a current read (a rule that must hold under concurrency needs a decision read or constraint, see the `cratis-chronicle-decision-reads` skill's `references/choosing-how-a-rule-holds.md`), or react to its events. **Never** instantiate or DI another slice's command/handler/service.
|
|
395
395
|
|
|
396
396
|
**DCB (Dynamic Consistency Boundary):** the boundary is the event state explicitly
|
|
397
397
|
enrolled in guarded decisions, not every model a command reads. Use stream
|
|
@@ -70,8 +70,9 @@ It removes only on **evidence of delivery**, never on a guess: the tip is merged
|
|
|
70
70
|
and was integrated rather than merely sitting on the default branch's first-parent history (where a
|
|
71
71
|
brand-new empty branch sits), or it is merged and its upstream is gone, or GitHub reports a merged pull
|
|
72
72
|
request whose head is exactly that tip. It never forces: a dirty, locked or current worktree is kept, as
|
|
73
|
-
is anything undelivered, and every kept item is reported with its reason.
|
|
74
|
-
|
|
73
|
+
is anything undelivered, and every kept item is reported with its reason. Worktrees with non-empty
|
|
74
|
+
`.ai-work/` directories are kept as "has untracked work records (.ai-work/)" by default, including
|
|
75
|
+
ignored records. Other ignored files (`node_modules`, build output) go with a delivered worktree.
|
|
75
76
|
|
|
76
77
|
- **When it runs.** After a Bash command that delivers or integrates work, and at the start of every
|
|
77
78
|
session, so orphans left by any earlier session, crash or harness are collected too.
|
|
@@ -79,9 +80,14 @@ build output, `.ai-work/`) go with a delivered worktree; they are the disk being
|
|
|
79
80
|
Harnesses with no hook wiring (Copilot, Cursor, OpenCode) rely on the **ship-changes** prompt, whose
|
|
80
81
|
final step runs the same script, and on running it by hand.
|
|
81
82
|
- **By hand.** `bash .cratis/ai/hooks/scripts/cratis-cleanup-worktrees.sh [--dry-run]` from any worktree;
|
|
82
|
-
run from the main checkout to also collect the worktree you are standing in.
|
|
83
|
-
-
|
|
84
|
-
|
|
83
|
+
run from the main checkout to also collect the worktree you are standing in. Add
|
|
84
|
+
`--include-work-records` only after preserving any records you still need: it permits deleting
|
|
85
|
+
`.ai-work/` content, but never overrides locks or other safety checks. Hook mode ignores this flag;
|
|
86
|
+
automatic hooks never opt in.
|
|
87
|
+
- **Pin a long-lived worktree.** Use `git worktree lock <path>` to keep it out of cleanup; release the
|
|
88
|
+
pin with `git worktree unlock <path>` when ready.
|
|
89
|
+
- **Self-test.** `--self-test` plants delivered, dirty, unmerged, brand-new, work-record and locked cases
|
|
90
|
+
(including detached locks), checks manual opt-in and hook protection, and fails if any is handled wrongly.
|
|
85
91
|
- **Opt out.** `CRATIS_HOOKS_SKIP_CLEANUP=1`.
|
|
86
92
|
|
|
87
93
|
## What is enforced
|
|
@@ -12,10 +12,14 @@
|
|
|
12
12
|
# 2. its tip is merged into origin/<default> and its upstream is gone (the PR branch was deleted), or
|
|
13
13
|
# 3. GitHub reports a merged pull request whose head commit is exactly this tip.
|
|
14
14
|
# Anything else is KEPT and reported with the reason. Nothing is ever forced: a dirty, locked or
|
|
15
|
-
# current worktree is kept,
|
|
15
|
+
# current worktree is kept, as is one holding .ai-work/ records unless explicitly opted in.
|
|
16
|
+
# `git worktree remove` is never given --force.
|
|
16
17
|
#
|
|
17
18
|
# Usage:
|
|
18
|
-
# cratis-cleanup-worktrees.sh [--dry-run] [--quiet] [--no-fetch]
|
|
19
|
+
# cratis-cleanup-worktrees.sh [--dry-run] [--quiet] [--no-fetch] [--include-work-records]
|
|
20
|
+
# run in the repository (any worktree)
|
|
21
|
+
# --include-work-records allow deletion of .ai-work/ records
|
|
22
|
+
# by hand only; ignored in hook mode
|
|
19
23
|
# cratis-cleanup-worktrees.sh --hook Claude hook mode: reads the hook JSON
|
|
20
24
|
# on stdin, acts only when relevant
|
|
21
25
|
# cratis-cleanup-worktrees.sh --self-test plants cases and fails if any is wrong
|
|
@@ -25,11 +29,12 @@
|
|
|
25
29
|
# shellcheck disable=SC2016 # the self-test checks are single-quoted on purpose: they are eval-ed later
|
|
26
30
|
set -uo pipefail
|
|
27
31
|
|
|
28
|
-
DRY=0; QUIET=0; FETCH=1; HOOK=0; SELFTEST=0
|
|
32
|
+
DRY=0; QUIET=0; FETCH=1; HOOK=0; SELFTEST=0; INCLUDE_WORK_RECORDS=0
|
|
29
33
|
for a in "$@"; do
|
|
30
34
|
case "$a" in
|
|
31
35
|
--dry-run) DRY=1 ;; --quiet) QUIET=1 ;; --no-fetch) FETCH=0 ;;
|
|
32
36
|
--hook) HOOK=1; QUIET=1 ;; --self-test) SELFTEST=1 ;;
|
|
37
|
+
--include-work-records) INCLUDE_WORK_RECORDS=1 ;;
|
|
33
38
|
*) echo "cratis-cleanup-worktrees: unknown argument '$a'" >&2; exit 2 ;;
|
|
34
39
|
esac
|
|
35
40
|
done
|
|
@@ -37,6 +42,7 @@ done
|
|
|
37
42
|
# ── Hook mode: decide whether this event is worth a sweep ─────────────────────
|
|
38
43
|
EVENT="PostToolUse"
|
|
39
44
|
if [ "$HOOK" = 1 ]; then
|
|
45
|
+
INCLUDE_WORK_RECORDS=0
|
|
40
46
|
payload=''; IFS= read -r -d '' payload || true
|
|
41
47
|
[ "${CRATIS_HOOKS_SKIP_CLEANUP:-}" = 1 ] && exit 0
|
|
42
48
|
case "$payload" in *'"SessionStart"'*) EVENT="SessionStart" ;; esac
|
|
@@ -57,6 +63,7 @@ fi
|
|
|
57
63
|
if [ "$SELFTEST" = 1 ]; then
|
|
58
64
|
self=$(cd "$(dirname "$0")" && pwd)/$(basename "$0")
|
|
59
65
|
t=$(mktemp -d "${TMPDIR:-/tmp}/cleanup-selftest.XXXXXX"); trap 'rm -rf "$t"' EXIT
|
|
66
|
+
t=$(cd "$t" && pwd -P)
|
|
60
67
|
export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t CRATIS_CLEANUP_NO_GH=1
|
|
61
68
|
git init -q --bare -b main "$t/origin.git"
|
|
62
69
|
git clone -q "$t/origin.git" "$t/repo" 2>/dev/null; cd "$t/repo" || exit 2
|
|
@@ -66,6 +73,16 @@ if [ "$SELFTEST" = 1 ]; then
|
|
|
66
73
|
mk dirty; (cd "$t/wt-dirty" && echo x > x && git add x && git commit -qm x)
|
|
67
74
|
mk unmerged; (cd "$t/wt-unmerged" && echo u > u && git add u && git commit -qm u)
|
|
68
75
|
mk fresh # brand new, no commits: must survive
|
|
76
|
+
for b in records empty-records locked locked-detached; do
|
|
77
|
+
mk "$b"; (cd "$t/wt-$b" && echo "$b" > "$b" && git add "$b" && git commit -qm "$b")
|
|
78
|
+
git merge -q --no-ff "$b" -m "merge $b"
|
|
79
|
+
done
|
|
80
|
+
mkdir "$t/wt-records/.ai-work" "$t/wt-empty-records/.ai-work"
|
|
81
|
+
echo '.ai-work/' >> "$t/repo/.git/info/exclude"
|
|
82
|
+
echo handoff > "$t/wt-records/.ai-work/.handoff"
|
|
83
|
+
git -C "$t/wt-locked-detached" checkout -q --detach
|
|
84
|
+
git worktree lock "$t/wt-locked"
|
|
85
|
+
git worktree lock --reason pinned "$t/wt-locked-detached"
|
|
69
86
|
git branch loose-delivered main; (git checkout -q loose-delivered && echo l > l && git add l && git commit -qm l && git checkout -q main)
|
|
70
87
|
git merge -q --no-ff delivered -m "merge delivered" && git merge -q --no-ff dirty -m "merge dirty" && git merge -q --no-ff loose-delivered -m "merge loose"
|
|
71
88
|
git push -q origin main
|
|
@@ -82,7 +99,23 @@ if [ "$SELFTEST" = 1 ]; then
|
|
|
82
99
|
chk "fresh branch kept" 'git rev-parse -q --verify refs/heads/fresh >/dev/null'
|
|
83
100
|
chk "main kept" 'git rev-parse -q --verify refs/heads/main >/dev/null'
|
|
84
101
|
chk "report names the removal" 'printf "%s" "$out" | grep -q "removed worktree"'
|
|
85
|
-
|
|
102
|
+
chk "work records kept" '[ -f "$t/wt-records/.ai-work/.handoff" ]'
|
|
103
|
+
chk "work records branch kept" 'git rev-parse -q --verify refs/heads/records >/dev/null'
|
|
104
|
+
chk "work records reason reported" 'printf "%s" "$out" | grep -Fq "has untracked work records (.ai-work/)"'
|
|
105
|
+
chk "empty work records removed" '[ ! -d "$t/wt-empty-records" ]'
|
|
106
|
+
chk "locked worktree kept" '[ -d "$t/wt-locked" ]'
|
|
107
|
+
chk "locked branch kept" 'git rev-parse -q --verify refs/heads/locked >/dev/null'
|
|
108
|
+
chk "locked reason reported" 'printf "%s" "$out" | grep -Fq "worktree $t/wt-locked (locked): locked"'
|
|
109
|
+
chk "locked detached kept" '[ -d "$t/wt-locked-detached" ]'
|
|
110
|
+
chk "locked detached reported" 'printf "%s" "$out" | grep -Fq "worktree $t/wt-locked-detached (detached): locked"'
|
|
111
|
+
out=$(printf '%s' '{"hook_event_name":"SessionStart"}' | "$self" --no-fetch --include-work-records --hook 2>&1) || { echo "FAIL: hook exit $?"; echo "$out"; exit 1; }
|
|
112
|
+
chk "hook ignores opt-in" '[ -f "$t/wt-records/.ai-work/.handoff" ]'
|
|
113
|
+
out=$("$self" --no-fetch --include-work-records 2>&1) || { echo "FAIL: opt-in exit $?"; echo "$out"; exit 1; }
|
|
114
|
+
chk "opt-in removes work records" '[ ! -d "$t/wt-records" ]'
|
|
115
|
+
chk "opt-in removes branch" '! git rev-parse -q --verify refs/heads/records >/dev/null'
|
|
116
|
+
chk "opt-in keeps locked" '[ -d "$t/wt-locked" ]'
|
|
117
|
+
chk "opt-in keeps locked detached" '[ -d "$t/wt-locked-detached" ]'
|
|
118
|
+
[ "$fail" = 0 ] && echo "cratis-cleanup-worktrees self-test: 24 checks passed" && exit 0
|
|
86
119
|
echo "$out"; exit 1
|
|
87
120
|
fi
|
|
88
121
|
|
|
@@ -134,6 +167,13 @@ process_worktree() {
|
|
|
134
167
|
if ! ev=$(delivered "$sha" "$br" "$([ -n "$br" ] && track_of "$br")"); then
|
|
135
168
|
note_kept "worktree $wt ($name): work not delivered to $default"; return 0
|
|
136
169
|
fi
|
|
170
|
+
if [ "$INCLUDE_WORK_RECORDS" = 0 ] && [ -d "$wt/.ai-work" ]; then
|
|
171
|
+
local records
|
|
172
|
+
if ! records=$(find "$wt/.ai-work/." -mindepth 1 -maxdepth 1 -print -quit); then
|
|
173
|
+
note_kept "worktree $wt ($name): could not inspect work records (.ai-work/)"; return 0
|
|
174
|
+
fi
|
|
175
|
+
if [ -n "$records" ]; then note_kept "worktree $wt ($name): has untracked work records (.ai-work/)"; return 0; fi
|
|
176
|
+
fi
|
|
137
177
|
if [ -n "$(git -C "$wt" status --porcelain 2>/dev/null)" ]; then note_kept "worktree $wt ($name): delivered but has uncommitted changes"; return 0; fi
|
|
138
178
|
local kb; kb=$(du -sk "$wt" 2>/dev/null | awk '{print $1}')
|
|
139
179
|
if [ "$DRY" = 1 ]; then note_removed "worktree $wt ($name): would remove, $ev"; return 0; fi
|
|
@@ -61,7 +61,10 @@ cost real disk and accumulate across sessions. After the merge succeeds:
|
|
|
61
61
|
1. Leave the worktree you worked in: `cd` to the main checkout (`git worktree list` shows it first).
|
|
62
62
|
2. Run `bash .cratis/ai/hooks/scripts/cratis-cleanup-worktrees.sh` and report its summary line.
|
|
63
63
|
It fetches, checks out nothing, and removes only worktrees and local branches whose work is
|
|
64
|
-
verifiably on the default branch
|
|
64
|
+
verifiably on the default branch; it never forces and reports what it kept and why. Worktrees holding
|
|
65
|
+
non-empty `.ai-work/` directories are kept by default. Preserve any needed records before a manual
|
|
66
|
+
`--include-work-records` opt-in; automatic hooks never opt in. Use `git worktree lock <path>` to pin a
|
|
67
|
+
long-lived worktree; locked worktrees remain kept even with opt-in.
|
|
65
68
|
3. `git switch main && git pull --ff-only` in the main checkout so it matches the merged result.
|
|
66
69
|
|
|
67
70
|
Claude Code and Pi also run the script from a hook after `gh pr merge` and at session start; running it
|
|
@@ -17,7 +17,7 @@ Pick exactly one type per slice folder — determined by what the slice *does*.
|
|
|
17
17
|
|
|
18
18
|
| Type | What it does | Contents |
|
|
19
19
|
| --- | --- | --- |
|
|
20
|
-
| **State Change** | Accepts a command, appends events | Command + validator + event(s); optional `[Passive]` read
|
|
20
|
+
| **State Change** | Accepts a command, appends events | Command + validator + event(s); optional `[Passive]` for a current read; a rule that must hold under concurrency needs a decision read or constraint (see the `cratis-chronicle-decision-reads` skill, `references/choosing-how-a-rule-holds.md`) |
|
|
21
21
|
| **State View** | Projects events into a queryable read model | `[ReadModel]` + model-bound projection + static query method(s) |
|
|
22
22
|
| **Automation** | Reacts to events, calls external systems / `ICommandPipeline`, or returns follow-up commands/events (including to another stream) | Reactor only |
|
|
23
23
|
| **Translation** | Takes data from outside our own facts (an external system or another service) and records it as our facts | An adapter at the boundary, often a reactor |
|
|
@@ -42,8 +42,12 @@ dumps, and similar coordination files. These are **work records, not documentati
|
|
|
42
42
|
main checkout when a pull request merges or you finish a task (hooks also run it after
|
|
43
43
|
`gh pr merge` and at session start where the harness supports them, and **ship-changes**
|
|
44
44
|
ends with it). It removes a worktree and its branch only on evidence the work reached the
|
|
45
|
-
default branch — pushed is not merged — and never forces
|
|
46
|
-
|
|
45
|
+
default branch — pushed is not merged — and never forces. Worktrees with non-empty `.ai-work/`
|
|
46
|
+
directories are kept by default as "has untracked work records (.ai-work/)". Manual
|
|
47
|
+
`--include-work-records` permits deleting those records after you preserve what you need;
|
|
48
|
+
automatic hooks never opt in. Pin a long-lived worktree with `git worktree lock <path>`;
|
|
49
|
+
locked worktrees are always kept, even with opt-in. Other ignored files such as `.env` files
|
|
50
|
+
and local databases can still be deleted with a removed worktree, so move anything you
|
|
47
51
|
still need out first. Do not hand-remove worktrees or `git branch -D` a delivered branch
|
|
48
52
|
when the script can; and `gh pr merge --delete-branch` from inside a worktree leaves the
|
|
49
53
|
worktree and branch behind, which is why the script exists. If the branch must outlive the
|
|
@@ -390,7 +390,7 @@ Redaction is a system-event request that removes payload availability from the e
|
|
|
390
390
|
|
|
391
391
|
## Cross-slice patterns **[convention]**
|
|
392
392
|
|
|
393
|
-
Cross-slice access is **read-only and goes through Chronicle** — inject another slice's read model (validator/`Provide()`/`Handle()`), read by explicit key with `IReadModels.GetInstanceById`, mark a `[Passive]` projection for
|
|
393
|
+
Cross-slice access is **read-only and goes through Chronicle** — inject another slice's read model (validator/`Provide()`/`Handle()`), read by explicit key with `IReadModels.GetInstanceById`, mark a `[Passive]` projection for a current read (a rule that must hold under concurrency needs a decision read or constraint, see the `cratis-chronicle-decision-reads` skill's `references/choosing-how-a-rule-holds.md`), or react to its events. **Never** instantiate or DI another slice's command/handler/service.
|
|
394
394
|
|
|
395
395
|
**DCB (Dynamic Consistency Boundary):** the boundary is the event state explicitly
|
|
396
396
|
enrolled in guarded decisions, not every model a command reads. Use stream
|
|
@@ -205,9 +205,8 @@ Chronicle resolves the command's event source id in this order:
|
|
|
205
205
|
property on the command;
|
|
206
206
|
4. otherwise a freshly generated id.
|
|
207
207
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
on property order.
|
|
208
|
+
Two or more candidates raise `ARCCHR0002` (`[Key]` does not silence it); Arc
|
|
209
|
+
silently takes the first declared. Implement `ICanProvideEventSourceId`.
|
|
211
210
|
|
|
212
211
|
`[Key]` on a positional record's primary-constructor parameter is recognized
|
|
213
212
|
and counted once. Child-only/nested read-model types are not standalone
|
|
@@ -217,8 +216,9 @@ stream metadata on commands and aggregate roots.
|
|
|
217
216
|
Read [decisions and routing](references/decisions-and-routing.md) when a command
|
|
218
217
|
needs guarded state, stream-id templates, definition-backed routes, event tags or
|
|
219
218
|
post-commit `CompleteStream`. Plain read-model injection remains advisory;
|
|
220
|
-
`Result<,>`
|
|
221
|
-
|
|
219
|
+
`Result<,>` and `concurrency: true` are not protection; see
|
|
220
|
+
[choosing how a rule holds](../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md).
|
|
221
|
+
A returned `EventForEventSourceId` route wins over command context.
|
|
222
222
|
|
|
223
223
|
Two attributes are spelled `[Key]`. Chronicle reads `Cratis.Chronicle.Keys.KeyAttribute`.
|
|
224
224
|
Marking `System.ComponentModel.DataAnnotations.KeyAttribute` in an application
|
|
@@ -256,7 +256,8 @@ public record Open<Thing>(<ThingId> Id, <OwnerId> OwnerId)
|
|
|
256
256
|
- `Provide` runs after authorization and validation.
|
|
257
257
|
|
|
258
258
|
An Arc read model can also be injected directly into `Provide`, `Handle`, or a
|
|
259
|
-
`CommandValidator<T>` — but only by **the command's own resolved key
|
|
259
|
+
`CommandValidator<T>` — but only by **the command's own resolved key**, as a plain
|
|
260
|
+
read that guards nothing. Reading a
|
|
260
261
|
read model keyed by anything else needs an explicit by-id read, and an absent
|
|
261
262
|
instance does not always arrive as `null`. Read
|
|
262
263
|
[read-model injection](references/read-model-injection.md) before relying on a
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Protected decisions and routed streams
|
|
2
2
|
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Pick the guarded read
|
|
6
|
+
- Definition-backed routes and templates
|
|
7
|
+
- Tags and completion
|
|
8
|
+
- Decision specifications
|
|
9
|
+
- Sources at v22.75.0
|
|
10
|
+
|
|
3
11
|
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
4
12
|
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
5
13
|
|
|
@@ -7,8 +15,11 @@ Verified at **Arc v22.75.0**. These features require `Cratis.Arc.Chronicle`.
|
|
|
7
15
|
|
|
8
16
|
## Pick the guarded read
|
|
9
17
|
|
|
10
|
-
Plain injected read models and `IReadModels.GetInstanceById` are advisory
|
|
11
|
-
`Result<TEvent, ValidationResult>` rejects a request
|
|
18
|
+
Plain injected read models and `IReadModels.GetInstanceById` are advisory,
|
|
19
|
+
materialized or passive. A `Result<TEvent, ValidationResult>` rejects a request
|
|
20
|
+
but does not enroll a guard. Uniqueness and create-once belong to a Chronicle
|
|
21
|
+
constraint, not to any read. For the routing steps, the matrix and the traps read
|
|
22
|
+
[choosing how a rule holds](../../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md).
|
|
12
23
|
|
|
13
24
|
- For one stream, inject `IStreamReads` into `Provide`, call `ForCommand()`, and
|
|
14
25
|
return `StreamDecision.Append(...)` from `Handle`. It returns
|
|
@@ -19,20 +30,39 @@ Plain injected read models and `IReadModels.GetInstanceById` are advisory. A
|
|
|
19
30
|
`Provide`/`Handle` (`Exists`/`Instance`). Command-aware `IDecisionReads.Get<T>`
|
|
20
31
|
enrolls reads of other keys. Only Chronicle-admitted direct event-source-keyed
|
|
21
32
|
projections with a known event-type set qualify; reducers, joins, children,
|
|
22
|
-
|
|
33
|
+
open-ended event types and incomplete definitions are refused. Arc certifies parameterless
|
|
23
34
|
validators it constructs; constructor dependencies and uncertified instances
|
|
24
|
-
are refused
|
|
25
|
-
|
|
35
|
+
are refused: a protected command's discoverable validator needs exactly one
|
|
36
|
+
public parameterless constructor, otherwise the command fails with HTTP 500.
|
|
37
|
+
The decision model needs an `Id` property, an event-source key and a flat
|
|
38
|
+
projection; self-reducing models are refused like reducers. When the command has
|
|
39
|
+
two or more key candidates, implement `ICanProvideEventSourceId`: `[Key]` does
|
|
40
|
+
not silence `ARCCHR0002`, and Arc silently keys by the first eligible property
|
|
41
|
+
in declaration order. Keep all decision state out of validators, including
|
|
42
|
+
static members and service locators. `[Unprotected]` on the command opts out; never
|
|
26
43
|
combine it with `[ProtectedDecision]`. A parameter-level marker acknowledges
|
|
27
44
|
tooling, not a runtime opt-out. `Validate` is advisory, not a commit promise.
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
- `concurrency: true` on the routing attributes is **not** a guard for the
|
|
46
|
+
decision: Arc reads the narrowed tail after `Handle`, so it only widens or
|
|
47
|
+
narrows the window the default check covers. Exact returned scopes replace
|
|
48
|
+
automatic capture; remove the flags when returning `EventsWithConcurrencyScopes`
|
|
49
|
+
(ARCCHR0016). The default check also reads the tail after `Handle`, and the first
|
|
50
|
+
append into a scope is unchecked unless `CheckFirstAppendIntoAScope` is set.
|
|
31
51
|
|
|
32
52
|
Do not manually append or commit to bypass the owner-capable unit of work.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
The guard detects every matching event appended after its boundary, whoever wrote
|
|
54
|
+
it, but it protects only guarded decisions: an unguarded writer deciding on the
|
|
55
|
+
same facts can still append on stale state, so the rule holds only when every
|
|
56
|
+
deciding writer is guarded or the rule is a constraint. Protection does not guard an unguarded writer's own decision (a plain read,
|
|
57
|
+
`[Unprotected]` or a direct append), external state, revisions, redactions,
|
|
58
|
+
migrations, changes to projection definitions or writes that bypass the kernel's
|
|
59
|
+
serialized append path. Protection is per command and
|
|
60
|
+
opt-in; an unmarked command keeps its plain reads, and a conflict is returned as a
|
|
61
|
+
`ConcurrencyViolation` validation result with no automatic retry. A protected command that
|
|
62
|
+
stages no events commits an empty guarded batch: current kernels validate the
|
|
63
|
+
enrolled reads (a scope with an actual boundary or expecting no matching event) and write nothing, while a kernel that rejects an empty batch
|
|
64
|
+
raises `DecisionReadValidateOnlyNotSupported` (HTTP 500), so cover it with an
|
|
65
|
+
integration specification. In contrast, `StreamDecision.Append([])`
|
|
36
66
|
returns no scopes: use it only for an identical retry, not a rejected request.
|
|
37
67
|
|
|
38
68
|
## Definition-backed routes and templates
|
|
@@ -56,7 +56,8 @@ A command that carries no usable key at all fails inside the resolver with
|
|
|
56
56
|
failure rather than a server fault.
|
|
57
57
|
|
|
58
58
|
`ARC0006` warns when a read-model parameter is non-nullable, precisely because a
|
|
59
|
-
command-scoped read model can be missing
|
|
59
|
+
command-scoped read model can be missing (it does not fire for model-bound
|
|
60
|
+
projections). Make it nullable when absence is part
|
|
60
61
|
of the command's valid behavior; keep it non-nullable when absence really is a
|
|
61
62
|
rejection. When absence is a rejection, check the nullable parameter and return
|
|
62
63
|
`ValidationResult.Error(...)` through `Result<TEvent, ValidationResult>`; never
|
|
@@ -63,6 +63,11 @@ another version.
|
|
|
63
63
|
|
|
64
64
|
## Step 1 — Choose the mechanism by what the decision *is*
|
|
65
65
|
|
|
66
|
+
Which mechanism makes a rule hold under concurrent writers (constraint, protected
|
|
67
|
+
decision, stream decision, aggregate, scope, reactor repair) is routed in
|
|
68
|
+
[choosing how a rule holds](../cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md).
|
|
69
|
+
A validator is never that mechanism.
|
|
70
|
+
|
|
66
71
|
| The rule is… | Put it in |
|
|
67
72
|
| --- | --- |
|
|
68
73
|
| A reusable value invariant — length, format, range | `ConceptValidator<T>` on the concept type |
|
|
@@ -116,7 +121,11 @@ public class TransferFundsValidator : CommandValidator<TransferFunds>
|
|
|
116
121
|
- The validator is discovered by type — no registration.
|
|
117
122
|
- Constructor dependencies (read models, services) are injected. A read model
|
|
118
123
|
injected here resolves the same way as one injected into `Handle()`; see
|
|
119
|
-
Step 5 for what "the same way" actually means.
|
|
124
|
+
Step 5 for what "the same way" actually means. A validator that reads state is
|
|
125
|
+
**advisory only**: it shows the state at validation time and guards nothing, so
|
|
126
|
+
use it for a friendly early message, never as the rule. A `[ProtectedDecision]`
|
|
127
|
+
command refuses a discoverable validator unless it has exactly one public
|
|
128
|
+
parameterless constructor (otherwise HTTP 500), so keep state rules out of it.
|
|
120
129
|
- **Omit the validator entirely when there are no rules.** An empty subclass is
|
|
121
130
|
noise the reader has to check.
|
|
122
131
|
- Single-property intrinsic rules belong on `ConceptValidator<T>` instead, so
|
|
@@ -162,13 +171,18 @@ append. Choose the first boundary that fits at Arc v22.75.0:
|
|
|
162
171
|
2. Projected state: mark the command `[ProtectedDecision]` and take
|
|
163
172
|
`DecisionRead<T>` (`.Exists`/`.Instance`) or command-aware `IDecisionReads`.
|
|
164
173
|
Only Chronicle-admitted, direct event-source-keyed projections with known
|
|
165
|
-
event types qualify; reducers, joins, children and
|
|
174
|
+
event types qualify; reducers (including self-reducing models), joins, children and open-ended event
|
|
175
|
+
types are refused. The model needs an `Id` property.
|
|
166
176
|
Only parameterless validators constructed/certified by Arc run. Constructor
|
|
167
177
|
dependencies are refused; static/service-locator decision state is still your
|
|
168
178
|
responsibility. Command-level `[Unprotected]` opts out, not into safety.
|
|
169
179
|
3. Stream-level automatic scopes: `concurrency: true` on routing attributes
|
|
170
|
-
(`EventStreamId`, `EventStreamType`, `EventSourceType`).
|
|
171
|
-
|
|
180
|
+
(`EventStreamId`, `EventStreamType`, `EventSourceType`). It is **not** a guard
|
|
181
|
+
for the decision: like the default check it reads the tail after `Handle`.
|
|
182
|
+
Exact returned scopes take precedence; do not combine automatic capture with
|
|
183
|
+
exact scopes. A guard detects every matching event after its boundary, whoever
|
|
184
|
+
wrote it, but it protects only guarded decisions, so every writer that decides
|
|
185
|
+
on the rule needs one, or the rule must be a constraint.
|
|
172
186
|
|
|
173
187
|
`ARCCHR0011/0012` flag unprotected reads and immediate append bypasses. Return
|
|
174
188
|
events, never append them directly. Read
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cratis-chronicle-decision-reads
|
|
3
|
-
description: Guard a state-dependent Chronicle decision with IDecisionReads, projection admission, ambient unit-of-work enrollment and commit conflict handling. Use when an append must remain valid for the facts read, when choosing whole-source versus stream-scoped reads, or diagnosing DecisionReadRefused and scope conflicts. Do not use for ordinary query reads, append-time uniqueness alone, or defining an Arc command's ProtectedDecision API.
|
|
3
|
+
description: Guard a state-dependent Chronicle decision with IDecisionReads, projection admission, ambient unit-of-work enrollment and commit conflict handling, and choose which mechanism makes a write-side rule hold (constraint, decision read, stream decision, aggregate, explicit scope, reactor repair or a plain read). Use when an append must remain valid for the facts read, when a rule must hold under concurrent writers, when choosing whole-source versus stream-scoped reads, or diagnosing DecisionReadRefused and scope conflicts. Do not use for ordinary query reads, append-time uniqueness alone, or defining an Arc command's ProtectedDecision API.
|
|
4
4
|
license: MIT
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -15,6 +15,12 @@ carries a guard to commit. The append is rejected when a later event inside that
|
|
|
15
15
|
guard could change the decision. This is the Chronicle side of a dynamic
|
|
16
16
|
consistency boundary (DCB), not authorization or a replacement for unique constraints.
|
|
17
17
|
|
|
18
|
+
Read [choosing how a rule holds](references/choosing-how-a-rule-holds.md) first
|
|
19
|
+
when the question is which mechanism to use, or before writing code that reads
|
|
20
|
+
state and then appends. It carries the routing steps, the matrix with what not to
|
|
21
|
+
use, and the traps. A plain read, a validator read, `Result<,>` and
|
|
22
|
+
`concurrency: true` are never the guard.
|
|
23
|
+
|
|
18
24
|
## Verified product sources
|
|
19
25
|
|
|
20
26
|
| Product | Version | Sources |
|
|
@@ -34,9 +40,11 @@ compatibility checking to force a read through.
|
|
|
34
40
|
their unit-of-work ownership in a handler. The Chronicle `DecisionRead<T>`
|
|
35
41
|
below is not a license to invent an Arc wrapper shape.
|
|
36
42
|
- For a unique value claimed atomically or a closed stream, use
|
|
37
|
-
**cratis-chronicle-event-constraints**.
|
|
43
|
+
**cratis-chronicle-event-constraints**. A decision read guards one key's
|
|
44
|
+
history, not a value across keys: it is the wrong tool for uniqueness.
|
|
38
45
|
- For read-model declarations, use **cratis-chronicle-read-model** and
|
|
39
|
-
**cratis-chronicle-projection**. Ordinary `IReadModels` reads do not enroll
|
|
46
|
+
**cratis-chronicle-projection**. Ordinary `IReadModels` reads do not enroll
|
|
47
|
+
guards, materialized or passive.
|
|
40
48
|
- In model-first scope, settle the rule and its refusal/concurrency specifications
|
|
41
49
|
in the accepted model using **cratis-screenplay-event-modeling** before gap-fill.
|
|
42
50
|
Never broaden a projection or bypass model protection just to make admission pass.
|
|
@@ -46,7 +54,10 @@ compatibility checking to force a read through.
|
|
|
46
54
|
`IDecisionReads` is in `Cratis.Chronicle.ReadModels`; obtain the reader with
|
|
47
55
|
`eventStore.GetDecisionReads()` (`ReadModels/DecisionReadExtensions.cs`).
|
|
48
56
|
`Admit<T>()` / `AdmitForStream<T>()` check shape **without I/O**, returning
|
|
49
|
-
`DecisionReadAdmission(IsAdmitted, Reason)`.
|
|
57
|
+
`DecisionReadAdmission(IsAdmitted, Reason)`. The model needs an `Id` property
|
|
58
|
+
(string, or a Guid in lowercase hyphenated form) and an event-source-keyed flat
|
|
59
|
+
projection. Reducers, including self-reducing models (19.58.0), are refused with
|
|
60
|
+
`Reducer`; a missing `Id` or an unconvertible key refuses with `KeyConversion`. A successful shape check is not
|
|
50
61
|
runtime read success: definitions, key conversion and fold completion are also
|
|
51
62
|
checked while reading.
|
|
52
63
|
|
|
@@ -82,8 +93,12 @@ Enroll the read **before** staging its decision's events through
|
|
|
82
93
|
`EventLog.Transactional` and let the owning unit of work commit. Inspect
|
|
83
94
|
`IsSuccess`, append errors/constraint violations/concurrency violations and
|
|
84
95
|
`GetDecisionConflicts()`; the latter reports decision conflicts without exposing
|
|
85
|
-
sequence numbers.
|
|
86
|
-
|
|
96
|
+
sequence numbers. On a kernel whose append validators accept an empty batch
|
|
97
|
+
(Chronicle v19.59.1 does when a scope carries an actual boundary or expects no matching event), a checked empty
|
|
98
|
+
append validates its scope and writes nothing; a kernel that rejects it surfaces
|
|
99
|
+
`DecisionReadValidateOnlyNotSupported`, which fails closed. Do not mistake "no
|
|
100
|
+
event" for "no consistency check", and assert validate-only in an integration
|
|
101
|
+
specification before relying on it.
|
|
87
102
|
|
|
88
103
|
Do not attach a separate explicit concurrency scope to a source already guarded
|
|
89
104
|
by a decision read: `DecisionReadConflictsWithConcurrencyScope` rejects that
|
|
@@ -97,6 +112,26 @@ business rule; never resend stale events as if a retry fixed the decision. A
|
|
|
97
112
|
DCB guard protects event facts, not external side effects. Durable follow-up
|
|
98
113
|
belongs in a reactor/outbox; use **cratis-chronicle-reactor**.
|
|
99
114
|
|
|
115
|
+
## When not to use a decision read
|
|
116
|
+
|
|
117
|
+
A guard detects every matching event after its boundary, whoever wrote it, but it
|
|
118
|
+
protects only the decision that carries it. A writer that decides on the same facts
|
|
119
|
+
without a guard can still append on stale state, so the rule holds only when every
|
|
120
|
+
deciding writer is guarded or the rule is a constraint.
|
|
121
|
+
|
|
122
|
+
- Uniqueness or create-once: a constraint. Two keys that must each be unique are
|
|
123
|
+
not a read problem.
|
|
124
|
+
- A UX hint or a display: a plain read. A decision read costs about four calls per
|
|
125
|
+
attempt and refolds the key's whole history every time.
|
|
126
|
+
- A hot key with a long history: shorten the history, or accept an advisory read
|
|
127
|
+
and repair with a reactor.
|
|
128
|
+
- External state, revise/redact, other sequences: no guard covers them.
|
|
129
|
+
- The unit commits in the ASP.NET Core middleware: it commits after the response
|
|
130
|
+
and reports no concurrency violation. Call
|
|
131
|
+
`IUnitOfWorkCompletionFeature.CommitAsync()` before responding.
|
|
132
|
+
- Protection is opt-in in Arc (`[ProtectedDecision]`), so an unmarked command with
|
|
133
|
+
a read model is still unguarded.
|
|
134
|
+
|
|
100
135
|
## Verify
|
|
101
136
|
|
|
102
137
|
- The model is admitted and the read is protected and enrolled in the intended
|