@skrr-ai/cli 0.1.231 → 0.1.233

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 (161) hide show
  1. package/README.md +42 -4
  2. package/bin/dev.cjs +4 -1
  3. package/bin/run.js +0 -15
  4. package/dist/base-command.d.ts +6 -11
  5. package/dist/base-command.js +34 -43
  6. package/dist/commands/agenda/plan.d.ts +2 -1
  7. package/dist/commands/agenda/plan.js +18 -4
  8. package/dist/commands/agent/message/context.d.ts +2 -0
  9. package/dist/commands/agent/message/context.js +18 -3
  10. package/dist/commands/agent/message/list.d.ts +22 -0
  11. package/dist/commands/agent/message/list.js +66 -0
  12. package/dist/commands/agent/message/send.d.ts +1 -1
  13. package/dist/commands/agent/message/send.js +1 -3
  14. package/dist/commands/agent/message/show.d.ts +14 -0
  15. package/dist/commands/agent/message/show.js +39 -0
  16. package/dist/commands/agents/chat.d.ts +4 -0
  17. package/dist/commands/agents/chat.js +79 -17
  18. package/dist/commands/agents/eval/list.d.ts +4 -0
  19. package/dist/commands/agents/eval/list.js +33 -0
  20. package/dist/commands/agents/eval/show.d.ts +1 -0
  21. package/dist/commands/agents/eval/show.js +19 -0
  22. package/dist/commands/agents/intuitions/generate.js +1 -1
  23. package/dist/commands/agents/intuitions/list.js +1 -1
  24. package/dist/commands/agents/permissions/policy.js +25 -2
  25. package/dist/commands/agents/spawn.js +61 -24
  26. package/dist/commands/agents/triggers/fire.js +1 -1
  27. package/dist/commands/agents/triggers/runs.js +3 -0
  28. package/dist/commands/code/acp.js +1 -1
  29. package/dist/commands/code/handover.d.ts +3 -3
  30. package/dist/commands/code/handover.js +12 -12
  31. package/dist/commands/code/index.d.ts +3 -8
  32. package/dist/commands/code/index.js +15 -21
  33. package/dist/commands/code/jobs/approve.d.ts +1 -11
  34. package/dist/commands/code/jobs/approve.js +3 -15
  35. package/dist/commands/code/jobs/cancel.js +3 -2
  36. package/dist/commands/code/jobs/index.js +1 -1
  37. package/dist/commands/code/jobs/list.js +4 -11
  38. package/dist/commands/code/jobs/run.js +13 -7
  39. package/dist/commands/code/jobs/show.js +52 -6
  40. package/dist/commands/code/run.js +1 -1
  41. package/dist/commands/commands.d.ts +1 -0
  42. package/dist/commands/commands.js +5 -1
  43. package/dist/commands/context.d.ts +1 -0
  44. package/dist/commands/context.js +1 -0
  45. package/dist/commands/duties/catalog/add.d.ts +18 -0
  46. package/dist/commands/duties/catalog/add.js +52 -0
  47. package/dist/commands/duties/catalog/index.d.ts +18 -0
  48. package/dist/commands/duties/catalog/index.js +88 -0
  49. package/dist/commands/duties/receipt.js +56 -1
  50. package/dist/commands/goals/plan-now.d.ts +5 -3
  51. package/dist/commands/goals/plan-now.js +21 -16
  52. package/dist/commands/goals/planner-compare.js +5 -3
  53. package/dist/commands/instructions/discovery.d.ts +10 -0
  54. package/dist/commands/instructions/discovery.js +74 -0
  55. package/dist/commands/runs/admission.d.ts +12 -0
  56. package/dist/commands/runs/admission.js +66 -0
  57. package/dist/commands/runs/events.d.ts +16 -0
  58. package/dist/commands/runs/events.js +89 -0
  59. package/dist/commands/runs/list.d.ts +27 -0
  60. package/dist/commands/runs/list.js +151 -0
  61. package/dist/commands/runs/show.d.ts +14 -0
  62. package/dist/commands/runs/show.js +273 -0
  63. package/dist/commands/runs/stop.d.ts +15 -0
  64. package/dist/commands/runs/stop.js +105 -0
  65. package/dist/commands/runs/transcript.d.ts +19 -0
  66. package/dist/commands/runs/transcript.js +178 -0
  67. package/dist/commands/tasks/attachments/download.d.ts +1 -0
  68. package/dist/commands/tasks/attachments/download.js +6 -4
  69. package/dist/commands/tasks/attachments/source.d.ts +6 -0
  70. package/dist/commands/tasks/attachments/source.js +18 -0
  71. package/dist/commands/tasks/chat/exchange.d.ts +0 -14
  72. package/dist/commands/tasks/chat/exchange.js +8 -39
  73. package/dist/commands/tasks/chat/reply-run.d.ts +15 -0
  74. package/dist/commands/tasks/chat/reply-run.js +69 -0
  75. package/dist/commands/tasks/complete.js +1 -1
  76. package/dist/commands/tasks/lifecycle/transition.d.ts +1 -0
  77. package/dist/commands/tasks/lifecycle/transition.js +51 -13
  78. package/dist/commands/tasks/operations/show.js +5 -0
  79. package/dist/commands/tasks/result/submit.js +4 -2
  80. package/dist/commands/tasks/retry.js +25 -16
  81. package/dist/commands/tasks/runs.js +7 -0
  82. package/dist/commands/tasks/start-receipt.js +8 -8
  83. package/dist/commands/tasks/start.js +12 -1
  84. package/dist/commands/triggers/audit.js +3 -1
  85. package/dist/commands/triggers/fire-detail.js +4 -1
  86. package/dist/commands/triggers/fire.js +1 -1
  87. package/dist/commands/usage.d.ts +1 -0
  88. package/dist/commands/usage.js +1 -0
  89. package/dist/generated/agent-guides.json +350 -777
  90. package/dist/help.d.ts +2 -7
  91. package/dist/help.js +13 -7
  92. package/dist/hooks/init.js +10 -0
  93. package/dist/lib/agent-chat-queue.d.ts +2 -1
  94. package/dist/lib/agent-chat-queue.js +26 -21
  95. package/dist/lib/agent-evals.d.ts +1 -1
  96. package/dist/lib/agent-evals.js +13 -3
  97. package/dist/lib/agent-guides.d.ts +3 -5
  98. package/dist/lib/agent-guides.js +12 -13
  99. package/dist/lib/agent-runs.d.ts +101 -0
  100. package/dist/lib/agent-runs.js +350 -0
  101. package/dist/lib/agentic-stream.d.ts +13 -1
  102. package/dist/lib/agentic-stream.js +165 -81
  103. package/dist/lib/api-fetch.d.ts +4 -2
  104. package/dist/lib/api-fetch.js +11 -5
  105. package/dist/lib/code-handover.d.ts +2 -3
  106. package/dist/lib/code-handover.js +4 -6
  107. package/dist/lib/command-manifest.d.ts +1 -6
  108. package/dist/lib/command-manifest.js +86 -13
  109. package/dist/lib/communication-history.d.ts +27 -0
  110. package/dist/lib/communication-history.js +45 -0
  111. package/dist/lib/config.d.ts +2 -3
  112. package/dist/lib/config.js +2 -3
  113. package/dist/lib/duties.d.ts +5 -1
  114. package/dist/lib/duties.js +4 -0
  115. package/dist/lib/execution-history.d.ts +34 -0
  116. package/dist/lib/execution-history.js +7 -0
  117. package/dist/lib/first-party-harness-broker.d.ts +1 -1
  118. package/dist/lib/first-party-harness-broker.js +3 -5
  119. package/dist/lib/format.d.ts +1 -0
  120. package/dist/lib/format.js +18 -0
  121. package/dist/lib/guide-pointer.d.ts +5 -1
  122. package/dist/lib/guide-pointer.js +21 -2
  123. package/dist/lib/hosted-job-status.d.ts +4 -0
  124. package/dist/lib/hosted-job-status.js +19 -0
  125. package/dist/lib/inbound-messages.d.ts +2 -0
  126. package/dist/lib/inbound-messages.js +5 -0
  127. package/dist/lib/intuition-look.js +20 -4
  128. package/dist/lib/memory-history-session.d.ts +8 -4
  129. package/dist/lib/memory-history-session.js +30 -23
  130. package/dist/lib/roles.d.ts +2 -2
  131. package/dist/lib/schedule.d.ts +4 -0
  132. package/dist/lib/schedule.js +4 -3
  133. package/dist/lib/task-agent-run.d.ts +4 -0
  134. package/dist/lib/task-agent-run.js +15 -0
  135. package/dist/lib/task-execution.d.ts +1 -1
  136. package/dist/lib/task-execution.js +3 -19
  137. package/dist/lib/task-extras.d.ts +11 -1
  138. package/dist/lib/task-extras.js +15 -1
  139. package/dist/lib/task-transcript.js +3 -8
  140. package/dist/lib/triggers.d.ts +5 -36
  141. package/dist/lib/triggers.js +48 -33
  142. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonWire.d.ts +9 -0
  143. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonWire.js +40 -3
  144. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessCommand.d.ts +37 -0
  145. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessCommand.js +59 -0
  146. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/toolApprovalSignature.d.ts +62 -0
  147. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/toolApprovalSignature.js +56 -0
  148. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonWire.d.ts +9 -0
  149. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonWire.js +34 -3
  150. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessCommand.d.ts +37 -0
  151. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessCommand.js +57 -0
  152. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/toolApprovalSignature.d.ts +62 -0
  153. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/toolApprovalSignature.js +51 -0
  154. package/dist/node_modules/@skrr-ai/auth-core/package.json +10 -0
  155. package/dist/node_modules/@skrr-ai/data-provider/index.js +12259 -12160
  156. package/docs/v1/quickstart.md +18 -0
  157. package/oclif.manifest.json +3405 -2112
  158. package/package.json +6 -2
  159. package/skills/skrr/SKILL.md +14 -0
  160. package/dist/commands/triggers/runs.d.ts +0 -22
  161. package/dist/commands/triggers/runs.js +0 -58
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RunStopConflictError = exports.RunStopUnconfirmedError = exports.RunTranscriptCursorInvalidError = exports.RunEventCursorStaleError = exports.RunListCursorInvalidError = exports.attemptIdFlag = exports.runIdArgument = void 0;
4
+ exports.canonicalRunId = canonicalRunId;
5
+ exports.exactAttemptId = exactAttemptId;
6
+ exports.runReadScopeArgs = runReadScopeArgs;
7
+ exports.listAgentRuns = listAgentRuns;
8
+ exports.listPrivateReleaseEvalHistory = listPrivateReleaseEvalHistory;
9
+ exports.chatCopyOrigin = chatCopyOrigin;
10
+ exports.readAgentRun = readAgentRun;
11
+ exports.readAgentRunEvents = readAgentRunEvents;
12
+ exports.readAgentRunTranscript = readAgentRunTranscript;
13
+ exports.stopAgentRun = stopAgentRun;
14
+ const core_1 = require("@oclif/core");
15
+ const api_fetch_1 = require("./api-fetch");
16
+ const http_error_1 = require("./http-error");
17
+ const search_display_1 = require("./search-display");
18
+ const write_outcome_1 = require("./write-outcome");
19
+ const workspace_header_1 = require("./workspace-header");
20
+ const RUN_ID = /^ar_[A-Za-z0-9_-]{43}$/;
21
+ const ATTEMPT_ID = /^aa_[A-Za-z0-9_-]{43}$/;
22
+ const STOPPABLE = new Set(['queued', 'active', 'reconciling', 'stopping']);
23
+ const TERMINAL = new Set(['succeeded', 'failed', 'cancelled', 'expired']);
24
+ const RUNS_PATH = '/api/agent-runs';
25
+ function canonicalRunId(value) {
26
+ return typeof value === 'string' && RUN_ID.test(value) ? value : undefined;
27
+ }
28
+ exports.runIdArgument = core_1.Args.string({
29
+ description: 'Canonical Agent Run ID',
30
+ required: true,
31
+ ignoreStdin: true,
32
+ parse: async (input) => {
33
+ const id = canonicalRunId(input);
34
+ if (!id)
35
+ throw new Error('Expected a canonical Run ID beginning with ar_.');
36
+ return id;
37
+ },
38
+ });
39
+ function exactAttemptId(input) {
40
+ if (!ATTEMPT_ID.test(input))
41
+ throw new Error('Expected a canonical Attempt ID beginning with aa_.');
42
+ return input;
43
+ }
44
+ exports.attemptIdFlag = core_1.Flags.string({
45
+ description: 'Canonical Agent Run Attempt ID',
46
+ required: true,
47
+ parse: async (input) => exactAttemptId(input),
48
+ });
49
+ function path(runId) {
50
+ if (!canonicalRunId(runId))
51
+ throw new Error('Expected a canonical Run ID beginning with ar_.');
52
+ return `${RUNS_PATH}/${runId}`;
53
+ }
54
+ function runReadScopeArgs(workspaceId) {
55
+ return workspaceId ? ['--workspace', workspaceId] : ['--personal'];
56
+ }
57
+ async function readRunResource(endpoint, read = api_fetch_1.apiFetch, { allowDefaultWorkspace = true, personal = false } = {}) {
58
+ if (personal) {
59
+ const scope = { workspaceScope: 'personal' };
60
+ return { value: await read(endpoint, scope), scope };
61
+ }
62
+ const headers = (0, workspace_header_1.withWorkspaceHeader)({});
63
+ const scope = headers['X-Workspace-Id'] ? { headers } : undefined;
64
+ try {
65
+ return { value: await read(endpoint, scope), scope };
66
+ }
67
+ catch (error) {
68
+ // A personal Run can be visible without a workspace. Try the account's
69
+ // default only when the product API could not find the Run in that scope.
70
+ if (!allowDefaultWorkspace || scope || process.env.OVERSKY_AUTONOMOUS_SESSION === '1' ||
71
+ !(0, http_error_1.isHttpNotFound)(error) || error.code !== 'RUN_HISTORY_NOT_FOUND') {
72
+ throw error;
73
+ }
74
+ const profile = await (0, api_fetch_1.apiFetch)('/api/auth/profile').catch(() => undefined);
75
+ const workspaceId = typeof profile?.workspaceId === 'string' ? profile.workspaceId.trim() : '';
76
+ if (!workspaceId)
77
+ throw error;
78
+ const defaultScope = { headers: { 'X-Workspace-Id': workspaceId } };
79
+ return { value: await read(endpoint, defaultScope), scope: defaultScope };
80
+ }
81
+ }
82
+ class RunListCursorInvalidError extends Error {
83
+ workspaceId;
84
+ constructor(workspaceId, cause) {
85
+ super('The Run History list cursor is no longer valid.', { cause });
86
+ this.workspaceId = workspaceId;
87
+ }
88
+ }
89
+ exports.RunListCursorInvalidError = RunListCursorInvalidError;
90
+ async function listAgentRuns({ agentId, conversationId, goalId, source, evaluationId, from, to, status, cursor, limit, personal = false, }) {
91
+ const query = new URLSearchParams();
92
+ for (const [key, value] of Object.entries({ agentId, conversationId, goalId, source, evaluationId, from, to, status, cursor, limit })) {
93
+ if (value !== undefined)
94
+ query.set(key, String(value));
95
+ }
96
+ const { value, scope } = await readRunResource(`${RUNS_PATH}?${query}`, async (endpoint, scope) => {
97
+ try {
98
+ return await (0, api_fetch_1.apiFetch)(endpoint, scope);
99
+ }
100
+ catch (error) {
101
+ if (cursor !== undefined && (0, http_error_1.httpStatusOf)(error) === 400 &&
102
+ (0, http_error_1.httpBodyOf)(error)?.code === 'INVALID_RUN_HISTORY_CURSOR') {
103
+ throw new RunListCursorInvalidError(scope?.headers?.['X-Workspace-Id'], error);
104
+ }
105
+ throw error;
106
+ }
107
+ }, { allowDefaultWorkspace: cursor === undefined, personal });
108
+ if (!Array.isArray(value?.items) ||
109
+ !value.items.every((row) => canonicalRunId(row?.id) && typeof row.source === 'string' &&
110
+ typeof row.status === 'string' && typeof row.acceptedAt === 'string' &&
111
+ (row.title == null || typeof row.title === 'string')) ||
112
+ (value.nextCursor !== null &&
113
+ (typeof value.nextCursor !== 'string' || !(0, search_display_1.isPrintableSearchCursor)(value.nextCursor)))) {
114
+ throw new Error('The server did not provide a Run History page.');
115
+ }
116
+ return { page: value, workspaceId: scope?.headers?.['X-Workspace-Id'] };
117
+ }
118
+ async function listPrivateReleaseEvalHistory({ agentId, releaseId, limit, cursor, }) {
119
+ const agent = `/api/agents/${encodeURIComponent(agentId)}`;
120
+ const route = releaseId ? `${agent}/releases/${encodeURIComponent(releaseId)}/evals` : `${agent}/evals`;
121
+ const query = new URLSearchParams({ scope: 'mine' });
122
+ if (limit !== undefined)
123
+ query.set('limit', String(limit));
124
+ if (cursor !== undefined)
125
+ query.set('cursor', cursor);
126
+ const { value } = await readRunResource(`${route}?${query}`);
127
+ if (value?.object !== 'list' || !Array.isArray(value.data) ||
128
+ !value.data.every((row) => typeof row?.id === 'string' && typeof row.status === 'string' && row.runHistorySupported === true) ||
129
+ (value.nextCursor !== null &&
130
+ (typeof value.nextCursor !== 'string' || !(0, search_display_1.isPrintableSearchCursor)(value.nextCursor)))) {
131
+ throw new Error('The server did not provide a private evaluation history page.');
132
+ }
133
+ return value;
134
+ }
135
+ function chatCopyOrigin(run) {
136
+ const origin = run.source === 'chat' ? run.derivedFrom : undefined;
137
+ if (!origin || (origin.kind !== 'fork' && origin.kind !== 'handover') ||
138
+ !canonicalRunId(origin.runId) || typeof origin.attemptId !== 'string' ||
139
+ !ATTEMPT_ID.test(origin.attemptId))
140
+ return undefined;
141
+ if (origin.workspaceId !== undefined && (typeof origin.workspaceId !== 'string' ||
142
+ !/^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,199}$/.test(origin.workspaceId)))
143
+ return undefined;
144
+ return origin;
145
+ }
146
+ async function readAgentRun(runId, { personal = false } = {}) {
147
+ const detailPath = path(runId);
148
+ const readDetail = async (endpoint, options) => {
149
+ const detail = await (0, api_fetch_1.apiFetch)(endpoint, options);
150
+ if (detail?.id !== runId)
151
+ throw new Error('The server returned an unexpected Run.');
152
+ return detail;
153
+ };
154
+ const { value: detail, scope } = await readRunResource(detailPath, readDetail, { personal });
155
+ if (!detail.eventReplay)
156
+ return detail;
157
+ try {
158
+ const page = await (0, api_fetch_1.apiFetch)(eventsPath(runId), scope);
159
+ const { snapshot } = assertEventsRun(runId, page);
160
+ return { ...detail, ...(snapshot ? { snapshot } : {}) };
161
+ }
162
+ catch (error) {
163
+ const status = (0, http_error_1.httpStatusOf)(error);
164
+ if (status === undefined || status < 500 || status >= 600)
165
+ throw error;
166
+ // Only a fresh source read in the original scope can release detail after
167
+ // the event journal fails. An authorization denial still closes the read.
168
+ const current = await readDetail(detailPath, {
169
+ ...(scope ?? { workspaceScope: 'personal' }),
170
+ singleAttempt: true,
171
+ signal: AbortSignal.timeout(5_000),
172
+ });
173
+ return current.eventReplay ? { ...current, snapshotAvailability: 'unavailable' } : current;
174
+ }
175
+ }
176
+ function eventsPath(runId, { attempt, cursor, limit } = {}) {
177
+ const query = new URLSearchParams();
178
+ if (attempt !== undefined)
179
+ query.set('attempt', exactAttemptId(attempt));
180
+ if (cursor !== undefined)
181
+ query.set('cursor', cursor);
182
+ if (limit !== undefined)
183
+ query.set('limit', String(limit));
184
+ const search = query.toString();
185
+ return `${path(runId)}/events${search ? `?${search}` : ''}`;
186
+ }
187
+ function assertEventsRun(runId, page) {
188
+ if (page?.runId !== runId)
189
+ throw new Error('The server returned events for an unexpected Run.');
190
+ return page;
191
+ }
192
+ class RunEventCursorStaleError extends Error {
193
+ workspaceId;
194
+ constructor(workspaceId, cause) {
195
+ super('The Run event cursor is no longer valid.', { cause });
196
+ this.workspaceId = workspaceId;
197
+ }
198
+ }
199
+ exports.RunEventCursorStaleError = RunEventCursorStaleError;
200
+ async function readAgentRunEvents(runId, options) {
201
+ const { value, scope } = await readRunResource(eventsPath(runId, options), async (endpoint, scope) => {
202
+ try {
203
+ return await (0, api_fetch_1.apiFetch)(endpoint, scope);
204
+ }
205
+ catch (error) {
206
+ if (options?.cursor !== undefined && (0, http_error_1.httpStatusOf)(error) === 410 &&
207
+ (0, http_error_1.httpBodyOf)(error)?.code === 'RUN_HISTORY_EVENT_CURSOR_STALE') {
208
+ throw new RunEventCursorStaleError(scope?.headers?.['X-Workspace-Id'], error);
209
+ }
210
+ throw error;
211
+ }
212
+ }, { allowDefaultWorkspace: options?.cursor === undefined, personal: options?.personal });
213
+ const page = assertEventsRun(runId, value);
214
+ if (page.attemptId !== options?.attempt || (options?.attempt && (!Array.isArray(page.events) ||
215
+ !page.events.every(({ attemptId }) => attemptId === options.attempt)))) {
216
+ throw new Error('The server returned events for an unexpected Attempt.');
217
+ }
218
+ return { page, workspaceId: scope?.headers?.['X-Workspace-Id'] };
219
+ }
220
+ class RunTranscriptCursorInvalidError extends Error {
221
+ workspaceId;
222
+ constructor(workspaceId, cause) {
223
+ super('The Run transcript cursor is no longer valid.', { cause });
224
+ this.workspaceId = workspaceId;
225
+ }
226
+ }
227
+ exports.RunTranscriptCursorInvalidError = RunTranscriptCursorInvalidError;
228
+ async function readAgentRunTranscript(runId, { attempt, offset, after, limit, personal = false }) {
229
+ if (after !== undefined && (offset !== undefined || !(0, search_display_1.isPrintableSearchCursor)(after))) {
230
+ throw new Error('Use an opaque transcript cursor or an offset.');
231
+ }
232
+ const query = new URLSearchParams({ attempt: exactAttemptId(attempt) });
233
+ if (offset !== undefined)
234
+ query.set('offset', String(offset));
235
+ if (after !== undefined)
236
+ query.set('after', after);
237
+ if (limit !== undefined)
238
+ query.set('limit', String(limit));
239
+ const { value, scope } = await readRunResource(`${path(runId)}/transcript?${query}`, async (endpoint, scope) => {
240
+ try {
241
+ return await (0, api_fetch_1.apiFetch)(endpoint, scope);
242
+ }
243
+ catch (error) {
244
+ if (after !== undefined && (0, http_error_1.httpStatusOf)(error) === 400 &&
245
+ (0, http_error_1.httpBodyOf)(error)?.code === 'INVALID_RUN_TRANSCRIPT_CURSOR') {
246
+ throw new RunTranscriptCursorInvalidError(scope?.headers?.['X-Workspace-Id'], error);
247
+ }
248
+ throw error;
249
+ }
250
+ },
251
+ // Forward cursors carry the original authorized scope. The first page's
252
+ // command includes that workspace when the server required one.
253
+ { allowDefaultWorkspace: after === undefined, personal });
254
+ if (!['available', 'partial', 'unverified', 'unavailable'].includes(value?.availability)) {
255
+ throw new Error('The server did not provide a Run transcript page.');
256
+ }
257
+ return { page: value, workspaceId: scope?.headers?.['X-Workspace-Id'] };
258
+ }
259
+ class RunStopUnconfirmedError extends Error {
260
+ expectedAttemptId;
261
+ workspaceId;
262
+ constructor(expectedAttemptId, workspaceId, cause) {
263
+ super('Stop was not confirmed.', { cause });
264
+ this.expectedAttemptId = expectedAttemptId;
265
+ this.workspaceId = workspaceId;
266
+ }
267
+ }
268
+ exports.RunStopUnconfirmedError = RunStopUnconfirmedError;
269
+ class RunStopConflictError extends Error {
270
+ expectedAttemptId;
271
+ workspaceId;
272
+ constructor(expectedAttemptId, workspaceId, cause) {
273
+ super('Stop was not accepted.', { cause });
274
+ this.expectedAttemptId = expectedAttemptId;
275
+ this.workspaceId = workspaceId;
276
+ }
277
+ }
278
+ exports.RunStopConflictError = RunStopConflictError;
279
+ async function recoverStopReceipt(runId, attemptId, before, scope) {
280
+ const head = before.snapshot;
281
+ if (!head || !Number.isSafeInteger(head.sequence) || head.sequence < 0 ||
282
+ !Number.isSafeInteger(head.controlGeneration) || head.controlGeneration < 0 ||
283
+ typeof before.cursor !== 'string' || !(0, search_display_1.isPrintableSearchCursor)(before.cursor))
284
+ return;
285
+ // The original boundary proves the Stop is newer than the snapshot used to
286
+ // choose its target. A stale cursor must never fall back to a new snapshot.
287
+ const page = await (0, api_fetch_1.apiFetch)(eventsPath(runId, { cursor: before.cursor }), {
288
+ ...scope, singleAttempt: true, signal: AbortSignal.timeout(5_000),
289
+ }).catch(() => undefined);
290
+ if (page?.runId !== runId || page.snapshot || page.attemptId !== undefined || !Array.isArray(page.events) ||
291
+ !page.events.every((event, index) => event?.sequence === head.sequence + index + 1))
292
+ return;
293
+ const stopIndex = page.events.findIndex(({ type }) => type === 'stop_requested');
294
+ const stop = page.events[stopIndex];
295
+ const generation = stop?.controlGeneration;
296
+ if (!stop || stop.attemptId !== attemptId || (stop.status !== 'stopping' && stop.status !== 'cancelled') ||
297
+ typeof generation !== 'number' || !Number.isSafeInteger(generation) || generation <= head.controlGeneration ||
298
+ typeof stop.observedAt !== 'string' || !Number.isFinite(Date.parse(stop.observedAt)))
299
+ return;
300
+ const cancelled = stop.status === 'cancelled' || page.events.slice(stopIndex + 1).some((event) => event.type === 'run_settled' && event.attemptId === attemptId && event.status === 'cancelled' &&
301
+ event.controlGeneration === generation);
302
+ return { runId, attemptId, status: cancelled ? 'cancelled' : 'stop_requested', requestedAt: stop.observedAt };
303
+ }
304
+ async function stopAgentRun(runId, expectedAttemptId, { personal = false } = {}) {
305
+ if (typeof expectedAttemptId === 'string')
306
+ exactAttemptId(expectedAttemptId);
307
+ const { value, scope } = await readRunResource(eventsPath(runId), api_fetch_1.apiFetch, { personal });
308
+ const { snapshot } = assertEventsRun(runId, value);
309
+ if (!snapshot || typeof snapshot.status !== 'string' ||
310
+ (snapshot.activeAttemptId !== null &&
311
+ (typeof snapshot.activeAttemptId !== 'string' || !ATTEMPT_ID.test(snapshot.activeAttemptId)))) {
312
+ throw new Error('The server did not provide an exact Run snapshot.');
313
+ }
314
+ let attemptId = expectedAttemptId;
315
+ if (attemptId === undefined) {
316
+ if (TERMINAL.has(snapshot.status)) {
317
+ return { kind: 'already-ended', runId, status: snapshot.status };
318
+ }
319
+ attemptId = snapshot.activeAttemptId;
320
+ if (!STOPPABLE.has(snapshot.status) || (snapshot.status === 'queued') !== (attemptId === null)) {
321
+ throw new Error('The server did not confirm a stoppable Run and Attempt.');
322
+ }
323
+ }
324
+ const workspaceId = scope?.headers?.['X-Workspace-Id'];
325
+ let cause;
326
+ try {
327
+ const receipt = await (0, api_fetch_1.apiFetch)(`${path(runId)}/stop`, {
328
+ ...scope,
329
+ method: 'POST',
330
+ body: { expectedAttemptId: attemptId },
331
+ singleAttempt: true,
332
+ });
333
+ if (receipt?.runId === runId && receipt.attemptId === attemptId &&
334
+ (receipt.status === 'stop_requested' || receipt.status === 'cancelled') &&
335
+ typeof receipt.requestedAt === 'string' && Number.isFinite(Date.parse(receipt.requestedAt))) {
336
+ return { kind: 'receipt', receipt };
337
+ }
338
+ }
339
+ catch (error) {
340
+ if ((0, http_error_1.httpStatusOf)(error) === 409)
341
+ throw new RunStopConflictError(attemptId, workspaceId, error);
342
+ if (!(0, write_outcome_1.unknownWriteOf)(error, (0, http_error_1.httpBodyOf)(error)) && !(error instanceof SyntaxError))
343
+ throw error;
344
+ cause = error;
345
+ }
346
+ const recovered = await recoverStopReceipt(runId, attemptId, value, scope);
347
+ if (recovered)
348
+ return { kind: 'receipt', receipt: recovered };
349
+ throw new RunStopUnconfirmedError(attemptId, workspaceId, cause);
350
+ }
@@ -82,6 +82,8 @@ export type ReconciledTerminal = {
82
82
  text?: string;
83
83
  /** The recorded failure reason — `metadata.agentic.error` on the message. */
84
84
  error?: string;
85
+ code?: string;
86
+ errorType?: string;
85
87
  /**
86
88
  * The failure is a hand-over, not an ending (OSK-13543): the row is failed
87
89
  * with {@link DAEMON_HANDOVER_REASON}, which the server itself treats as
@@ -221,7 +223,9 @@ export type AgenticStreamOptions = {
221
223
  * the stream alone.
222
224
  */
223
225
  reconcileTerminal?: () => Promise<ReconciledTerminal | null>;
224
- /** Ingress returned this response for an idempotent retry. Its session may have expired. */
226
+ /** The response bound to this Chat by its admission receipt. */
227
+ admittedResponseMessageId?: string;
228
+ /** The original response from an idempotent Chat retry. Its session may have expired. */
225
229
  resumeRecordedResponseId?: string;
226
230
  /** Owner-authorized canonical envelopes, including events emitted before room admission. */
227
231
  replayEnvelopes?: (from: number) => Promise<EnvelopeReplayPage>;
@@ -593,6 +597,8 @@ export declare class AgenticStreamClient {
593
597
  /** A `tool-call-end` arrived whose start never did — proof a tool envelope was lost. */
594
598
  private orphanToolEnd;
595
599
  private readonly seenEnvelopes;
600
+ /** Durable reset IDs observed on this response's exact session stream. */
601
+ private readonly canonicalResetIds;
596
602
  /**
597
603
  * Lifecycle events already emitted, by their own identity (OSK-7632/7689/7709).
598
604
  *
@@ -657,6 +663,7 @@ export declare class AgenticStreamClient {
657
663
  /** Releases a connect wait still in flight; `close()` calls it. */
658
664
  private abandonConnectWait;
659
665
  private reconciling;
666
+ private readonly admittedResponseMessageId;
660
667
  private responseMessageId;
661
668
  private lastEvent;
662
669
  /**
@@ -803,7 +810,12 @@ export declare class AgenticStreamClient {
803
810
  * a block opener is held back, so nothing printed is ever retracted.
804
811
  */
805
812
  private answerText;
813
+ private matchesAdmittedResponse;
814
+ /** Match the binding used by data-provider's canonical retry reducer. */
815
+ private canonicalResetId;
816
+ private resetAttemptOutput;
806
817
  private applySessionOutput;
818
+ private applySessionEnvelopeBatch;
807
819
  private installHandlers;
808
820
  /**
809
821
  * One server ask, one prompt (OSK-11796, OSK-22641).