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.
- package/README.md +42 -0
- package/THIRD_PARTY_LICENSES +31 -0
- package/dist/auth/refresh.d.ts +2 -1
- package/dist/commands/protocol/files-get.d.ts +3 -0
- package/dist/commands/protocol/result.d.ts +7 -1
- package/dist/commands/protocol/source-dir.d.ts +263 -0
- package/dist/commands/protocol/source-exit-codes.d.ts +8 -0
- package/dist/commands/protocol/source-primer.d.ts +14 -0
- package/dist/commands/protocol/source-status.d.ts +145 -0
- package/dist/commands/protocol/source-tree.d.ts +159 -0
- package/dist/commands/protocol/source-ui.d.ts +89 -0
- package/dist/commands/protocol/stored-edges.d.ts +44 -0
- package/dist/commands/protocol/workflow-source-apply.d.ts +38 -0
- package/dist/commands/protocol/workflow-source-check.d.ts +70 -0
- package/dist/commands/protocol/workflow-source-get.d.ts +40 -0
- package/dist/commands/protocol/workflow-source-params.d.ts +7 -0
- package/dist/commands/protocol/workflow-source-status.d.ts +14 -0
- package/dist/commands/protocol/workspace-source-apply.d.ts +15 -0
- package/dist/commands/protocol/workspace-source-blobs.d.ts +111 -0
- package/dist/commands/protocol/workspace-source-check.d.ts +7 -0
- package/dist/commands/protocol/workspace-source-dir.d.ts +135 -0
- package/dist/commands/protocol/workspace-source-get.d.ts +13 -0
- package/dist/commands/protocol/workspace-source-status.d.ts +13 -0
- package/dist/embed-context.d.ts +6 -3
- package/dist/exit-codes.d.ts +66 -0
- package/dist/generated/v2-api.d.ts +1297 -1
- package/dist/http/client.d.ts +22 -0
- package/dist/index.js +58843 -20211
- package/dist/output/io.d.ts +6 -0
- package/dist/program.d.ts +1 -1
- package/dist/runtime.js +59083 -20451
- package/dist/terminal/interrupts.d.ts +23 -0
- package/dist/terminal/line-input.d.ts +8 -0
- package/dist/terminal.d.ts +1 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -315,6 +315,48 @@ sim secrets set API_KEY --scope workspace --value @secret.txt
|
|
|
315
315
|
printf '%s' "$API_KEY" | sim secrets set API_KEY --scope workspace --value @-
|
|
316
316
|
```
|
|
317
317
|
|
|
318
|
+
## Exit codes
|
|
319
|
+
|
|
320
|
+
Success exits 0 and most failures exit 1. Two failures any command can hit have their own codes:
|
|
321
|
+
13 (`AUTH_REQUIRED`) when the profile has no login, its OAuth login expired, or the server answered
|
|
322
|
+
`401` (run `sim login`), and 9 when the API answered `429`. Every `GET`, and the source applies,
|
|
323
|
+
creates and dry runs, are resent up to 6 times first, each wait the longer of `Retry-After` (up to
|
|
324
|
+
60 seconds) and a backoff of about 1 to 30 seconds; any other write exits 9 at once. Before this
|
|
325
|
+
release both exited 1. Ctrl-C exits 130; a source apply or create already sent is finished and
|
|
326
|
+
saved into its directory first. The `workflows source` and `workspaces source` commands also use
|
|
327
|
+
5 (stale), 6 (a locked workflow or folder; a locked block exits 1), 7 (too large), 8 (a workspace
|
|
328
|
+
apply stopped part-way), 10 (busy), 11 (status: local changes) and 12 (status: the server
|
|
329
|
+
changed). Command-specific codes: [Exit codes](https://docs.sim.ai/cli/scripting#exit-codes).
|
|
330
|
+
|
|
331
|
+
## Workflows and workspaces as code
|
|
332
|
+
|
|
333
|
+
A workflow can be read and saved as a TypeScript file, and a whole workspace as a
|
|
334
|
+
directory. These commands are in preview: they work once workflows as code is
|
|
335
|
+
enabled on your Sim deployment.
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
sim workflows source get <workflowId> --dir ./support-triage # write workflow.ts, types and .sim/
|
|
339
|
+
sim workflows source check --dir ./support-triage # compile offline, no request
|
|
340
|
+
sim workflows source status --dir ./support-triage # your edits, server changes, next step
|
|
341
|
+
sim workflows source diff --dir ./support-triage # your edits as a unified diff
|
|
342
|
+
sim workflows source apply --dir ./support-triage --dry-run # run every check a save runs
|
|
343
|
+
sim workflows source apply --dir ./support-triage --yes # save the draft (never deploys)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
`sim workspaces source get|check|status|diff|apply --dir <dir>` does the same for
|
|
347
|
+
tables, knowledge bases, files, custom tools, skills, MCP servers, workflows and
|
|
348
|
+
deployments in one directory. `sim workflows source create --dir <dir> --workspace <id>`
|
|
349
|
+
starts a new workflow in that workspace.
|
|
350
|
+
|
|
351
|
+
Coding agents (Claude Code, Cursor, Codex) start at `.sim/AGENTS.md`, which `get`
|
|
352
|
+
writes into the directory. The loop is get, edit `workflow.ts`, check, status,
|
|
353
|
+
apply with `--dry-run`, then apply with `--yes`. Saving source acts as a person:
|
|
354
|
+
use a personal API key or an OAuth login, since a workspace API key cannot save
|
|
355
|
+
workflows.
|
|
356
|
+
|
|
357
|
+
See [Workflows as code](https://docs.sim.ai/workflows/code) and
|
|
358
|
+
[Workspace as code](https://docs.sim.ai/workflows/workspace-code).
|
|
359
|
+
|
|
318
360
|
## CI and automation
|
|
319
361
|
|
|
320
362
|
In CI, use an API key instead of `sim login`:
|
package/THIRD_PARTY_LICENSES
CHANGED
|
@@ -76,3 +76,34 @@ LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
|
|
|
76
76
|
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
77
77
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
78
78
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
79
|
+
|
|
80
|
+
diff
|
|
81
|
+
BSD 3-Clause License
|
|
82
|
+
|
|
83
|
+
Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
|
|
84
|
+
All rights reserved.
|
|
85
|
+
|
|
86
|
+
Redistribution and use in source and binary forms, with or without
|
|
87
|
+
modification, are permitted provided that the following conditions are met:
|
|
88
|
+
|
|
89
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
90
|
+
list of conditions and the following disclaimer.
|
|
91
|
+
|
|
92
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
93
|
+
this list of conditions and the following disclaimer in the documentation
|
|
94
|
+
and/or other materials provided with the distribution.
|
|
95
|
+
|
|
96
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
97
|
+
contributors may be used to endorse or promote products derived from
|
|
98
|
+
this software without specific prior written permission.
|
|
99
|
+
|
|
100
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
101
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
102
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
103
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
104
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
105
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
106
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
107
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
108
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
109
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/dist/auth/refresh.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { type ResolvedProfile, type StoredOAuthCredential } from '../config/inde
|
|
|
11
11
|
* `invalid_grant` means the server no longer honours the refresh token — it
|
|
12
12
|
* was revoked from Settings → General → Authorized apps, expired, or was already rotated
|
|
13
13
|
* by a process this one could not see — and the remedy is logout followed by a
|
|
14
|
-
* new login.
|
|
14
|
+
* new login, so it exits as `AUTH_REQUIRED` (13). Any other failure, such as an
|
|
15
|
+
* unreachable server, keeps its own error.
|
|
15
16
|
*/
|
|
16
17
|
export declare function refreshStoredOAuth(profile: Pick<ResolvedProfile, 'name' | 'endpoint' | 'authProfile'>, current: StoredOAuthCredential): Promise<StoredOAuthCredential>;
|
|
@@ -12,6 +12,9 @@ export declare function streamToFile(body: ReadableStream<Uint8Array>, file: Wri
|
|
|
12
12
|
* The removal is synchronous because the termination that follows gives an
|
|
13
13
|
* async `rm` no turn to run.
|
|
14
14
|
*
|
|
15
|
+
* An interrupt held by {@link interruptsDeferred} is left alone: the deferral
|
|
16
|
+
* raises it again when its write is done, and the cleanup runs then.
|
|
17
|
+
*
|
|
15
18
|
* Exported for its own test: driving it through a real interrupt would take the
|
|
16
19
|
* test runner down with it.
|
|
17
20
|
*/
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { OutputFormat } from '../../config/index';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Prints a protocol command's result: the record itself in a machine format, else one line per
|
|
4
|
+
* field, with `display` replacing the text of the fields it names (a list a person reads as a
|
|
5
|
+
* sentence rather than as JSON). An override is built from server text (resource keys, ids), so it
|
|
6
|
+
* is sanitized like every other field.
|
|
7
|
+
*/
|
|
8
|
+
export declare function printProtocolResult(format: OutputFormat, result: Record<string, unknown>, display?: Readonly<Record<string, string>>): void;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source directory on disk, for `workflows source` (one workflow's directory) and
|
|
3
|
+
* `workspaces source` (whose `workflows/<key>/` folders are each one): its layout beside the
|
|
4
|
+
* printed files, and the only code that reads or writes it. One definition, so the commands
|
|
5
|
+
* cannot drift apart.
|
|
6
|
+
*
|
|
7
|
+
* Every path is relative to `realpath(--dir)` and no component below it may be a symbolic link,
|
|
8
|
+
* so nothing is read from or written to outside the directory, whatever a link in it points at.
|
|
9
|
+
* Writes are staged in the directory first and moved into place, so a failed write leaves the
|
|
10
|
+
* files it did not reach as they were. An embedded run reads and writes through its host instead.
|
|
11
|
+
*/
|
|
12
|
+
import type { Stats } from 'node:fs';
|
|
13
|
+
import type { Command } from 'commander';
|
|
14
|
+
import type { ResolvedProfile } from '../../config/index';
|
|
15
|
+
/** Generated SDK declarations: the blocks the source uses (every block's are cached), plus `workspace.d.ts`. */
|
|
16
|
+
export declare const SOURCE_SDK_DIR = ".sim/sdk";
|
|
17
|
+
/** A short guide for an agent working in the directory; never a top-level `AGENTS.md`. */
|
|
18
|
+
export declare const SOURCE_AGENTS_FILE = ".sim/AGENTS.md";
|
|
19
|
+
/**
|
|
20
|
+
* Example workflows (`cookbook.ts`, `integrations.ts`, `agents.ts`): together one correct example
|
|
21
|
+
* of each common block, rewritten on every get like the agent guide. They name example resources
|
|
22
|
+
* the workspace may lack, so the written `tsconfig.json` never includes them.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SOURCE_EXAMPLES_DIR = ".sim/examples";
|
|
25
|
+
/** Pins the source files to LF, merged into whatever the directory already holds. */
|
|
26
|
+
export declare const SOURCE_GITATTRIBUTES_FILE = ".gitattributes";
|
|
27
|
+
/** Keeps a command's transient files out of a repository, merged like `.gitattributes`. */
|
|
28
|
+
export declare const SOURCE_GITIGNORE_FILE = ".gitignore";
|
|
29
|
+
/**
|
|
30
|
+
* A digest of each source file as the CLI last wrote it, so a later get can tell an unapplied
|
|
31
|
+
* edit from a file it may replace. The CLI's own record: never sent to the server.
|
|
32
|
+
*/
|
|
33
|
+
export declare const SOURCE_WRITTEN_FILE = ".sim/written.json";
|
|
34
|
+
/**
|
|
35
|
+
* The workspace a starter written by `workflows source create` was typed for, so the create that
|
|
36
|
+
* follows targets that workspace. The CLI's own record: never sent, and removed once the workflow
|
|
37
|
+
* exists.
|
|
38
|
+
*/
|
|
39
|
+
export declare const SOURCE_STARTER_FILE = ".sim/starter.json";
|
|
40
|
+
/**
|
|
41
|
+
* The edges of the workflow a get or apply printed, by lock key, with the base fingerprint they
|
|
42
|
+
* belong to, so an offline check tells an edge the stored workflow holds from one the source
|
|
43
|
+
* adds. The CLI's own record: never sent to the server.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SOURCE_STORED_EDGES_FILE = ".sim/stored-edges.json";
|
|
46
|
+
/**
|
|
47
|
+
* Where a workspace get keeps the blobs it verified until they move into place. A get that fails
|
|
48
|
+
* leaves them there, so the next one downloads only the rest; the one that completes removes the
|
|
49
|
+
* folder.
|
|
50
|
+
*/
|
|
51
|
+
export declare const SOURCE_DOWNLOADS_DIR = ".sim/downloads";
|
|
52
|
+
/** The folder a write stages its files in before moving them into place; removed when it ends. */
|
|
53
|
+
export declare const SOURCE_STAGING_PREFIX = ".sim-staging-";
|
|
54
|
+
/** Refuses a server answer naming a file the printer never writes, before anything is written. */
|
|
55
|
+
export declare function assertPrintedSourcePaths(files: Record<string, string>): void;
|
|
56
|
+
/** Files read or written at once on a local disk; a catalog's declarations run to hundreds of small files. */
|
|
57
|
+
export declare const FILE_CONCURRENCY = 32;
|
|
58
|
+
/**
|
|
59
|
+
* A path inside the source directory, normalized (`./functions/x.js` → `functions/x.js`), or
|
|
60
|
+
* `null` for an absolute path, a drive letter or a `..` escape.
|
|
61
|
+
*/
|
|
62
|
+
export declare function sourceRelativePath(path: string): string | null;
|
|
63
|
+
/** Every `codeFile` a lock records, as source-relative paths. */
|
|
64
|
+
export declare function lockCodeFiles(lock: unknown): Set<string>;
|
|
65
|
+
/**
|
|
66
|
+
* The function files a write leaves behind: named by the lock the directory held (so the CLI
|
|
67
|
+
* wrote them), no longer named by the new lock, and not being written now. A file the person
|
|
68
|
+
* added and no lock ever named is never pruned.
|
|
69
|
+
*/
|
|
70
|
+
export declare function orphanedCodeFiles(previousLock: unknown, nextLock: unknown, written: Iterable<string>): string[];
|
|
71
|
+
/**
|
|
72
|
+
* The lock an earlier get, apply or create left, read leniently (missing or invalid is `null`):
|
|
73
|
+
* it names the function files the CLI wrote, which is all a prune needs from it.
|
|
74
|
+
*/
|
|
75
|
+
export declare function readPreviousLock(dir: string): Promise<unknown>;
|
|
76
|
+
/** A JSON file in the source directory, read leniently: `null` when it is missing or invalid. */
|
|
77
|
+
export declare function readSourceJson(dir: string, path: string): Promise<unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* Makes `command`'s `--dir` (given or defaulted) an absolute path before its action runs, so every
|
|
80
|
+
* message names the directory it read wherever the CLI ran: a wrapper that changes directory
|
|
81
|
+
* first made `.` name a folder its caller never meant. An embedded run keeps its host's path.
|
|
82
|
+
*/
|
|
83
|
+
export declare function absoluteDirOption(command: Command): Command;
|
|
84
|
+
/**
|
|
85
|
+
* The workspace a source command acts on for a directory read from `readFrom`: that workspace,
|
|
86
|
+
* whatever the profile's default, so a directory stays bound to where it came from. Only a
|
|
87
|
+
* `--workspace` naming another one is refused, with `next` saying what to run instead (given the
|
|
88
|
+
* workspace the directory was read from and the one named). A directory that records no workspace
|
|
89
|
+
* takes the profile's (`null` when none is selected).
|
|
90
|
+
*/
|
|
91
|
+
export declare function directoryWorkspace(dir: string, readFrom: string | null, profile: Pick<ResolvedProfile, 'workspaceId' | 'sources'>, next: (readFrom: string, named: string) => string): string | null;
|
|
92
|
+
/** The workspace {@link SOURCE_STARTER_FILE} names, or `null` when the directory holds no starter. */
|
|
93
|
+
export declare function readStarterWorkspace(dir: string): Promise<string | null>;
|
|
94
|
+
/**
|
|
95
|
+
* A line file (`.gitattributes`, `.gitignore`) with `lines` appended where missing, or `null`
|
|
96
|
+
* when it has them all.
|
|
97
|
+
*/
|
|
98
|
+
export declare function withMissingLines(existing: string | null, lines?: readonly string[]): string | null;
|
|
99
|
+
/** Whether a file-system error means the path does not exist (`ENOENT`, or a file as a folder). */
|
|
100
|
+
export declare function isMissing(error: unknown): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* The absolute path of `path` under `root` (already a realpath), refusing a symbolic link at any
|
|
103
|
+
* component that exists. `verified` caches directories already checked across one operation.
|
|
104
|
+
*/
|
|
105
|
+
export declare function checkedPath(root: string, path: string, verified: Set<string>): Promise<string>;
|
|
106
|
+
/**
|
|
107
|
+
* The text of `path` in the source directory, normalized by `normalizeSourceText`, or `null` when
|
|
108
|
+
* it does not exist. A symbolic link anywhere below the directory is refused rather than followed.
|
|
109
|
+
*/
|
|
110
|
+
export declare function readSourceText(dir: string, path: string): Promise<string | null>;
|
|
111
|
+
/** What one write does to the source directory: files to remove first, then files to write. */
|
|
112
|
+
export interface SourceDirChange {
|
|
113
|
+
write: ReadonlyArray<readonly [path: string, text: string]>;
|
|
114
|
+
/**
|
|
115
|
+
* Files whose bytes `stage` writes into the staged file it is handed (a download), before
|
|
116
|
+
* anything is moved into place: one that throws leaves the directory as it was.
|
|
117
|
+
*/
|
|
118
|
+
fetch?: ReadonlyArray<readonly [path: string, stage: (stagedFile: string) => Promise<void>]>;
|
|
119
|
+
/** Files or directories (removed recursively); an embedded run cannot remove, so skips these. */
|
|
120
|
+
remove?: readonly string[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Applies a change to the source directory, creating it when absent. Every target is checked
|
|
124
|
+
* before anything is touched; the files are written to a staging directory inside it, then the
|
|
125
|
+
* removals run and each file is renamed into place, never through a link, the record files last.
|
|
126
|
+
*/
|
|
127
|
+
export declare function updateSourceDir(dir: string, change: SourceDirChange): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* What identifies a file's bytes without reading them, taken when its digest was: the file (device
|
|
130
|
+
* and inode), its size, and its modification and change times. The change time is the one a user
|
|
131
|
+
* tool cannot set back (`cp -p`, `rsync -t` and `touch -d` restore only the modification time), so
|
|
132
|
+
* any write since the digest moves it even when the size and modification time match.
|
|
133
|
+
*/
|
|
134
|
+
export interface FileStat {
|
|
135
|
+
dev: number;
|
|
136
|
+
ino: number;
|
|
137
|
+
size: number;
|
|
138
|
+
mtimeMs: number;
|
|
139
|
+
ctimeMs: number;
|
|
140
|
+
}
|
|
141
|
+
/** The {@link FileStat} of a `stat` result. */
|
|
142
|
+
export declare function fileStatOf(stats: FileStat): FileStat;
|
|
143
|
+
/** Whether two stats name the same, unchanged bytes. */
|
|
144
|
+
export declare function sameFileStat(a: FileStat, b: FileStat): boolean;
|
|
145
|
+
/** A blob's SHA-256 with the stat of the file it was read from. */
|
|
146
|
+
export interface StatDigest extends FileStat {
|
|
147
|
+
sha256: string;
|
|
148
|
+
}
|
|
149
|
+
/** `.sim/written.json` as one command reads it, once. */
|
|
150
|
+
export interface Written {
|
|
151
|
+
digests: Record<string, string>;
|
|
152
|
+
stats: Record<string, FileStat>;
|
|
153
|
+
}
|
|
154
|
+
/** The digest of `text` as `readSourceText` would read it back. */
|
|
155
|
+
export declare function digest(text: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* What `.sim/written.json` records for `files` as they are about to be written, keeping the `kept`
|
|
158
|
+
* digests of files this write leaves as they are. A blob's stat is recorded only beside the digest
|
|
159
|
+
* it was taken with.
|
|
160
|
+
*/
|
|
161
|
+
export declare function writtenRecord(files: Record<string, string>, kept?: Record<string, string>, stats?: ReadonlyMap<string, StatDigest>): Written;
|
|
162
|
+
/** The text of `.sim/written.json` for `written`. */
|
|
163
|
+
export declare function writtenFile(written: Written): string;
|
|
164
|
+
/** What the CLI recorded for its last write, empty when it recorded nothing. */
|
|
165
|
+
export declare function readWritten(dir: string): Promise<Written>;
|
|
166
|
+
/** The blob digests `written` holds with their stats, to carry into the next record. */
|
|
167
|
+
export declare function recordedStats(written: Written): Map<string, StatDigest>;
|
|
168
|
+
/**
|
|
169
|
+
* The files among `touched` (path → the text about to be written, or `null` for a removal) whose
|
|
170
|
+
* text on disk is neither what the CLI last wrote there nor what it is about to write: a write
|
|
171
|
+
* would destroy an edit no apply has saved. A file the CLI has no record of counts as edited, so a
|
|
172
|
+
* hand-written file is never replaced silently either; so does one the CLI wrote that is missing
|
|
173
|
+
* now and would be written again, a delete no apply has sent.
|
|
174
|
+
*/
|
|
175
|
+
export declare function editedFiles(dir: string, touched: ReadonlyMap<string, string | null>, written: Written['digests']): Promise<string[]>;
|
|
176
|
+
/**
|
|
177
|
+
* The source files a write of `answer` would destroy edits in: a file it replaces or prunes whose
|
|
178
|
+
* text on disk is neither what the CLI last wrote there nor what it is about to write.
|
|
179
|
+
*/
|
|
180
|
+
export declare function locallyEditedFiles(dir: string, answer: Pick<PrintedSourceAnswer, 'files' | 'lock'>, previousLock: unknown): Promise<string[]>;
|
|
181
|
+
/**
|
|
182
|
+
* A `workflows/<key>` folder of a workspace directory: `root` holds a workspace `.sim/base.json`.
|
|
183
|
+
* The workspace's `.sim/written.json` and base are the folder's records too, so a single-workflow
|
|
184
|
+
* write keeps them instead of writing a record of its own the workspace commands never read.
|
|
185
|
+
*/
|
|
186
|
+
export interface WorkspaceFolder {
|
|
187
|
+
root: string;
|
|
188
|
+
workspaceId: string;
|
|
189
|
+
/** The folder's key under `workflows/`. */
|
|
190
|
+
key: string;
|
|
191
|
+
}
|
|
192
|
+
/** The workspace directory `dir` is a workflow folder of, or `null`. */
|
|
193
|
+
export declare function workspaceFolderOf(dir: string): Promise<WorkspaceFolder | null>;
|
|
194
|
+
/**
|
|
195
|
+
* What the CLI last wrote into the workflow directory `dir`: its own `.sim/written.json`, or for a
|
|
196
|
+
* workflow folder of a workspace directory, the workspace record's entries for the folder (its
|
|
197
|
+
* `.sim/` records left out). A write into such a folder records there and never in the folder, but
|
|
198
|
+
* a CLI from before that left a record of the folder's own. That record wins only when it is the
|
|
199
|
+
* later one: when the workspace record's digest of the folder's `.sim/base.json` is not the base on
|
|
200
|
+
* disk, a single-workflow write replaced the base after the workspace record was taken. Otherwise
|
|
201
|
+
* the folder's own record is stale and ignored.
|
|
202
|
+
*/
|
|
203
|
+
export declare function readFolderWritten(dir: string): Promise<Written>;
|
|
204
|
+
/**
|
|
205
|
+
* Every plain file under `folder` in the source directory, as source-relative paths. A symbolic
|
|
206
|
+
* link anywhere is refused rather than followed; a missing folder lists nothing.
|
|
207
|
+
*/
|
|
208
|
+
export declare function listSourceFiles(dir: string, folder: string): Promise<string[]>;
|
|
209
|
+
/** What the server answers a get, apply or create with: the printed files, lock and base. */
|
|
210
|
+
interface PrintedSourceAnswer {
|
|
211
|
+
files: Record<string, string>;
|
|
212
|
+
lock: unknown;
|
|
213
|
+
base: unknown;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Writes a server answer into the source directory in one staged update: its files, lock and base,
|
|
217
|
+
* plus `extra`, pruning the function files the previous lock named and the new one no longer does.
|
|
218
|
+
* Returns how many files it wrote.
|
|
219
|
+
*/
|
|
220
|
+
export declare function writeBack(dir: string, answer: PrintedSourceAnswer, previousLock: unknown, extra?: SourceDirChange): Promise<number>;
|
|
221
|
+
/**
|
|
222
|
+
* Held while a command reads and rewrites a source directory, so two commands on one directory
|
|
223
|
+
* (an agent and a person, two terminals) never interleave their writes: each file moves into
|
|
224
|
+
* place atomically, but a set of them does not, and records from one command beside text from
|
|
225
|
+
* another would send stale text as an edit. A folder, since creating one is atomic everywhere.
|
|
226
|
+
*/
|
|
227
|
+
export declare const SOURCE_DIR_LOCK = ".sim/command.lock";
|
|
228
|
+
/** The help line every command that holds {@link SOURCE_DIR_LOCK} adds to its exit codes. */
|
|
229
|
+
export declare const SOURCE_DIR_BUSY_HELP = "\nExit 10 (busy, retry): another sim workspaces source command is using this directory\n(SOURCE_DIR_BUSY); nothing was read or written. Run this one again once it finished.";
|
|
230
|
+
/** The lock folder a command found, as it found it: which folder, and when it last changed. */
|
|
231
|
+
type LockSighting = Pick<Stats, 'dev' | 'ino' | 'mtimeMs'>;
|
|
232
|
+
/**
|
|
233
|
+
* Removes the lock at `lock`, which the caller found stale as `seen`, unless another command took
|
|
234
|
+
* it over first. Two commands can find one lock stale at once: one removes it and takes the lock,
|
|
235
|
+
* and the other, acting on what it saw before, must not remove the live lock that replaced it. So
|
|
236
|
+
* a takeover first claims the lock folder it means to remove (creating {@link LOCK_TAKEOVER_DIR}
|
|
237
|
+
* in it, which only one command can), then removes it only while it is still the folder it saw
|
|
238
|
+
* and still stale; a lock that replaced the stale one is another folder or records a live owner,
|
|
239
|
+
* so the late command leaves it. A command that died mid-takeover leaves its claim in a stale
|
|
240
|
+
* lock, which the busy message says to remove.
|
|
241
|
+
*/
|
|
242
|
+
export declare function takeOverStaleLock(lock: string, seen: LockSighting): Promise<void>;
|
|
243
|
+
/**
|
|
244
|
+
* Runs `run` holding the directory's command lock ({@link SOURCE_DIR_LOCK}). A second command on
|
|
245
|
+
* the directory meanwhile is refused (`SOURCE_DIR_BUSY`, exit 10) with nothing read or written; a
|
|
246
|
+
* lock its command left behind when it died is taken over ({@link takeOverStaleLock}). Like every
|
|
247
|
+
* other source path, `.sim` and the lock are never followed through a symbolic link
|
|
248
|
+
* (`SOURCE_SYMLINK`). An embedded run has no local directory to lock.
|
|
249
|
+
*/
|
|
250
|
+
export declare function withSourceDirLock<T>(dir: string, run: () => Promise<T>, options?: {
|
|
251
|
+
readOnly?: boolean;
|
|
252
|
+
}): Promise<T>;
|
|
253
|
+
/**
|
|
254
|
+
* Runs a single-workflow command on `dir` holding the command lock of the workspace directory it
|
|
255
|
+
* is a workflow folder of, if any: such a command rewrites the workspace's own records (see
|
|
256
|
+
* {@link writeBack}), so it must not interleave with a workspace command, or with another workflow
|
|
257
|
+
* command in a sibling folder. Refused like a workspace command (`SOURCE_DIR_BUSY`, exit 10), with
|
|
258
|
+
* nothing read or written.
|
|
259
|
+
*/
|
|
260
|
+
export declare function withWorkspaceFolderLock<T>(dir: string, run: () => Promise<T>): Promise<T>;
|
|
261
|
+
/** The help line every single-workflow command that writes a directory adds to its exit codes. */
|
|
262
|
+
export declare const WORKSPACE_FOLDER_BUSY_HELP = "\nExit 10 (busy, retry): --dir is a workflow folder of a workspace directory another sim command is\nusing (SOURCE_DIR_BUSY); nothing was read or written. Run this one again once it finished.";
|
|
263
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every exit code of the `workflows source` and `workspaces source` commands, as the Markdown
|
|
3
|
+
* table both directory guides (`.sim/AGENTS.md`) print, built from the codes the CLI exits with so
|
|
4
|
+
* the guides cannot drift from them. `prefix` is the command group the guide is for.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sourceExitCodesTable(prefix: 'sim workflows source' | 'sim workspaces source'): string;
|
|
7
|
+
/** The exit codes every source write (apply, create) shares, appended to its help. */
|
|
8
|
+
export declare const SOURCE_WRITE_EXIT_CODES_HELP = "\nExit 13: not logged in, or the server refused the credential (AUTH_REQUIRED); nothing was sent.\nRun `sim login`, or fix or unset SIM_API_KEY when the key comes from it. Exit 130: interrupted\n(Ctrl-C). A write already sent is finished and saved into the directory first, waiting up to\n60s for its answer; a second Ctrl-C, or no answer by then, stops at once and prints that it may\nhave been written and how to check.";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The primer a source get prints and writes atop `.sim/AGENTS.md`: the few rules an agent needs to
|
|
3
|
+
* edit a source directory without reading the guide, plus a snippet for each builder the source
|
|
4
|
+
* already calls, so the blocks in front of it need no lookup. The guide below it is the reference.
|
|
5
|
+
*/
|
|
6
|
+
import type { BlockCatalog } from '@sim/workflow-code';
|
|
7
|
+
/** Which directory a primer is for. */
|
|
8
|
+
export type PrimerKind = 'workflow' | 'workspace';
|
|
9
|
+
/** The primer without its builder snippets stays within this many bytes. */
|
|
10
|
+
export declare const PRIMER_MAX_BYTES = 3072;
|
|
11
|
+
/** The primer for a `kind` directory, without builder snippets. */
|
|
12
|
+
export declare function sourcePrimer(kind: PrimerKind): string;
|
|
13
|
+
/** The primer with the snippets of the builders `sources` call. */
|
|
14
|
+
export declare function primerFor(kind: PrimerKind, catalog: BlockCatalog, sources: Iterable<string>): string;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `status` and `diff` print, shared by `workflows source` and `workspaces source`: the status
|
|
3
|
+
* report (local changes, drift, conflicts, the dry run's plan and the one next command), its exit
|
|
4
|
+
* status, the unified diff of each changed file, and the rule for when the server counts as
|
|
5
|
+
* unreachable, so both commands degrade to the local view the same way.
|
|
6
|
+
*/
|
|
7
|
+
import type { FileChange, SourceStatus } from '@sim/workspace-code/status';
|
|
8
|
+
import type { OutputFormat } from '../../config/index';
|
|
9
|
+
/** Whether the server was asked: `checked`, `unreachable` (degraded to local), or `offline`. */
|
|
10
|
+
export type ServerCheck = 'checked' | 'unreachable' | 'offline';
|
|
11
|
+
/** The next command a status recommends, and why. */
|
|
12
|
+
export interface NextStep {
|
|
13
|
+
command: string;
|
|
14
|
+
reason: string;
|
|
15
|
+
}
|
|
16
|
+
/** What `status --output json` prints; `plan` is the command's own dry-run summary. */
|
|
17
|
+
export interface StatusReport<Plan> extends SourceStatus {
|
|
18
|
+
dir: string;
|
|
19
|
+
server: ServerCheck;
|
|
20
|
+
/** Why the server was not checked, or what it left unchecked. */
|
|
21
|
+
note?: string;
|
|
22
|
+
plan: Plan | null;
|
|
23
|
+
next: NextStep | null;
|
|
24
|
+
}
|
|
25
|
+
/** The status exit codes, each documented in the commands' help. */
|
|
26
|
+
export declare const STATUS_EXIT_CODES_HELP = "\nExit codes: 0 clean (nothing to apply, and the server changed nothing since the directory was\nread); 11 local changes only (applying writes them); 12 the server changed since the\ndirectory was read: drift (a resource edited, added or deleted there that the directory leaves\nalone) or a conflict (also changed here, so applying it is refused as stale), with or without\nlocal changes; 7 the source is too large for the server to read in one dry run; 1 the command\nfailed; 13 not logged in (AUTH_REQUIRED) or the credential was refused: the status shows the\nlocal changes only, then run `sim login`. A server that cannot be reached is not a failure: the\nstatus shows the local changes only and says so (exit 0 or 11).";
|
|
27
|
+
/** What `diff` compares, and its exit codes. */
|
|
28
|
+
export declare const DIFF_HELP = "\nWithout --server, each file created, edited or deleted since the directory was read is shown\nagainst the text it was read at. The CLI records only each file's digest, so that text is the\nserver's current text where it still matches the digest; a file the server changed since is\nnamed instead (compare it with --server). A binary file is shown by its sizes. Paths filter by\nfile or folder (and in a workspace directory by kind:key, such as table:leads). Exit codes: 0 the\ndifferences were shown, whether or not there were any; 7 the source is too large for the server\nto read; 1 the command failed.";
|
|
29
|
+
/**
|
|
30
|
+
* The exit status of a status report: no login (`login` holds the command to run), else drift or
|
|
31
|
+
* conflict, else local changes, else clean.
|
|
32
|
+
*/
|
|
33
|
+
export declare function statusExitCode(state: SourceStatus['state'], login: string | null): number;
|
|
34
|
+
/**
|
|
35
|
+
* Whether `error` says this profile cannot authenticate: the CLI's own refusal of a profile with
|
|
36
|
+
* no login, or a credential the server refused (`401`, which exits 13 like it).
|
|
37
|
+
*/
|
|
38
|
+
export declare function credentialRefused(error: unknown): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Why the server could not be reached (no connection, a timeout, a gateway that gave up, no login
|
|
41
|
+
* on the profile or a credential it refused), as a sentence, or `null` for any other failure (a
|
|
42
|
+
* cancelled request included), which a status reports rather than hides.
|
|
43
|
+
*/
|
|
44
|
+
export declare function unreachableReason(error: unknown): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* The login a status recommends when `error` says the profile cannot authenticate (which a status
|
|
47
|
+
* treats as an unreachable server), or `null` for any other failure.
|
|
48
|
+
*/
|
|
49
|
+
export declare function loginCommand(error: unknown, authProfile: string): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* Prints a status: the machine shape for `json` and `yaml`, else one screen naming each local
|
|
52
|
+
* change, each drifted and conflicting resource, the dry run's summary line and the next command.
|
|
53
|
+
*/
|
|
54
|
+
export declare function printStatusReport<Plan>(format: OutputFormat, heading: string, report: StatusReport<Plan>, planLine: (plan: Plan) => string): void;
|
|
55
|
+
/** One file's difference, as `diff --output json` prints it. */
|
|
56
|
+
export interface FileDiff {
|
|
57
|
+
path: string;
|
|
58
|
+
change: FileChange;
|
|
59
|
+
/** A binary file: its sizes instead of a patch (`null` when not known). */
|
|
60
|
+
binary?: {
|
|
61
|
+
before: number | null;
|
|
62
|
+
after: number | null;
|
|
63
|
+
};
|
|
64
|
+
/** The unified diff, without the `Index:` header. */
|
|
65
|
+
patch?: string;
|
|
66
|
+
/** Why the file's other side could not be read, instead of a patch. */
|
|
67
|
+
unavailable?: string;
|
|
68
|
+
}
|
|
69
|
+
/** What `diff --output json` prints. */
|
|
70
|
+
export interface DiffReport {
|
|
71
|
+
dir: string;
|
|
72
|
+
/** `base`: local against what the directory was read at; `server`: against the server now. */
|
|
73
|
+
against: 'base' | 'server';
|
|
74
|
+
/** Why the server, which holds the base text, could not be reached. */
|
|
75
|
+
unreachable?: string;
|
|
76
|
+
files: FileDiff[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A changed file whose base text is not at hand: the CLI records only digests, so the base text
|
|
80
|
+
* is the server's current text where it still matches the record, and here the server either
|
|
81
|
+
* could not be reached (`unreachable`) or changed the file since.
|
|
82
|
+
*/
|
|
83
|
+
export declare function baseUnavailable(file: {
|
|
84
|
+
path: string;
|
|
85
|
+
change: FileChange;
|
|
86
|
+
}, unreachable: string | null): FileDiff;
|
|
87
|
+
/**
|
|
88
|
+
* The unified diff of one text file (`null` for a missing side: a created or deleted file), as a
|
|
89
|
+
* list holding it, or an empty list when the two are the same.
|
|
90
|
+
*/
|
|
91
|
+
export declare function textDiff(path: string, before: string | null, after: string | null, against: DiffReport['against']): FileDiff[];
|
|
92
|
+
/**
|
|
93
|
+
* Prints a diff: the machine shape for `json` and `yaml`, else each file's unified diff (colored
|
|
94
|
+
* when stdout is a terminal), a binary file's sizes, and the reason a file's other side is
|
|
95
|
+
* unavailable.
|
|
96
|
+
*/
|
|
97
|
+
export declare function printDiffReport(format: OutputFormat, report: DiffReport): void;
|
|
98
|
+
/** The paths a `diff [paths...]` names. */
|
|
99
|
+
export interface PathFilter {
|
|
100
|
+
/** Whether `path` (relative to the directory) is selected: every path when no filter is given. */
|
|
101
|
+
selects(path: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Refuses, naming each filter that selects none of `paths` (every path the comparison could
|
|
104
|
+
* show), so a mistyped filter is an error rather than "No local changes."
|
|
105
|
+
*/
|
|
106
|
+
assertEachMatches(paths: Iterable<string>): void;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The filter of `filters` against `dir`: a filter selects the path it names, every path under a
|
|
110
|
+
* folder it names, or (as `kind:key` given to `keyOf`) every file of that resource.
|
|
111
|
+
*/
|
|
112
|
+
export declare function pathFilter(filters: readonly string[], dir: string, keyOf?: (path: string) => string | null): PathFilter;
|
|
113
|
+
/** What the next command depends on beyond the status itself. */
|
|
114
|
+
interface NextStepInput {
|
|
115
|
+
/** `sim workspaces source` or `sim workflows source`. */
|
|
116
|
+
prefix: string;
|
|
117
|
+
dir: string;
|
|
118
|
+
/** What `get` takes before `--dir` (a workflow id), with its trailing space. */
|
|
119
|
+
getArgs: string;
|
|
120
|
+
server: ServerCheck;
|
|
121
|
+
/** Errors in the dry run, server changes left out. */
|
|
122
|
+
errors: number;
|
|
123
|
+
/**
|
|
124
|
+
* Whether the dry run deletes anything (a resource, or data an update drops), which applying
|
|
125
|
+
* needs `--allow-delete` for.
|
|
126
|
+
*/
|
|
127
|
+
deletes: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Arguments every recommended command carries after `--dir`, each with a leading space: the
|
|
130
|
+
* scope the status was asked for (`--only`, `--workspace`), so the command acts on what it showed.
|
|
131
|
+
*/
|
|
132
|
+
scope: string;
|
|
133
|
+
/**
|
|
134
|
+
* The login command when the server was not checked because the profile has no login: nothing
|
|
135
|
+
* else can be decided until it runs.
|
|
136
|
+
*/
|
|
137
|
+
login?: string | null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The one command a status recommends: get into a fresh directory on a conflict, get into this
|
|
141
|
+
* one when the server drifted and nothing here is unapplied, the dry run when the server was not
|
|
142
|
+
* checked or the changes have errors, else apply. `null` when there is nothing to do.
|
|
143
|
+
*/
|
|
144
|
+
export declare function nextStep(status: SourceStatus, input: NextStepInput): NextStep | null;
|
|
145
|
+
export {};
|