@skrr-ai/cli 0.1.204 → 0.1.207

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.
Files changed (55) hide show
  1. package/bin/dev-fallback.js +47 -29
  2. package/bin/dev.cjs +6 -0
  3. package/dist/commands/agent/message/send.d.ts +7 -1
  4. package/dist/commands/agent/message/send.js +13 -0
  5. package/dist/commands/agents/models.d.ts +11 -0
  6. package/dist/commands/agents/models.js +51 -0
  7. package/dist/commands/balance/route-premiums.d.ts +9 -0
  8. package/dist/commands/balance/route-premiums.js +33 -0
  9. package/dist/commands/convos/transcript.d.ts +47 -0
  10. package/dist/commands/convos/transcript.js +460 -0
  11. package/dist/commands/goals/create.d.ts +1 -0
  12. package/dist/commands/goals/create.js +8 -0
  13. package/dist/commands/goals/creation-receipt.d.ts +10 -0
  14. package/dist/commands/goals/creation-receipt.js +43 -0
  15. package/dist/commands/goals/key-results/create.d.ts +2 -0
  16. package/dist/commands/goals/key-results/create.js +14 -0
  17. package/dist/commands/goals/key-results/creation-receipt.d.ts +13 -0
  18. package/dist/commands/goals/key-results/creation-receipt.js +51 -0
  19. package/dist/commands/harnesses/forget.d.ts +2 -0
  20. package/dist/commands/harnesses/forget.js +31 -0
  21. package/dist/commands/harnesses/removal-receipt.d.ts +11 -0
  22. package/dist/commands/harnesses/removal-receipt.js +32 -0
  23. package/dist/commands/harnesses/removal-review.d.ts +11 -0
  24. package/dist/commands/harnesses/removal-review.js +28 -0
  25. package/dist/commands/spaces/loops/release-receipt.d.ts +14 -0
  26. package/dist/commands/spaces/loops/release-receipt.js +48 -0
  27. package/dist/commands/spaces/loops/release.js +1 -1
  28. package/dist/commands/spaces/workflow-templates/archive.d.ts +1 -0
  29. package/dist/commands/spaces/workflow-templates/archive.js +9 -1
  30. package/dist/commands/spaces/workflow-templates/show.js +2 -0
  31. package/dist/commands/spaces/workflow-templates/update.d.ts +1 -0
  32. package/dist/commands/spaces/workflow-templates/update.js +12 -1
  33. package/dist/commands/spaces/workflows/publish.d.ts +1 -0
  34. package/dist/commands/spaces/workflows/publish.js +41 -2
  35. package/dist/commands/tasks/create.d.ts +2 -0
  36. package/dist/commands/tasks/create.js +19 -6
  37. package/dist/commands/tasks/creation-receipt.d.ts +12 -0
  38. package/dist/commands/tasks/creation-receipt.js +53 -0
  39. package/dist/commands/tasks/delete.d.ts +1 -0
  40. package/dist/commands/tasks/delete.js +22 -4
  41. package/dist/commands/tasks/deletion-receipt.d.ts +12 -0
  42. package/dist/commands/tasks/deletion-receipt.js +37 -0
  43. package/dist/lib/execution-target.d.ts +1 -1
  44. package/dist/lib/execution-target.js +4 -0
  45. package/dist/lib/harnesses.d.ts +25 -0
  46. package/dist/lib/harnesses.js +15 -0
  47. package/dist/lib/request-uuid.d.ts +2 -0
  48. package/dist/lib/request-uuid.js +10 -0
  49. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.d.ts +16 -15
  50. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.js +0 -22
  51. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.d.ts +16 -15
  52. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.js +0 -22
  53. package/dist/node_modules/@skrr-ai/data-provider/index.js +11498 -11396
  54. package/oclif.manifest.json +915 -2
  55. package/package.json +6 -3
