@skrr-ai/cli 0.1.232 → 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 (118) hide show
  1. package/README.md +29 -13
  2. package/bin/dev.cjs +0 -1
  3. package/bin/run.js +0 -15
  4. package/dist/base-command.d.ts +6 -1
  5. package/dist/base-command.js +24 -4
  6. package/dist/commands/agenda/plan.d.ts +2 -1
  7. package/dist/commands/agenda/plan.js +18 -4
  8. package/dist/commands/agents/chat.d.ts +2 -0
  9. package/dist/commands/agents/chat.js +59 -13
  10. package/dist/commands/agents/eval/list.d.ts +4 -0
  11. package/dist/commands/agents/eval/list.js +33 -0
  12. package/dist/commands/agents/permissions/policy.js +25 -2
  13. package/dist/commands/agents/spawn.js +61 -24
  14. package/dist/commands/agents/triggers/fire.js +1 -1
  15. package/dist/commands/agents/triggers/runs.js +3 -0
  16. package/dist/commands/code/jobs/approve.d.ts +1 -11
  17. package/dist/commands/code/jobs/approve.js +3 -15
  18. package/dist/commands/code/jobs/cancel.js +3 -2
  19. package/dist/commands/code/jobs/index.js +1 -1
  20. package/dist/commands/code/jobs/list.js +4 -11
  21. package/dist/commands/code/jobs/run.js +13 -7
  22. package/dist/commands/code/jobs/show.js +51 -6
  23. package/dist/commands/commands.d.ts +1 -0
  24. package/dist/commands/commands.js +5 -1
  25. package/dist/commands/context.d.ts +1 -0
  26. package/dist/commands/context.js +1 -0
  27. package/dist/commands/duties/catalog/add.d.ts +18 -0
  28. package/dist/commands/duties/catalog/add.js +52 -0
  29. package/dist/commands/duties/catalog/index.d.ts +18 -0
  30. package/dist/commands/duties/catalog/index.js +88 -0
  31. package/dist/commands/duties/receipt.js +56 -1
  32. package/dist/commands/goals/planner-compare.js +5 -3
  33. package/dist/commands/instructions/discovery.d.ts +10 -0
  34. package/dist/commands/instructions/discovery.js +74 -0
  35. package/dist/commands/runs/admission.d.ts +12 -0
  36. package/dist/commands/runs/admission.js +66 -0
  37. package/dist/commands/runs/events.d.ts +2 -0
  38. package/dist/commands/runs/events.js +40 -10
  39. package/dist/commands/runs/list.d.ts +7 -1
  40. package/dist/commands/runs/list.js +81 -17
  41. package/dist/commands/runs/show.d.ts +1 -0
  42. package/dist/commands/runs/show.js +225 -15
  43. package/dist/commands/runs/stop.d.ts +1 -0
  44. package/dist/commands/runs/stop.js +34 -7
  45. package/dist/commands/runs/transcript.d.ts +2 -0
  46. package/dist/commands/runs/transcript.js +102 -17
  47. package/dist/commands/tasks/attachments/download.d.ts +1 -0
  48. package/dist/commands/tasks/attachments/download.js +6 -4
  49. package/dist/commands/tasks/attachments/source.d.ts +6 -0
  50. package/dist/commands/tasks/attachments/source.js +18 -0
  51. package/dist/commands/tasks/chat/exchange.d.ts +0 -14
  52. package/dist/commands/tasks/chat/exchange.js +8 -39
  53. package/dist/commands/tasks/chat/reply-run.d.ts +15 -0
  54. package/dist/commands/tasks/chat/reply-run.js +69 -0
  55. package/dist/commands/tasks/complete.js +1 -1
  56. package/dist/commands/tasks/lifecycle/transition.d.ts +1 -0
  57. package/dist/commands/tasks/lifecycle/transition.js +51 -13
  58. package/dist/commands/tasks/operations/show.js +5 -0
  59. package/dist/commands/tasks/result/submit.js +4 -2
  60. package/dist/commands/tasks/retry.js +25 -16
  61. package/dist/commands/triggers/audit.js +3 -1
  62. package/dist/commands/triggers/fire-detail.js +4 -1
  63. package/dist/commands/triggers/fire.js +1 -1
  64. package/dist/commands/usage.d.ts +1 -0
  65. package/dist/commands/usage.js +1 -0
  66. package/dist/generated/agent-guides.json +64 -712
  67. package/dist/help.d.ts +2 -7
  68. package/dist/help.js +13 -7
  69. package/dist/hooks/init.js +10 -0
  70. package/dist/lib/agent-evals.d.ts +1 -1
  71. package/dist/lib/agent-evals.js +13 -3
  72. package/dist/lib/agent-guides.d.ts +3 -5
  73. package/dist/lib/agent-guides.js +12 -13
  74. package/dist/lib/agent-runs.d.ts +69 -9
  75. package/dist/lib/agent-runs.js +208 -35
  76. package/dist/lib/agentic-stream.d.ts +12 -0
  77. package/dist/lib/agentic-stream.js +163 -79
  78. package/dist/lib/api-fetch.d.ts +2 -0
  79. package/dist/lib/api-fetch.js +6 -1
  80. package/dist/lib/command-manifest.d.ts +1 -6
  81. package/dist/lib/command-manifest.js +86 -13
  82. package/dist/lib/config.d.ts +2 -3
  83. package/dist/lib/config.js +2 -3
  84. package/dist/lib/duties.d.ts +5 -1
  85. package/dist/lib/duties.js +4 -0
  86. package/dist/lib/execution-history.d.ts +3 -0
  87. package/dist/lib/format.d.ts +1 -0
  88. package/dist/lib/format.js +18 -0
  89. package/dist/lib/guide-pointer.d.ts +5 -1
  90. package/dist/lib/guide-pointer.js +21 -2
  91. package/dist/lib/hosted-job-status.d.ts +4 -0
  92. package/dist/lib/hosted-job-status.js +19 -0
  93. package/dist/lib/inbound-messages.d.ts +1 -0
  94. package/dist/lib/inbound-messages.js +2 -0
  95. package/dist/lib/roles.d.ts +2 -2
  96. package/dist/lib/schedule.d.ts +4 -0
  97. package/dist/lib/schedule.js +4 -3
  98. package/dist/lib/task-execution.d.ts +1 -1
  99. package/dist/lib/task-execution.js +3 -19
  100. package/dist/lib/task-extras.d.ts +11 -1
  101. package/dist/lib/task-extras.js +15 -1
  102. package/dist/lib/task-transcript.js +3 -8
  103. package/dist/lib/triggers.d.ts +5 -36
  104. package/dist/lib/triggers.js +48 -33
  105. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonWire.js +5 -1
  106. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessCommand.d.ts +37 -0
  107. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessCommand.js +59 -0
  108. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonWire.js +5 -1
  109. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessCommand.d.ts +37 -0
  110. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessCommand.js +57 -0
  111. package/dist/node_modules/@skrr-ai/auth-core/package.json +10 -0
  112. package/dist/node_modules/@skrr-ai/data-provider/index.js +12261 -12172
  113. package/docs/v1/quickstart.md +18 -0
  114. package/oclif.manifest.json +2505 -629
  115. package/package.json +3 -2
  116. package/skills/skrr/SKILL.md +14 -0
  117. package/dist/commands/triggers/runs.d.ts +0 -22
  118. package/dist/commands/triggers/runs.js +0 -58
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RunStopUnconfirmedError = exports.attemptIdFlag = exports.runIdArgument = void 0;
3
+ exports.RunStopConflictError = exports.RunStopUnconfirmedError = exports.RunTranscriptCursorInvalidError = exports.RunEventCursorStaleError = exports.RunListCursorInvalidError = exports.attemptIdFlag = exports.runIdArgument = void 0;
4
4
  exports.canonicalRunId = canonicalRunId;
