path linkify: skip trailing-slash (directory) matches

This commit is contained in:
müde 2026-05-17 23:25:51 +02:00
parent 2ad5a94897
commit e772182724

View file

@ -48,7 +48,13 @@
// perspective (we'd need to know which agent the message is about
// to translate it). Prefer `/agents/<name>/state/...` in agent
// outputs and the link will resolve.
const PATH_RE = /(\/var\/lib\/hyperhive\/agents\/[\w.-]+\/state\/[\w./-]+|\/var\/lib\/hyperhive\/shared\/[\w./-]+|\/agents\/[\w.-]+\/state\/[\w./-]+|\/shared\/[\w./-]+)/g;
// Each branch insists the tail is at least one segment AND the
// last character is `[\w.-]` (not `/`), so trailing-slash paths
// — i.e. plain directories — don't linkify. The /api/state-file
// endpoint also refuses non-files; this is the front-end peer so
// the operator doesn't see a dead link they'll just get an error
// from on click.
const PATH_RE = /(\/var\/lib\/hyperhive\/agents\/[\w.-]+\/state\/(?:[\w.-]+\/)*[\w.-]+|\/var\/lib\/hyperhive\/shared\/(?:[\w.-]+\/)*[\w.-]+|\/agents\/[\w.-]+\/state\/(?:[\w.-]+\/)*[\w.-]+|\/shared\/(?:[\w.-]+\/)*[\w.-]+)/g;
async function fetchStateFile(path) {
const resp = await fetch('/api/state-file?path=' + encodeURIComponent(path));
const text = await resp.text();