dsh-dlp 0.6.0 → 0.7.0

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/README.md CHANGED
@@ -26,7 +26,9 @@ built as an out-of-repo plugin.
26
26
  credential.
27
27
  7. **Asks before a call switches off its own confirmation** — `non_interactive: true`,
28
28
  `approval_mode: auto`, an `apply` whose approval is still pending. Both `ask` tiers are
29
- prompts rather than controls: they live at `tools/pre-execute` and can be neutralised.
29
+ prompts rather than controls: they live at `tools/pre-execute`, they can be neutralised, and
30
+ they abstain wherever the approval seam prompts nobody — which includes every install under
31
+ `DSH_PERMISSION_MODE=danger-full-access` and a stock headless install under any mode.
30
32
  8. **Writes an audit record for every decision.** A redaction or denial names the rule, its
31
33
  version, the offsets and a keyed hash; the three kinds with no matched region to describe —
32
34
  an ask, a rewritten call, a neutralised image — carry a rule id, the changed field names or
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Whether an `ask` this plugin returns can still reach a human.
3
+ *
4
+ * The `ask` tier is documented as a prompt and never a block: its rules have a
5
+ * real false-positive rate, so a developer who is asked about `CLAUDE.md` or
6
+ * `.github/workflows/**` says yes and carries on. The tool registry resolves an
7
+ * `ask` through `ctx.get('approval')`, and three states of that seam turn the
8
+ * prompt into a denial nobody ever saw:
9
+ *
10
+ * 1. **No service composed.** `ToolRegistry.serviceAsk` keeps the historical
11
+ * degrade to `deny` when `ctx.get('approval')` is `undefined`.
12
+ * 2. **The policy in force is `'never'`.** `ApprovalService.decide` resolves
13
+ * `'rejected'` before any dispatch — its own JSDoc calls this "never prompt
14
+ * anyone". The shipped `dsh-base` bundle selects it for every install under
15
+ * `DSH_PERMISSION_MODE=danger-full-access`, which is the unattended posture.
16
+ * 3. **Nothing composed on `approval/request`.** The waterfall falls through to
17
+ * the fail-closed `'unavailable'`, which the registry maps to `deny`. The
18
+ * shipped `dsh-headless` bundle composes no answerer, so this is the state
19
+ * of a stock headless install under every other permission mode.
20
+ *
21
+ * In all three the call is stopped with no human involved, which is exactly
22
+ * what this tier was designed not to do. Each is decided here so the caller can
23
+ * abstain instead — the same thing it already did for (1) alone.
24
+ *
25
+ * **Every check reports "reachable" when it cannot tell.** Abstaining removes a
26
+ * prompt, so an unreadable service, a missing session, or a `ctx.get` that
27
+ * returned something other than the service read here all keep the ask. Only a
28
+ * positive reading of one of the three states above abstains.
29
+ * @module dsh-dlp/approval-reach
30
+ */
31
+ /** The event `ApprovalService.decide` dispatches its answerer waterfall on. */
32
+ const APPROVAL_REQUEST = 'approval/request';
33
+ /**
34
+ * Whether every ask for this session resolves without prompting anyone.
35
+ *
36
+ * `'never'` is the only policy whose outcome is knowable without asking, and
37
+ * the service decides it before dispatch, so no composed answerer can change
38
+ * it. Anything else — including a value this build does not recognise — leaves
39
+ * the answerers to decide and is therefore not a positive reading.
40
+ * @param approval - whatever `ctx.get('approval')` returned.
41
+ * @param session - the calling agent's session, or `undefined` when the call has no agent.
42
+ * @returns `true` only when the policy in force was read and is `'never'`.
43
+ */
44
+ function policyIsNever(approval, session) {
45
+ // Without a session there is no override to fold, and the configured default
46
+ // alone cannot tell a session that never switched from one that switched to
47
+ // 'ask' — so an agent-less call keeps its prompt.
48
+ if (session === undefined)
49
+ return false;
50
+ const service = approval;
51
+ let policy;
52
+ try {
53
+ policy = service.overrideOf === undefined ? undefined : service.overrideOf(session) ?? service.config?.policy;
54
+ }
55
+ catch {
56
+ // Only a service without the members ApprovalSurface describes reaches
57
+ // here. It answers nothing about whether a human can be asked, and
58
+ // this runs inside a live tool call: a diagnostic read must not fail it.
59
+ return false;
60
+ }
61
+ return policy === 'never';
62
+ }
63
+ /**
64
+ * How many listeners are composed on the answerer waterfall.
65
+ *
66
+ * The count is read across the whole context tree, before the scope filter
67
+ * `ApprovalService.decide` applies. That over-counts — an agent-scoped answerer
68
+ * belonging to a different agent is included — and over-counting is the safe
69
+ * direction here, because only a count of zero abstains and zero listeners
70
+ * cannot be filtered into some.
71
+ *
72
+ * `EventsService._hooks` is a declared public field of the exported class, so a
73
+ * Cordis that stops carrying it fails `typecheck` and `build` in this package
74
+ * rather than being misread at a user's install; `@deepseek-ai/cordis` is
75
+ * pinned to one exact version (ADR §19) for the same reason.
76
+ * @param ctx - the plugin's context; every context in one tree shares the bus.
77
+ * @returns the number of composed answerers.
78
+ */
79
+ function composedAnswerers(ctx) {
80
+ return ctx.events._hooks[APPROVAL_REQUEST]?.length ?? 0;
81
+ }
82
+ /**
83
+ * Decide whether an ask would reach a human, at the moment of the decision.
84
+ *
85
+ * Evaluated per call rather than at mount: a session switches policy mid-run
86
+ * through `approval/policy`, the override is per session, and an answerer can
87
+ * be composed or disposed while the harness runs. A mount-time answer would be
88
+ * a cached guess at all three.
89
+ * @param ctx - the plugin's context, for the service and the event bus.
90
+ * @param session - the calling agent's session, or `undefined` when the call has no agent.
91
+ * @returns whether to ask, or which state stopped the ask from reaching anyone.
92
+ */
93
+ export function askReach(ctx, session) {
94
+ const approval = ctx.get('approval');
95
+ if (approval === undefined)
96
+ return { kind: 'unreachable', cause: 'no-service' };
97
+ // Policy first, matching the service's own order: it decides 'never' before
98
+ // dispatching, so that is the state an operator sees reported.
99
+ if (policyIsNever(approval, session))
100
+ return { kind: 'unreachable', cause: 'policy-never' };
101
+ if (composedAnswerers(ctx) === 0)
102
+ return { kind: 'unreachable', cause: 'no-answerer' };
103
+ return { kind: 'reachable' };
104
+ }
105
+ /** What abstaining does, said once and identically for all three states. */
106
+ const CONSEQUENCE = 'This tier abstains rather than becoming the silent hard deny it was designed not to be: a'
107
+ + ' write to a behaviour-changing config path, and a call that switches its own confirmation off, are allowed'
108
+ + ' through with no prompt, and each one is recorded in the audit sink as "pre-execute-ask-abstained". The'
109
+ + ' guard floor is unaffected. Set configWriteAsk: false and approvalSuppressionAsk: false to turn this tier'
110
+ + ' off entirely.';
111
+ /**
112
+ * What to tell the operator when the ask tier has nowhere to ask.
113
+ *
114
+ * Each line names the state, what to change to get the prompt back, and the
115
+ * consequence. Reported on `process.stderr` as well as `ctx.logger` for the
116
+ * reason ADR §7 records: the logger's default exporter is an in-memory ring
117
+ * buffer and no shipped bundle mounts a console exporter.
118
+ * @param cause - the state {@link askReach} read.
119
+ * @returns the whole line to report.
120
+ */
121
+ export function approvalSeamNotice(cause) {
122
+ const prefix = 'dsh-dlp: the ask tier (configWriteAsk, approvalSuppressionAsk) is enabled, but';
123
+ switch (cause) {
124
+ case 'no-service':
125
+ return `${prefix} no approval service is mounted, so the tool registry would resolve an ask as a denial`
126
+ + ' with nothing shown to anyone. Composing an approval service and an answerer puts the prompt back.'
127
+ + ` ${CONSEQUENCE}`;
128
+ case 'policy-never':
129
+ return `${prefix} the approval policy in force is "never", which resolves every ask as rejected without`
130
+ + ' prompting anyone. DSH_PERMISSION_MODE=danger-full-access selects that policy in the shipped dsh-base'
131
+ + ' bundle; run under another permission mode, or set the approval row\'s policy to "ask", for these'
132
+ + ` calls to be asked about. ${CONSEQUENCE}`;
133
+ case 'no-answerer':
134
+ return `${prefix} nothing is composed on the approval/request waterfall, which fails every ask closed as`
135
+ + ' unavailable and denies the call with nothing shown to anyone. The shipped dsh-headless bundle'
136
+ + ' composes no answerer; a surface that answers approvals, such as the Host API proxy or the ACP'
137
+ + ` bridge, puts the prompt back. ${CONSEQUENCE}`;
138
+ /* v8 ignore next 4 -- unreachable while `AskUnreachable` stays closed; the arm exists so adding a variant fails the build. */
139
+ default: {
140
+ const unhandled = cause;
141
+ throw new TypeError(`dsh-dlp: unhandled ask-tier state ${JSON.stringify(unhandled)}`);
142
+ }
143
+ }
144
+ }
package/lib/index.js CHANGED
@@ -13,7 +13,7 @@
13
13
  * config paths and for calls carrying an argument that switches their own
