sidekick-shared 0.27.5 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +93 -52
- package/dist/accountHealth.d.ts +14 -0
- package/dist/accountHealth.js +61 -14
- package/dist/accountLaunch.d.ts +6 -0
- package/dist/accountLaunch.js +61 -4
- package/dist/accountLease.d.ts +5 -0
- package/dist/accountLease.js +98 -0
- package/dist/accountManager.d.ts +7 -0
- package/dist/accountManager.js +226 -89
- package/dist/accountSync.d.ts +1 -5
- package/dist/accountSync.js +22 -6
- package/dist/accountSyncTypes.d.ts +9 -0
- package/dist/accounts.d.ts +75 -18
- package/dist/accounts.js +712 -189
- package/dist/browser.d.ts +13 -2
- package/dist/browser.js +30 -2
- package/dist/claudeCredentialDoctor.d.ts +50 -0
- package/dist/claudeCredentialDoctor.js +277 -0
- package/dist/claudeCredentialLedger.d.ts +15 -0
- package/dist/claudeCredentialLedger.js +130 -0
- package/dist/claudeCredentials.d.ts +20 -3
- package/dist/claudeCredentials.js +50 -3
- package/dist/claudeLiveGuard.d.ts +33 -0
- package/dist/claudeLiveGuard.js +46 -0
- package/dist/claudePaths.d.ts +11 -0
- package/dist/claudePaths.js +61 -0
- package/dist/claudeProfiles.d.ts +15 -8
- package/dist/claudeProfiles.js +30 -23
- package/dist/claudeRefreshLock.d.ts +15 -0
- package/dist/claudeRefreshLock.js +145 -0
- package/dist/codexAuth.d.ts +4 -0
- package/dist/codexAuth.js +18 -0
- package/dist/codexCredentialDoctor.d.ts +33 -0
- package/dist/codexCredentialDoctor.js +302 -0
- package/dist/codexCredentialStore.d.ts +29 -0
- package/dist/codexCredentialStore.js +213 -0
- package/dist/codexKeepAlive.d.ts +2 -0
- package/dist/codexKeepAlive.js +116 -0
- package/dist/codexPaths.d.ts +30 -2
- package/dist/codexPaths.js +118 -7
- package/dist/codexProfiles.d.ts +38 -35
- package/dist/codexProfiles.js +848 -715
- package/dist/credentialIO.d.ts +67 -7
- package/dist/credentialIO.js +211 -47
- package/dist/doctor.js +2 -2
- package/dist/ensureDefaultAccounts.js +1 -8
- package/dist/esm/accountChangeSignal.js +15 -0
- package/dist/esm/accountChanges.js +152 -0
- package/dist/esm/accountHealth.js +288 -0
- package/dist/esm/accountLaunch.js +145 -0
- package/dist/esm/accountLease.js +60 -0
- package/dist/esm/accountManager.js +606 -0
- package/dist/esm/accountRegistry.js +214 -0
- package/dist/esm/accountStatus.js +51 -0
- package/dist/esm/accountSwitch.js +74 -0
- package/dist/esm/accountSync.js +156 -0
- package/dist/esm/accountSyncTypes.js +4 -0
- package/dist/esm/accounts.js +1291 -0
- package/dist/esm/aggregation/EventAggregator.js +2034 -0
- package/dist/esm/aggregation/FrequencyTracker.js +69 -0
- package/dist/esm/aggregation/HeatmapTracker.js +89 -0
- package/dist/esm/aggregation/PatternExtractor.js +168 -0
- package/dist/esm/aggregation/costProvenance.js +31 -0
- package/dist/esm/aggregation/snapshot.js +161 -0
- package/dist/esm/aggregation/types.js +5 -0
- package/dist/esm/analytics/codeImpact.js +18 -0
- package/dist/esm/analytics/compactionLedger.js +37 -0
- package/dist/esm/analytics/qualityScore.js +112 -0
- package/dist/esm/autoSwitch.js +185 -0
- package/dist/esm/browser.js +34 -0
- package/dist/esm/claudeCredentialDoctor.js +239 -0
- package/dist/esm/claudeCredentialLedger.js +91 -0
- package/dist/esm/claudeCredentials.js +111 -0
- package/dist/esm/claudeLiveGuard.js +43 -0
- package/dist/esm/claudePaths.js +22 -0
- package/dist/esm/claudeProfiles.js +142 -0
- package/dist/esm/claudeRefreshLock.js +106 -0
- package/dist/esm/codexAuth.js +101 -0
- package/dist/esm/codexCredentialDoctor.js +265 -0
- package/dist/esm/codexCredentialStore.js +164 -0
- package/dist/esm/codexKeepAlive.js +112 -0
- package/dist/esm/codexPaths.js +172 -0
- package/dist/esm/codexProfiles.js +1251 -0
- package/dist/esm/codexQuota.js +564 -0
- package/dist/esm/codexQuotaWatcher.js +363 -0
- package/dist/esm/context/composer.js +71 -0
- package/dist/esm/context/sessionContext.js +546 -0
- package/dist/esm/credentialIO.js +283 -0
- package/dist/esm/credentials.js +49 -0
- package/dist/esm/doctor.js +305 -0
- package/dist/esm/ensureDefaultAccounts.js +62 -0
- package/dist/esm/errorHistory.js +56 -0
- package/dist/esm/extractors/errorTaxonomy.js +43 -0
- package/dist/esm/extractors/gatherAssets.js +32 -0
- package/dist/esm/extractors/sessionAssets.js +176 -0
- package/dist/esm/extractors/sources/claudeAssets.js +158 -0
- package/dist/esm/extractors/sources/codexAssets.js +234 -0
- package/dist/esm/extractors/tokenUsage.js +41 -0
- package/dist/esm/extractors/toolCall.js +142 -0
- package/dist/esm/failingTools.js +65 -0
- package/dist/esm/fileHead.js +27 -0
- package/dist/esm/formatters/eventHighlighter.js +332 -0
- package/dist/esm/formatters/noiseClassifier.js +209 -0
- package/dist/esm/formatters/sessionDump.js +328 -0
- package/dist/esm/formatters/toolSummary.js +226 -0
- package/dist/esm/formatting.js +82 -0
- package/dist/esm/handoffUrl.js +23 -0
- package/dist/esm/historicalStore.js +305 -0
- package/dist/esm/humanPrompt.js +88 -0
- package/dist/esm/index.js +213 -0
- package/dist/esm/keepAlive.js +189 -0
- package/dist/esm/liveCredentialGuard.js +33 -0
- package/dist/esm/modelAliases.js +51 -0
- package/dist/esm/modelCatalog.js +139 -0
- package/dist/esm/modelContext.js +280 -0
- package/dist/esm/modelInfo.js +832 -0
- package/dist/esm/multiProviderQuotaService.js +450 -0
- package/dist/esm/node.js +46 -0
- package/dist/esm/observedContextWindows.js +165 -0
- package/dist/esm/observedSessionCollector.js +939 -0
- package/dist/esm/parsers/changelogParser.js +71 -0
- package/dist/esm/parsers/codexHistory.js +89 -0
- package/dist/esm/parsers/codexParser.js +906 -0
- package/dist/esm/parsers/debugLogParser.js +126 -0
- package/dist/esm/parsers/jsonl.js +66 -0
- package/dist/esm/parsers/mcpToolName.js +28 -0
- package/dist/esm/parsers/openCodeParser.js +625 -0
- package/dist/esm/parsers/planExtractor.js +335 -0
- package/dist/esm/parsers/sessionActivityDetector.js +246 -0
- package/dist/esm/parsers/sessionPathResolver.js +713 -0
- package/dist/esm/parsers/subagentScanner.js +360 -0
- package/dist/esm/parsers/subagentStatsCache.js +45 -0
- package/dist/esm/parsers/subagentTraceParser.js +325 -0
- package/dist/esm/paths.js +134 -0
- package/dist/esm/peakHours.js +194 -0
- package/dist/esm/phrases.js +1330 -0
- package/dist/esm/pricingCatalog.js +247 -0
- package/dist/esm/processDetection.js +200 -0
- package/dist/esm/projectMigration.js +59 -0
- package/dist/esm/promptHistory.js +1221 -0
- package/dist/esm/providerFailure.js +362 -0
- package/dist/esm/providerIds.js +6 -0
- package/dist/esm/providerQuota.js +1 -0
- package/dist/esm/providerServiceStatus.js +145 -0
- package/dist/esm/providerServiceStatusTypes.js +1 -0
- package/dist/esm/providerStatus.js +117 -0
- package/dist/esm/providers/claudeCode.js +575 -0
- package/dist/esm/providers/claudeListing.js +121 -0
- package/dist/esm/providers/codex.js +1034 -0
- package/dist/esm/providers/codexDatabase.js +297 -0
- package/dist/esm/providers/codexRollouts.js +215 -0
- package/dist/esm/providers/detect.js +185 -0
- package/dist/esm/providers/diagnostics.js +83 -0
- package/dist/esm/providers/directoryListingCache.js +206 -0
- package/dist/esm/providers/factory.js +54 -0
- package/dist/esm/providers/openCode.js +2008 -0
- package/dist/esm/providers/openCodeDatabase.js +419 -0
- package/dist/esm/providers/rolloutWalker.js +252 -0
- package/dist/esm/providers/types.js +12 -0
- package/dist/esm/quota.js +182 -0
- package/dist/esm/quotaHistory.js +364 -0
- package/dist/esm/quotaPoller.js +230 -0
- package/dist/esm/quotaPresentation.js +97 -0
- package/dist/esm/quotaResolver.js +231 -0
- package/dist/esm/quotaSnapshots.js +130 -0
- package/dist/esm/quotaThresholds.js +85 -0
- package/dist/esm/readers/decisions.js +24 -0
- package/dist/esm/readers/handoff.js +20 -0
- package/dist/esm/readers/helpers.js +27 -0
- package/dist/esm/readers/history.js +9 -0
- package/dist/esm/readers/notes.js +48 -0
- package/dist/esm/readers/plans.js +225 -0
- package/dist/esm/readers/tasks.js +19 -0
- package/dist/esm/report/htmlHelpers.js +280 -0
- package/dist/esm/report/htmlReportGenerator.js +704 -0
- package/dist/esm/report/index.js +7 -0
- package/dist/esm/report/logo.js +2 -0
- package/dist/esm/report/openBrowser.js +19 -0
- package/dist/esm/report/sessionReportInputs.js +33 -0
- package/dist/esm/report/transcriptParser.js +83 -0
- package/dist/esm/report/types.js +4 -0
- package/dist/esm/schemas/accountManager.js +204 -0
- package/dist/esm/schemas/accountStatus.js +25 -0
- package/dist/esm/schemas/assistantTurn.js +74 -0
- package/dist/esm/schemas/index.js +25 -0
- package/dist/esm/schemas/observedSessionV1.js +77 -0
- package/dist/esm/schemas/providerFailure.js +37 -0
- package/dist/esm/schemas/quota.js +132 -0
- package/dist/esm/schemas/quotaHistory.js +40 -0
- package/dist/esm/schemas/sessionEvent.js +216 -0
- package/dist/esm/schemas/stateFile.js +75 -0
- package/dist/esm/schemas/tokenEstimation.js +7 -0
- package/dist/esm/schemas/transcript.js +86 -0
- package/dist/esm/schemas/usageNormalization.js +38 -0
- package/dist/esm/search/advancedFilter.js +197 -0
- package/dist/esm/search/sessionSearch.js +66 -0
- package/dist/esm/sessionFingerprint.js +40 -0
- package/dist/esm/sessionMonitor.js +198 -0
- package/dist/esm/sessionPreviews.js +522 -0
- package/dist/esm/sessionPromptHistory.js +254 -0
- package/dist/esm/sessionPromptSignals.js +364 -0
- package/dist/esm/sessionStats.js +160 -0
- package/dist/esm/sessionTokenTotals.js +98 -0
- package/dist/esm/sessionTranscripts.js +49 -0
- package/dist/esm/stateFile.js +119 -0
- package/dist/esm/statusline/BurnRateCalculator.js +40 -0
- package/dist/esm/statusline/claudeStatuslinePayload.js +148 -0
- package/dist/esm/statusline/formatter.js +122 -0
- package/dist/esm/statusline/index.js +8 -0
- package/dist/esm/terminalSync.js +95 -0
- package/dist/esm/testing/credentialGuard.js +197 -0
- package/dist/esm/testing/index.js +12 -0
- package/dist/esm/testing/sessionLogFixtures.js +128 -0
- package/dist/esm/tokenEstimation.js +67 -0
- package/dist/esm/tokenSummary.js +113 -0
- package/dist/esm/toolCategory.js +82 -0
- package/dist/esm/transcript.js +257 -0
- package/dist/esm/turns/assistantTurn.js +373 -0
- package/dist/esm/types/codex.js +23 -0
- package/dist/esm/types/decisionLog.js +5 -0
- package/dist/esm/types/historicalData.js +47 -0
- package/dist/esm/types/knowledgeNote.js +15 -0
- package/dist/esm/types/observedSessionV1.js +257 -0
- package/dist/esm/types/opencode.js +12 -0
- package/dist/esm/types/plan.js +7 -0
- package/dist/esm/types/sessionEvent.js +10 -0
- package/dist/esm/types/taskPersistence.js +12 -0
- package/dist/esm/usage/billingBlocks.js +148 -0
- package/dist/esm/usage/claudeUsageDedupe.js +189 -0
- package/dist/esm/usage/importSessionHistory.js +84 -0
- package/dist/esm/usage/subagentUsage.js +18 -0
- package/dist/esm/usage/usageEvents.js +402 -0
- package/dist/esm/usage/usageReports.js +202 -0
- package/dist/esm/usageNormalization.js +95 -0
- package/dist/esm/watchers/eventBridge.js +219 -0
- package/dist/esm/watchers/factory.js +63 -0
- package/dist/esm/watchers/jsonlTail.js +289 -0
- package/dist/esm/watchers/jsonlWatcher.js +435 -0
- package/dist/esm/watchers/providerReaderWatcher.js +118 -0
- package/dist/esm/watchers/sqliteWatcher.js +285 -0
- package/dist/esm/watchers/types.js +4 -0
- package/dist/esm/workspaceRoots.js +56 -0
- package/dist/esm/writers/atomic.js +375 -0
- package/dist/esm/writers/decisions.js +51 -0
- package/dist/esm/writers/notes.js +46 -0
- package/dist/esm/writers/tasks.js +63 -0
- package/dist/esm/zaiQuota.js +323 -0
- package/dist/esm/zaiQuotaApi.js +271 -0
- package/dist/esm/zaiQuotaWatcher.js +265 -0
- package/dist/fileHead.d.ts +22 -0
- package/dist/fileHead.js +33 -0
- package/dist/index.d.ts +30 -11
- package/dist/index.js +72 -15
- package/dist/keepAlive.d.ts +2 -1
- package/dist/keepAlive.js +116 -29
- package/dist/liveCredentialGuard.d.ts +28 -0
- package/dist/liveCredentialGuard.js +36 -0
- package/dist/node.d.ts +13 -1
- package/dist/node.js +43 -2
- package/dist/parsers/codexHistory.js +2 -2
- package/dist/parsers/codexParser.d.ts +12 -0
- package/dist/parsers/codexParser.js +34 -12
- package/dist/parsers/debugLogParser.js +2 -2
- package/dist/parsers/sessionPathResolver.js +5 -4
- package/dist/processDetection.d.ts +10 -3
- package/dist/processDetection.js +44 -11
- package/dist/promptHistory.d.ts +32 -0
- package/dist/promptHistory.js +115 -59
- package/dist/providerFailure.d.ts +12 -6
- package/dist/providerFailure.js +45 -0
- package/dist/providers/claudeCode.js +7 -99
- package/dist/providers/claudeListing.d.ts +22 -0
- package/dist/providers/claudeListing.js +158 -0
- package/dist/providers/codex.d.ts +3 -1
- package/dist/providers/codex.js +26 -227
- package/dist/providers/codexRollouts.d.ts +44 -0
- package/dist/providers/codexRollouts.js +261 -0
- package/dist/providers/detect.js +4 -4
- package/dist/readers/plans.js +3 -3
- package/dist/schemas/accountManager.d.ts +22 -0
- package/dist/schemas/accountManager.js +4 -0
- package/dist/schemas/assistantTurn.d.ts +2 -2
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +7 -2
- package/dist/schemas/providerFailure.d.ts +154 -0
- package/dist/schemas/providerFailure.js +40 -0
- package/dist/sessionPromptHistory.d.ts +12 -7
- package/dist/sessionPromptHistory.js +15 -3
- package/dist/sessionPromptSignals.d.ts +9 -0
- package/dist/sessionPromptSignals.js +13 -0
- package/dist/terminalSync.d.ts +12 -2
- package/dist/terminalSync.js +27 -2
- package/dist/testing/credentialGuard.d.ts +23 -0
- package/dist/testing/credentialGuard.js +233 -0
- package/dist/testing/index.d.ts +14 -0
- package/dist/testing/index.js +22 -0
- package/dist/testing/sessionLogFixtures.d.ts +28 -0
- package/dist/testing/sessionLogFixtures.js +169 -0
- package/dist/tokenEstimation.d.ts +2 -0
- package/dist/tokenEstimation.js +21 -11
- package/dist/toolCategory.d.ts +18 -0
- package/dist/toolCategory.js +86 -0
- package/dist/types/codex.d.ts +4 -0
- package/dist/usage/usageEvents.d.ts +16 -0
- package/dist/usage/usageEvents.js +53 -9
- package/dist/watchers/jsonlTail.d.ts +26 -1
- package/dist/watchers/jsonlTail.js +136 -28
- package/dist/watchers/jsonlWatcher.js +7 -0
- package/dist/watchers/providerReaderWatcher.js +1 -0
- package/dist/watchers/types.d.ts +6 -0
- package/dist/workspaceRoots.d.ts +23 -0
- package/dist/workspaceRoots.js +93 -0
- package/package.json +22 -2
package/dist/codexPaths.d.ts
CHANGED
|
@@ -2,16 +2,23 @@ export declare function getDefaultSystemCodexHome(): string;
|
|
|
2
2
|
export declare function getExplicitCodexHome(): string | null;
|
|
3
3
|
/** The home the `codex` CLI reads for this process: `CODEX_HOME` or `~/.codex`. */
|
|
4
4
|
export declare function getSystemCodexHome(): string;
|
|
5
|
+
export declare function resolveSidekickCodexHome(): string;
|
|
6
|
+
/**
|
|
7
|
+
* The environment for spawning `codex`: `baseEnv` with `CODEX_HOME` set to the
|
|
8
|
+
* live home. A non-blank `CODEX_HOME` already in `baseEnv` is kept, so a caller
|
|
9
|
+
* that points one child at its own home does not have it overwritten.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCodexExecutionEnv(baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
5
12
|
export declare function getCodexProfilesDir(): string;
|
|
6
13
|
export declare function getCodexProfileDir(profileId: string): string;
|
|
7
14
|
export declare function getCodexProfileHome(profileId: string): string;
|
|
8
15
|
export declare function getCodexProfileStatePath(profileId: string): string;
|
|
9
16
|
export declare function ensureCodexProfileDirs(profileId: string): void;
|
|
10
17
|
export declare function readFileOrNull(filePath: string): string | null;
|
|
11
|
-
export type CodexCredentialStoreMode = 'file' | 'keyring' | 'auto' | 'ephemeral' | 'unknown';
|
|
18
|
+
export type CodexCredentialStoreMode = 'file' | 'keyring' | 'auto' | 'ephemeral' | 'unknown' | 'unreadable';
|
|
12
19
|
/**
|
|
13
20
|
* How the `codex` CLI persists credentials for a home, from its `config.toml`.
|
|
14
|
-
* `unknown` means the key is absent (
|
|
21
|
+
* `unknown` means the key is absent (Codex defaults to file storage).
|
|
15
22
|
*/
|
|
16
23
|
export declare function getCodexCredentialStoreMode(codexHome?: string): CodexCredentialStoreMode;
|
|
17
24
|
/**
|
|
@@ -19,3 +26,24 @@ export declare function getCodexCredentialStoreMode(codexHome?: string): CodexCr
|
|
|
19
26
|
* keyring entry sidekick could never swap. Adds the key when absent.
|
|
20
27
|
*/
|
|
21
28
|
export declare function forceFileCredentialStore(configToml: string): string;
|
|
29
|
+
export declare function getCodexBackupPath(id: string, legacy?: boolean): string;
|
|
30
|
+
export declare function getCodexLoginsDir(): string;
|
|
31
|
+
export declare function getCodexLoginDir(id: string): string;
|
|
32
|
+
/** Legacy pending profiles remain readable until finalized or discarded. */
|
|
33
|
+
export declare function getCodexLoginHome(id: string): string;
|
|
34
|
+
export declare function getCodexLoginStatePath(id: string): string;
|
|
35
|
+
export declare function getCodexMonitoringHomes(): string[];
|
|
36
|
+
/** Where Codex writes live rollouts, below each home. */
|
|
37
|
+
export declare const CODEX_SESSIONS_SUBDIR = "sessions";
|
|
38
|
+
/** Where Codex moves a rollout when its thread is archived, below each home. */
|
|
39
|
+
export declare const CODEX_ARCHIVED_SESSIONS_SUBDIR = "archived_sessions";
|
|
40
|
+
export interface CodexSessionsDirsOptions {
|
|
41
|
+
/** Also list each home's `archived_sessions` directory when it exists (default true). */
|
|
42
|
+
includeArchived?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Every directory that may hold Codex rollouts: each home's `sessions`, then
|
|
46
|
+
* each home's `archived_sessions` that exists. Live directories come first so
|
|
47
|
+
* callers that pick one directory pick a live one.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getCodexSessionsDirs(homes?: string[], options?: CodexSessionsDirsOptions): string[];
|
package/dist/codexPaths.js
CHANGED
|
@@ -33,9 +33,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CODEX_ARCHIVED_SESSIONS_SUBDIR = exports.CODEX_SESSIONS_SUBDIR = void 0;
|
|
36
37
|
exports.getDefaultSystemCodexHome = getDefaultSystemCodexHome;
|
|
37
38
|
exports.getExplicitCodexHome = getExplicitCodexHome;
|
|
38
39
|
exports.getSystemCodexHome = getSystemCodexHome;
|
|
40
|
+
exports.resolveSidekickCodexHome = resolveSidekickCodexHome;
|
|
41
|
+
exports.getCodexExecutionEnv = getCodexExecutionEnv;
|
|
39
42
|
exports.getCodexProfilesDir = getCodexProfilesDir;
|
|
40
43
|
exports.getCodexProfileDir = getCodexProfileDir;
|
|
41
44
|
exports.getCodexProfileHome = getCodexProfileHome;
|
|
@@ -44,6 +47,13 @@ exports.ensureCodexProfileDirs = ensureCodexProfileDirs;
|
|
|
44
47
|
exports.readFileOrNull = readFileOrNull;
|
|
45
48
|
exports.getCodexCredentialStoreMode = getCodexCredentialStoreMode;
|
|
46
49
|
exports.forceFileCredentialStore = forceFileCredentialStore;
|
|
50
|
+
exports.getCodexBackupPath = getCodexBackupPath;
|
|
51
|
+
exports.getCodexLoginsDir = getCodexLoginsDir;
|
|
52
|
+
exports.getCodexLoginDir = getCodexLoginDir;
|
|
53
|
+
exports.getCodexLoginHome = getCodexLoginHome;
|
|
54
|
+
exports.getCodexLoginStatePath = getCodexLoginStatePath;
|
|
55
|
+
exports.getCodexMonitoringHomes = getCodexMonitoringHomes;
|
|
56
|
+
exports.getCodexSessionsDirs = getCodexSessionsDirs;
|
|
47
57
|
const fs = __importStar(require("fs"));
|
|
48
58
|
const os = __importStar(require("os"));
|
|
49
59
|
const path = __importStar(require("path"));
|
|
@@ -59,10 +69,32 @@ function getExplicitCodexHome() {
|
|
|
59
69
|
function getSystemCodexHome() {
|
|
60
70
|
return getExplicitCodexHome() ?? getDefaultSystemCodexHome();
|
|
61
71
|
}
|
|
72
|
+
function resolveSidekickCodexHome() {
|
|
73
|
+
// Account switching swaps auth.json inside the system home, so the system
|
|
74
|
+
// home (or an explicit CODEX_HOME) is always the single live home.
|
|
75
|
+
return getSystemCodexHome();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The environment for spawning `codex`: `baseEnv` with `CODEX_HOME` set to the
|
|
79
|
+
* live home. A non-blank `CODEX_HOME` already in `baseEnv` is kept, so a caller
|
|
80
|
+
* that points one child at its own home does not have it overwritten.
|
|
81
|
+
*/
|
|
82
|
+
function getCodexExecutionEnv(baseEnv = process.env) {
|
|
83
|
+
const requested = baseEnv.CODEX_HOME?.trim();
|
|
84
|
+
return {
|
|
85
|
+
...baseEnv,
|
|
86
|
+
CODEX_HOME: requested ? requested : resolveSidekickCodexHome(),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
62
89
|
function getCodexProfilesDir() {
|
|
63
90
|
return path.join((0, accountRegistry_1.getAccountsDir)(), 'codex', 'profiles');
|
|
64
91
|
}
|
|
92
|
+
function assertCodexAccountId(id) {
|
|
93
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(id))
|
|
94
|
+
throw new Error('Invalid Codex account id.');
|
|
95
|
+
}
|
|
65
96
|
function getCodexProfileDir(profileId) {
|
|
97
|
+
assertCodexAccountId(profileId);
|
|
66
98
|
return path.join(getCodexProfilesDir(), profileId);
|
|
67
99
|
}
|
|
68
100
|
function getCodexProfileHome(profileId) {
|
|
@@ -82,26 +114,40 @@ function readFileOrNull(filePath) {
|
|
|
82
114
|
return null;
|
|
83
115
|
}
|
|
84
116
|
}
|
|
85
|
-
const STORE_MODE_PATTERN =
|
|
117
|
+
const STORE_MODE_PATTERN = /^[ \t]*cli_auth_credentials_store[ \t]*=[ \t]*["']([a-z]+)["']/m;
|
|
86
118
|
/**
|
|
87
119
|
* How the `codex` CLI persists credentials for a home, from its `config.toml`.
|
|
88
|
-
* `unknown` means the key is absent (
|
|
120
|
+
* `unknown` means the key is absent (Codex defaults to file storage).
|
|
89
121
|
*/
|
|
90
122
|
function getCodexCredentialStoreMode(codexHome = getSystemCodexHome()) {
|
|
91
|
-
|
|
92
|
-
|
|
123
|
+
let config;
|
|
124
|
+
try {
|
|
125
|
+
config = fs.readFileSync(path.join(codexHome, 'config.toml'), 'utf8');
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return error.code === 'ENOENT' ? 'unknown' : 'unreadable';
|
|
129
|
+
}
|
|
130
|
+
const topLevel = config.split(/^[ \t]*\[/m, 1)[0];
|
|
131
|
+
const match = topLevel.match(STORE_MODE_PATTERN);
|
|
132
|
+
if (!match && /^[ \t]*cli_auth_credentials_store\s*=/m.test(topLevel))
|
|
133
|
+
return 'unreadable';
|
|
93
134
|
const value = match?.[1];
|
|
94
135
|
return value === 'file' || value === 'keyring' || value === 'auto' || value === 'ephemeral'
|
|
95
136
|
? value
|
|
96
|
-
:
|
|
137
|
+
: value === undefined
|
|
138
|
+
? 'unknown'
|
|
139
|
+
: 'unreadable';
|
|
97
140
|
}
|
|
98
141
|
/**
|
|
99
142
|
* Rewrite a `config.toml` so an isolated login writes `auth.json` instead of a
|
|
100
143
|
* keyring entry sidekick could never swap. Adds the key when absent.
|
|
101
144
|
*/
|
|
102
145
|
function forceFileCredentialStore(configToml) {
|
|
103
|
-
|
|
104
|
-
|
|
146
|
+
const firstHeader = configToml.search(/^[ \t]*\[/m);
|
|
147
|
+
const header = firstHeader < 0 ? configToml : configToml.slice(0, firstHeader);
|
|
148
|
+
if (STORE_MODE_PATTERN.test(header)) {
|
|
149
|
+
return (header.replace(STORE_MODE_PATTERN, 'cli_auth_credentials_store = "file"') +
|
|
150
|
+
(firstHeader < 0 ? '' : configToml.slice(firstHeader)));
|
|
105
151
|
}
|
|
106
152
|
const line = 'cli_auth_credentials_store = "file"';
|
|
107
153
|
const trimmed = configToml.replace(/\s*$/, '');
|
|
@@ -115,3 +161,68 @@ function forceFileCredentialStore(configToml) {
|
|
|
115
161
|
const head = trimmed.slice(0, firstTable).replace(/\s*$/, '');
|
|
116
162
|
return `${head ? `${head}\n` : ''}${line}\n\n${trimmed.slice(firstTable).replace(/^\s*/, '')}\n`;
|
|
117
163
|
}
|
|
164
|
+
function getCodexBackupPath(id, legacy = false) {
|
|
165
|
+
assertCodexAccountId(id);
|
|
166
|
+
return path.join((0, accountRegistry_1.getAccountsDir)(), 'codex', 'backups', `${id}.${legacy ? 'credentials' : 'auth'}.json`);
|
|
167
|
+
}
|
|
168
|
+
function getCodexLoginsDir() {
|
|
169
|
+
return path.join((0, accountRegistry_1.getAccountsDir)(), 'codex', 'logins');
|
|
170
|
+
}
|
|
171
|
+
function getCodexLoginDir(id) {
|
|
172
|
+
assertCodexAccountId(id);
|
|
173
|
+
return path.join(getCodexLoginsDir(), id);
|
|
174
|
+
}
|
|
175
|
+
/** Legacy pending profiles remain readable until finalized or discarded. */
|
|
176
|
+
function getCodexLoginHome(id) {
|
|
177
|
+
const dir = getCodexLoginDir(id);
|
|
178
|
+
return fs.existsSync(dir) ? path.join(dir, 'codex-home') : getCodexProfileHome(id);
|
|
179
|
+
}
|
|
180
|
+
function getCodexLoginStatePath(id) {
|
|
181
|
+
const dir = getCodexLoginDir(id);
|
|
182
|
+
return fs.existsSync(dir) ? path.join(dir, 'profile.json') : getCodexProfileStatePath(id);
|
|
183
|
+
}
|
|
184
|
+
function dedupePaths(paths) {
|
|
185
|
+
const seen = new Set();
|
|
186
|
+
const unique = [];
|
|
187
|
+
for (const candidate of paths) {
|
|
188
|
+
const normalized = path.resolve(candidate);
|
|
189
|
+
if (seen.has(normalized))
|
|
190
|
+
continue;
|
|
191
|
+
seen.add(normalized);
|
|
192
|
+
unique.push(candidate);
|
|
193
|
+
}
|
|
194
|
+
return unique;
|
|
195
|
+
}
|
|
196
|
+
function getCodexMonitoringHomes() {
|
|
197
|
+
const explicitHome = getExplicitCodexHome();
|
|
198
|
+
if (explicitHome)
|
|
199
|
+
return [explicitHome];
|
|
200
|
+
// The system home is the single live home; profile homes only matter for
|
|
201
|
+
// sessions recorded back when they doubled as live CODEX_HOMEs.
|
|
202
|
+
const homes = [getDefaultSystemCodexHome()];
|
|
203
|
+
for (const profile of (0, accountRegistry_1.listSavedAccountProfiles)('codex')) {
|
|
204
|
+
const profileHome = getCodexProfileHome(profile.id);
|
|
205
|
+
if (fs.existsSync(path.join(profileHome, 'sessions'))) {
|
|
206
|
+
homes.push(profileHome);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return dedupePaths(homes);
|
|
210
|
+
}
|
|
211
|
+
/** Where Codex writes live rollouts, below each home. */
|
|
212
|
+
exports.CODEX_SESSIONS_SUBDIR = 'sessions';
|
|
213
|
+
/** Where Codex moves a rollout when its thread is archived, below each home. */
|
|
214
|
+
exports.CODEX_ARCHIVED_SESSIONS_SUBDIR = 'archived_sessions';
|
|
215
|
+
/**
|
|
216
|
+
* Every directory that may hold Codex rollouts: each home's `sessions`, then
|
|
217
|
+
* each home's `archived_sessions` that exists. Live directories come first so
|
|
218
|
+
* callers that pick one directory pick a live one.
|
|
219
|
+
*/
|
|
220
|
+
function getCodexSessionsDirs(homes = getCodexMonitoringHomes(), options = {}) {
|
|
221
|
+
const live = homes.map((home) => path.join(home, exports.CODEX_SESSIONS_SUBDIR));
|
|
222
|
+
if (options.includeArchived === false)
|
|
223
|
+
return live;
|
|
224
|
+
const archived = homes
|
|
225
|
+
.map((home) => path.join(home, exports.CODEX_ARCHIVED_SESSIONS_SUBDIR))
|
|
226
|
+
.filter((dir) => fs.existsSync(dir));
|
|
227
|
+
return [...live, ...archived];
|
|
228
|
+
}
|
package/dist/codexProfiles.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import type { AccountManagerResult } from './accounts';
|
|
|
3
3
|
import { type AccountHealthSource } from './accountHealth';
|
|
4
4
|
import { type SwitchAccountOptions, type SwitchAccountResult } from './accountSwitch';
|
|
5
5
|
import { type ProviderSyncReport } from './accountSyncTypes';
|
|
6
|
-
|
|
6
|
+
import { type AccountConsumerScan } from './processDetection';
|
|
7
|
+
import { type CodexAuthSnapshot } from './codexCredentialStore';
|
|
8
|
+
export { getCodexProfilesDir, getCodexProfileHome, getSystemCodexHome, getCodexCredentialStoreMode, getCodexMonitoringHomes, resolveSidekickCodexHome, getCodexExecutionEnv, } from './codexPaths';
|
|
7
9
|
export type { CodexCredentialStoreMode } from './codexPaths';
|
|
8
10
|
export interface CodexAccountManagerResult extends AccountManagerResult {
|
|
9
11
|
needsLogin?: boolean;
|
|
@@ -11,12 +13,11 @@ export interface CodexAccountManagerResult extends AccountManagerResult {
|
|
|
11
13
|
codexHome?: string;
|
|
12
14
|
}
|
|
13
15
|
export declare const CODEX_KEYRING_FIX_HINT = "Set `cli_auth_credentials_store = \"file\"` in ~/.codex/config.toml and run `codex login` again.";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
16
|
+
/** Read the freshest saved login without creating a CLI-usable copy. */
|
|
17
|
+
export declare function readStoredCodexAccount(profileId: string): CodexAuthSnapshot | null;
|
|
18
|
+
export declare function isLiveCodexProfile(profile: SavedAccountProfile): boolean;
|
|
19
|
+
/** Caller holds the swap lock. Live-account credentials only enter private storage. */
|
|
20
|
+
export declare function storeCodexProfileAuthUnlocked(profileId: string, authRaw: string | null, legacyRaw: string | null, source: AccountHealthSource): void;
|
|
20
21
|
export declare function storeCodexProfileAuth(profileId: string, authRaw: string | null, legacyRaw: string | null, source: AccountHealthSource): void;
|
|
21
22
|
interface CodexLoginStatus {
|
|
22
23
|
loggedIn: boolean;
|
|
@@ -34,11 +35,9 @@ export declare function readCodexAccountMetadata(codexHome: string): AccountIden
|
|
|
34
35
|
/** {@link readCodexAccountMetadata} without blocking the event loop on the CLI probe. */
|
|
35
36
|
export declare function readCodexAccountMetadataAsync(codexHome: string): Promise<AccountIdentityMetadata>;
|
|
36
37
|
export declare function isCodexProfileAuthenticated(codexHome: string): boolean;
|
|
37
|
-
/** {@link isCodexProfileAuthenticated} without blocking the event loop on the CLI probe. */
|
|
38
38
|
export declare function isCodexProfileAuthenticatedAsync(codexHome: string): Promise<boolean>;
|
|
39
39
|
export declare function listCodexAccounts(): SavedAccountProfile[];
|
|
40
40
|
export declare function getActiveCodexAccount(): SavedAccountProfile | null;
|
|
41
|
-
export declare function resolveSidekickCodexHome(): string;
|
|
42
41
|
/**
|
|
43
42
|
* Resolves the *currently logged-in* Codex account for display, preferring the
|
|
44
43
|
* live `auth.json` identity over the saved registry pointer (which only sidekick's
|
|
@@ -55,14 +54,18 @@ export declare function resolveSidekickCodexHome(): string;
|
|
|
55
54
|
export declare function resolveActiveCodexAccount(options?: {
|
|
56
55
|
selfHeal?: boolean;
|
|
57
56
|
}): ResolvedActiveAccount;
|
|
58
|
-
|
|
59
|
-
export declare function prepareCodexAccount(label: string
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
/** Legacy callers can import current; explicit sign-in passes importCurrent: false. */
|
|
58
|
+
export declare function prepareCodexAccount(label: string, options?: {
|
|
59
|
+
importCurrent?: boolean;
|
|
60
|
+
}): CodexAccountManagerResult;
|
|
61
|
+
export declare function prepareCodexAccountAsync(label: string, options?: {
|
|
62
|
+
importCurrent?: boolean;
|
|
63
|
+
}): Promise<CodexAccountManagerResult>;
|
|
64
|
+
/** Removes only a pending login, never a registered canonical profile. */
|
|
65
|
+
export declare function discardCodexLogin(id: string): void;
|
|
62
66
|
export declare function finalizeCodexAccount(profileId: string, opts?: {
|
|
63
67
|
activate?: boolean;
|
|
64
68
|
}): CodexAccountManagerResult;
|
|
65
|
-
/** {@link finalizeCodexAccount} without blocking the event loop on CLI probes. */
|
|
66
69
|
export declare function finalizeCodexAccountAsync(profileId: string, opts?: {
|
|
67
70
|
activate?: boolean;
|
|
68
71
|
}): Promise<CodexAccountManagerResult>;
|
|
@@ -75,33 +78,33 @@ export declare function finalizeCodexAccountAsync(profileId: string, opts?: {
|
|
|
75
78
|
* child process while holding it.
|
|
76
79
|
*/
|
|
77
80
|
export declare function withCodexAuthSwapLock<T>(operation: () => T): T;
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* Returns the removed ids. Caller holds the swap lock.
|
|
83
|
-
*/
|
|
84
|
-
export declare function dedupeCodexProfiles(): string[];
|
|
85
|
-
/**
|
|
86
|
-
* Fold the live `auth.json` into the saved profiles: register an unknown login
|
|
87
|
-
* (label = email), refresh the matching profile's backup when the live file is
|
|
88
|
-
* newer, and re-point the active pointer at it. Caller holds the swap lock.
|
|
89
|
-
* Never throws; problems land in `warnings`.
|
|
90
|
-
*/
|
|
81
|
+
/** Merge owned profiles only after preserving their newest login in a verified backup. */
|
|
82
|
+
export declare function dedupeCodexProfiles(scan?: AccountConsumerScan): string[];
|
|
83
|
+
export declare function hasPendingCodexRepair(): boolean;
|
|
84
|
+
/** No subprocesses inside this function: hosts resolve process scans before taking the lock. */
|
|
91
85
|
export declare function syncCodexLiveStateUnlocked(source?: AccountHealthSource, probes?: {
|
|
86
|
+
scan?: AccountConsumerScan;
|
|
92
87
|
systemKeyringLoggedIn?: boolean;
|
|
93
88
|
}): ProviderSyncReport;
|
|
94
|
-
/** {@link syncCodexLiveStateUnlocked} under the swap lock. */
|
|
95
89
|
export declare function syncCodexLiveState(source?: AccountHealthSource): ProviderSyncReport;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
export declare function cleanupAbandonedCodexLogins(olderThanMs?: number, now?: number): string[];
|
|
90
|
+
export declare function syncCodexLiveStateAsync(source?: AccountHealthSource): Promise<ProviderSyncReport>;
|
|
91
|
+
/** Only abandoned Sidekick-owned login homes; authenticated copies are preserved privately first. */
|
|
92
|
+
export declare function cleanupAbandonedCodexLogins(olderThanMs?: number, now?: number, scan?: AccountConsumerScan): string[];
|
|
101
93
|
export declare function switchToCodexAccount(profileId: string, options?: SwitchAccountOptions): SwitchAccountResult;
|
|
102
|
-
/** {@link switchToCodexAccount} without blocking the event loop on CLI probes. */
|
|
103
94
|
export declare function switchToCodexAccountAsync(profileId: string, options?: SwitchAccountOptions): Promise<SwitchAccountResult>;
|
|
95
|
+
/** Legacy migration entry points now use the same guarded reconciliation as ordinary sync. */
|
|
104
96
|
export declare function reconcileCodexAuthState(): void;
|
|
105
|
-
/** {@link reconcileCodexAuthState} without blocking the event loop on CLI probes. */
|
|
106
97
|
export declare function reconcileCodexAuthStateAsync(): Promise<void>;
|
|
98
|
+
export declare function getCodexKeepAliveBlocker(id: string): string | null;
|
|
99
|
+
export declare function beginCodexKeepAlive(id: string, leaseMs: number): {
|
|
100
|
+
ok: true;
|
|
101
|
+
} | {
|
|
102
|
+
ok: false;
|
|
103
|
+
reason: string;
|
|
104
|
+
};
|
|
105
|
+
export declare function finishCodexKeepAlive(id: string): void;
|
|
106
|
+
export declare function restoreCodexProfileFromBackup(id: string, options?: {
|
|
107
|
+
restore?: boolean;
|
|
108
|
+
}): 'restored' | 'present' | 'live' | 'none';
|
|
107
109
|
export declare function removeCodexAccount(profileId: string): AccountManagerResult;
|
|
110
|
+
export declare function cleanupAbandonedCodexLoginsAsync(olderThanMs?: number, now?: number): Promise<string[]>;
|