Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(scm): publish reuses the existing git token — no separate gh login

enes07a1391ea742
diff --git a/src/main/git-service.ts b/src/main/git-service.ts
index b8f661993..fb510fa88 100644
--- a/src/main/git-service.ts
+++ b/src/main/git-service.ts
@@ -1,4 +1,4 @@
-import { execFile } from 'child_process'
+import { execFile, spawn } from 'child_process'
import fs from 'fs'
import path from 'path'
import { promisify } from 'util'
@@ -107,6 +107,36 @@ function parseNumstat(out: string): Map<string, { added: number; deleted: number
return map
}
+/**
+ * Read the user's stored github.com HTTPS token from git's credential helper
+ * (macOS keychain etc.) so we can hand it to `gh` as GH_TOKEN — letting someone
+ * who can already push over HTTPS publish a new repo without a separate
+ * `gh auth login`. Returns null if no HTTPS credential is stored (e.g. SSH-only).
+ * Never logs the token. `git credential fill` reads the query from stdin.
+ */
+function githubTokenFromGitCredentials(cwd: string): Promise<string | null> {
+ return new Promise((resolve) => {
+ let out = ''
+ const child = spawn('git', ['credential', 'fill'], { cwd: cwd || undefined, env: GIT_ENV })
+ const timer = setTimeout(() => child.kill('SIGKILL'), 5000)
+ child.stdout.on('data', (d) => {
+ out += d.toString()
+ })
+ child.on('error', () => {
+ clearTimeout(timer)
+ resolve(null)
+ })
+ child.on('close', () => {
+ clearTimeout(timer)
+ const line = out.split('\n').find((l) => l.startsWith('password='))
+ const token = line ? line.slice('password='.length).trim() : ''
+ resolve(token || null)
+ })
+ child.stdin.write('protocol=https\nhost=github.com\n\n')
+ child.stdin.end()
+ })
+}
+
/**
* Per-project git operations using the system `git` (and `gh` for publishing).
* The repo root is the active project's working directory.
@@ -427,16 +457,33 @@ export class GitService {
if (!repo || repo.startsWith('-') || !/^[A-Za-z0-9._/-]+$/.test(repo)) {
return { ok: false, message: 'Invalid repository name.' }
}
+ // Prefer gh's own login; otherwise reuse the user's existing git HTTPS token
+ // (the one that already lets them push) so publishing doesn't demand a separate
+ // `gh auth login`. If neither is available, signal the UI to start a login.
+ const env: NodeJS.ProcessEnv = { ...GIT_ENV }
+ if (!(await ghAuthed())) {
+ const token = await githubTokenFromGitCredentials(cwd)
+ if (!token) {
+ return { ok: false, message: 'Sign in to GitHub to publish.', needsAuth: true }
+ }
+ env.GH_TOKEN = token
+ }
try {
await run(
GH_PATH,
['repo', 'create', repo, isPrivate ? '--private' : '--public', '--source=.', '--push'],
- { cwd, env: GIT_ENV, maxBuffer: 10 * 1024 * 1024 }
+ { cwd, env, maxBuffer: 10 * 1024 * 1024 }
)
return { ok: true, message: 'Published to GitHub.' }
} catch (e) {
const err = e as { stderr?: string; message?: string }
- return { ok: false, message: (err.stderr || err.message || 'gh failed').trim() }
+ const msg = (err.stderr || err.message || 'gh failed').trim()
+ // A reused token without repo-create scope (or an expired one) reads as an auth
+ // failure — let the UI offer a full login rather than a dead-end error.
+ if (/\b(401|403)\b|unauthor|forbidden|auth|token|scope|HTTP 4/i.test(msg)) {
+ return { ok: false, message: msg, needsAuth: true }
+ }
+ return { ok: false, message: msg }
}
}
}
diff --git a/src/renderer/components/SourceControlPanel.tsx b/src/renderer/components/SourceControlPanel.tsx
index 66b38c55d..f71fec4ff 100644
--- a/src/renderer/components/SourceControlPanel.tsx
+++ b/src/renderer/components/SourceControlPanel.tsx
@@ -505,19 +505,30 @@ export function SourceControlPanel({
<PublishDialog
defaultName={project?.name || 'repo'}
onCancel={() => setPublishOpen(false)}
- onPublish={(name, isPrivate) => {
+ onPublish={async (name, isPrivate) => {
setPublishOpen(false)
- if (status?.ghAuthed) {
- void act(() => git.publish(cwd!, name, isPrivate))
- } else {
- // Not signed in: run the interactive gh login, chained straight into
- // creating + pushing the chosen repo, so login flows into publish.
+ // Always try in-app: publish() reuses gh's login OR the user's existing git
+ // HTTPS token, so an already-authenticated user never sees a terminal.
+ setBusy(true)
+ const r = await git.publish(cwd!, name, isPrivate)
+ setBusy(false)
+ if (r.ok) {
+ setError('')
+ await refresh()
+ await refreshHistory()
+ return
+ }
+ if (r.needsAuth) {
+ // No usable credential (e.g. SSH-only): fall back to an interactive gh
+ // login chained straight into creating + pushing the chosen repo.
const safe = name.replace(/'/g, `'\\''`)
onRunInTerminal(
`gh auth login && gh repo create '${safe}' ${isPrivate ? '--private' : '--public'} --source=. --push`
)
onClose()
+ return
}
+ setError(r.message)
}}
/>
)}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 8bfa4a319..266ea307a 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -280,6 +280,9 @@ export interface GitStatus {
export interface GitResult {
ok: boolean
message: string
+ /** Set by publish() when no usable GitHub credential was found, so the UI can
+ * fall back to an interactive `gh auth login` instead of just showing an error. */
+ needsAuth?: boolean
}
export interface GitApi {