@lizard-build/cli 4.0.134 → 4.0.136
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/commands/git-hosting.js +35 -33
- package/dist/commands/git-hosting.js.map +1 -1
- package/dist/commands/logs.js +15 -12
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/sandbox.js +24 -13
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/up.d.ts +9 -0
- package/dist/commands/up.js +43 -13
- package/dist/commands/up.js.map +1 -1
- package/dist/lib/checkout.d.ts +7 -0
- package/dist/lib/checkout.js +20 -1
- package/dist/lib/checkout.js.map +1 -1
- package/dist/lib/config.d.ts +6 -1
- package/dist/lib/config.js +16 -4
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/env-guard.js +38 -2
- package/dist/lib/env-guard.js.map +1 -1
- package/dist/lib/signin.d.ts +9 -0
- package/dist/lib/signin.js +19 -2
- package/dist/lib/signin.js.map +1 -1
- package/dist/lib/skills-data.generated.js +2 -2
- package/dist/lib/skills-data.generated.js.map +1 -1
- package/dist/lib/terminal.d.ts +20 -0
- package/dist/lib/terminal.js +32 -0
- package/dist/lib/terminal.js.map +1 -0
- package/dist/lib/updater.d.ts +1 -1
- package/dist/lib/updater.js +1 -1
- package/dist/lib/upload-filter.d.ts +14 -0
- package/dist/lib/upload-filter.js +146 -0
- package/dist/lib/upload-filter.js.map +1 -0
- package/package.json +1 -1
- package/skill-data/core/references/deploys.md +1 -1
- package/skill-data/core/references/sandboxes.md +1 -1
- package/src/commands/git-hosting.ts +35 -33
- package/src/commands/logs.ts +16 -12
- package/src/commands/sandbox.ts +27 -12
- package/src/commands/up.ts +59 -9
- package/src/lib/checkout.ts +22 -1
- package/src/lib/config.ts +12 -5
- package/src/lib/env-guard.ts +37 -2
- package/src/lib/signin.ts +24 -2
- package/src/lib/terminal.ts +36 -0
- package/src/lib/updater.ts +1 -1
- package/src/lib/upload-filter.ts +141 -0
- package/test/unit/checkout-symlink.test.ts +19 -1
- package/test/unit/config.test.ts +21 -0
- package/test/unit/env-guard.test.ts +6 -2
- package/test/unit/login.test.ts +26 -1
- package/test/unit/terminal.test.ts +25 -0
- package/test/unit/upload-filter.test.ts +62 -0
- package/lizard-wrapper.sh +0 -2
package/src/commands/up.ts
CHANGED
|
@@ -13,12 +13,15 @@ import { ensureLinked } from "./init.js";
|
|
|
13
13
|
import {
|
|
14
14
|
success,
|
|
15
15
|
info,
|
|
16
|
+
warn,
|
|
16
17
|
error,
|
|
17
18
|
isJSONMode,
|
|
18
19
|
isTTY,
|
|
19
20
|
printJSON,
|
|
20
21
|
statusColor,
|
|
21
22
|
} from "../lib/format.js";
|
|
23
|
+
import { termSafe } from "../lib/terminal.js";
|
|
24
|
+
import { isEnvFile, isSensitivePath, isTooBroadToUpload, loadLizardIgnore } from "../lib/upload-filter.js";
|
|
22
25
|
|
|
23
26
|
interface App {
|
|
24
27
|
id: string;
|
|
@@ -150,7 +153,17 @@ export async function deployFromLocal(args: {
|
|
|
150
153
|
appName = nameInput || defaultName;
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
const files = getUploadFiles(args.targetPath, args.useGitignore);
|
|
156
|
+
const { files, skipped, untrackedEnv } = getUploadFiles(args.targetPath, args.useGitignore);
|
|
157
|
+
if (skipped.length) {
|
|
158
|
+
warn(`Not uploading files that look like secrets: ${skipped.join(", ")}`);
|
|
159
|
+
info(chalk.dim(" Set their values with `lizard secrets set` instead."));
|
|
160
|
+
}
|
|
161
|
+
if (untrackedEnv.length) {
|
|
162
|
+
warn(
|
|
163
|
+
`Uploading ${untrackedEnv.join(", ")}: not in git and not ignored. ` +
|
|
164
|
+
"Add to .gitignore or .lizardignore to keep out of the upload, and use `lizard secrets set` for its values.",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
154
167
|
if (files.length === 0) {
|
|
155
168
|
throw new Error(
|
|
156
169
|
"No files to upload. Run from a directory with files, or pass a path: `lizard up <path>`.",
|
|
@@ -251,7 +264,18 @@ function getDefaultAppName(cwd: string = process.cwd()): string {
|
|
|
251
264
|
return path.basename(cwd);
|
|
252
265
|
}
|
|
253
266
|
|
|
254
|
-
|
|
267
|
+
interface UploadFiles {
|
|
268
|
+
files: string[];
|
|
269
|
+
/** Left out because they look like credentials (folder walk only). */
|
|
270
|
+
skipped: string[];
|
|
271
|
+
/** Untracked, not ignored .env files the git listing will upload. */
|
|
272
|
+
untrackedEnv: string[];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const toPosix = (p: string) => p.split(path.sep).join("/");
|
|
276
|
+
|
|
277
|
+
export function getUploadFiles(cwd: string, useGitignore: boolean): UploadFiles {
|
|
278
|
+
const ignored = loadLizardIgnore(cwd);
|
|
255
279
|
if (useGitignore) {
|
|
256
280
|
try {
|
|
257
281
|
// `-z` outputs NUL-separated paths and disables git's default behaviour
|
|
@@ -272,12 +296,25 @@ function getUploadFiles(cwd: string, useGitignore: boolean): string[] {
|
|
|
272
296
|
.toString("utf8")
|
|
273
297
|
.split("\0")
|
|
274
298
|
.filter(Boolean);
|
|
275
|
-
|
|
299
|
+
const files = [...new Set([...tracked, ...untracked])]
|
|
300
|
+
.filter((f) => f !== ".lizard-git" && !f.startsWith(".lizard-git/"))
|
|
301
|
+
.filter((f) => !ignored?.(f));
|
|
302
|
+
const kept = new Set(files);
|
|
303
|
+
const untrackedEnv = untracked.filter((f) => kept.has(f) && isEnvFile(path.posix.basename(f)));
|
|
304
|
+
return { files, skipped: [], untrackedEnv };
|
|
276
305
|
} catch {
|
|
277
306
|
// fall through to manual collection
|
|
278
307
|
}
|
|
279
308
|
}
|
|
280
|
-
|
|
309
|
+
if (isTooBroadToUpload(cwd)) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`Refusing to upload ${cwd}: it is your home folder or the file system root. ` +
|
|
312
|
+
"Run `lizard up` from the project's folder, or pass it: `lizard up <path>`.",
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
const skipped: string[] = [];
|
|
316
|
+
const files = collectFilesManually(cwd, cwd, skipped, ignored);
|
|
317
|
+
return { files, skipped, untrackedEnv: [] };
|
|
281
318
|
}
|
|
282
319
|
|
|
283
320
|
const EXCLUDE_DIRS = new Set([
|
|
@@ -300,15 +337,28 @@ const EXCLUDE_EXT = new Set([".pyc", ".pyo", ".log"]);
|
|
|
300
337
|
// extension matching never catches these.
|
|
301
338
|
const EXCLUDE_FILES = new Set([".DS_Store"]);
|
|
302
339
|
|
|
303
|
-
function collectFilesManually(
|
|
340
|
+
function collectFilesManually(
|
|
341
|
+
root: string,
|
|
342
|
+
dir: string,
|
|
343
|
+
skipped: string[],
|
|
344
|
+
ignored: ((rel: string, isDir?: boolean) => boolean) | null,
|
|
345
|
+
): string[] {
|
|
304
346
|
const results: string[] = [];
|
|
305
347
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
306
348
|
if (EXCLUDE_DIRS.has(entry.name)) continue;
|
|
307
349
|
if (EXCLUDE_FILES.has(entry.name)) continue;
|
|
308
350
|
if (EXCLUDE_EXT.has(path.extname(entry.name))) continue;
|
|
309
351
|
const full = path.join(dir, entry.name);
|
|
310
|
-
|
|
311
|
-
|
|
352
|
+
const rel = path.relative(root, full);
|
|
353
|
+
const relPosix = toPosix(rel);
|
|
354
|
+
const isDir = entry.isDirectory();
|
|
355
|
+
if (ignored?.(relPosix, isDir)) continue;
|
|
356
|
+
if (isSensitivePath(relPosix)) {
|
|
357
|
+
skipped.push(isDir ? relPosix + "/" : relPosix);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (isDir) results.push(...collectFilesManually(root, full, skipped, ignored));
|
|
361
|
+
else results.push(rel);
|
|
312
362
|
}
|
|
313
363
|
return results;
|
|
314
364
|
}
|
|
@@ -456,8 +506,8 @@ function emitBuildLine(data: string) {
|
|
|
456
506
|
);
|
|
457
507
|
return;
|
|
458
508
|
}
|
|
459
|
-
|
|
460
|
-
|
|
509
|
+
const out = termSafe(line || data, { keepColors: true });
|
|
510
|
+
process.stdout.write(out + "\n");
|
|
461
511
|
}
|
|
462
512
|
|
|
463
513
|
function stripLine(obj: any): Record<string, unknown> {
|
package/src/lib/checkout.ts
CHANGED
|
@@ -226,8 +226,29 @@ export async function listFiles(repo: string, root: string, sparse: string[] | n
|
|
|
226
226
|
|
|
227
227
|
// ── working files ──────────────────────────────────────────────────────
|
|
228
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Is this path component (a spelling of) git's or this checkout's metadata folder? File systems
|
|
231
|
+
* fold names: case (Windows, macOS), trailing dots and spaces and `:stream` suffixes (NTFS),
|
|
232
|
+
* 8.3 short names (`GIT~1`), zero-width characters (HFS+). A tree from the server must never
|
|
233
|
+
* write into `.git` (hooks, config run code) or `.lizard-git`.
|
|
234
|
+
*/
|
|
235
|
+
export function isMetadataName(x: string): boolean {
|
|
236
|
+
const n = x
|
|
237
|
+
.replace(/[\u200b-\u200f\u202a-\u202e\u2060-\u2064\u206a-\u206f\ufeff]/g, "")
|
|
238
|
+
.toLowerCase()
|
|
239
|
+
.replace(/:.*$/s, "")
|
|
240
|
+
.replace(/[. ]+$/, "");
|
|
241
|
+
return n === ".git" || n === STATE_DIR || /^git~\d+$/.test(n) || /^lizard~\d+$/.test(n);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** A component Windows would rename or treat as a stream: trailing dot/space, or a `:`. */
|
|
245
|
+
function badOnWindows(x: string): boolean {
|
|
246
|
+
return /[. ]$/.test(x) || x.includes(":");
|
|
247
|
+
}
|
|
248
|
+
|
|
229
249
|
function safeJoin(root: string, p: string): string {
|
|
230
|
-
|
|
250
|
+
const win = process.platform === "win32";
|
|
251
|
+
if (p.split("/").some((x) => x === "" || x === "." || x === ".." || isMetadataName(x) || (win && badOnWindows(x))) || p.includes("\\") || p.includes("\0")) {
|
|
231
252
|
throw new APIError(400, `refusing a path outside the checkout: ${p}`);
|
|
232
253
|
}
|
|
233
254
|
return join(root, ...p.split("/"));
|
package/src/lib/config.ts
CHANGED
|
@@ -47,7 +47,8 @@ export interface PendingAuth {
|
|
|
47
47
|
authUrl: string;
|
|
48
48
|
createdAt: number;
|
|
49
49
|
/** When the platform drops the session. Older CLIs did not save it. */
|
|
50
|
-
expiresAt?: number;
|
|
50
|
+
expiresAt?: number; /** The confirmation code the platform showed for this session (newer platforms only). */
|
|
51
|
+
userCode?: string;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
export interface Config {
|
|
@@ -64,11 +65,17 @@ export function loadConfig(): Config {
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The config holds the login token: the folder is 0700 and the file 0600. `mode` only applies
|
|
70
|
+
* when a file or folder is created, so both are chmod-ed on every write (fixes older installs).
|
|
71
|
+
*/
|
|
67
72
|
export function saveConfig(config: Config) {
|
|
68
|
-
|
|
69
|
-
fs.
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
const dir = configDir();
|
|
74
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
75
|
+
try { fs.chmodSync(dir, 0o700); } catch {}
|
|
76
|
+
const file = configFile();
|
|
77
|
+
fs.writeFileSync(file, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
78
|
+
try { fs.chmodSync(file, 0o600); } catch {}
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
/**
|
package/src/lib/env-guard.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Variables that change how a program starts rather than what it does: a loader to preload, code
|
|
3
|
-
* a shell or runtime runs first, where commands are looked up, git config and helpers
|
|
3
|
+
* a shell or runtime runs first, where commands are looked up, git config and helpers, programs
|
|
4
|
+
* that tools start (pagers, editors, wrappers), proxies and trusted certificates.
|
|
4
5
|
* `lizard run` puts a project's variables into a command on this machine, and anyone who can
|
|
5
6
|
* edit the project's variables could set these to run code here; so they are not set locally
|
|
6
7
|
* (they still apply to the service on Lizard).
|
|
@@ -28,10 +29,44 @@ const EXACT = new Set([
|
|
|
28
29
|
"JAVA_TOOL_OPTIONS",
|
|
29
30
|
"_JAVA_OPTIONS",
|
|
30
31
|
"ZDOTDIR",
|
|
32
|
+
// git: programs it runs (diff, pager, editors, proxy)
|
|
33
|
+
"GIT_EXTERNAL_DIFF",
|
|
34
|
+
"GIT_PAGER",
|
|
35
|
+
"GIT_EDITOR",
|
|
36
|
+
"GIT_SEQUENCE_EDITOR",
|
|
37
|
+
"GIT_PROXY_COMMAND",
|
|
38
|
+
// toolchains that run a wrapper or read flags/hooks from the environment
|
|
39
|
+
"GOFLAGS",
|
|
40
|
+
"RUSTC_WRAPPER",
|
|
41
|
+
"RUSTC",
|
|
42
|
+
"CARGO_BUILD_RUSTC_WRAPPER",
|
|
43
|
+
"PYTHONWARNINGS",
|
|
44
|
+
"JDK_JAVA_OPTIONS",
|
|
45
|
+
"DOTNET_STARTUP_HOOKS",
|
|
46
|
+
"PHPRC",
|
|
47
|
+
"PHP_INI_SCAN_DIR",
|
|
48
|
+
// programs other programs start for you
|
|
49
|
+
"PAGER",
|
|
50
|
+
"EDITOR",
|
|
51
|
+
"VISUAL",
|
|
52
|
+
"LESSOPEN",
|
|
53
|
+
"LESSCLOSE",
|
|
54
|
+
"BROWSER",
|
|
55
|
+
// where traffic goes and which certificates are trusted
|
|
56
|
+
"NODE_EXTRA_CA_CERTS",
|
|
57
|
+
"SSL_CERT_FILE",
|
|
58
|
+
"SSL_CERT_DIR",
|
|
59
|
+
"REQUESTS_CA_BUNDLE",
|
|
60
|
+
"CURL_CA_BUNDLE",
|
|
31
61
|
]);
|
|
32
62
|
const PREFIXES = ["LD_", "DYLD_", "GIT_CONFIG", "GIT_SSH", "BASH_FUNC_"];
|
|
63
|
+
/** Matched whatever the case: tools read these in either case (npm_config_*, http_proxy). */
|
|
64
|
+
const ANY_CASE_EXACT = new Set(["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"]);
|
|
65
|
+
const ANY_CASE_PREFIXES = ["NPM_CONFIG_"];
|
|
33
66
|
|
|
34
67
|
export function isStartupEnvName(name: string): boolean {
|
|
35
68
|
const n = process.platform === "win32" ? name.toUpperCase() : name;
|
|
36
|
-
|
|
69
|
+
if (EXACT.has(n) || PREFIXES.some((p) => n.startsWith(p))) return true;
|
|
70
|
+
const u = name.toUpperCase();
|
|
71
|
+
return ANY_CASE_EXACT.has(u) || ANY_CASE_PREFIXES.some((p) => u.startsWith(p));
|
|
37
72
|
}
|
package/src/lib/signin.ts
CHANGED
|
@@ -35,6 +35,9 @@ interface SessionResponse {
|
|
|
35
35
|
sessionId: string;
|
|
36
36
|
sessionSecret: string;
|
|
37
37
|
expiresIn: number;
|
|
38
|
+
/** Shown here and on the approval page, so the person approves this terminal's session.
|
|
39
|
+
* Older platforms do not send it. */
|
|
40
|
+
userCode?: string;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
export interface CheckResponse {
|
|
@@ -92,6 +95,17 @@ export interface Pending {
|
|
|
92
95
|
sessionId: string;
|
|
93
96
|
sessionSecret: string;
|
|
94
97
|
expiresAt: number;
|
|
98
|
+
userCode?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The platform's confirmation code if it is one (letters, digits, dashes); never other text. */
|
|
102
|
+
export function cleanUserCode(code: unknown): string | undefined {
|
|
103
|
+
return typeof code === "string" && /^[A-Za-z0-9-]{1,32}$/.test(code) ? code : undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The line that asks the person to check the code in the browser, or null without one. */
|
|
107
|
+
export function userCodeLine(code: string | undefined): string | null {
|
|
108
|
+
return code ? `Confirm this code in your browser: ${chalk.bold(code)}` : null;
|
|
95
109
|
}
|
|
96
110
|
|
|
97
111
|
export type Resumed =
|
|
@@ -175,6 +189,7 @@ export async function resumePending(): Promise<Resumed> {
|
|
|
175
189
|
sessionId: saved.sessionId,
|
|
176
190
|
sessionSecret: saved.sessionSecret,
|
|
177
191
|
expiresAt: saved.expiresAt ?? saved.createdAt + SESSION_TTL_MS,
|
|
192
|
+
userCode: cleanUserCode(saved.userCode),
|
|
178
193
|
};
|
|
179
194
|
let result: CheckResponse;
|
|
180
195
|
try {
|
|
@@ -203,6 +218,7 @@ export async function startSession(provider?: AuthProvider): Promise<Pending> {
|
|
|
203
218
|
sessionId: session.sessionId,
|
|
204
219
|
sessionSecret: session.sessionSecret,
|
|
205
220
|
expiresAt: now + session.expiresIn * 1000,
|
|
221
|
+
userCode: cleanUserCode(session.userCode),
|
|
206
222
|
};
|
|
207
223
|
savePendingAuth({ ...pending, authUrl: authUrlFor(session.sessionId, provider), createdAt: now });
|
|
208
224
|
return pending;
|
|
@@ -245,6 +261,9 @@ export function pendingPayload(
|
|
|
245
261
|
const minutes = Math.max(1, Math.round((pending.expiresAt - now) / 60_000));
|
|
246
262
|
const window = minutes === 1 ? "1 more minute" : `${minutes} more minutes`;
|
|
247
263
|
const then = opts.nextCommand ? "run nextCommand" : "run the same command again";
|
|
264
|
+
const code = pending.userCode
|
|
265
|
+
? ` Tell the user to check that the browser shows the code ${pending.userCode} before approving.`
|
|
266
|
+
: "";
|
|
248
267
|
const lead =
|
|
249
268
|
why === "waiting"
|
|
250
269
|
? "The user has not finished signing in yet. "
|
|
@@ -253,16 +272,17 @@ export function pendingPayload(
|
|
|
253
272
|
: "";
|
|
254
273
|
const instruction = single
|
|
255
274
|
? `${lead}Sign-in is needed. Give the user authUrl to open. Once the browser says "CLI authorized", ${then}. ` +
|
|
256
|
-
`The link works for ${window}; after that a new one is printed
|
|
275
|
+
`The link works for ${window}; after that a new one is printed.${code}`
|
|
257
276
|
: `${lead}Sign-in is needed. Ask the user how they sign in to Lizard and give them that link from authUrls. ` +
|
|
258
277
|
"Someone who already has an account must use the same method as before: another method opens a second, empty account " +
|
|
259
278
|
"unless both share a verified email. A new user can pick either. " +
|
|
260
|
-
`Once the browser says "CLI authorized", ${then}. The links work for ${window}; after that new ones are printed
|
|
279
|
+
`Once the browser says "CLI authorized", ${then}. The links work for ${window}; after that new ones are printed.${code}`;
|
|
261
280
|
return {
|
|
262
281
|
status: "pending" as const,
|
|
263
282
|
authUrl: single ? authUrls[single]! : authUrlFor(pending.sessionId, opts.flag),
|
|
264
283
|
authUrls,
|
|
265
284
|
expiresAt: new Date(pending.expiresAt).toISOString(),
|
|
285
|
+
...(pending.userCode ? { userCode: pending.userCode } : {}),
|
|
266
286
|
...(opts.nextCommand ? { nextCommand: opts.nextCommand } : {}),
|
|
267
287
|
instruction,
|
|
268
288
|
};
|
|
@@ -329,6 +349,8 @@ export async function signInInteractive(flag?: AuthProvider): Promise<Me> {
|
|
|
329
349
|
["Open one of these links to sign in:", ...methods.map((m) => `${PROVIDER_LABEL[m]}: ${chalk.cyan(authUrlFor(pending.sessionId, m))}`)].join("\n"),
|
|
330
350
|
);
|
|
331
351
|
}
|
|
352
|
+
const codeLine = userCodeLine(pending.userCode);
|
|
353
|
+
if (codeLine) p.log.warn(codeLine);
|
|
332
354
|
|
|
333
355
|
// Ctrl+C at a terminal never reaches onCancel: clack holds stdin raw while it
|
|
334
356
|
// spins and exits on the keypress itself, printing cancelMessage on the way
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text that someone else wrote (log lines, issue titles, comments, file contents from the
|
|
3
|
+
* server) can carry terminal control sequences: OSC 52 writes the clipboard, OSC 8 hides a link
|
|
4
|
+
* behind other text, CSI moves the cursor to overwrite what was printed, \r rewrites a line.
|
|
5
|
+
* Printed to a terminal, such text is shown, never obeyed.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ESC sequences: CSI (ESC [ ... final), OSC (ESC ] ... BEL | ST), DCS/SOS/PM/APC (ESC P|X|^|_ ... ST),
|
|
9
|
+
// and two-byte ESC sequences; plus their 8-bit C1 forms (CSI 0x9b, OSC 0x9d, DCS 0x90, ...).
|
|
10
|
+
const SEQUENCES =
|
|
11
|
+
/\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?|\x1b[PX^_][^\x1b\x9c]*(?:\x1b\\|\x9c)?|\x1b[ -/]*[0-~]|\x9b[0-?]*[ -/]*[@-~]|[\x90\x98\x9d\x9e\x9f][^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?/g;
|
|
12
|
+
// SGR (colors, bold): moves nothing, writes nothing; kept for a service's own colored logs.
|
|
13
|
+
const SGR = /^\x1b\[[0-9;:]*m$/;
|
|
14
|
+
// C0 controls except \t and \n, DEL, and C1 controls.
|
|
15
|
+
const CONTROLS = "[\\x00-\\x08\\x0b-\\x1f\\x7f-\\x9f]";
|
|
16
|
+
// One pass, sequences first, so a kept color code's ESC is not then stripped as a control.
|
|
17
|
+
const ALL = new RegExp(`${SEQUENCES.source}|${CONTROLS}`, "g");
|
|
18
|
+
|
|
19
|
+
/** text without terminal control sequences or control characters (\n and \t stay). */
|
|
20
|
+
export function stripTerminalControls(text: string, opts: { keepColors?: boolean } = {}): string {
|
|
21
|
+
return text.replace(ALL, (m) => (opts.keepColors && SGR.test(m) ? m : ""));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* text made safe for `stream` (stdout by default): stripped when it is a terminal, unchanged
|
|
26
|
+
* when it goes to a file or a pipe (`> log.txt` keeps the bytes the service wrote).
|
|
27
|
+
*/
|
|
28
|
+
export function termSafe(text: unknown, opts: { keepColors?: boolean; stream?: NodeJS.WriteStream } = {}): string {
|
|
29
|
+
const s = text == null ? "" : String(text);
|
|
30
|
+
return (opts.stream ?? process.stdout).isTTY ? stripTerminalControls(s, opts) : s;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** termSafe for text printed through info()/warn() (stderr). */
|
|
34
|
+
export function termSafeErr(text: unknown): string {
|
|
35
|
+
return termSafe(text, { stream: process.stderr });
|
|
36
|
+
}
|
package/src/lib/updater.ts
CHANGED
|
@@ -6,7 +6,7 @@ import os from "node:os";
|
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
import { createPublicKey, verify } from "node:crypto";
|
|
8
8
|
|
|
9
|
-
export const CURRENT_VERSION = "4.0.
|
|
9
|
+
export const CURRENT_VERSION = "4.0.136";
|
|
10
10
|
const RELEASES_API = "https://api.github.com/repos/lizard-build/lizard-cli/releases/latest";
|
|
11
11
|
const RELEASE_BASE = "https://github.com/lizard-build/lizard-cli/releases/latest/download";
|
|
12
12
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
// ── what `lizard up` must not upload by accident ────────────────────────────
|
|
6
|
+
|
|
7
|
+
const SECRET_DIRS = new Set([".ssh", ".aws", ".gnupg"]);
|
|
8
|
+
const SECRET_FILES = new Set([".npmrc", ".pypirc", ".netrc"]);
|
|
9
|
+
const ENV_TEMPLATES = new Set([".env.example", ".env.sample"]);
|
|
10
|
+
|
|
11
|
+
/** A `.env` or `.env.*` file that holds values (not `.env.example` / `.env.sample`). */
|
|
12
|
+
export function isEnvFile(name: string): boolean {
|
|
13
|
+
return (name === ".env" || name.startsWith(".env.")) && !ENV_TEMPLATES.has(name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Credentials and keys that a folder walk would otherwise upload: env files, SSH/AWS/GnuPG
|
|
18
|
+
* folders, package-manager and netrc credentials, Docker's login file, private keys.
|
|
19
|
+
* `rel` is a /-separated path relative to the upload root.
|
|
20
|
+
*/
|
|
21
|
+
export function isSensitivePath(rel: string): boolean {
|
|
22
|
+
const parts = rel.split("/");
|
|
23
|
+
const name = parts[parts.length - 1];
|
|
24
|
+
if (parts.slice(0, -1).some((d) => SECRET_DIRS.has(d))) return true;
|
|
25
|
+
if (SECRET_DIRS.has(name)) return true;
|
|
26
|
+
if (SECRET_FILES.has(name) || isEnvFile(name)) return true;
|
|
27
|
+
if (name === "config.json" && parts[parts.length - 2] === ".docker") return true;
|
|
28
|
+
if (/^id_(rsa|ed25519|ecdsa)/.test(name)) return true;
|
|
29
|
+
const ext = path.extname(name).toLowerCase();
|
|
30
|
+
return ext === ".pem" || ext === ".key";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The home folder or a file system root: a walk from there would upload a whole machine. */
|
|
34
|
+
export function isTooBroadToUpload(dir: string): boolean {
|
|
35
|
+
const real = (p: string) => {
|
|
36
|
+
try {
|
|
37
|
+
return fs.realpathSync(p);
|
|
38
|
+
} catch {
|
|
39
|
+
return path.resolve(p);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const d = real(dir);
|
|
43
|
+
return d === real(os.homedir()) || d === path.parse(d).root;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ── .lizardignore (gitignore syntax) ────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
interface Rule {
|
|
49
|
+
re: RegExp;
|
|
50
|
+
negate: boolean;
|
|
51
|
+
dirOnly: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function globToRegex(glob: string): string {
|
|
55
|
+
let out = "";
|
|
56
|
+
for (let i = 0; i < glob.length; i++) {
|
|
57
|
+
const c = glob[i];
|
|
58
|
+
if (c === "*") {
|
|
59
|
+
if (glob[i + 1] === "*") {
|
|
60
|
+
const atStart = i === 0 || glob[i - 1] === "/";
|
|
61
|
+
const atEnd = i + 2 === glob.length || glob[i + 2] === "/";
|
|
62
|
+
if (atStart && atEnd) {
|
|
63
|
+
if (glob[i + 2] === "/") {
|
|
64
|
+
out += "(?:.*/)?"; // `**/`: any number of folders, including none
|
|
65
|
+
i += 2;
|
|
66
|
+
} else {
|
|
67
|
+
out += ".*"; // trailing `**`: everything inside
|
|
68
|
+
i += 1;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
out += "[^/]*";
|
|
74
|
+
} else if (c === "?") {
|
|
75
|
+
out += "[^/]";
|
|
76
|
+
} else if (c === "[") {
|
|
77
|
+
const close = glob.indexOf("]", i + 2);
|
|
78
|
+
if (close === -1) {
|
|
79
|
+
out += "\\[";
|
|
80
|
+
} else {
|
|
81
|
+
let body = glob.slice(i + 1, close).replace(/\\/g, "\\\\");
|
|
82
|
+
if (body.startsWith("!")) body = "^" + body.slice(1);
|
|
83
|
+
out += `[${body}]`;
|
|
84
|
+
i = close;
|
|
85
|
+
}
|
|
86
|
+
} else if (c === "\\" && i + 1 < glob.length) {
|
|
87
|
+
out += glob[++i].replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
88
|
+
} else {
|
|
89
|
+
out += c.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Parse gitignore-syntax text into a matcher for /-separated paths relative to its folder. */
|
|
96
|
+
export function parseIgnore(text: string): (rel: string, isDir?: boolean) => boolean {
|
|
97
|
+
const rules: Rule[] = [];
|
|
98
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
99
|
+
let line = raw.replace(/(?<!\\)\s+$/, "");
|
|
100
|
+
if (!line || line.startsWith("#")) continue;
|
|
101
|
+
let negate = false;
|
|
102
|
+
if (line.startsWith("!")) {
|
|
103
|
+
negate = true;
|
|
104
|
+
line = line.slice(1);
|
|
105
|
+
} else if (line.startsWith("\\!") || line.startsWith("\\#")) {
|
|
106
|
+
line = line.slice(1);
|
|
107
|
+
}
|
|
108
|
+
let dirOnly = false;
|
|
109
|
+
if (line.endsWith("/")) {
|
|
110
|
+
dirOnly = true;
|
|
111
|
+
line = line.replace(/\/+$/, "");
|
|
112
|
+
}
|
|
113
|
+
if (!line) continue;
|
|
114
|
+
const anchored = line.includes("/");
|
|
115
|
+
line = line.replace(/^\//, "");
|
|
116
|
+
const body = globToRegex(line);
|
|
117
|
+
rules.push({ re: new RegExp(`^${anchored ? "" : "(?:.*/)?"}${body}$`), negate, dirOnly });
|
|
118
|
+
}
|
|
119
|
+
const verdict = (p: string, isDir: boolean): boolean | undefined => {
|
|
120
|
+
let v: boolean | undefined;
|
|
121
|
+
for (const r of rules) if ((!r.dirOnly || isDir) && r.re.test(p)) v = !r.negate;
|
|
122
|
+
return v;
|
|
123
|
+
};
|
|
124
|
+
// As in git: a file inside an ignored folder stays ignored.
|
|
125
|
+
return (rel: string, isDir = false) => {
|
|
126
|
+
const parts = rel.split("/");
|
|
127
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
128
|
+
if (verdict(parts.slice(0, i).join("/"), i < parts.length || isDir)) return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The matcher for `<root>/.lizardignore`, or null when there is none. */
|
|
135
|
+
export function loadLizardIgnore(root: string): ((rel: string, isDir?: boolean) => boolean) | null {
|
|
136
|
+
try {
|
|
137
|
+
return parseIgnore(fs.readFileSync(path.join(root, ".lizardignore"), "utf8"));
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -2,7 +2,7 @@ import { describe, it, expect, afterEach, beforeEach, vi } from "vitest";
|
|
|
2
2
|
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { saveCheckout, sha256, sync, type Checkout } from "../../src/lib/checkout.js";
|
|
5
|
+
import { isMetadataName, saveCheckout, sha256, sync, type Checkout } from "../../src/lib/checkout.js";
|
|
6
6
|
|
|
7
7
|
// A fake Lizard Git that serves one changeset: `tree` maps paths to contents (a symlink is
|
|
8
8
|
// { link: target }). Trees are addressed by a made-up hash, blobs by their sha256.
|
|
@@ -101,3 +101,21 @@ describe("lizard git sync never writes through a symlink", () => {
|
|
|
101
101
|
expect(readFileSync(join(root, "e/x"), "utf8")).toBe("ok");
|
|
102
102
|
});
|
|
103
103
|
});
|
|
104
|
+
|
|
105
|
+
describe("lizard git sync never writes into git metadata", () => {
|
|
106
|
+
it.each([".git", ".GIT", ".Git", ".git.", ".git ", ".git. .", ".git::$INDEX_ALLOCATION", "git~1", "GIT~1", "Git~2", ".g\u200cit",
|
|
107
|
+
".lizard-git", ".LIZARD-GIT", "LIZARD~1"])("%s is metadata", (n) => expect(isMetadataName(n)).toBe(true));
|
|
108
|
+
|
|
109
|
+
it.each([".gitignore", ".gitkeep", ".github", "git", "src", "git~", "my.git"])("%s is an ordinary name", (n) =>
|
|
110
|
+
expect(isMetadataName(n)).toBe(false));
|
|
111
|
+
|
|
112
|
+
it("a changeset with .git paths writes nothing there", async () => {
|
|
113
|
+
mkdirSync(join(root, ".git"));
|
|
114
|
+
const c = checkout({});
|
|
115
|
+
serve({ ".git/hooks/post-checkout": "evil", "GIT~1/config": "evil", "sub/.Git/config": "evil" });
|
|
116
|
+
await sync(root, c).catch(() => {});
|
|
117
|
+
expect(existsSync(join(root, ".git/hooks/post-checkout"))).toBe(false);
|
|
118
|
+
expect(existsSync(join(root, "GIT~1"))).toBe(false);
|
|
119
|
+
expect(existsSync(join(root, "sub/.Git"))).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
});
|
package/test/unit/config.test.ts
CHANGED
|
@@ -3,6 +3,8 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import {
|
|
6
|
+
configDir,
|
|
7
|
+
saveConfig,
|
|
6
8
|
setProjectLink,
|
|
7
9
|
getProjectLink,
|
|
8
10
|
updateProjectLink,
|
|
@@ -121,3 +123,22 @@ describe("ProjectLink schema", () => {
|
|
|
121
123
|
expect(link?.workspaceId).toBeUndefined();
|
|
122
124
|
});
|
|
123
125
|
});
|
|
126
|
+
|
|
127
|
+
describe.skipIf(process.platform === "win32")("config file permissions", () => {
|
|
128
|
+
test("a new config is 0600 in a 0700 folder", () => {
|
|
129
|
+
saveConfig({});
|
|
130
|
+
expect(fs.statSync(configDir()).mode & 0o777).toBe(0o700);
|
|
131
|
+
expect(fs.statSync(path.join(configDir(), "config.json")).mode & 0o777).toBe(0o600);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("an existing world-readable config is fixed on the next write", () => {
|
|
135
|
+
fs.mkdirSync(configDir(), { recursive: true, mode: 0o755 });
|
|
136
|
+
fs.chmodSync(configDir(), 0o755);
|
|
137
|
+
const file = path.join(configDir(), "config.json");
|
|
138
|
+
fs.writeFileSync(file, "{}", { mode: 0o644 });
|
|
139
|
+
fs.chmodSync(file, 0o644);
|
|
140
|
+
saveConfig({});
|
|
141
|
+
expect(fs.statSync(configDir()).mode & 0o777).toBe(0o700);
|
|
142
|
+
expect(fs.statSync(file).mode & 0o777).toBe(0o600);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -5,9 +5,13 @@ import { writableChanges } from "../../src/commands/gha.js";
|
|
|
5
5
|
describe("lizard run: variables that change how programs start are not set locally", () => {
|
|
6
6
|
it.each(["LD_PRELOAD", "LD_LIBRARY_PATH", "DYLD_INSERT_LIBRARIES", "NODE_OPTIONS", "BASH_ENV", "ENV", "PROMPT_COMMAND", "PATH",
|
|
7
7
|
"PYTHONSTARTUP", "PYTHONPATH", "PERL5OPT", "RUBYOPT", "GIT_CONFIG_COUNT", "GIT_CONFIG_KEY_0", "GIT_CONFIG_GLOBAL", "GIT_SSH_COMMAND", "GIT_EXEC_PATH",
|
|
8
|
-
"BASH_FUNC_ls%%"
|
|
8
|
+
"BASH_FUNC_ls%%", "GIT_EXTERNAL_DIFF", "GIT_PAGER", "GIT_EDITOR", "GIT_SEQUENCE_EDITOR", "GIT_PROXY_COMMAND", "GIT_SSH", "GIT_ASKPASS",
|
|
9
|
+
"SSH_ASKPASS", "GOFLAGS", "RUSTC_WRAPPER", "RUSTC", "CARGO_BUILD_RUSTC_WRAPPER", "PYTHONWARNINGS", "JDK_JAVA_OPTIONS", "JAVA_TOOL_OPTIONS",
|
|
10
|
+
"_JAVA_OPTIONS", "DOTNET_STARTUP_HOOKS", "npm_config_script_shell", "NPM_CONFIG_NODE_OPTIONS", "Npm_Config_x", "PHPRC", "PHP_INI_SCAN_DIR",
|
|
11
|
+
"PAGER", "EDITOR", "VISUAL", "LESSOPEN", "LESSCLOSE", "BROWSER", "HTTPS_PROXY", "https_proxy", "http_proxy", "ALL_PROXY", "all_proxy",
|
|
12
|
+
"NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "SSL_CERT_DIR", "REQUESTS_CA_BUNDLE", "CURL_CA_BUNDLE"])("%s is skipped", (n) => expect(isStartupEnvName(n)).toBe(true));
|
|
9
13
|
|
|
10
|
-
it.each(["DATABASE_URL", "NODE_ENV", "PORT", "REDIS_URL", "API_KEY", "PATHNAME", "ENVIRONMENT", "GITHUB_TOKEN"])("%s is set", (n) =>
|
|
14
|
+
it.each(["DATABASE_URL", "NODE_ENV", "PORT", "REDIS_URL", "API_KEY", "PATHNAME", "ENVIRONMENT", "GITHUB_TOKEN", "NO_PROXY", "NPM_TOKEN", "EDITOR_THEME"])("%s is set", (n) =>
|
|
11
15
|
expect(isStartupEnvName(n)).toBe(false));
|
|
12
16
|
});
|
|
13
17
|
|
package/test/unit/login.test.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as path from "node:path";
|
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import { Readable } from "node:stream";
|
|
7
7
|
import { registerLogin, accountState, accountInstruction, nextSteps, nextStepsNote, readTokenFromStdin } from "../../src/commands/login.js";
|
|
8
|
-
import { authUrlFor, providerFlag, pendingPayload } from "../../src/lib/signin.js";
|
|
8
|
+
import { authUrlFor, providerFlag, pendingPayload, cleanUserCode, userCodeLine } from "../../src/lib/signin.js";
|
|
9
9
|
import type { Subscription } from "../../src/commands/billing.js";
|
|
10
10
|
import { requireAuth } from "../../src/lib/auth.js";
|
|
11
11
|
import { APIError, setBaseURL } from "../../src/lib/api.js";
|
|
@@ -157,6 +157,31 @@ describe("sign-in links", () => {
|
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
+
describe("login confirmation code", () => {
|
|
161
|
+
test("a code from the platform is shown and passed to agents", () => {
|
|
162
|
+
const ev = pendingPayload({ sessionId: "s", sessionSecret: "x", expiresAt: Date.now() + 300_000, userCode: "K7QX-M2PA" }, ["github"], "new");
|
|
163
|
+
expect(ev.userCode).toBe("K7QX-M2PA");
|
|
164
|
+
expect(ev.instruction).toContain("K7QX-M2PA");
|
|
165
|
+
expect(userCodeLine("K7QX-M2PA")).toContain("Confirm this code in your browser: ");
|
|
166
|
+
expect(userCodeLine("K7QX-M2PA")).toContain("K7QX-M2PA");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("an older platform sends none: nothing changes", () => {
|
|
170
|
+
const ev = pendingPayload({ sessionId: "s", sessionSecret: "x", expiresAt: Date.now() + 300_000 }, ["github"], "new");
|
|
171
|
+
expect(ev).not.toHaveProperty("userCode");
|
|
172
|
+
expect(ev.instruction).not.toContain("code");
|
|
173
|
+
expect(userCodeLine(undefined)).toBeNull();
|
|
174
|
+
expect(cleanUserCode(undefined)).toBeUndefined();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("only letters, digits and dashes are taken as a code", () => {
|
|
178
|
+
expect(cleanUserCode("K7QX-M2PA")).toBe("K7QX-M2PA");
|
|
179
|
+
expect(cleanUserCode("K7QX\x1b]52;c;aGk=\x07")).toBeUndefined();
|
|
180
|
+
expect(cleanUserCode(42)).toBeUndefined();
|
|
181
|
+
expect(cleanUserCode("")).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
160
185
|
describe("account state", () => {
|
|
161
186
|
test("maps the subscription to what the account still needs", () => {
|
|
162
187
|
expect(accountState(null)).toBe("unknown");
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { stripTerminalControls } from "../../src/lib/terminal.js";
|
|
3
|
+
|
|
4
|
+
describe("text from others is shown, never obeyed by the terminal", () => {
|
|
5
|
+
it.each([
|
|
6
|
+
["OSC 52 clipboard write", "a\x1b]52;c;ZWNobyBoaQ==\x07b", "ab"],
|
|
7
|
+
["OSC 8 hidden link", "\x1b]8;;https://evil\x1b\\click\x1b]8;;\x1b\\", "click"],
|
|
8
|
+
["cursor up + erase line", "ok\x1b[1A\x1b[2Kfake", "okfake"],
|
|
9
|
+
["carriage return overwrite", "real\rfake", "realfake"],
|
|
10
|
+
["8-bit CSI", "a\x9b2Jb", "ab"],
|
|
11
|
+
["DCS", "a\x1bPq#0;2;0;0;0\x1b\\b", "ab"],
|
|
12
|
+
["bell, backspace, DEL", "a\x07\x08\x7fb", "ab"],
|
|
13
|
+
["lone ESC", "a\x1b", "a"],
|
|
14
|
+
["title set", "\x1b]0;pwned\x07x", "x"],
|
|
15
|
+
])("%s", (_n, input, want) => expect(stripTerminalControls(input)).toBe(want));
|
|
16
|
+
|
|
17
|
+
it("keeps newlines, tabs and ordinary text, unicode included", () => {
|
|
18
|
+
expect(stripTerminalControls("a\tb\nc → é 日本")).toBe("a\tb\nc → é 日本");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("colors go unless asked to keep them; with keepColors only colors stay", () => {
|
|
22
|
+
expect(stripTerminalControls("\x1b[31mred\x1b[0m")).toBe("red");
|
|
23
|
+
expect(stripTerminalControls("\x1b[31mred\x1b[0m\x1b[2J\x1b]52;c;x\x07", { keepColors: true })).toBe("\x1b[31mred\x1b[0m");
|
|
24
|
+
});
|
|
25
|
+
});
|