@lucascouts/claude-agent-tui 0.14.0 → 0.14.1

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.
@@ -617,7 +617,9 @@ export type ToolUseCache = {
617
617
  * Return user-message content with local-command marker tags removed, or
618
618
  * `null` if nothing meaningful remains (caller should skip the message).
619
619
  * Preserves real prose that's mixed in alongside the markers — e.g. a
620
- * message like `<command-name>…</command-name>hi` becomes `hi`.
620
+ * message like `<command-name>…</command-name>hi` becomes `hi`. A marker-only
621
+ * slash-skill record is reconstructed as `/name args` unless it is client-local
622
+ * (see REPLAY_HIDDEN_COMMANDS) or carries local stdout/stderr.
621
623
  */
622
624
  export declare function stripLocalCommandMetadata(content: unknown): unknown | null;
623
625
  export declare function isLocalCommandMetadata(content: unknown): boolean;
package/dist/acp-agent.js CHANGED
@@ -458,6 +458,24 @@ const IS_ROOT = (process.geteuid?.() ?? process.getuid?.()) === 0;
458
458
  const ALLOW_BYPASS = !IS_ROOT || !!process.env.IS_SANDBOX;
459
459
  // Slash commands that the SDK handles locally without replaying the user
460
460
  // message and without invoking the model.
461
+ const LOCAL_ONLY_COMMANDS = new Set(["/context", "/heapdump", "/extra-usage"]);
462
+ // Commands whose marker-only transcript records are client-local UI noise, not
463
+ // model-visible user prompts (port of upstream #1035, 97394d9). Marker-only
464
+ // custom slash skills are not in this list, so replay can reconstruct them from
465
+ // `<command-name>`/`<command-args>`. `/effort` and `/fast` are the tui's own:
466
+ // the config-option applies and the fast-mode probe type them into the PTY, and
467
+ // the CLI records them like any user-typed command — without an entry every
468
+ // config change would surface in the thread as a prompt the user never sent.
469
+ // `/model` is injected the same way and is already covered upstream.
470
+ const REPLAY_HIDDEN_COMMANDS = new Set([
471
+ ...LOCAL_ONLY_COMMANDS,
472
+ "/compact",
473
+ "/model",
474
+ "/status",
475
+ "/usage",
476
+ "/effort",
477
+ "/fast",
478
+ ]);
461
479
  // The Claude SDK persists local slash command invocations (e.g. `/model`) and
462
480
  // their output as user messages in the session transcript, wrapping the
463
481
  // payload in these XML-like markers that the CLI uses for its own display.
@@ -498,16 +516,49 @@ function stripMarkerTags(text) {
498
516
  }
499
517
  return result + text.slice(copiedUpTo);
500
518
  }
519
+ function markerTagText(text, tag) {
520
+ const open = `<${tag}>`;
521
+ const close = `</${tag}>`;
522
+ const start = text.indexOf(open);
523
+ if (start === -1)
524
+ return undefined;
525
+ const end = text.indexOf(close, start + open.length);
526
+ if (end === -1)
527
+ return undefined;
528
+ return text.slice(start + open.length, end);
529
+ }
530
+ function hasMarkerTag(text, tag) {
531
+ return markerTagText(text, tag) !== undefined;
532
+ }
533
+ function commandInvocationFromMarkerOnlyText(text) {
534
+ if (hasMarkerTag(text, "local-command-stdout") || hasMarkerTag(text, "local-command-stderr")) {
535
+ return null;
536
+ }
537
+ const commandName = markerTagText(text, "command-name")?.trim();
538
+ if (!commandName?.startsWith("/"))
539
+ return null;
540
+ if (REPLAY_HIDDEN_COMMANDS.has(commandName.split(" ", 1)[0]))
541
+ return null;
542
+ const commandArgs = markerTagText(text, "command-args")?.trim();
543
+ return commandArgs ? `${commandName} ${commandArgs}` : commandName;
544
+ }
545
+ function stripLocalCommandMetadataText(text) {
546
+ const stripped = stripMarkerTags(text);
547
+ if (stripped.trim() !== "")
548
+ return stripped;
549
+ return commandInvocationFromMarkerOnlyText(text);
550
+ }
501
551
  /**
502
552
  * Return user-message content with local-command marker tags removed, or
503
553
  * `null` if nothing meaningful remains (caller should skip the message).
504
554
  * Preserves real prose that's mixed in alongside the markers — e.g. a
505
- * message like `<command-name>…</command-name>hi` becomes `hi`.
555
+ * message like `<command-name>…</command-name>hi` becomes `hi`. A marker-only
556
+ * slash-skill record is reconstructed as `/name args` unless it is client-local
557
+ * (see REPLAY_HIDDEN_COMMANDS) or carries local stdout/stderr.
506
558
  */
