Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): host-qualified --repo for pr-watcher gh calls
Adam Eivy30a3af895170
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 383015fd0f..a7795d3019 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -38,7 +38,7 @@- **claim-issue no longer reports "no open issues" when an author filter is hiding a full queue.** The perpetual `claim-issue` / `claim-issue-gitlab` work-detector runs `gh`/`glab issue list` with an author filter (`self`→`@me`, or `owner`→the repo owner), and an empty *filtered* result was flattened to the reason `no-open-issues` — so a repo with open issues that simply don't match the filter parked for a full recheck cadence claiming there was nothing to do. The two failure modes this hid: `owner` resolves to an **org** (e.g. a GHE repo owned by a team), which is never an issue author, so the filter matches nothing; and `self`/`@me` is the wrong identity when the forge session differs from whoever filed the issues. The detector now re-probes without the author filter when the filtered list is empty, and if open issues exist it parks with a new `no-authored-issues` reason carrying the real open count. The on-demand "Run" toast now says *"open issues exist, but none match the author filter — set it to \"any\" (0 of N open)"* instead of the misleading "no open issues", pointing the user at the fix. A genuinely empty repo still reports `no-open-issues`, and the `any` filter is unaffected (no wasted re-probe). New private helper `countOpenIssuesUnfiltered`; covered by `perpetualWork.test.js` and `useOnDemandTaskToast.test.jsx`.- **claim-issue distinguishes the "owner filter matches an org" trap from a personal-username mismatch.** Building on the fix above: when the `owner` author filter resolves to an **organization** login (the common case for team/enterprise repos), `--author <org>` can only ever match zero issues — an org is never an issue author. The detector now recognizes an org owner up front (`gh repo view --json owner,isInOrganization`), skips the guaranteed-empty query entirely, and parks with a distinct `owner-is-org` reason carrying the real open count. The toast now reads *"the \"owner\" filter matches an org, which can't author issues — set it to \"self\" or \"any\" (0 of N open)"* instead of the generic "set it to any", so the user isn't left thinking their own username is mismatched. `owner` mode on a user-owned repo is unchanged. Covered by `perpetualWork.test.js` and `useOnDemandTaskToast.test.jsx`.-- **pr-watcher now works on GitHub Enterprise hosts and resolves "self" against the repo's actual host.** The `pr-watcher` task gated on `getOriginInfo().isGithub`, which is github.com-only, so it silently no-op'd (`not-a-github-repo`) on self-hosted GitHub Enterprise (`github.*`) repos. Worse, its self/others author gate resolved the operator login via `gh api user` with no `--hostname` — which always targets github.com regardless of the repo — and cached one login process-wide, so on an enterprise repo it compared PR authors against the wrong identity (a user is commonly a different login per host). The gate now classifies GitHub-family hosts via the shared `hostToWorkTracker` (the same rule the claim-issue router uses; `gitlab.*` still falls through as not-a-github-repo), the default-branch and PR-list `gh` calls run inside the repo checkout so gh auto-detects the host, and `getSelfLogin(host)` resolves identity with an explicit `--hostname` and caches per host. `execGh` gained an optional `cwd` argument. Covered by `prWatcher.test.js`.+- **pr-watcher now works on GitHub Enterprise hosts and resolves "self" against the repo's actual host.** The `pr-watcher` task gated on `getOriginInfo().isGithub`, which is github.com-only, so it silently no-op'd (`not-a-github-repo`) on self-hosted GitHub Enterprise (`github.*`) repos. Worse, its self/others author gate resolved the operator login via `gh api user` with no `--hostname` — which always targets github.com regardless of the repo — and cached one login process-wide, so on an enterprise repo it compared PR authors against the wrong identity (a user is commonly a different login per host). The gate now classifies GitHub-family hosts via the shared `hostToWorkTracker` (the same rule the claim-issue router uses; `gitlab.*` still falls through as not-a-github-repo), the default-branch and PR-list `gh` calls pass a host-qualified `--repo HOST/OWNER/REPO` selector (enterprise-correct, and deterministic on a fork+upstream multi-remote checkout where cwd-based detection would ambiguously resolve to the parent), and `getSelfLogin(host)` resolves identity with an explicit `--hostname` and caches per host. Covered by `prWatcher.test.js`.- **Retry lazy route chunks before failing on flaky mobile networks.** Lazy-loaded pages fetch their JS chunk on demand, and on a weak cellular/Wi-Fi link that fetch can fail on a transient blip ("Importing a module script failed" on Safari, "Failed to fetch dynamically imported module" on Chrome) even though the chunk still exists — a page reload can't fix a network hiccup, so once the one-shot stale-chunk reload was spent for a build, the next blip stranded the user on the error screen. `lazyWithReload` now retries the dynamic import twice with a short backoff before treating the failure as terminal, so a transient mobile-network failure recovers silently without a jarring reload; a genuinely stale chunk (renamed by a rebuild) still 404s on each quick retry and falls through to the existing reload-once path. New `importWithRetry` helper with unit coverage.- **[issue-2643] De-flake the Wiki vault-default test under full-suite load.** `Wiki.test.jsx`'s "defaults to the first vault" (and the sibling "restores the selected vault") assertions checked `scanNotesVault` synchronously right after `await waitFor(...)` on the rendered vault id. That mock call is fired by a *separate* `useEffect` keyed on the selected vault, so the committed overview render can land before the passive effect flushes — reliably true in isolation, but on a CPU-saturated full client run the bare assertion raced ahead of the effect and failed (`expected vi.fn() to be called with arguments`). The two mock-call assertions now sit inside their own `waitFor`, awaiting the async side-effect instead of sampling it. Test-only change (no `test.retry` or timeout inflation) — no runtime behavior change.diff --git a/server/services/github.js b/server/services/github.jsindex 040aeeb652..d1d39988f0 100644--- a/server/services/github.js+++ b/server/services/github.js@@ -36,14 +36,11 @@ async function save(data) {}/**- * Execute a gh CLI command safely using spawn. Pass `cwd` to run inside a repo- * checkout so gh auto-detects the forge host from that repo's git remote (how- * `gh pr list` / `gh repo view` target an enterprise host). `gh api` is the- * exception — it ignores cwd and needs an explicit `--hostname` in `args`.+ * Execute a gh CLI command safely using spawn*/-export function execGh(args, cwd) {+export function execGh(args) {return new Promise((resolve, reject) => {- const child = spawn('gh', args, { cwd, shell: false, windowsHide: true });+ const child = spawn('gh', args, { shell: false, windowsHide: true });let stdout = '';let stderr = '';child.stdout.on('data', (d) => { stdout += d.toString(); });diff --git a/server/services/prWatcher.js b/server/services/prWatcher.jsindex dbd4aa1e1a..b307468514 100644--- a/server/services/prWatcher.js+++ b/server/services/prWatcher.js@@ -78,28 +78,31 @@ export function __resetSelfLoginCache() {}/**- * Resolve a repo's default branch via gh. Runs inside `repoPath` so gh- * auto-detects the forge host from the repo's remote (works for github.com AND- * enterprise). Returns null on failure.+ * Resolve a repo's default branch via gh. `repoSpec` is a host-qualified+ * `HOST/OWNER/REPO` selector (see checkPullRequests) — pinning the host makes+ * this work on GitHub Enterprise (a bare `OWNER/REPO` defaults to github.com)+ * while staying deterministic on a multi-remote (fork + upstream) checkout that+ * cwd-based auto-detection would resolve ambiguously. Returns null on failure.*/-async function getDefaultBranch(repoPath) {- const name = await execGh(['repo', 'view', '--json', 'defaultBranchRef', '-q', '.defaultBranchRef.name'], repoPath)+async function getDefaultBranch(repoSpec) {+ const name = await execGh(['repo', 'view', repoSpec, '--json', 'defaultBranchRef', '-q', '.defaultBranchRef.name']).catch(() => null);return name ? name.trim() : null;}/**- * List open PRs targeting `baseBranch` for the repo at `repoPath`. Runs inside- * `repoPath` so gh auto-detects the host (no `--repo`, which would default to- * github.com). Returns an array of normalized PR objects, or null on failure.+ * List open PRs targeting `baseBranch` for the host-qualified `repoSpec`+ * (`HOST/OWNER/REPO`). The host qualifier is what makes this enterprise-correct+ * and fork-safe — see getDefaultBranch. Returns an array of normalized PR+ * objects, or null on failure.*/-async function listOpenPullRequests(repoPath, baseBranch) {+async function listOpenPullRequests(repoSpec, baseBranch) {const raw = await execGh([- 'pr', 'list',+ 'pr', 'list', '--repo', repoSpec,'--base', baseBranch, '--state', 'open','--limit', String(PR_LIST_LIMIT),'--json', 'number,title,author,url,createdAt,isDraft,headRefName'- ], repoPath).catch(() => null);+ ]).catch(() => null);if (raw === null) return null;// Guard the parse: a success-exit gh that emits empty/malformed stdout would// otherwise throw a SyntaxError, breaking this module's "never throws"@@ -199,9 +202,14 @@ export async function checkPullRequests(app, { authorFilter = 'any' } = {}) {return { ok: false, reason: 'not-a-github-repo' };}const repoFullName = origin.fullName;- const { repoPath } = app;+ // Host-qualified `HOST/OWNER/REPO` selector for gh's `--repo`. The host+ // qualifier fixes the original bug (a bare `OWNER/REPO` defaults to+ // github.com, so enterprise repos were silently queried against github.com)+ // AND stays deterministic on a fork+upstream checkout, where relying on gh's+ // cwd remote-detection would ambiguously resolve to the parent repo.+ const repoSpec = `${origin.host}/${repoFullName}`;- const defaultBranch = await getDefaultBranch(repoPath);+ const defaultBranch = await getDefaultBranch(repoSpec);if (!defaultBranch) {return { ok: false, reason: 'default-branch-unresolved', repoFullName };}@@ -216,7 +224,7 @@ export async function checkPullRequests(app, { authorFilter = 'any' } = {}) {}}- const prs = await listOpenPullRequests(repoPath, defaultBranch);+ const prs = await listOpenPullRequests(repoSpec, defaultBranch);if (prs === null) {return { ok: false, reason: 'pr-list-failed', repoFullName, defaultBranch };}diff --git a/server/services/prWatcher.test.js b/server/services/prWatcher.test.jsindex 89be954b4a..3bf68c24fa 100644--- a/server/services/prWatcher.test.js+++ b/server/services/prWatcher.test.js@@ -260,8 +260,18 @@ describe('checkPullRequests', () => {const r = await checkPullRequests({ id: 'ent', repoPath: '/repos/ent', prWatcherState: { lastSeenPrNumber: 6 } }, { authorFilter: 'self' });expect(r.ok).toBe(true);expect(r.newPrs.map(p => p.number)).toEqual([7]);- // self was resolved on the enterprise host, so the enterprise-login PR matches.+ // Mechanism assertions (not just the end result): self is resolved on the+ // enterprise host via --hostname, and repo view / pr list pin the+ // host-qualified HOST/OWNER/REPO selector. These pin the exact contract so a+ // regression that reintroduced the original bug — a host-less `--repo o/r`+ // (defaults to github.com) or a dropped host qualifier — fails here.expect(execGhMock).toHaveBeenCalledWith(['api', 'user', '--hostname', 'github.enterprise.test', '--jq', '.login']);+ expect(execGhMock).toHaveBeenCalledWith(['repo', 'view', 'github.enterprise.test/o/r', '--json', 'defaultBranchRef', '-q', '.defaultBranchRef.name']);+ expect(execGhMock).toHaveBeenCalledWith(['pr', 'list', '--repo', 'github.enterprise.test/o/r', '--base', 'main', '--state', 'open', '--limit', '200', '--json', 'number,title,author,url,createdAt,isDraft,headRefName']);+ // No call ever passes a host-less `--repo o/r` (the exact original bug).+ const usedHostlessRepo = execGhMock.mock.calls.some(([args]) =>+ Array.isArray(args) && args.indexOf('--repo') !== -1 && args[args.indexOf('--repo') + 1] === 'o/r');+ expect(usedHostlessRepo).toBe(false);});it('rejects a non-GitHub (GitLab) host as not-a-github-repo', async () => {