@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,35 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "outcome": {
5
+ "type": "string",
6
+ "enum": ["decided", "out-of-scope", "needs-decision"],
7
+ "description": "decided: every finding has one decision below. out-of-scope: answering the feedback needs changes the brief does not cover. needs-decision: the feedback turns on a choice a person should make."
8
+ },
9
+ "head": { "type": "string", "description": "The worktree's HEAD after the commit, from git rev-parse HEAD, or the head the brief named when nothing was committed." },
10
+ "reason": { "type": "string", "description": "One paragraph: what the findings were, what was decided, and where the evidence is." },
11
+ "decisions": {
12
+ "type": "array",
13
+ "description": "One object per finding, by the id the brief gave it.",
14
+ "items": {
15
+ "type": "object",
16
+ "properties": {
17
+ "finding": { "type": "string", "description": "The finding's id, as the brief gave it: review:<n>, comment:<n> or inline:<n>." },
18
+ "decision": {
19
+ "type": "string",
20
+ "enum": ["fixed", "deferred", "rejected"],
21
+ "description": "fixed: real and inside the brief, with a commit on the branch. deferred: real and outside the brief, with a tracking issue for the pass to open. rejected: wrong, with the fact checked."
22
+ },
23
+ "reason": { "type": "string", "description": "For a fix, what changed; for a deferral, why it is outside the brief; for a rejection, the fact checked that shows the finding wrong. The pass replies with it." },
24
+ "commit": { "type": ["string", "null"], "description": "For a fix, the sha of the commit that fixes it, which the ledger's feedback committed line names. Null otherwise." },
25
+ "title": { "type": ["string", "null"], "description": "For a deferral, the tracking issue's title. Null otherwise." },
26
+ "body": { "type": ["string", "null"], "description": "For a deferral, the tracking issue's body. Null otherwise." }
27
+ },
28
+ "required": ["finding", "decision", "reason", "commit", "title", "body"],
29
+ "additionalProperties": false
30
+ }
31
+ }
32
+ },
33
+ "required": ["outcome", "head", "reason", "decisions"],
34
+ "additionalProperties": false
35
+ }
@@ -0,0 +1,228 @@
1
+ #!/usr/bin/env bash
2
+ # feedback.sh: the one reading of a pull request's review feedback that the pass script, the
3
+ # driver's progress fingerprint and the stacked sweep's merge-ready read all share. It reads
4
+ # the whole of the evidence, every page of the reviews, the conversation and the inline
5
+ # comments, the resolution state of every thread and the head the PR stands at, into one
6
+ # document with a stable id per item, and sorts each item as harmless or actionable by an
7
+ # explicit rule table. Authorship decides nothing: a bot's notice and a person's approval
8
+ # are harmless by what they say and what state they are in, and anything the table does
9
+ # not name is kept for a decision. An endpoint that cannot be read or answers with the
10
+ # wrong shape is an evidence failure, `unreadable: <why>` on stdout and status 1, never an
11
+ # empty feedback set.
12
+ #
13
+ # Sourced, it defines functions and the marker pattern and runs nothing. Run as a command:
14
+ # feedback.sh read <owner/repo> <pr number> the normalized document, from gh
15
+ # feedback.sh normalize <reviews> <comments> <inline> <threads> <head>
16
+ # the document from four raw payloads
17
+ # feedback.sh classify the document on stdin, classified
18
+ # feedback.sh actionable <owner/repo> <pr number> read, then classify
19
+ # feedback.sh marker <finding> <decision> <digest> <issue>
20
+ # the marker a reply to a finding carries
21
+ # feedback.sh tracking-marker <finding> <pr url> the marker a tracking issue's body carries
22
+ # Needs jq, and gh for read and actionable.
23
+
24
+ # The marker a reply written by a pass carries on its first line, and the marker a tracking
25
+ # issue's body carries. They are the durable identifiers of a decision's remote effects: a
26
+ # read that finds the reply marks its finding answered, and a restart that finds either
27
+ # knows its write landed and does not write it again. The reply's marker carries the digest
28
+ # of the finding's text as it was decided, so an edit to the finding reopens it. A marker
29
+ # with no digest, written by hand, answers its finding whatever the finding says later.
30
+ feedback_marker() { printf '<!-- ship-it: finding=%s decision=%s digest=%s pass=%s -->' "$1" "$2" "$3" "$4"; }
31
+ feedback_tracking_marker() { printf '<!-- ship-it: tracks finding=%s pr=%s -->' "$1" "$2"; }
32
+ FEEDBACK_MARKER_RE='<!-- ship-it: finding=([a-z]+:[0-9]+) decision=(fixed|deferred|rejected)(?: digest=([0-9a-f]{12}))? pass=[^ ]+ -->'
33
+
34
+ # _feedback_digest: the first twelve hex digits of the sha256 of stdin. coreutils' sha256sum
35
+ # comes first, because shasum is a Perl script whose start costs more than the hash.
36
+ _feedback_sha() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$@"; else shasum -a 256 "$@"; fi; }
37
+ _feedback_digest() {
38
+ local d
39
+ d="$(_feedback_sha)"
40
+ printf '%s\n' "${d:0:12}"
41
+ }
42
+ # _feedback_digests <dir> <n>: the first twelve hex digits of the sha256 of each of the files
43
+ # <dir>/1 to <dir>/<n>, a line each in that order, from one hash process.
44
+ _feedback_digests() {
45
+ local dir="$1" n="$2" i line
46
+ local -a files=()
47
+ for ((i = 1; i <= n; i++)); do files+=("$dir/$i"); done
48
+ _feedback_sha "${files[@]}" | while IFS= read -r line; do printf '%s\n' "${line:0:12}"; done
49
+ }
50
+
51
+ # feedback_normalize <reviews> <comments> <inline> <threads> <head>: the four raw payloads,
52
+ # each one JSON array, and the head, to one document: {head, items}. Each item has an id of
53
+ # the form <kind>:<number> that is the same on every read, its author (null for a deleted
54
+ # account), body, state, path and line, the commit it was left on, and for an inline comment
55
+ # its thread's resolution, the thread's first comment it replies to and the review that holds
56
+ # it. No timestamp is kept, so none can move a reading. Prints `unreadable: <why>` and
57
+ # returns 1 on a payload of the wrong shape.
58
+ feedback_normalize() {
59
+ local reviews="$1" comments="$2" inline="$3" threads="$4" head="$5" name payload out
60
+ # One jq checks the four shapes and normalizes. Only when it refuses does each payload get a
61
+ # check of its own, so the refusal still names the first one of the wrong shape.
62
+ if out="$(_feedback_normalized "$@" 2>/dev/null)"; then printf '%s\n' "$out"; return 0; fi
63
+ for name in reviews comments inline threads; do
64
+ payload="${!name}"
65
+ jq -e 'type == "array"' <<< "$payload" >/dev/null 2>&1 || { echo "unreadable: the $name payload is not an array"; return 1; }
66
+ done
67
+ _feedback_normalized "$@"
68
+ }
69
+ _feedback_normalized() {
70
+ local reviews="$1" comments="$2" inline="$3" threads="$4" head="$5"
71
+ jq -cn --argjson reviews "$reviews" --argjson comments "$comments" --argjson inline "$inline" --argjson threads "$threads" --arg head "$head" '
72
+ if ([$reviews, $comments, $inline, $threads] | all(type == "array") | not) then error("a payload is not an array") else . end
73
+ | def user_login: if (.user | type) == "object" then (.user.login // null) else null end;
74
+ ($threads | map(. as $t | ($t.comments.nodes // [])[] | {key: ((.databaseId // 0) | tostring), value: ($t.isResolved // false)}) | from_entries) as $resolved
75
+ | {head: $head,
76
+ items: (
77
+ ($reviews | map({id: "review:\(.id)", kind: "review", author: user_login, body: (.body // ""), state: (.state // null),
78
+ path: null, line: null, commit: (.commit_id // null), resolved: null, in_reply_to: null,
79
+ review: null, url: (.html_url // null)}))
80
+ + ($comments | map({id: "comment:\(.id)", kind: "comment", author: user_login, body: (.body // ""), state: null,
81
+ path: null, line: null, commit: null, resolved: null, in_reply_to: null,
82
+ review: null, url: (.html_url // null)}))
83
+ + ($inline | map({id: "inline:\(.id)", kind: "inline", author: user_login, body: (.body // ""), state: null,
84
+ path: (.path // null), line: (.line // .original_line // null), commit: (.commit_id // null),
85
+ resolved: ($resolved[(.id | tostring)] // false), in_reply_to: (if .in_reply_to_id then "inline:\(.in_reply_to_id)" else null end),
86
+ review: (if .pull_request_review_id then "review:\(.pull_request_review_id)" else null end), url: (.html_url // null)}))
87
+ )}'
88
+ }
89
+
90
+ # feedback_read <owner/repo> <pr number>: the normalized document, read through gh: the PR's
91
+ # head, every page of the three REST endpoints and every page of the review threads. Any
92
+ # read that fails or comes back in the wrong shape is `unreadable: <why>`, status 1.
93
+ feedback_read() {
94
+ local nwo="$1" n="$2" pr_json head err raw reviews comments inline threads owner name
95
+ [[ "$n" =~ ^[0-9]+$ ]] || { echo "unreadable: '$n' is not a pull request number"; return 1; }
96
+ [[ "$nwo" == */* ]] || { echo "unreadable: '$nwo' is not owner/repo"; return 1; }
97
+ err="$(mktemp)"
98
+ pr_json="$(gh pr view "$n" --json headRefOid,state 2>"$err")" || { echo "unreadable: gh pr view $n: $(head -1 "$err")"; rm -f "$err"; return 1; }
99
+ head="$(jq -r '.headRefOid // empty' <<< "$pr_json" 2>/dev/null)"
100
+ [[ -n "$head" ]] || { echo "unreadable: gh pr view $n reported no head"; rm -f "$err"; return 1; }
101
+ _feedback_pages() {
102
+ local ep="$1" label="$2" pages
103
+ raw="$(gh api --paginate "$ep" 2>"$err")" || { echo "unreadable: gh api $ep: $(head -1 "$err")"; return 1; }
104
+ pages="$(jq -sc 'if length > 0 and all(type == "array") then [.[][]] else null end' <<< "$raw" 2>/dev/null)"
105
+ [[ -n "$pages" && "$pages" != null ]] || { echo "unreadable: the $label payload from $ep is not an array"; return 1; }
106
+ printf '%s' "$pages"
107
+ }
108
+ reviews="$(_feedback_pages "repos/$nwo/pulls/$n/reviews" reviews)" || { echo "$reviews"; rm -f "$err"; return 1; }
109
+ comments="$(_feedback_pages "repos/$nwo/issues/$n/comments" comments)" || { echo "$comments"; rm -f "$err"; return 1; }
110
+ inline="$(_feedback_pages "repos/$nwo/pulls/$n/comments" "inline comments")" || { echo "$inline"; rm -f "$err"; return 1; }
111
+ owner="${nwo%%/*}"; name="${nwo#*/}"
112
+ raw="$(gh api graphql --paginate -f owner="$owner" -f name="$name" -F number="$n" -f query='query($owner: String!, $name: String!, $number: Int!, $endCursor: String) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { reviewThreads(first: 100, after: $endCursor) { pageInfo { hasNextPage endCursor } nodes { isResolved comments(first: 100) { nodes { databaseId } } } } } } }' 2>"$err")" \
113
+ || { echo "unreadable: review threads: $(head -1 "$err")"; rm -f "$err"; return 1; }
114
+ threads="$(jq -sc 'if length > 0 and all(type == "object" and (.errors | not) and (.data.repository.pullRequest.reviewThreads.nodes | type) == "array") then [.[].data.repository.pullRequest.reviewThreads.nodes[]] else null end' <<< "$raw" 2>/dev/null)"
115
+ [[ -n "$threads" && "$threads" != null ]] || { echo "unreadable: the review threads query answered with the wrong shape: $(jq -c '.errors // .' <<< "$raw" 2>/dev/null | head -c 160)"; rm -f "$err"; return 1; }
116
+ rm -f "$err"
117
+ feedback_normalize "$reviews" "$comments" "$inline" "$threads" "$head"
118
+ }
119
+
120
+ # feedback_classify: the document on stdin, with each item sorted by the first rule that
121
+ # matches, in this order. own-reply: the body carries a pass's reply marker. answered: an
122
+ # item carries the marker naming this item, with this item's digest or none. resolved: an
123
+ # inline comment whose thread is resolved. dismissed: a dismissed review. approval: an
124
+ # approving review whose body is empty or an approval phrase. empty-review: a review with no
125
+ # body that holds inline comments, which are read on their own. approval-phrase: a body that
126
+ # is, whole, one of the approval phrases. status-notice: a first line that is, whole, one of
127
+ # the notice forms, and nothing after it but blank lines, table rows and HTML comments.
128
+ # review-skipped: CodeRabbit's notice that it skipped the review, by its form: blank lines,
129
+ # table rows and HTML comments, then the skip-review block holding only a quoted callout that
130
+ # opens `[!IMPORTANT]` and `## Review skipped`, then nothing but blank lines, table rows, HTML
131
+ # comments and generated blocks, each fenced by `<!-- name_start -->` and `<!-- name_end -->`
132
+ # or their `:start` and `:end` forms with the same name. A line's trailing whitespace, a
133
+ # carriage return included, is not read. Anything else is actionable, rule `unmatched`. Adds per item its class, rule and text digest, and to
134
+ # the document the actionable ids, their authors and an evidence digest of the actionable
135
+ # set's ids and text, which no timestamp, harmless item, ordering or head can move.
136
+ feedback_classify() {
137
+ local doc id body classified dir n=0 d
138
+ local -a ids=() pairs=()
139
+ doc="$(cat)"
140
+ # jq has no hash, so each item's text digest is computed here and joined back on the id. One
141
+ # jq checks the shape and prints every id and text, each ended by a NUL, and one hash process
142
+ # digests every text from a file of its own. A text is what `jq -r` printed into a command
143
+ # substitution: its NULs dropped, and its trailing newlines, which the loop below drops.
144
+ dir="$(mktemp -d)" || { echo "unreadable: cannot make a directory for the digests"; return 1; }
145
+ while IFS= read -r -d '' id && IFS= read -r -d '' body; do
146
+ while [[ "$body" == *$'\n' ]]; do body="${body%$'\n'}"; done
147
+ n=$((n + 1)); ids+=("$id"); printf '%s' "$body" > "$dir/$n"
148
+ done < <(jq -j 'if type == "object" and (.items | type) == "array" then . else error("not a document") end
149
+ | .items[] | (.id | if type == "string" then . else tojson end), "\u0000",
150
+ (.body // "" | if type == "string" then gsub("\u0000"; "") else tojson end), "\u0000"' <<< "$doc" 2>/dev/null; echo "$?" > "$dir/status")
151
+ if [[ "$(< "$dir/status")" != 0 ]]; then rm -rf "$dir"; echo "unreadable: the document on stdin is not {head, items}"; return 1; fi
152
+ n=0
153
+ if [[ "${#ids[@]}" -gt 0 ]]; then
154
+ while IFS= read -r d; do pairs+=("${ids[n]}" "$d"); n=$((n + 1)); done < <(_feedback_digests "$dir" "${#ids[@]}")
155
+ fi
156
+ rm -rf "$dir"
157
+ classified="$(jq -c --arg marker "$FEEDBACK_MARKER_RE" '
158
+ ([$ARGS.positional as $a | range(0; $a | length; 2) | {id: $a[.], digest: $a[. + 1]}]) as $digests
159
+ |
160
+ def trim: sub("^\\s+"; "") | sub("\\s+$"; "");
161
+ def first_line: (split("\n")[0] // "") | trim;
162
+ def approval_phrase: (trim | ascii_downcase)
163
+ | test("^(lgtm|looks (good|fine)( to me| by me)?|fine by me|approved?|ship it|:\\+1:|:shipit:|:white_check_mark:|👍|✅|\\+1)[ .!]*$");
164
+ def furniture: test("^\\s*$") or test("^\\s*\\|.*\\|\\s*$") or test("^\\s*<!--.*-->\\s*$");
165
+ def status_notice: (first_line | ascii_downcase) as $l
166
+ | (($l | test("^(:rocket: |🚀 )?(deploy(ment)? preview|preview deployment|preview)( for [^ ]+)? (is )?ready[.!]?(:? *<?https?://[^ <>]+>?[.!]?)?$"))
167
+ or ($l | test("^(#+ )?\\[?(codecov|coverage)\\]?(\\([^)]*\\))? report(: [0-9.]+% (of )?[a-z]+ covered\\.?)?$"))
168
+ or ($l | test("^the latest updates on your projects\\.?$"))
169
+ or ($l | test("^(this|the) (pull request|pr) (is|has been|was) (linked|associated) (to|with) (an? )?(issue |ticket )?(#[0-9]+|[a-z][a-z0-9]*-[0-9]+|https?://[^ ]+)[.!]?$")))
170
+ and (split("\n")[1:] | all(furniture));
171
+ def generated_only: reduce .[] as $l ({open: [], ok: true};
172
+ ($l | capture("^<!--\\s*(?<name>[A-Za-z0-9_-]+?)(?<edge>_start|:start|_end|:end)\\s*-->$") // null) as $fence
173
+ | if $fence != null and ($fence.edge | endswith("start")) then .open += [$fence.name]
174
+ elif $fence != null then (if (.open | last) == $fence.name then .open |= .[:-1] else .ok = false end)
175
+ elif (.open | length) > 0 or ($l | furniture) then .
176
+ else .ok = false end)
177
+ | .ok and (.open | length) == 0;
178
+ def review_skipped: (split("\n") | map(sub("\\s+$"; ""))) as $lines
179
+ | ($lines | index("<!-- This is an auto-generated comment: skip review by coderabbit.ai -->")) as $open
180
+ | ($lines | index("<!-- end of auto-generated comment: skip review by coderabbit.ai -->")) as $close
181
+ | $open != null and $close != null and $open < $close
182
+ and ($lines[:$open] | all(furniture))
183
+ and ($lines[$open + 1:$close] | map(select(. != "")) | (.[0:2] == ["> [!IMPORTANT]", "> ## Review skipped"]) and all(test("^>")))
184
+ and ($lines[$close + 1:] | generated_only);
185
+ ($digests | map({key: .id, value: .digest}) | from_entries) as $d
186
+ | (.items | map(select(.body | test($marker)) | (.body | match($marker) | {id: .captures[0].string, digest: .captures[2].string}))) as $answered
187
+ | ([.items[] | select(.kind == "inline" and .review != null) | .review] | unique) as $containers
188
+ | .items |= map(
189
+ . as $it
190
+ | ($it.body // "") as $b
191
+ | (if ($b | test($marker)) then ["harmless", "own-reply"]
192
+ elif any($answered[]; .id == $it.id and (.digest == null or .digest == ($d[$it.id] // ""))) then ["harmless", "answered"]
193
+ elif $it.kind == "inline" and $it.resolved == true then ["harmless", "resolved"]
194
+ elif $it.kind == "review" and $it.state == "DISMISSED" then ["harmless", "dismissed"]
195
+ elif $it.kind == "review" and $it.state == "APPROVED" and (($b | trim) == "" or ($b | approval_phrase)) then ["harmless", "approval"]
196
+ elif $it.kind == "review" and ($b | trim) == "" and ($containers | index($it.id)) != null then ["harmless", "empty-review"]
197
+ elif ($b | approval_phrase) then ["harmless", "approval-phrase"]
198
+ elif ($b | status_notice) then ["harmless", "status-notice"]
199
+ elif ($b | review_skipped) then ["harmless", "review-skipped"]
200
+ else ["actionable", "unmatched"] end) as $c
201
+ | . + {class: $c[0], rule: $c[1], digest: ($d[$it.id] // "")})
202
+ | . + {actionable: [.items[] | select(.class == "actionable") | .id],
203
+ authors: ([.items[] | select(.class == "actionable") | (.author // "(deleted)")] | unique),
204
+ harmless: ([.items[] | select(.class == "harmless") | .rule] | group_by(.) | map("\(length) \(.[0])") | join(", "))}' --args -- ${pairs[@]+"${pairs[@]}"} <<< "$doc")"
205
+ jq -c --arg e "$(jq -r '[.items[] | select(.class == "actionable") | "\(.id) \(.digest)"] | sort | join("\n")' <<< "$classified" | _feedback_digest)" '. + {evidence: $e}' <<< "$classified"
206
+ }
207
+
208
+ # feedback_actionable <owner/repo> <pr number>: read, then classify. `unreadable: <why>` and
209
+ # status 1 when the read fails, so a caller that needs the answer fails closed.
210
+ feedback_actionable() {
211
+ local doc
212
+ doc="$(feedback_read "$1" "$2")" || { echo "$doc"; return 1; }
213
+ feedback_classify <<< "$doc"
214
+ }
215
+
216
+ # Run as a command: one verb, its arguments, the answer on stdout.
217
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
218
+ set -uo pipefail
219
+ case "${1:-}" in
220
+ read) [[ $# -eq 3 ]] || { echo "usage: feedback.sh read <owner/repo> <pr number>" >&2; exit 64; }; feedback_read "$2" "$3" ;;
221
+ normalize) [[ $# -eq 6 ]] || { echo "usage: feedback.sh normalize <reviews> <comments> <inline> <threads> <head>" >&2; exit 64; }; feedback_normalize "$2" "$3" "$4" "$5" "$6" ;;
222
+ classify) feedback_classify ;;
223
+ actionable) [[ $# -eq 3 ]] || { echo "usage: feedback.sh actionable <owner/repo> <pr number>" >&2; exit 64; }; feedback_actionable "$2" "$3" ;;
224
+ marker) [[ $# -eq 5 ]] || { echo "usage: feedback.sh marker <finding> <decision> <digest> <issue>" >&2; exit 64; }; feedback_marker "$2" "$3" "$4" "$5" ;;
225
+ tracking-marker) [[ $# -eq 3 ]] || { echo "usage: feedback.sh tracking-marker <finding> <pr url>" >&2; exit 64; }; feedback_tracking_marker "$2" "$3" ;;
226
+ *) echo "usage: feedback.sh read|normalize|classify|actionable|marker|tracking-marker ..." >&2; exit 64 ;;
227
+ esac
228
+ fi
@@ -0,0 +1,331 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/krysoworks/kryso/skills/kryso-shift/history-manifest.schema.json",
4
+ "title": "Shipping history capture",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "schema",
9
+ "snapshot",
10
+ "repositories",
11
+ "attempts",
12
+ "sessions",
13
+ "collection",
14
+ "inventory",
15
+ "entries",
16
+ "gaps",
17
+ "excluded"
18
+ ],
19
+ "properties": {
20
+ "schema": { "const": "ship-history-manifest/1" },
21
+ "snapshot": {
22
+ "type": "object",
23
+ "additionalProperties": false,
24
+ "required": ["id", "captured_at"],
25
+ "properties": {
26
+ "id": { "$ref": "#/$defs/hash" },
27
+ "captured_at": { "type": "string", "format": "date-time" }
28
+ }
29
+ },
30
+ "repositories": {
31
+ "type": "array",
32
+ "items": { "$ref": "#/$defs/repository" }
33
+ },
34
+ "attempts": {
35
+ "type": "array",
36
+ "items": { "$ref": "#/$defs/attempt" }
37
+ },
38
+ "sessions": {
39
+ "type": "array",
40
+ "items": { "$ref": "#/$defs/session" }
41
+ },
42
+ "collection": {
43
+ "type": "object",
44
+ "additionalProperties": false,
45
+ "required": ["completeness", "errors"],
46
+ "properties": {
47
+ "completeness": { "enum": ["complete", "partial"] },
48
+ "errors": {
49
+ "type": "array",
50
+ "items": { "$ref": "#/$defs/error" }
51
+ }
52
+ }
53
+ },
54
+ "inventory": { "$ref": "#/$defs/inventory" },
55
+ "entries": {
56
+ "type": "array",
57
+ "items": { "$ref": "#/$defs/entry" }
58
+ },
59
+ "gaps": {
60
+ "type": "array",
61
+ "items": { "$ref": "#/$defs/gap" }
62
+ },
63
+ "excluded": {
64
+ "type": "array",
65
+ "items": {
66
+ "type": "object",
67
+ "additionalProperties": false,
68
+ "required": ["source", "reason"],
69
+ "properties": {
70
+ "source": { "type": "string" },
71
+ "reason": { "type": "string" }
72
+ }
73
+ }
74
+ }
75
+ },
76
+ "$defs": {
77
+ "hash": {
78
+ "type": "string",
79
+ "pattern": "^[0-9a-f]{64}$"
80
+ },
81
+ "nullableString": {
82
+ "type": ["string", "null"]
83
+ },
84
+ "repository": {
85
+ "type": "object",
86
+ "additionalProperties": false,
87
+ "required": ["id", "name", "source", "files", "bytes", "gaps", "errors"],
88
+ "properties": {
89
+ "id": { "type": "string" },
90
+ "name": { "type": "string" },
91
+ "source": { "type": "string" },
92
+ "files": { "type": "integer", "minimum": 0 },
93
+ "bytes": { "type": "integer", "minimum": 0 },
94
+ "gaps": { "type": "integer", "minimum": 0 },
95
+ "errors": { "type": "integer", "minimum": 0 }
96
+ }
97
+ },
98
+ "attempt": {
99
+ "type": "object",
100
+ "additionalProperties": false,
101
+ "required": [
102
+ "id",
103
+ "identity",
104
+ "repository",
105
+ "issue",
106
+ "outcome",
107
+ "shift",
108
+ "source",
109
+ "sources",
110
+ "copy_of",
111
+ "retries",
112
+ "session_ids",
113
+ "host",
114
+ "reported_usd",
115
+ "activity"
116
+ ],
117
+ "properties": {
118
+ "id": { "type": "string" },
119
+ "identity": { "enum": ["native", "legacy"] },
120
+ "repository": { "type": "string" },
121
+ "issue": { "$ref": "#/$defs/nullableString" },
122
+ "outcome": { "$ref": "#/$defs/nullableString" },
123
+ "shift": { "$ref": "#/$defs/nullableString" },
124
+ "source": { "type": "string" },
125
+ "sources": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
126
+ "copy_of": { "$ref": "#/$defs/nullableString" },
127
+ "retries": { "type": "integer", "minimum": 0 },
128
+ "session_ids": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
129
+ "host": { "$ref": "#/$defs/nullableString" },
130
+ "reported_usd": { "type": ["number", "null"], "minimum": 0 },
131
+ "activity": { "enum": ["active", "finished", "unknown"] }
132
+ }
133
+ },
134
+ "session": {
135
+ "type": "object",
136
+ "additionalProperties": false,
137
+ "required": ["id", "host", "status", "attempts", "sources"],
138
+ "properties": {
139
+ "id": { "type": "string" },
140
+ "host": { "$ref": "#/$defs/nullableString" },
141
+ "status": { "enum": ["associated", "ambiguous", "absent"] },
142
+ "attempts": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
143
+ "sources": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
144
+ }
145
+ },
146
+ "error": {
147
+ "type": "object",
148
+ "additionalProperties": false,
149
+ "required": ["source", "error"],
150
+ "properties": {
151
+ "source": { "type": "string" },
152
+ "error": { "type": "string" }
153
+ }
154
+ },
155
+ "entry": {
156
+ "type": "object",
157
+ "additionalProperties": false,
158
+ "required": ["path", "source", "role", "bytes", "sha256", "condition"],
159
+ "properties": {
160
+ "path": { "type": "string" },
161
+ "source": { "type": "string" },
162
+ "role": {
163
+ "enum": [
164
+ "brief",
165
+ "checkpoint",
166
+ "host-stderr",
167
+ "ledger",
168
+ "measurement-input",
169
+ "module",
170
+ "other",
171
+ "receipt",
172
+ "record",
173
+ "result",
174
+ "review",
175
+ "session-metadata",
176
+ "shift",
177
+ "transcript"
178
+ ]
179
+ },
180
+ "bytes": { "type": "integer", "minimum": 0 },
181
+ "sha256": { "$ref": "#/$defs/hash" },
182
+ "condition": { "enum": ["valid-json", "invalid-json", "empty", "present"] }
183
+ }
184
+ },
185
+ "inventory": {
186
+ "type": "object",
187
+ "additionalProperties": false,
188
+ "required": [
189
+ "repositories",
190
+ "attempts",
191
+ "coverage",
192
+ "files",
193
+ "bytes",
194
+ "conditions",
195
+ "roles",
196
+ "host_totals",
197
+ "transcripts"
198
+ ],
199
+ "properties": {
200
+ "repositories": { "type": "integer", "minimum": 0 },
201
+ "attempts": { "type": "integer", "minimum": 0 },
202
+ "coverage": {
203
+ "type": "object",
204
+ "additionalProperties": false,
205
+ "required": ["retained_worktrees", "shifts", "shipped_archives"],
206
+ "properties": {
207
+ "retained_worktrees": { "type": "integer", "minimum": 0 },
208
+ "shifts": { "type": "integer", "minimum": 0 },
209
+ "shipped_archives": { "type": "integer", "minimum": 0 }
210
+ }
211
+ },
212
+ "files": { "type": "integer", "minimum": 0 },
213
+ "bytes": { "type": "integer", "minimum": 0 },
214
+ "conditions": {
215
+ "type": "object",
216
+ "additionalProperties": false,
217
+ "properties": {
218
+ "valid-json": { "type": "integer", "minimum": 0 },
219
+ "invalid-json": { "type": "integer", "minimum": 0 },
220
+ "empty": { "type": "integer", "minimum": 0 },
221
+ "present": { "type": "integer", "minimum": 0 }
222
+ }
223
+ },
224
+ "roles": {
225
+ "type": "object",
226
+ "additionalProperties": { "type": "integer", "minimum": 0 }
227
+ },
228
+ "host_totals": {
229
+ "type": "object",
230
+ "additionalProperties": false,
231
+ "required": ["basis", "attempts", "reported_usd", "unknown"],
232
+ "properties": {
233
+ "basis": { "type": "string" },
234
+ "attempts": { "type": "integer", "minimum": 0 },
235
+ "reported_usd": { "type": "number", "minimum": 0 },
236
+ "unknown": { "type": "integer", "minimum": 0 }
237
+ }
238
+ },
239
+ "transcripts": {
240
+ "type": "object",
241
+ "additionalProperties": false,
242
+ "required": ["basis", "files", "bytes", "exclusive_usage"],
243
+ "properties": {
244
+ "basis": { "type": "string" },
245
+ "files": { "type": "integer", "minimum": 0 },
246
+ "bytes": { "type": "integer", "minimum": 0 },
247
+ "exclusive_usage": {
248
+ "type": "object",
249
+ "additionalProperties": false,
250
+ "properties": {
251
+ "input_tokens": { "type": "number", "minimum": 0 },
252
+ "output_tokens": { "type": "number", "minimum": 0 },
253
+ "cache_read_input_tokens": { "type": "number", "minimum": 0 },
254
+ "cache_creation_input_tokens": { "type": "number", "minimum": 0 }
255
+ }
256
+ }
257
+ }
258
+ }
259
+ }
260
+ },
261
+ "gap": {
262
+ "oneOf": [
263
+ {
264
+ "type": "object",
265
+ "additionalProperties": false,
266
+ "required": ["kind", "repository", "source", "condition"],
267
+ "properties": {
268
+ "kind": { "const": "malformed-attempt" },
269
+ "repository": { "type": "string" },
270
+ "source": { "type": "string" },
271
+ "condition": { "enum": ["invalid-json", "empty"] }
272
+ }
273
+ },
274
+ {
275
+ "type": "object",
276
+ "additionalProperties": false,
277
+ "required": ["kind", "repository", "issue", "source", "reason"],
278
+ "properties": {
279
+ "kind": { "const": "report-body-unavailable" },
280
+ "repository": { "type": "string" },
281
+ "issue": { "const": "94" },
282
+ "source": { "type": "string" },
283
+ "reason": { "type": "string" }
284
+ }
285
+ },
286
+ {
287
+ "type": "object",
288
+ "additionalProperties": false,
289
+ "required": ["kind", "source"],
290
+ "properties": {
291
+ "kind": { "const": "missing-input" },
292
+ "source": { "type": "string" }
293
+ }
294
+ },
295
+ {
296
+ "type": "object",
297
+ "additionalProperties": false,
298
+ "required": ["kind", "session_id", "attempts"],
299
+ "properties": {
300
+ "kind": { "const": "absent-session" },
301
+ "session_id": { "type": "string" },
302
+ "attempts": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
303
+ }
304
+ },
305
+ {
306
+ "type": "object",
307
+ "additionalProperties": false,
308
+ "required": ["kind", "session_id", "attempts", "candidates"],
309
+ "properties": {
310
+ "kind": { "const": "ambiguous-session" },
311
+ "session_id": { "type": "string" },
312
+ "attempts": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
313
+ "candidates": { "type": "array", "items": { "type": "string" }, "minItems": 2, "uniqueItems": true }
314
+ }
315
+ },
316
+ {
317
+ "type": "object",
318
+ "additionalProperties": false,
319
+ "required": ["kind", "repository", "attempt", "source", "last_seen"],
320
+ "properties": {
321
+ "kind": { "const": "vanished-attempt" },
322
+ "repository": { "type": "string" },
323
+ "attempt": { "type": "string" },
324
+ "source": { "type": "string" },
325
+ "last_seen": { "$ref": "#/$defs/hash" }
326
+ }
327
+ }
328
+ ]
329
+ }
330
+ }
331
+ }
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+ # keep-after: run a shift, then keep the archive, and exit with the shift's own status.
3
+ #
4
+ # The command runs in the foreground with this script's stdin, stdout and stderr, so what it prints and the
5
+ # status it exits with are what the caller sees. Afterwards `archive.py keep` runs once, waiting up to --wait
6
+ # seconds for a scheduled keep that is already running, and everything it prints goes to stderr. A keep that
7
+ # fails is reported on stderr and never changes the exit status: that is the command's own, or 128 plus the
8
+ # signal for a command a signal stopped. See archiving-keep.md.
9
+ set -uo pipefail
10
+
11
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+
13
+ usage() {
14
+ cat <<'EOF'
15
+ Usage: kryso archive keep-after --config <file> [--wait <s>] -- <command> ...
16
+
17
+ It runs the command, then keeps the archive, and exits with the command's
18
+ status.
19
+
20
+ --config FILE the keep configuration that archive.py keep reads
21
+ --wait N how many seconds to wait for a keep already running (default
22
+ 900)
23
+ EOF
24
+ }
25
+
26
+ CONFIG="" WAIT=900
27
+ while [[ $# -gt 0 ]]; do
28
+ case "$1" in
29
+ --config) [[ $# -ge 2 ]] || { usage >&2; exit 64; }; CONFIG="$2"; shift 2 ;;
30
+ --wait)
31
+ [[ "${2:-}" =~ ^[0-9]+$ ]] || { echo "keep-after: --wait takes a whole number of seconds, got '${2:-}'" >&2; exit 64; }
32
+ WAIT="$2"; shift 2 ;;
33
+ --) shift; break ;;
34
+ -h|--help) usage; exit 0 ;;
35
+ *) echo "keep-after: unknown argument $1" >&2; usage >&2; exit 64 ;;
36
+ esac
37
+ done
38
+ [[ -n "$CONFIG" && $# -gt 0 ]] || { usage >&2; exit 64; }
39
+
40
+ # A trap rather than an ignore: the command, which resets it, still takes the signal, and this script outlives
41
+ # the command to keep its evidence. A signal sent to this script alone waits for the command, so stop a shift
42
+ # by signalling its process group.
43
+ trap ':' INT TERM HUP
44
+ "$@"
45
+ status=$?
46
+ trap - INT TERM HUP
47
+
48
+ python3 "$HERE/archive.py" keep --config "$CONFIG" --wait "$WAIT" >&2
49
+ kept=$?
50
+ case "$kept" in
51
+ 0) ;;
52
+ 2) echo "keep-after: the keep saved a partial capture (exit 2), and the command's exit status $status stands" >&2 ;;
53
+ *) echo "keep-after: the keep failed (exit $kept), and the command's exit status $status stands" >&2 ;;
54
+ esac
55
+ exit "$status"