@lazyingart/agintiflow 0.20.84 → 0.20.86

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/README.md CHANGED
@@ -157,6 +157,8 @@ aginti --resume <session-id> \
157
157
 
158
158
  Permission behavior is intentionally consistent: writes inside the current project are allowed through file tools, network/setup runs are normal in approved Docker workspace mode, and outside-project or trusted-host actions stop with a clear blocker plus a suggested rerun command. See [runtime modes and autonomy](docs/runtime-modes-and-autonomy.md) for the full contract.
159
159
 
160
+ Tmux follows the same rule. In Docker sandbox mode, `tmux_start_session` and `tmux_send_keys` are durable host tools, but their commands must stay workspace-bound. In host mode, tmux startup/send command text follows the same host shell policy as `run_command`; broad host shell work needs explicit `--allow-destructive`. Use `--sandbox-mode host --allow-destructive` only when a tmux task really needs trusted whole-host execution.
161
+
160
162
  ## Permission Recipes
161
163
 
162
164
  Use these when you want explicit control instead of the default interactive policy:
@@ -13,6 +13,8 @@ The failed task was expected under the current Docker design, but the agent shou
13
13
 
14
14
  The fix is guidance plus guardrails: raw `tmux` shell commands are blocked inside Docker `run_command`, and the model is told to use host tmux tools for durable sessions.
15
15
 
16
+ Important boundary: host tmux tools are durable, but they are not a permission escape hatch. In `docker-readonly` and `docker-workspace` modes, `tmux_start_session` and `tmux_send_keys` are still workspace-bound. Startup commands and sent shell text must use relative paths under the project, not absolute host paths outside the project. In `host` mode, tmux startup/send command text follows the same host shell policy as `run_command`, so broad host shell work requires `--allow-destructive`. If a task really needs `/home/...`, `/etc/...`, an emulator outside the project, or whole-host maintenance, rerun explicitly with `--sandbox-mode host --allow-destructive`.
17
+
16
18
  ## Execution Modes
17
19
 
18
20
  | Mode | Similar Codex idea | Best use | What persists | Risk |
@@ -137,7 +139,7 @@ Durable tmux task:
137
139
  aginti "start a tmux session named demo, run ls in it, keep it open, and tell me how to attach"
