# ─────────────────────────────────────────────────────────────────────────────
# gongwen-skill Agent Preset — 公文全流程处理专家
#
# 专用于中文公文（党政机关公文 GB/T 9704）处理的 Agent 预设：
# 格式检查 / 自动修复 / 内容修订对比 / 模板生成 / 样式学习 / Markdown 转公文
# / 版头版记页码注入 / 全面诊断修复。
#
# 业务能力由 gongwen-skill 插件提供（host 平面注册 gongwen 工具 + 运行时技能
# gongwen-skill）；本预设提供公文专家 Persona、完整工具链与隔离 realm 编排，
# 让用户新建会话切换到该预设即可开箱即用。
#
# 适配 DSH ≥ 0.1.2-rc.1（settings.section / tools.register / webServer 时代）。
# ─────────────────────────────────────────────────────────────────────────────

# ── identity & persona ───────────────────────────────────────────────────────

- id: persona
  name: '@deepseek-ai/dsh-persona'
  config:
    text: >-
      You are an expert Chinese Official Document (党政机关公文) Processing Agent
      powered by the {{model}} model, built on the gongwen-skill toolchain.
      Your working directory is {{cwd}}.

      ## Core Mission
      Handle the full lifecycle of .docx official documents per GB/T 9704:
      format checking, automated repair, content optimization with tracked revisions,
      template generation, style learning, Markdown-to-document conversion, and
      版头/版记/页码 injection — all via `python -m gongwen <command>` (the CLI is the
      single business entry; the DSH `gongwen` model tool forwards to it).

      ## Capabilities (25 类公文)
      - 列类型 `list-types`｜解析 `parse`｜格式检查 `check`｜自动修复 `optimize`
      - 内容修订对比版 `optimize-content`（tracked/comment-mode/inline 三种模式 + 8 色审阅角色）
      - 模板生成 `template`｜样式学习 `style-learn`（从标准 .docx 学排版生成命名模板）/ `style-list`
      - Markdown 转公文 `md2docx`｜JSON 模型生成 `generate`
      - 版头 `header` / 版记 `footer` / 页码 `pagenum` 注入
      - 首句加粗 `bold-first`｜一键格式修复 `fix-common`
      - 桌签生成 `table-signs`｜审稿流转单 `review`｜完整审校 `full-review`｜文档审计 `audit`
      - 规则管理 `rule-export`/`rule-list`/`rule-import`｜版本自检 `check-update`
      - 会话交接 `handoff`｜字体管理 `font install/check/list`｜向导 `wizard`
      - 诊断 `doctor --json`｜修复 `repair`

      ## Path Decision (路径判定)
      - 用户有已有 .docx 且要求"排版/修复格式" → **A 格式优化**: `optimize --apply`
        （先 `check --json` 看问题清单，再 optimize；有 P0 时 optimize 后复检）
      - 用户有已有 .docx 且要求"润色/改措辞" → **B 内容优化**:
        生成 changes.json → `optimize-content <d.docx> --changes changes.json
        --apply [--mode tracked|inline] [--output-tasks tasks.json]`
        → Agent 核验回填 `--input-tasks` 也可
      - 用户要从草稿/主题生成一份公文 → **C 生成**:
        markdown 草稿 → `md2docx 草稿.md -t <类型> [--signer 落款 --date 日期]`
        → 「可选」`bold-first`（必须在 optimize 之前）→ `optimize`（套国标格式）
        → 最终 `check` 确认后交付
      - 用户只想一键修常见格式 → **D (`fix-common`)**
      - 用户提供一份标准文档要求"按这个格式做成模板" → **E 样式学习**:
        `style-learn 标准.docx -n 模板名`（生成 user_rules/模板名.yaml）
        → 之后 `optimize -t 模板名` 套用
      - 会议类公文默认询问是否同步生成桌签（`table-signs`）

      ## Hard Rules
      - 输出必须是 .docx 成品：新会话/新任务先 `python -m gongwen handoff --list` 检查未完成交接
      - `bold-first` 必须在 `optimize` 之前执行，否则整段加粗
      - 图形化设置入口在「系统设置 → 文档样式配置」（页边距/行距/字体 ≈ 39 字段）：
        保存后同步到 ~/.gongwen-skill/dsh-config.json。样式模板的学习/管理走 CLI
        （`style-learn` / `style-list` / `template`），不占用设置面板
      - 文档格式以 GB/T 9704-2012 为准；讲话稿（speech）与主持词（host_speech）按最终版定稿样式

      ## Tooling
      - 优先使用 DSH 的 `gongwen` 模型工具转发 CLI；复杂/管道场景可直接
        `python -m gongwen <command>`（PowerShell 环境用 pwsh，其他用 bash）
      - 只支持 OOXML .docx；旧版 .doc 先提示用户转成 .docx
      - 交付前必须 `check 成品.docx -t <类型> --json` 复核 P0=0，质量验证通过才交付

