Skip to content

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

refactor([issue-2650]): extract shared githubRepoSpec helper for the --repo selector

[._.]/ Adam Eivyc0bfdc574009
diff --git a/server/lib/README.md b/server/lib/README.md
index 3da39b2cf5..f7af38c904 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -283,7 +283,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `streamBackpressure.js` | `awaitWritableDrain(res)` — park a streaming-response producer on the socket's next `drain` (or `close`) when `res.write()` returned false, so SSE/NDJSON writes stay bounded for a slow reader. Shared by `routes/ask.js` (SSE) and `routes/localLlm.js` (NDJSON). |
| `uuid.js` | `v4()` thin wrapper over `crypto.randomUUID()`. |
| `versionUtils.js` | `compareSemver(a, b)` — semver ordering (-1/0/1) with pre-release precedence and build-metadata stripping. Shared by the self-update checker (`updateChecker.js`) and the local-LLM Ollama update detector (`localLlm.js`). Inputs must be `v`-stripped. |
-| `workTracker.js` | `WORK_TRACKERS`/`CONCRETE_WORK_TRACKERS`/`DEFAULT_WORK_TRACKER`, `workTrackerLabel`, `hostToWorkTracker`, `isGithubHost` (GitHub-family host test — github.com + enterprise github.*; enterprise-aware replacement for the github.com-only `isGithub` gate, shared by prWatcher/branchReconcile/issueReconcile), `forgeCliForTracker`, `trackerToClaimTaskType`, `hostFromOriginUrl` (subgroup-tolerant host parse), pure `resolveWorkTracker({configured,host})`, async `resolveAppWorkTracker(app)` — resolves a managed app's autonomous work source (PLAN.md / GitHub / GitLab / JIRA), defaulting `'auto'` to the git origin host. Consumed by the `claim-work` router in `cosTaskGenerator.js` and `routes/apps.js`. |
+| `workTracker.js` | `WORK_TRACKERS`/`CONCRETE_WORK_TRACKERS`/`DEFAULT_WORK_TRACKER`, `workTrackerLabel`, `hostToWorkTracker`, `isGithubHost` (GitHub-family host test — github.com + enterprise github.*; enterprise-aware replacement for the github.com-only `isGithub` gate), `githubRepoSpec(origin)` (host-qualified `HOST/OWNER/REPO` selector for `gh --repo`, or null for a non-GitHub origin — pairs the isGithubHost gate with the selector so prWatcher/branchReconcile/issueReconcile share one "resolvable GitHub repo" definition), `forgeCliForTracker`, `trackerToClaimTaskType`, `hostFromOriginUrl` (subgroup-tolerant host parse), pure `resolveWorkTracker({configured,host})`, async `resolveAppWorkTracker(app)` — resolves a managed app's autonomous work source (PLAN.md / GitHub / GitLab / JIRA), defaulting `'auto'` to the git origin host. Consumed by the `claim-work` router in `cosTaskGenerator.js` and `routes/apps.js`. |
| `workspaceRoots.js` | Shared allow-list for routes that take a caller-supplied filesystem path. `ALLOWED_WORKSPACE_ROOTS` (defaults + `PORTOS_WORKSPACE_ROOTS`, symlink-resolved), `isWithinRoot(resolvedPath, root)` (separator-safe containment), `isWithinAllowedRoots(realPath)`, and `WORKSPACE_ROOTS_CONFIGURED` (true when the operator set the env var — lets a permissive-by-default route like `routes/detect.js` opt into confinement). Used by `routes/commands.js` (always scoped) and `routes/detect.js` (scoped only when configured). |
| `zodCompat.js` | Zod 4 compatibility helpers. `partialWithoutDefaults(objectSchema)` — like `.partial()` but strips inner field defaults first, so a PATCH/update schema doesn't inject (and clobber) the stored values of fields the caller didn't send. Use for any update schema derived from a defaulted base. |
diff --git a/server/lib/workTracker.js b/server/lib/workTracker.js
index 2d0ecc7e5d..b3b82599f7 100644
--- a/server/lib/workTracker.js
+++ b/server/lib/workTracker.js
@@ -66,6 +66,26 @@ export function isGithubHost(host) {
return hostToWorkTracker(host) === 'github';
}
+/**
+ * Build the host-qualified `HOST/OWNER/REPO` selector for `gh --repo` from a
+ * `getOriginInfo()` result, or null when the origin isn't a usable GitHub repo
+ * (no origin, unparsed owner/repo, or a non-GitHub host). The host qualifier is
+ * load-bearing: a bare `OWNER/REPO` defaults `gh` to github.com, so enterprise
+ * repos would be silently queried against github.com — and it stays
+ * deterministic on a fork+upstream checkout where gh's cwd remote-detection
+ * ambiguously resolves to the parent repo. Pairs the isGithubHost gate with the
+ * selector so prWatcher, branchReconcile, and issueReconcile share one
+ * definition of "a resolvable GitHub repo" instead of three hand-copied ones.
+ * (No separate `hasOrigin` check: isGithubHost is true only for a real GitHub
+ * host string, which getOriginInfo returns only when an origin exists.)
+ * @param {{host?:string|null, fullName?:string|null}} origin
+ * @returns {string|null}
+ */
+export function githubRepoSpec(origin) {
+ if (!origin?.fullName || !isGithubHost(origin.host)) return null;
+ return `${origin.host}/${origin.fullName}`;
+}
+
/**
* Which forge CLI a concrete tracker drives: github → `gh`, gitlab → `glab`.
* PLAN.md and JIRA have no forge CLI, so they return null.
diff --git a/server/lib/workTracker.test.js b/server/lib/workTracker.test.js
index e07d71810d..4fab97db09 100644
--- a/server/lib/workTracker.test.js
+++ b/server/lib/workTracker.test.js
@@ -6,6 +6,7 @@ import {
workTrackerLabel,
hostToWorkTracker,
isGithubHost,
+ githubRepoSpec,
forgeCliForTracker,
trackerToClaimTaskType,
resolveWorkTracker,
@@ -56,6 +57,22 @@ describe('isGithubHost', () => {
});
});
+describe('githubRepoSpec', () => {
+ it('builds a host-qualified selector for github.com and enterprise hosts', () => {
+ expect(githubRepoSpec({ host: 'github.com', fullName: 'atomantic/PortOS' }))
+ .toBe('github.com/atomantic/PortOS');
+ expect(githubRepoSpec({ host: 'github.acme.example', fullName: 'acme/app' }))
+ .toBe('github.acme.example/acme/app');
+ });
+ it('returns null for a non-GitHub host, a missing owner/repo, or no origin', () => {
+ expect(githubRepoSpec({ host: 'gitlab.com', fullName: 'group/proj' })).toBeNull();
+ expect(githubRepoSpec({ host: 'bitbucket.org', fullName: 'team/proj' })).toBeNull();
+ expect(githubRepoSpec({ host: 'github.com', fullName: null })).toBeNull();
+ expect(githubRepoSpec({ host: null, fullName: null })).toBeNull();
+ expect(githubRepoSpec(null)).toBeNull();
+ });
+});
+
describe('forgeCliForTracker', () => {
it('maps forge trackers to their CLI, others to null', () => {
expect(forgeCliForTracker('github')).toBe('gh');
diff --git a/server/services/branchReconcile.js b/server/services/branchReconcile.js
index cd54d94794..4542a02421 100644
--- a/server/services/branchReconcile.js
+++ b/server/services/branchReconcile.js
@@ -22,7 +22,7 @@ import { execGit } from '../lib/execGit.js';
import { listWorktrees, forceRemoveWorktreeDir, classifyWorktreeDirt, isHumanClaimWorktree } from './worktreeManager.js';
import { execGh } from './github.js';
import { getOriginInfo } from '../lib/gitRemote.js';
-import { isGithubHost } from '../lib/workTracker.js';
+import { githubRepoSpec } from '../lib/workTracker.js';
import { safeJSONParse, PATHS } from '../lib/fileUtils.js';
// Never reconciled — these are long-lived shared branches, not disposable work.
@@ -97,11 +97,10 @@ async function getOpenPrsByHead(repoPath) {
const origin = await getOriginInfo(repoPath).catch(() => null);
// Accept any GitHub-family host (github.com AND enterprise github.*), mirroring
// prWatcher.checkPullRequests. `origin.isGithub` is github.com-only, so gating
- // on it silently skipped enterprise repos. The host-qualified `HOST/OWNER/REPO`
- // selector keeps gh deterministic on a fork+upstream checkout (a bare
- // OWNER/REPO defaults to github.com) — the same reason prWatcher pins the host.
- if (!origin?.hasOrigin || !origin.fullName || !isGithubHost(origin.host)) return new Map();
- const repoSpec = `${origin.host}/${origin.fullName}`;
+ // on it silently skipped enterprise repos. githubRepoSpec pairs that gate with
+ // the host-qualified `HOST/OWNER/REPO` selector (null for a non-GitHub origin).
+ const repoSpec = githubRepoSpec(origin);
+ if (!repoSpec) return new Map();
const raw = await execGh([
'pr', 'list', '--repo', repoSpec, '--state', 'open',
'--limit', String(PR_LIST_LIMIT),
diff --git a/server/services/issueReconcile.js b/server/services/issueReconcile.js
index f920ab378b..b76b7eae38 100644
--- a/server/services/issueReconcile.js
+++ b/server/services/issueReconcile.js
@@ -55,7 +55,7 @@ import { execGh } from './github.js';
import { execGlab } from './gitlab.js';
import { fetchMyCurrentSprintTickets } from './jira.js';
import { getOriginInfo, readOriginRemoteUrl } from '../lib/gitRemote.js';
-import { hostToWorkTracker, hostFromOriginUrl, isGithubHost } from '../lib/workTracker.js';
+import { hostToWorkTracker, hostFromOriginUrl, githubRepoSpec } from '../lib/workTracker.js';
import { safeJSONParse, PATHS } from '../lib/fileUtils.js';
// Bound the forge queries (single-user repos never realistically truncate at 200).
@@ -378,10 +378,10 @@ function gitlabProjectPath(originUrl) {
* state. github.* → GitHub, gitlab.* → GitLab; any other remote (or no origin)
* returns null so the caller skips without parking.
*
- * GitHub is classified off the origin HOST via `isGithubHost` (github.com AND
- * enterprise github.*), mirroring prWatcher — `getOriginInfo().isGithub` is
- * github.com-only and silently skipped enterprise repos. It still needs a parsed
- * `owner/repo` for the host-qualified `--repo` selector. GitLab is classified
+ * GitHub is resolved via `githubRepoSpec` (github.com AND enterprise github.*),
+ * mirroring prWatcher — `getOriginInfo().isGithub` is github.com-only and
+ * silently skipped enterprise repos. That helper also needs a parsed `owner/repo`
+ * to build the host-qualified `--repo` selector. GitLab is classified
* straight off the origin HOST via the
* subgroup-safe `hostFromOriginUrl`, NOT `getOriginInfo().fullName`: the latter's
* strict `owner/repo` parse returns null for a nested `group/subgroup/project`
@@ -392,11 +392,11 @@ function gitlabProjectPath(originUrl) {
*/
async function getForgeState(repoPath) {
const origin = await getOriginInfo(repoPath).catch(() => null);
- // GitHub (incl. enterprise): needs a parsed owner/repo for the host-qualified
- // `HOST/OWNER/REPO` --repo selector (deterministic on fork+upstream checkouts).
- if (isGithubHost(origin?.host) && origin.fullName) {
- return getGithubState(`${origin.host}/${origin.fullName}`, origin.fullName);
- }
+ // GitHub (incl. enterprise): githubRepoSpec is the host-qualified
+ // `HOST/OWNER/REPO` --repo selector (deterministic on fork+upstream checkouts),
+ // or null when the origin isn't a resolvable GitHub repo.
+ const githubSpec = githubRepoSpec(origin);
+ if (githubSpec) return getGithubState(githubSpec, origin.fullName);
// GitLab: classify off the host (subgroup-safe). `glab` is cwd-based, so a
// display path is best-effort — prefer getOriginInfo's fullName, else derive the
diff --git a/server/services/issueReconcile.test.js b/server/services/issueReconcile.test.js
index c273058770..24232941c6 100644
--- a/server/services/issueReconcile.test.js
+++ b/server/services/issueReconcile.test.js
@@ -32,7 +32,7 @@ vi.mock('../lib/workTracker.js', async (importActual) => {
return {
hostToWorkTracker: actual.hostToWorkTracker,
hostFromOriginUrl: actual.hostFromOriginUrl,
- isGithubHost: actual.isGithubHost,
+ githubRepoSpec: actual.githubRepoSpec,
};
});
vi.mock('../lib/fileUtils.js', () => ({
diff --git a/server/services/prWatcher.js b/server/services/prWatcher.js
index 46a7f97a58..fef32f3d54 100644
--- a/server/services/prWatcher.js
+++ b/server/services/prWatcher.js
@@ -27,7 +27,7 @@
import { execGh } from './github.js';
import { getAppById, updateApp } from './apps.js';
import { getOriginInfo } from '../lib/gitRemote.js';
-import { isGithubHost } from '../lib/workTracker.js';
+import { githubRepoSpec } from '../lib/workTracker.js';
import { PR_AUTHOR_FILTERS } from '../lib/validation.js';
import { safeJSONParse } from '../lib/fileUtils.js';
@@ -196,18 +196,14 @@ export async function checkPullRequests(app, { authorFilter = 'any' } = {}) {
// Accept any GitHub-family host — github.com AND self-hosted GitHub Enterprise
// (github.*) — not just github.com. `origin.isGithub` is github.com-only (it
// drives PortOS's own fork/update flow), so gating on it silently excluded
- // enterprise repos. isGithubHost classifies enterprise GitHub the same way the
- // claim-issue router does; gitlab.* and non-forge hosts fall through.
- if (!origin?.hasOrigin || !origin.fullName || !isGithubHost(origin.host)) {
+ // enterprise repos. githubRepoSpec pairs the GitHub-host gate with the
+ // host-qualified `HOST/OWNER/REPO` selector (null when not a resolvable GitHub
+ // repo); gitlab.* and non-forge hosts fall through.
+ const repoSpec = githubRepoSpec(origin);
+ if (!repoSpec) {
return { ok: false, reason: 'not-a-github-repo' };
}
const repoFullName = origin.fullName;
- // 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(repoSpec);
if (!defaultBranch) {