stitchkit 0.132.2 → 0.133.0
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 +181 -1
- package/dist/agent-executor/acp/v1-connect.d.ts +12 -1
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +3 -1
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts +9 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-permission.d.ts +3 -2
- package/dist/agent-executor/acp/v1-permission.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-probe.d.ts +10 -1
- package/dist/agent-executor/acp/v1-probe.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +11 -2
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-turn.d.ts +13 -10
- package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +6 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/record-router.d.ts +44 -0
- package/dist/agent-executor/claude/record-router.d.ts.map +1 -0
- package/dist/agent-executor/claude/session.d.ts +2 -0
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/controls.d.ts +1 -0
- package/dist/agent-executor/claude-sdk/controls.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/driver.d.ts +20 -2
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/engine-spawn.d.ts +18 -0
- package/dist/agent-executor/claude-sdk/engine-spawn.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-loop.d.ts +9 -7
- package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-manager.d.ts +42 -0
- package/dist/agent-executor/claude-sdk/query-manager.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-options.d.ts +4 -1
- package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/capabilities.d.ts +8 -0
- package/dist/agent-executor/codex/capabilities.d.ts.map +1 -0
- package/dist/agent-executor/codex/connect.d.ts +6 -1
- package/dist/agent-executor/codex/connect.d.ts.map +1 -1
- package/dist/agent-executor/codex/driver.d.ts +10 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/event-routing.d.ts +23 -1
- package/dist/agent-executor/codex/event-routing.d.ts.map +1 -1
- package/dist/agent-executor/codex/handlers.d.ts +24 -4
- package/dist/agent-executor/codex/handlers.d.ts.map +1 -1
- package/dist/agent-executor/codex/limits.d.ts +17 -0
- package/dist/agent-executor/codex/limits.d.ts.map +1 -1
- package/dist/agent-executor/codex/request-answers.d.ts +23 -3
- package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-bind.d.ts +6 -1
- package/dist/agent-executor/codex/session-bind.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-types.d.ts +5 -1
- package/dist/agent-executor/codex/session-types.d.ts.map +1 -1
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-server.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-thread.d.ts +7 -7
- package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -1
- package/dist/agent-executor/codex/thread-open.d.ts +12 -3
- package/dist/agent-executor/codex/thread-open.d.ts.map +1 -1
- package/dist/agent-executor/engine-requests.d.ts +42 -0
- package/dist/agent-executor/engine-requests.d.ts.map +1 -1
- package/dist/agent-executor/handoff-schemas.d.ts.map +1 -1
- package/dist/agent-executor/handoff.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +6 -5
- package/dist/agent-executor/image-input.d.ts.map +1 -1
- package/dist/agent-executor/profile.d.ts +3 -5
- package/dist/agent-executor/profile.d.ts.map +1 -1
- package/dist/agent-executor/session-primitives.d.ts +64 -3
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-executor/testing/claude-sdk-stubs.d.ts +5 -0
- package/dist/agent-executor/testing/claude-sdk-stubs.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance-lifecycle.d.ts +11 -0
- package/dist/agent-executor/testing/conformance-lifecycle.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance-support.d.ts +23 -0
- package/dist/agent-executor/testing/conformance-support.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance.d.ts +7 -2
- package/dist/agent-executor/testing/conformance.d.ts.map +1 -1
- package/dist/agent-executor/testing/consumer-stubs.d.ts +5 -3
- package/dist/agent-executor/testing/consumer-stubs.d.ts.map +1 -1
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts +5 -1
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-driver.d.ts +6 -0
- package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-gate.d.ts +4 -1
- package/dist/agent-executor/testing/replay-gate.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-types.d.ts +2 -0
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools.d.ts.map +1 -1
- package/dist/agent-runtime/sql-rows.d.ts +10 -10
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
- package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
- package/dist/agent-runtime/terminal-commit.d.ts +10 -10
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/operation-refusal.d.ts +10 -0
- package/dist/browser/operation-refusal.d.ts.map +1 -0
- package/dist/contract/client-types.d.ts +13 -4
- package/dist/contract/client-types.d.ts.map +1 -1
- package/dist/contract/define-validation.d.ts +6 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +3 -0
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors-factory.d.ts +8 -2
- package/dist/contract/errors-factory.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +9 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/fingerprint.d.ts +4 -1
- package/dist/contract/fingerprint.d.ts.map +1 -1
- package/dist/contract/operation-refusals.d.ts +51 -0
- package/dist/contract/operation-refusals.d.ts.map +1 -0
- package/dist/contract/tool-options.d.ts +4 -0
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +254 -196
- package/dist/entrypoints/agent-executor/claude-sdk.js +467 -294
- package/dist/entrypoints/agent-executor/claude.js +130 -99
- package/dist/entrypoints/agent-executor/codex.js +441 -314
- package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts +3 -0
- package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/testing/claude-sdk.js +329 -0
- package/dist/entrypoints/agent-executor/testing.d.ts +1 -2
- package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/testing.js +413 -667
- package/dist/entrypoints/agent-executor.d.ts +1 -1
- package/dist/entrypoints/agent-executor.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor.js +12 -12
- package/dist/entrypoints/agent-runtime/browser.js +2 -2
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +8 -8
- package/dist/entrypoints/agent-runtime/postgres.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +2 -2
- package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +5 -5
- package/dist/entrypoints/agent-runtime.js +26 -18
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application.js +2 -2
- package/dist/entrypoints/cli.js +8 -8
- package/dist/entrypoints/contract.d.ts +3 -2
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +6 -4
- package/dist/entrypoints/files/packaging.d.ts +4 -1
- package/dist/entrypoints/files/packaging.d.ts.map +1 -1
- package/dist/entrypoints/files/packaging.js +868 -167
- package/dist/entrypoints/files.js +1 -1
- package/dist/entrypoints/handler.js +7 -7
- package/dist/entrypoints/http.js +2 -2
- package/dist/entrypoints/index.js +10 -8
- package/dist/entrypoints/node.js +11 -11
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/process/bootstrap.d.ts +3 -0
- package/dist/entrypoints/process/bootstrap.d.ts.map +1 -0
- package/dist/entrypoints/process/bootstrap.js +16 -0
- package/dist/entrypoints/process.js +7 -7
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +8 -7
- package/dist/entrypoints/server.js +30 -14
- package/dist/entrypoints/service-host/macos.js +72 -206
- package/dist/entrypoints/service-host/work.d.ts +15 -0
- package/dist/entrypoints/service-host/work.d.ts.map +1 -0
- package/dist/entrypoints/service-host/work.js +676 -0
- package/dist/entrypoints/service-host.js +146 -536
- package/dist/entrypoints/telegram/screens.js +4 -4
- package/dist/entrypoints/telegram.js +4 -4
- package/dist/entrypoints/testing.d.ts +2 -1
- package/dist/entrypoints/testing.d.ts.map +1 -1
- package/dist/entrypoints/testing.js +27 -8
- package/dist/entrypoints/tools/agent.js +6 -6
- package/dist/entrypoints/tools/connections.js +2 -2
- package/dist/entrypoints/tools/invoker.js +5 -5
- package/dist/entrypoints/tools/mcp.js +8 -6
- package/dist/entrypoints/tools/toolkit.js +11 -9
- package/dist/entrypoints/tools.js +19 -17
- package/dist/entrypoints/tracking/contract.js +1 -1
- package/dist/entrypoints/tracking/performance.js +3 -3
- package/dist/files/client-artifact.d.ts +14 -42
- package/dist/files/client-artifact.d.ts.map +1 -1
- package/dist/files/client-build.d.ts +57 -0
- package/dist/files/client-build.d.ts.map +1 -0
- package/dist/files/client-declarations.d.ts +35 -0
- package/dist/files/client-declarations.d.ts.map +1 -0
- package/dist/files/client-package-contract.d.ts +162 -0
- package/dist/files/client-package-contract.d.ts.map +1 -0
- package/dist/files/client-package-proof.d.ts +38 -0
- package/dist/files/client-package-proof.d.ts.map +1 -0
- package/dist/files/client-package.d.ts +17 -0
- package/dist/files/client-package.d.ts.map +1 -0
- package/dist/files/declaration-specifiers.d.ts +30 -0
- package/dist/files/declaration-specifiers.d.ts.map +1 -0
- package/dist/{index-v759mzed.js → index-02r5sq9p.js} +36 -23
- package/dist/{index-0r15pkjq.js → index-0k1ba0ss.js} +1 -1
- package/dist/{index-znd1b57f.js → index-1dn2wjq6.js} +5 -4
- package/dist/{index-p06z7g7w.js → index-1p8q0yrt.js} +6 -5
- package/dist/{index-wa6h4tz6.js → index-1qwd54n3.js} +6 -5
- package/dist/index-2dzc7mv9.js +174 -0
- package/dist/index-2mz8hj58.js +155 -0
- package/dist/{index-17qgm6xe.js → index-34k82crg.js} +2 -2
- package/dist/index-3mcbr8sx.js +349 -0
- package/dist/{index-ybdq8kk2.js → index-3y2tzhr8.js} +3 -3
- package/dist/{index-fgahdc7s.js → index-5n3a8hd8.js} +5 -3
- package/dist/{index-jb4m241t.js → index-6918kxbf.js} +45 -1
- package/dist/{index-n3bm7zqq.js → index-6kmjcm81.js} +4 -4
- package/dist/{index-akf0xkrm.js → index-78da4g74.js} +1 -1
- package/dist/{index-9pv126eh.js → index-7fjbdga8.js} +7 -1
- package/dist/{index-zhshhxew.js → index-8jf4bt7v.js} +1 -1
- package/dist/{index-p16q492v.js → index-8t9dr41h.js} +18 -5
- package/dist/{index-xq4s9mka.js → index-8yt3rwe7.js} +1 -1
- package/dist/{index-39c2hj6h.js → index-9c76vfxf.js} +7 -3
- package/dist/index-9ft4n9j1.js +432 -0
- package/dist/{index-sd4e5x5j.js → index-9wdrwx3b.js} +8 -7
- package/dist/{index-z114ax5e.js → index-an7vcmwf.js} +49 -2
- package/dist/{index-pzhqydxb.js → index-d04w81fz.js} +1 -1
- package/dist/index-d2drhb9c.js +219 -0
- package/dist/{index-8gmmdz7k.js → index-dacxr7nf.js} +1 -1
- package/dist/{index-dnzxxf8a.js → index-dm6nxkn1.js} +1 -1
- package/dist/index-dxft2mnm.js +42 -0
- package/dist/{index-rxh3qy4x.js → index-fzd477xk.js} +1 -1
- package/dist/{index-xgae0bn7.js → index-g4gstmp1.js} +2 -2
- package/dist/{index-athc412x.js → index-g5fgeb6v.js} +1 -1
- package/dist/{index-z9d74jmb.js → index-gbhj370g.js} +3 -3
- package/dist/{index-3fym4j8n.js → index-gtaaxe9d.js} +1 -1
- package/dist/{index-v59pxmf1.js → index-jpecjm30.js} +2 -2
- package/dist/index-k9g061ma.js +164 -0
- package/dist/{index-669374qc.js → index-ma26mfnt.js} +84 -315
- package/dist/{index-ryxb427v.js → index-msxf2r8x.js} +16 -3
- package/dist/{index-rbd2rq3z.js → index-nr4fhfn4.js} +1 -1
- package/dist/{index-qa2jjb65.js → index-pbekeqzm.js} +1 -1
- package/dist/{index-mkfhpk11.js → index-pq6g1k9t.js} +2 -2
- package/dist/{index-gya4hwh3.js → index-pws5c3x6.js} +21 -1
- package/dist/{index-x2fb37t0.js → index-q427q23r.js} +3 -2
- package/dist/{index-jcrj0b8z.js → index-qggqqja2.js} +39 -2
- package/dist/{index-jxtg307y.js → index-rkjfzs0a.js} +1 -1
- package/dist/{index-5tdc0q43.js → index-rw8ze745.js} +5 -3
- package/dist/index-s43tr4my.js +129 -0
- package/dist/{index-f9p62ean.js → index-stpy56r3.js} +175 -249
- package/dist/index-t5g5rm9n.js +213 -0
- package/dist/{index-z20pdxeb.js → index-tmv3ez1h.js} +3 -3
- package/dist/{index-dcsxj68j.js → index-tqjamnax.js} +1 -1
- package/dist/{index-j15dhkda.js → index-wddcfbng.js} +1 -325
- package/dist/{index-9sfhje6y.js → index-wh70tmpd.js} +24 -234
- package/dist/index-wxjv4sqx.js +82 -0
- package/dist/{index-qhjmmsm2.js → index-x46y9z26.js} +2 -2
- package/dist/{index-nk0cy9g1.js → index-y53cqwke.js} +1 -1
- package/dist/{index-sv5svtq7.js → index-y68gavb5.js} +1 -1
- package/dist/{index-5y7j383h.js → index-yrhw10ef.js} +1 -1
- package/dist/process/bootstrap.d.ts +12 -0
- package/dist/process/bootstrap.d.ts.map +1 -0
- package/dist/process/owner-loss-guard.d.ts +2 -9
- package/dist/process/owner-loss-guard.d.ts.map +1 -1
- package/dist/process/work-root.d.ts +20 -0
- package/dist/process/work-root.d.ts.map +1 -0
- package/dist/server/contract-identity.d.ts.map +1 -1
- package/dist/server/contract-method.d.ts +12 -0
- package/dist/server/contract-method.d.ts.map +1 -1
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/types.d.ts +10 -9
- package/dist/server/types.d.ts.map +1 -1
- package/dist/service-host/host-adapter.d.ts +2 -0
- package/dist/service-host/host-adapter.d.ts.map +1 -1
- package/dist/service-host/work/command.d.ts +72 -0
- package/dist/service-host/work/command.d.ts.map +1 -0
- package/dist/service-host/work/errors.d.ts +29 -0
- package/dist/service-host/work/errors.d.ts.map +1 -0
- package/dist/service-host/work/host.d.ts +38 -0
- package/dist/service-host/work/host.d.ts.map +1 -0
- package/dist/service-host/work/launch.d.ts +51 -0
- package/dist/service-host/work/launch.d.ts.map +1 -0
- package/dist/service-host/work/membership.d.ts +51 -0
- package/dist/service-host/work/membership.d.ts.map +1 -0
- package/dist/service-host/work/origin.d.ts +79 -0
- package/dist/service-host/work/origin.d.ts.map +1 -0
- package/dist/service-host/work/owner.d.ts +45 -0
- package/dist/service-host/work/owner.d.ts.map +1 -0
- package/dist/service-host/work/placement.d.ts +55 -0
- package/dist/service-host/work/placement.d.ts.map +1 -0
- package/dist/service-host/work/probe.d.ts +24 -0
- package/dist/service-host/work/probe.d.ts.map +1 -0
- package/dist/service-host/work/scope-command.d.ts +68 -0
- package/dist/service-host/work/scope-command.d.ts.map +1 -0
- package/dist/sync/session.d.ts +4 -1
- package/dist/sync/session.d.ts.map +1 -1
- package/dist/testing/surface-manifest-digest.d.ts +2 -0
- package/dist/testing/surface-manifest-digest.d.ts.map +1 -1
- package/dist/testing/surface-manifest.d.ts +32 -3
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +2 -0
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts.map +1 -1
- package/dist/tools/internal/mcp-projection.d.ts +58 -0
- package/dist/tools/internal/mcp-projection.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +3 -47
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +2 -0
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -0
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +4 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/prepare.d.ts +5 -2
- package/dist/tools/mcp/prepare.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +2 -0
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/schema/nesting-limit.d.ts +8 -0
- package/dist/tools/schema/nesting-limit.d.ts.map +1 -0
- package/dist/tools/schema/presentation.d.ts +7 -0
- package/dist/tools/schema/presentation.d.ts.map +1 -1
- package/dist/tools/surface.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +3 -3
- package/llms/agent-executor-claude-sdk.txt +1 -1
- package/llms/agent-executor-claude.txt +1 -1
- package/llms/agent-executor-codex.txt +1 -1
- package/llms/agent-executor-testing-claude-sdk.txt +28 -0
- package/llms/agent-executor-testing.txt +7 -8
- package/llms/agent-executor.txt +27 -4
- package/llms/agent-runtime.txt +1 -1
- package/llms/contract.txt +8 -2
- package/llms/files-packaging.txt +11 -6
- package/llms/process-bootstrap.txt +18 -0
- package/llms/process.2.txt +215 -18
- package/llms/process.txt +130 -92
- package/llms/server.4.txt +49 -1
- package/llms/service-host-work.txt +34 -0
- package/llms/stitchkit.2.txt +31 -0
- package/llms/stitchkit.txt +78 -75
- package/llms/sync.txt +5 -2
- package/llms/testing.txt +1 -0
- package/llms/tools.2.txt +747 -775
- package/llms/tools.3.txt +846 -210
- package/llms/tools.4.txt +226 -0
- package/llms/tools.txt +3 -790
- package/llms/{upgrading-0.128.0-0.132.0.txt → upgrading-0.128.0-0.133.0.txt} +194 -6
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +746 -135
- package/llms.txt +18 -16
- package/package.json +12 -4
- package/dist/entrypoints/process/owner-loss.d.ts +0 -3
- package/dist/entrypoints/process/owner-loss.d.ts.map +0 -1
- package/dist/entrypoints/process/owner-loss.js +0 -7
- package/llms/process-owner-loss.txt +0 -18
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import"../../index-6kec3b14.js";
|
|
2
|
+
import {
|
|
3
|
+
probeLiveness,
|
|
4
|
+
ProcessInstanceSchema2,
|
|
5
|
+
sameProcessInstance,
|
|
6
|
+
observeProcessInstance2,
|
|
7
|
+
readProcessInstanceSync
|
|
8
|
+
} from "../../index-673drwkn.js";
|
|
9
|
+
import {
|
|
10
|
+
workRootCommand
|
|
11
|
+
} from "../../index-wxjv4sqx.js";
|
|
12
|
+
import"../../index-jpecjm30.js";
|
|
13
|
+
import {
|
|
14
|
+
startNativeCommand
|
|
15
|
+
} from "../../index-pbekeqzm.js";
|
|
16
|
+
import"../../index-21cfxc4z.js";
|
|
17
|
+
import {
|
|
18
|
+
SystemdScopeSchema2,
|
|
19
|
+
SYSTEMCTL_PATH,
|
|
20
|
+
systemdScopeArgs
|
|
21
|
+
} from "../../index-9ft4n9j1.js";
|
|
22
|
+
import {
|
|
23
|
+
hostCommandEnv
|
|
24
|
+
} from "../../index-d2drhb9c.js";
|
|
25
|
+
import {
|
|
26
|
+
PS_PATH2,
|
|
27
|
+
createDefaultMacosCommandRunner2
|
|
28
|
+
} from "../../index-2mz8hj58.js";
|
|
29
|
+
import {
|
|
30
|
+
runNativeCommand2
|
|
31
|
+
} from "../../index-d04w81fz.js";
|
|
32
|
+
import {
|
|
33
|
+
errnoOf
|
|
34
|
+
} from "../../index-jj9228tt.js";
|
|
35
|
+
|
|
36
|
+
// src/service-host/work/command.ts
|
|
37
|
+
import { z as z5 } from "zod";
|
|
38
|
+
|
|
39
|
+
// src/service-host/work/errors.ts
|
|
40
|
+
import { z } from "zod";
|
|
41
|
+
var WorkLaunchErrorReasonSchema = z.enum([
|
|
42
|
+
"origin-unreadable",
|
|
43
|
+
"platform-unsupported",
|
|
44
|
+
"systemd-unavailable",
|
|
45
|
+
"systemd-too-old",
|
|
46
|
+
"manager-unreachable",
|
|
47
|
+
"manager-unauthorized",
|
|
48
|
+
"user-manager-unreachable",
|
|
49
|
+
"slice-unresolvable",
|
|
50
|
+
"unit-exists",
|
|
51
|
+
"scope-refused",
|
|
52
|
+
"root-unobservable",
|
|
53
|
+
"root-unobserved",
|
|
54
|
+
"membership-unavailable",
|
|
55
|
+
"stop-failed"
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
class WorkLaunchError extends Error {
|
|
59
|
+
reason;
|
|
60
|
+
constructor(reason, message, options) {
|
|
61
|
+
super(message, options);
|
|
62
|
+
this.name = "WorkLaunchError";
|
|
63
|
+
this.reason = WorkLaunchErrorReasonSchema.parse(reason);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/service-host/work/host.ts
|
|
68
|
+
import { readFile, stat } from "node:fs/promises";
|
|
69
|
+
var HOST_COMMAND_TIMEOUT_MS = 30000;
|
|
70
|
+
var HOST_COMMAND_MAX_OUTPUT_BYTES = 64 * 1024;
|
|
71
|
+
function parseLinuxLineage(stat) {
|
|
72
|
+
const end = stat.lastIndexOf(")");
|
|
73
|
+
if (end < 0)
|
|
74
|
+
return null;
|
|
75
|
+
const fields = stat.slice(end + 1).trim().split(/\s+/);
|
|
76
|
+
const ppid = Number(fields[1]);
|
|
77
|
+
const pgid = Number(fields[2]);
|
|
78
|
+
return Number.isSafeInteger(ppid) && Number.isSafeInteger(pgid) && ppid >= 0 && pgid >= 0 ? { ppid, pgid } : null;
|
|
79
|
+
}
|
|
80
|
+
function parsePsLineage(stdout) {
|
|
81
|
+
const match = /^\s*(\d+)\s+(\d+)\s*$/.exec(stdout);
|
|
82
|
+
return match ? { ppid: Number(match[1]), pgid: Number(match[2]) } : null;
|
|
83
|
+
}
|
|
84
|
+
async function readText(path) {
|
|
85
|
+
try {
|
|
86
|
+
return await readFile(path, "utf8");
|
|
87
|
+
} catch (cause) {
|
|
88
|
+
const code = errnoOf(cause);
|
|
89
|
+
if (code === "ENOENT" || code === "ESRCH")
|
|
90
|
+
return null;
|
|
91
|
+
throw cause;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function darwinLineage(pid) {
|
|
95
|
+
const result = await createDefaultMacosCommandRunner2().runCommand(PS_PATH2, [
|
|
96
|
+
"-o",
|
|
97
|
+
"ppid=,pgid=",
|
|
98
|
+
"-p",
|
|
99
|
+
String(pid)
|
|
100
|
+
]);
|
|
101
|
+
const lineage = parsePsLineage(result.stdout);
|
|
102
|
+
if (lineage !== null)
|
|
103
|
+
return lineage;
|
|
104
|
+
if (result.exitCode === 1 && result.stdout.trim().length === 0)
|
|
105
|
+
return null;
|
|
106
|
+
throw new Error(`ps did not report the process: ${result.stderr.trim()}`);
|
|
107
|
+
}
|
|
108
|
+
function createDefaultWorkHost() {
|
|
109
|
+
const decoder = new TextDecoder;
|
|
110
|
+
return {
|
|
111
|
+
platform: process.platform,
|
|
112
|
+
uid: typeof process.getuid === "function" ? process.getuid() : null,
|
|
113
|
+
env: process.env,
|
|
114
|
+
canReplaceProcess: typeof process.execve === "function",
|
|
115
|
+
async runCommand(executable, args, options) {
|
|
116
|
+
const result = await runNativeCommand2({
|
|
117
|
+
executable,
|
|
118
|
+
args: [...args],
|
|
119
|
+
envPolicy: "declared-only",
|
|
120
|
+
env: { ...hostCommandEnv(), ...options?.env },
|
|
121
|
+
capture: true,
|
|
122
|
+
maxOutputBytes: HOST_COMMAND_MAX_OUTPUT_BYTES,
|
|
123
|
+
timeoutMs: HOST_COMMAND_TIMEOUT_MS
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
exitCode: result.exitCode ?? 1,
|
|
127
|
+
stdout: decoder.decode(result.stdout),
|
|
128
|
+
stderr: decoder.decode(result.stderr)
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
readText,
|
|
132
|
+
async directoryOwner(path) {
|
|
133
|
+
try {
|
|
134
|
+
const entry = await stat(path);
|
|
135
|
+
return entry.isDirectory() ? entry.uid : null;
|
|
136
|
+
} catch (cause) {
|
|
137
|
+
if (errnoOf(cause) === "ENOENT")
|
|
138
|
+
return null;
|
|
139
|
+
throw cause;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
observeInstance: observeProcessInstance2,
|
|
143
|
+
liveness: (pid) => probeLiveness(pid),
|
|
144
|
+
async lineage(pid) {
|
|
145
|
+
if (process.platform === "darwin")
|
|
146
|
+
return darwinLineage(pid);
|
|
147
|
+
const text = await readText(`/proc/${pid}/stat`);
|
|
148
|
+
if (text === null)
|
|
149
|
+
return null;
|
|
150
|
+
const lineage = parseLinuxLineage(text);
|
|
151
|
+
if (lineage === null)
|
|
152
|
+
throw new Error(`Unreadable /proc/${pid}/stat`);
|
|
153
|
+
return lineage;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/service-host/work/origin.ts
|
|
159
|
+
import { z as z3 } from "zod";
|
|
160
|
+
|
|
161
|
+
// src/service-host/work/owner.ts
|
|
162
|
+
import { z as z2 } from "zod";
|
|
163
|
+
var PRINTABLE = /^\P{Cc}+$/u;
|
|
164
|
+
var WorkLauncherSchema = z2.string().min(1).max(32).regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/);
|
|
165
|
+
var WorkIdSchema = z2.string().min(1).max(96).regex(/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/);
|
|
166
|
+
var WorkRefSchema = z2.strictObject({
|
|
167
|
+
launcher: WorkLauncherSchema,
|
|
168
|
+
id: WorkIdSchema
|
|
169
|
+
});
|
|
170
|
+
var WorkAgentSchema = z2.strictObject({
|
|
171
|
+
harness: z2.string().trim().min(1).max(64).regex(PRINTABLE),
|
|
172
|
+
model: z2.string().trim().min(1).max(64).regex(PRINTABLE),
|
|
173
|
+
address: z2.string().trim().min(1).max(128).regex(PRINTABLE)
|
|
174
|
+
});
|
|
175
|
+
var WorkOwnerSchema = z2.strictObject({
|
|
176
|
+
launcher: WorkLauncherSchema,
|
|
177
|
+
id: WorkIdSchema,
|
|
178
|
+
label: z2.string().trim().min(1).max(120).regex(PRINTABLE),
|
|
179
|
+
project: z2.string().min(1).max(128).regex(/^\S+$/).nullable(),
|
|
180
|
+
agent: WorkAgentSchema.nullable(),
|
|
181
|
+
parent: WorkRefSchema.nullable()
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// src/service-host/work/origin.ts
|
|
185
|
+
var MAX_PID = 2 ** 31 - 1;
|
|
186
|
+
var WORK_ORIGIN_ENV = "STITCHKIT_WORK_ORIGIN";
|
|
187
|
+
var MAX_WORK_ORIGIN_BYTES = 1024;
|
|
188
|
+
var WorkScopeUnitSchema = z3.string().max(255).regex(/^[a-z][a-z0-9-]*-[A-Za-z0-9][A-Za-z0-9_.:-]*\.scope$/);
|
|
189
|
+
var WorkBoundarySchema = z3.discriminatedUnion("kind", [
|
|
190
|
+
z3.strictObject({
|
|
191
|
+
kind: z3.literal("transient-scope"),
|
|
192
|
+
manager: SystemdScopeSchema2,
|
|
193
|
+
unit: WorkScopeUnitSchema
|
|
194
|
+
}),
|
|
195
|
+
z3.strictObject({
|
|
196
|
+
kind: z3.literal("process-root"),
|
|
197
|
+
root: z3.strictObject({
|
|
198
|
+
pid: z3.number().int().positive().max(MAX_PID),
|
|
199
|
+
instance: ProcessInstanceSchema2
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
]);
|
|
203
|
+
var WorkOriginSchema = z3.strictObject({
|
|
204
|
+
v: z3.literal(1),
|
|
205
|
+
work: WorkRefSchema,
|
|
206
|
+
boundary: WorkBoundarySchema
|
|
207
|
+
});
|
|
208
|
+
function workOriginPrefix(work) {
|
|
209
|
+
return { v: 1, work: WorkRefSchema.parse(work) };
|
|
210
|
+
}
|
|
211
|
+
function encodeWorkOrigin(origin) {
|
|
212
|
+
const text = JSON.stringify(WorkOriginSchema.parse(origin));
|
|
213
|
+
if (Buffer.byteLength(text) > MAX_WORK_ORIGIN_BYTES)
|
|
214
|
+
throw new WorkLaunchError("origin-unreadable", `${WORK_ORIGIN_ENV} would exceed ${MAX_WORK_ORIGIN_BYTES} bytes`);
|
|
215
|
+
return text;
|
|
216
|
+
}
|
|
217
|
+
function readWorkOrigin(env = process.env) {
|
|
218
|
+
const text = env[WORK_ORIGIN_ENV];
|
|
219
|
+
if (text === undefined)
|
|
220
|
+
return null;
|
|
221
|
+
try {
|
|
222
|
+
if (Buffer.byteLength(text) > MAX_WORK_ORIGIN_BYTES)
|
|
223
|
+
throw new Error(`value exceeds ${MAX_WORK_ORIGIN_BYTES} bytes`);
|
|
224
|
+
return WorkOriginSchema.parse(JSON.parse(text));
|
|
225
|
+
} catch (cause) {
|
|
226
|
+
throw new WorkLaunchError("origin-unreadable", `${WORK_ORIGIN_ENV} does not parse`, {
|
|
227
|
+
cause
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/service-host/work/placement.ts
|
|
233
|
+
import { z as z4 } from "zod";
|
|
234
|
+
var MAX_MEMORY_MB = 2 ** 30;
|
|
235
|
+
var WorkScopeLimitsSchema = z4.strictObject({
|
|
236
|
+
memoryMaxMb: z4.number().int().positive().max(MAX_MEMORY_MB).optional(),
|
|
237
|
+
memorySwapMaxMb: z4.number().int().nonnegative().max(MAX_MEMORY_MB).optional(),
|
|
238
|
+
cpuQuotaPercent: z4.number().int().positive().max(1e5).optional(),
|
|
239
|
+
cpuWeight: z4.number().int().min(1).max(1e4).optional(),
|
|
240
|
+
runtimeMaxSeconds: z4.number().int().positive().max(31536000).optional()
|
|
241
|
+
});
|
|
242
|
+
var NamedSliceSchema = z4.string().max(255).regex(/^[A-Za-z0-9][A-Za-z0-9_.:-]*\.slice$/);
|
|
243
|
+
var WorkScopePlacementSchema = z4.strictObject({
|
|
244
|
+
kind: z4.literal("transient-scope"),
|
|
245
|
+
manager: SystemdScopeSchema2,
|
|
246
|
+
slice: z4.union([z4.literal("caller"), NamedSliceSchema]),
|
|
247
|
+
limits: WorkScopeLimitsSchema.optional()
|
|
248
|
+
});
|
|
249
|
+
var WorkPlacementSchema = z4.discriminatedUnion("kind", [
|
|
250
|
+
WorkScopePlacementSchema,
|
|
251
|
+
z4.strictObject({ kind: z4.literal("process-root") })
|
|
252
|
+
]);
|
|
253
|
+
|
|
254
|
+
// src/service-host/work/scope-command.ts
|
|
255
|
+
var SYSTEMD_RUN_PATH = "/usr/bin/systemd-run";
|
|
256
|
+
var MIN_SYSTEMD_VERSION = 254;
|
|
257
|
+
function workUnitName(work) {
|
|
258
|
+
const ref = WorkRefSchema.parse({ launcher: work.launcher, id: work.id });
|
|
259
|
+
return `${ref.launcher}-${ref.id}.scope`;
|
|
260
|
+
}
|
|
261
|
+
function unifiedControlGroup(text) {
|
|
262
|
+
for (const line of text.split(`
|
|
263
|
+
`))
|
|
264
|
+
if (line.startsWith("0::"))
|
|
265
|
+
return line.slice(3);
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
var USER_MANAGER_UNIT = /^user@\d+\.service$/;
|
|
269
|
+
function callerSlice(controlGroup, manager) {
|
|
270
|
+
const components = controlGroup.split("/").filter((part) => part.length > 0);
|
|
271
|
+
const userManager = components.findIndex((part) => USER_MANAGER_UNIT.test(part));
|
|
272
|
+
const owned = manager === "user" ? userManager < 0 ? [] : components.slice(userManager + 1) : userManager < 0 ? components : components.slice(0, userManager);
|
|
273
|
+
return owned.findLast((part) => part.endsWith(".slice")) ?? null;
|
|
274
|
+
}
|
|
275
|
+
async function resolveCallerSlice(host, manager) {
|
|
276
|
+
const text = await host.readText("/proc/self/cgroup");
|
|
277
|
+
const controlGroup = text === null ? null : unifiedControlGroup(text);
|
|
278
|
+
const slice = controlGroup === null ? null : callerSlice(controlGroup, manager);
|
|
279
|
+
if (slice === null)
|
|
280
|
+
throw new WorkLaunchError("slice-unresolvable", `The caller has no slice of its own under the ${manager} manager; name the slice`, { cause: { controlGroup } });
|
|
281
|
+
return slice;
|
|
282
|
+
}
|
|
283
|
+
async function userManagerEnv(host) {
|
|
284
|
+
const env = {};
|
|
285
|
+
const bus = host.env.DBUS_SESSION_BUS_ADDRESS;
|
|
286
|
+
if (bus !== undefined)
|
|
287
|
+
env.DBUS_SESSION_BUS_ADDRESS = bus;
|
|
288
|
+
const declared = host.env.XDG_RUNTIME_DIR;
|
|
289
|
+
if (declared !== undefined && declared.length > 0)
|
|
290
|
+
return { ...env, XDG_RUNTIME_DIR: declared };
|
|
291
|
+
const runtimeDir = host.uid === null ? null : `/run/user/${host.uid}`;
|
|
292
|
+
if (runtimeDir !== null && await host.directoryOwner(runtimeDir) === host.uid)
|
|
293
|
+
return { ...env, XDG_RUNTIME_DIR: runtimeDir };
|
|
294
|
+
throw new WorkLaunchError("user-manager-unreachable", "No XDG_RUNTIME_DIR and no runtime directory of the caller: its user manager cannot be reached", { cause: { runtimeDir } });
|
|
295
|
+
}
|
|
296
|
+
async function managerEnv(host, manager) {
|
|
297
|
+
return manager === "user" ? userManagerEnv(host) : {};
|
|
298
|
+
}
|
|
299
|
+
function classifyManagerFailure(stderr, manager) {
|
|
300
|
+
if (stderr.includes("not been booted with systemd"))
|
|
301
|
+
return "systemd-unavailable";
|
|
302
|
+
if (/Failed to connect to (?:\w+ )*bus/.test(stderr))
|
|
303
|
+
return manager === "user" ? "user-manager-unreachable" : "manager-unreachable";
|
|
304
|
+
if (stderr.includes("was already loaded or has a fragment file"))
|
|
305
|
+
return "unit-exists";
|
|
306
|
+
return "scope-refused";
|
|
307
|
+
}
|
|
308
|
+
function parseSystemdVersion(stdout) {
|
|
309
|
+
const match = /^systemd (\d+)\b/.exec(stdout);
|
|
310
|
+
return match ? Number(match[1]) : null;
|
|
311
|
+
}
|
|
312
|
+
function assertManagerAuthorized(host, manager) {
|
|
313
|
+
if (manager === "system" && host.uid !== 0)
|
|
314
|
+
throw new WorkLaunchError("manager-unauthorized", `The system manager takes transient scopes from root only (uid ${String(host.uid)}); place the work on manager 'user'`);
|
|
315
|
+
}
|
|
316
|
+
async function assertSystemdRunVersion(host) {
|
|
317
|
+
if (host.platform !== "linux")
|
|
318
|
+
throw new WorkLaunchError("platform-unsupported", "A transient scope needs Linux with systemd");
|
|
319
|
+
let result;
|
|
320
|
+
try {
|
|
321
|
+
result = await host.runCommand(SYSTEMD_RUN_PATH, ["--version"]);
|
|
322
|
+
} catch (cause) {
|
|
323
|
+
throw new WorkLaunchError("systemd-unavailable", `${SYSTEMD_RUN_PATH} could not run`, {
|
|
324
|
+
cause
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
const version = result.exitCode === 0 ? parseSystemdVersion(result.stdout) : null;
|
|
328
|
+
if (version === null)
|
|
329
|
+
throw new WorkLaunchError("systemd-unavailable", "systemd-run did not report its version", {
|
|
330
|
+
cause: result
|
|
331
|
+
});
|
|
332
|
+
if (version < MIN_SYSTEMD_VERSION)
|
|
333
|
+
throw new WorkLaunchError("systemd-too-old", `systemd ${version} is older than ${MIN_SYSTEMD_VERSION}: its systemd-run cannot pass a command's arguments unexpanded`, { cause: { version, required: MIN_SYSTEMD_VERSION } });
|
|
334
|
+
return version;
|
|
335
|
+
}
|
|
336
|
+
function limitProperties(limits) {
|
|
337
|
+
if (limits === undefined)
|
|
338
|
+
return [];
|
|
339
|
+
const properties = [];
|
|
340
|
+
if (limits.memoryMaxMb !== undefined)
|
|
341
|
+
properties.push(`MemoryMax=${limits.memoryMaxMb}M`);
|
|
342
|
+
if (limits.memorySwapMaxMb !== undefined)
|
|
343
|
+
properties.push(`MemorySwapMax=${limits.memorySwapMaxMb}M`);
|
|
344
|
+
if (limits.cpuQuotaPercent !== undefined)
|
|
345
|
+
properties.push(`CPUQuota=${limits.cpuQuotaPercent}%`);
|
|
346
|
+
if (limits.cpuWeight !== undefined)
|
|
347
|
+
properties.push(`CPUWeight=${limits.cpuWeight}`);
|
|
348
|
+
if (limits.runtimeMaxSeconds !== undefined)
|
|
349
|
+
properties.push(`RuntimeMaxSec=${limits.runtimeMaxSeconds}`);
|
|
350
|
+
return properties.map((property) => `--property=${property}`);
|
|
351
|
+
}
|
|
352
|
+
function scopeCommandArgs(input) {
|
|
353
|
+
return [
|
|
354
|
+
...input.manager === "user" ? ["--user"] : [],
|
|
355
|
+
"--scope",
|
|
356
|
+
"--quiet",
|
|
357
|
+
"--collect",
|
|
358
|
+
"--expand-environment=no",
|
|
359
|
+
`--unit=${input.unit}`,
|
|
360
|
+
`--description=${input.description}`,
|
|
361
|
+
`--slice=${input.slice}`,
|
|
362
|
+
...limitProperties(input.limits),
|
|
363
|
+
"--",
|
|
364
|
+
input.executable,
|
|
365
|
+
...input.args
|
|
366
|
+
];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/service-host/work/command.ts
|
|
370
|
+
var WorkCommandInputSchema = z5.strictObject({
|
|
371
|
+
owner: WorkOwnerSchema,
|
|
372
|
+
placement: WorkPlacementSchema,
|
|
373
|
+
executable: z5.string().min(1),
|
|
374
|
+
args: z5.array(z5.string()).default([]),
|
|
375
|
+
env: z5.record(z5.string(), z5.string())
|
|
376
|
+
});
|
|
377
|
+
async function workCommandWith(host, input) {
|
|
378
|
+
const { owner, placement, executable, args, env } = WorkCommandInputSchema.parse(input);
|
|
379
|
+
const work = { launcher: owner.launcher, id: owner.id };
|
|
380
|
+
if (placement.kind === "process-root") {
|
|
381
|
+
if (host.platform !== "linux" && host.platform !== "darwin")
|
|
382
|
+
throw new WorkLaunchError("platform-unsupported", "A process root needs Linux or macOS");
|
|
383
|
+
if (!host.canReplaceProcess)
|
|
384
|
+
throw new WorkLaunchError("platform-unsupported", "A process root needs a runtime with process.execve");
|
|
385
|
+
const [root, ...rootArgs] = workRootCommand({
|
|
386
|
+
variable: WORK_ORIGIN_ENV,
|
|
387
|
+
origin: workOriginPrefix(work),
|
|
388
|
+
executable,
|
|
389
|
+
args
|
|
390
|
+
});
|
|
391
|
+
return { executable: root, args: rootArgs, env: { ...env }, work, unit: null };
|
|
392
|
+
}
|
|
393
|
+
await assertSystemdRunVersion(host);
|
|
394
|
+
assertManagerAuthorized(host, placement.manager);
|
|
395
|
+
const unit = workUnitName(work);
|
|
396
|
+
const slice = placement.slice === "caller" ? await resolveCallerSlice(host, placement.manager) : placement.slice;
|
|
397
|
+
return {
|
|
398
|
+
executable: SYSTEMD_RUN_PATH,
|
|
399
|
+
args: scopeCommandArgs({
|
|
400
|
+
manager: placement.manager,
|
|
401
|
+
unit,
|
|
402
|
+
description: owner.label,
|
|
403
|
+
slice,
|
|
404
|
+
limits: placement.limits,
|
|
405
|
+
executable,
|
|
406
|
+
args
|
|
407
|
+
}),
|
|
408
|
+
env: {
|
|
409
|
+
...env,
|
|
410
|
+
...await managerEnv(host, placement.manager),
|
|
411
|
+
[WORK_ORIGIN_ENV]: encodeWorkOrigin({
|
|
412
|
+
v: 1,
|
|
413
|
+
work,
|
|
414
|
+
boundary: { kind: "transient-scope", manager: placement.manager, unit }
|
|
415
|
+
})
|
|
416
|
+
},
|
|
417
|
+
work,
|
|
418
|
+
unit: { manager: placement.manager, name: unit }
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
function workCommand(input) {
|
|
422
|
+
return workCommandWith(createDefaultWorkHost(), input);
|
|
423
|
+
}
|
|
424
|
+
// src/service-host/work/membership.ts
|
|
425
|
+
import { z as z6 } from "zod";
|
|
426
|
+
var MAX_PID2 = 2 ** 31 - 1;
|
|
427
|
+
var MAX_ANCESTORS = 256;
|
|
428
|
+
var MembershipInputSchema = z6.strictObject({
|
|
429
|
+
pid: z6.number().int().positive().max(MAX_PID2),
|
|
430
|
+
boundary: WorkBoundarySchema
|
|
431
|
+
});
|
|
432
|
+
var unavailable = (reason, cause) => ({ state: "unavailable", reason, cause });
|
|
433
|
+
async function scopeMembership(host, pid, unit) {
|
|
434
|
+
if (host.platform !== "linux")
|
|
435
|
+
return unavailable("platform-unsupported", new Error("A transient scope is read on Linux"));
|
|
436
|
+
let text;
|
|
437
|
+
try {
|
|
438
|
+
text = await host.readText(`/proc/${pid}/cgroup`);
|
|
439
|
+
} catch (cause) {
|
|
440
|
+
return unavailable("proc-unreadable", cause);
|
|
441
|
+
}
|
|
442
|
+
if (text === null) {
|
|
443
|
+
return await host.liveness(pid) === "gone" ? { state: "gone" } : unavailable("proc-unreadable", new Error(`/proc/${pid}/cgroup is hidden`));
|
|
444
|
+
}
|
|
445
|
+
if (await host.liveness(pid) === "gone")
|
|
446
|
+
return { state: "gone" };
|
|
447
|
+
const controlGroup = unifiedControlGroup(text);
|
|
448
|
+
if (controlGroup === null)
|
|
449
|
+
return unavailable("cgroup-v2-required", new Error("No unified control group hierarchy"));
|
|
450
|
+
return controlGroup.split("/").includes(unit) ? { state: "member", via: "cgroup" } : { state: "outside", observed: { cgroup: controlGroup } };
|
|
451
|
+
}
|
|
452
|
+
async function observeRoot(host, root) {
|
|
453
|
+
const observation = await host.observeInstance(root.pid);
|
|
454
|
+
if (observation.state === "observed")
|
|
455
|
+
return sameProcessInstance(observation.instance, root.instance) ? "same" : "reused";
|
|
456
|
+
return await host.liveness(root.pid) === "gone" ? "gone" : unavailable("root-unobservable", observation.cause);
|
|
457
|
+
}
|
|
458
|
+
async function rootMembership(host, pid, root) {
|
|
459
|
+
if (host.platform !== "linux" && host.platform !== "darwin")
|
|
460
|
+
return unavailable("platform-unsupported", new Error("A process root is read on Linux and macOS"));
|
|
461
|
+
const rootState = await observeRoot(host, root);
|
|
462
|
+
if (typeof rootState !== "string")
|
|
463
|
+
return rootState;
|
|
464
|
+
if (pid === root.pid) {
|
|
465
|
+
if (rootState === "gone")
|
|
466
|
+
return { state: "gone" };
|
|
467
|
+
return rootState === "same" ? { state: "member", via: "root" } : { state: "outside", observed: { pgid: pid, ancestors: [] } };
|
|
468
|
+
}
|
|
469
|
+
const ancestors = [];
|
|
470
|
+
try {
|
|
471
|
+
const own = await host.lineage(pid);
|
|
472
|
+
if (own === null)
|
|
473
|
+
return await host.liveness(pid) === "gone" ? { state: "gone" } : unavailable("process-table-failed", new Error(`Process ${pid} is hidden`));
|
|
474
|
+
if (rootState === "reused")
|
|
475
|
+
return { state: "outside", observed: { pgid: own.pgid, ancestors } };
|
|
476
|
+
if (own.pgid === root.pid)
|
|
477
|
+
return { state: "member", via: "process-group" };
|
|
478
|
+
if (rootState === "gone")
|
|
479
|
+
return { state: "outside", observed: { pgid: own.pgid, ancestors } };
|
|
480
|
+
let parent = own.ppid;
|
|
481
|
+
while (parent > 1 && ancestors.length < MAX_ANCESTORS) {
|
|
482
|
+
ancestors.push(parent);
|
|
483
|
+
if (parent === root.pid) {
|
|
484
|
+
const still = await observeRoot(host, root);
|
|
485
|
+
if (typeof still !== "string")
|
|
486
|
+
return still;
|
|
487
|
+
return still === "same" ? { state: "member", via: "ancestry" } : { state: "outside", observed: { pgid: own.pgid, ancestors } };
|
|
488
|
+
}
|
|
489
|
+
const next = await host.lineage(parent);
|
|
490
|
+
if (next === null)
|
|
491
|
+
break;
|
|
492
|
+
parent = next.ppid;
|
|
493
|
+
}
|
|
494
|
+
return { state: "outside", observed: { pgid: own.pgid, ancestors } };
|
|
495
|
+
} catch (cause) {
|
|
496
|
+
return unavailable("process-table-failed", cause);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
async function checkWorkMembershipWith(host, input) {
|
|
500
|
+
const { pid, boundary } = MembershipInputSchema.parse(input);
|
|
501
|
+
return boundary.kind === "transient-scope" ? scopeMembership(host, pid, boundary.unit) : rootMembership(host, pid, boundary.root);
|
|
502
|
+
}
|
|
503
|
+
function checkWorkMembership(input) {
|
|
504
|
+
return checkWorkMembershipWith(createDefaultWorkHost(), input);
|
|
505
|
+
}
|
|
506
|
+
async function inheritedWorkWith(host, pid) {
|
|
507
|
+
const origin = readWorkOrigin(host.env);
|
|
508
|
+
if (origin === null)
|
|
509
|
+
return null;
|
|
510
|
+
const membership = await checkWorkMembershipWith(host, { pid, boundary: origin.boundary });
|
|
511
|
+
if (membership.state === "member")
|
|
512
|
+
return origin.work;
|
|
513
|
+
if (membership.state === "unavailable")
|
|
514
|
+
throw new WorkLaunchError("membership-unavailable", `The inherited boundary could not be asked: ${membership.reason}`, { cause: membership.cause });
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
function inheritedWork() {
|
|
518
|
+
return inheritedWorkWith(createDefaultWorkHost(), process.pid);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/service-host/work/probe.ts
|
|
522
|
+
async function assertManagerReachable(host, manager) {
|
|
523
|
+
const env = await managerEnv(host, manager);
|
|
524
|
+
let result;
|
|
525
|
+
try {
|
|
526
|
+
result = await host.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(manager, ["show", "--no-pager", "--property=Version", "--value"]), { env });
|
|
527
|
+
} catch (cause) {
|
|
528
|
+
throw new WorkLaunchError("systemd-unavailable", `${SYSTEMCTL_PATH} could not run`, {
|
|
529
|
+
cause
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
if (result.exitCode !== 0) {
|
|
533
|
+
const reason = classifyManagerFailure(result.stderr, manager);
|
|
534
|
+
throw new WorkLaunchError(reason === "scope-refused" ? "manager-unreachable" : reason, `The ${manager} manager did not answer: ${result.stderr.trim()}`, { cause: result });
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async function probeWorkBoundaryWith(host, input) {
|
|
538
|
+
const placement = WorkPlacementSchema.parse(input);
|
|
539
|
+
try {
|
|
540
|
+
if (placement.kind === "process-root") {
|
|
541
|
+
if (host.platform !== "linux" && host.platform !== "darwin")
|
|
542
|
+
throw new WorkLaunchError("platform-unsupported", "A process root needs Linux or macOS");
|
|
543
|
+
if (!host.canReplaceProcess)
|
|
544
|
+
throw new WorkLaunchError("platform-unsupported", "A process root needs a runtime with process.execve");
|
|
545
|
+
const own = await host.observeInstance(process.pid);
|
|
546
|
+
if (own.state !== "observed")
|
|
547
|
+
throw new WorkLaunchError("root-unobservable", "This host cannot observe a process instance", { cause: own.cause });
|
|
548
|
+
return { state: "available" };
|
|
549
|
+
}
|
|
550
|
+
await assertSystemdRunVersion(host);
|
|
551
|
+
assertManagerAuthorized(host, placement.manager);
|
|
552
|
+
await assertManagerReachable(host, placement.manager);
|
|
553
|
+
if (placement.slice === "caller")
|
|
554
|
+
await resolveCallerSlice(host, placement.manager);
|
|
555
|
+
return { state: "available" };
|
|
556
|
+
} catch (error) {
|
|
557
|
+
if (error instanceof WorkLaunchError)
|
|
558
|
+
return { state: "unavailable", reason: error.reason, cause: error };
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function probeWorkBoundary(placement) {
|
|
563
|
+
return probeWorkBoundaryWith(createDefaultWorkHost(), placement);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// src/service-host/work/launch.ts
|
|
567
|
+
var SCOPE_ENTRY_TIMEOUT_MS = 1e4;
|
|
568
|
+
var SCOPE_ENTRY_POLL_MS = 10;
|
|
569
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
570
|
+
async function unitLoaded(host, unit) {
|
|
571
|
+
const result = await host.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(unit.manager, [
|
|
572
|
+
"show",
|
|
573
|
+
"--no-pager",
|
|
574
|
+
"--property=LoadState",
|
|
575
|
+
"--value",
|
|
576
|
+
"--",
|
|
577
|
+
unit.name
|
|
578
|
+
]), { env: await managerEnv(host, unit.manager) });
|
|
579
|
+
if (result.exitCode !== 0)
|
|
580
|
+
throw new WorkLaunchError(classifyManagerFailure(result.stderr, unit.manager), `The ${unit.manager} manager did not answer for ${unit.name}: ${result.stderr.trim()}`, { cause: result });
|
|
581
|
+
return result.stdout.trim() !== "not-found";
|
|
582
|
+
}
|
|
583
|
+
async function stopUnit(host, unit) {
|
|
584
|
+
const result = await host.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(unit.manager, ["stop", "--", unit.name]), { env: await managerEnv(host, unit.manager) });
|
|
585
|
+
if (result.exitCode !== 0 && !/not loaded\.?\s*$/.test(result.stderr))
|
|
586
|
+
throw new WorkLaunchError("stop-failed", `Could not stop ${unit.name}: ${result.stderr.trim()}`, { cause: result });
|
|
587
|
+
}
|
|
588
|
+
async function enteredScope(host, pid, boundary, ended) {
|
|
589
|
+
let over = false;
|
|
590
|
+
ended.then(() => {
|
|
591
|
+
over = true;
|
|
592
|
+
}, () => {
|
|
593
|
+
over = true;
|
|
594
|
+
});
|
|
595
|
+
const deadline = Date.now() + SCOPE_ENTRY_TIMEOUT_MS;
|
|
596
|
+
while (!over && Date.now() < deadline) {
|
|
597
|
+
const membership = await checkWorkMembershipWith(host, { pid, boundary });
|
|
598
|
+
if (membership.state === "member")
|
|
599
|
+
return true;
|
|
600
|
+
if (membership.state === "gone")
|
|
601
|
+
return false;
|
|
602
|
+
if (membership.state === "unavailable")
|
|
603
|
+
throw new WorkLaunchError("membership-unavailable", `The scope could not be asked for its root: ${membership.reason}`, { cause: membership.cause });
|
|
604
|
+
await sleep(SCOPE_ENTRY_POLL_MS);
|
|
605
|
+
}
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
async function launchWorkWith(host, input) {
|
|
609
|
+
const { executable, args, env, ...rest } = input.command;
|
|
610
|
+
const placed = await workCommandWith(host, {
|
|
611
|
+
owner: input.owner,
|
|
612
|
+
placement: input.placement,
|
|
613
|
+
executable,
|
|
614
|
+
args,
|
|
615
|
+
env: env ?? {}
|
|
616
|
+
});
|
|
617
|
+
if (placed.unit !== null) {
|
|
618
|
+
await assertManagerReachable(host, placed.unit.manager);
|
|
619
|
+
if (await unitLoaded(host, placed.unit))
|
|
620
|
+
throw new WorkLaunchError("unit-exists", `${placed.unit.name} is already loaded: the id is still in use on this machine`);
|
|
621
|
+
}
|
|
622
|
+
const started = Promise.withResolvers();
|
|
623
|
+
const command = startNativeCommand({
|
|
624
|
+
...rest,
|
|
625
|
+
executable: placed.executable,
|
|
626
|
+
args: placed.args,
|
|
627
|
+
env: placed.env,
|
|
628
|
+
group: "own",
|
|
629
|
+
onLeaderStarted: ({ pid }) => started.resolve({ pid, instance: readProcessInstanceSync(pid) })
|
|
630
|
+
});
|
|
631
|
+
const outcome = command.result.then((value) => ({ state: "fulfilled", value }), (reason) => ({ state: "rejected", reason }));
|
|
632
|
+
const stop = async () => {
|
|
633
|
+
if (placed.unit !== null)
|
|
634
|
+
await stopUnit(host, placed.unit);
|
|
635
|
+
await command.stop();
|
|
636
|
+
};
|
|
637
|
+
const refuse = async (message) => {
|
|
638
|
+
await stop();
|
|
639
|
+
throw new WorkLaunchError("root-unobserved", message, { cause: await outcome });
|
|
640
|
+
};
|
|
641
|
+
const first = await Promise.race([started.promise, outcome.then(() => null)]);
|
|
642
|
+
if (first === null)
|
|
643
|
+
return refuse("The command ended before its root was observed");
|
|
644
|
+
const { pid, instance } = first;
|
|
645
|
+
if (instance === null)
|
|
646
|
+
return refuse("The root ended before its process instance was read");
|
|
647
|
+
const boundary = placed.unit === null ? { kind: "process-root", root: { pid, instance } } : { kind: "transient-scope", manager: placed.unit.manager, unit: placed.unit.name };
|
|
648
|
+
if (placed.unit !== null && !await enteredScope(host, pid, boundary, command.result))
|
|
649
|
+
return refuse(`The command ended before it was seen inside ${placed.unit.name}`);
|
|
650
|
+
return {
|
|
651
|
+
origin: { v: 1, work: placed.work, boundary },
|
|
652
|
+
unit: placed.unit,
|
|
653
|
+
root: { pid, instance },
|
|
654
|
+
result: command.result,
|
|
655
|
+
stop
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function launchWork(input) {
|
|
659
|
+
return launchWorkWith(createDefaultWorkHost(), input);
|
|
660
|
+
}
|
|
661
|
+
export {
|
|
662
|
+
WORK_ORIGIN_ENV,
|
|
663
|
+
WorkAgentSchema,
|
|
664
|
+
WorkBoundarySchema,
|
|
665
|
+
WorkLaunchError,
|
|
666
|
+
WorkOriginSchema,
|
|
667
|
+
WorkOwnerSchema,
|
|
668
|
+
WorkRefSchema,
|
|
669
|
+
checkWorkMembership,
|
|
670
|
+
inheritedWork,
|
|
671
|
+
launchWork,
|
|
672
|
+
probeWorkBoundary,
|
|
673
|
+
readWorkOrigin,
|
|
674
|
+
workCommand,
|
|
675
|
+
workUnitName
|
|
676
|
+
};
|