@jini-ai/daemon 0.3.7 → 0.5.0

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 (159) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/README.md +50 -8
  3. package/dist/agent-executor/contracts.d.ts +736 -0
  4. package/dist/agent-executor/contracts.js +28 -0
  5. package/dist/agent-executor/event-translation.d.ts +87 -0
  6. package/dist/agent-executor/event-translation.js +230 -0
  7. package/dist/agent-executor/events.d.ts +190 -0
  8. package/dist/agent-executor/events.js +848 -0
  9. package/dist/agent-executor/handoff.d.ts +18 -0
  10. package/dist/agent-executor/handoff.js +16 -0
  11. package/dist/agent-executor/index.d.ts +98 -0
  12. package/dist/agent-executor/index.js +98 -0
  13. package/dist/agent-executor/launch.d.ts +375 -0
  14. package/dist/agent-executor/launch.js +1001 -0
  15. package/dist/agent-executor/mcp-bridge.d.ts +338 -0
  16. package/dist/agent-executor/mcp-bridge.js +835 -0
  17. package/dist/agent-executor/values.d.ts +5 -0
  18. package/dist/agent-executor/values.js +13 -0
  19. package/dist/agent-executor.d.ts +382 -177
  20. package/dist/agent-executor.js +408 -344
  21. package/dist/close-status.d.ts +11 -8
  22. package/dist/close-status.js +31 -19
  23. package/dist/continuation/continuation-transport.d.ts +3 -1
  24. package/dist/continuation/continuation-transport.js +1 -1
  25. package/dist/continuation/journal.d.ts +12 -5
  26. package/dist/continuation/journal.js +4 -4
  27. package/dist/continuation/run-scoped-context-store.d.ts +13 -4
  28. package/dist/continuation/run-scoped-context-store.js +6 -6
  29. package/dist/continuation/run-start-handler.d.ts +1 -1
  30. package/dist/continuation/run-start-handler.js +3 -16
  31. package/dist/delegated-tool-bridge.d.ts +7 -3
  32. package/dist/delegated-tool-bridge.js +32 -31
  33. package/dist/event-log.d.ts +7 -5
  34. package/dist/event-log.js +12 -11
  35. package/dist/frontend-capability-tools.d.ts +1 -1
  36. package/dist/frontend-capability-tools.js +3 -2
  37. package/dist/frontend-session-registry.d.ts +32 -9
  38. package/dist/frontend-session-registry.js +12 -11
  39. package/dist/http/active-context.d.ts +105 -0
  40. package/dist/http/active-context.js +67 -0
  41. package/dist/http/agents.d.ts +68 -0
  42. package/dist/http/agents.js +12 -0
  43. package/dist/http/attachments.d.ts +618 -0
  44. package/dist/http/attachments.js +1034 -0
  45. package/dist/http/cancel-owned-runs.d.ts +49 -0
  46. package/dist/http/cancel-owned-runs.js +35 -0
  47. package/dist/http/component-catalog.d.ts +84 -0
  48. package/dist/http/component-catalog.js +64 -0
  49. package/dist/http/connectors.d.ts +209 -0
  50. package/dist/http/connectors.js +409 -0
  51. package/dist/http/daemon-status.d.ts +76 -0
  52. package/dist/http/daemon-status.js +55 -0
  53. package/dist/http/db-ops.d.ts +123 -0
  54. package/dist/http/db-ops.js +189 -0
  55. package/dist/http/delegated-tools.d.ts +113 -0
  56. package/dist/http/delegated-tools.js +230 -0
  57. package/dist/http/frontend-control.d.ts +136 -0
  58. package/dist/http/frontend-control.js +79 -0
  59. package/dist/http/frontend-sessions.d.ts +110 -0
  60. package/dist/http/frontend-sessions.js +180 -0
  61. package/dist/http/health.d.ts +95 -0
  62. package/dist/http/health.js +40 -0
  63. package/dist/http/host-tools.d.ts +214 -0
  64. package/dist/http/host-tools.js +329 -0
  65. package/dist/http/index.d.ts +52 -0
  66. package/dist/http/index.js +27 -0
  67. package/dist/http/media.d.ts +146 -0
  68. package/dist/http/media.js +346 -0
  69. package/dist/http/memory.d.ts +265 -0
  70. package/dist/http/memory.js +328 -0
  71. package/dist/http/model-proxy.d.ts +49 -0
  72. package/dist/http/model-proxy.js +642 -0
  73. package/dist/http/remote-run-events.d.ts +70 -0
  74. package/dist/http/remote-run-events.js +224 -0
  75. package/dist/http/research.d.ts +48 -0
  76. package/dist/http/research.js +315 -0
  77. package/dist/http/route-manifest.d.ts +35 -0
  78. package/dist/http/route-manifest.js +103 -0
  79. package/dist/http/routines.d.ts +120 -0
  80. package/dist/http/routines.js +298 -0
  81. package/dist/http/run-credentials.d.ts +73 -0
  82. package/dist/http/run-credentials.js +71 -0
  83. package/dist/http/runs.d.ts +91 -0
  84. package/dist/http/runs.js +221 -0
  85. package/dist/http/terminals.d.ts +138 -0
  86. package/dist/http/terminals.js +325 -0
  87. package/dist/http/tool-catalog.d.ts +78 -0
  88. package/dist/http/tool-catalog.js +66 -0
  89. package/dist/http/workspace-root.d.ts +77 -0
  90. package/dist/http/workspace-root.js +63 -0
  91. package/dist/http/xai.d.ts +90 -0
  92. package/dist/http/xai.js +655 -0
  93. package/dist/image-prompt-delivery.d.ts +13 -3
  94. package/dist/image-prompt-delivery.js +5 -5
  95. package/dist/index.d.ts +556 -4
  96. package/dist/index.js +556 -4
  97. package/dist/legacy-data-migration.d.ts +59 -8
  98. package/dist/legacy-data-migration.js +38 -33
  99. package/dist/read-only-tools.d.ts +130 -0
  100. package/dist/read-only-tools.js +115 -0
  101. package/dist/remote-tool-bridge.d.ts +11 -5
  102. package/dist/remote-tool-bridge.js +15 -15
  103. package/dist/routines/index.d.ts +1 -1
  104. package/dist/routines/index.js +1 -1
  105. package/dist/routines/routine-store.d.ts +34 -12
  106. package/dist/routines/routine-store.js +21 -20
  107. package/dist/routines/schedule.d.ts +48 -10
  108. package/dist/routines/schedule.js +21 -21
  109. package/dist/routines/scheduler.d.ts +32 -11
  110. package/dist/routines/scheduler.js +61 -57
  111. package/dist/routines/types.d.ts +10 -3
  112. package/dist/run/core/result.d.ts +6 -2
  113. package/dist/run/core/result.js +3 -3
  114. package/dist/run/core/retry.d.ts +17 -4
  115. package/dist/run/core/retry.js +7 -11
  116. package/dist/run/diagnostics/diagnostics.d.ts +14 -4
  117. package/dist/run/diagnostics/diagnostics.js +7 -7
  118. package/dist/run/index.d.ts +1 -1
  119. package/dist/run/index.js +1 -1
  120. package/dist/run-credentials.d.ts +138 -0
  121. package/dist/run-credentials.js +152 -0
  122. package/dist/run-lifecycle.d.ts +92 -33
  123. package/dist/run-lifecycle.js +86 -73
  124. package/dist/scheduler.d.ts +8 -0
  125. package/dist/scheduler.js +2 -0
  126. package/dist/session-coordination.d.ts +115 -0
  127. package/dist/session-coordination.js +111 -0
  128. package/dist/store/agent-sessions/errors.d.ts +8 -0
  129. package/dist/store/agent-sessions/errors.js +10 -0
  130. package/dist/store/agent-sessions/index.d.ts +12 -0
  131. package/dist/store/agent-sessions/index.js +19 -0
  132. package/dist/store/agent-sessions/pglite.d.ts +12 -0
  133. package/dist/store/agent-sessions/pglite.js +7 -0
  134. package/dist/store/agent-sessions/ports.d.ts +24 -0
  135. package/dist/store/agent-sessions/ports.js +2 -0
  136. package/dist/store/agent-sessions/postgres.d.ts +12 -0
  137. package/dist/store/agent-sessions/postgres.js +7 -0
  138. package/dist/store/agent-sessions/schema.d.ts +3 -0
  139. package/dist/store/agent-sessions/schema.js +23 -0
  140. package/dist/store/agent-sessions/sql.d.ts +35 -0
  141. package/dist/store/agent-sessions/sql.js +59 -0
  142. package/dist/store/agent-sessions/sqlite.d.ts +117 -0
  143. package/dist/store/agent-sessions/sqlite.js +128 -0
  144. package/dist/store/event-log/sqlite.d.ts +75 -0
  145. package/dist/store/event-log/sqlite.js +230 -0
  146. package/dist/surface-exchanges.d.ts +97 -0
  147. package/dist/surface-exchanges.js +153 -0
  148. package/dist/terminal-session.d.ts +43 -11
  149. package/dist/terminal-session.js +22 -20
  150. package/dist/tokens.js +4 -4
  151. package/dist/tool-audit.d.ts +114 -0
  152. package/dist/tool-audit.js +95 -0
  153. package/dist/tool-executor.d.ts +22 -7
  154. package/dist/tool-executor.js +16 -16
  155. package/dist/tool-result-media.d.ts +3 -1
  156. package/dist/tool-result-media.js +1 -1
  157. package/dist/tool-result-surfaces.d.ts +3 -1
  158. package/dist/tool-result-surfaces.js +1 -1
  159. package/package.json +127 -9
