loki-mode 11.128.2 → 11.129.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/SKILL.md +3 -3
- package/VERSION +1 -1
- package/autonomy/lib/help-core.sh +30 -42
- package/autonomy/lib/workspace.py +292 -19
- package/autonomy/lib/workspace_comment.py +40 -11
- package/autonomy/loki +97 -159
- package/autonomy/route.sh +3 -2
- package/autonomy/trigger-server.py +373 -32
- package/bin/loki +77 -14
- package/completions/_loki +11 -142
- package/completions/loki.bash +4 -2
- package/dashboard/__init__.py +1 -1
- package/docs/CLI-CORE-VERBS.md +61 -37
- package/docs/CLI-INVENTORY.md +152 -153
- package/docs/CLI-REFERENCE.md +20 -166
- package/docs/DEPLOYMENT.md +38 -3
- package/docs/INSTALLATION.md +7 -1
- package/docs/KNOWN-ISSUES.md +1 -1
- package/docs/PROOF-PASSPORT.md +21 -0
- package/docs/WORKSPACES.md +27 -0
- package/docs/cost-controls.md +74 -12
- package/docs/dev/architecture-reference.md +2 -2
- package/docs/environment-variables.md +7 -0
- package/docs/merge-queue.md +44 -3
- package/docs/sentry-intake.md +1 -1
- package/docs/slack.md +1 -1
- package/docs/v10/GUIDE.md +22 -4
- package/loki-ts/dist/loki.js +1510 -1465
- package/mcp/__init__.py +1 -1
- package/memory/knowledge_graph.py +442 -56
- package/package.json +2 -2
- package/packages/control-plane/dist/server.js +1901 -1585
- package/plugins/loki-mode/.claude-plugin/plugin.json +1 -1
- package/schemas/loki-yaml.schema.json +1 -0
- package/web-app/dist/assets/{AdminPage-B-9a_urH.js → AdminPage-uxbsIyND.js} +1 -1
- package/web-app/dist/assets/{Avatar-DWFQPBje.js → Avatar-5GhUf4pP.js} +1 -1
- package/web-app/dist/assets/{Badge-CuLYjGKc.js → Badge-93rdLyl8.js} +1 -1
- package/web-app/dist/assets/{Button-Cws5TOeA.js → Button-C94f2_e6.js} +1 -1
- package/web-app/dist/assets/{CockpitPage-CCT1U0rq.js → CockpitPage-C8cDx1mp.js} +1 -1
- package/web-app/dist/assets/{ComparePage-ChcsGaeo.js → ComparePage-BU7VVcVf.js} +1 -1
- package/web-app/dist/assets/{ErrorBoundary-C5Mz6Y_d.js → ErrorBoundary-Bn81ZPkG.js} +1 -1
- package/web-app/dist/assets/{EvidenceReceiptPanel-jXRFyeG-.js → EvidenceReceiptPanel-CVqzhxXI.js} +1 -1
- package/web-app/dist/assets/{GitHubIssuesPanel-C_YjFJSB.js → GitHubIssuesPanel-i1Yjc0mH.js} +1 -1
- package/web-app/dist/assets/{GitHubPRsPanel-B3bRY_lb.js → GitHubPRsPanel-eoXw0hiw.js} +1 -1
- package/web-app/dist/assets/{HomePage-JLwBDYu8.js → HomePage-Cv_BXFF9.js} +2 -2
- package/web-app/dist/assets/{LoginPage-BcDvWJr1.js → LoginPage-CWYdAQSQ.js} +1 -1
- package/web-app/dist/assets/{MagicPage-Bj3qzygY.js → MagicPage-5r2ci7MS.js} +1 -1
- package/web-app/dist/assets/{MetricsPage-9k0NVtge.js → MetricsPage-C37jE1uR.js} +1 -1
- package/web-app/dist/assets/{NotFoundPage-D81Z_SCM.js → NotFoundPage-CuBrziZd.js} +1 -1
- package/web-app/dist/assets/{ProjectPage-D9CkJI0B.js → ProjectPage-59GLzJlR.js} +3 -3
- package/web-app/dist/assets/{ProjectsPage-vxSmYYzh.js → ProjectsPage-DgDtFRNm.js} +1 -1
- package/web-app/dist/assets/{SettingsPage-Cd2AS1Sg.js → SettingsPage-DjMSy-kZ.js} +1 -1
- package/web-app/dist/assets/{ShowcasePage-DOZCRLg5.js → ShowcasePage-DESkYmrG.js} +1 -1
- package/web-app/dist/assets/{SystemSettingsPage-wl2UO5DF.js → SystemSettingsPage-d5jFreyF.js} +1 -1
- package/web-app/dist/assets/{TeamsPage-CA9FPLPm.js → TeamsPage-BEVAkxj3.js} +1 -1
- package/web-app/dist/assets/{TemplatesPage-DLRTBM8i.js → TemplatesPage-DeK9wx22.js} +1 -1
- package/web-app/dist/assets/{TerminalOutput-RqmPEs4o.js → TerminalOutput-2vwck437.js} +1 -1
- package/web-app/dist/assets/{activity-CoyjHBZ4.js → activity-XgL1xWCM.js} +1 -1
- package/web-app/dist/assets/{bell-Dn2BCsQu.js → bell-EXDsjrzh.js} +1 -1
- package/web-app/dist/assets/{bot-CNqPuD8h.js → bot-B9I58zKH.js} +1 -1
- package/web-app/dist/assets/{check-BWAwFpe2.js → check-DgLUYM2x.js} +1 -1
- package/web-app/dist/assets/{chevron-left-BgTjvxLB.js → chevron-left-BhHLpt7K.js} +1 -1
- package/web-app/dist/assets/{circle-alert-CIYxFeDp.js → circle-alert-rgioMmC9.js} +1 -1
- package/web-app/dist/assets/{clock-Dj6DRvL7.js → clock-BO__fq1n.js} +1 -1
- package/web-app/dist/assets/{cloud-DZBvW6-f.js → cloud-iLJ3RtJs.js} +1 -1
- package/web-app/dist/assets/{code-xml-B0sAmzAO.js → code-xml-BFYU6YlU.js} +1 -1
- package/web-app/dist/assets/{database-BkO44OAR.js → database-CXDLeUh_.js} +1 -1
- package/web-app/dist/assets/{dollar-sign-ChTZgVxB.js → dollar-sign-C9Jbgo-O.js} +1 -1
- package/web-app/dist/assets/{file-code-corner-CQSIiG1T.js → file-code-corner-CNPi6dkK.js} +1 -1
- package/web-app/dist/assets/{file-plus-BAV2KC_M.js → file-plus-DAc0Sd1J.js} +1 -1
- package/web-app/dist/assets/{globe-TUNeqVA9.js → globe-DN0njo3S.js} +1 -1
- package/web-app/dist/assets/{hammer-CMD4wrup.js → hammer-CnpZO-SH.js} +1 -1
- package/web-app/dist/assets/{index-B5lRV-ZJ.js → index-BHwx0KjF.js} +3 -3
- package/web-app/dist/assets/{layers-BxXkAn6j.js → layers-_kP2XVgZ.js} +1 -1
- package/web-app/dist/assets/{loader-circle-CE46Yvcr.js → loader-circle-CcupfVc5.js} +1 -1
- package/web-app/dist/assets/{lock-3uBPp5eV.js → lock-D3I89F_A.js} +1 -1
- package/web-app/dist/assets/{package-DjPZ3DLs.js → package-BMz7_qR6.js} +1 -1
- package/web-app/dist/assets/{plus-D8v6ZCYM.js → plus-3rKyjjc7.js} +1 -1
- package/web-app/dist/assets/{refresh-cw-BSPJHBul.js → refresh-cw-DGI9P9uf.js} +1 -1
- package/web-app/dist/assets/{rotate-ccw-D0u6PH4j.js → rotate-ccw-CEIZqe5z.js} +1 -1
- package/web-app/dist/assets/{scroll-text-Dcwu9apa.js → scroll-text-CBQ5ISFk.js} +1 -1
- package/web-app/dist/assets/{server-pd5YWyJw.js → server-DOr9ns7A.js} +1 -1
- package/web-app/dist/assets/{shield-alert-C3TqM2Xm.js → shield-alert-pcQbbyMb.js} +1 -1
- package/web-app/dist/assets/{thumbs-up-U1Wkm_Rg.js → thumbs-up-Q7fwPWa9.js} +1 -1
- package/web-app/dist/assets/{trash-2-BspH7NSu.js → trash-2-D81689SS.js} +1 -1
- package/web-app/dist/assets/{trending-down-DNg_ybr3.js → trending-down-8b0O5hb9.js} +1 -1
- package/web-app/dist/assets/{trending-up-CYzIu-lq.js → trending-up-CD0tv_w5.js} +1 -1
- package/web-app/dist/assets/{upload-ChhyDeon.js → upload-CphI5Pe_.js} +1 -1
- package/web-app/dist/assets/{usePolling-ClMveR0q.js → usePolling-yhGOhxnY.js} +1 -1
- package/web-app/dist/assets/{user-BlFXAv0-.js → user-CXM61B6o.js} +1 -1
- package/web-app/dist/index.html +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ loki setup # first-run wizard (or: loki doctor
|
|
|
46
46
|
loki start "add rate limiting to /api/login" # the primary path: build, verify, seal a receipt, open a PR
|
|
47
47
|
loki start prd.md # same, from a PRD file
|
|
48
48
|
loki start owner/repo#123 # same, from a GitHub, GitLab or Jira issue
|
|
49
|
+
loki "fix #123" # an issue of this checkout; a copied issue or PR URL works as is
|
|
49
50
|
loki edit "rename fooBar to foo_bar" # one small change, no loop
|
|
50
51
|
loki chat # interactive alternative: Plan and Build modes
|
|
51
52
|
```
|
package/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: loki-mode
|
|
|
3
3
|
description: Runs an autonomous software factory that knows what it is supposed to deliver and proves it did, with a signed receipt. Use when the user says Loki Mode or asks to build, fix or verify software autonomously.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Loki Mode v11.
|
|
6
|
+
# Loki Mode v11.129.0
|
|
7
7
|
|
|
8
8
|
**Current entry points (Loki 10 engine):** `loki "<task>"`, `loki owner/repo#N` and `loki quick "<task>"` run the Loki 10 engine and end with a signed receipt (`loki verify`). `loki backlog owner/repo --all` runs many issues in parallel. Guide: `docs/v10/GUIDE.md`. The skill instructions below, and `loki start`, describe the previous bash loop. PRD-file starts (`loki start ./prd.md`) and the opencode provider still run on it until FC38-SWEEP ports them; the legacy-engine command and the LOKI_ENGINE switch remain removed. Prefer `loki owner/repo#N` for issues.
|
|
9
9
|
|
|
@@ -225,7 +225,7 @@ Pick modules from this table, one hop from here. Each module over 100 lines open
|
|
|
225
225
|
<!-- generated:commands -->
|
|
226
226
|
Commands (generated from `loki-ts/src/cli/registry.ts`; full reference in `docs/CLI-REFERENCE.md`):
|
|
227
227
|
|
|
228
|
-
`
|
|
228
|
+
`start`, `chat`, `status`, `verify`, `receipt`, `stop`, `undo`, `deploy`, `doctor`, `config`, `control`
|
|
229
229
|
<!-- /generated -->
|
|
230
230
|
|
|
231
231
|
---
|
|
@@ -461,4 +461,4 @@ Implemented, planned and deprecated items, with the version each landed in: `CHA
|
|
|
461
461
|
|
|
462
462
|
---
|
|
463
463
|
|
|
464
|
-
**v11.
|
|
464
|
+
**v11.129.0 | [Autonomi](https://www.autonomi.dev/) flagship product | core skill**
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
11.
|
|
1
|
+
11.129.0
|
|
@@ -1,57 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Core help screen and help topics for `loki help`. Source this file; it
|
|
3
|
-
# defines functions only. The
|
|
4
|
-
# (
|
|
3
|
+
# defines functions only. The front page lists exactly the 11 KEEP commands of
|
|
4
|
+
# loki-ts/src/cli/registry.ts (tests/min/cli-entrypoints.sh compares them). The
|
|
5
|
+
# hidden and renamed commands stay in show_help_all (autonomy/loki), reached
|
|
6
|
+
# with `loki help all`.
|
|
5
7
|
|
|
6
8
|
# Topics reachable as `loki help <topic>`. Keep in sync with help_topic_text.
|
|
7
9
|
LOKI_HELP_TOPICS="providers exit-codes"
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
echo "
|
|
12
|
-
echo ""
|
|
13
|
-
echo "
|
|
14
|
-
echo ""
|
|
15
|
-
echo "Start:"
|
|
16
|
-
echo " start [SPEC] PRIMARY: build from a PRD file, brief, or issue (owner/repo#N, PROJ-1) (alias: run)"
|
|
17
|
-
echo " chat [--attach] Interactive alternative; --attach joins the current 'loki start' run"
|
|
18
|
-
echo " edit \"<change>\" Make one targeted change to the current repo"
|
|
19
|
-
echo " quick \"<task>\" One small task, no PR"
|
|
11
|
+
# The 11 core commands, grouped. Shared by the front page and `loki help all`.
|
|
12
|
+
help_core_commands() {
|
|
13
|
+
echo "Build:"
|
|
14
|
+
echo " loki \"<goal>\" Build it: a goal, a PRD file, or an issue (owner/repo#N)"
|
|
15
|
+
echo " start [input] [options] Same, with options (--no-pr, --max-cost USD, --model, --provider, --dry-run, --deploy)"
|
|
16
|
+
echo " chat [--attach] Talk it through instead; --attach joins the running build"
|
|
20
17
|
echo ""
|
|
21
18
|
echo "Check:"
|
|
22
|
-
echo " status [--json
|
|
23
|
-
echo " verify [--
|
|
24
|
-
echo " receipt
|
|
25
|
-
echo " diff / undo See what a run changed; undo <run> to plan or apply a rollback"
|
|
26
|
-
echo ""
|
|
27
|
-
echo "Configure:"
|
|
28
|
-
echo " setup First-run setup (provider, keys, defaults)"
|
|
29
|
-
echo " config Show or change settings (config list --json)"
|
|
30
|
-
echo " models Model tiers and routes (models --local for local models)"
|
|
31
|
-
echo " agents Agent roles and routing (route shows where a task would go)"
|
|
32
|
-
echo " doctor [--json] Check your setup is ready"
|
|
19
|
+
echo " status [--json] What is running, how it ended, what to do next"
|
|
20
|
+
echo " verify [base] [--fast] Deterministic verification with CI exit codes (--json)"
|
|
21
|
+
echo " receipt [run] The signed proof of a run (share, badge, bundle)"
|
|
33
22
|
echo ""
|
|
34
|
-
echo "
|
|
35
|
-
echo "
|
|
36
|
-
echo "
|
|
23
|
+
echo "Control:"
|
|
24
|
+
echo " stop Stop the running build"
|
|
25
|
+
echo " undo <run> Plan (--plan) or apply an undo of a run"
|
|
26
|
+
echo " deploy Deploy a VERIFIED run"
|
|
37
27
|
echo ""
|
|
38
|
-
echo "
|
|
39
|
-
echo "
|
|
40
|
-
echo "
|
|
41
|
-
echo "
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
echo "
|
|
47
|
-
echo " loki doctor --fix Check setup and repair what it can"
|
|
28
|
+
echo "Setup:"
|
|
29
|
+
echo " doctor [--fix] Check and repair your setup (first run: loki doctor --fix)"
|
|
30
|
+
echo " config list|get|set Show or change settings (config list --json)"
|
|
31
|
+
echo " control serve The local UI"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
help_core_screen() {
|
|
35
|
+
local version="$1"
|
|
36
|
+
echo "Loki Mode v${version}"
|
|
48
37
|
echo ""
|
|
49
|
-
|
|
50
|
-
echo " loki help all Every command"
|
|
51
|
-
echo " loki help <topic> Topics: ${LOKI_HELP_TOPICS// /, }"
|
|
52
|
-
echo " loki <command> --help Help for one command"
|
|
38
|
+
help_core_commands
|
|
53
39
|
echo ""
|
|
54
|
-
echo "
|
|
40
|
+
echo "Default spend cap per run: $(loki_budget_default_usd 2>/dev/null) USD (--max-cost USD). Exit codes: docs/exit-codes.md"
|
|
41
|
+
echo "loki <command> --help | loki help all | loki help <topic> (${LOKI_HELP_TOPICS// /, })"
|
|
42
|
+
echo "docs: https://www.autonomi.dev/docs"
|
|
55
43
|
}
|
|
56
44
|
|
|
57
45
|
help_topic_text() {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
loki workspace run <name> <issue-ref>
|
|
7
7
|
loki workspace status [<run-id>]
|
|
8
8
|
loki workspace infer <name>
|
|
9
|
+
loki workspace affected <name> [--json] <goal>
|
|
9
10
|
|
|
10
11
|
On by default (LOKI_WORKSPACES=0 disables). Workspaces are defined in loki.yaml:
|
|
11
12
|
|
|
@@ -43,6 +44,11 @@ With `integration: {per_stage: true}` the integration command also runs after
|
|
|
43
44
|
each topological layer; a failing stage SKIPs every later layer, so a broken
|
|
44
45
|
contract stops before downstream repos build on it.
|
|
45
46
|
|
|
47
|
+
`affected` prints which repos a goal touches (lexical search of each local checkout, file:line evidence) and
|
|
48
|
+
the run order; no model call, no files. `affected: true` in the workspace (or LOKI_WORKSPACE_AFFECTED=1)
|
|
49
|
+
makes `run` run only those repos in declared plus inferred `after` order and records the selection in integration.json.
|
|
50
|
+
Unselected repos stay read-only via LOKI_WS_DIR_*. Off by default.
|
|
51
|
+
|
|
46
52
|
Test seam: LOKI_WORKSPACE_LAUNCHER replaces the engine launcher (called with
|
|
47
53
|
the issue ref or task text, cwd = the repo worktree).
|
|
48
54
|
"""
|
|
@@ -218,8 +224,11 @@ def task_for(entry, ref, siblings, plan=None):
|
|
|
218
224
|
return text, {"LOKI_E10_TASK_TEXT": text}
|
|
219
225
|
|
|
220
226
|
|
|
221
|
-
def run_integration(ws, run_dir, worktrees, heads):
|
|
222
|
-
"""Run the integration command once; return the evidence dict.
|
|
227
|
+
def run_integration(ws, run_dir, worktrees, heads, extra_dirs=None):
|
|
228
|
+
"""Run the integration command once; return the evidence dict.
|
|
229
|
+
|
|
230
|
+
extra_dirs: {repo: unchanged checkout} exported read-only as LOKI_WS_DIR_* for repos that did not run.
|
|
231
|
+
"""
|
|
223
232
|
integ = ws.get("integration") or {}
|
|
224
233
|
cmd = integ.get("command")
|
|
225
234
|
ev = {"heads": heads, "exit_code": None, "log_sha256": None, "status": "not_configured"}
|
|
@@ -227,7 +236,7 @@ def run_integration(ws, run_dir, worktrees, heads):
|
|
|
227
236
|
return ev
|
|
228
237
|
timeout = integ.get("timeout_s", 900)
|
|
229
238
|
env = dict(os.environ)
|
|
230
|
-
for repo, wt in worktrees.items():
|
|
239
|
+
for repo, wt in list((extra_dirs or {}).items()) + list(worktrees.items()):
|
|
231
240
|
env["LOKI_WS_DIR_" + re.sub(r"[^A-Za-z0-9]", "_", repo).upper()] = wt
|
|
232
241
|
log_path = os.path.join(run_dir, "integration.log")
|
|
233
242
|
with open(log_path, "wb") as lf:
|
|
@@ -259,8 +268,12 @@ def _heads(worktrees):
|
|
|
259
268
|
return out
|
|
260
269
|
|
|
261
270
|
|
|
262
|
-
def run_workspace(name, ref, workspaces, base_dir=None, launcher=None):
|
|
263
|
-
"""Run the workspace; return (exit_code, evidence_path_or_None).
|
|
271
|
+
def run_workspace(name, ref, workspaces, base_dir=None, launcher=None, affected=None):
|
|
272
|
+
"""Run the workspace; return (exit_code, evidence_path_or_None).
|
|
273
|
+
|
|
274
|
+
affected: True prunes to the repos the goal touches and adds inferred `after` edges; None reads the
|
|
275
|
+
workspace `affected` key and LOKI_WORKSPACE_AFFECTED=1. Off by default.
|
|
276
|
+
"""
|
|
264
277
|
ws = workspaces.get(name)
|
|
265
278
|
if ws is None:
|
|
266
279
|
say("workspace: unknown workspace %r (known: %s)" % (name, ", ".join(sorted(workspaces)) or "none"))
|
|
@@ -281,6 +294,25 @@ def run_workspace(name, ref, workspaces, base_dir=None, launcher=None):
|
|
|
281
294
|
launcher = launcher or os.environ.get("LOKI_WORKSPACE_LAUNCHER") or os.path.join(REPO_ROOT, "bin", "loki")
|
|
282
295
|
child_env_base = dict(os.environ, LOKI_NO_BROWSER="1")
|
|
283
296
|
|
|
297
|
+
on = affected if affected is not None else (ws.get("affected") is True or
|
|
298
|
+
os.environ.get("LOKI_WORKSPACE_AFFECTED") == "1")
|
|
299
|
+
selection, extra_dirs = None, {}
|
|
300
|
+
if on:
|
|
301
|
+
selection = select_affected(ws, ref)
|
|
302
|
+
repos, note = compose(ws, selection)
|
|
303
|
+
ordered = order_repos({"repos": repos})
|
|
304
|
+
for r in selection["selected"]:
|
|
305
|
+
say("workspace: %s selected (%s)" % (r, selection["evidence"].get(r, "")))
|
|
306
|
+
for r, why in selection["not_selected"].items():
|
|
307
|
+
say("workspace: %s not selected (%s)" % (r, why))
|
|
308
|
+
if selection["fallback"]:
|
|
309
|
+
say("workspace: " + selection["fallback"])
|
|
310
|
+
if note:
|
|
311
|
+
say("workspace: " + note)
|
|
312
|
+
selection["note"] = note
|
|
313
|
+
roots = _local_roots(ws.get("repos") or [])
|
|
314
|
+
extra_dirs = {r: roots[r] for r in selection["not_selected"] if roots.get(r)}
|
|
315
|
+
|
|
284
316
|
outcome, worktrees, heads, kind = {}, {}, {}, {}
|
|
285
317
|
timing = {} # repo -> {started_at, finished_at} epoch seconds
|
|
286
318
|
running = {} # repo -> (Popen, log file handle)
|
|
@@ -341,7 +373,7 @@ def run_workspace(name, ref, workspaces, base_dir=None, launcher=None):
|
|
|
341
373
|
if any(kind[r] != "ok" for r in members):
|
|
342
374
|
gate[lv] = "failed"
|
|
343
375
|
else:
|
|
344
|
-
sev = run_integration(ws, run_dir, worktrees, _heads(worktrees))
|
|
376
|
+
sev = run_integration(ws, run_dir, worktrees, _heads(worktrees), extra_dirs)
|
|
345
377
|
sev["layer"] = lv
|
|
346
378
|
stages.append(sev)
|
|
347
379
|
gate[lv] = "failed" if sev["status"] == "failed" else "passed"
|
|
@@ -415,9 +447,11 @@ def run_workspace(name, ref, workspaces, base_dir=None, launcher=None):
|
|
|
415
447
|
if per_stage and stages:
|
|
416
448
|
ev = dict(stages[-1], heads=heads, stages=[{k: v for k, v in s_.items() if k != "heads"} for s_ in stages])
|
|
417
449
|
else:
|
|
418
|
-
ev = run_integration(ws, run_dir, worktrees, heads)
|
|
450
|
+
ev = run_integration(ws, run_dir, worktrees, heads, extra_dirs)
|
|
419
451
|
ev["outcomes"] = outcome
|
|
420
452
|
ev["timing"] = {r: t for r, t in timing.items() if "finished_at" in t}
|
|
453
|
+
if selection is not None:
|
|
454
|
+
ev["selection"] = selection
|
|
421
455
|
ev_path = os.path.join(run_dir, "integration.json")
|
|
422
456
|
tmp = ev_path + ".tmp"
|
|
423
457
|
with open(tmp, "w") as f:
|
|
@@ -426,17 +460,24 @@ def run_workspace(name, ref, workspaces, base_dir=None, launcher=None):
|
|
|
426
460
|
|
|
427
461
|
seal_composite(ordered, outcome, ev, run_dir)
|
|
428
462
|
|
|
463
|
+
links = {}
|
|
429
464
|
try:
|
|
430
465
|
import workspace_comment
|
|
431
|
-
workspace_comment.
|
|
466
|
+
links = workspace_comment.find_prs(worktrees)
|
|
467
|
+
workspace_comment.post_comments(name, run_id, run_dir, worktrees, ev, say, links)
|
|
432
468
|
except Exception as e: # commenting must never fail the run
|
|
433
469
|
say("workspace: commenting skipped (%s)" % type(e).__name__)
|
|
434
470
|
|
|
435
471
|
say("")
|
|
436
472
|
say("Summary: workspace %s (%s)" % (name, run_id))
|
|
437
473
|
for repo, res in outcome.items():
|
|
438
|
-
|
|
474
|
+
pr = links.get(repo)
|
|
475
|
+
say("%-30s %s" % (repo, res + (" %s%s" % (pr["url"], " (draft)" if pr.get("draft") else "") if pr else "")))
|
|
439
476
|
say("%-30s %s" % ("integration", ev["status"]))
|
|
477
|
+
if worktrees:
|
|
478
|
+
draft = sum(1 for v in links.values() if v.get("draft"))
|
|
479
|
+
say("linked PRs: %d of %d repos have an open PR (%d ready, %d draft)" % (
|
|
480
|
+
len(links), len(worktrees), len(links) - draft, draft))
|
|
440
481
|
if ev["status"] == "failed" or any(k == "fail" for k in kind.values()):
|
|
441
482
|
return 1, ev_path
|
|
442
483
|
return (3 if any(k == "budget" for k in kind.values()) else 0), ev_path
|
|
@@ -663,24 +704,23 @@ def _openapi_evidence(root, roots):
|
|
|
663
704
|
return found
|
|
664
705
|
|
|
665
706
|
|
|
666
|
-
def
|
|
667
|
-
"""
|
|
668
|
-
ws = workspaces.get(name)
|
|
669
|
-
if ws is None:
|
|
670
|
-
say("workspace: unknown workspace %r (known: %s)" % (name, ", ".join(sorted(workspaces)) or "none"))
|
|
671
|
-
return 2
|
|
672
|
-
entries = [e for e in ws.get("repos") or [] if isinstance(e.get("repo"), str)]
|
|
707
|
+
def _local_roots(entries):
|
|
708
|
+
"""{repo: absolute local checkout or None} (the entry's path, else ~/.loki/repos/<slug>)."""
|
|
673
709
|
roots = {}
|
|
674
710
|
for e in entries:
|
|
675
711
|
root = os.path.abspath(os.path.expanduser(e["path"])) if e.get("path") else os.path.join(
|
|
676
712
|
os.path.expanduser("~"), ".loki", "repos", _slug(e["repo"]))
|
|
677
713
|
roots[e["repo"]] = root if os.path.isdir(root) else None
|
|
714
|
+
return roots
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
def infer_edges(entries, roots):
|
|
718
|
+
"""-> (proposed {repo: [deps]}, evidence {(repo, dep): str}) from manifests, imports and generator configs."""
|
|
678
719
|
ids = {e["repo"]: _identities(e, roots[e["repo"]]) if roots[e["repo"]] else set() for e in entries}
|
|
679
720
|
proposed, evidence = {}, {}
|
|
680
721
|
for e in entries:
|
|
681
722
|
repo = e["repo"]
|
|
682
723
|
if not roots[repo]:
|
|
683
|
-
say("workspace: %s: no local checkout, skipped" % repo)
|
|
684
724
|
proposed[repo] = list(e.get("after") or [])
|
|
685
725
|
continue
|
|
686
726
|
toks = _dep_tokens(roots[repo])
|
|
@@ -701,6 +741,21 @@ def infer(name, workspaces, say=say):
|
|
|
701
741
|
deps.append(o)
|
|
702
742
|
evidence[(repo, o)] = imp[o]
|
|
703
743
|
proposed[repo] = deps
|
|
744
|
+
return proposed, evidence
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def infer(name, workspaces, say=say):
|
|
748
|
+
"""Print suggested `after:` edges from manifests; never writes loki.yaml."""
|
|
749
|
+
ws = workspaces.get(name)
|
|
750
|
+
if ws is None:
|
|
751
|
+
say("workspace: unknown workspace %r (known: %s)" % (name, ", ".join(sorted(workspaces)) or "none"))
|
|
752
|
+
return 2
|
|
753
|
+
entries = [e for e in ws.get("repos") or [] if isinstance(e.get("repo"), str)]
|
|
754
|
+
roots = _local_roots(entries)
|
|
755
|
+
for e in entries:
|
|
756
|
+
if not roots[e["repo"]]:
|
|
757
|
+
say("workspace: %s: no local checkout, skipped" % e["repo"])
|
|
758
|
+
proposed, evidence = infer_edges(entries, roots)
|
|
704
759
|
try:
|
|
705
760
|
order_repos({"repos": [{"repo": e["repo"], "after": proposed[e["repo"]]} for e in entries]})
|
|
706
761
|
except ValueError as err:
|
|
@@ -716,12 +771,226 @@ def infer(name, workspaces, say=say):
|
|
|
716
771
|
return 0
|
|
717
772
|
|
|
718
773
|
|
|
774
|
+
# ---- goal-driven repo selection (print-only `affected`; pruning via the affected key or env) ----------------------
|
|
775
|
+
_GOAL_STOP = frozenset(
|
|
776
|
+
"rename change update add remove fix everywhere all every across repos repo the a an to in of for from with "
|
|
777
|
+
"and or field fields use make new old into on by it its be should so that this as at is are we our code "
|
|
778
|
+
"support implement".split())
|
|
779
|
+
_SCAN_EXCLUDES = ("node_modules", "dist", "build", "vendor", ".loki")
|
|
780
|
+
_SCAN_TIMEOUT_S = 60
|
|
781
|
+
_MAX_TERMS = 40
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def _split_words(ident):
|
|
785
|
+
"""Lower-cased words of an identifier: split on _ - and camelCase humps."""
|
|
786
|
+
out = []
|
|
787
|
+
for part in re.split(r"[_\-\s]+", ident):
|
|
788
|
+
out += [w.lower() for w in re.findall(r"[A-Z]+(?![a-z])|[A-Z]?[a-z]+|[0-9]+", part)]
|
|
789
|
+
return out
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
def _variants(words):
|
|
793
|
+
"""Spelling variants of a word list: snake, kebab, camel, pascal, UPPER_SNAKE, concatenated, and ID forms."""
|
|
794
|
+
cap = [w.capitalize() for w in words]
|
|
795
|
+
out = ["_".join(words), "-".join(words), words[0] + "".join(cap[1:]), "".join(cap),
|
|
796
|
+
"_".join(words).upper(), "".join(words)]
|
|
797
|
+
if len(words[-1]) <= 3:
|
|
798
|
+
up = words[-1].upper()
|
|
799
|
+
out += [words[0] + "".join(cap[1:-1]) + up, "".join(cap[:-1]) + up]
|
|
800
|
+
return out
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
def goal_terms(text):
|
|
804
|
+
"""Searchable terms for a goal: explicit identifiers verbatim, plus variants of 2-3 word phrases."""
|
|
805
|
+
text = text or ""
|
|
806
|
+
explicit = []
|
|
807
|
+
for m in re.finditer(r"`([^`\n]+)`|\"([^\"\n]+)\"|(?<!\w)'([^'\n]+)'(?!\w)", text):
|
|
808
|
+
t = (m.group(1) or m.group(2) or m.group(3)).strip()
|
|
809
|
+
if len(t) >= 3:
|
|
810
|
+
explicit.append(t)
|
|
811
|
+
toks = re.findall(r"[A-Za-z][A-Za-z0-9_]*", text)
|
|
812
|
+
for i, tok in enumerate(toks):
|
|
813
|
+
if len(tok) < 2 or tok.lower() in _GOAL_STOP:
|
|
814
|
+
continue
|
|
815
|
+
if "_" in tok or re.search(r"[a-z0-9][A-Z]", tok) or (i > 0 and tok[0].isupper()):
|
|
816
|
+
explicit.append(tok)
|
|
817
|
+
terms = list(explicit)
|
|
818
|
+
for ident in explicit:
|
|
819
|
+
words = _split_words(ident)
|
|
820
|
+
if len(words) >= 2:
|
|
821
|
+
terms += _variants(words)
|
|
822
|
+
words = [w.lower() for w in re.findall(r"[A-Za-z][A-Za-z0-9]*", text)]
|
|
823
|
+
run = []
|
|
824
|
+
for w in words + [None]:
|
|
825
|
+
if w is not None and w not in _GOAL_STOP:
|
|
826
|
+
run.append(w)
|
|
827
|
+
continue
|
|
828
|
+
for n in (2, 3):
|
|
829
|
+
for i in range(len(run) - n + 1):
|
|
830
|
+
terms += _variants(run[i:i + n])
|
|
831
|
+
run = []
|
|
832
|
+
seen, out = set(), []
|
|
833
|
+
for t in terms:
|
|
834
|
+
if t and t not in seen:
|
|
835
|
+
seen.add(t)
|
|
836
|
+
out.append(t)
|
|
837
|
+
return out[:_MAX_TERMS]
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
def _term_regex(term):
|
|
841
|
+
# A term that starts with a capital may follow a lowercase letter (getCustomerId).
|
|
842
|
+
behind = r"(?<![A-Z0-9])" if term[:1].isupper() else r"(?<![A-Za-z0-9])"
|
|
843
|
+
return re.compile(behind + re.escape(term) + r"(?![a-z0-9])")
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
def _term_hit(root, terms):
|
|
847
|
+
"""-> (evidence or None, error or None): first tracked line in root with a boundary-matched term."""
|
|
848
|
+
cmd = ["git", "-C", root, "grep", "-I", "-n", "-F"]
|
|
849
|
+
for t in terms:
|
|
850
|
+
cmd += ["-e", t]
|
|
851
|
+
cmd += ["--", "."] + [":(exclude,glob)**/%s/**" % d for d in _SCAN_EXCLUDES]
|
|
852
|
+
rx = [(t, _term_regex(t)) for t in terms]
|
|
853
|
+
try:
|
|
854
|
+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
|
|
855
|
+
text=True, errors="replace")
|
|
856
|
+
except OSError as e:
|
|
857
|
+
return None, type(e).__name__
|
|
858
|
+
timed_out = []
|
|
859
|
+
|
|
860
|
+
def _kill():
|
|
861
|
+
timed_out.append(1)
|
|
862
|
+
try:
|
|
863
|
+
p.kill()
|
|
864
|
+
except OSError:
|
|
865
|
+
pass
|
|
866
|
+
timer = threading.Timer(_SCAN_TIMEOUT_S, _kill)
|
|
867
|
+
timer.start()
|
|
868
|
+
try:
|
|
869
|
+
for line in p.stdout:
|
|
870
|
+
parts = line.rstrip("\n").split(":", 2)
|
|
871
|
+
if len(parts) < 3:
|
|
872
|
+
continue
|
|
873
|
+
for t, r in rx:
|
|
874
|
+
if r.search(parts[2]):
|
|
875
|
+
p.kill()
|
|
876
|
+
p.wait()
|
|
877
|
+
return "%s:%s (%s)" % (parts[0], parts[1], t), None
|
|
878
|
+
rc = p.wait()
|
|
879
|
+
finally:
|
|
880
|
+
timer.cancel()
|
|
881
|
+
if p.poll() is None:
|
|
882
|
+
p.kill()
|
|
883
|
+
p.wait()
|
|
884
|
+
p.stdout.close()
|
|
885
|
+
if timed_out:
|
|
886
|
+
return None, "scan timed out after %ds" % _SCAN_TIMEOUT_S
|
|
887
|
+
if rc in (0, 1):
|
|
888
|
+
return None, None
|
|
889
|
+
return None, "git grep exit %d" % rc
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
def select_affected(ws, goal):
|
|
893
|
+
"""Pick the repos a goal touches by lexical search of each local checkout. Never returns an empty selection."""
|
|
894
|
+
entries = [e for e in ws.get("repos") or [] if isinstance(e.get("repo"), str)]
|
|
895
|
+
roots = _local_roots(entries)
|
|
896
|
+
sel = {"mode": "affected", "goal": goal, "terms": [], "selected": [], "not_selected": {}, "evidence": {},
|
|
897
|
+
"fallback": None}
|
|
898
|
+
m = REF_RE.match(goal or "")
|
|
899
|
+
text = goal
|
|
900
|
+
if m:
|
|
901
|
+
text = ""
|
|
902
|
+
try:
|
|
903
|
+
import backlog # lazy: backlog imports this module at load time
|
|
904
|
+
issue = backlog.view_issues(m.group(1), [int(m.group(2))], os.environ)[0]
|
|
905
|
+
text = "%s\n%s" % (issue.get("title") or "", issue.get("body") or "")
|
|
906
|
+
except Exception as e:
|
|
907
|
+
say("workspace: issue text unavailable (%s)" % (str(e).strip().splitlines() or [type(e).__name__])[0])
|
|
908
|
+
terms = goal_terms(text)
|
|
909
|
+
sel["terms"] = terms
|
|
910
|
+
for e in entries:
|
|
911
|
+
repo = e["repo"]
|
|
912
|
+
if m and repo == m.group(1):
|
|
913
|
+
sel["selected"].append(repo)
|
|
914
|
+
sel["evidence"][repo] = "issue owner"
|
|
915
|
+
elif not roots[repo]:
|
|
916
|
+
sel["selected"].append(repo)
|
|
917
|
+
sel["evidence"][repo] = "no local checkout; included unscanned"
|
|
918
|
+
elif not terms:
|
|
919
|
+
sel["not_selected"][repo] = "no match"
|
|
920
|
+
else:
|
|
921
|
+
hit, err = _term_hit(roots[repo], terms)
|
|
922
|
+
if err:
|
|
923
|
+
sel["selected"].append(repo)
|
|
924
|
+
sel["evidence"][repo] = "scan failed: %s; included" % err
|
|
925
|
+
elif hit:
|
|
926
|
+
sel["selected"].append(repo)
|
|
927
|
+
sel["evidence"][repo] = hit
|
|
928
|
+
else:
|
|
929
|
+
sel["not_selected"][repo] = "no match"
|
|
930
|
+
if not sel["selected"]:
|
|
931
|
+
sel["fallback"] = "no repo matched the goal; running every repo"
|
|
932
|
+
sel["selected"] = [e["repo"] for e in entries]
|
|
933
|
+
sel["not_selected"] = {}
|
|
934
|
+
return sel
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
def compose(ws, selection):
|
|
938
|
+
"""-> (repo entries for the selection with inferred `after` merged in, note or None)."""
|
|
939
|
+
entries = [e for e in ws.get("repos") or [] if isinstance(e.get("repo"), str)]
|
|
940
|
+
chosen = set(selection["selected"])
|
|
941
|
+
proposed, _ev = infer_edges(entries, _local_roots(entries))
|
|
942
|
+
picked, declared = [], []
|
|
943
|
+
for e in entries:
|
|
944
|
+
if e["repo"] not in chosen:
|
|
945
|
+
continue
|
|
946
|
+
keep = [d for d in e.get("after") or [] if d in chosen]
|
|
947
|
+
merged = list(dict.fromkeys(keep + [d for d in proposed.get(e["repo"], []) if d in chosen]))
|
|
948
|
+
picked.append(dict(e, after=merged))
|
|
949
|
+
declared.append(dict(e, after=keep))
|
|
950
|
+
try:
|
|
951
|
+
order_repos({"repos": picked})
|
|
952
|
+
return picked, None
|
|
953
|
+
except ValueError as err:
|
|
954
|
+
return declared, "inferred edges not used: %s" % err
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
def affected(name, workspaces, goal, as_json=False, say=say):
|
|
958
|
+
"""Print which repos a goal touches and the run order. Print-only: no model call, no files."""
|
|
959
|
+
ws = workspaces.get(name)
|
|
960
|
+
if ws is None:
|
|
961
|
+
say("workspace: unknown workspace %r (known: %s)" % (name, ", ".join(sorted(workspaces)) or "none"))
|
|
962
|
+
return 2
|
|
963
|
+
sel = select_affected(ws, goal)
|
|
964
|
+
try:
|
|
965
|
+
repos, note = compose(ws, sel)
|
|
966
|
+
order = [e["repo"] for e in order_repos({"repos": repos})]
|
|
967
|
+
except ValueError as e:
|
|
968
|
+
say("workspace: %s: %s" % (name, e))
|
|
969
|
+
return 2
|
|
970
|
+
if as_json:
|
|
971
|
+
say(json.dumps(dict(sel, order=order, note=note), indent=2, sort_keys=True))
|
|
972
|
+
return 0
|
|
973
|
+
say('workspace %s: affected by "%s" (terms: %s)' % (name, goal, ", ".join(sel["terms"]) or "none"))
|
|
974
|
+
for e in ws.get("repos") or []:
|
|
975
|
+
r = e.get("repo")
|
|
976
|
+
if r in sel["selected"]:
|
|
977
|
+
say("%-30s selected %s" % (r, sel["evidence"].get(r, "")))
|
|
978
|
+
else:
|
|
979
|
+
say("%-30s not selected (%s)" % (r, sel["not_selected"].get(r, "no match")))
|
|
980
|
+
if sel["fallback"]:
|
|
981
|
+
say("workspace: " + sel["fallback"])
|
|
982
|
+
if note:
|
|
983
|
+
say("workspace: " + note)
|
|
984
|
+
say("order: " + " -> ".join(order))
|
|
985
|
+
return 0
|
|
986
|
+
|
|
987
|
+
|
|
719
988
|
def main(argv):
|
|
720
989
|
if not enabled():
|
|
721
990
|
say("loki workspace is disabled (LOKI_WORKSPACES=0). Unset it to use workspaces.")
|
|
722
991
|
return 2
|
|
723
992
|
if not argv or argv[0] in ("-h", "--help", "help"):
|
|
724
|
-
say("Usage: loki workspace list | show <name> | infer <name> | run <name> <owner/repo#N | task text> | status [<run-id>]")
|
|
993
|
+
say("Usage: loki workspace list | show <name> | infer <name> | affected <name> [--json] <goal> | run <name> <owner/repo#N | task text> | status [<run-id>]")
|
|
725
994
|
return 0 if argv else 2
|
|
726
995
|
try:
|
|
727
996
|
workspaces, errors = load_workspaces()
|
|
@@ -745,10 +1014,14 @@ def main(argv):
|
|
|
745
1014
|
return show(argv[1], workspaces)
|
|
746
1015
|
if cmd == "status" and len(argv) <= 2:
|
|
747
1016
|
return status(os.getcwd(), argv[1] if len(argv) == 2 else None)
|
|
1017
|
+
if cmd == "affected" and len(argv) >= 3:
|
|
1018
|
+
rest = [a for a in argv[2:] if a != "--json"]
|
|
1019
|
+
if rest:
|
|
1020
|
+
return affected(argv[1], workspaces, " ".join(rest), as_json="--json" in argv[2:])
|
|
748
1021
|
if cmd == "run" and len(argv) >= 3:
|
|
749
1022
|
rc, _ = run_workspace(argv[1], " ".join(argv[2:]), workspaces)
|
|
750
1023
|
return rc
|
|
751
|
-
say("Usage: loki workspace list | show <name> | run <name> <issue-ref> | status [<run-id>]")
|
|
1024
|
+
say("Usage: loki workspace list | show <name> | infer <name> | affected <name> [--json] <goal> | run <name> <issue-ref> | status [<run-id>]")
|
|
752
1025
|
return 2
|
|
753
1026
|
|
|
754
1027
|
|
|
@@ -5,8 +5,8 @@ GITHUB_TOKEN is read by gh itself and never placed in argv, the comment body
|
|
|
5
5
|
or any log line. Commenting is best effort: it never raises and never changes
|
|
6
6
|
the run's exit code. Opt out with LOKI_WORKSPACE_COMMENT=0.
|
|
7
7
|
"""
|
|
8
|
+
import json
|
|
8
9
|
import os
|
|
9
|
-
import re
|
|
10
10
|
import subprocess
|
|
11
11
|
import tempfile
|
|
12
12
|
|
|
@@ -25,7 +25,7 @@ def verdict(ev):
|
|
|
25
25
|
return "FAILED"
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def render(ws_name, run_id, repo, ev):
|
|
28
|
+
def render(ws_name, run_id, repo, ev, links=None):
|
|
29
29
|
heads = ev.get("heads") or {}
|
|
30
30
|
lines = ["Loki workspace `%s` run `%s`" % (ws_name, run_id), "",
|
|
31
31
|
"Integration: **%s** (exit code %s)" % (verdict(ev), ev.get("exit_code")), "",
|
|
@@ -38,6 +38,15 @@ def render(ws_name, run_id, repo, ev):
|
|
|
38
38
|
lines.append("| %s%s | %s | %s |" % (r, mark, out, heads.get(r) or "none"))
|
|
39
39
|
if ev.get("log_sha256"):
|
|
40
40
|
lines += ["", "Integration log sha256: `%s`" % ev["log_sha256"]]
|
|
41
|
+
if links is not None:
|
|
42
|
+
lines += ["", "Linked PRs:"]
|
|
43
|
+
for r in sorted(links.keys() | set(worktrees_of(ev))):
|
|
44
|
+
pr = links.get(r)
|
|
45
|
+
if pr:
|
|
46
|
+
lines.append("- %s: %s%s%s" % (r, pr["url"], " (this PR)" if r == repo else "",
|
|
47
|
+
" (draft)" if pr.get("draft") else ""))
|
|
48
|
+
else:
|
|
49
|
+
lines.append("- %s: no open PR" % r)
|
|
41
50
|
lines += ["", "Integration evidence is not part of the Seal."]
|
|
42
51
|
return "\n".join(lines) + "\n"
|
|
43
52
|
|
|
@@ -54,26 +63,46 @@ def _branch(wt):
|
|
|
54
63
|
return b if r.returncode == 0 and b and b != "HEAD" else None
|
|
55
64
|
|
|
56
65
|
|
|
57
|
-
def
|
|
66
|
+
def worktrees_of(ev):
|
|
67
|
+
"""Repos that ran: the ones with a recorded head SHA or outcome."""
|
|
68
|
+
return list((ev.get("heads") or {}).keys() | (ev.get("outcomes") or {}).keys())
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def find_prs(worktrees):
|
|
72
|
+
"""{repo: {number, url, draft}} for each repo with an open PR on its run branch. Never raises."""
|
|
73
|
+
found = {}
|
|
74
|
+
for repo, wt in sorted(worktrees.items()):
|
|
75
|
+
try:
|
|
76
|
+
branch = _branch(wt)
|
|
77
|
+
if not branch:
|
|
78
|
+
continue
|
|
79
|
+
r = _gh(["pr", "list", "--repo", repo, "--head", branch, "--state", "open",
|
|
80
|
+
"--json", "number,url,isDraft", "--jq", ".[0]"], wt)
|
|
81
|
+
d = json.loads(r.stdout) if r.returncode == 0 and r.stdout.strip() else None
|
|
82
|
+
if isinstance(d, dict) and isinstance(d.get("number"), int) and isinstance(d.get("url"), str):
|
|
83
|
+
found[repo] = {"number": d["number"], "url": d["url"], "draft": bool(d.get("isDraft"))}
|
|
84
|
+
except (OSError, subprocess.SubprocessError, ValueError):
|
|
85
|
+
continue
|
|
86
|
+
return found
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def post_comments(ws_name, run_id, run_dir, worktrees, ev, say, links=None):
|
|
58
90
|
"""One comment per repo that has an open PR on its run branch. Never raises."""
|
|
59
91
|
if os.environ.get("LOKI_WORKSPACE_COMMENT") == "0":
|
|
60
92
|
return 0
|
|
61
93
|
posted = 0
|
|
62
94
|
try:
|
|
95
|
+
if links is None:
|
|
96
|
+
links = find_prs(worktrees)
|
|
63
97
|
for repo, wt in sorted(worktrees.items()):
|
|
64
98
|
try:
|
|
65
|
-
|
|
66
|
-
if not branch:
|
|
67
|
-
continue
|
|
68
|
-
r = _gh(["pr", "list", "--repo", repo, "--head", branch, "--state", "open",
|
|
69
|
-
"--json", "number", "--jq", ".[0].number"], wt)
|
|
70
|
-
num = r.stdout.strip()
|
|
71
|
-
if r.returncode != 0 or not re.fullmatch(r"\d+", num):
|
|
99
|
+
if repo not in links:
|
|
72
100
|
continue
|
|
101
|
+
num = str(links[repo]["number"])
|
|
73
102
|
fd, body = tempfile.mkstemp(prefix="comment-", suffix=".md", dir=run_dir) # mode 0600
|
|
74
103
|
try:
|
|
75
104
|
with os.fdopen(fd, "w") as f:
|
|
76
|
-
f.write(render(ws_name, run_id, repo, ev))
|
|
105
|
+
f.write(render(ws_name, run_id, repo, ev, links))
|
|
77
106
|
c = _gh(["pr", "comment", num, "--repo", repo, "--body-file", body], wt)
|
|
78
107
|
finally:
|
|
79
108
|
try:
|