dsh-deep-ptc-mode 1.7.1 → 1.7.3
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 +91 -63
- package/README.md +180 -174
- package/README.zh.md +195 -193
- package/TEST_REPORT.md +33 -0
- package/lib/ask-user.mjs +2 -1
- package/lib/client.js +46 -0
- package/lib/guard.mjs +2 -1
- package/lib/host.mjs +30 -13
- package/lib/index.mjs +47 -9
- package/lib/jobs-tool.mjs +2 -1
- package/lib/model.mjs +18 -16
- package/lib/official-names.mjs +115 -0
- package/lib/rules.mjs +5 -5
- package/lib/sleep-lint.mjs +391 -41
- package/lib/tool-catalog.mjs +45 -0
- package/lib/tool-compatibility.mjs +87 -4
- package/lib/tool-policy.mjs +193 -87
- package/lib/upstream.mjs +13 -0
- package/package.json +126 -120
- package/lib/official-tools.mjs +0 -8
package/lib/tool-policy.mjs
CHANGED
|
@@ -1,52 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const MAX_FAILURES = 8;
|
|
5
|
-
const MAX_NAMES = 12;
|
|
6
|
-
const validName = name => typeof name === 'string' && /^[\w.:-]{1,128}$/u.test(name);
|
|
1
|
+
import { DIRECTORY_TOOL, blankState, toolSchema, searchCatalog } from './tool-catalog.mjs';
|
|
2
|
+
const officialDefinitions = new WeakMap();
|
|
3
|
+
const validName = name => typeof name === 'string' && name.length > 0 && name.length <= 256 && !/[\u0000-\u001f]/u.test(name);
|
|
7
4
|
const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
+
export function markOfficialTool(definition, provider = 'official PTC') { officialDefinitions.set(definition, provider); return definition; }
|
|
6
|
+
export function isOfficialTool(definition) { return officialDefinitions.has(definition); }
|
|
7
|
+
export function officialToolSource(definition) { return officialDefinitions.get(definition); }
|
|
8
|
+
export const compatibilityPolicy = `## Efficient tool cooperation
|
|
9
|
+
- Search available external capabilities by function using deep_ptc_tools. Load only matching definitions; then use their actual schemas. If none fit, use an admitted official PTC tool. Provider discovery/loaders remain authoritative for provider-specific SDKs.
|
|
10
|
+
- When an external capability fails, read the error: correct wrong input, and retry a temporary failure at most twice. A capability that is unavailable or keeps failing is quarantined for this conversation. Unless the user asks you to investigate it, do not retry, probe, diagnose or repair a quarantined capability; promptly use a working equivalent or the official fallback and focus on finishing the task. Only the user's Reload all tool states button resets quarantine.
|
|
11
|
+
- At task completion, briefly list the failed tool names and their declared plugins (or unknown source) and say there may be a compatibility problem. Do not claim a root cause. Mention completed work first.
|
|
12
|
+
- Preserve authorization, cancellation, the selected shell and managed jobs. Empty results and running/background jobs are not failures. Before replacing a partially completed write or command, read only the task state needed to avoid duplicate effects; this is task recovery, not plugin diagnosis.
|
|
13
|
+
- Search skills through deep_ptc_tools(action=skills), then use the official loader named by loadWith and follow its full instructions. Reuse already-loaded instructions in the current context; discovery summaries are not skill instructions.
|
|
14
|
+
- Never bypass hidden tools, policy denials, cancelled work or an unavailable whole executor. Deep PTC's existing foreground/steering wrappers continue to govern official execution.`;
|
|
15
|
+
// Error text is only consulted when a failure carries no code. Plain throws are the common case for
|
|
16
|
+
// plugins, so these patterns separate a broken provider from wrong input and passing trouble.
|
|
17
|
+
const MISSING_TEXT = /is not a (?:function|constructor)|cannot find (?:module|package)|err_module_not_found|not implemented|cannot read propert(?:y|ies) of (?:undefined|null)/iu;
|
|
18
|
+
const DENIED_TEXT = /permission denied|eacces|eperm|forbidden|unauthori[sz]ed|\b40[13]\b/iu;
|
|
19
|
+
const INPUT_TEXT = /enoent|no such file|not found|does not exist|invalid|missing required|bad request|\b40[04]\b/iu;
|
|
20
|
+
const TEMPORARY_TEXT = /timed? ?out|timeout|etimedout|econnreset|econnrefused|eai_again|enotfound|socket hang up|network|fetch failed|rate.?limit|too many requests|\b429\b|\b50[234]\b|temporar|try again|overloaded/iu;
|
|
21
|
+
/** Consecutive unexplained or temporary failures before a capability is quarantined. */
|
|
22
|
+
export const QUARANTINE_STRIKES = 3;
|
|
23
|
+
const IMMEDIATE = new Set(['unavailable', 'partial']);
|
|
8
24
|
|
|
9
|
-
export function markOfficialTool(definition) {
|
|
10
|
-
officialDefinitions.add(definition);
|
|
11
|
-
return definition;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const compatibilityPolicy = `## Cooperate with tool plugins
|
|
15
|
-
|
|
16
|
-
- Tool selection has two layers. First search the available extension/plugin capabilities for the needed function, including the provider's own discovery/SDK loader when present; prefer a suitable working enhancement. Second, if that layer has no suitable capability or its tool fails, use the inherited official PTC capability as the fallback. Do not repeatedly rediscover or retry the same broken enhancement. Do not assume any plugin is installed or enabled.
|
|
17
|
-
- Use each provider's actual live schema and result contract; tool names, arguments, return values and execution environments are not interchangeable. A preference is a task-level routing choice, not an alias or permission to forward raw arguments between tools.
|
|
18
|
-
- The inherited official PTC tools are the baseline. If an enhancement is missing or fails, automatically continue the task with an available official tool that supports the operation; do not ask for permission merely to change a tool within the already-authorized task. Rebuild the call from that tool's real schema. No equivalent official capability means report the limitation instead of inventing one.
|
|
19
|
-
- A failed call may already have written files, submitted a request, or started a command/job. Before continuing a mutation, inspect its receipts and read back the relevant state; apply only the remaining work. Never replay a command just because its output or renderer failed. A background/promoted job is still running, not a failed call.
|
|
20
|
-
- Permission/approval denials, policy blocks and user cancellation remain authoritative: never switch tools, shells or credentials to evade them. Invalid arguments, missing input files and an ordinary nonzero command exit require diagnosis, not a claim that the provider is broken. Empty searches are valid results. Partial/truncated results require continuation or explicit coverage limits.
|
|
21
|
-
- Keep the selected execution environment and reachability rules. A plugin shell is not automatically the selected WSL/native shell. Use its real job and cancellation contract; prefer explicit background execution for long work. Do not claim Deep PTC's official-tool wait wrapper automatically controls every third-party executor.
|
|
22
|
-
- Keep official fallbacks available in the enhancement plugin's own configuration where supported. If another plugin or host policy hides or removes them, do not bypass its restrictions or call a captured private implementation. Explain the unavailable fallback and the configuration needed to restore it. This compatibility layer adds no tools and cannot repair an unloaded tool executor.`;
|
|
23
|
-
|
|
24
|
-
/** Only structured outcome metadata is interpreted; arbitrary result text is never prompt policy. */
|
|
25
25
|
export function classifyToolOutcome(exec, result) {
|
|
26
26
|
if (exec.signal?.aborted) return { kind: 'cancelled', effect: 'unknown' };
|
|
27
27
|
const value = object(result?.value) ? result.value : undefined;
|
|
28
28
|
if (value?.cancelled === true || ['cancelled', 'aborted'].includes(value?.status)) return { kind: 'cancelled', effect: 'unknown' };
|
|
29
29
|
if (value?.sandbox?.denied === true) return { kind: 'denied', effect: 'unknown' };
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
if (!result?.isError && value?.kind === 'foreground' && typeof value.exitCode === 'number' && value.exitCode !== 0)
|
|
33
|
-
return { kind: 'command', effect: 'unknown' };
|
|
34
|
-
const status = typeof value?.status === 'string' ? value.status.toLowerCase() : '';
|
|
30
|
+
// A call that returned is the tool working; its status field describes the tool's own subject (a
|
|
31
|
+
// failed build, an unavailable service). Only an explicit failure object reports on the tool itself.
|
|
35
32
|
const failure = object(value?.failure) ? value.failure : undefined;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
if (!result?.isError && !failure) {
|
|
34
|
+
return value?.kind === 'foreground' && typeof value.exitCode === 'number' && value.exitCode !== 0
|
|
35
|
+
? { kind: 'command', effect: 'unknown' } : undefined;
|
|
36
|
+
}
|
|
37
|
+
// The host reports a thrown HarnessError's code under error.info.
|
|
38
|
+
const rawCode = result?.error?.info?.code ?? result?.error?.code ?? failure?.code;
|
|
39
39
|
const code = typeof rawCode === 'string' && /^[A-Z0-9_:-]{1,96}$/u.test(rawCode) ? rawCode : '';
|
|
40
40
|
const effect = ['none', 'unknown', 'partial', 'completed'].includes(failure?.effectState)
|
|
41
41
|
? failure.effectState : 'unknown';
|
|
42
|
+
const status = typeof value?.status === 'string' ? value.status.toLowerCase() : '';
|
|
42
43
|
if (/ABORT|CANCEL/u.test(code) || status === 'cancelled') return { kind: 'cancelled', effect };
|
|
43
44
|
if (/DENIED|FORBIDDEN|POLICY|APPROVAL|PERMISSION|EACCES|EPERM|READ_ONLY/u.test(code))
|
|
44
45
|
return { kind: 'denied', effect };
|
|
46
|
+
if (code === 'ENOENT' && /\bspawn(?:sync)?\b[^\n]*\bENOENT\b/iu.test(String(result?.error?.message ?? failure?.message ?? ''))) return {kind:'unavailable',effect};
|
|
45
47
|
if (/ARGUMENT|INVALID_ARGS|VALIDATION|ENOENT|NOT_FOUND/u.test(code) && code !== 'UNKNOWN_TOOL')
|
|
46
48
|
return { kind: 'input', effect };
|
|
47
49
|
if (status === 'partial') return { kind: 'partial', effect };
|
|
48
50
|
if (/UNKNOWN_TOOL|UNAVAILABLE|WORKER_MISSING|RUNTIME_MISSING/u.test(code) || status === 'unavailable')
|
|
49
51
|
return { kind: 'unavailable', effect };
|
|
52
|
+
if (code) return { kind: /TIMEOUT|RATE|BUSY|OVERLOAD/u.test(code) ? 'temporary' : 'failure', effect };
|
|
53
|
+
const message = String(result?.error?.message ?? failure?.message ?? '');
|
|
54
|
+
if (MISSING_TEXT.test(message)) return { kind: 'unavailable', effect };
|
|
55
|
+
if (DENIED_TEXT.test(message)) return { kind: 'denied', effect };
|
|
56
|
+
if (TEMPORARY_TEXT.test(message)) return { kind: 'temporary', effect };
|
|
57
|
+
if (INPUT_TEXT.test(message)) return { kind: 'input', effect };
|
|
50
58
|
return { kind: 'failure', effect };
|
|
51
59
|
}
|
|
52
60
|
|
|
@@ -64,78 +72,176 @@ export function normalizePreferences(preferences = []) {
|
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
74
|
|
|
67
|
-
export function createCompatibilityState(tools, preferences = []) {
|
|
75
|
+
export function createCompatibilityState(tools, preferences = [], storage = {}, directory = {}) {
|
|
68
76
|
const routes = normalizePreferences(preferences);
|
|
69
|
-
let
|
|
70
|
-
let
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
let sessions = new WeakMap();
|
|
78
|
+
let calls = new WeakMap();
|
|
79
|
+
const sessionOf = agent => object(agent?.session) ? agent.session : agent;
|
|
80
|
+
function entry(agent) {
|
|
81
|
+
if (storage.read && !object(agent?.session)) return undefined;
|
|
82
|
+
const session = sessionOf(agent);
|
|
83
|
+
if (!object(session)) return undefined;
|
|
84
|
+
let row = sessions.get(session);
|
|
85
|
+
if (!row) { row = { state: storage.read?.(session) ?? blankState(), selected: new Set(), strikes: new Map() }; sessions.set(session, row); }
|
|
86
|
+
const current = storage.read?.(session);
|
|
87
|
+
if (current && current !== row.state) { if (current.epoch !== row.state.epoch) { row.selected.clear(); row.strikes.clear(); } row.state = current; }
|
|
88
|
+
return row;
|
|
89
|
+
}
|
|
90
|
+
function save(agent, row, state) {
|
|
91
|
+
storage.write?.(sessionOf(agent), state); // Persist first: an unsuccessful reset never clears quarantine.
|
|
92
|
+
row.state = state;
|
|
93
|
+
}
|
|
94
|
+
function definitions(agent, toolSet) { return tools.definitions(agent, toolSet).filter(def => validName(def.name)); }
|
|
95
|
+
// Unknown ownership is deliberately fail-open. Source scraping can miss dynamic official
|
|
96
|
+
// registrations; only a positively attributed external provider may be quarantined or hidden.
|
|
97
|
+
const declaredExternal = def => typeof def?.deepPtc?.provider === 'string' && !def.deepPtc.provider.startsWith('@deepseek-ai/');
|
|
98
|
+
const official = def => !!def && (isOfficialTool(def) || (!declaredExternal(def) && directory.isOfficial?.(def.name) === true));
|
|
99
|
+
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/')));
|
|
100
|
+
const protectedName = (agent, name) => {
|
|
101
|
+
const def = tools.get(name, agent);
|
|
102
|
+
return def ? !external(def) : directory.isOfficial?.(name) === true;
|
|
74
103
|
};
|
|
75
|
-
|
|
76
|
-
|
|
104
|
+
const usableState = agent => {
|
|
105
|
+
const state = entry(agent)?.state ?? blankState();
|
|
106
|
+
const filter = rows => rows.filter(row => !protectedName(agent, row.name));
|
|
107
|
+
return { ...state, blocked: filter(state.blocked), report: state.report ? {...state.report,tools:filter(state.report.tools)} : null };
|
|
108
|
+
};
|
|
109
|
+
const blocked = (agent, name) => !protectedName(agent, name) && entry(agent)?.state.blocked.some(row => row.name === name) === true;
|
|
110
|
+
// Most official tools are known by the name their module declares; the feature wrappers also mark theirs.
|
|
111
|
+
|
|
112
|
+
const providerOf = def => officialDefinitions.get(def) ?? (typeof def?.deepPtc?.provider === 'string' ? def.deepPtc.provider.slice(0, 160) : undefined) ?? directory.providerOf?.(def?.name) ?? 'unknown plugin';
|
|
113
|
+
const api = {
|
|
114
|
+
dispatched(exec) {
|
|
115
|
+
const row = entry(exec.agent);
|
|
116
|
+
if (!row || calls.has(exec)) return;
|
|
117
|
+
const cleaned=usableState(exec.agent);
|
|
118
|
+
if(JSON.stringify(cleaned)!==JSON.stringify(row.state)) save(exec.agent,row,cleaned);
|
|
119
|
+
const definition = tools.get(exec.name, exec.agent, exec.toolSet);
|
|
120
|
+
calls.set(exec, { epoch: row.state.epoch, definition, official: !external(definition), provider: providerOf(definition) });
|
|
121
|
+
},
|
|
122
|
+
guard(exec) { return blocked(exec.agent, exec.name) ? `Deep PTC: ${JSON.stringify(exec.name)} is quarantined in this conversation. Do not retry or diagnose it. Continue with another admitted equivalent or official tool. Only the user can reload all tool states.` : undefined; },
|
|
77
123
|
observe(exec, result) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
124
|
+
const call = calls.get(exec);
|
|
125
|
+
// 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;
|
|
127
|
+
const row = entry(exec.agent);
|
|
128
|
+
if (!row || call.epoch !== row.state.epoch || blocked(exec.agent, exec.name)) return;
|
|
129
|
+
const outcome = classifyToolOutcome(exec, result);
|
|
130
|
+
if (!outcome) { row.strikes.delete(exec.name); return; }
|
|
131
|
+
// Authorization and cancelled actions must never be converted to provider failover, and wrong
|
|
132
|
+
// input says nothing about the tool.
|
|
133
|
+
if (['denied', 'cancelled', 'command', 'input'].includes(outcome.kind)) return;
|
|
134
|
+
if (!IMMEDIATE.has(outcome.kind)) {
|
|
135
|
+
const strikes = (row.strikes.get(exec.name) ?? 0) + 1;
|
|
136
|
+
row.strikes.set(exec.name, strikes);
|
|
137
|
+
if (strikes < QUARANTINE_STRIKES) return;
|
|
138
|
+
}
|
|
139
|
+
const failure = { name: exec.name, provider: call.provider, kind: outcome.kind };
|
|
140
|
+
save(exec.agent, row, { ...row.state, blocked: [...row.state.blocked, failure] });
|
|
141
|
+
row.strikes.delete(exec.name);
|
|
142
|
+
row.selected.delete(exec.name);
|
|
143
|
+
},
|
|
144
|
+
reset(agent) {
|
|
145
|
+
const row = entry(agent);
|
|
146
|
+
if (!row) throw new Error('No conversation is active');
|
|
147
|
+
const count = row.state.blocked.length;
|
|
148
|
+
save(agent, row, { ...blankState(), epoch: row.state.epoch + 1 });
|
|
149
|
+
row.selected.clear();
|
|
150
|
+
row.strikes.clear();
|
|
151
|
+
return count;
|
|
152
|
+
},
|
|
153
|
+
status(agent) { return usableState(agent); },
|
|
154
|
+
sdkDefinitions(agent, toolSet, compact = true) {
|
|
155
|
+
const row = entry(agent);
|
|
156
|
+
const excluded = new Set(usableState(agent).blocked.map(item => item.name));
|
|
157
|
+
return definitions(agent, toolSet).filter(def => !excluded.has(def.name)
|
|
158
|
+
&& (!compact || !external(def) || def.name === DIRECTORY_TOOL || row?.selected.has(def.name)));
|
|
159
|
+
},
|
|
160
|
+
search(agent, args, toolSet) {
|
|
161
|
+
const excluded = new Set(usableState(agent).blocked.map(item => item.name));
|
|
162
|
+
const visible = definitions(agent, toolSet).filter(def => def.name !== DIRECTORY_TOOL && !excluded.has(def.name));
|
|
163
|
+
const externalTools = visible.filter(external);
|
|
164
|
+
const result = searchCatalog(externalTools, args.query, args.offset, args.limit);
|
|
165
|
+
if (result.total) return { layer: 'external', ...result };
|
|
166
|
+
const baseline=searchCatalog(visible.filter(official),args.query,args.offset,args.limit);
|
|
167
|
+
if(baseline.total)return {layer:'official',...baseline};
|
|
168
|
+
return {layer:'unattributed',...searchCatalog(visible.filter(def=>!external(def)&&!official(def)),args.query,args.offset,args.limit)};
|
|
169
|
+
},
|
|
170
|
+
load(agent, names, toolSet) {
|
|
171
|
+
if (!Array.isArray(names) || names.length < 1 || names.length > 6 || names.some(name => !validName(name))) throw new Error('Load 1–6 exact tool names');
|
|
172
|
+
const live = new Map(definitions(agent, toolSet).map(def => [def.name, def]));
|
|
173
|
+
const row = entry(agent);
|
|
174
|
+
if (!row) throw new Error('No conversation is active');
|
|
175
|
+
let budget = 16000;
|
|
176
|
+
const loaded = [], unavailable = [], deferred = [];
|
|
177
|
+
for (const name of new Set(names)) {
|
|
178
|
+
const def = live.get(name);
|
|
179
|
+
if (!def || blocked(agent, name) || name === DIRECTORY_TOOL) { unavailable.push(name); continue; }
|
|
180
|
+
const schema = toolSchema(def);
|
|
181
|
+
const size = Buffer.byteLength(JSON.stringify(schema), 'utf8');
|
|
182
|
+
if (size > budget) { row.selected.add(name); if(row.selected.size>12)row.selected.delete(row.selected.values().next().value); deferred.push(name); continue; }
|
|
183
|
+
budget -= size;
|
|
184
|
+
row.selected.delete(name);
|
|
185
|
+
row.selected.add(name);
|
|
186
|
+
if (row.selected.size > 12) row.selected.delete(row.selected.values().next().value);
|
|
187
|
+
loaded.push(schema);
|
|
188
|
+
}
|
|
189
|
+
return { loaded, unavailable, deferred, nextStep: true, note: 'Deferred names are selected and will appear in full in the next host SDK. Unavailable names are hidden or quarantined. No tool was executed. Use an equivalent or load fewer definitions.' };
|
|
93
190
|
},
|
|
94
191
|
text({ scope: agent, toolSet } = {}) {
|
|
95
192
|
if (!object(agent)) return '';
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
for (const [name, failure] of rows ?? []) {
|
|
100
|
-
let current;
|
|
101
|
-
try { current = tools.get(name, agent); } catch { /* unavailable */ }
|
|
102
|
-
if (current !== failure.definition) rows.delete(name);
|
|
103
|
-
}
|
|
104
|
-
const unhealthy = name => ['failure', 'unavailable'].includes(rows?.get(name)?.kind);
|
|
105
|
-
const official = live.filter(def => officialDefinitions.has(def)).map(def => def.name).slice(0, MAX_NAMES);
|
|
106
|
-
const enhancements = live.filter(def => !officialDefinitions.has(def) && def.name !== 'run_code' && !unhealthy(def.name)).map(def => def.name).slice(0, MAX_NAMES);
|
|
193
|
+
const row = entry(agent);
|
|
194
|
+
if (!row) return '';
|
|
195
|
+
const state = usableState(agent);
|
|
107
196
|
const lines = [];
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
197
|
+
if (state.blocked.length) {
|
|
198
|
+
lines.push('Quarantined for this conversation; no retries or diagnosis. Finish the task using working equivalents. At completion briefly report these tool/plugin names and a possible compatibility problem:');
|
|
199
|
+
lines.push(JSON.stringify(state.blocked.slice(0, 8).map(({name,provider}) => ({name,provider}))));
|
|
200
|
+
if (state.blocked.length > 8) lines.push(`${state.blocked.length} tools total; the user interface retains the full list.`);
|
|
201
|
+
lines.push('Check only necessary task state before replacing a possibly partial mutation. Reset is a user action.');
|
|
113
202
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
else if (failure.kind === 'not-dispatched') lines.push(`${label}: not dispatched. Check the original policy/guard/approval or preparation result; do not assume provider failure or switch tools around a denial.`);
|
|
118
|
-
else if (failure.kind === 'cancelled') lines.push(`${label}: cancelled. Do not retry or fall back unless the user authorizes continuing.`);
|
|
119
|
-
else if (failure.kind === 'input') lines.push(`${label}: input/argument failure. Diagnose the call and actual schema before choosing a recovery.`);
|
|
120
|
-
else if (failure.kind === 'command') lines.push(`${label}: foreground command exited unsuccessfully. Diagnose the command and its effects; do not switch shells or treat a nonzero exit alone as provider failure.`);
|
|
121
|
-
else if (failure.kind === 'partial') lines.push(`${label}: partial completion. Preserve completed work and inspect continuation/receipts before completing the remainder.`);
|
|
122
|
-
else if (failure.official) lines.push(`${label}: official fallback failed. Diagnose the actual error and effects; do not loop through the same failed call. Report a precise blocker if no other appropriate admitted capability exists.`);
|
|
123
|
-
else lines.push(`${label}: ${failure.kind}; reported effect state ${failure.effect}. Continue with an equivalent admitted official tool when possible. Inspect state before any mutation/command retry; never copy arguments between schemas.`);
|
|
203
|
+
const available = routes.length ? new Set(definitions(agent, toolSet).map(def => def.name)) : new Set();
|
|
204
|
+
for (const route of routes) {
|
|
205
|
+
if (available.has(route.preferred) && !blocked(agent, route.preferred)) lines.push(`Prefer ${JSON.stringify(route.preferred)} when applicable; visible equivalents: ${JSON.stringify(route.fallback.filter(name => available.has(name) && !blocked(agent, name)))}. Read live schemas.`);
|
|
124
206
|
}
|
|
125
|
-
if (!lines.length) return '';
|
|
126
|
-
lines.push(`Layer 2: visible official baseline tools (bounded list): ${JSON.stringify(official)}. Use an appropriate fallback when layer 1 has no matching working capability. Missing/hidden/step-inactive tools are unavailable; this layer never lifts restrictions.`);
|
|
127
207
|
return lines.join('\n');
|
|
128
208
|
},
|
|
129
|
-
dispose() {
|
|
209
|
+
dispose() { sessions = new WeakMap(); calls = new WeakMap(); },
|
|
130
210
|
};
|
|
211
|
+
return api;
|
|
131
212
|
}
|
|
132
213
|
|
|
133
|
-
|
|
214
|
+
// A failure in this layer must leave tool calls and prompts as the host would have them.
|
|
215
|
+
export function failOpen(ctx, label, fn, fallback) {
|
|
216
|
+
let warned = false;
|
|
217
|
+
return (...args) => {
|
|
218
|
+
try {
|
|
219
|
+
return fn(...args);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (!warned) {
|
|
222
|
+
warned = true;
|
|
223
|
+
ctx.logger?.warn?.('Deep PTC: %s failed (%s); continuing without it', label, error?.message);
|
|
224
|
+
}
|
|
225
|
+
return fallback;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function installToolCompatibility(ctx, { enabled = true, preferences = [], storage, directory } = {}) {
|
|
134
231
|
if (!enabled) return;
|
|
135
|
-
const state = createCompatibilityState(ctx.tools, preferences);
|
|
232
|
+
const state = createCompatibilityState(ctx.tools, preferences, storage, directory);
|
|
233
|
+
const guard = failOpen(ctx, 'tool quarantine check', exec => state.guard(exec));
|
|
234
|
+
const dispatched = failOpen(ctx, 'tool call tracking', exec => state.dispatched(exec));
|
|
136
235
|
ctx.systemPrompt.section({ name: 'deep-ptc:tool-compatibility', order: 10194, text: compatibilityPolicy });
|
|
137
|
-
ctx.systemPrompt.context({ name: 'deep-ptc:tool-recovery', order: 122, text: context => state.text(context) });
|
|
138
|
-
ctx.
|
|
139
|
-
ctx.on('tools/
|
|
236
|
+
ctx.systemPrompt.context({ name: 'deep-ptc:tool-recovery', order: 122, text: failOpen(ctx, 'tool recovery context', context => state.text(context), '') });
|
|
237
|
+
ctx.tools.guard(guard);
|
|
238
|
+
ctx.on('tools/execute', (exec, next) => {
|
|
239
|
+
const reason = guard(exec);
|
|
240
|
+
if (reason) return Promise.resolve({ isError: true, error: { message: reason }, content: [{ type: 'text', text: reason }] });
|
|
241
|
+
dispatched(exec);
|
|
242
|
+
return next();
|
|
243
|
+
});
|
|
244
|
+
ctx.on('tools/result', failOpen(ctx, 'tool result tracking', (exec, result) => state.observe(exec, result)));
|
|
140
245
|
ctx.effect(() => () => state.dispose());
|
|
246
|
+
return state;
|
|
141
247
|
}
|
package/lib/upstream.mjs
CHANGED
|
@@ -196,3 +196,16 @@ export function loadOfficialPreset({ presetPath } = {}) {
|
|
|
196
196
|
const text = readFileSync(fileURLToPath(url), 'utf8');
|
|
197
197
|
return { preset: parseOfficialPreset(text), source: url };
|
|
198
198
|
}
|
|
199
|
+
|
|
200
|
+
/** Prefer the running host's public preset registry, including its live composition. */
|
|
201
|
+
export async function loadCurrentPreset(registry) {
|
|
202
|
+
if (!process.env[PRESET_PATH_ENV]?.trim() && typeof registry?.readDocument === 'function') {
|
|
203
|
+
try {
|
|
204
|
+
const document=await registry.readDocument(OFFICIAL_PRESET_ID);
|
|
205
|
+
const plugins=loadYaml().load(document.content,{schema:presetSchema()});
|
|
206
|
+
if(!Array.isArray(plugins)||plugins.length===0)throw new Error('empty official composition');
|
|
207
|
+
return {preset:{id:OFFICIAL_PRESET_ID,name:document.name,description:document.description,plugins},source:'agentPresets.readDocument(ptc)'};
|
|
208
|
+
} catch { /* Older/initializing registries fall back to installed declaration discovery. */ }
|
|
209
|
+
}
|
|
210
|
+
return loadOfficialPreset();
|
|
211
|
+
}
|
package/package.json
CHANGED
|
@@ -1,120 +1,126 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-deep-ptc-mode",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"description": "
|
|
5
|
-
"type": "module",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"dsh-plugin",
|
|
8
|
-
"deepseek-harness",
|
|
9
|
-
"agent-preset",
|
|
10
|
-
"ptc",
|
|
11
|
-
"agent-team",
|
|
12
|
-
"subagent",
|
|
13
|
-
"clarification",
|
|
14
|
-
"background-jobs",
|
|
15
|
-
"plugin-compatibility",
|
|
16
|
-
"tool-cooperation",
|
|
17
|
-
"official-ptc-fallback"
|
|
18
|
-
],
|
|
19
|
-
"license": "MIT",
|
|
20
|
-
"author": {
|
|
21
|
-
"name": "lishize20040802-rgb",
|
|
22
|
-
"email": "lishize20040802@gmail.com",
|
|
23
|
-
"url": "https://github.com/lishize20040802-rgb"
|
|
24
|
-
},
|
|
25
|
-
"repository": {
|
|
26
|
-
"type": "git",
|
|
27
|
-
"url": "git+https://github.com/lishize20040802-rgb/dsh-deep-ptc-mode.git"
|
|
28
|
-
},
|
|
29
|
-
"homepage": "https://github.com/lishize20040802-rgb/dsh-deep-ptc-mode#readme",
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/lishize20040802-rgb/dsh-deep-ptc-mode/issues"
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"cordis.patch.yml",
|
|
35
|
-
"lib",
|
|
36
|
-
"compatibility.json",
|
|
37
|
-
"README.md",
|
|
38
|
-
"README.zh.md",
|
|
39
|
-
"CHANGELOG.md",
|
|
40
|
-
"assets/icon.png"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
"@deepseek-ai/dsh-client-
|
|
56
|
-
"@deepseek-ai/dsh-client-ui-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"./
|
|
66
|
-
"./
|
|
67
|
-
"./
|
|
68
|
-
"./
|
|
69
|
-
"./
|
|
70
|
-
"./
|
|
71
|
-
"./
|
|
72
|
-
"./
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
"check
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"@deepseek-ai/
|
|
85
|
-
"@deepseek-ai/dsh-client-ui-
|
|
86
|
-
"@deepseek-ai/dsh-client-
|
|
87
|
-
"@deepseek-ai/dsh-
|
|
88
|
-
"@deepseek-ai/dsh-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
"@deepseek-ai/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"@deepseek-ai/
|
|
95
|
-
"optional": true
|
|
96
|
-
},
|
|
97
|
-
"@deepseek-ai/dsh-client-ui-
|
|
98
|
-
"optional": true
|
|
99
|
-
},
|
|
100
|
-
"@deepseek-ai/dsh-client-ui-
|
|
101
|
-
"optional": true
|
|
102
|
-
},
|
|
103
|
-
"@deepseek-ai/dsh-client-
|
|
104
|
-
"optional": true
|
|
105
|
-
},
|
|
106
|
-
"@deepseek-ai/dsh-
|
|
107
|
-
"optional": true
|
|
108
|
-
},
|
|
109
|
-
"@deepseek-ai/dsh-
|
|
110
|
-
"optional": true
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-deep-ptc-mode",
|
|
3
|
+
"version": "1.7.3",
|
|
4
|
+
"description": "Lightweight adaptive Deep PTC: live host presets, plugin cooperation and interruptible jobs. / 轻量自适配深度 PTC:动态宿主预设、插件协作与官方兜底、后台可插话。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"dsh-plugin",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"agent-preset",
|
|
10
|
+
"ptc",
|
|
11
|
+
"agent-team",
|
|
12
|
+
"subagent",
|
|
13
|
+
"clarification",
|
|
14
|
+
"background-jobs",
|
|
15
|
+
"plugin-compatibility",
|
|
16
|
+
"tool-cooperation",
|
|
17
|
+
"official-ptc-fallback"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "lishize20040802-rgb",
|
|
22
|
+
"email": "lishize20040802@gmail.com",
|
|
23
|
+
"url": "https://github.com/lishize20040802-rgb"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/lishize20040802-rgb/dsh-deep-ptc-mode.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/lishize20040802-rgb/dsh-deep-ptc-mode#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/lishize20040802-rgb/dsh-deep-ptc-mode/issues"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"cordis.patch.yml",
|
|
35
|
+
"lib",
|
|
36
|
+
"compatibility.json",
|
|
37
|
+
"README.md",
|
|
38
|
+
"README.zh.md",
|
|
39
|
+
"CHANGELOG.md",
|
|
40
|
+
"assets/icon.png",
|
|
41
|
+
"TEST_REPORT.md"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=24",
|
|
45
|
+
"dsh": ">=0.2.2-rc.1"
|
|
46
|
+
},
|
|
47
|
+
"dsh": {
|
|
48
|
+
"manifestVersion": 1,
|
|
49
|
+
"bundle": {
|
|
50
|
+
"patch": "./cordis.patch.yml"
|
|
51
|
+
},
|
|
52
|
+
"client": {
|
|
53
|
+
"platform": "web",
|
|
54
|
+
"inject": [
|
|
55
|
+
"@deepseek-ai/dsh-client-locale",
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-commands"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"main": "lib/index.mjs",
|
|
63
|
+
"exports": {
|
|
64
|
+
".": "./lib/index.mjs",
|
|
65
|
+
"./executor": "./lib/executor.mjs",
|
|
66
|
+
"./terminal": "./lib/terminal.mjs",
|
|
67
|
+
"./jobs-tool": "./lib/jobs-tool.mjs",
|
|
68
|
+
"./ask-user": "./lib/ask-user.mjs",
|
|
69
|
+
"./guard": "./lib/guard.mjs",
|
|
70
|
+
"./tool-compatibility": "./lib/tool-compatibility.mjs",
|
|
71
|
+
"./environment": "./lib/environment.mjs",
|
|
72
|
+
"./client": "./lib/client.js",
|
|
73
|
+
"./package.json": "./package.json"
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"test": "node --test",
|
|
77
|
+
"check": "node scripts/check.mjs",
|
|
78
|
+
"check:upstream": "node scripts/check.mjs --upstream",
|
|
79
|
+
"check:parity": "node scripts/check-parity.mjs",
|
|
80
|
+
"prepack": "npm run check && npm test",
|
|
81
|
+
"sync:snapshot": "node scripts/sync-snapshot.mjs"
|
|
82
|
+
},
|
|
83
|
+
"peerDependencies": {
|
|
84
|
+
"@deepseek-ai/schemastery": "^3.18.4",
|
|
85
|
+
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.2-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.2-rc.1",
|
|
87
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.2-rc.1",
|
|
88
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.2-rc.1",
|
|
89
|
+
"@deepseek-ai/dsh-web-app": ">=0.2.2-rc.1",
|
|
90
|
+
"@deepseek-ai/dsh-base": ">=0.2.2-rc.1",
|
|
91
|
+
"@deepseek-ai/dsh-client-ui-commands": ">=0.2.2-rc.1"
|
|
92
|
+
},
|
|
93
|
+
"peerDependenciesMeta": {
|
|
94
|
+
"@deepseek-ai/schemastery": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"@deepseek-ai/dsh-client-ui-renderer": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"@deepseek-ai/dsh-client-ui-settings": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"@deepseek-ai/dsh-client-ui-slots": {
|
|
104
|
+
"optional": true
|
|
105
|
+
},
|
|
106
|
+
"@deepseek-ai/dsh-client-locale": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"@deepseek-ai/dsh-web-app": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"@deepseek-ai/dsh-base": {
|
|
113
|
+
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"@deepseek-ai/dsh-client-ui-commands": {
|
|
116
|
+
"optional": true
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"dependencies": {
|
|
120
|
+
"js-yaml": "4.3.2"
|
|
121
|
+
},
|
|
122
|
+
"devDependencies": {
|
|
123
|
+
"react": "18.3.1",
|
|
124
|
+
"react-test-renderer": "18.3.1"
|
|
125
|
+
}
|
|
126
|
+
}
|
package/lib/official-tools.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import z from '@deepseek-ai/schemastery';
|
|
2
|
-
import { applyOfficial } from './host.mjs';
|
|
3
|
-
|
|
4
|
-
export const name = 'deep-ptc-official-tools';
|
|
5
|
-
export const inject = [];
|
|
6
|
-
export const Config = z.object({ upstream: z.string().required(), options: z.any() });
|
|
7
|
-
// Preserve official schemas, bodies, options and lifecycle; record their provenance for recovery.
|
|
8
|
-
export function apply(ctx, config) { return applyOfficial(ctx, config.upstream, config.options, child => child); }
|