@cratis/pi 7.188.2 → 7.189.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 (23) hide show
  1. package/package/corpus/harnesses/copilot/instructions/operational-safety.instructions.md +3 -4
  2. package/package/corpus/harnesses/copilot/instructions/scripting.instructions.md +1 -1
  3. package/package/corpus/harnesses/copilot/instructions/secrets.instructions.md +1 -0
  4. package/package/corpus/hooks/README.md +23 -0
  5. package/package/corpus/hooks/scripts/cratis-guard-secrets.sh +44 -12
  6. package/package/corpus/rules/operational-safety.md +3 -4
  7. package/package/corpus/rules/scripting.md +1 -1
  8. package/package/corpus/rules/secrets.md +1 -0
  9. package/package/corpus/skills/cratis-arc-elixir/SKILL.md +3 -0
  10. package/package/corpus/skills/cratis-arc-elixir/references/availability.md +79 -0
  11. package/package/corpus/skills/cratis-arc-hosting/SKILL.md +3 -0
  12. package/package/corpus/skills/cratis-arc-hosting/references/availability.md +115 -0
  13. package/package/corpus/skills/cratis-arc-react-page/references/availability.md +10 -0
  14. package/package/corpus/skills/cratis-screenplay-availability/SKILL.md +51 -4
  15. package/package/corpus/skills/cratis-screenplay-availability/references/review-checks.md +4 -0
  16. package/package/corpus/skills/cratis-screenplay-availability/references/runtime-ownership.md +3 -3
  17. package/package/corpus/skills/cratis-screenplay-availability/verification.json +6 -0
  18. package/package/corpus/skills/cratis-screenplay-model-review/SKILL.md +1 -1
  19. package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +3 -1
  20. package/package/corpus/skills/cratis-screenplay-toolchain/references/diagnostics.md +3 -1
  21. package/package/corpus/skills/cratis-screenplay-toolchain/references/screenplay-contract.json +3140 -79
  22. package/package/corpus/skills/cratis-screenplay-toolchain/references/screenplay-contract.version +1 -1
  23. package/package.json +1 -1
@@ -5,10 +5,9 @@ applyTo: "**/*"
5
5
 
6
6
  # Operational safety
7
7
 
8
- Operation-specific invariants that hold before any skill is chosen or file is open. Authority comes
9
- from [`capability-is-not-authority.md`](./capability-is-not-authority.instructions.md); credentials and data
10
- channels from [`secrets.md`](./secrets.instructions.md). All lines are **[contract]** (see
11
- [`general.md`](../../../rules/general.md)). They are policy, not a sandbox: none is mechanically enforced.
8
+ Before skills/files: [authority](./capability-is-not-authority.instructions.md), [credentials/data channels](./secrets.instructions.md).
9
+ All are **[contract]** ([general.md](../../../rules/general.md)): policy, not enforcement or a sandbox.
10
+ [Inline guards](../../../hooks/README.md#inline-interpreter-policy) are not sandboxes.
12
11
 
13
12
  ## Screenplay models and rendering
14
13
 
@@ -19,4 +19,4 @@ paths:
19
19
  - Use a C# file-based app (`dotnet run --file tool.cs`, `#:package` pinned) when the script needs .NET or Cratis libraries or shares types with the product. Do not use one in hooks or on per-call hot paths.
20
20
  - Hooks under `.cratis/ai/hooks` are POSIX sh compatible with bash 3.2, or Node. Read stdin with `IFS= read -r -d '' x || true`, never `$(</dev/stdin)`.
21
21
  - Do not add Python scripts or `python3` workflow steps to Cratis repositories unless the project itself is Python (for example the Chronicle Python client). Existing Python scripts are ported to Node opportunistically: when you substantially change one, port it in the same PR. There is no bulk port.
22
- - Agents: edit files with the edit/write tools, query JSON with `gh --jq`/`jq`, and use `node -e` or `node --input-type=module - <<'EOF'` for ad-hoc logic. Never `python3 -c`, and never rewrite files by script.
22
+ - Agents: edit files with the edit/write tools, query JSON with `gh --jq`/`jq`, and use `node -e` or `node --input-type=module - <<'EOF'` for trigger-free ad-hoc logic. Never `python3 -c`, and never rewrite files by script.
@@ -23,6 +23,7 @@ they also hold without it.
23
23
  - **[contract] Command-text checks cannot see** shell-piped code (`… | sh`, `bash -c "$(…)"`),
24
24
  recursive searches without filenames (`grep -r PASSWORD .`), or paths hidden in variables,
25
25
  aliases or scripts. The rules still apply; output redaction is the backstop.
26
+ - **[contract] Inline refusals:** Read exact non-credential files.
26
27
  - **[contract] After a guard block, narrowing to literal non-credential files is supported remediation,
27
28
  not a workaround.** Follow `Use instead`; never disguise the same secret read.
28
29
 
@@ -19,6 +19,29 @@ Three layers:
19
19
  | Quality gate (Pi) | explicit `cratis_quality_gate` tool | same script | only at a requested verification checkpoint | error on failure; no turn-end hook |
20
20
  | Handoff checker | not wired: run by the skill | `scripts/cratis-check-handoff.mjs` | local files and git only | errors fail; warnings are advisory unless `--strict` |
21
21
 
22
+ ### Inline interpreter policy
23
+
24
+ Inline interpreter argv programs (`node -e`/`--eval`/`-p`/`--print`, Python `-c`, Ruby/Perl/Lua/
25
+ osascript `-e`, Perl `-E`, PHP `-r`, Deno `eval`, Bun/tsx/ts-node eval/print, PowerShell
26
+ `-Command`/`-c`, and shell `-c` including `-lc`) and executable interpreter heredocs share a
27
+ boundary-aware protected-file vocabulary. When a parsed invocation and a vocabulary hit occur anywhere
28
+ in the Bash call, the guard refuses the call, even for comments, output strings or aliases of read APIs.
29
+ Wrappers and absolute executable paths are recognized; script operands and words merely mentioning an
30
+ interpreter are not inline invocations. Python `-m <module>` and Node `--test` are file-running modes,
31
+ not inline programs; eval flags and executable heredocs still receive the inline checks. Unknown startup
32
+ options fail closed when vocabulary is present.
33
+ The vocabulary combines the protected file stems above with `.aws/`, `credentials.json`, `secrets.yaml`
34
+ and `secrets.yml`; `credentials` needs word boundaries and `.pem` must not continue into an identifier.
35
+ Thus `withCredentials`, `RecordingCredentials` and `.pembroke` are allowed in heredocs, while the bare
36
+ word in Python `from google.oauth2 import credentials` is refused. File-shaped key extensions count,
37
+ but `Object.keys`, JSON, `process.env.NAME`, bare key properties and `.env.example` are not new triggers.
38
+ Existing argv taint refusals remain in force.
39
+ Quoted heredoc delimiters disable shell expansion, not interpreter execution. Plain-consumer heredocs
40
+ remain data. Use the read (Claude: Read) tool for an exact non-credential file after this refusal; splitting
41
+ or disguising the same interpreter read is not remediation. This best-effort text filter is **not a sandbox**:
42
+ encoded or split paths, external helper scripts and generated stdin can evade text analysis. OS-level
43
+ sandboxing or file permissions are the protection boundary; literal shell reads remain supported.
44
+
22
45
  For false positives, a literal-prefix trailing `*`, including literal directory components, can be
23
46
  resolved in a known, readable cwd and parent directory. A single reader may stand alone or appear in
24
47
  an `&&` chain of literal read-only Git metadata commands, optionally after a literal leading `cd`.
@@ -15,7 +15,10 @@
15
15
  # aliases, functions, script files and recursive searches without named files remain outside its text analysis.
16
16
  # Allowlisted safe shapes (each commented where it is implemented, each with specs): source-file names classified by
17
17
  # real secret patterns, a leading plain NAME=VALUE, quoted commit and pull request text, literal here-document
18
- # text, and link-target checks. Anything else naming a protected file is refused.
18
+ # text for plain consumers, and link-target checks. Inline interpreter programs and executable heredocs share
19
+ # boundary-aware protected file vocabulary. This text filter is not a sandbox: encoded paths, external scripts
20
+ # and arbitrarily assembled names need OS-level protection. See ../README.md#inline-interpreter-policy.
21
+ # Anything else naming a protected file is refused.
19
22
  #
20
23
  # Escape hatch for a human who authorized the read — set in the environment the agent harness was started
21
24
  # from, never inside the command (an assignment in the command is ignored):
@@ -806,15 +809,42 @@ function interpreter_hit(body, t, k, stem, from, p, before, after, kind) {
806
809
  before = (p > 1) ? substr(t, p - 1, 1) : ""
807
810
  after = substr(t, p + length(stem), 1)
808
811
  kind = INTERP_KIND[k]
812
+ # Template filenames and bare properties are not protected file vocabulary. Existing argv
813
+ # taint checks remain independent; process.env.NAME and data.key in heredocs are not reads.
814
+ if (stem == ".env" && substr(t, p + length(stem)) ~ /^\.(example|sample|template|dist|defaults)([^a-z0-9_]|$)/) { from = p + 1; continue }
809
815
  if (kind == "env" && before !~ /[]a-z0-9_)]/ && after !~ /[a-z0-9_]/) return stem
