gitoria

kunibert

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit38313f2d38313f2dverdict guard live: LOG, STATUS, K19 gatemre38313f2d/lib/review-memory.hl

7.1 KB

  1. $mode = 'static'
  2. import { mkDir, tryReadFile, writeFile, exists, remove } from 'hl:fs'
  3. import { require, isList } from './review-output.hl'
  4. import { RULES_VERSION } from './review-prompt.hl'
  5. statePath = (String data, String repo, String pr) => {
  6. folder = data + '/' + encodeURIComponent(repo)
  7. mkDir(folder)
  8. return folder + '/' + encodeURIComponent(pr) + '.json'
  9. }
  10. loadState = (String path) => {
  11. text = tryReadFile(path)
  12. if (text != null) { return JSON.parse(text) }
  13. return { rules = RULES_VERSION, session = null, head = null, verdict = null, generation = 0, threads = [], settled = [], pending = [], usage = [] }
  14. }
  15. reset = (String data, String repo, String pr) => {
  16. path = statePath(data, repo, pr)
  17. let state = loadState(path)
  18. state.session = null
  19. state.pending = []
  20. state.generation = state.generation + 1
  21. writeFile(path, JSON.stringify(state))
  22. return { reset = true, generation = state.generation }
  23. }
  24. // The PR's session is removed (closed/merged PR): the state file goes. Answers whether there was one.
  25. drop = (String data, String repo, String pr) => {
  26. path = statePath(data, repo, pr)
  27. if (!exists(path)) { return { dropped = false } }
  28. remove(path)
  29. return { dropped = true }
  30. }
  31. // Author notes (`@kunibert <text>`) go to the state's pending list; the next prompt carries them and a finished run clears them.
  32. // A retry of the same job does not add them twice.
  33. addNotes = (String data, String repo, String pr, Hybrid notes) => {
  34. path = statePath(data, repo, pr)
  35. let state = loadState(path)
  36. for (n of notes) {
  37. let by = 'the author'
  38. if (n.by != null && hlTypeName(n.by) == 'Hybrid' && n.by.name != null) { by = '' + n.by.name }
  39. line = 'Note from ' + by + ' (@kunibert): ' + n.text
  40. if (!state.pending.includes(line)) { state.pending.push(line) }
  41. }
  42. writeFile(path, JSON.stringify(state))
  43. return state.pending.length
  44. }
  45. threadUpdates = (Hybrid state, String file) => {
  46. if (file == null) { return { =state, updates = [] } }
  47. return threadUpdatesFrom(state, JSON.parse(tryReadFile(file)))
  48. }
  49. // The same from an already parsed array. Comment ids are watermarks: in the local mode the file's own ids, with gitoria `comment.seq`.
  50. threadUpdatesFrom = (Hybrid state, Hybrid input) => {
  51. let updates = []
  52. require(isList(input), 'thread input must be an array')
  53. for (u of input) {
  54. let found = false
  55. for (let i = 0; i < state.threads.length; i = i + 1) {
  56. let t = state.threads[i]
  57. if (t.key != u.key) { continue }
  58. found = true
  59. if (t.vendored) { continue }
  60. let bits = [t.key + ' ' + t.path + ':' + t.line + ' "' + t.title + '"']
  61. let changed = false
  62. if (u.resolved != null) {
  63. require(hlTypeName(u.resolved) == 'Boolean', 'resolved must be boolean')
  64. if (u.resolved != t.resolved) {
  65. changed = true
  66. if (u.resolved) { bits.push('was RESOLVED') } else { bits.push('was REOPENED') }
  67. t.resolved = u.resolved
  68. if (u.resolved) { t.settled = true }
  69. }
  70. }
  71. // severity of a thread made before severities were stored (2026-11-24): read from its first comment on gitoria
  72. if (u.severity != null && t.severity == null) {
  73. require(['blocker', 'major', 'minor', 'nit'].includes(u.severity), 'invalid thread severity')
  74. t.severity = u.severity
  75. }
  76. if (u.comments != null) {
  77. require(isList(u.comments), 'comments must be an array')
  78. watermark = t.seen
  79. for (c of u.comments) {
  80. require(hlTypeName(c.id) == 'Number' && c.id >= 0 && c.id % 1 == 0 && hlTypeName(c.author) == 'String' && hlTypeName(c.body) == 'String', 'invalid comment')
  81. if (c.id <= watermark) { continue }
  82. changed = true
  83. bits.push(c.author + ' replied: ' + JSON.stringify(c.body))
  84. if (c.id > t.seen) { t.seen = c.id }
  85. }
  86. }
  87. if (t.settled && !state.settled.includes(t.key)) { state.settled.push(t.key) }
  88. state.threads[i] = t
  89. if (changed) { updates.push('- ' + bits.join('; ')) }
  90. }
  91. require(found, 'unknown thread key: ' + u.key)
  92. }
  93. return { =state, =updates }
  94. }
  95. ledger = (Hybrid state, Boolean settledOnly = false) => {
  96. let lines = []
  97. for (t of state.threads) {
  98. if (settledOnly && !t.settled) { continue }
  99. lines.push(t.key + ' ' + t.path + ':' + t.line + ' [' + t.axis + '] ' + t.title + '; resolved=' + t.resolved + '; settled=' + t.settled)
  100. }
  101. return lines.join('
  102. ')
  103. }
  104. // Earlier open threads retain their keys even when the model starts a new session.
  105. mergeOpenFindings = (Hybrid state, Hybrid result) => {
  106. findings = []
  107. let merged = 0
  108. for (f of result.findings) {
  109. let key = null
  110. for (t of state.threads) {
  111. if (!t.vendored && !t.resolved && !t.settled && !state.settled.includes(t.key) && t.path == f.path && t.line == f.line) { key = t.key break }
  112. }
  113. if (key == null) { findings.push(f) continue }
  114. merged = merged + 1
  115. let replied = false
  116. for (r of result.replies) { if (r.thread == key) { replied = true } }
  117. if (!replied) { result.replies.push({ thread = key, body = f.title + '
  118. ' + f.body, resolve = false }) }
  119. }
  120. result.findings = findings
  121. return { =result, =merged }
  122. }
  123. applyResult = (Hybrid state, Hybrid result) => {
  124. for (reply of result.replies) {
  125. let found = false
  126. for (let i = 0; i < state.threads.length; i = i + 1) {
  127. let t = state.threads[i]
  128. if (t.key != reply.thread) { continue }
  129. found = true
  130. if (reply.resolve) {
  131. t.resolved = true
  132. t.settled = true
  133. if (!state.settled.includes(t.key)) { state.settled.push(t.key) }
  134. }
  135. state.threads[i] = t
  136. }
  137. require(found, 'reply references unknown thread: ' + reply.thread)
  138. }
  139. for (f of result.findings) {
  140. key = 'T' + (state.threads.length + 1)
  141. state.threads.push({ =key, path = f.path, line = f.line, axis = f.axis, severity = f.severity, title = f.title, resolved = false, settled = false, seen = 0, gid = null })
  142. }
  143. return state
  144. }
  145. // Verdict guard (Apollo 2026-11-24): an open Blocker, Major or unknown-severity thread of the app keeps the PR at request_changes, whatever the
  146. // model wrote. Open = not resolved on gitoria (by a person, or by the conductor citing his recorded decision) and not settled.
  147. blockingOpen = (Hybrid state) => {
  148. keys = []
  149. for (t of state.threads) {
  150. if (t.vendored || t.resolved || t.settled || state.settled.includes(t.key)) { continue }
  151. // unknown = an older finding whose severity could not be read (a failed or incomplete read): it blocks until a later run
  152. // reads it or the thread is resolved
  153. if (t.severity == null || t.severity == 'blocker' || t.severity == 'major') { keys.push(t.key) }
  154. }
  155. return keys
  156. }

Branches

Latest commits

  • 38313f2dverdict guard live: LOG, STATUS, K19 gatemre
  • 94db01c5Merge branch 'verdict-guard' into mainKunibert
  • 8d3fb2e7verdict guard: unknown severity blocks; L2mre
  • 9cb7994fverdict guard: severity of older off-diff findings from review bodies; tolerant read; L2mre
  • fa2ba67c|||PR verdict guard: an open Blocker/Major thread holds request_changesmre
  • 9e89de3cSTATUS 11-24mre
  • 841ce528LOG: gitoria PR 25 round 2mre
  • 3c6c05feLOG: gitoria PR 25 reviewmre
  • 5a5c1accLOG: hycon PR 382 round 3mre
  • 0ab030b9LOG: gitoria PR 24 approvedmre
  • 0e7be144LOG: gitoria PR 24 round 4mre
  • 58075360LOG: hycon PR 382 clarificationmre
  • b5c8d9c5LOG: gitoria PR 24 round 3mre
  • d9c9857bLOG: gitoria PR 24 re-reviewmre
  • d678c1e3LOG: gitoria PR 24 reviewmre
  • bd3591c7conductor: gates run on the live day44 binarymre
  • 47f747a7records: jukebox #9 fix livemre
  • 0a3169fdMerge branch 'vendored-size' into mainKunibert
  • e447bb09Vendored size fix: keep renames with an app side whole; type the filter parameter (L10)mre
  • 99ccc742Vendored size fix: no renames in the app diff, filter the resumed delta toomre