mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-07 01:21:37 +00:00
* feat(cli): add hapi set-mode to change a session's permission mode (#2094) The CLI could only pick a permission mode at launch; changing it on an existing session required the web UI or a hand-rolled JWT + curl call. `hapi set-mode <session-id-or-prefix> <mode>` resolves the session like ping-peer / inspect-peer, validates the mode against the session flavor's catalog (printing the allowed list on mismatch), and calls the existing POST /api/sessions/:id/permission-mode route. Active sessions switch live; inactive ones keep the mode for the next resume. No MCP tool is added: raising a peer's mode stays behind the agent's normal shell-approval path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: reject Safe Yolo for shared sessions on the permission-mode route Shared (concurrentClients) Codex sessions cannot launch with safe-yolo. The web picker hides it, but the route only checked the flavor catalog, so `hapi set-mode` (or any API client) could store it on an inactive shared session and break its next resume. Guard the route and apply the same filter to the CLI's allowed-mode list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
16 lines
666 B
TypeScript
16 lines
666 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { PingPeerError } from '@/modules/pingPeer/pingPeer'
|
|
import { parseSetModeArgs } from './setMode'
|
|
|
|
describe('parseSetModeArgs', () => {
|
|
it('parses session id and mode', () => {
|
|
expect(parseSetModeArgs(['7d55ed21', 'plan'])).toEqual({ help: false, sessionIdPrefix: '7d55ed21', mode: 'plan' })
|
|
expect(parseSetModeArgs(['-h'])).toEqual({ help: true })
|
|
})
|
|
|
|
it('rejects flags and extra args', () => {
|
|
expect(() => parseSetModeArgs(['7d55ed21', '--yolo'])).toThrow(PingPeerError)
|
|
expect(() => parseSetModeArgs(['7d55ed21', 'plan', 'extra'])).toThrow(PingPeerError)
|
|
})
|
|
})
|