sidekick-shared 0.24.5 → 0.25.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 +35 -0
- package/README.md +159 -52
- package/dist/accountChangeSignal.d.ts +3 -0
- package/dist/accountChangeSignal.js +19 -0
- package/dist/accountChanges.d.ts +21 -0
- package/dist/accountChanges.js +151 -0
- package/dist/accountRegistry.d.ts +3 -1
- package/dist/accountRegistry.js +5 -0
- package/dist/browser.d.ts +8 -3
- package/dist/browser.js +15 -1
- package/dist/codexQuotaWatcher.d.ts +6 -0
- package/dist/codexQuotaWatcher.js +101 -47
- package/dist/index.d.ts +23 -13
- package/dist/index.js +34 -10
- package/dist/modelAliases.d.ts +13 -0
- package/dist/modelAliases.js +58 -0
- package/dist/modelCatalog.d.ts +32 -0
- package/dist/modelCatalog.js +145 -0
- package/dist/modelContext.d.ts +36 -3
- package/dist/modelContext.js +109 -34
- package/dist/modelInfo.d.ts +30 -1
- package/dist/modelInfo.js +116 -26
- package/dist/multiProviderQuotaService.d.ts +8 -0
- package/dist/multiProviderQuotaService.js +64 -3
- package/dist/node.d.ts +4 -4
- package/dist/node.js +4 -1
- package/dist/observedSessionCollector.d.ts +75 -4
- package/dist/observedSessionCollector.js +452 -42
- package/dist/parsers/codexHistory.d.ts +4 -2
- package/dist/parsers/codexHistory.js +9 -2
- package/dist/parsers/sessionActivityDetector.d.ts +6 -0
- package/dist/parsers/sessionActivityDetector.js +17 -0
- package/dist/providerIds.d.ts +11 -0
- package/dist/providerIds.js +9 -0
- package/dist/providerQuota.d.ts +3 -1
- package/dist/providerQuota.js +3 -0
- package/dist/providers/claudeCode.d.ts +10 -1
- package/dist/providers/claudeCode.js +204 -39
- package/dist/providers/codex.d.ts +18 -1
- package/dist/providers/codex.js +269 -40
- package/dist/providers/codexDatabase.d.ts +9 -0
- package/dist/providers/codexDatabase.js +107 -2
- package/dist/providers/diagnostics.d.ts +13 -0
- package/dist/providers/diagnostics.js +88 -0
- package/dist/providers/factory.d.ts +14 -0
- package/dist/providers/factory.js +57 -0
- package/dist/providers/openCode.d.ts +20 -1
- package/dist/providers/openCode.js +361 -11
- package/dist/providers/openCodeDatabase.d.ts +10 -0
- package/dist/providers/openCodeDatabase.js +69 -0
- package/dist/providers/types.d.ts +52 -2
- package/dist/providers/types.js +4 -0
- package/dist/quota.d.ts +4 -1
- package/dist/quota.js +3 -7
- package/dist/quotaHistory.d.ts +2 -1
- package/dist/quotaPoller.d.ts +13 -1
- package/dist/quotaPoller.js +65 -3
- package/dist/schemas/accountManager.d.ts +2 -2
- package/dist/schemas/accountManager.js +2 -4
- package/dist/schemas/accountStatus.d.ts +3 -0
- package/dist/schemas/accountStatus.js +1 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.js +7 -2
- package/dist/schemas/observedSessionV1.d.ts +27 -26
- package/dist/schemas/observedSessionV1.js +6 -4
- package/dist/schemas/quota.d.ts +2 -2
- package/dist/schemas/quota.js +3 -6
- package/dist/schemas/quotaHistory.d.ts +2 -2
- package/dist/schemas/tokenEstimation.d.ts +1 -1
- package/dist/sessionMonitor.d.ts +15 -0
- package/dist/sessionMonitor.js +142 -0
- package/dist/sessionPreviews.d.ts +26 -1
- package/dist/sessionPreviews.js +319 -4
- package/dist/types/observedSessionV1.d.ts +6 -2
- package/dist/types/observedSessionV1.js +14 -8
- package/package.json +22 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderDiagnosticTracker = void 0;
|
|
4
|
+
exports.diagnosticFromRuntimeStatus = diagnosticFromRuntimeStatus;
|
|
5
|
+
const AVAILABLE_STATUS = { available: true, kind: 'available' };
|
|
6
|
+
/** Small per-provider diagnostic state; it never stores transcript or environment contents. */
|
|
7
|
+
class ProviderDiagnosticTracker {
|
|
8
|
+
providerId;
|
|
9
|
+
options;
|
|
10
|
+
lastEmittedSignature = null;
|
|
11
|
+
lastStatus = {
|
|
12
|
+
operation: 'construct',
|
|
13
|
+
usable: true,
|
|
14
|
+
degraded: false,
|
|
15
|
+
runtimeStatus: AVAILABLE_STATUS,
|
|
16
|
+
diagnostics: [],
|
|
17
|
+
};
|
|
18
|
+
constructor(providerId, options = {}) {
|
|
19
|
+
this.providerId = providerId;
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
available(operation) {
|
|
23
|
+
this.lastEmittedSignature = null;
|
|
24
|
+
this.lastStatus = {
|
|
25
|
+
operation,
|
|
26
|
+
usable: true,
|
|
27
|
+
degraded: false,
|
|
28
|
+
runtimeStatus: AVAILABLE_STATUS,
|
|
29
|
+
diagnostics: [],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
degraded(operation, runtimeStatus, diagnostic, usable = true) {
|
|
33
|
+
const value = { providerId: this.providerId, ...diagnostic };
|
|
34
|
+
this.lastStatus = {
|
|
35
|
+
operation,
|
|
36
|
+
usable,
|
|
37
|
+
degraded: true,
|
|
38
|
+
runtimeStatus,
|
|
39
|
+
diagnostics: [value],
|
|
40
|
+
};
|
|
41
|
+
const signature = `${value.kind}\0${value.severity}\0${value.phase}\0${value.message}`;
|
|
42
|
+
if (signature === this.lastEmittedSignature)
|
|
43
|
+
return;
|
|
44
|
+
this.lastEmittedSignature = signature;
|
|
45
|
+
try {
|
|
46
|
+
this.options.onDiagnostic?.(value);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Diagnostics are observational and cannot break provider operations.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getLastOperationStatus() {
|
|
53
|
+
return {
|
|
54
|
+
...this.lastStatus,
|
|
55
|
+
runtimeStatus: { ...this.lastStatus.runtimeStatus },
|
|
56
|
+
diagnostics: [...this.lastStatus.diagnostics],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ProviderDiagnosticTracker = ProviderDiagnosticTracker;
|
|
61
|
+
function diagnosticFromRuntimeStatus(providerId, phase, status) {
|
|
62
|
+
if (status.kind === 'available')
|
|
63
|
+
return null;
|
|
64
|
+
const kind = status.kind;
|
|
65
|
+
return {
|
|
66
|
+
providerId,
|
|
67
|
+
kind,
|
|
68
|
+
severity: status.kind === 'query_failed' ? 'error' : 'warning',
|
|
69
|
+
phase,
|
|
70
|
+
message: status.message ?? defaultRuntimeMessage(providerId, status.kind),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function defaultRuntimeMessage(providerId, kind) {
|
|
74
|
+
switch (kind) {
|
|
75
|
+
case 'home_unavailable':
|
|
76
|
+
return `${providerId} data home is unavailable.`;
|
|
77
|
+
case 'config_unreadable':
|
|
78
|
+
return `${providerId} configuration is unreadable.`;
|
|
79
|
+
case 'db_missing':
|
|
80
|
+
return `${providerId} database is unavailable; file fallback is active.`;
|
|
81
|
+
case 'sqlite_missing':
|
|
82
|
+
return 'The sqlite3 executable is unavailable; file fallback is active.';
|
|
83
|
+
case 'sqlite_blocked':
|
|
84
|
+
return 'The sqlite3 executable could not be started; file fallback is active.';
|
|
85
|
+
case 'query_failed':
|
|
86
|
+
return `${providerId} database query failed; fallback data may be incomplete.`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProviderId, SessionProviderBase, SessionProviderDiagnostic } from './types';
|
|
2
|
+
export interface CreateSessionProvidersOptions {
|
|
3
|
+
providerIds?: readonly ProviderId[];
|
|
4
|
+
onDiagnostic?: (diagnostic: SessionProviderDiagnostic) => void;
|
|
5
|
+
}
|
|
6
|
+
export interface CreateSessionProvidersResult {
|
|
7
|
+
providers: SessionProviderBase[];
|
|
8
|
+
diagnostics: SessionProviderDiagnostic[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Constructs built-in providers without probing the filesystem or binaries.
|
|
12
|
+
* A broken provider is isolated and reported instead of aborting host startup.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createSessionProviders(options?: CreateSessionProvidersOptions): CreateSessionProvidersResult;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSessionProviders = createSessionProviders;
|
|
4
|
+
const claudeCode_1 = require("./claudeCode");
|
|
5
|
+
const codex_1 = require("./codex");
|
|
6
|
+
const openCode_1 = require("./openCode");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
/**
|
|
9
|
+
* Constructs built-in providers without probing the filesystem or binaries.
|
|
10
|
+
* A broken provider is isolated and reported instead of aborting host startup.
|
|
11
|
+
*/
|
|
12
|
+
function createSessionProviders(options = {}) {
|
|
13
|
+
const diagnostics = [];
|
|
14
|
+
const diagnosticIndexes = new Map();
|
|
15
|
+
const providers = [];
|
|
16
|
+
const selected = new Set(options.providerIds ?? types_1.SESSION_PROVIDER_IDS);
|
|
17
|
+
const emit = (diagnostic) => {
|
|
18
|
+
const key = `${diagnostic.providerId}\0${diagnostic.kind}\0${diagnostic.phase}`;
|
|
19
|
+
const existingIndex = diagnosticIndexes.get(key);
|
|
20
|
+
if (existingIndex === undefined) {
|
|
21
|
+
diagnosticIndexes.set(key, diagnostics.length);
|
|
22
|
+
diagnostics.push(diagnostic);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
diagnostics[existingIndex] = diagnostic;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
options.onDiagnostic?.(diagnostic);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// A host diagnostic callback cannot break provider setup.
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
for (const providerId of types_1.SESSION_PROVIDER_IDS) {
|
|
35
|
+
if (!selected.has(providerId))
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
const providerOptions = { onDiagnostic: emit };
|
|
39
|
+
providers.push(providerId === 'claude-code'
|
|
40
|
+
? new claudeCode_1.ClaudeCodeProvider(providerOptions)
|
|
41
|
+
: providerId === 'opencode'
|
|
42
|
+
? new openCode_1.OpenCodeProvider(providerOptions)
|
|
43
|
+
: new codex_1.CodexProvider(providerOptions));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
const diagnostic = {
|
|
47
|
+
providerId,
|
|
48
|
+
kind: 'construction_failed',
|
|
49
|
+
severity: 'error',
|
|
50
|
+
phase: 'construct',
|
|
51
|
+
message: `${providerId} could not be constructed and was omitted.`,
|
|
52
|
+
};
|
|
53
|
+
emit(diagnostic);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { providers, diagnostics };
|
|
57
|
+
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import type { ReadSessionContextSnapshotOptions, SessionContextSnapshot } from '../context/sessionContext';
|
|
19
19
|
import type { ZaiTier } from '../zaiQuota';
|
|
20
20
|
import type { QuotaState } from '../quota';
|
|
21
|
-
import type { SessionProviderBase, SessionReader, ProjectFolderInfo, SearchHit, SessionFileStats, ProviderId, ProviderRuntimeStatus } from './types';
|
|
21
|
+
import type { SessionProviderBase, SessionReader, ProjectFolderInfo, SearchHit, SessionFileStats, ProviderId, ProviderRuntimeStatus, ProviderOperationStatus, SessionFileInfo, SessionProviderOptions } from './types';
|
|
22
22
|
import type { TokenUsage, SubagentStats, ContextAttribution } from '../types/sessionEvent';
|
|
23
23
|
/**
|
|
24
24
|
* Gets the OpenCode data directory.
|
|
@@ -42,13 +42,23 @@ export declare class OpenCodeProvider implements SessionProviderBase {
|
|
|
42
42
|
private db;
|
|
43
43
|
private dbInitialized;
|
|
44
44
|
private dbStatus;
|
|
45
|
+
private readonly diagnostics;
|
|
45
46
|
/** Cache of session metadata populated during listing */
|
|
46
47
|
private sessionMetaCache;
|
|
47
48
|
/** Runtime-reported context window limit (overrides static map when set). */
|
|
48
49
|
private dynamicContextWindowLimit;
|
|
50
|
+
constructor(options?: SessionProviderOptions);
|
|
49
51
|
/** Lazy-initialize the database connection. */
|
|
50
52
|
private ensureDb;
|
|
53
|
+
private ensureDbAsync;
|
|
54
|
+
/**
|
|
55
|
+
* Cache an async-created database only after an operation proved it usable.
|
|
56
|
+
* Sync paths treat a cached `db` as "open() succeeded", so adopting an
|
|
57
|
+
* unproven instance would cut them off from the file-storage fallback.
|
|
58
|
+
*/
|
|
59
|
+
private adoptDbIfAvailable;
|
|
51
60
|
getRuntimeStatus(): ProviderRuntimeStatus;
|
|
61
|
+
getLastOperationStatus(): ProviderOperationStatus;
|
|
52
62
|
canMonitorDirectory(dir: string): boolean;
|
|
53
63
|
private mapDbSessions;
|
|
54
64
|
getSessionDirectory(workspacePath: string): string;
|
|
@@ -58,14 +68,18 @@ export declare class OpenCodeProvider implements SessionProviderBase {
|
|
|
58
68
|
/** Backward-compatible alias for findAllSessions. */
|
|
59
69
|
findSessionFiles(workspacePath: string): string[];
|
|
60
70
|
findAllSessions(workspacePath: string): string[];
|
|
71
|
+
findSessionById(workspacePath: string, sessionId: string): string | null;
|
|
61
72
|
findSessionsInDirectory(dir: string): string[];
|
|
62
73
|
private findSessionsInDirectoryFromFiles;
|
|
74
|
+
listAllSessionFiles(): SessionFileInfo[];
|
|
75
|
+
listSessionFilesAsync(workspacePath?: string): Promise<SessionFileInfo[]>;
|
|
63
76
|
getAllProjectFolders(workspacePath?: string): ProjectFolderInfo[];
|
|
64
77
|
private getAllProjectFoldersFromFiles;
|
|
65
78
|
isSessionFile(filename: string): boolean;
|
|
66
79
|
getSessionId(sessionPath: string): string;
|
|
67
80
|
encodeWorkspacePath(workspacePath: string): string;
|
|
68
81
|
extractSessionLabel(sessionPath: string): string | null;
|
|
82
|
+
extractSessionLabelsAsync(sessionPaths: readonly string[]): Promise<Map<string, string | null>>;
|
|
69
83
|
private extractSessionLabelFromFiles;
|
|
70
84
|
createReader(sessionPath: string): SessionReader;
|
|
71
85
|
scanSubagents(_sessionDir: string, sessionId: string): SubagentStats[];
|
|
@@ -73,11 +87,15 @@ export declare class OpenCodeProvider implements SessionProviderBase {
|
|
|
73
87
|
private searchInSessionFromDb;
|
|
74
88
|
private searchInSessionFromFiles;
|
|
75
89
|
getProjectsBaseDir(): string;
|
|
90
|
+
getWatchRoots(): string[];
|
|
76
91
|
readSessionStats(sessionPath: string): SessionFileStats;
|
|
77
92
|
readSessionContextSnapshot(sessionPath: string, options?: ReadSessionContextSnapshotOptions): SessionContextSnapshot;
|
|
78
93
|
getSessionMetadata(sessionPath: string): {
|
|
79
94
|
mtime: Date;
|
|
80
95
|
} | null;
|
|
96
|
+
getSessionMetadataAsync(sessionPath: string): Promise<{
|
|
97
|
+
mtime: Date;
|
|
98
|
+
} | null>;
|
|
81
99
|
/**
|
|
82
100
|
* Returns the latest assistant message's token snapshot for context window sizing.
|
|
83
101
|
* Cumulative session totals are derived from readNew() events processed by SessionMonitor.
|
|
@@ -89,6 +107,7 @@ export declare class OpenCodeProvider implements SessionProviderBase {
|
|
|
89
107
|
/** Set a runtime-reported context window limit (overrides static map). */
|
|
90
108
|
setDynamicContextWindowLimit(limit: number): void;
|
|
91
109
|
dispose(): void;
|
|
110
|
+
private recordDatabaseStatus;
|
|
92
111
|
/**
|
|
93
112
|
* Derives a z.ai coding-plan `QuotaState` from OpenCode assistant turns
|
|
94
113
|
* tagged with `providerID ∈ {zai, zai-coding-plan}`.
|