deepline 0.3.324 → 0.3.326

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 (133) hide show
  1. package/dist/bundling-sources/sdk/src/client.ts +23 -25
  2. package/dist/bundling-sources/sdk/src/compat.ts +11 -6
  3. package/dist/bundling-sources/sdk/src/db/query.ts +172 -0
  4. package/dist/bundling-sources/sdk/src/errors.ts +35 -0
  5. package/dist/bundling-sources/sdk/src/index.ts +13 -0
  6. package/dist/bundling-sources/sdk/src/play.ts +34 -31
  7. package/dist/bundling-sources/sdk/src/plays/authoring-graph-path.ts +13 -0
  8. package/dist/bundling-sources/sdk/src/plays/bundle-play-file.ts +2 -1
  9. package/dist/bundling-sources/sdk/src/plays/local-play-execution.ts +189 -0
  10. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  11. package/dist/bundling-sources/sdk/src/tool-calls.ts +1 -1
  12. package/dist/bundling-sources/sdk/src/types.ts +6 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +2 -0
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +7 -1
  15. package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +1 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +5 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +84 -10
  18. package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +9 -0
  19. package/dist/cli/auth-6STWK6UK.js +31 -0
  20. package/dist/cli/{auth-6KWNR6AI.mjs → auth-VON5FFUK.mjs} +4 -4
  21. package/dist/cli/{billing-VQ2NUJLB.mjs → billing-X6JUEFRE.mjs} +4 -4
  22. package/dist/cli/{billing-CLLWHIAT.js → billing-YI4RZI2O.js} +70 -70
  23. package/dist/cli/{chunk-NC2ZXG2Y.js → chunk-3NGWGFVL.js} +26 -26
  24. package/dist/cli/{chunk-5CQ554BM.mjs → chunk-4AB4Y6FF.mjs} +1 -1
  25. package/dist/cli/{chunk-EXKRHZRG.js → chunk-4LNBSQM4.js} +5928 -5730
  26. package/dist/cli/{chunk-G4F2AIQ5.js → chunk-5NXHSRRE.js} +6 -6
  27. package/dist/cli/{chunk-XNL3SEMC.js → chunk-AFNEQ43J.js} +8 -3
  28. package/dist/cli/{chunk-XSEMQ4II.js → chunk-AGH6YP2T.js} +2 -1
  29. package/dist/cli/chunk-AID3OYVJ.js +8 -0
  30. package/dist/cli/{chunk-HHZDWBSQ.mjs → chunk-BQJVMKWL.mjs} +1 -1
  31. package/dist/cli/{chunk-TJGJTB5T.mjs → chunk-BR7GGTAE.mjs} +24 -1
  32. package/dist/cli/{chunk-IXYR65PW.js → chunk-BUYZEUY4.js} +1 -1
  33. package/dist/cli/{chunk-GROXVGGW.js → chunk-CUUHQ3AO.js} +6 -6
  34. package/dist/cli/{chunk-NIOFMRYW.mjs → chunk-DFDXKOLR.mjs} +98 -113
  35. package/dist/cli/{chunk-GMO3NBE2.js → chunk-EMZ7Y5SW.js} +70 -67
  36. package/dist/cli/chunk-GVESPYSY.mjs +234 -0
  37. package/dist/cli/{chunk-N5E66DP3.js → chunk-GVYKY6T6.js} +344 -254
  38. package/dist/cli/{chunk-EHSI2DMO.mjs → chunk-IQCCGOQH.mjs} +4 -20
  39. package/dist/cli/{chunk-76VKBPOC.mjs → chunk-JOA6IKDE.mjs} +7 -2
  40. package/dist/cli/{chunk-3ZKAKQYC.mjs → chunk-KLWBAQ5A.mjs} +104 -14
  41. package/dist/cli/{chunk-PAA4FYCF.js → chunk-KZ4PCK4O.js} +29 -45
  42. package/dist/cli/chunk-LVEDPCLJ.js +234 -0
  43. package/dist/cli/{chunk-I7RLL7LN.mjs → chunk-M7CPVMDB.mjs} +1 -1
  44. package/dist/cli/{chunk-2UQUOUAW.js → chunk-MDQZQ3NY.js} +2 -2
  45. package/dist/cli/{chunk-V5PA6TCT.js → chunk-MKHSZA2X.js} +48 -48
  46. package/dist/cli/{chunk-LHJKYMTS.mjs → chunk-MOBZS4F3.mjs} +1 -1
  47. package/dist/cli/chunk-OVDNJAJN.mjs +8 -0
  48. package/dist/cli/{chunk-QM2Z4FQF.js → chunk-T33W6JUJ.js} +6 -6
  49. package/dist/cli/{chunk-DO2VA5UP.mjs → chunk-TDSNAC3C.mjs} +2 -2
  50. package/dist/cli/{chunk-D5YJHGST.js → chunk-TXVOB5J2.js} +29 -6
  51. package/dist/cli/{chunk-TZZNI2A4.js → chunk-TZQMFWLF.js} +147 -162
  52. package/dist/cli/{chunk-NQJQ3CLX.mjs → chunk-VGKVLADU.mjs} +3 -3
  53. package/dist/cli/{chunk-U2RPP53P.mjs → chunk-VKXGOQG5.mjs} +5674 -5476
  54. package/dist/cli/{chunk-AKM5JVPG.mjs → chunk-W74E5ETE.mjs} +12 -9
  55. package/dist/cli/{chunk-7PZFGB7L.mjs → chunk-YIY74KUF.mjs} +2 -1
  56. package/dist/cli/{chunk-5QZFWY7C.mjs → chunk-ZRN6YOF2.mjs} +2 -2
  57. package/dist/cli/client-TEBW2P24.js +20 -0
  58. package/dist/cli/{client-VHUKTDAZ.mjs → client-ZMOKUNL2.mjs} +3 -3
  59. package/dist/cli/{csv-5MZY7HU5.js → csv-HZRKEI7J.js} +12 -12
  60. package/dist/cli/{csv-7DA4APB6.mjs → csv-IICJHJZ4.mjs} +3 -3
  61. package/dist/cli/{db-ICG3FUVE.js → db-TM5NZF73.js} +226 -149
  62. package/dist/cli/{db-7UPW3N5U.mjs → db-X4B7YFNY.mjs} +214 -137
  63. package/dist/cli/{describe-VDRY2JCE.js → describe-BDBARWZJ.js} +28 -27
  64. package/dist/cli/{describe-ZAPGM5ND.mjs → describe-GMVS3LFC.mjs} +12 -11
  65. package/dist/cli/{executions-TK3C2FAQ.mjs → executions-447ZJMN4.mjs} +4 -4
  66. package/dist/cli/{executions-D5GYCY3A.js → executions-QX25UOQM.js} +6 -6
  67. package/dist/cli/{feedback-PZAZZUXF.js → feedback-4IXUTBX7.js} +6 -6
  68. package/dist/cli/{feedback-T4EIP5QR.mjs → feedback-JB7HHIC6.mjs} +3 -3
  69. package/dist/cli/git-C7C7DTEH.js +23 -0
  70. package/dist/cli/{git-WBFWIVO5.mjs → git-VID6KGAA.mjs} +4 -4
  71. package/dist/cli/index.js +105 -87
  72. package/dist/cli/index.mjs +65 -47
  73. package/dist/cli/{legacy-noops-LRBJWXRK.js → legacy-noops-3FYTCOZO.js} +7 -7
  74. package/dist/cli/{legacy-noops-DUCK7OKN.mjs → legacy-noops-SGR3G5WS.mjs} +4 -4
  75. package/dist/cli/{monitors-WYH5AQIO.mjs → monitors-SH4FOMBM.mjs} +4 -4
  76. package/dist/cli/{monitors-7S2SL62G.js → monitors-SP52UHS4.js} +85 -85
  77. package/dist/cli/{org-XCSMLTUW.mjs → org-B32MMIQT.mjs} +4 -4
  78. package/dist/cli/{org-EQNGGHPV.js → org-UQMX7JOR.js} +60 -60
  79. package/dist/cli/play-UCIWBN7U.js +153 -0
  80. package/dist/cli/{play-A5ISFBJM.mjs → play-XTE4LUP7.mjs} +11 -10
  81. package/dist/cli/{providers-DR2CLD3N.js → providers-JNMJJ2OH.js} +7 -7
  82. package/dist/cli/{providers-KHTZFQ5I.mjs → providers-RWLN6FUR.mjs} +4 -4
  83. package/dist/cli/{quickstart-NIRWI6YU.js → quickstart-HK6WZ342.js} +5 -5
  84. package/dist/cli/{quickstart-KT4LKORA.mjs → quickstart-IDB3Y375.mjs} +3 -3
  85. package/dist/cli/{search-WCEXPBAT.mjs → search-6D3IFNPT.mjs} +5 -5
  86. package/dist/cli/search-LUZ2S7DH.js +26 -0
  87. package/dist/cli/{secrets-QSFEZGVE.js → secrets-JOQB57IE.js} +13 -13
  88. package/dist/cli/{secrets-TN7DW3QR.mjs → secrets-TZ53CQ3D.mjs} +4 -4
  89. package/dist/cli/{sessions-WSE5FN4H.mjs → sessions-4MBDC4EK.mjs} +4 -4
  90. package/dist/cli/{sessions-LJS6W67T.js → sessions-QSAICDXX.js} +5 -5
  91. package/dist/cli/{settings-FGS3VYJN.js → settings-OTOCW7L7.js} +74 -74
  92. package/dist/cli/{settings-Z3V53A6J.mjs → settings-RKQFMLDU.mjs} +7 -7
  93. package/dist/cli/{setup-GMH4VJS3.mjs → setup-2S5TNTUB.mjs} +6 -6
  94. package/dist/cli/{setup-ZA234HEY.js → setup-AKZUDVYY.js} +41 -41
  95. package/dist/cli/skills-26LASHZF.js +28 -0
  96. package/dist/cli/{skills-7G2RZMYH.mjs → skills-AGZXDLSA.mjs} +4 -4
  97. package/dist/cli/{tools-7EE4BGXO.mjs → tools-7Y6RD6FY.mjs} +8 -7
  98. package/dist/cli/tools-L5VIJQWX.js +39 -0
  99. package/dist/cli/{update-O5QEWS7K.mjs → update-M7YGF67I.mjs} +6 -6
  100. package/dist/cli/update-MNHF6M2F.js +28 -0
  101. package/dist/cli/{workflow-KE54RUTR.mjs → workflow-CTVE7S7W.mjs} +5 -5
  102. package/dist/cli/{workflow-M5PAAW3O.js → workflow-NGMY425T.js} +15 -15
  103. package/dist/{client-BV68GMPo.d.ts → client-DHq8dJ56.d.ts} +45 -11
  104. package/dist/{client-D9ACjiRC.d.mts → client-wiWPZhnI.d.mts} +45 -11
  105. package/dist/{compiler-manifest-BXcZ4P4W.d.mts → compiler-manifest-9TkZ_ykI.d.mts} +717 -711
  106. package/dist/{compiler-manifest-BXcZ4P4W.d.ts → compiler-manifest-9TkZ_ykI.d.ts} +717 -711
  107. package/dist/index-B-5_Xhud.d.mts +75 -0
  108. package/dist/index-ykksoEyR.d.ts +75 -0
  109. package/dist/index.d.mts +52 -13
  110. package/dist/index.d.ts +52 -13
  111. package/dist/index.js +92 -28
  112. package/dist/index.mjs +91 -27
  113. package/dist/install-integrity.json +91 -84
  114. package/dist/plays/bundle-play-file.d.mts +7 -75
  115. package/dist/plays/bundle-play-file.d.ts +7 -75
  116. package/dist/plays/bundle-play-file.mjs +1 -1
  117. package/dist/plays/run-request.d.mts +2 -2
  118. package/dist/plays/run-request.d.ts +2 -2
  119. package/dist/release.d.mts +1 -1
  120. package/dist/release.d.ts +1 -1
  121. package/dist/release.js +2 -2
  122. package/dist/release.mjs +1 -1
  123. package/package.json +1 -1
  124. package/dist/cli/auth-LKSTC3YV.js +0 -31
  125. package/dist/cli/chunk-OWJZUE3Y.mjs +0 -103
  126. package/dist/cli/chunk-SDK3ZA2C.js +0 -103
  127. package/dist/cli/client-WMSTRUGP.js +0 -20
  128. package/dist/cli/git-73N6EUZ3.js +0 -23
  129. package/dist/cli/play-CLC2Z5SO.js +0 -152
  130. package/dist/cli/search-DM7IQS5F.js +0 -26
  131. package/dist/cli/skills-6APAQV6W.js +0 -28
  132. package/dist/cli/tools-EPYUFWPB.js +0 -38
  133. package/dist/cli/update-FPVX3XJC.js +0 -28
