sidekick-shared 0.27.6 → 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 +28 -0
- package/README.md +58 -18
- package/dist/browser.d.ts +13 -2
- package/dist/browser.js +30 -2
- package/dist/claudePaths.d.ts +11 -0
- package/dist/claudePaths.js +61 -0
- package/dist/claudeProfiles.d.ts +2 -9
- package/dist/claudeProfiles.js +10 -25
- package/dist/codexPaths.d.ts +22 -0
- package/dist/codexPaths.js +67 -0
- package/dist/codexProfiles.d.ts +1 -4
- package/dist/codexProfiles.js +5 -43
- package/dist/doctor.js +2 -2
- 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 +16 -7
- package/dist/index.js +49 -15
- 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/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/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/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
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { getAccountsDir, listSavedAccountProfiles } from './accountRegistry';
|
|
5
|
+
export function getDefaultSystemCodexHome() {
|
|
6
|
+
return path.join(os.homedir(), '.codex');
|
|
7
|
+
}
|
|
8
|
+
export function getExplicitCodexHome() {
|
|
9
|
+
const explicitHome = process.env.CODEX_HOME?.trim();
|
|
10
|
+
return explicitHome ? explicitHome : null;
|
|
11
|
+
}
|
|
12
|
+
/** The home the `codex` CLI reads for this process: `CODEX_HOME` or `~/.codex`. */
|
|
13
|
+
export function getSystemCodexHome() {
|
|
14
|
+
return getExplicitCodexHome() ?? getDefaultSystemCodexHome();
|
|
15
|
+
}
|
|
16
|
+
export function resolveSidekickCodexHome() {
|
|
17
|
+
// Account switching swaps auth.json inside the system home, so the system
|
|
18
|
+
// home (or an explicit CODEX_HOME) is always the single live home.
|
|
19
|
+
return getSystemCodexHome();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The environment for spawning `codex`: `baseEnv` with `CODEX_HOME` set to the
|
|
23
|
+
* live home. A non-blank `CODEX_HOME` already in `baseEnv` is kept, so a caller
|
|
24
|
+
* that points one child at its own home does not have it overwritten.
|
|
25
|
+
*/
|
|
26
|
+
export function getCodexExecutionEnv(baseEnv = process.env) {
|
|
27
|
+
const requested = baseEnv.CODEX_HOME?.trim();
|
|
28
|
+
return {
|
|
29
|
+
...baseEnv,
|
|
30
|
+
CODEX_HOME: requested ? requested : resolveSidekickCodexHome(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function getCodexProfilesDir() {
|
|
34
|
+
return path.join(getAccountsDir(), 'codex', 'profiles');
|
|
35
|
+
}
|
|
36
|
+
function assertCodexAccountId(id) {
|
|
37
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(id))
|
|
38
|
+
throw new Error('Invalid Codex account id.');
|
|
39
|
+
}
|
|
40
|
+
export function getCodexProfileDir(profileId) {
|
|
41
|
+
assertCodexAccountId(profileId);
|
|
42
|
+
return path.join(getCodexProfilesDir(), profileId);
|
|
43
|
+
}
|
|
44
|
+
export function getCodexProfileHome(profileId) {
|
|
45
|
+
return path.join(getCodexProfileDir(profileId), 'codex-home');
|
|
46
|
+
}
|
|
47
|
+
export function getCodexProfileStatePath(profileId) {
|
|
48
|
+
return path.join(getCodexProfileDir(profileId), 'profile.json');
|
|
49
|
+
}
|
|
50
|
+
export function ensureCodexProfileDirs(profileId) {
|
|
51
|
+
fs.mkdirSync(getCodexProfileHome(profileId), { recursive: true, mode: 0o700 });
|
|
52
|
+
}
|
|
53
|
+
export function readFileOrNull(filePath) {
|
|
54
|
+
try {
|
|
55
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const STORE_MODE_PATTERN = /^[ \t]*cli_auth_credentials_store[ \t]*=[ \t]*["']([a-z]+)["']/m;
|
|
62
|
+
/**
|
|
63
|
+
* How the `codex` CLI persists credentials for a home, from its `config.toml`.
|
|
64
|
+
* `unknown` means the key is absent (Codex defaults to file storage).
|
|
65
|
+
*/
|
|
66
|
+
export function getCodexCredentialStoreMode(codexHome = getSystemCodexHome()) {
|
|
67
|
+
let config;
|
|
68
|
+
try {
|
|
69
|
+
config = fs.readFileSync(path.join(codexHome, 'config.toml'), 'utf8');
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return error.code === 'ENOENT' ? 'unknown' : 'unreadable';
|
|
73
|
+
}
|
|
74
|
+
const topLevel = config.split(/^[ \t]*\[/m, 1)[0];
|
|
75
|
+
const match = topLevel.match(STORE_MODE_PATTERN);
|
|
76
|
+
if (!match && /^[ \t]*cli_auth_credentials_store\s*=/m.test(topLevel))
|
|
77
|
+
return 'unreadable';
|
|
78
|
+
const value = match?.[1];
|
|
79
|
+
return value === 'file' || value === 'keyring' || value === 'auto' || value === 'ephemeral'
|
|
80
|
+
? value
|
|
81
|
+
: value === undefined
|
|
82
|
+
? 'unknown'
|
|
83
|
+
: 'unreadable';
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Rewrite a `config.toml` so an isolated login writes `auth.json` instead of a
|
|
87
|
+
* keyring entry sidekick could never swap. Adds the key when absent.
|
|
88
|
+
*/
|
|
89
|
+
export function forceFileCredentialStore(configToml) {
|
|
90
|
+
const firstHeader = configToml.search(/^[ \t]*\[/m);
|
|
91
|
+
const header = firstHeader < 0 ? configToml : configToml.slice(0, firstHeader);
|
|
92
|
+
if (STORE_MODE_PATTERN.test(header)) {
|
|
93
|
+
return (header.replace(STORE_MODE_PATTERN, 'cli_auth_credentials_store = "file"') +
|
|
94
|
+
(firstHeader < 0 ? '' : configToml.slice(firstHeader)));
|
|
95
|
+
}
|
|
96
|
+
const line = 'cli_auth_credentials_store = "file"';
|
|
97
|
+
const trimmed = configToml.replace(/\s*$/, '');
|
|
98
|
+
if (!trimmed)
|
|
99
|
+
return `${line}\n`;
|
|
100
|
+
// A key after a `[table]` header belongs to that table: keep this one at the
|
|
101
|
+
// top level by inserting it before the first table header.
|
|
102
|
+
const firstTable = trimmed.search(/^\s*\[/m);
|
|
103
|
+
if (firstTable === -1)
|
|
104
|
+
return `${trimmed}\n${line}\n`;
|
|
105
|
+
const head = trimmed.slice(0, firstTable).replace(/\s*$/, '');
|
|
106
|
+
return `${head ? `${head}\n` : ''}${line}\n\n${trimmed.slice(firstTable).replace(/^\s*/, '')}\n`;
|
|
107
|
+
}
|
|
108
|
+
export function getCodexBackupPath(id, legacy = false) {
|
|
109
|
+
assertCodexAccountId(id);
|
|
110
|
+
return path.join(getAccountsDir(), 'codex', 'backups', `${id}.${legacy ? 'credentials' : 'auth'}.json`);
|
|
111
|
+
}
|
|
112
|
+
export function getCodexLoginsDir() {
|
|
113
|
+
return path.join(getAccountsDir(), 'codex', 'logins');
|
|
114
|
+
}
|
|
115
|
+
export function getCodexLoginDir(id) {
|
|
116
|
+
assertCodexAccountId(id);
|
|
117
|
+
return path.join(getCodexLoginsDir(), id);
|
|
118
|
+
}
|
|
119
|
+
/** Legacy pending profiles remain readable until finalized or discarded. */
|
|
120
|
+
export function getCodexLoginHome(id) {
|
|
121
|
+
const dir = getCodexLoginDir(id);
|
|
122
|
+
return fs.existsSync(dir) ? path.join(dir, 'codex-home') : getCodexProfileHome(id);
|
|
123
|
+
}
|
|
124
|
+
export function getCodexLoginStatePath(id) {
|
|
125
|
+
const dir = getCodexLoginDir(id);
|
|
126
|
+
return fs.existsSync(dir) ? path.join(dir, 'profile.json') : getCodexProfileStatePath(id);
|
|
127
|
+
}
|
|
128
|
+
function dedupePaths(paths) {
|
|
129
|
+
const seen = new Set();
|
|
130
|
+
const unique = [];
|
|
131
|
+
for (const candidate of paths) {
|
|
132
|
+
const normalized = path.resolve(candidate);
|
|
133
|
+
if (seen.has(normalized))
|
|
134
|
+
continue;
|
|
135
|
+
seen.add(normalized);
|
|
136
|
+
unique.push(candidate);
|
|
137
|
+
}
|
|
138
|
+
return unique;
|
|
139
|
+
}
|
|
140
|
+
export function getCodexMonitoringHomes() {
|
|
141
|
+
const explicitHome = getExplicitCodexHome();
|
|
142
|
+
if (explicitHome)
|
|
143
|
+
return [explicitHome];
|
|
144
|
+
// The system home is the single live home; profile homes only matter for
|
|
145
|
+
// sessions recorded back when they doubled as live CODEX_HOMEs.
|
|
146
|
+
const homes = [getDefaultSystemCodexHome()];
|
|
147
|
+
for (const profile of listSavedAccountProfiles('codex')) {
|
|
148
|
+
const profileHome = getCodexProfileHome(profile.id);
|
|
149
|
+
if (fs.existsSync(path.join(profileHome, 'sessions'))) {
|
|
150
|
+
homes.push(profileHome);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return dedupePaths(homes);
|
|
154
|
+
}
|
|
155
|
+
/** Where Codex writes live rollouts, below each home. */
|
|
156
|
+
export const CODEX_SESSIONS_SUBDIR = 'sessions';
|
|
157
|
+
/** Where Codex moves a rollout when its thread is archived, below each home. */
|
|
158
|
+
export const CODEX_ARCHIVED_SESSIONS_SUBDIR = 'archived_sessions';
|
|
159
|
+
/**
|
|
160
|
+
* Every directory that may hold Codex rollouts: each home's `sessions`, then
|
|
161
|
+
* each home's `archived_sessions` that exists. Live directories come first so
|
|
162
|
+
* callers that pick one directory pick a live one.
|
|
163
|
+
*/
|
|
164
|
+
export function getCodexSessionsDirs(homes = getCodexMonitoringHomes(), options = {}) {
|
|
165
|
+
const live = homes.map((home) => path.join(home, CODEX_SESSIONS_SUBDIR));
|
|
166
|
+
if (options.includeArchived === false)
|
|
167
|
+
return live;
|
|
168
|
+
const archived = homes
|
|
169
|
+
.map((home) => path.join(home, CODEX_ARCHIVED_SESSIONS_SUBDIR))
|
|
170
|
+
.filter((dir) => fs.existsSync(dir));
|
|
171
|
+
return [...live, ...archived];
|
|
172
|
+
}
|