@phyzess/kitto 0.2.1 → 0.3.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/CHANGELOG.md +27 -0
- package/README.md +36 -4
- package/bin/kitto.mjs +173 -2
- package/integration/dsh-archive-review.mjs +55 -0
- package/integration/dsh.mjs +3 -1
- package/integration/plugin.json +1 -1
- package/integration/scoped-dsh/native.mjs +33 -1
- package/integration/skills/kitto/SKILL.md +5 -4
- package/lib/codegraph.mjs +135 -0
- package/lib/codex-mcp.mjs +738 -0
- package/lib/dsh-profile.mjs +111 -0
- package/lib/environment-setup.mjs +19 -3
- package/lib/host-config.mjs +29 -4
- package/lib/hosts.mjs +288 -0
- package/lib/kitto.mjs +420 -55
- package/lib/mcp-credentials.mjs +289 -0
- package/lib/mcp-sync.mjs +500 -0
- package/lib/parity.mjs +64 -0
- package/lib/pi_config.py +218 -9
- package/lib/scope-dsh.mjs +10 -31
- package/lib/scope-setup.mjs +34 -12
- package/lib/scopes.mjs +45 -10
- package/lib/setup-wizard.mjs +38 -13
- package/lib/versions.mjs +8 -2
- package/lib/worktree-audit.mjs +189 -0
- package/lib/worktree-lifecycle.mjs +451 -0
- package/package.json +3 -3
- package/sync.sh +94 -25
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential-reference parsing and literal-secret detection shared by the DSH
|
|
3
|
+
* and Codex MCP syncers.
|
|
4
|
+
*
|
|
5
|
+
* A source may only name a credential through a whole `${VAR}` reference (or
|
|
6
|
+
* `Bearer ${VAR}` for an Authorization header). Everything else is reported by
|
|
7
|
+
* key path and label; a value itself is never returned, logged or written to a
|
|
8
|
+
* host configuration. The literal shapes mirror the export guard in
|
|
9
|
+
* `lib/pi_config.py` so both directions refuse the same tokens.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const REFERENCE_PATTERN = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;
|
|
13
|
+
const BEARER_REFERENCE_PATTERN = /^Bearer \$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;
|
|
14
|
+
const PLACEHOLDER_PATTERN = /YOUR_[A-Za-z0-9_]+/;
|
|
15
|
+
|
|
16
|
+
const SECRET_VALUE_PATTERNS = [
|
|
17
|
+
['openai-style key', /sk-[A-Za-z0-9_-]{16,}/],
|
|
18
|
+
['GitHub token', /(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}/],
|
|
19
|
+
['GitHub fine-grained token', /github_pat_[A-Za-z0-9_]{20,}/],
|
|
20
|
+
['Slack token', /xox[baprs]-[A-Za-z0-9-]{10,}/],
|
|
21
|
+
['AWS access key', /AKIA[0-9A-Z]{16}/],
|
|
22
|
+
['JWT', /eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/],
|
|
23
|
+
['private key', /-----BEGIN [A-Z ]*PRIVATE KEY-----/],
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
27
|
+
|
|
28
|
+
/** The variable name of a whole `${VAR}` reference, or null. */
|
|
29
|
+
export function credentialReference(value) {
|
|
30
|
+
if (typeof value !== 'string') return null;
|
|
31
|
+
return REFERENCE_PATTERN.exec(value)?.[1] ?? null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The variable name of a `Bearer ${VAR}` reference, or null. */
|
|
35
|
+
export function bearerCredentialReference(value) {
|
|
36
|
+
if (typeof value !== 'string') return null;
|
|
37
|
+
return BEARER_REFERENCE_PATTERN.exec(value)?.[1] ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The DSH `${credential:REF}` template that resolves the referenced secret. */
|
|
41
|
+
export function credentialTemplate(reference) {
|
|
42
|
+
return `\${credential:${reference}}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The DSH template for an Authorization value that keeps its scheme prefix. */
|
|
46
|
+
export function bearerCredentialTemplate(reference) {
|
|
47
|
+
return `Bearer \${credential:${reference}}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Whether any string inside `value` contains a template-like `${...}`. */
|
|
51
|
+
export function containsTemplate(value) {
|
|
52
|
+
if (typeof value === 'string') return value.includes('${');
|
|
53
|
+
if (Array.isArray(value)) return value.some(containsTemplate);
|
|
54
|
+
if (isObject(value)) return Object.values(value).some(containsTemplate);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function walk(value, path, visit) {
|
|
59
|
+
if (typeof value === 'string') {
|
|
60
|
+
visit(value, path || 'value');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
for (const [index, item] of value.entries()) walk(item, `${path || 'value'}[${index}]`, visit);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!isObject(value)) return;
|
|
68
|
+
for (const [key, item] of Object.entries(value)) walk(item, path ? `${path}.${key}` : key, visit);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Literal token shapes anywhere in a server definition. Returns key paths and
|
|
73
|
+
* labels only; a matching value is never part of the result.
|
|
74
|
+
*/
|
|
75
|
+
export function literalSecretsIn(value) {
|
|
76
|
+
const found = [];
|
|
77
|
+
walk(value, '', (text, path) => {
|
|
78
|
+
for (const [label, pattern] of SECRET_VALUE_PATTERNS) {
|
|
79
|
+
if (pattern.test(text)) {
|
|
80
|
+
found.push({ path, label });
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return found;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Paths whose string still carries a `YOUR_*` template placeholder. */
|
|
89
|
+
export function unresolvedPlaceholdersIn(value) {
|
|
90
|
+
const found = [];
|
|
91
|
+
walk(value, '', (text, path) => {
|
|
92
|
+
if (PLACEHOLDER_PATTERN.test(text)) found.push({ path });
|
|
93
|
+
});
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A name that reads as a credential slot: query parameter, header-like flag or
|
|
99
|
+
* env assignment. Segment-aware so `?monkey=1` is not mistaken for a key.
|
|
100
|
+
*/
|
|
101
|
+
export function isCredentialName(name) {
|
|
102
|
+
const folded = String(name).toLowerCase();
|
|
103
|
+
if (/(?:token|secret|password|passwd|credential|bearer|authorization)/.test(folded)) return true;
|
|
104
|
+
if (/(?:api[-_]?key|access[-_]?key|private[-_]?key|client[-_]?secret)/.test(folded)) return true;
|
|
105
|
+
if (/(?:^|[-_.])(?:auth|sig|signature)(?:$|[-_.])/.test(folded)) return true;
|
|
106
|
+
return /(?:^|[-_.])key(?:$|[-_.])/.test(folded);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function safeDecode(value) {
|
|
110
|
+
try {
|
|
111
|
+
return decodeURIComponent(value);
|
|
112
|
+
} catch {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function queryCredentialReason(text) {
|
|
118
|
+
for (const match of text.matchAll(/[?&;#]([^=&;#\s]+)=/g)) {
|
|
119
|
+
if (isCredentialName(safeDecode(match[1]))) return 'has a credential-like query parameter';
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Why a URL must not be copied literally, or null. Rejects any userinfo
|
|
126
|
+
* (`user:pass@host`) and credential-like query or fragment parameters, which
|
|
127
|
+
* are a common carrier for literal tokens. The URL itself is never returned.
|
|
128
|
+
*/
|
|
129
|
+
export function urlCredentialReason(value) {
|
|
130
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
131
|
+
// Authority userinfo, including strings another parser might reject later.
|
|
132
|
+
if (/[A-Za-z][A-Za-z0-9+.-]*:\/\/[^/?#\s]*@/.test(value)) return 'contains userinfo credentials';
|
|
133
|
+
const fromText = queryCredentialReason(value);
|
|
134
|
+
if (fromText) return fromText;
|
|
135
|
+
try {
|
|
136
|
+
const parsed = new URL(value);
|
|
137
|
+
if (parsed.username || parsed.password) return 'contains userinfo credentials';
|
|
138
|
+
for (const [name] of parsed.searchParams) {
|
|
139
|
+
if (isCredentialName(name)) return 'has a credential-like query parameter';
|
|
140
|
+
}
|
|
141
|
+
for (const part of parsed.hash.replace(/^#/, '').split(/[&;]/)) {
|
|
142
|
+
const name = part.split('=')[0];
|
|
143
|
+
if (name && isCredentialName(safeDecode(name))) return 'has a credential-like query parameter';
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// Relative values were already covered by the textual query scan.
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const FLAG_PATTERN = /^(?:--?|\/)([A-Za-z0-9][A-Za-z0-9_.-]*)(?:=(.*))?$/;
|
|
152
|
+
const ENV_ASSIGNMENT = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;
|
|
153
|
+
const ASSIGNMENT_PAIR = /(?:^|[\s,;])([A-Za-z0-9]+(?:[-_.][A-Za-z0-9]+)*)\s*[:=]\s*(\S+)/g;
|
|
154
|
+
const HEADER_FLAG_NAMES = new Set(['header', 'headers', 'http-header']);
|
|
155
|
+
|
|
156
|
+
function valueLooksCredentialLike(value) {
|
|
157
|
+
if (typeof value !== 'string' || value === '') return false;
|
|
158
|
+
if (literalSecretsIn(value).length) return true;
|
|
159
|
+
if (/^Bearer\s+\S+/i.test(value)) return true;
|
|
160
|
+
// A long unbroken token-like value in a header is treated as a secret.
|
|
161
|
+
return value.length >= 20 && /^[A-Za-z0-9+/_=-]+$/.test(value);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Inspect one `Name: value` header specification. Sensitive header names and
|
|
166
|
+
* credential-looking values are refused; the specification is never echoed.
|
|
167
|
+
*/
|
|
168
|
+
function headerSpecProblem(spec) {
|
|
169
|
+
if (typeof spec !== 'string' || spec.trim() === '') return null;
|
|
170
|
+
const separator = spec.search(/[:=]/);
|
|
171
|
+
let name, value;
|
|
172
|
+
if (separator >= 0) {
|
|
173
|
+
name = spec.slice(0, separator).trim();
|
|
174
|
+
value = spec.slice(separator + 1).trim();
|
|
175
|
+
} else {
|
|
176
|
+
const [first, ...rest] = spec.trim().split(/\s+/);
|
|
177
|
+
name = first;
|
|
178
|
+
value = rest.join(' ');
|
|
179
|
+
}
|
|
180
|
+
if (isCredentialName(name)) return 'looks like a sensitive header';
|
|
181
|
+
if (value && valueLooksCredentialLike(value)) return 'looks like a credential header value';
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function headerFlagMatch(value) {
|
|
186
|
+
const match = FLAG_PATTERN.exec(value);
|
|
187
|
+
if (!match) return null;
|
|
188
|
+
const name = match[1].toLowerCase();
|
|
189
|
+
const header = (match[1] === 'H' && value.startsWith('-H')) || HEADER_FLAG_NAMES.has(name);
|
|
190
|
+
return header ? match : null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** A `name=value` / `name: value` token whose name reads as a credential. */
|
|
194
|
+
function assignmentLooksLikeCredential(value) {
|
|
195
|
+
for (const match of value.matchAll(ASSIGNMENT_PAIR)) {
|
|
196
|
+
if (match[2] !== '' && isCredentialName(match[1])) return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function credentialFlagIsLiteral(value) {
|
|
202
|
+
const match = FLAG_PATTERN.exec(value);
|
|
203
|
+
if (!match) return false;
|
|
204
|
+
if (typeof match[2] === 'string') {
|
|
205
|
+
if (/authorization\s*:/i.test(match[2]) || /\bbearer\s+[^$\s]/i.test(match[2])) return true;
|
|
206
|
+
const assigned = ENV_ASSIGNMENT.exec(match[2]);
|
|
207
|
+
if (assigned && assigned[2] !== '' && isCredentialName(assigned[1])) return true;
|
|
208
|
+
if (assignmentLooksLikeCredential(match[2])) return true;
|
|
209
|
+
}
|
|
210
|
+
return isCredentialName(match[1]) && typeof match[2] === 'string' && match[2] !== '';
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function tokenLooksLikeCredential(value) {
|
|
214
|
+
if (typeof value !== 'string' || value === '') return false;
|
|
215
|
+
if (credentialFlagIsLiteral(value)) return true;
|
|
216
|
+
const assigned = ENV_ASSIGNMENT.exec(value);
|
|
217
|
+
if (assigned && assigned[2] !== '' && isCredentialName(assigned[1])) return true;
|
|
218
|
+
if (/authorization\s*:/i.test(value)) return true;
|
|
219
|
+
if (/\bbearer\s+[^$\s]/i.test(value)) return true;
|
|
220
|
+
if (assignmentLooksLikeCredential(value)) return true;
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* A literal credential in a transport that Kitto would otherwise copy into a
|
|
226
|
+
* host configuration: URL userinfo/query, a credential-shaped command flag or
|
|
227
|
+
* env assignment, or a literal Authorization/Bearer value. Returns a path-only
|
|
228
|
+
* reason so a failing command can be reported without echoing its argv.
|
|
229
|
+
*/
|
|
230
|
+
export function transportCredentialProblem(entry) {
|
|
231
|
+
if (!isObject(entry)) return null;
|
|
232
|
+
if (typeof entry.url === 'string') {
|
|
233
|
+
const reason = urlCredentialReason(entry.url);
|
|
234
|
+
if (reason) return `url ${reason}`;
|
|
235
|
+
}
|
|
236
|
+
const tokens = [];
|
|
237
|
+
if (typeof entry.command === 'string') tokens.push({ path: 'command', value: entry.command });
|
|
238
|
+
if (Array.isArray(entry.args)) {
|
|
239
|
+
for (const [index, value] of entry.args.entries()) {
|
|
240
|
+
if (typeof value === 'string') tokens.push({ path: `args[${index}]`, value });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
for (const [index, token] of tokens.entries()) {
|
|
244
|
+
const reason = urlCredentialReason(token.value);
|
|
245
|
+
if (reason) return `${token.path} ${reason}`;
|
|
246
|
+
const header = headerFlagMatch(token.value);
|
|
247
|
+
if (header) {
|
|
248
|
+
const spec = header[2] ?? tokens[index + 1]?.value;
|
|
249
|
+
const specPath = header[2] === undefined ? tokens[index + 1]?.path ?? token.path : token.path;
|
|
250
|
+
if (spec !== undefined) {
|
|
251
|
+
const problem = headerSpecProblem(spec);
|
|
252
|
+
if (problem) return `${specPath} ${problem}`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (tokenLooksLikeCredential(token.value)) return `${token.path} looks like a literal credential`;
|
|
256
|
+
const previous = tokens[index - 1];
|
|
257
|
+
if (previous && !token.value.startsWith('-') && isCredentialFlag(previous.value)) {
|
|
258
|
+
return `${token.path} looks like a literal credential`;
|
|
259
|
+
}
|
|
260
|
+
const next = tokens[index + 1];
|
|
261
|
+
if (next && isCredentialFlag(token.value) && !next.value.startsWith('-')) {
|
|
262
|
+
return `${next.path} looks like a literal credential`;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function isCredentialFlag(value) {
|
|
269
|
+
const match = FLAG_PATTERN.exec(value);
|
|
270
|
+
return Boolean(match && isCredentialName(match[1]));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Explain why one env/header value is not a usable reference without quoting
|
|
275
|
+
* the value. `field` is a key path such as `env.TOKEN`.
|
|
276
|
+
*/
|
|
277
|
+
export function literalValueReason(field, value, { authorization = false } = {}) {
|
|
278
|
+
const [secret] = literalSecretsIn(value);
|
|
279
|
+
if (secret) {
|
|
280
|
+
return `${field} contains a literal secret (${secret.label}); only \${VAR} references are synced`;
|
|
281
|
+
}
|
|
282
|
+
if (authorization) {
|
|
283
|
+
return `${field} is not a credential reference; use "Bearer \${VAR}" or "\${VAR}"`;
|
|
284
|
+
}
|
|
285
|
+
if (typeof value === 'string' && value.includes('${')) {
|
|
286
|
+
return `${field} is not a whole \${VAR} reference`;
|
|
287
|
+
}
|
|
288
|
+
return `${field} is a literal value; only \${VAR} references are synced`;
|
|
289
|
+
}
|