5
5
  exports.exactAttemptId = exactAttemptId;
6
+ exports.runReadScopeArgs = runReadScopeArgs;
6
7
  exports.listAgentRuns = listAgentRuns;
8
+ exports.listPrivateReleaseEvalHistory = listPrivateReleaseEvalHistory;
9
+ exports.chatCopyOrigin = chatCopyOrigin;
7
10
  exports.readAgentRun = readAgentRun;
8
11
  exports.readAgentRunEvents = readAgentRunEvents;
9
12
  exports.readAgentRunTranscript = readAgentRunTranscript;
@@ -48,16 +51,23 @@ function path(runId) {
48
51
  throw new Error('Expected a canonical Run ID beginning with ar_.');
49
52
  return `${RUNS_PATH}/${runId}`;
50
53
  }
51
- async function readRunResource(endpoint) {
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
+ }
52
62
  const headers = (0, workspace_header_1.withWorkspaceHeader)({});
53
63
  const scope = headers['X-Workspace-Id'] ? { headers } : undefined;
54
64
  try {
55
- return { value: await (0, api_fetch_1.apiFetch)(endpoint, scope), scope };
65
+ return { value: await read(endpoint, scope), scope };
56
66
  }
57
67
  catch (error) {
58
68
  // A personal Run can be visible without a workspace. Try the account's
59
69
  // default only when the product API could not find the Run in that scope.
60
- if (scope || process.env.OVERSKY_AUTONOMOUS_SESSION === '1' ||
70
+ if (!allowDefaultWorkspace || scope || process.env.OVERSKY_AUTONOMOUS_SESSION === '1' ||
61
71
  !(0, http_error_1.isHttpNotFound)(error) || error.code !== 'RUN_HISTORY_NOT_FOUND') {
62
72
  throw error;
63
73
  }
@@ -66,16 +76,35 @@ async function readRunResource(endpoint) {
66
76
  if (!workspaceId)
67
77
  throw error;
68
78
  const defaultScope = { headers: { 'X-Workspace-Id': workspaceId } };
69
- return { value: await (0, api_fetch_1.apiFetch)(endpoint, defaultScope), scope: defaultScope };
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;
70
87
  }
71
88
  }
72
- async function listAgentRuns({ agentId, conversationId, source, from, to, status, cursor, limit, }) {
89
+ exports.RunListCursorInvalidError = RunListCursorInvalidError;
90
+ async function listAgentRuns({ agentId, conversationId, goalId, source, evaluationId, from, to, status, cursor, limit, personal = false, }) {
73
91
  const query = new URLSearchParams();
74
- for (const [key, value] of Object.entries({ agentId, conversationId, source, from, to, status, cursor, limit })) {
92
+ for (const [key, value] of Object.entries({ agentId, conversationId, goalId, source, evaluationId, from, to, status, cursor, limit })) {
75
93
  if (value !== undefined)
76
94
  query.set(key, String(value));
77
95
  }
78
- const { value } = await readRunResource(`${RUNS_PATH}?${query}`);
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 });
79
108
  if (!Array.isArray(value?.items) ||
80
109
  !value.items.every((row) => canonicalRunId(row?.id) && typeof row.source === 'string' &&
81
110
  typeof row.status === 'string' && typeof row.acceptedAt === 'string' &&
@@ -84,20 +113,70 @@ async function listAgentRuns({ agentId, conversationId, source, from, to, status
84
113
  (typeof value.nextCursor !== 'string' || !(0, search_display_1.isPrintableSearchCursor)(value.nextCursor)))) {
85
114
  throw new Error('The server did not provide a Run History page.');
86
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
+ }
87
133
  return value;
88
134
  }
89
- async function readAgentRun(runId) {
90
- const { value: detail, scope } = await readRunResource(path(runId));
91
- if (detail?.id !== runId)
92
- throw new Error('The server returned an unexpected Run.');
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 });
93
155
  if (!detail.eventReplay)
94
156
  return detail;
95
- const page = await (0, api_fetch_1.apiFetch)(eventsPath(runId), scope);
96
- const { snapshot } = assertEventsRun(runId, page);
97
- return { ...detail, ...(snapshot ? { snapshot } : {}) };
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
+ }
98
175
  }