@@ -0,0 +1,460 @@
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
+ */
43
+ exports.CONTINUATION_STATE_WORDS = {
44
+ preparing: 'sent from here, still being prepared',
45
+ unknown: 'sent from here, outcome not confirmed',
46
+ settled: 'sent from here, ended on the source computer',
47
+ not_submitted: 'sent from here, not submitted',
48
+ };
49
+ const oneLine = (text) => text.replace(WHITESPACE_RE, ' ').trim();
50
+ const clip = (text, max) => (text.length > max ? `${text.slice(0, max)}…` : text);
51
+ const when = (value) => {
52
+ if (!value)
53
+ return '';
54
+ const date = new Date(value);
55
+ return Number.isNaN(date.getTime()) ? value : date.toISOString();
56
+ };
57
+ /** A row's time and the gap after it, or nothing: an imported event may record no time. */
58
+ const stamp = (value) => (value ? `${when(value)} ` : '');
59
+ function formatBytes(bytes) {
60
+ if (bytes < 1024)
61
+ return `${bytes} B`;
62
+ if (bytes < 1024 * 1024)
63
+ return `${(bytes / 1024).toFixed(1)} KiB`;
64
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
65
+ }
66
+ /**
67
+ * A recorded duration in words. Only `usage.durationMs` is one: a row's `updatedAt` moves with
68
+ * any later write to it (an archive pointer, a retraction), so it is not when the turn ended.
69
+ */
70
+ function formatDuration(ms) {
71
+ if (ms === undefined || !Number.isFinite(ms) || ms < 0)
72
+ return null;
73
+ if (ms < 1000)
74
+ return `${ms}ms`;
75
+ const seconds = Math.round(ms / 1000);
76
+ if (seconds < 60)
77
+ return `${seconds}s`;
78
+ const minutes = Math.floor(seconds / 60);
79
+ return `${minutes}m${String(seconds % 60).padStart(2, '0')}s`;
80
+ }
81
+ /** Whether the harness context continued into this turn, in words. Never guesses "continued". */
82
+ function describeContext(turn) {
83
+ const lineage = turn.contextLineage;
84
+ if (!lineage)
85
+ return 'not recorded';
86
+ if (lineage.continued)
87
+ return 'continued';
88
+ return lineage.breakReason
89
+ ? `new session: ${exports.CONTEXT_BREAK_WORDS[lineage.breakReason]}`
90
+ : 'new session: no reason was recorded';
91
+ }
92
+ /** The line drawn above a turn whose harness context did not continue, or null. */
93
+ function boundaryLine(turn) {
94
+ if (turn.contextLineage?.continued !== false)
95
+ return null;
96
+ return `──── ${describeContext(turn)} ────`;
97
+ }
98
+ const COUNT_FORMAT = new Intl.NumberFormat('en-US');
99
+ /**
100
+ * What the turn recorded of its usage, in one line, or null when it recorded nothing. Only the
101
+ * fields the server sent: an absent one was not recorded and is not printed as zero.
102
+ */
103
+ function contextLine(usage) {
104
+ if (usage.contextTokens === undefined)
105
+ return null;
106
+ const window = usage.contextWindow !== undefined ? ` of ${COUNT_FORMAT.format(usage.contextWindow)}` : '';
107
+ return `${COUNT_FORMAT.format(usage.contextTokens)}${window} context`;
108
+ }
109
+ function usageSummary(usage) {
110
+ if (!usage)
111
+ return null;
112
+ const parts = [
113
+ usage.inputTokens !== undefined ? `${COUNT_FORMAT.format(usage.inputTokens)} in` : null,
114
+ usage.outputTokens !== undefined ? `${COUNT_FORMAT.format(usage.outputTokens)} out` : null,
115
+ usage.cacheReadTokens !== undefined
116
+ ? `${COUNT_FORMAT.format(usage.cacheReadTokens)} cache read`
117
+ : null,
118
+ usage.cacheWriteTokens !== undefined
119
+ ? `${COUNT_FORMAT.format(usage.cacheWriteTokens)} cache write`
120
+ : null,
121
+ usage.numTurns !== undefined ? `${usage.numTurns} model call(s)` : null,
122
+ contextLine(usage),
123
+ // The harness's running estimate for the whole session, never this turn's cost or a charge.
124
+ usage.sessionCostUsd !== undefined
125
+ ? `session cost so far $${usage.sessionCostUsd.toFixed(4)} (estimate)`
126
+ : null,
127
+ usage.model ?? null,
128
+ ].filter(Boolean);
129
+ return parts.length ? parts.join(', ') : null;
130
+ }
131
+ /** The turn's process in one line: where it is kept, how much, and what was lost. */
132
+ function processSummary(turn) {
133
+ const { transcript } = turn;
134
+ const parts = [exports.TRANSCRIPT_SOURCE_WORDS[transcript.source]];
135
+ const archive = transcript.archive;
136
+ if (archive) {
137
+ if (archive.envelopeCount !== undefined)
138
+ parts.push(`${archive.envelopeCount} events`);
139
+ if (archive.bytes !== undefined)
140
+ parts.push(formatBytes(archive.bytes));
141
+ if (archive.truncated)
142
+ parts.push('truncated');
143
+ else if (archive.clipped)
144
+ parts.push('some outputs clipped');
145
+ else if (archive.complete === false)
146
+ parts.push('incomplete');
147
+ }
148
+ else if (transcript.compactedBytes !== undefined) {
149
+ parts.push(formatBytes(transcript.compactedBytes));
150
+ }
151
+ for (const loss of transcript.losses ?? []) {
152
+ const classes = loss.classes.length ? loss.classes.join(', ') : 'events';
153
+ parts.push(`lost ${classes} (${loss.reason})`);
154
+ }
155
+ return parts.join(', ');
156
+ }
157
+ /**
158
+ * Who wrote a row the person did not type, in the words the web view uses. Exhaustive, so a new
159
+ * origin in the contract fails to compile here until it has a label.
160
+ */
161
+ const USER_MESSAGE_ORIGIN_LABELS = {
162
+ widget: 'sent by a widget on your click',
163
+ task_start: "the Task's instructions, sent when it was started",
164
+ recovery: 'sent automatically to continue an interrupted turn',
165
+ heartbeat: 'heartbeat check-in, sent automatically',
166
+ subagent: 'sent by the Agent that delegated this work',
167
+ activity: 'sent automatically for new group or Space activity',
168
+ automatic: 'sent automatically',
169
+ };
170
+ function userMessageLines(item) {
171
+ const marks = [
172
+ item.steeredInto ? `steered into turn ${item.steeredInto}` : null,
173
+ item.hidden ? 'hidden in Main Chat' : null,
174
+ item.files?.length ? `${item.files.length} file(s)` : null,
175
+ ].filter(Boolean);
176
+ // A row a widget, the platform or another Agent wrote is not the person speaking.
177
+ const who = item.origin ? `[${USER_MESSAGE_ORIGIN_LABELS[item.origin]}]` : 'you';
178
+ const other = (item.importedBlocks ?? []).filter((block) => block.kind !== 'text').length;
179
+ if (other)
180
+ marks.push(`${other} other block(s)`);
181
+ const lines = [`${stamp(item.createdAt)}${who}${marks.length ? ` (${marks.join('; ')})` : ''}`];
182
+ const text = clip(oneLine(item.text), TEXT_CLIP);
183
+ if (text)
184
+ lines.push(` ${text}`);
185
+ return lines;
186
+ }
187
+ function turnLines(item) {
188
+ const lines = [];
189
+ const boundary = boundaryLine(item);
190
+ if (boundary)
191
+ lines.push(boundary);
192
+ let status = 'finished';
193
+ if (item.unfinished)
194
+ status = 'running';
195
+ if (item.failure)
196
+ status = 'failed';
197
+ // An imported session records no turn state; a continuation's is its receipt's.
198
+ if (item.localSession)
199
+ status = item.localSession.continuation ? 'continuation' : 'imported';
200
+ const duration = item.unfinished ? null : formatDuration(item.usage?.durationMs);
201
+ let who = item.agentId ? `agent ${item.agentId}` : 'agent';
202
+ if (item.localSession)
203
+ who = item.localSession.provider;
204
+ lines.push(`${stamp(item.createdAt)}turn ${item.messageId} ${who} ${status}${duration ? ` in ${duration}` : ''}`);
205
+ if (item.failure) {
206
+ const type = item.failure.type ? ` (${item.failure.type})` : '';
207
+ lines.push(` failed: ${item.failure.reason ?? 'no reason was recorded'}${type}`);
208
+ }
209
+ const reply = clip(oneLine(item.text ?? ''), TEXT_CLIP);
210
+ if (reply)
211
+ lines.push(` reply: ${reply}`);
212
+ const continuation = item.localSession?.continuation;
213
+ if (continuation) {
214
+ const reason = continuation.reason ? ` (${continuation.reason})` : '';
215
+ lines.push(` continuation: ${exports.CONTINUATION_STATE_WORDS[continuation.state] ?? continuation.state}${reason}`);
216
+ if (continuation.liveOutput) {
217
+ lines.push(` live preview: ${clip(oneLine(continuation.liveOutput.text), TEXT_CLIP)}`);
218
+ }
219
+ }
220
+ lines.push(` process: ${processSummary(item)}`);
221
+ const usage = usageSummary(item.usage);
222
+ if (usage)
223
+ lines.push(` usage: ${usage}`);
224
+ // An imported turn is one stretch of the source's own session, which records no lineage.
225
+ if (!item.localSession)
226
+ lines.push(` context: ${describeContext(item)}`);
227
+ return lines;
228
+ }
229
+ function agentMessageLines(item) {
230
+ const who = item.agentId ? `agent ${item.agentId}` : 'agent';
231
+ const marks = [
232
+ item.turn
233
+ ? `sent during turn ${item.turn.messageId}${item.turn.seq !== undefined ? ` at step ${item.turn.seq}` : ''}${item.turn.sentDuring === 'grace' ? ', just after it ended' : ''}`
234
+ : 'sent on its own',
235
+ item.retracted ? 'retracted' : null,
236
+ ].filter(Boolean);
237
+ const lines = [`${when(item.createdAt)} ${who} → you (${marks.join('; ')})`];
238
+ const text = clip(oneLine(item.text), TEXT_CLIP);
239
+ if (text)
240
+ lines.push(` ${text}`);
241
+ return lines;
242
+ }
243
+ /** The lines `skrr convos transcript` prints for one item. */
244
+ function formatTranscriptItem(item) {
245
+ switch (item.kind) {
246
+ case 'user_message':
247
+ return userMessageLines(item);
248
+ case 'turn':
249
+ return turnLines(item);
250
+ case 'agent_message':
251
+ return agentMessageLines(item);
252
+ }
253
+ }
254
+ function envelopeSummary(envelope) {
255
+ const ev = envelope.ev;
256
+ const kind = typeof ev?.t === 'string' ? ev.t : 'event';
257
+ const text = (value) => clip(oneLine(typeof value === 'string' ? value : ''), ENVELOPE_CLIP);
258
+ switch (kind) {
259
+ case 'text':
260
+ return `${ev.thinking ? 'thinking' : 'text'}: ${text(ev.text)}`;
261
+ case 'service':
262
+ return `service: ${text(ev.text)}`;
263
+ case 'steer':
264
+ return `steer: ${text(ev.text)}`;
265
+ case 'tool-call-start':
266
+ return `tool ${String(ev.name ?? '')}: ${text(ev.title || ev.description)}`;
267
+ case 'tool-call-end':
268
+ return `tool done${ev.status ? ` (${String(ev.status)})` : ''}`;
269
+ case 'turn-end':
270
+ return `turn end: ${String(ev.status ?? '')}`;
271
+ default:
272
+ return kind;
273
+ }
274
+ }
275
+ /** The lines printed for one turn's whole body. */
276
+ /** One imported event's blocks in a line: its text, tool calls and results as the source stored them. */
277
+ function importedEventSummary(event) {
278
+ return event.blocks
279
+ .map((block) => {
280
+ if (block.kind === 'text')
281
+ return block.text;
282
+ if (block.kind === 'tool_call')
283
+ return `tool ${block.name}: ${block.input}`;
284
+ if (block.kind === 'tool_result') {
285
+ return `${block.failed ? 'tool error' : 'tool output'}: ${block.text}`;
286
+ }
287
+ return `(${block.sourceType}, not shown)`;
288
+ })
289
+ .join(' ');
290
+ }
291
+ function formatTurnBody(body) {
292
+ const lines = [
293
+ `turn ${body.messageId} process: ${exports.TRANSCRIPT_SOURCE_WORDS[body.source]}, ${body.total} ${body.source === 'content' ? 'content part(s)' : 'event(s)'}`,
294
+ ];
295
+ const archive = body.archive;
296
+ if (archive) {
297
+ const notes = [
298
+ archive.complete ? 'complete' : 'incomplete',
299
+ archive.truncated
300
+ ? `truncated: ${archive.droppedEnvelopes} event(s), ${formatBytes(archive.droppedBytes)} dropped`
301
+ : null,
302
+ archive.clips.length ? `${archive.clips.length} output(s) clipped` : null,
303
+ ].filter(Boolean);
304
+ lines.push(` archive: ${notes.join('; ')}`);
305
+ }
306
+ for (const loss of body.losses ?? []) {
307
+ const range = loss.fromSeq !== undefined ? ` (steps ${loss.fromSeq}–${loss.toSeq ?? loss.fromSeq})` : '';
308
+ lines.push(` lost: ${loss.classes.join(', ') || 'events'}, ${loss.reason}${range}`);
309
+ }
310
+ for (const envelope of body.envelopes ?? []) {
311
+ const seq = envelope.__seq;
312
+ lines.push(` ${seq !== undefined ? `#${seq} ` : ''}${envelope.role} ${envelopeSummary(envelope)}`);
313
+ }
314
+ // An imported turn's events, numbered by their place in the turn (the page's offset counts).
315
+ for (const [index, event] of (body.events ?? []).entries()) {
316
+ lines.push(` #${body.offset + index + 1} ${event.role} ${clip(oneLine(importedEventSummary(event)), ENVELOPE_CLIP)}`);
317
+ }
318
+ for (const part of body.content ?? []) {
319
+ const record = (part ?? {});
320
+ const type = typeof record.type === 'string' ? record.type : 'part';
321
+ const text = typeof record.text === 'string' ? `: ${clip(oneLine(record.text), ENVELOPE_CLIP)}` : '';
322
+ lines.push(` ${type}${text}`);
323
+ }
324
+ if (body.source === 'live') {
325
+ lines.push(` (still running: this is what ${data_provider_1.BRAND.displayName} holds so far)`);
326
+ }
327
+ return lines;
328
+ }
329
+ /**
330
+ * `skrr convos transcript` — a conversation's whole session, as a conversation (G11, D12).
331
+ *
332
+ * The same items Session Details shows: the person's messages (follow-ups and steers included,
333
+ * and those Main Chat hides), each turn with where its process is kept, and every message the
334
+ * agent sent. A line marks each place the harness context did not continue. `--turn` prints one
335
+ * turn's whole process, paging through it.
336
+ */
337
+ class ConvosTranscript extends base_command_1.BaseCommand {
338
+ static description = "Read a conversation's whole session: messages, turns and the agent's messages";
339
+ static examples = [
340
+ '<%= config.bin %> convos transcript <conversationId>',
341
+ '<%= config.bin %> convos transcript <conversationId> --limit 20 --cursor <nextCursor>',
342
+ '<%= config.bin %> convos transcript <conversationId> --around latest --limit 20',
343
+ '<%= config.bin %> convos transcript <conversationId> --around <messageId>',
344
+ '<%= config.bin %> convos transcript <conversationId> --turn <messageId>',
345
+ '<%= config.bin %> convos transcript <conversationId> --json',
346
+ ];
347
+ static args = {
348
+ id: core_1.Args.string({ description: 'Conversation ID', required: true, ignoreStdin: true }),
349
+ };
350
+ static flags = {
351
+ json: core_1.Flags.boolean({ description: 'Print the API response as JSON' }),
352
+ turn: core_1.Flags.string({ description: "Print one turn's whole process (the turn's messageId)" }),
353
+ limit: core_1.Flags.integer({
354
+ description: `Items per page (1-${data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems}). Omit to read the whole session.`,
355
+ }),
356
+ cursor: core_1.Flags.string({
357
+ description: "Cursor from a previous page's nextCursor (newer) or prevCursor (older)",
358
+ exclusive: ['around'],
359
+ }),
360
+ around: core_1.Flags.string({
361
+ description: 'Read one page around an item: `latest` for the newest page, or an item messageId',
362
+ exclusive: ['cursor'],
363
+ }),
364
+ };
365
+ async run() {
366
+ this.requireAuth();
367
+ const { args, flags } = await this.parse(ConvosTranscript);
368
+ if (flags.turn) {
369
+ await this.printTurn(args.id, flags.turn, flags.json);
370
+ return;
371
+ }
372
+ if (flags.limit !== undefined &&
373
+ (flags.limit < 1 || flags.limit > data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems)) {
374
+ this.error(`--limit must be between 1 and ${data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems}.`);
375
+ }
376
+ // Without --limit or --around, read on (newer) to the end; otherwise one page.
377
+ const readOn = flags.limit === undefined && flags.around === undefined;
378
+ const pages = [];
379
+ let params = {
380
+ ...(flags.around ? { around: flags.around } : { cursor: flags.cursor ?? null }),
381
+ limit: flags.limit ?? data_provider_1.TURN_TRANSCRIPT_LIMITS.pageMaxItems,
382
+ };
383
+ try {
384
+ for (;;) {
385
+ const page = await data_provider_1.dataService.getConversationTranscript(args.id, params);
386
+ pages.push(page);
387
+ if (!readOn || !page.nextCursor)
388
+ break;
389
+ params = { cursor: page.nextCursor, limit: params.limit };
390
+ }
391
+ }
392
+ catch (err) {
393
+ this.handleApiError(err);
394
+ }
395
+ const first = pages[0];
396
+ const last = pages[pages.length - 1];
397
+ const result = {
398
+ conversationId: last?.conversationId ?? args.id,
399
+ items: pages.flatMap((page) => page.items),
400
+ nextCursor: last?.nextCursor ?? null,
401
+ prevCursor: first?.prevCursor ?? null,
402
+ ...(last?.previousConversationId !== undefined
403
+ ? { previousConversationId: last.previousConversationId }
404
+ : {}),
405
+ };
406
+ if (flags.json) {
407
+ this.log(JSON.stringify(result, null, 2));
408
+ return;
409
+ }
410
+ if (result.items.length === 0) {
411
+ this.log('Nothing in this session yet.');
412
+ }
413
+ for (const item of result.items) {
414
+ for (const line of formatTranscriptItem(item))
415
+ this.log(line);
416
+ }
417
+ const turns = result.items.filter((item) => item.kind === 'turn').length;
418
+ this.log(`\n${result.items.length} item(s), ${turns} turn(s)`);
419
+ if (result.prevCursor)
420
+ this.log(`older: --cursor ${result.prevCursor}`);
421
+ if (result.nextCursor)
422
+ this.log(`newer: --cursor ${result.nextCursor}`);
423
+ if (result.previousConversationId) {
424
+ this.log(`earlier in this chat: skrr convos transcript ${result.previousConversationId}`);
425
+ }
426
+ }
427
+ async printTurn(conversationId, messageId, json) {
428
+ const pages = [];
429
+ let offset = 0;
430
+ try {
431
+ while (offset !== null) {
432
+ const page = await data_provider_1.dataService.getConversationTranscriptTurn(conversationId, messageId, {
433
+ offset,
434
+ limit: data_provider_1.TURN_TRANSCRIPT_LIMITS.turnPageMaxEnvelopes,
435
+ });
436
+ pages.push(page);
437
+ offset = page.nextOffset !== null && page.nextOffset > offset ? page.nextOffset : null;
438
+ }
439
+ }
440
+ catch (err) {
441
+ this.handleApiError(err);
442
+ }
443
+ const first = pages[0];
444
+ const body = {
445
+ ...first,
446
+ offset: 0,
447
+ nextOffset: null,
448
+ ...(first.envelopes ? { envelopes: pages.flatMap((page) => page.envelopes ?? []) } : {}),
449
+ ...(first.content ? { content: pages.flatMap((page) => page.content ?? []) } : {}),
450
+ ...(first.events ? { events: pages.flatMap((page) => page.events ?? []) } : {}),
451
+ };
452
+ if (json) {
453
+ this.log(JSON.stringify(body, null, 2));
454
+ return;
455
+ }
456
+ for (const line of formatTurnBody(body))
457
+ this.log(line);
458
+ }
459
+ }
460
+ exports.default = ConvosTranscript;
@@ -4,6 +4,7 @@ export default class GoalsCreate extends BaseCommand {
4
4
  static examples: string[];
5
5
  static flags: {
6
6
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
+ 'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
8
  'from-json': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
9
  title: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -20,6 +20,9 @@ class GoalsCreate extends base_command_1.BaseCommand {
20
20
  ];
21
21
  static flags = {
22
22
  json: core_1.Flags.boolean({ description: 'Output the created goal as JSON' }),
23
+ 'dry-run': core_1.Flags.boolean({
24
+ description: 'Print the resolved create payload without creating a Goal',
25
+ }),
23
26
  'from-json': core_1.Flags.string({
24
27
  description: 'Path to a JSON file (or "-" for stdin) to use as the request body',
25
28
  }),
@@ -127,6 +130,11 @@ class GoalsCreate extends base_command_1.BaseCommand {
127
130
  }
128
131
  if (resolvedLabelIds)
129
132
  payload.labelIds = resolvedLabelIds;
133
+ if (flags['dry-run']) {
134
+ const result = { object: 'goal_create_dry_run', payload };
135
+ this.printJsonOperation(result, { mode: 'dry_run' });
136
+ return;
137
+ }
130
138
  let created;
131
139
  try {
132
140
  created = await data_provider_1.dataService.createGoal(payload, flags['idempotency-key'] ? { idempotencyKey: flags['idempotency-key'] } : undefined);
@@ -0,0 +1,10 @@
1
+ import { BaseCommand } from '../../base-command';
2
+ export default class GoalsCreationReceipt extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ 'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
6
+ 'from-json': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ };
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const data_provider_1 = require("@skrr-ai/data-provider");
5
+ const base_command_1 = require("../../base-command");
6
+ const prompt_1 = require("../../lib/prompt");
7
+ class GoalsCreationReceipt extends base_command_1.BaseCommand {
8
+ static description = 'Check whether the original Goal creation request committed';
9
+ static flags = {
10
+ 'idempotency-key': core_1.Flags.string({ description: 'Key used by the original `goals create`', required: true }),
11
+ 'from-json': core_1.Flags.string({
12
+ description: 'Original request body, such as .payload from `goals create --dry-run --json` ("-" for stdin)',
13
+ required: true,
14
+ }),
15
+ json: core_1.Flags.boolean({ description: 'Output the receipt as JSON' }),
16
+ };
17
+ async run() {
18
+ this.requireAuth();
19
+ const { flags } = await this.parse(GoalsCreationReceipt);
20
+ let payload;
21
+ try {
22
+ payload = await (0, prompt_1.readJsonBody)(flags['from-json']);
23
+ }
24
+ catch (error) {
25
+ this.error(error.message, { exit: 2 });
26
+ }
27
+ try {
28
+ const receipt = await data_provider_1.dataService.getGoalCreationReceipt(payload, flags['idempotency-key']);
29
+ if (flags.json)
30
+ return this.printJsonResult(receipt);
31
+ const messages = {
32
+ committed: 'The original Goal creation committed.',
33
+ gone: 'The Goal from that request is no longer available.',
34
+ unknown: 'The server could not confirm that Goal creation.',
35
+ };
36
+ this.log(messages[receipt.state]);
37
+ }
38
+ catch (error) {
39
+ this.handleApiError(error, { subject: 'Goal creation receipt' });
40
+ }
41
+ }
42
+ }
43
+ exports.default = GoalsCreationReceipt;
@@ -14,9 +14,11 @@ export default class GoalsKeyResultsCreate extends BaseCommand {
14
14
  };
15
15
  static flags: {
16
16
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
+ 'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
18
  'from-json': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
19
  title: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
20
  description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ 'request-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
22
  progress: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
23
  'progress-mode': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
22
24
  status: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -4,6 +4,7 @@ const core_1 = require("@oclif/core");
4
4
  const data_provider_1 = require("@skrr-ai/data-provider");
5
5
  const base_command_1 = require("../../../base-command");
6
6
  const prompt_1 = require("../../../lib/prompt");
7
+ const request_uuid_1 = require("../../../lib/request-uuid");
7
8
  /**
8
9
  * `skrr goals key-results create <goal-id> --title "..."` — add a key result to a
9
10
  * goal. Wraps `POST /api/goals/:goalId/key-results` (data-provider
@@ -23,11 +24,18 @@ class GoalsKeyResultsCreate extends base_command_1.BaseCommand {
23
24
  };
24
25
  static flags = {
25
26
  json: core_1.Flags.boolean({ description: 'Output the created key result as JSON' }),
27
+ 'dry-run': core_1.Flags.boolean({
28
+ description: 'Print the resolved create payload without creating a Key Result',
29
+ }),
26
30
  'from-json': core_1.Flags.string({
27
31
  description: 'Path to a JSON file (or "-" for stdin) to use as the request body',
28
32
  }),
29
33
  title: core_1.Flags.string({ description: 'Key result title (required unless set via --from-json)' }),
30
34
  description: core_1.Flags.string({ description: 'Key result description' }),
35
+ 'request-id': core_1.Flags.string({
36
+ description: 'UUID for this exact create payload, recoverable with `goals key-results creation-receipt`',
37
+ parse: request_uuid_1.parseRequestUuid,
38
+ }),
31
39
  // The bound is declared, not just described. `--progress 150` and
32
40
  // `--progress -5` both came back as a bare `Invalid request data /
33
41
  // HTTP_400` from the server — byte-identical for two different mistakes,
@@ -65,6 +73,7 @@ class GoalsKeyResultsCreate extends base_command_1.BaseCommand {
65
73
  const data = (0, prompt_1.mergeDefined)(body, {
66
74
  title: flags.title,
67
75
  description: flags.description,
76
+ creationRequestId: flags['request-id'],
68
77
  progress: flags.progress,
69
78
  progressMode: flags['progress-mode'],
70
79
  status: flags.status,
@@ -75,6 +84,11 @@ class GoalsKeyResultsCreate extends base_command_1.BaseCommand {
75
84
  exit: 1,
76
85
  });
77
86
  }
87
+ if (flags['dry-run']) {
88
+ const result = { object: 'key_result_create_dry_run', payload: data };
89
+ this.printJsonOperation(result, { mode: 'dry_run' });
90
+ return;
91
+ }
78
92
  let created;
79
93
  try {
80
94
  created = await data_provider_1.dataService.createKeyResult({
@@ -0,0 +1,13 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ export default class GoalsKeyResultsCreationReceipt extends BaseCommand {
3
+ static description: string;
4
+ static args: {
5
+ goalId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
6
+ };
7
+ static flags: {
8
+ 'request-id': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'from-json': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ run(): Promise<void>;
13
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const data_provider_1 = require("@skrr-ai/data-provider");
5
+ const base_command_1 = require("../../../base-command");
6
+ const prompt_1 = require("../../../lib/prompt");
7
+ const request_uuid_1 = require("../../../lib/request-uuid");
8
+ class GoalsKeyResultsCreationReceipt extends base_command_1.BaseCommand {
9
+ static description = 'Check whether the original Key Result creation request completed';
10
+ static args = {
11
+ goalId: core_1.Args.string({ description: 'Goal ID', required: true, ignoreStdin: true }),
12
+ };
13
+ static flags = {
14
+ 'request-id': core_1.Flags.string({
15
+ description: 'UUID used for the original Key Result create', required: true, parse: request_uuid_1.parseRequestUuid,
16
+ }),
17
+ 'from-json': core_1.Flags.string({
18
+ description: 'Original request body, such as .payload from `goals key-results create --dry-run --json` ("-" for stdin)',
19
+ required: true,
20
+ }),
21
+ json: core_1.Flags.boolean({ description: 'Output the receipt as JSON' }),
22
+ };
23
+ async run() {
24
+ this.requireAuth();
25
+ const { args, flags } = await this.parse(GoalsKeyResultsCreationReceipt);
26
+ const requestId = flags['request-id'];
27
+ let body;
28
+ try {
29
+ body = await (0, prompt_1.readJsonBody)(flags['from-json']);
30
+ }
31
+ catch (error) {
32
+ this.error(error.message, { exit: 2 });
33
+ }
34
+ const { creationRequestId, ...payload } = body;
35
+ if (creationRequestId !== undefined && creationRequestId !== requestId) {
36
+ this.error('The original body contains a different creationRequestId.', { exit: 2 });
37
+ }
38
+ try {
39
+ const receipt = await data_provider_1.dataService.getKeyResultCreationReceipt(args.goalId, { requestId, payload });
40
+ if (flags.json)
41
+ return this.printJsonResult(receipt);
42
+ this.log(receipt.state === 'created'
43
+ ? `Created Key Result ${receipt.keyResultId}.`
44
+ : 'The server could not confirm that Key Result creation.');
45
+ }
46
+ catch (error) {
47
+ this.handleApiError(error, { subject: `Goal ${args.goalId} Key Result creation receipt` });
48
+ }
49
+ }
50
+ }
51
+ exports.default = GoalsKeyResultsCreationReceipt;