@@ -14,7 +14,7 @@
14
14
  * today as its own small, well-scoped task." Its only import was `node:crypto`'s `randomUUID`
15
15
  * (unchanged here); its `Routine`/`RoutineSchedule` types were already a documented local mirror,
16
16
  * not a product coupling (now `./types.js`); its `RoutinePersistence` injected port and
17
- * `RoutineRunHandler` callback are unchanged (see `./types.js`'s doc comments for why
17
+ * `RoutineRunHandler` callback preserve their behavior, with object arguments on the port (see `./types.js`'s doc comments for why
18
18
  * `RoutinePersistence` deliberately stays synchronous rather than converted to this package's
19
19
  * usual async-port convention). Logic is otherwise unchanged from the OD source — this is a
20
20
  * faithful port, not a redesign, per the proposal's own warning against "casually reinventing"
@@ -35,7 +35,7 @@ export class ScheduledRunPersistenceError extends Error {
35
35
  routineId;
36
36
  slotAt;
37
37
  originalError;
38
- constructor(routineId, slotAt, originalError) {
38
+ constructor({ routineId, slotAt, originalError }) {
39
39
  super(`Routine ${routineId} scheduled slot ${slotAt} could not be persisted`);
40
40
  this.routineId = routineId;
41
41
  this.slotAt = slotAt;
@@ -50,30 +50,34 @@ function errorMessage(error) {
50
50
  return error instanceof Error ? error.message : String(error);
51
51
  }
52
52
  export class RoutineService {
53
- persistence;
54
53
  timers = new Map();
55
54
  inflight = new Map();
56
55
  runHandler = null;
57
56
  started = false;
58
- constructor(persistence) {
57
+ persistence;
58
+ now;
59
+ newId;
60
+ constructor({ persistence }, { now = Date.now, newId = randomUUID } = {}) {
59
61
  this.persistence = persistence;
62
+ this.now = now;
63
+ this.newId = newId;
60
64
  }
61
- setRunHandler(handler) {
65
+ setRunHandler({ handler }) {
62
66
  this.runHandler = handler;
63
67
  }
64
- start() {
68
+ start(_args) {
65
69
  if (this.started)
66
70
  return;
67
71
  this.started = true;
68
- this.rescheduleAll();
72
+ this.rescheduleAll({});
69
73
  }
70
- stop() {
74
+ stop(_args) {
71
75
  for (const entry of this.timers.values())
72
76
  clearTimeout(entry.timer);
73
77
  this.timers.clear();
74
78
  this.started = false;
75
79
  }
76
- rescheduleAll() {
80
+ rescheduleAll(_args) {
77
81
  for (const entry of this.timers.values())
78
82
  clearTimeout(entry.timer);
79
83
  this.timers.clear();
@@ -83,7 +87,7 @@ export class RoutineService {
83
87
  this.scheduleRoutine(routine);
84
88
  }
85
89
  }
86
- rescheduleOne(routineId) {
90
+ rescheduleOne({ routineId }) {
87
91
  const existing = this.timers.get(routineId);
88
92
  if (existing) {
89
93
  clearTimeout(existing.timer);
@@ -95,7 +99,7 @@ export class RoutineService {
95
99
  if (routine)
96
100
  this.scheduleRoutine(routine);
97
101
  }
98
- unschedule(routineId) {
102
+ unschedule({ routineId }) {
99
103
  const existing = this.timers.get(routineId);
100
104
  if (existing) {
101
105
  clearTimeout(existing.timer);
@@ -105,7 +109,7 @@ export class RoutineService {
105
109
  scheduleRoutine(routine) {
106
110
  if (!routine.enabled)
107
111
  return;
108
- const fireAt = nextRunAtForSchedule(routine.schedule);
112
+ const fireAt = nextRunAtForSchedule({ schedule: routine.schedule }, { now: new Date(this.now()) });
109
113
  if (!fireAt)
110
114
  return;
111
115
  this.scheduleRoutineAt(routine, fireAt);
@@ -122,14 +126,14 @@ export class RoutineService {
122
126
  // setTimeout can't carry past 2^31 ms (~24.8 days); we cap and use a chained re-schedule.
123
127
  // Routines fire within hours/days, but a misconfigured "next month" weekly value could
124
128
  // otherwise overflow.
125
- const delay = Math.max(1_000, Math.min(2_000_000_000, fireAt.getTime() - Date.now()));
129
+ const delay = Math.max(1_000, Math.min(2_000_000_000, fireAt.getTime() - this.now()));
126
130
  const timer = setTimeout(() => {
127
131
  this.timers.delete(routine.id);
128
132
  const slotAt = fireAt.getTime();
129
133
  this.start_(routine.id, 'scheduled', { scheduledSlotAt: slotAt })
130
134
  .then(() => {
131
135
  // Always reschedule so a single fire keeps the cadence alive.
132
- this.rescheduleOne(routine.id);
136
+ this.rescheduleOne({ routineId: routine.id });
133
137
  })
134
138
  .catch((error) => {
135
139
  console.error(`[@jini-ai/daemon] routine ${routine.id} scheduled run failed:`, error instanceof ScheduledRunPersistenceError
@@ -143,7 +147,7 @@ export class RoutineService {
143
147
  this.retryScheduledSlot(routine.id, fireAt);
144
148
  }
145
149
  else {
146
- this.rescheduleOne(routine.id);
150
+ this.rescheduleOne({ routineId: routine.id });
147
151
  }
148
152
  });
149
153
  }, delay);
@@ -151,10 +155,10 @@ export class RoutineService {
151
155
  timer.unref();
152
156
  this.timers.set(routine.id, { routineId: routine.id, timer, fireAt });
153
157
  }
154
- nextRunAt(routineId) {
158
+ nextRunAt({ routineId }) {
155
159
  return this.timers.get(routineId)?.fireAt ?? null;
156
160
  }
157
- async runNow(routineId) {
161
+ async runNow({ routineId }) {
158
162
  return this.start_(routineId, 'manual');
159
163
  }
160
164
  /**
@@ -166,7 +170,7 @@ export class RoutineService {
166
170
  const slotAt = attempt.scheduledSlotAt;
167
171
  if (slotAt == null)
168
172
  return error;
169
- return new ScheduledRunPersistenceError(attempt.routine.id, slotAt, error);
173
+ return new ScheduledRunPersistenceError({ routineId: attempt.routine.id, slotAt: slotAt, originalError: error });
170
174
  }
171
175
  /**
172
176
  * Tear-down for when the durable routine_run row was never inserted (insertRun threw, or another
@@ -192,7 +196,7 @@ export class RoutineService {
192
196
  claimRunRow(attempt) {
193
197
  let inserted = true;
194
198
  try {
195
- inserted = this.persistence.insertRun(attempt.run, attempt.insertOptions) !== false;
199
+ inserted = this.persistence.insertRun({ run: attempt.run }, attempt.insertOptions) !== false;
196
200
  }
197
201
  catch (error) {
198
202
  this.discardUnstartedRun(attempt);
@@ -217,11 +221,11 @@ export class RoutineService {
217
221
  handlerStart.conversationId = run.conversationId;
218
222
  handlerStart.agentRunId = run.agentRunId;
219
223
  if (attempt.scheduledSlotAt != null || preparedIdsChanged) {
220
- this.persistence.updateRun(attempt.runId, {
221
- projectId: run.projectId,
222
- conversationId: run.conversationId,
223
- agentRunId: run.agentRunId,
224
- });
224
+ this.persistence.updateRun({ id: attempt.runId, patch: {
225
+ projectId: run.projectId,
226
+ conversationId: run.conversationId,
227
+ agentRunId: run.agentRunId,
228
+ } });
225
229
  }
226
230
  }
227
231
  /**
@@ -251,37 +255,37 @@ export class RoutineService {
251
255
  run.projectId = clearRoutinePlaceholderId(run.projectId);
252
256
  run.conversationId = clearRoutinePlaceholderId(run.conversationId);
253
257
  run.agentRunId = clearRoutinePlaceholderId(run.agentRunId);
254
- this.persistence.updateRun(attempt.runId, {
255
- status: 'failed',
256
- completedAt: Date.now(),
257
- summary: null,
258
- error: errorMessage(error),
259
- errorCode: null,
260
- projectId: run.projectId,
261
- conversationId: run.conversationId,
262
- agentRunId: run.agentRunId,
263
- });
258
+ this.persistence.updateRun({ id: attempt.runId, patch: {
259
+ status: 'failed',
260
+ completedAt: this.now(),
261
+ summary: null,
262
+ error: errorMessage(error),
263
+ errorCode: null,
264
+ projectId: run.projectId,
265
+ conversationId: run.conversationId,
266
+ agentRunId: run.agentRunId,
267
+ } });
264
268
  }
265
269
  /** Persists the terminal row once the host's run completes (or its completion promise rejects). */
266
270
  wireRunCompletion(attempt) {
267
271
  attempt.handlerStart.completion
268
272
  .then((completion) => {
269
- this.persistence.updateRun(attempt.runId, {
270
- status: completion.status,
271
- completedAt: Date.now(),
272
- summary: completion.summary ?? null,
273
- error: completion.error ?? null,
274
- errorCode: completion.errorCode ?? null,
275
- });
273
+ this.persistence.updateRun({ id: attempt.runId, patch: {
274
+ status: completion.status,
275
+ completedAt: this.now(),
276
+ summary: completion.summary ?? null,
277
+ error: completion.error ?? null,
278
+ errorCode: completion.errorCode ?? null,
279
+ } });
276
280
  })
277
281
  .catch((error) => {
278
- this.persistence.updateRun(attempt.runId, {
279
- status: 'failed',
280
- completedAt: Date.now(),
281
- summary: null,
282
- error: errorMessage(error),
283
- errorCode: null,
284
- });
282
+ this.persistence.updateRun({ id: attempt.runId, patch: {
283
+ status: 'failed',
284
+ completedAt: this.now(),
285
+ summary: null,
286
+ error: errorMessage(error),
287
+ errorCode: null,
288
+ } });
285
289
  });
286
290
  }
287
291
  /** Hands control to the host's `start()`, finalizing the row as failed if it throws synchronously. */
@@ -290,13 +294,13 @@ export class RoutineService {
290
294
  attempt.handlerStart.start?.();
291
295
  }
292
296
  catch (error) {
293
- this.persistence.updateRun(attempt.runId, {
294
- status: 'failed',
295
- completedAt: Date.now(),
296
- summary: null,
297
- error: errorMessage(error),
298
- errorCode: null,
299
- });
297
+ this.persistence.updateRun({ id: attempt.runId, patch: {
298
+ status: 'failed',
299
+ completedAt: this.now(),
300
+ summary: null,
301
+ error: errorMessage(error),
302
+ errorCode: null,
303
+ } });
300
304
  throw error;
301
305
  }
302
306
  }
@@ -309,8 +313,8 @@ export class RoutineService {
309
313
  const routine = this.persistence.list().find((r) => r.id === routineId);
310
314
  if (!routine)
311
315
  throw new Error(`Routine ${routineId} not found`);
312
- const startedAt = Date.now();
313
- const runId = `routine-run-${randomUUID()}`;
316
+ const startedAt = this.now();
317
+ const runId = `routine-run-${this.newId()}`;
314
318
  const promise = (async () => {
315
319
  const handler = this.runHandler;
316
320
  if (!handler)
@@ -122,10 +122,17 @@ export type RoutineRunHandler = (input: {
122
122
  */
123
123
  export interface RoutinePersistence {
124
124
  list(): Routine[];
125
- insertRun(run: RoutineRun, options?: {
125
+ insertRun(args: {
126
+ readonly run: RoutineRun;
127
+ }, optionalArgs?: {
126
128
  scheduledSlotAt?: number;
127
129
  }): boolean | void;
128
- updateRun(id: string, patch: Partial<RoutineRun>): void;
129
- getLatestRun(routineId: string): RoutineRun | null;
130
+ updateRun(args: {
131
+ readonly id: string;
132
+ readonly patch: Partial<RoutineRun>;
133
+ }): void;
134
+ getLatestRun(args: {
135
+ readonly routineId: string;
136
+ }): RoutineRun | null;
130
137
  }
131
138
  //# sourceMappingURL=types.d.ts.map
@@ -13,7 +13,9 @@ export interface RunStatusForAnalytics {
13
13
  * @param status - Raw status string from the run record (e.g. 'succeeded', 'canceled').
14
14
  * @returns 'success', 'cancelled', or 'failed'.
15
15
  */
16
- export declare function runResultFromStatus(status: string | undefined): RunResult;
16
+ export declare function runResultFromStatus({ status }: {
17
+ readonly status: string | undefined;
18
+ }): RunResult;
17
19
  /**
18
20
  * Derives a non-empty `error_code` for analytics whenever `result === 'failed'`.
19
21
  * Prefers the structured code stamped on the run; falls back to signal, exit
@@ -21,5 +23,7 @@ export declare function runResultFromStatus(status: string | undefined): RunResu
21
23
  * @param status - Run status fields including any stamped error code, exit code, and signal.
22
24
  * @returns An error code string, or `undefined` when the run succeeded.
23
25
  */
24
- export declare function deriveRunErrorCode(status: RunStatusForAnalytics): string | undefined;
26
+ export declare function deriveRunErrorCode({ status }: {
27
+ readonly status: RunStatusForAnalytics;
28
+ }): string | undefined;
25
29
  //# sourceMappingURL=result.d.ts.map
@@ -14,7 +14,7 @@
14
14
  * @param status - Raw status string from the run record (e.g. 'succeeded', 'canceled').
15
15
  * @returns 'success', 'cancelled', or 'failed'.
16
16
  */
17
- export function runResultFromStatus(status) {
17
+ export function runResultFromStatus({ status }) {
18
18
  if (status === 'succeeded')
19
19
  return 'success';
20
20
  if (status === 'canceled')
@@ -28,8 +28,8 @@ export function runResultFromStatus(status) {
28
28
  * @param status - Run status fields including any stamped error code, exit code, and signal.
29
29
  * @returns An error code string, or `undefined` when the run succeeded.
30
30
  */
31
- export function deriveRunErrorCode(status) {
32
- const result = runResultFromStatus(status.status);
31
+ export function deriveRunErrorCode({ status }) {
32
+ const result = runResultFromStatus({ status: status.status });
33
33
  if (result === 'success')
34
34
  return undefined;
35
35
  // Cancellation usually carries no error; only forward an explicit one
@@ -19,7 +19,12 @@ export declare const MAX_RETRY_BACKOFF_DELAY_MS = 8000;
19
19
  * @param random - Optional jitter source; defaults to `Math.random` for production use.
20
20
  * @returns Backoff duration in milliseconds, capped at `MAX_RETRY_BACKOFF_DELAY_MS`.
21
21
  */
22
- export declare function computeRetryBackoffMs(attemptIndex: number, category: RunFailureCategory | undefined, random?: () => number): number;
22
+ export declare function computeRetryBackoffMs({ attemptIndex, category }: {
23
+ readonly attemptIndex: number;
24
+ readonly category: RunFailureCategory | undefined;
25
+ }, { random }?: {
26
+ readonly random?: () => number;
27
+ }): number;
23
28
  /** Failure signal fields extracted from a run's error state, used by the retry policy. */
24
29
  export interface RunRetryFailureSignal {
25
30
  failure_category?: RunFailureCategory;
@@ -70,7 +75,10 @@ export type RunRetryPolicyDecision = {
70
75
  * @returns A `RunRetryFailureSignal` suitable for {@link decideSafeRunRetry}.
71
76
  * @complexity O(1).
72
77
  */
73
- export declare function classifyProcessExitFailure(code: number | null, signal: string | null): RunRetryFailureSignal;
78
+ export declare function classifyProcessExitFailure({ code, signal }: {
79
+ readonly code: number | null;
80
+ readonly signal: string | null;
81
+ }): RunRetryFailureSignal;
74
82
  /**
75
83
  * `@jini-ai/daemon`'s `ClassifyFailure` port needs a plain `boolean`, not a full
76
84
  * {@link RunRetryPolicyDecision} — gap 4 only sets a failed run's `resumable` flag (informational
@@ -95,12 +103,17 @@ export declare function classifyProcessExitFailure(code: number | null, signal:
95
103
  * behavior for any other caller.
96
104
  * @complexity O(1).
97
105
  */
98
- export declare function resumableFromProcessExit(code: number | null, signal: string | null, sideEffects?: Pick<RunRetrySideEffectState, 'userVisibleOutputSeen' | 'toolCallSeen'>): boolean;
106
+ export declare function resumableFromProcessExit({ code, signal }: {
107
+ readonly code: number | null;
108
+ readonly signal: string | null;
109
+ }, { sideEffects }?: {
110
+ readonly sideEffects?: Pick<RunRetrySideEffectState, 'userVisibleOutputSeen' | 'toolCallSeen'>;
111
+ }): boolean;
99
112
  /**
100
113
  * Decides whether a failed run should be automatically retried and, if so, schedules the delay.
101
114
  * Suppresses retries when the run was cancelled, emitted user-visible output, or hit a non-transient failure.
102
115
  * @param input - Run outcome, failure classification, attempt count, and observable side effects.
103
116
  * @returns A `RunRetryPolicyDecision` with `shouldRetry: true` and a delay, or `shouldRetry: false` with a suppression reason.
104
117
  */
105
- export declare function decideSafeRunRetry(input: RunRetryPolicyInput): RunRetryPolicyDecision;
118
+ export declare function decideSafeRunRetry(requiredArgs: Pick<RunRetryPolicyInput, "result" | "attemptCount">, optionalArgs?: Pick<RunRetryPolicyInput, "failure" | "maxAttempts" | "sideEffects" | "random">): RunRetryPolicyDecision;
106
119
  //# sourceMappingURL=retry.d.ts.map
@@ -37,7 +37,7 @@ function backoffBaseDelayMs(category) {
37
37
  * @param random - Optional jitter source; defaults to `Math.random` for production use.
38
38
  * @returns Backoff duration in milliseconds, capped at `MAX_RETRY_BACKOFF_DELAY_MS`.
39
39
  */
40
- export function computeRetryBackoffMs(attemptIndex, category, random = Math.random) {
40
+ export function computeRetryBackoffMs({ attemptIndex, category }, { random = Math.random } = {}) {
41
41
  const exponent = Math.max(0, Math.floor(attemptIndex) - 1);
42
42
  const raw = backoffBaseDelayMs(category) * RETRY_BACKOFF_MULTIPLIER ** exponent;
43
43
  const capped = Math.min(raw, MAX_RETRY_BACKOFF_DELAY_MS);
@@ -57,7 +57,7 @@ export function computeRetryBackoffMs(attemptIndex, category, random = Math.rand
57
57
  * @returns A `RunRetryFailureSignal` suitable for {@link decideSafeRunRetry}.
58
58
  * @complexity O(1).
59
59
  */
60
- export function classifyProcessExitFailure(code, signal) {
60
+ export function classifyProcessExitFailure({ code, signal }) {
61
61
  if (signal !== null) {
62
62
  return { failure_category: 'process_exit', failure_detail: 'signal_killed', retryable: true };
63
63
  }
@@ -90,13 +90,8 @@ export function classifyProcessExitFailure(code, signal) {
90
90
  * behavior for any other caller.
91
91
  * @complexity O(1).
92
92
  */
93
- export function resumableFromProcessExit(code, signal, sideEffects) {
94
- const decision = decideSafeRunRetry({
95
- result: 'failed',
96
- failure: classifyProcessExitFailure(code, signal),
97
- attemptCount: 0,
98
- ...(sideEffects !== undefined ? { sideEffects } : {}),
99
- });
93
+ export function resumableFromProcessExit({ code, signal }, { sideEffects } = {}) {
94
+ const decision = decideSafeRunRetry({ result: 'failed', attemptCount: 0 }, { failure: classifyProcessExitFailure({ code: code, signal: signal }), ...(sideEffects !== undefined ? { sideEffects } : {}) });
100
95
  return decision.shouldRetry;
101
96
  }
102
97
  function normalizeAttemptCount(attemptCount) {
@@ -171,7 +166,8 @@ function transientSuppressedReason(category, detail, stage) {
171
166
  * @param input - Run outcome, failure classification, attempt count, and observable side effects.
172
167
  * @returns A `RunRetryPolicyDecision` with `shouldRetry: true` and a delay, or `shouldRetry: false` with a suppression reason.
173
168
  */
174
- export function decideSafeRunRetry(input) {
169
+ export function decideSafeRunRetry(requiredArgs, optionalArgs = {}) {
170
+ const input = { ...requiredArgs, ...optionalArgs };
175
171
  const attemptCount = normalizeAttemptCount(input.attemptCount);
176
172
  const retryMaxAttempts = normalizeMaxAttempts(input.maxAttempts);
177
173
  const retryAttemptIndex = attemptCount + 1;
@@ -216,7 +212,7 @@ export function decideSafeRunRetry(input) {
216
212
  ...base,
217
213
  shouldRetry: true,
218
214
  retryReason: 'transient_failure',
219
- retryDelayMs: computeRetryBackoffMs(retryAttemptIndex, failure.failure_category, input.random),
215
+ retryDelayMs: computeRetryBackoffMs({ attemptIndex: retryAttemptIndex, category: failure.failure_category }, input.random === undefined ? {} : { random: input.random }),
220
216
  };
221
217
  }
222
218
  //# sourceMappingURL=retry.js.map
@@ -6,7 +6,9 @@
6
6
  * `redactSecrets`). Defaults to identity so a caller that has already scrubbed —
7
7
  * or genuinely wants the raw tail — need not pass one.
8
8
  */
9
- export type TailRedactor = (text: string) => string;
9
+ export type TailRedactor = (args: {
10
+ text: string;
11
+ }) => string;
10
12
  /** A recorded run event entry passed to diagnostics collection functions for scanning. */
11
13
  export interface RunEventForDiagnostics {
12
14
  event: string;
@@ -48,7 +50,9 @@ export type StdoutTailSummary = StreamTailSummary;
48
50
  * @param count - Total number of non-empty lines in the stream.
49
51
  * @returns A `StderrLineCountBucket` string for use in analytics payloads.
50
52
  */
51
- export declare function stderrLineCountBucket(count: number): StderrLineCountBucket;
53
+ export declare function stderrLineCountBucket({ count }: {
54
+ readonly count: number;
55
+ }): StderrLineCountBucket;
52
56
  /**
53
57
  * Collects the tail of the stderr stream from a run's event list, scrubbed by the
54
58
  * supplied redactor. Returns `undefined` when no stderr output was recorded.
@@ -56,7 +60,10 @@ export declare function stderrLineCountBucket(count: number): StderrLineCountBuc
56
60
  * @param redact - Secret/PII scrubber applied to the joined tail; defaults to identity.
57
61
  * @returns A `StderrTailSummary` with the last 20 lines (capped at 4 KB) and a truncation flag, or `undefined`.
58
62
  */
59
- export declare function collectStderrTailSummary(events?: RunEventForDiagnostics[], redact?: TailRedactor): StderrTailSummary | undefined;
63
+ export declare function collectStderrTailSummary(_requiredArgs: Record<string, never>, { events, redact }?: {
64
+ readonly events?: RunEventForDiagnostics[];
65
+ readonly redact?: TailRedactor;
66
+ }): StderrTailSummary | undefined;
60
67
  /**
61
68
  * Collects the tail of the stdout stream from a run's event list, scrubbed by the
62
69
  * supplied redactor. Returns `undefined` when no stdout output was recorded.
@@ -64,7 +71,10 @@ export declare function collectStderrTailSummary(events?: RunEventForDiagnostics
64
71
  * @param redact - Secret/PII scrubber applied to the joined tail; defaults to identity.
65
72
  * @returns A `StdoutTailSummary` with the last 20 lines (capped at 4 KB) and a truncation flag, or `undefined`.
66
73
  */
67
- export declare function collectStdoutTailSummary(events?: RunEventForDiagnostics[], redact?: TailRedactor): StdoutTailSummary | undefined;
74
+ export declare function collectStdoutTailSummary(_requiredArgs: Record<string, never>, { events, redact }?: {
75
+ readonly events?: RunEventForDiagnostics[];
76
+ readonly redact?: TailRedactor;
77
+ }): StdoutTailSummary | undefined;
68
78
  /**
69
79
  * Produces the full `RunDiagnosticsAnalytics` payload for a completed run by scanning its event stream
70
80
  * and combining observed flags (tool calls, artifact writes, first token) with process-level signals.
@@ -1,5 +1,5 @@
1
1
  /** @module run/diagnostics/diagnostics — Stderr/stdout tail collection and diagnostic analytics summarization for completed runs. */
2
- const identityRedactor = (text) => text;
2
+ const identityRedactor = ({ text }) => text;
3
3
  const STDERR_TAIL_MAX_LINES = 20;
4
4
  const STDERR_TAIL_MAX_BYTES = 4 * 1024;
5
5
  function readStderrChunk(data) {
@@ -36,7 +36,7 @@ function countLines(text) {
36
36
  * @param count - Total number of non-empty lines in the stream.
37
37
  * @returns A `StderrLineCountBucket` string for use in analytics payloads.
38
38
  */
39
- export function stderrLineCountBucket(count) {
39
+ export function stderrLineCountBucket({ count }) {
40
40
  if (count <= 0)
41
41
  return 'none';
42
42
  if (count <= 5)
@@ -72,7 +72,7 @@ function collectStreamTailSummary(events, eventName, readChunk, redact) {
72
72
  const lines = streamText.trimEnd().split(/\r?\n/);
73
73
  const tailLines = lines.slice(-STDERR_TAIL_MAX_LINES);
74
74
  const lineTruncated = lines.length > tailLines.length;
75
- const redacted = redact(tailLines.join('\n'));
75
+ const redacted = redact({ text: tailLines.join('\n') });
76
76
  const byteCapped = truncateUtf8(redacted, STDERR_TAIL_MAX_BYTES);
77
77
  return {
78
78
  tail: byteCapped.value,
@@ -87,7 +87,7 @@ function collectStreamTailSummary(events, eventName, readChunk, redact) {
87
87
  * @param redact - Secret/PII scrubber applied to the joined tail; defaults to identity.
88
88
  * @returns A `StderrTailSummary` with the last 20 lines (capped at 4 KB) and a truncation flag, or `undefined`.
89
89
  */
90
- export function collectStderrTailSummary(events = [], redact = identityRedactor) {
90
+ export function collectStderrTailSummary(_requiredArgs, { events = [], redact = identityRedactor } = {}) {
91
91
  return collectStreamTailSummary(events, 'stderr', readStderrChunk, redact);
92
92
  }
93
93
  /**
@@ -97,7 +97,7 @@ export function collectStderrTailSummary(events = [], redact = identityRedactor)
97
97
  * @param redact - Secret/PII scrubber applied to the joined tail; defaults to identity.
98
98
  * @returns A `StdoutTailSummary` with the last 20 lines (capped at 4 KB) and a truncation flag, or `undefined`.
99
99
  */
100
- export function collectStdoutTailSummary(events = [], redact = identityRedactor) {
100
+ export function collectStdoutTailSummary(_requiredArgs, { events = [], redact = identityRedactor } = {}) {
101
101
  return collectStreamTailSummary(events, 'stdout', readStdoutChunk, redact);
102
102
  }
103
103
  /** The set of `rpc_close_reason` strings a `runtime_close` diagnostic may legitimately carry. */
@@ -254,9 +254,9 @@ export function summarizeRunDiagnosticsForAnalytics(args) {
254
254
  exitCode: args.exitCode,
255
255
  }),
256
256
  stderr_present: stderrPresent,
257
- stderr_line_count_bucket: stderrLineCountBucket(stderrLineCount),
257
+ stderr_line_count_bucket: stderrLineCountBucket({ count: stderrLineCount }),
258
258
  stdout_present: stdoutPresent,
259
- stdout_line_count_bucket: stderrLineCountBucket(stdoutLineCount),
259
+ stdout_line_count_bucket: stderrLineCountBucket({ count: stdoutLineCount }),
260
260
  rpc_close_reason: resolveRpcCloseReason(observed.recordedCloseReason, args),
261
261
  first_token_seen: args.firstTokenSeen === true,
262
262
  user_visible_output_seen: observed.userVisibleOutputSeen,
@@ -7,7 +7,7 @@
7
7
  * daemon's run capability barrel. Product telemetry (runtime-type / usage /
8
8
  * timing analytics), the vendor-specific failure classifier, artifact
9
9
  * filesystem snapshotting, and MCP tool-bundle resolution are deliberately
10
- * out of scope here — see `source-map.md`.
10
+ * out of scope here — see `archived provenance ledger`.
11
11
  */
12
12
  export { runResultFromStatus, deriveRunErrorCode, DEFAULT_SAFE_RUN_RETRY_MAX_ATTEMPTS, SAFE_RUN_RETRY_STRATEGY, RATE_LIMIT_RETRY_BASE_DELAY_MS, TRANSIENT_RETRY_BASE_DELAY_MS, RETRY_BACKOFF_MULTIPLIER, MAX_RETRY_BACKOFF_DELAY_MS, computeRetryBackoffMs, decideSafeRunRetry, classifyProcessExitFailure, resumableFromProcessExit, } from './core/index.js';
13
13
  export type { RunResult, RunStatusForAnalytics, RunFailureResult, RunFailureCategory, RunFailureDetail, RunFailureStage, RunRetryStrategy, RunRetrySuppressedReason, RunRetryFailureSignal, RunRetrySideEffectState, RunRetryPolicyInput, RunRetryPolicyDecision, } from './core/index.js';
package/dist/run/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * daemon's run capability barrel. Product telemetry (runtime-type / usage /
8
8
  * timing analytics), the vendor-specific failure classifier, artifact
9
9
  * filesystem snapshotting, and MCP tool-bundle resolution are deliberately
10
- * out of scope here — see `source-map.md`.
10
+ * out of scope here — see `archived provenance ledger`.
11
11
  */
12
12
  // core — result derivation, failure taxonomy, and retry policy
13
13
  export { runResultFromStatus, deriveRunErrorCode, DEFAULT_SAFE_RUN_RETRY_MAX_ATTEMPTS, SAFE_RUN_RETRY_STRATEGY, RATE_LIMIT_RETRY_BASE_DELAY_MS, TRANSIENT_RETRY_BASE_DELAY_MS, RETRY_BACKOFF_MULTIPLIER, MAX_RETRY_BACKOFF_DELAY_MS, computeRetryBackoffMs, decideSafeRunRetry, classifyProcessExitFailure, resumableFromProcessExit, } from './core/index.js';