dsh-perm-gate 5.5.2 → 5.5.4

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.5.4
4
+
5
+ - 终端面(dsh-tui / Desktop 命令面板同源):/gate 终端面(status/rules/why/history/grants)+ GrantRegistry.list()。
6
+
3
7
  ## Unreleased
4
8
 
5
9
  ## 5.5.2 (2026-11-12)
package/README.ja.md CHANGED
@@ -64,7 +64,7 @@ fail-closed を徹底します:P0 の判定は、grant・ルール・分類器
64
64
 
65
65
  <!-- host-compat:begin — generated by scripts/sync-hosts.mjs from scripts/hosts.mjs; DO NOT EDIT -->
66
66
  - **対応する DSH ホスト:** `0.1.0-rc.2` `0.1.0-rc.3` `0.1.0-rc.6` `0.1.0-rc.7` `0.1.0-rc.8` `0.1.1-rc.1` `0.1.1-rc.2` `0.1.2-rc.1` `0.1.5-rc.1` `0.1.5-rc.2` `0.1.5-rc.3` `0.1.7-rc.1` `0.1.7-rc.2` `0.2.0-rc.1` `0.2.0-rc.2` `0.2.1-rc.1` `0.2.1-rc.2` `0.2.1-rc.3` `0.2.1-rc.4` `0.2.1-rc.5` `0.2.2-rc.1`(0.1.0 / 0.1.1 / 0.1.2 / 0.1.5 / 0.1.7 / 0.2.0 / 0.2.1 の 21 rc)
67
- - **ランタイム検証済み:** `0.2.0-rc.2`(証跡は `.compat-results/`)
67
+ - **ランタイム検証済み:** `0.1.0-rc.2`, `0.1.0-rc.3`, `0.1.0-rc.6`, `0.1.0-rc.7`, `0.1.0-rc.8`, `0.1.1-rc.1`, `0.1.1-rc.2`, `0.1.2-rc.1`, `0.1.5-rc.1`, `0.1.5-rc.2`, `0.1.5-rc.3`, `0.1.7-rc.1`, `0.1.7-rc.2`, `0.2.0-rc.1`, `0.2.0-rc.2`(証跡は `.compat-results/`)
68
68
  <!-- host-compat:end -->
69
69
 
70
70
  ## 背景
package/README.ko.md CHANGED
@@ -62,7 +62,7 @@ DeepSeek Harness용 단일·자족적·결정론 우선·fail-closed 권한 게
62
62
 
63
63
  <!-- host-compat:begin — generated by scripts/sync-hosts.mjs from scripts/hosts.mjs; DO NOT EDIT -->
64
64
  - **지원하는 DSH 호스트:** `0.1.0-rc.2` `0.1.0-rc.3` `0.1.0-rc.6` `0.1.0-rc.7` `0.1.0-rc.8` `0.1.1-rc.1` `0.1.1-rc.2` `0.1.2-rc.1` `0.1.5-rc.1` `0.1.5-rc.2` `0.1.5-rc.3` `0.1.7-rc.1` `0.1.7-rc.2` `0.2.0-rc.1` `0.2.0-rc.2` `0.2.1-rc.1` `0.2.1-rc.2` `0.2.1-rc.3` `0.2.1-rc.4` `0.2.1-rc.5` `0.2.2-rc.1` (0.1.0 / 0.1.1 / 0.1.2 / 0.1.5 / 0.1.7 / 0.2.0 / 0.2.1 라인의 21개 rc)
65
- - **런타임 검증됨:** `0.2.0-rc.2` (증적은 `.compat-results/`)
65
+ - **런타임 검증됨:** `0.1.0-rc.2`, `0.1.0-rc.3`, `0.1.0-rc.6`, `0.1.0-rc.7`, `0.1.0-rc.8`, `0.1.1-rc.1`, `0.1.1-rc.2`, `0.1.2-rc.1`, `0.1.5-rc.1`, `0.1.5-rc.2`, `0.1.5-rc.3`, `0.1.7-rc.1`, `0.1.7-rc.2`, `0.2.0-rc.1`, `0.2.0-rc.2` (증적은 `.compat-results/`)
66
66
  <!-- host-compat:end -->
