dsh-perm-gate 5.5.3 → 5.5.5
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 +5 -0
- package/CHANGELOG.pt.md +313 -0
- package/INSTALL.ja.md +3 -1
- package/INSTALL.ko.md +3 -1
- package/INSTALL.md +3 -1
- package/INSTALL.pt.md +227 -0
- package/INSTALL.zh.md +3 -1
- package/README.ja.md +5 -2
- package/README.ko.md +5 -2
- package/README.md +19 -3
- package/README.pt.md +669 -0
- package/README.zh.md +5 -2
- package/dsh.plugin.json +3 -2
- package/lib/client.js +210 -3
- package/lib/client.js.map +1 -1
- package/lib/grant.d.ts +11 -0
- package/lib/grant.js +13 -0
- package/lib/index.js +25 -0
- package/lib/runtime.d.ts +6 -0
- package/lib/runtime.js +4 -0
- package/lib/tui-command.d.ts +64 -0
- package/lib/tui-command.js +137 -0
- package/locale/pt.json +1 -0
- package/package.json +4 -1
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/locale/pt.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"Portal de permissões","description":"Portal de permissões determinístico e de fechamento seguro para o DeepSeek Harness: P0 negação dura → P1 concessão de sessão → P2 cadeia de regras estáticas → P3 classificador LLM opcional → P4 confirmação, com lista de permissões e lista de bloqueio de comandos."}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-perm-gate",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org",
|
|
6
6
|
"tag": "latest"
|
|
@@ -20,13 +20,16 @@
|
|
|
20
20
|
"README.zh.md",
|
|
21
21
|
"README.ja.md",
|
|
22
22
|
"README.ko.md",
|
|
23
|
+
"README.pt.md",
|
|
23
24
|
"INSTALL.md",
|
|
24
25
|
"INSTALL.zh.md",
|
|
25
26
|
"INSTALL.ja.md",
|
|
26
27
|
"INSTALL.ko.md",
|
|
28
|
+
"INSTALL.pt.md",
|
|
27
29
|
"CHANGELOG.md",
|
|
28
30
|
"CHANGELOG.ja.md",
|
|
29
31
|
"CHANGELOG.ko.md",
|
|
32
|
+
"CHANGELOG.pt.md",
|
|
30
33
|
"THIRD_PARTY_NOTICES.md",
|
|
31
34
|
"LICENSE"
|
|
32
35
|
],
|