@@ -1,6 +1,10 @@
1
1
  import {
2
- DeeplineClient
3
- } from "./chunk-3ZKAKQYC.mjs";
2
+ shellQuote
3
+ } from "./chunk-OVDNJAJN.mjs";
4
+ import {
5
+ DeeplineClient,
6
+ planCustomerDbQuery
7
+ } from "./chunk-KLWBAQ5A.mjs";
4
8
  import "./chunk-CBVIJSHF.mjs";
5
9
  import {
6
10
  argsWantJson,
@@ -9,11 +13,14 @@ import {
9
13
  dataExportRows,
10
14
  markdownTableFromRows,
11
15
  printCommandEnvelope,
12
- recordRows
13
- } from "./chunk-I7RLL7LN.mjs";
14
- import "./chunk-TJGJTB5T.mjs";
16
+ recordRows,
17
+ shouldEmitJson
18
+ } from "./chunk-M7CPVMDB.mjs";
19
+ import {
20
+ CustomerDbQueryOutcomeUnknownError
21
+ } from "./chunk-BR7GGTAE.mjs";
15
22
  import "./chunk-DLIRSHV6.mjs";
16
- import "./chunk-HHZDWBSQ.mjs";
23
+ import "./chunk-BQJVMKWL.mjs";
17
24
  import "./chunk-6IKARAYD.mjs";
