kunibert
All repositories: gitoria
6.0 KB
$mode = 'static'import { mkDir, tryReadFile, writeFile, exists, remove } from 'hl:fs'import { require, isList } from './review-output.hl'import { RULES_VERSION } from './review-prompt.hl'statePath = (String data, String repo, String pr) => {folder = data + '/' + encodeURIComponent(repo)mkDir(folder)return folder + '/' + encodeURIComponent(pr) + '.json'}loadState = (String path) => {text = tryReadFile(path)if (text != null) { return JSON.parse(text) }return { rules = RULES_VERSION, session = null, head = null, verdict = null, generation = 0, threads = [], settled = [], pending = [], usage = [] }}reset = (String data, String repo, String pr) => {path = statePath(data, repo, pr)let state = loadState(path)state.session = nullstate.pending = []state.generation = state.generation + 1writeFile(path, JSON.stringify(state))return { reset = true, generation = state.generation }}// The PR's session is removed (closed/merged PR): the state file goes. Answers whether there was one.drop = (String data, String repo, String pr) => {path = statePath(data, repo, pr)if (!exists(path)) { return { dropped = false } }remove(path)return { dropped = true }}// Author notes (`@kunibert <text>`) go to the state's pending list; the next prompt carries them and a finished run clears them.// A retry of the same job does not add them twice.addNotes = (String data, String repo, String pr, Hybrid notes) => {path = statePath(data, repo, pr)let state = loadState(path)for (n of notes) {let by = 'the author'if (n.by != null && hlTypeName(n.by) == 'Hybrid' && n.by.name != null) { by = '' + n.by.name }line = 'Note from ' + by + ' (@kunibert): ' + n.textif (!state.pending.includes(line)) { state.pending.push(line) }}writeFile(path, JSON.stringify(state))return state.pending.length}threadUpdates = (Hybrid state, String file) => {if (file == null) { return { =state, updates = [] } }return threadUpdatesFrom(state, JSON.parse(tryReadFile(file)))}// The same from an already parsed array. Comment ids are watermarks: in the local mode the file's own ids, with gitoria `comment.seq`.threadUpdatesFrom = (Hybrid state, Hybrid input) => {let updates = []require(isList(input), 'thread input must be an array')for (u of input) {let found = falsefor (let i = 0; i < state.threads.length; i = i + 1) {let t = state.threads[i]if (t.key != u.key) { continue }found = trueif (t.vendored) { continue }let bits = [t.key + ' ' + t.path + ':' + t.line + ' "' + t.title + '"']let changed = falseif (u.resolved != null) {require(hlTypeName(u.resolved) == 'Boolean', 'resolved must be boolean')if (u.resolved != t.resolved) {changed = trueif (u.resolved) { bits.push('was RESOLVED') } else { bits.push('was REOPENED') }t.resolved = u.resolvedif (u.resolved) { t.settled = true }}}if (u.comments != null) {require(isList(u.comments), 'comments must be an array')watermark = t.seenfor (c of u.comments) {require(hlTypeName(c.id) == 'Number' && c.id >= 0 && c.id % 1 == 0 && hlTypeName(c.author) == 'String' && hlTypeName(c.body) == 'String', 'invalid comment')if (c.id <= watermark) { continue }changed = truebits.push(c.author + ' replied: ' + JSON.stringify(c.body))if (c.id > t.seen) { t.seen = c.id }}}if (t.settled && !state.settled.includes(t.key)) { state.settled.push(t.key) }state.threads[i] = tif (changed) { updates.push('- ' + bits.join('; ')) }}require(found, 'unknown thread key: ' + u.key)}return { =state, =updates }}ledger = (Hybrid state, Boolean settledOnly = false) => {let lines = []for (t of state.threads) {if (settledOnly && !t.settled) { continue }lines.push(t.key + ' ' + t.path + ':' + t.line + ' [' + t.axis + '] ' + t.title + '; resolved=' + t.resolved + '; settled=' + t.settled)}return lines.join('')}// Earlier open threads retain their keys even when the model starts a new session.mergeOpenFindings = (Hybrid state, Hybrid result) => {findings = []let merged = 0for (f of result.findings) {let key = nullfor (t of state.threads) {if (!t.vendored && !t.resolved && !t.settled && !state.settled.includes(t.key) && t.path == f.path && t.line == f.line) { key = t.key break }}if (key == null) { findings.push(f) continue }merged = merged + 1let replied = falsefor (r of result.replies) { if (r.thread == key) { replied = true } }if (!replied) { result.replies.push({ thread = key, body = f.title + '' + f.body, resolve = false }) }}result.findings = findingsreturn { =result, =merged }}applyResult = (Hybrid state, Hybrid result) => {for (reply of result.replies) {let found = falsefor (let i = 0; i < state.threads.length; i = i + 1) {let t = state.threads[i]if (t.key != reply.thread) { continue }found = trueif (reply.resolve) {t.resolved = truet.settled = trueif (!state.settled.includes(t.key)) { state.settled.push(t.key) }}state.threads[i] = t}require(found, 'reply references unknown thread: ' + reply.thread)}for (f of result.findings) {key = 'T' + (state.threads.length + 1)state.threads.push({ =key, path = f.path, line = f.line, axis = f.axis, title = f.title, resolved = false, settled = false, seen = 0, gid = null })}return state}
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