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): fix TUI env ordering and pin-token contract
[._.]/ Adam Eivyc6a3d450849d
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 73b6d61ef2..3d2de8bf5e 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -205,8 +205,10 @@ export function createAgentTuiSession({ agentId, provider, model, tuiConfig, cwd// Only AI agent sessions get this — the user's own Shell page does not.// opencodeEnv comes after provider.envVars to override the static config.// forgeTokenEnv is threaded in explicitly because buildSafeEnv strips- // GH_TOKEN from the inherited env (see resolveForgeTokenEnv).- env: { ...(provider.envVars || {}), ...opencodeEnv, ...forgeTokenEnv, ...agentGuardEnv() },+ // GH_TOKEN from the inherited env (see resolveForgeTokenEnv); it goes before+ // provider.envVars so an explicit provider GH_TOKEN override still wins,+ // matching the direct-CLI and runner spawn paths.+ env: { ...forgeTokenEnv, ...(provider.envVars || {}), ...opencodeEnv, ...agentGuardEnv() },onData,onExit,});diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex a6c44646f5..2557c61dc8 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -446,6 +446,25 @@ describe('spawnTuiAgent runtime', () => {await completeDone;});+ it('lets an explicit provider GH_TOKEN override win over the owner-pinned token (spread order matches the CLI/runner paths)', async () => {+ let resolveComplete;+ const completeDone = new Promise((r) => { resolveComplete = r; });+ vi.mocked(agentLifecycle.finalizeAgent).mockImplementation(async () => { resolveComplete(); });+ vi.mocked(gitService.resolveForgeTokenEnv).mockResolvedValueOnce({ GH_TOKEN: 'ghp_owner_pinned' });++ runSpawn({ provider: { id: 'codex-tui', name: 'Codex TUI', type: 'tui', envVars: { GH_TOKEN: 'ghp_provider_override' } } });+ await flushMicrotasks();++ // provider.envVars.GH_TOKEN must win — forgeTokenEnv is spread first.+ expect(shellService.createShellSession).toHaveBeenCalledWith(+ null,+ expect.objectContaining({ env: expect.objectContaining({ GH_TOKEN: 'ghp_provider_override' }) }),+ );++ await capturedOnExit({ exitCode: 0, killed: false });+ await completeDone;+ });+// ── 1. Successful idle-complete path ────────────────────────────────────────it('idle-complete: calls finalizeAgent(success:true) with completionReason=idle-complete when idle fires after enough output and runtime', async () => {// Wire finalizeAgent to resolve a promise we can await, so we can detectdiff --git a/server/services/git.js b/server/services/git.jsindex 27ac10443f..ac6a93b915 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -372,10 +372,14 @@ export async function resolveForgeForRepo(dir) {*/export async function resolveForgeTokenEnv(dir) {const resolved = await resolveForgeForRepo(dir).catch(() => null);- // Only overlay when an owner-matched account was actually picked — the- // no-match branches of resolveForgeForRepo return the ambient env verbatim,- // and re-setting the ambient GH_TOKEN would be a meaningless no-op.- const token = resolved?.account ? resolved.env?.GH_TOKEN : null;+ // resolveForgeForRepo returns a NEW env object (`{ ...process.env, GH_TOKEN }`)+ // ONLY when it successfully minted an owner-matched token; every other branch+ // (unparseable remote, glab, no account match, token fetch failed) returns the+ // ambient `process.env` by reference. So an identity check on the env object is+ // the precise "a pinned token was minted" signal — keying on `account` alone+ // would wrongly re-emit the ambient GH_TOKEN when the account matched but the+ // token fetch failed (that branch keeps `account` set but env === process.env).+ const token = resolved && resolved.env !== process.env ? resolved.env.GH_TOKEN : null;return token ? { GH_TOKEN: token } : {};}