sidekick-shared 0.24.0 → 0.24.1
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 +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/observedSessionCollector.d.ts +5 -2
- package/dist/observedSessionCollector.js +1 -0
- package/dist/parsers/codexParser.js +11 -8
- package/dist/schemas/index.d.ts +2 -2
- package/dist/schemas/index.js +3 -2
- package/dist/schemas/sessionEvent.d.ts +20 -0
- package/dist/schemas/sessionEvent.js +25 -2
- package/dist/schemas/transcript.d.ts +2 -1
- package/dist/schemas/transcript.js +10 -4
- package/dist/transcript.d.ts +6 -0
- package/dist/transcript.js +15 -0
- package/dist/types/sessionEvent.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -165,6 +165,18 @@ const transcript = readSessionTranscript(provider, recent.sessionPath, {
|
|
|
165
165
|
|
|
166
166
|
The same API works with `ClaudeCodeProvider` and `OpenCodeProvider`. It covers provider sessions discoverable by those readers. Remote Claude SDK-only history and Codex history entries whose rollout file has disappeared are not synthesized.
|
|
167
167
|
|
|
168
|
+
Canonical transcript messages retain provider-origin facts on `message.source`, including the original role, entrypoint, meta/sidechain flags, and source identifiers. Transcript-level `cwd` and `gitBranch` use the latest non-empty value reported by the provider. Consumers can therefore distinguish a human Claude Code CLI prompt without reparsing JSONL:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const humanCliPrompts = transcript.messages.filter(
|
|
172
|
+
(message) =>
|
|
173
|
+
message.source.originalRole === 'user' &&
|
|
174
|
+
message.source.entrypoint === 'cli' &&
|
|
175
|
+
message.source.isMeta !== true &&
|
|
176
|
+
message.source.isSidechain !== true,
|
|
177
|
+
);
|
|
178
|
+
```
|
|
179
|
+
|
|
168
180
|
For an already-open incremental Codex rollout, keep one `CodexRolloutParser` per stream and pass each parsed `SessionEvent[]` batch to `projectSessionTranscript()` (or append the events to an existing projection). This preserves parser state for paired tool calls, model context, and cumulative token deltas; consumers should not convert raw `response_item` rows themselves.
|
|
169
181
|
|
|
170
182
|
### Collect observed sessions with isolation and retry
|
|
@@ -181,6 +193,13 @@ const collector = new ObservedSessionCollector({
|
|
|
181
193
|
await collector.collect(); // scheduling remains the host's responsibility
|
|
182
194
|
```
|
|
183
195
|
|
|
196
|
+
Each provider-backed source also exposes the same adapter's `ProviderCapabilitiesV1` record used for its reads and lifecycle:
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const source = observedSessionSourceFromProvider(provider, workspacePath);
|
|
200
|
+
applyReadOnlyProjection(source.capabilities);
|
|
201
|
+
```
|
|
202
|
+
|
|
184
203
|
Discovery and reads are isolated, retries use bounded 30-second-to-5-minute exponential backoff, file changes bypass delay, duplicate identical failures are suppressed, and recovery emits a content-free diagnostic. Clock and fingerprint callbacks are injectable for deterministic hosts/tests.
|
|
185
204
|
|
|
186
205
|
## Usage Examples
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type { TranscriptFidelity, TranscriptSourceProvenance, CanonicalTranscrip
|
|
|
10
10
|
export { listRecentSessions, readSessionTranscript } from './sessionTranscripts';
|
|
11
11
|
export type { ProviderSessionIndex, ListRecentSessionsOptions } from './sessionTranscripts';
|
|
12
12
|
export { ObservedSessionCollector, observedSessionSourceFromProvider, fileFingerprint, } from './observedSessionCollector';
|
|
13
|
-
export type { ObservedSessionReference, ObservedSessionCollectionSource, ObservedSessionDiagnosticKind, ObservedSessionDiagnostic, ObservedSessionCollection, ObservedSessionCollectorOptions, } from './observedSessionCollector';
|
|
13
|
+
export type { ObservedSessionReference, ObservedSessionCollectionSource, ProviderObservedSessionCollectionSource, ObservedSessionDiagnosticKind, ObservedSessionDiagnostic, ObservedSessionCollection, ObservedSessionCollectorOptions, } from './observedSessionCollector';
|
|
14
14
|
export type { SessionEvent, ClaudeSessionEvent, MessageUsage, SessionMessage, SessionEventBase, MessageSessionEvent, UserSessionEvent, AssistantSessionEvent, SummarySessionEvent, SystemSessionEvent, ToolUseSessionEvent, ToolResultSessionEvent, TokenUsage, ToolCall, ToolAnalytics, TimelineEvent, PendingToolCall, TaskStatus as SessionTaskStatus, TrackedTask, TaskState, SubagentStats, PendingUserRequest, ResponseLatency, LatencyStats, PlanStep, PlanState, SessionStats, CompactionEvent, TruncationEvent, ContextAttribution, TurnAttribution, ContextSizePoint, PermissionMode, PermissionModeChange, } from './types/sessionEvent';
|
|
15
15
|
export type { OpenCodeSession, OpenCodeMessage, OpenCodePart, OpenCodeTextPart, OpenCodeReasoningPart, OpenCodeToolInvocationPart, OpenCodeCompactionPart, OpenCodeDbToolPart, OpenCodeStepStartPart, OpenCodeStepFinishPart, OpenCodePatchPart, OpenCodeSubtaskPart, OpenCodeAgentPart, OpenCodeFilePart, OpenCodeRetryPart, OpenCodeSnapshotPart, OpenCodeProject, DbProject as OpenCodeDbProject, DbSession as OpenCodeDbSession, DbMessage as OpenCodeDbMessage, DbPart as OpenCodeDbPart, } from './types/opencode';
|
|
16
16
|
export type { CodexRolloutLine, CodexSessionMeta, CodexResponseItem, CodexMessageItem, CodexContentPart, CodexReasoningItem, CodexFunctionCallItem, CodexFunctionCallOutputItem, CodexLocalShellCallItem, CodexWebSearchCallItem, CodexCustomToolCallItem, CodexCustomToolCallOutputItem, CodexCompacted, CodexTurnContext, CodexEventMsg, CodexEvent, CodexTurnStartedEvent, CodexTurnCompleteEvent, CodexTaskStartedEvent, CodexTaskCompleteEvent, CodexTurnAbortedEvent, CodexTokenCountEvent, CodexTokenUsage, CodexRateLimits, CodexAgentMessageEvent, CodexAgentReasoningEvent, CodexUserMessageEvent, CodexExecCommandBeginEvent, CodexExecCommandEndEvent, CodexMcpToolCallBeginEvent, CodexMcpToolCallEndEvent, CodexErrorEvent, CodexContextCompactedEvent, CodexPatchAppliedEvent, CodexBackgroundEvent, CodexGenericEvent, CodexDbThread, CodexReasoningSummary, } from './types/codex';
|
package/dist/node.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export type { HydrateOptions, HydrateResult } from './pricingCatalog';
|
|
|
10
10
|
export { listRecentSessions, readSessionTranscript } from './sessionTranscripts';
|
|
11
11
|
export type { ProviderSessionIndex, ListRecentSessionsOptions } from './sessionTranscripts';
|
|
12
12
|
export { ObservedSessionCollector, observedSessionSourceFromProvider, fileFingerprint, } from './observedSessionCollector';
|
|
13
|
-
export type { ObservedSessionReference, ObservedSessionCollectionSource, ObservedSessionDiagnosticKind, ObservedSessionDiagnostic, ObservedSessionCollection, ObservedSessionCollectorOptions, } from './observedSessionCollector';
|
|
13
|
+
export type { ObservedSessionReference, ObservedSessionCollectionSource, ProviderObservedSessionCollectionSource, ObservedSessionDiagnosticKind, ObservedSessionDiagnostic, ObservedSessionCollection, ObservedSessionCollectorOptions, } from './observedSessionCollector';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ObservedAgentSessionV1 } from './types/observedSessionV1';
|
|
1
|
+
import type { ObservedAgentSessionV1, ProviderCapabilitiesV1 } from './types/observedSessionV1';
|
|
2
2
|
import type { SessionProviderBase } from './providers/types';
|
|
3
3
|
export interface ObservedSessionReference {
|
|
4
4
|
sessionId: string;
|
|
@@ -12,6 +12,9 @@ export interface ObservedSessionCollectionSource<T = unknown> {
|
|
|
12
12
|
read(reference: ObservedSessionReference): Promise<T> | T;
|
|
13
13
|
dispose?(): void;
|
|
14
14
|
}
|
|
15
|
+
export interface ProviderObservedSessionCollectionSource extends ObservedSessionCollectionSource<ObservedAgentSessionV1> {
|
|
16
|
+
capabilities: ProviderCapabilitiesV1;
|
|
17
|
+
}
|
|
15
18
|
export type ObservedSessionDiagnosticKind = 'provider-discovery-failed' | 'session-read-failed' | 'provider-recovered' | 'session-recovered';
|
|
16
19
|
/** Content-safe diagnostics: identifiers and retry metadata only. */
|
|
17
20
|
export interface ObservedSessionDiagnostic {
|
|
@@ -63,6 +66,6 @@ export declare class ObservedSessionCollector<T = unknown> {
|
|
|
63
66
|
* Adapt a provider using path-only discovery and independent adapter reads, so
|
|
64
67
|
* one malformed session cannot reject discovery of its healthy siblings.
|
|
65
68
|
*/
|
|
66
|
-
export declare function observedSessionSourceFromProvider(provider: SessionProviderBase, cwd: string):
|
|
69
|
+
export declare function observedSessionSourceFromProvider(provider: SessionProviderBase, cwd: string): ProviderObservedSessionCollectionSource;
|
|
67
70
|
/** Size/mtime fingerprint suitable for retry bypass; returns null for synthetic DB locators. */
|
|
68
71
|
export declare function fileFingerprint(sourcePath: string): string | null;
|
|
@@ -144,6 +144,7 @@ function observedSessionSourceFromProvider(provider, cwd) {
|
|
|
144
144
|
const adapter = (0, observedSessionV1_1.createProviderSessionAdapterV1)(provider);
|
|
145
145
|
return {
|
|
146
146
|
providerId: provider.id,
|
|
147
|
+
capabilities: adapter.capabilities,
|
|
147
148
|
discover() {
|
|
148
149
|
return provider.findAllSessions(cwd).map((sessionPath) => ({
|
|
149
150
|
sessionId: provider.getSessionId(sessionPath),
|
|
@@ -200,18 +200,21 @@ class CodexRolloutParser {
|
|
|
200
200
|
handleSessionMeta(timestamp, payload) {
|
|
201
201
|
this.sessionMeta = payload;
|
|
202
202
|
const text = payload.base_instructions?.text?.trim();
|
|
203
|
-
if (!text)
|
|
204
|
-
return [];
|
|
205
203
|
return [
|
|
206
204
|
{
|
|
207
205
|
type: 'system',
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
...(text
|
|
207
|
+
? {
|
|
208
|
+
message: {
|
|
209
|
+
role: 'system',
|
|
210
|
+
id: `${payload.id}:base-instructions`,
|
|
211
|
+
sourceLabel: 'base instructions',
|
|
212
|
+
content: [{ type: 'text', text }],
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
: {}),
|
|
214
216
|
timestamp,
|
|
217
|
+
cwd: payload.cwd || undefined,
|
|
215
218
|
},
|
|
216
219
|
];
|
|
217
220
|
}
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ export { normalizedUsageSchema, normalizedUsageCostSchema } from './usageNormali
|
|
|
16
16
|
export type { NormalizedUsage, NormalizedUsageCost } from '../usageNormalization';
|
|
17
17
|
export { tokenEstimateSchema } from './tokenEstimation';
|
|
18
18
|
export type { TokenEstimate } from '../tokenEstimation';
|
|
19
|
-
export { canonicalTranscriptBlockSchema, canonicalToolCallSchema, canonicalTranscriptMessageSchema, canonicalSessionTranscriptSchema, } from './transcript';
|
|
20
|
-
export type { CanonicalSessionTranscript, CanonicalTranscriptMessage, CanonicalToolCall, } from '../transcript';
|
|
19
|
+
export { transcriptSourceProvenanceSchema, canonicalTranscriptBlockSchema, canonicalToolCallSchema, canonicalTranscriptMessageSchema, canonicalSessionTranscriptSchema, } from './transcript';
|
|
20
|
+
export type { CanonicalSessionTranscript, CanonicalTranscriptMessage, CanonicalToolCall, TranscriptSourceProvenance, } from '../transcript';
|
|
21
21
|
export { observationProvenanceV1Schema, observedAgentSessionV1Schema, observedValueV1Schema, pendingUserRequestV1Schema, providerCapabilitiesV1Schema, providerSessionAdapterV1Schema, sessionEvidenceRefV1Schema, } from './observedSessionV1';
|
|
22
22
|
export type { ObservationProvenanceV1, ObservedAgentSessionV1, ObservedValueV1, PendingUserRequestV1, ProviderCapabilitiesV1, ProviderSessionAdapterV1, SessionEvidenceRefV1, } from '../types/observedSessionV1';
|
|
23
23
|
export { quotaWindowSchema, quotaStateSchema, quotaFailureKindSchema, quotaProviderIdSchema, quotaSourceSchema, codexResetCreditSchema, codexResetCreditsSnapshotSchema, peakHoursStateSchema, quotaFailureDescriptorSchema, runtimeQuotaProviderSchema, providerQuotaStateSchema, claudeProviderQuotaStateSchema, codexProviderQuotaStateSchema, zaiProviderQuotaStateSchema, providerQuotaMapSchema, } from './quota';
|
package/dist/schemas/index.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* subpath is self-sufficient for boundary-validation modules.
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = void 0;
|
|
15
|
+
exports.accountLoginStatusSchema = exports.beginAccountLoginResultSchema = exports.accountManagerResultSchema = exports.accountProviderIdSchema = exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.zaiProviderQuotaStateSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.codexResetCreditsSnapshotSchema = exports.codexResetCreditSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.sessionEvidenceRefV1Schema = exports.providerSessionAdapterV1Schema = exports.providerCapabilitiesV1Schema = exports.pendingUserRequestV1Schema = exports.observedValueV1Schema = exports.observedAgentSessionV1Schema = exports.observationProvenanceV1Schema = exports.canonicalSessionTranscriptSchema = exports.canonicalTranscriptMessageSchema = exports.canonicalToolCallSchema = exports.canonicalTranscriptBlockSchema = exports.transcriptSourceProvenanceSchema = exports.tokenEstimateSchema = exports.normalizedUsageCostSchema = exports.normalizedUsageSchema = exports.toolResultSessionEventSchema = exports.toolUseSessionEventSchema = exports.systemSessionEventSchema = exports.summarySessionEventSchema = exports.assistantSessionEventSchema = exports.userSessionEventSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = void 0;
|
|
16
|
+
exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = void 0;
|
|
17
17
|
var sessionEvent_1 = require("./sessionEvent");
|
|
18
18
|
Object.defineProperty(exports, "messageUsageSchema", { enumerable: true, get: function () { return sessionEvent_1.messageUsageSchema; } });
|
|
19
19
|
Object.defineProperty(exports, "sessionMessageSchema", { enumerable: true, get: function () { return sessionEvent_1.sessionMessageSchema; } });
|
|
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "normalizedUsageCostSchema", { enumerable: true,
|
|
|
32
32
|
var tokenEstimation_1 = require("./tokenEstimation");
|
|
33
33
|
Object.defineProperty(exports, "tokenEstimateSchema", { enumerable: true, get: function () { return tokenEstimation_1.tokenEstimateSchema; } });
|
|
34
34
|
var transcript_1 = require("./transcript");
|
|
35
|
+
Object.defineProperty(exports, "transcriptSourceProvenanceSchema", { enumerable: true, get: function () { return transcript_1.transcriptSourceProvenanceSchema; } });
|
|
35
36
|
Object.defineProperty(exports, "canonicalTranscriptBlockSchema", { enumerable: true, get: function () { return transcript_1.canonicalTranscriptBlockSchema; } });
|
|
36
37
|
Object.defineProperty(exports, "canonicalToolCallSchema", { enumerable: true, get: function () { return transcript_1.canonicalToolCallSchema; } });
|
|
37
38
|
Object.defineProperty(exports, "canonicalTranscriptMessageSchema", { enumerable: true, get: function () { return transcript_1.canonicalTranscriptMessageSchema; } });
|
|
@@ -61,7 +61,11 @@ export declare const permissionModeSchema: z.ZodEnum<{
|
|
|
61
61
|
}>;
|
|
62
62
|
export declare const userSessionEventSchema: z.ZodObject<{
|
|
63
63
|
timestamp: z.ZodString;
|
|
64
|
+
entrypoint: z.ZodOptional<z.ZodString>;
|
|
65
|
+
isMeta: z.ZodOptional<z.ZodBoolean>;
|
|
64
66
|
isSidechain: z.ZodOptional<z.ZodBoolean>;
|
|
67
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
68
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
65
69
|
permissionMode: z.ZodOptional<z.ZodEnum<{
|
|
66
70
|
default: "default";
|
|
67
71
|
acceptEdits: "acceptEdits";
|
|
@@ -136,7 +140,11 @@ export declare const userSessionEventSchema: z.ZodObject<{
|
|
|
136
140
|
}, z.core.$strip>;
|
|
137
141
|
export declare const assistantSessionEventSchema: z.ZodObject<{
|
|
138
142
|
timestamp: z.ZodString;
|
|
143
|
+
entrypoint: z.ZodOptional<z.ZodString>;
|
|
144
|
+
isMeta: z.ZodOptional<z.ZodBoolean>;
|
|
139
145
|
isSidechain: z.ZodOptional<z.ZodBoolean>;
|
|
146
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
147
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
140
148
|
permissionMode: z.ZodOptional<z.ZodEnum<{
|
|
141
149
|
default: "default";
|
|
142
150
|
acceptEdits: "acceptEdits";
|
|
@@ -212,7 +220,11 @@ export declare const assistantSessionEventSchema: z.ZodObject<{
|
|
|
212
220
|
export declare const summarySessionEventSchema: z.ZodType<SummarySessionEvent>;
|
|
213
221
|
export declare const systemSessionEventSchema: z.ZodObject<{
|
|
214
222
|
timestamp: z.ZodString;
|
|
223
|
+
entrypoint: z.ZodOptional<z.ZodString>;
|
|
224
|
+
isMeta: z.ZodOptional<z.ZodBoolean>;
|
|
215
225
|
isSidechain: z.ZodOptional<z.ZodBoolean>;
|
|
226
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
227
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
216
228
|
permissionMode: z.ZodOptional<z.ZodEnum<{
|
|
217
229
|
default: "default";
|
|
218
230
|
acceptEdits: "acceptEdits";
|
|
@@ -291,7 +303,11 @@ export declare const toolUseSessionEventSchema: z.ZodObject<{
|
|
|
291
303
|
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
292
304
|
}, z.core.$strip>;
|
|
293
305
|
timestamp: z.ZodString;
|
|
306
|
+
entrypoint: z.ZodOptional<z.ZodString>;
|
|
307
|
+
isMeta: z.ZodOptional<z.ZodBoolean>;
|
|
294
308
|
isSidechain: z.ZodOptional<z.ZodBoolean>;
|
|
309
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
310
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
295
311
|
permissionMode: z.ZodOptional<z.ZodEnum<{
|
|
296
312
|
default: "default";
|
|
297
313
|
acceptEdits: "acceptEdits";
|
|
@@ -371,7 +387,11 @@ export declare const toolResultSessionEventSchema: z.ZodObject<{
|
|
|
371
387
|
is_error: z.ZodOptional<z.ZodBoolean>;
|
|
372
388
|
}, z.core.$strip>;
|
|
373
389
|
timestamp: z.ZodString;
|
|
390
|
+
entrypoint: z.ZodOptional<z.ZodString>;
|
|
391
|
+
isMeta: z.ZodOptional<z.ZodBoolean>;
|
|
374
392
|
isSidechain: z.ZodOptional<z.ZodBoolean>;
|
|
393
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
394
|
+
gitBranch: z.ZodOptional<z.ZodString>;
|
|
375
395
|
permissionMode: z.ZodOptional<z.ZodEnum<{
|
|
376
396
|
default: "default";
|
|
377
397
|
acceptEdits: "acceptEdits";
|
|
@@ -41,7 +41,11 @@ exports.permissionModeSchema = zod_1.z.enum([
|
|
|
41
41
|
// ── SessionEvent ──
|
|
42
42
|
const eventBaseShape = {
|
|
43
43
|
timestamp: zod_1.z.string(),
|
|
44
|
+
entrypoint: zod_1.z.string().optional(),
|
|
45
|
+
isMeta: zod_1.z.boolean().optional(),
|
|
44
46
|
isSidechain: zod_1.z.boolean().optional(),
|
|
47
|
+
cwd: zod_1.z.string().optional(),
|
|
48
|
+
gitBranch: zod_1.z.string().optional(),
|
|
45
49
|
permissionMode: exports.permissionModeSchema.optional(),
|
|
46
50
|
rateLimits: zod_1.z
|
|
47
51
|
.object({
|
|
@@ -169,19 +173,38 @@ const MAX_PROGRESS_DEPTH = 8;
|
|
|
169
173
|
* Returns zero events for unrecognized input — never throws.
|
|
170
174
|
*/
|
|
171
175
|
function extractSessionEvents(raw, depth = 0) {
|
|
176
|
+
return extractSessionEventsWithProvenance(raw, depth, {});
|
|
177
|
+
}
|
|
178
|
+
function extractSessionEventsWithProvenance(raw, depth, inherited) {
|
|
172
179
|
const direct = exports.sessionEventSchema.safeParse(raw);
|
|
173
180
|
if (direct.success)
|
|
174
|
-
return [direct.data];
|
|
181
|
+
return [{ ...inherited, ...direct.data }];
|
|
175
182
|
if (depth >= MAX_PROGRESS_DEPTH)
|
|
176
183
|
return [];
|
|
177
184
|
if (typeof raw === 'object' && raw !== null && raw.type === 'progress') {
|
|
185
|
+
const provenance = { ...inherited, ...progressProvenance(raw) };
|
|
178
186
|
const data = raw.data;
|
|
179
187
|
if (typeof data === 'object' && data !== null) {
|
|
180
188
|
const message = data.message;
|
|
181
189
|
if (typeof message === 'object' && message !== null) {
|
|
182
|
-
return
|
|
190
|
+
return extractSessionEventsWithProvenance(message, depth + 1, provenance);
|
|
183
191
|
}
|
|
184
192
|
}
|
|
185
193
|
}
|
|
186
194
|
return [];
|
|
187
195
|
}
|
|
196
|
+
function progressProvenance(raw) {
|
|
197
|
+
const value = raw;
|
|
198
|
+
const provenance = {};
|
|
199
|
+
if (typeof value.entrypoint === 'string')
|
|
200
|
+
provenance.entrypoint = value.entrypoint;
|
|
201
|
+
if (typeof value.isMeta === 'boolean')
|
|
202
|
+
provenance.isMeta = value.isMeta;
|
|
203
|
+
if (typeof value.isSidechain === 'boolean')
|
|
204
|
+
provenance.isSidechain = value.isSidechain;
|
|
205
|
+
if (typeof value.cwd === 'string')
|
|
206
|
+
provenance.cwd = value.cwd;
|
|
207
|
+
if (typeof value.gitBranch === 'string')
|
|
208
|
+
provenance.gitBranch = value.gitBranch;
|
|
209
|
+
return provenance;
|
|
210
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { CanonicalSessionTranscript, CanonicalTranscriptMessage, CanonicalToolCall } from '../transcript';
|
|
2
|
+
import type { CanonicalSessionTranscript, CanonicalTranscriptMessage, CanonicalToolCall, TranscriptSourceProvenance } from '../transcript';
|
|
3
|
+
export declare const transcriptSourceProvenanceSchema: z.ZodType<TranscriptSourceProvenance>;
|
|
3
4
|
export declare const canonicalTranscriptBlockSchema: z.ZodObject<{
|
|
4
5
|
type: z.ZodEnum<{
|
|
5
6
|
unknown: "unknown";
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canonicalSessionTranscriptSchema = exports.canonicalTranscriptMessageSchema = exports.canonicalToolCallSchema = exports.canonicalTranscriptBlockSchema = void 0;
|
|
3
|
+
exports.canonicalSessionTranscriptSchema = exports.canonicalTranscriptMessageSchema = exports.canonicalToolCallSchema = exports.canonicalTranscriptBlockSchema = exports.transcriptSourceProvenanceSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const usageNormalization_1 = require("./usageNormalization");
|
|
6
|
-
|
|
6
|
+
exports.transcriptSourceProvenanceSchema = zod_1.z.object({
|
|
7
7
|
provider: zod_1.z.string().optional(),
|
|
8
8
|
sessionId: zod_1.z.string().optional(),
|
|
9
9
|
sourcePath: zod_1.z.string().optional(),
|
|
10
10
|
source: zod_1.z.string().optional(),
|
|
11
|
+
entrypoint: zod_1.z.string().optional(),
|
|
12
|
+
isMeta: zod_1.z.boolean().optional(),
|
|
13
|
+
isSidechain: zod_1.z.boolean().optional(),
|
|
14
|
+
originalRole: zod_1.z.string().optional(),
|
|
11
15
|
eventIndex: zod_1.z.number().int().nonnegative(),
|
|
12
16
|
eventType: zod_1.z.enum(['user', 'assistant', 'tool_use', 'tool_result', 'summary', 'system']),
|
|
13
17
|
eventId: zod_1.z.string().optional(),
|
|
@@ -32,7 +36,7 @@ exports.canonicalToolCallSchema = zod_1.z.object({
|
|
|
32
36
|
output: zod_1.z.unknown().optional(),
|
|
33
37
|
isError: zod_1.z.boolean().optional(),
|
|
34
38
|
command: zod_1.z.string().optional(),
|
|
35
|
-
source:
|
|
39
|
+
source: exports.transcriptSourceProvenanceSchema,
|
|
36
40
|
});
|
|
37
41
|
exports.canonicalTranscriptMessageSchema = zod_1.z.object({
|
|
38
42
|
id: zod_1.z.string().optional(),
|
|
@@ -46,12 +50,14 @@ exports.canonicalTranscriptMessageSchema = zod_1.z.object({
|
|
|
46
50
|
cost: usageNormalization_1.normalizedUsageCostSchema.optional(),
|
|
47
51
|
tools: zod_1.z.array(exports.canonicalToolCallSchema),
|
|
48
52
|
commands: zod_1.z.array(zod_1.z.string()),
|
|
49
|
-
source:
|
|
53
|
+
source: exports.transcriptSourceProvenanceSchema,
|
|
50
54
|
});
|
|
51
55
|
exports.canonicalSessionTranscriptSchema = zod_1.z.object({
|
|
52
56
|
provider: zod_1.z.string().optional(),
|
|
53
57
|
sessionId: zod_1.z.string().optional(),
|
|
54
58
|
sourcePath: zod_1.z.string().optional(),
|
|
59
|
+
cwd: zod_1.z.string().optional(),
|
|
60
|
+
gitBranch: zod_1.z.string().optional(),
|
|
55
61
|
startedAt: zod_1.z.string().optional(),
|
|
56
62
|
endedAt: zod_1.z.string().optional(),
|
|
57
63
|
models: zod_1.z.array(zod_1.z.string()),
|
package/dist/transcript.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export interface TranscriptSourceProvenance {
|
|
|
7
7
|
sessionId?: string;
|
|
8
8
|
sourcePath?: string;
|
|
9
9
|
source?: string;
|
|
10
|
+
entrypoint?: string;
|
|
11
|
+
isMeta?: boolean;
|
|
12
|
+
isSidechain?: boolean;
|
|
13
|
+
originalRole?: string;
|
|
10
14
|
eventIndex: number;
|
|
11
15
|
eventType: SessionEvent['type'];
|
|
12
16
|
eventId?: string;
|
|
@@ -61,6 +65,8 @@ export interface CanonicalSessionTranscript {
|
|
|
61
65
|
provider?: ProviderId | string;
|
|
62
66
|
sessionId?: string;
|
|
63
67
|
sourcePath?: string;
|
|
68
|
+
cwd?: string;
|
|
69
|
+
gitBranch?: string;
|
|
64
70
|
startedAt?: string;
|
|
65
71
|
endedAt?: string;
|
|
66
72
|
models: string[];
|
package/dist/transcript.js
CHANGED
|
@@ -25,13 +25,23 @@ function projectSessionTranscript(events, options = {}) {
|
|
|
25
25
|
const usageCosts = [];
|
|
26
26
|
const totals = { ...EMPTY_TOTALS };
|
|
27
27
|
const toolsById = new Map();
|
|
28
|
+
let cwd;
|
|
29
|
+
let gitBranch;
|
|
28
30
|
events.forEach((event, eventIndex) => {
|
|
31
|
+
if (nonEmpty(event.cwd))
|
|
32
|
+
cwd = event.cwd;
|
|
33
|
+
if (nonEmpty(event.gitBranch))
|
|
34
|
+
gitBranch = event.gitBranch;
|
|
29
35
|
const message = event.message;
|
|
30
36
|
const source = {
|
|
31
37
|
provider: options.provider ?? event.providerMetadata?.providerId,
|
|
32
38
|
sessionId: options.sessionId,
|
|
33
39
|
sourcePath: options.sourcePath,
|
|
34
40
|
source: event.providerMetadata?.source,
|
|
41
|
+
entrypoint: event.entrypoint,
|
|
42
|
+
isMeta: event.isMeta,
|
|
43
|
+
isSidechain: event.isSidechain,
|
|
44
|
+
originalRole: message?.role,
|
|
35
45
|
eventIndex,
|
|
36
46
|
eventType: event.type,
|
|
37
47
|
eventId: message?.id,
|
|
@@ -119,6 +129,8 @@ function projectSessionTranscript(events, options = {}) {
|
|
|
119
129
|
provider: options.provider,
|
|
120
130
|
sessionId: options.sessionId,
|
|
121
131
|
sourcePath: options.sourcePath,
|
|
132
|
+
cwd,
|
|
133
|
+
gitBranch,
|
|
122
134
|
startedAt: events[0]?.timestamp,
|
|
123
135
|
endedAt: events.at(-1)?.timestamp,
|
|
124
136
|
models: [...models],
|
|
@@ -136,6 +148,9 @@ function projectSessionTranscript(events, options = {}) {
|
|
|
136
148
|
provenance: { source: 'session-events', fidelity, eventCount: events.length },
|
|
137
149
|
};
|
|
138
150
|
}
|
|
151
|
+
function nonEmpty(value) {
|
|
152
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
153
|
+
}
|
|
139
154
|
function roleForEvent(event) {
|
|
140
155
|
if (event.type === 'summary')
|
|
141
156
|
return 'summary';
|
|
@@ -57,8 +57,16 @@ export interface SessionMessage {
|
|
|
57
57
|
export interface SessionEventBase {
|
|
58
58
|
/** ISO 8601 timestamp of event */
|
|
59
59
|
timestamp: string;
|
|
60
|
+
/** Provider-reported entrypoint that produced this event. */
|
|
61
|
+
entrypoint?: string;
|
|
62
|
+
/** Whether the provider identifies this as orchestration or metadata. */
|
|
63
|
+
isMeta?: boolean;
|
|
60
64
|
/** Whether this is a subagent/sidechain event */
|
|
61
65
|
isSidechain?: boolean;
|
|
66
|
+
/** Provider-reported working directory for this event/session. */
|
|
67
|
+
cwd?: string;
|
|
68
|
+
/** Provider-reported git branch for this event/session. */
|
|
69
|
+
gitBranch?: string;
|
|
62
70
|
/** Permission mode active when this event occurred */
|
|
63
71
|
permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
|
|
64
72
|
/** Subscription rate limits, when provided by the session source. */
|
package/package.json
CHANGED