From 9117c995a3f36c20414c6a92ae5e978e98c2a3de Mon Sep 17 00:00:00 2001 From: Logan Johnson Date: Mon, 21 Sep 2026 15:43:21 -0400 Subject: [PATCH] fix(beehive): retain contextual request and decline without entering section Signed-off-by: Logan Johnson --- beehive/src/owner-panel.ts | 25 +++++++++++++++++-------- beehive/src/owner-service.ts | 8 ++++---- beehive/test/shell-owner.test.ts | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/beehive/src/owner-panel.ts b/beehive/src/owner-panel.ts index cf19372819..6efeafcf56 100644 --- a/beehive/src/owner-panel.ts +++ b/beehive/src/owner-panel.ts @@ -39,7 +39,7 @@ export class OwnerPanel { get modal() { return !!this.dialog; } private commands() { if (!this.state.ownerActive) return this.snapshot.signedIn ? [] : ['Sign in']; - if (this.snapshot.signedIn) return [...(this.continuation === undefined ? [] : [`Continue to ${this.continuation === 0 ? 'Host' : 'Agents'}`]), 'Sign out']; + if (this.snapshot.signedIn) return [...(this.continuation === undefined ? [] : [`Continue to ${this.continuation === 0 ? 'Host' : 'Agents'}`, 'Stay here']), 'Sign out']; if (!this.snapshot.relay && !this.relay) return ['Choose a relay', 'Use Buzz Desktop identity', 'Provide owner nsec']; return ['Use Buzz Desktop identity', 'Provide owner nsec', ...(this.snapshot.relay ? [] : ['Change relay']), 'Check Desktop identity']; } @@ -47,6 +47,7 @@ export class OwnerPanel { private selectionNote(command: string) { if (command === 'Use Buzz Desktop identity') return !(this.snapshot.relay || this.relay) ? 'Choose a relay first. No sign-in or connection happens yet.' : this.snapshot.desktopReason; if (command === 'Provide owner nsec') return !(this.snapshot.relay || this.relay) ? 'Choose a relay first.' : 'Your nsec stays in memory until sign-out or quit.'; + if (command === 'Stay here') return 'Keeps you signed in without opening the requested section.'; if (command === 'Sign out') return 'Signs out of Beehive. Host and agents keep running.'; if (command.startsWith('Continue')) return 'Opens the requested section. No Host or agent operation runs.'; if (command.includes('relay')) return 'Sets public routing on first sign-in. Does not connect or configure a Host.'; @@ -57,7 +58,12 @@ export class OwnerPanel { this.continuation = this.state.activeSection; this.state.mode = 'owner'; this.state.headerIndex = destinations.length; this.state.focus = 'detail'; this.index = 0; this.repaint(); } + private stay() { + this.generation++; this.continuation = undefined; this.prior = undefined; this.index = 0; + this.state.mode = 'owner'; this.state.headerIndex = destinations.length; this.state.focus = 'header'; this.repaint(); + } private back() { + if (this.snapshot.signedIn) { this.stay(); return; } this.generation++; this.client.cancel(); this.continuation = undefined; if (this.prior) { Object.assign(this.state, this.prior); this.prior = undefined; } else { this.state.mode = 'section'; this.state.headerIndex = this.state.activeSection; this.state.focus = 'header'; } @@ -93,6 +99,7 @@ export class OwnerPanel { if (target !== undefined && this.snapshot.signedIn) this.state.activateHeader(target); this.repaint(); return; } + if (command === 'Stay here') { this.stay(); return; } if (command === 'Sign out') { this.continuation = undefined; this.prior = undefined; this.index = 0; await this.client.request({ action: 'signout' }); this.repaint(); return; } if (command === 'Check Desktop identity') { await this.client.request({ action: 'probe' }); return; } if (command.includes('relay')) { @@ -126,17 +133,19 @@ export class OwnerPanel { if (entered && !this.snapshot.signedIn && this.snapshot.desktop === 'unknown') void this.client.request({ action: 'probe' }); const width = this.renderer.width - 4, height = this.renderer.height - 5; const wrap = (value: string) => { const rows: string[] = []; for (const line of value.split('\n')) { let rest = line; while (rest.length > width) { const at = rest.lastIndexOf(' ', width); const end = at > 0 ? at : width; rows.push(rest.slice(0, end)); rest = rest.slice(end).trimStart(); } rows.push(rest); } return rows; }; - const truncate = (value: string) => value.length > width - 8 ? value.slice(0, Math.ceil((width - 9) / 2)) + '…' + value.slice(-Math.floor((width - 9) / 2)) : value; + const truncate = (value: string) => { const limit = width - (owner && this.continuation !== undefined ? 19 : 8); return value.length > limit ? value.slice(0, Math.ceil((limit - 1) / 2)) + '…' + value.slice(-Math.floor((limit - 1) / 2)) : value; }; const commands = this.commands(); this.index = Math.max(0, Math.min(this.index, commands.length - 1)); this.title.top = 1; this.title.width = width; this.title.height = 1; this.title.content = owner ? this.snapshot.signedIn ? 'SIGNED IN' : this.continuation === undefined ? 'OWNER SIGN-IN' : 'SIGN-IN REQUIRED' : destinations[this.state.activeSection]!; - this.facts.top = 2; this.facts.left = owner ? 10 : 2; this.facts.width = owner ? width - 8 : width; - this.labels.top = 2; this.labels.width = 8; this.labels.height = 2; this.labels.visible = owner; this.labels.content = 'Relay\nOwner'; - this.facts.content = owner ? `${truncate(this.snapshot.relay || this.relay || 'Not configured')}\n${truncate(this.snapshot.owner || this.snapshot.boundOwner || 'Not configured')}` : this.snapshot.signedIn ? 'Owner access granted.\nThis section is not implemented in this slice.' : `Sign in to view and manage ${this.state.activeSection === 0 ? 'Host' : 'Agents'}.`; - this.facts.height = owner || this.snapshot.signedIn ? 2 : 1; - this.heading.top = 4; this.heading.width = width; this.heading.height = 1; this.heading.visible = commands.length > 0; + const contextual = owner && this.continuation !== undefined; + const labelWidth = contextual ? 19 : 8; + this.facts.top = 2; this.facts.left = owner ? 2 + labelWidth : 2; this.facts.width = owner ? width - labelWidth : width; + this.labels.top = 2; this.labels.width = labelWidth; this.labels.height = contextual ? 3 : 2; this.labels.visible = owner; this.labels.content = (contextual ? 'Requested section\n' : '') + 'Relay\nOwner'; + this.facts.content = owner ? `${contextual ? (this.continuation === 0 ? 'Host' : 'Agents') + '\n' : ''}${truncate(this.snapshot.relay || this.relay || 'Not configured')}\n${truncate(this.snapshot.owner || this.snapshot.boundOwner || 'Not configured')}` : this.snapshot.signedIn ? 'Owner access granted.\nThis section is not implemented in this slice.' : `Sign in to view and manage ${this.state.activeSection === 0 ? 'Host' : 'Agents'}.`; + this.facts.height = contextual ? 3 : owner || this.snapshot.signedIn ? 2 : 1; + this.heading.top = contextual ? 5 : 4; this.heading.width = width; this.heading.height = 1; this.heading.visible = commands.length > 0; this.heading.content = 'AVAILABLE ACTIONS ' + '─'.repeat(Math.max(1, width - 18)); - this.actionTop = 5; + this.actionTop = contextual ? 6 : 5; this.actions.forEach((action, i) => { action.visible = i < commands.length; action.top = this.actionTop + i; action.width = width; action.height = 1; action.content = `${this.state.focus === 'detail' && i === this.index ? '›' : ' '} ${commands[i] ?? ''}`; action.fg = this.disabled(commands[i] ?? '') ? palette.muted : this.state.focus === 'detail' && i === this.index ? palette.focus : palette.text; diff --git a/beehive/src/owner-service.ts b/beehive/src/owner-service.ts index eb7a843316..587f380b10 100644 --- a/beehive/src/owner-service.ts +++ b/beehive/src/owner-service.ts @@ -20,7 +20,7 @@ export class OwnerService implements OwnerClient { private generation = 0; private disposed = false; constructor(private home = homedir(), private desktop = desktopOwnerKey) { - try { this.projectBinding(); } catch { this.current.phase = 'error'; this.current.message = 'Saved owner routing is invalid or inconsistent. Repair the retained configuration; nothing was reset.'; } + try { this.projectBinding(); } catch { this.current.phase = 'error'; this.current.message = 'Saved owner routing is invalid. Repair the retained configuration; nothing was reset.'; } } private binding() { const controller = readControllerConfig(join(this.home, '.beehive', 'owner')); @@ -67,7 +67,7 @@ export class OwnerService implements OwnerClient { if (url.username || url.password || url.hash || !(url.protocol === 'wss:' || (url.protocol === 'ws:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)))) throw Error(); let secret: string; if (request.action === 'signin-desktop') { - error = 'Buzz Desktop key access failed or was cancelled. Unlock Keychain and check again, or provide an owner nsec. No session was opened.'; + error = 'Desktop key access failed or was cancelled. Unlock Keychain or provide owner nsec. No session opened.'; const result = await this.desktop(false, abort.signal); check(); if (!result.secret) throw Error(); secret = result.secret; @@ -76,10 +76,10 @@ export class OwnerService implements OwnerClient { secret = agentNsec(this.input); } else throw Error('Unsupported action'); const owner = publicKey(secret); check(); - error = 'This identity does not match the configured owner. Use the matching identity. Owner and relay were not changed.'; + error = 'Identity does not match this owner. Use the matching key. Owner and relay were not changed.'; const now = this.binding(); if (now && (now.owner !== owner || now.relay !== relay)) throw Error(); - error = 'Owner routing changed or could not be saved. Reopen sign-in and check the retained configuration. No session was opened.'; + error = 'Owner routing changed or was not saved. Reopen sign-in and check configuration. No session opened.'; if (!now) createControllerConfig(join(this.home, '.beehive', 'owner'), owner, relay); // Read back the sole public authority after first-use activation. const saved = this.binding(); diff --git a/beehive/test/shell-owner.test.ts b/beehive/test/shell-owner.test.ts index 626f44e77f..37e2921ed1 100644 --- a/beehive/test/shell-owner.test.ts +++ b/beehive/test/shell-owner.test.ts @@ -59,3 +59,23 @@ for (const [width,height] of [[120,40],[60,20]]) test(`owner unavailable identit assert.equal(f.requests.at(-1)?.action,'signin-nsec');assert.equal(shell.state.signedIn,true); }finally{shell.close();} }); +for (const [width,height] of [[120,40],[60,20]]) for (const target of [0,1]) test(`contextual request fact and decline keep owner screen at ${width}x${height}, target ${target}`, async () => { + for (const decline of ['action','escape','left']) { + const ui=await createTestRenderer({width,height,exitOnCtrlC:false}),f=fixture(); + const shell=new OpenTuiShell(ui.renderer,f.inventory,undefined,undefined,f.client); + try { + if(target) ui.mockInput.pressArrow('right'); + ui.mockInput.pressEnter();ui.mockInput.pressEnter();await ui.renderOnce(); + assert.match(ui.captureCharFrame(),new RegExp(`Requested section\\s+${target?'Agents':'Host'}`)); + ui.mockInput.pressEnter();await ui.renderOnce(); + assert.equal(shell.state.signedIn,true);assert.match(ui.captureCharFrame(),/Stay here/); + if(decline==='action') { ui.mockInput.pressEnter();ui.mockInput.pressArrow('down');ui.mockInput.pressEnter(); } + else if(decline==='escape') {ui.mockInput.pressEscape();await new Promise(r=>setTimeout(r,50));} + else {ui.mockInput.pressEnter();ui.mockInput.pressArrow('left');} + await ui.renderOnce(); + assert.equal(shell.state.mode,'owner');assert.equal(shell.state.signedIn,true);assert.equal(shell.state.focus,'header'); + assert.doesNotMatch(ui.captureCharFrame(),/Continue to|Requested section|not implemented/); + assert.deepEqual(f.requests.map(r=>r.action),['signin-desktop']); + }finally{shell.close();} + } +});