dsh-loop-engine 1.0.0-rc10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +121 -0
  2. package/README.zh.md +38 -0
  3. package/cordis.patch.yml +3 -0
  4. package/lib/client.js +37506 -0
  5. package/lib/index.js +6412 -0
  6. package/lib/invariant.js +108 -0
  7. package/lib/types/client/LoopEngineBadge.d.ts +34 -0
  8. package/lib/types/client/LoopEngineComposerSelect.d.ts +40 -0
  9. package/lib/types/client/LoopEngineSection.d.ts +34 -0
  10. package/lib/types/client/index.d.ts +29 -0
  11. package/lib/types/client/locales.d.ts +46 -0
  12. package/lib/types/client/store.d.ts +58 -0
  13. package/lib/types/commands.d.ts +69 -0
  14. package/lib/types/driver-core/context-files.d.ts +62 -0
  15. package/lib/types/driver-core/ownership.d.ts +40 -0
  16. package/lib/types/driver-core/permission-knobs.d.ts +26 -0
  17. package/lib/types/driver-core/prompt.d.ts +23 -0
  18. package/lib/types/driver-core/skill-inject.d.ts +59 -0
  19. package/lib/types/engine-claude/agent.d.ts +104 -0
  20. package/lib/types/engine-claude/loop.d.ts +111 -0
  21. package/lib/types/engine-claude/mapping.d.ts +83 -0
  22. package/lib/types/engine-claude/permission.d.ts +41 -0
  23. package/lib/types/engine-claude/process.d.ts +59 -0
  24. package/lib/types/engine-claude/sdk.d.ts +57 -0
  25. package/lib/types/engine-claude/types.d.ts +18 -0
  26. package/lib/types/engine-codex/agent.d.ts +111 -0
  27. package/lib/types/engine-codex/appserver/client.d.ts +49 -0
  28. package/lib/types/engine-codex/appserver/mapping.d.ts +67 -0
  29. package/lib/types/engine-codex/appserver/thread.d.ts +66 -0
  30. package/lib/types/engine-codex/appserver/types.d.ts +215 -0
  31. package/lib/types/engine-codex/loop.d.ts +114 -0
  32. package/lib/types/engine-codex/permission.d.ts +32 -0
  33. package/lib/types/engine-codex/skills.d.ts +29 -0
  34. package/lib/types/engine-codex/types.d.ts +19 -0
  35. package/lib/types/engine-kimi/acp/client.d.ts +76 -0
  36. package/lib/types/engine-kimi/acp/mapping.d.ts +44 -0
  37. package/lib/types/engine-kimi/acp/types.d.ts +95 -0
  38. package/lib/types/engine-kimi/agent.d.ts +123 -0
  39. package/lib/types/engine-kimi/commands.d.ts +40 -0
  40. package/lib/types/engine-kimi/loop.d.ts +108 -0
  41. package/lib/types/engine-kimi/mapping.d.ts +71 -0
  42. package/lib/types/engine-kimi/permission.d.ts +28 -0
  43. package/lib/types/engine-kimi/process.d.ts +61 -0
  44. package/lib/types/engine-kimi/skills.d.ts +57 -0
  45. package/lib/types/engine-kimi/types.d.ts +23 -0
  46. package/lib/types/engine-pi/agent.d.ts +135 -0
  47. package/lib/types/engine-pi/loop.d.ts +123 -0
  48. package/lib/types/engine-pi/permission.d.ts +43 -0
  49. package/lib/types/engine-pi/probe.d.ts +23 -0
  50. package/lib/types/engine-pi/rpc/client.d.ts +105 -0
  51. package/lib/types/engine-pi/rpc/mapping.d.ts +37 -0
  52. package/lib/types/engine-pi/rpc/types.d.ts +235 -0
  53. package/lib/types/engine-pi/skills.d.ts +55 -0
  54. package/lib/types/engine-pi/types.d.ts +27 -0
  55. package/lib/types/index.d.ts +114 -0
  56. package/lib/types/invariant.d.ts +23 -0
  57. package/lib/types/namespace.d.ts +9 -0
  58. package/lib/types/patch-manager.d.ts +59 -0
  59. package/lib/types/preset.d.ts +73 -0
  60. package/lib/types/provider-route.d.ts +49 -0
  61. package/lib/types/settings.d.ts +31 -0
  62. package/lib/types/skills.d.ts +93 -0
  63. package/package.json +103 -0
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # dsh-loop-engine
2
+
3
+ [![npm version](https://img.shields.io/npm/v/dsh-loop-engine?color=cb3837)](https://www.npmjs.com/package/dsh-loop-engine)
4
+
5
+ Switch the agent loop engine of **dsh web** the same way you switch a model: a
6
+ "Loop engine" dropdown in Settings chooses which driver runs your agents — the
7
+ built-in in-process loop, the Claude Code CLI, the Codex CLI, the Pi CLI, or the
8
+ Kimi Code CLI — without changing anything in the main repository.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ dsh plugin --profile web add dsh-loop-engine
14
+ ```
15
+
16
+ Restart `dsh web`, then open **Settings → Loop engine**.
17
+
18
+ > Switching engines rewrites a small managed block in `cordis.patch.yml`.
19
+ > Everything else you wrote in that file is preserved; only the plugin's own
20
+ > span changes.
21
+
22
+ > **pnpm users:** pnpm 10+ blocks dependency build scripts by default, so the
23
+ > install may report `@google/genai`, `node-pty`, and `protobufjs` as blocked.
24
+ > This is expected — click **"Allow build scripts and retry"** (or run
25
+ > `pnpm approve-builds`, or list them under `pnpm.onlyBuiltDependencies` in
26
+ > your project root) and retry. Only the installing project can grant this;
27
+ > the plugin cannot pre-approve its own dependencies.
28
+
29
+ ## Version compatibility
30
+
31
+ dsh-loop-engine is versioned **independently** of the harness (`1.0.0-rcN`) but
32
+ is bound to a specific harness release via `peerDependencies`. The two must be
33
+ matched — a mismatch fails loudly at boot or session resume:
34
+
35
+ | dsh-loop-engine | Requires harness |
36
+ |---|---|
37
+ | 1.0.0-rc10 | **0.1.2-rc.1** |
38
+ | 1.0.0-rc9 | **0.1.2-rc.1** |
39
+ | 1.0.0-rc8 | **0.1.2-rc.1** |
40
+ | 1.0.0-rc7 | 0.1.1-rc.2 |
41
+
42
+ - **1.0.0-rc10 (and 1.0.0-rc9 / rc8) is not compatible with harness 0.1.1-rc.2 or earlier.** It uses
43
+ the 0.1.2 persistence seam (`SessionPersistence.create` / `open` +
44
+ `SessionHandle`), the `installSection` settings API, `ToolCallId`, and
45
+ `Session.snapshotEvents()` — none of which exist in older harnesses.
46
+ - To use the plugin with an older harness, install the loop-engine release that
47
+ matches it (e.g. `npm i dsh-loop-engine@1.0.0-rc7` for harness 0.1.1-rc.2).
48
+ - The GitHub Release body of each tag states the harness version it targets.
49
+
50
+ ### Requirements
51
+
52
+ - For the Claude Code engine: the Claude Code CLI installed and logged in on
53
+ the host.
54
+ - For the Codex engine: authenticated either via `codex login` on the host or a
55
+ `CODEX_API_KEY` environment entry.
56
+ - For the Pi engine: authenticated the way `pi` expects (its own
57
+ `~/.pi/agent/auth.json` or the provider's API-key environment variable such as
58
+ `ANTHROPIC_API_KEY`).
59
+ - For the Kimi Code engine: the `kimi` CLI installed and logged in on the host
60
+ (e.g. `kimi login`), and reachable on `PATH` (or pinned to an absolute path
61
+ via `kimiBin` in the composition entry).
62
+
63
+ ## Usage
64
+
65
+ 1. Pick an engine in **Settings → Loop engine** — `in-process` (default),
66
+ `claude-code`, `codex`, `pi`, or `kimi` — then restart `dsh web`.
67
+ 2. To return to the default, pick **In-process** and restart again.
68
+ 3. To remove the plugin: `dsh plugin --profile web remove dsh-loop-engine`, then
69
+ restart `dsh web`.
70
+
71
+ ### What a hosted engine takes over
72
+
73
+ While a hosted engine is selected, it owns the session's command and skill
74
+ surface: the plugin disables dsh's own `/goal` and points new sessions at a
75
+ managed `loop-engine` agent preset — a copy of `standard` minus the dsh-native
76
+ `/compact`, `/plan`, goal-tool, and skill rows that an external engine cannot
77
+ honor — so the slash menu shows the engine's bridged commands and its own
78
+ skill catalog. Engine-agnostic dsh commands (`/export`, `/feedback`,
79
+ `/permission`) keep working and stay. Switching back to `in-process` restores
80
+ the previous preset default; already-running sessions always keep the preset
81
+ they were created with.
82
+
83
+ ### Engine notes
84
+
85
+ - The Claude Code driver runs one SDK query per step; its slash commands are
86
+ bridged into the web menu (built-ins plus user-level `~/.claude/commands/`)
87
+ and forwarded to the engine, which expands them natively. Project-level
88
+ `.claude/commands/` files stay engine-side and also work typed directly.
89
+ - The Codex driver runs `codex app-server` and has no interactive tool
90
+ approval — permissions come from the session's `sandboxMode` +
91
+ `approvalPolicy`. Its `AGENTS.md` instruction files are surfaced through the
92
+ dsh skill-injection seam across every directory from the session cwd up to
93
+ the git root, plus `~/.codex/AGENTS.md`.
94
+ - The Pi driver runs `pi --mode rpc`; Pi has no permission system, so the whole
95
+ child is sandboxed through the dsh subprocess service (default `read-only`).
96
+ Its context files (`AGENTS.md`/`CLAUDE.md` with `AGENTS.override.md`
97
+ preferred, plus the user-level file under the pi config dir) and its
98
+ `skills/` catalogs (`~/.pi/agent/skills/` and `.pi/skills/`) are surfaced
99
+ through the dsh skill-injection seam.
100
+ - The Kimi Code driver runs a persistent `kimi acp` child (Agent Client
101
+ Protocol over stdio) and speaks one stateless `session/new` + `session/prompt`
102
+ per dsh step; the durable dsh session log is the sole model context. It streams
103
+ assistant text (`agent_message_chunk`) and thinking (`agent_thought_chunk`)
104
+ incrementally into the log, and maps tool calls/streams (`tool_call` /
105
+ `tool_call_update`) into `tool/call` + `tool/result`. ACP surfaces tool
106
+ approvals as `session/request_permission`, which the driver answers from the
107
+ session's dsh approval knobs (an `ask` policy denies, fail-closed). The child
108
+ is spawned through the dsh subprocess seam — the only privilege boundary
109
+ (default read-only sandbox). Its project `AGENTS.md` chain (cwd→git root) and
110
+ `.kimi-code/skills/` catalogs (user and project) are surfaced through the dsh
111
+ skill-injection seam, and its slash commands are bridged (built-ins forward the
112
+ raw `/name` line back to the engine, which expands it). The prompt is an ACP
113
+ request body — not an argv positional — so there is no command-line length
114
+ ceiling. Note Kimi's remaining slash-command surface is TUI-only
115
+ (`/login`, `/provider`, `/settings`, `/sessions`, …); those are not bridged
116
+ because the ACP prompt surface does not expand them, but `skill:` commands are
117
+ carried by the skill seam and Kimi's own shorthand.
118
+
119
+ ## License
120
+
121
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,38 @@
1
+ # dsh-loop-engine
2
+
3
+ [![npm version](https://img.shields.io/npm/v/dsh-loop-engine?color=cb3837)](https://www.npmjs.com/package/dsh-loop-engine)
4
+
5
+ 像切换模型一样切换 **dsh web** 的 agent 循环引擎:设置页的「Loop engine」下拉选择运行 agent 的驱动——内置 in-process 循环、Claude Code CLI、Codex CLI、Pi CLI,或 Kimi Code CLI——**无需改动主仓库**。
6
+
7
+ ## 安装
8
+
9
+ ```sh
10
+ dsh plugin --profile web add dsh-loop-engine
11
+ ```
12
+
13
+ 重启 `dsh web`,然后打开 **Settings → Loop engine**。
14
+
15
+ > 切换引擎会重写 `cordis.patch.yml` 中一小段受管理的内容,文件里你写的其它部分都会保留,只改动插件自己的区间。
16
+
17
+ ### 环境要求
18
+
19
+ - 使用 Claude Code 引擎时需要本机已安装并登录 Claude Code CLI。
20
+ - 使用 Codex 引擎时需要完成认证:本机执行过 `codex login`,或配置 `CODEX_API_KEY` 环境变量。
21
+ - 使用 Pi 引擎时需要以 `pi` 要求的方式完成认证(其自身的 `~/.pi/agent/auth.json`,或提供方的 API-key 环境变量,如 `ANTHROPIC_API_KEY`)。
22
+ - 使用 Kimi Code 引擎时需要本机已安装并登录 `kimi` CLI(例如 `kimi login`),且在 `PATH` 上(或在组合条目里用 `kimiBin` 固定为绝对路径)。
23
+
24
+ ## 使用方法
25
+
26
+ 1. 在 **Settings → Loop engine** 选择引擎——`in-process`(默认)、`claude-code`、`codex`、`pi` 或 `kimi`——然后重启 `dsh web`。
27
+ 2. 要切回默认,选 **In-process** 再重启即可。
28
+ 3. 卸载插件:`dsh plugin --profile web remove dsh-loop-engine`,然后重启 `dsh web`。
29
+
30
+ ### 引擎说明
31
+
32
+ - Codex 驱动运行 `codex app-server`,没有交互式工具审批——权限来自会话的 `sandboxMode` + `approvalPolicy`。
33
+ - Pi 驱动运行 `pi --mode rpc`;Pi 没有权限系统,所以整个子进程经 dsh subprocess 服务做沙箱化(默认 `read-only`)。
34
+ - Kimi Code 驱动运行一个常驻的 `kimi acp` 子进程(Agent Client Protocol over stdio),每步一次无状态的 `session/new` + `session/prompt`;durable 会话日志是唯一模型上下文。它把助手文本(`agent_message_chunk`)与**思考**(`agent_thought_chunk`)**增量**写入日志,并把工具调用/流(`tool_call` / `tool_call_update`)映射为 `tool/call` + `tool/result`。ACP 通过 `session/request_permission` 暴露工具审批,驱动根据会话的 dsh 审批旋钮应答(ask 策略拒绝,失败关闭)。子进程经 dsh subprocess seam 拉起——唯一权限边界(默认只读沙箱)。其项目 `AGENTS.md` 链(cwd→git 根)与 `.kimi-code/skills/` 目录(用户与项目)通过 dsh 技能注入接口暴露,其斜杠命令也已桥接(内置命令把原始 `/name` 行转发回引擎展开)。prompt 是 ACP 请求体而非 argv 位置参数,因此**不存在命令行长度上限**。注意 Kimi 剩余的斜杠命令面是纯 TUI(`/login`、`/provider`、`/settings`、`/sessions`…),这些不桥接(ACP prompt 面不扩展它们);`skill:` 命令由技能接口与 kimi 自身的 shorthand 承载。
35
+
36
+ ## License
37
+
38
+ MIT
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: loop-engine
3
+ name: 'dsh-loop-engine'