skillio 0.1.11 → 0.1.13

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.
@@ -1,163 +0,0 @@
1
- import {
2
- cyan,
3
- discoverSkills,
4
- getLockPath,
5
- red
6
- } from "./chunk-0qvp6v8g.js";
7
-
8
- // src/commands/picker.ts
9
- import { spawnSync } from "node:child_process";
10
-
11
- // src/utils/list-removable.ts
12
- function listRemovableTargets(input) {
13
- const records = [...discoverSkills(input).values()];
14
- const inLock = [];
15
- const orphan = [];
16
- for (const r of records) {
17
- if (r.sources.includes("lock"))
18
- inLock.push(r.name);
19
- else
20
- orphan.push(r.name);
21
- }
22
- inLock.sort();
23
- orphan.sort();
24
- return { inLock, orphan };
25
- }
26
-
27
- // src/utils/prompt.ts
28
- import { emitKeypressEvents } from "node:readline";
29
- async function select(params) {
30
- const input = params.input ?? process.stdin;
31
- const output = params.output ?? process.stdout;
32
- if (!input.isTTY || !output.isTTY)
33
- return null;
34
- let cursor = 0;
35
- const total = params.options.length;
36
- function render() {
37
- output.write(`${params.title}
38
- `);
39
- for (let i = 0;i < total; i++) {
40
- const opt = params.options[i];
41
- if (!opt)
42
- continue;
43
- const marker = i === cursor ? cyan(">") : " ";
44
- output.write(`${marker} ${opt.label}
45
- `);
46
- }
47
- }
48
- function clear() {
49
- output.write(`\x1B[${total + 1}A\x1B[J`);
50
- }
51
- emitKeypressEvents(input);
52
- if (input.setRawMode)
53
- input.setRawMode(true);
54
- input.resume();
55
- render();
56
- return await new Promise((resolve) => {
57
- const onKey = (_str, key) => {
58
- if (key.ctrl && key.name === "c") {
59
- cleanup();
60
- resolve(null);
61
- return;
62
- }
63
- if (key.name === "escape" || key.name === "q") {
64
- cleanup();
65
- resolve(null);
66
- return;
67
- }
68
- if (key.name === "up" && cursor > 0) {
69
- cursor--;
70
- clear();
71
- render();
72
- return;
73
- }
74
- if (key.name === "down" && cursor < total - 1) {
75
- cursor++;
76
- clear();
77
- render();
78
- return;
79
- }
80
- if (key.name === "return") {
81
- cleanup();
82
- const chosen = params.options[cursor]?.value ?? null;
83
- resolve(chosen);
84
- return;
85
- }
86
- };
87
- function onSigterm() {
88
- cleanup();
89
- resolve(null);
90
- }
91
- function cleanup() {
92
- input.removeListener("keypress", onKey);
93
- process.removeListener("SIGTERM", onSigterm);
94
- if (input.setRawMode)
95
- input.setRawMode(false);
96
- input.pause();
97
- }
98
- process.once("SIGTERM", onSigterm);
99
- input.on("keypress", onKey);
100
- });
101
- }
102
-
103
- // src/commands/picker.ts
104
- var CANCEL = "__cancel__";
105
- async function pickRemoveTarget(args) {
106
- const lockPath = getLockPath(args.global);
107
- const { inLock, orphan } = listRemovableTargets({
108
- isGlobal: args.global,
109
- cwd: process.cwd(),
110
- lockPath
111
- });
112
- if (inLock.length === 0 && orphan.length === 0) {
113
- console.log("No skills found in scope.");
114
- return null;
115
- }
116
- const options = [
117
- ...inLock.map((name) => ({ value: name, label: name })),
118
- ...orphan.map((name) => ({ value: name, label: `${name} ${red("(orphan)")}` })),
119
- { value: CANCEL, label: "cancel" }
120
- ];
121
- const choice = await select({ title: "skillio — pick a skill to remove", options });
122
- if (choice === null || choice === CANCEL)
123
- return null;
124
- return choice;
125
- }
126
- async function runPicker(args) {
127
- const choice = await select({
128
- title: "skillio — pick a command",
129
- options: [
130
- { value: "usage", label: "usage — count of skill invocations" },
131
- { value: "cost", label: "cost — per-skill ambient tokens" },
132
- { value: "list", label: "list — installed skills per source" },
133
- { value: "remove", label: "remove — delete a skill (disk-only; lock with --force-lock)" },
134
- { value: "quit", label: "quit" }
135
- ]
136
- });
137
- if (choice === null || choice === "quit")
138
- return 0;
139
- const cliPath = process.argv[1];
140
- if (!cliPath) {
141
- console.error("skillio: cannot resolve CLI path (process.argv[1] missing)");
142
- return 1;
143
- }
144
- let argv;
145
- if (choice === "remove") {
146
- const target = await pickRemoveTarget(args);
147
- if (target === null)
148
- return 0;
149
- argv = ["rm", target];
150
- } else {
151
- argv = [choice];
152
- }
153
- if (args.global)
154
- argv.push("-g");
155
- const r = spawnSync(process.execPath, [cliPath, ...argv], {
156
- stdio: "inherit",
157
- env: process.env
158
- });
159
- return r.status ?? 0;
160
- }
161
- export {
162
- runPicker
163
- };