18
25
  import {
19
26
  DeeplineError
@@ -21,26 +28,18 @@ import {
21
28
  import "./chunk-WZYKRD7T.mjs";
22
29
  import "./chunk-KRD6H754.mjs";
23
30
 
24
- // src/cli/commands/db.ts
25
- import { readFileSync, writeFileSync } from "fs";
31
+ // src/cli/operations/db-query.ts
32
+ import { readFileSync } from "fs";
33
+ import { resolve as resolve2 } from "path";
34
+
35
+ // src/cli/renderers/db-query.ts
36
+ import { writeFileSync } from "fs";
26
37
  import { resolve } from "path";
27
- var CUSTOMER_DB_QUERY_FORMATS = /* @__PURE__ */ new Set(["table", "json", "csv", "markdown"]);
28
- var CUSTOMER_DB_QUERY_MAX_ROWS = 1e3;
29
- function parsePositiveInteger(value, flagName) {
30
- const parsed = Number.parseInt(value, 10);
31
- if (!Number.isFinite(parsed) || parsed <= 0) {
32
- throw new Error(`${flagName} must be a positive integer.`);
33
- }
34
- return parsed;
38
+ function queryIntentLine(operationKey) {
39
+ return operationKey === void 0 ? "The tool equivalent starts a new SQL execution; it cannot recover this unkeyed operation." : "The tool equivalent recovers this SQL operation through its original key.";
35
40
  }
36
- function parseMaxRows(value) {
37
- const parsed = parsePositiveInteger(value, "--max-rows");
38
- if (parsed > CUSTOMER_DB_QUERY_MAX_ROWS) {
39
- throw new Error(
40
- `--max-rows must be ${CUSTOMER_DB_QUERY_MAX_ROWS} or less. Add LIMIT/OFFSET to page larger exports.`
41
- );
42
- }
43
- return parsed;
41
+ function errorMessage(value) {
42
+ return value instanceof Error ? value.message : String(value ?? "");
44
43
  }
45
44
  function formatCell(value) {
46
45
  if (value === null || value === void 0) return "";
@@ -100,18 +99,6 @@ function customerDbRows(result) {
100
99
  function customerDbColumnNames(result) {
101
100
  return result.columns.map((column) => column.name).filter(Boolean);
102
101
  }
103
- function errorMessage(value) {
104
- return value instanceof Error ? value.message : String(value ?? "");
105
- }
106
- function resolveDbQuerySql(rawSql, readFile = (path) => readFileSync(path, "utf8")) {
107
- const value = rawSql.trim();
108
- if (!value.startsWith("@")) return value;
109
- const filePath = value.slice(1).trim();
110
- if (!filePath) {
111
- throw new Error("--sql @file requires a file path after `@`.");
112
- }
113
- return readFile(resolve(filePath)).trim();
114
- }
115
102
  function collectErrorText(value) {
116
103
  if (!value || typeof value !== "object" || Array.isArray(value)) {
117
104
  return errorMessage(value);
@@ -129,14 +116,15 @@ function collectErrorText(value) {
129
116
  ].filter(Boolean).join("\n");
130
117
  }
131
118
  function formatDbQueryError(sql, error) {
132
- const text = collectErrorText(error);
119
+ const text = error instanceof CustomerDbQueryOutcomeUnknownError ? collectErrorText(error.cause) : collectErrorText(error);
133
120
  const lower = text.toLowerCase();
134
121
  const referencesStorage = /"storage"\.|storage\./i.test(sql);
135
122
  const runIdColumnMissing = /column\s+"?run_id"?\s+does not exist/i.test(text) || /run_id.*does not exist/i.test(lower);
136
123
  const relationMissing = /relation\s+["']?[^"']*storage[^"']*["']?\s+does not exist/i.test(text) || /42p01/i.test(text);
137
124
  if (referencesStorage && relationMissing) {
138
125
  return [
139
- "Customer DB query failed: the referenced storage table does not exist.",
126
+ ...error instanceof CustomerDbQueryOutcomeUnknownError ? [error.message] : [],
127
+ error instanceof CustomerDbQueryOutcomeUnknownError ? "The server reported that the referenced storage table does not exist." : "Customer DB query failed: the referenced storage table does not exist.",
140
128
  "Play dataset tables are created only when the corresponding ctx.dataset(...).run(...) call executes. Pilot branches, early returns, and runs that fail before the dataset do not create that table.",
141
129
  "Use `deepline runs get <run-id> --full --json` to inspect returned dataset handles, then export them with `deepline runs export <run-id> --dataset result.rows --out rows.csv`.",
142
130
  `Original error: ${errorMessage(error)}`
@@ -144,6 +132,7 @@ function formatDbQueryError(sql, error) {
144
132
  }
145
133
  if (referencesStorage && runIdColumnMissing) {
146
134
  return [
135
+ ...error instanceof CustomerDbQueryOutcomeUnknownError ? [error.message] : [],
147
136
  "Customer DB query failed: storage dataset tables use `_run_id`, not `run_id`.",
148
137
  "Prefer `deepline runs export <run-id> --dataset result.rows --out rows.csv` unless you are doing deep table debugging.",
149
138
  `Original error: ${errorMessage(error)}`
@@ -154,28 +143,6 @@ function formatDbQueryError(sql, error) {
154
143
  }
155
144
  return errorMessage(error);
156
145
  }
157
- function dbRepairHumanLines(result) {
158
- const repair = result.repair;
159
- return [
160
- "Workspace storage repair completed.",
161
- ...repair ? [
162
- `Location changed: ${repair.location.changed ? "yes" : "no"}`,
163
- `Storage contract: ${repair.storage_contract.current ? "current" : "not ready"}`,
164
- `Runtime migration: ${repair.runtime_migration.current ? "current" : "not ready"}`,
165
- `Runtime capability probe: ${repair.runtime_capabilities.after.runtime_capabilities_ready ? "passed" : "failed"}`,
166
- `Materialized table grants reconciled: ${repair.materialized_tables.repaired_count}`
167
- ] : [
168
- "Runtime capability probe: unavailable from this server version",
169
- `Materialized table grants reconciled: ${result.count}`
170
- ],
171
- `Runtime role: ${result.connection_grants.runtime_role}`,
172
- `Customer DB role: ${result.connection_grants.customer_db_role}`
173
- ];
174
- }
175
- function dbRepairPlainText(result) {
176
- return result.repair ? "Workspace storage repair completed. Runtime capability probe passed.\n" : `Workspace storage repair completed. ${result.count} materialized table grant(s) reconciled; runtime capability probe unavailable.
177
- `;
178
- }
179
146
  function writeCustomerDbCsv(result, outPath) {
180
147
  const resolved = resolve(outPath);
181
148
  writeFileSync(
@@ -194,72 +161,41 @@ function dbQueryExportEnvelope(input) {
194
161
  row_count_returned: input.result.row_count_returned,
195
162
  truncated: input.result.truncated,
196
163
  ...input.outPath ? { file: input.outPath, local: { file: input.outPath } } : {},
197
- next: { toolEquivalent: input.toolCommand },
164
+ next: {
165
+ toolEquivalent: input.toolCommand,
166
+ executionIntent: input.operationKey === void 0 ? "new_execution" : "recover_original",
167
+ ...input.operationKey === void 0 ? {} : { recoverOperation: input.toolCommand }
168
+ },
198
169
  render: {
199
170
  sections: [
200
171
  {
201
172
  title: "customer db export",
202
173
  lines: [
203
- `Rendered ${input.result.row_count_returned} row(s) as ${input.format} to ${destination}`
174
+ `Rendered ${input.result.row_count_returned} row(s) as ${input.format} to ${destination}`,
175
+ queryIntentLine(input.operationKey)
204
176
  ]
205
177
  }
206
178
  ],
207
- actions: [{ label: "Tool equivalent", command: input.toolCommand }]
179
+ actions: [
180
+ {
181
+ label: "Tool equivalent",
182
+ command: input.toolCommand
183
+ }
184
+ ]
208
185
  }
209
186
  };
210
187
  }
211
- async function handleDbQuery(args) {
212
- const sqlIndex = args.indexOf("--sql");
213
- const rawSql = sqlIndex >= 0 ? args[sqlIndex + 1]?.trim() : "";
214
- if (!rawSql) {
215
- console.error(
216
- 'Usage: deepline db query --sql "select * from table limit 20"|@query.sql [--max-rows N] [--json]'
217
- );
218
- return 1;
219
- }
220
- let sql;
221
- try {
222
- sql = resolveDbQuerySql(rawSql);
223
- } catch (error) {
224
- console.error(errorMessage(error));
225
- return 1;
226
- }
227
- if (!sql) {
228
- console.error("SQL file is empty.");
229
- return 1;
230
- }
231
- const maxRowsIndex = args.indexOf("--max-rows");
232
- const maxRows = maxRowsIndex >= 0 && args[maxRowsIndex + 1] ? parseMaxRows(args[maxRowsIndex + 1]) : void 0;
233
- const formatIndex = args.indexOf("--format");
234
- const format = formatIndex >= 0 ? args[formatIndex + 1]?.trim().toLowerCase() : "";
235
- if (format && !CUSTOMER_DB_QUERY_FORMATS.has(format)) {
236
- console.error(
237
- 'Usage: deepline db query --sql "select * from table limit 20" [--format table|json|csv|markdown] [--out path]'
238
- );
239
- return 1;
240
- }
241
- const outIndex = args.indexOf("--out");
242
- const outPath = outIndex >= 0 ? args[outIndex + 1]?.trim() : "";
243
- if (outIndex >= 0 && !outPath) {
244
- console.error("--out requires a path.");
245
- return 1;
246
- }
247
- const jsonOutput = argsWantJson(args);
248
- const explicitJsonOutput = args.includes("--json");
249
- const client = new DeeplineClient();
250
- let result;
251
- try {
252
- result = await client.db.query({ sql, maxRows });
253
- } catch (error) {
254
- console.error(formatDbQueryError(sql, error));
255
- return 1;
256
- }
257
- const toolCommand = `deepline tools execute query_customer_db --payload ${JSON.stringify(
258
- {
259
- sql,
260
- ...maxRows ? { max_rows: maxRows } : {}
261
- }
262
- )} --json`;
188
+ function renderDbQueryResult(result, query, options) {
189
+ const { sql, maxRows, operationKey } = query;
190
+ const { format, out: outPath, json: explicitJsonOutput = false } = options;
191
+ const jsonOutput = explicitJsonOutput || shouldEmitJson();
192
+ const toolPayload = JSON.stringify({
193
+ sql,
194
+ result_mode: "rows",
195
+ ...maxRows ? { max_rows: maxRows } : {},
196
+ ...operationKey !== void 0 ? { operation_key: operationKey } : {}
197
+ });
198
+ const toolCommand = `deepline tools execute query_customer_db --payload ${shellQuote(toolPayload)} --json`;
263
199
  if (format === "csv") {
264
200
  if (outPath) {
265
201
  const exportedPath = writeCustomerDbCsv(result, outPath);
@@ -268,7 +204,8 @@ async function handleDbQuery(args) {
268
204
  result,
269
205
  format,
270
206
  outPath: exportedPath,
271
- toolCommand
207
+ toolCommand,
208
+ operationKey
272
209
  }),
273
210
  {
274
211
  json: jsonOutput,
@@ -276,14 +213,15 @@ async function handleDbQuery(args) {
276
213
  `
277
214
  }
278
215
  );
279
- return 0;
216
+ return;
280
217
  }
281
218
  printCommandEnvelope(
282
219
  dbQueryExportEnvelope({
283
220
  result,
284
221
  format,
285
222
  outPath: null,
286
- toolCommand
223
+ toolCommand,
224
+ operationKey
287
225
  }),
288
226
  {
289
227
  json: explicitJsonOutput,
@@ -293,7 +231,7 @@ async function handleDbQuery(args) {
293
231
  )
294
232
  }
295
233
  );
296
- return 0;
234
+ return;
297
235
  }
298
236
  if (format === "markdown") {
299
237
  const content = markdownTableFromRows(
@@ -308,7 +246,8 @@ async function handleDbQuery(args) {
308
246
  result,
309
247
  format,
310
248
  outPath: exportedPath,
311
- toolCommand
249
+ toolCommand,
250
+ operationKey
312
251
  }),
313
252
  {
314
253
  json: jsonOutput,
@@ -316,36 +255,170 @@ async function handleDbQuery(args) {
316
255
  `
317
256
  }
318
257
  );
319
- return 0;
258
+ return;
320
259
  }
321
260
  printCommandEnvelope(
322
261
  dbQueryExportEnvelope({
323
262
  result,
324
263
  format,
325
264
  outPath: null,
326
- toolCommand
265
+ toolCommand,
266
+ operationKey
327
267
  }),
328
268
  {
329
269
  json: explicitJsonOutput,
330
270
  text: content
331
271
  }
332
272
  );
333
- return 0;
273
+ return;
334
274
  }
335
275
  printCommandEnvelope(
336
276
  {
337
277
  ...result,
338
- next: { toolEquivalent: toolCommand },
278
+ next: {
279
+ toolEquivalent: toolCommand,
280
+ executionIntent: operationKey === void 0 ? "new_execution" : "recover_original",
281
+ ...operationKey === void 0 ? {} : { recoverOperation: toolCommand }
282
+ },
339
283
  render: {
340
- sections: [{ title: "customer db query", lines: tableLines(result) }],
341
- actions: [{ label: "Tool equivalent", command: toolCommand }]
284
+ sections: [
285
+ {
286
+ title: "customer db query",
287
+ lines: [...tableLines(result), queryIntentLine(operationKey)]
288
+ }
289
+ ],
290
+ actions: [
291
+ {
292
+ label: "Tool equivalent",
293
+ command: toolCommand
294
+ }
295
+ ]
342
296
  }
343
297
  },
344
298
  {
345
299
  json: explicitJsonOutput || format === "json" || format !== "table" && jsonOutput
346
300
  }
347
301
  );
348
- return 0;
302
+ return;
303
+ }
304
+
305
+ // src/cli/operations/db-query.ts
306
+ function resolveDbQuerySql(rawSql, readFile = (path) => readFileSync(path, "utf8")) {
307
+ const value = rawSql.trim();
308
+ if (!value.startsWith("@")) return value;
309
+ const filePath = value.slice(1).trim();
310
+ if (!filePath) {
311
+ throw new Error("--sql @file requires a file path after `@`.");
312
+ }
313
+ return readFile(resolve2(filePath)).trim();
314
+ }
315
+ async function runDbQueryCommand(options) {
316
+ let sql = "";
317
+ try {
318
+ sql = resolveDbQuerySql(options.sql);
319
+ if (!sql) throw new Error("SQL file is empty.");
320
+ const maxRows = options.maxRows === void 0 ? void 0 : Number(options.maxRows);
321
+ if (maxRows !== void 0 && maxRows > 1e3)
322
+ throw new Error(
323
+ "--max-rows must be 1000 or less. Add LIMIT/OFFSET to page larger exports."
324
+ );
325
+ if (maxRows !== void 0 && (!Number.isSafeInteger(maxRows) || maxRows < 1)) {
326
+ throw new Error(
327
+ "--max-rows must be a positive whole number of 1000 or less. Add LIMIT/OFFSET to page larger exports."
328
+ );
329
+ }
330
+ const operationKey = options.operationKey;
331
+ if (operationKey !== void 0 && (!operationKey.trim() || operationKey.length > 512)) {
332
+ throw new Error(
333
+ "--operation-key requires a non-empty intended-operation key of at most 512 characters."
334
+ );
335
+ }
336
+ const format = options.format?.trim().toLowerCase();
337
+ if (format !== void 0 && !["table", "json", "csv", "markdown"].includes(format)) {
338
+ throw new Error("--format must be table, json, csv, or markdown.");
339
+ }
340
+ const out = options.out?.trim();
341
+ if (out !== void 0 && !out) throw new Error("--out requires a path.");
342
+ if (out !== void 0 && format !== "csv" && format !== "markdown")
343
+ throw new Error("--out requires --format csv or --format markdown.");
344
+ const query = {
345
+ sql,
346
+ ...maxRows === void 0 ? {} : { maxRows },
347
+ ...operationKey === void 0 ? {} : { operationKey }
348
+ };
349
+ const plan = planCustomerDbQuery(query);
350
+ if (options.dryRun) {
351
+ printCommandEnvelope(
352
+ {
353
+ dryRun: true,
354
+ ...plan,
355
+ effects: {
356
+ ...plan.effects,
357
+ localWrites: out === void 0 ? "none" : "export_file"
358
+ },
359
+ output: {
360
+ format: format ?? "automatic",
361
+ ...out === void 0 ? {} : { file: resolve2(out) }
362
+ }
363
+ },
364
+ { json: options.json || shouldEmitJson() }
365
+ );
366
+ return 0;
367
+ }
368
+ const client = new DeeplineClient();
369
+ const result = await client.db.query(query);
370
+ renderDbQueryResult(result, query, {
371
+ format,
372
+ out,
373
+ json: options.json
374
+ });
375
+ return 0;
376
+ } catch (error) {
377
+ if (error instanceof CustomerDbQueryOutcomeUnknownError && (options.json || shouldEmitJson())) {
378
+ printCommandEnvelope(
379
+ {
380
+ ok: false,
381
+ error: {
382
+ code: error.code,
383
+ message: error.message,
384
+ outcome: error.outcome,
385
+ retryable: error.retryable,
386
+ ...error.operationKey === void 0 ? {} : { operationKey: error.operationKey }
387
+ }
388
+ },
389
+ { json: true }
390
+ );
391
+ }
392
+ console.error(formatDbQueryError(sql, error));
393
+ return 1;
394
+ }
395
+ }
396
+
397
+ // src/cli/commands/db.ts
398
+ function errorMessage2(value) {
399
+ return value instanceof Error ? value.message : String(value ?? "");
400
+ }
401
+ function dbRepairHumanLines(result) {
402
+ const repair = result.repair;
403
+ return [
404
+ "Workspace storage repair completed.",
405
+ ...repair ? [
406
+ `Location changed: ${repair.location.changed ? "yes" : "no"}`,
407
+ `Storage contract: ${repair.storage_contract.current ? "current" : "not ready"}`,
408
+ `Runtime migration: ${repair.runtime_migration.current ? "current" : "not ready"}`,
409
+ `Runtime capability probe: ${repair.runtime_capabilities.after.runtime_capabilities_ready ? "passed" : "failed"}`,
410
+ `Materialized table grants reconciled: ${repair.materialized_tables.repaired_count}`
411
+ ] : [
412
+ "Runtime capability probe: unavailable from this server version",
413
+ `Materialized table grants reconciled: ${result.count}`
414
+ ],
415
+ `Runtime role: ${result.connection_grants.runtime_role}`,
416
+ `Customer DB role: ${result.connection_grants.customer_db_role}`
417
+ ];
418
+ }
419
+ function dbRepairPlainText(result) {
420
+ return result.repair ? "Workspace storage repair completed. Runtime capability probe passed.\n" : `Workspace storage repair completed. ${result.count} materialized table grant(s) reconciled; runtime capability probe unavailable.
421
+ `;
349
422
  }
350
423
  async function handleDbRepair(args) {
351
424
  const providerIndex = args.indexOf("--provider");
@@ -364,7 +437,7 @@ async function handleDbRepair(args) {
364
437
  );
365
438
  return 1;
366
439
  }
367
- console.error(errorMessage(error));
440
+ console.error(errorMessage2(error));
368
441
  return 1;
369
442
  }
370
443
  printCommandEnvelope(
@@ -427,6 +500,11 @@ Examples:
427
500
  CREATE TABLE storage.blocked (...) instead of CREATE TABLE blocked (...).
428
501
  --format csv and --format markdown are explicit data/display formats and can
429
502
  be written directly with --out.
503
+ Effects: SQL may mutate customer storage; --out writes one local export. SQL does not spend credits.
504
+ SQL is attempted once, without automatic retries or URL failover. A lost response means unknown outcome.
505
+ For recoverable writes, choose --operation-key before execution. Recover with the original key,
506
+ SQL and options; a new key starts a new operation. A key added afterward cannot recover unkeyed SQL.
507
+ --dry-run shows this plan without executing SQL, exporting data, or maintaining the installation.
430
508
 
431
509
  Examples:
432
510
  deepline db query --sql "select * from companies limit 20"
@@ -437,18 +515,17 @@ Examples:
437
515
  deepline db query --sql "select * from contacts limit 20" --format csv --out contacts.csv
438
516
  deepline db query --sql "select domain, name from companies limit 20" --format markdown
439
517
  `
440
- ).requiredOption("--sql <sql>", "SQL statement").option("--max-rows <n>", "Maximum returned rows").option("--format <format>", "Output format: table, json, csv, or markdown").option("--out <path>", "Write csv or markdown output to a file").option(
518
+ ).requiredOption("--sql <sql>", "SQL statement").option(
519
+ "--dry-run",
520
+ "Describe the request, effects and recovery without executing SQL or writing an export"
521
+ ).option("--max-rows <n>", "Maximum returned rows").option(
522
+ "--operation-key <key>",
523
+ "Recover this intended transactional SQL operation; separate intentions need separate keys"
524
+ ).option("--format <format>", "Output format: table, json, csv, or markdown").option("--out <path>", "Write csv or markdown output to a file").option(
441
525
  "--json",
442
526
  "Emit raw JSON response. Also automatic when stdout is piped"
443
527
  ).action(async (options) => {
444
- process.exitCode = await handleDbQuery([
445
- "--sql",
446
- options.sql,
447
- ...options.maxRows ? ["--max-rows", options.maxRows] : [],
448
- ...options.format ? ["--format", options.format] : [],
449
- ...options.out ? ["--out", options.out] : [],
450
- ...options.json ? ["--json"] : []
451
- ]);
528
+ process.exitCode = await runDbQueryCommand(options);
452
529
  });
453
530
  db.command("repair").description(
454
531
  "Repair this workspace storage contract (role/DB grants). Org admin only."
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkTZZNI2A4js = require('./chunk-TZZNI2A4.js');
5
+ var _chunkTZQMFWLFjs = require('./chunk-TZQMFWLF.js');
6
6
 
7
7
 
8
- var _chunkEXKRHZRGjs = require('./chunk-EXKRHZRG.js');
8
+ var _chunk4LNBSQM4js = require('./chunk-4LNBSQM4.js');
9
9
 
10
10
 
11
11
 
@@ -13,26 +13,27 @@ var _chunkEXKRHZRGjs = require('./chunk-EXKRHZRG.js');
13
13
 
14
14
 
15
15
 
16
- var _chunkXNL3SEMCjs = require('./chunk-XNL3SEMC.js');
16
+ var _chunkAFNEQ43Jjs = require('./chunk-AFNEQ43J.js');
17
+ require('./chunk-AID3OYVJ.js');
17
18
  require('./chunk-5JLQPVNX.js');
18
- require('./chunk-QM2Z4FQF.js');
19
- require('./chunk-NC2ZXG2Y.js');
19
+ require('./chunk-T33W6JUJ.js');
20
+ require('./chunk-3NGWGFVL.js');
20
21
  require('./chunk-NXDRDJ4K.js');
21
- require('./chunk-SDK3ZA2C.js');
22
+ require('./chunk-LVEDPCLJ.js');
22
23
 
23
24
 
24
- var _chunkN5E66DP3js = require('./chunk-N5E66DP3.js');
25
+ var _chunkGVYKY6T6js = require('./chunk-GVYKY6T6.js');
25
26
  require('./chunk-LA46MMTL.js');
26
27
  require('./chunk-QJBJZVG6.js');
27
28
  require('./chunk-AYHLUHE5.js');
28
29
  require('./chunk-WJYPBHTE.js');
29
30
 
30
31
 
31
- var _chunkGROXVGGWjs = require('./chunk-GROXVGGW.js');
32
- require('./chunk-D5YJHGST.js');
32
+ var _chunkCUUHQ3AOjs = require('./chunk-CUUHQ3AO.js');
33
+ require('./chunk-TXVOB5J2.js');
33
34
  require('./chunk-XNYIZMNQ.js');
34
- require('./chunk-IXYR65PW.js');
35
- require('./chunk-XSEMQ4II.js');
35
+ require('./chunk-BUYZEUY4.js');
36
+ require('./chunk-AGH6YP2T.js');
36
37
  require('./chunk-3KC45UVF.js');
37
38
  require('./chunk-2HKPAZVJ.js');
38
39
  require('./chunk-S6R3OX7B.js');
@@ -64,11 +65,11 @@ async function found(lookup) {
64
65
  async function describeAnything(name, options, onMissing) {
65
66
  const maintainedOnly = options.prebuilt === true || options.tool === true;
66
67
  const wants = (filter) => (!options.kinds || options.kinds.includes(filter)) && !(maintainedOnly && filter === "custom");
67
- const client = new (0, _chunkN5E66DP3js.DeeplineClient)();
68
+ const client = new (0, _chunkGVYKY6T6js.DeeplineClient)();
68
69
  const play = async (reference) => {
69
70
  const record2 = await client.describePlay(reference);
70
71
  return {
71
- described: _chunkEXKRHZRGjs.describedPlay.call(void 0, record2),
72
+ described: _chunk4LNBSQM4js.describedPlay.call(void 0, record2),
72
73
  record: { ...record2 },
73
74
  schemas: {
74
75
  inputSchema: _nullishCoalesce(record2.inputSchema, () => ( null)),
@@ -79,9 +80,9 @@ async function describeAnything(name, options, onMissing) {
79
80
  const tool = async () => {
80
81
  const record2 = await _asyncNullishCoalesce(options.fetchedTool, async () => ( await client.getTool(name)));
81
82
  return {
82
- described: _chunkTZZNI2A4js.describedTool.call(void 0, record2, name),
83
- record: _chunkTZZNI2A4js.toolMetadataJsonForDescribe.call(void 0, record2, name),
84
- schemas: _chunkTZZNI2A4js.publicToolSchemas.call(void 0, record2)
83
+ described: _chunkTZQMFWLFjs.describedTool.call(void 0, record2, name),
84
+ record: _chunkTZQMFWLFjs.toolMetadataJsonForDescribe.call(void 0, record2, name),
85
+ schemas: _chunkTZQMFWLFjs.publicToolSchemas.call(void 0, record2)
85
86
  };
86
87
  };
87
88
  const sources = name.includes("/") ? [{ kinds: ["prebuilts", "custom"], find: () => play(name) }] : [
@@ -130,21 +131,21 @@ async function describeAnything(name, options, onMissing) {
130
131
  },
131
132
  lines: [
132
133
  `${described.id} [${described.kind.replace("_", " ")}]`,
133
- ..._chunkXNL3SEMCjs.schemaLines.call(void 0, described, { full: true })
134
+ ..._chunkAFNEQ43Jjs.schemaLines.call(void 0, described, { full: true })
134
135
  ]
135
136
  } : {
136
137
  envelope: {
137
138
  ...summary,
138
- inputs: inputs.map(_chunkXNL3SEMCjs.topLevelField),
139
- outputs: outputs.map(_chunkXNL3SEMCjs.topLevelField),
140
- ...described.rowInputs ? { rowInputs: described.rowInputs.map(_chunkXNL3SEMCjs.topLevelField) } : {},
141
- ...described.rowOutputs ? { rowOutputs: described.rowOutputs.map(_chunkXNL3SEMCjs.topLevelField) } : {},
142
- runExamples: _chunkXNL3SEMCjs.examples.call(void 0, described, { verbose }),
139
+ inputs: inputs.map(_chunkAFNEQ43Jjs.topLevelField),
140
+ outputs: outputs.map(_chunkAFNEQ43Jjs.topLevelField),
141
+ ...described.rowInputs ? { rowInputs: described.rowInputs.map(_chunkAFNEQ43Jjs.topLevelField) } : {},
142
+ ...described.rowOutputs ? { rowOutputs: described.rowOutputs.map(_chunkAFNEQ43Jjs.topLevelField) } : {},
143
+ runExamples: _chunkAFNEQ43Jjs.examples.call(void 0, described, { verbose }),
143
144
  ...shadows ? { shadows, note } : {}
144
145
  },
145
146
  lines: [
146
147
  ...note ? [`Note: ${note}`, ""] : [],
147
- ..._chunkXNL3SEMCjs.describedLines.call(void 0, described, {
148
+ ..._chunkAFNEQ43Jjs.describedLines.call(void 0, described, {
148
149
  cli: shown && (!named || options.cliExample === true),
149
150
  play: shown && (!named || options.playExample === true),
150
151
  explain: named,
@@ -166,18 +167,18 @@ async function describeAnything(name, options, onMissing) {
166
167
  ` : text;
167
168
  _fs.writeFileSync.call(void 0, path, content);
168
169
  const bytes = Buffer.byteLength(content);
169
- _chunkGROXVGGWjs.printCommandEnvelope.call(void 0,
170
+ _chunkCUUHQ3AOjs.printCommandEnvelope.call(void 0,
170
171
  { path, bytes },
171
172
  { json, text: `Wrote ${path} (${bytes} bytes)
172
173
  ` }
173
174
  );
174
175
  return 0;
175
176
  }
176
- _chunkGROXVGGWjs.printCommandEnvelope.call(void 0, envelope, { json, text });
177
+ _chunkCUUHQ3AOjs.printCommandEnvelope.call(void 0, envelope, { json, text });
177
178
  return 0;
178
179
  }
179
180
  function registerDescribeCommand(program) {
180
- _chunkXNL3SEMCjs.addDescribeOptions.call(void 0, program.command("describe <name>")).description(
181
+ _chunkAFNEQ43Jjs.addDescribeOptions.call(void 0, program.command("describe <name>")).description(
181
182
  "Describe anything search returns: a tool, monitor type, or play."
182
183
  ).addHelpText(
183
184
  "after",
@@ -204,7 +205,7 @@ Examples in the output:
204
205
  --no-example no examples
205
206
 
206
207
  Schema size and format:
207
- A schema over ${_chunkXNL3SEMCjs.SCHEMA_LINE_LIMIT} lines is folded: deeper objects show only their field
208
+ A schema over ${_chunkAFNEQ43Jjs.SCHEMA_LINE_LIMIT} lines is folded: deeper objects show only their field
208
209
  names. A shape used more than once is printed once under Types.
209
210
  --full-schema the normal output, with the schema not folded
210
211
  --schema-only only the schema, not folded, and nothing else