Team Core — Default Room
← All Room Trees › alice › @advisor › alice › @advisor › alice: "alice approved suggestion sg-5o7k (…"
4 replies
alice 16:02:41 approval Next post lands here
alice approved suggestion sg-5o7k (Draft direct environment execution slash command spec). Notifying @sup-core.
alice approved suggestion sg-5o7k (Draft direct environment execution slash command spec). Notifying @sup-core.
Truncated in your view
Suggestion sg-5o7k Draft direct environment execution slash command spec activated

User requested a slash command to run verbatim shell commands inside specific spawned environments without agent mediation.

Draft a feature specification for a `/exec` or `/run` slash command covering syntax, environment targeting, output streaming, and security boundaries.
@sup clanker 16:02:41 dispatch Next post lands here
@sup-core dispatched @clnkr-sdxv (Draft direct environment execution s) via hermes_ai [gcp-gemini-3.8-flash]: Draft a feature specification for a `/exec` or `/run` slash command covering syntax, environment targeting, output streaming, and security boundaries.
@sup-core dispatched @clnkr-sdxv (Draft direct environment execution s) via hermes_ai [gcp-gemini-3.8-flash]: Draft a feature specification for a `/exec` or `/run` slash command covering syntax, environment targeting, output streaming, and security boundaries.
Truncated in your view
@clnkr-sdxv clanker 16:03:51 depth 6 Next post lands here
# Feature Specification: Direct Environment Execution (`/exec`, `/run`)

**Status:** Draft / Proposed  
**Proposal Reference:** `sg-5o7k`  
**Target:** Europa Core Orchestrator & Room Terminal Services  

---

## 1. Overview & Objective

Allows human operators (such as `@alice`) to dispatch arbitrary, verbatim shell commands directly into spawned worker sandboxes or container environments via a slash command, completely bypassing conversational agent synthesis and clanker dispatch proposals.

### Key Requirements
- **Deterministic & Verbatim:** Execute exact shell commands without LLM reinterpretation or tool formatting.
- **Low-Latency & Direct:** Low-overhead dispatch directly to the target environment's runtime daemon.
- **Context Preservation:** Stream output directly to the active room/thread without polluting chat context with unbounded terminal dumps.
- **Enforced Isolation:** Maintain strict container boundaries, permission controls, and secret redaction.

---

## 2. Command Syntax & CLI Interface

### 2.1 Basic Grammar
```text
/exec [options] <target-env> -- <verbatim_command>
/run  [options] <target-env> <verbatim_command>
```
- **Primary Command:** `/exec`
- **Aliases:** `/run`, `/sh`
- **Double-Dash (`--`):** Optional separator that treats all subsequent tokens strictly as literal command strings, preventing collision with `/exec` flags (e.g. `/exec @clnkr-3b9a -- ls -la --sort=time`).

### 2.2 Options & Flags
| Flag | Long Form | Default | Description |
|---|---|---|---|
| `-e, --env <target>` | `--env` | *Positional or active default* | Explicit environment/agent selector. |
| `-d, --dir <path>` | `--dir` | Workspace root (`/workspace`) | Working directory inside target container. |
| `-t, --timeout <sec>` | `--timeout` | `60` (max `600`) | Command timeout before sending `SIGTERM`/`SIGKILL`. |
| `-b, --background` | `--background` | `false` | Run asynchronously; returns a background task ID (`job-xxxx`). |
| `--pty` | `--pty` | `false` | Allocate a pseudo-terminal (emulates TTY for colored CLI tools). |
| `--ephemeral` | `--ephemeral` | `false` | Output is delivered only to the invoking user's view (not posted to room). |
| `--thread` | `--thread` | `false` | Force output card into a separate response thread rather than main room feed. |

### 2.3 Invocation Examples
```bash
# Quick inspection in a worker container
/exec @clnkr-8f2a git status -s

# Running a build with flags using -- delimiter
/exec @clnkr-8f2a -- pytest -q tests/test_auth.py -k "test_jwt"

# Ephemeral diagnostic in a specific directory
/exec --dir /workspace/frontend --ephemeral @clnkr-8f2a pnpm build

# Long-running background job
/exec -b -t 300 @clnkr-8f2a cargo test
```

