@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 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAKzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAE5F,MAAM,cAAc,GAAG,4BAA4B,CAAC;AACpD,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAe5C,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,iBAAiB,CAAC;QACvB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACjC,MAAM,EAAE,EAAE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;QACD,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACnE,MAAM,CAAC,aAAa,EAAE,qBAAqB,GAAG,IAAI,CAAC,CAAC;YACpD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,IAAI,mBAAmB,CAAC,CAAC;QACvD,MAAM,QAAQ,GACZ,IAAI,CAAC,SAAS,IAAI,CAAC;YACjB,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC;gBACnB,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE;oBACpB,CAAC,CAAC,+BAA+B;oBACjC,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE;wBACpB,CAAC,CAAC,uBAAuB;wBACzB,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE;4BACpB,CAAC,CAAC,qBAAqB;4BACvB,CAAC,CAAC,eAAe,CAAC;QAC9B,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,KAAK,CAAC,KAAK,CACT,aAAa,CACX,OAAO,IAAI,CAAC,SAAS,MAAM,QAAQ,KAAK,IAAI,QAAQ,IAAI,CAAC,IAAI,8GAA8G,CAC5K,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Context } from \"@deepseek-ai/cordis\";\nimport { createHash } from \"node:crypto\";\nimport type { Agent } from \"@deepseek-ai/dsh-agent\";\nimport { createUserMessage } from \"@deepseek-ai/dsh-llm\";\nimport type { Session, UserMessage } from \"@deepseek-ai/dsh-session\";\nimport type { ToolExecutionResult } from \"@deepseek-ai/dsh-tools\";\nimport type { SubprocessRuntime } from \"@deepseek-ai/dsh-subprocess\";\nimport type { Action } from \"./args.js\";\nimport { HookContent } from \"./hook-content.js\";\nimport { SourceCatalog } from \"./source.js\";\nimport { StateStore } from \"./state.js\";\nimport type { PuaMode } from \"./content.js\";\nimport { hasPendingToolCalls, repairPuaToolOrder } from \"./tool-order.js\";\nimport { replacementSurface } from \"./session-compat.js\";\nimport { terminalTextNeedsReview, TERMINAL_REVIEW_PROMPT } from \"./terminal-observation.js\";\n\nconst RUNTIME_SOURCE = \"@michengai/dsh-pua/runtime\";\nconst RECORD = \"PUA_RUNTIME_V1 \";\nexport const LOOP_START = \"PUA_LOOP_START \";\ntype LoopAction = Extract<Action, { kind: \"loop\" }>;\ninterface LoopState extends LoopAction {\n id: string;\n iteration: number;\n rejections: number;\n status: \"active\" | \"paused\" | \"cancelled\" | \"complete\" | \"max_reached\";\n}\ninterface RuntimeState {\n failureCount: number;\n failures: string[];\n feedbackCount?: number;\n candidateCount?: number;\n loop?: LoopState;\n}\nexport function pluginMessage(text: string): UserMessage {\n return createUserMessage({\n content: [{ type: \"text\", text }],\n source: { kind: \"plugin\", plugin: RUNTIME_SOURCE },\n });\n}\nconst messageText = (message: {\n content: readonly { type: string; text?: string }[];\n}) =>\n message.content\n .filter((block) => block.type === \"text\")\n .map((block) => block.text ?? \"\")\n .join(\"\\n\");\n\n/** 与原版一样,只接受终端结果的直接结构字段,不从 stdout 或嵌套 JSON 猜失败。 */\nexport function isTerminalFailure(\n result: Readonly<ToolExecutionResult>,\n): boolean {\n if (result.isError)\n return !!result.error.info?.code && !/ABORT|DENIED|PERMISSION|EPERM|EACCES|UNKNOWN_TOOL|BLOCKED|APPROVAL/u.test(\n result.error.info?.code ?? \"\",\n );\n const value = result.value;\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n return (\n value.is_error === true ||\n [\"exitCode\", \"exit_code\"].some(\n (key) => typeof value[key] === \"number\" && value[key] !== 0,\n )\n );\n}\n\n/** 独立验收执行用户提供的命令,120 秒超时;输出只作为证据,不作为指令。 */\nexport async function verifyLoop(\n subprocess: Pick<SubprocessRuntime, \"spawn\">,\n command: string,\n cwd: string,\n signal: AbortSignal,\n timeoutMs = 120_000,\n): Promise<{ ok: boolean; detail: string }> {\n signal.throwIfAborted();\n const timeout = new AbortController();\n const timer = setTimeout(() => timeout.abort(), timeoutMs);\n try {\n const combined = AbortSignal.any([signal, timeout.signal]);\n // 脚本是 argv 的单个参数,由宿主 spawn(program, args) 传递,无外层 shell 字符串转义。\n const argv =\n process.platform === \"win32\"\n ? [\n \"powershell.exe\",\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-Command\",\n `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8\\n$OutputEncoding = [System.Text.Encoding]::UTF8\\n$ErrorActionPreference = 'Stop'\\n${command}\\nif (-not $?) { if ($null -ne $LASTEXITCODE -and $LASTEXITCODE -ne 0) { exit $LASTEXITCODE }; exit 1 }; if ($null -ne $LASTEXITCODE) { exit $LASTEXITCODE }`,\n ]\n : [\"/bin/sh\", \"-c\", command];\n const handle = subprocess.spawn({\n argv,\n cwd,\n signal: combined,\n graceMs: 1000,\n stdio: {\n stdin: \"ignore\",\n stdout: { maxBytes: 8192 },\n stderr: { maxBytes: 8192 },\n },\n });\n const result = await handle.done;\n signal.throwIfAborted();\n const stdout = handle.collected.stdout?.readFrom(0);\n const stderr = handle.collected.stderr?.readFrom(0);\n return {\n ok: !timeout.signal.aborted && result.exitCode === 0 && !result.signal,\n detail: JSON.stringify({\n exitCode: result.exitCode,\n timedOut: timeout.signal.aborted,\n stdout: stdout?.text,\n stderr: stderr?.text,\n truncated: stdout?.lossy || stderr?.lossy || false,\n }),\n };\n } catch (error) {\n signal.throwIfAborted();\n return {\n ok: false,\n detail: timeout.signal.aborted\n ? \"独立验收超时。\"\n : `独立验收未执行成功:${error instanceof Error ? error.message : String(error)}`,\n };\n } finally {\n clearTimeout(timer);\n }\n}\n\n/** 生命周期移植;完整状态留在日志,通过宿主 surface 替换只向模型提供说明。 */\nexport class PuaRuntime {\n private readonly hooks: HookContent;\n private readonly activeVerifiers = new Map<Session, AbortController>();\n private readonly sessions = new Set<Session>();\n private readonly cache = new WeakMap<Session, RuntimeState>();\n private readonly normalized = new WeakSet<Session>();\n private readonly pendingWrites = new Map<Session, string>();\n private readonly pendingCandidates = new WeakSet<Session>();\n private readonly pendingTerminalReviews = new WeakSet<Session>();\n constructor(\n private readonly ctx: Context,\n private readonly store: StateStore,\n catalog: SourceCatalog,\n private readonly lifetime: AbortSignal,\n feedback: () => { offline: boolean; frequency: number } = () => ({\n offline: false,\n frequency: 5,\n }),\n ) {\n this.hooks = new HookContent(catalog);\n ctx.on(\"agent/pre-step\", async ({ agent }, next) => {\n const decision = await next();\n if (decision.kind !== \"enter\") return decision;\n this.hideLegacyRecords(agent.session);\n this.flush(agent.session);\n const state = store.read(agent.session);\n const runtime = this.read(agent.session);\n if (this.pendingTerminalReviews.has(agent.session) && !hasPendingToolCalls(agent.session)) {\n this.pendingTerminalReviews.delete(agent.session);\n if (state.enabled && state.terminalReview) decision.messages.push(pluginMessage(TERMINAL_REVIEW_PROMPT));\n }\n if (this.pendingCandidates.has(agent.session) && !hasPendingToolCalls(agent.session)) {\n this.pendingCandidates.delete(agent.session);\n let prompt = '';\n if (state.enabled && state.failureCandidates && (runtime.candidateCount ?? 0) < 4) {\n try { prompt = this.hooks.candidate(runtime.failureCount, state); }\n catch (error) { ctx.logger.warn('PUA 候选素材不可用,跳过本次提示:%s', error); }\n if (prompt) runtime.candidateCount = (runtime.candidateCount ?? 0) + 1;\n }\n if (prompt) decision.messages.push(pluginMessage(prompt));\n }\n if (!state.enabled || state.mode !== \"pua-loop\")\n this.cancel(agent.session);\n for (const message of decision.messages) {\n const text = messageText(message);\n if (\n message.source.kind === \"plugin\" &&\n message.source.plugin === \"@michengai/dsh-pua\" &&\n text.startsWith(LOOP_START) &&\n state.enabled &&\n state.mode === \"pua-loop\"\n ) {\n const config = JSON.parse(\n text.slice(LOOP_START.length).split(\"\\n\")[0]!,\n ) as LoopAction & { id: string };\n if (config.id !== state.loopCommandId) continue;\n runtime.loop = {\n ...config,\n iteration: 1,\n rejections: 0,\n status: \"active\",\n };\n this.save(\n agent.session,\n runtime,\n \"显式启动 Loop;验证配置以用户命令为准。\",\n );\n } else if (message.source.kind === \"user\" && state.enabled) {\n if (runtime.loop?.status === \"paused\" && state.mode === \"pua-loop\") {\n runtime.loop = { ...runtime.loop, status: \"active\" };\n this.save(\n agent.session,\n runtime,\n \"用户补充输入,恢复同会话 Loop。\",\n );\n }\n if (state.qualityTriggers && this.hooks.trigger.test(text))\n decision.messages.push(\n pluginMessage(this.hooks.frustrationPrompt(state)),\n );\n }\n }\n return decision;\n });\n ctx.inject([\"tools\"], (child) => {\n child.tools.register({\n name: \"pua_reference\",\n description:\n \"读取已安装的 PUA 3.5.1 完整原版资料。path=list 列目录;其他值必须为目录中 .md 路径。\",\n parameters: {\n type: \"object\",\n properties: { path: { type: \"string\" } },\n required: [\"path\"],\n additionalProperties: false,\n },\n output: {\n schema: { type: \"string\" },\n render: (_args, value) => [{ type: \"text\", text: String(value) }],\n },\n isConcurrencySafe: () => true,\n execute: async (args, exec) => {\n exec.signal.throwIfAborted();\n if (\n !args ||\n typeof args !== \"object\" ||\n !(\"path\" in args) ||\n typeof args.path !== \"string\"\n )\n throw new Error(\"path 必须为资料路径或 list。\");\n if (args.path === \"list\") return catalog.list().join(\"\\n\");\n if (!catalog.list().includes(args.path))\n throw new Error(\"仅允许读取已收录的 Markdown 资料。\");\n return catalog.read(args.path);\n },\n });\n child.on(\"tools/result\", (exec, result) => {\n const agent = exec.agent;\n if (!agent || exec.signal.aborted || !store.read(agent.session).enabled)\n return;\n const tool = child.tools.get(exec.name, agent);\n const terminal =\n /^(Bash|bash|terminal|exec_command|shell|shell_command|run_terminal_cmd)$/u.test(\n exec.name,\n ) || tool?.presentCall?.(exec.arguments)?.card === \"terminal\";\n if (!terminal) return;\n if (!isTerminalFailure(result)) {\n // 拒绝、取消及无结构化错误码的宿主故障不是成功,不清零已有观察。\n if (result.isError) return;\n if (terminalTextNeedsReview(result)) this.pendingTerminalReviews.add(agent.session);\n else {\n // 成功打断连续失败观察;不会撤销独立验收结果。\n const observation = this.read(agent.session);\n if (observation.failureCount) this.pendingWrites.set(agent.session, '终端成功,清除连续失败观察。');\n observation.failureCount = 0;\n this.pendingCandidates.delete(agent.session);\n }\n return;\n }\n const runtime = this.read(agent.session);\n const id = createHash(\"sha256\").update(exec.callId).digest(\"hex\");\n if (runtime.failures.includes(id)) return;\n runtime.failures = [...runtime.failures, id].slice(-128);\n runtime.failureCount = Math.min(runtime.failureCount + 1, 1_000_000);\n // 此通知早于宿主 tool/result 落库;只暂存,不能在工具组中插入普通消息。\n this.pendingWrites.set(\n agent.session,\n \"新增终端失败观察;不是任务失败判定。\",\n );\n this.pendingCandidates.add(agent.session);\n return;\n });\n });\n ctx.on(\"agent/turn-stopping\", async (payload) => {\n this.flush(payload.agent.session);\n const wasLoop =\n this.read(payload.agent.session).loop?.status === \"active\";\n await this.stopping(payload.agent, payload.turn, payload.signal);\n const session = payload.agent.session;\n const preferences = store.read(session);\n const config = { offline: preferences.offline, frequency: preferences.feedbackFrequency };\n if (\n wasLoop ||\n !store.read(session).enabled ||\n config.offline ||\n config.frequency === 0 ||\n session.header.parentSession\n )\n return;\n const visible = [...session.ownEvents()].some(\n (event) =>\n event.type === \"assistant/message\" &&\n event.data.turn === payload.turn &&\n !event.data.interrupted &&\n /PUA生效|\\[Auto-select:|\\[PIP-REPORT\\]|\\[PUA-REPORT\\]|\\[PUA-DIAGNOSIS\\]/u.test(\n messageText(event.data.message),\n ),\n );\n if (!visible) return;\n const state = this.read(session);\n state.feedbackCount = (state.feedbackCount ?? 0) + 1;\n const note =\n state.feedbackCount % config.frequency === 0\n ? \"PUA 本地反馈(自愿):如需记录本次效果,可运行 /pua survey quick。评分只写本机 ~/.pua/feedback.jsonl;跳过不记录,不阻断交付,不上传。\"\n : \"记录一次有可见 PUA 输出的交付,不记录评分。\";\n this.save(session, state, note);\n });\n ctx.on(\"agent/session-start\", ({ agent, source }) => {\n if (source === \"clear\") {\n this.pendingCandidates.delete(agent.session);\n this.pendingTerminalReviews.delete(agent.session);\n this.cancel(agent.session);\n this.save(\n agent.session,\n { failureCount: 0, failures: [] },\n \"清空上下文,清除当前运行观察。\",\n );\n } else if (source === \"compact\" && store.read(agent.session).enabled) {\n agent.inject(\n pluginMessage(\n \"PUA 压缩后恢复:\" +\n this.status(agent.session) +\n \" 数值仅为运行观察;不代表任务失败次数或验收结论。完整核心与风味继续由系统提示词提供。\",\n ),\n );\n }\n });\n ctx.on(\"session/event\", (session, event) => {\n if (event.type === 'turn/start') this.read(session).candidateCount = 0;\n // Session 的发布边界禁止重入 append;turn/end 本身已是可回放的取消事实。\n if (event.type === \"turn/end\" && event.data.reason.kind !== \"completed\") {\n this.pendingTerminalReviews.delete(session);\n this.cancel(session, false);\n }\n });\n ctx.on(\"agent/disposed\", ({ agent }) => {\n this.cancel(agent.session);\n this.flush(agent.session);\n if (this.pendingWrites.delete(agent.session)) ctx.logger.warn('PUA 会话已销毁且工具组未完整结束,丢弃未落库的运行观察,避免插入工具组。');\n this.sessions.delete(agent.session);\n });\n let disposed = false;\n // 卸载发生在工具组中途时,只保留待写状态的边界监听,写完即撤销。\n // 根上下文监听不注入候选或唤醒模型,也不接管工具生命周期。\n const stopObserving = ctx.root.on('session/event', (session, event) => {\n if (!this.pendingWrites.has(session) || !['step/end', 'turn/end'].includes(event.type)) return;\n // Session 禁止在事件发布栈重入 append;由已发生的明确边界触发微任务。\n queueMicrotask(() => {\n try { this.flush(session); }\n catch (error) { ctx.logger.warn('PUA 延后状态记录未写入,将在下一安全边界重试:%s', error); }\n if (disposed && this.pendingWrites.size === 0) { stopObserving(); stopDisposed(); }\n });\n });\n const stopDisposed = ctx.root.on('agent/disposed', ({ agent }) => {\n if (this.pendingWrites.delete(agent.session)) ctx.logger.warn('PUA 已销毁会话的未落库观察已释放;未插入不完整工具组。');\n if (disposed && this.pendingWrites.size === 0) { stopObserving(); stopDisposed(); }\n });\n ctx.effect(() => () => {\n disposed = true;\n for (const session of this.sessions) this.cancel(session);\n for (const session of this.pendingWrites.keys()) this.flush(session);\n this.sessions.clear();\n if (this.pendingWrites.size === 0) { stopObserving(); stopDisposed(); }\n });\n }\n read(session: Session): RuntimeState {\n let state = this.cache.get(session);\n if (!state) {\n state = { failureCount: 0, failures: [] };\n for (const event of session.ownEvents()) {\n if (\n event.type === \"user/message\" &&\n event.data.source.kind === \"plugin\" &&\n event.data.source.plugin === RUNTIME_SOURCE\n ) {\n const text = messageText(event.data);\n if (text.startsWith(RECORD))\n state = JSON.parse(\n text.slice(RECORD.length).split(\"\\n\")[0]!,\n ) as RuntimeState;\n }\n if (\n event.type === \"turn/end\" &&\n event.data.reason.kind !== \"completed\" &&\n state.loop\n )\n state.loop.status = \"cancelled\";\n }\n this.cache.set(session, state);\n this.sessions.add(session);\n }\n return state;\n }\n private save(session: Session, state: RuntimeState, note: string): void {\n this.cache.set(session, state);\n this.pendingWrites.set(session, note);\n this.flush(session);\n }\n private flush(session: Session): void {\n const note = this.pendingWrites.get(session);\n if (note === undefined || hasPendingToolCalls(session)) return;\n const state = this.read(session);\n const record = session.append(\n \"user/message\",\n pluginMessage(RECORD + JSON.stringify(state) + \"\\n\" + note),\n { surfaceOp: \"append\" },\n );\n // 当前宿主 append 不支持 ignorable 自定义事件。用原生替换保留回放依据,\n // 避免未知必需事件导致卸载后无法加载;两次同步 append 之间不发起模型请求。\n session.append(\"user/message\", pluginMessage(note), {\n surfaceOp: replacementSurface(record.seq, record.seq),\n sourceEventSeqs: [record.seq],\n });\n this.pendingWrites.delete(session);\n }\n private hideLegacyRecords(session: Session): void {\n if (this.normalized.has(session)) return;\n repairPuaToolOrder(session, RUNTIME_SOURCE);\n // 包括分叉带入的可见旧记录,但配置恢复仍只读取 ownEvents。\n for (const seq of [...session.surface.nodes]) {\n const event = session.eventAt(seq);\n if (\n event?.type !== \"user/message\" ||\n event.data.source.kind !== \"plugin\" ||\n event.data.source.plugin !== RUNTIME_SOURCE\n )\n continue;\n const text = messageText(event.data);\n if (!text.startsWith(RECORD)) continue;\n const newline = text.indexOf(\"\\n\");\n const note =\n newline < 0\n ? \"PUA 历史运行记录已保留在会话日志中。\"\n : text.slice(newline + 1);\n session.append(\"user/message\", pluginMessage(note), {\n surfaceOp: replacementSurface(seq, seq),\n sourceEventSeqs: [seq],\n });\n }\n this.normalized.add(session);\n }\n cancel(session: Session, persist = true): void {\n this.activeVerifiers.get(session)?.abort();\n const state = this.read(session);\n if (state.loop && [\"active\", \"paused\"].includes(state.loop.status)) {\n state.loop = { ...state.loop, status: \"cancelled\" };\n if (persist) this.save(session, state, \"Loop 已取消,不再续轮。\");\n }\n }\n cancelAll(): number {\n let count = 0;\n for (const session of this.sessions) {\n if (\n [\"active\", \"paused\"].includes(this.read(session).loop?.status ?? \"\")\n ) {\n this.cancel(session);\n count++;\n }\n }\n return count;\n }\n status(session: Session): string {\n const state = this.read(session);\n return `终端失败观察:${state.failureCount}(候选,非任务失败数);Loop:${state.loop ? `${state.loop.status},第 ${state.loop.iteration} 轮,Oracle 拒绝 ${state.loop.rejections} 次` : \"未启动\"}。`;\n }\n effectiveMode(session: Session, mode: PuaMode): PuaMode {\n const status = this.read(session).loop?.status;\n return mode === \"pua-loop\" &&\n status &&\n [\"cancelled\", \"complete\", \"max_reached\"].includes(status)\n ? \"pua\"\n : mode;\n }\n private async stopping(\n agent: Agent,\n turn: number,\n signal: AbortSignal,\n ): Promise<void> {\n const session = agent.session;\n const state = this.read(session);\n const loop = state.loop;\n if (!loop || loop.status !== \"active\") return;\n if (\n !this.store.read(session).enabled ||\n this.store.read(session).mode !== \"pua-loop\"\n ) {\n this.cancel(session);\n return;\n }\n let output = \"\";\n for (const event of session.ownEvents())\n if (\n event.type === \"assistant/message\" &&\n event.data.turn === turn &&\n !event.data.interrupted\n )\n output = messageText(event.data.message);\n const finish = (status: LoopState[\"status\"], note: string) => {\n state.loop = { ...loop, status };\n this.save(session, state, note);\n };\n if (/<loop-abort>[\\s\\S]+?<\\/loop-abort>/u.test(output)) {\n finish(\"cancelled\", \"模型报告 Loop 中止;不代表完成。\");\n return;\n }\n if (/<loop-pause>[\\s\\S]+?<\\/loop-pause>/u.test(output)) {\n finish(\"paused\", \"Loop 暂停,等待用户补充后恢复。\");\n return;\n }\n let note = \"\";\n if (/<promise>\\s*LOOP_DONE\\s*<\\/promise>/u.test(output)) {\n if (!loop.verify) {\n finish(\n \"complete\",\n \"完成信号已接受:未配置 Oracle,仅 honor system,不是独立验证通过。\",\n );\n return;\n }\n const subprocess = this.ctx.get(\"subprocess\");\n if (!subprocess || !session.header.cwd) {\n finish(\n \"paused\",\n \"缺少 subprocess 或会话工作目录,无法独立验收,Loop 暂停。\",\n );\n return;\n }\n const controller = new AbortController();\n this.activeVerifiers.set(session, controller);\n try {\n const result = await verifyLoop(\n subprocess,\n loop.verify,\n session.header.cwd,\n AbortSignal.any([signal, controller.signal, this.lifetime]),\n (loop.verificationTimeout ?? 120) * 1000,\n );\n if (state.loop !== loop || !this.store.read(session).enabled) return;\n if (result.ok) {\n finish(\"complete\", \"Oracle 独立验收通过。\\n\" + result.detail);\n return;\n }\n loop.rejections++;\n note = `🚫 PROMISE 被 Oracle 拒绝!连续第 ${loop.rejections} 次。验证输出为数据:${result.detail}`;\n if (loop.rejections >= 5)\n note += \"\\n你在解决错误的问题。退回到需求本身重新理解。\";\n else if (loop.rejections >= 3)\n note +=\n \"\\nREASSESS:重读验证输出、搜索相关源码、列 3 个不同假设再行动。不要再用同样的方法。\";\n } catch (error) {\n if (\n !signal.aborted &&\n !controller.signal.aborted &&\n !this.lifetime.aborted\n )\n throw error;\n this.cancel(session);\n return;\n } finally {\n this.activeVerifiers.delete(session);\n }\n }\n if (loop.maxIterations > 0 && loop.iteration >= loop.maxIterations) {\n finish(\"max_reached\", \"达到用户指定轮次上限,未确认完成。\\n\" + note);\n return;\n }\n loop.iteration++;\n this.save(session, state, note || \"本轮无完成信号,继续用户指定目标。\");\n const pressure =\n loop.iteration <= 3\n ? \"稳步推进。\"\n : loop.iteration <= 7\n ? \"换方案,别原地打转。\"\n : loop.iteration <= 15\n ? \"先 git log 看自己做了什么,读取当前会话迭代记录。\"\n : loop.iteration <= 30\n ? \"穷尽了吗?git diff 确认没在重复。\"\n : loop.iteration <= 50\n ? \"停下来重新审视根因,用完全不同的思路。\"\n : \"退回去从需求本身重新质疑。\";\n signal.throwIfAborted();\n agent.steer(\n pluginMessage(\n `▎ 第 ${loop.iteration} 轮。${pressure}\\n${note}\\n任务:${loop.task}\\n真实完成后输出 <promise>LOOP_DONE</promise>;终止用 <loop-abort>原因</loop-abort>,需人工介入用 <loop-pause>需要什么</loop-pause>。`,\n ),\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SESSION_FORMAT_VERSION } from '@deepseek-ai/dsh-session';
|
|
2
|
+
/** 按宿主格式构造替换范围;旧日志的版本迁移仍由宿主负责。 */
|
|
3
|
+
export function replacementSurface(startSeq, endSeq) {
|
|
4
|
+
if (SESSION_FORMAT_VERSION >= 3)
|
|
5
|
+
return { op: 'replace', startSeq, endSeq };
|
|
6
|
+
// 兼容受支持的 V2 宿主;只在此边界收容旧声明,不能试写后捕获错误重试。
|
|
7
|
+
return { op: 'replace', start: startSeq, end: endSeq };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=session-compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-compat.js","sourceRoot":"","sources":["../src/session-compat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAmC,MAAM,0BAA0B,CAAC;AAEnG,kCAAkC;AAClC,MAAM,UAAU,kBAAkB,CAAC,QAAoB,EAAE,MAAkB;IACzE,IAAI,sBAAsB,IAAI,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC5E,uCAAuC;IACvC,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAA0B,CAAC;AACjF,CAAC","sourcesContent":["import { SESSION_FORMAT_VERSION, type SessionSeq, type SurfaceOp } from '@deepseek-ai/dsh-session';\n\n/** 按宿主格式构造替换范围;旧日志的版本迁移仍由宿主负责。 */\nexport function replacementSurface(startSeq: SessionSeq, endSeq: SessionSeq): SurfaceOp {\n if (SESSION_FORMAT_VERSION >= 3) return { op: 'replace', startSeq, endSeq };\n // 兼容受支持的 V2 宿主;只在此边界收容旧声明,不能试写后捕获错误重试。\n return { op: 'replace', start: startSeq, end: endSeq } as unknown as SurfaceOp;\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
3
|
+
import type { PuaState } from './state.js';
|
|
4
|
+
import { type Configuration } from './configuration.js';
|
|
5
|
+
export interface Preferences extends Omit<Configuration, 'enabled'> {
|
|
6
|
+
alwaysOn: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const SETTINGS_SCHEMA: Schema<Schemastery.ObjectS<{
|
|
9
|
+
alwaysOn: Schema<boolean, boolean>;
|
|
10
|
+
flavor: Schema<"alibaba" | "bytedance" | "huawei" | "tencent" | "baidu" | "pinduoduo" | "meituan" | "jd" | "xiaomi" | "netflix" | "tesla" | "apple" | "amazon" | "microsoft" | "ding" | "auto", "alibaba" | "bytedance" | "huawei" | "tencent" | "baidu" | "pinduoduo" | "meituan" | "jd" | "xiaomi" | "netflix" | "tesla" | "apple" | "amazon" | "microsoft" | "ding" | "auto">;
|
|
11
|
+
offline: Schema<boolean, boolean>;
|
|
12
|
+
feedbackFrequency: Schema<number, number>;
|
|
13
|
+
mode: Schema<"pua" | "p7" | "p9" | "p10" | "pro" | "yes" | "mama" | "shot" | "pua-en" | "pua-ja", "pua" | "p7" | "p9" | "p10" | "pro" | "yes" | "mama" | "shot" | "pua-en" | "pua-ja">;
|
|
14
|
+
subagents: Schema<boolean, boolean>;
|
|
15
|
+
terminalReview: Schema<boolean, boolean>;
|
|
16
|
+
failureCandidates: Schema<boolean, boolean>;
|
|
17
|
+
qualityTriggers: Schema<boolean, boolean>;
|
|
18
|
+
maxIterations: Schema<number, number>;
|
|
19
|
+
verify: Schema<string, string>;
|
|
20
|
+
verificationTimeout: Schema<number, number>;
|
|
21
|
+
}>, Schemastery.ObjectT<{
|
|
22
|
+
alwaysOn: Schema<boolean, boolean>;
|
|
23
|
+
flavor: Schema<"alibaba" | "bytedance" | "huawei" | "tencent" | "baidu" | "pinduoduo" | "meituan" | "jd" | "xiaomi" | "netflix" | "tesla" | "apple" | "amazon" | "microsoft" | "ding" | "auto", "alibaba" | "bytedance" | "huawei" | "tencent" | "baidu" | "pinduoduo" | "meituan" | "jd" | "xiaomi" | "netflix" | "tesla" | "apple" | "amazon" | "microsoft" | "ding" | "auto">;
|
|
24
|
+
offline: Schema<boolean, boolean>;
|
|
25
|
+
feedbackFrequency: Schema<number, number>;
|
|
26
|
+
mode: Schema<"pua" | "p7" | "p9" | "p10" | "pro" | "yes" | "mama" | "shot" | "pua-en" | "pua-ja", "pua" | "p7" | "p9" | "p10" | "pro" | "yes" | "mama" | "shot" | "pua-en" | "pua-ja">;
|
|
27
|
+
subagents: Schema<boolean, boolean>;
|
|
28
|
+
terminalReview: Schema<boolean, boolean>;
|
|
29
|
+
failureCandidates: Schema<boolean, boolean>;
|
|
30
|
+
qualityTriggers: Schema<boolean, boolean>;
|
|
31
|
+
maxIterations: Schema<number, number>;
|
|
32
|
+
verify: Schema<string, string>;
|
|
33
|
+
verificationTimeout: Schema<number, number>;
|
|
34
|
+
}>>;
|
|
35
|
+
/** 可选设置服务:标准 DSH 设置页自动读取此 schema;无服务时仅当前会话生效。 */
|
|
36
|
+
export declare class PreferencesBridge {
|
|
37
|
+
private scope;
|
|
38
|
+
constructor(ctx: Context);
|
|
39
|
+
defaults(): Partial<PuaState>;
|
|
40
|
+
configuration(): Configuration;
|
|
41
|
+
description(): string;
|
|
42
|
+
feedback(): {
|
|
43
|
+
offline: boolean;
|
|
44
|
+
frequency: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
package/lib/settings.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
2
|
+
import { FLAVORS } from './flavors.js';
|
|
3
|
+
import { CONFIG_DEFAULTS, CONFIG_MODES } from './configuration.js';
|
|
4
|
+
export const SETTINGS_SCHEMA = Schema.object({
|
|
5
|
+
alwaysOn: Schema.boolean().default(true).description('默认开启 PUA(与原版一致);会话内显式 on/off 优先。'),
|
|
6
|
+
flavor: Schema.union(['auto', ...FLAVORS.map(item => item.id)].map(value => Schema.const(value))).default('auto').description('默认风味;auto 按原版任务路由,指定风味则锁定。'),
|
|
7
|
+
offline: Schema.boolean().default(false).description('离线模式:关闭自愿反馈提醒。本移植始终不包含联网刷新或上报能力。'),
|
|
8
|
+
feedbackFrequency: Schema.number().min(0).max(9999).step(1).default(5).description('每多少次有 PUA 可见输出的交付显示本地反馈入口;0 关闭,不自动记录评分。'),
|
|
9
|
+
mode: Schema.union(CONFIG_MODES.map(value => Schema.const(value))).default('pua').description('默认角色模式。'),
|
|
10
|
+
subagents: Schema.boolean().default(false).description('对子代理启用 PUA;使用父会话生效配置,不继承 Loop 和失败计数。'),
|
|
11
|
+
terminalReview: Schema.boolean().default(true).description('终端异常文本核验提醒。'),
|
|
12
|
+
failureCandidates: Schema.boolean().default(true).description('失败后的升级候选提示,仍须核验任务失败。'),
|
|
13
|
+
qualityTriggers: Schema.boolean().default(true).description('用户不满或要求证据时的质量纠偏提示。'),
|
|
14
|
+
maxIterations: Schema.number().min(0).max(10000).step(1).default(0).description('Loop 默认轮次上限;0 不限。保存不启动循环。'),
|
|
15
|
+
verify: Schema.string().max(8192).default('').description('默认验收命令;空白使用模型报告。启动时可按项目修改。'),
|
|
16
|
+
verificationTimeout: Schema.number().min(1).max(3600).step(1).default(120).description('独立验收超时(秒),已启动 Loop 不随设置变化。'),
|
|
17
|
+
});
|
|
18
|
+
/** 可选设置服务:标准 DSH 设置页自动读取此 schema;无服务时仅当前会话生效。 */
|
|
19
|
+
export class PreferencesBridge {
|
|
20
|
+
scope;
|
|
21
|
+
constructor(ctx) {
|
|
22
|
+
ctx.inject(['settings'], child => {
|
|
23
|
+
this.scope = child.settings.register('michengai-pua', SETTINGS_SCHEMA);
|
|
24
|
+
child.effect(() => () => { this.scope = undefined; });
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
defaults() {
|
|
28
|
+
const config = this.scope?.get();
|
|
29
|
+
return config ? { ...config, enabled: config.alwaysOn, flavor: config.flavor === 'auto' ? 'alibaba' : config.flavor, flavorLocked: config.flavor !== 'auto' } : {};
|
|
30
|
+
}
|
|
31
|
+
configuration() {
|
|
32
|
+
const config = this.scope?.get();
|
|
33
|
+
if (!config)
|
|
34
|
+
return { ...CONFIG_DEFAULTS, enabled: false };
|
|
35
|
+
const { alwaysOn, ...rest } = config;
|
|
36
|
+
return { ...rest, enabled: alwaysOn };
|
|
37
|
+
}
|
|
38
|
+
description() { return this.scope ? '仅当前会话;全局默认请在设置 → 插件 → PUA 配置中修改' : '仅当前会话(宿主未提供 settings)'; }
|
|
39
|
+
feedback() {
|
|
40
|
+
const config = this.scope?.get();
|
|
41
|
+
return { offline: config?.offline ?? false, frequency: config?.feedbackFrequency ?? 5 };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAiB,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AAGvF,MAAM,CAAC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OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrK,CAAC;IACD,aAAa;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,GAAG,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC3D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QACrC,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IACxC,CAAC;IACD,WAAW,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC;IAC1G,QAAQ;QACN,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;QACjC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,IAAI,CAAC,EAAE,CAAC;IAC1F,CAAC;CACF","sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport type { SettingsScope } from '@deepseek-ai/dsh-settings';\nimport Schema from '@deepseek-ai/schemastery';\nimport { FLAVORS, type FlavorId } from './flavors.js';\nimport type { PuaState } from './state.js';\nimport { CONFIG_DEFAULTS, CONFIG_MODES, type Configuration } from './configuration.js';\n\nexport interface Preferences extends Omit<Configuration, 'enabled'> { alwaysOn: boolean }\nexport const SETTINGS_SCHEMA = Schema.object({\n alwaysOn: Schema.boolean().default(true).description('默认开启 PUA(与原版一致);会话内显式 on/off 优先。'),\n flavor: Schema.union((['auto', ...FLAVORS.map(item => item.id)] as const).map(value => Schema.const(value))).default('auto').description('默认风味;auto 按原版任务路由,指定风味则锁定。'),\n offline: Schema.boolean().default(false).description('离线模式:关闭自愿反馈提醒。本移植始终不包含联网刷新或上报能力。'),\n feedbackFrequency: Schema.number().min(0).max(9999).step(1).default(5).description('每多少次有 PUA 可见输出的交付显示本地反馈入口;0 关闭,不自动记录评分。'),\n mode: Schema.union(CONFIG_MODES.map(value => Schema.const(value))).default('pua').description('默认角色模式。'),\n subagents: Schema.boolean().default(false).description('对子代理启用 PUA;使用父会话生效配置,不继承 Loop 和失败计数。'),\n terminalReview: Schema.boolean().default(true).description('终端异常文本核验提醒。'),\n failureCandidates: Schema.boolean().default(true).description('失败后的升级候选提示,仍须核验任务失败。'),\n qualityTriggers: Schema.boolean().default(true).description('用户不满或要求证据时的质量纠偏提示。'),\n maxIterations: Schema.number().min(0).max(10000).step(1).default(0).description('Loop 默认轮次上限;0 不限。保存不启动循环。'),\n verify: Schema.string().max(8192).default('').description('默认验收命令;空白使用模型报告。启动时可按项目修改。'),\n verificationTimeout: Schema.number().min(1).max(3600).step(1).default(120).description('独立验收超时(秒),已启动 Loop 不随设置变化。'),\n});\n\n/** 可选设置服务:标准 DSH 设置页自动读取此 schema;无服务时仅当前会话生效。 */\nexport class PreferencesBridge {\n private scope: SettingsScope<Preferences> | undefined;\n constructor(ctx: Context) {\n ctx.inject(['settings'], child => {\n this.scope = child.settings.register('michengai-pua', SETTINGS_SCHEMA);\n child.effect(() => () => { this.scope = undefined; });\n });\n }\n defaults(): Partial<PuaState> {\n const config = this.scope?.get();\n return config ? { ...config, enabled: config.alwaysOn, flavor: config.flavor === 'auto' ? 'alibaba' : config.flavor, flavorLocked: config.flavor !== 'auto' } : {};\n }\n configuration(): Configuration {\n const config = this.scope?.get();\n if (!config) return { ...CONFIG_DEFAULTS, enabled: false };\n const { alwaysOn, ...rest } = config;\n return { ...rest, enabled: alwaysOn };\n }\n description(): string { return this.scope ? '仅当前会话;全局默认请在设置 → 插件 → PUA 配置中修改' : '仅当前会话(宿主未提供 settings)'; }\n feedback(): { offline: boolean; frequency: number } {\n const config = this.scope?.get();\n return { offline: config?.offline ?? false, frequency: config?.feedbackFrequency ?? 5 };\n }\n}\n"]}
|
package/lib/source.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** 固定 Git 提交的原版目录;提供给模型的路径必须命中白名单。 */
|
|
2
|
+
export declare class SourceCatalog {
|
|
3
|
+
readonly revision: string;
|
|
4
|
+
private readonly documents;
|
|
5
|
+
constructor();
|
|
6
|
+
list(): readonly string[];
|
|
7
|
+
/** 返回完整原文;未知路径失败,不将输入转换为任意文件路径。 */
|
|
8
|
+
read(path: string): string;
|
|
9
|
+
body(path: string): string;
|
|
10
|
+
}
|
package/lib/source.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
/** 固定 Git 提交的原版目录;提供给模型的路径必须命中白名单。 */
|
|
4
|
+
export class SourceCatalog {
|
|
5
|
+
revision;
|
|
6
|
+
documents = new Map();
|
|
7
|
+
constructor() {
|
|
8
|
+
const root = new URL('../assets/pua/', import.meta.url);
|
|
9
|
+
const manifest = JSON.parse(readFileSync(new URL('upstream.json', root), 'utf8'));
|
|
10
|
+
this.revision = manifest.revision;
|
|
11
|
+
for (const entry of manifest.files.filter(entry => entry.file.startsWith('upstream/'))) {
|
|
12
|
+
if (!/^(skills|commands|agents|hooks)\/[a-zA-Z0-9_./-]+$/.test(entry.source) || entry.source.split('/').includes('..') || entry.file !== `upstream/${entry.source}`)
|
|
13
|
+
throw new Error('原版文件清单包含无效路径。');
|
|
14
|
+
const bytes = readFileSync(new URL(entry.file, root));
|
|
15
|
+
if (createHash('sha256').update(bytes).digest('hex') !== entry.sha256)
|
|
16
|
+
throw new Error(`原版文件指纹不匹配:${entry.source}`);
|
|
17
|
+
this.documents.set(entry.source, bytes.toString('utf8'));
|
|
18
|
+
}
|
|
19
|
+
if (!this.documents.has('skills/pua/SKILL.md'))
|
|
20
|
+
throw new Error('缺少原版 PUA 核心文件。');
|
|
21
|
+
}
|
|
22
|
+
list() { return [...this.documents.keys()].filter(path => path.endsWith('.md')).sort(); }
|
|
23
|
+
/** 返回完整原文;未知路径失败,不将输入转换为任意文件路径。 */
|
|
24
|
+
read(path) {
|
|
25
|
+
const text = this.documents.get(path);
|
|
26
|
+
if (text === undefined)
|
|
27
|
+
throw new Error(`未收录此原版资料:${path}`);
|
|
28
|
+
return text;
|
|
29
|
+
}
|
|
30
|
+
body(path) { return this.read(path).replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/u, '').trim(); }
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,sCAAsC;AACtC,MAAM,OAAO,aAAa;IACf,QAAQ,CAAS;IACT,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvD;QACE,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAE/E,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAClC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CA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AE,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,IAAY,IAAY,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,iCAAiC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;CAC7G","sourcesContent":["import { readFileSync } from 'node:fs';\nimport { createHash } from 'node:crypto';\n\n/** 固定 Git 提交的原版目录;提供给模型的路径必须命中白名单。 */\nexport class SourceCatalog {\n readonly revision: string;\n private readonly documents = new Map<string, string>();\n constructor() {\n const root = new URL('../assets/pua/', import.meta.url);\n const manifest = JSON.parse(readFileSync(new URL('upstream.json', root), 'utf8')) as {\n revision: string; files: { file: string; source: string; sha256: string }[];\n };\n this.revision = manifest.revision;\n for (const entry of manifest.files.filter(entry => entry.file.startsWith('upstream/'))) {\n if (!/^(skills|commands|agents|hooks)\\/[a-zA-Z0-9_./-]+$/.test(entry.source) || entry.source.split('/').includes('..') || entry.file !== `upstream/${entry.source}`) throw new Error('原版文件清单包含无效路径。');\n const bytes = readFileSync(new URL(entry.file, root));\n if (createHash('sha256').update(bytes).digest('hex') !== entry.sha256) throw new Error(`原版文件指纹不匹配:${entry.source}`);\n this.documents.set(entry.source, bytes.toString('utf8'));\n }\n if (!this.documents.has('skills/pua/SKILL.md')) throw new Error('缺少原版 PUA 核心文件。');\n }\n list(): readonly string[] { return [...this.documents.keys()].filter(path => path.endsWith('.md')).sort(); }\n /** 返回完整原文;未知路径失败,不将输入转换为任意文件路径。 */\n read(path: string): string {\n const text = this.documents.get(path);\n if (text === undefined) throw new Error(`未收录此原版资料:${path}`);\n return text;\n }\n body(path: string): string { return this.read(path).replace(/^---\\r?\\n[\\s\\S]*?\\r?\\n---\\r?\\n/u, '').trim(); }\n}\r\n"]}
|
package/lib/state.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
2
|
+
import { type Action } from './args.js';
|
|
3
|
+
import type { FlavorId } from './flavors.js';
|
|
4
|
+
import type { PuaMode } from './content.js';
|
|
5
|
+
import { type Configuration } from './configuration.js';
|
|
6
|
+
export interface PuaState extends Omit<Configuration, 'flavor' | 'mode'> {
|
|
7
|
+
readonly enabled: boolean;
|
|
8
|
+
readonly configured: boolean;
|
|
9
|
+
readonly flavor: FlavorId;
|
|
10
|
+
readonly flavorLocked: boolean;
|
|
11
|
+
readonly mode: PuaMode;
|
|
12
|
+
readonly loopCommandId?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const RESULT_PREFIX = "PUA \u00B7 ";
|
|
15
|
+
export declare const SESSION_RESULT_PREFIX: string;
|
|
16
|
+
export declare function transition(state: PuaState, action: Action): PuaState;
|
|
17
|
+
/**
|
|
18
|
+
* 从当前会话自己的成功命令恢复配置。分叉前缀不参与恢复,存储归宿主 profile 管理。
|
|
19
|
+
* 暂存只覆盖同步 handler 到 command/done 落日志的间隙,避免唤醒时读到旧配置。
|
|
20
|
+
*/
|
|
21
|
+
export declare class StateStore {
|
|
22
|
+
private readonly defaults;
|
|
23
|
+
private readonly parent;
|
|
24
|
+
private readonly pending;
|
|
25
|
+
private readonly cache;
|
|
26
|
+
constructor(defaults?: () => Partial<PuaState>, parent?: (session: Session) => Session | undefined);
|
|
27
|
+
/** 配置以原生命令日志保存,不追加模型消息,不会插入工具消息组。 */
|
|
28
|
+
configure(session: Session, value: unknown, expectedRevision?: number): void;
|
|
29
|
+
overrides(session: Session): Partial<Configuration>;
|
|
30
|
+
revision(session: Session): number;
|
|
31
|
+
configuration(session: Session): Configuration;
|
|
32
|
+
stage(session: Session, commandId: string, action: Action): void;
|
|
33
|
+
rollback(session: Session, commandId: string): void;
|
|
34
|
+
private invalidate;
|
|
35
|
+
read(session: Session): PuaState;
|
|
36
|
+
}
|
package/lib/state.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { parseArgs } from './args.js';
|
|
2
|
+
import { CONFIG_DEFAULTS, CONFIG_KEYS, parsePatch } from './configuration.js';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { CommandId } from '@deepseek-ai/dsh-commands';
|
|
5
|
+
const DEFAULT_STATE = Object.freeze({ ...CONFIG_DEFAULTS, enabled: false, configured: false, flavor: 'alibaba', flavorLocked: false, mode: 'pua' });
|
|
6
|
+
export const RESULT_PREFIX = 'PUA · ';
|
|
7
|
+
export const SESSION_RESULT_PREFIX = RESULT_PREFIX + '会话 · ';
|
|
8
|
+
export function transition(state, action) {
|
|
9
|
+
switch (action.kind) {
|
|
10
|
+
case 'on':
|
|
11
|
+
case 'again':
|
|
12
|
+
case 'done-check':
|
|
13
|
+
case 'evidence':
|
|
14
|
+
case 'survey':
|
|
15
|
+
return { ...state, enabled: true, configured: true };
|
|
16
|
+
case 'kpi':
|
|
17
|
+
return { ...state, enabled: true, configured: true, mode: 'pro' };
|
|
18
|
+
case 'activate':
|
|
19
|
+
return { ...state, enabled: true, configured: true };
|
|
20
|
+
case 'review':
|
|
21
|
+
return { ...state, enabled: true, configured: true, mode: 'pua' };
|
|
22
|
+
case 'mode':
|
|
23
|
+
return { ...state, enabled: true, configured: true, mode: action.mode, ...(action.task.startsWith('使用钉内/钉外味。') ? { flavor: 'ding', flavorLocked: true } : {}) };
|
|
24
|
+
case 'loop':
|
|
25
|
+
return { ...state, enabled: true, configured: true, mode: 'pua-loop' };
|
|
26
|
+
case 'cancel-pua-loop':
|
|
27
|
+
case 'teardown-all':
|
|
28
|
+
return { ...state, mode: 'pua' };
|
|
29
|
+
case 'off': {
|
|
30
|
+
const { loopCommandId: _loop, ...rest } = state;
|
|
31
|
+
return { ...rest, enabled: false, configured: true, mode: state.mode === 'pua-loop' ? 'pua' : state.mode };
|
|
32
|
+
}
|
|
33
|
+
case 'offline':
|
|
34
|
+
return { ...state, offline: true };
|
|
35
|
+
case 'flavor':
|
|
36
|
+
return { ...state, flavor: action.flavor === 'auto' ? 'alibaba' : action.flavor, flavorLocked: action.flavor !== 'auto' };
|
|
37
|
+
default:
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 从当前会话自己的成功命令恢复配置。分叉前缀不参与恢复,存储归宿主 profile 管理。
|
|
43
|
+
* 暂存只覆盖同步 handler 到 command/done 落日志的间隙,避免唤醒时读到旧配置。
|
|
44
|
+
*/
|
|
45
|
+
export class StateStore {
|
|
46
|
+
defaults;
|
|
47
|
+
parent;
|
|
48
|
+
pending = new WeakMap();
|
|
49
|
+
cache = new WeakMap();
|
|
50
|
+
constructor(defaults = () => ({}), parent = () => undefined) {
|
|
51
|
+
this.defaults = defaults;
|
|
52
|
+
this.parent = parent;
|
|
53
|
+
}
|
|
54
|
+
/** 配置以原生命令日志保存,不追加模型消息,不会插入工具消息组。 */
|
|
55
|
+
configure(session, value, expectedRevision) {
|
|
56
|
+
const patch = parsePatch(value);
|
|
57
|
+
if (expectedRevision !== undefined && expectedRevision !== this.revision(session))
|
|
58
|
+
throw new Error('配置已被其他窗口修改,请刷新后重试。');
|
|
59
|
+
const commandId = CommandId(randomUUID());
|
|
60
|
+
session.append('command/run', { commandId, name: 'pua', args: 'config ' + JSON.stringify(patch), source: { kind: 'user' } });
|
|
61
|
+
session.append('command/done', { commandId, kind: 'success', text: SESSION_RESULT_PREFIX + '配置已保存。' });
|
|
62
|
+
this.invalidate(session);
|
|
63
|
+
}
|
|
64
|
+
overrides(session) { this.read(session); return { ...this.cache.get(session)?.overrides }; }
|
|
65
|
+
revision(session) { this.read(session); return this.cache.get(session)?.revision ?? 0; }
|
|
66
|
+
configuration(session) {
|
|
67
|
+
const state = this.read(session);
|
|
68
|
+
return Object.fromEntries(CONFIG_KEYS.map(key => [key, key === 'flavor' ? (state.flavorLocked ? state.flavor : 'auto') : key === 'mode' && state.mode === 'pua-loop' ? 'pua' : state[key]]));
|
|
69
|
+
}
|
|
70
|
+
stage(session, commandId, action) {
|
|
71
|
+
let pending = this.pending.get(session);
|
|
72
|
+
if (!pending)
|
|
73
|
+
this.pending.set(session, pending = new Map());
|
|
74
|
+
pending.set(commandId, action);
|
|
75
|
+
this.invalidate(session);
|
|
76
|
+
}
|
|
77
|
+
rollback(session, commandId) {
|
|
78
|
+
this.pending.get(session)?.delete(commandId);
|
|
79
|
+
this.invalidate(session);
|
|
80
|
+
}
|
|
81
|
+
invalidate(session) {
|
|
82
|
+
const cache = this.cache.get(session);
|
|
83
|
+
if (cache)
|
|
84
|
+
delete cache.state;
|
|
85
|
+
}
|
|
86
|
+
read(session) {
|
|
87
|
+
let cache = this.cache.get(session);
|
|
88
|
+
if (!cache) {
|
|
89
|
+
cache = { cursor: session.inheritedEventCount, commands: new Map() };
|
|
90
|
+
this.cache.set(session, cache);
|
|
91
|
+
}
|
|
92
|
+
const pending = this.pending.get(session);
|
|
93
|
+
// Session 日志只追加;从分叉继承边界开始,每个命令结果只解析一次。
|
|
94
|
+
for (const event of session.snapshotEvents(cache.cursor)) {
|
|
95
|
+
if (event.type === 'command/run' && event.data.name === 'pua' && typeof event.data.args === 'string') {
|
|
96
|
+
cache.commands.set(event.data.commandId, { input: event.data.args, done: false });
|
|
97
|
+
delete cache.state;
|
|
98
|
+
}
|
|
99
|
+
else if (event.type === 'command/run' && event.data.name === 'cancel-pua-loop') {
|
|
100
|
+
cache.commands.set(event.data.commandId, { input: 'cancel-pua-loop', done: false });
|
|
101
|
+
delete cache.state;
|
|
102
|
+
}
|
|
103
|
+
else if (event.type === 'command/done' && cache.commands.has(event.data.commandId)) {
|
|
104
|
+
const record = cache.commands.get(event.data.commandId);
|
|
105
|
+
record.done = true;
|
|
106
|
+
delete record.action;
|
|
107
|
+
const outcome = event.data.text;
|
|
108
|
+
if (event.data.kind === 'success' && outcome?.startsWith(RESULT_PREFIX)) {
|
|
109
|
+
record.legacy = !outcome.startsWith(SESSION_RESULT_PREFIX);
|
|
110
|
+
// 0.1.0 将 in / pua flavor 当成任务;尊重已记录结果,不用新语法改写旧状态。
|
|
111
|
+
if (outcome.startsWith(RESULT_PREFIX + '已提交任务请求,'))
|
|
112
|
+
record.action = { kind: 'activate', task: record.input };
|
|
113
|
+
else {
|
|
114
|
+
try {
|
|
115
|
+
record.action = parseArgs(record.input);
|
|
116
|
+
}
|
|
117
|
+
catch { /* 不认识的历史命令保留在日志中,不猜测其配置语义。 */ }
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
pending?.delete(event.data.commandId);
|
|
121
|
+
delete cache.state;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
cache.cursor = session.seq;
|
|
125
|
+
const parent = this.parent(session);
|
|
126
|
+
const inherited = parent ? this.configuration(parent) : undefined;
|
|
127
|
+
const child = (session.header.delegationDepth ?? 0) > 0;
|
|
128
|
+
const defaults = inherited ? { ...inherited, flavor: inherited.flavor === 'auto' ? 'alibaba' : inherited.flavor, flavorLocked: inherited.flavor !== 'auto' } : this.defaults();
|
|
129
|
+
const defaultsKey = JSON.stringify(defaults);
|
|
130
|
+
if (cache.state && cache.defaultsKey === defaultsKey)
|
|
131
|
+
return cache.state;
|
|
132
|
+
let state = { ...DEFAULT_STATE, ...defaults };
|
|
133
|
+
const baseline = state;
|
|
134
|
+
const overrides = {};
|
|
135
|
+
let revision = 0;
|
|
136
|
+
// 按进入命令的顺序折叠,避免并发 handler 的完成顺序改变配置语义。
|
|
137
|
+
for (const [id, record] of cache.commands) {
|
|
138
|
+
const action = record.done ? record.action : pending?.get(id);
|
|
139
|
+
const before = JSON.stringify(overrides);
|
|
140
|
+
const patch = action?.kind === 'configure' ? action.patch : undefined;
|
|
141
|
+
if (patch) {
|
|
142
|
+
for (const key of CONFIG_KEYS)
|
|
143
|
+
if (key in patch) {
|
|
144
|
+
const value = patch[key];
|
|
145
|
+
if (value === null)
|
|
146
|
+
delete overrides[key];
|
|
147
|
+
else
|
|
148
|
+
Object.assign(overrides, { [key]: value });
|
|
149
|
+
if (key === 'flavor')
|
|
150
|
+
state = { ...state, flavor: value === null ? baseline.flavor : value === 'auto' ? 'alibaba' : value, flavorLocked: value === null ? baseline.flavorLocked : value !== 'auto' };
|
|
151
|
+
else
|
|
152
|
+
state = { ...state, [key]: value === null ? baseline[key] : value };
|
|
153
|
+
if (key === 'enabled' && !state.enabled && state.mode === 'pua-loop') {
|
|
154
|
+
const { loopCommandId: _loop, ...rest } = state;
|
|
155
|
+
state = { ...rest, mode: 'pua' };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (record.done && JSON.stringify(overrides) !== before)
|
|
159
|
+
revision++;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (action) {
|
|
163
|
+
state = transition(state, action);
|
|
164
|
+
// 旧版任务激活和关闭会重置角色;仅新命令使用保留角色的语义。
|
|
165
|
+
if (record.legacy && (action.kind === 'activate' || action.kind === 'off')) {
|
|
166
|
+
state = { ...state, mode: 'pua' };
|
|
167
|
+
overrides.mode = 'pua';
|
|
168
|
+
}
|
|
169
|
+
const keys = action.kind === 'flavor' ? ['flavor'] : action.kind === 'mode' ? ['enabled', 'mode', ...(action.task.startsWith('使用钉内/钉外味。') ? ['flavor'] : [])] : action.kind === 'offline' ? ['offline'] : ['on', 'off', 'activate', 'again', 'done-check', 'evidence', 'survey'].includes(action.kind) ? ['enabled'] : ['review', 'kpi', 'loop'].includes(action.kind) ? ['enabled', 'mode'] : ['cancel-pua-loop', 'teardown-all'].includes(action.kind) ? ['mode'] : [];
|
|
170
|
+
for (const key of keys)
|
|
171
|
+
Object.assign(overrides, { [key]: key === 'flavor' ? state.flavorLocked ? state.flavor : 'auto' : key === 'mode' && state.mode === 'pua-loop' ? 'pua' : state[key] });
|
|
172
|
+
if (action.kind === 'loop')
|
|
173
|
+
state = { ...state, loopCommandId: id };
|
|
174
|
+
if (record.done && JSON.stringify(overrides) !== before)
|
|
175
|
+
revision++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (child && (!inherited || !inherited.enabled || !inherited.subagents))
|
|
179
|
+
state = { ...state, enabled: false };
|
|
180
|
+
cache.overrides = overrides;
|
|
181
|
+
cache.revision = revision;
|
|
182
|
+
cache.defaultsKey = defaultsKey;
|
|
183
|
+
cache.state = Object.freeze(state);
|
|
184
|
+
return cache.state;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=state.js.map
|
package/lib/state.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAe,MAAM,WAAW,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAA+C,MAAM,oBAAoB,CAAC;AAC3H,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAWtD,MAAM,aAAa,GAAa,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAC9J,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;AACtC,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,GAAG,OAAO,CAAC;AAY7D,MAAM,UAAU,UAAU,CAAC,KAAe,EAAE,MAAc;IACxD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,IAAI,CAAC;QAAC,KAAK,OAAO,CAAC;QAAC,KAAK,YAAY,CAAC;QAAC,KAAK,UAAU,CAAC;QAAC,KAAK,QAAQ;YACxE,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACvD,KAAK,KAAK;YACR,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE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C,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;YAAE,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC9G,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;QAC5B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC1B,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;QAChC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;CACF","sourcesContent":["import type { Session } from '@deepseek-ai/dsh-session';\nimport type {} from '@deepseek-ai/dsh-commands';\nimport { parseArgs, type Action } from './args.js';\nimport type { FlavorId } from './flavors.js';\nimport type { PuaMode } from './content.js';\nimport { CONFIG_DEFAULTS, CONFIG_KEYS, parsePatch, type Configuration, type ConfigurationPatch } from './configuration.js';\nimport { randomUUID } from 'node:crypto';\nimport { CommandId } from '@deepseek-ai/dsh-commands';\n\nexport interface PuaState extends Omit<Configuration, 'flavor' | 'mode'> {\n readonly enabled: boolean;\n readonly configured: boolean;\n readonly flavor: FlavorId;\n readonly flavorLocked: boolean;\n readonly mode: PuaMode;\n readonly loopCommandId?: string;\n}\n\nconst DEFAULT_STATE: PuaState = Object.freeze({ ...CONFIG_DEFAULTS, enabled: false, configured: false, flavor: 'alibaba', flavorLocked: false, mode: 'pua' });\nexport const RESULT_PREFIX = 'PUA · ';\nexport const SESSION_RESULT_PREFIX = RESULT_PREFIX + '会话 · ';\n\ninterface CommandRecord { input: string; done: boolean; action?: Action; legacy?: boolean }\ninterface CommandCache {\n cursor: Session['seq'];\n commands: Map<string, CommandRecord>;\n state?: PuaState;\n defaultsKey?: string;\n overrides?: Partial<Configuration>;\n revision?: number;\n}\n\nexport function transition(state: PuaState, action: Action): PuaState {\n switch (action.kind) {\n case 'on': case 'again': case 'done-check': case 'evidence': case 'survey':\n return { ...state, enabled: true, configured: true };\n case 'kpi':\n return { ...state, enabled: true, configured: true, mode: 'pro' };\n case 'activate':\n return { ...state, enabled: true, configured: true };\n case 'review':\n return { ...state, enabled: true, configured: true, mode: 'pua' };\n case 'mode':\n return { ...state, enabled: true, configured: true, mode: action.mode, ...(action.task.startsWith('使用钉内/钉外味。') ? { flavor: 'ding' as const, flavorLocked: true } : {}) };\n case 'loop':\n return { ...state, enabled: true, configured: true, mode: 'pua-loop' };\n case 'cancel-pua-loop': case 'teardown-all':\n return { ...state, mode: 'pua' };\n case 'off': {\n const { loopCommandId: _loop, ...rest } = state;\n return { ...rest, enabled: false, configured: true, mode: state.mode === 'pua-loop' ? 'pua' : state.mode };\n }\n case 'offline':\n return { ...state, offline: true };\n case 'flavor':\n return { ...state, flavor: action.flavor === 'auto' ? 'alibaba' : action.flavor, flavorLocked: action.flavor !== 'auto' };\n default:\n return state;\n }\n}\n\n/**\n * 从当前会话自己的成功命令恢复配置。分叉前缀不参与恢复,存储归宿主 profile 管理。\n * 暂存只覆盖同步 handler 到 command/done 落日志的间隙,避免唤醒时读到旧配置。\n */\nexport class StateStore {\n private readonly pending = new WeakMap<Session, Map<string, Action>>();\n private readonly cache = new WeakMap<Session, CommandCache>();\n constructor(private readonly defaults: () => Partial<PuaState> = () => ({}),\n private readonly parent: (session: Session) => Session | undefined = () => undefined) {}\n\n /** 配置以原生命令日志保存,不追加模型消息,不会插入工具消息组。 */\n configure(session: Session, value: unknown, expectedRevision?: number): void {\n const patch = parsePatch(value);\n if (expectedRevision !== undefined && expectedRevision !== this.revision(session)) throw new Error('配置已被其他窗口修改,请刷新后重试。');\n const commandId = CommandId(randomUUID());\n session.append('command/run', { commandId, name: 'pua', args: 'config ' + JSON.stringify(patch), source: { kind: 'user' } });\n session.append('command/done', { commandId, kind: 'success', text: SESSION_RESULT_PREFIX + '配置已保存。' });\n this.invalidate(session);\n }\n overrides(session: Session): Partial<Configuration> { this.read(session); return { ...this.cache.get(session)?.overrides }; }\n revision(session: Session): number { this.read(session); return this.cache.get(session)?.revision ?? 0; }\n configuration(session: Session): Configuration {\n const state = this.read(session);\n return Object.fromEntries(CONFIG_KEYS.map(key => [key, key === 'flavor' ? (state.flavorLocked ? state.flavor : 'auto') : key === 'mode' && state.mode === 'pua-loop' ? 'pua' : state[key]])) as Configuration;\n }\n\n stage(session: Session, commandId: string, action: Action): void {\n let pending = this.pending.get(session);\n if (!pending) this.pending.set(session, pending = new Map());\n pending.set(commandId, action);\n this.invalidate(session);\n }\n\n rollback(session: Session, commandId: string): void {\n this.pending.get(session)?.delete(commandId);\n this.invalidate(session);\n }\n\n private invalidate(session: Session): void {\n const cache = this.cache.get(session);\n if (cache) delete cache.state;\n }\n\n read(session: Session): PuaState {\n let cache = this.cache.get(session);\n if (!cache) {\n cache = { cursor: session.inheritedEventCount, commands: new Map() };\n this.cache.set(session, cache);\n }\n const pending = this.pending.get(session);\n // Session 日志只追加;从分叉继承边界开始,每个命令结果只解析一次。\n for (const event of session.snapshotEvents(cache.cursor)) {\n if (event.type === 'command/run' && event.data.name === 'pua' && typeof event.data.args === 'string') {\n cache.commands.set(event.data.commandId, { input: event.data.args, done: false });\n delete cache.state;\n } else if (event.type === 'command/run' && event.data.name === 'cancel-pua-loop') {\n cache.commands.set(event.data.commandId, { input: 'cancel-pua-loop', done: false });\n delete cache.state;\n } else if (event.type === 'command/done' && cache.commands.has(event.data.commandId)) {\n const record = cache.commands.get(event.data.commandId)!;\n record.done = true;\n delete record.action;\n const outcome = event.data.text;\n if (event.data.kind === 'success' && outcome?.startsWith(RESULT_PREFIX)) {\n record.legacy = !outcome.startsWith(SESSION_RESULT_PREFIX);\n // 0.1.0 将 in / pua flavor 当成任务;尊重已记录结果,不用新语法改写旧状态。\n if (outcome.startsWith(RESULT_PREFIX + '已提交任务请求,')) record.action = { kind: 'activate', task: record.input };\n else {\n try { record.action = parseArgs(record.input); }\n catch { /* 不认识的历史命令保留在日志中,不猜测其配置语义。 */ }\n }\n }\n pending?.delete(event.data.commandId);\n delete cache.state;\n }\n }\n cache.cursor = session.seq;\n const parent = this.parent(session);\n const inherited = parent ? this.configuration(parent) : undefined;\n const child = (session.header.delegationDepth ?? 0) > 0;\n const defaults = inherited ? { ...inherited, flavor: inherited.flavor === 'auto' ? 'alibaba' as const : inherited.flavor, flavorLocked: inherited.flavor !== 'auto' } : this.defaults();\n const defaultsKey = JSON.stringify(defaults);\n if (cache.state && cache.defaultsKey === defaultsKey) return cache.state;\n let state = { ...DEFAULT_STATE, ...defaults };\n const baseline = state;\n const overrides: Partial<Configuration> = {};\n let revision = 0;\n // 按进入命令的顺序折叠,避免并发 handler 的完成顺序改变配置语义。\n for (const [id, record] of cache.commands) {\n const action = record.done ? record.action : pending?.get(id);\n const before = JSON.stringify(overrides);\n const patch = action?.kind === 'configure' ? action.patch : undefined;\n if (patch) {\n for (const key of CONFIG_KEYS) if (key in patch) {\n const value = patch[key];\n if (value === null) delete overrides[key];\n else Object.assign(overrides, { [key]: value });\n if (key === 'flavor') state = { ...state, flavor: value === null ? baseline.flavor : value === 'auto' ? 'alibaba' : value as FlavorId, flavorLocked: value === null ? baseline.flavorLocked : value !== 'auto' };\n else state = { ...state, [key]: value === null ? baseline[key] : value };\n if (key === 'enabled' && !state.enabled && state.mode === 'pua-loop') {\n const { loopCommandId: _loop, ...rest } = state;\n state = { ...rest, mode: 'pua' };\n }\n }\n if (record.done && JSON.stringify(overrides) !== before) revision++;\n continue;\n }\n if (action) {\n state = transition(state, action);\n // 旧版任务激活和关闭会重置角色;仅新命令使用保留角色的语义。\n if (record.legacy && (action.kind === 'activate' || action.kind === 'off')) {\n state = { ...state, mode: 'pua' };\n overrides.mode = 'pua';\n }\n const keys: (keyof Configuration)[] = action.kind === 'flavor' ? ['flavor'] : action.kind === 'mode' ? ['enabled', 'mode', ...(action.task.startsWith('使用钉内/钉外味。') ? ['flavor' as const] : [])] : action.kind === 'offline' ? ['offline'] : ['on', 'off', 'activate', 'again', 'done-check', 'evidence', 'survey'].includes(action.kind) ? ['enabled'] : ['review', 'kpi', 'loop'].includes(action.kind) ? ['enabled', 'mode'] : ['cancel-pua-loop', 'teardown-all'].includes(action.kind) ? ['mode'] : [];\n for (const key of keys) Object.assign(overrides, { [key]: key === 'flavor' ? state.flavorLocked ? state.flavor : 'auto' : key === 'mode' && state.mode === 'pua-loop' ? 'pua' : state[key] });\n if (action.kind === 'loop') state = { ...state, loopCommandId: id };\n if (record.done && JSON.stringify(overrides) !== before) revision++;\n }\n }\n if (child && (!inherited || !inherited.enabled || !inherited.subagents)) state = { ...state, enabled: false };\n cache.overrides = overrides;\n cache.revision = revision;\n cache.defaultsKey = defaultsKey;\n cache.state = Object.freeze(state);\n return cache.state;\n }\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolExecutionResult } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
export declare const TERMINAL_REVIEW_PROMPT = "PUA \u00B7 \u7EC8\u7AEF\u72B6\u6001\u5F85\u6838\u9A8C\uFF1A\u8F93\u51FA\u5305\u542B\u975E\u96F6\u9000\u51FA\u3001\u8D85\u65F6\u6216 shell \u5F02\u5E38\u7ED3\u675F\u7684\u6587\u672C\u6807\u8BB0\uFF0C\u4F46\u6587\u672C\u4E5F\u53EF\u80FD\u7531\u547D\u4EE4\u81EA\u884C\u6253\u5370\u3002\u5148\u7ED3\u5408\u5B9E\u9645\u9519\u8BEF\u3001\u5F53\u524D\u5B50\u76EE\u6807\u548C\u5FC5\u8981\u7684\u72EC\u7ACB\u68C0\u67E5\u5224\u65AD\uFF0C\u518D\u9009\u62E9\u4FEE\u590D\u65B9\u6CD5\uFF1B\u4E0D\u8981\u4EC5\u51ED\u6807\u8BB0\u5BA3\u79F0\u5931\u8D25\u6B21\u6570\u3001\u5347\u7EA7\u538B\u529B\u6216\u58F0\u79F0\u9A8C\u6536\u901A\u8FC7\u3002";
|
|
3
|
+
/** 持久终端仅返回文本时提供核验线索;绝不将可伪造的输出算成结构化失败。 */
|
|
4
|
+
export declare function terminalTextNeedsReview(result: Readonly<ToolExecutionResult>): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const TERMINAL_REVIEW_PROMPT = 'PUA · 终端状态待核验:输出包含非零退出、超时或 shell 异常结束的文本标记,但文本也可能由命令自行打印。先结合实际错误、当前子目标和必要的独立检查判断,再选择修复方法;不要仅凭标记宣称失败次数、升级压力或声称验收通过。';
|
|
2
|
+
/** 持久终端仅返回文本时提供核验线索;绝不将可伪造的输出算成结构化失败。 */
|
|
3
|
+
export function terminalTextNeedsReview(result) {
|
|
4
|
+
if (result.isError || typeof result.value !== 'string')
|
|
5
|
+
return false;
|
|
6
|
+
const value = result.value.trim();
|
|
7
|
+
const exit = /(?:^|\n)\[(?:exit code: |shell exited: code |Command finished with exit code )(-?\d+)\](?:\r?\nThe persistent (?:pwsh|bash) shell was reset;[^\n]*)?$/u.exec(value);
|
|
8
|
+
return (exit !== null && Number(exit[1]) !== 0)
|
|
9
|
+
|| /^Your command timed out after \d+ seconds or experienced an OOM error\./u.test(value)
|
|
10
|
+
|| /(?:^|\n)\[shell killed by signal: [A-Z0-9]+\](?:\r?\nThe persistent (?:pwsh|bash) shell was reset;[^\n]*)?$/u.test(value);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=terminal-observation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-observation.js","sourceRoot":"","sources":["../src/terminal-observation.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAG,oHAAoH,CAAC;AAE3J,yCAAyC;AACzC,MAAM,UAAU,uBAAuB,CAAC,MAAqC;IAC3E,IAAI,MAAM,CAAC,OAAO,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACrE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,wJAAwJ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClL,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;WAC1C,0EAA0E,CAAC,IAAI,CAAC,KAAK,CAAC;WACtF,8GAA8G,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClI,CAAC","sourcesContent":["import type { ToolExecutionResult } from '@deepseek-ai/dsh-tools';\n\nexport const TERMINAL_REVIEW_PROMPT = 'PUA · 终端状态待核验:输出包含非零退出、超时或 shell 异常结束的文本标记,但文本也可能由命令自行打印。先结合实际错误、当前子目标和必要的独立检查判断,再选择修复方法;不要仅凭标记宣称失败次数、升级压力或声称验收通过。';\n\n/** 持久终端仅返回文本时提供核验线索;绝不将可伪造的输出算成结构化失败。 */\nexport function terminalTextNeedsReview(result: Readonly<ToolExecutionResult>): boolean {\n if (result.isError || typeof result.value !== 'string') return false;\n const value = result.value.trim();\n const exit = /(?:^|\\n)\\[(?:exit code: |shell exited: code |Command finished with exit code )(-?\\d+)\\](?:\\r?\\nThe persistent (?:pwsh|bash) shell was reset;[^\\n]*)?$/u.exec(value);\n return (exit !== null && Number(exit[1]) !== 0)\n || /^Your command timed out after \\d+ seconds or experienced an OOM error\\./u.test(value)\n || /(?:^|\\n)\\[shell killed by signal: [A-Z0-9]+\\](?:\\r?\\nThe persistent (?:pwsh|bash) shell was reset;[^\\n]*)?$/u.test(value);\n}\n"]}
|