forge-workflow 0.1.0-beta.5 → 0.1.0-beta.7

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 (268) hide show
  1. package/AGENTS.md +4 -0
  2. package/CHANGELOG.md +48 -0
  3. package/CLAUDE.md +0 -12
  4. package/CODING_STANDARDS.md +72 -0
  5. package/bin/forge.js +12 -1
  6. package/docs/guides/MIGRATION.md +3 -3
  7. package/docs/reference/FORGE_KERNEL_STORAGE_MODEL.md +4 -0
  8. package/docs/reference/INSTALL.md +4 -0
  9. package/docs/reference/LEGACY_CLAIM_REPAIR.md +112 -0
  10. package/docs/reference/RELEASE.md +4 -4
  11. package/docs/reference/github-accounts.md +134 -0
  12. package/docs/reference/shepherd.md +63 -13
  13. package/lib/adapters/pr-state-adapter.js +15 -2
  14. package/lib/base-remote.js +138 -0
  15. package/lib/beta5-compatibility-evidence.js +1093 -0
  16. package/lib/bun-lockfile-proof.js +413 -0
  17. package/lib/bun-workflow-pins.js +461 -0
  18. package/lib/capabilities/index.js +9 -0
  19. package/lib/capabilities/model.js +141 -0
  20. package/lib/capabilities/probes.js +347 -0
  21. package/lib/codex-skills.js +2 -2
  22. package/lib/commands/_manifest.js +1 -0
  23. package/lib/commands/_registry.js +48 -18
  24. package/lib/commands/clean.js +57 -1
  25. package/lib/commands/doctor.js +37 -6
  26. package/lib/commands/gate.js +197 -27
  27. package/lib/commands/github.js +215 -0
  28. package/lib/commands/hooks.js +54 -6
  29. package/lib/commands/memory.js +66 -2
  30. package/lib/commands/merge.js +720 -73
  31. package/lib/commands/plan.js +33 -2
  32. package/lib/commands/pr.js +2 -0
  33. package/lib/commands/preflight.js +10 -2
  34. package/lib/commands/push.js +120 -9
  35. package/lib/commands/recall.js +95 -61
  36. package/lib/commands/release.js +23 -2
  37. package/lib/commands/remember.js +28 -4
  38. package/lib/commands/serve.js +26 -9
  39. package/lib/commands/setup.js +132 -4
  40. package/lib/commands/shepherd.js +578 -72
  41. package/lib/commands/ship.js +15 -69
  42. package/lib/commands/skill.js +8 -0
  43. package/lib/commands/team.js +47 -8
  44. package/lib/commands/test.js +163 -4
  45. package/lib/commands/validate.js +78 -22
  46. package/lib/commands/worktree.js +155 -19
  47. package/lib/fixtures/beta5-corpus/v1/README.md +9 -0
  48. package/lib/fixtures/beta5-corpus/v1/contract/command-contract.json +26 -0
  49. package/lib/fixtures/beta5-corpus/v1/contract/package-contract.json +13 -0
  50. package/lib/fixtures/beta5-corpus/v1/contract/workflow-stage-matrix.json +8 -0
  51. package/lib/fixtures/beta5-corpus/v1/manifest.json +25 -0
  52. package/lib/fixtures/beta5-corpus/v1/state/comments.jsonl +1 -0
  53. package/lib/fixtures/beta5-corpus/v1/state/config.yaml +6 -0
  54. package/lib/fixtures/beta5-corpus/v1/state/dependencies.jsonl +1 -0
  55. package/lib/fixtures/beta5-corpus/v1/state/issues.jsonl +2 -0
  56. package/lib/fixtures/beta5-corpus/v1/state/kernel.sql +20 -0
  57. package/lib/forge-issues.js +78 -0
  58. package/lib/gate-events.js +98 -10
  59. package/lib/github-context.js +308 -0
  60. package/lib/global-flags.js +1 -0
  61. package/lib/hook-renderer.js +29 -1
  62. package/lib/issue-render.js +19 -0
  63. package/lib/kernel/broker.js +723 -31
  64. package/lib/kernel/claim-reconciler.js +238 -0
  65. package/lib/kernel/lease-enforcer.js +9 -4
  66. package/lib/kernel/legacy-claim-repair.js +442 -0
  67. package/lib/kernel/live-claim-projection.js +26 -0
  68. package/lib/kernel/migrations.js +118 -3
  69. package/lib/kernel/readiness-model.js +184 -12
  70. package/lib/kernel/schema.js +49 -1
  71. package/lib/kernel/sqlite-driver.js +3322 -183
  72. package/lib/kernel/taxonomy-validator.js +4 -1
  73. package/lib/kernel/windows-private-acl.js +239 -0
  74. package/lib/memory/hygiene.js +191 -0
  75. package/lib/memory/router.js +94 -27
  76. package/lib/memory/usage-evidence.js +4 -0
  77. package/lib/memory-digest.js +59 -0
  78. package/lib/merge-rules.js +135 -17
  79. package/lib/npm-publish-workflow.js +233 -40
  80. package/lib/package-root.js +2 -0
  81. package/lib/pr-monitor/auto-actions.js +169 -28
  82. package/lib/pr-monitor/differ.js +110 -4
  83. package/lib/pr-monitor/events.js +0 -0
  84. package/lib/pr-monitor/flow-monitor.js +1424 -0
  85. package/lib/pr-monitor/gather.js +251 -44
  86. package/lib/pr-monitor/journal.js +0 -37
  87. package/lib/pr-monitor/monitor.js +117 -10
  88. package/lib/pr-monitor/process-identity.js +117 -0
  89. package/lib/pr-monitor/reconcile-executor.js +1101 -625
  90. package/lib/pr-monitor/reconcile.js +0 -0
  91. package/lib/pr-monitor/render-summary.js +121 -24
  92. package/lib/pr-monitor/review-preflight.js +269 -0
  93. package/lib/pr-monitor/shepherd-lease.js +28 -19
  94. package/lib/pr-monitor/verdict.js +438 -0
  95. package/lib/pr-monitor/watch-lifecycle.js +144 -38
  96. package/lib/pr-monitor/watch-owner.js +1414 -0
  97. package/lib/pr-monitor/watch.js +129 -58
  98. package/lib/pr-shepherd.js +17 -3
  99. package/lib/project-memory.js +145 -3
  100. package/lib/protected-state-authority.js +799 -4
  101. package/lib/protected-state-surfaces.js +181 -3
  102. package/lib/release-readiness.js +2 -3
  103. package/lib/review-adapter.js +65 -0
  104. package/lib/skills-sync.js +65 -32
  105. package/lib/validation/risk-manifest.js +339 -0
  106. package/lib/validation-receipt.js +190 -0
  107. package/lib/workflow/enforce-stage.js +44 -0
  108. package/lib/workflow/plan-authority.js +225 -0
  109. package/node_modules/@forge/contracts/compatibility-matrix.v1.json +1 -0
  110. package/node_modules/@forge/contracts/contract-baseline.v1.json +134 -0
  111. package/node_modules/@forge/contracts/fixtures/v1/canonical-hash.json +1 -0
  112. package/node_modules/@forge/contracts/fixtures/v1/contract-inputs.v1.json +71 -0
  113. package/node_modules/@forge/contracts/fixtures/v1/feedback-secret-reject.json +1 -0
  114. package/node_modules/@forge/contracts/fixtures/v1/identity-conflict.json +1 -0
  115. package/node_modules/@forge/contracts/fixtures/v1/malformed-envelope-inputs.v1.json +16 -0
  116. package/node_modules/@forge/contracts/fixtures/v1/malformed-missing-required.json +1 -0
  117. package/node_modules/@forge/contracts/fixtures/v1/monitor-bounds-reject.json +1 -0
  118. package/node_modules/@forge/contracts/fixtures/v1/monitor-receipt-privacy-reject.json +1 -0
  119. package/node_modules/@forge/contracts/fixtures/v1/not-executed-receipt.json +1 -0
  120. package/node_modules/@forge/contracts/fixtures/v1/privacy-redaction.json +1 -0
  121. package/node_modules/@forge/contracts/fixtures/v1/retry-identical.json +1 -0
  122. package/node_modules/@forge/contracts/fixtures/v1/stale-authority-reject.json +1 -0
  123. package/node_modules/@forge/contracts/fixtures/v1/structured-error-privacy-reject.json +1 -0
  124. package/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-live-reject.json +1 -0
  125. package/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-test-reject.json +1 -0
  126. package/node_modules/@forge/contracts/fixtures/v1/unknown-advisory-roundtrip.json +1 -0
  127. package/node_modules/@forge/contracts/fixtures/v1/unknown-consequential-reject.json +1 -0
  128. package/node_modules/@forge/contracts/fixtures/v1/valid-full.json +1 -0
  129. package/node_modules/@forge/contracts/fixtures/v1/valid-minimal.json +1 -0
  130. package/node_modules/@forge/contracts/fixtures/v1/wrong-capability-digest.json +1 -0
  131. package/node_modules/@forge/contracts/index.js +32 -0
  132. package/node_modules/@forge/contracts/package.json +35 -0
  133. package/node_modules/@forge/contracts/schemas/v1/capability-manifest.schema.json +1 -0
  134. package/node_modules/@forge/contracts/schemas/v1/claim-request.schema.json +1 -0
  135. package/node_modules/@forge/contracts/schemas/v1/context-packet.schema.json +1 -0
  136. package/node_modules/@forge/contracts/schemas/v1/delivery-receipt.schema.json +1 -0
  137. package/node_modules/@forge/contracts/schemas/v1/feedback-report.schema.json +1 -0
  138. package/node_modules/@forge/contracts/schemas/v1/lease-receipt.schema.json +1 -0
  139. package/node_modules/@forge/contracts/schemas/v1/monitor-event.schema.json +1 -0
  140. package/node_modules/@forge/contracts/schemas/v1/monitor-receipt.schema.json +1 -0
  141. package/node_modules/@forge/contracts/schemas/v1/run-receipt.schema.json +1 -0
  142. package/node_modules/@forge/contracts/schemas/v1/structured-error.schema.json +1 -0
  143. package/node_modules/@forge/contracts/schemas/v1/work-packet.schema.json +1 -0
  144. package/node_modules/@forge/contracts/src/baseline.js +23 -0
  145. package/node_modules/@forge/contracts/src/canonical.js +151 -0
  146. package/node_modules/@forge/contracts/src/definitions.js +176 -0
  147. package/node_modules/@forge/contracts/src/identity.js +42 -0
  148. package/node_modules/@forge/contracts/src/schema.js +72 -0
  149. package/node_modules/@forge/contracts/src/validate.js +305 -0
  150. package/node_modules/@forge/flow/index.js +114 -0
  151. package/node_modules/@forge/flow/package.json +34 -0
  152. package/node_modules/@forge/flow/src/bounded-loop.js +415 -0
  153. package/node_modules/@forge/flow/src/efficiency-supervisor.js +89 -0
  154. package/node_modules/@forge/flow/src/executor.js +279 -0
  155. package/node_modules/@forge/flow/src/monitor-durability.js +419 -0
  156. package/node_modules/@forge/flow/src/monitor-runtime.js +460 -0
  157. package/node_modules/@forge/flow/src/process-lifecycle.js +469 -0
  158. package/node_modules/@forge/flow/src/skill-runtime.js +343 -0
  159. package/node_modules/@forge/memory/index.js +331 -0
  160. package/node_modules/@forge/memory/package.json +34 -0
  161. package/node_modules/@forge/memory/src/authority-provider.js +67 -0
  162. package/node_modules/@forge/memory/src/backend-registry.js +166 -0
  163. package/node_modules/@forge/memory/src/feedback-intake.js +243 -0
  164. package/node_modules/@forge/memory/src/pr-lifecycle-authority.js +946 -0
  165. package/node_modules/@forge/memory/src/usage-evidence.js +205 -0
  166. package/package.json +16 -4
  167. package/packages/flow/node_modules/@forge/contracts/compatibility-matrix.v1.json +1 -0
  168. package/packages/flow/node_modules/@forge/contracts/contract-baseline.v1.json +134 -0
  169. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/canonical-hash.json +1 -0
  170. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/contract-inputs.v1.json +71 -0
  171. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/feedback-secret-reject.json +1 -0
  172. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/identity-conflict.json +1 -0
  173. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/malformed-envelope-inputs.v1.json +16 -0
  174. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/malformed-missing-required.json +1 -0
  175. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/monitor-bounds-reject.json +1 -0
  176. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/monitor-receipt-privacy-reject.json +1 -0
  177. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/not-executed-receipt.json +1 -0
  178. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/privacy-redaction.json +1 -0
  179. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/retry-identical.json +1 -0
  180. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/stale-authority-reject.json +1 -0
  181. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/structured-error-privacy-reject.json +1 -0
  182. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-live-reject.json +1 -0
  183. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-test-reject.json +1 -0
  184. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/unknown-advisory-roundtrip.json +1 -0
  185. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/unknown-consequential-reject.json +1 -0
  186. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/valid-full.json +1 -0
  187. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/valid-minimal.json +1 -0
  188. package/packages/flow/node_modules/@forge/contracts/fixtures/v1/wrong-capability-digest.json +1 -0
  189. package/packages/flow/node_modules/@forge/contracts/index.js +32 -0
  190. package/packages/flow/node_modules/@forge/contracts/package.json +35 -0
  191. package/packages/flow/node_modules/@forge/contracts/schemas/v1/capability-manifest.schema.json +1 -0
  192. package/packages/flow/node_modules/@forge/contracts/schemas/v1/claim-request.schema.json +1 -0
  193. package/packages/flow/node_modules/@forge/contracts/schemas/v1/context-packet.schema.json +1 -0
  194. package/packages/flow/node_modules/@forge/contracts/schemas/v1/delivery-receipt.schema.json +1 -0
  195. package/packages/flow/node_modules/@forge/contracts/schemas/v1/feedback-report.schema.json +1 -0
  196. package/packages/flow/node_modules/@forge/contracts/schemas/v1/lease-receipt.schema.json +1 -0
  197. package/packages/flow/node_modules/@forge/contracts/schemas/v1/monitor-event.schema.json +1 -0
  198. package/packages/flow/node_modules/@forge/contracts/schemas/v1/monitor-receipt.schema.json +1 -0
  199. package/packages/flow/node_modules/@forge/contracts/schemas/v1/run-receipt.schema.json +1 -0
  200. package/packages/flow/node_modules/@forge/contracts/schemas/v1/structured-error.schema.json +1 -0
  201. package/packages/flow/node_modules/@forge/contracts/schemas/v1/work-packet.schema.json +1 -0
  202. package/packages/flow/node_modules/@forge/contracts/src/baseline.js +23 -0
  203. package/packages/flow/node_modules/@forge/contracts/src/canonical.js +151 -0
  204. package/packages/flow/node_modules/@forge/contracts/src/definitions.js +176 -0
  205. package/packages/flow/node_modules/@forge/contracts/src/identity.js +42 -0
  206. package/packages/flow/node_modules/@forge/contracts/src/schema.js +72 -0
  207. package/packages/flow/node_modules/@forge/contracts/src/validate.js +305 -0
  208. package/packages/memory/node_modules/@forge/contracts/compatibility-matrix.v1.json +1 -0
  209. package/packages/memory/node_modules/@forge/contracts/contract-baseline.v1.json +134 -0
  210. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/canonical-hash.json +1 -0
  211. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/contract-inputs.v1.json +71 -0
  212. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/feedback-secret-reject.json +1 -0
  213. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/identity-conflict.json +1 -0
  214. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/malformed-envelope-inputs.v1.json +16 -0
  215. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/malformed-missing-required.json +1 -0
  216. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/monitor-bounds-reject.json +1 -0
  217. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/monitor-receipt-privacy-reject.json +1 -0
  218. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/not-executed-receipt.json +1 -0
  219. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/privacy-redaction.json +1 -0
  220. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/retry-identical.json +1 -0
  221. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/stale-authority-reject.json +1 -0
  222. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/structured-error-privacy-reject.json +1 -0
  223. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-live-reject.json +1 -0
  224. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-test-reject.json +1 -0
  225. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/unknown-advisory-roundtrip.json +1 -0
  226. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/unknown-consequential-reject.json +1 -0
  227. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/valid-full.json +1 -0
  228. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/valid-minimal.json +1 -0
  229. package/packages/memory/node_modules/@forge/contracts/fixtures/v1/wrong-capability-digest.json +1 -0
  230. package/packages/memory/node_modules/@forge/contracts/index.js +32 -0
  231. package/packages/memory/node_modules/@forge/contracts/package.json +35 -0
  232. package/packages/memory/node_modules/@forge/contracts/schemas/v1/capability-manifest.schema.json +1 -0
  233. package/packages/memory/node_modules/@forge/contracts/schemas/v1/claim-request.schema.json +1 -0
  234. package/packages/memory/node_modules/@forge/contracts/schemas/v1/context-packet.schema.json +1 -0
  235. package/packages/memory/node_modules/@forge/contracts/schemas/v1/delivery-receipt.schema.json +1 -0
  236. package/packages/memory/node_modules/@forge/contracts/schemas/v1/feedback-report.schema.json +1 -0
  237. package/packages/memory/node_modules/@forge/contracts/schemas/v1/lease-receipt.schema.json +1 -0
  238. package/packages/memory/node_modules/@forge/contracts/schemas/v1/monitor-event.schema.json +1 -0
  239. package/packages/memory/node_modules/@forge/contracts/schemas/v1/monitor-receipt.schema.json +1 -0
  240. package/packages/memory/node_modules/@forge/contracts/schemas/v1/run-receipt.schema.json +1 -0
  241. package/packages/memory/node_modules/@forge/contracts/schemas/v1/structured-error.schema.json +1 -0
  242. package/packages/memory/node_modules/@forge/contracts/schemas/v1/work-packet.schema.json +1 -0
  243. package/packages/memory/node_modules/@forge/contracts/src/baseline.js +23 -0
  244. package/packages/memory/node_modules/@forge/contracts/src/canonical.js +151 -0
  245. package/packages/memory/node_modules/@forge/contracts/src/definitions.js +176 -0
  246. package/packages/memory/node_modules/@forge/contracts/src/identity.js +42 -0
  247. package/packages/memory/node_modules/@forge/contracts/src/schema.js +72 -0
  248. package/packages/memory/node_modules/@forge/contracts/src/validate.js +305 -0
  249. package/scripts/commitlint.js +13 -15
  250. package/scripts/generate-risk-manifest.js +91 -0
  251. package/scripts/github-context-bridge.sh +10 -0
  252. package/scripts/legacy-claim-repair.js +145 -0
  253. package/scripts/lib/behavioral-eval-runtime.js +3 -2
  254. package/scripts/process-tree.js +14 -2
  255. package/scripts/protected-state-check.js +440 -17
  256. package/scripts/sync-agent-skills.js +333 -34
  257. package/scripts/test-full-suite.js +704 -18
  258. package/scripts/test-profile.js +13 -3
  259. package/scripts/test.js +96 -15
  260. package/skills/coverage.json +1 -0
  261. package/skills/review/SKILL.md +2 -0
  262. package/skills/review/evals/scorecard.json +2 -2
  263. package/skills/setup/SKILL.md +18 -0
  264. package/skills/setup/evals/scorecard.json +3 -3
  265. package/skills/shepherd/SKILL.md +19 -2
  266. package/skills/shepherd/evals/scorecard.json +3 -3
  267. package/skills/validate/SKILL.md +3 -0
  268. package/skills/validate/evals/scorecard.json +1 -1
