@lucascouts/claude-agent-tui 0.14.2 → 0.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-agent.d.ts +18 -2
- package/dist/acp-agent.js +29 -9
- package/package.json +1 -1
package/dist/acp-agent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Agent, AgentSideConnection, AuthenticateRequest, CancelNotification, ClientCapabilities, ForkSessionRequest, ForkSessionResponse, InitializeRequest, InitializeResponse, ListSessionsRequest, ListSessionsResponse, LoadSessionRequest, LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, ReadTextFileRequest, ReadTextFileResponse, ResumeSessionRequest, ResumeSessionResponse, SessionConfigOption, SessionModeState, SessionNotification, SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, SetSessionModeRequest, SetSessionModeResponse, CloseSessionRequest, CloseSessionResponse, DeleteSessionRequest, DeleteSessionResponse, LogoutRequest, LogoutResponse, TerminalHandle, TerminalOutputResponse, WriteTextFileRequest, WriteTextFileResponse, AvailableCommand } from "@agentclientprotocol/sdk";
|
|
2
|
-
import { ModelInfo, Options, PermissionMode, PermissionUpdate, SDKMessageOrigin, SDKPartialAssistantMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { ModelInfo, Options, PermissionMode, PermissionUpdate, SDKMessageOrigin, SDKPartialAssistantMessage, Settings } from "@anthropic-ai/claude-agent-sdk";
|
|
3
3
|
import { ContentBlockParam } from "@anthropic-ai/sdk/resources";
|
|
4
4
|
import { BetaContentBlock, BetaRawContentBlockDelta } from "@anthropic-ai/sdk/resources/beta.mjs";
|
|
5
5
|
import { SettingsManager } from "./settings.js";
|
|
@@ -98,6 +98,13 @@ type Session = {
|
|
|
98
98
|
accumulatedUsage: AccumulatedUsage;
|
|
99
99
|
modes: SessionModeState;
|
|
100
100
|
modelInfos: ModelInfo[];
|
|
101
|
+
/**
|
|
102
|
+
* Upstream #1165: whether this session may offer/enter `bypassPermissions` — {@link ALLOW_BYPASS}
|
|
103
|
+
* AND not disabled by `permissions.disableBypassPermissionsMode` ({@link sessionAllowsBypass}).
|
|
104
|
+
* Decided once at createSession; the model-change catalog rebuild reads it. Absent (hand-built
|
|
105
|
+
* test sessions) falls back to the process-wide {@link ALLOW_BYPASS}.
|
|
106
|
+
*/
|
|
107
|
+
allowBypass?: boolean;
|
|
101
108
|
/**
|
|
102
109
|
* Story 056 (R3.2) — the main-thread agent personas discovered for this session's cwd at
|
|
103
110
|
* create time ({@link discoverAgents}, glob-only). Stored so the model-change reconcile in
|
|
@@ -613,6 +620,15 @@ export type ToolUseCache = {
|
|
|
613
620
|
input: unknown;
|
|
614
621
|
};
|
|
615
622
|
};
|
|
623
|
+
/**
|
|
624
|
+
* Ported from upstream #1165 (281e47e): Claude Code refuses `bypassPermissions` when any settings
|
|
625
|
+
* tier (user, project, local, managed) sets `permissions.disableBypassPermissionsMode` to
|
|
626
|
+
* `"disable"`. The key can only take a permission away, so it is honoured from every tier, project
|
|
627
|
+
* included. Decided once per session and fed to every gate that used the process-wide
|
|
628
|
+
* {@link ALLOW_BYPASS}: the mode catalog, the `defaultMode` seed, and (through the catalog) the
|
|
629
|
+
* set_mode / set_config_option re-spawn into `--permission-mode bypassPermissions`.
|
|
630
|
+
*/
|
|
631
|
+
export declare function sessionAllowsBypass(permissions: Settings["permissions"] | undefined): boolean;
|
|
616
632
|
/**
|
|
617
633
|
* Return user-message content with local-command marker tags removed, or
|
|
618
634
|
* `null` if nothing meaningful remains (caller should skip the message).
|
|
@@ -623,7 +639,7 @@ export type ToolUseCache = {
|
|
|
623
639
|
*/
|
|
624
640
|
export declare function stripLocalCommandMetadata(content: unknown): unknown | null;
|
|
625
641
|
export declare function isLocalCommandMetadata(content: unknown): boolean;
|
|
626
|
-
export declare function resolvePermissionMode(defaultMode?: unknown, logger?: Logger): PermissionMode;
|
|
642
|
+
export declare function resolvePermissionMode(defaultMode?: unknown, logger?: Logger, allowBypass?: boolean): PermissionMode;
|
|
627
643
|
/**
|
|
628
644
|
* Builds the label for the "Always Allow" permission option so the user can see
|
|
629
645
|
* the exact scope they are committing to. Uses the SDK-provided suggestions
|
package/dist/acp-agent.js
CHANGED
|
@@ -456,6 +456,17 @@ function shouldHideClaudeAuth() {
|
|
|
456
456
|
// Bypass Permissions doesn't work if we are a root/sudo user
|
|
457
457
|
const IS_ROOT = (process.geteuid?.() ?? process.getuid?.()) === 0;
|
|
458
458
|
const ALLOW_BYPASS = !IS_ROOT || !!process.env.IS_SANDBOX;
|
|
459
|
+
/**
|
|
460
|
+
* Ported from upstream #1165 (281e47e): Claude Code refuses `bypassPermissions` when any settings
|
|
461
|
+
* tier (user, project, local, managed) sets `permissions.disableBypassPermissionsMode` to
|
|
462
|
+
* `"disable"`. The key can only take a permission away, so it is honoured from every tier, project
|
|
463
|
+
* included. Decided once per session and fed to every gate that used the process-wide
|
|
464
|
+
* {@link ALLOW_BYPASS}: the mode catalog, the `defaultMode` seed, and (through the catalog) the
|
|
465
|
+
* set_mode / set_config_option re-spawn into `--permission-mode bypassPermissions`.
|
|
466
|
+
*/
|
|
467
|
+
export function sessionAllowsBypass(permissions) {
|
|
468
|
+
return ALLOW_BYPASS && permissions?.disableBypassPermissionsMode !== "disable";
|
|
469
|
+
}
|
|
459
470
|
// Slash commands that the SDK handles locally without replaying the user
|
|
460
471
|
// message and without invoking the model.
|
|
461
472
|
const LOCAL_ONLY_COMMANDS = new Set(["/context", "/heapdump", "/extra-usage"]);
|
|
@@ -602,7 +613,7 @@ const PERMISSION_MODE_ALIASES = {
|
|
|
602
613
|
bypasspermissions: "bypassPermissions",
|
|
603
614
|
bypass: "bypassPermissions",
|
|
604
615
|
};
|
|
605
|
-
export function resolvePermissionMode(defaultMode, logger = console) {
|
|
616
|
+
export function resolvePermissionMode(defaultMode, logger = console, allowBypass = ALLOW_BYPASS) {
|
|
606
617
|
if (defaultMode === undefined) {
|
|
607
618
|
return "default";
|
|
608
619
|
}
|
|
@@ -620,8 +631,10 @@ export function resolvePermissionMode(defaultMode, logger = console) {
|
|
|
620
631
|
logger.error(`Ignoring permissions.defaultMode from settings: unknown value '${defaultMode}'.`);
|
|
621
632
|
return "default";
|
|
622
633
|
}
|
|
623
|
-
if (mapped === "bypassPermissions" && !
|
|
624
|
-
logger.error(
|
|
634
|
+
if (mapped === "bypassPermissions" && !allowBypass) {
|
|
635
|
+
logger.error(ALLOW_BYPASS
|
|
636
|
+
? "Ignoring permissions.defaultMode from settings: bypassPermissions is disabled by permissions.disableBypassPermissionsMode."
|
|
637
|
+
: "Ignoring permissions.defaultMode from settings: bypassPermissions is not available when running as root.");
|
|
625
638
|
return "default";
|
|
626
639
|
}
|
|
627
640
|
return mapped;
|
|
@@ -2452,7 +2465,7 @@ export class ClaudeAcpAgent {
|
|
|
2452
2465
|
// mode if the SDK no longer offers it (today: "auto" on Haiku).
|
|
2453
2466
|
// `ModelInfo.supportsAutoMode` is the canonical SDK signal.
|
|
2454
2467
|
const newModelInfo = session.modelInfos.find((m) => m.value === value);
|
|
2455
|
-
const newAvailableModes = buildAvailableModes(newModelInfo);
|
|
2468
|
+
const newAvailableModes = buildAvailableModes(newModelInfo, session.allowBypass ?? ALLOW_BYPASS);
|
|
2456
2469
|
// Capture BEFORE mutating session.modes so the log message reflects
|
|
2457
2470
|
// the invalidated mode rather than "default".
|
|
2458
2471
|
const previousModeId = session.modes.currentModeId;
|
|
@@ -2600,7 +2613,12 @@ export class ClaudeAcpAgent {
|
|
|
2600
2613
|
// on undefined/invalid AND strips bypassPermissions under the root guard — so R3.1 reconciles
|
|
2601
2614
|
// with R3.6). Drives both the spawn flag (--permission-mode, fresh path) and the advertised
|
|
2602
2615
|
// currentModeId, replacing the old hardcoded "default".
|
|
2603
|
-
|
|
2616
|
+
// Upstream #1165: bypass is also off when any settings tier sets
|
|
2617
|
+
// permissions.disableBypassPermissionsMode to "disable" (the CLI refuses it then too). Decided
|
|
2618
|
+
// once here: it gates the defaultMode seed, the advertised catalog, and therefore every later
|
|
2619
|
+
// set_mode / set_config_option request for bypass (applySessionMode checks the catalog).
|
|
2620
|
+
const allowBypass = sessionAllowsBypass(settingsManager.getSettings().permissions);
|
|
2621
|
+
const seededMode = resolvePermissionMode(settingsManager.getSettings().permissions?.defaultMode, this.logger, allowBypass);
|
|
2604
2622
|
// Per-session task state — still surfaced via plan notifications by the Group 2 pump / hooks.
|
|
2605
2623
|
const taskState = new Map();
|
|
2606
2624
|
// === SEAM(034) §9 hybrid gate: set up the per-session permission gate BEFORE the spawn =======
|
|
@@ -2712,7 +2730,7 @@ export class ClaudeAcpAgent {
|
|
|
2712
2730
|
// any failure — see live-model-catalog.ts. `default` is present in both, which
|
|
2713
2731
|
// is why the seed below can stay a constant.
|
|
2714
2732
|
const liveModelCatalog = await resolveModelCatalog(this.logger);
|
|
2715
|
-
const availableModes = buildAvailableModes(DEFAULT_MODEL_INFO);
|
|
2733
|
+
const availableModes = buildAvailableModes(DEFAULT_MODEL_INFO, allowBypass);
|
|
2716
2734
|
const modes = {
|
|
2717
2735
|
currentModeId: seededMode,
|
|
2718
2736
|
availableModes,
|
|
@@ -2755,6 +2773,7 @@ export class ClaudeAcpAgent {
|
|
|
2755
2773
|
},
|
|
2756
2774
|
modes,
|
|
2757
2775
|
modelInfos: liveModelCatalog,
|
|
2776
|
+
allowBypass,
|
|
2758
2777
|
agents,
|
|
2759
2778
|
configOptions,
|
|
2760
2779
|
contextWindowSize: inferContextWindowFromModel(DEFAULT_MODEL_INFO.value) ?? DEFAULT_CONTEXT_WINDOW,
|
|
@@ -2777,9 +2796,10 @@ export class ClaudeAcpAgent {
|
|
|
2777
2796
|
* Build the list of permission modes the agent will advertise for the given
|
|
2778
2797
|
* model. `auto` is gated by `ModelInfo.supportsAutoMode === true`, which is
|
|
2779
2798
|
* the SDK's model-level availability signal. `undefined`/`false` both exclude
|
|
2780
|
-
* `auto`. `bypassPermissions` is
|
|
2799
|
+
* `auto`. `bypassPermissions` is gated by the per-session `allowBypass`
|
|
2800
|
+
* ({@link sessionAllowsBypass}: `ALLOW_BYPASS` and not disabled by settings).
|
|
2781
2801
|
*/
|
|
2782
|
-
function buildAvailableModes(modelInfo) {
|
|
2802
|
+
function buildAvailableModes(modelInfo, allowBypass) {
|
|
2783
2803
|
const modes = [];
|
|
2784
2804
|
// `_meta.kind` is ported from upstream #1025 (REBASE-AND-DRIFT.md §15.5): a coarse
|
|
2785
2805
|
// classification a client can style or group by, alongside the free-text description.
|
|
@@ -2824,7 +2844,7 @@ function buildAvailableModes(modelInfo) {
|
|
|
2824
2844
|
name: "Don't Ask",
|
|
2825
2845
|
description: "Don't prompt for permissions, deny if not pre-approved. Selecting this restarts the session.",
|
|
2826
2846
|
});
|
|
2827
|
-
if (
|
|
2847
|
+
if (allowBypass) {
|
|
2828
2848
|
modes.push({
|
|
2829
2849
|
id: "bypassPermissions",
|
|
2830
2850
|
name: "Bypass Permissions",
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.14.
|
|
6
|
+
"version": "0.14.3",
|
|
7
7
|
"description": "Run the official Claude Code TUI in Zed's agent panel on your Claude Pro/Max subscription — an ACP-over-PTY bridge created for Anthropic's billing split (paused June 15; see README).",
|
|
8
8
|
"main": "dist/lib.js",
|
|
9
9
|
"types": "dist/lib.d.ts",
|