@codelia/cli 0.1.89 → 0.1.91
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/{chunk-YULPYRW7.js → chunk-3NQYB4G5.js} +100 -26
- package/dist/{chunk-3YQPBHM7.js → chunk-445VMRAL.js} +1 -1
- package/dist/{chunk-S7OVJIGV.js → chunk-BYLYQTEO.js} +93 -87
- package/dist/{chunk-QYWLK4HY.js → chunk-KQTBRN7C.js} +3 -4
- package/dist/index.cjs +313 -139
- package/dist/index.js +6 -6
- package/dist/{launch-OTCP4VZR.js → launch-J7YLNS4R.js} +2 -2
- package/dist/launcher-LZ4ZSKHM.js +23 -0
- package/dist/{prompt-mode-CNJKMBMF.js → prompt-mode-OBNSK4YB.js} +11 -10
- package/dist/{update-IM6H3PZR.js → update-BZKC7YPS.js} +90 -3
- package/package.json +10 -10
- package/dist/launcher-2HVS2HZE.js +0 -19
package/dist/index.cjs
CHANGED
|
@@ -79,7 +79,7 @@ var CLI_VERSION;
|
|
|
79
79
|
var init_version = __esm({
|
|
80
80
|
"src/version.ts"() {
|
|
81
81
|
"use strict";
|
|
82
|
-
CLI_VERSION = "0.1.
|
|
82
|
+
CLI_VERSION = "0.1.91".trim().length > 0 ? "0.1.91" : "0.0.0";
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
|
|
@@ -1530,8 +1530,8 @@ var init_check = __esm({
|
|
|
1530
1530
|
init_registry();
|
|
1531
1531
|
init_semver();
|
|
1532
1532
|
init_state();
|
|
1533
|
-
CHECK_SUCCESS_TTL_MS =
|
|
1534
|
-
CHECK_FAILURE_TTL_MS =
|
|
1533
|
+
CHECK_SUCCESS_TTL_MS = 2 * 60 * 60 * 1e3;
|
|
1534
|
+
CHECK_FAILURE_TTL_MS = 5 * 60 * 1e3;
|
|
1535
1535
|
resolveEffectiveChannel = (currentVersion, configuredChannel) => configuredChannel ?? inferChannelFromVersion(currentVersion);
|
|
1536
1536
|
isMatchingCheckScope = (state, scope) => state.registry_id === scope.registryId && state.channel === scope.channel && state.configured_channel === scope.configuredChannel;
|
|
1537
1537
|
shouldCheckNow = (state, options) => {
|
|
@@ -1851,91 +1851,12 @@ var init_install_method = __esm({
|
|
|
1851
1851
|
}
|
|
1852
1852
|
});
|
|
1853
1853
|
|
|
1854
|
-
// src/update/notices.ts
|
|
1855
|
-
var import_node_crypto3, import_node_fs6, import_node_path7, UPDATE_NOTICE_FILE_ENV, STALE_NOTICE_AGE_MS, commandHint, buildStartupNotices, writeStartupNoticeFile, removeNoticeFileSync, cleanupStaleNotices;
|
|
1856
|
-
var init_notices = __esm({
|
|
1857
|
-
"src/update/notices.ts"() {
|
|
1858
|
-
"use strict";
|
|
1859
|
-
import_node_crypto3 = require("crypto");
|
|
1860
|
-
import_node_fs6 = __toESM(require("fs"), 1);
|
|
1861
|
-
import_node_path7 = __toESM(require("path"), 1);
|
|
1862
|
-
init_install_method();
|
|
1863
|
-
init_semver();
|
|
1864
|
-
init_state();
|
|
1865
|
-
UPDATE_NOTICE_FILE_ENV = "CODELIA_UPDATE_NOTICE_FILE";
|
|
1866
|
-
STALE_NOTICE_AGE_MS = 60 * 60 * 1e3;
|
|
1867
|
-
commandHint = (command) => command ? `Update with: ${command}` : "Update using the package manager that installed Codelia.";
|
|
1868
|
-
buildStartupNotices = (state, options) => {
|
|
1869
|
-
const notices = [];
|
|
1870
|
-
if (options.reexecFrom && options.reexecFrom !== options.currentVersion) {
|
|
1871
|
-
notices.push(
|
|
1872
|
-
`Updated Codelia ${options.reexecFrom} -> ${options.currentVersion}.`
|
|
1873
|
-
);
|
|
1874
|
-
}
|
|
1875
|
-
if (options.mode === "off") return notices;
|
|
1876
|
-
const latest = state.latest_version;
|
|
1877
|
-
if (!latest || !isNewerVersion(latest, options.currentVersion)) {
|
|
1878
|
-
return notices;
|
|
1879
|
-
}
|
|
1880
|
-
const channel = state.channel ?? "latest";
|
|
1881
|
-
const command = options.method ? buildUpdateCommand(options.method, { version: latest, channel }) : null;
|
|
1882
|
-
if (state.apply_failure && state.apply_failure.version === latest) {
|
|
1883
|
-
const hint = state.apply_failure.unmanaged ? commandHint(null) : commandHint(command);
|
|
1884
|
-
notices.push(
|
|
1885
|
-
`Automatic update to ${latest} failed (${state.apply_failure.message}). ${hint}`
|
|
1886
|
-
);
|
|
1887
|
-
return notices;
|
|
1888
|
-
}
|
|
1889
|
-
if (options.mode === "notify" || !options.method?.autoApply.supported) {
|
|
1890
|
-
const hint = options.method?.autoApply.supported ? "Run `codelia update` to install." : commandHint(command);
|
|
1891
|
-
notices.push(
|
|
1892
|
-
`Update available: ${options.currentVersion} -> ${latest}. ${hint}`
|
|
1893
|
-
);
|
|
1894
|
-
}
|
|
1895
|
-
return notices;
|
|
1896
|
-
};
|
|
1897
|
-
writeStartupNoticeFile = async (paths, notices) => {
|
|
1898
|
-
if (notices.length === 0) return null;
|
|
1899
|
-
await import_node_fs6.promises.mkdir(paths.noticesDir, { recursive: true, mode: 448 });
|
|
1900
|
-
void cleanupStaleNotices(paths.noticesDir);
|
|
1901
|
-
const file = import_node_path7.default.join(
|
|
1902
|
-
paths.noticesDir,
|
|
1903
|
-
`notice-${process.pid}-${(0, import_node_crypto3.randomBytes)(4).toString("hex")}.json`
|
|
1904
|
-
);
|
|
1905
|
-
await writeJsonAtomic(file, { notices: [...notices] });
|
|
1906
|
-
return file;
|
|
1907
|
-
};
|
|
1908
|
-
removeNoticeFileSync = (file) => {
|
|
1909
|
-
if (!file) return;
|
|
1910
|
-
try {
|
|
1911
|
-
import_node_fs6.default.rmSync(file, { force: true });
|
|
1912
|
-
} catch {
|
|
1913
|
-
}
|
|
1914
|
-
};
|
|
1915
|
-
cleanupStaleNotices = async (dir) => {
|
|
1916
|
-
try {
|
|
1917
|
-
const cutoff = Date.now() - STALE_NOTICE_AGE_MS;
|
|
1918
|
-
const entries = await import_node_fs6.promises.readdir(dir);
|
|
1919
|
-
for (const entry of entries) {
|
|
1920
|
-
if (!entry.startsWith("notice-") || !entry.endsWith(".json")) continue;
|
|
1921
|
-
const full = import_node_path7.default.join(dir, entry);
|
|
1922
|
-
const stat = await import_node_fs6.promises.lstat(full).catch(() => null);
|
|
1923
|
-
if (stat?.isFile() && stat.mtimeMs < cutoff) {
|
|
1924
|
-
await import_node_fs6.promises.rm(full, { force: true }).catch(() => void 0);
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
} catch {
|
|
1928
|
-
}
|
|
1929
|
-
};
|
|
1930
|
-
}
|
|
1931
|
-
});
|
|
1932
|
-
|
|
1933
1854
|
// src/update/settings.ts
|
|
1934
|
-
var
|
|
1855
|
+
var import_node_fs6, import_config_loader4, isRecord3, isCiEnvironment, parseEnvMode, readGlobalUpdateConfig, resolveUpdateSettings;
|
|
1935
1856
|
var init_settings = __esm({
|
|
1936
1857
|
"src/update/settings.ts"() {
|
|
1937
1858
|
"use strict";
|
|
1938
|
-
|
|
1859
|
+
import_node_fs6 = require("fs");
|
|
1939
1860
|
import_config_loader4 = require("@codelia/config-loader");
|
|
1940
1861
|
isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1941
1862
|
isCiEnvironment = (env) => {
|
|
@@ -1964,18 +1885,21 @@ var init_settings = __esm({
|
|
|
1964
1885
|
const warnings = [];
|
|
1965
1886
|
let rawText;
|
|
1966
1887
|
try {
|
|
1967
|
-
rawText = await
|
|
1968
|
-
} catch {
|
|
1969
|
-
return { warnings };
|
|
1888
|
+
rawText = await import_node_fs6.promises.readFile(configFile, "utf8");
|
|
1889
|
+
} catch (error) {
|
|
1890
|
+
return { modeUnset: isRecord3(error) && error.code === "ENOENT", warnings };
|
|
1970
1891
|
}
|
|
1971
1892
|
let parsed;
|
|
1972
1893
|
try {
|
|
1973
1894
|
parsed = JSON.parse(rawText);
|
|
1974
1895
|
} catch {
|
|
1975
|
-
return { warnings };
|
|
1896
|
+
return { modeUnset: false, warnings };
|
|
1897
|
+
}
|
|
1898
|
+
if (!isRecord3(parsed)) {
|
|
1899
|
+
return { modeUnset: false, warnings };
|
|
1976
1900
|
}
|
|
1977
|
-
if (!isRecord3(parsed
|
|
1978
|
-
return { warnings };
|
|
1901
|
+
if (!isRecord3(parsed.update)) {
|
|
1902
|
+
return { modeUnset: parsed.update === void 0, warnings };
|
|
1979
1903
|
}
|
|
1980
1904
|
const update = parsed.update;
|
|
1981
1905
|
let mode;
|
|
@@ -1997,7 +1921,7 @@ var init_settings = __esm({
|
|
|
1997
1921
|
);
|
|
1998
1922
|
}
|
|
1999
1923
|
}
|
|
2000
|
-
return { mode, channel, warnings };
|
|
1924
|
+
return { mode, modeUnset: update.mode === void 0, channel, warnings };
|
|
2001
1925
|
};
|
|
2002
1926
|
resolveUpdateSettings = async (options) => {
|
|
2003
1927
|
const env = options.env ?? process.env;
|
|
@@ -2022,11 +1946,170 @@ var init_settings = __esm({
|
|
|
2022
1946
|
);
|
|
2023
1947
|
}
|
|
2024
1948
|
}
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
1949
|
+
const savedMode = fromConfig.mode ?? "notify";
|
|
1950
|
+
const disabled = !options.interactive || isCiEnvironment(env);
|
|
1951
|
+
return {
|
|
1952
|
+
mode: disabled ? "off" : envMode.value ?? savedMode,
|
|
1953
|
+
savedMode,
|
|
1954
|
+
offerModeChoice: !disabled && fromConfig.modeUnset && !envMode.value && !envMode.invalid,
|
|
1955
|
+
modeSource: disabled ? "disabled" : envMode.value ? "environment" : "config",
|
|
1956
|
+
channel,
|
|
1957
|
+
warnings
|
|
1958
|
+
};
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
|
|
1963
|
+
// src/update/control.ts
|
|
1964
|
+
var import_config_loader5, import_storage6, runUpdateControl;
|
|
1965
|
+
var init_control = __esm({
|
|
1966
|
+
"src/update/control.ts"() {
|
|
1967
|
+
"use strict";
|
|
1968
|
+
import_config_loader5 = require("@codelia/config-loader");
|
|
1969
|
+
import_storage6 = require("@codelia/storage");
|
|
1970
|
+
init_check();
|
|
1971
|
+
init_install_method();
|
|
1972
|
+
init_registry();
|
|
1973
|
+
init_semver();
|
|
1974
|
+
init_settings();
|
|
1975
|
+
init_state();
|
|
1976
|
+
runUpdateControl = async (args2, options, out, err) => {
|
|
1977
|
+
const save = args2[0] === "--tui-set-mode";
|
|
1978
|
+
const mode = save && args2.length === 2 ? (0, import_config_loader5.parseUpdateMode)(args2[1]) : void 0;
|
|
1979
|
+
if (!mode && !(args2.length === 1 && args2[0] === "--tui-status")) {
|
|
1980
|
+
err("Invalid update settings request.");
|
|
1981
|
+
return 1;
|
|
1982
|
+
}
|
|
1983
|
+
const storage = (0, import_storage6.resolveStoragePaths)();
|
|
1984
|
+
const configFile = options.configFile ?? storage.configFile;
|
|
1985
|
+
if (mode) {
|
|
1986
|
+
try {
|
|
1987
|
+
await (0, import_config_loader5.updateConfigValue)(configFile, ["update", "mode"], mode);
|
|
1988
|
+
} catch {
|
|
1989
|
+
err(
|
|
1990
|
+
"Could not save the global update mode. Check the config and its permissions."
|
|
1991
|
+
);
|
|
1992
|
+
return 1;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
const settings = await resolveUpdateSettings({
|
|
1996
|
+
configFile,
|
|
1997
|
+
env: options.env,
|
|
1998
|
+
interactive: true
|
|
1999
|
+
});
|
|
2000
|
+
const channel = resolveEffectiveChannel(
|
|
2001
|
+
options.currentVersion,
|
|
2002
|
+
settings.channel
|
|
2003
|
+
);
|
|
2004
|
+
const paths = resolveUpdatePaths(options.cacheDir ?? storage.cacheDir);
|
|
2005
|
+
const state = await readUpdateState(paths.stateFile);
|
|
2006
|
+
let candidate = null;
|
|
2007
|
+
try {
|
|
2008
|
+
const registryId = computeRegistryId(resolveRegistryUrl(options.env));
|
|
2009
|
+
if (isMatchingCheckScope(state, {
|
|
2010
|
+
channel,
|
|
2011
|
+
configuredChannel: settings.channel,
|
|
2012
|
+
registryId
|
|
2013
|
+
}) && state.latest_version && isNewerVersion(state.latest_version, options.currentVersion)) {
|
|
2014
|
+
candidate = state.latest_version;
|
|
2015
|
+
}
|
|
2016
|
+
} catch {
|
|
2017
|
+
}
|
|
2018
|
+
const method = options.packageRoot ? detectInstallMethod({
|
|
2019
|
+
packageRoot: options.packageRoot,
|
|
2020
|
+
env: options.env,
|
|
2021
|
+
resolveNpm: options.resolveNpm
|
|
2022
|
+
}) : null;
|
|
2023
|
+
out(
|
|
2024
|
+
JSON.stringify({
|
|
2025
|
+
current_version: options.currentVersion,
|
|
2026
|
+
channel,
|
|
2027
|
+
candidate,
|
|
2028
|
+
saved_mode: settings.savedMode,
|
|
2029
|
+
effective_mode: settings.mode,
|
|
2030
|
+
mode_source: settings.modeSource,
|
|
2031
|
+
auto_apply_supported: method?.autoApply.supported ?? false
|
|
2032
|
+
})
|
|
2033
|
+
);
|
|
2034
|
+
return 0;
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
});
|
|
2038
|
+
|
|
2039
|
+
// src/update/notices.ts
|
|
2040
|
+
var import_node_crypto3, import_node_fs7, import_node_path7, STALE_NOTICE_AGE_MS, commandHint, buildStartupNotices, writeStartupNoticeFile, removeNoticeFileSync, cleanupStaleNotices;
|
|
2041
|
+
var init_notices = __esm({
|
|
2042
|
+
"src/update/notices.ts"() {
|
|
2043
|
+
"use strict";
|
|
2044
|
+
import_node_crypto3 = require("crypto");
|
|
2045
|
+
import_node_fs7 = __toESM(require("fs"), 1);
|
|
2046
|
+
import_node_path7 = __toESM(require("path"), 1);
|
|
2047
|
+
init_install_method();
|
|
2048
|
+
init_semver();
|
|
2049
|
+
init_state();
|
|
2050
|
+
STALE_NOTICE_AGE_MS = 60 * 60 * 1e3;
|
|
2051
|
+
commandHint = (command) => command ? `Update with: ${command}` : "Update using the package manager that installed Codelia.";
|
|
2052
|
+
buildStartupNotices = (state, options) => {
|
|
2053
|
+
const notices = [];
|
|
2054
|
+
if (options.reexecFrom && options.reexecFrom !== options.currentVersion) {
|
|
2055
|
+
notices.push(
|
|
2056
|
+
`Updated Codelia ${options.reexecFrom} -> ${options.currentVersion}.`
|
|
2057
|
+
);
|
|
2058
|
+
}
|
|
2059
|
+
if (options.mode === "off") return notices;
|
|
2060
|
+
const latest = state.latest_version;
|
|
2061
|
+
if (!latest || !isNewerVersion(latest, options.currentVersion)) {
|
|
2062
|
+
return notices;
|
|
2063
|
+
}
|
|
2064
|
+
const channel = state.channel ?? "latest";
|
|
2065
|
+
const command = options.method ? buildUpdateCommand(options.method, { version: latest, channel }) : null;
|
|
2066
|
+
if (state.apply_failure && state.apply_failure.version === latest) {
|
|
2067
|
+
const hint = state.apply_failure.unmanaged ? commandHint(null) : commandHint(command);
|
|
2068
|
+
notices.push(
|
|
2069
|
+
`Automatic update to ${latest} failed (${state.apply_failure.message}). ${hint}`
|
|
2070
|
+
);
|
|
2071
|
+
return notices;
|
|
2072
|
+
}
|
|
2073
|
+
if (options.mode === "notify" || !options.method?.autoApply.supported) {
|
|
2074
|
+
const hint = options.method?.autoApply.supported ? "Run `codelia update` to install." : commandHint(command);
|
|
2075
|
+
notices.push(
|
|
2076
|
+
`Update available: ${options.currentVersion} -> ${latest}. ${hint}`
|
|
2077
|
+
);
|
|
2078
|
+
}
|
|
2079
|
+
return notices;
|
|
2080
|
+
};
|
|
2081
|
+
writeStartupNoticeFile = async (paths, notices) => {
|
|
2082
|
+
if (notices.length === 0) return null;
|
|
2083
|
+
await import_node_fs7.promises.mkdir(paths.noticesDir, { recursive: true, mode: 448 });
|
|
2084
|
+
void cleanupStaleNotices(paths.noticesDir);
|
|
2085
|
+
const file = import_node_path7.default.join(
|
|
2086
|
+
paths.noticesDir,
|
|
2087
|
+
`notice-${process.pid}-${(0, import_node_crypto3.randomBytes)(4).toString("hex")}.json`
|
|
2088
|
+
);
|
|
2089
|
+
await writeJsonAtomic(file, { notices: [...notices] });
|
|
2090
|
+
return file;
|
|
2091
|
+
};
|
|
2092
|
+
removeNoticeFileSync = (file) => {
|
|
2093
|
+
if (!file) return;
|
|
2094
|
+
try {
|
|
2095
|
+
import_node_fs7.default.rmSync(file, { force: true });
|
|
2096
|
+
} catch {
|
|
2097
|
+
}
|
|
2098
|
+
};
|
|
2099
|
+
cleanupStaleNotices = async (dir) => {
|
|
2100
|
+
try {
|
|
2101
|
+
const cutoff = Date.now() - STALE_NOTICE_AGE_MS;
|
|
2102
|
+
const entries = await import_node_fs7.promises.readdir(dir);
|
|
2103
|
+
for (const entry of entries) {
|
|
2104
|
+
if (!entry.startsWith("notice-") || !entry.endsWith(".json")) continue;
|
|
2105
|
+
const full = import_node_path7.default.join(dir, entry);
|
|
2106
|
+
const stat = await import_node_fs7.promises.lstat(full).catch(() => null);
|
|
2107
|
+
if (stat?.isFile() && stat.mtimeMs < cutoff) {
|
|
2108
|
+
await import_node_fs7.promises.rm(full, { force: true }).catch(() => void 0);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
} catch {
|
|
2028
2112
|
}
|
|
2029
|
-
return { mode, channel, warnings };
|
|
2030
2113
|
};
|
|
2031
2114
|
}
|
|
2032
2115
|
});
|
|
@@ -2036,15 +2119,16 @@ var update_exports = {};
|
|
|
2036
2119
|
__export(update_exports, {
|
|
2037
2120
|
runUpdateCommand: () => runUpdateCommand
|
|
2038
2121
|
});
|
|
2039
|
-
var import_node_fs8,
|
|
2122
|
+
var import_node_fs8, import_storage7, USAGE2, runUpdateCommand;
|
|
2040
2123
|
var init_update = __esm({
|
|
2041
2124
|
"src/commands/update.ts"() {
|
|
2042
2125
|
"use strict";
|
|
2043
2126
|
import_node_fs8 = require("fs");
|
|
2044
|
-
|
|
2127
|
+
import_storage7 = require("@codelia/storage");
|
|
2045
2128
|
init_package_root();
|
|
2046
2129
|
init_apply();
|
|
2047
2130
|
init_check();
|
|
2131
|
+
init_control();
|
|
2048
2132
|
init_install_method();
|
|
2049
2133
|
init_notices();
|
|
2050
2134
|
init_semver();
|
|
@@ -2055,6 +2139,21 @@ var init_update = __esm({
|
|
|
2055
2139
|
runUpdateCommand = async (args2, deps = {}) => {
|
|
2056
2140
|
const out = deps.out ?? ((line) => console.log(line));
|
|
2057
2141
|
const err = deps.err ?? ((line) => console.error(line));
|
|
2142
|
+
if (args2[0] === "--tui-status" || args2[0] === "--tui-set-mode") {
|
|
2143
|
+
return runUpdateControl(
|
|
2144
|
+
args2,
|
|
2145
|
+
{
|
|
2146
|
+
currentVersion: deps.currentVersion ?? CLI_VERSION,
|
|
2147
|
+
packageRoot: deps.packageRoot === void 0 ? resolveLoadedCliPackageRoot() : deps.packageRoot,
|
|
2148
|
+
configFile: deps.configFile,
|
|
2149
|
+
cacheDir: deps.cacheDir,
|
|
2150
|
+
env: deps.env ?? process.env,
|
|
2151
|
+
resolveNpm: deps.resolveNpm
|
|
2152
|
+
},
|
|
2153
|
+
out,
|
|
2154
|
+
err
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2058
2157
|
if (args2.length === 1 && ["-h", "--help", "help"].includes(args2[0])) {
|
|
2059
2158
|
out(USAGE2);
|
|
2060
2159
|
return 0;
|
|
@@ -2068,7 +2167,7 @@ var init_update = __esm({
|
|
|
2068
2167
|
const currentVersion = deps.currentVersion ?? CLI_VERSION;
|
|
2069
2168
|
const packageRoot2 = deps.packageRoot === void 0 ? resolveLoadedCliPackageRoot() : deps.packageRoot;
|
|
2070
2169
|
const method = packageRoot2 ? detectInstallMethod({ packageRoot: packageRoot2, env, resolveNpm: deps.resolveNpm }) : null;
|
|
2071
|
-
const storagePaths = (0,
|
|
2170
|
+
const storagePaths = (0, import_storage7.resolveStoragePaths)();
|
|
2072
2171
|
const paths = resolveUpdatePaths(deps.cacheDir ?? storagePaths.cacheDir);
|
|
2073
2172
|
await import_node_fs8.promises.mkdir(paths.dir, { recursive: true });
|
|
2074
2173
|
const settings = await resolveUpdateSettings({
|
|
@@ -2158,13 +2257,13 @@ var init_update = __esm({
|
|
|
2158
2257
|
});
|
|
2159
2258
|
|
|
2160
2259
|
// src/atif.ts
|
|
2161
|
-
var import_promises2, import_node_path8,
|
|
2260
|
+
var import_promises2, import_node_path8, import_storage8, asRecord, asString, stringifyContent, normalizeTimestamp, extractInputText, extractModelName, extractSessionId, createStepIdAllocator, pushTextStep, getOrCreateToolStep, extractUsageMetrics, sessionRecordsToAtif, parseSessionJsonl, readSessionJsonl, writeAtifFromSessionJsonl;
|
|
2162
2261
|
var init_atif = __esm({
|
|
2163
2262
|
"src/atif.ts"() {
|
|
2164
2263
|
"use strict";
|
|
2165
2264
|
import_promises2 = require("fs/promises");
|
|
2166
2265
|
import_node_path8 = __toESM(require("path"), 1);
|
|
2167
|
-
|
|
2266
|
+
import_storage8 = require("@codelia/storage");
|
|
2168
2267
|
asRecord = (value) => typeof value === "object" && value !== null ? value : null;
|
|
2169
2268
|
asString = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
2170
2269
|
stringifyContent = (value) => {
|
|
@@ -2371,7 +2470,7 @@ var init_atif = __esm({
|
|
|
2371
2470
|
};
|
|
2372
2471
|
readSessionJsonl = async (filePath) => {
|
|
2373
2472
|
const lines = [];
|
|
2374
|
-
for await (const line of (0,
|
|
2473
|
+
for await (const line of (0, import_storage8.readRunLogLines)(filePath)) lines.push(line);
|
|
2375
2474
|
return parseSessionJsonl(lines.join("\n"));
|
|
2376
2475
|
};
|
|
2377
2476
|
writeAtifFromSessionJsonl = async ({
|
|
@@ -2399,11 +2498,11 @@ __export(launch_exports, {
|
|
|
2399
2498
|
NOOP_LAUNCH_UPDATE_SESSION: () => NOOP_LAUNCH_UPDATE_SESSION,
|
|
2400
2499
|
prepareTuiLaunch: () => prepareTuiLaunch
|
|
2401
2500
|
});
|
|
2402
|
-
var
|
|
2501
|
+
var import_storage9, NOOP_LAUNCH_UPDATE_SESSION, tryResolveRegistryId, prepareTuiLaunch;
|
|
2403
2502
|
var init_launch = __esm({
|
|
2404
2503
|
"src/update/launch.ts"() {
|
|
2405
2504
|
"use strict";
|
|
2406
|
-
|
|
2505
|
+
import_storage9 = require("@codelia/storage");
|
|
2407
2506
|
init_apply();
|
|
2408
2507
|
init_check();
|
|
2409
2508
|
init_install_method();
|
|
@@ -2414,7 +2513,6 @@ var init_launch = __esm({
|
|
|
2414
2513
|
init_settings();
|
|
2415
2514
|
init_state();
|
|
2416
2515
|
NOOP_LAUNCH_UPDATE_SESSION = {
|
|
2417
|
-
tuiEnv: {},
|
|
2418
2516
|
startBackground: async () => void 0,
|
|
2419
2517
|
dispose: () => void 0
|
|
2420
2518
|
};
|
|
@@ -2428,7 +2526,7 @@ var init_launch = __esm({
|
|
|
2428
2526
|
prepareTuiLaunch = async (options) => {
|
|
2429
2527
|
const env = options.env ?? process.env;
|
|
2430
2528
|
const interactive = options.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
2431
|
-
const storage = (0,
|
|
2529
|
+
const storage = (0, import_storage9.resolveStoragePaths)();
|
|
2432
2530
|
const paths = resolveUpdatePaths(options.cacheDir ?? storage.cacheDir);
|
|
2433
2531
|
const configFile = options.configFile ?? storage.configFile;
|
|
2434
2532
|
const settings = await resolveUpdateSettings({
|
|
@@ -2533,7 +2631,8 @@ var init_launch = __esm({
|
|
|
2533
2631
|
return {
|
|
2534
2632
|
kind: "launch",
|
|
2535
2633
|
session: {
|
|
2536
|
-
|
|
2634
|
+
...noticeFile ? { noticeFile } : {},
|
|
2635
|
+
startupConfirmations: settings.offerModeChoice ? ["update-mode"] : [],
|
|
2537
2636
|
startBackground,
|
|
2538
2637
|
dispose
|
|
2539
2638
|
}
|
|
@@ -2545,14 +2644,16 @@ var init_launch = __esm({
|
|
|
2545
2644
|
// src/tui/launcher.ts
|
|
2546
2645
|
var launcher_exports = {};
|
|
2547
2646
|
__export(launcher_exports, {
|
|
2548
|
-
|
|
2647
|
+
TUI_LAUNCH_CONTEXT_FLAG: () => TUI_LAUNCH_CONTEXT_FLAG,
|
|
2648
|
+
buildTuiArgs: () => buildTuiArgs,
|
|
2649
|
+
buildTuiLaunchContext: () => buildTuiLaunchContext,
|
|
2650
|
+
resolveBundledRuntimeLaunch: () => resolveBundledRuntimeLaunch,
|
|
2549
2651
|
resolveOptionalTuiBinaryPath: () => resolveOptionalTuiBinaryPath,
|
|
2550
2652
|
resolvePlatformTuiPackageName: () => resolvePlatformTuiPackageName,
|
|
2551
|
-
resolveRuntimeEnvForTui: () => resolveRuntimeEnvForTui,
|
|
2552
2653
|
resolveTuiCommand: () => resolveTuiCommand,
|
|
2553
2654
|
runTui: () => runTui
|
|
2554
2655
|
});
|
|
2555
|
-
var import_node_child_process3, import_node_fs9, import_node_module, import_node_path9,
|
|
2656
|
+
var import_node_child_process3, import_node_fs9, import_node_module, import_node_path9, import_storage10, resolveTuiBinaryName, TUI_PACKAGE_BY_TARGET, describeError2, splitArgs, isExecutable, initStorage, resolveRuntimeRequireBase, runtimeRequire, resolveBundledRuntimeEntry, resolveInstalledPackageJson, resolvePlatformTuiPackageName, resolveOptionalTuiBinaryPath, resolveBundledRuntimeLaunch, TUI_LAUNCH_CONTEXT_FLAG, buildTuiLaunchContext, TUI_VALUE_FLAGS, isLaunchContextOption, buildTuiArgs, resolveTuiCommand, runTui;
|
|
2556
2657
|
var init_launcher = __esm({
|
|
2557
2658
|
"src/tui/launcher.ts"() {
|
|
2558
2659
|
"use strict";
|
|
@@ -2560,7 +2661,7 @@ var init_launcher = __esm({
|
|
|
2560
2661
|
import_node_fs9 = __toESM(require("fs"), 1);
|
|
2561
2662
|
import_node_module = require("module");
|
|
2562
2663
|
import_node_path9 = __toESM(require("path"), 1);
|
|
2563
|
-
|
|
2664
|
+
import_storage10 = require("@codelia/storage");
|
|
2564
2665
|
init_package_root();
|
|
2565
2666
|
init_launch();
|
|
2566
2667
|
init_launcher_entry();
|
|
@@ -2575,7 +2676,6 @@ var init_launcher = __esm({
|
|
|
2575
2676
|
};
|
|
2576
2677
|
describeError2 = (error) => error instanceof Error ? error.message : String(error);
|
|
2577
2678
|
splitArgs = (value) => value.split(/\s+/).map((part) => part.trim()).filter((part) => part.length > 0);
|
|
2578
|
-
quoteShellWord = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
2579
2679
|
isExecutable = (candidate) => {
|
|
2580
2680
|
try {
|
|
2581
2681
|
import_node_fs9.default.accessSync(candidate, import_node_fs9.default.constants.X_OK);
|
|
@@ -2586,8 +2686,8 @@ var init_launcher = __esm({
|
|
|
2586
2686
|
};
|
|
2587
2687
|
initStorage = async () => {
|
|
2588
2688
|
try {
|
|
2589
|
-
const paths = (0,
|
|
2590
|
-
await (0,
|
|
2689
|
+
const paths = (0, import_storage10.resolveStoragePaths)();
|
|
2690
|
+
await (0, import_storage10.ensureStorageDirs)(paths);
|
|
2591
2691
|
} catch (error) {
|
|
2592
2692
|
console.warn(
|
|
2593
2693
|
`Failed to initialize storage directories: ${describeError2(error)}`
|
|
@@ -2632,29 +2732,97 @@ var init_launcher = __esm({
|
|
|
2632
2732
|
resolveTuiBinaryName(platform)
|
|
2633
2733
|
);
|
|
2634
2734
|
};
|
|
2635
|
-
|
|
2636
|
-
if (env.CODELIA_RUNTIME_CMD || env.CODELIA_RUNTIME_ARGS)
|
|
2637
|
-
return env;
|
|
2638
|
-
}
|
|
2735
|
+
resolveBundledRuntimeLaunch = (env, resolveRuntimeEntry = resolveBundledRuntimeEntry) => {
|
|
2736
|
+
if (env.CODELIA_RUNTIME_CMD || env.CODELIA_RUNTIME_ARGS) return void 0;
|
|
2639
2737
|
const runtimeEntry = resolveRuntimeEntry();
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2738
|
+
return runtimeEntry ? { command: process.execPath, args: [runtimeEntry] } : void 0;
|
|
2739
|
+
};
|
|
2740
|
+
TUI_LAUNCH_CONTEXT_FLAG = "--internal-launch-context";
|
|
2741
|
+
buildTuiLaunchContext = ({
|
|
2742
|
+
env,
|
|
2743
|
+
cliVersion = CLI_VERSION,
|
|
2744
|
+
update = NOOP_LAUNCH_UPDATE_SESSION,
|
|
2745
|
+
launcherEntry: launcherEntry2,
|
|
2746
|
+
resolveRuntimeEntry = resolveBundledRuntimeEntry
|
|
2747
|
+
}) => {
|
|
2748
|
+
const runtime = resolveBundledRuntimeLaunch(env, resolveRuntimeEntry);
|
|
2749
|
+
const version = cliVersion.trim();
|
|
2643
2750
|
return {
|
|
2644
|
-
...
|
|
2645
|
-
|
|
2646
|
-
|
|
2751
|
+
...version ? { cli_version: version } : {},
|
|
2752
|
+
...runtime ? { runtime } : {},
|
|
2753
|
+
...update.noticeFile ? { update_notice_file: update.noticeFile } : {},
|
|
2754
|
+
// Bind update controls to this launcher, not to PATH or the runtime.
|
|
2755
|
+
...launcherEntry2 ? {
|
|
2756
|
+
update_control: {
|
|
2757
|
+
node: process.execPath,
|
|
2758
|
+
entry: import_node_path9.default.resolve(launcherEntry2)
|
|
2759
|
+
}
|
|
2760
|
+
} : {},
|
|
2761
|
+
...update.startupConfirmations?.length ? { startup_confirmations: update.startupConfirmations } : {}
|
|
2647
2762
|
};
|
|
2648
2763
|
};
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2764
|
+
TUI_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
2765
|
+
"--initial-message",
|
|
2766
|
+
"--initial-user-message",
|
|
2767
|
+
"--tui-mode",
|
|
2768
|
+
"--sandbox-mode",
|
|
2769
|
+
"--approval-mode"
|
|
2770
|
+
]);
|
|
2771
|
+
isLaunchContextOption = (arg) => arg.startsWith(`${TUI_LAUNCH_CONTEXT_FLAG}=`);
|
|
2772
|
+
buildTuiArgs = (context, forwarded, prefixArgs = []) => {
|
|
2773
|
+
const cleanedPrefix = [];
|
|
2774
|
+
let pendingValue = false;
|
|
2775
|
+
for (const arg of prefixArgs) {
|
|
2776
|
+
if (pendingValue) {
|
|
2777
|
+
cleanedPrefix.push(arg);
|
|
2778
|
+
pendingValue = false;
|
|
2779
|
+
continue;
|
|
2780
|
+
}
|
|
2781
|
+
if (TUI_VALUE_FLAGS.has(arg)) {
|
|
2782
|
+
cleanedPrefix.push(arg);
|
|
2783
|
+
pendingValue = true;
|
|
2784
|
+
continue;
|
|
2785
|
+
}
|
|
2786
|
+
if (isLaunchContextOption(arg)) continue;
|
|
2787
|
+
cleanedPrefix.push(arg);
|
|
2788
|
+
}
|
|
2789
|
+
let startIndex = 0;
|
|
2790
|
+
if (pendingValue && forwarded.length > 0) {
|
|
2791
|
+
cleanedPrefix.push(forwarded[0]);
|
|
2792
|
+
pendingValue = false;
|
|
2793
|
+
startIndex = 1;
|
|
2794
|
+
}
|
|
2795
|
+
const cleanedForwarded = [];
|
|
2796
|
+
let afterDoubleDash = false;
|
|
2797
|
+
for (let i = startIndex; i < forwarded.length; i += 1) {
|
|
2798
|
+
const arg = forwarded[i];
|
|
2799
|
+
if (afterDoubleDash) {
|
|
2800
|
+
cleanedForwarded.push(arg);
|
|
2801
|
+
continue;
|
|
2802
|
+
}
|
|
2803
|
+
if (pendingValue) {
|
|
2804
|
+
cleanedForwarded.push(arg);
|
|
2805
|
+
pendingValue = false;
|
|
2806
|
+
continue;
|
|
2807
|
+
}
|
|
2808
|
+
if (arg === "--") {
|
|
2809
|
+
cleanedForwarded.push(arg);
|
|
2810
|
+
afterDoubleDash = true;
|
|
2811
|
+
continue;
|
|
2812
|
+
}
|
|
2813
|
+
if (TUI_VALUE_FLAGS.has(arg)) {
|
|
2814
|
+
cleanedForwarded.push(arg);
|
|
2815
|
+
pendingValue = true;
|
|
2816
|
+
continue;
|
|
2817
|
+
}
|
|
2818
|
+
if (isLaunchContextOption(arg)) continue;
|
|
2819
|
+
cleanedForwarded.push(arg);
|
|
2653
2820
|
}
|
|
2654
|
-
return
|
|
2655
|
-
...
|
|
2656
|
-
|
|
2657
|
-
|
|
2821
|
+
return [
|
|
2822
|
+
...cleanedPrefix,
|
|
2823
|
+
`${TUI_LAUNCH_CONTEXT_FLAG}=${JSON.stringify(context)}`,
|
|
2824
|
+
...cleanedForwarded
|
|
2825
|
+
];
|
|
2658
2826
|
};
|
|
2659
2827
|
resolveTuiCommand = (options = {}) => {
|
|
2660
2828
|
const env = options.env ?? process.env;
|
|
@@ -2706,9 +2874,14 @@ var init_launcher = __esm({
|
|
|
2706
2874
|
void initStorage();
|
|
2707
2875
|
const tuiCmd = resolveTuiCommand({ cliPackageRoot });
|
|
2708
2876
|
const tuiArgs = process.env.CODELIA_TUI_ARGS ? splitArgs(process.env.CODELIA_TUI_ARGS) : [];
|
|
2709
|
-
const
|
|
2877
|
+
const context = buildTuiLaunchContext({
|
|
2878
|
+
env: process.env,
|
|
2879
|
+
update,
|
|
2880
|
+
launcherEntry: process.argv[1]
|
|
2881
|
+
});
|
|
2882
|
+
const tuiEnv = { ...process.env };
|
|
2710
2883
|
delete tuiEnv[UPDATE_REEXEC_ENV];
|
|
2711
|
-
const child = (0, import_node_child_process3.spawn)(tuiCmd,
|
|
2884
|
+
const child = (0, import_node_child_process3.spawn)(tuiCmd, buildTuiArgs(context, args2, tuiArgs), {
|
|
2712
2885
|
stdio: "inherit",
|
|
2713
2886
|
env: tuiEnv
|
|
2714
2887
|
});
|
|
@@ -2927,10 +3100,11 @@ var init_prompt_mode = __esm({
|
|
|
2927
3100
|
);
|
|
2928
3101
|
const atifOut = process.env.CODELIA_ATIF_OUT?.trim();
|
|
2929
3102
|
const harborShellRequested = options.harborShellApproval === true && options.sandboxMode === "full-access" && process.env.CODELIA_HARBOR_SHELL_APPROVAL === "1";
|
|
2930
|
-
const
|
|
2931
|
-
const runtimeCmd =
|
|
2932
|
-
const
|
|
2933
|
-
|
|
3103
|
+
const bundledRuntime = resolveBundledRuntimeLaunch(process.env);
|
|
3104
|
+
const runtimeCmd = bundledRuntime?.command ?? process.env.CODELIA_RUNTIME_CMD ?? process.execPath;
|
|
3105
|
+
const runtimeArgs = bundledRuntime ? [...bundledRuntime.args] : parseShellLikeArgs(
|
|
3106
|
+
process.env.CODELIA_RUNTIME_ARGS ?? "packages/runtime/src/index.ts"
|
|
3107
|
+
);
|
|
2934
3108
|
if (runtimeArgs.length === 0) {
|
|
2935
3109
|
runtimeArgs.push("packages/runtime/src/index.ts");
|
|
2936
3110
|
}
|
|
@@ -2941,7 +3115,7 @@ var init_prompt_mode = __esm({
|
|
|
2941
3115
|
runtimeArgs.push("--approval-mode", options.approvalMode);
|
|
2942
3116
|
}
|
|
2943
3117
|
const child = (0, import_node_child_process4.spawn)(runtimeCmd, runtimeArgs, {
|
|
2944
|
-
env:
|
|
3118
|
+
env: process.env,
|
|
2945
3119
|
stdio: ["pipe", "pipe", "pipe"]
|
|
2946
3120
|
});
|
|
2947
3121
|
let buffer = "";
|
|
@@ -3229,7 +3403,7 @@ var TOP_LEVEL_HELP_TEXT = [
|
|
|
3229
3403
|
" -p, --prompt <text> Run one headless prompt and exit",
|
|
3230
3404
|
"",
|
|
3231
3405
|
"Commands:",
|
|
3232
|
-
" auth authorize-keychain
|
|
3406
|
+
" auth authorize-keychain Restore access to saved credentials after a macOS Keychain timeout or denial",
|
|
3233
3407
|
" mcp ... Manage MCP servers and auth",
|
|
3234
3408
|
" session ... List, pin, archive, or clean up session run logs",
|
|
3235
3409
|
" update [--check] Check for a newer release and install it",
|