deepline 0.3.293 → 0.3.295

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 (138) hide show
  1. package/dist/bundling-sources/sdk/src/compat.ts +35 -7
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +269 -267
  4. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +3 -4
  5. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +14 -1
  6. package/dist/cli/auth-EDTRERZP.mjs +31 -0
  7. package/dist/cli/auth-TDHKB277.js +31 -0
  8. package/dist/cli/billing-ELIDPILY.js +1749 -0
  9. package/dist/cli/billing-EXGXJVAU.mjs +1749 -0
  10. package/dist/cli/chunk-2S5Y3TZP.js +5688 -0
  11. package/dist/cli/chunk-3KC45UVF.js +150 -0
  12. package/dist/cli/chunk-3XX5TEA4.js +15 -0
  13. package/dist/cli/chunk-4MBOJQPL.mjs +0 -0
  14. package/dist/cli/chunk-4NEFYBF7.js +2240 -0
  15. package/dist/cli/chunk-5JLQPVNX.js +3056 -0
  16. package/dist/cli/chunk-5KDKFHZI.js +1269 -0
  17. package/dist/cli/chunk-6A3TJUWC.js +76 -0
  18. package/dist/cli/chunk-6O5YZOVN.mjs +890 -0
  19. package/dist/cli/chunk-7P5AA3SN.js +344 -0
  20. package/dist/cli/chunk-AYHLUHE5.js +52 -0
  21. package/dist/cli/chunk-CBVIJSHF.mjs +560 -0
  22. package/dist/cli/chunk-CFVVCN4A.js +735 -0
  23. package/dist/cli/chunk-COGTRVWW.js +30 -0
  24. package/dist/cli/chunk-D4AZUZO4.js +190 -0
  25. package/dist/cli/chunk-DLIRSHV6.mjs +28 -0
  26. package/dist/cli/chunk-EACVZI6N.mjs +1995 -0
  27. package/dist/cli/chunk-EDWJY6T4.mjs +3056 -0
  28. package/dist/cli/chunk-EXMLR72R.mjs +0 -0
  29. package/dist/cli/chunk-F35VOIQL.js +890 -0
  30. package/dist/cli/chunk-GAMFK2ZP.mjs +148 -0
  31. package/dist/cli/chunk-GHRQQPW2.mjs +2240 -0
  32. package/dist/cli/chunk-GONRLVV3.js +3440 -0
  33. package/dist/cli/chunk-GVUJJJ5G.mjs +76 -0
  34. package/dist/cli/chunk-H7HIDGZ7.mjs +150 -0
  35. package/dist/cli/chunk-HUZXWOSK.mjs +503 -0
  36. package/dist/cli/chunk-I5YZLGMG.js +1 -0
  37. package/dist/cli/chunk-ITOFSXIU.mjs +15 -0
  38. package/dist/cli/chunk-J5NA2TTX.js +503 -0
  39. package/dist/cli/chunk-JCS5TPNY.mjs +3440 -0
  40. package/dist/cli/chunk-JNNOCMQY.js +47 -0
  41. package/dist/cli/chunk-KRD6H754.mjs +30 -0
  42. package/dist/cli/chunk-LA46MMTL.js +560 -0
  43. package/dist/cli/chunk-LDWT7RJK.mjs +190 -0
  44. package/dist/cli/chunk-M2V26OR5.js +499 -0
  45. package/dist/cli/chunk-MIMASXO4.mjs +389 -0
  46. package/dist/cli/chunk-MROPCKW2.mjs +190 -0
  47. package/dist/cli/chunk-NXDRDJ4K.js +389 -0
  48. package/dist/cli/chunk-NXGCO4JB.mjs +344 -0
  49. package/dist/cli/chunk-OG64RBAC.js +6 -0
  50. package/dist/cli/chunk-OQYEC4GL.mjs +34 -0
  51. package/dist/cli/chunk-OWJZUE3Y.mjs +103 -0
  52. package/dist/cli/chunk-SDK3ZA2C.js +103 -0
  53. package/dist/cli/chunk-SFLARO4Y.mjs +47 -0
  54. package/dist/cli/chunk-SVIIIYIQ.js +923 -0
  55. package/dist/cli/chunk-TAC3JIFE.mjs +354 -0
  56. package/dist/cli/chunk-U3PI7HBM.js +34 -0
  57. package/dist/cli/chunk-UFS752TU.mjs +52 -0
  58. package/dist/cli/chunk-UI37DQE7.mjs +499 -0
  59. package/dist/cli/chunk-UNEMDKXN.js +1 -0
  60. package/dist/cli/chunk-WB6Z2Q44.mjs +1622 -0
  61. package/dist/cli/chunk-WJYPBHTE.js +148 -0
  62. package/dist/cli/chunk-WOHBA5PV.js +354 -0
  63. package/dist/cli/chunk-WQICC2B3.js +190 -0
  64. package/dist/cli/chunk-WZYKRD7T.mjs +6 -0
  65. package/dist/cli/chunk-XL2FO6CW.mjs +5688 -0
  66. package/dist/cli/chunk-XNYIZMNQ.js +28 -0
  67. package/dist/cli/chunk-XRK2TZT5.js +1995 -0
  68. package/dist/cli/chunk-YJYPL5OK.mjs +1269 -0
  69. package/dist/cli/chunk-YWNDYCXR.mjs +735 -0
  70. package/dist/cli/chunk-YWWAF7KZ.mjs +923 -0
  71. package/dist/cli/chunk-ZDO3TO3M.js +1622 -0
  72. package/dist/cli/client-4JVOYVC5.js +20 -0
  73. package/dist/cli/client-EEN2IJN2.mjs +20 -0
  74. package/dist/cli/csv-BOHBEP2I.mjs +585 -0
  75. package/dist/cli/csv-S5NYRUEX.js +585 -0
  76. package/dist/cli/db-CLODWCOB.mjs +486 -0
  77. package/dist/cli/db-F6PKFOOV.js +486 -0
  78. package/dist/cli/executions-5TQAKLJU.js +28 -0
  79. package/dist/cli/executions-MAKW6QOY.mjs +28 -0
  80. package/dist/cli/feedback-GV4QJFEN.js +107 -0
  81. package/dist/cli/feedback-XY24TW7H.mjs +107 -0
  82. package/dist/cli/getting-started.js +18 -76
  83. package/dist/cli/getting-started.mjs +10 -37
  84. package/dist/cli/git-6S2C22T5.js +23 -0
  85. package/dist/cli/git-OZLBD5HH.mjs +23 -0
  86. package/dist/cli/index.js +291 -54294
  87. package/dist/cli/index.mjs +209 -54352
  88. package/dist/cli/legacy-noops-LLCGDPQE.js +157 -0
  89. package/dist/cli/legacy-noops-TYH3TW2D.mjs +157 -0
  90. package/dist/cli/monitors-CABMB4DW.js +3251 -0
  91. package/dist/cli/monitors-TTD55HMK.mjs +3251 -0
  92. package/dist/cli/org-MSF3RG76.js +849 -0
  93. package/dist/cli/org-SFJ77MWY.mjs +849 -0
  94. package/dist/cli/play-NXHJSCKL.mjs +18439 -0
  95. package/dist/cli/play-OKSFNNO4.js +18439 -0
  96. package/dist/cli/providers-QC2ERERL.js +95 -0
  97. package/dist/cli/providers-TIIAZEUA.mjs +95 -0
  98. package/dist/cli/proxy-env-EBANZHPV.js +161 -0
  99. package/dist/cli/proxy-env-M4ZHXHRL.mjs +161 -0
  100. package/dist/cli/quickstart-ICANHLMI.js +69 -0
  101. package/dist/cli/quickstart-KWUOP3FI.mjs +69 -0
  102. package/dist/cli/search-U5H2FDOO.mjs +18 -0
  103. package/dist/cli/search-XQRQOLWS.js +18 -0
  104. package/dist/cli/secrets-3J6YTWFA.mjs +400 -0
  105. package/dist/cli/secrets-YNMNZNOM.js +400 -0
  106. package/dist/cli/sessions-CLEES4L6.mjs +15 -0
  107. package/dist/cli/sessions-J6VR47FG.js +15 -0
  108. package/dist/cli/settings-EEKZMTY4.js +846 -0
  109. package/dist/cli/settings-UVLOQZRH.mjs +846 -0
  110. package/dist/cli/setup-DLMDXPGJ.mjs +1257 -0
  111. package/dist/cli/setup-HC4Q7QM4.js +1257 -0
  112. package/dist/cli/skills-33PHFBSB.mjs +28 -0
  113. package/dist/cli/skills-LFRY3KPX.js +28 -0
  114. package/dist/cli/tools-3COEPKML.mjs +2955 -0
  115. package/dist/cli/tools-QXEVCN45.js +2955 -0
  116. package/dist/cli/update-LSAC4FF5.mjs +28 -0
  117. package/dist/cli/update-NXHSPYXA.js +28 -0
  118. package/dist/cli/workflow-7S44OECF.mjs +1936 -0
  119. package/dist/cli/workflow-QPZWYSZE.js +1936 -0
  120. package/dist/helpers.js +6 -32
  121. package/dist/helpers.mjs +2 -0
  122. package/dist/index.js +1972 -12825
  123. package/dist/index.mjs +1910 -12672
  124. package/dist/install-integrity.json +110 -0
  125. package/dist/monitor-fleet-contract.js +31 -730
  126. package/dist/monitor-fleet-contract.mjs +18 -667
  127. package/dist/monitor-input-contract.js +10 -390
  128. package/dist/monitor-input-contract.mjs +7 -348
  129. package/dist/plays/bundle-play-file.mjs +13 -5178
  130. package/dist/plays/csv-data-input.js +5 -3132
  131. package/dist/plays/csv-data-input.mjs +5 -3105
  132. package/dist/plays/run-request.js +56 -664
  133. package/dist/plays/run-request.mjs +30 -588
  134. package/dist/release.d.mts +1 -1
  135. package/dist/release.d.ts +1 -1
  136. package/dist/release.js +5 -212
  137. package/dist/release.mjs +5 -185
  138. package/package.json +1 -1
