feat(chat): per-chat permission modes for Claude, Codex and OpenCode

This commit is contained in:
2026-10-24 18:16:10 +01:00
parent ef575898f2
commit 6d430948a6
29 changed files with 1512 additions and 3 deletions
@@ -0,0 +1,318 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../core/error_reason.dart';
import '../data/chat_repository.dart';
import '../ui/sessions/chat_adaptive.dart';
/// The conversation bar's permission-mode control.
///
/// It shows the mode the session row names (`mode_name`, the harness default
/// when none was chosen) without a request of its own, since requests are
/// serialized and must not delay the transcript. Tapping reads the harness's
/// modes (`chat_modes`) into a native picker; choosing one sends `chat_mode`. A
/// refusal keeps the picker open with the server's reason. A row without a
/// mode (an older server or a harness without modes) shows no control.
class ChatModeControl extends StatefulWidget {
const ChatModeControl({
super.key,
required this.gateway,
required this.sessionId,
required this.mode,
required this.modeName,
this.onChanged,
});
final ApiGateway gateway;
final String sessionId;
/// The row's `mode` id and its display name.
final String mode;
final String modeName;
/// The accepted mode's id and name, so the opened row keeps up.
final void Function(String mode, String name)? onChanged;
@override
State<ChatModeControl> createState() => _ChatModeControlState();
}
class _ChatModeControlState extends State<ChatModeControl> {
late String _mode = widget.mode;
late String _name = widget.modeName;
@override
void didUpdateWidget(covariant ChatModeControl oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.mode != widget.mode ||
oldWidget.modeName != widget.modeName) {
_mode = widget.mode;
_name = widget.modeName;
}
}
Future<void> _open() async {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final repository = ChatRepository(widget.gateway);
final picker = _ChatModePicker(
load: () => repository.modes(widget.sessionId),
current: _mode,
cupertino: cupertino,
choose: (mode) async {
final applied = await repository.selectMode(widget.sessionId, mode.id);
final name = applied == mode.id ? mode.name : applied;
widget.onChanged?.call(applied, name);
if (mounted) {
setState(() {
_mode = applied;
_name = name;
});
}
},
);
if (cupertino) {
await showCupertinoModalPopup<void>(
context: context,
builder: (_) => picker,
);
return;
}
await showModalBottomSheet<void>(
context: context,
showDragHandle: true,
isScrollControlled: true,
useSafeArea: true,
builder: (_) => picker,
);
}
@override
Widget build(BuildContext context) {
if (_mode.isEmpty || _name.isEmpty) return const SizedBox.shrink();
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final label = _name;
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
cupertino
? CupertinoIcons.shield_lefthalf_fill
: Icons.shield_outlined,
),
const SizedBox(width: 4),
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
],
);
const key = Key('chat-mode');
if (cupertino) {
return Semantics(
container: true,
button: true,
label: 'Change mode, currently $label',
onTap: _open,
child: ExcludeSemantics(
child: CupertinoButton(
key: key,
padding: const EdgeInsets.symmetric(horizontal: 8),
onPressed: _open,
child: content,
),
),
);
}
return Tooltip(
message: 'Change mode (currently $label)',
child: TextButton(key: key, onPressed: _open, child: content),
);
}
}
/// One mode the harness offers.
typedef _Mode = ({String id, String name, String description});
/// The native mode list: each mode's name and description, the current one
/// checked. It reads the list when opened and closes once the server accepts
/// a choice.
class _ChatModePicker extends StatefulWidget {
const _ChatModePicker({
required this.load,
required this.current,
required this.cupertino,
required this.choose,
});
final Future<({List<JsonMap> modes, String current})> Function() load;
final String current;
final bool cupertino;
final Future<void> Function(_Mode mode) choose;
@override
State<_ChatModePicker> createState() => _ChatModePickerState();
}
class _ChatModePickerState extends State<_ChatModePicker> {
List<_Mode>? _modes;
late String _current = widget.current;
bool _busy = false;
String? _error;
@override
void initState() {
super.initState();
_read();
}
Future<void> _read() async {
try {
final reply = await widget.load();
if (!mounted) return;
setState(() {
_modes = [
for (final mode in reply.modes)
if ('${mode['id'] ?? ''}'.trim().isNotEmpty)
(
id: '${mode['id']}'.trim(),
name: '${mode['name'] ?? mode['id']}'.trim(),
description: '${mode['description'] ?? ''}'.trim(),
),
];
if (reply.current.isNotEmpty) _current = reply.current;
});
} catch (error) {
if (!mounted) return;
setState(() {
_modes = const [];
_error = describeErrorReason(
error,
fallback: 'The modes could not be loaded.',
);
});
}
}
Future<void> _choose(_Mode mode) async {
if (_busy) return;
if (mode.id == _current) {
Navigator.of(context).pop();
return;
}
setState(() {
_busy = true;
_error = null;
});
try {
await widget.choose(mode);
if (mounted) Navigator.of(context).pop();
} catch (error) {
if (!mounted) return;
setState(() {
_busy = false;
_error = describeErrorReason(
error,
fallback: 'The mode was not changed.',
);
});
}
}
@override
Widget build(BuildContext context) =>
widget.cupertino ? _cupertinoSheet(context) : _materialSheet(context);
Widget _materialSheet(BuildContext context) {
final theme = Theme.of(context);
final modes = _modes;
return SafeArea(
child: ListView(
key: const Key('chat-mode-sheet'),
shrinkWrap: true,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
child: Text('Mode', style: theme.textTheme.titleMedium),
),
if (_error != null)
Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
child: Text(
_error!,
style: TextStyle(color: theme.colorScheme.error),
),
),
if (modes == null)
const Padding(
padding: EdgeInsets.all(16),
child: Center(child: CircularProgressIndicator()),
)
else
for (final mode in modes)
ListTile(
key: ValueKey<String>('chat-mode-option-${mode.id}'),
enabled: !_busy,
title: Text(mode.name),
subtitle: mode.description.isEmpty
? null
: Text(mode.description),
trailing: mode.id == _current
? Icon(Icons.check, color: theme.colorScheme.primary)
: null,
onTap: () => _choose(mode),
),
],
),
);
}
Widget _cupertinoSheet(BuildContext context) {
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
final modes = _modes;
return CupertinoActionSheet(
key: const Key('chat-mode-sheet'),
title: const Text('Mode'),
message: _error != null
? Text(
_error!,
style: TextStyle(
color: CupertinoColors.systemRed.resolveFrom(context),
),
)
: modes == null
? const CupertinoActivityIndicator()
: null,
actions: [
for (final mode in modes ?? const <_Mode>[])
CupertinoActionSheetAction(
key: ValueKey<String>('chat-mode-option-${mode.id}'),
onPressed: () => _choose(mode),
child: Column(
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(child: Text(mode.name)),
if (mode.id == _current) ...[
const SizedBox(width: 6),
const Icon(CupertinoIcons.checkmark_alt),
],
],
),
if (mode.description.isNotEmpty)
Text(
mode.description,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 13, color: secondary),
),
],
),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Cancel'),
),
);
}
}
@@ -20,6 +20,7 @@ import 'chat_command_actions.dart';
import 'chat_composer_bar.dart';
import 'chat_composer_controller.dart';
import 'chat_draft_store.dart';
import 'chat_mode_control.dart';
import 'chat_model_control.dart';
import 'chat_models.dart';
import 'chat_row_keys.dart';
@@ -48,6 +49,7 @@ class ChatThreadView extends StatefulWidget {
this.title = '',
this.session,
this.onModelChanged,
this.onModeChanged,
this.syncToken = 0,
this.drafts,
this.newOperationId,
@@ -90,6 +92,9 @@ class ChatThreadView extends StatefulWidget {
/// keep the row it opened current for the next visit.
final ValueChanged<ChatModelSelection>? onModelChanged;
/// The accepted permission mode's id and name.
final void Function(String mode, String name)? onModeChanged;
/// Advances when the shared socket is replaced, keeping this selection.
final int syncToken;
@@ -701,6 +706,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
answeredBy: latestReplyModel(_controller.messages),
),
),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: constraints.maxWidth * 0.3,
),
child: _modeControl(),
),
ChatBarAction(
key: const Key('chat-info'),
label: 'Chat information',
@@ -864,6 +875,10 @@ class _ChatThreadViewState extends State<ChatThreadView> {
answeredBy: latestReplyModel(_controller.messages),
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 160),
child: _modeControl(),
),
ChatBarAction(
key: const Key('chat-info'),
label: 'Chat information',
@@ -877,6 +892,17 @@ class _ChatThreadViewState extends State<ChatThreadView> {
},
);
/// The session's permission mode, keyed per session so another chat
/// re-reads its own modes.
Widget _modeControl() => ChatModeControl(
key: ValueKey<String>('chat-mode-${widget.sessionId}'),
gateway: widget.gateway,
sessionId: widget.sessionId,
mode: '${widget.session?['mode'] ?? ''}'.trim(),
modeName: '${widget.session?['mode_name'] ?? ''}'.trim(),
onChanged: widget.onModeChanged,
);
ChatNotice? _noticeOf(List<ChatNotice> notices, ChatNoticeKind kind) {
for (final notice in notices) {
if (notice.kind == kind) return notice;
@@ -49,6 +49,40 @@ class ChatRepository {
});
}
/// The permission modes the session's harness offers, in the server's
/// order, and the session's stored mode (empty for the harness default).
Future<({List<JsonMap> modes, String current})> modes(
String sessionId,
) async {
final session = sessionId.trim();
if (session.isEmpty) {
throw ArgumentError('Select a chat session first.');
}
final reply = await gateway.call('chat_modes', {
'chat_query': {'session_id': session},
});
final value = reply['chat_modes'];
final current = reply['chat_mode'];
return (
modes: value is List ? _maps(value) : const <JsonMap>[],
current: current is Map ? '${current['mode'] ?? ''}'.trim() : '',
);
}
/// Switches the session's mode; the reply echoes the stored mode.
Future<String> selectMode(String sessionId, String mode) async {
final session = sessionId.trim();
if (session.isEmpty) {
throw ArgumentError('Select a chat session first.');
}
if (mode.trim().isEmpty) throw ArgumentError('Choose a mode first.');
final reply = await gateway.call('chat_mode', {
'chat_mode': {'session_id': session, 'mode': mode.trim()},
});
final echoed = reply['chat_mode'];
return echoed is Map ? '${echoed['mode'] ?? ''}'.trim() : mode.trim();
}
Future<List<JsonMap>> shells(String sessionId) async => _maps(
(await gateway.call('chat_shells', {
'chat_query': {'session_id': sessionId},
+11
View File
@@ -145,6 +145,16 @@ class _ChatScreenState extends State<ChatScreen> {
setState(() => _acceptedModels[id] = applied);
}
/// An accepted mode switch updates the opened row, so reopening the chat in
/// this visit shows it before the list re-reads.
void _modeChanged(String id, String mode, String name) {
final row = _openedSessions[id];
if (!mounted || row == null) return;
setState(
() => _openedSessions[id] = {...row, 'mode': mode, 'mode_name': name},
);
}
/// The row to open for [id], with an accepted model folded in.
JsonMap? _rowFor(String id) {
final row = _openedSessions[id];
@@ -194,6 +204,7 @@ class _ChatScreenState extends State<ChatScreen> {
: null,
onBack: onBack,
onModelChanged: (applied) => _modelChanged(selected, applied),
onModeChanged: (mode, name) => _modeChanged(selected, mode, name),
onCreatedSession: _openCreated,
onSessionRenamed: (title) => _renamed(selected, title),
onSessionClosed: _closed,
+42
View File
@@ -0,0 +1,42 @@
# Chat permission modes
User request (2026-10-24): change a chat to auto mode instead of plan/ask, for
Claude, Codex and OpenCode. Server and app change (user authorized the server).
## Server
- Protocol: `chat_modes` (ChatQuery → `chat_modes` list + current `chat_mode`)
and `chat_mode` ({session_id, mode} → echoed stored mode). `ChatSession` rows
carry `mode` and `mode_name` (the harness default, listed first, when none was
chosen).
- Stored in `operator_sessions.chat_mode` (additive migration); re-applied to the
harness before every turn, so a server restart keeps the choice.
- Claude: default (ask), acceptEdits, plan, auto, bypassPermissions. A new CLI
starts with `--permission-mode`; a running one switches in place with the
`set_permission_mode` control request (verified present in CLI 2.1.310).
`dontAsk` is omitted on purpose.
- Codex: ask (on-request + workspaceWrite), auto (never + workspaceWrite), full
(never + dangerFullAccess), sent as turn/start `approvalPolicy`/`sandboxPolicy`
(checked against codex 0.163.0's app-server schema).
- OpenCode: build / plan agents, sent as the prompt's `agent` (v2 body and the v1
native translation).
## App
`ChatModeControl` in the chat bar shows the row's `mode_name` without a request
(client requests are serialized, so an eager read would delay history), and reads
`chat_modes` only when tapped. Native sheet / action sheet with descriptions; a
refusal stays in the picker. Accepted switches update the opened row.
## Evidence
- Go: new tests for storage, Claude (spawn flag, live switch, default omits the
flag), Codex turn overrides, OpenCode agent on v1/v2 prompts, server
store/apply/restart. Full `go test ./...` passes except two tests that already fail
on main in this environment (umask 077 file-permission checks, and
`TestHumanRunAttentionNotification` picking up the host's real web URL).
- App: `chat_mode_control_test.dart`; analyze clean; full suite 1,867 pass.
- Browser: `tool/chat_mode_probe.mjs` (fixture gained chat_modes/chat_mode),
Material and Cupertino at 1280: `build/chat-mode-probe/`.
- Not verified against live Claude/Codex/OpenCode processes. The server isn't
deployed yet and no device was used.
@@ -0,0 +1,184 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/conversation/chat_mode_control.dart';
class _ModeGateway implements ApiGateway {
_ModeGateway({this.current = '', this.refuse, this.supported = true});
String current;
final String? refuse;
final bool supported;
final requests = <JsonMap>[];
@override
Stream<JsonMap> get frames => const Stream.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
requests.add({'type': type, ...fields});
if (!supported) throw ProtocolError('unknown request type');
if (type == 'chat_modes') {
return {
'chat_modes': [
{
'id': 'default',
'name': 'Ask for permission',
'description': 'Ask first.',
},
{'id': 'plan', 'name': 'Plan', 'description': 'Plan only.'},
{'id': 'auto', 'name': 'Auto', 'description': 'Act without asking.'},
],
'chat_mode': {'session_id': 's', 'mode': current},
};
}
if (type == 'chat_mode') {
final refused = refuse;
if (refused != null) throw ProtocolError(refused);
current = '${(fields['chat_mode'] as Map)['mode']}';
return {
'chat_mode': {'session_id': 's', 'mode': current},
};
}
return {};
}
}
Widget _material(
ApiGateway gateway, {
String mode = 'default',
String name = 'Ask for permission',
void Function(String, String)? onChanged,
}) => MaterialApp(
home: Scaffold(
appBar: AppBar(
actions: [
ChatModeControl(
gateway: gateway,
sessionId: 's',
mode: mode,
modeName: name,
onChanged: onChanged,
),
],
),
),
);
void main() {
testWidgets("shows the row's mode without a request and switches to Auto", (
tester,
) async {
final gateway = _ModeGateway();
final changes = <String>[];
await tester.pumpWidget(
_material(gateway, onChanged: (mode, name) => changes.add('$mode/$name')),
);
await tester.pumpAndSettle();
// The row names the mode; nothing is requested until the picker opens,
// so the serialized transport never delays the transcript.
expect(find.text('Ask for permission'), findsOneWidget);
expect(gateway.requests, isEmpty);
await tester.tap(find.byKey(const Key('chat-mode')));
await tester.pumpAndSettle();
expect(find.text('Act without asking.'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('chat-mode-option-auto')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-mode-sheet')), findsNothing);
expect(gateway.requests.last, {
'type': 'chat_mode',
'chat_mode': {'session_id': 's', 'mode': 'auto'},
});
expect(
find.descendant(
of: find.byKey(const Key('chat-mode')),
matching: find.text('Auto'),
),
findsOneWidget,
);
expect(changes, ['auto/Auto']);
});
testWidgets('the stored mode is shown and checked', (tester) async {
await tester.pumpWidget(
_material(
_ModeGateway(current: 'plan'),
mode: 'plan',
name: 'Plan',
),
);
await tester.pumpAndSettle();
expect(find.text('Plan'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-mode')));
await tester.pumpAndSettle();
expect(
find.descendant(
of: find.byKey(const ValueKey('chat-mode-option-plan')),
matching: find.byIcon(Icons.check),
),
findsOneWidget,
);
});
testWidgets('a refusal keeps the picker open with the reason', (
tester,
) async {
final gateway = _ModeGateway(refuse: 'mode switch refused');
await tester.pumpWidget(_material(gateway));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-mode')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('chat-mode-option-auto')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-mode-sheet')), findsOneWidget);
expect(find.textContaining('mode switch refused'), findsOneWidget);
expect(gateway.current, '');
});
testWidgets('a row without a mode shows no control', (tester) async {
await tester.pumpWidget(_material(_ModeGateway(), mode: '', name: ''));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-mode')), findsNothing);
});
testWidgets('a failed mode list is reported in the picker', (tester) async {
await tester.pumpWidget(_material(_ModeGateway(supported: false)));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-mode')));
await tester.pumpAndSettle();
expect(find.textContaining('unknown request type'), findsOneWidget);
});
testWidgets('Cupertino uses a native action sheet', (tester) async {
final gateway = _ModeGateway();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
trailing: ChatModeControl(
gateway: gateway,
sessionId: 's',
mode: 'default',
modeName: 'Ask for permission',
),
),
child: const SizedBox.shrink(),
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-mode')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('chat-mode-option-auto')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsNothing);
expect(gateway.current, 'auto');
});
}
+82
View File
@@ -0,0 +1,82 @@
// Switches an open chat's permission mode in a real browser against a loopback
// fixture, never operator data.
// PROBE_WIDTH=1280 PROBE_HOST=material|cupertino node tool/chat_mode_probe.mjs <web-build> <out>
import assert from 'node:assert/strict';
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
import { once } from 'node:events';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { startFixture } from './runs_probe_server.mjs';
import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs';
import { axNodes, enableSemantics, waitFor, capture } from './pipelines_probe_cdp_input.mjs';
const width = Number(process.env.PROBE_WIDTH ?? 1280);
const host = process.env.PROBE_HOST ?? 'material';
const output = resolve(process.argv[3] ?? 'build/chat-mode-probe');
await mkdir(output, { recursive: true });
const messages = [
{ id: 'u0', role: 'user', parts: [{ id: 'p0', type: 'text', text: 'Switch this chat to auto mode.' }] },
{ id: 'a0', role: 'assistant', parts: [{ id: 'p1', type: 'text', text: 'Recorded fixture reply.' }] },
];
const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: messages });
const profile = await mkdtemp(join(tmpdir(), 'chat-mode-'));
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
const log = { width, host, checks: [], captures: [] };
let c;
const named = async (pattern) => (await axNodes(c)).filter((n) => pattern.test(n.name?.value ?? ''));
const press = async (node) => {
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: node.backendDOMNodeId });
const [x1, y1, , , x3, y3] = model.content;
for (const type of ['mousePressed', 'mouseReleased']) {
await c.send('Input.dispatchMouseEvent', { type, x: (x1 + x3) / 2, y: (y1 + y3) / 2, button: 'left', clickCount: 1 });
}
};
const first = async (pattern, what) => {
let found;
assert.ok(await waitFor(async () => (found = (await named(pattern)).find((n) => n.backendDOMNodeId)), 30000), what);
return found;
};
try {
c = await connect((await waitForPage(await waitForPort(join(profile, 'DevToolsActivePort')))).webSocketDebuggerUrl);
await c.send('Page.enable');
if (host === 'cupertino') {
await c.send('Emulation.setUserAgentOverride', {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15', platform: 'MacIntel',
});
} else {
await c.send('Emulation.setUserAgentOverride', {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36', platform: 'Win32',
});
}
await c.send('Emulation.setDeviceMetricsOverride', { width, height: 800, deviceScaleFactor: 1, mobile: false });
await c.send('Page.navigate', { url: fixture.url + '/chat/ses_probechat' });
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000));
await enableSemantics(c);
await first(/Change mode\b.*Ask for permission/, 'mode control shows the row mode');
await sleep(800);
await capture(c, output, log, `${host}-mode-default`);
log.checks.push('bar shows the stored/default mode before any chat_modes request');
await press(await first(/Change mode\b/, 'mode control'));
await first(/^Auto/, 'Auto option');
await sleep(600);
await capture(c, output, log, `${host}-mode-picker`);
await press(await first(/^Auto/, 'Auto option'));
await first(/Change mode\b.*Auto/, 'bar shows Auto');
await sleep(600);
await capture(c, output, log, `${host}-mode-auto`);
const state = await (await fetch(fixture.url + '/fixture/state')).json();
assert.deepEqual(state.chatModeRequests, [{ session_id: 'ses_probechat', mode: 'auto' }]);
log.checks.push('choosing Auto sent chat_mode and the bar shows Auto');
console.log(JSON.stringify(log, null, 2));
} catch (error) {
if (c) {
await capture(c, output, log, 'failure');
await writeFile(join(output, 'failure-ax.json'), JSON.stringify(await axNodes(c), null, 2));
}
throw error;
} finally {
await writeFile(join(output, `${host}-result.json`), JSON.stringify(log, null, 2));
c?.close(); const exited = once(chrome, 'exit'); chrome.kill(); await exited;
await fixture.close();
}
+29
View File
@@ -337,7 +337,18 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
kind: 'operator',
directory: '/srv/probe',
updated_at: '2026-10-21T12:00:00Z',
backend: 'claude',
mode: 'default',
mode_name: 'Ask for permission',
};
const CHAT_MODES = [
{ id: 'default', name: 'Ask for permission', description: 'Ask before edits and commands.' },
{ id: 'acceptEdits', name: 'Accept edits', description: 'Make file edits without asking; ask for other actions.' },
{ id: 'plan', name: 'Plan', description: 'Explore and plan without changing anything.' },
{ id: 'auto', name: 'Auto', description: "Act without asking, with Claude Code's safety checks." },
{ id: 'bypassPermissions', name: 'Bypass permissions', description: 'Never ask. Everything runs without checks.' },
];
const chatModeRequests = [];
const dropConnections = () => {
for (const connection of connections) connection.close();
@@ -394,6 +405,7 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
.writeHead(200, { 'content-type': 'application/json' })
.end(JSON.stringify({
subscribed,
chatModeRequests,
live,
connections: connections.size,
refuse,
@@ -550,6 +562,23 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
setTimeout(() => client.send({ id: request.id, type: 'chat_prompt', chat_queued: chatRunning }), 300);
return;
}
if (request.type === 'chat_modes') {
client.send({ id: request.id, type: 'chat_modes', chat_modes: CHAT_MODES,
chat_mode: { session_id: CHAT_SESSION.id, mode: CHAT_SESSION.mode } });
return;
}
if (request.type === 'chat_mode') {
const mode = CHAT_MODES.find((entry) => entry.id === request.chat_mode?.mode);
chatModeRequests.push(request.chat_mode);
if (!mode) {
client.send({ id: request.id, type: 'error', error: 'unknown Claude permission mode' });
return;
}
CHAT_SESSION.mode = mode.id;
CHAT_SESSION.mode_name = mode.name;
client.send({ id: request.id, type: 'chat_mode', chat_mode: { session_id: CHAT_SESSION.id, mode: mode.id } });
return;
}
if (request.type === 'chat_shells') {
client.send({ id: request.id, type: 'chat_shells', chat_shells: [] });
return;