99
- function eventsPath(runId, { cursor, limit } = {}) {
176
+ function eventsPath(runId, { attempt, cursor, limit } = {}) {
100
177
  const query = new URLSearchParams();
178
+ if (attempt !== undefined)
179
+ query.set('attempt', exactAttemptId(attempt));
101
180
  if (cursor !== undefined)
102
181
  query.set('cursor', cursor);
103
182
  if (limit !== undefined)
@@ -110,34 +189,122 @@ function assertEventsRun(runId, page) {
110
189
  throw new Error('The server returned events for an unexpected Run.');
111
190
  return page;
112
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;
113
200
  async function readAgentRunEvents(runId, options) {
114
- const { value } = await readRunResource(eventsPath(runId, options));
115
- return assertEventsRun(runId, value);
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
+ }
116
226
  }
117
- async function readAgentRunTranscript(runId, { attempt, offset, limit }) {
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
+ }
118
232
  const query = new URLSearchParams({ attempt: exactAttemptId(attempt) });
119
233
  if (offset !== undefined)
120
234
  query.set('offset', String(offset));
235
+ if (after !== undefined)
236
+ query.set('after', after);
121
237
  if (limit !== undefined)
122
238
  query.set('limit', String(limit));
123
- const { value } = await readRunResource(`${path(runId)}/transcript?${query}`);
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 });
124
254
  if (!['available', 'partial', 'unverified', 'unavailable'].includes(value?.availability)) {
125
255
  throw new Error('The server did not provide a Run transcript page.');
126
256
  }