14
14
  * confirmation off. Deliberately here rather than on the floor: its rules
15
15
  * have a real false-positive rate and the floor cannot ask. Neutralizable,
16
- * and it abstains entirely when no approval service is mounted.
16
+ * and it abstains entirely wherever the approval seam cannot prompt anyone.
17
17
  * 3. `tools/post-execute` — result redaction, applied before the `tool/result`
18
18
  * session event is appended, so the durable log records the redacted copy;
19
19
  * a result that cannot be cleaned is withheld rather than accepted.
@@ -43,6 +43,7 @@ import { neutralizeImageStream } from "./images.js";
43
43
  import { ExecutionSnapshots, mutationReason } from "./mutation.js";
44
44
  import { evaluateConfigWrite } from "./config-writes.js";
45
45
  import { evaluateApprovalSuppression } from "./approvals.js";
46
+ import { approvalSeamNotice, askReach } from "./approval-reach.js";
46
47
  import { breadthTierDenial, evaluateBreadthTier, redactDecision } from "./results.js";
47
48
  import { redactRecord, telemetrySeamNotice } from "./telemetry.js";
48
49
  import { AuditSink, CallCorrelator, newDecisionId, RECORD_VERSION } from "./sink.js";
@@ -238,25 +239,20 @@ export function apply(ctx, config) {
238
239
  return verdict.reason;
239
240
  }), 'dsh-dlp guard floor');
