dsh-deep-ptc-mode 1.7.3 → 1.7.4
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.
- package/CHANGELOG.md +14 -0
- package/README.md +29 -5
- package/README.zh.md +29 -5
- package/lib/client.js +55 -7
- package/lib/creative.mjs +127 -0
- package/lib/environment.mjs +2 -1
- package/lib/executor.mjs +31 -6
- package/lib/index.mjs +62 -4
- package/lib/lab.mjs +13 -0
- package/lib/model.mjs +34 -7
- package/lib/resident.mjs +27 -0
- package/lib/shells.mjs +114 -0
- package/lib/tool-policy.mjs +5 -2
- package/lib/upstream.mjs +81 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.7.4 — 2026-11-07
|
|
4
|
+
|
|
5
|
+
- 支持当前桌面端 DSH RC `>=0.2.2-rc.1`。只声明支持 RC,不支持 alpha。
|
|
6
|
+
- PowerShell、Bash、Zsh 可以选择本机已发现的可执行文件。未选择或文件消失时仍走官方自动查找。WSL 仍只选择发行版。PowerShell 写入官方执行器的 `pwshPath`;Bash 和 Zsh 只替换启动参数,沙箱与批准仍用官方执行器。
|
|
7
|
+
- 新增插件实验台,默认关闭。打开后按读取 PTC 的同一方式,动态读取宿主正在发布的官方创造模式,只追加相对 PTC 多出来的行,模块名以该预设原文为准。实验在内存中检查、定义并经宿主批准后运行,不写仓库、已发布预设、桌面组合或本插件源码。预设读不到时继续使用官方 PTC 工具。
|
|
8
|
+
- 适配 dsh-go 的屏幕控制:这类工具留在初始 SDK,失败不隔离。识别依据是工具自己的常驻标记、`dsh-go/view`、屏幕控制工具名,或提供者标记,不把 dsh-go 写成依赖,也不占用它的槽位和设置表单。其他外部工具仍是能力优先、官方兜底,普通扩展按需加载。
|
|
9
|
+
- 工具状态按钮在界面投影失败时留空,输入区和屏幕控制界面保持原位。
|
|
10
|
+
|
|
11
|
+
- Declare support for the installed desktop DSH release candidate, `>=0.2.2-rc.1`. Alpha builds are not supported.
|
|
12
|
+
- PowerShell, Bash and Zsh can use a discovered executable. An empty or missing choice keeps the official lookup. WSL still selects a distribution only. PowerShell writes the official `pwshPath`; Bash and Zsh change argv only, and sandbox plus approval stay on the official executor.
|
|
13
|
+
- Add plugin lab, off by default. When on, load the official creative mode the same way PTC is loaded and append only the extra rows, using the module names in that document. Lab packages stay in memory: inspect, define, then run through host approval. They do not write the repository, shipped presets, the desktop composition, or this plugin. If that preset cannot be read, official PTC tools remain.
|
|
14
|
+
- Adapt dsh-go screen control: those tools stay in the initial SDK and are not quarantined. Recognition uses the tool's own resident flag, `dsh-go/view`, screen-control names, or the provider mark. dsh-go is not a dependency, and its slots and settings forms stay its own. Other external tools stay capability-first, with official tools as the fallback. Ordinary extensions stay on demand.
|
|
15
|
+
- The tool-state control renders nothing when the composer projection fails, leaving the input row and the screen-control chrome in place.
|
|
16
|
+
|
|
3
17
|
## 1.7.3 — 2026-11-05
|
|
4
18
|
|
|
5
19
|
- 优先读取运行宿主的官方预设注册表并自动检测更新;修复官方工具误隔离、暂停误判和桌面重载按钮的依赖/返回值处理。保留后台运行与插话。
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Deep PTC mode
|
|
2
2
|
|
|
3
|
-
[中文](README.zh.md) · MIT · **1.7.
|
|
3
|
+
[中文](README.zh.md) · MIT · **1.7.4**
|
|
4
4
|
|
|
5
5
|
[1.7.3 实测汇总 / Test summary](TEST_REPORT.md)
|
|
6
6
|
**Let plugins cooperate. Keep current official PTC tools as the fallback. Stay interruptible while work runs.**
|
|
@@ -22,7 +22,7 @@ Compatibility has two directions: follow the installed official PTC composition
|
|
|
22
22
|
|
|
23
23
|
An extension must publish into the `deep-ptc` scope and support the installed host. Keep official fallbacks visible in the provider's own configuration where supported. This is cooperative task-level selection, not a guarantee that every plugin or replacement executor is interchangeable. OPS is one possible provider, not a bundled dependency or a completed integration claim.
|
|
24
24
|
|
|
25
|
-
The official fallback retains the 1.6.1 derivation mechanism: the plugin reads the running host’s PTC declaration and checks for changes every five seconds; only changed declarations or this plugin’s settings rebuild the preset and follows its module names and configuration. The bundled snapshot is used only if loading, parsing or derivation fails, with a warning. Reload after an official upgrade and use a new preset revision; existing sessions are not forcibly switched. DSH support starts at `>=0.2.2-rc.1
|
|
25
|
+
The official fallback retains the 1.6.1 derivation mechanism: the plugin reads the running host’s PTC declaration and checks for changes every five seconds; only changed declarations or this plugin’s settings rebuild the preset and follows its module names and configuration. The bundled snapshot is used only if loading, parsing or derivation fails, with a warning. Reload after an official upgrade and use a new preset revision; existing sessions are not forcibly switched. DSH support starts at the installed desktop release candidate, `>=0.2.2-rc.1`. Only RC builds are supported; alpha builds are not. There is no upper bound on later release candidates, and a newer RC still needs a host-interface check.
|
|
26
26
|
|
|
27
27
|
## 1.7.2: lightweight, on-demand tool orchestration
|
|
28
28
|
|
|
@@ -105,6 +105,28 @@ WSL source uses Linux/POSIX syntax, while file tools and `workdir` use Windows h
|
|
|
105
105
|
|
|
106
106
|
Native PowerShell, Bash and Zsh use Harness sandbox, approval and process management. WSL currently supports only execution already authorized as `danger-full-access`. Confined Windows policies are refused before execution, without fallback or permission changes. The plugin does not authorize escalation.
|
|
107
107
|
|
|
108
|
+
PowerShell, Bash and Zsh can use a common executable discovered on this machine. Leaving it empty keeps the official lookup. WSL still selects a distribution only. A missing file logs a warning and falls back to automatic. PowerShell writes the official executor's `pwshPath`. Bash and Zsh change only the startup argv.
|
|
109
|
+
|
|
110
|
+
## Plugin lab: official creative mode, in memory
|
|
111
|
+
|
|
112
|
+
Deep PTC is often used for programming, and it can also be used to design a DSH plugin. **Plugin lab** (设置里的「插件实验台」) is off by default. Turn it on under **Settings → Plugins → Deep PTC**, then start a new session. `pluginLab: true` in the Cordis settings is the same switch.
|
|
113
|
+
|
|
114
|
+
When the lab is on, Deep PTC loads the official **creative mode** (创造模式) the same way it loads PTC: from the preset the running host publishes (`agentPresets.readDocument`, preferring the preset named 创造模式, otherwise the shipped id `cordis`). It appends only the rows that creative mode adds beyond the current PTC composition. Module names stay exactly as that document declares them, so an official rename follows the host instead of a name baked into this plugin. Skill directories that the creative preset expresses relative to its own file are resolved against that preset's directory. The desktop already mounts the host runner, so those rows are left to the host and are not copied a second time.
|
|
115
|
+
|
|
116
|
+
The lab is an environment for designing and trying a plugin in this process: inspect the live composition, define a syntax-checked package, then run it only through the host's existing approval. Packages stay in memory for this process. They do not write the repository, shipped presets, the desktop composition, or this plugin's source. Host approval stays as the host defined it. If the creative preset cannot be read, or a lab tool is missing or fails, the session continues with the official PTC tools.
|
|
117
|
+
|
|
118
|
+
## dsh-go and other external tools
|
|
119
|
+
|
|
120
|
+
External plugins are discovered from what they actually register. Tools and workflows are chosen by capability first. Official PTC tools stay available and are the fallback when a third-party tool fails. No external plugin, including dsh-go, is a dependency of this package.
|
|
121
|
+
|
|
122
|
+
**dsh-go** (the phone app and its screen-control surface) stays usable inside a Deep PTC session:
|
|
123
|
+
|
|
124
|
+
- Screen-control tools remain in the initial PTC SDK. They are not folded into the on-demand catalog and they are not quarantined after a failure. A tool qualifies when it sets `resident` (or `deepPtc.resident`), when its presentation carries the `dsh-go/view` key, when its name is `intent`, `collect`, `tap_xy`, or starts with `screen_`, or when its provider is marked as dsh-go, screen control, computer use, or phone control. Any other plugin can use the same `resident` flag. Ordinary extensions stay on demand.
|
|
125
|
+
- Deep PTC does not declare dsh-go's own slots and does not replace its settings. Those forms still come from the Cordis schema, so the app renders them itself.
|
|
126
|
+
- The tool-state control under the composer reads its own state first. If the projection is missing, belongs to another preset, or throws, that control renders nothing. A failure there leaves the input row and the screen-control chrome in place.
|
|
127
|
+
|
|
128
|
+
Phone screen control was not clicked on a device for this release. The guarantee above is the SDK membership, the quarantine rule, and the composer failure path.
|
|
129
|
+
|
|
108
130
|
## Working contract
|
|
109
131
|
|
|
110
132
|
- Spend the budget on the work: the persona states that the model works at DeepSeek with an unlimited token budget in this mode, so it does not skip reads, searches, commands or checks to save tokens. Guardrails forbid padding, and compaction, pruning and subagents keep each request inside its finite context window.
|
|
@@ -118,13 +140,13 @@ A prompt changes the model's working tendency, not the real token limit or billi
|
|
|
118
140
|
|
|
119
141
|
## Install or upgrade
|
|
120
142
|
|
|
121
|
-
Requires Node `>=24` and DSH `>=0.2.2-rc.1
|
|
143
|
+
Requires Node `>=24` and DSH RC `>=0.2.2-rc.1` (the installed desktop). Alpha builds are not supported. Windows desktop rc.5 was used for real WSL/PowerShell command checks. macOS/Zsh configuration, argv and tool mounting were checked; native macOS execution has not been verified on this Windows host.
|
|
122
144
|
|
|
123
145
|
```js
|
|
124
|
-
plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.7.
|
|
146
|
+
plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.7.4" })
|
|
125
147
|
// Or from a local checkout or archive:
|
|
126
148
|
plugin_manager({ action: "install_bundle", target: "C:\\path\\to\\dsh-deep-ptc-mode" })
|
|
127
|
-
// Or target: "C:\\path\\to\\dsh-deep-ptc-mode-1.7.
|
|
149
|
+
// Or target: "C:\\path\\to\\dsh-deep-ptc-mode-1.7.4.tgz"
|
|
128
150
|
```
|
|
129
151
|
|
|
130
152
|
Repository locator: `github:lishize20040802-rgb/dsh-deep-ptc-mode`. It installs content actually published there; a local upgrade does not publish to GitHub or npm.
|
|
@@ -138,6 +160,8 @@ Settings persist through the active profile's Cordis patch:
|
|
|
138
160
|
config:
|
|
139
161
|
environment: auto # auto | wsl | powershell | zsh | bash
|
|
140
162
|
wslDistribution: '' # blank uses the Windows default
|
|
163
|
+
shellExecutable: '' # blank keeps the official lookup
|
|
164
|
+
pluginLab: false # true loads the host's creative-mode rows
|
|
141
165
|
```
|
|
142
166
|
|
|
143
167
|
Prefer the UI, which uses revisioned, atomic Host form writes.
|
package/README.zh.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 深度 PTC 模式
|
|
2
2
|
|
|
3
|
-
[English](README.md) · MIT · 当前版本:**1.7.
|
|
3
|
+
[English](README.md) · MIT · 当前版本:**1.7.4**
|
|
4
4
|
|
|
5
5
|
[1.7.3 实测汇总 / Test summary](TEST_REPORT.md)
|
|
6
6
|
**让插件协作,让当前官方 PTC 工具兜底,让任务始终可沟通。**
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
外部插件需支持当前宿主,并在 `deep-ptc` 的作用域中发布工具;支持保留官方工具的插件,应在自身配置中保留兜底能力。这是任务级的合作选择机制,不代表所有插件或整个替换执行器都能直接互换。OPS 可以作为其中一个提供者,不是内置依赖,也不表示已经完成 OPS 的实际联调。
|
|
24
24
|
|
|
25
|
-
官方兜底沿用 1.6.1 的动态派生机制:自动读取实际运行宿主的官方 PTC 声明;每 5
|
|
25
|
+
官方兜底沿用 1.6.1 的动态派生机制:自动读取实际运行宿主的官方 PTC 声明;每 5 秒检测声明变化,仅在声明或本插件配置变化时重建预设,工具模块和配置跟随该声明;仅在声明无法读取、解析或派生时使用随包快照并记录日志。官方升级后需重载并创建使用新版预设的会话,既有会话不被强制切换。最低支持当前桌面端 DSH RC `>=0.2.2-rc.1`。只支持 RC,不支持 alpha。不设 RC 上限;更高的 RC 仍需验证宿主接口。
|
|
26
26
|
|
|
27
27
|
## 1.7.2:轻量、按需、可恢复的工具调用层
|
|
28
28
|
|
|
@@ -105,6 +105,28 @@ WSL 命令使用 Linux/POSIX 语法;文件工具和 `workdir` 仍用 Windows
|
|
|
105
105
|
|
|
106
106
|
原生 PowerShell、Bash 和 Zsh 继续使用 Harness 的沙箱、审批和进程管理。WSL 跨越 Windows/Linux 边界,目前仅支持宿主已经授权的 `danger-full-access` 执行;`read-only` 或 `workspace-write` 调用在启动命令前失败。插件不会自行升权、改变默认权限或悄悄换 shell。
|
|
107
107
|
|
|
108
|
+
选择 PowerShell、Bash 或 Zsh 时,可以指定本机已经发现的常见可执行文件。留空则沿用官方查找顺序。WSL 仍只选择发行版。所选文件不存在时记一条警告并回到自动。PowerShell 的选择写入官方执行器的 `pwshPath`。Bash 和 Zsh 只改启动参数。
|
|
109
|
+
|
|
110
|
+
## 插件实验台:官方创造模式,只在内存里试
|
|
111
|
+
|
|
112
|
+
深度 PTC 经常用来编程,也可以用来设计和试写 DSH 插件。**插件实验台**默认关闭。在 **设置 → 插件 → 深度 PTC** 里勾选,然后新建会话。Cordis 配置里的 `pluginLab: true` 是同一个开关。
|
|
113
|
+
|
|
114
|
+
打开后,深度 PTC 用和官方 PTC 相同的方式读取宿主正在发布的**创造模式**:走 `agentPresets.readDocument`,优先名称正好是「创造模式」的预设,否则用已随宿主发布的 id `cordis`。只追加创造模式相对当前 PTC 多出来的那些行。模块名保持该预设原文,官方以后改名时跟着宿主走,不把包名写死在本插件里。创造模式技能目录如果写成相对它自己文件的位置,就按那个预设所在目录解析。桌面端已经挂了宿主运行器,这些行留给宿主,不在深度 PTC 里再挂一份。
|
|
115
|
+
|
|
116
|
+
实验台用来在当前进程里设计和试运行插件:检查当前组合,定义一个通过语法检查的包,再经宿主原有的批准后运行。包只留在本进程内存里,不写入仓库、已发布预设、桌面端组合或本插件源码。宿主的批准保持原样。创造模式预设读不到,或实验工具缺失、失败时,会话继续使用官方 PTC 工具。
|
|
117
|
+
|
|
118
|
+
## dsh-go 与其他外部工具
|
|
119
|
+
|
|
120
|
+
外部插件按它们实际注册出来的工具和工作流接入。先按能力选用,第三方工具失败时官方 PTC 工具仍在,并作为兜底。本包不把任何外部插件(包括 dsh-go)写成依赖。
|
|
121
|
+
|
|
122
|
+
**dsh-go**(手机端,以及手机屏幕控制)在深度 PTC 会话里保持可用:
|
|
123
|
+
|
|
124
|
+
- 屏幕控制工具留在初始 PTC SDK 里,不收进按需目录,失败后也不隔离。满足下面任一条件即可:工具自己标了 `resident`(或 `deepPtc.resident`);展示信息带有 `dsh-go/view`;名称是 `intent`、`collect`、`tap_xy`,或以 `screen_` 开头;提供者标记为 dsh-go、屏幕控制、computer use 或手机控制。其他插件也可以用同一个 `resident` 标记把自己留在初始列表。普通扩展仍按需加载。
|
|
125
|
+
- 深度 PTC 不声明 dsh-go 自己的槽位,也不替换它的设置表单。表单仍来自 Cordis schema,由应用自己渲染。
|
|
126
|
+
- 输入框下方的工具状态控件先读自己的状态。投影缺失、不属于本预设或抛错时,这块控件留空。这里失败不会拆掉输入区,也不会拆掉屏幕控制界面。
|
|
127
|
+
|
|
128
|
+
本版没有在真机上点过手机屏幕控制。上面保证的是 SDK 成员资格、隔离规则,以及界面投影失败时的退让。
|
|
129
|
+
|
|
108
130
|
## 工作规则
|
|
109
131
|
|
|
110
132
|
- **不为 token 省力:** 人设写明在深度求索工作、本模式 token 预算无限,按问题需要而不是成本决定读取、搜索、命令和验证的深度;同时禁止注水和啰嗦,单次上下文仍有限,靠压缩、裁剪和子代理控制。
|
|
@@ -118,15 +140,15 @@ WSL 命令使用 Linux/POSIX 语法;文件工具和 `workdir` 仍用 Windows
|
|
|
118
140
|
|
|
119
141
|
## 安装和升级
|
|
120
142
|
|
|
121
|
-
要求 Node `>=24`、DSH `>=0.2.2-rc.1
|
|
143
|
+
要求 Node `>=24`、DSH RC `>=0.2.2-rc.1`(当前桌面端)。不支持 alpha 版本。1.3.0 已用 Windows 桌面端 rc.5 做 WSL/PowerShell 命令验证。macOS/Zsh 分支做了配置、工具挂载与参数测试,尚未在 macOS 真机执行。
|
|
122
144
|
|
|
123
145
|
本地目录或构建产物可通过插件管理器安装:
|
|
124
146
|
|
|
125
147
|
```js
|
|
126
|
-
plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.7.
|
|
148
|
+
plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.7.4" })
|
|
127
149
|
// 也可从本地目录或安装包安装:
|
|
128
150
|
plugin_manager({ action: "install_bundle", target: "C:\\path\\to\\dsh-deep-ptc-mode" })
|
|
129
|
-
// 或 target: "C:\\path\\to\\dsh-deep-ptc-mode-1.7.
|
|
151
|
+
// 或 target: "C:\\path\\to\\dsh-deep-ptc-mode-1.7.4.tgz"
|
|
130
152
|
```
|
|
131
153
|
|
|
132
154
|
GitHub 地址:`github:lishize20040802-rgb/dsh-deep-ptc-mode`。该地址安装远端实际内容;本地升级不会自动发布到 GitHub/npm。
|
|
@@ -140,6 +162,8 @@ GitHub 地址:`github:lishize20040802-rgb/dsh-deep-ptc-mode`。该地址安装
|
|
|
140
162
|
config:
|
|
141
163
|
environment: wsl # auto | wsl | powershell | zsh | bash
|
|
142
164
|
wslDistribution: Ubuntu # 留空为 Windows 默认发行版
|
|
165
|
+
shellExecutable: '' # 留空沿用官方查找
|
|
166
|
+
pluginLab: false # true 时加载宿主创造模式多出来的行
|
|
143
167
|
```
|
|
144
168
|
|
|
145
169
|
优先使用界面保存,宿主会处理版本冲突和原子配置写入。
|
package/lib/client.js
CHANGED
|
@@ -10,6 +10,9 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
10
10
|
wsl: 'WSL Bash(Windows)', powershell: 'PowerShell(Windows)',
|
|
11
11
|
zsh: 'Zsh(macOS / Linux)', bash: '原生 Bash(macOS / Linux)',
|
|
12
12
|
distribution: 'WSL 发行版', distributionHint: '留空使用 Windows 的默认发行版,例如 Ubuntu。',
|
|
13
|
+
shell: 'Shell 版本', shellAuto: '自动(沿用官方查找顺序)',
|
|
14
|
+
shellHint: '只列出本机已发现的常见版本。文件消失后自动回退。WSL 仍只选择发行版。',
|
|
15
|
+
pluginLab: '插件实验台', pluginLabHint: '默认关闭。打开后在内存中检查、定义并经宿主批准后运行插件,不改已发布预设,也不绕过批准。',
|
|
13
16
|
sessions: '保存后请新建一个“深度PTC模式”会话。已有会话与后台任务保留原环境。',
|
|
14
17
|
wslHint: 'WSL 暂不支持 Windows 的受限沙箱;受限调用会明确失败,不会自动切换或绕过限制。',
|
|
15
18
|
save: '保存', saving: '保存中…', saved: '已保存,新会话将使用所选环境。',
|
|
@@ -22,6 +25,9 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
22
25
|
wsl: 'WSL Bash (Windows)', powershell: 'PowerShell (Windows)',
|
|
23
26
|
zsh: 'Zsh (macOS / Linux)', bash: 'Native Bash (macOS / Linux)',
|
|
24
27
|
distribution: 'WSL distribution', distributionHint: 'Leave blank for the Windows default distribution, for example Ubuntu.',
|
|
28
|
+
shell: 'Shell version', shellAuto: 'Automatic (official lookup)',
|
|
29
|
+
shellHint: 'Lists common executables found on this machine. A missing file falls back to automatic. WSL still selects a distribution only.',
|
|
30
|
+
pluginLab: 'Plugin lab', pluginLabHint: 'Off by default. When on, inspect, define and run plugins in memory through host approval. Shipped presets stay unchanged.',
|
|
25
31
|
sessions: 'After saving, create a new Deep PTC session. Existing sessions and background jobs keep their environment.',
|
|
26
32
|
wslHint: 'WSL does not support the confined Windows sandbox. Confined calls fail without execution or fallback.',
|
|
27
33
|
save: 'Save', saving: 'Saving…', saved: 'Saved. New sessions will use this environment.',
|
|
@@ -36,6 +42,8 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
36
42
|
const state = React.useSyncExternalStore(subscribe, read, read);
|
|
37
43
|
const [environment, setEnvironment] = React.useState('auto');
|
|
38
44
|
const [distribution, setDistribution] = React.useState('');
|
|
45
|
+
const [shellExecutable, setShellExecutable] = React.useState('');
|
|
46
|
+
const [pluginLab, setPluginLab] = React.useState(false);
|
|
39
47
|
const [saving, setSaving] = React.useState(false);
|
|
40
48
|
const [message, setMessage] = React.useState('');
|
|
41
49
|
const [failed, setFailed] = React.useState(false);
|
|
@@ -45,6 +53,8 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
45
53
|
if (!state.value || dirty.current) return;
|
|
46
54
|
setEnvironment(state.value.environment);
|
|
47
55
|
setDistribution(state.value.wslDistribution ?? '');
|
|
56
|
+
setShellExecutable(state.value.shellExecutable ?? '');
|
|
57
|
+
setPluginLab(state.value.pluginLab === true);
|
|
48
58
|
draftRevision.current = state.revision;
|
|
49
59
|
}, [state.value, state.revision]);
|
|
50
60
|
if (view === 'summary') return t('summary');
|
|
@@ -64,6 +74,8 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
64
74
|
const ok = await form.mutate([
|
|
65
75
|
{ op: 'set', path: ['environment'], value: environment },
|
|
66
76
|
{ op: 'set', path: ['wslDistribution'], value: distribution.trim() },
|
|
77
|
+
{ op: 'set', path: ['shellExecutable'], value: shellExecutable },
|
|
78
|
+
{ op: 'set', path: ['pluginLab'], value: pluginLab },
|
|
67
79
|
], draftRevision.current);
|
|
68
80
|
if (!ok) throw new Error('Configuration was rejected');
|
|
69
81
|
dirty.current = false;
|
|
@@ -71,12 +83,20 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
71
83
|
draftRevision.current = latest.revision;
|
|
72
84
|
setEnvironment(latest.value?.environment ?? environment);
|
|
73
85
|
setDistribution(latest.value?.wslDistribution ?? distribution.trim());
|
|
86
|
+
setShellExecutable(latest.value?.shellExecutable ?? shellExecutable);
|
|
87
|
+
setPluginLab(latest.value?.pluginLab === true);
|
|
74
88
|
setMessage(t('saved'));
|
|
75
89
|
} catch {
|
|
76
90
|
draftRevision.current = form.getSnapshot().revision;
|
|
77
91
|
setFailed(true); setMessage(t('failed'));
|
|
78
92
|
} finally { setSaving(false); }
|
|
79
93
|
}
|
|
94
|
+
const effective = environment === 'auto'
|
|
95
|
+
? (state.value.hostPlatform === 'win32' ? 'powershell' : state.value.hostPlatform === 'darwin' ? 'zsh' : 'bash')
|
|
96
|
+
: environment;
|
|
97
|
+
const choices = (Array.isArray(state.value.shellChoices) ? state.value.shellChoices : [])
|
|
98
|
+
.filter(item => item && item.family === effective && typeof item.id === 'string');
|
|
99
|
+
const showShell = effective !== 'wsl' && choices.length > 0;
|
|
80
100
|
const control = { width: '100%', padding: '8px 10px', borderRadius: '6px',
|
|
81
101
|
color: 'inherit', background: 'var(--dsw-alias-bg-base)', border: '1px solid var(--dsw-alias-border-l1)' };
|
|
82
102
|
return h('form', { onSubmit: save, style: { display: 'grid', gap: '12px', maxWidth: '600px' } },
|
|
@@ -90,6 +110,18 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
90
110
|
h('input', { id: 'deep-ptc-distribution', value: distribution, disabled, style: control,
|
|
91
111
|
onChange: event => { changed(); setDistribution(event.target.value); } }),
|
|
92
112
|
h('p', null, t('distributionHint')), h('p', null, t('wslHint'))) : null,
|
|
113
|
+
showShell ? h(React.Fragment, null,
|
|
114
|
+
h('label', { htmlFor: 'deep-ptc-shell' }, t('shell')),
|
|
115
|
+
h('select', { id: 'deep-ptc-shell', value: shellExecutable, disabled, style: control,
|
|
116
|
+
onChange: event => { changed(); setShellExecutable(event.target.value); } },
|
|
117
|
+
h('option', { value: '' }, t('shellAuto')),
|
|
118
|
+
...choices.map(item => h('option', { key: item.id, value: item.id }, item.label))),
|
|
119
|
+
h('p', null, t('shellHint'))) : null,
|
|
120
|
+
h('label', { htmlFor: 'deep-ptc-plugin-lab' },
|
|
121
|
+
h('input', { id: 'deep-ptc-plugin-lab', type: 'checkbox', checked: pluginLab, disabled,
|
|
122
|
+
onChange: event => { changed(); setPluginLab(event.target.checked); } }),
|
|
123
|
+
' ', t('pluginLab')),
|
|
124
|
+
h('p', null, t('pluginLabHint')),
|
|
93
125
|
h('p', null, t('sessions')),
|
|
94
126
|
!state.writable ? h('p', { role: 'status' }, t('readOnly')) : null,
|
|
95
127
|
message ? h('p', { role: failed ? 'alert' : 'status' }, message) : null,
|
|
@@ -98,13 +130,17 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
98
130
|
}
|
|
99
131
|
|
|
100
132
|
function ToolStateControls({ useProjection, reset, t }) {
|
|
101
|
-
const preset = useProjection('agentPreset');
|
|
102
|
-
const state = useProjection('deepPtcTools');
|
|
103
133
|
const [busy, setBusy] = React.useState(false);
|
|
104
134
|
const [message, setMessage] = React.useState('');
|
|
105
135
|
const generation = React.useRef(0);
|
|
106
136
|
React.useEffect(() => { generation.current++; setBusy(false); setMessage(''); return () => { generation.current++; }; }, [reset]);
|
|
107
|
-
|
|
137
|
+
let preset, state;
|
|
138
|
+
try {
|
|
139
|
+
if (typeof useProjection !== 'function') return null;
|
|
140
|
+
preset = useProjection('agentPreset');
|
|
141
|
+
state = useProjection('deepPtcTools');
|
|
142
|
+
} catch { return null; }
|
|
143
|
+
if (preset !== 'deep-ptc' || !state || typeof state !== 'object') return null;
|
|
108
144
|
const failed = state?.report?.tools ?? [];
|
|
109
145
|
async function reload() {
|
|
110
146
|
const current = generation.current;
|
|
@@ -148,10 +184,22 @@ window.__ModuleLoader__.load({ id: 'dsh-deep-ptc-mode', factory: require => {
|
|
|
148
184
|
name: 'plugins.item', id: 'deep-ptc', order: 41,
|
|
149
185
|
label: () => t('title'), locale: 'deep-ptc',
|
|
150
186
|
}, props => h(Card, { ...props, form, t })))));
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
187
|
+
try {
|
|
188
|
+
ctx.inject?.(['remote', 'remote.commands'], child => {
|
|
189
|
+
try {
|
|
190
|
+
child.slots.inject('conversation.composer.dock', () => child.slots.register({
|
|
191
|
+
name: 'conversation.composer.dock', id: 'deep-ptc-tool-states', order: 90,
|
|
192
|
+
inject: sessionId => ({
|
|
193
|
+
reset: () => {
|
|
194
|
+
const execute = child.remote?.commands?.execute;
|
|
195
|
+
if (typeof execute !== 'function') return Promise.resolve({ ok: false, error: { message: 'unavailable' } });
|
|
196
|
+
return execute(sessionId, '/deep-ptc-reset-tools', []);
|
|
197
|
+
},
|
|
198
|
+
}),
|
|
199
|
+
}, props => h(ToolStateControls, { ...props, t })));
|
|
200
|
+
} catch { /* a broken dock must not take the composer with it */ }
|
|
201
|
+
});
|
|
202
|
+
} catch { /* the composer stays usable when this slot cannot register */ }
|
|
155
203
|
}
|
|
156
204
|
return { apply, inject };
|
|
157
205
|
} });
|
package/lib/creative.mjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Rows the official creative-mode preset adds beyond the preset Deep PTC is
|
|
2
|
+
// derived from. Module names are copied from that declaration. A renamed
|
|
3
|
+
// official package is followed because this file never names one.
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
/** Shipped preset id, the same kind of lookup key as `ptc`. Not a module name. */
|
|
7
|
+
export const CREATIVE_PRESET_ID = 'cordis';
|
|
8
|
+
|
|
9
|
+
function text(value) {
|
|
10
|
+
return typeof value === 'string' ? value : '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Pick the creative preset from a live roster.
|
|
15
|
+
* The published name wins, then the shipped id, then a description that says so.
|
|
16
|
+
* @param {Array<{ id?: string, name?: string, description?: string }>} roster
|
|
17
|
+
*/
|
|
18
|
+
export function selectCreativePreset(roster) {
|
|
19
|
+
const rows = Array.isArray(roster) ? roster.filter(row => row && typeof row === 'object') : [];
|
|
20
|
+
return rows.find(row => row.name === '创造模式')
|
|
21
|
+
?? rows.find(row => row.id === CREATIVE_PRESET_ID)
|
|
22
|
+
?? rows.find(row => text(row.description).includes('创造'));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isPersona(row) {
|
|
26
|
+
return row?.id === 'persona' || (typeof row?.name === 'string' && row.name.includes('dsh-persona'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function walk(rows, visit) {
|
|
30
|
+
if (!Array.isArray(rows)) return;
|
|
31
|
+
for (const row of rows) {
|
|
32
|
+
if (!row || typeof row !== 'object') continue;
|
|
33
|
+
visit(row);
|
|
34
|
+
if (row.group === true && Array.isArray(row.config)) walk(row.config, visit);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function idsOf(rows) {
|
|
39
|
+
const ids = new Set();
|
|
40
|
+
walk(rows, row => { if (typeof row.id === 'string') ids.add(row.id); });
|
|
41
|
+
return ids;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function rowById(rows, id) {
|
|
45
|
+
let found;
|
|
46
|
+
walk(rows, row => { if (found === undefined && row.id === id) found = row; });
|
|
47
|
+
return found;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function pinDir(entry, root) {
|
|
51
|
+
if (!root || !entry || typeof entry !== 'object' || typeof entry.__jsExpr !== 'string') return entry;
|
|
52
|
+
if (!entry.__jsExpr.includes('baseUrl') || !entry.__jsExpr.includes('skills')) return entry;
|
|
53
|
+
return join(root, 'skills');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function pinDirs(dirs, root) {
|
|
57
|
+
return Array.isArray(dirs) ? dirs.map(entry => pinDir(entry, root)) : dirs;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function sameDir(left, right) {
|
|
61
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function withPinnedSkillDirs(row, root) {
|
|
65
|
+
const copy = structuredClone(row);
|
|
66
|
+
const dirs = copy?.config?.customSkillDirs;
|
|
67
|
+
if (Array.isArray(dirs)) copy.config = { ...copy.config, customSkillDirs: pinDirs(dirs, root) };
|
|
68
|
+
return copy;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Rows to append when the creative preset is enabled.
|
|
73
|
+
* Baseline rows stay as they are: official PTC remains the fallback.
|
|
74
|
+
* @param {object[]} creativePlugins
|
|
75
|
+
* @param {object[]} baselinePlugins
|
|
76
|
+
* @param {{ root?: string }} [options] directory of the creative preset, used to pin skill paths
|
|
77
|
+
*/
|
|
78
|
+
export function creativeAdditions(creativePlugins, baselinePlugins, options = {}) {
|
|
79
|
+
const root = typeof options.root === 'string' ? options.root : '';
|
|
80
|
+
const baselineIds = idsOf(baselinePlugins);
|
|
81
|
+
const additions = [];
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
|
|
84
|
+
const uniqueId = preferred => {
|
|
85
|
+
if (!baselineIds.has(preferred) && !seen.has(preferred)) return preferred;
|
|
86
|
+
for (let suffix = 2; ; suffix += 1) {
|
|
87
|
+
const candidate = `${preferred}-${suffix}`;
|
|
88
|
+
if (!baselineIds.has(candidate) && !seen.has(candidate)) return candidate;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const push = row => {
|
|
93
|
+
if (!row || seen.has(row.id)) return;
|
|
94
|
+
seen.add(row.id);
|
|
95
|
+
additions.push(row);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const consider = row => {
|
|
99
|
+
if (!row || typeof row !== 'object' || isPersona(row)) return;
|
|
100
|
+
if (row.group === true) {
|
|
101
|
+
if (typeof row.id === 'string' && baselineIds.has(row.id)) {
|
|
102
|
+
if (Array.isArray(row.config)) for (const child of row.config) consider(child);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
push(withPinnedSkillDirs(row, root));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (typeof row.id === 'string' && baselineIds.has(row.id)) {
|
|
109
|
+
const baseline = rowById(baselinePlugins, row.id);
|
|
110
|
+
const creativeDirs = row.config?.customSkillDirs;
|
|
111
|
+
const baselineDirs = baseline?.config?.customSkillDirs ?? [];
|
|
112
|
+
if (!Array.isArray(creativeDirs) || creativeDirs.length === 0) return;
|
|
113
|
+
const pinned = pinDirs(creativeDirs, root);
|
|
114
|
+
const extra = pinned.filter(entry => !baselineDirs.some(existing => sameDir(existing, entry)));
|
|
115
|
+
if (extra.length === 0) return;
|
|
116
|
+
const id = uniqueId(`${row.id}-creative`);
|
|
117
|
+
push({ id, name: row.name, config: { customSkillDirs: extra } });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
push(withPinnedSkillDirs(row, root));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (Array.isArray(creativePlugins)) {
|
|
124
|
+
for (const row of creativePlugins) consider(row);
|
|
125
|
+
}
|
|
126
|
+
return additions;
|
|
127
|
+
}
|
package/lib/environment.mjs
CHANGED
|
@@ -5,10 +5,11 @@ export const inject = ['systemPrompt'];
|
|
|
5
5
|
export const Config = z.object({
|
|
6
6
|
environment: z.union(['wsl', 'powershell', 'zsh', 'bash']).required(),
|
|
7
7
|
wslDistribution: z.string().default(''),
|
|
8
|
+
shellNote: z.string().default(''),
|
|
8
9
|
});
|
|
9
10
|
export function apply(ctx, config) {
|
|
10
11
|
ctx.systemPrompt.section({
|
|
11
12
|
name: 'deep-ptc:execution-environment', order: 10190,
|
|
12
|
-
text: environmentText(config.environment, config.wslDistribution),
|
|
13
|
+
text: environmentText(config.environment, config.wslDistribution, config.shellNote),
|
|
13
14
|
});
|
|
14
15
|
}
|
package/lib/executor.mjs
CHANGED
|
@@ -5,30 +5,55 @@ import { assertExecutionPolicy, shellArgv } from './model.mjs';
|
|
|
5
5
|
export const name = 'deep-ptc-mapped-executor';
|
|
6
6
|
export const inject = [];
|
|
7
7
|
export const Config = z.object({
|
|
8
|
-
environment: z.union(['wsl', 'zsh']).required(),
|
|
8
|
+
environment: z.union(['wsl', 'zsh', 'bash']).required(),
|
|
9
9
|
wslDistribution: z.string().default(''),
|
|
10
|
+
shellExecutable: z.string().default(''),
|
|
10
11
|
// The official bash executor module and its options, as the installed base declaration names them.
|
|
11
12
|
base: z.string().required(),
|
|
12
13
|
options: z.any(),
|
|
13
14
|
});
|
|
14
15
|
|
|
16
|
+
function argvOf(environment, spec, distribution, executable) {
|
|
17
|
+
return shellArgv(environment, spec, distribution, process.platform, executable);
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
// Extend the official bash executor: its process handles, output retention, cancellation, jobs,
|
|
16
21
|
// sandbox and Config stay official; only the argv that starts the shell changes.
|
|
17
|
-
export function mappedExecutor(Base, environment, distribution = '') {
|
|
22
|
+
export function mappedExecutor(Base, environment, distribution = '', executable = '') {
|
|
23
|
+
const explicit = typeof executable === 'string' && executable !== '';
|
|
18
24
|
return class MappedShellExecutor extends Base {
|
|
19
25
|
async execute(spec) {
|
|
20
26
|
assertExecutionPolicy(environment, spec.sandboxPolicy);
|
|
21
27
|
if (spec.sandboxPolicy.mode !== 'danger-full-access') return super.execute(spec);
|
|
22
|
-
const process = await super.executeArgv(spec,
|
|
28
|
+
const process = await super.executeArgv(spec, argvOf(environment, spec, distribution, executable));
|
|
23
29
|
return Base.decorateResult(process, result => ({
|
|
24
30
|
...result, sandbox: { mode: spec.sandboxPolicy.mode, denied: false },
|
|
25
31
|
}));
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
// Current sandboxes enter through run/start. Confined calls use confine, so the chosen
|
|
35
|
+
// binary stays inside the official sandbox. Full access keeps the same denial stamp as before.
|
|
36
|
+
async run(spec) {
|
|
37
|
+
if (!explicit || typeof super.run !== 'function') return super.run?.call(this, spec) ?? this.execute(spec);
|
|
38
|
+
assertExecutionPolicy(environment, spec.sandboxPolicy);
|
|
39
|
+
if (spec.sandboxPolicy?.mode !== 'danger-full-access') return super.run(spec);
|
|
40
|
+
if (typeof super.runArgv !== 'function') return this.execute(spec);
|
|
41
|
+
const result = await super.runArgv(spec, argvOf(environment, spec, distribution, executable));
|
|
42
|
+
return { ...result, sandbox: { mode: spec.sandboxPolicy.mode, denied: false } };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
start(spec) {
|
|
46
|
+
if (!explicit || typeof super.start !== 'function') return super.start?.call(this, spec);
|
|
47
|
+
assertExecutionPolicy(environment, spec.sandboxPolicy);
|
|
48
|
+
if (spec.sandboxPolicy?.mode !== 'danger-full-access') return super.start(spec);
|
|
49
|
+
if (typeof this.startArgv !== 'function') return super.start(spec);
|
|
50
|
+
return this.startArgv(spec, argvOf(environment, spec, distribution, executable));
|
|
51
|
+
}
|
|
52
|
+
|
|
28
53
|
confine(command, policy, signal) {
|
|
29
54
|
assertExecutionPolicy(environment, policy);
|
|
30
|
-
return this.ctx.sandbox.confine(
|
|
31
|
-
{ command, workdir: policy.workspaceRoot }, distribution), policy, signal);
|
|
55
|
+
return this.ctx.sandbox.confine(argvOf(environment,
|
|
56
|
+
{ command, workdir: policy.workspaceRoot }, distribution, executable), policy, signal);
|
|
32
57
|
}
|
|
33
58
|
};
|
|
34
59
|
}
|
|
@@ -37,5 +62,5 @@ export async function apply(ctx, config) {
|
|
|
37
62
|
const Base = pluginOf(await importHost(config.base));
|
|
38
63
|
if (typeof Base !== 'function' || typeof Base.decorateResult !== 'function' || typeof Base.prototype.executeArgv !== 'function')
|
|
39
64
|
throw new Error(`${config.base} no longer exposes the executor API Deep PTC extends; choose PowerShell or native Bash`);
|
|
40
|
-
ctx.plugin(mappedExecutor(Base, config.environment, config.wslDistribution), config.options);
|
|
65
|
+
ctx.plugin(mappedExecutor(Base, config.environment, config.wslDistribution, config.shellExecutable), config.options);
|
|
41
66
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
2
|
import snapshot from './preset.json' with { type: 'json' };
|
|
3
|
-
import {
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { CREATIVE_PRESET_ID } from './creative.mjs';
|
|
5
7
|
import { normalizePreferences } from './tool-policy.mjs';
|
|
6
8
|
import { availableEnvironments, BASE_SNAPSHOT, DEFAULT_FOREGROUND_SECONDS, deriveDeepPtc, normalizeDistribution, resolveEnvironment } from './model.mjs';
|
|
7
|
-
import {
|
|
9
|
+
import { discoverShells, resolveShellExecutable, shellNote } from './shells.mjs';
|
|
10
|
+
import { BASE_DECLARATION_SPECIFIER, creativePresetUrl, loadCreativePreset, loadCurrentPreset, officialPresetUrl, parseOfficialExecutors } from './upstream.mjs';
|
|
8
11
|
import { importHost, pluginOf, resolveHost } from './host.mjs';
|
|
9
12
|
import { presetLifecycle } from './lifecycle.mjs';
|
|
10
13
|
|
|
14
|
+
function whereExecutable(name) {
|
|
15
|
+
try {
|
|
16
|
+
const command = process.platform === 'win32' ? 'where.exe' : 'which';
|
|
17
|
+
const result = spawnSync(command, [name], { encoding: 'utf8', timeout: 2000, windowsHide: true });
|
|
18
|
+
if (result.status !== 0 || typeof result.stdout !== 'string') return [];
|
|
19
|
+
return result.stdout.split(/\r?\n/u).map(line => line.trim()).filter(Boolean);
|
|
20
|
+
} catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const discoveredShells = discoverShells({
|
|
26
|
+
platform: process.platform,
|
|
27
|
+
env: process.env,
|
|
28
|
+
exists: existsSync,
|
|
29
|
+
where: whereExecutable,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function shellFamily(environment) {
|
|
33
|
+
return environment === 'powershell' || environment === 'bash' || environment === 'zsh' ? environment : '';
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
export const name = 'deep-ptc-settings';
|
|
12
37
|
export const inject = ['agentPresets'];
|
|
13
38
|
export const Config = z.object({
|
|
14
39
|
environment: z.union(availableEnvironments(process.platform)).default('auto').volatile(),
|
|
15
40
|
wslDistribution: z.string().pattern(/^(?!\s*-)[^\u0000-\u001f\u007f]*$/u).default('').volatile(),
|
|
41
|
+
shellExecutable: z.string().default('').volatile(),
|
|
42
|
+
pluginLab: z.boolean().default(false).volatile(),
|
|
43
|
+
shellChoices: z.array(z.object({
|
|
44
|
+
id: z.string(), label: z.string(), path: z.string(), family: z.string(),
|
|
45
|
+
})).default(discoveredShells).volatile(),
|
|
16
46
|
foregroundSeconds: z.number().step(1).min(5).max(600).default(DEFAULT_FOREGROUND_SECONDS).volatile(),
|
|
17
47
|
toolCompatibility: z.boolean().default(true).volatile(),
|
|
18
48
|
toolPreferences: z.any().default([]).volatile(),
|
|
@@ -34,6 +64,8 @@ function settingsOf(ctx, config) {
|
|
|
34
64
|
return {
|
|
35
65
|
environment: config.environment.get(),
|
|
36
66
|
wslDistribution: normalizeDistribution(config.wslDistribution.get()),
|
|
67
|
+
shellExecutable: config.shellExecutable.get(),
|
|
68
|
+
pluginLab: config.pluginLab.get() === true,
|
|
37
69
|
foregroundSeconds: config.foregroundSeconds.get(),
|
|
38
70
|
toolCompatibility: config.toolCompatibility.get(),
|
|
39
71
|
toolPreferences: preferencesOf(ctx, config),
|
|
@@ -78,7 +110,32 @@ async function buildPreset(ctx, config, safeMode) {
|
|
|
78
110
|
const settings = { ...settingsOf(ctx, config), safeMode };
|
|
79
111
|
const executors = officialExecutors(ctx);
|
|
80
112
|
const environment = resolveEnvironment(settings.environment);
|
|
81
|
-
|
|
113
|
+
const family = shellFamily(environment);
|
|
114
|
+
if (family) {
|
|
115
|
+
const requested = typeof settings.shellExecutable === 'string' ? settings.shellExecutable : '';
|
|
116
|
+
const resolved = resolveShellExecutable(requested, { family, discovered: discoveredShells, exists: existsSync });
|
|
117
|
+
if (requested && requested !== 'auto' && !resolved) {
|
|
118
|
+
ctx.logger.warn('Deep PTC: selected shell %s is not available; using the automatic executable', requested);
|
|
119
|
+
}
|
|
120
|
+
settings.shellExecutable = resolved;
|
|
121
|
+
const note = shellNote({ family, executable: resolved });
|
|
122
|
+
if (note) settings.shellNote = note;
|
|
123
|
+
} else {
|
|
124
|
+
settings.shellExecutable = '';
|
|
125
|
+
}
|
|
126
|
+
if (environment === 'wsl' || environment === 'zsh' || (environment === 'bash' && settings.shellExecutable)) {
|
|
127
|
+
settings.mappedExecutor = await canExtend(ctx, executors.bash);
|
|
128
|
+
}
|
|
129
|
+
if (settings.pluginLab && !safeMode) {
|
|
130
|
+
try {
|
|
131
|
+
const creative = await loadCreativePreset(ctx.agentPresets);
|
|
132
|
+
settings.creativePlugins = creative.plugins;
|
|
133
|
+
settings.creativeRoot = creative.root;
|
|
134
|
+
ctx.logger.info('Deep PTC: plugin lab reading %s', creative.source);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
ctx.logger.warn('Deep PTC: creative preset unavailable (%s); plugin lab keeps the PTC tools', error.message);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
82
139
|
settings.executors = executors;
|
|
83
140
|
let upstream = snapshot;
|
|
84
141
|
let source = 'bundled snapshot';
|
|
@@ -127,7 +184,8 @@ export async function apply(ctx, config) {
|
|
|
127
184
|
const signature = async () => {
|
|
128
185
|
const read = url => {try{return readFileSync(fileURLToPath(url),'utf8');}catch{return '';}};
|
|
129
186
|
let runtime='';try{runtime=JSON.stringify(await ctx.agentPresets.readDocument?.('ptc'));}catch{}
|
|
130
|
-
|
|
187
|
+
let creative='';try{creative=JSON.stringify(await ctx.agentPresets.readDocument?.(CREATIVE_PRESET_ID));}catch{}
|
|
188
|
+
return JSON.stringify(settingsOf(ctx,config))+'\0'+runtime+'\0'+creative+'\0'+read(officialPresetUrl())+'\0'+read(resolveHost(BASE_DECLARATION_SPECIFIER))+'\0'+read(creativePresetUrl());
|
|
131
189
|
};
|
|
132
190
|
let previous=await signature(), detecting=false, active=true;
|
|
133
191
|
const detect = async () => {
|
package/lib/lab.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
|
|
3
|
+
export const name = 'deep-ptc-plugin-lab';
|
|
4
|
+
export const inject = ['systemPrompt'];
|
|
5
|
+
export const Config = z.object({});
|
|
6
|
+
|
|
7
|
+
const text = `Plugin lab is on for this Deep PTC session.
|
|
8
|
+
Inspect the live composition, define a syntax-checked package, then run it only through the host approval. Packages stay in memory for this process. They do not write the repository, shipped presets, the desktop composition, or this plugin's source.
|
|
9
|
+
Do not bypass or weaken approval. If a lab tool is missing or fails, continue with the official PTC tools.`;
|
|
10
|
+
|
|
11
|
+
export function apply(ctx) {
|
|
12
|
+
ctx.systemPrompt.section({ name: 'deep-ptc:plugin-lab', order: 10192, text });
|
|
13
|
+
}
|
package/lib/model.mjs
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// never leaves a stale module name behind.
|
|
9
9
|
import snapshot from './preset.json' with { type: 'json' };
|
|
10
10
|
import baseSnapshot from './base-snapshot.json' with { type: 'json' };
|
|
11
|
+
import { creativeAdditions } from './creative.mjs';
|
|
11
12
|
import { normalizePreferences } from './tool-policy.mjs';
|
|
12
13
|
|
|
13
14
|
export const ENVIRONMENTS = ['auto', 'wsl', 'powershell', 'zsh', 'bash'];
|
|
@@ -34,14 +35,16 @@ export function normalizeDistribution(value = '') {
|
|
|
34
35
|
return distribution;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export function shellArgv(environment, spec, distribution = '', platform = process.platform) {
|
|
38
|
+
export function shellArgv(environment, spec, distribution = '', platform = process.platform, executable = '') {
|
|
38
39
|
if (environment === 'wsl') {
|
|
39
40
|
if (platform !== 'win32') throw new Error('WSL requires a Windows host');
|
|
40
41
|
const distro = normalizeDistribution(distribution);
|
|
41
42
|
return ['wsl.exe', ...(distro ? ['--distribution', distro] : []),
|
|
42
43
|
'--cd', spec.workdir, '--exec', 'bash', '-lc', spec.command];
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
const binary = typeof executable === 'string' ? executable : '';
|
|
46
|
+
if (environment === 'zsh') return [binary || (platform === 'darwin' ? '/bin/zsh' : 'zsh'), '-lc', spec.command];
|
|
47
|
+
if (environment === 'bash' && binary) return [binary, '-c', spec.command];
|
|
45
48
|
throw new Error(`No mapped executor for ${environment}`);
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -51,7 +54,7 @@ export function assertExecutionPolicy(environment, policy) {
|
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
export function environmentText(environment, distribution = '') {
|
|
57
|
+
export function environmentText(environment, distribution = '', note = '') {
|
|
55
58
|
const descriptions = {
|
|
56
59
|
wsl: `Execution environment: WSL Bash${distribution ? ` (${distribution})` : ' (Windows default distribution)'}. The bash tool runs POSIX source via wsl.exe and bash -lc. File tools and the tool workdir use Windows host paths; Linux paths belong inside command source. WSL is available only in danger-full-access; a confined call fails without execution. Never silently fall back to PowerShell or another distribution.`,
|
|
57
60
|
powershell: 'Execution environment: native Windows PowerShell. Use the pwsh tool and PowerShell syntax, native Windows paths and $env:NAME. This selection takes precedence over older workspace guidance that assumed WSL. The configured sandbox and approval policy still apply.',
|
|
@@ -59,7 +62,7 @@ export function environmentText(environment, distribution = '') {
|
|
|
59
62
|
bash: 'Execution environment: native Bash on macOS/Linux. Use the bash tool with Bash/POSIX command source and native host paths. This is not WSL. The configured sandbox and approval policy still apply.',
|
|
60
63
|
};
|
|
61
64
|
if (!descriptions[environment]) throw new Error(`Unknown environment ${environment}`);
|
|
62
|
-
return descriptions[environment];
|
|
65
|
+
return typeof note === 'string' && note !== '' ? `${descriptions[environment]}\n${note}` : descriptions[environment];
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
export const DEFAULT_FOREGROUND_SECONDS = 30;
|
|
@@ -148,6 +151,17 @@ export function isShellRow(row) {
|
|
|
148
151
|
return row.group !== true && (SHELL_ROWS.names.includes(row.name) || SHELL_ROWS.ids.includes(row.id));
|
|
149
152
|
}
|
|
150
153
|
|
|
154
|
+
// The desktop already mounts this host service. Copying it into the session would start a second one.
|
|
155
|
+
function isHostRunner(row) {
|
|
156
|
+
return row?.id === 'dynamicCordisRunner'
|
|
157
|
+
|| (typeof row?.name === 'string' && row.name.includes('cordis-host-runner'));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function chosenExecutable(environment, value) {
|
|
161
|
+
if (environment !== 'powershell' && environment !== 'bash' && environment !== 'zsh') return '';
|
|
162
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
163
|
+
}
|
|
164
|
+
|
|
151
165
|
function findRow(rows, { ids = [], names = [] }) {
|
|
152
166
|
let found;
|
|
153
167
|
walkRows(rows, row => {
|
|
@@ -231,7 +245,8 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
231
245
|
const executors = { ...BASE_SNAPSHOT, ...(options.executors ?? {}) };
|
|
232
246
|
const tool = findRow(plugins, SHELL_TOOLS[kind]);
|
|
233
247
|
const official = executors[kind];
|
|
234
|
-
const
|
|
248
|
+
const shellPath = chosenExecutable(environment, options.shellExecutable);
|
|
249
|
+
const mapped = environment === 'wsl' || environment === 'zsh' || (environment === 'bash' && shellPath !== '');
|
|
235
250
|
const unusable = tool === undefined ? `the official PTC preset has no ${kind} tool row`
|
|
236
251
|
: typeof official?.name !== 'string' ? `the installed Harness declares no ${kind} executor`
|
|
237
252
|
: mapped && options.mappedExecutor === false ? `the official bash executor cannot be extended for ${environment}`
|
|
@@ -264,9 +279,11 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
264
279
|
// With background jobs available, the executor timeout only decides when a foreground command
|
|
265
280
|
// moves to the background; the official tools run such commands with onExpiry: none.
|
|
266
281
|
const executorOptions = { ...(official.config ?? {}), timeoutMs: foregroundMs, maxTimeoutMs: foregroundMs };
|
|
282
|
+
if (environment === 'powershell' && shellPath) executorOptions.pwshPath = shellPath;
|
|
267
283
|
const executor = mapped
|
|
268
284
|
? { id: 'executor', name: 'dsh-deep-ptc-mode/executor',
|
|
269
|
-
config: { environment, wslDistribution: distribution, base: official.name, options: executorOptions
|
|
285
|
+
config: { environment, wslDistribution: distribution, base: official.name, options: executorOptions,
|
|
286
|
+
...shellPath ? { shellExecutable: shellPath } : {} } }
|
|
270
287
|
: { id: 'executor', name: official.name, config: executorOptions };
|
|
271
288
|
const terminal = {
|
|
272
289
|
id: environment === 'zsh' ? 'tool-zsh' : tool.id ?? `tool-${kind}`,
|
|
@@ -280,7 +297,8 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
280
297
|
rows.push({
|
|
281
298
|
id: uniqueRowId(plugins, 'execution'), name: 'cordis:group', group: true, isolate: { shell: true },
|
|
282
299
|
config: [executor, terminal, { id: 'execution-instructions', name: 'dsh-deep-ptc-mode/environment',
|
|
283
|
-
config: { environment, wslDistribution: distribution
|
|
300
|
+
config: { environment, wslDistribution: distribution,
|
|
301
|
+
...typeof options.shellNote === 'string' && options.shellNote !== '' ? { shellNote: options.shellNote } : {} } }],
|
|
284
302
|
});
|
|
285
303
|
}
|
|
286
304
|
rows.push({
|
|
@@ -317,6 +335,15 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
317
335
|
skillProvider: findRow(upstream.plugins, {ids:['tool-skill'],names:['@deepseek-ai/dsh-tool-skill']})?.name ?? '@deepseek-ai/dsh-tool-skill' },
|
|
318
336
|
});
|
|
319
337
|
|
|
338
|
+
if (options.pluginLab === true) {
|
|
339
|
+
const additions = creativeAdditions(options.creativePlugins, plugins, {
|
|
340
|
+
root: typeof options.creativeRoot === 'string' ? options.creativeRoot : '',
|
|
341
|
+
}).filter(row => !isHostRunner(row));
|
|
342
|
+
plugins.push(...additions);
|
|
343
|
+
plugins.push({ id: uniqueRowId(plugins, 'plugin-lab'), name: 'dsh-deep-ptc-mode/lab' });
|
|
344
|
+
report.pluginLab = additions.map(row => `${row.id} (${row.name})`);
|
|
345
|
+
}
|
|
346
|
+
|
|
320
347
|
const description = `${PRESET_META.description} 当前环境:${environment}${environment === 'wsl' && distribution ? ` (${distribution})` : ''}`;
|
|
321
348
|
return {
|
|
322
349
|
preset: {
|
package/lib/resident.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Which external tools stay in the initial PTC SDK and are never quarantined.
|
|
2
|
+
// Any plugin can opt in with `resident: true`. Screen-control tools are recognised
|
|
3
|
+
// from their own definition or provider string, not from a pinned package list.
|
|
4
|
+
|
|
5
|
+
const SCREEN_NAMES = new Set(['intent', 'collect', 'tap_xy']);
|
|
6
|
+
const PROVIDER_MARK = /dsh-go|screen-control|computer-use|phone-control/iu;
|
|
7
|
+
|
|
8
|
+
function presentationOf(definition) {
|
|
9
|
+
const presentation = definition.presentationMeta ?? definition.presentation;
|
|
10
|
+
return presentation && typeof presentation === 'object' ? presentation : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {object | null | undefined} definition live tool definition
|
|
15
|
+
* @param {string} [provider] module or plugin that declared it
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
export function staysResident(definition, provider = '') {
|
|
19
|
+
if (!definition || typeof definition !== 'object') return false;
|
|
20
|
+
if (definition.resident === true || definition.deepPtc?.resident === true) return true;
|
|
21
|
+
const presentation = presentationOf(definition);
|
|
22
|
+
if (presentation && Object.prototype.hasOwnProperty.call(presentation, 'dsh-go/view')) return true;
|
|
23
|
+
const name = typeof definition.name === 'string' ? definition.name : '';
|
|
24
|
+
if (SCREEN_NAMES.has(name) || name.startsWith('screen_')) return true;
|
|
25
|
+
const owner = `${provider}\n${typeof definition.deepPtc?.provider === 'string' ? definition.deepPtc.provider : ''}`;
|
|
26
|
+
return PROVIDER_MARK.test(owner);
|
|
27
|
+
}
|
package/lib/shells.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Filesystem probe for shell executables. Callers supply exists/where; this module never spawns.
|
|
2
|
+
|
|
3
|
+
export const AUTO_SHELL = '';
|
|
4
|
+
|
|
5
|
+
const BASH_CANDIDATES = ['/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash', '/opt/homebrew/bin/bash'];
|
|
6
|
+
const ZSH_CANDIDATES = ['/bin/zsh', '/usr/bin/zsh', '/usr/local/bin/zsh', '/opt/homebrew/bin/zsh'];
|
|
7
|
+
|
|
8
|
+
function pathKey(filePath, platform) {
|
|
9
|
+
if (platform === 'win32') return String(filePath).replace(/[\\/]+/gu, '\\').toLowerCase();
|
|
10
|
+
return String(filePath).replace(/\/+/gu, '/');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function rootKey(root, platform) {
|
|
14
|
+
return pathKey(String(root).replace(/[\\/]+$/gu, ''), platform);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function winJoin(root, tail) {
|
|
18
|
+
return `${String(root).replace(/[\\/]+$/gu, '')}\\${tail}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function located(where, name) {
|
|
22
|
+
try {
|
|
23
|
+
const found = where(name);
|
|
24
|
+
if (!Array.isArray(found)) return [];
|
|
25
|
+
return found.filter(item => typeof item === 'string' && item.length > 0);
|
|
26
|
+
} catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function addShell(shells, seen, platform, exists, filePath, label, family) {
|
|
32
|
+
if (typeof filePath !== 'string' || filePath.length === 0) return;
|
|
33
|
+
const key = pathKey(filePath, platform);
|
|
34
|
+
if (seen.has(key) || !exists(filePath)) return;
|
|
35
|
+
seen.add(key);
|
|
36
|
+
shells.push({ id: `path:${filePath}`, label, path: filePath, family });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function bashLabel(filePath, platform) {
|
|
40
|
+
return platform === 'darwin' && filePath === '/bin/bash' ? 'bash (system)' : 'bash';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function zshLabel(filePath) {
|
|
44
|
+
return filePath === '/bin/zsh' ? 'zsh (system)' : 'zsh';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function envPath(env, key, fallback) {
|
|
48
|
+
const value = env?.[key];
|
|
49
|
+
return typeof value === 'string' && value !== '' ? value : fallback;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function discoverShells({ platform, env = {}, exists, where }) {
|
|
53
|
+
const shells = [];
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
const add = (filePath, label, family) => addShell(shells, seen, platform, exists, filePath, label, family);
|
|
56
|
+
|
|
57
|
+
if (platform === 'win32') {
|
|
58
|
+
const systemRoot = envPath(env, 'SystemRoot', 'C:\\Windows');
|
|
59
|
+
const programFiles = envPath(env, 'ProgramFiles', 'C:\\Program Files');
|
|
60
|
+
add(winJoin(systemRoot, 'System32\\WindowsPowerShell\\v1.0\\powershell.exe'), 'Windows PowerShell 5.1', 'powershell');
|
|
61
|
+
const roots = [programFiles];
|
|
62
|
+
const programW6432 = env?.ProgramW6432;
|
|
63
|
+
if (typeof programW6432 === 'string' && programW6432 !== '' && rootKey(programW6432, platform) !== rootKey(programFiles, platform)) {
|
|
64
|
+
roots.push(programW6432);
|
|
65
|
+
}
|
|
66
|
+
for (const root of roots) {
|
|
67
|
+
add(winJoin(root, 'PowerShell\\7\\pwsh.exe'), 'PowerShell 7', 'powershell');
|
|
68
|
+
add(winJoin(root, 'PowerShell\\7-preview\\pwsh.exe'), 'PowerShell 7 Preview', 'powershell');
|
|
69
|
+
}
|
|
70
|
+
for (const name of ['pwsh.exe', 'pwsh']) {
|
|
71
|
+
for (const filePath of located(where, name)) add(filePath, 'PowerShell (pwsh)', 'powershell');
|
|
72
|
+
}
|
|
73
|
+
return shells;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (platform === 'darwin' || platform === 'linux') {
|
|
77
|
+
for (const filePath of BASH_CANDIDATES) add(filePath, bashLabel(filePath, platform), 'bash');
|
|
78
|
+
for (const filePath of located(where, 'bash')) add(filePath, bashLabel(filePath, platform), 'bash');
|
|
79
|
+
for (const filePath of ZSH_CANDIDATES) add(filePath, zshLabel(filePath), 'zsh');
|
|
80
|
+
for (const filePath of located(where, 'zsh')) add(filePath, zshLabel(filePath), 'zsh');
|
|
81
|
+
}
|
|
82
|
+
return shells;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function resolveShellExecutable(value, { family, discovered, exists }) {
|
|
86
|
+
if (value === undefined || value === '' || value === 'auto') return AUTO_SHELL;
|
|
87
|
+
if (!Array.isArray(discovered)) return '';
|
|
88
|
+
for (const item of discovered) {
|
|
89
|
+
if (item?.family !== family || (item.id !== value && item.path !== value)) continue;
|
|
90
|
+
if (typeof item.path !== 'string' || exists(item.path) === false) return '';
|
|
91
|
+
return item.path;
|
|
92
|
+
}
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function fileNameIs(filePath, name) {
|
|
97
|
+
const normalized = String(filePath).replace(/[\\/]+/gu, '/');
|
|
98
|
+
const slash = normalized.lastIndexOf('/');
|
|
99
|
+
const base = slash === -1 ? normalized : normalized.slice(slash + 1);
|
|
100
|
+
return base.toLowerCase() === name;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function shellNote({ family, executable }) {
|
|
104
|
+
if (typeof executable !== 'string' || executable === '') return '';
|
|
105
|
+
if (family === 'powershell' && fileNameIs(executable, 'powershell.exe')) {
|
|
106
|
+
return `Windows PowerShell 5.1 at ${executable} uses Windows PowerShell syntax, not PowerShell 7.`;
|
|
107
|
+
}
|
|
108
|
+
if (family === 'powershell' && fileNameIs(executable, 'pwsh.exe')) {
|
|
109
|
+
return `PowerShell 7+ at ${executable} uses pwsh syntax.`;
|
|
110
|
+
}
|
|
111
|
+
if (family === 'bash') return `The bash tool uses ${executable} with bash -c.`;
|
|
112
|
+
if (family === 'zsh') return `The zsh tool uses ${executable} with zsh -lc.`;
|
|
113
|
+
return '';
|
|
114
|
+
}
|
package/lib/tool-policy.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DIRECTORY_TOOL, blankState, toolSchema, searchCatalog } from './tool-catalog.mjs';
|
|
2
|
+
import { staysResident } from './resident.mjs';
|
|
2
3
|
const officialDefinitions = new WeakMap();
|
|
3
4
|
const validName = name => typeof name === 'string' && name.length > 0 && name.length <= 256 && !/[\u0000-\u001f]/u.test(name);
|
|
4
5
|
const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -97,8 +98,10 @@ export function createCompatibilityState(tools, preferences = [], storage = {},
|
|
|
97
98
|
const declaredExternal = def => typeof def?.deepPtc?.provider === 'string' && !def.deepPtc.provider.startsWith('@deepseek-ai/');
|
|
98
99
|
const official = def => !!def && (isOfficialTool(def) || (!declaredExternal(def) && directory.isOfficial?.(def.name) === true));
|
|
99
100
|
const external = def => !!def && !official(def) && (typeof def.deepPtc?.provider === 'string' || directory.isExternal?.(def.name) === true || (typeof directory.providerOf?.(def.name) === 'string' && !directory.providerOf(def.name).startsWith('@deepseek-ai/')));
|
|
101
|
+
const resident = def => staysResident(def, directory.providerOf?.(def?.name) ?? '');
|
|
100
102
|
const protectedName = (agent, name) => {
|
|
101
103
|
const def = tools.get(name, agent);
|
|
104
|
+
if (def && resident(def)) return true;
|
|
102
105
|
return def ? !external(def) : directory.isOfficial?.(name) === true;
|
|
103
106
|
};
|
|
104
107
|
const usableState = agent => {
|
|
@@ -123,7 +126,7 @@ export function createCompatibilityState(tools, preferences = [], storage = {},
|
|
|
123
126
|
observe(exec, result) {
|
|
124
127
|
const call = calls.get(exec);
|
|
125
128
|
// No definition means the name never belonged to a plugin, so there is nothing to quarantine.
|
|
126
|
-
if (!call?.definition || call.official || exec.name === DIRECTORY_TOOL || exec.name === 'run_code') return;
|
|
129
|
+
if (!call?.definition || call.official || resident(call.definition) || exec.name === DIRECTORY_TOOL || exec.name === 'run_code') return;
|
|
127
130
|
const row = entry(exec.agent);
|
|
128
131
|
if (!row || call.epoch !== row.state.epoch || blocked(exec.agent, exec.name)) return;
|
|
129
132
|
const outcome = classifyToolOutcome(exec, result);
|
|
@@ -155,7 +158,7 @@ export function createCompatibilityState(tools, preferences = [], storage = {},
|
|
|
155
158
|
const row = entry(agent);
|
|
156
159
|
const excluded = new Set(usableState(agent).blocked.map(item => item.name));
|
|
157
160
|
return definitions(agent, toolSet).filter(def => !excluded.has(def.name)
|
|
158
|
-
&& (!compact || !external(def) || def.name === DIRECTORY_TOOL || row?.selected.has(def.name)));
|
|
161
|
+
&& (!compact || !external(def) || def.name === DIRECTORY_TOOL || row?.selected.has(def.name) || resident(def)));
|
|
159
162
|
},
|
|
160
163
|
search(agent, args, toolSet) {
|
|
161
164
|
const excluded = new Set(usableState(agent).blocked.map(item => item.name));
|
package/lib/upstream.mjs
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
// and the plugin only replaces the parts it actually owns (persona, execution
|
|
6
6
|
// environment, reachability guard, job/question wrappers).
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
9
9
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
10
10
|
import { dirname, join, isAbsolute, resolve } from 'node:path';
|
|
11
|
+
import { CREATIVE_PRESET_ID, selectCreativePreset } from './creative.mjs';
|
|
11
12
|
|
|
12
13
|
export const OFFICIAL_PACKAGE = '@deepseek-ai/dsh-web-app';
|
|
13
14
|
const PACKAGE = OFFICIAL_PACKAGE;
|
|
@@ -197,6 +198,85 @@ export function loadOfficialPreset({ presetPath } = {}) {
|
|
|
197
198
|
return { preset: parseOfficialPreset(text), source: url };
|
|
198
199
|
}
|
|
199
200
|
|
|
201
|
+
function pluginRows(value) {
|
|
202
|
+
return Array.isArray(value) && value.length > 0
|
|
203
|
+
&& value.every(row => row && typeof row === 'object' && typeof row.name === 'string');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** A creative-mode composition list, or the creative preset inside a patch document. */
|
|
207
|
+
export function parseCreativeDocument(text) {
|
|
208
|
+
const document = loadYaml().load(text, { schema: presetSchema() });
|
|
209
|
+
if (pluginRows(document)) return document;
|
|
210
|
+
const layers = Array.isArray(document) ? document : [];
|
|
211
|
+
const inserted = [];
|
|
212
|
+
const collect = rows => {
|
|
213
|
+
if (!Array.isArray(rows)) return;
|
|
214
|
+
for (const row of rows) if (row && typeof row === 'object') inserted.push(row);
|
|
215
|
+
};
|
|
216
|
+
collect(layers);
|
|
217
|
+
for (const layer of layers) collect(layer?.insert);
|
|
218
|
+
const presets = inserted.map(row => row.config).filter(config => config && pluginRows(config.plugins));
|
|
219
|
+
const preset = presets.find(config => config.id === CREATIVE_PRESET_ID || config.name === '创造模式');
|
|
220
|
+
if (!preset) throw new Error('installed creative preset has no composition');
|
|
221
|
+
return preset.plugins;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function compositionRoot(path) {
|
|
225
|
+
if (typeof path !== 'string' || path === '') return '';
|
|
226
|
+
try {
|
|
227
|
+
return dirname(path.startsWith('file:') ? fileURLToPath(path) : path);
|
|
228
|
+
} catch {
|
|
229
|
+
return '';
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* File URL of the shipped creative preset.
|
|
235
|
+
* The directory id is the same kind of key as `ptc`. The composition filename is whatever
|
|
236
|
+
* that directory actually contains, so an official rename of the file still resolves.
|
|
237
|
+
*/
|
|
238
|
+
export function creativePresetUrl() {
|
|
239
|
+
const pkg = tryResolve('@deepseek-ai/dsh-agent-presets/package.json');
|
|
240
|
+
if (pkg === undefined) return undefined;
|
|
241
|
+
const dir = join(dirname(fileURLToPath(pkg)), 'presets', CREATIVE_PRESET_ID);
|
|
242
|
+
if (!existsSync(dir)) return undefined;
|
|
243
|
+
let names = [];
|
|
244
|
+
try { names = readdirSync(dir).filter(name => name.endsWith('.yml') || name.endsWith('.yaml')); } catch { return undefined; }
|
|
245
|
+
const named = names.find(name => name.startsWith('agent.')) ?? names[0];
|
|
246
|
+
return named === undefined ? undefined : pathToFileURL(join(dir, named)).href;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Read the creative preset the running host publishes.
|
|
251
|
+
* Module names come from that document. An unreadable preset throws so the caller can keep PTC only.
|
|
252
|
+
*/
|
|
253
|
+
export async function loadCreativePreset(registry) {
|
|
254
|
+
let roster = [];
|
|
255
|
+
if (typeof registry?.list === 'function') {
|
|
256
|
+
try { roster = await registry.list(); } catch { roster = []; }
|
|
257
|
+
}
|
|
258
|
+
const selected = selectCreativePreset(roster);
|
|
259
|
+
if (!process.env[PRESET_PATH_ENV]?.trim() && selected && typeof registry?.readDocument === 'function') {
|
|
260
|
+
const document = await registry.readDocument(selected.id);
|
|
261
|
+
return {
|
|
262
|
+
plugins: parseCreativeDocument(document.content),
|
|
263
|
+
root: compositionRoot(selected.path),
|
|
264
|
+
source: `agentPresets.readDocument(${selected.id})`,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
if (typeof selected?.path === 'string' && selected.path !== '' && existsSync(selected.path.startsWith('file:') ? fileURLToPath(selected.path) : selected.path)) {
|
|
268
|
+
const file = selected.path.startsWith('file:') ? fileURLToPath(selected.path) : selected.path;
|
|
269
|
+
return { plugins: parseCreativeDocument(readFileSync(file, 'utf8')), root: dirname(file), source: file };
|
|
270
|
+
}
|
|
271
|
+
const url = creativePresetUrl();
|
|
272
|
+
if (url === undefined) throw new Error('creative preset is not installed');
|
|
273
|
+
return {
|
|
274
|
+
plugins: parseCreativeDocument(readFileSync(fileURLToPath(url), 'utf8')),
|
|
275
|
+
root: dirname(fileURLToPath(url)),
|
|
276
|
+
source: url,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
200
280
|
/** Prefer the running host's public preset registry, including its live composition. */
|
|
201
281
|
export async function loadCurrentPreset(registry) {
|
|
202
282
|
if (!process.env[PRESET_PATH_ENV]?.trim() && typeof registry?.readDocument === 'function') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deep-ptc-mode",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "Lightweight adaptive Deep PTC: live host presets, plugin cooperation and interruptible jobs. / 轻量自适配深度 PTC:动态宿主预设、插件协作与官方兜底、后台可插话。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"./guard": "./lib/guard.mjs",
|
|
70
70
|
"./tool-compatibility": "./lib/tool-compatibility.mjs",
|
|
71
71
|
"./environment": "./lib/environment.mjs",
|
|
72
|
+
"./lab": "./lib/lab.mjs",
|
|
72
73
|
"./client": "./lib/client.js",
|
|
73
74
|
"./package.json": "./package.json"
|
|
74
75
|
},
|