@pipelex/sdk 0.69.5 → 0.71.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/artifacts.d.ts +46 -23
- package/dist/artifacts.js +89 -35
- package/dist/artifacts.js.map +1 -1
- package/dist/cli/script.d.ts +1 -1
- package/dist/client.d.ts +41 -5
- package/dist/client.js +91 -12
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +38 -16
- package/dist/errors.js +43 -16
- package/dist/errors.js.map +1 -1
- package/dist/hooks/claude-mthds-check.d.ts +2 -1
- package/dist/hooks/claude-mthds-check.js +5 -6
- package/dist/hooks/claude-mthds-check.js.map +1 -1
- package/dist/hooks/format-write.d.ts +67 -0
- package/dist/hooks/format-write.js +175 -0
- package/dist/hooks/format-write.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/product-models.d.ts +61 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/architecture.md +3 -3
- package/docs/artifact-download.md +10 -10
- package/docs/errors.md +2 -2
- package/docs/files.md +41 -1
- package/docs/hook-bundle.md +13 -1
- package/docs/run-results.md +8 -6
- package/package.json +1 -1
package/docs/hook-bundle.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## What the hook does with a file
|
|
6
6
|
|
|
7
|
-
Each file goes through three stages: a local lint that blocks on any diagnostic, a local format that rewrites the file
|
|
7
|
+
Each file goes through three stages: a local lint that blocks on any diagnostic, a local format that rewrites the file when its layout changes, and a validation by the hosted API (`POST /v1/validate`) that blocks on an invalid verdict and adds a non-blocking note about pending pipe signatures. The hook fails open: when the engine cannot load, when `PIPELEX_API_KEY` is unset or the API cannot be reached, the stage that could not run passes silently and the others stand. When several files are checked, one block among them wins and the notes are joined, and each file is read when its turn comes, so an edit made to it while an earlier file was being validated is checked rather than overwritten. The hook always exits 0, since its verdict is on stdout.
|
|
8
8
|
|
|
9
9
|
An invalid verdict blocks with the server's Markdown rendering of it, which the hook always asks for, forwarded verbatim. When the server sends none, the hook words the block itself: the file that failed, the verdict's message, then one line for each fault the verdict lists in `errors[]`, each an MTHDS problem item named by its code, its sentence and where it happened, with its suggested fix, when it carries one, on a line of its own. The place and the fix are worded by the `mthds` package's `formatLocation` and `formatSuggestedFix`, as every MTHDS client words them, and a fix of a safety the hook does not know is shown as unsafe:
|
|
10
10
|
|
|
@@ -22,6 +22,18 @@ The hook reads each item member by member, with the SDK's `readProblemItems`, as
|
|
|
22
22
|
|
|
23
23
|
The validation sends the method's tree around the file, the tree a run of the method would send: the edited file's directory listed by the `mthds` package's lister under the MTHDS standard's membership rule, so it is rooted at the nearest `METHODS.toml` at or above that directory, else at the directory itself, and holds every file the rule keeps — every bundle of the method, and every file a step reads, such as the template a `PipeDocGen` step names in `template_file`, under its tree path — while hidden entries, `node_modules`, `__pycache__`, what a `.gitignore` inside the tree keeps out and a run's inputs file never travel ([`method-trees.md`](./method-trees.md#the-four-forms-of-a-tree)), and neither does a file that looks like a secret ([below](#secrets-stay-home)). A method that fills a template thus validates as it would load from disk, its template checked by the dry run, and a step whose template file the tree does not hold makes the verdict say so, which blocks until the file is written. The client sends the tree inline when small and by hash otherwise, uploading the files the API lacks. The whole validation runs under one ten-second deadline, the version handshake, the blob route, the uploads and the validation request together, and the deadline stops whichever of them is under way when it runs out. Validation passes silently, as when the API cannot be reached, when that deadline runs out, when the tree holds a symbolic link or a directory the lister cannot read, when the edited file is not in its own tree because the rule keeps it out, when a file of the tree changes between its listing and its reading, when a file of the tree fails to upload, and past the hook's own caps: 100 files, 5 MiB for one of them or 12 MiB in all, each checked while the tree is listed, before any file is read.
|
|
24
24
|
|
|
25
|
+
### How the format is written
|
|
26
|
+
|
|
27
|
+
When the format changes nothing, the file is not written at all. When it changes the layout, the hook does not write into the user's file: it writes the formatted text to a temporary file in the same directory, gives it the original's owner and group, flushes it to disk, gives it the original's permission bits, then renames it over the original (`src/hooks/format-write.ts`). A rename within one directory is atomic, so a hook stopped at any moment, by the agent's hook timeout or by the plugin wrapper's kill, leaves either the original file or the formatted one, never a truncated one. The temporary file is named after the original with a leading dot and a random suffix, such as `.main.mthds.4242.1a2b3c4d5e6f.tmp`, so the tree the validation sends, which leaves hidden entries out, never holds it, and it is removed on every failure. A symbolic link is followed, so the file it points to is replaced and the link stays a link, and a file the user cannot write is refused, as an in-place write refused it. The path is resolved to the name the directory stores, so on a case-insensitive filesystem the file keeps its name's case whatever case the agent wrote the path in.
|
|
28
|
+
|
|
29
|
+
A rename puts a new file at the original's name, so it keeps only what the hook gives the new file. Where that would change the file for the user, the hook writes the formatted text into the original in place instead, as it did before it renamed, which keeps everything the file carries at the cost of the atomicity: when the file has several hard links, since its other names would keep the old content, and on macOS and Linux when the new file cannot take the original's owner and group, because the file belongs to another user or to a group the user is not in and only root may give a file away. Running the hook as root thus formats a user's file without making it root's. The hook writes in place rather than skipping the format because these files are rare and the in-place write is the behaviour they always had.
|
|
30
|
+
|
|
31
|
+
Extended attributes and access control lists are neither copied nor looked for. Node has no interface to read them, so finding them would cost a separate program run on every format, and on macOS nearly every file carries the `com.apple.provenance` attribute, so the mere presence of one says nothing. An ACL the file inherits from its directory reaches the new file in the same way, since the new file is created in that directory; what a format loses is an attribute or an ACL entry set on the file itself, such as a Finder tag on macOS or a `setfacl` entry on Linux.
|
|
32
|
+
|
|
33
|
+
On Windows the same holds for the file's security descriptor: the renamed file keeps the one the temporary file was created with, made of the entries inherited from the directory. A file whose permissions only come from its folder, as in nearly every project tree, keeps the same permissions; a file given its own explicit entries, with `icacls` or the Security tab, loses them. Writing in place would keep them, but finding them would mean running `icacls` on every format, and the case is rare enough that the hook keeps the atomic rename there too. Windows has no POSIX owner to restore.
|
|
34
|
+
|
|
35
|
+
On Windows, a rename over an existing file also fails while another process holds that file open, as an antivirus scanner, a search indexer or an editor briefly does after a save. The hook retries such a refusal (`EPERM`, `EACCES` or `EBUSY`) a few times over about half a second. Before each retry it reads the file again, and when the file no longer holds the text the hook formatted, a newer save landed while the file was held: the hook keeps that save, removes the temporary file and prints a warning that the format was not written. When the file is still held after the last retry, or cannot be read to make that check, it removes the temporary file, prints a warning that the format could not be written, and goes on to the validation with the original file left exactly as it was.
|
|
36
|
+
|
|
25
37
|
## Secrets stay home
|
|
26
38
|
|
|
27
39
|
When a `PIPELEX_API_KEY` is set, and before the validation sends anything, the hook reads every file of the tree once, after the format write-back, and screens it with the workshop's secret guard, the rule pipelex-mcp applies to every tree it sends, in a copy (`src/hooks/secret-guard.ts`) that is ahead of pipelex-mcp's `src/capabilities/secret-guard.ts` on the SSH key names and the PEM private key block below, until the workshop takes them up. The bytes screened are the bytes sent, never read again. The screen is needed because the listing reads only the `.gitignore` files inside the tree, so a repository's own `.gitignore` above the method's directory protects nothing in it, and the hook sends every file of the tree, not only its bundles. A `.env` never travels in any case, since the membership rule keeps out every name starting with a dot. With no key, the hook neither reads nor sends any file of the tree.
|
package/docs/run-results.md
CHANGED
|
@@ -238,17 +238,17 @@ The runtime keeps a large text out of a run's results. A `native.Text`, `native.
|
|
|
238
238
|
{ "url": "pipelex-storage://org/…/generated/3f9c…/value.md", "size": 182344, "mime_type": "text/markdown", "preview": "# Quarterly review…" }
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
-
An inline value arrives as `{ "text": "…" }`, `{ "inner_html": "…" }` (its `css_class` beside it) or `{ "json_obj": { … } }`. **The result readers load every stored text of `main_stuff` before they return**, so it reaches the generated parser in the shape the method's concepts describe, the value field required: `getRunResult`, `waitForResult` and `startAndWaitForResult` resolve the references through the
|
|
241
|
+
An inline value arrives as `{ "text": "…" }`, `{ "inner_html": "…" }` (its `css_class` beside it) or `{ "json_obj": { … } }`. **The result readers load every stored text of `main_stuff` before they return**, so it reaches the generated parser in the shape the method's concepts describe, the value field required: `getRunResult`, `waitForResult` and `startAndWaitForResult` resolve the references through the server's bulk route, at most `BULK_RESOLVE_MAX_URIS` per request, fetch each signed link under the bounds `fetchArtifact` applies, and decode the bytes as UTF-8, a JSON value being the object they serialize. A text that cannot be loaded throws `StoredTextLoadError`, naming its `uri`, its `path` in `main_stuff` and a `reason` (`not_found`, `pipelex.org.mismatch`, `resolve_failed`, `unsupported_url`, `too_large`, `total_limit_exceeded`, `concepts_missing`, `not_utf8`, `not_json_object`, …). The first text that fails stops every other read in flight.
|
|
242
242
|
|
|
243
243
|
**A load holds a bounded amount of memory.** Each text is capped by `maxBytes` (100 MiB by default) and the load as a whole by `maxTotalBytes` (256 MiB by default, `DEFAULT_STORED_TEXT_MAX_TOTAL_BYTES`), since every loaded value is held until the load ends, as bytes and then as a string that can take twice as many. Both caps are checked first against the `size` each reference states, before anything is sent, then counted as the bytes arrive; a load whose texts together cross `maxTotalBytes` throws `StoredTextLoadError` with the reason `total_limit_exceeded`, naming the text that crossed it. A `data:` URL's decoded size is bounded from its length before it is decoded. Pass larger caps to `loadStoredTexts(client, results, { maxBytes, maxTotalBytes })` on a result read with `loadStoredTexts: false`.
|
|
244
244
|
|
|
245
|
-
**A link about to expire is resolved again before its read.** The
|
|
245
|
+
**A link about to expire is resolved again before its read.** The server signs each link for a short time, about fifteen minutes on the hosted platform and `STORAGE_LINK_TTL_SECONDS` on a self-hosted runner, and a load reads only a few texts at once, so a text waiting behind long reads could reach its turn with a stale link. A link within ten seconds of its `expires_at` when its read is about to start is resolved again first, as `downloadArtifacts` does.
|
|
246
246
|
|
|
247
|
-
**Only the platform's references and `data:` URLs are loaded.** A `pipelex-storage://` reference is fetched through the link the platform signs for it, and a `data:` URL is decoded where it is. A stored text under any other URL, which a method's own code can put there, is refused as `unsupported_url` before anything is sent, so a method never has the SDK read a host the caller did not choose; `loadStoredTexts: false` hands it back as written.
|
|
247
|
+
**Only the platform's references and `data:` URLs are loaded.** A `pipelex-storage://` reference is fetched through the link the platform signs for it, and a `data:` URL is decoded where it is. A signed link on plain `http:` is fetched when it is on the origin of the client's configured base URL, which is what a self-hosted runner listening on plain http hands out, and refused as `plain_http_refused` on any other origin unless `allowHttp` is set ([artifact-download.md](./artifact-download.md)). A stored text under any other URL, which a method's own code can put there, is refused as `unsupported_url` before anything is sent, so a method never has the SDK read a host the caller did not choose; `loadStoredTexts: false` hands it back as written.
|
|
248
248
|
|
|
249
249
|
**`waitForResult`'s `timeoutMs` bounds the load.** The wait reads the run's status without loading, then loads the completed result under the time it has left. A deadline that passes during the load throws `RunTimeoutError` saying the run completed and its stored texts did not load in time; `getRunResult` reads it again, and with `loadStoredTexts: false` it answers at once.
|
|
250
250
|
|
|
251
|
-
**The blocking fallback never loses a completed result.** `startAndWaitForResult` on a bare runner, or falling back to one, holds the run's only copy in the `POST /v1/execute` answer, and a
|
|
251
|
+
**The blocking fallback never loses a completed result.** `startAndWaitForResult` on a bare runner, or falling back to one, holds the run's only copy in the `POST /v1/execute` answer, and a runner older than pipelex-api 0.118.0 serves no bulk resolve route; the hosted platform and, from that version, a self-hosted runner serve it. A load that fails there throws `StoredTextLoadError` with that result, every stored text still its reference, on its `wireResults`; on every other path `wireResults` is `undefined`, since the run can be read again.
|
|
252
252
|
|
|
253
253
|
**`loadStoredTexts: false` hands the wire shape back**, the references untouched, on all three readers. The generated `<Name>Wire` types describe that shape, the value field optional beside the reference's fields. `loadStoredTexts(client, results, options)`, exported, loads such a result later, and returns a new one, never changing the one it is given.
|
|
254
254
|
|
|
@@ -376,13 +376,15 @@ For the run's totals, call `summarizeUsage(results)` rather than adding the reco
|
|
|
376
376
|
|
|
377
377
|
A run that produces an image, a PDF or a document does not embed the bytes. The content inside `main_stuff` carries the file's durable reference — a `pipelex-storage://` URI, in the content's `url` — beside a `public_url` the storage provider signed when the run wrote the file. **That signed link is short-lived and must not be stored**: it expires on the provider's own schedule, so a link persisted in a database or rendered into a cached page stops working without warning, while the `pipelex-storage://` reference beside it is permanent and is what belongs in your records.
|
|
378
378
|
|
|
379
|
-
To read the bytes, mint a fresh link from the reference:
|
|
379
|
+
To read the bytes, mint a fresh link from the reference. On the hosted platform, `resolveStorageUrl` mints one link:
|
|
380
380
|
|
|
381
381
|
```ts
|
|
382
382
|
const resolved = await client.resolveStorageUrl({ uri: "pipelex-storage://..." });
|
|
383
383
|
// { url, expires_at, content_type } — fetch `url` now; re-resolve for the next reader.
|
|
384
384
|
```
|
|
385
385
|
|
|
386
|
-
|
|
386
|
+
`resolveStorageUrl` calls `POST /v1/resolve-storage-url`, which only the hosted platform serves: a self-hosted runner, from pipelex-api 0.118.0, serves the bulk route alone, so a caller of one mints its link with `resolveArtifacts([uri])`, a one-item list.
|
|
387
|
+
|
|
388
|
+
The same rule holds in a browser: resolve on the server, hand the client a link it uses immediately, and never let a signed link outlive the request it was minted for.
|
|
387
389
|
|
|
388
390
|
Bringing the files down is the SDK's job, not something to re-implement over `resolveStorageUrl`: `locateArtifacts` lists a result's references without touching the network, each with the paths of the fields it fills (`collectArtifacts` gives the references alone), `resolveArtifacts` mints fresh links for a whole list in one bulk call, `fetchArtifact` streams one file within safe bounds, and `downloadArtifacts` saves everything a run produced under a directory, each file named after the field it fills, by run id even days later. They all share one page, [`artifact-download.md`](./artifact-download.md). The upload direction — turning local files into `pipelex-storage://` references before a run — is the mirror of this and has its own page too, [`input-preparation.md`](./input-preparation.md).
|