@cratis/pi 7.151.1 → 7.151.3

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 (17) hide show
  1. package/package/corpus/hooks/README.md +9 -0
  2. package/package/corpus/hooks/scripts/cratis-guard-secrets.sh +137 -6
  3. package/package/corpus/hooks/scripts/cratis-guard-shell-writes.sh +112 -9
  4. package/package/corpus/hooks/scripts/cratis-guard-writes.sh +2 -1
  5. package/package/corpus/skills/cratis-screenplay-reverse-engineering/SKILL.md +3 -3
  6. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/process-drift.md +2 -2
  7. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/drift-scope-self-test.mjs +25 -24
  8. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/fixtures/library-drift/change.diff +100 -0
  9. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/fixtures/library-drift/evidence-map.json +20 -0
  10. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/fixtures/library-drift/expected.json +54 -0
  11. package/package/corpus/skills/cratis-screenplay-ui-composition/SKILL.md +3 -3
  12. package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +10 -5
  13. package/package.json +1 -1
  14. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/fixtures/solocrm-drift/README.md +0 -23
  15. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/fixtures/solocrm-drift/change.diff +0 -131
  16. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/fixtures/solocrm-drift/evidence-map.json +0 -39
  17. package/package/corpus/skills/cratis-screenplay-reverse-engineering/scripts/fixtures/solocrm-drift/expected.json +0 -52
@@ -34,6 +34,15 @@ searches with secret/certificate/key-like prefixes also remain blocked. For ripg
34
34
  symlinks, not filename-only mode. Literal directory checks retain the process-cwd fallback when the
35
35
  payload omits cwd; glob probing does not. Filesystem check/use races remain: this is not a sandbox.
36
36
 