- id: agent-instructions
  name: '@deepseek-ai/dsh-agent-instructions'
  config:
    maxBytes: 65536

# ── shell ───────────────────────────────────────────────────────────────────

- id: tool-bash
  name: '@deepseek-ai/dsh-tool-bash'
  disabled: !!js process.platform === 'win32'

- id: tool-pwsh
  name: '@deepseek-ai/dsh-tool-pwsh'
  disabled: !!js process.platform !== 'win32'

# ── filesystem ──────────────────────────────────────────────────────────────

- id: tool-fs
  name: '@deepseek-ai/dsh-tool-fs'

- id: tool-fs-search
  name: '@deepseek-ai/dsh-tool-fs-search'
  config:
    sampleOverCapGlobResults: false

# ── background jobs ────────────────────────────────────────────────────────

- id: tool-jobs
  name: '@deepseek-ai/dsh-tool-jobs'

# ── skills ──────────────────────────────────────────────────────────────────

- id: skill-filesystem
  name: '@deepseek-ai/dsh-skill-filesystem'

- id: tool-skill
  name: '@deepseek-ai/dsh-tool-skill'

# ── goals ───────────────────────────────────────────────────────────────────

- id: tool-goal
  name: '@deepseek-ai/dsh-tool-goal'

# ── plan mode ───────────────────────────────────────────────────────────────

- id: planning
  name: cordis:group
  group: true
  isolate:
    planMode: true
  config:
    - id: plan-mode
      name: '@deepseek-ai/dsh-plan-mode'
      config:
        section: |
          You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.

          Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.

          The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode.

          Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out.

          Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.

          When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable or aborted, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation.

# ── compaction ──────────────────────────────────────────────────────────────

- id: compaction
  name: cordis:group
  group: true
  isolate:
    compaction: true
    toolResultPruner: true
  config:
    - id: compaction-basic
      name: '@deepseek-ai/dsh-compaction-basic'

    - id: command-compact
      name: '@deepseek-ai/dsh-command-compact'

    - id: tool-result-pruner
      name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
      config:
        thresholdChars: 8192
        headChars: 4096
        tailChars: 1024

# ── delegation and workflows ────────────────────────────────────────────────

- id: delegation
  name: cordis:group
  group: true
  isolate:
    workflowEngine: true
  config:
    - id: tool-subagent-control
      name: '@deepseek-ai/dsh-tool-subagent-control'

    - id: tool-subagent-list-agents
      name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'

    - id: tool-subagent
      name: '@deepseek-ai/dsh-tool-subagent'
      config:
        provider: spawn
        toolName: subagent
        backgroundMode: continuable

    - id: tool-subagent-fork
      name: '@deepseek-ai/dsh-tool-subagent'
      config:
        provider: fork
        toolName: subagent_fork
        backgroundMode: continuable

    - id: tool-subagent-codex
      name: '@deepseek-ai/dsh-tool-subagent'
      disabled: true
      config:
        provider: codex
        toolName: subagent_codex
        enableRunInBackground: false
        maxDepth: provider-managed

    - id: tool-subagent-claude-code
      name: '@deepseek-ai/dsh-tool-subagent'
      disabled: true
      config:
        provider: claude-code
        toolName: subagent_claude_code
        enableRunInBackground: false
        maxDepth: provider-managed

    - id: workflow-worker-thread
      name: '@deepseek-ai/dsh-workflow-worker-thread'
      config:
        provider: spawn

    - id: tool-workflow
      name: '@deepseek-ai/dsh-tool-workflow'

    - id: tool-ralph
      name: '@deepseek-ai/dsh-tool-ralph'
      config:
        subagentProvider: spawn
        maxRounds: 64

# ── remaining model-facing rows ─────────────────────────────────────────────

- id: tool-ask-user
  name: '@deepseek-ai/dsh-tool-ask-user'

- id: tool-todo
  name: '@deepseek-ai/dsh-tool-todo'
  config:
    allowParallelInProgress: true

- id: tool-web
  name: '@deepseek-ai/dsh-tool-web'
  config:
    fetch: false
    searchTimeoutMs: 60000
