deepline 0.3.63 → 0.3.64

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.
@@ -570,6 +570,8 @@ var ConfigError = class extends DeeplineError {
570
570
  // src/config.ts
571
571
  var HOST_URL_ENV = "DEEPLINE_HOST_URL";
572
572
  var API_KEY_ENV = "DEEPLINE_API_KEY";
573
+ var ACTIVE_ORG_ID_ENV = "DEEPLINE_ACTIVE_ORG_ID";
574
+ var ACTIVE_ORG_NAME_ENV = "DEEPLINE_ACTIVE_ORG_NAME";
573
575
  var PROD_URL = "https://code.deepline.com";
574
576
  var DEFAULT_TIMEOUT = 6e4;
575
577
  var DEFAULT_MAX_RETRIES = 3;
@@ -590,6 +592,12 @@ var COWORK_PROJECT_MARKERS = [
590
592
  "package.json",
591
593
  "pyproject.toml"
592
594
  ];
595
+ var CLI_ENV_ALLOWED_KEYS = /* @__PURE__ */ new Set([
596
+ HOST_URL_ENV,
597
+ API_KEY_ENV,
598
+ ACTIVE_ORG_ID_ENV,
599
+ ACTIVE_ORG_NAME_ENV
600
+ ]);
593
601
  function baseUrlSlug(baseUrl) {
594
602
  let url;
595
603
  try {
@@ -616,7 +624,13 @@ function parseEnvFile(filePath) {
616
624
  if (eqIndex < 0) continue;
617
625
  const key = trimmed.slice(0, eqIndex).trim();
618
626
  let value = trimmed.slice(eqIndex + 1).trim();
619
- if (value.length >= 2 && (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'"))) {
627
+ if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
628
+ try {
629
+ value = JSON.parse(value);
630
+ } catch {
631
+ value = value.slice(1, -1);
632
+ }
633
+ } else if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) {
620
634
  value = value.slice(1, -1);
621
635
  }
622
636
  if (key && value) {
@@ -774,6 +788,23 @@ function firstNonEmpty(...values) {
774
788
  }
775
789
  return "";
776
790
  }
791
+ function formatEnvFileValue(value) {
792
+ return /^[a-zA-Z0-9_./:@%+=,-]+$/.test(value) ? value : JSON.stringify(value);
793
+ }
794
+ function mergePersistedEnvValues(existing, values) {
795
+ const merged = { ...existing, ...values };
796
+ const nextApiKey = values[API_KEY_ENV];
797
+ if (nextApiKey !== void 0 && nextApiKey !== existing[API_KEY_ENV] && values[ACTIVE_ORG_ID_ENV] === void 0) {
798
+ delete merged[ACTIVE_ORG_ID_ENV];
799
+ delete merged[ACTIVE_ORG_NAME_ENV];
800
+ }
801
+ return merged;
802
+ }
803
+ function persistedEnvLines(values) {
804
+ return Object.entries(values).filter(
805
+ ([key, value]) => CLI_ENV_ALLOWED_KEYS.has(key) && value.trim() !== ""
806
+ ).map(([key, value]) => `${key}=${formatEnvFileValue(value)}`);
807
+ }
777
808
  function sdkCliConfigDir(baseUrl) {
778
809
  const home = process.env.HOME?.trim() || homedir();
779
810
  return join(home, ".local", "deepline", baseUrlSlug(baseUrl || PROD_URL));
@@ -806,9 +837,8 @@ function saveHostEnvValues(baseUrl, values) {
806
837
  mkdirSync(dir, { recursive: true });
807
838
  }
808
839
  const existing = parseEnvFile(filePath);
809
- const merged = { ...existing, ...values };
810
- const allowedKeys = /* @__PURE__ */ new Set([HOST_URL_ENV, API_KEY_ENV]);
811
- const lines = Object.entries(merged).filter(([key, value]) => allowedKeys.has(key) && value !== "").map(([key, value]) => `${key}=${value}`);
840
+ const merged = mergePersistedEnvValues(existing, values);
841
+ const lines = persistedEnvLines(merged);
812
842
  writeFileSync(filePath, `${lines.join("\n")}
813
843
  `, "utf-8");
814
844
  }
@@ -884,12 +914,11 @@ function resolveConfig(options) {
884
914
  }
885
915
  function mergeProjectEnvFile(filePath, values) {
886
916
  const existing = parseEnvFile(filePath);
887
- const merged = { ...existing, ...values };
917
+ const merged = mergePersistedEnvValues(existing, values);
888
918
  const dir = dirname(filePath);
889
919
  if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
890
920
  ensureProjectEnvIsIgnored(dir);
891
- const allowedKeys = /* @__PURE__ */ new Set([HOST_URL_ENV, API_KEY_ENV]);
892
- const lines = Object.entries(merged).filter(([key, value]) => allowedKeys.has(key) && value !== "").map(([key, value]) => `${key}=${value}`);
921
+ const lines = persistedEnvLines(merged);
893
922
  writeFileSync(filePath, `${lines.join("\n")}
894
923
  `, "utf-8");
895
924
  }
@@ -1055,6 +1084,71 @@ function resolveCliAuthProvenance(config, startDir = process.cwd()) {
1055
1084
  folderAuthPath: folderAuth?.filePath ?? null
1056
1085
  };
1057
1086
  }
1087
+ function activeOrganizationFromEnv(env) {
1088
+ const orgId = env[ACTIVE_ORG_ID_ENV]?.trim();
1089
+ if (!orgId) return null;
1090
+ const orgName = env[ACTIVE_ORG_NAME_ENV]?.trim() || null;
1091
+ return { org_id: orgId, org_name: orgName };
1092
+ }
1093
+ function resolveCliCommandContext(inputConfig, requestedScope) {
1094
+ let config = inputConfig;
1095
+ if (!config) {
1096
+ try {
1097
+ config = resolveConfig();
1098
+ } catch {
1099
+ return {
1100
+ active_organization: null,
1101
+ auth_scope: null,
1102
+ metadata_source: null
1103
+ };
1104
+ }
1105
+ }
1106
+ const contextForScope = (scope) => {
1107
+ if (scope === "env") {
1108
+ const processApiKey = process.env[API_KEY_ENV]?.trim();
1109
+ return processApiKey && processApiKey === config.apiKey ? {
1110
+ active_organization: activeOrganizationFromEnv(process.env),
1111
+ auth_scope: "env",
1112
+ metadata_source: "process_env"
1113
+ } : null;
1114
+ }
1115
+ if (scope === "folder") {
1116
+ const projectAuth = getResolvedProjectAuthSource(
1117
+ config.baseUrl,
1118
+ config.apiKey
1119
+ );
1120
+ return projectAuth ? {
1121
+ active_organization: activeOrganizationFromEnv(projectAuth.env),
1122
+ auth_scope: "folder",
1123
+ metadata_source: "folder_env"
1124
+ } : null;
1125
+ }
1126
+ const hostEnv = loadCliEnv(config.baseUrl);
1127
+ return (hostEnv[API_KEY_ENV] ?? "").trim() === config.apiKey ? {
1128
+ active_organization: activeOrganizationFromEnv(hostEnv),
1129
+ auth_scope: "global",
1130
+ metadata_source: "host_env"
1131
+ } : null;
1132
+ };
1133
+ const processContext = contextForScope("env");
1134
+ if (processContext) return processContext;
1135
+ if (requestedScope) {
1136
+ return contextForScope(requestedScope) ?? {
1137
+ active_organization: null,
1138
+ auth_scope: requestedScope,
1139
+ metadata_source: null
1140
+ };
1141
+ }
1142
+ for (const scope of ["folder", "global"]) {
1143
+ const context = contextForScope(scope);
1144
+ if (context) return context;
1145
+ }
1146
+ return {
1147
+ active_organization: null,
1148
+ auth_scope: null,
1149
+ metadata_source: null
1150
+ };
1151
+ }
1058
1152
 
1059
1153
  // ../plays/artifact-contract-version.ts
1060
1154
  var CURRENT_PLAY_ARTIFACT_CONTRACT_VERSION = 2;
@@ -1105,7 +1199,7 @@ var SDK_RELEASE = {
1105
1199
  // available at toolResponse.rawV2 while toolResponse.raw and all declared
1106
1200
  // getters keep their established compatibility behavior.
1107
1201
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
1108
- version: "0.3.63",
1202
+ version: "0.3.64",
1109
1203
  updateSummary: "Automatic CLI updates are now enabled by default. To opt out, run `deepline settings autoupdate off`; use `deepline settings autoupdate on` to re-enable updates or `deepline settings autoupdate pin <version>` to hold an exact release. This release also adds raw-v2 tool responses at toolResponse.rawV2 while preserving existing toolResponse.raw and declared getters.",
1110
1204
  packageCapabilities: {
1111
1205
  updatePreferences: 1
@@ -7996,8 +8090,21 @@ function markdownTableFromRows(rows, preferredColumns = []) {
7996
8090
  return `${[header, separator, ...body].join("\n")}
7997
8091
  `;
7998
8092
  }
8093
+ function withAgentCommandContext(value) {
8094
+ const valueRecord = value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
8095
+ return detectAgentRuntime() !== "unknown" && valueRecord && !Object.prototype.hasOwnProperty.call(valueRecord, "command_context") ? {
8096
+ ...valueRecord,
8097
+ command_context: resolveCliCommandContext()
8098
+ } : value;
8099
+ }
7999
8100
  function printJson(value) {
8000
- process.stdout.write(`${JSON.stringify(value, null, 2)}
8101
+ process.stdout.write(
8102
+ `${JSON.stringify(withAgentCommandContext(value), null, 2)}
8103
+ `
8104
+ );
8105
+ }
8106
+ function printCompactJson(value) {
8107
+ process.stdout.write(`${JSON.stringify(withAgentCommandContext(value))}
8001
8108
  `);
8002
8109
  }
8003
8110
  function errorToJsonPayload(error) {
@@ -8221,7 +8328,9 @@ function shouldWaitForRegisterClaim(mode) {
8221
8328
  function saveEnvValues(values, baseUrl, scope) {
8222
8329
  const filtered = {
8223
8330
  ...values[HOST_URL_ENV] ? { [HOST_URL_ENV]: values[HOST_URL_ENV] } : {},
8224
- ...values[API_KEY_ENV] ? { [API_KEY_ENV]: values[API_KEY_ENV] } : {}
8331
+ ...values[API_KEY_ENV] ? { [API_KEY_ENV]: values[API_KEY_ENV] } : {},
8332
+ ...values[ACTIVE_ORG_ID_ENV] ? { [ACTIVE_ORG_ID_ENV]: values[ACTIVE_ORG_ID_ENV] } : {},
8333
+ ...Object.prototype.hasOwnProperty.call(values, ACTIVE_ORG_NAME_ENV) ? { [ACTIVE_ORG_NAME_ENV]: values[ACTIVE_ORG_NAME_ENV] } : {}
8225
8334
  };
8226
8335
  if (scope === "folder") {
8227
8336
  saveProjectDeeplineEnvValues(filtered);
@@ -8229,6 +8338,15 @@ function saveEnvValues(values, baseUrl, scope) {
8229
8338
  saveHostEnvValues(baseUrl, filtered);
8230
8339
  }
8231
8340
  }
8341
+ function activeOrgEnvValues(data) {
8342
+ const orgId = typeof data.org_id === "string" ? data.org_id.trim() : "";
8343
+ if (!orgId) return {};
8344
+ const orgName = typeof data.org_name === "string" ? data.org_name.trim() : "";
8345
+ return {
8346
+ [ACTIVE_ORG_ID_ENV]: orgId,
8347
+ [ACTIVE_ORG_NAME_ENV]: orgName
8348
+ };
8349
+ }
8232
8350
  async function httpJson(method, url, apiKey, body) {
8233
8351
  const headers = {
8234
8352
  "Content-Type": "application/json",
@@ -8464,7 +8582,8 @@ async function handleRegister(args) {
8464
8582
  saveEnvValues(
8465
8583
  {
8466
8584
  [HOST_URL_ENV]: baseUrl,
8467
- [API_KEY_ENV]: apiKey
8585
+ [API_KEY_ENV]: apiKey,
8586
+ ...activeOrgEnvValues(statusData)
8468
8587
  },
8469
8588
  baseUrl,
8470
8589
  authScope
@@ -8545,7 +8664,8 @@ async function handleWait(args) {
8545
8664
  saveEnvValues(
8546
8665
  {
8547
8666
  [HOST_URL_ENV]: baseUrl,
8548
- [API_KEY_ENV]: apiKey
8667
+ [API_KEY_ENV]: apiKey,
8668
+ ...activeOrgEnvValues(data)
8549
8669
  },
8550
8670
  baseUrl,
8551
8671
  authScope
@@ -8728,7 +8848,8 @@ async function handleStatus(args) {
8728
8848
  saveEnvValues(
8729
8849
  {
8730
8850
  [HOST_URL_ENV]: baseUrl,
8731
- [API_KEY_ENV]: apiKeyResp
8851
+ [API_KEY_ENV]: apiKeyResp,
8852
+ ...activeOrgEnvValues(data)
8732
8853
  },
8733
8854
  baseUrl,
8734
8855
  resolvedAuthScope
@@ -8744,6 +8865,12 @@ async function handleStatus(args) {
8744
8865
  printCommandEnvelope(
8745
8866
  {
8746
8867
  ...payload,
8868
+ ...detectAgentRuntime() !== "unknown" ? {
8869
+ command_context: resolveCliCommandContext(
8870
+ { baseUrl, apiKey },
8871
+ resolvedAuthScope
8872
+ )
8873
+ } : {},
8747
8874
  ...savedApiKeyPath ? { saved_api_key_path: savedApiKeyPath } : {},
8748
8875
  render: {
8749
8876
  sections: [
@@ -21695,8 +21822,7 @@ async function handlePlayCheck(args) {
21695
21822
  note: "Named/prebuilt play contract is available. No run was started."
21696
21823
  };
21697
21824
  if (options.jsonOutput) {
21698
- process.stdout.write(`${JSON.stringify(result)}
21699
- `);
21825
+ printCompactJson(result);
21700
21826
  } else {
21701
21827
  console.log(`\u2713 ${result.reference} passed named play contract check`);
21702
21828
  console.log(" no run started; no Deepline credits spent");
@@ -21714,14 +21840,11 @@ async function handlePlayCheck(args) {
21714
21840
  const resolved = resolve11(options.target);
21715
21841
  const message = error instanceof Error && error.message ? error.message : `File not found: ${resolved}`;
21716
21842
  if (options.jsonOutput) {
21717
- process.stdout.write(
21718
- `${JSON.stringify({
21719
- valid: false,
21720
- target: options.target,
21721
- errors: [message]
21722
- })}
21723
- `
21724
- );
21843
+ printCompactJson({
21844
+ valid: false,
21845
+ target: options.target,
21846
+ errors: [message]
21847
+ });
21725
21848
  } else {
21726
21849
  console.error(message);
21727
21850
  }
@@ -21744,8 +21867,7 @@ async function handlePlayCheck(args) {
21744
21867
  }
21745
21868
  const merged = mergePlayCheckExportOutcomes(outcomes);
21746
21869
  if (options.jsonOutput) {
21747
- process.stdout.write(`${JSON.stringify(merged.json)}
21748
- `);
21870
+ printCompactJson(merged.json);
21749
21871
  } else {
21750
21872
  printPlayCheckOutcomes(outcomes, options.target);
21751
21873
  }
@@ -22956,21 +23078,18 @@ async function handlePlayGet(args) {
22956
23078
  }
22957
23079
  const loadedMessage = materializedFile ? formatLoadedPlayMessage(materializedFile) : null;
22958
23080
  if (jsonOutput) {
22959
- process.stdout.write(
22960
- `${JSON.stringify({
22961
- ...detail,
22962
- ...materializedFile ? {
22963
- message: loadedMessage,
22964
- materializedFile: {
22965
- path: materializedFile.path,
22966
- created: materializedFile.created,
22967
- status: materializedFile.status,
22968
- message: loadedMessage
22969
- }
22970
- } : {}
22971
- })}
22972
- `
22973
- );
23081
+ printCompactJson({
23082
+ ...detail,
23083
+ ...materializedFile ? {
23084
+ message: loadedMessage,
23085
+ materializedFile: {
23086
+ path: materializedFile.path,
23087
+ created: materializedFile.created,
23088
+ status: materializedFile.status,
23089
+ message: loadedMessage
23090
+ }
23091
+ } : {}
23092
+ });
22974
23093
  return 0;
22975
23094
  }
22976
23095
  if (sourceOutput) {
@@ -23055,8 +23174,7 @@ async function handlePlayVersions(args) {
23055
23174
  parseReferencedPlayTarget2(playName).playName
23056
23175
  );
23057
23176
  if (jsonOutput) {
23058
- process.stdout.write(`${JSON.stringify({ versions })}
23059
- `);
23177
+ printCompactJson({ versions });
23060
23178
  return 0;
23061
23179
  }
23062
23180
  if (versions.length === 0) {
@@ -23142,13 +23260,11 @@ async function handlePlayPin(args, pinned) {
23142
23260
  const name = parsedTarget.playName;
23143
23261
  const plan = { name, pinned, dryRun };
23144
23262
  if (dryRun) {
23145
- process.stdout.write(`${JSON.stringify(plan)}
23146
- `);
23263
+ printCompactJson(plan);
23147
23264
  return 0;
23148
23265
  }
23149
23266
  const result = await new DeeplineClient().setPlayPinned(name, pinned);
23150
- if (jsonOutput) process.stdout.write(`${JSON.stringify(result)}
23151
- `);
23267
+ if (jsonOutput) printCompactJson(result);
23152
23268
  else console.log(`${result.pinned ? "Pinned" : "Unpinned"} ${result.name}.`);
23153
23269
  return 0;
23154
23270
  }
@@ -23350,21 +23466,18 @@ async function handlePlaySearch(args) {
23350
23466
  ...play,
23351
23467
  inputSchema: compactPlaySchema(play.inputSchema)
23352
23468
  })) : plays;
23353
- process.stdout.write(
23354
- `${JSON.stringify({
23355
- disclaimer,
23356
- search_policy: {
23357
- default_scope: "prebuilt",
23358
- included_origins: options.scope === "all" ? ["prebuilt", "owned"] : ["prebuilt"],
23359
- owned_plays_omitted: options.scope === "prebuilt",
23360
- include_owned_flag: "--all"
23361
- },
23362
- plays: jsonPlays,
23363
- total: jsonPlays.length,
23364
- truncated: false
23365
- })}
23366
- `
23367
- );
23469
+ printCompactJson({
23470
+ disclaimer,
23471
+ search_policy: {
23472
+ default_scope: "prebuilt",
23473
+ included_origins: options.scope === "all" ? ["prebuilt", "owned"] : ["prebuilt"],
23474
+ owned_plays_omitted: options.scope === "prebuilt",
23475
+ include_owned_flag: "--all"
23476
+ },
23477
+ plays: jsonPlays,
23478
+ total: jsonPlays.length,
23479
+ truncated: false
23480
+ });
23368
23481
  return 0;
23369
23482
  }
23370
23483
  const displayPlays = options.scope === "prebuilt" ? plays.slice(0, 5) : plays;
@@ -23453,15 +23566,12 @@ async function handlePlayGrep(args) {
23453
23566
  )
23454
23567
  ).map((play) => summarizePlayListItemForCli(play, { compact }));
23455
23568
  if (argsWantJson(args)) {
23456
- process.stdout.write(
23457
- `${JSON.stringify({
23458
- plays,
23459
- count: plays.length,
23460
- query,
23461
- grep: { mode, terms: parsePlayGrepTerms(query, mode) }
23462
- })}
23463
- `
23464
- );
23569
+ printCompactJson({
23570
+ plays,
23571
+ count: plays.length,
23572
+ query,
23573
+ grep: { mode, terms: parsePlayGrepTerms(query, mode) }
23574
+ });
23465
23575
  return 0;
23466
23576
  }
23467
23577
  process.stdout.write(`${plays.length} plays found:
@@ -23507,14 +23617,11 @@ async function handlePlayDescribe(args) {
23507
23617
  ...definedName ? [`deepline plays describe <workspace>/${definedName}`] : []
23508
23618
  ];
23509
23619
  if (argsWantJson(args)) {
23510
- process.stdout.write(
23511
- `${JSON.stringify({
23512
- ok: false,
23513
- error: { message },
23514
- next
23515
- })}
23516
- `
23517
- );
23620
+ printCompactJson({
23621
+ ok: false,
23622
+ error: { message },
23623
+ next
23624
+ });
23518
23625
  } else {
23519
23626
  console.error(message);
23520
23627
  console.error(`Try: ${next[0]}`);
@@ -23535,8 +23642,7 @@ async function handlePlayDescribe(args) {
23535
23642
  }
23536
23643
  );
23537
23644
  if (argsWantJson(args)) {
23538
- process.stdout.write(`${JSON.stringify(play)}
23539
- `);
23645
+ printCompactJson(play);
23540
23646
  return 0;
23541
23647
  }
23542
23648
  printPlayDescription(play);
@@ -23580,8 +23686,7 @@ async function handlePlaySave(args) {
23580
23686
  next: `deepline plays check ${shellQuote2(options.target)}`
23581
23687
  };
23582
23688
  if (options.jsonOutput) {
23583
- process.stdout.write(`${JSON.stringify(result)}
23584
- `);
23689
+ printCompactJson(result);
23585
23690
  } else {
23586
23691
  console.error(result.message);
23587
23692
  console.error(` checked artifact: ${result.expectedArtifactHash}`);
@@ -23603,8 +23708,7 @@ async function handlePlaySave(args) {
23603
23708
  };
23604
23709
  if (options.dryRun) {
23605
23710
  if (options.jsonOutput) {
23606
- process.stdout.write(`${JSON.stringify(dryRun)}
23607
- `);
23711
+ printCompactJson(dryRun);
23608
23712
  } else {
23609
23713
  console.log(`Dry run: ${playName}`);
23610
23714
  console.log(` source: ${dryRun.sourceHash}`);
@@ -23649,8 +23753,7 @@ async function handlePlaySave(args) {
23649
23753
  }
23650
23754
  };
23651
23755
  if (options.jsonOutput) {
23652
- process.stdout.write(`${JSON.stringify(result)}
23653
- `);
23756
+ printCompactJson(result);
23654
23757
  } else {
23655
23758
  console.log(
23656
23759
  `\u2713 Saved ${playName} working draft as v${result.version ?? "?"}`
@@ -23708,8 +23811,7 @@ async function handlePlayPublish(args) {
23708
23811
  next: `deepline plays check ${shellQuote2(playName)}`
23709
23812
  };
23710
23813
  if (options.jsonOutput) {
23711
- process.stdout.write(`${JSON.stringify(result3)}
23712
- `);
23814
+ printCompactJson(result3);
23713
23815
  } else {
23714
23816
  console.error(result3.message);
23715
23817
  console.error(` checked artifact: ${result3.expectedArtifactHash}`);
@@ -23732,8 +23834,7 @@ async function handlePlayPublish(args) {
23732
23834
  };
23733
23835
  if (options.dryRun) {
23734
23836
  if (options.jsonOutput) {
23735
- process.stdout.write(`${JSON.stringify(dryRun)}
23736
- `);
23837
+ printCompactJson(dryRun);
23737
23838
  } else {
23738
23839
  console.log(`Dry run: ${rootPlayName}`);
23739
23840
  console.log(` source: ${dryRun.sourceHash}`);
@@ -23801,8 +23902,7 @@ async function handlePlayPublish(args) {
23801
23902
  triggerBindings: published.triggerBindings ?? []
23802
23903
  };
23803
23904
  if (options.jsonOutput) {
23804
- process.stdout.write(`${JSON.stringify(result2)}
23805
- `);
23905
+ printCompactJson(result2);
23806
23906
  } else {
23807
23907
  printPublishReceipt({
23808
23908
  name: rootPlayName,
@@ -23833,8 +23933,7 @@ async function handlePlayPublish(args) {
23833
23933
  revisionId: revisionId ?? null,
23834
23934
  latest: useLatest
23835
23935
  };
23836
- process.stdout.write(`${JSON.stringify(result2)}
23837
- `);
23936
+ printCompactJson(result2);
23838
23937
  return 0;
23839
23938
  }
23840
23939
  const resolvedName = parseReferencedPlayTarget2(playName).playName;
@@ -23858,8 +23957,7 @@ async function handlePlayPublish(args) {
23858
23957
  revisionId ? { revisionId } : {}
23859
23958
  );
23860
23959
  if (options.jsonOutput) {
23861
- process.stdout.write(`${JSON.stringify(result)}
23862
- `);
23960
+ printCompactJson(result);
23863
23961
  } else {
23864
23962
  printPublishReceipt({
23865
23963
  name: result.name,
@@ -23924,8 +24022,7 @@ async function handlePlayDelete(args) {
23924
24022
  plannedMutation: "move saved org-owned play to Trash and stop triggers"
23925
24023
  };
23926
24024
  if (argsWantJson(args)) {
23927
- process.stdout.write(`${JSON.stringify(result2)}
23928
- `);
24025
+ printCompactJson(result2);
23929
24026
  } else {
23930
24027
  process.stdout.write(
23931
24028
  `Dry run: would move ${result2.name} to Trash and stop its active triggers.
@@ -23936,8 +24033,7 @@ async function handlePlayDelete(args) {
23936
24033
  }
23937
24034
  const result = await client2.deletePlay(resolvedName);
23938
24035
  if (argsWantJson(args)) {
23939
- process.stdout.write(`${JSON.stringify(result)}
23940
- `);
24036
+ printCompactJson(result);
23941
24037
  return result.archived || result.alreadyArchived ? 0 : 4;
23942
24038
  }
23943
24039
  if (result.alreadyArchived) {
@@ -23982,8 +24078,7 @@ async function handlePlayRestore(args) {
23982
24078
  parseReferencedPlayTarget2(playName).playName
23983
24079
  );
23984
24080
  if (argsWantJson(args)) {
23985
- process.stdout.write(`${JSON.stringify(result)}
23986
- `);
24081
+ printCompactJson(result);
23987
24082
  return result.restored || result.alreadyActive ? 0 : 4;
23988
24083
  }
23989
24084
  if (result.alreadyActive) {
@@ -24869,8 +24964,7 @@ async function handlePlayShareStatus(args) {
24869
24964
  const status = await new DeeplineClient().getSharePage(name);
24870
24965
  const outputStatus = shareStatusForOutput(status);
24871
24966
  if (argsWantJson(args)) {
24872
- process.stdout.write(`${JSON.stringify(outputStatus)}
24873
- `);
24967
+ printCompactJson(outputStatus);
24874
24968
  return 0;
24875
24969
  }
24876
24970
  if (!outputStatus.share) {
@@ -24941,10 +25035,12 @@ async function handlePlaySharePublish(args) {
24941
25035
  if (!hasCompleted) {
24942
25036
  const message = `No completed run for ${name}. Publish a play only after it has run successfully. (Override with --no-run-check.)`;
24943
25037
  if (argsWantJson(args)) {
24944
- process.stdout.write(
24945
- `${JSON.stringify({ ok: false, code: "NO_SUCCESSFUL_RUN", message, next: `deepline plays run ${name} --wait` })}
24946
- `
24947
- );
25038
+ printCompactJson({
25039
+ ok: false,
25040
+ code: "NO_SUCCESSFUL_RUN",
25041
+ message,
25042
+ next: `deepline plays run ${name} --wait`
25043
+ });
24948
25044
  } else {
24949
25045
  console.error(message);
24950
25046
  console.error(` deepline plays run ${name} --wait`);
@@ -24964,8 +25060,7 @@ async function handlePlaySharePublish(args) {
24964
25060
  if (args.includes("--dry-run")) {
24965
25061
  const plan = { dryRun: true, name, version: resolvedVersion, ...request };
24966
25062
  if (argsWantJson(args)) {
24967
- process.stdout.write(`${JSON.stringify(plan)}
24968
- `);
25063
+ printCompactJson(plan);
24969
25064
  } else {
24970
25065
  console.log(
24971
25066
  `Would publish ${name}${resolvedVersion ? ` v${resolvedVersion}` : ""} (revision ${revisionId}).`
@@ -24976,8 +25071,7 @@ async function handlePlaySharePublish(args) {
24976
25071
  const status = await client2.publishSharePage(name, request);
24977
25072
  const outputStatus = shareStatusForOutput(status);
24978
25073
  if (argsWantJson(args)) {
24979
- process.stdout.write(`${JSON.stringify(outputStatus)}
24980
- `);
25074
+ printCompactJson(outputStatus);
24981
25075
  return 0;
24982
25076
  }
24983
25077
  const urls = shareUrlFields(outputStatus);
@@ -25010,8 +25104,7 @@ async function handlePlayShareUpdate(args) {
25010
25104
  };
25011
25105
  const status = await new DeeplineClient().updateSharePage(name, request);
25012
25106
  if (argsWantJson(args)) {
25013
- process.stdout.write(`${JSON.stringify(status)}
25014
- `);
25107
+ printCompactJson(status);
25015
25108
  return 0;
25016
25109
  }
25017
25110
  console.log(`Updated ${name} share settings.`);
@@ -25044,8 +25137,7 @@ async function handlePlayShareRegenerate(args) {
25044
25137
  );
25045
25138
  const outputStatus = shareStatusForOutput(status);
25046
25139
  if (argsWantJson(args)) {
25047
- process.stdout.write(`${JSON.stringify(outputStatus)}
25048
- `);
25140
+ printCompactJson(outputStatus);
25049
25141
  return 0;
25050
25142
  }
25051
25143
  const urls = shareUrlFields(outputStatus);
@@ -25072,8 +25164,7 @@ async function handlePlayShareUnpublish(args) {
25072
25164
  const name = parseReferencedPlayTarget2(target).playName;
25073
25165
  const status = await new DeeplineClient().unpublishSharePage(name);
25074
25166
  if (argsWantJson(args)) {
25075
- process.stdout.write(`${JSON.stringify(status)}
25076
- `);
25167
+ printCompactJson(status);
25077
25168
  return 0;
25078
25169
  }
25079
25170
  console.log(`Unpublished ${name}; the public page has been removed.`);
@@ -33640,6 +33731,27 @@ function redactApiKey(value) {
33640
33731
  function processEnvValue(name) {
33641
33732
  return process.env[name]?.trim() ?? "";
33642
33733
  }
33734
+ function organizationAuthValues(input2) {
33735
+ return {
33736
+ [HOST_URL_ENV]: input2.baseUrl,
33737
+ [API_KEY_ENV]: input2.apiKey,
33738
+ [ACTIVE_ORG_ID_ENV]: input2.orgId,
33739
+ [ACTIVE_ORG_NAME_ENV]: input2.orgName
33740
+ };
33741
+ }
33742
+ function organizationCommandContext(input2) {
33743
+ return {
33744
+ active_organization: {
33745
+ org_id: input2.orgId,
33746
+ org_name: input2.orgName
33747
+ },
33748
+ auth_scope: input2.authScope,
33749
+ metadata_source: input2.authScope === "folder" ? "folder_env" : "host_env"
33750
+ };
33751
+ }
33752
+ function agentCommandContext(commandContext) {
33753
+ return detectAgentRuntime() !== "unknown" ? { command_context: commandContext } : {};
33754
+ }
33643
33755
  function resolveOrgSwitchAuthTarget(scope, config) {
33644
33756
  const activeProject = getResolvedProjectAuthSource(
33645
33757
  config.baseUrl,
@@ -33836,10 +33948,16 @@ async function handleOrgSwitch(selection, options) {
33836
33948
  const config = resolveConfig();
33837
33949
  const provenance = resolveCliAuthProvenance(config);
33838
33950
  if (!selection && !options.orgId && authScope === "folder" && provenance.scope === "global" && provenance.project.state === "project") {
33951
+ const commandContext = resolveCliCommandContext(config);
33952
+ const activeOrganization = commandContext.active_organization;
33839
33953
  const project_env_paths2 = saveProjectDeeplineEnvValues(
33840
33954
  {
33841
33955
  [HOST_URL_ENV]: config.baseUrl,
33842
- [API_KEY_ENV]: config.apiKey
33956
+ [API_KEY_ENV]: config.apiKey,
33957
+ ...activeOrganization ? {
33958
+ [ACTIVE_ORG_ID_ENV]: activeOrganization.org_id,
33959
+ [ACTIVE_ORG_NAME_ENV]: activeOrganization.org_name ?? ""
33960
+ } : {}
33843
33961
  },
33844
33962
  provenance.project.dir
33845
33963
  );
@@ -33850,6 +33968,13 @@ async function handleOrgSwitch(selection, options) {
33850
33968
  requested_auth_scope: "folder",
33851
33969
  effective_auth_scope: "folder",
33852
33970
  auth_scope: "folder",
33971
+ ...agentCommandContext(
33972
+ activeOrganization ? organizationCommandContext({
33973
+ orgId: activeOrganization.org_id,
33974
+ orgName: activeOrganization.org_name,
33975
+ authScope: "folder"
33976
+ }) : resolveCliCommandContext(config, "folder")
33977
+ ),
33853
33978
  project_env_paths: project_env_paths2,
33854
33979
  next: { status: "deepline org status --json" },
33855
33980
  render: {
@@ -33912,10 +34037,12 @@ async function handleOrgSwitch(selection, options) {
33912
34037
  const authTarget = resolveOrgSwitchAuthTarget(authScope, config);
33913
34038
  if (target.is_current) {
33914
34039
  let project_env_paths2 = [];
33915
- const authValues2 = {
33916
- [HOST_URL_ENV]: config.baseUrl,
33917
- [API_KEY_ENV]: config.apiKey
33918
- };
34040
+ const authValues2 = organizationAuthValues({
34041
+ baseUrl: config.baseUrl,
34042
+ apiKey: config.apiKey,
34043
+ orgId: target.org_id,
34044
+ orgName: target.name
34045
+ });
33919
34046
  if (authTarget.kind === "folder") {
33920
34047
  project_env_paths2 = saveProjectDeeplineEnvValues(authValues2);
33921
34048
  } else {
@@ -33952,6 +34079,13 @@ async function handleOrgSwitch(selection, options) {
33952
34079
  effective_auth_scope: authTarget.effective_scope,
33953
34080
  auth_scope_reason: authTarget.reason,
33954
34081
  auth_scope: authTarget.effective_scope,
34082
+ ...agentCommandContext(
34083
+ organizationCommandContext({
34084
+ orgId: target.org_id,
34085
+ orgName: target.name,
34086
+ authScope: authTarget.effective_scope
34087
+ })
34088
+ ),
33955
34089
  host_env_path: authTarget.kind === "global" ? hostEnvFilePath(config.baseUrl) : null,
33956
34090
  project_env_paths: project_env_paths2,
33957
34091
  deprecated_command: options.deprecatedSwitch ? "org switch" : null,
@@ -33970,18 +34104,16 @@ async function handleOrgSwitch(selection, options) {
33970
34104
  org_id: target.org_id
33971
34105
  });
33972
34106
  let project_env_paths = [];
33973
- const authValues = {
33974
- [HOST_URL_ENV]: config.baseUrl,
33975
- [API_KEY_ENV]: switched.api_key
33976
- };
34107
+ const authValues = organizationAuthValues({
34108
+ baseUrl: config.baseUrl,
34109
+ apiKey: switched.api_key,
34110
+ orgId: switched.org_id,
34111
+ orgName: switched.org_name
34112
+ });
33977
34113
  if (authTarget.kind === "folder") {
33978
34114
  project_env_paths = saveProjectDeeplineEnvValues(authValues);
33979
34115
  } else {
33980
- saveHostEnvValues(config.baseUrl, {
33981
- ...authValues,
33982
- DEEPLINE_ACTIVE_ORG_ID: switched.org_id,
33983
- DEEPLINE_ACTIVE_ORG_NAME: switched.org_name
33984
- });
34116
+ saveHostEnvValues(config.baseUrl, authValues);
33985
34117
  }
33986
34118
  const { api_key: _apiKey, ...publicSwitched } = switched;
33987
34119
  const renderLines = [`Switched to ${switched.org_name}.`];
@@ -34016,6 +34148,13 @@ async function handleOrgSwitch(selection, options) {
34016
34148
  effective_auth_scope: authTarget.effective_scope,
34017
34149
  auth_scope_reason: authTarget.reason,
34018
34150
  auth_scope: authTarget.effective_scope,
34151
+ ...agentCommandContext(
34152
+ organizationCommandContext({
34153
+ orgId: switched.org_id,
34154
+ orgName: switched.org_name,
34155
+ authScope: authTarget.effective_scope
34156
+ })
34157
+ ),
34019
34158
  deprecated_command: options.deprecatedSwitch ? "org switch" : null,
34020
34159
  replacement_command: options.deprecatedSwitch ? "deepline org set" : null,
34021
34160
  warnings,
@@ -34038,15 +34177,13 @@ async function handleOrgCreate(name, options) {
34038
34177
  api_key: config.apiKey,
34039
34178
  name
34040
34179
  });
34041
- const authValues = {
34042
- [HOST_URL_ENV]: config.baseUrl,
34043
- [API_KEY_ENV]: created.api_key
34044
- };
34045
- saveHostEnvValues(config.baseUrl, {
34046
- ...authValues,
34047
- DEEPLINE_ACTIVE_ORG_ID: created.org_id,
34048
- DEEPLINE_ACTIVE_ORG_NAME: created.org_name
34180
+ const authValues = organizationAuthValues({
34181
+ baseUrl: config.baseUrl,
34182
+ apiKey: created.api_key,
34183
+ orgId: created.org_id,
34184
+ orgName: created.org_name
34049
34185
  });
34186
+ saveHostEnvValues(config.baseUrl, authValues);
34050
34187
  const { api_key: _apiKey, ...publicCreated } = created;
34051
34188
  printCommandEnvelope(
34052
34189
  {
@@ -34055,6 +34192,13 @@ async function handleOrgCreate(name, options) {
34055
34192
  api_key_saved: true,
34056
34193
  switched: true,
34057
34194
  host_env_path: hostEnvFilePath(config.baseUrl),
34195
+ ...agentCommandContext(
34196
+ organizationCommandContext({
34197
+ orgId: created.org_id,
34198
+ orgName: created.org_name,
34199
+ authScope: "global"
34200
+ })
34201
+ ),
34058
34202
  render: {
34059
34203
  sections: [
34060
34204
  {
@@ -39962,26 +40106,20 @@ async function getTool(toolId, options = {}) {
39962
40106
  return 2;
39963
40107
  }
39964
40108
  if (options.contractJson) {
39965
- process.stdout.write(
39966
- `${JSON.stringify({
39967
- ...toolContractJsonForDescribe(tool, toolId),
39968
- ...modelDescription ? { modelOptions: modelDescription } : {},
39969
- ...inferenceQuote ? { inferenceQuote } : {}
39970
- })}
39971
- `
39972
- );
40109
+ printCompactJson({
40110
+ ...toolContractJsonForDescribe(tool, toolId),
40111
+ ...modelDescription ? { modelOptions: modelDescription } : {},
40112
+ ...inferenceQuote ? { inferenceQuote } : {}
40113
+ });
39973
40114
  return 0;
39974
40115
  }
39975
40116
  const emitJson = options.json === true;
39976
40117
  if (emitJson) {
39977
- process.stdout.write(
39978
- `${JSON.stringify({
39979
- ...toolMetadataJsonForDescribe(tool, toolId),
39980
- ...modelDescription ? { modelOptions: modelDescription } : {},
39981
- ...inferenceQuote ? { inferenceQuote } : {}
39982
- })}
39983
- `
39984
- );
40118
+ printCompactJson({
40119
+ ...toolMetadataJsonForDescribe(tool, toolId),
40120
+ ...modelDescription ? { modelOptions: modelDescription } : {},
40121
+ ...inferenceQuote ? { inferenceQuote } : {}
40122
+ });
39985
40123
  return 0;
39986
40124
  }
39987
40125
  const onlyModes = [
@@ -40026,14 +40164,11 @@ ${formatModelDescription(modelDescription)}`);
40026
40164
  return 0;
40027
40165
  }
40028
40166
  if (shouldEmitJson()) {
40029
- process.stdout.write(
40030
- `${JSON.stringify({
40031
- ...toolContractJsonForDescribe(tool, toolId),
40032
- ...modelDescription ? { modelOptions: modelDescription } : {},
40033
- ...inferenceQuote ? { inferenceQuote } : {}
40034
- })}
40035
- `
40036
- );
40167
+ printCompactJson({
40168
+ ...toolContractJsonForDescribe(tool, toolId),
40169
+ ...modelDescription ? { modelOptions: modelDescription } : {},
40170
+ ...inferenceQuote ? { inferenceQuote } : {}
40171
+ });
40037
40172
  return 0;
40038
40173
  }
40039
40174
  printCompactToolContract(tool, toolId);
@@ -42704,8 +42839,7 @@ Examples:
42704
42839
  ).action(async (options) => {
42705
42840
  const data = await runPreflightCheck();
42706
42841
  if (shouldEmitJson(options.json)) {
42707
- process.stdout.write(`${JSON.stringify(data, null, 2)}
42708
- `);
42842
+ printJson(data);
42709
42843
  } else {
42710
42844
  printPreflightHuman(data);
42711
42845
  }
@@ -42730,14 +42864,12 @@ Examples:
42730
42864
  try {
42731
42865
  if (options.playRunner) {
42732
42866
  const data2 = await runPlayRunnerHealthCheck();
42733
- process.stdout.write(`${JSON.stringify(data2, null, 2)}
42734
- `);
42867
+ printJson(data2);
42735
42868
  return;
42736
42869
  }
42737
42870
  const client2 = new DeeplineClient();
42738
42871
  const data = await client2.health();
42739
- process.stdout.write(`${JSON.stringify(data, null, 2)}
42740
- `);
42872
+ printJson(data);
42741
42873
  } catch (error) {
42742
42874
  throw new Error(
42743
42875
  `Cannot reach Deepline API: ${error instanceof Error ? error.message : String(error)}`
@@ -42758,8 +42890,7 @@ Examples:
42758
42890
  `
42759
42891
  ).option("--json", "Emit JSON output").action((options) => {
42760
42892
  if (options.json) {
42761
- process.stdout.write(`${JSON.stringify({ version: SDK_VERSION })}
42762
- `);
42893
+ printCompactJson({ version: SDK_VERSION });
42763
42894
  return;
42764
42895
  }
42765
42896
  process.stdout.write(`deepline ${SDK_VERSION}