sim 2.2.32-preview.314.1 → 2.2.33-preview.316.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.
Files changed (35) hide show
  1. package/README.md +42 -0
  2. package/THIRD_PARTY_LICENSES +31 -0
  3. package/dist/auth/refresh.d.ts +2 -1
  4. package/dist/commands/protocol/files-get.d.ts +3 -0
  5. package/dist/commands/protocol/result.d.ts +7 -1
  6. package/dist/commands/protocol/source-dir.d.ts +263 -0
  7. package/dist/commands/protocol/source-exit-codes.d.ts +8 -0
  8. package/dist/commands/protocol/source-primer.d.ts +14 -0
  9. package/dist/commands/protocol/source-status.d.ts +145 -0
  10. package/dist/commands/protocol/source-tree.d.ts +159 -0
  11. package/dist/commands/protocol/source-ui.d.ts +89 -0
  12. package/dist/commands/protocol/stored-edges.d.ts +44 -0
  13. package/dist/commands/protocol/workflow-source-apply.d.ts +38 -0
  14. package/dist/commands/protocol/workflow-source-check.d.ts +70 -0
  15. package/dist/commands/protocol/workflow-source-get.d.ts +40 -0
  16. package/dist/commands/protocol/workflow-source-params.d.ts +7 -0
  17. package/dist/commands/protocol/workflow-source-status.d.ts +14 -0
  18. package/dist/commands/protocol/workspace-source-apply.d.ts +15 -0
  19. package/dist/commands/protocol/workspace-source-blobs.d.ts +111 -0
  20. package/dist/commands/protocol/workspace-source-check.d.ts +7 -0
  21. package/dist/commands/protocol/workspace-source-dir.d.ts +135 -0
  22. package/dist/commands/protocol/workspace-source-get.d.ts +13 -0
  23. package/dist/commands/protocol/workspace-source-status.d.ts +13 -0
  24. package/dist/embed-context.d.ts +6 -3
  25. package/dist/exit-codes.d.ts +66 -0
  26. package/dist/generated/v2-api.d.ts +1297 -1
  27. package/dist/http/client.d.ts +22 -0
  28. package/dist/index.js +58843 -20211
  29. package/dist/output/io.d.ts +6 -0
  30. package/dist/program.d.ts +1 -1
  31. package/dist/runtime.js +59083 -20451
  32. package/dist/terminal/interrupts.d.ts +23 -0
  33. package/dist/terminal/line-input.d.ts +8 -0
  34. package/dist/terminal.d.ts +1 -0
  35. package/package.json +5 -1