---

## 3. Environment Targeting & Resolution

### 3.1 Target Resolution Hierarchy
When resolving `<target-env>`, the orchestrator matches against the following priorities:

1. **Clanker Worker Tag (`@clnkr-xxxx`):**
   - Resolves to the container sandbox allocated to that worker clanker.
2. **Explicit Environment / Container ID (`env:<id>` or `ct:<id>`):**
   - Direct handle to a spawned container or container pool instance.
3. **Ambient Default Resolution (when `<target-env>` is omitted or set to `.`):**
   - If the room has **exactly one** running worker/container, it binds automatically.
   - If **multiple** or **zero** environments are active, execution fails fast with an ephemeral disambiguation list:
     ```text
     [Target Ambiguity Error] Multiple active environments in this room:
       - @clnkr-8f2a (Node/TypeScript worker) [running]
       - @clnkr-91cb (Python/Pytest worker)  [running]
     Use /exec <target> <cmd> to target a specific sandbox.
     ```

### 3.2 Environment Lifecycle Checks
- **Target State Validation:** Before dispatching, the executor checks that the container state is `RUNNING`.
- **Suspended / Paused Containers:** Commands are rejected unless `--wake` is supplied, preventing unintentional billing or latency spikes.
- **Terminated Environments:** Clear error indicating the worker environment has already shut down.

---

## 4. Output Streaming & Presentation Architecture

### 4.1 Real-Time Streaming Pipeline
```
[User Slash Input]
       │
       ▼
[Europa Slash Router]  ──(Auth & Target Resolution)
       │
       ▼
[Container Exec Bridge] (via container engine exec socket / gRPC)
       │
       ├── stdout / stderr chunk events
       ▼
[Room Event Bus / WebSocket]
       │
       ▼
[Room Stream / UI Terminal Block]
```

- **Delta Streaming:** Output is streamed over the room WebSocket using lightweight `exec.chunk` events containing `{exec_id, stream: "stdout"|"stderr", seq, delta}`.
- **Interactive UI Card:** Renders as a dedicated collapsible terminal card in the chat UI:
  - Header: Target environment, working directory, verbatim command string, elapsed runtime timer.
  - Body: Scrollable, dark-mode ANSI terminal block with line numbering.
  - Footer: Exit status code (e.g. `Exit 0 [Success]` or `Exit 137 [OOM/Killed]`), total execution duration, and log download action.

### 4.2 Bounded Output & Flood Protection
To prevent blowing context limits or browser performance on unbounded output (e.g., recursive `tree` or runaway `find /`):
- **Inline Display Caps:** UI terminal preview is capped at **1,000 lines or 50 KB**.
- **Head & Tail Truncation:** If output exceeds the limit, the inline view displays the first 200 lines and last 300 lines with an inline notice:
  ```text
  [Output truncated: 4,821 lines omitted. Download complete output: /artifacts/exec-8f2a-71d.log]
  ```
- **Log Archiving:** The full un-truncated raw stdout/stderr stream is saved to the workspace artifact store.
- **Control Character Sanitization:** Terminal escape sequences are filtered to permit ANSI colors/text styling while stripping malicious terminal control escapes (cursor jumps, terminal title rewrites, screen clears).

### 4.3 Process Control
- **Cancellation Button:** Active exec blocks render a live `Cancel (SIGINT)` / `Force Kill (SIGKILL)` button in the UI for the command owner.
- **Automatic Heartbeat:** If no output is received within a 30-second silence window during long commands, a quiet ping indicator is displayed.

---

## 5. Security Boundaries & Guardrails

### 5.1 Authorization & Role Boundaries
- **Room RBAC:** Direct execution is restricted to users with `Room Owner` or `Operator` roles. Clankers and guest observers cannot execute `/exec`.
- **Attribution:** Every execution event records the initiating user's ID (`actor_user_id`), ensuring auditability.