507
559
  export function stripLocalCommandMetadata(content) {
508
560
  if (typeof content === "string") {
509
- const stripped = stripMarkerTags(content);
510
- return stripped.trim() === "" ? null : stripped;
561
+ return stripLocalCommandMetadataText(content);
511
562
  }
512
563
  if (!Array.isArray(content))
513
564
  return content;
@@ -519,8 +570,8 @@ export function stripLocalCommandMetadata(content) {
519
570
  block.type === "text" &&
520
571
  "text" in block &&
521
572
  typeof block.text === "string") {
522
- const stripped = stripMarkerTags(block.text);
523
- if (stripped.trim() === "")
573
+ const stripped = stripLocalCommandMetadataText(block.text);
574
+ if (stripped === null)
524
575
  continue;
525
576
  kept.push({ ...block, text: stripped });
526
577
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { resolveSettings } from "@anthropic-ai/claude-agent-sdk";
3
2
  import { runAcp, driveFastModeProbe } from "./acp-agent.js";
3
+ import { applyManagedPolicyEnv } from "./managed-policy.js";
4
4
  import { resolveClaudePath } from "./claude-path.js";
5
5
  import { usageUpdateEnabled } from "./usage-env.js";
6
6
  import { liveDiffEnabled } from "./live-diff-env.js";
@@ -50,13 +50,10 @@ else if (process.argv.includes("--version")) {
50
50
  }
51
51
  else {
52
52
  // Apply env vars from the managed-policy tier before any SDK call so the
53
- // SDK subprocess inherits them. Going through resolveSettings (vs. a raw
54
- // read of managed-settings.json) also picks up MDM sources on macOS and
55
- // HKLM/HKCU on Windows.
56
- const policy = await resolveSettings({ settingSources: [] });
57
- for (const [key, value] of Object.entries(policy.effective.env ?? {})) {
58
- process.env[key] = value;
59
- }
53
+ // SDK subprocess inherits them. Reading the tier is best-effort: a transient
54
+ // failure leaves the agent running with no policy env instead of aborting
55
+ // module evaluation here, before any ACP traffic (port of upstream #1146).
56
+ await applyManagedPolicyEnv();
60
57
  // stdout is used to send messages to the client
61
58
  // we redirect everything else to stderr to make sure it doesn't interfere with ACP
62
59
  console.log = console.error;
@@ -0,0 +1,20 @@
1
+ import { resolveSettings } from "@anthropic-ai/claude-agent-sdk";
2
+ /**
3
+ * Applies the managed-policy tier's env vars to `process.env` before any SDK
4
+ * call, so the spawned CLI inherits them. Going through `resolveSettings`
5
+ * rather than a raw read of `managed-settings.json` also picks up MDM sources on
6
+ * macOS and `HKLM`/`HKCU` on Windows.
7
+ *
8
+ * Port of upstream #1146 (58c5db1). Reading the tier is best-effort by nature:
9
+ * on a host with no MDM and no managed policy the result is empty and the agent
10
+ * behaves identically. So a transient failure to read it — `EINTR`, `EMFILE`,
11
+ * `EAGAIN` — must leave the agent running with no policy env rather than stop
12
+ * it from starting.
13
+ *
14
+ * That guard matters because index.ts awaits this at module scope in an ESM
15
+ * entry point, before its `unhandledRejection` handler exists, where a
16
+ * rejection aborts module evaluation and the process exits before serving any
17
+ * ACP traffic. `SettingsManager` (settings.ts) wraps the same SDK call for the
18
+ * same reason.
19
+ */
20
+ export declare function applyManagedPolicyEnv(resolve?: typeof resolveSettings, env?: Record<string, string | undefined>): Promise<void>;
@@ -0,0 +1,33 @@
1
+ import { resolveSettings } from "@anthropic-ai/claude-agent-sdk";
2
+ /**
3
+ * Applies the managed-policy tier's env vars to `process.env` before any SDK
4
+ * call, so the spawned CLI inherits them. Going through `resolveSettings`
5
+ * rather than a raw read of `managed-settings.json` also picks up MDM sources on
6
+ * macOS and `HKLM`/`HKCU` on Windows.
7
+ *
8
+ * Port of upstream #1146 (58c5db1). Reading the tier is best-effort by nature:
9
+ * on a host with no MDM and no managed policy the result is empty and the agent
10
+ * behaves identically. So a transient failure to read it — `EINTR`, `EMFILE`,
11
+ * `EAGAIN` — must leave the agent running with no policy env rather than stop
12
+ * it from starting.
13
+ *
14
+ * That guard matters because index.ts awaits this at module scope in an ESM
15
+ * entry point, before its `unhandledRejection` handler exists, where a
16
+ * rejection aborts module evaluation and the process exits before serving any
17
+ * ACP traffic. `SettingsManager` (settings.ts) wraps the same SDK call for the
18
+ * same reason.
19
+ */
20
+ export async function applyManagedPolicyEnv(resolve = resolveSettings, env = process.env) {
21
+ let policy;
22
+ try {
23
+ policy = await resolve({ settingSources: [] });
24
+ }
25
+ catch (error) {
26
+ // stderr, so the ACP stream on stdout stays clean.
27
+ console.error("Failed to resolve managed policy settings:", error);
28
+ return;
29
+ }
30
+ for (const [key, value] of Object.entries(policy.effective.env ?? {})) {
31
+ env[key] = value;
32
+ }
33
+ }
package/dist/tools.js CHANGED
@@ -29,6 +29,19 @@ export function toDisplayPath(filePath, cwd) {
29
29
  export function toolCallIdFor(toolUseId, sessionId, options = {}) {
30
30
  return options.namespaced ? `${sessionId}:${toolUseId}` : toolUseId;
31
31
  }
32
+ /** Read a Write tool_use input the way the CLI validates it. Port of upstream #1161 (90cde4b):
33
+ * since 2.1.280 the CLI accepts `path` for `file_path` and `file_text`/`file_content` for
34
+ * `content` when a model sends those spellings, but the transcript's tool_use block still carries
35
+ * them raw — without this the call renders as "Preparing file…" with no diff while the write goes
36
+ * through. The canonical fields win when both spellings are present. */
37
+ function normalizeWriteInput(input) {
38
+ if (!input || typeof input !== "object")
39
+ return undefined;
40
+ const raw = input;
41
+ const filePath = raw.file_path ?? (typeof raw.path === "string" ? raw.path : undefined);
42
+ const content = raw.content ?? raw.file_text ?? raw.file_content;
43
+ return { ...raw, file_path: filePath, content };
44
+ }
32
45
  export function toolInfoFromToolUse(toolUse, supportsTerminalOutput = false, cwd) {
33
46
  const name = toolUse.name;
34
47
  switch (name) {
@@ -110,7 +123,7 @@ export function toolInfoFromToolUse(toolUse, supportsTerminalOutput = false, cwd
110
123
  };
111
124
  }
112
125
  case "Write": {
113
- const input = toolUse.input;
126
+ const input = normalizeWriteInput(toolUse.input);
114
127
  let content = [];
115
128
  if (input && input.file_path) {
116
129
  content = [
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.14.0",
6
+ "version": "0.14.1",
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",