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
fix: pin claim-issue detector to the app's GitHub account
Adam Eivy8ad4d98f6dc2
diff --git a/docs/MANAGED_APP_FORGE_ACCOUNTS.md b/docs/MANAGED_APP_FORGE_ACCOUNTS.mdindex e6e6df1c30..2364343219 100644--- a/docs/MANAGED_APP_FORGE_ACCOUNTS.md+++ b/docs/MANAGED_APP_FORGE_ACCOUNTS.md@@ -55,13 +55,19 @@ gh auth login # once per account; `gh auth status` should list them all```When set, PortOS pins **both halves** of that identity for every agent it-launches against the app's repo (and every worktree of it):+launches against the app's repo (and every worktree of it), and for PortOS-owned+`gh` probes against that repo (the claim-issue work detector and scheduled-task+issue preloads):| | ||---|---|-| `GH_TOKEN` | minted for that account, so `gh pr create` and `git push` act as it |+| `GH_TOKEN` | minted for that account, so `gh pr create`, `git push`, and issue-list probes act as it || `GIT_AUTHOR_*` / `GIT_COMMITTER_*` | `<id>+<login>@users.noreply.github.com`, the address GitHub attributes back to the account |+Without the probe pin, those checks inherit the install's ambient `GH_TOKEN` or+active `gh` user, so a private repo under another logged-in account fails the+detector as a transient forge error and never dispatches an agent.+The credential and the authorship move together on purpose: authenticating asanother account while committing under the machine owner's name and email writesthe wrong person into someone else's repository history.diff --git a/server/services/perpetualWork.js b/server/services/perpetualWork.jsindex 83a1f7c167..3c7b79c351 100644--- a/server/services/perpetualWork.js+++ b/server/services/perpetualWork.js@@ -141,14 +141,14 @@ async function resolveGitlabNamespace(repoPath) {* `forge` selects how open changes are listed: GitHub PR head refs* (`gh pr list`) vs GitLab MR source branches (`glab mr list`).*/-async function inFlightIssueNumbers(repoPath, forge = 'github') {+async function inFlightIssueNumbers(repoPath, forge = 'github', env) {const nums = new Set();// The branch list and the PR/MR list are independent CLI calls — run concurrently.const prListCall = forge === 'gitlab'- ? runCli('glab', withGlabJson(['mr', 'list', '--per-page', '100']), repoPath)- : runCli('gh', ['pr', 'list', '--state', 'open', '--json', 'headRefName', '-q', '.[].headRefName'], repoPath);+ ? runCli('glab', withGlabJson(['mr', 'list', '--per-page', '100']), repoPath, env)+ : runCli('gh', ['pr', 'list', '--state', 'open', '--json', 'headRefName', '-q', '.[].headRefName'], repoPath, env);const [branchRes, prRes] = await Promise.all([- runCli('git', ['branch', '-a', '--no-color', '--format=%(refname:short)'], repoPath),+ runCli('git', ['branch', '-a', '--no-color', '--format=%(refname:short)'], repoPath, env),prListCall]);const refs = (branchRes.stdout || '').split('\n').map((s) => s.trim()).filter(Boolean);@@ -344,6 +344,30 @@ const GLAB_SELF_LOGIN_ARGS = ['api', 'user'];// queried and the truncation is LOGGED — never dropped silently.const MAX_COLLABORATOR_AUTHOR_QUERIES = 25;+/**+ * Env for PortOS-owned `gh` probes against a managed app.+ *+ * Agents already get `resolveForgeTokenEnv` so `gh` authenticates as the app's+ * pinned (or owner-matched) account. The claim-issue detector used to inherit+ * the install's ambient `GH_TOKEN` / active `gh` user instead, so a private+ * repo under a different logged-in account failed the list as a "transient+ * forge" blip and never dispatched. A caller-supplied `env` wins (prompt+ * preloads already resolve the same overlay); otherwise mint and merge here.+ * `GITHUB_TOKEN` / enterprise aliases from another account are dropped so they+ * cannot outrank the pin.+ */+async function resolveGithubDetectorEnv(repoPath, env) {+ if (env) return env;+ const { resolveForgeTokenEnv } = await import('./forgeAuth.js');+ const overlay = await resolveForgeTokenEnv(repoPath).catch(() => ({}));+ if (!overlay?.GH_TOKEN) return undefined;+ const merged = { ...process.env, ...overlay };+ delete merged.GITHUB_TOKEN;+ delete merged.GH_ENTERPRISE_TOKEN;+ delete merged.GITHUB_ENTERPRISE_TOKEN;+ return merged;+}+// Per-forge config for the shared issue detector. Each entry captures only what// differs between GitHub (`gh`) and GitLab (`glab`): the CLI + issue-list args,// how owner/self/collaborators mode resolves the author filter, the transient@@ -507,6 +531,7 @@ async function detectForgeIssues(forgeKey, app, { issueAuthorFilter = 'self', isconst cfg = FORGE_ISSUE_CONFIG[forgeKey];const repoPath = app?.repoPath;if (!repoPath) return { actionable: false, count: 0, reason: 'no-repo-path' };+ if (cfg.cli === 'gh') env = await resolveGithubDetectorEnv(repoPath, env);// Shared shape for a "parked" (no actionable work) result where only `reason`// and `total` (the open-issue denominator) vary. `count`/`inFlightCount`/@@ -663,7 +688,7 @@ async function detectForgeIssues(forgeKey, app, { issueAuthorFilter = 'self', isconst hasAssignedIssue = issues.some((issue) => Array.isArray(issue.assignees) && issue.assignees.length > 0);const [inFlight, currentLoginResult] = await Promise.all([- inFlightIssueNumbers(repoPath, cfg.inFlightForge),+ inFlightIssueNumbers(repoPath, cfg.inFlightForge, env),hasAssignedIssue? resolveAuthenticatedLogin(cfg.cli, cfg.selfLoginArgs, repoPath, env): Promise.resolve({ login: null })diff --git a/server/services/perpetualWork.test.js b/server/services/perpetualWork.test.jsindex 5201fd35a9..c74e1354f9 100644--- a/server/services/perpetualWork.test.js+++ b/server/services/perpetualWork.test.js@@ -11,7 +11,12 @@ vi.mock('../lib/childProcess.js', async (importOriginal) => {return { ...actual, spawn: vi.fn() };});+vi.mock('./forgeAuth.js', () => ({+ resolveForgeTokenEnv: vi.fn(async () => ({}))+}));+import { spawn } from '../lib/childProcess.js';+import { resolveForgeTokenEnv } from './forgeAuth.js';import {isActionableIssue,titleMarksEpic,@@ -221,7 +226,11 @@ describe('perpetualWork', () => {});describe('detectGithubIssues (spawn-mocked)', () => {- beforeEach(() => { spawn.mockReset(); });+ beforeEach(() => {+ spawn.mockReset();+ resolveForgeTokenEnv.mockReset();+ resolveForgeTokenEnv.mockResolvedValue({});+ });const app = { id: 'a', repoPath: '/repo' };it('counts actionable issues, excluding labelled/assigned/in-flight', async () => {@@ -565,6 +574,7 @@ describe('perpetualWork', () => {expect(spawn.mock.calls.filter(([cmd]) => cmd === 'gh').every(([, , options]) =>options.env?.PATH === '/bin')).toBe(true);+ expect(resolveForgeTokenEnv).not.toHaveBeenCalled();expect(authorListCalls()).toEqual(['alice', 'bob', 'carol']);});@@ -652,12 +662,64 @@ describe('perpetualWork', () => {expect(out).toMatchObject({ reason: 'gh-unavailable', transient: true });});});++ it('runs every gh probe as the repo-pinned account, not the ambient credential', async () => {+ // Ambient GH_TOKEN/GITHUB_TOKEN are the install's default account; a+ // managed app under a different logged-in login must not inherit them.+ vi.stubEnv('GH_TOKEN', 'ambient-owner-token');+ vi.stubEnv('GITHUB_TOKEN', 'other-account-token');+ vi.stubEnv('GH_ENTERPRISE_TOKEN', 'enterprise-token');+ resolveForgeTokenEnv.mockResolvedValue({ GH_TOKEN: 'app-account-token' });+ routeSpawn({+ 'gh issue': { stdout: '[]' },+ 'git branch': { stdout: 'main\n' },+ 'gh pr': { stdout: '' }+ });+ try {+ await detectGithubIssues(app, { issueAuthorFilter: 'any' });+ expect(resolveForgeTokenEnv).toHaveBeenCalledWith('/repo');+ const ghCalls = spawn.mock.calls.filter(([cmd]) => cmd === 'gh');+ expect(ghCalls.length).toBeGreaterThan(0);+ for (const [, , options] of ghCalls) {+ expect(options.env.GH_TOKEN).toBe('app-account-token');+ expect(options.env).not.toHaveProperty('GITHUB_TOKEN');+ expect(options.env).not.toHaveProperty('GH_ENTERPRISE_TOKEN');+ }+ } finally {+ vi.unstubAllEnvs();+ }+ });++ it('leaves gh on ambient auth when no account token can be minted', async () => {+ routeSpawn({+ 'gh issue': { stdout: '[]' },+ 'git branch': { stdout: 'main\n' },+ 'gh pr': { stdout: '' }+ });+ await detectGithubIssues(app, { issueAuthorFilter: 'any' });+ expect(resolveForgeTokenEnv).toHaveBeenCalledWith('/repo');+ const ghCalls = spawn.mock.calls.filter(([cmd]) => cmd === 'gh');+ expect(ghCalls.length).toBeGreaterThan(0);+ expect(ghCalls.every(([, , options]) => !options.env)).toBe(true);+ });});describe('detectGitlabIssues (spawn-mocked)', () => {beforeEach(() => { spawn.mockReset(); });const app = { id: 'a', repoPath: '/repo' };+ it('does not overlay a GitHub token onto glab probes', async () => {+ resolveForgeTokenEnv.mockResolvedValue({ GH_TOKEN: 'app-account-token' });+ routeSpawn({+ 'glab issue': { stdout: '[]' },+ 'git branch': { stdout: 'main\n' },+ 'glab mr': { stdout: '[]' }+ });+ await detectGitlabIssues(app, { issueAuthorFilter: 'any' });+ expect(resolveForgeTokenEnv).not.toHaveBeenCalled();+ expect(spawn.mock.calls.filter(([cmd]) => cmd === 'glab').every(([, , options]) => !options.env)).toBe(true);+ });+it('normalizes iid + string labels and excludes MR-in-flight issues', async () => {routeSpawn({'glab issue': { stdout: JSON.stringify([