sim 2.2.33-preview.321.1 → 2.3.0-preview.323.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.
@@ -1,5 +1,11 @@
1
1
  The Sim CLI bundle includes the following third-party software.
2
2
 
3
+ @babel/parser
4
+ Copyright (C) 2012-2014 by various contributors (see AUTHORS)
5
+
6
+ @noble/hashes
7
+ Copyright (c) 2022 Paul Miller (https://paulmillr.com)
8
+
3
9
  chalk
4
10
  Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
5
11
 
@@ -22,6 +28,9 @@ retry
22
28
  Copyright (c) 2011 Tim Koschützki (tim@debuggable.com)
23
29
  Copyright (c) 2011 Felix Geisendörfer (felix@debuggable.com)
24
30
 
31
+ zod
32
+ Copyright (c) 2025 Colin McDonnell
33
+
25
34
  Each dependency above is licensed under the MIT License:
26
35
 
27
36
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -104,13 +104,19 @@ export interface WorkspaceSubmission {
104
104
  /** Files under a kind folder that are not sent: hidden names and unsupported characters. */
105
105
  ignored: string[];
106
106
  /**
107
- * Files under a workflow folder's `functions/` that neither its `workflow.ts` nor its lock names:
108
- * never sent, as a workflow directory's apply never sends them.
107
+ * Code files nothing names: under a workflow folder's `functions/`, one neither its `workflow.ts`
108
+ * nor its lock names, and a tool's code file its declaration does not name. Never sent, as a
109
+ * workflow directory's apply never sends them.
109
110
  */
110
111
  unnamed: string[];
111
112
  /** The blobs this read hashed or reused a recorded digest for, with their stats. */
112
113
  hashed: ReadonlyMap<string, StatDigest>;
113
114
  }
115
+ /** The tool a code file (`tools/<key>.js`) belongs to and its declaration path; `null` for any other path. */
116
+ export declare function toolOfCodeFile(path: string): {
117
+ key: string;
118
+ declaration: string;
119
+ } | null;
114
120
  /**
115
121
  * `submission` (read `whole`) as a read without `whole` sends it: its unchanged workflow folders
116
122
  * pruned for `workspaceId`, without walking, reading or hashing the directory again.
@@ -333,6 +333,11 @@ export interface CommandSpec {
333
333
  * column. Only meaningful when `columns` is absent.
334
334
  */
335
335
  expand?: string;
336
+ /**
337
+ * The record's keys are data, not field names, as in `workflows outline`'s blocks keyed by block
338
+ * id: the display formats print each key as sent rather than humanized, so it can be copied back.
339
+ */
340
+ dataKeys?: true;
336
341
  /**
337
342
  * The response IS a document, not a record to look at.
338
343
  *
@@ -148,6 +148,12 @@ export declare class SimClient {
148
148
  requestRaw(path: string, options?: RequestOptions): Promise<Response>;
149
149
  request<T>(path: string, options?: RequestOptions): Promise<T>;
150
150
  private send;
151
+ /**
152
+ * What to do about a credential the server refused, by where it came from: `sim login` replaces
153
+ * a stored login, but a key from `SIM_API_KEY` or `--api-key` overrides any login, so logging in
154
+ * again would change nothing.
155
+ */
156
+ private credentialRemedy;
151
157
  /**
152
158
  * Explains a redirect instead of following it, naming the endpoint to switch to.
153
159
  *
@@ -156,12 +162,6 @@ export declare class SimClient {
156
162
  * endpoint. A `Location` that is missing or unparseable still has to produce a
157
163
  * sentence — the redirect is the finding either way.
158
164
  */
159
- /**
160
- * What to do about a credential the server refused, by where it came from: `sim login` replaces
161
- * a stored login, but a key from `SIM_API_KEY` or `--api-key` overrides any login, so logging in
162
- * again would change nothing.
163
- */
164
- private credentialRemedy;
165
165
  private toRedirectError;
166
166
  }
