@krysoworks/kryso 0.0.0-stage → 2.0.0-rc.1

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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -2
  3. package/bin/kryso +31 -0
  4. package/bin/ship-it-status +14 -0
  5. package/bin/ship-ledger +14 -0
  6. package/bin/ship-loop +14 -0
  7. package/bin/ship-pass +14 -0
  8. package/bin/warden +14 -0
  9. package/dist/answer.d.ts +38 -0
  10. package/dist/answer.js +48 -0
  11. package/dist/bytes.d.ts +5 -0
  12. package/dist/bytes.js +35 -0
  13. package/dist/cleanup.d.ts +1 -0
  14. package/dist/cleanup.js +629 -0
  15. package/dist/commands.d.ts +48 -0
  16. package/dist/commands.js +293 -0
  17. package/dist/completions.d.ts +24 -0
  18. package/dist/completions.js +239 -0
  19. package/dist/daemon.d.ts +15 -0
  20. package/dist/daemon.js +23 -0
  21. package/dist/diagnose.d.ts +47 -0
  22. package/dist/diagnose.js +314 -0
  23. package/dist/doctor.d.ts +1 -0
  24. package/dist/doctor.js +241 -0
  25. package/dist/env.d.ts +9 -0
  26. package/dist/env.js +17 -0
  27. package/dist/evidence.d.ts +39 -0
  28. package/dist/evidence.js +327 -0
  29. package/dist/home.d.ts +3 -0
  30. package/dist/home.js +27 -0
  31. package/dist/install.d.ts +59 -0
  32. package/dist/install.js +137 -0
  33. package/dist/isolate.d.ts +28 -0
  34. package/dist/isolate.js +402 -0
  35. package/dist/leftovers.d.ts +5 -0
  36. package/dist/leftovers.js +156 -0
  37. package/dist/machine.d.ts +6 -0
  38. package/dist/machine.js +185 -0
  39. package/dist/palette.d.ts +147 -0
  40. package/dist/palette.js +167 -0
  41. package/dist/plan.d.ts +1 -0
  42. package/dist/plan.js +133 -0
  43. package/dist/proc.d.ts +23 -0
  44. package/dist/proc.js +23 -0
  45. package/dist/read.d.ts +1 -0
  46. package/dist/read.js +297 -0
  47. package/dist/readiness.d.ts +5 -0
  48. package/dist/readiness.js +64 -0
  49. package/dist/remote.d.ts +6 -0
  50. package/dist/remote.js +85 -0
  51. package/dist/self-update.d.ts +1 -0
  52. package/dist/self-update.js +224 -0
  53. package/dist/semver.d.ts +7 -0
  54. package/dist/semver.js +42 -0
  55. package/dist/style.d.ts +71 -0
  56. package/dist/style.js +187 -0
  57. package/dist/update.d.ts +47 -0
  58. package/dist/update.js +190 -0
  59. package/dist/work.d.ts +25 -0
  60. package/dist/work.js +449 -0
  61. package/dist/workflows.d.ts +4 -0
  62. package/dist/workflows.js +73 -0
  63. package/docker/entrypoint.sh +44 -0
  64. package/docker/runner.Dockerfile +39 -0
  65. package/package.json +65 -4
  66. package/scripts/install-skills.sh +607 -0
  67. package/skills/code-review/SKILL.md +231 -0
  68. package/skills/kryso/SKILL.md +107 -0
  69. package/skills/kryso/golden/help.rounded.ansi +23 -0
  70. package/skills/kryso/golden/help.square.ansi +23 -0
  71. package/skills/kryso/golden/help.txt +23 -0
  72. package/skills/kryso/golden/table-narrow.json +11 -0
  73. package/skills/kryso/golden/table-narrow.rounded.ansi +4 -0
  74. package/skills/kryso/golden/table-narrow.square.ansi +4 -0
  75. package/skills/kryso/golden/table.ansi +5 -0
  76. package/skills/kryso/golden/table.json +11 -0
  77. package/skills/kryso/ledger.sh +2146 -0
  78. package/skills/kryso/palette.json +57 -0
  79. package/skills/kryso/reference/resuming.md +30 -0
  80. package/skills/kryso/reference/routing.md +23 -0
  81. package/skills/kryso/reference/stage-1-claim.md +79 -0
  82. package/skills/kryso/reference/stage-2-build.md +133 -0
  83. package/skills/kryso/reference/stage-3-prove.md +51 -0
  84. package/skills/kryso/reference/stage-4-pr.md +76 -0
  85. package/skills/kryso/reference/stage-5-reconcile.md +81 -0
  86. package/skills/kryso/reference/stage-6-merge-or-park.md +73 -0
  87. package/skills/kryso/reference/stage-7-close-out.md +62 -0
  88. package/skills/kryso/reference/terminal.md +7 -0
  89. package/skills/kryso/ship-it-status.sh +1503 -0
  90. package/skills/kryso/ui.py +274 -0
  91. package/skills/kryso/ui.sh +609 -0
  92. package/skills/kryso-build/SKILL.md +168 -0
  93. package/skills/kryso-shift/SKILL.md +167 -0
  94. package/skills/kryso-shift/archive.py +2784 -0
  95. package/skills/kryso-shift/archive_checker.py +462 -0
  96. package/skills/kryso-shift/archive_checker_lambda.py +155 -0
  97. package/skills/kryso-shift/archive_health.py +364 -0
  98. package/skills/kryso-shift/archive_launchd.py +140 -0
  99. package/skills/kryso-shift/archive_remote.py +990 -0
  100. package/skills/kryso-shift/archiving-checker.md +140 -0
  101. package/skills/kryso-shift/archiving-keep.md +115 -0
  102. package/skills/kryso-shift/archiving-recovery.md +112 -0
  103. package/skills/kryso-shift/archiving-remote.md +166 -0
  104. package/skills/kryso-shift/archiving.md +146 -0
  105. package/skills/kryso-shift/coverage.schema.json +225 -0
  106. package/skills/kryso-shift/deadline.sh +254 -0
  107. package/skills/kryso-shift/feedback.schema.json +35 -0
  108. package/skills/kryso-shift/feedback.sh +228 -0
  109. package/skills/kryso-shift/history-manifest.schema.json +331 -0
  110. package/skills/kryso-shift/keep-after.sh +55 -0
  111. package/skills/kryso-shift/measure.sh +611 -0
  112. package/skills/kryso-shift/merge-ready.sh +207 -0
  113. package/skills/kryso-shift/outcome.schema.json +16 -0
  114. package/skills/kryso-shift/pass-rules.md +8 -0
  115. package/skills/kryso-shift/profile.schema.json +42 -0
  116. package/skills/kryso-shift/reader.sh +692 -0
  117. package/skills/kryso-shift/reads.sh +151 -0
  118. package/skills/kryso-shift/reference/allowance.md +21 -0
  119. package/skills/kryso-shift/reference/driver.md +95 -0
  120. package/skills/kryso-shift/reference/measuring.md +67 -0
  121. package/skills/kryso-shift/reference/outputs.md +21 -0
  122. package/skills/kryso-shift/reference/pass-script.md +115 -0
  123. package/skills/kryso-shift/reference/reconcile-and-merge.md +55 -0
  124. package/skills/kryso-shift/reference/second-reader.md +9 -0
  125. package/skills/kryso-shift/reference/sweeps.md +83 -0
  126. package/skills/kryso-shift/repair.schema.json +14 -0
  127. package/skills/kryso-shift/report-template.html +679 -0
  128. package/skills/kryso-shift/report.py +389 -0
  129. package/skills/kryso-shift/report_fixture.py +65 -0
  130. package/skills/kryso-shift/reporting.md +58 -0
  131. package/skills/kryso-shift/result.sh +91 -0
  132. package/skills/kryso-shift/runner.sh +1178 -0
  133. package/skills/kryso-shift/ship-loop.sh +3977 -0
  134. package/skills/kryso-shift/ship-pass.sh +4987 -0
  135. package/skills/kryso-shift/steps.jq +19 -0
  136. package/skills/kryso-shift/workflow.mjs +830 -0
  137. package/skills/kryso-shift/workflows/default.json +22 -0
  138. package/skills/kryso-shift/workflows/ralph.json +13 -0
  139. package/skills/kryso-watch/SKILL.md +100 -0
  140. package/skills/kryso-watch/answer.schema.json +23 -0
  141. package/skills/kryso-watch/base-refs.sh +44 -0
  142. package/skills/kryso-watch/board.sh +58 -0
  143. package/skills/kryso-watch/reference/config.md +23 -0
  144. package/skills/kryso-watch/reference/outputs.md +30 -0
  145. package/skills/kryso-watch/reference/report.md +29 -0
  146. package/skills/kryso-watch/reference/scheduler.md +32 -0
  147. package/skills/kryso-watch/reference/settlement.md +29 -0
  148. package/skills/kryso-watch/reference/shift.md +44 -0
  149. package/skills/kryso-watch/reference/shim-limits.md +22 -0
  150. package/skills/kryso-watch/reference/triage.md +26 -0
  151. package/skills/kryso-watch/schema.jq +40 -0
  152. package/skills/kryso-watch/settle.schema.json +36 -0
  153. package/skills/kryso-watch/stage-common.sh +187 -0
  154. package/skills/kryso-watch/stages/report.sh +525 -0
  155. package/skills/kryso-watch/stages/settle.sh +722 -0
  156. package/skills/kryso-watch/stages/shift.sh +466 -0
  157. package/skills/kryso-watch/stages/triage.sh +379 -0
  158. package/skills/kryso-watch/tracker.sh +27 -0
  159. package/skills/kryso-watch/triage.schema.json +77 -0
  160. package/skills/kryso-watch/warden.launchd.plist +50 -0
  161. package/skills/kryso-watch/warden.schema.json +98 -0
  162. package/skills/kryso-watch/warden.sh +1004 -0