@@ -0,0 +1,1269 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkU3PI7HBMjs = require('./chunk-U3PI7HBM.js');
5
+
6
+
7
+
8
+ var _chunk4NEFYBF7js = require('./chunk-4NEFYBF7.js');
9
+
10
+
11
+ var _chunkF35VOIQLjs = require('./chunk-F35VOIQL.js');
12
+
13
+
14
+ var _chunkXRK2TZT5js = require('./chunk-XRK2TZT5.js');
15
+
16
+ // src/cli/commands/update.ts
17
+ var _child_process = require('child_process');
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ var _fs = require('fs');
28
+ var _os = require('os');
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ var _path = require('path');
37
+
38
+ // src/cli/install-integrity.ts
39
+ var _module = require('module');
40
+
41
+
42
+ var SDK_SIDECAR_CRITICAL_PACKAGE_FILES = [
43
+ "dist/cli/index.mjs",
44
+ "dist/index.mjs",
45
+ "dist/index.d.ts",
46
+ "dist/plays/bundle-play-file.mjs",
47
+ "dist/bundling-sources/shared_libs/observability/telemetry.ts",
48
+ "dist/bundling-sources/shared_libs/integration-contracts/bettercontact/execution-policy.ts",
49
+ "dist/bundling-sources/shared_libs/integration-contracts/theirstack/execution-policy.ts",
50
+ "dist/bundling-sources/shared_libs/play-runtime/backend.ts",
51
+ "dist/bundling-sources/shared_libs/plays/bundling/index.ts",
52
+ "dist/bundling-sources/shared_libs/product-notifications/contract.ts",
53
+ "dist/bundling-sources/shared_libs/tool-execution-error.ts"
54
+ ];
55
+ var SDK_SIDECAR_CRITICAL_DEPENDENCY_FILES = [
56
+ "esbuild/package.json",
57
+ "esbuild/lib/main.js"
58
+ ];
59
+ function safeRelativePath(value) {
60
+ if (typeof value !== "string" || !value || _path.isAbsolute.call(void 0, value)) return false;
61
+ const segments = value.split(/[\\/]+/);
62
+ return segments.every(
63
+ (segment) => Boolean(segment) && segment !== "." && segment !== ".."
64
+ );
65
+ }
66
+ function resolveContainedPath(root, value) {
67
+ if (!safeRelativePath(value)) return null;
68
+ const target = _path.resolve.call(void 0, root, value);
69
+ const relativeTarget = _path.relative.call(void 0, _path.resolve.call(void 0, root), target);
70
+ if (!relativeTarget || relativeTarget.startsWith("..") || _path.isAbsolute.call(void 0, relativeTarget)) {
71
+ return null;
72
+ }
73
+ return target;
74
+ }
75
+ function parseJson(path) {
76
+ return JSON.parse(_fs.readFileSync.call(void 0, path, "utf8"));
77
+ }
78
+ function isFile(path) {
79
+ try {
80
+ return _fs.statSync.call(void 0, path).isFile();
81
+ } catch (e) {
82
+ return false;
83
+ }
84
+ }
85
+ function readManifest(packageRoot) {
86
+ const packageJsonPath = _path.join.call(void 0, packageRoot, "package.json");
87
+ let packageJson;
88
+ try {
89
+ packageJson = parseJson(packageJsonPath);
90
+ } catch (error) {
91
+ return {
92
+ mode: "manifest",
93
+ invalidReason: `invalid Deepline package metadata: ${error.message}`,
94
+ missing: _fs.existsSync.call(void 0, packageJsonPath) ? [] : ["deepline/package.json"]
95
+ };
96
+ }
97
+ if (!packageJson || typeof packageJson !== "object" || Array.isArray(packageJson)) {
98
+ return {
99
+ mode: "manifest",
100
+ invalidReason: "invalid Deepline package metadata: expected an object"
101
+ };
102
+ }
103
+ const metadata = packageJson;
104
+ if (metadata.deepline !== void 0 && (!metadata.deepline || typeof metadata.deepline !== "object" || Array.isArray(metadata.deepline))) {
105
+ return {
106
+ mode: "manifest",
107
+ invalidReason: "invalid Deepline package metadata: deepline must be an object"
108
+ };
109
+ }
110
+ const declaration = _optionalChain([metadata, 'access', _ => _.deepline, 'optionalAccess', _2 => _2.installIntegrity]);
111
+ if (!declaration) {
112
+ return {
113
+ mode: "legacy",
114
+ manifest: {
115
+ schemaVersion: 1,
116
+ packageFiles: [...SDK_SIDECAR_CRITICAL_PACKAGE_FILES],
117
+ dependencyFiles: [...SDK_SIDECAR_CRITICAL_DEPENDENCY_FILES]
118
+ }
119
+ };
120
+ }
121
+ if (declaration.schemaVersion !== 1 || !safeRelativePath(declaration.manifest)) {
122
+ return {
123
+ mode: "manifest",
124
+ invalidReason: "invalid Deepline install-integrity declaration"
125
+ };
126
+ }
127
+ const manifestPath = resolveContainedPath(packageRoot, declaration.manifest);
128
+ if (!manifestPath || !isFile(manifestPath)) {
129
+ return {
130
+ mode: "manifest",
131
+ invalidReason: "declared Deepline install-integrity manifest is missing",
132
+ missing: [String(declaration.manifest)]
133
+ };
134
+ }
135
+ let raw;
136
+ try {
137
+ raw = parseJson(manifestPath);
138
+ } catch (error) {
139
+ return {
140
+ mode: "manifest",
141
+ invalidReason: `invalid Deepline install-integrity manifest: ${error.message}`
142
+ };
143
+ }
144
+ if (!raw || typeof raw !== "object" || raw.schemaVersion !== 1 || !Array.isArray(raw.packageFiles) || !Array.isArray(raw.dependencyFiles)) {
145
+ return {
146
+ mode: "manifest",
147
+ invalidReason: "invalid Deepline install-integrity manifest schema"
148
+ };
149
+ }
150
+ const manifest = raw;
151
+ if (manifest.packageFiles.length === 0 || manifest.dependencyFiles.length === 0 || !manifest.packageFiles.every(safeRelativePath) || !manifest.dependencyFiles.every(safeRelativePath)) {
152
+ return {
153
+ mode: "manifest",
154
+ invalidReason: "unsafe path in Deepline install-integrity manifest"
155
+ };
156
+ }
157
+ return { mode: "manifest", manifest };
158
+ }
159
+ function inspectSdkSidecarInstall(versionDir) {
160
+ const nodeModulesRoot = _path.join.call(void 0, versionDir, "node_modules");
161
+ const packageRoot = _path.join.call(void 0, nodeModulesRoot, "deepline");
162
+ const manifestResult = readManifest(packageRoot);
163
+ if ("invalidReason" in manifestResult) {
164
+ return {
165
+ ok: false,
166
+ missing: _nullishCoalesce(manifestResult.missing, () => ( [])),
167
+ invalidReason: manifestResult.invalidReason,
168
+ mode: manifestResult.mode
169
+ };
170
+ }
171
+ const missing = [
172
+ ...manifestResult.manifest.packageFiles.filter((path) => !isFile(_path.join.call(void 0, packageRoot, path))).map((path) => `deepline/${path}`),
173
+ ...manifestResult.manifest.dependencyFiles.filter((path) => !isFile(_path.join.call(void 0, nodeModulesRoot, path))).map((path) => `node_modules/${path}`)
174
+ ];
175
+ return {
176
+ ok: missing.length === 0,
177
+ missing,
178
+ invalidReason: null,
179
+ mode: manifestResult.mode
180
+ };
181
+ }
182
+ function probeSdkSidecarEsbuild(versionDir) {
183
+ try {
184
+ const requireFromInstall = _module.createRequire.call(void 0, _path.join.call(void 0, versionDir, "package.json"));
185
+ const esbuild = requireFromInstall("esbuild");
186
+ if (typeof esbuild.transformSync !== "function") {
187
+ return "esbuild does not export transformSync";
188
+ }
189
+ const result = esbuild.transformSync("const value: number = 1;", {
190
+ loader: "ts"
191
+ });
192
+ if (typeof _optionalChain([result, 'optionalAccess', _3 => _3.code]) !== "string") {
193
+ return "esbuild transform probe returned no code";
194
+ }
195
+ return null;
196
+ } catch (error) {
197
+ return error instanceof Error ? error.message : String(error);
198
+ }
199
+ }
200
+
201
+ // src/cli/update-preferences.ts
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+ var UPDATE_PREFERENCES_SCHEMA_VERSION = 1;
213
+ var CLI_UPDATE_MESSAGES = [
214
+ {
215
+ id: "auto-update-default-v1",
216
+ message: "Automatic CLI updates are now enabled by default. To opt out, run `deepline settings autoupdate off`."
217
+ }
218
+ ];
219
+ function defaultPreferences() {
220
+ return {
221
+ schemaVersion: UPDATE_PREFERENCES_SCHEMA_VERSION,
222
+ autoUpdateEnabled: true,
223
+ pinnedVersion: null,
224
+ acknowledgedMessages: []
225
+ };
226
+ }
227
+ function unreadablePreferences(path, error) {
228
+ const detail = error instanceof Error ? error.message : String(error);
229
+ console.error(
230
+ `[deepline] Could not read CLI update preferences at ${path}; automatic updates are disabled until the file is repaired or an autoupdate setting is explicitly changed. ${detail}`
231
+ );
232
+ return {
233
+ schemaVersion: UPDATE_PREFERENCES_SCHEMA_VERSION,
234
+ autoUpdateEnabled: false,
235
+ pinnedVersion: null,
236
+ acknowledgedMessages: CLI_UPDATE_MESSAGES.map(({ id }) => id)
237
+ };
238
+ }
239
+ function cliUpdatePreferencesPath(homeDir = _os.homedir.call(void 0, )) {
240
+ return _path.join.call(void 0,
241
+ homeDir,
242
+ ".local",
243
+ "deepline",
244
+ "sdk-cli",
245
+ "update-preferences.json"
246
+ );
247
+ }
248
+ function readCliUpdatePreferences(homeDir = _os.homedir.call(void 0, )) {
249
+ const path = cliUpdatePreferencesPath(homeDir);
250
+ if (!_fs.existsSync.call(void 0, path)) return defaultPreferences();
251
+ try {
252
+ const parsed = JSON.parse(_fs.readFileSync.call(void 0, path, "utf8"));
253
+ return {
254
+ schemaVersion: UPDATE_PREFERENCES_SCHEMA_VERSION,
255
+ autoUpdateEnabled: typeof parsed.autoUpdateEnabled === "boolean" ? parsed.autoUpdateEnabled : true,
256
+ pinnedVersion: typeof parsed.pinnedVersion === "string" && parsed.pinnedVersion.trim() ? parsed.pinnedVersion.trim() : null,
257
+ acknowledgedMessages: Array.isArray(parsed.acknowledgedMessages) ? parsed.acknowledgedMessages.filter(
258
+ (value) => typeof value === "string"
259
+ ) : []
260
+ };
261
+ } catch (error) {
262
+ return unreadablePreferences(path, error);
263
+ }
264
+ }
265
+ function writeCliUpdatePreferences(preferences, homeDir = _os.homedir.call(void 0, )) {
266
+ const path = cliUpdatePreferencesPath(homeDir);
267
+ const tempPath = `${path}.${process.pid}.tmp`;
268
+ _fs.mkdirSync.call(void 0, _path.dirname.call(void 0, path), { recursive: true });
269
+ try {
270
+ _fs.writeFileSync.call(void 0, tempPath, `${JSON.stringify(preferences, null, 2)}
271
+ `, {
272
+ encoding: "utf8",
273
+ mode: 384
274
+ });
275
+ _fs.renameSync.call(void 0, tempPath, path);
276
+ } finally {
277
+ _fs.rmSync.call(void 0, tempPath, { force: true });
278
+ }
279
+ }
280
+ function setCliAutoUpdateEnabled(enabled, homeDir = _os.homedir.call(void 0, )) {
281
+ const current = readCliUpdatePreferences(homeDir);
282
+ const next = {
283
+ ...current,
284
+ autoUpdateEnabled: enabled,
285
+ ...enabled ? { pinnedVersion: null } : {}
286
+ };
287
+ writeCliUpdatePreferences(next, homeDir);
288
+ return next;
289
+ }
290
+ function setCliPinnedVersion(version, homeDir = _os.homedir.call(void 0, )) {
291
+ const next = {
292
+ ...readCliUpdatePreferences(homeDir),
293
+ pinnedVersion: version
294
+ };
295
+ writeCliUpdatePreferences(next, homeDir);
296
+ return next;
297
+ }
298
+ function clearCliPinnedVersion(homeDir = _os.homedir.call(void 0, )) {
299
+ const current = readCliUpdatePreferences(homeDir);
300
+ if (current.pinnedVersion === null) return current;
301
+ const next = { ...current, pinnedVersion: null };
302
+ writeCliUpdatePreferences(next, homeDir);
303
+ return next;
304
+ }
305
+ function shouldRunCliAutoUpdate(homeDir = _os.homedir.call(void 0, )) {
306
+ const preferences = readCliUpdatePreferences(homeDir);
307
+ return preferences.autoUpdateEnabled && preferences.pinnedVersion === null;
308
+ }
309
+ function consumePendingCliUpdateMessages(homeDir = _os.homedir.call(void 0, )) {
310
+ const preferences = readCliUpdatePreferences(homeDir);
311
+ const acknowledged = new Set(preferences.acknowledgedMessages);
312
+ const pending = CLI_UPDATE_MESSAGES.filter(({ id }) => !acknowledged.has(id));
313
+ if (pending.length === 0) return [];
314
+ for (const { id } of pending) acknowledged.add(id);
315
+ try {
316
+ writeCliUpdatePreferences(
317
+ { ...preferences, acknowledgedMessages: [...acknowledged] },
318
+ homeDir
319
+ );
320
+ } catch (e2) {
321
+ }
322
+ return pending.map(({ message }) => message);
323
+ }
324
+
325
+ // src/cli/commands/update.ts
326
+ function canAutomaticallyApplyUpdatePlan(plan) {
327
+ return plan.kind === "python-sidecar" || plan.kind === "npm-global" && Boolean(plan.installPrefix);
328
+ }
329
+ var NPM_SDK_INSTALL_COMMON_FLAGS = [
330
+ "--no-audit",
331
+ "--no-fund",
332
+ "--include=optional"
333
+ ];
334
+ var NPM_SDK_SIDECAR_PACKAGE_JSON = `${JSON.stringify(
335
+ {
336
+ private: true,
337
+ allowScripts: {
338
+ esbuild: true
339
+ }
340
+ },
341
+ null,
342
+ 2
343
+ )}
344
+ `;
345
+ function posixShellQuote(value) {
346
+ return `'${value.replace(/'/g, `'\\''`)}'`;
347
+ }
348
+ function windowsCmdQuote(value) {
349
+ return `"${value.replace(/"/g, '""')}"`;
350
+ }
351
+ function shellQuote(value) {
352
+ if (process.platform === "win32") {
353
+ return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : windowsCmdQuote(value);
354
+ }
355
+ return posixShellQuote(value);
356
+ }
357
+ function buildSourceUpdateCommand(sourceRoot) {
358
+ const quotedRoot = shellQuote(sourceRoot);
359
+ const cdCommand = process.platform === "win32" ? `cd /d ${quotedRoot}` : `cd ${quotedRoot}`;
360
+ return `${cdCommand} && git fetch origin main --tags && git merge --ff-only origin/main`;
361
+ }
362
+ function buildSidecarProjectConfigCommand(versionDir, nodeBin) {
363
+ const script = [
364
+ "const fs=require('node:fs');",
365
+ "const path=require('node:path');",
366
+ "const dir=process.argv[1];",
367
+ "fs.mkdirSync(dir,{recursive:true});",
368
+ `fs.writeFileSync(path.join(dir,'package.json'),${JSON.stringify(NPM_SDK_SIDECAR_PACKAGE_JSON)});`
369
+ ].join("");
370
+ return `${shellQuote(nodeBin)} -e ${shellQuote(script)} ${shellQuote(versionDir)}`;
371
+ }
372
+ function sidecarStateDir(input) {
373
+ const scope = _optionalChain([input, 'access', _4 => _4.env, 'access', _5 => _5.DEEPLINE_CONFIG_SCOPE, 'optionalAccess', _6 => _6.trim, 'call', _7 => _7()]);
374
+ if (!scope || scope.includes("/") || scope.includes("\\")) {
375
+ return null;
376
+ }
377
+ return _path.join.call(void 0, input.homeDir, ".local", "deepline", scope, "sdk-cli");
378
+ }
379
+ function sidecarRegistryUrl(hostUrl) {
380
+ let url;
381
+ try {
382
+ url = new URL(hostUrl);
383
+ } catch (e3) {
384
+ throw new Error(
385
+ "The Python-managed SDK sidecar is missing a valid Deepline host URL for its npm registry."
386
+ );
387
+ }
388
+ if (url.protocol !== "https:" && url.protocol !== "http:" || !url.hostname || url.username || url.password) {
389
+ throw new Error(
390
+ "The Python-managed SDK sidecar has an invalid Deepline host URL for its npm registry."
391
+ );
392
+ }
393
+ return new URL("/api/v2/npm/", url).toString();
394
+ }
395
+ function publicNpmFallbackRegistryUrl(hostUrl) {
396
+ try {
397
+ return sidecarRegistryUrl(hostUrl);
398
+ } catch (e4) {
399
+ return void 0;
400
+ }
401
+ }
402
+ function readOptionalText(path) {
403
+ try {
404
+ return _fs.readFileSync.call(void 0, path, "utf8").trim();
405
+ } catch (e5) {
406
+ return "";
407
+ }
408
+ }
409
+ function resolvePythonSidecarUpdatePlan(options) {
410
+ const stateDir = sidecarStateDir(options);
411
+ if (!stateDir) return null;
412
+ const relativeEntrypoint = _path.relative.call(void 0,
413
+ _path.resolve.call(void 0, stateDir),
414
+ _path.resolve.call(void 0, options.entrypoint)
415
+ );
416
+ if (!relativeEntrypoint || relativeEntrypoint.startsWith("..") || _path.isAbsolute.call(void 0, relativeEntrypoint)) {
417
+ return null;
418
+ }
419
+ const installMethod = readOptionalText(_path.join.call(void 0, stateDir, ".install-method"));
420
+ if (installMethod !== "python-sidecar") return null;
421
+ const scope = _optionalChain([options, 'access', _8 => _8.env, 'access', _9 => _9.DEEPLINE_CONFIG_SCOPE, 'optionalAccess', _10 => _10.trim, 'call', _11 => _11()]) || "";
422
+ const hostUrl = _optionalChain([options, 'access', _12 => _12.env, 'access', _13 => _13.DEEPLINE_HOST_URL, 'optionalAccess', _14 => _14.trim, 'call', _15 => _15()]) || "";
423
+ const nodeBin = readOptionalText(_path.join.call(void 0, stateDir, ".node-bin")) || process.execPath;
424
+ const sidecarPath = readOptionalText(_path.join.call(void 0, stateDir, ".command-path")) || _path.join.call(void 0,
425
+ stateDir,
426
+ "bin",
427
+ process.platform === "win32" ? "deepline-sdk.cmd" : "deepline-sdk"
428
+ );
429
+ const packageSpec = options.packageSpec || "deepline@latest";
430
+ const npmCommand = "npm";
431
+ const registryUrl = sidecarRegistryUrl(hostUrl);
432
+ const versionDir = _path.join.call(void 0, stateDir, "versions", "<version>");
433
+ const manualCommand = `${buildSidecarProjectConfigCommand(versionDir, nodeBin)} && ${npmCommand} install --prefix ${shellQuote(versionDir)} --registry ${shellQuote(registryUrl)} ${NPM_SDK_INSTALL_COMMON_FLAGS.map(shellQuote).join(" ")} ${shellQuote(packageSpec)}`;
434
+ return {
435
+ kind: "python-sidecar",
436
+ stateDir,
437
+ sidecarPath,
438
+ nodeBin,
439
+ npmCommand,
440
+ scope,
441
+ hostUrl,
442
+ registryUrl,
443
+ packageSpec,
444
+ manualCommand
445
+ };
446
+ }
447
+ function findRepoBackedSdkRoot(startPath) {
448
+ let current = _path.resolve.call(void 0, startPath);
449
+ while (true) {
450
+ if (_fs.existsSync.call(void 0, _path.join.call(void 0, current, "package.json")) && _fs.existsSync.call(void 0, _path.join.call(void 0, current, "bin", "deepline-dev.ts"))) {
451
+ const parent2 = _path.dirname.call(void 0, current);
452
+ return _path.basename.call(void 0, parent2) === "packages" && _path.basename.call(void 0, current) === "sdk" ? _path.dirname.call(void 0, parent2) : parent2;
453
+ }
454
+ if (_fs.existsSync.call(void 0, _path.join.call(void 0, current, "sdk", "package.json")) && _fs.existsSync.call(void 0, _path.join.call(void 0, current, "sdk", "bin", "deepline-dev.ts"))) {
455
+ return current;
456
+ }
457
+ const parent = _path.dirname.call(void 0, current);
458
+ if (parent === current) return null;
459
+ current = parent;
460
+ }
461
+ }
462
+ function inferNpmGlobalPrefixFromEntrypoint(entrypoint, env) {
463
+ const normalized = (() => {
464
+ try {
465
+ return _fs.realpathSync.call(void 0, entrypoint);
466
+ } catch (e6) {
467
+ return _path.resolve.call(void 0, entrypoint);
468
+ }
469
+ })();
470
+ const parts = normalized.split(/[\\/]+/);
471
+ const nodeModulesIndex = parts.lastIndexOf("node_modules");
472
+ if (nodeModulesIndex <= 0 || parts[nodeModulesIndex + 1] !== "deepline") {
473
+ return null;
474
+ }
475
+ const prefixParts = parts.slice(0, nodeModulesIndex);
476
+ if (prefixParts.at(-1) === "lib") {
477
+ prefixParts.pop();
478
+ } else {
479
+ const directPrefix = prefixParts.join("/").toLowerCase();
480
+ const knownWindowsPrefixes = [
481
+ env.npm_config_prefix,
482
+ env.APPDATA ? _path.join.call(void 0, env.APPDATA, "npm") : void 0
483
+ ].filter((value) => Boolean(value)).map((value) => _path.resolve.call(void 0, value).replace(/\\/g, "/").toLowerCase());
484
+ if (!knownWindowsPrefixes.includes(
485
+ _path.resolve.call(void 0, directPrefix).replace(/\\/g, "/").toLowerCase()
486
+ )) {
487
+ return null;
488
+ }
489
+ }
490
+ const prefix = normalized.startsWith("/") && prefixParts[0] !== "" ? `/${prefixParts.join("/")}` : prefixParts.join("/");
491
+ return prefix || null;
492
+ }
493
+ function normalizedNpmPrefix(value) {
494
+ const trimmed = _optionalChain([value, 'optionalAccess', _16 => _16.trim, 'call', _17 => _17()]);
495
+ if (!trimmed) return null;
496
+ const normalized = (() => {
497
+ try {
498
+ return _fs.realpathSync.call(void 0, _path.resolve.call(void 0, trimmed));
499
+ } catch (e7) {
500
+ return _path.resolve.call(void 0, trimmed);
501
+ }
502
+ })().replace(/\\/g, "/");
503
+ return process.platform === "win32" ? normalized.toLowerCase() : normalized;
504
+ }
505
+ function resolveNpmGlobalPrefix(env) {
506
+ try {
507
+ const plan = _chunk4NEFYBF7js.resolveShellSpawn.call(void 0, "npm", ["prefix", "-g"]);
508
+ const result = _child_process.spawnSync.call(void 0, plan.command, plan.args, {
509
+ encoding: "utf8",
510
+ env,
511
+ shell: plan.shell,
512
+ stdio: ["ignore", "pipe", "ignore"]
513
+ });
514
+ if (result.status !== 0) return null;
515
+ return String(_nullishCoalesce(result.stdout, () => ( ""))).trim() || null;
516
+ } catch (e8) {
517
+ return null;
518
+ }
519
+ }
520
+ function isHomebrewFormulaEntrypoint(entrypoint) {
521
+ const normalized = (() => {
522
+ try {
523
+ return _fs.realpathSync.call(void 0, entrypoint);
524
+ } catch (e9) {
525
+ return _path.resolve.call(void 0, entrypoint);
526
+ }
527
+ })();
528
+ const parts = normalized.split(/[\\/]+/);
529
+ const cellarIndex = parts.lastIndexOf("Cellar");
530
+ return cellarIndex >= 0 && parts[cellarIndex + 1] === "deepline" && parts.slice(cellarIndex + 3).includes("libexec");
531
+ }
532
+ function resolveUpdatePlan(options = {}) {
533
+ const env = _nullishCoalesce(options.env, () => ( process.env));
534
+ const homeDir = _nullishCoalesce(options.homeDir, () => ( _os.homedir.call(void 0, )));
535
+ const entrypoint = _nullishCoalesce(options.entrypoint, () => ( (process.argv[1] ? _path.resolve.call(void 0, process.argv[1]) : "")));
536
+ const sourceRoot = entrypoint ? findRepoBackedSdkRoot(_path.dirname.call(void 0, entrypoint)) : null;
537
+ if (sourceRoot) {
538
+ return {
539
+ kind: "source",
540
+ repoRoot: sourceRoot,
541
+ manualCommand: buildSourceUpdateCommand(sourceRoot)
542
+ };
543
+ }
544
+ if (entrypoint && isHomebrewFormulaEntrypoint(entrypoint)) {
545
+ return {
546
+ kind: "homebrew",
547
+ manualCommand: "brew upgrade deepline"
548
+ };
549
+ }
550
+ const sidecarPlan = resolvePythonSidecarUpdatePlan({
551
+ entrypoint,
552
+ env,
553
+ homeDir,
554
+ packageSpec: options.packageSpec
555
+ });
556
+ if (sidecarPlan) return sidecarPlan;
557
+ const command = "npm";
558
+ const packageSpec = options.packageSpec || "deepline@latest";
559
+ const inferredInstallPrefix = entrypoint ? inferNpmGlobalPrefixFromEntrypoint(entrypoint, env) : null;
560
+ const npmGlobalPrefix = options.npmGlobalPrefix !== void 0 ? options.npmGlobalPrefix : resolveNpmGlobalPrefix(env);
561
+ const hasVerifiedNpmOwnership = inferredInstallPrefix !== null && normalizedNpmPrefix(inferredInstallPrefix) === normalizedNpmPrefix(npmGlobalPrefix);
562
+ const installPrefix = options.requireVerifiedNpmOwnership ? hasVerifiedNpmOwnership ? inferredInstallPrefix : null : inferredInstallPrefix;
563
+ const npmVersion = options.npmVersion === void 0 ? _chunkU3PI7HBMjs.readNpmVersion.call(void 0, env) : options.npmVersion;
564
+ const npmGlobalInstallFlags = _chunkU3PI7HBMjs.npmSupportsAllowScripts.call(void 0, npmVersion) ? [...NPM_SDK_INSTALL_COMMON_FLAGS, "--allow-scripts=esbuild"] : NPM_SDK_INSTALL_COMMON_FLAGS;
565
+ const args = installPrefix ? [
566
+ "install",
567
+ "-g",
568
+ "--prefix",
569
+ installPrefix,
570
+ ...npmGlobalInstallFlags,
571
+ packageSpec
572
+ ] : ["install", "-g", ...npmGlobalInstallFlags, packageSpec];
573
+ const fallbackRegistryUrl = options.npmFallbackRegistryUrl !== void 0 ? options.npmFallbackRegistryUrl : publicNpmFallbackRegistryUrl(
574
+ _optionalChain([env, 'access', _18 => _18.DEEPLINE_HOST_URL, 'optionalAccess', _19 => _19.trim, 'call', _20 => _20()]) || _chunkXRK2TZT5js.autoDetectBaseUrl.call(void 0, )
575
+ );
576
+ return {
577
+ kind: "npm-global",
578
+ command,
579
+ args,
580
+ ...installPrefix ? { installPrefix } : {},
581
+ ...fallbackRegistryUrl ? { fallbackRegistryUrl } : {},
582
+ manualCommand: `${command} ${args.map(shellQuote).join(" ")}`
583
+ };
584
+ }
585
+ var AUTO_UPDATE_FAILURE_FILE = ".auto-update-failure.json";
586
+ function autoUpdateFailurePath(plan) {
587
+ if (plan.kind === "source" || plan.kind === "homebrew") return null;
588
+ if (plan.kind === "python-sidecar") {
589
+ return _path.join.call(void 0, plan.stateDir, AUTO_UPDATE_FAILURE_FILE);
590
+ }
591
+ return _path.join.call(void 0,
592
+ _os.homedir.call(void 0, ),
593
+ ".local",
594
+ "deepline",
595
+ "sdk-cli",
596
+ AUTO_UPDATE_FAILURE_FILE
597
+ );
598
+ }
599
+ function autoUpdatePackageSpec(plan) {
600
+ if (plan.kind === "source" || plan.kind === "homebrew") return "";
601
+ if (plan.kind === "python-sidecar") return plan.packageSpec;
602
+ return _nullishCoalesce(plan.args[plan.args.length - 1], () => ( plan.manualCommand));
603
+ }
604
+ function readAutoUpdateFailure(plan) {
605
+ const path = autoUpdateFailurePath(plan);
606
+ if (!path) return null;
607
+ try {
608
+ const parsed = JSON.parse(
609
+ _fs.readFileSync.call(void 0, path, "utf8")
610
+ );
611
+ if ((parsed.kind === "npm-global" || parsed.kind === "python-sidecar") && typeof parsed.packageSpec === "string" && typeof parsed.failedAt === "string" && typeof parsed.exitCode === "number" && typeof parsed.manualCommand === "string") {
612
+ return parsed;
613
+ }
614
+ } catch (e10) {
615
+ return null;
616
+ }
617
+ return null;
618
+ }
619
+ function writeAutoUpdateFailure(plan, exitCode) {
620
+ const path = autoUpdateFailurePath(plan);
621
+ if (!path || plan.kind === "source" || plan.kind === "homebrew") return;
622
+ const marker = {
623
+ kind: plan.kind,
624
+ packageSpec: autoUpdatePackageSpec(plan),
625
+ failedAt: (/* @__PURE__ */ new Date()).toISOString(),
626
+ exitCode,
627
+ manualCommand: plan.manualCommand
628
+ };
629
+ try {
630
+ _fs.mkdirSync.call(void 0, _path.dirname.call(void 0, path), { recursive: true });
631
+ _fs.writeFileSync.call(void 0, path, `${JSON.stringify(marker, null, 2)}
632
+ `, "utf8");
633
+ } catch (e11) {
634
+ }
635
+ }
636
+ function clearAutoUpdateFailure(plan) {
637
+ const path = autoUpdateFailurePath(plan);
638
+ if (!path) return;
639
+ try {
640
+ _fs.unlinkSync.call(void 0, path);
641
+ } catch (e12) {
642
+ }
643
+ }
644
+ function matchingAutoUpdateFailure(plan) {
645
+ const marker = readAutoUpdateFailure(plan);
646
+ if (!marker || plan.kind === "source" || plan.kind === "homebrew") {
647
+ return null;
648
+ }
649
+ if (marker.kind !== plan.kind) return null;
650
+ if (marker.packageSpec !== autoUpdatePackageSpec(plan)) return null;
651
+ return marker;
652
+ }
653
+ async function runAutomaticUpdatePlan(plan) {
654
+ const previousFailure = matchingAutoUpdateFailure(plan);
655
+ if (previousFailure) {
656
+ process.stderr.write(
657
+ [
658
+ "Skipping Deepline SDK/CLI auto-update because this same update already failed on this machine.",
659
+ `Fix Node/npm native package installation issues, then run: ${previousFailure.manualCommand}`,
660
+ "Common causes include broken esbuild installs, node-gyp build toolchain errors, npm cache corruption, or registry/network failures.",
661
+ ""
662
+ ].join("\n")
663
+ );
664
+ return {
665
+ status: "skipped_previous_failure",
666
+ exitCode: previousFailure.exitCode || 1,
667
+ previousFailure
668
+ };
669
+ }
670
+ const exitCode = await runUpdatePlan(plan);
671
+ return exitCode === 0 ? { status: "updated", exitCode: 0 } : { status: "failed", exitCode };
672
+ }
673
+ function safeVersionSegment(value) {
674
+ const normalized = value.trim();
675
+ return /^[0-9A-Za-z._-]+$/.test(normalized) ? normalized : "";
676
+ }
677
+ function entryPathInVersionDir(versionDir) {
678
+ return _path.join.call(void 0,
679
+ versionDir,
680
+ "node_modules",
681
+ "deepline",
682
+ "dist",
683
+ "cli",
684
+ "index.mjs"
685
+ );
686
+ }
687
+ function installedPackageVersion(versionDir) {
688
+ const packageJsonPath = _path.join.call(void 0,
689
+ versionDir,
690
+ "node_modules",
691
+ "deepline",
692
+ "package.json"
693
+ );
694
+ try {
695
+ const parsed = JSON.parse(_fs.readFileSync.call(void 0, packageJsonPath, "utf8"));
696
+ return typeof parsed.version === "string" ? safeVersionSegment(parsed.version) : "";
697
+ } catch (e13) {
698
+ return "";
699
+ }
700
+ }
701
+ function sidecarStructureFailure(versionDir) {
702
+ const health = inspectSdkSidecarInstall(versionDir);
703
+ if (!health.ok) {
704
+ const details = [
705
+ ...health.invalidReason ? [health.invalidReason] : [],
706
+ ...health.missing.length > 0 ? [`missing ${health.missing.join(", ")}`] : []
707
+ ].join("; ");
708
+ return details || "required SDK CLI files are missing";
709
+ }
710
+ return null;
711
+ }
712
+ function sidecarInstallFailure(versionDir) {
713
+ const structureFailure = sidecarStructureFailure(versionDir);
714
+ if (structureFailure) return structureFailure;
715
+ const esbuildFailure = probeSdkSidecarEsbuild(versionDir);
716
+ return esbuildFailure ? `esbuild probe failed: ${esbuildFailure}` : null;
717
+ }
718
+ function runCommand(command, args, env = process.env) {
719
+ return new Promise((resolveResult) => {
720
+ let output = "";
721
+ const plan = _chunk4NEFYBF7js.resolveShellSpawn.call(void 0, command, args);
722
+ const child = _child_process.spawn.call(void 0, plan.command, plan.args, {
723
+ stdio: ["inherit", "pipe", "pipe"],
724
+ shell: plan.shell,
725
+ env
726
+ });
727
+ _optionalChain([child, 'access', _21 => _21.stdout, 'optionalAccess', _22 => _22.on, 'call', _23 => _23("data", (chunk) => {
728
+ output += chunk.toString();
729
+ process.stderr.write(chunk);
730
+ })]);
731
+ _optionalChain([child, 'access', _24 => _24.stderr, 'optionalAccess', _25 => _25.on, 'call', _26 => _26("data", (chunk) => {
732
+ output += chunk.toString();
733
+ process.stderr.write(chunk);
734
+ })]);
735
+ child.on("error", (error) => {
736
+ process.stderr.write(`Failed to start ${command}: ${error.message}
737
+ `);
738
+ resolveResult({ exitCode: 1, output: `${output}
739
+ ${error.message}` });
740
+ });
741
+ child.on("close", (code) => {
742
+ resolveResult({ exitCode: _nullishCoalesce(code, () => ( 1)), output });
743
+ });
744
+ });
745
+ }
746
+ var DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org/";
747
+ function isRegistryAccessFailure(output, registryUrl) {
748
+ let registryHost = "";
749
+ try {
750
+ registryHost = new URL(registryUrl).hostname;
751
+ } catch (e14) {
752
+ return false;
753
+ }
754
+ if (!registryHost || !output.toLowerCase().includes(registryHost.toLowerCase())) {
755
+ return false;
756
+ }
757
+ return /\b(?:EAI_AGAIN|ECONNREFUSED|ECONNRESET|ENETUNREACH|ENOTFOUND|EHOSTUNREACH|ETIMEDOUT|E5\d\d)\b|\b5\d\d\b|access denied|blocked|forbidden|network (?:error|timeout)|request .* failed/iu.test(
758
+ output
759
+ );
760
+ }
761
+ function withRegistry(args, registryUrl) {
762
+ return [...args.slice(0, -1), "--registry", registryUrl, _nullishCoalesce(args.at(-1), () => ( ""))];
763
+ }
764
+ function isBinLinkExistsFailure(output) {
765
+ return /\bEEXIST\b/i.test(output) && /symlink/i.test(output);
766
+ }
767
+ function withForce(args) {
768
+ if (args.includes("--force")) return args;
769
+ return [...args.slice(0, -1), "--force", _nullishCoalesce(args.at(-1), () => ( ""))];
770
+ }
771
+ async function runNpmInstallWithRegistryFallback(input) {
772
+ const primaryArgs = input.primaryRegistryUrl ? withRegistry(input.installArgs, input.primaryRegistryUrl) : input.installArgs;
773
+ const first = await runCommand(
774
+ input.npmCommand,
775
+ primaryArgs,
776
+ _nullishCoalesce(input.env, () => ( process.env))
777
+ );
778
+ if (first.exitCode === 0) {
779
+ return first.exitCode;
780
+ }
781
+ if (input.fallbackRegistryUrl && isRegistryAccessFailure(
782
+ first.output,
783
+ _nullishCoalesce(input.primaryRegistryUrl, () => ( DEFAULT_NPM_REGISTRY_URL))
784
+ )) {
785
+ process.stderr.write(
786
+ `Primary npm registry access failed; retrying through Deepline's registry: ${input.fallbackRegistryUrl}
787
+ `
788
+ );
789
+ const fallback = await runCommand(
790
+ input.npmCommand,
791
+ withRegistry(input.installArgs, input.fallbackRegistryUrl),
792
+ _nullishCoalesce(input.env, () => ( process.env))
793
+ );
794
+ return fallback.exitCode;
795
+ }
796
+ if (isBinLinkExistsFailure(first.output)) {
797
+ process.stderr.write(
798
+ "npm refused to relink an existing global bin symlink (EEXIST); retrying with --force since this plan only targets this CLI's own install prefix.\n"
799
+ );
800
+ const forced = await runCommand(
801
+ input.npmCommand,
802
+ withForce(primaryArgs),
803
+ _nullishCoalesce(input.env, () => ( process.env))
804
+ );
805
+ return forced.exitCode;
806
+ }
807
+ return first.exitCode;
808
+ }
809
+ function writeSidecarLauncher(input) {
810
+ _fs.mkdirSync.call(void 0, _path.dirname.call(void 0, input.path), { recursive: true });
811
+ const packageRoot = _path.dirname.call(void 0, _path.dirname.call(void 0, _path.dirname.call(void 0, input.entryPath)));
812
+ const versionDir = _path.dirname.call(void 0, _path.dirname.call(void 0, packageRoot));
813
+ const esbuildProbe = "const {createRequire}=require('node:module');const path=require('node:path');const req=createRequire(path.join(process.argv[1],'package.json'));const result=req('esbuild').transformSync('const value: number = 1;',{loader:'ts'});if(!result||typeof result.code!=='string')process.exit(3);";
814
+ const criticalPaths = [
815
+ ...SDK_SIDECAR_CRITICAL_PACKAGE_FILES.map(
816
+ (path) => _path.join.call(void 0, packageRoot, path)
817
+ ),
818
+ ...SDK_SIDECAR_CRITICAL_DEPENDENCY_FILES.map(
819
+ (path) => _path.join.call(void 0, versionDir, "node_modules", path)
820
+ )
821
+ ];
822
+ if (process.platform === "win32") {
823
+ _fs.writeFileSync.call(void 0,
824
+ input.path,
825
+ [
826
+ `@set DEEPLINE_HOST_URL=${input.hostUrl.replace(/\r?\n/g, "")}`,
827
+ `@set DEEPLINE_CONFIG_SCOPE=${input.scope.replace(/\r?\n/g, "")}`,
828
+ ...criticalPaths.map(
829
+ (path) => `@if not exist "${path}" goto repair_sdk`
830
+ ),
831
+ `@"${input.nodeBin}" -e "${esbuildProbe}" "${versionDir}" >NUL 2>&1`,
832
+ "@if errorlevel 1 goto repair_sdk",
833
+ `@"${input.nodeBin}" "${input.entryPath}" %*`,
834
+ "@exit /b %ERRORLEVEL%",
835
+ ":repair_sdk",
836
+ '@if defined DEEPLINE_REAL_BINARY "%DEEPLINE_REAL_BINARY%" --version=v2 %*',
837
+ "@if defined DEEPLINE_REAL_BINARY exit /b %ERRORLEVEL%",
838
+ "@echo Deepline SDK CLI install is incomplete. Run `deepline update` to repair it. 1>&2",
839
+ "@exit /b 1",
840
+ ""
841
+ ].join("\r\n"),
842
+ "utf8"
843
+ );
844
+ return;
845
+ }
846
+ _fs.writeFileSync.call(void 0,
847
+ input.path,
848
+ [
849
+ "#!/usr/bin/env sh",
850
+ `export DEEPLINE_HOST_URL=${shellQuote(input.hostUrl)}`,
851
+ `export DEEPLINE_CONFIG_SCOPE=${shellQuote(input.scope)}`,
852
+ `if ${criticalPaths.map((path) => `[ ! -f ${shellQuote(path)} ]`).join(" || ")}; then`,
853
+ ' if [ -n "${DEEPLINE_REAL_BINARY:-}" ] && [ -x "$DEEPLINE_REAL_BINARY" ]; then',
854
+ ' exec "$DEEPLINE_REAL_BINARY" --version=v2 "$@"',
855
+ " fi",
856
+ ' printf "%s\\n" "Deepline SDK CLI install is incomplete. Run \\`deepline update\\` to repair it." >&2',
857
+ " exit 1",
858
+ "fi",
859
+ `if ! ${shellQuote(input.nodeBin)} -e ${shellQuote(esbuildProbe)} ${shellQuote(versionDir)} >/dev/null 2>&1; then`,
860
+ ' if [ -n "${DEEPLINE_REAL_BINARY:-}" ] && [ -x "$DEEPLINE_REAL_BINARY" ]; then',
861
+ ' exec "$DEEPLINE_REAL_BINARY" --version=v2 "$@"',
862
+ " fi",
863
+ ' printf "%s\\n" "Deepline SDK CLI install is incomplete. Run \\`deepline update\\` to repair it." >&2',
864
+ " exit 1",
865
+ "fi",
866
+ `exec ${shellQuote(input.nodeBin)} ${shellQuote(input.entryPath)} "$@"`,
867
+ ""
868
+ ].join("\n"),
869
+ { encoding: "utf8", mode: 493 }
870
+ );
871
+ }
872
+ async function runPythonSidecarUpdatePlan(plan) {
873
+ const versionsDir = _path.join.call(void 0, plan.stateDir, "versions");
874
+ const tempDir = _path.join.call(void 0,
875
+ versionsDir,
876
+ `.tmp-sdk-update-${process.pid}-${Date.now()}`
877
+ );
878
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
879
+ _fs.mkdirSync.call(void 0, tempDir, { recursive: true });
880
+ _fs.writeFileSync.call(void 0, _path.join.call(void 0, tempDir, "package.json"), NPM_SDK_SIDECAR_PACKAGE_JSON);
881
+ const env = {
882
+ ...process.env,
883
+ PATH: `${_path.dirname.call(void 0, plan.nodeBin)}${process.platform === "win32" ? ";" : ":"}${_nullishCoalesce(process.env.PATH, () => ( ""))}`
884
+ };
885
+ const installResult = await runCommand(
886
+ plan.npmCommand,
887
+ [
888
+ "install",
889
+ "--prefix",
890
+ tempDir,
891
+ "--registry",
892
+ plan.registryUrl,
893
+ ...NPM_SDK_INSTALL_COMMON_FLAGS,
894
+ plan.packageSpec
895
+ ],
896
+ env
897
+ );
898
+ const installExitCode = installResult.exitCode;
899
+ if (installExitCode !== 0) {
900
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
901
+ return installExitCode;
902
+ }
903
+ const installedVersion = installedPackageVersion(tempDir);
904
+ if (!installedVersion) {
905
+ process.stderr.write(
906
+ "Updated Deepline SDK package did not report a version.\n"
907
+ );
908
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
909
+ return 1;
910
+ }
911
+ const stagedFailure = sidecarInstallFailure(tempDir);
912
+ if (stagedFailure) {
913
+ process.stderr.write(
914
+ `Updated Deepline SDK package is incomplete: ${stagedFailure}.
915
+ `
916
+ );
917
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
918
+ return 1;
919
+ }
920
+ const finalDir = _path.join.call(void 0, versionsDir, installedVersion);
921
+ const finalEntryPath = entryPathInVersionDir(finalDir);
922
+ const finalFailure = sidecarInstallFailure(finalDir);
923
+ let backupDir = null;
924
+ if (!finalFailure) {
925
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
926
+ } else {
927
+ let shouldPublishTemp = true;
928
+ if (_fs.existsSync.call(void 0, finalDir)) {
929
+ backupDir = _path.join.call(void 0,
930
+ versionsDir,
931
+ `.backup-${installedVersion}-${process.pid}-${Date.now()}`
932
+ );
933
+ try {
934
+ _fs.renameSync.call(void 0, finalDir, backupDir);
935
+ } catch (error) {
936
+ const concurrentlyPublishedFailure = sidecarInstallFailure(finalDir);
937
+ if (!concurrentlyPublishedFailure) {
938
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
939
+ backupDir = null;
940
+ shouldPublishTemp = false;
941
+ } else {
942
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
943
+ process.stderr.write(
944
+ `Failed to preserve the incomplete Deepline SDK sidecar before repair: ${error.message}.
945
+ `
946
+ );
947
+ return 1;
948
+ }
949
+ }
950
+ }
951
+ if (shouldPublishTemp) {
952
+ try {
953
+ _fs.renameSync.call(void 0, tempDir, finalDir);
954
+ } catch (error) {
955
+ _fs.rmSync.call(void 0, tempDir, { recursive: true, force: true });
956
+ const concurrentlyPublishedFailure = sidecarInstallFailure(finalDir);
957
+ if (!concurrentlyPublishedFailure) {
958
+ if (backupDir) _fs.rmSync.call(void 0, backupDir, { recursive: true, force: true });
959
+ backupDir = null;
960
+ } else {
961
+ let restoreFailure = "";
962
+ if (backupDir && _fs.existsSync.call(void 0, backupDir) && !_fs.existsSync.call(void 0, finalDir)) {
963
+ try {
964
+ _fs.renameSync.call(void 0, backupDir, finalDir);
965
+ backupDir = null;
966
+ } catch (restoreError) {
967
+ restoreFailure = `; failed to restore previous install: ${restoreError.message}`;
968
+ }
969
+ }
970
+ process.stderr.write(
971
+ `Failed to publish Deepline SDK sidecar update: ${error.message}; current install remains incomplete: ${concurrentlyPublishedFailure}${restoreFailure}.
972
+ `
973
+ );
974
+ return 1;
975
+ }
976
+ }
977
+ }
978
+ }
979
+ const publishedFailure = sidecarStructureFailure(finalDir);
980
+ if (publishedFailure) {
981
+ if (backupDir && _fs.existsSync.call(void 0, backupDir)) {
982
+ _fs.rmSync.call(void 0, finalDir, { recursive: true, force: true });
983
+ try {
984
+ _fs.renameSync.call(void 0, backupDir, finalDir);
985
+ backupDir = null;
986
+ } catch (e15) {
987
+ }
988
+ }
989
+ process.stderr.write(
990
+ `Updated Deepline SDK CLI install is incomplete: ${publishedFailure}.
991
+ `
992
+ );
993
+ return 1;
994
+ }
995
+ if (backupDir) _fs.rmSync.call(void 0, backupDir, { recursive: true, force: true });
996
+ writeSidecarLauncher({
997
+ path: plan.sidecarPath,
998
+ hostUrl: plan.hostUrl,
999
+ scope: plan.scope,
1000
+ nodeBin: plan.nodeBin,
1001
+ entryPath: finalEntryPath
1002
+ });
1003
+ _fs.writeFileSync.call(void 0,
1004
+ _path.join.call(void 0, plan.stateDir, ".version"),
1005
+ `${installedVersion}
1006
+ `,
1007
+ "utf8"
1008
+ );
1009
+ _fs.writeFileSync.call(void 0,
1010
+ _path.join.call(void 0, plan.stateDir, ".install-method"),
1011
+ "python-sidecar\n",
1012
+ "utf8"
1013
+ );
1014
+ _fs.writeFileSync.call(void 0,
1015
+ _path.join.call(void 0, plan.stateDir, ".command-path"),
1016
+ `${plan.sidecarPath}
1017
+ `,
1018
+ "utf8"
1019
+ );
1020
+ _fs.writeFileSync.call(void 0, _path.join.call(void 0, plan.stateDir, ".runner"), "node\n", "utf8");
1021
+ _fs.writeFileSync.call(void 0, _path.join.call(void 0, plan.stateDir, ".node-bin"), `${plan.nodeBin}
1022
+ `, "utf8");
1023
+ _fs.writeFileSync.call(void 0,
1024
+ _path.join.call(void 0, plan.stateDir, ".entry-path"),
1025
+ `${finalEntryPath}
1026
+ `,
1027
+ "utf8"
1028
+ );
1029
+ return 0;
1030
+ }
1031
+ async function runUpdatePlan(plan) {
1032
+ let exitCode = 1;
1033
+ if (plan.kind === "npm-global") {
1034
+ exitCode = await runNpmInstallWithRegistryFallback({
1035
+ npmCommand: plan.command,
1036
+ installArgs: plan.args,
1037
+ primaryRegistryUrl: plan.primaryRegistryUrl,
1038
+ fallbackRegistryUrl: plan.fallbackRegistryUrl
1039
+ });
1040
+ } else if (plan.kind === "python-sidecar") {
1041
+ exitCode = await runPythonSidecarUpdatePlan(plan);
1042
+ } else if (plan.kind === "homebrew") {
1043
+ exitCode = 0;
1044
+ }
1045
+ if (exitCode === 0) {
1046
+ clearAutoUpdateFailure(plan);
1047
+ } else {
1048
+ writeAutoUpdateFailure(plan, exitCode);
1049
+ }
1050
+ return exitCode;
1051
+ }
1052
+ function normalizeBaseUrl(value) {
1053
+ return value.replace(/\/$/, "");
1054
+ }
1055
+ function normalizePinnedVersion(value) {
1056
+ const normalized = _nullishCoalesce(_optionalChain([value, 'optionalAccess', _27 => _27.trim, 'call', _28 => _28(), 'access', _29 => _29.replace, 'call', _30 => _30(/^v/, "")]), () => ( ""));
1057
+ return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(normalized) ? normalized : null;
1058
+ }
1059
+ async function publishedVersionSupportsPin(version, fallbackRegistryUrl) {
1060
+ const registryUrls = [
1061
+ "https://registry.npmjs.org/",
1062
+ ...fallbackRegistryUrl ? [fallbackRegistryUrl] : []
1063
+ ];
1064
+ let lastError = null;
1065
+ for (const registryUrl of registryUrls) {
1066
+ const controller = new AbortController();
1067
+ const timeout = setTimeout(() => controller.abort(), 3e3);
1068
+ try {
1069
+ const response = await fetch(
1070
+ new URL(
1071
+ `deepline/${encodeURIComponent(version)}`,
1072
+ registryUrl.endsWith("/") ? registryUrl : `${registryUrl}/`
1073
+ ),
1074
+ {
1075
+ headers: { accept: "application/json" },
1076
+ signal: controller.signal
1077
+ }
1078
+ );
1079
+ if (response.status === 404) return false;
1080
+ if (!response.ok) {
1081
+ lastError = new Error(
1082
+ `${registryUrl} returned HTTP ${response.status}`
1083
+ );
1084
+ continue;
1085
+ }
1086
+ const metadata = await response.json();
1087
+ return _optionalChain([metadata, 'access', _31 => _31.deepline, 'optionalAccess', _32 => _32.updatePreferences]) === 1;
1088
+ } catch (error) {
1089
+ lastError = error instanceof Error ? error : new Error(String(error));
1090
+ } finally {
1091
+ clearTimeout(timeout);
1092
+ }
1093
+ }
1094
+ throw _nullishCoalesce(lastError, () => ( new Error("No npm registry was available")));
1095
+ }
1096
+ async function runUpdateCommand(options, dependencies = {}) {
1097
+ const detectBaseUrl = _nullishCoalesce(dependencies.detectBaseUrl, () => ( _chunkXRK2TZT5js.autoDetectBaseUrl));
1098
+ const resolvePlan = _nullishCoalesce(dependencies.resolvePlan, () => ( resolveUpdatePlan));
1099
+ const runPlan = _nullishCoalesce(dependencies.runPlan, () => ( runUpdatePlan));
1100
+ const syncSkills = _nullishCoalesce(dependencies.syncSkillsIfNeeded, () => ( (async () => {
1101
+ const originalWrite = process.stdout.write.bind(process.stdout);
1102
+ process.stdout.write = (() => true);
1103
+ try {
1104
+ const exitCode = await _chunk4NEFYBF7js.runSkillsCommand.call(void 0, { json: true });
1105
+ if (exitCode !== 0) {
1106
+ throw new Error(
1107
+ `Deepline skills update failed with exit ${exitCode}.`
1108
+ );
1109
+ }
1110
+ } finally {
1111
+ process.stdout.write = originalWrite;
1112
+ }
1113
+ })));
1114
+ const stderr = _nullishCoalesce(dependencies.stderr, () => ( process.stderr));
1115
+ const setPinnedVersion = _nullishCoalesce(dependencies.setPinnedVersion, () => ( setCliPinnedVersion));
1116
+ const clearPinnedVersion = _nullishCoalesce(dependencies.clearPinnedVersion, () => ( clearCliPinnedVersion));
1117
+ const targetSupportsPin = _nullishCoalesce(dependencies.targetSupportsPin, () => ( publishedVersionSupportsPin));
1118
+ const pinnedVersion = options.pin ? normalizePinnedVersion(options.pin) : null;
1119
+ if (options.pin && !pinnedVersion) {
1120
+ stderr.write(
1121
+ `Invalid pinned version "${options.pin}". Use an exact semantic version such as 0.3.0.
1122
+ `
1123
+ );
1124
+ return 2;
1125
+ }
1126
+ const plan = resolvePlan(
1127
+ pinnedVersion ? {
1128
+ packageSpec: `deepline@${pinnedVersion}`
1129
+ } : void 0
1130
+ );
1131
+ if (pinnedVersion && !canAutomaticallyApplyUpdatePlan(plan)) {
1132
+ stderr.write(
1133
+ plan.kind === "source" ? "Cannot pin a repo-backed Deepline CLI. Check out the desired SDK revision in the backing repository.\n" : plan.kind === "homebrew" ? "Cannot pin a Homebrew-managed Deepline CLI with npm. Pin the Homebrew formula version instead.\n" : "Cannot pin a project-local or npm-exec Deepline CLI because it does not own a global installation.\n"
1134
+ );
1135
+ return 2;
1136
+ }
1137
+ if (pinnedVersion) {
1138
+ let supportsPin = false;
1139
+ try {
1140
+ const fallbackRegistryUrl = plan.kind === "python-sidecar" ? plan.registryUrl : plan.kind === "npm-global" ? plan.fallbackRegistryUrl : void 0;
1141
+ supportsPin = await targetSupportsPin(pinnedVersion, fallbackRegistryUrl);
1142
+ } catch (error) {
1143
+ stderr.write(
1144
+ `Could not verify whether Deepline CLI ${pinnedVersion} supports version pins: ${error instanceof Error ? error.message : String(error)}
1145
+ `
1146
+ );
1147
+ return 5;
1148
+ }
1149
+ if (!supportsPin) {
1150
+ stderr.write(
1151
+ `Cannot pin Deepline CLI ${pinnedVersion}. That published version does not support persisted version pins.
1152
+ `
1153
+ );
1154
+ return 2;
1155
+ }
1156
+ }
1157
+ const render = {
1158
+ sections: [
1159
+ {
1160
+ title: "update",
1161
+ lines: plan.kind === "source" ? [
1162
+ "This Deepline CLI is running from SDK source, so it cannot safely update itself like an npm global.",
1163
+ `Update the backing checkout with: ${plan.manualCommand}`
1164
+ ] : plan.kind === "homebrew" ? [
1165
+ "This Deepline CLI was installed by Homebrew, which owns its upgrades.",
1166
+ `Update it with: ${plan.manualCommand}`
1167
+ ] : plan.kind === "python-sidecar" ? [
1168
+ "This Deepline CLI is running from the Python-managed SDK sidecar.",
1169
+ "Updating will refresh that sidecar, not a global npm binary."
1170
+ ] : [`Updating Deepline SDK/CLI with: ${plan.manualCommand}`]
1171
+ }
1172
+ ]
1173
+ };
1174
+ if (options.json && !options.executeWithJson) {
1175
+ _chunkF35VOIQLjs.printCommandEnvelope.call(void 0, { ...plan, render }, { json: true });
1176
+ return 0;
1177
+ }
1178
+ if (options.printCommand) {
1179
+ _chunkF35VOIQLjs.printCommandEnvelope.call(void 0,
1180
+ {
1181
+ ...plan,
1182
+ render: {
1183
+ sections: [{ title: "update command", lines: [plan.manualCommand] }]
1184
+ }
1185
+ },
1186
+ { json: false, text: `${plan.manualCommand}
1187
+ ` }
1188
+ );
1189
+ return 0;
1190
+ }
1191
+ if (plan.kind === "source" || plan.kind === "homebrew") {
1192
+ _chunkF35VOIQLjs.printCommandEnvelope.call(void 0, { ...plan, render }, { json: false });
1193
+ return 0;
1194
+ }
1195
+ stderr.write(`Updating Deepline SDK/CLI with: ${plan.manualCommand}
1196
+ `);
1197
+ const updateExitCode = await runPlan(plan);
1198
+ if (updateExitCode !== 0) {
1199
+ return updateExitCode;
1200
+ }
1201
+ if (pinnedVersion) {
1202
+ setPinnedVersion(pinnedVersion);
1203
+ stderr.write(
1204
+ `Pinned Deepline CLI to ${pinnedVersion}. Run deepline settings autoupdate on to clear the pin.
1205
+ `
1206
+ );
1207
+ } else {
1208
+ clearPinnedVersion();
1209
+ }
1210
+ try {
1211
+ await syncSkills(normalizeBaseUrl(detectBaseUrl()));
1212
+ } catch (error) {
1213
+ const detail = error instanceof Error ? error.message : String(error);
1214
+ stderr.write(
1215
+ `Deepline SDK/CLI update completed, but the optional local agent-skills refresh failed. Your CLI update succeeded; this does not affect authentication, data, billing, or the command result.
1216
+ Skills refresh detail: ${detail}
1217
+ To retry with full installer output, run: deepline skills --json
1218
+ `
1219
+ );
1220
+ }
1221
+ if (options.executeWithJson && options.json) {
1222
+ _chunkF35VOIQLjs.printCommandEnvelope.call(void 0,
1223
+ {
1224
+ ok: true,
1225
+ pinnedVersion
1226
+ },
1227
+ { json: true }
1228
+ );
1229
+ }
1230
+ return 0;
1231
+ }
1232
+ function registerUpdateCommand(program) {
1233
+ program.command("update").description("Update the Deepline SDK/CLI.").addHelpText(
1234
+ "after",
1235
+ `
1236
+ Notes:
1237
+ For the published npm CLI, this runs npm install -g deepline@latest.
1238
+ Automatic updates are enabled by default and run before normal commands.
1239
+ Configure automatic updates with deepline settings autoupdate.
1240
+ For a Homebrew installation, this prints brew upgrade deepline; Homebrew
1241
+ owns formula upgrades and Deepline never runs npm inside its Cellar.
1242
+ For Python-managed SDK sidecars, this refreshes the sidecar that launched
1243
+ the current SDK CLI instead of changing a global npm binary.
1244
+ For repo-backed SDK wrappers such as cli-env sdk-prod or sdk-worktree, this
1245
+ prints the exact git command to update the checkout that provides the CLI.
1246
+
1247
+ Examples:
1248
+ deepline update
1249
+ deepline update --print-command
1250
+ deepline update --json
1251
+ `
1252
+ ).option("--print-command", "Print the update command without running it").option("--json", "Emit the resolved update plan as JSON").action(async (options) => {
1253
+ process.exitCode = await runUpdateCommand(options);
1254
+ });
1255
+ }
1256
+
1257
+
1258
+
1259
+
1260
+
1261
+
1262
+
1263
+
1264
+
1265
+
1266
+
1267
+
1268
+
1269
+ exports.readCliUpdatePreferences = readCliUpdatePreferences; exports.setCliAutoUpdateEnabled = setCliAutoUpdateEnabled; exports.shouldRunCliAutoUpdate = shouldRunCliAutoUpdate; exports.consumePendingCliUpdateMessages = consumePendingCliUpdateMessages; exports.canAutomaticallyApplyUpdatePlan = canAutomaticallyApplyUpdatePlan; exports.resolveUpdatePlan = resolveUpdatePlan; exports.runAutomaticUpdatePlan = runAutomaticUpdatePlan; exports.runUpdatePlan = runUpdatePlan; exports.publishedVersionSupportsPin = publishedVersionSupportsPin; exports.runUpdateCommand = runUpdateCommand; exports.registerUpdateCommand = registerUpdateCommand;