810
816
  if (kind == "ext" && (after == "\"" || after == "\047" || after == "`")) return stem
811
- if (kind == "name" && after !~ /[a-z0-9_]/) return stem
817
+ if (kind == "word" && before !~ /[a-z0-9_]/ && after !~ /[a-z0-9_]/) return stem
818
+ if (kind == "path" || kind ~ /^(name|suffix)$/ && after !~ /[a-z0-9_]/) return stem
812
819
  from = p + 1
813
820
  }
814
821
  }
815
822
  return ""
816
823
  }
817
- function read_heredocs(s, i, n, h, e, line, cmp, body, hit) {
824
+ function interpreter_name(b) {
825
+ return b ~ /^(node(js)?|deno|bun|python[0-9.]*|ruby|perl|php|lua|osascript|pwsh|powershell|dotnet|java|jshell|rscript|tclsh|julia|groovy|tsx|ts-node|bash|sh|zsh|dash|ksh)$/
826
+ }
827
+ # Inspect only the executable selected after shell wrappers; later script operands are data, not flags.
828
+ # Unknown startup switches fail closed when vocabulary is present rather than guessing their arity.
829
+ function interpreter_invocation(A, s, n, b, k, option) {
830
+ if (nheredoc > 0) { hd_interp = 1; INLINE = 1 }
831
+ if (b ~ /^(bash|sh|zsh|dash|ksh)$/) return
832
+ for (k = s + 1; k <= n; k++) {
833
+ option = tolower(A[k])
834
+ if (option == "--" || b ~ /^python/ && option ~ /^-m/) return
835
+ if (b ~ /^node(js)?$/ && option == "--test") continue
836
+ if (b == "deno" && option == "eval") { INLINE = 1; return }
837
+ if (b ~ /^(pwsh|powershell)$/ && option ~ /^-(c|command)$/) { INLINE = 1; return }
838
+ if (b ~ /^python/ && option ~ /^-c/ || b == "php" && option ~ /^-r/ ||
839
+ b ~ /^(node(js)?|bun|ruby|perl|lua|osascript|tsx|ts-node)$/ && option ~ /^-[ep]/ ||
840
+ b ~ /^(node(js)?|bun|tsx|ts-node)$/ && option ~ /^--(eval|print)(=|$)/) { INLINE = 1; return }
841
+ if (option !~ /^-/ || option == "-") return
842
+ if (option ~ /^--(input-type|require|loader|import)$/ || b ~ /^(node(js)?|bun|tsx|ts-node)$/ && option == "-r") { k++; continue }
843
+ if (option ~ /^--(input-type|require|loader|import)=/ || option ~ /^--(no-config|no-warnings|quiet)$/) continue
844
+ INLINE = 1; return
845
+ }
846
+ }
847
+ function read_heredocs(s, i, n, h, e, line, cmp, body) {
818
848
  for (h = 1; h <= nheredoc; h++) {
819
849
  body = ""
820
850
  while (i <= n) {
@@ -825,11 +855,9 @@ function read_heredocs(s, i, n, h, e, line, cmp, body, hit) {
825
855
  if (cmp == HD[h]) break
826
856
  body = body line "\n"
827
857
  }
858
+ if (hd_interp && interpreter_hit(body) != "") INLINE_HIT = 1
828
859
  if (hd_shell) enqueue(body)
829
- else {
830
- if (!HDQ[h]) heredoc_substitutions(body)
831
- if (hd_interp && (hit = interpreter_hit(body)) != "") { complex = 1; if (TAINT == "") TAINT = hit }
832
- }
860
+ else if (!HDQ[h]) heredoc_substitutions(body)
833
861
  }
834
862
  nheredoc = 0; hd_shell = 0; hd_interp = 0
835
863
  return i
@@ -1609,7 +1637,7 @@ function shell_invocation(A, s, n, k, j, flags, c, script) {
1609
1637
  if (j != length(flags) || expands(A[k + 1], mask_of(A, k + 1)) || !allowed_option(A[k + 1])) config_report()
1610
1638
  k++; break
1611
1639
  }
1612
- if (script) { enqueue(A[k + 1]); return }
1640
+ if (script) { INLINE = 1; enqueue(A[k + 1]); return }
1613
1641
  }
1614
1642
  if (nheredoc > 0) hd_shell = 1
1615
1643
  }
@@ -2102,6 +2130,8 @@ function git_content(A, s, n, subcommand, k, w, kind, ended, pathspec) {
2102
2130
  }
2103
2131
  }
