@michengai/dsh-pua 0.3.8
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 +152 -0
- package/LICENSE +201 -0
- package/NOTICE +38 -0
- package/README.md +150 -0
- package/assets/pua/command-again.md +23 -0
- package/assets/pua/command-done-check.md +21 -0
- package/assets/pua/command-evidence.md +18 -0
- package/assets/pua/flavors.md +388 -0
- package/assets/pua/methodology-alibaba.md +33 -0
- package/assets/pua/methodology-amazon.md +42 -0
- package/assets/pua/methodology-apple.md +42 -0
- package/assets/pua/methodology-baidu.md +33 -0
- package/assets/pua/methodology-bytedance.md +41 -0
- package/assets/pua/methodology-ding.md +75 -0
- package/assets/pua/methodology-huawei.md +95 -0
- package/assets/pua/methodology-jd.md +42 -0
- package/assets/pua/methodology-meituan.md +41 -0
- package/assets/pua/methodology-microsoft.md +138 -0
- package/assets/pua/methodology-netflix.md +41 -0
- package/assets/pua/methodology-pinduoduo.md +33 -0
- package/assets/pua/methodology-tencent.md +41 -0
- package/assets/pua/methodology-tesla.md +42 -0
- package/assets/pua/methodology-xiaomi.md +42 -0
- package/assets/pua/upstream/agents/cto-p10.md +87 -0
- package/assets/pua/upstream/agents/pua-action-executor.md +60 -0
- package/assets/pua/upstream/agents/pua-policy-guardian.md +54 -0
- package/assets/pua/upstream/agents/pua-self-reviewer.md +62 -0
- package/assets/pua/upstream/agents/pua-verifier.md +61 -0
- package/assets/pua/upstream/agents/senior-engineer-p7.md +116 -0
- package/assets/pua/upstream/agents/tech-lead-p9.md +97 -0
- package/assets/pua/upstream/commands/again.md +23 -0
- package/assets/pua/upstream/commands/cancel-pua-loop.md +62 -0
- package/assets/pua/upstream/commands/ding.md +25 -0
- package/assets/pua/upstream/commands/done-check.md +21 -0
- package/assets/pua/upstream/commands/evidence.md +18 -0
- package/assets/pua/upstream/commands/flavor.md +6 -0
- package/assets/pua/upstream/commands/kpi.md +5 -0
- package/assets/pua/upstream/commands/mama.md +5 -0
- package/assets/pua/upstream/commands/off.md +41 -0
- package/assets/pua/upstream/commands/offline.md +38 -0
- package/assets/pua/upstream/commands/on.md +15 -0
- package/assets/pua/upstream/commands/p10.md +5 -0
- package/assets/pua/upstream/commands/p7.md +5 -0
- package/assets/pua/upstream/commands/p9.md +5 -0
- package/assets/pua/upstream/commands/pro.md +5 -0
- package/assets/pua/upstream/commands/pua-loop.md +5 -0
- package/assets/pua/upstream/commands/pua.md +44 -0
- package/assets/pua/upstream/commands/reap-orphans.md +68 -0
- package/assets/pua/upstream/commands/survey.md +9 -0
- package/assets/pua/upstream/commands/team-status.md +56 -0
- package/assets/pua/upstream/commands/teardown-all.md +80 -0
- package/assets/pua/upstream/commands/yes.md +5 -0
- package/assets/pua/upstream/hooks/checkpoint-save.sh +56 -0
- package/assets/pua/upstream/hooks/failure-detector.sh +266 -0
- package/assets/pua/upstream/hooks/flavor-helper.sh +300 -0
- package/assets/pua/upstream/hooks/frustration-trigger.sh +61 -0
- package/assets/pua/upstream/hooks/hooks.json +114 -0
- package/assets/pua/upstream/hooks/integrity-guard.sh +494 -0
- package/assets/pua/upstream/hooks/pua-loop-hook.sh +360 -0
- package/assets/pua/upstream/hooks/runtime-state.py +460 -0
- package/assets/pua/upstream/hooks/sanitize-session.sh +165 -0
- package/assets/pua/upstream/hooks/session-restore.sh +189 -0
- package/assets/pua/upstream/hooks/stop-feedback.sh +51 -0
- package/assets/pua/upstream/hooks/subagent-teardown.sh +56 -0
- package/assets/pua/upstream/skills/ding/SKILL.md +83 -0
- package/assets/pua/upstream/skills/ding/references/ding-reminders.md +77 -0
- package/assets/pua/upstream/skills/ding/references/methodology-ding.md +75 -0
- package/assets/pua/upstream/skills/mama/SKILL.md +117 -0
- package/assets/pua/upstream/skills/p10/SKILL.md +13 -0
- package/assets/pua/upstream/skills/p7/SKILL.md +13 -0
- package/assets/pua/upstream/skills/p9/SKILL.md +15 -0
- package/assets/pua/upstream/skills/pro/SKILL.md +69 -0
- package/assets/pua/upstream/skills/pua/SKILL.md +438 -0
- package/assets/pua/upstream/skills/pua/references/agent-team.md +110 -0
- package/assets/pua/upstream/skills/pua/references/de-escalation-protocol.md +134 -0
- package/assets/pua/upstream/skills/pua/references/ding-reminders.md +77 -0
- package/assets/pua/upstream/skills/pua/references/display-protocol.md +63 -0
- package/assets/pua/upstream/skills/pua/references/evolution-protocol.md +187 -0
- package/assets/pua/upstream/skills/pua/references/flavors.md +388 -0
- package/assets/pua/upstream/skills/pua/references/harness-governance.md +159 -0
- package/assets/pua/upstream/skills/pua/references/methodology-alibaba.md +33 -0
- package/assets/pua/upstream/skills/pua/references/methodology-amazon.md +42 -0
- package/assets/pua/upstream/skills/pua/references/methodology-apple.md +42 -0
- package/assets/pua/upstream/skills/pua/references/methodology-baidu.md +33 -0
- package/assets/pua/upstream/skills/pua/references/methodology-bytedance.md +41 -0
- package/assets/pua/upstream/skills/pua/references/methodology-ding.md +75 -0
- package/assets/pua/upstream/skills/pua/references/methodology-huawei.md +95 -0
- package/assets/pua/upstream/skills/pua/references/methodology-jd.md +42 -0
- package/assets/pua/upstream/skills/pua/references/methodology-meituan.md +41 -0
- package/assets/pua/upstream/skills/pua/references/methodology-microsoft.md +138 -0
- package/assets/pua/upstream/skills/pua/references/methodology-netflix.md +41 -0
- package/assets/pua/upstream/skills/pua/references/methodology-pinduoduo.md +33 -0
- package/assets/pua/upstream/skills/pua/references/methodology-router.md +81 -0
- package/assets/pua/upstream/skills/pua/references/methodology-tencent.md +41 -0
- package/assets/pua/upstream/skills/pua/references/methodology-tesla.md +42 -0
- package/assets/pua/upstream/skills/pua/references/methodology-xiaomi.md +42 -0
- package/assets/pua/upstream/skills/pua/references/p10-protocol.md +127 -0
- package/assets/pua/upstream/skills/pua/references/p7-protocol.md +250 -0
- package/assets/pua/upstream/skills/pua/references/p9-protocol.md +266 -0
- package/assets/pua/upstream/skills/pua/references/platform.md +126 -0
- package/assets/pua/upstream/skills/pua/references/runtime-contract.md +65 -0
- package/assets/pua/upstream/skills/pua/references/survey.md +292 -0
- package/assets/pua/upstream/skills/pua/references/teardown-protocol.md +195 -0
- package/assets/pua/upstream/skills/pua-en/SKILL.md +344 -0
- package/assets/pua/upstream/skills/pua-ja/SKILL.md +378 -0
- package/assets/pua/upstream/skills/pua-loop/SKILL.md +162 -0
- package/assets/pua/upstream/skills/shot/SKILL.md +449 -0
- package/assets/pua/upstream/skills/yes/SKILL.md +76 -0
- package/assets/pua/upstream.json +637 -0
- package/assets/screenshots/pua-global-settings.png +0 -0
- package/assets/screenshots/pua-session-settings.png +0 -0
- package/cordis.patch.yml +5 -0
- package/lib/args.d.ts +34 -0
- package/lib/args.js +149 -0
- package/lib/args.js.map +1 -0
- package/lib/client-refresh.d.ts +6 -0
- package/lib/client-refresh.js +41 -0
- package/lib/client-refresh.js.map +1 -0
- package/lib/client.d.ts +30 -0
- package/lib/client.js +68 -0
- package/lib/client.js.map +7 -0
- package/lib/command.d.ts +18 -0
- package/lib/command.js +118 -0
- package/lib/command.js.map +1 -0
- package/lib/configuration.d.ts +89 -0
- package/lib/configuration.js +31 -0
- package/lib/configuration.js.map +1 -0
- package/lib/content.d.ts +14 -0
- package/lib/content.js +51 -0
- package/lib/content.js.map +1 -0
- package/lib/flavors.d.ts +82 -0
- package/lib/flavors.js +30 -0
- package/lib/flavors.js.map +1 -0
- package/lib/hook-content.d.ts +14 -0
- package/lib/hook-content.js +63 -0
- package/lib/hook-content.js.map +1 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.js +75 -0
- package/lib/index.js.map +1 -0
- package/lib/remote-contract.d.ts +148 -0
- package/lib/remote-contract.js +20 -0
- package/lib/remote-contract.js.map +1 -0
- package/lib/remote.d.ts +20 -0
- package/lib/remote.js +133 -0
- package/lib/remote.js.map +1 -0
- package/lib/review.d.ts +4 -0
- package/lib/review.js +72 -0
- package/lib/review.js.map +1 -0
- package/lib/runtime.d.ts +61 -0
- package/lib/runtime.js +519 -0
- package/lib/runtime.js.map +1 -0
- package/lib/session-compat.d.ts +3 -0
- package/lib/session-compat.js +9 -0
- package/lib/session-compat.js.map +1 -0
- package/lib/settings.d.ts +46 -0
- package/lib/settings.js +44 -0
- package/lib/settings.js.map +1 -0
- package/lib/source.d.ts +10 -0
- package/lib/source.js +32 -0
- package/lib/source.js.map +1 -0
- package/lib/state.d.ts +36 -0
- package/lib/state.js +187 -0
- package/lib/state.js.map +1 -0
- package/lib/terminal-observation.d.ts +4 -0
- package/lib/terminal-observation.js +12 -0
- package/lib/terminal-observation.js.map +1 -0
- package/lib/tool-order.d.ts +9 -0
- package/lib/tool-order.js +82 -0
- package/lib/tool-order.js.map +1 -0
- package/package.json +172 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Session } from '@deepseek-ai/dsh-session';
|
|
2
|
+
/** 从原始日志增量检查整组调用;包含已声明但尚未派发的并行调用。 */
|
|
3
|
+
export declare function hasPendingToolCalls(session: Session): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* 兼容本插件打断的完整历史工具组。只追加模型上下文替换,不改写原始事件。
|
|
6
|
+
* 原工具结果本来就是 user-role 消息;使用通用 user/message 投影保留其完整
|
|
7
|
+
* id、tool 来源和 content,覆盖前置 PUA 节点与结果节点,避免伪造或重执行工具。
|
|
8
|
+
*/
|
|
9
|
+
export declare function repairPuaToolOrder(session: Session, plugin: string): void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {} from '@deepseek-ai/dsh-session';
|
|
2
|
+
import { replacementSurface } from './session-compat.js';
|
|
3
|
+
const calls = new WeakMap();
|
|
4
|
+
/** 从原始日志增量检查整组调用;包含已声明但尚未派发的并行调用。 */
|
|
5
|
+
export function hasPendingToolCalls(session) {
|
|
6
|
+
let pending = calls.get(session);
|
|
7
|
+
if (!pending) {
|
|
8
|
+
pending = { cursor: session.inheritedEventCount, ids: new Map() };
|
|
9
|
+
calls.set(session, pending);
|
|
10
|
+
}
|
|
11
|
+
for (const event of session.snapshotEvents(pending.cursor)) {
|
|
12
|
+
if (event.type === 'assistant/message' && event.surfaceOp === 'append') {
|
|
13
|
+
for (const block of event.data.message.content)
|
|
14
|
+
if (block.type === 'tool-call')
|
|
15
|
+
pending.ids.set(block.id, event.seq);
|
|
16
|
+
}
|
|
17
|
+
else if (event.type === 'tool/result' && event.surfaceOp === 'append') {
|
|
18
|
+
pending.ids.delete(event.data.message.source.callId);
|
|
19
|
+
}
|
|
20
|
+
else if (event.type === 'turn/end' || event.type === 'turn/start') {
|
|
21
|
+
// 结束轮次的孤儿不再阻塞后续轮次,不伪造缺失结果。
|
|
22
|
+
pending.ids.clear();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
pending.cursor = session.seq;
|
|
26
|
+
const visible = new Set(session.surface.nodes);
|
|
27
|
+
for (const [id, seq] of pending.ids)
|
|
28
|
+
if (!visible.has(seq))
|
|
29
|
+
pending.ids.delete(id);
|
|
30
|
+
return pending.ids.size !== 0;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 兼容本插件打断的完整历史工具组。只追加模型上下文替换,不改写原始事件。
|
|
34
|
+
* 原工具结果本来就是 user-role 消息;使用通用 user/message 投影保留其完整
|
|
35
|
+
* id、tool 来源和 content,覆盖前置 PUA 节点与结果节点,避免伪造或重执行工具。
|
|
36
|
+
*/
|
|
37
|
+
export function repairPuaToolOrder(session, plugin) {
|
|
38
|
+
const nodes = [...session.surface.nodes];
|
|
39
|
+
for (let index = 0; index < nodes.length; index++) {
|
|
40
|
+
const first = session.eventAt(nodes[index]);
|
|
41
|
+
if (!first)
|
|
42
|
+
continue;
|
|
43
|
+
const assistant = session.deriveEventMessage(first);
|
|
44
|
+
if (assistant?.role !== 'assistant')
|
|
45
|
+
continue;
|
|
46
|
+
const ids = assistant.content.flatMap(block => block.type === 'tool-call' ? [block.id] : []);
|
|
47
|
+
if (!ids.length || new Set(ids).size !== ids.length)
|
|
48
|
+
continue;
|
|
49
|
+
const pending = new Set(ids);
|
|
50
|
+
let gap = [];
|
|
51
|
+
const replacements = [];
|
|
52
|
+
let next = index + 1;
|
|
53
|
+
for (; next < nodes.length && pending.size; next++) {
|
|
54
|
+
const seq = nodes[next];
|
|
55
|
+
const event = session.eventAt(seq);
|
|
56
|
+
const message = session.deriveEventMessage(event);
|
|
57
|
+
if (event.type === 'user/message' && message?.source.kind === 'plugin' && message.source.plugin === plugin) {
|
|
58
|
+
gap.push(seq);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (message?.role !== 'user' || message.source.kind !== 'tool' || message.content.length !== 1)
|
|
62
|
+
break;
|
|
63
|
+
const block = message.content[0];
|
|
64
|
+
if (block.type !== 'tool-result' || block.toolCallId !== message.source.callId || !pending.delete(block.toolCallId))
|
|
65
|
+
break;
|
|
66
|
+
if (gap.length)
|
|
67
|
+
replacements.push({ nodes: [...gap, seq], message: message });
|
|
68
|
+
gap = [];
|
|
69
|
+
}
|
|
70
|
+
// 缺失结果或夹入其他来源消息时不猜测,也不进行半组修复。
|
|
71
|
+
if (pending.size)
|
|
72
|
+
continue;
|
|
73
|
+
for (const replacement of replacements) {
|
|
74
|
+
session.append('user/message', replacement.message, {
|
|
75
|
+
surfaceOp: replacementSurface(replacement.nodes[0], replacement.nodes.at(-1)),
|
|
76
|
+
sourceEventSeqs: replacement.nodes,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
index = next - 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=tool-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-order.js","sourceRoot":"","sources":["../src/tool-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,MAAM,KAAK,GAAG,IAAI,OAAO,EAAyB,CAAC;AAEnD,qCAAqC;AACrC,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,IAAI,OAAO,GAA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AAE,WAAW,CAAC,OAAO,EAAE;gBAClD,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;gBAC/E,eAAe,EAAE,WAAW,CAAC,KAAK;aACnC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { type Session, type UserMessage } from '@deepseek-ai/dsh-session';\nimport { replacementSurface } from './session-compat.js';\n\ninterface PendingCalls { cursor: Session['seq']; ids: Map<string, Session[\"surface\"][\"nodes\"][number]> }\nconst calls = new WeakMap<Session, PendingCalls>();\n\n/** 从原始日志增量检查整组调用;包含已声明但尚未派发的并行调用。 */\nexport function hasPendingToolCalls(session: Session): boolean {\n let pending = calls.get(session);\n if (!pending) {\n pending = { cursor: session.inheritedEventCount, ids: new Map() };\n calls.set(session, pending);\n }\n for (const event of session.snapshotEvents(pending.cursor)) {\n if (event.type === 'assistant/message' && event.surfaceOp === 'append') {\n for (const block of event.data.message.content) if (block.type === 'tool-call') pending.ids.set(block.id, event.seq);\n } else if (event.type === 'tool/result' && event.surfaceOp === 'append') {\n pending.ids.delete(event.data.message.source.callId);\n } else if (event.type === 'turn/end' || event.type === 'turn/start') {\n // 结束轮次的孤儿不再阻塞后续轮次,不伪造缺失结果。\n pending.ids.clear();\n }\n }\n pending.cursor = session.seq;\n const visible = new Set(session.surface.nodes);\n for (const [id, seq] of pending.ids) if (!visible.has(seq)) pending.ids.delete(id);\n return pending.ids.size !== 0;\n}\n\n/**\n * 兼容本插件打断的完整历史工具组。只追加模型上下文替换,不改写原始事件。\n * 原工具结果本来就是 user-role 消息;使用通用 user/message 投影保留其完整\n * id、tool 来源和 content,覆盖前置 PUA 节点与结果节点,避免伪造或重执行工具。\n */\nexport function repairPuaToolOrder(session: Session, plugin: string): void {\n const nodes = [...session.surface.nodes];\n for (let index = 0; index < nodes.length; index++) {\n const first = session.eventAt(nodes[index]!);\n if (!first) continue;\n const assistant = session.deriveEventMessage(first);\n if (assistant?.role !== 'assistant') continue;\n const ids = assistant.content.flatMap(block => block.type === 'tool-call' ? [block.id] : []);\n if (!ids.length || new Set(ids).size !== ids.length) continue;\n const pending = new Set<string>(ids);\n let gap: Session['surface']['nodes'][number][] = [];\n const replacements: { nodes: typeof gap; message: UserMessage }[] = [];\n let next = index + 1;\n for (; next < nodes.length && pending.size; next++) {\n const seq = nodes[next]!;\n const event = session.eventAt(seq)!;\n const message = session.deriveEventMessage(event);\n if (event.type === 'user/message' && message?.source.kind === 'plugin' && message.source.plugin === plugin) {\n gap.push(seq);\n continue;\n }\n if (message?.role !== 'user' || message.source.kind !== 'tool' || message.content.length !== 1) break;\n const block = message.content[0]!;\n if (block.type !== 'tool-result' || block.toolCallId !== message.source.callId || !pending.delete(block.toolCallId)) break;\n if (gap.length) replacements.push({ nodes: [...gap, seq], message: message as UserMessage });\n gap = [];\n }\n // 缺失结果或夹入其他来源消息时不猜测,也不进行半组修复。\n if (pending.size) continue;\n for (const replacement of replacements) {\n session.append('user/message', replacement.message, {\n surfaceOp: replacementSurface(replacement.nodes[0]!, replacement.nodes.at(-1)!),\n sourceEventSeqs: replacement.nodes,\n });\n }\n index = next - 1;\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@michengai/dsh-pua",
|
|
3
|
+
"version": "0.3.8",
|
|
4
|
+
"description": "PUA 的 DSH 实现:完整协议、全局与会话配置、角色风味、子代理策略与独立验收 Loop",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.19.0"
|
|
9
|
+
},
|
|
10
|
+
"main": "./lib/index.js",
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
|
+
"default": "./lib/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./client": {
|
|
18
|
+
"default": "./lib/client.js"
|
|
19
|
+
},
|
|
20
|
+
"./remote": {
|
|
21
|
+
"types": "./lib/remote.d.ts",
|
|
22
|
+
"default": "./lib/remote.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"lib",
|
|
27
|
+
"assets/pua",
|
|
28
|
+
"assets/screenshots",
|
|
29
|
+
"cordis.patch.yml",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"NOTICE",
|
|
33
|
+
"CHANGELOG.md"
|
|
34
|
+
],
|
|
35
|
+
"dsh": {
|
|
36
|
+
"bundle": {
|
|
37
|
+
"patch": "./cordis.patch.yml"
|
|
38
|
+
},
|
|
39
|
+
"client": {
|
|
40
|
+
"inject": [
|
|
41
|
+
"@deepseek-ai/dsh-client-connection",
|
|
42
|
+
"@deepseek-ai/dsh-api-remotes",
|
|
43
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
44
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
45
|
+
"@deepseek-ai/dsh-client-ui-primitives"
|
|
46
|
+
],
|
|
47
|
+
"platform": "web"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -p tsconfig.json && node scripts/build-client.mjs",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
53
|
+
"test": "npm run build && node --test tests/*.test.mjs",
|
|
54
|
+
"check": "npm run typecheck && npm test && npm run verify",
|
|
55
|
+
"verify": "node scripts/verify.mjs",
|
|
56
|
+
"prepack": "npm run build && npm run verify",
|
|
57
|
+
"test:compat": "node scripts/check-compat.mjs"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public",
|
|
61
|
+
"registry": "https://registry.npmjs.org/"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
65
|
+
"@deepseek-ai/dsh-agent": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
66
|
+
"@deepseek-ai/dsh-api-remotes": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
67
|
+
"@deepseek-ai/dsh-client-connection": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
69
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
70
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
71
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
72
|
+
"@deepseek-ai/dsh-commands": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
73
|
+
"@deepseek-ai/dsh-llm": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
74
|
+
"@deepseek-ai/dsh-session": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
75
|
+
"@deepseek-ai/dsh-settings": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
76
|
+
"@deepseek-ai/dsh-subprocess": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
77
|
+
"@deepseek-ai/dsh-system-prompt": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
78
|
+
"@deepseek-ai/dsh-tools": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
79
|
+
"@deepseek-ai/dsh-typert-protocol": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
80
|
+
"@deepseek-ai/dsh-typert-registry": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
81
|
+
"@deepseek-ai/schemastery": "3.18.2",
|
|
82
|
+
"react": "^18.2.0",
|
|
83
|
+
"react-dom": "^18.2.0"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@deepseek-ai/dsh-subprocess": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"@deepseek-ai/dsh-settings": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"@deepseek-ai/dsh-tools": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@deepseek-ai/dsh-typert-protocol": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@deepseek-ai/dsh-typert-registry": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@deepseek-ai/dsh-api-remotes": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"@deepseek-ai/dsh-client-ui-settings": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"@deepseek-ai/dsh-client-ui-conversation": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"@deepseek-ai/dsh-client-ui-slots": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"@deepseek-ai/dsh-client-connection": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"react": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"react-dom": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"@deepseek-ai/dsh-client-ui-primitives": {
|
|
123
|
+
"optional": true
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"devDependencies": {
|
|
127
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
128
|
+
"@deepseek-ai/dsh-agent": "0.1.5-rc.2",
|
|
129
|
+
"@deepseek-ai/dsh-agent-loop": "0.1.5-rc.2",
|
|
130
|
+
"@deepseek-ai/dsh-api-remotes": "0.1.5-rc.2",
|
|
131
|
+
"@deepseek-ai/dsh-client-connection": "0.1.5-rc.2",
|
|
132
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.1.5-rc.2",
|
|
133
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.1.5-rc.2",
|
|
134
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.5-rc.2",
|
|
135
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.5-rc.2",
|
|
136
|
+
"@deepseek-ai/dsh-commands": "0.1.5-rc.2",
|
|
137
|
+
"@deepseek-ai/dsh-llm": "0.1.5-rc.2",
|
|
138
|
+
"@deepseek-ai/dsh-session": "0.1.5-rc.2",
|
|
139
|
+
"@deepseek-ai/dsh-session-format-v2-to-v3": "0.1.5-rc.2",
|
|
140
|
+
"@deepseek-ai/dsh-session-projection": "0.1.5-rc.2",
|
|
141
|
+
"@deepseek-ai/dsh-settings": "0.1.5-rc.2",
|
|
142
|
+
"@deepseek-ai/dsh-subprocess": "0.1.5-rc.2",
|
|
143
|
+
"@deepseek-ai/dsh-subprocess-local": "0.1.5-rc.2",
|
|
144
|
+
"@deepseek-ai/dsh-system-prompt": "0.1.5-rc.2",
|
|
145
|
+
"@deepseek-ai/dsh-terminal": "0.1.5-rc.2",
|
|
146
|
+
"@deepseek-ai/dsh-tool-bash-persistent": "0.1.5-rc.2",
|
|
147
|
+
"@deepseek-ai/dsh-tool-pwsh-persistent": "0.1.5-rc.2",
|
|
148
|
+
"@deepseek-ai/dsh-tools": "0.1.5-rc.2",
|
|
149
|
+
"@deepseek-ai/dsh-typert-protocol": "0.1.5-rc.2",
|
|
150
|
+
"@deepseek-ai/dsh-typert-registry": "0.1.5-rc.2",
|
|
151
|
+
"@deepseek-ai/schemastery": "3.18.2",
|
|
152
|
+
"@types/node": "^22.19.0",
|
|
153
|
+
"@types/react": "18.3.7",
|
|
154
|
+
"@types/react-dom": "18.3.7",
|
|
155
|
+
"clsx": "2.1.1",
|
|
156
|
+
"esbuild": "0.25.12",
|
|
157
|
+
"react": "18.3.1",
|
|
158
|
+
"react-dom": "18.3.1",
|
|
159
|
+
"typescript": "~5.7.2"
|
|
160
|
+
},
|
|
161
|
+
"dependencies": {
|
|
162
|
+
"zod": "4.4.3"
|
|
163
|
+
},
|
|
164
|
+
"repository": {
|
|
165
|
+
"type": "git",
|
|
166
|
+
"url": "git+https://github.com/MichengAI/dsh-pua.git"
|
|
167
|
+
},
|
|
168
|
+
"homepage": "https://github.com/MichengAI/dsh-pua#readme",
|
|
169
|
+
"bugs": {
|
|
170
|
+
"url": "https://github.com/MichengAI/dsh-pua/issues"
|
|
171
|
+
}
|
|
172
|
+
}
|