sidekick-shared 0.26.5 → 0.27.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +98 -59
  3. package/dist/accountChanges.js +21 -2
  4. package/dist/accountHealth.d.ts +72 -0
  5. package/dist/accountHealth.js +286 -0
  6. package/dist/accountLaunch.d.ts +30 -0
  7. package/dist/accountLaunch.js +124 -0
  8. package/dist/accountManager.d.ts +33 -8
  9. package/dist/accountManager.js +183 -50
  10. package/dist/accountRegistry.d.ts +10 -0
  11. package/dist/accountRegistry.js +42 -22
  12. package/dist/accountSwitch.d.ts +43 -0
  13. package/dist/accountSwitch.js +115 -0
  14. package/dist/accountSync.d.ts +30 -0
  15. package/dist/accountSync.js +180 -0
  16. package/dist/accountSyncTypes.d.ts +25 -0
  17. package/dist/accountSyncTypes.js +7 -0
  18. package/dist/accounts.d.ts +58 -6
  19. package/dist/accounts.js +408 -189
  20. package/dist/claudeCredentials.d.ts +38 -0
  21. package/dist/claudeCredentials.js +74 -0
  22. package/dist/claudeProfiles.d.ts +40 -0
  23. package/dist/claudeProfiles.js +102 -10
  24. package/dist/codexAuth.d.ts +32 -0
  25. package/dist/codexAuth.js +127 -0
  26. package/dist/codexPaths.d.ts +21 -0
  27. package/dist/codexPaths.js +117 -0
  28. package/dist/codexProfiles.d.ts +58 -5
  29. package/dist/codexProfiles.js +574 -289
  30. package/dist/credentialIO.d.ts +12 -5
  31. package/dist/credentialIO.js +63 -29
  32. package/dist/credentials.d.ts +8 -0
  33. package/dist/credentials.js +28 -32
  34. package/dist/ensureDefaultAccounts.d.ts +8 -0
  35. package/dist/ensureDefaultAccounts.js +42 -82
  36. package/dist/humanPrompt.d.ts +27 -0
  37. package/dist/humanPrompt.js +93 -0
  38. package/dist/index.d.ts +31 -10
  39. package/dist/index.js +72 -13
  40. package/dist/keepAlive.d.ts +44 -0
  41. package/dist/keepAlive.js +106 -0
  42. package/dist/modelContext.js +4 -0
  43. package/dist/modelInfo.js +26 -1
  44. package/dist/node.d.ts +4 -0
  45. package/dist/node.js +9 -2
  46. package/dist/processDetection.d.ts +32 -0
  47. package/dist/processDetection.js +210 -0
  48. package/dist/promptHistory.d.ts +108 -0
  49. package/dist/promptHistory.js +616 -0
  50. package/dist/schemas/accountManager.d.ts +283 -1
  51. package/dist/schemas/accountManager.js +122 -1
  52. package/dist/schemas/assistantTurn.d.ts +2 -2
  53. package/dist/schemas/index.d.ts +6 -1
  54. package/dist/schemas/index.js +14 -1
  55. package/dist/schemas/observedSessionV1.d.ts +21 -21
  56. package/dist/schemas/quota.d.ts +18 -18
  57. package/dist/schemas/quotaHistory.d.ts +1 -1
  58. package/dist/schemas/sessionEvent.d.ts +25 -0
  59. package/dist/schemas/sessionEvent.js +3 -0
  60. package/dist/schemas/stateFile.d.ts +5 -5
  61. package/dist/terminalSync.d.ts +5 -5
  62. package/dist/terminalSync.js +7 -112
  63. package/dist/transcript.d.ts +6 -0
  64. package/dist/transcript.js +3 -0
  65. package/dist/types/sessionEvent.d.ts +8 -0
  66. package/dist/writers/atomic.d.ts +2 -0
  67. package/dist/writers/atomic.js +49 -2
  68. package/package.json +1 -1
@@ -1,14 +1,35 @@
1
1
  import type { AccountIdentityMetadata, ResolvedActiveAccount, SavedAccountProfile } from './accountRegistry';
2
2
  import type { AccountManagerResult } from './accounts';
3
+ import { type AccountHealthSource } from './accountHealth';
4
+ import { type SwitchAccountOptions, type SwitchAccountResult } from './accountSwitch';
5
+ import { type ProviderSyncReport } from './accountSyncTypes';
6
+ export { getCodexProfilesDir, getCodexProfileHome, getSystemCodexHome, getCodexCredentialStoreMode, } from './codexPaths';
7
+ export type { CodexCredentialStoreMode } from './codexPaths';
3
8
  export interface CodexAccountManagerResult extends AccountManagerResult {
4
9
  needsLogin?: boolean;
5
10
  profileId?: string;
6
11
  codexHome?: string;
7
12
  }
