@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
package/lib/command.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CommandInvocation, CommandResult } from '@deepseek-ai/dsh-commands';
|
|
2
|
+
import { StateStore } from './state.js';
|
|
3
|
+
import type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess';
|
|
4
|
+
import type { QualityCommand } from './content.js';
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
import { SourceCatalog } from './source.js';
|
|
7
|
+
import type { PreferencesBridge } from './settings.js';
|
|
8
|
+
import { type PuaRuntime } from './runtime.js';
|
|
9
|
+
interface Services {
|
|
10
|
+
catalog: SourceCatalog;
|
|
11
|
+
preferences: PreferencesBridge;
|
|
12
|
+
runtime: PuaRuntime;
|
|
13
|
+
ctx: Context;
|
|
14
|
+
}
|
|
15
|
+
export declare const HELP = "\u7528\u6CD5\uFF1A\n/pua [\u4EFB\u52A1\u63CF\u8FF0]\uFF1A\u5F00\u542F PUA\uFF1B\u65E0\u63CF\u8FF0\u65F6\u7EE7\u7EED\u5F53\u524D\u4EFB\u52A1\n/pua review [\u8303\u56F4]\uFF1A\u53EA\u8BFB\u5BA1\u67E5\uFF0C\u9644\u5E26\u5F53\u524D\u4ED3\u5E93 Git \u7D22\u5F15\u8BC1\u636E\uFF08\u5BBF\u4E3B\u53EF\u7528\u65F6\uFF09\n/pua on / /pua off\uFF1A\u53EA\u4FEE\u6539\u5F53\u524D\u4F1A\u8BDD\uFF1B\u4E0D\u6539\u53D8\u5168\u5C40\u9ED8\u8BA4\u3001\u4E0D\u53D1\u8D77\u6A21\u578B\u8BF7\u6C42\n/pua config {\"subagents\":true}\uFF1A\u4FEE\u6539\u5F53\u524D\u4F1A\u8BDD\u53C2\u6570\n/pua reset [\u53C2\u6570\u540D]\uFF1A\u6062\u590D\u5355\u9879\u6216\u5168\u90E8\u8DDF\u968F\u5168\u5C40\n/pua flavor [\u540D\u79F0|auto]\uFF1A\u5217\u51FA\u3001\u9501\u5B9A\u6216\u6062\u590D\u81EA\u52A8\u9009\u5473\uFF0C\u4E0D\u81EA\u52A8\u5F00\u542F\n/pua p7|p9|p10|pro|yes|mama|shot|pua-en|pua-ja [\u4EFB\u52A1]\uFF1A\u5B8C\u6574\u539F\u7248\u6A21\u5F0F\n/pua ding [\u4EFB\u52A1]\uFF1A\u9489\u5185/\u9489\u5916\u5473\n/pua loop \"\u4EFB\u52A1\" --verify \"npm test\" --max-iterations 10\uFF1A\u72EC\u7ACB\u9A8C\u6536\u5FAA\u73AF\uFF1B\u7701\u7565\u53C2\u6570\u4F7F\u7528\u5F53\u524D\u4F1A\u8BDD\u751F\u6548\u9ED8\u8BA4\u503C\n/pua cancel-pua-loop \u6216 /cancel-pua-loop\uFF1A\u53D6\u6D88\u5F53\u524D\u5FAA\u73AF\n/pua kpi / /pua survey [quick]\uFF1A\u539F\u7248 KPI \u4E0E\u672C\u5730\u95EE\u5377\n/pua offline\uFF1A\u4FDD\u6301\u672C\u5730\u6A21\u5F0F\uFF0C\u65E0\u4E0A\u4F20\u80FD\u529B\n/pua team-status\uFF1A\u5F53\u524D\u4F1A\u8BDD\u53CA\u5176 DSH \u5B50\u4EE3\u7406\u72B6\u6001\n/pua reap-orphans / /pua teardown-all\uFF1A\u56DE\u6536\u672C\u63D2\u4EF6\u5FAA\u73AF\uFF1B\u4E0D\u5220\u9664\u5176\u4ED6\u5DE5\u5177\u7BA1\u7406\u7684 worktree\n/pua again\uFF1A\u9488\u5BF9\u5F53\u524D\u76EE\u6807\u6362\u4E00\u79CD\u5B9E\u8D28\u4E0D\u540C\u7684\u65B9\u6CD5\n/pua done-check\uFF1A\u6838\u5BF9\u9700\u6C42\u3001\u4EA4\u4ED8\u7ED3\u679C\u3001\u9A8C\u6536\u8BC1\u636E\u548C\u7F3A\u53E3\n/pua evidence\uFF1A\u6838\u5BF9\u5DF2\u5B58\u5728\u8BC1\u636E\uFF0C\u6307\u51FA\u672A\u8BC1\u660E\u7684\u7ED3\u8BBA\n/pua status\uFF1A\u67E5\u770B\u5F53\u524D\u914D\u7F6E\n/pua -- \u4EFB\u52A1\u63CF\u8FF0\uFF1A\u4EFB\u52A1\u4EE5\u63A7\u5236\u547D\u4EE4\u540C\u540D\u5355\u8BCD\u5F00\u5934\u65F6\u4F7F\u7528\n\u539F\u7248\u5192\u53F7\u547D\u4EE4\u5BF9\u5E94 DSH \u7A7A\u683C\u5B50\u547D\u4EE4\uFF0C\u4F8B\u5982 /pua:p9 \u2192 /pua p9\u3002\n\u8BBE\u7F6E\u9875\u547D\u540D\u7A7A\u95F4\uFF1Amichengai-pua\u3002\u65E0 settings \u65F6\u964D\u7EA7\u4E3A\u5F53\u524D\u4F1A\u8BDD\uFF0C\u9ED8\u8BA4\u5173\u95ED\u3002";
|
|
16
|
+
/** 执行原生命令;投递失败撤销临时状态,成功状态由宿主 command/done 日志恢复。 */
|
|
17
|
+
export declare function handleCommand(store: StateStore, invocation: CommandInvocation, templates: ReadonlyMap<QualityCommand, string>, subprocess?: Pick<SubprocessRuntime, 'spawn'>, services?: Services): Promise<CommandResult>;
|
|
18
|
+
export {};
|
package/lib/command.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import { parseArgs } from './args.js';
|
|
3
|
+
import { flavorLabel, listFlavors } from './flavors.js';
|
|
4
|
+
import { StateStore, SESSION_RESULT_PREFIX as RESULT_PREFIX } from './state.js';
|
|
5
|
+
import { collectGitEvidence, REVIEW_RULES } from './review.js';
|
|
6
|
+
import { SourceCatalog } from './source.js';
|
|
7
|
+
import { LOOP_START } from './runtime.js';
|
|
8
|
+
export const HELP = `用法:
|
|
9
|
+
/pua [任务描述]:开启 PUA;无描述时继续当前任务
|
|
10
|
+
/pua review [范围]:只读审查,附带当前仓库 Git 索引证据(宿主可用时)
|
|
11
|
+
/pua on / /pua off:只修改当前会话;不改变全局默认、不发起模型请求
|
|
12
|
+
/pua config {"subagents":true}:修改当前会话参数
|
|
13
|
+
/pua reset [参数名]:恢复单项或全部跟随全局
|
|
14
|
+
/pua flavor [名称|auto]:列出、锁定或恢复自动选味,不自动开启
|
|
15
|
+
/pua p7|p9|p10|pro|yes|mama|shot|pua-en|pua-ja [任务]:完整原版模式
|
|
16
|
+
/pua ding [任务]:钉内/钉外味
|
|
17
|
+
/pua loop "任务" --verify "npm test" --max-iterations 10:独立验收循环;省略参数使用当前会话生效默认值
|
|
18
|
+
/pua cancel-pua-loop 或 /cancel-pua-loop:取消当前循环
|
|
19
|
+
/pua kpi / /pua survey [quick]:原版 KPI 与本地问卷
|
|
20
|
+
/pua offline:保持本地模式,无上传能力
|
|
21
|
+
/pua team-status:当前会话及其 DSH 子代理状态
|
|
22
|
+
/pua reap-orphans / /pua teardown-all:回收本插件循环;不删除其他工具管理的 worktree
|
|
23
|
+
/pua again:针对当前目标换一种实质不同的方法
|
|
24
|
+
/pua done-check:核对需求、交付结果、验收证据和缺口
|
|
25
|
+
/pua evidence:核对已存在证据,指出未证明的结论
|
|
26
|
+
/pua status:查看当前配置
|
|
27
|
+
/pua -- 任务描述:任务以控制命令同名单词开头时使用
|
|
28
|
+
原版冒号命令对应 DSH 空格子命令,例如 /pua:p9 → /pua p9。
|
|
29
|
+
设置页命名空间:michengai-pua。无 settings 时降级为当前会话,默认关闭。`;
|
|
30
|
+
function actionPrompt(action, templates, catalog) {
|
|
31
|
+
switch (action.kind) {
|
|
32
|
+
case 'activate':
|
|
33
|
+
return action.task ? `请处理下面用户指定的任务。任务正文:\n\n${action.task}`
|
|
34
|
+
: '继续当前已授权任务:先核对目标和现有证据,诊断后完成剩余工作。若历史没有可识别任务,请用户提供目标,不自行编造任务。';
|
|
35
|
+
case 'review':
|
|
36
|
+
return `${REVIEW_RULES}\n\n用户审查范围:${action.task}`;
|
|
37
|
+
case 'again':
|
|
38
|
+
case 'done-check':
|
|
39
|
+
case 'evidence':
|
|
40
|
+
return templates.get(action.kind) + (action.task ? `\n\n用户补充:${action.task}` : '');
|
|
41
|
+
case 'mode':
|
|
42
|
+
return `执行当前 ${action.mode} 完整原版模式。\n${action.task || '继续当前已授权任务;历史无任务时请用户提供目标。'}`;
|
|
43
|
+
case 'loop':
|
|
44
|
+
return `按当前系统中的完整 PUA Loop 协议执行任务:${action.task}\n本轮上限:${action.maxIterations || '无限'};${action.verify ? 'Oracle 使用用户指定命令独立验证。' : '未配置 Oracle,使用 honor system,不得声称独立验收通过。'}配置已由 DSH 接管,不运行 setup shell 脚本。`;
|
|
45
|
+
case 'kpi':
|
|
46
|
+
return catalog.body('commands/kpi.md') + '\n\n当前 pro 原版协议已完整注入;只基于实际证据生成报告卡,不编造历史。';
|
|
47
|
+
case 'survey':
|
|
48
|
+
return catalog.body('commands/survey.md') + '\n\n参数:' + (action.task ?? '') + (action.task === 'quick' ? '' : '\n\n' + catalog.body('skills/pua/references/survey.md'));
|
|
49
|
+
default:
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** 执行原生命令;投递失败撤销临时状态,成功状态由宿主 command/done 日志恢复。 */
|
|
54
|
+
export async function handleCommand(store, invocation, templates, subprocess, services) {
|
|
55
|
+
const { agent, signal, commandId } = invocation;
|
|
56
|
+
try {
|
|
57
|
+
signal.throwIfAborted();
|
|
58
|
+
const action = parseArgs(invocation.rawInput, store.configuration(agent.session));
|
|
59
|
+
if (action.kind === 'help')
|
|
60
|
+
return { kind: 'success', text: RESULT_PREFIX + HELP };
|
|
61
|
+
if (action.kind === 'flavors')
|
|
62
|
+
return { kind: 'success', text: RESULT_PREFIX + listFlavors() + '\n例如:/pua flavor huawei' };
|
|
63
|
+
if (action.kind === 'status') {
|
|
64
|
+
const state = store.read(agent.session);
|
|
65
|
+
return { kind: 'success', text: `${RESULT_PREFIX}${state.enabled ? '已开启' : '已关闭'};模式:${services?.runtime.effectiveMode(agent.session, state.mode) ?? state.mode};风味:${state.flavorLocked ? flavorLabel(state.flavor) + '(锁定)' : '自动路由'}。\n${services?.preferences.description() ?? '当前会话'};原版 3.5.1 完整正文。\n${services?.runtime.status(agent.session) ?? ''}` };
|
|
66
|
+
}
|
|
67
|
+
if (action.kind === 'team-status') {
|
|
68
|
+
const agents = services?.ctx.get('agents')?.list().filter(item => item.id === agent.id || item.session.header.parentSession === agent.id) ?? [];
|
|
69
|
+
return { kind: 'success', text: RESULT_PREFIX + (agents.length ? agents.map(item => `${item.id} | ${item.status}`).join('\n') : '宿主未提供子代理状态。') + '\n' + (services?.runtime.status(agent.session) ?? '') + '\nDSH Agent 由宿主管理,无原版 PID/TTL 文件。' };
|
|
70
|
+
}
|
|
71
|
+
if (action.kind === 'reap-orphans')
|
|
72
|
+
return { kind: 'success', text: RESULT_PREFIX + 'DSH 已在取消、异常结束和卸载时回收本插件循环;没有独立后台进程或 .claude 孤儿状态可清理。其他工具的子代理/worktree 由所属工具管理。' };
|
|
73
|
+
if (action.kind === 'loop' && action.verify && (!subprocess || !agent.session.header.cwd))
|
|
74
|
+
throw new Error('独立验收需要宿主 subprocess 和会话工作目录;未启动循环。');
|
|
75
|
+
// 只读预检完成且未取消后才暂存开关;等待期间不让其他模型请求误用未完成配置。
|
|
76
|
+
const evidence = action.kind === 'review' ? await collectGitEvidence(subprocess, agent.session.header.cwd, signal) : undefined;
|
|
77
|
+
signal.throwIfAborted();
|
|
78
|
+
if (action.kind === 'off' || action.kind === 'cancel-pua-loop' || action.kind === 'loop')
|
|
79
|
+
services?.runtime.cancel(agent.session);
|
|
80
|
+
const stopped = action.kind === 'teardown-all' ? services?.runtime.cancelAll() ?? 0 : 0;
|
|
81
|
+
store.stage(agent.session, commandId, action);
|
|
82
|
+
const state = store.read(agent.session);
|
|
83
|
+
if (!state.enabled)
|
|
84
|
+
services?.runtime.cancel(agent.session);
|
|
85
|
+
if (action.kind === 'configure')
|
|
86
|
+
return { kind: 'success', text: RESULT_PREFIX + '会话配置已保存;未覆盖项继续跟随全局。' };
|
|
87
|
+
const task = actionPrompt(action, templates, services?.catalog ?? new SourceCatalog());
|
|
88
|
+
if (task !== undefined) {
|
|
89
|
+
signal.throwIfAborted();
|
|
90
|
+
const message = createUserMessage({
|
|
91
|
+
content: [{ type: 'text', text: `${action.kind === 'loop' ? LOOP_START + JSON.stringify({ ...action, id: commandId }) + '\n' : ''}这是通过 /pua 提交的用户请求。是否使用 PUA 及所选风味,以执行时的 DSH PUA 当前状态为准;如果用户已关闭模式,正常处理任务,不因这条历史请求重新启用。启用时执行完整原版核心、展示协议及当前角色,不能用摘要替代。遵循宿主权限与用户最新要求。\n\n${task}${evidence === undefined ? '' : '\n\n' + evidence}` }],
|
|
92
|
+
source: { kind: 'plugin', plugin: '@michengai/dsh-pua' },
|
|
93
|
+
});
|
|
94
|
+
// 明确的新任务排入后续轮次;对当前任务的纠偏在最近的步骤边界生效。
|
|
95
|
+
if (action.kind === 'review' || action.kind === 'loop' || (action.kind === 'mode' && action.task) || (action.kind === 'activate' && action.task))
|
|
96
|
+
agent.followup(message);
|
|
97
|
+
else
|
|
98
|
+
agent.steer(message);
|
|
99
|
+
return { kind: 'success', text: `${RESULT_PREFIX}已提交${action.kind === 'review' ? '只读审查' : action.kind === 'mode' ? action.mode + ' 模式' : action.kind === 'loop' ? 'Loop' : action.kind === 'done-check' ? '完成检查' : action.kind === 'evidence' ? '证据检查' : action.kind === 'again' ? '换方法请求' : action.kind === 'activate' ? '任务请求' : action.kind},风味:${state.flavorLocked ? flavorLabel(state.flavor) : '自动路由'}。请查看 Agent 后续结果。${action.kind === 'loop' ? '\n' + (action.verify ? 'Oracle:用户指定验证命令。' : '未配置 Oracle,仅 honor system。') : ''}${evidence?.startsWith('未获取') ? '\nGit 预检未取得证据,已要求 Agent 补充只读验证。' : ''}` };
|
|
100
|
+
}
|
|
101
|
+
if (action.kind === 'cancel-pua-loop')
|
|
102
|
+
return { kind: 'success', text: RESULT_PREFIX + '当前 Loop 已取消,不再自动续轮。' };
|
|
103
|
+
if (action.kind === 'teardown-all')
|
|
104
|
+
return { kind: 'success', text: `${RESULT_PREFIX}已停止本插件管理的 ${stopped} 个循环;未删除宿主子代理或其他工具的 worktree。` };
|
|
105
|
+
if (action.kind === 'offline')
|
|
106
|
+
return { kind: 'success', text: RESULT_PREFIX + '保持本地模式,无联网刷新或上报能力。' };
|
|
107
|
+
if (action.kind === 'off')
|
|
108
|
+
return { kind: 'success', text: RESULT_PREFIX + 'PUA 已关闭,Loop 已取消。范围:' + (services?.preferences.description() ?? '当前会话') + '。' };
|
|
109
|
+
if (action.kind === 'flavor')
|
|
110
|
+
return { kind: 'success', text: `${RESULT_PREFIX}${state.flavorLocked ? '已锁定' + flavorLabel(state.flavor) : '已恢复自动路由'};当前模式${state.enabled ? '已开启' : '仍关闭'}。范围:${services?.preferences.description() ?? '当前会话'}。` };
|
|
111
|
+
return { kind: 'success', text: `${RESULT_PREFIX}当前任务模式已开启,风味:${flavorLabel(state.flavor)},从下次模型步骤生效。` };
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
store.rollback(agent.session, commandId);
|
|
115
|
+
return { kind: 'error', text: signal.aborted ? 'PUA 命令已取消。' : error instanceof Error ? error.message : String(error) };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":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AAC,EAAE,CAAC;IACzH,CAAC;AACH,CAAC","sourcesContent":["import type { CommandInvocation, CommandResult } from '@deepseek-ai/dsh-commands';\nimport { createUserMessage } from '@deepseek-ai/dsh-llm';\nimport { parseArgs, type Action } from './args.js';\nimport { flavorLabel, listFlavors } from './flavors.js';\nimport { StateStore, SESSION_RESULT_PREFIX as RESULT_PREFIX } from './state.js';\nimport type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess';\nimport type { QualityCommand } from './content.js';\nimport { collectGitEvidence, REVIEW_RULES } from './review.js';\nimport type { Context } from '@deepseek-ai/cordis';\nimport { SourceCatalog } from './source.js';\nimport type { PreferencesBridge } from './settings.js';\nimport { LOOP_START, type PuaRuntime } from './runtime.js';\n\ninterface Services { catalog: SourceCatalog; preferences: PreferencesBridge; runtime: PuaRuntime; ctx: Context }\n\nexport const HELP = `用法:\n/pua [任务描述]:开启 PUA;无描述时继续当前任务\n/pua review [范围]:只读审查,附带当前仓库 Git 索引证据(宿主可用时)\n/pua on / /pua off:只修改当前会话;不改变全局默认、不发起模型请求\n/pua config {\"subagents\":true}:修改当前会话参数\n/pua reset [参数名]:恢复单项或全部跟随全局\n/pua flavor [名称|auto]:列出、锁定或恢复自动选味,不自动开启\n/pua p7|p9|p10|pro|yes|mama|shot|pua-en|pua-ja [任务]:完整原版模式\n/pua ding [任务]:钉内/钉外味\n/pua loop \"任务\" --verify \"npm test\" --max-iterations 10:独立验收循环;省略参数使用当前会话生效默认值\n/pua cancel-pua-loop 或 /cancel-pua-loop:取消当前循环\n/pua kpi / /pua survey [quick]:原版 KPI 与本地问卷\n/pua offline:保持本地模式,无上传能力\n/pua team-status:当前会话及其 DSH 子代理状态\n/pua reap-orphans / /pua teardown-all:回收本插件循环;不删除其他工具管理的 worktree\n/pua again:针对当前目标换一种实质不同的方法\n/pua done-check:核对需求、交付结果、验收证据和缺口\n/pua evidence:核对已存在证据,指出未证明的结论\n/pua status:查看当前配置\n/pua -- 任务描述:任务以控制命令同名单词开头时使用\n原版冒号命令对应 DSH 空格子命令,例如 /pua:p9 → /pua p9。\n设置页命名空间:michengai-pua。无 settings 时降级为当前会话,默认关闭。`;\n\nfunction actionPrompt(action: Action, templates: ReadonlyMap<QualityCommand, string>, catalog: SourceCatalog): string | undefined {\n switch (action.kind) {\n case 'activate':\n return action.task ? `请处理下面用户指定的任务。任务正文:\\n\\n${action.task}`\n : '继续当前已授权任务:先核对目标和现有证据,诊断后完成剩余工作。若历史没有可识别任务,请用户提供目标,不自行编造任务。';\n case 'review':\n return `${REVIEW_RULES}\\n\\n用户审查范围:${action.task}`;\n case 'again': case 'done-check': case 'evidence':\n return templates.get(action.kind)! + (action.task ? `\\n\\n用户补充:${action.task}` : '');\n case 'mode':\n return `执行当前 ${action.mode} 完整原版模式。\\n${action.task || '继续当前已授权任务;历史无任务时请用户提供目标。'}`;\n case 'loop':\n return `按当前系统中的完整 PUA Loop 协议执行任务:${action.task}\\n本轮上限:${action.maxIterations || '无限'};${action.verify ? 'Oracle 使用用户指定命令独立验证。' : '未配置 Oracle,使用 honor system,不得声称独立验收通过。'}配置已由 DSH 接管,不运行 setup shell 脚本。`;\n case 'kpi':\n return catalog.body('commands/kpi.md') + '\\n\\n当前 pro 原版协议已完整注入;只基于实际证据生成报告卡,不编造历史。';\n case 'survey':\n return catalog.body('commands/survey.md') + '\\n\\n参数:' + (action.task ?? '') + (action.task === 'quick' ? '' : '\\n\\n' + catalog.body('skills/pua/references/survey.md'));\n default:\n return undefined;\n }\n}\n\n/** 执行原生命令;投递失败撤销临时状态,成功状态由宿主 command/done 日志恢复。 */\nexport async function handleCommand(store: StateStore, invocation: CommandInvocation, templates: ReadonlyMap<QualityCommand, string>, subprocess?: Pick<SubprocessRuntime, 'spawn'>, services?: Services): Promise<CommandResult> {\n const { agent, signal, commandId } = invocation;\n try {\n signal.throwIfAborted();\n const action = parseArgs(invocation.rawInput, store.configuration(agent.session));\n if (action.kind === 'help') return { kind: 'success', text: RESULT_PREFIX + HELP };\n if (action.kind === 'flavors') return { kind: 'success', text: RESULT_PREFIX + listFlavors() + '\\n例如:/pua flavor huawei' };\n if (action.kind === 'status') {\n const state = store.read(agent.session);\n return { kind: 'success', text: `${RESULT_PREFIX}${state.enabled ? '已开启' : '已关闭'};模式:${services?.runtime.effectiveMode(agent.session, state.mode) ?? state.mode};风味:${state.flavorLocked ? flavorLabel(state.flavor) + '(锁定)' : '自动路由'}。\\n${services?.preferences.description() ?? '当前会话'};原版 3.5.1 完整正文。\\n${services?.runtime.status(agent.session) ?? ''}` };\n }\n if (action.kind === 'team-status') {\n const agents = services?.ctx.get('agents')?.list().filter(item => item.id === agent.id || item.session.header.parentSession === agent.id) ?? [];\n return { kind: 'success', text: RESULT_PREFIX + (agents.length ? agents.map(item => `${item.id} | ${item.status}`).join('\\n') : '宿主未提供子代理状态。') + '\\n' + (services?.runtime.status(agent.session) ?? '') + '\\nDSH Agent 由宿主管理,无原版 PID/TTL 文件。' };\n }\n if (action.kind === 'reap-orphans') return { kind: 'success', text: RESULT_PREFIX + 'DSH 已在取消、异常结束和卸载时回收本插件循环;没有独立后台进程或 .claude 孤儿状态可清理。其他工具的子代理/worktree 由所属工具管理。' };\n if (action.kind === 'loop' && action.verify && (!subprocess || !agent.session.header.cwd)) throw new Error('独立验收需要宿主 subprocess 和会话工作目录;未启动循环。');\n // 只读预检完成且未取消后才暂存开关;等待期间不让其他模型请求误用未完成配置。\n const evidence = action.kind === 'review' ? await collectGitEvidence(subprocess, agent.session.header.cwd, signal) : undefined;\n signal.throwIfAborted();\n if (action.kind === 'off' || action.kind === 'cancel-pua-loop' || action.kind === 'loop') services?.runtime.cancel(agent.session);\n const stopped = action.kind === 'teardown-all' ? services?.runtime.cancelAll() ?? 0 : 0;\n store.stage(agent.session, commandId, action);\n const state = store.read(agent.session);\n if (!state.enabled) services?.runtime.cancel(agent.session);\n if (action.kind === 'configure') return { kind: 'success', text: RESULT_PREFIX + '会话配置已保存;未覆盖项继续跟随全局。' };\n const task = actionPrompt(action, templates, services?.catalog ?? new SourceCatalog());\n if (task !== undefined) {\n signal.throwIfAborted();\n const message = createUserMessage({\n content: [{ type: 'text', text: `${action.kind === 'loop' ? LOOP_START + JSON.stringify({ ...action, id: commandId }) + '\\n' : ''}这是通过 /pua 提交的用户请求。是否使用 PUA 及所选风味,以执行时的 DSH PUA 当前状态为准;如果用户已关闭模式,正常处理任务,不因这条历史请求重新启用。启用时执行完整原版核心、展示协议及当前角色,不能用摘要替代。遵循宿主权限与用户最新要求。\\n\\n${task}${evidence === undefined ? '' : '\\n\\n' + evidence}` }],\n source: { kind: 'plugin', plugin: '@michengai/dsh-pua' },\n });\n // 明确的新任务排入后续轮次;对当前任务的纠偏在最近的步骤边界生效。\n if (action.kind === 'review' || action.kind === 'loop' || (action.kind === 'mode' && action.task) || (action.kind === 'activate' && action.task)) agent.followup(message);\n else agent.steer(message);\n return { kind: 'success', text: `${RESULT_PREFIX}已提交${action.kind === 'review' ? '只读审查' : action.kind === 'mode' ? action.mode + ' 模式' : action.kind === 'loop' ? 'Loop' : action.kind === 'done-check' ? '完成检查' : action.kind === 'evidence' ? '证据检查' : action.kind === 'again' ? '换方法请求' : action.kind === 'activate' ? '任务请求' : action.kind},风味:${state.flavorLocked ? flavorLabel(state.flavor) : '自动路由'}。请查看 Agent 后续结果。${action.kind === 'loop' ? '\\n' + (action.verify ? 'Oracle:用户指定验证命令。' : '未配置 Oracle,仅 honor system。') : ''}${evidence?.startsWith('未获取') ? '\\nGit 预检未取得证据,已要求 Agent 补充只读验证。' : ''}` };\n }\n if (action.kind === 'cancel-pua-loop') return { kind: 'success', text: RESULT_PREFIX + '当前 Loop 已取消,不再自动续轮。' };\n if (action.kind === 'teardown-all') return { kind: 'success', text: `${RESULT_PREFIX}已停止本插件管理的 ${stopped} 个循环;未删除宿主子代理或其他工具的 worktree。` };\n if (action.kind === 'offline') return { kind: 'success', text: RESULT_PREFIX + '保持本地模式,无联网刷新或上报能力。' };\n if (action.kind === 'off') return { kind: 'success', text: RESULT_PREFIX + 'PUA 已关闭,Loop 已取消。范围:' + (services?.preferences.description() ?? '当前会话') + '。' };\n if (action.kind === 'flavor') return { kind: 'success', text: `${RESULT_PREFIX}${state.flavorLocked ? '已锁定' + flavorLabel(state.flavor) : '已恢复自动路由'};当前模式${state.enabled ? '已开启' : '仍关闭'}。范围:${services?.preferences.description() ?? '当前会话'}。` };\n return { kind: 'success', text: `${RESULT_PREFIX}当前任务模式已开启,风味:${flavorLabel(state.flavor)},从下次模型步骤生效。` };\n } catch (error) {\n store.rollback(agent.session, commandId);\n return { kind: 'error', text: signal.aborted ? 'PUA 命令已取消。' : error instanceof Error ? error.message : String(error) };\n }\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** 全局默认与会话覆盖共用的参数契约;null 仅在覆盖补丁中表示恢复继承。 */
|
|
3
|
+
export declare const CONFIG_MODES: readonly ["pua", "p7", "p9", "p10", "pro", "yes", "mama", "shot", "pua-en", "pua-ja"];
|
|
4
|
+
export declare const configSchema: z.ZodObject<{
|
|
5
|
+
enabled: z.ZodBoolean;
|
|
6
|
+
flavor: z.ZodEnum<{
|
|
7
|
+
alibaba: "alibaba";
|
|
8
|
+
bytedance: "bytedance";
|
|
9
|
+
huawei: "huawei";
|
|
10
|
+
tencent: "tencent";
|
|
11
|
+
baidu: "baidu";
|
|
12
|
+
pinduoduo: "pinduoduo";
|
|
13
|
+
meituan: "meituan";
|
|
14
|
+
jd: "jd";
|
|
15
|
+
xiaomi: "xiaomi";
|
|
16
|
+
netflix: "netflix";
|
|
17
|
+
tesla: "tesla";
|
|
18
|
+
apple: "apple";
|
|
19
|
+
amazon: "amazon";
|
|
20
|
+
microsoft: "microsoft";
|
|
21
|
+
ding: "ding";
|
|
22
|
+
auto: "auto";
|
|
23
|
+
}>;
|
|
24
|
+
mode: z.ZodEnum<{
|
|
25
|
+
pua: "pua";
|
|
26
|
+
p7: "p7";
|
|
27
|
+
p9: "p9";
|
|
28
|
+
p10: "p10";
|
|
29
|
+
pro: "pro";
|
|
30
|
+
yes: "yes";
|
|
31
|
+
mama: "mama";
|
|
32
|
+
shot: "shot";
|
|
33
|
+
"pua-en": "pua-en";
|
|
34
|
+
"pua-ja": "pua-ja";
|
|
35
|
+
}>;
|
|
36
|
+
subagents: z.ZodBoolean;
|
|
37
|
+
terminalReview: z.ZodBoolean;
|
|
38
|
+
failureCandidates: z.ZodBoolean;
|
|
39
|
+
qualityTriggers: z.ZodBoolean;
|
|
40
|
+
offline: z.ZodBoolean;
|
|
41
|
+
feedbackFrequency: z.ZodNumber;
|
|
42
|
+
maxIterations: z.ZodNumber;
|
|
43
|
+
verify: z.ZodString;
|
|
44
|
+
verificationTimeout: z.ZodNumber;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
export type Configuration = z.infer<typeof configSchema>;
|
|
47
|
+
export declare const patchSchema: z.ZodObject<{
|
|
48
|
+
[x: string]: z.ZodOptional<z.ZodNullable<z.ZodBoolean>> | z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
49
|
+
alibaba: "alibaba";
|
|
50
|
+
bytedance: "bytedance";
|
|
51
|
+
huawei: "huawei";
|
|
52
|
+
tencent: "tencent";
|
|
53
|
+
baidu: "baidu";
|
|
54
|
+
pinduoduo: "pinduoduo";
|
|
55
|
+
meituan: "meituan";
|
|
56
|
+
jd: "jd";
|
|
57
|
+
xiaomi: "xiaomi";
|
|
58
|
+
netflix: "netflix";
|
|
59
|
+
tesla: "tesla";
|
|
60
|
+
apple: "apple";
|
|
61
|
+
amazon: "amazon";
|
|
62
|
+
microsoft: "microsoft";
|
|
63
|
+
ding: "ding";
|
|
64
|
+
auto: "auto";
|
|
65
|
+
}>>> | z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
66
|
+
pua: "pua";
|
|
67
|
+
p7: "p7";
|
|
68
|
+
p9: "p9";
|
|
69
|
+
p10: "p10";
|
|
70
|
+
pro: "pro";
|
|
71
|
+
yes: "yes";
|
|
72
|
+
mama: "mama";
|
|
73
|
+
shot: "shot";
|
|
74
|
+
"pua-en": "pua-en";
|
|
75
|
+
"pua-ja": "pua-ja";
|
|
76
|
+
}>>> | z.ZodOptional<z.ZodNullable<z.ZodNumber>> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
export type ConfigurationPatch = {
|
|
79
|
+
[K in keyof Configuration]?: Configuration[K] | null;
|
|
80
|
+
};
|
|
81
|
+
export declare const CONFIG_DEFAULTS: Configuration;
|
|
82
|
+
export declare const CONFIG_KEYS: (keyof Configuration)[];
|
|
83
|
+
export declare const loopStartSchema: z.ZodObject<{
|
|
84
|
+
task: z.ZodString;
|
|
85
|
+
maxIterations: z.ZodNumber;
|
|
86
|
+
verify: z.ZodString;
|
|
87
|
+
verificationTimeout: z.ZodNumber;
|
|
88
|
+
}, z.core.$strict>;
|
|
89
|
+
export declare function parsePatch(value: unknown): ConfigurationPatch;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { FLAVORS } from './flavors.js';
|
|
3
|
+
/** 全局默认与会话覆盖共用的参数契约;null 仅在覆盖补丁中表示恢复继承。 */
|
|
4
|
+
export const CONFIG_MODES = ['pua', 'p7', 'p9', 'p10', 'pro', 'yes', 'mama', 'shot', 'pua-en', 'pua-ja'];
|
|
5
|
+
export const configSchema = z.object({
|
|
6
|
+
enabled: z.boolean(),
|
|
7
|
+
flavor: z.enum(['auto', ...FLAVORS.map(item => item.id)]),
|
|
8
|
+
mode: z.enum(CONFIG_MODES),
|
|
9
|
+
subagents: z.boolean(),
|
|
10
|
+
terminalReview: z.boolean(),
|
|
11
|
+
failureCandidates: z.boolean(),
|
|
12
|
+
qualityTriggers: z.boolean(),
|
|
13
|
+
offline: z.boolean(),
|
|
14
|
+
feedbackFrequency: z.number().int().min(0).max(9999),
|
|
15
|
+
maxIterations: z.number().int().min(0).max(10000),
|
|
16
|
+
verify: z.string().max(8192),
|
|
17
|
+
verificationTimeout: z.number().int().min(1).max(3600),
|
|
18
|
+
}).strict();
|
|
19
|
+
export const patchSchema = configSchema.partial().extend({
|
|
20
|
+
...Object.fromEntries(Object.entries(configSchema.shape).map(([key, schema]) => [key, schema.nullable().optional()])),
|
|
21
|
+
}).strict();
|
|
22
|
+
export const CONFIG_DEFAULTS = { enabled: true, flavor: 'auto', mode: 'pua', subagents: false,
|
|
23
|
+
terminalReview: true, failureCandidates: true, qualityTriggers: true, offline: false,
|
|
24
|
+
feedbackFrequency: 5, maxIterations: 0, verify: '', verificationTimeout: 120 };
|
|
25
|
+
export const CONFIG_KEYS = Object.keys(CONFIG_DEFAULTS);
|
|
26
|
+
export const loopStartSchema = z.object({ task: z.string().trim().min(1).max(4096), maxIterations: configSchema.shape.maxIterations,
|
|
27
|
+
verify: configSchema.shape.verify, verificationTimeout: configSchema.shape.verificationTimeout }).strict();
|
|
28
|
+
export function parsePatch(value) {
|
|
29
|
+
return patchSchema.parse(value);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,2CAA2C;AAC3C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAClH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,GAAG,O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,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK;IAC1G,cAAc,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK;IACpF,iBAAiB,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC;AACjF,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAA4B,CAAC;AACnF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,aAAa,EAAE,YAAY,CAAC,KAAK,CAAC,aAAa;IACjI,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,mBAAmB,EAAE,YAAY,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAC7G,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,CAAuB,CAAC;AACxD,CAAC","sourcesContent":["import { z } from 'zod';\nimport { FLAVORS } from './flavors.js';\n\n/** 全局默认与会话覆盖共用的参数契约;null 仅在覆盖补丁中表示恢复继承。 */\nexport const CONFIG_MODES = ['pua', 'p7', 'p9', 'p10', 'pro', 'yes', 'mama', 'shot', 'pua-en', 'pua-ja'] as const;\nexport const configSchema = z.object({\n enabled: z.boolean(),\n flavor: z.enum(['auto', ...FLAVORS.map(item => item.id)]),\n mode: z.enum(CONFIG_MODES),\n subagents: z.boolean(),\n terminalReview: z.boolean(),\n failureCandidates: z.boolean(),\n qualityTriggers: z.boolean(),\n offline: z.boolean(),\n feedbackFrequency: z.number().int().min(0).max(9999),\n maxIterations: z.number().int().min(0).max(10000),\n verify: z.string().max(8192),\n verificationTimeout: z.number().int().min(1).max(3600),\n}).strict();\nexport type Configuration = z.infer<typeof configSchema>;\nexport const patchSchema = configSchema.partial().extend({\n ...Object.fromEntries(Object.entries(configSchema.shape).map(([key, schema]) => [key, schema.nullable().optional()])),\n}).strict();\nexport type ConfigurationPatch = { [K in keyof Configuration]?: Configuration[K] | null };\nexport const CONFIG_DEFAULTS: Configuration = { enabled: true, flavor: 'auto', mode: 'pua', subagents: false,\n terminalReview: true, failureCandidates: true, qualityTriggers: true, offline: false,\n feedbackFrequency: 5, maxIterations: 0, verify: '', verificationTimeout: 120 };\nexport const CONFIG_KEYS = Object.keys(CONFIG_DEFAULTS) as (keyof Configuration)[];\nexport const loopStartSchema = z.object({ task: z.string().trim().min(1).max(4096), maxIterations: configSchema.shape.maxIterations,\n verify: configSchema.shape.verify, verificationTimeout: configSchema.shape.verificationTimeout }).strict();\nexport function parsePatch(value: unknown): ConfigurationPatch {\n return patchSchema.parse(value) as ConfigurationPatch;\n}\n"]}
|
package/lib/content.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FlavorId } from './flavors.js';
|
|
2
|
+
import { SourceCatalog } from './source.js';
|
|
3
|
+
export declare const MAX_PROMPT_BYTES: number;
|
|
4
|
+
export declare const MODES: readonly ["pua", "p7", "p9", "p10", "pro", "yes", "mama", "pua-loop", "shot", "pua-en", "pua-ja"];
|
|
5
|
+
export type PuaMode = typeof MODES[number];
|
|
6
|
+
export declare const QUALITY_COMMANDS: readonly ["again", "done-check", "evidence"];
|
|
7
|
+
export type QualityCommand = typeof QUALITY_COMMANDS[number];
|
|
8
|
+
/** 防止原版字面模板被宿主变量插值执行;除此之外保留正文。 */
|
|
9
|
+
export declare function escapePromptLiteral(text: string): string;
|
|
10
|
+
/** 拼接原版完整核心和当前模式;模式差异由原版扩展协议提供。 */
|
|
11
|
+
export declare function renderOriginalPrompt(catalog: SourceCatalog, flavor: FlavorId | 'auto', mode?: PuaMode): string;
|
|
12
|
+
export declare function loadPrompts(): ReadonlyMap<FlavorId, string>;
|
|
13
|
+
export declare function loadCommandPrompts(): ReadonlyMap<QualityCommand, string>;
|
|
14
|
+
export declare const DISABLED_PROMPT = "## DSH PUA \u5F53\u524D\u72B6\u6001\n\u5F53\u524D\u4EFB\u52A1\u7684 PUA \u6A21\u5F0F\u5DF2\u5173\u95ED\u3002\u505C\u6B62\u6CBF\u7528\u5386\u53F2\u6D88\u606F\u3001\u538B\u7F29\u6458\u8981\u6216\u7236\u4F1A\u8BDD\u91CC\u7684 PUA \u65C1\u767D\u3001\u98CE\u5473\u53CA\u5347\u538B\u8981\u6C42\uFF1B\u7EE7\u7EED\u6309\u7528\u6237\u8981\u6C42\u6B63\u5E38\u5DE5\u4F5C\u3002\u53EA\u6709\u5F53\u524D\u4EFB\u52A1\u4E4B\u540E\u7684\u663E\u5F0F PUA \u8BF7\u6C42\u624D\u91CD\u65B0\u542F\u7528\u3002";
|
package/lib/content.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FLAVORS } from './flavors.js';
|
|
2
|
+
import { SourceCatalog } from './source.js';
|
|
3
|
+
export const MAX_PROMPT_BYTES = 192 * 1024;
|
|
4
|
+
export const MODES = ['pua', 'p7', 'p9', 'p10', 'pro', 'yes', 'mama', 'pua-loop', 'shot', 'pua-en', 'pua-ja'];
|
|
5
|
+
export const QUALITY_COMMANDS = ['again', 'done-check', 'evidence'];
|
|
6
|
+
const PLATFORM = `## DSH 平台映射(仅替换平台接口,原版行为与展示协议继续适用)
|
|
7
|
+
核心、风味、展示和角色协议均来自固定的 PUA 3.5.1 原文,正文未改写成摘要。
|
|
8
|
+
资料路径相对原版插件根目录。用 pua_reference 读取完整资料,用 list 查看目录;不要递归调用 /pua 路由加载自己。Read、Bash、Skill、Task 等名字表示原宿主能力,在 DSH 中使用当前实际提供的读取、PowerShell/终端、技能和子代理工具。
|
|
9
|
+
开关、风味与离线设置由 /pua 原生命令和 DSH settings 管理;不要执行原文写 ~/.pua/config.json 或 .claude 状态的 shell 片段。命令返回信息说明实际持久化范围。用户当前指定和锁定的风味优先,auto 保留原版智能路由。
|
|
10
|
+
Loop 由本插件的 DSH 停止边界驱动;当前请求未显式启动 loop 时不运行循环。配置、取消、上限和独立验证结果以宿主实际反馈为准,不自行写状态文件或声称已安装原版 shell hook。
|
|
11
|
+
子代理使用 DSH 当前可用能力,传递完整核心和角色资料;无能力就明确限制,不虚构队友、进程或结果。团队清理由宿主资源归属管理,不执行原版跨项目删除脚本。
|
|
12
|
+
长期自进化和问卷仅在用户明确选择对应入口且宿主允许时执行;未启用的能力不能自行扩张。原版 Pro 末尾“联网功能已移除”适用于整份文档,不执行早期段落中残留的远端刷新或上报说明。
|
|
13
|
+
PUA 保留原版角色、狠话、旁白、方框面板和 Owner 要求;原版运行契约中关于任务范围、真实证据、用户锁定、授权和不重复验收的口径同样保留。`;
|
|
14
|
+
/** 防止原版字面模板被宿主变量插值执行;除此之外保留正文。 */
|
|
15
|
+
export function escapePromptLiteral(text) { return text.replaceAll('{{', '{ {'); }
|
|
16
|
+
/** 拼接原版完整核心和当前模式;模式差异由原版扩展协议提供。 */
|
|
17
|
+
export function renderOriginalPrompt(catalog, flavor, mode = 'pua') {
|
|
18
|
+
const parts = [catalog.body('skills/pua/SKILL.md'), catalog.body('skills/pua/references/display-protocol.md'), catalog.body('skills/pua/references/methodology-router.md')];
|
|
19
|
+
if (mode !== 'pua')
|
|
20
|
+
parts.push(catalog.body(`skills/${mode}/SKILL.md`));
|
|
21
|
+
if (mode === 'pro')
|
|
22
|
+
parts.push(catalog.body('skills/pua/references/evolution-protocol.md'), catalog.body('skills/pua/references/platform.md'));
|
|
23
|
+
if (mode === 'p7' || mode === 'p9' || mode === 'p10')
|
|
24
|
+
parts.push(catalog.body(`skills/pua/references/${mode}-protocol.md`));
|
|
25
|
+
if (mode === 'p9' || mode === 'p10')
|
|
26
|
+
parts.push(catalog.body('skills/pua/references/agent-team.md'));
|
|
27
|
+
if (flavor !== 'auto') {
|
|
28
|
+
const descriptor = FLAVORS.find(item => item.id === flavor);
|
|
29
|
+
const section = catalog.body('skills/pua/references/flavors.md').split(/(?=^## \d+\. )/mu).find(text => text.startsWith(`## ${descriptor.chapter}. `));
|
|
30
|
+
if (!section)
|
|
31
|
+
throw new Error(`原版风味章节缺失:${flavor}`);
|
|
32
|
+
parts.push(section.trim(), catalog.body(`skills/pua/references/methodology-${flavor}.md`));
|
|
33
|
+
if (flavor === 'ding')
|
|
34
|
+
parts.push(catalog.body('skills/pua/references/ding-reminders.md'));
|
|
35
|
+
}
|
|
36
|
+
parts.push(PLATFORM, `当前 DSH 模式:${mode}。${flavor === 'auto' ? '风味未锁定,按原版方法论路由选择;无可识别任务时从阿里味开始。' : `用户锁定风味:${flavor},自动路由不得更换表达风格。`} ${mode === 'yes' || mode === 'mama' ? `本次显式选择 ${mode},其原版情绪表达替代默认领导语气,行为底线继续生效。` : ''}`);
|
|
37
|
+
const prompt = escapePromptLiteral(parts.join('\n\n'));
|
|
38
|
+
if (Buffer.byteLength(prompt, 'utf8') > MAX_PROMPT_BYTES)
|
|
39
|
+
throw new Error(`原版 ${mode}/${flavor} 超出提示词预算,请检查素材,不得静默截断。`);
|
|
40
|
+
return prompt;
|
|
41
|
+
}
|
|
42
|
+
export function loadPrompts() {
|
|
43
|
+
const catalog = new SourceCatalog();
|
|
44
|
+
return new Map(FLAVORS.map(flavor => [flavor.id, renderOriginalPrompt(catalog, flavor.id)]));
|
|
45
|
+
}
|
|
46
|
+
export function loadCommandPrompts() {
|
|
47
|
+
const catalog = new SourceCatalog();
|
|
48
|
+
return new Map(QUALITY_COMMANDS.map(name => [name, catalog.body(`commands/${name}.md`)]));
|
|
49
|
+
}
|
|
50
|
+
export const DISABLED_PROMPT = '## DSH PUA 当前状态\n当前任务的 PUA 模式已关闭。停止沿用历史消息、压缩摘要或父会话里的 PUA 旁白、风味及升压要求;继续按用户要求正常工作。只有当前任务之后的显式 PUA 请求才重新启用。';
|
|
51
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAEvH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,CAAU,CAAC;AAG7E,MAAM,QAAQ,GAAG;;;;;;;yEAOwD,CAAC;AAE1E,kCAAkC;AAClC,MAAM,UAAU,mBAAmB,CAAC,IAAY,IAAY,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAElG,mCAAmC;AACnC,MAAM,UAAU,oBAAoB,CAAC,OAAsB,EAAE,MAAyB,EAAE,OAAgB,KAAK;IAC3G,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,2CAA2C,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC,CAAC;IAC5K,IAAI,IAAI,KAAK,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,WAAW,CAAC,CAAC,CAAC;IACxE,IAAI,IAAI,KAAK,KAAK;QAAE,KAAK,CAAC,IAAI,CAA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U,MAAM,gBAAgB,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,IAAI,4BAA4B,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7N,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,MAAM,wBAAwB,CAAC,CAAC;IACxH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IACpC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/F,CAAC;AACD,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IACpC,OAAO,IAAI,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5F,CAAC;AACD,MAAM,CAAC,MAAM,eAAe,GAAG,0GAA0G,CAAC","sourcesContent":["import { FLAVORS, type FlavorId } from './flavors.js';\nimport { SourceCatalog } from './source.js';\n\nexport const MAX_PROMPT_BYTES = 192 * 1024;\nexport const MODES = ['pua', 'p7', 'p9', 'p10', 'pro', 'yes', 'mama', 'pua-loop', 'shot', 'pua-en', 'pua-ja'] as const;\nexport type PuaMode = typeof MODES[number];\nexport const QUALITY_COMMANDS = ['again', 'done-check', 'evidence'] as const;\nexport type QualityCommand = typeof QUALITY_COMMANDS[number];\n\nconst PLATFORM = `## DSH 平台映射(仅替换平台接口,原版行为与展示协议继续适用)\n核心、风味、展示和角色协议均来自固定的 PUA 3.5.1 原文,正文未改写成摘要。\n资料路径相对原版插件根目录。用 pua_reference 读取完整资料,用 list 查看目录;不要递归调用 /pua 路由加载自己。Read、Bash、Skill、Task 等名字表示原宿主能力,在 DSH 中使用当前实际提供的读取、PowerShell/终端、技能和子代理工具。\n开关、风味与离线设置由 /pua 原生命令和 DSH settings 管理;不要执行原文写 ~/.pua/config.json 或 .claude 状态的 shell 片段。命令返回信息说明实际持久化范围。用户当前指定和锁定的风味优先,auto 保留原版智能路由。\nLoop 由本插件的 DSH 停止边界驱动;当前请求未显式启动 loop 时不运行循环。配置、取消、上限和独立验证结果以宿主实际反馈为准,不自行写状态文件或声称已安装原版 shell hook。\n子代理使用 DSH 当前可用能力,传递完整核心和角色资料;无能力就明确限制,不虚构队友、进程或结果。团队清理由宿主资源归属管理,不执行原版跨项目删除脚本。\n长期自进化和问卷仅在用户明确选择对应入口且宿主允许时执行;未启用的能力不能自行扩张。原版 Pro 末尾“联网功能已移除”适用于整份文档,不执行早期段落中残留的远端刷新或上报说明。\nPUA 保留原版角色、狠话、旁白、方框面板和 Owner 要求;原版运行契约中关于任务范围、真实证据、用户锁定、授权和不重复验收的口径同样保留。`;\n\n/** 防止原版字面模板被宿主变量插值执行;除此之外保留正文。 */\nexport function escapePromptLiteral(text: string): string { return text.replaceAll('{{', '{ {'); }\n\n/** 拼接原版完整核心和当前模式;模式差异由原版扩展协议提供。 */\nexport function renderOriginalPrompt(catalog: SourceCatalog, flavor: FlavorId | 'auto', mode: PuaMode = 'pua'): string {\n const parts = [catalog.body('skills/pua/SKILL.md'), catalog.body('skills/pua/references/display-protocol.md'), catalog.body('skills/pua/references/methodology-router.md')];\n if (mode !== 'pua') parts.push(catalog.body(`skills/${mode}/SKILL.md`));\n if (mode === 'pro') parts.push(catalog.body('skills/pua/references/evolution-protocol.md'), catalog.body('skills/pua/references/platform.md'));\n if (mode === 'p7' || mode === 'p9' || mode === 'p10') parts.push(catalog.body(`skills/pua/references/${mode}-protocol.md`));\n if (mode === 'p9' || mode === 'p10') parts.push(catalog.body('skills/pua/references/agent-team.md'));\n if (flavor !== 'auto') {\n const descriptor = FLAVORS.find(item => item.id === flavor)!;\n const section = catalog.body('skills/pua/references/flavors.md').split(/(?=^## \\d+\\. )/mu).find(text => text.startsWith(`## ${descriptor.chapter}. `));\n if (!section) throw new Error(`原版风味章节缺失:${flavor}`);\n parts.push(section.trim(), catalog.body(`skills/pua/references/methodology-${flavor}.md`));\n if (flavor === 'ding') parts.push(catalog.body('skills/pua/references/ding-reminders.md'));\n }\n parts.push(PLATFORM, `当前 DSH 模式:${mode}。${flavor === 'auto' ? '风味未锁定,按原版方法论路由选择;无可识别任务时从阿里味开始。' : `用户锁定风味:${flavor},自动路由不得更换表达风格。`} ${mode === 'yes' || mode === 'mama' ? `本次显式选择 ${mode},其原版情绪表达替代默认领导语气,行为底线继续生效。` : ''}`);\n const prompt = escapePromptLiteral(parts.join('\\n\\n'));\n if (Buffer.byteLength(prompt, 'utf8') > MAX_PROMPT_BYTES) throw new Error(`原版 ${mode}/${flavor} 超出提示词预算,请检查素材,不得静默截断。`);\n return prompt;\n}\n\nexport function loadPrompts(): ReadonlyMap<FlavorId, string> {\n const catalog = new SourceCatalog();\n return new Map(FLAVORS.map(flavor => [flavor.id, renderOriginalPrompt(catalog, flavor.id)]));\n}\nexport function loadCommandPrompts(): ReadonlyMap<QualityCommand, string> {\n const catalog = new SourceCatalog();\n return new Map(QUALITY_COMMANDS.map(name => [name, catalog.body(`commands/${name}.md`)]));\n}\nexport const DISABLED_PROMPT = '## DSH PUA 当前状态\\n当前任务的 PUA 模式已关闭。停止沿用历史消息、压缩摘要或父会话里的 PUA 旁白、风味及升压要求;继续按用户要求正常工作。只有当前任务之后的显式 PUA 请求才重新启用。';\r\n"]}
|
package/lib/flavors.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** 风味白名单与原版章节对应关系;任何用户输入都不能直接构造素材路径。 */
|
|
2
|
+
export declare const FLAVORS: readonly [{
|
|
3
|
+
readonly id: "alibaba";
|
|
4
|
+
readonly label: "阿里";
|
|
5
|
+
readonly aliases: readonly ["阿里", "阿里巴巴"];
|
|
6
|
+
readonly chapter: 1;
|
|
7
|
+
}, {
|
|
8
|
+
readonly id: "bytedance";
|
|
9
|
+
readonly label: "字节";
|
|
10
|
+
readonly aliases: readonly ["字节", "字节跳动"];
|
|
11
|
+
readonly chapter: 2;
|
|
12
|
+
}, {
|
|
13
|
+
readonly id: "huawei";
|
|
14
|
+
readonly label: "华为";
|
|
15
|
+
readonly aliases: readonly ["华为"];
|
|
16
|
+
readonly chapter: 3;
|
|
17
|
+
}, {
|
|
18
|
+
readonly id: "tencent";
|
|
19
|
+
readonly label: "腾讯";
|
|
20
|
+
readonly aliases: readonly ["腾讯"];
|
|
21
|
+
readonly chapter: 4;
|
|
22
|
+
}, {
|
|
23
|
+
readonly id: "baidu";
|
|
24
|
+
readonly label: "百度";
|
|
25
|
+
readonly aliases: readonly ["百度"];
|
|
26
|
+
readonly chapter: 5;
|
|
27
|
+
}, {
|
|
28
|
+
readonly id: "pinduoduo";
|
|
29
|
+
readonly label: "拼多多";
|
|
30
|
+
readonly aliases: readonly ["拼多多"];
|
|
31
|
+
readonly chapter: 6;
|
|
32
|
+
}, {
|
|
33
|
+
readonly id: "meituan";
|
|
34
|
+
readonly label: "美团";
|
|
35
|
+
readonly aliases: readonly ["美团"];
|
|
36
|
+
readonly chapter: 7;
|
|
37
|
+
}, {
|
|
38
|
+
readonly id: "jd";
|
|
39
|
+
readonly label: "京东";
|
|
40
|
+
readonly aliases: readonly ["京东"];
|
|
41
|
+
readonly chapter: 8;
|
|
42
|
+
}, {
|
|
43
|
+
readonly id: "xiaomi";
|
|
44
|
+
readonly label: "小米";
|
|
45
|
+
readonly aliases: readonly ["小米"];
|
|
46
|
+
readonly chapter: 9;
|
|
47
|
+
}, {
|
|
48
|
+
readonly id: "netflix";
|
|
49
|
+
readonly label: "Netflix";
|
|
50
|
+
readonly aliases: readonly ["奈飞"];
|
|
51
|
+
readonly chapter: 10;
|
|
52
|
+
}, {
|
|
53
|
+
readonly id: "tesla";
|
|
54
|
+
readonly label: "Musk";
|
|
55
|
+
readonly aliases: readonly ["musk", "马斯克", "特斯拉"];
|
|
56
|
+
readonly chapter: 11;
|
|
57
|
+
}, {
|
|
58
|
+
readonly id: "apple";
|
|
59
|
+
readonly label: "Jobs";
|
|
60
|
+
readonly aliases: readonly ["jobs", "乔布斯", "苹果"];
|
|
61
|
+
readonly chapter: 12;
|
|
62
|
+
}, {
|
|
63
|
+
readonly id: "amazon";
|
|
64
|
+
readonly label: "Amazon";
|
|
65
|
+
readonly aliases: readonly ["亚马逊"];
|
|
66
|
+
readonly chapter: 13;
|
|
67
|
+
}, {
|
|
68
|
+
readonly id: "microsoft";
|
|
69
|
+
readonly label: "Microsoft";
|
|
70
|
+
readonly aliases: readonly ["微软"];
|
|
71
|
+
readonly chapter: 14;
|
|
72
|
+
}, {
|
|
73
|
+
readonly id: "ding";
|
|
74
|
+
readonly label: "钉内/钉外";
|
|
75
|
+
readonly aliases: readonly ["钉味", "钉钉", "钉内", "钉外"];
|
|
76
|
+
readonly chapter: 15;
|
|
77
|
+
}];
|
|
78
|
+
export type FlavorId = (typeof FLAVORS)[number]['id'];
|
|
79
|
+
/** 解析公开标识或别名;未知名称返回 undefined。 */
|
|
80
|
+
export declare function resolveFlavor(value: string): FlavorId | undefined;
|
|
81
|
+
export declare function flavorLabel(id: FlavorId): string;
|
|
82
|
+
export declare function listFlavors(): string;
|
package/lib/flavors.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 风味白名单与原版章节对应关系;任何用户输入都不能直接构造素材路径。 */
|
|
2
|
+
export const FLAVORS = [
|
|
3
|
+
{ id: 'alibaba', label: '阿里', aliases: ['阿里', '阿里巴巴'], chapter: 1 },
|
|
4
|
+
{ id: 'bytedance', label: '字节', aliases: ['字节', '字节跳动'], chapter: 2 },
|
|
5
|
+
{ id: 'huawei', label: '华为', aliases: ['华为'], chapter: 3 },
|
|
6
|
+
{ id: 'tencent', label: '腾讯', aliases: ['腾讯'], chapter: 4 },
|
|
7
|
+
{ id: 'baidu', label: '百度', aliases: ['百度'], chapter: 5 },
|
|
8
|
+
{ id: 'pinduoduo', label: '拼多多', aliases: ['拼多多'], chapter: 6 },
|
|
9
|
+
{ id: 'meituan', label: '美团', aliases: ['美团'], chapter: 7 },
|
|
10
|
+
{ id: 'jd', label: '京东', aliases: ['京东'], chapter: 8 },
|
|
11
|
+
{ id: 'xiaomi', label: '小米', aliases: ['小米'], chapter: 9 },
|
|
12
|
+
{ id: 'netflix', label: 'Netflix', aliases: ['奈飞'], chapter: 10 },
|
|
13
|
+
{ id: 'tesla', label: 'Musk', aliases: ['musk', '马斯克', '特斯拉'], chapter: 11 },
|
|
14
|
+
{ id: 'apple', label: 'Jobs', aliases: ['jobs', '乔布斯', '苹果'], chapter: 12 },
|
|
15
|
+
{ id: 'amazon', label: 'Amazon', aliases: ['亚马逊'], chapter: 13 },
|
|
16
|
+
{ id: 'microsoft', label: 'Microsoft', aliases: ['微软'], chapter: 14 },
|
|
17
|
+
{ id: 'ding', label: '钉内/钉外', aliases: ['钉味', '钉钉', '钉内', '钉外'], chapter: 15 },
|
|
18
|
+
];
|
|
19
|
+
/** 解析公开标识或别名;未知名称返回 undefined。 */
|
|
20
|
+
export function resolveFlavor(value) {
|
|
21
|
+
const normalized = value.toLowerCase();
|
|
22
|
+
return FLAVORS.find(item => item.id === normalized || item.aliases.some(alias => alias === normalized))?.id;
|
|
23
|
+
}
|
|
24
|
+
export function flavorLabel(id) {
|
|
25
|
+
return FLAVORS.find(item => item.id === id).label;
|
|
26
|
+
}
|
|
27
|
+
export function listFlavors() {
|
|
28
|
+
return FLAVORS.map(item => `${item.id}(${item.label})`).join('、');
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=flavors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flavors.js","sourceRoot":"","sources":["../src/flavors.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IACnE,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IACrE,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IAC1D,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IAC3D,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IACzD,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IAC/D,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IAC3D,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IACtD,EAAE,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AAE,CAAC;AAC9G,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAY;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAE,CAAC,KAAK,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpE,CAAC","sourcesContent":["/** 风味白名单与原版章节对应关系;任何用户输入都不能直接构造素材路径。 */\nexport const FLAVORS = [\n { id: 'alibaba', label: '阿里', aliases: ['阿里', '阿里巴巴'], chapter: 1 },\n { id: 'bytedance', label: '字节', aliases: ['字节', '字节跳动'], chapter: 2 },\n { id: 'huawei', label: '华为', aliases: ['华为'], chapter: 3 },\n { id: 'tencent', label: '腾讯', aliases: ['腾讯'], chapter: 4 },\n { id: 'baidu', label: '百度', aliases: ['百度'], chapter: 5 },\n { id: 'pinduoduo', label: '拼多多', aliases: ['拼多多'], chapter: 6 },\n { id: 'meituan', label: '美团', aliases: ['美团'], chapter: 7 },\n { id: 'jd', label: '京东', aliases: ['京东'], chapter: 8 },\n { id: 'xiaomi', label: '小米', aliases: ['小米'], chapter: 9 },\n { id: 'netflix', label: 'Netflix', aliases: ['奈飞'], chapter: 10 },\n { id: 'tesla', label: 'Musk', aliases: ['musk', '马斯克', '特斯拉'], chapter: 11 },\n { id: 'apple', label: 'Jobs', aliases: ['jobs', '乔布斯', '苹果'], chapter: 12 },\n { id: 'amazon', label: 'Amazon', aliases: ['亚马逊'], chapter: 13 },\n { id: 'microsoft', label: 'Microsoft', aliases: ['微软'], chapter: 14 },\n { id: 'ding', label: '钉内/钉外', aliases: ['钉味', '钉钉', '钉内', '钉外'], chapter: 15 },\n] as const;\n\nexport type FlavorId = (typeof FLAVORS)[number]['id'];\n\n/** 解析公开标识或别名;未知名称返回 undefined。 */\nexport function resolveFlavor(value: string): FlavorId | undefined {\n const normalized = value.toLowerCase();\n return FLAVORS.find(item => item.id === normalized || item.aliases.some(alias => alias === normalized))?.id;\n}\n\nexport function flavorLabel(id: FlavorId): string {\n return FLAVORS.find(item => item.id === id)!.label;\n}\n\nexport function listFlavors(): string {\n return FLAVORS.map(item => `${item.id}(${item.label})`).join('、');\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SourceCatalog } from './source.js';
|
|
2
|
+
import type { PuaState } from './state.js';
|
|
3
|
+
/** 只解析固定版本的模板,不执行上游 shell 或任意变量表达式。 */
|
|
4
|
+
export declare class HookContent {
|
|
5
|
+
private readonly failure;
|
|
6
|
+
private readonly flavors;
|
|
7
|
+
private readonly frustration;
|
|
8
|
+
readonly trigger: RegExp;
|
|
9
|
+
constructor(catalog: SourceCatalog);
|
|
10
|
+
private variables;
|
|
11
|
+
private interpolate;
|
|
12
|
+
frustrationPrompt(state: PuaState): string;
|
|
13
|
+
candidate(count: number, state: PuaState): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SourceCatalog } from './source.js';
|
|
2
|
+
/** 只解析固定版本的模板,不执行上游 shell 或任意变量表达式。 */
|
|
3
|
+
export class HookContent {
|
|
4
|
+
failure;
|
|
5
|
+
flavors;
|
|
6
|
+
frustration;
|
|
7
|
+
trigger;
|
|
8
|
+
constructor(catalog) {
|
|
9
|
+
this.failure = catalog.read('hooks/failure-detector.sh');
|
|
10
|
+
this.flavors = catalog.read('hooks/flavor-helper.sh');
|
|
11
|
+
this.frustration = catalog.read('hooks/frustration-trigger.sh');
|
|
12
|
+
const expression = /^TRIGGER_RE='(.*)'$/mu.exec(this.frustration)?.[1];
|
|
13
|
+
if (!expression)
|
|
14
|
+
throw new Error('原版质量纠偏触发规则缺失。');
|
|
15
|
+
this.trigger = new RegExp(expression.replaceAll('[:alnum:]', 'A-Za-z0-9'), 'iu');
|
|
16
|
+
}
|
|
17
|
+
variables(state) {
|
|
18
|
+
const name = state.flavor === 'tesla' ? 'musk' : state.flavor === 'apple' ? 'jobs' : state.flavor;
|
|
19
|
+
const block = new RegExp(`^ ${name}\\)\\n([\\s\\S]*?)^ ;;`, 'mu').exec(this.flavors)?.[1];
|
|
20
|
+
if (!block)
|
|
21
|
+
throw new Error(`缺少原版 hook 风味:${name}`);
|
|
22
|
+
return { PUA_FLAVOR: name, ...Object.fromEntries([...block.matchAll(/^\s+(PUA_[A-Z0-9_]+)="(.*)"$/gmu)].map(match => [match[1], match[2]])) };
|
|
23
|
+
}
|
|
24
|
+
interpolate(text, variables) {
|
|
25
|
+
return text.replace(/\$\{([A-Z0-9_]+)\}/gu, (_, key) => {
|
|
26
|
+
if (!(key in variables))
|
|
27
|
+
throw new Error(`原版 hook 变量未适配:${key}`);
|
|
28
|
+
return variables[key];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
frustrationPrompt(state) {
|
|
32
|
+
const body = /cat << EOF\n([\s\S]*?)\nEOF/mu.exec(this.frustration)?.[1];
|
|
33
|
+
if (!body)
|
|
34
|
+
throw new Error('原版质量纠偏模板缺失。');
|
|
35
|
+
return this.interpolate(body, this.variables(state));
|
|
36
|
+
}
|
|
37
|
+
candidate(count, state) {
|
|
38
|
+
// 原版 failure-detector.sh 首次确认失败保持不打断,从第二次观察才提供 L1 候选。
|
|
39
|
+
const level = Math.min(4, count - 1);
|
|
40
|
+
if (level < 1)
|
|
41
|
+
return '';
|
|
42
|
+
const blocks = [...this.failure.matchAll(/<< EOF_OUTPUT\n([\s\S]*?)\nEOF_OUTPUT/gu)];
|
|
43
|
+
const gate = /<< EOF_GATE[^\n]*\n([\s\S]*?)\nEOF_GATE/u.exec(this.failure)?.[1];
|
|
44
|
+
const routing = [...this.failure.matchAll(/<< EOF_ROUTING[^\n]*\n([\s\S]*?)\nEOF_ROUTING/gu)];
|
|
45
|
+
const flavorContext = [...this.failure.matchAll(/^\s*FLAVOR_CONTEXT="(.*)"$/gmu)];
|
|
46
|
+
// 索引顺序来自固定版本:locked L2/L4、auto L2/L4;升级素材须显式适配。
|
|
47
|
+
if (!gate || blocks.length !== 4 || routing.length !== 4 || flavorContext.length !== 2) {
|
|
48
|
+
throw new Error(`原版失败候选模板结构不匹配:gate=${Boolean(gate)},output=${blocks.length}/4,routing=${routing.length}/4,flavor=${flavorContext.length}/2。`);
|
|
49
|
+
}
|
|
50
|
+
const variables = { ...this.variables(state), COUNT: String(count), CANDIDATE_LEVEL: `L${level}`, CANDIDATE_THRESHOLD: count >= 5 ? '5+' : String(count) };
|
|
51
|
+
const expanded = {
|
|
52
|
+
...variables,
|
|
53
|
+
CONDITIONAL_GATE: this.interpolate(gate, variables),
|
|
54
|
+
OBSERVATION_NOTE: `Scoped tool-failure observation count: ${count}. It is not a task/sub-goal failure count or an acceptance conclusion.`,
|
|
55
|
+
SKILL_READ_NOTE: '需要细节时用 pua_reference 读取 skills/pua/SKILL.md;不递归激活技能。',
|
|
56
|
+
FLAVOR_CONTEXT: this.interpolate(flavorContext[state.flavorLocked ? 0 : 1][1], variables),
|
|
57
|
+
L2_ROUTING_BLOCK: this.interpolate(routing[state.flavorLocked ? 0 : 2][1], variables),
|
|
58
|
+
L4_ROUTING_BLOCK: this.interpolate(routing[state.flavorLocked ? 1 : 3][1], variables),
|
|
59
|
+
};
|
|
60
|
+
return this.interpolate(blocks[level - 1][1], expanded);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=hook-content.js.map
|