owenloop 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/README.md +182 -53
- package/bin/owenloop.mjs +50 -2
- package/dist/packages/work/src/agent/brief.d.ts +176 -0
- package/dist/packages/work/src/agent/brief.js +197 -0
- package/dist/packages/work/src/agent/loop.d.ts +141 -0
- package/dist/packages/work/src/agent/loop.js +669 -0
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -0
- package/dist/packages/work/src/agent/workdir.d.ts +210 -0
- package/dist/packages/work/src/agent/workdir.js +319 -0
- package/dist/packages/work/src/bundle/cache.d.ts +92 -0
- package/dist/packages/work/src/bundle/cache.js +338 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
- package/dist/packages/work/src/bundle/fetch.js +345 -0
- package/dist/packages/work/src/bundle/types.d.ts +164 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
- package/dist/packages/work/src/credentials/owenloop.js +28 -0
- package/dist/packages/work/src/credentials/reader.d.ts +36 -0
- package/dist/packages/work/src/credentials/reader.js +32 -0
- package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
- package/dist/packages/work/src/credentials/resolve.js +56 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +40 -0
- package/dist/packages/work/src/exec/loop.js +332 -0
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +41 -0
- package/dist/packages/work/src/exec/receipt.js +32 -0
- package/dist/packages/work/src/exec/runner.d.ts +71 -0
- package/dist/packages/work/src/exec/runner.js +256 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +134 -0
- package/dist/packages/work/src/harness/claude.d.ts +140 -0
- package/dist/packages/work/src/harness/claude.js +837 -0
- package/dist/packages/work/src/harness/codex.d.ts +111 -0
- package/dist/packages/work/src/harness/codex.js +1024 -0
- package/dist/packages/work/src/harness/contract.d.ts +308 -0
- package/dist/packages/work/src/harness/contract.js +32 -0
- package/dist/packages/work/src/harness/fake.d.ts +59 -0
- package/dist/packages/work/src/harness/fake.js +91 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
- package/dist/packages/work/src/harness/permissions.d.ts +75 -0
- package/dist/packages/work/src/harness/permissions.js +182 -0
- package/dist/packages/work/src/harness/registry.d.ts +47 -0
- package/dist/packages/work/src/harness/registry.js +45 -0
- package/dist/packages/work/src/harness/session-store.d.ts +181 -0
- package/dist/packages/work/src/harness/session-store.js +523 -0
- package/dist/packages/work/src/harness/types.d.ts +29 -0
- package/dist/packages/work/src/harness/types.js +14 -0
- package/dist/packages/work/src/harnesses.d.ts +38 -0
- package/dist/packages/work/src/harnesses.js +38 -0
- package/dist/packages/work/src/hold/loop.d.ts +36 -0
- package/dist/packages/work/src/hold/loop.js +23 -0
- package/dist/packages/work/src/hold/mcp.d.ts +75 -0
- package/dist/packages/work/src/hold/mcp.js +264 -0
- package/dist/packages/work/src/hub/client.d.ts +23 -0
- package/dist/packages/work/src/hub/client.js +91 -0
- package/dist/packages/work/src/hub/types.d.ts +326 -0
- package/dist/packages/work/src/hub/types.js +26 -0
- package/dist/packages/work/src/lease/loop.d.ts +94 -0
- package/dist/packages/work/src/lease/loop.js +277 -0
- package/dist/packages/work/src/main.d.ts +1 -0
- package/dist/packages/work/src/main.js +48 -0
- package/dist/packages/work/src/mcp/server.d.ts +125 -0
- package/dist/packages/work/src/mcp/server.js +320 -0
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
- package/dist/packages/work/src/roles/agent-run.js +529 -0
- package/dist/packages/work/src/roles/exec.d.ts +48 -0
- package/dist/packages/work/src/roles/exec.js +228 -0
- package/dist/packages/work/src/roles/hold.d.ts +72 -0
- package/dist/packages/work/src/roles/hold.js +363 -0
- package/dist/packages/work/src/roles/join.d.ts +18 -0
- package/dist/packages/work/src/roles/join.js +204 -0
- package/dist/packages/work/src/roles/lint.d.ts +58 -0
- package/dist/packages/work/src/roles/lint.js +234 -0
- package/dist/packages/work/src/roles/prepare.d.ts +1 -0
- package/dist/packages/work/src/roles/prepare.js +249 -0
- package/dist/packages/work/src/roles/release.d.ts +48 -0
- package/dist/packages/work/src/roles/release.js +137 -0
- package/dist/packages/work/src/roles/sessions.d.ts +61 -0
- package/dist/packages/work/src/roles/sessions.js +180 -0
- package/dist/packages/work/src/roles/settings.d.ts +6 -0
- package/dist/packages/work/src/roles/settings.js +71 -0
- package/dist/packages/work/src/roles/shift.d.ts +13 -0
- package/dist/packages/work/src/roles/shift.js +250 -0
- package/dist/packages/work/src/roles/signals.d.ts +55 -0
- package/dist/packages/work/src/roles/signals.js +62 -0
- package/dist/packages/work/src/settings/provision.d.ts +21 -0
- package/dist/packages/work/src/settings/provision.js +47 -0
- package/dist/packages/work/src/settings/settings.d.ts +136 -0
- package/dist/packages/work/src/settings/settings.js +155 -0
- package/dist/packages/work/src/shift/client.d.ts +24 -0
- package/dist/packages/work/src/shift/client.js +124 -0
- package/dist/packages/work/src/shift/loop.d.ts +131 -0
- package/dist/packages/work/src/shift/loop.js +751 -0
- package/dist/packages/work/src/shift/protocol.d.ts +95 -0
- package/dist/packages/work/src/shift/protocol.js +24 -0
- package/dist/packages/work/src/shift/routing.d.ts +35 -0
- package/dist/packages/work/src/shift/routing.js +50 -0
- package/dist/packages/work/src/shift/runtime.d.ts +45 -0
- package/dist/packages/work/src/shift/runtime.js +337 -0
- package/dist/packages/work/src/shift/server.d.ts +23 -0
- package/dist/packages/work/src/shift/server.js +716 -0
- package/dist/packages/work/src/shift/spawn.d.ts +109 -0
- package/dist/packages/work/src/shift/spawn.js +158 -0
- package/dist/packages/work/src/shift/state.d.ts +79 -0
- package/dist/packages/work/src/shift/state.js +385 -0
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/src/add.d.ts +189 -0
- package/dist/src/add.js +300 -0
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
- package/dist/src/cli.js +5968 -0
- package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
- package/dist/{credentials.js → src/credentials.js} +35 -31
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
- package/dist/{defs.js → src/defs.js} +181 -61
- package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
- package/dist/{engine.js → src/engine.js} +251 -47
- package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
- package/dist/{factory.js → src/factory.js} +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
- package/dist/{hub.js → src/hub.js} +493 -52
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.js +41 -0
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +38 -0
- package/dist/src/lock.js +325 -0
- package/dist/src/mcp/serve.d.ts +109 -0
- package/dist/{mcp → src/mcp}/serve.js +335 -75
- package/dist/{mcp → src/mcp}/server.d.ts +6 -9
- package/dist/{mcp → src/mcp}/server.js +18 -10
- package/dist/{model.d.ts → src/model.d.ts} +15 -0
- package/dist/{model.js → src/model.js} +112 -2
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
- package/dist/{paths.js → src/paths.js} +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/{types.d.ts → src/types.d.ts} +58 -24
- package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
- package/dist/src/untar.js +38 -0
- package/dist/{util.d.ts → src/util.d.ts} +3 -2
- package/dist/{util.js → src/util.js} +3 -2
- package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
- package/dist/{owenwork.js → src/work-settings.js} +27 -27
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +150 -59
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1758 -163
- package/docs/crypto.md +816 -0
- package/docs/design.md +374 -52
- package/docs/embedding.md +135 -27
- package/docs/wire-contracts.md +380 -0
- package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
- package/examples/workflows/compile-dev-playbook.yaml +338 -0
- package/examples/workflows/judges/gate-sharpness.md +39 -0
- package/examples/workflows/judges/security.md +34 -0
- package/package.json +22 -8
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
- package/dist/add.d.ts +0 -384
- package/dist/add.js +0 -834
- package/dist/cli.js +0 -3270
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -23
- package/dist/lock.d.ts +0 -80
- package/dist/lock.js +0 -217
- package/dist/mcp/serve.d.ts +0 -84
- package/dist/untar.js +0 -164
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{store.d.ts → src/store.d.ts} +0 -0
- /package/dist/{store.js → src/store.js} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.wnlp` manifest (`bundle.yaml`) — strict fail-closed parsing, schema
|
|
3
|
+
* validation, cross-reference lock checks, integrity construction, and
|
|
4
|
+
* canonical YAML serialization (WP-A1, see `docs/bundles.md`).
|
|
5
|
+
*
|
|
6
|
+
* The manifest is package-only: it carries identity, platform selectors, a
|
|
7
|
+
* named workflow-to-path map, a per-file integrity map, REQUESTED capabilities
|
|
8
|
+
* (never granted here), and a digest-pinned `lock` map for explicit
|
|
9
|
+
* `namespace/name@version` call references. Execution fields (`worker`,
|
|
10
|
+
* `command`, interpreter, script…) are unknown keys and refused — workflow
|
|
11
|
+
* files remain the only execution surface.
|
|
12
|
+
*
|
|
13
|
+
* Parsing is fail-closed on the YAML AST: parse errors AND warnings refuse
|
|
14
|
+
* the document; aliases, merge keys, tags (custom or built-in), non-string
|
|
15
|
+
* map keys, and duplicate keys are all named refusals. Canonical
|
|
16
|
+
* serialization is deterministic: fixed key order, sorted map keys and list
|
|
17
|
+
* values (ascending UTF-8 bytes), every string double-quoted, two-space
|
|
18
|
+
* indent, one final newline.
|
|
19
|
+
*/
|
|
20
|
+
import { createHash } from 'node:crypto';
|
|
21
|
+
import { isAlias, isMap, isPair, isScalar, isSeq, parseDocument, } from 'yaml';
|
|
22
|
+
import { canonicalBundlePathViolation } from "../archive.js";
|
|
23
|
+
import { assertCurrentRuntimeCompatible, isCanonicalSemver } from "./runtime.js";
|
|
24
|
+
import { BundleError } from "./types.js";
|
|
25
|
+
/** Lowercase 64-hex SHA-256 of `bytes`. */
|
|
26
|
+
export function sha256Hex(bytes) {
|
|
27
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
28
|
+
}
|
|
29
|
+
const DIGEST_RE = /^[0-9a-f]{64}$/;
|
|
30
|
+
/** Portable package namespace. */
|
|
31
|
+
const PACKAGE_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
32
|
+
/** Workflow map keys: lowercase-start, lowercase alphanumeric and hyphen. */
|
|
33
|
+
export const WORKFLOW_NAME_RE = /^[a-z][a-z0-9-]*$/;
|
|
34
|
+
/** Version: printable ASCII, no separators that would break filenames or lock keys. */
|
|
35
|
+
const VERSION_RE = /^[!-~]{1,128}$/;
|
|
36
|
+
/** Versioned runtime feature identifier ending in a positive `.vN` version. */
|
|
37
|
+
const RUNTIME_FEATURE_RE = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*\.v[1-9][0-9]*$/;
|
|
38
|
+
/** Platform selector: `os-arch`-style identifier. */
|
|
39
|
+
const PLATFORM_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
40
|
+
/** Capability class identifier. */
|
|
41
|
+
const CAPABILITY_CLASS_RE = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/;
|
|
42
|
+
/** Explicit cross-bundle reference: `namespace/name@version`. */
|
|
43
|
+
const VERSIONED_REF_RE = /^([A-Za-z0-9._-]+)\/([A-Za-z0-9._-]+)@([!-~]+)$/;
|
|
44
|
+
/** True when `text` is the explicit `namespace/name@version` reference form. */
|
|
45
|
+
export function isVersionedReference(text) {
|
|
46
|
+
return VERSIONED_REF_RE.test(text);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Walk a yaml AST into plain JS values, fail-closed: refuses aliases, merge
|
|
50
|
+
* keys, any tag (custom `!x` or built-in `!!x`), and non-string map keys.
|
|
51
|
+
* Plain scalars keep their parsed type (string/number/boolean/null); quoted
|
|
52
|
+
* scalars are always strings.
|
|
53
|
+
*/
|
|
54
|
+
function astToPlain(node, ctx) {
|
|
55
|
+
if (node === null) {
|
|
56
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: empty value is not allowed`);
|
|
57
|
+
}
|
|
58
|
+
if (isPair(node)) {
|
|
59
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: unexpected key/value pair outside a mapping`);
|
|
60
|
+
}
|
|
61
|
+
if (isAlias(node)) {
|
|
62
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: YAML aliases are not allowed`);
|
|
63
|
+
}
|
|
64
|
+
const tag = node.tag;
|
|
65
|
+
if (tag !== undefined && tag !== null) {
|
|
66
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: tagged YAML nodes are not allowed`);
|
|
67
|
+
}
|
|
68
|
+
if (isMap(node)) {
|
|
69
|
+
const out = Object.create(null);
|
|
70
|
+
for (const item of node.items) {
|
|
71
|
+
const keyNode = item.key;
|
|
72
|
+
if (isAlias(keyNode)) {
|
|
73
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: YAML aliases are not allowed`);
|
|
74
|
+
}
|
|
75
|
+
if (!isScalar(keyNode) || typeof keyNode.value !== 'string') {
|
|
76
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: mapping keys must be strings`);
|
|
77
|
+
}
|
|
78
|
+
const key = keyNode.value;
|
|
79
|
+
if (key === '<<') {
|
|
80
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: YAML merge keys are not allowed`);
|
|
81
|
+
}
|
|
82
|
+
out[key] = astToPlain(item.value, `${ctx}.${key}`);
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
if (isSeq(node)) {
|
|
87
|
+
return node.items.map((item, i) => astToPlain(item, `${ctx}[${i}]`));
|
|
88
|
+
}
|
|
89
|
+
if (isScalar(node)) {
|
|
90
|
+
if (node.tag !== undefined && node.tag !== null) {
|
|
91
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: tagged scalar '${node.tag}' is not allowed`);
|
|
92
|
+
}
|
|
93
|
+
return node.value;
|
|
94
|
+
}
|
|
95
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: unsupported YAML node`);
|
|
96
|
+
}
|
|
97
|
+
function asString(value, ctx) {
|
|
98
|
+
if (typeof value !== 'string') {
|
|
99
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: must be a string`);
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
function asMap(value, ctx) {
|
|
104
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
105
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: must be a mapping`);
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
function assertExactKeys(obj, keys, ctx, optionalKeys = []) {
|
|
110
|
+
const allowed = new Set([...keys, ...optionalKeys]);
|
|
111
|
+
for (const k of Object.keys(obj)) {
|
|
112
|
+
if (!allowed.has(k)) {
|
|
113
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: unknown key '${k}'`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (const k of keys) {
|
|
117
|
+
if (!(k in obj)) {
|
|
118
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: missing required key '${k}'`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Assert a string list is duplicate-free; returns it. */
|
|
123
|
+
function assertDuplicateFree(values, ctx) {
|
|
124
|
+
const seen = new Set();
|
|
125
|
+
for (const v of values) {
|
|
126
|
+
if (seen.has(v)) {
|
|
127
|
+
throw new BundleError('MANIFEST_ERROR', `${ctx}: duplicate value '${v}'`);
|
|
128
|
+
}
|
|
129
|
+
seen.add(v);
|
|
130
|
+
}
|
|
131
|
+
return values;
|
|
132
|
+
}
|
|
133
|
+
const sortedByUtf8 = (values) => [...values].sort((a, b) => Buffer.compare(Buffer.from(a, 'utf8'), Buffer.from(b, 'utf8')));
|
|
134
|
+
/**
|
|
135
|
+
* Parse and validate `.wnlp` manifest bytes, fail-closed. Refuses non-UTF-8
|
|
136
|
+
* input, a missing (or double) final newline, any YAML parse error or
|
|
137
|
+
* warning, and every shape violation. Returns the validated manifest; the
|
|
138
|
+
* source byte order of collections is NOT enforced here — canonicality is a
|
|
139
|
+
* separate concern ({@link manifestIsCanonical}).
|
|
140
|
+
*/
|
|
141
|
+
export function parseManifestBytes(bytes) {
|
|
142
|
+
let text;
|
|
143
|
+
try {
|
|
144
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml: not valid UTF-8');
|
|
148
|
+
}
|
|
149
|
+
if (!text.endsWith('\n')) {
|
|
150
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml: must end with exactly one final newline');
|
|
151
|
+
}
|
|
152
|
+
if (text.endsWith('\n\n')) {
|
|
153
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml: must end with exactly one final newline');
|
|
154
|
+
}
|
|
155
|
+
const doc = parseDocument(text);
|
|
156
|
+
if (doc.errors.length > 0) {
|
|
157
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml: YAML parse error: ${doc.errors[0].message.split('\n')[0]}`);
|
|
158
|
+
}
|
|
159
|
+
if (doc.warnings.length > 0) {
|
|
160
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml: YAML rejected: ${doc.warnings[0].message.split('\n')[0]}`);
|
|
161
|
+
}
|
|
162
|
+
const plain = astToPlain(doc.contents, 'bundle.yaml');
|
|
163
|
+
const root = asMap(plain, 'bundle.yaml');
|
|
164
|
+
assertExactKeys(root, ['formatVersion', 'package', 'workflows', 'platforms', 'integrity', 'capabilities', 'lock'], 'bundle.yaml', ['runtime', 'default']);
|
|
165
|
+
// formatVersion — refuse future versions rather than guess.
|
|
166
|
+
const formatVersion = root['formatVersion'];
|
|
167
|
+
if (typeof formatVersion !== 'number' || !Number.isInteger(formatVersion)) {
|
|
168
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml.formatVersion: must be an integer');
|
|
169
|
+
}
|
|
170
|
+
if (formatVersion !== 2) {
|
|
171
|
+
throw new BundleError('UNSUPPORTED_FORMAT_VERSION', `bundle.yaml.formatVersion: unsupported format version ${formatVersion} (this reader supports 2)`);
|
|
172
|
+
}
|
|
173
|
+
// package identity.
|
|
174
|
+
const pkg = asMap(root['package'], 'bundle.yaml.package');
|
|
175
|
+
assertExactKeys(pkg, ['name', 'version'], 'bundle.yaml.package');
|
|
176
|
+
const name = asString(pkg['name'], 'bundle.yaml.package.name');
|
|
177
|
+
if (!PACKAGE_NAME_RE.test(name)) {
|
|
178
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.package.name: '${name}' must be 1-128 chars of letters, digits, '-', '_' (starting alphanumeric)`);
|
|
179
|
+
}
|
|
180
|
+
const version = asString(pkg['version'], 'bundle.yaml.package.version');
|
|
181
|
+
if (!VERSION_RE.test(version) || version.includes('/') || version.includes('\\')) {
|
|
182
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.package.version: '${version}' must be 1-128 printable ASCII chars with no '/' or '\\'`);
|
|
183
|
+
}
|
|
184
|
+
// runtime — an optional closed compatibility declaration. Shape errors are
|
|
185
|
+
// MANIFEST_ERROR; a well-formed declaration unsupported by this process is
|
|
186
|
+
// RUNTIME_INCOMPATIBLE. Evaluate before workflow fields are consumed so all
|
|
187
|
+
// admission paths refuse an incompatible bundle before loading definitions.
|
|
188
|
+
let runtime;
|
|
189
|
+
if (Object.prototype.hasOwnProperty.call(root, 'runtime')) {
|
|
190
|
+
const runtimeRaw = asMap(root['runtime'], 'bundle.yaml.runtime');
|
|
191
|
+
assertExactKeys(runtimeRaw, [], 'bundle.yaml.runtime', ['minVersion', 'features']);
|
|
192
|
+
if (!Object.prototype.hasOwnProperty.call(runtimeRaw, 'minVersion') &&
|
|
193
|
+
!Object.prototype.hasOwnProperty.call(runtimeRaw, 'features')) {
|
|
194
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml.runtime: must declare minVersion, features, or both');
|
|
195
|
+
}
|
|
196
|
+
let minVersion;
|
|
197
|
+
if (Object.prototype.hasOwnProperty.call(runtimeRaw, 'minVersion')) {
|
|
198
|
+
minVersion = asString(runtimeRaw['minVersion'], 'bundle.yaml.runtime.minVersion');
|
|
199
|
+
if (!isCanonicalSemver(minVersion)) {
|
|
200
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.runtime.minVersion: '${minVersion}' must be one canonical strict SemVer value with no range, prefix, or whitespace`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
let features;
|
|
204
|
+
if (Object.prototype.hasOwnProperty.call(runtimeRaw, 'features')) {
|
|
205
|
+
const featuresRaw = runtimeRaw['features'];
|
|
206
|
+
if (!Array.isArray(featuresRaw)) {
|
|
207
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml.runtime.features: must be a list');
|
|
208
|
+
}
|
|
209
|
+
if (featuresRaw.length === 0) {
|
|
210
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml.runtime.features: must contain at least one feature');
|
|
211
|
+
}
|
|
212
|
+
features = assertDuplicateFree(featuresRaw.map((feature, i) => asString(feature, `bundle.yaml.runtime.features[${i}]`)), 'bundle.yaml.runtime.features');
|
|
213
|
+
for (const feature of features) {
|
|
214
|
+
if (!RUNTIME_FEATURE_RE.test(feature) || Buffer.byteLength(feature, 'utf8') > 128) {
|
|
215
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.runtime.features: feature '${feature}' must be a lowercase versioned identifier ending in '.vN' (maximum 128 UTF-8 bytes)`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
runtime = {
|
|
220
|
+
...(minVersion === undefined ? {} : { minVersion }),
|
|
221
|
+
...(features === undefined ? {} : { features }),
|
|
222
|
+
};
|
|
223
|
+
assertCurrentRuntimeCompatible(runtime);
|
|
224
|
+
}
|
|
225
|
+
// workflows — at least one named, archive-relative definition path.
|
|
226
|
+
const workflowsRaw = asMap(root['workflows'], 'bundle.yaml.workflows');
|
|
227
|
+
const workflowEntries = Object.entries(workflowsRaw);
|
|
228
|
+
if (workflowEntries.length === 0) {
|
|
229
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml.workflows: must contain at least one workflow');
|
|
230
|
+
}
|
|
231
|
+
const workflows = Object.create(null);
|
|
232
|
+
const workflowPaths = new Set();
|
|
233
|
+
for (const [workflowName, workflowPathRaw] of workflowEntries) {
|
|
234
|
+
if (!WORKFLOW_NAME_RE.test(workflowName)) {
|
|
235
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.workflows: name '${workflowName}' must match /^[a-z][a-z0-9-]*$/`);
|
|
236
|
+
}
|
|
237
|
+
const workflowPath = asString(workflowPathRaw, `bundle.yaml.workflows['${workflowName}']`);
|
|
238
|
+
const violation = canonicalBundlePathViolation(workflowPath);
|
|
239
|
+
if (violation) {
|
|
240
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.workflows['${workflowName}']: unsafe path '${workflowPath}': ${violation}`, workflowPath);
|
|
241
|
+
}
|
|
242
|
+
if (workflowPaths.has(workflowPath)) {
|
|
243
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.workflows: duplicate path '${workflowPath}'`, workflowPath);
|
|
244
|
+
}
|
|
245
|
+
workflowPaths.add(workflowPath);
|
|
246
|
+
workflows[workflowName] = workflowPath;
|
|
247
|
+
}
|
|
248
|
+
let defaultWorkflow;
|
|
249
|
+
if (Object.prototype.hasOwnProperty.call(root, 'default')) {
|
|
250
|
+
defaultWorkflow = asString(root['default'], 'bundle.yaml.default');
|
|
251
|
+
if (!Object.prototype.hasOwnProperty.call(workflows, defaultWorkflow)) {
|
|
252
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.default: '${defaultWorkflow}' is not a workflow name`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// platforms — duplicate-free string selectors.
|
|
256
|
+
const platformsRaw = root['platforms'];
|
|
257
|
+
if (!Array.isArray(platformsRaw)) {
|
|
258
|
+
throw new BundleError('MANIFEST_ERROR', 'bundle.yaml.platforms: must be a list');
|
|
259
|
+
}
|
|
260
|
+
const platforms = assertDuplicateFree(platformsRaw.map((p, i) => asString(p, `bundle.yaml.platforms[${i}]`)), 'bundle.yaml.platforms');
|
|
261
|
+
for (const p of platforms) {
|
|
262
|
+
if (!PLATFORM_RE.test(p)) {
|
|
263
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.platforms: selector '${p}' must be 1-128 chars of letters, digits, '.', '_', '-' (starting alphanumeric)`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// integrity — algorithm fixed; per-file digests validated here and the
|
|
267
|
+
// exact coverage is cross-checked against archive entries by the caller.
|
|
268
|
+
const integrity = asMap(root['integrity'], 'bundle.yaml.integrity');
|
|
269
|
+
assertExactKeys(integrity, ['algorithm', 'files'], 'bundle.yaml.integrity');
|
|
270
|
+
if (integrity['algorithm'] !== 'sha256') {
|
|
271
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.integrity.algorithm: must be 'sha256' (got '${String(integrity['algorithm'])}')`);
|
|
272
|
+
}
|
|
273
|
+
const files = Object.create(null);
|
|
274
|
+
for (const [path, digest] of Object.entries(asMap(integrity['files'], 'bundle.yaml.integrity.files'))) {
|
|
275
|
+
const violation = canonicalBundlePathViolation(path);
|
|
276
|
+
if (violation) {
|
|
277
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.integrity.files: unsafe path '${path}': ${violation}`, path);
|
|
278
|
+
}
|
|
279
|
+
if (path === 'bundle.yaml') {
|
|
280
|
+
throw new BundleError('MANIFEST_ERROR', "bundle.yaml.integrity.files: must not list 'bundle.yaml' (recursive self-hash)");
|
|
281
|
+
}
|
|
282
|
+
const d = asString(digest, `bundle.yaml.integrity.files['${path}']`);
|
|
283
|
+
if (!DIGEST_RE.test(d)) {
|
|
284
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.integrity.files['${path}']: digest must be lowercase 64-hex SHA-256`);
|
|
285
|
+
}
|
|
286
|
+
files[path] = d;
|
|
287
|
+
}
|
|
288
|
+
// capabilities — requested classes → requested values (requests only).
|
|
289
|
+
const capabilities = Object.create(null);
|
|
290
|
+
for (const [cls, values] of Object.entries(asMap(root['capabilities'], 'bundle.yaml.capabilities'))) {
|
|
291
|
+
if (!CAPABILITY_CLASS_RE.test(cls)) {
|
|
292
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.capabilities: class '${cls}' must be 1-128 chars of letters, digits, '.', '_', '-' (starting with a letter)`);
|
|
293
|
+
}
|
|
294
|
+
if (!Array.isArray(values)) {
|
|
295
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.capabilities['${cls}']: must be a list`);
|
|
296
|
+
}
|
|
297
|
+
const vals = assertDuplicateFree(values.map((v, i) => asString(v, `bundle.yaml.capabilities['${cls}'][${i}]`)), `bundle.yaml.capabilities['${cls}']`);
|
|
298
|
+
for (const v of vals) {
|
|
299
|
+
const hasControl = [...v].some((ch) => {
|
|
300
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
301
|
+
return code === 0 || code < 0x20 || code === 0x7f;
|
|
302
|
+
});
|
|
303
|
+
if (v === '' || hasControl || v.length > 1024) {
|
|
304
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.capabilities['${cls}']: value '${v}' must be a non-empty printable string (<= 1024 chars)`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
capabilities[cls] = vals;
|
|
308
|
+
}
|
|
309
|
+
// lock — explicit versioned reference text → def digest.
|
|
310
|
+
const lock = Object.create(null);
|
|
311
|
+
for (const [ref, digestRaw] of Object.entries(asMap(root['lock'], 'bundle.yaml.lock'))) {
|
|
312
|
+
if (!isVersionedReference(ref)) {
|
|
313
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.lock: key '${ref}' must be an explicit 'namespace/name@version' reference`);
|
|
314
|
+
}
|
|
315
|
+
const digest = asString(digestRaw, `bundle.yaml.lock['${ref}']`);
|
|
316
|
+
if (!DIGEST_RE.test(digest)) {
|
|
317
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.lock['${ref}']: digest must be lowercase 64-hex SHA-256`);
|
|
318
|
+
}
|
|
319
|
+
lock[ref] = digest;
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
formatVersion: 2,
|
|
323
|
+
package: { name, version },
|
|
324
|
+
...(runtime === undefined ? {} : { runtime }),
|
|
325
|
+
workflows,
|
|
326
|
+
...(defaultWorkflow === undefined ? {} : { default: defaultWorkflow }),
|
|
327
|
+
platforms,
|
|
328
|
+
integrity: { algorithm: 'sha256', files },
|
|
329
|
+
capabilities,
|
|
330
|
+
lock,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
/** Double-quote a string for canonical YAML output (JSON escaping is valid YAML). */
|
|
334
|
+
const q = (s) => JSON.stringify(s);
|
|
335
|
+
/**
|
|
336
|
+
* Serialize a manifest to its canonical bytes: fixed top-level key order,
|
|
337
|
+
* map keys and list values sorted by ascending UTF-8 bytes, every string
|
|
338
|
+
* double-quoted, two-space indent, one final newline. Deterministic across
|
|
339
|
+
* platforms — the checked-in golden vector freezes the result.
|
|
340
|
+
*/
|
|
341
|
+
export function manifestToBytes(manifest) {
|
|
342
|
+
const lines = [];
|
|
343
|
+
lines.push(`formatVersion: ${manifest.formatVersion}`);
|
|
344
|
+
lines.push('package:');
|
|
345
|
+
lines.push(` name: ${q(manifest.package.name)}`);
|
|
346
|
+
lines.push(` version: ${q(manifest.package.version)}`);
|
|
347
|
+
if (manifest.runtime !== undefined) {
|
|
348
|
+
lines.push('runtime:');
|
|
349
|
+
if (manifest.runtime.minVersion !== undefined) {
|
|
350
|
+
lines.push(` minVersion: ${q(manifest.runtime.minVersion)}`);
|
|
351
|
+
}
|
|
352
|
+
if (manifest.runtime.features !== undefined) {
|
|
353
|
+
lines.push(' features:');
|
|
354
|
+
for (const feature of sortedByUtf8(manifest.runtime.features)) {
|
|
355
|
+
lines.push(` - ${q(feature)}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const workflowKeys = sortedByUtf8(Object.keys(manifest.workflows));
|
|
360
|
+
lines.push('workflows:');
|
|
361
|
+
for (const workflowName of workflowKeys) {
|
|
362
|
+
lines.push(` ${q(workflowName)}: ${q(manifest.workflows[workflowName])}`);
|
|
363
|
+
}
|
|
364
|
+
if (manifest.default !== undefined)
|
|
365
|
+
lines.push(`default: ${q(manifest.default)}`);
|
|
366
|
+
const platforms = sortedByUtf8(manifest.platforms);
|
|
367
|
+
if (platforms.length === 0) {
|
|
368
|
+
lines.push('platforms: []');
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
lines.push('platforms:');
|
|
372
|
+
for (const p of platforms)
|
|
373
|
+
lines.push(` - ${q(p)}`);
|
|
374
|
+
}
|
|
375
|
+
lines.push('integrity:');
|
|
376
|
+
lines.push(' algorithm: "sha256"');
|
|
377
|
+
const fileKeys = sortedByUtf8(Object.keys(manifest.integrity.files));
|
|
378
|
+
if (fileKeys.length === 0) {
|
|
379
|
+
lines.push(' files: {}');
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
lines.push(' files:');
|
|
383
|
+
for (const k of fileKeys)
|
|
384
|
+
lines.push(` ${q(k)}: ${q(manifest.integrity.files[k])}`);
|
|
385
|
+
}
|
|
386
|
+
const capKeys = sortedByUtf8(Object.keys(manifest.capabilities));
|
|
387
|
+
if (capKeys.length === 0) {
|
|
388
|
+
lines.push('capabilities: {}');
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
lines.push('capabilities:');
|
|
392
|
+
for (const cls of capKeys) {
|
|
393
|
+
const vals = sortedByUtf8(manifest.capabilities[cls]);
|
|
394
|
+
if (vals.length === 0) {
|
|
395
|
+
lines.push(` ${q(cls)}: []`);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
lines.push(` ${q(cls)}:`);
|
|
399
|
+
for (const v of vals)
|
|
400
|
+
lines.push(` - ${q(v)}`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const lockKeys = sortedByUtf8(Object.keys(manifest.lock));
|
|
405
|
+
if (lockKeys.length === 0) {
|
|
406
|
+
lines.push('lock: {}');
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
lines.push('lock:');
|
|
410
|
+
for (const k of lockKeys)
|
|
411
|
+
lines.push(` ${q(k)}: ${q(manifest.lock[k])}`);
|
|
412
|
+
}
|
|
413
|
+
return Buffer.from(`${lines.join('\n')}\n`, 'utf8');
|
|
414
|
+
}
|
|
415
|
+
/** True when `bytes` is exactly the canonical serialization of the manifest it parses to. */
|
|
416
|
+
export function manifestIsCanonical(bytes) {
|
|
417
|
+
const manifest = parseManifestBytes(bytes);
|
|
418
|
+
const canonical = manifestToBytes(manifest);
|
|
419
|
+
return Buffer.compare(Buffer.from(bytes), Buffer.from(canonical)) === 0;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Cross-reference check: every `calls:` target in `callsTargets` that uses
|
|
423
|
+
* the explicit `namespace/name@version` form must carry a `lock` entry. Bare
|
|
424
|
+
* (same-package) calls stay governed by the existing def grammar and need no
|
|
425
|
+
* lock. A1 does not resolve or fetch locks — it only validates coverage.
|
|
426
|
+
*/
|
|
427
|
+
export function assertLockCoverage(manifest, callsTargets) {
|
|
428
|
+
for (const target of callsTargets) {
|
|
429
|
+
if (!isVersionedReference(target))
|
|
430
|
+
continue;
|
|
431
|
+
if (!Object.prototype.hasOwnProperty.call(manifest.lock, target)) {
|
|
432
|
+
throw new BundleError('MANIFEST_ERROR', `bundle.yaml.lock: calls: target '${target}' uses the explicit 'namespace/name@version' form and requires a lock entry`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BundleRuntimeRequirements } from './types.ts';
|
|
2
|
+
/** Runtime features implemented by this Owenloop release. */
|
|
3
|
+
export declare const SUPPORTED_RUNTIME_FEATURES: readonly ["harness-policy-enforcement.v1", "native-judge-policy-inheritance.v1"];
|
|
4
|
+
export interface RuntimeCompatibilityEnvironment {
|
|
5
|
+
/** The running Owenloop package version. `0.0.0` is the unavailable-version sentinel. */
|
|
6
|
+
version: string;
|
|
7
|
+
/** Runtime feature identifiers implemented by the running Owenloop process. */
|
|
8
|
+
features: ReadonlySet<string>;
|
|
9
|
+
}
|
|
10
|
+
export interface RuntimeCompatibilityResult {
|
|
11
|
+
compatible: boolean;
|
|
12
|
+
runningVersion: string;
|
|
13
|
+
versionSatisfied: boolean;
|
|
14
|
+
unsupportedFeatures: string[];
|
|
15
|
+
diagnostics: string[];
|
|
16
|
+
}
|
|
17
|
+
/** True only for one canonical strict SemVer value, with no prefix, range, or whitespace. */
|
|
18
|
+
export declare function isCanonicalSemver(value: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Evaluate already-validated requirements against an injected runtime. Version
|
|
21
|
+
* and feature requirements use AND semantics: every declared condition must
|
|
22
|
+
* be satisfied.
|
|
23
|
+
*/
|
|
24
|
+
export declare function evaluateRuntimeCompatibility(requirements: BundleRuntimeRequirements, environment: RuntimeCompatibilityEnvironment): RuntimeCompatibilityResult;
|
|
25
|
+
/** Evaluate requirements against the production package version and advertised features. */
|
|
26
|
+
export declare function assertCurrentRuntimeCompatible(requirements: BundleRuntimeRequirements): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { packageVersion } from "../package-version.js";
|
|
3
|
+
import { BundleError } from "./types.js";
|
|
4
|
+
const semver = createRequire(import.meta.url)('semver');
|
|
5
|
+
/** Runtime features implemented by this Owenloop release. */
|
|
6
|
+
export const SUPPORTED_RUNTIME_FEATURES = Object.freeze([
|
|
7
|
+
'harness-policy-enforcement.v1',
|
|
8
|
+
'native-judge-policy-inheritance.v1',
|
|
9
|
+
]);
|
|
10
|
+
/** True only for one canonical strict SemVer value, with no prefix, range, or whitespace. */
|
|
11
|
+
export function isCanonicalSemver(value) {
|
|
12
|
+
try {
|
|
13
|
+
const parsed = new semver.SemVer(value);
|
|
14
|
+
const canonical = parsed.build.length === 0
|
|
15
|
+
? parsed.version
|
|
16
|
+
: `${parsed.version}+${parsed.build.join('.')}`;
|
|
17
|
+
return canonical === value;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Evaluate already-validated requirements against an injected runtime. Version
|
|
25
|
+
* and feature requirements use AND semantics: every declared condition must
|
|
26
|
+
* be satisfied.
|
|
27
|
+
*/
|
|
28
|
+
export function evaluateRuntimeCompatibility(requirements, environment) {
|
|
29
|
+
const diagnostics = [];
|
|
30
|
+
let versionSatisfied = true;
|
|
31
|
+
if (requirements.minVersion !== undefined) {
|
|
32
|
+
if (environment.version === '0.0.0' || !isCanonicalSemver(environment.version)) {
|
|
33
|
+
versionSatisfied = false;
|
|
34
|
+
diagnostics.push(`bundle requires Owenloop >= ${requirements.minVersion}, but the running package version is unavailable (${environment.version}); install or upgrade Owenloop and retry`);
|
|
35
|
+
}
|
|
36
|
+
else if (!semver.gte(environment.version, requirements.minVersion)) {
|
|
37
|
+
versionSatisfied = false;
|
|
38
|
+
diagnostics.push(`bundle requires Owenloop >= ${requirements.minVersion}, but the running version is ${environment.version}; install or upgrade Owenloop and retry`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const unsupportedFeatures = (requirements.features ?? [])
|
|
42
|
+
.filter((feature) => !environment.features.has(feature))
|
|
43
|
+
.sort((a, b) => Buffer.compare(Buffer.from(a, 'utf8'), Buffer.from(b, 'utf8')));
|
|
44
|
+
if (unsupportedFeatures.length > 0) {
|
|
45
|
+
diagnostics.push(`bundle requires unsupported Owenloop runtime feature${unsupportedFeatures.length === 1 ? '' : 's'}: ${unsupportedFeatures.join(', ')}; install or upgrade Owenloop and retry`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
compatible: versionSatisfied && unsupportedFeatures.length === 0,
|
|
49
|
+
runningVersion: environment.version,
|
|
50
|
+
versionSatisfied,
|
|
51
|
+
unsupportedFeatures,
|
|
52
|
+
diagnostics,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Evaluate requirements against the production package version and advertised features. */
|
|
56
|
+
export function assertCurrentRuntimeCompatible(requirements) {
|
|
57
|
+
const result = evaluateRuntimeCompatibility(requirements, {
|
|
58
|
+
version: packageVersion(),
|
|
59
|
+
features: new Set(SUPPORTED_RUNTIME_FEATURES),
|
|
60
|
+
});
|
|
61
|
+
if (!result.compatible) {
|
|
62
|
+
throw new BundleError('RUNTIME_INCOMPATIBLE', `bundle.yaml.runtime: incompatible with this Owenloop runtime: ${result.diagnostics.join('; ')}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic `.wnlp` archive writer (WP-A1).
|
|
3
|
+
*
|
|
4
|
+
* Canonical tar rules (see `docs/bundles.md`): regular-file entries only,
|
|
5
|
+
* `/`-separated paths sorted by ascending UTF-8 bytes, uid/gid 0, empty
|
|
6
|
+
* uname/gname, mtime 0, mode 0755 when any source execute bit is set and
|
|
7
|
+
* 0644 otherwise, USTAR name when it fits (UTF-8 bytes ≤ 100), else ONE
|
|
8
|
+
* deterministic POSIX PAX `path` extended record in a `PaxHeader` block
|
|
9
|
+
* (mode 0644, uid/gid 0, mtime 0), exactly two trailing zero blocks. The
|
|
10
|
+
* gzip wrapper uses fixed options, zero mtime bytes, and OS byte 0 (patched
|
|
11
|
+
* explicitly — Node reports OS 19 on Darwin). The raw header helpers are
|
|
12
|
+
* deliberately module-private: the public bundle surface exposes only the
|
|
13
|
+
* high-level pack/inspect/digest/unpack API.
|
|
14
|
+
*/
|
|
15
|
+
import type { Dirent } from 'node:fs';
|
|
16
|
+
import type { TarLimits } from '../archive.ts';
|
|
17
|
+
/** One file to archive: archive path (already validated + sorted), bytes, canonical mode. */
|
|
18
|
+
export interface CanonicalFile {
|
|
19
|
+
path: string;
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
/** 0o644 or 0o755. */
|
|
22
|
+
mode: number;
|
|
23
|
+
}
|
|
24
|
+
/** Fixed gzip level for canonical output. */
|
|
25
|
+
export declare const BUNDLE_GZIP_LEVEL = 9;
|
|
26
|
+
/**
|
|
27
|
+
* Build the canonical uncompressed tar bytes for a set of files. The input
|
|
28
|
+
* MUST already be sorted by ascending UTF-8 byte order of `path` and carry
|
|
29
|
+
* canonical modes; the bundle packer guarantees both.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildCanonicalTar(files: CanonicalFile[], limits?: TarLimits): Buffer;
|
|
32
|
+
/**
|
|
33
|
+
* Gzip `tar` with fixed options and a normalized header: no FEXTRA/FNAME/
|
|
34
|
+
* FCOMMENT, mtime bytes zeroed, OS byte forced to 0. Node's zlib reports
|
|
35
|
+
* OS 19 on Darwin and embeds the clock in mtime by default — patch both so
|
|
36
|
+
* the output is byte-identical across platforms and times.
|
|
37
|
+
*/
|
|
38
|
+
export declare function gzipDeterministic(tar: Uint8Array): Buffer;
|
|
39
|
+
/** A file collected from a bundle source tree. */
|
|
40
|
+
export interface SourceFile {
|
|
41
|
+
/** Archive-relative path with `/` separators (validated, sorted by callers). */
|
|
42
|
+
rel: string;
|
|
43
|
+
abs: string;
|
|
44
|
+
/** True when any execute bit was set on the source file. */
|
|
45
|
+
executable: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Compare archive paths by ascending UTF-8 bytes, as required by canonical packing. */
|
|
48
|
+
export declare function compareUtf8Paths(a: string, b: string): number;
|
|
49
|
+
/**
|
|
50
|
+
* Recursively walk `sourceRoot` WITHOUT following symlinks and collect every
|
|
51
|
+
* regular file. Refuses: a missing/non-directory/symlinked root; any symlink,
|
|
52
|
+
* or any non-regular/non-directory node, found below it; any path that
|
|
53
|
+
* violates the shared archive path policy. Returns files sorted by ascending
|
|
54
|
+
* UTF-8 byte order of their archive path.
|
|
55
|
+
*/
|
|
56
|
+
export interface CollectSourceFilesOptions {
|
|
57
|
+
/** Optional directory-entry source used by tests to control filesystem order. */
|
|
58
|
+
readDir?: (directory: string) => Dirent[];
|
|
59
|
+
/** Optional visit trace used by tests to assert sorted recursive traversal. */
|
|
60
|
+
onVisit?: (relativePath: string) => void;
|
|
61
|
+
}
|
|
62
|
+
export declare function collectSourceFiles(sourceRoot: string, limits?: TarLimits, options?: CollectSourceFilesOptions): SourceFile[];
|