@@ -0,0 +1,525 @@
1
+ #!/usr/bin/env bash
2
+ # stages/report.sh: the warden's decision report stage, run by warden.sh after triage and
3
+ # before the shift, as its own process.
4
+ #
5
+ # report.sh <repo> <watch-dir> apply the answers on the open report, then post this watch's items
6
+ # report.sh --post <repo> <watch-dir>
7
+ # post only the items in report-items.json not yet posted, which
8
+ # is how settlement's items reach the report after it ran
9
+ # report.sh --dry-run <repo> print the items pending and the answers a watch would apply
10
+ #
11
+ # The driver exports KRYSO_WATCH_CONFIG (the resolved config, base included), KRYSO_WATCH_ID and
12
+ # KRYSO_SHIFT_SKILL_DIR. The report is one open issue carrying the report label, found live by
13
+ # the label. Its body holds the items, each under a numbered heading with a hidden marker that
14
+ # carries the item whole, so the body is the report's only state. A person answers in
15
+ # comments. This body reads the comments made since the last watch read them, writes each
16
+ # answer onto its parked issue, and once every item an issue waits on is answered, gives that
17
+ # issue one fresh context that rewrites its brief and acceptance criteria from the answers,
18
+ # then puts it back in the queue. Then it closes a report whose every item is applied, and
19
+ # posts the items triage parked this watch: appended to the open report with one comment, or
20
+ # as a new report when none is open. ADR 0004 and reference/report.md say why.
21
+ set -uo pipefail
22
+
23
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24
+ WARDEN_DIR="$(dirname "$HERE")"
25
+ OUTCOME_SCHEMA="$WARDEN_DIR/answer.schema.json"
26
+ ITEMS_MARKER='<!-- warden:items'
27
+ ITEM_MARKER='<!-- warden:item '
28
+ # An option's letter from its index and back, for every jq program that names one.
29
+ LETTERS='def letter($i): "abcdefghijklmnopqrstuvwxyz"[$i:$i + 1]; def letter_index($l): "abcdefghijklmnopqrstuvwxyz" | index($l);'
30
+
31
+ MODE=watch
32
+ case "${1:-}" in --dry-run) MODE=dry; shift ;; --post) MODE=post; shift ;; esac
33
+ REPO_ROOT="${1:-}"
34
+ WATCH_DIR="${2:-}"
35
+ WATCH_ID="${KRYSO_WATCH_ID:-}"
36
+
37
+ # What the result reports, filled as the stage goes.
38
+ ADDED='[]'
39
+ APPLIED='[]'
40
+ NOTES='[]'
41
+ ISSUES_JSON='[]'
42
+ REPORT_NUMBER=""
43
+ REPORT_URL=""
44
+ ITEMS='[]'
45
+
46
+ # result [extra-json]: the stage's one result object, after the report body is brought up to
47
+ # date, so a stop part-way still leaves the answers it wrote recorded on the report.
48
+ result() {
49
+ local extra="${1:-}"
50
+ [[ -n "$extra" ]] || extra='{}'
51
+ [[ "$MODE" == dry ]] || flush_body
52
+ jq -cn --argjson items "$ITEMS" --argjson added "$ADDED" --argjson applied "$APPLIED" --argjson notes "$NOTES" \
53
+ --argjson issues "$ISSUES_JSON" --arg url "$REPORT_URL" --argjson extra "$extra" '
54
+ ($added | map(.id)) as $new
55
+ | ($issues | map(select(.state == "ready-for-agent")) | length) as $released
56
+ | ($issues | map(select(.state == "wontfix-confirmed")) | length) as $confirmed
57
+ | ($items | map(select(.answer == null)) | length) as $pending
58
+ | {found: (($added | length) + ($applied | length) + $released),
59
+ open: ($items | map(select(.answer == null and (.id as $i | $new | index($i) | not))) | length),
60
+ counts: (if ($added | length) + ($applied | length) + ($issues | length) + ($notes | length) + $pending == 0 then {}
61
+ else {added: ($added | length), answered: ($applied | length), released: $released, pending: $pending,
62
+ "not understood": ($notes | length)} + (if $confirmed > 0 then {confirmed: $confirmed} else {} end) end),
63
+ report: (if $url == "" then null else $url end),
64
+ added: $added, applied: $applied, unparsed: [$notes[].what], issues: $issues,
65
+ reason: "\($added | length) item(s) added, \($applied | length) answer(s) applied, \($released) issue(s) back in the queue, \(if $confirmed > 0 then "\($confirmed) handed to settlement to close, " else "" end)\($pending) item(s) pending"}
66
+ + $extra'
67
+ exit 0
68
+ }
69
+
70
+ # stop <check> <reason>: an environment stop. In a watch it is the stage's result, carrying
71
+ # whatever was applied before it; in a dry run it is the driver's stop line and exit 3.
72
+ stop() {
73
+ if [[ "$MODE" == dry ]]; then echo "warden: stop environment ($1): $2" >&2; exit 3; fi
74
+ result "$(jq -cn --arg check "$1" --arg reason "$2" '{stop: "environment", check: $check, reason: $reason}')"
75
+ }
76
+
77
+ [[ -n "$REPO_ROOT" && -n "${KRYSO_WATCH_CONFIG:-}" ]] || { echo "report: needs <repo> and KRYSO_WATCH_CONFIG from warden.sh" >&2; exit 64; }
78
+ [[ "$MODE" == dry || -n "$WATCH_DIR" ]] || { echo "report: needs <watch-dir> outside a dry run" >&2; exit 64; }
79
+ cd "$REPO_ROOT" || stop repo "cannot enter $REPO_ROOT"
80
+
81
+ CONFIG="$KRYSO_WATCH_CONFIG"
82
+ cfg() { jq -r "$1" <<< "$CONFIG"; }
83
+ BASE="$(cfg .base)"
84
+ CAP="$(cfg .caps.triage)"
85
+ LOG_LABEL="$(cfg .labels.log)"
86
+ REPORT_LABEL="$(cfg .labels.report)"
87
+ export LOG_LABEL REPORT_LABEL
88
+ # shellcheck source=../tracker.sh
89
+ source "$WARDEN_DIR/tracker.sh" || stop install "cannot source $WARDEN_DIR/tracker.sh"
90
+ # shellcheck source=../stage-common.sh
91
+ source "$WARDEN_DIR/stage-common.sh" || stop install "cannot source $WARDEN_DIR/stage-common.sh"
92
+ ROLE_MAP="$(role_map "$REPO_ROOT")"
93
+ label_for() { jq -r --arg r "$1" '.[$r]' <<< "$ROLE_MAP"; }
94
+
95
+ # ---- the report ----------------------------------------------------------------------------
96
+ #
97
+ # The open report is the lowest-numbered open issue carrying the report label. Its items are
98
+ # the markers in its body, and the items marker records when a watch last read its comments.
99
+
100
+ OPEN="$(gh issue list --state open --label "$REPORT_LABEL" --json number,url,body,comments --limit 100 2>&1)" \
101
+ || stop "report reads" "cannot read the decision report: $(head -1 <<< "$OPEN")"
102
+ OPEN="$(jq -c 'if type == "array" then (min_by(.number) // null) else error("not an array") end' <<< "$OPEN" 2>/dev/null)" \
103
+ || stop "report reads" "the decision report list is not a JSON array"
104
+ OPEN="$(markers_read "$OPEN")"
105
+ BODY_NOW=""
106
+ READ_AT=""
107
+ PREAMBLE=""
108
+ COMMENTS='[]'
109
+ if [[ "$OPEN" != null ]]; then
110
+ REPORT_NUMBER="$(jq -r .number <<< "$OPEN")"
111
+ REPORT_URL="$(jq -r .url <<< "$OPEN")"
112
+ BODY_NOW="$(jq -r '.body // ""' <<< "$OPEN")"
113
+ COMMENTS="$(jq -c '.comments // []' <<< "$OPEN")"
114
+ ITEMS="$(jq -c --arg m "$ITEM_MARKER" '.body // "" | split("\n")
115
+ | [.[] | select(startswith($m)) | ltrimstr($m) | rtrimstr(" -->") | fromjson? | select(type == "object")]' <<< "$OPEN")"
116
+ READ_AT="$(jq -r --arg m "$ITEMS_MARKER" '.body // "" | split("\n") | map(select(startswith($m))) | first // ""
117
+ | capture("read=(?<at>[^ ]+)").at? // ""' <<< "$OPEN")"
118
+ PREAMBLE="$(jq -r --arg m "$ITEMS_MARKER" '.body // "" | split("\n")
119
+ | (map(startswith($m)) | index(true)) as $at | if $at == null then . else .[:$at] end | join("\n") | sub("\\s+$"; "")' <<< "$OPEN")"
120
+ fi
121
+
122
+ # The header a report the warden opens starts with.
123
+ HEADER="Calls the warden could not make on its own. Answer them all in one comment, one answer per line:
124
+
125
+ - \`yes to all\` takes the recommended option for every open item
126
+ - \`Q3: b\` or \`3: b\` answers one item
127
+ - \`Q3: other\` followed by your own words records a free answer
128
+
129
+ A later comment overrides an earlier one. The next watch writes each answer onto its issue and puts the issue back in the queue once every item it waits on is answered."
130
+
131
+ # render_body: the report body for ITEMS, the items marker carrying the read time.
132
+ render_body() {
133
+ jq -rn --arg pre "${PREAMBLE:-$HEADER}" --arg read "$READ_AT" --arg m "$ITEMS_MARKER" --arg im "$ITEM_MARKER" --argjson items "$ITEMS" "$LETTERS"'
134
+ def answer_line:
135
+ if .answer == null then empty
136
+ elif .answer.option != null then "**Answer:** **\(letter(.answer.option))**, \(.options[.answer.option].label)."
137
+ else "**Answer**, in the person'"'"'s own words: \(.answer.text)" end;
138
+ $pre, "", "\($m)\(if $read == "" then "" else " read=\($read)" end) -->",
139
+ ($items[]
140
+ | "", "### Q\(.n). \(.title)\(if .answer != null then " (answered)" else "" end)", "",
141
+ "\($im)\(tojson | gsub("--"; "-\\u002d")) -->", "",
142
+ "For \(.url) (item \(.id)). \(.why)", "",
143
+ (.recommended as $r | .options | to_entries[]
144
+ | "- **\(letter(.key))** \(.value.label): \(.value.consequence)\(if .key == $r then " (recommended)" else "" end)"),
145
+ (answer_line | "", .))'
146
+ }
147
+
148
+ # flush_body: the rendered body onto the open report when it changed. A failed write here is
149
+ # recorded as a note, since the stage is already on its way out.
150
+ FLUSHING=0
151
+ FLUSHED_ITEMS="$ITEMS"
152
+ FLUSHED_READ="$READ_AT"
153
+ flush_body() {
154
+ [[ -n "$REPORT_NUMBER" && "$FLUSHING" -eq 0 && -d "$WATCH_DIR/report" ]] || return 0
155
+ [[ "$ITEMS" != "$FLUSHED_ITEMS" || "$READ_AT" != "$FLUSHED_READ" ]] || return 0
156
+ FLUSHING=1
157
+ local f="$WATCH_DIR/report/body.md" err
158
+ render_body > "$f"
159
+ if [[ "$(cat "$f")" != "$BODY_NOW" ]]; then
160
+ if err="$(tracker_write issue edit "$REPORT_NUMBER" --body-file "$f" 2>&1 >/dev/null)"; then
161
+ BODY_NOW="$(cat "$f")"; FLUSHED_ITEMS="$ITEMS"; FLUSHED_READ="$READ_AT"
162
+ else
163
+ NOTES="$(jq -c --arg w "the report body edit on #$REPORT_NUMBER failed: $(head -1 <<< "$err")" '. + [{what: $w}]' <<< "$NOTES")"
164
+ fi
165
+ fi
166
+ FLUSHING=0
167
+ }
168
+
169
+ # ---- the answers ---------------------------------------------------------------------------
170
+ #
171
+ # A person's comments are every comment that carries no warden marker, does not open with an
172
+ # agent's header, the warden's or any other procedure's, on its first line or on the line
173
+ # after a machine marker, and is not a bot's, since the warden
174
+ # and the other agents post as the person's own login.
175
+ # Only comments made since the last read count, in order, later overriding earlier.
176
+
177
+ PARSED="$(jq -c --argjson items "$ITEMS" --arg read "$READ_AT" --arg agent_stem "$AGENT_HEADER_STEM" "$LETTERS"'
178
+ def agent_header: gsub("\r"; "") | split("\n")
179
+ | (.[0] | startswith($agent_stem)) or ((.[0] | test("^<!--.*-->$")) and ((.[1] // "") | startswith($agent_stem)));
180
+ def human: ((.body // "") | (contains("<!-- warden:") or agent_header) | not)
181
+ and ((.author.login // "") | (endswith("[bot]") or IN("github-actions", "dependabot", "renovate")) | not);
182
+ def all_line: test("^\\s*yes to all\\s*[.!]?\\s*$"; "i");
183
+ def one_line: test("^\\s*[Qq]?[0-9]+\\s*:");
184
+ def near_line: test("^\\s*[Qq][0-9]+\\b");
185
+ def events:
186
+ (.body // "" | gsub("\r"; "") | split("\n")) as $lines
187
+ | [range(0; $lines | length) as $i | $lines[$i] as $l
188
+ | if ($l | all_line) then {kind: "all", line: $l}
189
+ elif ($l | one_line) then
190
+ ($l | capture("^\\s*[Qq]?(?<n>[0-9]+)\\s*:\\s*(?<rest>.*?)\\s*$")) as $m
191
+ | {n: ($m.n | tonumber), line: ($l | sub("^\\s+"; ""))} as $base
192
+ | if ($m.rest | test("^[A-Za-z]$")) then $base + {kind: "one", letter: ($m.rest | ascii_downcase)}
193
+ elif ($m.rest | test("^other\\b"; "i")) then
194
+ ($m.rest | sub("^other\\b[\\s:,.]*"; ""; "i")) as $same
195
+ | (if $same != "" then $same
196
+ else $lines[($i + 1):] | (map(all_line or one_line) | index(true)) as $stop
197
+ | .[:($stop // length)] | join("\n") | sub("^\\s+"; "") | sub("\\s+$"; "") end) as $text
198
+ | if $text == "" then $base + {kind: "bad", why: "Q\($base.n): other with no words after it"}
199
+ else $base + {kind: "other", text: $text} end
200
+ else $base + {kind: "bad", why: "Q\($base.n): \($m.rest | if . == "" then "no answer" else "\"\(.)\" is not an option" end)"} end
201
+ elif ($l | near_line) then {kind: "form", why: "\"\($l | sub("^\\s+"; "") | sub("\\s+$"; ""))\" is not in a form the report reads, such as Q3: b"}
202
+ else empty end];
203
+ def note($c; $what): .notes += [{comment: ($c.url // null), at: $c.createdAt, what: $what}];
204
+ def item($n): [$items[] | select(.n == $n)] | first;
205
+ [.[] | select(human and ($read == "" or .createdAt > $read))] | sort_by(.createdAt) as $people
206
+ | $people | reduce .[] as $c ({answers: {}, notes: []};
207
+ ($c | events) as $ev
208
+ | if ($ev | length) == 0 then note($c; "a comment with no answer in it")
209
+ else reduce $ev[] as $e (.;
210
+ if $e.kind == "form" then note($c; $e.why)
211
+ elif $e.kind == "all" then
212
+ reduce ($items[] | select(.answer == null and .added_at < $c.createdAt)) as $it (.;
213
+ if .answers | has($it.n | tostring) then .
214
+ else .answers[$it.n | tostring] = {n: $it.n, option: $it.recommended, text: null, form: "yes to all", comment: ($c.url // null), at: $c.createdAt} end)
215
+ else item($e.n) as $it
216
+ | if $it == null or $it.added_at >= $c.createdAt then note($c; "Q\($e.n): no such item")
217
+ elif $it.applied != null then note($c; "Q\($e.n): already applied to its issue, so this later answer is not")
218
+ elif $e.kind == "bad" then note($c; $e.why)
219
+ elif $e.kind == "one" then
220
+ letter_index($e.letter) as $o
221
+ | if $o >= ($it.options | length) then note($c; "Q\($e.n): \"\($e.letter)\" is not an option")
222
+ else .answers[$e.n | tostring] = {n: $e.n, option: $o, text: null, form: $e.line, comment: ($c.url // null), at: $c.createdAt} end
223
+ else .answers[$e.n | tostring] = {n: $e.n, option: null, text: $e.text, form: $e.line, comment: ($c.url // null), at: $c.createdAt} end
224
+ end)
225
+ end)
226
+ | {answers: ([.answers[]] | sort_by(.n)), notes,
227
+ read: ([$read, ($people[].createdAt)] | map(select(. != null and . != "")) | max // "")}' <<< "$COMMENTS" 2>&1)" || stop "report reads" "cannot read the answers on the report: $(head -1 <<< "$PARSED")"
228
+ NEW_ANSWERS="$(jq -c .answers <<< "$PARSED")"
229
+ NOTES="$(jq -c '.notes' <<< "$PARSED")"
230
+ # The post mode applies nothing: the comments were read by this watch's first run, and a
231
+ # comment made between the two runs waits for the next watch.
232
+ if [[ "$MODE" == post ]]; then NEW_ANSWERS='[]'; NOTES='[]'; fi
233
+
234
+ # items_of <numbers-json>: the report's items with those numbers.
235
+ items_of() { jq -c --argjson ns "$1" 'map(select(.n as $n | $ns | index($n)))' <<< "$ITEMS"; }
236
+
237
+ # confirmed_file <items-json> <answers-json>: the out-of-scope ledger file a person confirmed
238
+ # the close for among the items, an answer given here winning over the one recorded, or
239
+ # nothing. Only an item triage matched to the ledger carries a file.
240
+ confirmed_file() {
241
+ jq -r --argjson answers "$2" --arg close "$CLOSE_OPTION" '
242
+ .[] | select(.out_of_scope != null) | . as $it
243
+ | (([$answers[] | select(.n == $it.n)] | last) // $it.answer) as $a
244
+ | select($a != null and $a.option != null and $it.options[$a.option].label == $close)
245
+ | .out_of_scope' <<< "$1" | head -1
246
+ }
247
+
248
+ # The issues whose every item on the report would be answered, in item order.
249
+ releasable() {
250
+ jq -c --argjson answers "$1" '
251
+ ($answers | map(.n)) as $now
252
+ | [map(select(.applied == null)) | group_by(.issue)[] | select(all(.[]; .answer != null or (.n as $n | $now | index($n))))
253
+ | {issue: .[0].issue, first: (map(.n) | min), items: map(.n)}]
254
+ | sort_by(.first)' <<< "$ITEMS"
255
+ }
256
+
257
+ # answer_text <n> [items-json]: an item's answer in words, read from the items given or ITEMS.
258
+ answer_text() {
259
+ jq -r --argjson n "$1" "$LETTERS"'
260
+ .[] | select(.n == $n)
261
+ | if .answer.option != null then "\(letter(.answer.option)) (\(.options[.answer.option].label): \(.options[.answer.option].consequence))"
262
+ else "other, in the person'"'"'s own words: \(.answer.text)" end' <<< "${2:-$ITEMS}"
263
+ }
264
+
265
+ if [[ "$MODE" == dry ]]; then
266
+ if [[ -z "$REPORT_URL" ]]; then echo "warden: report: none open"; exit 0; fi
267
+ jq -r --arg url "$REPORT_URL" --argjson a "$NEW_ANSWERS" --argjson notes "$NOTES" "$LETTERS"'
268
+ ([.[] | select(.answer == null)]) as $pending
269
+ | "warden: report: \($url) open, \(length) item(s), \($pending | length) pending",
270
+ ($pending[] | "warden: report pending Q\(.n): \(.title) (#\(.issue))"),
271
+ (.[] | . as $it | $a[] | select(.n == $it.n)
272
+ | "warden: report would apply Q\(.n) to #\($it.issue): \(if .option != null then letter(.option) else "other: \(.text)" end)"),
273
+ ($notes[] | "warden: report not understood: \(.what)")' <<< "$ITEMS"
274
+ released=0
275
+ while IFS= read -r r; do
276
+ [[ -n "$r" ]] || continue
277
+ file="$(confirmed_file "$(items_of "$(jq -c .items <<< "$r")")" "$NEW_ANSWERS")"
278
+ if [[ -n "$file" ]]; then
279
+ echo "warden: report would hand #$(jq -r .issue <<< "$r") to settlement to close as wontfix, citing $file"
280
+ continue
281
+ fi
282
+ [[ "$released" -lt "$CAP" ]] || continue
283
+ released=$(( released + 1 ))
284
+ echo "warden: report would put #$(jq -r .issue <<< "$r") back in the queue, every item it waits on answered"
285
+ done < <(jq -c '.[]' <<< "$(releasable "$NEW_ANSWERS")")
286
+ exit 0
287
+ fi
288
+
289
+ mkdir -p "$WATCH_DIR/report" || stop state "cannot create $WATCH_DIR/report"
290
+ REPORT_DIR="$WATCH_DIR/report"
291
+ [[ "$MODE" == post ]] || printf '%s\n' "$PARSED" | jq . > "$REPORT_DIR/answers.json"
292
+
293
+ # ---- the writes ----------------------------------------------------------------------------
294
+
295
+ WRITE_ERR=""
296
+ write() {
297
+ WRITE_ERR="$(tracker_write "$@" 2>&1 >/dev/null)" || { WRITE_ERR="$(head -1 <<< "$WRITE_ERR")"; return 1; }
298
+ }
299
+ write_or_stop() {
300
+ local what="$1"; shift
301
+ write "$@" || stop "tracker write" "$what failed${WRITE_ERR:+: $WRITE_ERR}"
302
+ }
303
+ save_applied() { printf '%s\n' "$APPLIED" | jq . > "$REPORT_DIR/applied.json"; }
304
+
305
+ # apply_answer <answer-json>: the answer written onto its parked issue, and only once that
306
+ # landed, recorded on the item, so a failed write leaves the item as the next watch finds it.
307
+ # A later answer to an item not yet applied replaces the earlier one and is posted again.
308
+ apply_answer() {
309
+ local a="$1" n issue f next
310
+ n="$(jq -r .n <<< "$a")"
311
+ next="$(jq -c --argjson a "$a" 'map(if .n == $a.n then .answer = ($a | {option, text, form, comment, at}) else . end)' <<< "$ITEMS")"
312
+ issue="$(jq -r --argjson n "$n" '.[] | select(.n == $n) | .issue' <<< "$next")"
313
+ f="$REPORT_DIR/Q$n.answer.md"
314
+ comment_file "$f" "$(jq -r --argjson n "$n" --arg url "$REPORT_URL" --arg report "$REPORT_NUMBER" --arg answer "$(answer_text "$n" "$next")" '
315
+ .[] | select(.n == $n)
316
+ | "**Decision report #\($report), Q\(.n) answered:** \(.title)", "",
317
+ "Answer: \($answer)", "",
318
+ "From \(.answer.comment // $url). \(if .out_of_scope != null then "Once every item it waits on is answered, a confirmed close goes to settlement, and any other answer puts this issue back in the queue." else "This issue goes back in the queue once every item it waits on is answered." end)", "",
319
+ "<!-- warden:answered report=\($report) q=\(.n) id=\(.id) -->"' <<< "$next")"
320
+ write_or_stop "the answer comment for Q$n on #$issue" issue comment "$issue" --body-file "$f"
321
+ ITEMS="$next"
322
+ APPLIED="$(jq -c --argjson a "$a" --argjson i "$issue" "$LETTERS"'. + [{n: $a.n, issue: $i, answer: (if $a.option != null then letter($a.option) else "other" end), comment: $a.comment}]' <<< "$APPLIED")"
323
+ save_applied
324
+ }
325
+
326
+ while IFS= read -r answer; do
327
+ [[ -z "$answer" ]] || apply_answer "$answer"
328
+ done < <(jq -c '.[]' <<< "$NEW_ANSWERS")
329
+ [[ "$MODE" == post ]] || READ_AT="$(jq -r .read <<< "$PARSED")"
330
+ flush_body
331
+
332
+ # ---- the release ---------------------------------------------------------------------------
333
+ #
334
+ # An issue whose every item is answered gets one fresh context, capped at caps.triage a
335
+ # watch, which rewrites its brief and criteria from the answers. The driver writes the
336
+ # criteria into the body, posts the brief with the release marker, and moves the issue to
337
+ # ready-for-agent. A refused outcome leaves the issue parked and the next watch tries again.
338
+
339
+ release_record() { printf '%s\n' "$2" | jq . > "$REPORT_DIR/$1.json"; }
340
+ note_issue() { ISSUES_JSON="$(jq -c --argjson n "$1" --arg s "$2" '. + [{issue: $n, state: $s}]' <<< "$ISSUES_JSON")"; }
341
+ mark_applied() {
342
+ ITEMS="$(jq -c --argjson ns "$1" --arg w "$WATCH_ID" --arg at "$(date -u +%FT%TZ)" --arg how "$2" \
343
+ 'map(if (.n as $n | $ns | index($n)) then .applied = {watch: $w, at: $at, how: $how} else . end)' <<< "$ITEMS")"
344
+ }
345
+
346
+ RUNNER_READY=0
347
+ load_runner() {
348
+ [[ "$RUNNER_READY" -eq 0 ]] || return 0
349
+ local dir="${KRYSO_SHIFT_SKILL_DIR:-}" err="$REPORT_DIR/runner.err"
350
+ [[ -f "$dir/runner.sh" && -f "$dir/result.sh" ]] || stop install "cannot find ship-loop's runner.sh and result.sh in '$dir'"
351
+ # shellcheck source=/dev/null
352
+ source "$dir/runner.sh" || stop install "cannot source $dir/runner.sh"
353
+ # shellcheck source=/dev/null
354
+ source "$dir/result.sh" || stop install "cannot source $dir/result.sh"
355
+ runner_profile_load "$(cfg .profile)" "${KRYSO_PROFILE_FILE:-}" 2> "$err" || stop runner "cannot load profile '$(cfg .profile)': $(head -1 "$err")"
356
+ runner_validate_options 0 "$(cfg .caps.budget)" 0 "$RUNNER_EFFORT" 2> "$err" || stop runner "$(head -1 "$err")"
357
+ rm -f "$err"
358
+ RUNNER_READY=1
359
+ }
360
+
361
+ release() {
362
+ local issue="$1" ns="$2" view host="$REPORT_DIR/$1.host.json" code limit outcome why record held f target answers
363
+ view="$(gh issue view "$issue" --json number,title,body,url,state,labels 2>&1)" \
364
+ || stop "report reads" "cannot read #$issue: $(head -1 <<< "$view")"
365
+ record="$(jq -cn --argjson n "$issue" --argjson ns "$ns" '{issue: $n, items: $ns}')"
366
+ if [[ "$(jq -r '.state // "OPEN"' <<< "$view")" != OPEN ]]; then
367
+ mark_applied "$ns" "the issue is closed"
368
+ release_record "$issue" "$(jq -c '. + {released: false, reason: "the issue is closed, so nothing was written"}' <<< "$record")"
369
+ note_issue "$issue" closed
370
+ return 0
371
+ fi
372
+ answers="$(jq -r --argjson ns "$ns" --arg url "$REPORT_URL" '.[] | select(.n as $n | $ns | index($n)) | .n' <<< "$ITEMS" \
373
+ | while read -r q; do jq -r --argjson n "$q" '.[] | select(.n == $n) | "- Q\(.n), \(.title) \(.why)"' <<< "$ITEMS"; echo " Answer: $(answer_text "$q")"; done)"
374
+ load_runner
375
+ # shellcheck disable=SC2034 # both read by runner_execute, from ship-loop's runner.sh
376
+ RUNNER_SCHEMA="$OUTCOME_SCHEMA"
377
+ # shellcheck disable=SC2034
378
+ RUNNER_EXTRA_ARGS=()
379
+ runner_execute start "$host" "$REPORT_DIR/$issue.final.json" "$REPORT_DIR/$issue.err" \
380
+ "$(runner_skill_prompt triage "Update issue #$issue after a person answered the decisions it was parked on, as one fresh context of a warden watch on base branch $BASE. Nobody is here to answer: never ask a person and never wait for direction. Write nothing to the tracker, the board or the working tree: the driver applies the outcome. The answers, from the decision report $REPORT_URL:
381
+ $answers
382
+ Read the issue, its comments and the code it touches. Return the agent brief rewritten to follow the answers in brief, and every acceptance criterion, updated to follow the answers, in acceptance_criteria.")" \
383
+ "" "" "" "$(cfg .caps.budget)" 0 "$RUNNER_EFFORT" </dev/null
384
+ code=$?
385
+ limit="$(result_limit "$host" "$code")"
386
+ record="$(jq -c --arg h "$issue.host.json" --argjson code "$code" --arg sub "$(result_field "$host" .subtype none)" \
387
+ --arg cost "$(result_field "$host" .cost_usd null)" '. + {host: {result: $h, exit: $code, subtype: $sub, cost_usd: ($cost | tonumber? // null)}}' <<< "$record")"
388
+ if [[ "$limit" == rate-limited ]]; then
389
+ release_record "$issue" "$(jq -c '. + {released: false, reason: "the host hit a rate limit"}' <<< "$record")"
390
+ note_issue "$issue" rate-limited
391
+ result "$(jq -cn --argjson n "$issue" '{stop: "rate-limited", reason: "the report context for #\($n) hit a rate limit"}')"
392
+ fi
393
+ outcome="$(outcome_of "$host" acceptance_criteria)"
394
+ if [[ -z "$outcome" ]]; then why="the context returned no outcome (${limit:-subtype $(result_field "$host" .subtype none)})"
395
+ else why="$(schema_reason "$OUTCOME_SCHEMA" "$outcome")"; fi
396
+ if [[ -n "$why" ]]; then
397
+ release_record "$issue" "$(jq -c --arg why "$why" --arg o "$outcome" '. + {outcome: ($o | fromjson? // null), released: false, reason: $why}' <<< "$record")"
398
+ note_issue "$issue" refused
399
+ return 0
400
+ fi
401
+
402
+ f="$REPORT_DIR/$issue.body.md"
403
+ criteria_body "$(jq -r '.body // ""' <<< "$view")" "$(jq -c .acceptance_criteria <<< "$outcome")" > "$f"
404
+ write_or_stop "the body edit on #$issue" issue edit "$issue" --body-file "$f"
405
+ f="$REPORT_DIR/$issue.brief.md"
406
+ comment_file "$f" "$(jq -r .brief <<< "$outcome")
407
+
408
+ $RELEASE_MARKER report=$REPORT_NUMBER q=$(jq -r 'join(",")' <<< "$ns") -->"
409
+ write_or_stop "the brief comment on #$issue" issue comment "$issue" --body-file "$f"
410
+ target="$(label_for ready-for-agent)"
411
+ held="$(jq -c '[.labels[]?.name]' <<< "$view")"
412
+ state_edit "$ROLE_MAP" "$held" "$target"
413
+ if [[ "${#STATE_ADD[@]}" -gt 0 || "${#STATE_REMOVE[@]}" -gt 0 ]]; then
414
+ write_or_stop "the label edit on #$issue" issue edit "$issue" ${STATE_ADD[@]+"${STATE_ADD[@]}"} ${STATE_REMOVE[@]+"${STATE_REMOVE[@]}"}
415
+ fi
416
+ mark_applied "$ns" "back in the queue as ready-for-agent"
417
+ release_record "$issue" "$(jq -c --argjson o "$outcome" '. + {outcome: $o, released: true, state: "ready-for-agent"}' <<< "$record")"
418
+ note_issue "$issue" ready-for-agent
419
+ }
420
+
421
+ # hand_off <issue> <numbers-json> <file>: a confirmed out-of-scope match, handed to
422
+ # settlement. No context starts and the state label stays: settlement closes the issue as
423
+ # wontfix, citing the file, once it reads the marker. ADR 0033 says why the report does not
424
+ # close it itself, and why nobody but a person writes to the ledger. A closed issue is left as
425
+ # it is, the way a release leaves one.
426
+ hand_off() {
427
+ local issue="$1" ns="$2" file="$3" f view
428
+ view="$(gh issue view "$issue" --json number,state 2>&1)" || stop "report reads" "cannot read #$issue: $(head -1 <<< "$view")"
429
+ if [[ "$(jq -r '.state // "OPEN"' <<< "$view")" != OPEN ]]; then
430
+ mark_applied "$ns" "the issue is closed"
431
+ release_record "$issue" "$(jq -cn --argjson n "$issue" --argjson ns "$ns" '{issue: $n, items: $ns, released: false, reason: "the issue is closed, so nothing was written"}')"
432
+ note_issue "$issue" closed
433
+ return 0
434
+ fi
435
+ f="$REPORT_DIR/$issue.confirmed.md"
436
+ comment_file "$f" "**Decision report #$REPORT_NUMBER confirmed the close:** the out-of-scope ledger refuses this request in \`$file\`. Settlement closes this issue as wontfix on its next run, with a comment linking the file. Adding the issue under the file's Prior requests is a person's step.
437
+
438
+ $CONFIRM_MARKER report=$REPORT_NUMBER q=$(jq -r 'join(",")' <<< "$ns") file=$file -->"
439
+ write_or_stop "the hand-off comment on #$issue" issue comment "$issue" --body-file "$f"
440
+ mark_applied "$ns" "confirmed wontfix, handed to settlement to close"
441
+ release_record "$issue" "$(jq -cn --argjson n "$issue" --argjson ns "$ns" --arg file "$file" \
442
+ '{issue: $n, items: $ns, released: false, confirmed: true, out_of_scope: $file, reason: "a person confirmed the out-of-scope match, so settlement closes it"}')"
443
+ note_issue "$issue" wontfix-confirmed
444
+ }
445
+
446
+ # A confirmed match costs no context, so the cap counts only the releases.
447
+ released=0
448
+ while IFS= read -r r; do
449
+ [[ -n "$r" && "$MODE" != post ]] || continue
450
+ file="$(confirmed_file "$(items_of "$(jq -c .items <<< "$r")")" '[]')"
451
+ if [[ -n "$file" ]]; then
452
+ hand_off "$(jq -r .issue <<< "$r")" "$(jq -c .items <<< "$r")" "$file"
453
+ flush_body
454
+ continue
455
+ fi
456
+ if [[ "$released" -ge "$CAP" ]]; then
457
+ NOTES="$(jq -c --argjson i "$(jq .issue <<< "$r")" --argjson cap "$CAP" '. + [{what: "#\($i) waits for the next watch: caps.triage is \($cap)"}]' <<< "$NOTES")"
458
+ continue
459
+ fi
460
+ released=$(( released + 1 ))
461
+ release "$(jq -r .issue <<< "$r")" "$(jq -c .items <<< "$r")"
462
+ flush_body
463
+ done < <(jq -c '.[]' <<< "$(releasable '[]')")
464
+
465
+ # ---- closing and posting -------------------------------------------------------------------
466
+ #
467
+ # A report whose every item is applied is closed, with the close's own comment. Then the items
468
+ # this watch parked go onto the open report with one comment, or open a new one, and each
469
+ # parked issue gets a marker naming the report and its items' numbers.
470
+
471
+ if [[ "$MODE" != post && -n "$REPORT_NUMBER" && "$(jq 'length > 0 and all(.[]; .applied != null)' <<< "$ITEMS")" == true ]]; then
472
+ flush_body
473
+ write_or_stop "the close of the report #$REPORT_NUMBER" issue close "$REPORT_NUMBER" \
474
+ --comment "Every item on this report is answered, and each issue it held is back in the queue or handed to settlement to close, so it is closed. The next decision opens a new report.
475
+
476
+ $REPORT_MARKER watch=$WATCH_ID closed -->"
477
+ REPORT_NUMBER=""
478
+ ITEMS='[]'
479
+ PREAMBLE=""
480
+ READ_AT=""
481
+ BODY_NOW=""
482
+ fi
483
+
484
+ # The items this watch left and has not posted yet: an earlier run of this body in the same
485
+ # watch recorded the ones it posted in added.json, and the post mode skips those.
486
+ NEW_ITEMS='[]'
487
+ [[ ! -f "$WATCH_DIR/report-items.json" ]] || NEW_ITEMS="$(jq -c 'if type == "array" then . else [] end' "$WATCH_DIR/report-items.json" 2>/dev/null || echo '[]')"
488
+ POSTED='[]'
489
+ [[ ! -f "$REPORT_DIR/added.json" ]] || POSTED="$(jq -c 'if type == "array" then . else [] end' "$REPORT_DIR/added.json" 2>/dev/null || echo '[]')"
490
+ NEW_ITEMS="$(jq -c --argjson posted "$POSTED" '($posted | map(.id)) as $ids | map(select(.id as $i | $ids | index($i) | not))' <<< "$NEW_ITEMS")"
491
+ if [[ "$(jq length <<< "$NEW_ITEMS")" -gt 0 ]]; then
492
+ ADDED="$(jq -c --argjson items "$ITEMS" --arg at "$(date -u +%FT%TZ)" '
493
+ ([$items[].n] | max // 0) as $top
494
+ | to_entries | map(.value + {n: ($top + .key + 1), added_at: $at, answer: null, applied: null})' <<< "$NEW_ITEMS")"
495
+ ITEMS="$(jq -c --argjson a "$ADDED" '. + $a' <<< "$ITEMS")"
496
+ ADDED="$(jq -c 'map({n, id, issue})' <<< "$ADDED")"
497
+ jq -n --argjson posted "$POSTED" --argjson added "$ADDED" '$posted + $added' > "$REPORT_DIR/added.json"
498
+ if [[ -n "$REPORT_NUMBER" ]]; then
499
+ flush_body
500
+ f="$REPORT_DIR/added.md"
501
+ jq -r --arg w "$WATCH_ID" --arg m "$REPORT_MARKER" '
502
+ "Watch `\($w)` added \(length) item(s): \(map("Q\(.n)") | join(", ")).", "", "\($m) watch=\($w) added=\(map(.n) | join(",")) -->"' <<< "$ADDED" > "$f"
503
+ write_or_stop "the comment on the report #$REPORT_NUMBER" issue comment "$REPORT_NUMBER" --body-file "$f"
504
+ else
505
+ f="$REPORT_DIR/body.md"
506
+ render_body > "$f"
507
+ out="$(tracker_write issue create --title "Decision report" --label "$REPORT_LABEL" --body-file "$f" 2>&1)" \
508
+ || stop "tracker write" "cannot open the decision report: $(head -1 <<< "$out")"
509
+ REPORT_URL="$(grep -oE 'https://[^ ]+/issues/[0-9]+' <<< "$out" | tail -1)"
510
+ [[ -n "$REPORT_URL" ]] || stop "tracker write" "gh issue create printed no issue URL for the decision report"
511
+ REPORT_NUMBER="${REPORT_URL##*/}"
512
+ BODY_NOW="$(cat "$f")"
513
+ fi
514
+ while IFS= read -r issue; do
515
+ [[ -n "$issue" ]] || continue
516
+ f="$REPORT_DIR/$issue.parked.md"
517
+ comment_file "$f" "$(jq -r --argjson i "$issue" --argjson added "$ADDED" --arg url "$REPORT_URL" --arg r "$REPORT_NUMBER" --arg w "$WATCH_ID" --arg m "$PARK_MARKER" '
518
+ ($added | map(.id)) as $new | map(select(.issue == $i and (.id as $id | $new | index($id)))) as $mine
519
+ | "Posted to the decision report, \($url), as \($mine | map("Q\(.n) (\(.title))") | join(" and ")). One reply there answers them.",
520
+ "", "\($m) watch=\($w) items=\($mine | map(.id) | join(",")) report=\($r) q=\($mine | map(.n) | join(",")) -->"' <<< "$ITEMS")"
521
+ write_or_stop "the parking marker on #$issue" issue comment "$issue" --body-file "$f"
522
+ done < <(jq -r 'map(.issue) | unique | .[]' <<< "$ADDED")
523
+ fi
524
+
525
+ result