litmus-cli 1.4.6 → 1.4.7-eng1502.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/README.md +15 -0
- package/dist/commands/init.d.ts +3 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +74 -10
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/submit.d.ts.map +1 -1
- package/dist/commands/submit.js +38 -4
- package/dist/commands/submit.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +2 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/editor.d.ts +73 -0
- package/dist/lib/editor.d.ts.map +1 -0
- package/dist/lib/editor.js +222 -0
- package/dist/lib/editor.js.map +1 -0
- package/dist/lib/select.d.ts +64 -0
- package/dist/lib/select.d.ts.map +1 -0
- package/dist/lib/select.js +170 -0
- package/dist/lib/select.js.map +1 -0
- package/dist/lib/session.d.ts +65 -0
- package/dist/lib/session.d.ts.map +1 -0
- package/dist/lib/session.js +212 -0
- package/dist/lib/session.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opening — and later closing — the candidate's editor on their own machine.
|
|
3
|
+
*
|
|
4
|
+
* `litmus init` offers the editors it can actually launch and opens the
|
|
5
|
+
* assessment in the chosen one; `litmus submit` closes that window again once
|
|
6
|
+
* the work is in, so the agent chat session that was open against the
|
|
7
|
+
* assessment ends with the assessment instead of outliving it.
|
|
8
|
+
*
|
|
9
|
+
* Closing is best-effort and SILENT. Neither VS Code nor Cursor exposes a
|
|
10
|
+
* "close this window" command, so every route here is an OS window-manager
|
|
11
|
+
* trick that can legitimately be unavailable: macOS gates UI scripting behind
|
|
12
|
+
* Accessibility permission, and a Linux box may have neither wmctrl nor
|
|
13
|
+
* xdotool. A candidate who has just submitted should not be handed a warning
|
|
14
|
+
* about a window they can close themselves, so a failure produces no output at
|
|
15
|
+
* all.
|
|
16
|
+
*/
|
|
17
|
+
import os from "os";
|
|
18
|
+
import path from "path";
|
|
19
|
+
import { existsSync } from "fs";
|
|
20
|
+
import { execFileSync, spawn } from "child_process";
|
|
21
|
+
const EDITORS = [
|
|
22
|
+
{ id: "vscode", label: "VS Code", cli: "code", macApp: "Visual Studio Code", macProcess: "Code", processName: "Code" },
|
|
23
|
+
{ id: "cursor", label: "Cursor", cli: "cursor", macApp: "Cursor", macProcess: "Cursor", processName: "Cursor" },
|
|
24
|
+
];
|
|
25
|
+
function onPath(cmd) {
|
|
26
|
+
try {
|
|
27
|
+
if (process.platform === "win32") {
|
|
28
|
+
execFileSync("where.exe", [cmd], { stdio: "ignore", timeout: 5000 });
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// `command -v` rather than `which`: POSIX, and present on the minimal
|
|
32
|
+
// shells some candidates run. cmd is a literal from EDITORS, never input.
|
|
33
|
+
execFileSync("/bin/sh", ["-c", `command -v ${cmd}`], { stdio: "ignore", timeout: 5000 });
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function macAppPath(bundleName) {
|
|
42
|
+
if (process.platform !== "darwin")
|
|
43
|
+
return null;
|
|
44
|
+
for (const base of ["/Applications", path.join(os.homedir(), "Applications")]) {
|
|
45
|
+
const p = path.join(base, `${bundleName}.app`);
|
|
46
|
+
if (existsSync(p))
|
|
47
|
+
return p;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The editors we can actually open on this machine, in menu order. An editor
|
|
53
|
+
* the candidate has installed but never added to PATH still shows up on macOS
|
|
54
|
+
* (we open the bundle directly) — that gap is common enough with Cursor that
|
|
55
|
+
* omitting it would hide the option most candidates want.
|
|
56
|
+
*/
|
|
57
|
+
export function detectEditors() {
|
|
58
|
+
const found = [];
|
|
59
|
+
for (const spec of EDITORS) {
|
|
60
|
+
if (onPath(spec.cli)) {
|
|
61
|
+
found.push({ spec, how: "cli" });
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const appPath = macAppPath(spec.macApp);
|
|
65
|
+
if (appPath)
|
|
66
|
+
found.push({ spec, how: "app", appPath });
|
|
67
|
+
}
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Open `dir` in the chosen editor. Resolves false only when the launcher itself
|
|
72
|
+
* is missing — spawn reports that asynchronously via 'error', so we give it a
|
|
73
|
+
* short grace period rather than reporting success and printing a line that
|
|
74
|
+
* turns out to be a lie. The editor is detached: it outlives the CLI.
|
|
75
|
+
*/
|
|
76
|
+
export function openInEditor(editor, dir) {
|
|
77
|
+
const [cmd, args] = editor.how === "cli" ? [editor.spec.cli, [dir]] : ["open", ["-a", editor.appPath, dir]];
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
let settled = false;
|
|
80
|
+
const done = (ok) => {
|
|
81
|
+
if (!settled) {
|
|
82
|
+
settled = true;
|
|
83
|
+
resolve(ok);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
|
|
88
|
+
child.on("error", () => done(false));
|
|
89
|
+
child.unref();
|
|
90
|
+
setTimeout(() => done(true), 400).unref();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
done(false);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** AppleScript string literal escaping (backslash, then quote). */
|
|
98
|
+
function escapeAppleScript(s) {
|
|
99
|
+
return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
100
|
+
}
|
|
101
|
+
/** PowerShell single-quoted string escaping (double the quote). */
|
|
102
|
+
function escapePowerShell(s) {
|
|
103
|
+
return s.replace(/'/g, "''");
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Close every window of `process` whose title mentions `folderName`, by
|
|
107
|
+
* pressing its close button through the Accessibility API. Editor window titles
|
|
108
|
+
* carry the workspace folder ("index.ts — acme-backend"), so this hits the
|
|
109
|
+
* assessment window and leaves the candidate's other projects alone.
|
|
110
|
+
*
|
|
111
|
+
* Exported for tests: the escaping is the part worth pinning.
|
|
112
|
+
*/
|
|
113
|
+
export function macCloseScript(processName, folderName) {
|
|
114
|
+
const proc = escapeAppleScript(processName);
|
|
115
|
+
const folder = escapeAppleScript(folderName);
|
|
116
|
+
return [
|
|
117
|
+
'tell application "System Events"',
|
|
118
|
+
` if not (exists process "${proc}") then return`,
|
|
119
|
+
` tell process "${proc}"`,
|
|
120
|
+
` repeat with w in (every window whose name contains "${folder}")`,
|
|
121
|
+
" try",
|
|
122
|
+
' perform action "AXPress" of (first button of w whose subrole is "AXCloseButton")',
|
|
123
|
+
" end try",
|
|
124
|
+
" end repeat",
|
|
125
|
+
" end tell",
|
|
126
|
+
"end tell",
|
|
127
|
+
].join("\n");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Windows equivalent. `.Contains` rather than `-like '*x*'` so a folder name
|
|
131
|
+
* with a wildcard character in it can't widen the match. CloseMainWindow is the
|
|
132
|
+
* polite close — an editor with unsaved work still gets to prompt.
|
|
133
|
+
*/
|
|
134
|
+
export function winCloseScript(processName, folderName) {
|
|
135
|
+
const proc = escapePowerShell(processName);
|
|
136
|
+
const folder = escapePowerShell(folderName);
|
|
137
|
+
return (`Get-Process -Name '${proc}' -ErrorAction SilentlyContinue | ` +
|
|
138
|
+
`Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle.Contains('${folder}') } | ` +
|
|
139
|
+
`ForEach-Object { $_.CloseMainWindow() | Out-Null }`);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Launch a close attempt and walk away.
|
|
143
|
+
*
|
|
144
|
+
* MEASURED, and the reason this is detached rather than a sync call: the first
|
|
145
|
+
* UI-scripting attempt on macOS blocks until the candidate answers a system
|
|
146
|
+
* permission dialog — a probe with a 10s cap timed out rather than returning.
|
|
147
|
+
* Waiting on that would freeze `litmus submit` at the exact moment the
|
|
148
|
+
* candidate has been told they are done. Detached, the attempt outlives us and
|
|
149
|
+
* either lands or doesn't; either way submit keeps moving. A new process group
|
|
150
|
+
* also means the hang-up submit sends to the assessment shell moments later
|
|
151
|
+
* doesn't take this with it.
|
|
152
|
+
*/
|
|
153
|
+
function fireAndForget(command, args) {
|
|
154
|
+
try {
|
|
155
|
+
const child = spawn(command, args, { detached: true, stdio: "ignore" });
|
|
156
|
+
child.on("error", () => {
|
|
157
|
+
// Launcher missing (no osascript, no powershell) — nothing to say.
|
|
158
|
+
});
|
|
159
|
+
child.unref();
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Silent by design — see the file header.
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Linux: ask the window manager, if the candidate has wmctrl. */
|
|
166
|
+
function linuxCloseWindow(processName, folderName) {
|
|
167
|
+
// -lx adds WM_CLASS ("code.Code", "cursor.Cursor"), so we can require both the
|
|
168
|
+
// right app and the right title before closing anything.
|
|
169
|
+
const listing = execFileSync("wmctrl", ["-lx"], { encoding: "utf8", timeout: 3000 });
|
|
170
|
+
const wantClass = processName.toLowerCase();
|
|
171
|
+
for (const line of listing.split("\n")) {
|
|
172
|
+
const m = line.match(/^(0x[0-9a-fA-F]+)\s+\S+\s+(\S+)\s+\S+\s+(.*)$/);
|
|
173
|
+
if (!m)
|
|
174
|
+
continue;
|
|
175
|
+
const [, winId, wmClass, title] = m;
|
|
176
|
+
if (!wmClass.toLowerCase().includes(wantClass))
|
|
177
|
+
continue;
|
|
178
|
+
if (!title.includes(folderName))
|
|
179
|
+
continue;
|
|
180
|
+
try {
|
|
181
|
+
execFileSync("wmctrl", ["-ic", winId], { stdio: "ignore", timeout: 5000 });
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// one window refusing to close doesn't stop the rest
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Best-effort, silent close of the assessment's editor window. Every failure
|
|
190
|
+
* mode — no permission, no window manager, editor already quit, window renamed
|
|
191
|
+
* — is a no-op with no output.
|
|
192
|
+
*/
|
|
193
|
+
export function closeEditorWindow(editorId, folderName) {
|
|
194
|
+
const spec = EDITORS.find((e) => e.id === editorId);
|
|
195
|
+
// A one- or two-character folder name would match far too many window titles
|
|
196
|
+
// to be safe to close on.
|
|
197
|
+
if (!spec || folderName.trim().length < 3)
|
|
198
|
+
return;
|
|
199
|
+
try {
|
|
200
|
+
if (process.platform === "darwin") {
|
|
201
|
+
fireAndForget("osascript", ["-e", macCloseScript(spec.macProcess, folderName)]);
|
|
202
|
+
}
|
|
203
|
+
else if (process.platform === "win32") {
|
|
204
|
+
fireAndForget("powershell.exe", [
|
|
205
|
+
"-NoProfile",
|
|
206
|
+
"-NonInteractive",
|
|
207
|
+
"-Command",
|
|
208
|
+
winCloseScript(spec.processName, folderName),
|
|
209
|
+
]);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
// The X11 route needs the window list back before it can close anything,
|
|
213
|
+
// so it is the one synchronous path — wmctrl answers immediately and asks
|
|
214
|
+
// no permission of anyone.
|
|
215
|
+
linuxCloseWindow(spec.processName, folderName);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// Silent by design — see the file header.
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../../src/lib/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,E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B,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QAChD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0CAA0C;IAC5C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single-choice arrow-key picker for the candidate-facing prompts.
|
|
3
|
+
*
|
|
4
|
+
* Written by hand rather than pulled from a prompt library: the CLI ships to
|
|
5
|
+
* candidates' machines, so every dependency is one more thing that can fail to
|
|
6
|
+
* install on an unknown Node/npm. The surface here is one function.
|
|
7
|
+
*
|
|
8
|
+
* Non-interactive stdin (piped, CI, the watcher's auto-submit) never blocks —
|
|
9
|
+
* `select` resolves to null immediately and the caller falls back to printing
|
|
10
|
+
* instructions.
|
|
11
|
+
*/
|
|
12
|
+
export interface SelectChoice<T> {
|
|
13
|
+
value: T;
|
|
14
|
+
label: string;
|
|
15
|
+
/** Dim trailing text — e.g. "not installed", "recommended". */
|
|
16
|
+
hint?: string;
|
|
17
|
+
}
|
|
18
|
+
export type SelectKey = "up" | "down" | "select" | "abort";
|
|
19
|
+
/**
|
|
20
|
+
* Escape sequence → intent. Exported for tests; there is no other way to
|
|
21
|
+
* exercise key handling without a real TTY.
|
|
22
|
+
*
|
|
23
|
+
* A bare ESC deliberately means nothing. An arrow key IS an ESC followed by two
|
|
24
|
+
* more bytes, and a terminal is free to deliver those bytes in separate reads —
|
|
25
|
+
* so a lone ESC is far more likely to be half an arrow than a candidate asking
|
|
26
|
+
* to dismiss the picker. Dismissing has its own row in the list; navigation
|
|
27
|
+
* that closes the picker at random does not.
|
|
28
|
+
*/
|
|
29
|
+
export declare function decodeKey(seq: string): SelectKey | null;
|
|
30
|
+
/**
|
|
31
|
+
* Pull every complete keypress out of the bytes read so far, and hand back
|
|
32
|
+
* whatever trailing fragment is still the start of a sequence.
|
|
33
|
+
*
|
|
34
|
+
* Reads are not keypresses in either direction: holding an arrow key down
|
|
35
|
+
* coalesces several presses into one read, and a slow link or a multiplexer can
|
|
36
|
+
* split a single arrow across two. The caller carries `pending` into the next
|
|
37
|
+
* read, so a split arrow still arrives as one "up".
|
|
38
|
+
*
|
|
39
|
+
* A fragment that turns out NOT to be a sequence start — ESC then a plain
|
|
40
|
+
* letter — drops just the ESC and re-reads the rest, so the letter is not
|
|
41
|
+
* swallowed along with it.
|
|
42
|
+
*/
|
|
43
|
+
export declare function consumeKeys(buffer: string): {
|
|
44
|
+
keys: SelectKey[];
|
|
45
|
+
pending: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The rendered block, one string per terminal line. Pure, so tests can assert
|
|
49
|
+
* which row carries the pointer without driving a TTY.
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderBlock<T>(title: string, choices: SelectChoice<T>[], active: number): string[];
|
|
52
|
+
/** Whether we can drive a picker at all: both ends must be a TTY. */
|
|
53
|
+
export declare function isInteractive(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Show `title` above `choices` and let the candidate move with ↑/↓ and confirm
|
|
56
|
+
* with enter. Resolves to the chosen value, or to null when the picker can't
|
|
57
|
+
* run at all (non-TTY). Ctrl-C exits with 130 — the same thing an un-swallowed
|
|
58
|
+
* SIGINT would have done.
|
|
59
|
+
*
|
|
60
|
+
* The block is erased on exit, so the caller owns what the candidate is left
|
|
61
|
+
* looking at.
|
|
62
|
+
*/
|
|
63
|
+
export declare function select<T>(title: string, choices: SelectChoice<T>[]): Promise<T | null>;
|
|
64
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/lib/select.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,KAAK,EAAE,CAAC,CAAA;IACR,KAAK,EAAE,MAAM,CAAA;IACb,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;AAK1D;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAkBvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAgBlF;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAelG;AAED,qEAAqE;AACrE,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CA4DtF"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single-choice arrow-key picker for the candidate-facing prompts.
|
|
3
|
+
*
|
|
4
|
+
* Written by hand rather than pulled from a prompt library: the CLI ships to
|
|
5
|
+
* candidates' machines, so every dependency is one more thing that can fail to
|
|
6
|
+
* install on an unknown Node/npm. The surface here is one function.
|
|
7
|
+
*
|
|
8
|
+
* Non-interactive stdin (piped, CI, the watcher's auto-submit) never blocks —
|
|
9
|
+
* `select` resolves to null immediately and the caller falls back to printing
|
|
10
|
+
* instructions.
|
|
11
|
+
*/
|
|
12
|
+
import { stdin, stdout } from "process";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
const ESC = "\u001b";
|
|
15
|
+
const CTRL_C = "\u0003";
|
|
16
|
+
/** The starts of sequences we understand — held back rather than acted on. */
|
|
17
|
+
const SEQUENCE_PREFIXES = new Set([ESC, `${ESC}[`, `${ESC}O`]);
|
|
18
|
+
/**
|
|
19
|
+
* Escape sequence → intent. Exported for tests; there is no other way to
|
|
20
|
+
* exercise key handling without a real TTY.
|
|
21
|
+
*
|
|
22
|
+
* A bare ESC deliberately means nothing. An arrow key IS an ESC followed by two
|
|
23
|
+
* more bytes, and a terminal is free to deliver those bytes in separate reads —
|
|
24
|
+
* so a lone ESC is far more likely to be half an arrow than a candidate asking
|
|
25
|
+
* to dismiss the picker. Dismissing has its own row in the list; navigation
|
|
26
|
+
* that closes the picker at random does not.
|
|
27
|
+
*/
|
|
28
|
+
export function decodeKey(seq) {
|
|
29
|
+
switch (seq) {
|
|
30
|
+
case `${ESC}[A`: // arrow up, normal mode
|
|
31
|
+
case `${ESC}OA`: // arrow up, application mode (tmux, some terminals)
|
|
32
|
+
case "k":
|
|
33
|
+
return "up";
|
|
34
|
+
case `${ESC}[B`:
|
|
35
|
+
case `${ESC}OB`:
|
|
36
|
+
case "j":
|
|
37
|
+
return "down";
|
|
38
|
+
case "\r":
|
|
39
|
+
case "\n":
|
|
40
|
+
return "select";
|
|
41
|
+
case CTRL_C: // raw mode swallows SIGINT, so we handle Ctrl-C ourselves
|
|
42
|
+
return "abort";
|
|
43
|
+
default:
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Pull every complete keypress out of the bytes read so far, and hand back
|
|
49
|
+
* whatever trailing fragment is still the start of a sequence.
|
|
50
|
+
*
|
|
51
|
+
* Reads are not keypresses in either direction: holding an arrow key down
|
|
52
|
+
* coalesces several presses into one read, and a slow link or a multiplexer can
|
|
53
|
+
* split a single arrow across two. The caller carries `pending` into the next
|
|
54
|
+
* read, so a split arrow still arrives as one "up".
|
|
55
|
+
*
|
|
56
|
+
* A fragment that turns out NOT to be a sequence start — ESC then a plain
|
|
57
|
+
* letter — drops just the ESC and re-reads the rest, so the letter is not
|
|
58
|
+
* swallowed along with it.
|
|
59
|
+
*/
|
|
60
|
+
export function consumeKeys(buffer) {
|
|
61
|
+
const keys = [];
|
|
62
|
+
let rest = buffer;
|
|
63
|
+
while (rest.length > 0) {
|
|
64
|
+
const three = rest.length >= 3 ? decodeKey(rest.slice(0, 3)) : null;
|
|
65
|
+
if (three) {
|
|
66
|
+
keys.push(three);
|
|
67
|
+
rest = rest.slice(3);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (SEQUENCE_PREFIXES.has(rest))
|
|
71
|
+
break; // incomplete — wait for the rest
|
|
72
|
+
const one = decodeKey(rest[0]);
|
|
73
|
+
if (one)
|
|
74
|
+
keys.push(one);
|
|
75
|
+
rest = rest.slice(1);
|
|
76
|
+
}
|
|
77
|
+
return { keys, pending: rest };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The rendered block, one string per terminal line. Pure, so tests can assert
|
|
81
|
+
* which row carries the pointer without driving a TTY.
|
|
82
|
+
*/
|
|
83
|
+
export function renderBlock(title, choices, active) {
|
|
84
|
+
const rows = choices.map((c, i) => {
|
|
85
|
+
const on = i === active;
|
|
86
|
+
const pointer = on ? chalk.cyan("❯") : " ";
|
|
87
|
+
const label = on ? chalk.cyan.bold(c.label) : c.label;
|
|
88
|
+
const hint = c.hint ? " " + chalk.dim(c.hint) : "";
|
|
89
|
+
return ` ${pointer} ${label}${hint}`;
|
|
90
|
+
});
|
|
91
|
+
return [
|
|
92
|
+
` ${chalk.bold(title)}`,
|
|
93
|
+
"",
|
|
94
|
+
...rows,
|
|
95
|
+
"",
|
|
96
|
+
chalk.dim(" ↑/↓ to move · enter to choose"),
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
/** Whether we can drive a picker at all: both ends must be a TTY. */
|
|
100
|
+
export function isInteractive() {
|
|
101
|
+
return Boolean(stdin.isTTY && stdout.isTTY && typeof stdin.setRawMode === "function");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Show `title` above `choices` and let the candidate move with ↑/↓ and confirm
|
|
105
|
+
* with enter. Resolves to the chosen value, or to null when the picker can't
|
|
106
|
+
* run at all (non-TTY). Ctrl-C exits with 130 — the same thing an un-swallowed
|
|
107
|
+
* SIGINT would have done.
|
|
108
|
+
*
|
|
109
|
+
* The block is erased on exit, so the caller owns what the candidate is left
|
|
110
|
+
* looking at.
|
|
111
|
+
*/
|
|
112
|
+
export function select(title, choices) {
|
|
113
|
+
if (!isInteractive() || choices.length === 0)
|
|
114
|
+
return Promise.resolve(null);
|
|
115
|
+
let active = 0;
|
|
116
|
+
const lineCount = renderBlock(title, choices, active).length;
|
|
117
|
+
const paint = (first) => {
|
|
118
|
+
if (!first)
|
|
119
|
+
stdout.write(`${ESC}[${lineCount}A`);
|
|
120
|
+
for (const line of renderBlock(title, choices, active)) {
|
|
121
|
+
stdout.write(`${ESC}[2K${line}\n`);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const erase = () => {
|
|
125
|
+
stdout.write(`${ESC}[${lineCount}A${ESC}[0J`);
|
|
126
|
+
};
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
const wasRaw = stdin.isRaw;
|
|
129
|
+
stdout.write(`${ESC}[?25l`); // hide cursor
|
|
130
|
+
stdin.setRawMode(true);
|
|
131
|
+
stdin.resume();
|
|
132
|
+
stdin.setEncoding("utf8");
|
|
133
|
+
paint(true);
|
|
134
|
+
const cleanup = () => {
|
|
135
|
+
stdin.off("data", onData);
|
|
136
|
+
stdin.setRawMode(Boolean(wasRaw));
|
|
137
|
+
stdin.pause();
|
|
138
|
+
stdout.write(`${ESC}[?25h`); // show cursor
|
|
139
|
+
};
|
|
140
|
+
// Carries a half-delivered escape sequence from one read to the next.
|
|
141
|
+
let pending = "";
|
|
142
|
+
const onData = (chunk) => {
|
|
143
|
+
const read = consumeKeys(pending + chunk);
|
|
144
|
+
pending = read.pending;
|
|
145
|
+
for (const key of read.keys) {
|
|
146
|
+
if (key === "up") {
|
|
147
|
+
active = (active - 1 + choices.length) % choices.length;
|
|
148
|
+
paint(false);
|
|
149
|
+
}
|
|
150
|
+
else if (key === "down") {
|
|
151
|
+
active = (active + 1) % choices.length;
|
|
152
|
+
paint(false);
|
|
153
|
+
}
|
|
154
|
+
else if (key === "select") {
|
|
155
|
+
erase();
|
|
156
|
+
cleanup();
|
|
157
|
+
resolve(choices[active].value);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
else if (key === "abort") {
|
|
161
|
+
erase();
|
|
162
|
+
cleanup();
|
|
163
|
+
process.exit(130);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
stdin.on("data", onData);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/lib/select.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,GAAG,GAAG,QAAQ,CAAA;AACpB,MAAM,MAAM,GAAG,QAAQ,CAAA;AAWvB,8EAA8E;AAC9E,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC,CAAA;AAE9D;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,wBAAwB;QACzC,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,oDAAoD;QACrE,KAAK,GAAG;YACN,OAAO,IAAI,CAAA;QACb,KAAK,GAAG,GAAG,IAAI,CAAC;QAChB,KAAK,GAAG,GAAG,IAAI,CAAC;QAChB,KAAK,G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K,CAAC,CAAA;YACzC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;YACtB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBAC5B,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;oBACjB,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAA;oBACvD,KAAK,CAAC,KAAK,CAAC,CAAA;gBACd,CAAC;qBAAM,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;oBAC1B,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAA;oBACtC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACd,CAAC;qBAAM,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;oBAC5B,KAAK,EAAE,CAAA;oBACP,OAAO,EAAE,CAAA;oBACT,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAA;oBAC9B,OAAM;gBACR,CAAC;qBAAM,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;oBAC3B,KAAK,EAAE,CAAA;oBACP,OAAO,EAAE,CAAA;oBACT,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBACnB,CAAC;YACH,CAAC;QACH,CAAC,CAAA;QAED,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The assessment shell — how `litmus init` puts the candidate *inside* their
|
|
3
|
+
* assessment folder, and how `litmus submit` takes them back out.
|
|
4
|
+
*
|
|
5
|
+
* A process cannot change its parent shell's working directory, so "cd into the
|
|
6
|
+
* folder for them" has exactly one honest implementation: init spawns an
|
|
7
|
+
* interactive shell rooted in the assessment directory and waits on it. The
|
|
8
|
+
* candidate works in that shell. When submit succeeds it hangs that shell up,
|
|
9
|
+
* the shell exits, init's wait returns, and the candidate is back at the prompt
|
|
10
|
+
* they started from, in the directory they started in — the `cd ..` they never
|
|
11
|
+
* had to type.
|
|
12
|
+
*
|
|
13
|
+
* Two independent facts have to line up before we signal anything:
|
|
14
|
+
* - LITMUS_ASSESSMENT_SHELL=1 in our own environment, which only a shell we
|
|
15
|
+
* spawned can have set, and
|
|
16
|
+
* - a .litmus/shell.pid written by that same init, for this same folder,
|
|
17
|
+
* naming a process that is genuinely one of our ancestors.
|
|
18
|
+
* Either alone could be stale; together they can only describe the shell we are
|
|
19
|
+
* actually standing in.
|
|
20
|
+
*/
|
|
21
|
+
/** Set in the spawned shell's environment; read back by `litmus submit`. */
|
|
22
|
+
export declare const SHELL_ENV_MARKER = "LITMUS_ASSESSMENT_SHELL";
|
|
23
|
+
/**
|
|
24
|
+
* Whether init should hand the candidate a shell at all. Piped stdin (the e2e
|
|
25
|
+
* suite, a CI script, `litmus init | tee`) must never get one — it would hang
|
|
26
|
+
* forever on a shell nobody can type into.
|
|
27
|
+
*/
|
|
28
|
+
export declare function shouldEnterShell(optIn: boolean | undefined): boolean;
|
|
29
|
+
/** The candidate's own shell, falling back to something that certainly exists. */
|
|
30
|
+
export declare function resolveShell(): {
|
|
31
|
+
command: string;
|
|
32
|
+
args: string[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Drop the candidate into `projectRoot` in their own shell and block until they
|
|
36
|
+
* leave it — by typing exit, or by `litmus submit` hanging it up.
|
|
37
|
+
*
|
|
38
|
+
* Resolves to "submitted" when the folder is gone by the time the shell exits
|
|
39
|
+
* (submit deleted it), "exited" when the candidate just left.
|
|
40
|
+
*
|
|
41
|
+
* Closing the shell has two triggers, because the two cases know different
|
|
42
|
+
* things: an in-shell `litmus submit` signals it directly (instant, and ordered
|
|
43
|
+
* against its own output), while a submit that happens elsewhere — the deadline
|
|
44
|
+
* auto-submit in the watcher, or a second terminal — is noticed here by the
|
|
45
|
+
* assessment folder disappearing.
|
|
46
|
+
*/
|
|
47
|
+
export declare function enterAssessmentShell(projectRoot: string, folderName: string): Promise<"submitted" | "exited">;
|
|
48
|
+
/** The pid init recorded for this folder's shell, if there is one. */
|
|
49
|
+
export declare function readAssessmentShellPid(projectRoot: string): number | null;
|
|
50
|
+
/**
|
|
51
|
+
* Are we running inside the shell init opened for this folder? Both the
|
|
52
|
+
* environment marker and an ancestry check have to agree — see the file header.
|
|
53
|
+
*
|
|
54
|
+
* Callers use this before printing anything about where the candidate will end
|
|
55
|
+
* up, since leaving the shell moves them out of the folder for free.
|
|
56
|
+
*/
|
|
57
|
+
export declare function inAssessmentShell(shellPid: number | null): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* End the assessment shell. Returns true when the hang-up went out.
|
|
60
|
+
*
|
|
61
|
+
* Call this LAST and print nothing after it: the shell hangs up its jobs on the
|
|
62
|
+
* way out, and this process is one of them.
|
|
63
|
+
*/
|
|
64
|
+
export declare function hangUpAssessmentShell(shellPid: number | null): boolean;
|
|
65
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/lib/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAOH,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,4BAA4B,CAAA;AAQzD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAIpE;AAED,kFAAkF;AAClF,wBAAgB,YAAY,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAOlE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,WAAW,GAAG,QAAQ,CAAC,CAmEjC;AAED,sEAAsE;AACtE,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOzE;AA6BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAIlE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAkBtE"}
|