leakshield 0.3.1 → 0.4.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.
Files changed (108) hide show
  1. package/README.md +35 -5
  2. package/README.zh-TW.md +34 -5
  3. package/dist/adapters/claude-code/capabilities.d.ts +14 -0
  4. package/dist/adapters/claude-code/capabilities.js +47 -0
  5. package/dist/adapters/claude-code/cli.d.ts +10 -0
  6. package/dist/adapters/claude-code/cli.js +51 -0
  7. package/dist/adapters/claude-code/doctor.d.ts +19 -0
  8. package/dist/adapters/claude-code/doctor.js +177 -0
  9. package/dist/adapters/claude-code/proxy.d.ts +47 -0
  10. package/dist/adapters/claude-code/proxy.js +348 -0
  11. package/dist/adapters/opencode/capabilities.d.ts +10 -0
  12. package/dist/adapters/opencode/capabilities.js +48 -0
  13. package/dist/adapters/opencode/doctor.d.ts +67 -0
  14. package/dist/{doctor.js → adapters/opencode/doctor.js} +16 -42
  15. package/dist/adapters/opencode/env-queries.d.ts +133 -0
  16. package/dist/adapters/opencode/env-tools.d.ts +20 -0
  17. package/dist/adapters/opencode/hooks.d.ts +4 -0
  18. package/dist/adapters/opencode/plugin.d.ts +12 -0
  19. package/dist/{opencode.js → adapters/opencode/plugin.js} +7 -7
  20. package/dist/adapters/opencode/tool-policy.d.ts +2 -0
  21. package/dist/adapters/opencode/tool-policy.js +23 -0
  22. package/dist/adapters/opencode/transparent-aisdk.d.ts +6 -0
  23. package/dist/{opencode-transparent-aisdk.js → adapters/opencode/transparent-aisdk.js} +1 -1
  24. package/dist/adapters/opencode/transparent.d.ts +66 -0
  25. package/dist/adapters/opencode/transparent.js +237 -0
  26. package/dist/adapters/opencode/v2.d.ts +20 -0
  27. package/dist/{opencode-v2.js → adapters/opencode/v2.js} +3 -3
  28. package/dist/adapters/pi/capabilities.d.ts +10 -0
  29. package/dist/adapters/pi/capabilities.js +50 -0
  30. package/dist/adapters/pi/doctor.d.ts +26 -0
  31. package/dist/adapters/pi/doctor.js +276 -0
  32. package/dist/adapters/pi/extension.d.ts +28 -0
  33. package/dist/adapters/pi/extension.js +109 -0
  34. package/dist/adapters/pi/guard.d.ts +33 -0
  35. package/dist/adapters/pi/guard.js +154 -0
  36. package/dist/adapters/pi/persistence.d.ts +9 -0
  37. package/dist/adapters/pi/persistence.js +69 -0
  38. package/dist/adapters/pi/settings.d.ts +51 -0
  39. package/dist/adapters/pi/settings.js +136 -0
  40. package/dist/adapters/pi/tool-policy.d.ts +11 -0
  41. package/dist/adapters/pi/tool-policy.js +114 -0
  42. package/dist/cli.d.ts +18 -0
  43. package/dist/cli.js +17 -6
  44. package/dist/config/loader.d.ts +70 -0
  45. package/dist/config/plain-object.d.ts +2 -0
  46. package/dist/core/index.d.ts +9 -0
  47. package/dist/core/index.js +9 -0
  48. package/dist/core/session-guard.d.ts +61 -0
  49. package/dist/{opencode-transparent.js → core/session-guard.js} +55 -713
  50. package/dist/core/sse-recovery.d.ts +6 -0
  51. package/dist/core/tool-restore-policy.d.ts +153 -0
  52. package/dist/core/tool-restore-policy.js +453 -0
  53. package/dist/core/wire.d.ts +213 -0
  54. package/dist/{opencode-transparent-http.js → core/wire.js} +125 -42
  55. package/dist/core/ws.d.ts +26 -0
  56. package/dist/{opencode-transparent-ws.js → core/ws.js} +1 -1
  57. package/dist/decision/deidentify.d.ts +63 -0
  58. package/dist/decision/ingress.d.ts +40 -0
  59. package/dist/decision/mapping-key.d.ts +91 -0
  60. package/dist/decision/mapping-store.d.ts +166 -0
  61. package/dist/decision/model.d.ts +41 -0
  62. package/dist/decision/pseudonymization.d.ts +176 -0
  63. package/dist/decision/redaction.d.ts +56 -0
  64. package/dist/decision/schema-strings.d.ts +23 -0
  65. package/dist/decision/schema-strings.js +2 -2
  66. package/dist/decision/value-search.d.ts +39 -0
  67. package/dist/doctor-capabilities.d.ts +21 -0
  68. package/dist/doctor-capabilities.js +58 -0
  69. package/dist/doctor-hosts.d.ts +18 -0
  70. package/dist/doctor-hosts.js +144 -0
  71. package/dist/doctor-report.d.ts +45 -0
  72. package/dist/doctor-report.js +111 -0
  73. package/dist/forget.d.ts +18 -0
  74. package/dist/guard-options.d.ts +45 -0
  75. package/dist/{plugin-options.js → guard-options.js} +4 -1
  76. package/dist/help.d.ts +2 -0
  77. package/dist/help.js +15 -1
  78. package/dist/i18n/en.d.ts +65 -0
  79. package/dist/i18n/index.d.ts +15 -0
  80. package/dist/i18n/zh-TW.d.ts +65 -0
  81. package/dist/index.d.ts +13 -0
  82. package/dist/index.js +1 -1
  83. package/dist/rules/builtin.d.ts +4 -0
  84. package/dist/rules/dynamic.d.ts +33 -0
  85. package/dist/scanner/allowlist.d.ts +22 -0
  86. package/dist/scanner/cidr.d.ts +39 -0
  87. package/dist/scanner/encoding.d.ts +87 -0
  88. package/dist/scanner/engine.d.ts +43 -0
  89. package/dist/scanner/exact-values.d.ts +11 -0
  90. package/dist/scanner/redaction-verifier.d.ts +24 -0
  91. package/dist/scanner/remotes.d.ts +29 -0
  92. package/dist/scanner/unicode.d.ts +57 -0
  93. package/dist/scanner/utils.d.ts +22 -0
  94. package/dist/transports/cli.d.ts +27 -0
  95. package/dist/transports/web-ui.d.ts +1 -0
  96. package/dist/transports/web-ui.js +1 -1
  97. package/dist/transports/web.d.ts +4 -0
  98. package/dist/types/capabilities.d.ts +67 -0
  99. package/dist/types/capabilities.js +133 -0
  100. package/dist/types.d.ts +149 -0
  101. package/dist/utils/files.d.ts +3 -0
  102. package/dist/utils/path-security.d.ts +18 -0
  103. package/dist/utils/win-encoding.d.ts +16 -0
  104. package/package.json +11 -3
  105. /package/dist/{env-queries.js → adapters/opencode/env-queries.js} +0 -0
  106. /package/dist/{opencode-env-tools.js → adapters/opencode/env-tools.js} +0 -0
  107. /package/dist/{opencode-hooks.js → adapters/opencode/hooks.js} +0 -0
  108. /package/dist/{opencode-transparent-stream.js → core/sse-recovery.js} +0 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Renders a host's capability declaration for `leakshield --doctor`.
3
+ *
4
+ * The declaration is the only input: the doctor cannot print a row the adapter
5
+ * does not declare, and a test compares this output with the constant. `outside`
6
+ * and `unknown` rows are warnings because the host verdict is capped at PARTIAL
7
+ * by them.
8
+ */
9
+ import { type HostCapabilities } from "./types/capabilities.js";
10
+ export interface CapabilityLine {
11
+ /** e.g. `cap.nonFetch` */
12
+ id: string;
13
+ state: "ok" | "warn";
14
+ detail: string;
15
+ note?: string;
16
+ }
17
+ export declare function capabilityLines(capabilities: HostCapabilities): CapabilityLine[];
18
+ export declare function capabilityHeader(capabilities: HostCapabilities): string;
19
+ export declare function capabilitySection(capabilities: HostCapabilities): string[];
20
+ /** One sentence for the host verdict line, or null when coverage is full. */
21
+ export declare function capabilityCapText(capabilities: HostCapabilities): string | null;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Renders a host's capability declaration for `leakshield --doctor`.
3
+ *
4
+ * The declaration is the only input: the doctor cannot print a row the adapter
5
+ * does not declare, and a test compares this output with the constant. `outside`
6
+ * and `unknown` rows are warnings because the host verdict is capped at PARTIAL
7
+ * by them.
8
+ */
9
+ import { CAPABILITY_ROWS, capabilityAt, capabilityVerdict, } from "./types/capabilities.js";
10
+ const WARN_STATES = new Set(["outside", "unknown"]);
11
+ function shortRow(row) {
12
+ return row.split(".")[1] ?? row;
13
+ }
14
+ export function capabilityLines(capabilities) {
15
+ return CAPABILITY_ROWS.map((row) => {
16
+ const capability = capabilityAt(capabilities, row);
17
+ return {
18
+ id: `cap.${shortRow(row)}`,
19
+ state: WARN_STATES.has(capability.state) ? "warn" : "ok",
20
+ detail: `${capability.state === "unknown" ? "UNKNOWN" : capability.state} — ${capability.mechanism}`,
21
+ note: capability.note,
22
+ };
23
+ });
24
+ }
25
+ export function capabilityHeader(capabilities) {
26
+ return `Host capabilities — ${capabilities.host} (verified ${capabilities.verifiedVersion}, ${capabilities.interception})`;
27
+ }
28
+ export function capabilitySection(capabilities) {
29
+ const icon = { ok: "[OK] ", warn: "[WARN]" };
30
+ const lines = [capabilityHeader(capabilities)];
31
+ lines.push("Coverage scope: host-wide declaration; not filtered to the selected provider/model.");
32
+ lines.push(`Credential handling (declared): ${capabilities.credentials}`);
33
+ lines.push(`Mapping persistence (declared): ${capabilities.persistence}`);
34
+ for (const line of capabilityLines(capabilities)) {
35
+ lines.push(`${icon[line.state]} ${line.id}: ${line.detail}`);
36
+ if (line.note !== undefined)
37
+ lines.push(` note: ${line.note}`);
38
+ }
39
+ const coverage = capabilityVerdict(capabilities);
40
+ const reasons = [...coverage.unknown.map((row) => `${row} unknown`), ...coverage.outside.map((row) => `${row} outside`)];
41
+ lines.push(coverage.verdict === "PROTECTED"
42
+ ? "Coverage: PROTECTED — every declared row is covered."
43
+ : `Coverage: PARTIAL — ${reasons.join("; ")}.`);
44
+ lines.push("Residuals (declared):");
45
+ if (capabilities.residuals.length === 0)
46
+ lines.push(" - none declared");
47
+ for (const residual of capabilities.residuals)
48
+ lines.push(` - ${residual}`);
49
+ return lines;
50
+ }
51
+ /** One sentence for the host verdict line, or null when coverage is full. */
52
+ export function capabilityCapText(capabilities) {
53
+ const coverage = capabilityVerdict(capabilities);
54
+ if (coverage.verdict === "PROTECTED")
55
+ return null;
56
+ const rows = [...coverage.unknown, ...coverage.outside];
57
+ return `${rows.length} declared row${rows.length === 1 ? "" : "s"} unknown or outside (${rows.join(", ")})`;
58
+ }
@@ -0,0 +1,18 @@
1
+ import { type DoctorCheck } from "./doctor-report.js";
2
+ import { type HostCapabilities } from "./types/capabilities.js";
3
+ export type DoctorTarget = "all" | "opencode" | "claude-code" | "pi";
4
+ /** Reads `--doctor=pi`, `--doctor pi`, or a bare `--doctor` (all). */
5
+ export declare function parseDoctorTarget(args: readonly string[]): DoctorTarget | {
6
+ error: string;
7
+ };
8
+ /** A Claude Code check is protected only behind a healthy LeakShield proxy. */
9
+ export declare function claudeCodeVerdict(checks: readonly DoctorCheck[], capabilities?: HostCapabilities): {
10
+ exit: number;
11
+ verdict: string;
12
+ };
13
+ /** An installed pi extension protects the process; load order is a caveat. */
14
+ export declare function piVerdict(checks: readonly DoctorCheck[], capabilities?: HostCapabilities): {
15
+ exit: number;
16
+ verdict: string;
17
+ };
18
+ export declare function runDoctorCommand(args: readonly string[]): Promise<number>;
@@ -0,0 +1,144 @@
1
+ /**
2
+ * `leakshield --doctor [host]` dispatch.
3
+ *
4
+ * Every host keeps its own checks and verdict. With no target the aggregate
5
+ * report decides as before; a target prints only that host and returns an exit
6
+ * code for it, so CI can check one integration without another host's state
7
+ * changing the answer.
8
+ */
9
+ import { createDoctorDeps, runDoctor, } from "./adapters/opencode/doctor.js";
10
+ import { doctorExitCode, formatDoctorReport } from "./doctor-report.js";
11
+ import { createClaudeCodeDoctorDeps, runClaudeCodeDoctor } from "./adapters/claude-code/doctor.js";
12
+ import { createPiDoctorDeps, runPiDoctor } from "./adapters/pi/doctor.js";
13
+ import { CLAUDE_CODE_CAPABILITIES } from "./adapters/claude-code/capabilities.js";
14
+ import { PI_CAPABILITIES } from "./adapters/pi/capabilities.js";
15
+ import { OPENCODE_CAPABILITIES } from "./adapters/opencode/capabilities.js";
16
+ import { capabilityCapText, capabilitySection } from "./doctor-capabilities.js";
17
+ import { capabilityVerdict } from "./types/capabilities.js";
18
+ const TARGETS = new Set(["all", "opencode", "claude-code", "pi"]);
19
+ /** Reads `--doctor=pi`, `--doctor pi`, or a bare `--doctor` (all). */
20
+ export function parseDoctorTarget(args) {
21
+ const inline = args.find((arg) => arg.startsWith("--doctor="));
22
+ let raw;
23
+ if (inline !== undefined) {
24
+ raw = inline.slice("--doctor=".length);
25
+ }
26
+ else {
27
+ const index = args.indexOf("--doctor");
28
+ const next = index === -1 ? undefined : args[index + 1];
29
+ if (next !== undefined && !next.startsWith("-"))
30
+ raw = next;
31
+ }
32
+ if (raw === undefined)
33
+ return "all";
34
+ if (raw.length === 0)
35
+ return { error: "doctor target is missing; use opencode, claude-code, pi or all" };
36
+ if (raw === "all")
37
+ return "all";
38
+ if (TARGETS.has(raw))
39
+ return raw;
40
+ return { error: `unknown doctor target "${raw}"; use opencode, claude-code, pi or all` };
41
+ }
42
+ const ICON = { ok: "[OK] ", warn: "[WARN]", fail: "[FAIL]", skip: "[SKIP]" };
43
+ function printSection(title, checks, verdict, capabilities) {
44
+ const lines = [`leakshield doctor — ${title}`];
45
+ for (const check of checks) {
46
+ lines.push(`${ICON[check.state]} ${check.id}: ${check.detail}`);
47
+ if (check.fix)
48
+ lines.push(` fix: ${check.fix}`);
49
+ }
50
+ if (capabilities) {
51
+ lines.push("");
52
+ lines.push(...capabilitySection(capabilities));
53
+ }
54
+ lines.push("");
55
+ lines.push(`Verdict: ${verdict}`);
56
+ console.log(lines.join("\n"));
57
+ }
58
+ /**
59
+ * A declaration can only lower a verdict. `unknown` and `outside` rows cap the
60
+ * host at PARTIAL even when its install-level checks pass; a broken install
61
+ * keeps its own failing verdict.
62
+ */
63
+ function withCoverage(result, capabilities) {
64
+ if (capabilities === undefined)
65
+ return result;
66
+ if (capabilityVerdict(capabilities).verdict === "PROTECTED")
67
+ return result;
68
+ if (!result.verdict.startsWith("PROTECTED"))
69
+ return result;
70
+ return {
71
+ exit: result.exit,
72
+ verdict: `PARTIAL — coverage is partial: ${capabilityCapText(capabilities)}; see the capability rows above.`,
73
+ };
74
+ }
75
+ /** A Claude Code check is protected only behind a healthy LeakShield proxy. */
76
+ export function claudeCodeVerdict(checks, capabilities) {
77
+ return withCoverage(claudeCodeInstallVerdict(checks), capabilities);
78
+ }
79
+ function claudeCodeInstallVerdict(checks) {
80
+ if (checks.some((check) => check.state === "fail"))
81
+ return { exit: 1, verdict: "BROKEN" };
82
+ if (checks.every((check) => check.state === "skip")) {
83
+ return { exit: 1, verdict: "NOT INSTALLED — claude is not on PATH" };
84
+ }
85
+ if (checks.some((check) => check.id === "claude-code-provider" || check.id === "claude-code-host-managed")) {
86
+ return { exit: 1, verdict: "BYPASSED — a provider or host-managed setting skips the proxy" };
87
+ }
88
+ if (checks.some((check) => check.id === "claude-code-proxy" && check.state === "ok")) {
89
+ return { exit: 0, verdict: "PROTECTED — Claude Code is behind the LeakShield proxy" };
90
+ }
91
+ return { exit: 1, verdict: "NOT PROTECTED — Claude Code is not behind the proxy" };
92
+ }
93
+ /** An installed pi extension protects the process; load order is a caveat. */
94
+ export function piVerdict(checks, capabilities) {
95
+ return withCoverage(piInstallVerdict(checks), capabilities);
96
+ }
97
+ function piInstallVerdict(checks) {
98
+ if (checks.every((check) => check.state === "skip")) {
99
+ return { exit: 1, verdict: "NOT INSTALLED — pi is not on PATH" };
100
+ }
101
+ if (checks.some((check) => check.state === "fail"))
102
+ return { exit: 1, verdict: "BROKEN" };
103
+ const registered = checks.find((check) => check.id === "pi-extension-registered");
104
+ if (registered?.state === "ok") {
105
+ return { exit: 0, verdict: "PROTECTED — the extension guards pi's provider requests" };
106
+ }
107
+ if (registered?.state === "warn") {
108
+ return { exit: 0, verdict: "PARTIAL — pi's own requests are guarded; an extension loaded before LeakShield can bypass" };
109
+ }
110
+ return { exit: 1, verdict: "NOT VERIFIED — the extension is not in settings.extensions; a `-e` run is invisible to the doctor" };
111
+ }
112
+ export async function runDoctorCommand(args) {
113
+ const target = parseDoctorTarget(args);
114
+ if (typeof target === "object") {
115
+ console.error(`leakshield: ${target.error}`);
116
+ return 2;
117
+ }
118
+ if (target === "all") {
119
+ const report = await runDoctor(createDoctorDeps());
120
+ report.claudeCode = await runClaudeCodeDoctor(createClaudeCodeDoctorDeps());
121
+ report.pi = await runPiDoctor(createPiDoctorDeps());
122
+ report.capabilities = OPENCODE_CAPABILITIES;
123
+ report.claudeCodeCapabilities = CLAUDE_CODE_CAPABILITIES;
124
+ report.piCapabilities = PI_CAPABILITIES;
125
+ console.log(formatDoctorReport(report));
126
+ return doctorExitCode(report);
127
+ }
128
+ if (target === "opencode") {
129
+ const report = await runDoctor(createDoctorDeps());
130
+ report.capabilities = OPENCODE_CAPABILITIES;
131
+ console.log(formatDoctorReport(report));
132
+ return report.status === "PROTECTED" || report.status === "PARTIAL" ? 0 : 1;
133
+ }
134
+ if (target === "claude-code") {
135
+ const checks = await runClaudeCodeDoctor(createClaudeCodeDoctorDeps());
136
+ const { exit, verdict } = claudeCodeVerdict(checks, CLAUDE_CODE_CAPABILITIES);
137
+ printSection("Claude Code", checks, verdict, CLAUDE_CODE_CAPABILITIES);
138
+ return exit;
139
+ }
140
+ const checks = await runPiDoctor(createPiDoctorDeps());
141
+ const { exit, verdict } = piVerdict(checks, PI_CAPABILITIES);
142
+ printSection("pi", checks, verdict, PI_CAPABILITIES);
143
+ return exit;
144
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Doctor report shape and rendering, shared by every host adapter.
3
+ *
4
+ * OpenCode's status still decides an aggregate run; the Claude Code and pi
5
+ * section checks are reported next to it and only decide a run when OpenCode
6
+ * is absent (see `doctorExitCode`).
7
+ */
8
+ import type { HostCapabilities } from "./types/capabilities.js";
9
+ export type DoctorStatus = "PROTECTED" | "PARTIAL" | "BROKEN" | "NOT_REGISTERED" | "HOST_MISSING";
10
+ export interface DoctorCheck {
11
+ id: string;
12
+ state: "ok" | "warn" | "fail" | "skip";
13
+ detail: string;
14
+ fix?: string;
15
+ }
16
+ export interface DoctorReport {
17
+ status: DoctorStatus;
18
+ hostVersion: string | null;
19
+ hostGeneration: "v1" | "v2" | null;
20
+ configPath: string | null;
21
+ checks: DoctorCheck[];
22
+ /** Weakest validated OpenCode configuration; absent when options are unknown. */
23
+ wireProtection?: "enabled" | "disabled" | "not-applicable";
24
+ /** Copy-paste registration snippet for the OpenCode v2 config. */
25
+ snippet?: string;
26
+ /** Claude Code proxy checks; reported separately from the OpenCode status. */
27
+ claudeCode?: DoctorCheck[];
28
+ /** pi adapter checks; reported separately from the OpenCode status. */
29
+ pi?: DoctorCheck[];
30
+ /** OpenCode's declared coverage, printed under the checks. */
31
+ capabilities?: HostCapabilities;
32
+ /** Claude Code's declared coverage, printed with its checks. */
33
+ claudeCodeCapabilities?: HostCapabilities;
34
+ /** pi's declared coverage, printed with its checks. */
35
+ piCapabilities?: HostCapabilities;
36
+ }
37
+ export declare function formatDoctorReport(report: DoctorReport): string;
38
+ /**
39
+ * The OpenCode status decides as before. Only when OpenCode is absent
40
+ * (HOST_MISSING) can Claude Code or an installed pi extension make the run
41
+ * pass, unless a provider or host setting bypasses it; a failed Claude Code
42
+ * check still fails it. A pi failure only decides the run when OpenCode is
43
+ * absent, so a broken ~/.pi never fails a protected OpenCode run.
44
+ */
45
+ export declare function doctorExitCode(report: DoctorReport): number;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Doctor report shape and rendering, shared by every host adapter.
3
+ *
4
+ * OpenCode's status still decides an aggregate run; the Claude Code and pi
5
+ * section checks are reported next to it and only decide a run when OpenCode
6
+ * is absent (see `doctorExitCode`).
7
+ */
8
+ import { capabilityCapText, capabilitySection } from "./doctor-capabilities.js";
9
+ export function formatDoctorReport(report) {
10
+ const icon = { ok: "[OK] ", warn: "[WARN]", fail: "[FAIL]", skip: "[SKIP]" };
11
+ const lines = [];
12
+ lines.push(`leakshield doctor — ${new Date().toISOString()}`);
13
+ for (const check of report.checks) {
14
+ lines.push(`${icon[check.state]} ${check.id}: ${check.detail}`);
15
+ if (check.fix)
16
+ lines.push(` fix: ${check.fix}`);
17
+ }
18
+ if (report.snippet) {
19
+ lines.push("");
20
+ lines.push("Registration snippet for your opencode.json:");
21
+ lines.push(report.snippet);
22
+ }
23
+ lines.push("");
24
+ lines.push(`Configuration status: ${report.status}`);
25
+ lines.push(`Wire protection: ${report.wireProtection ?? "unknown"} (configuration only; live-session interception is not verified).`);
26
+ const capText = report.capabilities ? capabilityCapText(report.capabilities) : null;
27
+ if (report.capabilities) {
28
+ lines.push("");
29
+ lines.push(...capabilitySection(report.capabilities));
30
+ }
31
+ if (report.status === "PROTECTED" || report.status === "PARTIAL") {
32
+ if (report.status === "PARTIAL") {
33
+ lines.push("Partial reason (configuration): wireProtection=false; final outbound HTTP bodies and WebSocket frames are not inspected.");
34
+ }
35
+ if (capText !== null) {
36
+ lines.push(`Partial reason (host coverage): ${capText}.`);
37
+ }
38
+ }
39
+ lines.push("");
40
+ const verdict = report.status === "PROTECTED"
41
+ ? capText === null
42
+ ? "PROTECTED — install-level checks pass."
43
+ : `PARTIAL — install-level checks pass, but ${capText}; see Host capabilities above.`
44
+ : report.status === "PARTIAL"
45
+ ? "PARTIAL — hook-first protection; final outbound HTTP bodies are not inspected."
46
+ : report.status === "BROKEN"
47
+ ? "BROKEN — registered but would not protect; fix the [FAIL] items above."
48
+ : report.status === "NOT_REGISTERED"
49
+ ? "NOT REGISTERED — LeakShield is not in the OpenCode config; sessions are unprotected."
50
+ : "HOST MISSING — no OpenCode binary found.";
51
+ lines.push(verdict);
52
+ if (report.claudeCode && report.claudeCode.length > 0) {
53
+ lines.push("");
54
+ lines.push("Claude Code:");
55
+ for (const check of report.claudeCode) {
56
+ lines.push(`${icon[check.state]} ${check.id}: ${check.detail}`);
57
+ if (check.fix)
58
+ lines.push(` fix: ${check.fix}`);
59
+ }
60
+ if (report.claudeCodeCapabilities) {
61
+ lines.push("");
62
+ lines.push(...capabilitySection(report.claudeCodeCapabilities));
63
+ }
64
+ }
65
+ if (report.pi && report.pi.length > 0) {
66
+ lines.push("");
67
+ lines.push("pi:");
68
+ for (const check of report.pi) {
69
+ lines.push(`${icon[check.state]} ${check.id}: ${check.detail}`);
70
+ if (check.fix)
71
+ lines.push(` fix: ${check.fix}`);
72
+ }
73
+ if (report.piCapabilities) {
74
+ lines.push("");
75
+ lines.push(...capabilitySection(report.piCapabilities));
76
+ }
77
+ }
78
+ lines.push("");
79
+ lines.push("Scope: model-conversation leak protection. This is NOT a tool-egress firewall: permitted local tools (curl, remote MCP, …) can still transmit originals. See README.");
80
+ return lines.join("\n");
81
+ }
82
+ /**
83
+ * The OpenCode status decides as before. Only when OpenCode is absent
84
+ * (HOST_MISSING) can Claude Code or an installed pi extension make the run
85
+ * pass, unless a provider or host setting bypasses it; a failed Claude Code
86
+ * check still fails it. A pi failure only decides the run when OpenCode is
87
+ * absent, so a broken ~/.pi never fails a protected OpenCode run.
88
+ */
89
+ export function doctorExitCode(report) {
90
+ const claudeCode = report.claudeCode ?? [];
91
+ const pi = report.pi ?? [];
92
+ if (claudeCode.some((check) => check.state === "fail"))
93
+ return 1;
94
+ // pi checks are supplementary: a broken ~/.pi must not fail an otherwise
95
+ // protected OpenCode run. They decide the run only when OpenCode is absent.
96
+ if (pi.some((check) => check.state === "fail") && report.status === "HOST_MISSING")
97
+ return 1;
98
+ if (report.status === "PROTECTED" || report.status === "PARTIAL")
99
+ return 0;
100
+ if (report.status !== "HOST_MISSING")
101
+ return 1;
102
+ // A bypassing provider or host-managed endpoint means requests may not reach
103
+ // the proxy even though it answers at the configured base URL.
104
+ const bypassed = claudeCode.some((check) => check.id === "claude-code-provider" || check.id === "claude-code-host-managed");
105
+ if (bypassed)
106
+ return 1;
107
+ const claudeCodeProtected = claudeCode.some((check) => check.id === "claude-code-proxy" && check.state === "ok");
108
+ const piProtected = pi.some((check) => check.id === "pi-extension-registered" && (check.state === "ok" || check.state === "warn"))
109
+ && !pi.some((check) => check.state === "fail");
110
+ return claudeCodeProtected || piProtected ? 0 : 1;
111
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * W2 (B5) `forget` — the active erasure lever for persisted mappings
3
+ * (decision `docs/plans/2026-10-07-persistence-decision-db-over-t2.md` §4:
4
+ * TTL is the passive bound, forget is the explicit one; dispose never
5
+ * erases). Output is content-free: counts and paths only, never originals.
6
+ *
7
+ * Deletion does not decrypt anything, so the store is opened with a throwaway
8
+ * in-memory key: the real key stays wherever the ladder put it (keychain /
9
+ * keyfile). The key itself holds no data and is retained — removing it is
10
+ * unnecessary and would only force regeneration.
11
+ */
12
+ export interface ForgetOptions {
13
+ all: boolean;
14
+ session?: string;
15
+ storePath?: string;
16
+ }
17
+ /** Process exit code. 0 = success/no-op, 1 = store error, 2 = usage error. */
18
+ export declare function runForget(options: ForgetOptions): number;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Plugin options schema — the single source of truth shared by the plugin
3
+ * entry (src/opencode.ts, which keeps a default-only export surface for the
4
+ * host loaders) and the install doctor (src/doctor.ts).
5
+ */
6
+ import { z } from "zod";
7
+ /** Shared with the pi adapter's environment parser so the bounds cannot drift. */
8
+ export declare const PERSISTENCE_TTL_DEFAULT_DAYS = 7;
9
+ export declare const PERSISTENCE_TTL_MAX_DAYS = 3650;
10
+ export declare const PluginOptionsSchema: z.ZodObject<{
11
+ mode: z.ZodEnum<{
12
+ block: "block";
13
+ redact: "redact";
14
+ transparent: "transparent";
15
+ }>;
16
+ configPath: z.ZodOptional<z.ZodString>;
17
+ deidentify: z.ZodDefault<z.ZodBoolean>;
18
+ envQueries: z.ZodDefault<z.ZodBoolean>;
19
+ attachments: z.ZodDefault<z.ZodEnum<{
20
+ allow: "allow";
21
+ block: "block";
22
+ }>>;
23
+ wireProtection: z.ZodOptional<z.ZodBoolean>;
24
+ persistence: z.ZodPrefault<z.ZodPipe<z.ZodCustom<unknown, unknown>, z.ZodObject<{
25
+ enabled: z.ZodDefault<z.ZodBoolean>;
26
+ ttlDays: z.ZodDefault<z.ZodNumber>;
27
+ path: z.ZodOptional<z.ZodString>;
28
+ keyFile: z.ZodDefault<z.ZodBoolean>;
29
+ keyfilePath: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$strip>>>;
31
+ }, z.core.$strip>;
32
+ export type PluginOptions = z.infer<typeof PluginOptionsSchema>;
33
+ /** Fills in the default mode (transparent) when the options omit `mode`. Any
34
+ * other non-object input is returned unchanged so the schema rejects it. */
35
+ export declare function withDefaultMode(input: unknown): unknown;
36
+ /** Validated plugin options for external consumers (doctor, tests). Never
37
+ * throws; returns the combined zod/refine error message on failure. */
38
+ export type PluginOptionsValidation = {
39
+ ok: true;
40
+ options: PluginOptions;
41
+ } | {
42
+ ok: false;
43
+ error: string;
44
+ };
45
+ export declare function validatePluginOptions(input: unknown): PluginOptionsValidation;
@@ -5,6 +5,9 @@
5
5
  */
6
6
  import { z } from "zod";
7
7
  import { plainObject } from "./config/plain-object.js";
8
+ /** Shared with the pi adapter's environment parser so the bounds cannot drift. */
9
+ export const PERSISTENCE_TTL_DEFAULT_DAYS = 7;
10
+ export const PERSISTENCE_TTL_MAX_DAYS = 3650;
8
11
  // deidentify is valid only in redact mode; an invalid combination
9
12
  // makes the parse throw, and every entry path already fails closed on that.
10
13
  // transparent is the reversible pseudonymization mode (issue #22):
@@ -48,7 +51,7 @@ export const PluginOptionsSchema = z
48
51
  persistence: plainObject(z.object({
49
52
  enabled: z.boolean().default(false),
50
53
  /** Session TTL in days; 0 = never expire (manual forget only). */
51
- ttlDays: z.number().int().min(0).max(3650).default(7),
54
+ ttlDays: z.number().int().min(0).max(PERSISTENCE_TTL_MAX_DAYS).default(PERSISTENCE_TTL_DEFAULT_DAYS),
52
55
  /** Store path. Default: ~/.local/share/leakshield/SGP.db */
53
56
  path: z.string().min(1).optional(),
54
57
  /** Opt-in weaker fallback when no OS keychain is available. */
package/dist/help.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const HELP_TEXT = "leakshield \u2014 scan text for secrets and PII before sending it to AI\n\nUsage:\n leakshield [--cli] [scan options] Scan text, a file, a directory or stdin\n leakshield --web [--port <n>] Start the local Web UI (default port 3000)\n leakshield --doctor [host] Check one host (opencode, claude-code, pi) or all;\n use --doctor pi, not pi --doctor\n leakshield --doctor=<host> Same target, inline form\n leakshield --claude-code-proxy Start the local proxy for Claude Code (see below)\n leakshield --forget --all Delete all persisted transparent-mode mappings\n leakshield --forget --session <id> Delete persisted mappings for one session\n leakshield --help Show this help\n\nScan input (stdin is read when none is given):\n --text <text> Scan the given text\n --file <path> Scan a single file\n --dir <path> Scan a directory recursively\n --ext <.ext ...> With --dir, only scan these extensions\n --stdin Read text from stdin\n --allow-outside Allow --file/--dir paths outside the working directory\n\nScan options:\n --format json JSON output (CI/CD friendly)\n --min-severity <level> Only report high, medium or low and above (default: low)\n --enable-encoding-detection Also decode Base64/hex/URL-encoded content before scanning\n\nRedaction:\n --redact Replace findings with [REDACTED_TYPE] and print to stdout\n --redact --out <path> Write the redacted text to a file\n --redact --dry-run Report what would be redacted without writing output\n\nClaude Code proxy options (then set ANTHROPIC_BASE_URL=http://127.0.0.1:<port>):\n --port <n> Listen port on 127.0.0.1 (default 8787)\n --upstream <url> Anthropic API base URL (default https://api.anthropic.com)\n --config <path> LeakShield config file (default: discovered from the working directory)\n --attachments block|allow Refuse (default) or pass images/documents through unscanned\n\npi (the LeakShield extension runs inside pi; see docs/pi.md):\n Register node_modules/leakshield/dist/adapters/pi/extension.js as the first entry of\n pi settings.extensions, or start pi with -e <path>. Check it with\n leakshield --doctor pi; LEAKSHIELD_CONFIG selects the guard config file.\n\nForget options:\n --path <file> Mapping store location (default: ~/.local/share/leakshield/SGP.db)\n\nExit codes: 0 = safe, 1 = findings detected, 2 = file not found\n";
2
+ export declare function isHelpRequest(args: readonly string[]): boolean;
package/dist/help.js CHANGED
@@ -4,7 +4,10 @@ export const HELP_TEXT = `leakshield — scan text for secrets and PII before se
4
4
  Usage:
5
5
  leakshield [--cli] [scan options] Scan text, a file, a directory or stdin
6
6
  leakshield --web [--port <n>] Start the local Web UI (default port 3000)
7
- leakshield --doctor Check the OpenCode plugin installation
7
+ leakshield --doctor [host] Check one host (opencode, claude-code, pi) or all;
8
+ use --doctor pi, not pi --doctor
9
+ leakshield --doctor=<host> Same target, inline form
10
+ leakshield --claude-code-proxy Start the local proxy for Claude Code (see below)
8
11
  leakshield --forget --all Delete all persisted transparent-mode mappings
9
12
  leakshield --forget --session <id> Delete persisted mappings for one session
10
13
  leakshield --help Show this help
@@ -27,6 +30,17 @@ Redaction:
27
30
  --redact --out <path> Write the redacted text to a file
28
31
  --redact --dry-run Report what would be redacted without writing output
29
32
 
33
+ Claude Code proxy options (then set ANTHROPIC_BASE_URL=http://127.0.0.1:<port>):
34
+ --port <n> Listen port on 127.0.0.1 (default 8787)
35
+ --upstream <url> Anthropic API base URL (default https://api.anthropic.com)
36
+ --config <path> LeakShield config file (default: discovered from the working directory)
37
+ --attachments block|allow Refuse (default) or pass images/documents through unscanned
38
+
39
+ pi (the LeakShield extension runs inside pi; see docs/pi.md):
40
+ Register node_modules/leakshield/dist/adapters/pi/extension.js as the first entry of
41
+ pi settings.extensions, or start pi with -e <path>. Check it with
42
+ leakshield --doctor pi; LEAKSHIELD_CONFIG selects the guard config file.
43
+
30
44
  Forget options:
31
45
  --path <file> Mapping store location (default: ~/.local/share/leakshield/SGP.db)
32
46
 
@@ -0,0 +1,65 @@
1
+ export declare const en: {
2
+ "scan.safe_summary": string;
3
+ "scan.unsafe_summary": string;
4
+ "scan.safe_recommendation": string;
5
+ "scan.unsafe_recommendation": string;
6
+ "scan.warning_encoded": string;
7
+ "scan.warning_truncated": string;
8
+ "scan.warning_zero_width": string;
9
+ "scan.warning_suspicious_unicode": string;
10
+ "redact.safe_summary": string;
11
+ "redact.unsafe_summary": string;
12
+ "cli.scan_target": string;
13
+ "cli.hits": string;
14
+ "cli.location": string;
15
+ "cli.preview": string;
16
+ "cli.more_of_type": string;
17
+ "cli.error_file_not_found": string;
18
+ "cli.error_dir_not_found": string;
19
+ "cli.error_redact_no_input": string;
20
+ "cli.error_path": string;
21
+ "cli.dryrun_header": string;
22
+ "cli.dryrun_safe": string;
23
+ "cli.dryrun_location": string;
24
+ "cli.dryrun_preview": string;
25
+ "cli.redact_written": string;
26
+ "cli.redact_footer": string;
27
+ "cli.redact_incomplete": string;
28
+ "cli.redact_verified": string;
29
+ "cli.scan_dir": string;
30
+ "cli.ext_filter": string;
31
+ "cli.found_files": string;
32
+ "cli.skipped_files": string;
33
+ "cli.dir_complete": string;
34
+ "cli.inline_label": string;
35
+ "cli.decision_warn_header": string;
36
+ "cli.decision_confirm_header": string;
37
+ "cli.confirm_next_step": string;
38
+ "cli.usage_title": string;
39
+ "cli.usage_heading": string;
40
+ "cli.usage_text": string;
41
+ "cli.usage_file": string;
42
+ "cli.usage_dir": string;
43
+ "cli.usage_dir_ext": string;
44
+ "cli.usage_stdin": string;
45
+ "cli.usage_web": string;
46
+ "cli.usage_redact_heading": string;
47
+ "cli.usage_redact_text": string;
48
+ "cli.usage_redact_file": string;
49
+ "cli.usage_redact_out": string;
50
+ "cli.usage_redact_stdin": string;
51
+ "cli.usage_redact_dryrun": string;
52
+ "cli.usage_options_heading": string;
53
+ "cli.usage_opt_format": string;
54
+ "cli.usage_opt_severity": string;
55
+ "cli.usage_opt_redact": string;
56
+ "cli.usage_opt_dryrun": string;
57
+ "cli.usage_opt_out": string;
58
+ "cli.usage_opt_outside": string;
59
+ "cli.usage_opt_web": string;
60
+ "cli.usage_opt_port": string;
61
+ "cli.usage_opt_encoding": string;
62
+ "web.server_title": string;
63
+ "web.server_url": string;
64
+ "web.server_stop": string;
65
+ };
@@ -0,0 +1,15 @@
1
+ import { en } from "./en.js";
2
+ type Messages = typeof en;
3
+ type MessageKey = keyof Messages;
4
+ declare const SUPPORTED_LOCALES: readonly ["en", "zh-TW"];
5
+ type Locale = (typeof SUPPORTED_LOCALES)[number];
6
+ declare const locale: Locale;
7
+ /**
8
+ * Translate a message key, interpolating `{param}` placeholders.
9
+ *
10
+ * @example
11
+ * t("scan.safe_summary")
12
+ * t("cli.found_files", { count: 12 })
13
+ */
14
+ export declare function t(key: MessageKey, params?: Record<string, string | number>): string;
15
+ export { locale };