deepline 0.3.525 → 0.3.526

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 (135) hide show
  1. package/dist/bundling-sources/sdk/src/agent-runtime.ts +98 -0
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/observability/dlq.ts +14 -5
  4. package/dist/bundling-sources/shared_libs/play-runtime/run-failure-class.ts +98 -0
  5. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-inventory.ts +2 -2
  6. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/durable-run-sql.ts +39 -0
  7. package/dist/cli/{auth-TH3VGYBK.mjs → auth-JATW5XZE.mjs} +5 -5
  8. package/dist/cli/auth-L2POG3LL.js +43 -0
  9. package/dist/cli/{billing-TWKVUFU2.js → billing-TSHBJIJS.js} +82 -82
  10. package/dist/cli/{billing-CMHFI2LN.mjs → billing-UT5LIESH.mjs} +7 -7
  11. package/dist/cli/{chunk-ZWFTHEPT.mjs → chunk-26ULNPQ7.mjs} +2 -2
  12. package/dist/cli/{chunk-OWQF6WVH.mjs → chunk-2GJW4RAQ.mjs} +61 -1
  13. package/dist/cli/{chunk-CZNEQMJR.mjs → chunk-2JNX3MDG.mjs} +1 -1
  14. package/dist/cli/{chunk-QR7VYYNM.js → chunk-3MYI3IXW.js} +7 -7
  15. package/dist/cli/{chunk-5JFAQUZS.js → chunk-3ZEV5BS5.js} +26 -26
  16. package/dist/cli/{chunk-NB2ECLQE.js → chunk-46HEYGLY.js} +9 -9
  17. package/dist/cli/{chunk-CKTRQSRA.js → chunk-477PXM65.js} +22 -22
  18. package/dist/cli/{chunk-WGRDOPAK.mjs → chunk-6COGHW7B.mjs} +2 -2
  19. package/dist/cli/{chunk-ESWM2JW4.js → chunk-6DHEV6IA.js} +2 -2
  20. package/dist/cli/{chunk-TO72GW5I.js → chunk-6H56LKJB.js} +16 -16
  21. package/dist/cli/{chunk-NO4URKKT.mjs → chunk-6JMWATX5.mjs} +5 -5
  22. package/dist/cli/{chunk-5BSGWIQD.mjs → chunk-77RAGJIZ.mjs} +2 -2
  23. package/dist/cli/{chunk-LE537GBC.js → chunk-7COEN3IR.js} +138 -78
  24. package/dist/cli/{chunk-WEYFSBAD.mjs → chunk-7FCD34YS.mjs} +18 -11
  25. package/dist/cli/{chunk-4UWXFXQF.js → chunk-B33J4YCC.js} +3 -3
  26. package/dist/cli/{chunk-7OF3A4KJ.mjs → chunk-BFH3DJYV.mjs} +84 -57
  27. package/dist/cli/{chunk-EP6YH6QJ.mjs → chunk-BVITYMBK.mjs} +2 -2
  28. package/dist/cli/{chunk-DYS3KWYF.js → chunk-BYEF4RBX.js} +11 -11
  29. package/dist/cli/{chunk-UXF3ODJJ.mjs → chunk-C3EW6I65.mjs} +1 -1
  30. package/dist/cli/{chunk-LXKH4MKH.js → chunk-CDP3LMDT.js} +6 -6
  31. package/dist/cli/{chunk-KBOSALBI.js → chunk-CYN2AHR6.js} +6 -6
  32. package/dist/cli/{chunk-OXFIJYN3.mjs → chunk-D2XMFXFM.mjs} +6 -6
  33. package/dist/cli/{chunk-AVDEYOVP.js → chunk-D5OEUPPM.js} +98 -98
  34. package/dist/cli/{chunk-YC7FKAJ4.mjs → chunk-DY2AT3JQ.mjs} +10 -10
  35. package/dist/cli/{chunk-N4MMU3QF.js → chunk-ED2N4NRI.js} +16 -16
  36. package/dist/cli/{chunk-7C4F4TLR.mjs → chunk-EEYZLTXX.mjs} +1 -1
  37. package/dist/cli/{chunk-CQSANB3V.js → chunk-F5KFGF45.js} +5 -5
  38. package/dist/cli/{chunk-2WFVLOB7.js → chunk-FMPGWAIR.js} +1 -1
  39. package/dist/cli/{chunk-KPINGHIF.mjs → chunk-HPACLONQ.mjs} +2 -2
  40. package/dist/cli/{chunk-TXSBPBHB.mjs → chunk-IMP7WR22.mjs} +5 -5
  41. package/dist/cli/{chunk-RMZ6CISE.mjs → chunk-IWLDJQGV.mjs} +3 -3
  42. package/dist/cli/{chunk-P62LON53.js → chunk-J5OXJ4JI.js} +2 -2
  43. package/dist/cli/{chunk-UQYKSOGO.mjs → chunk-MQB25LMV.mjs} +5 -5
  44. package/dist/cli/{chunk-KEZ3KBWW.js → chunk-O7WUATQC.js} +97 -70
  45. package/dist/cli/{chunk-V2GN4PLK.js → chunk-RZJWHL7L.js} +5 -5
  46. package/dist/cli/{chunk-NRBCETWL.js → chunk-SCLRGDF4.js} +44 -44
  47. package/dist/cli/{chunk-V65J64FL.js → chunk-SJ6KUCGM.js} +53 -53
  48. package/dist/cli/{chunk-MHBSRNI7.js → chunk-TBQC2XS3.js} +41 -41
  49. package/dist/cli/{chunk-JVWSIA2V.mjs → chunk-TCLJXJAG.mjs} +4 -4
  50. package/dist/cli/{chunk-ETHVJ2ZE.mjs → chunk-TVHDWS5U.mjs} +1 -1
  51. package/dist/cli/{chunk-U4M32NFS.mjs → chunk-TXJW6RIM.mjs} +1 -1
  52. package/dist/cli/{chunk-LAMGJQDY.mjs → chunk-U6OUX47C.mjs} +2 -2
  53. package/dist/cli/{chunk-S5LUY3KJ.js → chunk-UTCGCES2.js} +7 -7
  54. package/dist/cli/{chunk-VYIAWAKJ.mjs → chunk-UUIC2JFZ.mjs} +1 -1
  55. package/dist/cli/{chunk-WA3FG7DH.js → chunk-UWCEBS7F.js} +14 -14
  56. package/dist/cli/{chunk-MRUFGOJR.js → chunk-WBY3R55B.js} +2 -2
  57. package/dist/cli/{chunk-TFEGJEYO.js → chunk-WITNIMLE.js} +3 -3
  58. package/dist/cli/{chunk-CWRL6IQP.js → chunk-WL6GAZBD.js} +18 -11
  59. package/dist/cli/{chunk-CLTL7ZJI.mjs → chunk-WOLY6SU4.mjs} +1 -1
  60. package/dist/cli/{chunk-GCLNX72G.mjs → chunk-XVIMOB2U.mjs} +2 -2
  61. package/dist/cli/{chunk-IMO3HXWZ.mjs → chunk-Y47OCS5V.mjs} +1 -1
  62. package/dist/cli/{chunk-M43ZYNDA.mjs → chunk-YNFPZVII.mjs} +5 -5
  63. package/dist/cli/command-docs.js +2 -2
  64. package/dist/cli/command-docs.mjs +1 -1
  65. package/dist/cli/{csv-OO554TPX.mjs → csv-4BLFRED6.mjs} +4 -4
  66. package/dist/cli/{csv-5JHWVJ5N.js → csv-KSJB5Z3M.js} +13 -13
  67. package/dist/cli/{db-CYQJ4OXF.js → db-G7Z5CKO2.js} +27 -27
  68. package/dist/cli/{db-SQKJ6RKU.mjs → db-OVW6C3DV.mjs} +6 -6
  69. package/dist/cli/describe-KMYR2JBC.js +50 -0
  70. package/dist/cli/{describe-N7AKTUQV.mjs → describe-OEFTD7WQ.mjs} +18 -18
  71. package/dist/cli/{executions-F34DORW6.mjs → executions-7ZKQ4ZU3.mjs} +6 -6
  72. package/dist/cli/{executions-K7EGCRKX.js → executions-O7USCBCW.js} +8 -8
  73. package/dist/cli/{feedback-GQHKCS66.mjs → feedback-KUBL5E3I.mjs} +61 -13
  74. package/dist/cli/{feedback-NOQVCA3Q.js → feedback-Y55WCRIQ.js} +65 -17
  75. package/dist/cli/{git-2EEITXDB.mjs → git-C6ZAU5JA.mjs} +5 -5
  76. package/dist/cli/git-NBVQ3VGW.js +25 -0
  77. package/dist/cli/index.js +145 -145
  78. package/dist/cli/index.mjs +44 -44
  79. package/dist/cli/{legacy-noops-JHMY5XRB.mjs → legacy-noops-MUXD4HRC.mjs} +6 -6
  80. package/dist/cli/{legacy-noops-RFNHQ7RG.js → legacy-noops-OVWX4KB3.js} +9 -9
  81. package/dist/cli/{monitors-RDMP6SPZ.mjs → monitors-2ZSGBY52.mjs} +7 -7
  82. package/dist/cli/{monitors-UKRZ4BDK.js → monitors-3QVYGYWA.js} +100 -100
  83. package/dist/cli/{org-RF3G4KMB.mjs → org-RDSPE5FB.mjs} +6 -6
  84. package/dist/cli/{org-OX7TYTHV.js → org-S6Z3SDLI.js} +86 -86
  85. package/dist/cli/{pages-FBM3MGSP.mjs → pages-K5DSMHLJ.mjs} +6 -6
  86. package/dist/cli/{pages-MKQT5LFV.js → pages-VUWF2OR7.js} +18 -18
  87. package/dist/cli/{play-YWC2UORM.mjs → play-PZLXOYEX.mjs} +18 -18
  88. package/dist/cli/{play-OOVX2DMV.js → play-SQOJTUFC.js} +317 -317
  89. package/dist/cli/{providers-3PEQESIU.mjs → providers-AMIGP3D4.mjs} +6 -6
  90. package/dist/cli/{providers-2CGZYLER.js → providers-FZBEPUOI.js} +9 -9
  91. package/dist/cli/{quickstart-KVB36SOW.mjs → quickstart-HNOQKGOF.mjs} +4 -4
  92. package/dist/cli/{quickstart-6AANHKQZ.js → quickstart-QIHZDBGM.js} +6 -6
  93. package/dist/cli/{run-NJ7WV5TK.js → run-IQGM3TO2.js} +41 -41
  94. package/dist/cli/{run-QC23NRKO.mjs → run-JDW6BDNT.mjs} +23 -23
  95. package/dist/cli/search-BNWRL3YY.js +33 -0
  96. package/dist/cli/{search-7BMFFZI2.mjs → search-DMVUKJ23.mjs} +8 -8
  97. package/dist/cli/{search-output-CALZ4ZI2.mjs → search-output-5UAPUUHH.mjs} +4 -4
  98. package/dist/cli/{search-output-XC2AVBFX.js → search-output-UUW6UNHF.js} +6 -6
  99. package/dist/cli/{secrets-7ZHA57DI.mjs → secrets-46KSTPFN.mjs} +6 -6
  100. package/dist/cli/{secrets-VHU4B2D4.js → secrets-U532KN24.js} +15 -15
  101. package/dist/cli/sessions-JZUONXH4.js +22 -0
  102. package/dist/cli/sessions-RUNWYHYX.mjs +22 -0
  103. package/dist/cli/{settings-AVY4NNHI.mjs → settings-56L3WHCY.mjs} +13 -13
  104. package/dist/cli/{settings-WV77QJGD.js → settings-O2A37FFA.js} +86 -86
  105. package/dist/cli/{setup-GE5TLTC4.js → setup-ETFSMSCH.js} +50 -50
  106. package/dist/cli/{setup-AOUJ3RMU.mjs → setup-Q27X6JZY.mjs} +10 -10
  107. package/dist/cli/skills-IKDJ5JDN.js +37 -0
  108. package/dist/cli/{skills-FVWO2G66.mjs → skills-WFQRZL4D.mjs} +8 -8
  109. package/dist/cli/tools-B735AA67.js +57 -0
  110. package/dist/cli/{tools-URE655B4.mjs → tools-EV6CKJOX.mjs} +17 -17
  111. package/dist/cli/update-CNNURAM3.js +35 -0
  112. package/dist/cli/{update-5B4G4345.mjs → update-KIPPFVCH.mjs} +10 -10
  113. package/dist/cli/{views-IC762HEQ.js → views-DNZ2HFTA.js} +18 -18
  114. package/dist/cli/{views-GSECJ5IK.mjs → views-LMJXWD4N.mjs} +6 -6
  115. package/dist/cli/{workflow-6UQM565I.mjs → workflow-3XKUQ73U.mjs} +7 -7
  116. package/dist/cli/{workflow-EME7ZEOV.js → workflow-ZUDTIOK6.js} +17 -17
  117. package/dist/index.js +9 -9
  118. package/dist/index.mjs +6 -6
  119. package/dist/install-integrity.json +107 -106
  120. package/dist/release.d.mts +1 -1
  121. package/dist/release.d.ts +1 -1
  122. package/dist/release.js +2 -2
  123. package/dist/release.mjs +1 -1
  124. package/dist/server.js +5 -5
  125. package/dist/server.mjs +3 -3
  126. package/package.json +1 -1
  127. package/dist/cli/auth-K7PMRXNG.js +0 -43
  128. package/dist/cli/describe-PASXOL3R.js +0 -50
  129. package/dist/cli/git-UU4YFJ2Q.js +0 -25
  130. package/dist/cli/search-NH4DTXUK.js +0 -33
  131. package/dist/cli/sessions-2TE5JWVP.js +0 -18
  132. package/dist/cli/sessions-YYULWFZE.mjs +0 -18
  133. package/dist/cli/skills-OL7LD6QX.js +0 -37
  134. package/dist/cli/tools-VQ5JO6DI.js +0 -57
  135. package/dist/cli/update-7ZOIOTZN.js +0 -35
