codiedev 0.9.89 → 0.9.91
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/dist/captureLog.d.ts +1 -1
- package/dist/codie.js +56 -4
- package/dist/codieLauncher.d.ts +3 -0
- package/dist/codieLauncher.js +16 -1
- package/dist/hook.js +52 -0
- package/dist/launchContext.d.ts +27 -0
- package/dist/launchContext.js +79 -0
- package/dist/promptGuard.d.ts +63 -0
- package/dist/promptGuard.js +261 -0
- package/dist/scrub/promptRules.d.ts +119 -0
- package/dist/scrub/promptRules.js +941 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +48 -9
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export interface Redaction {
|
|
2
|
+
rule: string;
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ScrubResult {
|
|
7
|
+
text: string;
|
|
8
|
+
redactions: Redaction[];
|
|
9
|
+
}
|
|
10
|
+
/** Rules a caller adds for one scrub (a company's own token formats). */
|
|
11
|
+
export interface ExtraRule {
|
|
12
|
+
name: string;
|
|
13
|
+
re: RegExp;
|
|
14
|
+
keywords?: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/** Shannon entropy in bits per character, as Gitleaks measures it. */
|
|
17
|
+
export declare function shannonEntropy(s: string): number;
|
|
18
|
+
export declare function scrubSecrets(input: string, opts?: {
|
|
19
|
+
extraRules?: readonly ExtraRule[];
|
|
20
|
+
}): ScrubResult;
|
|
21
|
+
/** Rewrite `input` with each span replaced by `[REDACTED:<rule>]`. Spans must
|
|
22
|
+
* be sorted by start and not overlap. One forward pass: repeated
|
|
23
|
+
* slice+concat would copy the whole string per redaction (quadratic). */
|
|
24
|
+
export declare function redactSpans(input: string, spans: readonly Redaction[]): string;
|
|
25
|
+
/** Where in a session a secret appeared. "typed" is a short message the
|
|
26
|
+
* person wrote; "pasted" is a long one (a log, config or JSON dump pasted in);
|
|
27
|
+
* "attached" is text the harness added to the person's turn (an @-mentioned
|
|
28
|
+
* file, a resumed session's summary). Older rows say "prompt" for all three. */
|
|
29
|
+
export type SecretWhere = "typed" | "pasted" | "attached" | "prompt" | "tool_call" | "commit" | "tool_output" | "assistant" | "unknown";
|
|
30
|
+
export interface SecretLocation {
|
|
31
|
+
where: SecretWhere;
|
|
32
|
+
/** Tool or MCP tool name for tool calls/outputs when the transcript has it. */
|
|
33
|
+
tool?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface SecretFinding {
|
|
36
|
+
rule: string;
|
|
37
|
+
/** Last four alphanumeric characters of the redacted value — enough for a
|
|
38
|
+
* person to recognise which key to rotate, never enough to use it. */
|
|
39
|
+
hint: string;
|
|
40
|
+
/** Distinct places in the session the key appeared. */
|
|
41
|
+
locations: SecretLocation[];
|
|
42
|
+
/** The variable or field it was assigned to (`X_BEARER_TOKEN`), when the
|
|
43
|
+
* text shows one. A name, never the value. */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** The file it was written to or read from (`altcap-bot/.env`), when the
|
|
46
|
+
* text shows one: last two path parts only. */
|
|
47
|
+
file?: string;
|
|
48
|
+
}
|
|
49
|
+
/** What a caller may check before a key becomes a finding (exceptions).
|
|
50
|
+
* `value` is the key itself: use it to compare, never store it. */
|
|
51
|
+
export interface KeyContext {
|
|
52
|
+
rule: string;
|
|
53
|
+
value: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
file?: string;
|
|
56
|
+
}
|
|
57
|
+
export declare const GENERIC_RULES: ReadonlySet<string>;
|
|
58
|
+
/** Values that share a key's shape but are test or sample values: words
|
|
59
|
+
* joined by _ or - with only digits or one repeated character between
|
|
60
|
+
* (`cdv_local_pilot_token_2026`, `…_token_000000`), a long counting run
|
|
61
|
+
* (`sk-1234567890…`), or a long repeated tail. Still removed from sessions;
|
|
62
|
+
* just not listed as a key to rotate. */
|
|
63
|
+
export declare function looksLikeTestValue(value: string): boolean;
|
|
64
|
+
export declare const isTestFile: (file: string) => boolean;
|
|
65
|
+
/** Where in one transcript line (a JSONL record) some text appeared, and the
|
|
66
|
+
* file that line reads or writes, if it names one. For any detector that
|
|
67
|
+
* works line by line (PHI/PII). `text` is the matched text as it reads
|
|
68
|
+
* after JSON unescaping. */
|
|
69
|
+
export declare function locateInLine(line: string, text: string): SecretLocation & {
|
|
70
|
+
file?: string;
|
|
71
|
+
};
|
|
72
|
+
/** Where each `[REDACTED:<rule>]` marker sits in an already-scrubbed
|
|
73
|
+
* transcript. Re-labels older findings that predate typed/pasted/attached. */
|
|
74
|
+
export declare function locateMarkers(scrubbed: string, rule: string): SecretLocation[];
|
|
75
|
+
/** Rules that match a shape (a secret-named variable, a header, a URL, a PEM
|
|
76
|
+
* block) rather than a provider's own key format. */
|
|
77
|
+
export declare const SHAPE_RULES: ReadonlySet<string>;
|
|
78
|
+
/** The name or location of a secret, or a value built from words, rather
|
|
79
|
+
* than a random key: an ARN, a secret-store path, or a value whose letters
|
|
80
|
+
* are mostly whole words (`mobile-data/client2`, `bracecomb-hc-service`,
|
|
81
|
+
* `mobileDataClientV2`). A random key does not break into words, whatever
|
|
82
|
+
* separators it has: under 1% of random 16-character keys pass this, and
|
|
83
|
+
* next to none at 24 or more. */
|
|
84
|
+
export declare function namesASecret(v: string): boolean;
|
|
85
|
+
/** True when a redacted value should not be listed as a key to rotate: a
|
|
86
|
+
* placeholder, a sample or test value, a reference to a variable, or a
|
|
87
|
+
* credential that expires by itself. `now` is injectable for tests. */
|
|
88
|
+
export declare function notWorthRotating(k: KeyContext, now?: number): boolean;
|
|
89
|
+
/** Last four letters or digits of a value. A PEM block ends in a fixed
|
|
90
|
+
* footer, and in a transcript its line breaks are a literal `\n`: the hint
|
|
91
|
+
* comes from the key body, without either. */
|
|
92
|
+
export declare function hintOf(rule: string, value: string): string;
|
|
93
|
+
/** One finding per distinct (rule, last-4) in a scrub result, with every
|
|
94
|
+
* distinct place it appeared. */
|
|
95
|
+
export declare function secretFindings(input: string, redactions: Redaction[], opts?: {
|
|
96
|
+
skip?: (k: KeyContext) => boolean;
|
|
97
|
+
now?: number;
|
|
98
|
+
}): SecretFinding[];
|
|
99
|
+
export interface PossibleSecret {
|
|
100
|
+
label: string;
|
|
101
|
+
prefix?: string;
|
|
102
|
+
hint: string;
|
|
103
|
+
length: number;
|
|
104
|
+
shape: "hex" | "base64" | "alnum";
|
|
105
|
+
snippet: string;
|
|
106
|
+
locations: SecretLocation[];
|
|
107
|
+
/** Spans in the text this was read from, for redaction once confirmed. */
|
|
108
|
+
spans: Array<{
|
|
109
|
+
start: number;
|
|
110
|
+
end: number;
|
|
111
|
+
}>;
|
|
112
|
+
}
|
|
113
|
+
export declare function possibleSecrets(text: string, limit?: number): PossibleSecret[];
|
|
114
|
+
/** Redact every occurrence of an already-reviewed possible secret. */
|
|
115
|
+
export declare function redactPossible(text: string, match: {
|
|
116
|
+
label: string;
|
|
117
|
+
hint: string;
|
|
118
|
+
length: number;
|
|
119
|
+
}, rule?: string): ScrubResult;
|