Skip to content

feat(platform): thread-level sandbox workdir for external-agent chats - #2541

Merged
yannickmonney merged 1 commit into
mainfrom
feat/chat-sandbox-workdir
Jul 7, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
feat/chat-sandbox-workdir

Conversation

@larryro

@larryro larryro commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a per-thread working directory for sandbox external-agent chats: threadMetadata.sandboxWorkdir (relative to /user/workspace), set from a new composer chip next to the Plan/Act toggle. Every turn's CLI process starts in that directory, so a repo cloned into a workspace subdir exposes its own CLAUDE.md / .claude/skills to the agent. Unset threads behave exactly as today; cloning a single repo into the workspace root continues to need no setting at all.

How it works

  • Validation is the workspace confinement (lib/shared/sandbox-workdir.ts + tests): runnerd accepts any existing dir under /user, and resolves relative cwds against /user — so the platform normalizes, rejects ./../empty segments, and always sends an absolute path under /user/workspace.
  • Turn injection (run_external_agent.ts): read thread meta → validate → probe existence via sessionListFiles → pass workdir into the pre-existing runAgentInSessionImpl arg. Fail-open: a missing/invalid dir degrades to the workspace root (bootstrap flow: save tale, ask the agent to clone, next turn picks it up). When set, /user/workspace rides along as an additional readable dir.
  • Repo-skill precedence follows the workdir: repoSkillScanDirs(workdirRel) + workspaceIsTaleRepo(sessionId, workdirRel) scan the agent's actual cwd — otherwise the platform would re-stage a skill the repo already provides and hand the agent two conflicting copies. All four repoOwnedSkillNames call sites (integration / builtin / bound-org / workflow staging) pass it through.
  • Chip = ambient indicator: shows the active dir (mono, highlighted when set); popover input with inline validation errors; a save-time probe toasts when the folder doesn't exist yet, so the root-fallback is never silent. External-agent threads only (same gating as the Plan/Act toggle). Locales: en/de/fr (de-CH inherits de).

Deliberate scope choices: fork/branch threads do not carry the setting (matches externalAgentMode); workflow/task exec paths are untouched; per-user/per-project defaults and an agent-settable tool are possible later layers.

Definition of done

  • Green gate — oxfmt (changed files), oxlint --type-aware, tsc --noEmit, vitest server+pii: 74 906 passed; 5 failing files are the known convexTest timeout flake (SCIM/Slack/conversations-RLS/workflow-executions/auto-route-cache — none touched here; all 29 tests pass when run in isolation). Root format:check couldn't complete in this environment (pypi/ruff fetch timeout — environmental).
  • Security gate — pre-commit opengrep on the staged files: 0 findings. (lint:sast full-repo has one pre-existing finding in services/sandbox-runtime/tale-gemini-run, untouched by this PR.)
  • Tests — validator/normalizer/resolver unit tests (19, incl. the .. workspace-escape case) + repoSkillScanDirs root/workdir cases; i18n parity (47) and @tale/ui i18n checks (54) green.
  • Migration — N/A: additive optional field; migrations:check passes (data-safe).
  • Locales — en/de/fr added; de-CH intentionally empty (inherits de; no ß/quote divergences in these strings).
  • Docs — manual test plan tests/manual/chat.md F35; docs/ site N/A (composer chips incl. Plan/Act are not documented there today).
  • Accessibility — real button with an accessible name, keyboard-reachable popover form, role="alert" on the inline error, semantic tokens only (both themes).
  • Sweep — all repoOwnedSkillNames call sites + workspaceIsTaleRepo; adapters need no change (every adapter already consumes spec.workdir; gemini gets the extra dir via --include-directories).
  • Observed — backend behaviour is test-covered, but the live chip has not been driven in a browser yet: the dev stack ports were held by the main checkout during development. Manual script ready as chat.md F35; will verify on the next available stack.
  • Commits — single atomic conventional commit, branched off main.

Where to look first

run_external_agent.ts 2b-pre block (fail-open resolution semantics) and the precedence-scan changes in integration_skills.ts / workflow_skills.ts.

Let each external-agent chat thread set a working directory relative to
/user/workspace (threadMetadata.sandboxWorkdir, composer chip next to the
Plan/Act toggle). Every turn's CLI now starts there, so a repo cloned into
a workspace subdir exposes its own CLAUDE.md and project skills; cloning
into the workspace root keeps working with no setting at all.

- lib/shared/sandbox-workdir: normalize + validate (reject `.`/`..`/empty
  segments — the platform is the only workspace confinement; runnerd
  accepts any existing dir under /user) and resolve to an absolute path
  (runnerd resolves relative cwds against /user, not the workspace root).
- run_external_agent: fail-open resolve + existence probe per turn;
  missing or invalid dirs fall back to the workspace root. When set, the
  workspace root rides along as an additional readable dir.
- Repo-skill precedence (repoSkillScanDirs) and workspaceIsTaleRepo follow
  the workdir so the platform never re-stages a skill the repo already
  provides.
- Composer chip doubles as the ambient indicator; a save-time probe warns
  when the folder does not exist yet. Locales: en/de/fr (de-CH inherits
  de). Manual test plan: chat.md F35.

Fork/branch threads do not carry the setting (matches externalAgentMode).
No migration: additive optional field (schema snapshot check passes).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants