kunibert
All repositories: gitoria
6.3 KB
import { appendFile, exists, writeFile, mkDir, tryReadFile } from 'hl:fs'import { timestamp } from 'hl:time'import { run, spawnArgs, dir } from 'hl:proc'import { after } from 'hl:time'\\ THE ONE FUNCTION the queue calls: runJob(job, done). It starts the review CLI (tools/runner.hl review-pr ...) as a CHILD with\\ spawnArgs and returns at once; `done(result)` is called later, from the child's exit event (or the timeout), with\\ { ok, error, out }. Nothing here blocks the web routes while the model runs.\\ Legacy test mode (no repos configured, K5 phases): the job is only recorded in <dataDir>/runjobs.jsonl; hooks\\ <dataDir>/fail-<key, # as _> (fails) and <dataDir>/slow-<key> (3 s, blocking) as before.String dataDir = ''Hybrid repos = null \\ repo.id -> { api, clone, keyFile }; null = legacy test modeString hybriel = 'hybriel' \\ the runtime binaryNumber timeoutSeconds = 900 \\ hard limit per job: past it the child is killed, the job failedString runnerData = '' \\ the CLI's own state dir (sessions, git cache)String ticketsBase = '' \\ tickets service base URL; '' = linked tickets are not readString reviewUser = '' \\ unix user the model runs as ('' = the service's own user)String codexBin = 'codex' \\ the codex binary (an absolute path when reviewUser is set)String workDir = '' \\ job worktrees ('' = the CLI default under runnerData)String ticketsTokenFile = '' \\ read token file of Kunibert for it (mode 600); only the PATH goes into the argv\\ the argv of the review child; the key file path is the only secret-related thing in itargvFor = (Hybrid job, Hybrid cfg) => {tool = dir() + '/../tools/runner.hl'let a = [hybriel, tool, 'review-pr', runnerData, '--api', cfg.api, '--key-file', cfg.keyFile, '--clone', cfg.clone]if (ticketsBase != '' && ticketsTokenFile != '') { a.push('--tickets-base') a.push(ticketsBase) a.push('--tickets-token-file') a.push(ticketsTokenFile) }if (reviewUser != '') { a.push('--review-user') a.push(reviewUser) }a.push('--codex-bin')a.push(codexBin)if (workDir != '') { a.push('--work-dir') a.push(workDir) }a.push('--timeout')a.push('' + timeoutSeconds)if (cfg.vendored != null && cfg.vendored.length > 0) { a.push('--vendored') a.push(cfg.vendored.join(',')) }if (cfg.vendoredLink != null) { a.push('--vendored-link') a.push(cfg.vendoredLink) }if (job.force || job.reset || job.notes.length > 0) { a.push('--force') }if (job.reset) { a.push('--reset') }if (job.notes.length > 0) {mkDir(dataDir + '/notes')nf = dataDir + '/notes/' + encodeURIComponent(job.key) + '.json'writeFile(nf, JSON.stringify(job.notes))a.push('--note-file')a.push(nf)}a.push('' + job.number)return a}cut = (String t) => {if (t.length <= 300) { return t }return t.slice(0, 300) + '…'}\\ run a child to its end or its timeout; cb({ exit, killed, out, err })runChild = (Hybrid argv, Number seconds, cb) => {let outLines = []let errLines = []let killed = falsechild = spawnArgs(argv)timer = after(seconds)on child.line(e) { if (e.stream == 'stdout') { outLines.push(e.line) } else { errLines.push(e.line) } }on child.exit(e) {timer.stop()cb({ exit = e.exit, =killed, out = outLines, err = errLines })}on timer.tick() {killed = truechild.kill()}return child.pid}\\ the JSON the CLI printed last (stdout), or nulllastJson = (Hybrid lines) => {for (let i = lines.length - 1; i >= 0; i = i - 1) {if (lines[i].trim() != '') {if (!lines[i].trim().startsWith('{')) { return null }return JSON.parse(lines[i])}}return null}runJob = (Hybrid job, done) => {if (repos == null) { return legacy(job, done) }cfg = repos['' + job.repo.id]if (cfg == null) { return done({ ok = false, error = 'no config for repo ' + job.repo.id }) }argv = argvFor(job, cfg)console.log(timestamp() + ' runjob: ' + job.key + ' start timeout=' + timeoutSeconds + 's force=' + job.force + ' reset=' + job.reset + ' notes=' + job.notes.length)runChild(argv, timeoutSeconds, (r) => {if (r.killed) {\\ the killed CLI cannot tell gitoria: do it now (short child), then report the failuremsg = 'Review timed out after ' + timeoutSeconds + 's'runChild([hybriel, dir() + '/../tools/runner.hl', 'status-error', '--api', cfg.api, '--key-file', cfg.keyFile, '--head', job.head, '--message', msg], 60, (s) => {console.log(timestamp() + ' runjob: ' + job.key + ' KILLED at timeout, error status exit=' + s.exit)done({ ok = false, error = msg })})return null}j = lastJson(r.out)if (r.exit == 0 && (j == null || j.error == null)) {done({ ok = true, out = j })return null}let err = 'review child exit ' + r.exitif (j != null && j.error != null) { err = '' + j.error }else if (r.err.length > 0) { err = err + ': ' + r.err[r.err.length - 1] }done({ ok = false, error = cut(err) })return null})return null}\\ closed/merged PR: remove its session (state) via the CLI; done({ ok })dropSession = (Hybrid mark, String number, done) => {let cfg = nullif (repos != null) { cfg = repos['' + mark.repo.id] }if (cfg == null) { return done({ ok = false, error = 'no config for repo ' + mark.repo.id }) }runChild([hybriel, dir() + '/../tools/runner.hl', 'drop', runnerData, cfg.clone, number], 60, (r) => {done({ ok = r.exit == 0 && !r.killed, error = r.err.join(' ') })return null})return null}legacy = (Hybrid job, done) => {appendFile(dataDir + '/runjobs.jsonl', JSON.stringify({ at = timestamp(), key = job.key, head = job.head, force = job.force, reset = job.reset, threadReplyOnly = job.threadReplyOnly, threads = job.threads.length, notes = job.notes, events = job.events, tries = job.tries }) + '')slowFile = dataDir + '/slow-' + job.key.replace('#', '_')if (exists(slowFile)) { run('sleep 3') }failFile = dataDir + '/fail-' + job.key.replace('#', '_')if (exists(failFile)) { return done({ ok = false, error = 'test failure hook' }) }return done({ ok = true })}
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