stitchkit 0.136.3 → 0.136.5
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/CHANGELOG.md +14 -0
- package/dist/browser/http-fetch.d.ts +6 -0
- package/dist/browser/http-fetch.d.ts.map +1 -1
- package/dist/browser/http-helpers.d.ts +21 -0
- package/dist/browser/http-helpers.d.ts.map +1 -1
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +5 -5
- package/dist/entrypoints/agent-executor/claude-sdk.js +7 -7
- package/dist/entrypoints/agent-executor/claude.js +7 -7
- package/dist/entrypoints/agent-executor/codex.js +9 -9
- package/dist/entrypoints/agent-executor/testing.js +9 -9
- package/dist/entrypoints/agent-executor.js +5 -5
- package/dist/entrypoints/agent-runtime/coding-tools.js +2 -2
- package/dist/entrypoints/agent-runtime/postgres.js +4 -4
- package/dist/entrypoints/agent-runtime/sandbox.js +7 -7
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +5 -5
- package/dist/entrypoints/agent-runtime/sqlite/node.js +5 -5
- package/dist/entrypoints/agent-runtime/testing.js +4 -4
- package/dist/entrypoints/agent-runtime.js +4 -4
- package/dist/entrypoints/application/diagnostic-journal.js +3 -3
- package/dist/entrypoints/application/directory-inbox.js +7 -7
- package/dist/entrypoints/cli/publish.d.ts +14 -6
- package/dist/entrypoints/cli/publish.d.ts.map +1 -1
- package/dist/entrypoints/cli/publish.js +685 -30
- package/dist/entrypoints/cli.js +7 -124
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/files.d.ts +1 -0
- package/dist/entrypoints/files.d.ts.map +1 -1
- package/dist/entrypoints/files.js +9 -9
- package/dist/entrypoints/http.js +3 -3
- package/dist/entrypoints/index.js +3 -3
- package/dist/entrypoints/node.js +3 -3
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/process.js +3 -3
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/remote.js +2 -2
- package/dist/entrypoints/server.js +6 -6
- package/dist/entrypoints/service-host/macos.js +7 -7
- package/dist/entrypoints/service-host/work.js +6 -6
- package/dist/entrypoints/service-host.js +9 -9
- package/dist/entrypoints/spend.js +1 -1
- package/dist/entrypoints/telegram.js +3 -3
- package/dist/entrypoints/testing.js +2 -2
- package/dist/entrypoints/tools.js +1 -1
- package/dist/{index-05b65gj4.js → index-0s75mjh7.js} +1 -1
- package/dist/{index-s2e3h616.js → index-150b1qyw.js} +10 -1
- package/dist/{index-tcv71frn.js → index-1fhbe4e4.js} +1 -1
- package/dist/{index-8cek82ar.js → index-1h0dtfz3.js} +1 -1
- package/dist/{index-jwtmw39p.js → index-2qnqvq11.js} +1 -1
- package/dist/index-2rs7ze0q.js +376 -0
- package/dist/{index-2wm9b9vs.js → index-3cwq5byx.js} +2 -2
- package/dist/{index-mtpcax6d.js → index-5md04mwc.js} +3 -3
- package/dist/{index-b0mh2t9x.js → index-67mzzkdv.js} +3 -3
- package/dist/{index-nne3yxew.js → index-6f4fjygr.js} +1 -1
- package/dist/{index-d5mhgx72.js → index-8tn10tp6.js} +1 -1
- package/dist/{index-rw31t8sj.js → index-9fzjgg86.js} +1 -1
- package/dist/{index-0sxj3y45.js → index-afaq0nc4.js} +1 -1
- package/dist/{index-nfm15ej7.js → index-bbpygynk.js} +1 -1
- package/dist/{index-g04hszcm.js → index-chapre0y.js} +1 -1
- package/dist/{index-vh4291qh.js → index-ctaxjpa4.js} +1 -1
- package/dist/{index-mhgkzwxz.js → index-d01akj5n.js} +134 -25
- package/dist/{index-x1r7kxzd.js → index-e4zt2x70.js} +3 -3
- package/dist/{index-s0n0nnz5.js → index-f103md2v.js} +122 -3
- package/dist/{index-2c5w2d1d.js → index-gyfsh29t.js} +1 -1
- package/dist/{index-kgkevngs.js → index-kadgaw1s.js} +4 -4
- package/dist/{index-ca1v40d3.js → index-kd48gk7d.js} +1 -1
- package/dist/{index-ke6jtxkd.js → index-mr3njw67.js} +1 -1
- package/dist/{index-cmqvf0dz.js → index-ppy23bd2.js} +1 -1
- package/dist/{index-43k180c2.js → index-rnhp7je8.js} +2 -2
- package/dist/{index-2tgmggcm.js → index-smvmnz5y.js} +1 -1
- package/dist/{index-9m1m92rg.js → index-tjhhsnjv.js} +1 -1
- package/dist/{index-64t6pheq.js → index-w161azza.js} +1 -1
- package/dist/{index-mttkdm5a.js → index-xqppqn97.js} +1 -1
- package/dist/{index-sjq4akrx.js → index-xsrma0jd.js} +2 -2
- package/dist/{index-zqc64g69.js → index-ypm85xwe.js} +1 -1
- package/dist/{index-zagc12j1.js → index-zcq3dby3.js} +1 -1
- package/dist/{index-29v1p1f4.js → index-zhngww7q.js} +1 -1
- package/dist/internal/atomic-file-owner.d.ts +91 -0
- package/dist/internal/atomic-file-owner.d.ts.map +1 -0
- package/dist/internal/atomic-file.d.ts +29 -7
- package/dist/internal/atomic-file.d.ts.map +1 -1
- package/dist/internal/bounded-file-read.d.ts +6 -2
- package/dist/internal/bounded-file-read.d.ts.map +1 -1
- package/dist/tools/cli/distribution-config.d.ts +56 -0
- package/dist/tools/cli/distribution-config.d.ts.map +1 -0
- package/dist/tools/cli/distribution-routes.d.ts +20 -0
- package/dist/tools/cli/distribution-routes.d.ts.map +1 -0
- package/dist/tools/cli/publication-source.d.ts +77 -0
- package/dist/tools/cli/publication-source.d.ts.map +1 -0
- package/llms/cli-publish.txt +15 -3
- package/llms/cli.2.txt +84 -63
- package/llms/cli.3.txt +67 -1
- package/llms/cli.txt +1 -1
- package/llms/files.txt +1 -1
- package/llms/process.txt +24 -4
- package/llms/stitchkit.txt +11 -3
- package/llms-full.txt +134 -11
- package/llms.txt +5 -5
- package/package.json +1 -1
- package/dist/index-pp97q86a.js +0 -221
- package/dist/{index-5c4m8zdf.js → index-tjakdpf2.js} +45 -45
package/llms/process.txt
CHANGED
|
@@ -50,14 +50,34 @@ try {
|
|
|
50
50
|
await writeFileAtomic('/srv/app/state.json', '{"version":2}', {
|
|
51
51
|
replace: true, durability: 'directory',
|
|
52
52
|
})
|
|
53
|
+
// When a privileged process (e.g. root) updates a private config owned by a service user:
|
|
54
|
+
await writeFileAtomic('/etc/app/node.json', '{"version":2}', {
|
|
55
|
+
mode: 0o600, owner: 'preserve',
|
|
56
|
+
})
|
|
57
|
+
// Or set an explicit POSIX owner on creation or replacement:
|
|
58
|
+
await writeFileAtomic('/etc/app/node.json', '{"version":2}', {
|
|
59
|
+
mode: 0o600, owner: { uid: 1000, gid: 1000 },
|
|
60
|
+
})
|
|
53
61
|
```
|
|
54
62
|
|
|
55
63
|
The defaults are `replace: true`, `durability: 'file'` and `mode: 0o600`: file fsync and atomic
|
|
56
64
|
replacement. `durability: 'none'` skips every sync. `'directory'` runs the full sequence: write all
|
|
57
|
-
bytes, exact descriptor
|
|
58
|
-
link, parent directory fsync. `writeFileAtomicSync` takes the same
|
|
59
|
-
Create fails with the native `EEXIST` when the target exists, is a
|
|
60
|
-
won. Never turn that refusal into a replace automatically.
|
|
65
|
+
bytes, optional descriptor `fchown`, exact descriptor `fchmod`, file fsync, rename (replace) or link
|
|
66
|
+
(create), remove the staging link, parent directory fsync. `writeFileAtomicSync` takes the same
|
|
67
|
+
options and runs the same order. Create fails with the native `EEXIST` when the target exists, is a
|
|
68
|
+
symlink, or a concurrent writer won. Never turn that refusal into a replace automatically.
|
|
69
|
+
|
|
70
|
+
`owner: 'preserve'` inspects an existing regular file at `target` with `lstat` (never following a
|
|
71
|
+
symlink; missing or non-regular targets keep the kernel default) and cannot be combined with
|
|
72
|
+
`replace: false`. `owner: { uid, gid }` validates numeric POSIX IDs (`0..4294967294`; `0xffff_ffff`
|
|
73
|
+
is refused because POSIX `fchown` treats `(uid_t)-1` as a no-op). Both forms compare against the
|
|
74
|
+
staged descriptor's actual `fstat(fd)` — never guessing from `process.getuid()`/`process.getgid()`
|
|
75
|
+
— call `fchown` strictly before `fchmod(mode)` and `fsync`, narrow the staging creation mode to
|
|
76
|
+
`mode & 0o700` while ownership is pending, remove the staging file on any error (including `EPERM`
|
|
77
|
+
and `EACCES`), and rethrow the original system error untouched. With `replace: false`,
|
|
78
|
+
`idempotent: true` and an explicit `owner`, an existing target satisfies the idempotent check only
|
|
79
|
+
when its bytes, mode and `(uid, gid)` all match (while a staging `fchown` failure such as `EPERM`
|
|
80
|
+
still fails before publication). Ownership options are refused explicitly on Windows.
|
|
61
81
|
|
|
62
82
|
`AtomicFilePublicationError.published === true` tells a visible target from an unconfirmed
|
|
63
83
|
acknowledgement. `phase` is `cleanup`, `directory-sync` or `directory-close`; the primary cause is
|
package/llms/stitchkit.txt
CHANGED
|
@@ -74,7 +74,7 @@ own, recorded as an ADR.
|
|
|
74
74
|
| `stitchkit/tools/invoker` | server | stable<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | peer-free `createToolInvoker` over the canonical contract tool runner |
|
|
75
75
|
| `stitchkit/tools/connections` | server (Bun or Node) | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | consume external MCP servers and a bounded OpenAPI subset — typed reauthorization, a per-request host fence and per-call credentials |
|
|
76
76
|
| `stitchkit/cli` | server | stable<br>_redefined in 12 of the 43 minors since 0.94.0, most recently 0.128.0_ | `createCli` / `createCliInvoker` — runtime and strict NodeNext declarations without MCP SDK / `ai` |
|
|
77
|
-
| `stitchkit/cli/publish` | build and
|
|
77
|
+
| `stitchkit/cli/publish` | build, release and server tooling (Bun or Node, POSIX) | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | `publishCli`, shipping-input versioning (`deriveCliVersionFromShippingInputs`, `cliShippingInputsChanged`, `assertCleanCliSource`), and `createCliDistributionRoutes` (`RawRoute[]` channel manifest, asset and installer routes); see [CLI guide](cli.md#publishing-a-complete-version) |
|
|
78
78
|
| `stitchkit/remote` | browser **and** server | stable<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.104.0_ | peer-free `implementRemote` for thin HTTP proxy processes |
|
|
79
79
|
| `stitchkit/process` | server (Bun or Node, POSIX) | evolving<br>_redefined in 4 of the 43 minors since 0.94.0, most recently 0.133.0_ | finite native commands, byte sinks, bounded capture, process-group cancellation and opt-in Linux/Darwin owner-loss cleanup; contract operations executed in one-call child processes |
|
|
80
80
|
| `stitchkit/process/bootstrap` | bundled server entry (Bun, POSIX) | evolving<br>_redefined in 0 of the 4 minors since 0.133.0_ | narrow bootstrap that keeps the process runner lazy while carrying the package's own invocations — the owner-loss guard and the process root of launched work — in a single-file bundle |
|
|
@@ -519,5 +519,13 @@ StitchKit passes that retry's current `Request.signal` in the second fetch
|
|
|
519
519
|
argument and materializes the current Request as URL + init. Next 16.3 otherwise
|
|
520
520
|
merges `init` into a Request before its dedupe layer and loses the explicit
|
|
521
521
|
signal opt-out. The retry therefore performs a new network attempt instead of
|
|
522
|
-
returning the cached rejection.
|
|
523
|
-
|
|
522
|
+
returning the cached rejection. When a retried request carries a body (for
|
|
523
|
+
example an `idempotent: true` `POST` or `PUT` with JSON or `FormData`),
|
|
524
|
+
StitchKit copies its headers and buffers the body into concrete `ArrayBuffer`
|
|
525
|
+
bytes instead of forwarding `Request.body` as a `ReadableStream` with
|
|
526
|
+
`duplex: 'half'`, so browser HTTP/1.1 transports (Chromium, WebKit) deliver the
|
|
527
|
+
retry intact. Calls whose method is not retried pass `retry: { limit: 0 }` so Ky
|
|
528
|
+
does not clone the `Request`, keeping the body as direct bytes in browser
|
|
529
|
+
DevTools Protocol and Playwright `request.postData()`. This adapter does not broaden retry policy: POST,
|
|
530
|
+
unconfigured HTTP statuses, cancellation and exhausted budgets retain the rules
|
|
531
|
+
above.
|
package/llms-full.txt
CHANGED
|
@@ -65,7 +65,7 @@ own, recorded as an ADR.
|
|
|
65
65
|
| `stitchkit/tools/invoker` | server | stable<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | peer-free `createToolInvoker` over the canonical contract tool runner |
|
|
66
66
|
| `stitchkit/tools/connections` | server (Bun or Node) | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | consume external MCP servers and a bounded OpenAPI subset — typed reauthorization, a per-request host fence and per-call credentials |
|
|
67
67
|
| `stitchkit/cli` | server | stable<br>_redefined in 12 of the 43 minors since 0.94.0, most recently 0.128.0_ | `createCli` / `createCliInvoker` — runtime and strict NodeNext declarations without MCP SDK / `ai` |
|
|
68
|
-
| `stitchkit/cli/publish` | build and
|
|
68
|
+
| `stitchkit/cli/publish` | build, release and server tooling (Bun or Node, POSIX) | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | `publishCli`, shipping-input versioning (`deriveCliVersionFromShippingInputs`, `cliShippingInputsChanged`, `assertCleanCliSource`), and `createCliDistributionRoutes` (`RawRoute[]` channel manifest, asset and installer routes); see [CLI guide](cli.md#publishing-a-complete-version) |
|
|
69
69
|
| `stitchkit/remote` | browser **and** server | stable<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.104.0_ | peer-free `implementRemote` for thin HTTP proxy processes |
|
|
70
70
|
| `stitchkit/process` | server (Bun or Node, POSIX) | evolving<br>_redefined in 4 of the 43 minors since 0.94.0, most recently 0.133.0_ | finite native commands, byte sinks, bounded capture, process-group cancellation and opt-in Linux/Darwin owner-loss cleanup; contract operations executed in one-call child processes |
|
|
71
71
|
| `stitchkit/process/bootstrap` | bundled server entry (Bun, POSIX) | evolving<br>_redefined in 0 of the 4 minors since 0.133.0_ | narrow bootstrap that keeps the process runner lazy while carrying the package's own invocations — the owner-loss guard and the process root of launched work — in a single-file bundle |
|
|
@@ -3367,8 +3367,16 @@ StitchKit passes that retry's current `Request.signal` in the second fetch
|
|
|
3367
3367
|
argument and materializes the current Request as URL + init. Next 16.3 otherwise
|
|
3368
3368
|
merges `init` into a Request before its dedupe layer and loses the explicit
|
|
3369
3369
|
signal opt-out. The retry therefore performs a new network attempt instead of
|
|
3370
|
-
returning the cached rejection.
|
|
3371
|
-
|
|
3370
|
+
returning the cached rejection. When a retried request carries a body (for
|
|
3371
|
+
example an `idempotent: true` `POST` or `PUT` with JSON or `FormData`),
|
|
3372
|
+
StitchKit copies its headers and buffers the body into concrete `ArrayBuffer`
|
|
3373
|
+
bytes instead of forwarding `Request.body` as a `ReadableStream` with
|
|
3374
|
+
`duplex: 'half'`, so browser HTTP/1.1 transports (Chromium, WebKit) deliver the
|
|
3375
|
+
retry intact. Calls whose method is not retried pass `retry: { limit: 0 }` so Ky
|
|
3376
|
+
does not clone the `Request`, keeping the body as direct bytes in browser
|
|
3377
|
+
DevTools Protocol and Playwright `request.postData()`. This adapter does not broaden retry policy: POST,
|
|
3378
|
+
unconfigured HTTP statuses, cancellation and exhausted budgets retain the rules
|
|
3379
|
+
above.
|
|
3372
3380
|
|
|
3373
3381
|
## `createClient`
|
|
3374
3382
|
|
|
@@ -10789,14 +10797,34 @@ try {
|
|
|
10789
10797
|
await writeFileAtomic('/srv/app/state.json', '{"version":2}', {
|
|
10790
10798
|
replace: true, durability: 'directory',
|
|
10791
10799
|
})
|
|
10800
|
+
// When a privileged process (e.g. root) updates a private config owned by a service user:
|
|
10801
|
+
await writeFileAtomic('/etc/app/node.json', '{"version":2}', {
|
|
10802
|
+
mode: 0o600, owner: 'preserve',
|
|
10803
|
+
})
|
|
10804
|
+
// Or set an explicit POSIX owner on creation or replacement:
|
|
10805
|
+
await writeFileAtomic('/etc/app/node.json', '{"version":2}', {
|
|
10806
|
+
mode: 0o600, owner: { uid: 1000, gid: 1000 },
|
|
10807
|
+
})
|
|
10792
10808
|
```
|
|
10793
10809
|
|
|
10794
10810
|
The defaults are `replace: true`, `durability: 'file'` and `mode: 0o600`: file fsync and atomic
|
|
10795
10811
|
replacement. `durability: 'none'` skips every sync. `'directory'` runs the full sequence: write all
|
|
10796
|
-
bytes, exact descriptor
|
|
10797
|
-
link, parent directory fsync. `writeFileAtomicSync` takes the same
|
|
10798
|
-
Create fails with the native `EEXIST` when the target exists, is a
|
|
10799
|
-
won. Never turn that refusal into a replace automatically.
|
|
10812
|
+
bytes, optional descriptor `fchown`, exact descriptor `fchmod`, file fsync, rename (replace) or link
|
|
10813
|
+
(create), remove the staging link, parent directory fsync. `writeFileAtomicSync` takes the same
|
|
10814
|
+
options and runs the same order. Create fails with the native `EEXIST` when the target exists, is a
|
|
10815
|
+
symlink, or a concurrent writer won. Never turn that refusal into a replace automatically.
|
|
10816
|
+
|
|
10817
|
+
`owner: 'preserve'` inspects an existing regular file at `target` with `lstat` (never following a
|
|
10818
|
+
symlink; missing or non-regular targets keep the kernel default) and cannot be combined with
|
|
10819
|
+
`replace: false`. `owner: { uid, gid }` validates numeric POSIX IDs (`0..4294967294`; `0xffff_ffff`
|
|
10820
|
+
is refused because POSIX `fchown` treats `(uid_t)-1` as a no-op). Both forms compare against the
|
|
10821
|
+
staged descriptor's actual `fstat(fd)` — never guessing from `process.getuid()`/`process.getgid()`
|
|
10822
|
+
— call `fchown` strictly before `fchmod(mode)` and `fsync`, narrow the staging creation mode to
|
|
10823
|
+
`mode & 0o700` while ownership is pending, remove the staging file on any error (including `EPERM`
|
|
10824
|
+
and `EACCES`), and rethrow the original system error untouched. With `replace: false`,
|
|
10825
|
+
`idempotent: true` and an explicit `owner`, an existing target satisfies the idempotent check only
|
|
10826
|
+
when its bytes, mode and `(uid, gid)` all match (while a staging `fchown` failure such as `EPERM`
|
|
10827
|
+
still fails before publication). Ownership options are refused explicitly on Windows.
|
|
10800
10828
|
|
|
10801
10829
|
`AtomicFilePublicationError.published === true` tells a visible target from an unconfirmed
|
|
10802
10830
|
acknowledgement. `phase` is `cleanup`, `directory-sync` or `directory-close`; the primary cause is
|
|
@@ -13636,6 +13664,89 @@ identity to recover; an error does not promise rollback. Optional `signing` and
|
|
|
13636
13664
|
raw digest and size; the updater checks manifest authorship when given a trust
|
|
13637
13665
|
root.
|
|
13638
13666
|
|
|
13667
|
+
### Versioning from shipping inputs and verifying clean source
|
|
13668
|
+
|
|
13669
|
+
When a CLI lives inside a larger repository, ordinary backend commits should not
|
|
13670
|
+
force a new CLI version. `stitchkit/cli/publish` provides three git-backed
|
|
13671
|
+
helpers (`deriveCliVersionFromShippingInputs`, `cliShippingInputsChanged`, and
|
|
13672
|
+
`assertCleanCliSource`) built on `runNativeCommand` with a declared-only
|
|
13673
|
+
environment (`GIT_TERMINAL_PROMPT=0`, `GIT_OPTIONAL_LOCKS=0`, ignoring inherited
|
|
13674
|
+
`GIT_DIR` / `GIT_WORK_TREE`):
|
|
13675
|
+
|
|
13676
|
+
```ts
|
|
13677
|
+
import {
|
|
13678
|
+
assertCleanCliSource,
|
|
13679
|
+
cliShippingInputsChanged,
|
|
13680
|
+
deriveCliVersionFromShippingInputs,
|
|
13681
|
+
} from 'stitchkit/cli/publish'
|
|
13682
|
+
|
|
13683
|
+
const shippingPaths = ['packages/cli', 'packages/shared', 'bun.lock']
|
|
13684
|
+
const head = await assertCleanCliSource({
|
|
13685
|
+
repository: '/srv/myapp/source',
|
|
13686
|
+
untrackedPaths: ['packages/cli', 'packages/shared', 'scripts/cli-publish*'],
|
|
13687
|
+
})
|
|
13688
|
+
const version = await deriveCliVersionFromShippingInputs({
|
|
13689
|
+
repository: '/srv/myapp/source',
|
|
13690
|
+
commit: head,
|
|
13691
|
+
packageJsonPath: 'packages/cli/package.json',
|
|
13692
|
+
shippingPaths,
|
|
13693
|
+
})
|
|
13694
|
+
const changed = await cliShippingInputsChanged({
|
|
13695
|
+
repository: '/srv/myapp/source',
|
|
13696
|
+
previousCommit,
|
|
13697
|
+
nextCommit: head,
|
|
13698
|
+
shippingPaths,
|
|
13699
|
+
})
|
|
13700
|
+
```
|
|
13701
|
+
|
|
13702
|
+
`deriveCliVersionFromShippingInputs` reads `major.minor` from `packageJsonPath`
|
|
13703
|
+
at `<commit>` and counts commits touching `shippingPaths` up to `<commit>`
|
|
13704
|
+
(`major.minor.<count>`). Both `deriveCliVersionFromShippingInputs` and
|
|
13705
|
+
`cliShippingInputsChanged` accept either a git worktree root or a bare
|
|
13706
|
+
repository root (`realpath(--show-toplevel)` or `realpath(--absolute-git-dir)`
|
|
13707
|
+
matching `realpath(repository)`), while `assertCleanCliSource` requires a
|
|
13708
|
+
worktree root; subdirectories and non-bare `.git` directories are refused. All
|
|
13709
|
+
three helpers require exact 40-hex commit objects (refusing tree, blob and
|
|
13710
|
+
annotated-tag SHAs), full history for version counting (refusing shallow
|
|
13711
|
+
clones), and safe repository-relative paths without `:` magic pathspecs.
|
|
13712
|
+
`assertCleanCliSource` returns the verified 40-hex `HEAD` and checks tracked
|
|
13713
|
+
changes plus either all untracked files (`--untracked-files=normal`) or only
|
|
13714
|
+
untracked files matching `untrackedPaths`.
|
|
13715
|
+
|
|
13716
|
+
### Serving a published CLI channel
|
|
13717
|
+
|
|
13718
|
+
`createCliDistributionRoutes` returns portable `RawRoute[]` (`GET` only) that
|
|
13719
|
+
serve a directory published by `publishCli` under `<root>/channels/<channel>/`:
|
|
13720
|
+
|
|
13721
|
+
```ts
|
|
13722
|
+
import { createCliDistributionRoutes } from 'stitchkit/cli/publish'
|
|
13723
|
+
import { createServer } from 'stitchkit/server'
|
|
13724
|
+
|
|
13725
|
+
const server = createServer({
|
|
13726
|
+
rawRoutes: createCliDistributionRoutes({
|
|
13727
|
+
root: process.env.CLI_DISTRIBUTION_DIR,
|
|
13728
|
+
name: 'myapp',
|
|
13729
|
+
trust: RELEASE_TRUST_ROOT,
|
|
13730
|
+
onUnavailable: (event) => logger.warn(event, 'CLI distribution unavailable'),
|
|
13731
|
+
}),
|
|
13732
|
+
})
|
|
13733
|
+
```
|
|
13734
|
+
|
|
13735
|
+
Each configured channel mounts `${basePath}/channels/<channel>/manifest.json`
|
|
13736
|
+
(`Cache-Control: no-store`, exact raw verified bytes) and
|
|
13737
|
+
`${basePath}/channels/<channel>/:version/:asset` (immutable `manifest.json` or a
|
|
13738
|
+
descriptor-streamed binary listed in the signed manifest with `Content-Length`
|
|
13739
|
+
and `Content-Disposition`). `${basePath}/install.sh` renders `renderCliInstaller`
|
|
13740
|
+
from the verified `installerChannel` manifest (`no-store`). Every read checks
|
|
13741
|
+
canonical directory containment (`realpath` + `isWithinDir`), opens regular files
|
|
13742
|
+
with `O_NOFOLLOW`, parses strict UTF-8 JSON without `__proto__`, verifies
|
|
13743
|
+
`manifest.name` and Ed25519 signature strictly (`verifyCliManifest === 'valid'`),
|
|
13744
|
+
and streams full asset bodies portably on both Bun and Node without `Bun.file`.
|
|
13745
|
+
When `root` is `undefined`, `trust.keys` is empty, or the manifest is missing,
|
|
13746
|
+
unsigned, tampered, oversized or has no assets, channel manifest and installer
|
|
13747
|
+
routes fail closed with `503 No verified CLI build is published` (`no-store`),
|
|
13748
|
+
and exceptions thrown by `onUnavailable` are isolated.
|
|
13749
|
+
|
|
13639
13750
|
### Proving who built it — signing the manifest
|
|
13640
13751
|
|
|
13641
13752
|
The asset digest proves the bytes that arrived are the bytes the manifest named.
|
|
@@ -31226,7 +31337,7 @@ available from `stitchkit/contract`.
|
|
|
31226
31337
|
| `ManagedFileError` / `ManagedFileErrorCode` | class / _type_ | stable boundary failures; registered `FILE_*` mistakes are caller-safe while `FILE_IO_ERROR` remains internal |
|
|
31227
31338
|
| `ManagedFileInspector` | _type_ | bounded-prefix read/write inspection callback with a finite cancellation signal that cannot own path or size |
|
|
31228
31339
|
| `ManagedFileInspectionInput` / `ManagedFileInspection` | _type_ | inspector prefix/name/declared media/signal input and validated metadata-only result |
|
|
31229
|
-
| `writeFileAtomic` / `writeFileAtomicSync` / `WriteFileAtomicOptions` | function / _type_ | replace a file atomically: a random staging name created exclusively (never through a planted link), the mode set on the descriptor before the file is visible (default `0o600`, not masked by the umask), `fsync`, rename; a failure leaves the target
|
|
31340
|
+
| `writeFileAtomic` / `writeFileAtomicSync` / `WriteFileAtomicOptions` / `WriteFileAtomicOwner` | function / _type_ | replace a file atomically: a random staging name created exclusively with `O_NOFOLLOW` (never through a planted link), optional POSIX `owner` (`'preserve'` from an existing regular target via `lstat`, or explicit `{ uid, gid }`, applied via `fchown` after comparing real `fstat(fd)` and strictly before `fchmod`), the exact `mode` set on the descriptor before the file is visible (default `0o600`, not masked by the umask), `fsync`, rename; a failure leaves the target untouched, removes the staging file, and propagates the native OS error. The asynchronous form keeps the event loop running. A process killed before publication leaves its staging file; sweeping it is the caller's job |
|
|
31230
31341
|
| `isAtomicStagingName` | function | true for a staging file name of an atomic write of this library (`.stitchkit-<24 lowercase hex>.tmp`, also used by the managed writer and the chunk spool); the form is a stable contract, and changing it is a breaking change ([ADR 0242](../decisions/0242-atomic-staging-name-is-a-public-contract.md)) |
|
|
31231
31342
|
| `sweepAtomicStaging` / `SweepAtomicStagingOptions` | function / _type_ | remove abandoned staging files from one `directory`: only regular files matching `isAtomicStagingName` and older than the required `olderThanMs`, never following a symlink or entering a subdirectory; stops on `signal`; returns the removed names, `[]` for a `directory` that does not exist |
|
|
31232
31343
|
| `withExclusiveLock` / `ExclusiveLockOptions` / `ExclusiveLock` / `ExclusiveLockOwner` | function / _type_ | run work under an exclusive lock between processes — a file recording its owner (pid, host, machine identity, time and nullable kernel process identity); waits up to `timeoutMs` (default 10 s) and stops on `signal`; a dead owner on this machine is taken over, a live, slow or foreign one never is; a lock recorded by this very process is held only while one of its descriptors is open on it, so the lock an earlier image of the same PID left (`bun --watch` restarts in place) is taken over at once; the lock is published with its owner already recorded (temporary file plus hard link), so a stalled holder is never displaced; a legacy empty lock file is taken by age only when `ownerlessGraceMs` is a number (default `null`: never; an abandoned empty reclaim guard is taken after 5 000 ms unless a value is set); exact `mode` is independent of umask; shared readers need a common group and traversable directories |
|
|
@@ -31965,9 +32076,12 @@ SDK nor the `ai` peer.
|
|
|
31965
32076
|
|
|
31966
32077
|
## `stitchkit/cli/publish`
|
|
31967
32078
|
|
|
31968
|
-
Build and
|
|
31969
|
-
application-owned directory
|
|
31970
|
-
|
|
32079
|
+
Build, source verification and distribution-route tooling, evolving. Publishes a
|
|
32080
|
+
CLI distribution into a local application-owned directory, derives deterministic
|
|
32081
|
+
versions from git shipping-input history, verifies clean source roots, and
|
|
32082
|
+
serves verified channel manifests, immutable assets and `install.sh` over
|
|
32083
|
+
`RawRoute[]`; the manifest, signatures, installer and updater it writes for stay
|
|
32084
|
+
in `stitchkit/cli` — [guide](../guide/cli.md#publishing-a-complete-version),
|
|
31971
32085
|
[ADR 0245](../decisions/0245-cli-publication-is-an-evolving-leaf.md).
|
|
31972
32086
|
|
|
31973
32087
|
| Export | Kind | Summary |
|
|
@@ -31976,6 +32090,15 @@ writes for stay in `stitchkit/cli` — [guide](../guide/cli.md#publishing-a-comp
|
|
|
31976
32090
|
| `CliPublicationOptions` | _type_ | identity, storage root, base URL, targets, limits, retention, the `admit` and `build` callbacks, optional signing and trust |
|
|
31977
32091
|
| `CliPublicationPhase` | _type_ | the step `admit` is asked about — `prepare`, `build`, `commit` or `promote` |
|
|
31978
32092
|
| `CliPublicationResult` | _type_ | `published` or `existing`, with the manifest ready to serve |
|
|
32093
|
+
| `deriveCliVersionFromShippingInputs` | function | derive `major.minor.<count>` from `packageJsonPath` at `<commit>` and the full git commit count touching `shippingPaths`; accepts worktree or bare repository roots and refuses shallow clones, subdirectories, non-bare `.git` dirs and non-commit SHAs |
|
|
32094
|
+
| `CliShippingVersionOptions` | _type_ | options for `deriveCliVersionFromShippingInputs` (`repository`, `commit`, `packageJsonPath`, `shippingPaths`, `timeoutMs`, `signal`) |
|
|
32095
|
+
| `cliShippingInputsChanged` | function | return `true` when any path in `shippingPaths` differs between `previousCommit` and `nextCommit` using `git diff --no-ext-diff --quiet` |
|
|
32096
|
+
| `CliShippingInputsChangedOptions` | _type_ | options for `cliShippingInputsChanged` (`repository`, `previousCommit`, `nextCommit`, `shippingPaths`, `timeoutMs`, `signal`) |
|
|
32097
|
+
| `assertCleanCliSource` | function | verify a clean git root matching optional `expectedCommit`, optional `untrackedPaths` globs and optional `servingSource` realpath; returns verified 40-hex `HEAD` |
|
|
32098
|
+
| `CleanCliSourceOptions` | _type_ | options for `assertCleanCliSource` (`repository`, `expectedCommit`, `untrackedPaths`, `servingSource`, `timeoutMs`, `signal`) |
|
|
32099
|
+
| `createCliDistributionRoutes` | function | portable `RawRoute[]` (`GET` only) serving verified signed channel manifests (`no-store`), immutable versioned manifests and descriptor-streamed binary assets, and `install.sh`, failing closed with `503 No verified CLI build is published` |
|
|
32100
|
+
| `CliDistributionRoutesOptions` | _type_ | options for `createCliDistributionRoutes` (`root`, `name`, `trust`, `channels`, `installerChannel`, `basePath`, `binaryName`, `installDir`, `maxManifestBytes`, `serviceName`, `onUnavailable`) |
|
|
32101
|
+
| `CliDistributionUnavailableEvent` | _type_ | diagnostic event passed to `onUnavailable` with `route`, `channel`, optional `version`/`asset`, inline `reason`, optional `verdict` and `error` |
|
|
31979
32102
|
|
|
31980
32103
|
---
|
|
31981
32104
|
|
package/llms.txt
CHANGED
|
@@ -9,7 +9,7 @@ Build with stitchkit: define a contract once, then `implement` it and serve it (
|
|
|
9
9
|
Load the slice for each entrypoint your code imports — `import … from 'stitchkit/server'` → `llms/server.txt`; the root `stitchkit` import → `llms/stitchkit.txt`. A slice holds that entrypoint's API reference section and the guide pages whose home it is; every guide lives in exactly one slice, and a slice that needs another's guide names it under "Also read". Each file is at most 50.0 KB; a longer one continues in numbered parts, each naming the next at its top. Moving across versions: load `llms/upgrading.txt` and the range slices it lists between your version and the target. `llms-full.txt` inlines everything; it is far larger than a context window, so do not read it whole.
|
|
10
10
|
|
|
11
11
|
## Entrypoint slices
|
|
12
|
-
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt)
|
|
12
|
+
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 44.6 KB → [llms/stitchkit.2.txt](llms/stitchkit.2.txt) 47.2 KB → [llms/stitchkit.3.txt](llms/stitchkit.3.txt) 29.4 KB
|
|
13
13
|
- **stitchkit/live**: [llms/live.txt](llms/live.txt) 22.9 KB
|
|
14
14
|
- **stitchkit/react**: [llms/react.txt](llms/react.txt) 8.7 KB
|
|
15
15
|
- **stitchkit/react/keyboard**: [llms/react-keyboard.txt](llms/react-keyboard.txt) 22.7 KB
|
|
@@ -21,8 +21,8 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
|
|
|
21
21
|
- **stitchkit/tools/contract**: [llms/tools-contract.txt](llms/tools-contract.txt) 0.2 KB
|
|
22
22
|
- **stitchkit/tools/invoker**: [llms/tools-invoker.txt](llms/tools-invoker.txt) 0.2 KB
|
|
23
23
|
- **stitchkit/tools/connections**: [llms/tools-connections.txt](llms/tools-connections.txt) 4.9 KB
|
|
24
|
-
- **stitchkit/cli**: [llms/cli.txt](llms/cli.txt) 42.0 KB → [llms/cli.2.txt](llms/cli.2.txt)
|
|
25
|
-
- **stitchkit/cli/publish**: [llms/cli-publish.txt](llms/cli-publish.txt)
|
|
24
|
+
- **stitchkit/cli**: [llms/cli.txt](llms/cli.txt) 42.0 KB → [llms/cli.2.txt](llms/cli.2.txt) 47.0 KB → [llms/cli.3.txt](llms/cli.3.txt) 16.2 KB
|
|
25
|
+
- **stitchkit/cli/publish**: [llms/cli-publish.txt](llms/cli-publish.txt) 3.6 KB
|
|
26
26
|
- **stitchkit/remote**: [llms/remote.txt](llms/remote.txt) 1.0 KB
|
|
27
27
|
- **stitchkit/contract**: [llms/contract.txt](llms/contract.txt) 36.5 KB
|
|
28
28
|
- **stitchkit/primitives**: [llms/primitives.txt](llms/primitives.txt) 15.2 KB
|
|
@@ -56,7 +56,7 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
|
|
|
56
56
|
- **stitchkit/agent-runtime/sandbox**: [llms/agent-runtime-sandbox.txt](llms/agent-runtime-sandbox.txt) 17.1 KB
|
|
57
57
|
- **stitchkit/spend**: [llms/spend.txt](llms/spend.txt) 11.0 KB
|
|
58
58
|
- **stitchkit/spend/testing**: [llms/spend-testing.txt](llms/spend-testing.txt) 1.2 KB
|
|
59
|
-
- **stitchkit/files**: [llms/files.txt](llms/files.txt) 11.
|
|
59
|
+
- **stitchkit/files**: [llms/files.txt](llms/files.txt) 11.7 KB
|
|
60
60
|
- **stitchkit/service-host**: [llms/service-host.txt](llms/service-host.txt) 10.3 KB
|
|
61
61
|
- **stitchkit/service-host/macos**: [llms/service-host-macos.txt](llms/service-host-macos.txt) 6.2 KB
|
|
62
62
|
- **stitchkit/service-host/work**: [llms/service-host-work.txt](llms/service-host-work.txt) 4.1 KB
|
|
@@ -83,7 +83,7 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
|
|
|
83
83
|
- **stitchkit/agent-runtime/react**: [llms/agent-runtime-react.txt](llms/agent-runtime-react.txt) 1.0 KB
|
|
84
84
|
- **stitchkit/agent-runtime/realtime**: [llms/agent-runtime-realtime.txt](llms/agent-runtime-realtime.txt) 2.6 KB
|
|
85
85
|
- **stitchkit/agent-runtime/ai-sdk**: [llms/agent-runtime-ai-sdk.txt](llms/agent-runtime-ai-sdk.txt) 1.6 KB
|
|
86
|
-
- **stitchkit/process**: [llms/process.txt](llms/process.txt)
|
|
86
|
+
- **stitchkit/process**: [llms/process.txt](llms/process.txt) 43.5 KB → [llms/process.2.txt](llms/process.2.txt) 31.1 KB
|
|
87
87
|
- **stitchkit/process/bootstrap**: [llms/process-bootstrap.txt](llms/process-bootstrap.txt) 1.0 KB
|
|
88
88
|
- **stitchkit/files/packaging**: [llms/files-packaging.txt](llms/files-packaging.txt) 5.7 KB
|
|
89
89
|
- **stitchkit/http**: [llms/http.txt](llms/http.txt) 3.0 KB
|
package/package.json
CHANGED
package/dist/index-pp97q86a.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AtomicFilePublicationError2,
|
|
3
|
-
assertDirectoryDurability,
|
|
4
|
-
syncDirectory,
|
|
5
|
-
publishAtomicFile,
|
|
6
|
-
publishAtomicFileSync
|
|
7
|
-
} from "./index-2c5w2d1d.js";
|
|
8
|
-
import {
|
|
9
|
-
closeAfter,
|
|
10
|
-
closeAfterSync,
|
|
11
|
-
readBoundedFile,
|
|
12
|
-
readBoundedFileSync
|
|
13
|
-
} from "./index-s2e3h616.js";
|
|
14
|
-
import {
|
|
15
|
-
stagingPath
|
|
16
|
-
} from "./index-psye60qn.js";
|
|
17
|
-
import {
|
|
18
|
-
errnoOf
|
|
19
|
-
} from "./index-jj9228tt.js";
|
|
20
|
-
|
|
21
|
-
// src/internal/atomic-file.ts
|
|
22
|
-
import { closeSync, fchmodSync, fsyncSync, openSync, unlinkSync, writeSync } from "node:fs";
|
|
23
|
-
import { open, unlink } from "node:fs/promises";
|
|
24
|
-
import { dirname } from "node:path";
|
|
25
|
-
var DEFAULT_MODE = 384;
|
|
26
|
-
function bytesOf(data) {
|
|
27
|
-
return typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
28
|
-
}
|
|
29
|
-
function assertWriteOptions(options) {
|
|
30
|
-
if (options.idempotent === true && options.replace !== false) {
|
|
31
|
-
throw new TypeError('writeFileAtomic option "idempotent: true" requires "replace: false"');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function bytesEqual(left, right) {
|
|
35
|
-
if (left.byteLength !== right.byteLength)
|
|
36
|
-
return false;
|
|
37
|
-
for (let index = 0;index < left.byteLength; index += 1) {
|
|
38
|
-
if (left[index] !== right[index])
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
function modeMatches(actualMode, expectedMode) {
|
|
44
|
-
if (process.platform === "win32")
|
|
45
|
-
return true;
|
|
46
|
-
return actualMode !== undefined && (actualMode & 4095) === (expectedMode & 4095);
|
|
47
|
-
}
|
|
48
|
-
function syncDirectorySync(dir) {
|
|
49
|
-
assertDirectoryDurability();
|
|
50
|
-
const descriptor = openSync(dir, "r");
|
|
51
|
-
closeAfterSync(() => closeSync(descriptor), () => fsyncSync(descriptor));
|
|
52
|
-
}
|
|
53
|
-
async function writeAllBytes(file, bytes) {
|
|
54
|
-
for (let offset = 0;offset < bytes.byteLength; ) {
|
|
55
|
-
const { bytesWritten } = await file.write(bytes, offset, bytes.byteLength - offset);
|
|
56
|
-
if (bytesWritten === 0)
|
|
57
|
-
throw new Error("zero-byte atomic-file write");
|
|
58
|
-
offset += bytesWritten;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async function writeFileAtomic2(target, data, options = {}) {
|
|
62
|
-
return writeAtomicFileData(target, data, options);
|
|
63
|
-
}
|
|
64
|
-
function isMissing(error) {
|
|
65
|
-
return errnoOf(error) === "ENOENT";
|
|
66
|
-
}
|
|
67
|
-
async function publishMaybeIdempotent(staged, target, mode, options, expectedBytes, io) {
|
|
68
|
-
const publishOptions = {
|
|
69
|
-
replace: options.replace ?? true,
|
|
70
|
-
durability: options.durability ?? "file"
|
|
71
|
-
};
|
|
72
|
-
try {
|
|
73
|
-
await io.publish(staged, target, publishOptions);
|
|
74
|
-
return;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (options.idempotent !== true || errnoOf(error) !== "EEXIST" || expectedBytes === undefined) {
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
const readExisting = io.readExisting ?? ((path, maxBytes) => readBoundedFile(path, maxBytes, { rejectSymlinks: true }));
|
|
80
|
-
let existing;
|
|
81
|
-
try {
|
|
82
|
-
existing = await readExisting(target, expectedBytes.byteLength);
|
|
83
|
-
} catch (readError) {
|
|
84
|
-
if (isMissing(readError)) {
|
|
85
|
-
await io.publish(staged, target, publishOptions);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
if (!modeMatches(existing.mode, mode) || !bytesEqual(existing.bytes, expectedBytes)) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
await io.unlink(staged);
|
|
95
|
-
} catch (cleanup) {
|
|
96
|
-
if (!isMissing(cleanup))
|
|
97
|
-
throw new AtomicFilePublicationError2("cleanup", cleanup);
|
|
98
|
-
}
|
|
99
|
-
if (publishOptions.durability === "directory") {
|
|
100
|
-
try {
|
|
101
|
-
const syncDir = io.syncDir ?? syncDirectory;
|
|
102
|
-
await syncDir(dirname(target));
|
|
103
|
-
} catch (syncError) {
|
|
104
|
-
throw new AtomicFilePublicationError2("directory-sync", syncError);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async function writeAtomicFileStaged(target, stage, options, io = { open, unlink, publish: publishAtomicFile }) {
|
|
110
|
-
assertWriteOptions(options);
|
|
111
|
-
const mode = options.mode ?? DEFAULT_MODE;
|
|
112
|
-
const staged = stagingPath(target);
|
|
113
|
-
const file = await io.open(staged, "wx", mode);
|
|
114
|
-
try {
|
|
115
|
-
const value = await closeAfter(file, async () => {
|
|
116
|
-
const filled = await stage.fill(file);
|
|
117
|
-
await file.chmod(mode);
|
|
118
|
-
if (options.durability !== "none")
|
|
119
|
-
await file.sync();
|
|
120
|
-
return filled;
|
|
121
|
-
});
|
|
122
|
-
await publishMaybeIdempotent(staged, target, mode, options, stage.expectedBytes, io);
|
|
123
|
-
return value;
|
|
124
|
-
} catch (error) {
|
|
125
|
-
await io.unlink(staged).catch((cleanup) => {
|
|
126
|
-
if (!isMissing(cleanup))
|
|
127
|
-
stage.onCleanupError?.(cleanup);
|
|
128
|
-
});
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async function writeAtomicFileData(target, data, options, io) {
|
|
133
|
-
const bytes = bytesOf(data);
|
|
134
|
-
await writeAtomicFileStaged(target, { fill: (file) => writeAllBytes(file, bytes), expectedBytes: bytes }, options, io);
|
|
135
|
-
}
|
|
136
|
-
var nativeSync = {
|
|
137
|
-
open(path, flags, mode) {
|
|
138
|
-
const descriptor = openSync(path, flags, mode);
|
|
139
|
-
return {
|
|
140
|
-
write: (bytes, offset, length) => writeSync(descriptor, bytes, offset, length),
|
|
141
|
-
chmod: (bits) => fchmodSync(descriptor, bits),
|
|
142
|
-
sync: () => fsyncSync(descriptor),
|
|
143
|
-
close: () => closeSync(descriptor)
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
unlink: unlinkSync,
|
|
147
|
-
publish: publishAtomicFileSync
|
|
148
|
-
};
|
|
149
|
-
function publishMaybeIdempotentSync(staged, target, mode, options, expectedBytes, io) {
|
|
150
|
-
const publishOptions = {
|
|
151
|
-
replace: options.replace ?? true,
|
|
152
|
-
durability: options.durability ?? "file"
|
|
153
|
-
};
|
|
154
|
-
try {
|
|
155
|
-
io.publish(staged, target, publishOptions);
|
|
156
|
-
return;
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if (options.idempotent !== true || errnoOf(error) !== "EEXIST") {
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
const readExisting = io.readExisting ?? ((path, maxBytes) => readBoundedFileSync(path, maxBytes, { rejectSymlinks: true }));
|
|
162
|
-
let existing;
|
|
163
|
-
try {
|
|
164
|
-
existing = readExisting(target, expectedBytes.byteLength);
|
|
165
|
-
} catch (readError) {
|
|
166
|
-
if (isMissing(readError)) {
|
|
167
|
-
io.publish(staged, target, publishOptions);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
throw error;
|
|
171
|
-
}
|
|
172
|
-
if (!modeMatches(existing.mode, mode) || !bytesEqual(existing.bytes, expectedBytes)) {
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
io.unlink(staged);
|
|
177
|
-
} catch (cleanup) {
|
|
178
|
-
if (!isMissing(cleanup))
|
|
179
|
-
throw new AtomicFilePublicationError2("cleanup", cleanup);
|
|
180
|
-
}
|
|
181
|
-
if (publishOptions.durability === "directory") {
|
|
182
|
-
try {
|
|
183
|
-
const syncDir = io.syncDir ?? syncDirectorySync;
|
|
184
|
-
syncDir(dirname(target));
|
|
185
|
-
} catch (syncError) {
|
|
186
|
-
throw new AtomicFilePublicationError2("directory-sync", syncError);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function writeAtomicFileDataSync(target, data, options, io = nativeSync) {
|
|
192
|
-
assertWriteOptions(options);
|
|
193
|
-
const mode = options.mode ?? DEFAULT_MODE;
|
|
194
|
-
const bytes = bytesOf(data);
|
|
195
|
-
const staged = stagingPath(target);
|
|
196
|
-
const file = io.open(staged, "wx", mode);
|
|
197
|
-
try {
|
|
198
|
-
closeAfterSync(() => file.close(), () => {
|
|
199
|
-
for (let offset = 0;offset < bytes.byteLength; ) {
|
|
200
|
-
const written = file.write(bytes, offset, bytes.byteLength - offset);
|
|
201
|
-
if (written === 0)
|
|
202
|
-
throw new Error("zero-byte atomic-file write");
|
|
203
|
-
offset += written;
|
|
204
|
-
}
|
|
205
|
-
file.chmod(mode);
|
|
206
|
-
if (options.durability !== "none")
|
|
207
|
-
file.sync();
|
|
208
|
-
});
|
|
209
|
-
publishMaybeIdempotentSync(staged, target, mode, options, bytes, io);
|
|
210
|
-
} catch (error) {
|
|
211
|
-
try {
|
|
212
|
-
io.unlink(staged);
|
|
213
|
-
} catch {}
|
|
214
|
-
throw error;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function writeFileAtomicSync2(target, data, options = {}) {
|
|
218
|
-
writeAtomicFileDataSync(target, data, options);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export { writeAllBytes, writeFileAtomic2, writeAtomicFileStaged, writeAtomicFileData, writeFileAtomicSync2 };
|
|
@@ -337,6 +337,51 @@ function waitForCommandClose(closed, timeoutMs) {
|
|
|
337
337
|
return raceAbort(closed, deadline.signal).finally(() => deadline.cancel());
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
// src/process/cleanup.ts
|
|
341
|
+
async function cleanupNativeCommand(input) {
|
|
342
|
+
const signalled = Promise.resolve().then(input.signal);
|
|
343
|
+
const teardown = () => input.transport?.destroy();
|
|
344
|
+
const destroyed = signalled.then(teardown, teardown);
|
|
345
|
+
const awaitRelease = async () => {
|
|
346
|
+
if (!input.transport)
|
|
347
|
+
return;
|
|
348
|
+
try {
|
|
349
|
+
await waitForCommandClose(input.transport.released, input.timeoutMs);
|
|
350
|
+
} catch (cause) {
|
|
351
|
+
throw new Error(`Command handles remained open: ${[...input.transport.pendingHandles].join(", ")}`, { cause });
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
const released = signalled.then(awaitRelease, () => {
|
|
355
|
+
return;
|
|
356
|
+
});
|
|
357
|
+
const stopped = async () => {
|
|
358
|
+
const failed = { kind: "error", cause: input.error };
|
|
359
|
+
if (!input.transport)
|
|
360
|
+
return failed;
|
|
361
|
+
await signalled.catch(() => {
|
|
362
|
+
return;
|
|
363
|
+
});
|
|
364
|
+
const leader = await waitForCommandClose(input.transport.leader, input.timeoutMs).catch(() => {
|
|
365
|
+
return;
|
|
366
|
+
});
|
|
367
|
+
return leader?.kind === "exit" ? {
|
|
368
|
+
kind: "stopped",
|
|
369
|
+
cause: input.error,
|
|
370
|
+
exitCode: leader.exitCode,
|
|
371
|
+
signal: leader.signal
|
|
372
|
+
} : failed;
|
|
373
|
+
};
|
|
374
|
+
const cleanup = await Promise.allSettled([
|
|
375
|
+
input.event ? input.settle(input.event) : stopped().then(input.settle),
|
|
376
|
+
destroyed,
|
|
377
|
+
signalled,
|
|
378
|
+
released
|
|
379
|
+
]);
|
|
380
|
+
const failures = cleanup.flatMap((item) => item.status === "rejected" && item.reason !== input.error ? [item.reason] : []);
|
|
381
|
+
if (failures.length)
|
|
382
|
+
throw commandCleanupError(new AggregateError([input.error, ...failures], "Command failed and cleanup failed"));
|
|
383
|
+
}
|
|
384
|
+
|
|
340
385
|
// src/process/command-lifetime.ts
|
|
341
386
|
class CommandStopped extends DOMException {
|
|
342
387
|
constructor() {
|
|
@@ -384,51 +429,6 @@ function createCommandLifetime(input) {
|
|
|
384
429
|
};
|
|
385
430
|
}
|
|
386
431
|
|
|
387
|
-
// src/process/cleanup.ts
|
|
388
|
-
async function cleanupNativeCommand(input) {
|
|
389
|
-
const signalled = Promise.resolve().then(input.signal);
|
|
390
|
-
const teardown = () => input.transport?.destroy();
|
|
391
|
-
const destroyed = signalled.then(teardown, teardown);
|
|
392
|
-
const awaitRelease = async () => {
|
|
393
|
-
if (!input.transport)
|
|
394
|
-
return;
|
|
395
|
-
try {
|
|
396
|
-
await waitForCommandClose(input.transport.released, input.timeoutMs);
|
|
397
|
-
} catch (cause) {
|
|
398
|
-
throw new Error(`Command handles remained open: ${[...input.transport.pendingHandles].join(", ")}`, { cause });
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
const released = signalled.then(awaitRelease, () => {
|
|
402
|
-
return;
|
|
403
|
-
});
|
|
404
|
-
const stopped = async () => {
|
|
405
|
-
const failed = { kind: "error", cause: input.error };
|
|
406
|
-
if (!input.transport)
|
|
407
|
-
return failed;
|
|
408
|
-
await signalled.catch(() => {
|
|
409
|
-
return;
|
|
410
|
-
});
|
|
411
|
-
const leader = await waitForCommandClose(input.transport.leader, input.timeoutMs).catch(() => {
|
|
412
|
-
return;
|
|
413
|
-
});
|
|
414
|
-
return leader?.kind === "exit" ? {
|
|
415
|
-
kind: "stopped",
|
|
416
|
-
cause: input.error,
|
|
417
|
-
exitCode: leader.exitCode,
|
|
418
|
-
signal: leader.signal
|
|
419
|
-
} : failed;
|
|
420
|
-
};
|
|
421
|
-
const cleanup = await Promise.allSettled([
|
|
422
|
-
input.event ? input.settle(input.event) : stopped().then(input.settle),
|
|
423
|
-
destroyed,
|
|
424
|
-
signalled,
|
|
425
|
-
released
|
|
426
|
-
]);
|
|
427
|
-
const failures = cleanup.flatMap((item) => item.status === "rejected" && item.reason !== input.error ? [item.reason] : []);
|
|
428
|
-
if (failures.length)
|
|
429
|
-
throw commandCleanupError(new AggregateError([input.error, ...failures], "Command failed and cleanup failed"));
|
|
430
|
-
}
|
|
431
|
-
|
|
432
432
|
// src/process/launch.ts
|
|
433
433
|
import { Readable as Readable2 } from "node:stream";
|
|
434
434
|
|