Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bin/omarchy-agent-account-add
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ key_login() {
if [[ $accounts == "false" ]]; then
# Gemini's page ends on a code to paste back, and a key is all there is to
# a key's sign-in; the panel shows a field for either, under what it's for.
if [[ $events == "true" && $provider == "agy" ]]; then
printf '@@omarchy paste %s\n' "$(omarchy-i18n agents.pasteSignInCode)"
fi
if [[ -z $key_provider ]]; then
say "$(omarchy-i18n agents.signInBrowser "$name")"
elif [[ $events == "true" ]]; then
printf '@@omarchy status %s\n@@omarchy key %s\n' "$(omarchy-i18n agents.apiKeyHint "$name")" "$(omarchy-i18n agents.apiKeyHint "$name")"
fi
if [[ $events == "true" && $provider == "agy" ]]; then
printf '@@omarchy paste %s\n' "$(omarchy-i18n agents.pasteSignInCode)"
printf '@@omarchy key %s\n@@omarchy status %s\n' "$(omarchy-i18n agents.apiKeyHint "$name")" "$(omarchy-i18n agents.apiKeyHint "$name")"
fi
interruptible "${login_command[@]}" 2>&1
login_status=$?
Expand All @@ -370,7 +370,7 @@ esac

# The CLI's own home, whatever this shell has pointed it at.
login() {
interruptible env -u CLAUDE_CONFIG_DIR -u CODEX_HOME -u GROK_HOME "OMARCHY_AGENT_${provider^^}_HOME=" "${login_command[@]}"
interruptible env -u CLAUDE_CONFIG_DIR -u CODEX_HOME -u GROK_HOME "OMARCHY_AGENT_${provider^^}_HOME=" "${login_command[@]}" 2>&1
}

# Signing an account that's already here in again: the primary through the
Expand All @@ -394,11 +394,11 @@ if [[ -n $reauth ]]; then

if [[ $(cut -f4 <<<"$found") == "1" ]]; then
say "$(omarchy-i18n agents.signInAgainBrowser "$name")"
interruptible "${where[@]}" "${login_command[@]}" || fail "$(omarchy-i18n agents.signInFailed "$name")"
interruptible "${where[@]}" "${login_command[@]}" 2>&1 || fail "$(omarchy-i18n agents.signInFailed "$name")"
else
say "$(omarchy-i18n agents.signInAgainPrivate)"
private_browser
interruptible "${where[@]}" BROWSER="$browser" "${login_command[@]}" || fail "$(omarchy-i18n agents.signInFailed "$name")"
interruptible "${where[@]}" BROWSER="$browser" "${login_command[@]}" 2>&1 || fail "$(omarchy-i18n agents.signInFailed "$name")"
fi
if [[ $provider == "claude" ]]; then
installed=$(omarchy-agent-account-state relogin "$provider" "$(cut -f1 <<<"$found")" "$home" 2>&1) || fail "$installed"
Expand Down Expand Up @@ -452,7 +452,7 @@ EOF
home=$(omarchy-agent-account-state begin "$provider" "$label" "$$") || fail "$(omarchy-i18n agents.homeFailed)"

private_browser
interruptible env BROWSER="$browser" "$home_env=$home" "${login_command[@]}"
interruptible env BROWSER="$browser" "$home_env=$home" "${login_command[@]}" 2>&1

if account=$(omarchy-agent-account-state register "$provider" "$label" "$home" 2>&1); then
home=""
Expand Down
2 changes: 1 addition & 1 deletion default/i18n/en/cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"agents.sameAccountEmail": "That's %1 (%2). Try again, and sign in as the other account in the private window.",
"agents.keyRefused": "%1 didn't accept that key.",
"agents.keyUnchecked": "Couldn't reach %1 to check that key. Try again in a moment.",
"agents.apiKeyHint": "It's checked with %1, then saved for pi and opencode.",
"agents.apiKeyHint": "It's checked with %1, then saved in OpenCode.",
"agents.pasteSignInCode": "Once you've signed in, paste the code the page shows here.",
"agents.signInAgainBrowser": "Sign in to %1 again in the browser window that opens.",
"agents.signInAgainPrivate": "Sign in again as this account in the private window that opens.",
Expand Down
2 changes: 1 addition & 1 deletion default/i18n/en/shell.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"agents.blockProviders": "USE PAY AS YOU GO",
"agents.blockSubscriptions": "USE A SUBSCRIPTION",
"agents.firstBecomesDefault": "The first one is your default",
"agents.addProviderAccount": "Add %1 account",
"agents.app": "App",
"agents.backToLimits": "Back to the limits",
"agents.balance": "Balance",
Expand Down Expand Up @@ -54,6 +53,7 @@
"agents.outOfCredits": "Out of credits",
"agents.pasteCode": "If the page shows a code instead of finishing, paste it here.",
"agents.pasteCodeLink": "Page showing a code instead?",
"agents.placeholderApiKey": "API key",
"agents.placeholderCode": "Code",
"agents.placeholderWork": "Work",
"agents.plugin": "Plugin",
Expand Down
120 changes: 64 additions & 56 deletions shell/plugins/agents/Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Panel {
for (var r = 0; r < more.length; r++) rows.push([{ kind: "choice", index: more[r].providerId }])
} else if (addStage === "running") {
if (pasteLinkShown) rows.push([{ kind: "pasteCode", index: 0 }])
if (addUrl !== "") rows.push([{ kind: "reopenSignIn", index: 0 }])
if (addUrl !== "" && !addCheckingCode) rows.push([{ kind: "reopenSignIn", index: 0 }])
} else if (addStage === "") {
for (var p = 0; p < providers.length; p++) {
// Every line is a stop, so Ctrl+Up/Down can move it: its terminal
Expand Down Expand Up @@ -904,6 +904,7 @@ Panel {
property string addPasteHint: ""
// An API key is the whole sign-in, with no browser login to speak of.
property bool addKeyEntry: false
property bool addCheckingCode: false
property string addResult: ""
// The CLI's own download, when it isn't installed yet: the first sign-in
// installs it before the browser opens.
Expand Down Expand Up @@ -932,28 +933,24 @@ Panel {
}
property bool addReauth: false
// Signing in takes over the hero: the provider's mark and name, with what's
// being set up below.
readonly property bool setupShown: addStage === "running" && addProviderEntry !== null
// being set up below, from naming through sign-in or failure.
readonly property bool setupShown: (addStage === "name" || addStage === "running" || addStage === "error") && addProviderEntry !== null
readonly property var addProviderEntry: {
for (var i = 0; i < signInProviders.length; i++)
if (signInProviders[i].providerId === addProvider) return signInProviders[i]
return null
}
// Claude only needs a code pasted back when its page shows one, so the
// field waits behind a link until then.
readonly property bool pasteLinkShown: addProvider === "claude" && !addNeedsPaste && !addDownloading
readonly property bool pasteLinkShown: addProvider === "claude" && !addNeedsPaste && !addDownloading && !addCheckingCode
// Whether the sign-in in progress opened a private window, so reopening its
// page does too.
property bool addPrivate: false

function addProviderName(id) {
for (var i = 0; i < signInProviders.length; i++)
if (signInProviders[i].providerId === id) return signInProviders[i].providerName
return id
}

function addAccount() {
if (addStage === "running") return
addProvider = ""
addReauth = false
addStage = "pick"
addChecks = ({})
if (!checkProcess.running) checkProcess.running = true
Expand All @@ -980,8 +977,9 @@ Panel {
else startAdd("")
}

function startAdd(label) {
addPrivate = (addChecks[addProvider] || "") === "additional"
function beginAdd(providerId, isPrivate, isReauth, command) {
addProvider = providerId
addPrivate = isPrivate
addStatus = Commons.I18n.t("agents.starting")
addCode = ""
addUrl = ""
Expand All @@ -991,15 +989,22 @@ Panel {
addNeedsPaste = false
addPasteHint = ""
addKeyEntry = false
addCheckingCode = false
addDownloading = false
addPhase = ""
addFetched = false
addFetchTimer.stop()
addReauth = false
addReauth = isReauth
addResult = ""
addStage = "running"
addProcess.command = ["omarchy-agent-account-add", "--events", addProvider].concat(label !== "" ? [label] : [])
addProcess.command = command
addProcess.running = true
root.focusKeys()
}

function startAdd(label) {
beginAdd(addProvider, (addChecks[addProvider] || "") === "additional", false,
["omarchy-agent-account-add", "--events", addProvider].concat(label !== "" ? [label] : []))
}

function cancelAdd() {
Expand All @@ -1010,6 +1015,9 @@ Panel {
}
if (addProcess.running) addProcess.signal(15)
addFetchTimer.stop()
addCheckingCode = false
addProvider = ""
addReauth = false
addStage = ""
root.focusKeys()
}
Expand All @@ -1024,9 +1032,9 @@ Panel {
function submitPaste(code) {
if (!addProcess.running || code.trim() === "") return
addProcess.write(code.trim() + "\n")
// A code or key that was asked for is the one answer, so its field goes.
if (addPasteHint !== "") addNeedsPaste = false
if (!addKeyEntry) addStatus = Commons.I18n.t("agents.checkingCode")
addNeedsPaste = false
if (!addKeyEntry) addCheckingCode = true
root.focusKeys()
}

// The add command's own lines are tagged; everything else is the CLI
Expand All @@ -1040,6 +1048,7 @@ Panel {
addPasteHint = tagged[2]
addNeedsPaste = true
addKeyEntry = tagged[1] === "key"
addCheckingCode = false
} else if (tagged[1] === "progress") {
var bytes = tagged[2].split(" ")
addDoneBytes = Number(bytes[0]) || 0
Expand All @@ -1063,27 +1072,33 @@ Panel {
addFetchTimer.stop()
addFetched = false
addDownloading = false
addCheckingCode = false
addResult = tagged[2]
// A sign-in that finishes goes straight back to the page, where the
// account shows once its limits arrive.
addStage = tagged[1] === "done" ? "" : tagged[1]
if (tagged[1] === "done") {
setProviderShown(addProvider, true)
addProvider = ""
addReauth = false
usage.refreshLimits()
root.focusKeys()
// Nothing to show yet means the sign-in is what counts as set up.
if (usage.enabledProviders.length === 0 && !checkProcess.running) {
addChecks = ({})
checkProcess.running = true
}
}
root.focusKeys()
}
return
}
// On a line of its own, or after OpenCode's "Enter code:".
var code = text.match(/(?:^|code:)\s*([A-Z0-9]{4}-[A-Z0-9]{4})\s*$/)
if (code) addCode = code[1]
if (/paste code/i.test(text)) addNeedsPaste = true
if (/paste code/i.test(text)) {
addCheckingCode = false
addNeedsPaste = true
}
var url = text.match(/(https:\/\/\S+)/)
if (url && addUrl === "") {
addUrl = url[1]
Expand All @@ -1093,6 +1108,7 @@ Panel {

// The field takes the keys from here, so the cursor lets go of the links.
function openPasteField() {
addCheckingCode = false
addNeedsPaste = true
cursorActive = false
}
Expand Down Expand Up @@ -1313,27 +1329,9 @@ Panel {
// add view just like adding one.
function signInAgain(p, account) {
if (!supportsSignIn(p) || addStage === "running") return
addProvider = p.providerId
addPrivate = !!account && account.primary !== true
addStatus = Commons.I18n.t("agents.starting")
addCode = ""
addUrl = ""
// Claude's login usually finishes on its own once the browser hands back
// to it. When its page shows a code instead, its prompt for it has no
// newline to read it by, so the field stays a link away the whole time.
addNeedsPaste = false
addPasteHint = ""
addKeyEntry = false
addDownloading = false
addPhase = ""
addFetched = false
addFetchTimer.stop()
addReauth = true
addResult = ""
addStage = "running"
addProcess.command = ["omarchy-agent-account-add", "--events", "--reauth",
account && account.primary !== true ? String(account.id) : ":primary", p.providerId]
addProcess.running = true
beginAdd(p.providerId, !!account && account.primary !== true, true,
["omarchy-agent-account-add", "--events", "--reauth",
account && account.primary !== true ? String(account.id) : ":primary", p.providerId])
}

function resetCreditsText(credits) {
Expand Down Expand Up @@ -1852,9 +1850,7 @@ Panel {
// Adding takes over the hero's line, and the cursor starts over.
readonly property string addHeading: setupShown
? (addReauth ? Commons.I18n.t("agents.signingInAgain") : Commons.I18n.t("agents.settingUp"))
: picking || addProvider === ""
? (blankSlate ? Commons.I18n.t("agents.firstBecomesDefault") : Commons.I18n.t("agents.addKinds"))
: Commons.I18n.t("agents.addProviderAccount").arg(addProviderName(addProvider))
: (blankSlate ? Commons.I18n.t("agents.firstBecomesDefault") : Commons.I18n.t("agents.addKinds"))
onAddStageChanged: {
phraseSwap.stop()
if (hero) hero.metaOpacity = 1.0
Expand Down Expand Up @@ -1892,7 +1888,11 @@ Panel {
makesOpenIndex = -1
} else {
deleteTarget = null
if (addStage !== "running") addStage = ""
if (addStage !== "running") {
addStage = ""
addProvider = ""
addReauth = false
}
resetKeys()
if (usage.enabledProviders.length === 0 && !checkProcess.running) checkProcess.running = true
nowMs = Date.now()
Expand Down Expand Up @@ -1956,8 +1956,10 @@ Panel {
stdout: SplitParser { onRead: function(line) { root.handleAddLine(line) } }
onExited: {
if (root.addStage === "running") {
root.addCheckingCode = false
root.addResult = Commons.I18n.t("agents.signInUnfinished")
root.addStage = "error"
root.focusKeys()
}
}
}
Expand Down Expand Up @@ -2086,10 +2088,10 @@ Panel {
Math.max(0, panelFlick.contentHeight - panelFlick.height))
}
onDeleteRequested: root.deleteSelected()
// A code field keeps its own keys: Qt passes Return on after accepting
// it, and here that would press the Cancel under the cursor too,
// stopping the sign-in just handed its code.
blocked: root.renaming || root.deleteTarget !== null || addView.pasteFocused
// A text field keeps its own keys: Qt passes Return on after accepting
// it, and here that would press the Cancel under the cursor too, or
// steal letters like j/k/x from an account name.
blocked: root.renaming || root.deleteTarget !== null || addView.inputFocused
onActivateRequested: root.activateSelection()
onCloseRequested: {
if (root.dragIndex >= 0) root.settleProviderDrag(true)
Expand Down Expand Up @@ -2346,7 +2348,7 @@ Panel {
id: add
spacing: Style.space(14)
// The panel's key catcher can't see inside this component, so it asks here.
readonly property bool pasteFocused: pasteField.activeFocus
readonly property bool inputFocused: pasteField.activeFocus || addNameField.activeFocus

PanelSeparator { foreground: root.foreground }

Expand Down Expand Up @@ -2690,8 +2692,9 @@ Panel {
Text {
width: parent.width
textFormat: Text.PlainText
text: !root.addKeyEntry ? Commons.I18n.t("agents.loginBrowser")
: root.addNeedsPaste ? Commons.I18n.t("agents.enterApiKey") : Commons.I18n.t("agents.checkingKey")
text: root.addKeyEntry
? (root.addNeedsPaste ? Commons.I18n.t("agents.enterApiKey") : Commons.I18n.t("agents.checkingKey"))
: (root.addCheckingCode ? Commons.I18n.t("agents.checkingCode") : Commons.I18n.t("agents.loginBrowser"))
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
Expand All @@ -2700,9 +2703,9 @@ Panel {
}

// Only what the plain line doesn't say: which window to use when it's
// a private one, or that a pasted code is being checked.
// a private one.
Text {
visible: root.addPrivate || root.addStatus === Commons.I18n.t("agents.checkingCode")
visible: root.addPrivate && !root.addCheckingCode
width: parent.width
textFormat: Text.PlainText
text: root.addStatus
Expand Down Expand Up @@ -2754,8 +2757,8 @@ Panel {
TextField {
id: pasteField
width: parent.width
placeholderText: root.addPasteHint === "" ? Commons.I18n.t("agents.placeholderCode") : ""
password: root.addKeyEntry
placeholderText: root.addKeyEntry ? Commons.I18n.t("agents.placeholderApiKey") : Commons.I18n.t("agents.placeholderCode")
password: true
foreground: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
Expand All @@ -2767,6 +2770,11 @@ Panel {
root.pasteFieldItem = visible ? pasteField : null
if (visible) forceActiveFocus()
}
Connections {
target: root
function onAddStageChanged() { if (root.addStage !== "running") pasteField.text = "" }
function onAddNeedsPasteChanged() { if (!root.addNeedsPaste) pasteField.text = "" }
}
Component.onDestruction: if (root.pasteFieldItem === pasteField) root.pasteFieldItem = null
Keys.onEscapePressed: function(event) { root.cancelAdd(); event.accepted = true }
}
Expand All @@ -2781,7 +2789,7 @@ Panel {
}

TextLink {
visible: root.addUrl !== ""
visible: root.addUrl !== "" && !root.addCheckingCode
picked: root.hasKey("reopenSignIn")
onHovered: root.hoverAt("reopenSignIn")
text: Commons.I18n.t("agents.reopenSignIn")
Expand Down
4 changes: 4 additions & 0 deletions test/shell.d/agent-account-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ grep -q "^auth import fw_good$" "$test_tmp/fireworks-opencode" && grep -q "^auth
fail "a Fireworks key is made opencode's active one" "$(cat "$test_tmp/fireworks-opencode")"
grep -q "^@@omarchy key " "$test_tmp/fireworks-output" && grep -qx "@@omarchy done Signed in to Fireworks." "$test_tmp/fireworks-output" ||
fail "the panel is asked for the key and told the result" "$(cat "$test_tmp/fireworks-output")"
key_line=$(grep -n "^@@omarchy key " "$test_tmp/fireworks-output" | cut -d: -f1 | head -1)
status_line=$(grep -n "^@@omarchy status " "$test_tmp/fireworks-output" | cut -d: -f1 | tail -1)
(( key_line < status_line )) ||
fail "key mode arrives before the sign-in status so the panel never flashes the browser prompt" "$(cat "$test_tmp/fireworks-output")"
[[ $(head -1 "$test_tmp/fireworks-check-args") == "--check-key" ]] ||
fail "a Fireworks key is only checked, not read for its usage" "$(cat "$test_tmp/fireworks-check-args")"
grep -q "Fireworks is ready" "$notifications" && ! grep -q "OpenCode is ready" "$notifications" ||
Expand Down
Loading