糸の窝
    avatar

    大战能量外壳:配置DeepSeek Harness PowerShell工具集

    用例

    四个命令都支持使用Get-Help获取帮助,使用示例:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    # 启动DeepSeek Harness
    dshweb
    Start-DshWeb

    # 安装插件
    dshinstall plugin-name -git
    Install-DshPlugin plugin-name -Git

    # 列出插件(默认web profile)
    dshlist
    dshlist tui
    Get-DshPlugin

    # 移除插件(默认web profile)
    dshremove plugin-name
    Uninstall-DshPlugin plugin-name -Profile tui
    # 跳过确认
    dshremove plugin-name -Confirm:$false

    (别问为什么前两个没有支持其他Profile,问就是后面那俩是大肥鱼顺手给补上的,前面我自己写的时候没想到)

    配置

    要求PowerShell版本在5.1及以上,使用 code $PROFILE 使用VSCode打开PowerShell配置文件(类似 ~/.bashrc 的文件)

    在文件末尾粘贴以下内容:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175

    #Requires -Version 5.1

    <#
    .SYNOPSIS
    启动 DeepSeek Harness 的 Web Profile。

    .DESCRIPTION
    通过 npx 运行 @deepseek-ai/dsh 的 web 子命令。

    .EXAMPLE
    Start-DshWeb
    #>
    function Start-DshWeb {
    [CmdletBinding()]
    [OutputType([void])]
    param()

    if (-not (Get-Command -Name npx -ErrorAction SilentlyContinue)) {
    throw "未在 PATH 中找到 npx,请先安装 Node.js (https://nodejs.org/)。"
    }

    Write-Verbose "> npx -y @deepseek-ai/dsh@latest web"
    npx -y '@deepseek-ai/dsh@latest' web
    }

    <#
    .SYNOPSIS
    在 DeepSeek Harness 的 Web Profile 中安装插件。

    .DESCRIPTION
    在 DSH 的 web profile 中添加插件。

    .PARAMETER Name
    插件名称。配合 -Git 时将从 GitHub 安装。

    .PARAMETER Git
    从 GitHub 安装(等价于给名称加上 'github:' 前缀)。

    .PARAMETER RemainingArgs
    容错参数:当用户书写 `--git` / `--github` 被 PowerShell 当作位置参数时,
    在这里被重新识别为开关。

    .EXAMPLE
    Install-DshPlugin plugin-name

    .EXAMPLE
    Install-DshPlugin plugin-name -Git

    .EXAMPLE
    Install-DshPlugin plugin-name --git
    #>
    function Install-DshPlugin {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    [OutputType([void])]
    param(
    [Parameter(Mandatory, Position = 0)]
    [ValidateNotNullOrEmpty()]
    [string]$Name,

    [Alias('g', 'github')]
    [switch]$Git,

    # 兼容 `--git` 这类被 PowerShell 当作位置实参的写法
    [Parameter(ValueFromRemainingArguments)]
    [string[]]$RemainingArgs
    )

    foreach ($arg in $RemainingArgs) {
    switch -Regex ($arg) {
    '^--?git(hub)?$' { $Git = $true; continue }
    default { Write-Warning "忽略未知参数: $arg" }
    }
    }

    $pluginSpec = if ($Git) { "github:$Name" } else { $Name }

    if ($PSCmdlet.ShouldProcess('DeepSeek Harness', "安装插件: $pluginSpec")) {
    Write-Verbose "Install from GitHub: $($Git.IsPresent)"
    if($Git) {
    Write-Verbose "Installing from GitHub..."
    } else {
    Write-Verbose "Installing from NPM..."
    }
    Write-Host "> npx -y @deepseek-ai/dsh@latest plugin --profile web add $pluginSpec" -ForegroundColor Cyan

    npx -y '@deepseek-ai/dsh@latest' plugin --profile web add $pluginSpec
    }
    }

    <#
    .SYNOPSIS
    列出 DeepSeek Harness 中 Web Profile 中已安装的插件。

    .DESCRIPTION
    通过 npx 运行 @deepseek-ai/dsh 的 plugin 子命令,列出 web profile 下的插件。

    .PARAMETER Profile
    要查询的 profile 名称,默认为 'web'。

    .EXAMPLE
    Get-DshPlugin

    .EXAMPLE
    Get-DshPlugin -Profile tui
    #>
    function Get-DshPlugin {
    [CmdletBinding()]
    [OutputType([void])]
    param(
    [Parameter(Position = 0)]
    [ValidateNotNullOrEmpty()]
    [string]$Profile = 'web'
    )

    if (-not (Get-Command -Name npx -ErrorAction SilentlyContinue)) {
    throw "未在 PATH 中找到 npx,请先安装 Node.js (https://nodejs.org)。"
    }

    Write-Verbose "> npx -y @deepseek-ai/dsh@latest plugin --profile $Profile list"

    npx -y '@deepseek-ai/dsh@latest' plugin --profile $Profile list
    }

    <#
    .SYNOPSIS
    从 DeepSeek Harness 的 Web Profile 中移除一个插件。

    .DESCRIPTION
    通过 npx 运行 @deepseek-ai/dsh 的 plugin 子命令,从指定 profile 移除插件。
    默认支持 -WhatIf / -Confirm。

    .PARAMETER Name
    要移除的插件名称。

    .PARAMETER Profile
    目标 profile 名称,默认为 'web'。

    .EXAMPLE
    Uninstall-DshPlugin plugin-name

    .EXAMPLE
    Uninstall-DshPlugin plugin-name -WhatIf

    .EXAMPLE
    Uninstall-DshPlugin plugin-name -Profile tui -Confirm:$false
    #>
    function Uninstall-DshPlugin {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    [OutputType([void])]
    param(
    [Parameter(Mandatory, Position = 0)]
    [ValidateNotNullOrEmpty()]
    [string]$Name,

    [Parameter(Position = 1)]
    [ValidateNotNullOrEmpty()]
    [string]$Profile = 'web'
    )

    if (-not (Get-Command -Name npx -ErrorAction SilentlyContinue)) {
    throw "未在 PATH 中找到 npx,请先安装 Node.js (https://nodejs.org)。"
    }

    if ($PSCmdlet.ShouldProcess('DeepSeek Harness', "在配置文件 $Profile 中移除插件: $Name")) {
    Write-Host "> npx -y @deepseek-ai/dsh@latest plugin --profile $Profile remove $Name" -ForegroundColor Cyan

    npx -y '@deepseek-ai/dsh@latest' plugin --profile $Profile remove $Name
    }
    }

    Set-Alias -Name dshweb -Value Start-DshWeb -Scope Global -Force -ErrorAction SilentlyContinue
    Set-Alias -Name dshinstall -Value Install-DshPlugin -Scope Global -Force -ErrorAction SilentlyContinue
    Set-Alias -Name dshlist -Value Get-DshPlugin -Scope Global -Force -ErrorAction SilentlyContinue
    Set-Alias -Name dshremove -Value Uninstall-DshPlugin -Scope Global -Force -ErrorAction SilentlyContinue