Merge remote-tracking branch 'origin/master' into codex/project-instruction-files

# Conflicts:
#	AGENTS.md
#	docs/config-catalog.md
#	docs/cordis-catalog/events.md
#	docs/cordis-catalog/services.md
#	docs/core-data-structures/core.md
#	docs/event-producer-consumer.md
#	docs/persistence-catalog.md
#	docs/rfc/implemented/architecture/2026-07-05-reconstructable-requests.md
#	docs/rfc/implemented/feature/2026-06-15-code-mode.md
#	docs/rfc/implemented/feature/2026-06-30-hook-bridges.md
#	docs/rfc/implemented/feature/2026-06-30-interception-seams.md
#	docs/rfc/implemented/feature/2026-07-08-repeat-tool-guard.md
#	docs/rfc/proposed/simplification/2026-07-04-prune-dead-core-spine-surface.md
#	examples/AGENTS.md
#	examples/acp-agent/cordis.yml
#	examples/acp-agent/tests/acp.snapshot.ts
#	examples/echo-agent/cordis.yml
#	examples/sandbox-acp-agent/cordis.yml
#	packages/cordis/tool-cordis/src/api-catalog.ts
#	packages/core/agent-core/README.md
#	packages/core/agent-core/src/index.ts
#	packages/core/agent-loop/README.md
#	packages/core/agent-loop/src/loop.ts
#	packages/core/agent-loop/tests/interception.spec.ts
#	packages/core/agent/src/types.ts
#	packages/core/tools/README.md
#	packages/core/tools/src/code-mode.ts
#	packages/core/tools/src/index.ts
#	packages/fs/fs-local/src/index.ts
#	packages/fs/fs/README.md
#	packages/fs/fs/src/index.ts
#	packages/guard/repeat-tool-guard/README.md
#	packages/guard/repeat-tool-guard/src/index.ts
#	packages/hooks/hooks-claude/src/index.ts
#	packages/hooks/hooks-codex/src/index.ts
#	packages/ui/acp-agent/src/index.ts
This commit is contained in:
Yichen Jiang
2026-07-14 19:50:25 +08:00
720 changed files with 21199 additions and 14129 deletions
@@ -0,0 +1,151 @@
"""Locate the bundled DeepSeek Harness SDK runtime shipped with this package.
Two runtime carriers coexist under ``runtime/``, both injected by the repo's
``scripts/build-exe-for-python-sdk.ts`` build (neither is checked into git):
- **exe (production)**: single-file executables named
``dsh-jsonrpc-agent-pkg-<platform>-<arch>`` (platform in {linux, macos}, arch in
{x64, arm64}); the target machine needs no Node installation.
- **node (dev-only)**: the full deploy closure under ``runtime/node/``
(``package.json`` + ``node_modules/``), executed as ``node
runtime/node/node_modules/@deepseek-ai/dsh-jsonrpc-agent/lib/bin.js`` on a
system Node >= 22.19. It is the current checkout's source build, never
selected automatically, and excluded from wheel/sdist distributions.
``runtime/cordis.yml`` IS checked in: it is the default agent configuration
the client SDK injects via ``$DSH_CORDIS_CONFIG`` for zero-config runs — the
runtime itself always requires an explicit config and has no built-in
fallback.
"""
from __future__ import annotations
import os
import platform
import shutil
import sys
from pathlib import Path
PACKAGE_METADATA_FILENAME = "deepseek-harness-runtime.json"
RUNTIME_MODE_ENV_VAR = "DSH_RUNTIME_MODE"
_PLATFORM_TAGS = {"linux": "linux", "darwin": "macos"}
_ARCH_TAGS = {"x86_64": "x64", "amd64": "x64", "arm64": "arm64", "aarch64": "arm64"}
_EXE_ACQUISITION_HINT = (
"Two ways to get the executable: run `scripts/build-exe-for-python-sdk.ts` (via tsx) in a "
"deepseek-harness checkout, or install the matching `deepseek-harness-runtime-bin` platform "
"wheel retained by the `build-exe-for-python-sdk` CI workflow. For local development "
"against a repo source build, explicitly select the dev-only node carrier with "
f"{RUNTIME_MODE_ENV_VAR}=node (or resolve_bundled_launch_args('node'))."
)
def bundled_package_dir() -> Path:
"""Root directory of the installed runtime package data (the directory of this module)."""
root = Path(__file__).resolve().parent
metadata = root / PACKAGE_METADATA_FILENAME
if not metadata.is_file():
raise FileNotFoundError(f"deepseek-harness-runtime-bin is missing {metadata}")
return root
def bundled_default_config_path() -> Path:
"""Path of the checked-in default runtime configuration (``runtime/cordis.yml``).
The client SDK injects this path via ``$DSH_CORDIS_CONFIG`` when the caller
supplies no config and the launch resolves to the bundled runtime — the
runtime binary itself always demands an explicit config.
"""
path = bundled_package_dir() / "runtime" / "cordis.yml"
if not path.is_file():
raise FileNotFoundError(
f"deepseek-harness-runtime-bin is missing the default runtime config at {path}"
)
return path
def bundled_runtime_path() -> Path:
"""Absolute path of the bundled single-file runtime executable for the current platform.
Raises FileNotFoundError when the platform is unsupported or the executable
has not been placed into this package; the message names the acquisition
routes (acquisition strategy is deliberately separate from this lookup
interface, so an on-demand download can replace it without touching
callers).
"""
tag = _current_platform_tag()
path = bundled_package_dir() / "runtime" / f"dsh-jsonrpc-agent-pkg-{tag}"
if not path.is_file():
raise FileNotFoundError(
f"deepseek-harness-runtime-bin is missing the runtime executable at {path}. "
+ _EXE_ACQUISITION_HINT
)
return path
def resolve_bundled_launch_args(mode: str | None = None) -> tuple[str, ...]:
"""The argv tuple that launches the bundled runtime.
Mode selection: the explicit ``mode`` argument wins, then the
``DSH_RUNTIME_MODE`` environment variable (``exe`` | ``node``), then
automatic resolution. Automatic resolution finds the production exe ONLY —
the dev-only node carrier must be selected explicitly so a production
deployment can never silently ride on a source build. Returns
``(exe_path,)`` in exe mode and ``(node_path, bin_js_path)`` in node mode;
raises FileNotFoundError when the selected carrier is unavailable and
ValueError for an unknown mode value.
"""
selected = mode if mode is not None else os.environ.get(RUNTIME_MODE_ENV_VAR)
if selected is None or selected == "exe":
return (str(bundled_runtime_path()),)
if selected == "node":
return _node_launch_args()
raise ValueError(
f"unsupported DeepSeek Harness runtime mode {selected!r}: expected 'exe' or 'node' "
f"(explicit argument or ${RUNTIME_MODE_ENV_VAR})"
)
def _current_platform_tag() -> str:
plat = _PLATFORM_TAGS.get(sys.platform)
arch = _ARCH_TAGS.get(platform.machine().lower())
if plat is None or arch is None:
raise FileNotFoundError(
"no bundled dsh-jsonrpc-agent executable exists for this platform "
f"(sys.platform={sys.platform!r}, machine={platform.machine()!r}); supported: "
"linux/macos on x64/arm64. " + _EXE_ACQUISITION_HINT
)
return f"{plat}-{arch}"
def _node_launch_args() -> tuple[str, str]:
node_root = bundled_package_dir() / "runtime" / "node"
bin_js = (
node_root / "node_modules" / "@deepseek-ai" / "dsh-jsonrpc-agent" / "lib" / "bin.js"
)
if not bin_js.is_file():
raise FileNotFoundError(
f"the dev-only node runtime closure is missing at {node_root} "
f"(no {bin_js}); run `scripts/build-exe-for-python-sdk.ts` in a deepseek-harness "
"checkout, which builds and copies the deploy closure here. The node carrier "
"is for repo-local development only — production uses the single-file exe."
)
node = shutil.which("node")
if node is None:
raise FileNotFoundError(
"the node runtime mode needs a system `node` (>=22.19) on PATH; "
"install Node.js or use the exe mode"
)
return (node, str(bin_js))
__all__ = [
"PACKAGE_METADATA_FILENAME",
"RUNTIME_MODE_ENV_VAR",
"bundled_default_config_path",
"bundled_package_dir",
"bundled_runtime_path",
"resolve_bundled_launch_args",
]
@@ -0,0 +1 @@
{"name":"deepseek-harness-runtime-bin","version":"0.0.0-dev"}
@@ -0,0 +1,44 @@
# Bundled default config. The runtime still requires an explicit
# $DSH_CORDIS_CONFIG or argv path; the SDK injects this path for bundled
# zero-config launches. SDK-set session-root and cwd variables have manual-run fallbacks.
# Stdio JSON-RPC serving surface; without it the agent has no SDK client.
- id: jsonrpc
name: '@deepseek-ai/dsh-jsonrpc'
# Agent spine; the SDK server creates agents per sessionId.
- id: agent-core
name: '@deepseek-ai/dsh-agent-core'
config:
workspaceContext:
maxBytes: 65536
# Stock DeepSeek adapters. Loading requires an API key; initialize and shutdown
# may use a dummy key because they do not call the model.
- id: llm-deepseek
name: '@deepseek-ai/dsh-llm-deepseek'
config:
apiKey: !!js process.env.DEEPSEEK_API_KEY
baseURL: !!js process.env.DEEPSEEK_BASE_URL
models:
- deepseek-v4-flash
- deepseek-v4-pro
# JSONL persistence; $DSH_SESSION_ROOT wins over ./.sessions in the process cwd.
- id: sessions
name: '@deepseek-ai/dsh-session-persistence-jsonl'
config:
root: !!js process.env.DSH_SESSION_ROOT ?? './.sessions'
# Local bash executor; $DSH_CWD wins over the process cwd.
- id: bash
name: '@deepseek-ai/dsh-bash-local'
config:
cwd: !!js process.env.DSH_CWD ?? process.cwd()
# Local filesystem provider for workspace instruction loading. This does not
# expose model-facing file tools by itself.
- id: fs-local
name: '@deepseek-ai/dsh-fs-local'
config:
cwd: !!js process.env.DSH_CWD ?? process.cwd()