owenloop 0.5.0 → 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.
Files changed (211) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +137 -35
  3. package/bin/owenloop.mjs +49 -1
  4. package/dist/packages/work/src/agent/brief.d.ts +8 -4
  5. package/dist/packages/work/src/agent/brief.js +7 -3
  6. package/dist/packages/work/src/agent/loop.d.ts +13 -7
  7. package/dist/packages/work/src/agent/loop.js +136 -9
  8. package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
  9. package/dist/packages/work/src/agent/model-policy.js +138 -0
  10. package/dist/packages/work/src/bundle/cache.d.ts +7 -5
  11. package/dist/packages/work/src/bundle/cache.js +20 -6
  12. package/dist/packages/work/src/bundle/fetch.d.ts +7 -5
  13. package/dist/packages/work/src/bundle/fetch.js +27 -7
  14. package/dist/packages/work/src/bundle/types.d.ts +8 -4
  15. package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
  16. package/dist/packages/work/src/consumed-verifier.js +205 -0
  17. package/dist/packages/work/src/exec/instructions.d.ts +99 -0
  18. package/dist/packages/work/src/exec/instructions.js +323 -0
  19. package/dist/packages/work/src/exec/loop.d.ts +12 -1
  20. package/dist/packages/work/src/exec/loop.js +137 -20
  21. package/dist/packages/work/src/exec/payload.d.ts +29 -0
  22. package/dist/packages/work/src/exec/payload.js +54 -0
  23. package/dist/packages/work/src/exec/receipt.d.ts +9 -6
  24. package/dist/packages/work/src/exec/receipt.js +12 -1
  25. package/dist/packages/work/src/exec/runner.d.ts +7 -1
  26. package/dist/packages/work/src/exec/runner.js +74 -3
  27. package/dist/packages/work/src/harness/child-env.js +7 -0
  28. package/dist/packages/work/src/harness/claude.d.ts +20 -8
  29. package/dist/packages/work/src/harness/claude.js +260 -58
  30. package/dist/packages/work/src/harness/codex.d.ts +5 -4
  31. package/dist/packages/work/src/harness/codex.js +169 -41
  32. package/dist/packages/work/src/harness/contract.d.ts +36 -11
  33. package/dist/packages/work/src/harness/fake.js +1 -0
  34. package/dist/packages/work/src/harness/jsonrpc-stdio.js +7 -0
  35. package/dist/packages/work/src/harness/permissions.d.ts +16 -3
  36. package/dist/packages/work/src/harness/permissions.js +102 -13
  37. package/dist/packages/work/src/harness/session-store.d.ts +27 -9
  38. package/dist/packages/work/src/harness/session-store.js +271 -67
  39. package/dist/packages/work/src/hold/mcp.d.ts +25 -5
  40. package/dist/packages/work/src/hold/mcp.js +126 -11
  41. package/dist/packages/work/src/hub/client.d.ts +2 -1
  42. package/dist/packages/work/src/hub/client.js +14 -1
  43. package/dist/packages/work/src/hub/types.d.ts +69 -33
  44. package/dist/packages/work/src/hub/types.js +8 -10
  45. package/dist/packages/work/src/mcp/server.js +1 -1
  46. package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
  47. package/dist/packages/work/src/owenloop-bin.js +18 -0
  48. package/dist/packages/work/src/roles/agent-run.d.ts +12 -6
  49. package/dist/packages/work/src/roles/agent-run.js +116 -34
  50. package/dist/packages/work/src/roles/exec.d.ts +8 -0
  51. package/dist/packages/work/src/roles/exec.js +27 -2
  52. package/dist/packages/work/src/roles/hold.d.ts +4 -0
  53. package/dist/packages/work/src/roles/hold.js +44 -5
  54. package/dist/packages/work/src/roles/lint.d.ts +3 -4
  55. package/dist/packages/work/src/roles/lint.js +41 -7
  56. package/dist/packages/work/src/roles/settings.js +5 -0
  57. package/dist/packages/work/src/roles/shift.d.ts +1 -0
  58. package/dist/packages/work/src/roles/shift.js +23 -1
  59. package/dist/packages/work/src/settings/settings.d.ts +17 -1
  60. package/dist/packages/work/src/settings/settings.js +39 -0
  61. package/dist/packages/work/src/shift/loop.d.ts +14 -3
  62. package/dist/packages/work/src/shift/loop.js +447 -164
  63. package/dist/packages/work/src/shift/protocol.d.ts +4 -0
  64. package/dist/packages/work/src/shift/runtime.d.ts +2 -0
  65. package/dist/packages/work/src/shift/runtime.js +66 -3
  66. package/dist/packages/work/src/shift/spawn.d.ts +41 -18
  67. package/dist/packages/work/src/shift/spawn.js +89 -31
  68. package/dist/packages/work/src/shift/state.d.ts +53 -51
  69. package/dist/packages/work/src/shift/state.js +325 -102
  70. package/dist/packages/work/src/submit-proof.d.ts +36 -0
  71. package/dist/packages/work/src/submit-proof.js +93 -0
  72. package/dist/src/add.d.ts +64 -259
  73. package/dist/src/add.js +81 -615
  74. package/dist/src/archive.d.ts +97 -0
  75. package/dist/src/archive.js +591 -0
  76. package/dist/src/bundle/index.d.ts +64 -0
  77. package/dist/src/bundle/index.js +508 -0
  78. package/dist/src/bundle/manifest.d.ts +50 -0
  79. package/dist/src/bundle/manifest.js +435 -0
  80. package/dist/src/bundle/runtime.d.ts +26 -0
  81. package/dist/src/bundle/runtime.js +64 -0
  82. package/dist/src/bundle/tar.d.ts +62 -0
  83. package/dist/src/bundle/tar.js +238 -0
  84. package/dist/src/bundle/types.d.ts +105 -0
  85. package/dist/src/bundle/types.js +21 -0
  86. package/dist/src/cli.d.ts +90 -20
  87. package/dist/src/cli.js +2407 -365
  88. package/dist/src/credentials.d.ts +4 -3
  89. package/dist/src/credentials.js +21 -19
  90. package/dist/src/crypto/allowed-signers.d.ts +68 -0
  91. package/dist/src/crypto/allowed-signers.js +307 -0
  92. package/dist/src/crypto/canonical.d.ts +8 -0
  93. package/dist/src/crypto/canonical.js +92 -0
  94. package/dist/src/crypto/chain.d.ts +65 -0
  95. package/dist/src/crypto/chain.js +377 -0
  96. package/dist/src/crypto/dsse.d.ts +209 -0
  97. package/dist/src/crypto/dsse.js +282 -0
  98. package/dist/src/crypto/enrollment.d.ts +78 -0
  99. package/dist/src/crypto/enrollment.js +186 -0
  100. package/dist/src/crypto/index.d.ts +48 -0
  101. package/dist/src/crypto/index.js +44 -0
  102. package/dist/src/crypto/keys.d.ts +258 -0
  103. package/dist/src/crypto/keys.js +908 -0
  104. package/dist/src/crypto/org-root.d.ts +33 -0
  105. package/dist/src/crypto/org-root.js +78 -0
  106. package/dist/src/crypto/origin-rules.d.ts +56 -0
  107. package/dist/src/crypto/origin-rules.js +143 -0
  108. package/dist/src/crypto/policy-floor.d.ts +98 -0
  109. package/dist/src/crypto/policy-floor.js +353 -0
  110. package/dist/src/crypto/records.d.ts +316 -0
  111. package/dist/src/crypto/records.js +157 -0
  112. package/dist/src/crypto/scope.d.ts +49 -0
  113. package/dist/src/crypto/scope.js +83 -0
  114. package/dist/src/crypto/ssh.d.ts +171 -0
  115. package/dist/src/crypto/ssh.js +396 -0
  116. package/dist/src/crypto/submission.d.ts +33 -0
  117. package/dist/src/crypto/submission.js +47 -0
  118. package/dist/src/crypto/trust-roots.d.ts +29 -0
  119. package/dist/src/crypto/trust-roots.js +39 -0
  120. package/dist/src/crypto/verify-consumed.d.ts +67 -0
  121. package/dist/src/crypto/verify-consumed.js +259 -0
  122. package/dist/src/crypto/verify-origin.d.ts +50 -0
  123. package/dist/src/crypto/verify-origin.js +151 -0
  124. package/dist/src/crypto/verify-publication.d.ts +60 -0
  125. package/dist/src/crypto/verify-publication.js +150 -0
  126. package/dist/src/defs.d.ts +24 -1
  127. package/dist/src/defs.js +145 -25
  128. package/dist/src/engine.d.ts +99 -3
  129. package/dist/src/engine.js +238 -34
  130. package/dist/src/factory.d.ts +16 -0
  131. package/dist/src/factory.js +16 -4
  132. package/dist/src/global-config.d.ts +59 -0
  133. package/dist/src/global-config.js +84 -0
  134. package/dist/src/hub.d.ts +75 -21
  135. package/dist/src/hub.js +123 -40
  136. package/dist/src/index.d.ts +17 -2
  137. package/dist/src/index.js +20 -2
  138. package/dist/src/install.d.ts +538 -0
  139. package/dist/src/install.js +1981 -0
  140. package/dist/src/lock.d.ts +15 -57
  141. package/dist/src/lock.js +251 -143
  142. package/dist/src/mcp/serve.d.ts +46 -22
  143. package/dist/src/mcp/serve.js +167 -44
  144. package/dist/src/mcp/server.js +12 -1
  145. package/dist/src/model.d.ts +15 -0
  146. package/dist/src/model.js +111 -1
  147. package/dist/src/order-resolver.d.ts +184 -0
  148. package/dist/src/order-resolver.js +252 -0
  149. package/dist/src/package-version.d.ts +10 -0
  150. package/dist/src/package-version.js +42 -0
  151. package/dist/src/paths.d.ts +14 -1
  152. package/dist/src/paths.js +18 -0
  153. package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
  154. package/dist/src/schemas/index.d.ts +1416 -0
  155. package/dist/src/schemas/index.js +31 -0
  156. package/dist/src/schemas/order.v1.schema.json +106 -0
  157. package/dist/src/schemas/origin.v1.schema.json +68 -0
  158. package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
  159. package/dist/src/schemas/publication.v1.schema.json +31 -0
  160. package/dist/src/schemas/revocation.v1.schema.json +39 -0
  161. package/dist/src/schemas/submission.v1.schema.json +61 -0
  162. package/dist/src/store/def-source.d.ts +52 -0
  163. package/dist/src/store/def-source.js +335 -0
  164. package/dist/src/store/index-file.d.ts +69 -0
  165. package/dist/src/store/index-file.js +151 -0
  166. package/dist/src/store/index.d.ts +27 -0
  167. package/dist/src/store/index.js +22 -0
  168. package/dist/src/store/ingestor.d.ts +43 -0
  169. package/dist/src/store/ingestor.js +211 -0
  170. package/dist/src/store/install.d.ts +228 -0
  171. package/dist/src/store/install.js +555 -0
  172. package/dist/src/store/instruction-source.d.ts +49 -0
  173. package/dist/src/store/instruction-source.js +298 -0
  174. package/dist/src/store/origin-evidence.d.ts +21 -0
  175. package/dist/src/store/origin-evidence.js +66 -0
  176. package/dist/src/store/pre-commit-verifier.d.ts +68 -0
  177. package/dist/src/store/pre-commit-verifier.js +418 -0
  178. package/dist/src/store/resolve.d.ts +138 -0
  179. package/dist/src/store/resolve.js +363 -0
  180. package/dist/src/store/types.d.ts +288 -0
  181. package/dist/src/store/types.js +356 -0
  182. package/dist/src/types.d.ts +45 -11
  183. package/dist/src/untar.d.ts +8 -23
  184. package/dist/src/untar.js +10 -136
  185. package/docs/agent-runner.md +86 -0
  186. package/docs/authoring.md +57 -6
  187. package/docs/bundles.md +250 -0
  188. package/docs/cli.md +1171 -97
  189. package/docs/crypto.md +816 -0
  190. package/docs/design.md +342 -20
  191. package/docs/embedding.md +132 -25
  192. package/docs/wire-contracts.md +380 -0
  193. package/package.json +6 -1
  194. package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
  195. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
  196. package/plugins/claude-code/plugin/.mcp.json +14 -0
  197. package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
  198. package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
  199. package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
  200. package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
  201. package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
  202. package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
  203. package/plugins/codex/.agents/plugins/marketplace.json +21 -0
  204. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
  205. package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
  206. package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
  207. package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
  208. package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
  209. package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
  210. package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
  211. package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -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[];