sidekick-shared 0.26.6 → 0.27.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/CHANGELOG.md +30 -0
- package/README.md +57 -20
- package/dist/humanPrompt.d.ts +27 -0
- package/dist/humanPrompt.js +93 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -10
- package/dist/modelContext.js +4 -0
- package/dist/modelInfo.js +26 -1
- package/dist/node.d.ts +4 -0
- package/dist/node.js +9 -2
- package/dist/promptHistory.d.ts +149 -0
- package/dist/promptHistory.js +719 -0
- package/dist/schemas/sessionEvent.d.ts +25 -0
- package/dist/schemas/sessionEvent.js +3 -0
- package/dist/transcript.d.ts +6 -0
- package/dist/transcript.js +3 -0
- package/dist/types/sessionEvent.d.ts +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-only collection of human-typed prompts from Claude Code and Codex
|
|
3
|
+
* session logs, scoped to a set of workspace roots.
|
|
4
|
+
*
|
|
5
|
+
* Parse-only: no redaction and no network I/O. Scope fails closed — a prompt
|
|
6
|
+
* is returned only when the working directory recorded on its log line (or,
|
|
7
|
+
* for Codex, its session/turn context) realpath-resolves to an allowed root
|
|
8
|
+
* or somewhere inside one. Every bound stops cleanly and is reported in
|
|
9
|
+
* `boundsHit`; nothing is silently truncated and no bound throws.
|
|
10
|
+
*
|
|
11
|
+
* A prompt can be written before its answer. The cursor then keeps the byte
|
|
12
|
+
* offset of that prompt's line (not its text), the next call replays from it,
|
|
13
|
+
* and the prompt is returned again under the same identity once its first
|
|
14
|
+
* answering call brings model or usage (`metadataStatus` says how settled).
|
|
15
|
+
*/
|
|
16
|
+
import { type HumanPromptProvider } from './humanPrompt';
|
|
17
|
+
export type PromptHistoryProvider = HumanPromptProvider;
|
|
18
|
+
export type PromptHistoryBound = 'maxSessions' | 'maxFileBytes' | 'maxTotalBytes' | 'deadline' | 'aborted';
|
|
19
|
+
export interface PromptHistoryBounds {
|
|
20
|
+
/** Session files read in one call (unchanged files do not count). Default 1000. */
|
|
21
|
+
maxSessions?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Bytes a single file may need read in this pass. Default 16 MiB. A file over
|
|
24
|
+
* it is skipped, and calling again with the same bounds skips it again.
|
|
25
|
+
*/
|
|
26
|
+
maxFileBytes?: number;
|
|
27
|
+
/** Bytes read across all files in this call. Default 256 MiB. */
|
|
28
|
+
maxTotalBytes?: number;
|
|
29
|
+
/** Wall-clock budget for the call. Default 30 000 ms. */
|
|
30
|
+
deadlineMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Codex parse state carried across resumes (Claude lines are self-describing). */
|
|
33
|
+
export interface PromptHistoryResumeState {
|
|
34
|
+
cwd?: string;
|
|
35
|
+
gitBranch?: string;
|
|
36
|
+
model?: string;
|
|
37
|
+
/** Session is not interactive (non-human source, fork, or missing metadata). */
|
|
38
|
+
excluded?: boolean;
|
|
39
|
+
/** `session_meta` has been seen. */
|
|
40
|
+
meta?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The last emitted prompt of a file whose answering call is not final yet.
|
|
44
|
+
* Holds a replay position and a metadata digest, never prompt or answer text.
|
|
45
|
+
*/
|
|
46
|
+
export interface PromptHistoryPendingPrompt {
|
|
47
|
+
ordinal: number;
|
|
48
|
+
/** Byte offset where the prompt's log line starts; the next pass replays from here. */
|
|
49
|
+
offset: number;
|
|
50
|
+
/** Digest of the model, usage, and status last returned for this prompt. */
|
|
51
|
+
emitted: string;
|
|
52
|
+
/** Codex parse state as it was just before the prompt line. */
|
|
53
|
+
state?: PromptHistoryResumeState;
|
|
54
|
+
}
|
|
55
|
+
export interface PromptHistoryCursorSession {
|
|
56
|
+
provider: PromptHistoryProvider;
|
|
57
|
+
sessionId: string;
|
|
58
|
+
size: number;
|
|
59
|
+
mtimeMs: number;
|
|
60
|
+
/** Ordinal of the last human prompt seen in this file, or -1 when none. */
|
|
61
|
+
lastOrdinal: number;
|
|
62
|
+
/** Byte offset just past the last complete line processed. */
|
|
63
|
+
offset: number;
|
|
64
|
+
state?: PromptHistoryResumeState;
|
|
65
|
+
pending?: PromptHistoryPendingPrompt;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* JSON-serializable resume point. Keys are opaque and never contain paths, but
|
|
69
|
+
* values can (Codex `state.cwd`), so treat the cursor as sensitive local state.
|
|
70
|
+
* Version 1 cursors from 0.27.0 are accepted as input; output is always version 2.
|
|
71
|
+
*/
|
|
72
|
+
export interface PromptHistoryCursor {
|
|
73
|
+
version: 2;
|
|
74
|
+
sessions: Record<string, PromptHistoryCursorSession>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* How settled an entry's `model` / `usage` are:
|
|
78
|
+
* - `pending`: no answering call seen yet.
|
|
79
|
+
* - `provisional`: the first answering call is still being written (Claude
|
|
80
|
+
* `stop_reason: null`); values may change.
|
|
81
|
+
* - `final`: the first answering call is complete, or the prompt was closed
|
|
82
|
+
* without one. Missing usage is then unknown, not zero.
|
|
83
|
+
*/
|
|
84
|
+
export type PromptHistoryMetadataStatus = 'pending' | 'provisional' | 'final';
|
|
85
|
+
export interface PromptHistoryUsage {
|
|
86
|
+
/** Uncached input tokens. */
|
|
87
|
+
inputTokens?: number;
|
|
88
|
+
outputTokens?: number;
|
|
89
|
+
cacheReadTokens?: number;
|
|
90
|
+
cacheWriteTokens?: number;
|
|
91
|
+
}
|
|
92
|
+
export interface PromptHistoryEntry {
|
|
93
|
+
provider: PromptHistoryProvider;
|
|
94
|
+
sessionId: string;
|
|
95
|
+
/** Stable index of this prompt among the session's human prompts (0-based). */
|
|
96
|
+
ordinal: number;
|
|
97
|
+
/** ISO timestamp from the log line; never synthesized. */
|
|
98
|
+
timestamp: string;
|
|
99
|
+
/** Full prompt text, untruncated. */
|
|
100
|
+
text: string;
|
|
101
|
+
/** Realpath of the working directory; always inside an allowed root. */
|
|
102
|
+
cwd: string;
|
|
103
|
+
gitBranch?: string;
|
|
104
|
+
/** Model of the first assistant response to this prompt, when known. */
|
|
105
|
+
model?: string;
|
|
106
|
+
/** Usage of that first answering model call, when known. */
|
|
107
|
+
usage?: PromptHistoryUsage;
|
|
108
|
+
/**
|
|
109
|
+
* Whether `model` / `usage` can still change. A prompt that is not `final`
|
|
110
|
+
* is returned again, with the same provider, sessionId, ordinal, timestamp,
|
|
111
|
+
* and text, by a later call once its metadata or status changes.
|
|
112
|
+
*/
|
|
113
|
+
metadataStatus: PromptHistoryMetadataStatus;
|
|
114
|
+
}
|
|
115
|
+
export interface PromptHistoryStats {
|
|
116
|
+
sessionsScanned: number;
|
|
117
|
+
sessionsSkippedUnchanged: number;
|
|
118
|
+
/** Scanned sessions with human prompts but none inside the allowed roots. */
|
|
119
|
+
sessionsOutOfScope: number;
|
|
120
|
+
filesOverSizeLimit: number;
|
|
121
|
+
/** Codex sessions skipped as non-interactive (subagent, fork, unknown source). */
|
|
122
|
+
sessionsNotInteractive: number;
|
|
123
|
+
/** Human prompts dropped because the log line had no usable timestamp. */
|
|
124
|
+
promptsMissingTimestamp: number;
|
|
125
|
+
/** Human prompts dropped because their cwd was missing or outside the roots. */
|
|
126
|
+
promptsOutOfScope: number;
|
|
127
|
+
}
|
|
128
|
+
export interface CollectPromptHistoryOptions {
|
|
129
|
+
/** Absolute workspace roots; realpath-normalized internally. */
|
|
130
|
+
workspacePaths: string[];
|
|
131
|
+
/** Add git worktree siblings of each root. Default true. */
|
|
132
|
+
includeWorktrees?: boolean;
|
|
133
|
+
/** Default both. */
|
|
134
|
+
providers?: PromptHistoryProvider[];
|
|
135
|
+
/** Drop prompts older than this (and skip files not modified since). */
|
|
136
|
+
since?: Date;
|
|
137
|
+
cursor?: PromptHistoryCursor;
|
|
138
|
+
bounds?: PromptHistoryBounds;
|
|
139
|
+
signal?: AbortSignal;
|
|
140
|
+
}
|
|
141
|
+
export interface PromptHistoryResult {
|
|
142
|
+
/** Ordered by provider, session, then ordinal. */
|
|
143
|
+
entries: PromptHistoryEntry[];
|
|
144
|
+
cursor: PromptHistoryCursor;
|
|
145
|
+
stats: PromptHistoryStats;
|
|
146
|
+
boundsHit: PromptHistoryBound[];
|
|
147
|
+
}
|
|
148
|
+
/** Collect human-typed prompts from Claude Code and Codex logs under the given roots. */
|
|
149
|
+
export declare function collectPromptHistory(options: CollectPromptHistoryOptions): Promise<PromptHistoryResult>;
|