@@ -1,4 +1,6 @@
1
+ import { readdirSync, statSync } from 'node:fs';
1
2
  import { homedir } from 'node:os';
3
+ import { basename, join } from 'node:path';
2
4
 
3
5
  const EXPLICIT_AGENT_RUNTIMES = new Set([
4
6
  'claude_code',
@@ -67,6 +69,102 @@ export function agentSessionIdFromEnvironment(
67
69
  return null;
68
70
  }
69
71
 
72
+ const SESSION_UUID_RE =
73
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
74
+
75
+ /** Whether a value has the UUID shape Claude and Codex session IDs use. */
76
+ export function isAgentSessionId(value: string): boolean {
77
+ return SESSION_UUID_RE.test(value);
78
+ }
79
+
80
+ /**
81
+ * The VM home of a Claude Cowork session, `/sessions/<name>`, taken from HOME
82
+ * or, when HOME is the bare `/sessions`, the working directory. These are the
83
+ * same homes isCoworkLikeSandbox treats as Cowork.
84
+ */
85
+ export function coworkSessionHome(
86
+ env: Readonly<Record<string, string | undefined>> = process.env,
87
+ cwd: string = process.cwd(),
88
+ ): string | null {
89
+ const home = env.HOME?.trim() || homedir();
90
+ const path = home === '/sessions' ? cwd : home;
91
+ return path.match(/^\/sessions\/(?!\.\.?(?:\/|$))[^/]+/)?.[0] ?? null;
92
+ }
93
+
94
+ /**
95
+ * Directories holding Claude transcripts as `<root>/<project>/<id>.jsonl`:
96
+ * CLAUDE_CONFIG_DIR, the Cowork session's mounted config dir, then ~/.claude.
97
+ */
98
+ export function claudeProjectsRoots(
99
+ env: Readonly<Record<string, string | undefined>> = process.env,
100
+ cwd: string = process.cwd(),
101
+ ): string[] {
102
+ const roots: string[] = [];
103
+ const configDir = env.CLAUDE_CONFIG_DIR?.trim();
104
+ if (configDir) roots.push(join(configDir, 'projects'));
105
+ const coworkHome = coworkSessionHome(env, cwd);
106
+ if (coworkHome) roots.push(coworkProjectsRoot(coworkHome));
107
+ roots.push(join(env.HOME?.trim() || homedir(), '.claude', 'projects'));
108
+ return [...new Set(roots)];
109
+ }
110
+
111
+ /**
112
+ * Cowork mounts each session's own Claude config dir at `~/mnt/.claude`, so
113
+ * its transcripts live in `~/mnt/.claude/projects/<project>/<id>.jsonl`.
114
+ */
115
+ function coworkProjectsRoot(coworkHome: string): string {
116
+ return join(coworkHome, 'mnt', '.claude', 'projects');
117
+ }
118
+
119
+ export type AgentTranscript = { sessionId: string; filePath: string };
120
+
121
+ /**
122
+ * The transcript of the Claude Cowork session this process runs in, or null
123
+ * outside Cowork or before the transcript exists. Cowork does not reliably
124
+ * pass CLAUDE_CODE_SESSION_ID to commands, but each session has its own
125
+ * config dir, so its newest transcript is the current session.
126
+ */
127
+ export function coworkTranscriptFromEnvironment(
128
+ env: Readonly<Record<string, string | undefined>> = process.env,
129
+ cwd: string = process.cwd(),
130
+ ): AgentTranscript | null {
131
+ const coworkHome = coworkSessionHome(env, cwd);
132
+ if (!coworkHome) return null;
133
+ const root = coworkProjectsRoot(coworkHome);
134
+ let newest: (AgentTranscript & { mtimeMs: number }) | null = null;
135
+ for (const project of readDirectoryNames(root)) {
136
+ for (const fileName of readDirectoryNames(join(root, project))) {
137
+ const sessionId = basename(fileName, '.jsonl');
138
+ if (!fileName.endsWith('.jsonl') || !SESSION_UUID_RE.test(sessionId)) {
139
+ continue;
140
+ }
141
+ const filePath = join(root, project, fileName);
142
+ let mtimeMs: number;
143
+ try {
144
+ const stat = statSync(filePath);
145
+ if (!stat.isFile()) continue;
146
+ mtimeMs = stat.mtimeMs;
147
+ } catch {
148
+ continue;
149
+ }
150
+ if (!newest || mtimeMs > newest.mtimeMs) {
151
+ newest = { sessionId, filePath, mtimeMs };
152
+ }
153
+ }
154
+ }
155
+ return newest
156
+ ? { sessionId: newest.sessionId, filePath: newest.filePath }
157
+ : null;
158
+ }
159
+
160
+ function readDirectoryNames(dir: string): string[] {
161
+ try {
162
+ return readdirSync(dir);
163
+ } catch {
164
+ return [];
165
+ }
166
+ }
167
+
70
168
  export function isCoworkLikeSandbox(): boolean {
71
169
  const pluginMode = truthyEnv('DEEPLINE_PLUGIN_MODE');
72
170
  const claudeRemote = truthyEnv('CLAUDE_CODE_REMOTE');
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
205
205
  // getters keep their established compatibility behavior.
206
206
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
207
207
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
208
- version: '0.3.525',
208
+ version: '0.3.526',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -338,13 +338,18 @@ export type DurableRunNextActionKind =
338
338
 
339
339
  /**
340
340
  * Why a stopped durable run stopped. `play_error`: the Play's own error (the
341
- * customer's). `platform_recovery_exhausted`: Deepline's automatic recovery
342
- * ran out (resume it). `platform_failure`: another platform failure the
343
- * runtime recognizes. `cancelled`: cancelled (code names a platform cancel).
344
- * `unknown`: no stored terminal error.
341
+ * customer's). `provider_failure`: a provider call failed the run, by the
342
+ * run's structured failure origin (as the public run event classes it).
343
+ * `platform_recovery_exhausted`: Deepline's automatic recovery ran out
344
+ * (resume it). `platform_failure`: another platform failure the runtime
345
+ * recognizes. `cancelled`: cancelled (code names a platform cancel).
346
+ * `unknown`: no stored terminal error. Readers must tolerate classes they do
347
+ * not know: older servers never send `provider_failure`, and a newer one may
348
+ * add a class.
345
349
  */
346
350
  export const DURABLE_RUN_FAILURE_CLASSES = [
347
351
  'play_error',
352
+ 'provider_failure',
348
353
  'platform_recovery_exhausted',
349
354
  'platform_failure',
350
355
  'cancelled',
@@ -354,7 +359,11 @@ export type DurableRunFailureClass =
354
359
  (typeof DURABLE_RUN_FAILURE_CLASSES)[number];
355
360
 
356
361
  /** `failureCause` list filter of the `durable-play-runs` quarantined listing. */
357
- export const DURABLE_RUN_FAILURE_CAUSE_FILTERS = ['platform', 'play'] as const;
362
+ export const DURABLE_RUN_FAILURE_CAUSE_FILTERS = [
363
+ 'platform',
364
+ 'provider',
365
+ 'play',
366
+ ] as const;
358
367
  export type DurableRunFailureCauseFilter =
359
368
  (typeof DURABLE_RUN_FAILURE_CAUSE_FILTERS)[number];
360
369
 
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Who a failed Play run's structured failure belongs to.
3
+ *
4
+ * One classifier for every reader of a run's structured failure (`errors[0]`
5
+ * of the terminal result, or its ledger summary): the public run event and
6
+ * the durable scheduler's inventory read the same code sets, so they cannot
7
+ * disagree about a provider failure. No value imports, so the scheduler's
8
+ * light SQL module can use it.
9
+ */
10
+ import type {
11
+ ToolExecutionErrorCategory,
12
+ ToolExecutionErrorOrigin,
13
+ } from '../plays/tool-execution-error';
14
+
15
+ /** Mirrors `PROVIDER_EXHAUSTED_CODE` in `run-failure.ts`. */
16
+ export const PROVIDER_EXHAUSTED_FAILURE_CODE = 'PROVIDER_EXHAUSTED';
17
+
18
+ export const PLATFORM_RUN_FAILURE_CODES = [
19
+ 'BILLING_UNAVAILABLE',
20
+ 'MODAL_PAYLOAD_UPLOAD_TIMEOUT',
21
+ 'PLATFORM_DEPLOY_INTERRUPTED',
22
+ 'PLATFORM_WORKER_SUBREQUEST_INTERRUPTED',
23
+ 'PLATFORM_WORKFLOW_ENDPOINT_INTERRUPTED',
24
+ 'RUN_STORAGE_FAILED',
25
+ 'RUNTIME_RUNNER_LOST',
26
+ 'RUNTIME_SANDBOX_INSPECTION_UNAVAILABLE',
27
+ 'RUNTIME_SANDBOX_KILLED',
28
+ 'RUNTIME_SANDBOX_LOST',
29
+ 'RUNTIME_SANDBOX_START_FAILED',
30
+ 'WORKSPACE_STORAGE_NOT_READY',
31
+ ] as const;
32
+
33
+ export const CALLER_RUN_FAILURE_CODES = [
34
+ 'OUTPUT_TOO_LARGE',
35
+ 'PLAY_CALL_DEPTH_EXCEEDED',
36
+ 'RUNTIME_LIMIT_EXCEEDED',
37
+ // The controlled memory abort is the same caller-side resource fact as the
38
+ // OOM it replaces: the run's byte profile, not Deepline's platform, is what
39
+ // has to change before a retry can succeed.
40
+ 'RUNTIME_SANDBOX_MEMORY_ABORT',
41
+ 'RUNTIME_SANDBOX_OOM',
42
+ 'RUNTIME_SUSPENDED_CHECKPOINT_TOO_LARGE',
43
+ ] as const;
44
+
45
+ export const ACCOUNT_POLICY_RUN_FAILURE_CODES = [
46
+ 'INSUFFICIENT_CREDITS',
47
+ 'MONTHLY_CREDIT_CAP_EXCEEDED',
48
+ 'RUN_CREDIT_CAP_EXCEEDED',
49
+ 'SANDBOX_CAPACITY_EXCEEDED',
50
+ ] as const;
51
+
52
+ /**
53
+ * Codes whose class wins over the failure's `origin`: a provider-origin
54
+ * failure carrying one of these is not a provider failure.
55
+ */
56
+ export const RUN_FAILURE_CODES_CLASSED_BEFORE_ORIGIN = [
57
+ ...ACCOUNT_POLICY_RUN_FAILURE_CODES,
58
+ ...PLATFORM_RUN_FAILURE_CODES,
59
+ ...CALLER_RUN_FAILURE_CODES,
60
+ ] as const;
61
+
62
+ export type PlayRunFailureClass =
63
+ | 'account_policy'
64
+ | 'platform_failure'
65
+ | 'caller_failure'
66
+ | 'provider_failure'
67
+ | 'unknown_failure';
68
+
69
+ const ACCOUNT_POLICY = new Set<string>(ACCOUNT_POLICY_RUN_FAILURE_CODES);
70
+ const PLATFORM = new Set<string>(PLATFORM_RUN_FAILURE_CODES);
71
+ const CALLER = new Set<string>(CALLER_RUN_FAILURE_CODES);
72
+
73
+ export function playRunFailureClass(failure: {
74
+ readonly code: string;
75
+ readonly phase: string;
76
+ readonly origin?: ToolExecutionErrorOrigin;
77
+ readonly category?: ToolExecutionErrorCategory;
78
+ }): PlayRunFailureClass {
79
+ const code = failure.code.trim().toUpperCase();
80
+ if (ACCOUNT_POLICY.has(code)) return 'account_policy';
81
+ if (PLATFORM.has(code)) return 'platform_failure';
82
+ if (CALLER.has(code)) return 'caller_failure';
83
+ if (code === PROVIDER_EXHAUSTED_FAILURE_CODE) return 'provider_failure';
84
+
85
+ if (failure.origin === 'provider') return 'provider_failure';
86
+ if (failure.origin === 'caller') return 'caller_failure';
87
+ if (failure.origin === 'deepline') {
88
+ return failure.category === 'billing'
89
+ ? 'account_policy'
90
+ : 'platform_failure';
91
+ }
92
+ if (failure.origin === 'unknown') return 'unknown_failure';
93
+ if (failure.phase === 'infrastructure' || failure.phase === 'storage') {
94
+ return 'platform_failure';
95
+ }
96
+ if (failure.phase === 'billing') return 'account_policy';
97
+ return 'unknown_failure';
98
+ }
@@ -479,8 +479,8 @@ export async function listDurableRuns(
479
479
  limit: number;
480
480
  cursor?: string | null;
481
481
  /**
482
- * `failed` only: keep platform (exhausted recovery or platform failure)
483
- * or Play failures. Filters a bounded index slice like `recovering`.
482
+ * `failed` only: keep platform (exhausted recovery or platform failure),
483
+ * provider, or Play failures. Filters a bounded index slice like `recovering`.
484
484
  */
485
485
  cause?: DurableRunFailureCause | null;
486
486
  },
@@ -10,6 +10,7 @@ import {
10
10
  } from '../../observability/dlq';
11
11
  import { resolveRuntimeSchedulerSchemaEnv } from './runtime-scheduler-schema';
12
12
  import { RUNTIME_DB_SESSION_PRELOAD_INCOMPLETE } from '../play-admission-outcome';
13
+ import { RUN_FAILURE_CODES_CLASSED_BEFORE_ORIGIN } from '../run-failure-class';
13
14
 
14
15
  export type DurableRunSqlOptions = { readonly schema?: string };
15
16
  type Options = DurableRunSqlOptions;
@@ -58,6 +59,7 @@ export {
58
59
  /** `list --state failed --cause` → the classes it keeps. */
59
60
  export const DURABLE_RUN_FAILURE_CAUSES = {
60
61
  platform: ['platform_recovery_exhausted', 'platform_failure'],
62
+ provider: ['provider_failure'],
61
63
  play: ['play_error'],
62
64
  } as const satisfies Record<
63
65
  DurableRunFailureCauseFilter,
@@ -94,6 +96,35 @@ const RUNTIME_ERROR_CLASS_PREFIXES = [
94
96
  */
95
97
  export const DURABLE_RUN_FAILURE_MESSAGE_MAX_CHARS = 512;
96
98
 
99
+ /**
100
+ * SQL: whether `runs.terminal_result_json` holds a provider-owned structured
101
+ * failure, read exactly as the public run event reads it
102
+ * (`playRunFailureClass` over the first `errors[]` entry, or its ledger
103
+ * summary): a well-formed entry (string `code` and `phase`, boolean or null
104
+ * `retryable`) whose `origin` is `provider` and whose code is not classed
105
+ * before origin (account policy, platform or caller codes). `origin` is set
106
+ * only from a typed `ToolExecutionError`, never from text, so a Play that
107
+ * merely throws or mentions a provider code stays the Play's. Rows written
108
+ * without `errors[]` or `origin` (older runners, string-only failures, or a
109
+ * result too large to store) read as before. `PROVIDER_EXHAUSTED` without an
110
+ * origin is a text-derived code, so it stays the Play's here.
111
+ */
112
+ function durableRunProviderFailureSql(): string {
113
+ // Extract `errors[0]` once per row: every reference to
114
+ // `runs.terminal_result_json` re-reads the whole stored result (up to
115
+ // TERMINAL_RUN_RESULT_MAX_BYTES), while `entry.failure` is the small entry.
116
+ return `EXISTS (
117
+ SELECT 1
118
+ FROM (SELECT runs.terminal_result_json #> '{errors,0}' AS failure) AS entry
119
+ WHERE jsonb_typeof(entry.failure) = 'object'
120
+ AND jsonb_typeof(entry.failure -> 'code') = 'string'
121
+ AND jsonb_typeof(entry.failure -> 'phase') = 'string'
122
+ AND jsonb_typeof(entry.failure -> 'retryable') IN ('boolean', 'null')
123
+ AND entry.failure ->> 'origin' = 'provider'
124
+ AND upper(btrim(entry.failure ->> 'code')) <> ALL (ARRAY[${RUN_FAILURE_CODES_CLASSED_BEFORE_ORIGIN.map((code) => `'${code}'`).join(', ')}]::text[])
125
+ )`;
126
+ }
127
+
97
128
  /**
98
129
  * SQL: `LEFT JOIN LATERAL ... AS failure` over `runs`, yielding
99
130
  * `failure.failure_class`, `failure_code`, `failure_message` and
@@ -117,6 +148,12 @@ export const DURABLE_RUN_FAILURE_MESSAGE_MAX_CHARS = 512;
117
148
  * (`RUNTIME_MODAL_SANDBOX_CREATE_OUTCOME_UNKNOWN`) and a Modal payload upload
118
149
  * past its deadline (`MODAL_PAYLOAD_UPLOAD_TIMEOUT`). Only the leading code
119
150
  * position counts, so stored rows of any age read the same way.
151
+ *
152
+ * A failure no platform rule claims is `provider_failure` when the run's
153
+ * stored terminal result carries a provider-origin structured failure (see
154
+ * `durableRunProviderFailureSql`), the class the public run event gives it;
155
+ * otherwise `play_error`. `terminal_result_json` is read only on that branch,
156
+ * so platform-classed and non-failed rows never load it.
120
157
  */
121
158
  export function durableRunFailureLateralSql(): string {
122
159
  return `LEFT JOIN LATERAL (
@@ -132,6 +169,8 @@ export function durableRunFailureLateralSql(): string {
132
169
  OR parsed.code IN ('CTX_RUN_PLAY_INLINE_ONLY', '${RUNTIME_DB_SESSION_PRELOAD_INCOMPLETE}', ${PLATFORM_RUNTIME_FAILURE_CODES.map((code) => `'${code}'`).join(', ')})
133
170
  OR starts_with(parsed.code, 'SCHEDULER_')
134
171
  THEN 'platform_failure'
172
+ WHEN ${durableRunProviderFailureSql()}
173
+ THEN 'provider_failure'
135
174
  ELSE 'play_error'
136
175
  END AS failure_class,
137
176
  CASE
@@ -14,14 +14,14 @@ import {
14
14
  reportSetupCompleted,
15
15
  resolvePendingAuthClaimForResume,
16
16
  statusBannerLine
17
- } from "./chunk-RMZ6CISE.mjs";
18
- import "./chunk-GCLNX72G.mjs";
19
- import "./chunk-U4M32NFS.mjs";
20
- import "./chunk-OWQF6WVH.mjs";
17
+ } from "./chunk-IWLDJQGV.mjs";
18
+ import "./chunk-XVIMOB2U.mjs";
19
+ import "./chunk-TXJW6RIM.mjs";
20
+ import "./chunk-2GJW4RAQ.mjs";
21
21
  import "./chunk-QNHHZ63P.mjs";
22
22
  import "./chunk-DLIRSHV6.mjs";
23
23
  import "./chunk-ZPGGW27Q.mjs";
24
- import "./chunk-7C4F4TLR.mjs";
24
+ import "./chunk-EEYZLTXX.mjs";
25
25
  import "./chunk-WZYKRD7T.mjs";
26
26
  import "./chunk-KRD6H754.mjs";
27
27
  export {
@@ -0,0 +1,43 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ var _chunkSJ6KUCGMjs = require('./chunk-SJ6KUCGM.js');
18
+ require('./chunk-UTCGCES2.js');
19
+ require('./chunk-WITNIMLE.js');
20
+ require('./chunk-7COEN3IR.js');
21
+ require('./chunk-T2N3B7IQ.js');
22
+ require('./chunk-XNYIZMNQ.js');
23
+ require('./chunk-SQWET4SL.js');
24
+ require('./chunk-FMPGWAIR.js');
25
+ require('./chunk-OG64RBAC.js');
26
+ require('./chunk-COGTRVWW.js');
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ exports.EXIT_WORKSPACE_MISMATCH = _chunkSJ6KUCGMjs.EXIT_WORKSPACE_MISMATCH; exports.authStatusLine = _chunkSJ6KUCGMjs.authStatusLine; exports.clearPendingClaim = _chunkSJ6KUCGMjs.clearPendingClaim; exports.clearSatisfiedPendingClaim = _chunkSJ6KUCGMjs.clearSatisfiedPendingClaim; exports.handleRegister = _chunkSJ6KUCGMjs.handleRegister; exports.handleStatus = _chunkSJ6KUCGMjs.handleStatus; exports.handleWait = _chunkSJ6KUCGMjs.handleWait; exports.httpJson = _chunkSJ6KUCGMjs.httpJson; exports.readPendingAuthClaim = _chunkSJ6KUCGMjs.readPendingAuthClaim; exports.readStatusBanner = _chunkSJ6KUCGMjs.readStatusBanner; exports.registerAuthCommands = _chunkSJ6KUCGMjs.registerAuthCommands; exports.reportApprovalLinkShown = _chunkSJ6KUCGMjs.reportApprovalLinkShown; exports.reportSetupCompleted = _chunkSJ6KUCGMjs.reportSetupCompleted; exports.resolvePendingAuthClaimForResume = _chunkSJ6KUCGMjs.resolvePendingAuthClaimForResume; exports.statusBannerLine = _chunkSJ6KUCGMjs.statusBannerLine;