@sema-agent/core 7.51.2 → 7.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +698 -2
- package/README.md +3 -1
- package/dist/agents/agent-transcript-tool.d.ts +1 -1
- package/dist/agents/cascade.js +4 -0
- package/dist/agents/cross-session-envelope.d.ts +8 -0
- package/dist/agents/cross-session-envelope.js +6 -0
- package/dist/agents/cross-session-judge.d.ts +21 -1
- package/dist/agents/cross-session-judge.js +8 -0
- package/dist/agents/cross-session-ref.d.ts +5 -0
- package/dist/agents/cross-session-ref.js +1 -0
- package/dist/agents/cumulative-stats.d.ts +3 -0
- package/dist/agents/cumulative-stats.js +3 -0
- package/dist/agents/list-agents-tool.d.ts +1 -1
- package/dist/agents/org-delivery-gate.d.ts +122 -0
- package/dist/agents/org-delivery-gate.js +69 -0
- package/dist/agents/peer-held-queue.d.ts +9 -4
- package/dist/agents/peer-held-queue.js +6 -5
- package/dist/agents/peer-session-drain.d.ts +35 -5
- package/dist/agents/peer-session-drain.js +271 -180
- package/dist/agents/read-inbox-tool.d.ts +8 -1
- package/dist/agents/read-inbox-tool.js +5 -1
- package/dist/agents/repair-loop.js +4 -0
- package/dist/agents/send-message-tool.d.ts +11 -16
- package/dist/agents/send-message-tool.js +11 -13
- package/dist/agents/subagent.d.ts +3 -0
- package/dist/agents/subagent.js +105 -76
- package/dist/agents/tool-filter.d.ts +58 -13
- package/dist/agents/tool-filter.js +34 -14
- package/dist/bench/metrics.d.ts +1 -0
- package/dist/brain/anthropic.d.ts +6 -1
- package/dist/brain/anthropic.js +17 -13
- package/dist/brain/model-presets.d.ts +4 -5
- package/dist/brain/model-presets.js +6 -5
- package/dist/brain/open-responses.js +16 -12
- package/dist/brain/openai.js +16 -12
- package/dist/brain/request-params.d.ts +12 -33
- package/dist/brain/request-params.js +5 -2
- package/dist/brain/request-route.d.ts +9 -8
- package/dist/brain/request-route.js +1 -0
- package/dist/brain/route-adjudicator.d.ts +123 -47
- package/dist/brain/route-adjudicator.js +171 -42
- package/dist/brain/route-conformance.js +2 -2
- package/dist/brain/routing.d.ts +24 -1
- package/dist/brain/routing.js +54 -19
- package/dist/brain/status-sink.d.ts +18 -0
- package/dist/brain/status-sink.js +7 -0
- package/dist/brain/timeout.js +5 -4
- package/dist/core/a2a.d.ts +5 -2
- package/dist/core/a2a.js +30 -13
- package/dist/core/allow-entry.d.ts +42 -9
- package/dist/core/allow-entry.js +25 -18
- package/dist/core/auto-compaction.d.ts +80 -20
- package/dist/core/auto-compaction.js +65 -18
- package/dist/core/auto-promote.d.ts +2 -1
- package/dist/core/auto-promote.js +2 -2
- package/dist/core/caller-tool-name.d.ts +9 -0
- package/dist/core/caller-tool-name.js +13 -0
- package/dist/core/checkpoint-requirements.d.ts +7 -1
- package/dist/core/checkpoint-requirements.js +2 -0
- package/dist/core/checkpoint-store.d.ts +57 -24
- package/dist/core/checkpoint-store.js +3 -3
- package/dist/core/child-clamp-seats.d.ts +6 -0
- package/dist/core/child-clamp-seats.js +2 -1
- package/dist/core/compliance.js +3 -1
- package/dist/core/credential-vocabulary.d.ts +33 -8
- package/dist/core/credential-vocabulary.js +32 -7
- package/dist/core/decision-receipt.d.ts +2 -2
- package/dist/core/delegation-frames.d.ts +9 -2
- package/dist/core/delegation-name.d.ts +18 -0
- package/dist/core/delegation-name.js +47 -0
- package/dist/core/effective-path-target.d.ts +25 -6
- package/dist/core/effective-path-target.js +24 -2
- package/dist/core/engine-capabilities.d.ts +8 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +49 -21
- package/dist/core/frontmatter-fence.d.ts +10 -0
- package/dist/core/frontmatter-fence.js +6 -0
- package/dist/core/gate-fold.js +8 -25
- package/dist/core/gate-lanes.js +358 -274
- package/dist/core/gate-outcome.d.ts +11 -6
- package/dist/core/governance-codes.d.ts +11 -4
- package/dist/core/governance-codes.js +12 -3
- package/dist/core/hands-band-screen.d.ts +7 -0
- package/dist/core/hands-band-screen.js +32 -0
- package/dist/core/hooks.d.ts +283 -739
- package/dist/core/hooks.js +100 -193
- package/dist/{tools/fs → core}/image-admission.d.ts +21 -3
- package/dist/{tools/fs → core}/image-admission.js +24 -6
- package/dist/core/locked-config.d.ts +84 -32
- package/dist/core/locked-config.js +128 -42
- package/dist/core/mcp-connection-pool.d.ts +4 -1
- package/dist/core/mcp-connection-pool.js +7 -2
- package/dist/core/mcp-probe.d.ts +12 -9
- package/dist/core/mcp-probe.js +3 -3
- package/dist/core/mcp-server-spec.d.ts +104 -10
- package/dist/core/mcp-server-spec.js +183 -33
- package/dist/core/mcp.d.ts +31 -20
- package/dist/core/mcp.js +66 -56
- package/dist/core/memory-engine/data-plane.js +5 -1
- package/dist/core/memory-engine/distiller.js +16 -2
- package/dist/core/memory-engine/engine.d.ts +22 -30
- package/dist/core/memory-engine/engine.js +16 -10
- package/dist/core/memory-engine/frontmatter.d.ts +6 -0
- package/dist/core/memory-engine/frontmatter.js +19 -16
- package/dist/core/memory.d.ts +2 -2
- package/dist/core/mode-policy.d.ts +5 -16
- package/dist/core/mode-policy.js +7 -19
- package/dist/core/model-seat.d.ts +4 -1
- package/dist/core/mods/dollar.d.ts +109 -0
- package/dist/core/mods/dollar.js +154 -0
- package/dist/core/mods/host.d.ts +23 -0
- package/dist/core/mods/host.js +21 -0
- package/dist/core/mods/kernel/budget.d.ts +43 -0
- package/dist/core/mods/kernel/budget.js +83 -0
- package/dist/core/mods/kernel/dispatch.d.ts +100 -0
- package/dist/core/mods/kernel/dispatch.js +699 -0
- package/dist/core/mods/kernel/events.d.ts +245 -0
- package/dist/core/mods/kernel/events.js +210 -0
- package/dist/core/mods/kernel/index.d.ts +6 -0
- package/dist/core/mods/kernel/index.js +5 -0
- package/dist/core/mods/kernel/receive.d.ts +94 -0
- package/dist/core/mods/kernel/receive.js +188 -0
- package/dist/core/mods/kernel/registration.d.ts +131 -0
- package/dist/core/mods/kernel/registration.js +102 -0
- package/dist/core/mods/kernel/site-rules.d.ts +149 -0
- package/dist/core/mods/kernel/site-rules.js +296 -0
- package/dist/core/mods/stations.d.ts +344 -0
- package/dist/core/mods/stations.js +437 -0
- package/dist/core/mounted-mcp.d.ts +57 -0
- package/dist/core/mounted-mcp.js +71 -2
- package/dist/core/own-property-receipt.d.ts +13 -0
- package/dist/core/own-property-receipt.js +13 -23
- package/dist/core/parent-spec-seat.d.ts +18 -7
- package/dist/core/parent-spec-seat.js +6 -2
- package/dist/core/path-identity.js +2 -1
- package/dist/core/permission-rule-model.d.ts +58 -9
- package/dist/core/permission-rule-model.js +81 -7
- package/dist/core/permission-rule-org.d.ts +163 -33
- package/dist/core/permission-rule-org.js +205 -71
- package/dist/core/permission-rule-syntax.d.ts +15 -0
- package/dist/core/permission-rule-syntax.js +24 -16
- package/dist/core/permission-rules.d.ts +14 -2
- package/dist/core/permission-rules.js +63 -23
- package/dist/core/prompt-section-seat.d.ts +15 -27
- package/dist/core/prompt-section-seat.js +73 -40
- package/dist/core/protocol-http-auth.d.ts +3 -1
- package/dist/core/protocol-http-auth.js +2 -0
- package/dist/core/reminder-mint.d.ts +2 -2
- package/dist/core/remote-env.d.ts +24 -12
- package/dist/core/remote-env.js +1 -0
- package/dist/core/resume-startup-cause.d.ts +16 -1
- package/dist/core/resume-startup-cause.js +4 -1
- package/dist/core/retention.js +7 -2
- package/dist/core/retired-keys.d.ts +12 -2
- package/dist/core/retired-keys.js +15 -1
- package/dist/core/roles.js +60 -10
- package/dist/core/rule-lane-reads.js +1 -1
- package/dist/core/runner/announce-once-ledger.d.ts +31 -1
- package/dist/core/runner/announce-once-ledger.js +22 -0
- package/dist/core/runner/assemble-result.d.ts +9 -0
- package/dist/core/runner/assemble-result.js +3 -1
- package/dist/core/runner/call-hook-stations.d.ts +23 -27
- package/dist/core/runner/call-hook-stations.js +58 -42
- package/dist/core/runner/caller-stop-gate.d.ts +25 -0
- package/dist/core/runner/caller-stop-gate.js +7 -0
- package/dist/core/runner/compaction-seams.d.ts +8 -22
- package/dist/core/runner/compaction-seams.js +28 -53
- package/dist/core/runner/construction-doors.js +11 -1
- package/dist/core/runner/contracts.d.ts +86 -83
- package/dist/core/runner/credential-origin-seat.d.ts +2 -0
- package/dist/core/runner/credential-origin-seat.js +19 -0
- package/dist/core/runner/extra-body-dropped-seat.d.ts +2 -6
- package/dist/core/runner/gate-exit.d.ts +47 -36
- package/dist/core/runner/gate-exit.js +12 -5
- package/dist/core/runner/image.js +1 -2
- package/dist/core/runner/inline-image.js +1 -1
- package/dist/core/runner/mcp-redial.d.ts +52 -10
- package/dist/core/runner/mcp-redial.js +38 -9
- package/dist/core/runner/notice-seat-input.d.ts +11 -0
- package/dist/core/runner/notice-seat-input.js +1 -0
- package/dist/core/runner/permission-rule-lanes.d.ts +5 -2
- package/dist/core/runner/permission-rule-lanes.js +22 -10
- package/dist/core/runner/person-path-rows.d.ts +3 -1
- package/dist/core/runner/person-path-rows.js +3 -2
- package/dist/core/runner/prepare-acquire-reconcile.js +5 -1
- package/dist/core/runner/prepare-ask-lane.d.ts +5 -7
- package/dist/core/runner/prepare-ask-lane.js +6 -15
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +25 -8
- package/dist/core/runner/prepare-config-doors.d.ts +52 -1
- package/dist/core/runner/prepare-config-doors.js +168 -143
- package/dist/core/runner/prepare-defer-classify.js +7 -11
- package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
- package/dist/core/runner/prepare-delegation-surface.js +7 -5
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -11
- package/dist/core/runner/prepare-gate-stations.js +11 -10
- package/dist/core/runner/prepare-hands-readface.d.ts +1 -1
- package/dist/core/runner/prepare-hands-readface.js +2 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -12
- package/dist/core/runner/prepare-inherited-gate.js +10 -23
- package/dist/core/runner/prepare-listings.d.ts +1 -1
- package/dist/core/runner/prepare-listings.js +4 -2
- package/dist/core/runner/prepare-memory-engine-session.d.ts +0 -6
- package/dist/core/runner/prepare-memory-engine-session.js +20 -7
- package/dist/core/runner/prepare-memory.d.ts +3 -2
- package/dist/core/runner/prepare-memory.js +6 -2
- package/dist/core/runner/prepare-offload-wrappers.d.ts +4 -4
- package/dist/core/runner/prepare-offload-wrappers.js +2 -1
- package/dist/core/runner/prepare-park-ask.js +10 -14
- package/dist/core/runner/prepare-policy-chain.d.ts +17 -15
- package/dist/core/runner/prepare-policy-chain.js +104 -109
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +11 -12
- package/dist/core/runner/prepare-prompt-assembly.d.ts +45 -40
- package/dist/core/runner/prepare-prompt-assembly.js +138 -101
- package/dist/core/runner/prepare-prompt-inputs.d.ts +28 -23
- package/dist/core/runner/prepare-prompt-inputs.js +11 -10
- package/dist/core/runner/prepare-protocol-tools.d.ts +11 -7
- package/dist/core/runner/prepare-protocol-tools.js +20 -13
- package/dist/core/runner/prepare-question-face.d.ts +4 -2
- package/dist/core/runner/prepare-question-face.js +4 -3
- package/dist/core/runner/prepare-safety-scan.js +6 -10
- package/dist/core/runner/prepare-suspend-saga.d.ts +6 -0
- package/dist/core/runner/prepare-suspend-saga.js +7 -5
- package/dist/core/runner/prepare-task.js +41 -23
- package/dist/core/runner/prepare-turn-wiring.d.ts +13 -15
- package/dist/core/runner/prepare-turn-wiring.js +29 -27
- package/dist/core/runner/prepare-wiring-manifest.d.ts +13 -9
- package/dist/core/runner/prepare-wiring-manifest.js +14 -11
- package/dist/core/runner/resume-admission.d.ts +4 -1
- package/dist/core/runner/resume-admission.js +7 -5
- package/dist/core/runner/resume-apply.d.ts +5 -2
- package/dist/core/runner/resume-apply.js +24 -42
- package/dist/core/runner/resume-checkpoint-screen.d.ts +1 -0
- package/dist/core/runner/resume-checkpoint-screen.js +9 -1
- package/dist/core/runner/resume-internals-and-config.d.ts +3 -3
- package/dist/core/runner/resume-internals-and-config.js +3 -8
- package/dist/core/runner/resume-preflight.js +38 -16
- package/dist/core/runner/retired-runner-deps.d.ts +5 -6
- package/dist/core/runner/retired-runner-deps.js +4 -5
- package/dist/core/runner/run-brain-sinks.d.ts +3 -2
- package/dist/core/runner/run-brain-sinks.js +5 -1
- package/dist/core/runner/run-compaction-machinery.d.ts +7 -1
- package/dist/core/runner/run-compaction-machinery.js +7 -33
- package/dist/core/runner/run-harness-handlers.js +4 -2
- package/dist/core/runner/run-identity-wiring.d.ts +3 -1
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +103 -95
- package/dist/core/runner/run-notification-lane.js +1 -0
- package/dist/core/runner/run-recovery-lanes.d.ts +3 -0
- package/dist/core/runner/run-recovery-lanes.js +14 -11
- package/dist/core/runner/run-settle-and-teardown.js +9 -28
- package/dist/core/runner/run-stop-and-final-verify.js +18 -25
- package/dist/core/runner/run-terminal-adoption.d.ts +3 -0
- package/dist/core/runner/run-terminal-adoption.js +34 -22
- package/dist/core/runner/run-tool-mount-facts.js +5 -3
- package/dist/core/runner/run-turn-boundary.js +32 -37
- package/dist/core/runner/runtask.d.ts +6 -7
- package/dist/core/runner/runtask.js +15 -73
- package/dist/core/runner/session-rule-policy.d.ts +5 -5
- package/dist/core/runner/session-rule-policy.js +13 -8
- package/dist/core/runner/side-call-account.d.ts +68 -0
- package/dist/core/runner/side-call-account.js +61 -0
- package/dist/core/runner/skills-seat.d.ts +15 -0
- package/dist/core/runner/skills-seat.js +57 -0
- package/dist/core/runner/stream-halt-verbs.js +12 -17
- package/dist/core/runner/stream-lifecycle-verbs.js +8 -5
- package/dist/core/runner/stream-steer-verb.d.ts +1 -1
- package/dist/core/runner/stream-steer-verb.js +20 -38
- package/dist/core/runner/sub-agent-deny-lists.d.ts +124 -23
- package/dist/core/runner/sub-agent-deny-lists.js +230 -71
- package/dist/core/runner/synthetic-tools.d.ts +5 -2
- package/dist/core/runner/synthetic-tools.js +2 -12
- package/dist/core/runner/tool-end-body.d.ts +5 -6
- package/dist/core/runner/tool-end-body.js +6 -4
- package/dist/core/runner/tool-not-executed.d.ts +15 -0
- package/dist/core/runner/tool-not-executed.js +30 -0
- package/dist/core/runner/tool-occurrence.d.ts +8 -7
- package/dist/core/runner/tool-occurrence.js +5 -5
- package/dist/core/runner/tool-result-media-seat.d.ts +1 -1
- package/dist/core/runner-deps.d.ts +43 -36
- package/dist/core/safety-merge-corpus.js +18 -2
- package/dist/core/secret-env.d.ts +88 -20
- package/dist/core/secret-env.js +192 -38
- package/dist/core/session-policy-store.d.ts +71 -16
- package/dist/core/session-policy-store.js +138 -28
- package/dist/core/session-reconcile.d.ts +4 -0
- package/dist/core/session-reconcile.js +2 -1
- package/dist/core/shell-read-silence.js +3 -32
- package/dist/core/side-query.d.ts +5 -3
- package/dist/core/skill-grant.d.ts +3 -2
- package/dist/core/skill-grant.js +17 -9
- package/dist/core/skills-directory.d.ts +31 -11
- package/dist/core/skills-directory.js +655 -104
- package/dist/core/store-contracts/mailbox-store-contract.js +13 -0
- package/dist/core/task-event.d.ts +49 -3
- package/dist/core/task-notification.js +2 -2
- package/dist/core/task-result.d.ts +8 -0
- package/dist/core/task-spec.d.ts +20 -19
- package/dist/core/task-stream.d.ts +14 -4
- package/dist/core/tighten-task-spec.d.ts +4 -3
- package/dist/core/tighten-task-spec.js +2 -4
- package/dist/core/tool-check-reading.d.ts +74 -0
- package/dist/core/tool-check-reading.js +80 -0
- package/dist/core/tool-policy.d.ts +62 -18
- package/dist/core/tool-policy.js +86 -15
- package/dist/core/tool-registry.d.ts +20 -0
- package/dist/core/tool-registry.js +4 -0
- package/dist/core/tool-spec.d.ts +10 -6
- package/dist/core/tools.js +2 -0
- package/dist/core/trace.d.ts +51 -32
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -1
- package/dist/core/unc-spelling.d.ts +10 -0
- package/dist/core/unc-spelling.js +3 -0
- package/dist/core/untrusted-egress.d.ts +8 -0
- package/dist/core/untrusted-egress.js +4 -1
- package/dist/core/untrusted-text.d.ts +16 -0
- package/dist/core/untrusted-text.js +7 -2
- package/dist/core/user-attachment.d.ts +25 -4
- package/dist/core/user-attachment.js +63 -42
- package/dist/core/wiring-manifest.d.ts +18 -15
- package/dist/core/wiring-manifest.js +2 -2
- package/dist/engine/compaction/utils.js +1 -2
- package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
- package/dist/engine/execution-env/symlink-chain.js +1 -1
- package/dist/engine/harness/agent-harness.d.ts +1 -1
- package/dist/engine/harness/agent-harness.js +5 -4
- package/dist/engine/harness/types.d.ts +20 -16
- package/dist/engine/harness/types.js +7 -1
- package/dist/engine/llm/types.d.ts +12 -7
- package/dist/engine/loop/agent-loop.d.ts +12 -1
- package/dist/engine/loop/agent-loop.js +18 -6
- package/dist/engine/loop/types.d.ts +8 -2
- package/dist/engine/lsp/node-lsp-manager.d.ts +2 -2
- package/dist/engine/session/import-validate.js +3 -10
- package/dist/engine/session/session.d.ts +4 -4
- package/dist/engine/session/session.js +4 -4
- package/dist/index.d.ts +33 -23
- package/dist/index.js +23 -15
- package/dist/internal/harness.d.ts +2 -1
- package/dist/internal/harness.js +2 -1
- package/dist/orchestration/goal.d.ts +24 -1
- package/dist/orchestration/goal.js +3 -2
- package/dist/orchestration/run-spec.d.ts +4 -6
- package/dist/orchestration/run-spec.js +39 -63
- package/dist/orchestration/run-workflow-tool.js +1 -2
- package/dist/orchestration/workflow.d.ts +11 -3
- package/dist/orchestration/workflow.js +11 -2
- package/dist/prompt-assembly/artifact-store.d.ts +72 -56
- package/dist/prompt-assembly/artifact-store.js +60 -52
- package/dist/prompt-assembly/artifact.d.ts +90 -76
- package/dist/prompt-assembly/artifact.js +197 -145
- package/dist/prompt-assembly/assemble.d.ts +36 -29
- package/dist/prompt-assembly/assemble.js +34 -220
- package/dist/prompt-assembly/bands.d.ts +20 -0
- package/dist/prompt-assembly/bands.js +18 -0
- package/dist/prompt-assembly/catalog/constitution.d.ts +23 -0
- package/dist/prompt-assembly/catalog/constitution.js +69 -0
- package/dist/prompt-assembly/catalog/core-behavior.d.ts +9 -0
- package/dist/prompt-assembly/catalog/core-behavior.js +85 -0
- package/dist/prompt-assembly/catalog/index.d.ts +11 -0
- package/dist/prompt-assembly/catalog/index.js +60 -0
- package/dist/prompt-assembly/catalog/memory.d.ts +13 -0
- package/dist/prompt-assembly/catalog/memory.js +6 -0
- package/dist/prompt-assembly/catalog/modes.d.ts +15 -0
- package/dist/prompt-assembly/catalog/modes.js +137 -0
- package/dist/prompt-assembly/catalog/role.d.ts +10 -0
- package/dist/prompt-assembly/catalog/role.js +157 -0
- package/dist/prompt-assembly/catalog/schema.d.ts +138 -0
- package/dist/prompt-assembly/catalog/schema.js +25 -0
- package/dist/prompt-assembly/catalog/sections.d.ts +9 -0
- package/dist/prompt-assembly/catalog/sections.js +98 -0
- package/dist/prompt-assembly/catalog/team.d.ts +4 -0
- package/dist/prompt-assembly/catalog/team.js +258 -0
- package/dist/prompt-assembly/composer.d.ts +26 -28
- package/dist/prompt-assembly/composer.js +124 -46
- package/dist/prompt-assembly/epoch.d.ts +89 -79
- package/dist/prompt-assembly/epoch.js +115 -142
- package/dist/prompt-assembly/explain.d.ts +58 -34
- package/dist/prompt-assembly/explain.js +21 -24
- package/dist/prompt-assembly/overlay.d.ts +137 -0
- package/dist/prompt-assembly/overlay.js +339 -0
- package/dist/prompt-assembly/renderers.d.ts +21 -0
- package/dist/prompt-assembly/renderers.js +39 -0
- package/dist/prompt-assembly/section-usage.d.ts +3 -3
- package/dist/prompt-assembly/section-usage.js +1 -1
- package/dist/prompt-assembly/select.d.ts +71 -0
- package/dist/prompt-assembly/select.js +106 -0
- package/dist/prompt-assembly/sugar.d.ts +31 -0
- package/dist/prompt-assembly/sugar.js +20 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +3 -2
- package/dist/prompt-assembly/types.d.ts +45 -148
- package/dist/prompts/coordinator.d.ts +2 -21
- package/dist/prompts/coordinator.js +3 -255
- package/dist/prompts/cowork.d.ts +27 -16
- package/dist/prompts/cowork.js +2 -23
- package/dist/prompts/default.d.ts +38 -511
- package/dist/prompts/default.js +20 -288
- package/dist/prompts/supervisor.d.ts +6 -71
- package/dist/prompts/supervisor.js +6 -117
- package/dist/stores/file/permission-rule-store.d.ts +1 -1
- package/dist/stores/file/permission-rule-store.js +2 -1
- package/dist/tools/artifact/artifact-tool.js +4 -3
- package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -5
- package/dist/tools/fs/dir-entries.d.ts +4 -2
- package/dist/tools/fs/dir-entries.js +16 -4
- package/dist/tools/fs/fs-bash.d.ts +1 -1
- package/dist/tools/fs/fs-bash.js +22 -11
- package/dist/tools/fs/fs-pdf.js +17 -13
- package/dist/tools/fs/fs-read.js +4 -3
- package/dist/tools/fs/fs-shared.d.ts +1 -10
- package/dist/tools/fs/fs-shared.js +3 -4
- package/dist/tools/fs/fs-write.js +2 -1
- package/dist/tools/fs/notebook.js +1 -1
- package/dist/tools/fs/pdf.d.ts +20 -10
- package/dist/tools/fs/pdf.js +19 -10
- package/dist/tools/fs/program-read-model.d.ts +68 -8
- package/dist/tools/fs/program-read-model.js +112 -33
- package/dist/tools/fs/program-read-model.rows.js +30 -10
- package/dist/tools/fs/read-deny-home.d.ts +25 -9
- package/dist/tools/fs/read-deny-home.js +28 -27
- package/dist/tools/fs/read-deny.d.ts +41 -11
- package/dist/tools/fs/read-deny.js +51 -5
- package/dist/tools/fs/safety.d.ts +4 -26
- package/dist/tools/fs/safety.js +10 -32
- package/dist/tools/fs/search.js +15 -10
- package/dist/tools/fs/shell-read-argv.d.ts +3 -2
- package/dist/tools/fs/shell-read-argv.js +118 -38
- package/dist/tools/fs/shell-read-establish.d.ts +5 -5
- package/dist/tools/fs/shell-read-establish.js +11 -61
- package/dist/tools/fs/shell-read-identity.js +6 -3
- package/dist/tools/fs/shell-read-judge.d.ts +13 -15
- package/dist/tools/fs/shell-read-judge.js +18 -4
- package/dist/tools/fs/shell-read-plan.d.ts +2 -2
- package/dist/tools/web.js +1 -1
- package/package.json +13 -1
- package/test/export-surface.snapshot.json +306 -103
- package/wire-changes/core@7.52.0.json +5859 -0
- package/wire-changes/core@7.53.0.json +1946 -0
- package/dist/core/hook-seats.d.ts +0 -66
- package/dist/core/hook-seats.js +0 -37
- package/dist/prompt-assembly/packs/sema-default.d.ts +0 -2
- package/dist/prompt-assembly/packs/sema-default.js +0 -147
- package/dist/prompts/simple-sections.d.ts +0 -58
- package/dist/prompts/simple-sections.js +0 -43
|
@@ -1,92 +1,106 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { type OverlayOp, type PromptTrait } from "./catalog/schema.js";
|
|
2
|
+
import { type PromptOverlay, type SourcedOverlay } from "./overlay.js";
|
|
3
|
+
/** What an artifact needs from the engine that composes it: the targets it names (each with what kind of target it
|
|
4
|
+
* is), the operations it uses, the traits its `when` conditions read, and the bindings they name. */
|
|
5
|
+
export interface PromptArtifactRequires {
|
|
6
|
+
readonly targets: readonly {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly kind: "message" | "section" | "band";
|
|
9
|
+
}[];
|
|
10
|
+
readonly ops: readonly OverlayOp[];
|
|
11
|
+
readonly traits: readonly PromptTrait[];
|
|
12
|
+
readonly bindings: readonly string[];
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
/** Why the artifact exists: an intent sentence (required) and references to the evaluations or goldens behind it. */
|
|
15
|
+
export interface PromptArtifactEvidence {
|
|
16
|
+
readonly intent: string;
|
|
17
|
+
readonly refs: readonly string[];
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
/** The digested part of an artifact. */
|
|
20
|
+
export interface PromptArtifactPayload {
|
|
21
|
+
readonly schemaVersion: 3;
|
|
22
|
+
readonly requires: PromptArtifactRequires;
|
|
23
|
+
/** Every overlay is of the `center` class; one with no `when.binding` applies under every binding. */
|
|
24
|
+
readonly overlays: readonly PromptOverlay[];
|
|
25
|
+
readonly evidence: PromptArtifactEvidence;
|
|
23
26
|
}
|
|
24
|
-
/**
|
|
25
|
-
export interface
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
/** An artifact's identity: the payload and its digest (what a session pins and a store holds by digest). */
|
|
28
|
+
export interface PromptArtifact {
|
|
29
|
+
readonly payload: PromptArtifactPayload;
|
|
30
|
+
readonly artifactDigest: string;
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
catalogDigest: string;
|
|
33
|
-
compatibleCore?: CoreCompatRange;
|
|
34
|
-
closure: PromptDependencyClosure;
|
|
32
|
+
/** The published form: the artifact plus its opaque source revision (never ordered, never compared for recency). */
|
|
33
|
+
export interface PublishedPromptArtifact extends PromptArtifact {
|
|
34
|
+
readonly sourceRevision: string;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
readonly maxTotalBytes: 131072;
|
|
54
|
-
readonly maxIdLength: 128;
|
|
55
|
-
readonly maxPackIdLength: 200;
|
|
56
|
-
};
|
|
57
|
-
export declare function sha256Hex(text: string): string;
|
|
58
|
-
export declare function computeCatalogDigest(catalog: PromptCatalogSnapshot): string;
|
|
59
|
-
export declare function computeArtifactDigest(payload: PromptEpochArtifactPayload): string;
|
|
36
|
+
/** Validator bounds: they bound abuse and runaway publishes, not legitimate artifacts. A `…Chars` bound counts Unicode
|
|
37
|
+
* code points (`codePointsOver`, the verifier's one character unit); a `…Bytes` bound counts UTF-8 bytes. */
|
|
38
|
+
export declare const ARTIFACT_LIMITS: Readonly<{
|
|
39
|
+
maxOverlays: 64;
|
|
40
|
+
maxOverlayTextBytes: 32000;
|
|
41
|
+
maxTotalTextBytes: 131072;
|
|
42
|
+
maxIntentChars: 2000;
|
|
43
|
+
maxRefs: 32;
|
|
44
|
+
maxRefChars: 500;
|
|
45
|
+
maxSourceRevisionChars: 500;
|
|
46
|
+
}>;
|
|
47
|
+
export declare function computeArtifactDigest(payload: PromptArtifactPayload): string;
|
|
48
|
+
/** The requirement set an overlay list implies — the one derivation the builder stores and the verifier recomputes. */
|
|
49
|
+
export declare function requiresOf(overlays: readonly PromptOverlay[]): PromptArtifactRequires;
|
|
50
|
+
/** The requirements this engine does not meet (empty ⇒ all met): a target its catalog lacks, an op or a trait outside
|
|
51
|
+
* its vocabulary. Bindings are the deployment's open vocabulary and are always met. */
|
|
52
|
+
export declare function unmetRequirements(requires: PromptArtifactRequires): string[];
|
|
60
53
|
export type ArtifactVerifyResult = {
|
|
61
54
|
ok: true;
|
|
62
|
-
artifact:
|
|
55
|
+
artifact: PublishedPromptArtifact;
|
|
56
|
+
} | {
|
|
57
|
+
ok: false;
|
|
58
|
+
code: ArtifactVerifyCode;
|
|
59
|
+
reason: string;
|
|
60
|
+
};
|
|
61
|
+
type BodyVerifyResult = {
|
|
62
|
+
ok: true;
|
|
63
|
+
artifact: PromptArtifact;
|
|
63
64
|
} | {
|
|
64
65
|
ok: false;
|
|
65
|
-
code:
|
|
66
|
+
code: ArtifactVerifyCode;
|
|
66
67
|
reason: string;
|
|
67
68
|
};
|
|
69
|
+
/** Why an artifact is invalid (docs/CLOSED-SETS.md). */
|
|
70
|
+
export type ArtifactVerifyCode = "shape" | "schema" | "limits" | "requires" | "overlay" | "evidence" | "digest";
|
|
68
71
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
+
* Verify an UNTRUSTED published artifact (a network body or stored bytes — a store re-verifies on read). Pure. Any
|
|
73
|
+
* failure invalidates the whole artifact: shape, schema version, bounds, each overlay under the center class's band
|
|
74
|
+
* columns and the locked-text guard, the stored requirement list (recomputed, then checked against this engine),
|
|
75
|
+
* same-target replace conflicts, the evidence rule, and the digest.
|
|
72
76
|
*/
|
|
73
|
-
export declare function verifyPromptArtifact(raw: unknown
|
|
74
|
-
engineVersion: string;
|
|
75
|
-
}): ArtifactVerifyResult;
|
|
77
|
+
export declare function verifyPromptArtifact(raw: unknown): ArtifactVerifyResult;
|
|
76
78
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
+
* The same verifier over an artifact without its provenance — what a run re-checks when it adopts an artifact from
|
|
80
|
+
* its source (a candidate, a pinned digest, a parent's layer): requirements are met by THIS engine, every overlay is
|
|
81
|
+
* legal here, the digest holds. A source is a deployment seat; what it hands the run is checked, not trusted.
|
|
79
82
|
*/
|
|
80
|
-
export declare function
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
export declare function verifyPromptArtifactBody(raw: unknown): BodyVerifyResult;
|
|
84
|
+
/** The center layer a run composes under: the adopted artifact and, when the source stamped one, its revision. */
|
|
85
|
+
export type CenterAdoption = {
|
|
86
|
+
artifact: PromptArtifact;
|
|
87
|
+
sourceRevision?: string;
|
|
88
|
+
};
|
|
89
|
+
/** The center class's overlays for an adopted artifact, in the artifact's order. Which of them apply to a run is their
|
|
90
|
+
* `when` (the binding included), read where every class's is — at the composition. */
|
|
91
|
+
export declare function centerOverlaysOf(adoption: CenterAdoption | undefined): readonly SourcedOverlay[];
|
|
92
|
+
/** An artifact a source handed a run, re-checked by this engine before the run adopts it; undefined when it fails. */
|
|
93
|
+
export declare function adoptCenter(artifact: PromptArtifact, sourceRevision: string | undefined): CenterAdoption | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Build a published artifact from overlays and evidence — the one builder (a center's publish pipeline calls it):
|
|
96
|
+
* `requires` is derived, the digest computed over the payload's JSON form (what travels) with each overlay as the
|
|
97
|
+
* overlay door leaves it (its `when` in normal form, so one meaning is one digest), and the result goes through the
|
|
98
|
+
* verifier, so the caller holds either a valid artifact or the reason it is not one. An overlay the door refuses goes on
|
|
99
|
+
* as it was given: the verifier names it, in its own order of checks.
|
|
100
|
+
*/
|
|
101
|
+
export declare function buildPromptArtifact(opts: {
|
|
102
|
+
overlays: readonly PromptOverlay[];
|
|
103
|
+
evidence: PromptArtifactEvidence;
|
|
90
104
|
sourceRevision: string;
|
|
91
|
-
|
|
92
|
-
}
|
|
105
|
+
}): ArtifactVerifyResult;
|
|
106
|
+
export {};
|
|
@@ -1,169 +1,221 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { isBandId } from "./bands.js";
|
|
3
|
+
import { SEMA_DEFAULT_CATALOG } from "./catalog/index.js";
|
|
4
|
+
import { OVERLAY_OPS, PROMPT_TRAITS, isWordOf } from "./catalog/schema.js";
|
|
2
5
|
import { canonical } from "./epoch.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import { codePointsOver, sectionOfMessage, validateOverlay } from "./overlay.js";
|
|
7
|
+
export const ARTIFACT_LIMITS = Object.freeze({
|
|
8
|
+
maxOverlays: 64,
|
|
9
|
+
maxOverlayTextBytes: 32_000,
|
|
10
|
+
maxTotalTextBytes: 131_072,
|
|
11
|
+
maxIntentChars: 2_000,
|
|
12
|
+
maxRefs: 32,
|
|
13
|
+
maxRefChars: 500,
|
|
14
|
+
maxSourceRevisionChars: 500,
|
|
15
|
+
});
|
|
11
16
|
const DIGEST_RE = /^sha256:[0-9a-f]{64}$/;
|
|
12
|
-
const
|
|
13
|
-
|
|
17
|
+
const MESSAGE_IDS = new Set(SEMA_DEFAULT_CATALOG.messages.map((m) => m.id));
|
|
18
|
+
const SECTION_IDS = new Set(SEMA_DEFAULT_CATALOG.sections.map((s) => s.id));
|
|
19
|
+
function sha256Hex(text) {
|
|
14
20
|
return `sha256:${createHash("sha256").update(text, "utf8").digest("hex")}`;
|
|
15
21
|
}
|
|
16
|
-
export function computeCatalogDigest(catalog) {
|
|
17
|
-
return sha256Hex(canonical(catalog));
|
|
18
|
-
}
|
|
19
22
|
export function computeArtifactDigest(payload) {
|
|
20
23
|
return sha256Hex(canonical(payload));
|
|
21
24
|
}
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
export function requiresOf(overlays) {
|
|
26
|
+
const targets = new Map();
|
|
27
|
+
const need = (id, kind) => {
|
|
28
|
+
targets.set(`${kind}:${id}`, { id, kind });
|
|
29
|
+
};
|
|
30
|
+
const ops = new Set();
|
|
31
|
+
const traits = new Set();
|
|
32
|
+
const bindings = new Set();
|
|
33
|
+
for (const o of overlays) {
|
|
34
|
+
ops.add(o.op);
|
|
35
|
+
need(o.target, o.op === "add" ? "band" : o.op === "drop" ? "section" : "message");
|
|
36
|
+
if (o.message !== undefined)
|
|
37
|
+
need(o.message, "message");
|
|
38
|
+
for (const t of [...(o.when?.traits?.allOf ?? []), ...(o.when?.traits?.noneOf ?? [])])
|
|
39
|
+
traits.add(t);
|
|
40
|
+
for (const b of [...(o.when?.binding?.anyOf ?? []), ...(o.when?.binding?.noneOf ?? [])])
|
|
41
|
+
bindings.add(b);
|
|
42
|
+
}
|
|
43
|
+
const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
44
|
+
return {
|
|
45
|
+
targets: [...targets.values()].sort((a, b) => byText(`${a.kind}:${a.id}`, `${b.kind}:${b.id}`)),
|
|
46
|
+
ops: OVERLAY_OPS.filter((op) => ops.has(op)),
|
|
47
|
+
traits: PROMPT_TRAITS.filter((t) => traits.has(t)),
|
|
48
|
+
bindings: [...bindings].sort(byText),
|
|
49
|
+
};
|
|
27
50
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
export function unmetRequirements(requires) {
|
|
52
|
+
const unmet = [];
|
|
53
|
+
for (const t of requires.targets) {
|
|
54
|
+
const has = t.kind === "message" ? MESSAGE_IDS.has(t.id) : t.kind === "section" ? SECTION_IDS.has(t.id) : isBandId(t.id);
|
|
55
|
+
if (!has)
|
|
56
|
+
unmet.push(`${t.kind} "${t.id}"`);
|
|
32
57
|
}
|
|
33
|
-
|
|
58
|
+
for (const op of requires.ops)
|
|
59
|
+
if (!isWordOf(OVERLAY_OPS, op))
|
|
60
|
+
unmet.push(`op "${String(op)}"`);
|
|
61
|
+
for (const tr of requires.traits)
|
|
62
|
+
if (!isWordOf(PROMPT_TRAITS, tr))
|
|
63
|
+
unmet.push(`trait "${String(tr)}"`);
|
|
64
|
+
return unmet;
|
|
34
65
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
66
|
+
function isRecord(v) {
|
|
67
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
68
|
+
}
|
|
69
|
+
function requiresShaped(v) {
|
|
70
|
+
if (!isRecord(v))
|
|
71
|
+
return false;
|
|
72
|
+
const strings = (a) => Array.isArray(a) && a.every((s) => typeof s === "string");
|
|
73
|
+
return (Object.keys(v).every((k) => k === "targets" || k === "ops" || k === "traits" || k === "bindings") &&
|
|
74
|
+
Array.isArray(v.targets) &&
|
|
75
|
+
v.targets.every((t) => isRecord(t) && typeof t.id === "string" && (t.kind === "message" || t.kind === "section" || t.kind === "band") && Object.keys(t).every((k) => k === "id" || k === "kind")) &&
|
|
76
|
+
strings(v.ops) &&
|
|
77
|
+
strings(v.traits) &&
|
|
78
|
+
strings(v.bindings));
|
|
79
|
+
}
|
|
80
|
+
const bindingListOf = (b) => {
|
|
81
|
+
if (b === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
const names = b.anyOf !== undefined ? b.anyOf : b.noneOf;
|
|
84
|
+
return { anyOf: b.anyOf !== undefined, names, set: new Set(names) };
|
|
85
|
+
};
|
|
86
|
+
function bindingsMeet(a, b) {
|
|
87
|
+
if (a === undefined || b === undefined)
|
|
88
|
+
return true;
|
|
89
|
+
if (a.anyOf && b.anyOf)
|
|
90
|
+
return a.names.some((x) => b.set.has(x));
|
|
91
|
+
if (a.anyOf)
|
|
92
|
+
return a.names.some((x) => !b.set.has(x));
|
|
93
|
+
if (b.anyOf)
|
|
94
|
+
return b.names.some((x) => !a.set.has(x));
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
function replaceConflict(overlays) {
|
|
98
|
+
const groups = new Map();
|
|
99
|
+
for (const o of overlays) {
|
|
100
|
+
if (o.op !== "replace")
|
|
101
|
+
continue;
|
|
102
|
+
const { binding, ...rest } = o.when ?? {};
|
|
103
|
+
const key = canonical({ target: o.target, when: rest });
|
|
104
|
+
groups.set(key, [...(groups.get(key) ?? []), { o, list: bindingListOf(binding) }]);
|
|
42
105
|
}
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (payload.assemblyApi !== 1)
|
|
52
|
-
return fail("schema", `unsupported assemblyApi ${String(payload.assemblyApi)}`);
|
|
53
|
-
if (typeof payload.catalogDigest !== "string" || !DIGEST_RE.test(payload.catalogDigest))
|
|
54
|
-
return fail("shape", "catalogDigest malformed");
|
|
55
|
-
let compatibleCore;
|
|
56
|
-
if (payload.compatibleCore !== undefined) {
|
|
57
|
-
const cc = payload.compatibleCore;
|
|
58
|
-
if (cc === null || typeof cc !== "object")
|
|
59
|
-
return fail("shape", "compatibleCore malformed");
|
|
60
|
-
compatibleCore = {};
|
|
61
|
-
for (const key of ["minCore", "maxCoreExclusive"]) {
|
|
62
|
-
const v = cc[key];
|
|
63
|
-
if (v === undefined)
|
|
64
|
-
continue;
|
|
65
|
-
if (typeof v !== "string" || triple(v) === undefined)
|
|
66
|
-
return fail("shape", `compatibleCore.${key} is not a dotted triple`);
|
|
67
|
-
compatibleCore[key] = v;
|
|
68
|
-
}
|
|
69
|
-
const engine = triple(opts.engineVersion);
|
|
70
|
-
if (engine === undefined)
|
|
71
|
-
return fail("core-range", `engine version "${opts.engineVersion}" is not a dotted triple`);
|
|
72
|
-
if (compatibleCore.minCore !== undefined && tripleCmp(engine, triple(compatibleCore.minCore)) < 0) {
|
|
73
|
-
return fail("core-range", `engine ${opts.engineVersion} < minCore ${compatibleCore.minCore}`);
|
|
106
|
+
for (const group of groups.values()) {
|
|
107
|
+
for (let i = 0; i < group.length; i++) {
|
|
108
|
+
for (let j = i + 1; j < group.length; j++) {
|
|
109
|
+
const [{ o: p, list: pl }, { o: q, list: ql }] = [group[i], group[j]];
|
|
110
|
+
if (bindingsMeet(pl, ql)) {
|
|
111
|
+
return `overlays "${p.id}" and "${q.id}" both replace "${p.target}" under one condition that can hold in the same run (write exclusive binding conditions: "noneOf": [x] beside "anyOf": [x])`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
74
114
|
}
|
|
75
|
-
if (compatibleCore.maxCoreExclusive !== undefined && tripleCmp(engine, triple(compatibleCore.maxCoreExclusive)) >= 0) {
|
|
76
|
-
return fail("core-range", `engine ${opts.engineVersion} >= maxCoreExclusive ${compatibleCore.maxCoreExclusive}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const closure = payload.closure;
|
|
80
|
-
if (closure === null || typeof closure !== "object")
|
|
81
|
-
return fail("shape", "closure is not an object");
|
|
82
|
-
if (closure.basePackId !== "sema-default@1") {
|
|
83
|
-
return fail("base-pack", `unsupported basePackId ${JSON.stringify(closure.basePackId).slice(0, 120)} (v1: bundled base only)`);
|
|
84
115
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
return
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
export function verifyPromptArtifact(raw) {
|
|
119
|
+
if (!isRecord(raw))
|
|
120
|
+
return { ok: false, code: "shape", reason: "the published artifact is not an object" };
|
|
121
|
+
if (typeof raw.sourceRevision !== "string" || raw.sourceRevision.length === 0 || codePointsOver(raw.sourceRevision, ARTIFACT_LIMITS.maxSourceRevisionChars)) {
|
|
122
|
+
return { ok: false, code: "shape", reason: `sourceRevision missing or over ${ARTIFACT_LIMITS.maxSourceRevisionChars} characters (code points)` };
|
|
90
123
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
124
|
+
const v = verifyPromptArtifactBody(raw);
|
|
125
|
+
return v.ok ? { ok: true, artifact: { ...v.artifact, sourceRevision: raw.sourceRevision } } : v;
|
|
126
|
+
}
|
|
127
|
+
export function verifyPromptArtifactBody(raw) {
|
|
128
|
+
const fail = (code, reason) => ({ ok: false, code, reason });
|
|
129
|
+
if (!isRecord(raw))
|
|
130
|
+
return fail("shape", "the artifact is not an object");
|
|
131
|
+
for (const k of Object.keys(raw))
|
|
132
|
+
if (k !== "payload" && k !== "artifactDigest" && k !== "sourceRevision")
|
|
133
|
+
return fail("shape", `the artifact carries ${JSON.stringify(k).slice(0, 60)}`);
|
|
134
|
+
if (typeof raw.artifactDigest !== "string" || !DIGEST_RE.test(raw.artifactDigest))
|
|
135
|
+
return fail("shape", "artifactDigest malformed");
|
|
136
|
+
const payload = raw.payload;
|
|
137
|
+
if (!isRecord(payload))
|
|
138
|
+
return fail("shape", "payload is not an object");
|
|
139
|
+
if (payload.schemaVersion !== 3) {
|
|
140
|
+
const republish = payload.schemaVersion === 2 ? `; republish under schemaVersion 3 — an overlay's "scope": { "binding": b } becomes "when": { "binding": { "anyOf": [b] } }` : "";
|
|
141
|
+
return fail("schema", `unsupported schemaVersion ${JSON.stringify(payload.schemaVersion)?.slice(0, 40)} (this engine reads schemaVersion 3 only${republish})`);
|
|
97
142
|
}
|
|
98
|
-
const
|
|
143
|
+
for (const k of Object.keys(payload))
|
|
144
|
+
if (k !== "schemaVersion" && k !== "requires" && k !== "overlays" && k !== "evidence")
|
|
145
|
+
return fail("shape", `payload carries ${JSON.stringify(k).slice(0, 60)}`);
|
|
146
|
+
if (!Array.isArray(payload.overlays))
|
|
147
|
+
return fail("shape", "overlays is not an array");
|
|
148
|
+
if (payload.overlays.length === 0)
|
|
149
|
+
return fail("shape", "overlays is empty — publish at least one overlay, or disable the source instead");
|
|
150
|
+
if (payload.overlays.length > ARTIFACT_LIMITS.maxOverlays)
|
|
151
|
+
return fail("limits", `${payload.overlays.length} overlays > max ${ARTIFACT_LIMITS.maxOverlays}`);
|
|
152
|
+
const requires = payload.requires;
|
|
153
|
+
if (!requiresShaped(requires))
|
|
154
|
+
return fail("shape", "requires is not { targets: { id, kind }[], ops: string[], traits: string[], bindings: string[] }");
|
|
155
|
+
const unmet = unmetRequirements(requires);
|
|
156
|
+
if (unmet.length > 0)
|
|
157
|
+
return fail("requires", `this engine does not meet the artifact's requirements: ${unmet.slice(0, 6).join(", ")}${unmet.length > 6 ? ` and ${unmet.length - 6} more` : ""}`);
|
|
158
|
+
const overlays = [];
|
|
99
159
|
let totalBytes = 0;
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
return fail("
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
|
|
160
|
+
for (const rawOverlay of payload.overlays) {
|
|
161
|
+
const v = validateOverlay(rawOverlay, { source: "center" });
|
|
162
|
+
if ("violation" in v)
|
|
163
|
+
return fail("overlay", v.violation);
|
|
164
|
+
const text = v.overlay.text;
|
|
165
|
+
if (text !== undefined) {
|
|
166
|
+
const bytes = Buffer.byteLength(text, "utf8");
|
|
167
|
+
if (bytes > ARTIFACT_LIMITS.maxOverlayTextBytes)
|
|
168
|
+
return fail("limits", `overlay "${v.overlay.id}" text ${bytes} bytes > max ${ARTIFACT_LIMITS.maxOverlayTextBytes}`);
|
|
169
|
+
totalBytes += bytes;
|
|
107
170
|
}
|
|
108
|
-
|
|
109
|
-
return fail("shape", `duplicate section id "${s.id}"`);
|
|
110
|
-
ids.add(s.id);
|
|
111
|
-
if (typeof s.slot !== "string" || !SLOTS.has(s.slot))
|
|
112
|
-
return fail("shape", `unknown slot ${JSON.stringify(s.slot).slice(0, 60)} ("${s.id}")`);
|
|
113
|
-
if (typeof s.text !== "string" || s.text.length === 0)
|
|
114
|
-
return fail("shape", `empty/missing text ("${s.id}")`);
|
|
115
|
-
const bytes = Buffer.byteLength(s.text, "utf8");
|
|
116
|
-
if (bytes > ARTIFACT_LIMITS.maxSectionBytes)
|
|
117
|
-
return fail("limits", `section "${s.id}" ${bytes} bytes > max ${ARTIFACT_LIMITS.maxSectionBytes}`);
|
|
118
|
-
totalBytes += bytes;
|
|
119
|
-
if (typeof s.contentHash !== "string" || !DIGEST_RE.test(s.contentHash))
|
|
120
|
-
return fail("shape", `contentHash missing/malformed ("${s.id}")`);
|
|
121
|
-
if (s.contentHash !== sha256Hex(s.text))
|
|
122
|
-
return fail("content-hash", `contentHash does not match text ("${s.id}")`);
|
|
123
|
-
sections.push({ id: s.id, slot: s.slot, text: s.text, contentHash: s.contentHash });
|
|
171
|
+
overlays.push(v.overlay);
|
|
124
172
|
}
|
|
125
|
-
if (totalBytes > ARTIFACT_LIMITS.
|
|
126
|
-
return fail("limits", `
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (computeCatalogDigest(normalizedCatalog) !== payload.catalogDigest) {
|
|
136
|
-
return fail("digest", "catalogDigest does not match canonical(promptCatalog)");
|
|
173
|
+
if (totalBytes > ARTIFACT_LIMITS.maxTotalTextBytes)
|
|
174
|
+
return fail("limits", `overlay text ${totalBytes} bytes > max ${ARTIFACT_LIMITS.maxTotalTextBytes}`);
|
|
175
|
+
if (canonical(requiresOf(overlays)) !== canonical(requires))
|
|
176
|
+
return fail("requires", "requires differs from what the overlays require (build the artifact with buildPromptArtifact)");
|
|
177
|
+
const conflict = replaceConflict(overlays);
|
|
178
|
+
if (conflict !== undefined)
|
|
179
|
+
return fail("overlay", conflict);
|
|
180
|
+
const evidence = payload.evidence;
|
|
181
|
+
if (!isRecord(evidence) || typeof evidence.intent !== "string" || evidence.intent.trim() === "" || codePointsOver(evidence.intent, ARTIFACT_LIMITS.maxIntentChars)) {
|
|
182
|
+
return fail("evidence", `evidence.intent is a non-blank string of at most ${ARTIFACT_LIMITS.maxIntentChars} characters (code points)`);
|
|
137
183
|
}
|
|
138
|
-
if (
|
|
139
|
-
return fail("
|
|
140
|
-
if (computeArtifactDigest(normalizedPayload) !== art.artifactDigest) {
|
|
141
|
-
return fail("digest", "artifactDigest does not match canonical(payload)");
|
|
184
|
+
if (!Array.isArray(evidence.refs) || evidence.refs.length > ARTIFACT_LIMITS.maxRefs || evidence.refs.some((r) => typeof r !== "string" || r.trim() === "" || codePointsOver(r, ARTIFACT_LIMITS.maxRefChars))) {
|
|
185
|
+
return fail("evidence", `evidence.refs is a list of at most ${ARTIFACT_LIMITS.maxRefs} non-blank references of at most ${ARTIFACT_LIMITS.maxRefChars} characters (code points) each`);
|
|
142
186
|
}
|
|
143
|
-
|
|
187
|
+
for (const k of Object.keys(evidence))
|
|
188
|
+
if (k !== "intent" && k !== "refs")
|
|
189
|
+
return fail("shape", `evidence carries ${JSON.stringify(k).slice(0, 60)}`);
|
|
190
|
+
const behaviorReplace = overlays.find((o) => o.op === "replace" && sectionOfMessage(o.target)?.band === "core-behavior");
|
|
191
|
+
if (behaviorReplace !== undefined && evidence.refs.length === 0) {
|
|
192
|
+
return fail("evidence", `overlay "${behaviorReplace.id}" replaces core-behavior text; evidence.refs names at least one evaluation or golden`);
|
|
193
|
+
}
|
|
194
|
+
const normalized = {
|
|
195
|
+
schemaVersion: 3,
|
|
196
|
+
requires: requiresOf(overlays),
|
|
197
|
+
overlays,
|
|
198
|
+
evidence: { intent: evidence.intent, refs: [...evidence.refs] },
|
|
199
|
+
};
|
|
200
|
+
if (computeArtifactDigest(normalized) !== raw.artifactDigest)
|
|
201
|
+
return fail("digest", "artifactDigest does not match canonical(payload)");
|
|
202
|
+
return { ok: true, artifact: { payload: normalized, artifactDigest: raw.artifactDigest } };
|
|
144
203
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
contentHash: s.contentHash,
|
|
151
|
-
}));
|
|
204
|
+
const CENTER_ORIGIN = Object.freeze({ source: "center", by: "center" });
|
|
205
|
+
export function centerOverlaysOf(adoption) {
|
|
206
|
+
if (adoption === undefined)
|
|
207
|
+
return [];
|
|
208
|
+
return adoption.artifact.payload.overlays.map((overlay) => ({ overlay, origin: CENTER_ORIGIN }));
|
|
152
209
|
}
|
|
153
|
-
export function
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
165
|
-
return {
|
|
166
|
-
artifact: { payload, artifactDigest: computeArtifactDigest(payload) },
|
|
167
|
-
sourceRevision: opts.sourceRevision,
|
|
168
|
-
};
|
|
210
|
+
export function adoptCenter(artifact, sourceRevision) {
|
|
211
|
+
const v = verifyPromptArtifactBody(artifact);
|
|
212
|
+
return v.ok ? { artifact: v.artifact, ...(sourceRevision !== undefined ? { sourceRevision } : {}) } : undefined;
|
|
213
|
+
}
|
|
214
|
+
export function buildPromptArtifact(opts) {
|
|
215
|
+
const overlays = opts.overlays.map((o) => {
|
|
216
|
+
const v = validateOverlay(o, { source: "center" });
|
|
217
|
+
return "overlay" in v ? v.overlay : o;
|
|
218
|
+
});
|
|
219
|
+
const payload = JSON.parse(JSON.stringify({ schemaVersion: 3, requires: requiresOf(overlays), overlays, evidence: opts.evidence }));
|
|
220
|
+
return verifyPromptArtifact({ payload, artifactDigest: sha256Hex(canonical(payload)), sourceRevision: opts.sourceRevision });
|
|
169
221
|
}
|