deepline 0.3.294 → 0.3.296

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.ts +108 -35
  4. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-api-origin.ts +25 -0
  5. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +14 -1
  6. package/dist/cli/auth-JCGIDVDF.mjs +31 -0
  7. package/dist/cli/auth-QDWV3TXX.js +31 -0
  8. package/dist/cli/billing-OQBSIXRG.mjs +1749 -0
  9. package/dist/cli/billing-YBK3J4WP.js +1749 -0
  10. package/dist/cli/chunk-2C3AVPTY.js +5688 -0
  11. package/dist/cli/chunk-2MZ5EQZE.mjs +499 -0
  12. package/dist/cli/chunk-3KC45UVF.js +150 -0
  13. package/dist/cli/chunk-3XX5TEA4.js +15 -0
  14. package/dist/cli/chunk-4MBOJQPL.mjs +0 -0
  15. package/dist/cli/chunk-4Y6CG4GE.js +2240 -0
  16. package/dist/cli/chunk-4ZB3CJRD.js +1269 -0
  17. package/dist/cli/chunk-5JLQPVNX.js +3056 -0
  18. package/dist/cli/chunk-6A3TJUWC.js +76 -0
  19. package/dist/cli/chunk-6HPEDBSJ.js +1995 -0
  20. package/dist/cli/chunk-7D6QG5KF.js +890 -0
  21. package/dist/cli/chunk-7P5AA3SN.js +344 -0
  22. package/dist/cli/chunk-7UAO5MWV.mjs +190 -0
  23. package/dist/cli/chunk-A7427JJH.js +190 -0
  24. package/dist/cli/chunk-AQRTLPHZ.js +735 -0
  25. package/dist/cli/chunk-AYHLUHE5.js +52 -0
  26. package/dist/cli/chunk-BZ77OTRF.mjs +923 -0
  27. package/dist/cli/chunk-CBVIJSHF.mjs +560 -0
  28. package/dist/cli/chunk-COGTRVWW.js +30 -0
  29. package/dist/cli/chunk-DLIRSHV6.mjs +28 -0
  30. package/dist/cli/chunk-DYWHXO7O.mjs +34 -0
  31. package/dist/cli/chunk-EDWJY6T4.mjs +3056 -0
  32. package/dist/cli/chunk-EXMLR72R.mjs +0 -0
  33. package/dist/cli/chunk-G46HHFNB.mjs +1269 -0
  34. package/dist/cli/chunk-GAMFK2ZP.mjs +148 -0
  35. package/dist/cli/chunk-GLKUGBTP.mjs +2240 -0
  36. package/dist/cli/chunk-GONRLVV3.js +3440 -0
  37. package/dist/cli/chunk-GVUJJJ5G.mjs +76 -0
  38. package/dist/cli/chunk-H7HIDGZ7.mjs +150 -0
  39. package/dist/cli/chunk-HUZXWOSK.mjs +503 -0
  40. package/dist/cli/chunk-I5YZLGMG.js +1 -0
  41. package/dist/cli/chunk-ITOFSXIU.mjs +15 -0
  42. package/dist/cli/chunk-J2D3VDOU.mjs +5688 -0
  43. package/dist/cli/chunk-J5NA2TTX.js +503 -0
  44. package/dist/cli/chunk-JCS5TPNY.mjs +3440 -0
  45. package/dist/cli/chunk-JNNOCMQY.js +47 -0
  46. package/dist/cli/chunk-KRD6H754.mjs +30 -0
  47. package/dist/cli/chunk-L4HBNHFW.js +34 -0
  48. package/dist/cli/chunk-LA46MMTL.js +560 -0
  49. package/dist/cli/chunk-LIKFCE7Z.js +190 -0
  50. package/dist/cli/chunk-MIMASXO4.mjs +389 -0
  51. package/dist/cli/chunk-NPPJX3BL.mjs +1995 -0
  52. package/dist/cli/chunk-NTEZFZLE.mjs +890 -0
  53. package/dist/cli/chunk-NXDRDJ4K.js +389 -0
  54. package/dist/cli/chunk-NXGCO4JB.mjs +344 -0
  55. package/dist/cli/chunk-OG64RBAC.js +6 -0
  56. package/dist/cli/chunk-OWJZUE3Y.mjs +103 -0
  57. package/dist/cli/chunk-QSIO4TX2.mjs +190 -0
  58. package/dist/cli/chunk-RCUE5C5C.mjs +735 -0
  59. package/dist/cli/chunk-SDK3ZA2C.js +103 -0
  60. package/dist/cli/chunk-SFLARO4Y.mjs +47 -0
  61. package/dist/cli/chunk-TAC3JIFE.mjs +354 -0
  62. package/dist/cli/chunk-UC6GHEL4.js +499 -0
  63. package/dist/cli/chunk-UFS752TU.mjs +52 -0
  64. package/dist/cli/chunk-UNEMDKXN.js +1 -0
  65. package/dist/cli/chunk-WB6Z2Q44.mjs +1622 -0
  66. package/dist/cli/chunk-WJYPBHTE.js +148 -0
  67. package/dist/cli/chunk-WOHBA5PV.js +354 -0
  68. package/dist/cli/chunk-WZYKRD7T.mjs +6 -0
  69. package/dist/cli/chunk-XNYIZMNQ.js +28 -0
  70. package/dist/cli/chunk-ZDO3TO3M.js +1622 -0
  71. package/dist/cli/chunk-ZDOC4HFL.js +923 -0
  72. package/dist/cli/client-CZDA4JKO.mjs +20 -0
  73. package/dist/cli/client-IZGIN2ZA.js +20 -0
  74. package/dist/cli/csv-6KOMZA2H.mjs +585 -0
  75. package/dist/cli/csv-UTEQY3NA.js +585 -0
  76. package/dist/cli/db-D5EP6TKO.mjs +486 -0
  77. package/dist/cli/db-SIBLPIKC.js +486 -0
  78. package/dist/cli/executions-2PHT57IO.js +28 -0
  79. package/dist/cli/executions-DFWM2YYY.mjs +28 -0
  80. package/dist/cli/feedback-GZW37JMI.mjs +107 -0
  81. package/dist/cli/feedback-IQVWIJZ4.js +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-563GYLMA.js +23 -0
  85. package/dist/cli/git-B72Y4FFQ.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-37F5MX2P.mjs +157 -0
  89. package/dist/cli/legacy-noops-IFGVDCOM.js +157 -0
  90. package/dist/cli/monitors-42H6LOVT.mjs +3251 -0
  91. package/dist/cli/monitors-GQCHXBXZ.js +3251 -0
  92. package/dist/cli/org-4GCPBTGR.js +849 -0
  93. package/dist/cli/org-JYZA3ZRJ.mjs +849 -0
  94. package/dist/cli/play-46ZJ4FMI.js +18439 -0
  95. package/dist/cli/play-Q2XV3FZZ.mjs +18439 -0
  96. package/dist/cli/providers-CTKQP45X.mjs +95 -0
  97. package/dist/cli/providers-PCNF5E3K.js +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-FTHWRVWN.js +69 -0
  101. package/dist/cli/quickstart-X7EVVWRG.mjs +69 -0
  102. package/dist/cli/search-73YPOFDO.mjs +18 -0
  103. package/dist/cli/search-XA5UVC3G.js +18 -0
  104. package/dist/cli/secrets-OUMPT4FX.mjs +400 -0
  105. package/dist/cli/secrets-UOEVR73Q.js +400 -0
  106. package/dist/cli/sessions-CMKXCN5Y.js +15 -0
  107. package/dist/cli/sessions-ZIFGDZE7.mjs +15 -0
  108. package/dist/cli/settings-OO5R3G52.mjs +846 -0
  109. package/dist/cli/settings-ULZT2NIC.js +846 -0
  110. package/dist/cli/setup-6GZH52OZ.mjs +1257 -0
  111. package/dist/cli/setup-DHGERXPZ.js +1257 -0
  112. package/dist/cli/skills-Q7NUCS2W.js +28 -0
  113. package/dist/cli/skills-T3EY2656.mjs +28 -0
  114. package/dist/cli/tools-BIMOAOTX.mjs +2955 -0
  115. package/dist/cli/tools-ODXVCKO7.js +2955 -0
  116. package/dist/cli/update-UMB3ULBR.js +28 -0
  117. package/dist/cli/update-X4HX7Z3M.mjs +28 -0
  118. package/dist/cli/workflow-EAUFVPIP.mjs +1936 -0
  119. package/dist/cli/workflow-IVLCPFTG.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,1257 @@
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
+
5
+
6
+
7
+
8
+
9
+ var _chunkZDOC4HFLjs = require('./chunk-ZDOC4HFL.js');
10
+
11
+
12
+
13
+ var _chunkL4HBNHFWjs = require('./chunk-L4HBNHFW.js');
14
+
15
+
16
+
17
+
18
+ var _chunk4Y6CG4GEjs = require('./chunk-4Y6CG4GE.js');
19
+ require('./chunk-WJYPBHTE.js');
20
+
21
+
22
+
23
+ var _chunk7D6QG5KFjs = require('./chunk-7D6QG5KF.js');
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ var _chunk6HPEDBSJjs = require('./chunk-6HPEDBSJ.js');
34
+ require('./chunk-XNYIZMNQ.js');
35
+ require('./chunk-LIKFCE7Z.js');
36
+
37
+
38
+
39
+
40
+ var _chunkJNNOCMQYjs = require('./chunk-JNNOCMQY.js');
41
+ require('./chunk-7P5AA3SN.js');
42
+ require('./chunk-OG64RBAC.js');
43
+ require('./chunk-COGTRVWW.js');
44
+
45
+ // src/cli/commands/setup.ts
46
+ var _child_process = require('child_process');
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ var _fs = require('fs');
55
+ var _os = require('os');
56
+ var _path = require('path');
57
+
58
+ // src/cli/installation-lifecycle.ts
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+ var nodeFileSystem = {
68
+ exists: _fs.existsSync,
69
+ isSymbolicLink(path) {
70
+ try {
71
+ return _fs.lstatSync.call(void 0, path).isSymbolicLink();
72
+ } catch (e) {
73
+ return false;
74
+ }
75
+ },
76
+ read(path) {
77
+ try {
78
+ return _fs.readFileSync.call(void 0, path, "utf8");
79
+ } catch (e2) {
80
+ return "";
81
+ }
82
+ },
83
+ realpath(path) {
84
+ try {
85
+ return _fs.realpathSync.call(void 0, path);
86
+ } catch (e3) {
87
+ return null;
88
+ }
89
+ },
90
+ remove(path) {
91
+ _fs.rmSync.call(void 0, path, { force: true });
92
+ }
93
+ };
94
+ function inspectLauncher(path, fileSystem = nodeFileSystem) {
95
+ if (!fileSystem.exists(path)) {
96
+ return { ownership: "missing", resolvedPath: null };
97
+ }
98
+ const resolvedPath = fileSystem.realpath(path);
99
+ if (CliInstallation.isNpmPackagePath(resolvedPath)) {
100
+ return { ownership: "npm", resolvedPath };
101
+ }
102
+ if (fileSystem.isSymbolicLink(path)) {
103
+ return { ownership: "symlink", resolvedPath };
104
+ }
105
+ const content = fileSystem.read(path);
106
+ if (content.includes("DEEPLINE_REAL_BINARY") && content.includes("DEEPLINE_ACTIVE_FILE")) {
107
+ return { ownership: "installer_legacy", resolvedPath };
108
+ }
109
+ return { ownership: "user", resolvedPath };
110
+ }
111
+ var CliInstallation = class _CliInstallation {
112
+ constructor(input) {
113
+ this.input = input;
114
+ }
115
+ static forUser(input) {
116
+ return new _CliInstallation({
117
+ ...input,
118
+ fileSystem: _nullishCoalesce(input.fileSystem, () => ( nodeFileSystem))
119
+ });
120
+ }
121
+ static isNpmPackagePath(path) {
122
+ return _nullishCoalesce(_optionalChain([path, 'optionalAccess', _ => _.includes, 'call', _2 => _2(`${_path.join.call(void 0, "node_modules", "deepline")}`)]), () => ( false));
123
+ }
124
+ launcher(path) {
125
+ return inspectLauncher(path, this.input.fileSystem);
126
+ }
127
+ retiredArtifacts() {
128
+ const hostDir = _path.join.call(void 0,
129
+ this.input.home,
130
+ ".local",
131
+ "deepline",
132
+ this.input.baseUrlSlug
133
+ );
134
+ const legacyLauncherPath = _path.join.call(void 0,
135
+ this.input.home,
136
+ ".local",
137
+ "bin",
138
+ "deepline"
139
+ );
140
+ const installerCommandPath = this.input.fileSystem.read(_path.join.call(void 0, hostDir, "sdk", ".command-path")).trim();
141
+ const ownedInstallerCommand = isOwnedInstallerCommandPath({
142
+ hostDir,
143
+ commandPath: installerCommandPath
144
+ });
145
+ const legacyLauncher = this.launcher(legacyLauncherPath);
146
+ const candidates = [
147
+ ...legacyLauncher.ownership === "installer_legacy" ? [legacyLauncherPath] : [],
148
+ _path.join.call(void 0, this.input.home, ".local", "bin", "deepline-real"),
149
+ _path.join.call(void 0, hostDir, "bin", "deepline"),
150
+ _path.join.call(void 0, hostDir, "bin", "deepline-real"),
151
+ _path.join.call(void 0, hostDir, "cli", ".install-method"),
152
+ _path.join.call(void 0, hostDir, "cli", ".version"),
153
+ _path.join.call(void 0, hostDir, "sdk", ".install-method"),
154
+ _path.join.call(void 0, hostDir, "sdk", ".command-path"),
155
+ ...ownedInstallerCommand ? [
156
+ installerCommandPath,
157
+ _path.join.call(void 0, _path.dirname.call(void 0, installerCommandPath), "deepline-sdk")
158
+ ] : []
159
+ ];
160
+ return {
161
+ paths: candidates.filter((path) => {
162
+ if (!this.input.fileSystem.exists(path)) return false;
163
+ return this.launcher(path).ownership !== "npm";
164
+ })
165
+ };
166
+ }
167
+ removeRetiredArtifacts() {
168
+ return removeArtifacts(this.retiredArtifacts(), this.input.fileSystem);
169
+ }
170
+ };
171
+ function isNpmCliPath(path) {
172
+ return CliInstallation.isNpmPackagePath(path);
173
+ }
174
+ function removeArtifacts(plan, fileSystem) {
175
+ for (const path of plan.paths) {
176
+ fileSystem.remove(path);
177
+ }
178
+ return plan.paths;
179
+ }
180
+ function isOwnedInstallerCommandPath(input) {
181
+ if (!input.commandPath || _path.basename.call(void 0, input.commandPath) !== "deepline") {
182
+ return false;
183
+ }
184
+ const commandPath = _path.resolve.call(void 0, input.commandPath);
185
+ const fromHost = _path.relative.call(void 0, _path.resolve.call(void 0, input.hostDir), commandPath);
186
+ return fromHost !== "" && fromHost !== ".." && !fromHost.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`);
187
+ }
188
+
189
+ // src/cli/commands/setup.ts
190
+ var SETUP_PHASE_NAMES = [
191
+ "cli",
192
+ "cleanup",
193
+ "skills",
194
+ "auth",
195
+ "verify"
196
+ ];
197
+ function initialSetupPhases() {
198
+ return {
199
+ cli: { status: "pending" },
200
+ cleanup: { status: "pending" },
201
+ skills: { status: "pending" },
202
+ auth: { status: "pending" },
203
+ verify: { status: "pending" }
204
+ };
205
+ }
206
+ function isSetupPhaseStatus(value) {
207
+ return value === "pending" || value === "in_progress" || value === "complete" || value === "waiting" || value === "failed";
208
+ }
209
+ function parseSetupPhases(value) {
210
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
211
+ const source = value;
212
+ const phases = initialSetupPhases();
213
+ for (const name of SETUP_PHASE_NAMES) {
214
+ const phase = source[name];
215
+ if (!phase || typeof phase !== "object" || Array.isArray(phase)) {
216
+ return null;
217
+ }
218
+ const record = phase;
219
+ if (!isSetupPhaseStatus(record.status)) return null;
220
+ switch (record.status) {
221
+ case "pending":
222
+ case "in_progress":
223
+ phases[name] = { status: record.status };
224
+ break;
225
+ case "complete":
226
+ phases[name] = {
227
+ status: "complete",
228
+ ...typeof record.outcome === "string" ? { outcome: record.outcome } : {}
229
+ };
230
+ break;
231
+ case "waiting":
232
+ if (typeof record.outcome !== "string") return null;
233
+ phases[name] = { status: "waiting", outcome: record.outcome };
234
+ break;
235
+ case "failed":
236
+ if (typeof record.code !== "string") return null;
237
+ phases[name] = { status: "failed", code: record.code };
238
+ break;
239
+ }
240
+ }
241
+ return phases;
242
+ }
243
+ function phasesFromLegacyStatus(status) {
244
+ const phases = initialSetupPhases();
245
+ if (status === "skills_installed" || status === "authorization_pending" || status === "complete") {
246
+ phases.cli = { status: "complete" };
247
+ phases.cleanup = { status: "complete" };
248
+ phases.skills = { status: "complete" };
249
+ }
250
+ if (status === "authorization_pending") {
251
+ phases.auth = { status: "waiting", outcome: "authorization_pending" };
252
+ } else if (status === "complete") {
253
+ phases.auth = { status: "complete" };
254
+ phases.verify = { status: "complete" };
255
+ }
256
+ return phases;
257
+ }
258
+ function readSetupState(input) {
259
+ try {
260
+ const parsed = JSON.parse(
261
+ _fs.readFileSync.call(void 0,
262
+ setupStatePath(input.baseUrl, input.scope, input.root),
263
+ "utf8"
264
+ )
265
+ );
266
+ if (parsed.host !== input.baseUrl || parsed.scope !== input.scope || parsed.root !== input.root || typeof parsed.status !== "string") {
267
+ return null;
268
+ }
269
+ return {
270
+ status: parsed.status,
271
+ phases: _nullishCoalesce(parseSetupPhases(parsed.phases), () => ( phasesFromLegacyStatus(parsed.status)))
272
+ };
273
+ } catch (e4) {
274
+ return null;
275
+ }
276
+ }
277
+ function selectSetupProgress(previousState) {
278
+ const resumed = Boolean(previousState && previousState.status !== "complete");
279
+ return {
280
+ resumed,
281
+ phases: resumed ? previousState.phases : initialSetupPhases()
282
+ };
283
+ }
284
+ function normalizeScope(value) {
285
+ if (!value || value === "global") return "global";
286
+ if (value === "local") return "local";
287
+ throw new Error("--scope must be one of: global, local");
288
+ }
289
+ function resolveScopeRoot(scope) {
290
+ if (scope === "global") return null;
291
+ const target = _chunk6HPEDBSJjs.resolveProjectPinTarget.call(void 0, );
292
+ if (!target.ok) {
293
+ throw new Error(
294
+ `Cowork project folder is ambiguous. Candidate folders: ${target.candidates.join(
295
+ ", "
296
+ )}. Set CLAUDE_PROJECT_DIR or cd into the intended project folder.`
297
+ );
298
+ }
299
+ return target.dir;
300
+ }
301
+ function authScopeForSetup(scope) {
302
+ return scope === "local" ? "folder" : "global";
303
+ }
304
+ function openSetupAuthorization(authorizationUrl, options = {}) {
305
+ const url = authorizationUrl.trim();
306
+ if (!url) return "failed";
307
+ if (options.open) return options.open(url);
308
+ const result = _chunk7D6QG5KFjs.openInBrowser.call(void 0, url, { deduplicate: false });
309
+ return result === "opened" ? "opened" : "failed";
310
+ }
311
+ function buildPendingAuthorizationOutput(input) {
312
+ const authorizationUrl = input.authorizationUrl.trim();
313
+ if (input.browserOpenStatus === "existing_claim" && authorizationUrl) {
314
+ return {
315
+ authorizationUrl,
316
+ next: `The existing approval is still pending. Use its authorization URL if needed, then run: ${input.resumeCommand}`,
317
+ lines: [
318
+ "Deepline did not open another browser tab. Use the existing approval page or this link:",
319
+ authorizationUrl
320
+ ]
321
+ };
322
+ }
323
+ if (input.browserOpenStatus === "timed_out" && authorizationUrl) {
324
+ return {
325
+ authorizationUrl,
326
+ next: `Approval is still pending after five minutes. Use the authorization URL if needed, then run: ${input.resumeCommand}`,
327
+ lines: [
328
+ "Approval is still pending. Use this link if the tab was missed:",
329
+ authorizationUrl
330
+ ]
331
+ };
332
+ }
333
+ if (authorizationUrl) {
334
+ return {
335
+ authorizationUrl,
336
+ next: `Open the authorization URL, approve it, then run: ${input.resumeCommand}`,
337
+ lines: [
338
+ "Browser launch failed. Open the authorization URL to continue.",
339
+ authorizationUrl
340
+ ]
341
+ };
342
+ }
343
+ return {
344
+ authorizationUrl: null,
345
+ next: `Authorization is pending without a browser URL. Retry: ${input.resumeCommand}`,
346
+ lines: ["Authorization is pending, but no browser URL was returned."]
347
+ };
348
+ }
349
+ function setupStatePath(baseUrl, scope, root) {
350
+ return scope === "local" && root ? _path.join.call(void 0, root, ".deepline", "setup", "state.json") : _path.join.call(void 0, _chunk6HPEDBSJjs.sdkCliStateDirPath.call(void 0, baseUrl), "setup.json");
351
+ }
352
+ async function captureStdout(run) {
353
+ let stdout = "";
354
+ const originalWrite = process.stdout.write.bind(process.stdout);
355
+ process.stdout.write = ((chunk) => {
356
+ stdout += typeof chunk === "string" ? chunk : String(chunk);
357
+ return true;
358
+ });
359
+ try {
360
+ return { exitCode: await run(), stdout, error: null };
361
+ } catch (error) {
362
+ return { exitCode: 4, stdout, error };
363
+ } finally {
364
+ process.stdout.write = originalWrite;
365
+ }
366
+ }
367
+ function parseCapturedJson(stdout) {
368
+ try {
369
+ return JSON.parse(stdout.trim());
370
+ } catch (e5) {
371
+ return null;
372
+ }
373
+ }
374
+ function asRecord(value) {
375
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
376
+ }
377
+ function safeRead(path) {
378
+ try {
379
+ return _fs.readFileSync.call(void 0, path, "utf8");
380
+ } catch (e6) {
381
+ return "";
382
+ }
383
+ }
384
+ function isNpmManagedDeeplinePath(path) {
385
+ try {
386
+ return isNpmCliPath(_fs.realpathSync.call(void 0, path));
387
+ } catch (e7) {
388
+ return false;
389
+ }
390
+ }
391
+ function removeKnownLegacyPaths(baseUrl) {
392
+ return CliInstallation.forUser({
393
+ baseUrlSlug: _chunk6HPEDBSJjs.baseUrlSlug.call(void 0, baseUrl),
394
+ home: _os.homedir.call(void 0, )
395
+ }).removeRetiredArtifacts();
396
+ }
397
+ function resolvePathCommands(command) {
398
+ const lookup = _child_process.spawnSync.call(void 0,
399
+ process.platform === "win32" ? "where" : "which",
400
+ process.platform === "win32" ? [command] : ["-a", command],
401
+ { encoding: "utf8", shell: process.platform === "win32" }
402
+ );
403
+ return [
404
+ ...new Set(
405
+ String(_nullishCoalesce(lookup.stdout, () => ( ""))).split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((path) => _path.resolve.call(void 0, path))
406
+ )
407
+ ];
408
+ }
409
+ function resolvePathCommand(command) {
410
+ return _nullishCoalesce(resolvePathCommands(command)[0], () => ( null));
411
+ }
412
+ function isHomebrewFormulaCommand(path) {
413
+ let resolvedPath = path;
414
+ try {
415
+ resolvedPath = _fs.realpathSync.call(void 0, path);
416
+ } catch (e8) {
417
+ return false;
418
+ }
419
+ const parts = resolvedPath.split(/[\\/]+/);
420
+ const cellarIndex = parts.lastIndexOf("Cellar");
421
+ return cellarIndex >= 0 && parts[cellarIndex + 1] === "deepline" && parts.slice(cellarIndex + 3).includes("libexec");
422
+ }
423
+ function resolvePersistentGlobalCommand(dependencies = {}) {
424
+ const platform = _nullishCoalesce(dependencies.platform, () => ( process.platform));
425
+ const run = _nullishCoalesce(dependencies.spawn, () => ( _child_process.spawnSync));
426
+ const pathExists = _nullishCoalesce(dependencies.exists, () => ( _fs.existsSync));
427
+ const pathClis = _nullishCoalesce(dependencies.pathClis, () => ( resolvePathCommands("deepline")));
428
+ const homebrewCommand = pathClis.find(isHomebrewFormulaCommand);
429
+ if (homebrewCommand) return homebrewCommand;
430
+ for (const manager of ["npm", "pnpm"]) {
431
+ const plan = _chunk4Y6CG4GEjs.resolveShellSpawn.call(void 0,
432
+ manager,
433
+ manager === "npm" ? ["prefix", "-g"] : ["bin", "-g"],
434
+ platform
435
+ );
436
+ const result = run(plan.command, plan.args, {
437
+ encoding: "utf8",
438
+ shell: plan.shell,
439
+ cwd: manager === "pnpm" ? _os.homedir.call(void 0, ) : void 0,
440
+ timeout: 1e4
441
+ });
442
+ if (result.status !== 0) continue;
443
+ const root = String(_nullishCoalesce(result.stdout, () => ( ""))).trim();
444
+ if (!root) continue;
445
+ const bin = manager === "npm" && platform !== "win32" ? _path.join.call(void 0, root, "bin") : root;
446
+ const candidates = platform === "win32" ? [_path.join.call(void 0, bin, "deepline.cmd"), _path.join.call(void 0, bin, "deepline")] : [_path.join.call(void 0, bin, "deepline")];
447
+ const command = candidates.find((candidate) => pathExists(candidate));
448
+ if (command) return command;
449
+ }
450
+ return null;
451
+ }
452
+ function inspectGlobalCliAvailability(input) {
453
+ const pathClis = _nullishCoalesce(_optionalChain([input, 'optionalAccess', _3 => _3.pathClis]), () => ( resolvePathCommands("deepline")));
454
+ const persistentPath = input && "persistentGlobalCli" in input ? _nullishCoalesce(input.persistentGlobalCli, () => ( null)) : resolvePersistentGlobalCommand({ pathClis });
455
+ const path = persistentPath ? _nullishCoalesce(pathClis.find(
456
+ (candidate) => pathsResolveToSameFile(candidate, persistentPath)
457
+ ), () => ( null)) : null;
458
+ return { ok: Boolean(path), persistentPath, path };
459
+ }
460
+ function pathsResolveToSameFile(left, right) {
461
+ try {
462
+ return _fs.realpathSync.call(void 0, left) === _fs.realpathSync.call(void 0, right);
463
+ } catch (e9) {
464
+ return _path.resolve.call(void 0, left) === _path.resolve.call(void 0, right);
465
+ }
466
+ }
467
+ function isKnownDeeplineCommand(path) {
468
+ const entrypoint = process.argv[1] ? _path.resolve.call(void 0, process.argv[1]) : "";
469
+ let resolvedPath = path;
470
+ try {
471
+ resolvedPath = _fs.realpathSync.call(void 0, path);
472
+ } catch (e10) {
473
+ }
474
+ if (entrypoint && resolvedPath === entrypoint) return true;
475
+ if (resolvedPath.includes(`${_path.join.call(void 0, "node_modules", "deepline")}`)) return true;
476
+ const content = safeRead(path);
477
+ return content.includes("node_modules/deepline") || content.includes("node_modules\\deepline") || content.includes("DEEPLINE_CONFIG_SCOPE") || content.includes("deepline-real");
478
+ }
479
+ function inspectPathConflict() {
480
+ const commandPath = resolvePathCommand("deepline");
481
+ if (!commandPath || isKnownDeeplineCommand(commandPath)) return null;
482
+ try {
483
+ if (_fs.lstatSync.call(void 0, commandPath).isSymbolicLink()) {
484
+ const target = _fs.realpathSync.call(void 0, commandPath);
485
+ if (target.includes(`${_path.join.call(void 0, "node_modules", "deepline")}`)) return null;
486
+ }
487
+ } catch (e11) {
488
+ }
489
+ return commandPath;
490
+ }
491
+ function writeSetupState(input) {
492
+ const path = setupStatePath(input.baseUrl, input.scope, input.root);
493
+ _fs.mkdirSync.call(void 0, _path.dirname.call(void 0, path), { recursive: true });
494
+ _fs.writeFileSync.call(void 0,
495
+ path,
496
+ `${JSON.stringify(
497
+ {
498
+ schemaVersion: 2,
499
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
500
+ cliVersion: _chunk6HPEDBSJjs.SDK_VERSION,
501
+ host: input.baseUrl,
502
+ scope: input.scope,
503
+ root: input.root,
504
+ status: input.status,
505
+ phases: input.phases
506
+ },
507
+ null,
508
+ 2
509
+ )}
510
+ `,
511
+ "utf8"
512
+ );
513
+ return path;
514
+ }
515
+ function persistSetupProgress(input) {
516
+ return writeSetupState({
517
+ ...input,
518
+ status: _nullishCoalesce(input.status, () => ( "in_progress"))
519
+ });
520
+ }
521
+ function completeSetupPhase(phases, phase, outcome) {
522
+ phases[phase] = {
523
+ status: "complete",
524
+ ...outcome ? { outcome } : {}
525
+ };
526
+ }
527
+ function beginSetupPhase(phases, phase) {
528
+ phases[phase] = { status: "in_progress" };
529
+ }
530
+ function failSetupPhase(phases, phase, code) {
531
+ phases[phase] = { status: "failed", code };
532
+ }
533
+ function rollbackCommand(scope, root) {
534
+ const prefix = scope === "local" && root ? ` --prefix ${JSON.stringify(_path.join.call(void 0, root, ".deepline", "runtime"))}` : "";
535
+ const allowScriptsFlag = _chunkL4HBNHFWjs.npmSupportsAllowScripts.call(void 0, _chunkL4HBNHFWjs.readNpmVersion.call(void 0, process.env)) ? " --allow-scripts=esbuild" : "";
536
+ return `npm install -g${prefix} --no-audit --no-fund --include=optional${allowScriptsFlag} deepline@${_chunk6HPEDBSJjs.SDK_VERSION}`;
537
+ }
538
+ function setupResumeCommand(baseUrl, scope, orgName) {
539
+ const hostPrefix = baseUrl === "https://code.deepline.com" ? "" : `DEEPLINE_HOST_URL=${JSON.stringify(baseUrl)} `;
540
+ const quotedOrgName = orgName ? process.platform === "win32" ? ` --org-name "${orgName.replace(/"/g, '""')}"` : ` --org-name '${orgName.replace(/'/g, `'\\''`)}'` : "";
541
+ return `${hostPrefix}deepline setup --scope ${scope}${quotedOrgName} --json`;
542
+ }
543
+ function setupRetry(input) {
544
+ return {
545
+ phase: input.phase,
546
+ command: setupResumeCommand(input.baseUrl, input.scope, input.orgName),
547
+ automatic: _nullishCoalesce(input.retryAutomatic, () => ( true))
548
+ };
549
+ }
550
+ function reportSetupPhaseFailure(input) {
551
+ failSetupPhase(input.phases, input.phase, input.code);
552
+ const statePath = persistSetupProgress({
553
+ baseUrl: input.baseUrl,
554
+ scope: input.scope,
555
+ root: input.root,
556
+ phases: input.phases,
557
+ status: "failed"
558
+ });
559
+ const retry = setupRetry(input);
560
+ _chunk7D6QG5KFjs.printCommandEnvelope.call(void 0,
561
+ {
562
+ ok: false,
563
+ status: "failed",
564
+ code: input.code,
565
+ exitCode: input.exitCode,
566
+ scope: input.scope,
567
+ message: input.message,
568
+ phases: input.phases,
569
+ failedPhase: input.phase,
570
+ retry,
571
+ statePath,
572
+ next: _nullishCoalesce(input.next, () => ( retry.command)),
573
+ ..._nullishCoalesce(input.extra, () => ( {}))
574
+ },
575
+ { json: input.json }
576
+ );
577
+ return input.exitCode;
578
+ }
579
+ async function readAuthStatus(authScope) {
580
+ try {
581
+ const captured = await captureStdout(
582
+ () => _chunkZDOC4HFLjs.handleStatus.call(void 0, [
583
+ "--json",
584
+ ...authScope ? ["--auth-scope", authScope] : []
585
+ ])
586
+ );
587
+ return {
588
+ exitCode: captured.exitCode,
589
+ payload: parseCapturedJson(captured.stdout),
590
+ error: captured.error
591
+ };
592
+ } catch (error) {
593
+ return { exitCode: 4, payload: null, error };
594
+ }
595
+ }
596
+ function reportSetupAuthStatusFailure(input) {
597
+ if (!input.auth.error) return null;
598
+ return reportSetupPhaseFailure({
599
+ baseUrl: input.baseUrl,
600
+ scope: input.scope,
601
+ root: input.root,
602
+ phases: input.phases,
603
+ orgName: input.orgName,
604
+ phase: "auth",
605
+ code: "AUTH_STATUS_FAILED",
606
+ exitCode: 4,
607
+ message: "Deepline could not verify authorization with the configured host.",
608
+ json: input.json,
609
+ extra: { authScope: input.authScope }
610
+ });
611
+ }
612
+ function buildDoctorAssessment(input) {
613
+ const skillsStatePath = _chunk4Y6CG4GEjs.skillsStatePathForScope.call(void 0,
614
+ input.baseUrl,
615
+ input.scope,
616
+ input.root
617
+ );
618
+ const skillsState = parseCapturedJson(safeRead(skillsStatePath));
619
+ const apiKey = input.scope === "local" ? _chunk6HPEDBSJjs.resolveProjectApiKeyForBaseUrl.call(void 0, input.baseUrl) : _chunk6HPEDBSJjs.resolveGlobalApiKeyForBaseUrl.call(void 0, input.baseUrl);
620
+ const projectAuth = input.scope === "local" && apiKey ? _chunk6HPEDBSJjs.getResolvedProjectAuthSource.call(void 0, input.baseUrl, apiKey) : null;
621
+ const connected = _optionalChain([input, 'access', _4 => _4.authStatus, 'access', _5 => _5.payload, 'optionalAccess', _6 => _6.connected]) === true;
622
+ const authScopeOk = input.scope === "local" ? Boolean(projectAuth) : Boolean(apiKey && !projectAuth);
623
+ const skillsOk = _optionalChain([skillsState, 'optionalAccess', _7 => _7.scope]) === input.scope && typeof skillsState.skillsVersion === "string" && Array.isArray(skillsState.agents) && skillsState.agents.length > 0;
624
+ const runningCliPath = process.argv[1] ? _path.resolve.call(void 0, process.argv[1]) : null;
625
+ const globalCli = input.scope === "global" ? inspectGlobalCliAvailability() : null;
626
+ const pathGlobalCli = _nullishCoalesce(_optionalChain([globalCli, 'optionalAccess', _8 => _8.path]), () => ( null));
627
+ const cliPath = input.scope === "global" ? pathGlobalCli : runningCliPath;
628
+ const cliScopeOk = input.scope === "global" ? Boolean(pathGlobalCli) : Boolean(
629
+ input.root && _optionalChain([runningCliPath, 'optionalAccess', _9 => _9.includes, 'call', _10 => _10(_path.join.call(void 0, input.root, ".deepline", "runtime"))])
630
+ );
631
+ const checks = {
632
+ cli: {
633
+ ok: Boolean(cliPath) && cliScopeOk,
634
+ version: _chunk6HPEDBSJjs.SDK_VERSION,
635
+ path: cliPath,
636
+ scope: input.scope
637
+ },
638
+ skills: {
639
+ ok: skillsOk,
640
+ statePath: skillsStatePath,
641
+ version: _nullishCoalesce(_optionalChain([skillsState, 'optionalAccess', _11 => _11.skillsVersion]), () => ( null)),
642
+ agents: _nullishCoalesce(_optionalChain([skillsState, 'optionalAccess', _12 => _12.agents]), () => ( []))
643
+ },
644
+ auth: {
645
+ ok: connected && authScopeOk,
646
+ scope: projectAuth ? "local" : apiKey ? "global" : null,
647
+ status: _nullishCoalesce(_optionalChain([input, 'access', _13 => _13.authStatus, 'access', _14 => _14.payload, 'optionalAccess', _15 => _15.status]), () => ( "not_connected"))
648
+ },
649
+ api: {
650
+ ok: connected && input.authStatus.exitCode === 0,
651
+ host: input.baseUrl,
652
+ workspace: _nullishCoalesce(_optionalChain([input, 'access', _16 => _16.authStatus, 'access', _17 => _17.payload, 'optionalAccess', _18 => _18.workspace]), () => ( null)),
653
+ providerSpend: false
654
+ }
655
+ };
656
+ return {
657
+ ok: Object.values(checks).every((check) => check.ok),
658
+ checks
659
+ };
660
+ }
661
+ async function runDoctorCommand(options) {
662
+ let scope;
663
+ let root;
664
+ try {
665
+ scope = normalizeScope(options.scope);
666
+ root = resolveScopeRoot(scope);
667
+ } catch (error) {
668
+ _chunk7D6QG5KFjs.printCommandEnvelope.call(void 0,
669
+ {
670
+ ok: false,
671
+ status: "failed",
672
+ code: "INVALID_SETUP_SCOPE",
673
+ exitCode: 2,
674
+ message: error instanceof Error ? error.message : String(error)
675
+ },
676
+ { json: options.json }
677
+ );
678
+ return 2;
679
+ }
680
+ const baseUrl = _chunk6HPEDBSJjs.autoDetectBaseUrl.call(void 0, ).replace(/\/$/, "");
681
+ const authScope = authScopeForSetup(scope);
682
+ const authStatus = await readAuthStatus(authScope);
683
+ const { ok, checks } = buildDoctorAssessment({
684
+ baseUrl,
685
+ scope,
686
+ root,
687
+ authStatus
688
+ });
689
+ const gettingStarted = _chunkJNNOCMQYjs.deeplineGtmGettingStartedPayload.call(void 0, );
690
+ _chunk7D6QG5KFjs.printCommandEnvelope.call(void 0,
691
+ {
692
+ ok,
693
+ status: ok ? "complete" : "failed",
694
+ code: ok ? "DOCTOR_OK" : "DOCTOR_FAILED",
695
+ exitCode: ok ? 0 : 7,
696
+ checks,
697
+ next: ok ? _chunkJNNOCMQYjs.DEEPLINE_GTM_SKILL : "Review failed checks, then rerun: deepline doctor --json",
698
+ ...ok ? { gettingStarted } : {},
699
+ render: {
700
+ sections: [
701
+ {
702
+ title: "doctor",
703
+ lines: Object.entries(checks).map(
704
+ ([name, check]) => `${check.ok ? "pass" : "fail"} ${name}`
705
+ )
706
+ }
707
+ ]
708
+ }
709
+ },
710
+ { json: options.json }
711
+ );
712
+ return ok ? 0 : 7;
713
+ }
714
+ function pendingResult(input) {
715
+ input.phases.auth = {
716
+ status: "waiting",
717
+ outcome: "authorization_pending"
718
+ };
719
+ const statePath = writeSetupState({
720
+ baseUrl: input.baseUrl,
721
+ scope: input.scope,
722
+ root: input.root,
723
+ status: "authorization_pending",
724
+ phases: input.phases
725
+ });
726
+ const pendingOutput = buildPendingAuthorizationOutput({
727
+ authorizationUrl: input.authorizationUrl,
728
+ browserOpenStatus: input.browserOpenStatus,
729
+ resumeCommand: setupResumeCommand(
730
+ input.baseUrl,
731
+ input.scope,
732
+ input.orgName
733
+ )
734
+ });
735
+ _chunk7D6QG5KFjs.printCommandEnvelope.call(void 0,
736
+ {
737
+ ok: true,
738
+ status: "authorization_pending",
739
+ complete: false,
740
+ scope: input.scope,
741
+ authorizationUrl: pendingOutput.authorizationUrl,
742
+ browserOpened: input.browserOpenStatus === "timed_out",
743
+ browserOpenStatus: input.browserOpenStatus,
744
+ authClaimSource: input.authClaimSource,
745
+ statePath,
746
+ phases: input.phases,
747
+ currentPhase: "auth",
748
+ resumed: input.resumed,
749
+ retry: setupRetry({
750
+ baseUrl: input.baseUrl,
751
+ scope: input.scope,
752
+ phase: "auth",
753
+ orgName: input.orgName
754
+ }),
755
+ next: pendingOutput.next,
756
+ render: {
757
+ sections: [
758
+ {
759
+ title: "setup",
760
+ lines: pendingOutput.lines
761
+ }
762
+ ]
763
+ }
764
+ },
765
+ { json: input.json }
766
+ );
767
+ return 0;
768
+ }
769
+ async function runSetupCommand(options) {
770
+ let orgName = _optionalChain([options, 'access', _19 => _19.orgName, 'optionalAccess', _20 => _20.trim, 'call', _21 => _21()]);
771
+ if (options.orgName !== void 0 && !orgName) {
772
+ _chunk7D6QG5KFjs.printCommandEnvelope.call(void 0,
773
+ {
774
+ ok: false,
775
+ status: "failed",
776
+ code: "INVALID_ORG_NAME",
777
+ exitCode: 2,
778
+ message: "Workspace name cannot be empty."
779
+ },
780
+ { json: options.json }
781
+ );
782
+ return 2;
783
+ }
784
+ let scope;
785
+ let root;
786
+ try {
787
+ scope = normalizeScope(options.scope);
788
+ root = resolveScopeRoot(scope);
789
+ } catch (error) {
790
+ _chunk7D6QG5KFjs.printCommandEnvelope.call(void 0,
791
+ {
792
+ ok: false,
793
+ status: "failed",
794
+ code: "INVALID_SETUP_SCOPE",
795
+ exitCode: 2,
796
+ message: error instanceof Error ? error.message : String(error),
797
+ phases: {
798
+ ...initialSetupPhases(),
799
+ cli: { status: "failed", code: "INVALID_SETUP_SCOPE" }
800
+ },
801
+ failedPhase: "cli"
802
+ },
803
+ { json: options.json }
804
+ );
805
+ return 2;
806
+ }
807
+ const baseUrl = _chunk6HPEDBSJjs.autoDetectBaseUrl.call(void 0, ).replace(/\/$/, "");
808
+ const previousState = readSetupState({ baseUrl, scope, root });
809
+ const { resumed, phases } = selectSetupProgress(previousState);
810
+ if (phases.cli.status !== "complete") {
811
+ beginSetupPhase(phases, "cli");
812
+ persistSetupProgress({ baseUrl, scope, root, phases });
813
+ if (scope === "global") {
814
+ const globalCli = inspectGlobalCliAvailability();
815
+ if (!globalCli.ok) {
816
+ const installedButUnreachable = Boolean(globalCli.persistentPath);
817
+ const code = installedButUnreachable ? "GLOBAL_CLI_NOT_ON_PATH" : "GLOBAL_CLI_NOT_INSTALLED";
818
+ return reportSetupPhaseFailure({
819
+ baseUrl,
820
+ scope,
821
+ root,
822
+ phases,
823
+ phase: "cli",
824
+ code,
825
+ exitCode: 7,
826
+ message: installedButUnreachable ? `The global Deepline executable is not reachable on PATH: ${globalCli.persistentPath}` : "No persistent global Deepline executable was found.",
827
+ json: options.json,
828
+ orgName,
829
+ extra: {
830
+ persistentPath: globalCli.persistentPath,
831
+ fallback: "https://code.deepline.com/INSTALL.md"
832
+ }
833
+ });
834
+ }
835
+ }
836
+ const conflict = inspectPathConflict();
837
+ if (conflict) {
838
+ return reportSetupPhaseFailure({
839
+ baseUrl,
840
+ scope,
841
+ root,
842
+ phases,
843
+ phase: "cli",
844
+ code: "PATH_CONFLICT",
845
+ exitCode: 7,
846
+ message: `An unknown executable named deepline is first on PATH: ${conflict}`,
847
+ json: options.json,
848
+ orgName,
849
+ extra: { path: conflict }
850
+ });
851
+ }
852
+ completeSetupPhase(phases, "cli", "available");
853
+ persistSetupProgress({ baseUrl, scope, root, phases });
854
+ }
855
+ if (phases.cleanup.status !== "complete") {
856
+ beginSetupPhase(phases, "cleanup");
857
+ persistSetupProgress({ baseUrl, scope, root, phases });
858
+ try {
859
+ const removedLegacyPaths = removeKnownLegacyPaths(baseUrl);
860
+ if (removedLegacyPaths.length > 0) {
861
+ process.stderr.write(
862
+ `Removed ${removedLegacyPaths.length} known legacy Deepline path(s).
863
+ `
864
+ );
865
+ }
866
+ completeSetupPhase(
867
+ phases,
868
+ "cleanup",
869
+ removedLegacyPaths.length > 0 ? "removed_legacy_paths" : "clean"
870
+ );
871
+ persistSetupProgress({ baseUrl, scope, root, phases });
872
+ } catch (error) {
873
+ return reportSetupPhaseFailure({
874
+ baseUrl,
875
+ scope,
876
+ root,
877
+ phases,
878
+ phase: "cleanup",
879
+ code: "LEGACY_CLEANUP_FAILED",
880
+ exitCode: 5,
881
+ message: error instanceof Error ? error.message : String(error),
882
+ json: options.json,
883
+ orgName
884
+ });
885
+ }
886
+ }
887
+ let skillsPayload = null;
888
+ if (phases.skills.status !== "complete") {
889
+ beginSetupPhase(phases, "skills");
890
+ persistSetupProgress({ baseUrl, scope, root, phases });
891
+ process.stderr.write(`Installing Deepline skills (${scope})...
892
+ `);
893
+ const skills = await captureStdout(
894
+ () => _chunk4Y6CG4GEjs.runSkillsCommand.call(void 0, { scope, json: true })
895
+ );
896
+ skillsPayload = parseCapturedJson(skills.stdout);
897
+ if (skills.exitCode !== 0) {
898
+ if (scope === "global") {
899
+ phases.skills = { status: "failed", code: "SKILLS_INSTALL_FAILED" };
900
+ persistSetupProgress({ baseUrl, scope, root, phases });
901
+ process.stderr.write(
902
+ "Global skill setup failed. Trying project-local skills instead.\n"
903
+ );
904
+ return runSetupCommand({ scope: "local", json: options.json, orgName });
905
+ }
906
+ return reportSetupPhaseFailure({
907
+ baseUrl,
908
+ scope,
909
+ root,
910
+ phases,
911
+ phase: "skills",
912
+ code: "SKILLS_INSTALL_FAILED",
913
+ exitCode: skills.exitCode,
914
+ message: typeof _optionalChain([skillsPayload, 'optionalAccess', _22 => _22.message]) === "string" ? skillsPayload.message : "Deepline skills could not be installed.",
915
+ json: options.json,
916
+ orgName,
917
+ next: `! ${setupResumeCommand(baseUrl, scope, orgName)}`,
918
+ extra: { detail: skillsPayload }
919
+ });
920
+ }
921
+ completeSetupPhase(
922
+ phases,
923
+ "skills",
924
+ _optionalChain([skillsPayload, 'optionalAccess', _23 => _23.status]) === "current" ? "current" : "installed"
925
+ );
926
+ writeSetupState({
927
+ baseUrl,
928
+ scope,
929
+ root,
930
+ status: "skills_installed",
931
+ phases
932
+ });
933
+ } else {
934
+ skillsPayload = parseCapturedJson(
935
+ safeRead(_chunk4Y6CG4GEjs.skillsStatePathForScope.call(void 0, baseUrl, scope, root))
936
+ );
937
+ }
938
+ const authScope = authScopeForSetup(scope);
939
+ const pendingAtStart = _chunkZDOC4HFLjs.readPendingAuthClaim.call(void 0, baseUrl, authScope);
940
+ const replacingPendingClaim = Boolean(
941
+ pendingAtStart && orgName && _optionalChain([pendingAtStart, 'access', _24 => _24.orgName, 'optionalAccess', _25 => _25.toLowerCase, 'call', _26 => _26()]) !== orgName.toLowerCase()
942
+ );
943
+ if (pendingAtStart && !replacingPendingClaim) {
944
+ if (pendingAtStart.orgName) orgName = pendingAtStart.orgName;
945
+ }
946
+ beginSetupPhase(phases, "auth");
947
+ persistSetupProgress({ baseUrl, scope, root, phases });
948
+ let auth = await readAuthStatus(authScope);
949
+ const initialAuthFailure = reportSetupAuthStatusFailure({
950
+ auth,
951
+ baseUrl,
952
+ authScope,
953
+ scope,
954
+ root,
955
+ phases,
956
+ orgName,
957
+ json: options.json
958
+ });
959
+ if (initialAuthFailure !== null) return initialAuthFailure;
960
+ const connectedToRequestedWorkspace = () => {
961
+ if (_optionalChain([auth, 'access', _27 => _27.payload, 'optionalAccess', _28 => _28.connected]) !== true) return false;
962
+ if (!orgName) return true;
963
+ const workspace = asRecord(auth.payload.workspace);
964
+ return typeof _optionalChain([workspace, 'optionalAccess', _29 => _29.name]) === "string" && workspace.name.trim().toLowerCase() === orgName.toLowerCase();
965
+ };
966
+ let pending = replacingPendingClaim ? null : _chunkZDOC4HFLjs.readPendingAuthClaim.call(void 0, baseUrl, authScope);
967
+ if (replacingPendingClaim && connectedToRequestedWorkspace()) {
968
+ _chunkZDOC4HFLjs.clearPendingClaim.call(void 0, baseUrl, authScope);
969
+ }
970
+ let authClaimSource = "none";
971
+ if (pending || !connectedToRequestedWorkspace()) {
972
+ const reusedClaim = Boolean(pending);
973
+ authClaimSource = reusedClaim ? "existing" : "new";
974
+ if (!pending) {
975
+ process.stderr.write("Starting Deepline browser authorization...\n");
976
+ const registered = await captureStdout(
977
+ () => _chunkZDOC4HFLjs.handleRegister.call(void 0, [
978
+ "--wait",
979
+ "no",
980
+ "--auth-scope",
981
+ authScope,
982
+ ...orgName ? ["--org-name", orgName] : []
983
+ ])
984
+ );
985
+ if (registered.exitCode !== 0) {
986
+ return reportSetupPhaseFailure({
987
+ baseUrl,
988
+ scope,
989
+ root,
990
+ phases,
991
+ phase: "auth",
992
+ code: "AUTH_REGISTER_FAILED",
993
+ exitCode: registered.exitCode,
994
+ message: "Deepline browser authorization could not be started.",
995
+ orgName,
996
+ json: options.json,
997
+ extra: { detail: parseCapturedJson(registered.stdout), authScope }
998
+ });
999
+ }
1000
+ pending = _chunkZDOC4HFLjs.readPendingAuthClaim.call(void 0, baseUrl, authScope);
1001
+ if (!_optionalChain([pending, 'optionalAccess', _30 => _30.claimUrl])) {
1002
+ return reportSetupPhaseFailure({
1003
+ baseUrl,
1004
+ scope,
1005
+ root,
1006
+ phases,
1007
+ phase: "auth",
1008
+ code: "AUTH_CLAIM_URL_MISSING",
1009
+ exitCode: 4,
1010
+ message: "Deepline authorization did not return a usable claim URL.",
1011
+ orgName,
1012
+ json: options.json
1013
+ });
1014
+ }
1015
+ const browserOpenStatus = openSetupAuthorization(pending.claimUrl);
1016
+ if (browserOpenStatus === "failed") {
1017
+ return pendingResult({
1018
+ baseUrl,
1019
+ scope,
1020
+ root,
1021
+ phases,
1022
+ authorizationUrl: pending.claimUrl,
1023
+ browserOpenStatus: "failed",
1024
+ authClaimSource,
1025
+ orgName,
1026
+ resumed,
1027
+ json: options.json
1028
+ });
1029
+ }
1030
+ process.stderr.write("Opened Deepline sign-in in the browser.\n");
1031
+ }
1032
+ process.stderr.write(
1033
+ "Waiting up to five minutes for Deepline approval...\n"
1034
+ );
1035
+ const waited = await captureStdout(
1036
+ () => _chunkZDOC4HFLjs.handleWait.call(void 0, ["--timeout", "300", "--auth-scope", authScope])
1037
+ );
1038
+ auth = await readAuthStatus(authScope);
1039
+ const authFailure = reportSetupAuthStatusFailure({
1040
+ auth,
1041
+ baseUrl,
1042
+ authScope,
1043
+ scope,
1044
+ root,
1045
+ phases,
1046
+ orgName,
1047
+ json: options.json
1048
+ });
1049
+ if (authFailure !== null) return authFailure;
1050
+ if (waited.exitCode === _chunkZDOC4HFLjs.EXIT_WORKSPACE_MISMATCH) {
1051
+ return reportSetupPhaseFailure({
1052
+ baseUrl,
1053
+ scope,
1054
+ root,
1055
+ phases,
1056
+ phase: "auth",
1057
+ code: "REQUESTED_WORKSPACE_NOT_IN_ACCOUNT",
1058
+ exitCode: _chunkZDOC4HFLjs.EXIT_WORKSPACE_MISMATCH,
1059
+ message: `The requested workspace${orgName ? ` ${orgName}` : ""} does not exist in this account. Connect to an existing workspace first; then use deepline org create if you need a new one.`,
1060
+ orgName,
1061
+ retryAutomatic: false,
1062
+ next: "Ask the user which existing workspace or account to use. Sign in with an account that can access it, then rerun setup with --org-name set to the confirmed workspace.",
1063
+ json: options.json
1064
+ });
1065
+ }
1066
+ if (!connectedToRequestedWorkspace()) {
1067
+ const stillPending = _chunkZDOC4HFLjs.readPendingAuthClaim.call(void 0, baseUrl, authScope);
1068
+ if (_optionalChain([stillPending, 'optionalAccess', _31 => _31.claimUrl])) {
1069
+ return pendingResult({
1070
+ baseUrl,
1071
+ scope,
1072
+ root,
1073
+ phases,
1074
+ authorizationUrl: stillPending.claimUrl,
1075
+ browserOpenStatus: reusedClaim ? "existing_claim" : "timed_out",
1076
+ authClaimSource,
1077
+ orgName,
1078
+ resumed,
1079
+ json: options.json
1080
+ });
1081
+ }
1082
+ return reportSetupPhaseFailure({
1083
+ baseUrl,
1084
+ scope,
1085
+ root,
1086
+ phases,
1087
+ phase: "auth",
1088
+ code: orgName && _optionalChain([auth, 'access', _32 => _32.payload, 'optionalAccess', _33 => _33.connected]) ? "AUTH_WORKSPACE_MISMATCH" : "AUTH_WAIT_FAILED",
1089
+ exitCode: waited.exitCode || 4,
1090
+ message: orgName && _optionalChain([auth, 'access', _34 => _34.payload, 'optionalAccess', _35 => _35.connected]) ? `Deepline is connected to a different workspace than ${orgName}.` : "Deepline authorization did not complete.",
1091
+ orgName,
1092
+ ...orgName && _optionalChain([auth, 'access', _36 => _36.payload, 'optionalAccess', _37 => _37.connected]) ? {
1093
+ retryAutomatic: false,
1094
+ next: "Ask the user which existing workspace or account to use. Rerun setup with --org-name set to the confirmed workspace."
1095
+ } : {},
1096
+ json: options.json
1097
+ });
1098
+ }
1099
+ }
1100
+ completeSetupPhase(phases, "auth", "connected");
1101
+ beginSetupPhase(phases, "verify");
1102
+ persistSetupProgress({ baseUrl, scope, root, phases });
1103
+ const assessment = buildDoctorAssessment({
1104
+ baseUrl,
1105
+ scope,
1106
+ root,
1107
+ authStatus: auth
1108
+ });
1109
+ const gettingStarted = _chunkJNNOCMQYjs.deeplineGtmGettingStartedPayload.call(void 0, );
1110
+ const doctorPayload = {
1111
+ ok: assessment.ok,
1112
+ status: assessment.ok ? "complete" : "failed",
1113
+ code: assessment.ok ? "DOCTOR_OK" : "DOCTOR_FAILED",
1114
+ exitCode: assessment.ok ? 0 : 7,
1115
+ checks: assessment.checks,
1116
+ next: assessment.ok ? _chunkJNNOCMQYjs.DEEPLINE_GTM_SKILL : `deepline doctor --scope ${scope} --json`,
1117
+ ...assessment.ok ? { gettingStarted } : {}
1118
+ };
1119
+ if (!assessment.ok) {
1120
+ return reportSetupPhaseFailure({
1121
+ baseUrl,
1122
+ scope,
1123
+ root,
1124
+ phases,
1125
+ phase: "verify",
1126
+ code: "DOCTOR_FAILED",
1127
+ exitCode: 7,
1128
+ message: "Deepline setup verification found one or more failed checks.",
1129
+ orgName,
1130
+ json: options.json,
1131
+ extra: {
1132
+ doctor: doctorPayload,
1133
+ diagnostic: {
1134
+ command: `deepline doctor --scope ${scope} --json`
1135
+ }
1136
+ }
1137
+ });
1138
+ }
1139
+ completeSetupPhase(phases, "verify", "verified");
1140
+ const statePath = writeSetupState({
1141
+ baseUrl,
1142
+ scope,
1143
+ root,
1144
+ status: "complete",
1145
+ phases
1146
+ });
1147
+ const installedAgents = Array.isArray(_optionalChain([skillsPayload, 'optionalAccess', _38 => _38.agents])) ? skillsPayload.agents.filter(
1148
+ (agent) => typeof agent === "string"
1149
+ ) : [];
1150
+ await _chunkZDOC4HFLjs.reportSetupCompleted.call(void 0, {
1151
+ baseUrl,
1152
+ authScope,
1153
+ scope,
1154
+ resumed,
1155
+ installedAgentCount: installedAgents.length
1156
+ });
1157
+ const doctorChecks = asRecord(_optionalChain([doctorPayload, 'optionalAccess', _39 => _39.checks]));
1158
+ const apiCheck = asRecord(_optionalChain([doctorChecks, 'optionalAccess', _40 => _40.api]));
1159
+ const workspaceRecord = asRecord(_optionalChain([apiCheck, 'optionalAccess', _41 => _41.workspace]));
1160
+ const workspaceName = typeof _optionalChain([workspaceRecord, 'optionalAccess', _42 => _42.name]) === "string" && workspaceRecord.name.trim() ? workspaceRecord.name.trim() : null;
1161
+ _chunk7D6QG5KFjs.printCommandEnvelope.call(void 0,
1162
+ {
1163
+ ok: true,
1164
+ status: "complete",
1165
+ complete: true,
1166
+ scope,
1167
+ cliVersion: _chunk6HPEDBSJjs.SDK_VERSION,
1168
+ agents: installedAgents,
1169
+ workspace: _nullishCoalesce(_optionalChain([apiCheck, 'optionalAccess', _43 => _43.workspace]), () => ( null)),
1170
+ businessDomain: typeof _optionalChain([auth, 'access', _44 => _44.payload, 'optionalAccess', _45 => _45.businessDomain]) === "string" ? auth.payload.businessDomain : null,
1171
+ authClaimSource,
1172
+ browserOpened: authClaimSource === "new",
1173
+ rollbackCommand: rollbackCommand(scope, root),
1174
+ statePath,
1175
+ doctor: doctorPayload,
1176
+ phases,
1177
+ currentPhase: null,
1178
+ failedPhase: null,
1179
+ resumed,
1180
+ next: _chunkJNNOCMQYjs.DEEPLINE_GTM_SKILL,
1181
+ gettingStarted,
1182
+ render: {
1183
+ sections: [
1184
+ {
1185
+ title: "setup",
1186
+ lines: [
1187
+ workspaceName ? `Deepline is installed and connected to ${workspaceName}.` : "Deepline is installed and connected.",
1188
+ ...workspaceName ? ["To link a different workspace, run: deepline auth register"] : [],
1189
+ `Use ${_chunkJNNOCMQYjs.DEEPLINE_GTM_SKILL} in your agent.`,
1190
+ gettingStarted.question,
1191
+ ..._chunkJNNOCMQYjs.DEEPLINE_GTM_STARTER_PROMPTS.map(
1192
+ (example, index) => `${index + 1}. ${example.title}: ${example.prompt}`
1193
+ ),
1194
+ `4. ${gettingStarted.customOption}`
1195
+ ]
1196
+ }
1197
+ ]
1198
+ }
1199
+ },
1200
+ { json: options.json }
1201
+ );
1202
+ return 0;
1203
+ }
1204
+ function registerSetupCommands(program) {
1205
+ program.command("setup").description("Install skills, authenticate, and verify Deepline.").option("--scope <scope>", "Setup scope: global or local", "global").option(
1206
+ "--org-name <name>",
1207
+ "Connect to an existing workspace, or name your first workspace"
1208
+ ).option("--json", "Emit one final JSON result envelope").addHelpText(
1209
+ "after",
1210
+ `
1211
+ Notes:
1212
+ Setup is idempotent. Bare setup resumes the first incomplete or failed phase.
1213
+ It installs skills before auth and does not run a starter workflow.
1214
+ JSON output includes phase status and an exact retry command.
1215
+
1216
+ Examples:
1217
+ deepline setup --json
1218
+ deepline setup --org-name Acme --json
1219
+ deepline setup --scope local --json
1220
+ `
1221
+ ).action(async (options) => {
1222
+ process.exitCode = await runSetupCommand(options);
1223
+ });
1224
+ program.command("doctor").description("Verify CLI, skills, auth, workspace, and API connectivity.").option(
1225
+ "--scope <scope>",
1226
+ "Expected setup scope: global or local",
1227
+ "global"
1228
+ ).option("--json", "Emit one JSON result envelope").addHelpText(
1229
+ "after",
1230
+ `
1231
+ Notes:
1232
+ Doctor is read-only and makes no paid provider calls. It reports repairs but
1233
+ does not apply them automatically.
1234
+
1235
+ Examples:
1236
+ deepline doctor --json
1237
+ deepline doctor --scope local --json
1238
+ `
1239
+ ).action(async (options) => {
1240
+ process.exitCode = await runDoctorCommand(options);
1241
+ });
1242
+ }
1243
+
1244
+
1245
+
1246
+
1247
+
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+
1256
+
1257
+ exports.buildPendingAuthorizationOutput = buildPendingAuthorizationOutput; exports.initialSetupPhases = initialSetupPhases; exports.inspectGlobalCliAvailability = inspectGlobalCliAvailability; exports.inspectPathConflict = inspectPathConflict; exports.isNpmManagedDeeplinePath = isNpmManagedDeeplinePath; exports.openSetupAuthorization = openSetupAuthorization; exports.registerSetupCommands = registerSetupCommands; exports.removeKnownLegacyPaths = removeKnownLegacyPaths; exports.reportSetupAuthStatusFailure = reportSetupAuthStatusFailure; exports.resolvePersistentGlobalCommand = resolvePersistentGlobalCommand; exports.runDoctorCommand = runDoctorCommand; exports.runSetupCommand = runSetupCommand; exports.selectSetupProgress = selectSetupProgress;