@@ -0,0 +1,159 @@
1
+ import type { BlockCatalog } from '@sim/workflow-code';
2
+ import { type WorkspaceManifest } from '@sim/workflow-sdk/codegen';
3
+ import type { OutputFormat } from '../../config/index';
4
+ import type { GetWorkflowSourceResponse } from '../../generated/v2-api';
5
+ import type { OperationClient } from '../../runtime/called-operations';
6
+ import { SOURCE_AGENTS_FILE, type SourceDirChange } from './source-dir';
7
+ import { type PrimerKind } from './source-primer';
8
+ /** Type-checks the source against every current block, for a block the default one leaves out. */
9
+ export declare const TSCONFIG_FULL_FILE = "tsconfig.full.json";
10
+ /** The workspace's resources as types (`generateWorkspaceTypes`), beside the SDK. */
11
+ export declare const WORKSPACE_TYPES_FILE = ".sim/sdk/workspace.d.ts";
12
+ /**
13
+ * The cached catalog of `hash`, or `null`. Standalone runs only: an embedded run has no local disk
14
+ * of its own to cache on. The file is read without following a link and under a size cap, and
15
+ * kept only when the catalog in it names the hash its file does.
16
+ */
17
+ export declare function cachedCatalogByHash(hash: unknown): BlockCatalog | null;
18
+ /** The cached catalog of the workspace, by the hash its last catalog read recorded, or `null`. */
19
+ export declare function cachedCatalog(workspaceId: string): BlockCatalog | null;
20
+ /**
21
+ * The cached catalog a workflow source directory was printed against, by the hash its
22
+ * `.sim/base.json` records (the workspace's, or the workflow's own for a workflow holding a type
23
+ * the workspace catalog lacks), or `null` when the directory has no base or that catalog is not
24
+ * cached. An offline check compiles against it, so it agrees with the dry run, which compiles
25
+ * against the same catalog.
26
+ */
27
+ export declare function cachedSourceCatalog(dir: string): Promise<BlockCatalog | null>;
28
+ /**
29
+ * The catalog of the workflow `workflowId` (the workspace catalog plus the types it stores that the
30
+ * workspace catalog lacks), fetched and cached by hash; `knownHash`, a hash the workflow's catalog
31
+ * may have, is sent as its ETag, so a catalog already cached answers `304` with no body.
32
+ */
33
+ export declare function loadWorkflowCatalog(client: OperationClient<'getSourceCatalog'>, workspaceId: string, workflowId: string, knownHash?: string): Promise<BlockCatalog>;
34
+ /**
35
+ * The workspace's block catalog, revalidated by ETag against the cached one: a `304` reuses it,
36
+ * anything else replaces it. A workflow can hold a type the workspace no longer offers (a legacy
37
+ * version, a block an allowlist now withholds); only then is that workflow's own catalog used
38
+ * instead, so its types still resolve: the one cached under the hash its base records
39
+ * (`catalogHash`), else fetched ({@link loadWorkflowCatalog}).
40
+ */
41
+ export declare function loadCatalog(client: OperationClient<'getSourceCatalog'>, source: Pick<GetWorkflowSourceResponse['data'], 'workspaceId' | 'blockTypes'> & {
42
+ workflowId?: string;
43
+ catalogHash?: string;
44
+ }): Promise<BlockCatalog>;
45
+ /** What a workspace directory declares itself, typed beside the stored resources. */
46
+ export type LocalDeclarations = Pick<WorkspaceManifest, 'declarationModules' | 'secretDeclarations' | 'credentialDeclarations' | 'tableDeclarations' | 'knowledgeBases' | 'skills' | 'customTools' | 'mcpServerDeclarations' | 'workflows'>;
47
+ /** `workspace.d.ts`, and the stored manifest it was generated from (`null` when none was read). */
48
+ export interface WorkspaceTypes {
49
+ text: string;
50
+ stored: WorkspaceManifest | null;
51
+ }
52
+ /**
53
+ * The workspace's resources as `workspace.d.ts` ({@link workspaceTypesFrom}), read from the
54
+ * server. When the resources cannot be listed (a `403` for a caller the manifest does not admit, a
55
+ * `404` from a server that predates the route) only the declared resources are typed, or `null`
56
+ * without any: the source still writes and type-checks, with every other key a plain string.
57
+ */
58
+ export declare function loadWorkspaceTypes(client: OperationClient<'getSourceResources'>, workspaceId: string, local?: LocalDeclarations): Promise<WorkspaceTypes | null>;
59
+ /**
60
+ * Regenerates `workspace.d.ts` from the stored manifest the last get kept beside it and what the
61
+ * directory declares now (`local`), so `tsc` types a key added since without a request. A
62
+ * directory with no kept manifest (written by an older CLI) is left as it is.
63
+ */
64
+ export declare function refreshWorkspaceTypes(dir: string, local: LocalDeclarations): Promise<void>;
65
+ /**
66
+ * Refuses a catalog for another SDK major than the bundled `core.d.ts`: its builders would be
67
+ * written beside declarations that cannot type them.
68
+ */
69
+ export declare function assertSdkMajor(catalog: BlockCatalog): void;
70
+ /**
71
+ * The first line of every `tsconfig.json` the CLI writes. A `tsconfig.json` without it is the
72
+ * person's own (an existing TypeScript project), and a get never replaces it.
73
+ */
74
+ export declare const TSCONFIG_MARKER = "// Written by `sim workflows source get`; remove this line to keep your own edits.";
75
+ /** What a tree write reports: the same fields after a get and a create scaffold. */
76
+ export interface SourceTree {
77
+ /** How many files were written. */
78
+ files: number;
79
+ /** Whether `workspace.d.ts` was written. */
80
+ workspaceTypes: boolean;
81
+ /** The agent guide to read before editing. */
82
+ guide: typeof SOURCE_AGENTS_FILE;
83
+ /** The primer atop the guide (`source-primer.ts`), printed so an agent needs no other read. */
84
+ primer: string;
85
+ }
86
+ /** Reports a `tsconfig.json` the CLI left alone and summarizes a tree write. */
87
+ export declare function finishTree(dir: string, written: number, workspaceTypes: WorkspaceTypes | null, tree: {
88
+ ownsTsconfig: boolean;
89
+ primer: string;
90
+ }): SourceTree;
91
+ /**
92
+ * Prints a tree write's result: in JSON or YAML one document with the primer as its `primer`
93
+ * field, otherwise the fields and then the primer as text, so it reads as written.
94
+ */
95
+ export declare function printTreeResult(format: OutputFormat, result: Record<string, unknown> & {
96
+ primer: string;
97
+ }): void;
98
+ /** What a directory's editable tree holds beside the printed source. */
99
+ export interface SourceTreeProfile {
100
+ /** Which primer opens `.sim/AGENTS.md`. */
101
+ kind: PrimerKind;
102
+ /** The reference in `.sim/AGENTS.md`, below the primer. */
103
+ agents: string;
104
+ /** More guides beside `.sim/AGENTS.md` (path → text), rewritten every time like it. */
105
+ guides?: ReadonlyArray<readonly [string, string]>;
106
+ /**
107
+ * A `tsconfig.json` the CLI writes, starting with {@link TSCONFIG_MARKER}, that type-checks the
108
+ * source with the SDK declarations `sdkFiles` (directory-relative paths).
109
+ */
110
+ tsconfig: (sdkFiles: readonly string[]) => string;
111
+ /** The `.gitattributes` lines that keep the source LF. */
112
+ gitattributes?: readonly string[];
113
+ /** The `.gitignore` lines for the files a command leaves only while it runs or between runs. */
114
+ gitignore?: readonly string[];
115
+ /** More declarations under the SDK directory, rewritten every time like `core.d.ts`. */
116
+ sdk?: ReadonlyArray<readonly [string, string]>;
117
+ /** More examples beside the cookbook, rewritten every time like it. */
118
+ examples?: ReadonlyArray<readonly [string, string]>;
119
+ }
120
+ /**
121
+ * Brings the CLI's tsconfig files and the block declarations the directory holds up to date with
122
+ * the source `use` names: after an apply, which may have added a block, and on a check, so a block
123
+ * the edit added type-checks before anything is applied. `incremental` (a check) keeps the blocks
124
+ * `tsconfig.json` includes now, since a check scans only the source text and not the server's
125
+ * block types, and rewrites `tsconfig.json` only when it exists (`tsconfig.full.json`, which names
126
+ * this machine's cache, is written again when missing, as a fresh clone lacks it). It reads the
127
+ * cached catalog, so it costs no request; without one nothing changes until the next get. A file
128
+ * whose text would not change is not rewritten.
129
+ */
130
+ export declare function refreshTsconfigs(dir: string, workspaceId: string, profile: Pick<SourceTreeProfile, 'tsconfig'>, use: SourceTreeUse, options?: {
131
+ incremental?: boolean;
132
+ }): Promise<void>;
133
+ /** What a tree write type-checks: the source texts it scans for builders, and known block types. */
134
+ export interface SourceTreeUse {
135
+ /** Workflow source texts (`workflow.ts` files); the builders they call pick the blocks. */
136
+ sources: Iterable<string>;
137
+ /** Block types the server reported the source using, as blocks or agent tools. */
138
+ blockTypes?: readonly string[];
139
+ }
140
+ /**
141
+ * Everything beside the printed source that makes a directory editable: the agent guide (the
142
+ * primer for the builders `use` calls, then the profile's reference) and the example workflows
143
+ * (both rewritten every time and never in `.sim/written.json`), the declarations of the blocks
144
+ * the source uses (every block's are cached once per catalog, for `tsconfig.full.json`),
145
+ * `workspace.d.ts`, the CLI's `tsconfig.json` and `tsconfig.full.json`, and the LF lines.
146
+ * Declarations of another catalog or generator are removed whole; otherwise only the block files,
147
+ * so a block the source no longer uses loses its file. `incremental` (a write that leaves
148
+ * workflows on disk unread, such as a get of only some kinds) keeps the blocks `tsconfig.json`
149
+ * includes now, as {@link refreshTsconfigs} does, adding the ones `use` needs.
150
+ */
151
+ export declare function sourceTreeChange(dir: string, catalog: BlockCatalog, workspaceTypes: WorkspaceTypes | null, profile: SourceTreeProfile, use: SourceTreeUse, options?: {
152
+ incremental?: boolean;
153
+ }): Promise<{
154
+ change: SourceDirChange;
155
+ ownsTsconfig: boolean;
156
+ primer: string;
157
+ }>;
158
+ /** A read the server refused as over the source size limits exits 7, as a refused apply does. */
159
+ export declare function withSourceExitCode(error: unknown): unknown;
@@ -0,0 +1,89 @@
1
+ import { type FlatDiagnostic } from '@sim/workspace-code';
2
+ import type { Command } from 'commander';
3
+ import type { OutputFormat } from '../../config/index';
4
+ import type { ApplyWorkflowSourceResponse, ApplyWorkspaceSourceResponse } from '../../generated/v2-api';
5
+ /** One finding of a source write, as the workflow and workspace answers both carry it. */
6
+ type WorkflowDiagnostic = ApplyWorkflowSourceResponse['data']['diagnostics'][number];
7
+ /** A workflow finding, or a workspace one: the same fields, over both code vocabularies. */
8
+ export type Diagnostic = Omit<WorkflowDiagnostic, 'code'> & {
9
+ code: WorkflowDiagnostic['code'] | ApplyWorkspaceSourceResponse['data']['diagnostics'][number]['code'];
10
+ };
11
+ /**
12
+ * The exit status of findings that refuse a write, the same for `workflows source` and
13
+ * `workspaces source` and for a dry run and a commit: the status of their most specific class
14
+ * (`refusalClass`).
15
+ */
16
+ export declare function refusedExitCode(diagnostics: ReadonlyArray<Pick<Diagnostic, 'code' | 'severity'>>): number;
17
+ /** A finding in a source command's `--output json` (or `yaml`) result: the frame stays human-only. */
18
+ type ResultDiagnostic = Omit<FlatDiagnostic, 'frame' | 'code'> & {
19
+ code: Diagnostic['code'];
20
+ };
21
+ /** Records `key` in `printed`, returning whether it was new. */
22
+ export declare function fresh(printed: Set<string>, key: string): boolean;
23
+ /**
24
+ * Where a source command's findings go, chosen once by its output format, so each is shown once:
25
+ * a display format prints them on stderr as frames (and never in the result), a machine format
26
+ * only in the one document on stdout (and never as frames, which an agent reading both streams
27
+ * read twice).
28
+ */
29
+ export interface FindingsOutput {
30
+ /** Whether the result is one machine document on stdout. */
31
+ machine: boolean;
32
+ /**
33
+ * Prints the findings not printed yet on stderr in a display format, so a finding the preview
34
+ * showed is not shown again by the write that follows it; nothing in a machine format.
35
+ */
36
+ print(diagnostics: readonly Diagnostic[]): void;
37
+ /** The result's `diagnostics` field: see {@link resultDiagnostics}. */
38
+ result(diagnostics: readonly Diagnostic[]): {
39
+ diagnostics?: ResultDiagnostic[];
40
+ };
41
+ }
42
+ /** The {@link FindingsOutput} of `format`; `verbose` keeps info findings in a machine result. */
43
+ export declare function findingsOutput(format: OutputFormat, verbose?: boolean): FindingsOutput;
44
+ /** A resource a source write created, as its result lists it; `id` once it is written. */
45
+ export interface CreatedResource {
46
+ kind: string;
47
+ key?: string;
48
+ id?: string;
49
+ }
50
+ /** The created resources as one line for a person: `workflow (abc), block start (b-1), …`. */
51
+ export declare function createdText(created: readonly CreatedResource[]): string;
52
+ /** Adds `--verbose` to a source command whose result can carry info findings. */
53
+ export declare function verboseFlag(command: Command): Command;
54
+ /** Asks `question` on the terminal; anything but `y` or `yes` is no. */
55
+ export declare function confirm(question: string): Promise<boolean>;
56
+ /**
57
+ * Re-throws an API refusal after printing its diagnostics, so each shows its source line, with
58
+ * the exit status a script branches on. In a machine `format` the error document keeps the
59
+ * refusal's details with each finding as a success result carries it ({@link resultDiagnostics});
60
+ * a display format prints the findings once, above the error, and `verbose` keeps info findings in
61
+ * the machine document as it does in a result. `ifAnswerLost` is the next step for a write whose
62
+ * answer never came back, appended to its message.
63
+ */
64
+ export declare function printRefusal(error: unknown, format: OutputFormat, options?: {
65
+ ifAnswerLost?: string;
66
+ verbose?: boolean;
67
+ }): never;
68
+ /**
69
+ * How a source write proceeds: `dry-run` checks only; `write` writes at once (`--yes`); `ask`
70
+ * previews and asks on a terminal; `plan` (no `--yes` and no terminal to ask) previews, prints the
71
+ * plan and stops with {@link SOURCE_PLANNED_EXIT_CODE}, so an agent's edit loop sees the plan
72
+ * without a separate dry run and applies it with `--yes`.
73
+ */
74
+ export type WriteMode = 'dry-run' | 'write' | 'ask' | 'plan';
75
+ /** The {@link WriteMode} of a write's `--dry-run` and `--yes` flags, here. */
76
+ export declare function writeMode(options: {
77
+ dryRun?: boolean;
78
+ yes?: boolean;
79
+ }): WriteMode;
80
+ /** `value` as one shell word: as it is when it needs no quoting, else single-quoted. */
81
+ export declare function shellWord(value: string): string;
82
+ /** The next step a `plan` run names: the same write with `--yes`. */
83
+ export declare function planNext(command: string): {
84
+ command: string;
85
+ reason: string;
86
+ };
87
+ /** Marks a `plan` run that found no errors: nothing was written, applying needs `--yes`. */
88
+ export declare function stopAtPlan(): void;
89
+ export {};
@@ -0,0 +1,44 @@
1
+ import { type BlockCatalog, type StoredEdgeRef } from '@sim/workflow-code';
2
+ import type { OperationClient } from '../../runtime/called-operations';
3
+ /** A printed source as a get, apply or create answers it. */
4
+ interface PrintedAnswer {
5
+ files: Record<string, string>;
6
+ lock: unknown;
7
+ base: unknown;
8
+ }
9
+ /**
10
+ * The `.sim/stored-edges.json` write for a printed source: its edges, compiled against `catalog`
11
+ * (the one it was printed with), tagged with its base fingerprint. `null` when the answer has no
12
+ * fingerprint or entry, or nothing to compile it with; the record left on disk then names an
13
+ * older fingerprint, which a check ignores.
14
+ */
15
+ export declare function storedEdgesWrite(answer: PrintedAnswer, catalog: BlockCatalog | null, folder?: string): readonly [string, string] | null;
16
+ /** The stored-edges records of a workspace answer, and the folders left without one. */
17
+ export interface WorkflowFolderRecords {
18
+ records: Array<readonly [string, string]>;
19
+ /** Folder keys whose catalog could not be fetched: their record is skipped, not failed. */
20
+ unrecorded: string[];
21
+ }
22
+ /**
23
+ * The `.sim/stored-edges.json` write of each workflow folder a workspace get or apply answered
24
+ * with, each compiled against the catalog its base names. A workflow holding a type the workspace
25
+ * catalog lacks was printed with its own catalog: one not cached yet is fetched, once per distinct
26
+ * hash, and cached, so an offline check compiles that folder against it too. The records are a
27
+ * cache fill, never part of the write: a catalog fetch that fails skips the folders printed with
28
+ * that catalog (named in `unrecorded`) rather than failing a write the server already committed.
29
+ */
30
+ export declare function workflowFolderRecords(client: OperationClient<'getSourceCatalog'>, workspaceId: string, workspaceCatalog: BlockCatalog, files: Record<string, string>): Promise<WorkflowFolderRecords>;
31
+ /**
32
+ * The warning for workflow folders {@link workflowFolderRecords} could not record, or `null`.
33
+ * Their edges are unrecorded, so an offline check of each one compiles without its stored edges
34
+ * until the next get records them.
35
+ */
36
+ export declare function unrecordedFoldersWarning(unrecorded: readonly string[]): string | null;
37
+ /**
38
+ * The stored edges recorded for the base `dir` holds now, or `undefined` when none are: no
39
+ * record, one an older CLI or another base wrote, or a malformed one.
40
+ */
41
+ export declare function readStoredEdges(dir: string): Promise<StoredEdgeRef[] | undefined>;
42
+ /** The stored-edges records of the workflow folders whose base a write removes (`paths`). */
43
+ export declare function removedWorkflowRecords(paths: Iterable<string>): string[];
44
+ export {};
@@ -0,0 +1,38 @@
1
+ import { type WorkflowLockV1 } from '@sim/workflow-code';
2
+ import type { Command } from 'commander';
3
+ import type { ApplyWorkflowSourceBody } from '../../generated/v2-api';
4
+ type SourceBase = ApplyWorkflowSourceBody['base'];
5
+ /**
6
+ * The base an apply sends, refused when it is not the named workflow's: a directory written for
7
+ * one workflow and applied to another would replace that workflow's draft with a stranger's
8
+ * source. Without a `workflowId` the apply targets the workflow the base names.
9
+ */
10
+ export declare function readBase(directory: string, workflowId: string | undefined): Promise<SourceBase>;
11
+ /** The directory's lock, refused with every problem the lock parser finds. */
12
+ export declare function readLock(directory: string): Promise<WorkflowLockV1>;
13
+ /** The directory's `workflow.ts`, or a refusal naming the command that writes one. */
14
+ export declare function requireEntry(directory: string): Promise<string>;
15
+ /**
16
+ * The files a write sends: the entry file and the code files it or the lock references. A
17
+ * referenced file that is missing is left out, and the server reports it with its source line.
18
+ */
19
+ export declare function readSourceFiles(directory: string, lock: WorkflowLockV1 | null): Promise<Record<string, string>>;
20
+ /**
21
+ * `sim workflows source apply [workflowId] --dir <dir>`: sends a source directory written by
22
+ * `workflows source get` (`workflow.ts`, its function-code files, `.sim/lock.json` and
23
+ * `.sim/base.json`) and, after a successful write, saves the re-printed files, the new lock and
24
+ * the new base back into it, so the next apply starts from what was stored. The workflow id
25
+ * defaults to the one `.sim/base.json` names; given, it must match it.
26
+ *
27
+ * Writing needs consent: on a terminal it shows the dry-run outcome and asks; anywhere else it
28
+ * needs `--yes`. `--dry-run` writes nothing, so it never asks.
29
+ */
30
+ export declare function attachWorkflowSourceApply(source: Command): void;
31
+ /**
32
+ * `sim workflows source create --dir <dir>`: creates a workflow from the directory's
33
+ * `workflow.ts`, then writes what `get --dir` would have: the new workflow's re-printed files, its
34
+ * lock files, the SDK declarations, `tsconfig.json` and the agent guide, so the directory is ready
35
+ * for the edit loop. Same consent rule as `apply`.
36
+ */
37
+ export declare function attachWorkflowSourceCreate(source: Command): void;
38
+ export {};
@@ -0,0 +1,70 @@
1
+ import { type BlockCatalog, type WorkflowInput } from '@sim/workflow-code';
2
+ import type { Command } from 'commander';
3
+ import { printProtocolResult } from './result';
4
+ import { type LocalDeclarations } from './source-tree';
5
+ import { type Diagnostic } from './source-ui';
6
+ import { type WorkspaceDeclarations } from './workspace-source-dir';
7
+ /**
8
+ * Which {@link STRICT_CODES} warnings fail a check: `new` those on a block the lock does not bind
9
+ * (one added since the get, or every block of a workflow that has no lock yet), `all` every one,
10
+ * `off` none. Printed source can hold such a warning on a block nobody edited (a field left empty
11
+ * in the editor), so the default fails only on blocks the edit wrote.
12
+ */
13
+ type StrictMode = 'new' | 'all' | 'off';
14
+ /** One finding of a check, as the write commands print theirs. */
15
+ export type CheckFinding = Diagnostic;
16
+ /** The `--strict` / `--no-strict` pair: absent selects the default, {@link StrictMode} `new`. */
17
+ export interface StrictOptions {
18
+ strict?: boolean;
19
+ }
20
+ /** The strict mode the `--strict` / `--no-strict` pair selects. */
21
+ export declare function strictMode(options: StrictOptions): StrictMode;
22
+ /** Help shared by both check commands: what fails, and the strict flags. */
23
+ export declare const STRICT_HELP: string;
24
+ /** Adds the `--strict` / `--no-strict` pair to a check command. */
25
+ export declare function strictFlags(command: Command): Command;
26
+ /** Every workflow key of the workspace directory `root` that has a `workflow.ts`. */
27
+ export declare function workspaceWorkflowKeys(root: string): Promise<string[]>;
28
+ /**
29
+ * Points the workspace directory's tsconfig files at the blocks its workflows now use, keeping the
30
+ * blocks they include.
31
+ */
32
+ export declare function refreshWorkspaceTsconfigs(root: string, workspaceId: string): Promise<void>;
33
+ /**
34
+ * The inputs of each workflow of the workspace directory `root` that compiles (`startInputs`,
35
+ * `null` for one without a Start trigger), by key: what a child workflow call is checked against
36
+ * and what `workspace.d.ts` types its `inputMapping` with.
37
+ */
38
+ export declare function workspaceWorkflowInputs(root: string, catalog: BlockCatalog): Promise<Map<string, WorkflowInput[] | null>>;
39
+ /**
40
+ * The workflows of `local` typed with the inputs each declares (`inputs`), for `workspace.d.ts`.
41
+ */
42
+ export declare function withWorkflowInputs(local: LocalDeclarations, inputs: ReadonlyMap<string, readonly WorkflowInput[] | null>): LocalDeclarations;
43
+ /**
44
+ * Compiles one workflow source directory offline against `catalog`, with the workspace's
45
+ * declarations when the directory sits in a workspace directory, and returns its findings with
46
+ * the {@link STRICT_CODES} the strict mode fails on raised to errors, and the `workflow.ts` text.
47
+ * `prefix` goes before each file path (`workflows/<key>/` in a workspace check).
48
+ */
49
+ export declare function checkWorkflowDir(dir: string, catalog: BlockCatalog, options: {
50
+ declarations?: WorkspaceDeclarations;
51
+ strict: StrictMode;
52
+ prefix?: string;
53
+ }): Promise<{
54
+ findings: CheckFinding[];
55
+ entry: string;
56
+ }>;
57
+ /**
58
+ * Prints a check's findings and result, and exits 1 on any error. `verbose` keeps info findings in
59
+ * a machine result.
60
+ */
61
+ export declare function reportCheck(output: Parameters<typeof printProtocolResult>[0], findings: CheckFinding[], result: Record<string, unknown>, verbose?: boolean): void;
62
+ /** The cached catalog of `workspaceId`, or a refusal naming `get`, the command that caches one. */
63
+ export declare function requireCachedCatalog(workspaceId: string, get: string): BlockCatalog;
64
+ /**
65
+ * `sim workflows source check [--dir <dir>]`: compiles a source directory locally with the bundled
66
+ * compiler and the cached catalog, so an agent's edit loop gets syntax and builder findings in
67
+ * milliseconds and without the network. The dry run stays the authority.
68
+ */
69
+ export declare function attachWorkflowSourceCheck(source: Command): void;
70
+ export {};
@@ -0,0 +1,40 @@
1
+ import type { Command } from 'commander';
2
+ import type { GetWorkflowSourceResponse } from '../../generated/v2-api';
3
+ import { type OperationClient } from '../../runtime/called-operations';
4
+ import { type SourceTree, type SourceTreeProfile } from './source-tree';
5
+ type WorkflowSource = GetWorkflowSourceResponse['data'];
6
+ /** The printed source a tree write saves: a get's answer, or an applied create's. */
7
+ type PrintedSource = Pick<WorkflowSource, 'workflowId' | 'workspaceId' | 'files' | 'lock' | 'base'>;
8
+ /** The workflow directory's tree beside the printed source. */
9
+ export declare const WORKFLOW_TREE: SourceTreeProfile;
10
+ /**
11
+ * Starts a new source directory: a starter `workflow.ts` plus the tree a get writes (the
12
+ * declarations for the workspace catalog and its resources, `tsconfig.json`, the agent guide),
13
+ * with no lock or base, since no workflow exists yet, and {@link SOURCE_STARTER_FILE} naming the
14
+ * workspace those declarations are for. Only for a directory with no `workflow.ts`.
15
+ */
16
+ export declare function writeSourceScaffold(client: OperationClient<'getSourceCatalog' | 'getSourceResources'>, dir: string, workspaceId: string): Promise<SourceTree>;
17
+ /**
18
+ * Writes a printed source with everything that makes the directory editable: the declarations
19
+ * for the workspace catalog and its resources, `tsconfig.json`, the agent guide and the LF lines.
20
+ * Shared by `get --dir` and `create --dir`, so a created workflow's directory is the one a get
21
+ * would have written.
22
+ */
23
+ export declare function writeSourceDirectory(client: OperationClient<'getSourceCatalog' | 'getSourceResources'>, dir: string, source: PrintedSource, blockTypes: readonly string[]): Promise<SourceTree>;
24
+ /**
25
+ * After an apply, points the CLI's tsconfig files at the blocks the applied source uses, so a
26
+ * block the edit added is type-checked by `tsconfig.json` from then on.
27
+ */
28
+ export declare function refreshWorkflowTsconfigs(dir: string, source: Pick<PrintedSource, 'workspaceId' | 'files'>): Promise<void>;
29
+ /**
30
+ * Teaches the generated `workflows source get` leaf `--dir <dir>`: instead of printing the
31
+ * response, it writes `workflow.ts`, `functions/*`, `.sim/lock.json`, `.sim/base.json`, SDK
32
+ * declarations for the blocks the source uses (`.sim/sdk/**`; every block's are generated once
33
+ * per catalog into the CLI's cache, which `tsconfig.full.json` includes, and the catalog itself is
34
+ * ETag-cached), `.sim/sdk/workspace.d.ts` from the resource manifest, the tsconfig files, the
35
+ * primer it prints atop `.sim/AGENTS.md`, the examples in `.sim/examples/` and the
36
+ * `.gitattributes` lines that keep the source LF. Without `--dir` the generated handler runs unchanged. Commander offers
37
+ * no way to read the action it holds, so it is captured and delegated to, as `runs get` does.
38
+ */
39
+ export declare function attachWorkflowSourceGet(source: Command): void;
40
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * `sim workflows source params <builder> [--dir <dir>]`: one builder's params and outputs from the
4
+ * cached catalog, so an agent reads the shape of a block it is about to write in one command
5
+ * instead of searching the declarations.
6
+ */
7
+ export declare function attachWorkflowSourceParams(source: Command): void;
@@ -0,0 +1,14 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * `sim workflows source status [--dir <dir>]`: the local changes since the directory was read,
4
+ * and (unless `--offline`, or when the server cannot be reached) whether the workflow changed on
5
+ * the server since, from a dry run. Ends with the next command.
6
+ */
7
+ export declare function attachWorkflowSourceStatus(source: Command): void;
8
+ /**
9
+ * `sim workflows source diff [paths...] [--dir <dir>] [--server]`: the content of each change.
10
+ * Without `--server`, each locally changed file against what the directory was read at (the
11
+ * server's current text of a file whose digest still matches the record, since the CLI keeps
12
+ * only digests); with it, every file against the server's current source.
13
+ */
14
+ export declare function attachWorkflowSourceDiff(source: Command): void;
@@ -0,0 +1,15 @@
1
+ import type { Command } from 'commander';
2
+ import type { ApplyWorkspaceSourceResponse } from '../../generated/v2-api';
3
+ type ApplyData = ApplyWorkspaceSourceResponse['data'];
4
+ type Change = ApplyData['plan'][number];
5
+ /** The changes that delete something (a resource, rows, documents, columns, a deployment). */
6
+ export declare function destructiveChanges(changes: readonly Change[]): number;
7
+ /**
8
+ * `sim workspaces source apply --dir <dir>`: applies a directory `workspaces source get` wrote.
9
+ * On a terminal it shows the plan and asks; anywhere else it needs `--yes`. Binary files are
10
+ * staged first, by hash (only those the server does not hold staged for this caller, so an
11
+ * interrupted upload resumes), then one apply names them: the server plans once and writes
12
+ * nothing when a blob it needs is missing.
13
+ */
14
+ export declare function attachWorkspaceSourceApply(source: Command): void;
15
+ export {};
@@ -0,0 +1,111 @@
1
+ import { type BlobEntry, type WorkspaceKind } from '@sim/workspace-code';
2
+ import type { GetWorkspaceSourceResponse } from '../../generated/v2-api';
3
+ import type { OperationClient } from '../../runtime/called-operations';
4
+ import { type FileStat, type StatDigest, type Written } from './source-dir';
5
+ type WorkspaceSource = GetWorkspaceSourceResponse['data'];
6
+ type ListedBlob = WorkspaceSource['blobs'][number];
7
+ /**
8
+ * The SHA-256 and size of the blob at `file` (the directory's `path`), with `current`, its stat
9
+ * taken before any read. The digest `written` records is reused only while every field of the stat
10
+ * recorded with it still holds (see {@link FileStat}); otherwise the file is read, so a same-size
11
+ * rewrite that kept its modification time is still seen as an edit.
12
+ */
13
+ export declare function statDigest(file: string, path: string, current: FileStat, written: Written): Promise<StatDigest>;
14
+ /**
15
+ * The digest of each of `paths` in the directory (see {@link statDigest}), read under one
16
+ * resolved root; a path with no file is left out.
17
+ */
18
+ export declare function blobDigests(dir: string, paths: readonly string[], written: Written): Promise<Map<string, StatDigest>>;
19
+ /**
20
+ * The blobs among `touched` (path → the SHA-256 about to be written, `null` when it is listed
21
+ * without one or removed) whose bytes on disk (`digests`, from {@link blobDigests}) are neither
22
+ * what the CLI last wrote there (`written`) nor what it is about to write. A blob the CLI wrote
23
+ * that is missing now counts as well, a delete no apply has sent: a removal names only a blob
24
+ * found on disk, so a missing one is about to be written again.
25
+ */
26
+ export declare function editedBlobs(touched: ReadonlyMap<string, string | null>, digests: ReadonlyMap<string, StatDigest>, written: Written['digests']): string[];
27
+ /** Refuses a listed blob the directory could not hold, before anything is downloaded. */
28
+ export declare function assertListedBlobs(blobs: readonly ListedBlob[]): void;
29
+ /**
30
+ * A blob's bytes in a get's downloads folder, verified against its listing. It carries no stat:
31
+ * the renames that move it into place change its change time, so the first command after the get
32
+ * reads it once and records the stat it then has.
33
+ */
34
+ export interface FetchedBlob {
35
+ sha256: string;
36
+ size: number;
37
+ file: string;
38
+ /** Whether a failed get keeps the file for the next one to reuse. */
39
+ kept: boolean;
40
+ }
41
+ /**
42
+ * The listed blob's bytes in `downloads`: the copy a failed get kept there when it still matches
43
+ * the listing (one that does not is discarded), else a fresh download, which is kept under its
44
+ * name once verified. The download streams into `partial`, this get's own folder inside
45
+ * `downloads`, as does a verified blob no later get could reuse, so removing that one folder (on an
46
+ * interrupt too) leaves only the kept copies behind.
47
+ */
48
+ export declare function fetchBlob(client: OperationClient<'downloadFile' | 'downloadKnowledgeDocument'>, blob: ListedBlob, downloads: string, partial: string): Promise<FetchedBlob>;
49
+ /**
50
+ * The base a get writes once it hashed the blobs the server listed without a hash (it had no
51
+ * budget left to): each such blob's resource records it as `{ id, rev, sha256 }`, and its
52
+ * fingerprint becomes that of the files the directory now holds for it, computed by the kind's
53
+ * codec exactly as an apply computes the directory's side. The next apply then judges the
54
+ * resource as one the server had hashed.
55
+ */
56
+ export declare function recordHashedBlobs(source: Pick<WorkspaceSource, 'files' | 'blobs' | 'base'>, digests: ReadonlyMap<string, string>): WorkspaceSource['base'];
57
+ /**
58
+ * The directory path of every blob the base records for `kinds`, with the SHA-256 it records: a
59
+ * workspace file's entry names its path, a knowledge base's names a document under its `docs/`
60
+ * folder.
61
+ */
62
+ export declare function baseBlobDigests(base: unknown, kinds: readonly WorkspaceKind[]): Map<string, string>;
63
+ /**
64
+ * The submitted blobs the server now holds byte for byte (the base an apply returned records the
65
+ * same SHA-256 for their path), as `.sim/written.json` records them: the directory's copy is what
66
+ * the CLI last synced, so a later removal reads as a delete and a server change as no local edit.
67
+ */
68
+ export declare function appliedBlobDigests(submission: {
69
+ kinds: readonly WorkspaceKind[];
70
+ blobs: ReadonlyArray<BlobEntry>;
71
+ }, base: unknown): Record<string, string>;
72
+ /**
73
+ * The submitted blobs whose bytes the server needs: new since the get, or changed (the base
74
+ * records another SHA-256 for their path). An apply without a dry run stages them; a blob the
75
+ * server needs beyond them is refused by name (`E_BLOB_MISSING`), and the CLI stages it and
76
+ * applies once more.
77
+ */
78
+ export declare function blobsToStage(submission: {
79
+ kinds: readonly WorkspaceKind[];
80
+ blobs: ReadonlyArray<BlobEntry>;
81
+ base?: unknown;
82
+ }): Set<string>;
83
+ /**
84
+ * Refuses an apply whose base records blobs the directory never held: missing on disk and absent
85
+ * from `.sim/written.json`, so no get downloaded them and no one removed them. Sent as they are,
86
+ * every one of them would read as deleted. A blob the CLI wrote and the user then removed is
87
+ * recorded, so its delete still goes through.
88
+ */
89
+ export declare function assertBlobsFetched(dir: string, submission: {
90
+ kinds: readonly WorkspaceKind[];
91
+ blobs: ReadonlyArray<{
92
+ path: string;
93
+ }>;
94
+ base?: unknown;
95
+ }, written: Written['digests']): void;
96
+ /** The bytes of the blob at `path` in the directory, read inside its resolved root. */
97
+ export declare function blobBytes(dir: string, path: string): Promise<Buffer>;
98
+ /** The calls staging makes. */
99
+ type StagingClient = OperationClient<'findMissingWorkspaceSourceBlobs' | 'stageWorkspaceSourceBlobs'>;
100
+ /**
101
+ * Stages the bytes of the blobs at `paths` for an apply to `workspaceId`: asks which of their
102
+ * hashes the server does not hold staged for this caller, then uploads only those, in requests of
103
+ * at most `maxBlobBytesPerRequest` (a larger blob alone). A blob staged by an earlier, interrupted run is not sent
104
+ * again. A file whose bytes no longer hash to what the directory read is refused before it is
105
+ * sent. Returns how many blobs and bytes were uploaded.
106
+ */
107
+ export declare function stageBlobs(client: StagingClient, workspaceId: string, dir: string, blobs: readonly BlobEntry[], paths: ReadonlySet<string>): Promise<{
108
+ count: number;
109
+ bytes: number;
110
+ }>;
111
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * `sim workspaces source check [--dir <dir>]`: compiles every workflow of a workspace source
4
+ * directory locally, each with the workspace's own declarations, so an agent's edit loop catches
5
+ * an unknown key or column without the network. The dry run stays the authority.
6
+ */
7
+ export declare function attachWorkspaceSourceCheck(source: Command): void;