codexuse-cli 3.9.8 → 3.9.9
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 +701 -352
- package/dist/index.js.map +1 -1
- package/dist/server/index.mjs +906 -425
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -48769,8 +48769,10 @@ const WS_METHODS = {
|
|
|
48769
48769
|
officialCodexFocusProfile: "officialCodex.focusProfile",
|
|
48770
48770
|
officialCodexStopProfile: "officialCodex.stopProfile",
|
|
48771
48771
|
officialCodexRestartProfile: "officialCodex.restartProfile",
|
|
48772
|
+
officialCodexUseProfile: "officialCodex.useProfile",
|
|
48772
48773
|
officialCodexLaunchProfiles: "officialCodex.launchProfiles",
|
|
48773
48774
|
officialCodexStopProfiles: "officialCodex.stopProfiles",
|
|
48775
|
+
officialCodexActivateProfiles: "officialCodex.activateProfiles",
|
|
48774
48776
|
cliInfo: "cli.info",
|
|
48775
48777
|
cliStatus: "cli.status",
|
|
48776
48778
|
cliCheckFreshness: "cli.checkFreshness",
|
|
@@ -48936,8 +48938,10 @@ const WebSocketRequestBody = Union([
|
|
|
48936
48938
|
tagRequestBody(WS_METHODS.officialCodexFocusProfile, Struct({ name: TrimmedNonEmptyString })),
|
|
48937
48939
|
tagRequestBody(WS_METHODS.officialCodexStopProfile, Struct({ name: TrimmedNonEmptyString })),
|
|
48938
48940
|
tagRequestBody(WS_METHODS.officialCodexRestartProfile, Struct({ name: TrimmedNonEmptyString })),
|
|
48941
|
+
tagRequestBody(WS_METHODS.officialCodexUseProfile, Struct({ name: TrimmedNonEmptyString })),
|
|
48939
48942
|
tagRequestBody(WS_METHODS.officialCodexLaunchProfiles, Struct({ names: Array$1(TrimmedNonEmptyString) })),
|
|
48940
48943
|
tagRequestBody(WS_METHODS.officialCodexStopProfiles, Struct({ names: Array$1(TrimmedNonEmptyString) })),
|
|
48944
|
+
tagRequestBody(WS_METHODS.officialCodexActivateProfiles, Struct({ names: Array$1(TrimmedNonEmptyString) })),
|
|
48941
48945
|
tagRequestBody(WS_METHODS.cliInfo, Struct({})),
|
|
48942
48946
|
tagRequestBody(WS_METHODS.cliStatus, Struct({})),
|
|
48943
48947
|
tagRequestBody(WS_METHODS.cliCheckFreshness, Struct({})),
|
|
@@ -58299,7 +58303,7 @@ const SQLITE_BUSY_MAX_ATTEMPTS = 3;
|
|
|
58299
58303
|
const SQLITE_BUSY_RETRY_DELAY_MS = 100;
|
|
58300
58304
|
const writeQueueByDbPath = /* @__PURE__ */ new Map();
|
|
58301
58305
|
const initializedDbPaths = /* @__PURE__ */ new Set();
|
|
58302
|
-
function isRecord$
|
|
58306
|
+
function isRecord$9(value) {
|
|
58303
58307
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
58304
58308
|
}
|
|
58305
58309
|
function clone$1(value) {
|
|
@@ -58411,7 +58415,7 @@ function resolveAppStorageDbPath(userDataDir) {
|
|
|
58411
58415
|
async function readDocument(dbPath, namespace, normalize) {
|
|
58412
58416
|
return withDatabase(dbPath, (db) => {
|
|
58413
58417
|
const row = useStatement(db, `SELECT value_json AS valueJson FROM ${APP_STORAGE_TABLE} WHERE namespace = ?`, (statement) => statement.get(namespace));
|
|
58414
|
-
const parsed = isRecord$
|
|
58418
|
+
const parsed = isRecord$9(row) ? safeParseJson(row.valueJson) : null;
|
|
58415
58419
|
if (parsed === null) return null;
|
|
58416
58420
|
return normalize(parsed);
|
|
58417
58421
|
});
|
|
@@ -58442,7 +58446,7 @@ async function updateDocument(input) {
|
|
|
58442
58446
|
beginImmediate(db);
|
|
58443
58447
|
try {
|
|
58444
58448
|
const row = useStatement(db, `SELECT value_json AS valueJson FROM ${APP_STORAGE_TABLE} WHERE namespace = ?`, (statement) => statement.get(input.namespace));
|
|
58445
|
-
const current = isRecord$
|
|
58449
|
+
const current = isRecord$9(row) ? input.normalize(safeParseJson(row.valueJson) ?? input.fallback()) : input.fallback();
|
|
58446
58450
|
const next = input.normalize(input.transform(clone$1(current)));
|
|
58447
58451
|
useStatement(db, `
|
|
58448
58452
|
INSERT INTO ${APP_STORAGE_TABLE} (namespace, value_json, updated_at)
|
|
@@ -58469,7 +58473,7 @@ let configuredUserDataDir = null;
|
|
|
58469
58473
|
let appStateCache = null;
|
|
58470
58474
|
let writeLock = Promise.resolve();
|
|
58471
58475
|
const writeLockContext = new AsyncLocalStorage();
|
|
58472
|
-
function isRecord$
|
|
58476
|
+
function isRecord$8(value) {
|
|
58473
58477
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
58474
58478
|
}
|
|
58475
58479
|
function clone(value) {
|
|
@@ -58606,7 +58610,7 @@ function createDefaultAppState() {
|
|
|
58606
58610
|
}
|
|
58607
58611
|
};
|
|
58608
58612
|
}
|
|
58609
|
-
function asString$
|
|
58613
|
+
function asString$10(value) {
|
|
58610
58614
|
if (typeof value !== "string") return null;
|
|
58611
58615
|
const trimmed = value.trim();
|
|
58612
58616
|
return trimmed.length > 0 ? trimmed : null;
|
|
@@ -58619,92 +58623,92 @@ function asBooleanOrNull(value) {
|
|
|
58619
58623
|
}
|
|
58620
58624
|
function normalizeAppState(raw) {
|
|
58621
58625
|
const defaults = createDefaultAppState();
|
|
58622
|
-
if (!isRecord$
|
|
58623
|
-
const rawAutoRoll = isRecord$
|
|
58626
|
+
if (!isRecord$8(raw)) return defaults;
|
|
58627
|
+
const rawAutoRoll = isRecord$8(raw.autoRoll) ? raw.autoRoll : void 0;
|
|
58624
58628
|
const merged = clone(deepMerge(defaults, raw));
|
|
58625
58629
|
merged.schemaVersion = 1;
|
|
58626
58630
|
merged.autoRoll = normalizeAutoRollSettings(rawAutoRoll);
|
|
58627
|
-
if (!isRecord$
|
|
58631
|
+
if (!isRecord$8(merged.officialCodex)) merged.officialCodex = clone(defaults.officialCodex);
|
|
58628
58632
|
merged.officialCodex.lastProfileSwitchAt = asNumberOrNull(merged.officialCodex.lastProfileSwitchAt);
|
|
58629
|
-
merged.officialCodex.lastProfileSwitchProfileKey = asString$
|
|
58633
|
+
merged.officialCodex.lastProfileSwitchProfileKey = asString$10(merged.officialCodex.lastProfileSwitchProfileKey);
|
|
58630
58634
|
merged.officialCodex.lastVerifiedLaunchAt = asNumberOrNull(merged.officialCodex.lastVerifiedLaunchAt);
|
|
58631
|
-
merged.officialCodex.lastVerifiedLaunchProfileKey = asString$
|
|
58635
|
+
merged.officialCodex.lastVerifiedLaunchProfileKey = asString$10(merged.officialCodex.lastVerifiedLaunchProfileKey);
|
|
58632
58636
|
merged.officialCodex.lastObservedPid = asNumberOrNull(merged.officialCodex.lastObservedPid);
|
|
58633
|
-
merged.officialCodex.lastRestartStatus = asString$
|
|
58634
|
-
merged.officialCodex.lastRestartReason = asString$
|
|
58635
|
-
merged.officialCodex.activity = Array.isArray(merged.officialCodex.activity) ? merged.officialCodex.activity.filter((entry) => isRecord$
|
|
58636
|
-
id: asString$
|
|
58637
|
-
at: asString$
|
|
58638
|
-
kind: entry.kind === "auto-roll-eval" || entry.kind === "profile-switch" || entry.kind === "auth-verified" || entry.kind === "official-codex-restart" || entry.kind === "low-remaining-alert" ? entry.kind : "auto-roll-eval",
|
|
58639
|
-
status: asString$
|
|
58640
|
-
reason: asString$
|
|
58641
|
-
decisionId: asString$
|
|
58642
|
-
profileName: asString$
|
|
58643
|
-
sourceProfileName: asString$
|
|
58644
|
-
targetProfileName: asString$
|
|
58637
|
+
merged.officialCodex.lastRestartStatus = asString$10(merged.officialCodex.lastRestartStatus);
|
|
58638
|
+
merged.officialCodex.lastRestartReason = asString$10(merged.officialCodex.lastRestartReason);
|
|
58639
|
+
merged.officialCodex.activity = Array.isArray(merged.officialCodex.activity) ? merged.officialCodex.activity.filter((entry) => isRecord$8(entry)).map((entry) => ({
|
|
58640
|
+
id: asString$10(entry.id) ?? "",
|
|
58641
|
+
at: asString$10(entry.at) ?? (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
58642
|
+
kind: entry.kind === "auto-roll-eval" || entry.kind === "profile-switch" || entry.kind === "auth-verified" || entry.kind === "official-codex-restart" || entry.kind === "reset-window-activation" || entry.kind === "low-remaining-alert" ? entry.kind : "auto-roll-eval",
|
|
58643
|
+
status: asString$10(entry.status) ?? "unknown",
|
|
58644
|
+
reason: asString$10(entry.reason),
|
|
58645
|
+
decisionId: asString$10(entry.decisionId),
|
|
58646
|
+
profileName: asString$10(entry.profileName),
|
|
58647
|
+
sourceProfileName: asString$10(entry.sourceProfileName),
|
|
58648
|
+
targetProfileName: asString$10(entry.targetProfileName),
|
|
58645
58649
|
remainingPercent: asNumberOrNull(entry.remainingPercent),
|
|
58646
58650
|
threshold: asNumberOrNull(entry.threshold),
|
|
58647
58651
|
snapshotAgeMs: asNumberOrNull(entry.snapshotAgeMs),
|
|
58648
|
-
snapshotSource: asString$
|
|
58649
|
-
phase: asString$
|
|
58652
|
+
snapshotSource: asString$10(entry.snapshotSource),
|
|
58653
|
+
phase: asString$10(entry.phase),
|
|
58650
58654
|
pid: asNumberOrNull(entry.pid),
|
|
58651
|
-
profileKeyHash: asString$
|
|
58655
|
+
profileKeyHash: asString$10(entry.profileKeyHash),
|
|
58652
58656
|
switchVerified: asBooleanOrNull(entry.switchVerified),
|
|
58653
58657
|
restartRequested: asBooleanOrNull(entry.restartRequested),
|
|
58654
|
-
restartResult: asString$
|
|
58655
|
-
observedProfileName: asString$
|
|
58656
|
-
observedProfileKeyHash: asString$
|
|
58657
|
-
observedProfileMatchSource: asString$
|
|
58658
|
+
restartResult: asString$10(entry.restartResult),
|
|
58659
|
+
observedProfileName: asString$10(entry.observedProfileName),
|
|
58660
|
+
observedProfileKeyHash: asString$10(entry.observedProfileKeyHash),
|
|
58661
|
+
observedProfileMatchSource: asString$10(entry.observedProfileMatchSource)
|
|
58658
58662
|
})).filter((entry) => entry.id && entry.at).slice(-50) : [];
|
|
58659
|
-
if (!isRecord$
|
|
58663
|
+
if (!isRecord$8(merged.officialCodex.instancesByProfileName)) merged.officialCodex.instancesByProfileName = {};
|
|
58660
58664
|
else {
|
|
58661
58665
|
const nextInstances = {};
|
|
58662
58666
|
for (const [key, value] of Object.entries(merged.officialCodex.instancesByProfileName)) {
|
|
58663
|
-
if (!isRecord$
|
|
58664
|
-
const profileName = asString$
|
|
58667
|
+
if (!isRecord$8(value)) continue;
|
|
58668
|
+
const profileName = asString$10(value.profileName) ?? asString$10(key);
|
|
58665
58669
|
if (!profileName) continue;
|
|
58666
58670
|
nextInstances[profileName] = {
|
|
58667
58671
|
profileName,
|
|
58668
|
-
profileKey: asString$
|
|
58669
|
-
profileHome: asString$
|
|
58670
|
-
appPath: asString$
|
|
58671
|
-
bundleId: asString$
|
|
58672
|
+
profileKey: asString$10(value.profileKey),
|
|
58673
|
+
profileHome: asString$10(value.profileHome),
|
|
58674
|
+
appPath: asString$10(value.appPath),
|
|
58675
|
+
bundleId: asString$10(value.bundleId),
|
|
58672
58676
|
pid: asNumberOrNull(value.pid),
|
|
58673
58677
|
appServerPid: asNumberOrNull(value.appServerPid),
|
|
58674
58678
|
launchedAt: asNumberOrNull(value.launchedAt),
|
|
58675
58679
|
lastVerifiedAt: asNumberOrNull(value.lastVerifiedAt),
|
|
58676
|
-
lastStatus: asString$
|
|
58677
|
-
lastError: asString$
|
|
58680
|
+
lastStatus: asString$10(value.lastStatus),
|
|
58681
|
+
lastError: asString$10(value.lastError)
|
|
58678
58682
|
};
|
|
58679
58683
|
}
|
|
58680
58684
|
merged.officialCodex.instancesByProfileName = nextInstances;
|
|
58681
58685
|
}
|
|
58682
|
-
if (isRecord$
|
|
58686
|
+
if (isRecord$8(merged.officialCodex.pendingRestartDebt)) {
|
|
58683
58687
|
const debt = merged.officialCodex.pendingRestartDebt;
|
|
58684
|
-
const targetProfileName = asString$
|
|
58688
|
+
const targetProfileName = asString$10(debt.targetProfileName);
|
|
58685
58689
|
merged.officialCodex.pendingRestartDebt = targetProfileName ? {
|
|
58686
58690
|
targetProfileName,
|
|
58687
|
-
targetProfileKey: asString$
|
|
58688
|
-
sourceProfileName: asString$
|
|
58689
|
-
sourceProfileKey: asString$
|
|
58690
|
-
decisionId: asString$
|
|
58691
|
+
targetProfileKey: asString$10(debt.targetProfileKey),
|
|
58692
|
+
sourceProfileName: asString$10(debt.sourceProfileName),
|
|
58693
|
+
sourceProfileKey: asString$10(debt.sourceProfileKey),
|
|
58694
|
+
decisionId: asString$10(debt.decisionId),
|
|
58691
58695
|
attempts: asNumberOrNull(debt.attempts) ?? 0,
|
|
58692
|
-
lastReason: asString$
|
|
58696
|
+
lastReason: asString$10(debt.lastReason)
|
|
58693
58697
|
} : null;
|
|
58694
58698
|
} else merged.officialCodex.pendingRestartDebt = null;
|
|
58695
|
-
merged.app.lastAppVersion = asString$
|
|
58696
|
-
merged.app.pendingUpdateVersion = asString$
|
|
58697
|
-
merged.app.lastProfileName = asString$
|
|
58699
|
+
merged.app.lastAppVersion = asString$10(merged.app.lastAppVersion);
|
|
58700
|
+
merged.app.pendingUpdateVersion = asString$10(merged.app.pendingUpdateVersion);
|
|
58701
|
+
merged.app.lastProfileName = asString$10(merged.app.lastProfileName);
|
|
58698
58702
|
{
|
|
58699
58703
|
const allowedAppKeys = new Set(Object.keys(defaults.app));
|
|
58700
58704
|
for (const key of Object.keys(merged.app)) if (!allowedAppKeys.has(key)) delete merged.app[key];
|
|
58701
58705
|
}
|
|
58702
|
-
merged.license.licenseKey = asString$
|
|
58703
|
-
merged.license.purchaseEmail = asString$
|
|
58704
|
-
merged.license.lastVerifiedAt = asString$
|
|
58705
|
-
merged.license.nextCheckAt = asString$
|
|
58706
|
-
merged.license.lastVerificationError = asString$
|
|
58707
|
-
merged.license.signature = asString$
|
|
58706
|
+
merged.license.licenseKey = asString$10(merged.license.licenseKey);
|
|
58707
|
+
merged.license.purchaseEmail = asString$10(merged.license.purchaseEmail);
|
|
58708
|
+
merged.license.lastVerifiedAt = asString$10(merged.license.lastVerifiedAt);
|
|
58709
|
+
merged.license.nextCheckAt = asString$10(merged.license.nextCheckAt);
|
|
58710
|
+
merged.license.lastVerificationError = asString$10(merged.license.lastVerificationError);
|
|
58711
|
+
merged.license.signature = asString$10(merged.license.signature);
|
|
58708
58712
|
if (![
|
|
58709
58713
|
"inactive",
|
|
58710
58714
|
"active",
|
|
@@ -58723,63 +58727,63 @@ function normalizeAppState(raw) {
|
|
|
58723
58727
|
const allowedPreferenceKeys = new Set(Object.keys(defaults.preferences));
|
|
58724
58728
|
for (const key of Object.keys(merged.preferences)) if (!allowedPreferenceKeys.has(key)) delete merged.preferences[key];
|
|
58725
58729
|
}
|
|
58726
|
-
if (!isRecord$
|
|
58727
|
-
if (!isRecord$
|
|
58730
|
+
if (!isRecord$8(merged.runtimeSettings)) merged.runtimeSettings = {};
|
|
58731
|
+
if (!isRecord$8(merged.ui)) merged.ui = clone(defaults.ui);
|
|
58728
58732
|
merged.ui.themeMode = merged.ui.themeMode === "light" || merged.ui.themeMode === "dark" ? merged.ui.themeMode : null;
|
|
58729
|
-
if (!isRecord$
|
|
58733
|
+
if (!isRecord$8(merged.ui.layout)) merged.ui.layout = clone(defaults.ui.layout);
|
|
58730
58734
|
if (typeof merged.ui.layout.sidebarCollapsed !== "boolean") merged.ui.layout.sidebarCollapsed = null;
|
|
58731
|
-
if (!isRecord$
|
|
58735
|
+
if (!isRecord$8(merged.ui.profiles)) merged.ui.profiles = clone(defaults.ui.profiles);
|
|
58732
58736
|
merged.ui.profiles.viewMode = merged.ui.profiles.viewMode === "cards" || merged.ui.profiles.viewMode === "compact" ? merged.ui.profiles.viewMode : null;
|
|
58733
|
-
merged.ui.profiles.sortBy = asString$
|
|
58734
|
-
merged.ui.profiles.groupBy = asString$
|
|
58735
|
-
merged.ui.profiles.planFilter = asString$
|
|
58736
|
-
merged.ui.profiles.healthFilter = asString$
|
|
58737
|
-
merged.ui.profiles.customGroupFilter = asString$
|
|
58737
|
+
merged.ui.profiles.sortBy = asString$10(merged.ui.profiles.sortBy);
|
|
58738
|
+
merged.ui.profiles.groupBy = asString$10(merged.ui.profiles.groupBy);
|
|
58739
|
+
merged.ui.profiles.planFilter = asString$10(merged.ui.profiles.planFilter);
|
|
58740
|
+
merged.ui.profiles.healthFilter = asString$10(merged.ui.profiles.healthFilter);
|
|
58741
|
+
merged.ui.profiles.customGroupFilter = asString$10(merged.ui.profiles.customGroupFilter);
|
|
58738
58742
|
if (typeof merged.ui.profiles.toolbarOpen !== "boolean") merged.ui.profiles.toolbarOpen = null;
|
|
58739
|
-
if (!isRecord$
|
|
58743
|
+
if (!isRecord$8(merged.ui.profiles.collapsedSections)) merged.ui.profiles.collapsedSections = {};
|
|
58740
58744
|
else merged.ui.profiles.collapsedSections = Object.fromEntries(Object.entries(merged.ui.profiles.collapsedSections).flatMap(([key, value]) => {
|
|
58741
|
-
const normalizedKey = asString$
|
|
58745
|
+
const normalizedKey = asString$10(key);
|
|
58742
58746
|
if (!normalizedKey || typeof value !== "boolean") return [];
|
|
58743
58747
|
return [[normalizedKey, value]];
|
|
58744
58748
|
}));
|
|
58745
|
-
if (!isRecord$
|
|
58749
|
+
if (!isRecord$8(merged.ui.onboarding)) merged.ui.onboarding = clone(defaults.ui.onboarding);
|
|
58746
58750
|
if (typeof merged.ui.onboarding.welcomeCompleted !== "boolean") merged.ui.onboarding.welcomeCompleted = false;
|
|
58747
58751
|
if (!Number.isFinite(merged.ui.onboarding.welcomeCompletedAt)) merged.ui.onboarding.welcomeCompletedAt = null;
|
|
58748
58752
|
merged.ui.onboarding.welcomeResumeStep = merged.ui.onboarding.welcomeResumeStep === 2 ? 2 : null;
|
|
58749
|
-
if (!isRecord$
|
|
58753
|
+
if (!isRecord$8(merged.ui.onboarding.milestones)) merged.ui.onboarding.milestones = clone(defaults.ui.onboarding.milestones);
|
|
58750
58754
|
if (typeof merged.ui.onboarding.milestones.firstProfileAdded !== "boolean") merged.ui.onboarding.milestones.firstProfileAdded = false;
|
|
58751
58755
|
if (typeof merged.ui.onboarding.milestones.secondProfileAdded !== "boolean") merged.ui.onboarding.milestones.secondProfileAdded = false;
|
|
58752
58756
|
if (!Number.isFinite(merged.ui.onboarding.sessionCount)) merged.ui.onboarding.sessionCount = 0;
|
|
58753
|
-
if (!isRecord$
|
|
58757
|
+
if (!isRecord$8(merged.ui.onboarding.nudgeCooldowns)) merged.ui.onboarding.nudgeCooldowns = {};
|
|
58754
58758
|
else merged.ui.onboarding.nudgeCooldowns = Object.fromEntries(Object.entries(merged.ui.onboarding.nudgeCooldowns).flatMap(([key, value]) => {
|
|
58755
|
-
const normalizedKey = asString$
|
|
58759
|
+
const normalizedKey = asString$10(key);
|
|
58756
58760
|
if (!normalizedKey || !Number.isFinite(value)) return [];
|
|
58757
58761
|
return [[normalizedKey, Number(value)]];
|
|
58758
58762
|
}));
|
|
58759
|
-
if (!isRecord$
|
|
58763
|
+
if (!isRecord$8(merged.ui.onboarding.nudgeDismissCount)) merged.ui.onboarding.nudgeDismissCount = {};
|
|
58760
58764
|
else merged.ui.onboarding.nudgeDismissCount = Object.fromEntries(Object.entries(merged.ui.onboarding.nudgeDismissCount).flatMap(([key, value]) => {
|
|
58761
|
-
const normalizedKey = asString$
|
|
58765
|
+
const normalizedKey = asString$10(key);
|
|
58762
58766
|
if (!normalizedKey || !Number.isFinite(value)) return [];
|
|
58763
58767
|
return [[normalizedKey, Number(value)]];
|
|
58764
58768
|
}));
|
|
58765
58769
|
if (typeof merged.ui.onboarding.proUnlockedCelebrated !== "boolean") merged.ui.onboarding.proUnlockedCelebrated = false;
|
|
58766
|
-
if (!isRecord$
|
|
58770
|
+
if (!isRecord$8(merged.ui.projectThreadSelections)) merged.ui.projectThreadSelections = {};
|
|
58767
58771
|
else merged.ui.projectThreadSelections = Object.fromEntries(Object.entries(merged.ui.projectThreadSelections).flatMap(([projectId, threadId]) => {
|
|
58768
|
-
const normalizedProjectId = asString$
|
|
58772
|
+
const normalizedProjectId = asString$10(projectId);
|
|
58769
58773
|
if (!normalizedProjectId) return [];
|
|
58770
58774
|
return [[normalizedProjectId, typeof threadId === "string" && threadId.trim().length > 0 ? threadId.trim() : null]];
|
|
58771
58775
|
}));
|
|
58772
|
-
merged.ui.duplicateWarningDismissedKey = asString$
|
|
58776
|
+
merged.ui.duplicateWarningDismissedKey = asString$10(merged.ui.duplicateWarningDismissedKey);
|
|
58773
58777
|
if (typeof merged.ui.pendingLicenseActivation !== "boolean") merged.ui.pendingLicenseActivation = false;
|
|
58774
58778
|
{
|
|
58775
58779
|
const allowedUiKeys = new Set(Object.keys(defaults.ui));
|
|
58776
58780
|
for (const key of Object.keys(merged.ui)) if (!allowedUiKeys.has(key)) delete merged.ui[key];
|
|
58777
58781
|
}
|
|
58778
|
-
if (!isRecord$
|
|
58779
|
-
if (!isRecord$
|
|
58782
|
+
if (!isRecord$8(merged.profileDashboard)) merged.profileDashboard = clone(defaults.profileDashboard);
|
|
58783
|
+
if (!isRecord$8(merged.profileDashboard.customGroupsByAccountKey)) merged.profileDashboard.customGroupsByAccountKey = {};
|
|
58780
58784
|
else merged.profileDashboard.customGroupsByAccountKey = Object.fromEntries(Object.entries(merged.profileDashboard.customGroupsByAccountKey).flatMap(([key, value]) => {
|
|
58781
|
-
const normalizedKey = asString$
|
|
58782
|
-
const normalizedValue = asString$
|
|
58785
|
+
const normalizedKey = asString$10(key);
|
|
58786
|
+
const normalizedValue = asString$10(value);
|
|
58783
58787
|
if (!normalizedKey || !normalizedValue) return [];
|
|
58784
58788
|
return [[normalizedKey, normalizedValue]];
|
|
58785
58789
|
}));
|
|
@@ -58787,54 +58791,54 @@ function normalizeAppState(raw) {
|
|
|
58787
58791
|
const allowedProfileDashboardKeys = new Set(Object.keys(defaults.profileDashboard));
|
|
58788
58792
|
for (const key of Object.keys(merged.profileDashboard)) if (!allowedProfileDashboardKeys.has(key)) delete merged.profileDashboard[key];
|
|
58789
58793
|
}
|
|
58790
|
-
const legacyProjectSettingsByPath = isRecord$
|
|
58791
|
-
if (!isRecord$
|
|
58794
|
+
const legacyProjectSettingsByPath = isRecord$8(raw.projectSettingsByPath) ? raw.projectSettingsByPath : null;
|
|
58795
|
+
if (!isRecord$8(merged.workspaceSettingsByPath)) merged.workspaceSettingsByPath = {};
|
|
58792
58796
|
if (legacyProjectSettingsByPath) merged.workspaceSettingsByPath = {
|
|
58793
58797
|
...legacyProjectSettingsByPath,
|
|
58794
58798
|
...merged.workspaceSettingsByPath
|
|
58795
58799
|
};
|
|
58796
58800
|
delete merged.projectSettingsByPath;
|
|
58797
|
-
if (!isRecord$
|
|
58798
|
-
if (!isRecord$
|
|
58799
|
-
if (!isRecord$
|
|
58801
|
+
if (!isRecord$8(merged.conversationCategoriesByCwd)) merged.conversationCategoriesByCwd = {};
|
|
58802
|
+
if (!isRecord$8(merged.conversationCategoryAssignmentsByCwd)) merged.conversationCategoryAssignmentsByCwd = {};
|
|
58803
|
+
if (!isRecord$8(merged.git)) merged.git = clone(defaults.git);
|
|
58800
58804
|
merged.git.commitMessagePrompt = normalizeCommitMessagePrompt(merged.git.commitMessagePrompt) ?? DEFAULT_COMMIT_MESSAGE_PROMPT;
|
|
58801
58805
|
{
|
|
58802
58806
|
const allowedGitKeys = new Set(Object.keys(defaults.git));
|
|
58803
58807
|
for (const key of Object.keys(merged.git)) if (!allowedGitKeys.has(key)) delete merged.git[key];
|
|
58804
58808
|
}
|
|
58805
|
-
if (!isRecord$
|
|
58809
|
+
if (!isRecord$8(merged.skills)) merged.skills = clone(defaults.skills);
|
|
58806
58810
|
if (!Array.isArray(merged.skills.sources)) merged.skills.sources = [];
|
|
58807
|
-
if (!isRecord$
|
|
58808
|
-
if (!isRecord$
|
|
58809
|
-
merged.sync.lastPushAt = asString$
|
|
58810
|
-
merged.sync.lastPullAt = asString$
|
|
58811
|
-
merged.sync.lastError = asString$
|
|
58812
|
-
merged.sync.remoteUpdatedAt = asString$
|
|
58813
|
-
if (!isRecord$
|
|
58814
|
-
merged.analytics.anonymousId = asString$
|
|
58811
|
+
if (!isRecord$8(merged.skills.installsBySlug)) merged.skills.installsBySlug = {};
|
|
58812
|
+
if (!isRecord$8(merged.sync)) merged.sync = clone(defaults.sync);
|
|
58813
|
+
merged.sync.lastPushAt = asString$10(merged.sync.lastPushAt);
|
|
58814
|
+
merged.sync.lastPullAt = asString$10(merged.sync.lastPullAt);
|
|
58815
|
+
merged.sync.lastError = asString$10(merged.sync.lastError);
|
|
58816
|
+
merged.sync.remoteUpdatedAt = asString$10(merged.sync.remoteUpdatedAt);
|
|
58817
|
+
if (!isRecord$8(merged.analytics)) merged.analytics = isRecord$8(merged.telemetry) ? clone(merged.telemetry) : clone(defaults.analytics);
|
|
58818
|
+
merged.analytics.anonymousId = asString$10(merged.analytics.anonymousId);
|
|
58815
58819
|
if (!merged.analytics.anonymousId) {
|
|
58816
|
-
const legacyInstallId = asString$
|
|
58820
|
+
const legacyInstallId = asString$10(merged.telemetry?.installId);
|
|
58817
58821
|
merged.analytics.anonymousId = legacyInstallId;
|
|
58818
58822
|
}
|
|
58819
58823
|
if (typeof merged.analytics.enabled !== "boolean") merged.analytics.enabled = true;
|
|
58820
|
-
merged.analytics.lastFlushAt = asString$
|
|
58821
|
-
merged.analytics.lastError = asString$
|
|
58824
|
+
merged.analytics.lastFlushAt = asString$10(merged.analytics.lastFlushAt);
|
|
58825
|
+
merged.analytics.lastError = asString$10(merged.analytics.lastError);
|
|
58822
58826
|
if ("telemetry" in merged) delete merged.telemetry;
|
|
58823
|
-
if (!isRecord$
|
|
58824
|
-
if (!isRecord$
|
|
58827
|
+
if (!isRecord$8(merged.profilesByName)) merged.profilesByName = {};
|
|
58828
|
+
if (!isRecord$8(merged.migration)) merged.migration = clone(defaults.migration);
|
|
58825
58829
|
if (![
|
|
58826
58830
|
"pending",
|
|
58827
58831
|
"pending_local_storage",
|
|
58828
58832
|
"complete"
|
|
58829
58833
|
].includes(merged.migration.status)) merged.migration.status = "pending";
|
|
58830
|
-
merged.migration.startedAt = asString$
|
|
58831
|
-
merged.migration.completedAt = asString$
|
|
58832
|
-
merged.migration.localStorageImportedAt = asString$
|
|
58833
|
-
merged.migration.lastError = asString$
|
|
58834
|
+
merged.migration.startedAt = asString$10(merged.migration.startedAt);
|
|
58835
|
+
merged.migration.completedAt = asString$10(merged.migration.completedAt);
|
|
58836
|
+
merged.migration.localStorageImportedAt = asString$10(merged.migration.localStorageImportedAt);
|
|
58837
|
+
merged.migration.lastError = asString$10(merged.migration.lastError);
|
|
58834
58838
|
return merged;
|
|
58835
58839
|
}
|
|
58836
58840
|
function deepMerge(base, patch) {
|
|
58837
|
-
if (!isRecord$
|
|
58841
|
+
if (!isRecord$8(base) || !isRecord$8(patch)) return clone(patch ?? base);
|
|
58838
58842
|
const next = { ...base };
|
|
58839
58843
|
for (const [key, patchValue] of Object.entries(patch)) {
|
|
58840
58844
|
if (patchValue === void 0) continue;
|
|
@@ -58843,7 +58847,7 @@ function deepMerge(base, patch) {
|
|
|
58843
58847
|
next[key] = clone(patchValue);
|
|
58844
58848
|
continue;
|
|
58845
58849
|
}
|
|
58846
|
-
if (isRecord$
|
|
58850
|
+
if (isRecord$8(currentValue) && isRecord$8(patchValue)) {
|
|
58847
58851
|
next[key] = deepMerge(currentValue, patchValue);
|
|
58848
58852
|
continue;
|
|
58849
58853
|
}
|
|
@@ -58990,12 +58994,12 @@ function isGeneralChatWorkspaceRoot(workspaceRoot) {
|
|
|
58990
58994
|
}
|
|
58991
58995
|
//#endregion
|
|
58992
58996
|
//#region ../../packages/runtime-codex/src/codex/settings.ts
|
|
58993
|
-
function asString$
|
|
58997
|
+
function asString$9(value) {
|
|
58994
58998
|
if (typeof value !== "string") return null;
|
|
58995
58999
|
const trimmed = value.trim();
|
|
58996
59000
|
return trimmed.length > 0 ? trimmed : null;
|
|
58997
59001
|
}
|
|
58998
|
-
function isRecord$
|
|
59002
|
+
function isRecord$7(value) {
|
|
58999
59003
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
59000
59004
|
}
|
|
59001
59005
|
function parseAutoRoll(raw) {
|
|
@@ -59007,8 +59011,8 @@ function parseAutoRoll(raw) {
|
|
|
59007
59011
|
}
|
|
59008
59012
|
}
|
|
59009
59013
|
function parseStoredLicense(raw) {
|
|
59010
|
-
if (!isRecord$
|
|
59011
|
-
const statusCandidate = asString$
|
|
59014
|
+
if (!isRecord$7(raw)) return null;
|
|
59015
|
+
const statusCandidate = asString$9(raw.status);
|
|
59012
59016
|
const status = [
|
|
59013
59017
|
"inactive",
|
|
59014
59018
|
"active",
|
|
@@ -59016,13 +59020,13 @@ function parseStoredLicense(raw) {
|
|
|
59016
59020
|
"error"
|
|
59017
59021
|
].includes(statusCandidate ?? "") ? statusCandidate : void 0;
|
|
59018
59022
|
const license = {
|
|
59019
|
-
licenseKey: asString$
|
|
59020
|
-
purchaseEmail: asString$
|
|
59021
|
-
lastVerifiedAt: asString$
|
|
59022
|
-
nextCheckAt: asString$
|
|
59023
|
-
lastVerificationError: asString$
|
|
59023
|
+
licenseKey: asString$9(raw.licenseKey ?? raw.license_key),
|
|
59024
|
+
purchaseEmail: asString$9(raw.purchaseEmail ?? raw.purchase_email),
|
|
59025
|
+
lastVerifiedAt: asString$9(raw.lastVerifiedAt ?? raw.last_verified_at),
|
|
59026
|
+
nextCheckAt: asString$9(raw.nextCheckAt ?? raw.next_check_at),
|
|
59027
|
+
lastVerificationError: asString$9(raw.lastVerificationError ?? raw.last_verification_error),
|
|
59024
59028
|
status,
|
|
59025
|
-
signature: asString$
|
|
59029
|
+
signature: asString$9(raw.signature)
|
|
59026
59030
|
};
|
|
59027
59031
|
return Boolean(license.licenseKey || license.purchaseEmail || license.lastVerifiedAt || license.nextCheckAt || license.lastVerificationError || license.status) ? license : null;
|
|
59028
59032
|
}
|
|
@@ -59089,14 +59093,14 @@ async function readCodexSettingsJsonRaw() {
|
|
|
59089
59093
|
};
|
|
59090
59094
|
}
|
|
59091
59095
|
async function writeCodexSettingsJsonRaw(payload) {
|
|
59092
|
-
if (!isRecord$
|
|
59096
|
+
if (!isRecord$7(payload)) return;
|
|
59093
59097
|
const autoRoll = parseAutoRoll(payload.autoRoll ?? payload.auto_roll);
|
|
59094
59098
|
const license = parseStoredLicense(payload.license);
|
|
59095
59099
|
await patchAppState({
|
|
59096
59100
|
app: {
|
|
59097
|
-
lastProfileName: asString$
|
|
59098
|
-
lastAppVersion: asString$
|
|
59099
|
-
pendingUpdateVersion: asString$
|
|
59101
|
+
lastProfileName: asString$9(payload.lastProfileName ?? payload.last_profile_name),
|
|
59102
|
+
lastAppVersion: asString$9(payload.lastAppVersion ?? payload.last_app_version),
|
|
59103
|
+
pendingUpdateVersion: asString$9(payload.pendingUpdateVersion ?? payload.pending_update_version)
|
|
59100
59104
|
},
|
|
59101
59105
|
autoRoll: autoRoll ? {
|
|
59102
59106
|
enabled: autoRoll.enabled,
|
|
@@ -59126,11 +59130,11 @@ async function writeCodexSettingsJsonRaw(payload) {
|
|
|
59126
59130
|
folderHistory: Array.isArray(payload.folderHistory) ? payload.folderHistory : void 0,
|
|
59127
59131
|
pinnedPaths: Array.isArray(payload.pinnedPaths) ? payload.pinnedPaths : void 0
|
|
59128
59132
|
},
|
|
59129
|
-
workspaceSettingsByPath: isRecord$
|
|
59130
|
-
conversationCategoriesByCwd: isRecord$
|
|
59131
|
-
conversationCategoryAssignmentsByCwd: isRecord$
|
|
59132
|
-
git: isRecord$
|
|
59133
|
-
sync: isRecord$
|
|
59133
|
+
workspaceSettingsByPath: isRecord$7(payload.workspaceSettingsByPath) ? payload.workspaceSettingsByPath : isRecord$7(payload.projectSettingsByPath) ? payload.projectSettingsByPath : void 0,
|
|
59134
|
+
conversationCategoriesByCwd: isRecord$7(payload.categoriesByCwd) ? payload.categoriesByCwd : void 0,
|
|
59135
|
+
conversationCategoryAssignmentsByCwd: isRecord$7(payload.conversationCategoryByCwd) ? payload.conversationCategoryByCwd : void 0,
|
|
59136
|
+
git: isRecord$7(payload.git) ? payload.git : void 0,
|
|
59137
|
+
sync: isRecord$7(payload.sync) ? payload.sync : void 0
|
|
59134
59138
|
});
|
|
59135
59139
|
}
|
|
59136
59140
|
//#endregion
|
|
@@ -60011,7 +60015,7 @@ function logInfo(...args) {
|
|
|
60011
60015
|
}
|
|
60012
60016
|
//#endregion
|
|
60013
60017
|
//#region ../../packages/runtime-codex/src/codex/app-server.ts
|
|
60014
|
-
function isRecord$
|
|
60018
|
+
function isRecord$6(value) {
|
|
60015
60019
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
60016
60020
|
}
|
|
60017
60021
|
function asTrimmedString$2(value) {
|
|
@@ -60032,7 +60036,7 @@ function isThreadNotFoundError$1(error) {
|
|
|
60032
60036
|
const lower = message.toLowerCase();
|
|
60033
60037
|
return lower.includes("thread not found") || lower.includes("rollout");
|
|
60034
60038
|
}
|
|
60035
|
-
function asString$
|
|
60039
|
+
function asString$8(value) {
|
|
60036
60040
|
return typeof value === "string" ? value : value != null ? String(value) : "";
|
|
60037
60041
|
}
|
|
60038
60042
|
function isInlineImageValue(value) {
|
|
@@ -60040,12 +60044,12 @@ function isInlineImageValue(value) {
|
|
|
60040
60044
|
return normalized.startsWith("data:") || normalized.startsWith("http://") || normalized.startsWith("https://");
|
|
60041
60045
|
}
|
|
60042
60046
|
function normalizeSendUserMessageItem(value) {
|
|
60043
|
-
if (!isRecord$
|
|
60044
|
-
const type = asString$
|
|
60047
|
+
if (!isRecord$6(value)) return null;
|
|
60048
|
+
const type = asString$8(value.type).trim();
|
|
60045
60049
|
if (!type) return null;
|
|
60046
|
-
const data = isRecord$
|
|
60050
|
+
const data = isRecord$6(value.data) ? value.data : {};
|
|
60047
60051
|
if (type === "text") {
|
|
60048
|
-
const text = asString$
|
|
60052
|
+
const text = asString$8(data.text ?? value.text);
|
|
60049
60053
|
if (!text.trim()) return null;
|
|
60050
60054
|
return {
|
|
60051
60055
|
type: "text",
|
|
@@ -60053,7 +60057,7 @@ function normalizeSendUserMessageItem(value) {
|
|
|
60053
60057
|
};
|
|
60054
60058
|
}
|
|
60055
60059
|
if (type === "image") {
|
|
60056
|
-
const imageUrl = asString$
|
|
60060
|
+
const imageUrl = asString$8(data.image_url ?? data.imageUrl ?? data.url ?? value.image_url ?? value.imageUrl ?? value.url).trim();
|
|
60057
60061
|
if (!imageUrl) return null;
|
|
60058
60062
|
return {
|
|
60059
60063
|
type: "image",
|
|
@@ -60061,7 +60065,7 @@ function normalizeSendUserMessageItem(value) {
|
|
|
60061
60065
|
};
|
|
60062
60066
|
}
|
|
60063
60067
|
if (type === "localImage") {
|
|
60064
|
-
const path = asString$
|
|
60068
|
+
const path = asString$8(data.path ?? value.path).trim();
|
|
60065
60069
|
if (!path) return null;
|
|
60066
60070
|
return {
|
|
60067
60071
|
type: "localImage",
|
|
@@ -60072,13 +60076,13 @@ function normalizeSendUserMessageItem(value) {
|
|
|
60072
60076
|
}
|
|
60073
60077
|
function normalizeTurnInputParams(params) {
|
|
60074
60078
|
const normalized = { ...params };
|
|
60075
|
-
const threadId = asString$
|
|
60076
|
-
if (threadId && !asString$
|
|
60077
|
-
const expectedTurnId = asString$
|
|
60078
|
-
if (expectedTurnId && !asString$
|
|
60079
|
-
const turnId = asString$
|
|
60080
|
-
if (turnId && !asString$
|
|
60081
|
-
const providedInput = Array.isArray(params.input) ? params.input.filter((entry) => isRecord$
|
|
60079
|
+
const threadId = asString$8(params.threadId ?? params.thread_id ?? params.conversationId ?? params.conversation_id ?? "").trim();
|
|
60080
|
+
if (threadId && !asString$8(params.threadId).trim()) normalized.threadId = threadId;
|
|
60081
|
+
const expectedTurnId = asString$8(params.expectedTurnId ?? params.expected_turn_id ?? params.turnId ?? params.turn_id ?? "").trim();
|
|
60082
|
+
if (expectedTurnId && !asString$8(params.expectedTurnId).trim()) normalized.expectedTurnId = expectedTurnId;
|
|
60083
|
+
const turnId = asString$8(params.turnId ?? params.turn_id ?? expectedTurnId).trim();
|
|
60084
|
+
if (turnId && !asString$8(params.turnId).trim()) normalized.turnId = turnId;
|
|
60085
|
+
const providedInput = Array.isArray(params.input) ? params.input.filter((entry) => isRecord$6(entry)) : [];
|
|
60082
60086
|
if (providedInput.length > 0) {
|
|
60083
60087
|
normalized.input = providedInput;
|
|
60084
60088
|
return normalized;
|
|
@@ -60086,17 +60090,17 @@ function normalizeTurnInputParams(params) {
|
|
|
60086
60090
|
const providedItems = Array.isArray(params.items) ? params.items.map((item) => normalizeSendUserMessageItem(item)).filter((item) => item !== null) : [];
|
|
60087
60091
|
if (providedItems.length > 0) {
|
|
60088
60092
|
const input = providedItems.flatMap((item) => {
|
|
60089
|
-
const type = asString$
|
|
60090
|
-
const data = isRecord$
|
|
60093
|
+
const type = asString$8(item.type).trim();
|
|
60094
|
+
const data = isRecord$6(item.data) ? item.data : item;
|
|
60091
60095
|
if (type === "text") {
|
|
60092
|
-
const text = asString$
|
|
60096
|
+
const text = asString$8(data.text).trim();
|
|
60093
60097
|
return text ? [{
|
|
60094
60098
|
type: "text",
|
|
60095
60099
|
text
|
|
60096
60100
|
}] : [];
|
|
60097
60101
|
}
|
|
60098
60102
|
if (type === "localImage") {
|
|
60099
|
-
const path = asString$
|
|
60103
|
+
const path = asString$8(data.path).trim();
|
|
60100
60104
|
return path ? [{
|
|
60101
60105
|
type: "localImage",
|
|
60102
60106
|
path
|
|
@@ -60110,13 +60114,13 @@ function normalizeTurnInputParams(params) {
|
|
|
60110
60114
|
}
|
|
60111
60115
|
}
|
|
60112
60116
|
const input = [];
|
|
60113
|
-
const text = asString$
|
|
60117
|
+
const text = asString$8(params.text);
|
|
60114
60118
|
if (text.trim()) input.push({
|
|
60115
60119
|
type: "text",
|
|
60116
60120
|
text
|
|
60117
60121
|
});
|
|
60118
60122
|
if (Array.isArray(params.images)) for (const candidate of params.images) {
|
|
60119
|
-
const image = asString$
|
|
60123
|
+
const image = asString$8(candidate).trim();
|
|
60120
60124
|
if (!image || isInlineImageValue(image)) continue;
|
|
60121
60125
|
input.push({
|
|
60122
60126
|
type: "localImage",
|
|
@@ -60130,7 +60134,7 @@ function pickMethodKind(method, params) {
|
|
|
60130
60134
|
const normalized = method.toLowerCase();
|
|
60131
60135
|
if (normalized.includes("requestapproval")) return "approval";
|
|
60132
60136
|
if (normalized.includes("requestuserinput")) return "user_input";
|
|
60133
|
-
if (isRecord$
|
|
60137
|
+
if (isRecord$6(params)) {
|
|
60134
60138
|
if ("file_changes" in params || "fileChanges" in params || "grant_root" in params || "grantRoot" in params) return "patch";
|
|
60135
60139
|
if ("command" in params || "parsed_cmd" in params || "parsedCmd" in params || "cwd" in params) return "exec";
|
|
60136
60140
|
}
|
|
@@ -60167,7 +60171,7 @@ function getRequestTimeoutMs(method) {
|
|
|
60167
60171
|
return DEFAULT_REQUEST_TIMEOUT_MS;
|
|
60168
60172
|
}
|
|
60169
60173
|
function normalizeThreadLiveWorkspaceId(value) {
|
|
60170
|
-
return asString$
|
|
60174
|
+
return asString$8(value).trim() || DEFAULT_THREAD_LIVE_WORKSPACE_ID;
|
|
60171
60175
|
}
|
|
60172
60176
|
function threadLiveKey(workspaceId, threadId) {
|
|
60173
60177
|
return `${workspaceId}:${threadId}`;
|
|
@@ -60332,7 +60336,7 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60332
60336
|
try {
|
|
60333
60337
|
const response = await this.request("addConversationListener", listenerParams);
|
|
60334
60338
|
this.addConversationListenerSupported = true;
|
|
60335
|
-
return isRecord$
|
|
60339
|
+
return isRecord$6(response) ? response : null;
|
|
60336
60340
|
} catch (error) {
|
|
60337
60341
|
if (isMethodUnavailableError(error, "addConversationListener")) {
|
|
60338
60342
|
this.addConversationListenerSupported = false;
|
|
@@ -60347,7 +60351,7 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60347
60351
|
try {
|
|
60348
60352
|
const response = await this.request("addConversationListener", listenerParams);
|
|
60349
60353
|
this.addConversationListenerSupported = true;
|
|
60350
|
-
return isRecord$
|
|
60354
|
+
return isRecord$6(response) ? response : null;
|
|
60351
60355
|
} catch (resumeError) {
|
|
60352
60356
|
if (isMethodUnavailableError(resumeError, "addConversationListener")) {
|
|
60353
60357
|
this.addConversationListenerSupported = false;
|
|
@@ -60371,8 +60375,8 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60371
60375
|
}
|
|
60372
60376
|
async addConversationListener(params) {
|
|
60373
60377
|
if (this.addConversationListenerSupported === false) return {};
|
|
60374
|
-
const conversationId = asString$
|
|
60375
|
-
const workspaceId = asString$
|
|
60378
|
+
const conversationId = asString$8(params.conversationId ?? params.threadId ?? params.thread_id ?? "").trim();
|
|
60379
|
+
const workspaceId = asString$8(params.workspaceId ?? params.workspace_id ?? "").trim();
|
|
60376
60380
|
if (!conversationId) try {
|
|
60377
60381
|
const response = await this.request("addConversationListener", params);
|
|
60378
60382
|
this.addConversationListenerSupported = true;
|
|
@@ -60400,7 +60404,7 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60400
60404
|
}
|
|
60401
60405
|
async threadLiveSubscribe(params) {
|
|
60402
60406
|
const workspaceId = normalizeThreadLiveWorkspaceId(params.workspaceId ?? params.workspace_id);
|
|
60403
|
-
const threadId = asString$
|
|
60407
|
+
const threadId = asString$8(params.threadId ?? params.thread_id ?? params.conversationId).trim();
|
|
60404
60408
|
if (!threadId) return {};
|
|
60405
60409
|
const key = threadLiveKey(workspaceId, threadId);
|
|
60406
60410
|
this.threadLiveModeByKey.set(key, "listener");
|
|
@@ -60409,7 +60413,7 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60409
60413
|
}
|
|
60410
60414
|
async threadLiveUnsubscribe(params) {
|
|
60411
60415
|
const workspaceId = normalizeThreadLiveWorkspaceId(params.workspaceId ?? params.workspace_id);
|
|
60412
|
-
const threadId = asString$
|
|
60416
|
+
const threadId = asString$8(params.threadId ?? params.thread_id ?? params.conversationId).trim();
|
|
60413
60417
|
if (!threadId) return {};
|
|
60414
60418
|
const key = threadLiveKey(workspaceId, threadId);
|
|
60415
60419
|
this.threadLiveModeByKey.delete(key);
|
|
@@ -60557,7 +60561,7 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60557
60561
|
listPendingUserInputRequests() {
|
|
60558
60562
|
return [...this.pendingServerRequests.values()].filter((request) => request.kind === "user_input").map((request) => {
|
|
60559
60563
|
const workspaceId = asTrimmedString$2(request.params.workspace_id ?? request.params.workspaceId);
|
|
60560
|
-
const params = isRecord$
|
|
60564
|
+
const params = isRecord$6(request.params.params) ? request.params.params : request.params;
|
|
60561
60565
|
if (!workspaceId) return null;
|
|
60562
60566
|
return {
|
|
60563
60567
|
workspace_id: workspaceId,
|
|
@@ -60670,7 +60674,7 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60670
60674
|
this.logParseFailure(line, parseError);
|
|
60671
60675
|
return true;
|
|
60672
60676
|
}
|
|
60673
|
-
if (!isRecord$
|
|
60677
|
+
if (!isRecord$6(parsed)) {
|
|
60674
60678
|
logWarn("[app-server] unexpected JSON message", parsed);
|
|
60675
60679
|
return true;
|
|
60676
60680
|
}
|
|
@@ -60759,9 +60763,9 @@ var CodexAppServer = class extends EventEmitter {
|
|
|
60759
60763
|
id: request.id,
|
|
60760
60764
|
kind,
|
|
60761
60765
|
method: request.method,
|
|
60762
|
-
params: isRecord$
|
|
60766
|
+
params: isRecord$6(request.params) ? request.params : {}
|
|
60763
60767
|
});
|
|
60764
|
-
const params = isRecord$
|
|
60768
|
+
const params = isRecord$6(request.params) ? request.params : {};
|
|
60765
60769
|
if (kind === "exec") this.emit("codex:exec-command-request", {
|
|
60766
60770
|
requestToken: token,
|
|
60767
60771
|
params
|
|
@@ -61522,11 +61526,11 @@ function startExternalCodexThreadSyncWatcher(homePath) {
|
|
|
61522
61526
|
function resolveStateDbPath(stateDir) {
|
|
61523
61527
|
return nodePath.join(stateDir, "state.sqlite");
|
|
61524
61528
|
}
|
|
61525
|
-
function asString$
|
|
61529
|
+
function asString$7(value) {
|
|
61526
61530
|
return typeof value === "string" ? value : value == null ? "" : String(value);
|
|
61527
61531
|
}
|
|
61528
61532
|
function asTrimmedString$1(value) {
|
|
61529
|
-
return asString$
|
|
61533
|
+
return asString$7(value).trim();
|
|
61530
61534
|
}
|
|
61531
61535
|
function asFiniteNumber(value) {
|
|
61532
61536
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
@@ -63210,7 +63214,7 @@ function proposedPlanIdFromEvent(event, threadId) {
|
|
|
63210
63214
|
if (event.itemId) return `plan:${threadId}:item:${event.itemId}`;
|
|
63211
63215
|
return `plan:${threadId}:event:${event.eventId}`;
|
|
63212
63216
|
}
|
|
63213
|
-
function asString$
|
|
63217
|
+
function asString$6(value) {
|
|
63214
63218
|
return typeof value === "string" ? value : void 0;
|
|
63215
63219
|
}
|
|
63216
63220
|
function runtimePayloadRecord(event) {
|
|
@@ -63228,13 +63232,13 @@ function normalizeRuntimeTurnState(value) {
|
|
|
63228
63232
|
}
|
|
63229
63233
|
}
|
|
63230
63234
|
function runtimeTurnState(event) {
|
|
63231
|
-
return normalizeRuntimeTurnState(asString$
|
|
63235
|
+
return normalizeRuntimeTurnState(asString$6(runtimePayloadRecord(event)?.state));
|
|
63232
63236
|
}
|
|
63233
63237
|
function runtimeTurnErrorMessage(event) {
|
|
63234
|
-
return asString$
|
|
63238
|
+
return asString$6(runtimePayloadRecord(event)?.errorMessage);
|
|
63235
63239
|
}
|
|
63236
63240
|
function runtimeErrorMessageFromEvent(event) {
|
|
63237
|
-
return asString$
|
|
63241
|
+
return asString$6(runtimePayloadRecord(event)?.message);
|
|
63238
63242
|
}
|
|
63239
63243
|
function shouldTriggerPassiveImportedThreadRecovery(event) {
|
|
63240
63244
|
switch (event.type) {
|
|
@@ -63972,13 +63976,13 @@ function asObject$1(value) {
|
|
|
63972
63976
|
if (!value || typeof value !== "object") return;
|
|
63973
63977
|
return value;
|
|
63974
63978
|
}
|
|
63975
|
-
function asString$
|
|
63979
|
+
function asString$5(value) {
|
|
63976
63980
|
return typeof value === "string" ? value : void 0;
|
|
63977
63981
|
}
|
|
63978
63982
|
function readCodexAccountSnapshot(response) {
|
|
63979
63983
|
const record = asObject$1(response);
|
|
63980
63984
|
const account = asObject$1(record?.account) ?? record;
|
|
63981
|
-
const accountType = asString$
|
|
63985
|
+
const accountType = asString$5(account?.type);
|
|
63982
63986
|
if (accountType === "apiKey") return {
|
|
63983
63987
|
type: "apiKey",
|
|
63984
63988
|
planType: null,
|
|
@@ -65522,7 +65526,7 @@ function asObject(value) {
|
|
|
65522
65526
|
if (!value || typeof value !== "object") return;
|
|
65523
65527
|
return value;
|
|
65524
65528
|
}
|
|
65525
|
-
function asString$
|
|
65529
|
+
function asString$4(value) {
|
|
65526
65530
|
return typeof value === "string" ? value : void 0;
|
|
65527
65531
|
}
|
|
65528
65532
|
function asArray(value) {
|
|
@@ -65541,7 +65545,7 @@ function toTurnStatus(value) {
|
|
|
65541
65545
|
}
|
|
65542
65546
|
}
|
|
65543
65547
|
function normalizeItemType(raw) {
|
|
65544
|
-
const type = asString$
|
|
65548
|
+
const type = asString$4(raw);
|
|
65545
65549
|
if (!type) return "item";
|
|
65546
65550
|
return type.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[._/-]/g, " ").replace(/\s+/g, " ").trim().toLowerCase();
|
|
65547
65551
|
}
|
|
@@ -65583,16 +65587,16 @@ function itemTitle(itemType) {
|
|
|
65583
65587
|
function itemDetail(item, payload) {
|
|
65584
65588
|
const nestedResult = asObject(item.result);
|
|
65585
65589
|
const candidates = [
|
|
65586
|
-
asString$
|
|
65587
|
-
asString$
|
|
65588
|
-
asString$
|
|
65589
|
-
asString$
|
|
65590
|
-
asString$
|
|
65591
|
-
asString$
|
|
65592
|
-
asString$
|
|
65593
|
-
asString$
|
|
65594
|
-
asString$
|
|
65595
|
-
asString$
|
|
65590
|
+
asString$4(item.command),
|
|
65591
|
+
asString$4(item.title),
|
|
65592
|
+
asString$4(item.summary),
|
|
65593
|
+
asString$4(item.text),
|
|
65594
|
+
asString$4(item.path),
|
|
65595
|
+
asString$4(item.prompt),
|
|
65596
|
+
asString$4(nestedResult?.command),
|
|
65597
|
+
asString$4(payload.command),
|
|
65598
|
+
asString$4(payload.message),
|
|
65599
|
+
asString$4(payload.prompt)
|
|
65596
65600
|
];
|
|
65597
65601
|
for (const candidate of candidates) {
|
|
65598
65602
|
if (!candidate) continue;
|
|
@@ -65624,9 +65628,9 @@ function toRequestTypeFromKind(kind) {
|
|
|
65624
65628
|
}
|
|
65625
65629
|
function toRequestTypeFromResolvedPayload(payload) {
|
|
65626
65630
|
const request = asObject(payload?.request);
|
|
65627
|
-
const method = asString$
|
|
65631
|
+
const method = asString$4(request?.method) ?? asString$4(payload?.method);
|
|
65628
65632
|
if (method) return toRequestTypeFromMethod(method);
|
|
65629
|
-
const requestKind = asString$
|
|
65633
|
+
const requestKind = asString$4(request?.kind) ?? asString$4(payload?.requestKind);
|
|
65630
65634
|
if (requestKind) return toRequestTypeFromKind(requestKind);
|
|
65631
65635
|
return "unknown";
|
|
65632
65636
|
}
|
|
@@ -65652,17 +65656,17 @@ function toUserInputQuestions(payload) {
|
|
|
65652
65656
|
const options = asArray(question.options)?.map((option) => {
|
|
65653
65657
|
const optionRecord = asObject(option);
|
|
65654
65658
|
if (!optionRecord) return void 0;
|
|
65655
|
-
const label = asString$
|
|
65656
|
-
const description = asString$
|
|
65659
|
+
const label = asString$4(optionRecord.label)?.trim();
|
|
65660
|
+
const description = asString$4(optionRecord.description)?.trim();
|
|
65657
65661
|
if (!label || !description) return;
|
|
65658
65662
|
return {
|
|
65659
65663
|
label,
|
|
65660
65664
|
description
|
|
65661
65665
|
};
|
|
65662
65666
|
}).filter((option) => option !== void 0);
|
|
65663
|
-
const id = asString$
|
|
65664
|
-
const header = asString$
|
|
65665
|
-
const prompt = asString$
|
|
65667
|
+
const id = asString$4(question.id)?.trim();
|
|
65668
|
+
const header = asString$4(question.header)?.trim();
|
|
65669
|
+
const prompt = asString$4(question.question)?.trim();
|
|
65666
65670
|
const multiSelect = question.multiSelect === true || question.multi_select === true;
|
|
65667
65671
|
if (!id || !header || !prompt || !options || options.length === 0) return;
|
|
65668
65672
|
return {
|
|
@@ -65715,9 +65719,9 @@ function codexEventMessage(payload) {
|
|
|
65715
65719
|
}
|
|
65716
65720
|
function codexEventBase(event, canonicalThreadId) {
|
|
65717
65721
|
const msg = codexEventMessage(asObject(event.payload));
|
|
65718
|
-
const turnId = asString$
|
|
65719
|
-
const itemId = asString$
|
|
65720
|
-
const requestId = asString$
|
|
65722
|
+
const turnId = asString$4(msg?.turn_id) ?? asString$4(msg?.turnId);
|
|
65723
|
+
const itemId = asString$4(msg?.item_id) ?? asString$4(msg?.itemId);
|
|
65724
|
+
const requestId = asString$4(msg?.request_id) ?? asString$4(msg?.requestId);
|
|
65721
65725
|
const base = runtimeEventBase(event, canonicalThreadId);
|
|
65722
65726
|
const providerRefs = base.providerRefs ? {
|
|
65723
65727
|
...base.providerRefs,
|
|
@@ -65810,7 +65814,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65810
65814
|
payload: { questions }
|
|
65811
65815
|
}];
|
|
65812
65816
|
}
|
|
65813
|
-
const detail = asString$
|
|
65817
|
+
const detail = asString$4(payload?.command) ?? asString$4(payload?.reason) ?? asString$4(payload?.prompt);
|
|
65814
65818
|
return [{
|
|
65815
65819
|
...runtimeEventBase(event, canonicalThreadId),
|
|
65816
65820
|
type: "request.opened",
|
|
@@ -65867,7 +65871,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65867
65871
|
}
|
|
65868
65872
|
}];
|
|
65869
65873
|
if (event.method === "thread/started") {
|
|
65870
|
-
const providerThreadId = asString$
|
|
65874
|
+
const providerThreadId = asString$4(asObject(payload?.thread)?.id) ?? asString$4(payload?.threadId);
|
|
65871
65875
|
if (!providerThreadId) return [];
|
|
65872
65876
|
return [{
|
|
65873
65877
|
...runtimeEventBase(event, canonicalThreadId),
|
|
@@ -65883,7 +65887,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65883
65887
|
type: "thread.state.changed",
|
|
65884
65888
|
...runtimeEventBase(event, canonicalThreadId),
|
|
65885
65889
|
payload: {
|
|
65886
|
-
state: event.method === "thread/archived" ? "archived" : event.method === "thread/closed" ? "closed" : event.method === "thread/compacted" ? "compacted" : toThreadState(asString$
|
|
65890
|
+
state: event.method === "thread/archived" ? "archived" : event.method === "thread/closed" ? "closed" : event.method === "thread/compacted" ? "compacted" : toThreadState(asString$4(statusRecord?.type) ?? asString$4(threadStatusRecord?.type) ?? asString$4(threadRecord?.state) ?? payload?.state),
|
|
65887
65891
|
...event.payload !== void 0 ? { detail: event.payload } : {}
|
|
65888
65892
|
}
|
|
65889
65893
|
}];
|
|
@@ -65892,7 +65896,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65892
65896
|
type: "thread.metadata.updated",
|
|
65893
65897
|
...runtimeEventBase(event, canonicalThreadId),
|
|
65894
65898
|
payload: {
|
|
65895
|
-
...asString$
|
|
65899
|
+
...asString$4(payload?.threadName) ? { name: asString$4(payload?.threadName) } : {},
|
|
65896
65900
|
...event.payload !== void 0 ? { metadata: asObject(event.payload) } : {}
|
|
65897
65901
|
}
|
|
65898
65902
|
}];
|
|
@@ -65909,19 +65913,19 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65909
65913
|
turnId,
|
|
65910
65914
|
type: "turn.started",
|
|
65911
65915
|
payload: {
|
|
65912
|
-
...asString$
|
|
65913
|
-
...asString$
|
|
65916
|
+
...asString$4(turn?.model) ? { model: asString$4(turn?.model) } : {},
|
|
65917
|
+
...asString$4(turn?.effort) ? { effort: asString$4(turn?.effort) } : {}
|
|
65914
65918
|
}
|
|
65915
65919
|
}];
|
|
65916
65920
|
}
|
|
65917
65921
|
if (event.method === "turn/completed") {
|
|
65918
|
-
const errorMessage = asString$
|
|
65922
|
+
const errorMessage = asString$4(asObject(turn?.error)?.message);
|
|
65919
65923
|
return [{
|
|
65920
65924
|
...runtimeEventBase(event, canonicalThreadId),
|
|
65921
65925
|
type: "turn.completed",
|
|
65922
65926
|
payload: {
|
|
65923
65927
|
state: toTurnStatus(turn?.status),
|
|
65924
|
-
...asString$
|
|
65928
|
+
...asString$4(turn?.stopReason) ? { stopReason: asString$4(turn?.stopReason) } : {},
|
|
65925
65929
|
...turn?.usage !== void 0 ? { usage: turn.usage } : {},
|
|
65926
65930
|
...asObject(turn?.modelUsage) ? { modelUsage: asObject(turn?.modelUsage) } : {},
|
|
65927
65931
|
...asNumber$2(turn?.totalCostUsd) !== void 0 ? { totalCostUsd: asNumber$2(turn?.totalCostUsd) } : {},
|
|
@@ -65940,9 +65944,9 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65940
65944
|
...runtimeEventBase(event, canonicalThreadId),
|
|
65941
65945
|
type: "turn.plan.updated",
|
|
65942
65946
|
payload: {
|
|
65943
|
-
...asString$
|
|
65947
|
+
...asString$4(payload?.explanation) ? { explanation: asString$4(payload?.explanation) } : {},
|
|
65944
65948
|
plan: steps.map((entry) => asObject(entry)).filter((entry) => entry !== void 0).map((entry) => ({
|
|
65945
|
-
step: asString$
|
|
65949
|
+
step: asString$4(entry.step) ?? "step",
|
|
65946
65950
|
status: entry.status === "completed" || entry.status === "inProgress" ? entry.status : "pending"
|
|
65947
65951
|
}))
|
|
65948
65952
|
}
|
|
@@ -65951,7 +65955,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65951
65955
|
if (event.method === "turn/diff/updated") return [{
|
|
65952
65956
|
...runtimeEventBase(event, canonicalThreadId),
|
|
65953
65957
|
type: "turn.diff.updated",
|
|
65954
|
-
payload: { unifiedDiff: asString$
|
|
65958
|
+
payload: { unifiedDiff: asString$4(payload?.unifiedDiff) ?? asString$4(payload?.diff) ?? asString$4(payload?.patch) ?? "" }
|
|
65955
65959
|
}];
|
|
65956
65960
|
if (event.method === "item/started") {
|
|
65957
65961
|
const started = mapItemLifecycle(event, canonicalThreadId, "item.started");
|
|
@@ -65978,7 +65982,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65978
65982
|
return updated ? [updated] : [];
|
|
65979
65983
|
}
|
|
65980
65984
|
if (event.method === "item/plan/delta") {
|
|
65981
|
-
const delta = event.textDelta ?? asString$
|
|
65985
|
+
const delta = event.textDelta ?? asString$4(payload?.delta) ?? asString$4(payload?.text) ?? asString$4(asObject(payload?.content)?.text);
|
|
65982
65986
|
if (!delta || delta.length === 0) return [];
|
|
65983
65987
|
return [{
|
|
65984
65988
|
...runtimeEventBase(event, canonicalThreadId),
|
|
@@ -65987,7 +65991,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
65987
65991
|
}];
|
|
65988
65992
|
}
|
|
65989
65993
|
if (event.method === "item/agentMessage/delta" || event.method === "item/commandExecution/outputDelta" || event.method === "item/fileChange/outputDelta" || event.method === "item/reasoning/summaryTextDelta" || event.method === "item/reasoning/textDelta") {
|
|
65990
|
-
const delta = event.textDelta ?? asString$
|
|
65994
|
+
const delta = event.textDelta ?? asString$4(payload?.delta) ?? asString$4(payload?.text) ?? asString$4(asObject(payload?.content)?.text);
|
|
65991
65995
|
if (!delta || delta.length === 0) return [];
|
|
65992
65996
|
return [{
|
|
65993
65997
|
...runtimeEventBase(event, canonicalThreadId),
|
|
@@ -66004,9 +66008,9 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66004
66008
|
...runtimeEventBase(event, canonicalThreadId),
|
|
66005
66009
|
type: "tool.progress",
|
|
66006
66010
|
payload: {
|
|
66007
|
-
...asString$
|
|
66008
|
-
...asString$
|
|
66009
|
-
...asString$
|
|
66011
|
+
...asString$4(payload?.toolUseId) ? { toolUseId: asString$4(payload?.toolUseId) } : {},
|
|
66012
|
+
...asString$4(payload?.toolName) ? { toolName: asString$4(payload?.toolName) } : {},
|
|
66013
|
+
...asString$4(payload?.summary) ? { summary: asString$4(payload?.summary) } : {},
|
|
66010
66014
|
...asNumber$2(payload?.elapsedSeconds) !== void 0 ? { elapsedSeconds: asNumber$2(payload?.elapsedSeconds) } : {}
|
|
66011
66015
|
}
|
|
66012
66016
|
}];
|
|
@@ -66028,21 +66032,21 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66028
66032
|
}];
|
|
66029
66033
|
if (event.method === "codex/event/task_started") {
|
|
66030
66034
|
const msg = codexEventMessage(payload);
|
|
66031
|
-
const taskId = asString$
|
|
66035
|
+
const taskId = asString$4(payload?.id) ?? asString$4(msg?.turn_id);
|
|
66032
66036
|
if (!taskId) return [];
|
|
66033
66037
|
return [{
|
|
66034
66038
|
...codexEventBase(event, canonicalThreadId),
|
|
66035
66039
|
type: "task.started",
|
|
66036
66040
|
payload: {
|
|
66037
66041
|
taskId: asRuntimeTaskId(taskId),
|
|
66038
|
-
...asString$
|
|
66042
|
+
...asString$4(msg?.collaboration_mode_kind) ? { taskType: asString$4(msg?.collaboration_mode_kind) } : {}
|
|
66039
66043
|
}
|
|
66040
66044
|
}];
|
|
66041
66045
|
}
|
|
66042
66046
|
if (event.method === "codex/event/task_complete") {
|
|
66043
66047
|
const msg = codexEventMessage(payload);
|
|
66044
|
-
const taskId = asString$
|
|
66045
|
-
const proposedPlanMarkdown = extractProposedPlanMarkdown(asString$
|
|
66048
|
+
const taskId = asString$4(payload?.id) ?? asString$4(msg?.turn_id);
|
|
66049
|
+
const proposedPlanMarkdown = extractProposedPlanMarkdown(asString$4(msg?.last_agent_message));
|
|
66046
66050
|
if (!taskId) {
|
|
66047
66051
|
if (!proposedPlanMarkdown) return [];
|
|
66048
66052
|
return [{
|
|
@@ -66057,7 +66061,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66057
66061
|
payload: {
|
|
66058
66062
|
taskId: asRuntimeTaskId(taskId),
|
|
66059
66063
|
status: "completed",
|
|
66060
|
-
...asString$
|
|
66064
|
+
...asString$4(msg?.last_agent_message) ? { summary: asString$4(msg?.last_agent_message) } : {}
|
|
66061
66065
|
}
|
|
66062
66066
|
}];
|
|
66063
66067
|
if (proposedPlanMarkdown) events.push({
|
|
@@ -66069,8 +66073,8 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66069
66073
|
}
|
|
66070
66074
|
if (event.method === "codex/event/agent_reasoning") {
|
|
66071
66075
|
const msg = codexEventMessage(payload);
|
|
66072
|
-
const taskId = asString$
|
|
66073
|
-
const description = asString$
|
|
66076
|
+
const taskId = asString$4(payload?.id);
|
|
66077
|
+
const description = asString$4(msg?.text);
|
|
66074
66078
|
if (!taskId || !description) return [];
|
|
66075
66079
|
return [{
|
|
66076
66080
|
...codexEventBase(event, canonicalThreadId),
|
|
@@ -66083,7 +66087,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66083
66087
|
}
|
|
66084
66088
|
if (event.method === "codex/event/reasoning_content_delta") {
|
|
66085
66089
|
const msg = codexEventMessage(payload);
|
|
66086
|
-
const delta = asString$
|
|
66090
|
+
const delta = asString$4(msg?.delta);
|
|
66087
66091
|
if (!delta) return [];
|
|
66088
66092
|
return [{
|
|
66089
66093
|
...codexEventBase(event, canonicalThreadId),
|
|
@@ -66099,26 +66103,26 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66099
66103
|
type: "model.rerouted",
|
|
66100
66104
|
...runtimeEventBase(event, canonicalThreadId),
|
|
66101
66105
|
payload: {
|
|
66102
|
-
fromModel: asString$
|
|
66103
|
-
toModel: asString$
|
|
66104
|
-
reason: asString$
|
|
66106
|
+
fromModel: asString$4(payload?.fromModel) ?? "unknown",
|
|
66107
|
+
toModel: asString$4(payload?.toModel) ?? "unknown",
|
|
66108
|
+
reason: asString$4(payload?.reason) ?? "unknown"
|
|
66105
66109
|
}
|
|
66106
66110
|
}];
|
|
66107
66111
|
if (event.method === "deprecationNotice") return [{
|
|
66108
66112
|
type: "deprecation.notice",
|
|
66109
66113
|
...runtimeEventBase(event, canonicalThreadId),
|
|
66110
66114
|
payload: {
|
|
66111
|
-
summary: asString$
|
|
66112
|
-
...asString$
|
|
66115
|
+
summary: asString$4(payload?.summary) ?? "Deprecation notice",
|
|
66116
|
+
...asString$4(payload?.details) ? { details: asString$4(payload?.details) } : {}
|
|
66113
66117
|
}
|
|
66114
66118
|
}];
|
|
66115
66119
|
if (event.method === "configWarning") return [{
|
|
66116
66120
|
type: "config.warning",
|
|
66117
66121
|
...runtimeEventBase(event, canonicalThreadId),
|
|
66118
66122
|
payload: {
|
|
66119
|
-
summary: asString$
|
|
66120
|
-
...asString$
|
|
66121
|
-
...asString$
|
|
66123
|
+
summary: asString$4(payload?.summary) ?? "Configuration warning",
|
|
66124
|
+
...asString$4(payload?.details) ? { details: asString$4(payload?.details) } : {},
|
|
66125
|
+
...asString$4(payload?.path) ? { path: asString$4(payload?.path) } : {},
|
|
66122
66126
|
...payload?.range !== void 0 ? { range: payload.range } : {}
|
|
66123
66127
|
}
|
|
66124
66128
|
}];
|
|
@@ -66137,12 +66141,12 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66137
66141
|
...runtimeEventBase(event, canonicalThreadId),
|
|
66138
66142
|
payload: {
|
|
66139
66143
|
success: payload?.success === true,
|
|
66140
|
-
...asString$
|
|
66141
|
-
...asString$
|
|
66144
|
+
...asString$4(payload?.name) ? { name: asString$4(payload?.name) } : {},
|
|
66145
|
+
...asString$4(payload?.error) ? { error: asString$4(payload?.error) } : {}
|
|
66142
66146
|
}
|
|
66143
66147
|
}];
|
|
66144
66148
|
if (event.method === "thread/realtime/started") {
|
|
66145
|
-
const realtimeSessionId = asString$
|
|
66149
|
+
const realtimeSessionId = asString$4(payload?.realtimeSessionId);
|
|
66146
66150
|
return [{
|
|
66147
66151
|
type: "thread.realtime.started",
|
|
66148
66152
|
...runtimeEventBase(event, canonicalThreadId),
|
|
@@ -66160,7 +66164,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66160
66164
|
payload: { audio: event.payload ?? {} }
|
|
66161
66165
|
}];
|
|
66162
66166
|
if (event.method === "thread/realtime/error") {
|
|
66163
|
-
const message = asString$
|
|
66167
|
+
const message = asString$4(payload?.message) ?? event.message ?? "Realtime error";
|
|
66164
66168
|
return [{
|
|
66165
66169
|
type: "thread.realtime.error",
|
|
66166
66170
|
...runtimeEventBase(event, canonicalThreadId),
|
|
@@ -66173,7 +66177,7 @@ function mapToRuntimeEvents(event, canonicalThreadId) {
|
|
|
66173
66177
|
payload: { reason: event.message }
|
|
66174
66178
|
}];
|
|
66175
66179
|
if (event.method === "error") {
|
|
66176
|
-
const message = asString$
|
|
66180
|
+
const message = asString$4(asObject(payload?.error)?.message) ?? event.message ?? "Provider runtime error";
|
|
66177
66181
|
const willRetry = payload?.willRetry === true;
|
|
66178
66182
|
return [{
|
|
66179
66183
|
type: willRetry ? "runtime.warning" : "runtime.error",
|
|
@@ -66780,12 +66784,12 @@ function decodeProviderKind(providerName, operation) {
|
|
|
66780
66784
|
detail: `Unknown persisted provider '${providerName}'.`
|
|
66781
66785
|
}));
|
|
66782
66786
|
}
|
|
66783
|
-
function isRecord$
|
|
66787
|
+
function isRecord$5(value) {
|
|
66784
66788
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
66785
66789
|
}
|
|
66786
66790
|
function mergeRuntimePayload(existing, next) {
|
|
66787
66791
|
if (next === void 0) return existing ?? null;
|
|
66788
|
-
if (isRecord$
|
|
66792
|
+
if (isRecord$5(existing) && isRecord$5(next)) return {
|
|
66789
66793
|
...existing,
|
|
66790
66794
|
...next
|
|
66791
66795
|
};
|
|
@@ -72803,7 +72807,7 @@ const FALLBACK_FEATURE_KEYS = [
|
|
|
72803
72807
|
];
|
|
72804
72808
|
let metadataCache = null;
|
|
72805
72809
|
let metadataCacheAt = 0;
|
|
72806
|
-
function isRecord$
|
|
72810
|
+
function isRecord$4(value) {
|
|
72807
72811
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
72808
72812
|
}
|
|
72809
72813
|
function uniqueSorted(values) {
|
|
@@ -72874,14 +72878,14 @@ function parseFeatureCatalog(output) {
|
|
|
72874
72878
|
}
|
|
72875
72879
|
function parseSchemaKeys(schemaRaw) {
|
|
72876
72880
|
const parsed = JSON.parse(schemaRaw);
|
|
72877
|
-
if (!isRecord$
|
|
72881
|
+
if (!isRecord$4(parsed)) return {
|
|
72878
72882
|
topLevelKeys: FALLBACK_SCHEMA_TOP_LEVEL_KEYS,
|
|
72879
72883
|
featureKeys: FALLBACK_FEATURE_KEYS
|
|
72880
72884
|
};
|
|
72881
|
-
const properties = isRecord$
|
|
72885
|
+
const properties = isRecord$4(parsed.properties) ? parsed.properties : {};
|
|
72882
72886
|
const topLevelKeys = uniqueSorted(Object.keys(properties));
|
|
72883
|
-
const features = isRecord$
|
|
72884
|
-
const featureProperties = isRecord$
|
|
72887
|
+
const features = isRecord$4(properties.features) ? properties.features : {};
|
|
72888
|
+
const featureProperties = isRecord$4(features.properties) ? features.properties : {};
|
|
72885
72889
|
const featureKeys = uniqueSorted(Object.keys(featureProperties));
|
|
72886
72890
|
return {
|
|
72887
72891
|
topLevelKeys: topLevelKeys.length > 0 ? topLevelKeys : FALLBACK_SCHEMA_TOP_LEVEL_KEYS,
|
|
@@ -73627,8 +73631,116 @@ function resolveProfileIdentityKeyFromProfile(profile) {
|
|
|
73627
73631
|
//#endregion
|
|
73628
73632
|
//#region ../../packages/runtime-codex/src/codex/rpc.ts
|
|
73629
73633
|
const RPC_TIMEOUT_MS = 1e4;
|
|
73634
|
+
const ACTIVATION_TURN_TIMEOUT_MS = 9e4;
|
|
73635
|
+
const ACTIVATION_PROMPT = "Reply with exactly: ok.";
|
|
73636
|
+
const ACTIVATION_MODEL = "gpt-5.1-codex-mini";
|
|
73630
73637
|
const MAX_STDERR_CAPTURE_CHARS = 32768;
|
|
73631
73638
|
const REFRESH_TOKEN_REDEEMED_SNIPPET$1 = "refresh token was already used";
|
|
73639
|
+
function isRecord$3(value) {
|
|
73640
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
73641
|
+
}
|
|
73642
|
+
function asString$3(value) {
|
|
73643
|
+
return typeof value === "string" ? value : value != null ? String(value) : "";
|
|
73644
|
+
}
|
|
73645
|
+
function createRpcMessageReader(rl) {
|
|
73646
|
+
const queue = [];
|
|
73647
|
+
const waiters = [];
|
|
73648
|
+
let closedError = null;
|
|
73649
|
+
const rejectAll = (error) => {
|
|
73650
|
+
closedError = error;
|
|
73651
|
+
while (waiters.length > 0) {
|
|
73652
|
+
const waiter = waiters.shift();
|
|
73653
|
+
clearTimeout(waiter.timer);
|
|
73654
|
+
waiter.reject(error);
|
|
73655
|
+
}
|
|
73656
|
+
};
|
|
73657
|
+
const onLine = (line) => {
|
|
73658
|
+
let parsed;
|
|
73659
|
+
try {
|
|
73660
|
+
parsed = JSON.parse(line);
|
|
73661
|
+
} catch {
|
|
73662
|
+
rejectAll(/* @__PURE__ */ new Error("codex RPC returned malformed JSON"));
|
|
73663
|
+
return;
|
|
73664
|
+
}
|
|
73665
|
+
const waiterIndex = waiters.findIndex((waiter) => waiter.predicate(parsed));
|
|
73666
|
+
if (waiterIndex >= 0) {
|
|
73667
|
+
const [waiter] = waiters.splice(waiterIndex, 1);
|
|
73668
|
+
clearTimeout(waiter.timer);
|
|
73669
|
+
waiter.resolve(parsed);
|
|
73670
|
+
return;
|
|
73671
|
+
}
|
|
73672
|
+
queue.push(parsed);
|
|
73673
|
+
};
|
|
73674
|
+
const onClose = () => {
|
|
73675
|
+
rejectAll(/* @__PURE__ */ new Error("codex RPC stream closed before response"));
|
|
73676
|
+
};
|
|
73677
|
+
rl.on("line", onLine);
|
|
73678
|
+
rl.on("close", onClose);
|
|
73679
|
+
return {
|
|
73680
|
+
read(predicate, timeoutMs) {
|
|
73681
|
+
const queuedIndex = queue.findIndex(predicate);
|
|
73682
|
+
if (queuedIndex >= 0) {
|
|
73683
|
+
const [message] = queue.splice(queuedIndex, 1);
|
|
73684
|
+
return Promise.resolve(message);
|
|
73685
|
+
}
|
|
73686
|
+
if (closedError) return Promise.reject(closedError);
|
|
73687
|
+
return new Promise((resolve, reject) => {
|
|
73688
|
+
const waiter = {
|
|
73689
|
+
predicate,
|
|
73690
|
+
resolve,
|
|
73691
|
+
reject,
|
|
73692
|
+
timer: setTimeout(() => {
|
|
73693
|
+
const index = waiters.indexOf(waiter);
|
|
73694
|
+
if (index >= 0) waiters.splice(index, 1);
|
|
73695
|
+
reject(/* @__PURE__ */ new Error("codex RPC timed out"));
|
|
73696
|
+
}, Math.max(1, timeoutMs))
|
|
73697
|
+
};
|
|
73698
|
+
waiters.push(waiter);
|
|
73699
|
+
});
|
|
73700
|
+
},
|
|
73701
|
+
dispose() {
|
|
73702
|
+
rl.off("line", onLine);
|
|
73703
|
+
rl.off("close", onClose);
|
|
73704
|
+
while (waiters.length > 0) {
|
|
73705
|
+
const waiter = waiters.shift();
|
|
73706
|
+
clearTimeout(waiter.timer);
|
|
73707
|
+
}
|
|
73708
|
+
}
|
|
73709
|
+
};
|
|
73710
|
+
}
|
|
73711
|
+
function readThreadIdFromResult(result) {
|
|
73712
|
+
if (!isRecord$3(result)) return null;
|
|
73713
|
+
const value = asString$3((isRecord$3(result.thread) ? result.thread : {}).id ?? result.threadId).trim();
|
|
73714
|
+
return value.length > 0 ? value : null;
|
|
73715
|
+
}
|
|
73716
|
+
function readTurnIdFromResult(result) {
|
|
73717
|
+
if (!isRecord$3(result)) return null;
|
|
73718
|
+
const value = asString$3((isRecord$3(result.turn) ? result.turn : {}).id ?? result.turnId).trim();
|
|
73719
|
+
return value.length > 0 ? value : null;
|
|
73720
|
+
}
|
|
73721
|
+
function readTurnIdFromNotification(message) {
|
|
73722
|
+
if (!isRecord$3(message.params)) return null;
|
|
73723
|
+
const value = asString$3((isRecord$3(message.params.turn) ? message.params.turn : {}).id ?? message.params.turnId).trim();
|
|
73724
|
+
return value.length > 0 ? value : null;
|
|
73725
|
+
}
|
|
73726
|
+
function readTurnStatusFromNotification(message) {
|
|
73727
|
+
if (!isRecord$3(message.params)) return {
|
|
73728
|
+
status: null,
|
|
73729
|
+
reason: null
|
|
73730
|
+
};
|
|
73731
|
+
const turn = isRecord$3(message.params.turn) ? message.params.turn : {};
|
|
73732
|
+
const error = isRecord$3(turn.error) ? turn.error : null;
|
|
73733
|
+
return {
|
|
73734
|
+
status: asString$3(turn.status).trim() || null,
|
|
73735
|
+
reason: error ? asString$3(error.message).trim() || null : null
|
|
73736
|
+
};
|
|
73737
|
+
}
|
|
73738
|
+
function readLegacyEventTurnId(message) {
|
|
73739
|
+
if (!isRecord$3(message.params)) return null;
|
|
73740
|
+
const msg = isRecord$3(message.params.msg) ? message.params.msg : {};
|
|
73741
|
+
const value = asString$3(message.params.id ?? msg.turn_id ?? msg.turnId).trim();
|
|
73742
|
+
return value.length > 0 ? value : null;
|
|
73743
|
+
}
|
|
73632
73744
|
function parseTimestamp$1(value) {
|
|
73633
73745
|
if (typeof value !== "string" || value.trim().length === 0) return null;
|
|
73634
73746
|
const parsed = Date.parse(value);
|
|
@@ -73867,6 +73979,160 @@ async function fetchRateLimitsViaRpc(envOverride, options = {}) {
|
|
|
73867
73979
|
}).catch(() => {});
|
|
73868
73980
|
}
|
|
73869
73981
|
}
|
|
73982
|
+
async function activateResetWindowViaRpc(envOverride, options = {}) {
|
|
73983
|
+
const binaryPath = options.codexPath ?? await requireCodexCli();
|
|
73984
|
+
const tempHome = await promises.mkdtemp(nodePath.join(nodeOs.tmpdir(), "codex-activation-"));
|
|
73985
|
+
const tempAuthPath = nodePath.join(tempHome, "auth.json");
|
|
73986
|
+
let initialSourceAuth = null;
|
|
73987
|
+
const sourceAuthPath = options.authPath ?? (envOverride?.CODEX_HOME ? nodePath.join(envOverride.CODEX_HOME, "auth.json") : nodePath.join(envOverride?.HOME ?? process.env.HOME ?? process.env.USERPROFILE ?? nodeOs.homedir(), ".codex", "auth.json"));
|
|
73988
|
+
try {
|
|
73989
|
+
initialSourceAuth = await promises.readFile(sourceAuthPath, "utf8").catch(() => null);
|
|
73990
|
+
if (!initialSourceAuth) {
|
|
73991
|
+
await promises.rm(tempHome, {
|
|
73992
|
+
recursive: true,
|
|
73993
|
+
force: true
|
|
73994
|
+
}).catch(() => {});
|
|
73995
|
+
return {
|
|
73996
|
+
status: "skipped",
|
|
73997
|
+
reason: "auth-missing"
|
|
73998
|
+
};
|
|
73999
|
+
}
|
|
74000
|
+
await promises.writeFile(tempAuthPath, initialSourceAuth, "utf8");
|
|
74001
|
+
} catch {
|
|
74002
|
+
await promises.rm(tempHome, {
|
|
74003
|
+
recursive: true,
|
|
74004
|
+
force: true
|
|
74005
|
+
}).catch(() => {});
|
|
74006
|
+
return {
|
|
74007
|
+
status: "skipped",
|
|
74008
|
+
reason: "auth-missing"
|
|
74009
|
+
};
|
|
74010
|
+
}
|
|
74011
|
+
const childEnv = {
|
|
74012
|
+
...process.env,
|
|
74013
|
+
...envOverride ?? {},
|
|
74014
|
+
HOME: tempHome,
|
|
74015
|
+
USERPROFILE: tempHome,
|
|
74016
|
+
CODEX_HOME: tempHome,
|
|
74017
|
+
CODEX_TELEMETRY_LABEL: "codex-reset-activation",
|
|
74018
|
+
ELECTRON_RUN_AS_NODE: "1"
|
|
74019
|
+
};
|
|
74020
|
+
const command = buildCodexCommand$1(binaryPath, [
|
|
74021
|
+
"-s",
|
|
74022
|
+
"read-only",
|
|
74023
|
+
"-a",
|
|
74024
|
+
"untrusted",
|
|
74025
|
+
"app-server"
|
|
74026
|
+
], childEnv);
|
|
74027
|
+
const child = spawn(command.command, command.args, {
|
|
74028
|
+
stdio: [
|
|
74029
|
+
"pipe",
|
|
74030
|
+
"pipe",
|
|
74031
|
+
"pipe"
|
|
74032
|
+
],
|
|
74033
|
+
env: childEnv,
|
|
74034
|
+
shell: command.shell
|
|
74035
|
+
});
|
|
74036
|
+
const rl = readline.createInterface({
|
|
74037
|
+
input: child.stdout,
|
|
74038
|
+
crlfDelay: Infinity
|
|
74039
|
+
});
|
|
74040
|
+
const reader = createRpcMessageReader(rl);
|
|
74041
|
+
let stderrOutput = "";
|
|
74042
|
+
child.stderr?.on("data", (chunk) => {
|
|
74043
|
+
if (stderrOutput.length >= MAX_STDERR_CAPTURE_CHARS) return;
|
|
74044
|
+
const text = chunk.toString("utf8");
|
|
74045
|
+
const remaining = MAX_STDERR_CAPTURE_CHARS - stderrOutput.length;
|
|
74046
|
+
stderrOutput += text.slice(0, Math.max(0, remaining));
|
|
74047
|
+
});
|
|
74048
|
+
try {
|
|
74049
|
+
await sendPayload(child, {
|
|
74050
|
+
id: 1,
|
|
74051
|
+
method: "initialize",
|
|
74052
|
+
params: { clientInfo: {
|
|
74053
|
+
name: "codexuse",
|
|
74054
|
+
version: "0.0.0"
|
|
74055
|
+
} }
|
|
74056
|
+
});
|
|
74057
|
+
const initializeResponse = await reader.read((message) => isRpcResponseForRequest(message, 1), RPC_TIMEOUT_MS);
|
|
74058
|
+
if (initializeResponse.error) throw new Error(formatRpcError("initialize", initializeResponse.error));
|
|
74059
|
+
await sendPayload(child, {
|
|
74060
|
+
method: "initialized",
|
|
74061
|
+
params: {}
|
|
74062
|
+
});
|
|
74063
|
+
await sendPayload(child, {
|
|
74064
|
+
id: 2,
|
|
74065
|
+
method: "thread/start",
|
|
74066
|
+
params: {
|
|
74067
|
+
cwd: tempHome,
|
|
74068
|
+
model: ACTIVATION_MODEL,
|
|
74069
|
+
approvalPolicy: "untrusted",
|
|
74070
|
+
sandbox: "read-only",
|
|
74071
|
+
experimentalRawEvents: false
|
|
74072
|
+
}
|
|
74073
|
+
});
|
|
74074
|
+
const threadResponse = await reader.read((message) => isRpcResponseForRequest(message, 2), RPC_TIMEOUT_MS);
|
|
74075
|
+
if (threadResponse.error) throw new Error(formatRpcError("thread/start", threadResponse.error));
|
|
74076
|
+
const threadId = readThreadIdFromResult(threadResponse.result);
|
|
74077
|
+
if (!threadId) throw new Error("thread/start response did not include a thread id.");
|
|
74078
|
+
await sendPayload(child, {
|
|
74079
|
+
id: 3,
|
|
74080
|
+
method: "turn/start",
|
|
74081
|
+
params: {
|
|
74082
|
+
threadId,
|
|
74083
|
+
model: ACTIVATION_MODEL,
|
|
74084
|
+
effort: "low",
|
|
74085
|
+
input: [{
|
|
74086
|
+
type: "text",
|
|
74087
|
+
text: ACTIVATION_PROMPT,
|
|
74088
|
+
text_elements: []
|
|
74089
|
+
}]
|
|
74090
|
+
}
|
|
74091
|
+
});
|
|
74092
|
+
const turnResponse = await reader.read((message) => isRpcResponseForRequest(message, 3), RPC_TIMEOUT_MS);
|
|
74093
|
+
if (turnResponse.error) {
|
|
74094
|
+
const base = formatRpcError("turn/start", turnResponse.error);
|
|
74095
|
+
const hint = inferRefreshFailureHint(stderrOutput);
|
|
74096
|
+
if (hint && !base.toLowerCase().includes(hint)) throw new Error(`${base}; ${hint}`);
|
|
74097
|
+
throw new Error(base);
|
|
74098
|
+
}
|
|
74099
|
+
const turnId = readTurnIdFromResult(turnResponse.result);
|
|
74100
|
+
if (!turnId) throw new Error("turn/start response did not include a turn id.");
|
|
74101
|
+
const turnStatus = readTurnStatusFromNotification(await reader.read((message) => message.method === "turn/completed" && readTurnIdFromNotification(message) === turnId || message.method === "codex/event/task_complete" && readLegacyEventTurnId(message) === turnId, ACTIVATION_TURN_TIMEOUT_MS));
|
|
74102
|
+
if (turnStatus.status === "failed") return {
|
|
74103
|
+
status: "failed",
|
|
74104
|
+
reason: turnStatus.reason ?? "turn-failed",
|
|
74105
|
+
threadId,
|
|
74106
|
+
turnId
|
|
74107
|
+
};
|
|
74108
|
+
return {
|
|
74109
|
+
status: "completed",
|
|
74110
|
+
reason: null,
|
|
74111
|
+
threadId,
|
|
74112
|
+
turnId
|
|
74113
|
+
};
|
|
74114
|
+
} finally {
|
|
74115
|
+
child.kill();
|
|
74116
|
+
reader.dispose();
|
|
74117
|
+
rl.close();
|
|
74118
|
+
try {
|
|
74119
|
+
const updatedAuth = await promises.readFile(tempAuthPath, "utf8");
|
|
74120
|
+
if (updatedAuth.trim().length > 0) {
|
|
74121
|
+
const currentSourceAuth = await promises.readFile(sourceAuthPath, "utf8").catch(() => null);
|
|
74122
|
+
if (shouldWriteBackAuth(initialSourceAuth, currentSourceAuth, updatedAuth)) await promises.writeFile(sourceAuthPath, updatedAuth, "utf8");
|
|
74123
|
+
else if (currentSourceAuth && currentSourceAuth !== updatedAuth && currentSourceAuth !== initialSourceAuth) logWarn("Skipped stale auth sync-back after reset-window activation; source auth changed in flight.", {
|
|
74124
|
+
sourceAuthPath,
|
|
74125
|
+
currentRecencyMs: extractAuthRecencyMs(currentSourceAuth),
|
|
74126
|
+
updatedRecencyMs: extractAuthRecencyMs(updatedAuth)
|
|
74127
|
+
});
|
|
74128
|
+
}
|
|
74129
|
+
} catch {}
|
|
74130
|
+
await promises.rm(tempHome, {
|
|
74131
|
+
recursive: true,
|
|
74132
|
+
force: true
|
|
74133
|
+
}).catch(() => {});
|
|
74134
|
+
}
|
|
74135
|
+
}
|
|
73870
74136
|
//#endregion
|
|
73871
74137
|
//#region ../../packages/runtime-profiles/src/profiles/profile-manager.ts
|
|
73872
74138
|
const TOKEN_EXPIRING_SOON_WINDOW_MS = 900 * 1e3;
|
|
@@ -75100,6 +75366,18 @@ var ProfileManager = class {
|
|
|
75100
75366
|
});
|
|
75101
75367
|
}
|
|
75102
75368
|
}
|
|
75369
|
+
async activateResetWindow(name, options = {}) {
|
|
75370
|
+
const profileName = this.normalizeProfileName(name);
|
|
75371
|
+
try {
|
|
75372
|
+
return await this.enqueueProfileOperation(profileName, () => this.runWithPreparedProfileHome(profileName, (env) => activateResetWindowViaRpc(env, { codexPath: options.codexPath }), { syncFromActiveAuthBeforeAction: false }));
|
|
75373
|
+
} finally {
|
|
75374
|
+
await this.enqueueAuthSwap(async () => {
|
|
75375
|
+
await this.syncActiveAuthFromProfileIfCurrent(profileName);
|
|
75376
|
+
}).catch((error) => {
|
|
75377
|
+
logWarn(`Failed to sync active auth after reset-window activation for '${profileName}':`, error);
|
|
75378
|
+
});
|
|
75379
|
+
}
|
|
75380
|
+
}
|
|
75103
75381
|
/**
|
|
75104
75382
|
* Rename a profile
|
|
75105
75383
|
*/
|
|
@@ -82884,210 +83162,212 @@ async function getOfficialCodexProfileInstances() {
|
|
|
82884
83162
|
};
|
|
82885
83163
|
}
|
|
82886
83164
|
function launchOfficialCodexProfileInstance(options) {
|
|
82887
|
-
return enqueueProfileAction(
|
|
82888
|
-
|
|
82889
|
-
|
|
82890
|
-
|
|
82891
|
-
|
|
82892
|
-
|
|
82893
|
-
|
|
82894
|
-
|
|
82895
|
-
|
|
82896
|
-
|
|
82897
|
-
|
|
82898
|
-
|
|
82899
|
-
|
|
82900
|
-
|
|
82901
|
-
|
|
82902
|
-
|
|
82903
|
-
|
|
82904
|
-
|
|
82905
|
-
|
|
82906
|
-
|
|
82907
|
-
|
|
82908
|
-
|
|
82909
|
-
|
|
82910
|
-
|
|
82911
|
-
|
|
82912
|
-
|
|
82913
|
-
|
|
82914
|
-
|
|
82915
|
-
lastError: null
|
|
82916
|
-
};
|
|
82917
|
-
await patchManagedInstance(verified);
|
|
82918
|
-
return {
|
|
82919
|
-
status: "already-running",
|
|
82920
|
-
profileName: options.profileName,
|
|
82921
|
-
instance: managedInstanceToPayload(verified, true, runtime.appServerPid, runtime.startedAt),
|
|
82922
|
-
reason: null
|
|
82923
|
-
};
|
|
82924
|
-
}
|
|
82925
|
-
}
|
|
82926
|
-
const launch = await openCodexWithProfileHome(candidate, options.profileHome, options.profileName, new Set(mainPids));
|
|
82927
|
-
if (!launch.opened) {
|
|
82928
|
-
const failed = {
|
|
82929
|
-
profileName: options.profileName,
|
|
82930
|
-
profileKey: options.profileKey,
|
|
82931
|
-
profileHome: options.profileHome,
|
|
82932
|
-
appPath: candidate.appPath,
|
|
82933
|
-
bundleId: candidate.bundleId,
|
|
82934
|
-
pid: null,
|
|
82935
|
-
appServerPid: null,
|
|
82936
|
-
launchedAt: null,
|
|
82937
|
-
lastVerifiedAt: null,
|
|
82938
|
-
lastStatus: "failed",
|
|
82939
|
-
lastError: "open-failed"
|
|
82940
|
-
};
|
|
82941
|
-
await patchManagedInstance(failed);
|
|
82942
|
-
return {
|
|
82943
|
-
status: "failed",
|
|
82944
|
-
profileName: options.profileName,
|
|
82945
|
-
instance: managedInstanceToPayload(failed, false),
|
|
82946
|
-
reason: "open-failed"
|
|
82947
|
-
};
|
|
82948
|
-
}
|
|
82949
|
-
const launchedPid = launch.pid;
|
|
82950
|
-
if (launchedPid === null) {
|
|
82951
|
-
const failed = {
|
|
82952
|
-
profileName: options.profileName,
|
|
82953
|
-
profileKey: options.profileKey,
|
|
82954
|
-
profileHome: options.profileHome,
|
|
82955
|
-
appPath: candidate.appPath,
|
|
82956
|
-
bundleId: candidate.bundleId,
|
|
82957
|
-
pid: null,
|
|
82958
|
-
appServerPid: null,
|
|
82959
|
-
launchedAt: null,
|
|
82960
|
-
lastVerifiedAt: null,
|
|
82961
|
-
lastStatus: "failed",
|
|
82962
|
-
lastError: "launch-timeout"
|
|
82963
|
-
};
|
|
82964
|
-
await patchManagedInstance(failed);
|
|
82965
|
-
return {
|
|
82966
|
-
status: "failed",
|
|
82967
|
-
profileName: options.profileName,
|
|
82968
|
-
instance: managedInstanceToPayload(failed, false),
|
|
82969
|
-
reason: "launch-timeout"
|
|
82970
|
-
};
|
|
82971
|
-
}
|
|
82972
|
-
const appServerPid = await waitForAppServerPid(launchedPid, options.profileHome);
|
|
82973
|
-
if (appServerPid === null) {
|
|
82974
|
-
const failed = {
|
|
82975
|
-
profileName: options.profileName,
|
|
82976
|
-
profileKey: options.profileKey,
|
|
82977
|
-
profileHome: options.profileHome,
|
|
82978
|
-
appPath: candidate.appPath,
|
|
82979
|
-
bundleId: candidate.bundleId,
|
|
82980
|
-
pid: null,
|
|
82981
|
-
appServerPid: null,
|
|
82982
|
-
launchedAt: null,
|
|
83165
|
+
return enqueueProfileAction(() => launchOfficialCodexProfileInstanceOnce(options));
|
|
83166
|
+
}
|
|
83167
|
+
async function launchOfficialCodexProfileInstanceOnce(options) {
|
|
83168
|
+
if (process.platform !== "darwin") return {
|
|
83169
|
+
status: "skipped",
|
|
83170
|
+
profileName: options.profileName,
|
|
83171
|
+
instance: null,
|
|
83172
|
+
reason: "unsupported-platform"
|
|
83173
|
+
};
|
|
83174
|
+
const { candidate, mainPids } = await resolveCodexAppTarget();
|
|
83175
|
+
if (!candidate) return {
|
|
83176
|
+
status: "skipped",
|
|
83177
|
+
profileName: options.profileName,
|
|
83178
|
+
instance: null,
|
|
83179
|
+
reason: "official-codex-app-not-found"
|
|
83180
|
+
};
|
|
83181
|
+
const existing = await readManagedInstance(options.profileName);
|
|
83182
|
+
if (existing) {
|
|
83183
|
+
const runtime = await resolveInstanceRuntimeState({
|
|
83184
|
+
instance: existing,
|
|
83185
|
+
candidate,
|
|
83186
|
+
rows: await readProcessRows()
|
|
83187
|
+
});
|
|
83188
|
+
if (runtime.running) {
|
|
83189
|
+
const verified = {
|
|
83190
|
+
...existing,
|
|
83191
|
+
profileHome: existing.profileHome ?? options.profileHome,
|
|
83192
|
+
appServerPid: runtime.appServerPid,
|
|
82983
83193
|
lastVerifiedAt: Date.now(),
|
|
82984
|
-
lastStatus: "
|
|
82985
|
-
lastError:
|
|
83194
|
+
lastStatus: "already-running",
|
|
83195
|
+
lastError: null
|
|
82986
83196
|
};
|
|
82987
|
-
await patchManagedInstance(
|
|
83197
|
+
await patchManagedInstance(verified);
|
|
82988
83198
|
return {
|
|
82989
|
-
status: "
|
|
83199
|
+
status: "already-running",
|
|
82990
83200
|
profileName: options.profileName,
|
|
82991
|
-
instance: managedInstanceToPayload(
|
|
82992
|
-
reason:
|
|
83201
|
+
instance: managedInstanceToPayload(verified, true, runtime.appServerPid, runtime.startedAt),
|
|
83202
|
+
reason: null
|
|
82993
83203
|
};
|
|
82994
83204
|
}
|
|
82995
|
-
|
|
82996
|
-
|
|
83205
|
+
}
|
|
83206
|
+
const launch = await openCodexWithProfileHome(candidate, options.profileHome, options.profileName, new Set(mainPids));
|
|
83207
|
+
if (!launch.opened) {
|
|
83208
|
+
const failed = {
|
|
82997
83209
|
profileName: options.profileName,
|
|
82998
83210
|
profileKey: options.profileKey,
|
|
82999
83211
|
profileHome: options.profileHome,
|
|
83000
83212
|
appPath: candidate.appPath,
|
|
83001
83213
|
bundleId: candidate.bundleId,
|
|
83002
|
-
pid:
|
|
83003
|
-
appServerPid,
|
|
83004
|
-
launchedAt:
|
|
83005
|
-
lastVerifiedAt:
|
|
83006
|
-
lastStatus: "
|
|
83007
|
-
lastError:
|
|
83214
|
+
pid: null,
|
|
83215
|
+
appServerPid: null,
|
|
83216
|
+
launchedAt: null,
|
|
83217
|
+
lastVerifiedAt: null,
|
|
83218
|
+
lastStatus: "failed",
|
|
83219
|
+
lastError: "open-failed"
|
|
83008
83220
|
};
|
|
83009
|
-
await patchManagedInstance(
|
|
83221
|
+
await patchManagedInstance(failed);
|
|
83010
83222
|
return {
|
|
83011
|
-
status: "
|
|
83223
|
+
status: "failed",
|
|
83012
83224
|
profileName: options.profileName,
|
|
83013
|
-
instance: managedInstanceToPayload(
|
|
83014
|
-
reason:
|
|
83225
|
+
instance: managedInstanceToPayload(failed, false),
|
|
83226
|
+
reason: "open-failed"
|
|
83015
83227
|
};
|
|
83016
|
-
}
|
|
83228
|
+
}
|
|
83229
|
+
const launchedPid = launch.pid;
|
|
83230
|
+
if (launchedPid === null) {
|
|
83231
|
+
const failed = {
|
|
83232
|
+
profileName: options.profileName,
|
|
83233
|
+
profileKey: options.profileKey,
|
|
83234
|
+
profileHome: options.profileHome,
|
|
83235
|
+
appPath: candidate.appPath,
|
|
83236
|
+
bundleId: candidate.bundleId,
|
|
83237
|
+
pid: null,
|
|
83238
|
+
appServerPid: null,
|
|
83239
|
+
launchedAt: null,
|
|
83240
|
+
lastVerifiedAt: null,
|
|
83241
|
+
lastStatus: "failed",
|
|
83242
|
+
lastError: "launch-timeout"
|
|
83243
|
+
};
|
|
83244
|
+
await patchManagedInstance(failed);
|
|
83245
|
+
return {
|
|
83246
|
+
status: "failed",
|
|
83247
|
+
profileName: options.profileName,
|
|
83248
|
+
instance: managedInstanceToPayload(failed, false),
|
|
83249
|
+
reason: "launch-timeout"
|
|
83250
|
+
};
|
|
83251
|
+
}
|
|
83252
|
+
const appServerPid = await waitForAppServerPid(launchedPid, options.profileHome);
|
|
83253
|
+
if (appServerPid === null) {
|
|
83254
|
+
const failed = {
|
|
83255
|
+
profileName: options.profileName,
|
|
83256
|
+
profileKey: options.profileKey,
|
|
83257
|
+
profileHome: options.profileHome,
|
|
83258
|
+
appPath: candidate.appPath,
|
|
83259
|
+
bundleId: candidate.bundleId,
|
|
83260
|
+
pid: null,
|
|
83261
|
+
appServerPid: null,
|
|
83262
|
+
launchedAt: null,
|
|
83263
|
+
lastVerifiedAt: Date.now(),
|
|
83264
|
+
lastStatus: "failed",
|
|
83265
|
+
lastError: "app-server-not-verified"
|
|
83266
|
+
};
|
|
83267
|
+
await patchManagedInstance(failed);
|
|
83268
|
+
return {
|
|
83269
|
+
status: "failed",
|
|
83270
|
+
profileName: options.profileName,
|
|
83271
|
+
instance: managedInstanceToPayload(failed, false),
|
|
83272
|
+
reason: "app-server-not-verified"
|
|
83273
|
+
};
|
|
83274
|
+
}
|
|
83275
|
+
const now = Date.now();
|
|
83276
|
+
const instance = {
|
|
83277
|
+
profileName: options.profileName,
|
|
83278
|
+
profileKey: options.profileKey,
|
|
83279
|
+
profileHome: options.profileHome,
|
|
83280
|
+
appPath: candidate.appPath,
|
|
83281
|
+
bundleId: candidate.bundleId,
|
|
83282
|
+
pid: launchedPid,
|
|
83283
|
+
appServerPid,
|
|
83284
|
+
launchedAt: now,
|
|
83285
|
+
lastVerifiedAt: now,
|
|
83286
|
+
lastStatus: "started",
|
|
83287
|
+
lastError: null
|
|
83288
|
+
};
|
|
83289
|
+
await patchManagedInstance(instance);
|
|
83290
|
+
return {
|
|
83291
|
+
status: "started",
|
|
83292
|
+
profileName: options.profileName,
|
|
83293
|
+
instance: managedInstanceToPayload(instance, true, appServerPid),
|
|
83294
|
+
reason: null
|
|
83295
|
+
};
|
|
83017
83296
|
}
|
|
83018
83297
|
function stopOfficialCodexProfileInstance(profileName) {
|
|
83019
|
-
return enqueueProfileAction(
|
|
83020
|
-
|
|
83021
|
-
|
|
83298
|
+
return enqueueProfileAction(() => stopOfficialCodexProfileInstanceOnce(profileName));
|
|
83299
|
+
}
|
|
83300
|
+
async function stopOfficialCodexProfileInstanceOnce(profileName) {
|
|
83301
|
+
const existing = await readManagedInstance(profileName);
|
|
83302
|
+
if (!existing) return {
|
|
83303
|
+
status: "not-running",
|
|
83304
|
+
profileName,
|
|
83305
|
+
instance: null,
|
|
83306
|
+
reason: "not-managed"
|
|
83307
|
+
};
|
|
83308
|
+
const { candidate } = await resolveCodexAppTarget();
|
|
83309
|
+
if (!candidate) {
|
|
83310
|
+
const stopped = {
|
|
83311
|
+
...existing,
|
|
83312
|
+
pid: null,
|
|
83313
|
+
appServerPid: null,
|
|
83314
|
+
lastVerifiedAt: Date.now(),
|
|
83315
|
+
lastStatus: "not-running",
|
|
83316
|
+
lastError: "official-codex-app-not-found"
|
|
83317
|
+
};
|
|
83318
|
+
await patchManagedInstance(stopped);
|
|
83319
|
+
return {
|
|
83022
83320
|
status: "not-running",
|
|
83023
83321
|
profileName,
|
|
83024
|
-
instance:
|
|
83025
|
-
reason: "not-
|
|
83322
|
+
instance: managedInstanceToPayload(stopped, false),
|
|
83323
|
+
reason: "official-codex-app-not-found"
|
|
83026
83324
|
};
|
|
83027
|
-
|
|
83028
|
-
|
|
83029
|
-
|
|
83030
|
-
|
|
83031
|
-
|
|
83032
|
-
|
|
83033
|
-
|
|
83034
|
-
|
|
83035
|
-
lastError: "official-codex-app-not-found"
|
|
83036
|
-
};
|
|
83037
|
-
await patchManagedInstance(stopped);
|
|
83038
|
-
return {
|
|
83039
|
-
status: "not-running",
|
|
83040
|
-
profileName,
|
|
83041
|
-
instance: managedInstanceToPayload(stopped, false),
|
|
83042
|
-
reason: "official-codex-app-not-found"
|
|
83043
|
-
};
|
|
83044
|
-
}
|
|
83045
|
-
const rows = await readProcessRows();
|
|
83046
|
-
const runtime = await resolveInstanceRuntimeState({
|
|
83047
|
-
instance: existing,
|
|
83048
|
-
candidate,
|
|
83049
|
-
rows
|
|
83050
|
-
});
|
|
83051
|
-
if (!runtime.running || !existing.pid) {
|
|
83052
|
-
const stopped = {
|
|
83053
|
-
...existing,
|
|
83054
|
-
pid: null,
|
|
83055
|
-
appServerPid: null,
|
|
83056
|
-
lastVerifiedAt: Date.now(),
|
|
83057
|
-
lastStatus: "not-running",
|
|
83058
|
-
lastError: null
|
|
83059
|
-
};
|
|
83060
|
-
await patchManagedInstance(stopped);
|
|
83061
|
-
return {
|
|
83062
|
-
status: "not-running",
|
|
83063
|
-
profileName,
|
|
83064
|
-
instance: managedInstanceToPayload(stopped, false),
|
|
83065
|
-
reason: null
|
|
83066
|
-
};
|
|
83067
|
-
}
|
|
83068
|
-
const tree = [existing.pid, ...getDescendantPids(existing.pid, rows)].filter((pid, index, all) => all.indexOf(pid) === index).sort((a, b) => b - a);
|
|
83069
|
-
await signalPids(tree, "SIGTERM");
|
|
83070
|
-
if (!await waitForMainPidExit(existing.pid, 5e3)) {
|
|
83071
|
-
await signalPids(tree, "SIGKILL");
|
|
83072
|
-
await waitForMainPidExit(existing.pid, EXIT_WAIT_MS);
|
|
83073
|
-
}
|
|
83074
|
-
const stillRunning = (await readProcessRows()).some((row) => row.pid === existing.pid);
|
|
83325
|
+
}
|
|
83326
|
+
const rows = await readProcessRows();
|
|
83327
|
+
const runtime = await resolveInstanceRuntimeState({
|
|
83328
|
+
instance: existing,
|
|
83329
|
+
candidate,
|
|
83330
|
+
rows
|
|
83331
|
+
});
|
|
83332
|
+
if (!runtime.running || !existing.pid) {
|
|
83075
83333
|
const stopped = {
|
|
83076
83334
|
...existing,
|
|
83077
|
-
pid:
|
|
83078
|
-
appServerPid:
|
|
83335
|
+
pid: null,
|
|
83336
|
+
appServerPid: null,
|
|
83079
83337
|
lastVerifiedAt: Date.now(),
|
|
83080
|
-
lastStatus:
|
|
83081
|
-
lastError:
|
|
83338
|
+
lastStatus: "not-running",
|
|
83339
|
+
lastError: null
|
|
83082
83340
|
};
|
|
83083
83341
|
await patchManagedInstance(stopped);
|
|
83084
83342
|
return {
|
|
83085
|
-
status:
|
|
83343
|
+
status: "not-running",
|
|
83086
83344
|
profileName,
|
|
83087
|
-
instance: managedInstanceToPayload(stopped,
|
|
83088
|
-
reason:
|
|
83345
|
+
instance: managedInstanceToPayload(stopped, false),
|
|
83346
|
+
reason: null
|
|
83089
83347
|
};
|
|
83090
|
-
}
|
|
83348
|
+
}
|
|
83349
|
+
const tree = [existing.pid, ...getDescendantPids(existing.pid, rows)].filter((pid, index, all) => all.indexOf(pid) === index).sort((a, b) => b - a);
|
|
83350
|
+
await signalPids(tree, "SIGTERM");
|
|
83351
|
+
if (!await waitForMainPidExit(existing.pid, 5e3)) {
|
|
83352
|
+
await signalPids(tree, "SIGKILL");
|
|
83353
|
+
await waitForMainPidExit(existing.pid, EXIT_WAIT_MS);
|
|
83354
|
+
}
|
|
83355
|
+
const stillRunning = (await readProcessRows()).some((row) => row.pid === existing.pid);
|
|
83356
|
+
const stopped = {
|
|
83357
|
+
...existing,
|
|
83358
|
+
pid: stillRunning ? existing.pid : null,
|
|
83359
|
+
appServerPid: stillRunning ? runtime.appServerPid : null,
|
|
83360
|
+
lastVerifiedAt: Date.now(),
|
|
83361
|
+
lastStatus: stillRunning ? "failed" : "stopped",
|
|
83362
|
+
lastError: stillRunning ? "stop-timeout" : null
|
|
83363
|
+
};
|
|
83364
|
+
await patchManagedInstance(stopped);
|
|
83365
|
+
return {
|
|
83366
|
+
status: stillRunning ? "failed" : "stopped",
|
|
83367
|
+
profileName,
|
|
83368
|
+
instance: managedInstanceToPayload(stopped, stillRunning, stopped.appServerPid, runtime.startedAt),
|
|
83369
|
+
reason: stillRunning ? "stop-timeout" : null
|
|
83370
|
+
};
|
|
83091
83371
|
}
|
|
83092
83372
|
function focusOfficialCodexProfileInstance(profileName) {
|
|
83093
83373
|
return enqueueProfileAction(async () => {
|
|
@@ -83224,13 +83504,15 @@ function stopOfficialCodexObservedProfileInstance(profileName, pid, appServerPid
|
|
|
83224
83504
|
});
|
|
83225
83505
|
}
|
|
83226
83506
|
async function restartOfficialCodexProfileInstance(options) {
|
|
83227
|
-
|
|
83228
|
-
|
|
83229
|
-
|
|
83230
|
-
|
|
83231
|
-
|
|
83232
|
-
|
|
83233
|
-
|
|
83507
|
+
return enqueueProfileAction(async () => {
|
|
83508
|
+
const stopped = await stopOfficialCodexProfileInstanceOnce(options.profileName);
|
|
83509
|
+
if (stopped.status === "failed") return stopped;
|
|
83510
|
+
const launched = await launchOfficialCodexProfileInstanceOnce(options);
|
|
83511
|
+
return {
|
|
83512
|
+
...launched,
|
|
83513
|
+
status: launched.status === "started" ? "restarted" : launched.status
|
|
83514
|
+
};
|
|
83515
|
+
});
|
|
83234
83516
|
}
|
|
83235
83517
|
//#endregion
|
|
83236
83518
|
//#region src/wsServer.ts
|
|
@@ -84587,7 +84869,38 @@ const createServer = fn(function* () {
|
|
|
84587
84869
|
reason: action.status
|
|
84588
84870
|
};
|
|
84589
84871
|
};
|
|
84872
|
+
let officialCodexRestartTargetLock = Promise.resolve();
|
|
84873
|
+
let officialCodexRestartTargetIntent = 0;
|
|
84874
|
+
const enqueueOfficialCodexRestartTarget = (work) => {
|
|
84875
|
+
const run = officialCodexRestartTargetLock.then(work, work);
|
|
84876
|
+
officialCodexRestartTargetLock = run.then(() => void 0, () => void 0);
|
|
84877
|
+
return run;
|
|
84878
|
+
};
|
|
84590
84879
|
const restartOfficialCodexProfileTarget = async (args) => {
|
|
84880
|
+
const intent = ++officialCodexRestartTargetIntent;
|
|
84881
|
+
return enqueueOfficialCodexRestartTarget(() => restartOfficialCodexProfileTargetOnce(args, intent));
|
|
84882
|
+
};
|
|
84883
|
+
const restartOfficialCodexProfileTargetOnce = async (args, intent) => {
|
|
84884
|
+
const isCurrentIntent = () => intent === officialCodexRestartTargetIntent;
|
|
84885
|
+
const skipSuperseded = async (phase) => {
|
|
84886
|
+
const skipped = {
|
|
84887
|
+
status: "skipped",
|
|
84888
|
+
reason: "superseded-by-newer-profile-target"
|
|
84889
|
+
};
|
|
84890
|
+
await recordAutoRollActivitySafe({
|
|
84891
|
+
kind: "official-codex-restart",
|
|
84892
|
+
status: skipped.status,
|
|
84893
|
+
reason: skipped.reason,
|
|
84894
|
+
decisionId: args.decisionId,
|
|
84895
|
+
targetProfileName: args.targetProfileName,
|
|
84896
|
+
profileKey: args.targetProfileKey,
|
|
84897
|
+
phase,
|
|
84898
|
+
restartRequested: false,
|
|
84899
|
+
restartResult: skipped.status
|
|
84900
|
+
});
|
|
84901
|
+
return skipped;
|
|
84902
|
+
};
|
|
84903
|
+
if (!isCurrentIntent()) return skipSuperseded("queued");
|
|
84591
84904
|
await recordAutoRollActivitySafe({
|
|
84592
84905
|
kind: "official-codex-restart",
|
|
84593
84906
|
status: "started",
|
|
@@ -84598,7 +84911,9 @@ const createServer = fn(function* () {
|
|
|
84598
84911
|
phase: "profile",
|
|
84599
84912
|
restartRequested: true
|
|
84600
84913
|
});
|
|
84914
|
+
if (!isCurrentIntent()) return skipSuperseded("start");
|
|
84601
84915
|
const observed = await resolveObservedOfficialCodexProfileMatch(args.targetProfileName, args.targetProfileKey);
|
|
84916
|
+
if (!isCurrentIntent()) return skipSuperseded("observe");
|
|
84602
84917
|
const canRestartManagedWindow = Boolean(observed.pid !== null && observed.observedProfileMatchSource === "managed" && observed.matched);
|
|
84603
84918
|
const canStopMatchedObservedWindow = Boolean(observed.pid !== null && observed.matched && observed.observedProfileMatchSource !== "managed" && observed.canStopObservedWindow);
|
|
84604
84919
|
const observedMatchesSource = !observed.matched && Boolean(args.sourceProfileName || args.sourceProfileKey) && observedOfficialCodexProfileMatches({
|
|
@@ -84625,8 +84940,19 @@ const createServer = fn(function* () {
|
|
|
84625
84940
|
return skipped;
|
|
84626
84941
|
}
|
|
84627
84942
|
const options = await prepareOfficialCodexProfileLaunch(args.targetProfileName);
|
|
84943
|
+
if (!isCurrentIntent()) return skipSuperseded("prepare");
|
|
84628
84944
|
if (observed.observedProfileMatchSource === "managed" && observed.matched) {
|
|
84629
|
-
const
|
|
84945
|
+
const action = await restartOfficialCodexProfileInstance(options);
|
|
84946
|
+
if (!isCurrentIntent()) {
|
|
84947
|
+
if (action.status === "started" || action.status === "restarted") await stopOfficialCodexProfileInstance(args.targetProfileName).catch((error) => {
|
|
84948
|
+
logger.warn("Failed to stop superseded Official Codex profile", {
|
|
84949
|
+
error,
|
|
84950
|
+
profileName: args.targetProfileName
|
|
84951
|
+
});
|
|
84952
|
+
});
|
|
84953
|
+
return skipSuperseded("profile");
|
|
84954
|
+
}
|
|
84955
|
+
const payload = profileActionToRestartPayload(action, "restarted", "profile");
|
|
84630
84956
|
await recordTargetedOfficialCodexRestartResult(payload, args.targetProfileName, args.targetProfileKey, args.decisionId);
|
|
84631
84957
|
return payload;
|
|
84632
84958
|
}
|
|
@@ -84656,7 +84982,18 @@ const createServer = fn(function* () {
|
|
|
84656
84982
|
}
|
|
84657
84983
|
stoppedRunningWindow = stopped.status === "stopped";
|
|
84658
84984
|
}
|
|
84659
|
-
|
|
84985
|
+
if (!isCurrentIntent()) return skipSuperseded("quit");
|
|
84986
|
+
const launched = await launchOfficialCodexProfileInstance(options);
|
|
84987
|
+
if (!isCurrentIntent()) {
|
|
84988
|
+
if (launched.status === "started" || launched.status === "restarted") await stopOfficialCodexProfileInstance(args.targetProfileName).catch((error) => {
|
|
84989
|
+
logger.warn("Failed to stop superseded Official Codex profile", {
|
|
84990
|
+
error,
|
|
84991
|
+
profileName: args.targetProfileName
|
|
84992
|
+
});
|
|
84993
|
+
});
|
|
84994
|
+
return skipSuperseded("launch");
|
|
84995
|
+
}
|
|
84996
|
+
const payload = profileActionToRestartPayload(launched, stoppedRunningWindow ? "restarted" : "started", "launch");
|
|
84660
84997
|
await recordTargetedOfficialCodexRestartResult(payload, args.targetProfileName, args.targetProfileKey, args.decisionId);
|
|
84661
84998
|
return payload;
|
|
84662
84999
|
};
|
|
@@ -84779,7 +85116,9 @@ const createServer = fn(function* () {
|
|
|
84779
85116
|
await rememberOfficialCodexRestartDebt(targetProfileName, targetProfileKey, "cooldown", decisionId);
|
|
84780
85117
|
await reconcileOfficialCodexRestartDebt();
|
|
84781
85118
|
} else if (result.status === "skipped" && result.reason === "official-codex-app-not-running" && !settings.launchOfficialCodexWhenClosedOnAutoRoll) await clearOfficialCodexRestartDebt();
|
|
84782
|
-
else if (result.status === "skipped"
|
|
85119
|
+
else if (result.status === "skipped" && result.reason === "superseded-by-newer-profile-target") {
|
|
85120
|
+
if ((await getOfficialCodexRestartDebt())?.targetProfileName === targetProfileName) await clearOfficialCodexRestartDebt();
|
|
85121
|
+
} else if (result.status === "skipped" || result.status === "failed") {
|
|
84783
85122
|
await rememberOfficialCodexRestartDebt(targetProfileName, targetProfileKey, result.reason, decisionId);
|
|
84784
85123
|
await reconcileOfficialCodexRestartDebt();
|
|
84785
85124
|
} else {
|
|
@@ -84899,15 +85238,33 @@ const createServer = fn(function* () {
|
|
|
84899
85238
|
switchVerified: true,
|
|
84900
85239
|
restartRequested: decisionContext.restartRequested ?? null
|
|
84901
85240
|
});
|
|
84902
|
-
} else
|
|
84903
|
-
|
|
84904
|
-
|
|
84905
|
-
|
|
84906
|
-
|
|
84907
|
-
|
|
84908
|
-
|
|
84909
|
-
|
|
84910
|
-
|
|
85241
|
+
} else {
|
|
85242
|
+
officialCodexRestartTargetIntent += 1;
|
|
85243
|
+
const pendingRestart = await getOfficialCodexRestartDebt();
|
|
85244
|
+
if (pendingRestart && pendingRestart.targetProfileName !== name) {
|
|
85245
|
+
await clearOfficialCodexRestartDebt();
|
|
85246
|
+
await recordAutoRollActivitySafe({
|
|
85247
|
+
kind: "official-codex-restart",
|
|
85248
|
+
status: "skipped",
|
|
85249
|
+
reason: "manual-profile-switch-superseded-restart",
|
|
85250
|
+
decisionId: pendingRestart.decisionId,
|
|
85251
|
+
sourceProfileName: pendingRestart.sourceProfileName,
|
|
85252
|
+
targetProfileName: pendingRestart.targetProfileName,
|
|
85253
|
+
profileKey: pendingRestart.targetProfileKey,
|
|
85254
|
+
restartRequested: false,
|
|
85255
|
+
restartResult: "skipped"
|
|
85256
|
+
});
|
|
85257
|
+
}
|
|
85258
|
+
try {
|
|
85259
|
+
const rearmAction = await resolveAutoRollRearmActionAfterManualSwitch(name);
|
|
85260
|
+
if (rearmAction === "block") blockAutoRollUntilRearm(name);
|
|
85261
|
+
else if (rearmAction === "unblock") unblockAutoRollRearm(name);
|
|
85262
|
+
} catch (error) {
|
|
85263
|
+
logger.warn("Failed to evaluate auto-roll rearm block after manual switch", {
|
|
85264
|
+
error,
|
|
85265
|
+
profileName: name
|
|
85266
|
+
});
|
|
85267
|
+
}
|
|
84911
85268
|
}
|
|
84912
85269
|
await publishProfileSwitched({ name });
|
|
84913
85270
|
trackAnalyticsEvent("profile_switched", { source });
|
|
@@ -85825,7 +86182,15 @@ const createServer = fn(function* () {
|
|
|
85825
86182
|
decisionId: null
|
|
85826
86183
|
});
|
|
85827
86184
|
});
|
|
85828
|
-
case WS_METHODS.officialCodexInstances: return yield* promise(async () =>
|
|
86185
|
+
case WS_METHODS.officialCodexInstances: return yield* promise(async () => {
|
|
86186
|
+
const [instances, current] = await Promise.all([enrichOfficialCodexInstances(await getOfficialCodexProfileInstances()), profileManager.getCurrentProfile()]);
|
|
86187
|
+
const currentProfile = current.name ? (await profileManager.listProfiles()).find((profile) => profile.name === current.name) ?? null : null;
|
|
86188
|
+
const syncStatus = await getOfficialCodexSyncStatus(currentProfile ? resolveProfileIdentityKeyFromProfile(currentProfile) : null);
|
|
86189
|
+
return {
|
|
86190
|
+
...instances,
|
|
86191
|
+
syncStatus
|
|
86192
|
+
};
|
|
86193
|
+
});
|
|
85829
86194
|
case WS_METHODS.officialCodexLaunchProfile: {
|
|
85830
86195
|
const name = stripRequestTag(request.body).name?.trim() ?? "";
|
|
85831
86196
|
const access = yield* tryPromise({
|
|
@@ -85925,6 +86290,50 @@ const createServer = fn(function* () {
|
|
|
85925
86290
|
return restartOfficialCodexProfileInstance(options);
|
|
85926
86291
|
});
|
|
85927
86292
|
}
|
|
86293
|
+
case WS_METHODS.officialCodexUseProfile: {
|
|
86294
|
+
const name = stripRequestTag(request.body).name?.trim() ?? "";
|
|
86295
|
+
const access = yield* tryPromise({
|
|
86296
|
+
try: () => resolveOfficialCodexProfileAccess(),
|
|
86297
|
+
catch: toOfficialCodexProfileAccessRouteError
|
|
86298
|
+
});
|
|
86299
|
+
yield* try_({
|
|
86300
|
+
try: () => assertOfficialCodexProfileAccess(name, access),
|
|
86301
|
+
catch: toOfficialCodexProfileAccessRouteError
|
|
86302
|
+
});
|
|
86303
|
+
return yield* promise(async () => {
|
|
86304
|
+
const previousName = (await profileManager.getCurrentProfile()).name ?? null;
|
|
86305
|
+
const previousKey = await resolveProfileIdentityKeyByName(previousName);
|
|
86306
|
+
await handleProfileSwitch(name, "app");
|
|
86307
|
+
const verified = await profileManager.getCurrentProfile();
|
|
86308
|
+
if (verified.name !== name || !verified.trusted) {
|
|
86309
|
+
await recordAutoRollActivitySafe({
|
|
86310
|
+
kind: "auth-verified",
|
|
86311
|
+
status: "failed",
|
|
86312
|
+
reason: "active-auth-mismatch-after-switch",
|
|
86313
|
+
sourceProfileName: previousName,
|
|
86314
|
+
targetProfileName: name,
|
|
86315
|
+
switchVerified: false
|
|
86316
|
+
});
|
|
86317
|
+
throw new Error("Profile switch did not verify active Codex auth.");
|
|
86318
|
+
}
|
|
86319
|
+
await recordAutoRollActivitySafe({
|
|
86320
|
+
kind: "auth-verified",
|
|
86321
|
+
status: "ok",
|
|
86322
|
+
reason: null,
|
|
86323
|
+
sourceProfileName: previousName,
|
|
86324
|
+
targetProfileName: name,
|
|
86325
|
+
switchVerified: true
|
|
86326
|
+
});
|
|
86327
|
+
return restartOfficialCodexProfileTarget({
|
|
86328
|
+
targetProfileName: name,
|
|
86329
|
+
targetProfileKey: await resolveProfileIdentityKeyByName(name),
|
|
86330
|
+
sourceProfileName: previousName,
|
|
86331
|
+
sourceProfileKey: previousKey,
|
|
86332
|
+
launchIfNotRunning: true,
|
|
86333
|
+
decisionId: null
|
|
86334
|
+
});
|
|
86335
|
+
});
|
|
86336
|
+
}
|
|
85928
86337
|
case WS_METHODS.officialCodexLaunchProfiles: {
|
|
85929
86338
|
const body = stripRequestTag(request.body);
|
|
85930
86339
|
const rawNames = Array.isArray(body.names) ? body.names : [];
|
|
@@ -85997,6 +86406,78 @@ const createServer = fn(function* () {
|
|
|
85997
86406
|
trackAnalyticsEvent("official_codex_profiles_stop_requested", { count: results.length });
|
|
85998
86407
|
return { results };
|
|
85999
86408
|
}
|
|
86409
|
+
case WS_METHODS.officialCodexActivateProfiles: {
|
|
86410
|
+
const body = stripRequestTag(request.body);
|
|
86411
|
+
const rawNames = Array.isArray(body.names) ? body.names : [];
|
|
86412
|
+
const names = Array.from(new Set(rawNames.map((name) => typeof name === "string" ? name.trim() : "").filter(Boolean)));
|
|
86413
|
+
const access = yield* tryPromise({
|
|
86414
|
+
try: () => resolveOfficialCodexProfileAccess(),
|
|
86415
|
+
catch: toOfficialCodexProfileAccessRouteError
|
|
86416
|
+
});
|
|
86417
|
+
yield* try_({
|
|
86418
|
+
try: () => {
|
|
86419
|
+
for (const name of names) assertOfficialCodexProfileAccess(name, access);
|
|
86420
|
+
},
|
|
86421
|
+
catch: toOfficialCodexProfileAccessRouteError
|
|
86422
|
+
});
|
|
86423
|
+
const results = [];
|
|
86424
|
+
for (const name of names) {
|
|
86425
|
+
const result = yield* promise(async () => {
|
|
86426
|
+
try {
|
|
86427
|
+
const activation = await profileManager.activateResetWindow(name);
|
|
86428
|
+
const entry = {
|
|
86429
|
+
profileName: name,
|
|
86430
|
+
status: activation.status,
|
|
86431
|
+
reason: activation.reason,
|
|
86432
|
+
threadId: activation.threadId ?? null,
|
|
86433
|
+
turnId: activation.turnId ?? null
|
|
86434
|
+
};
|
|
86435
|
+
await recordAutoRollActivitySafe({
|
|
86436
|
+
kind: "reset-window-activation",
|
|
86437
|
+
status: entry.status,
|
|
86438
|
+
reason: entry.reason,
|
|
86439
|
+
profileName: name
|
|
86440
|
+
});
|
|
86441
|
+
return entry;
|
|
86442
|
+
} catch (error) {
|
|
86443
|
+
const entry = {
|
|
86444
|
+
profileName: name,
|
|
86445
|
+
status: "failed",
|
|
86446
|
+
reason: formatUserFacingError(error, { fallback: "Could not activate reset window." }),
|
|
86447
|
+
threadId: null,
|
|
86448
|
+
turnId: null
|
|
86449
|
+
};
|
|
86450
|
+
await recordAutoRollActivitySafe({
|
|
86451
|
+
kind: "reset-window-activation",
|
|
86452
|
+
status: entry.status,
|
|
86453
|
+
reason: entry.reason,
|
|
86454
|
+
profileName: name
|
|
86455
|
+
});
|
|
86456
|
+
return entry;
|
|
86457
|
+
}
|
|
86458
|
+
});
|
|
86459
|
+
results.push(result);
|
|
86460
|
+
}
|
|
86461
|
+
const completed = results.filter((result) => result.status === "completed").length;
|
|
86462
|
+
const failed = results.filter((result) => result.status === "failed").length;
|
|
86463
|
+
const skipped = results.filter((result) => result.status === "skipped").length;
|
|
86464
|
+
if (completed > 0) enqueueAccountsRefreshNow(results.filter((result) => result.status === "completed").map((result) => result.profileName)).catch((error) => {
|
|
86465
|
+
logger.warn("Failed to refresh rate limits after reset-window activation", { error });
|
|
86466
|
+
});
|
|
86467
|
+
trackAnalyticsEvent("official_codex_profiles_activation_requested", {
|
|
86468
|
+
count: results.length,
|
|
86469
|
+
completed,
|
|
86470
|
+
failed,
|
|
86471
|
+
skipped
|
|
86472
|
+
});
|
|
86473
|
+
return {
|
|
86474
|
+
total: results.length,
|
|
86475
|
+
completed,
|
|
86476
|
+
failed,
|
|
86477
|
+
skipped,
|
|
86478
|
+
results
|
|
86479
|
+
};
|
|
86480
|
+
}
|
|
86000
86481
|
case WS_METHODS.cliInfo: return yield* promise(() => getCodexCliInfo());
|
|
86001
86482
|
case WS_METHODS.cliStatus: return yield* promise(() => getCliInstallStatusWithFreshness());
|
|
86002
86483
|
case WS_METHODS.cliCheckFreshness: {
|