gitoria

kunibert

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit44af321b44af321bRecords: contract v1.4mre44af321b/lib/review-memory.hl

5.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. let bits = [t.key + ' ' + t.path + ':' + t.line + ' "' + t.title + '"']
  60. let changed = false
  61. if (u.resolved != null) {
  62. require(hlTypeName(u.resolved) == 'Boolean', 'resolved must be boolean')
  63. if (u.resolved != t.resolved) {
  64. changed = true
  65. if (u.resolved) { bits.push('was RESOLVED') } else { bits.push('was REOPENED') }
  66. t.resolved = u.resolved
  67. if (u.resolved) { t.settled = true }
  68. }
  69. }
  70. if (u.comments != null) {
  71. require(isList(u.comments), 'comments must be an array')
  72. watermark = t.seen
  73. for (c of u.comments) {
  74. require(hlTypeName(c.id) == 'Number' && c.id >= 0 && c.id % 1 == 0 && hlTypeName(c.author) == 'String' && hlTypeName(c.body) == 'String', 'invalid comment')
  75. if (c.id <= watermark) { continue }
  76. changed = true
  77. bits.push(c.author + ' replied: ' + JSON.stringify(c.body))
  78. if (c.id > t.seen) { t.seen = c.id }
  79. }
  80. }
  81. if (t.settled && !state.settled.includes(t.key)) { state.settled.push(t.key) }
  82. state.threads[i] = t
  83. if (changed) { updates.push('- ' + bits.join('; ')) }
  84. }
  85. require(found, 'unknown thread key: ' + u.key)
  86. }
  87. return { =state, =updates }
  88. }
  89. ledger = (Hybrid state, Boolean settledOnly = false) => {
  90. let lines = []
  91. for (t of state.threads) {
  92. if (settledOnly && !t.settled) { continue }
  93. lines.push(t.key + ' ' + t.path + ':' + t.line + ' [' + t.axis + '] ' + t.title + '; resolved=' + t.resolved + '; settled=' + t.settled)
  94. }
  95. return lines.join('
  96. ')
  97. }
  98. applyResult = (Hybrid state, Hybrid result) => {
  99. for (reply of result.replies) {
  100. let found = false
  101. for (let i = 0; i < state.threads.length; i = i + 1) {
  102. let t = state.threads[i]
  103. if (t.key != reply.thread) { continue }
  104. found = true
  105. if (reply.resolve) {
  106. t.resolved = true
  107. t.settled = true
  108. if (!state.settled.includes(t.key)) { state.settled.push(t.key) }
  109. }
  110. state.threads[i] = t
  111. }
  112. require(found, 'reply references unknown thread: ' + reply.thread)
  113. }
  114. for (f of result.findings) {
  115. key = 'T' + (state.threads.length + 1)
  116. state.threads.push({ =key, path = f.path, line = f.line, axis = f.axis, title = f.title, resolved = false, settled = false, seen = 0, gid = null })
  117. }
  118. return state
  119. }

Branches

Latest commits

  • 44af321bRecords: contract v1.4mre
  • 310f3fd0Records: outdated semanticsmre
  • 268ebfe6Records: #11 proven live and closedmre
  • 88e8aad3Records: K11 verified and deployedmre
  • cd4cb09cNo review and status error when the model's tools did not run (kunibert#11)Kunibert
  • a6b54efaStatus updatemre
  • 5a72268eRecords: #4-#10 done, #11 started, review package on #1mre
  • 194c7da6Records: real proof greenmre
  • cdfa94a9Records: AppArmor profile for the review sandboxmre
  • c1bf02d8Status: sandbox blockermre
  • 88aaacc5Records: real proof part 2 (posting works, sandbox blocked by AppArmor userns)mre
  • 401df4e8Records: review user logged inmre
  • 6ca681b3Records: login command, status cleanupmre
  • 6b8d763cRecords: review user, device login startedKunibert
  • 07025b99Open the job worktree read-only for the review user before each model runKunibert
  • 2a44bd54Runner CLI: --review-user/--codex-bin/--work-dir work in every modeKunibert
  • 2177f66fReview model runs as its own unix user (reviewUser, codexBin, workDir)Kunibert
  • 35df8306Records: live service on byrodin, real proof part 1Kunibert
  • 7480a98dkunibert.service: SIGTERM stop is a clean exitKunibert
  • 3a8d93f9gitoria client: parse only JSON answers, accept a plain-text errorKunibert