@yadsh/dsh-prompt-firewall 0.1.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/LICENSE +21 -0
- package/README.md +165 -0
- package/cordis.patch.yml +4 -0
- package/lib/audit.js +121 -0
- package/lib/audit.js.map +1 -0
- package/lib/client/index.js +155 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/styles.js +7 -0
- package/lib/client/styles.js.map +1 -0
- package/lib/client.js +5857 -0
- package/lib/client.js.map +1 -0
- package/lib/config.js +100 -0
- package/lib/config.js.map +1 -0
- package/lib/firewall.js +88 -0
- package/lib/firewall.js.map +1 -0
- package/lib/index.js +166 -0
- package/lib/index.js.map +1 -0
- package/lib/metrics.js +38 -0
- package/lib/metrics.js.map +1 -0
- package/lib/presets.js +23 -0
- package/lib/presets.js.map +1 -0
- package/lib/rules.js +103 -0
- package/lib/rules.js.map +1 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +258 -0
- package/lib/typert.remote-client.d.ts +24 -0
- package/lib/typert.remote-client.js +141 -0
- package/lib/types/audit.d.ts +17 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/styles.d.ts +1 -0
- package/lib/types/config.d.ts +8 -0
- package/lib/types/firewall.d.ts +17 -0
- package/lib/types/index.d.ts +46 -0
- package/lib/types/metrics.d.ts +16 -0
- package/lib/types/presets.d.ts +4 -0
- package/lib/types/rules.d.ts +25 -0
- package/lib/types/types.d.ts +125 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
export interface AuditConfig {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
logAllowed: boolean;
|
|
8
|
+
logBlocked: boolean;
|
|
9
|
+
includePreview: boolean;
|
|
10
|
+
previewChars: number;
|
|
11
|
+
historySize: number;
|
|
12
|
+
highlightNewSections: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface MetricsConfig {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** User-facing configuration. Every field is optional at the Cordis boundary. */
|
|
18
|
+
export interface PromptFirewallConfig {
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
mode?: FirewallMode;
|
|
21
|
+
preset?: FirewallPreset;
|
|
22
|
+
blockedSections?: string[];
|
|
23
|
+
allowedSections?: string[];
|
|
24
|
+
blockedPrefixes?: string[];
|
|
25
|
+
allowedPrefixes?: string[];
|
|
26
|
+
blockedPatterns?: string[];
|
|
27
|
+
allowedPatterns?: string[];
|
|
28
|
+
protectedSections?: string[];
|
|
29
|
+
protectCoreSections?: boolean;
|
|
30
|
+
unknownPluginPolicy?: UnknownPluginPolicy;
|
|
31
|
+
audit?: Partial<AuditConfig>;
|
|
32
|
+
metrics?: Partial<MetricsConfig>;
|
|
33
|
+
}
|
|
34
|
+
/** Fully materialized, immutable runtime configuration. */
|
|
35
|
+
export interface ResolvedPromptFirewallConfig {
|
|
36
|
+
readonly enabled: boolean;
|
|
37
|
+
readonly mode: FirewallMode;
|
|
38
|
+
readonly preset?: FirewallPreset;
|
|
39
|
+
readonly blockedSections: readonly string[];
|
|
40
|
+
readonly allowedSections: readonly string[];
|
|
41
|
+
readonly blockedPrefixes: readonly string[];
|
|
42
|
+
readonly allowedPrefixes: readonly string[];
|
|
43
|
+
readonly blockedPatterns: readonly string[];
|
|
44
|
+
readonly allowedPatterns: readonly string[];
|
|
45
|
+
readonly protectedSections: readonly string[];
|
|
46
|
+
readonly protectCoreSections: boolean;
|
|
47
|
+
readonly unknownPluginPolicy: UnknownPluginPolicy;
|
|
48
|
+
readonly audit: Readonly<AuditConfig>;
|
|
49
|
+
readonly metrics: Readonly<MetricsConfig>;
|
|
50
|
+
}
|
|
51
|
+
export type FirewallAction = 'allow' | 'block' | 'protect';
|
|
52
|
+
export type SectionPolicy = FirewallAction | 'clear';
|
|
53
|
+
export interface FirewallDecision {
|
|
54
|
+
action: FirewallAction;
|
|
55
|
+
reason: string;
|
|
56
|
+
rule?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface PromptSectionAudit {
|
|
59
|
+
name: string;
|
|
60
|
+
decision: 'allowed' | 'blocked' | 'protected';
|
|
61
|
+
reason: string;
|
|
62
|
+
chars: number;
|
|
63
|
+
estimatedTokens: number;
|
|
64
|
+
preview?: string;
|
|
65
|
+
suspicious?: boolean;
|
|
66
|
+
isNew?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface PromptAuditResult {
|
|
69
|
+
timestamp: number;
|
|
70
|
+
totalSections: number;
|
|
71
|
+
allowedSections: number;
|
|
72
|
+
blockedSections: number;
|
|
73
|
+
charsBefore: number;
|
|
74
|
+
charsAfter: number;
|
|
75
|
+
charsRemoved: number;
|
|
76
|
+
estimatedTokensBefore: number;
|
|
77
|
+
estimatedTokensAfter: number;
|
|
78
|
+
estimatedTokensRemoved: number;
|
|
79
|
+
sections: PromptSectionAudit[];
|
|
80
|
+
bypassed?: boolean;
|
|
81
|
+
bypassReason?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface KnownSection {
|
|
84
|
+
name: string;
|
|
85
|
+
firstSeenAt: number;
|
|
86
|
+
lastSeenAt: number;
|
|
87
|
+
observations: number;
|
|
88
|
+
}
|
|
89
|
+
export interface PromptFirewallService {
|
|
90
|
+
inspect(): PromptFirewallInspectorSnapshot;
|
|
91
|
+
inspectLast(): PromptAuditResult | null;
|
|
92
|
+
inspectHistory(): PromptAuditResult[];
|
|
93
|
+
getKnownSections(): KnownSection[];
|
|
94
|
+
getMetrics(): PromptFirewallMetricsSnapshot;
|
|
95
|
+
getConfig(): ResolvedPromptFirewallConfig;
|
|
96
|
+
evaluateSection(section: AssembledSection): FirewallDecision;
|
|
97
|
+
setSectionPolicy(name: string, policy: SectionPolicy, expectedRevision?: number): Promise<void>;
|
|
98
|
+
reloadRules(): void;
|
|
99
|
+
}
|
|
100
|
+
/** JSON-safe state exposed to the browser Prompt Inspector. */
|
|
101
|
+
export interface PromptFirewallInspectorSnapshot {
|
|
102
|
+
config: ResolvedPromptFirewallConfig;
|
|
103
|
+
last: PromptAuditResult | null;
|
|
104
|
+
knownSections: KnownSection[];
|
|
105
|
+
metrics: PromptFirewallMetricsSnapshot;
|
|
106
|
+
}
|
|
107
|
+
export interface PromptFirewallMetricsSnapshot {
|
|
108
|
+
requestsTotal: number;
|
|
109
|
+
sectionsTotal: number;
|
|
110
|
+
sectionsBlockedTotal: number;
|
|
111
|
+
charsRemovedTotal: number;
|
|
112
|
+
estimatedTokensRemovedTotal: number;
|
|
113
|
+
}
|
|
114
|
+
export interface FirewallLogger {
|
|
115
|
+
info(message: string): unknown;
|
|
116
|
+
warn(message: string): unknown;
|
|
117
|
+
error(message: string): unknown;
|
|
118
|
+
}
|
|
119
|
+
/** Upstream currently strips `complete` before the waterfall; kept for compatible hosts. */
|
|
120
|
+
export type FirewallSection = AssembledSection & {
|
|
121
|
+
complete?: boolean;
|
|
122
|
+
};
|
|
123
|
+
export type FirewallAssembly = PromptAssembly & {
|
|
124
|
+
sections: FirewallSection[];
|
|
125
|
+
};
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yadsh/dsh-prompt-firewall",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Prompt hygiene, observability, and policy middleware for DeepSeek Harness",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/xarleyn/dsh-plugins.git",
|
|
8
|
+
"directory": "plugins/dsh-prompt-firewall"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/xarleyn/dsh-plugins/tree/main/plugins/dsh-prompt-firewall#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/xarleyn/dsh-plugins/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./lib/index.js",
|
|
16
|
+
"types": "./lib/types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./lib/types/index.d.ts",
|
|
20
|
+
"default": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./client": {
|
|
23
|
+
"types": "./lib/types/client/index.d.ts",
|
|
24
|
+
"default": "./lib/client.js"
|
|
25
|
+
},
|
|
26
|
+
"./remote": {
|
|
27
|
+
"types": "./lib/typert.remote-client.d.ts",
|
|
28
|
+
"default": "./lib/typert.remote-client.js"
|
|
29
|
+
},
|
|
30
|
+
"./typert": {
|
|
31
|
+
"types": "./lib/typert.host.d.ts",
|
|
32
|
+
"default": "./lib/typert.host.js"
|
|
33
|
+
},
|
|
34
|
+
"./types": {
|
|
35
|
+
"types": "./lib/types/types.d.ts",
|
|
36
|
+
"default": "./lib/types.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"dsh": {
|
|
41
|
+
"bundle": {
|
|
42
|
+
"patch": "./cordis.patch.yml"
|
|
43
|
+
},
|
|
44
|
+
"client": {
|
|
45
|
+
"external": [
|
|
46
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
47
|
+
],
|
|
48
|
+
"inject": [
|
|
49
|
+
"@deepseek-ai/dsh-api-gateway",
|
|
50
|
+
"@deepseek-ai/dsh-client-connection",
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
52
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins"
|
|
53
|
+
],
|
|
54
|
+
"platform": "web"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"lib/**/*.js",
|
|
59
|
+
"lib/**/*.js.map",
|
|
60
|
+
"lib/**/*.d.ts",
|
|
61
|
+
"lib/client.js",
|
|
62
|
+
"cordis.patch.yml",
|
|
63
|
+
"README.md"
|
|
64
|
+
],
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "node scripts/generate-typert.mjs && tsc -p tsconfig.build.json && tsdown",
|
|
67
|
+
"lint": "eslint src tests scripts",
|
|
68
|
+
"test": "vitest run",
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
71
|
+
"verify": "node scripts/verify-package.mjs"
|
|
72
|
+
},
|
|
73
|
+
"keywords": [
|
|
74
|
+
"deepseek-harness",
|
|
75
|
+
"dsh",
|
|
76
|
+
"prompt",
|
|
77
|
+
"firewall",
|
|
78
|
+
"cordis"
|
|
79
|
+
],
|
|
80
|
+
"license": "MIT",
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"@deepseek-ai/cordis": "catalog:dsh",
|
|
83
|
+
"@deepseek-ai/schemastery": "catalog:dsh",
|
|
84
|
+
"@deepseek-ai/dsh-api-gateway": "catalog:dsh",
|
|
85
|
+
"@deepseek-ai/dsh-client-runtime": "catalog:dsh",
|
|
86
|
+
"@deepseek-ai/dsh-client-ui-settings": "catalog:dsh",
|
|
87
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins": "catalog:dsh",
|
|
88
|
+
"@deepseek-ai/dsh-client-ui-slots": "catalog:dsh",
|
|
89
|
+
"@deepseek-ai/dsh-settings": "catalog:dsh",
|
|
90
|
+
"@deepseek-ai/dsh-system-prompt": "catalog:dsh",
|
|
91
|
+
"@deepseek-ai/dsh-typert-protocol": "catalog:dsh",
|
|
92
|
+
"react": ">=18.2.0 <20"
|
|
93
|
+
},
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"zod": "^4.4.3"
|
|
96
|
+
},
|
|
97
|
+
"devDependencies": {
|
|
98
|
+
"@deepseek-ai/cordis": "catalog:dsh-dev",
|
|
99
|
+
"@deepseek-ai/schemastery": "catalog:dsh-dev",
|
|
100
|
+
"@deepseek-ai/dsh-api-gateway": "catalog:dsh-dev",
|
|
101
|
+
"@deepseek-ai/dsh-client-runtime": "catalog:dsh-dev",
|
|
102
|
+
"@deepseek-ai/dsh-client-ui-settings": "catalog:dsh-dev",
|
|
103
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins": "catalog:dsh-dev",
|
|
104
|
+
"@deepseek-ai/dsh-client-ui-slots": "catalog:dsh-dev",
|
|
105
|
+
"@deepseek-ai/dsh-settings": "catalog:dsh-dev",
|
|
106
|
+
"@deepseek-ai/dsh-system-prompt": "catalog:dsh-dev",
|
|
107
|
+
"@deepseek-ai/dsh-typert-generator": "catalog:dsh-dev",
|
|
108
|
+
"@deepseek-ai/dsh-typert-protocol": "catalog:dsh-dev",
|
|
109
|
+
"@types/node": "catalog:tooling",
|
|
110
|
+
"@types/react": "catalog:frontend-dev",
|
|
111
|
+
"react": "catalog:frontend-dev",
|
|
112
|
+
"eslint": "catalog:tooling",
|
|
113
|
+
"tsdown": "catalog:tooling",
|
|
114
|
+
"typescript": "catalog:plugin-tooling",
|
|
115
|
+
"vitest": "catalog:tooling"
|
|
116
|
+
},
|
|
117
|
+
"engines": {
|
|
118
|
+
"node": ">=20"
|
|
119
|
+
},
|
|
120
|
+
"publishConfig": {
|
|
121
|
+
"access": "public",
|
|
122
|
+
"registry": "https://registry.npmjs.org/"
|
|
123
|
+
}
|
|
124
|
+
}
|