37
+ A Pi session runs guards from its starting checkout. Refresh the corpus there with `cratis ai update`,
38
+ or start a new session in the checkout you change. Selecting a newer installed guard corpus per call
39
+ is tracked in [Cratis/AI#1114](https://github.com/Cratis/AI/issues/1114).
40
+
41
+ Reader glob probes skip directories only when decoded options establish a nonrecursive reader;
42
+ unknown or recursive grep options keep directory matches conservative. Simple sed print/substitution
43
+ programs are data only without in-place edits, execution, or file writes; `-f` remains a file operand.
44
+ GitHub API endpoints are normalized before checking sensitive paths.
45
+
37
46
  The shell-write guard classifies **write-target words**, not every word. It lexes the command into
38
47
  simple commands. When every command is a reviewed reader or staging verb (`cat`, `head`, `tail`, `wc`,
39
48
  `ls`, `rg`, `grep`, `echo`, `git status|diff|log|show|add|commit`, `git ls-files`, `jq`, read-only
@@ -436,15 +436,91 @@ function split_scan(w, m, k, r, hit) {
436
436
  }
437
437
  return ""
438
438
  }
439
- function end_cmd( k, m, w, j, hit, exempt, path_git) {
439
+ # Admit only print/substitution scripts without secondary commands, execution or file writes.
440
+ function safe_sed_script(p, delimiter, i, c, spans) {
441
+ if (p ~ /^([0-9]+(,([0-9]+|\$))?|\$)?p$/) return 1
442
+ if (substr(p, 1, 1) != "s" || length(p) < 4) return 0
443
+ delimiter = substr(p, 2, 1)
444
+ if (delimiter ~ /[A-Za-z0-9\\ \t\n]/) return 0
445
+ for (i = 3; i <= length(p); i++) {
446
+ c = substr(p, i, 1)
447
+ if (c == "\n") return 0
448
+ if (c == "\\") { if (++i > length(p) || substr(p, i, 1) == "\n") return 0; continue }
449
+ if (c == delimiter && ++spans == 2) return substr(p, i + 1) ~ /^[gpI0-9]*$/
450
+ }
451
+ return 0
452
+ }
453
+ function sed_slots(A, s, n, i, w, program, explicit, ended, scripts) {
454
+ delete SED_DATA
455
+ for (i = s + 1; i <= n && A[i] != "--"; i++) if (A[i] ~ /^(-e|--expression)(=|$)/ || A[i] ~ /^-e./) explicit = 1
456
+ for (i = s + 1; i <= n; i++) {
457
+ w = A[i]
458
+ if (!ended && w == "--") { ended = 1; continue }
459
+ if (!ended && (w ~ /^-[nEr]+$/ || w ~ /^--(quiet|silent|regexp-extended)$/)) continue
460
+ if (!ended && (w == "-e" || w == "--expression")) { if (++i > n) return 0; program = A[i] }
461
+ else if (!ended && w ~ /^(-e.|--expression=)/) { program = w; sub(/^(-e|--expression=)/, "", program) }
462
+ else if (!ended && w ~ /^-/) return 0
463
+ else if (!explicit && !scripts) program = w
464
+ else continue
465
+ if (!safe_sed_script(program)) return 0
466
+ SED_DATA[i] = 1; scripts++
467
+ }
468
+ return scripts > 0
469
+ }
470
+ # Only fully modeled literal non-readers can distinguish data slots from paths.
471
+ function nonreader(A, M, n, i, w, first, read) {
472
+ delete DATA
473
+ for (i = 1; i <= n; i++) if (expands(A[i], M[i]) || index(A[i], "`") || A[i] ~ /^</) return 0
474
+ first = tolower(base(A[1]))
475
+ if (first == "sed") {
476
+ if (!sed_slots(A, 1, n)) return 0
477
+ for (i in SED_DATA) DATA[i] = 1
478
+ return 1
479
+ }
480
+ if (first == "dotnet") return A[2] ~ /^(test|build)$/
481
+ if (first == "git" && A[2] == "clone") {
482
+ for (i = 3; i <= n; i++) if (A[i] ~ /^(https?|ssh|git):\/\// || A[i] ~ /^git@/) DATA[i] = 1
483
+ return 1
484
+ }
485
+ if (first == "shellcheck") return 1
486
+ if (first == "find") {
487
+ for (i = 2; i <= n; i++) {
488
+ w = A[i]
489
+ if (w ~ /^>/) { if (w == ">" || w == ">>") i++; continue }
490
+ if (w ~ /^-(name|iname|path|regex|wholename)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
491
+ if (w ~ /^-(maxdepth|mindepth)$/) { if (++i > n || A[i] !~ /^[0-9]+$/) return 0; DATA[i] = 1; continue }
492
+ if (w ~ /^-/ && w !~ /^-(print|print0|type|L|P|H)$/) return 0
493
+ if (w == "-type") { if (++i > n || A[i] !~ /^[bcdflps]$/) return 0 }
494
+ }
495
+ return 1
496
+ }
497
+ if (first != "gh") return 0
498
+ read = A[2] " " A[3]
499
+ if (A[2] != "api" && read !~ /^(repo (view|list)|issue (view|list|status)|pr (view|list|status|diff|checks)|release (view|list)|run (view|list|watch)|search (issues|prs|repos|commits|code))$/) return 0
500
+ for (i = A[2] == "api" ? 3 : 4; i <= n; i++) {
501
+ w = A[i]
502
+ if (w ~ /^>/) { if (w == ">" || w == ">>") i++; continue }
503
+ if (w ~ /^(--jq|-q|--template|-t)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
504
+ if (w ~ /^(--json|--repo|-R|--limit|-L|--hostname|--header|-H)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
505
+ if (A[2] == "api" && w ~ /^(--method|-X)$/) { if (++i > n || A[i] !~ /^(GET|HEAD)$/) return 0; continue }
506
+ if (w ~ /^-/ && w !~ /^(--paginate|--slurp|--include|--silent|--log|--log-failed|--web)$/) return 0
507
+ if (A[2] != "api") DATA[i] = 1
508
+ }
509
+ return 1
510
+ }
511
+ function end_cmd( k, m, w, j, hit, exempt, path_git, paths_only) {
440
512
  flush_word()
441
513
  if (nw > 0) {
442
514
  commands++
515
+ delete PROBE_WORDS; PROBE_COUNT = nw
516
+ for (k = 1; k <= nw; k++) PROBE_WORDS[k] = W[k]
517
+ paths_only = nonreader(W, WM, nw)
443
518
  regex_slots(W, 1, nw)
444
519
  path_git = git_paths(W, WM, nw)
445
520
  for (k = 1; k <= nw; k++) {
446
521
  if (path_git && W[k] !~ /^-/) continue
447
522
  if (is_assign(W[k])) set_var(W[k], WM[k])
523
+ if (paths_only && ((k in DATA) || sensitive_path(W[k]) == "")) continue
448
524
  exempt = (k in RP) && !WU[k]
449
525
  if (exempt && RP[k] < 0) continue
450
526
  w = exempt ? substr(W[k], 1, RP[k]) : W[k]
@@ -735,6 +811,7 @@ function sensitive_path(w, l, b) {
735
811
  b ~ /credentials.*\.(yaml|yml|xml|ini|toml|txt|conf|properties|config)([.]|$)/ ||
736
812
  b ~ /secrets\.ya?ml([.]|$)/) return "a credentials file"
737
813
  if (l ~ /\.docker\/config\.json$/) return "the Docker registry credentials"
814
+ if (l ~ /(^|\/)(\.ssh|\.aws)\/?$/) return "a credential directory"
738
815
  if (l ~ /\/proc\/[^\/]*\/environ$/) return "a process environment"
739
816
  if (l ~ /^\/(var\/)?run\/secrets\//) return "mounted secrets"
740
817
  return ""
@@ -1017,7 +1094,10 @@ function probe_read_chain(text, prior, i, c, q, normal, n, k, readers, reader
1017
1094
  n = split(normal, parts, "\034")
1018
1095
  for (k = 1; k <= n; k++) {
1019
1096
  clause = parts[k]; sub(/^[ \t]+/, "", clause); sub(/[ \t]+$/, "", clause)
1020
- if (clause ~ /^(cat|rg|grep|egrep|fgrep|head|tail)[ \t]/) { readers++; reader_index = prior + k; continue }
1097
+ if (clause ~ /^(cat|rg|grep|egrep|fgrep|head|tail|wc)[ \t]/) {
1098
+ glob_recursive = reader_may_recurse(PROBE_WORDS, PROBE_COUNT)
1099
+ readers++; reader_index = prior + k; continue
1100
+ }
1021
1101
  if (clause ~ /^git[ \t]+diff([ \t]+(--cc|--stat|--check|--no-color))*$/) continue
1022
1102
  if (clause ~ /^git[ \t]+log([ \t]+(-[0-9]+|--format=[^ \t]+|--oneline|--no-color))*$/) continue
1023
1103
  if (clause ~ /^git[ \t]+(branch[ \t]+--show-current|rev-parse[ \t]+HEAD|status[ \t]+--short)$/) continue
@@ -1025,6 +1105,25 @@ function probe_read_chain(text, prior, i, c, q, normal, n, k, readers, reader
1025
1105
  }
1026
1106
  return readers == 1 && reader_index == commands
1027
1107
  }
1108
+ # Options are decoded by tokenize, not inferred from quote-masked command text.
1109
+ # Only known nonrecursive grep flags can justify skipping a directory. Unknown/value options refuse.
1110
+ function reader_may_recurse(A, n, i, j, w, b, ended, pattern) {
1111
+ b = base(A[1])
1112
+ if (b ~ /^(cat|head|tail|wc)$/) return 0
1113
+ if (b !~ /^(grep|egrep|fgrep)$/) return 1
1114
+ for (i = 2; i <= n; i++) {
1115
+ w = A[i]
1116
+ if (!ended && w == "--") { ended = 1; continue }
1117
+ if (!ended && w ~ /^-/) {
1118
+ if (w == "-e" || w == "--regexp") { if (++i > n) return 1; pattern = 1; continue }
1119
+ if (w ~ /^(-e.|--regexp=)/) { pattern = 1; continue }
1120
+ if (w ~ /^--/ || w !~ /^-[EFGPivwxcnNlLoqsaHIhVzuUSyZ0]+$/) return 1
1121
+ continue
1122
+ }
1123
+ if (!pattern) pattern = 1
1124
+ }
1125
+ return 0
1126
+ }
1028
1127
  function glob_directory( text, head, dir, prior) {
1029
1128
  dir = ENVIRON["GS_CWD"]; text = CMD
1030
1129
  if (ENVIRON["GS_GLOB_SAFE"] != "1" || dir == "" || dir !~ /^\//) return ""
@@ -1052,10 +1151,13 @@ function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count,
1052
1151
  "checked_cd() { local logical; logical=$(cd -L -- \"$1\" && pwd -P) || return 3; " \
1053
1152
  "cd -P -- \"$1\" || return 3; [ \"$logical\" = \"$PWD\" ] && [ -r . ] && [ -x . ]; }; " \
1054
1153
  "checked_cd \"$1\" || exit 3; parent=${2%/*}; stem=${2##*/}; [ \"$parent\" != \"$2\" ] || parent=.; " \
1055
- "checked_cd \"$parent\" || exit 3; " \
1056
- "n=0; for f in \"$stem\"*; do n=$((n+1)); [ \"$n\" -le 200 ] && [ -f \"$f\" ] && [ ! -L \"$f\" ] || exit 3; " \
1154
+ "probe=$parent; while [ ! -e \"$probe\" ]; do [ ! -L \"$probe\" ] || exit 3; next=${probe%/*}; " \
1155
+ "[ \"$next\" != \"$probe\" ] || next=.; probe=$next; done; " \
1156
+ "checked_cd \"$probe\" || exit 3; [ \"$probe\" = \"$parent\" ] || { echo OK; exit 0; }; " \
1157
+ "n=0; for f in \"$stem\"*; do n=$((n+1)); [ \"$n\" -le 200 ] && [ ! -L \"$f\" ] || exit 3; " \
1158
+ "if [ -d \"$f\" ]; then [ \"$3\" != 1 ] || exit 3; continue; fi; [ -f \"$f\" ] || exit 3; " \
1057
1159
  "case \"$PWD/$f\" in *[!a-zA-Z0-9._/@+=,:%-]*) exit 3;; esac; printf \"F:%s\\n\" \"$PWD/$f\"; done; echo OK"
1058
- cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(dir) " " shell_quote(prefix) " 2>/dev/null"
1160
+ cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(dir) " " shell_quote(prefix) " " shell_quote(glob_recursive ? "1" : "0") " 2>/dev/null"
1059
1161
  while ((cmd | getline line) > 0) {
1060
1162
  if (line == "OK") { ok = 1; continue }
1061
1163
  if (ok || substr(line, 1, 2) != "F:" || ++count > 200) { ok = 0; break }
@@ -1069,6 +1171,10 @@ function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count,
1069
1171
  }
1070
1172
  close(cmd)
1071
1173
  if (!ok) { matched_file = ""; return "a key or certificate file" }
1174
+ # Explicit credential-name prefixes stay protected even before those files exist.
1175
+ if (!count && base(prefix) != "") for (k = 1; k <= nprobe; k++) {
1176
+ if (index(PROBE[k], tolower(base(prefix))) == 1 && sensitive_path(PROBE[k]) != "") return sensitive_path(PROBE[k])
1177
+ }
1072
1178
  if (!count && !filenames_only && (base(prefix) ~ /^(secrets?|cert(ificate)?s?|keys?|private|credentials?)([._-]|$)/ || tolower(prefix) ~ /\.(pem|key|p12|pfx|jks|keystore|kdbx|kubeconfig|env)([._-]|$)/ || sensitive_path(dir "/" prefix) != "")) return "a key or certificate file"
1073
1179
  return found
1074
1180
  }
@@ -1080,6 +1186,8 @@ function alt_kind(a, b, d, kind, k, glob) {
1080
1186
  b = a; sub(/.*\//, "", b)
1081
1187
  glob = (a ~ /[\004-\006]/)
1082
1188
  if (!has_sentinel(a)) return sensitive_path(a)
1189
+ # A supported reader glob is judged by its real regular-file matches, not possible key basenames.
1190
+ if (glob && substr(a, length(a), 1) == "\004") return glob_secret_match(a)
1083
1191
  if (!glob) {
1084
1192
  kind = sensitive_path(a)
1085
1193
  if (kind != "") return kind
@@ -1284,7 +1392,21 @@ function dock(A, s, n, off, sub1, nxt, insp, k, listing) {
1284
1392
  }
1285
1393
  if (sub1 == "exec" && np >= 3 + off) analyze(A, PI[3 + off], n)
1286
1394
  }
1287
- function gh(A, s, n, i, w, mutating, k) {
1395
+ function endpoint_path(path, i, pair, value, decoded) {
1396
+ sub(/[?#].*$/, "", path)
1397
+ endpoint_uncertain = 0
1398
+ for (i = 1; i <= length(path); i++) {
1399
+ pair = tolower(substr(path, i + 1, 2))
1400
+ if (substr(path, i, 1) == "%" && length(pair) == 2 && pair ~ /^[0-9a-f][0-9a-f]$/) {
1401
+ value = HEX[substr(pair, 1, 1)] * 16 + HEX[substr(pair, 2, 1)]
1402
+ if (value < 32 || value == 127) { endpoint_uncertain = 1; return "" }
1403
+ decoded = decoded sprintf("%c", value); i += 2
1404
+ } else decoded = decoded substr(path, i, 1)
1405
+ }
1406
+ sub(/[?#].*$/, "", decoded); gsub(/\/\/+/, "/", decoded); sub(/\/+$/, "", decoded)
1407
+ return decoded
1408
+ }
1409
+ function gh(A, s, n, i, w, mutating, k, path, kind) {
1288
1410
  kparse(A, s + 1, n, "XHfFqtR")
1289
1411
  if (P[1] == "secret") {
1290
1412
  if (P[2] != "set" && P[2] != "delete" && P[2] != "remove")
@@ -1298,6 +1420,10 @@ function gh(A, s, n, i, w, mutating, k) {
1298
1420
  return
1299
1421
  }
1300
1422
  if (P[1] == "api") {
1423
+ for (k = 2; k <= np; k++) {
1424
+ path = endpoint_path(P[k]); kind = sensitive_path(path)
1425
+ if (endpoint_uncertain || kind != "") report("gh api endpoint names a protected file", "request only non-credential file contents; list filenames instead")
1426
+ }
1301
1427
  mutating = 0
1302
1428
  for (i = s + 1; i < n; i++) if (A[i] == "-X" || A[i] == "--method") { w = toupper(A[i + 1]); if (w == "PUT" || w == "PATCH" || w == "DELETE") mutating = 1 }
1303
1429
  if (!mutating)
@@ -1358,6 +1484,11 @@ function env_program(b, p, t) {
1358
1484
  }
1359
1485
  function reader(A, s, n, b, k, w, mode, havepat, need, afterdd, kind, valued, valued2, shortvals, filenames) {
1360
1486
  b = base(A[s]); mode = ""; valued = " "; valued2 = " "; shortvals = ""
1487
+ if (b == "sed") {
1488
+ sed_slots(A, s, n)
1489
+ for (k = s + 1; k <= n; k++) if (!(k in SED_DATA) && A[k] !~ /^-/) report_operand(A, k, b, 0)
1490
+ return
1491
+ }
1361
1492
  if (b == "busybox") { if (base(A[s + 1]) == "awk") reader(A, s + 1, n); return }
1362
1493
  if (b ~ /^(awk|gawk|mawk|nawk|jq|yq|gojq|jaq)$/) for (k = s + 1; k <= n; k++) env_program(b, A[k])
1363
1494
  if (b ~ /^(rg|grep|egrep|fgrep)$/) {
@@ -57,6 +57,9 @@ function quoted_literal(s) {
57
57
  return s
58
58
  }
59
59
  function raw_brace_word(w, quote, first, bare) {
60
+ # Unknown interpreter/program text may concatenate brace fragments: retain its conservative refusal.
61
+ # Modeled readers never send their opaque filters through this fallback.
62
+ if (unparsed && index(w, "{") && !index(w, "}")) candidate("*")
60
63
  if (!(w ~ /[$`"\047\\]/)) return
61
64
  first = substr(w, 1, 1); quote = (first == "\047" || first == "\"") ? first : ""
62
65
  if (quote != "" && substr(w, length(w), 1) == quote && index(substr(w, 2, length(w) - 2), quote) == 0) return
@@ -164,6 +167,7 @@ function endword() {
164
167
  if (redirect) {
165
168
  if (!(redirect == 2 && word ~ /^([0-9]+|-)$/)) {
166
169
  file_redirect = 1
170
+ redirect_words = redirect_words " " word
167
171
  if (changed_cwd || lead_glob) unparsed = 1
168
172
  if (changed_cwd || word ~ /[$`*?\[{~()]/ || protected(word)) bad = 1
169
173
  }
@@ -211,6 +215,7 @@ function options_allowed(verb, first, i, w) {
211
215
  }
212
216
  }
213
217
  if (verb == "git diff" && w ~ /^-U[0-9]+$/) continue
218
+ if (verb == "shellcheck" && w ~ /^--severity=(error|warning|info|style)$/) continue
214
219
  if ((verb == "git log" && w ~ /^--(format|pretty)=/) || (verb == "git show" && w ~ /^--format=/)) {
215
220
  if (index(w, "%(")) return 0
216
221
  continue
@@ -256,9 +261,41 @@ function directory_metadata() {
256
261
  if (argc == 5) return (W[4] == "status" && W[5] == "--short") || (W[4] == "rev-parse" && W[5] == "HEAD") || (W[4] == "branch" && W[5] == "--show-current")
257
262
  return argc == 6 && W[4] == "tag" && W[5] == "--list" && W[6] !~ /^-/
258
263
  }
259
- # -n alone is not read-only: sed scripts can still execute or write files.
260
- # Only numeric/last-line print addresses qualify, with no additional options.
261
- function print_only_sed( i, ended) {
264
+ # Keep this bounded sed grammar in sync with the secrets guard. Program files and unknown commands
265
+ # remain conservative; only print/substitution scripts without execution or file-write flags qualify.
266
+ function safe_sed_script(p, delimiter, i, c, spans) {
267
+ if (p ~ /^([0-9]+(,([0-9]+|\$))?|\$)?p$/) return 1
268
+ if (substr(p, 1, 1) != "s" || length(p) < 4) return 0
269
+ delimiter = substr(p, 2, 1)
270
+ if (delimiter ~ /[A-Za-z0-9\\ \t\n]/) return 0
271
+ for (i = 3; i <= length(p); i++) {
272
+ c = substr(p, i, 1)
273
+ if (c == "\n") return 0
274
+ if (c == "\\") { if (++i > length(p) || substr(p, i, 1) == "\n") return 0; continue }
275
+ if (c == delimiter && ++spans == 2) return substr(p, i + 1) ~ /^[gpI0-9]*$/
276
+ }
277
+ return 0
278
+ }
279
+ function sed_slots(A, s, n, i, w, program, explicit, ended, scripts) {
280
+ delete SED_DATA
281
+ for (i = s + 1; i <= n && A[i] != "--"; i++) if (A[i] ~ /^(-e|--expression)(=|$)/ || A[i] ~ /^-e./) explicit = 1
282
+ for (i = s + 1; i <= n; i++) {
283
+ w = A[i]
284
+ if (!ended && w == "--") { ended = 1; continue }
285
+ if (!ended && (w ~ /^-[nEr]+$/ || w ~ /^--(quiet|silent|regexp-extended)$/)) continue
286
+ if (!ended && (w == "-e" || w == "--expression")) { if (++i > n) return 0; program = A[i] }
287
+ else if (!ended && w ~ /^(-e.|--expression=)/) { program = w; sub(/^(-e|--expression=)/, "", program) }
288
+ else if (!ended && w ~ /^-/) return 0
289
+ else if (!explicit && !scripts) program = w
290
+ else continue
291
+ if (!safe_sed_script(program)) return 0
292
+ SED_DATA[i] = 1; scripts++
293
+ }
294
+ return scripts > 0
295
+ }
296
+ # Preserve the original protected-file read lane exactly; newly admitted programs below retain
297
+ # the pre-existing conservative file-operand check rather than broadening this exception.
298
+ function legacy_print_sed( i, ended) {
262
299
  if (argc < 4 || W[2] != "-n" || W[3] !~ /^([0-9]+(,([0-9]+|\$))?|\$)?p$/) return 0
263
300
  for (i = 4; i <= argc; i++) {
264
301
  if (!ended && W[i] == "--") { ended = 1; continue }
@@ -266,10 +303,69 @@ function print_only_sed( i, ended) {
266
303
  }
267
304
  return 1
268
305
  }
306
+ function print_only_sed( i, ended) {
307
+ if (legacy_print_sed()) return 1
308
+ if (!sed_slots(W, 1, argc)) return 0
309
+ for (i = 2; i <= argc; i++) {
310
+ if (i in SED_DATA) { if (globbed[i]) return 0; continue }
311
+ if (!ended && W[i] == "--") { ended = 1; continue }
312
+ if (!ended && W[i] ~ /^-/) continue
313
+ # Exempt script data, never the input paths: retain the existing protected-input refusal.
314
+ redirect_words = redirect_words " " W[i]
315
+ if (protected(W[i])) return 0
316
+ }
317
+ return 1
318
+ }
269
319
  # Verbs whose reviewed options are display flags only: a word-leading glob that expands to an option-shaped
270
320
  # file name can change what they print, never what they write or run. Every other verb refuses a leading glob.
321
+ function shell_quote(s) { gsub(/\047/, "\047\\\047\047", s); return "\047" s "\047" }
322
+ # rg can execute --pre supplied by a filename. Check real leading-glob matches, never command text.
323
+ function reader_globs( i, cmd, line, count, ok, script) {
324
+ if (changed_cwd || ENVIRON["GSW_GLOB_SAFE"] != "1") return 0
325
+ script = "cd -- \"$1\" && [ -r . ] && [ -x . ] || exit 3; unset GLOBIGNORE; shopt -s nullglob dotglob nocaseglob; " \
326
+ "n=0; while IFS= read -r f; do n=$((n+1)); [ \"$n\" -le 200 ] || exit 3; " \
327
+ "case $f in -*|*[!a-zA-Z0-9._/@+=,:%-]*) exit 3;; esac; printf \"F:%s\\n\" \"$f\"; done < <(compgen -G \"$2\"); echo OK"
328
+ for (i = 2; i <= argc; i++) {
329
+ if (W[i] == "--") return 1
330
+ if (!leading[i]) continue
331
+ cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(ENVIRON["GSW_CWD"]) " " shell_quote(W[i]) " 2>/dev/null"
332
+ ok = count = 0
333
+ while ((cmd | getline line) > 0) {
334
+ if (line == "OK") { ok = 1; continue }
335
+ if (ok || substr(line, 1, 2) != "F:" || ++count > 200) { ok = 0; break }
336
+ }
337
+ if (close(cmd) != 0 || !ok) return 0
338
+ }
339
+ return 1
340
+ }
271
341
  function glob_safe() {
272
- return W[1] ~ /^(cat|head|tail|wc|ls|grep|egrep|fgrep)$/ || (W[1] == "git" && W[2] == "ls-files")
342
+ return W[1] ~ /^(cat|head|tail|wc|ls|grep|egrep|fgrep|shellcheck)$/ || (W[1] == "rg" && reader_globs()) || (W[1] == "git" && W[2] == "ls-files")
343
+ }
344
+ function find_allowed( i, w, predicates) {
345
+ for (i = 2; i <= argc; i++) {
346
+ w = W[i]
347
+ if (w ~ /^-(name|iname|path|regex|wholename)$/) { if (++i > argc || globbed[i]) return 0; predicates++; continue }
348
+ if (w ~ /^-(maxdepth|mindepth)$/) { if (++i > argc || W[i] !~ /^[0-9]+$/) return 0; continue }
349
+ if (w ~ /^-/ && w !~ /^-(print|print0|type|L|P|H)$/) return 0
350
+ if (w == "-type") { if (++i > argc || W[i] !~ /^[bcdflps]$/) return 0 }
351
+ }
352
+ return predicates > 0
353
+ }
354
+ function gh_allowed( i, w, subcommand, read) {
355
+ subcommand = W[2] " " W[3]
356
+ read = subcommand ~ /^(repo (view|list)|issue (view|list|status)|pr (view|list|status|diff|checks)|release (view|list)|run (view|list|watch)|search (issues|prs|repos|commits|code))$/
357
+ if (W[2] != "api" && !read) return 0
358
+ for (i = W[2] == "api" ? 3 : 4; i <= argc; i++) {
359
+ w = W[i]
360
+ if (globbed[i]) return 0
361
+ if (w ~ /^(--jq|-q|--json|-t|--template|--repo|-R|--limit|-L|--hostname|--header|-H)$/) {
362
+ if (++i > argc || globbed[i]) return 0
363
+ continue
364
+ }
365
+ if (W[2] == "api" && w ~ /^(--method|-X)$/) { if (++i > argc || W[i] !~ /^(GET|HEAD)$/) return 0; continue }
366
+ if (w ~ /^-/ && w !~ /^(--paginate|--slurp|--include|--silent|--log|--log-failed|--web)$/) return 0
367
+ }
368
+ return 1
273
369
  }
274
370
  # The two managed corpus scripts are admitted for execution only by exact literal spelling: the path is
275
371
  # compared as a whole word (no ./, .., variable, glob or quoting variant can equal it), every other word must
@@ -304,6 +400,8 @@ function allow_command( verb, first, i) {
304
400
  return
305
401
  }
306
402
  if (verb == "sed") { if (!print_only_sed()) cmd_failed = 1; return }
403
+ if (verb == "find") { if (!find_allowed()) cmd_failed = 1; return }
404
+ if (verb == "gh") { if (!gh_allowed()) cmd_failed = 1; return }
307
405
  if (verb == "git" && W[2] == "-C") {
308
406
  if (argc >= 4 && W[3] != "" && W[3] !~ /^-/ && !globbed[3] && W[4] ~ /^(add|commit)$/) {
309
407
  verb = verb " " W[4]; first = 5
@@ -327,11 +425,12 @@ function command_end(separator, upto, resume, silent) {
327
425
  endword(); cmd_failed = 0; allow_command()
328
426
  if (cmd_failed) { bad = 1; unparsed = 1 }
329
427
  if (W[1] == "cd" && (separator == "|" || previous_pipe)) fail()
330
- silent = argc && !cmd_failed && !cmd_redirect && !force_emit && W[1] != "cd"
428
+ silent = argc && !cmd_failed && !input_redirect && !force_emit && W[1] != "cd"
429
+ if (silent && redirect_words != "") emitted[++emitted_count] = redirect_words
331
430
  if (!silent && upto > seg_start) emitted[++emitted_count] = substr(lexed, seg_start, upto - seg_start)
332
431
  seg_start = resume
333
432
  previous_pipe = (separator == "|")
334
- cmd_redirect = force_emit = 0
433
+ cmd_redirect = force_emit = input_redirect = 0; redirect_words = ""
335
434
  delete W; delete globbed; delete leading; argc = 0
336
435
  }
337
436
  function readonly(s, i, c, c2, sq, dq) {
@@ -357,6 +456,7 @@ function readonly(s, i, c, c2, sq, dq) {
357
456
  if (c == "(" || c == ")" || c == "{" || c == "}") fail()
358
457
  if (c == ">" || c == "<" || (c == "&" && c2 == ">")) {
359
458
  cmd_redirect = 1
459
+ if (c == "<") input_redirect = 1
360
460
  if (inword && word ~ /^[0-9]+$/) { word = ""; inword = 0 } else endword()
361
461
  if (redirect) fail()
362
462
  if (c == "<" && (c2 == "<" || c2 == "(")) fail()
@@ -391,6 +491,7 @@ BEGIN {
391
491
  # operand. No value-taking option is accepted (--arg, -f, -L, --rawfile, --slurpfile, --from-file, --indent).
392
492
  policy("jq", "rcesnRSjaMC", "--raw-output --compact-output --slurp --null-input --exit-status --raw-input --sort-keys --join-output --ascii-output --monochrome-output --tab")
393
493
  policy("awk", "", "")
494
+ policy("shellcheck", "x", "--external-sources")
394
495
  policy("git status", "sb", "--short --porcelain")
395
496
  policy("git diff", "p", "--stat --numstat --name-only --name-status --cached --staged --check --no-color --cc")
396
497
  policy("git log", "p", "--oneline --stat --name-only --no-color --follow")
@@ -413,7 +514,9 @@ BEGIN {
413
514
  exit readonly(text) ? 0 : 1
414
515
  }
415
516
  AWK
416
- candidates_text="$(GSW_COMMAND="$command_text" GSW_MODE=targets LC_ALL=C awk "$program" </dev/null)" || parser_failed
517
+ glob_shell_safe=1
518
+ if [[ -n "${BASH_ENV+x}" || -n "${ENV+x}" || -n "${GLOBIGNORE+x}" ]]; then glob_shell_safe=0; fi
519
+ candidates_text="$(GSW_COMMAND="$command_text" GSW_CWD="$cwd" GSW_GLOB_SAFE="$glob_shell_safe" GSW_MODE=targets LC_ALL=C awk "$program" </dev/null)" || parser_failed
417
520
  [ -n "$candidates_text" ] || exit 0
418
521
  candidates=()
419
522
  while IFS= read -r candidate; do candidates[${#candidates[@]}]="$candidate"; done <<<"$candidates_text"
@@ -431,7 +534,7 @@ references="$("$BASH" "$classifier" --references <<<"$classifier_input" 2>"$clas
431
534
  # A command that is not read-only is refused whatever the classifier could model, so an unmodeled word
432
535
  # (for example program text inside an interpreter heredoc) must not hide the refusal behind a parser
433
536
  # failure. A read-only command keeps the fail-closed parser failure.
434
- if ! GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_PROTECTED="" LC_ALL=C awk "$program" </dev/null; then
537
+ if ! GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_CWD="$cwd" GSW_GLOB_SAFE="$glob_shell_safe" GSW_PROTECTED="" LC_ALL=C awk "$program" </dev/null; then
435
538
  printf '%s\n' 'BLOCKED by cratis-guard-shell-writes: this command is not read-only and its references could not all be modeled; use the edit/write tools, or report the intended change.' >&2
436
539
  exit 2
437
540
  fi
@@ -440,6 +543,6 @@ references="$("$BASH" "$classifier" --references <<<"$classifier_input" 2>"$clas
440
543
  exit 2
441
544
  }
442
545
  [ -n "$references" ] || exit 0
443
- if GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_PROTECTED="$references" LC_ALL=C awk "$program" </dev/null; then exit 0; fi
546
+ if GSW_COMMAND="$command_text" GSW_MODE=readonly GSW_CWD="$cwd" GSW_GLOB_SAFE="$glob_shell_safe" GSW_PROTECTED="$references" LC_ALL=C awk "$program" </dev/null; then exit 0; fi
444
547
  printf "BLOCKED by cratis-guard-shell-writes: protected reference '%s' (cratis-guard-writes). Use the edit/write tools, or report the intended change; for a read, name literal paths or use the Read/Grep tools.\n" "${references%%$'\n'*}" >&2
445
548
  exit 2
@@ -221,7 +221,8 @@ function tokens(s, side, i, c, j, k, t, copy, jumps, first, closing) {
221
221
  for (i = 1; i <= length(s); i++) {
222
222
  c = substr(s, i, 1); t = c; j = i
223
223
  if (c == "{") {
224
- j = index(substr(s, i), "}"); j = j ? i + j - 1 : i; t = "*"
224
+ j = index(substr(s, i), "}")
225
+ if (j) { j = i + j - 1; t = "*" } else j = i
225
226
  if (side == 1 && index(substr(s, i, j - i + 1), "/")) exit 2
226
227
  }
227
228
  N[side]++; A[side, N[side]] = t
@@ -135,9 +135,9 @@ Work area: `.ai-work/screenplay/<slug>/re/` (`captures/`, `EVIDENCE.md`, optiona
135
135
  `scripts/score-fidelity.mjs --self-test` to check the arithmetic; it executes
136
136
  `scripts/score-fidelity-self-test.mjs` and prints the checked count.
137
137
  For process-drift scoping, run `scripts/drift-scope.mjs --self-test`, which executes
138
- `scripts/drift-scope-self-test.mjs`. The [SoloCrm case](scripts/fixtures/solocrm-drift/README.md)
139
- uses `scripts/fixtures/solocrm-drift/change.diff`, `scripts/fixtures/solocrm-drift/evidence-map.json`
140
- and `scripts/fixtures/solocrm-drift/expected.json`; see [process drift](references/process-drift.md).
138
+ `scripts/drift-scope-self-test.mjs`. The self-test reads `scripts/fixtures/library-drift/change.diff`,
139
+ `scripts/fixtures/library-drift/evidence-map.json` and `scripts/fixtures/library-drift/expected.json`
140
+ (a synthetic application); see [process drift](references/process-drift.md).
141
141
 
142
142
  When the sources are only a website, user docs or a description document, or the run must feel
143
143
  like a product on Stage, read
@@ -12,7 +12,7 @@ capture sets, or, when source is offered, `<commit>..HEAD` (`cratis-screenplay-l
12
12
  ## Source-diff scope helper
13
13
 
14
14
  Run `node scripts/drift-scope.mjs change.diff evidence-map.json` for JSON work lists;
15
- `node scripts/drift-scope.mjs --self-test` checks the SoloCrm case and rejection rules.
15
+ `node scripts/drift-scope.mjs --self-test` checks a synthetic library drift case and the rejection rules.
16
16
  The map projects evidence rows into `flows: [{id, evidenceIds, paths}]` and carries
17
17
  `watermarks: {from: {revision, inputDigest}, to: {revision, inputDigest}}`. Paths are
18
18
  repository-relative, case-sensitive exact paths or globs (`*` within a segment,
@@ -34,7 +34,7 @@ These are scope hints, not semantic proof: generated markers must be present to
34
34
  proxies, artifact/formatting changes can still affect behavior, and the keep list means
35
35
  no process hunk matched the supplied mapping. Reconcile artifacts with their source and
36
36
  inspect uncertain changes before a no-drift verdict. The helper echoes both watermarks;
37
- it never advances the accepted one. See the [SoloCrm fixture](../scripts/fixtures/solocrm-drift/README.md).
37
+ it never advances the accepted one. The self-test fixture is a synthetic library application: two process hunks in mapped flows, an indentation-only hunk, an unmapped added file that yields a new-flow candidate, and header-only generated, lockfile and scene hunks.
38
38
 
39
39
  ## Steps
40
40
 
@@ -6,17 +6,17 @@ import { spawnSync } from 'node:child_process';
6
6
  import { readFileSync } from 'node:fs';
7
7
  import { fileURLToPath } from 'node:url';
8
8
 
9
- const fixture = name => new URL(`./fixtures/solocrm-drift/${name}`, import.meta.url);
9
+ const fixture = name => new URL(`./fixtures/library-drift/${name}`, import.meta.url);
10
10
  const readJson = name => JSON.parse(readFileSync(fixture(name), 'utf8'));
11
11
 
12
12
  function change(path, body, before = path) {
13
13
  return `diff --git a/${before} b/${path}\n--- a/${before}\n+++ b/${path}\n${body}\n`;
14
14
  }
15
15
 
16
- function miniatureMap(paths = ['Source/Crm/Tags/**']) {
16
+ function miniatureMap(paths = ['Source/Library/Shelves/**']) {
17
17
  return {
18
18
  watermarks: { from: { revision: 'before', inputDigest: 'fixture-before' }, to: { revision: 'after', inputDigest: 'fixture-after' } },
19
- flows: [{ id: 'Tags', evidenceIds: ['RE-E1'], paths }],
19
+ flows: [{ id: 'Shelves', evidenceIds: ['RE-E1'], paths }],
20
20
  };
21
21
  }
22
22
 
@@ -27,55 +27,56 @@ function fixtureChecks(scopeDrift) {
27
27
  const actual = scopeDrift(diff, map);
28
28
  assert.deepEqual(actual, expected);
29
29
  assert.deepEqual(scopeDrift(diff, map), actual, 'deterministic output');
30
- assert.equal(map.flows.length, 31);
31
- assert.deepEqual(actual.newFlowCandidates[0].symbols, ['IsDormant', 'IsDueToday', 'IsOverdue']);
32
- assert.ok(actual.untouchedFlows.includes('Crm/Tags/Tags'));
30
+ assert.equal(map.flows.length, 12);
31
+ assert.deepEqual(actual.newFlowCandidates[0].symbols, ['IsReservable', 'IsShelfReady', 'NeedsReview']);
32
+ assert.ok(!actual.newFlowCandidates[0].symbols.some(name => ['Where', 'Capacity', 'ShelveAfterDays', 'ShelfRules'].includes(name)), 'generic methods, properties, constants and types are not symbols');
33
+ assert.ok(actual.untouchedFlows.includes('Library/Members/Members'));
33
34
  const cli = spawnSync(process.execPath, [fileURLToPath(new URL('./drift-scope.mjs', import.meta.url)),
34
35
  fileURLToPath(fixture('change.diff')), fileURLToPath(fixture('evidence-map.json'))], { encoding: 'utf8', timeout: 10000 });
35
36
  assert.equal(cli.error, undefined);
36
37
  assert.equal(cli.status, 0, cli.stderr);
37
38
  assert.deepEqual(JSON.parse(cli.stdout), expected);
38
- return 8;
39
+ return 9;
39
40
  }
40
41
 
41
42
  function classificationChecks(scopeDrift) {
42
43
  const map = miniatureMap();
43
44
  const run = (path, body, before) => scopeDrift(change(path, body, before), map);
44
- assert.equal(run('Source/Crm/Tags/Tags.cs', '@@ -1 +1 @@\n- old();\n+new();').hunks[0].classification, 'process');
45
- assert.equal(run('Source/Crm/Tags/Tags.cs', '@@ -1 +1 @@\n- same();\n+same();').hunks[0].classification, 'structure-only');
46
- assert.equal(run('Source/Crm/Tags/Tags.cs', '@@ -1 +1 @@\n-Print("a b");\n+Print("ab");').hunks[0].classification, 'process');
47
- assert.equal(run('Source/Crm/Tags/Tags.cs', '@@ -1 +0,0 @@\n-DeleteTag();').touchedFlows[0], 'Tags');
48
- assert.equal(run('Source/Crm/New/New.cs', '@@ -0,0 +1 @@\n+NewRule();').newFlowCandidates.length, 1);
45
+ assert.equal(run('Source/Library/Shelves/Shelves.cs', '@@ -1 +1 @@\n- old();\n+new();').hunks[0].classification, 'process');
46
+ assert.equal(run('Source/Library/Shelves/Shelves.cs', '@@ -1 +1 @@\n- same();\n+same();').hunks[0].classification, 'structure-only');
47
+ assert.equal(run('Source/Library/Shelves/Shelves.cs', '@@ -1 +1 @@\n-Print("a b");\n+Print("ab");').hunks[0].classification, 'process');
48
+ assert.equal(run('Source/Library/Shelves/Shelves.cs', '@@ -1 +0,0 @@\n-DeleteShelf();').touchedFlows[0], 'Shelves');
49
+ assert.equal(run('Source/Library/New/New.cs', '@@ -0,0 +1 @@\n+NewRule();').newFlowCandidates.length, 1);
49
50
  assert.equal(run('Source/dist/app.js', '@@ -1 +1 @@').hunks[0].reason, 'build output');
50
51
  assert.equal(run('Source/.cratis-render.json', '@@ -1 +1 @@').hunks[0].reason, 'scene/build artifact');
51
- assert.equal(run('Source/Crm/Tags/Tags.ts', '@@ -0,0 +1 @@\n+export const rule = 1;').hunks[0].classification, 'process');
52
- assert.equal(run('Source/Crm/Tags/Tags.cs', '@@ -0,0 +2 @@\n+// @generated by Cratis\n+// DO NOT EDIT').hunks[0].classification, 'process');
52
+ assert.equal(run('Source/Library/Shelves/Shelves.ts', '@@ -0,0 +1 @@\n+export const rule = 1;').hunks[0].classification, 'process');
53
+ assert.equal(run('Source/Library/Shelves/Shelves.cs', '@@ -0,0 +2 @@\n+// @generated by Cratis\n+// DO NOT EDIT').hunks[0].classification, 'process');
53
54
  return 9;
54
55
  }
55
56
 
56
57
  function renameAndMappingChecks(scopeDrift) {
57
58
  const map = miniatureMap();
58
- const renamed = 'diff --git a/Source/Crm/Tags/Tags.cs b/Source/Moved.cs\nsimilarity index 100%\nrename from Source/Crm/Tags/Tags.cs\nrename to Source/Moved.cs\n';
59
+ const renamed = 'diff --git a/Source/Library/Shelves/Shelves.cs b/Source/Moved.cs\nsimilarity index 100%\nrename from Source/Library/Shelves/Shelves.cs\nrename to Source/Moved.cs\n';
59
60
  assert.equal(scopeDrift(renamed, map).hunks[0].classification, 'structure-only');
60
- const changed = change('Source/Moved.cs', '@@ -1 +1 @@\n-old();\n+changed();', 'Source/Crm/Tags/Tags.cs');
61
- assert.deepEqual(scopeDrift(changed, map).touchedFlows, ['Tags']);
62
- const mixed = change('Source/Crm/Tags/Tags.cs', '@@ -1 +1 @@\n- same();\n+same();\n@@ -9 +9 @@\n-old();\n+new();');
61
+ const changed = change('Source/Moved.cs', '@@ -1 +1 @@\n-old();\n+changed();', 'Source/Library/Shelves/Shelves.cs');
62
+ assert.deepEqual(scopeDrift(changed, map).touchedFlows, ['Shelves']);
63
+ const mixed = change('Source/Library/Shelves/Shelves.cs', '@@ -1 +1 @@\n- same();\n+same();\n@@ -9 +9 @@\n-old();\n+new();');
63
64
  assert.deepEqual(scopeDrift(mixed, map).hunks.map(hunk => hunk.classification), ['structure-only', 'process']);
64
- const oneSegment = miniatureMap(['Source/*/Tags.cs']);
65
- assert.equal(scopeDrift(change('Source/Crm/Tags.cs', '@@ -1 +1 @@\n+x'), oneSegment).touchedFlows.length, 1);
66
- assert.equal(scopeDrift(change('Source/Crm/Other/Tags.cs', '@@ -1 +1 @@\n+x'), oneSegment).touchedFlows.length, 0);
65
+ const oneSegment = miniatureMap(['Source/*/Shelves.cs']);
66
+ assert.equal(scopeDrift(change('Source/Library/Shelves.cs', '@@ -1 +1 @@\n+x'), oneSegment).touchedFlows.length, 1);
67
+ assert.equal(scopeDrift(change('Source/Library/Other/Shelves.cs', '@@ -1 +1 @@\n+x'), oneSegment).touchedFlows.length, 0);
67
68
  const literal = miniatureMap(['Source/a.b.cs']);
68
69
  assert.equal(scopeDrift(change('Source/axb.cs', '@@ -1 +1 @@\n+x'), literal).touchedFlows.length, 0);
69
70
  return 6;
70
71
  }
71
72
 
72
73
  function rejectionChecks(scopeDrift) {
73
- const diff = change('Source/Crm/Tags/Tags.cs', '@@ -1 +1 @@\n+x');
74
+ const diff = change('Source/Library/Shelves/Shelves.cs', '@@ -1 +1 @@\n+x');
74
75
  assert.throws(() => scopeDrift('', miniatureMap()), /unified diff/);
75
76
  for (const map of [null, {}, { watermarks: {} }, { watermarks: { from: { revision: 'x' } } }]) {
76
77
  assert.throws(() => scopeDrift(diff, map), /revision or inputDigest/);
77
78
  }
78
- for (const flows of [[], null, [{ id: 'Tags', paths: [] }], [miniatureMap().flows[0], miniatureMap().flows[0]]]) {
79
+ for (const flows of [[], null, [{ id: 'Shelves', paths: [] }], [miniatureMap().flows[0], miniatureMap().flows[0]]]) {
79
80
  assert.throws(() => scopeDrift(diff, { ...miniatureMap(), flows }), /flows|paths|Duplicate flow/);
80
81
  }
81
82
  return 9;
@@ -83,5 +84,5 @@ function rejectionChecks(scopeDrift) {
83
84
 
84
85
  export function selfTest(scopeDrift) {
85
86
  const checks = fixtureChecks(scopeDrift) + classificationChecks(scopeDrift) + renameAndMappingChecks(scopeDrift) + rejectionChecks(scopeDrift);
86
- console.log(`drift-scope self-test: ${checks} checks passed; SoloCrm: 3 process, 4 structure-only, 2 touched, 29 kept, Today candidates IsDormant/IsDueToday/IsOverdue`);
87
+ console.log(`drift-scope self-test: ${checks} checks passed; synthetic library fixture: 3 process, 5 structure-only, 2 touched, 10 kept, 1 new-flow candidate with 3 symbols`);
87
88
  }
@@ -0,0 +1,100 @@
1
+ diff --git a/Source/Library/Loans/Loans/Loans.cs b/Source/Library/Loans/Loans/Loans.cs
2
+ index 4f1c2aa..9d03be7 100644
3
+ --- a/Source/Library/Loans/Loans/Loans.cs
4
+ +++ b/Source/Library/Loans/Loans/Loans.cs
5
+ @@ -20,4 +20,7 @@ public record Loan(Guid Id, string Title, DateOnly DueDate)
6
+ [AllowAnonymous]
7
+ public static ISubject<IEnumerable<Loan>> AllLoans(IReadModels readModels) => readModels.Observe<Loan>();
8
+ +
9
+ + [AllowAnonymous]
10
+ + public static ISubject<IEnumerable<Loan>> OverdueLoans(IReadModels readModels) => readModels.Observe<Loan>();
11
+ }
12
+ diff --git a/Source/Library/Books/Books/Books.cs b/Source/Library/Books/Books/Books.cs
13
+ index 81ab3c4..5e77d10 100644
14
+ --- a/Source/Library/Books/Books/Books.cs
15
+ +++ b/Source/Library/Books/Books/Books.cs
16
+ @@ -12,4 +12,7 @@ public record Book(Guid Id, string Title, string Shelf)
17
+ [AllowAnonymous]
18
+ public static ISubject<IEnumerable<Book>> AllBooks(IReadModels readModels) => readModels.Observe<Book>();
19
+ +
20
+ + [AllowAnonymous]
21
+ + public static ISubject<IEnumerable<Book>> ShelvedBooks(IReadModels readModels) => readModels.Observe<Book>();
22
+ }
23
+ diff --git a/Source/Library/Members/Members/Members.cs b/Source/Library/Members/Members/Members.cs
24
+ index 0a9e3d2..0a9e3d3 100644
25
+ --- a/Source/Library/Members/Members/Members.cs
26
+ +++ b/Source/Library/Members/Members/Members.cs
27
+ @@ -8,3 +8,3 @@ public record Member(Guid Id, string Name)
28
+ - public string Display => Name;
29
+ + public string Display => Name;
30
+
31
+ diff --git a/Source/Library/Shelving/ShelfRules.cs b/Source/Library/Shelving/ShelfRules.cs
32
+ new file mode 100644
33
+ index 0000000..b21c4e9
34
+ --- /dev/null
35
+ +++ b/Source/Library/Shelving/ShelfRules.cs
36
+ @@ -0,0 +1,31 @@
37
+ +// Copyright (c) Cratis. All rights reserved.
38
+ +// Licensed under the MIT license. See LICENSE file in the project root for full license information.
39
+ +
40
+ +// Hand-written gap-fill: the shelving rules compare against a calendar date, which the model cannot express.
41
+ +namespace Library.Shelving;
42
+ +
43
+ +public static class ShelfRules
44
+ +{
45
+ + /// <summary>The number of days a returned book waits before it is shelved.</summary>
46
+ + public const int ShelveAfterDays = 2;
47
+ +
48
+ + /// <summary>Gets the number of books one shelf holds.</summary>
49
+ + public static int Capacity => ShelfCapacity.Resolve();
50
+ +
51
+ + /// <summary>Whether a book can be reserved.</summary>
52
+ + public static bool IsReservable(Book book) => !book.IsRetired && book.Copies > 0;
53
+ +
54
+ + /// <summary>Whether a returned book is ready for its shelf.</summary>
55
+ + public static bool IsShelfReady(Book book)
56
+ + {
57
+ + return book.ReturnedOn.AddDays(ShelveAfterDays) <= Today;
58
+ + }
59
+ +
60
+ + /// <summary>Whether a book needs a condition review.</summary>
61
+ + public static bool NeedsReview(Book book) => book.Loans >= 25;
62
+ +
63
+ + /// <summary>Narrows a collection with a rule.</summary>
64
+ + public static IEnumerable<T> Where<T>(IEnumerable<T> source, Func<T, bool> rule) =>
65
+ + source.Where(rule).ToArray();
66
+ +}
67
+ diff --git a/Source/Library/Loans/Loans/Loans.ts b/Source/Library/Loans/Loans/Loans.ts
68
+ new file mode 100644
69
+ index 0000000..c4d11aa
70
+ --- /dev/null
71
+ +++ b/Source/Library/Loans/Loans/Loans.ts
72
+ @@ -0,0 +1,6 @@
73
+ +// Copyright (c) Cratis. All rights reserved.
74
+ +// Licensed under the MIT license. See LICENSE file in the project root for full license information.
75
+ +
76
+ +// @generated by Cratis. Source: Library.Loans.Loans.Loan
77
+ +// **DO NOT EDIT** - This file is an automatically generated file.
78
+ +export class Loan {}
79
+ diff --git a/Source/yarn.lock b/Source/yarn.lock
80
+ new file mode 100644
81
+ index 0000000..0ec6bad
82
+ --- /dev/null
83
+ +++ b/Source/yarn.lock
84
+ @@ -0,0 +1,3 @@
85
+ +# yarn lockfile v1
86
+ +
87
+ +"@scope/package@^1.0.0":
88
+ diff --git a/Source/scene.json b/Source/scene.json
89
+ index 27ad977..6692a21 100644
90
+ --- a/Source/scene.json
91
+ +++ b/Source/scene.json
92
+ @@ -1 +1 @@
93
+ -{"scene":"before"}
94
+ +{"scene":"after"}
95
+ diff --git a/Source/src/stage-scene.json b/Source/src/stage-scene.json
96
+ --- a/Source/src/stage-scene.json
97
+ +++ b/Source/src/stage-scene.json
98
+ @@ -1 +1 @@
99
+ -{"scene":"before"}
100
+ +{"scene":"after"}
@@ -0,0 +1,20 @@
1
+ {
2
+ "watermarks": {
3
+ "from": { "revision": "a1b2c3d", "input": "Screenplay/Library.play", "inputDigest": "sha256:1111111111111111111111111111111111111111111111111111111111111111" },
4
+ "to": { "revision": "e4f5a6b", "input": "Screenplay/Library.play", "inputDigest": "sha256:2222222222222222222222222222222222222222222222222222222222222222" }
5
+ },
6
+ "flows": [
7
+ { "id": "Library/Books/RegisterBook", "evidenceIds": ["RE-E1"], "modelLocator": "Screenplay/Library.play:6-20", "paths": ["Source/Library/Books/RegisterBook/**"] },
8
+ { "id": "Library/Books/RetireBook", "evidenceIds": ["RE-E2"], "modelLocator": "Screenplay/Library.play:21-26", "paths": ["Source/Library/Books/RetireBook/**"] },
9
+ { "id": "Library/Books/Books", "evidenceIds": ["RE-E3"], "modelLocator": "Screenplay/Library.play:27-52", "paths": ["Source/Library/Books/Books/**"] },
10
+ { "id": "Library/Members/EnrollMember", "evidenceIds": ["RE-E4"], "modelLocator": "Screenplay/Library.play:53-70", "paths": ["Source/Library/Members/EnrollMember/**"] },
11
+ { "id": "Library/Members/SuspendMember", "evidenceIds": ["RE-E5"], "modelLocator": "Screenplay/Library.play:71-77", "paths": ["Source/Library/Members/SuspendMember/**"] },
12
+ { "id": "Library/Members/Members", "evidenceIds": ["RE-E6"], "modelLocator": "Screenplay/Library.play:78-99", "paths": ["Source/Library/Members/Members/**"] },
13
+ { "id": "Library/Loans/LendBook", "evidenceIds": ["RE-E7"], "modelLocator": "Screenplay/Library.play:100-124", "paths": ["Source/Library/Loans/LendBook/**"] },
14
+ { "id": "Library/Loans/ReturnBook", "evidenceIds": ["RE-E8"], "modelLocator": "Screenplay/Library.play:125-140", "paths": ["Source/Library/Loans/ReturnBook/**"] },
15
+ { "id": "Library/Loans/ExtendLoan", "evidenceIds": ["RE-E9"], "modelLocator": "Screenplay/Library.play:141-155", "paths": ["Source/Library/Loans/ExtendLoan/**"] },
16
+ { "id": "Library/Loans/Loans", "evidenceIds": ["RE-E10"], "modelLocator": "Screenplay/Library.play:156-180", "paths": ["Source/Library/Loans/Loans/**"] },
17
+ { "id": "Library/Fines/AssessFine", "evidenceIds": ["RE-E11"], "modelLocator": "Screenplay/Library.play:181-199", "paths": ["Source/Library/Fines/AssessFine/**"] },
18
+ { "id": "Library/Fines/Fines", "evidenceIds": ["RE-E12"], "modelLocator": "Screenplay/Library.play:200-221", "paths": ["Source/Library/Fines/Fines/**"] }
19
+ ]
20
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "watermarks": {
3
+ "from": { "revision": "a1b2c3d", "input": "Screenplay/Library.play", "inputDigest": "sha256:1111111111111111111111111111111111111111111111111111111111111111" },
4
+ "to": { "revision": "e4f5a6b", "input": "Screenplay/Library.play", "inputDigest": "sha256:2222222222222222222222222222222222222222222222222222222222222222" }
5
+ },
6
+ "hunks": [
7
+ {
8
+ "path": "Source/Library/Loans/Loans/Loans.cs", "before": "Source/Library/Loans/Loans/Loans.cs",
9
+ "hunk": "@@ -20,4 +20,7 @@ public record Loan(Guid Id, string Title, DateOnly DueDate)",
10
+ "classification": "process", "reason": "behavior source or unrecognized change; re-derive before deciding drift", "flows": ["Library/Loans/Loans"]
11
+ },
12
+ {
13
+ "path": "Source/Library/Books/Books/Books.cs", "before": "Source/Library/Books/Books/Books.cs",
14
+ "hunk": "@@ -12,4 +12,7 @@ public record Book(Guid Id, string Title, string Shelf)",
15
+ "classification": "process", "reason": "behavior source or unrecognized change; re-derive before deciding drift", "flows": ["Library/Books/Books"]
16
+ },
17
+ {
18
+ "path": "Source/Library/Members/Members/Members.cs", "before": "Source/Library/Members/Members/Members.cs",
19
+ "hunk": "@@ -8,3 +8,3 @@ public record Member(Guid Id, string Name)",
20
+ "classification": "structure-only", "reason": "indentation/blank-line change only", "flows": []
21
+ },
22
+ {
23
+ "path": "Source/Library/Shelving/ShelfRules.cs", "before": "Source/Library/Shelving/ShelfRules.cs", "hunk": "@@ -0,0 +1,31 @@",
24
+ "classification": "process", "reason": "behavior source or unrecognized change; re-derive before deciding drift", "flows": []
25
+ },
26
+ {
27
+ "path": "Source/Library/Loans/Loans/Loans.ts", "before": "Source/Library/Loans/Loans/Loans.ts", "hunk": "@@ -0,0 +1,6 @@",
28
+ "classification": "structure-only", "reason": "generated TypeScript proxy", "flows": []
29
+ },
30
+ {
31
+ "path": "Source/yarn.lock", "before": "Source/yarn.lock", "hunk": "@@ -0,0 +1,3 @@",
32
+ "classification": "structure-only", "reason": "lockfile", "flows": []
33
+ },
34
+ {
35
+ "path": "Source/scene.json", "before": "Source/scene.json", "hunk": "@@ -1 +1 @@",
36
+ "classification": "structure-only", "reason": "scene/build artifact", "flows": []
37
+ },
38
+ {
39
+ "path": "Source/src/stage-scene.json", "before": "Source/src/stage-scene.json", "hunk": "@@ -1 +1 @@",
40
+ "classification": "structure-only", "reason": "scene/build artifact", "flows": []
41
+ }
42
+ ],
43
+ "touchedFlows": ["Library/Books/Books", "Library/Loans/Loans"],
44
+ "untouchedFlows": [
45
+ "Library/Books/RegisterBook", "Library/Books/RetireBook",
46
+ "Library/Fines/AssessFine", "Library/Fines/Fines",
47
+ "Library/Loans/ExtendLoan", "Library/Loans/LendBook", "Library/Loans/ReturnBook",
48
+ "Library/Members/EnrollMember", "Library/Members/Members", "Library/Members/SuspendMember"
49
+ ],
50
+ "newFlowCandidates": [
51
+ { "path": "Source/Library/Shelving/ShelfRules.cs", "symbols": ["IsReservable", "IsShelfReady", "NeedsReview"], "reason": "unmapped source; intake a candidate flow (including deletions or unsupported changes)" }
52
+ ],
53
+ "structureOnlyCount": 5
54
+ }
@@ -289,7 +289,7 @@ layout AppShell
289
289
  content page routed primary
290
290
 
291
291
  outlet sidebar of navigation
292
- logo image "/assets/solocrm.svg" title "SoloCRM"
292
+ logo image "/assets/shop.svg" title "Shopfront"
293
293
  default organizations title "Organizations" target Crm.Organizations
294
294
 
295
295
  ui profile Desktop
@@ -297,8 +297,8 @@ ui profile Desktop
297
297
  root template AppShell
298
298
  option showFooter false
299
299
  identity
300
- name "SoloCRM"
301
- logo initials "SC"
300
+ name "Shopfront"
301
+ logo initials "SF"
302
302
  ```
303
303
 
304
304
  ```screenplay excerpt
@@ -264,11 +264,16 @@ Stage renders two projection forms; the restrictions differ.
264
264
  inside a child are admitted), `nested`
265
265
  over an optional composite property, and `every`/`all` with set-from-event-source mappings. Keys
266
266
  are an event property or the event source. The key establishes the identifier, so it must
267
- end up unmapped: a mapping onto it is refused unless it restates the key (the key's own
268
- event property, `$eventSourceId` for an event-source key, or the same literal)
267
+ end up unmapped: in a `from`, a mapping onto it is refused unless it restates the key (the key's own
268
+ event property, `$eventSourceId` for an event-source key, or the same literal);
269
+ `join` and `every` refuse any mapping onto the identifier
269
270
  (`STAGE-ESM-017`). Auto-map
270
- counts as a mapping: if the event carries a property with the identifier's name and type,
271
- declare `no automap` and map the other properties explicitly. `from E` and
271
+ counts as a mapping, and it restates the key only when the event property it maps from is the key.
272
+ When the event carries a property with the identifier's name and that property is the intended key,
273
+ key the `from` by it (`from E key <property>`); the auto-mapped identifier then restates the key and is
274
+ admitted. Declare `no automap` only when the event's identifier-named property is not the key, and map
275
+ the other properties explicitly. `no automap` alone does not fix routing: with the key left on the event
276
+ source, every event goes to the event source's instance, not the one the payload names. `from E` and
272
277
  `from E key $eventSourceId` render when the identifier ends up unmapped, whether or not
273
278
  the event repeats the identifier.
274
279
  - `all` renders as Chronicle `FromAll` for event-source-identity mappings, including
@@ -359,5 +364,5 @@ Query-performer gaps are a separate contract: see [bodies and implementation gap
359
364
 
360
365
  | Draft | Diagnostic | Fix that rendered |
361
366
  | --- | --- | --- |
362
- | Projection `from BerthReserved` with `berthId = $eventSourceId` (mapping the identifier) | `STAGE-ESM-017`: mappings cannot overwrite the key | Do not map the identifier; the key establishes it, so map only the other properties. `from E key $eventSourceId` plus the same mapping is also refused |
367
+ | Projection `from BerthReserved` with `berthId = $eventSourceId` (mapping the identifier) | `STAGE-ESM-017`: mappings cannot overwrite the key | Leave the identifier unmapped (the key establishes it), or restate the key in a `from`: `berthId = $eventSourceId` under the default or `key $eventSourceId` key is admitted, and so is mapping the key's own event property. Only a plain set of the key's own value (its event property, `$eventSourceId` or the same literal) is admitted; any other mapping onto the key is refused, and `join` and `every` refuse any identifier mapping. If the payload property is the intended key, write `from E key <property>` |
363
368
  | A `then query` spec in the view slice, then one without `then <Event>` | `PLAY0273`, then `STAGE-ESM-011` | Put the spec in the command slice with `given caller`, `when`, the `then` event and `then query` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.151.1",
3
+ "version": "7.151.3",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,23 +0,0 @@
1
- # SoloCrm process-drift case
2
-
3
- Read-only source: SoloCrmIn5Minutes, `0cd6557..df908a2`. The first revision's
4
- `Screenplay/Crm.play` has 31 slices and no Today feature. The later revision adds
5
- OverdueTasks, TasksDueToday and DormantOpportunities plus hand-written date rules.
6
-
7
- `change.diff` excerpts `git diff --unified=2` for the two existing C# query files and
8
- includes the complete added TodayRules.cs. The generated Tasks.ts retains its header
9
- only; yarn.lock, scene.json and src/stage-scene.json retain file/hunk headers only.
10
- Original hunk ranges are retained: this is a scope fixture, not an applyable patch.
11
- Other changed files, including Crm.play, are deliberately omitted. The keep list is
12
- relative to these excerpts, not a claim that the full revision has no other drift.
13
-
14
- `evidence-map.json` projects every baseline slice to its rendered source folder.
15
- RE-E1 through RE-E31 are fixture-local evidence ids: each `modelLocator` cites the
16
- baseline declaration, not a claim that implementation behavior was verified.
17
- Paths include generated proxies so the artifact precedence is exercised. The two
18
- watermarks carry SHA-256 digests of the respective `Screenplay/Crm.play` inputs,
19
- not digests of the entire repositories. No private checkout is needed to run the test.
20
-
21
- `expected.json` is the complete expected scope result: two existing flows to
22
- re-derive, 29 to keep, and one unmapped Today source candidate with symbols for
23
- overdue, due-today and dormant rules. It is a work list, not an accepted model delta.
@@ -1,131 +0,0 @@
1
- diff --git a/Source/Crm/Opportunities/Pipeline/Pipeline.cs b/Source/Crm/Opportunities/Pipeline/Pipeline.cs
2
- index e401bf9..2b47c7c 100644
3
- --- a/Source/Crm/Opportunities/Pipeline/Pipeline.cs
4
- +++ b/Source/Crm/Opportunities/Pipeline/Pipeline.cs
5
- @@ -30,4 +30,7 @@ public record Opportunity(global::SoloCrm.Common.OpportunityTitle Title, global:
6
- [global::Cratis.Arc.Authorization.AllowAnonymousAttribute]
7
- public static global::System.Reactive.Subjects.ISubject<global::System.Collections.Generic.IEnumerable<Opportunity>> AllOpportunities(global::Cratis.Chronicle.ReadModels.IReadModels readModels) => readModels.Observe<Opportunity>();
8
- +
9
- + [global::Cratis.Arc.Authorization.AllowAnonymousAttribute]
10
- + public static global::System.Reactive.Subjects.ISubject<global::System.Collections.Generic.IEnumerable<Opportunity>> DormantOpportunities(global::Cratis.Chronicle.ReadModels.IReadModels readModels) => global::SoloCrm.Crm.Today.TodayRules.Where(readModels.Observe<Opportunity>(), global::SoloCrm.Crm.Today.TodayRules.IsDormant);
11
- }
12
- diff --git a/Source/Crm/Tasks/Tasks/Tasks.cs b/Source/Crm/Tasks/Tasks/Tasks.cs
13
- index 7298e09..422a293 100644
14
- --- a/Source/Crm/Tasks/Tasks/Tasks.cs
15
- +++ b/Source/Crm/Tasks/Tasks/Tasks.cs
16
- @@ -25,4 +25,10 @@ public record TaskItem(string RegardingId, global::SoloCrm.Common.TaskTitle Titl
17
- [global::Cratis.Arc.Authorization.AllowAnonymousAttribute]
18
- public static global::System.Reactive.Subjects.ISubject<global::System.Collections.Generic.IEnumerable<TaskItem>> AllTasks(global::Cratis.Chronicle.ReadModels.IReadModels readModels, bool? isCompleted = null) => readModels.Observe<TaskItem>(instance => (isCompleted == null || global::System.Collections.Generic.EqualityComparer<bool?>.Default.Equals(instance.IsCompleted, isCompleted)));
19
- +
20
- + [global::Cratis.Arc.Authorization.AllowAnonymousAttribute]
21
- + public static global::System.Reactive.Subjects.ISubject<global::System.Collections.Generic.IEnumerable<TaskItem>> OverdueTasks(global::Cratis.Chronicle.ReadModels.IReadModels readModels) => global::SoloCrm.Crm.Today.TodayRules.Where(readModels.Observe<TaskItem>(), global::SoloCrm.Crm.Today.TodayRules.IsOverdue);
22
- +
23
- + [global::Cratis.Arc.Authorization.AllowAnonymousAttribute]
24
- + public static global::System.Reactive.Subjects.ISubject<global::System.Collections.Generic.IEnumerable<TaskItem>> TasksDueToday(global::Cratis.Chronicle.ReadModels.IReadModels readModels) => global::SoloCrm.Crm.Today.TodayRules.Where(readModels.Observe<TaskItem>(), global::SoloCrm.Crm.Today.TodayRules.IsDueToday);
25
- }
26
- diff --git a/Source/Crm/Today/TodayRules.cs b/Source/Crm/Today/TodayRules.cs
27
- new file mode 100644
28
- index 0000000..c00d172
29
- --- /dev/null
30
- +++ b/Source/Crm/Today/TodayRules.cs
31
- @@ -0,0 +1,74 @@
32
- +// Copyright (c) Cratis. All rights reserved.
33
- +// Licensed under the MIT license. See LICENSE file in the project root for full license information.
34
- +
35
- +// Hand-written gap-fill: the Today rules from SPEC S1 compare against "today", which the Screenplay
36
- +// executable subset cannot express (`today` and $context date comparisons are PLAY0268). The model
37
- +// declares the OverdueTasks, TasksDueToday and DormantOpportunities queries; these rules narrow them.
38
- +using System.Reactive.Linq;
39
- +using System.Reactive.Subjects;
40
- +using SoloCrm.Common;
41
- +using SoloCrm.Crm.Opportunities.Pipeline;
42
- +using SoloCrm.Crm.Tasks.Tasks;
43
- +
44
- +namespace SoloCrm.Crm.Today;
45
- +
46
- +/// <summary>
47
- +/// The date rules behind the Today view, evaluated in the configured time zone (default Europe/Berlin).
48
- +/// </summary>
49
- +public static class TodayRules
50
- +{
51
- + /// <summary>The number of calendar days without activity after which an open opportunity is dormant.</summary>
52
- + public const int DormantAfterDays = 7;
53
- +
54
- + static readonly TimeZoneInfo _timeZone = ResolveTimeZone();
55
- +
56
- + /// <summary>Gets today's date in the configured time zone.</summary>
57
- + public static DateOnly Today => DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, _timeZone).DateTime);
58
- +
59
- + /// <summary>Whether a task is open and due before today.</summary>
60
- + /// <param name="task">The task.</param>
61
- + /// <returns>True when overdue.</returns>
62
- + public static bool IsOverdue(TaskItem task) => !task.IsCompleted && task.DueDate < Today;
63
- +
64
- + /// <summary>Whether a task is open and due today.</summary>
65
- + /// <param name="task">The task.</param>
66
- + /// <returns>True when due today.</returns>
67
- + public static bool IsDueToday(TaskItem task) => !task.IsCompleted && task.DueDate == Today;
68
- +
69
- + /// <summary>Whether an opportunity is open, not archived and has had no activity for the threshold.</summary>
70
- + /// <param name="opportunity">The opportunity.</param>
71
- + /// <returns>True when dormant.</returns>
72
- + public static bool IsDormant(Opportunity opportunity)
73
- + {
74
- + if (opportunity.IsArchived || (opportunity.StageStatus is not null && opportunity.StageStatus != StageStatus.Open))
75
- + {
76
- + return false;
77
- + }
78
- +
79
- + var lastTouched = opportunity.ReceivedOn;
80
- + if (opportunity.LastActivityAt is { } lastActivity)
81
- + {
82
- + var activityDay = DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(lastActivity, _timeZone).DateTime);
83
- + if (activityDay > lastTouched)
84
- + {
85
- + lastTouched = activityDay;
86
- + }
87
- + }
88
- +
89
- + return lastTouched.AddDays(DormantAfterDays) <= Today;
90
- + }
91
- +
92
- + /// <summary>Narrows an observed collection with a rule, keeping it observable.</summary>
93
- + /// <typeparam name="T">The read model type.</typeparam>
94
- + /// <param name="source">The observed collection.</param>
95
- + /// <param name="rule">The rule an item must satisfy.</param>
96
- + /// <returns>A subject producing only the matching items.</returns>
97
- + public static ISubject<IEnumerable<T>> Where<T>(ISubject<IEnumerable<T>> source, Func<T, bool> rule) =>
98
- + System.Reactive.Subjects.Subject.Create<IEnumerable<T>>(source, source.Select(items => items.Where(rule).ToArray()));
99
- +
100
- + static TimeZoneInfo ResolveTimeZone()
101
- + {
102
- + var id = Environment.GetEnvironmentVariable("App__TimeZone") ?? "Europe/Berlin";
103
- + return TimeZoneInfo.TryFindSystemTimeZoneById(id, out var zone) ? zone : TimeZoneInfo.Utc;
104
- + }
105
- +}
106
- diff --git a/Source/Crm/Tasks/Tasks/Tasks.ts b/Source/Crm/Tasks/Tasks/Tasks.ts
107
- new file mode 100644
108
- index 0000000..dce490a
109
- --- /dev/null
110
- +++ b/Source/Crm/Tasks/Tasks/Tasks.ts
111
- @@ -0,0 +1,439 @@
112
- +// Copyright (c) Cratis. All rights reserved.
113
- +// Licensed under the MIT license. See LICENSE file in the project root for full license information.
114
- +
115
- +// @generated by Cratis. Source: SoloCrm.Crm.Tasks.Tasks.TaskItem, SoloCrm.Crm.Tasks.Tasks.TaskItem, SoloCrm.Crm.Tasks.Tasks.TaskItem, SoloCrm.Crm.Tasks.Tasks.TaskItem, SoloCrm.Crm.Tasks.Tasks.TaskItem. Time: 2026-10-22T14:47:52.1631720Z. Hash: DF5CD97919A2A5E11B36B476995EF8E1DC18665058C35D98CEE524C93C1C760D
116
- +// **DO NOT EDIT** - This file is an automatically generated file.
117
- diff --git a/Source/yarn.lock b/Source/yarn.lock
118
- new file mode 100644
119
- index 0000000..0ec6bad
120
- --- /dev/null
121
- +++ b/Source/yarn.lock
122
- @@ -0,0 +1,1670 @@
123
- diff --git a/Source/scene.json b/Source/scene.json
124
- index 27ad977..6692a21 100644
125
- --- a/Source/scene.json
126
- +++ b/Source/scene.json
127
- @@ -1 +1 @@
128
- diff --git a/Source/src/stage-scene.json b/Source/src/stage-scene.json
129
- --- a/Source/src/stage-scene.json
130
- +++ b/Source/src/stage-scene.json
131
- @@ -1 +1 @@
@@ -1,39 +0,0 @@
1
- {
2
- "watermarks": {
3
- "from": { "revision": "0cd6557", "input": "Screenplay/Crm.play", "inputDigest": "sha256:3b93313c21d1c51ea35dac93377cc852e0a3ee3fee38d998927ba4b90c562c44" },
4
- "to": { "revision": "df908a2", "input": "Screenplay/Crm.play", "inputDigest": "sha256:166ff866090d299fc955f69826ff70aeef920ad4b53e58168814e1d3fe562ef7" }
5
- },
6
- "flows": [
7
- { "id": "Crm/Organizations/RegisterOrganization", "evidenceIds": ["RE-E1"], "modelLocator": "Screenplay/Crm.play:6-34", "paths": ["Source/Crm/Organizations/RegisterOrganization/**"] },
8
- { "id": "Crm/Organizations/ArchiveOrganization", "evidenceIds": ["RE-E2"], "modelLocator": "Screenplay/Crm.play:35-39", "paths": ["Source/Crm/Organizations/ArchiveOrganization/**"] },
9
- { "id": "Crm/Organizations/RestoreOrganization", "evidenceIds": ["RE-E3"], "modelLocator": "Screenplay/Crm.play:40-44", "paths": ["Source/Crm/Organizations/RestoreOrganization/**"] },
10
- { "id": "Crm/Organizations/Organizations", "evidenceIds": ["RE-E4"], "modelLocator": "Screenplay/Crm.play:45-89", "paths": ["Source/Crm/Organizations/Organizations/**"] },
11
- { "id": "Crm/Contacts/RegisterContact", "evidenceIds": ["RE-E5"], "modelLocator": "Screenplay/Crm.play:91-137", "paths": ["Source/Crm/Contacts/RegisterContact/**"] },
12
- { "id": "Crm/Contacts/TagContact", "evidenceIds": ["RE-E6"], "modelLocator": "Screenplay/Crm.play:138-144", "paths": ["Source/Crm/Contacts/TagContact/**"] },
13
- { "id": "Crm/Contacts/ArchiveContact", "evidenceIds": ["RE-E7"], "modelLocator": "Screenplay/Crm.play:145-149", "paths": ["Source/Crm/Contacts/ArchiveContact/**"] },
14
- { "id": "Crm/Contacts/RestoreContact", "evidenceIds": ["RE-E8"], "modelLocator": "Screenplay/Crm.play:150-154", "paths": ["Source/Crm/Contacts/RestoreContact/**"] },
15
- { "id": "Crm/Contacts/Contacts", "evidenceIds": ["RE-E9"], "modelLocator": "Screenplay/Crm.play:155-203", "paths": ["Source/Crm/Contacts/Contacts/**"] },
16
- { "id": "Crm/Tags/DefineTag", "evidenceIds": ["RE-E10"], "modelLocator": "Screenplay/Crm.play:205-224", "paths": ["Source/Crm/Tags/DefineTag/**"] },
17
- { "id": "Crm/Tags/Tags", "evidenceIds": ["RE-E11"], "modelLocator": "Screenplay/Crm.play:225-245", "paths": ["Source/Crm/Tags/Tags/**"] },
18
- { "id": "Crm/Stages/DefineStage", "evidenceIds": ["RE-E12"], "modelLocator": "Screenplay/Crm.play:247-268", "paths": ["Source/Crm/Stages/DefineStage/**"] },
19
- { "id": "Crm/Stages/RenameStage", "evidenceIds": ["RE-E13"], "modelLocator": "Screenplay/Crm.play:269-275", "paths": ["Source/Crm/Stages/RenameStage/**"] },
20
- { "id": "Crm/Stages/ReorderStage", "evidenceIds": ["RE-E14"], "modelLocator": "Screenplay/Crm.play:276-282", "paths": ["Source/Crm/Stages/ReorderStage/**"] },
21
- { "id": "Crm/Stages/Stages", "evidenceIds": ["RE-E15"], "modelLocator": "Screenplay/Crm.play:283-312", "paths": ["Source/Crm/Stages/Stages/**"] },
22
- { "id": "Crm/Opportunities/RegisterOpportunity", "evidenceIds": ["RE-E16"], "modelLocator": "Screenplay/Crm.play:314-380", "paths": ["Source/Crm/Opportunities/RegisterOpportunity/**"] },
23
- { "id": "Crm/Opportunities/MoveOpportunityToStage", "evidenceIds": ["RE-E17"], "modelLocator": "Screenplay/Crm.play:381-388", "paths": ["Source/Crm/Opportunities/MoveOpportunityToStage/**"] },
24
- { "id": "Crm/Opportunities/ChangeOpportunityPricing", "evidenceIds": ["RE-E18"], "modelLocator": "Screenplay/Crm.play:389-406", "paths": ["Source/Crm/Opportunities/ChangeOpportunityPricing/**"] },
25
- { "id": "Crm/Opportunities/TagOpportunity", "evidenceIds": ["RE-E19"], "modelLocator": "Screenplay/Crm.play:407-413", "paths": ["Source/Crm/Opportunities/TagOpportunity/**"] },
26
- { "id": "Crm/Opportunities/ArchiveOpportunity", "evidenceIds": ["RE-E20"], "modelLocator": "Screenplay/Crm.play:414-418", "paths": ["Source/Crm/Opportunities/ArchiveOpportunity/**"] },
27
- { "id": "Crm/Opportunities/RestoreOpportunity", "evidenceIds": ["RE-E21"], "modelLocator": "Screenplay/Crm.play:419-423", "paths": ["Source/Crm/Opportunities/RestoreOpportunity/**"] },
28
- { "id": "Crm/Opportunities/Pipeline", "evidenceIds": ["RE-E22"], "modelLocator": "Screenplay/Crm.play:424-505", "paths": ["Source/Crm/Opportunities/Pipeline/**"] },
29
- { "id": "Crm/Timeline/LogOpportunityActivity", "evidenceIds": ["RE-E23"], "modelLocator": "Screenplay/Crm.play:507-520", "paths": ["Source/Crm/Timeline/LogOpportunityActivity/**"] },
30
- { "id": "Crm/Timeline/LogContactActivity", "evidenceIds": ["RE-E24"], "modelLocator": "Screenplay/Crm.play:521-534", "paths": ["Source/Crm/Timeline/LogContactActivity/**"] },
31
- { "id": "Crm/Timeline/LogOrganizationActivity", "evidenceIds": ["RE-E25"], "modelLocator": "Screenplay/Crm.play:535-548", "paths": ["Source/Crm/Timeline/LogOrganizationActivity/**"] },
32
- { "id": "Crm/Timeline/Timeline", "evidenceIds": ["RE-E26"], "modelLocator": "Screenplay/Crm.play:549-598", "paths": ["Source/Crm/Timeline/Timeline/**"] },
33
- { "id": "Crm/Tasks/AddTask", "evidenceIds": ["RE-E27"], "modelLocator": "Screenplay/Crm.play:600-621", "paths": ["Source/Crm/Tasks/AddTask/**"] },
34
- { "id": "Crm/Tasks/RescheduleTask", "evidenceIds": ["RE-E28"], "modelLocator": "Screenplay/Crm.play:622-628", "paths": ["Source/Crm/Tasks/RescheduleTask/**"] },
35
- { "id": "Crm/Tasks/CompleteTask", "evidenceIds": ["RE-E29"], "modelLocator": "Screenplay/Crm.play:629-634", "paths": ["Source/Crm/Tasks/CompleteTask/**"] },
36
- { "id": "Crm/Tasks/ReopenTask", "evidenceIds": ["RE-E30"], "modelLocator": "Screenplay/Crm.play:635-639", "paths": ["Source/Crm/Tasks/ReopenTask/**"] },
37
- { "id": "Crm/Tasks/Tasks", "evidenceIds": ["RE-E31"], "modelLocator": "Screenplay/Crm.play:640-678", "paths": ["Source/Crm/Tasks/Tasks/**"] }
38
- ]
39
- }
@@ -1,52 +0,0 @@
1
- {
2
- "watermarks": {
3
- "from": { "revision": "0cd6557", "input": "Screenplay/Crm.play", "inputDigest": "sha256:3b93313c21d1c51ea35dac93377cc852e0a3ee3fee38d998927ba4b90c562c44" },
4
- "to": { "revision": "df908a2", "input": "Screenplay/Crm.play", "inputDigest": "sha256:166ff866090d299fc955f69826ff70aeef920ad4b53e58168814e1d3fe562ef7" }
5
- },
6
- "hunks": [
7
- {
8
- "path": "Source/Crm/Opportunities/Pipeline/Pipeline.cs", "before": "Source/Crm/Opportunities/Pipeline/Pipeline.cs",
9
- "hunk": "@@ -30,4 +30,7 @@ public record Opportunity(global::SoloCrm.Common.OpportunityTitle Title, global:",
10
- "classification": "process", "reason": "behavior source or unrecognized change; re-derive before deciding drift", "flows": ["Crm/Opportunities/Pipeline"]
11
- },
12
- {
13
- "path": "Source/Crm/Tasks/Tasks/Tasks.cs", "before": "Source/Crm/Tasks/Tasks/Tasks.cs",
14
- "hunk": "@@ -25,4 +25,10 @@ public record TaskItem(string RegardingId, global::SoloCrm.Common.TaskTitle Titl",
15
- "classification": "process", "reason": "behavior source or unrecognized change; re-derive before deciding drift", "flows": ["Crm/Tasks/Tasks"]
16
- },
17
- {
18
- "path": "Source/Crm/Today/TodayRules.cs", "before": "Source/Crm/Today/TodayRules.cs", "hunk": "@@ -0,0 +1,74 @@",
19
- "classification": "process", "reason": "behavior source or unrecognized change; re-derive before deciding drift", "flows": []
20
- },
21
- {
22
- "path": "Source/Crm/Tasks/Tasks/Tasks.ts", "before": "Source/Crm/Tasks/Tasks/Tasks.ts", "hunk": "@@ -0,0 +1,439 @@",
23
- "classification": "structure-only", "reason": "generated TypeScript proxy", "flows": []
24
- },
25
- {
26
- "path": "Source/yarn.lock", "before": "Source/yarn.lock", "hunk": "@@ -0,0 +1,1670 @@",
27
- "classification": "structure-only", "reason": "lockfile", "flows": []
28
- },
29
- {
30
- "path": "Source/scene.json", "before": "Source/scene.json", "hunk": "@@ -1 +1 @@",
31
- "classification": "structure-only", "reason": "scene/build artifact", "flows": []
32
- },
33
- {
34
- "path": "Source/src/stage-scene.json", "before": "Source/src/stage-scene.json", "hunk": "@@ -1 +1 @@",
35
- "classification": "structure-only", "reason": "scene/build artifact", "flows": []
36
- }
37
- ],
38
- "touchedFlows": ["Crm/Opportunities/Pipeline", "Crm/Tasks/Tasks"],
39
- "untouchedFlows": [
40
- "Crm/Contacts/ArchiveContact", "Crm/Contacts/Contacts", "Crm/Contacts/RegisterContact", "Crm/Contacts/RestoreContact", "Crm/Contacts/TagContact",
41
- "Crm/Opportunities/ArchiveOpportunity", "Crm/Opportunities/ChangeOpportunityPricing", "Crm/Opportunities/MoveOpportunityToStage", "Crm/Opportunities/RegisterOpportunity", "Crm/Opportunities/RestoreOpportunity", "Crm/Opportunities/TagOpportunity",
42
- "Crm/Organizations/ArchiveOrganization", "Crm/Organizations/Organizations", "Crm/Organizations/RegisterOrganization", "Crm/Organizations/RestoreOrganization",
43
- "Crm/Stages/DefineStage", "Crm/Stages/RenameStage", "Crm/Stages/ReorderStage", "Crm/Stages/Stages",
44
- "Crm/Tags/DefineTag", "Crm/Tags/Tags",
45
- "Crm/Tasks/AddTask", "Crm/Tasks/CompleteTask", "Crm/Tasks/ReopenTask", "Crm/Tasks/RescheduleTask",
46
- "Crm/Timeline/LogContactActivity", "Crm/Timeline/LogOpportunityActivity", "Crm/Timeline/LogOrganizationActivity", "Crm/Timeline/Timeline"
47
- ],
48
- "newFlowCandidates": [
49
- { "path": "Source/Crm/Today/TodayRules.cs", "symbols": ["IsDormant", "IsDueToday", "IsOverdue"], "reason": "unmapped source; intake a candidate flow (including deletions or unsupported changes)" }
50
- ],
51
- "structureOnlyCount": 4
52
- }