@cratis/pi 7.53.1 → 7.55.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.
- package/package/corpus/agents/backend-developer.md +1 -1
- package/package/corpus/agents/code-reviewer.md +1 -1
- package/package/corpus/agents/coordinator.md +1 -1
- package/package/corpus/agents/frontend-developer.md +1 -1
- package/package/corpus/agents/orchestrator.md +1 -1
- package/package/corpus/agents/planner.md +1 -1
- package/package/corpus/agents/screenplay-modeler.md +1 -1
- package/package/corpus/agents/slice-implementer.md +2 -2
- package/package/corpus/agents/spec-writer.md +1 -1
- package/package/corpus/harnesses/copilot/instructions/application-profile.instructions.md +1 -1
- package/package/corpus/harnesses/copilot/instructions/glossary.instructions.md +2 -0
- package/package/corpus/harnesses/copilot/instructions/profiles.instructions.md +1 -5
- package/package/corpus/harnesses/copilot/instructions/reactors.instructions.md +3 -2
- package/package/corpus/harnesses/copilot/instructions/vertical-slices.instructions.md +14 -1
- package/package/corpus/prompts/add-reactor.prompt.md +1 -1
- package/package/corpus/prompts/new-vertical-slice.prompt.md +1 -1
- package/package/corpus/prompts/write-specs.prompt.md +1 -1
- package/package/corpus/rules/application-profile.md +1 -1
- package/package/corpus/rules/glossary.md +2 -0
- package/package/corpus/rules/profiles.md +1 -5
- package/package/corpus/rules/reactors.md +3 -2
- package/package/corpus/rules/vertical-slices.md +14 -1
- package/package/corpus/skills/cratis-application-react-specifications/SKILL.md +1 -4
- package/package/corpus/skills/cratis-application-slice-conformance/SKILL.md +6 -10
- package/package/corpus/skills/cratis-application-slice-conformance/references/contract-and-precedence.md +3 -8
- package/package/corpus/skills/cratis-application-slice-specifications/SKILL.md +1 -3
- package/package/corpus/skills/cratis-arc-command/SKILL.md +1 -4
- package/package/corpus/skills/cratis-arc-command-execution/SKILL.md +1 -4
- package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +1 -4
- package/package/corpus/skills/cratis-arc-observable-query-http/SKILL.md +1 -4
- package/package/corpus/skills/cratis-arc-query-paging/SKILL.md +1 -4
- package/package/corpus/skills/cratis-arc-react-page/SKILL.md +1 -4
- package/package/corpus/skills/cratis-chronicle-event-constraints/SKILL.md +1 -4
- package/package/corpus/skills/cratis-chronicle-event-modeling/SKILL.md +16 -5
- package/package/corpus/skills/cratis-chronicle-event-modeling/references/event-log-cleanup-rollout.md +53 -0
- package/package/corpus/skills/cratis-chronicle-event-modeling/references/event-log-hygiene.md +92 -0
- package/package/corpus/skills/cratis-chronicle-event-type-migration/SKILL.md +1 -4
- package/package/corpus/skills/cratis-chronicle-projection/SKILL.md +7 -4
- package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +9 -3
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +1 -4
- package/package/corpus/skills/cratis-chronicle-read-model-specifications/SKILL.md +1 -3
- package/package/corpus/skills/cratis-chronicle-reducer/SKILL.md +1 -4
- package/package/corpus/skills/cratis-components-stepper-command-dialog/SKILL.md +1 -4
- package/package/corpus/skills/cratis-screenplay-discovery/SKILL.md +1 -2
- package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +1 -7
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/SKILL.md +9 -9
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/opt-in.md +3 -33
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/references/phases.md +1 -5
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/scripts/model-first-self-test.mjs +104 -0
- package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/scripts/model-first-status.mjs +141 -0
- package/package/corpus/skills/cratis-screenplay-toolchain/SKILL.md +1 -1
- package/package/corpus/skills/cratis-specification-by-example/SKILL.md +1 -3
- package/package/corpus/skills/cratis-specifications-csharp/SKILL.md +1 -4
- package/package.json +1 -1
|
@@ -10,10 +10,7 @@ Arc applies paging and sorting for you. You never write `Skip`/`Take` or read
|
|
|
10
10
|
the query string — you choose a **return shape** that the framework can narrow.
|
|
11
11
|
|
|
12
12
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
13
|
-
repository is opted in (
|
|
14
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
15
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
16
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
13
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
17
14
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
18
15
|
say so and do not author `.play` from memory.
|
|
19
16
|
Edit code here only for infrastructure, clients, adapters, Screenplay code
|
|
@@ -10,10 +10,7 @@ Build the page from the generated Arc proxies and the Cratis Components
|
|
|
10
10
|
wrappers. Do not hand-roll a table, a dialog, or a fetch.
|
|
11
11
|
|
|
12
12
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
13
|
-
repository is opted in (
|
|
14
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
15
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
16
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
13
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
17
14
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
18
15
|
say so and do not author `.play` from memory.
|
|
19
16
|
Read the model's `screen` and `form` with
|
|
@@ -51,10 +51,7 @@ memory.
|
|
|
51
51
|
- You are writing the specification and want the `EventScenario` mechanics in
|
|
52
52
|
depth: use `cratis-chronicle-event-specifications`.
|
|
53
53
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
54
|
-
repository is opted in (
|
|
55
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
56
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
57
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
54
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
58
55
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
59
56
|
say so and do not author `.play` from memory.
|
|
60
57
|
Edit code here only for infrastructure, clients, adapters, Screenplay code
|
|
@@ -7,13 +7,10 @@ license: MIT
|
|
|
7
7
|
# Chronicle event modeling
|
|
8
8
|
|
|
9
9
|
> **Model-first check.** If an accepted model under the model root covers this scope, or the
|
|
10
|
-
> repository is opted in (
|
|
11
|
-
> file (`git ls-tree -r --name-only HEAD` lists a `.play` file there, narrowed to `-- <root>` when a root is configured), or the project explicitly set `mcpServers.screenplay.root` in
|
|
12
|
-
> `.cratis/ai.json`), the model is the source of truth: use
|
|
10
|
+
> repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`), the model is the source of truth: use
|
|
13
11
|
> `cratis-screenplay-event-modeling` (and the lifecycle in
|
|
14
12
|
> `cratis-screenplay-modeling-lifecycle`, which holds the master definition)
|
|
15
|
-
> instead of this skill.
|
|
16
|
-
> outside the root or an untracked or uncommitted draft is not consent. This skill is for
|
|
13
|
+
> instead of this skill. This skill is for
|
|
17
14
|
> hand-written C# models where the repository has not opted in (never force a
|
|
18
15
|
> model; only the entry-point session proposes one, at most once per session), and for
|
|
19
16
|
> code-level work against an already accepted contract (stream identity,
|
|
@@ -104,6 +101,20 @@ Do not append an event for derived or aggregate state. Project it from the sourc
|
|
|
104
101
|
events instead; an event that records a total is a fact that can disagree with
|
|
105
102
|
its own inputs.
|
|
106
103
|
|
|
104
|
+
## Only domain facts, never repeats
|
|
105
|
+
|
|
106
|
+
Append only real domain facts. A tick, a heartbeat, a `…Requested`/`…Started`/`…Skipped`/`…Undecided`
|
|
107
|
+
event whose only job is to wake a reactor, a "last looked" timestamp, usage or cost telemetry and a
|
|
108
|
+
non-answer such as "could not decide" are not facts; orchestrate with a durable job, a state machine,
|
|
109
|
+
a reminder, a command operation or `ICommandPipeline` instead. An observation command (webhook, poll,
|
|
110
|
+
sweep, retry, classifier) compares with current state and appends nothing when nothing changed.
|
|
111
|
+
`…Changed` must be a real change, and a counter built from `[Increment]`/`[Decrement]` needs commands
|
|
112
|
+
that refuse non-transitions. Read [references/event-log-hygiene.md](references/event-log-hygiene.md)
|
|
113
|
+
when modeling an event vocabulary, an observation command or a counter, or measuring a log that grows
|
|
114
|
+
faster than the product's activity. Read
|
|
115
|
+
[references/event-log-cleanup-rollout.md](references/event-log-cleanup-rollout.md) when a release removes
|
|
116
|
+
or reshapes many event types and the stored data must be repaired.
|
|
117
|
+
|
|
107
118
|
## Public facts and streams that end
|
|
108
119
|
|
|
109
120
|
Declare source vocabulary with `IEventSource`, `[EventSource]` and `[EventStream]`;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
2
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
3
|
+
|
|
4
|
+
# Rolling out a cleanup that removes or reshapes many event types
|
|
5
|
+
|
|
6
|
+
Read this when a release deletes or reshapes many event types in place (no generations) and the
|
|
7
|
+
stored data must be repaired to match. The mechanics of repair are repository-specific; these are
|
|
8
|
+
the traps that apply to any store.
|
|
9
|
+
|
|
10
|
+
## Contents
|
|
11
|
+
|
|
12
|
+
- Procedure
|
|
13
|
+
- Traps in the new code
|
|
14
|
+
- Traps in the repair
|
|
15
|
+
|
|
16
|
+
## Procedure
|
|
17
|
+
|
|
18
|
+
1. Scale every registrant of the store to zero so nothing appends or registers while data changes.
|
|
19
|
+
2. Back up every collection the repair writes, before the first write.
|
|
20
|
+
3. Run a **dry run** and review each count. Give every step a **fuse** (the most documents it may
|
|
21
|
+
touch, sized from the reviewed dry run) so a step over its fuse stops before writing; see
|
|
22
|
+
[guards-and-fuses.md](../../../rules/guards-and-fuses.md). Make the repair idempotent: a re-run skips work already done.
|
|
23
|
+
4. Apply, then restart the kernel if it caches the event type registry, then scale the application
|
|
24
|
+
back up.
|
|
25
|
+
5. **Wipe the whole schema registry** for the store rather than a hand-picked subset; the application
|
|
26
|
+
registers every current type again on start. A hand-picked list misses stale registrations and the
|
|
27
|
+
application crash-loops against them.
|
|
28
|
+
6. Verify the pages that read each reshaped model, then re-run the dry run: every step reports zero.
|
|
29
|
+
|
|
30
|
+
## Traps in the new code
|
|
31
|
+
|
|
32
|
+
- **A reactor added by the release catches up the whole history on first registration, and
|
|
33
|
+
`[OnceOnly]` does not cover that**: a first catch-up is not a replay. A side-effect reactor (jobs,
|
|
34
|
+
AI calls, external calls) therefore starts at the tail of the log, or its handlers ignore facts
|
|
35
|
+
that predate its registration. Specify that a new side-effect reactor does nothing for history.
|
|
36
|
+
- **Reconciliation sweeps must not decide from read models that are replaying.** A rebuilding model
|
|
37
|
+
looks like "nothing was ever processed" and the sweep starts the work again for everything. Decide
|
|
38
|
+
from the events or a `[Passive]` model, or refuse to run while the model's observer is replaying or
|
|
39
|
+
behind; specify the replaying case. See **cratis-chronicle-reactor**.
|
|
40
|
+
- **Re-recorded facts retrigger downstream consumers.** Recording facts again in a new shape (for
|
|
41
|
+
example a synchronizer re-emitting per-fact events once the broad event was removed) looks like new
|
|
42
|
+
evidence to gates and evaluations and supersedes concluded work. Make consumers follow what the
|
|
43
|
+
evidence says, not that an event arrived, and prefer rewriting the stored events over re-recording.
|
|
44
|
+
|
|
45
|
+
## Traps in the repair
|
|
46
|
+
|
|
47
|
+
- **Numbers written by `mongosh` are BSON doubles** and break `int64` event schemas. Write integers
|
|
48
|
+
with `NumberLong`.
|
|
49
|
+
- **Every observer whose read model is reset must actually replay.** After a reset, check each
|
|
50
|
+
observer's state and position: a projection left at position 0 without a running replay job leaves
|
|
51
|
+
its read model empty (counter projections were missed this way). Request the replay again and verify.
|
|
52
|
+
- **A dry run is evidence only for the data it saw.** Wait out the quiet period, run it again just
|
|
53
|
+
before applying, and investigate any count that grew before raising a fuse.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
2
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
3
|
+
|
|
4
|
+
# Event log hygiene
|
|
5
|
+
|
|
6
|
+
An event log that fills with ticks, triggers and repeats makes every projection replay noise
|
|
7
|
+
forever, grows the database without the product doing more, and hides real changes among
|
|
8
|
+
restatements. The log holds domain facts only.
|
|
9
|
+
|
|
10
|
+
## Contents
|
|
11
|
+
|
|
12
|
+
- What is not an event
|
|
13
|
+
- Orchestration without events
|
|
14
|
+
- Zero repeats in observation commands
|
|
15
|
+
- Event names
|
|
16
|
+
- Counters need clean transitions
|
|
17
|
+
- Measure the log
|
|
18
|
+
|
|
19
|
+
## What is not an event
|
|
20
|
+
|
|
21
|
+
A fact is something that happened in the domain and that the domain would still care about
|
|
22
|
+
after the process that noticed it is gone. These are not facts:
|
|
23
|
+
|
|
24
|
+
- **Ticks and heartbeats**: "still alive", "checked again", "retried", anything recorded because
|
|
25
|
+
time passed or a loop came round.
|
|
26
|
+
- **Signals**: an event appended so a reactor does something. `…Requested`, `…Started`,
|
|
27
|
+
`…Skipped`, `…Deferred`, `…Undecided`, `…Concluded` and `…Passed` used as triggers describe work
|
|
28
|
+
being asked for or the act of looking, not the world.
|
|
29
|
+
- **"When did we last look"**: a freshness timestamp belongs in a read model, a metric or job
|
|
30
|
+
state. Do not derive it from the time of the last recorded event; that makes it mean "the last
|
|
31
|
+
time anything was recorded".
|
|
32
|
+
- **Telemetry**: usage, token counts, cost, latency. Use metrics or an operational store unless
|
|
33
|
+
the figure is itself a business fact (a billable amount).
|
|
34
|
+
- **Non-answers**: `Pending`, `Computing`, "could not decide", "nothing was judged". The previous
|
|
35
|
+
fact stays; the process logs the non-answer and a later attempt answers.
|
|
36
|
+
- **Retry policy**: how often something was tried and when to try again lives in the retrying
|
|
37
|
+
process.
|
|
38
|
+
|
|
39
|
+
## Orchestration without events
|
|
40
|
+
|
|
41
|
+
Pick the mechanism that owns the progress, so progress is state of that mechanism, not events:
|
|
42
|
+
|
|
43
|
+
- a **durable job** (Cratis.Orleans jobs, see **cratis-orleans-jobs**) for work with steps, retries and pacing;
|
|
44
|
+
- an **event-sourced state machine** when the lifecycle is itself a domain fact sequence;
|
|
45
|
+
- an **Orleans reminder** to wake up later;
|
|
46
|
+
- a **command operation** (**cratis-arc-command-operation**) for inline work with compensation;
|
|
47
|
+
- **`ICommandPipeline`** (**cratis-arc-command-execution**) when a reactor or job must run a command.
|
|
48
|
+
|
|
49
|
+
## Zero repeats in observation commands
|
|
50
|
+
|
|
51
|
+
An *observation command* takes input from outside the model's own decisions: a webhook, a poll,
|
|
52
|
+
a sweep, a retry, a classifier result. The same fact is never recorded twice in a row on one stream.
|
|
53
|
+
|
|
54
|
+
- `Handle()` takes the thing it would change and returns no events when they agree. A bare
|
|
55
|
+
`=> new SomethingChanged(...)` is a defect for any command fed by polling, webhooks, retries or
|
|
56
|
+
classifiers.
|
|
57
|
+
- Compare **each fact on its own**, so a change in one does not re-record the others.
|
|
58
|
+
- Compare against something that **cannot lag**: a `[Passive]` read model read by key, or the
|
|
59
|
+
stream's own events. A materialized read model trails the log, so a guard reading it is bypassed
|
|
60
|
+
exactly while it is rebuilding or behind. A stale comparison may cost one extra event; it must
|
|
61
|
+
never drop a change. A poller may instead compare with the last-look store it writes itself.
|
|
62
|
+
- A passive model proves existence only through a flag set by the first event; read
|
|
63
|
+
[vertical-slices.md](../../../rules/vertical-slices.md) "Existence checks" first.
|
|
64
|
+
- Specify two behaviors per observation command: the **same observation twice appends nothing**,
|
|
65
|
+
and a **changed observation appends exactly the changed fact**. A command that can judge
|
|
66
|
+
nothing also gets a specification that "nothing judged" appends nothing.
|
|
67
|
+
|
|
68
|
+
## Event names
|
|
69
|
+
|
|
70
|
+
`…Changed` is a promise that something changed. An event of that name that can be appended with
|
|
71
|
+
nothing changed is wrong; so is `…Observed` appended on every sighting. Split a broad
|
|
72
|
+
`…DetailsChanged` into one event per fact (`…BodyChanged`, `…LabelsChanged`) so a change in one
|
|
73
|
+
field records one event and consumers subscribe to the facts they care about.
|
|
74
|
+
|
|
75
|
+
## Counters need clean transitions
|
|
76
|
+
|
|
77
|
+
`[Increment]`/`[Decrement]` projections know the event, not the item's previous state. A close for
|
|
78
|
+
an already closed item, or an add for one already present, drifts the counter permanently, and
|
|
79
|
+
replay reproduces the drift (a "failing builds" counter went deeply negative this way). The command that
|
|
80
|
+
appends a lifecycle event refuses a non-transition and appends nothing. Before shipping a counter,
|
|
81
|
+
fold the log per event source with the proposed mapping and compare the result with the state it
|
|
82
|
+
summarizes; any difference means the events are not clean transitions.
|
|
83
|
+
|
|
84
|
+
## Measure the log
|
|
85
|
+
|
|
86
|
+
- Set an **event volume budget** from the product's real activity (events per entity lifecycle and
|
|
87
|
+
per day) and alarm on a sustained rate far above it. A rate above budget is a defect to find.
|
|
88
|
+
- Count events per type and per day, then find `(event type, event source)` pairs with **identical
|
|
89
|
+
consecutive events** (same payload, ignoring sequence number and occurred time). Those are repeats a
|
|
90
|
+
missing comparison produced; each pair names the command to fix.
|
|
91
|
+
- Per entity, compare the measured events per lifecycle with the modeled ones; the difference is
|
|
92
|
+
almost always non-facts.
|
|
@@ -19,10 +19,7 @@ events.
|
|
|
19
19
|
## Route near misses
|
|
20
20
|
|
|
21
21
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
22
|
-
repository is opted in (
|
|
23
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
24
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
25
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
22
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
26
23
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
27
24
|
say so and do not author `.play` from memory.
|
|
28
25
|
Edit code here only for infrastructure, clients, adapters, Screenplay code
|
|
@@ -74,6 +74,12 @@ targets. Two things there are worth knowing before you write anything:
|
|
|
74
74
|
`[FromEvent<T>]` is an **object-initializer property**, never a constructor
|
|
75
75
|
argument: `[Count<TEvent>(ConstantKey = "<key>")]`.
|
|
76
76
|
|
|
77
|
+
A counter or aggregate (`[Increment<T>]`, `[Decrement<T>]`, `[Count<T>]`) sees the
|
|
78
|
+
event, not the item's previous state. Its commands must refuse non-transitions
|
|
79
|
+
(a close for an already closed item) or the counter drifts permanently and replay
|
|
80
|
+
reproduces the drift; see **cratis-chronicle-event-modeling**
|
|
81
|
+
(`references/event-log-hygiene.md`).
|
|
82
|
+
|
|
77
83
|
## Fluent projections — structured mappings
|
|
78
84
|
|
|
79
85
|
Use `Cratis.Chronicle.Projections.IProjectionFor<TReadModel>` when the mapping
|
|
@@ -271,10 +277,7 @@ projection spans streams.
|
|
|
271
277
|
## Route near misses
|
|
272
278
|
|
|
273
279
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
274
|
-
repository is opted in (
|
|
275
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
276
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
277
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
280
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
278
281
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
279
282
|
say so and do not author `.play` from memory.
|
|
280
283
|
Edit code here only for infrastructure, clients, adapters, Screenplay code
|
|
@@ -20,9 +20,7 @@ effects. If the answer is "populate a queryable model", it is not a reactor.
|
|
|
20
20
|
| both a model and an effect | one projection *and* one reactor |
|
|
21
21
|
|
|
22
22
|
> **Model first.** If an accepted model under the model root covers this scope, or
|
|
23
|
-
> the repository is opted in (
|
|
24
|
-
> committed `.play` file (`git ls-tree -r --name-only HEAD` lists a `.play` file there, narrowed to `-- <root>` when a root is configured), or the project explicitly set `mcpServers.screenplay.root` in
|
|
25
|
-
> `.cratis/ai.json`; master definition in `cratis-screenplay-modeling-lifecycle`), the automation is
|
|
23
|
+
> the repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`), the automation is
|
|
26
24
|
> a modeled slice: find it (`Automation` or `Translate`), treat its `produces` /
|
|
27
25
|
> `invokes`, conditions and fields as the contract, and write the reactor only as
|
|
28
26
|
> gap-fill for what the model leaves to code (Stage renders supported event-triggered Automation;
|
|
@@ -135,6 +133,14 @@ re-delivers the event as an ordinary observation, and a `[OnceOnly]` handler run
|
|
|
135
133
|
again. Catch-up and crash redelivery are not replay either; every ordinary
|
|
136
134
|
matching event can run, even on the same source. Keep effects idempotent.
|
|
137
135
|
|
|
136
|
+
**A reactor new to a store catches up the whole history on first registration, and
|
|
137
|
+
`[OnceOnly]` does not cover that.** For a side-effect reactor (jobs, AI or external
|
|
138
|
+
calls), start the observer at the tail or have the handler ignore facts that
|
|
139
|
+
predate its registration, and specify that history causes nothing. A
|
|
140
|
+
reconciliation sweep that decides from a read model must not run while that model's
|
|
141
|
+
observer is replaying or behind: a rebuilding model looks like "never processed".
|
|
142
|
+
Decide from the events or a `[Passive]` model, and specify the replaying case.
|
|
143
|
+
|
|
138
144
|
Analyzer **CHR0022** (warning) requires `[OnceOnly]` on a handler that returns
|
|
139
145
|
event side effects, because a replay would otherwise append duplicates.
|
|
140
146
|
|
|
@@ -249,10 +249,7 @@ spans streams.
|
|
|
249
249
|
## Route near misses
|
|
250
250
|
|
|
251
251
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
252
|
-
repository is opted in (
|
|
253
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
254
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
255
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
252
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
256
253
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
257
254
|
say so and do not author `.play` from memory.
|
|
258
255
|
Edit code here only for infrastructure, clients, adapters, Screenplay code
|
|
@@ -49,9 +49,7 @@ version.
|
|
|
49
49
|
readmodel` rows are the contract). Decide this with the decision rule in
|
|
50
50
|
`cratis-screenplay-modeling-lifecycle`: model-first only when an accepted
|
|
51
51
|
model under the model root covers this scope, or the repository is opted in
|
|
52
|
-
(
|
|
53
|
-
in `.cratis/ai.json`); an empty directory, install output, a `.play` file
|
|
54
|
-
outside the root or an uncommitted draft does not count, and framework, infrastructure, client, adapter and not-opted-in
|
|
52
|
+
(opted in per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`); framework, infrastructure, client, adapter and not-opted-in
|
|
55
53
|
brownfield work stays code-first. Opted in but no model for this scope: model
|
|
56
54
|
it first (`cratis-screenplay-discovery`, then `cratis-screenplay-slice-design`)
|
|
57
55
|
before writing specifications. If those Screenplay skills are not installed,
|
|
@@ -272,10 +272,7 @@ prove transport, replay, encryption, erasure or sink migration. Cover, at minimu
|
|
|
272
272
|
## Route near misses
|
|
273
273
|
|
|
274
274
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
275
|
-
repository is opted in (
|
|
276
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
277
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
278
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
275
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
279
276
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
280
277
|
say so and do not author `.play` from memory.
|
|
281
278
|
Edit code here only for infrastructure, clients, adapters, Screenplay code
|
|
@@ -207,10 +207,7 @@ validation failures), and guards against double submission.
|
|
|
207
207
|
## Route near misses
|
|
208
208
|
|
|
209
209
|
- An accepted `.play` model under the model root covers the behavior, or the
|
|
210
|
-
repository is opted in (
|
|
211
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`; an empty directory, install
|
|
212
|
-
output, an uncommitted `.play` draft or a `.play` file outside the root does not count; master definition:
|
|
213
|
-
`cratis-screenplay-modeling-lifecycle`): change the model first with
|
|
210
|
+
repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`): change the model first with
|
|
214
211
|
`cratis-screenplay-event-modeling`. If the Screenplay skills are not installed,
|
|
215
212
|
say so and do not author `.play` from memory.
|
|
216
213
|
Edit code here only for infrastructure, clients, adapters, Screenplay code
|
|
@@ -28,8 +28,7 @@ syntax and tool commands in `cratis-screenplay-toolchain`.
|
|
|
28
28
|
existing code or a database as the source (`cratis-screenplay-legacy-extraction`).
|
|
29
29
|
- Small change to an existing model (one or two events): enter at step 5.
|
|
30
30
|
- Model-first: work in `.play` where an accepted model under the model root covers the scope or
|
|
31
|
-
the repository is opted in (
|
|
32
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`). Otherwise stay code-first; only the
|
|
31
|
+
the repository is opted in (per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs`). Otherwise stay code-first; only the
|
|
33
32
|
entry-point session proposes a model, at most once per session; the master definition is in
|
|
34
33
|
`cratis-screenplay-modeling-lifecycle`. A direct request to model this scope is itself consent.
|
|
35
34
|
|
|
@@ -29,13 +29,7 @@ into the work that acts on them. Flag a real trade-off to the user instead of re
|
|
|
29
29
|
|
|
30
30
|
**1. Decide the level (short form; master copy in `cratis-screenplay-modeling-lifecycle`).**
|
|
31
31
|
Check first that the method skills are installed; installing them never opts a
|
|
32
|
-
repository in.
|
|
33
|
-
root (the folder holding the project's `.play` files) holds a committed `.play` file (`git ls-tree -r --name-only HEAD` lists a `.play` file there, narrowed to `-- <root>` when a root is configured), or the project explicitly set
|
|
34
|
-
`mcpServers.screenplay.root` in `.cratis/ai.json`. An empty directory, install output,
|
|
35
|
-
an installed skill, a `.play` file outside the root or an untracked or uncommitted draft is not
|
|
36
|
-
opt-in; staged or untracked files under the root are drafts. A committed file with uncommitted
|
|
37
|
-
working-tree edits is a model change in progress; its HEAD version is the contract until the
|
|
38
|
-
change is committed. A behavior is a contract only when an accepted model under the root covers it.
|
|
32
|
+
repository in. Decide opt-in per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs` for the decision, model root and drafts.
|
|
39
33
|
Otherwise stay code-first. Only the entry-point session proposes a model (at most once
|
|
40
34
|
per session, never for trivial, bug-fix, infrastructure, client, framework or
|
|
41
35
|
brownfield-maintenance work; unattended: record the recommendation in the final report).
|
|
@@ -18,16 +18,16 @@ an unproven pass.
|
|
|
18
18
|
|
|
19
19
|
## Decide the level first (master copy; run once per request, from any entry point)
|
|
20
20
|
|
|
21
|
-
1. **Opted in?**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
root counts). **Not opt-in:** an empty model folder or the MCP entry that `cratis ai
|
|
25
|
-
install`/`update` creates; an installed profile or skill; a `.play` file outside the root; a
|
|
26
|
-
staged or untracked `.play` file under the root (a draft). Committing a model under the root
|
|
27
|
-
is the team's act of acceptance and opts the repository in.
|
|
28
|
-
A committed file with uncommitted working-tree edits is a model change in progress: its HEAD version is the contract until the change is committed.
|
|
21
|
+
1. **Opted in?** A committed `.play` file under the model root or an explicitly configured
|
|
22
|
+
`mcpServers.screenplay.root` in `.cratis/ai.json` opts in (even an empty configured root).
|
|
23
|
+
The invariant is in `general.md` ("Model first").
|
|
29
24
|
A behavior is a **contract** only when an accepted (committed) model under the root covers it.
|
|
30
|
-
A direct user request to model a scope is consent for that scope.
|
|
25
|
+
A direct user request to model a scope is consent for that scope. Run `scripts/model-first-status.mjs` from the repository with Node.js and Git:
|
|
26
|
+
`node <skill-directory>/scripts/model-first-status.mjs [--root <repository-relative-dir>] [--json]`.
|
|
27
|
+
Read-only roots: `--root`, configuration, then discovery from HEAD project paths (drafts only if none). Discovery prefers legacy `.cratis/screenplay/`, else the common folder, else `Source/`, `src/`, `Screenplay/`. It excludes hidden/build/docs/samples/examples/scratch/test fixtures from discovery and acceptance, including at `.`; explicit roots include everything beneath them.
|
|
28
|
+
Output: root, reason, file counts, drafts and model changes. Exits: **0 opted in**, **1 not opted in**, **2 could not run** (Git/configuration/arguments). Treat 2 as blocked, not code-first.
|
|
29
|
+
Run `scripts/model-first-status.mjs --self-test` to plant and check verdict fixtures; it executes `scripts/model-first-self-test.mjs` and prints the checked count on success.
|
|
30
|
+
Read `references/opt-in.md` when checking the project configuration mechanism.
|
|
31
31
|
2. **Not opted in:** continue code-first; never force a model (framework, brownfield,
|
|
32
32
|
infrastructure, client and adapter work stays code-first). Only the entry-point agent or session
|
|
33
33
|
may **propose a model**: at most once per session, never for trivial, bug-fix, infrastructure,
|
|
@@ -23,40 +23,10 @@ project-owned `mcpServers` property in `.cratis/ai.json` overrides the model dir
|
|
|
23
23
|
disables registration"; `AiConfiguration.McpServers`, read by `AiMcpDescriptor.Root`). Verify with
|
|
24
24
|
`Source/Cli/Commands/Ai/AiMcpDescriptor.cs` in the CLI repository.
|
|
25
25
|
|
|
26
|
-
## Model root and
|
|
27
|
-
|
|
28
|
-
model, use `Source/` or `src/`, else `Screenplay/` at the repository root, never
|
|
29
|
-
under `.cratis/`. An explicitly configured `mcpServers.screenplay.root` selects
|
|
30
|
-
the root. A committed `.play` there is rule (a)'s opt-in signal without requiring
|
|
31
|
-
the setting; setting a root is independently rule (b), even when empty. The legacy
|
|
32
|
-
CLI discovery behavior above is historical evidence, not a default corpus root.
|
|
33
|
-
Do not count unrelated documentation, samples or scratch files as the project model.
|
|
34
|
-
|
|
35
|
-
## Edge cases
|
|
36
|
-
- `.play` files only under `.ai-work/`, a docs folder or a sample: not under the root, so not opt-in.
|
|
37
|
-
- Acceptance is visible in the repository: the model root holds at least one `.play` file in
|
|
38
|
-
the committed tree (`git ls-tree -r --name-only HEAD` lists a `.play` file there, narrowed to `-- <root>` when a root is configured). Committing a model
|
|
39
|
-
under the root is the team's act of acceptance and opts the repository in. P6 commits the
|
|
40
|
-
accepted `.play` files and `.screenplay/identities.json` when present.
|
|
41
|
-
- Staged or untracked files under the root are drafts: they do not opt the repository in and
|
|
42
|
-
are not a contract for code agents. The modeler writes drafts into the root as before; they
|
|
43
|
-
stay drafts until committed. A local STATE.md alone proves nothing to another clone.
|
|
44
|
-
- A committed file with uncommitted working-tree edits is a model change in progress. Its HEAD
|
|
45
|
-
version is the contract until the change is committed; `git diff --quiet HEAD -- <file>`
|
|
46
|
-
detects whether the working copy differs.
|
|
47
|
-
- An explicitly configured root (`mcpServers.screenplay.root`) that is empty still counts as
|
|
48
|
-
opted in; rule (b) is independent of rule (a).
|
|
26
|
+
## Model root and edge cases
|
|
27
|
+
Run `cratis-screenplay-modeling-lifecycle`'s `scripts/model-first-status.mjs` for root resolution, the opt-in verdict, drafts and model changes in progress.
|
|
49
28
|
- Declined proposals: a team that wants a lasting "no model" answer writes it in its own
|
|
50
29
|
repository instructions, never in managed corpus files.
|
|
51
30
|
|
|
52
31
|
## Acceptance test cases
|
|
53
|
-
|
|
54
|
-
except in the last row. A committed model is a contract only for the slice it covers.
|
|
55
|
-
|
|
56
|
-
| Case under the model root | Opted in? | Contract for code agents |
|
|
57
|
-
|---|---|---|
|
|
58
|
-
| Untracked `.play` file | No | None; draft |
|
|
59
|
-
| Staged-only `.play` file, absent from HEAD | No | None; draft |
|
|
60
|
-
| Committed `.play` file | Yes | Its HEAD version |
|
|
61
|
-
| Committed `.play` file with working-tree edits | Yes | Its HEAD version; edits are a model change in progress until committed |
|
|
62
|
-
| Explicitly configured empty root | Yes | None yet; model the slice first |
|
|
32
|
+
Run `scripts/model-first-status.mjs --self-test` for the executable verdict fixtures.
|
|
@@ -111,11 +111,7 @@ phase, a decision important enough that a later reader could misread the model (
|
|
|
111
111
|
- **Carry-forward**: the accepted **source identity** (`verdicts-and-modes.md`).
|
|
112
112
|
- **Commit at P6**: the accepted `.play` files and `.screenplay/identities.json` when present.
|
|
113
113
|
The user commits, or explicitly authorizes the owning session to commit; the modeler never
|
|
114
|
-
commits on its own.
|
|
115
|
-
and opts the repository in (`git ls-tree -r --name-only HEAD -- <root>` lists the `.play`
|
|
116
|
-
file). Staged or untracked files under the root are drafts, not contracts for code agents.
|
|
117
|
-
A committed file with working-tree edits is a model change in progress; its HEAD version is
|
|
118
|
-
the contract until the change is committed.
|
|
114
|
+
commits on its own. Run `cratis-screenplay-modeling-lifecycle`'s `scripts/model-first-status.mjs` to check acceptance, drafts and model changes in progress.
|
|
119
115
|
- **Gate**: explicit acceptance and the model commit before P7-P9. After committing, recompute
|
|
120
116
|
the source identity. Its digest must equal the digest reviewed at P5; only the commit part may
|
|
121
117
|
differ. If the digest differs, return to P4/P5 for the changed scope. Record the post-commit
|
package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/scripts/model-first-self-test.mjs
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
8
|
+
import { dirname, join, resolve } from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
export function selfTest(modelFirstStatus) {
|
|
11
|
+
const temporary = mkdtempSync(join(tmpdir(), 'model-first-self-test-'));
|
|
12
|
+
let cases = 0;
|
|
13
|
+
const write = (path, content) => {
|
|
14
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
15
|
+
writeFileSync(path, content);
|
|
16
|
+
};
|
|
17
|
+
const git = (repository, args) => {
|
|
18
|
+
const result = spawnSync('git', ['-c', 'user.name=Model first self-test', '-c', 'user.email=specs@example.invalid',
|
|
19
|
+
'-c', 'commit.gpgsign=false', '-c', 'core.hooksPath=/dev/null', ...args], { cwd: repository, encoding: 'utf8', timeout: 10000 });
|
|
20
|
+
assert.equal(result.status, 0, result.stderr || result.error?.message);
|
|
21
|
+
};
|
|
22
|
+
const repo = name => {
|
|
23
|
+
const repository = join(temporary, name);
|
|
24
|
+
mkdirSync(repository);
|
|
25
|
+
git(repository, ['init', '--quiet']);
|
|
26
|
+
return repository;
|
|
27
|
+
};
|
|
28
|
+
const check = (repository, expected, root) => {
|
|
29
|
+
const report = modelFirstStatus(repository, root);
|
|
30
|
+
assert.equal(report.optedIn, expected);
|
|
31
|
+
cases++;
|
|
32
|
+
return report;
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
const drafts = repo('drafts');
|
|
36
|
+
check(drafts, false);
|
|
37
|
+
write(join(drafts, 'Screenplay/model.play'), 'module Test\n');
|
|
38
|
+
assert.equal(check(drafts, false).drafts.untracked.length, 1);
|
|
39
|
+
git(drafts, ['add', 'Screenplay/model.play']);
|
|
40
|
+
assert.equal(check(drafts, false).drafts.staged.length, 1);
|
|
41
|
+
git(drafts, ['commit', '--quiet', '-m', 'Accept model']);
|
|
42
|
+
assert.equal(check(drafts, true).contract, 'HEAD');
|
|
43
|
+
write(join(drafts, 'Screenplay/model.play'), 'module Changed\n');
|
|
44
|
+
assert.equal(check(drafts, true).modelChangesInProgress.length, 1);
|
|
45
|
+
const configured = repo('configured');
|
|
46
|
+
write(join(configured, '.cratis/ai.json'), JSON.stringify({ mcpServers: { screenplay: { root: 'Models' } } }));
|
|
47
|
+
check(configured, true, 'Models');
|
|
48
|
+
write(join(configured, 'Models/model.play'), 'module Test\n');
|
|
49
|
+
assert.equal(check(configured, true, 'Models').committed.length, 0);
|
|
50
|
+
const outside = repo('outside');
|
|
51
|
+
write(join(outside, 'docs/example.play'), 'module Example\n');
|
|
52
|
+
git(outside, ['add', '.']);
|
|
53
|
+
git(outside, ['commit', '--quiet', '-m', 'Add example']);
|
|
54
|
+
check(outside, false);
|
|
55
|
+
assert.throws(() => modelFirstStatus(temporary), /git rev-parse/);
|
|
56
|
+
cases++;
|
|
57
|
+
write(join(configured, '.cratis/ai.json'), '{');
|
|
58
|
+
assert.throws(() => modelFirstStatus(configured));
|
|
59
|
+
cases++;
|
|
60
|
+
for (const [name, path] of [
|
|
61
|
+
['fixture', 'Source/X.Specs/Projections/for_model/Cases/fixture.play'],
|
|
62
|
+
['example', 'Source/examples/example.play'],
|
|
63
|
+
['docs', 'src/docs/example.play'],
|
|
64
|
+
]) {
|
|
65
|
+
const repository = repo(name);
|
|
66
|
+
write(join(repository, path), 'module Example\n');
|
|
67
|
+
git(repository, ['add', '.']);
|
|
68
|
+
git(repository, ['commit', '--quiet', '-m', 'Add non-project model']);
|
|
69
|
+
assert.equal(check(repository, false, undefined).modelFilesExamined, 0);
|
|
70
|
+
}
|
|
71
|
+
const project = repo('project');
|
|
72
|
+
write(join(project, 'Source/model.play'), 'module Test\n');
|
|
73
|
+
git(project, ['add', '.']);
|
|
74
|
+
git(project, ['commit', '--quiet', '-m', 'Accept project model']);
|
|
75
|
+
assert.equal(check(project, true, undefined).modelRoot, 'Source');
|
|
76
|
+
write(join(project, '.cratis/screenplay/draft.play'), 'module Draft\n');
|
|
77
|
+
assert.equal(check(project, true, undefined).modelRoot, 'Source');
|
|
78
|
+
git(project, ['add', '.cratis/screenplay/draft.play']);
|
|
79
|
+
assert.equal(check(project, true, undefined).modelRoot, 'Source');
|
|
80
|
+
const broad = repo('broad');
|
|
81
|
+
for (const path of ['Source/model.play', 'Other/model.play', 'Source/samples/example.play']) {
|
|
82
|
+
write(join(broad, path), 'module Test\n');
|
|
83
|
+
}
|
|
84
|
+
git(broad, ['add', '.']);
|
|
85
|
+
git(broad, ['commit', '--quiet', '-m', 'Add project and sample models']);
|
|
86
|
+
const broadReport = check(broad, true, undefined);
|
|
87
|
+
assert.equal(broadReport.modelRoot, '.');
|
|
88
|
+
assert.equal(broadReport.committed.length, 2);
|
|
89
|
+
write(join(broad, '.cratis/ai.json'), JSON.stringify({ mcpServers: { screenplay: { root: '.' } } }));
|
|
90
|
+
assert.equal(check(broad, true, undefined).committed.length, 3);
|
|
91
|
+
const aliasRepository = repo('alias');
|
|
92
|
+
const alias = join(aliasRepository, 'skills');
|
|
93
|
+
symlinkSync(resolve(dirname(fileURLToPath(import.meta.url)), '../..'), alias, 'dir');
|
|
94
|
+
const result = spawnSync(process.execPath, [join(alias, 'cratis-screenplay-modeling-lifecycle/scripts/model-first-status.mjs'), '--json'], {
|
|
95
|
+
cwd: aliasRepository, encoding: 'utf8', timeout: 20000,
|
|
96
|
+
});
|
|
97
|
+
assert.equal(result.status, 1, result.stderr);
|
|
98
|
+
assert.equal(JSON.parse(result.stdout).optedIn, false);
|
|
99
|
+
cases++;
|
|
100
|
+
console.log(`model-first-status self-test: checked ${cases} fixtures/verdicts; passed`);
|
|
101
|
+
} finally {
|
|
102
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
103
|
+
}
|
|
104
|
+
}
|