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.
- package/AGENTS.md +4 -0
- package/CHANGELOG.md +48 -0
- package/CLAUDE.md +0 -12
- package/CODING_STANDARDS.md +72 -0
- package/bin/forge.js +12 -1
- package/docs/guides/MIGRATION.md +3 -3
- package/docs/reference/FORGE_KERNEL_STORAGE_MODEL.md +4 -0
- package/docs/reference/INSTALL.md +4 -0
- package/docs/reference/LEGACY_CLAIM_REPAIR.md +112 -0
- package/docs/reference/RELEASE.md +4 -4
- package/docs/reference/github-accounts.md +134 -0
- package/docs/reference/shepherd.md +63 -13
- package/lib/adapters/pr-state-adapter.js +15 -2
- package/lib/base-remote.js +138 -0
- package/lib/beta5-compatibility-evidence.js +1093 -0
- package/lib/bun-lockfile-proof.js +413 -0
- package/lib/bun-workflow-pins.js +461 -0
- package/lib/capabilities/index.js +9 -0
- package/lib/capabilities/model.js +141 -0
- package/lib/capabilities/probes.js +347 -0
- package/lib/codex-skills.js +2 -2
- package/lib/commands/_manifest.js +1 -0
- package/lib/commands/_registry.js +48 -18
- package/lib/commands/clean.js +57 -1
- package/lib/commands/doctor.js +37 -6
- package/lib/commands/gate.js +197 -27
- package/lib/commands/github.js +215 -0
- package/lib/commands/hooks.js +54 -6
- package/lib/commands/memory.js +66 -2
- package/lib/commands/merge.js +720 -73
- package/lib/commands/plan.js +33 -2
- package/lib/commands/pr.js +2 -0
- package/lib/commands/preflight.js +10 -2
- package/lib/commands/push.js +120 -9
- package/lib/commands/recall.js +95 -61
- package/lib/commands/release.js +23 -2
- package/lib/commands/remember.js +28 -4
- package/lib/commands/serve.js +26 -9
- package/lib/commands/setup.js +132 -4
- package/lib/commands/shepherd.js +578 -72
- package/lib/commands/ship.js +15 -69
- package/lib/commands/skill.js +8 -0
- package/lib/commands/team.js +47 -8
- package/lib/commands/test.js +163 -4
- package/lib/commands/validate.js +78 -22
- package/lib/commands/worktree.js +155 -19
- package/lib/fixtures/beta5-corpus/v1/README.md +9 -0
- package/lib/fixtures/beta5-corpus/v1/contract/command-contract.json +26 -0
- package/lib/fixtures/beta5-corpus/v1/contract/package-contract.json +13 -0
- package/lib/fixtures/beta5-corpus/v1/contract/workflow-stage-matrix.json +8 -0
- package/lib/fixtures/beta5-corpus/v1/manifest.json +25 -0
- package/lib/fixtures/beta5-corpus/v1/state/comments.jsonl +1 -0
- package/lib/fixtures/beta5-corpus/v1/state/config.yaml +6 -0
- package/lib/fixtures/beta5-corpus/v1/state/dependencies.jsonl +1 -0
- package/lib/fixtures/beta5-corpus/v1/state/issues.jsonl +2 -0
- package/lib/fixtures/beta5-corpus/v1/state/kernel.sql +20 -0
- package/lib/forge-issues.js +78 -0
- package/lib/gate-events.js +98 -10
- package/lib/github-context.js +308 -0
- package/lib/global-flags.js +1 -0
- package/lib/hook-renderer.js +29 -1
- package/lib/issue-render.js +19 -0
- package/lib/kernel/broker.js +723 -31
- package/lib/kernel/claim-reconciler.js +238 -0
- package/lib/kernel/lease-enforcer.js +9 -4
- package/lib/kernel/legacy-claim-repair.js +442 -0
- package/lib/kernel/live-claim-projection.js +26 -0
- package/lib/kernel/migrations.js +118 -3
- package/lib/kernel/readiness-model.js +184 -12
- package/lib/kernel/schema.js +49 -1
- package/lib/kernel/sqlite-driver.js +3322 -183
- package/lib/kernel/taxonomy-validator.js +4 -1
- package/lib/kernel/windows-private-acl.js +239 -0
- package/lib/memory/hygiene.js +191 -0
- package/lib/memory/router.js +94 -27
- package/lib/memory/usage-evidence.js +4 -0
- package/lib/memory-digest.js +59 -0
- package/lib/merge-rules.js +135 -17
- package/lib/npm-publish-workflow.js +233 -40
- package/lib/package-root.js +2 -0
- package/lib/pr-monitor/auto-actions.js +169 -28
- package/lib/pr-monitor/differ.js +110 -4
- package/lib/pr-monitor/events.js +0 -0
- package/lib/pr-monitor/flow-monitor.js +1424 -0
- package/lib/pr-monitor/gather.js +251 -44
- package/lib/pr-monitor/journal.js +0 -37
- package/lib/pr-monitor/monitor.js +117 -10
- package/lib/pr-monitor/process-identity.js +117 -0
- package/lib/pr-monitor/reconcile-executor.js +1101 -625
- package/lib/pr-monitor/reconcile.js +0 -0
- package/lib/pr-monitor/render-summary.js +121 -24
- package/lib/pr-monitor/review-preflight.js +269 -0
- package/lib/pr-monitor/shepherd-lease.js +28 -19
- package/lib/pr-monitor/verdict.js +438 -0
- package/lib/pr-monitor/watch-lifecycle.js +144 -38
- package/lib/pr-monitor/watch-owner.js +1414 -0
- package/lib/pr-monitor/watch.js +129 -58
- package/lib/pr-shepherd.js +17 -3
- package/lib/project-memory.js +145 -3
- package/lib/protected-state-authority.js +799 -4
- package/lib/protected-state-surfaces.js +181 -3
- package/lib/release-readiness.js +2 -3
- package/lib/review-adapter.js +65 -0
- package/lib/skills-sync.js +65 -32
- package/lib/validation/risk-manifest.js +339 -0
- package/lib/validation-receipt.js +190 -0
- package/lib/workflow/enforce-stage.js +44 -0
- package/lib/workflow/plan-authority.js +225 -0
- package/node_modules/@forge/contracts/compatibility-matrix.v1.json +1 -0
- package/node_modules/@forge/contracts/contract-baseline.v1.json +134 -0
- package/node_modules/@forge/contracts/fixtures/v1/canonical-hash.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/contract-inputs.v1.json +71 -0
- package/node_modules/@forge/contracts/fixtures/v1/feedback-secret-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/identity-conflict.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/malformed-envelope-inputs.v1.json +16 -0
- package/node_modules/@forge/contracts/fixtures/v1/malformed-missing-required.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/monitor-bounds-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/monitor-receipt-privacy-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/not-executed-receipt.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/privacy-redaction.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/retry-identical.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/stale-authority-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/structured-error-privacy-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-live-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-test-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/unknown-advisory-roundtrip.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/unknown-consequential-reject.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/valid-full.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/valid-minimal.json +1 -0
- package/node_modules/@forge/contracts/fixtures/v1/wrong-capability-digest.json +1 -0
- package/node_modules/@forge/contracts/index.js +32 -0
- package/node_modules/@forge/contracts/package.json +35 -0
- package/node_modules/@forge/contracts/schemas/v1/capability-manifest.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/claim-request.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/context-packet.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/delivery-receipt.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/feedback-report.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/lease-receipt.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/monitor-event.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/monitor-receipt.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/run-receipt.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/structured-error.schema.json +1 -0
- package/node_modules/@forge/contracts/schemas/v1/work-packet.schema.json +1 -0
- package/node_modules/@forge/contracts/src/baseline.js +23 -0
- package/node_modules/@forge/contracts/src/canonical.js +151 -0
- package/node_modules/@forge/contracts/src/definitions.js +176 -0
- package/node_modules/@forge/contracts/src/identity.js +42 -0
- package/node_modules/@forge/contracts/src/schema.js +72 -0
- package/node_modules/@forge/contracts/src/validate.js +305 -0
- package/node_modules/@forge/flow/index.js +114 -0
- package/node_modules/@forge/flow/package.json +34 -0
- package/node_modules/@forge/flow/src/bounded-loop.js +415 -0
- package/node_modules/@forge/flow/src/efficiency-supervisor.js +89 -0
- package/node_modules/@forge/flow/src/executor.js +279 -0
- package/node_modules/@forge/flow/src/monitor-durability.js +419 -0
- package/node_modules/@forge/flow/src/monitor-runtime.js +460 -0
- package/node_modules/@forge/flow/src/process-lifecycle.js +469 -0
- package/node_modules/@forge/flow/src/skill-runtime.js +343 -0
- package/node_modules/@forge/memory/index.js +331 -0
- package/node_modules/@forge/memory/package.json +34 -0
- package/node_modules/@forge/memory/src/authority-provider.js +67 -0
- package/node_modules/@forge/memory/src/backend-registry.js +166 -0
- package/node_modules/@forge/memory/src/feedback-intake.js +243 -0
- package/node_modules/@forge/memory/src/pr-lifecycle-authority.js +946 -0
- package/node_modules/@forge/memory/src/usage-evidence.js +205 -0
- package/package.json +16 -4
- package/packages/flow/node_modules/@forge/contracts/compatibility-matrix.v1.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/contract-baseline.v1.json +134 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/canonical-hash.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/contract-inputs.v1.json +71 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/feedback-secret-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/identity-conflict.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/malformed-envelope-inputs.v1.json +16 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/malformed-missing-required.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/monitor-bounds-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/monitor-receipt-privacy-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/not-executed-receipt.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/privacy-redaction.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/retry-identical.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/stale-authority-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/structured-error-privacy-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-live-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-test-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/unknown-advisory-roundtrip.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/unknown-consequential-reject.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/valid-full.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/valid-minimal.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/fixtures/v1/wrong-capability-digest.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/index.js +32 -0
- package/packages/flow/node_modules/@forge/contracts/package.json +35 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/capability-manifest.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/claim-request.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/context-packet.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/delivery-receipt.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/feedback-report.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/lease-receipt.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/monitor-event.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/monitor-receipt.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/run-receipt.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/structured-error.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/schemas/v1/work-packet.schema.json +1 -0
- package/packages/flow/node_modules/@forge/contracts/src/baseline.js +23 -0
- package/packages/flow/node_modules/@forge/contracts/src/canonical.js +151 -0
- package/packages/flow/node_modules/@forge/contracts/src/definitions.js +176 -0
- package/packages/flow/node_modules/@forge/contracts/src/identity.js +42 -0
- package/packages/flow/node_modules/@forge/contracts/src/schema.js +72 -0
- package/packages/flow/node_modules/@forge/contracts/src/validate.js +305 -0
- package/packages/memory/node_modules/@forge/contracts/compatibility-matrix.v1.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/contract-baseline.v1.json +134 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/canonical-hash.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/contract-inputs.v1.json +71 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/feedback-secret-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/identity-conflict.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/malformed-envelope-inputs.v1.json +16 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/malformed-missing-required.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/monitor-bounds-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/monitor-receipt-privacy-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/not-executed-receipt.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/privacy-redaction.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/retry-identical.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/stale-authority-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/structured-error-privacy-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-live-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/structured-error-stripe-test-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/unknown-advisory-roundtrip.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/unknown-consequential-reject.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/valid-full.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/valid-minimal.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/fixtures/v1/wrong-capability-digest.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/index.js +32 -0
- package/packages/memory/node_modules/@forge/contracts/package.json +35 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/capability-manifest.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/claim-request.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/context-packet.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/delivery-receipt.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/feedback-report.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/lease-receipt.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/monitor-event.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/monitor-receipt.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/run-receipt.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/structured-error.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/schemas/v1/work-packet.schema.json +1 -0
- package/packages/memory/node_modules/@forge/contracts/src/baseline.js +23 -0
- package/packages/memory/node_modules/@forge/contracts/src/canonical.js +151 -0
- package/packages/memory/node_modules/@forge/contracts/src/definitions.js +176 -0
- package/packages/memory/node_modules/@forge/contracts/src/identity.js +42 -0
- package/packages/memory/node_modules/@forge/contracts/src/schema.js +72 -0
- package/packages/memory/node_modules/@forge/contracts/src/validate.js +305 -0
- package/scripts/commitlint.js +13 -15
- package/scripts/generate-risk-manifest.js +91 -0
- package/scripts/github-context-bridge.sh +10 -0
- package/scripts/legacy-claim-repair.js +145 -0
- package/scripts/lib/behavioral-eval-runtime.js +3 -2
- package/scripts/process-tree.js +14 -2
- package/scripts/protected-state-check.js +440 -17
- package/scripts/sync-agent-skills.js +333 -34
- package/scripts/test-full-suite.js +704 -18
- package/scripts/test-profile.js +13 -3
- package/scripts/test.js +96 -15
- package/skills/coverage.json +1 -0
- package/skills/review/SKILL.md +2 -0
- package/skills/review/evals/scorecard.json +2 -2
- package/skills/setup/SKILL.md +18 -0
- package/skills/setup/evals/scorecard.json +3 -3
- package/skills/shepherd/SKILL.md +19 -2
- package/skills/shepherd/evals/scorecard.json +3 -3
- package/skills/validate/SKILL.md +3 -0
- package/skills/validate/evals/scorecard.json +1 -1
|
@@ -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"}}
|
package/packages/memory/node_modules/@forge/contracts/fixtures/v1/unknown-advisory-roundtrip.json
ADDED
|
@@ -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}}
|
package/packages/memory/node_modules/@forge/contracts/fixtures/v1/unknown-consequential-reject.json
ADDED
|
@@ -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}}
|
package/packages/memory/node_modules/@forge/contracts/fixtures/v1/wrong-capability-digest.json
ADDED
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@forge/contracts",
|
|
3
|
+
"version": "0.1.0-beta.6",
|
|
4
|
+
"description": "Behavior-neutral packet and receipt contracts for Forge products",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"src/",
|
|
10
|
+
"schemas/",
|
|
11
|
+
"fixtures/",
|
|
12
|
+
"contract-baseline.v1.json",
|
|
13
|
+
"compatibility-matrix.v1.json"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "bun test test",
|
|
17
|
+
"lint": "eslint . --max-warnings 0"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/harshanandak/forge.git",
|
|
26
|
+
"directory": "packages/contracts"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/harshanandak/forge#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/harshanandak/forge/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22.16.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/packages/memory/node_modules/@forge/contracts/schemas/v1/capability-manifest.schema.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.capability-manifest.v1","title":"CapabilityManifest","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.capability-manifest.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["provider_id","manifest_revision","config_revision","executable_identity","provider_version","probe_revision","result_hash","capabilities","evaluator_status","probed_at","expires_at"],"properties":{"provider_id":{"type":"string","minLength":1},"manifest_revision":{"type":"integer","minimum":1},"config_revision":{"type":"string","minLength":1},"executable_identity":{"type":"object"},"provider_version":{"type":"string","minLength":1},"probe_revision":{"type":"string","minLength":1},"result_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"capabilities":{"type":"array","items":{"type":"object","required":["capability_id","available"],"properties":{"capability_id":{"type":"string","minLength":1},"available":{"type":"boolean"}}}},"evaluator_status":{"type":"string","enum":["approved","unavailable","quarantined"]},"probed_at":{"type":"string","format":"date-time"},"expires_at":{"type":"string","format":"date-time"}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.claim-request.v1","title":"ClaimRequest","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.claim-request.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["issue_id","expected_issue_revision","actor_id","request_id","requested_scope","idempotency_key"],"properties":{"issue_id":{"type":"string","minLength":1},"expected_issue_revision":{"type":"integer","minimum":0},"actor_id":{"type":"string","minLength":1},"request_id":{"type":"string","minLength":1},"requested_scope":{"type":"object"},"idempotency_key":{"type":"string","minLength":1}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.context-packet.v1","title":"ContextPacket","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.context-packet.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["work_packet_hash","context_selection_revision","privacy_scope_hash","retention_class","disclosure_class"],"properties":{"work_packet_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"context_selection_revision":{"type":"integer","minimum":1},"privacy_scope_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"retention_class":{"type":"string","enum":["public_metadata","local_sensitive","remote_redacted","restricted"]},"disclosure_class":{"type":"string","enum":["public_metadata","local_sensitive","remote_redacted","restricted"]},"references":{"type":"array","maxItems":128,"items":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"}},"summaries":{"type":"array","maxItems":128,"items":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"}},"redaction_policy_revision":{"type":"string","minLength":1}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.delivery-receipt.v1","title":"DeliveryReceipt","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.delivery-receipt.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["event_id","target","transport_tier","attempt","delivered_at","acknowledged","outcome"],"properties":{"event_id":{"type":"string","minLength":1},"target":{"type":"string","minLength":1},"transport_tier":{"type":"string","enum":["T0","T1","T2","T3","T4"]},"attempt":{"type":"integer","minimum":1},"delivered_at":{"type":"string","format":"date-time"},"acknowledged":{"type":"boolean"},"outcome":{"type":"string","enum":["delivered","pending","failed","acknowledged"]}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.feedback-report.v1","title":"FeedbackReport","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.feedback-report.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["report_id","product_version","contract_version","stable_error_code","affected_capability","redacted_reproduction_steps","expected_classification","actual_classification","occurrence_count","content_fingerprint","consent_event_id","redaction_policy_revision"],"properties":{"report_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"contract_version":{"type":"integer","minimum":1},"stable_error_code":{"type":"string","minLength":1},"affected_capability":{"type":"string","minLength":1},"redacted_reproduction_steps":{"type":"array","maxItems":64,"items":{"type":"string","minLength":1,"maxLength":4096,"not":{"pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})|(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"}}},"expected_classification":{"type":"string","minLength":1},"actual_classification":{"type":"string","minLength":1},"occurrence_count":{"type":"integer","minimum":1},"content_fingerprint":{"type":"string","pattern":"^[0-9a-f]{64}$"},"consent_event_id":{"type":"string","minLength":1},"redaction_policy_revision":{"type":"string","minLength":1},"proposed_fix":{"type":"string","minLength":1,"maxLength":4096,"not":{"pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})|(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"}},"return_channel":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.lease-receipt.v1","title":"LeaseReceipt","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.lease-receipt.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["claim_request_id","lease_id","lease_epoch","issue_revision","actor_id","scope","expires_at","durable","authority_signature"],"properties":{"claim_request_id":{"type":"string","minLength":1},"lease_id":{"type":"string","minLength":1},"lease_epoch":{"type":"integer","minimum":1},"issue_revision":{"type":"integer","minimum":0},"actor_id":{"type":"string","minLength":1},"scope":{"type":"object"},"expires_at":{"type":"string","format":"date-time"},"durable":{"type":"boolean"},"authority_signature":{"type":"string","minLength":1}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.monitor-event.v1","title":"MonitorEvent","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.monitor-event.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["monitor_id","event_id","sequence","subject_revision","type","actionability","observed_at"],"properties":{"monitor_id":{"type":"string","minLength":1},"event_id":{"type":"string","minLength":1},"sequence":{"type":"integer","minimum":0},"subject_revision":{"type":"string","minLength":1},"type":{"type":"string","minLength":1},"actionability":{"type":"string","enum":["advisory","action_required","terminal"]},"observed_at":{"type":"string","format":"date-time"},"bounded_payload":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"},"artifact_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.monitor-receipt.v1","title":"MonitorReceipt","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.monitor-receipt.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["monitor_id","owner_run_id","terminal_state","terminal_reason","last_sequence","evidence_digest","cancellation_acknowledged","process_cleanup","lease_cleanup"],"properties":{"monitor_id":{"type":"string","minLength":1},"owner_run_id":{"type":"string","minLength":1},"terminal_state":{"type":"string","enum":["PASS","FAIL","INCOMPLETE","CANCELLED"]},"terminal_reason":{"type":"string","minLength":1},"last_sequence":{"type":"integer","minimum":0},"evidence_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"},"cancellation_acknowledged":{"type":"boolean"},"process_cleanup":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"},"lease_cleanup":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"},"undelivered_cursor":{"type":"integer","minimum":0}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.run-receipt.v1","title":"RunReceipt","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.run-receipt.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["packet_hash","run_id","attempt_id","exact_head","packet_revision","manifest_digest","workflow_config_revision","status","executor","started_at","ended_at","evidence_refs","validation","cleanup"],"properties":{"packet_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"run_id":{"type":"string","minLength":1},"attempt_id":{"type":"string","minLength":1},"exact_head":{"type":"string","pattern":"^[0-9a-f]{40}(?:[0-9a-f]{24})?$"},"packet_revision":{"type":"integer","minimum":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"},"workflow_config_revision":{"type":"string","minLength":1},"status":{"type":"string","enum":["PASS","FAIL","INCOMPLETE","NOT_EXECUTED"]},"executor":{"type":"object"},"started_at":{"type":"string","format":"date-time"},"ended_at":{"type":"string","format":"date-time"},"evidence_refs":{"type":"array","items":{"type":"object"}},"validation":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"},"cleanup":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"},"lease_epoch":{"type":"integer","minimum":1},"tokens":{"type":"object"},"retries":{"type":"integer","minimum":0},"corrections":{"type":"integer","minimum":0},"mutations_attempted":{"type":"array","items":{"type":"string"}},"mutations_authorized":{"type":"array","items":{"type":"string"}},"structured_error":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"},"active_time_ms":{"type":"integer","minimum":0},"passive_time_ms":{"type":"integer","minimum":0}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.structured-error.v1","title":"StructuredError","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.structured-error.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["parent_object_hash","error_occurrence_id","code","terminal_classification","safe_details"],"properties":{"parent_object_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"error_occurrence_id":{"type":"string","minLength":1},"code":{"type":"string","minLength":1},"terminal_classification":{"type":"string","enum":["FAIL","INCOMPLETE"]},"safe_details":{"type":"object","maxProperties":64,"x-forge-max-depth":8,"x-forge-max-items":128,"x-forge-max-serialized-bytes":16384,"x-forge-secret-pattern":"(?:gh[pousr]_[A-Za-z0-9]{20,}|sk_(?:live|test)_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{16,}|AKIA[0-9A-Z]{16}|(?:api[_-]?key|token|secret|password)\\s*[:=]\\s*\\S{8,})","x-forge-absolute-user-path-pattern":"(?:[A-Za-z]:\\\\Users\\\\[^\\\\\\s]+|/(?:Users|home)/[^/\\s]+/)"},"retryable":{"type":"boolean"},"evidence_refs":{"type":"array","items":{"type":"object"}}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"forge.memory.work-packet.v1","title":"WorkPacket","type":"object","required":["schema_id","schema_version","object_id","created_at","producer","capabilities_used","provenance","content_hash","payload","extensions"],"properties":{"schema_id":{"const":"forge.memory.work-packet.v1"},"schema_version":{"const":1},"object_id":{"type":"string","format":"uuid"},"created_at":{"type":"string","format":"date-time"},"producer":{"type":"object","required":["product_id","product_version","instance_id"],"properties":{"product_id":{"type":"string","minLength":1},"product_version":{"type":"string","minLength":1},"instance_id":{"type":"string","minLength":1}},"additionalProperties":false},"capabilities_used":{"type":"array","items":{"type":"object","required":["capability_id","manifest_digest"],"properties":{"capability_id":{"type":"string","minLength":1},"manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false}},"provenance":{"type":"object","required":["source_kind","actor_class","actor_id"],"properties":{"source_kind":{"type":"string","minLength":1},"actor_class":{"type":"string","minLength":1},"actor_id":{"type":"string","minLength":1}},"additionalProperties":false},"content_hash":{"type":"string","pattern":"^[0-9a-f]{64}$"},"payload":{"type":"object","required":["issue_id","expected_issue_revision","packet_id","packet_revision","repository_id","target_head","objective","authority","allowed_mutations","workflow_config_revision","capability_manifest_digest"],"properties":{"issue_id":{"type":"string","minLength":1},"expected_issue_revision":{"type":"integer","minimum":0},"packet_id":{"type":"string","minLength":1},"packet_revision":{"type":"integer","minimum":1},"repository_id":{"type":"string","minLength":1},"target_head":{"type":"string","pattern":"^[0-9a-f]{40}(?:[0-9a-f]{24})?$"},"objective":{"type":"string","minLength":1},"authority":{"type":"object","required":["kind","issue_revision"],"properties":{"kind":{"type":"string","minLength":1},"issue_revision":{"type":"integer","minimum":0}}},"allowed_mutations":{"type":"array","items":{"type":"string"}},"workflow_config_revision":{"type":"string","minLength":1},"capability_manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"},"acceptance_criteria":{"type":"array","items":{"type":"string"}},"prohibited_actions":{"type":"array","items":{"type":"string"}},"dependencies":{"type":"array","items":{"type":"string"}},"constraints":{"type":"object"},"risk":{"type":"object"},"platform":{"type":"object"},"context_references":{"type":"array","items":{"type":"object"}},"expected_outputs":{"type":"array","items":{"type":"string"}},"target":{"type":"object"},"receipt_requirements":{"type":"object"},"idempotency_key":{"type":"string","minLength":1},"token_budget":{"type":"integer","minimum":1},"budget_metric":{"type":"string","enum":["provider_reported_total_tokens"]},"risk_manifest_digest":{"type":"string","pattern":"^[0-9a-f]{64}$"}},"additionalProperties":false},"extensions":{"type":"object","propertyNames":{"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*(?:[./][A-Za-z0-9][A-Za-z0-9_-]*)+$","maxLength":255},"additionalProperties":{"type":"object","required":["impact","schema_version","value"],"properties":{"impact":{"const":"advisory"},"schema_version":{"type":"integer","minimum":1},"value":{}},"additionalProperties":false}}},"additionalProperties":false}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { createHash } = require("node:crypto");
|
|
4
|
+
const { readFileSync } = require("node:fs");
|
|
5
|
+
const { join } = require("node:path");
|
|
6
|
+
|
|
7
|
+
const PACKAGE_ROOT = join(__dirname, "..");
|
|
8
|
+
|
|
9
|
+
function sha256File(path) {
|
|
10
|
+
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function verifyContractBaseline() {
|
|
14
|
+
const baseline = JSON.parse(readFileSync(join(PACKAGE_ROOT, "contract-baseline.v1.json"), "utf8"));
|
|
15
|
+
const mismatches = [];
|
|
16
|
+
for (const entry of baseline.artifacts) {
|
|
17
|
+
const actual = sha256File(join(PACKAGE_ROOT, ...entry.path.split("/")));
|
|
18
|
+
if (actual !== entry.sha256) mismatches.push({ path: entry.path, expected: entry.sha256, actual });
|
|
19
|
+
}
|
|
20
|
+
return { ok: mismatches.length === 0, mismatches };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { verifyContractBaseline };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { createHash } = require("node:crypto");
|
|
4
|
+
const { types } = require("node:util");
|
|
5
|
+
|
|
6
|
+
const DEFAULT_LIMITS = Object.freeze({ maxDepth: 64, maxNodes: 100_000, maxBytes: 1_048_576 });
|
|
7
|
+
|
|
8
|
+
class CanonicalizationError extends TypeError {
|
|
9
|
+
constructor(code, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "CanonicalizationError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fail(code, message) {
|
|
17
|
+
throw new CanonicalizationError(code, message);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function assertUnicode(value) {
|
|
21
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
22
|
+
const code = value.charCodeAt(index);
|
|
23
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
24
|
+
const next = value.charCodeAt(index + 1);
|
|
25
|
+
if (!(next >= 0xdc00 && next <= 0xdfff)) fail("CANONICAL_UNICODE", "Canonical JSON rejects unpaired UTF-16 surrogates");
|
|
26
|
+
index += 1;
|
|
27
|
+
} else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
28
|
+
fail("CANONICAL_UNICODE", "Canonical JSON rejects unpaired UTF-16 surrogates");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function limits(options) {
|
|
34
|
+
const resolved = { ...DEFAULT_LIMITS, ...options };
|
|
35
|
+
for (const field of Object.keys(DEFAULT_LIMITS)) {
|
|
36
|
+
if (!Number.isInteger(resolved[field]) || resolved[field] < 1) fail("CANONICAL_INVALID_LIMIT", `${field} must be a positive integer`);
|
|
37
|
+
}
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function append(state, text) {
|
|
42
|
+
state.bytes += Buffer.byteLength(text, "utf8");
|
|
43
|
+
if (state.bytes > state.limits.maxBytes) fail("CANONICAL_BYTE_LIMIT", "Canonical JSON byte limit exceeded");
|
|
44
|
+
return text;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function enter(state, depth) {
|
|
48
|
+
if (depth > state.limits.maxDepth) fail("CANONICAL_DEPTH_LIMIT", "Canonical JSON depth limit exceeded");
|
|
49
|
+
state.nodes += 1;
|
|
50
|
+
if (state.nodes > state.limits.maxNodes) fail("CANONICAL_NODE_LIMIT", "Canonical JSON node limit exceeded");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function descriptorsForPlainObject(value) {
|
|
54
|
+
if (types.isProxy(value)) fail("CANONICAL_PROXY", "Canonical JSON rejects Proxy inputs");
|
|
55
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) fail("CANONICAL_NON_PLAIN", "Canonical JSON requires plain objects");
|
|
56
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
57
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
58
|
+
if (typeof key === "symbol") fail("CANONICAL_SYMBOL", "Canonical JSON rejects symbol keys");
|
|
59
|
+
const descriptor = descriptors[key];
|
|
60
|
+
if (!Object.hasOwn(descriptor, "value")) fail("CANONICAL_ACCESSOR", "Canonical JSON rejects accessors");
|
|
61
|
+
if (!descriptor.enumerable) fail("CANONICAL_NON_ENUMERABLE", "Canonical JSON rejects non-enumerable data properties");
|
|
62
|
+
assertUnicode(key);
|
|
63
|
+
}
|
|
64
|
+
return descriptors;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function descriptorsForArray(value) {
|
|
68
|
+
if (types.isProxy(value)) fail("CANONICAL_PROXY", "Canonical JSON rejects Proxy inputs");
|
|
69
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
70
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
71
|
+
if (typeof key === "symbol") fail("CANONICAL_SYMBOL", "Canonical JSON rejects symbol keys");
|
|
72
|
+
if (key === "length") continue;
|
|
73
|
+
const index = Number(key);
|
|
74
|
+
if (!Number.isInteger(index) || index < 0 || String(index) !== key || index >= value.length) fail("CANONICAL_ARRAY_PROPERTY", "Canonical JSON arrays cannot have named properties");
|
|
75
|
+
const descriptor = descriptors[key];
|
|
76
|
+
if (!Object.hasOwn(descriptor, "value")) fail("CANONICAL_ACCESSOR", "Canonical JSON rejects accessors");
|
|
77
|
+
if (!descriptor.enumerable) fail("CANONICAL_NON_ENUMERABLE", "Canonical JSON rejects non-enumerable array items");
|
|
78
|
+
}
|
|
79
|
+
return descriptors;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function serialize(value, state, depth) {
|
|
83
|
+
enter(state, depth);
|
|
84
|
+
if (value === null || typeof value === "boolean") return append(state, JSON.stringify(value));
|
|
85
|
+
if (typeof value === "string") {
|
|
86
|
+
assertUnicode(value);
|
|
87
|
+
return append(state, JSON.stringify(value));
|
|
88
|
+
}
|
|
89
|
+
if (typeof value === "number") {
|
|
90
|
+
if (!Number.isFinite(value)) fail("CANONICAL_NUMBER", "Canonical JSON requires finite numbers");
|
|
91
|
+
return append(state, JSON.stringify(value));
|
|
92
|
+
}
|
|
93
|
+
if (!value || typeof value !== "object") fail("CANONICAL_TYPE", `Canonical JSON cannot encode ${typeof value}`);
|
|
94
|
+
if (types.isProxy(value)) fail("CANONICAL_PROXY", "Canonical JSON rejects Proxy inputs");
|
|
95
|
+
if (state.active.has(value)) fail("CANONICAL_CYCLE", "Canonical JSON rejects cyclic values");
|
|
96
|
+
|
|
97
|
+
state.active.add(value);
|
|
98
|
+
try {
|
|
99
|
+
if (Array.isArray(value)) {
|
|
100
|
+
const descriptors = descriptorsForArray(value);
|
|
101
|
+
let output = append(state, "[");
|
|
102
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
103
|
+
const descriptor = descriptors[String(index)];
|
|
104
|
+
if (!descriptor) fail("CANONICAL_SPARSE_ARRAY", "Canonical JSON rejects sparse arrays");
|
|
105
|
+
if (index > 0) output += append(state, ",");
|
|
106
|
+
output += serialize(descriptor.value, state, depth + 1);
|
|
107
|
+
}
|
|
108
|
+
return output + append(state, "]");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const descriptors = descriptorsForPlainObject(value);
|
|
112
|
+
const keys = Object.keys(descriptors).sort();
|
|
113
|
+
let output = append(state, "{");
|
|
114
|
+
keys.forEach((key, index) => {
|
|
115
|
+
if (index > 0) output += append(state, ",");
|
|
116
|
+
output += append(state, JSON.stringify(key));
|
|
117
|
+
output += append(state, ":");
|
|
118
|
+
output += serialize(descriptors[key].value, state, depth + 1);
|
|
119
|
+
});
|
|
120
|
+
return output + append(state, "}");
|
|
121
|
+
} finally {
|
|
122
|
+
state.active.delete(value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function canonicalize(value, options = {}) {
|
|
127
|
+
const state = { limits: limits(options), nodes: 0, bytes: 0, active: new WeakSet() };
|
|
128
|
+
return serialize(value, state, 0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function preflightCanonicalValue(value, options = {}) {
|
|
132
|
+
canonicalize(value, options);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function withoutContentHash(value) {
|
|
136
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) fail("CANONICAL_CONTRACT_OBJECT", "Contract object must be a plain JSON object");
|
|
137
|
+
const descriptors = descriptorsForPlainObject(value);
|
|
138
|
+
const copy = {};
|
|
139
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
140
|
+
if (key !== "content_hash") copy[key] = descriptor.value;
|
|
141
|
+
}
|
|
142
|
+
return copy;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function computeContentHash(value, options = {}) {
|
|
146
|
+
return createHash("sha256")
|
|
147
|
+
.update(canonicalize(withoutContentHash(value), options), "utf8")
|
|
148
|
+
.digest("hex");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
module.exports = { CanonicalizationError, canonicalize, computeContentHash, preflightCanonicalValue };
|