@@ -0,0 +1,205 @@
1
+ 'use strict';
2
+
3
+ const { types: { isProxy } } = require('node:util');
4
+
5
+ // Public, storage-agnostic contract for bounded durable-memory usage evidence.
6
+ const USE_KINDS = Object.freeze(['cli-recall', 'prompt-injection', 'read-attention', 'session-digest']);
7
+ const MAX_IDENTIFIER_LENGTH = 255;
8
+ const DIGEST_PATTERN = /^[a-f0-9]{64}$/i;
9
+ const SQLITE_CONTENTION_CODES = new Set(['SQLITE_BUSY', 'SQLITE_LOCKED']);
10
+
11
+ const USAGE_EVIDENCE_MIGRATION = Object.freeze({
12
+ id: '011_memory_usage_evidence',
13
+ additive: true,
14
+ rollback_mode: 'disable-writes-preserve-evidence',
15
+ apply: Object.freeze([
16
+ `CREATE TABLE IF NOT EXISTS memory_usage_writer_state (
17
+ singleton INTEGER NOT NULL PRIMARY KEY CHECK (singleton = 1),
18
+ enabled INTEGER NOT NULL CHECK (enabled IN (0, 1))
19
+ );`,
20
+ 'INSERT OR IGNORE INTO memory_usage_writer_state (singleton, enabled) VALUES (1, 1);',
21
+ `CREATE TABLE IF NOT EXISTS memory_usage_events (
22
+ event_id TEXT NOT NULL PRIMARY KEY,
23
+ memory_id TEXT NOT NULL,
24
+ scope TEXT NOT NULL,
25
+ use_kind TEXT NOT NULL,
26
+ consumer_id TEXT NOT NULL,
27
+ selection_digest TEXT NOT NULL,
28
+ observed_at TEXT NOT NULL,
29
+ idempotency_key TEXT NOT NULL UNIQUE
30
+ );`,
31
+ 'CREATE INDEX IF NOT EXISTS idx_memory_usage_events_memory_observed ON memory_usage_events(memory_id, observed_at);',
32
+ `CREATE TABLE IF NOT EXISTS memory_usage_projection (
33
+ scope TEXT NOT NULL,
34
+ memory_id TEXT NOT NULL PRIMARY KEY,
35
+ last_used_at TEXT NOT NULL,
36
+ use_count INTEGER NOT NULL CHECK (typeof(use_count) = 'integer' AND use_count >= 0)
37
+ );`,
38
+ 'CREATE INDEX IF NOT EXISTS idx_memory_usage_projection_scope_last_used_memory ON memory_usage_projection(scope, last_used_at, memory_id);',
39
+ ]),
40
+ rollback: Object.freeze(['UPDATE memory_usage_writer_state SET enabled = 0 WHERE singleton = 1;']),
41
+ });
42
+
43
+ class UsageIdempotencyConflictError extends Error {
44
+ constructor(idempotencyKey) {
45
+ super(`usage evidence idempotency key conflicts: ${idempotencyKey}`);
46
+ this.name = 'UsageIdempotencyConflictError';
47
+ }
48
+ }
49
+
50
+ class UsageMemoryScopeConflictError extends Error {
51
+ constructor(memoryId) {
52
+ super(`usage evidence memory scope conflicts: ${memoryId}`);
53
+ this.name = 'UsageMemoryScopeConflictError';
54
+ }
55
+ }
56
+
57
+ function assertAdapter(store, method) {
58
+ return ownDataMethod(store, method, 'store');
59
+ }
60
+
61
+ function ownDataMethod(value, method, subject = 'adapter') {
62
+ if (!value || typeof value !== 'object' || isProxy(value)) {
63
+ throw new TypeError(`usage evidence ${subject} must be a plain record`);
64
+ }
65
+ let descriptor;
66
+ try { descriptor = Object.getOwnPropertyDescriptor(value, method); } catch { throw new TypeError(`usage evidence ${subject} ${method} must be an own data property`); }
67
+ if (!descriptor || !Object.hasOwn(descriptor, 'value') || typeof descriptor.value !== 'function') {
68
+ throw new TypeError(`usage evidence ${subject} ${method} must be an own data property`);
69
+ }
70
+ return descriptor.value;
71
+ }
72
+
73
+ function optionalOwnDataMethod(value, method, subject = 'store') {
74
+ if (!value || typeof value !== 'object' || isProxy(value)) {
75
+ throw new TypeError(`usage evidence ${subject} must be a plain record`);
76
+ }
77
+ let descriptor;
78
+ try { descriptor = Object.getOwnPropertyDescriptor(value, method); } catch { throw new TypeError(`usage evidence ${subject} ${method} must be an own data property`); }
79
+ if (!descriptor) return undefined;
80
+ if (!Object.hasOwn(descriptor, 'value') || typeof descriptor.value !== 'function') {
81
+ throw new TypeError(`usage evidence ${subject} ${method} must be an own data property`);
82
+ }
83
+ return descriptor.value;
84
+ }
85
+
86
+ function assertOpaqueIdentifier(value, fieldName) {
87
+ if (typeof value !== 'string' || value.length === 0 || value.length > MAX_IDENTIFIER_LENGTH
88
+ || /[\\/]/.test(value) || [...value].some(character => character.charCodeAt(0) < 32)) {
89
+ throw new TypeError(`usage evidence ${fieldName} must be a bounded opaque identifier`);
90
+ }
91
+ }
92
+
93
+ function assertObservedAt(value) {
94
+ if (typeof value !== 'string' || Number.isNaN(Date.parse(value)) || new Date(value).toISOString() !== value) {
95
+ throw new TypeError('usage evidence observed_at must be a canonical ISO timestamp');
96
+ }
97
+ }
98
+
99
+ function readOwnDataProperty(input, fieldName) {
100
+ let descriptor;
101
+ try { descriptor = Object.getOwnPropertyDescriptor(input, fieldName); } catch { throw new TypeError(`usage evidence ${fieldName} must be an own data property`); }
102
+ if (!descriptor || !Object.hasOwn(descriptor, 'value')) throw new TypeError(`usage evidence ${fieldName} must be an own data property`);
103
+ return descriptor.value;
104
+ }
105
+
106
+ function normalizeUsageEvidence(input) {
107
+ if (!input || typeof input !== 'object' || Array.isArray(input)) throw new TypeError('usage evidence must be an object');
108
+ const event = Object.fromEntries(['event_id', 'memory_id', 'scope', 'use_kind', 'consumer_id', 'selection_digest', 'observed_at', 'idempotency_key']
109
+ .map(field => [field, readOwnDataProperty(input, field)]));
110
+ for (const fieldName of ['event_id', 'memory_id', 'scope', 'consumer_id', 'idempotency_key']) assertOpaqueIdentifier(event[fieldName], fieldName);
111
+ if (!USE_KINDS.includes(event.use_kind)) throw new TypeError(`usage evidence use_kind must be one of: ${USE_KINDS.join(', ')}`);
112
+ if (typeof event.selection_digest !== 'string' || !DIGEST_PATTERN.test(event.selection_digest)) throw new TypeError('usage evidence selection_digest must be a SHA-256 digest');
113
+ assertObservedAt(event.observed_at);
114
+ return event;
115
+ }
116
+
117
+ function installUsageEvidenceSchema(store) {
118
+ const exec = assertAdapter(store, 'exec');
119
+ for (const statement of USAGE_EVIDENCE_MIGRATION.apply) exec.call(store, statement);
120
+ }
121
+
122
+ function sameUsageEvidence(left, right) {
123
+ return ['event_id', 'memory_id', 'scope', 'use_kind', 'consumer_id', 'selection_digest', 'observed_at', 'idempotency_key']
124
+ .every(field => left[field] === right[field]);
125
+ }
126
+
127
+ function loadProjection(one, store, event) {
128
+ return one.call(store, 'SELECT last_used_at, use_count FROM memory_usage_projection WHERE memory_id = ?', [event.memory_id]);
129
+ }
130
+
131
+ function runTransactionWithSingleContentionRetry(transaction, store, callback) {
132
+ try { return transaction.call(store, callback); } catch (error) {
133
+ if (!SQLITE_CONTENTION_CODES.has(error?.code)) throw error;
134
+ return transaction.call(store, callback);
135
+ }
136
+ }
137
+
138
+ function assertWriterEnabled(writerGuard, store) {
139
+ if (writerGuard) writerGuard.call(store);
140
+ }
141
+
142
+ function appendUsageEvidence(store, input) {
143
+ const transaction = assertAdapter(store, 'transaction');
144
+ const one = assertAdapter(store, 'one');
145
+ const run = assertAdapter(store, 'run');
146
+ const writerGuard = optionalOwnDataMethod(store, 'assertUsageWriterEnabled');
147
+ const event = normalizeUsageEvidence(input);
148
+ return runTransactionWithSingleContentionRetry(transaction, store, () => {
149
+ assertWriterEnabled(writerGuard, store);
150
+ const existing = one.call(store, `SELECT event_id, memory_id, scope, use_kind, consumer_id, selection_digest, observed_at, idempotency_key
151
+ FROM memory_usage_events WHERE idempotency_key = ?`, [event.idempotency_key]);
152
+ if (existing) {
153
+ if (!sameUsageEvidence(existing, event)) throw new UsageIdempotencyConflictError(event.idempotency_key);
154
+ return { appended: false, ...loadProjection(one, store, event) };
155
+ }
156
+ const conflictingEvent = one.call(store, 'SELECT scope FROM memory_usage_events WHERE memory_id = ? AND scope <> ? LIMIT 1', [event.memory_id, event.scope]);
157
+ const existingProjection = one.call(store, 'SELECT scope FROM memory_usage_projection WHERE memory_id = ?', [event.memory_id]);
158
+ if (conflictingEvent || (existingProjection && existingProjection.scope !== event.scope)) throw new UsageMemoryScopeConflictError(event.memory_id);
159
+ run.call(store, `INSERT INTO memory_usage_events (event_id, memory_id, scope, use_kind, consumer_id, selection_digest, observed_at, idempotency_key)
160
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [event.event_id, event.memory_id, event.scope, event.use_kind, event.consumer_id, event.selection_digest, event.observed_at, event.idempotency_key]);
161
+ run.call(store, `INSERT INTO memory_usage_projection (scope, memory_id, last_used_at, use_count) VALUES (?, ?, ?, 1)
162
+ ON CONFLICT(memory_id) DO UPDATE SET last_used_at = MAX(memory_usage_projection.last_used_at, excluded.last_used_at), use_count = memory_usage_projection.use_count + 1`,
163
+ [event.scope, event.memory_id, event.observed_at]);
164
+ return { appended: true, ...loadProjection(one, store, event) };
165
+ });
166
+ }
167
+
168
+ function rebuildUsageProjection(store) {
169
+ const transaction = assertAdapter(store, 'transaction');
170
+ const exec = assertAdapter(store, 'exec');
171
+ const one = assertAdapter(store, 'one');
172
+ const writerGuard = optionalOwnDataMethod(store, 'assertUsageWriterEnabled');
173
+ return runTransactionWithSingleContentionRetry(transaction, store, () => {
174
+ assertWriterEnabled(writerGuard, store);
175
+ const conflict = one.call(store, `SELECT memory_id FROM memory_usage_events GROUP BY memory_id HAVING COUNT(DISTINCT scope) > 1 LIMIT 1`);
176
+ if (conflict) throw new UsageMemoryScopeConflictError(conflict.memory_id);
177
+ exec.call(store, 'DELETE FROM memory_usage_projection');
178
+ exec.call(store, `INSERT INTO memory_usage_projection (scope, memory_id, last_used_at, use_count)
179
+ SELECT MIN(scope), memory_id, MAX(observed_at), COUNT(*) FROM memory_usage_events GROUP BY memory_id`);
180
+ return { projections: Number(one.call(store, 'SELECT COUNT(*) AS count FROM memory_usage_projection').count) };
181
+ });
182
+ }
183
+
184
+ function createUsageEvidenceStore(driver) {
185
+ const append = ownDataMethod(driver, 'appendUsageEvidence', 'adapter');
186
+ const rebuild = ownDataMethod(driver, 'rebuildUsageProjection', 'adapter');
187
+ const projection = ownDataMethod(driver, 'loadUsageProjection', 'adapter');
188
+ const projections = ownDataMethod(driver, 'loadUsageProjections', 'adapter');
189
+ return Object.freeze({
190
+ append: (event, config = {}) => append.call(driver, normalizeUsageEvidence(event), config),
191
+ rebuild: (config = {}) => rebuild.call(driver, config),
192
+ projection: (memoryId, config = {}) => {
193
+ assertOpaqueIdentifier(memoryId, 'memory_id');
194
+ return projection.call(driver, memoryId, config);
195
+ },
196
+ projections: (memoryIds, config = {}) => {
197
+ if (!Array.isArray(memoryIds) || memoryIds.length > 200) throw new TypeError('usage evidence memory ids must be a bounded array');
198
+ const unique = [...new Set(memoryIds)];
199
+ unique.forEach(memoryId => assertOpaqueIdentifier(memoryId, 'memory_id'));
200
+ return projections.call(driver, unique, config);
201
+ },
202
+ });
203
+ }
204
+
205
+ module.exports = { USE_KINDS, USAGE_EVIDENCE_MIGRATION, UsageIdempotencyConflictError, UsageMemoryScopeConflictError, appendUsageEvidence, createUsageEvidenceStore, installUsageEvidenceSchema, normalizeUsageEvidence, rebuildUsageProjection };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "forge-workflow",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.7",
4
+ "packageManager": "bun@1.4.2",
4
5
  "description": "Local runtime control plane for AI-assisted engineering workflows, gates, evidence, and all AI agents",
5
6
  "bin": {
6
7
  "forge": "bin/forge.js",
@@ -34,7 +35,7 @@
34
35
  "test:benchmark:full": "node scripts/benchmark.js --output test-results/benchmark-full-results.json --profile-dir test-results/benchmark-full-profiles --group full-suite --group validate",
35
36
  "test:full:parallel": "node scripts/test-full-suite.js",
36
37
  "test:dashboard": "node scripts/test-dashboard.js",
37
- "test:profile": "node scripts/test-profile.js --input-dir test-results --output test-results/test-profile.json --label local",
38
+ "test:profile": "node scripts/test-profile.js --input-dir test-results --output test-results/test-profile.profile.json --label local",
38
39
  "test:randomized": "bun test --timeout 15000 --randomize",
39
40
  "test:rerun": "bun test --timeout 15000 --rerun-each 2",
40
41
  "agentic:sync": "node scripts/sync-agentic-workflow.js"
@@ -57,7 +58,7 @@
57
58
  "eslint": "^10.0.2",
58
59
  "eslint-plugin-sonarjs": "^4.1.0",
59
60
  "globals": "^17.3.0",
60
- "js-yaml": "^5.2.2",
61
+ "js-yaml": "^5.2.3",
61
62
  "lefthook": "^2.1.4",
62
63
  "typescript": "7.0.2"
63
64
  },
@@ -101,6 +102,7 @@
101
102
  ".forge/hooks/",
102
103
  ".forge/protected-paths.yaml",
103
104
  "CHANGELOG.md",
105
+ "CODING_STANDARDS.md",
104
106
  "QUICKSTART.md",
105
107
  "docs/*.md",
106
108
  "docs/architecture/**/*.md",
@@ -114,10 +116,19 @@
114
116
  ".mcp.json.example"
115
117
  ],
116
118
  "dependencies": {
119
+ "@forge/flow": "0.1.0-beta.6",
120
+ "@forge/memory": "0.1.0-beta.6",
121
+ "@forge/contracts": "0.1.0-beta.6",
117
122
  "@babel/parser": "^8.0.0",
123
+ "cross-spawn": "^7.0.6",
118
124
  "fastest-levenshtein": "^1.0.16",
119
125
  "yaml": "^2.8.3"
120
126
  },
127
+ "bundledDependencies": [
128
+ "@forge/flow",
129
+ "@forge/memory",
130
+ "@forge/contracts"
131
+ ],
121
132
  "overrides": {
122
133
  "eslint": "^10.0.2",
123
134
  "fast-uri": "^3.1.4",
@@ -125,7 +136,8 @@
125
136
  "minimatch": "10.2.4",
126
137
  "brace-expansion": "5.0.9",
127
138
  "linkify-it": "^5.0.2",
128
- "lodash": "4.18.1"
139
+ "lodash": "4.18.1",
140
+ "qs": "6.16.0"
129
141
  },
130
142
  "c8": {
131
143
  "lines": 80,
@@ -0,0 +1 @@
1
+ {"matrix_version":1,"readers":{"0.1.0-beta.6":{"accepted":{"forge.memory.work-packet.v1":[1],"forge.memory.context-packet.v1":[1],"forge.memory.claim-request.v1":[1],"forge.memory.lease-receipt.v1":[1],"forge.memory.capability-manifest.v1":[1],"forge.memory.run-receipt.v1":[1],"forge.memory.feedback-report.v1":[1],"forge.memory.structured-error.v1":[1],"forge.memory.monitor-event.v1":[1],"forge.memory.delivery-receipt.v1":[1],"forge.memory.monitor-receipt.v1":[1]},"validation_surfaces":{"structural":"no_authority_or_freshness_claim","consequential":"requires_independent_live_expected"},"schema_annotations":{"generic_json_schema_enforces_x_forge":false,"conformance_helper":"validateContractStructure","requirement":"x-forge bounds and privacy annotations require the Forge runtime validator"},"run_receipt_non_authoritative_statuses":["NOT_EXECUTED"],"unknown_advisory":"preserve","unknown_consequential":"reject","unknown_schema_version":"reject"}}}
@@ -0,0 +1,134 @@
1
+ {
2
+ "baseline_version": 1,
3
+ "generator_version": "contracts-schema-gen/7",
4
+ "artifacts": [
5
+ {
6
+ "path": "compatibility-matrix.v1.json",
7
+ "sha256": "4ca93d10ae9bff80dd3785bb5ebfc77610cf19e928b9b9ae3f6a1ad9c2fea18e"
8
+ },
9
+ {
10
+ "path": "fixtures/v1/canonical-hash.json",
11
+ "sha256": "469c5b83ebe5e02601cd41b83f35f013f8fb4b118b8e213dc1790bb61301dc3c"
12
+ },
13
+ {
14
+ "path": "fixtures/v1/contract-inputs.v1.json",
15
+ "sha256": "40f28821f77ea153259a43e0ca8a5d6611f3e5e0ec4e4e47114d4cddeadac3fc"
16
+ },
17
+ {
18
+ "path": "fixtures/v1/feedback-secret-reject.json",
19
+ "sha256": "d2a8762a169617a6c98f5654e1d5265732485037e55af107018d139895b47869"
20
+ },
21
+ {
22
+ "path": "fixtures/v1/identity-conflict.json",
23
+ "sha256": "c703733d89f8adb079fb0e0ffe01ad35238d9a5f3ae725af54bca8b518fd6039"
24
+ },
25
+ {
26
+ "path": "fixtures/v1/malformed-envelope-inputs.v1.json",
27
+ "sha256": "17354a1178523332645f27d506eeabaa39eb6ea6bfa448807f7d0b8d4a1226f2"
28
+ },
29
+ {
30
+ "path": "fixtures/v1/malformed-missing-required.json",
31
+ "sha256": "e4031505309e8b172d274ef7c4ef617e71217742ff2b7285f37859db0eea42b9"
32
+ },
33
+ {
34
+ "path": "fixtures/v1/monitor-bounds-reject.json",
35
+ "sha256": "36594e37f3707572ec73c60134f24f5fb3ae17a41d804c409fc03a83e9716c26"
36
+ },
37
+ {
38
+ "path": "fixtures/v1/monitor-receipt-privacy-reject.json",
39
+ "sha256": "e2c53bc43d727d3583f9f2da6538c127a08997fe279f9e74d585c5b95983b4bf"
40
+ },
41
+ {
42
+ "path": "fixtures/v1/not-executed-receipt.json",
43
+ "sha256": "4582002c36cca422ac1ad9a5858558234d5ed162dbe72b36665fe09ab098099f"
44
+ },
45
+ {
46
+ "path": "fixtures/v1/privacy-redaction.json",
47
+ "sha256": "be4bae1d68db334875b3d198525dcd46f3efb46dbeea62de03399a915b716e20"
48
+ },
49
+ {
50
+ "path": "fixtures/v1/retry-identical.json",
51
+ "sha256": "41c944e15725d45a19bd97015c4bf7fb6ca1a4740426225426bc38799046bd8a"
52
+ },
53
+ {
54
+ "path": "fixtures/v1/stale-authority-reject.json",
55
+ "sha256": "700173546cff08486df201316472921d8304ea892c29770b5f199e63c92601b3"
56
+ },
57
+ {
58
+ "path": "fixtures/v1/structured-error-privacy-reject.json",
59
+ "sha256": "008186d22ed5048e4926c7b56c08a71802392886425944d0e1a22b10c7433d58"
60
+ },
61
+ {
62
+ "path": "fixtures/v1/structured-error-stripe-live-reject.json",
63
+ "sha256": "6e7e0d865ccab874fed66cefd15943bbaf51e4be37bfc99cd38f2e8cd6cafce6"
64
+ },
65
+ {
66
+ "path": "fixtures/v1/structured-error-stripe-test-reject.json",
67
+ "sha256": "ab9d748875e4688299a8678a551a2d3f13eb85c6f852ccbaaf102b870b3da82c"
68
+ },
69
+ {
70
+ "path": "fixtures/v1/unknown-advisory-roundtrip.json",
71
+ "sha256": "674e1dd9585d86ed7c8851a3d7e2b0ce81427a3dbc59c149409ee87375f9e879"
72
+ },
73
+ {
74
+ "path": "fixtures/v1/unknown-consequential-reject.json",
75
+ "sha256": "4228ce85d8f92d6eea61802fd34a410eab778314c70c8315cd1d9c9ba8ef2813"
76
+ },
77
+ {
78
+ "path": "fixtures/v1/valid-full.json",
79
+ "sha256": "2ba47dfcd5bc6dc4fae83160b05eeca480b51b065d251a0f531ca2c3effb0397"
80
+ },
81
+ {
82
+ "path": "fixtures/v1/valid-minimal.json",
83
+ "sha256": "e7d4e7d5cb11b4de809140d572c6f40a5ed4fc813f0044983930a6fbaab99444"
84
+ },
85
+ {
86
+ "path": "fixtures/v1/wrong-capability-digest.json",
87
+ "sha256": "8599acc3eebfba3883ec05e496cfc66e08e79877c8193c24db75540b4549062a"
88
+ },
89
+ {
90
+ "path": "schemas/v1/capability-manifest.schema.json",
91
+ "sha256": "8435c1ec9ebfd0f9b9b6d06f490dcfdac4696f002a83692899e1e172f17cd6dd"
92
+ },
93
+ {
94
+ "path": "schemas/v1/claim-request.schema.json",
95
+ "sha256": "eb9a6aa46c51550fa5505caeeff6e7773fce128e940fdb85a851cfd13cbf1375"
96
+ },
97
+ {
98
+ "path": "schemas/v1/context-packet.schema.json",
99
+ "sha256": "36f422011e03fafe07de5fb16a1e9c745015b4257f640e77f1ae1f4ba70971eb"
100
+ },
101
+ {
102
+ "path": "schemas/v1/delivery-receipt.schema.json",
103
+ "sha256": "1e505c9a790d2e5a3ccf1cd227b7a708924f9d92a61c2220964f7cb05a9d8f4c"
104
+ },
105
+ {
106
+ "path": "schemas/v1/feedback-report.schema.json",
107
+ "sha256": "6f9f272b831d30574ecf56601307a361544f022c7690fd8077aeae8ca5913e37"
108
+ },
109
+ {
110
+ "path": "schemas/v1/lease-receipt.schema.json",
111
+ "sha256": "e7b3c1f6857e4ebad930518236011b8346054b1fa7d38607def4a42c1ba9a739"
112
+ },
113
+ {
114
+ "path": "schemas/v1/monitor-event.schema.json",
115
+ "sha256": "df270f5b7e280c10293f2c964727d13baa0488c9e1cc87037ba1307bc76958dc"
116
+ },
117
+ {
118
+ "path": "schemas/v1/monitor-receipt.schema.json",
119
+ "sha256": "555dba3db355498a1813bfcf045fe2c3f10057789539918e3303c11191048b33"
120
+ },
121
+ {
122
+ "path": "schemas/v1/run-receipt.schema.json",
123
+ "sha256": "de55aca54248a208560fffade7bcfdc555e83daf330f37fe482bb8068495ece6"
124
+ },
125
+ {
126
+ "path": "schemas/v1/structured-error.schema.json",
127
+ "sha256": "ea8b6d40528634743efa91a550d27d8191adc8ce95e630356dadce98ba864d64"
128
+ },
129
+ {
130
+ "path": "schemas/v1/work-packet.schema.json",
131
+ "sha256": "82f149e5ceedf004a5c129f264d0cb94e6704a7eadae8f02dbd40a62b75a556c"
132
+ }
133
+ ]
134
+ }
@@ -0,0 +1 @@
1
+ {"fixture_id":"canonical-hash","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"operation":"canonical-hash","expected":{"stable_under_key_reordering":true,"content_hash_excluded":true}}
@@ -0,0 +1,71 @@
1
+ {
2
+ "corpus_version": 1,
3
+ "inputs": [
4
+ {
5
+ "schema_id": "forge.memory.work-packet.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000001", "created_at": "2026-08-09T12:00:00.000Z",
6
+ "producer": { "product_id": "forge-memory", "product_version": "0.1.0-beta.6", "instance_id": "fixture" }, "capabilities_used": [],
7
+ "provenance": { "source_kind": "fixture", "actor_class": "system", "actor_id": "fixture" }, "content_hash": "b5b6527735acceed41f41cb4b7ae778ad8e3d3fd517832c4936e8c632881c10c",
8
+ "payload": { "issue_id": "issue-1", "expected_issue_revision": 1, "packet_id": "packet-1", "packet_revision": 1, "repository_id": "github.com/example/forge", "target_head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "objective": "fixture objective", "authority": { "kind": "kernel", "issue_revision": 1 }, "allowed_mutations": ["files"], "workflow_config_revision": "config-1", "capability_manifest_digest": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" }, "extensions": {}
9
+ },
10
+ {
11
+ "schema_id": "forge.memory.context-packet.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000002", "created_at": "2026-08-09T12:00:00.000Z",
12
+ "producer": { "product_id": "forge-memory", "product_version": "0.1.0-beta.6", "instance_id": "fixture" }, "capabilities_used": [],
13
+ "provenance": { "source_kind": "fixture", "actor_class": "system", "actor_id": "fixture" }, "content_hash": "278663383d458667b71eb25f6bed8c5828445e070b5af2369a46bc2953b34999",
14
+ "payload": { "work_packet_hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "context_selection_revision": 1, "privacy_scope_hash": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "retention_class": "local_sensitive", "disclosure_class": "remote_redacted", "redaction_policy_revision": "redaction-1", "summaries": [{ "kind": "issue", "text": "redacted fixture" }] }, "extensions": {}
15
+ },
16
+ {
17
+ "schema_id": "forge.memory.claim-request.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000003", "created_at": "2026-08-09T12:00:00.000Z",
18
+ "producer": { "product_id": "forge-memory", "product_version": "0.1.0-beta.6", "instance_id": "fixture" }, "capabilities_used": [],
19
+ "provenance": { "source_kind": "fixture", "actor_class": "agent", "actor_id": "agent-1" }, "content_hash": "aa1972081945dbfff1b9a800ce139968f6bc8581f19d5f243906181565a665aa",
20
+ "payload": { "issue_id": "issue-1", "expected_issue_revision": 1, "actor_id": "agent-1", "request_id": "request-1", "requested_scope": { "mutations": ["files"] }, "idempotency_key": "claim-1" }, "extensions": {}
21
+ },
22
+ {
23
+ "schema_id": "forge.memory.lease-receipt.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000004", "created_at": "2026-08-09T12:00:00.000Z",
24
+ "producer": { "product_id": "forge-memory", "product_version": "0.1.0-beta.6", "instance_id": "fixture" }, "capabilities_used": [],
25
+ "provenance": { "source_kind": "kernel", "actor_class": "authority", "actor_id": "kernel" }, "content_hash": "f3fdc336f2da33d69ed4e1e360e455d9903123add962464062d29f373cabe3d0",
26
+ "payload": { "claim_request_id": "request-1", "lease_id": "lease-1", "lease_epoch": 1, "issue_revision": 1, "actor_id": "agent-1", "scope": { "mutations": ["files"] }, "expires_at": "2026-08-09T13:00:00.000Z", "durable": true, "authority_signature": "fixture-signature" }, "extensions": {}
27
+ },
28
+ {
29
+ "schema_id": "forge.memory.capability-manifest.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000005", "created_at": "2026-08-09T12:00:00.000Z",
30
+ "producer": { "product_id": "forge-flow", "product_version": "0.1.0-beta.6", "instance_id": "fixture" }, "capabilities_used": [],
31
+ "provenance": { "source_kind": "probe", "actor_class": "system", "actor_id": "probe" }, "content_hash": "296ff678e04103e339231fef672db2220f5bd23981fefdc96dcfcd6f338f355e",
32
+ "payload": { "provider_id": "codex", "manifest_revision": 1, "config_revision": "config-1", "executable_identity": { "path_hash": "fixture" }, "provider_version": "1.0.0", "probe_revision": "probe-1", "result_hash": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", "capabilities": [{ "capability_id": "flow.execute", "available": true }], "evaluator_status": "approved", "probed_at": "2026-08-09T12:00:00.000Z", "expires_at": "2026-08-09T13:00:00.000Z" }, "extensions": {}
33
+ },
34
+ {
35
+ "schema_id": "forge.memory.run-receipt.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000006", "created_at": "2026-08-09T12:30:00.000Z",
36
+ "producer": { "product_id": "forge-flow", "product_version": "0.1.0-beta.6", "instance_id": "run-1" }, "capabilities_used": [],
37
+ "provenance": { "source_kind": "execution", "actor_class": "agent", "actor_id": "agent-1" }, "content_hash": "4f919795d2c62ad6520b54fc526c215621ef046a59326f673aa6e41a1f6fc751",
38
+ "payload": { "packet_hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "run_id": "run-1", "attempt_id": "attempt-1", "exact_head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "packet_revision": 1, "manifest_digest": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "workflow_config_revision": "config-1", "status": "PASS", "executor": { "product": "forge-flow" }, "started_at": "2026-08-09T12:00:00.000Z", "ended_at": "2026-08-09T12:30:00.000Z", "evidence_refs": [], "validation": { "status": "PASS" }, "cleanup": { "status": "PASS" } }, "extensions": {}
39
+ },
40
+ {
41
+ "schema_id": "forge.memory.feedback-report.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000007", "created_at": "2026-08-09T12:00:00.000Z",
42
+ "producer": { "product_id": "forge-memory", "product_version": "0.1.0-beta.6", "instance_id": "fixture" }, "capabilities_used": [],
43
+ "provenance": { "source_kind": "feedback", "actor_class": "anonymous-user", "actor_id": "report-1" }, "content_hash": "3adb5b3f1b726b7b67032bf607ab89e54aee3f9eeefa6d4cdbd29340bee555c1",
44
+ "payload": { "report_id": "report-1", "product_version": "0.1.0-beta.6", "contract_version": 1, "stable_error_code": "FORGE_FIXTURE", "affected_capability": "flow.execute", "redacted_reproduction_steps": ["run fixture"], "expected_classification": "PASS", "actual_classification": "FAIL", "occurrence_count": 1, "content_fingerprint": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "consent_event_id": "consent-1", "redaction_policy_revision": "redaction-1" }, "extensions": {}
45
+ },
46
+ {
47
+ "schema_id": "forge.memory.structured-error.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000008", "created_at": "2026-08-09T12:00:00.000Z",
48
+ "producer": { "product_id": "forge-memory", "product_version": "0.1.0-beta.6", "instance_id": "fixture" }, "capabilities_used": [],
49
+ "provenance": { "source_kind": "execution", "actor_class": "system", "actor_id": "forge" }, "content_hash": "50d181d71714a308539f5612fee7dfa854a4abe9591981842303de24db64982d",
50
+ "payload": { "parent_object_hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "error_occurrence_id": "error-1", "code": "FORGE_FIXTURE", "terminal_classification": "FAIL", "safe_details": { "summary": "fixture failure" } }, "extensions": {}
51
+ },
52
+ {
53
+ "schema_id": "forge.memory.monitor-event.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000009", "created_at": "2026-08-09T12:00:00.000Z",
54
+ "producer": { "product_id": "forge-flow", "product_version": "0.1.0-beta.6", "instance_id": "monitor-1" }, "capabilities_used": [],
55
+ "provenance": { "source_kind": "monitor", "actor_class": "system", "actor_id": "monitor" }, "content_hash": "01b1e7086a5ba2ddf521ad8e8901db925d9f9e8fe2db75c43ca5eea941d68559",
56
+ "payload": { "monitor_id": "monitor-1", "event_id": "event-1", "sequence": 0, "subject_revision": "head-1", "type": "check.completed", "actionability": "advisory", "observed_at": "2026-08-09T12:00:00.000Z", "bounded_payload": { "status": "PASS" } }, "extensions": {}
57
+ },
58
+ {
59
+ "schema_id": "forge.memory.delivery-receipt.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000010", "created_at": "2026-08-09T12:00:00.000Z",
60
+ "producer": { "product_id": "forge-flow", "product_version": "0.1.0-beta.6", "instance_id": "delivery-1" }, "capabilities_used": [],
61
+ "provenance": { "source_kind": "delivery", "actor_class": "system", "actor_id": "adapter" }, "content_hash": "0bfe86d8a48be6ac271c92c1e767ec53ce0f7bfc2e228a47832522eefa44b40a",
62
+ "payload": { "event_id": "event-1", "target": "agent-1", "transport_tier": "T1", "attempt": 1, "delivered_at": "2026-08-09T12:00:00.000Z", "acknowledged": true, "outcome": "acknowledged" }, "extensions": {}
63
+ },
64
+ {
65
+ "schema_id": "forge.memory.monitor-receipt.v1", "schema_version": 1, "object_id": "00000000-0000-4000-8000-000000000011", "created_at": "2026-08-09T12:00:00.000Z",
66
+ "producer": { "product_id": "forge-flow", "product_version": "0.1.0-beta.6", "instance_id": "monitor-1" }, "capabilities_used": [],
67
+ "provenance": { "source_kind": "monitor", "actor_class": "system", "actor_id": "monitor" }, "content_hash": "01da8754bae5d5a17501a7e20bfc93959e274227add6a31e451424b2c1ac7251",
68
+ "payload": { "monitor_id": "monitor-1", "owner_run_id": "run-1", "terminal_state": "PASS", "terminal_reason": "predicate satisfied", "last_sequence": 0, "evidence_digest": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "cancellation_acknowledged": true, "process_cleanup": { "status": "PASS" }, "lease_cleanup": { "status": "PASS" } }, "extensions": {}
69
+ }
70
+ ]
71
+ }
@@ -0,0 +1 @@
1
+ {"fixture_id":"feedback-secret-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.feedback-report.v1"},"mutation":{"operation":"replace","path":"payload.redacted_reproduction_steps","value":["token=ghp_123456789012345678901234567890"],"rehash":true},"operation":"validate-structure","expected":{"ok":false,"code":"PRIVACY_SECRET_PATTERN"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"identity-conflict","accepted_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"candidate_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"candidate_mutation":{"operation":"replace","path":"payload.objective","value":"conflicting objective","rehash":true},"operation":"classify-semantic-attempt","expected":{"status":"identity-conflict"}}
@@ -0,0 +1,16 @@
1
+ {
2
+ "corpus_version": 1,
3
+ "base_input": { "ref": "contract-inputs.v1.json", "schema_id": "forge.memory.work-packet.v1" },
4
+ "cases": [
5
+ { "missing_field": "schema_id", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
6
+ { "missing_field": "schema_version", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
7
+ { "missing_field": "object_id", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
8
+ { "missing_field": "created_at", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
9
+ { "missing_field": "producer", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
10
+ { "missing_field": "capabilities_used", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
11
+ { "missing_field": "provenance", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
12
+ { "missing_field": "content_hash", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
13
+ { "missing_field": "payload", "operation": "remove", "expected_code": "MISSING_REQUIRED" },
14
+ { "missing_field": "extensions", "operation": "remove", "expected_code": "MISSING_REQUIRED" }
15
+ ]
16
+ }
@@ -0,0 +1 @@
1
+ {"fixture_id":"malformed-missing-required","input_ref":{"file":"malformed-envelope-inputs.v1.json"},"operation":"materialize-cases","expected":{"case_count":10,"code":"MISSING_REQUIRED"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"monitor-bounds-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.monitor-event.v1"},"mutation":{"operation":"replace","path":"payload.bounded_payload","value":{"shape":"nine-level nested object; materializer repeats key child nine times"},"rehash":true},"operation":"validate-structure","expected":{"ok":false,"code":"BOUNDED_VALUE_TOO_DEEP"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"monitor-receipt-privacy-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.monitor-receipt.v1"},"mutation":{"operation":"replace","path":"payload.process_cleanup","value":{"detail":"password=supersecretvalue"},"rehash":true},"operation":"validate-structure","expected":{"ok":false,"code":"PRIVACY_SECRET_PATTERN"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"not-executed-receipt","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.run-receipt.v1"},"mutation":{"operation":"replace","path":"payload.status","value":"NOT_EXECUTED","rehash":true},"operation":"validate-structure-then-authority","expected":{"structural_ok":true,"authority_ok":false,"authority_code":"NOT_EXECUTED_NO_TRANSITION"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"privacy-redaction","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.context-packet.v1"},"live_expected":{"workPacketHash":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","privacyScopeHash":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd","redactionPolicyRevision":"redaction-1","allowedDisclosureClasses":["remote_redacted"]},"operation":"validate-expected","expected":{"code":"STALE_PRIVACY_SCOPE","raw_content_embedded":false}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"retry-identical","accepted_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"candidate_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"operation":"classify-semantic-attempt","expected":{"status":"retry-identical"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"stale-authority-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"live_expected":{"issueRevision":2,"workflowConfigRevision":"config-1","capabilityManifestDigest":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc","exactHead":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},"operation":"validate-expected","expected":{"code":"STALE_ISSUE_REVISION"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"structured-error-privacy-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.structured-error.v1"},"mutation":{"operation":"replace","path":"payload.safe_details","value":{"detail":"token=ghp_123456789012345678901234567890"},"rehash":true},"operation":"validate-structure","expected":{"ok":false,"code":"PRIVACY_SECRET_PATTERN"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"structured-error-stripe-live-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.structured-error.v1"},"mutation":{"operation":"replace","path":"payload.safe_details","value":{"detail":"sk_live_1234567890ABCDEF"},"rehash":true},"operation":"validate-structure","expected":{"ok":false,"code":"PRIVACY_SECRET_PATTERN"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"structured-error-stripe-test-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.structured-error.v1"},"mutation":{"operation":"replace","path":"payload.safe_details","value":{"detail":"sk_test_ABCDEF1234567890"},"rehash":true},"operation":"validate-structure","expected":{"ok":false,"code":"PRIVACY_SECRET_PATTERN"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"unknown-advisory-roundtrip","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"mutation":{"operation":"add","path":"extensions.vendor.example/advisory","value":{"impact":"advisory","schema_version":1,"value":{"note":"preserve"}},"rehash":true},"operation":"roundtrip-extension","expected":{"preserved":true}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"unknown-consequential-reject","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"mutation":{"operation":"add","path":"extensions.vendor.example/authority","value":{"impact":"consequential","schema_version":1,"value":{"permit":true}},"rehash":true},"operation":"validate-extension","expected":{"code":"UNKNOWN_CONSEQUENTIAL_EXTENSION"}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"valid-full","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"mutations":[{"operation":"add","path":"payload.acceptance_criteria","value":["all gates pass"]},{"operation":"add","path":"payload.prohibited_actions","value":["merge"]}],"operation":"rehash-and-validate-structure","authority_claim":false,"expected":{"ok":true}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"valid-minimal","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"operation":"validate-structure","authority_claim":false,"expected":{"ok":true}}
@@ -0,0 +1 @@
1
+ {"fixture_id":"wrong-capability-digest","input_ref":{"file":"contract-inputs.v1.json","schema_id":"forge.memory.work-packet.v1"},"live_expected":{"issueRevision":1,"workflowConfigRevision":"config-1","capabilityManifestDigest":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd","exactHead":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},"operation":"validate-expected","expected":{"code":"WRONG_CAPABILITY_DIGEST"}}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ const { canonicalize, computeContentHash } = require("./src/canonical.js");
4
+ const { verifyContractBaseline } = require("./src/baseline.js");
5
+ const { CONTRACTS } = require("./src/definitions.js");
6
+ const { classifySemanticAttempt, semanticIdentity } = require("./src/identity.js");
7
+ const { generateJsonSchema, supportedSchemaVersions } = require("./src/schema.js");
8
+ const {
9
+ ContractValidationError,
10
+ ENVELOPE_FIELDS,
11
+ parseContract,
12
+ validateContract,
13
+ validateContractStructure,
14
+ validateEnvelope,
15
+ } = require("./src/validate.js");
16
+
17
+ module.exports = {
18
+ ENVELOPE_FIELDS,
19
+ CONTRACTS,
20
+ ContractValidationError,
21
+ canonicalize,
22
+ classifySemanticAttempt,
23
+ computeContentHash,
24
+ generateJsonSchema,
25
+ parseContract,
26
+ semanticIdentity,
27
+ supportedSchemaVersions,
28
+ validateContract,
29
+ validateContractStructure,
30
+ validateEnvelope,
31
+ verifyContractBaseline,
32
+ };