138
140
  ```
139
141
 
140
- The agent should use `tmux_start_session`, `tmux_send_keys`, and `tmux_capture_pane`, not Docker `run_command`.
142
+ The agent should use `tmux_start_session`, `tmux_send_keys`, and `tmux_capture_pane`, not Docker `run_command`. In Docker sandbox mode, tmux commands must stay inside the project. In host mode, tmux command text is still governed by host shell policy; if a tmux command is blocked, present the suggested rerun path instead of trying tmux as a workaround. For trusted whole-host tmux work, use the host recipe above.
141
143
 
142
144
  ## Future Persistent Container Mode
143
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazyingart/agintiflow",
3
- "version": "0.20.84",
3
+ "version": "0.20.86",
4
4
  "type": "module",
5
5
  "description": "Low-cost, project-aware Web and CLI agents with DeepSeek/Venice/OpenAI routing, visible tool calls, durable sessions, scouts, AAPS, SCS, and guarded local execution.",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,21 @@ const workspace = await fs.mkdtemp(path.join(os.tmpdir(), "agintiflow-tmux-"));
20
20
  const session = `aginti-smoke-${process.pid}`;
21
21
  const config = {
22
22
  allowShellTool: true,
23
+ allowDestructive: true,
23
24
  commandCwd: workspace,
25
+ sandboxMode: "host",
26
+ useDockerSandbox: false,
27
+ };
28
+ const strictHostConfig = {
29
+ ...config,
30
+ allowDestructive: false,
31
+ };
32
+ const dockerConfig = {
33
+ ...config,
34
+ allowDestructive: false,
35
+ useDockerSandbox: true,
36
+ sandboxMode: "docker-workspace",
37
+ packageInstallPolicy: "allow",
24
38
  };
25
39
 
26
40
  function sleep(ms) {
@@ -41,7 +55,7 @@ try {
41
55
  target: start.target,
42
56
  text: "printf 'aginti tmux smoke\\n'; pwd",
43
57
  enter: true,
44
- });
58
+ }, config);
45
59
  assert.equal(send.ok, true, send.error || send.reason);
46
60
  await sleep(500);
47
61
 
@@ -65,23 +79,101 @@ try {
65
79
  const destructive = checkTmuxToolUse("tmux_send_keys", { target: start.target, text: "rm -rf /" }, config);
66
80
  assert.equal(destructive.allowed, false, "tmux guardrail did not block destructive text");
67
81
 
82
+ const outsidePath = path.join(os.tmpdir(), "agintiflow-outside-workspace-canary.txt");
83
+ const workspacePath = path.join(workspace, "inside-workspace.txt");
84
+ const dockerTmuxOutsideStart = checkToolUse({
85
+ toolName: "tmux_start_session",
86
+ args: { name: `${session}-outside`, cwd: ".", command: `cat ${outsidePath}` },
87
+ config: dockerConfig,
88
+ });
89
+ assert.equal(dockerTmuxOutsideStart.allowed, false, "Docker-mode tmux_start_session should block outside host paths");
90
+ assert.equal(dockerTmuxOutsideStart.category, "tmux", "outside tmux path block should be categorized as tmux");
91
+
92
+ const dockerTmuxOutsideSend = checkTmuxToolUse(
93
+ "tmux_send_keys",
94
+ { target: start.target, text: `cat ${outsidePath}` },
95
+ dockerConfig
96
+ );
97
+ assert.equal(dockerTmuxOutsideSend.allowed, false, "Docker-mode tmux_send_keys should block outside host paths");
98
+
99
+ const directOutsideStart = await startTmuxSession(
100
+ { name: `${session}-direct-outside`, cwd: ".", command: `cat ${outsidePath}` },
101
+ dockerConfig
102
+ );
103
+ assert.equal(directOutsideStart.ok, false, "tmux_start_session should enforce outside host path guard at execution time");
104
+
105
+ const directOutsideSend = await sendTmuxKeys(
106
+ { target: start.target, text: `cat ${outsidePath}`, enter: false },
107
+ dockerConfig
108
+ );
109
+ assert.equal(directOutsideSend.ok, false, "tmux_send_keys should enforce outside host path guard at execution time");
110
+
111
+ const dockerTmuxWorkspaceStart = checkToolUse({
112
+ toolName: "tmux_start_session",
113
+ args: { name: `${session}-inside`, cwd: ".", command: `cat ${workspacePath}` },
114
+ config: dockerConfig,
115
+ });
116
+ assert.equal(dockerTmuxWorkspaceStart.allowed, true, "Docker-mode tmux_start_session should allow project absolute paths");
117
+
118
+ const dockerTmuxRelativeStart = checkToolUse({
119
+ toolName: "tmux_start_session",
120
+ args: { name: `${session}-relative`, cwd: ".", command: "cat inside-workspace.txt" },
121
+ config: dockerConfig,
122
+ });
123
+ assert.equal(dockerTmuxRelativeStart.allowed, true, "Docker-mode tmux_start_session should allow workspace-relative paths");
124
+
125
+ const hostBroadTmuxStart = checkToolUse({
126
+ toolName: "tmux_start_session",
127
+ args: { name: `${session}-host-broad`, cwd: ".", command: 'echo "HOST_TMUX_STARTED"; sleep 1' },
128
+ config: strictHostConfig,
129
+ });
130
+ assert.equal(hostBroadTmuxStart.allowed, false, "Host-mode tmux_start_session should not bypass host shell approval");
131
+ assert.equal(hostBroadTmuxStart.category, "general-shell", "Host tmux broad command should keep shell policy category");
132
+
133
+ const hostBroadTmuxSend = checkTmuxToolUse(
134
+ "tmux_send_keys",
135
+ { target: start.target, text: 'echo "HOST_TMUX_SEND"; sleep 1' },
136
+ strictHostConfig
137
+ );
138
+ assert.equal(hostBroadTmuxSend.allowed, false, "Host-mode tmux_send_keys should not bypass host shell approval");
139
+ assert.equal(hostBroadTmuxSend.category, "general-shell", "Host tmux send should keep shell policy category");
140
+
141
+ const directHostBroadStart = await startTmuxSession(
142
+ { name: `${session}-direct-host-broad`, cwd: ".", command: 'echo "HOST_TMUX_STARTED"; sleep 1' },
143
+ strictHostConfig
144
+ );
145
+ assert.equal(directHostBroadStart.ok, false, "tmux_start_session direct path should enforce host shell approval");
146
+
147
+ const directHostBroadSend = await sendTmuxKeys(
148
+ { target: start.target, text: 'echo "HOST_TMUX_SEND"; sleep 1', enter: false },
149
+ strictHostConfig
150
+ );
151
+ assert.equal(directHostBroadSend.ok, false, "tmux_send_keys direct path should enforce host shell approval");
152
+
153
+ const hostInterruptKey = checkTmuxToolUse(
154
+ "tmux_send_keys",
155
+ { target: start.target, text: "", keys: ["C-c"], enter: false },
156
+ strictHostConfig
157
+ );
158
+ assert.equal(hostInterruptKey.allowed, true, "Host-mode tmux_send_keys should still allow safe control keys");
159
+
68
160
  const dockerTmuxCommand = checkToolUse({
69
161
  toolName: "run_command",
70
162
  args: { command: "tmux new-session -d -s should-not-run" },
71
- config: { ...config, useDockerSandbox: true, sandboxMode: "docker-workspace", packageInstallPolicy: "allow" },
163
+ config: dockerConfig,
72
164
  });
73
165
  assert.equal(dockerTmuxCommand.allowed, false, "Docker run_command tmux usage should be blocked in favor of host tmux tools");
74
166
  const dockerTmuxSearch = checkToolUse({
75
167
  toolName: "run_command",
76
168
  args: { command: "rg tmux README.md" },
77
- config: { ...config, useDockerSandbox: true, sandboxMode: "docker-workspace", packageInstallPolicy: "allow" },
169
+ config: dockerConfig,
78
170
  });
79
171
  assert.equal(dockerTmuxSearch.allowed, true, "Docker run_command should still allow harmless tmux text searches");
80
172
 
81
173
  const dockerNpxAginti = checkToolUse({
82
174
  toolName: "run_command",
83
175
  args: { command: "npx aginti doctor --json" },
84
- config: { ...config, useDockerSandbox: true, sandboxMode: "docker-workspace", packageInstallPolicy: "allow" },
176
+ config: dockerConfig,
85
177
  });
86
178
  assert.equal(dockerNpxAginti.allowed, false, "Docker run_command should block npx aginti self-invocation");
87
179
  assert.equal(dockerNpxAginti.category, "nested-aginti", "npx aginti block should be categorized");
@@ -89,7 +181,7 @@ try {
89
181
  const dockerNestedAginti = checkToolUse({
90
182
  toolName: "run_command",
91
183
  args: { command: "aginti storage status" },
92
- config: { ...config, useDockerSandbox: true, sandboxMode: "docker-workspace", packageInstallPolicy: "allow" },
184
+ config: dockerConfig,
93
185
  });
94
186
  assert.equal(dockerNestedAginti.allowed, false, "Docker run_command should block nested aginti CLI calls");
95
187
  assert.equal(dockerNestedAginti.category, "nested-aginti", "nested aginti block should be categorized");
@@ -107,6 +199,13 @@ try {
107
199
  "list-sessions",
108
200
  "secret-guardrail",
109
201
  "destructive-guardrail",
202
+ "docker-tmux-start-outside-path-guardrail",
203
+ "docker-tmux-send-outside-path-guardrail",
204
+ "docker-tmux-start-project-path-allowed",
205
+ "docker-tmux-start-relative-path-allowed",
206
+ "host-tmux-start-shell-policy-guardrail",
207
+ "host-tmux-send-shell-policy-guardrail",
208
+ "host-tmux-control-key-allowed",
110
209
  "docker-run-command-tmux-guardrail",
111
210
  "docker-run-command-tmux-search-allowed",
112
211
  "docker-run-command-npx-aginti-guardrail",
@@ -428,7 +428,7 @@ async function createInitialState(config, sessionId) {
428
428
  "Permission contract: current-workspace file writes are allowed through workspace file tools when enabled. Outside-workspace paths, host sudo, host OS package installs, destructive git/shell actions, and blocked network/setup must not be bypassed by retrying variants. If a tool result includes permissionAdvice or suggestedCommand, stop, explain the blocker, copy the exact suggestedCommand when giving a rerun path, and ask the user to approve/rerun that mode or choose a safer workspace-relative path. Never invent legacy AgInTi syntax such as `aginti run --sandbox host`; use the exact flags from permissionAdvice.",
429
429
  "If an operation fails but a directory, artifact, or file already exists, treat it as pre-existing unless you have evidence this run created or updated it. Verify expected outputs before claiming success.",
430
430
  config.allowShellTool
431
- ? "Host tmux tools are available for long-running terminals: list sessions, capture panes, send safe keys/text, and start detached sessions. Prefer these tools for monitoring long installs/tests/dev servers without blocking; capture before sending input and never send secrets or sudo passwords. Do not start or install tmux inside Docker run_command containers because those containers are short-lived."
431
+ ? "Host tmux tools are available for long-running terminals: list sessions, capture panes, send safe keys/text, and start detached sessions. Prefer these tools for monitoring long installs/tests/dev servers without blocking; capture before sending input and never send secrets or sudo passwords. Do not start or install tmux inside Docker run_command containers because those containers are short-lived. In Docker sandbox mode, tmux start/send commands must stay workspace-bound and must not reference absolute host paths outside the project; ask for --sandbox-mode host for trusted whole-host work."
432
432
  + " For one-shot tmux commands, redirect stdout/stderr and exit status to a durable workspace log or keep the pane alive for capture; if capture fails because the session ended, do not infer output or exit status."
433
433
  : "",
434
434
  config.allowFileTools
@@ -894,7 +894,7 @@ async function captureSyntheticSnapshot(store, step, config) {
894
894
  : `Shell tool available in: ${config.commandCwd} on ${platformLabel(platform)}. Use OS-compatible commands; prefer WSL/Docker for bash-heavy workflows on Windows.`
895
895
  : "Shell tool disabled.",
896
896
  config.allowShellTool
897
- ? "Host tmux tools available: tmux_list_sessions, tmux_capture_pane, tmux_send_keys, tmux_start_session. Use them for long-running jobs and agent terminals; capture before sending input. Docker run_command containers are ephemeral, so tmux there will not persist. For one-shot tmux commands, redirect output and exit status to a durable workspace log or keep the pane alive for capture; if capture fails because the session ended, do not infer output or exit status."
897
+ ? "Host tmux tools available: tmux_list_sessions, tmux_capture_pane, tmux_send_keys, tmux_start_session. Use them for long-running jobs and agent terminals; capture before sending input. Docker run_command containers are ephemeral, so tmux there will not persist. In Docker sandbox mode, tmux start/send commands must stay workspace-bound and cannot reference absolute host paths outside the project; use --sandbox-mode host for trusted whole-host work. In host mode, tmux startup/send command text follows the same host shell policy as run_command; if a broad host command is blocked, present the approval/rerun path instead of trying tmux as a workaround. For one-shot tmux commands, redirect output and exit status to a durable workspace log or keep the pane alive for capture; if capture fails because the session ended, do not infer output or exit status."
898
898
  : "",
899
899
  config.allowFileTools
900
900
  ? `Workspace file tools available in: ${config.commandCwd}. Use inspect_project first for large or unfamiliar codebases, then search/read exact files before editing. Use workspace-relative paths. Use apply_patch for code edits; it supports exact single-file replacement and multi-file Codex-style/unified patches. For new standalone generated content, pick a descriptive non-conflicting filename and avoid overwriting unless explicitly requested.`
@@ -1224,7 +1224,7 @@ async function executeTool(browserState, toolCall, snapshot, config, store, obse
1224
1224
  return result;
1225
1225
  }
1226
1226
  case "tmux_send_keys": {
1227
- const result = await sendTmuxKeys(args);
1227
+ const result = await sendTmuxKeys(args, config);
1228
1228
  const eventResult = sanitizeToolResult(result);
1229
1229
  await store.appendEvent(result.ok ? "tool.completed" : "tool.failed", eventResult);
1230
1230
  observers.event(result.ok ? "tool.completed" : "tool.failed", eventResult);
@@ -512,7 +512,7 @@ export async function createPlan(client, config, state) {
512
512
  ? `Shell tool is enabled in ${config.commandCwd}. Host platform: ${platformLabel(platform)}. In Docker, this path is mounted as /workspace with persistent /aginti-env and /aginti-cache mounts. Use relative paths or /workspace paths, not absolute host temp paths. Sandbox mode: ${config.sandboxMode}. Package install policy: ${config.packageInstallPolicy}. For npm/pip/conda/venv setup, explain the need and wait for approval unless policy is allow. Do not run npx aginti, npm exec aginti, or nested aginti diagnostics from this shell; they may resolve stale project packages or create recursive agent sessions. On native Windows host mode, prefer PowerShell/cmd-compatible commands or WSL/Docker for bash-like toolchains.`
513
513
  : "",
514
514
  config.allowShellTool
515
- ? "Host tmux tools are enabled for long-running sessions. Plan to use tmux_start_session for durable jobs, tmux_capture_pane to monitor, tmux_send_keys to interact after capture, and tmux_list_sessions to discover existing sessions. Do not install or run tmux inside Docker run_command containers; those containers are short-lived and cannot preserve tmux servers."
515
+ ? "Host tmux tools are enabled for long-running sessions. Plan to use tmux_start_session for durable jobs, tmux_capture_pane to monitor, tmux_send_keys to interact after capture, and tmux_list_sessions to discover existing sessions. Do not install or run tmux inside Docker run_command containers; those containers are short-lived and cannot preserve tmux servers. In Docker sandbox mode, tmux startup/send commands are still workspace-bound: use relative project paths, not absolute host paths outside the workspace. In host mode, tmux startup/send command text follows the same host shell policy as run_command; if blocked, present the suggested approval/rerun path instead of trying tmux as a workaround. Ask for --sandbox-mode host --allow-destructive before trusted whole-host tmux work."
516
516
  : "",
517
517
  config.allowFileTools
518
518
  ? `Workspace file tools are enabled in ${config.commandCwd}: inspect_project, list_files, read_file, search_files, write_file, apply_patch, open_workspace_file, preview_workspace. For large or unfamiliar repos, plan to call inspect_project first, then search/read AGINTI.md/AGENTS.md/README/manifests and exact files. apply_patch supports exact single-file replacements and Codex-style/unified multi-file patches; prefer it for edits after reading relevant context. Keep all paths workspace-relative, for example plot_fx.svg or docs/report.tex, and avoid secrets. For newly generated standalone prose/docs/stories/assets, choose a descriptive non-conflicting filename from the topic/language instead of generic names like story.txt or output.txt; do not overwrite existing files unless the user explicitly asked to update/replace/overwrite that file. For generated local HTML/SVG/PDF/static sites, plan to use open_workspace_file or preview_workspace rather than starting a localhost server inside Docker.`
@@ -786,7 +786,7 @@ export async function requestNextStep(client, config, messages) {
786
786
  function: {
787
787
  name: "tmux_send_keys",
788
788
  description:
789
- "Send literal text and/or safe control keys to a durable host tmux pane. Use for interacting with known shells or agent sessions after capturing context. Do not send secrets, passwords, sudo passwords, or destructive commands.",
789
+ "Send literal text and/or safe control keys to a durable host tmux pane. Use for interacting with known shells or agent sessions after capturing context. Do not send secrets, passwords, sudo passwords, destructive commands, or absolute host paths outside the workspace unless the run is explicitly in host sandbox mode.",
790
790
  parameters: {
791
791
  type: "object",
792
792
  properties: {
@@ -812,7 +812,7 @@ export async function requestNextStep(client, config, messages) {
812
812
  function: {
813
813
  name: "tmux_start_session",
814
814
  description:
815
- "Start a detached durable host tmux session rooted inside the workspace, optionally with a startup command. Use for long-running local jobs that should be monitored with tmux_capture_pane instead of blocking the agent. For one-shot commands, redirect output and exit status to a durable workspace log or keep the shell open so capture can verify; do not claim results from an auto-terminated session. This is the correct tmux path in Docker mode because run_command containers are ephemeral.",
815
+ "Start a detached durable host tmux session rooted inside the workspace, optionally with a startup command. Use for long-running local jobs that should be monitored with tmux_capture_pane instead of blocking the agent. For one-shot commands, redirect output and exit status to a durable workspace log or keep the shell open so capture can verify; do not claim results from an auto-terminated session. In Docker sandbox mode, startup commands must stay workspace-bound and must not reference absolute host paths outside the project; ask for --sandbox-mode host for trusted whole-host work.",
816
816
  parameters: {
817
817
  type: "object",
818
818
  properties: {
@@ -67,12 +67,12 @@ function currentMode(config = {}) {
67
67
  }
68
68
 
69
69
  function adviceForCategory(category = "", { toolName = "", args = {}, config = {}, state = {}, reason = "" } = {}) {
70
- const command = compactLine(args.command || "");
70
+ const command = compactLine(args.command || args.text || "");
71
71
  const base = {
72
72
  category: category || "permission",
73
73
  reason: compactLine(reason || "The runtime policy blocked this operation."),
74
74
  currentMode: currentMode(config),
75
- blockedOperation: command ? `run_command: ${command}` : toolName,
75
+ blockedOperation: command ? `${toolName || "tool"}: ${command}` : toolName,
76
76
  instruction:
77
77
  "Stop and present this blocker to the user instead of repeatedly trying variants. Continue only after the user approves a safer mode, changes the workspace, or gives a replacement instruction.",
78
78
  };
package/src/tmux-tools.js CHANGED
@@ -2,6 +2,7 @@ import crypto from "node:crypto";
2
2
  import path from "node:path";
3
3
  import { execFile as execFileCallback } from "node:child_process";
4
4
  import { promisify } from "node:util";
5
+ import { evaluateCommandPolicy } from "./command-policy.js";
5
6
  import { redactSensitiveText } from "./redaction.js";
6
7
 
7
8
  const execFile = promisify(execFileCallback);
@@ -30,6 +31,8 @@ const ALLOWED_KEYS = new Set([
30
31
  const SECRET_PATTERN = /(api[_-]?key|auth[_-]?token|npm[_-]?token|_authToken|password|passwd|secret|bearer\s+[A-Za-z0-9._-]+)/i;
31
32
  const DESTRUCTIVE_PATTERN =
32
33
  /\b(rm\s+-[^\n;]*[rf][^\n;]*(\/|\*|~|\$HOME)|mkfs(?:\.[a-z0-9]+)?\b|dd\s+if=.*\s+of=\/dev\/|shutdown\b|reboot\b|poweroff\b)/i;
34
+ const ABSOLUTE_PATH_PATTERN = /(^|[\s"'`=(:])((?:\/[A-Za-z0-9._@%+~:-]+)+\/?)/g;
35
+ const ALWAYS_ALLOWED_ABSOLUTE_PATHS = new Set(["/dev/null"]);
33
36
 
