chore: cleanup unused files

This commit is contained in:
sam committed 2026-11-16 02:04:45 +11:00
1 parent 200c6d0928
commit e594ec3780
4 files changed
-300

No files matched your search

-88
View File
@@ -1,88 +0,0 @@
# Gitea agent-run view
Untracked reference copies — deploy by hand onto the gitea container.
Renders inside Gitea's own Actions page (real `base/head` / `repo/header`
/ `base/footer`, real `.Repository`/`.CurWorkflow` context) via the
`body_inner_post.tmpl` hook — no full-file template override needed.
Confirmed 2026-07-22 that this hook receives the same per-page context
as `templates/repo/actions/list.tmpl`.
## Files → destinations
| file | destination on gitea container | role |
| ---------------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------- |
| `extra_tabs.tmpl` | `$GITEA_CUSTOM/templates/custom/extra_tabs.tmpl` | adds the "Agent Run" repo tab |
| `body_inner_post.tmpl` | `$GITEA_CUSTOM/templates/custom/body_inner_post.tmpl` | loads the CDN CSS/JS + agent-monitor.js, gated on the sentinel |
| `agent-monitor.js` | `$GITEA_CUSTOM/public/assets/agent-monitor.js` | swaps the runs-list segment's content for the terminal, opens the SSE connection |
`$GITEA_CUSTOM` is usually `/data/gitea` in the container — confirm via
Site Administration > Configuration, or `gitea help`.
Restart Gitea after copying either file (custom/templates is only read
at startup unless `RUN_MODE = dev`).
## How it fits together
`extra_tabs.tmpl` links to the real `/actions` route with a sentinel
`?workflow=__agent_monitor__`. Gitea's Actions handler happily sets
`.CurWorkflow` to that string (it doesn't validate it matches a real
workflow file) and renders the stock page as normal — sidebar, run-count
bar, "0 workflow runs" panel, all real Gitea markup. `body_inner_post.tmpl`
then fires on that same page, sees the sentinel, and loads
`agent-monitor.js`, which:
1. finds the real `.ui.attached.segment` inside `.flex-container-main`
— the element list.tmpl already sizes correctly to hold the runs
list — and swaps its content for the terminal, rather than hiding or
duplicating anything
2. hides the run-count/filter bar directly above that segment (nothing
to filter once the terminal's showing)
3. styles the segment as a floating rounded card (border radius, shadow)
4. mounts the xterm.js terminal inside it and opens the SSE connection
The sidebar is deliberately left alone — it's real, always-current Gitea
markup (actual workflow files, actual routes). An earlier version tried
hiding it and hardcoding a lookalike sidebar instead; that goes stale the
moment a workflow is added/renamed, so it was dropped in favour of this.
Nesting the terminal inside other stock wrapper classes (e.g.
`.ui.top.attached.header`, meant for the slim counter bar) also produced
a tiny clipped box in testing — reason `.ui.attached.segment` specifically
is the target now.
**Why the terminal logic is a separate `.js` file, not inline in the
template:** Gitea's CSP requires a per-request nonce for inline
`<script>` blocks, and that nonce isn't exposed to custom/templates.
External `<script src>` tags match the `*` already in `script-src` and
load with zero CSP changes — discovered the hard way when the first
inline-script version got silently blocked by the browser.
No stock Gitea file is copied or overridden, so there's nothing to
re-diff on version bumps — this is the whole reason the hook route won
out over overriding `list.tmpl`.
## Before it'll actually connect
`body_inner_post.tmpl` reads `internal/webui`'s `GET /events` SSE
stream. Two things need doing on the archie-core side first:
1. **Reachability** — the browser loads Gitea's origin, so it needs a
path to the webui SSE endpoint. Either reverse-proxy `/events` under
Gitea's own host (cleanest — avoids CORS entirely), or add CORS
headers to `handleSSE` in `internal/webui/webui.go` for Gitea's
origin, and set `?webui=` on the tab link (or edit `WEBUI_BASE` in
the template) to point at it.
2. **Auth** — `internal/webui`'s own doc comment says "it has no auth" —
this whole path is trusted-network only right now, same as the
dashboard. Don't expose it publicly without adding one.
`/events` has no server-side repo/task filter; `agent-monitor.js`
filters client-side on `event.repo`, so it still receives every task's
events over the wire — fine at current volume, revisit if that stream
gets busy.
Note: the `[cors]` section in Gitea's own `app.ini` does NOT help here —
it controls CORS headers Gitea sends to let _other_ origins call Gitea's
API, not the reverse (the browser, loaded from Gitea's origin, fetching
archie-core's separate `internal/webui` server). The CORS header needs
to live on that webui response, or use the reverse-proxy route instead.
-158
View File
@@ -1,158 +0,0 @@
// Copy to: $GITEA_CUSTOM/public/assets/agent-monitor.js
// Referenced from body_inner_post.tmpl via
// <script src="{{AppSubUrl}}/assets/agent-monitor.js" data-repo="{{.Repository.FullName}}">
// rather than an inline <script> block — Gitea's CSP header requires a
// per-request nonce for inline scripts that custom/templates has no way
// to supply, but external script sources match the "*" already present
// in script-src, so this loads fine with no CSP changes needed.
//
// Doesn't hide or duplicate list.tmpl's sidebar — that's real,
// always-current Gitea markup. Instead it swaps the CONTENT of the
// existing ".ui.attached.segment" (the element list.tmpl already sizes
// correctly to hold the runs list) for the terminal. Nesting the
// terminal inside other stock wrapper classes instead (e.g.
// ".ui.top.attached.header", meant for the slim run-count bar) is what
// produced a tiny clipped box in earlier testing — this element is the
// right one.
(function () {
const scriptTag = document.currentScript;
const repoFilter = scriptTag ? scriptTag.dataset.repo : "";
console.log("[agent-monitor] loaded, repo=", repoFilter);
// Primary selector matches list.tmpl's structure; fall back to a looser
// one (drop the .flex-container-main ancestor requirement) and finally
// to "last .ui.attached.segment on the page" in case a workflow_dispatch
// block or markup drift shifted things — log which one hit so a failed
// match is visible in the console instead of silently doing nothing.
const candidates = [
".repository.actions .flex-container-main .ui.attached.segment",
".repository.actions .ui.attached.segment",
".ui.attached.segment",
];
let segment = null;
for (const sel of candidates) {
const found = document.querySelectorAll(sel);
if (found.length) {
segment = found[found.length - 1]; // last match = likely the runs-list one
console.log(
"[agent-monitor] matched selector:",
sel,
"(",
found.length,
"candidate(s))",
);
break;
}
}
if (!segment) {
console.warn(
"[agent-monitor] no .ui.attached.segment found on page — markup shape changed, nothing to swap",
);
return;
}
// The run-count/filter bar sits directly above the segment; hide it,
// there's nothing meaningful to filter once we're showing the terminal.
const counterBar = segment.previousElementSibling;
if (counterBar && counterBar.classList.contains("flex-left-right")) {
counterBar.style.display = "none";
}
segment.innerHTML = "";
Object.assign(segment.style, {
padding: "12px",
borderRadius: "10px",
overflow: "hidden",
boxShadow: "0 2px 10px rgba(0,0,0,0.35)",
background: "#1e1e1e",
border: "none",
height: "70vh",
boxSizing: "border-box",
});
const el = document.createElement("div");
Object.assign(el.style, { height: "100%", width: "100%" });
segment.appendChild(el);
// TODO: point this at wherever internal/webui (archie-core's SSE
// dashboard) is reachable from the browser — reverse-proxy it under
// this same host to avoid CORS. Override per-load with ?webui=.
const WEBUI_BASE =
new URLSearchParams(location.search).get("webui") ||
"https://gitea.example.com/agent-events";
const term = new Terminal({
convertEol: true,
disableStdin: true,
cursorBlink: false,
fontSize: 13,
});
term.open(el);
// FitAddon sizes xterm's internal viewport (rows/cols) to match the
// container's actual pixel size — without it xterm falls back to a
// default 80x24 grid that doesn't match our div, which is what made
// the terminal look mismatched/"out of place" against the card.
if (window.FitAddon) {
const fit = new window.FitAddon.FitAddon();
term.loadAddon(fit);
fit.fit();
window.addEventListener("resize", () => fit.fit());
}
term.writeln(
`\x1b[90mconnecting to ${WEBUI_BASE} (repo=${repoFilter})...\x1b[0m`,
);
function colorFor(stage) {
switch (stage) {
case "error":
return "\x1b[31m";
case "done":
return "\x1b[32m";
default:
return "\x1b[36m";
}
}
function render(e) {
if (repoFilter && e.repo && e.repo !== repoFilter) return;
const ts = new Date().toLocaleTimeString();
const tag = [e.workflow, e.stage].filter(Boolean).join(":");
term.writeln(
`\x1b[90m${ts}\x1b[0m ${colorFor(e.stage)}[${tag || "event"}]\x1b[0m ${e.detail || ""}`,
);
if (e.data && Object.keys(e.data).length) {
term.writeln(`\x1b[90m ${JSON.stringify(e.data)}\x1b[0m`);
}
}
// A new line per failed attempt spams the screen when the endpoint is
// unreachable for a while (each retry is 3s apart, but it adds up).
// Print the "lost" message once per disconnect, then just tick dots on
// the same line so it still reads as "trying," not a wall of red text.
let retrying = false;
function connect() {
const es = new EventSource(WEBUI_BASE + "/events");
es.onopen = () => {
if (retrying) term.writeln("\x1b[32m connected\x1b[0m");
retrying = false;
};
es.onmessage = (msg) => {
try {
render(JSON.parse(msg.data));
} catch {}
};
es.onerror = () => {
es.close();
if (!retrying) {
term.writeln("\x1b[31mconnection lost, retrying...\x1b[0m");
retrying = true;
} else {
term.write("\x1b[31m.\x1b[0m");
}
setTimeout(connect, 3000);
};
}
connect();
})();
@@ -1,36 +0,0 @@
{{/*
Copy to: $GITEA_CUSTOM/templates/custom/body_inner_post.tmpl
This is an optional hook file Gitea looks for if present (like
extra_links.tmpl) — nothing to diff against upstream, no maintenance
burden across Gitea version bumps, unlike overriding list.tmpl outright.
Confirmed empirically (2026-07-22): this hook gets the SAME per-page
context as templates/repo/actions/list.tmpl — .CurWorkflow, .Repository
etc. are all real values here, not a stripped-down base context.
Renders the agent terminal in place of the normal Actions runs list
when the tab link's sentinel ?workflow=__agent_monitor__ is present.
Does NOT hide or rebuild list.tmpl's sidebar/menu — that's real,
always-current Gitea markup (actual workflow files, actual routes) and
duplicating it here as static HTML would go stale the moment a
workflow is added/renamed/removed. Only the runs-list segment itself
(".ui.attached.segment" inside ".flex-container-main") gets its
content swapped for the terminal — done in JS (agent-monitor.js), not
here, since that's the element list.tmpl already sized correctly to
hold content; nesting the terminal inside other stock wrapper classes
(e.g. ".ui.top.attached.header", meant for a slim counter bar) is what
caused the tiny clipped box in testing.
The JS logic itself lives in the external agent-monitor.js (loaded via
<script src>, not inline) because Gitea's CSP requires a per-request
nonce for inline <script> blocks that custom/templates has no way to
supply — external script sources match the "*" already in script-src
and load fine without touching Gitea's CSP config at all.
*/}}
{{if eq $.CurWorkflow "__agent_monitor__"}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@5/css/xterm.css">
<script src="https://cdn.jsdelivr.net/npm/xterm@5/lib/xterm.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@xterm/addon-fit@0/lib/addon-fit.js"></script>
<script src="{{AppSubUrl}}/assets/agent-monitor.js" data-repo="{{.Repository.FullName}}"></script>
{{end}}
-18
View File
@@ -1,18 +0,0 @@
{{/*
Copy to: $GITEA_CUSTOM/templates/custom/extra_tabs.tmpl
(on the gitea container: /data/gitea/templates/custom/extra_tabs.tmpl,
or wherever GITEA_CUSTOM points — check Site Administration > Configuration)
Adds an "Agent Run" tab to the repo header, matching the markup Gitea
uses for its own tabs (see templates/repo/header.tmpl upstream).
Restart Gitea after copying (custom/templates is only read at startup
unless RUN_MODE = dev).
Links into the real Actions list route with a sentinel ?workflow= value
that list.tmpl (see list.tmpl in this same directory) intercepts to
render agent_monitor.tmpl instead of the normal runs list — real
head/header/footer, no separate static page or route needed.
*/}}
<a class="item" href="{{AppSubUrl}}/{{.Repository.OwnerName}}/{{.Repository.Name}}/actions?workflow=__agent_monitor__">
{{svg "octicon-play" 16 "tw-mr-2"}}Agent Run
</a>