sim 2.2.33-preview.318.1 → 2.2.33-preview.320.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/dist/commands/protocol/local-errors.d.ts +35 -0
- package/dist/commands/protocol/source-check.d.ts +83 -0
- package/dist/commands/protocol/source-dir/command-lock.d.ts +49 -0
- package/dist/commands/protocol/source-dir/dir-kind.d.ts +43 -0
- package/dist/commands/protocol/source-dir/files.d.ts +63 -0
- package/dist/commands/protocol/source-dir/index.d.ts +12 -0
- package/dist/commands/protocol/source-dir/layout.d.ts +74 -0
- package/dist/commands/protocol/source-dir/write-back.d.ts +13 -0
- package/dist/commands/protocol/source-dir/written.d.ts +82 -0
- package/dist/commands/protocol/source-exit-codes.d.ts +14 -3
- package/dist/commands/protocol/source-status.d.ts +7 -0
- package/dist/commands/protocol/source-ui.d.ts +5 -1
- package/dist/commands/protocol/source-write.d.ts +58 -0
- package/dist/commands/protocol/workflow-dir.d.ts +61 -0
- package/dist/commands/protocol/workflow-source-apply.d.ts +0 -19
- package/dist/commands/protocol/workflow-source-check.d.ts +0 -63
- package/dist/commands/protocol/workflow-source-get.d.ts +0 -28
- package/dist/commands/protocol/workspace-source-apply.d.ts +0 -6
- package/dist/commands/protocol/workspace-source-dir.d.ts +9 -0
- package/dist/commands/protocol/workspace-source-get.d.ts +0 -5
- package/dist/exit-codes.d.ts +2 -2
- package/dist/generated/v2-api.d.ts +12 -9
- package/dist/index.js +11464 -11030
- package/dist/runtime.js +11464 -11030
- package/package.json +1 -1
- package/dist/commands/protocol/source-dir.d.ts +0 -284
package/package.json
CHANGED
|
@@ -1,284 +0,0 @@
|
|
|
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
|
-
/**
|
|
57
|
-
* Refuses, before a write is sent, a code file the server would store but the CLI could never
|
|
58
|
-
* write back: one rule ({@link isCodeFilePath}) for both, so an apply is never stored and then
|
|
59
|
-
* reported as failed.
|
|
60
|
-
*/
|
|
61
|
-
export declare function assertSendableCodeFiles(files: Record<string, string>): void;
|
|
62
|
-
/** Files read or written at once on a local disk; a catalog's declarations run to hundreds of small files. */
|
|
63
|
-
export declare const FILE_CONCURRENCY = 32;
|
|
64
|
-
/**
|
|
65
|
-
* A path inside the source directory, normalized (`./functions/x.js` → `functions/x.js`), or
|
|
66
|
-
* `null` for an absolute path, a drive letter or a `..` escape.
|
|
67
|
-
*/
|
|
68
|
-
export declare function sourceRelativePath(path: string): string | null;
|
|
69
|
-
/** Every `codeFile` a lock records, as source-relative paths. */
|
|
70
|
-
export declare function lockCodeFiles(lock: unknown): Set<string>;
|
|
71
|
-
/**
|
|
72
|
-
* The function files a write leaves behind: named by the lock the directory held (so the CLI
|
|
73
|
-
* wrote them), no longer named by the new lock, and not being written now. A file the person
|
|
74
|
-
* added and no lock ever named is never pruned.
|
|
75
|
-
*/
|
|
76
|
-
export declare function orphanedCodeFiles(previousLock: unknown, nextLock: unknown, written: Iterable<string>): string[];
|
|
77
|
-
/**
|
|
78
|
-
* The lock an earlier get, apply or create left, read leniently (missing or invalid is `null`):
|
|
79
|
-
* it names the function files the CLI wrote, which is all a prune needs from it.
|
|
80
|
-
*/
|
|
81
|
-
export declare function readPreviousLock(dir: string): Promise<unknown>;
|
|
82
|
-
/** A JSON file in the source directory, read leniently: `null` when it is missing or invalid. */
|
|
83
|
-
export declare function readSourceJson(dir: string, path: string): Promise<unknown>;
|
|
84
|
-
/**
|
|
85
|
-
* Makes `command`'s `--dir` (given or defaulted) an absolute path before its action runs, so every
|
|
86
|
-
* message names the directory it read wherever the CLI ran: a wrapper that changes directory
|
|
87
|
-
* first made `.` name a folder its caller never meant. An embedded run keeps its host's path.
|
|
88
|
-
*/
|
|
89
|
-
export declare function absoluteDirOption(command: Command): Command;
|
|
90
|
-
/**
|
|
91
|
-
* The workspace a source command acts on for a directory read from `readFrom`: that workspace,
|
|
92
|
-
* whatever the profile's default, so a directory stays bound to where it came from. Only a
|
|
93
|
-
* `--workspace` naming another one is refused, with `next` saying what to run instead (given the
|
|
94
|
-
* workspace the directory was read from and the one named). A directory that records no workspace
|
|
95
|
-
* takes the profile's (`null` when none is selected).
|
|
96
|
-
*/
|
|
97
|
-
export declare function directoryWorkspace(dir: string, readFrom: string | null, profile: Pick<ResolvedProfile, 'workspaceId' | 'sources'>, next: (readFrom: string, named: string) => string): string | null;
|
|
98
|
-
/** Which source command family a directory belongs to: one workflow's, or a whole workspace's. */
|
|
99
|
-
export type SourceDirKind = 'workflow' | 'workspace';
|
|
100
|
-
/**
|
|
101
|
-
* Refuses a `kind` command on a directory of the other kind, whatever `--force` says: a workflow
|
|
102
|
-
* get into a workspace directory (or the reverse) would replace its base, so staleness could no
|
|
103
|
-
* longer be detected and its unapplied edits would sit in a directory neither command reads.
|
|
104
|
-
*/
|
|
105
|
-
export declare function assertSourceDirKind(dir: string, kind: SourceDirKind): Promise<void>;
|
|
106
|
-
/** The workspace {@link SOURCE_STARTER_FILE} names, or `null` when the directory holds no starter. */
|
|
107
|
-
export declare function readStarterWorkspace(dir: string): Promise<string | null>;
|
|
108
|
-
/**
|
|
109
|
-
* A line file (`.gitattributes`, `.gitignore`) with `lines` appended where missing, or `null`
|
|
110
|
-
* when it has them all.
|
|
111
|
-
*/
|
|
112
|
-
export declare function withMissingLines(existing: string | null, lines?: readonly string[]): string | null;
|
|
113
|
-
/** Whether a file-system error means the path does not exist (`ENOENT`, or a file as a folder). */
|
|
114
|
-
export declare function isMissing(error: unknown): boolean;
|
|
115
|
-
/**
|
|
116
|
-
* The absolute path of `path` under `root` (already a realpath), refusing a symbolic link at any
|
|
117
|
-
* component that exists. `verified` caches directories already checked across one operation.
|
|
118
|
-
*/
|
|
119
|
-
export declare function checkedPath(root: string, path: string, verified: Set<string>): Promise<string>;
|
|
120
|
-
/**
|
|
121
|
-
* The text of `path` in the source directory, normalized by `normalizeSourceText`, or `null` when
|
|
122
|
-
* it does not exist. A symbolic link anywhere below the directory is refused rather than followed.
|
|
123
|
-
*/
|
|
124
|
-
export declare function readSourceText(dir: string, path: string): Promise<string | null>;
|
|
125
|
-
/** What one write does to the source directory: files to remove first, then files to write. */
|
|
126
|
-
export interface SourceDirChange {
|
|
127
|
-
write: ReadonlyArray<readonly [path: string, text: string]>;
|
|
128
|
-
/**
|
|
129
|
-
* Files whose bytes `stage` writes into the staged file it is handed (a download), before
|
|
130
|
-
* anything is moved into place: one that throws leaves the directory as it was.
|
|
131
|
-
*/
|
|
132
|
-
fetch?: ReadonlyArray<readonly [path: string, stage: (stagedFile: string) => Promise<void>]>;
|
|
133
|
-
/** Files or directories (removed recursively); an embedded run cannot remove, so skips these. */
|
|
134
|
-
remove?: readonly string[];
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Applies a change to the source directory, creating it when absent. Every target is checked
|
|
138
|
-
* before anything is touched; the files are written to a staging directory inside it, then the
|
|
139
|
-
* removals run and each file is renamed into place, never through a link, the record files last.
|
|
140
|
-
*/
|
|
141
|
-
export declare function updateSourceDir(dir: string, change: SourceDirChange): Promise<void>;
|
|
142
|
-
/**
|
|
143
|
-
* What identifies a file's bytes without reading them, taken when its digest was: the file (device
|
|
144
|
-
* and inode), its size, and its modification and change times. The change time is the one a user
|
|
145
|
-
* tool cannot set back (`cp -p`, `rsync -t` and `touch -d` restore only the modification time), so
|
|
146
|
-
* any write since the digest moves it even when the size and modification time match.
|
|
147
|
-
*/
|
|
148
|
-
export interface FileStat {
|
|
149
|
-
dev: number;
|
|
150
|
-
ino: number;
|
|
151
|
-
size: number;
|
|
152
|
-
mtimeMs: number;
|
|
153
|
-
ctimeMs: number;
|
|
154
|
-
}
|
|
155
|
-
/** The {@link FileStat} of a `stat` result. */
|
|
156
|
-
export declare function fileStatOf(stats: FileStat): FileStat;
|
|
157
|
-
/** Whether two stats name the same, unchanged bytes. */
|
|
158
|
-
export declare function sameFileStat(a: FileStat, b: FileStat): boolean;
|
|
159
|
-
/** A blob's SHA-256 with the stat of the file it was read from. */
|
|
160
|
-
export interface StatDigest extends FileStat {
|
|
161
|
-
sha256: string;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* What the CLI last wrote, as one command reads it, once: the digests from `.sim/written.json`
|
|
165
|
-
* and the stats from `.sim/cache/stats.json` that still match them.
|
|
166
|
-
*/
|
|
167
|
-
export interface Written {
|
|
168
|
-
digests: Record<string, string>;
|
|
169
|
-
stats: Record<string, FileStat>;
|
|
170
|
-
}
|
|
171
|
-
/** The digest of `text` as `readSourceText` would read it back. */
|
|
172
|
-
export declare function digest(text: string): string;
|
|
173
|
-
/**
|
|
174
|
-
* What `.sim/written.json` records for `files` as they are about to be written, keeping the `kept`
|
|
175
|
-
* digests of files this write leaves as they are. A blob's stat is recorded only beside the digest
|
|
176
|
-
* it was taken with.
|
|
177
|
-
*/
|
|
178
|
-
export declare function writtenRecord(files: Record<string, string>, kept?: Record<string, string>, stats?: ReadonlyMap<string, StatDigest>): Written;
|
|
179
|
-
/**
|
|
180
|
-
* The files that record `written`: `.sim/written.json` (committed) and, when a blob stat is
|
|
181
|
-
* recorded, the machine-local `.sim/cache/stats.json` with the cache folder's own `.gitignore`.
|
|
182
|
-
*/
|
|
183
|
-
export declare function writtenFiles(written: Written): Array<readonly [string, string]>;
|
|
184
|
-
/** What the CLI recorded for its last write, empty when it recorded nothing. */
|
|
185
|
-
export declare function readWritten(dir: string): Promise<Written>;
|
|
186
|
-
/** The blob digests `written` holds with their stats, to carry into the next record. */
|
|
187
|
-
export declare function recordedStats(written: Written): Map<string, StatDigest>;
|
|
188
|
-
/**
|
|
189
|
-
* The files among `touched` (path → the text about to be written, or `null` for a removal) whose
|
|
190
|
-
* text on disk is neither what the CLI last wrote there nor what it is about to write: a write
|
|
191
|
-
* would destroy an edit no apply has saved. A file the CLI has no record of counts as edited, so a
|
|
192
|
-
* hand-written file is never replaced silently either; so does one the CLI wrote that is missing
|
|
193
|
-
* now and would be written again, a delete no apply has sent.
|
|
194
|
-
*/
|
|
195
|
-
export declare function editedFiles(dir: string, touched: ReadonlyMap<string, string | null>, written: Written['digests']): Promise<string[]>;
|
|
196
|
-
/**
|
|
197
|
-
* The source files a write of `answer` would destroy edits in: a file it replaces or prunes whose
|
|
198
|
-
* text on disk is neither what the CLI last wrote there nor what it is about to write.
|
|
199
|
-
*/
|
|
200
|
-
export declare function locallyEditedFiles(dir: string, answer: Pick<PrintedSourceAnswer, 'files' | 'lock'>, previousLock: unknown): Promise<string[]>;
|
|
201
|
-
/**
|
|
202
|
-
* A `workflows/<key>` folder of a workspace directory: `root` holds a workspace `.sim/base.json`.
|
|
203
|
-
* The workspace's `.sim/written.json` and base are the folder's records too, so a single-workflow
|
|
204
|
-
* write keeps them instead of writing a record of its own the workspace commands never read.
|
|
205
|
-
*/
|
|
206
|
-
export interface WorkspaceFolder {
|
|
207
|
-
root: string;
|
|
208
|
-
workspaceId: string;
|
|
209
|
-
/** The folder's key under `workflows/`. */
|
|
210
|
-
key: string;
|
|
211
|
-
}
|
|
212
|
-
/** The workspace directory `dir` is a workflow folder of, or `null`. */
|
|
213
|
-
export declare function workspaceFolderOf(dir: string): Promise<WorkspaceFolder | null>;
|
|
214
|
-
/**
|
|
215
|
-
* What the CLI last wrote into the workflow directory `dir`: its own `.sim/written.json`, or for a
|
|
216
|
-
* workflow folder of a workspace directory, the workspace record's entries for the folder (its
|
|
217
|
-
* `.sim/` records left out). A write into such a folder records there and never in the folder, but
|
|
218
|
-
* a CLI from before that left a record of the folder's own. That record wins only when it is the
|
|
219
|
-
* later one: when the workspace record's digest of the folder's `.sim/base.json` is not the base on
|
|
220
|
-
* disk, a single-workflow write replaced the base after the workspace record was taken. Otherwise
|
|
221
|
-
* the folder's own record is stale and ignored.
|
|
222
|
-
*/
|
|
223
|
-
export declare function readFolderWritten(dir: string): Promise<Written>;
|
|
224
|
-
/**
|
|
225
|
-
* Every plain file under `folder` in the source directory, as source-relative paths. A symbolic
|
|
226
|
-
* link anywhere is refused rather than followed; a missing folder lists nothing.
|
|
227
|
-
*/
|
|
228
|
-
export declare function listSourceFiles(dir: string, folder: string): Promise<string[]>;
|
|
229
|
-
/** What the server answers a get, apply or create with: the printed files, lock and base. */
|
|
230
|
-
interface PrintedSourceAnswer {
|
|
231
|
-
files: Record<string, string>;
|
|
232
|
-
lock: unknown;
|
|
233
|
-
base: unknown;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Writes a server answer into the source directory in one staged update: its files, lock and base,
|
|
237
|
-
* plus `extra`, pruning the function files the previous lock named and the new one no longer does.
|
|
238
|
-
* Returns how many files it wrote. A get refuses an unsafe path first
|
|
239
|
-
* ({@link assertPrintedSourcePaths}); after a stored write one is skipped ({@link writableFiles}).
|
|
240
|
-
*/
|
|
241
|
-
export declare function writeBack(dir: string, answer: PrintedSourceAnswer, previousLock: unknown, extra?: SourceDirChange): Promise<number>;
|
|
242
|
-
/**
|
|
243
|
-
* Held while a command reads and rewrites a source directory, so two commands on one directory
|
|
244
|
-
* (an agent and a person, two terminals) never interleave their writes: each file moves into
|
|
245
|
-
* place atomically, but a set of them does not, and records from one command beside text from
|
|
246
|
-
* another would send stale text as an edit. A folder, since creating one is atomic everywhere.
|
|
247
|
-
*/
|
|
248
|
-
export declare const SOURCE_DIR_LOCK = ".sim/command.lock";
|
|
249
|
-
/** The help line every command that holds {@link SOURCE_DIR_LOCK} adds to its exit codes. */
|
|
250
|
-
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.";
|
|
251
|
-
/** The lock folder a command found, as it found it: which folder, and when it last changed. */
|
|
252
|
-
type LockSighting = Pick<Stats, 'dev' | 'ino' | 'mtimeMs'>;
|
|
253
|
-
/**
|
|
254
|
-
* Removes the lock at `lock`, which the caller found stale as `seen`, unless another command took
|
|
255
|
-
* it over first. Two commands can find one lock stale at once: one removes it and takes the lock,
|
|
256
|
-
* and the other, acting on what it saw before, must not remove the live lock that replaced it. So
|
|
257
|
-
* a takeover first claims the lock folder it means to remove (creating {@link LOCK_TAKEOVER_DIR}
|
|
258
|
-
* in it, which only one command can), then removes it only while it is still the folder it saw
|
|
259
|
-
* and still stale; a lock that replaced the stale one is another folder or records a live owner,
|
|
260
|
-
* so the late command leaves it. A command that died mid-takeover leaves its claim in a stale
|
|
261
|
-
* lock, which the busy message says to remove.
|
|
262
|
-
*/
|
|
263
|
-
export declare function takeOverStaleLock(lock: string, seen: LockSighting): Promise<void>;
|
|
264
|
-
/**
|
|
265
|
-
* Runs `run` holding the directory's command lock ({@link SOURCE_DIR_LOCK}). A second command on
|
|
266
|
-
* the directory meanwhile is refused (`SOURCE_DIR_BUSY`, exit 10) with nothing read or written; a
|
|
267
|
-
* lock its command left behind when it died is taken over ({@link takeOverStaleLock}). Like every
|
|
268
|
-
* other source path, `.sim` and the lock are never followed through a symbolic link
|
|
269
|
-
* (`SOURCE_SYMLINK`). An embedded run has no local directory to lock.
|
|
270
|
-
*/
|
|
271
|
-
export declare function withSourceDirLock<T>(dir: string, run: () => Promise<T>, options?: {
|
|
272
|
-
readOnly?: boolean;
|
|
273
|
-
}): Promise<T>;
|
|
274
|
-
/**
|
|
275
|
-
* Runs a single-workflow command on `dir` holding the command lock of the workspace directory it
|
|
276
|
-
* is a workflow folder of, if any: such a command rewrites the workspace's own records (see
|
|
277
|
-
* {@link writeBack}), so it must not interleave with a workspace command, or with another workflow
|
|
278
|
-
* command in a sibling folder. Refused like a workspace command (`SOURCE_DIR_BUSY`, exit 10), with
|
|
279
|
-
* nothing read or written.
|
|
280
|
-
*/
|
|
281
|
-
export declare function withWorkspaceFolderLock<T>(dir: string, run: () => Promise<T>): Promise<T>;
|
|
282
|
-
/** The help line every single-workflow command that writes a directory adds to its exit codes. */
|
|
283
|
-
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.";
|
|
284
|
-
export {};
|