34
37
  export const TMUX_TOOL_NAMES = ["tmux_list_sessions", "tmux_capture_pane", "tmux_send_keys", "tmux_start_session"];
35
38
 
@@ -103,6 +106,53 @@ function resolveCwd(config, cwd = ".") {
103
106
  return { ok: true, cwd: requested };
104
107
  }
105
108
 
109
+ function isInsideDirectory(root, candidate) {
110
+ const relative = path.relative(root, candidate);
111
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
112
+ }
113
+
114
+ function uniqueAbsolutePaths(text = "") {
115
+ const paths = new Set();
116
+ for (const match of String(text || "").matchAll(ABSOLUTE_PATH_PATTERN)) {
117
+ const candidate = match[2];
118
+ if (!candidate || candidate.startsWith("//")) continue;
119
+ paths.add(candidate.replace(/[),.;]+$/g, ""));
120
+ }
121
+ return [...paths].filter(Boolean);
122
+ }
123
+
124
+ function checkWorkspaceBoundTmuxText(text = "", config = {}, label = "tmux text") {
125
+ if (!config.useDockerSandbox) return { ok: true };
126
+ const root = path.resolve(config.commandCwd || process.cwd());
127
+ for (const candidate of uniqueAbsolutePaths(text)) {
128
+ if (ALWAYS_ALLOWED_ABSOLUTE_PATHS.has(candidate)) continue;
129
+ const resolved = path.resolve(candidate);
130
+ if (!isInsideDirectory(root, resolved)) {
131
+ return {
132
+ ok: false,
133
+ reason: `${label} references an absolute host path outside the configured workspace while Docker sandbox mode is active: ${candidate}. Use a workspace-relative path or rerun with --sandbox-mode host for trusted whole-host access.`,
134
+ };
135
+ }
136
+ }
137
+ return { ok: true };
138
+ }
139
+
140
+ function checkHostShellPolicyForTmuxText(text = "", config = {}, label = "tmux text") {
141
+ const command = String(text || "").trim();
142
+ if (!command) return { ok: true };
143
+ if (config.useDockerSandbox || config.sandboxMode !== "host" || config.allowDestructive) {
144
+ return { ok: true };
145
+ }
146
+ const policy = evaluateCommandPolicy(command, config);
147
+ if (policy.allowed) return { ok: true };
148
+ return {
149
+ ok: false,
150
+ reason: `${label} is blocked by the same host shell policy as run_command: ${policy.reason}`,
151
+ category: policy.category || "tmux",
152
+ needsApproval: policy.needsApproval,
153
+ };
154
+ }
155
+
106
156
  function parseSessions(stdout = "") {
107
157
  return String(stdout || "")
108
158
  .split(/\r?\n/)
@@ -186,7 +236,7 @@ export async function captureTmuxPane(args = {}) {
186
236
  };
187
237
  }
