@openinference/cli 1.1.0 → 1.2.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/data/models.json +4 -2
- package/dist/data/models.json +4 -2
- package/dist/hardware.d.ts +3 -0
- package/dist/hardware.d.ts.map +1 -1
- package/dist/hardware.js +18 -7
- package/dist/hardware.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linereader.d.ts +73 -0
- package/dist/linereader.d.ts.map +1 -0
- package/dist/linereader.js +375 -0
- package/dist/linereader.js.map +1 -0
- package/dist/prompt.d.ts +18 -6
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +136 -52
- package/dist/prompt.js.map +1 -1
- package/dist/recommend-run.js +2 -2
- package/dist/recommend-run.js.map +1 -1
- package/dist/recommend.d.ts +1 -1
- package/dist/recommend.d.ts.map +1 -1
- package/dist/recommend.js +5 -5
- package/dist/recommend.js.map +1 -1
- package/dist/setup.d.ts +4 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +58 -30
- package/dist/setup.js.map +1 -1
- package/dist/shell.d.ts.map +1 -1
- package/dist/shell.js +229 -61
- package/dist/shell.js.map +1 -1
- package/dist/use-cases.d.ts.map +1 -1
- package/dist/use-cases.js +5 -22
- package/dist/use-cases.js.map +1 -1
- package/package.json +1 -1
package/data/models.json
CHANGED
|
@@ -357,7 +357,8 @@
|
|
|
357
357
|
"useCase": "code small",
|
|
358
358
|
"categories": [
|
|
359
359
|
"coding"
|
|
360
|
-
]
|
|
360
|
+
],
|
|
361
|
+
"verified": true
|
|
361
362
|
},
|
|
362
363
|
{
|
|
363
364
|
"id": "wizardcoder:3b",
|
|
@@ -596,7 +597,8 @@
|
|
|
596
597
|
"useCase": "code small",
|
|
597
598
|
"categories": [
|
|
598
599
|
"coding"
|
|
599
|
-
]
|
|
600
|
+
],
|
|
601
|
+
"verified": true
|
|
600
602
|
},
|
|
601
603
|
{
|
|
602
604
|
"id": "deepseek-r1:7b",
|
package/dist/data/models.json
CHANGED
|
@@ -357,7 +357,8 @@
|
|
|
357
357
|
"useCase": "code small",
|
|
358
358
|
"categories": [
|
|
359
359
|
"coding"
|
|
360
|
-
]
|
|
360
|
+
],
|
|
361
|
+
"verified": true
|
|
361
362
|
},
|
|
362
363
|
{
|
|
363
364
|
"id": "wizardcoder:3b",
|
|
@@ -596,7 +597,8 @@
|
|
|
596
597
|
"useCase": "code small",
|
|
597
598
|
"categories": [
|
|
598
599
|
"coding"
|
|
599
|
-
]
|
|
600
|
+
],
|
|
601
|
+
"verified": true
|
|
600
602
|
},
|
|
601
603
|
{
|
|
602
604
|
"id": "deepseek-r1:7b",
|
package/dist/hardware.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ export type HardwareProfile = {
|
|
|
2
2
|
ramGb: number;
|
|
3
3
|
cpuCores: number;
|
|
4
4
|
vramGb: number;
|
|
5
|
+
/** A GPU is physically present (any VRAM). Used for display. */
|
|
5
6
|
hasGpu: boolean;
|
|
7
|
+
/** The GPU has enough VRAM to offload models. Used for all sizing decisions. */
|
|
8
|
+
gpuUsable: boolean;
|
|
6
9
|
gpuName: string | null;
|
|
7
10
|
platform: NodeJS.Platform;
|
|
8
11
|
osLabel: string;
|
package/dist/hardware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hardware.d.ts","sourceRoot":"","sources":["../src/hardware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hardware.d.ts","sourceRoot":"","sources":["../src/hardware.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,MAAM,EAAE,OAAO,CAAC;IAChB,gFAAgF;IAChF,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAwEF,wBAAgB,cAAc,IAAI,eAAe,CAqBhD;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,eAAe,GAAG,MAAM,CAM1D;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAKzE"}
|
package/dist/hardware.js
CHANGED
|
@@ -11,6 +11,9 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
11
11
|
const node_os_1 = __importDefault(require("node:os"));
|
|
12
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
13
13
|
const node_child_process_1 = require("node:child_process");
|
|
14
|
+
/** Minimum VRAM (GB) for a GPU to actually help run models. Below this,
|
|
15
|
+
* Ollama falls back to CPU, so a tiny GPU shouldn't change the budget. */
|
|
16
|
+
const MIN_USEFUL_VRAM_GB = 4;
|
|
14
17
|
function roundGb(bytes) {
|
|
15
18
|
return Math.round((bytes / 1024 ** 3) * 10) / 10;
|
|
16
19
|
}
|
|
@@ -65,13 +68,15 @@ function osLabel() {
|
|
|
65
68
|
return `macOS ${rel}`;
|
|
66
69
|
return `${type} ${rel}`;
|
|
67
70
|
}
|
|
68
|
-
function memoryBudgetGb(ramGb,
|
|
71
|
+
function memoryBudgetGb(ramGb, gpuUsable, vramGb) {
|
|
69
72
|
// Scale OS reserve for small cloud VMs (e.g. AWS 4 GB → reports ~3.7 GB)
|
|
70
73
|
const headroom = ramGb <= 4 ? 1.2 : ramGb <= 6 ? 2 : ramGb <= 8 ? 2.5 : 4;
|
|
71
74
|
const ramBudget = Math.max(0.35, ramGb - headroom);
|
|
72
|
-
|
|
75
|
+
// A usable GPU can only *raise* the ceiling (full offload up to VRAM).
|
|
76
|
+
// It must never drop below what the CPU alone could run.
|
|
77
|
+
if (gpuUsable && vramGb > 0) {
|
|
73
78
|
const vramBudget = Math.max(0, vramGb - 0.5);
|
|
74
|
-
return Math.max(vramBudget, ramBudget
|
|
79
|
+
return Math.max(vramBudget, ramBudget);
|
|
75
80
|
}
|
|
76
81
|
return ramBudget;
|
|
77
82
|
}
|
|
@@ -80,13 +85,15 @@ function detectHardware() {
|
|
|
80
85
|
const cpuCores = node_os_1.default.cpus().length;
|
|
81
86
|
const { vramGb, name } = detectVram();
|
|
82
87
|
const hasGpu = vramGb > 0;
|
|
88
|
+
const gpuUsable = vramGb >= MIN_USEFUL_VRAM_GB;
|
|
83
89
|
const diskFreeGb = detectDiskFreeGb();
|
|
84
|
-
const budgetGb = memoryBudgetGb(ramGb,
|
|
90
|
+
const budgetGb = memoryBudgetGb(ramGb, gpuUsable, vramGb);
|
|
85
91
|
return {
|
|
86
92
|
ramGb,
|
|
87
93
|
cpuCores,
|
|
88
94
|
vramGb,
|
|
89
95
|
hasGpu,
|
|
96
|
+
gpuUsable,
|
|
90
97
|
gpuName: name,
|
|
91
98
|
platform: process.platform,
|
|
92
99
|
osLabel: osLabel(),
|
|
@@ -95,9 +102,13 @@ function detectHardware() {
|
|
|
95
102
|
};
|
|
96
103
|
}
|
|
97
104
|
function formatHardware(hw) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
let gpu;
|
|
106
|
+
if (!hw.hasGpu)
|
|
107
|
+
gpu = 'CPU inference';
|
|
108
|
+
else if (hw.gpuUsable)
|
|
109
|
+
gpu = `${hw.gpuName ?? 'GPU'} (${hw.vramGb} GB VRAM)`;
|
|
110
|
+
else
|
|
111
|
+
gpu = `${hw.gpuName ?? 'GPU'} (${hw.vramGb} GB — too small, using CPU)`;
|
|
101
112
|
return `${hw.ramGb} GB RAM · ${hw.cpuCores} cores · ${gpu}`;
|
|
102
113
|
}
|
|
103
114
|
function ollamaModelsPath() {
|
package/dist/hardware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hardware.js","sourceRoot":"","sources":["../src/hardware.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"hardware.js","sourceRoot":"","sources":["../src/hardware.ts"],"names":[],"mappings":";;;;;AA+FA,wCAqBC;AAED,wCAMC;AAED,4CAEC;AAGD,4BAKC;AAxID,sDAAyB;AACzB,sDAAyB;AACzB,0DAA6B;AAC7B,2DAA+C;AAE/C;2EAC2E;AAC3E,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAkB7B,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;AACnD,CAAC;AAED,SAAS,UAAU;IACjB,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,IAAA,8BAAS,EAAC,YAAY,EAAE,CAAC,+BAA+B,EAAE,+BAA+B,CAAC,EAAE;YACpG,QAAQ,EAAE,MAAM;YAChB,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE;YAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAA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AO,GAAG,EAAE,CAAC,KAAK,aAAa,EAAE,CAAC,QAAQ,YAAY,GAAG,EAAE,CAAC;AAC9D,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,mBAAI,CAAC,IAAI,CAAC,iBAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC;AAED,0FAA0F;AAC1F,SAAgB,QAAQ,CAAC,WAAmB,EAAE,UAAkB;IAC9D,IAAI,UAAU,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACjC,MAAM,SAAS,GAAG,UAAU,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,OAAO,UAAU,IAAI,MAAM,CAAC;AAC9B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -100,7 +100,7 @@ setupCmd.action(async (opts) => {
|
|
|
100
100
|
program
|
|
101
101
|
.command('recommend')
|
|
102
102
|
.description('Preview recommendations (no install)')
|
|
103
|
-
.option('-n, --limit <n>', 'number of results', '
|
|
103
|
+
.option('-n, --limit <n>', 'number of results', '5')
|
|
104
104
|
.option('--use-case <id>', 'coding | chat | pdfs | writing | image | research')
|
|
105
105
|
.option('--all', 'full catalog')
|
|
106
106
|
.action((opts) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,qCAAsC;AACtC,mCAAmC;AACnC,mDAA2E;AAC3E,iCAAsD;AACtD,2CAA0C;AAC1C,qCAAuD;AACvD,2CAA2C;AAC3C,yCAA8C;AAC9C,mCAAmC;AACnC,uCAAoC;AAEpC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,SAAS,IAAI,CAAC,CAAU;IACtB,MAAM,G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G,CAAC,mDAAmD,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type Suggestion = {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
/** When true, accepting this item (Enter) runs it immediately; otherwise it
|
|
6
|
+
* just fills the buffer so the user can continue (e.g. add an argument). */
|
|
7
|
+
submit?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type ReaderConfig = {
|
|
10
|
+
/** Colored prompt string (may contain ANSI). */
|
|
11
|
+
prompt: string;
|
|
12
|
+
/** Visible width of the prompt (excluding ANSI codes). */
|
|
13
|
+
promptWidth: number;
|
|
14
|
+
/** Live suggestions for the current buffer; empty array hides the menu. */
|
|
15
|
+
suggest: (buffer: string) => Suggestion[];
|
|
16
|
+
/** Command history, oldest first. */
|
|
17
|
+
history: string[];
|
|
18
|
+
/** Max menu rows to show. */
|
|
19
|
+
maxRows?: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A minimal line editor with a live drop-down suggestion menu (Claude-Code
|
|
23
|
+
* style). Supports inline editing (←/→/Home/End/Backspace), history (↑/↓ when
|
|
24
|
+
* the menu is closed), and Tab/Enter to accept a suggestion.
|
|
25
|
+
*
|
|
26
|
+
* Falls back to plain readline when stdin is not a TTY or OI_SIMPLE is set.
|
|
27
|
+
*/
|
|
28
|
+
export declare class LineReader {
|
|
29
|
+
private cfg;
|
|
30
|
+
private buf;
|
|
31
|
+
private cursor;
|
|
32
|
+
private menu;
|
|
33
|
+
private sel;
|
|
34
|
+
private histIdx;
|
|
35
|
+
private prevTop;
|
|
36
|
+
private onKey?;
|
|
37
|
+
private resolve?;
|
|
38
|
+
constructor(cfg: ReaderConfig);
|
|
39
|
+
private get cols();
|
|
40
|
+
private get maxRows();
|
|
41
|
+
question(): Promise<string | null>;
|
|
42
|
+
/** Fallback: plain readline question (pipes, non-TTY, OI_SIMPLE). */
|
|
43
|
+
private questionSimple;
|
|
44
|
+
private cleanup;
|
|
45
|
+
private commit;
|
|
46
|
+
private handleKey;
|
|
47
|
+
private refreshMenu;
|
|
48
|
+
private accept;
|
|
49
|
+
private historyPrev;
|
|
50
|
+
private historyNext;
|
|
51
|
+
private renderItem;
|
|
52
|
+
/** Box width + the horizontally-scrolled slice of the buffer that is visible. */
|
|
53
|
+
private window;
|
|
54
|
+
private render;
|
|
55
|
+
}
|
|
56
|
+
export type Choice<T> = {
|
|
57
|
+
value: T;
|
|
58
|
+
label: string;
|
|
59
|
+
hint?: string;
|
|
60
|
+
};
|
|
61
|
+
export type SelectConfig<T> = {
|
|
62
|
+
title: string;
|
|
63
|
+
choices: Choice<T>[];
|
|
64
|
+
/** Footer hint; defaults to navigation help. */
|
|
65
|
+
hint?: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Arrow-key list selector (↑/↓ to move, Enter to choose, 1-9 as shortcuts,
|
|
69
|
+
* Ctrl+C to cancel). Falls back to a numbered prompt when stdin is not a TTY
|
|
70
|
+
* or OI_SIMPLE is set. Returns the chosen value, or null if cancelled.
|
|
71
|
+
*/
|
|
72
|
+
export declare function select<T>(cfg: SelectConfig<T>): Promise<T | null>;
|
|
73
|
+
//# sourceMappingURL=linereader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linereader.d.ts","sourceRoot":"","sources":["../src/linereader.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;iFAC6E;IAC7E,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,WAAW,EAAE,MA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,CAAC,CAAC,EAAE,CAAC;IACrB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAuEjE"}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LineReader = void 0;
|
|
7
|
+
exports.select = select;
|
|
8
|
+
const node_readline_1 = __importDefault(require("node:readline"));
|
|
9
|
+
const DIM = '\x1b[2m';
|
|
10
|
+
const RESET = '\x1b[0m';
|
|
11
|
+
const TEAL = '\x1b[38;5;43m';
|
|
12
|
+
/** Truncate a plain (ANSI-free) string so it never wraps the terminal. */
|
|
13
|
+
function clamp(s, max) {
|
|
14
|
+
if (max <= 1)
|
|
15
|
+
return '';
|
|
16
|
+
return s.length > max ? s.slice(0, max - 1) + '…' : s;
|
|
17
|
+
}
|
|
18
|
+
/** Lay out a list row "<indent><marker> <label> <hint>" within `cols`. */
|
|
19
|
+
function listRow(marker, label, hint, cols, on) {
|
|
20
|
+
const avail = Math.max(12, cols - 6); // 3 indent + marker + 2 spacing
|
|
21
|
+
let lab = clamp(label, avail);
|
|
22
|
+
let h = '';
|
|
23
|
+
const rest = avail - lab.length - 2;
|
|
24
|
+
if (hint && rest > 1)
|
|
25
|
+
h = clamp(hint, rest);
|
|
26
|
+
const mark = on ? `${TEAL}${marker}${RESET}` : ' ';
|
|
27
|
+
const labCol = on ? `${TEAL}${lab}${RESET}` : `${DIM}${lab}${RESET}`;
|
|
28
|
+
const hintCol = h ? ` ${DIM}${h}${RESET}` : '';
|
|
29
|
+
return ` ${mark} ${labCol}${hintCol}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A minimal line editor with a live drop-down suggestion menu (Claude-Code
|
|
33
|
+
* style). Supports inline editing (←/→/Home/End/Backspace), history (↑/↓ when
|
|
34
|
+
* the menu is closed), and Tab/Enter to accept a suggestion.
|
|
35
|
+
*
|
|
36
|
+
* Falls back to plain readline when stdin is not a TTY or OI_SIMPLE is set.
|
|
37
|
+
*/
|
|
38
|
+
class LineReader {
|
|
39
|
+
cfg;
|
|
40
|
+
buf = '';
|
|
41
|
+
cursor = 0;
|
|
42
|
+
menu = [];
|
|
43
|
+
sel = 0;
|
|
44
|
+
histIdx;
|
|
45
|
+
prevTop = 0; // rows from top of block to terminal cursor at last render
|
|
46
|
+
onKey;
|
|
47
|
+
resolve;
|
|
48
|
+
constructor(cfg) {
|
|
49
|
+
this.cfg = cfg;
|
|
50
|
+
this.histIdx = cfg.history.length;
|
|
51
|
+
}
|
|
52
|
+
get cols() {
|
|
53
|
+
return process.stdout.columns || 80;
|
|
54
|
+
}
|
|
55
|
+
get maxRows() {
|
|
56
|
+
return this.cfg.maxRows ?? 8;
|
|
57
|
+
}
|
|
58
|
+
question() {
|
|
59
|
+
const stdin = process.stdin;
|
|
60
|
+
const simple = process.env.OI_SIMPLE === '1' || !stdin.isTTY;
|
|
61
|
+
if (simple)
|
|
62
|
+
return this.questionSimple();
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
this.resolve = resolve;
|
|
65
|
+
this.buf = '';
|
|
66
|
+
this.cursor = 0;
|
|
67
|
+
this.histIdx = this.cfg.history.length;
|
|
68
|
+
this.menu = this.cfg.suggest('');
|
|
69
|
+
this.sel = 0;
|
|
70
|
+
this.prevTop = 0;
|
|
71
|
+
node_readline_1.default.emitKeypressEvents(stdin);
|
|
72
|
+
stdin.setRawMode(true);
|
|
73
|
+
stdin.resume();
|
|
74
|
+
this.onKey = (str, key) => this.handleKey(str, key);
|
|
75
|
+
stdin.on('keypress', this.onKey);
|
|
76
|
+
this.render(true);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Fallback: plain readline question (pipes, non-TTY, OI_SIMPLE). */
|
|
80
|
+
questionSimple() {
|
|
81
|
+
return new Promise((resolve) => {
|
|
82
|
+
const rl = node_readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
83
|
+
rl.question(this.cfg.prompt, (answer) => {
|
|
84
|
+
rl.close();
|
|
85
|
+
resolve(answer);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
cleanup() {
|
|
90
|
+
const stdin = process.stdin;
|
|
91
|
+
if (this.onKey)
|
|
92
|
+
stdin.removeListener('keypress', this.onKey);
|
|
93
|
+
this.onKey = undefined;
|
|
94
|
+
if (stdin.isTTY)
|
|
95
|
+
stdin.setRawMode(false);
|
|
96
|
+
stdin.pause();
|
|
97
|
+
}
|
|
98
|
+
commit() {
|
|
99
|
+
// Erase the input box + menu, echo the entered line, then drop to a fresh line.
|
|
100
|
+
const out = process.stdout;
|
|
101
|
+
if (this.prevTop > 0)
|
|
102
|
+
node_readline_1.default.moveCursor(out, 0, -this.prevTop);
|
|
103
|
+
node_readline_1.default.cursorTo(out, 0);
|
|
104
|
+
node_readline_1.default.clearScreenDown(out);
|
|
105
|
+
out.write(` ${TEAL}›${RESET} ${this.buf}\n`);
|
|
106
|
+
const value = this.buf;
|
|
107
|
+
this.cleanup();
|
|
108
|
+
this.resolve?.(value);
|
|
109
|
+
}
|
|
110
|
+
handleKey(str, key) {
|
|
111
|
+
if (!key)
|
|
112
|
+
return;
|
|
113
|
+
if (key.ctrl && key.name === 'c') {
|
|
114
|
+
process.stdout.write('\n');
|
|
115
|
+
this.cleanup();
|
|
116
|
+
this.resolve?.(null);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (key.ctrl && key.name === 'd' && this.buf === '') {
|
|
120
|
+
process.stdout.write('\n');
|
|
121
|
+
this.cleanup();
|
|
122
|
+
this.resolve?.(null);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const menuOpen = this.menu.length > 0;
|
|
126
|
+
switch (key.name) {
|
|
127
|
+
case 'return':
|
|
128
|
+
case 'enter':
|
|
129
|
+
if (menuOpen) {
|
|
130
|
+
const pick = this.menu[this.sel];
|
|
131
|
+
if (pick) {
|
|
132
|
+
this.buf = pick.value;
|
|
133
|
+
this.cursor = this.buf.length;
|
|
134
|
+
if (pick.submit) {
|
|
135
|
+
this.commit();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.refreshMenu();
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
this.commit();
|
|
143
|
+
return;
|
|
144
|
+
case 'tab':
|
|
145
|
+
if (menuOpen)
|
|
146
|
+
this.accept();
|
|
147
|
+
break;
|
|
148
|
+
case 'escape':
|
|
149
|
+
this.menu = [];
|
|
150
|
+
break;
|
|
151
|
+
case 'up':
|
|
152
|
+
if (menuOpen)
|
|
153
|
+
this.sel = (this.sel - 1 + this.menu.length) % this.menu.length;
|
|
154
|
+
else
|
|
155
|
+
this.historyPrev();
|
|
156
|
+
break;
|
|
157
|
+
case 'down':
|
|
158
|
+
if (menuOpen)
|
|
159
|
+
this.sel = (this.sel + 1) % this.menu.length;
|
|
160
|
+
else
|
|
161
|
+
this.historyNext();
|
|
162
|
+
break;
|
|
163
|
+
case 'left':
|
|
164
|
+
if (this.cursor > 0)
|
|
165
|
+
this.cursor--;
|
|
166
|
+
break;
|
|
167
|
+
case 'right':
|
|
168
|
+
if (this.cursor < this.buf.length)
|
|
169
|
+
this.cursor++;
|
|
170
|
+
break;
|
|
171
|
+
case 'home':
|
|
172
|
+
this.cursor = 0;
|
|
173
|
+
break;
|
|
174
|
+
case 'end':
|
|
175
|
+
this.cursor = this.buf.length;
|
|
176
|
+
break;
|
|
177
|
+
case 'backspace':
|
|
178
|
+
if (this.cursor > 0) {
|
|
179
|
+
this.buf = this.buf.slice(0, this.cursor - 1) + this.buf.slice(this.cursor);
|
|
180
|
+
this.cursor--;
|
|
181
|
+
this.refreshMenu();
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
case 'delete':
|
|
185
|
+
if (this.cursor < this.buf.length) {
|
|
186
|
+
this.buf = this.buf.slice(0, this.cursor) + this.buf.slice(this.cursor + 1);
|
|
187
|
+
this.refreshMenu();
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
// Printable input (including pasted chunks). Ignore control sequences.
|
|
192
|
+
if (str && !key.ctrl && !key.meta) {
|
|
193
|
+
const clean = str.replace(/[\x00-\x1f\x7f]/g, '');
|
|
194
|
+
if (clean) {
|
|
195
|
+
this.buf = this.buf.slice(0, this.cursor) + clean + this.buf.slice(this.cursor);
|
|
196
|
+
this.cursor += clean.length;
|
|
197
|
+
this.refreshMenu();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
this.render();
|
|
203
|
+
}
|
|
204
|
+
refreshMenu() {
|
|
205
|
+
this.menu = this.cfg.suggest(this.buf);
|
|
206
|
+
if (this.sel >= this.menu.length)
|
|
207
|
+
this.sel = 0;
|
|
208
|
+
}
|
|
209
|
+
accept() {
|
|
210
|
+
const pick = this.menu[this.sel];
|
|
211
|
+
if (!pick)
|
|
212
|
+
return;
|
|
213
|
+
this.buf = pick.value;
|
|
214
|
+
this.cursor = this.buf.length;
|
|
215
|
+
this.refreshMenu();
|
|
216
|
+
}
|
|
217
|
+
historyPrev() {
|
|
218
|
+
const h = this.cfg.history;
|
|
219
|
+
if (this.histIdx > 0) {
|
|
220
|
+
this.histIdx--;
|
|
221
|
+
this.buf = h[this.histIdx] ?? '';
|
|
222
|
+
this.cursor = this.buf.length;
|
|
223
|
+
this.menu = [];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
historyNext() {
|
|
227
|
+
const h = this.cfg.history;
|
|
228
|
+
if (this.histIdx < h.length) {
|
|
229
|
+
this.histIdx++;
|
|
230
|
+
this.buf = this.histIdx === h.length ? '' : h[this.histIdx] ?? '';
|
|
231
|
+
this.cursor = this.buf.length;
|
|
232
|
+
this.menu = [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
renderItem(s, i) {
|
|
236
|
+
return listRow('❯', s.label, s.hint, this.cols, i === this.sel);
|
|
237
|
+
}
|
|
238
|
+
/** Box width + the horizontally-scrolled slice of the buffer that is visible. */
|
|
239
|
+
window() {
|
|
240
|
+
const margin = 1; // leading space before the box
|
|
241
|
+
const boxW = Math.max(20, Math.min(this.cols - 2 - margin, 100));
|
|
242
|
+
const prefixW = 3; // " › "
|
|
243
|
+
const avail = boxW - prefixW;
|
|
244
|
+
let off = 0;
|
|
245
|
+
if (this.buf.length > avail) {
|
|
246
|
+
if (this.cursor > avail - 1)
|
|
247
|
+
off = this.cursor - (avail - 1);
|
|
248
|
+
off = Math.min(off, this.buf.length - avail);
|
|
249
|
+
off = Math.max(0, off);
|
|
250
|
+
}
|
|
251
|
+
const text = this.buf.slice(off, off + avail);
|
|
252
|
+
const cursorCol = margin + 1 /* │ */ + prefixW + (this.cursor - off);
|
|
253
|
+
return { boxW, text, cursorCol };
|
|
254
|
+
}
|
|
255
|
+
render(first = false) {
|
|
256
|
+
const out = process.stdout;
|
|
257
|
+
if (!first && this.prevTop > 0)
|
|
258
|
+
node_readline_1.default.moveCursor(out, 0, -this.prevTop);
|
|
259
|
+
node_readline_1.default.cursorTo(out, 0);
|
|
260
|
+
node_readline_1.default.clearScreenDown(out);
|
|
261
|
+
const { boxW, text, cursorCol } = this.window();
|
|
262
|
+
const m = ' '; // margin
|
|
263
|
+
const pad = ' '.repeat(Math.max(0, boxW - 3 - text.length));
|
|
264
|
+
const top = `${m}${DIM}╭${'─'.repeat(boxW)}╮${RESET}`;
|
|
265
|
+
const input = `${m}${DIM}│${RESET} ${TEAL}›${RESET} ${text}${pad}${DIM}│${RESET}`;
|
|
266
|
+
const bottom = `${m}${DIM}╰${'─'.repeat(boxW)}╯${RESET}`;
|
|
267
|
+
out.write(top + '\n');
|
|
268
|
+
out.write(input + '\n');
|
|
269
|
+
out.write(bottom);
|
|
270
|
+
const menu = this.menu.slice(0, this.maxRows);
|
|
271
|
+
if (menu.length) {
|
|
272
|
+
out.write('\n');
|
|
273
|
+
menu.forEach((s, i) => out.write(this.renderItem(s, i) + (i < menu.length - 1 ? '\n' : '')));
|
|
274
|
+
}
|
|
275
|
+
// Move from the last drawn row back up to the input row (row index 1).
|
|
276
|
+
const rowsBelowInput = 1 + menu.length;
|
|
277
|
+
node_readline_1.default.moveCursor(out, 0, -rowsBelowInput);
|
|
278
|
+
node_readline_1.default.cursorTo(out, cursorCol);
|
|
279
|
+
this.prevTop = 1;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.LineReader = LineReader;
|
|
283
|
+
/**
|
|
284
|
+
* Arrow-key list selector (↑/↓ to move, Enter to choose, 1-9 as shortcuts,
|
|
285
|
+
* Ctrl+C to cancel). Falls back to a numbered prompt when stdin is not a TTY
|
|
286
|
+
* or OI_SIMPLE is set. Returns the chosen value, or null if cancelled.
|
|
287
|
+
*/
|
|
288
|
+
function select(cfg) {
|
|
289
|
+
const { title, choices } = cfg;
|
|
290
|
+
if (choices.length === 0)
|
|
291
|
+
return Promise.resolve(null);
|
|
292
|
+
const stdin = process.stdin;
|
|
293
|
+
const simple = process.env.OI_SIMPLE === '1' || !stdin.isTTY;
|
|
294
|
+
if (simple)
|
|
295
|
+
return selectSimple(cfg);
|
|
296
|
+
return new Promise((resolve) => {
|
|
297
|
+
const out = process.stdout;
|
|
298
|
+
let sel = 0;
|
|
299
|
+
const block = 1 + choices.length; // rows from title row to footer row
|
|
300
|
+
const render = (first = false) => {
|
|
301
|
+
const cols = out.columns || 80;
|
|
302
|
+
if (!first)
|
|
303
|
+
node_readline_1.default.moveCursor(out, 0, -block);
|
|
304
|
+
node_readline_1.default.cursorTo(out, 0);
|
|
305
|
+
node_readline_1.default.clearScreenDown(out);
|
|
306
|
+
out.write(clamp(title, cols - 1) + '\n');
|
|
307
|
+
choices.forEach((c, i) => out.write(listRow('❯', c.label, c.hint, cols, i === sel) + '\n'));
|
|
308
|
+
out.write(` ${DIM}${clamp(cfg.hint ?? '↑↓ to move · Enter to select', cols - 4)}${RESET}`);
|
|
309
|
+
};
|
|
310
|
+
const cleanup = () => {
|
|
311
|
+
stdin.removeListener('keypress', onKey);
|
|
312
|
+
if (stdin.isTTY)
|
|
313
|
+
stdin.setRawMode(false);
|
|
314
|
+
out.write('\x1b[?25h'); // show cursor
|
|
315
|
+
stdin.pause();
|
|
316
|
+
};
|
|
317
|
+
const finish = (value) => {
|
|
318
|
+
node_readline_1.default.moveCursor(out, 0, -block);
|
|
319
|
+
node_readline_1.default.cursorTo(out, 0);
|
|
320
|
+
node_readline_1.default.clearScreenDown(out);
|
|
321
|
+
if (value !== null) {
|
|
322
|
+
const chosen = choices.find((c) => c.value === value);
|
|
323
|
+
out.write(`${title} ${TEAL}${chosen?.label ?? ''}${RESET}\n`);
|
|
324
|
+
}
|
|
325
|
+
cleanup();
|
|
326
|
+
resolve(value);
|
|
327
|
+
};
|
|
328
|
+
const onKey = (str, key) => {
|
|
329
|
+
if (!key)
|
|
330
|
+
return;
|
|
331
|
+
if (key.ctrl && key.name === 'c')
|
|
332
|
+
return finish(null);
|
|
333
|
+
switch (key.name) {
|
|
334
|
+
case 'up':
|
|
335
|
+
sel = (sel - 1 + choices.length) % choices.length;
|
|
336
|
+
break;
|
|
337
|
+
case 'down':
|
|
338
|
+
sel = (sel + 1) % choices.length;
|
|
339
|
+
break;
|
|
340
|
+
case 'return':
|
|
341
|
+
case 'enter':
|
|
342
|
+
return finish(choices[sel].value);
|
|
343
|
+
default:
|
|
344
|
+
if (str && /^[1-9]$/.test(str)) {
|
|
345
|
+
const n = parseInt(str, 10);
|
|
346
|
+
if (n <= choices.length)
|
|
347
|
+
return finish(choices[n - 1].value);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
render();
|
|
351
|
+
};
|
|
352
|
+
node_readline_1.default.emitKeypressEvents(stdin);
|
|
353
|
+
stdin.setRawMode(true);
|
|
354
|
+
stdin.resume();
|
|
355
|
+
out.write('\x1b[?25l'); // hide cursor
|
|
356
|
+
stdin.on('keypress', onKey);
|
|
357
|
+
render(true);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function selectSimple(cfg) {
|
|
361
|
+
console.log(cfg.title + '\n');
|
|
362
|
+
cfg.choices.forEach((c, i) => console.log(` ${i + 1}. ${c.label}${c.hint ? ' ' + c.hint : ''}`));
|
|
363
|
+
const rl = node_readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
364
|
+
return new Promise((resolve) => {
|
|
365
|
+
rl.question(`\n Choose (1-${cfg.choices.length}) [1]: `, (ans) => {
|
|
366
|
+
rl.close();
|
|
367
|
+
const n = parseInt(ans.trim() || '1', 10);
|
|
368
|
+
if (!Number.isNaN(n) && n >= 1 && n <= cfg.choices.length)
|
|
369
|
+
resolve(cfg.choices[n - 1].value);
|
|
370
|
+
else
|
|
371
|
+
resolve(cfg.choices[0].value);
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=linereader.js.map
|