@gmickel/gno 1.0.5 → 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/README.md +21 -14
- package/assets/skill/cli-reference.md +105 -5
- package/package.json +1 -1
- package/src/cli/commands/collection/clear-embeddings.ts +6 -1
- package/src/cli/commands/publish.ts +6 -6
- package/src/cli/detach.ts +986 -0
- package/src/cli/errors.ts +42 -5
- package/src/cli/program.ts +687 -30
- package/src/cli/run.ts +11 -3
- package/src/core/user-dirs.ts +86 -0
package/src/cli/run.ts
CHANGED
|
@@ -169,7 +169,10 @@ Run '${CLI_NAME} --help' for full command list.
|
|
|
169
169
|
* No process.exit() - caller sets process.exitCode.
|
|
170
170
|
*/
|
|
171
171
|
export async function runCli(argv: string[]): Promise<number> {
|
|
172
|
-
// Reset global state for clean invocation (important for testing)
|
|
172
|
+
// Reset global state for clean invocation (important for testing).
|
|
173
|
+
// The detach paths (runServeDetach / runDaemonDetach) read argv from
|
|
174
|
+
// Commander's per-invocation `Command.rawArgs` via `resolveCliArgv()`,
|
|
175
|
+
// so no separate process-global capture is needed here.
|
|
173
176
|
resetGlobals();
|
|
174
177
|
|
|
175
178
|
const isJson = argvWantsJson(argv);
|
|
@@ -204,8 +207,13 @@ export async function runCli(argv: string[]): Promise<number> {
|
|
|
204
207
|
} catch (err) {
|
|
205
208
|
// Handle CliError with proper JSON formatting
|
|
206
209
|
if (err instanceof CliError) {
|
|
207
|
-
|
|
208
|
-
|
|
210
|
+
// `silent` is reserved for codes whose exit value carries the meaning
|
|
211
|
+
// (e.g. NOT_RUNNING from `--stop` per spec/cli.md). Skip stderr but
|
|
212
|
+
// still propagate the code.
|
|
213
|
+
if (!err.silent) {
|
|
214
|
+
const output = formatErrorForOutput(err, { json: isJson });
|
|
215
|
+
process.stderr.write(`${output}\n`);
|
|
216
|
+
}
|
|
209
217
|
return exitCodeFor(err);
|
|
210
218
|
}
|
|
211
219
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// node:os homedir: no Bun equivalent.
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
// node:path join/normalize: no Bun path utilities.
|
|
4
|
+
import { join, normalize } from "node:path";
|
|
5
|
+
|
|
6
|
+
interface ResolveDownloadsDirDeps {
|
|
7
|
+
env?: Record<string, string | undefined>;
|
|
8
|
+
homeDir?: string;
|
|
9
|
+
platform?: NodeJS.Platform;
|
|
10
|
+
readTextFile?: (path: string) => Promise<string | null>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const XDG_DOWNLOAD_DIR_REGEX = /^XDG_DOWNLOAD_DIR=(?:"([^"]+)"|([^\r\n#]+))$/mu;
|
|
14
|
+
|
|
15
|
+
function expandEnvPath(
|
|
16
|
+
value: string,
|
|
17
|
+
env: Record<string, string | undefined>,
|
|
18
|
+
homeDir: string
|
|
19
|
+
): string {
|
|
20
|
+
return normalize(
|
|
21
|
+
value
|
|
22
|
+
.trim()
|
|
23
|
+
.replaceAll(/\$HOME|\$\{HOME\}/gu, homeDir)
|
|
24
|
+
.replace(/^~(?=$|[\\/])/u, homeDir)
|
|
25
|
+
.replaceAll(
|
|
26
|
+
/%([^%]+)%/gu,
|
|
27
|
+
(_match, key: string) => env[key] ?? env[key.toUpperCase()] ?? ""
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseXdgDownloadsDir(
|
|
33
|
+
fileContents: string,
|
|
34
|
+
env: Record<string, string | undefined>,
|
|
35
|
+
homeDir: string
|
|
36
|
+
): string | null {
|
|
37
|
+
const match = fileContents.match(XDG_DOWNLOAD_DIR_REGEX);
|
|
38
|
+
const rawValue = match?.[1] ?? match?.[2];
|
|
39
|
+
if (!rawValue) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return expandEnvPath(rawValue, env, homeDir);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function defaultReadTextFile(path: string): Promise<string | null> {
|
|
46
|
+
const file = Bun.file(path);
|
|
47
|
+
if (!(await file.exists())) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return file.text();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function resolveDownloadsDir(
|
|
54
|
+
deps: ResolveDownloadsDirDeps = {}
|
|
55
|
+
): Promise<string> {
|
|
56
|
+
const env = deps.env ?? process.env;
|
|
57
|
+
const platform = deps.platform ?? process.platform;
|
|
58
|
+
const homeDir = deps.homeDir ?? homedir();
|
|
59
|
+
const readTextFile = deps.readTextFile ?? defaultReadTextFile;
|
|
60
|
+
|
|
61
|
+
if (platform === "linux") {
|
|
62
|
+
const explicit = env.XDG_DOWNLOAD_DIR?.trim();
|
|
63
|
+
if (explicit) {
|
|
64
|
+
return expandEnvPath(explicit, env, homeDir);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const xdgConfigHome =
|
|
68
|
+
env.XDG_CONFIG_HOME?.trim() || join(homeDir, ".config");
|
|
69
|
+
const userDirs = await readTextFile(join(xdgConfigHome, "user-dirs.dirs"));
|
|
70
|
+
if (userDirs) {
|
|
71
|
+
const parsed = parseXdgDownloadsDir(userDirs, env, homeDir);
|
|
72
|
+
if (parsed) {
|
|
73
|
+
return parsed;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (platform === "win32") {
|
|
79
|
+
const userProfile = env.USERPROFILE?.trim();
|
|
80
|
+
if (userProfile) {
|
|
81
|
+
return join(userProfile, "Downloads");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return join(homeDir, "Downloads");
|
|
86
|
+
}
|