diff --git a/.github/scripts/test-required-check-concurrency.py b/.github/scripts/test-required-check-concurrency.py new file mode 100644 index 0000000000..a61c87366d --- /dev/null +++ b/.github/scripts/test-required-check-concurrency.py @@ -0,0 +1,419 @@ +#!/usr/bin/env python3 +"""Required checks must never be CANCELLED by a re-check of the same head (#18578). + +GitHub scores every check-run of a required name on a commit, so one cancelled +sibling keeps a PR BLOCKED beside a green survivor and Tide jams on it +(#11250, #18578). Two concurrency behaviours produce such siblings: + + * cancel-in-progress: a new run in the group cancels the one in flight; + * queue replacement: a group holds at most one pending run, and the next run + to queue cancels it, even with cancel-in-progress false. + +So any event that re-checks the SAME head (a label flip, an edit, a reopen) +must land in a concurrency group of its own. This test parses every workflow +under .github/workflows/, finds the jobs that produce a required context on +v5, and evaluates their concurrency expressions for a push followed by a +burst of label events on one head SHA. It fails if any two of those runs +share a group. + +The expression evaluator below covers the subset of GitHub's expression +syntax these workflows use (contexts, literals, ==, !=, !, &&, ||, +parentheses, contains/fromJSON/format/startsWith/endsWith). An unsupported +construct fails loudly rather than passing. +""" +import json +import pathlib +import re +import unittest + +import yaml + +ROOT = pathlib.Path(__file__).resolve().parents[2] +WORKFLOWS = ROOT / ".github/workflows" + +# Mirror of the v5 branch protection's required contexts, read with +# `gh api repos/hivecommons/hive/branches/v5/protection/required_status_checks`. +# Keep in step when a context is added; contexts produced by an app (DCO) and +# not by a workflow job are simply never matched. +REQUIRED_CONTEXTS = { + "gate", + "DCO", + "build-and-test", + "test", + "coverage", + "golangci-lint", + "gosec (insecure patterns)", + "govulncheck (known vulnerabilities)", + "changelog-fragment-guard", + "verify PR contents", + "Sign-off survives the squash", +} + +PR_EVENTS = ("pull_request", "pull_request_target") +# Events that re-check a head SHA that already has (or is getting) a run. +RECHECK_ACTIONS = ("labeled", "unlabeled") +# GitHub's default activity types when `types:` is omitted. +DEFAULT_PR_TYPES = ["opened", "synchronize", "reopened"] + +PR_NUMBER = 4242 +HEAD_SHA = "a" * 40 +MERGE_SHA = "b" * 40 + + +# --- minimal GitHub expression evaluator ------------------------------------ + +TOKEN = re.compile(r""" + \s*(?: + (?P-?\d+(?:\.\d+)?) + | (?P'(?:[^']|'')*') + | (?P==|!=|&&|\|\||<=|>=|[!<>()\[\],.*]) + | (?P[A-Za-z_][A-Za-z0-9_-]*) + )""", re.X) + + +class ExprError(ValueError): + pass + + +def tokenize(src): + pos, out = 0, [] + while pos < len(src): + if src[pos:].strip() == "": + break + m = TOKEN.match(src, pos) + if not m or m.end() == pos: + raise ExprError(f"cannot tokenize {src[pos:]!r}") + pos = m.end() + kind = m.lastgroup + out.append((kind, m.group(kind))) + return out + + +def truthy(v): + return not (v is None or v is False or v == 0 or v == "") + + +def to_str(v): + if v is None: + return "" + if v is True: + return "true" + if v is False: + return "false" + if isinstance(v, (dict, list)): + return json.dumps(v) + return str(v) + + +def loose_eq(a, b): + if type(a) is type(b): + return a == b + if isinstance(a, str) and isinstance(b, str): + return a.lower() == b.lower() + return to_str(a) == to_str(b) + + +def fn_format(fmt, *args): + return re.sub(r"\{(\d+)\}", lambda m: to_str(args[int(m.group(1))]), fmt) + + +FUNCTIONS = { + "contains": lambda hay, needle: ( + any(loose_eq(x, needle) for x in hay) if isinstance(hay, list) + else to_str(needle).lower() in to_str(hay).lower()), + "fromjson": lambda s: json.loads(s), + "format": fn_format, + "startswith": lambda s, p: to_str(s).lower().startswith(to_str(p).lower()), + "endswith": lambda s, p: to_str(s).lower().endswith(to_str(p).lower()), +} + + +class Parser: + def __init__(self, src, ctx): + self.toks, self.i, self.ctx = tokenize(src), 0, ctx + + def peek(self, value=None): + if self.i >= len(self.toks): + return None + tok = self.toks[self.i] + return tok if value is None or tok[1] == value else None + + def take(self, value=None): + tok = self.peek(value) + if tok is None: + raise ExprError(f"expected {value!r} at token {self.i}") + self.i += 1 + return tok + + def parse(self): + v = self.or_() + if self.i != len(self.toks): + raise ExprError(f"trailing tokens: {self.toks[self.i:]}") + return v + + def or_(self): + v = self.and_() + while self.peek("||"): + self.take() + rhs = self.and_() + v = v if truthy(v) else rhs + return v + + def and_(self): + v = self.cmp() + while self.peek("&&"): + self.take() + rhs = self.cmp() + v = rhs if truthy(v) else v + return v + + def cmp(self): + v = self.unary() + while self.peek("==") or self.peek("!="): + op = self.take()[1] + rhs = self.unary() + v = loose_eq(v, rhs) if op == "==" else not loose_eq(v, rhs) + return v + + def unary(self): + if self.peek("!"): + self.take() + return not truthy(self.unary()) + return self.postfix() + + def postfix(self): + v = self.primary() + while True: + if self.peek("."): + self.take() + name = self.take()[1] + v = v.get(name) if isinstance(v, dict) else None + elif self.peek("["): + self.take() + key = self.or_() + self.take("]") + v = v.get(key) if isinstance(v, dict) else None + else: + return v + + def primary(self): + kind, val = self.take() + if val == "(": + v = self.or_() + self.take(")") + return v + if kind == "num": + return float(val) if "." in val else int(val) + if kind == "str": + return val[1:-1].replace("''", "'") + if kind != "ident": + raise ExprError(f"unexpected token {val!r}") + if val in ("true", "false"): + return val == "true" + if val == "null": + return None + if self.peek("("): + fn = FUNCTIONS.get(val.lower()) + if fn is None: + raise ExprError(f"unsupported function {val}()") + self.take("(") + args = [] + while not self.peek(")"): + args.append(self.or_()) + if not self.peek(")"): + self.take(",") + self.take(")") + return fn(*args) + if val not in self.ctx: + raise ExprError(f"unsupported context {val!r}") + return self.ctx[val] + + +def evaluate(template, ctx): + """Evaluate a workflow value: a plain scalar or a string with ${{ }} parts.""" + if not isinstance(template, str): + return template + parts = re.split(r"\$\{\{(.*?)\}\}", template) + if len(parts) == 3 and parts[0].strip() == "" and parts[2].strip() == "": + return Parser(parts[1], ctx).parse() + out = [] + for idx, part in enumerate(parts): + out.append(part if idx % 2 == 0 else to_str(Parser(part, ctx).parse())) + return "".join(out) + + +# --- workflow inspection ----------------------------------------------------- + +def load(path): + data = yaml.safe_load(path.read_text()) + # PyYAML's YAML 1.1 loader reads the key `on` as True. + events = data.get("on", data.get(True)) or {} + if isinstance(events, str): + events = {events: None} + elif isinstance(events, list): + events = {e: None for e in events} + return data, events + + +def pr_types(events, name): + cfg = events.get(name) + if name not in events: + return [] + if isinstance(cfg, dict) and "types" in cfg: + return list(cfg["types"]) + return list(DEFAULT_PR_TYPES) + + +def context_for(workflow_name, event_name, action, run_id): + return { + "github": { + "workflow": workflow_name, + "event_name": event_name, + "ref": f"refs/pull/{PR_NUMBER}/merge", + "sha": MERGE_SHA, + "run_id": run_id, + "repository": "hivecommons/hive", + "event": { + "action": action, + "number": PR_NUMBER, + "pull_request": { + "number": PR_NUMBER, + "head": {"sha": HEAD_SHA, "repo": {"full_name": "hivecommons/hive"}}, + "base": {"ref": "v5"}, + }, + }, + }, + "inputs": {}, + "vars": {}, + } + + +def same_head_runs(data, events): + """Yield (event_name, action, run_id) for a push then a burst of re-checks.""" + run_id = 1000 + for event_name in PR_EVENTS: + types = pr_types(events, event_name) + if not any(a in types for a in RECHECK_ACTIONS): + continue + first = "synchronize" if "synchronize" in types else types[0] + yield event_name, first, run_id + for action in RECHECK_ACTIONS: + if action in types: + # Two of each: lgtm + approved land together on approval. + for _ in range(2): + run_id += 1 + yield event_name, action, run_id + + +def collisions(workflow_name, concurrency, runs): + """Return a list of human-readable problems for one concurrency block.""" + if concurrency is None: + return [] + if isinstance(concurrency, str): + concurrency = {"group": concurrency} + problems, seen = [], {} + for event_name, action, run_id in runs: + ctx = context_for(workflow_name, event_name, action, run_id) + group = to_str(evaluate(concurrency["group"], ctx)) + if group in seen: + other = seen[group] + cancel = truthy(evaluate(concurrency.get("cancel-in-progress", False), ctx)) + how = "cancels it in flight" if cancel else "replaces it in the queue" + problems.append( + f"{event_name}/{action} (run {run_id}) shares group {group!r} with " + f"{other[0]}/{other[1]} (run {other[2]}) on the same head SHA and {how}") + else: + seen[group] = (event_name, action, run_id) + return problems + + +def required_jobs(data): + for key, job in (data.get("jobs") or {}).items(): + name = job.get("name", key) if isinstance(job, dict) else key + if name in REQUIRED_CONTEXTS: + yield name, job + + +def audit(path): + data, events = load(path) + jobs = list(required_jobs(data)) + if not jobs: + return None, [] + runs = list(same_head_runs(data, events)) + if not runs: + return [n for n, _ in jobs], [] + name = data.get("name", path.name) + problems = collisions(name, data.get("concurrency"), runs) + for job_name, job in jobs: + problems += [f"job {job_name!r}: {p}" + for p in collisions(name, job.get("concurrency"), runs)] + return [n for n, _ in jobs], problems + + +class RequiredCheckConcurrency(unittest.TestCase): + def test_same_head_rechecks_never_share_a_group(self): + audited = {} + for path in sorted(WORKFLOWS.glob("*.yml")): + with self.subTest(workflow=path.name): + contexts, problems = audit(path) + if contexts: + audited[path.name] = contexts + self.assertEqual(problems, [], f"{path.name}: see #18578") + # Positive control: the label-triggered required checks this guard + # exists for must actually have been found and evaluated. + for file, context in ( + ("pr-verifier.yml", "verify PR contents"), + ("dco-squash-attribution.yml", "Sign-off survives the squash"), + ("changelog-fragment-guard.yml", "changelog-fragment-guard"), + ): + self.assertIn(context, audited.get(file, []), file) + + def test_guard_flags_the_pre_18578_shapes(self): + events = {"pull_request_target": {"types": ["opened", "synchronize", "labeled", "unlabeled"]}} + runs = list(same_head_runs({}, events)) + # pr-verifier.yml before #18578: per-PR group, cancel on PR events. + old_verifier = { + "group": "${{ github.workflow }}-${{ github.event.pull_request.number || inputs.pr_number || github.ref }}", + "cancel-in-progress": "${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}", + } + problems = collisions("PR Verifier", old_verifier, runs) + self.assertTrue(problems) + self.assertIn("cancels it in flight", problems[0]) + # Head SHA in the group alone still lets label runs on that SHA cancel + # each other. + sha_only = { + "group": "${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}", + "cancel-in-progress": True, + } + self.assertTrue(collisions("PR Verifier", sha_only, runs)) + # changelog-fragment-guard before #18578: no cancel on labels, but a + # shared group still drops queued runs. + queued = { + "group": "changelog-fragment-guard-${{ github.event.pull_request.number }}", + "cancel-in-progress": "${{ github.event.action == 'synchronize' }}", + } + problems = collisions("changelog-fragment-guard", queued, runs) + self.assertTrue(problems) + self.assertIn("replaces it in the queue", problems[0]) + + def test_head_moving_events_still_share_the_per_sha_group(self): + # The run_id suffix is for re-checks only: the push-triggered run keeps + # the plain per-PR, per-SHA group. + data, _ = load(WORKFLOWS / "pr-verifier.yml") + ctx = context_for("PR Verifier", "pull_request_target", "synchronize", 1) + self.assertEqual(evaluate(data["concurrency"]["group"], ctx), + f"PR Verifier-{PR_NUMBER}-{HEAD_SHA}") + ctx = context_for("PR Verifier", "pull_request_target", "labeled", 7) + self.assertEqual(evaluate(data["concurrency"]["group"], ctx), + f"PR Verifier-{PR_NUMBER}-{HEAD_SHA}-labeled-7") + self.assertIs(data["concurrency"]["cancel-in-progress"], False) + + def test_evaluator_rejects_what_it_cannot_model(self): + with self.assertRaises(ExprError): + evaluate("${{ hashFiles('x') }}", context_for("w", "pull_request", "opened", 1)) + with self.assertRaises(ExprError): + evaluate("${{ needs.a.outputs.b }}", context_for("w", "pull_request", "opened", 1)) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/changelog-fragment-guard.yml b/.github/workflows/changelog-fragment-guard.yml index 850a0da40f..235d88096b 100644 --- a/.github/workflows/changelog-fragment-guard.yml +++ b/.github/workflows/changelog-fragment-guard.yml @@ -72,8 +72,14 @@ permissions: # was left with CANCELLED check-runs for this *required* context. GitHub # scores every run of a required name, so one cancelled sibling kept the PR # at mergeStateStatus=BLOCKED with a green survivor beside it (#11250). +# cancel-in-progress false is not enough on its own: a queued run in a shared +# group is cancelled by the next run to queue, so a burst of three or four +# labels still left CANCELLED siblings (#18578). labeled/unlabeled/reopened +# runs therefore get their own group (github.run_id) and can neither cancel +# nor be cancelled; .github/scripts/test-required-check-concurrency.py +# enforces it. concurrency: - group: changelog-fragment-guard-${{ github.event.pull_request.number }} + group: changelog-fragment-guard-${{ github.event.pull_request.number }}${{ contains(fromJSON('["labeled","unlabeled","reopened"]'), github.event.action) && format('-{0}-{1}', github.event.action, github.run_id) || '' }} cancel-in-progress: ${{ github.event.action == 'synchronize' }} jobs: @@ -88,8 +94,8 @@ jobs: # a malformed fragment (#14629), which then broke the release `decide` # job on v5 and held every open v5 PR behind a red base. The guard is # cheap (git, grep, echo); re-running it on each label event keeps the - # reported verdict truthful. Label runs are not cancelled by concurrency - # (see above), so they cannot leave CANCELLED check-runs either. + # reported verdict truthful. Label runs each get their own concurrency + # group (see above), so they cannot leave CANCELLED check-runs either. # Forward-merge sync PRs (v5-topup.yml / v6-topup.yml, and the hand-rolled # ones maintainers open when those conflict) live on sync/* branches — # or on /sync-vN-to-vM when an agent opens the top-up, since the diff --git a/.github/workflows/dco-squash-attribution.yml b/.github/workflows/dco-squash-attribution.yml index 0445602975..0594c12bd6 100644 --- a/.github/workflows/dco-squash-attribution.yml +++ b/.github/workflows/dco-squash-attribution.yml @@ -22,9 +22,24 @@ on: types: [opened, synchronize, reopened, labeled, unlabeled] +# Required context: never CANCEL a run on the head SHA (#18578). GitHub scores +# every check-run of a required name on a commit, so one cancelled sibling +# leaves the PR BLOCKED beside a green survivor and Tide jams on it (#11250). +# The verdict does depend on labels (merge-method/merge), so label events keep +# re-running the job in full, but: +# - the group carries the head SHA, so runs on different commits never meet; +# - labeled/unlabeled/reopened runs also carry github.run_id, so each runs +# in its own group: a burst of label flips can neither cancel the run in +# flight nor have its queued runs cancelled by the next one to queue +# (GitHub does that to pending runs even with cancel-in-progress false). +# Every run reads the label set from its own event payload, and the +# newest run carries the newest set. +# - runs on a superseded commit finish (5 min cap) rather than being +# cancelled; their verdict lands on that old SHA, which never merges. +# .github/scripts/test-required-check-concurrency.py enforces this. concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.event.pull_request.head.sha || github.sha }}${{ contains(fromJSON('["labeled","unlabeled","reopened"]'), github.event.action) && format('-{0}-{1}', github.event.action, github.run_id) || '' }} + cancel-in-progress: false permissions: contents: read diff --git a/.github/workflows/integration-candidate.yml b/.github/workflows/integration-candidate.yml index 34289ba892..25c3e6250f 100644 --- a/.github/workflows/integration-candidate.yml +++ b/.github/workflows/integration-candidate.yml @@ -468,6 +468,9 @@ jobs: - name: hive-review helper tests working-directory: . run: bash bin/test_hive_review.sh + - name: hive-topic helper tests + working-directory: . + run: bash bin/test_hive_topic.sh - name: Shared CI baseline classifier tests working-directory: . run: bash bin/test_hive_baseline_check.sh diff --git a/.github/workflows/integration-technical-v2-ci.yml b/.github/workflows/integration-technical-v2-ci.yml index 76e170ee16..1127eb20f1 100644 --- a/.github/workflows/integration-technical-v2-ci.yml +++ b/.github/workflows/integration-technical-v2-ci.yml @@ -328,6 +328,9 @@ jobs: - name: hive-review helper tests working-directory: . run: bash bin/test_hive_review.sh + - name: hive-topic helper tests + working-directory: . + run: bash bin/test_hive_topic.sh - name: Shared CI baseline classifier tests working-directory: . run: bash bin/test_hive_baseline_check.sh diff --git a/.github/workflows/pr-auto-update-test.yml b/.github/workflows/pr-auto-update-test.yml index 011d3c6c78..118e3ec806 100644 --- a/.github/workflows/pr-auto-update-test.yml +++ b/.github/workflows/pr-auto-update-test.yml @@ -17,6 +17,9 @@ on: - '.github/workflows/v2-tests.yml' - '.github/workflows/go-security-analysis.yml' - '.github/workflows/pr-verifier.yml' + # Any workflow edit can change a required check's concurrency (#18578). + - '.github/scripts/test-required-check-concurrency.py' + - '.github/workflows/*.yml' push: branches: [v5, v6] paths: @@ -34,6 +37,9 @@ on: - '.github/workflows/v2-tests.yml' - '.github/workflows/go-security-analysis.yml' - '.github/workflows/pr-verifier.yml' + # Any workflow edit can change a required check's concurrency (#18578). + - '.github/scripts/test-required-check-concurrency.py' + - '.github/workflows/*.yml' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -63,3 +69,5 @@ jobs: sudo apt-get install -y -qq python3-yaml - name: Check native queue workflow contracts run: python3 .github/scripts/test-native-queue-workflows.py + - name: Required checks are never cancelled by same-head re-checks (#18578) + run: python3 .github/scripts/test-required-check-concurrency.py diff --git a/.github/workflows/pr-verifier.yml b/.github/workflows/pr-verifier.yml index c01821d511..e3fe5dcc90 100644 --- a/.github/workflows/pr-verifier.yml +++ b/.github/workflows/pr-verifier.yml @@ -19,7 +19,7 @@ name: PR Verifier # and the run's check lands on the branch tip, i.e. the pushed head. Only # same-repo branches are ever dispatched (the autofix never pushes to # forks); such a run uses the GitHub-hosted ARM runner like fork PRs do. -# The concurrency group below bounds the cost. +# The concurrency group below bounds the cost without cancelling anything. on: pull_request_target: types: [opened, edited, synchronize, reopened, ready_for_review, labeled, unlabeled] @@ -30,9 +30,24 @@ on: required: true type: string +# Required context: never CANCEL a run on the head SHA (#18578). GitHub scores +# every check-run of a required name on a commit, so one cancelled sibling +# leaves the PR BLOCKED beside a green survivor and Tide jams on it (#11250). +# A per-PR group with cancel-in-progress let every label flip (lgtm, approved, +# size, stage) cancel the run in flight, and a queued run in a shared group is +# cancelled by the next one to queue even with cancel-in-progress false. So: +# - the group carries the head SHA, so runs on different commits never meet; +# - events that re-check the same head (labeled, unlabeled, edited, +# reopened, ready_for_review) also carry github.run_id: each runs in its +# own group and can neither cancel nor be cancelled. The wrapper is green +# whatever the label set (every verdict step is continue-on-error), and +# the label types stay for #17036, not for the verdict. +# - runs on a superseded commit finish (10 min cap) rather than being +# cancelled; their verdict lands on that old SHA, which never merges. +# .github/scripts/test-required-check-concurrency.py enforces this. concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || inputs.pr_number || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number || inputs.pr_number || github.ref }}-${{ github.event.pull_request.head.sha || github.sha }}${{ contains(fromJSON('["labeled","unlabeled","edited","reopened","ready_for_review"]'), github.event.action) && format('-{0}-{1}', github.event.action, github.run_id) || '' }} + cancel-in-progress: false permissions: checks: write diff --git a/.github/workflows/v2-ci.yml b/.github/workflows/v2-ci.yml index a9e1c8a6b1..083d3b2d75 100644 --- a/.github/workflows/v2-ci.yml +++ b/.github/workflows/v2-ci.yml @@ -902,6 +902,10 @@ jobs: working-directory: . run: bash bin/test_hive_review.sh + - name: hive-topic helper tests + working-directory: . + run: bash bin/test_hive_topic.sh + - name: Shared CI baseline classifier tests working-directory: . run: bash bin/test_hive_baseline_check.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index cffdb5e64d..fc6baa85f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -296,6 +296,92 @@ Hive did not historically maintain a complete changelog. This file starts a prag - The signed-commit reconciler's intentional refusal to rewrite a foreign or merge commit no longer files repeated unclassified-error fleet reports; its warning and PR remediation remain visible ([#17924](https://github.com/hivecommons/hive/issues/17924)). - Dashboard logs one summary warning per five minutes for dropped SSE events instead of one warning per event, so a stalled browser tab no longer triggers repeated-error fleet reports (#17995). +## 2026-11-17 (v5.292.0) + +### Added + +- **Agents declared in a managed repo's `.hive/agents/`** are discovered and held for owner approval, so a project adds an agent with a PR instead of a hive config edit. Every allowlisted managed repo (the same repo-sourced prompt allowlist as `definition_source`: the seed list or an owner-approved repo) is scanned at startup, every 15 minutes (`HIVE_REPO_AGENTS_INTERVAL`) and on a default-branch push touching `.hive/agents/`; each `.yaml` shows up as pending under **Agents → Import → Declared in your repos** and nothing runs until an owner approves it. Approval registers the agent with `definition_source` (marked `discovered`) and, with a sibling `.md`, `prompt_source`; backend, model, mode and tools stay owner-controlled on every later re-apply. Removing the file pauses the agent rather than deleting it. ([#18491](https://github.com/hivecommons/hive/issues/18491)) + +### Fixed + +- **The hive no longer fights a repository's own triage tooling over `needs-triage`.** Once an issue was claimed or covered by a pull request (020, 030, 040) the issue stage sweep took `needs-triage` off on every pass, so in a repository whose own tooling owns that label — Prow's `require-matching-label` action re-adds it to every issue without a `triage/*` label — the two removed and re-added it without end: 312 removals on 16 `projectbluefin/utah` issues in one night, each also starting a GitHub Actions run there. The hive now removes the label at most once per issue; if anything puts it back (another tool or a person), it leaves it on that issue from then on, logs one INFO line naming the repo, issue and label, and remembers the yield in the stage store, so a restart does not restart the loop. Issues whose label never comes back — hive-filed self-reports included — lose a stale `needs-triage` once claimed exactly as before ([#18387](https://github.com/hivecommons/hive/issues/18387)). +- Dashboard: an agent that is running but has never been kicked (for example the opt-in red team lane with every cadence at 0) now shows as idle instead of "running" forever, and the reviewer autoscaler no longer counts a never-tasked reviewer replica as busy. Both now use one shared check, `crux.Process.TurnInFlight` (#18458). +- A multi-repo hive keeps exactly one `🐝 Hive Advisory Report`, in `project.primary_repo`. A candidate build had started opening an advisory report in every repo of `project.repos`, and posting the digest to each, so every monitored repo got its own report. The per-repo ensure and digest post are removed. The single report is still found by title and the `hive/advisory` label before anything is created, so a restart reuses it rather than filing a new one. Reports already opened in non-primary repos are not reopened by this build and can be closed ([#18568](https://github.com/hivecommons/hive/issues/18568)). +- `needs-sha` now keeps the hive off an issue until the reporter adds a commit SHA, whatever the reporter-trust setting: an issue wearing it (the configured `issues.sha_hold_trusted_label`, default `needs-sha`) leaves every agent work lane, so nothing implements, decomposes or claims it. The SHA-hold sweep removes the label once a SHA appears, which releases the issue. This restores the safety the old `hold` gave after #18542 stopped the hive applying `hold`. The label is created with the description "Waiting on the reporter for the commit SHA; hive won't work this until it's added." + +## 2026-11-17 (v5.291.0) + +### Added + +- Meetings agent-backend mode now answers through `copilot` and `omp` (one tool-less CLI per call with the agents' sign-in, usage charged to the meeting), through `vllm`, `llm-d` and every named model gateway on the OpenAI-compatible path, and on hives that sign Claude in only with `HIVE_CLAUDE_OAUTH_TOKEN`; `codex`, `gemini`, watsonx and the other CLIs are refused at validation and in the Settings picker with the specific reason. + +### Changed + +- Sentinel: in `github.notifications.mode: quiet` (the default) the informational notice on a trusted author's PR (no label, merge not blocked) is now a `sentinel` section of the PR's `hive:status` card, edited in place, instead of a new comment per PR. A sentinel hold (`sentinel-alert` label, maintainer review required), including one from `sentinel.trusted_authors_block`, still posts its own comment, and `normal` mode is unchanged (#18453). +- The hive no longer applies `hold` itself: a PR its ACMM level gate holds for review now gets `ready-for-review`, and items blocked on a human decision (reporter trust, self-authorization, the hold guard's re-hold, owner-only decisions) get `decision-needed`; both block merging exactly like `hold`, carry a label description saying who acts next, and are renameable via `governor.labels.ready_for_review` / `governor.labels.decision_needed`. A `hold` a person adds still means hands-off. On boot the hive swaps the `hold` labels it can prove it applied (App label event plus its gate notice) for the new labels and leaves every other `hold` alone; the SHA-hold sweep now gives every reporter `needs-sha` instead of `hold`. + +## 2026-11-17 (v5.290.0) + +### Added + +- **Owners can approve their own managed repos as prompt and definition sources.** Settings → Security → Prompt sources and the owner-only `GET /api/config/prompt-sources` / `PUT /api/config/prompt-sources/owner-repos` let the hive owner allow one of the hive's `project.repos` for `agents..prompt_source` and `definition_source` without editing the config volume, behind a confirm naming the trust implication (whoever can merge there can steer the agents). Approvals cover that repo only, are audit-logged as `config_prompt_source_repo`, persist to `variables.security.owner_github_prompt_repos` in the PVC runtime config, and lapse if the repo leaves `project.repos`. Non-owners get 403, repos outside the hive are refused, and the seed `github_prompt_allowlist` path is unchanged ([#18490](https://github.com/hivecommons/hive/issues/18490)). +- Long-lived agents can claim a topic for one pull request with `bd topic claim --repo --pr `: the claim is stored in the agent's bead store, a second open claim for the same topic is refused, the kick lists the agent's claims (also as `${TOPIC_CLAIMS}`) so it finds its PR by number after a branch rename, the FIX-BEFORE-NEW and held-PR blocks show the topic next to the PR, and hive releases the claim when the PR merges or closes. +- Sandboxed agent kicks now get hive's own `hive-review` relay on `PATH`. The Job runtime copies it in from the running hive image by digest, through a restricted-SCC-safe init container. Podman bind-mounts it read-only. Project images no longer need to include hive's scripts, only bash and python3, and a kick on an image without them fails with a clear message (#18512). +- Sandboxed reviewers now get the PR they review. Hive fetches `refs/pull/N/head` (fork PRs included) and the PR's base with its clone token and checks the head out on `pr-N`. It writes `.hive/pr/N.json`, marked untrusted, with the PR's metadata, changed files, capped diff and review comments, and names both in the kick prompt. Review kicks never push. ([#18513](https://github.com/hivecommons/hive/issues/18513)) +- Reference repos: new `project.remote_write_identity` (`bot` default, `bot_only`, `owner`) picks whether a hive's writes on a granted remote repo appear as its GitHub App bot (only where the repo's owner installed the App) or as the hive owner's connected account; without the App, `bot` falls back to the owner and `bot_only` stays read-only (#18516). +- Meetings can answer through the hive's own agent backends: `meetings.llm.mode: agent-backend` (or `claude-cli`) runs Betty on a warm, tool-less Claude Code CLI per meeting with `claude-sonnet-5-5` by default and Spek through `hive meeting-llm`, using the agents' sign-in and charging the meeting budget; Settings, Meeting attendee, Model picks the mode, backend and model from the agents' catalog, and the panel shows the model name. +- Hive reviewers can now post findings as inline, line-anchored comments: `hive-review --comments-file` sends the summary and every line comment in one GitHub review, so each finding is its own resolvable thread with a single notification, and a finding whose line is not in the diff is moved into the summary instead of failing the review. +- CEL `triggers:` rules can now match `pr.labeled`: when an already-seen PR gains a label the eval cycle emits it once, with the new labels in `event.added_labels`, so a rule like `event.kind == "pr.labeled" && "hive-review" in event.added_labels` kicks the reviewer right after a maintainer opts a PR into review instead of waiting for its cadence (#18538). +- The dashboard sidebar has a new Collaborate group holding Inbox, Calendar, Meetings and Inception (spek), moved out of Intelligence. +- Inbox: hive recordings get a 🗑 Delete action. It removes the audio stored on the hive, the Inbox item and the recording's Knowledge fact with its transcript, after an in-page confirm that says shared copies (RFCs, issues, DIBS ideas, spek seeds) stay. Owners can delete any recording, read-write members only their own, read members none; each delete is audited as `inbox_recording_delete` (`DELETE /api/inbox/hive-recording/{id}`). + +### Fixed + +- In a hive with several repos, every repo now gets its own governor (advisory) issue and the digest is posted to each, including repos added later in Settings; a repo where the hive cannot create the issue shows a dashboard warning instead of failing silently. +- The agent inference proxy now picks up a rotated LiteLLM or gateway key file without a restart, re-resolves the key and retries once on an upstream 401, and logs `key_source` and `key_changed_since_start` on auth failures; an `api_key_file` outside `/secrets` or `/data/secrets` is now rejected at dashboard/API save with the allowed dirs listed, warned about at boot and once at runtime with the source actually used, and the effective key source is shown in the governor config API and the LiteLLM tab (#18532, #18533). +- Dashboard: the Meetings and Calendar panels wait for the viewer's role instead of telling the owner they are not allowed, say when the hive is unreachable instead of staying on "Loading meetings…", sit inside the dashboard like other sections (they had lost their card padding), and lay out the join form, meeting rows (status pill, platform, time, a plain-language error with the raw one under details) and empty states like the rest of the dashboard. +- Inbox ● Record: the "Saved to the Inbox" panel now follows the recording's item, says "Transcribed. See the item below." (or why transcription failed or is off) and then closes itself with the toast countdown; the item preview shows the plain transcript text instead of the provenance line and untrusted-data envelope; hive recordings and dropped audio files get a plain "Transcript made by this hive with / on ." line; and the player says how long the audio is kept on this hive instead of "the recording is not stored". +- Agent restarts no longer log a warning when tmux has no server or session to kill before relaunching (#18486). + +## 2026-11-16 (v5.289.1) + +### Changed + +- The AGENTS.md injection cap defaults to 32 KiB (was 8 KiB), so a 13 KB AGENTS.md now reaches agents in full; set `repos..agents_md_max_bytes` to override it per repo (hard ceiling 256 KiB) or `HIVE_AGENTS_MD_MAX_BYTES` for the default, the truncation warning is logged once per file change, and `/api/status` repos report each repo's AGENTS.md size and any dropped sections. + +### Fixed + +- Workflow-model repositories no longer flap `stage/020-claimed` every cycle: the in-progress sweep leaves a stage label the bound model derives for the issue (TechDocs "Accepted") in place and does not treat it as a claim, and out-of-cycle stage facts derive through the same bound model as the sweeps (#18434). +- Meetings: hive ships Quorum v0.2.1, which sends Vexa the full join link (`meeting_url`) for Zoom meetings, so sending hive to a Zoom link no longer fails with "unsupported platform 'zoom' without a meeting_url". + +## 2026-11-16 (v5.289.0) + +### Added + +- Settings, Meeting attendee now shows Betty's email address with everyone's calendar emails and proof status, lets each user add, prove and remove their own calendar emails, lists mailed-in files waiting for approval, and lets the owner turn calendar invites and mail-in files on or off. +- Mail Markdown, audio and image files to `hive@` and they land in the Inbox as email items: from an allowlisted calendar email they are routable, shareable and transcribed like voice items; from anyone else they wait for the owner's Approve or Decline. +- The hub sign-in, access-needed and link-preview pages now also show the LF Projects legal footer. +- Every hub page (public pages, fleet views, hosted dashboard, contribute landing and error page) now shows the LF Projects legal footer linking to lfprojects.org/policies/. + +### Fixed + +- Dashboard: the "rejected hub-proxied request with unverified proxy proof" warning is now logged at most once a minute per reason and path (with a suppressed count) instead of once per request; the request is still rejected with 403 (#18377). +- Hub heartbeat collect no longer times out when the PVC scan behind `app_keys_held` stalls: the scan is bounded to 2s and falls back to the last completed result (#18484). +- The scanner (and every repair queue) no longer pushes onto a PR branch the hive App did not open while someone else is working on it ([#18488](https://github.com/hivecommons/hive/issues/18488)). A red or conflicted non-App PR whose head was pushed within `HIVE_SCANNER_BUSY_BRANCH_MINUTES` (default 60), or whose PR or linked issue another worker holds a live claim on, moves from FIX-BEFORE-NEW and the CI_FAILING push queue to a "BUSY BRANCHES — suggest, do not push" list, and the agent posts the fix as one suggestion comment for the worker to apply as its own signed commit. Idle branches, App-authored lane branches and in-place adoptions are listed exactly as before. + +## 2026-11-16 (v5.288.0) + +### Added + +- Gateway spend is priced from the gateway: OpenRouter's catalog prices, LiteLLM `/model/info`, or a new per-gateway `prices:` block (input, cached input, output per 1M tokens). Cached prompt tokens are billed at the cache-read rate. Gateway models with no price show as "price unknown" instead of $0 or a tier guess, and the usage gauge gets a spend row per gateway. +- Inbox recordings are transcribed automatically when you stop, with the hive's transcription provider (auto: the built-in whisper first), with the usual progress bar and time-left estimate. The transcriber reads the recording from the hive's own disk (new `AudioOpener`; no HTTP call to itself). Nothing runs until `inbox.transcription` is enabled with consent; from then on every dashboard recording counts as opted in whatever the mode, and recordings made while it was off are picked up by the transcription sweep. +- Inbox ● Record can record a meeting tab's audio together with the microphone in Chrome and Edge on a computer: you pick the tab and tick "Share tab audio", the video track is dropped, the two are mixed in the browser (Web Audio) and both get a level meter. The consent notice then says remote participants are recorded too and must have been told. Where the browser cannot share tab audio (Safari, Firefox, phones) the option is hidden with the reason, and a share without an audio track warns and records the microphone only. The dashboard document's Permissions-Policy gains `display-capture=(self)`; `/terminal/` and `/api/` keep it closed. +- Drop audio and video onto the Inbox (mp3, m4a, aac, wav, ogg, opus, webm, mp4, mov, checked by container signature): the file streams straight to the hive's disk under the recording size cap (`inbox.recording.max_bytes`, 200 MiB), plays back from disk through the same-origin stream, and is transcribed as soon as it is added when transcription is enabled (otherwise 🎧 Transcribe shows why it is unavailable); the machine transcript lands in the item's Knowledge fact. Originals are deleted after the recordings retention (5 days, `inbox.uploads.media_retention_days` overrides) while the transcript and item stay; video keeps only its audio track. Uploads now get a 20-minute read window instead of the dashboard's 30-second read timeout. +- A weekly workflow compares hive's static model fallbacks and curated OpenRouter suggestions against OpenRouter's public catalog, plus npm release metadata, and keeps one tracking issue listing any drift. A unit test now fails on empty or duplicate static lists and on Go/JS copies that disagree. + +### Fixed + +- Self-upgrade no longer aborts with `cannot unmarshal string "dashboard" into Go value of type json.Number` when the hive container's probes use a named port; named ports are kept in the backfilled startupProbe, and a probe decode problem now skips the backfill with a warning instead of blocking the image upgrade (#18479). ## 2026-11-16 (v5.287.0) diff --git a/bin/hive-open-issue.sh b/bin/hive-open-issue.sh index c9f56e6f74..c430788037 100755 --- a/bin/hive-open-issue.sh +++ b/bin/hive-open-issue.sh @@ -134,6 +134,19 @@ set -euo pipefail REQ_DIR="/var/run/hive-metrics/issue-requests" +# Inside a sandbox (Podman or a Kubernetes Job) the pod-local relay dir is not +# reachable. Hive sets HIVE_SANDBOX_REQUEST_DIR to the kick's request spool and +# HIVE_SANDBOX_SPOOL_KEY to a per-run key (hivecommons/hive#18573); the request +# is then written there as {"kind": "issue", "request": "", +# "mac": ""}. The relay runs it +# through the same issue handler and gates, attributed to the kick's own agent +# whatever "agent" says. The older HIVE_REVIEW_* names are accepted too. +SPOOL_DIR="${HIVE_SANDBOX_REQUEST_DIR:-${HIVE_REVIEW_REQUEST_DIR:-}}" +SPOOL_KEY="${HIVE_SANDBOX_SPOOL_KEY:-${HIVE_REVIEW_SPOOL_KEY:-}}" +if [ -n "$SPOOL_DIR" ] && [ -n "$SPOOL_KEY" ]; then + REQ_DIR="$SPOOL_DIR" + export HIVE_OPEN_ISSUE_SPOOL_KEY="$SPOOL_KEY" +fi KIND="issue" case "${1:-}" in @@ -535,8 +548,16 @@ if dry_run == "1": print("hive-open-issue: DRY RUN — no request written, nothing will be created. Would write %s:" % path) print(json.dumps(req, indent=2)) sys.exit(0) +data = json.dumps(req) +# Sandbox spool: sign for this run. Read from the environment, never argv: +# argv is visible to every user. +key = os.environ.get("HIVE_OPEN_ISSUE_SPOOL_KEY", "") +if key: + import hashlib, hmac + mac = hmac.new(key.encode(), ("issue\n" + data).encode(), hashlib.sha256).hexdigest() + data = json.dumps({"kind": "issue", "request": data, "mac": mac}) with open(temporary, "w") as fh: - json.dump(req, fh) + fh.write(data) os.replace(temporary, path) PY diff --git a/bin/hive-review.sh b/bin/hive-review.sh index f6490b911f..675828716e 100755 --- a/bin/hive-review.sh +++ b/bin/hive-review.sh @@ -28,6 +28,16 @@ # hive, not by any agent uid. Post the comment WITHOUT a verdict and the comment # is all that survives — nothing is routed, nothing is labeled. # +# Inline findings (hivecommons/hive#18531) — one review, N line threads: +# hive-review --repo --comment --body-file \ +# --comments-file --verdict-file +# is a JSON array of {"path","line","body"} objects, optionally with +# "side" ("RIGHT", the PR head, by default; "LEFT" for a deleted line) and +# "start_line" for a multi-line range. The hive submits the summary and every +# comment in ONE GitHub review, so the PR gets one notification and each +# finding becomes its own resolvable thread. A comment whose line is not in +# the PR diff is moved into the summary instead of failing the review. +# # Nothing worth commenting on? Record the verdict anyway — an unrecorded # judgement reads downstream as "never reviewed", so the PR comes back forever: # hive-review --repo --record-verdict --verdict-file @@ -59,6 +69,7 @@ set -euo pipefail REQ_DIR="${HIVE_REVIEW_REQUEST_DIR:-/var/run/hive-metrics/review-requests}" REPO=""; NUMBER=""; EVENT=""; BODY=""; BODY_FILE=""; THREAD=""; VERDICT_FILE=""; VERDICT=""; REVISE=0 +COMMENTS_FILE=""; COMMENTS="" while [ $# -gt 0 ]; do case "$1" in --repo|-R) REPO="$2"; shift 2;; @@ -69,6 +80,8 @@ while [ $# -gt 0 ]; do --body-file=*) BODY_FILE="${1#*=}"; shift;; --verdict-file) VERDICT_FILE="$2"; shift 2;; --verdict-file=*) VERDICT_FILE="${1#*=}"; shift;; + --comments-file) COMMENTS_FILE="$2"; shift 2;; + --comments-file=*) COMMENTS_FILE="${1#*=}"; shift;; --approve|-a) EVENT="approve"; shift;; --request-changes|-r) EVENT="request_changes"; shift;; --comment|-c) EVENT="comment"; shift;; @@ -112,6 +125,15 @@ if [ -n "$VERDICT_FILE" ]; then fi fi +if [ -n "$COMMENTS_FILE" ]; then + if [ -f "$COMMENTS_FILE" ]; then + COMMENTS="$(cat "$COMMENTS_FILE")" + else + echo "hive-review: comments file not found: $COMMENTS_FILE" >&2 + exit 2 + fi +fi + if [ -z "$REPO" ] || [ -z "$NUMBER" ] || [ -z "$EVENT" ]; then echo "hive-review: --repo, a PR number (or URL), and one of --approve/--request-changes/--comment/--resolve-thread/--record-verdict are required" >&2 exit 2 @@ -128,6 +150,10 @@ if [ -n "$THREAD" ] && [ "$EVENT" != "comment" ] && [ "$EVENT" != "resolve_threa echo "hive-review: --thread only applies to --comment (in-thread reply) or --resolve-thread" >&2 exit 2 fi +if [ -n "$COMMENTS" ] && { [ -n "$THREAD" ] || [ "$EVENT" = "resolve_thread" ] || [ "$EVENT" = "record_verdict" ]; }; then + echo "hive-review: --comments-file only applies to a PR-level review (--comment/--approve/--request-changes)" >&2 + exit 2 +fi if [ "$EVENT" != "approve" ] && [ "$EVENT" != "resolve_thread" ] && [ "$EVENT" != "record_verdict" ] && [ -z "$BODY" ]; then echo "hive-review: --request-changes and --comment require --body" >&2 exit 2 @@ -157,9 +183,9 @@ if ! command -v python3 >/dev/null 2>&1; then exit 1 fi -python3 - "$TEMP_FILE" "$REQ_FILE" "$REPO" "$NUMBER" "$EVENT" "$BODY" "$AGENT" "$THREAD" "$VERDICT" "$REVISE" <<'PY' +python3 - "$TEMP_FILE" "$REQ_FILE" "$REPO" "$NUMBER" "$EVENT" "$BODY" "$AGENT" "$THREAD" "$VERDICT" "$REVISE" "$COMMENTS" <<'PY' import json, os, sys -temporary, path, repo, number, event, body, agent, thread, verdict, revise = sys.argv[1:11] +temporary, path, repo, number, event, body, agent, thread, verdict, revise, comments = sys.argv[1:12] req = {"repo": repo, "number": int(number), "event": event, "agent": agent} if revise == "1": req["revise"] = True @@ -205,6 +231,47 @@ if verdict.strip(): % (i, obj.get("repo"), obj.get("number"), repo, number)) raise SystemExit(2) req["report"] = verdict +if comments.strip(): + # Same checks the relay makes, so a bad file fails here with the fix + # named instead of quarantining the whole review server-side. + try: + parsed = json.loads(comments) + except ValueError as exc: + sys.stderr.write("hive-review: --comments-file is not valid JSON: %s\n" % exc) + raise SystemExit(2) + if not isinstance(parsed, list): + sys.stderr.write("hive-review: --comments-file must hold a JSON array of {\"path\",\"line\",\"body\"} objects\n") + raise SystemExit(2) + out = [] + for i, c in enumerate(parsed): + if not isinstance(c, dict): + sys.stderr.write("hive-review: comment %d is not a JSON object\n" % i) + raise SystemExit(2) + p, line, text = c.get("path"), c.get("line"), c.get("body") + if not isinstance(p, str) or not p.strip() or p.startswith("/"): + sys.stderr.write("hive-review: comment %d needs a repository-relative \"path\"\n" % i) + raise SystemExit(2) + if not isinstance(line, int) or isinstance(line, bool) or line <= 0: + sys.stderr.write("hive-review: comment %d needs a positive integer \"line\"\n" % i) + raise SystemExit(2) + if not isinstance(text, str) or not text.strip(): + sys.stderr.write("hive-review: comment %d needs a non-empty \"body\"\n" % i) + raise SystemExit(2) + item = {"path": p, "line": line, "body": text} + side = str(c.get("side", "RIGHT") or "RIGHT").upper() + if side not in ("RIGHT", "LEFT"): + sys.stderr.write("hive-review: comment %d \"side\" must be RIGHT or LEFT\n" % i) + raise SystemExit(2) + item["side"] = side + start = c.get("start_line") + if start not in (None, 0): + if not isinstance(start, int) or isinstance(start, bool) or start <= 0 or start >= line: + sys.stderr.write("hive-review: comment %d \"start_line\" must be a positive integer below \"line\"\n" % i) + raise SystemExit(2) + item["start_line"] = start + out.append(item) + if out: + req["comments"] = out data = json.dumps(req) # Read from the environment, never argv: argv is visible to every user. key = os.environ.get("HIVE_REVIEW_SPOOL_KEY", "") @@ -223,6 +290,8 @@ elif [ -n "$THREAD" ]; then echo "hive-review: requested $EVENT on thread $THREAD of $REPO#$NUMBER as the App bot" elif [ "$REVISE" = "1" ]; then echo "hive-review: requested revision of the existing review on $REPO#$NUMBER (edits in place; no notification)" +elif [ -n "$COMMENTS" ]; then + echo "hive-review: requested $EVENT review with inline comments on $REPO#$NUMBER as the App bot (one review, one notification)" else echo "hive-review: requested $EVENT review on $REPO#$NUMBER as the App bot" fi diff --git a/bin/hive-topic.sh b/bin/hive-topic.sh new file mode 100755 index 0000000000..92765526e2 --- /dev/null +++ b/bin/hive-topic.sh @@ -0,0 +1,184 @@ +#!/bin/bash +# hive-topic.sh — read and write your topic claims from anywhere, sandbox included. +# +# A topic claim is a durable "this topic is mine, through this PR" record in +# the agent's own bead store (`bd topic`, hivecommons/hive#18493). In the hive +# pod this script simply runs `bd topic` with the same arguments. Inside a +# sandbox (a Podman container or a Kubernetes Job) neither `bd` nor the bead +# store exists, so it writes a signed request into the kick's request spool +# instead, waits for hive's reply and prints it (hivecommons/hive#18572). Hive +# applies the request to the bead store of the agent the kick belongs to, +# whatever this script says about who is asking. +# +# Usage (the same as `bd topic`): +# hive-topic claim [--repo owner/name] [--pr N] [--branch B] +# hive-topic get [--json] +# hive-topic list [--json] +# hive-topic release +# +# In a sandbox, `claim ` WITHOUT --pr claims the pull request hive opens +# from this kick: a sandbox has no PR number yet, so hive records the claim as +# pending on the kick's branch and binds it to the PR once it is open. --repo +# defaults to the kick's repository. Pass --pr when the PR already exists. +# +# Sandbox-only flags: --no-wait returns as soon as the request is written +# (the result appears at .result.json); --timeout bounds the wait +# (default $HIVE_TOPIC_WAIT_SECONDS, else 120). +# +# Exit codes, as `bd topic`: 0 success, 1 usage or store error (or no reply in +# time), 2 refused (the topic is held through a different PR) or not found on +# get. + +set -euo pipefail + +# The kick's spool and its per-run key (hivecommons/hive#18572). The older +# HIVE_REVIEW_* names are accepted too. +SPOOL_DIR="${HIVE_SANDBOX_REQUEST_DIR:-${HIVE_REVIEW_REQUEST_DIR:-}}" +SPOOL_KEY="${HIVE_SANDBOX_SPOOL_KEY:-${HIVE_REVIEW_SPOOL_KEY:-}}" + +if [ -z "$SPOOL_DIR" ] || [ -z "$SPOOL_KEY" ]; then + # In-pod: the bead store is right here. + if ! command -v bd >/dev/null 2>&1; then + echo "hive-topic: no sandbox spool (HIVE_SANDBOX_REQUEST_DIR/HIVE_SANDBOX_SPOOL_KEY unset) and no bd on PATH" >&2 + exit 1 + fi + exec bd topic "$@" +fi + +if ! command -v python3 >/dev/null 2>&1; then + echo "hive-topic: python3 is required to encode the topic request" >&2 + exit 1 +fi + +AGENT="${HIVE_AGENT:-agent}" +mkdir -p "$SPOOL_DIR" 2>/dev/null || true +REQ_FILE="$SPOOL_DIR/${AGENT//[^A-Za-z0-9_.-]/_}-topic-$(date +%s%N).json" + +export HIVE_TOPIC_SPOOL_KEY="$SPOOL_KEY" +exec python3 - "$REQ_FILE" "$AGENT" "${HIVE_TOPIC_WAIT_SECONDS:-120}" "$@" <<'PY' +import hashlib, hmac, json, os, sys, time + +USAGE = """Usage: + hive-topic claim [--repo owner/name] [--pr N] [--branch B] + hive-topic get [--json] + hive-topic list [--json] + hive-topic release """ + +path, agent, wait = sys.argv[1], sys.argv[2], sys.argv[3] +args = sys.argv[4:] + +def die(msg, code=1): + sys.stderr.write("hive-topic: %s\n" % msg) + sys.exit(code) + +if not args: + die("a subcommand is required\n" + USAGE) +op, rest = args[0], args[1:] +if op not in ("claim", "get", "list", "release"): + die("unknown subcommand %r\n%s" % (op, USAGE)) + +req = {"op": op, "agent": agent} +if op != "list": + if not rest or not rest[0] or rest[0].startswith("-"): + die("%s requires a topic key" % op) + req["key"], rest = rest[0], rest[1:] + +as_json, no_wait = False, False +try: + wait_s = float(wait) +except ValueError: + die("HIVE_TOPIC_WAIT_SECONDS must be a number, got %r" % wait) +i = 0 +while i < len(rest): + a = rest[i] + name, _, inline = a.partition("=") + def value(): + global i + if inline: + return inline + i += 1 + if i >= len(rest): + die("%s needs a value" % name) + return rest[i] + if name in ("--repo", "-R") and op == "claim": + req["repo"] = value() + elif name == "--pr" and op == "claim": + v = value() + if not v.isdigit() or int(v) <= 0: + die("--pr expects a positive pull request number, got %r" % v) + req["pr"] = int(v) + elif name == "--branch" and op == "claim": + req["branch"] = value() + elif name == "--actor" and op == "claim": + value() # accepted for bd compatibility; hive attributes the claim itself + elif name == "--json" and op in ("get", "list"): + as_json = True + elif name == "--no-wait": + no_wait = True + elif name == "--timeout": + v = value() + try: + wait_s = float(v) + except ValueError: + die("--timeout expects seconds, got %r" % v) + else: + die("unknown flag %r for %s; nothing was written\n%s" % (a, op, USAGE)) + i += 1 + +data = json.dumps(req) +# Read from the environment, never argv: argv is visible to every user. +key = os.environ.get("HIVE_TOPIC_SPOOL_KEY", "") +mac = hmac.new(key.encode(), ("topic\n" + data).encode(), hashlib.sha256).hexdigest() +tmp = path + ".tmp" +with open(tmp, "w") as fh: + fh.write(json.dumps({"kind": "topic", "request": data, "mac": mac})) +os.replace(tmp, path) + +result = path[:-len(".json")] + ".result.json" +if no_wait: + print("hive-topic: request %s (result appears at %s)" % (path, result)) + sys.exit(0) + +deadline = time.time() + wait_s +resp = None +while time.time() < deadline: + try: + with open(result) as fh: + resp = json.load(fh) + break + except (OSError, ValueError): + time.sleep(1) +if resp is None: + die("no reply from hive within %gs; the request stays queued at %s and its result will appear at %s" % (wait_s, path, result)) + +def line(c): + pr = "#%d" % c["pr"] if c.get("pr") else " (PR not opened yet)" + s = "%s -> %s%s" % (c.get("key", ""), c.get("repo", ""), pr) + if c.get("branch"): + s += " branch %s" % c["branch"] + return s + +if not resp.get("ok"): + if resp.get("claim"): + sys.stderr.write("hive-topic: held: %s\n" % line(resp["claim"])) + die(resp.get("error") or "request refused", 2 if resp.get("refused") else 1) +if op == "list": + claims = resp.get("claims") or [] + if as_json: + print(json.dumps(claims, indent=2)) + elif not claims: + print("no open topic claims") + else: + for c in claims: + print(line(c)) +elif op == "release": + print("released %s" % req["key"] if resp.get("released") else "no open claim for %s" % req["key"]) +else: + c = resp.get("claim") or {} + if as_json: + print(json.dumps(c, indent=2)) + elif op == "claim": + print("claimed %s" % line(c)) + else: + print(line(c)) +PY diff --git a/bin/test_hive_open_issue.sh b/bin/test_hive_open_issue.sh index a346808f0e..06fe880ac3 100755 --- a/bin/test_hive_open_issue.sh +++ b/bin/test_hive_open_issue.sh @@ -755,6 +755,52 @@ check "repo inside HIVE_REPOS (case-insensitive) is written" "1" "$(find "$REQ_D env HIVE_AGENT=cfgbot HIVE_REPOS="org/repo" bash "$MODIFIED_SCRIPT" --repo org/repo --title t --body b >/dev/null 2>&1 || true check "configured placeholder-looking repo is accepted" "1" "$(find "$REQ_DIR" -name 'cfgbot-*.json' | wc -l | tr -d ' ')" +# --- sandbox spool (hivecommons/hive#18573) --- +# Runs the UNMODIFIED script: the spool redirect is the script's own behavior. +echo "" +echo "--- sandbox spool via HIVE_SANDBOX_REQUEST_DIR ---" +ISSUE_SPOOL="$TMPDIR_ROOT/workspace/.hive/review-requests" +ISSUE_KEY="0123456789abcdef0123456789abcdef" +env HIVE_AGENT="spoolbot" HIVE_SANDBOX_REQUEST_DIR="$ISSUE_SPOOL" HIVE_SANDBOX_SPOOL_KEY="$ISSUE_KEY" \ + bash "$SCRIPT" --repo hiveorg/widgets --title "dependency X breaks us" --body "detail" >/dev/null 2>&1 || true +ISSUE_FILES=("$ISSUE_SPOOL"/spoolbot-*.json) +if [ -f "${ISSUE_FILES[0]}" ]; then + check "spooled envelope kind is issue" "issue" "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["kind"])' "${ISSUE_FILES[0]}")" + # The relay recomputes HMAC-SHA256(key, "issue\n" + request): the kind is bound. + check "envelope MAC binds the issue kind" "ok" "$(python3 -c ' +import hashlib, hmac, json, sys +env = json.load(open(sys.argv[1])) +want = hmac.new(sys.argv[2].encode(), ("issue\n" + env["request"]).encode(), hashlib.sha256).hexdigest() +print("ok" if hmac.compare_digest(env["mac"], want) else "bad")' "${ISSUE_FILES[0]}" "$ISSUE_KEY")" + check "spooled request carries the title" "dependency X breaks us" "$(python3 -c 'import json,sys; print(json.loads(json.load(open(sys.argv[1]))["request"])["title"])' "${ISSUE_FILES[0]}")" + if grep -q "$ISSUE_KEY" "${ISSUE_FILES[0]}"; then + echo " FAIL: the spool key itself was written into the spool"; FAIL=$((FAIL + 1)) + else + echo " PASS: the spool key is not in the spool file"; PASS=$((PASS + 1)) + fi +else + echo " FAIL: issue request not written to HIVE_SANDBOX_REQUEST_DIR"; FAIL=$((FAIL + 4)) +fi + +echo "" +echo "--- sandbox spool via the older HIVE_REVIEW_* names ---" +OLD_SPOOL="$TMPDIR_ROOT/old/.hive/review-requests" +env HIVE_AGENT="oldbot" HIVE_REVIEW_REQUEST_DIR="$OLD_SPOOL" HIVE_REVIEW_SPOOL_KEY="$ISSUE_KEY" \ + bash "$SCRIPT" comment --repo hiveorg/widgets 41 --body "note" >/dev/null 2>&1 || true +OLD_FILES=("$OLD_SPOOL"/oldbot-*.json) +if [ -f "${OLD_FILES[0]}" ]; then + check "older env names spool a signed comment" "issue comment" "$(python3 -c 'import json,sys; e=json.load(open(sys.argv[1])); print(e["kind"], json.loads(e["request"])["kind"])' "${OLD_FILES[0]}")" +else + echo " FAIL: comment not written to HIVE_REVIEW_REQUEST_DIR"; FAIL=$((FAIL + 1)) +fi + +echo "" +echo "--- a spool dir without a key is not a spool ---" +NOKEY_SPOOL="$TMPDIR_ROOT/nokey/.hive/review-requests" +env HIVE_AGENT="nokeybot" HIVE_SANDBOX_REQUEST_DIR="$NOKEY_SPOOL" bash "$MODIFIED_SCRIPT" --repo hiveorg/widgets --title t --body b >/dev/null 2>&1 || true +check "no key: nothing written to the spool dir" "0" "$(find "$TMPDIR_ROOT/nokey" -name 'nokeybot-*.json' 2>/dev/null | wc -l | tr -d ' ')" +check "no key: the pod-local request is plain JSON" "issue" "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("kind",""))' "$(find "$REQ_DIR" -name 'nokeybot-*.json' | head -1)")" + echo "" echo "=== $PASS passed, $FAIL failed ===" [ "$FAIL" -eq 0 ] diff --git a/bin/test_hive_review.sh b/bin/test_hive_review.sh index 67fb8995e6..c21bd876e5 100755 --- a/bin/test_hive_review.sh +++ b/bin/test_hive_review.sh @@ -201,6 +201,38 @@ else echo " FAIL: signed request not written to HIVE_REVIEW_REQUEST_DIR"; FAIL=$((FAIL + 3)) fi +# --- inline comments (hivecommons/hive#18531) --- +echo "" +echo "--- --comments-file carries line-anchored findings ---" +CDIR="$TMPDIR_ROOT/comments"; mkdir -p "$CDIR" +printf '%s' '[{"path":"a.go","line":3,"body":"x"},{"path":"b.go","line":9,"start_line":7,"side":"left","body":"y"}]' > "$CDIR/ok.json" +run_script inliner 31 --repo org/repo --comment --body "summary" --comments-file "$CDIR/ok.json" >/dev/null || true +INLINE_REQ="$(find_req inliner || true)" +if [ -n "$INLINE_REQ" ]; then + check "two comments relayed" "2" "$(python3 -c 'import json,sys; print(len(json.load(open(sys.argv[1]))["comments"]))' "$INLINE_REQ")" + check "side defaults to RIGHT" "RIGHT" "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["comments"][0]["side"])' "$INLINE_REQ")" + check "side is upper-cased and range kept" "LEFT 7" "$(python3 -c 'import json,sys; c=json.load(open(sys.argv[1]))["comments"][1]; print(c["side"], c["start_line"])' "$INLINE_REQ")" +else + echo " FAIL: inline request not written"; FAIL=$((FAIL + 3)) +fi +printf '%s' '{"path":"a.go"}' > "$CDIR/notarray.json" +printf '%s' '[{"path":"/abs","line":1,"body":"x"}]' > "$CDIR/abs.json" +printf '%s' '[{"path":"a","line":0,"body":"x"}]' > "$CDIR/line.json" +printf '%s' '[{"path":"a","line":2,"body":" "}]' > "$CDIR/body.json" +printf '%s' '[{"path":"a","line":2,"side":"up","body":"x"}]' > "$CDIR/side.json" +printf '%s' '[{"path":"a","line":2,"start_line":2,"body":"x"}]' > "$CDIR/range.json" +printf '%s' 'not json' > "$CDIR/bad.json" +for f in notarray abs line body side range bad; do + check_exit "comments file '$f' is refused" 2 \ + env HIVE_AGENT=x bash "$MODIFIED_SCRIPT" --repo org/repo 31 --comment --body s --comments-file "$CDIR/$f.json" +done +check_exit "missing comments file exits 2" 2 \ + env HIVE_AGENT=x bash "$MODIFIED_SCRIPT" --repo org/repo 31 --comment --body s --comments-file "$CDIR/nope.json" +check_exit "comments with --record-verdict exits 2" 2 \ + env HIVE_AGENT=x bash "$MODIFIED_SCRIPT" --repo org/repo 31 --record-verdict --verdict-file "$CDIR/ok.json" --comments-file "$CDIR/ok.json" +check_exit "comments with --thread exits 2" 2 \ + env HIVE_AGENT=x bash "$MODIFIED_SCRIPT" --repo org/repo 31 --comment --body s --thread PRRT_x --comments-file "$CDIR/ok.json" + echo "" echo "=== $PASS passed, $FAIL failed ===" [ "$FAIL" -eq 0 ] diff --git a/bin/test_hive_topic.sh b/bin/test_hive_topic.sh new file mode 100755 index 0000000000..420f4f93f8 --- /dev/null +++ b/bin/test_hive_topic.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash +# Tests for bin/hive-topic.sh — topic claims from the hive pod or a sandbox +# (hivecommons/hive#18572). +# +# Run: bash bin/test_hive_topic.sh +set -euo pipefail + +PASS=0 +FAIL=0 + +SCRIPT="$(cd "$(dirname "$0")" && pwd)/hive-topic.sh" + +check() { + local label="$1" want="$2" got="$3" + if [ "$want" = "$got" ]; then + echo " PASS: $label"; PASS=$((PASS + 1)) + else + echo " FAIL: $label"; echo " want: '$want'"; echo " got: '$got'"; FAIL=$((FAIL + 1)) + fi +} + +echo "=== hive-topic.sh tests ===" + +TMPDIR_ROOT="$(mktemp -d)" +trap 'rm -rf "$TMPDIR_ROOT"' EXIT +KEY="0123456789abcdef0123456789abcdef" +SPOOL="$TMPDIR_ROOT/workspace/.hive/review-requests" + +# Run the relay as a sandbox would, with the spool and key in its env. +in_sandbox() { env HIVE_AGENT=deps HIVE_SANDBOX_REQUEST_DIR="$SPOOL" HIVE_SANDBOX_SPOOL_KEY="$KEY" bash "$SCRIPT" "$@"; } +newest() { { ls -t "$SPOOL"/deps-topic-*.json 2>/dev/null || true; } | { grep -v '\.result\.json$' || true; } | head -1; } +reqfield() { python3 -c 'import json,sys; print(json.loads(json.load(open(sys.argv[1]))["request"]).get(sys.argv[2], ""))' "$1" "$2"; } + +echo "" +echo "--- in-pod: runs bd topic ---" +FAKEBIN="$TMPDIR_ROOT/bin"; mkdir -p "$FAKEBIN" +printf '#!/bin/sh\necho "bd $*"\n' > "$FAKEBIN/bd"; chmod +x "$FAKEBIN/bd" +check "no spool env execs bd topic with the same args" "bd topic get deps-bump --json" \ + "$(env -u HIVE_SANDBOX_REQUEST_DIR -u HIVE_REVIEW_REQUEST_DIR PATH="$FAKEBIN:$PATH" bash "$SCRIPT" get deps-bump --json)" +check "a spool dir without a key is not a spool" "bd topic list" \ + "$(env HIVE_SANDBOX_REQUEST_DIR="$SPOOL" PATH="$FAKEBIN:$PATH" bash "$SCRIPT" list)" + +echo "" +echo "--- sandbox: claim without --pr is written signed, kind topic ---" +in_sandbox claim deps-bump --no-wait >/dev/null +REQ="$(newest)" +if [ -n "$REQ" ]; then + check "envelope kind is topic" "topic" "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["kind"])' "$REQ")" + check "envelope MAC binds the topic kind" "ok" "$(python3 -c ' +import hashlib, hmac, json, sys +env = json.load(open(sys.argv[1])) +want = hmac.new(sys.argv[2].encode(), ("topic\n" + env["request"]).encode(), hashlib.sha256).hexdigest() +print("ok" if hmac.compare_digest(env["mac"], want) else "bad")' "$REQ" "$KEY")" + check "op is claim" "claim" "$(reqfield "$REQ" op)" + check "key is carried" "deps-bump" "$(reqfield "$REQ" key)" + check "no pr: hive binds the kick's PR" "" "$(reqfield "$REQ" pr)" + if grep -q "$KEY" "$REQ"; then + echo " FAIL: the spool key was written into the spool"; FAIL=$((FAIL + 1)) + else + echo " PASS: the spool key is not in the spool file"; PASS=$((PASS + 1)) + fi +else + echo " FAIL: no topic request in the spool"; FAIL=$((FAIL + 6)) +fi +rm -f "$SPOOL"/*.json + +in_sandbox claim deps-bump --repo acme/widget --pr 42 --branch bump --no-wait >/dev/null +REQ="$(newest)" +check "explicit pr, repo and branch" "42 acme/widget bump" "$(reqfield "$REQ" pr) $(reqfield "$REQ" repo) $(reqfield "$REQ" branch)" +rm -f "$SPOOL"/*.json + +echo "" +echo "--- sandbox: usage errors write nothing ---" +rc=0; in_sandbox claim >/dev/null 2>&1 || rc=$? +check "claim without a key exits 1" "1" "$rc" +rc=0; in_sandbox claim k --pr nope >/dev/null 2>&1 || rc=$? +check "non-numeric --pr exits 1" "1" "$rc" +rc=0; in_sandbox frobnicate >/dev/null 2>&1 || rc=$? +check "unknown subcommand exits 1" "1" "$rc" +rc=0; in_sandbox get k --bogus >/dev/null 2>&1 || rc=$? +check "unknown flag exits 1" "1" "$rc" +check "nothing was written" "0" "$(find "$SPOOL" -name '*.json' | wc -l | tr -d ' ')" + +# reply answers the newest request with $1 once it appears, as the relay does. +reply() { + ( for _ in $(seq 1 50); do + r="$(newest)" + if [ -n "$r" ]; then printf '%s' "$1" > "${r%.json}.result.json"; exit 0; fi + sleep 0.1 + done ) & +} + +echo "" +echo "--- sandbox: waits for hive's reply ---" +reply '{"ok":true,"pending":true,"claim":{"key":"deps-bump","repo":"acme/widget","pr":0,"branch":"hive/deps-1"}}' +OUT="$(in_sandbox claim deps-bump --timeout 10)"; wait +check "pending claim is reported" "claimed deps-bump -> acme/widget (PR not opened yet) branch hive/deps-1" "$OUT" +rm -f "$SPOOL"/*.json + +reply '{"ok":false,"refused":true,"error":"topic already claimed","claim":{"key":"deps-bump","repo":"acme/widget","pr":7}}' +rc=0; in_sandbox claim deps-bump --pr 9 --timeout 10 >/dev/null 2>&1 || rc=$?; wait +check "a refused claim exits 2" "2" "$rc" +rm -f "$SPOOL"/*.json + +reply '{"ok":false,"error":"authorization denied: no topic store configured (fail closed)"}' +rc=0; in_sandbox release deps-bump --timeout 10 >/dev/null 2>&1 || rc=$?; wait +check "an error exits 1" "1" "$rc" +rm -f "$SPOOL"/*.json + +reply '{"ok":true,"claims":[{"key":"a","repo":"acme/widget","pr":3},{"key":"b","repo":"acme/widget","pr":4}]}' +check "list prints every claim" "2" "$(in_sandbox list --json --timeout 10 | python3 -c 'import json,sys; print(len(json.load(sys.stdin)))')"; wait +rm -f "$SPOOL"/*.json + +rc=0; in_sandbox get deps-bump --timeout 1 >/dev/null 2>&1 || rc=$? +check "no reply in time exits 1" "1" "$rc" + +echo "" +echo "=== $PASS passed, $FAIL failed ===" +[ "$FAIL" -eq 0 ] diff --git a/changelog.d/added-18448-advisory-report-every-repo.md b/changelog.d/added-18448-advisory-report-every-repo.md new file mode 100644 index 0000000000..893c328534 --- /dev/null +++ b/changelog.d/added-18448-advisory-report-every-repo.md @@ -0,0 +1 @@ +- New owner setting **Advisory report in every repo** (Settings, Governor Config, Advisory; `governor.advisory.per_repo`, default off, `HIVE_ADVISORY_PER_REPO` sets the default when the key is absent). Off keeps one Hive Advisory Report in the primary repo covering all repos. On, each monitored repo also gets exactly one report, found by title plus the `hive/advisory` label or a hive marker so a restart never files a second; a report a person closed is left closed and no longer posted to; repos with Issues disabled or no write access are skipped with one warning. Turning it off stops updating those reports without closing them ([#18448](https://github.com/hivecommons/hive/issues/18448)). diff --git a/changelog.d/added-18494-release-feed-watcher.md b/changelog.d/added-18494-release-feed-watcher.md new file mode 100644 index 0000000000..71a1a62317 --- /dev/null +++ b/changelog.d/added-18494-release-feed-watcher.md @@ -0,0 +1 @@ +- **Release-feed watcher: kick an agent when a tracked upstream dependency releases.** `governor.release_feeds.agents..sources` lists GitHub releases or tags (`owner/repo`), PyPI packages, or a generic index URL. The governor polls them every `interval_s` (default `HIVE_RELEASE_FEED_INTERVAL`, else 15 minutes) with `If-None-Match` / `If-Modified-Since`, through the spoke's upstream-proxy rules, and keeps last-seen versions in `/data/release-feeds.json`. A new version queues a kick for the subscribed agent through the kick queue with a `${NEW_RELEASES}` block (package, old, new, URL) and records the reason on the governor kick-history entry; the first answer is a baseline and an unchanged feed kicks nothing. Kicks pass the same gates as the webhook CI-failure kick and are bounded by a per-agent cooldown (default `HIVE_RELEASE_FEED_COOLDOWN`, else 1 hour). Private indexes authenticate with `auth_var`, an existing per-agent or hive-level variable whose value is never logged. See `src/docs/release-feeds.md` ([#18494](https://github.com/hivecommons/hive/issues/18494)). diff --git a/changelog.d/added-18516-remote-write-identity-settings.md b/changelog.d/added-18516-remote-write-identity-settings.md new file mode 100644 index 0000000000..c4472712a9 --- /dev/null +++ b/changelog.d/added-18516-remote-write-identity-settings.md @@ -0,0 +1 @@ +- Settings → Repos → Reference repos: owner-only "Post on other projects as" control (Hive bot, falling back to me / Hive bot only / Me) for `project.remote_write_identity`, a per-repo line saying which identity posts there and why, `PUT /api/config/reference-repos/write-identity`, and the docs (#18516). diff --git a/changelog.d/added-18564-mailin-body-video-size.md b/changelog.d/added-18564-mailin-body-video-size.md new file mode 100644 index 0000000000..9281eed732 --- /dev/null +++ b/changelog.d/added-18564-mailin-body-video-size.md @@ -0,0 +1 @@ +- Mail-in to `hive@` now accepts a plain-text or HTML body as a Markdown note (a body-only mail becomes a `message.md` Inbox item), accepts `.mp4`, `.mov` and `.mkv` video (MP4 and QuickTime audio is transcribed), and raises the SMTP SIZE limit to 35 MiB with 25 MB per file; hive-mx spools mail to disk, the hub relays large deliveries to the spoke in signed pieces under the 1 MiB ingress limit, and each hive gets a daily byte budget (#18564). diff --git a/changelog.d/added-18572-sandbox-issue-topic-spool.md b/changelog.d/added-18572-sandbox-issue-topic-spool.md new file mode 100644 index 0000000000..d11c13cb4a --- /dev/null +++ b/changelog.d/added-18572-sandbox-issue-topic-spool.md @@ -0,0 +1 @@ +- **Sandboxed agents can open issues and keep topic claims.** The sandbox request spool now carries `issue` and `topic` requests as well as reviews, signed with the same per-kick key and attributed to the kick's own agent. `hive-open-issue` and the new `hive-topic` relay ship on every sandbox's `PATH` and write to the spool when they run in a sandbox. Issue requests go through the issue relay with all its gates (ACMM mode, lane write allowlist, repo scope, dedupe by title, canary scan, audit); topic requests land in the agent's own bead store, and `hive-topic claim ` without `--pr` claims the PR hive opens from the kick. `hive-review` is unchanged. ([#18572](https://github.com/hivecommons/hive/issues/18572), [#18573](https://github.com/hivecommons/hive/issues/18573)) diff --git a/changelog.d/added-18574-sandbox-existing-pr.md b/changelog.d/added-18574-sandbox-existing-pr.md new file mode 100644 index 0000000000..0e7cbd518a --- /dev/null +++ b/changelog.d/added-18574-sandbox-existing-pr.md @@ -0,0 +1 @@ +- **Sandboxed fix kicks push to the agent's own existing PR, and sandbox-opened PRs are credited to their agent.** A sandboxed kick that names one of the agent's open PRs (an explicit `[hive:target-pr #]` line, the red-PR or red-CI kick header, the first FIX-BEFORE-NEW row, or a single topic claim) checks out that PR's head branch and adds its commits there. Hive pushes only if the PR is open, same-repo, opened by this hive for this agent, still at the head the kick checked out (`--force-with-lease`), and the usual broker scans pass; otherwise the kick fails with the reason and nothing is pushed. A PR a sandboxed kick opens now gets the attribution trailer and `agent_pr_created` audit entry a relay-opened PR gets, so red CI on it kicks the agent that opened it instead of `scanner`. ([#18574](https://github.com/hivecommons/hive/issues/18574), [#18575](https://github.com/hivecommons/hive/issues/18575)) diff --git a/changelog.d/added-18579-proof-failure-reason.md b/changelog.d/added-18579-proof-failure-reason.md new file mode 100644 index 0000000000..35ed18fc17 --- /dev/null +++ b/changelog.d/added-18579-proof-failure-reason.md @@ -0,0 +1 @@ +- **A calendar email whose proof mail was refused now says why** under **Settings, Meeting attendee, My calendar emails**, instead of only "pending": the reason in plain words with what to do (not authenticated by the sender's mail server, sent from a different address, naming the From address hive-mx saw, or the code expired), when it arrived, and the SPF, DKIM and alignment results hive-mx saw (results and domains only, never the message), with a **Check again** button. The calendar-emails API carries the same summary as `last_failure`. A proof mail whose code matches no address shows, sender masked, under the owner's **Recent proof attempts** (`recent_proof_attempts`, owner only). ([#18579](https://github.com/hivecommons/hive/issues/18579)) diff --git a/changelog.d/added-18590-betty-hive-status.md b/changelog.d/added-18590-betty-hive-status.md new file mode 100644 index 0000000000..b770bc437d --- /dev/null +++ b/changelog.d/added-18590-betty-hive-status.md @@ -0,0 +1 @@ +- **Betty answers questions about the hive from its live state.** "Betty, how many open issues are there?" or "what PRs are open in the hive repo?" is answered in seconds from the same in-memory status the Overview and the dashboard chat read (open, actionable, held and blocked counts, agents and what they are doing, recent completions, open PRs), and is no longer sent to the research agents. ([#18590](https://github.com/hivecommons/hive/issues/18590)) diff --git a/changelog.d/added-workflow-model-dispatch-targets.md b/changelog.d/added-workflow-model-dispatch-targets.md new file mode 100644 index 0000000000..cae227fe17 --- /dev/null +++ b/changelog.d/added-workflow-model-dispatch-targets.md @@ -0,0 +1 @@ +- Workflow models resolve where each agent profile takes over an item (`spec.agents[].dispatch`, or by convention the grant's first state, on entry or on the gate reply for a reviewing profile), and `workflow.dispatch.profiles..agent` maps a profile to a hive agent (default: an agent named after the profile, else a writer, docs or feature agent); the curated TechDocs model hands Accepted to `techdocs-drafter` and `/verify` to `techdocs-verifier`. diff --git a/changelog.d/changed-18452-automerge-note-status-card.md b/changelog.d/changed-18452-automerge-note-status-card.md new file mode 100644 index 0000000000..903a148d9c --- /dev/null +++ b/changelog.d/changed-18452-automerge-note-status-card.md @@ -0,0 +1 @@ +- Notifications: in `github.notifications.mode: quiet` (the default) the auto-merge note ("merged by Hive trusted-author auto-merge …" / "merged by Hive on behalf of …") is now the `auto-merge` section of the PR's `hive:status` card, edited in place with its @-mentions neutralised, instead of a fresh comment on every merged PR (about 32 notifying comments a day on hivecommons/hive). `mode: normal` keeps the standalone comment, and a merge that waits on a person still gets its own 085 / 090 entry comment (hivecommons/hive#18452). diff --git a/changelog.d/changed-18590-betty-early-ack.md b/changelog.d/changed-18590-betty-early-ack.md new file mode 100644 index 0000000000..e55aa4f015 --- /dev/null +++ b/changelog.d/changed-18590-betty-early-ack.md @@ -0,0 +1 @@ +- Betty speaks her acknowledgement as soon as a partial transcript names her with a request, instead of after the final transcript, so the room hears she is on it within a couple of seconds (hivecommons/hive#18590). diff --git a/changelog.d/fixed-18470-kick-freshness-stale-repo.md b/changelog.d/fixed-18470-kick-freshness-stale-repo.md new file mode 100644 index 0000000000..ff0bebf831 --- /dev/null +++ b/changelog.d/fixed-18470-kick-freshness-stale-repo.md @@ -0,0 +1 @@ +- The kick freshness guard now logs a ref it withheld because its repo's snapshot is stale (last-good data after a failed reconcile or a refused enumeration) at INFO, and a kick withheld only by stale, closed or deferred refs summarises at INFO, so a stale repo no longer files a `kick_freshness_withheld` self-report on every cycle; the stale repo itself is still logged at WARN where it is produced ([#18470](https://github.com/hivecommons/hive/issues/18470)). diff --git a/changelog.d/fixed-18497-copilot-relink-log-level.md b/changelog.d/fixed-18497-copilot-relink-log-level.md new file mode 100644 index 0000000000..682e08af78 --- /dev/null +++ b/changelog.d/fixed-18497-copilot-relink-log-level.md @@ -0,0 +1 @@ +- **A Copilot agent's config being re-linked to the shared login is no longer reported as a fleet error.** The routine, successful repair logged at WARN, so a hive where the CLI kept saving over the link filed an `unclassified_error_repeated` self-report (16 in 10 minutes); it now logs at INFO, while failed repairs still warn ([#18497](https://github.com/hivecommons/hive/issues/18497)). diff --git a/changelog.d/fixed-18525-sandbox-toggle-and-job-reap.md b/changelog.d/fixed-18525-sandbox-toggle-and-job-reap.md new file mode 100644 index 0000000000..cc3025a653 --- /dev/null +++ b/changelog.d/fixed-18525-sandbox-toggle-and-job-reap.md @@ -0,0 +1 @@ +- The dashboard's per-agent **Run in sandbox** toggle no longer wedges an agent ([#18525](https://github.com/hivecommons/hive/issues/18525)). Turning it on used to write `sandbox.enabled: true` alone, so with no `agent_sandbox` image every kick failed with "sandbox image is not configured". It now writes a complete block, prefilled from the `agent_sandbox` defaults or copied (`copy_from`) from another agent that has one, minus that agent's `publish.verify`, and refuses with a 400 that names what is missing when neither exists. The General tab shows a picker for the source when the toggle is turned on, with an inline error when there is none. Turning it off keeps the block and sets `enabled: false`. Switching an agent into sandbox mode now stops its tmux session, and a refused kick names the real state ("agent has a live interactive session; sandbox kicks are blocked until it stops") instead of "sandbox execution already running". Every sandbox Kubernetes Job now carries `activeDeadlineSeconds` (the kick timeout plus a 15-minute margin), and at boot hive reaps unfinished `app.kubernetes.io/managed-by=hive-kubejob` sandbox Jobs that no live kick owns, logging and auditing each one (`sandbox_job_reaped`). Before this, one Job sat Pending for 11 days. diff --git a/changelog.d/fixed-18530-inference-auth-report.md b/changelog.d/fixed-18530-inference-auth-report.md new file mode 100644 index 0000000000..b70aed2bb1 --- /dev/null +++ b/changelog.d/fixed-18530-inference-auth-report.md @@ -0,0 +1 @@ +- Repeated inference backend 401 warnings now produce an operator-action self-report identifying the rejected credential instead of an unclassified error. diff --git a/changelog.d/fixed-18544-kick-pool-busy-level.md b/changelog.d/fixed-18544-kick-pool-busy-level.md new file mode 100644 index 0000000000..8d430f2c46 --- /dev/null +++ b/changelog.d/fixed-18544-kick-pool-busy-level.md @@ -0,0 +1 @@ +- The "failed to send kick" log for a busy shared CLI session pool is now INFO instead of WARN, so routine pool contention is no longer fleet-reported as a repeated runtime error (#18544). diff --git a/changelog.d/fixed-18547-hold-guard-head-lag.md b/changelog.d/fixed-18547-hold-guard-head-lag.md new file mode 100644 index 0000000000..1a43b9e93c --- /dev/null +++ b/changelog.d/fixed-18547-hold-guard-head-lag.md @@ -0,0 +1 @@ +- The hold guard no longer logs a WARN (which self-reported as a defect) when GitHub has not yet shown the new head right after keeping a held PR mergeable; it retries next tick. diff --git a/changelog.d/fixed-18578-required-check-label-cancel.md b/changelog.d/fixed-18578-required-check-label-cancel.md new file mode 100644 index 0000000000..2ce7cb508b --- /dev/null +++ b/changelog.d/fixed-18578-required-check-label-cancel.md @@ -0,0 +1 @@ +- CI: label flips no longer cancel the required `verify PR contents`, `Sign-off survives the squash` and `changelog-fragment-guard` checks. Their concurrency groups now carry the head SHA, and label, edit and reopen re-checks each run in their own group, so a burst of `lgtm`/`approved`/size labels can neither cancel the run in flight nor drop a queued run. Those cancelled runs used to leave PRs BLOCKED and jam Tide. A new guard, `.github/scripts/test-required-check-concurrency.py`, evaluates every required-check workflow's concurrency for a label burst and fails on any shared group (#18578). diff --git a/changelog.d/fixed-18590-betty-spoken-intro-voice.md b/changelog.d/fixed-18590-betty-spoken-intro-voice.md new file mode 100644 index 0000000000..f600acc16c --- /dev/null +++ b/changelog.d/fixed-18590-betty-spoken-intro-voice.md @@ -0,0 +1 @@ +- **Betty answers a spoken "introduce yourself" by voice.** The intro reply did not carry the reply kind, so it went to the meeting chat even when the request was spoken and voice was on; typed intro requests still get a chat reply. ([#18590](https://github.com/hivecommons/hive/issues/18590)) diff --git a/changelog.d/fixed-18590-consent-confirmed.md b/changelog.d/fixed-18590-consent-confirmed.md new file mode 100644 index 0000000000..1eec6be42f --- /dev/null +++ b/changelog.d/fixed-18590-consent-confirmed.md @@ -0,0 +1 @@ +- Meetings: the consent notice now counts as posted only when Quorum confirms the line reached the meeting. In a live Teams test the bot could not open the meeting chat (`chat_send_failed reason=no_composer`, chat closed to guests) yet hive recorded `consent_posted_at` and kept listening (#18590, finding 11). Hive now posts the notice with `chat.post {confirm:true}` (quorum 0.2.2) and treats anything but `delivery: confirmed`, including an older Quorum that cannot say, as not posted. When chat cannot deliver it and the meeting has voice on, Betty speaks the notice instead (`consent_via: voice`, shown in the Meetings panel); when neither works she leaves at once with state reason `consent_undelivered`, and the panel says "Left: the consent notice could not be delivered (chat unavailable (...), voice off)". Transient failures (bot not admitted yet, rate limit, a dropped call) are retried up to three times before that. The image now ships quorum v0.2.2. diff --git a/changelog.d/fixed-18590-spek-status-plain.md b/changelog.d/fixed-18590-spek-status-plain.md new file mode 100644 index 0000000000..fedf422456 --- /dev/null +++ b/changelog.d/fixed-18590-spek-status-plain.md @@ -0,0 +1 @@ +- **The Meetings panel says plainly when notes and clarifying questions are off.** When Spektacular live mode is not running for a meeting the panel now leads with "Notes and clarifying questions are off" (or "paused" while hive cannot reach a restarting child, cleared when it writes again) instead of showing nothing until the child gives up. ([#18590](https://github.com/hivecommons/hive/issues/18590)) diff --git a/changelog.d/fixed-18598-hosted-spoke-502-body-passthrough.md b/changelog.d/fixed-18598-hosted-spoke-502-body-passthrough.md new file mode 100644 index 0000000000..29363da464 --- /dev/null +++ b/changelog.d/fixed-18598-hosted-spoke-502-body-passthrough.md @@ -0,0 +1 @@ +- **A hosted hive's own error is no longer hidden behind "hive unavailable".** The hosted ingress replaces any 502 with its generic "this hive is restarting" page, so an error the spoke actually answered (a Discord join refused for a missing permission, a failed upstream call) read as an outage. On a request that came through the hosted ingress, a JSON 502 from a dashboard API handler is now sent as 424 with the original status in `X-Hive-Status`, which the ingress passes through with the spoke's message; the generic page still appears when the spoke cannot be reached ([#18598](https://github.com/hivecommons/hive/issues/18598)). diff --git a/changelog.d/fixed-collaborate-sidebar-group-order.md b/changelog.d/fixed-collaborate-sidebar-group-order.md new file mode 100644 index 0000000000..ec0624f8cc --- /dev/null +++ b/changelog.d/fixed-collaborate-sidebar-group-order.md @@ -0,0 +1 @@ +- Dashboard: the Collaborate sidebar group (Inbox, Calendar, Meetings, Inception (spek)) no longer disappears into the Dashboard group when the section layout is applied, and now sits right after Dashboard, before Agents. diff --git a/changelog.d/fixed-stale-dependabot-prs.md b/changelog.d/fixed-stale-dependabot-prs.md new file mode 100644 index 0000000000..19f38bee12 --- /dev/null +++ b/changelog.d/fixed-stale-dependabot-prs.md @@ -0,0 +1 @@ +- Stale Dependabot PRs no longer get stuck behind refused `@dependabot rebase` comments: the hive never posts Dependabot commands (Dependabot ignores them from the App), updates a merely-behind Dependabot PR with the update-branch API, leaves a conflicting one to Dependabot's own rebase, and closes a conflicting one whose branch someone else pushed to so Dependabot opens a fresh PR (#18441). diff --git a/changelog.d/fixed-unsigned-squash-selfreport.md b/changelog.d/fixed-unsigned-squash-selfreport.md new file mode 100644 index 0000000000..6c656e106c --- /dev/null +++ b/changelog.d/fixed-unsigned-squash-selfreport.md @@ -0,0 +1 @@ +- Avoid spurious runtime self-reports when automerge safely refuses a squash of unsigned commits; the refusal remains visible in logs. diff --git a/dashboard/openapi.json b/dashboard/openapi.json index c3c707d661..794c9c7c29 100644 --- a/dashboard/openapi.json +++ b/dashboard/openapi.json @@ -815,7 +815,7 @@ "Meetings" ], "summary": "List my calendar emails", - "description": "The signed-in user's calendar email addresses with proof status and pending codes, the hive's address (hive@) and the meetings.email switches. ?all=1 adds the whole allowlist for the owner. Any role.", + "description": "The signed-in user's calendar email addresses with proof status and pending codes, the hive's address (hive@) and the meetings.email switches. An unproven address whose latest proof mail was refused carries last_failure. The owner also gets recent_proof_attempts (proof mails whose code matched no address, sender masked). ?all=1 adds the whole allowlist for the owner. Any role.", "parameters": [ { "name": "all", @@ -842,14 +842,14 @@ "type": "array", "items": { "type": "object", - "description": "Calendar email: email, proven, proven_at, code (pending proof code, own list only), code_expires_at, last_error, active (the user still has access), login (owner allowlist only)" + "description": "Calendar email: email, proven, proven_at, code (pending proof code, own list only), code_expires_at, last_error, active (the user still has access), login (owner allowlist only), last_failure (latest refused proof: reason not_aligned, from_mismatch or expired; at; from (from_mismatch only: the From address parsed, empty when missing, repeated or unparsable); from_domain, spf, spf_domain, spf_aligned, dkim [{domain, result}], dkim_aligned, dmarc, aligned; message, the reason in plain words with what to do)" } }, "allowlist": { "type": "array", "items": { "type": "object", - "description": "Calendar email: email, proven, proven_at, code (pending proof code, own list only), code_expires_at, last_error, active (the user still has access), login (owner allowlist only)" + "description": "Calendar email: email, proven, proven_at, code (pending proof code, own list only), code_expires_at, last_error, active (the user still has access), login (owner allowlist only), last_failure (latest refused proof: reason not_aligned, from_mismatch or expired; at; from (from_mismatch only: the From address parsed, empty when missing, repeated or unparsable); from_domain, spf, spf_domain, spf_aligned, dkim [{domain, result}], dkim_aligned, dmarc, aligned; message, the reason in plain words with what to do)" } }, "invites_enabled": { @@ -857,6 +857,14 @@ }, "files_enabled": { "type": "boolean" + }, + "recent_proof_attempts": { + "type": "array", + "description": "Owner only: recent proof mails whose code matched no address, newest first; kept in memory", + "items": { + "type": "object", + "description": "Proof attempt: at, from (masked, a***@example.com), reason (code not recognized)" + } } } } @@ -905,7 +913,7 @@ "properties": { "email": { "type": "object", - "description": "Calendar email: email, proven, proven_at, code (pending proof code, own list only), code_expires_at, last_error, active (the user still has access), login (owner allowlist only)" + "description": "Calendar email: email, proven, proven_at, code (pending proof code, own list only), code_expires_at, last_error, active (the user still has access), login (owner allowlist only), last_failure (latest refused proof: reason not_aligned, from_mismatch or expired; at; from (from_mismatch only: the From address parsed, empty when missing, repeated or unparsable); from_domain, spf, spf_domain, spf_aligned, dkim [{domain, result}], dkim_aligned, dmarc, aligned; message, the reason in plain words with what to do)" }, "address": { "type": "string" @@ -1505,6 +1513,215 @@ } } }, + "/api/meetings/model": { + "get": { + "tags": [ + "Meetings" + ], + "summary": "Meetings model", + "description": "meetings.llm.mode, backend and model as set, the label the meeting panel shows, the backends that can answer for meetings, the backends the hive's agents use, the defaults and the env overrides that are set. Owner or read-write.", + "responses": { + "200": { + "description": "The model settings", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "mode": { + "type": "string" + }, + "backend": { + "type": "string" + }, + "model": { + "type": "string" + }, + "label": { + "type": "string", + "description": "What the meeting panel shows for the resolved model" + }, + "modes": { + "type": "array", + "items": { + "type": "string" + } + }, + "supported_backends": { + "type": "array", + "items": { + "type": "string" + } + }, + "refused_backends": { + "type": "object", + "description": "Why each known backend that cannot answer for meetings is refused", + "additionalProperties": { + "type": "string" + } + }, + "agent_backends": { + "type": "array", + "items": { + "type": "string" + } + }, + "default_backend": { + "type": "string" + }, + "default_model": { + "type": "string" + }, + "default_models": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "env_overrides": { + "type": "array", + "items": { + "type": "string" + } + }, + "restart_required": { + "type": "boolean" + } + } + } + } + } + }, + "403": { + "description": "Owner or read-write access required" + }, + "503": { + "description": "Config is not available" + } + } + }, + "put": { + "tags": [ + "Meetings" + ], + "summary": "Save the meetings model", + "description": "Saves meetings.llm.mode, backend and model; omitted fields are kept and the change applies after a restart (restart_required). A backend with no meetings completion profile is refused. Owner only. Audited as meetings_model_settings.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "mode": { + "type": "string", + "enum": [ + "auto", + "openai", + "anthropic", + "agent-backend", + "claude-cli", + "none" + ] + }, + "backend": { + "type": "string" + }, + "model": { + "type": "string" + } + } + } + } + } + }, + "responses": { + "200": { + "description": "The saved model settings", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "mode": { + "type": "string" + }, + "backend": { + "type": "string" + }, + "model": { + "type": "string" + }, + "label": { + "type": "string", + "description": "What the meeting panel shows for the resolved model" + }, + "modes": { + "type": "array", + "items": { + "type": "string" + } + }, + "supported_backends": { + "type": "array", + "items": { + "type": "string" + } + }, + "refused_backends": { + "type": "object", + "description": "Why each known backend that cannot answer for meetings is refused", + "additionalProperties": { + "type": "string" + } + }, + "agent_backends": { + "type": "array", + "items": { + "type": "string" + } + }, + "default_backend": { + "type": "string" + }, + "default_model": { + "type": "string" + }, + "default_models": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "env_overrides": { + "type": "array", + "items": { + "type": "string" + } + }, + "restart_required": { + "type": "boolean" + } + } + } + } + } + }, + "400": { + "description": "Invalid body, unknown mode or unsupported backend" + }, + "403": { + "description": "Owner access required" + }, + "500": { + "description": "Saving the config failed" + }, + "503": { + "description": "Config is not available" + } + } + } + }, "/api/meetings/actions/{aid}/edit": { "post": { "tags": [ @@ -6304,6 +6521,173 @@ } } }, + "/api/config/prompt-sources": { + "get": { + "tags": [ + "System" + ], + "summary": "Get prompt and definition source repos", + "description": "Lists the hive's managed repos and whether agents' prompt_source / definition_source may read from each, via the config-volume allowlist or an owner approval (#18490). Requires owner role.", + "responses": { + "200": { + "description": "Prompt source gate state", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "repos": { + "type": "array", + "items": { + "type": "object", + "properties": { + "repo": { + "type": "string" + }, + "managed": { + "type": "boolean" + }, + "owner_approved": { + "type": "boolean" + }, + "seed_allowed": { + "type": "boolean" + }, + "allowed": { + "type": "boolean" + }, + "approved_by": { + "type": "string" + }, + "approved_at": { + "type": "string", + "description": "RFC 3339 time of the owner approval." + } + } + }, + "description": "One row per managed repo (project.repos), then any owner approval whose repo is no longer managed (inert)." + }, + "seed_enabled": { + "type": "boolean", + "description": "variables.security.allow_github_prompt from the config volume." + }, + "seed_allowlist": { + "type": "array", + "items": { + "type": "string" + } + }, + "trust_notice": { + "type": "string" + }, + "seed_only_note": { + "type": "string" + } + } + } + } + } + } + } + } + }, + "/api/config/prompt-sources/owner-repos": { + "put": { + "tags": [ + "System" + ], + "summary": "Approve or revoke a managed repo as a prompt source", + "description": "Approves (allowed: true, with acknowledge_trust: true) or revokes (allowed: false) one of the hive's managed repos as a prompt_source / definition_source repo. A repo outside project.repos, a malformed slug, or an approval without acknowledge_trust is refused with 400 and nothing changes. Persisted to variables.security.owner_github_prompt_repos in the running config and audit-logged. Requires owner role.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "repo", + "allowed" + ], + "properties": { + "repo": { + "type": "string", + "description": "owner/repo slug of a managed repo." + }, + "allowed": { + "type": "boolean" + }, + "acknowledge_trust": { + "type": "boolean", + "description": "Must be true to approve: anyone who can merge to the repo can steer the hive's agents." + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Updated prompt source gate state", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "repos": { + "type": "array", + "items": { + "type": "object", + "properties": { + "repo": { + "type": "string" + }, + "managed": { + "type": "boolean" + }, + "owner_approved": { + "type": "boolean" + }, + "seed_allowed": { + "type": "boolean" + }, + "allowed": { + "type": "boolean" + }, + "approved_by": { + "type": "string" + }, + "approved_at": { + "type": "string", + "description": "RFC 3339 time of the owner approval." + } + } + }, + "description": "One row per managed repo (project.repos), then any owner approval whose repo is no longer managed (inert)." + }, + "seed_enabled": { + "type": "boolean", + "description": "variables.security.allow_github_prompt from the config volume." + }, + "seed_allowlist": { + "type": "array", + "items": { + "type": "string" + } + }, + "trust_notice": { + "type": "string" + }, + "seed_only_note": { + "type": "string" + } + } + } + } + } + } + } + } + }, "/api/config/reference-repos": { "get": { "tags": [ @@ -6330,6 +6714,18 @@ "items": { "type": "string" } + }, + "write_identity": { + "type": "string" + }, + "write_identities": { + "type": "array", + "items": { + "type": "string" + } + }, + "bot_login": { + "type": "string" } } } @@ -6384,6 +6780,18 @@ "items": { "type": "string" } + }, + "write_identity": { + "type": "string" + }, + "write_identities": { + "type": "array", + "items": { + "type": "string" + } + }, + "bot_login": { + "type": "string" } } } @@ -6402,6 +6810,85 @@ } } }, + "/api/config/reference-repos/write-identity": { + "put": { + "tags": [ + "System" + ], + "summary": "Set the remote write identity", + "description": "Sets project.remote_write_identity: whose name the hive's writes to granted reference repos carry (bot: the App bot where the repo's owner installed the App, else the owner's connected account; bot_only: the App bot or read-only; owner: the owner's connected account). Refused when a hand-written write entry would have no credential under the new value. Re-resolves the reference repos before answering. Owner only.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "write_identity" + ], + "properties": { + "write_identity": { + "type": "string", + "enum": [ + "bot", + "bot_only", + "owner" + ] + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Current reference repos, resolved under the new value (same body as GET /api/config/reference-repos)", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "reference_repos": { + "type": "array", + "items": { + "type": "object" + } + }, + "write_kinds": { + "type": "array", + "items": { + "type": "string" + } + }, + "write_identity": { + "type": "string" + }, + "write_identities": { + "type": "array", + "items": { + "type": "string" + } + }, + "bot_login": { + "type": "string" + } + } + } + } + } + }, + "400": { + "description": "Unknown value, or a hand-written write entry would have no credential; nothing was stored" + }, + "403": { + "description": "Owner role required" + }, + "500": { + "description": "The config file could not be written; the setting is unchanged" + } + } + } + }, "/api/config/stat-sources": { "get": { "tags": [ @@ -7699,6 +8186,364 @@ } } }, + "/api/agents/discovered": { + "get": { + "tags": [ + "Agents" + ], + "summary": "List agents discovered in managed repos", + "description": "Agent definitions found under .hive/agents/*.yaml in managed repos that pass the repo-sourced prompt allowlist, with their approval status. Nothing runs until an owner approves an entry.", + "responses": { + "200": { + "description": "Discovered definitions", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean", + "description": "False when discovery is not running (no GitHub client)." + }, + "pending": { + "type": "integer" + }, + "entries": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "owner/repo:path of the definition file." + }, + "repo": { + "type": "string" + }, + "path": { + "type": "string" + }, + "prompt_path": { + "type": "string", + "description": "Sibling .md that becomes prompt_source on approval, when present." + }, + "name": { + "type": "string", + "description": "Agent key the definition maps to." + }, + "display_name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "emoji": { + "type": "string" + }, + "status": { + "type": "string", + "enum": [ + "pending", + "invalid", + "approved", + "rejected", + "orphaned" + ] + }, + "agent": { + "type": "string", + "description": "Registered agent, once approved." + }, + "error": { + "type": "string" + }, + "first_seen": { + "type": "string", + "format": "date-time" + }, + "last_seen": { + "type": "string", + "format": "date-time" + }, + "decided_at": { + "type": "string", + "format": "date-time" + }, + "decided_by": { + "type": "string" + }, + "orphaned_at": { + "type": "string", + "format": "date-time" + } + } + } + } + } + } + } + } + } + } + } + }, + "/api/agents/discovered/approve": { + "post": { + "tags": [ + "Agents" + ], + "summary": "Approve a discovered agent", + "description": "Owner-only. Re-reads the definition through the allowlist gate and registers the agent with definition_source (marked discovered) and, when a sibling .md exists, prompt_source. Backend, model and mode come from this request, never the file; tools stay unset for the owner to grant.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string", + "description": "Agent key; defaults to the definition's normalized metadata.name." + }, + "backend": { + "type": "string", + "description": "Defaults to copilot." + }, + "model": { + "type": "string" + }, + "mode": { + "type": "string", + "enum": [ + "ADVISORY", + "ISSUES_ONLY", + "ISSUES_AND_PRS", + "ISSUES_PRS_MERGE", + "NO_GITHUB" + ] + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Approved", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "approved" + }, + "name": { + "type": "string" + } + } + } + } + } + }, + "400": { + "description": "Invalid body, mode or agent name" + }, + "403": { + "description": "Owner role required, or the repo is no longer allowlisted" + }, + "404": { + "description": "Unknown entry" + }, + "409": { + "description": "Entry is not pending, or the agent name is taken" + }, + "502": { + "description": "The definition could not be read or parsed" + }, + "503": { + "description": "Discovery is not running" + } + } + } + }, + "/api/agents/discovered/reject": { + "post": { + "tags": [ + "Agents" + ], + "summary": "Reject a discovered agent", + "description": "Owner-only. A rejected definition stays rejected until its file is removed.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string" + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Rejected", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "example": "rejected" + }, + "id": { + "type": "string" + } + } + } + } + } + }, + "400": { + "description": "Invalid body" + }, + "403": { + "description": "Owner role required" + }, + "404": { + "description": "Unknown entry" + }, + "409": { + "description": "Entry is not pending" + }, + "503": { + "description": "Discovery is not running" + } + } + } + }, + "/api/agents/discovered/refresh": { + "post": { + "tags": [ + "Agents" + ], + "summary": "Rescan managed repos for agent definitions", + "description": "Owner-only. Rescans every managed repo now instead of waiting for the timer and returns the refreshed list.", + "responses": { + "200": { + "description": "Discovered definitions", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean", + "description": "False when discovery is not running (no GitHub client)." + }, + "pending": { + "type": "integer" + }, + "entries": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "owner/repo:path of the definition file." + }, + "repo": { + "type": "string" + }, + "path": { + "type": "string" + }, + "prompt_path": { + "type": "string", + "description": "Sibling .md that becomes prompt_source on approval, when present." + }, + "name": { + "type": "string", + "description": "Agent key the definition maps to." + }, + "display_name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "emoji": { + "type": "string" + }, + "status": { + "type": "string", + "enum": [ + "pending", + "invalid", + "approved", + "rejected", + "orphaned" + ] + }, + "agent": { + "type": "string", + "description": "Registered agent, once approved." + }, + "error": { + "type": "string" + }, + "first_seen": { + "type": "string", + "format": "date-time" + }, + "last_seen": { + "type": "string", + "format": "date-time" + }, + "decided_at": { + "type": "string", + "format": "date-time" + }, + "decided_by": { + "type": "string" + }, + "orphaned_at": { + "type": "string", + "format": "date-time" + } + } + } + } + } + } + } + } + }, + "403": { + "description": "Owner role required" + }, + "503": { + "description": "Discovery is not running" + } + } + } + }, "/api/agents/{name}": { "delete": { "tags": [ @@ -11325,6 +12170,10 @@ }, "linear_issue": { "type": "string" + }, + "per_repo": { + "type": "boolean", + "description": "Advisory report in every repo (governor.advisory.per_repo, default false)" } } } @@ -11376,6 +12225,10 @@ "linear_issue": { "type": "string", "description": "Required when target is linear" + }, + "per_repo": { + "type": "boolean", + "description": "Off: one Hive Advisory Report in the primary repo covers all repos. On: each monitored repo also gets its own report." } } } @@ -43308,14 +44161,14 @@ "Inbox" ], "summary": "Receive mail-in files (hub relay)", - "description": "Markdown, audio and image attachments hive-mx received for hive@. A sender whose From address passed DMARC alignment and is a proven calendar email of a user with access becomes normal Inbox items; anyone else's items await the owner's approval. Relay signature: X-Hive-Relay-Timestamp, X-Hive-Relay-Signature-256 (HMAC-SHA256 with this hive's relay key over timestamp.delivery.body) and X-Hive-Relay-Delivery; no session.", + "description": "Markdown, audio, video and image attachments and text bodies hive-mx received for hive@ (#18395, #18564); a body-only mail arrives as message.md and a mail's body is kept as each item's note. A sender whose From address passed DMARC alignment and is a proven calendar email of a user with access becomes normal Inbox items; anyone else's items await the owner's approval. Relay signature: X-Hive-Relay-Timestamp, X-Hive-Relay-Signature-256 (HMAC-SHA256 with this hive's relay key over timestamp.delivery.body) and X-Hive-Relay-Delivery; no session.", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", - "description": "hive-mx delivery (pkg/mailin/wire.Delivery) of kind files: id, kind, recipient, message_id, received_at, auth, files {title, attachments[] {name, kind, content_type, size, sha256, data}}" + "description": "hive-mx delivery (pkg/mailin/wire.Delivery) of kind files: id, kind, recipient, message_id, received_at, auth, files {title, note, attachments[] {name, kind, content_type, size, sha256, data}}" } } } @@ -43363,6 +44216,74 @@ } } }, + "/api/inbox/email/chunk": { + "post": { + "tags": [ + "Inbox" + ], + "summary": "Receive one piece of a large mail-in delivery (hub relay)", + "description": "The hub relays a files delivery larger than one request in order, each piece signed with this hive's relay key over the relay delivery id .. (X-Hive-Relay-Delivery), so the order and count are covered and each piece passes the replay check. X-Hive-Mail-Body-Type is the whole body's type (multipart/form-data from hive-mx, or application/json). Pieces are staged on disk; the last one decodes the body, checks each file's size and SHA-256 and stores it like POST /api/inbox/email. No session.", + "requestBody": { + "required": true, + "content": { + "application/octet-stream": { + "schema": { + "type": "string", + "format": "binary", + "description": "One piece of the delivery body, at most 8 MiB" + } + } + } + }, + "responses": { + "200": { + "description": "Piece staged ({piece, pieces}), or, for the last piece, stored ({items, awaiting_approval})", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "piece": { + "type": "integer" + }, + "pieces": { + "type": "integer" + }, + "items": { + "type": "array", + "items": { + "type": "string" + } + }, + "awaiting_approval": { + "type": "boolean" + } + } + } + } + } + }, + "400": { + "description": "Invalid piece, missing piece or undecodable body" + }, + "401": { + "description": "Relay signature rejected or piece replayed" + }, + "409": { + "description": "Mail-in files are off or unavailable" + }, + "413": { + "description": "Piece or delivery too large" + }, + "503": { + "description": "This hive holds no relay key" + }, + "507": { + "description": "The email spool is full" + } + } + } + }, "/api/inbox/email/{id}/approve": { "post": { "tags": [ @@ -45376,6 +46297,97 @@ } } }, + "/api/inbox/hive-recording/{id}": { + "delete": { + "tags": [ + "Knowledge" + ], + "summary": "Delete a hive recording", + "description": "An owner, or the read-write member who recorded it. Deletes a finished recording for good: its stored audio and chunks, the Inbox item and its state, and its Knowledge fact with the machine transcript. What was already shared from it (RFC, issues, DIBS ideas, spek seeds) is not touched. Audited as `inbox_recording_delete`.", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Recording id (the Inbox item id)" + } + ], + "responses": { + "200": { + "description": "Deleted", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "deleted": { + "type": "boolean" + }, + "fact_removed": { + "type": "boolean" + }, + "shares_kept": { + "type": "integer" + } + } + } + } + } + }, + "403": { + "description": "Read role, or a read-write member deleting someone else's recording", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + }, + "404": { + "description": "Unknown recording", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + }, + "409": { + "description": "Still in progress, or being transcribed", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + } + } + } + }, "/api/inbox/recordings/{id}": { "delete": { "tags": [ diff --git a/dashboard/test/inbox-item.test.js b/dashboard/test/inbox-item.test.js index 39e0a8c860..430c51a547 100644 --- a/dashboard/test/inbox-item.test.js +++ b/dashboard/test/inbox-item.test.js @@ -51,7 +51,7 @@ function makeContext(role) { Array, }; vm.createContext(ctx); - for (const fn of ['inboxSharePillText', 'inboxShareTargetHref', 'inboxSharePillHtml', 'inboxSharePillsHtml', 'inboxCanShare', 'inboxIntentLabel', 'inboxIntentThen', 'inboxSourceIcon', 'inboxItemHasAudio', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxTxUnavailableText', 'inboxTxEtaText', 'inboxTxElapsedText', 'inboxTxProgressHtml', 'inboxTranscriptionHtml', 'inboxItemHtml']) { + for (const fn of ['inboxSharePillText', 'inboxShareTargetHref', 'inboxSharePillHtml', 'inboxSharePillsHtml', 'inboxCanShare', 'inboxIntentLabel', 'inboxIntentThen', 'inboxSourceIcon', 'inboxItemHasAudio', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxTxUnavailableText', 'inboxTxEtaText', 'inboxTxElapsedText', 'inboxTxProgressHtml', 'inboxTranscriptionHtml', 'inboxCanDeleteRecording', 'inboxItemHtml']) { vm.runInContext(extractFunction(fn), ctx); } return ctx; diff --git a/dashboard/test/meetings-calendar-role-race.test.js b/dashboard/test/meetings-calendar-role-race.test.js new file mode 100644 index 0000000000..b2caab7f22 --- /dev/null +++ b/dashboard/test/meetings-calendar-role-race.test.js @@ -0,0 +1,148 @@ +'use strict'; + +// The Meetings and Calendar panels must not show their "not allowed" notice +// while /api/role is unresolved, and must fetch and render the moment the +// role arrives (same race the Inbox fixed in #18442). They must also sit in +// the dashboard layout template, or layout.js leaves them outside +// #hive-dashboard-root and the card loses its padding tokens. Functions are +// extracted from the generated dashboard page. +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); + +const indexHtml = fs.readFileSync(path.join(__dirname, '..', '..', 'src', 'pkg', 'dashboard', 'static', 'index.html'), 'utf8'); + +function extractFunction(name) { + const start = indexHtml.indexOf('function ' + name + '('); + assert.notEqual(start, -1, `${name} function exists`); + const brace = indexHtml.indexOf('{', start); + let depth = 0; + for (let i = brace; i < indexHtml.length; i++) { + const ch = indexHtml[i]; + if (ch === '{') depth++; + if (ch === '}') depth--; + if (depth === 0) return (indexHtml.slice(start - 6, start) === 'async ' ? 'async ' : '') + indexHtml.slice(start, i + 1); + } + throw new Error(`unterminated ${name}`); +} + +function extractConst(name) { + const m = new RegExp('const ' + name + ' = [^;]+;').exec(indexHtml); + assert.ok(m, `${name} const exists`); + return m[0]; +} + +const GH_AUTH = ['hiveRoleSettled']; +const MEETINGS = ['meetingsIsOwner', 'meetingsRoleKnown', 'meetingsOnRoleReady', 'fetchMeetings', 'renderMeetings', 'meetingsJoinFormHtml', + 'meetingsRowHtml', 'meetingsFormatTime', 'meetingsFriendlyReason', 'meetingsReasonHtml', 'meetingsLabel']; +const CALENDAR = ['calendarRoleKnown', 'calendarOnRoleReady', 'calendarCanView', 'calendarIsOwner', 'fetchCalendar', 'calendarRefreshMeetings', + 'fetchMeetingDrafts', 'renderCalendar', 'renderMeetingDrafts', 'meetingDraftsSplit', 'calendarFormHtml', 'calendarViewerTimeZone', + 'calendarRowHtml', 'calendarFormatTime', 'calendarPlatformLabel', 'calendarMeetingLink', 'calendarActionButtons', 'renderCalendarIndicator', + 'calendarIndicatorState', 'calendarBadgeCount', 'calendarMeetingList']; + +function makeSandbox(opts) { + const els = {}; + const el = (id) => (els[id] = els[id] || { id, innerHTML: '', dataset: {}, querySelector: () => null, setAttribute() {} }); + const calls = []; + const sb = { + window: { _hiveRoleListeners: [] }, + document: { getElementById: (id) => el(id), querySelector: () => null }, + els, + calls, + escapeHtml: (s) => String(s).replace(/&/g, '&').replace(/ {}, + setSectionSummary: () => {}, + setSidebarCountBadge: () => {}, + renderMeetingsLive: () => {}, + dashboardRoleAtLeast: (role, min) => ['read', 'read-write', 'owner'].indexOf(role) >= ['read', 'read-write', 'owner'].indexOf(min), + fetch: async (url) => { + calls.push(url); + if (opts && opts.fetch) return opts.fetch(url); + if (url === '/api/meetings') return { ok: true, status: 200, json: async () => ({ meetings: (opts && opts.meetings) || [] }) }; + if (url === '/api/meetings/schedule') return { ok: true, status: 200, json: async () => ({ upcoming: [], recent: [] }) }; + if (url === '/api/meetings/actions') return { ok: true, status: 200, json: async () => ({ drafts: [] }) }; + return { ok: true, status: 200, json: async () => ({}) }; + }, + _meetingsList: null, _meetingsError: '', _meetingsOpen: null, + _calendarData: null, _calendarError: '', _calendarMeetings: {}, + _meetingDrafts: null, _meetingDraftsError: '', _meetingDraftRepos: ['o/r'], + console, Math, Number, Array, Error, Promise, String, Object, Date, Intl, isNaN, + }; + vm.createContext(sb); + const consts = ['MEETINGS_ERROR_INLINE_CHARS', 'MEETINGS_PLATFORM_LABELS', 'MEETINGS_PILL_STATUS', 'MEETINGS_LIVE_STATES', + 'CALENDAR_ACTIVE_STATES', 'CALENDAR_DEFAULT_NAME', 'CALENDAR_PLATFORM_LABELS', 'CALENDAR_PLATFORM_ICONS', 'CALENDAR_SOURCE_LABELS', + 'CALENDAR_STATUS_LABELS', 'CALENDAR_PILL_STATUS'].map(extractConst); + // const declarations stay script-scoped in a vm context; re-declare the + // mutable module state with var so the extracted functions share it. + vm.runInContext(consts.join('\n') + '\n' + GH_AUTH.concat(MEETINGS, CALENDAR).map(extractFunction).join('\n'), sb); + // Same registrations meetings.js and calendar.js perform at load. + sb.window._hiveRoleListeners.push(sb.meetingsOnRoleReady, sb.calendarOnRoleReady); + return sb; +} + +const settle = () => new Promise((r) => setImmediate(r)); + +test('meetings and calendar are in the dashboard layout template', () => { + const m = /var DASHBOARD_LAYOUT_TEMPLATE=\{main:\[([^\]]+)\]\}/.exec(indexHtml); + assert.ok(m, 'layout template found'); + assert.match(m[1], /'inbox-section','calendar-section','meetings-section'/); +}); + +test('while the role is unknown both panels show loading, not the not-allowed notice, and fetch nothing', async () => { + const sb = makeSandbox({}); + await sb.fetchMeetings(); + await sb.fetchCalendar(); + assert.match(sb.els['meetings-panel'].innerHTML, /Loading meetings/); + assert.match(sb.els['calendar-panel'].innerHTML, /Loading calendar/); + assert.doesNotMatch(sb.els['meetings-panel'].innerHTML + sb.els['calendar-panel'].innerHTML, /visible to the hive owner/); + assert.deepEqual(sb.calls, []); +}); + +test('role arriving as owner fetches and renders the join form and the calendar', async () => { + const sb = makeSandbox({}); + await sb.fetchMeetings(); + await sb.fetchCalendar(); + sb.window._hiveRole = 'owner'; + sb.hiveRoleSettled(false); + await settle(); + await settle(); + assert.ok(sb.calls.includes('/api/meetings')); + assert.ok(sb.calls.includes('/api/meetings/schedule')); + assert.match(sb.els['meetings-panel'].innerHTML, /data-action="meetingsJoin"/); + assert.match(sb.els['meetings-panel'].innerHTML, /No meetings yet/); + assert.match(sb.els['calendar-panel'].innerHTML, /Nothing scheduled/); + assert.match(sb.els['meeting-drafts-panel'].innerHTML, /No drafts waiting/); + assert.doesNotMatch(sb.els['meetings-panel'].innerHTML, /visible to the hive owner/); +}); + +test('role arriving as read shows the not-allowed notices', async () => { + const sb = makeSandbox({}); + sb.window._hiveRole = 'read'; + sb.hiveRoleSettled(false); + await settle(); + assert.match(sb.els['meetings-panel'].innerHTML, /visible to the hive owner only/); + assert.match(sb.els['calendar-panel'].innerHTML, /visible to the hive owner and read-write users/); + assert.equal(sb.calls.length, 0); +}); + +test('a network failure says so instead of staying on Loading meetings', async () => { + const sb = makeSandbox({ fetch: async () => { throw new Error('network'); } }); + sb.window._hiveRole = 'owner'; + await sb.fetchMeetings(); + assert.doesNotMatch(sb.els['meetings-panel'].innerHTML, /Loading meetings/); + assert.match(sb.els['meetings-panel'].innerHTML, /unreachable right now/); +}); + +test('a failed meeting row shows a pill, a friendly line and the raw error under details', async () => { + const raw = 'quorum meeting.join: invalid_argument: Vexa POST /bots answered 422: unsupported platform \'zoom\' without a meeting_url'; + const sb = makeSandbox({ meetings: [{ id: 'm1', title: 'Live test', platform: 'zoom', state: 'failed', state_reason: raw, created_at: '2026-11-16T15:00:00Z' }] }); + sb.window._hiveRole = 'owner'; + await sb.fetchMeetings(); + const html = sb.els['meetings-panel'].innerHTML; + assert.match(html, /failed<\/span>/); + assert.match(html, /class="meetings-row-error">The meeting service did not accept this meeting link\./); + assert.match(html, /details<\/summary>
quorum meeting\.join/); + assert.match(html, /Zoom · /); +}); diff --git a/dashboard/test/sidebar-collaborate-group.test.js b/dashboard/test/sidebar-collaborate-group.test.js new file mode 100644 index 0000000000..905c669e60 --- /dev/null +++ b/dashboard/test/sidebar-collaborate-group.test.js @@ -0,0 +1,210 @@ +'use strict'; + +// The Collaborate sidebar group (Inbox, Calendar, Meetings, Inception (spek)) +// must survive the dashboard layout sidebar sort. Those sections are in +// DASHBOARD_LAYOUT_TEMPLATE (so their cards get layout padding, collapse +// defaults and ordering), and dashboardSortSidebar used to re-home every +// layout-listed nav link into #dashboard-section-nav-group, which emptied and +// hid Collaborate. This test renders the real sidebar markup and the real +// layout functions from the generated page, applies a saved layout that puts +// the Collaborate sections first, and checks the group keeps its links, in +// order, right after Dashboard and before Agents. +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); + +const indexHtml = fs.readFileSync(path.join(__dirname, '..', '..', 'src', 'pkg', 'dashboard', 'static', 'index.html'), 'utf8'); + +const DASHBOARD_GROUP_ID = 'dashboard-section-nav-group'; +const AGENT_GROUP_ID = 'oc-agent-nav-group'; +const COLLABORATE_LABEL = 'Collaborate'; +const COLLABORATE_LINKS = ['Inbox', 'Calendar', 'Meetings', 'Inception (spek)']; +const COLLABORATE_SECTIONS = ['inbox-section', 'calendar-section', 'meetings-section', 'sessions-section']; +const LAYOUT_KEY = 'hive.dashboard.layout'; + +function extractFunction(name) { + const start = indexHtml.indexOf('function ' + name + '('); + assert.notEqual(start, -1, `${name} function exists`); + const brace = indexHtml.indexOf('{', start); + let depth = 0; + for (let i = brace; i < indexHtml.length; i++) { + const ch = indexHtml[i]; + if (ch === '{') depth++; + if (ch === '}') depth--; + if (depth === 0) return indexHtml.slice(start, i + 1); + } + throw new Error(`unterminated ${name}`); +} + +function extractVar(name) { + const m = new RegExp('var ' + name + '=[^;]+;').exec(indexHtml); + assert.ok(m, `${name} var exists`); + return m[0]; +} + +// Minimal element model: enough DOM for the sidebar sort/drag helpers. +class El { + constructor(attrs) { + this.attrs = Object.assign({}, attrs); + this.children = []; + this.parentElement = null; + this.hidden = 'hidden' in this.attrs; + this.textContent = this.attrs._text || ''; + this.dataset = {}; + } + get id() { return this.attrs.id || ''; } + hasClass(c) { return (this.attrs.class || '').split(/\s+/).includes(c); } + getAttribute(n) { return n in this.attrs ? this.attrs[n] : null; } + setAttribute(n, v) { this.attrs[n] = String(v); } + removeAttribute(n) { delete this.attrs[n]; } + appendChild(ch) { + if (ch.parentElement) ch.parentElement.children = ch.parentElement.children.filter((x) => x !== ch); + ch.parentElement = this; + this.children.push(ch); + return ch; + } + descendants() { return this.children.flatMap((c) => [c, ...c.descendants()]); } + closest(sel) { + assert.equal(sel, '.oc-nav-group', `unexpected closest(${sel})`); + for (let el = this; el; el = el.parentElement) if (el.hasClass('oc-nav-group')) return el; + return null; + } + querySelectorAll(sel) { + if (sel === '.oc-nav-item') return this.descendants().filter((e) => e.hasClass('oc-nav-item')); + if (sel === ':scope > [data-dashboard-section]') return this.children.filter((c) => c.attrs['data-dashboard-section']); + throw new Error(`unexpected querySelectorAll(${sel})`); + } + querySelector() { return null; } +} + +function parseAttrs(s) { + const out = {}; + for (const m of s.matchAll(/([\w-]+)(?:="([^"]*)")?/g)) out[m[1]] = m[2] === undefined ? '' : m[2]; + return out; +} + +// Build the sidebar tree from the generated page: every .oc-nav-group in +// source order, its heading, and its .oc-nav-item links. +function buildSidebar() { + const navStart = indexHtml.indexOf('