leakshield 0.1.0 → 0.1.1

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
@@ -24,7 +24,7 @@ MCP server mode has been removed. It depended on the model voluntarily calling a
24
24
 
25
25
  ## Project status
26
26
 
27
- **Experimental, pre-release.** Nothing is published to npm yet: build locally (`npm ci && npm run build`) and point OpenCode at the `dist` directory.
27
+ **Experimental, pre-release.** Published to npm as `leakshield` (`0.1.x`): run `npx leakshield`, or build locally (`npm ci && npm run build`) and point OpenCode at the `dist` directory.
28
28
 
29
29
  - Transparent mode has been verified on OpenCode v2.0.28 with local loopback providers, and once against a real OpenAI model. It is **not** a guarantee that nothing sensitive reaches a model: the recommended hook-first setup is reported as `PARTIAL` by `--doctor`, and content added after the plugin's hooks or sent by permitted tools (curl, remote MCP) is outside its coverage.
30
30
  - Not yet verified: OS-keychain persistence, a real Anthropic provider, long histories on other providers, long-running use ([#26](https://github.com/jwcrystal/leakshield/issues/26)).
@@ -99,9 +99,9 @@ npm install
99
99
  npm run build
100
100
  ```
101
101
 
102
- Nothing is published to npm yet, so `npx leakshield` only works after you
103
- install the build globally or `npm link` it; then use `leakshield`
104
- directly. `npm run scan -- ...` works from this repository without installing.
102
+ `npx leakshield …` runs the published package. For local development, install
103
+ the build globally or `npm link` it, then use `leakshield` directly.
104
+ `npm run scan -- ...` works from this repository without installing.
105
105
 
106
106
  ### npm Scripts
107
107
 
package/README.zh-TW.md CHANGED
@@ -24,7 +24,7 @@ MCP Server 模式已移除。它依賴模型在已收到相關 context 後自行
24
24
 
25
25
  ## 目前狀態
26
26
 
27
- **實驗性,尚未正式發佈。** 還沒發佈到 npm:請在本機建置(`npm ci && npm run build`),再讓 OpenCode 指向 `dist` 目錄。
27
+ **實驗性,尚未正式發佈。** 已發佈到 npm(`leakshield`,`0.1.x`):可直接用 `npx leakshield`,或在本機建置(`npm ci && npm run build`)再讓 OpenCode 指向 `dist` 目錄。
28
28
 
29
29
  - Transparent 模式已在 OpenCode v2.0.28 搭配本機替身 provider 驗證,並用真實 OpenAI 模型驗證過一次。它**不保證**敏感內容絕不會送到模型:建議的 hook-first 設定在 `--doctor` 顯示為 `PARTIAL`,hook 之後才加入的內容,以及被允許的工具外送(curl、遠端 MCP),都不在保護範圍內。
30
30
  - 尚未驗證:OS keychain 持久化、真實 Anthropic provider、其他 provider 的長對話、長時間使用([#26](https://github.com/jwcrystal/leakshield/issues/26))。
@@ -104,7 +104,7 @@ npm install
104
104
  npm run build
105
105
  ```
106
106
 
107
- 尚未發佈到 npm,所以 `npx leakshield` 要等你全域安裝或 `npm link` 這份 build 後才能用,之後可直接使用
107
+ `npx leakshield …` 會執行已發佈的套件。本機開發時,全域安裝或 `npm link` 這份 build 後即可直接使用
108
108
  `leakshield`;在此 repository 內不用安裝,直接用 `npm run scan -- ...` 即可。
109
109
 
110
110
  ### npm scripts 速查
@@ -4,7 +4,7 @@ import { redactAndVerify } from "../scanner/redaction-verifier.js";
4
4
  const DEFAULT_CACHE_SIZE = 512;
5
5
  export function blockedText(context, totalFindings) {
6
6
  const count = totalFindings === 0 ? "unscanned" : `${totalFindings} sensitive item(s)`;
7
- return `[LeakShield blocked ${context}: ${count}. Original content was not sent to the model.]`;
7
+ return `[LeakShield blocked ${context}: ${count}. The original was not sent to the model.]`;
8
8
  }
9
9
  /**
10
10
  * Returns text that is safe to place in an LLM context. Content that exceeds
@@ -121,7 +121,7 @@ export function protectUnknownStrings(value, config, options, protector = protec
121
121
  return copy;
122
122
  }
123
123
  if (!isPlainRecord(value)) {
124
- return "[LeakShield blocked unsupported metadata value.]";
124
+ return "[LeakShield blocked an unsupported metadata value.]";
125
125
  }
126
126
  const copy = {};
127
127
  seen.set(value, copy);
@@ -1,12 +1,12 @@
1
1
  import { ContentHashCache, protectUnknownStrings, } from "./decision/ingress.js";
2
- const INITIALIZATION_ERROR = "LeakShield initialization failed. Model request blocked before content was sent.";
2
+ const INITIALIZATION_ERROR = "LeakShield initialization failed, so the request was blocked before anything was sent.";
3
3
  function blockedAttachment(part) {
4
4
  return {
5
5
  id: part.id,
6
6
  sessionID: part.sessionID,
7
7
  messageID: part.messageID,
8
8
  type: "text",
9
- text: "[LeakShield blocked an attachment. Attachments are not forwarded because their content cannot be safely scanned.]",
9
+ text: "[LeakShield blocked an attachment: its content cannot be scanned, so it was not sent.]",
10
10
  synthetic: true,
11
11
  };
12
12
  }
@@ -5,9 +5,9 @@
5
5
  * the supported contract (including any private sockets/global-fetch path). */
6
6
  import { types } from "node:util";
7
7
  import { classifyModelRoute } from "./opencode-transparent-http.js";
8
- const ADMISSION_ERROR = "LeakShield transparent mode blocked an unsupported model transport route. AI SDK providers must honor OpenCode's injected HTTP fetch.";
9
- const DISPOSED_ERROR = "LeakShield transparent mode blocked an inactive AI SDK transport.";
10
- const PROTECTION_ERROR = "LeakShield transparent mode blocked an AI SDK HTTP request. Check its protocol, metadata and content before retrying.";
8
+ const ADMISSION_ERROR = "LeakShield blocked an unsupported route. The provider must use the fetch OpenCode injects.";
9
+ const DISPOSED_ERROR = "LeakShield blocked a request on an inactive AI SDK transport.";
10
+ const PROTECTION_ERROR = "LeakShield blocked an AI SDK request. Check its protocol, metadata and content, then try again.";
11
11
  function optionsOf(event) {
12
12
  if (types.isProxy(event))
13
13
  throw new Error(ADMISSION_ERROR);
@@ -48,13 +48,13 @@ import { createRecoveringSseStream } from "./opencode-transparent-stream.js";
48
48
  const warnDegradation = (context) => {
49
49
  console.warn(`[leakshield] degraded: ${context}`);
50
50
  };
51
- const UNSUPPORTED_REQUEST_BODY = "LeakShield transparent mode blocked a model request with an unsupported or unidentifiable body.";
52
- const UNSUPPORTED_TRANSPORT = "LeakShield transparent mode blocked a request on an unsupported model transport route.";
53
- const MASK_FAILURE = "LeakShield transparent mode failed to mask a model request.";
54
- const UNSUPPORTED_RESPONSE = "LeakShield transparent mode blocked a response it cannot restore safely.";
55
- const RESTORE_FAILURE = "LeakShield transparent mode failed to restore a model response.";
56
- const MALFORMED_STREAM = "LeakShield transparent mode blocked a malformed or incomplete streaming response.";
57
- const STREAM_BUFFER_LIMIT = "LeakShield transparent mode blocked an oversized streaming buffer.";
51
+ const UNSUPPORTED_REQUEST_BODY = "LeakShield blocked the request because its body is unsupported or could not be identified.";
52
+ const UNSUPPORTED_TRANSPORT = "LeakShield blocked a request on an unsupported route.";
53
+ const MASK_FAILURE = "LeakShield blocked the request because it could not be masked safely.";
54
+ const UNSUPPORTED_RESPONSE = "LeakShield blocked a response it could not restore safely.";
55
+ const RESTORE_FAILURE = "LeakShield blocked the response because it could not be restored safely.";
56
+ const MALFORMED_STREAM = "LeakShield blocked a malformed or incomplete stream.";
57
+ const STREAM_BUFFER_LIMIT = "LeakShield blocked an oversized stream buffer.";
58
58
  /**
59
59
  * Content-free refusal classification (2026-10-08): every request refusal
60
60
  * appends a fixed code naming WHICH check failed — the refusal-policy spec
@@ -4,10 +4,10 @@
4
4
  * OpenCode exposes no connection ID; attribution uses the hook's session,
5
5
  * kind and model lane, then the provider's response ID. */
6
6
  import { admitModelRequest, classifyModelRoute, remaskResponsesRequest, RESPONSES_TEXT_DELTA_TYPES, RESPONSES_TEXT_DONE_TYPES, restoreDisplayText, restoreResponsesEventDisplay, splitRestorable, } from "./opencode-transparent-http.js";
7
- const ROUTE_ERROR = "LeakShield transparent mode blocked an unsupported model transport route.";
8
- const FRAME_ERROR = "LeakShield transparent mode blocked an unsupported or malformed WebSocket frame.";
9
- const ATTRIBUTION_ERROR = "LeakShield transparent mode blocked a WebSocket frame without matching request attribution.";
10
- const LIMIT_ERROR = "LeakShield transparent mode blocked an oversized WebSocket buffer.";
7
+ const ROUTE_ERROR = "LeakShield blocked a request on an unsupported route.";
8
+ const FRAME_ERROR = "LeakShield blocked an unsupported or malformed WebSocket frame.";
9
+ const ATTRIBUTION_ERROR = "LeakShield blocked a WebSocket frame that could not be matched to a request.";
10
+ const LIMIT_ERROR = "LeakShield blocked an oversized WebSocket buffer.";
11
11
  const MAX_FRAME_BYTES = 4 * 1024 * 1024;
12
12
  const MAX_LANES = 1024;
13
13
  const MAX_CHANNELS = 256;
@@ -46,16 +46,16 @@ import { createResponsesWebSocketAdapter } from "./opencode-transparent-ws.js";
46
46
  import { createAISDKTransportAdmission } from "./opencode-transparent-aisdk.js";
47
47
  import { BUILTIN_RULES } from "./rules/builtin.js";
48
48
  // ─── Static failure messages (no content ever included) ─────────────────────
49
- const INITIALIZATION_ERROR = "LeakShield initialization failed. Model request blocked before content was sent.";
50
- const PROTECT_FAILED_ERROR = "LeakShield transparent mode failed to protect a model request.";
51
- const ATTRIBUTION_ERROR = "LeakShield transparent mode blocked a response without verified request attribution.";
52
- const UNSUPPORTED_ROUTE_ERROR = "LeakShield transparent mode blocked an unsupported model transport route.";
53
- const TOOL_REFUSAL_ERROR = "LeakShield transparent mode blocked this tool call because its arguments could not be safely restored. Refresh the affected arguments and retry.";
54
- const TOOL_UNKNOWN_MAPPING_ERROR = "LeakShield transparent mode blocked this tool call because a placeholder has no mapping in this session. Re-read the source in this session, refresh the affected arguments, and retry.";
55
- const TOOL_RESTORE_LIMIT_ERROR = "LeakShield transparent mode blocked this tool call because its arguments exceed the safe restoration limit. Reduce the arguments and retry.";
56
- const TOOL_SHELL_CONTEXT_ERROR = "LeakShield transparent mode blocked this tool call because the shell command does not use a supported literal-argument form. Rewrite it as a simple command or use a non-shell tool.";
57
- const TOOL_INPUT_SHAPE_ERROR = "LeakShield transparent mode blocked this tool call because its argument structure cannot be safely restored. Refresh the arguments using plain JSON values and retry.";
58
- const STRUCTURAL_SENSITIVE_ERROR = "LeakShield transparent mode refused this model request: a structural identifier (message or tool id, name, role, or part type) scans as sensitive, and masking cannot rewrite it without breaking the protocol. Adjust the matching rule in the guard config or change the identifier, then retry.";
49
+ const INITIALIZATION_ERROR = "LeakShield initialization failed, so the request was blocked before anything was sent.";
50
+ const PROTECT_FAILED_ERROR = "LeakShield blocked a model request because it could not be masked safely.";
51
+ const ATTRIBUTION_ERROR = "LeakShield blocked a response because it could not be matched to a request.";
52
+ const UNSUPPORTED_ROUTE_ERROR = "LeakShield blocked a request on an unsupported route.";
53
+ const TOOL_REFUSAL_ERROR = "LeakShield blocked this tool call because its arguments could not be restored safely. Re-read the file and try again.";
54
+ const TOOL_UNKNOWN_MAPPING_ERROR = "LeakShield blocked this tool call because a placeholder has no mapping in this session. Re-read the file, then try again.";
55
+ const TOOL_RESTORE_LIMIT_ERROR = "LeakShield blocked this tool call because its arguments are too large to restore safely. Use smaller arguments and try again.";
56
+ const TOOL_SHELL_CONTEXT_ERROR = "LeakShield blocked this tool call because the shell command's quoting is not supported. Use a simple command with plain arguments, or a different tool.";
57
+ const TOOL_INPUT_SHAPE_ERROR = "LeakShield blocked this tool call because its argument structure cannot be safely restored. Use plain JSON values and try again.";
58
+ const STRUCTURAL_SENSITIVE_ERROR = "LeakShield blocked this request because a structural identifier (message or tool id, name, role, or part type) scans as sensitive and cannot be masked. Change it or adjust the matching rule, then try again.";
59
59
  function toolRestoreError(reason) {
60
60
  if (reason === "unknown_token" || reason === "malformed_token")
61
61
  return TOOL_UNKNOWN_MAPPING_ERROR;
@@ -2,8 +2,8 @@ import { createHmac } from "node:crypto";
2
2
  import { ContentHashCache, protectUnknownStrings, } from "./decision/ingress.js";
3
3
  import { deidentifyText } from "./decision/deidentify.js";
4
4
  import { registerV2EnvTools } from "./opencode-env-tools.js";
5
- const INITIALIZATION_ERROR = "LeakShield initialization failed. Model request blocked before content was sent.";
6
- const BLOCKED_ATTACHMENT_NOTICE = "[LeakShield blocked an attachment. Attachments are not forwarded because their content cannot be safely scanned.]";
5
+ const INITIALIZATION_ERROR = "LeakShield initialization failed, so the request was blocked before anything was sent.";
6
+ const BLOCKED_ATTACHMENT_NOTICE = "[LeakShield blocked an attachment: its content cannot be scanned, so it was not sent.]";
7
7
  function isRecordLike(value) {
8
8
  return typeof value === "object" && value !== null;
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leakshield",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "OpenCode plugin, CLI, and web scanner for sensitive content before sending it to AI",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "node": ">=20"
35
35
  },
36
36
  "bin": {
37
- "leakshield": "./dist/cli.js"
37
+ "leakshield": "dist/cli.js"
38
38
  },
39
39
  "scripts": {
40
40
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",