167
167
  /**
package/dist/index.js CHANGED
@@ -35478,7 +35478,8 @@ var CLI_CONTRACT = {
35478
35478
  getWorkflowState: { command: "workflows state get" },
35479
35479
  getWorkflowOutline: {
35480
35480
  command: "workflows outline",
35481
- describe: "Show a workflow’s draft as a compact read-only outline"
35481
+ describe: "Show a workflow’s draft as a compact read-only outline",
35482
+ dataKeys: true
35482
35483
  },
35483
35484
  getWorkflowSource: {
35484
35485
  command: "workflows source get",
@@ -37244,6 +37245,12 @@ function inferHeader(key, format) {
37244
37245
  const trimmed = format === "duration" || format === "bytes" ? key.replace(/(?:Ms|Bytes)$/, "") : format === "bool" ? key.replace(/^is(?=[A-Z])/, "") : key;
37245
37246
  return humanizeKey(trimmed || key);
37246
37247
  }
37248
+ function inferredFields(record, dataKeys) {
37249
+ return Object.entries(record).map(([key, value]) => [
37250
+ dataKeys ? key : inferHeader(key, inferFormat(key, value)),
37251
+ inferredCell(key, value)
37252
+ ]);
37253
+ }
37247
37254
  function columnsFrom(specs) {
37248
37255
  return specs.map((spec) => ({
37249
37256
  header: spec.header,
@@ -37366,10 +37373,7 @@ function renderResult(operation, format, raw, spec, options = {}, envelope) {
37366
37373
  printList(format, data, spec.columns ? columnsFrom(spec.columns) : inferColumns(data, spec.expand));
37367
37374
  return;
37368
37375
  }
37369
- const fields = spec.fields ? fieldsFrom(data, spec.fields, options) : data && typeof data === "object" ? Object.entries(data).map(([key, value]) => [
37370
- inferHeader(key, inferFormat(key, value)),
37371
- inferredCell(key, value)
37372
- ]) : [];
37376
+ const fields = spec.fields ? fieldsFrom(data, spec.fields, options) : data && typeof data === "object" ? inferredFields(data, spec.dataKeys === true) : [];
37373
37377
  printRecord(format, fields, data);
37374
37378
  if (spec.expandedTrace && options.expandedTrace) {
37375
37379
  const traceSpans = at(data, "traceSpans");
@@ -55478,8 +55482,7 @@ export default workflow('Support', { description: 'Answers an order question.' }
55478
55482
  })
55479
55483
  ` };
55480
55484
  // ../workflow-sdk/src/codegen/workspace-text.generated.ts
55481
- var WORKSPACE_SDK_DTS = {
55482
- "credentials.d.ts": `/**
55485
+ var WORKSPACE_SDK_DTS = { "credentials.d.ts": `/**
55483
55486
  * Credential declarations: \`credentials.ts\` at the root of a workspace source directory names the
55484
55487
  * saved credentials its workflows use, each by the provider it is for. Never a token: connect one
55485
55488
  * with \`sim credentials connect <provider> --name "<display name>"\`.
@@ -55523,8 +55526,7 @@ export declare function defineCredentials<const T extends Record<string, Credent
55523
55526
  export type DeclaredCredentials<T> = {
55524
55527
  [K in keyof T]: T[K] extends { provider: infer P } ? { provider: P } : never
55525
55528
  }
55526
- `,
55527
- "deployment.d.ts": `/**
55529
+ `, "deployment.d.ts": `/**
55528
55530
  * Deployment declarations: \`deployments/<workflow key>.ts\` in a workspace source directory deploys
55529
55531
  * \`workflows/<workflow key>/\`, so its schedule, webhook, API and chat triggers run.
55530
55532
  *
@@ -55606,9 +55608,7 @@ export interface DeploymentDeclaration {
55606
55608
 
55607
55609
  /** Declares a workflow's deployment. Its default export is the whole file. */
55608
55610
  export declare function defineDeployment(deployment: DeploymentDeclaration): DeploymentDeclaration
