dsh-deep-ptc-mode 1.4.0 → 1.6.0

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/lib/terminal.mjs CHANGED
@@ -1,41 +1,36 @@
1
+ import z from '@deepseek-ai/schemastery';
1
2
  import { apply as applyBash } from '@deepseek-ai/dsh-tool-bash';
3
+ import { apply as applyPwsh } from '@deepseek-ai/dsh-tool-pwsh';
4
+ import { adaptContext, registering } from './adapt.mjs';
5
+ import { finishPromoted, steerableJobs, steerableTool, steeringWatch } from './reachable.mjs';
2
6
 
3
- export const name = 'deep-ptc-zsh-tool';
7
+ export const name = 'deep-ptc-terminal';
4
8
  export const inject = ['tools', 'shell', 'systemPrompt', 'shellEnv', 'workingDirectory'];
9
+ export const Config = z.object({
10
+ tool: z.union(['bash', 'pwsh']).required(),
11
+ dialect: z.union(['zsh']),
12
+ });
5
13
 
6
- // Keep the official execution, jobs and approval implementation; adapt its public dialect.
7
- export function apply(ctx) {
8
- const dialect = text => text.replace(/\bbash\b/gu, 'zsh').replace(/\bBash\b/gu, 'Zsh');
9
- const tools = new Proxy(ctx.tools, {
10
- get(target, key) {
11
- if (key === 'register') return definition => target.register({
12
- ...definition, name: definition.name === 'bash' ? 'zsh' : definition.name,
13
- description: dialect(definition.description),
14
- });
15
- const value = Reflect.get(target, key, target);
16
- return typeof value === 'function' ? value.bind(target) : value;
17
- },
14
+ // Keep the official execution, jobs and approval implementation. Foreground waits yield to user
15
+ // messages; the Zsh dialect only renames the bash tool's public face.
16
+ export function apply(ctx, config) {
17
+ const watch = steeringWatch(ctx);
18
+ const zsh = config.dialect === 'zsh';
19
+ const dialect = text => zsh ? text.replace(/\bbash\b/gu, 'zsh').replace(/\bBash\b/gu, 'Zsh') : text;
20
+ const adapted = adaptContext(ctx, {
21
+ tools: tools => registering(tools, definition => steerableTool({
22
+ ...definition,
23
+ ...zsh ? { name: definition.name === 'bash' ? 'zsh' : definition.name, description: dialect(definition.description) } : {},
24
+ }, finishPromoted)),
25
+ systemPrompt: prompt => zsh ? new Proxy(prompt, {
26
+ get(target, key) {
27
+ if (key === 'section') return section => target.section({ ...section,
28
+ name: section.name === 'tool:bash' ? 'tool:zsh' : section.name, text: dialect(section.text) });
29
+ const value = Reflect.get(target, key, target);
30
+ return typeof value === 'function' ? value.bind(target) : value;
31
+ },
32
+ }) : prompt,
33
+ jobs: jobs => steerableJobs(jobs, watch),
18
34
  });
19
- const systemPrompt = new Proxy(ctx.systemPrompt, {
20
- get(target, key) {
21
- if (key === 'section') return section => target.section({ ...section,
22
- name: section.name === 'tool:bash' ? 'tool:zsh' : section.name, text: dialect(section.text) });
23
- const value = Reflect.get(target, key, target);
24
- return typeof value === 'function' ? value.bind(target) : value;
25
- },
26
- });
27
- // A proxy preserves the real Cordis context for inject/effects, changing only the registry face.
28
- const adapted = new Proxy(ctx, {
29
- get(target, key) {
30
- if (key === 'tools') return tools;
31
- if (key === 'systemPrompt') return systemPrompt;
32
- const value = Reflect.get(target, key, target);
33
- if (key === 'inject') return (dependencies, callback) => target.inject(dependencies, child => {
34
- const wrapped = new Proxy(child, { get(c, k) { return k === 'tools' ? tools : Reflect.get(c, k, c); } });
35
- return callback(wrapped);
36
- });
37
- return typeof value === 'function' ? value.bind(target) : value;
38
- },
39
- });
40
- applyBash(adapted);
35
+ (config.tool === 'pwsh' ? applyPwsh : applyBash)(adapted, {});
41
36
  }
@@ -0,0 +1,169 @@
1
+ // Locate and parse the official PTC agent preset the installed dsh ships.
2
+ //
3
+ // Deep PTC derives its own preset from this declaration instead of freezing a
4
+ // copy: rows the official preset gains, renames or reconfigures are inherited,
5
+ // and the plugin only replaces the parts it actually owns (persona, execution
6
+ // environment, reachability guard, job/question wrappers).
7
+ import { createRequire } from 'node:module';
8
+ import { existsSync, readFileSync } from 'node:fs';
9
+ import { fileURLToPath, pathToFileURL } from 'node:url';
10
+ import { dirname, join, isAbsolute, resolve } from 'node:path';
11
+
12
+ export const OFFICIAL_PACKAGE = '@deepseek-ai/dsh-web-app';
13
+ const PACKAGE = OFFICIAL_PACKAGE;
14
+ const PRESET_PATH = 'presets/ptc.patch.yml';
15
+ /** Preset identity the plugin composes from. */
16
+ export const OFFICIAL_PRESET_ID = 'ptc';
17
+ /** Module specifier of the shipped declaration, resolvable through the host's runtime resolution. */
18
+ export const OFFICIAL_PRESET_SPECIFIER = `${PACKAGE}/${PRESET_PATH}`;
19
+ /** Diagnostics-only override, e.g. a snapshot path or a file URL. */
20
+ export const PRESET_PATH_ENV = 'DSH_DEEP_PTC_PRESET';
21
+
22
+ // The declaration is YAML, so the plugin needs js-yaml. In the desktop host
23
+ // the parser belongs to the installed runtime: load it through the runtime's
24
+ // module graph so a linked installation keeps working without its own
25
+ // node_modules. Peer-declaring the package (see package.json) is what lets the
26
+ // host route this bare specifier to the installation; the remaining strategies
27
+ // also cover a plain repository run and non-flat installs.
28
+ let yamlModule;
29
+ let yamlFailure;
30
+ function loadYaml() {
31
+ if (yamlModule !== undefined) return yamlModule;
32
+ try {
33
+ yamlModule = createRequire(import.meta.url)('js-yaml');
34
+ return yamlModule;
35
+ } catch (error) {
36
+ yamlFailure = error;
37
+ }
38
+ let packageFile;
39
+ try {
40
+ packageFile = fileURLToPath(import.meta.resolve(`${PACKAGE}/package.json`));
41
+ } catch (error) {
42
+ throw yamlFailure ?? error;
43
+ }
44
+ try {
45
+ yamlModule = createRequire(packageFile)('js-yaml');
46
+ return yamlModule;
47
+ } catch {
48
+ // The parser may be hoisted beside the runtime package instead.
49
+ }
50
+ let directory = dirname(packageFile);
51
+ while (true) {
52
+ const candidate = join(directory, 'node_modules', 'js-yaml', 'package.json');
53
+ if (existsSync(candidate)) {
54
+ yamlModule = createRequire(join(directory, 'node_modules', 'package.json'))('js-yaml');
55
+ return yamlModule;
56
+ }
57
+ const parent = dirname(directory);
58
+ if (parent === directory) break;
59
+ directory = parent;
60
+ }
61
+ throw yamlFailure;
62
+ }
63
+
64
+ /** YAML dialect of the Loader: `!!js` scalars stay expression nodes for the host to evaluate. */
65
+ export function presetSchema() {
66
+ const yaml = loadYaml();
67
+ const JsExpr = new yaml.Type('tag:yaml.org,2002:js', {
68
+ kind: 'scalar',
69
+ resolve: data => typeof data === 'string',
70
+ construct: data => ({ __jsExpr: data }),
71
+ });
72
+ return yaml.JSON_SCHEMA.extend(JsExpr);
73
+ }
74
+
75
+ /**
76
+ * Read the `ptc` agent-preset declaration out of a PTC patch document.
77
+ *
78
+ * The document is a list of patch layers; the declaration lives in an `insert`
79
+ * list. Future revisions may move it, so every layer is inspected, but only a
80
+ * declaration explicitly identified as `ptc` is accepted: composing Deep PTC
81
+ * from an unrelated preset would be worse than reporting the declaration
82
+ * missing.
83
+ * @param text - YAML source of the official PTC preset patch.
84
+ * @returns Parsed preset configuration (`{ id, order, plugins, ... }`).
85
+ */
86
+ export function parseOfficialPreset(text) {
87
+ const document = loadYaml().load(text, { schema: presetSchema() });
88
+ const layers = Array.isArray(document) ? document : [];
89
+ const inserted = [];
90
+ const collect = rows => {
91
+ if (!Array.isArray(rows)) return;
92
+ for (const row of rows) if (row && typeof row === 'object') inserted.push(row);
93
+ };
94
+ collect(layers);
95
+ for (const layer of layers) {
96
+ if (!layer || typeof layer !== 'object') continue;
97
+ collect(layer.insert);
98
+ }
99
+ const declarations = inserted
100
+ .map(row => row.config)
101
+ .filter(config => config && Array.isArray(config.plugins));
102
+ const preset = declarations.find(config => config.id === OFFICIAL_PRESET_ID);
103
+ if (!preset) {
104
+ const found = declarations.map(config => JSON.stringify(config.id ?? null)).join(', ');
105
+ throw new Error(`${OFFICIAL_PRESET_SPECIFIER} declares no agent preset with id "${OFFICIAL_PRESET_ID}"${found ? ` (found ${found})` : ''}`);
106
+ }
107
+ return preset;
108
+ }
109
+
110
+ function tryResolve(specifier) {
111
+ try {
112
+ return import.meta.resolve(specifier);
113
+ } catch {
114
+ return undefined;
115
+ }
116
+ }
117
+
118
+ function packageFileUrl() {
119
+ const direct = tryResolve(OFFICIAL_PRESET_SPECIFIER);
120
+ if (direct !== undefined) return direct;
121
+ for (const specifier of [`${PACKAGE}/package.json`, PACKAGE]) {
122
+ const url = tryResolve(specifier);
123
+ if (url === undefined) continue;
124
+ try {
125
+ const file = fileURLToPath(url);
126
+ if (file.endsWith('package.json')) return pathToFileURL(join(dirname(file), PRESET_PATH)).href;
127
+ // A package-root export may point at any file; the declaration sits beside the package.
128
+ let dir = dirname(file);
129
+ while (dir !== dirname(dir)) {
130
+ if (dir.endsWith(PACKAGE) || dir.endsWith(PACKAGE.replace('/', '-'))) break;
131
+ dir = dirname(dir);
132
+ }
133
+ return pathToFileURL(join(dir, PRESET_PATH)).href;
134
+ } catch {
135
+ // Try the next strategy.
136
+ }
137
+ }
138
+ return undefined;
139
+ }
140
+
141
+ /**
142
+ * Resolve the installed declaration to a file URL.
143
+ * @returns `file:` URL, or `undefined` when the runtime exposes none.
144
+ */
145
+ export function officialPresetUrl() {
146
+ const override = process.env[PRESET_PATH_ENV]?.trim();
147
+ if (override) {
148
+ if (override.startsWith('file:')) return override;
149
+ return pathToFileURL(isAbsolute(override) ? override : resolve(override)).href;
150
+ }
151
+ return packageFileUrl();
152
+ }
153
+
154
+ /**
155
+ * Load the official PTC preset from the installed runtime.
156
+ * @param options - `presetPath` reads one explicit file (path or file URL) instead of the runtime declaration.
157
+ * @returns The parsed preset and where it came from.
158
+ */
159
+ export function loadOfficialPreset({ presetPath } = {}) {
160
+ const url = presetPath === undefined
161
+ ? officialPresetUrl()
162
+ : presetPath instanceof URL ? presetPath.href
163
+ : pathToFileURL(isAbsolute(presetPath) ? presetPath : resolve(presetPath)).href;
164
+ if (url === undefined) {
165
+ throw new Error(`cannot resolve ${OFFICIAL_PRESET_SPECIFIER}; set ${PRESET_PATH_ENV} to its path`);
166
+ }
167
+ const text = readFileSync(fileURLToPath(url), 'utf8');
168
+ return { preset: parseOfficialPreset(text), source: url };
169
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-deep-ptc-mode",
3
- "version": "1.4.0",
4
- "description": "Deep PTC mode for DeepSeek Harness: no token rationing, stays interruptible while background jobs run, plans by task size (approval only for long tasks), asks instead of guessing intent, and runs commands in WSL, PowerShell, Zsh or Bash.",
3
+ "version": "1.6.0",
4
+ "description": "Deep PTC mode for DeepSeek Harness: no token rationing, code-enforced no-sleep (long commands move to the background and user messages interrupt waits), plans by task size (approval only for long tasks), asks instead of guessing intent, and runs commands in WSL, PowerShell, Zsh or Bash.",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "dsh-plugin",
@@ -10,7 +10,8 @@
10
10
  "ptc",
11
11
  "agent-team",
12
12
  "subagent",
13
- "clarification"
13
+ "clarification",
14
+ "background-jobs"
14
15
  ],
15
16
  "license": "MIT",
16
17
  "author": {
@@ -58,6 +59,9 @@
58
59
  ".": "./lib/index.mjs",
59
60
  "./executor": "./lib/executor.mjs",
60
61
  "./terminal": "./lib/terminal.mjs",
62
+ "./jobs-tool": "./lib/jobs-tool.mjs",
63
+ "./ask-user": "./lib/ask-user.mjs",
64
+ "./guard": "./lib/guard.mjs",
61
65
  "./environment": "./lib/environment.mjs",
62
66
  "./client": "./lib/client.js",
63
67
  "./package.json": "./package.json"
@@ -66,22 +70,22 @@
66
70
  "test": "node --test",
67
71
  "check": "node scripts/check.mjs",
68
72
  "check:upstream": "node scripts/check.mjs --upstream",
69
- "prepack": "npm run check && npm test"
70
- },
71
- "devDependencies": {
72
- "js-yaml": "4.3.2",
73
- "react": "18.3.1",
74
- "react-test-renderer": "18.3.1"
73
+ "prepack": "npm run check && npm test",
74
+ "sync:snapshot": "node scripts/sync-snapshot.mjs"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@deepseek-ai/schemastery": "^3.18.4",
78
78
  "@deepseek-ai/dsh-bash-local": ">=0.2.1-rc.5",
79
79
  "@deepseek-ai/dsh-bash-sandbox": ">=0.2.1-rc.5",
80
80
  "@deepseek-ai/dsh-tool-bash": ">=0.2.1-rc.5",
81
+ "@deepseek-ai/dsh-tool-pwsh": ">=0.2.1-rc.5",
82
+ "@deepseek-ai/dsh-tool-jobs": ">=0.2.1-rc.5",
83
+ "@deepseek-ai/dsh-tool-ask-user": ">=0.2.1-rc.5",
81
84
  "@deepseek-ai/dsh-client-ui-renderer": ">=0.2.1-rc.5",
82
85
  "@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-rc.5",
83
86
  "@deepseek-ai/dsh-client-ui-slots": ">=0.2.1-rc.5",
84
- "@deepseek-ai/dsh-client-locale": ">=0.2.1-rc.5"
87
+ "@deepseek-ai/dsh-client-locale": ">=0.2.1-rc.5",
88
+ "@deepseek-ai/dsh-web-app": ">=0.2.1-rc.5"
85
89
  },
86
90
  "peerDependenciesMeta": {
87
91
  "@deepseek-ai/schemastery": {
@@ -96,6 +100,15 @@
96
100
  "@deepseek-ai/dsh-tool-bash": {
97
101
  "optional": true
98
102
  },
103
+ "@deepseek-ai/dsh-tool-pwsh": {
104
+ "optional": true
105
+ },
106
+ "@deepseek-ai/dsh-tool-jobs": {
107
+ "optional": true
108
+ },
109
+ "@deepseek-ai/dsh-tool-ask-user": {
110
+ "optional": true
111
+ },
99
112
  "@deepseek-ai/dsh-client-ui-renderer": {
100
113
  "optional": true
101
114
  },
@@ -107,6 +120,16 @@
107
120
  },
108
121
  "@deepseek-ai/dsh-client-locale": {
109
122
  "optional": true
123
+ },
124
+ "@deepseek-ai/dsh-web-app": {
125
+ "optional": true
110
126
  }
127
+ },
128
+ "dependencies": {
129
+ "js-yaml": "4.3.2"
130
+ },
131
+ "devDependencies": {
132
+ "react": "18.3.1",
133
+ "react-test-renderer": "18.3.1"
111
134
  }
112
135
  }