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
@@ -41,6 +41,9 @@ function projectSessionTranscript(events, options = {}) {
41
41
  entrypoint: event.entrypoint,
42
42
  isMeta: event.isMeta,
43
43
  isSidechain: event.isSidechain,
44
+ ...(event.isCompactSummary !== undefined ? { isCompactSummary: event.isCompactSummary } : {}),
45
+ ...(event.origin?.kind !== undefined ? { originKind: event.origin.kind } : {}),
46
+ ...(event.promptSource !== undefined ? { promptSource: event.promptSource } : {}),
44
47
  originalRole: message?.role,
45
48
  eventIndex,
46
49
  eventType: event.type,
@@ -65,6 +65,14 @@ export interface SessionEventBase {
65
65
  isMeta?: boolean;
66
66
  /** Whether this is a subagent/sidechain event */
67
67
  isSidechain?: boolean;
68
+ /** Whether the provider marks this event as a compaction/continuation summary. */
69
+ isCompactSummary?: boolean;
70
+ /** Provider-reported prompt origin (Claude Code `origin.kind`, e.g. `human`, `task-notification`). */
71
+ origin?: {
72
+ kind?: string;
73
+ };
74
+ /** Provider-reported prompt source (Claude Code `promptSource`, e.g. `typed`, `system`). */
75
+ promptSource?: string;
68
76
  /** Provider-reported working directory for this event/session. */
69
77
  cwd?: string;
70
78
  /** Provider-reported git branch for this event/session. */
@@ -1,3 +1,5 @@
1
+ export declare function renameSyncWithRetry(from: string, to: string): void;
2
+ export declare function renameWithRetry(from: string, to: string): Promise<void>;
1
3
  export declare function atomicWriteJson(filePath: string, value: unknown): Promise<void>;
2
4
  export declare function atomicWriteJsonSync(filePath: string, value: unknown): void;
3
5
  /** Raw-string sibling of {@link atomicWriteJsonSync} for non-JSON payloads. */
@@ -33,6 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.renameSyncWithRetry = renameSyncWithRetry;
37
+ exports.renameWithRetry = renameWithRetry;
36
38
  exports.atomicWriteJson = atomicWriteJson;
37
39
  exports.atomicWriteJsonSync = atomicWriteJsonSync;
38
40
  exports.atomicWriteFileSync = atomicWriteFileSync;
@@ -71,6 +73,51 @@ const LOCK_ABANDONED_MS = 120_000;
71
73
  const SYNC_LOCK_MAX_WAIT_MS = 15_000;
72
74
  const LOCK_WAIT_INTERVAL_MS = 15;
73
75
  const lockSleepView = new Int32Array(new SharedArrayBuffer(4));
76
+ /**
77
+ * Windows refuses to replace a file another process holds open (antivirus
78
+ * scanners, an editor extension re-reading `auth.json`) with EPERM/EBUSY/EACCES
79
+ * even though the rename would succeed a few milliseconds later. Retry with a
80
+ * short back-off on that platform only; other platforms surface the error.
81
+ */
82
+ const WIN32_RENAME_RETRY_CODES = new Set(['EPERM', 'EBUSY', 'EACCES']);
83
+ const WIN32_RENAME_MAX_ATTEMPTS = 10;
84
+ function renameRetryDelayMs(attempt) {
85
+ return Math.min(320, 20 * 2 ** attempt);
86
+ }
87
+ function shouldRetryRename(error, attempt) {
88
+ if (process.platform !== 'win32')
89
+ return false;
90
+ if (attempt >= WIN32_RENAME_MAX_ATTEMPTS - 1)
91
+ return false;
92
+ const code = error.code ?? '';
93
+ return WIN32_RENAME_RETRY_CODES.has(code);
94
+ }
95
+ function renameSyncWithRetry(from, to) {
96
+ for (let attempt = 0;; attempt++) {
97
+ try {
98
+ fs.renameSync(from, to);
99
+ return;
100
+ }
101
+ catch (error) {
102
+ if (!shouldRetryRename(error, attempt))
103
+ throw error;
104
+ Atomics.wait(lockSleepView, 0, 0, renameRetryDelayMs(attempt));
105
+ }
106
+ }
107
+ }
108
+ async function renameWithRetry(from, to) {
109
+ for (let attempt = 0;; attempt++) {
110
+ try {
111
+ await fs.promises.rename(from, to);
112
+ return;
113
+ }
114
+ catch (error) {
115
+ if (!shouldRetryRename(error, attempt))
116
+ throw error;
117
+ await new Promise((resolve) => setTimeout(resolve, renameRetryDelayMs(attempt)));
118
+ }
119
+ }
120
+ }
74
121
  async function syncDirectory(directory) {
75
122
  let handle;
76
123
  try {
@@ -112,7 +159,7 @@ async function atomicWriteJson(filePath, value) {
112
159
  await handle.sync();
113
160
  await handle.close();
114
161
  handle = undefined;
115
- await fs.promises.rename(tempPath, filePath);
162
+ await renameWithRetry(tempPath, filePath);
116
163
  await syncDirectory(path.dirname(filePath));
117
164
  }
118
165
  catch (error) {
@@ -135,7 +182,7 @@ function atomicWriteFileSync(filePath, content, mode = 0o600) {
135
182
  fs.fsyncSync(descriptor);
136
183
  fs.closeSync(descriptor);
137
184
  descriptor = undefined;
138
- fs.renameSync(tempPath, filePath);
185
+ renameSyncWithRetry(tempPath, filePath);
139
186
  syncDirectorySync(path.dirname(filePath));
140
187
  }
141
188
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sidekick-shared",
3
- "version": "0.26.5",
3
+ "version": "0.27.0",
4
4
  "description": "Shared data access layer for Sidekick — readers, types, providers, credentials, quota",
5
5
  "keywords": [
6
6
  "claude-code",