Files
deepseek-harness/packages/session/working-directory
LegGasai 58ee5a6edf fix(working-directory): move within into dsh-util-workspace-path
forge's Host code imported within from dsh-working-directory, a runtime
value edge the dependency policy refuses for a client-host package. The
helper is a stateless lexical containment test, so it now lives in the
browser-safe workspace-path utility, which joins duplicateSafePackages;
the directory service, the subagent manager, and forge import it from
there and carry the utility as an ordinary dependency.

Review: https://github.com/deepseek-harness/deepseek-harness/pull/7817#discussion_r4454836492
2026-11-04 11:33:17 +08:00
..

description, kind
description kind
Change one Session’s working directory while existing processes retain theirs. The selected directory survives replay and appears in user context. A missing directory restores the original project when it remains available. package-reference

@deepseek-ai/dsh-working-directory

English | 中文

Summary

Change one Session’s working directory while existing processes retain theirs. The selected directory survives replay and appears in user context. A missing directory restores the original project when it remains available.

Table of Contents


Use this package

Mount alongside fs, sessionProjections, and systemPrompt. defaultDirectory selects an absolute fallback for Sessions without an original directory; omission uses the launch directory. See the configuration catalog.

- name: '@deepseek-ai/dsh-working-directory'

Understand the implementation

Implementation internals — click to expand

The Session projection owns the effective directory and exposes it in Session observations, so cold readers can use it without activating an Agent; the header continues to identify the original project. A second projection folds the workspace anchors and the root they select from the same event, and relocate validates the root and the directory inside it before committing one event that carries anchor. Changes serialize per Session, validate through the filesystem provider, check cancellation and Agent lifetime, commit an event, and queue a user-context notice. If notice queuing fails after commit, the operation returns the committed directory and logs a warning; the next request or resume still receives the required directory context. Prompt assembly validates the current directory before publishing its required context contribution. Existing processes and sandbox grants keep their independent ownership. The service implementation defines the API.

No runtime invariant companion is published because the service reads its only directory state from the Session projection and checks filesystem validity at use.


Further Exploration


Model Experience

Working directory context

What the model sees

The current value is Current working directory: <JSON-quoted absolute path>., followed by Workspace root: <JSON-quoted absolute path>. on a second line while the two differ. Each committed change, including automatic recovery, attempts to queue a user-context notice through the ordinary Agent inbox; a change that selects another root ends its notice with <JSON-quoted root> is now the workspace root. Cancellation or disposal may discard unadmitted notices; the durable directory remains available to the next request. Directory context stays outside the system prompt and remains enabled when optional runtime context is disabled.

Token effect

The initial snapshot and changed values add user-context tokens; unchanged snapshots are not repeated.

KV Cache effect

Directory transitions append context without replacing the stable system-prompt prefix. A changed directory or recovery creates new context after retained history.

Known Limitations and Deferred Work

  • Missing original project — when the current directory and the original project are both unavailable, prompt assembly rejects every model turn, including chat-only turns. The service does not choose or recreate a repository. Restore the original directory, or use SDK setWorkingDirectory (set_working_directory in Python) or ctx.workingDirectory.set to select an existing absolute directory before retrying. Existing shells retain their process-local directories.
  • Anchors compare as recorded — the original project is the header's recorded path, while set and relocate record canonical paths from the filesystem provider. A header recorded through a symlink or with different casing never contains those paths, so the root stays on the original project as it does for a directory outside every anchor.
  • Root without consumers — workspaceRoot has no consumer yet: the sandbox write boundary, the workspace file service, the change recorder, sidebar terminals, @ file candidates, the skill catalog, project instructions, and the LSP workspace still read the header or the current directory. Connecting them is the deferred work the workspace-root note lists; rootOf alone changes none of their behavior.

Dev Note

Working context for maintainers — click to expand

None.