codexuse-cli 6.4.0 → 6.4.1
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/index.js +229 -152
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6666,7 +6666,7 @@ function shouldEnforceProfileLimit(status) {
|
|
|
6666
6666
|
|
|
6667
6667
|
// ../../packages/runtime-profiles/src/profiles/profile-manager.ts
|
|
6668
6668
|
var import_node_crypto15 = require("crypto");
|
|
6669
|
-
var
|
|
6669
|
+
var import_fs3 = require("fs");
|
|
6670
6670
|
var import_node_os8 = __toESM(require("os"), 1);
|
|
6671
6671
|
var import_path = __toESM(require("path"), 1);
|
|
6672
6672
|
var import_path2 = require("path");
|
|
@@ -6722,6 +6722,20 @@ function resolveProfileIdentityKeyFromProfile(profile) {
|
|
|
6722
6722
|
return resolveProfileIdentityKey(profile) ?? `profile:${profile.name}`;
|
|
6723
6723
|
}
|
|
6724
6724
|
|
|
6725
|
+
// ../../packages/shared/src/core/fs.ts
|
|
6726
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
6727
|
+
async function syncDirectory(directoryPath) {
|
|
6728
|
+
if (process.platform === "win32") {
|
|
6729
|
+
return;
|
|
6730
|
+
}
|
|
6731
|
+
const directory = await import_promises2.default.open(directoryPath, "r");
|
|
6732
|
+
try {
|
|
6733
|
+
await directory.sync();
|
|
6734
|
+
} finally {
|
|
6735
|
+
await directory.close();
|
|
6736
|
+
}
|
|
6737
|
+
}
|
|
6738
|
+
|
|
6725
6739
|
// ../../packages/runtime-codex/src/codex/rpc.ts
|
|
6726
6740
|
var import_node_child_process5 = require("child_process");
|
|
6727
6741
|
var import_node_crypto11 = require("crypto");
|
|
@@ -7016,7 +7030,7 @@ function buildCodexCommand(binaryPath, args2, env) {
|
|
|
7016
7030
|
// ../../packages/runtime-codex/src/codex/home.ts
|
|
7017
7031
|
var import_node_crypto9 = require("crypto");
|
|
7018
7032
|
var import_node_fs6 = require("fs");
|
|
7019
|
-
var
|
|
7033
|
+
var import_promises3 = require("fs/promises");
|
|
7020
7034
|
var import_node_os4 = __toESM(require("os"), 1);
|
|
7021
7035
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
7022
7036
|
function resolveHomeDir() {
|
|
@@ -7078,11 +7092,11 @@ function resolveProfileCodexHomesRoot() {
|
|
|
7078
7092
|
async function ensureProfileCodexHomesRoot() {
|
|
7079
7093
|
const root = resolveProfileCodexHomesRoot();
|
|
7080
7094
|
const parent = import_node_path8.default.dirname(root);
|
|
7081
|
-
await (0,
|
|
7082
|
-
await (0,
|
|
7095
|
+
await (0, import_promises3.mkdir)(parent, { recursive: true, mode: 448 });
|
|
7096
|
+
await (0, import_promises3.mkdir)(root, { recursive: true, mode: 448 });
|
|
7083
7097
|
if (process.platform !== "win32") {
|
|
7084
|
-
await (0,
|
|
7085
|
-
await (0,
|
|
7098
|
+
await (0, import_promises3.chmod)(parent, 448);
|
|
7099
|
+
await (0, import_promises3.chmod)(root, 448);
|
|
7086
7100
|
}
|
|
7087
7101
|
return root;
|
|
7088
7102
|
}
|
|
@@ -7102,7 +7116,7 @@ async function migrateProfileCodexHomeDir(profileHomeId) {
|
|
|
7102
7116
|
}
|
|
7103
7117
|
await ensureProfileCodexHomesRoot();
|
|
7104
7118
|
try {
|
|
7105
|
-
await (0,
|
|
7119
|
+
await (0, import_promises3.rename)(legacy, current);
|
|
7106
7120
|
} catch (error) {
|
|
7107
7121
|
if (error.code === "EXDEV") {
|
|
7108
7122
|
throw Object.assign(new Error("profile-home-cross-volume-unsupported"), {
|
|
@@ -7169,7 +7183,7 @@ var import_toml = __toESM(require_toml(), 1);
|
|
|
7169
7183
|
|
|
7170
7184
|
// ../../packages/runtime-codex/src/codex/config-metadata.ts
|
|
7171
7185
|
var import_node_child_process4 = require("child_process");
|
|
7172
|
-
var
|
|
7186
|
+
var import_promises4 = require("fs/promises");
|
|
7173
7187
|
var import_node_path9 = __toESM(require("path"), 1);
|
|
7174
7188
|
var CONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/openai/codex/main/codex-rs/core/config.schema.json";
|
|
7175
7189
|
var METADATA_CACHE_TTL_MS = 6e4;
|
|
@@ -7361,7 +7375,7 @@ async function readSchemaFromLocal() {
|
|
|
7361
7375
|
].filter((candidate) => Boolean(candidate));
|
|
7362
7376
|
for (const candidate of candidates) {
|
|
7363
7377
|
try {
|
|
7364
|
-
return await (0,
|
|
7378
|
+
return await (0, import_promises4.readFile)(candidate, "utf8");
|
|
7365
7379
|
} catch {
|
|
7366
7380
|
}
|
|
7367
7381
|
}
|
|
@@ -7462,7 +7476,7 @@ async function getCodexConfigMetadata(forceRefresh = false) {
|
|
|
7462
7476
|
|
|
7463
7477
|
// ../../packages/runtime-codex/src/codex/config-io.ts
|
|
7464
7478
|
var import_node_crypto10 = require("crypto");
|
|
7465
|
-
var
|
|
7479
|
+
var import_promises5 = require("fs/promises");
|
|
7466
7480
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
7467
7481
|
|
|
7468
7482
|
// ../../packages/runtime-codex/src/codex/config-presets.ts
|
|
@@ -7510,20 +7524,20 @@ function getConfigPath(options) {
|
|
|
7510
7524
|
}
|
|
7511
7525
|
async function ensureConfigDirExists(filePath) {
|
|
7512
7526
|
const dir = import_node_path10.default.dirname(filePath);
|
|
7513
|
-
await (0,
|
|
7527
|
+
await (0, import_promises5.mkdir)(dir, { recursive: true });
|
|
7514
7528
|
}
|
|
7515
7529
|
async function resolveConfigWriteTarget(configPath) {
|
|
7516
7530
|
try {
|
|
7517
|
-
if (!(await (0,
|
|
7531
|
+
if (!(await (0, import_promises5.lstat)(configPath)).isSymbolicLink()) {
|
|
7518
7532
|
return configPath;
|
|
7519
7533
|
}
|
|
7520
7534
|
try {
|
|
7521
|
-
return await (0,
|
|
7535
|
+
return await (0, import_promises5.realpath)(configPath);
|
|
7522
7536
|
} catch (error) {
|
|
7523
7537
|
if (error.code !== "ENOENT") {
|
|
7524
7538
|
throw error;
|
|
7525
7539
|
}
|
|
7526
|
-
return import_node_path10.default.resolve(import_node_path10.default.dirname(configPath), await (0,
|
|
7540
|
+
return import_node_path10.default.resolve(import_node_path10.default.dirname(configPath), await (0, import_promises5.readlink)(configPath));
|
|
7527
7541
|
}
|
|
7528
7542
|
} catch (error) {
|
|
7529
7543
|
if (error.code === "ENOENT") {
|
|
@@ -7535,19 +7549,19 @@ async function resolveConfigWriteTarget(configPath) {
|
|
|
7535
7549
|
async function removeStaleConfigStagingFiles(targetPath) {
|
|
7536
7550
|
const directory = import_node_path10.default.dirname(targetPath);
|
|
7537
7551
|
const prefix = `${import_node_path10.default.basename(targetPath)}.tmp-`;
|
|
7538
|
-
const entries3 = await (0,
|
|
7552
|
+
const entries3 = await (0, import_promises5.readdir)(directory).catch((error) => {
|
|
7539
7553
|
if (error.code === "ENOENT") {
|
|
7540
7554
|
return [];
|
|
7541
7555
|
}
|
|
7542
7556
|
throw error;
|
|
7543
7557
|
});
|
|
7544
7558
|
await Promise.all(
|
|
7545
|
-
entries3.filter((entry) => entry.startsWith(prefix)).map((entry) => (0,
|
|
7559
|
+
entries3.filter((entry) => entry.startsWith(prefix)).map((entry) => (0, import_promises5.rm)(import_node_path10.default.join(directory, entry), { force: true }))
|
|
7546
7560
|
);
|
|
7547
7561
|
}
|
|
7548
7562
|
async function resolveConfigWriteMode(targetPath) {
|
|
7549
7563
|
try {
|
|
7550
|
-
return (await (0,
|
|
7564
|
+
return (await (0, import_promises5.stat)(targetPath)).mode & 511;
|
|
7551
7565
|
} catch (error) {
|
|
7552
7566
|
if (error.code === "ENOENT") {
|
|
7553
7567
|
return 384;
|
|
@@ -7566,7 +7580,7 @@ async function readConfigContent(options) {
|
|
|
7566
7580
|
return withCloudSyncTransaction(getUserDataDir(), "read", async () => {
|
|
7567
7581
|
const configPath = getConfigPath(options);
|
|
7568
7582
|
try {
|
|
7569
|
-
const content = await (0,
|
|
7583
|
+
const content = await (0, import_promises5.readFile)(configPath, "utf8");
|
|
7570
7584
|
return {
|
|
7571
7585
|
exists: true,
|
|
7572
7586
|
content: normalizeLineEndings(content)
|
|
@@ -7593,25 +7607,20 @@ async function writeConfigContent(content, options) {
|
|
|
7593
7607
|
const normalized = ensureTrailingNewline(normalizeLineEndings(content));
|
|
7594
7608
|
const stagingPath = `${targetPath}.tmp-${process.pid}-${(0, import_node_crypto10.randomUUID)()}`;
|
|
7595
7609
|
try {
|
|
7596
|
-
const handle = await (0,
|
|
7610
|
+
const handle = await (0, import_promises5.open)(stagingPath, "wx", mode);
|
|
7597
7611
|
try {
|
|
7598
7612
|
await handle.writeFile(normalized, "utf8");
|
|
7599
7613
|
await handle.sync();
|
|
7600
7614
|
} finally {
|
|
7601
7615
|
await handle.close();
|
|
7602
7616
|
}
|
|
7603
|
-
await (0,
|
|
7617
|
+
await (0, import_promises5.rename)(stagingPath, targetPath);
|
|
7604
7618
|
if (process.platform !== "win32") {
|
|
7605
|
-
await (0,
|
|
7606
|
-
const directory = await (0, import_promises4.open)(import_node_path10.default.dirname(targetPath), "r");
|
|
7607
|
-
try {
|
|
7608
|
-
await directory.sync();
|
|
7609
|
-
} finally {
|
|
7610
|
-
await directory.close();
|
|
7611
|
-
}
|
|
7619
|
+
await (0, import_promises5.chmod)(targetPath, mode);
|
|
7612
7620
|
}
|
|
7621
|
+
await syncDirectory(import_node_path10.default.dirname(targetPath));
|
|
7613
7622
|
} finally {
|
|
7614
|
-
await (0,
|
|
7623
|
+
await (0, import_promises5.rm)(stagingPath, { force: true });
|
|
7615
7624
|
}
|
|
7616
7625
|
});
|
|
7617
7626
|
}
|
|
@@ -7619,19 +7628,14 @@ async function removeConfigContent(options) {
|
|
|
7619
7628
|
await withCloudSyncTransaction(getUserDataDir(), "write", async () => {
|
|
7620
7629
|
const configPath = getConfigPath(options);
|
|
7621
7630
|
try {
|
|
7622
|
-
await (0,
|
|
7631
|
+
await (0, import_promises5.unlink)(configPath);
|
|
7623
7632
|
} catch (error) {
|
|
7624
7633
|
if (error.code === "ENOENT") {
|
|
7625
7634
|
return;
|
|
7626
7635
|
}
|
|
7627
7636
|
throw error;
|
|
7628
7637
|
}
|
|
7629
|
-
|
|
7630
|
-
try {
|
|
7631
|
-
await directory.sync();
|
|
7632
|
-
} finally {
|
|
7633
|
-
await directory.close();
|
|
7634
|
-
}
|
|
7638
|
+
await syncDirectory(import_node_path10.default.dirname(configPath));
|
|
7635
7639
|
});
|
|
7636
7640
|
}
|
|
7637
7641
|
async function getUpdatedAt(configPath, exists) {
|
|
@@ -7639,7 +7643,7 @@ async function getUpdatedAt(configPath, exists) {
|
|
|
7639
7643
|
return null;
|
|
7640
7644
|
}
|
|
7641
7645
|
try {
|
|
7642
|
-
const stats = await (0,
|
|
7646
|
+
const stats = await (0, import_promises5.stat)(configPath);
|
|
7643
7647
|
return stats.mtimeMs;
|
|
7644
7648
|
} catch (error) {
|
|
7645
7649
|
const nodeError = error;
|
|
@@ -25939,14 +25943,7 @@ async function writeAtomicPath(filePath, content) {
|
|
|
25939
25943
|
}
|
|
25940
25944
|
try {
|
|
25941
25945
|
await import_node_fs7.promises.rename(tempPath, filePath);
|
|
25942
|
-
|
|
25943
|
-
const dirHandle = await import_node_fs7.promises.open(dir, "r");
|
|
25944
|
-
try {
|
|
25945
|
-
await dirHandle.sync();
|
|
25946
|
-
} finally {
|
|
25947
|
-
await dirHandle.close();
|
|
25948
|
-
}
|
|
25949
|
-
}
|
|
25946
|
+
await syncDirectory(dir);
|
|
25950
25947
|
} finally {
|
|
25951
25948
|
await import_node_fs7.promises.rm(tempPath, { force: true }).catch(() => void 0);
|
|
25952
25949
|
}
|
|
@@ -27092,7 +27089,7 @@ async function findOfficialCodexThreadRecord(profileHome, threadId, options = {}
|
|
|
27092
27089
|
// ../../packages/runtime-codex/src/codex/sharedHistory.ts
|
|
27093
27090
|
var import_node_crypto12 = require("crypto");
|
|
27094
27091
|
var import_node_fs9 = require("fs");
|
|
27095
|
-
var
|
|
27092
|
+
var import_promises6 = require("fs/promises");
|
|
27096
27093
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
27097
27094
|
var HISTORY_MARKER = ".codexuse-shared-history-v1.json";
|
|
27098
27095
|
var HISTORY_INDEX = "session_index.jsonl";
|
|
@@ -33694,6 +33691,9 @@ function createAppServerRequestClientExpression(options = {}) {
|
|
|
33694
33691
|
} catch {
|
|
33695
33692
|
}
|
|
33696
33693
|
if (/^\\s*class\\b/.test(source)) continue;
|
|
33694
|
+
// React hooks also mention sendRequest, and calling one outside a
|
|
33695
|
+
// component throws React error #321, which failed every account read.
|
|
33696
|
+
if (/\\(0,\\s*[\\w$]+\\.c\\)\\(\\d+\\)|\\buse(?:Context|State|Ref|Memo|Callback|Effect|SyncExternalStore)\\b/.test(source)) continue;
|
|
33697
33697
|
if (source.includes(".sendRequest(") || source.includes("send-cli-request-for-host")) return value;
|
|
33698
33698
|
}
|
|
33699
33699
|
return null;
|
|
@@ -33736,6 +33736,95 @@ function createAppServerRequestClientExpression(options = {}) {
|
|
|
33736
33736
|
}
|
|
33737
33737
|
throw new Error("codex-app-chatgpt-api-client-not-found");
|
|
33738
33738
|
};
|
|
33739
|
+
// Codex App builds since September 2026 keep the app-server connection in
|
|
33740
|
+
// a scoped store rather than in React props. An exported getter, the one
|
|
33741
|
+
// that throws "AppServerManager RPC is not connected", takes the store
|
|
33742
|
+
// handle a component holds and a host id.
|
|
33743
|
+
const findScopedStoreHandle = () => {
|
|
33744
|
+
const roots = [];
|
|
33745
|
+
const codexRoot = window.__codexRoot?._internalRoot?.current;
|
|
33746
|
+
if (codexRoot) roots.push(codexRoot);
|
|
33747
|
+
const rootElement = document.querySelector("#root");
|
|
33748
|
+
for (const key of Object.getOwnPropertyNames(rootElement || {})) {
|
|
33749
|
+
if (key.startsWith("__reactContainer$") && rootElement[key]) roots.push(rootElement[key]);
|
|
33750
|
+
}
|
|
33751
|
+
const queue = roots.slice();
|
|
33752
|
+
const seen = new WeakSet();
|
|
33753
|
+
for (let cursor = 0; cursor < queue.length && cursor < 80000; cursor += 1) {
|
|
33754
|
+
const value = queue[cursor];
|
|
33755
|
+
if (!value || (typeof value !== "object" && typeof value !== "function") || seen.has(value)) {
|
|
33756
|
+
continue;
|
|
33757
|
+
}
|
|
33758
|
+
seen.add(value);
|
|
33759
|
+
if (
|
|
33760
|
+
typeof value.get === "function" &&
|
|
33761
|
+
typeof value.getOwnValue === "function" &&
|
|
33762
|
+
"scope" in value &&
|
|
33763
|
+
"node" in value
|
|
33764
|
+
) {
|
|
33765
|
+
return value;
|
|
33766
|
+
}
|
|
33767
|
+
let names = [];
|
|
33768
|
+
try {
|
|
33769
|
+
names = Object.getOwnPropertyNames(value);
|
|
33770
|
+
} catch {
|
|
33771
|
+
}
|
|
33772
|
+
for (const key of names) {
|
|
33773
|
+
if ([
|
|
33774
|
+
"window",
|
|
33775
|
+
"self",
|
|
33776
|
+
"globalThis",
|
|
33777
|
+
"ownerDocument",
|
|
33778
|
+
"defaultView",
|
|
33779
|
+
"parentNode",
|
|
33780
|
+
"parentElement"
|
|
33781
|
+
].includes(key)) continue;
|
|
33782
|
+
let descriptor = null;
|
|
33783
|
+
try {
|
|
33784
|
+
descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
33785
|
+
} catch {
|
|
33786
|
+
}
|
|
33787
|
+
const child = descriptor && "value" in descriptor ? descriptor.value : null;
|
|
33788
|
+
if (
|
|
33789
|
+
child &&
|
|
33790
|
+
(typeof child === "object" || typeof child === "function") &&
|
|
33791
|
+
!(typeof Node !== "undefined" && child instanceof Node)
|
|
33792
|
+
) {
|
|
33793
|
+
queue.push(child);
|
|
33794
|
+
}
|
|
33795
|
+
}
|
|
33796
|
+
}
|
|
33797
|
+
throw new Error("codex-app-scoped-store-not-found");
|
|
33798
|
+
};
|
|
33799
|
+
const resolveScopedHostClient = async () => {
|
|
33800
|
+
if (typeof state.scopedHostClient?.sendRequest === "function") {
|
|
33801
|
+
return state.scopedHostClient;
|
|
33802
|
+
}
|
|
33803
|
+
const handle = findScopedStoreHandle();
|
|
33804
|
+
for (const url of codexAppAssetUrls()) {
|
|
33805
|
+
let module = null;
|
|
33806
|
+
try {
|
|
33807
|
+
module = await loadCodexAppModuleByUrl(url);
|
|
33808
|
+
} catch {
|
|
33809
|
+
continue;
|
|
33810
|
+
}
|
|
33811
|
+
for (const value of Object.values(module || {})) {
|
|
33812
|
+
if (typeof value !== "function") continue;
|
|
33813
|
+
let source = "";
|
|
33814
|
+
try {
|
|
33815
|
+
source = Function.prototype.toString.call(value);
|
|
33816
|
+
} catch {
|
|
33817
|
+
}
|
|
33818
|
+
if (!source.includes("AppServerManager RPC is not connected")) continue;
|
|
33819
|
+
const client = value(handle, "local");
|
|
33820
|
+
if (typeof client?.sendRequest === "function") {
|
|
33821
|
+
state.scopedHostClient = client;
|
|
33822
|
+
return client;
|
|
33823
|
+
}
|
|
33824
|
+
}
|
|
33825
|
+
}
|
|
33826
|
+
throw new Error("codex-app-scoped-host-client-not-found");
|
|
33827
|
+
};
|
|
33739
33828
|
const resolveClient = async () => {
|
|
33740
33829
|
try {
|
|
33741
33830
|
const directHostClient = resolveDirectHostClient();
|
|
@@ -33746,6 +33835,16 @@ function createAppServerRequestClientExpression(options = {}) {
|
|
|
33746
33835
|
} catch (error) {
|
|
33747
33836
|
state.directHostError = sanitizeError(error, "direct-host-unavailable");
|
|
33748
33837
|
}
|
|
33838
|
+
try {
|
|
33839
|
+
const scopedHostClient = await resolveScopedHostClient();
|
|
33840
|
+
// sendRequest here is a store proxy: calling it works, .bind does not.
|
|
33841
|
+
return {
|
|
33842
|
+
directHost: true,
|
|
33843
|
+
sendRequest: (...args) => scopedHostClient.sendRequest(...args)
|
|
33844
|
+
};
|
|
33845
|
+
} catch (error) {
|
|
33846
|
+
state.scopedHostError = sanitizeError(error, "scoped-host-unavailable");
|
|
33847
|
+
}
|
|
33749
33848
|
try {
|
|
33750
33849
|
const sendRequest = await resolveHostRequest();
|
|
33751
33850
|
return { sendRequest };
|
|
@@ -37892,7 +37991,7 @@ var ProfileManager = class {
|
|
|
37892
37991
|
}
|
|
37893
37992
|
async readActiveAuthFile() {
|
|
37894
37993
|
try {
|
|
37895
|
-
const raw = await
|
|
37994
|
+
const raw = await import_fs3.promises.readFile(this.activeAuth, "utf8");
|
|
37896
37995
|
const trimmed = raw.trim();
|
|
37897
37996
|
if (!trimmed) {
|
|
37898
37997
|
return null;
|
|
@@ -37914,7 +38013,7 @@ var ProfileManager = class {
|
|
|
37914
38013
|
async readActiveAuthFileStrict() {
|
|
37915
38014
|
let raw;
|
|
37916
38015
|
try {
|
|
37917
|
-
raw = await
|
|
38016
|
+
raw = await import_fs3.promises.readFile(this.activeAuth, "utf8");
|
|
37918
38017
|
} catch (error) {
|
|
37919
38018
|
if (this.isNotFoundError(error)) {
|
|
37920
38019
|
return null;
|
|
@@ -37948,7 +38047,7 @@ var ProfileManager = class {
|
|
|
37948
38047
|
async captureAuthSnapshotAtPath(authPath) {
|
|
37949
38048
|
let raw;
|
|
37950
38049
|
try {
|
|
37951
|
-
raw = await
|
|
38050
|
+
raw = await import_fs3.promises.readFile(authPath, "utf8");
|
|
37952
38051
|
} catch (error) {
|
|
37953
38052
|
if (this.isNotFoundError(error)) {
|
|
37954
38053
|
return this.emptyAuthSnapshot();
|
|
@@ -38370,7 +38469,7 @@ var ProfileManager = class {
|
|
|
38370
38469
|
async initialize() {
|
|
38371
38470
|
this.profileHomesRoot = resolveProfileCodexHomesRoot();
|
|
38372
38471
|
try {
|
|
38373
|
-
await
|
|
38472
|
+
await import_fs3.promises.mkdir(this.codexDir, { recursive: true });
|
|
38374
38473
|
} catch (error) {
|
|
38375
38474
|
logError("Failed to ensure Codex directory exists:", error);
|
|
38376
38475
|
throw errorWithCause("Failed to initialize profile manager", error);
|
|
@@ -38460,7 +38559,7 @@ var ProfileManager = class {
|
|
|
38460
38559
|
const targetHome = this.getProfileHomePath(nextHomeId);
|
|
38461
38560
|
let sourceExists = true;
|
|
38462
38561
|
try {
|
|
38463
|
-
await
|
|
38562
|
+
await import_fs3.promises.access(sourceHome);
|
|
38464
38563
|
} catch (error) {
|
|
38465
38564
|
if (!this.isNotFoundError(error)) {
|
|
38466
38565
|
throw error;
|
|
@@ -38470,7 +38569,7 @@ var ProfileManager = class {
|
|
|
38470
38569
|
if (sourceExists) {
|
|
38471
38570
|
let targetExists = true;
|
|
38472
38571
|
try {
|
|
38473
|
-
await
|
|
38572
|
+
await import_fs3.promises.access(targetHome);
|
|
38474
38573
|
} catch (error) {
|
|
38475
38574
|
if (!this.isNotFoundError(error)) {
|
|
38476
38575
|
throw error;
|
|
@@ -38502,7 +38601,7 @@ var ProfileManager = class {
|
|
|
38502
38601
|
} else {
|
|
38503
38602
|
const releaseGuard = await this.acquireProfileHomeMutationGuard(record2);
|
|
38504
38603
|
try {
|
|
38505
|
-
await
|
|
38604
|
+
await import_fs3.promises.rename(sourceHome, targetHome);
|
|
38506
38605
|
} finally {
|
|
38507
38606
|
await releaseGuard();
|
|
38508
38607
|
}
|
|
@@ -38643,11 +38742,11 @@ var ProfileManager = class {
|
|
|
38643
38742
|
dir,
|
|
38644
38743
|
`.${import_path.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto15.randomUUID)()}.tmp`
|
|
38645
38744
|
);
|
|
38646
|
-
await
|
|
38745
|
+
await import_fs3.promises.mkdir(dir, { recursive: true, mode: 448 });
|
|
38647
38746
|
if (process.platform !== "win32") {
|
|
38648
|
-
await
|
|
38747
|
+
await import_fs3.promises.chmod(dir, 448);
|
|
38649
38748
|
}
|
|
38650
|
-
const handle = await
|
|
38749
|
+
const handle = await import_fs3.promises.open(tempPath, "wx", 384);
|
|
38651
38750
|
try {
|
|
38652
38751
|
await handle.writeFile(contents, "utf8");
|
|
38653
38752
|
await handle.sync();
|
|
@@ -38656,25 +38755,18 @@ var ProfileManager = class {
|
|
|
38656
38755
|
}
|
|
38657
38756
|
try {
|
|
38658
38757
|
if (process.platform !== "win32") {
|
|
38659
|
-
await
|
|
38660
|
-
}
|
|
38661
|
-
await import_fs.promises.rename(tempPath, filePath);
|
|
38662
|
-
if (process.platform !== "win32") {
|
|
38663
|
-
const dirHandle = await import_fs.promises.open(dir, "r");
|
|
38664
|
-
try {
|
|
38665
|
-
await dirHandle.sync();
|
|
38666
|
-
} finally {
|
|
38667
|
-
await dirHandle.close();
|
|
38668
|
-
}
|
|
38758
|
+
await import_fs3.promises.chmod(tempPath, 384);
|
|
38669
38759
|
}
|
|
38760
|
+
await import_fs3.promises.rename(tempPath, filePath);
|
|
38761
|
+
await syncDirectory(dir);
|
|
38670
38762
|
} finally {
|
|
38671
38763
|
try {
|
|
38672
|
-
await
|
|
38764
|
+
await import_fs3.promises.rm(tempPath, { force: true });
|
|
38673
38765
|
} catch {
|
|
38674
38766
|
}
|
|
38675
38767
|
}
|
|
38676
38768
|
if (process.platform !== "win32") {
|
|
38677
|
-
await
|
|
38769
|
+
await import_fs3.promises.chmod(filePath, 384);
|
|
38678
38770
|
}
|
|
38679
38771
|
}
|
|
38680
38772
|
async writeAtomicWithReadback(filePath, contents, label) {
|
|
@@ -38706,9 +38798,9 @@ var ProfileManager = class {
|
|
|
38706
38798
|
async cleanupProfileAuthCas(authPath) {
|
|
38707
38799
|
const paths = this.profileAuthCasPaths(authPath);
|
|
38708
38800
|
await Promise.all([
|
|
38709
|
-
|
|
38710
|
-
|
|
38711
|
-
|
|
38801
|
+
import_fs3.promises.rm(paths.manifest, { force: true }),
|
|
38802
|
+
import_fs3.promises.rm(paths.backup, { force: true }),
|
|
38803
|
+
import_fs3.promises.rm(paths.replaced, { force: true })
|
|
38712
38804
|
]);
|
|
38713
38805
|
}
|
|
38714
38806
|
async rollbackProfileAuthCas(authPath, manifest) {
|
|
@@ -38733,7 +38825,7 @@ var ProfileManager = class {
|
|
|
38733
38825
|
throw new Error("Profile auth rollback backup is missing.");
|
|
38734
38826
|
}
|
|
38735
38827
|
if (currentRaw !== null) {
|
|
38736
|
-
await
|
|
38828
|
+
await import_fs3.promises.rename(authPath, paths.replaced);
|
|
38737
38829
|
const replacedRaw = await this.readOptionalFile(paths.replaced);
|
|
38738
38830
|
if (this.fingerprintAuthContent(replacedRaw) !== manifest.targetFingerprint) {
|
|
38739
38831
|
if (await this.readOptionalFile(authPath) === null && replacedRaw) {
|
|
@@ -38789,7 +38881,7 @@ var ProfileManager = class {
|
|
|
38789
38881
|
let displaced = false;
|
|
38790
38882
|
try {
|
|
38791
38883
|
if (expectedRaw !== null) {
|
|
38792
|
-
await
|
|
38884
|
+
await import_fs3.promises.rename(authPath, paths.backup);
|
|
38793
38885
|
displaced = true;
|
|
38794
38886
|
if (await this.readOptionalFile(paths.backup) !== expectedRaw) {
|
|
38795
38887
|
throw new Error(
|
|
@@ -38932,7 +39024,7 @@ var ProfileManager = class {
|
|
|
38932
39024
|
}
|
|
38933
39025
|
async readOptionalFile(filePath) {
|
|
38934
39026
|
try {
|
|
38935
|
-
return await
|
|
39027
|
+
return await import_fs3.promises.readFile(filePath, "utf8");
|
|
38936
39028
|
} catch (error) {
|
|
38937
39029
|
if (this.isNotFoundError(error)) {
|
|
38938
39030
|
return null;
|
|
@@ -38972,13 +39064,13 @@ var ProfileManager = class {
|
|
|
38972
39064
|
return value3;
|
|
38973
39065
|
}
|
|
38974
39066
|
async cleanupAuthMutationFiles() {
|
|
38975
|
-
await
|
|
39067
|
+
await import_fs3.promises.rm(import_path.default.join(this.codexDir, AUTH_MUTATION_MANIFEST_NAME), {
|
|
38976
39068
|
force: true
|
|
38977
39069
|
});
|
|
38978
|
-
await
|
|
39070
|
+
await import_fs3.promises.rm(import_path.default.join(this.codexDir, AUTH_MUTATION_BACKUP_NAME), {
|
|
38979
39071
|
force: true
|
|
38980
39072
|
});
|
|
38981
|
-
await
|
|
39073
|
+
await import_fs3.promises.rm(import_path.default.join(this.codexDir, AUTH_MUTATION_REPLACED_NAME), {
|
|
38982
39074
|
force: true
|
|
38983
39075
|
});
|
|
38984
39076
|
}
|
|
@@ -38988,7 +39080,7 @@ var ProfileManager = class {
|
|
|
38988
39080
|
dir,
|
|
38989
39081
|
`.${import_path.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto15.randomUUID)()}.install`
|
|
38990
39082
|
);
|
|
38991
|
-
const handle = await
|
|
39083
|
+
const handle = await import_fs3.promises.open(tempPath, "wx", 384);
|
|
38992
39084
|
try {
|
|
38993
39085
|
await handle.writeFile(contents, "utf8");
|
|
38994
39086
|
await handle.sync();
|
|
@@ -38996,17 +39088,10 @@ var ProfileManager = class {
|
|
|
38996
39088
|
await handle.close();
|
|
38997
39089
|
}
|
|
38998
39090
|
try {
|
|
38999
|
-
await
|
|
39000
|
-
|
|
39001
|
-
const dirHandle = await import_fs.promises.open(dir, "r");
|
|
39002
|
-
try {
|
|
39003
|
-
await dirHandle.sync();
|
|
39004
|
-
} finally {
|
|
39005
|
-
await dirHandle.close();
|
|
39006
|
-
}
|
|
39007
|
-
}
|
|
39091
|
+
await import_fs3.promises.link(tempPath, filePath);
|
|
39092
|
+
await syncDirectory(dir);
|
|
39008
39093
|
} finally {
|
|
39009
|
-
await
|
|
39094
|
+
await import_fs3.promises.rm(tempPath, { force: true });
|
|
39010
39095
|
}
|
|
39011
39096
|
}
|
|
39012
39097
|
async replaceActiveAuthIfCurrent(expectedSourceRaw, targetRaw) {
|
|
@@ -39019,7 +39104,7 @@ var ProfileManager = class {
|
|
|
39019
39104
|
);
|
|
39020
39105
|
}
|
|
39021
39106
|
} else {
|
|
39022
|
-
await
|
|
39107
|
+
await import_fs3.promises.rename(this.activeAuth, backupPath);
|
|
39023
39108
|
const displacedRaw2 = await this.readOptionalFile(backupPath);
|
|
39024
39109
|
if (displacedRaw2 !== expectedSourceRaw) {
|
|
39025
39110
|
if (displacedRaw2 !== null && await this.readOptionalFile(this.activeAuth) === null) {
|
|
@@ -39100,8 +39185,8 @@ var ProfileManager = class {
|
|
|
39100
39185
|
async beginAuthMutation(operation, targetFingerprint) {
|
|
39101
39186
|
const sourceRaw = await this.readOptionalFile(this.activeAuth);
|
|
39102
39187
|
const backupPath = import_path.default.join(this.codexDir, AUTH_MUTATION_BACKUP_NAME);
|
|
39103
|
-
await
|
|
39104
|
-
await
|
|
39188
|
+
await import_fs3.promises.rm(backupPath, { force: true });
|
|
39189
|
+
await import_fs3.promises.rm(import_path.default.join(this.codexDir, AUTH_MUTATION_REPLACED_NAME), {
|
|
39105
39190
|
force: true
|
|
39106
39191
|
});
|
|
39107
39192
|
const manifest = {
|
|
@@ -39155,7 +39240,7 @@ var ProfileManager = class {
|
|
|
39155
39240
|
);
|
|
39156
39241
|
}
|
|
39157
39242
|
if (currentRaw !== null) {
|
|
39158
|
-
await
|
|
39243
|
+
await import_fs3.promises.rename(this.activeAuth, replacedPath);
|
|
39159
39244
|
const replacedRaw = await this.readOptionalFile(replacedPath);
|
|
39160
39245
|
if (this.fingerprintAuthContent(replacedRaw) !== manifest.targetFingerprint) {
|
|
39161
39246
|
if (await this.readOptionalFile(this.activeAuth) === null && replacedRaw) {
|
|
@@ -39937,11 +40022,11 @@ var ProfileManager = class {
|
|
|
39937
40022
|
async removeProfileHome(record2, recoverable) {
|
|
39938
40023
|
const profileHome = this.getProfileHomePath(record2.homeId);
|
|
39939
40024
|
if (!recoverable) {
|
|
39940
|
-
await
|
|
40025
|
+
await import_fs3.promises.rm(profileHome, { recursive: true, force: true });
|
|
39941
40026
|
return null;
|
|
39942
40027
|
}
|
|
39943
40028
|
try {
|
|
39944
|
-
await
|
|
40029
|
+
await import_fs3.promises.access(profileHome);
|
|
39945
40030
|
} catch (error) {
|
|
39946
40031
|
if (this.isNotFoundError(error)) {
|
|
39947
40032
|
return null;
|
|
@@ -39949,13 +40034,13 @@ var ProfileManager = class {
|
|
|
39949
40034
|
throw error;
|
|
39950
40035
|
}
|
|
39951
40036
|
const trashRoot = process.platform === "darwin" ? import_path.default.join(process.env.HOME || import_node_os8.default.homedir(), ".Trash") : import_path.default.join(getUserDataDir(), "deleted-profile-homes");
|
|
39952
|
-
await
|
|
40037
|
+
await import_fs3.promises.mkdir(trashRoot, { recursive: true, mode: 448 });
|
|
39953
40038
|
const safeName = record2.name.replace(/[^A-Za-z0-9._-]+/g, "-").slice(0, 48) || "profile";
|
|
39954
40039
|
const destination = import_path.default.join(
|
|
39955
40040
|
trashRoot,
|
|
39956
40041
|
`CodexUse-${safeName}-${(0, import_node_crypto15.randomUUID)()}`
|
|
39957
40042
|
);
|
|
39958
|
-
await
|
|
40043
|
+
await import_fs3.promises.rename(profileHome, destination);
|
|
39959
40044
|
return destination;
|
|
39960
40045
|
}
|
|
39961
40046
|
async deleteProfileRecordAndHome(record2, options = {}) {
|
|
@@ -40185,7 +40270,7 @@ var ProfileManager = class {
|
|
|
40185
40270
|
async syncProfileTokensFromActiveAuth(profileName, baselineProfile, authPath) {
|
|
40186
40271
|
const targetPath = authPath ?? this.activeAuth;
|
|
40187
40272
|
try {
|
|
40188
|
-
const authRaw = await
|
|
40273
|
+
const authRaw = await import_fs3.promises.readFile(targetPath, "utf8");
|
|
40189
40274
|
await this.syncProfileTokensFromAuthContent(profileName, baselineProfile, authRaw);
|
|
40190
40275
|
} catch (error) {
|
|
40191
40276
|
if (!this.isNotFoundError(error)) {
|
|
@@ -40197,7 +40282,7 @@ var ProfileManager = class {
|
|
|
40197
40282
|
const authPath = import_path.default.join(this.getProfileHomePath(homeId), "auth.json");
|
|
40198
40283
|
let fileKey;
|
|
40199
40284
|
try {
|
|
40200
|
-
const stats = await
|
|
40285
|
+
const stats = await import_fs3.promises.stat(authPath);
|
|
40201
40286
|
fileKey = `${stats.mtimeMs}:${stats.size}`;
|
|
40202
40287
|
const cached2 = this.profileHomeAuthSyncCache.get(profileName);
|
|
40203
40288
|
const currentRecency2 = this.getProfileTokenRecencyMs(baselineProfile);
|
|
@@ -40212,7 +40297,7 @@ var ProfileManager = class {
|
|
|
40212
40297
|
}
|
|
40213
40298
|
let authRaw;
|
|
40214
40299
|
try {
|
|
40215
|
-
authRaw = await
|
|
40300
|
+
authRaw = await import_fs3.promises.readFile(authPath, "utf8");
|
|
40216
40301
|
} catch (error) {
|
|
40217
40302
|
if (!this.isNotFoundError(error)) {
|
|
40218
40303
|
logWarn(`Failed to read profile-home auth for '${profileName}' while syncing tokens:`, error);
|
|
@@ -40304,7 +40389,7 @@ var ProfileManager = class {
|
|
|
40304
40389
|
const source = (0, import_path2.join)(this.codexDir, file);
|
|
40305
40390
|
const destination = (0, import_path2.join)(targetCodexHome, file);
|
|
40306
40391
|
try {
|
|
40307
|
-
await
|
|
40392
|
+
await import_fs3.promises.copyFile(source, destination, import_fs3.constants.COPYFILE_EXCL);
|
|
40308
40393
|
if (file === "config.toml") {
|
|
40309
40394
|
copiedToml = true;
|
|
40310
40395
|
}
|
|
@@ -40366,7 +40451,7 @@ var ProfileManager = class {
|
|
|
40366
40451
|
}
|
|
40367
40452
|
async isProfileHomeMutationMarkerLive(deletingPath) {
|
|
40368
40453
|
try {
|
|
40369
|
-
const owner = JSON.parse(await
|
|
40454
|
+
const owner = JSON.parse(await import_fs3.promises.readFile(deletingPath, "utf8"));
|
|
40370
40455
|
const expiresAt = typeof owner.expiresAt === "number" && Number.isFinite(owner.expiresAt) ? owner.expiresAt : null;
|
|
40371
40456
|
const ownerId = typeof owner.ownerId === "string" ? owner.ownerId : null;
|
|
40372
40457
|
const ownerStartedAt = typeof owner.ownerStartedAt === "number" ? owner.ownerStartedAt : null;
|
|
@@ -40387,10 +40472,10 @@ var ProfileManager = class {
|
|
|
40387
40472
|
const releaseIntent = await this.acquireProfileHomeWriteIntent(record2);
|
|
40388
40473
|
let operationError = null;
|
|
40389
40474
|
try {
|
|
40390
|
-
await
|
|
40475
|
+
await import_fs3.promises.mkdir(leaseDir, { recursive: true, mode: 448 });
|
|
40391
40476
|
let deletingMarkerExists = true;
|
|
40392
40477
|
try {
|
|
40393
|
-
await
|
|
40478
|
+
await import_fs3.promises.access(deletingPath);
|
|
40394
40479
|
} catch (error) {
|
|
40395
40480
|
if (this.isNotFoundError(error)) {
|
|
40396
40481
|
deletingMarkerExists = false;
|
|
@@ -40402,10 +40487,10 @@ var ProfileManager = class {
|
|
|
40402
40487
|
if (await this.isProfileHomeMutationMarkerLive(deletingPath)) {
|
|
40403
40488
|
throw new Error(`Profile '${record2.name}' is being removed or replaced.`);
|
|
40404
40489
|
}
|
|
40405
|
-
await
|
|
40490
|
+
await import_fs3.promises.rm(deletingPath, { force: true });
|
|
40406
40491
|
}
|
|
40407
40492
|
activeProfileRuntimeLeasePaths.add(leasePath);
|
|
40408
|
-
const auth = await
|
|
40493
|
+
const auth = await import_fs3.promises.readFile(
|
|
40409
40494
|
(0, import_path2.join)(this.getProfileHomePath(record2.homeId), "auth.json"),
|
|
40410
40495
|
"utf8"
|
|
40411
40496
|
);
|
|
@@ -40421,7 +40506,7 @@ var ProfileManager = class {
|
|
|
40421
40506
|
})
|
|
40422
40507
|
);
|
|
40423
40508
|
try {
|
|
40424
|
-
await
|
|
40509
|
+
await import_fs3.promises.access(deletingPath);
|
|
40425
40510
|
throw new Error(
|
|
40426
40511
|
`Profile '${record2.name}' is being removed or replaced.`
|
|
40427
40512
|
);
|
|
@@ -40439,8 +40524,8 @@ var ProfileManager = class {
|
|
|
40439
40524
|
);
|
|
40440
40525
|
if (operationError || releaseError) {
|
|
40441
40526
|
await Promise.allSettled([
|
|
40442
|
-
|
|
40443
|
-
|
|
40527
|
+
import_fs3.promises.rm(leasePath, { force: true }),
|
|
40528
|
+
import_fs3.promises.rm(backupPath, { force: true })
|
|
40444
40529
|
]);
|
|
40445
40530
|
activeProfileRuntimeLeasePaths.delete(leasePath);
|
|
40446
40531
|
if (operationError && releaseError) {
|
|
@@ -40463,18 +40548,18 @@ var ProfileManager = class {
|
|
|
40463
40548
|
this.getProfileRuntimeLeaseDir(record2.homeId),
|
|
40464
40549
|
`${leaseId}.auth.backup`
|
|
40465
40550
|
);
|
|
40466
|
-
const backup = await
|
|
40551
|
+
const backup = await import_fs3.promises.readFile(backupPath, "utf8");
|
|
40467
40552
|
const releaseIntent = await this.acquireProfileHomeWriteIntent(record2);
|
|
40468
40553
|
try {
|
|
40469
40554
|
const leaseDir = this.getProfileRuntimeLeaseDir(record2.homeId);
|
|
40470
|
-
for (const entry of await
|
|
40555
|
+
for (const entry of await import_fs3.promises.readdir(leaseDir)) {
|
|
40471
40556
|
if (!entry.endsWith(".json") || entry === `${leaseId}.json`) {
|
|
40472
40557
|
continue;
|
|
40473
40558
|
}
|
|
40474
40559
|
try {
|
|
40475
40560
|
const leasePath = (0, import_path2.join)(leaseDir, entry);
|
|
40476
40561
|
const lease = JSON.parse(
|
|
40477
|
-
await
|
|
40562
|
+
await import_fs3.promises.readFile(leasePath, "utf8")
|
|
40478
40563
|
);
|
|
40479
40564
|
if (this.resolveLiveProfileRuntimeLeasePid(lease, leasePath)) {
|
|
40480
40565
|
throw new Error(
|
|
@@ -40525,10 +40610,10 @@ var ProfileManager = class {
|
|
|
40525
40610
|
const currentLeaseRaw = await this.readOptionalFile(leasePath);
|
|
40526
40611
|
const currentLease = currentLeaseRaw ? JSON.parse(currentLeaseRaw) : null;
|
|
40527
40612
|
if (!currentLease || currentLease.id !== leaseId || currentLease.released === true) {
|
|
40528
|
-
await
|
|
40613
|
+
await import_fs3.promises.rm(backupPath, { force: true });
|
|
40529
40614
|
}
|
|
40530
40615
|
} catch (error) {
|
|
40531
|
-
await
|
|
40616
|
+
await import_fs3.promises.rm(backupPath, { force: true });
|
|
40532
40617
|
throw error;
|
|
40533
40618
|
}
|
|
40534
40619
|
}
|
|
@@ -40541,7 +40626,7 @@ var ProfileManager = class {
|
|
|
40541
40626
|
try {
|
|
40542
40627
|
let leaseRaw = null;
|
|
40543
40628
|
try {
|
|
40544
|
-
leaseRaw = await
|
|
40629
|
+
leaseRaw = await import_fs3.promises.readFile(leasePath, "utf8");
|
|
40545
40630
|
} catch (error) {
|
|
40546
40631
|
if (!this.isNotFoundError(error)) {
|
|
40547
40632
|
throw error;
|
|
@@ -40564,8 +40649,8 @@ var ProfileManager = class {
|
|
|
40564
40649
|
);
|
|
40565
40650
|
}
|
|
40566
40651
|
const results = await Promise.allSettled([
|
|
40567
|
-
|
|
40568
|
-
...options.preserveBackup === true ? [] : [
|
|
40652
|
+
import_fs3.promises.rm(leasePath, { force: true }),
|
|
40653
|
+
...options.preserveBackup === true ? [] : [import_fs3.promises.rm((0, import_path2.join)(leaseDir, `${leaseId}.auth.backup`), { force: true })]
|
|
40569
40654
|
]);
|
|
40570
40655
|
const failed = results.find(
|
|
40571
40656
|
(result2) => result2.status === "rejected"
|
|
@@ -40598,7 +40683,7 @@ var ProfileManager = class {
|
|
|
40598
40683
|
profileName: record2.name
|
|
40599
40684
|
});
|
|
40600
40685
|
const openMarker = async () => {
|
|
40601
|
-
const handle = await
|
|
40686
|
+
const handle = await import_fs3.promises.open(deletingPath, "wx", 384);
|
|
40602
40687
|
try {
|
|
40603
40688
|
await handle.writeFile(
|
|
40604
40689
|
JSON.stringify({
|
|
@@ -40613,14 +40698,14 @@ var ProfileManager = class {
|
|
|
40613
40698
|
);
|
|
40614
40699
|
await handle.sync();
|
|
40615
40700
|
} catch (error) {
|
|
40616
|
-
await
|
|
40701
|
+
await import_fs3.promises.rm(deletingPath, { force: true });
|
|
40617
40702
|
throw error;
|
|
40618
40703
|
} finally {
|
|
40619
40704
|
await handle.close();
|
|
40620
40705
|
}
|
|
40621
40706
|
};
|
|
40622
40707
|
try {
|
|
40623
|
-
await
|
|
40708
|
+
await import_fs3.promises.mkdir(leaseDir, { recursive: true, mode: 448 });
|
|
40624
40709
|
try {
|
|
40625
40710
|
await openMarker();
|
|
40626
40711
|
} catch (error) {
|
|
@@ -40634,7 +40719,7 @@ var ProfileManager = class {
|
|
|
40634
40719
|
error
|
|
40635
40720
|
);
|
|
40636
40721
|
}
|
|
40637
|
-
await
|
|
40722
|
+
await import_fs3.promises.rm(deletingPath, { force: true });
|
|
40638
40723
|
try {
|
|
40639
40724
|
await openMarker();
|
|
40640
40725
|
} catch (retryError) {
|
|
@@ -40659,7 +40744,7 @@ var ProfileManager = class {
|
|
|
40659
40744
|
throw error;
|
|
40660
40745
|
}
|
|
40661
40746
|
try {
|
|
40662
|
-
const entries3 = await
|
|
40747
|
+
const entries3 = await import_fs3.promises.readdir(leaseDir);
|
|
40663
40748
|
const officialInstances = await getOfficialCodexProfileInstances({
|
|
40664
40749
|
profileNames: [record2.name]
|
|
40665
40750
|
});
|
|
@@ -40686,12 +40771,12 @@ var ProfileManager = class {
|
|
|
40686
40771
|
let leasePid = 0;
|
|
40687
40772
|
try {
|
|
40688
40773
|
const parsed = JSON.parse(
|
|
40689
|
-
await
|
|
40774
|
+
await import_fs3.promises.readFile(leasePath, "utf8")
|
|
40690
40775
|
);
|
|
40691
40776
|
if (parsed.released === true) {
|
|
40692
40777
|
await Promise.allSettled([
|
|
40693
|
-
|
|
40694
|
-
|
|
40778
|
+
import_fs3.promises.rm(leasePath, { force: true }),
|
|
40779
|
+
import_fs3.promises.rm(backupPath, { force: true })
|
|
40695
40780
|
]);
|
|
40696
40781
|
continue;
|
|
40697
40782
|
}
|
|
@@ -40705,14 +40790,14 @@ var ProfileManager = class {
|
|
|
40705
40790
|
);
|
|
40706
40791
|
}
|
|
40707
40792
|
await Promise.allSettled([
|
|
40708
|
-
|
|
40709
|
-
|
|
40793
|
+
import_fs3.promises.rm(leasePath, { force: true }),
|
|
40794
|
+
import_fs3.promises.rm(backupPath, { force: true })
|
|
40710
40795
|
]);
|
|
40711
40796
|
}
|
|
40712
40797
|
} catch (error) {
|
|
40713
40798
|
try {
|
|
40714
40799
|
try {
|
|
40715
|
-
await
|
|
40800
|
+
await import_fs3.promises.rm(deletingPath, { force: true });
|
|
40716
40801
|
} finally {
|
|
40717
40802
|
await releaseProfileHomeMutationIntent(
|
|
40718
40803
|
record2.homeId,
|
|
@@ -40731,7 +40816,7 @@ var ProfileManager = class {
|
|
|
40731
40816
|
let markerError = null;
|
|
40732
40817
|
let ownsMarker = false;
|
|
40733
40818
|
try {
|
|
40734
|
-
const owner = JSON.parse(await
|
|
40819
|
+
const owner = JSON.parse(await import_fs3.promises.readFile(deletingPath, "utf8"));
|
|
40735
40820
|
if (owner.id !== mutationId) {
|
|
40736
40821
|
markerError = new Error(
|
|
40737
40822
|
`Profile '${record2.name}' mutation marker ownership changed unexpectedly.`
|
|
@@ -40747,7 +40832,7 @@ var ProfileManager = class {
|
|
|
40747
40832
|
let markerReleaseError = null;
|
|
40748
40833
|
if (ownsMarker) {
|
|
40749
40834
|
try {
|
|
40750
|
-
await
|
|
40835
|
+
await import_fs3.promises.rm(deletingPath);
|
|
40751
40836
|
} catch (error) {
|
|
40752
40837
|
markerReleaseError = error;
|
|
40753
40838
|
}
|
|
@@ -40777,7 +40862,7 @@ var ProfileManager = class {
|
|
|
40777
40862
|
const configPath = (0, import_path2.join)(profileHome, "config.toml");
|
|
40778
40863
|
let raw;
|
|
40779
40864
|
try {
|
|
40780
|
-
raw = await
|
|
40865
|
+
raw = await import_fs3.promises.readFile(configPath, "utf8");
|
|
40781
40866
|
} catch (error) {
|
|
40782
40867
|
if (!this.isNotFoundError(error)) {
|
|
40783
40868
|
logWarn(`Failed to read config for profile home '${profileHome}':`, error);
|
|
@@ -40807,7 +40892,7 @@ var ProfileManager = class {
|
|
|
40807
40892
|
(0, import_toml2.stringify)(parsed)
|
|
40808
40893
|
);
|
|
40809
40894
|
try {
|
|
40810
|
-
await
|
|
40895
|
+
await import_fs3.promises.writeFile(configPath, sanitized, "utf8");
|
|
40811
40896
|
} catch (error) {
|
|
40812
40897
|
logWarn(`Failed to write sanitized config.toml for profile home '${profileHome}':`, error);
|
|
40813
40898
|
}
|
|
@@ -40825,9 +40910,9 @@ var ProfileManager = class {
|
|
|
40825
40910
|
}
|
|
40826
40911
|
}
|
|
40827
40912
|
const profileHome = this.getProfileHomePath(record2.homeId);
|
|
40828
|
-
await
|
|
40913
|
+
await import_fs3.promises.mkdir(profileHome, { recursive: true, mode: 448 });
|
|
40829
40914
|
if (process.platform !== "win32") {
|
|
40830
|
-
await
|
|
40915
|
+
await import_fs3.promises.chmod(profileHome, 448);
|
|
40831
40916
|
}
|
|
40832
40917
|
const authPath = (0, import_path2.join)(profileHome, "auth.json");
|
|
40833
40918
|
await this.withProfileAuthFileLock(authPath, async (currentRaw) => {
|
|
@@ -40953,7 +41038,7 @@ var ProfileManager = class {
|
|
|
40953
41038
|
let syncError = null;
|
|
40954
41039
|
let finalAuthContent = null;
|
|
40955
41040
|
try {
|
|
40956
|
-
finalAuthContent = await
|
|
41041
|
+
finalAuthContent = await import_fs3.promises.readFile(authPath, "utf8");
|
|
40957
41042
|
} catch (error) {
|
|
40958
41043
|
if (!this.isNotFoundError(error)) {
|
|
40959
41044
|
logWarn(`Failed to read isolated auth for '${profileName}' after action:`, error);
|
|
@@ -41090,7 +41175,7 @@ var ProfileManager = class {
|
|
|
41090
41175
|
throw new Error("Profile runtime lease is no longer active.");
|
|
41091
41176
|
}
|
|
41092
41177
|
const lease = JSON.parse(
|
|
41093
|
-
await
|
|
41178
|
+
await import_fs3.promises.readFile(leasePath, "utf8")
|
|
41094
41179
|
);
|
|
41095
41180
|
if (lease.id !== leaseId || lease.ownerId !== PROCESS_OWNER_ID2 || lease.released === true) {
|
|
41096
41181
|
throw new Error(
|
|
@@ -41126,7 +41211,7 @@ var ProfileManager = class {
|
|
|
41126
41211
|
);
|
|
41127
41212
|
let finalAuthContent = null;
|
|
41128
41213
|
try {
|
|
41129
|
-
finalAuthContent = await
|
|
41214
|
+
finalAuthContent = await import_fs3.promises.readFile(authPath, "utf8");
|
|
41130
41215
|
} catch (error) {
|
|
41131
41216
|
if (!this.isNotFoundError(error)) {
|
|
41132
41217
|
logWarn(`Failed to read isolated auth for '${profileName}' while syncing runtime:`, error);
|
|
@@ -41206,7 +41291,7 @@ var ProfileManager = class {
|
|
|
41206
41291
|
async readAuthFileForImport(authPath, actionLabel) {
|
|
41207
41292
|
let authRaw;
|
|
41208
41293
|
try {
|
|
41209
|
-
authRaw = await
|
|
41294
|
+
authRaw = await import_fs3.promises.readFile(authPath, "utf8");
|
|
41210
41295
|
} catch (error) {
|
|
41211
41296
|
if (this.isNotFoundError(error)) {
|
|
41212
41297
|
throw errorWithCause(
|
|
@@ -42057,7 +42142,7 @@ var ProfileManager = class {
|
|
|
42057
42142
|
const profileHome = this.getProfileHomePath(record2.homeId);
|
|
42058
42143
|
let homeExisted = true;
|
|
42059
42144
|
try {
|
|
42060
|
-
await
|
|
42145
|
+
await import_fs3.promises.access(profileHome);
|
|
42061
42146
|
} catch (error) {
|
|
42062
42147
|
if (!this.isNotFoundError(error)) {
|
|
42063
42148
|
throw error;
|
|
@@ -42083,7 +42168,7 @@ var ProfileManager = class {
|
|
|
42083
42168
|
const sourceHome = this.getProfileHomePath(sourceHomeId);
|
|
42084
42169
|
let sourceHomeExists = true;
|
|
42085
42170
|
try {
|
|
42086
|
-
await
|
|
42171
|
+
await import_fs3.promises.access(sourceHome);
|
|
42087
42172
|
} catch (error) {
|
|
42088
42173
|
if (!this.isNotFoundError(error)) {
|
|
42089
42174
|
throw error;
|
|
@@ -42091,16 +42176,16 @@ var ProfileManager = class {
|
|
|
42091
42176
|
sourceHomeExists = false;
|
|
42092
42177
|
}
|
|
42093
42178
|
if (sourceHomeExists) {
|
|
42094
|
-
await
|
|
42179
|
+
await import_fs3.promises.cp(sourceHome, profileHome, {
|
|
42095
42180
|
recursive: true,
|
|
42096
42181
|
errorOnExist: true,
|
|
42097
42182
|
force: false
|
|
42098
42183
|
});
|
|
42099
42184
|
}
|
|
42100
42185
|
}
|
|
42101
|
-
await
|
|
42186
|
+
await import_fs3.promises.mkdir(profileHome, { recursive: true, mode: 448 });
|
|
42102
42187
|
if (process.platform !== "win32") {
|
|
42103
|
-
await
|
|
42188
|
+
await import_fs3.promises.chmod(profileHome, 448);
|
|
42104
42189
|
}
|
|
42105
42190
|
await this.writeProfileAuthAtomic(
|
|
42106
42191
|
(0, import_path2.join)(profileHome, "auth.json"),
|
|
@@ -42155,7 +42240,7 @@ var ProfileManager = class {
|
|
|
42155
42240
|
const rollbackResults = await Promise.allSettled(
|
|
42156
42241
|
Array.from(
|
|
42157
42242
|
preparedHomeIds,
|
|
42158
|
-
(homeId) =>
|
|
42243
|
+
(homeId) => import_fs3.promises.rm(this.getProfileHomePath(homeId), {
|
|
42159
42244
|
recursive: true,
|
|
42160
42245
|
force: true
|
|
42161
42246
|
})
|
|
@@ -42225,7 +42310,7 @@ var ProfileManager = class {
|
|
|
42225
42310
|
let deleted = 0;
|
|
42226
42311
|
for (const homeId of homeIds) {
|
|
42227
42312
|
try {
|
|
42228
|
-
await
|
|
42313
|
+
await import_fs3.promises.rm(this.getProfileHomePath(homeId), {
|
|
42229
42314
|
recursive: true,
|
|
42230
42315
|
force: true
|
|
42231
42316
|
});
|
|
@@ -46483,14 +46568,6 @@ var JOURNAL_FILENAME = "cloud-sync-pull.journal.json";
|
|
|
46483
46568
|
function getCloudSyncJournalPath() {
|
|
46484
46569
|
return import_node_path21.default.join(getUserDataDir(), JOURNAL_FILENAME);
|
|
46485
46570
|
}
|
|
46486
|
-
async function syncDirectory(dir) {
|
|
46487
|
-
const directory = await import_node_fs16.promises.open(dir, "r");
|
|
46488
|
-
try {
|
|
46489
|
-
await directory.sync();
|
|
46490
|
-
} finally {
|
|
46491
|
-
await directory.close();
|
|
46492
|
-
}
|
|
46493
|
-
}
|
|
46494
46571
|
async function writeCloudSyncJournal(journal) {
|
|
46495
46572
|
const target = getCloudSyncJournalPath();
|
|
46496
46573
|
const dir = import_node_path21.default.dirname(target);
|
|
@@ -47407,7 +47484,7 @@ async function ensureCliStorageReady() {
|
|
|
47407
47484
|
}
|
|
47408
47485
|
|
|
47409
47486
|
// src/app/main.ts
|
|
47410
|
-
var VERSION = true ? "6.4.
|
|
47487
|
+
var VERSION = true ? "6.4.1" : "0.0.0";
|
|
47411
47488
|
async function runCli() {
|
|
47412
47489
|
const args2 = process.argv.slice(2);
|
|
47413
47490
|
if (args2.length === 0) {
|