sim 2.1.18-dev.129.1 → 2.1.18-dev.131.1

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.
@@ -17,7 +17,7 @@ export declare function streamToFile(body: ReadableStream<Uint8Array>, file: Wri
17
17
  */
18
18
  export declare function removeStagingOnSignal(stagingDirectory: () => string | null, terminate?: (signal: NodeJS.Signals) => void): () => void;
19
19
  /** Publishes a complete staged body atomically, with overwrite requiring explicit force. */
20
- export declare function saveToFile(body: ReadableStream<Uint8Array>, target: string, force: boolean): Promise<void>;
20
+ export declare function saveToFile(body: ReadableStream<Uint8Array>, target: string, force: boolean): Promise<string>;
21
21
  /** Streams a fetch body to stdout without closing the process-wide stream. */
22
22
  export declare function streamToStdout(body: ReadableStream<Uint8Array>, output?: NodeJS.WriteStream): Promise<void>;
23
23
  /** Returns whether content can be written directly to an interactive terminal. */
@@ -30,6 +30,8 @@ export interface EmbeddedFileSnapshot {
30
30
  }
31
31
  export interface EmbedContext {
32
32
  identity: EmbeddedCliIdentity;
33
+ /** Absolute caller filesystem working directory; never inherited from the embedding server. */
34
+ workingDirectory?: string;
33
35
  stdout: EmbeddedOutput;
34
36
  stderr: EmbeddedOutput;
35
37
  /**
package/dist/embed.d.ts CHANGED
@@ -14,7 +14,7 @@ import { SimClient } from './http/client';
14
14
  */
15
15
  export type { EmbeddedCliIdentity, EmbeddedFileSnapshot } from './embed-context';
16
16
  export type { ExportWorkflowResponse, ListFilesResponse, ListWorkflowsResponse, ReadFileTextResponse, } from './generated/v2-api';
17
- export { SimClient } from './http/client';
17
+ export { SimApiError, SimClient } from './http/client';
18
18
  export interface EmbeddedCliResult {
19
19
  exitCode: number;
20
20
  stdout: string;
@@ -33,6 +33,7 @@ export declare function createEmbeddedClient(identity: EmbeddedCliIdentity): Sim
33
33
  * stderr, exitCode 1 — never thrown.
34
34
  */
35
35
  export declare function runEmbeddedCli(argv: string[], identity: EmbeddedCliIdentity, options?: {
36
+ workingDirectory?: string;
36
37
  readFile?: EmbedContext['readFile'];
37
38
  openFile?: EmbedContext['openFile'];
38
39
  writeFile?: EmbedContext['writeFile'];
package/dist/index.js CHANGED
@@ -19505,7 +19505,7 @@ Examples:
19505
19505
  import { once as once2 } from "node:events";
19506
19506
  import { createWriteStream, rmSync as rmSync2 } from "node:fs";
19507
19507
  import { link, lstat, mkdtemp, readlink, rename, rm } from "node:fs/promises";
19508
- import { dirname as dirname4, join as join3, resolve as resolve2 } from "node:path";
19508
+ import { dirname as dirname4, join as join3, posix, resolve as resolve2 } from "node:path";
19509
19509
  import { Readable } from "node:stream";
19510
19510
  import { pipeline } from "node:stream/promises";
19511
19511
  function writeFailure(path, error) {
@@ -19624,6 +19624,11 @@ async function saveToFile(body, target, force) {
19624
19624
  const embedded = embedStore.getStore();
19625
19625
  if (embedded) {
19626
19626
  try {
19627
+ if (embedded.workingDirectory) {
19628
+ if (!posix.isAbsolute(embedded.workingDirectory))
19629
+ throw new SimApiError("The caller working directory must be absolute.", 0);
19630
+ target = posix.resolve(embedded.workingDirectory, target);
19631
+ }
19627
19632
  embedded.identity.signal?.throwIfAborted();
19628
19633
  if (!embedded.writeFile) {
19629
19634
  throw new SimApiError(`--output-file cannot save ${target} here: this surface has no machine to write to. Read the file instead, or use a client with filesystem access to download it.`, 0);
@@ -19633,9 +19638,11 @@ async function saveToFile(body, target, force) {
19633
19638
  } finally {
19634
19639
  await body.cancel().catch(() => {});
19635
19640
  }
19636
- return;
19641
+ return target;
19637
19642
  }
19638
- return saveStagedFile(body, target, force);
19643
+ target = resolve2(target);
19644
+ await saveStagedFile(body, target, force);
19645
+ return target;
19639
19646
  }
19640
19647
  async function streamToStdout(body, output) {
19641
19648
  const reader = body.getReader();
@@ -19698,8 +19705,7 @@ function attachFileGet(files) {
19698
19705
  await streamToStdout(response.body);
19699
19706
  return;
19700
19707
  }
19701
- const target = options.outputFile;
19702
- await saveToFile(response.body, target, Boolean(options.force));
19708
+ const target = await saveToFile(response.body, options.outputFile, Boolean(options.force));
19703
19709
  printProtocolResult(profile.output, {
19704
19710
  id: fileId,
19705
19711
  path: target,
@@ -19996,7 +20002,7 @@ function attachKnowledgeDocumentUpload(documents) {
19996
20002
  }
19997
20003
 
19998
20004
  // src/commands/protocol/knowledge-export.ts
19999
- import { basename as basename2, join as join4 } from "node:path";
20005
+ import { basename as basename2 } from "node:path";
20000
20006
  function attachmentFileName(contentDisposition) {
20001
20007
  if (!contentDisposition)
20002
20008
  return null;
@@ -20031,15 +20037,15 @@ function attachKnowledgeExport(knowledge) {
20031
20037
  }
20032
20038
  if (writesToStdout) {
20033
20039
  const contentType = response.headers.get("content-type");
20034
- if (process.stdout.isTTY && !isTerminalSafeContentType(contentType)) {
20040
+ const embedded = embedStore.getStore();
20041
+ if ((embedded || process.stdout.isTTY) && !isTerminalSafeContentType(contentType)) {
20035
20042
  await response.body.cancel();
20036
- throw new SimApiError(`Refusing to write ${contentType ?? "unknown content"} to an interactive terminal. Use --output-file <path> or pipe stdout.`, 0);
20043
+ throw new SimApiError(embedded ? `Refusing to put ${contentType ?? "unknown content"} in a text result. Use --output-file <path>.` : `Refusing to write ${contentType ?? "unknown content"} to an interactive terminal. Use --output-file <path> or pipe stdout.`, 0);
20037
20044
  }
20038
20045
  await streamToStdout(response.body);
20039
20046
  return;
20040
20047
  }
20041
- const target = options.outputFile ?? join4(process.cwd(), attachmentFileName(response.headers.get("content-disposition")) ?? `${knowledgeBaseId}.simkb.zip`);
20042
- await saveToFile(response.body, target, Boolean(options.force));
20048
+ const target = await saveToFile(response.body, options.outputFile ?? attachmentFileName(response.headers.get("content-disposition")) ?? `${knowledgeBaseId}.simkb.zip`, Boolean(options.force));
20043
20049
  printProtocolResult(profile.output, {
20044
20050
  id: knowledgeBaseId,
20045
20051
  path: target,
package/dist/runtime.js CHANGED
@@ -19556,7 +19556,7 @@ Examples:
19556
19556
  import { once as once2 } from "node:events";
19557
19557
  import { createWriteStream, rmSync as rmSync2 } from "node:fs";
19558
19558
  import { link, lstat, mkdtemp, readlink, rename, rm } from "node:fs/promises";
19559
- import { dirname as dirname4, join as join3, resolve as resolve2 } from "node:path";
19559
+ import { dirname as dirname4, join as join3, posix, resolve as resolve2 } from "node:path";
19560
19560
  import { Readable } from "node:stream";
19561
19561
  import { pipeline } from "node:stream/promises";
19562
19562
  function writeFailure(path, error) {
@@ -19675,6 +19675,11 @@ async function saveToFile(body, target, force) {
19675
19675
  const embedded = embedStore.getStore();
19676
19676
  if (embedded) {
19677
19677
  try {
19678
+ if (embedded.workingDirectory) {
19679
+ if (!posix.isAbsolute(embedded.workingDirectory))
19680
+ throw new SimApiError("The caller working directory must be absolute.", 0);
19681
+ target = posix.resolve(embedded.workingDirectory, target);
19682
+ }
19678
19683
  embedded.identity.signal?.throwIfAborted();
19679
19684
  if (!embedded.writeFile) {
19680
19685
  throw new SimApiError(`--output-file cannot save ${target} here: this surface has no machine to write to. Read the file instead, or use a client with filesystem access to download it.`, 0);
@@ -19684,9 +19689,11 @@ async function saveToFile(body, target, force) {
19684
19689
  } finally {
19685
19690
  await body.cancel().catch(() => {});
19686
19691
  }
19687
- return;
19692
+ return target;
19688
19693
  }
19689
- return saveStagedFile(body, target, force);
19694
+ target = resolve2(target);
19695
+ await saveStagedFile(body, target, force);
19696
+ return target;
19690
19697
  }
19691
19698
  async function streamToStdout(body, output) {
19692
19699
  const reader = body.getReader();
@@ -19749,8 +19756,7 @@ function attachFileGet(files) {
19749
19756
  await streamToStdout(response.body);
19750
19757
  return;
19751
19758
  }
19752
- const target = options.outputFile;
19753
- await saveToFile(response.body, target, Boolean(options.force));
19759
+ const target = await saveToFile(response.body, options.outputFile, Boolean(options.force));
19754
19760
  printProtocolResult(profile.output, {
19755
19761
  id: fileId,
19756
19762
  path: target,
@@ -20047,7 +20053,7 @@ function attachKnowledgeDocumentUpload(documents) {
20047
20053
  }
20048
20054
 
20049
20055
  // src/commands/protocol/knowledge-export.ts
20050
- import { basename as basename2, join as join4 } from "node:path";
20056
+ import { basename as basename2 } from "node:path";
20051
20057
  function attachmentFileName(contentDisposition) {
20052
20058
  if (!contentDisposition)
20053
20059
  return null;
@@ -20082,15 +20088,15 @@ function attachKnowledgeExport(knowledge) {
20082
20088
  }
20083
20089
  if (writesToStdout) {
20084
20090
  const contentType = response.headers.get("content-type");
20085
- if (process.stdout.isTTY && !isTerminalSafeContentType(contentType)) {
20091
+ const embedded = embedStore.getStore();
20092
+ if ((embedded || process.stdout.isTTY) && !isTerminalSafeContentType(contentType)) {
20086
20093
  await response.body.cancel();
20087
- throw new SimApiError(`Refusing to write ${contentType ?? "unknown content"} to an interactive terminal. Use --output-file <path> or pipe stdout.`, 0);
20094
+ throw new SimApiError(embedded ? `Refusing to put ${contentType ?? "unknown content"} in a text result. Use --output-file <path>.` : `Refusing to write ${contentType ?? "unknown content"} to an interactive terminal. Use --output-file <path> or pipe stdout.`, 0);
20088
20095
  }
20089
20096
  await streamToStdout(response.body);
20090
20097
  return;
20091
20098
  }
20092
- const target = options.outputFile ?? join4(process.cwd(), attachmentFileName(response.headers.get("content-disposition")) ?? `${knowledgeBaseId}.simkb.zip`);
20093
- await saveToFile(response.body, target, Boolean(options.force));
20099
+ const target = await saveToFile(response.body, options.outputFile ?? attachmentFileName(response.headers.get("content-disposition")) ?? `${knowledgeBaseId}.simkb.zip`, Boolean(options.force));
20094
20100
  printProtocolResult(profile.output, {
20095
20101
  id: knowledgeBaseId,
20096
20102
  path: target,
@@ -21689,6 +21695,7 @@ async function runEmbeddedCli(argv, identity, options) {
21689
21695
  const opener = options?.openFile;
21690
21696
  const ctx = {
21691
21697
  identity,
21698
+ ...options?.workingDirectory ? { workingDirectory: options.workingDirectory } : {},
21692
21699
  stdout: new EmbeddedOutput,
21693
21700
  stderr: new EmbeddedOutput,
21694
21701
  ...reader ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim",
3
- "version": "2.1.18-dev.129.1",
3
+ "version": "2.1.18-dev.131.1",
4
4
  "description": "Sim CLI - talk to the Sim API from your terminal",
5
5
  "type": "module",
6
6
  "imports": {