### 5.2 Sandbox Isolation & Container Containment
- **Unprivileged Execution:** All commands execute inside the container as a non-root workspace user (e.g., `user` / `uid 1000`), never host root.
- **Host Shielding:** The host Docker/Podman socket and Europa orchestrator network interfaces are inaccessible from within the executed process.
- **Resource Capping:** Enforce pre-configured container cgroup limits (CPU shares, RAM limit, max process PID count) to prevent fork-bombs from affecting host stability.

### 5.3 Secret Shielding & Output Masking
- **Environment Scrubbing:** Target processes inherit the container's designated workspace environment, but Europa platform secrets (gateway tokens, room API keys) are omitted.
- **Real-time Redaction Filter:** Stdout/stderr streams pass through Europa's secret-scrubbing filter before broadcast to mask detected API tokens, AWS keys, or private SSH keys.

### 5.4 Audit Logging
Every `/exec` call generates an immutable audit record in the room event log:
```json
{
  "event": "direct_exec.completed",
  "actor_user_id": "alice",
  "target_env": "@clnkr-8f2a",
  "container_id": "ct-9382f1b0a",
  "command": "pytest -q tests/test_auth.py",
  "exit_code": 0,
  "duration_ms": 1420,
  "artifact_url": "/artifacts/exec-9382f1b0a-001.log"
}
```

---

## 6. Implementation Phases

1. **Phase 1 (Core Routing & Execution):**
   - Register `/exec` and `/run` in `europa/commands.py`.
   - Wire target resolution to running worker containers.
   - Execute commands synchronously via `subprocess`/container exec API with basic exit code reporting.
2. **Phase 2 (Streaming & Terminal Card UI):**
   - Implement WebSocket `exec.chunk` streaming events.
   - Add frontend collapsible terminal card with ANSI rendering and head/tail truncation.
3. **Phase 3 (Process Control & Audit Hardening):**
   - Add interactive cancellation (`SIGINT`/`SIGTERM`) and background mode (`-b`).
   - Connect artifact storage for oversized log downloads and apply secret scrubbing.
# Feature Specification: Direct Environment Execution (`/exec`, `/run`)

**Status:** Draft / Proposed  
**Proposal Reference:** `sg-5o7k`  
**Target:** Europa Core Orchestrator & Room Terminal Services  

---

## 1. Overview & Objective

Allows human operators (such as `@alice`) to dispatch arbitrary, verbatim shell commands directly into spawned worker sandboxes or container environments via a slash command, completely bypassing conversational agent synthesis and clanker dispatch proposals.

### Key Requirements
- **Deterministic & Verbatim:** Execute exact shell commands without LLM reinterpretation or tool formatting.
- **Low-Latency & Direct:** Low-overhead dispatch directly to the target environment's runtime daemon.
- **Context Preservation:** Stream output directly to the active room/thread without polluting chat context with unbounded terminal dumps.
- **Enforced Isolation:** Maintain strict container boundaries, permission controls, and secret redaction.

---

## 2. Command Syntax & CLI Interface

### 2.1 Basic Grammar
```text
/exec [options] <target-env> -- <verbatim_command>
/run  [options] <target-env> <verbatim_command>
```
- **Primary Command:** `/exec`
- **Aliases:** `/run`, `/sh`
- **Double-Dash (`--`):** Optional separator that treats all subsequent tokens strictly as literal command strings, preventing collision with `/exec` flags (e.g. `/exec @clnkr-3b9a -- ls -la --sort=time`).