67
67
 
68
68
  ## 배경
package/README.md CHANGED
@@ -60,7 +60,7 @@ Strictly fail-closed: a P0 decision is never overridden by a grant, a rule, the
60
60
 
61
61
  <!-- host-compat:begin — generated by scripts/sync-hosts.mjs from scripts/hosts.mjs; DO NOT EDIT -->
62
62
  - **Supported DSH hosts:** `0.1.0-rc.2` `0.1.0-rc.3` `0.1.0-rc.6` `0.1.0-rc.7` `0.1.0-rc.8` `0.1.1-rc.1` `0.1.1-rc.2` `0.1.2-rc.1` `0.1.5-rc.1` `0.1.5-rc.2` `0.1.5-rc.3` `0.1.7-rc.1` `0.1.7-rc.2` `0.2.0-rc.1` `0.2.0-rc.2` `0.2.1-rc.1` `0.2.1-rc.2` `0.2.1-rc.3` `0.2.1-rc.4` `0.2.1-rc.5` `0.2.2-rc.1` (21 rc releases across lines 0.1.0 / 0.1.1 / 0.1.2 / 0.1.5 / 0.1.7 / 0.2.0 / 0.2.1)
63
- - **Runtime-verified:** `0.2.0-rc.2` — evidence in `.compat-results/`
63
+ - **Runtime-verified:** `0.1.0-rc.2`, `0.1.0-rc.3`, `0.1.0-rc.6`, `0.1.0-rc.7`, `0.1.0-rc.8`, `0.1.1-rc.1`, `0.1.1-rc.2`, `0.1.2-rc.1`, `0.1.5-rc.1`, `0.1.5-rc.2`, `0.1.5-rc.3`, `0.1.7-rc.1`, `0.1.7-rc.2`, `0.2.0-rc.1`, `0.2.0-rc.2` — evidence in `.compat-results/`
64
64
  <!-- host-compat:end -->
65
65
 
66
66
  ## Why
@@ -624,4 +624,17 @@ npm run build
624
624
 
625
625
  ## License
626
626
 
627
- [MIT](./LICENSE)
627
+ [MIT](./LICENSE)
628
+
629
+ ## TUI 终端面(dsh-tui)
630
+
631
+ dsh-tui 不加载插件的 client 半边(面板/卡片/设置页),也调不到插件自有 RPC;工具调用只显示一行摘要。人可读、人可操作的面只剩宿主斜杠命令。输出约定:单行 ≤100 字符、总行 ≤40、无 ANSI、两空格对齐;写操作默认 dry、加 `--yes` 才执行;`--json` 输出单行 JSON。
632
+
633
+ | 命令 | 作用 |
634
+ |---|---|
635
+ | `/gate` | 规则文件路径、默认动作、allow/deny/ask 计数 |
636
+ | `/gate rules` | 规则计数摘要 |
637
+ | `/gate why <command>` | 对一条命令干跑判定链(不执行) |
638
+ | `/gate history` | 最近 10 条判定/审批(审计环,`--n=20`) |
639
+
640
+ 命令由插件自己在宿主侧注册(`ctx.inject(['commands'], …)`):命令服务缺席的老宿主线上不激活、不报错。
package/README.zh.md CHANGED
@@ -57,7 +57,7 @@
57
57
 
58
58
  <!-- host-compat:begin — generated by scripts/sync-hosts.mjs from scripts/hosts.mjs; DO NOT EDIT -->
59
59
  - **支持的 DSH 宿主:** `0.1.0-rc.2` `0.1.0-rc.3` `0.1.0-rc.6` `0.1.0-rc.7` `0.1.0-rc.8` `0.1.1-rc.1` `0.1.1-rc.2` `0.1.2-rc.1` `0.1.5-rc.1` `0.1.5-rc.2` `0.1.5-rc.3` `0.1.7-rc.1` `0.1.7-rc.2` `0.2.0-rc.1` `0.2.0-rc.2` `0.2.1-rc.1` `0.2.1-rc.2` `0.2.1-rc.3` `0.2.1-rc.4` `0.2.1-rc.5` `0.2.2-rc.1`(覆盖 0.1.0 / 0.1.1 / 0.1.2 / 0.1.5 / 0.1.7 / 0.2.0 / 0.2.1 七条线共 21 个 rc)
