deepline 0.3.206 → 0.3.208

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.
@@ -3046,7 +3046,7 @@ var SDK_RELEASE = {
3046
3046
  // getters keep their established compatibility behavior.
3047
3047
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
3048
3048
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
3049
- version: "0.3.206",
3049
+ version: "0.3.208",
3050
3050
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
3051
3051
  packageCapabilities: {
3052
3052
  updatePreferences: 1
@@ -11652,6 +11652,7 @@ function printCommandEnvelope(envelope, options = {}) {
11652
11652
  var EXIT_OK = 0;
11653
11653
  var EXIT_AUTH = 3;
11654
11654
  var EXIT_SERVER = 5;
11655
+ var EXIT_WORKSPACE_MISMATCH = 6;
11655
11656
  var AUTH_HTTP_TIMEOUT_MS = 1e4;
11656
11657
  var AUTH_REGISTER_HTTP_TIMEOUT_MS = 3e4;
11657
11658
  function statusBannerLine(value) {
@@ -11742,7 +11743,8 @@ function readPendingAuthClaim(baseUrl, scope) {
11742
11743
  if (!claimToken) return null;
11743
11744
  return {
11744
11745
  claimToken,
11745
- claimUrl: typeof parsed.claimUrl === "string" ? parsed.claimUrl.trim() : "",
11746
+ claimUrl: typeof parsed.claimUrl === "string" && parsed.claimUrl.trim() ? parsed.claimUrl.trim() : `${baseUrl}/api/v2/auth/cli/claim/${encodeURIComponent(claimToken)}`,
11747
+ orgName: typeof parsed.orgName === "string" ? parsed.orgName.trim() : void 0,
11746
11748
  // The record's own scope, when it has one. `register` writes this field
11747
11749
  // precisely so a resume can learn where the credential belongs; reading
11748
11750
  // back the caller's argument instead made it decorative, and a record
@@ -11763,6 +11765,14 @@ function clearPendingClaim(baseUrl, scope) {
11763
11765
  } catch {
11764
11766
  }
11765
11767
  }
11768
+ function clearSatisfiedPendingClaim(baseUrl, scope, connectedWorkspaceName) {
11769
+ const pending = readPendingAuthClaim(baseUrl, scope);
11770
+ if (!pending) return;
11771
+ if (pending.orgName && pending.orgName.toLowerCase() !== connectedWorkspaceName?.trim().toLowerCase()) {
11772
+ return;
11773
+ }
11774
+ clearPendingClaim(baseUrl, scope);
11775
+ }
11766
11776
  function parseRegisterWaitMode(args) {
11767
11777
  let mode = "auto";
11768
11778
  for (let i = 0; i < args.length; i++) {
@@ -12000,7 +12010,12 @@ async function handleRegister(args) {
12000
12010
  const claimUrl = String(data.claim_url || "");
12001
12011
  const claimToken = String(data.claim_token || "");
12002
12012
  if (claimToken) {
12003
- savePendingClaim(baseUrl, { claimToken, claimUrl, scope: authScope });
12013
+ savePendingClaim(baseUrl, {
12014
+ claimToken,
12015
+ claimUrl,
12016
+ scope: authScope,
12017
+ ...orgName ? { orgName } : {}
12018
+ });
12004
12019
  saveEnvValues(
12005
12020
  {
12006
12021
  [HOST_URL_ENV]: baseUrl
@@ -12046,6 +12061,13 @@ async function handleRegister(args) {
12046
12061
  return EXIT_SERVER;
12047
12062
  }
12048
12063
  const state = String(statusData.status || "").toLowerCase();
12064
+ if (statusData.code === "REQUESTED_WORKSPACE_NOT_IN_ACCOUNT") {
12065
+ clearPendingClaim(baseUrl, authScope);
12066
+ console.error(
12067
+ "The requested workspace does not exist in this account. Connect to an existing workspace first; then use `deepline org create` if you need a new one."
12068
+ );
12069
+ return EXIT_WORKSPACE_MISMATCH;
12070
+ }
12049
12071
  if (state === "claimed") {
12050
12072
  const apiKey = String(statusData.api_key || "");
12051
12073
  if (apiKey) {
@@ -12107,12 +12129,13 @@ async function handleWait(args) {
12107
12129
  return EXIT_AUTH;
12108
12130
  }
12109
12131
  const deadline = Date.now() + timeoutSeconds * 1e3;
12110
- while (Date.now() <= deadline) {
12132
+ while (Date.now() < deadline) {
12111
12133
  const { status, data } = await httpJson(
12112
12134
  "POST",
12113
12135
  `${baseUrl}/api/v2/auth/cli/status`,
12114
12136
  null,
12115
- { claim_token: claimToken, reveal: true }
12137
+ { claim_token: claimToken, reveal: true },
12138
+ Math.min(AUTH_HTTP_TIMEOUT_MS, Math.max(1, deadline - Date.now()))
12116
12139
  );
12117
12140
  if (status === 401 || status === 403) {
12118
12141
  clearPendingClaim(baseUrl, authScope);
@@ -12120,7 +12143,7 @@ async function handleWait(args) {
12120
12143
  return EXIT_AUTH;
12121
12144
  }
12122
12145
  if (status >= 500 || status === 0 || status === 400) {
12123
- await sleep4(2e3);
12146
+ await sleep4(Math.min(2e3, Math.max(0, deadline - Date.now())));
12124
12147
  continue;
12125
12148
  }
12126
12149
  if (status >= 400) {
@@ -12128,6 +12151,13 @@ async function handleWait(args) {
12128
12151
  return EXIT_SERVER;
12129
12152
  }
12130
12153
  const state = String(data.status || "").toLowerCase();
12154
+ if (data.code === "REQUESTED_WORKSPACE_NOT_IN_ACCOUNT") {
12155
+ clearPendingClaim(baseUrl, authScope);
12156
+ console.error(
12157
+ "The requested workspace does not exist in this account. Connect to an existing workspace first; then use `deepline org create` if you need a new one."
12158
+ );
12159
+ return EXIT_WORKSPACE_MISMATCH;
12160
+ }
12131
12161
  if (state === "claimed") {
12132
12162
  const apiKey = String(data.api_key || "");
12133
12163
  if (apiKey) {
@@ -12150,7 +12180,7 @@ async function handleWait(args) {
12150
12180
  console.error("That approval link expired. Run: deepline auth register");
12151
12181
  return EXIT_AUTH;
12152
12182
  }
12153
- await sleep4(2e3);
12183
+ await sleep4(Math.min(2e3, Math.max(0, deadline - Date.now())));
12154
12184
  }
12155
12185
  console.error(
12156
12186
  "Still pending. Approve the browser link, then run: deepline auth wait"
@@ -12295,7 +12325,11 @@ async function handleStatus(args) {
12295
12325
  return EXIT_SERVER;
12296
12326
  }
12297
12327
  const resolvedAuthScope = authScope ?? (getResolvedProjectAuthSource(baseUrl, apiKey) ? "folder" : "global");
12298
- clearPendingClaim(baseUrl, resolvedAuthScope);
12328
+ clearSatisfiedPendingClaim(
12329
+ baseUrl,
12330
+ resolvedAuthScope,
12331
+ typeof data.org_name === "string" ? data.org_name : null
12332
+ );
12299
12333
  const payload = {
12300
12334
  ...hostStatusPayload ?? { host: baseUrl },
12301
12335
  status: data.status || "(unknown)",
@@ -12309,6 +12343,7 @@ async function handleStatus(args) {
12309
12343
  user: {
12310
12344
  id: data.user_id ?? null
12311
12345
  },
12346
+ businessDomain: typeof data.business_domain === "string" ? data.business_domain : null,
12312
12347
  examples: Array.isArray(data.examples) ? data.examples : []
12313
12348
  };
12314
12349
  let savedApiKeyPath = null;
@@ -12420,7 +12455,7 @@ Examples:
12420
12455
  `
12421
12456
  ).option(
12422
12457
  "--org-name <name>",
12423
- "Use this workspace, or create a separate one with this name"
12458
+ "Connect to an existing workspace, or name your first workspace"
12424
12459
  ).option(
12425
12460
  "--org-id <id>",
12426
12461
  "Bind to this workspace directly, skipping the browser picker"
@@ -21609,6 +21644,11 @@ function carriesArtifact(revision, artifact) {
21609
21644
  revision && revision.sourceHash === artifact.sourceHash && revision.artifactHash === artifact.artifactHash && revision.graphHash === artifact.graphHash && revision.artifactKind === artifact.artifactKind
21610
21645
  );
21611
21646
  }
21647
+ function isSdkUpdated(live, artifact) {
21648
+ return Boolean(
21649
+ live && live.sourceHash === artifact.sourceHash && live.graphHash === artifact.graphHash && live.artifactHash !== artifact.artifactHash
21650
+ );
21651
+ }
21612
21652
  function annotationForFailure(input2) {
21613
21653
  return {
21614
21654
  path: input2.file,
@@ -22043,6 +22083,11 @@ async function runDeployment(params, hooks) {
22043
22083
  });
22044
22084
  }
22045
22085
  const playByName = new Map(ordered.map((play) => [play.name, play]));
22086
+ const sdkUpdated = (name) => {
22087
+ const artifact = playByName.get(name)?.result.artifact;
22088
+ const live = stateByName.get(name)?.liveRevision ?? null;
22089
+ return artifact && isSdkUpdated(live, artifact) ? { sdkUpdated: true } : {};
22090
+ };
22046
22091
  const outcomes = [];
22047
22092
  const toRegister = [];
22048
22093
  const toPromote = [];
@@ -22089,6 +22134,7 @@ async function runDeployment(params, hooks) {
22089
22134
  file: play.file,
22090
22135
  status: "registered",
22091
22136
  version: playState?.workingRevision?.version ?? void 0,
22137
+ ...sdkUpdated(play.name),
22092
22138
  ...warning ? { warning } : {}
22093
22139
  });
22094
22140
  }
@@ -22130,6 +22176,7 @@ async function runDeployment(params, hooks) {
22130
22176
  file: item.play.file,
22131
22177
  status: "registered",
22132
22178
  version: typeof artifact.version === "number" ? artifact.version : void 0,
22179
+ ...sdkUpdated(item.play.name),
22133
22180
  ...warning ? { warning } : {}
22134
22181
  });
22135
22182
  }
@@ -22144,7 +22191,7 @@ async function runDeployment(params, hooks) {
22144
22191
  title: `${ordered.length} play${ordered.length === 1 ? "" : "s"} validated and registered (not deployed)`,
22145
22192
  ...annotations.length > 0 ? { annotations } : {},
22146
22193
  summary: outcomes.map(
22147
- (outcome) => `- \`${outcome.name}\`: ${outcome.status}${outcome.version !== void 0 ? ` (v${outcome.version})` : ""}${outcome.warning ? `
22194
+ (outcome) => `- \`${outcome.name}\`: ${outcome.status}${outcome.version !== void 0 ? ` (v${outcome.version})` : ""}${outcome.sdkUpdated ? " \u2014 SDK updated" : ""}${outcome.warning ? `
22148
22195
  - :warning: ${outcome.warning}` : ""}`
22149
22196
  ).join("\n")
22150
22197
  });
@@ -22173,6 +22220,7 @@ async function runDeployment(params, hooks) {
22173
22220
  status: outcome.status === "promoted" ? "promoted" : "failed",
22174
22221
  version: outcome.version,
22175
22222
  ...outcome.status === "promoted" && typeof previousVersion === "number" && previousVersion !== outcome.version ? { previousVersion } : {},
22223
+ ...outcome.status === "promoted" ? sdkUpdated(outcome.name) : {},
22176
22224
  ...outcome.status === "promoted" && warning ? { warning } : {},
22177
22225
  ...outcome.error ? { error: outcome.error } : {}
22178
22226
  });
@@ -22219,7 +22267,7 @@ async function runDeployment(params, hooks) {
22219
22267
  title: `Deployed ${outcomes.filter((o) => o.status === "promoted").length} play(s) (${outcomes.filter((o) => o.status === "unchanged").length} unchanged)`,
22220
22268
  ...annotations.length > 0 ? { annotations } : {},
22221
22269
  summary: outcomes.map(
22222
- (outcome) => `- \`${outcome.name}\`: ${outcome.status}${outcome.warning ? `
22270
+ (outcome) => `- \`${outcome.name}\`: ${outcome.status}${outcome.sdkUpdated ? " \u2014 SDK updated" : ""}${outcome.warning ? `
22223
22271
  - :warning: ${outcome.warning}` : ""}`
22224
22272
  ).join("\n")
22225
22273
  });
@@ -22307,8 +22355,9 @@ function topoSortByPlayDependencies(plays) {
22307
22355
  var MAX_DEPLOY_ATTEMPTS = 3;
22308
22356
  function renderOutcome(outcome) {
22309
22357
  const version = outcome.version === void 0 ? "" : outcome.previousVersion === void 0 ? ` v${outcome.version}` : ` v${outcome.previousVersion} -> v${outcome.version}`;
22358
+ const sdkUpdated = outcome.sdkUpdated ? " (SDK updated)" : "";
22310
22359
  const note = outcome.error ?? outcome.warning;
22311
- return `${outcome.name} (${outcome.file}): ${outcome.status}${version}${note ? ` - ${note}` : ""}`;
22360
+ return `${outcome.name} (${outcome.file}): ${outcome.status}${version}${sdkUpdated}${note ? ` - ${note}` : ""}`;
22312
22361
  }
22313
22362
  function printResult(input2) {
22314
22363
  const failed = input2.status === "failed" || input2.status === "cancelled";
@@ -22740,8 +22789,9 @@ function renderDeploymentPlayLines(results) {
22740
22789
  return plays.flatMap((play) => {
22741
22790
  const version = play.version === void 0 ? "" : play.previousVersion === void 0 ? ` v${play.version}` : ` v${play.previousVersion} -> v${play.version}`;
22742
22791
  const file = play.file ? ` (${play.file})` : "";
22792
+ const sdkUpdated = play.sdkUpdated ? " (SDK updated)" : "";
22743
22793
  return [
22744
- `${play.name ?? "?"}${file} - ${play.status ?? "?"}${version}`,
22794
+ `${play.name ?? "?"}${file} - ${play.status ?? "?"}${version}${sdkUpdated}`,
22745
22795
  ...play.error ? [` error: ${play.error}`] : [],
22746
22796
  ...play.warning ? [` warning: ${play.warning}`] : []
22747
22797
  ];
@@ -45547,11 +45597,24 @@ function openSetupAuthorization(authorizationUrl, options = {}) {
45547
45597
  }
45548
45598
  function buildPendingAuthorizationOutput(input2) {
45549
45599
  const authorizationUrl = input2.authorizationUrl.trim();
45550
- if (input2.browserOpenStatus === "opened") {
45600
+ if (input2.browserOpenStatus === "existing_claim" && authorizationUrl) {
45551
45601
  return {
45552
- authorizationUrl: null,
45553
- next: `Complete browser approval, then run: ${input2.resumeCommand}`,
45554
- lines: ["Complete authorization in the browser window Deepline opened."]
45602
+ authorizationUrl,
45603
+ next: `The existing approval is still pending. Use its authorization URL if needed, then run: ${input2.resumeCommand}`,
45604
+ lines: [
45605
+ "Deepline did not open another browser tab. Use the existing approval page or this link:",
45606
+ authorizationUrl
45607
+ ]
45608
+ };
45609
+ }
45610
+ if (input2.browserOpenStatus === "timed_out" && authorizationUrl) {
45611
+ return {
45612
+ authorizationUrl,
45613
+ next: `Approval is still pending after five minutes. Use the authorization URL if needed, then run: ${input2.resumeCommand}`,
45614
+ lines: [
45615
+ "Approval is still pending. Use this link if the tab was missed:",
45616
+ authorizationUrl
45617
+ ]
45555
45618
  };
45556
45619
  }
45557
45620
  if (authorizationUrl) {
@@ -45741,15 +45804,16 @@ function rollbackCommand(scope, root) {
45741
45804
  const allowScriptsFlag = npmSupportsAllowScripts(readNpmVersion(process.env)) ? " --allow-scripts=esbuild" : "";
45742
45805
  return `npm install -g${prefix} --no-audit --no-fund --include=optional${allowScriptsFlag} deepline@${SDK_VERSION}`;
45743
45806
  }
45744
- function setupResumeCommand(baseUrl, scope) {
45807
+ function setupResumeCommand(baseUrl, scope, orgName) {
45745
45808
  const hostPrefix = baseUrl === "https://code.deepline.com" ? "" : `DEEPLINE_HOST_URL=${JSON.stringify(baseUrl)} `;
45746
- return `${hostPrefix}deepline setup --scope ${scope} --json`;
45809
+ const quotedOrgName = orgName ? process.platform === "win32" ? ` --org-name "${orgName.replace(/"/g, '""')}"` : ` --org-name '${orgName.replace(/'/g, `'\\''`)}'` : "";
45810
+ return `${hostPrefix}deepline setup --scope ${scope}${quotedOrgName} --json`;
45747
45811
  }
45748
45812
  function setupRetry(input2) {
45749
45813
  return {
45750
45814
  phase: input2.phase,
45751
- command: setupResumeCommand(input2.baseUrl, input2.scope),
45752
- automatic: true
45815
+ command: setupResumeCommand(input2.baseUrl, input2.scope, input2.orgName),
45816
+ automatic: input2.retryAutomatic ?? true
45753
45817
  };
45754
45818
  }
45755
45819
  function reportSetupPhaseFailure(input2) {
@@ -45805,6 +45869,7 @@ function reportSetupAuthStatusFailure(input2) {
45805
45869
  scope: input2.scope,
45806
45870
  root: input2.root,
45807
45871
  phases: input2.phases,
45872
+ orgName: input2.orgName,
45808
45873
  phase: "auth",
45809
45874
  code: "AUTH_STATUS_FAILED",
45810
45875
  exitCode: 4,
@@ -45927,22 +45992,14 @@ function pendingResult(input2) {
45927
45992
  status: "authorization_pending",
45928
45993
  phases: input2.phases
45929
45994
  });
45930
- let browserOpenStatus = "failed";
45931
- if (input2.authorizationUrl) {
45932
- browserOpenStatus = openSetupAuthorization(input2.authorizationUrl);
45933
- if (browserOpenStatus === "opened") {
45934
- process.stderr.write(
45935
- "Opened Deepline authorization in your browser. Complete approval there.\n"
45936
- );
45937
- } else if (browserOpenStatus === "failed") {
45938
- process.stderr.write(`Authorize Deepline: ${input2.authorizationUrl}
45939
- `);
45940
- }
45941
- }
45942
45995
  const pendingOutput = buildPendingAuthorizationOutput({
45943
45996
  authorizationUrl: input2.authorizationUrl,
45944
- browserOpenStatus,
45945
- resumeCommand: setupResumeCommand(input2.baseUrl, input2.scope)
45997
+ browserOpenStatus: input2.browserOpenStatus,
45998
+ resumeCommand: setupResumeCommand(
45999
+ input2.baseUrl,
46000
+ input2.scope,
46001
+ input2.orgName
46002
+ )
45946
46003
  });
45947
46004
  printCommandEnvelope(
45948
46005
  {
@@ -45951,8 +46008,9 @@ function pendingResult(input2) {
45951
46008
  complete: false,
45952
46009
  scope: input2.scope,
45953
46010
  authorizationUrl: pendingOutput.authorizationUrl,
45954
- browserOpened: browserOpenStatus === "opened",
45955
- browserOpenStatus,
46011
+ browserOpened: input2.browserOpenStatus === "timed_out",
46012
+ browserOpenStatus: input2.browserOpenStatus,
46013
+ authClaimSource: input2.authClaimSource,
45956
46014
  statePath,
45957
46015
  phases: input2.phases,
45958
46016
  currentPhase: "auth",
@@ -45960,7 +46018,8 @@ function pendingResult(input2) {
45960
46018
  retry: setupRetry({
45961
46019
  baseUrl: input2.baseUrl,
45962
46020
  scope: input2.scope,
45963
- phase: "auth"
46021
+ phase: "auth",
46022
+ orgName: input2.orgName
45964
46023
  }),
45965
46024
  next: pendingOutput.next,
45966
46025
  render: {
@@ -45977,6 +46036,20 @@ function pendingResult(input2) {
45977
46036
  return 0;
45978
46037
  }
45979
46038
  async function runSetupCommand(options) {
46039
+ let orgName = options.orgName?.trim();
46040
+ if (options.orgName !== void 0 && !orgName) {
46041
+ printCommandEnvelope(
46042
+ {
46043
+ ok: false,
46044
+ status: "failed",
46045
+ code: "INVALID_ORG_NAME",
46046
+ exitCode: 2,
46047
+ message: "Workspace name cannot be empty."
46048
+ },
46049
+ { json: options.json }
46050
+ );
46051
+ return 2;
46052
+ }
45980
46053
  let scope;
45981
46054
  let root;
45982
46055
  try {
@@ -46021,6 +46094,7 @@ async function runSetupCommand(options) {
46021
46094
  exitCode: 7,
46022
46095
  message: installedButUnreachable ? `The global Deepline executable is not reachable on PATH: ${globalCli.persistentPath}` : "No persistent global Deepline executable was found.",
46023
46096
  json: options.json,
46097
+ orgName,
46024
46098
  extra: {
46025
46099
  persistentPath: globalCli.persistentPath,
46026
46100
  fallback: "https://code.deepline.com/INSTALL.md"
@@ -46040,6 +46114,7 @@ async function runSetupCommand(options) {
46040
46114
  exitCode: 7,
46041
46115
  message: `An unknown executable named deepline is first on PATH: ${conflict}`,
46042
46116
  json: options.json,
46117
+ orgName,
46043
46118
  extra: { path: conflict }
46044
46119
  });
46045
46120
  }
@@ -46073,7 +46148,8 @@ async function runSetupCommand(options) {
46073
46148
  code: "LEGACY_CLEANUP_FAILED",
46074
46149
  exitCode: 5,
46075
46150
  message: error instanceof Error ? error.message : String(error),
46076
- json: options.json
46151
+ json: options.json,
46152
+ orgName
46077
46153
  });
46078
46154
  }
46079
46155
  }
@@ -46094,7 +46170,7 @@ async function runSetupCommand(options) {
46094
46170
  process.stderr.write(
46095
46171
  "Global skill setup failed. Trying project-local skills instead.\n"
46096
46172
  );
46097
- return runSetupCommand({ scope: "local", json: options.json });
46173
+ return runSetupCommand({ scope: "local", json: options.json, orgName });
46098
46174
  }
46099
46175
  return reportSetupPhaseFailure({
46100
46176
  baseUrl,
@@ -46106,7 +46182,8 @@ async function runSetupCommand(options) {
46106
46182
  exitCode: skills.exitCode,
46107
46183
  message: typeof skillsPayload?.message === "string" ? skillsPayload.message : "Deepline skills could not be installed.",
46108
46184
  json: options.json,
46109
- next: `! ${setupResumeCommand(baseUrl, scope)}`,
46185
+ orgName,
46186
+ next: `! ${setupResumeCommand(baseUrl, scope, orgName)}`,
46110
46187
  extra: { detail: skillsPayload }
46111
46188
  });
46112
46189
  }
@@ -46128,6 +46205,13 @@ async function runSetupCommand(options) {
46128
46205
  );
46129
46206
  }
46130
46207
  const authScope = authScopeForSetup(scope);
46208
+ const pendingAtStart = readPendingAuthClaim(baseUrl, authScope);
46209
+ const replacingPendingClaim = Boolean(
46210
+ pendingAtStart && orgName && pendingAtStart.orgName?.toLowerCase() !== orgName.toLowerCase()
46211
+ );
46212
+ if (pendingAtStart && !replacingPendingClaim) {
46213
+ if (pendingAtStart.orgName) orgName = pendingAtStart.orgName;
46214
+ }
46131
46215
  beginSetupPhase(phases, "auth");
46132
46216
  persistSetupProgress({ baseUrl, scope, root, phases });
46133
46217
  let auth = await readAuthStatus(authScope);
@@ -46138,88 +46222,146 @@ async function runSetupCommand(options) {
46138
46222
  scope,
46139
46223
  root,
46140
46224
  phases,
46225
+ orgName,
46141
46226
  json: options.json
46142
46227
  });
46143
46228
  if (initialAuthFailure !== null) return initialAuthFailure;
46144
- if (auth.payload?.connected !== true) {
46145
- const pending = readPendingAuthClaim(baseUrl, authScope);
46146
- if (pending) {
46147
- process.stderr.write("Checking pending Deepline authorization...\n");
46148
- await captureStdout2(
46149
- () => handleWait(["--timeout", "1", "--auth-scope", authScope])
46150
- );
46151
- auth = await readAuthStatus(authScope);
46152
- const resumedAuthFailure = reportSetupAuthStatusFailure({
46153
- auth,
46154
- baseUrl,
46155
- authScope,
46156
- scope,
46157
- root,
46158
- phases,
46159
- json: options.json
46160
- });
46161
- if (resumedAuthFailure !== null) return resumedAuthFailure;
46162
- if (auth.payload?.connected !== true) {
46163
- const stillPending = readPendingAuthClaim(baseUrl, authScope);
46164
- if (stillPending) {
46165
- return pendingResult({
46166
- baseUrl,
46167
- scope,
46168
- root,
46169
- phases,
46170
- authorizationUrl: stillPending.claimUrl,
46171
- resumed,
46172
- json: options.json
46173
- });
46174
- }
46229
+ const connectedToRequestedWorkspace = () => {
46230
+ if (auth.payload?.connected !== true) return false;
46231
+ if (!orgName) return true;
46232
+ const workspace = asRecord3(auth.payload.workspace);
46233
+ return typeof workspace?.name === "string" && workspace.name.trim().toLowerCase() === orgName.toLowerCase();
46234
+ };
46235
+ let pending = replacingPendingClaim ? null : readPendingAuthClaim(baseUrl, authScope);
46236
+ if (replacingPendingClaim && connectedToRequestedWorkspace()) {
46237
+ clearPendingClaim(baseUrl, authScope);
46238
+ }
46239
+ let authClaimSource = "none";
46240
+ if (pending || !connectedToRequestedWorkspace()) {
46241
+ const reusedClaim = Boolean(pending);
46242
+ authClaimSource = reusedClaim ? "existing" : "new";
46243
+ if (!pending) {
46244
+ process.stderr.write("Starting Deepline browser authorization...\n");
46245
+ const registered = await captureStdout2(
46246
+ () => handleRegister([
46247
+ "--wait",
46248
+ "no",
46249
+ "--auth-scope",
46250
+ authScope,
46251
+ ...orgName ? ["--org-name", orgName] : []
46252
+ ])
46253
+ );
46254
+ if (registered.exitCode !== 0) {
46255
+ return reportSetupPhaseFailure({
46256
+ baseUrl,
46257
+ scope,
46258
+ root,
46259
+ phases,
46260
+ phase: "auth",
46261
+ code: "AUTH_REGISTER_FAILED",
46262
+ exitCode: registered.exitCode,
46263
+ message: "Deepline browser authorization could not be started.",
46264
+ orgName,
46265
+ json: options.json,
46266
+ extra: { detail: parseCapturedJson(registered.stdout), authScope }
46267
+ });
46268
+ }
46269
+ pending = readPendingAuthClaim(baseUrl, authScope);
46270
+ if (!pending?.claimUrl) {
46271
+ return reportSetupPhaseFailure({
46272
+ baseUrl,
46273
+ scope,
46274
+ root,
46275
+ phases,
46276
+ phase: "auth",
46277
+ code: "AUTH_CLAIM_URL_MISSING",
46278
+ exitCode: 4,
46279
+ message: "Deepline authorization did not return a usable claim URL.",
46280
+ orgName,
46281
+ json: options.json
46282
+ });
46175
46283
  }
46284
+ const browserOpenStatus = openSetupAuthorization(pending.claimUrl);
46285
+ if (browserOpenStatus === "failed") {
46286
+ return pendingResult({
46287
+ baseUrl,
46288
+ scope,
46289
+ root,
46290
+ phases,
46291
+ authorizationUrl: pending.claimUrl,
46292
+ browserOpenStatus: "failed",
46293
+ authClaimSource,
46294
+ orgName,
46295
+ resumed,
46296
+ json: options.json
46297
+ });
46298
+ }
46299
+ process.stderr.write("Opened Deepline sign-in in the browser.\n");
46176
46300
  }
46177
- }
46178
- if (auth.payload?.connected !== true) {
46179
- process.stderr.write("Starting Deepline browser authorization...\n");
46180
- const agentRuntime = detectAgentRuntime();
46181
- const agentLed = agentRuntime !== "unknown";
46182
- const waitMode = options.json || agentLed || !process.stdin.isTTY ? "no" : "auto";
46183
- const registered = await captureStdout2(
46184
- () => handleRegister(["--wait", waitMode, "--auth-scope", authScope])
46301
+ process.stderr.write(
46302
+ "Waiting up to five minutes for Deepline approval...\n"
46303
+ );
46304
+ const waited = await captureStdout2(
46305
+ () => handleWait(["--timeout", "300", "--auth-scope", authScope])
46185
46306
  );
46186
- if (registered.exitCode !== 0) {
46187
- return reportSetupPhaseFailure({
46188
- baseUrl,
46189
- scope,
46190
- root,
46191
- phases,
46192
- phase: "auth",
46193
- code: "AUTH_REGISTER_FAILED",
46194
- exitCode: registered.exitCode,
46195
- message: "Deepline browser authorization could not be started.",
46196
- json: options.json,
46197
- extra: {
46198
- detail: parseCapturedJson(registered.stdout),
46199
- authScope
46200
- }
46201
- });
46202
- }
46203
46307
  auth = await readAuthStatus(authScope);
46204
- const registeredAuthFailure = reportSetupAuthStatusFailure({
46308
+ const authFailure = reportSetupAuthStatusFailure({
46205
46309
  auth,
46206
46310
  baseUrl,
46207
46311
  authScope,
46208
46312
  scope,
46209
46313
  root,
46210
46314
  phases,
46315
+ orgName,
46211
46316
  json: options.json
46212
46317
  });
46213
- if (registeredAuthFailure !== null) return registeredAuthFailure;
46214
- if (auth.payload?.connected !== true) {
46215
- const pending = readPendingAuthClaim(baseUrl, authScope);
46216
- return pendingResult({
46318
+ if (authFailure !== null) return authFailure;
46319
+ if (waited.exitCode === EXIT_WORKSPACE_MISMATCH) {
46320
+ return reportSetupPhaseFailure({
46321
+ baseUrl,
46322
+ scope,
46323
+ root,
46324
+ phases,
46325
+ phase: "auth",
46326
+ code: "REQUESTED_WORKSPACE_NOT_IN_ACCOUNT",
46327
+ exitCode: EXIT_WORKSPACE_MISMATCH,
46328
+ 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.`,
46329
+ orgName,
46330
+ retryAutomatic: false,
46331
+ 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.",
46332
+ json: options.json
46333
+ });
46334
+ }
46335
+ if (!connectedToRequestedWorkspace()) {
46336
+ const stillPending = readPendingAuthClaim(baseUrl, authScope);
46337
+ if (stillPending?.claimUrl) {
46338
+ return pendingResult({
46339
+ baseUrl,
46340
+ scope,
46341
+ root,
46342
+ phases,
46343
+ authorizationUrl: stillPending.claimUrl,
46344
+ browserOpenStatus: reusedClaim ? "existing_claim" : "timed_out",
46345
+ authClaimSource,
46346
+ orgName,
46347
+ resumed,
46348
+ json: options.json
46349
+ });
46350
+ }
46351
+ return reportSetupPhaseFailure({
46217
46352
  baseUrl,
46218
46353
  scope,
46219
46354
  root,
46220
46355
  phases,
46221
- authorizationUrl: pending?.claimUrl ?? "",
46222
- resumed,
46356
+ phase: "auth",
46357
+ code: orgName && auth.payload?.connected ? "AUTH_WORKSPACE_MISMATCH" : "AUTH_WAIT_FAILED",
46358
+ exitCode: waited.exitCode || 4,
46359
+ message: orgName && auth.payload?.connected ? `Deepline is connected to a different workspace than ${orgName}.` : "Deepline authorization did not complete.",
46360
+ orgName,
46361
+ ...orgName && auth.payload?.connected ? {
46362
+ retryAutomatic: false,
46363
+ next: "Ask the user which existing workspace or account to use. Rerun setup with --org-name set to the confirmed workspace."
46364
+ } : {},
46223
46365
  json: options.json
46224
46366
  });
46225
46367
  }
@@ -46253,6 +46395,7 @@ async function runSetupCommand(options) {
46253
46395
  code: "DOCTOR_FAILED",
46254
46396
  exitCode: 7,
46255
46397
  message: "Deepline setup verification found one or more failed checks.",
46398
+ orgName,
46256
46399
  json: options.json,
46257
46400
  extra: {
46258
46401
  doctor: doctorPayload,
@@ -46293,6 +46436,9 @@ async function runSetupCommand(options) {
46293
46436
  cliVersion: SDK_VERSION,
46294
46437
  agents: installedAgents,
46295
46438
  workspace: apiCheck?.workspace ?? null,
46439
+ businessDomain: typeof auth.payload?.businessDomain === "string" ? auth.payload.businessDomain : null,
46440
+ authClaimSource,
46441
+ browserOpened: authClaimSource === "new",
46296
46442
  rollbackCommand: rollbackCommand(scope, root),
46297
46443
  statePath,
46298
46444
  doctor: doctorPayload,
@@ -46324,7 +46470,10 @@ async function runSetupCommand(options) {
46324
46470
  return 0;
46325
46471
  }
46326
46472
  function registerSetupCommands(program) {
46327
- program.command("setup").description("Install skills, authenticate, and verify Deepline.").option("--scope <scope>", "Setup scope: global or local", "global").option("--json", "Emit one final JSON result envelope").addHelpText(
46473
+ program.command("setup").description("Install skills, authenticate, and verify Deepline.").option("--scope <scope>", "Setup scope: global or local", "global").option(
46474
+ "--org-name <name>",
46475
+ "Connect to an existing workspace, or name your first workspace"
46476
+ ).option("--json", "Emit one final JSON result envelope").addHelpText(
46328
46477
  "after",
46329
46478
  `
46330
46479
  Notes:
@@ -46334,6 +46483,7 @@ Notes:
46334
46483
 
46335
46484
  Examples:
46336
46485
  deepline setup --json
46486
+ deepline setup --org-name Acme --json
46337
46487
  deepline setup --scope local --json
46338
46488
  `
46339
46489
  ).action(async (options) => {
package/dist/index.js CHANGED
@@ -864,7 +864,7 @@ var SDK_RELEASE = {
864
864
  // getters keep their established compatibility behavior.
865
865
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
866
866
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
867
- version: "0.3.206",
867
+ version: "0.3.208",
868
868
  updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
869
869
  packageCapabilities: {
870
870
  updatePreferences: 1