dsh-deep-ptc-mode 1.8.2 → 1.8.6
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 +51 -0
- package/LICENSE +0 -0
- package/README.md +43 -10
- package/README.zh.md +43 -10
- package/TEST_REPORT.md +0 -0
- package/assets/icon.png +0 -0
- package/compatibility.json +0 -0
- package/cordis.patch.yml +0 -0
- package/lib/adapt.mjs +0 -0
- package/lib/ask-user.mjs +0 -0
- package/lib/base-snapshot.json +0 -0
- package/lib/client.js +1123 -25
- package/lib/creative.mjs +0 -0
- package/lib/environment.mjs +0 -0
- package/lib/executor.mjs +0 -0
- package/lib/freshness.mjs +31 -0
- package/lib/guard.mjs +0 -0
- package/lib/host.mjs +0 -0
- package/lib/index.mjs +45 -16
- package/lib/jobs-tool.mjs +0 -0
- package/lib/lab.mjs +0 -0
- package/lib/lifecycle.mjs +0 -0
- package/lib/model.mjs +0 -0
- package/lib/official-names.mjs +0 -0
- package/lib/preset-compat.mjs +5 -3
- package/lib/preset.json +2 -2
- package/lib/reachable.mjs +0 -0
- package/lib/resident.mjs +0 -0
- package/lib/rules.mjs +0 -0
- package/lib/shells.mjs +0 -0
- package/lib/skill-card.mjs +217 -0
- package/lib/skill-context.mjs +89 -0
- package/lib/sleep-lint.mjs +0 -0
- package/lib/terminal.mjs +0 -0
- package/lib/tool-catalog.mjs +0 -0
- package/lib/tool-compatibility.mjs +14 -14
- package/lib/tool-policy.mjs +7 -2
- package/lib/tool-state.mjs +51 -0
- package/package.json +2 -1
package/lib/tool-policy.mjs
CHANGED
|
@@ -17,6 +17,9 @@ export const compatibilityPolicy = `## Efficient tool cooperation
|
|
|
17
17
|
// plugins, so these patterns separate a broken provider from wrong input and passing trouble.
|
|
18
18
|
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;
|
|
19
19
|
const DENIED_TEXT = /permission denied|eacces|eperm|forbidden|unauthori[sz]ed|\b40[13]\b/iu;
|
|
20
|
+
// A command the tool ran is not installed. Not wrong input, and not proof that the tool itself is broken
|
|
21
|
+
// (an external shell tool may simply run a missing command), so it counts as a strike.
|
|
22
|
+
const MISSING_COMMAND_TEXT = /command not found|not recognized as an internal or external command|is not recognized as the name of a cmdlet/iu;
|
|
20
23
|
const INPUT_TEXT = /enoent|no such file|not found|does not exist|invalid|missing required|bad request|\b40[04]\b/iu;
|
|
21
24
|
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;
|
|
22
25
|
/** Consecutive unexplained or temporary failures before a capability is quarantined. */
|
|
@@ -44,14 +47,16 @@ export function classifyToolOutcome(exec, result) {
|
|
|
44
47
|
if (/ABORT|CANCEL/u.test(code) || status === 'cancelled') return { kind: 'cancelled', effect };
|
|
45
48
|
if (/DENIED|FORBIDDEN|POLICY|APPROVAL|PERMISSION|EACCES|EPERM|READ_ONLY/u.test(code))
|
|
46
49
|
return { kind: 'denied', effect };
|
|
47
|
-
|
|
50
|
+
const message = String(result?.error?.message ?? failure?.message ?? '');
|
|
51
|
+
// The tool could not start its own program: the provider is incompletely installed.
|
|
52
|
+
if ((code === 'ENOENT' || code === '') && /\bspawn(?:sync)?\b[^\n]*\bENOENT\b/iu.test(message)) return { kind: 'unavailable', effect };
|
|
53
|
+
if (MISSING_COMMAND_TEXT.test(message)) return { kind: 'failure', effect };
|
|
48
54
|
if (/ARGUMENT|INVALID_ARGS|VALIDATION|ENOENT|NOT_FOUND/u.test(code) && code !== 'UNKNOWN_TOOL')
|
|
49
55
|
return { kind: 'input', effect };
|
|
50
56
|
if (status === 'partial') return { kind: 'partial', effect };
|
|
51
57
|
if (/UNKNOWN_TOOL|UNAVAILABLE|WORKER_MISSING|RUNTIME_MISSING/u.test(code) || status === 'unavailable')
|
|
52
58
|
return { kind: 'unavailable', effect };
|
|
53
59
|
if (code) return { kind: /TIMEOUT|RATE|BUSY|OVERLOAD/u.test(code) ? 'temporary' : 'failure', effect };
|
|
54
|
-
const message = String(result?.error?.message ?? failure?.message ?? '');
|
|
55
60
|
if (MISSING_TEXT.test(message)) return { kind: 'unavailable', effect };
|
|
56
61
|
if (DENIED_TEXT.test(message)) return { kind: 'denied', effect };
|
|
57
62
|
if (TEMPORARY_TEXT.test(message)) return { kind: 'temporary', effect };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { importHost } from './host.mjs';
|
|
2
|
+
import { RESET_COMMAND, STATE_EVENT, STATE_KEY, blankState, parseState, foldToolState } from './tool-catalog.mjs';
|
|
3
|
+
|
|
4
|
+
// The tool state and its reset command live at the plugin root, like the skill card. A preset-scoped
|
|
5
|
+
// projection or command exists only while a session's agent is loaded, so the side card could neither
|
|
6
|
+
// read the state nor reset it in an idle conversation. The preset layer reuses the root projection and
|
|
7
|
+
// registers its own only when the root one is unavailable.
|
|
8
|
+
const ROOT = Symbol.for('dsh-deep-ptc-mode/tool-state');
|
|
9
|
+
const DEEP_PTC = 'deep-ptc';
|
|
10
|
+
export const resetText = count => `已重载本对话全部工具状态,清除 ${count} 个故障标记。正在运行的任务继续执行。 / All tool states reloaded for this conversation; ${count} quarantine marks cleared. Running jobs continue.`;
|
|
11
|
+
|
|
12
|
+
export function registerState(ctx) {
|
|
13
|
+
const schema = { parse: parseState };
|
|
14
|
+
return ctx.sessionProjections.register({ key: STATE_KEY, stateVersion: 1,
|
|
15
|
+
stateSchema: schema, init: blankState, apply: foldToolState,
|
|
16
|
+
wire: { viewSchema: schema, view: state => state, summary: false } });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function sessionRecords() {
|
|
20
|
+
const { appendPluginRecord } = await importHost('@deepseek-ai/dsh-session');
|
|
21
|
+
if (typeof appendPluginRecord !== 'function') throw new Error('the installed session module has no appendPluginRecord');
|
|
22
|
+
return appendPluginRecord;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function applyRoot(ctx) {
|
|
26
|
+
return ctx.plugin({ name: 'deep-ptc-tool-state', inject: ['commands', 'sessionProjections'], apply: installRoot }).await()
|
|
27
|
+
.catch(error => ctx.logger.warn('Deep PTC: root tool state is off (%s); the preset layer keeps its own', error.message));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function installRoot(ctx, records = sessionRecords) {
|
|
31
|
+
const appendPluginRecord = await records();
|
|
32
|
+
const projection = await registerState(ctx);
|
|
33
|
+
const handle = { projection, write: (session, value) => appendPluginRecord(session, STATE_EVENT, value) };
|
|
34
|
+
globalThis[ROOT] = handle;
|
|
35
|
+
ctx.effect(() => () => { projection.dispose(); if (globalThis[ROOT] === handle) delete globalThis[ROOT]; });
|
|
36
|
+
ctx.commands.register({ name: RESET_COMMAND, description: '重载所有工具状态 / Reload all tool states',
|
|
37
|
+
handler: ({ agent }) => {
|
|
38
|
+
const session = agent?.session;
|
|
39
|
+
if (!session) return { kind: 'error', text: 'No active conversation. / 当前没有活动对话。' };
|
|
40
|
+
if (session.header?.agentPreset !== DEEP_PTC) return { kind: 'error', text: 'This command is available in Deep PTC sessions only. / 该功能仅在深度 PTC 会话中可用。' };
|
|
41
|
+
const current = projection.stateOf(session) ?? blankState();
|
|
42
|
+
// A new epoch clears quarantine; the preset layer drops on-demand selections and strike counts when it reads it.
|
|
43
|
+
handle.write(session, { ...blankState(), epoch: current.epoch + 1 });
|
|
44
|
+
return { kind: 'success', text: resetText(current.blocked.length) };
|
|
45
|
+
} });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The root state the preset layer reuses, when the root installed it. */
|
|
49
|
+
export function rootToolState() {
|
|
50
|
+
return globalThis[ROOT];
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deep-ptc-mode",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.6",
|
|
4
4
|
"description": "Agent mode for DSH: reporting, asking, reachability, planning, budget use. Plugin-first, official PTC fallback, dynamic tools, creative lab, dsh-go, multi-shell, dsh-ops-tested. / 面向 DSH:汇报、先问、休眠、计划、预算;插件优先、官方兜底,动态工具、创造模式、dsh-go、多 shell 与外部工具(dsh-ops 已测)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"./guard": "./lib/guard.mjs",
|
|
73
73
|
"./tool-compatibility": "./lib/tool-compatibility.mjs",
|
|
74
74
|
"./preset-compat": "./lib/preset-compat.mjs",
|
|
75
|
+
"./skill-context": "./lib/skill-context.mjs",
|
|
75
76
|
"./environment": "./lib/environment.mjs",
|
|
76
77
|
"./lab": "./lib/lab.mjs",
|
|
77
78
|
"./client": "./lib/client.js",
|