### 2.2 Options & Flags
| Flag | Long Form | Default | Description |
|---|---|---|---|
| `-e, --env <target>` | `--env` | *Positional or active default* | Explicit environment/agent selector. |
| `-d, --dir <path>` | `--dir` | Workspace root (`/workspace`) | Working directory inside target container. |
| `-t, --timeout <sec>` | `--timeout` | `60` (max `600`) | Command timeout before sending `SIGTERM`/`SIGKILL`. |
| `-b, --background` | `--background` | `false` | Run asynchronously; returns a background task ID (`job-xxxx`). |
| `--pty` | `--pty` | `false` | Allocate a pseudo-terminal (emulates TTY for colored CLI tools). |
| `--ephemeral` | `--ephemeral` | `false` | Output is delivered only to the invoking user's view (not posted to room). |
| `--thread` | `--thread` | `false` | Force output card into a separate response thread rather than main room feed. |

### 2.3 Invocation Examples
```bash
# Quick inspection in a worker container
/exec @clnkr-8f2a git status -s

# Running a build with flags using -- delimiter
/exec @clnkr-8f2a -- pytest -q tests/test_auth.py -k "test_jwt"

# Ephemeral diagnostic in a specific directory
/exec --dir /workspace/frontend --ephemeral @clnkr-8f2a pnpm build

# Long-running background job
/exec -b -t 300 @clnkr-8f2a cargo test
```

---

## 3. Environment Targeting & Resolution

### 3.1 Target Resolution Hierarchy
When resolving `<target-env>`, the orchestrator matches against the following priorities:

1. **Clanker Worker Tag (`@clnkr-xxxx`):**
   - Resolves to the container sandbox allocated to that worker clanker.
2. **Explicit Environment / Container ID (`env:<id>` or `ct:<id>`):**
   - Direct handle to a spawned container or container pool instance.
3. **Ambient Default Resolution (when `<target-env>` is omitted or set to `.`):**
   - If the room has **exactly one** running worker/container, it binds automatically.
   - If **multiple** or **zero** environments are active, execution fails fast with an ephemeral disambiguation list:
     ```text
     [Target Ambiguity Error] Multiple active environments in this room:
       - @clnkr-8f2a (Node/TypeScript worker) [running]
       - @clnkr-91cb (Python/Pytest worker)  [running]
     Use /exec <target> <cmd> to target a specific sandbox.
     ```

### 3.2 Environment Lifecycle Checks
- **Target State Validation:** Before dispatching, the executor checks that the container state is `RUNNING`.
- **Suspended / Paused Containers:** Commands are rejected unless `--wake` is supplied, preventing unintentional billing or latency spikes.
- **Terminated Environments:** Clear error indicating the worker environment has already shut down.

---

## 4. Output Streaming & Presentation Architecture

### 4.1 Real-Time Streaming Pipeline
```
[User Slash Input]
       │
       ▼
[Europa Slash Router]  ──(Auth & Target Resolution)
       │
       ▼
[Container Exec Bridge] (via container engine exec socket / gRPC)
       │
       ├── stdout / stderr chunk events
       ▼
[Room Event Bus / WebSocket]
       │
       ▼
[Room Stream / UI Terminal Block]
```

- **Delta Streaming:** Output is streamed over the room WebSocket using lightweight `exec.chunk` events containing `{exec_id, stream: "stdout"|"stderr", seq, delta}`.
- **Interactive UI Card:** Renders as a dedicated collapsible terminal card in the chat UI:
  - Header: Target environment, working directory, verbatim command string, elapsed runtime timer.
  - Body: Scrollable, dark-mode ANSI terminal block with line numbering.
  - Footer: Exit status code (e.g. `Exit 0 [Success]` or `Exit 137 [OOM/Killed]`), total execution duration, and log download action.

### 4.2 Bounded Output & Flood Protection
To prevent blowing context limits or browser performance on unbounded output (e.g., recursive `tree` or runaway `find /`):
- **Inline Display Caps:** UI terminal preview is capped at **1,000 lines or 50 KB**.
- **Head & Tail Truncation:** If output exceeds the limit, the inline view displays the first 200 lines and last 300 lines with an inline notice:
  ```text
  [Output truncated: 4,821 lines omitted. Download complete output: /artifacts/exec-8f2a-71d.log]
  ```
