sidekick-shared 0.13.2
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/README.md +92 -0
- package/dist/aggregation/EventAggregator.d.ts +172 -0
- package/dist/aggregation/EventAggregator.js +1443 -0
- package/dist/aggregation/FrequencyTracker.d.ts +42 -0
- package/dist/aggregation/FrequencyTracker.js +73 -0
- package/dist/aggregation/HeatmapTracker.d.ts +40 -0
- package/dist/aggregation/HeatmapTracker.js +93 -0
- package/dist/aggregation/PatternExtractor.d.ts +51 -0
- package/dist/aggregation/PatternExtractor.js +171 -0
- package/dist/aggregation/snapshot.d.ts +64 -0
- package/dist/aggregation/snapshot.js +151 -0
- package/dist/aggregation/types.d.ts +121 -0
- package/dist/aggregation/types.js +6 -0
- package/dist/context/composer.d.ts +31 -0
- package/dist/context/composer.js +72 -0
- package/dist/credentials.d.ts +23 -0
- package/dist/credentials.js +96 -0
- package/dist/formatters/eventHighlighter.d.ts +30 -0
- package/dist/formatters/eventHighlighter.js +217 -0
- package/dist/formatters/noiseClassifier.d.ts +73 -0
- package/dist/formatters/noiseClassifier.js +226 -0
- package/dist/formatters/sessionDump.d.ts +38 -0
- package/dist/formatters/sessionDump.js +313 -0
- package/dist/formatters/toolSummary.d.ts +23 -0
- package/dist/formatters/toolSummary.js +230 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +182 -0
- package/dist/parsers/changelogParser.d.ts +25 -0
- package/dist/parsers/changelogParser.js +74 -0
- package/dist/parsers/codexParser.d.ts +76 -0
- package/dist/parsers/codexParser.js +653 -0
- package/dist/parsers/debugLogParser.d.ts +63 -0
- package/dist/parsers/debugLogParser.js +164 -0
- package/dist/parsers/jsonl.d.ts +45 -0
- package/dist/parsers/jsonl.js +57 -0
- package/dist/parsers/openCodeParser.d.ts +64 -0
- package/dist/parsers/openCodeParser.js +581 -0
- package/dist/parsers/planExtractor.d.ts +63 -0
- package/dist/parsers/planExtractor.js +330 -0
- package/dist/parsers/sessionActivityDetector.d.ts +31 -0
- package/dist/parsers/sessionActivityDetector.js +184 -0
- package/dist/parsers/sessionPathResolver.d.ts +230 -0
- package/dist/parsers/sessionPathResolver.js +753 -0
- package/dist/parsers/subagentScanner.d.ts +43 -0
- package/dist/parsers/subagentScanner.js +366 -0
- package/dist/parsers/subagentTraceParser.d.ts +58 -0
- package/dist/parsers/subagentTraceParser.js +346 -0
- package/dist/paths.d.ts +38 -0
- package/dist/paths.js +107 -0
- package/dist/phrases.d.ts +52 -0
- package/dist/phrases.js +1333 -0
- package/dist/providers/claudeCode.d.ts +48 -0
- package/dist/providers/claudeCode.js +465 -0
- package/dist/providers/codex.d.ts +57 -0
- package/dist/providers/codex.js +944 -0
- package/dist/providers/codexDatabase.d.ts +37 -0
- package/dist/providers/codexDatabase.js +148 -0
- package/dist/providers/detect.d.ts +16 -0
- package/dist/providers/detect.js +162 -0
- package/dist/providers/openCode.d.ts +70 -0
- package/dist/providers/openCode.js +1524 -0
- package/dist/providers/openCodeDatabase.d.ts +87 -0
- package/dist/providers/openCodeDatabase.js +232 -0
- package/dist/providers/types.d.ts +154 -0
- package/dist/providers/types.js +12 -0
- package/dist/quota.d.ts +34 -0
- package/dist/quota.js +80 -0
- package/dist/readers/decisions.d.ts +10 -0
- package/dist/readers/decisions.js +27 -0
- package/dist/readers/handoff.d.ts +4 -0
- package/dist/readers/handoff.js +51 -0
- package/dist/readers/helpers.d.ts +7 -0
- package/dist/readers/helpers.js +52 -0
- package/dist/readers/history.d.ts +5 -0
- package/dist/readers/history.js +12 -0
- package/dist/readers/notes.d.ts +10 -0
- package/dist/readers/notes.js +46 -0
- package/dist/readers/plans.d.ts +35 -0
- package/dist/readers/plans.js +247 -0
- package/dist/readers/tasks.d.ts +8 -0
- package/dist/readers/tasks.js +22 -0
- package/dist/report/htmlHelpers.d.ts +18 -0
- package/dist/report/htmlHelpers.js +166 -0
- package/dist/report/htmlReportGenerator.d.ts +11 -0
- package/dist/report/htmlReportGenerator.js +650 -0
- package/dist/report/index.d.ts +8 -0
- package/dist/report/index.js +16 -0
- package/dist/report/logo.d.ts +2 -0
- package/dist/report/logo.js +5 -0
- package/dist/report/openBrowser.d.ts +5 -0
- package/dist/report/openBrowser.js +22 -0
- package/dist/report/transcriptParser.d.ts +12 -0
- package/dist/report/transcriptParser.js +177 -0
- package/dist/report/types.d.ts +43 -0
- package/dist/report/types.js +5 -0
- package/dist/search/advancedFilter.d.ts +62 -0
- package/dist/search/advancedFilter.js +201 -0
- package/dist/search/sessionSearch.d.ts +16 -0
- package/dist/search/sessionSearch.js +93 -0
- package/dist/types/codex.d.ts +276 -0
- package/dist/types/codex.js +14 -0
- package/dist/types/decisionLog.d.ts +23 -0
- package/dist/types/decisionLog.js +8 -0
- package/dist/types/historicalData.d.ts +74 -0
- package/dist/types/historicalData.js +17 -0
- package/dist/types/knowledgeNote.d.ts +40 -0
- package/dist/types/knowledgeNote.js +18 -0
- package/dist/types/opencode.d.ts +268 -0
- package/dist/types/opencode.js +13 -0
- package/dist/types/plan.d.ts +49 -0
- package/dist/types/plan.js +10 -0
- package/dist/types/sessionEvent.d.ts +562 -0
- package/dist/types/sessionEvent.js +11 -0
- package/dist/types/taskPersistence.d.ts +33 -0
- package/dist/types/taskPersistence.js +16 -0
- package/dist/watchers/eventBridge.d.ts +19 -0
- package/dist/watchers/eventBridge.js +162 -0
- package/dist/watchers/factory.d.ts +15 -0
- package/dist/watchers/factory.js +85 -0
- package/dist/watchers/jsonlWatcher.d.ts +30 -0
- package/dist/watchers/jsonlWatcher.js +444 -0
- package/dist/watchers/sqliteWatcher.d.ts +30 -0
- package/dist/watchers/sqliteWatcher.js +278 -0
- package/dist/watchers/types.d.ts +60 -0
- package/dist/watchers/types.js +5 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# sidekick-shared
|
|
2
|
+
|
|
3
|
+
Shared data access library for [Sidekick Agent Hub](https://github.com/cesarandreslopez/sidekick-agent-hub).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/sidekick-shared)
|
|
6
|
+
[](https://github.com/cesarandreslopez/sidekick-agent-hub/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Types, parsers, providers, readers, formatters, aggregation, search, reporting, credentials, and quota for AI agent session monitoring. Used by both the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=CesarAndresLopez.sidekick-for-max) and the [CLI dashboard](https://www.npmjs.com/package/sidekick-agent-hub).
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install sidekick-shared
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## API Overview
|
|
17
|
+
|
|
18
|
+
| Module | Description |
|
|
19
|
+
|--------|-------------|
|
|
20
|
+
| **Types** | Session events, OpenCode/Codex format types, persistence schemas (tasks, decisions, notes, plans, historical data) |
|
|
21
|
+
| **Paths** | Config directory resolution, project data paths, workspace encoding |
|
|
22
|
+
| **Readers** | Read tasks, decisions, notes, history, handoff, and plans from `~/.config/sidekick/` |
|
|
23
|
+
| **Providers** | Session provider abstraction with Claude Code, OpenCode, and Codex implementations; auto-detection via filesystem |
|
|
24
|
+
| **Parsers** | JSONL event parsing, OpenCode/Codex format normalization, subagent scanning, session path resolution, debug log parsing |
|
|
25
|
+
| **Watchers** | Live session file watching with event bridging |
|
|
26
|
+
| **Formatters** | Tool summary, noise classification, session dump (text/markdown/JSON), event highlighting |
|
|
27
|
+
| **Search** | Cross-session full-text search, advanced filtering (substring, fuzzy, regex, date) |
|
|
28
|
+
| **Aggregation** | Event aggregation, frequency tracking, activity heatmaps, pattern extraction |
|
|
29
|
+
| **Report** | Self-contained HTML session report generation |
|
|
30
|
+
| **Credentials** | Claude Max OAuth credential reading from `~/.claude/.credentials.json` |
|
|
31
|
+
| **Quota** | Claude Max subscription quota fetching (5-hour and 7-day windows) |
|
|
32
|
+
|
|
33
|
+
## Usage Examples
|
|
34
|
+
|
|
35
|
+
### Detect the active session provider
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { detectProvider } from 'sidekick-shared';
|
|
39
|
+
|
|
40
|
+
const provider = await detectProvider('/path/to/project');
|
|
41
|
+
if (provider) {
|
|
42
|
+
console.log(`Active provider: ${provider.id}`);
|
|
43
|
+
const sessions = await provider.listSessions();
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Read persisted tasks
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { readTasks, getProjectSlug } from 'sidekick-shared';
|
|
51
|
+
|
|
52
|
+
const slug = getProjectSlug('/path/to/project');
|
|
53
|
+
const tasks = readTasks({ projectSlug: slug });
|
|
54
|
+
console.log(`Found ${tasks.length} tasks`);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Fetch subscription quota
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { fetchQuota, readClaudeMaxCredentials } from 'sidekick-shared';
|
|
61
|
+
|
|
62
|
+
const creds = readClaudeMaxCredentials();
|
|
63
|
+
if (creds) {
|
|
64
|
+
const quota = await fetchQuota(creds.accessToken);
|
|
65
|
+
console.log(`5-hour utilization: ${quota.fiveHour.percentUsed}%`);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Building
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm run build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Compiles TypeScript to `dist/` via `tsc`.
|
|
76
|
+
|
|
77
|
+
## Testing
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm test
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Uses Vitest. Run `npm run test:watch` for watch mode.
|
|
84
|
+
|
|
85
|
+
## See Also
|
|
86
|
+
|
|
87
|
+
- [Sidekick for Max](https://marketplace.visualstudio.com/items?itemName=CesarAndresLopez.sidekick-for-max) — VS Code extension
|
|
88
|
+
- [Sidekick CLI](https://www.npmjs.com/package/sidekick-agent-hub) — Terminal dashboard (`npm install -g sidekick-agent-hub`)
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared event aggregation engine.
|
|
3
|
+
*
|
|
4
|
+
* Pure computation class (no I/O, no framework dependencies) that processes
|
|
5
|
+
* SessionEvent and FollowEvent objects to accumulate session metrics.
|
|
6
|
+
* Both the VS Code SessionMonitor and CLI DashboardState delegate to this.
|
|
7
|
+
*
|
|
8
|
+
* @module aggregation/EventAggregator
|
|
9
|
+
*/
|
|
10
|
+
import type { SessionEvent, ToolAnalytics, TimelineEvent, TrackedTask, TaskState, PlanState, CompactionEvent, TruncationEvent, ContextAttribution, ContextSizePoint, ResponseLatency, LatencyStats, PermissionMode, PermissionModeChange } from '../types/sessionEvent';
|
|
11
|
+
import type { FollowEvent } from '../watchers/types';
|
|
12
|
+
import type { EventAggregatorOptions, AggregatedTokens, ModelUsageStats, BurnRateInfo, SubagentLifecycle, AggregatedMetrics } from './types';
|
|
13
|
+
import type { SerializedFrequencyState } from './FrequencyTracker';
|
|
14
|
+
import type { SerializedHeatmapState } from './HeatmapTracker';
|
|
15
|
+
import type { SerializedPatternState } from './PatternExtractor';
|
|
16
|
+
/**
|
|
17
|
+
* JSON-serializable snapshot of EventAggregator state.
|
|
18
|
+
* Used by session snapshot sidecar files for fast resume.
|
|
19
|
+
*/
|
|
20
|
+
export interface SerializedAggregatorState {
|
|
21
|
+
version: number;
|
|
22
|
+
tokens: {
|
|
23
|
+
input: number;
|
|
24
|
+
output: number;
|
|
25
|
+
cacheWrite: number;
|
|
26
|
+
cacheRead: number;
|
|
27
|
+
reportedCost: number;
|
|
28
|
+
};
|
|
29
|
+
modelUsage: Array<[string, {
|
|
30
|
+
calls: number;
|
|
31
|
+
tokens: number;
|
|
32
|
+
inputTokens: number;
|
|
33
|
+
outputTokens: number;
|
|
34
|
+
cacheWriteTokens: number;
|
|
35
|
+
cacheReadTokens: number;
|
|
36
|
+
cost: number;
|
|
37
|
+
}]>;
|
|
38
|
+
contextSize: number;
|
|
39
|
+
previousContextSize: number;
|
|
40
|
+
compactionEvents: CompactionEvent[];
|
|
41
|
+
truncationEvents: TruncationEvent[];
|
|
42
|
+
toolAnalytics: Array<[string, ToolAnalytics]>;
|
|
43
|
+
contextAttribution: ContextAttribution;
|
|
44
|
+
burnSamples: BurnSample[];
|
|
45
|
+
lastBurnSampleTime: number;
|
|
46
|
+
tokensSinceLastSample: number;
|
|
47
|
+
latencyRecords: ResponseLatency[];
|
|
48
|
+
tasks: Array<[string, TrackedTask]>;
|
|
49
|
+
activeTaskId: string | null;
|
|
50
|
+
subagents: SubagentLifecycle[];
|
|
51
|
+
permissionMode?: PermissionMode | null;
|
|
52
|
+
permissionModeHistory?: PermissionModeChange[];
|
|
53
|
+
contextTimeline?: ContextSizePoint[];
|
|
54
|
+
contextTurnIndex?: number;
|
|
55
|
+
timeline: TimelineEvent[];
|
|
56
|
+
messageCount: number;
|
|
57
|
+
eventCount: number;
|
|
58
|
+
sessionStartTime: string | null;
|
|
59
|
+
lastEventTime: string | null;
|
|
60
|
+
currentModel: string | null;
|
|
61
|
+
toolFrequency?: SerializedFrequencyState;
|
|
62
|
+
wordFrequency?: SerializedFrequencyState;
|
|
63
|
+
patternState?: SerializedPatternState;
|
|
64
|
+
heatmapState?: SerializedHeatmapState;
|
|
65
|
+
}
|
|
66
|
+
interface BurnSample {
|
|
67
|
+
time: number;
|
|
68
|
+
tokens: number;
|
|
69
|
+
}
|
|
70
|
+
export declare class EventAggregator {
|
|
71
|
+
private readonly timelineCap;
|
|
72
|
+
private readonly latencyCap;
|
|
73
|
+
private readonly burnWindowMs;
|
|
74
|
+
private readonly burnSampleMs;
|
|
75
|
+
private readonly computeContextSize;
|
|
76
|
+
private readonly providerId;
|
|
77
|
+
private inputTokens;
|
|
78
|
+
private outputTokens;
|
|
79
|
+
private cacheWriteTokens;
|
|
80
|
+
private cacheReadTokens;
|
|
81
|
+
private reportedCost;
|
|
82
|
+
private modelUsage;
|
|
83
|
+
private currentContextSize;
|
|
84
|
+
private previousContextSize;
|
|
85
|
+
private compactionEvents;
|
|
86
|
+
private truncationEvents;
|
|
87
|
+
private toolAnalytics;
|
|
88
|
+
private pendingToolCalls;
|
|
89
|
+
private burnSamples;
|
|
90
|
+
private lastBurnSampleTime;
|
|
91
|
+
private tokensSinceLastSample;
|
|
92
|
+
private tasks;
|
|
93
|
+
private pendingTaskCreates;
|
|
94
|
+
private activeTaskId;
|
|
95
|
+
private subagents;
|
|
96
|
+
private pendingSubagents;
|
|
97
|
+
private planExtractor;
|
|
98
|
+
private contextAttribution;
|
|
99
|
+
private currentPermissionMode;
|
|
100
|
+
private permissionModeHistory;
|
|
101
|
+
private contextTimeline;
|
|
102
|
+
private contextTurnIndex;
|
|
103
|
+
private timeline;
|
|
104
|
+
private pendingUserRequest;
|
|
105
|
+
private latencyRecords;
|
|
106
|
+
private messageCount;
|
|
107
|
+
private eventCount;
|
|
108
|
+
private sessionStartTime;
|
|
109
|
+
private lastEventTime;
|
|
110
|
+
private currentModel;
|
|
111
|
+
private _providerId;
|
|
112
|
+
private toolFrequency;
|
|
113
|
+
private wordFrequency;
|
|
114
|
+
private patternExtractor;
|
|
115
|
+
private heatmapTracker;
|
|
116
|
+
constructor(options?: EventAggregatorOptions);
|
|
117
|
+
processEvent(event: SessionEvent): void;
|
|
118
|
+
processFollowEvent(event: FollowEvent): void;
|
|
119
|
+
getAggregatedTokens(): AggregatedTokens;
|
|
120
|
+
getModelStats(): ModelUsageStats[];
|
|
121
|
+
getToolStats(): ToolAnalytics[];
|
|
122
|
+
getCompactionEvents(): CompactionEvent[];
|
|
123
|
+
getTruncationEvents(): TruncationEvent[];
|
|
124
|
+
getBurnRate(): BurnRateInfo;
|
|
125
|
+
getTaskState(): TaskState;
|
|
126
|
+
getSubagents(): SubagentLifecycle[];
|
|
127
|
+
getPlan(): PlanState | null;
|
|
128
|
+
getContextAttribution(): ContextAttribution;
|
|
129
|
+
getTimeline(): TimelineEvent[];
|
|
130
|
+
getLatencyStats(): LatencyStats | null;
|
|
131
|
+
getMetrics(): AggregatedMetrics;
|
|
132
|
+
reset(): void;
|
|
133
|
+
/** Seeds the current context size (e.g., from a provider usage snapshot on attach). */
|
|
134
|
+
seedContextSize(size: number): void;
|
|
135
|
+
/** Seeds context attribution (e.g., from a provider's DB-backed attribution). */
|
|
136
|
+
seedContextAttribution(attribution: ContextAttribution): void;
|
|
137
|
+
/** Serializes all mutable state to a JSON-safe object for snapshot persistence. */
|
|
138
|
+
serialize(): SerializedAggregatorState;
|
|
139
|
+
/** Restores mutable state from a serialized snapshot. Clears transient state (pending calls). */
|
|
140
|
+
restore(state: SerializedAggregatorState): void;
|
|
141
|
+
private accumulateUsage;
|
|
142
|
+
private updateBurnRate;
|
|
143
|
+
private processLatency;
|
|
144
|
+
private extractToolsFromContent;
|
|
145
|
+
private detectTruncationInContent;
|
|
146
|
+
private recordFollowToolUse;
|
|
147
|
+
private recordFollowToolResult;
|
|
148
|
+
private detectTruncationFromFollowEvent;
|
|
149
|
+
private extractTaskStateFromEvent;
|
|
150
|
+
private extractTaskStateFromFollowEvent;
|
|
151
|
+
private applyTaskUpdate;
|
|
152
|
+
private resolveTaskCreate;
|
|
153
|
+
private extractSubagentFromEvent;
|
|
154
|
+
private extractSubagentFromFollowEvent;
|
|
155
|
+
private completeSubagent;
|
|
156
|
+
private extractPlanFromSessionEvent;
|
|
157
|
+
private convertExtractedPlanToPlanState;
|
|
158
|
+
private attributeContextFromEvent;
|
|
159
|
+
private attributeContextFromFollowEvent;
|
|
160
|
+
private trackPermissionMode;
|
|
161
|
+
private addTimelineFromSessionEvent;
|
|
162
|
+
private addTimelineFromFollowEvent;
|
|
163
|
+
private estimateTokens;
|
|
164
|
+
private hasTextContent;
|
|
165
|
+
private extractTextContent;
|
|
166
|
+
private extractTaskIdFromResult;
|
|
167
|
+
private isSystemPromptContent;
|
|
168
|
+
private extractToolNameFromEvent;
|
|
169
|
+
/** Feed event data into frequency trackers, pattern extractor, and heatmap. */
|
|
170
|
+
private feedAnalytics;
|
|
171
|
+
}
|
|
172
|
+
export {};
|