@skrr-ai/cli 0.1.204 → 0.1.206
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/bin/dev-fallback.js +47 -29
- package/bin/dev.cjs +6 -0
- package/dist/commands/agent/message/send.d.ts +7 -1
- package/dist/commands/agent/message/send.js +13 -0
- package/dist/commands/convos/transcript.d.ts +48 -0
- package/dist/commands/convos/transcript.js +461 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.d.ts +16 -15
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.js +0 -22
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.d.ts +16 -15
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.js +0 -22
- package/dist/node_modules/@skrr-ai/data-provider/index.js +11469 -11392
- package/oclif.manifest.json +113 -1
- package/package.json +6 -3
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTINUATION_STATE_WORDS = exports.TRANSCRIPT_SOURCE_WORDS = exports.CONTEXT_BREAK_WORDS = void 0;
|
|
4
|
+
exports.describeContext = describeContext;
|
|
5
|
+
exports.boundaryLine = boundaryLine;
|
|
6
|
+
exports.usageSummary = usageSummary;
|
|
7
|
+
exports.processSummary = processSummary;
|
|
8
|
+
exports.formatTranscriptItem = formatTranscriptItem;
|
|
9
|
+
exports.formatTurnBody = formatTurnBody;
|
|
10
|
+
const core_1 = require("@oclif/core");
|
|
11
|
+
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
12
|
+
const base_command_1 = require("../../base-command");
|
|
13
|
+
const WHITESPACE_RE = /\s+/g;
|
|
14
|
+
const TEXT_CLIP = 300;
|
|
15
|
+
const ENVELOPE_CLIP = 160;
|
|
16
|
+
/**
|
|
17
|
+
* What each break reason says on a boundary line. Exhaustive by type: a reason added to
|
|
18
|
+
* `CONTEXT_BREAK_REASONS` does not compile here until it has words.
|
|
19
|
+
*/
|
|
20
|
+
exports.CONTEXT_BREAK_WORDS = {
|
|
21
|
+
first_turn: 'the first turn of this conversation',
|
|
22
|
+
config_changed: "the agent's configuration changed",
|
|
23
|
+
release_changed: 'the agent moved to another release',
|
|
24
|
+
harness_changed: 'the turn ran on another harness',
|
|
25
|
+
machine_changed: 'the session moved to another machine',
|
|
26
|
+
reanchored: 're-anchored to keep the context small',
|
|
27
|
+
cleared_after_failure: 'the previous session was cleared after a failure',
|
|
28
|
+
resume_failed: 'the previous session could not be resumed',
|
|
29
|
+
not_resumable: 'this kind of turn does not resume a session',
|
|
30
|
+
};
|
|
31
|
+
/** What each transcript source says in a turn header. Exhaustive by type. */
|
|
32
|
+
exports.TRANSCRIPT_SOURCE_WORDS = {
|
|
33
|
+
live: 'still running',
|
|
34
|
+
archive: 'full archive',
|
|
35
|
+
compacted: 'compacted copy only',
|
|
36
|
+
content: 'cloud content parts',
|
|
37
|
+
none: 'nothing was kept',
|
|
38
|
+
imported: 'imported history',
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Where a continuation sent to an imported session is, as its receipt says. Exhaustive by type.
|
|
42
|
+
* (An imported session is read only with a first-party app's session; a CLI token is refused.)
|
|
43
|
+
*/
|
|
44
|
+
exports.CONTINUATION_STATE_WORDS = {
|
|
45
|
+
preparing: 'sent from here, still being prepared',
|
|
46
|
+
unknown: 'sent from here, outcome not confirmed',
|
|
47
|
+
settled: 'sent from here, ended on the source computer',
|
|
48
|
+
not_submitted: 'sent from here, not submitted',
|
|
49
|
+
};
|
|
50
|
+
const oneLine = (text) => text.replace(WHITESPACE_RE, ' ').trim();
|
|
51
|
+
const clip = (text, max) => (text.length > max ? `${text.slice(0, max)}…` : text);
|
|
52
|
+
const when = (value) => {
|
|
53
|
+
if (!value)
|
|
54
|
+
return '';
|
|
55
|
+
const date = new Date(value);
|
|
56
|
+
return Number.isNaN(date.getTime()) ? value : date.toISOString();
|
|
57
|
+
};
|
|
58
|
+
/** A row's time and the gap after it, or nothing: an imported event may record no time. */
|
|
59
|
+
const stamp = (value) => (value ? `${when(value)} ` : '');
|
|
60
|
+
function formatBytes(bytes) {
|
|
61
|
+
if (bytes < 1024)
|
|
62
|
+
return `${bytes} B`;
|
|
63
|
+
if (bytes < 1024 * 1024)
|
|
64
|
+
return `${(bytes / 1024).toFixed(1)} KiB`;
|
|
65
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A recorded duration in words. Only `usage.durationMs` is one: a row's `updatedAt` moves with
|
|
69
|
+
* any later write to it (an archive pointer, a retraction), so it is not when the turn ended.
|
|
70
|
+
*/
|
|
71
|
+
function formatDuration(ms) {
|
|
72
|
+
if (ms === undefined || !Number.isFinite(ms) || ms < 0)
|
|
73
|
+
return null;
|
|
74
|
+
if (ms < 1000)
|
|
75
|
+
return `${ms}ms`;
|
|
76
|
+
const seconds = Math.round(ms / 1000);
|
|
77
|
+
if (seconds < 60)
|
|
78
|
+
return `${seconds}s`;
|
|
79
|
+
const minutes = Math.floor(seconds / 60);
|
|
80
|
+
return `${minutes}m${String(seconds % 60).padStart(2, '0')}s`;
|
|
81
|
+
}
|
|
82
|
+
/** Whether the harness context continued into this turn, in words. Never guesses "continued". */
|
|
83
|
+
function describeContext(turn) {
|
|
84
|
+
const lineage = turn.contextLineage;
|
|
85
|
+
if (!lineage)
|
|
86
|
+
return 'not recorded';
|
|
87
|
+
if (lineage.continued)
|
|
88
|
+
return 'continued';
|
|
89
|
+
return lineage.breakReason
|
|
90
|
+
? `new session: ${exports.CONTEXT_BREAK_WORDS[lineage.breakReason]}`
|
|
91
|
+
: 'new session: no reason was recorded';
|
|
92
|
+
}
|
|
93
|
+
/** The line drawn above a turn whose harness context did not continue, or null. */
|
|
94
|
+
function boundaryLine(turn) {
|
|
95
|
+
if (turn.contextLineage?.continued !== false)
|
|
96
|
+
return null;
|
|
97
|
+
return `──── ${describeContext(turn)} ────`;
|
|
98
|
+
}
|
|
99
|
+
const COUNT_FORMAT = new Intl.NumberFormat('en-US');
|
|
100
|
+
/**
|
|
101
|
+
* What the turn recorded of its usage, in one line, or null when it recorded nothing. Only the
|
|
102
|
+
* fields the server sent: an absent one was not recorded and is not printed as zero.
|
|
103
|
+
*/
|
|
104
|
+
function contextLine(usage) {
|
|
105
|
+
if (usage.contextTokens === undefined)
|
|
106
|
+
return null;
|
|
107
|
+
const window = usage.contextWindow !== undefined ? ` of ${COUNT_FORMAT.format(usage.contextWindow)}` : '';
|
|
108
|
+
return `${COUNT_FORMAT.format(usage.contextTokens)}${window} context`;
|
|
109
|
+
}
|
|
110
|
+
function usageSummary(usage) {
|
|
111
|
+
if (!usage)
|
|
112
|
+
return null;
|
|
113
|
+
const parts = [
|
|
114
|
+
usage.inputTokens !== undefined ? `${COUNT_FORMAT.format(usage.inputTokens)} in` : null,
|
|
115
|
+
usage.outputTokens !== undefined ? `${COUNT_FORMAT.format(usage.outputTokens)} out` : null,
|
|
116
|
+
usage.cacheReadTokens !== undefined
|
|
117
|
+
? `${COUNT_FORMAT.format(usage.cacheReadTokens)} cache read`
|
|
118
|
+
: null,
|
|
119
|
+
usage.cacheWriteTokens !== undefined
|
|
120
|
+
? `${COUNT_FORMAT.format(usage.cacheWriteTokens)} cache write`
|
|
121
|
+
: null,
|
|
122
|
+
usage.numTurns !== undefined ? `${usage.numTurns} model call(s)` : null,
|
|
123
|
+
contextLine(usage),
|
|
124
|
+
// The harness's running estimate for the whole session, never this turn's cost or a charge.
|
|
125
|
+
usage.sessionCostUsd !== undefined
|
|
126
|
+
? `session cost so far $${usage.sessionCostUsd.toFixed(4)} (estimate)`
|
|
127
|
+
: null,
|
|
128
|
+
usage.model ?? null,
|
|
129
|
+
].filter(Boolean);
|
|
130
|
+
return parts.length ? parts.join(', ') : null;
|
|
131
|
+
}
|
|
132
|
+
/** The turn's process in one line: where it is kept, how much, and what was lost. */
|
|
133
|
+
function processSummary(turn) {
|
|
134
|
+
const { transcript } = turn;
|
|
135
|
+
const parts = [exports.TRANSCRIPT_SOURCE_WORDS[transcript.source]];
|
|
136
|
+
const archive = transcript.archive;
|
|
137
|
+
if (archive) {
|
|
138
|
+
if (archive.envelopeCount !== undefined)
|
|
139
|
+
parts.push(`${archive.envelopeCount} events`);
|
|
140
|
+
if (archive.bytes !== undefined)
|
|
141
|
+
parts.push(formatBytes(archive.bytes));
|
|
142
|
+
if (archive.truncated)
|
|
143
|
+
parts.push('truncated');
|
|
144
|
+
else if (archive.clipped)
|
|
145
|
+
parts.push('some outputs clipped');
|
|
146
|
+
else if (archive.complete === false)
|
|
147
|
+
parts.push('incomplete');
|
|
148
|
+
}
|
|
149
|
+
else if (transcript.compactedBytes !== undefined) {
|
|
150
|
+
parts.push(formatBytes(transcript.compactedBytes));
|
|
151
|
+
}
|
|
152
|
+
for (const loss of transcript.losses ?? []) {
|
|
153
|
+
const classes = loss.classes.length ? loss.classes.join(', ') : 'events';
|
|
154
|
+
parts.push(`lost ${classes} (${loss.reason})`);
|
|
155
|
+
}
|
|
156
|
+
return parts.join(', ');
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Who wrote a row the person did not type, in the words the web view uses. Exhaustive, so a new
|
|
160
|
+
* origin in the contract fails to compile here until it has a label.
|
|
161
|
+
*/
|
|
162
|
+
const USER_MESSAGE_ORIGIN_LABELS = {
|
|
163
|
+
widget: 'sent by a widget on your click',
|
|
164
|
+
task_start: "the Task's instructions, sent when it was started",
|
|
165
|
+
recovery: 'sent automatically to continue an interrupted turn',
|
|
166
|
+
heartbeat: 'heartbeat check-in, sent automatically',
|
|
167
|
+
subagent: 'sent by the Agent that delegated this work',
|
|
168
|
+
activity: 'sent automatically for new group or Space activity',
|
|
169
|
+
automatic: 'sent automatically',
|
|
170
|
+
};
|
|
171
|
+
function userMessageLines(item) {
|
|
172
|
+
const marks = [
|
|
173
|
+
item.steeredInto ? `steered into turn ${item.steeredInto}` : null,
|
|
174
|
+
item.hidden ? 'hidden in Main Chat' : null,
|
|
175
|
+
item.files?.length ? `${item.files.length} file(s)` : null,
|
|
176
|
+
].filter(Boolean);
|
|
177
|
+
// A row a widget, the platform or another Agent wrote is not the person speaking.
|
|
178
|
+
const who = item.origin ? `[${USER_MESSAGE_ORIGIN_LABELS[item.origin]}]` : 'you';
|
|
179
|
+
const other = (item.importedBlocks ?? []).filter((block) => block.kind !== 'text').length;
|
|
180
|
+
if (other)
|
|
181
|
+
marks.push(`${other} other block(s)`);
|
|
182
|
+
const lines = [`${stamp(item.createdAt)}${who}${marks.length ? ` (${marks.join('; ')})` : ''}`];
|
|
183
|
+
const text = clip(oneLine(item.text), TEXT_CLIP);
|
|
184
|
+
if (text)
|
|
185
|
+
lines.push(` ${text}`);
|
|
186
|
+
return lines;
|
|
187
|
+
}
|
|
188
|
+
function turnLines(item) {
|
|
189
|
+
const lines = [];
|
|
190
|
+
const boundary = boundaryLine(item);
|
|
191
|
+
if (boundary)
|
|
192
|
+
lines.push(boundary);
|
|
193
|
+
let status = 'finished';
|
|
194
|
+
if (item.unfinished)
|
|
195
|
+
status = 'running';
|
|
196
|
+
if (item.failure)
|
|
197
|
+
status = 'failed';
|
|
198
|
+
// An imported session records no turn state; a continuation's is its receipt's.
|
|
199
|
+
if (item.localSession)
|
|
200
|
+
status = item.localSession.continuation ? 'continuation' : 'imported';
|
|
201
|
+
const duration = item.unfinished ? null : formatDuration(item.usage?.durationMs);
|
|
202
|
+
let who = item.agentId ? `agent ${item.agentId}` : 'agent';
|
|
203
|
+
if (item.localSession)
|
|
204
|
+
who = item.localSession.provider;
|
|
205
|
+
lines.push(`${stamp(item.createdAt)}turn ${item.messageId} ${who} ${status}${duration ? ` in ${duration}` : ''}`);
|
|
206
|
+
if (item.failure) {
|
|
207
|
+
const type = item.failure.type ? ` (${item.failure.type})` : '';
|
|
208
|
+
lines.push(` failed: ${item.failure.reason ?? 'no reason was recorded'}${type}`);
|
|
209
|
+
}
|
|
210
|
+
const reply = clip(oneLine(item.text ?? ''), TEXT_CLIP);
|
|
211
|
+
if (reply)
|
|
212
|
+
lines.push(` reply: ${reply}`);
|
|
213
|
+
const continuation = item.localSession?.continuation;
|
|
214
|
+
if (continuation) {
|
|
215
|
+
const reason = continuation.reason ? ` (${continuation.reason})` : '';
|
|
216
|
+
lines.push(` continuation: ${exports.CONTINUATION_STATE_WORDS[continuation.state] ?? continuation.state}${reason}`);
|
|
217
|
+
if (continuation.liveOutput) {
|
|
218
|
+
lines.push(` live preview: ${clip(oneLine(continuation.liveOutput.text), TEXT_CLIP)}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
lines.push(` process: ${processSummary(item)}`);
|
|
222
|
+
const usage = usageSummary(item.usage);
|
|
223
|
+
if (usage)
|
|
224
|
+
lines.push(` usage: ${usage}`);
|
|
225
|
+
// An imported turn is one stretch of the source's own session, which records no lineage.
|
|
226
|
+
if (!item.localSession)
|
|
227
|
+
lines.push(` context: ${describeContext(item)}`);
|
|
228
|
+
return lines;
|
|
229
|
+
}
|
|
230
|
+
function agentMessageLines(item) {
|
|
231
|
+
const who = item.agentId ? `agent ${item.agentId}` : 'agent';
|
|
232
|
+
const marks = [
|
|
233
|
+
item.turn
|
|
234
|
+
? `sent during turn ${item.turn.messageId}${item.turn.seq !== undefined ? ` at step ${item.turn.seq}` : ''}${item.turn.sentDuring === 'grace' ? ', just after it ended' : ''}`
|
|
235
|
+
: 'sent on its own',
|
|
236
|
+
item.retracted ? 'retracted' : null,
|
|
237
|
+
].filter(Boolean);
|
|
238
|
+
const lines = [`${when(item.createdAt)} ${who} → you (${marks.join('; ')})`];
|
|
239
|
+
const text = clip(oneLine(item.text), TEXT_CLIP);
|
|
240
|
+
if (text)
|
|
241
|
+
lines.push(` ${text}`);
|
|
242
|
+
return lines;
|
|
243
|
+
}
|
|
244
|
+
/** The lines `skrr convos transcript` prints for one item. */
|
|
245
|
+
function formatTranscriptItem(item) {
|
|
246
|
+
switch (item.kind) {
|
|
247
|
+
case 'user_message':
|
|
248
|
+
return userMessageLines(item);
|
|
249
|
+
case 'turn':
|
|
250
|
+
return turnLines(item);
|
|
251
|
+
case 'agent_message':
|
|
252
|
+
return agentMessageLines(item);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function envelopeSummary(envelope) {
|
|
256
|
+
const ev = envelope.ev;
|
|
257
|
+
const kind = typeof ev?.t === 'string' ? ev.t : 'event';
|
|
258
|
+
const text = (value) => clip(oneLine(typeof value === 'string' ? value : ''), ENVELOPE_CLIP);
|
|
259
|
+
switch (kind) {
|
|
260
|
+
case 'text':
|
|
261
|
+
return `${ev.thinking ? 'thinking' : 'text'}: ${text(ev.text)}`;
|
|
262
|
+
case 'service':
|
|
263
|
+
return `service: ${text(ev.text)}`;
|
|
264
|
+
case 'steer':
|
|
265
|
+
return `steer: ${text(ev.text)}`;
|
|
266
|
+
case 'tool-call-start':
|
|
267
|
+
return `tool ${String(ev.name ?? '')}: ${text(ev.title || ev.description)}`;
|
|
268
|
+
case 'tool-call-end':
|
|
269
|
+
return `tool done${ev.status ? ` (${String(ev.status)})` : ''}`;
|
|
270
|
+
case 'turn-end':
|
|
271
|
+
return `turn end: ${String(ev.status ?? '')}`;
|
|
272
|
+
default:
|
|
273
|
+
return kind;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/** The lines printed for one turn's whole body. */
|
|
277
|
+
/** One imported event's blocks in a line: its text, tool calls and results as the source stored them. */
|
|
278
|
+
function importedEventSummary(event) {
|
|
279
|
+
return event.blocks
|
|
280
|
+
.map((block) => {
|
|
281
|
+
if (block.kind === 'text')
|
|
282
|
+
return block.text;
|
|
283
|
+
if (block.kind === 'tool_call')
|
|
284
|
+
return `tool ${block.name}: ${block.input}`;
|
|
285
|
+
if (block.kind === 'tool_result') {
|
|
286
|
+
return `${block.failed ? 'tool error' : 'tool output'}: ${block.text}`;
|
|
287
|
+
}
|
|
288
|
+
return `(${block.sourceType}, not shown)`;
|
|
289
|
+
})
|
|
290
|
+
.join(' ');
|
|
291
|
+
}
|
|
292
|
+
function formatTurnBody(body) {
|
|
293
|
+
const lines = [
|
|
294
|
+
`turn ${body.messageId} process: ${exports.TRANSCRIPT_SOURCE_WORDS[body.source]}, ${body.total} ${body.source === 'content' ? 'content part(s)' : 'event(s)'}`,
|
|
295
|
+
];
|
|
296
|
+
const archive = body.archive;
|
|
297
|
+
if (archive) {
|
|
298
|
+
const notes = [
|
|
299
|
+
archive.complete ? 'complete' : 'incomplete',
|
|
300
|
+
archive.truncated
|
|
301
|
+
? `truncated: ${archive.droppedEnvelopes} event(s), ${formatBytes(archive.droppedBytes)} dropped`
|
|
302
|
+
: null,
|
|
303
|
+
archive.clips.length ? `${archive.clips.length} output(s) clipped` : null,
|
|
304
|
+
].filter(Boolean);
|
|
305
|
+
lines.push(` archive: ${notes.join('; ')}`);
|
|
306
|
+
}
|
|
307
|
+
for (const loss of body.losses ?? []) {
|
|
308
|
+
const range = loss.fromSeq !== undefined ? ` (steps ${loss.fromSeq}–${loss.toSeq ?? loss.fromSeq})` : '';
|
|
309
|
+
lines.push(` lost: ${loss.classes.join(', ') || 'events'}, ${loss.reason}${range}`);
|
|
310
|
+
}
|
|
311
|
+
for (const envelope of body.envelopes ?? []) {
|
|
312
|
+
const seq = envelope.__seq;
|
|
313
|
+
lines.push(` ${seq !== undefined ? `#${seq} ` : ''}${envelope.role} ${envelopeSummary(envelope)}`);
|
|
314
|
+
}
|
|
315
|
+
// An imported turn's events, numbered by their place in the turn (the page's offset counts).
|
|
316
|
+
for (const [index, event] of (body.events ?? []).entries()) {
|
|
317
|
+
lines.push(` #${body.offset + index + 1} ${event.role} ${clip(oneLine(importedEventSummary(event)), ENVELOPE_CLIP)}`);
|
|
318
|
+
}
|
|
319
|
+
for (const part of body.content ?? []) {
|
|
320
|
+
const record = (part ?? {});
|
|
321
|
+
const type = typeof record.type === 'string' ? record.type : 'part';
|
|
322
|
+
const text = typeof record.text === 'string' ? `: ${clip(oneLine(record.text), ENVELOPE_CLIP)}` : '';
|
|
323
|
+
lines.push(` ${type}${text}`);
|
|
324
|
+
}
|
|
325
|
+
if (body.source === 'live') {
|
|
326
|
+
lines.push(` (still running: this is what ${data_provider_1.BRAND.displayName} holds so far)`);
|
|
327
|
+
}
|
|
328
|
+
return lines;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* `skrr convos transcript` — a conversation's whole session, as a conversation (G11, D12).
|
|
332
|
+
*
|
|
333
|
+
* The same items Session Details shows: the person's messages (follow-ups and steers included,
|
|
334
|
+
* and those Main Chat hides), each turn with where its process is kept, and every message the
|
|
335
|
+
* agent sent. A line marks each place the harness context did not continue. `--turn` prints one
|
|
336
|
+
* turn's whole process, paging through it.
|
|
337
|
+
*/
|
|
338
|
+
class ConvosTranscript extends base_command_1.BaseCommand {
|
|
339
|
+
static description = "Read a conversation's whole session: messages, turns and the agent's messages";
|
|
340
|
+
static examples = [
|
|
341
|
+
'<%= config.bin %> convos transcript <conversationId>',
|
|
342
|
+
'<%= config.bin %> convos transcript <conversationId> --limit 20 --cursor <nextCursor>',
|
|
343
|
+
'<%= config.bin %> convos transcript <conversationId> --around latest --limit 20',
|
|
344
|
+
'<%= config.bin %> convos transcript <conversationId> --around <messageId>',
|
|
345
|
+
'<%= config.bin %> convos transcript <conversationId> --turn <messageId>',
|
|
346
|
+
'<%= config.bin %> convos transcript <conversationId> --json',
|
|
347
|
+
];
|
|
348
|
+
static args = {
|
|
349
|
+
id: core_1.Args.string({ description: 'Conversation ID', required: true, ignoreStdin: true }),
|
|
350
|
+
};
|
|
351
|
+
static flags = {
|
|
352
|
+
json: core_1.Flags.boolean({ description: 'Print the API response as JSON' }),
|
|
353
|
+
turn: core_1.Flags.string({ description: "Print one turn's whole process (the turn's messageId)" }),
|
|
354
|
+
limit: core_1.Flags.integer({
|
|
355
|
+
description: `Items per page (1-${data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems}). Omit to read the whole session.`,
|
|
356
|
+
}),
|
|
357
|
+
cursor: core_1.Flags.string({
|
|
358
|
+
description: "Cursor from a previous page's nextCursor (newer) or prevCursor (older)",
|
|
359
|
+
exclusive: ['around'],
|
|
360
|
+
}),
|
|
361
|
+
around: core_1.Flags.string({
|
|
362
|
+
description: 'Read one page around an item: `latest` for the newest page, or an item messageId',
|
|
363
|
+
exclusive: ['cursor'],
|
|
364
|
+
}),
|
|
365
|
+
};
|
|
366
|
+
async run() {
|
|
367
|
+
this.requireAuth();
|
|
368
|
+
const { args, flags } = await this.parse(ConvosTranscript);
|
|
369
|
+
if (flags.turn) {
|
|
370
|
+
await this.printTurn(args.id, flags.turn, flags.json);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (flags.limit !== undefined &&
|
|
374
|
+
(flags.limit < 1 || flags.limit > data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems)) {
|
|
375
|
+
this.error(`--limit must be between 1 and ${data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems}.`);
|
|
376
|
+
}
|
|
377
|
+
// Without --limit or --around, read on (newer) to the end; otherwise one page.
|
|
378
|
+
const readOn = flags.limit === undefined && flags.around === undefined;
|
|
379
|
+
const pages = [];
|
|
380
|
+
let params = {
|
|
381
|
+
...(flags.around ? { around: flags.around } : { cursor: flags.cursor ?? null }),
|
|
382
|
+
limit: flags.limit ?? data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems,
|
|
383
|
+
};
|
|
384
|
+
try {
|
|
385
|
+
for (;;) {
|
|
386
|
+
const page = await data_provider_1.dataService.getConversationTranscript(args.id, params);
|
|
387
|
+
pages.push(page);
|
|
388
|
+
if (!readOn || !page.nextCursor)
|
|
389
|
+
break;
|
|
390
|
+
params = { cursor: page.nextCursor, limit: params.limit };
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
this.handleApiError(err);
|
|
395
|
+
}
|
|
396
|
+
const first = pages[0];
|
|
397
|
+
const last = pages[pages.length - 1];
|
|
398
|
+
const result = {
|
|
399
|
+
conversationId: last?.conversationId ?? args.id,
|
|
400
|
+
items: pages.flatMap((page) => page.items),
|
|
401
|
+
nextCursor: last?.nextCursor ?? null,
|
|
402
|
+
prevCursor: first?.prevCursor ?? null,
|
|
403
|
+
...(last?.previousConversationId !== undefined
|
|
404
|
+
? { previousConversationId: last.previousConversationId }
|
|
405
|
+
: {}),
|
|
406
|
+
};
|
|
407
|
+
if (flags.json) {
|
|
408
|
+
this.log(JSON.stringify(result, null, 2));
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (result.items.length === 0) {
|
|
412
|
+
this.log('Nothing in this session yet.');
|
|
413
|
+
}
|
|
414
|
+
for (const item of result.items) {
|
|
415
|
+
for (const line of formatTranscriptItem(item))
|
|
416
|
+
this.log(line);
|
|
417
|
+
}
|
|
418
|
+
const turns = result.items.filter((item) => item.kind === 'turn').length;
|
|
419
|
+
this.log(`\n${result.items.length} item(s), ${turns} turn(s)`);
|
|
420
|
+
if (result.prevCursor)
|
|
421
|
+
this.log(`older: --cursor ${result.prevCursor}`);
|
|
422
|
+
if (result.nextCursor)
|
|
423
|
+
this.log(`newer: --cursor ${result.nextCursor}`);
|
|
424
|
+
if (result.previousConversationId) {
|
|
425
|
+
this.log(`earlier in this chat: skrr convos transcript ${result.previousConversationId}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
async printTurn(conversationId, messageId, json) {
|
|
429
|
+
const pages = [];
|
|
430
|
+
let offset = 0;
|
|
431
|
+
try {
|
|
432
|
+
while (offset !== null) {
|
|
433
|
+
const page = await data_provider_1.dataService.getConversationTranscriptTurn(conversationId, messageId, {
|
|
434
|
+
offset,
|
|
435
|
+
limit: data_provider_1.TURN_TRANSCRIPT_LIMITS.turnPageMaxEnvelopes,
|
|
436
|
+
});
|
|
437
|
+
pages.push(page);
|
|
438
|
+
offset = page.nextOffset !== null && page.nextOffset > offset ? page.nextOffset : null;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
catch (err) {
|
|
442
|
+
this.handleApiError(err);
|
|
443
|
+
}
|
|
444
|
+
const first = pages[0];
|
|
445
|
+
const body = {
|
|
446
|
+
...first,
|
|
447
|
+
offset: 0,
|
|
448
|
+
nextOffset: null,
|
|
449
|
+
...(first.envelopes ? { envelopes: pages.flatMap((page) => page.envelopes ?? []) } : {}),
|
|
450
|
+
...(first.content ? { content: pages.flatMap((page) => page.content ?? []) } : {}),
|
|
451
|
+
...(first.events ? { events: pages.flatMap((page) => page.events ?? []) } : {}),
|
|
452
|
+
};
|
|
453
|
+
if (json) {
|
|
454
|
+
this.log(JSON.stringify(body, null, 2));
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
for (const line of formatTurnBody(body))
|
|
458
|
+
this.log(line);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
exports.default = ConvosTranscript;
|
|
@@ -329,43 +329,44 @@ declare const ENGINE_ENV_SUFFIXES: Readonly<{
|
|
|
329
329
|
sessionId: "SESSION_ID";
|
|
330
330
|
}>;
|
|
331
331
|
export type FirstPartyHarnessEngineEnvKey = keyof typeof ENGINE_ENV_SUFFIXES;
|
|
332
|
-
|
|
333
|
-
* Names the ENGINE itself defines and reads. The platform sets or reads them
|
|
334
|
-
* across the daemon↔engine boundary, so they are recorded here as values rather
|
|
335
|
-
* than scattered as literals. They are the fork's names, and moving one is a
|
|
336
|
-
* two-sided change: the engine reads the new name first and every legacy name
|
|
337
|
-
* second, and while engine and platform releases can arrive in either order the
|
|
338
|
-
* platform SETS every name and READS new-then-legacy (contract §6, OSK-8674).
|
|
339
|
-
*/
|
|
340
|
-
export declare const FIRST_PARTY_HARNESS_ENGINE: Readonly<{
|
|
332
|
+
interface FirstPartyHarnessEngineNamespace {
|
|
341
333
|
/**
|
|
342
334
|
* The engine's state namespace: XDG dirs, project marker, config basename, and
|
|
343
335
|
* the engine home under the skrr root (`firstPartyHarnessHomeDirname`).
|
|
344
336
|
*/
|
|
345
|
-
appName: string;
|
|
337
|
+
readonly appName: string;
|
|
346
338
|
/**
|
|
347
339
|
* Earlier `appName`s, newest first. `migrateFirstPartyHarnessHome` moves a home
|
|
348
340
|
* under one of them onto the current name and leaves a symlink; readers of
|
|
349
341
|
* engine state look under them after the current name.
|
|
350
342
|
*/
|
|
351
|
-
legacyAppNames: readonly string[];
|
|
343
|
+
readonly legacyAppNames: readonly string[];
|
|
352
344
|
/** Project-local configuration directory inside a user's repository. */
|
|
353
|
-
projectDirectory: `.${string}`;
|
|
345
|
+
readonly projectDirectory: `.${string}`;
|
|
354
346
|
/**
|
|
355
347
|
* Earlier project directories, newest first. The engine still reads them and
|
|
356
348
|
* the platform never rewrites a user's repository to move one, so a reader
|
|
357
349
|
* looks here after `projectDirectory`, and a writer adopts an existing file
|
|
358
350
|
* here rather than creating a second one beside it.
|
|
359
351
|
*/
|
|
360
|
-
legacyProjectDirectories: readonly string[];
|
|
352
|
+
readonly legacyProjectDirectories: readonly string[];
|
|
361
353
|
/**
|
|
362
354
|
* Environment variables the engine reads, under the CURRENT namespace. The
|
|
363
355
|
* engine also reads each one under every legacy namespace, second — use
|
|
364
356
|
* `readFirstPartyHarnessEngineEnv` to read one the way the engine does and
|
|
365
357
|
* `firstPartyHarnessEngineEnvEntries` to set one every engine build honours.
|
|
366
358
|
*/
|
|
367
|
-
env: Readonly<Record<
|
|
368
|
-
}
|
|
359
|
+
readonly env: Readonly<Record<FirstPartyHarnessEngineEnvKey, string>>;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Names the ENGINE itself defines and reads. The platform sets or reads them
|
|
363
|
+
* across the daemon↔engine boundary, so they are recorded here as values rather
|
|
364
|
+
* than scattered as literals. They are the fork's names, and moving one is a
|
|
365
|
+
* two-sided change: the engine reads the new name first and every legacy name
|
|
366
|
+
* second, and while engine and platform releases can arrive in either order the
|
|
367
|
+
* platform SETS every name and READS new-then-legacy (contract §6, OSK-8674).
|
|
368
|
+
*/
|
|
369
|
+
export declare const FIRST_PARTY_HARNESS_ENGINE: FirstPartyHarnessEngineNamespace;
|
|
369
370
|
/**
|
|
370
371
|
* Every name the engine reads for one purpose, current namespace first — the
|
|
371
372
|
* engine's own lookup order.
|
|
@@ -297,32 +297,10 @@ function defineEngineNamespace(appName, legacyAppNames) {
|
|
|
297
297
|
throw new Error("first-party harness engine appName and legacyAppNames must be distinct");
|
|
298
298
|
}
|
|
299
299
|
return Object.freeze({
|
|
300
|
-
/**
|
|
301
|
-
* The engine's state namespace: XDG dirs, project marker, config basename, and
|
|
302
|
-
* the engine home under the skrr root (`firstPartyHarnessHomeDirname`).
|
|
303
|
-
*/
|
|
304
300
|
appName,
|
|
305
|
-
/**
|
|
306
|
-
* Earlier `appName`s, newest first. `migrateFirstPartyHarnessHome` moves a home
|
|
307
|
-
* under one of them onto the current name and leaves a symlink; readers of
|
|
308
|
-
* engine state look under them after the current name.
|
|
309
|
-
*/
|
|
310
301
|
legacyAppNames: Object.freeze([...legacyAppNames]),
|
|
311
|
-
/** Project-local configuration directory inside a user's repository. */
|
|
312
302
|
projectDirectory: `.${appName}`,
|
|
313
|
-
/**
|
|
314
|
-
* Earlier project directories, newest first. The engine still reads them and
|
|
315
|
-
* the platform never rewrites a user's repository to move one, so a reader
|
|
316
|
-
* looks here after `projectDirectory`, and a writer adopts an existing file
|
|
317
|
-
* here rather than creating a second one beside it.
|
|
318
|
-
*/
|
|
319
303
|
legacyProjectDirectories: Object.freeze(legacyAppNames.map((name) => `.${name}`)),
|
|
320
|
-
/**
|
|
321
|
-
* Environment variables the engine reads, under the CURRENT namespace. The
|
|
322
|
-
* engine also reads each one under every legacy namespace, second — use
|
|
323
|
-
* `readFirstPartyHarnessEngineEnv` to read one the way the engine does and
|
|
324
|
-
* `firstPartyHarnessEngineEnvEntries` to set one every engine build honours.
|
|
325
|
-
*/
|
|
326
304
|
env: engineEnvTable(appName)
|
|
327
305
|
});
|
|
328
306
|
}
|
|
@@ -329,43 +329,44 @@ declare const ENGINE_ENV_SUFFIXES: Readonly<{
|
|
|
329
329
|
sessionId: "SESSION_ID";
|
|
330
330
|
}>;
|
|
331
331
|
export type FirstPartyHarnessEngineEnvKey = keyof typeof ENGINE_ENV_SUFFIXES;
|
|
332
|
-
|
|
333
|
-
* Names the ENGINE itself defines and reads. The platform sets or reads them
|
|
334
|
-
* across the daemon↔engine boundary, so they are recorded here as values rather
|
|
335
|
-
* than scattered as literals. They are the fork's names, and moving one is a
|
|
336
|
-
* two-sided change: the engine reads the new name first and every legacy name
|
|
337
|
-
* second, and while engine and platform releases can arrive in either order the
|
|
338
|
-
* platform SETS every name and READS new-then-legacy (contract §6, OSK-8674).
|
|
339
|
-
*/
|
|
340
|
-
export declare const FIRST_PARTY_HARNESS_ENGINE: Readonly<{
|
|
332
|
+
interface FirstPartyHarnessEngineNamespace {
|
|
341
333
|
/**
|
|
342
334
|
* The engine's state namespace: XDG dirs, project marker, config basename, and
|
|
343
335
|
* the engine home under the skrr root (`firstPartyHarnessHomeDirname`).
|
|
344
336
|
*/
|
|
345
|
-
appName: string;
|
|
337
|
+
readonly appName: string;
|
|
346
338
|
/**
|
|
347
339
|
* Earlier `appName`s, newest first. `migrateFirstPartyHarnessHome` moves a home
|
|
348
340
|
* under one of them onto the current name and leaves a symlink; readers of
|
|
349
341
|
* engine state look under them after the current name.
|
|
350
342
|
*/
|
|
351
|
-
legacyAppNames: readonly string[];
|
|
343
|
+
readonly legacyAppNames: readonly string[];
|
|
352
344
|
/** Project-local configuration directory inside a user's repository. */
|
|
353
|
-
projectDirectory: `.${string}`;
|
|
345
|
+
readonly projectDirectory: `.${string}`;
|
|
354
346
|
/**
|
|
355
347
|
* Earlier project directories, newest first. The engine still reads them and
|
|
356
348
|
* the platform never rewrites a user's repository to move one, so a reader
|
|
357
349
|
* looks here after `projectDirectory`, and a writer adopts an existing file
|
|
358
350
|
* here rather than creating a second one beside it.
|
|
359
351
|
*/
|
|
360
|
-
legacyProjectDirectories: readonly string[];
|
|
352
|
+
readonly legacyProjectDirectories: readonly string[];
|
|
361
353
|
/**
|
|
362
354
|
* Environment variables the engine reads, under the CURRENT namespace. The
|
|
363
355
|
* engine also reads each one under every legacy namespace, second — use
|
|
364
356
|
* `readFirstPartyHarnessEngineEnv` to read one the way the engine does and
|
|
365
357
|
* `firstPartyHarnessEngineEnvEntries` to set one every engine build honours.
|
|
366
358
|
*/
|
|
367
|
-
env: Readonly<Record<
|
|
368
|
-
}
|
|
359
|
+
readonly env: Readonly<Record<FirstPartyHarnessEngineEnvKey, string>>;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Names the ENGINE itself defines and reads. The platform sets or reads them
|
|
363
|
+
* across the daemon↔engine boundary, so they are recorded here as values rather
|
|
364
|
+
* than scattered as literals. They are the fork's names, and moving one is a
|
|
365
|
+
* two-sided change: the engine reads the new name first and every legacy name
|
|
366
|
+
* second, and while engine and platform releases can arrive in either order the
|
|
367
|
+
* platform SETS every name and READS new-then-legacy (contract §6, OSK-8674).
|
|
368
|
+
*/
|
|
369
|
+
export declare const FIRST_PARTY_HARNESS_ENGINE: FirstPartyHarnessEngineNamespace;
|
|
369
370
|
/**
|
|
370
371
|
* Every name the engine reads for one purpose, current namespace first — the
|
|
371
372
|
* engine's own lookup order.
|
|
@@ -457,32 +457,10 @@ function defineEngineNamespace(appName, legacyAppNames) {
|
|
|
457
457
|
throw new Error('first-party harness engine appName and legacyAppNames must be distinct');
|
|
458
458
|
}
|
|
459
459
|
return Object.freeze({
|
|
460
|
-
/**
|
|
461
|
-
* The engine's state namespace: XDG dirs, project marker, config basename, and
|
|
462
|
-
* the engine home under the skrr root (`firstPartyHarnessHomeDirname`).
|
|
463
|
-
*/
|
|
464
460
|
appName,
|
|
465
|
-
/**
|
|
466
|
-
* Earlier `appName`s, newest first. `migrateFirstPartyHarnessHome` moves a home
|
|
467
|
-
* under one of them onto the current name and leaves a symlink; readers of
|
|
468
|
-
* engine state look under them after the current name.
|
|
469
|
-
*/
|
|
470
461
|
legacyAppNames: Object.freeze([...legacyAppNames]),
|
|
471
|
-
/** Project-local configuration directory inside a user's repository. */
|
|
472
462
|
projectDirectory: `.${appName}`,
|
|
473
|
-
/**
|
|
474
|
-
* Earlier project directories, newest first. The engine still reads them and
|
|
475
|
-
* the platform never rewrites a user's repository to move one, so a reader
|
|
476
|
-
* looks here after `projectDirectory`, and a writer adopts an existing file
|
|
477
|
-
* here rather than creating a second one beside it.
|
|
478
|
-
*/
|
|
479
463
|
legacyProjectDirectories: Object.freeze(legacyAppNames.map((name) => `.${name}`)),
|
|
480
|
-
/**
|
|
481
|
-
* Environment variables the engine reads, under the CURRENT namespace. The
|
|
482
|
-
* engine also reads each one under every legacy namespace, second — use
|
|
483
|
-
* `readFirstPartyHarnessEngineEnv` to read one the way the engine does and
|
|
484
|
-
* `firstPartyHarnessEngineEnvEntries` to set one every engine build honours.
|
|
485
|
-
*/
|
|
486
464
|
env: engineEnvTable(appName),
|
|
487
465
|
});
|
|
488
466
|
}
|