gitoria

kunibert

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainbd3591c7conductor: gates run on the live day44 binarymremain/lib/review-memory.hl

6.0 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. if (u.comments != null) {
  72. require(isList(u.comments), 'comments must be an array')
  73. watermark = t.seen
  74. for (c of u.comments) {
  75. require(hlTypeName(c.id) == 'Number' && c.id >= 0 && c.id % 1 == 0 && hlTypeName(c.author) == 'String' && hlTypeName(c.body) == 'String', 'invalid comment')
  76. if (c.id <= watermark) { continue }
  77. changed = true
  78. bits.push(c.author + ' replied: ' + JSON.stringify(c.body))
  79. if (c.id > t.seen) { t.seen = c.id }
  80. }
  81. }
  82. if (t.settled && !state.settled.includes(t.key)) { state.settled.push(t.key) }
  83. state.threads[i] = t
  84. if (changed) { updates.push('- ' + bits.join('; ')) }
  85. }
  86. require(found, 'unknown thread key: ' + u.key)
  87. }
  88. return { =state, =updates }
  89. }
  90. ledger = (Hybrid state, Boolean settledOnly = false) => {
  91. let lines = []
  92. for (t of state.threads) {
  93. if (settledOnly && !t.settled) { continue }
  94. lines.push(t.key + ' ' + t.path + ':' + t.line + ' [' + t.axis + '] ' + t.title + '; resolved=' + t.resolved + '; settled=' + t.settled)
  95. }
  96. return lines.join('
  97. ')
  98. }
  99. // Earlier open threads retain their keys even when the model starts a new session.
  100. mergeOpenFindings = (Hybrid state, Hybrid result) => {
  101. findings = []
  102. let merged = 0
  103. for (f of result.findings) {
  104. let key = null
  105. for (t of state.threads) {
  106. if (!t.vendored && !t.resolved && !t.settled && !state.settled.includes(t.key) && t.path == f.path && t.line == f.line) { key = t.key break }
  107. }
  108. if (key == null) { findings.push(f) continue }
  109. merged = merged + 1
  110. let replied = false
  111. for (r of result.replies) { if (r.thread == key) { replied = true } }
  112. if (!replied) { result.replies.push({ thread = key, body = f.title + '
  113. ' + f.body, resolve = false }) }
  114. }
  115. result.findings = findings
  116. return { =result, =merged }
  117. }
  118. applyResult = (Hybrid state, Hybrid result) => {
  119. for (reply of result.replies) {
  120. let found = false
  121. for (let i = 0; i < state.threads.length; i = i + 1) {
  122. let t = state.threads[i]
  123. if (t.key != reply.thread) { continue }
  124. found = true
  125. if (reply.resolve) {
  126. t.resolved = true
  127. t.settled = true
  128. if (!state.settled.includes(t.key)) { state.settled.push(t.key) }
  129. }
  130. state.threads[i] = t
  131. }
  132. require(found, 'reply references unknown thread: ' + reply.thread)
  133. }
  134. for (f of result.findings) {
  135. key = 'T' + (state.threads.length + 1)
  136. state.threads.push({ =key, path = f.path, line = f.line, axis = f.axis, title = f.title, resolved = false, settled = false, seen = 0, gid = null })
  137. }
  138. return state
  139. }

Branches

Latest commits

  • 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
  • 1a52e100|||PR Diff size limit counts only app files when vendored paths are setmre
  • 50a1867estatus: jukebox #9mre
  • c57484e6log: jukebox #9 diff sizemre
  • 795a20carecords: guard fix live (PR 8)mre
  • 6981d96fMerge branch 'fresh-on-nocmd' into mainKunibert
  • 37c47840runner: one shared prompt for both fresh-session fallbacks (L16)mre
  • f945d2e1|||PR runner: a resumed run with no command on a new head gets one fresh session instead of a tool errormre
  • 10b2a49estatus: PR 314, guard fix proposedmre
  • e73995a3log: hycon PR 314 approved after fresh reviewmre
  • f60427falog: hycon PR 314 false tool errormre
  • 481974f7log: Hermes accepts PR 259 findingmre
  • bb0976acrecords: hycon PR 259 design findingmre
  • 5c637c24records: hycon PR 259 false tool errormre
  • a344c406log: routger 132 reviewedmre
  • 56e70dcbrecords: review time limit 1800 s (routger 132)mre