@yadsh/dsh-prompt-firewall 0.2.1 → 0.2.2
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/compatibility.json +3 -9
- package/lib/audit.js +20 -18
- package/lib/audit.js.map +1 -1
- package/lib/client/index.js +23 -17
- package/lib/client/index.js.map +1 -1
- package/lib/client/sections.js +115 -34
- package/lib/client/sections.js.map +1 -1
- package/lib/client/styles.js +1 -1
- package/lib/client/styles.js.map +1 -1
- package/lib/client.js +2 -2
- package/lib/client.js.map +1 -1
- package/lib/config.js +26 -20
- package/lib/config.js.map +1 -1
- package/lib/firewall.js +34 -27
- package/lib/firewall.js.map +1 -1
- package/lib/index.js +42 -38
- package/lib/index.js.map +1 -1
- package/lib/metrics.js +5 -5
- package/lib/metrics.js.map +1 -1
- package/lib/presets.js +9 -9
- package/lib/presets.js.map +1 -1
- package/lib/rules.js +36 -35
- package/lib/rules.js.map +1 -1
- package/lib/typert.host.js +9 -9
- package/lib/typert.remote-client.js +2 -2
- package/lib/types/audit.d.ts +1 -1
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/sections.d.ts +2 -2
- package/lib/types/config.d.ts +2 -2
- package/lib/types/firewall.d.ts +4 -4
- package/lib/types/index.d.ts +12 -12
- package/lib/types/metrics.d.ts +7 -7
- package/lib/types/presets.d.ts +1 -1
- package/lib/types/rules.d.ts +1 -1
- package/lib/types/types.d.ts +7 -7
- package/package.json +5 -3
package/lib/rules.js
CHANGED
|
@@ -4,30 +4,30 @@
|
|
|
4
4
|
* The remaining conservative namespaces are retained for compatible hosts.
|
|
5
5
|
*/
|
|
6
6
|
export const CORE_SECTION_PREFIXES = Object.freeze([
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
"harness:",
|
|
8
|
+
"deployment:",
|
|
9
|
+
"tool:",
|
|
10
|
+
"tools:",
|
|
11
|
+
"runtime:",
|
|
12
|
+
"system:",
|
|
13
13
|
]);
|
|
14
14
|
function escapeRegExp(value) {
|
|
15
|
-
return value.replace(/[|\\{}()[\]^$+?.]/g,
|
|
15
|
+
return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
16
16
|
}
|
|
17
17
|
export function globToRegExp(glob) {
|
|
18
|
-
let source =
|
|
18
|
+
let source = "";
|
|
19
19
|
for (const character of glob) {
|
|
20
|
-
if (character ===
|
|
21
|
-
source +=
|
|
22
|
-
else if (character ===
|
|
23
|
-
source +=
|
|
20
|
+
if (character === "*")
|
|
21
|
+
source += ".*";
|
|
22
|
+
else if (character === "?")
|
|
23
|
+
source += ".";
|
|
24
24
|
else
|
|
25
25
|
source += escapeRegExp(character);
|
|
26
26
|
}
|
|
27
|
-
return new RegExp(`^${source}$`,
|
|
27
|
+
return new RegExp(`^${source}$`, "u");
|
|
28
28
|
}
|
|
29
29
|
function compilePatterns(patterns) {
|
|
30
|
-
return Object.freeze(patterns.map(source => Object.freeze({
|
|
30
|
+
return Object.freeze(patterns.map((source) => Object.freeze({
|
|
31
31
|
source,
|
|
32
32
|
expression: globToRegExp(source),
|
|
33
33
|
})));
|
|
@@ -45,59 +45,60 @@ export function compileRules(config) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
function prefixMatch(name, prefixes) {
|
|
48
|
-
return prefixes.find(prefix => name.startsWith(prefix));
|
|
48
|
+
return prefixes.find((prefix) => name.startsWith(prefix));
|
|
49
49
|
}
|
|
50
50
|
function patternMatch(name, patterns) {
|
|
51
|
-
return patterns.find(pattern => pattern.expression.test(name))?.source;
|
|
51
|
+
return patterns.find((pattern) => pattern.expression.test(name))?.source;
|
|
52
52
|
}
|
|
53
53
|
export function evaluateSection(section, rules) {
|
|
54
54
|
const { name } = section;
|
|
55
|
-
if (typeof name !==
|
|
56
|
-
throw new TypeError(
|
|
55
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
56
|
+
throw new TypeError("prompt section name must be a non-empty string");
|
|
57
57
|
}
|
|
58
58
|
if (rules.protectedSections.has(name)) {
|
|
59
|
-
return { action:
|
|
59
|
+
return { action: "protect", reason: "exact-protect", rule: name };
|
|
60
60
|
}
|
|
61
61
|
if (rules.config.protectCoreSections) {
|
|
62
62
|
const corePrefix = prefixMatch(name, CORE_SECTION_PREFIXES);
|
|
63
63
|
if (corePrefix !== undefined) {
|
|
64
|
-
return { action:
|
|
64
|
+
return { action: "protect", reason: "core-protect", rule: corePrefix };
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
if (!rules.config.enabled || rules.config.mode ===
|
|
68
|
-
return { action:
|
|
67
|
+
if (!rules.config.enabled || rules.config.mode === "off") {
|
|
68
|
+
return { action: "allow", reason: "mode-off" };
|
|
69
69
|
}
|
|
70
|
-
if (rules.config.mode ===
|
|
71
|
-
return { action:
|
|
70
|
+
if (rules.config.mode === "audit") {
|
|
71
|
+
return { action: "allow", reason: "mode-audit" };
|
|
72
72
|
}
|
|
73
73
|
if (rules.allowedSections.has(name)) {
|
|
74
|
-
return { action:
|
|
74
|
+
return { action: "allow", reason: "exact-allow", rule: name };
|
|
75
75
|
}
|
|
76
76
|
if (rules.blockedSections.has(name)) {
|
|
77
|
-
return { action:
|
|
77
|
+
return { action: "block", reason: "exact-block", rule: name };
|
|
78
78
|
}
|
|
79
79
|
const allowedPrefix = prefixMatch(name, rules.allowedPrefixes);
|
|
80
80
|
if (allowedPrefix !== undefined) {
|
|
81
|
-
return { action:
|
|
81
|
+
return { action: "allow", reason: "prefix-allow", rule: allowedPrefix };
|
|
82
82
|
}
|
|
83
83
|
const blockedPrefix = prefixMatch(name, rules.blockedPrefixes);
|
|
84
84
|
if (blockedPrefix !== undefined) {
|
|
85
|
-
return { action:
|
|
85
|
+
return { action: "block", reason: "prefix-block", rule: blockedPrefix };
|
|
86
86
|
}
|
|
87
87
|
const allowedPattern = patternMatch(name, rules.allowedPatterns);
|
|
88
88
|
if (allowedPattern !== undefined) {
|
|
89
|
-
return { action:
|
|
89
|
+
return { action: "allow", reason: "pattern-allow", rule: allowedPattern };
|
|
90
90
|
}
|
|
91
91
|
const blockedPattern = patternMatch(name, rules.blockedPatterns);
|
|
92
92
|
if (blockedPattern !== undefined) {
|
|
93
|
-
return { action:
|
|
93
|
+
return { action: "block", reason: "pattern-block", rule: blockedPattern };
|
|
94
94
|
}
|
|
95
|
-
if (rules.config.mode ===
|
|
96
|
-
return { action:
|
|
95
|
+
if (rules.config.mode === "allowlist") {
|
|
96
|
+
return { action: "block", reason: "allowlist-default" };
|
|
97
97
|
}
|
|
98
|
-
if (rules.config.unknownPluginPolicy ===
|
|
99
|
-
|
|
98
|
+
if (rules.config.unknownPluginPolicy === "block" &&
|
|
99
|
+
name.startsWith("plugin:")) {
|
|
100
|
+
return { action: "block", reason: "unknown-plugin-policy" };
|
|
100
101
|
}
|
|
101
|
-
return { action:
|
|
102
|
+
return { action: "allow", reason: "blocklist-default" };
|
|
102
103
|
}
|
|
103
104
|
//# sourceMappingURL=rules.js.map
|
package/lib/rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IACjD,UAAU;IACV,aAAa;IACb,OAAO;IACP,QAAQ;IACR,UAAU;IACV,SAAS;CACD,CAAC,CAAC;AAkBZ,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE,CAAC;QAC7B,IAAI,SAAS,KAAK,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M,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IAC5E,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACtC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC1D,CAAC;IACD,IACE,KAAK,CAAC,MAAM,CAAC,mBAAmB,KAAK,OAAO;QAC5C,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAC1B,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;IAC9D,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;AAC1D,CAAC"}
|
package/lib/typert.host.js
CHANGED
|
@@ -90,7 +90,7 @@ export const TYPERT = {
|
|
|
90
90
|
typeSymbol: '@yadsh/dsh-prompt-firewall/types#PromptFirewallInspectorSnapshot',
|
|
91
91
|
schema: _yadsh_dsh_prompt_firewall_promptFirewall_inspect_result$schema,
|
|
92
92
|
},
|
|
93
|
-
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":
|
|
93
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":152,"column":3},
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
id: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy',
|
|
@@ -136,7 +136,7 @@ export const TYPERT = {
|
|
|
136
136
|
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:result',
|
|
137
137
|
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_result$schema,
|
|
138
138
|
},
|
|
139
|
-
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":
|
|
139
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":166,"column":9},
|
|
140
140
|
},
|
|
141
141
|
],
|
|
142
142
|
model: {
|
|
@@ -184,7 +184,7 @@ export const TYPERT = {
|
|
|
184
184
|
{
|
|
185
185
|
"kind": "method",
|
|
186
186
|
"name": "setSectionPolicy",
|
|
187
|
-
"signature": "setSectionPolicy(name: string, policy: SectionPolicy, expectedRevision?: number): Promise<void>"
|
|
187
|
+
"signature": "setSectionPolicy( name: string, policy: SectionPolicy, expectedRevision?: number, ): Promise<void>"
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
190
|
"kind": "method",
|
|
@@ -199,7 +199,7 @@ export const TYPERT = {
|
|
|
199
199
|
},
|
|
200
200
|
{
|
|
201
201
|
"name": "FirewallAction",
|
|
202
|
-
"declaration": "export type FirewallAction =
|
|
202
|
+
"declaration": "export type FirewallAction = \"allow\" | \"block\" | \"protect\";"
|
|
203
203
|
},
|
|
204
204
|
{
|
|
205
205
|
"name": "FirewallDecision",
|
|
@@ -207,11 +207,11 @@ export const TYPERT = {
|
|
|
207
207
|
},
|
|
208
208
|
{
|
|
209
209
|
"name": "FirewallMode",
|
|
210
|
-
"declaration": "export type FirewallMode =
|
|
210
|
+
"declaration": "export type FirewallMode = \"off\" | \"audit\" | \"blocklist\" | \"allowlist\";"
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
213
|
"name": "FirewallPreset",
|
|
214
|
-
"declaration": "export type FirewallPreset =
|
|
214
|
+
"declaration": "export type FirewallPreset = \"clean\" | \"strict\" | \"audit-only\";"
|
|
215
215
|
},
|
|
216
216
|
{
|
|
217
217
|
"name": "KnownSection",
|
|
@@ -235,7 +235,7 @@ export const TYPERT = {
|
|
|
235
235
|
},
|
|
236
236
|
{
|
|
237
237
|
"name": "PromptSectionAudit",
|
|
238
|
-
"declaration": "export interface PromptSectionAudit {\n name: string;\n decision:
|
|
238
|
+
"declaration": "export interface PromptSectionAudit {\n name: string;\n decision: \"allowed\" | \"blocked\" | \"protected\";\n reason: string;\n chars: number;\n estimatedTokens: number;\n preview?: string;\n suspicious?: boolean;\n isNew?: boolean;\n}"
|
|
239
239
|
},
|
|
240
240
|
{
|
|
241
241
|
"name": "ResolvedPromptFirewallConfig",
|
|
@@ -243,11 +243,11 @@ export const TYPERT = {
|
|
|
243
243
|
},
|
|
244
244
|
{
|
|
245
245
|
"name": "SectionPolicy",
|
|
246
|
-
"declaration": "export type SectionPolicy = FirewallAction |
|
|
246
|
+
"declaration": "export type SectionPolicy = FirewallAction | \"clear\";"
|
|
247
247
|
},
|
|
248
248
|
{
|
|
249
249
|
"name": "UnknownPluginPolicy",
|
|
250
|
-
"declaration": "export type UnknownPluginPolicy =
|
|
250
|
+
"declaration": "export type UnknownPluginPolicy = \"allow\" | \"block\";"
|
|
251
251
|
}
|
|
252
252
|
]
|
|
253
253
|
}
|
|
@@ -87,7 +87,7 @@ export const TYPERT_REMOTE = {
|
|
|
87
87
|
typeSymbol: '@yadsh/dsh-prompt-firewall/types#PromptFirewallInspectorSnapshot',
|
|
88
88
|
schema: _yadsh_dsh_prompt_firewall_promptFirewall_inspect_result$schema,
|
|
89
89
|
},
|
|
90
|
-
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":
|
|
90
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":152,"column":3},
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
93
|
id: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy',
|
|
@@ -133,7 +133,7 @@ export const TYPERT_REMOTE = {
|
|
|
133
133
|
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:result',
|
|
134
134
|
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_result$schema,
|
|
135
135
|
},
|
|
136
|
-
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":
|
|
136
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":166,"column":9},
|
|
137
137
|
},
|
|
138
138
|
],
|
|
139
139
|
}
|
package/lib/types/audit.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuditConfig, FirewallDecision, FirewallSection, KnownSection, PromptAuditResult, PromptSectionAudit } from
|
|
1
|
+
import type { AuditConfig, FirewallDecision, FirewallSection, KnownSection, PromptAuditResult, PromptSectionAudit } from "./types.js";
|
|
2
2
|
export declare function estimateTokens(chars: number): number;
|
|
3
3
|
export declare function looksLikeAnnouncement(text: string): boolean;
|
|
4
4
|
export declare function createSectionAudit(section: FirewallSection, decision: FirewallDecision, config: Readonly<AuditConfig>): PromptSectionAudit;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
export declare const inject: string[];
|
|
3
3
|
/** Mount the generated Remote contribution and register the native Settings card. */
|
|
4
4
|
export declare function apply(ctx: Context): Promise<() => Promise<void>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PromptFirewallConfig, PromptFirewallInspectorSnapshot, SectionPolicy } from
|
|
2
|
-
export type RuleField =
|
|
1
|
+
import type { PromptFirewallConfig, PromptFirewallInspectorSnapshot, SectionPolicy } from "../types.js";
|
|
2
|
+
export type RuleField = "allowedSections" | "blockedSections" | "protectedSections" | "allowedPrefixes" | "blockedPrefixes" | "allowedPatterns" | "blockedPatterns";
|
|
3
3
|
export declare function Toggle(props: {
|
|
4
4
|
checked: boolean;
|
|
5
5
|
disabled: boolean;
|
package/lib/types/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import z from
|
|
2
|
-
import type { AuditConfig, MetricsConfig, PromptFirewallConfig, ResolvedPromptFirewallConfig } from
|
|
1
|
+
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
import type { AuditConfig, MetricsConfig, PromptFirewallConfig, ResolvedPromptFirewallConfig } from "./types.js";
|
|
3
3
|
export declare const DEFAULT_AUDIT_CONFIG: Readonly<AuditConfig>;
|
|
4
4
|
export declare const DEFAULT_METRICS_CONFIG: Readonly<MetricsConfig>;
|
|
5
5
|
export declare const DEFAULT_CONFIG: ResolvedPromptFirewallConfig;
|
package/lib/types/firewall.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PromptAssembly } from
|
|
2
|
-
import { AuditStore } from
|
|
3
|
-
import type { FirewallMetrics } from
|
|
4
|
-
import type { FirewallDecision, FirewallLogger, FirewallSection, ResolvedPromptFirewallConfig } from
|
|
1
|
+
import type { PromptAssembly } from "@deepseek-ai/dsh-system-prompt";
|
|
2
|
+
import { AuditStore } from "./audit.js";
|
|
3
|
+
import type { FirewallMetrics } from "./metrics.js";
|
|
4
|
+
import type { FirewallDecision, FirewallLogger, FirewallSection, ResolvedPromptFirewallConfig } from "./types.js";
|
|
5
5
|
export type SectionEvaluator = (section: FirewallSection) => FirewallDecision;
|
|
6
6
|
export interface ApplyFirewallOptions {
|
|
7
7
|
config: ResolvedPromptFirewallConfig;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Context } from
|
|
2
|
-
import type { AssembledSection } from
|
|
3
|
-
import { TypertRemoteService } from
|
|
4
|
-
import type { FirewallDecision, KnownSection, PromptAuditResult, PromptFirewallConfig, PromptFirewallInspectorSnapshot, PromptFirewallMetricsSnapshot, PromptFirewallService, ResolvedPromptFirewallConfig, SectionPolicy } from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
declare module
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { AssembledSection } from "@deepseek-ai/dsh-system-prompt";
|
|
3
|
+
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
4
|
+
import type { FirewallDecision, KnownSection, PromptAuditResult, PromptFirewallConfig, PromptFirewallInspectorSnapshot, PromptFirewallMetricsSnapshot, PromptFirewallService, ResolvedPromptFirewallConfig, SectionPolicy } from "./types.js";
|
|
5
|
+
export * from "./audit.js";
|
|
6
|
+
export * from "./config.js";
|
|
7
|
+
export * from "./firewall.js";
|
|
8
|
+
export * from "./metrics.js";
|
|
9
|
+
export * from "./presets.js";
|
|
10
|
+
export * from "./rules.js";
|
|
11
|
+
export * from "./types.js";
|
|
12
|
+
declare module "@deepseek-ai/cordis" {
|
|
13
13
|
interface Context {
|
|
14
14
|
/** Inspect and evaluate prompt firewall state without accessing internals. */
|
|
15
15
|
promptFirewall: PromptFirewallService;
|
package/lib/types/metrics.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { PromptAuditResult, PromptFirewallMetricsSnapshot } from
|
|
1
|
+
import type { PromptAuditResult, PromptFirewallMetricsSnapshot } from "./types.js";
|
|
2
2
|
export declare const METRIC_NAMES: Readonly<{
|
|
3
|
-
readonly requestsTotal:
|
|
4
|
-
readonly sectionsTotal:
|
|
5
|
-
readonly sectionsBlockedTotal:
|
|
6
|
-
readonly charsRemovedTotal:
|
|
7
|
-
readonly estimatedTokensRemovedTotal:
|
|
3
|
+
readonly requestsTotal: "dsh_prompt_firewall_requests_total";
|
|
4
|
+
readonly sectionsTotal: "dsh_prompt_firewall_sections_total";
|
|
5
|
+
readonly sectionsBlockedTotal: "dsh_prompt_firewall_sections_blocked_total";
|
|
6
|
+
readonly charsRemovedTotal: "dsh_prompt_firewall_chars_removed_total";
|
|
7
|
+
readonly estimatedTokensRemovedTotal: "dsh_prompt_firewall_estimated_tokens_removed_total";
|
|
8
8
|
}>;
|
|
9
|
-
export type PromptFirewallMetricName = typeof METRIC_NAMES[keyof typeof METRIC_NAMES];
|
|
9
|
+
export type PromptFirewallMetricName = (typeof METRIC_NAMES)[keyof typeof METRIC_NAMES];
|
|
10
10
|
/** Backend-neutral, label-free counters suitable for UI or an OTel adapter. */
|
|
11
11
|
export declare class FirewallMetrics {
|
|
12
12
|
private counters;
|
package/lib/types/presets.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FirewallPreset, PromptFirewallConfig } from
|
|
1
|
+
import type { FirewallPreset, PromptFirewallConfig } from "./types.js";
|
|
2
2
|
export declare const CLEAN_BLOCKED_SECTIONS: readonly ["plugin:dsh-liangshen", "plugin:dsh-ssh", "plugin:task-board", "plugin:dsh-desktop-launcher"];
|
|
3
3
|
export declare const PRESETS: Readonly<Record<FirewallPreset, Readonly<PromptFirewallConfig>>>;
|
|
4
4
|
export declare function getPreset(name: FirewallPreset | undefined): Readonly<PromptFirewallConfig>;
|
package/lib/types/rules.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FirewallDecision, FirewallSection, ResolvedPromptFirewallConfig } from
|
|
1
|
+
import type { FirewallDecision, FirewallSection, ResolvedPromptFirewallConfig } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Verified against the upstream DSH registry. `harness:` and `deployment:` are
|
|
4
4
|
* emitted by dsh-system-prompt; `tool:` and `tools:` are used for tool guidance.
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AssembledSection, PromptAssembly } from
|
|
2
|
-
export type FirewallMode =
|
|
3
|
-
export type FirewallPreset =
|
|
4
|
-
export type UnknownPluginPolicy =
|
|
1
|
+
import type { AssembledSection, PromptAssembly } from "@deepseek-ai/dsh-system-prompt";
|
|
2
|
+
export type FirewallMode = "off" | "audit" | "blocklist" | "allowlist";
|
|
3
|
+
export type FirewallPreset = "clean" | "strict" | "audit-only";
|
|
4
|
+
export type UnknownPluginPolicy = "allow" | "block";
|
|
5
5
|
export interface AuditConfig {
|
|
6
6
|
enabled: boolean;
|
|
7
7
|
logAllowed: boolean;
|
|
@@ -48,8 +48,8 @@ export interface ResolvedPromptFirewallConfig {
|
|
|
48
48
|
readonly audit: Readonly<AuditConfig>;
|
|
49
49
|
readonly metrics: Readonly<MetricsConfig>;
|
|
50
50
|
}
|
|
51
|
-
export type FirewallAction =
|
|
52
|
-
export type SectionPolicy = FirewallAction |
|
|
51
|
+
export type FirewallAction = "allow" | "block" | "protect";
|
|
52
|
+
export type SectionPolicy = FirewallAction | "clear";
|
|
53
53
|
export interface FirewallDecision {
|
|
54
54
|
action: FirewallAction;
|
|
55
55
|
reason: string;
|
|
@@ -57,7 +57,7 @@ export interface FirewallDecision {
|
|
|
57
57
|
}
|
|
58
58
|
export interface PromptSectionAudit {
|
|
59
59
|
name: string;
|
|
60
|
-
decision:
|
|
60
|
+
decision: "allowed" | "blocked" | "protected";
|
|
61
61
|
reason: string;
|
|
62
62
|
chars: number;
|
|
63
63
|
estimatedTokens: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yadsh/dsh-prompt-firewall",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Prompt hygiene, observability, and policy middleware for DeepSeek Harness",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
95
|
"zod": "^4.4.3",
|
|
96
|
-
"@yadsh/dsh-plugin-log": "^0.3.
|
|
96
|
+
"@yadsh/dsh-plugin-log": "^0.3.1"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@deepseek-ai/cordis": "4.0.2",
|
|
@@ -131,6 +131,8 @@
|
|
|
131
131
|
"test": "vitest run",
|
|
132
132
|
"test:watch": "vitest",
|
|
133
133
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
134
|
-
"verify": "node scripts/verify-package.mjs"
|
|
134
|
+
"verify:package": "node scripts/verify-package.mjs",
|
|
135
|
+
"verify": "pnpm run verify:package",
|
|
136
|
+
"check": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build && pnpm run verify"
|
|
135
137
|
}
|
|
136
138
|
}
|