55609
- `,
55610
- "file.d.ts": "/**\n * Workspace files need no declaration: every file under `files/` is one workspace file, at the\n * folder path and name it has there (`files/reports/q1.pdf` is `q1.pdf` in the `reports`\n * folder), synced by content hash. Each apply that changes a file's bytes records a new version\n * of it, so an earlier one can be restored in the Files tab. Files over 10 MB, or whose name no\n * directory can hold (a reserved character, or a path that differs only in letter case from\n * another file or folder), are left out of a get (listed in `.sim/skipped.json`) and never written\n * by an apply; a file the directory no longer holds is deleted only with `--allow-delete`.\n */\nexport {}\n",
55611
- "index.d.ts": `/**
55611
+ `, "file.d.ts": "/**\n * Workspace files need no declaration: every file under `files/` is one workspace file, at the\n * folder path and name it has there (`files/reports/q1.pdf` is `q1.pdf` in the `reports`\n * folder), synced by content hash. Each apply that changes a file's bytes records a new version\n * of it, so an earlier one can be restored in the Files tab. Files over 10 MB, or whose name no\n * directory can hold (a reserved character, or a path that differs only in letter case from\n * another file or folder), are left out of a get (listed in `.sim/skipped.json`) and never written\n * by an apply; a file the directory no longer holds is deleted only with `--allow-delete`.\n */\nexport {}\n", "index.d.ts": `/**
55612
55612
  * The workspace declaration SDK: \`import { … } from '@sim/workflow-sdk/workspace'\` in the
55613
55613
  * declaration files of a workspace source directory (\`tables/<key>.ts\`, …). Like the workflow
55614
55614
  * SDK, nothing here runs: the server reads each file statically.
@@ -55622,8 +55622,7 @@ export * from './secrets'
55622
55622
  export * from './skill'
55623
55623
  export * from './table'
55624
55624
  export * from './tool'
55625
- `,
55626
- "knowledge.d.ts": `/**
55625
+ `, "knowledge.d.ts": `/**
55627
55626
  * Knowledge base declarations: \`knowledge/<key>/knowledge.ts\` in a workspace source directory,
55628
55627
  * beside \`knowledge/<key>/docs/\`, which holds one file per document.
55629
55628
  *
@@ -55682,9 +55681,7 @@ export interface KnowledgeBaseDeclaration {
55682
55681
  export declare function defineKnowledgeBase(
55683
55682
  knowledgeBase: KnowledgeBaseDeclaration
55684
55683
  ): KnowledgeBaseDeclaration
55685
- `,
55686
- "mcp.d.ts": "/**\n * MCP server declarations: `mcp/<key>.ts` declares one server the workspace's agents call tools\n * on.\n *\n * ```ts\n * // @sim-sdk 1\n * import { defineMcpServer, env } from '@sim/workflow-sdk/workspace'\n *\n * export default defineMcpServer({\n * name: 'GitHub',\n * url: 'https://api.githubcopilot.com/mcp/',\n * headers: { Authorization: 'Bearer {{GITHUB_TOKEN}}', 'X-Team': env.GITHUB_TEAM },\n * })\n * ```\n *\n * A workflow names the server by its key and one of its tools by name:\n * `mcp('github').tool('create_issue')`. Secrets never sit in source: a credential header\n * (`Authorization`, `Cookie`, or a name with `key`, `token`, `secret`, `auth`, …) holds env\n * references (`env.NAME`, or `{{NAME}}` in its text after a scheme such as `Bearer`) or\n * `stored()`, which keeps the value the server holds. The server's id derives from its URL, so a\n * `url` with another host or path replaces the server; a new query string updates it in place.\n */\nimport type { EnvRef } from '@sim/workflow-sdk'\n\nexport { env, stored } from '@sim/workflow-sdk'\n\n/** A header value: text (`{{NAME}}` names an env variable), `env.NAME`, or `stored()`. */\nexport type McpHeaderValue = string | EnvRef\n\n/** How the server authenticates. */\nexport interface McpServerAuth {\n /** `headers` (the default) sends the declared headers; `oauth` signs in with an OAuth grant. */\n type: 'none' | 'headers' | 'oauth'\n /** A pre-registered OAuth client, for a server without dynamic client registration. */\n clientId?: string\n}\n\n/** An MCP server declaration. */\nexport interface McpServerDeclaration {\n /** The display name; the key when left out. */\n name?: string\n description?: string\n /** An `http://` or `https://` URL. A new host or path replaces the server; a new query does not. */\n url: string\n transport?: 'streamable-http'\n headers?: { [name: string]: McpHeaderValue }\n /** `{ type: 'headers' }` when left out. The OAuth client secret is set in the server settings. */\n auth?: McpServerAuth\n /** Milliseconds a request waits; 30000 when left out. */\n timeout?: number\n /** 3 when left out. */\n retries?: number\n /** `true` when left out. */\n enabled?: boolean\n}\n\n/** Declares an MCP server. Its default export is the whole file. */\nexport declare function defineMcpServer(server: McpServerDeclaration): McpServerDeclaration\n",
55687
- "secrets.d.ts": `/**
55684
+ `, "mcp.d.ts": "/**\n * MCP server declarations: `mcp/<key>.ts` declares one server the workspace's agents call tools\n * on.\n *\n * ```ts\n * // @sim-sdk 1\n * import { defineMcpServer, env } from '@sim/workflow-sdk/workspace'\n *\n * export default defineMcpServer({\n * name: 'GitHub',\n * url: 'https://api.githubcopilot.com/mcp/',\n * headers: { Authorization: 'Bearer {{GITHUB_TOKEN}}', 'X-Team': env.GITHUB_TEAM },\n * })\n * ```\n *\n * A workflow names the server by its key and one of its tools by name:\n * `mcp('github').tool('create_issue')`. Secrets never sit in source: a credential header\n * (`Authorization`, `Cookie`, or a name with `key`, `token`, `secret`, `auth`, …) holds env\n * references (`env.NAME`, or `{{NAME}}` in its text after a scheme such as `Bearer`) or\n * `stored()`, which keeps the value the server holds. The server's id derives from its URL, so a\n * `url` with another host or path replaces the server; a new query string updates it in place.\n */\nimport type { EnvRef } from '@sim/workflow-sdk'\n\nexport { env, stored } from '@sim/workflow-sdk'\n\n/** A header value: text (`{{NAME}}` names an env variable), `env.NAME`, or `stored()`. */\nexport type McpHeaderValue = string | EnvRef\n\n/** How the server authenticates. */\nexport interface McpServerAuth {\n /** `headers` (the default) sends the declared headers; `oauth` signs in with an OAuth grant. */\n type: 'none' | 'headers' | 'oauth'\n /** A pre-registered OAuth client, for a server without dynamic client registration. */\n clientId?: string\n}\n\n/** An MCP server declaration. */\nexport interface McpServerDeclaration {\n /** The display name; the key when left out. */\n name?: string\n description?: string\n /** An `http://` or `https://` URL. A new host or path replaces the server; a new query does not. */\n url: string\n transport?: 'streamable-http'\n headers?: { [name: string]: McpHeaderValue }\n /** `{ type: 'headers' }` when left out. The OAuth client secret is set in the server settings. */\n auth?: McpServerAuth\n /** Milliseconds a request waits; 30000 when left out. */\n timeout?: number\n /** 3 when left out. */\n retries?: number\n /** `true` when left out. */\n enabled?: boolean\n}\n\n/** Declares an MCP server. Its default export is the whole file. */\nexport declare function defineMcpServer(server: McpServerDeclaration): McpServerDeclaration\n", "secrets.d.ts": `/**
55688
55685
  * Secret declarations: \`secrets.ts\` at the root of a workspace source directory names the
55689
55686
  * workspace secrets its workflows read, by name and what each is for. Never a value: set one with
55690
55687
  * \`sim secrets set <NAME> --scope workspace\`, or in the workspace's secrets settings.
@@ -55718,9 +55715,7 @@ export declare function defineSecrets<const T extends Record<string, SecretDecla
55718
55715
 
55719
55716
  /** The env names a \`secrets.ts\` declaration adds, as \`workspace.d.ts\` merges them into \`env\`. */
55720
55717
  export type DeclaredSecretNames<T> = { [K in keyof T]: true }
55721
- `,
55722
- "skill.d.ts": '/**\n * Skills are markdown, not TypeScript: `skills/<key>.md` is a frontmatter block of `name` and\n * `description`, then the skill\'s content.\n *\n * ```md\n * ---\n * name: tone\n * description: "Answer in the support team\'s voice: short, warm, specific."\n * ---\n * Write like a person, not a policy.\n * ```\n *\n * A value is plain text on one line, or a JSON string (`"…"`) when it holds a line break,\n * surrounding spaces, quotes, `: ` or ` #`, ends in `:`, or starts with anything but a letter,\n * digit or `(`. Quote a value YAML would read as a boolean, number or date (`"yes"`, `"1e3"`) too,\n * so other markdown tools read it as text. The name is kebab-case; a workflow names the skill by\n * its key, `skill(\'tone\')`. This module declares nothing.\n */\nexport {}\n',
55723
- "table.d.ts": `/**
55718
+ `, "skill.d.ts": '/**\n * Skills are markdown, not TypeScript: `skills/<key>.md` is a frontmatter block of `name` and\n * `description`, then the skill\'s content.\n *\n * ```md\n * ---\n * name: tone\n * description: "Answer in the support team\'s voice: short, warm, specific."\n * ---\n * Write like a person, not a policy.\n * ```\n *\n * A value is plain text on one line, or a JSON string (`"…"`) when it holds a line break,\n * surrounding spaces, quotes, `: ` or ` #`, ends in `:`, or starts with anything but a letter,\n * digit or `(`. Quote a value YAML would read as a boolean, number or date (`"yes"`, `"1e3"`) too,\n * so other markdown tools read it as text. The name is kebab-case; a workflow names the skill by\n * its key, `skill(\'tone\')`. This module declares nothing.\n */\nexport {}\n', "table.d.ts": `/**
55724
55719
  * Table declarations: \`tables/<key>.ts\` in a workspace source directory.
55725
55720
  *
55726
55721
  * \`\`\`ts
@@ -55865,8 +55860,7 @@ type CellOf<C> = C extends Column<infer V, infer _N, infer R>
55865
55860
  export type RowOf<T> = T extends TableDeclaration<infer C>
55866
55861
  ? { [K in keyof C as StoredName<K, C[K]>]: CellOf<C[K]> }
55867
55862
  : never
55868
- `,
55869
- "tool.d.ts": `/**
55863
+ `, "tool.d.ts": `/**
55870
55864
  * Custom tool declarations: \`tools/<key>.ts\`, with the tool's code beside it in \`tools/<key>.js\`.
55871
55865
  *
55872
55866
  * \`\`\`ts
@@ -55933,8 +55927,7 @@ export interface ToolDeclaration {
55933
55927
 
55934
55928
  /** Declares a custom tool. Its default export is the whole file. */
55935
55929
  export declare function defineTool(tool: ToolDeclaration): ToolDeclaration
55936
- `
55937
- };
55930
+ ` };
55938
55931
  // src/commands/protocol/source-primer.ts
55939
55932
  var MAX_SNIPPETS = 12;
55940
55933
  var MAX_SNIPPET_BYTES = 4096;
@@ -63729,10 +63722,31 @@ async function assertWorkspaceDir(dir) {
63729
63722
  function keepFile(kind) {
63730
63723
  return isFileKind(kind) ? null : `${KIND_DIRS[kind]}/${KEEP_FILE}`;
63731
63724
  }
63725
+ function toolOfCodeFile(path) {
63726
+ if (kindOfPath(path) !== "custom-tool")
63727
+ return null;
63728
+ const [key] = toolCodec.group([path]).groups.keys();
63729
+ if (key === undefined)
63730
+ return null;
63731
+ const declaration = toolDeclarationPath(key);
63732
+ return path === declaration ? null : { key, declaration };
63733
+ }
63734
+ function isUnnamedToolCode(files, path) {
63735
+ const tool = toolOfCodeFile(path);
63736
+ const text = tool ? files[tool.declaration] : undefined;
63737
+ if (!tool || text === undefined)
63738
+ return false;
63739
+ return toolCodec.parse(tool.key, { [tool.declaration]: text }, []).decl !== undefined;
63740
+ }
63732
63741
  function dropUnnamedCodeFiles(files) {
63733
63742
  const named = new Map;
63734
63743
  const unnamed = [];
63735
63744
  for (const path of Object.keys(files)) {
63745
+ if (isUnnamedToolCode(files, path)) {
63746
+ unnamed.push(path);
63747
+ delete files[path];
63748
+ continue;
63749
+ }
63736
63750
  if (kindOfPath(path) !== "workflow")
63737
63751
  continue;
63738
63752
  const segments = path.split("/");
@@ -65851,14 +65865,20 @@ function droppedResourceFiles(sent, reprinted) {
65851
65865
  }
65852
65866
  async function saveApplied(dir, data, submission, written, records) {
65853
65867
  assertWorkspacePaths(Object.keys(data.files));
65854
- const orphaned = [
65855
- ...await orphanedWorkflowFiles(dir, data.files, written.digests),
65856
- ...droppedResourceFiles(submission.files, data.files)
65857
- ];
65868
+ const toolCode = [];
65869
+ const orphaned = await orphanedWorkflowFiles(dir, data.files, written.digests);
65870
+ for (const path of droppedResourceFiles(submission.files, data.files)) {
65871
+ const tool = toolOfCodeFile(path);
65872
+ if (tool)
65873
+ toolCode.push({ path, declaration: tool.declaration });
65874
+ else
65875
+ orphaned.push(path);
65876
+ }
65858
65877
  const kept = { ...written.digests, ...appliedBlobDigests(submission, data.base) };
65859
65878
  const deleted = await deletedRecordedPaths(dir, written.digests, submission.kinds, data.base);
65860
- for (const path of [...orphaned, ...deleted])
65879
+ for (const path of [...orphaned, ...deleted, ...toolCode.map(({ path }) => path)]) {
65861
65880
  delete kept[path];
65881
+ }
65862
65882
  const record = writtenRecord(data.files, kept, new Map([...recordedStats(written), ...submission.hashed]));
65863
65883
  await updateSourceDir(dir, {
65864
65884
  write: [
@@ -65870,6 +65890,9 @@ async function saveApplied(dir, data, submission, written, records) {
65870
65890
  ],
65871
65891
  remove: [...orphaned, ...removedWorkflowRecords(deleted)]
65872
65892
  });
65893
+ for (const { path, declaration } of toolCode) {
65894
+ printError(`warning: ${path} is no longer named by ${declaration} (its code is now kept as stored() or printed inline), so it was left on disk as written and no apply sends it: delete it, or name it again with codeFile(). Never commit one that holds a credential.`);
65895
+ }
65873
65896
  }
65874
65897
  function baseWorkflowOf(base) {
65875
65898
  return isRecordLike(base) && typeof base.workflowId === "string" ? base.workflowId : null;
package/dist/runtime.js CHANGED
@@ -35527,7 +35527,8 @@ var CLI_CONTRACT = {
35527
35527
  getWorkflowState: { command: "workflows state get" },
35528
35528
  getWorkflowOutline: {
35529
35529
  command: "workflows outline",
35530
- describe: "Show a workflow’s draft as a compact read-only outline"
35530
+ describe: "Show a workflow’s draft as a compact read-only outline",
35531
+ dataKeys: true
35531
35532
  },
35532
35533
  getWorkflowSource: {
35533
35534
  command: "workflows source get",
@@ -37293,6 +37294,12 @@ function inferHeader(key, format) {
37293
37294
  const trimmed = format === "duration" || format === "bytes" ? key.replace(/(?:Ms|Bytes)$/, "") : format === "bool" ? key.replace(/^is(?=[A-Z])/, "") : key;
37294
37295
  return humanizeKey(trimmed || key);
37295
37296
  }
37297
+ function inferredFields(record, dataKeys) {
37298
+ return Object.entries(record).map(([key, value]) => [
37299
+ dataKeys ? key : inferHeader(key, inferFormat(key, value)),
37300
+ inferredCell(key, value)
37301
+ ]);
37302
+ }
37296
37303
  function columnsFrom(specs) {
37297
37304
  return specs.map((spec) => ({
37298
37305
  header: spec.header,
@@ -37415,10 +37422,7 @@ function renderResult(operation, format, raw, spec, options = {}, envelope) {
37415
37422
  printList(format, data, spec.columns ? columnsFrom(spec.columns) : inferColumns(data, spec.expand));
37416
37423
  return;
37417
37424
  }
37418
- const fields = spec.fields ? fieldsFrom(data, spec.fields, options) : data && typeof data === "object" ? Object.entries(data).map(([key, value]) => [
37419
- inferHeader(key, inferFormat(key, value)),
37420
- inferredCell(key, value)
37421
- ]) : [];
37425
+ const fields = spec.fields ? fieldsFrom(data, spec.fields, options) : data && typeof data === "object" ? inferredFields(data, spec.dataKeys === true) : [];
37422
37426
  printRecord(format, fields, data);
37423
37427
  if (spec.expandedTrace && options.expandedTrace) {
37424
37428
  const traceSpans = at(data, "traceSpans");
@@ -55527,8 +55531,7 @@ export default workflow('Support', { description: 'Answers an order question.' }
55527
55531
  })
55528
55532
  ` };
