deepline 0.2.20 → 0.2.22

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.
package/dist/cli/index.js CHANGED
@@ -186,7 +186,7 @@ configureProxyFromEnv();
186
186
 
187
187
  // src/cli/index.ts
188
188
  var import_promises8 = require("fs/promises");
189
- var import_node_path25 = require("path");
189
+ var import_node_path26 = require("path");
190
190
  var import_node_os19 = require("os");
191
191
  var import_commander4 = require("commander");
192
192
 
@@ -1044,7 +1044,7 @@ var SDK_RELEASE = {
1044
1044
  // 0.2.0 makes Dataset Handles uniformly async-only after 0.1.320 briefly
1045
1045
  // exposed storage-dependent synchronous access. This deliberate minor
1046
1046
  // release keeps lazy paging semantics independent of row residency.
1047
- version: "0.2.20",
1047
+ version: "0.2.22",
1048
1048
  contracts: {
1049
1049
  api: {
1050
1050
  name: "sdk-http-api",
@@ -1812,7 +1812,7 @@ function decodeSseFrame(frame) {
1812
1812
  return parsed;
1813
1813
  }
1814
1814
  function sleep(ms) {
1815
- return new Promise((resolve18) => setTimeout(resolve18, ms));
1815
+ return new Promise((resolve19) => setTimeout(resolve19, ms));
1816
1816
  }
1817
1817
  function withCoworkNetworkHint(message) {
1818
1818
  if (!isCoworkLikeSandbox2() || message.includes(COWORK_NETWORK_HINT)) {
@@ -3114,14 +3114,14 @@ async function* observeRunEvents(options) {
3114
3114
  try {
3115
3115
  for (; ; ) {
3116
3116
  if (queue.length === 0) {
3117
- const waitForItem = new Promise((resolve18) => {
3118
- wake = resolve18;
3117
+ const waitForItem = new Promise((resolve19) => {
3118
+ wake = resolve19;
3119
3119
  });
3120
3120
  if (!sawFirstSnapshot) {
3121
3121
  const timedOut = await Promise.race([
3122
3122
  waitForItem.then(() => false),
3123
3123
  new Promise(
3124
- (resolve18) => setTimeout(() => resolve18(true), OBSERVE_BOOTSTRAP_TIMEOUT_MS)
3124
+ (resolve19) => setTimeout(() => resolve19(true), OBSERVE_BOOTSTRAP_TIMEOUT_MS)
3125
3125
  )
3126
3126
  ]);
3127
3127
  if (timedOut && queue.length === 0) {
@@ -3431,7 +3431,7 @@ function parseEnvTestPolicyOverrides() {
3431
3431
  return normalizeTestPolicyOverrides(parsed, "DEEPLINE_TEST_POLICY_OVERRIDES");
3432
3432
  }
3433
3433
  function sleep2(ms) {
3434
- return new Promise((resolve18) => setTimeout(resolve18, ms));
3434
+ return new Promise((resolve19) => setTimeout(resolve19, ms));
3435
3435
  }
3436
3436
  function isTransientCompileManifestError(error) {
3437
3437
  if (error instanceof DeeplineError && typeof error.statusCode === "number") {
@@ -3775,6 +3775,8 @@ var DeeplineClient = class {
3775
3775
  list: (options2) => this.listRuns(options2),
3776
3776
  tail: (runId, options2) => this.tailRun(runId, options2),
3777
3777
  logs: (runId, options2) => this.getRunLogs(runId, options2),
3778
+ input: (runId) => this.getRunInput(runId),
3779
+ rerun: (runId) => this.rerun(runId),
3778
3780
  exportDatasetRows: (input2) => this.getPlaySheetRows(input2),
3779
3781
  stop: (runId, options2) => this.stopRun(runId, options2),
3780
3782
  stopAll: (options2) => this.stopAllRuns(options2)
@@ -5179,6 +5181,17 @@ var DeeplineClient = class {
5179
5181
  await sleep2(delayMs);
5180
5182
  }
5181
5183
  }
5184
+ /** Get the exact original input retained for a run. This is intentionally separate from status. */
5185
+ async getRunInput(runId) {
5186
+ return this.http.get(`/api/v2/runs/${encodeURIComponent(runId)}/input`);
5187
+ }
5188
+ /** Start a fresh run from a prior run's retained input and pinned revision. */
5189
+ async rerun(runId) {
5190
+ return this.http.post(
5191
+ `/api/v2/runs/${encodeURIComponent(runId)}/rerun`,
5192
+ {}
5193
+ );
5194
+ }
5182
5195
  /**
5183
5196
  * Fetch persisted logs for a run using the public runs resource model.
5184
5197
  *
@@ -6965,7 +6978,7 @@ function buildCandidateUrls2(url) {
6965
6978
  }
6966
6979
  }
6967
6980
  function sleep4(ms) {
6968
- return new Promise((resolve18) => setTimeout(resolve18, ms));
6981
+ return new Promise((resolve19) => setTimeout(resolve19, ms));
6969
6982
  }
6970
6983
  function printDeeplineLogo() {
6971
6984
  if (process.stdout.isTTY && (process.stdout.columns ?? 80) >= 70) {
@@ -17058,7 +17071,7 @@ function traceCliSync(phase, fields, run) {
17058
17071
  }
17059
17072
  }
17060
17073
  function sleep5(ms) {
17061
- return new Promise((resolve18) => setTimeout(resolve18, ms));
17074
+ return new Promise((resolve19) => setTimeout(resolve19, ms));
17062
17075
  }
17063
17076
  function parseReferencedPlayTarget2(target) {
17064
17077
  const trimmed = target.trim();
@@ -21842,7 +21855,7 @@ async function handlePlayRun(args, hooks) {
21842
21855
  function parseRunIdPositional(args, usage) {
21843
21856
  for (let index = 0; index < args.length; index += 1) {
21844
21857
  const arg = args[index];
21845
- if (arg === "--json" || arg === "--full" || arg === "--logs" || arg === "--compact" || arg === "--log-failed" || arg === "--failed" || arg === "--limit") {
21858
+ if (arg === "--json" || arg === "--full" || arg === "--input" || arg === "--logs" || arg === "--compact" || arg === "--log-failed" || arg === "--failed" || arg === "--limit") {
21846
21859
  if (arg === "--limit" && args[index + 1]) {
21847
21860
  index += 1;
21848
21861
  }
@@ -21859,7 +21872,7 @@ function parseRunIdPositional(args, usage) {
21859
21872
  throw new DeeplineError(usage);
21860
21873
  }
21861
21874
  async function handleRunGet(args) {
21862
- const usage = "Usage: deepline runs get <run-id> [--json] [--full] [--log-failed]";
21875
+ const usage = "Usage: deepline runs get <run-id> [--json] [--full] [--input] [--log-failed]";
21863
21876
  let runId;
21864
21877
  try {
21865
21878
  runId = parseRunIdPositional(args, usage);
@@ -21868,6 +21881,11 @@ async function handleRunGet(args) {
21868
21881
  return 1;
21869
21882
  }
21870
21883
  const client2 = new DeeplineClient();
21884
+ if (args.includes("--input")) {
21885
+ const input2 = await client2.getRunInput(runId);
21886
+ printCommandEnvelope(input2, { json: true });
21887
+ return 0;
21888
+ }
21871
21889
  const status = await client2.runs.get(runId, {
21872
21890
  full: args.includes("--full"),
21873
21891
  failedLogs: args.includes("--log-failed")
@@ -21877,6 +21895,29 @@ async function handleRunGet(args) {
21877
21895
  });
21878
21896
  return 0;
21879
21897
  }
21898
+ async function handleRunsRerun(args) {
21899
+ const usage = "Usage: deepline runs rerun <run-id> [--json]";
21900
+ let runId;
21901
+ try {
21902
+ runId = parseRunIdPositional(args, usage);
21903
+ } catch (error) {
21904
+ console.error(error instanceof Error ? error.message : usage);
21905
+ return 1;
21906
+ }
21907
+ const result = await new DeeplineClient().runs.rerun(runId);
21908
+ if (argsWantJson(args)) {
21909
+ printCommandEnvelope(result, { json: true });
21910
+ } else {
21911
+ console.log(`
21912
+ Rerun started from ${runId}.`);
21913
+ console.log(` inspect: deepline runs get ${result.runId} --json`);
21914
+ console.log(` original input: deepline runs get ${result.runId} --input`);
21915
+ console.log(
21916
+ " This is a fresh run using the original input and pinned revision. Normal tool receipt reuse still applies."
21917
+ );
21918
+ }
21919
+ return 0;
21920
+ }
21880
21921
  async function handleRunsList(args) {
21881
21922
  const usage = "Usage: deepline runs list [--play <play-name>] [--status <status>] [--limit <count>] [--offset <count>] [--json]";
21882
21923
  let playName = null;
@@ -23455,14 +23496,20 @@ Examples:
23455
23496
  `
23456
23497
  Notes:
23457
23498
  Full run status read. Use --full --json when debugging raw stream/status fields.
23499
+ Use --input only when you intentionally need the original payload; it can
23500
+ contain customer data and is never included in ordinary status output.
23458
23501
 
23459
23502
  Examples:
23460
23503
  deepline runs get play/my-play/run/20260501t000000-000
23461
23504
  deepline runs get play/my-play/run/20260501t000000-000 --json
23462
23505
  deepline runs get play/my-play/run/20260501t000000-000 --log-failed --json
23463
23506
  deepline runs get play/my-play/run/20260501t000000-000 --full --json
23507
+ deepline runs get play/my-play/run/20260501t000000-000 --input
23464
23508
  `
23465
23509
  ).option("--json", "Emit JSON output. Also automatic when stdout is piped").option("--full", "Debug only: with --json, emit the raw status payload").option(
23510
+ "--input",
23511
+ "Explicitly print the original retained input JSON (may contain customer data)"
23512
+ ).option(
23466
23513
  "--log-failed",
23467
23514
  "Attach a bounded terminal-failure log window for failed runs"
23468
23515
  ).action(async (runId, options) => {
@@ -23470,9 +23517,30 @@ Examples:
23470
23517
  runId,
23471
23518
  ...options.json ? ["--json"] : [],
23472
23519
  ...options.full ? ["--full"] : [],
23520
+ ...options.input ? ["--input"] : [],
23473
23521
  ...options.logFailed ? ["--log-failed"] : []
23474
23522
  ]);
23475
23523
  });
23524
+ runs.command("rerun <runId>").description(
23525
+ "Start a fresh run from a prior run's retained input and pinned revision."
23526
+ ).addHelpText(
23527
+ "after",
23528
+ `
23529
+ Notes:
23530
+ Creates a new run. It never mutates the original run.
23531
+ The rerun uses the original input and exact saved revision. Normal completed
23532
+ tool receipts may be reused; inspect the new run before forcing any external
23533
+ side effect.
23534
+
23535
+ Examples:
23536
+ deepline runs rerun play/my-play/webhook/abc --json
23537
+ `
23538
+ ).option("--json", "Emit JSON output. Also automatic when stdout is piped").action(async (runId, options) => {
23539
+ process.exitCode = await handleRunsRerun([
23540
+ runId,
23541
+ ...options.json ? ["--json"] : []
23542
+ ]);
23543
+ });
23476
23544
  runs.command("list").description("List play runs.").addHelpText(
23477
23545
  "after",
23478
23546
  `
@@ -25521,7 +25589,7 @@ function emitEnrichDebug(message) {
25521
25589
  );
25522
25590
  }
25523
25591
  function sleep6(ms) {
25524
- return new Promise((resolve18) => setTimeout(resolve18, ms));
25592
+ return new Promise((resolve19) => setTimeout(resolve19, ms));
25525
25593
  }
25526
25594
  function enrichExportBackingRowsWaitMs() {
25527
25595
  const raw = process.env.DEEPLINE_ENRICH_EXPORT_BACKING_ROWS_WAIT_MS?.trim();
@@ -31686,7 +31754,7 @@ async function readHiddenLine(prompt, streams = {}) {
31686
31754
  }
31687
31755
  let value = "";
31688
31756
  inputStream.resume();
31689
- return await new Promise((resolve18, reject) => {
31757
+ return await new Promise((resolve19, reject) => {
31690
31758
  let settled = false;
31691
31759
  const cleanup = () => {
31692
31760
  inputStream.off("data", onData);
@@ -31704,7 +31772,7 @@ async function readHiddenLine(prompt, streams = {}) {
31704
31772
  settled = true;
31705
31773
  outputStream.write("\n");
31706
31774
  cleanup();
31707
- resolve18(line);
31775
+ resolve19(line);
31708
31776
  };
31709
31777
  const fail = (error) => {
31710
31778
  if (settled) return;
@@ -35152,9 +35220,9 @@ Notes:
35152
35220
 
35153
35221
  // src/cli/commands/update.ts
35154
35222
  var import_node_child_process3 = require("child_process");
35155
- var import_node_fs19 = require("fs");
35223
+ var import_node_fs20 = require("fs");
35156
35224
  var import_node_os16 = require("os");
35157
- var import_node_path22 = require("path");
35225
+ var import_node_path23 = require("path");
35158
35226
 
35159
35227
  // src/cli/commands/skills.ts
35160
35228
  var import_node_child_process2 = require("child_process");
@@ -35458,7 +35526,7 @@ function readSkillsInstallState(path) {
35458
35526
  }
35459
35527
  }
35460
35528
  function runProcess(command, args, cwd) {
35461
- return new Promise((resolve18, reject) => {
35529
+ return new Promise((resolve19, reject) => {
35462
35530
  const plan = resolveShellSpawn(command, args);
35463
35531
  const child = (0, import_node_child_process2.spawn)(plan.command, plan.args, {
35464
35532
  cwd,
@@ -35477,7 +35545,7 @@ function runProcess(command, args, cwd) {
35477
35545
  process.stderr.write(`skills@latest exited ${code}.
35478
35546
  `);
35479
35547
  }
35480
- resolve18(code ?? 1);
35548
+ resolve19(code ?? 1);
35481
35549
  });
35482
35550
  });
35483
35551
  }
@@ -35671,6 +35739,166 @@ Examples:
35671
35739
  });
35672
35740
  }
35673
35741
 
35742
+ // src/cli/install-integrity.ts
35743
+ var import_node_module2 = require("module");
35744
+ var import_node_fs19 = require("fs");
35745
+ var import_node_path22 = require("path");
35746
+ var SDK_SIDECAR_CRITICAL_PACKAGE_FILES = [
35747
+ "dist/cli/index.mjs",
35748
+ "dist/index.mjs",
35749
+ "dist/index.d.ts",
35750
+ "dist/plays/bundle-play-file.mjs",
35751
+ "dist/bundling-sources/shared_libs/observability/telemetry.ts",
35752
+ "dist/bundling-sources/shared_libs/play-runtime/backend.ts",
35753
+ "dist/bundling-sources/shared_libs/plays/bundling/index.ts",
35754
+ "dist/bundling-sources/shared_libs/tool-execution-error.ts"
35755
+ ];
35756
+ var SDK_SIDECAR_CRITICAL_DEPENDENCY_FILES = [
35757
+ "esbuild/package.json",
35758
+ "esbuild/lib/main.js"
35759
+ ];
35760
+ function safeRelativePath(value) {
35761
+ if (typeof value !== "string" || !value || (0, import_node_path22.isAbsolute)(value)) return false;
35762
+ const segments = value.split(/[\\/]+/);
35763
+ return segments.every(
35764
+ (segment) => Boolean(segment) && segment !== "." && segment !== ".."
35765
+ );
35766
+ }
35767
+ function resolveContainedPath(root, value) {
35768
+ if (!safeRelativePath(value)) return null;
35769
+ const target = (0, import_node_path22.resolve)(root, value);
35770
+ const relativeTarget = (0, import_node_path22.relative)((0, import_node_path22.resolve)(root), target);
35771
+ if (!relativeTarget || relativeTarget.startsWith("..") || (0, import_node_path22.isAbsolute)(relativeTarget)) {
35772
+ return null;
35773
+ }
35774
+ return target;
35775
+ }
35776
+ function parseJson(path) {
35777
+ return JSON.parse((0, import_node_fs19.readFileSync)(path, "utf8"));
35778
+ }
35779
+ function isFile(path) {
35780
+ try {
35781
+ return (0, import_node_fs19.statSync)(path).isFile();
35782
+ } catch {
35783
+ return false;
35784
+ }
35785
+ }
35786
+ function readManifest(packageRoot) {
35787
+ const packageJsonPath = (0, import_node_path22.join)(packageRoot, "package.json");
35788
+ let packageJson;
35789
+ try {
35790
+ packageJson = parseJson(packageJsonPath);
35791
+ } catch (error) {
35792
+ return {
35793
+ mode: "manifest",
35794
+ invalidReason: `invalid Deepline package metadata: ${error.message}`,
35795
+ missing: (0, import_node_fs19.existsSync)(packageJsonPath) ? [] : ["deepline/package.json"]
35796
+ };
35797
+ }
35798
+ if (!packageJson || typeof packageJson !== "object" || Array.isArray(packageJson)) {
35799
+ return {
35800
+ mode: "manifest",
35801
+ invalidReason: "invalid Deepline package metadata: expected an object"
35802
+ };
35803
+ }
35804
+ const metadata = packageJson;
35805
+ if (metadata.deepline !== void 0 && (!metadata.deepline || typeof metadata.deepline !== "object" || Array.isArray(metadata.deepline))) {
35806
+ return {
35807
+ mode: "manifest",
35808
+ invalidReason: "invalid Deepline package metadata: deepline must be an object"
35809
+ };
35810
+ }
35811
+ const declaration = metadata.deepline?.installIntegrity;
35812
+ if (!declaration) {
35813
+ return {
35814
+ mode: "legacy",
35815
+ manifest: {
35816
+ schemaVersion: 1,
35817
+ packageFiles: [...SDK_SIDECAR_CRITICAL_PACKAGE_FILES],
35818
+ dependencyFiles: [...SDK_SIDECAR_CRITICAL_DEPENDENCY_FILES]
35819
+ }
35820
+ };
35821
+ }
35822
+ if (declaration.schemaVersion !== 1 || !safeRelativePath(declaration.manifest)) {
35823
+ return {
35824
+ mode: "manifest",
35825
+ invalidReason: "invalid Deepline install-integrity declaration"
35826
+ };
35827
+ }
35828
+ const manifestPath = resolveContainedPath(packageRoot, declaration.manifest);
35829
+ if (!manifestPath || !isFile(manifestPath)) {
35830
+ return {
35831
+ mode: "manifest",
35832
+ invalidReason: "declared Deepline install-integrity manifest is missing",
35833
+ missing: [String(declaration.manifest)]
35834
+ };
35835
+ }
35836
+ let raw;
35837
+ try {
35838
+ raw = parseJson(manifestPath);
35839
+ } catch (error) {
35840
+ return {
35841
+ mode: "manifest",
35842
+ invalidReason: `invalid Deepline install-integrity manifest: ${error.message}`
35843
+ };
35844
+ }
35845
+ if (!raw || typeof raw !== "object" || raw.schemaVersion !== 1 || !Array.isArray(raw.packageFiles) || !Array.isArray(raw.dependencyFiles)) {
35846
+ return {
35847
+ mode: "manifest",
35848
+ invalidReason: "invalid Deepline install-integrity manifest schema"
35849
+ };
35850
+ }
35851
+ const manifest = raw;
35852
+ if (manifest.packageFiles.length === 0 || manifest.dependencyFiles.length === 0 || !manifest.packageFiles.every(safeRelativePath) || !manifest.dependencyFiles.every(safeRelativePath)) {
35853
+ return {
35854
+ mode: "manifest",
35855
+ invalidReason: "unsafe path in Deepline install-integrity manifest"
35856
+ };
35857
+ }
35858
+ return { mode: "manifest", manifest };
35859
+ }
35860
+ function inspectSdkSidecarInstall(versionDir) {
35861
+ const nodeModulesRoot = (0, import_node_path22.join)(versionDir, "node_modules");
35862
+ const packageRoot = (0, import_node_path22.join)(nodeModulesRoot, "deepline");
35863
+ const manifestResult = readManifest(packageRoot);
35864
+ if ("invalidReason" in manifestResult) {
35865
+ return {
35866
+ ok: false,
35867
+ missing: manifestResult.missing ?? [],
35868
+ invalidReason: manifestResult.invalidReason,
35869
+ mode: manifestResult.mode
35870
+ };
35871
+ }
35872
+ const missing = [
35873
+ ...manifestResult.manifest.packageFiles.filter((path) => !isFile((0, import_node_path22.join)(packageRoot, path))).map((path) => `deepline/${path}`),
35874
+ ...manifestResult.manifest.dependencyFiles.filter((path) => !isFile((0, import_node_path22.join)(nodeModulesRoot, path))).map((path) => `node_modules/${path}`)
35875
+ ];
35876
+ return {
35877
+ ok: missing.length === 0,
35878
+ missing,
35879
+ invalidReason: null,
35880
+ mode: manifestResult.mode
35881
+ };
35882
+ }
35883
+ function probeSdkSidecarEsbuild(versionDir) {
35884
+ try {
35885
+ const requireFromInstall = (0, import_node_module2.createRequire)((0, import_node_path22.join)(versionDir, "package.json"));
35886
+ const esbuild = requireFromInstall("esbuild");
35887
+ if (typeof esbuild.transformSync !== "function") {
35888
+ return "esbuild does not export transformSync";
35889
+ }
35890
+ const result = esbuild.transformSync("const value: number = 1;", {
35891
+ loader: "ts"
35892
+ });
35893
+ if (typeof result?.code !== "string") {
35894
+ return "esbuild transform probe returned no code";
35895
+ }
35896
+ return null;
35897
+ } catch (error) {
35898
+ return error instanceof Error ? error.message : String(error);
35899
+ }
35900
+ }
35901
+
35674
35902
  // src/cli/commands/update.ts
35675
35903
  var NPM_SDK_INSTALL_COMMON_FLAGS = [
35676
35904
  "--no-audit",
@@ -35726,7 +35954,7 @@ function sidecarStateDir(input2) {
35726
35954
  if (!scope || scope.includes("/") || scope.includes("\\")) {
35727
35955
  return null;
35728
35956
  }
35729
- return (0, import_node_path22.join)(input2.homeDir, ".local", "deepline", scope, "sdk-cli");
35957
+ return (0, import_node_path23.join)(input2.homeDir, ".local", "deepline", scope, "sdk-cli");
35730
35958
  }
35731
35959
  function sidecarRegistryUrl(hostUrl) {
35732
35960
  let url;
@@ -35753,7 +35981,7 @@ function publicNpmFallbackRegistryUrl(hostUrl) {
35753
35981
  }
35754
35982
  function readOptionalText(path) {
35755
35983
  try {
35756
- return (0, import_node_fs19.readFileSync)(path, "utf8").trim();
35984
+ return (0, import_node_fs20.readFileSync)(path, "utf8").trim();
35757
35985
  } catch {
35758
35986
  return "";
35759
35987
  }
@@ -35761,19 +35989,19 @@ function readOptionalText(path) {
35761
35989
  function resolvePythonSidecarUpdatePlan(options) {
35762
35990
  const stateDir = sidecarStateDir(options);
35763
35991
  if (!stateDir) return null;
35764
- const relativeEntrypoint = (0, import_node_path22.relative)(
35765
- (0, import_node_path22.resolve)(stateDir),
35766
- (0, import_node_path22.resolve)(options.entrypoint)
35992
+ const relativeEntrypoint = (0, import_node_path23.relative)(
35993
+ (0, import_node_path23.resolve)(stateDir),
35994
+ (0, import_node_path23.resolve)(options.entrypoint)
35767
35995
  );
35768
- if (!relativeEntrypoint || relativeEntrypoint.startsWith("..") || (0, import_node_path22.isAbsolute)(relativeEntrypoint)) {
35996
+ if (!relativeEntrypoint || relativeEntrypoint.startsWith("..") || (0, import_node_path23.isAbsolute)(relativeEntrypoint)) {
35769
35997
  return null;
35770
35998
  }
35771
- const installMethod = readOptionalText((0, import_node_path22.join)(stateDir, ".install-method"));
35999
+ const installMethod = readOptionalText((0, import_node_path23.join)(stateDir, ".install-method"));
35772
36000
  if (installMethod !== "python-sidecar") return null;
35773
36001
  const scope = options.env.DEEPLINE_CONFIG_SCOPE?.trim() || "";
35774
36002
  const hostUrl = options.env.DEEPLINE_HOST_URL?.trim() || "";
35775
- const nodeBin = readOptionalText((0, import_node_path22.join)(stateDir, ".node-bin")) || process.execPath;
35776
- const sidecarPath = readOptionalText((0, import_node_path22.join)(stateDir, ".command-path")) || (0, import_node_path22.join)(
36003
+ const nodeBin = readOptionalText((0, import_node_path23.join)(stateDir, ".node-bin")) || process.execPath;
36004
+ const sidecarPath = readOptionalText((0, import_node_path23.join)(stateDir, ".command-path")) || (0, import_node_path23.join)(
35777
36005
  stateDir,
35778
36006
  "bin",
35779
36007
  process.platform === "win32" ? "deepline-sdk.cmd" : "deepline-sdk"
@@ -35781,7 +36009,7 @@ function resolvePythonSidecarUpdatePlan(options) {
35781
36009
  const packageSpec = options.packageSpec || "deepline@latest";
35782
36010
  const npmCommand = "npm";
35783
36011
  const registryUrl = sidecarRegistryUrl(hostUrl);
35784
- const versionDir = (0, import_node_path22.join)(stateDir, "versions", "<version>");
36012
+ const versionDir = (0, import_node_path23.join)(stateDir, "versions", "<version>");
35785
36013
  const manualCommand = `${buildSidecarProjectConfigCommand(versionDir, nodeBin)} && ${npmCommand} install --prefix ${shellQuote4(versionDir)} --registry ${shellQuote4(registryUrl)} ${NPM_SDK_INSTALL_COMMON_FLAGS.map(shellQuote4).join(" ")} ${shellQuote4(packageSpec)}`;
35786
36014
  return {
35787
36015
  kind: "python-sidecar",
@@ -35797,12 +36025,12 @@ function resolvePythonSidecarUpdatePlan(options) {
35797
36025
  };
35798
36026
  }
35799
36027
  function findRepoBackedSdkRoot(startPath) {
35800
- let current = (0, import_node_path22.resolve)(startPath);
36028
+ let current = (0, import_node_path23.resolve)(startPath);
35801
36029
  while (true) {
35802
- if ((0, import_node_fs19.existsSync)((0, import_node_path22.join)(current, "sdk", "package.json")) && (0, import_node_fs19.existsSync)((0, import_node_path22.join)(current, "sdk", "bin", "deepline-dev.ts"))) {
36030
+ if ((0, import_node_fs20.existsSync)((0, import_node_path23.join)(current, "sdk", "package.json")) && (0, import_node_fs20.existsSync)((0, import_node_path23.join)(current, "sdk", "bin", "deepline-dev.ts"))) {
35803
36031
  return current;
35804
36032
  }
35805
- const parent = (0, import_node_path22.dirname)(current);
36033
+ const parent = (0, import_node_path23.dirname)(current);
35806
36034
  if (parent === current) return null;
35807
36035
  current = parent;
35808
36036
  }
@@ -35810,9 +36038,9 @@ function findRepoBackedSdkRoot(startPath) {
35810
36038
  function inferNpmGlobalPrefixFromEntrypoint(entrypoint) {
35811
36039
  const normalized = (() => {
35812
36040
  try {
35813
- return (0, import_node_fs19.realpathSync)(entrypoint);
36041
+ return (0, import_node_fs20.realpathSync)(entrypoint);
35814
36042
  } catch {
35815
- return (0, import_node_path22.resolve)(entrypoint);
36043
+ return (0, import_node_path23.resolve)(entrypoint);
35816
36044
  }
35817
36045
  })();
35818
36046
  const parts = normalized.split(/[\\/]+/);
@@ -35831,9 +36059,9 @@ function inferNpmGlobalPrefixFromEntrypoint(entrypoint) {
35831
36059
  function isHomebrewFormulaEntrypoint(entrypoint) {
35832
36060
  const normalized = (() => {
35833
36061
  try {
35834
- return (0, import_node_fs19.realpathSync)(entrypoint);
36062
+ return (0, import_node_fs20.realpathSync)(entrypoint);
35835
36063
  } catch {
35836
- return (0, import_node_path22.resolve)(entrypoint);
36064
+ return (0, import_node_path23.resolve)(entrypoint);
35837
36065
  }
35838
36066
  })();
35839
36067
  const parts = normalized.split(/[\\/]+/);
@@ -35843,8 +36071,8 @@ function isHomebrewFormulaEntrypoint(entrypoint) {
35843
36071
  function resolveUpdatePlan(options = {}) {
35844
36072
  const env = options.env ?? process.env;
35845
36073
  const homeDir2 = options.homeDir ?? (0, import_node_os16.homedir)();
35846
- const entrypoint = options.entrypoint ?? (process.argv[1] ? (0, import_node_path22.resolve)(process.argv[1]) : "");
35847
- const sourceRoot = entrypoint ? findRepoBackedSdkRoot((0, import_node_path22.dirname)(entrypoint)) : null;
36074
+ const entrypoint = options.entrypoint ?? (process.argv[1] ? (0, import_node_path23.resolve)(process.argv[1]) : "");
36075
+ const sourceRoot = entrypoint ? findRepoBackedSdkRoot((0, import_node_path23.dirname)(entrypoint)) : null;
35848
36076
  if (sourceRoot) {
35849
36077
  return {
35850
36078
  kind: "source",
@@ -35891,9 +36119,9 @@ var AUTO_UPDATE_FAILURE_FILE = ".auto-update-failure.json";
35891
36119
  function autoUpdateFailurePath(plan) {
35892
36120
  if (plan.kind === "source" || plan.kind === "homebrew") return null;
35893
36121
  if (plan.kind === "python-sidecar") {
35894
- return (0, import_node_path22.join)(plan.stateDir, AUTO_UPDATE_FAILURE_FILE);
36122
+ return (0, import_node_path23.join)(plan.stateDir, AUTO_UPDATE_FAILURE_FILE);
35895
36123
  }
35896
- return (0, import_node_path22.join)(
36124
+ return (0, import_node_path23.join)(
35897
36125
  (0, import_node_os16.homedir)(),
35898
36126
  ".local",
35899
36127
  "deepline",
@@ -35911,7 +36139,7 @@ function readAutoUpdateFailure(plan) {
35911
36139
  if (!path) return null;
35912
36140
  try {
35913
36141
  const parsed = JSON.parse(
35914
- (0, import_node_fs19.readFileSync)(path, "utf8")
36142
+ (0, import_node_fs20.readFileSync)(path, "utf8")
35915
36143
  );
35916
36144
  if ((parsed.kind === "npm-global" || parsed.kind === "python-sidecar") && typeof parsed.packageSpec === "string" && typeof parsed.failedAt === "string" && typeof parsed.exitCode === "number" && typeof parsed.manualCommand === "string") {
35917
36145
  return parsed;
@@ -35932,8 +36160,8 @@ function writeAutoUpdateFailure(plan, exitCode) {
35932
36160
  manualCommand: plan.manualCommand
35933
36161
  };
35934
36162
  try {
35935
- (0, import_node_fs19.mkdirSync)((0, import_node_path22.dirname)(path), { recursive: true });
35936
- (0, import_node_fs19.writeFileSync)(path, `${JSON.stringify(marker, null, 2)}
36163
+ (0, import_node_fs20.mkdirSync)((0, import_node_path23.dirname)(path), { recursive: true });
36164
+ (0, import_node_fs20.writeFileSync)(path, `${JSON.stringify(marker, null, 2)}
35937
36165
  `, "utf8");
35938
36166
  } catch {
35939
36167
  }
@@ -35942,7 +36170,7 @@ function clearAutoUpdateFailure(plan) {
35942
36170
  const path = autoUpdateFailurePath(plan);
35943
36171
  if (!path) return;
35944
36172
  try {
35945
- (0, import_node_fs19.unlinkSync)(path);
36173
+ (0, import_node_fs20.unlinkSync)(path);
35946
36174
  } catch {
35947
36175
  }
35948
36176
  }
@@ -35980,7 +36208,7 @@ function safeVersionSegment(value) {
35980
36208
  return /^[0-9A-Za-z._-]+$/.test(normalized) ? normalized : "";
35981
36209
  }
35982
36210
  function entryPathInVersionDir(versionDir) {
35983
- return (0, import_node_path22.join)(
36211
+ return (0, import_node_path23.join)(
35984
36212
  versionDir,
35985
36213
  "node_modules",
35986
36214
  "deepline",
@@ -35990,19 +36218,36 @@ function entryPathInVersionDir(versionDir) {
35990
36218
  );
35991
36219
  }
35992
36220
  function installedPackageVersion(versionDir) {
35993
- const packageJsonPath = (0, import_node_path22.join)(
36221
+ const packageJsonPath = (0, import_node_path23.join)(
35994
36222
  versionDir,
35995
36223
  "node_modules",
35996
36224
  "deepline",
35997
36225
  "package.json"
35998
36226
  );
35999
36227
  try {
36000
- const parsed = JSON.parse((0, import_node_fs19.readFileSync)(packageJsonPath, "utf8"));
36228
+ const parsed = JSON.parse((0, import_node_fs20.readFileSync)(packageJsonPath, "utf8"));
36001
36229
  return typeof parsed.version === "string" ? safeVersionSegment(parsed.version) : "";
36002
36230
  } catch {
36003
36231
  return "";
36004
36232
  }
36005
36233
  }
36234
+ function sidecarStructureFailure(versionDir) {
36235
+ const health = inspectSdkSidecarInstall(versionDir);
36236
+ if (!health.ok) {
36237
+ const details = [
36238
+ ...health.invalidReason ? [health.invalidReason] : [],
36239
+ ...health.missing.length > 0 ? [`missing ${health.missing.join(", ")}`] : []
36240
+ ].join("; ");
36241
+ return details || "required SDK CLI files are missing";
36242
+ }
36243
+ return null;
36244
+ }
36245
+ function sidecarInstallFailure(versionDir) {
36246
+ const structureFailure = sidecarStructureFailure(versionDir);
36247
+ if (structureFailure) return structureFailure;
36248
+ const esbuildFailure = probeSdkSidecarEsbuild(versionDir);
36249
+ return esbuildFailure ? `esbuild probe failed: ${esbuildFailure}` : null;
36250
+ }
36006
36251
  function runCommand(command, args, env = process.env) {
36007
36252
  return new Promise((resolveResult) => {
36008
36253
  let output2 = "";
@@ -36074,26 +36319,62 @@ async function runNpmInstallWithRegistryFallback(input2) {
36074
36319
  return fallback.exitCode;
36075
36320
  }
36076
36321
  function writeSidecarLauncher(input2) {
36077
- (0, import_node_fs19.mkdirSync)((0, import_node_path22.dirname)(input2.path), { recursive: true });
36322
+ (0, import_node_fs20.mkdirSync)((0, import_node_path23.dirname)(input2.path), { recursive: true });
36323
+ const packageRoot = (0, import_node_path23.dirname)((0, import_node_path23.dirname)((0, import_node_path23.dirname)(input2.entryPath)));
36324
+ const versionDir = (0, import_node_path23.dirname)((0, import_node_path23.dirname)(packageRoot));
36325
+ const esbuildProbe = "const {createRequire}=require('node:module');const path=require('node:path');const req=createRequire(path.join(process.argv[1],'package.json'));const result=req('esbuild').transformSync('const value: number = 1;',{loader:'ts'});if(!result||typeof result.code!=='string')process.exit(3);";
36326
+ const criticalPaths = [
36327
+ ...SDK_SIDECAR_CRITICAL_PACKAGE_FILES.map(
36328
+ (path) => (0, import_node_path23.join)(packageRoot, path)
36329
+ ),
36330
+ ...SDK_SIDECAR_CRITICAL_DEPENDENCY_FILES.map(
36331
+ (path) => (0, import_node_path23.join)(versionDir, "node_modules", path)
36332
+ )
36333
+ ];
36078
36334
  if (process.platform === "win32") {
36079
- (0, import_node_fs19.writeFileSync)(
36335
+ (0, import_node_fs20.writeFileSync)(
36080
36336
  input2.path,
36081
36337
  [
36082
36338
  `@set DEEPLINE_HOST_URL=${input2.hostUrl.replace(/\r?\n/g, "")}`,
36083
36339
  `@set DEEPLINE_CONFIG_SCOPE=${input2.scope.replace(/\r?\n/g, "")}`,
36340
+ ...criticalPaths.map(
36341
+ (path) => `@if not exist "${path}" goto repair_sdk`
36342
+ ),
36343
+ `@"${input2.nodeBin}" -e "${esbuildProbe}" "${versionDir}" >NUL 2>&1`,
36344
+ "@if errorlevel 1 goto repair_sdk",
36084
36345
  `@"${input2.nodeBin}" "${input2.entryPath}" %*`,
36346
+ "@exit /b %ERRORLEVEL%",
36347
+ ":repair_sdk",
36348
+ '@if defined DEEPLINE_REAL_BINARY "%DEEPLINE_REAL_BINARY%" --version=v2 %*',
36349
+ "@if defined DEEPLINE_REAL_BINARY exit /b %ERRORLEVEL%",
36350
+ "@echo Deepline SDK CLI install is incomplete. Run `deepline update` to repair it. 1>&2",
36351
+ "@exit /b 1",
36085
36352
  ""
36086
36353
  ].join("\r\n"),
36087
36354
  "utf8"
36088
36355
  );
36089
36356
  return;
36090
36357
  }
36091
- (0, import_node_fs19.writeFileSync)(
36358
+ (0, import_node_fs20.writeFileSync)(
36092
36359
  input2.path,
36093
36360
  [
36094
36361
  "#!/usr/bin/env sh",
36095
36362
  `export DEEPLINE_HOST_URL=${shellQuote4(input2.hostUrl)}`,
36096
36363
  `export DEEPLINE_CONFIG_SCOPE=${shellQuote4(input2.scope)}`,
36364
+ `if ${criticalPaths.map((path) => `[ ! -f ${shellQuote4(path)} ]`).join(" || ")}; then`,
36365
+ ' if [ -n "${DEEPLINE_REAL_BINARY:-}" ] && [ -x "$DEEPLINE_REAL_BINARY" ]; then',
36366
+ ' exec "$DEEPLINE_REAL_BINARY" --version=v2 "$@"',
36367
+ " fi",
36368
+ ' printf "%s\\n" "Deepline SDK CLI install is incomplete. Run \\`deepline update\\` to repair it." >&2',
36369
+ " exit 1",
36370
+ "fi",
36371
+ `if ! ${shellQuote4(input2.nodeBin)} -e ${shellQuote4(esbuildProbe)} ${shellQuote4(versionDir)} >/dev/null 2>&1; then`,
36372
+ ' if [ -n "${DEEPLINE_REAL_BINARY:-}" ] && [ -x "$DEEPLINE_REAL_BINARY" ]; then',
36373
+ ' exec "$DEEPLINE_REAL_BINARY" --version=v2 "$@"',
36374
+ " fi",
36375
+ ' printf "%s\\n" "Deepline SDK CLI install is incomplete. Run \\`deepline update\\` to repair it." >&2',
36376
+ " exit 1",
36377
+ "fi",
36097
36378
  `exec ${shellQuote4(input2.nodeBin)} ${shellQuote4(input2.entryPath)} "$@"`,
36098
36379
  ""
36099
36380
  ].join("\n"),
@@ -36101,17 +36382,17 @@ function writeSidecarLauncher(input2) {
36101
36382
  );
36102
36383
  }
36103
36384
  async function runPythonSidecarUpdatePlan(plan) {
36104
- const versionsDir = (0, import_node_path22.join)(plan.stateDir, "versions");
36105
- const tempDir = (0, import_node_path22.join)(
36385
+ const versionsDir = (0, import_node_path23.join)(plan.stateDir, "versions");
36386
+ const tempDir = (0, import_node_path23.join)(
36106
36387
  versionsDir,
36107
36388
  `.tmp-sdk-update-${process.pid}-${Date.now()}`
36108
36389
  );
36109
- (0, import_node_fs19.rmSync)(tempDir, { recursive: true, force: true });
36110
- (0, import_node_fs19.mkdirSync)(tempDir, { recursive: true });
36111
- (0, import_node_fs19.writeFileSync)((0, import_node_path22.join)(tempDir, "package.json"), NPM_SDK_SIDECAR_PACKAGE_JSON);
36390
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36391
+ (0, import_node_fs20.mkdirSync)(tempDir, { recursive: true });
36392
+ (0, import_node_fs20.writeFileSync)((0, import_node_path23.join)(tempDir, "package.json"), NPM_SDK_SIDECAR_PACKAGE_JSON);
36112
36393
  const env = {
36113
36394
  ...process.env,
36114
- PATH: `${(0, import_node_path22.dirname)(plan.nodeBin)}${process.platform === "win32" ? ";" : ":"}${process.env.PATH ?? ""}`
36395
+ PATH: `${(0, import_node_path23.dirname)(plan.nodeBin)}${process.platform === "win32" ? ";" : ":"}${process.env.PATH ?? ""}`
36115
36396
  };
36116
36397
  const installResult = await runCommand(
36117
36398
  plan.npmCommand,
@@ -36128,7 +36409,7 @@ async function runPythonSidecarUpdatePlan(plan) {
36128
36409
  );
36129
36410
  const installExitCode = installResult.exitCode;
36130
36411
  if (installExitCode !== 0) {
36131
- (0, import_node_fs19.rmSync)(tempDir, { recursive: true, force: true });
36412
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36132
36413
  return installExitCode;
36133
36414
  }
36134
36415
  const installedVersion = installedPackageVersion(tempDir);
@@ -36136,33 +36417,94 @@ async function runPythonSidecarUpdatePlan(plan) {
36136
36417
  process.stderr.write(
36137
36418
  "Updated Deepline SDK package did not report a version.\n"
36138
36419
  );
36139
- (0, import_node_fs19.rmSync)(tempDir, { recursive: true, force: true });
36420
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36421
+ return 1;
36422
+ }
36423
+ const stagedFailure = sidecarInstallFailure(tempDir);
36424
+ if (stagedFailure) {
36425
+ process.stderr.write(
36426
+ `Updated Deepline SDK package is incomplete: ${stagedFailure}.
36427
+ `
36428
+ );
36429
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36140
36430
  return 1;
36141
36431
  }
36142
- const finalDir = (0, import_node_path22.join)(versionsDir, installedVersion);
36432
+ const finalDir = (0, import_node_path23.join)(versionsDir, installedVersion);
36143
36433
  const finalEntryPath = entryPathInVersionDir(finalDir);
36144
- if ((0, import_node_fs19.existsSync)(finalEntryPath)) {
36145
- (0, import_node_fs19.rmSync)(tempDir, { recursive: true, force: true });
36434
+ const finalFailure = sidecarInstallFailure(finalDir);
36435
+ let backupDir = null;
36436
+ if (!finalFailure) {
36437
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36146
36438
  } else {
36147
- (0, import_node_fs19.rmSync)(finalDir, { recursive: true, force: true });
36148
- try {
36149
- (0, import_node_fs19.renameSync)(tempDir, finalDir);
36150
- } catch (error) {
36151
- (0, import_node_fs19.rmSync)(tempDir, { recursive: true, force: true });
36152
- process.stderr.write(
36153
- `Failed to publish Deepline SDK sidecar update: ${error.message}
36154
- `
36439
+ let shouldPublishTemp = true;
36440
+ if ((0, import_node_fs20.existsSync)(finalDir)) {
36441
+ backupDir = (0, import_node_path23.join)(
36442
+ versionsDir,
36443
+ `.backup-${installedVersion}-${process.pid}-${Date.now()}`
36155
36444
  );
36156
- return 1;
36445
+ try {
36446
+ (0, import_node_fs20.renameSync)(finalDir, backupDir);
36447
+ } catch (error) {
36448
+ const concurrentlyPublishedFailure = sidecarInstallFailure(finalDir);
36449
+ if (!concurrentlyPublishedFailure) {
36450
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36451
+ backupDir = null;
36452
+ shouldPublishTemp = false;
36453
+ } else {
36454
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36455
+ process.stderr.write(
36456
+ `Failed to preserve the incomplete Deepline SDK sidecar before repair: ${error.message}.
36457
+ `
36458
+ );
36459
+ return 1;
36460
+ }
36461
+ }
36462
+ }
36463
+ if (shouldPublishTemp) {
36464
+ try {
36465
+ (0, import_node_fs20.renameSync)(tempDir, finalDir);
36466
+ } catch (error) {
36467
+ (0, import_node_fs20.rmSync)(tempDir, { recursive: true, force: true });
36468
+ const concurrentlyPublishedFailure = sidecarInstallFailure(finalDir);
36469
+ if (!concurrentlyPublishedFailure) {
36470
+ if (backupDir) (0, import_node_fs20.rmSync)(backupDir, { recursive: true, force: true });
36471
+ backupDir = null;
36472
+ } else {
36473
+ let restoreFailure = "";
36474
+ if (backupDir && (0, import_node_fs20.existsSync)(backupDir) && !(0, import_node_fs20.existsSync)(finalDir)) {
36475
+ try {
36476
+ (0, import_node_fs20.renameSync)(backupDir, finalDir);
36477
+ backupDir = null;
36478
+ } catch (restoreError) {
36479
+ restoreFailure = `; failed to restore previous install: ${restoreError.message}`;
36480
+ }
36481
+ }
36482
+ process.stderr.write(
36483
+ `Failed to publish Deepline SDK sidecar update: ${error.message}; current install remains incomplete: ${concurrentlyPublishedFailure}${restoreFailure}.
36484
+ `
36485
+ );
36486
+ return 1;
36487
+ }
36488
+ }
36157
36489
  }
36158
36490
  }
36159
- if (!(0, import_node_fs19.existsSync)(finalEntryPath)) {
36491
+ const publishedFailure = sidecarStructureFailure(finalDir);
36492
+ if (publishedFailure) {
36493
+ if (backupDir && (0, import_node_fs20.existsSync)(backupDir)) {
36494
+ (0, import_node_fs20.rmSync)(finalDir, { recursive: true, force: true });
36495
+ try {
36496
+ (0, import_node_fs20.renameSync)(backupDir, finalDir);
36497
+ backupDir = null;
36498
+ } catch {
36499
+ }
36500
+ }
36160
36501
  process.stderr.write(
36161
- `Updated Deepline SDK CLI entrypoint missing: ${finalEntryPath}
36502
+ `Updated Deepline SDK CLI install is incomplete: ${publishedFailure}.
36162
36503
  `
36163
36504
  );
36164
36505
  return 1;
36165
36506
  }
36507
+ if (backupDir) (0, import_node_fs20.rmSync)(backupDir, { recursive: true, force: true });
36166
36508
  writeSidecarLauncher({
36167
36509
  path: plan.sidecarPath,
36168
36510
  hostUrl: plan.hostUrl,
@@ -36170,28 +36512,28 @@ async function runPythonSidecarUpdatePlan(plan) {
36170
36512
  nodeBin: plan.nodeBin,
36171
36513
  entryPath: finalEntryPath
36172
36514
  });
36173
- (0, import_node_fs19.writeFileSync)(
36174
- (0, import_node_path22.join)(plan.stateDir, ".version"),
36515
+ (0, import_node_fs20.writeFileSync)(
36516
+ (0, import_node_path23.join)(plan.stateDir, ".version"),
36175
36517
  `${installedVersion}
36176
36518
  `,
36177
36519
  "utf8"
36178
36520
  );
36179
- (0, import_node_fs19.writeFileSync)(
36180
- (0, import_node_path22.join)(plan.stateDir, ".install-method"),
36521
+ (0, import_node_fs20.writeFileSync)(
36522
+ (0, import_node_path23.join)(plan.stateDir, ".install-method"),
36181
36523
  "python-sidecar\n",
36182
36524
  "utf8"
36183
36525
  );
36184
- (0, import_node_fs19.writeFileSync)(
36185
- (0, import_node_path22.join)(plan.stateDir, ".command-path"),
36526
+ (0, import_node_fs20.writeFileSync)(
36527
+ (0, import_node_path23.join)(plan.stateDir, ".command-path"),
36186
36528
  `${plan.sidecarPath}
36187
36529
  `,
36188
36530
  "utf8"
36189
36531
  );
36190
- (0, import_node_fs19.writeFileSync)((0, import_node_path22.join)(plan.stateDir, ".runner"), "node\n", "utf8");
36191
- (0, import_node_fs19.writeFileSync)((0, import_node_path22.join)(plan.stateDir, ".node-bin"), `${plan.nodeBin}
36532
+ (0, import_node_fs20.writeFileSync)((0, import_node_path23.join)(plan.stateDir, ".runner"), "node\n", "utf8");
36533
+ (0, import_node_fs20.writeFileSync)((0, import_node_path23.join)(plan.stateDir, ".node-bin"), `${plan.nodeBin}
36192
36534
  `, "utf8");
36193
- (0, import_node_fs19.writeFileSync)(
36194
- (0, import_node_path22.join)(plan.stateDir, ".entry-path"),
36535
+ (0, import_node_fs20.writeFileSync)(
36536
+ (0, import_node_path23.join)(plan.stateDir, ".entry-path"),
36195
36537
  `${finalEntryPath}
36196
36538
  `,
36197
36539
  "utf8"
@@ -36314,9 +36656,9 @@ Examples:
36314
36656
 
36315
36657
  // src/cli/commands/setup.ts
36316
36658
  var import_node_child_process4 = require("child_process");
36317
- var import_node_fs20 = require("fs");
36659
+ var import_node_fs21 = require("fs");
36318
36660
  var import_node_os17 = require("os");
36319
- var import_node_path23 = require("path");
36661
+ var import_node_path24 = require("path");
36320
36662
  var SETUP_PHASE_NAMES = [
36321
36663
  "cli",
36322
36664
  "cleanup",
@@ -36373,7 +36715,7 @@ function phasesFromLegacyStatus(status) {
36373
36715
  function readSetupState(input2) {
36374
36716
  try {
36375
36717
  const parsed = JSON.parse(
36376
- (0, import_node_fs20.readFileSync)(
36718
+ (0, import_node_fs21.readFileSync)(
36377
36719
  setupStatePath(input2.baseUrl, input2.scope, input2.root),
36378
36720
  "utf8"
36379
36721
  )
@@ -36449,7 +36791,7 @@ function buildPendingAuthorizationOutput(input2) {
36449
36791
  };
36450
36792
  }
36451
36793
  function setupStatePath(baseUrl, scope, root) {
36452
- return scope === "local" && root ? (0, import_node_path23.join)(root, ".deepline", "setup", "state.json") : (0, import_node_path23.join)(sdkCliStateDirPath(baseUrl), "setup.json");
36794
+ return scope === "local" && root ? (0, import_node_path24.join)(root, ".deepline", "setup", "state.json") : (0, import_node_path24.join)(sdkCliStateDirPath(baseUrl), "setup.json");
36453
36795
  }
36454
36796
  async function captureStdout2(run) {
36455
36797
  let stdout = "";
@@ -36478,14 +36820,14 @@ function asRecord3(value) {
36478
36820
  }
36479
36821
  function safeRead(path) {
36480
36822
  try {
36481
- return (0, import_node_fs20.readFileSync)(path, "utf8");
36823
+ return (0, import_node_fs21.readFileSync)(path, "utf8");
36482
36824
  } catch {
36483
36825
  return "";
36484
36826
  }
36485
36827
  }
36486
36828
  function isNpmManagedDeeplinePath(path) {
36487
36829
  try {
36488
- return (0, import_node_fs20.realpathSync)(path).includes(`${(0, import_node_path23.join)("node_modules", "deepline")}`);
36830
+ return (0, import_node_fs21.realpathSync)(path).includes(`${(0, import_node_path24.join)("node_modules", "deepline")}`);
36489
36831
  } catch {
36490
36832
  return false;
36491
36833
  }
@@ -36496,32 +36838,32 @@ function isInstallerManagedLegacyLauncher(path) {
36496
36838
  }
36497
36839
  function removeKnownLegacyPaths(baseUrl) {
36498
36840
  const home = (0, import_node_os17.homedir)();
36499
- const hostDir = (0, import_node_path23.join)(home, ".local", "deepline", baseUrlSlug(baseUrl));
36500
- const legacyLauncherPath = (0, import_node_path23.join)(home, ".local", "bin", "deepline");
36841
+ const hostDir = (0, import_node_path24.join)(home, ".local", "deepline", baseUrlSlug(baseUrl));
36842
+ const legacyLauncherPath = (0, import_node_path24.join)(home, ".local", "bin", "deepline");
36501
36843
  const installerCommandPath = safeRead(
36502
- (0, import_node_path23.join)(hostDir, "sdk", ".command-path")
36844
+ (0, import_node_path24.join)(hostDir, "sdk", ".command-path")
36503
36845
  ).trim();
36504
36846
  const candidates = [
36505
36847
  ...isInstallerManagedLegacyLauncher(legacyLauncherPath) ? [legacyLauncherPath] : [],
36506
- (0, import_node_path23.join)(home, ".local", "bin", "deepline-real"),
36507
- (0, import_node_path23.join)(hostDir, "bin", "deepline"),
36508
- (0, import_node_path23.join)(hostDir, "bin", "deepline-real"),
36509
- (0, import_node_path23.join)(hostDir, "cli", ".install-method"),
36510
- (0, import_node_path23.join)(hostDir, "cli", ".version"),
36511
- (0, import_node_path23.join)(hostDir, "sdk", ".install-method"),
36512
- (0, import_node_path23.join)(hostDir, "sdk", ".command-path"),
36848
+ (0, import_node_path24.join)(home, ".local", "bin", "deepline-real"),
36849
+ (0, import_node_path24.join)(hostDir, "bin", "deepline"),
36850
+ (0, import_node_path24.join)(hostDir, "bin", "deepline-real"),
36851
+ (0, import_node_path24.join)(hostDir, "cli", ".install-method"),
36852
+ (0, import_node_path24.join)(hostDir, "cli", ".version"),
36853
+ (0, import_node_path24.join)(hostDir, "sdk", ".install-method"),
36854
+ (0, import_node_path24.join)(hostDir, "sdk", ".command-path"),
36513
36855
  ...installerCommandPath ? [
36514
36856
  installerCommandPath,
36515
- (0, import_node_path23.join)((0, import_node_path23.dirname)(installerCommandPath), "deepline-sdk")
36857
+ (0, import_node_path24.join)((0, import_node_path24.dirname)(installerCommandPath), "deepline-sdk")
36516
36858
  ] : []
36517
36859
  ];
36518
36860
  const removed = [];
36519
36861
  for (const path of candidates) {
36520
- if (!(0, import_node_fs20.existsSync)(path)) continue;
36862
+ if (!(0, import_node_fs21.existsSync)(path)) continue;
36521
36863
  if (path === installerCommandPath && isNpmManagedDeeplinePath(path)) {
36522
36864
  continue;
36523
36865
  }
36524
- (0, import_node_fs20.rmSync)(path, { force: true });
36866
+ (0, import_node_fs21.rmSync)(path, { force: true });
36525
36867
  removed.push(path);
36526
36868
  }
36527
36869
  return removed;
@@ -36534,7 +36876,7 @@ function resolvePathCommands(command) {
36534
36876
  );
36535
36877
  return [
36536
36878
  ...new Set(
36537
- String(lookup.stdout ?? "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((path) => (0, import_node_path23.resolve)(path))
36879
+ String(lookup.stdout ?? "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((path) => (0, import_node_path24.resolve)(path))
36538
36880
  )
36539
36881
  ];
36540
36882
  }
@@ -36544,7 +36886,7 @@ function resolvePathCommand(command) {
36544
36886
  function isHomebrewFormulaCommand(path) {
36545
36887
  let resolvedPath = path;
36546
36888
  try {
36547
- resolvedPath = (0, import_node_fs20.realpathSync)(path);
36889
+ resolvedPath = (0, import_node_fs21.realpathSync)(path);
36548
36890
  } catch {
36549
36891
  return false;
36550
36892
  }
@@ -36555,7 +36897,7 @@ function isHomebrewFormulaCommand(path) {
36555
36897
  function resolvePersistentGlobalCommand(dependencies = {}) {
36556
36898
  const platform3 = dependencies.platform ?? process.platform;
36557
36899
  const run = dependencies.spawn ?? import_node_child_process4.spawnSync;
36558
- const pathExists = dependencies.exists ?? import_node_fs20.existsSync;
36900
+ const pathExists = dependencies.exists ?? import_node_fs21.existsSync;
36559
36901
  const pathClis = dependencies.pathClis ?? resolvePathCommands("deepline");
36560
36902
  const homebrewCommand = pathClis.find(isHomebrewFormulaCommand);
36561
36903
  if (homebrewCommand) return homebrewCommand;
@@ -36567,7 +36909,7 @@ function resolvePersistentGlobalCommand(dependencies = {}) {
36567
36909
  if (prefix.status !== 0) return null;
36568
36910
  const root = String(prefix.stdout ?? "").trim();
36569
36911
  if (!root) return null;
36570
- const candidates = platform3 === "win32" ? [(0, import_node_path23.join)(root, "deepline.cmd"), (0, import_node_path23.join)(root, "deepline")] : [(0, import_node_path23.join)(root, "bin", "deepline")];
36912
+ const candidates = platform3 === "win32" ? [(0, import_node_path24.join)(root, "deepline.cmd"), (0, import_node_path24.join)(root, "deepline")] : [(0, import_node_path24.join)(root, "bin", "deepline")];
36571
36913
  return candidates.find((candidate) => pathExists(candidate)) ?? null;
36572
36914
  }
36573
36915
  function inspectGlobalCliAvailability(input2) {
@@ -36580,20 +36922,20 @@ function inspectGlobalCliAvailability(input2) {
36580
36922
  }
36581
36923
  function pathsResolveToSameFile(left, right) {
36582
36924
  try {
36583
- return (0, import_node_fs20.realpathSync)(left) === (0, import_node_fs20.realpathSync)(right);
36925
+ return (0, import_node_fs21.realpathSync)(left) === (0, import_node_fs21.realpathSync)(right);
36584
36926
  } catch {
36585
- return (0, import_node_path23.resolve)(left) === (0, import_node_path23.resolve)(right);
36927
+ return (0, import_node_path24.resolve)(left) === (0, import_node_path24.resolve)(right);
36586
36928
  }
36587
36929
  }
36588
36930
  function isKnownDeeplineCommand(path) {
36589
- const entrypoint = process.argv[1] ? (0, import_node_path23.resolve)(process.argv[1]) : "";
36931
+ const entrypoint = process.argv[1] ? (0, import_node_path24.resolve)(process.argv[1]) : "";
36590
36932
  let resolvedPath = path;
36591
36933
  try {
36592
- resolvedPath = (0, import_node_fs20.realpathSync)(path);
36934
+ resolvedPath = (0, import_node_fs21.realpathSync)(path);
36593
36935
  } catch {
36594
36936
  }
36595
36937
  if (entrypoint && resolvedPath === entrypoint) return true;
36596
- if (resolvedPath.includes(`${(0, import_node_path23.join)("node_modules", "deepline")}`)) return true;
36938
+ if (resolvedPath.includes(`${(0, import_node_path24.join)("node_modules", "deepline")}`)) return true;
36597
36939
  const content = safeRead(path);
36598
36940
  return content.includes("node_modules/deepline") || content.includes("node_modules\\deepline") || content.includes("DEEPLINE_CONFIG_SCOPE") || content.includes("deepline-real");
36599
36941
  }
@@ -36601,9 +36943,9 @@ function inspectPathConflict() {
36601
36943
  const commandPath = resolvePathCommand("deepline");
36602
36944
  if (!commandPath || isKnownDeeplineCommand(commandPath)) return null;
36603
36945
  try {
36604
- if ((0, import_node_fs20.lstatSync)(commandPath).isSymbolicLink()) {
36605
- const target = (0, import_node_fs20.realpathSync)(commandPath);
36606
- if (target.includes(`${(0, import_node_path23.join)("node_modules", "deepline")}`)) return null;
36946
+ if ((0, import_node_fs21.lstatSync)(commandPath).isSymbolicLink()) {
36947
+ const target = (0, import_node_fs21.realpathSync)(commandPath);
36948
+ if (target.includes(`${(0, import_node_path24.join)("node_modules", "deepline")}`)) return null;
36607
36949
  }
36608
36950
  } catch {
36609
36951
  }
@@ -36611,8 +36953,8 @@ function inspectPathConflict() {
36611
36953
  }
36612
36954
  function writeSetupState(input2) {
36613
36955
  const path = setupStatePath(input2.baseUrl, input2.scope, input2.root);
36614
- (0, import_node_fs20.mkdirSync)((0, import_node_path23.dirname)(path), { recursive: true });
36615
- (0, import_node_fs20.writeFileSync)(
36956
+ (0, import_node_fs21.mkdirSync)((0, import_node_path24.dirname)(path), { recursive: true });
36957
+ (0, import_node_fs21.writeFileSync)(
36616
36958
  path,
36617
36959
  `${JSON.stringify(
36618
36960
  {
@@ -36652,7 +36994,7 @@ function failSetupPhase(phases, phase, code) {
36652
36994
  phases[phase] = { status: "failed", code };
36653
36995
  }
36654
36996
  function rollbackCommand(scope, root) {
36655
- const prefix = scope === "local" && root ? ` --prefix ${JSON.stringify((0, import_node_path23.join)(root, ".deepline", "runtime"))}` : "";
36997
+ const prefix = scope === "local" && root ? ` --prefix ${JSON.stringify((0, import_node_path24.join)(root, ".deepline", "runtime"))}` : "";
36656
36998
  return `npm install -g${prefix} --no-audit --no-fund --include=optional --allow-scripts=esbuild deepline@${SDK_VERSION}`;
36657
36999
  }
36658
37000
  function setupResumeCommand(baseUrl, scope) {
@@ -36739,12 +37081,12 @@ function buildDoctorAssessment(input2) {
36739
37081
  const connected = input2.authStatus.payload?.connected === true;
36740
37082
  const authScopeOk = input2.scope === "local" ? Boolean(projectAuth) : Boolean(apiKey && !projectAuth);
36741
37083
  const skillsOk = skillsState?.scope === input2.scope && typeof skillsState.skillsVersion === "string" && Array.isArray(skillsState.agents) && skillsState.agents.length > 0;
36742
- const runningCliPath = process.argv[1] ? (0, import_node_path23.resolve)(process.argv[1]) : null;
37084
+ const runningCliPath = process.argv[1] ? (0, import_node_path24.resolve)(process.argv[1]) : null;
36743
37085
  const globalCli = input2.scope === "global" ? inspectGlobalCliAvailability() : null;
36744
37086
  const pathGlobalCli = globalCli?.path ?? null;
36745
37087
  const cliPath = input2.scope === "global" ? pathGlobalCli : runningCliPath;
36746
37088
  const cliScopeOk = input2.scope === "global" ? Boolean(pathGlobalCli) : Boolean(
36747
- input2.root && runningCliPath?.includes((0, import_node_path23.join)(input2.root, ".deepline", "runtime"))
37089
+ input2.root && runningCliPath?.includes((0, import_node_path24.join)(input2.root, ".deepline", "runtime"))
36748
37090
  );
36749
37091
  const checks = {
36750
37092
  cli: {
@@ -37390,7 +37732,7 @@ function isDowngradeAutoUpdateResponse(response) {
37390
37732
  return compareSemver(target, current) < 0;
37391
37733
  }
37392
37734
  function relaunchCurrentCommand(plan) {
37393
- return new Promise((resolve18) => {
37735
+ return new Promise((resolve19) => {
37394
37736
  const command = plan.kind === "python-sidecar" ? plan.sidecarPath : process.execPath;
37395
37737
  const args = plan.kind === "python-sidecar" ? process.argv.slice(2) : process.argv.slice(1);
37396
37738
  const child = (0, import_node_child_process5.spawn)(command, args, {
@@ -37406,9 +37748,9 @@ function relaunchCurrentCommand(plan) {
37406
37748
  `Deepline SDK/CLI updated, but relaunch failed: ${error.message}
37407
37749
  `
37408
37750
  );
37409
- resolve18(1);
37751
+ resolve19(1);
37410
37752
  });
37411
- child.on("close", (code) => resolve18(code ?? 1));
37753
+ child.on("close", (code) => resolve19(code ?? 1));
37412
37754
  });
37413
37755
  }
37414
37756
  async function maybeAutoUpdateAndRelaunch(response) {
@@ -37459,8 +37801,8 @@ async function maybeAutoUpdateAndRelaunch(response) {
37459
37801
 
37460
37802
  // src/cli/skills-sync.ts
37461
37803
  var import_node_child_process6 = require("child_process");
37462
- var import_node_fs21 = require("fs");
37463
- var import_node_path24 = require("path");
37804
+ var import_node_fs22 = require("fs");
37805
+ var import_node_path25 = require("path");
37464
37806
  var CHECK_TIMEOUT_MS2 = 3e3;
37465
37807
  var attemptedSync = false;
37466
37808
  function shouldSkipSkillsSync() {
@@ -37476,51 +37818,51 @@ function activePluginSkillsDir() {
37476
37818
  return "";
37477
37819
  }
37478
37820
  const dir = process.env.DEEPLINE_PLUGIN_SKILLS_DIR?.trim() ?? "";
37479
- return dir && (0, import_node_fs21.existsSync)(dir) ? dir : "";
37821
+ return dir && (0, import_node_fs22.existsSync)(dir) ? dir : "";
37480
37822
  }
37481
37823
  function readPluginSkillsVersion() {
37482
37824
  const dir = activePluginSkillsDir();
37483
37825
  if (!dir) return "";
37484
37826
  try {
37485
- return (0, import_node_fs21.readFileSync)((0, import_node_path24.join)(dir, ".version"), "utf-8").trim();
37827
+ return (0, import_node_fs22.readFileSync)((0, import_node_path25.join)(dir, ".version"), "utf-8").trim();
37486
37828
  } catch {
37487
37829
  return "";
37488
37830
  }
37489
37831
  }
37490
37832
  function sdkSkillsVersionPath(baseUrl) {
37491
- return (0, import_node_path24.join)(sdkCliStateDirPath(baseUrl), "skills-version");
37833
+ return (0, import_node_path25.join)(sdkCliStateDirPath(baseUrl), "skills-version");
37492
37834
  }
37493
37835
  function legacySdkSkillsVersionPath(baseUrl) {
37494
- return (0, import_node_path24.join)((0, import_node_path24.dirname)(sdkCliStateDirPath(baseUrl)), "sdk-skills", ".version");
37836
+ return (0, import_node_path25.join)((0, import_node_path25.dirname)(sdkCliStateDirPath(baseUrl)), "sdk-skills", ".version");
37495
37837
  }
37496
37838
  function unavailableSkillsNoticePath(baseUrl) {
37497
- return (0, import_node_path24.join)(sdkCliStateDirPath(baseUrl), "skills-sync-unavailable-version");
37839
+ return (0, import_node_path25.join)(sdkCliStateDirPath(baseUrl), "skills-sync-unavailable-version");
37498
37840
  }
37499
37841
  function readSdkSkillsLocalVersion(baseUrl) {
37500
37842
  const pluginVersion = readPluginSkillsVersion();
37501
37843
  if (pluginVersion) return pluginVersion;
37502
- const path = (0, import_node_fs21.existsSync)(sdkSkillsVersionPath(baseUrl)) ? sdkSkillsVersionPath(baseUrl) : legacySdkSkillsVersionPath(baseUrl);
37503
- if (!(0, import_node_fs21.existsSync)(path)) return "";
37844
+ const path = (0, import_node_fs22.existsSync)(sdkSkillsVersionPath(baseUrl)) ? sdkSkillsVersionPath(baseUrl) : legacySdkSkillsVersionPath(baseUrl);
37845
+ if (!(0, import_node_fs22.existsSync)(path)) return "";
37504
37846
  try {
37505
- return (0, import_node_fs21.readFileSync)(path, "utf-8").trim();
37847
+ return (0, import_node_fs22.readFileSync)(path, "utf-8").trim();
37506
37848
  } catch {
37507
37849
  return "";
37508
37850
  }
37509
37851
  }
37510
37852
  function writeLocalSkillsVersion(baseUrl, version) {
37511
37853
  const path = sdkSkillsVersionPath(baseUrl);
37512
- (0, import_node_fs21.mkdirSync)((0, import_node_path24.dirname)(path), { recursive: true });
37513
- (0, import_node_fs21.writeFileSync)(path, `${version}
37854
+ (0, import_node_fs22.mkdirSync)((0, import_node_path25.dirname)(path), { recursive: true });
37855
+ (0, import_node_fs22.writeFileSync)(path, `${version}
37514
37856
  `, "utf-8");
37515
37857
  }
37516
37858
  function writeUnavailableSkillsNotice(baseUrl, remoteVersion, skillNames) {
37517
37859
  const path = unavailableSkillsNoticePath(baseUrl);
37518
37860
  try {
37519
- if ((0, import_node_fs21.existsSync)(path) && (0, import_node_fs21.readFileSync)(path, "utf-8").trim() === remoteVersion) {
37861
+ if ((0, import_node_fs22.existsSync)(path) && (0, import_node_fs22.readFileSync)(path, "utf-8").trim() === remoteVersion) {
37520
37862
  return;
37521
37863
  }
37522
- (0, import_node_fs21.mkdirSync)((0, import_node_path24.dirname)(path), { recursive: true });
37523
- (0, import_node_fs21.writeFileSync)(path, `${remoteVersion}
37864
+ (0, import_node_fs22.mkdirSync)((0, import_node_path25.dirname)(path), { recursive: true });
37865
+ (0, import_node_fs22.writeFileSync)(path, `${remoteVersion}
37524
37866
  `, "utf-8");
37525
37867
  } catch {
37526
37868
  }
@@ -37532,7 +37874,7 @@ ${manualCommand}`
37532
37874
  }
37533
37875
  function clearUnavailableSkillsNotice(baseUrl) {
37534
37876
  try {
37535
- (0, import_node_fs21.unlinkSync)(unavailableSkillsNoticePath(baseUrl));
37877
+ (0, import_node_fs22.unlinkSync)(unavailableSkillsNoticePath(baseUrl));
37536
37878
  } catch {
37537
37879
  }
37538
37880
  }
@@ -37654,7 +37996,7 @@ function resolveSkillsInstallCommands(baseUrl, skillNames = DEFAULT_SDK_SKILL_NA
37654
37996
  return commands;
37655
37997
  }
37656
37998
  function runOneSkillsInstall(install) {
37657
- return new Promise((resolve18) => {
37999
+ return new Promise((resolve19) => {
37658
38000
  const plan = resolveSkillsInstallSpawn(install);
37659
38001
  const child = (0, import_node_child_process6.spawn)(plan.command, plan.args, {
37660
38002
  stdio: ["ignore", "ignore", "pipe"],
@@ -37666,7 +38008,7 @@ function runOneSkillsInstall(install) {
37666
38008
  stderr += chunk.toString("utf-8");
37667
38009
  });
37668
38010
  child.on("error", (error) => {
37669
- resolve18({
38011
+ resolve19({
37670
38012
  ok: false,
37671
38013
  detail: `failed to start ${install.command}: ${error.message}`,
37672
38014
  manualCommand: install.manualCommand
@@ -37674,11 +38016,11 @@ function runOneSkillsInstall(install) {
37674
38016
  });
37675
38017
  child.on("close", (code) => {
37676
38018
  if (code === 0) {
37677
- resolve18({ ok: true, detail: "", manualCommand: install.manualCommand });
38019
+ resolve19({ ok: true, detail: "", manualCommand: install.manualCommand });
37678
38020
  return;
37679
38021
  }
37680
38022
  const detail = stderr.trim();
37681
- resolve18({
38023
+ resolve19({
37682
38024
  ok: false,
37683
38025
  detail: detail ? `${install.command}: ${detail}` : `${install.command} exited ${code}`,
37684
38026
  manualCommand: install.manualCommand
@@ -38106,8 +38448,8 @@ function topLevelCommandKnown(program, commandName) {
38106
38448
  );
38107
38449
  }
38108
38450
  async function runPlayRunnerHealthCheck() {
38109
- const dir = await (0, import_promises8.mkdtemp)((0, import_node_path25.join)((0, import_node_os19.tmpdir)(), "deepline-health-play-"));
38110
- const file = (0, import_node_path25.join)(dir, "health-check.play.ts");
38451
+ const dir = await (0, import_promises8.mkdtemp)((0, import_node_path26.join)((0, import_node_os19.tmpdir)(), "deepline-health-play-"));
38452
+ const file = (0, import_node_path26.join)(dir, "health-check.play.ts");
38111
38453
  try {
38112
38454
  await (0, import_promises8.writeFile)(
38113
38455
  file,