240
241
  /**
241
- * Report once that the `ask` tier has nowhere to ask.
242
+ * Report once per state that the `ask` tier has nowhere to ask.
242
243
  *
243
- * The registry resolves an `ask` through `ctx.get('approval')` and keeps the
244
- * historical degrade to *deny* when no service is composed. This tier exists
245
- * because its rules are too false-positive-prone for a deny, so under a
246
- * deployment with no approval channel it abstains instead of becoming the
247
- * silent hard deny it was designed not to be. Evaluated at decision time
248
- * rather than at mount, because by then the harness is running and an absent
249
- * service is conclusive rather than a load order.
244
+ * Latched per state rather than once overall: the three states have
245
+ * different fixes, a session can move between them mid-run by switching its
246
+ * approval policy, and a single latch would leave the first one reported
247
+ * standing for a different one afterwards. `approval-reach.ts` records why
248
+ * each is a state in which an ask reaches nobody.
250
249
  */
251
- let approvalSeamReported = false;
252
- const discloseApprovalSeam = () => {
253
- if (approvalSeamReported)
250
+ const approvalSeamReported = new Set();
251
+ const discloseApprovalSeam = (cause) => {
252
+ if (approvalSeamReported.has(cause))
254
253
  return;
255
- approvalSeamReported = true;
256
- notice(ctx, 'dsh-dlp: the ask tier (configWriteAsk, approvalSuppressionAsk) is enabled, but no approval service'
257
- + ' is mounted, so an ask would degrade to a denial. This tier abstains instead: a write to a'
258
- + ' behaviour-changing config path, and a call that switches its own confirmation off, are allowed through'
259
- + ' with no prompt. The guard floor is unaffected.');
254
+ approvalSeamReported.add(cause);
255
+ notice(ctx, approvalSeamNotice(cause));
260
256
  };
261
257
  if (policy.configWriteAsk || policy.approvalSuppressionAsk) {
262
258
  // Registered ahead of the breadth tier, so a call that is both a config
@@ -280,8 +276,25 @@ export function apply(ctx, config) {
280
276
  // and would file the decision as an ask rather than as a guard denial.
281
277
  if (safeEvaluateGuard(exec, policy, hasher) !== undefined)
282
278
  return decision;
283
- if (ctx.get('approval') === undefined) {
284
- discloseApprovalSeam();
279
+ // Asked at decision time, never at mount: the session's policy is a fold
280
+ // over its own log and can change mid-run, and an answerer can be
281
+ // composed or disposed while the harness runs.
282
+ const reach = askReach(ctx, exec.agent?.session);
283
+ if (reach.kind === 'unreachable') {
284
+ discloseApprovalSeam(reach.cause);
285
+ // An abstention allowed a call this tier would have asked about, so it
286
+ // is recorded rather than left silent. Its own kind, not a flag on
287
+ // `pre-execute-ask`: `dsh-dlp report` counts by kind, and an ask that
288
+ // reached nobody must not be counted as a prompt that happened.
289
+ sink.write({
290
+ v: RECORD_VERSION,
291
+ time: new Date().toISOString(),
292
+ kind: 'pre-execute-ask-abstained',
293
+ decisionId: newDecisionId(),
294
+ ...identity(exec),
295
+ ruleId: finding.rule.id,
296
+ askUnreachable: reach.cause,
297
+ });
285
298
  return decision;
286
299
  }
287
300
  sink.write({
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Whether an `ask` this plugin returns can still reach a human.
3
+ *
4
+ * The `ask` tier is documented as a prompt and never a block: its rules have a
5
+ * real false-positive rate, so a developer who is asked about `CLAUDE.md` or
6
+ * `.github/workflows/**` says yes and carries on. The tool registry resolves an
7
+ * `ask` through `ctx.get('approval')`, and three states of that seam turn the
8
+ * prompt into a denial nobody ever saw:
9
+ *
10
+ * 1. **No service composed.** `ToolRegistry.serviceAsk` keeps the historical
11
+ * degrade to `deny` when `ctx.get('approval')` is `undefined`.
12
+ * 2. **The policy in force is `'never'`.** `ApprovalService.decide` resolves
13
+ * `'rejected'` before any dispatch — its own JSDoc calls this "never prompt
14
+ * anyone". The shipped `dsh-base` bundle selects it for every install under
15
+ * `DSH_PERMISSION_MODE=danger-full-access`, which is the unattended posture.
16
+ * 3. **Nothing composed on `approval/request`.** The waterfall falls through to
17
+ * the fail-closed `'unavailable'`, which the registry maps to `deny`. The
18
+ * shipped `dsh-headless` bundle composes no answerer, so this is the state
19
+ * of a stock headless install under every other permission mode.
20
+ *
21
+ * In all three the call is stopped with no human involved, which is exactly
22
+ * what this tier was designed not to do. Each is decided here so the caller can
23
+ * abstain instead — the same thing it already did for (1) alone.
24
+ *
25
+ * **Every check reports "reachable" when it cannot tell.** Abstaining removes a
26
+ * prompt, so an unreadable service, a missing session, or a `ctx.get` that
27
+ * returned something other than the service read here all keep the ask. Only a
28
+ * positive reading of one of the three states above abstains.
29
+ * @module dsh-dlp/approval-reach
30
+ */
31
+ import type { Context } from '@deepseek-ai/cordis';
32
+ import type { Session } from '@deepseek-ai/dsh-session';
33
+ /** Which of the three states stopped an ask from reaching a human. */
34
+ export type AskUnreachable =
35
+ /** Nothing is composed on `ctx.approval`. */
36
+ 'no-service'
37
+ /** The policy in force for this session is `'never'`. */
38
+ | 'policy-never'
39
+ /** Nothing is composed on the `approval/request` waterfall. */
40
+ | 'no-answerer';
41
+ /** Whether an ask can reach a human, and when it cannot, which state stopped it. */
42
+ export type AskReach = {
43
+ readonly kind: 'reachable';
44
+ } | {
45
+ readonly kind: 'unreachable';
46
+ readonly cause: AskUnreachable;
47
+ };
48
+ /**
49
+ * Decide whether an ask would reach a human, at the moment of the decision.
50
+ *
51
+ * Evaluated per call rather than at mount: a session switches policy mid-run
52
+ * through `approval/policy`, the override is per session, and an answerer can
53
+ * be composed or disposed while the harness runs. A mount-time answer would be
54
+ * a cached guess at all three.
55
+ * @param ctx - the plugin's context, for the service and the event bus.
56
+ * @param session - the calling agent's session, or `undefined` when the call has no agent.
57
+ * @returns whether to ask, or which state stopped the ask from reaching anyone.
58
+ */
59
+ export declare function askReach(ctx: Context, session: Session | undefined): AskReach;
60
+ /**
61
+ * What to tell the operator when the ask tier has nowhere to ask.
62
+ *
63
+ * Each line names the state, what to change to get the prompt back, and the
64
+ * consequence. Reported on `process.stderr` as well as `ctx.logger` for the
65
+ * reason ADR §7 records: the logger's default exporter is an in-memory ring
66
+ * buffer and no shipped bundle mounts a console exporter.
67
+ * @param cause - the state {@link askReach} read.
68
+ * @returns the whole line to report.
69
+ */
70
+ export declare function approvalSeamNotice(cause: AskUnreachable): string;
71
+ //# sourceMappingURL=approval-reach.d.ts.map
@@ -13,7 +13,7 @@
13
13
  * config paths and for calls carrying an argument that switches their own
14
14
  * confirmation off. Deliberately here rather than on the floor: its rules
15
15
  * have a real false-positive rate and the floor cannot ask. Neutralizable,
16
- * and it abstains entirely when no approval service is mounted.
16
+ * and it abstains entirely wherever the approval seam cannot prompt anyone.
17
17
  * 3. `tools/post-execute` — result redaction, applied before the `tool/result`
18
18
  * session event is appended, so the durable log records the redacted copy;
19
19
  * a result that cannot be cleaned is withheld rather than accepted.
@@ -14,6 +14,7 @@
14
14
  * `callId`, and a producer-minted `decisionId`.
15
15
  * @module dsh-dlp/sink
16
16
  */
17
+ import type { AskUnreachable } from './approval-reach.ts';
17
18
  import type { RedactedSpan } from './redaction.ts';
18
19
  declare const decisionIdBrand: unique symbol;
19
20
  /** Producer-minted id correlating one decision across records. */
@@ -28,7 +29,7 @@ export declare function newDecisionId(): DecisionId;
28
29
  /** Payload version carried inside every record this plugin writes. */
29
30
  export declare const RECORD_VERSION = 1;
30
31
  /** What produced one audit record. */
31
- export type AuditKind = 'guard-deny' | 'pre-execute-deny' | 'pre-execute-ask' | 'execution-mutation' | 'result-redaction' | 'telemetry-redaction' | 'assistant-image-neutralized' | 'audit-failure';
32
+ export type AuditKind = 'guard-deny' | 'pre-execute-deny' | 'pre-execute-ask' | 'pre-execute-ask-abstained' | 'execution-mutation' | 'result-redaction' | 'telemetry-redaction' | 'assistant-image-neutralized' | 'audit-failure';
32
33
  /** One durable record. Never carries matched secret text. */
33
34
  export interface AuditRecord {
34
35
  readonly v: number;
@@ -66,6 +67,13 @@ export interface AuditRecord {
66
67
  * behaviour-changing file, not that any part of it matched a secret.
67
68
  */
68
69
  readonly ruleId?: string;
70
+ /**
71
+ * Which state left the ask tier with nowhere to ask, for a
72
+ * `pre-execute-ask-abstained`. An abstention allowed a call the tier would
73
+ * otherwise have asked about, so the state that caused it is the field an
74
+ * operator needs to change to get the prompt back.
75
+ */
76
+ readonly askUnreachable?: AskUnreachable;
69
77
  /** Telemetry record channel, for `telemetry-redaction`. */
70
78
  readonly channel?: string;
71
79
  /** Fields another plugin rewrote after the call was logged, for `execution-mutation`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dlp",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Data-loss-prevention plugin for DeepSeek Harness: a non-configurable tool guard floor, tool-result redaction, and fail-closed telemetry redaction",
5
5
  "license": "MIT",
6
6
  "author": "Ivan Tyshchenko <nsof@protonmail.com>",