@codelia/cli 0.1.85 → 0.1.89
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/auth-VNP4GLGX.js +66 -0
- package/dist/chunk-3YQPBHM7.js +45 -0
- package/dist/chunk-QYWLK4HY.js +156 -0
- package/dist/chunk-S7OVJIGV.js +1052 -0
- package/dist/chunk-YULPYRW7.js +202 -0
- package/dist/index.cjs +3246 -1581
- package/dist/index.js +87 -1628
- package/dist/launch-OTCP4VZR.js +9 -0
- package/dist/launcher-2HVS2HZE.js +19 -0
- package/dist/mcp-GB4CGP6K.js +699 -0
- package/dist/prompt-mode-CNJKMBMF.js +705 -0
- package/dist/session-2EB4JKFW.js +52 -0
- package/dist/update-IM6H3PZR.js +124 -0
- package/package.json +10 -10
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/commands/auth.ts
|
|
2
|
+
import {
|
|
3
|
+
authLockPathFor,
|
|
4
|
+
CODELIA_AUTH_KEYCHAIN_SERVICE,
|
|
5
|
+
CODELIA_MCP_AUTH_KEYCHAIN_SERVICE,
|
|
6
|
+
KeychainError,
|
|
7
|
+
keychainAccountForConfigDir,
|
|
8
|
+
MacOsKeychainClient,
|
|
9
|
+
resolveStoragePaths,
|
|
10
|
+
withAuthStoreLock
|
|
11
|
+
} from "@codelia/storage";
|
|
12
|
+
var USAGE = "usage: codelia auth authorize-keychain";
|
|
13
|
+
var runAuthCommand = async (args) => {
|
|
14
|
+
if (args.length === 1 && ["-h", "--help", "help"].includes(args[0])) {
|
|
15
|
+
console.log(USAGE);
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
if (args.length !== 1 || args[0] !== "authorize-keychain") {
|
|
19
|
+
console.error(USAGE);
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
if (process.platform !== "darwin" || !process.stdin.isTTY || !process.stderr.isTTY) {
|
|
23
|
+
console.error("Run this command from a local macOS terminal.");
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const paths = resolveStoragePaths();
|
|
28
|
+
const client = new MacOsKeychainClient();
|
|
29
|
+
const account = keychainAccountForConfigDir(paths.configDir);
|
|
30
|
+
const probe = await client.probe();
|
|
31
|
+
if (!probe.available) {
|
|
32
|
+
console.error(probe.message);
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
console.error(
|
|
36
|
+
"If macOS requests access, choose Always Allow to authorize Keychain access."
|
|
37
|
+
);
|
|
38
|
+
let failed = false;
|
|
39
|
+
await withAuthStoreLock(authLockPathFor(paths.credentialsDir), async () => {
|
|
40
|
+
for (const service of [
|
|
41
|
+
CODELIA_AUTH_KEYCHAIN_SERVICE,
|
|
42
|
+
CODELIA_MCP_AUTH_KEYCHAIN_SERVICE
|
|
43
|
+
]) {
|
|
44
|
+
try {
|
|
45
|
+
const found = await client.authorize(service, account);
|
|
46
|
+
console.log(
|
|
47
|
+
`${service}: ${found ? "access granted" : "no item found"}`
|
|
48
|
+
);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
failed = true;
|
|
51
|
+
const message = error instanceof KeychainError ? error.message : "Keychain authorization failed.";
|
|
52
|
+
console.error(`${service}: ${message}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return failed ? 1 : 0;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(
|
|
59
|
+
error instanceof KeychainError ? error.message : "Keychain authorization failed."
|
|
60
|
+
);
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
runAuthCommand
|
|
66
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/package-root.ts
|
|
2
|
+
import fsSync from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
var installedCliRoot = (file) => {
|
|
6
|
+
let candidate = file;
|
|
7
|
+
while (path.dirname(candidate) !== candidate) {
|
|
8
|
+
const scope = path.dirname(candidate);
|
|
9
|
+
if (path.basename(candidate) === "cli" && path.basename(scope) === "@codelia" && path.basename(path.dirname(scope)) === "node_modules") {
|
|
10
|
+
return candidate;
|
|
11
|
+
}
|
|
12
|
+
candidate = scope;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
var resolveCliPackageRoot = (scriptPath = process.argv[1]) => {
|
|
17
|
+
if (!scriptPath) return null;
|
|
18
|
+
try {
|
|
19
|
+
const resolvedScriptPath = fsSync.realpathSync(scriptPath);
|
|
20
|
+
const installed = installedCliRoot(resolvedScriptPath);
|
|
21
|
+
if (installed) return installed;
|
|
22
|
+
const scriptDir = path.dirname(resolvedScriptPath);
|
|
23
|
+
if (path.basename(scriptDir) === "dist") {
|
|
24
|
+
return path.dirname(scriptDir);
|
|
25
|
+
}
|
|
26
|
+
return scriptDir;
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var resolveLoadedCliPackageRoot = () => {
|
|
32
|
+
const fromArgv = resolveCliPackageRoot();
|
|
33
|
+
if (fromArgv) return fromArgv;
|
|
34
|
+
const moduleDir = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
35
|
+
return installedCliRoot(moduleDir) ?? (path.basename(moduleDir) === "dist" ? path.dirname(moduleDir) : null);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/version.ts
|
|
39
|
+
var CLI_VERSION = "0.1.89".trim().length > 0 ? "0.1.89" : "0.0.0";
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
resolveCliPackageRoot,
|
|
43
|
+
resolveLoadedCliPackageRoot,
|
|
44
|
+
CLI_VERSION
|
|
45
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UPDATE_NOTICE_FILE_ENV,
|
|
3
|
+
UPDATE_REEXEC_ENV,
|
|
4
|
+
applyUpdate,
|
|
5
|
+
buildStartupNotices,
|
|
6
|
+
computeRegistryId,
|
|
7
|
+
detectInstallMethod,
|
|
8
|
+
isMatchingCheckScope,
|
|
9
|
+
isNewerVersion,
|
|
10
|
+
isValidVersion,
|
|
11
|
+
launcherEntry,
|
|
12
|
+
readUpdateState,
|
|
13
|
+
reexecLauncher,
|
|
14
|
+
removeNoticeFileSync,
|
|
15
|
+
resolveEffectiveChannel,
|
|
16
|
+
resolveRegistryUrl,
|
|
17
|
+
resolveUpdatePaths,
|
|
18
|
+
resolveUpdateSettings,
|
|
19
|
+
runRegistryCheck,
|
|
20
|
+
shouldCheckNow,
|
|
21
|
+
writeStartupNoticeFile
|
|
22
|
+
} from "./chunk-S7OVJIGV.js";
|
|
23
|
+
|
|
24
|
+
// src/update/launch.ts
|
|
25
|
+
import { resolveStoragePaths } from "@codelia/storage";
|
|
26
|
+
var NOOP_LAUNCH_UPDATE_SESSION = {
|
|
27
|
+
tuiEnv: {},
|
|
28
|
+
startBackground: async () => void 0,
|
|
29
|
+
dispose: () => void 0
|
|
30
|
+
};
|
|
31
|
+
var tryResolveRegistryId = (env) => {
|
|
32
|
+
try {
|
|
33
|
+
return computeRegistryId(resolveRegistryUrl(env));
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var prepareTuiLaunch = async (options) => {
|
|
39
|
+
const env = options.env ?? process.env;
|
|
40
|
+
const interactive = options.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
41
|
+
const storage = resolveStoragePaths();
|
|
42
|
+
const paths = resolveUpdatePaths(options.cacheDir ?? storage.cacheDir);
|
|
43
|
+
const configFile = options.configFile ?? storage.configFile;
|
|
44
|
+
const settings = await resolveUpdateSettings({
|
|
45
|
+
env,
|
|
46
|
+
interactive,
|
|
47
|
+
configFile
|
|
48
|
+
});
|
|
49
|
+
const method = options.packageRoot ? detectInstallMethod({
|
|
50
|
+
packageRoot: options.packageRoot,
|
|
51
|
+
env,
|
|
52
|
+
resolveNpm: options.resolveNpm
|
|
53
|
+
}) : null;
|
|
54
|
+
const rawReexecFrom = env[UPDATE_REEXEC_ENV];
|
|
55
|
+
const reexecFrom = isValidVersion(rawReexecFrom) ? rawReexecFrom : void 0;
|
|
56
|
+
if (settings.mode === "off" && !reexecFrom) {
|
|
57
|
+
return { kind: "launch", session: NOOP_LAUNCH_UPDATE_SESSION };
|
|
58
|
+
}
|
|
59
|
+
let state = await readUpdateState(paths.stateFile);
|
|
60
|
+
const currentRegistryId = tryResolveRegistryId(env);
|
|
61
|
+
const effectiveChannel = resolveEffectiveChannel(
|
|
62
|
+
options.currentVersion,
|
|
63
|
+
settings.channel
|
|
64
|
+
);
|
|
65
|
+
const cacheMatchesScope = currentRegistryId !== null && isMatchingCheckScope(state, {
|
|
66
|
+
channel: effectiveChannel,
|
|
67
|
+
configuredChannel: settings.channel,
|
|
68
|
+
registryId: currentRegistryId
|
|
69
|
+
});
|
|
70
|
+
const cachedTarget = cacheMatchesScope ? state.latest_version : void 0;
|
|
71
|
+
const canAutoApply = settings.mode === "auto" && !reexecFrom && Boolean(method?.autoApply.supported) && Boolean(cachedTarget) && isNewerVersion(cachedTarget, options.currentVersion) && state.apply_failure?.version !== cachedTarget;
|
|
72
|
+
if (canAutoApply && method && cachedTarget) {
|
|
73
|
+
const applied = await applyUpdate({
|
|
74
|
+
paths,
|
|
75
|
+
method,
|
|
76
|
+
from: options.currentVersion,
|
|
77
|
+
to: cachedTarget,
|
|
78
|
+
configuredChannel: settings.channel,
|
|
79
|
+
env,
|
|
80
|
+
runner: options.runner,
|
|
81
|
+
now: options.now
|
|
82
|
+
});
|
|
83
|
+
if (applied.status === "installed") {
|
|
84
|
+
const reexec = options.reexec ?? reexecLauncher;
|
|
85
|
+
const exitCode = await reexec({
|
|
86
|
+
entry: launcherEntry(method.packageRoot),
|
|
87
|
+
args: options.args,
|
|
88
|
+
env: {
|
|
89
|
+
...env,
|
|
90
|
+
[UPDATE_REEXEC_ENV]: options.currentVersion
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
if (exitCode !== null) {
|
|
94
|
+
return { kind: "exit", exitCode };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
state = await readUpdateState(paths.stateFile);
|
|
98
|
+
}
|
|
99
|
+
const notices = buildStartupNotices(
|
|
100
|
+
cacheMatchesScope ? state : { version: 1 },
|
|
101
|
+
{
|
|
102
|
+
currentVersion: options.currentVersion,
|
|
103
|
+
mode: settings.mode,
|
|
104
|
+
method,
|
|
105
|
+
reexecFrom
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
let noticeFile = null;
|
|
109
|
+
try {
|
|
110
|
+
noticeFile = await writeStartupNoticeFile(paths, notices);
|
|
111
|
+
} catch {
|
|
112
|
+
noticeFile = null;
|
|
113
|
+
}
|
|
114
|
+
const abortController = new AbortController();
|
|
115
|
+
const startBackground = async () => {
|
|
116
|
+
if (settings.mode === "off" || method?.kind === "development") return;
|
|
117
|
+
const regId = tryResolveRegistryId(env);
|
|
118
|
+
if (!regId) return;
|
|
119
|
+
const latestState = await readUpdateState(paths.stateFile);
|
|
120
|
+
if (!shouldCheckNow(latestState, {
|
|
121
|
+
now: options.now?.(),
|
|
122
|
+
currentVersion: options.currentVersion,
|
|
123
|
+
configuredChannel: settings.channel,
|
|
124
|
+
registryId: regId
|
|
125
|
+
})) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
await runRegistryCheck({
|
|
129
|
+
paths,
|
|
130
|
+
currentVersion: options.currentVersion,
|
|
131
|
+
configuredChannel: settings.channel,
|
|
132
|
+
env,
|
|
133
|
+
fetchImpl: options.fetchImpl,
|
|
134
|
+
signal: abortController.signal,
|
|
135
|
+
now: options.now
|
|
136
|
+
}).catch(() => void 0);
|
|
137
|
+
};
|
|
138
|
+
const dispose = () => {
|
|
139
|
+
abortController.abort();
|
|
140
|
+
removeNoticeFileSync(noticeFile);
|
|
141
|
+
noticeFile = null;
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
kind: "launch",
|
|
145
|
+
session: {
|
|
146
|
+
tuiEnv: noticeFile ? { [UPDATE_NOTICE_FILE_ENV]: noticeFile } : {},
|
|
147
|
+
startBackground,
|
|
148
|
+
dispose
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export {
|
|
154
|
+
NOOP_LAUNCH_UPDATE_SESSION,
|
|
155
|
+
prepareTuiLaunch
|
|
156
|
+
};
|