55529
55533
  // ../workflow-sdk/src/codegen/workspace-text.generated.ts
55530
- var WORKSPACE_SDK_DTS = {
55531
- "credentials.d.ts": `/**
55534
+ var WORKSPACE_SDK_DTS = { "credentials.d.ts": `/**
55532
55535
  * Credential declarations: \`credentials.ts\` at the root of a workspace source directory names the
55533
55536
  * saved credentials its workflows use, each by the provider it is for. Never a token: connect one
55534
55537
  * with \`sim credentials connect <provider> --name "<display name>"\`.
@@ -55572,8 +55575,7 @@ export declare function defineCredentials<const T extends Record<string, Credent
55572
55575
  export type DeclaredCredentials<T> = {
55573
55576
  [K in keyof T]: T[K] extends { provider: infer P } ? { provider: P } : never
55574
55577
  }
55575
- `,
55576
- "deployment.d.ts": `/**
55578
+ `, "deployment.d.ts": `/**
55577
55579
  * Deployment declarations: \`deployments/<workflow key>.ts\` in a workspace source directory deploys
55578
55580
  * \`workflows/<workflow key>/\`, so its schedule, webhook, API and chat triggers run.
55579
55581
  *
@@ -55655,9 +55657,7 @@ export interface DeploymentDeclaration {
55655
55657
 
55656
55658
  /** Declares a workflow's deployment. Its default export is the whole file. */
55657
55659
  export declare function defineDeployment(deployment: DeploymentDeclaration): DeploymentDeclaration
55658
- `,
55659
- "file.d.ts": "/**\n * Workspace files need no declaration: every file under `files/` is one workspace file, at the\n * folder path and name it has there (`files/reports/q1.pdf` is `q1.pdf` in the `reports`\n * folder), synced by content hash. Each apply that changes a file's bytes records a new version\n * of it, so an earlier one can be restored in the Files tab. Files over 10 MB, or whose name no\n * directory can hold (a reserved character, or a path that differs only in letter case from\n * another file or folder), are left out of a get (listed in `.sim/skipped.json`) and never written\n * by an apply; a file the directory no longer holds is deleted only with `--allow-delete`.\n */\nexport {}\n",
55660
- "index.d.ts": `/**
55660
+ `, "file.d.ts": "/**\n * Workspace files need no declaration: every file under `files/` is one workspace file, at the\n * folder path and name it has there (`files/reports/q1.pdf` is `q1.pdf` in the `reports`\n * folder), synced by content hash. Each apply that changes a file's bytes records a new version\n * of it, so an earlier one can be restored in the Files tab. Files over 10 MB, or whose name no\n * directory can hold (a reserved character, or a path that differs only in letter case from\n * another file or folder), are left out of a get (listed in `.sim/skipped.json`) and never written\n * by an apply; a file the directory no longer holds is deleted only with `--allow-delete`.\n */\nexport {}\n", "index.d.ts": `/**
55661
55661
  * The workspace declaration SDK: \`import { … } from '@sim/workflow-sdk/workspace'\` in the
55662
55662
  * declaration files of a workspace source directory (\`tables/<key>.ts\`, …). Like the workflow
55663
55663
  * SDK, nothing here runs: the server reads each file statically.
@@ -55671,8 +55671,7 @@ export * from './secrets'
55671
55671
  export * from './skill'
55672
55672
  export * from './table'
55673
55673
  export * from './tool'
55674
- `,
55675
- "knowledge.d.ts": `/**
55674
+ `, "knowledge.d.ts": `/**
55676
55675
  * Knowledge base declarations: \`knowledge/<key>/knowledge.ts\` in a workspace source directory,
55677
55676
  * beside \`knowledge/<key>/docs/\`, which holds one file per document.
55678
55677
  *
@@ -55731,9 +55730,7 @@ export interface KnowledgeBaseDeclaration {
55731
55730
  export declare function defineKnowledgeBase(
55732
55731
  knowledgeBase: KnowledgeBaseDeclaration
55733
55732
  ): KnowledgeBaseDeclaration
55734
- `,
55735
- "mcp.d.ts": "/**\n * MCP server declarations: `mcp/<key>.ts` declares one server the workspace's agents call tools\n * on.\n *\n * ```ts\n * // @sim-sdk 1\n * import { defineMcpServer, env } from '@sim/workflow-sdk/workspace'\n *\n * export default defineMcpServer({\n * name: 'GitHub',\n * url: 'https://api.githubcopilot.com/mcp/',\n * headers: { Authorization: 'Bearer {{GITHUB_TOKEN}}', 'X-Team': env.GITHUB_TEAM },\n * })\n * ```\n *\n * A workflow names the server by its key and one of its tools by name:\n * `mcp('github').tool('create_issue')`. Secrets never sit in source: a credential header\n * (`Authorization`, `Cookie`, or a name with `key`, `token`, `secret`, `auth`, …) holds env\n * references (`env.NAME`, or `{{NAME}}` in its text after a scheme such as `Bearer`) or\n * `stored()`, which keeps the value the server holds. The server's id derives from its URL, so a\n * `url` with another host or path replaces the server; a new query string updates it in place.\n */\nimport type { EnvRef } from '@sim/workflow-sdk'\n\nexport { env, stored } from '@sim/workflow-sdk'\n\n/** A header value: text (`{{NAME}}` names an env variable), `env.NAME`, or `stored()`. */\nexport type McpHeaderValue = string | EnvRef\n\n/** How the server authenticates. */\nexport interface McpServerAuth {\n /** `headers` (the default) sends the declared headers; `oauth` signs in with an OAuth grant. */\n type: 'none' | 'headers' | 'oauth'\n /** A pre-registered OAuth client, for a server without dynamic client registration. */\n clientId?: string\n}\n\n/** An MCP server declaration. */\nexport interface McpServerDeclaration {\n /** The display name; the key when left out. */\n name?: string\n description?: string\n /** An `http://` or `https://` URL. A new host or path replaces the server; a new query does not. */\n url: string\n transport?: 'streamable-http'\n headers?: { [name: string]: McpHeaderValue }\n /** `{ type: 'headers' }` when left out. The OAuth client secret is set in the server settings. */\n auth?: McpServerAuth\n /** Milliseconds a request waits; 30000 when left out. */\n timeout?: number\n /** 3 when left out. */\n retries?: number\n /** `true` when left out. */\n enabled?: boolean\n}\n\n/** Declares an MCP server. Its default export is the whole file. */\nexport declare function defineMcpServer(server: McpServerDeclaration): McpServerDeclaration\n",
55736
- "secrets.d.ts": `/**
55733
+ `, "mcp.d.ts": "/**\n * MCP server declarations: `mcp/<key>.ts` declares one server the workspace's agents call tools\n * on.\n *\n * ```ts\n * // @sim-sdk 1\n * import { defineMcpServer, env } from '@sim/workflow-sdk/workspace'\n *\n * export default defineMcpServer({\n * name: 'GitHub',\n * url: 'https://api.githubcopilot.com/mcp/',\n * headers: { Authorization: 'Bearer {{GITHUB_TOKEN}}', 'X-Team': env.GITHUB_TEAM },\n * })\n * ```\n *\n * A workflow names the server by its key and one of its tools by name:\n * `mcp('github').tool('create_issue')`. Secrets never sit in source: a credential header\n * (`Authorization`, `Cookie`, or a name with `key`, `token`, `secret`, `auth`, …) holds env\n * references (`env.NAME`, or `{{NAME}}` in its text after a scheme such as `Bearer`) or\n * `stored()`, which keeps the value the server holds. The server's id derives from its URL, so a\n * `url` with another host or path replaces the server; a new query string updates it in place.\n */\nimport type { EnvRef } from '@sim/workflow-sdk'\n\nexport { env, stored } from '@sim/workflow-sdk'\n\n/** A header value: text (`{{NAME}}` names an env variable), `env.NAME`, or `stored()`. */\nexport type McpHeaderValue = string | EnvRef\n\n/** How the server authenticates. */\nexport interface McpServerAuth {\n /** `headers` (the default) sends the declared headers; `oauth` signs in with an OAuth grant. */\n type: 'none' | 'headers' | 'oauth'\n /** A pre-registered OAuth client, for a server without dynamic client registration. */\n clientId?: string\n}\n\n/** An MCP server declaration. */\nexport interface McpServerDeclaration {\n /** The display name; the key when left out. */\n name?: string\n description?: string\n /** An `http://` or `https://` URL. A new host or path replaces the server; a new query does not. */\n url: string\n transport?: 'streamable-http'\n headers?: { [name: string]: McpHeaderValue }\n /** `{ type: 'headers' }` when left out. The OAuth client secret is set in the server settings. */\n auth?: McpServerAuth\n /** Milliseconds a request waits; 30000 when left out. */\n timeout?: number\n /** 3 when left out. */\n retries?: number\n /** `true` when left out. */\n enabled?: boolean\n}\n\n/** Declares an MCP server. Its default export is the whole file. */\nexport declare function defineMcpServer(server: McpServerDeclaration): McpServerDeclaration\n", "secrets.d.ts": `/**
55737
55734
  * Secret declarations: \`secrets.ts\` at the root of a workspace source directory names the
55738
55735
  * workspace secrets its workflows read, by name and what each is for. Never a value: set one with
55739
55736
  * \`sim secrets set <NAME> --scope workspace\`, or in the workspace's secrets settings.
@@ -55767,9 +55764,7 @@ export declare function defineSecrets<const T extends Record<string, SecretDecla
55767
55764
 
55768
55765
  /** The env names a \`secrets.ts\` declaration adds, as \`workspace.d.ts\` merges them into \`env\`. */
55769
55766
  export type DeclaredSecretNames<T> = { [K in keyof T]: true }
55770
- `,
55771
- "skill.d.ts": '/**\n * Skills are markdown, not TypeScript: `skills/<key>.md` is a frontmatter block of `name` and\n * `description`, then the skill\'s content.\n *\n * ```md\n * ---\n * name: tone\n * description: "Answer in the support team\'s voice: short, warm, specific."\n * ---\n * Write like a person, not a policy.\n * ```\n *\n * A value is plain text on one line, or a JSON string (`"…"`) when it holds a line break,\n * surrounding spaces, quotes, `: ` or ` #`, ends in `:`, or starts with anything but a letter,\n * digit or `(`. Quote a value YAML would read as a boolean, number or date (`"yes"`, `"1e3"`) too,\n * so other markdown tools read it as text. The name is kebab-case; a workflow names the skill by\n * its key, `skill(\'tone\')`. This module declares nothing.\n */\nexport {}\n',
55772
- "table.d.ts": `/**
55767
+ `, "skill.d.ts": '/**\n * Skills are markdown, not TypeScript: `skills/<key>.md` is a frontmatter block of `name` and\n * `description`, then the skill\'s content.\n *\n * ```md\n * ---\n * name: tone\n * description: "Answer in the support team\'s voice: short, warm, specific."\n * ---\n * Write like a person, not a policy.\n * ```\n *\n * A value is plain text on one line, or a JSON string (`"…"`) when it holds a line break,\n * surrounding spaces, quotes, `: ` or ` #`, ends in `:`, or starts with anything but a letter,\n * digit or `(`. Quote a value YAML would read as a boolean, number or date (`"yes"`, `"1e3"`) too,\n * so other markdown tools read it as text. The name is kebab-case; a workflow names the skill by\n * its key, `skill(\'tone\')`. This module declares nothing.\n */\nexport {}\n', "table.d.ts": `/**
55773
55768
  * Table declarations: \`tables/<key>.ts\` in a workspace source directory.
55774
55769
  *
55775
55770
  * \`\`\`ts
@@ -55914,8 +55909,7 @@ type CellOf<C> = C extends Column<infer V, infer _N, infer R>
55914
55909
  export type RowOf<T> = T extends TableDeclaration<infer C>
55915
55910
  ? { [K in keyof C as StoredName<K, C[K]>]: CellOf<C[K]> }
55916
55911
  : never
55917
- `,
55918
- "tool.d.ts": `/**
55912
+ `, "tool.d.ts": `/**
55919
55913
  * Custom tool declarations: \`tools/<key>.ts\`, with the tool's code beside it in \`tools/<key>.js\`.
55920
55914
  *
55921
55915
  * \`\`\`ts
@@ -55982,8 +55976,7 @@ export interface ToolDeclaration {
55982
55976
 
55983
55977
  /** Declares a custom tool. Its default export is the whole file. */
55984
55978
  export declare function defineTool(tool: ToolDeclaration): ToolDeclaration
55985
- `
55986
- };
55979
+ ` };
55987
55980
  // src/commands/protocol/source-primer.ts
55988
55981
  var MAX_SNIPPETS = 12;
55989
55982
  var MAX_SNIPPET_BYTES = 4096;
@@ -63778,10 +63771,31 @@ async function assertWorkspaceDir(dir) {
63778
63771
  function keepFile(kind) {
63779
63772
  return isFileKind(kind) ? null : `${KIND_DIRS[kind]}/${KEEP_FILE}`;
63780
63773
  }
63774
+ function toolOfCodeFile(path) {
63775
+ if (kindOfPath(path) !== "custom-tool")
63776
+ return null;
63777
+ const [key] = toolCodec.group([path]).groups.keys();
63778
+ if (key === undefined)
63779
+ return null;
63780
+ const declaration = toolDeclarationPath(key);
63781
+ return path === declaration ? null : { key, declaration };
63782
+ }
63783
+ function isUnnamedToolCode(files, path) {
63784
+ const tool = toolOfCodeFile(path);
63785
+ const text = tool ? files[tool.declaration] : undefined;
63786
+ if (!tool || text === undefined)
63787
+ return false;
63788
+ return toolCodec.parse(tool.key, { [tool.declaration]: text }, []).decl !== undefined;
63789
+ }
63781
63790
  function dropUnnamedCodeFiles(files) {
63782
63791
  const named = new Map;
63783
63792
  const unnamed = [];
63784
63793
  for (const path of Object.keys(files)) {
63794
+ if (isUnnamedToolCode(files, path)) {
63795
+ unnamed.push(path);
63796
+ delete files[path];
63797
+ continue;
63798
+ }
63785
63799
  if (kindOfPath(path) !== "workflow")
63786
63800
  continue;
63787
63801
  const segments = path.split("/");
@@ -65900,14 +65914,20 @@ function droppedResourceFiles(sent, reprinted) {
65900
65914
  }
65901
65915
  async function saveApplied(dir, data, submission, written, records) {
65902
65916
  assertWorkspacePaths(Object.keys(data.files));
65903
- const orphaned = [
65904
- ...await orphanedWorkflowFiles(dir, data.files, written.digests),
65905
- ...droppedResourceFiles(submission.files, data.files)
65906
- ];
65917
+ const toolCode = [];
65918
+ const orphaned = await orphanedWorkflowFiles(dir, data.files, written.digests);
65919
+ for (const path of droppedResourceFiles(submission.files, data.files)) {
65920
+ const tool = toolOfCodeFile(path);
65921
+ if (tool)
65922
+ toolCode.push({ path, declaration: tool.declaration });
65923
+ else
65924
+ orphaned.push(path);
65925
+ }
65907
65926
  const kept = { ...written.digests, ...appliedBlobDigests(submission, data.base) };
65908
65927
  const deleted = await deletedRecordedPaths(dir, written.digests, submission.kinds, data.base);
65909
- for (const path of [...orphaned, ...deleted])
65928
+ for (const path of [...orphaned, ...deleted, ...toolCode.map(({ path }) => path)]) {
65910
65929
  delete kept[path];
65930
+ }
65911
65931
  const record = writtenRecord(data.files, kept, new Map([...recordedStats(written), ...submission.hashed]));
65912
65932
  await updateSourceDir(dir, {
65913
65933
  write: [
@@ -65919,6 +65939,9 @@ async function saveApplied(dir, data, submission, written, records) {
65919
65939
  ],
65920
65940
  remove: [...orphaned, ...removedWorkflowRecords(deleted)]
65921
65941
  });
65942
+ for (const { path, declaration } of toolCode) {
65943
+ printError(`warning: ${path} is no longer named by ${declaration} (its code is now kept as stored() or printed inline), so it was left on disk as written and no apply sends it: delete it, or name it again with codeFile(). Never commit one that holds a credential.`);
65944
+ }
65922
65945
  }
65923
65946
  function baseWorkflowOf(base) {
65924
65947
  return isRecordLike(base) && typeof base.workflowId === "string" ? base.workflowId : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim",
3
- "version": "2.2.33-preview.321.1",
3
+ "version": "2.3.0-preview.323.1",
4
4
  "description": "Sim CLI - talk to the Sim API from your terminal",
5
5
  "type": "module",
6
6
  "bin": {