127
- return value;
257
+ return { page: value, workspaceId: scope?.headers?.['X-Workspace-Id'] };
128
258
  }
129
259
  class RunStopUnconfirmedError extends Error {
130
260
  expectedAttemptId;
131
- constructor(expectedAttemptId, cause) {
261
+ workspaceId;
262
+ constructor(expectedAttemptId, workspaceId, cause) {
132
263
  super('Stop was not confirmed.', { cause });
133
264
  this.expectedAttemptId = expectedAttemptId;
265
+ this.workspaceId = workspaceId;
134
266
  }
135
267
  }
136
268
  exports.RunStopUnconfirmedError = RunStopUnconfirmedError;
137
- async function stopAgentRun(runId, expectedAttemptId) {
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 } = {}) {
138
305
  if (typeof expectedAttemptId === 'string')
139
306
  exactAttemptId(expectedAttemptId);
140
- const { value, scope } = await readRunResource(eventsPath(runId));
307
+ const { value, scope } = await readRunResource(eventsPath(runId), api_fetch_1.apiFetch, { personal });
141
308
  const { snapshot } = assertEventsRun(runId, value);
142
309
  if (!snapshot || typeof snapshot.status !== 'string' ||
143
310
  (snapshot.activeAttemptId !== null &&
@@ -154,24 +321,30 @@ async function stopAgentRun(runId, expectedAttemptId) {
154
321
  throw new Error('The server did not confirm a stoppable Run and Attempt.');
155
322
  }
156
323
  }
157
- let receipt;
324
+ const workspaceId = scope?.headers?.['X-Workspace-Id'];
325
+ let cause;
158
326
  try {
159
- receipt = await (0, api_fetch_1.apiFetch)(`${path(runId)}/stop`, {
327
+ const receipt = await (0, api_fetch_1.apiFetch)(`${path(runId)}/stop`, {
160
328
  ...scope,
161
329
  method: 'POST',
162
330
  body: { expectedAttemptId: attemptId },
163
331
  singleAttempt: true,
164
332
  });
165
- }
166
- catch (error) {
167
- if ((0, write_outcome_1.unknownWriteOf)(error, (0, http_error_1.httpBodyOf)(error)) || error instanceof SyntaxError) {
168
- throw new RunStopUnconfirmedError(attemptId, error);
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 };
169
337
  }
170
- throw error;
171
338
  }
172
- if (receipt?.runId !== runId || receipt.attemptId !== attemptId ||
173
- (receipt.status !== 'stop_requested' && receipt.status !== 'cancelled')) {
174
- throw new RunStopUnconfirmedError(attemptId);
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;
175
345
  }
176
- return { kind: 'receipt', receipt };
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);
177
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,6 +223,8 @@ export type AgenticStreamOptions = {
221
223
  * the stream alone.
222
224
  */
223
225
  reconcileTerminal?: () => Promise<ReconciledTerminal | null>;
226
+ /** The response bound to this Chat by its admission receipt. */
227
+ admittedResponseMessageId?: string;
224
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. */
@@ -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).