60
- - **运行时已验证:** `0.2.0-rc.2`(证据见 `.compat-results/`)
60
+ - **运行时已验证:** `0.1.0-rc.2`, `0.1.0-rc.3`, `0.1.0-rc.6`, `0.1.0-rc.7`, `0.1.0-rc.8`, `0.1.1-rc.1`, `0.1.1-rc.2`, `0.1.2-rc.1`, `0.1.5-rc.1`, `0.1.5-rc.2`, `0.1.5-rc.3`, `0.1.7-rc.1`, `0.1.7-rc.2`, `0.2.0-rc.1`, `0.2.0-rc.2`(证据见 `.compat-results/`)
61
61
  <!-- host-compat:end -->
62
62
 
63
63
  ## 特性
package/dsh.plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "dsh-perm-gate",
3
3
  "name": "dsh-perm-gate",
4
- "version": "5.5.2",
4
+ "version": "5.5.4",
5
5
  "description": {
6
6
  "en": "Deterministic-first, fail-closed permission gate for DeepSeek Harness 0.1.2+: a P0 hard-deny -> P1 precise session grant -> P2 static allow/deny rule chain -> P3 optional LLM classifier -> P4 ask pipeline over the tools/pre-execute waterfall, with a standalone CLI dry-run evaluator and an auditable decision log. Credential handling is a seven-family ladder (ssh/cloud/package/gitcreds/env/cli/db) with deny/ask/readonly/readwrite rungs kept in the rules document plus a paired write-exemption list; a protected-branch push switch keeps the P0 floor by default. It only vetoes with deny/ask and always delegates otherwise, and unknown or malformed rules fail loud instead of silently standing the gate down.",
7
7
  "zh": "面向 DeepSeek Harness 0.1.2+ 的确定性优先、失败即拒的权限闸门:在 tools/pre-execute 瀑布上串起 P0 硬拒绝 → P1 精确会话授权 → P2 静态 allow/deny 规则链 → P3 可选 LLM 语义分类 → P4 ask,并附带独立 CLI 干跑评估器与可审计的决策日志。凭据处理为七族阶梯(ssh/cloud/package/gitcreds/env/cli/db)× deny/ask/readonly/readwrite 四档,档位存规则文档 + 成对写豁免清单;保护分支强推开关默认保留 P0 地板。只以 deny/ask 否决、其余一律放行,规则未知或非法时直接报错,绝不静默失效。"
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "license": "MIT",
15
15
  "engines": {
16
- "dsh": ">=0.1.1-rc.2 <0.3.0"
16
+ "dsh": ">=0.1.0-rc.2 <0.3.0-0"
17
17
  },
18
18
  "components": {
19
19
  "host": "lib/index.js",
package/lib/grant.d.ts CHANGED
@@ -47,6 +47,17 @@ export declare class GrantRegistry {
47
47
  private readonly grants;
48
48
  constructor(sessionId: string, now?: () => number);
49
49
  get size(): number;
50
+ /**
51
+ * Read-only summary of the live grants (TUI `/gate grants` 用)。
52
+ *
53
+ * 只暴露清单需要的三列:工具名、到期时间、剩余次数——不泄露指纹、
54
+ * 也不给任何改动入口(本方法无副作用)。
55
+ */
56
+ list(): Array<{
57
+ tool: string;
58
+ expiresAt: number;
59
+ remaining: number;
60
+ }>;
50
61
  /** Mint a precise grant. Self-minting restrictions are enforced by the decision engine, not here. */
51
62
  mint(spec: Omit<GrantSpec, 'sessionId' | 'expiresAt'>): SessionGrant;
52
63
  /**
package/lib/grant.js CHANGED
@@ -77,6 +77,19 @@ export class GrantRegistry {
77
77
  get size() {
78
78
  return this.grants.length;
79
79
  }
80
+ /**
81
+ * Read-only summary of the live grants (TUI `/gate grants` 用)。
82
+ *
83
+ * 只暴露清单需要的三列:工具名、到期时间、剩余次数——不泄露指纹、
84
+ * 也不给任何改动入口(本方法无副作用)。
85
+ */
86
+ list() {
87
+ return this.grants.map((grant) => ({
88
+ tool: grant.spec.tool,
89
+ expiresAt: grant.expiresAt,
90
+ remaining: grant.remaining,
91
+ }));
92
+ }
80
93
  /** Mint a precise grant. Self-minting restrictions are enforced by the decision engine, not here. */
81
94
  mint(spec) {
82
95
  const now = this.now();
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ import { buildReceiverInfo } from './receiver-info.js';
13
13
  import { composeReviewOpinion } from './feedback.js';
14
14
  import { redactCommandText } from './redact.js';
15
15
  import { readRulesView, readRulesViewFromSettings } from './rules-view.js';
16
+ import { registerGateCommand } from './tui-command.js';
16
17
  import { PermGateRuntime } from './runtime.js';
17
18
  import { classifySessions, sweepSessionData } from './session-sweep.js';
18
19
  import { isHumanFree } from './unattended.js';
@@ -1152,5 +1153,29 @@ export function apply(ctx, config = {}) {
1152
1153
  ruleWatcher.closeAll();
1153
1154
  }, 'dsh-perm-gate: rule watcher');
1154
1155
  }
1156
+ // ── dsh-tui 终端面:`/gate` ────────────────────────────────────────
1157
+ // TUI 下 history 卡片/规则页不执行,审批只显示 toolName 一行——无法回答
1158
+ // 「为什么被拦」。命令面复用与面板同一条路径:规则视图 + 干跑(不执行)。
1159
+ ;
1160
+ ctx.inject?.(['commands'], (scope) => {
1161
+ registerGateCommand(scope, {
1162
+ rules: () => {
1163
+ const settingsDoc = readRulesDocument();
1164
+ return (settingsDoc !== undefined
1165
+ ? readRulesViewFromSettings(settingsDoc)
1166
+ : readRulesView(rulesFilePath));
1167
+ },
1168
+ evaluate: (command) => runDryRun({ tool: 'bash', args: { command } }, runtime),
1169
+ // 审计环:宿主把每次判定/审批写进 MemoryAuditMirror,这里只读最后 N 条。
1170
+ history: (limit) => (runtime.auditEntries ?? []).slice(-limit).reverse().map((entry) => ({
1171
+ at: entry.at,
1172
+ tool: entry.tool,
1173
+ decision: entry.outcome,
1174
+ reason: entry.reason,
1175
+ })),
1176
+ // 会话级授权:运行时新增的只读清单(工具/到期/剩余次数)。
1177
+ grants: () => runtime.listGrants(),
1178
+ });
1179
+ });
1155
1180
  return runtime;
1156
1181
  }
package/lib/runtime.d.ts CHANGED
@@ -356,6 +356,12 @@ export declare class PermGateRuntime {
356
356
  private readonly options;
357
357
  private ruleset;
358
358
  private readonly grants;
359
+ /** 只读授权清单(TUI `/gate grants`):工具名 / 到期时间 / 剩余次数。 */
360
+ listGrants(): Array<{
361
+ tool: string;
362
+ expiresAt: number;
363
+ remaining: number;
364
+ }>;
359
365
  private readonly artifacts;
360
366
  private readonly audit;
361
367
  private readonly cache;
package/lib/runtime.js CHANGED
@@ -218,6 +218,10 @@ export class PermGateRuntime {
218
218
  options;
219
219
  ruleset;
220
220
  grants;
221
+ /** 只读授权清单(TUI `/gate grants`):工具名 / 到期时间 / 剩余次数。 */
222
+ listGrants() {
223
+ return this.grants.list();
224
+ }
221
225
  artifacts = new ArtifactRegistry();
222
226
  audit = new MemoryAuditMirror();
223
227
  cache = new Map(); // hash -> compiled
@@ -0,0 +1,64 @@
1
+ /**
2
+ * tui-command.ts — `/gate`:权限门(perm-gate)的 dsh-tui 终端面。
3
+ *
4
+ * 背景:dsh-tui 不加载 client 半边(history 卡片 / 规则页不执行),工具审批只显示
5
+ * `toolName` 一行。于是「这条命令为什么被拦 / 规则文件长什么样」在终端里无从查证。
6
+ * 命令面只读 + 干跑:
7
+ * status = 规则文件路径/默认动作
8
+ * rules = allow/deny/ask 计数
9
+ * why = 对一条命令跑 dry-run,输出判定链(不执行命令)
10
+ *
11
+ * 契约(.agents/plans/dsh-tui-faces/spec.md §3):单行 <=100、总行 <=40、无 ANSI、--json 单行。
12
+ */
13
+ import type { Context } from '@deepseek-ai/cordis';
14
+ export type CommandKind = 'success' | 'error';
15
+ export interface CommandResult {
16
+ kind: CommandKind;
17
+ text: string;
18
+ }
19
+ export interface GateRulesView {
20
+ path: string;
21
+ exists: boolean;
22
+ bytes: number;
23
+ lines: number;
24
+ truncated: boolean;
25
+ defaultAction?: string;
26
+ counts: {
27
+ allow: number;
28
+ deny: number;
29
+ ask: number;
30
+ };
31
+ }
32
+ export interface GateVerdict {
33
+ decision?: string;
34
+ reason?: string;
35
+ layers?: Array<{
36
+ name?: string;
37
+ decision?: string;
38
+ reason?: string;
39
+ }>;
40
+ [key: string]: unknown;
41
+ }
42
+ export interface GateCommandDeps {
43
+ rules(): GateRulesView;
44
+ evaluate(command: string): GateVerdict;
45
+ /** 最近的审计环条目(只读;宿主把审批/判定写进 MemoryAuditMirror)。 */
46
+ history(limit: number): Array<{
47
+ at?: number;
48
+ tool?: string;
49
+ decision?: string;
50
+ reason?: string;
51
+ }>;
52
+ /** 会话级授权清单(只读)。 */
53
+ grants(): Array<{
54
+ tool: string;
55
+ expiresAt: number;
56
+ remaining: number;
57
+ }>;
58
+ }
59
+ export declare function clip(text: string, width?: number): string;
60
+ export declare function renderLines(lines: string[], limit?: number): string;
61
+ /** 纯函数入口。 */
62
+ export declare function runGateCommand(rawInput: string, deps: GateCommandDeps): CommandResult;
63
+ /** 注册 `/gate`:无 commands 服务时静默跳过(老线安全)。 */
64
+ export declare function registerGateCommand(ctx: Context, deps: GateCommandDeps): void;
@@ -0,0 +1,137 @@
1
+ /**
2
+ * tui-command.ts — `/gate`:权限门(perm-gate)的 dsh-tui 终端面。
3
+ *
4
+ * 背景:dsh-tui 不加载 client 半边(history 卡片 / 规则页不执行),工具审批只显示
5
+ * `toolName` 一行。于是「这条命令为什么被拦 / 规则文件长什么样」在终端里无从查证。
6
+ * 命令面只读 + 干跑:
7
+ * status = 规则文件路径/默认动作
8
+ * rules = allow/deny/ask 计数
9
+ * why = 对一条命令跑 dry-run,输出判定链(不执行命令)
10
+ *
11
+ * 契约(.agents/plans/dsh-tui-faces/spec.md §3):单行 <=100、总行 <=40、无 ANSI、--json 单行。
12
+ */
13
+ const MAX_LINES = 40;
14
+ const MAX_WIDTH = 100;
15
+ export function clip(text, width = MAX_WIDTH) {
16
+ const value = String(text ?? '').replace(/[\r\n]+/g, ' ').replace(/\s+$/, '');
17
+ return value.length <= width ? value : `${value.slice(0, width - 1)}…`;
18
+ }
19
+ export function renderLines(lines, limit = MAX_LINES) {
20
+ const clipped = lines.map((line) => clip(line));
21
+ if (clipped.length <= limit)
22
+ return clipped.join('\n');
23
+ const kept = clipped.slice(0, limit - 1);
24
+ return [...kept, `… 还有 ${clipped.length - kept.length} 行,加 --all 查看`].join('\n');
25
+ }
26
+ const ok = (lines) => ({ kind: 'success', text: renderLines(lines) });
27
+ const fail = (reason, next) => ({ kind: 'error', text: renderLines([reason, ...(next ? [` ${next}`] : [])]) });
28
+ function parse(rawInput) {
29
+ const argv = [];
30
+ let json = false;
31
+ let limit = 10;
32
+ for (const token of String(rawInput ?? '').trim().split(/\s+/).filter(Boolean)) {
33
+ if (token === '--json')
34
+ json = true;
35
+ else if (/^--n=\d+$/.test(token))
36
+ limit = Math.min(40, Math.max(1, Number(token.slice(4))));
37
+ else if (!token.startsWith('--'))
38
+ argv.push(token);
39
+ }
40
+ return { argv, json, limit };
41
+ }
42
+ const HELP = [
43
+ 'gate — 权限门的只读终端面(判定链 / 规则计数 / 审计环)',
44
+ ' /gate 规则文件路径与默认动作',
45
+ ' /gate rules allow / deny / ask 计数',
46
+ ' /gate why <command> 对一条命令干跑判定链(不执行)',
47
+ ' /gate history 最近 10 条判定/审批(--n=20)',
48
+ ' /gate grants 当前会话级授权(工具/到期/剩余次数)',
49
+ ' flags --json 单行 JSON',
50
+ ];
51
+ /** 纯函数入口。 */
52
+ export function runGateCommand(rawInput, deps) {
53
+ const { argv, json, limit } = parse(rawInput);
54
+ const sub = (argv[0] ?? 'status').toLowerCase();
55
+ const wrap = (result, data) => {
56
+ if (!json)
57
+ return result;
58
+ const body = result.kind === 'error'
59
+ ? { ok: false, cmd: 'gate', error: { message: result.text.split('\n')[0] ?? result.text } }
60
+ : { ok: true, cmd: 'gate', data };
61
+ return { kind: result.kind, text: JSON.stringify(body) };
62
+ };
63
+ if (sub === 'help' || sub === '?')
64
+ return wrap(ok(HELP), { help: true });
65
+ if (sub === 'status' || sub === 'rules') {
66
+ const view = deps.rules();
67
+ const lines = sub === 'status'
68
+ ? [
69
+ `gate — 规则文件 ${view.exists ? '已加载' : '缺失'} 默认动作 ${view.defaultAction ?? '—'}`,
70
+ ` path ${view.path || '(未配置)'}`,
71
+ ` bytes ${view.bytes} lines ${view.lines}${view.truncated ? ' (truncated)' : ''}`,
72
+ ` counts allow ${view.counts.allow} deny ${view.counts.deny} ask ${view.counts.ask}`,
73
+ ' use /gate why <command> 或 /gate rules',
74
+ ]
75
+ : [
76
+ `gate rules — allow ${view.counts.allow} deny ${view.counts.deny} ask ${view.counts.ask}`,
77
+ ` path ${view.path || '(未配置)'}`,
78
+ ` default ${view.defaultAction ?? '—'}`,
79
+ ];
80
+ return wrap(ok(lines), view);
81
+ }
82
+ if (sub === 'why') {
83
+ const command = argv.slice(1).join(' ').trim();
84
+ if (command === '')
85
+ return wrap(fail('gate why: 缺少命令', 'next: /gate why "<command>"'), {});
86
+ const verdict = deps.evaluate(command);
87
+ const decision = String(verdict.decision ?? verdict.reason ?? 'unknown');
88
+ const lines = [`gate why — ${decision}`];
89
+ if (verdict.reason)
90
+ lines.push(` reason ${clip(String(verdict.reason), 80)}`);
91
+ for (const layer of (verdict.layers ?? []).slice(0, 8)) {
92
+ lines.push(` ${clip(String(layer.name ?? 'layer'), 14).padEnd(14)} ${clip(String(layer.decision ?? '—'), 12)} ${clip(String(layer.reason ?? ''), 50)}`);
93
+ }
94
+ if ((verdict.layers ?? []).length === 0)
95
+ lines.push(' layers (干跑未返回分层,只给最终判定)');
96
+ lines.push(` cmd ${clip(command, 80)}`);
97
+ return wrap(ok(lines), verdict);
98
+ }
99
+ if (sub === 'history') {
100
+ const rows = deps.history(limit);
101
+ if (rows.length === 0)
102
+ return wrap(ok(['gate history — 审计环为空(本会话还没有判定记录)']), { rows: 0 });
103
+ const lines = [`gate history — 最近 ${rows.length} 条`];
104
+ for (const row of rows) {
105
+ const stamp = typeof row.at === 'number' ? new Date(row.at).toISOString().replace('T', ' ').slice(0, 16) : '—';
106
+ lines.push(` ${stamp} ${clip(row.decision ?? '—', 10).padEnd(10)} ${clip(row.tool ?? '', 18).padEnd(18)} ${clip(row.reason ?? '', 30)}`);
107
+ }
108
+ return wrap(ok(lines), { rows });
109
+ }
110
+ if (sub === 'grants') {
111
+ const rows = deps.grants();
112
+ if (rows.length === 0)
113
+ return wrap(ok(['gate grants — 当前没有会话级授权']), { rows: 0 });
114
+ const lines = [`gate grants — ${rows.length} 条活跃授权`];
115
+ for (const row of rows.slice(0, limit)) {
116
+ const stamp = new Date(row.expiresAt).toISOString().replace('T', ' ').slice(0, 16);
117
+ lines.push(` ${clip(row.tool, 24).padEnd(24)} until ${stamp} left ${row.remaining}`);
118
+ }
119
+ if (rows.length > limit)
120
+ lines.push(` … 还有 ${rows.length - limit} 条,加 --n=40`);
121
+ return wrap(ok(lines), { rows });
122
+ }
123
+ return wrap(fail(`gate: 未知子命令 "${sub}"`, 'next: /gate help'), {});
124
+ }
125
+ /** 注册 `/gate`:无 commands 服务时静默跳过(老线安全)。 */
126
+ export function registerGateCommand(ctx, deps) {
127
+ const registry = ctx.commands;
128
+ if (!registry || typeof registry.register !== 'function')
129
+ return;
130
+ registry.register({
131
+ definitionId: 'dsh-perm-gate',
132
+ name: 'gate',
133
+ description: 'Permission gate console: rules counts / dry-run why <command> (never executes)',
134
+ input: { hint: '[status|rules|why <command>|history|grants] [--n=20] [--json]' },
135
+ handler: (invocation) => runGateCommand(invocation?.rawInput ?? '', deps),
136
+ });
137
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-perm-gate",
3
- "version": "5.5.2",
3
+ "version": "5.5.4",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "tag": "latest"
@@ -69,15 +69,15 @@
69
69
  },
70
70
  "engines": {
71
71
  "node": ">=24",
72
- "dsh": ">=0.1.1-rc.2 <0.3.0"
72
+ "dsh": ">=0.1.0-rc.2 <0.3.0-0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "@deepseek-ai/cordis": "^4.0.1",
76
- "@deepseek-ai/dsh-client-locale": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1",
77
- "@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1",
78
- "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1",
79
- "@deepseek-ai/dsh-settings": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1",
80
- "@deepseek-ai/dsh-client-ui-conversation": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5 || 0.2.2-rc.1"
76
+ "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.2 <0.3.0-0",
77
+ "@deepseek-ai/dsh-client-ui-renderer": ">=0.1.0-rc.2 <0.3.0-0",
78
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.1.0-rc.2 <0.3.0-0",
79
+ "@deepseek-ai/dsh-settings": ">=0.1.0-rc.2 <0.3.0-0",
80
+ "@deepseek-ai/dsh-client-ui-conversation": ">=0.1.0-rc.2 <0.3.0-0"
81
81
  },
82
82
  "dependencies": {
83
83
  "@deepseek-ai/schemastery": "^3.18.4",