188
238
 
189
- export async function sendTmuxKeys(args = {}) {
239
+ export async function sendTmuxKeys(args = {}, config = {}) {
190
240
  const target = validateTarget(args.target);
191
241
  if (!target.ok) return { ok: false, toolName: "tmux_send_keys", blocked: true, reason: target.reason };
192
242
  const text = String(args.text || "");
@@ -201,6 +251,21 @@ export async function sendTmuxKeys(args = {}) {
201
251
  if (DESTRUCTIVE_PATTERN.test(text)) {
202
252
  return { ok: false, toolName: "tmux_send_keys", blocked: true, reason: "tmux text appears destructive; ask the user before sending it." };
203
253
  }
254
+ const workspaceBound = checkWorkspaceBoundTmuxText(text, config, "tmux text");
255
+ if (!workspaceBound.ok) {
256
+ return { ok: false, toolName: "tmux_send_keys", blocked: true, reason: workspaceBound.reason };
257
+ }
258
+ const hostPolicy = checkHostShellPolicyForTmuxText(text, config, "tmux text");
259
+ if (!hostPolicy.ok) {
260
+ return {
261
+ ok: false,
262
+ toolName: "tmux_send_keys",
263
+ blocked: true,
264
+ reason: hostPolicy.reason,
265
+ category: hostPolicy.category,
266
+ needsApproval: hostPolicy.needsApproval,
267
+ };
268
+ }
204
269
  for (const key of keys) {
205
270
  if (!ALLOWED_KEYS.has(key)) {
206
271
  return { ok: false, toolName: "tmux_send_keys", blocked: true, reason: `Unsupported tmux key: ${key}` };
@@ -252,6 +317,21 @@ export async function startTmuxSession(args = {}, config = {}) {
252
317
  reason: "tmux startup command appears destructive; ask the user before starting it.",
253
318
  };
254
319
  }
320
+ const workspaceBound = checkWorkspaceBoundTmuxText(command, config, "tmux startup command");
321
+ if (!workspaceBound.ok) {
322
+ return { ok: false, toolName: "tmux_start_session", blocked: true, reason: workspaceBound.reason };
323
+ }
324
+ const hostPolicy = checkHostShellPolicyForTmuxText(command, config, "tmux startup command");
325
+ if (!hostPolicy.ok) {
326
+ return {
327
+ ok: false,
328
+ toolName: "tmux_start_session",
329
+ blocked: true,
330
+ reason: hostPolicy.reason,
331
+ category: hostPolicy.category,
332
+ needsApproval: hostPolicy.needsApproval,
333
+ };
334
+ }
255
335
 
256
336
  const tmuxArgs = ["new-session", "-d", "-s", name.name, "-c", cwd.cwd];
257
337
  if (command) tmuxArgs.push(command);
@@ -289,6 +369,17 @@ export function checkTmuxToolUse(toolName, args = {}, config = {}) {
289
369
  if (DESTRUCTIVE_PATTERN.test(text)) {
290
370
  return { allowed: false, reason: "tmux text appears destructive; ask the user before sending it.", category: "tmux" };
291
371
  }
372
+ const workspaceBound = checkWorkspaceBoundTmuxText(text, config, "tmux text");
373
+ if (!workspaceBound.ok) return { allowed: false, reason: workspaceBound.reason, category: "tmux" };
374
+ const hostPolicy = checkHostShellPolicyForTmuxText(text, config, "tmux text");
375
+ if (!hostPolicy.ok) {
376
+ return {
377
+ allowed: false,
378
+ reason: hostPolicy.reason,
379
+ category: hostPolicy.category || "tmux",
380
+ needsApproval: hostPolicy.needsApproval,
381
+ };
382
+ }
292
383
  for (const key of Array.isArray(args.keys) ? args.keys : []) {
293
384
  if (!ALLOWED_KEYS.has(String(key))) return { allowed: false, reason: `Unsupported tmux key: ${key}`, category: "tmux" };
294
385
  }
@@ -309,6 +400,17 @@ export function checkTmuxToolUse(toolName, args = {}, config = {}) {
309
400
  if (DESTRUCTIVE_PATTERN.test(command)) {
310
401
  return { allowed: false, reason: "tmux startup command appears destructive; ask the user before starting it.", category: "tmux" };
311
402
  }
403
+ const workspaceBound = checkWorkspaceBoundTmuxText(command, config, "tmux startup command");
404
+ if (!workspaceBound.ok) return { allowed: false, reason: workspaceBound.reason, category: "tmux" };
405
+ const hostPolicy = checkHostShellPolicyForTmuxText(command, config, "tmux startup command");
406
+ if (!hostPolicy.ok) {
407
+ return {
408
+ allowed: false,
409
+ reason: hostPolicy.reason,
410
+ category: hostPolicy.category || "tmux",
411
+ needsApproval: hostPolicy.needsApproval,
412
+ };
413
+ }
312
414
  return { allowed: true, category: "tmux" };
313
415
  }
314
416
  return { allowed: true, category: "tmux" };