@fatelabs/opencode-estelle 0.0.0-stage → 0.0.18
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 +201 -0
- package/NOTICE +6 -0
- package/README.md +46 -2
- package/adapters/claude.mjs +17 -0
- package/adapters/codex.mjs +85 -0
- package/adapters/cursor.mjs +66 -0
- package/adapters/dsh-host.mjs +181 -0
- package/adapters/dsh-plugin.mjs +11 -0
- package/adapters/dsh.mjs +54 -0
- package/adapters/grok.mjs +63 -0
- package/adapters/host-bridge.mjs +85 -0
- package/adapters/kimi.mjs +135 -0
- package/adapters/opencode-mirror.mjs +103 -0
- package/adapters/opencode-plugin.mjs +143 -0
- package/adapters/opencode.mjs +15 -0
- package/adapters/pi-extension.mjs +107 -0
- package/adapters/pi.mjs +13 -0
- package/adapters/plugin-envelope.mjs +56 -0
- package/agents/estelle-grounder.md +34 -0
- package/agents/estelle-historian.md +28 -0
- package/agents/estelle-repair.md +29 -0
- package/agents/estelle-reviewer.md +32 -0
- package/commands/cloud.md +28 -0
- package/commands/code.md +6 -0
- package/commands/handoff.md +25 -0
- package/commands/monitor.md +6 -0
- package/commands/resume.md +6 -0
- package/commands/review.md +6 -0
- package/commands/rooms.md +7 -0
- package/instructions.md +19 -0
- package/package.json +34 -4
- package/runtime/auth.mjs +27 -0
- package/runtime/checkpoint.mjs +208 -0
- package/runtime/claude-setup.mjs +130 -0
- package/runtime/cli.mjs +112 -0
- package/runtime/codex-trust.mjs +68 -0
- package/runtime/credential.mjs +341 -0
- package/runtime/dsh-session.mjs +91 -0
- package/runtime/dsh-telemetry.mjs +31 -0
- package/runtime/hooks.mjs +234 -0
- package/runtime/identity.mjs +20 -0
- package/runtime/io.mjs +155 -0
- package/runtime/key-check.mjs +51 -0
- package/runtime/kimi-history.mjs +163 -0
- package/runtime/mailbox.mjs +46 -0
- package/runtime/migration.mjs +118 -0
- package/runtime/move.mjs +443 -0
- package/runtime/native-export.mjs +204 -0
- package/runtime/native-index.mjs +77 -0
- package/runtime/native-tree.mjs +117 -0
- package/runtime/queued-context.mjs +152 -0
- package/runtime/redact.mjs +74 -0
- package/runtime/reindex.mjs +259 -0
- package/runtime/setup.mjs +174 -0
- package/runtime/stream.mjs +755 -0
- package/runtime/version.mjs +2 -0
- package/runtime/write-warning.mjs +67 -0
- package/skills/abstain-right/SKILL.md +19 -0
- package/skills/api-call-ground/SKILL.md +19 -0
- package/skills/bug-hunt/SKILL.md +20 -0
- package/skills/chain-of-verification/SKILL.md +19 -0
- package/skills/change-impact/SKILL.md +19 -0
- package/skills/coding-workflow/SKILL.md +20 -0
- package/skills/commit-guard/SKILL.md +20 -0
- package/skills/context-checkpoint/SKILL.md +19 -0
- package/skills/continuity-brief/SKILL.md +19 -0
- package/skills/dead-code-sweep/SKILL.md +19 -0
- package/skills/deep-search/SKILL.md +19 -0
- package/skills/diff-review/SKILL.md +19 -0
- package/skills/estelle/SKILL.md +119 -0
- package/skills/estelle-loop/SKILL.md +19 -0
- package/skills/estelle-monitor-install/SKILL.md +20 -0
- package/skills/evidence-traceability-audit/SKILL.md +19 -0
- package/skills/grounded-generate/SKILL.md +19 -0
- package/skills/incident-rca/SKILL.md +20 -0
- package/skills/mutation-test/SKILL.md +19 -0
- package/skills/program-repair/SKILL.md +20 -0
- package/skills/prompt-injection-defense/SKILL.md +19 -0
- package/skills/property-based-test/SKILL.md +19 -0
- package/skills/refactor-rfc/SKILL.md +19 -0
- package/skills/root-cause-loop/SKILL.md +19 -0
- package/skills/test-first/SKILL.md +19 -0
- package/skills/threat-model-stride/SKILL.md +19 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// What counts as a credential in text. One owner, separate from privacy redaction on purpose.
|
|
2
|
+
//
|
|
3
|
+
// redact.mjs hides too much by design: over-hiding a log line costs nothing. What reads this acts on someone's
|
|
4
|
+
// work, so it needs evidence of a VALUE. A NAME that merely sounds secret is not evidence, and ML code is full of them.
|
|
5
|
+
// Two readers, of different strength: `textHasCredential` decides what a handoff leaves behind instead of pushing
|
|
6
|
+
// (move.mjs), and `vendorKindIn` is all the write hook looks at, because it only warns (write-warning.mjs).
|
|
7
|
+
import { VENDOR_PATTERNS } from './redact.mjs';
|
|
8
|
+
|
|
9
|
+
const MIN_LITERAL = 8;
|
|
10
|
+
const MIN_OPAQUE = 20;
|
|
11
|
+
const MIN_HEX = 32;
|
|
12
|
+
const MIN_OPAQUE_SEGMENT = 16;
|
|
13
|
+
const MIN_OPAQUE_DIGITS = 2;
|
|
14
|
+
const MIN_ENTROPY_LENGTH = 24;
|
|
15
|
+
const MIN_ENTROPY_BITS = 4.2;
|
|
16
|
+
const MAX_ENTROPY_SEPARATORS = 2;
|
|
17
|
+
const MAX_VALUE_SCAN = 4096;
|
|
18
|
+
const MAX_EXPRESSION_SCAN = 512;
|
|
19
|
+
const MAX_LINE_LOOKBACK = 64;
|
|
20
|
+
const MAX_LABEL_PART = 128;
|
|
21
|
+
const MAX_TEMPLATE_REMAINDER = 3;
|
|
22
|
+
|
|
23
|
+
// A label is found by its credential word; the words around it decide how much evidence it needs.
|
|
24
|
+
const LABEL = new RegExp(String.raw`(?<![\w$-])[\w$-]{0,${MAX_LABEL_PART}}`
|
|
25
|
+
+ String.raw`(?:secret|token|passw(?:or)?d|passphrase|api[_-]?key|private[_-]?key)[\w$-]{0,${MAX_LABEL_PART}}`, 'gi');
|
|
26
|
+
const CREDENTIAL_WORD = /(?:secrets?|tokens?|passw(?:or)?d|passphrase|apikey|privatekey)$/;
|
|
27
|
+
const COUNT_LIKE_NEIGHBOURS = new Set(['max', 'min', 'num', 'n', 'total', 'input', 'output', 'prompt', 'completion',
|
|
28
|
+
'cached', 'cache', 'reasoning', 'bos', 'eos', 'pad', 'unk', 'sep', 'cls', 'mask', 'start', 'end', 'stop', 'special',
|
|
29
|
+
'next', 'prev', 'previous', 'last', 'first', 'current', 'page', 'continuation', 'lexer', 'parser', 'word', 'char']);
|
|
30
|
+
const DESCRIPTOR_ENDINGS = new Set(['env', 'envvar', 'var', 'variable', 'name', 'names', 'url', 'uri', 'endpoint', 'path',
|
|
31
|
+
'file', 'header', 'field', 'param', 'parameter', 'prefix', 'suffix', 'pattern', 'regex', 'type', 'kind', 'count',
|
|
32
|
+
'counts', 'id', 'ids', 'len', 'length', 'limit', 'budget', 'usage', 'size', 'index', 'idx', 'ttl', 'expiry', 'expires',
|
|
33
|
+
'expiration', 'lifetime', 'timeout', 'scope', 'scopes', 'audience', 'issuer', 'provider', 'manager', 'store', 'policy',
|
|
34
|
+
'label', 'description', 'desc', 'help', 'hint', 'placeholder', 'format', 'digest', 'hash', 'hashed', 'version',
|
|
35
|
+
'revision', 'rev', 'schema', 'class']);
|
|
36
|
+
const CREDENTIAL_PLURAL_PREFIXES = /^(?:auth|access|refresh|bearer|session|api|id|oauth|csrf|jwt)/;
|
|
37
|
+
|
|
38
|
+
const PLACEHOLDER_MARKERS = new Set(['test', 'testing', 'tests', 'example', 'examples', 'sample', 'dummy', 'fake', 'mock',
|
|
39
|
+
'placeholder', 'changeme', 'your', 'foo', 'bar', 'baz', 'qux', 'redacted', 'todo', 'fixture', 'stub', 'invalid',
|
|
40
|
+
'notreal', 'nonexistent']);
|
|
41
|
+
const PLACEHOLDER_WORDS = new Set([...PLACEHOLDER_MARKERS, 'change', 'me', 'my', 'here', 'insert', 'replace', 'put', 'enter',
|
|
42
|
+
'not', 'a', 'an', 'real', 'secret', 'token', 'key', 'api', 'apikey', 'password', 'pass', 'value', 'string', 'client', 'user',
|
|
43
|
+
'auth', 'access', 'the', 'for', 'only', 'local', 'dev', 'unit', 'wrong', 'bad', 'good', 'correct', 'valid', 'expired',
|
|
44
|
+
'revoked', 'none', 'null']);
|
|
45
|
+
const KEYWORD_VALUES = new Set(['required', 'optional', 'redacted', 'disabled', 'enabled', 'hidden', 'masked', 'unknown',
|
|
46
|
+
'provided', 'undefined', 'password', 'username']);
|
|
47
|
+
const PROSE_WORDS = new Set(['the', 'a', 'an', 'is', 'are', 'of', 'for', 'to', 'your', 'not', 'missing', 'invalid', 'enter',
|
|
48
|
+
'please', 'must', 'be', 'required', 'provide', 'set', 'no', 'with', 'and', 'or', 'in', 'this', 'that', 'can', 'cannot',
|
|
49
|
+
'failed', 'expired', 'use', 'using', 'used']);
|
|
50
|
+
// The two example keys AWS prints in its own documentation; nothing else with this shape is waived.
|
|
51
|
+
const EXACT_VENDOR_EXAMPLES = new Set(['AKIA', 'ASIA'].map(prefix => `${prefix}IOSFODNN7EXAMPLE`));
|
|
52
|
+
const STORE_REFERENCE = /^(?:process\.env|import\.meta\.env|os\.environ|os\.getenv|getenv\b|System\.getenv|ENV\[|env\[|Deno\.env|std::env|env::var|secrets\.|vault\.)/;
|
|
53
|
+
const TEMPLATES = /\$\{\{[^}]*\}\}|\$\{[^}]*\}|\$\([^)]*\)|\{\{[^}]*\}\}|\$[A-Za-z_]\w*|%\([^)]*\)[sd]|%[A-Za-z_]\w*%|%[sd]|\{[A-Za-z_][\w.]*\}|<[^<>\n]*>|\[[A-Za-z_][\w -]*\]/g;
|
|
54
|
+
const STORE_LOCATOR = /^(?:op|vault|ssm|secretsmanager|gcp-secret|azure-keyvault|ref\+[a-z]+):|^arn:aws:(?:secretsmanager|ssm):|^ENC\[/;
|
|
55
|
+
const ENV_NAME = /^[A-Z][A-Z0-9_]*_?(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|PASSPHRASE)$/;
|
|
56
|
+
const EMPTY_PEM = /-----BEGIN ([A-Z ]*PRIVATE KEY)-----((?:\s|\\+[rn])*)(?:-----END \1-----)?/g;
|
|
57
|
+
const SOURCE_END = /^(?:\\*["'`]|\/[gimsuy]*)(?:\s|\\+[rn])*(?:[,;)}\]]|$)/;
|
|
58
|
+
const BEARER = /\bBearer\s+([A-Za-z0-9._~+/-]{8,}=*)/gi;
|
|
59
|
+
const NAMED_HEX = /\bsession[_-]token\s+is\s+["'`]?[a-f0-9]{32,128}/i;
|
|
60
|
+
// Any scheme with a userinfo password. The vendor list only knows one database scheme.
|
|
61
|
+
const URL_USERINFO = /\b[a-z][a-z0-9+.-]{1,20}:\/\/[^\s:@/'"`]{0,128}:([^\s@/'"`]{3,256})@/gi;
|
|
62
|
+
const PORT_ONLY = /^\d{1,5}$/;
|
|
63
|
+
const COMMON_URL_WORDS = /^(?:password|pass|postgres|secret)$/i;
|
|
64
|
+
const YAML_LINE_START = /^[+\- \t]*$/;
|
|
65
|
+
const YAML_LINE_END = /[ \t]*(?:#[^\n]*)?(?:\r?\n|$)/y;
|
|
66
|
+
const CLOSES_OBJECT = /\s*[}\])]/y;
|
|
67
|
+
const CONTAINS_CREDENTIAL_WORD = /secret|token|passw|passphrase|key/;
|
|
68
|
+
const QUOTED_VALUE_ON_NEXT_LINE = /\s*/y;
|
|
69
|
+
const SAME_LINE_GAP = /[ \t]*/y;
|
|
70
|
+
const OPERATOR = /\\*["'`]?\s*(:=|=>|=(?![=~])|:(?!:))/y;
|
|
71
|
+
const QUOTE_OPEN = /([frbuFRBU]{0,2})(\\*)(["'`])/y;
|
|
72
|
+
const BARE_VALUE = /[^\s,;)}\]"'`]{1,512}/y;
|
|
73
|
+
// A type hint can sit between the name and the value, in Python and TypeScript annotations alike.
|
|
74
|
+
const TYPE_THEN_ASSIGN = /[A-Za-z_][\w.]*(?:\[[^\]\n]{0,128}\])?(?:\s*\|\s*[A-Za-z_][\w.]*(?:\[[^\]\n]{0,64}\])?){0,4}\??\s*=(?![=~>])[ \t]*/y;
|
|
75
|
+
const TYPE_NAME = /^[A-Z][\w.]*(?:\[.*)?$|^(?:str|string|bytes|int|bool|number|any|object|None|null|undefined)(?:\[.*)?\??$/;
|
|
76
|
+
const REGEX_LITERAL = /^\/(?=[^/]*[|^$*+?\\])[^/\n]+\/[dgimsuvy]*$/;
|
|
77
|
+
|
|
78
|
+
const matchAt = (pattern, text, index) => { pattern.lastIndex = index; return pattern.exec(text); };
|
|
79
|
+
const wordsOf = label => label.replace(/([a-z0-9])([A-Z])/g, '$1_$2').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
|
80
|
+
.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
81
|
+
|
|
82
|
+
function joinTwoPartNames(words) {
|
|
83
|
+
const joined = [];
|
|
84
|
+
for (let i = 0; i < words.length; i++) {
|
|
85
|
+
const pair = `${words[i]}${words[i + 1] ?? ''}`;
|
|
86
|
+
if (pair === 'apikey' || pair === 'privatekey') { joined.push(pair); i++; } else joined.push(words[i]);
|
|
87
|
+
}
|
|
88
|
+
return joined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 'none' never refuses on its own; 'weak' needs an opaque value; 'strong' refuses any real-looking literal. */
|
|
92
|
+
export function labelStrength(label) {
|
|
93
|
+
const words = joinTwoPartNames(wordsOf(label));
|
|
94
|
+
const at = words.findIndex(word => CREDENTIAL_WORD.test(word));
|
|
95
|
+
if (at < 0) return 'none';
|
|
96
|
+
const word = words[at];
|
|
97
|
+
if (DESCRIPTOR_ENDINGS.has(words.at(-1)) && words.length > 1) return 'weak';
|
|
98
|
+
if (!word.endsWith('tokens') && !/token$/.test(word)) return 'strong';
|
|
99
|
+
const before = words[at - 1];
|
|
100
|
+
if (word.endsWith('tokens')) {
|
|
101
|
+
const authPrefix = CREDENTIAL_PLURAL_PREFIXES.test(before ?? '') || CREDENTIAL_PLURAL_PREFIXES.test(word.replace(/tokens$/, ''));
|
|
102
|
+
return authPrefix ? 'strong' : 'weak';
|
|
103
|
+
}
|
|
104
|
+
return COUNT_LIKE_NEIGHBOURS.has(before) ? 'weak' : 'strong';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function shannonBits(text) {
|
|
108
|
+
const counts = new Map();
|
|
109
|
+
for (const char of text) counts.set(char, (counts.get(char) ?? 0) + 1);
|
|
110
|
+
let bits = 0;
|
|
111
|
+
for (const count of counts.values()) { const p = count / text.length; bits -= p * Math.log2(p); }
|
|
112
|
+
return bits;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Random-looking: the shape of a generated value rather than of a name, path, URL or sentence. */
|
|
116
|
+
export function isOpaque(value) {
|
|
117
|
+
if (value.length < MIN_OPAQUE || /:\/\//.test(value) || !/^[\w\-./:=+~]+$/.test(value)) return false;
|
|
118
|
+
const hex = new RegExp(`^[a-fA-F0-9]{${MIN_HEX},}$`);
|
|
119
|
+
if (hex.test(value)) return true;
|
|
120
|
+
const segments = value.split(/[-_./:=+]/);
|
|
121
|
+
for (const segment of segments) {
|
|
122
|
+
if (hex.test(segment)) return true;
|
|
123
|
+
const digits = segment.replace(/\D/g, '').length;
|
|
124
|
+
if (segment.length >= MIN_OPAQUE_SEGMENT && digits >= MIN_OPAQUE_DIGITS && digits < segment.length) return true;
|
|
125
|
+
}
|
|
126
|
+
return value.length >= MIN_ENTROPY_LENGTH && segments.length - 1 <= MAX_ENTROPY_SEPARATORS
|
|
127
|
+
&& shannonBits(value) >= MIN_ENTROPY_BITS;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const isTemplate = body => STORE_LOCATOR.test(body) || body.replace(TEMPLATES, '').trim().length <= MAX_TEMPLATE_REMAINDER;
|
|
131
|
+
const isRepeatedMask = body => /^(.)\1*$/.test(body) && /^[xX*.\-#•]/.test(body);
|
|
132
|
+
|
|
133
|
+
function isPlaceholder(body) {
|
|
134
|
+
if (isRepeatedMask(body)) return true;
|
|
135
|
+
const words = body.toLowerCase().split(/[^a-z0-9]+/).flatMap(word => word.split(/(?<=[a-z])(?=\d)|(?<=\d)(?=[a-z])/)).filter(Boolean);
|
|
136
|
+
if (!words.length) return false;
|
|
137
|
+
let marked = false;
|
|
138
|
+
for (const word of words) {
|
|
139
|
+
if (/^\d{1,4}$/.test(word) || /^x{3,}$/.test(word)) continue;
|
|
140
|
+
const glued = [...PLACEHOLDER_MARKERS].find(marker => word.startsWith(marker) && PLACEHOLDER_WORDS.has(word.slice(marker.length)));
|
|
141
|
+
if (PLACEHOLDER_MARKERS.has(word) || glued) { marked = true; continue; }
|
|
142
|
+
if (!PLACEHOLDER_WORDS.has(word)) return false;
|
|
143
|
+
}
|
|
144
|
+
return marked;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function isProse(body) {
|
|
148
|
+
const words = body.trim().split(/\s+/);
|
|
149
|
+
if (words.length < 2 || !words.every(word => /^[A-Za-z][A-Za-z'-]*[.,:;!?)]?$/.test(word))) return false;
|
|
150
|
+
return words.some(word => PROSE_WORDS.has(word.toLowerCase().replace(/[.,:;!?)]$/, '')));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Does this literal, assigned to a label of this strength, hold a credential? */
|
|
154
|
+
function literalIsCredential(body, strength) {
|
|
155
|
+
if (strength === 'none' || isTemplate(body) || isPlaceholder(body)) return false;
|
|
156
|
+
if (strength === 'weak') return isOpaque(body);
|
|
157
|
+
if (body.length < MIN_LITERAL || KEYWORD_VALUES.has(body.toLowerCase())) return false;
|
|
158
|
+
return !isProse(body) && !ENV_NAME.test(body);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function closingQuote(text, from, quote, escapes) {
|
|
162
|
+
const end = Math.min(text.length, from + MAX_VALUE_SCAN);
|
|
163
|
+
for (let i = from; i < end; i++) {
|
|
164
|
+
const char = text[i];
|
|
165
|
+
if (char === '\n' && quote !== '`') return i;
|
|
166
|
+
if (char === '\\' && escapes === 0) { i++; continue; }
|
|
167
|
+
if (char !== quote) continue;
|
|
168
|
+
if (escapes === 0) return i;
|
|
169
|
+
let run = 0;
|
|
170
|
+
while (run <= escapes && text[i - run - 1] === '\\') run++;
|
|
171
|
+
if (run >= escapes) return i - escapes;
|
|
172
|
+
}
|
|
173
|
+
return end;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function readValue(text, start) {
|
|
177
|
+
const open = matchAt(QUOTE_OPEN, text, start);
|
|
178
|
+
if (open) {
|
|
179
|
+
const from = start + open[0].length;
|
|
180
|
+
const close = closingQuote(text, from, open[3], open[2].length);
|
|
181
|
+
return { quoted: true, body: text.slice(from, close), after: close + open[2].length + 1 };
|
|
182
|
+
}
|
|
183
|
+
const bare = matchAt(BARE_VALUE, text, start);
|
|
184
|
+
return { quoted: false, body: bare ? bare[0] : '', after: start + (bare ? bare[0].length : 0) };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Walk the rest of one expression: a reference followed by an opaque literal is still a literal. */
|
|
188
|
+
function expressionHoldsOpaqueLiteral(text, from) {
|
|
189
|
+
let depth = 0;
|
|
190
|
+
const end = Math.min(text.length, from + MAX_EXPRESSION_SCAN);
|
|
191
|
+
for (let i = from; i < end; i++) {
|
|
192
|
+
const char = text[i];
|
|
193
|
+
if (char === '\n' || (depth === 0 && (char === ',' || char === ';'))) return false;
|
|
194
|
+
if ('([{'.includes(char)) depth++;
|
|
195
|
+
if (')]}'.includes(char) && --depth < 0) return false;
|
|
196
|
+
if (!'"\'`'.includes(char)) continue;
|
|
197
|
+
const close = closingQuote(text, i + 1, char, 0);
|
|
198
|
+
const body = text.slice(i + 1, close);
|
|
199
|
+
if (isOpaque(body) && !isTemplate(body) && !isPlaceholder(body) && !ENV_NAME.test(body)) return true;
|
|
200
|
+
i = close;
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** An all-caps name assigned with no spaces at the start of a line, or a long command-line flag:
|
|
206
|
+
* an env file or shell line, where a bare value cannot be a variable. */
|
|
207
|
+
function isDeclarationForm(text, label, labelStart, operatorText) {
|
|
208
|
+
if (operatorText !== '=') return false;
|
|
209
|
+
if (label.startsWith('--')) return true;
|
|
210
|
+
if (label !== label.toUpperCase() || !/[A-Z]/.test(label)) return false;
|
|
211
|
+
const prefix = lineBefore(text, labelStart);
|
|
212
|
+
return prefix !== null && /^[+\- \t]*(?:export[ \t]+|set[ \t]+)?$/.test(prefix);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** What precedes a position on its line, or null when that line is longer than the lookback. */
|
|
216
|
+
function lineBefore(text, position) {
|
|
217
|
+
const before = text.slice(Math.max(0, position - MAX_LINE_LOOKBACK), position);
|
|
218
|
+
const newline = before.lastIndexOf('\n');
|
|
219
|
+
if (newline < 0 && position > before.length) return null;
|
|
220
|
+
return before.slice(newline + 1);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** A key and one lowercase word alone on a line: YAML's unquoted string. Anything that could be a
|
|
224
|
+
* variable (punctuation, a trailing comma, the last property of an object) stays a reference. */
|
|
225
|
+
function isLoneYamlWord(text, labelStart, value) {
|
|
226
|
+
const { body } = value;
|
|
227
|
+
if (!/^[a-z]+$/.test(body) || body.length < MIN_LITERAL) return false;
|
|
228
|
+
if (KEYWORD_VALUES.has(body) || CONTAINS_CREDENTIAL_WORD.test(body) || isPlaceholder(body)) return false;
|
|
229
|
+
const prefix = lineBefore(text, labelStart);
|
|
230
|
+
if (prefix === null || !YAML_LINE_START.test(prefix)) return false;
|
|
231
|
+
const end = matchAt(YAML_LINE_END, text, value.after);
|
|
232
|
+
if (!end) return false;
|
|
233
|
+
if (matchAt(CLOSES_OBJECT, text, end.index + end[0].length)) return false;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Source, not a value: at least two lowercase words joined by `_`, one of them all letters, none with more than two digits.
|
|
238
|
+
* This stops catching a human password written bare in that shape, such as `hunter2_summer`. Quoted, or on an env-file line, it is still refused. */
|
|
239
|
+
function isSnakeIdentifier(body) {
|
|
240
|
+
if (!/^[a-z_$][a-z0-9_$]*$/.test(body)) return false;
|
|
241
|
+
const segments = body.split('_').filter(Boolean);
|
|
242
|
+
if (segments.length < 2 || !segments.some(segment => /^[a-z]{3,}$/.test(segment))) return false;
|
|
243
|
+
return segments.every(segment => segment.replace(/\D/g, '').length <= MIN_OPAQUE_DIGITS);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function bareLiteralIsCredential(body, strength) {
|
|
247
|
+
if (/^\d+$/.test(body)) return strength === 'strong' && body.length >= MIN_LITERAL;
|
|
248
|
+
if (isOpaque(body)) return !isTemplate(body) && !isPlaceholder(body) && !ENV_NAME.test(body);
|
|
249
|
+
if (strength !== 'strong' || body.length < MIN_LITERAL || /[()[\]{}."'`]/.test(body)) return false;
|
|
250
|
+
// A regex with an operator in it describes values. An opaque one between slashes was already refused above.
|
|
251
|
+
if (REGEX_LITERAL.test(body) || isSnakeIdentifier(body)) return false;
|
|
252
|
+
return /\d/.test(body) && /[A-Za-z]/.test(body) && !isPlaceholder(body);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function assignmentIsCredential(text, label, labelStart, labelEnd) {
|
|
256
|
+
const strength = labelStrength(label);
|
|
257
|
+
if (strength === 'none') return false;
|
|
258
|
+
const operator = matchAt(OPERATOR, text, labelEnd);
|
|
259
|
+
if (!operator) return false;
|
|
260
|
+
// A segment of a colon-separated path, as in a cloud resource name, is not a name being assigned.
|
|
261
|
+
if (operator[1] === ':' && text[labelStart - 1] === ':') return false;
|
|
262
|
+
const labelQuoted = /["'`]/.test(operator[0]);
|
|
263
|
+
const start = operator.index + operator[0].length;
|
|
264
|
+
const gap = matchAt(labelQuoted ? QUOTED_VALUE_ON_NEXT_LINE : SAME_LINE_GAP, text, start);
|
|
265
|
+
const valueStart = start + gap[0].length;
|
|
266
|
+
const value = readValue(text, valueStart);
|
|
267
|
+
if (value.quoted) return literalIsCredential(value.body, strength) || expressionHoldsOpaqueLiteral(text, value.after);
|
|
268
|
+
if (!value.body) return false;
|
|
269
|
+
if (operator[1] === ':' && TYPE_NAME.test(value.body) && !isOpaque(value.body) && !/(?:\D*\d){3}/.test(value.body)) {
|
|
270
|
+
const typed = matchAt(TYPE_THEN_ASSIGN, text, valueStart);
|
|
271
|
+
if (!typed) return false;
|
|
272
|
+
const assignedStart = valueStart + typed[0].length;
|
|
273
|
+
const assigned = readValue(text, assignedStart);
|
|
274
|
+
const direct = assigned.quoted ? literalIsCredential(assigned.body, strength) : bareLiteralIsCredential(assigned.body, strength);
|
|
275
|
+
return direct || expressionHoldsOpaqueLiteral(text, assignedStart);
|
|
276
|
+
}
|
|
277
|
+
if (operator[1] === ':' && strength === 'strong' && !labelQuoted && isLoneYamlWord(text, labelStart, value)) return true;
|
|
278
|
+
const reference = STORE_REFERENCE.test(value.body) || /^[$%]/.test(value.body);
|
|
279
|
+
if (!reference && strength === 'strong' && gap[0] === '' && isDeclarationForm(text, label, labelStart, operator[0])) {
|
|
280
|
+
return value.body.length >= MIN_LITERAL && !isTemplate(value.body) && !isPlaceholder(value.body);
|
|
281
|
+
}
|
|
282
|
+
if (!reference && bareLiteralIsCredential(value.body, strength)) return true;
|
|
283
|
+
return expressionHoldsOpaqueLiteral(text, valueStart);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function urlPasswordIsReal(value) {
|
|
287
|
+
return !(isTemplate(value) || isPlaceholder(value) || COMMON_URL_WORDS.test(value) || PORT_ONLY.test(value));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function urlCredential(text) {
|
|
291
|
+
for (const match of text.matchAll(URL_USERINFO)) if (urlPasswordIsReal(match[1])) return true;
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function vendorMatchIsReal(match) {
|
|
296
|
+
const whole = match[0];
|
|
297
|
+
if (EXACT_VENDOR_EXAMPLES.has(whole)) return false;
|
|
298
|
+
if (/^postgres/.test(whole)) return urlPasswordIsReal(whole.slice(whole.lastIndexOf(':') + 1, -1));
|
|
299
|
+
if (whole.startsWith('-----BEGIN')) return true;
|
|
300
|
+
return !/^x{6,}$/i.test(whole.slice(Math.max(whole.lastIndexOf('_'), whole.lastIndexOf('-')) + 1));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** The kind of the first real vendor shape in this text, or ''. */
|
|
304
|
+
function vendorKind(text) {
|
|
305
|
+
for (const [pattern, label] of VENDOR_PATTERNS) {
|
|
306
|
+
for (const match of text.matchAll(pattern)) {
|
|
307
|
+
if (vendorMatchIsReal(match)) return /\[redacted ([^\]]+)\]/.exec(label)?.[1] ?? 'database password';
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return '';
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function bearerCredential(text) {
|
|
314
|
+
for (const match of text.matchAll(BEARER)) {
|
|
315
|
+
const value = match[1];
|
|
316
|
+
if (STORE_REFERENCE.test(value)) continue;
|
|
317
|
+
if (/\d/.test(value) || isOpaque(value) || (/[a-z]/.test(value) && /[A-Z]/.test(value) && value.length >= MIN_OPAQUE)) return true;
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** A bare PEM marker is public syntax used by every scanner; a marker with a body is a key. */
|
|
323
|
+
function withoutEmptyPem(text) {
|
|
324
|
+
return text.replace(EMPTY_PEM, (whole, _kind, _space, offset) => {
|
|
325
|
+
const rest = text.slice(offset + whole.length);
|
|
326
|
+
return !rest || SOURCE_END.test(rest) ? '' : whole;
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** The kind of the first exact vendor key shape in this text, or ''. A name, a URL password or a bearer value is not one. */
|
|
331
|
+
export const vendorKindIn = source => vendorKind(withoutEmptyPem(source.replaceAll('\0', '')));
|
|
332
|
+
|
|
333
|
+
/** Input size is capped at MAX_JSON_BYTES by the hook runner, so each scan below is bounded by it. */
|
|
334
|
+
export function textHasCredential(source) {
|
|
335
|
+
const text = withoutEmptyPem(source.replaceAll('\0', ''));
|
|
336
|
+
if (vendorKind(text) || urlCredential(text) || bearerCredential(text) || NAMED_HEX.test(text)) return true;
|
|
337
|
+
for (const match of text.matchAll(LABEL)) {
|
|
338
|
+
if (assignmentIsCredential(text, match[0], match.index, match.index + match[0].length)) return true;
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The pane a cloud Silo types into. dsh ships no terminal interface, only one-shot `--profile headless`, so this turns each
|
|
3
|
+
// submitted prompt into one headless run on one continued session, and draws the two markers the typing layer reads.
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { realpathSync } from 'node:fs';
|
|
6
|
+
import { createInterface } from 'node:readline';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { git, repository } from './io.mjs';
|
|
9
|
+
|
|
10
|
+
export const READY = 'dsh-ready>';
|
|
11
|
+
export const WORKING = 'dsh-working';
|
|
12
|
+
// A pasted prompt arrives as several lines. It is one task once input has been quiet this long.
|
|
13
|
+
const SETTLE_MS = 800;
|
|
14
|
+
const MAX_TASK_CHARS = 200_000;
|
|
15
|
+
const MAX_LINE_BYTES = 8_000_000;
|
|
16
|
+
const CLEAR = '\u001b[2J\u001b[H';
|
|
17
|
+
|
|
18
|
+
export function headlessArguments({ sessionId, gitDirectory }) {
|
|
19
|
+
return ['--profile', 'headless', '--json', '--permission-mode', 'workspace-write', '--approval-policy', 'never',
|
|
20
|
+
...(gitDirectory ? ['--add-dir', gitDirectory] : []), ...(sessionId ? ['--session-id', sessionId] : []), '-'];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Telemetry stays off even if a later patch layer turned a row back on. */
|
|
24
|
+
export function sessionEnvironment(env, repo) {
|
|
25
|
+
return { ...env, DSH_TELEMETRY_DISABLED: '1', DSH_TELEMETRY_MODE: 'DISABLED', ...(repo ? { ESTELLE_REPO: repo } : {}) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function describe(event) {
|
|
29
|
+
if (event?.type === 'tool_call') return `${WORKING} · ${event.tool ?? 'tool'}`;
|
|
30
|
+
if (event?.type === 'text' && typeof event.text === 'string') return `${WORKING} · ${event.text.split('\n')[0].slice(0, 160)}`;
|
|
31
|
+
if (event?.type === 'status' && event.phase === 'step_start') return `${WORKING} · step ${event.step ?? ''}`.trimEnd();
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** One submitted prompt, one headless process. The run's own exit decides what the pane says, never a parsed fragment. */
|
|
36
|
+
function runTask(task, state, out, spawnImpl) {
|
|
37
|
+
return new Promise(resolve => {
|
|
38
|
+
out.write(`${WORKING} · started\n`);
|
|
39
|
+
const child = spawnImpl('dsh', headlessArguments(state), { cwd: state.cwd, env: state.env, stdio: ['pipe', 'pipe', 'ignore'] });
|
|
40
|
+
let answer = '';
|
|
41
|
+
let failure = '';
|
|
42
|
+
createInterface({ input: child.stdout, crlfDelay: Infinity }).on('line', line => {
|
|
43
|
+
if (Buffer.byteLength(line) > MAX_LINE_BYTES) return;
|
|
44
|
+
let event;
|
|
45
|
+
try { event = JSON.parse(line); } catch { return; }
|
|
46
|
+
if (event.type === 'session' && typeof event.sessionId === 'string') state.sessionId = event.sessionId;
|
|
47
|
+
if (event.type === 'final') answer = typeof event.text === 'string' ? event.text : '';
|
|
48
|
+
if (event.type === 'error') failure = String(event.message ?? 'dsh reported an error').slice(0, 2000);
|
|
49
|
+
const shown = describe(event);
|
|
50
|
+
if (shown) out.write(`${shown}\n`);
|
|
51
|
+
});
|
|
52
|
+
child.on('error', error => { failure = `dsh could not start: ${error.code ?? error.message}`; resolve({ answer, failure }); });
|
|
53
|
+
child.on('close', code => resolve({ answer, failure: failure || (code === 0 ? '' : `dsh exited ${code}`) }));
|
|
54
|
+
child.stdin.on('error', () => {});
|
|
55
|
+
child.stdin.end(task);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function runSession({ input = process.stdin, out = process.stdout, cwd = process.cwd(), env = process.env, spawnImpl = spawn } = {}) {
|
|
60
|
+
const repo = repository(cwd, env);
|
|
61
|
+
const state = { cwd, env: sessionEnvironment(env, repo?.name), sessionId: '',
|
|
62
|
+
gitDirectory: git(cwd, ['rev-parse', '--path-format=absolute', '--git-common-dir']) };
|
|
63
|
+
const prompt = () => out.write(`${READY} `);
|
|
64
|
+
let pending = [];
|
|
65
|
+
let timer;
|
|
66
|
+
let chain = Promise.resolve();
|
|
67
|
+
const submit = () => {
|
|
68
|
+
const task = pending.join('\n').slice(0, MAX_TASK_CHARS);
|
|
69
|
+
pending = [];
|
|
70
|
+
if (!task.trim()) return prompt();
|
|
71
|
+
chain = chain.then(async () => {
|
|
72
|
+
const { answer, failure } = await runTask(task, state, out, spawnImpl);
|
|
73
|
+
// The screen is cleared so no working line stays above the ready marker for the typing layer to read as busy.
|
|
74
|
+
out.write(`${CLEAR}${answer}${answer ? '\n' : ''}${failure ? `dsh failed: ${failure}\n` : ''}`);
|
|
75
|
+
prompt();
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
prompt();
|
|
79
|
+
const lines = createInterface({ input, crlfDelay: Infinity });
|
|
80
|
+
for await (const line of lines) {
|
|
81
|
+
pending.push(line);
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
timer = setTimeout(submit, SETTLE_MS);
|
|
84
|
+
}
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
if (pending.length) submit();
|
|
87
|
+
await chain;
|
|
88
|
+
return state;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) await runSession();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Reads what dsh will actually mount, from the text of `dsh --profile <name> --dump-config`, and answers one question:
|
|
2
|
+
// is any harness telemetry row on? A later patch layer can undo ours, so the plugin's own file is not evidence.
|
|
3
|
+
export const TELEMETRY_ROWS = Object.freeze(['session-log-deepseek', 'session-telemetry-otel', 'plugin-package-inventory-deepseek']);
|
|
4
|
+
// Only the web profile mounts this one, so its absence from another profile's dump is not a failure. Present, it must be off.
|
|
5
|
+
export const WEB_ONLY_TELEMETRY_ROWS = Object.freeze(['desktop-product-telemetry']);
|
|
6
|
+
export const TELEMETRY_OFF = 'DSH-TELEMETRY-OFF';
|
|
7
|
+
const MAX_DUMP_BYTES = 8_000_000;
|
|
8
|
+
const MAX_ROW_LINES = 64;
|
|
9
|
+
|
|
10
|
+
/** The rows that are on or absent from the dump. Absent is not off: it is a dump this reader could not read. */
|
|
11
|
+
export function telemetryViolations(dump) {
|
|
12
|
+
if (typeof dump !== 'string' || !dump.trim() || dump.length > MAX_DUMP_BYTES) return [...TELEMETRY_ROWS];
|
|
13
|
+
const lines = dump.split('\n');
|
|
14
|
+
return [...TELEMETRY_ROWS, ...WEB_ONLY_TELEMETRY_ROWS].filter(id => {
|
|
15
|
+
const start = lines.findIndex(line => new RegExp(`^(\\s*)- id: ['"]?${id}['"]?\\s*(#.*)?$`).test(line));
|
|
16
|
+
if (start < 0) return !WEB_ONLY_TELEMETRY_ROWS.includes(id);
|
|
17
|
+
const indent = /^\s*/.exec(lines[start])[0].length;
|
|
18
|
+
const row = [];
|
|
19
|
+
for (let at = start + 1; at < lines.length && row.length < MAX_ROW_LINES; at++) {
|
|
20
|
+
const line = lines[at];
|
|
21
|
+
if (line.trim() && !line.trim().startsWith('#') && /^\s*/.exec(line)[0].length <= indent) break;
|
|
22
|
+
row.push(line);
|
|
23
|
+
}
|
|
24
|
+
return !row.some(line => /^\s*disabled:\s*true\s*(#.*)?$/.test(line));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function telemetryCheck(dump) {
|
|
29
|
+
const violations = telemetryViolations(dump);
|
|
30
|
+
return violations.length ? `DSH-TELEMETRY-ON: ${violations.join(',')}` : TELEMETRY_OFF;
|
|
31
|
+
}
|