- **Log Archiving:** The full un-truncated raw stdout/stderr stream is saved to the workspace artifact store.
- **Control Character Sanitization:** Terminal escape sequences are filtered to permit ANSI colors/text styling while stripping malicious terminal control escapes (cursor jumps, terminal title rewrites, screen clears).

### 4.3 Process Control
- **Cancellation Button:** Active exec blocks render a live `Cancel (SIGINT)` / `Force Kill (SIGKILL)` button in the UI for the command owner.
- **Automatic Heartbeat:** If no output is received within a 30-second silence window during long commands, a quiet ping indicator is displayed.

---

## 5. Security Boundaries & Guardrails

### 5.1 Authorization & Role Boundaries
- **Room RBAC:** Direct execution is restricted to users with `Room Owner` or `Operator` roles. Clankers and guest observers cannot execute `/exec`.
- **Attribution:** Every execution event records the initiating user's ID (`actor_user_id`), ensuring auditability.

### 5.2 Sandbox Isolation & Container Containment
- **Unprivileged Execution:** All commands execute inside the container as a non-root workspace user (e.g., `user` / `uid 1000`), never host root.
- **Host Shielding:** The host Docker/Podman socket and Europa orchestrator network interfaces are inaccessible from within the executed process.
- **Resource Capping:** Enforce pre-configured container cgroup limits (CPU shares, RAM limit, max process PID count) to prevent fork-bombs from affecting host stability.

### 5.3 Secret Shielding & Output Masking
- **Environment Scrubbing:** Target processes inherit the container's designated workspace environment, but Europa platform secrets (gateway tokens, room API keys) are omitted.
- **Real-time Redaction Filter:** Stdout/stderr streams pass through Europa's secret-scrubbing filter before broadcast to mask detected API tokens, AWS keys, or private SSH keys.

### 5.4 Audit Logging
Every `/exec` call generates an immutable audit record in the room event log:
```json
{
  "event": "direct_exec.completed",
  "actor_user_id": "alice",
  "target_env": "@clnkr-8f2a",
  "container_id": "ct-9382f1b0a",
  "command": "pytest -q tests/test_auth.py",
  "exit_code": 0,
  "duration_ms": 1420,
  "artifact_url": "/artifacts/exec-9382f1b0a-001.log"
}
```

---

## 6. Implementation Phases

1. **Phase 1 (Core Routing & Execution):**
   - Register `/exec` and `/run` in `europa/commands.py`.
   - Wire target resolution to running worker containers.
   - Execute commands synchronously via `subprocess`/container exec API with basic exit code reporting.
2. **Phase 2 (Streaming & Terminal Card UI):**
   - Implement WebSocket `exec.chunk` streaming events.
   - Add frontend collapsible terminal card with ANSI rendering and head/tail truncation.
3. **Phase 3 (Process Control & Audit Hardening):**
   - Add interactive cancellation (`SIGINT`/`SIGTERM`) and background mode (`-b`).
   - Connect artifact storage for oversized log downloads and apply secret scrubbing.
Truncated in your view
alice 16:15:10 depth 7 Next post lands here
Looks good. In addition and to clarify, this should be a real terminal emulator session, owned by the human user who called for it, running via ssh. Other's should be able to see that human's activity in real-time. By default, everyone else sees a small terminal box appear and never grow, with real activity in it, but the participant sees a blown up box. Others can opt into that, too. Implement the UI for this plan.
Looks good. In addition and to clarify, this should be a real terminal emulator session, owned by the human user who called for it, running via ssh. Other's should be able to see that human's activity in real-time. By default, everyone else sees a small terminal box appear and never grow, with real activity in it, but the participant sees a blown up box. Others can opt into that, too. Implement the UI for this plan.
Truncated in your view
@clnkr-sdxv clanker 16:18:13 error depth 8 Next post lands here
@clnkr-sdxv errored: Hermes turn timed out
@clnkr-sdxv errored: Hermes turn timed out
Truncated in your view
Composer Options
Raw · Unrendered Post (/ commands active)
Enter to send · Tab to complete · Shift+Enter newline · @mention · /command