8
- export declare function getSystemCodexHome(): string;
13
+ export declare const CODEX_KEYRING_FIX_HINT = "Set `cli_auth_credentials_store = \"file\"` in ~/.codex/config.toml and run `codex login` again.";
9
14
  export declare function getCodexMonitoringHomes(): string[];
10
- export declare function getCodexProfilesDir(): string;
11
- export declare function getCodexProfileHome(profileId: string): string;
15
+ /**
16
+ * The single chokepoint for storing a Codex credential in a profile: the raw
17
+ * `auth.json` bytes (never re-serialized), the legacy `.credentials.json`
18
+ * when present, and the secret-free health sidecar.
19
+ */
20
+ export declare function storeCodexProfileAuth(profileId: string, authRaw: string | null, legacyRaw: string | null, source: AccountHealthSource): void;
21
+ interface CodexLoginStatus {
22
+ loggedIn: boolean;
23
+ authMode?: 'chatgpt' | 'api-key';
24
+ }
25
+ export declare function parseCodexLoginStatusOutput(status: number | null, stdout: string): CodexLoginStatus;
26
+ /**
27
+ * Blocks the caller's event loop for up to {@link PROBE_TIMEOUT_MS}. Async code
28
+ * paths must use {@link getCodexLoginStatusAsync} instead — external consumers
29
+ * embed this package in processes where a blocked event loop freezes all IPC.
30
+ */
31
+ export declare function getCodexLoginStatus(codexHome: string): CodexLoginStatus;
32
+ export declare function getCodexLoginStatusAsync(codexHome: string): Promise<CodexLoginStatus>;
12
33
  export declare function readCodexAccountMetadata(codexHome: string): AccountIdentityMetadata;
13
34
  /** {@link readCodexAccountMetadata} without blocking the event loop on the CLI probe. */
14
35
  export declare function readCodexAccountMetadataAsync(codexHome: string): Promise<AccountIdentityMetadata>;
@@ -45,9 +66,41 @@ export declare function finalizeCodexAccount(profileId: string, opts?: {
45
66
  export declare function finalizeCodexAccountAsync(profileId: string, opts?: {
46
67
  activate?: boolean;
47
68
  }): Promise<CodexAccountManagerResult>;
48
- export declare function switchToCodexAccount(profileId: string): CodexAccountManagerResult;
69
+ /**
70
+ * Serializes live-auth mutations across processes. Codex rotates refresh
71
+ * tokens, so two interleaved swaps stashing and restoring auth.json can
72
+ * resurrect a stale token and permanently invalidate the login. Lock ordering:
73
+ * this lock is taken first and the registry lock (inside setActiveSavedAccount
74
+ * / upsertSavedAccountProfile) inside it — never the reverse. Never spawn a
75
+ * child process while holding it.
76
+ */
77
+ export declare function withCodexAuthSwapLock<T>(operation: () => T): T;
78
+ /**
79
+ * Merge duplicate Codex profiles (same workspace, else same email). The oldest
80
+ * profile keeps its id and label, receives the freshest `auth.json` and the
81
+ * quota snapshot, and the active pointer; losers are stashed, never deleted.
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
+ */
91
+ export declare function syncCodexLiveStateUnlocked(source?: AccountHealthSource, probes?: {
92
+ systemKeyringLoggedIn?: boolean;
93
+ }): ProviderSyncReport;
94
+ /** {@link syncCodexLiveStateUnlocked} under the swap lock. */
95
+ export declare function syncCodexLiveState(source?: AccountHealthSource): ProviderSyncReport;
96
+ /**
97
+ * Remove isolated login homes that never authenticated once they are older
98
+ * than `olderThanMs`. Returns the removed profile ids.
99
+ */
100
+ export declare function cleanupAbandonedCodexLogins(olderThanMs?: number, now?: number): string[];
101
+ export declare function switchToCodexAccount(profileId: string, options?: SwitchAccountOptions): SwitchAccountResult;
49
102
  /** {@link switchToCodexAccount} without blocking the event loop on CLI probes. */
50
- export declare function switchToCodexAccountAsync(profileId: string): Promise<CodexAccountManagerResult>;
103
+ export declare function switchToCodexAccountAsync(profileId: string, options?: SwitchAccountOptions): Promise<SwitchAccountResult>;
51
104
  export declare function reconcileCodexAuthState(): void;
52
105
  /** {@link reconcileCodexAuthState} without blocking the event loop on CLI probes. */
53
106
  export declare function reconcileCodexAuthStateAsync(): Promise<void>;