# Development, verification, and limitations

[中文](development.md) · [Back to README](../README.en.md)

## Architecture

- Host: `src/index.ts` connects `tools/pre-execute` and `approval/request` and mounts `AutoReviewLiveRemote`; `orchestrator.ts` owns Guardian, native manual approval, audit, and lifecycle; `LiveReviewHub` owns bounded watcher queues and one latest snapshot per retained Session, while the Remote can recover a persisted final state from the current audit JSONL; `audit.ts` writes final JSONL.
- Client: the settings card registers in `settings.plugin.item`; plugin `apply()` captures the generated Typert Remote and timer callbacks, then supplies them to `LiveAutoReviewCard` through the `conversation.input.dock` inject face for polling roughly every 250 ms. The React component never retains Cordis `ctx`, so a session-switch remount cannot escape the plugin injection context; `apply()` installs the styles shared by the Card and settings independently from the currently disabled legacy presentation registrations; the Card above the composer uses the same dock-column width, border level, and tip background as the built-in task card.
- Host and Client exchange minimal JSON through the Remote only. `src/client/review.ts`, Chat/Tool View/Trajectory registration, and Host Session appends remain compiled and tested, but production entry points comment them out under `TODO(dsh-session-events)`.

## TypeScript-only workflow

Requires Node `^22.19.0 || >=24`:

```bash
pnpm install
pnpm typecheck
pnpm lint
pnpm test
pnpm coverage
pnpm publint
pnpm check:no-js
npm pack --dry-run
```

`pnpm verify` runs the release gates. Git tracks no `.js/.mjs/.cjs`; runtime artifacts are generated only under ignored, publishable `lib/`.

The Client bundle uses DSH ModuleLoader with React external. The Typert generator produces the `./typert` and `./remote` artifacts before Client typecheck/bundling, and `zod` is bundled into the Client. The Cordis patch must use manifest package identity `dsh-auto-review-plugin` so the Host loader discovers the contract.

## pnpm dependency build-script approval

pnpm 11 blocks dependencies that have not been explicitly approved from running installation lifecycle scripts such as `preinstall`, `install`, and `postinstall`. The following output does not mean that the lockfile or package contents are corrupted:

```text
[ERR_PNPM_IGNORED_BUILDS] Ignored build scripts:
@deepseek-ai/dsh-subprocess-local, koffi
```

`koffi` is a native FFI dependency that normally selects or builds binaries for the current platform; DSH's local subprocess path introduces it transitively. TypeScript builds may still pass while these scripts are blocked, but runtime paths that require local subprocesses, terminals, or native FFI can fail.

After reviewing package names, versions, and provenance, approve only the required dependencies:

```bash
pnpm approve-builds @deepseek-ai/dsh-subprocess-local koffi
pnpm rebuild @deepseek-ai/dsh-subprocess-local koffi
```

You can also run interactive `pnpm approve-builds` and select entries one by one. Do not use `pnpm approve-builds --all` unless every pending dependency has been reviewed.

A line such as `Packages: +N -M` only reports pnpm reconciling `node_modules` with the current `package.json` and lockfile: packages needed by the current graph are added and stale packages are removed. This is independent from build-script approval.

## CI and npm publishing

- `.github/workflows/ci.yml` runs `pnpm verify` and coverage for Pull Requests targeting `main`/`master` and for new pushes to either branch.
- `.github/workflows/publish.yml` responds to strict stable semantic-version tags in the form `vX.Y.Z`. The tag must match `package.json`; after verification it publishes `dsh-auto-review-plugin` with repository Secret `TOKEN` and npm dist-tag `latest`.

## Test focus

- Shell/network/MCP/extension classification and one-use `session + callId + live signal` correlation;
- Guardian output, risk policy, cancellation, and disposal;
- native approval waterfall allow/reject/cancel/unavailable outcomes;
- audit-before-allow and JSONL repair/rotation/serialization;
- live watcher latest-snapshot replay, Session/permission isolation, bounded queues and snapshots, TTL, audit recovery, and `start → status → end`;
- no custom Session appends, live payload allowlists, and Guardian-reason redaction;
- default-collapsed settings, save/reset/rollback, and hidden Trajectory control;
- retained legacy Chat aggregation and Trajectory RunningToolCall → ToolResultNode.

## Local installation verification

```bash
pnpm build
dsh plugin --profile <isolated-profile> add "$PWD"
dsh --profile <isolated-profile> --dump-config
```

Web changes require rebuilding the Client artifact used by the existing GUI and refreshing the real DSH Web page. Do not substitute a standalone Vite page for `dsh web`; the shell depends on `window.__DSH_BOOT__`.

## Known limitations

- The plugin cannot intercept native network connections outside ToolRuntime or manufacture trusted network/MCP provenance that DSH does not expose.
- Shell classification is deliberately conservative; complex safe commands may still be reviewed.
- Guardian cannot call read-only tools for follow-up investigation and decides from bounded Host evidence only.
- The JSONL writer has no cross-process file lock.
- The latest card is not stored in Session history. Host restart recovery depends on a final record under the current audit path; auditing disabled, audit failure, or an audit-path change cannot recover from an older path.
- No third-party Session UI events are currently written; incompatible events already present in old Sessions are not repaired automatically.
- The settings card requires the Host Settings namespace and Plugins Settings Slot; the live card also requires Remote, timer, and `conversation.input.dock`.
- Current DSH hardcodes built-in permission preset SVGs by name, and `PresetSpec` has no icon field. A plugin-only release cannot register a matching `auto-review` icon; this requires an upstream icon extension point.