2104
2132
  function analyze(A, s, n, w, b, k, names, p, config, get, show, first) {
2133
+ # Preserve decoded evidence before search-pattern, Git-path and source/template exemptions.
2134
+ for (k = s; k <= n; k++) if (interpreter_hit(A[k]) != "") INLINE_HIT = 1
2105
2135
  nrt = 0; nwrap = 0; delete REDIRECT_TOKENS; delete ROFF; first = s
2106
2136
  while (s <= n) {
2107
2137
  w = A[s]; b = base(w)
@@ -2139,7 +2169,7 @@ function analyze(A, s, n, w, b, k, names, p, config, get, show, first) {
2139
2169
  }
2140
2170
  if (expands(A[s], mask_of(A, s))) return dyn_command(A, s, n)
2141
2171
  b = base(A[s])
2142
- if (nheredoc > 0 && b ~ /^(node|nodejs|deno|bun|python[0-9.]*|ruby|perl|php|lua|osascript|pwsh|powershell|dotnet|java|jshell|rscript|tclsh|julia|groovy|tsx|ts-node)$/) hd_interp = 1
2172
+ if (interpreter_name(b)) interpreter_invocation(A, s, n, b)
2143
2173
  if (b == "cd" || b == "pushd" || b == "popd") { change_directory(A, s, n, b); return }
2144
2174
  check_bulk_roots(A, s, n, b)
2145
2175
  if (A[s] == "git") git_content(A, s, n)
@@ -2233,18 +2263,20 @@ BEGIN {
2233
2263
  }
2234
2264
  nextension = split("pem key p12 pfx jks keystore kdbx kubeconfig env", EXT, " ")
2235
2265
  ndispatch = split("cat tac nl less more head tail bat batcat strings xxd od hexdump cut sort uniq base64 wc dd cp mv ln rsync scp tar zip shopt set setopt unsetopt emulate grep egrep fgrep rg ag sed awk gawk mawk nawk busybox jq yq gojq jaq kubectl oc docker podman docker-compose gh vault aws az gcloud pulumi cratis printenv export declare typeset env bash sh zsh dash ksh eval", DN, " ")
2236
- ninterp = split(".env|env .env.local|name .env.production|name .envrc|name id_rsa|name id_ed25519|name id_ecdsa|name id_dsa|name .netrc|name .npmrc|name .pgpass|name .pypirc|name .git-credentials|name kubeconfig|name .kube/|name .aws/|name .docker/config.json|name credentials.json|name secrets.yaml|name secrets.yml|name .pem|ext .key|ext .p12|ext .pfx|ext .jks|ext .keystore|ext .kdbx|ext", INTERP_SPEC, " ")
2266
+ ninterp = split(".env|env .env.local|name .env.production|name .envrc|name id_rsa|name id_ed25519|name id_ecdsa|name id_dsa|name .netrc|name .npmrc|name .pgpass|name .pypirc|name .git-credentials|name kubeconfig|name .kube/|path .aws/|path .docker/|path credentials|word credential|word secrets.yaml|name secrets.yml|name /environ|name run/secrets|path .pem|suffix .key|ext .p12|ext .pfx|ext .jks|ext .keystore|ext .kdbx|ext", INTERP_SPEC, " ")
2237
2267
  for (i = 1; i <= ninterp; i++) { split(INTERP_SPEC[i], L, "|"); INTERP[i] = L[1]; INTERP_KIND[i] = L[2] }
2238
2268
  nstem = split(".env .pem .key .p12 .pfx .jks .keystore .kdbx id_rsa id_ed25519 id_ecdsa id_dsa .netrc .npmrc .pgpass .pypirc .git-credentials .kube/ kubeconfig credentials credential secrets.yaml secrets.yml .docker/ /environ run/secrets", STEM, " ")
2239
2269
  CMD = ENVIRON["GS_COMMAND"]
2240
2270
  for (pass = 1; pass <= 2; pass++) {
2241
2271
  delete queue; delete QUEUE_DIR; delete QUEUE_COUNT; queued = 0; qi = 0; delete seen; reports = ""
2242
2272
  delete CWD; ncd = 1; nwrap = 0; CWD[1] = ENVIRON["GS_CWD_FALLBACK"]; effective_dir = CWD[1]
2243
- nheredoc = 0; hd_shell = 0; hd_interp = 0; commands = 0; complex = 0; simple_ok = 1; TAINT = ""
2273
+ nheredoc = 0; hd_shell = 0; hd_interp = 0; INLINE = 0; INLINE_HIT = interpreter_hit(CMD) != ""; commands = 0; complex = 0; simple_ok = 1; TAINT = ""
2244
2274
  enqueue(CMD)
2245
2275
  while (qi < queued) { qi++; tokenize(queue[qi]) }
2246
2276
  if (pass == 1 && bindings > 0) continue
2247
- if (TAINT != "" && (complex || queued != 1 || commands != 1 || !simple_ok)) {
2277
+ if (INLINE && INLINE_HIT) {
2278
+ report("inline interpreter programs with protected file vocabulary cannot be checked safely", "the read (Claude: Read) tool for an exact non-credential file; use find/ls to locate files first. Never read credential files or disguise the same read in a variable, encoded string or script file")
2279
+ } else if (TAINT != "" && (complex || queued != 1 || commands != 1 || !simple_ok)) {
2248
2280
  other_reports = reports; reports = ""
2249
2281
  report("the command names a protected file (" TAINT ") and is not a single literal read", "run the read on its own with literal paths, e.g. cat .env.example; split compound commands into separate calls; do not build the name with variables, globs, loops, pipes, redirections or nested shells; for a commit message or PR body that mentions the name, write the text to a file with the file tool and pass the file")
2250
2282
  reports = reports other_reports
@@ -4,10 +4,9 @@ applyTo: "**/*"
4
4
 
5
5
  # Operational safety
6
6
 
7
- Operation-specific invariants that hold before any skill is chosen or file is open. Authority comes
8
- from [`capability-is-not-authority.md`](./capability-is-not-authority.md); credentials and data
9
- channels from [`secrets.md`](./secrets.md). All lines are **[contract]** (see
10
- [`general.md`](./general.md)). They are policy, not a sandbox: none is mechanically enforced.
7
+ Before skills/files: [authority](./capability-is-not-authority.md), [credentials/data channels](./secrets.md).
8
+ All are **[contract]** ([general.md](./general.md)): policy, not enforcement or a sandbox.
9
+ [Inline guards](../hooks/README.md#inline-interpreter-policy) are not sandboxes.
11
10
 
12
11
  ## Screenplay models and rendering
13
12
 
@@ -18,4 +18,4 @@ paths:
18
18
  - Use a C# file-based app (`dotnet run --file tool.cs`, `#:package` pinned) when the script needs .NET or Cratis libraries or shares types with the product. Do not use one in hooks or on per-call hot paths.
19
19
  - Hooks under `.cratis/ai/hooks` are POSIX sh compatible with bash 3.2, or Node. Read stdin with `IFS= read -r -d '' x || true`, never `$(</dev/stdin)`.
20
20
  - Do not add Python scripts or `python3` workflow steps to Cratis repositories unless the project itself is Python (for example the Chronicle Python client). Existing Python scripts are ported to Node opportunistically: when you substantially change one, port it in the same PR. There is no bulk port.
21
- - Agents: edit files with the edit/write tools, query JSON with `gh --jq`/`jq`, and use `node -e` or `node --input-type=module - <<'EOF'` for ad-hoc logic. Never `python3 -c`, and never rewrite files by script.
21
+ - Agents: edit files with the edit/write tools, query JSON with `gh --jq`/`jq`, and use `node -e` or `node --input-type=module - <<'EOF'` for trigger-free ad-hoc logic. Never `python3 -c`, and never rewrite files by script.
@@ -22,6 +22,7 @@ they also hold without it.
22
22
  - **[contract] Command-text checks cannot see** shell-piped code (`… | sh`, `bash -c "$(…)"`),
23
23
  recursive searches without filenames (`grep -r PASSWORD .`), or paths hidden in variables,
24
24
  aliases or scripts. The rules still apply; output redaction is the backstop.
25
+ - **[contract] Inline refusals:** Read exact non-credential files.
25
26
  - **[contract] After a guard block, narrowing to literal non-credential files is supported remediation,
26
27
  not a workaround.** Follow `Use instead`; never disguise the same secret read.
27
28
 
@@ -113,5 +113,8 @@ Phoenix and LiveView use the same application in process. Read
113
113
  - **Organize by feature.** Backend, generated proxies and React page of a feature share a
114
114
  folder. `layout: :colocated` generates that layout.
115
115
 
116
+ - **Availability is planned, not shipped.** Read [references/availability.md](references/availability.md) before
117
+ promising `not`, suspension or gates in Elixir.
118
+
116
119
  See [references/pitfalls.md](references/pitfalls.md) for the full list, and
117
120
  [references/product-sources.md](references/product-sources.md) for package facts.
@@ -0,0 +1,79 @@
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
+ # Availability in Arc for Elixir
5
+
6
+ Arc for Elixir ships availability (v1.3.0): the same model as Arc for .NET and Screenplay, in the same words.
7
+ Verify names against the package's `Documentation/availability.md`.
8
+
9
+ It is one gate and runs **first**, before binding, `Arc.Filter`, authorization and validation.
10
+
11
+ | Decision | Result |
12
+ | --- | --- |
13
+ | Available | The request continues to authorization and validation. |
14
+ | Not available, or unknown | Not authorized, reason `NotAvailable`, HTTP `403`. |
15
+ | Suspended | Not authorized, reason `Suspended`, HTTP `403`. |
16
+ | The decision could not be made | Retryable error (`isRetryable` true), HTTP `503`; never a denial. |
17
+
18
+ ## Configure and declare
19
+
20
+ ```elixir
21
+ config :my_app, MyApp.Arc,
22
+ availability: [
23
+ definition: MyApp.Availability,
24
+ audience_source: MyApp.AudienceSource,
25
+ suspension_source: MyApp.SuspensionSource,
26
+ pubsub: MyApp.PubSub
27
+ ]
28
+ ```
29
+
30
+ ```elixir
31
+ defmodule MyApp.Availability do
32
+ use Arc.Availability.Definition
33
+
34
+ audience "Plus", "Customers on the Plus package"
35
+ block "Paid", "Sold with Plus", for: ["Plus", "Admin"]
36
+ scope "MyApp.Fleet", with: "Paid"
37
+ value "vessel", MyApp.VesselValue
38
+ end
39
+
40
+ defmodule MyApp.Fleet.Vessels.DockVessel do
41
+ use Arc.Command
42
+ available for: ["Plus", "Admin"], not: "Preview", with: "Reported"
43
+ available when: Arc.Availability.Condition.equal("vessel.package", "Plus")
44
+ end
45
+ ```
46
+
47
+ - `for:` audience(s), one is enough; `not:` none may be held; `with:` a named block; `when:` a condition
48
+ (`Arc.Availability.Condition` data shared with other languages, or a module implementing the behaviour).
49
+ - On a read model `available` gates every query; `@query available: [...]` gates one query.
50
+ - Module, feature and slice come from `Arc.Descriptor.slice_location/2`.
51
+ - Conditions read `tenant`, `identity.user`, `arguments.<name>` (camelCase wire name) and `<name>.<path>` of a
52
+ provided value; tenant and identity always come from the server.
53
+ - Three values: available, unavailable, unknown. Only available opens a gate; an absent value is unknown for every
54
+ operator. `Arc.Availability.Engine` passes the shared conformance cases.
55
+
56
+ ## Sources: audiences granted and withdrawn, parts suspended and resumed
57
+
58
+ - `Arc.Availability.AudienceSource`: `grants(subject)` returns the audience names held. Undeclared audiences never match.
59
+ - `Arc.Availability.SuspensionSource`: `suspended/0` returns paths (`"Fleet"`, `"Fleet/Vessels"`,
60
+ `"Fleet/Vessels/Dock"`, or a part's full name); suspension is decided before any gate.
61
+ - `Arc.Availability.Memory` serves specifications and samples (`grant/2`, `withdraw/2`, `suspend/1`, `resume/1`).
62
+ - Call `Arc.Availability.changed/1` when a source changes; open sessions decide again, on every node with `:pubsub`.
63
+
64
+ ## Client
65
+
66
+ - `/.cratis/availability` is an observable query listing what is unavailable to the caller (name, module, feature,
67
+ slice, reason); `?part=<name>&arguments=<json>` asks about one part. A decision that cannot be made is a retryable error.
68
+ - Generated proxies carry `static readonly part` (part identity).
69
+ - LiveView: `<Arc.LiveView.Availability.available socket={@socket} version={@arc_availability} command={...}>`
70
+ hides a part (`Arc.LiveView.available?/3`). Hiding is presentation; the server still refuses.
71
+ - `Arc.Availability.Manifest.build/1`, `to_json/1`, `decode/1`, `decide/3` use the shared
72
+ `cratis-availability-manifest` (version 1).
73
+
74
+ ## Rules
75
+
76
+ - Model availability in Screenplay (`cratis-screenplay-availability`); do not invent a second gating mechanism.
77
+ - Keep the vocabulary: audiences are granted and withdrawn; parts are suspended and resumed.
78
+ - Unknown is closed; failure to decide is a retryable error, never a denial.
79
+ - Compare the C# side in `cratis-arc-hosting` (`references/availability.md`).
@@ -59,6 +59,9 @@ comes from `ArcOptions.Hosting.ApplicationUrl`, not an argument to `UseCratisArc
59
59
  Read [integrations and publish boundaries](references/integrations-and-publish.md)
60
60
  when selecting storage, disabling MVC, adding generated JSON contracts, or
61
61
  configuring the explorer.
62
+ Read [availability](references/availability.md) when gating, suspending or
63
+ asking availability of a module, feature, slice or part with
64
+ `arc.WithAvailability()`, typed audiences and `[AvailableFor<T>]`.
62
65
 
63
66
  ## Keep trust and discovery explicit
64
67
 
@@ -0,0 +1,115 @@
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
+ # Availability in a C# Arc host
5
+
6
+ ## Contents
7
+
8
+ - Where the engine lives
9
+ - Declare with types
10
+ - Suspension
11
+ - Proxies and asking
12
+ - Manifest file and shared cases
13
+ - Pitfalls
14
+
15
+ Availability decides whether a part (module, feature, slice, command, read model) exists for a tenant, user or
16
+ system caller. It is decided before `authorize` and is not authorization. The Screenplay model side is the
17
+ `cratis-screenplay-availability` skill; this page is the C# side. Facts come from the Arc availability
18
+ documentation (`Documentation/backend/csharp/availability.md` and `availability-engine/`).
19
+
20
+ ## Where the engine lives
21
+
22
+ - The engine is `Cratis.Arc.Availability`: gate expressions, evaluator, audiences, context values and the manifest.
23
+ It does not depend on ASP.NET and does not depend on `Cratis.Choreography`.
24
+ - `arc.WithAvailability()` registers the gates, the engine, an in-memory audience source by default and startup
25
+ validation that discovers gated parts and verifies the declared blocks once.
26
+ - `AddAvailability` registers the engine alone, for a host that is not a web application.
27
+ - `Cratis.Choreography.Availability` is an obsolete forwarder from Choreography 2.11.0. Move to the Arc types
28
+ (`Cratis.Arc.Availability`, `.Audiences`, `.Context`); `ChoreographyContextValueSource` is now
29
+ `AvailabilityContextValueSource`.
30
+
31
+ ## Declare with types
32
+
33
+ What you write in C# is what a model can say; a typo is a compile error because nothing is named by a string.
34
+
35
+ | Screenplay | C# |
36
+ | --- | --- |
37
+ | `audience Plus` | `public class Plus : Audience;` (summary is the description) |
38
+ | `availability DataQuality` | `public class DataQuality : AvailabilityBlock` with `Lines` |
39
+ | `for`, `with`, `not`, `when` | `For<T>()`, `With<T>()`, `Not<T>()`, `When` |
40
+ | `available for Plus` | `[AvailableFor<Plus>]` (up to three audiences; any opens the gate) |
41
+ | `available with DataQuality` | `[Available<DataQuality>]` |
42
+ | `available when <condition>` | `[AvailableWhen<HasPaidInvoice>]` |
43
+ | gate on a module, feature or slice | a type deriving from `AvailabilityScope` in its namespace |
44
+ | `provide vessel Vessel from query ...` | `[ProvideContext<Vessel>(...)]` |
45
+
46
+ ```csharp
47
+ public class Plus : Audience;
48
+
49
+ public class DataQuality : AvailabilityBlock
50
+ {
51
+ protected override IReadOnlyList<AvailabilityTerm> Lines =>
52
+ [
53
+ For<Plus>(),
54
+ When.On<Vessel>(_ => _.HasReported).IsTrue()
55
+ ];
56
+ }
57
+
58
+ [Command]
59
+ [AvailableFor<Plus, Preview>]
60
+ public record ResetScore(VesselId Vessel);
61
+
62
+ [Available<DataQuality>]
63
+ public class Feature : AvailabilityScope;
64
+ ```
65
+
66
+ - Every attribute is one line and every line must hold: `[AvailableFor<Plus>, AvailableFor<Preview>]` needs both.
67
+ For either, use `[AvailableFor<Plus, Preview>]` or a block.
68
+ - `For<T>()` and `With<T>()` combine with `&`, `|` and parentheses. `Not<T>()` applies to one audience and is
69
+ three-valued: an unknown audience keeps the gate closed. A `&` between different forms is separate lines;
70
+ a `|` between different forms or beneath `not` cannot be stated and the generator reports it.
71
+ - Conditions come in two forms. The restricted comparison (`When.On<Vessel>(_ => _.CommercialPackage).IsNot(Package.Basic)`,
72
+ with `Is`, `IsNot`, `IsTrue`, `In`, `NotIn`, `IsGreaterThan`, `IsAtLeast`, `IsLessThan`, `IsAtMost`) compiles to a
73
+ Screenplay `when`. An injectable `IAvailabilityCondition` class (`When.Condition<T>()` or `[AvailableWhen<T>]`) is
74
+ emitted as an opaque condition the model cannot read.
75
+ - Obsolete, with a migration table in the Arc docs: `[AvailableFor("name")]`, `[AvailableWith("name")]`, the
76
+ `AvailabilityExpression` factories, `GateNamespace`, `ContextValueCatalog.Declare` and `DeclaredAudiences`.
77
+
78
+ ## Suspension
79
+
80
+ Any discovered module, feature, slice or part can be suspended for a tenant, a user or the system without declaring
81
+ anything. Audiences are **granted and withdrawn**; parts are **suspended and resumed**.
82
+
83
+ - Reason `Suspended` (`AvailabilityReason.Suspended`), distinct from `NotAvailable`; both are HTTP 403.
84
+ - Checked first: before gates and before `authorize`. Suspension wins over every grant; a suspended module or feature
85
+ suspends what is beneath it. The newest decision per level and path wins.
86
+ - `ISuspensionSource` (`GetDecisions`, `OnChanged`) is what a product implements, fed by the events `PartSuspended`
87
+ and `PartResumed` (never `TenantSuspended`). `InMemorySuspensionSource` is the default. A source that cannot
88
+ answer is a retryable failure (503), never a suspension.
89
+ - Part paths are the slice location joined with `/` (`Fleet/DataQuality/QualityScores`); `DiscoveredParts.Entries()`
90
+ and `AvailabilityManifest.Parts` list what an operator can suspend.
91
+ - `/.cratis/availability` lists refused parts with their `reason`; MCP tools of a suspended part are left out.
92
+
93
+ ## Proxies and asking
94
+
95
+ - Regenerate the TypeScript proxies after updating: every command and query proxy (including model-bound read model
96
+ queries) declares `static part`. The gate stays on the server.
97
+ - `/.cratis/availability` accepts `part` and `arguments`, so a gate reading `arguments.vesselId` answers for one
98
+ vessel with the same gate that decides execution. In code: `IUnavailableParts.Get(PartQuestion)`.
99
+ - Frontend: see the [React availability reference](../../cratis-arc-react-page/references/availability.md).
100
+
101
+ ## Manifest file and shared cases
102
+
103
+ - One JSON format, `cratis.availability.manifest.json`, `format` `cratis-availability-manifest`, `version` 1, with a
104
+ schema in `Specifications/availability` of the Arc repository. It is written by the engine (`ManifestFileBuilder`)
105
+ and by the proxy generator at build (set `CratisAvailabilityManifest` to a path), and decided by
106
+ `ManifestFileEvaluator`.
107
+ - `Specifications/availability/vectors` holds shared data-driven cases any Arc engine can run. Named conditions
108
+ (code) are listed in the file but cannot be evaluated from it.
109
+
110
+ ## Pitfalls
111
+
112
+ - `AddArcAvailability` configured before `AddCratis()` was once discarded (gates lost, parts failed open); use
113
+ `arc.WithAvailability()` on a version that has the fix.
114
+ - Never use availability as authorization or the reverse; never model suspension in the Screenplay model.
115
+ - A decision failure is a retryable error, never `NotAvailable`.
@@ -48,6 +48,16 @@ import { AllAccounts } from './AllAccounts';
48
48
  proxy class/instance. Strings match the full name; proxies match their slice
49
49
  location. Missing slice metadata is not an authorization grant.
50
50
 
51
+ ## Ask for one part and its data
52
+
53
+ Generated command and query proxies declare `static part` (regenerate the proxies after updating Arc), so a part is a
54
+ proxy rather than a string. `useIsAvailable(part, args?)` and `askAvailability(part, args)` from `@cratis/arc/availability`
55
+ ask the server for one part, with the arguments the gate reads (for example `{ vesselId }`), using the same gate that
56
+ decides execution. `RequireAvailable` takes `args` and a `suspended` slot beside `unavailable`.
57
+
58
+ `Suspended` (an operator suspended the part) is told apart from `NotAvailable`: `isSuspended(result)` and, on a
59
+ `CommandResult`, `isSuspended` and `onSuspended`. Both are refusals with HTTP 403; neither is a failure to decide.
60
+
51
61
  ## Navigation and decisions in code
52
62
 
53
63
  `useAvailability()` returns the `Availability` decision: `isKnown`,
@@ -53,14 +53,57 @@ module Fleet
53
53
  - `availability <Name>` is a reusable rule. Its `for`, `when` and `with` lines must all hold;
54
54
  `with` builds on another availability. A `with` cycle is PLAY1137.
55
55
  - `available for <audiences>`, `available when <condition>`, `available with <Availability>`.
56
- `for` and `with` combine names with `and`, `or` and parentheses. A `when` is one condition with its own
56
+ `for` and `with` combine names with `and`, `or`, `not` and parentheses (see [`not`](#not-and-the-closing-pattern)). A `when` is one condition with its own
57
57
  `and`/`or`. One line holds one form; to mix forms, name them in an `availability` and use `with`.
58
58
  Several `available` lines on one construct all have to hold.
59
- - A gate is allowed on a module, feature, slice, command, query and screen. Gates AND down the
59
+ - A gate is allowed on a module, feature, slice, command, query, screen, and on a screen `action` or `data`
60
+ element (see [screen elements](#screen-elements)). Gates AND down the
60
61
  path from module to construct. Gate at the highest level that is true for everything beneath it.
61
62
  - The runtime context carries `$context.audiences`, the union of the tenant's, user's and
62
63
  system caller's audiences. Withdrawing a grant removes it from its own level only.
63
64
 
65
+ ## `not` and the closing pattern
66
+
67
+ `not` is an audience term: `available for Plus and not Incident` and `available for not Incident`, also on the
68
+ `for` line of an `availability` block. `not` binds tighter than `and`, then `or`, and applies to **one audience name**.
69
+
70
+ - It is three-valued. `not` of an unknown audience is unknown, so the part stays closed (**unknown never opens a gate**).
71
+ A part is closed for a *granted* audience: grant an `Incident` audience to close it, withdraw the grant to reopen it.
72
+ Do not list every other audience to simulate a negation.
73
+ - `PLAY1171` (error): `not` on a group (`not (Plus)`), on another `not`, on nothing, or on an availability in
74
+ `available with` (`with not Open`).
75
+ - `PLAY1139` skips any gate that contains `not`, as it skips `when`: it depends on grants the model cannot see.
76
+ - A negated audience is ESM v58 (`"negated": true` on the audience requirement). A model without `not` keeps its earlier version.
77
+
78
+ ## Screen elements
79
+
80
+ An element bound to a command or a query is offered only when the part is available and the caller is authorized.
81
+ That is **derived**; write nothing for it. The path is suspension first, then the module, feature, slice and construct
82
+ gates, then `authorize`.
83
+
84
+ - `available for | when | with` is allowed under a screen `action` (plain, not guarded) and a screen `data` directive,
85
+ one form per line. Elements with nothing bound (section, table, summary, component) take no gate.
86
+ - **An element gate can only narrow.** It is added to the derived path. `PLAY1172` (warning) reports a gate that can be on
87
+ while the bound part is not; narrow or remove it.
88
+ - Availability of an element is asked with the data the screen shows (for example the one vessel), not only the tenant and user.
89
+ - An element gate is ESM v59 (`"available"` on a screen `data` entry and `action`, written only when present).
90
+ - The reference evaluator reports everything available unless `SemanticScreenAvailability.Evaluate` is given a
91
+ `SemanticAvailabilityState` (audiences and suspended parts). A result carries a `Cause`: `NotAuthorized`,
92
+ `NotAvailable` or `Suspended`. `when` conditions stay undecided there. Specifications still run with everything available.
93
+
94
+ ## Suspension
95
+
96
+ An operator can suspend any module, feature, slice or part (command, read model) for a tenant, a user or the system,
97
+ and resume it. **The model declares nothing for this**; do not add an audience or a flag to simulate it.
98
+
99
+ - The reason is `Suspended`, distinct from `NotAvailable` (same 403; clients tell them apart by reason).
100
+ - It is checked **first**, before gates (so before audiences and context values resolve) and before `authorize`.
101
+ A suspension at any level wins over every grant (deny wins); suspending a module or feature suspends what is beneath it.
102
+ - Levels are tenant, user and system; the newest decision per level and path wins, so a later resume ends an earlier
103
+ suspension at the same level only.
104
+ - **Two pairs of verbs, kept apart:** audiences are **granted and withdrawn**; parts are **suspended and resumed**.
105
+ The events are `PartSuspended` and `PartResumed`. Never name one `TenantSuspended`; that belongs to another product.
106
+
64
107
  ## Rules the language holds
65
108
 
66
109
  - **Unknown never opens a gate.** A missing audience, a missing value, an unresolved condition or an
@@ -75,6 +118,7 @@ module Fleet
75
118
  the tenant's and system's audiences, never a user's.
76
119
  - **Persona `audience` lines are authoring only.** `audience Plus` under a `persona` tells the board, Studio
77
120
  and docs which audiences the persona is in. It changes nothing at runtime and is not in the executable model.
121
+ - **Suspension is not a gate.** It is runtime state, never in the model and never in a specification.
78
122
  - **Cross-slice warning (PLAY1139).** A screen action, form or reaction that `invokes` a command whose audiences
79
123
  can be off while the invoker's are on can be refused as not available. Align the audiences, or accept and say
80
124
  why. `when` conditions are opaque and skipped, never guessed.
@@ -136,7 +180,9 @@ Read [complete example](references/complete-example.md) for a model that compile
136
180
  ## Who owns what
137
181
 
138
182
  Read [runtime ownership](references/runtime-ownership.md) when a request asks where a gate is enforced, how
139
- audiences are granted, or whether application code can check one. Applications never call these directly.
183
+ audiences are granted, how parts are suspended, or whether application code can check one. The engine lives in Arc
184
+ (`Cratis.Arc.Availability`); for the typed C# declaration, see the Arc hosting skill's
185
+ [availability reference](../cratis-arc-hosting/references/availability.md).
140
186
 
141
187
  ## Review checks
142
188
 
@@ -146,7 +192,8 @@ Read [review checks](references/review-checks.md) before accepting a model that
146
192
 
147
193
  PLAY1119-1129 are `provide` (line shape, source, body, duplicates, reserved names, type override, query source, cycle).
148
194
  PLAY1130-1141 are `audience`, `availability` and `available` (shape, duplicates, undeclared, cycle, unprovided value,
149
- cross-slice invocation, gate tokens and parentheses). The full table is in the toolchain
195
+ cross-slice invocation, gate tokens and parentheses). PLAY1171 is a misplaced `not`; PLAY1172 is an element gate broader
196
+ than the bound part. The full table is in the toolchain
150
197
  [diagnostics](../cratis-screenplay-toolchain/references/diagnostics.md).
151
198
  Fix by changing the model: declare the audience, name the availability, provide the value or correct the key; never remove a
152
199
  gate to silence a warning.
@@ -26,6 +26,10 @@ with the construct address and the change to ask for; do not edit the model in a
26
26
  carries Chronicle's routing audience as a field.
27
27
  8. **Entitlements.** A package already enforced by Box Office modules is not also modeled as an audience unless
28
28
  the model deliberately reads a host value.
29
+ 9. **`not` use.** Each `not` negates one audience name and a granted audience (such as `Incident`) is what closes the part;
30
+ PLAY1171 is an error. A list of every other audience instead of `not` is a smell. `not` of an unknown audience stays closed.
31
+ 10. **Screen element gates.** A gate on a screen `action` or `data` only narrows the derived path of the bound part; PLAY1172 means it
32
+ is broader. Elements with nothing bound take no gate. Nothing models suspension (no audience, flag or command for it).
29
33
 
30
34
  ## Provided values
31
35
 
@@ -9,9 +9,8 @@ writes enforcement code and an application never calls the pieces below.
9
9
  | Piece | Owns |
10
10
  | --- | --- |
11
11
  | Screenplay | The language: `audience`, `availability`, `available`, `provide`, their diagnostics, and the reference evaluator (every gate available in specifications; opaque sources unsupported) |
12
- | Choreography engine | Evaluates an availability for a request: Available, Unavailable with a reason, or Unknown, which denies. A failure to decide is an error result, never a denial. Request-scoped context values are resolved lazily, once per request |
13
- | Showrunner GuestList | The audience contracts: public events that grant and withdraw an audience at tenant, user and system level, payload field `Audience`; the newest grant wins and a withdrawal removes only its own level |
14
- | Arc | Enforcement at the command and query boundary, before authorization, refusing with `NotAvailable` |
12
+ | Arc (`Cratis.Arc.Availability`) | The engine and the enforcement. Evaluates an availability for a request: Available, Unavailable with a reason (`NotAvailable` or `Suspended`), or Unknown, which denies. A failure to decide is an error result, never a denial. Context values are resolved lazily, once per request. Enforces at the command and query boundary, before authorization. Needs no ASP.NET: `arc.WithAvailability()` for an Arc host, `AddAvailability` for any other. Choreography's availability is an obsolete forwarder to Arc's |
13
+ | Showrunner GuestList | The audience contracts: public events that grant and withdraw an audience at tenant, user and system level, payload field `Audience`; the newest grant wins and a withdrawal removes only its own level. Suspension decisions come from `PartSuspended` and `PartResumed` through Arc's `ISuspensionSource` |
15
14
  | Stage | Renders and runs the admitted model with the engine; consumes it rather than owning it |
16
15
  | Direct | Not called by an application. Box Office module entitlements stay separate and unchanged |
17
16
 
@@ -19,6 +18,7 @@ writes enforcement code and an application never calls the pieces below.
19
18
 
20
19
  - The model declares audiences and never members. Do not add a membership event or a grant command to the
21
20
  model to simulate GuestList; granting is the runtime's job.
21
+ - Do not model suspension: no audience, flag or command. Suspension is operator state, checked first, and wins over every grant.
22
22
  - Chronicle's routing audience stays in event options and is never a field of an event.
23
23
  - A union of audiences comes from tenant, user and system levels; a reaction sees the tenant's and system's only.
24
24
  - Decide a hidden entry from `NotAvailable`, not from guessing the package in client code.
@@ -11,6 +11,12 @@
11
11
  { "kind": "skill-contains", "value": "PLAY1139" },
12
12
  { "kind": "skill-contains", "value": "$context.identity.claims.aud" },
13
13
  { "kind": "skill-contains", "value": "PLAY1124" },
14
+ { "kind": "skill-contains", "value": "PLAY1171" },
15
+ { "kind": "skill-contains", "value": "PLAY1172" },
16
+ { "kind": "skill-contains", "value": "`PartSuspended` and `PartResumed`" },
17
+ { "kind": "skill-contains", "value": "granted and withdrawn" },
18
+ { "kind": "skill-contains", "value": "An element gate can only narrow" },
19
+ { "kind": "skill-contains", "file": "references/runtime-ownership.md", "value": "Cratis.Arc.Availability" },
14
20
  { "kind": "skill-contains", "file": "references/runtime-ownership.md", "value": "Showrunner GuestList" },
15
21
  { "kind": "skill-contains", "file": "references/review-checks.md", "value": "A gate no persona can satisfy" },
16
22
  { "kind": "skill-contains", "file": "references/review-checks.md", "value": "A rule reading identity-derived values" }
@@ -155,7 +155,7 @@ P5 uses a fresh reviewer who authored nothing in scope; record reviewer/author m
155
155
 
156
156
  ## Availability and context pass
157
157
 
158
- For a model with `available` or `provide`, check: a gate no persona can satisfy, unreferenced or undeclared audiences, a gate used as authorization (or the reverse), a `provide` whose key cannot be resolved for a command, a rule reading identity-derived values, and specifications that depend on a gate. Read [review checks](../cratis-screenplay-availability/references/review-checks.md).
158
+ For a model with `available` or `provide`, check: a gate no persona can satisfy, unreferenced or undeclared audiences, a gate used as authorization (or the reverse), a `provide` whose key cannot be resolved for a command, a rule reading identity-derived values, specifications that depend on a gate, a `not` that is misplaced (PLAY1171) or replaces a granted audience with a list, and a screen element gate that is broader than its bound part (PLAY1172). Read [review checks](../cratis-screenplay-availability/references/review-checks.md).
159
159
 
160
160
  ## Rules
161
161
  - Compiler contracts (defects when the mode needs them): V1 must pass with warnings
@@ -257,7 +257,9 @@ choosing a whole action list rather than one labeled command, use block-form
257
257
  `when`/`otherwise` on click, double click, select or change:
258
258
  [guarded interactions](../cratis-screenplay-ui-composition/references/guarded-interactions.md).
259
259
 
260
- `available` and `provide`: `cratis-screenplay-availability`.
260
+ `available` and `provide`: `cratis-screenplay-availability`. A screen `action` or `data` bound to a command or query is offered only when the
261
+ bound part is available and the caller authorized; that is derived. An explicit `available` line under it (ESM v59) can only narrow
262
+ (PLAY1172 when broader); a section, table, summary or component takes none.
261
263
 
262
264
  ## How a bare name resolves
263
265