@sema-agent/core 7.71.1 → 7.73.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 +500 -0
- package/dist/agents/cross-session-ref.d.ts +2 -2
- package/dist/agents/cross-session-ref.js +7 -2
- package/dist/agents/inherited-tool-pool.d.ts +30 -2
- package/dist/agents/inherited-tool-pool.js +53 -7
- package/dist/agents/parked-resume-drive.d.ts +10 -0
- package/dist/agents/parked-resume-drive.js +9 -0
- package/dist/agents/retain-ledger.d.ts +3 -0
- package/dist/agents/send-message-tool.js +7 -2
- package/dist/agents/send-user-message-tool.d.ts +12 -0
- package/dist/agents/send-user-message-tool.js +67 -0
- package/dist/agents/subagent-steps.d.ts +9 -0
- package/dist/agents/subagent-steps.js +38 -0
- package/dist/agents/subagent.d.ts +2 -0
- package/dist/agents/subagent.js +47 -12
- package/dist/agents/verify.js +23 -7
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.js +14 -9
- package/dist/brain/open-responses.js +4 -5
- package/dist/brain/openai.js +30 -23
- package/dist/brain/stream-engine.js +159 -151
- package/dist/core/a2a.d.ts +24 -3
- package/dist/core/a2a.js +27 -8
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/agent-state.d.ts +28 -7
- package/dist/core/agent-state.js +19 -6
- package/dist/core/allow-entry.js +3 -3
- package/dist/core/approval-object.d.ts +7 -3
- package/dist/core/approval-object.js +30 -9
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/checkpoint-features.d.ts +16 -5
- package/dist/core/checkpoint-features.js +35 -6
- package/dist/core/checkpoint-rekey.d.ts +1 -1
- package/dist/core/checkpoint-rekey.js +6 -1
- package/dist/core/checkpoint-requirements.d.ts +23 -3
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-row-verdict.d.ts +1 -1
- package/dist/core/checkpoint-row-verdict.js +10 -4
- package/dist/core/checkpoint-store.d.ts +24 -2
- package/dist/core/checkpoint-store.js +1 -0
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/effective-path-target.d.ts +19 -0
- package/dist/core/effective-path-target.js +95 -38
- package/dist/core/engine-capabilities.d.ts +5 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +34 -23
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +19 -7
- package/dist/core/entries-not-applied.js +33 -1
- package/dist/core/file-history-store.d.ts +15 -4
- package/dist/core/file-history-store.js +53 -23
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +10 -1
- package/dist/core/governance-codes.js +17 -5
- package/dist/core/hooks.d.ts +3 -0
- package/dist/core/hooks.js +1 -0
- package/dist/core/host-instance.d.ts +23 -0
- package/dist/core/host-instance.js +69 -0
- package/dist/core/instruction-preview.d.ts +63 -0
- package/dist/core/instruction-preview.js +406 -0
- package/dist/core/judged-read.d.ts +57 -0
- package/dist/core/judged-read.js +1 -0
- package/dist/core/leg-budget.d.ts +26 -0
- package/dist/core/leg-budget.js +9 -0
- package/dist/core/leg-identity.d.ts +51 -1
- package/dist/core/leg-identity.js +45 -2
- package/dist/core/manager-launch-check.d.ts +48 -0
- package/dist/core/manager-launch-check.js +64 -0
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-host-seat.d.ts +5 -0
- package/dist/core/mcp-host-seat.js +7 -1
- package/dist/core/mcp-injection-drop.d.ts +20 -10
- package/dist/core/mcp-injection-drop.js +9 -3
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/mcp.js +3 -1
- package/dist/core/member-outcome.d.ts +3 -2
- package/dist/core/member-outcome.js +1 -1
- package/dist/core/memory-engine/deletion-record.d.ts +46 -0
- package/dist/core/memory-engine/deletion-record.js +96 -0
- package/dist/core/memory-engine/engine.js +24 -16
- package/dist/core/memory-engine/file-backend.js +7 -5
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/index.js +1 -1
- package/dist/core/memory-engine/layout.js +6 -4
- package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
- package/dist/core/memory-engine/projection-ledger.js +1 -1
- package/dist/core/memory-engine/scope-contract.d.ts +69 -11
- package/dist/core/memory-engine/scope-contract.js +99 -34
- package/dist/core/memory-engine/sync-client.js +26 -6
- package/dist/core/memory-engine/sync.d.ts +20 -2
- package/dist/core/memory-engine/sync.js +18 -17
- package/dist/core/mode-policy.d.ts +21 -6
- package/dist/core/mode-policy.js +15 -6
- package/dist/core/mounted-mcp.d.ts +7 -2
- package/dist/core/mounted-mcp.js +10 -1
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/param-rule-reach.d.ts +8 -3
- package/dist/core/param-rule-reach.js +9 -1
- package/dist/core/parent-spec-seat.d.ts +13 -1
- package/dist/core/parent-spec-seat.js +18 -0
- package/dist/core/peer-registration.d.ts +52 -0
- package/dist/core/peer-registration.js +37 -0
- package/dist/core/peer-seat.d.ts +3 -1
- package/dist/core/peer-seat.js +3 -3
- package/dist/core/peer-task-store.d.ts +365 -0
- package/dist/core/peer-task-store.js +682 -0
- package/dist/core/permission-rule-consent.js +6 -11
- package/dist/core/permission-rule-model.d.ts +27 -0
- package/dist/core/permission-rule-model.js +34 -6
- package/dist/core/permission-rule-provider.d.ts +35 -33
- package/dist/core/permission-rule-provider.js +38 -295
- package/dist/core/permission-rule-store.d.ts +181 -8
- package/dist/core/permission-rule-store.js +420 -17
- package/dist/core/permission-rule-sync.js +15 -1
- package/dist/core/project-seat.d.ts +55 -0
- package/dist/core/project-seat.js +96 -0
- package/dist/core/protocol-http-auth.d.ts +3 -2
- package/dist/core/protocol-http-auth.js +26 -18
- package/dist/core/remote-env.d.ts +4 -4
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/run-ledger-seat.d.ts +66 -0
- package/dist/core/run-ledger-seat.js +70 -0
- package/dist/core/run-ledger.d.ts +332 -0
- package/dist/core/run-ledger.js +550 -0
- package/dist/core/runner/chain-mismatch.d.ts +32 -0
- package/dist/core/runner/chain-mismatch.js +29 -0
- package/dist/core/runner/changes-history.d.ts +1 -0
- package/dist/core/runner/changes-history.js +2 -2
- package/dist/core/runner/checkpoint-scope.d.ts +13 -3
- package/dist/core/runner/checkpoint-scope.js +12 -4
- package/dist/core/runner/construction-doors.js +6 -0
- package/dist/core/runner/contracts.d.ts +22 -3
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/file-history-restore.d.ts +3 -1
- package/dist/core/runner/file-history-restore.js +9 -6
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/loaded-skills.d.ts +2 -0
- package/dist/core/runner/loaded-skills.js +10 -0
- package/dist/core/runner/nested-memory-lane.d.ts +22 -5
- package/dist/core/runner/nested-memory-lane.js +91 -30
- package/dist/core/runner/person-path-rows.d.ts +23 -20
- package/dist/core/runner/person-path-rows.js +82 -18
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +105 -90
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +5 -3
- package/dist/core/runner/prepare-context-lane.js +1 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +6 -0
- package/dist/core/runner/prepare-execution-env.d.ts +3 -3
- package/dist/core/runner/prepare-file-history.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +10 -2
- package/dist/core/runner/prepare-hands-readface.js +36 -22
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -5
- package/dist/core/runner/prepare-inherited-gate.js +14 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -2
- package/dist/core/runner/prepare-memory-engine-session.js +2 -2
- package/dist/core/runner/prepare-memory.js +3 -15
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +3 -7
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -0
- package/dist/core/runner/prepare-protocol-tools.js +2 -2
- package/dist/core/runner/prepare-run-refs.d.ts +1 -1
- package/dist/core/runner/prepare-run-refs.js +3 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
- package/dist/core/runner/prepare-suspend-saga.js +4 -2
- package/dist/core/runner/prepare-task.js +50 -37
- package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
- package/dist/core/runner/prepare-turn-wiring.js +2 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -1
- package/dist/core/runner/prepare-wiring-manifest.js +8 -4
- package/dist/core/runner/read-session-changes.js +1 -1
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-checkpoint-screen.d.ts +8 -7
- package/dist/core/runner/resume-checkpoint-screen.js +7 -6
- package/dist/core/runner/resume-review-outcome.d.ts +3 -0
- package/dist/core/runner/resume-review-outcome.js +24 -1
- package/dist/core/runner/rewind-files.js +3 -2
- package/dist/core/runner/run-harness-handlers.js +3 -0
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +9 -2
- package/dist/core/runner/run-notification-lane.js +20 -1
- package/dist/core/runner/run-settle-and-teardown.js +21 -12
- package/dist/core/runner/run-stop-and-final-verify.js +6 -0
- package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
- package/dist/core/runner/runtask.d.ts +6 -2
- package/dist/core/runner/runtask.js +21 -9
- package/dist/core/runner/shell-env-withheld.d.ts +3 -2
- package/dist/core/runner/shell-env-withheld.js +1 -2
- package/dist/core/runner/stop-tail-notice.d.ts +10 -2
- package/dist/core/runner/stop-tail-notice.js +9 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +10 -1
- package/dist/core/runner/terminal-account.js +23 -3
- package/dist/core/runner/tool-face-overlay.d.ts +2 -11
- package/dist/core/runner/tool-face-overlay.js +39 -0
- package/dist/core/runner/trim-stretch.js +7 -2
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner-deps.d.ts +13 -10
- package/dist/core/scheduler.d.ts +47 -7
- package/dist/core/scheduler.js +19 -7
- package/dist/core/secret-env.d.ts +60 -37
- package/dist/core/secret-env.js +45 -48
- package/dist/core/sensitive-path-policy.js +14 -7
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +1 -0
- package/dist/core/session-store.d.ts +12 -6
- package/dist/core/session-store.js +26 -6
- package/dist/core/session.d.ts +31 -8
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +17 -0
- package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
- package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
- package/dist/core/store-contracts/session-store-contract.js +87 -3
- package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
- package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
- package/dist/core/task-event.d.ts +11 -3
- package/dist/core/task-notification.d.ts +97 -10
- package/dist/core/task-notification.js +129 -5
- package/dist/core/task-registry-shared.d.ts +12 -1
- package/dist/core/task-registry-shared.js +3 -1
- package/dist/core/task-registry-workflow.d.ts +1 -1
- package/dist/core/task-registry-workflow.js +9 -1
- package/dist/core/task-registry.d.ts +39 -2
- package/dist/core/task-registry.js +76 -12
- package/dist/core/task-result.d.ts +13 -0
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +11 -3
- package/dist/core/task-spec.d.ts +57 -23
- package/dist/core/tool-catalog-entries.js +4 -0
- package/dist/core/tool-face-reader.js +1 -1
- package/dist/core/tool-face.d.ts +7 -0
- package/dist/core/tool-face.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +5 -3
- package/dist/core/tool-mount-facts.js +4 -3
- package/dist/core/tool-mount-plan.d.ts +7 -3
- package/dist/core/tool-mount-plan.js +11 -5
- package/dist/core/tool-mount-static.d.ts +2 -2
- package/dist/core/tool-mount-static.js +28 -14
- package/dist/core/tool-registry.d.ts +33 -1
- package/dist/core/tool-registry.js +33 -0
- package/dist/core/tool-result-store.d.ts +19 -2
- package/dist/core/tool-result-store.js +51 -2
- package/dist/core/tool-roster.d.ts +16 -0
- package/dist/core/tool-roster.js +6 -0
- package/dist/core/tool-spec.d.ts +13 -4
- package/dist/core/tools.d.ts +6 -0
- package/dist/core/tools.js +1 -1
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +89 -29
- package/dist/core/wiring-manifest.js +44 -4
- package/dist/core/workflow-journal-store.d.ts +53 -10
- package/dist/core/workflow-journal-store.js +27 -4
- package/dist/core/workflow-run-store-contract.js +16 -0
- package/dist/core/workflow-run-store.d.ts +9 -7
- package/dist/core/workflow-run-store.js +4 -1
- package/dist/engine/execution-env/node-execution-env.js +3 -1
- package/dist/engine/harness/messages.d.ts +1 -1
- package/dist/engine/harness/messages.js +2 -1
- package/dist/engine/harness/types.d.ts +24 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +5 -7
- package/dist/engine/loop/types.d.ts +2 -0
- package/dist/engine/lsp/node-lsp-manager.js +2 -1
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +15 -2
- package/dist/engine/session/session.js +35 -5
- package/dist/index.d.ts +27 -12
- package/dist/index.js +20 -8
- package/dist/orchestration/run-workflow-tool.js +40 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
- package/dist/orchestration/workflow-park-adoption.js +47 -12
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +30 -6
- package/dist/orchestration/workflow.js +117 -54
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/stores/file/adoption/marker.d.ts +2 -27
- package/dist/stores/file/adoption/marker.js +12 -0
- package/dist/stores/file/index.d.ts +1 -1
- package/dist/stores/file/index.js +1 -1
- package/dist/stores/file/permission-rule-store.d.ts +3 -1
- package/dist/stores/file/permission-rule-store.js +0 -1
- package/dist/stores/file/workflow-journal-store.d.ts +16 -3
- package/dist/stores/file/workflow-journal-store.js +93 -5
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/tools/artifact/artifact-tool.js +11 -6
- package/dist/tools/fs/file-read-check.d.ts +45 -11
- package/dist/tools/fs/file-read-check.js +200 -57
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- package/dist/tools/fs/judged-reads.d.ts +51 -0
- package/dist/tools/fs/judged-reads.js +68 -0
- package/dist/tools/fs/read-deny-home.d.ts +1 -1
- package/dist/tools/fs/read-deny-home.js +5 -5
- package/dist/tools/fs/read-deny.d.ts +33 -8
- package/dist/tools/fs/read-deny.js +114 -25
- package/dist/tools/fs/safety.d.ts +12 -1
- package/dist/tools/fs/safety.js +16 -3
- package/dist/tools/fs/shell-read-check.d.ts +25 -5
- package/dist/tools/fs/shell-read-check.js +100 -15
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +34 -14
- package/dist/tools/fs/shell-read-judge.d.ts +13 -1
- package/dist/tools/fs/shell-read-judge.js +26 -7
- package/dist/tools/fs/shell-read-plan.d.ts +5 -0
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/dist/tools/scheduler-store-move.d.ts +74 -0
- package/dist/tools/scheduler-store-move.js +103 -0
- package/dist/tools/scheduler-tools.d.ts +43 -29
- package/dist/tools/scheduler-tools.js +161 -118
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +173 -3
- package/wire-changes/answers/core-stores-sql@7.72.0.json +12 -0
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core@7.72.0.json +84 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/mods-kernel@7.72.0.json +7 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/primitives@7.72.0.json +6 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/wiki-gate@7.72.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/core-stores-sql@7.72.0.json +215 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core@7.72.0.json +2426 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/mods-kernel@7.72.0.json +147 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/primitives@7.72.0.json +143 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/wiki-gate@7.72.0.json +145 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isNameableToolName } from "@sema-agent/primitives";
|
|
4
|
-
import { PERMISSION_RULES_DAMAGED_BUCKET_CODE, PERMISSION_RULE_WRITER, errText, holdsRuleWriter, isValidDurableScope, normalizePersistedRule, sameRuleIdentity, writerOf, } from "./permission-rule-store.js";
|
|
1
|
+
import { escapeForDisclosure, isRuleBehavior, parseRuleText } from "./permission-rule-model.js";
|
|
2
|
+
import { PERMISSION_RULES_DAMAGED_BUCKET_CODE, PERMISSION_RULE_WRITER, TOMBSTONE_ROW_MEMBERS, errText, holdsRuleWriter, memberValueOf, normalizePersistedRule, readDurableRuleRow, ruleRowReadOf, sameRuleIdentity, servedLengthOf, servedRowOf, servedValueOf, unreadableRowsLine, writerOf, } from "./permission-rule-store.js";
|
|
5
3
|
import { readRuleOwner } from "./rule-owner.js";
|
|
6
4
|
import { ruleStoreFaultReasonOf } from "./rule-store-fault.js";
|
|
7
5
|
import { readPrincipal } from "./principal-name.js";
|
|
@@ -30,247 +28,12 @@ function usableSessionId(sessionId) {
|
|
|
30
28
|
return typeof sessionId === "string" && sessionId !== "" ? sessionId : undefined;
|
|
31
29
|
}
|
|
32
30
|
const EMPTY_DURABLE = { rules: [], tombstones: [], rev: 0 };
|
|
33
|
-
|
|
34
|
-
const SCOPE_SHAPE = { members: { kind: "primitive" }, byKind: { project: { root: "primitive" }, session: { sessionId: "primitive" } }, held: true };
|
|
35
|
-
const ADD_SHAPE = { members: { dot: { members: { actor: "value", counter: "value" }, held: true }, origin: "primitive", createdAt: "time", peerFingerprint: "primitive" }, own: ["peerFingerprint"], held: true };
|
|
36
|
-
const RULE_ROW_MEMBERS = { behavior: "text", rule: "text", tool: "text", match: "text", command: "text", scope: SCOPE_SHAPE, adds: { listOf: ADD_SHAPE, held: true } };
|
|
37
|
-
const TOMBSTONE_ROW_MEMBERS = { behavior: "primitive", rule: "primitive", scope: SCOPE_SHAPE, removedDots: { listOf: DOT_SHAPE }, deletedBy: DOT_SHAPE };
|
|
38
|
-
const TIME_OF_DATE = Date.prototype.getTime;
|
|
39
|
-
const ISO_OF_DATE = Date.prototype.toISOString;
|
|
40
|
-
const unreadValue = (why, kept) => ({ ok: false, why, ...(kept !== undefined ? { kept } : {}) });
|
|
41
|
-
function servedValueOf(v, shape) {
|
|
42
|
-
const held = heldKindOf(shape);
|
|
43
|
-
if (v === null || (typeof v !== "object" && typeof v !== "function")) {
|
|
44
|
-
if (held === undefined || (held === "a text" && typeof v === "string") || (held === "a value" && v !== null && v !== undefined))
|
|
45
|
-
return { ok: true, v };
|
|
46
|
-
return unreadValue(`${v === null || v === undefined ? String(v) : `a ${typeof v}`} where ${held} belongs`);
|
|
47
|
-
}
|
|
48
|
-
if (shape === "time" && typeof v === "object" && !types.isProxy(v) && types.isDate(v) && Number.isFinite(TIME_OF_DATE.call(v)))
|
|
49
|
-
return { ok: true, v: ISO_OF_DATE.call(v) };
|
|
50
|
-
if (typeof shape === "string" || typeof v === "function")
|
|
51
|
-
return unreadValue(`${typeof v === "function" ? "a function" : shape === "time" ? "an object that is no valid date" : "an object"} where a ${typeof shape === "string" ? shape : "primitive"} belongs`);
|
|
52
|
-
if ("listOf" in shape) {
|
|
53
|
-
const length = servedLengthOf(v);
|
|
54
|
-
if ("why" in length)
|
|
55
|
-
return unreadValue(length.why);
|
|
56
|
-
const out = new Array(length.n);
|
|
57
|
-
const kept = [];
|
|
58
|
-
let why;
|
|
59
|
-
for (let i = 0; i < length.n; i++) {
|
|
60
|
-
const el = memberOf(v, i);
|
|
61
|
-
const got = "why" in el ? el : el.held ? servedValueOf(el.v, shape.listOf) : heldKindOf(shape.listOf) !== undefined ? unreadValue(`a hole where ${heldKindOf(shape.listOf)} belongs`) : undefined;
|
|
62
|
-
if (got === undefined)
|
|
63
|
-
continue;
|
|
64
|
-
if ("why" in got)
|
|
65
|
-
why ??= `element #${i}: ${got.why}`;
|
|
66
|
-
else
|
|
67
|
-
kept.push((out[i] = got.v));
|
|
68
|
-
}
|
|
69
|
-
return why === undefined ? { ok: true, v: out } : unreadValue(why, kept);
|
|
70
|
-
}
|
|
71
|
-
const out = {};
|
|
72
|
-
const readMembers = (members) => {
|
|
73
|
-
for (const [k, member] of Object.entries(members)) {
|
|
74
|
-
const got = memberOf(v, k);
|
|
75
|
-
if ("why" in got)
|
|
76
|
-
return unreadValue(got.why);
|
|
77
|
-
if (!got.held) {
|
|
78
|
-
if (heldKindOf(member) !== undefined)
|
|
79
|
-
return unreadValue(`nothing where ${heldKindOf(member)} belongs`);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (got.v !== undefined && got.v !== null && "members" in shape && shape.own?.includes(k) === true && !ownMemberOf(v, k))
|
|
83
|
-
return unreadValue(`${k}: a value its prototype supplies, not the object's own`);
|
|
84
|
-
const value = servedValueOf(got.v, member);
|
|
85
|
-
if (!value.ok)
|
|
86
|
-
return unreadValue(value.why);
|
|
87
|
-
out[k] = value.v;
|
|
88
|
-
}
|
|
89
|
-
return undefined;
|
|
90
|
-
};
|
|
91
|
-
const failed = readMembers(shape.members);
|
|
92
|
-
if (failed !== undefined)
|
|
93
|
-
return failed;
|
|
94
|
-
const kind = out.kind;
|
|
95
|
-
const byKind = shape.byKind !== undefined && typeof kind === "string" && Object.hasOwn(shape.byKind, kind) ? readMembers(shape.byKind[kind]) : undefined;
|
|
96
|
-
return byKind ?? { ok: true, v: out };
|
|
97
|
-
}
|
|
98
|
-
function memberOf(o, k) {
|
|
99
|
-
try {
|
|
100
|
-
const v = Reflect.get(o, k);
|
|
101
|
-
return v === undefined && !(k in o) ? { held: false } : { held: true, v };
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
return { why: errText(e), thrown: e };
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function ownMemberOf(o, k) {
|
|
108
|
-
try {
|
|
109
|
-
return Object.hasOwn(o, k);
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function memberValueOf(o, k) {
|
|
116
|
-
const got = memberOf(o, k);
|
|
117
|
-
return "why" in got ? { ok: false, why: got.why, thrown: got.thrown } : { ok: true, v: got.held ? got.v : undefined };
|
|
118
|
-
}
|
|
119
|
-
function servedLengthOf(v) {
|
|
120
|
-
let isList;
|
|
121
|
-
try {
|
|
122
|
-
isList = Array.isArray(v);
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
return { why: errText(e), thrown: e };
|
|
126
|
-
}
|
|
127
|
-
if (!isList)
|
|
128
|
-
return { why: "an object where a list belongs" };
|
|
129
|
-
const got = memberValueOf(v, "length");
|
|
130
|
-
if (!got.ok)
|
|
131
|
-
return { why: got.why, ...("thrown" in got ? { thrown: got.thrown } : {}) };
|
|
132
|
-
const n = got.v;
|
|
133
|
-
return typeof n === "number" && Number.isInteger(n) && n >= 0 && n <= MAX_LIST_LENGTH ? { n } : { why: "a list whose length is no count" };
|
|
134
|
-
}
|
|
135
|
-
const MAX_LIST_LENGTH = 2 ** 32 - 1;
|
|
136
|
-
function heldKindOf(shape) {
|
|
137
|
-
if (shape === "text")
|
|
138
|
-
return "a text";
|
|
139
|
-
if (shape === "value")
|
|
140
|
-
return "a value";
|
|
141
|
-
if (typeof shape !== "object" || shape.held !== true)
|
|
142
|
-
return undefined;
|
|
143
|
-
return "listOf" in shape ? "a list" : "an object";
|
|
144
|
-
}
|
|
145
|
-
function servedRowOf(row, members) {
|
|
146
|
-
if (row === null || typeof row !== "object") {
|
|
147
|
-
const why = `${row === null ? "null" : row === undefined ? "nothing" : `a ${typeof row}`} where a row belongs`;
|
|
148
|
-
return { failed: Object.keys(members).map((member) => ({ member, why })), read: {}, notObject: why };
|
|
149
|
-
}
|
|
150
|
-
const read = {};
|
|
151
|
-
const failed = [];
|
|
152
|
-
for (const [k, shape] of Object.entries(members)) {
|
|
153
|
-
const got = servedMemberOf(row, k, shape);
|
|
154
|
-
if ("why" in got)
|
|
155
|
-
failed.push({ member: k, why: got.why, ...("thrown" in got ? { threw: true } : {}), ...("kept" in got && got.kept !== undefined ? { kept: got.kept } : {}) });
|
|
156
|
-
else if (got.held)
|
|
157
|
-
read[k] = got.v;
|
|
158
|
-
}
|
|
159
|
-
return failed.length > 0 ? { failed: failed, read } : { row: read };
|
|
160
|
-
}
|
|
161
|
-
function servedMemberOf(row, k, shape) {
|
|
162
|
-
const got = memberOf(row, k);
|
|
163
|
-
if ("why" in got)
|
|
164
|
-
return got;
|
|
165
|
-
if (!got.held)
|
|
166
|
-
return heldKindOf(shape) !== undefined ? { why: `nothing where ${heldKindOf(shape)} belongs` } : got;
|
|
167
|
-
const value = servedValueOf(got.v, shape);
|
|
168
|
-
return value.ok ? { held: true, v: value.v } : { why: value.why, ...(value.kept !== undefined ? { kept: value.kept } : {}) };
|
|
169
|
-
}
|
|
170
|
-
function behaviorWordDamaged(kind, at, row) {
|
|
31
|
+
function tombstoneWordDamaged(at, row) {
|
|
171
32
|
return {
|
|
172
33
|
ok: false,
|
|
173
|
-
e: Object.assign(new Error(`the persisted rule partition served a
|
|
34
|
+
e: Object.assign(new Error(`the persisted rule partition served a tombstone row (#${at}, ${escapeForDisclosure(row?.rule)}) whose behavior word ${escapeForDisclosure(row?.behavior)} is outside deny/ask/allow — which rows it retired is unknown, so the partition is read as one that could not be read`), { code: PERMISSION_RULES_DAMAGED_BUCKET_CODE }),
|
|
174
35
|
};
|
|
175
36
|
}
|
|
176
|
-
function commandIsIdentity(match) {
|
|
177
|
-
return match !== "tool";
|
|
178
|
-
}
|
|
179
|
-
const UNNAMED_ADD = Object.freeze({ dot: Object.freeze({ actor: "", counter: 0 }), origin: "user", createdAt: "" });
|
|
180
|
-
const UNREADABLE_RULE_TEXT = "(unreadable)";
|
|
181
|
-
function standingTextOf(read) {
|
|
182
|
-
const { tool, match } = read;
|
|
183
|
-
const command = match === "tool" ? "" : read.command;
|
|
184
|
-
if (typeof tool !== "string" || typeof match !== "string" || typeof command !== "string")
|
|
185
|
-
return UNREADABLE_RULE_TEXT;
|
|
186
|
-
try {
|
|
187
|
-
const rule = formatRuleText(command, match, tool);
|
|
188
|
-
return "reject" in normalizePersistedRule({ ...read, command, rule }) ? UNREADABLE_RULE_TEXT : rule;
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
191
|
-
return UNREADABLE_RULE_TEXT;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
function identityOf(read, failed) {
|
|
195
|
-
if (!failed.has("tool") && !failed.has("match") && !(failed.has("command") && commandIsIdentity(read.match)))
|
|
196
|
-
return {};
|
|
197
|
-
const parsed = failed.has("rule") || typeof read.rule !== "string" ? undefined : parseRuleText(read.rule, read.behavior);
|
|
198
|
-
return parsed === undefined || "reject" in parsed ? undefined : { tool: parsed.rule.tool, match: parsed.rule.match, command: parsed.rule.command };
|
|
199
|
-
}
|
|
200
|
-
function standingRowOf(read, failed, seat) {
|
|
201
|
-
const adds = failed.find((f) => f.member === "adds");
|
|
202
|
-
const stood = {
|
|
203
|
-
...read,
|
|
204
|
-
...(failed.some((f) => f.member === "scope") ? { scope: widestScopeOf(seat) } : {}),
|
|
205
|
-
...(read.match === "tool" && typeof read.command !== "string" ? { command: "" } : {}),
|
|
206
|
-
...(adds !== undefined ? { adds: adds.kept !== undefined && adds.kept.length > 0 ? [...adds.kept] : [UNNAMED_ADD] } : {}),
|
|
207
|
-
};
|
|
208
|
-
return failed.some((f) => f.member === "rule") ? { ...stood, rule: standingTextOf(stood) } : stood;
|
|
209
|
-
}
|
|
210
|
-
function unreadableRowOf(read, failed, first, seat) {
|
|
211
|
-
const behavior = read.behavior;
|
|
212
|
-
const tool = failed.has("tool") ? undefined : read.tool;
|
|
213
|
-
const pathDeny = behavior === "deny" && typeof tool === "string" && Object.hasOwn(PATH_RULE_FACES, tool) && PATH_RULE_FACES[tool]?.deny !== undefined;
|
|
214
|
-
return {
|
|
215
|
-
reason: failed.has("rule") ? "invalid_rule_text" : "metadata_mismatch",
|
|
216
|
-
rule: failed.has("rule") ? UNREADABLE_RULE_TEXT : String(read.rule),
|
|
217
|
-
behavior,
|
|
218
|
-
member: first,
|
|
219
|
-
reach: typeof tool === "string" && isNameableToolName(tool) && !pathDeny ? { tool } : "every",
|
|
220
|
-
...namedScopeOf(failed.has("scope") ? undefined : read.scope, seat),
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
const DURABLE_SEAT = {};
|
|
224
|
-
function widestScopeOf(seat) {
|
|
225
|
-
return seat.session !== undefined ? { kind: "session", sessionId: seat.session } : { kind: "global" };
|
|
226
|
-
}
|
|
227
|
-
function namedScopeOf(scope, seat) {
|
|
228
|
-
if (seat.session === undefined)
|
|
229
|
-
return isValidDurableScope(scope) ? { scope: scope } : {};
|
|
230
|
-
if (scope === undefined)
|
|
231
|
-
return { scope: widestScopeOf(seat) };
|
|
232
|
-
const session = typeof scope === "object" && scope !== null && scope.kind === "session" && typeof scope.sessionId === "string";
|
|
233
|
-
return session ? { scope: scope } : {};
|
|
234
|
-
}
|
|
235
|
-
function unreadableRowsLine(partition, rows) {
|
|
236
|
-
return (`the ${partition} rule partition served ${rows.length} deny or ask row(s) a member of which could not be read as the type it holds — one whose tool, match and command read, or whose text says the ones that did not, stands as written (its text, when that is the member, spelled from them; its scope, when that is the member, ${partition === "session" ? "the session's" : "everywhere"}); one whose neither do stands at its strictest reading over the calls it may reach (no allow clears them; a readable deny still refuses, a readable ask still asks); every other row stands: ` +
|
|
237
|
-
rows
|
|
238
|
-
.slice(0, 3)
|
|
239
|
-
.map(({ row, why }) => `${escapeForDisclosure(row.rule)} (${escapeForDisclosure(why)}; ${row.reach === "as_read" ? "as written" : row.reach === "every" ? "every call" : `the ${escapeForDisclosure(row.reach.tool)} calls`})`)
|
|
240
|
-
.join(", "));
|
|
241
|
-
}
|
|
242
|
-
function ruleRowReadOf(served, seat) {
|
|
243
|
-
const r = servedRowOf(served, RULE_ROW_MEMBERS);
|
|
244
|
-
if ("row" in r)
|
|
245
|
-
return { row: r.row };
|
|
246
|
-
const failed = new Set(r.failed.map((f) => f.member));
|
|
247
|
-
if (!failed.has("behavior") && !isRuleBehavior(r.read.behavior))
|
|
248
|
-
return { word: r.read };
|
|
249
|
-
const [first] = r.failed;
|
|
250
|
-
const why = `${first.member}: ${first.why}`;
|
|
251
|
-
const reason = failed.has("rule") ? "invalid_rule_text" : "metadata_mismatch";
|
|
252
|
-
const rule = failed.has("rule") ? UNREADABLE_RULE_TEXT : String(r.read.rule);
|
|
253
|
-
const scope = failed.has("scope") ? widestScopeOf(seat) : r.read.scope;
|
|
254
|
-
const dead = !failed.has("adds") && Array.isArray(r.read.adds) && r.read.adds.length === 0;
|
|
255
|
-
if (dead)
|
|
256
|
-
return { dead };
|
|
257
|
-
if (failed.has("behavior"))
|
|
258
|
-
return { noRow: { reason, rule, read: r.notObject ?? `behavior: ${first.threw === true ? "a read that threw" : first.why}` }, scope };
|
|
259
|
-
if (r.read.behavior === "allow")
|
|
260
|
-
return { left: { reason, rule, member: first.member }, scope };
|
|
261
|
-
const identity = identityOf(r.read, failed);
|
|
262
|
-
if (identity === undefined)
|
|
263
|
-
return { named: { row: unreadableRowOf(r.read, failed, first.member, seat), why } };
|
|
264
|
-
const stood = standingRowOf({ ...r.read, ...identity }, r.failed, seat);
|
|
265
|
-
return { row: stood, named: { row: { reason, rule, behavior: r.read.behavior, member: first.member, reach: "as_read", ...namedScopeOf(failed.has("scope") ? undefined : r.read.scope, seat) }, why, stood } };
|
|
266
|
-
}
|
|
267
|
-
function noRowDroppedOf(e, partition, index) {
|
|
268
|
-
return { reason: e.reason, rule: e.rule, member: "behavior", element: { partition, index, read: e.read } };
|
|
269
|
-
}
|
|
270
|
-
function noRowsLine(partition, rows) {
|
|
271
|
-
const at = rows.flatMap((r) => ("element" in r && r.element !== undefined ? [`#${r.element.index} (${escapeForDisclosure(r.element.read)})`] : []));
|
|
272
|
-
return `the ${partition} rule partition served ${at.length} element(s) whose behavior word could not be read — not read as rules (nothing says one was a deny): ${at.slice(0, 3).join(", ")}`;
|
|
273
|
-
}
|
|
274
37
|
function durableSnapshotOf(served) {
|
|
275
38
|
const damaged = (what) => ({ ok: false, e: Object.assign(new Error(`the persisted rule partition served ${what} — what it refuses is unknown, so the partition is read as one that could not be read`), { code: PERMISSION_RULES_DAMAGED_BUCKET_CODE }) });
|
|
276
39
|
if (served === null || typeof served !== "object")
|
|
@@ -299,21 +62,27 @@ function durableSnapshotOf(served) {
|
|
|
299
62
|
const rules = [];
|
|
300
63
|
const unread = [];
|
|
301
64
|
const unreadable = [];
|
|
65
|
+
const dropped = new Map();
|
|
302
66
|
for (let i = 0; i < ruleCount.n; i++) {
|
|
303
67
|
const at = rowOf(servedRules.v, "rule", i);
|
|
304
68
|
if ("e" in at)
|
|
305
69
|
return at.e;
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
70
|
+
const reading = readDurableRuleRow(at.row);
|
|
71
|
+
if (reading.kind === "inert") {
|
|
72
|
+
if (reading.unread === true && reading.dropped !== undefined)
|
|
73
|
+
unread.push(reading.dropped);
|
|
74
|
+
else if (reading.row !== undefined) {
|
|
75
|
+
rules.push(reading.row);
|
|
76
|
+
if (reading.dropped !== undefined)
|
|
77
|
+
dropped.set(reading.row, reading.dropped);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (reading.row !== undefined)
|
|
82
|
+
rules.push(reading.row);
|
|
83
|
+
if (reading.named !== undefined)
|
|
84
|
+
unreadable.push(reading.named);
|
|
85
|
+
}
|
|
317
86
|
}
|
|
318
87
|
const tombstones = [];
|
|
319
88
|
for (let i = 0; i < tombstoneCount.n; i++) {
|
|
@@ -326,18 +95,22 @@ function durableSnapshotOf(served) {
|
|
|
326
95
|
tombstones.push(t.row);
|
|
327
96
|
}
|
|
328
97
|
const settled = durableReadOf({ ok: true, v: { rules, tombstones, rev: rev.ok ? rev.v : 0 } });
|
|
329
|
-
return settled.ok
|
|
98
|
+
return settled.ok
|
|
99
|
+
? {
|
|
100
|
+
...settled,
|
|
101
|
+
...(unread.length > 0 ? { unread } : {}),
|
|
102
|
+
...(unreadable.length > 0 ? { unreadable } : {}),
|
|
103
|
+
...(dropped.size > 0 ? { dropped } : {}),
|
|
104
|
+
...(revUnread !== undefined ? { revUnread } : {}),
|
|
105
|
+
}
|
|
106
|
+
: settled;
|
|
330
107
|
}
|
|
331
108
|
function durableReadOf(settled) {
|
|
332
109
|
if (!settled.ok)
|
|
333
110
|
return settled;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
continue;
|
|
338
|
-
return behaviorWordDamaged(kind, at, rows[at]);
|
|
339
|
-
}
|
|
340
|
-
return settled;
|
|
111
|
+
const rows = settled.v.tombstones;
|
|
112
|
+
const at = rows.findIndex((r) => !isRuleBehavior(r?.behavior));
|
|
113
|
+
return at < 0 ? settled : tombstoneWordDamaged(at, rows[at]);
|
|
341
114
|
}
|
|
342
115
|
export function createPermissionRuleStoreProvider(cfg) {
|
|
343
116
|
if (cfg === null || typeof cfg !== "object") {
|
|
@@ -425,28 +198,18 @@ class UnifiedPermissionRuleStore {
|
|
|
425
198
|
const sessionRead = "unreadable" in sessionRows ? [] : sessionRows.rows;
|
|
426
199
|
const shadowed = compileOrgShadowPredicate(orgResolution.rules);
|
|
427
200
|
const rules = [];
|
|
428
|
-
const dropped = new Map();
|
|
429
|
-
for (const r of durableRead.rules) {
|
|
430
|
-
const why = droppedRowOf(r);
|
|
431
|
-
if (why !== undefined)
|
|
432
|
-
dropped.set(r, why);
|
|
433
|
-
}
|
|
201
|
+
const dropped = durableSettled.ok && durableSettled.dropped !== undefined ? durableSettled.dropped : new Map();
|
|
434
202
|
const illegal = durableRead.rules.filter((r) => dropped.get(r)?.reason === "scope_root_not_absolute");
|
|
435
203
|
const misspelt = durableRead.rules.filter((r) => dropped.has(r) && !illegal.includes(r));
|
|
436
204
|
const unread = durableSettled.ok ? (durableSettled.unread ?? []) : [];
|
|
437
|
-
const
|
|
438
|
-
const noRows = unread.filter(isNoRow);
|
|
439
|
-
const unreadAllows = unread.filter((r) => !isNoRow(r));
|
|
440
|
-
const durableNamed = (durableSettled.ok ? (durableSettled.unreadable ?? []) : []).filter((u) => u.stood === undefined || !dropped.has(u.stood));
|
|
205
|
+
const durableNamed = durableSettled.ok ? (durableSettled.unreadable ?? []) : [];
|
|
441
206
|
const unreadRows = [...durableNamed, ...("unreadable" in sessionRows ? [] : sessionRows.named)];
|
|
442
207
|
const unreadableRev = durableSettled.ok ? durableSettled.revUnread : undefined;
|
|
443
208
|
if (unreadableRev !== undefined)
|
|
444
209
|
disclosures.push(unreadableRev);
|
|
445
210
|
const droppedRows = [...unread, ...("unreadable" in sessionRows ? [] : sessionRows.left), ...dropped.values()];
|
|
446
|
-
if (
|
|
447
|
-
disclosures.push(
|
|
448
|
-
if (unreadAllows.length > 0)
|
|
449
|
-
disclosures.push(`the persisted rule partition served ${unreadAllows.length} allow row(s) a member of which could not be read as data — dropped, not adjudicated: ${unreadAllows.slice(0, 3).map((r) => escapeForDisclosure(r.rule)).join(", ")}`);
|
|
211
|
+
if (unread.length > 0)
|
|
212
|
+
disclosures.push(`the persisted rule partition served ${unread.length} allow row(s) a member of which could not be read as data — dropped, not adjudicated: ${unread.slice(0, 3).map((r) => escapeForDisclosure(r.rule)).join(", ")}`);
|
|
450
213
|
if (durableNamed.length > 0)
|
|
451
214
|
disclosures.push(unreadableRowsLine("persisted", durableNamed));
|
|
452
215
|
if (illegal.length > 0)
|
|
@@ -479,11 +242,9 @@ class UnifiedPermissionRuleStore {
|
|
|
479
242
|
throw "thrown" in count ? count.thrown : new Error(`an answer that is no list (${count.why})`);
|
|
480
243
|
const seat = { session: sessionId };
|
|
481
244
|
const ofThisSession = (scope) => scope?.kind === "session" && scope.sessionId === sessionId;
|
|
482
|
-
const ofAnotherSession = (scope) => scope?.kind === "session" && typeof scope.sessionId === "string" && !ofThisSession(scope);
|
|
483
245
|
const rows = [];
|
|
484
246
|
const named = [];
|
|
485
247
|
const left = [];
|
|
486
|
-
const noRows = [];
|
|
487
248
|
let taken = 0;
|
|
488
249
|
for (let i = 0; i < count.n; i++) {
|
|
489
250
|
const got = memberValueOf(served, i);
|
|
@@ -494,11 +255,6 @@ class UnifiedPermissionRuleStore {
|
|
|
494
255
|
taken++;
|
|
495
256
|
continue;
|
|
496
257
|
}
|
|
497
|
-
if (r.noRow !== undefined) {
|
|
498
|
-
if (!ofAnotherSession(r.scope))
|
|
499
|
-
(noRows.push(noRowDroppedOf(r.noRow, "session", i)), taken++);
|
|
500
|
-
continue;
|
|
501
|
-
}
|
|
502
258
|
if (r.left !== undefined) {
|
|
503
259
|
if (ofThisSession(r.scope))
|
|
504
260
|
(left.push(r.left), taken++);
|
|
@@ -522,13 +278,11 @@ class UnifiedPermissionRuleStore {
|
|
|
522
278
|
if (taken < count.n) {
|
|
523
279
|
disclosures.push(`the session rule partition served ${count.n - taken} row(s) that are not canonical session rows of this session — dropped, not adjudicated`);
|
|
524
280
|
}
|
|
525
|
-
if (noRows.length > 0)
|
|
526
|
-
disclosures.push(noRowsLine("session", noRows));
|
|
527
281
|
if (left.length > 0)
|
|
528
282
|
disclosures.push(`the session rule partition served ${left.length} allow row(s) a member of which could not be read as data — dropped, not adjudicated: ${left.slice(0, 3).map((x) => escapeForDisclosure(x.rule)).join(", ")}`);
|
|
529
283
|
if (named.length > 0)
|
|
530
284
|
disclosures.push(unreadableRowsLine("session", named));
|
|
531
|
-
return { rows, named, left
|
|
285
|
+
return { rows, named, left };
|
|
532
286
|
}
|
|
533
287
|
catch (err) {
|
|
534
288
|
const why = `the session rule partition could not be read: ${escapeForDisclosure(errText(err))}`;
|
|
@@ -537,17 +291,6 @@ class UnifiedPermissionRuleStore {
|
|
|
537
291
|
}
|
|
538
292
|
}
|
|
539
293
|
}
|
|
540
|
-
function droppedRowOf(r) {
|
|
541
|
-
if (!isValidDurableScope(r.scope))
|
|
542
|
-
return { reason: "scope_root_not_absolute", rule: String(r.rule), scopeRoot: scopeRootAsServed(r.scope.root) };
|
|
543
|
-
if (r.behavior !== "allow")
|
|
544
|
-
return undefined;
|
|
545
|
-
const shape = normalizePersistedRule(r);
|
|
546
|
-
return "reject" in shape ? { reason: shape.reject, rule: r.rule } : undefined;
|
|
547
|
-
}
|
|
548
|
-
function scopeRootAsServed(root) {
|
|
549
|
-
return typeof root === "string" ? root : `(${root === null ? "null" : typeof root})`;
|
|
550
|
-
}
|
|
551
294
|
function rowBindingOf(r, seat) {
|
|
552
295
|
if (seat === undefined || r.behavior !== "allow")
|
|
553
296
|
return {};
|
|
@@ -362,9 +362,35 @@ export declare function holdsRuleWriter(store: DurableRulePartition | import("./
|
|
|
362
362
|
/** Do two scopes name the same place? Three members (design/382 §4.1): global, project-by-root,
|
|
363
363
|
* session-by-sessionId. */
|
|
364
364
|
export declare function sameScope(a: RuleScope, b: RuleScope): boolean;
|
|
365
|
-
/**
|
|
366
|
-
*
|
|
367
|
-
|
|
365
|
+
/** The text a stored row whose text does not read is named by when its stored fields spell no rule this grammar reads: a text that is
|
|
366
|
+
* no rule, so every check that reads it reads none (an earlier grammar's row's reading). */
|
|
367
|
+
export declare const UNREADABLE_RULE_TEXT = "(unreadable)";
|
|
368
|
+
/**
|
|
369
|
+
* The text a stored row whose own text does not read stands under and is named by: the canonical spelling of its stored tool, match and
|
|
370
|
+
* command ({@link formatRuleText}) when they spell a rule this grammar reads whose canonical fields they are ({@link normalizePersistedRule}'s
|
|
371
|
+
* law) — what its checks judge it by — else {@link UNREADABLE_RULE_TEXT}. A whole-tool row is spelled by its tool alone.
|
|
372
|
+
*/
|
|
373
|
+
export declare function storedRuleTextOf(read: Readonly<Record<string, unknown>>): string;
|
|
374
|
+
/**
|
|
375
|
+
* The identity a stored row, tombstone or quarantine row is DISPLAYED under — the one name the view shows it under:
|
|
376
|
+
* · For a row whose behavior is in `deny | ask | allow`: its behavior; its text, or — when its text is no string — the
|
|
377
|
+
* spelling of its stored fields ({@link storedRuleTextOf}); its scope, or the durable partition's widest (`global`) when
|
|
378
|
+
* its scope does not read as one.
|
|
379
|
+
* · For a row that is no object or whose behavior word is unreadable / outside `deny | ask | allow`: the strictest-reading
|
|
380
|
+
* display name (`behavior: "ask"`, its string text or {@link UNREADABLE_RULE_TEXT}, and its durable scope or `global`),
|
|
381
|
+
* matching `unreadableRowOf` in `permission-rule-provider.ts`.
|
|
382
|
+
* Each member is read once; a read that throws is a member that does not read.
|
|
383
|
+
*/
|
|
384
|
+
export declare function storedRuleIdentityOf(row: unknown): {
|
|
385
|
+
behavior: RuleBehavior;
|
|
386
|
+
rule: string;
|
|
387
|
+
scope: RuleScope;
|
|
388
|
+
};
|
|
389
|
+
/** Do two rows/tombstones/quarantine rows name the SAME stored logical rule — their stored (behavior, text, scope) triple
|
|
390
|
+
* ({@link storedExactIdentityOf})? Every identity comparison goes through this one predicate: a comparison that forgot the behavior
|
|
391
|
+
* member would let a delete aimed at an allow take the same-text deny, and deriving a missing text or scope would let a tombstone hide
|
|
392
|
+
* a damaged deny before disclosure or fold a fresh approval into a damaged allow. A row without a stored triple matches nothing; the
|
|
393
|
+
* predicate never throws. */
|
|
368
394
|
export declare function sameRuleIdentity(a: {
|
|
369
395
|
behavior: RuleBehavior;
|
|
370
396
|
rule: string;
|
|
@@ -374,15 +400,158 @@ export declare function sameRuleIdentity(a: {
|
|
|
374
400
|
rule: string;
|
|
375
401
|
scope: RuleScope;
|
|
376
402
|
}): boolean;
|
|
403
|
+
/** One row of `EffectivePermissionRules.droppedRows`. */
|
|
404
|
+
export type StoredDroppedRow = {
|
|
405
|
+
readonly reason: "scope_root_not_absolute";
|
|
406
|
+
readonly rule: string;
|
|
407
|
+
readonly scopeRoot: string;
|
|
408
|
+
} | {
|
|
409
|
+
readonly reason: "invalid_rule_text" | "metadata_mismatch";
|
|
410
|
+
readonly rule: string;
|
|
411
|
+
readonly member?: string;
|
|
412
|
+
readonly element?: {
|
|
413
|
+
readonly partition: "durable" | "session";
|
|
414
|
+
readonly index: number;
|
|
415
|
+
readonly read: string;
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
/** One row of `EffectivePermissionRules.unreadableRows`. */
|
|
419
|
+
export type StoredUnreadableRow = {
|
|
420
|
+
readonly reason: "invalid_rule_text" | "metadata_mismatch";
|
|
421
|
+
readonly rule: string;
|
|
422
|
+
readonly behavior: "deny" | "ask";
|
|
423
|
+
readonly member: string;
|
|
424
|
+
readonly reach: "as_read" | "every" | {
|
|
425
|
+
readonly tool: string;
|
|
426
|
+
};
|
|
427
|
+
readonly scope?: RuleScope;
|
|
428
|
+
};
|
|
429
|
+
/** How one served member is read as data: a primitive; a time (a primitive, or a date object read as its ISO text); a text, which every
|
|
430
|
+
* row holds — a string; a value, which every row holds — a primitive save `null` and `undefined`; an object's own members, each by its
|
|
431
|
+
* own shape — and, where its `kind` reads as a word `byKind` names, the members that kind uses — `held`, an object every row holds;
|
|
432
|
+
* `own`, the members that are an AUTHORIZATION (an add's identity stamp, which clears an inside peer's question): only the object's own
|
|
433
|
+
* member is one, so a value its prototype supplies is no value of it — the object then cannot be read (#5013's judge, `addStampsOf`,
|
|
434
|
+
* reads a stamp as an add's own member only; the copy never makes an inherited one own); a list's elements — `held`, a list every row
|
|
435
|
+
* holds. */
|
|
436
|
+
type ServedShape = "primitive" | "time" | "text" | "value" | {
|
|
437
|
+
readonly members: Readonly<Record<string, ServedShape>>;
|
|
438
|
+
readonly byKind?: Readonly<Record<string, Readonly<Record<string, ServedShape>>>>;
|
|
439
|
+
readonly own?: readonly string[];
|
|
440
|
+
readonly held?: true;
|
|
441
|
+
} | {
|
|
442
|
+
readonly listOf: ServedShape;
|
|
443
|
+
readonly held?: true;
|
|
444
|
+
};
|
|
445
|
+
export declare const TOMBSTONE_ROW_MEMBERS: {
|
|
446
|
+
readonly behavior: "primitive";
|
|
447
|
+
readonly rule: "primitive";
|
|
448
|
+
readonly scope: {
|
|
449
|
+
readonly members: Readonly<Record<string, ServedShape>>;
|
|
450
|
+
readonly byKind?: Readonly<Record<string, Readonly<Record<string, ServedShape>>>>;
|
|
451
|
+
readonly own?: readonly string[];
|
|
452
|
+
readonly held?: true;
|
|
453
|
+
};
|
|
454
|
+
readonly removedDots: {
|
|
455
|
+
readonly listOf: {
|
|
456
|
+
readonly members: Readonly<Record<string, ServedShape>>;
|
|
457
|
+
readonly byKind?: Readonly<Record<string, Readonly<Record<string, ServedShape>>>>;
|
|
458
|
+
readonly own?: readonly string[];
|
|
459
|
+
readonly held?: true;
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
readonly deletedBy: {
|
|
463
|
+
readonly members: Readonly<Record<string, ServedShape>>;
|
|
464
|
+
readonly byKind?: Readonly<Record<string, Readonly<Record<string, ServedShape>>>>;
|
|
465
|
+
readonly own?: readonly string[];
|
|
466
|
+
readonly held?: true;
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
type Served = {
|
|
470
|
+
readonly ok: true;
|
|
471
|
+
readonly v: unknown;
|
|
472
|
+
} | {
|
|
473
|
+
readonly ok: false;
|
|
474
|
+
readonly why: string;
|
|
475
|
+
readonly kept?: readonly unknown[];
|
|
476
|
+
};
|
|
477
|
+
/** A served value read as data by `shape` into a copy of the engine's own, every member and element through {@link memberOf} and every
|
|
478
|
+
* list's length through {@link servedLengthOf} — the one reader of what a personal partition serves. */
|
|
479
|
+
export declare function servedValueOf(v: unknown, shape: ServedShape): Served;
|
|
480
|
+
export declare function memberValueOf(o: object, k: string | number): Served | {
|
|
481
|
+
readonly ok: false;
|
|
482
|
+
readonly why: string;
|
|
483
|
+
readonly thrown: unknown;
|
|
484
|
+
};
|
|
485
|
+
export declare function servedLengthOf(v: unknown): {
|
|
486
|
+
readonly n: number;
|
|
487
|
+
} | {
|
|
488
|
+
readonly why: string;
|
|
489
|
+
readonly thrown?: unknown;
|
|
490
|
+
};
|
|
491
|
+
type FailedMember = {
|
|
492
|
+
readonly member: string;
|
|
493
|
+
readonly why: string;
|
|
494
|
+
readonly threw?: true;
|
|
495
|
+
readonly kept?: readonly unknown[];
|
|
496
|
+
};
|
|
497
|
+
export declare function servedRowOf(row: unknown, members: Readonly<Record<string, ServedShape>>): {
|
|
498
|
+
readonly row: unknown;
|
|
499
|
+
} | {
|
|
500
|
+
readonly failed: readonly [FailedMember, ...FailedMember[]];
|
|
501
|
+
readonly read: Readonly<Record<string, unknown>>;
|
|
502
|
+
readonly notObject?: string;
|
|
503
|
+
};
|
|
504
|
+
export type RowSeat = {
|
|
505
|
+
readonly session?: string;
|
|
506
|
+
};
|
|
507
|
+
export declare const DURABLE_SEAT: RowSeat;
|
|
508
|
+
export type NamedRow = {
|
|
509
|
+
readonly row: StoredUnreadableRow;
|
|
510
|
+
readonly why: string;
|
|
511
|
+
readonly stood?: unknown;
|
|
512
|
+
};
|
|
513
|
+
export declare function unreadableRowsLine(partition: "persisted" | "session", rows: readonly NamedRow[]): string;
|
|
514
|
+
/** One served rule row as the rules read it — shared by both personal partitions, the delete verb, and read-back. */
|
|
515
|
+
export declare function ruleRowReadOf(served: unknown, seat: RowSeat): {
|
|
516
|
+
readonly row?: unknown;
|
|
517
|
+
readonly left?: StoredDroppedRow;
|
|
518
|
+
readonly scope?: unknown;
|
|
519
|
+
readonly named?: NamedRow;
|
|
520
|
+
readonly dead?: true;
|
|
521
|
+
};
|
|
522
|
+
/** Why a served durable row takes no part in any check, or `undefined` when it does. */
|
|
523
|
+
export declare function droppedRowOf(r: PersistedRule): StoredDroppedRow | undefined;
|
|
524
|
+
/**
|
|
525
|
+
* Whether a row is LIVE is read in exactly one way — the way the rule reader reads it; the delete verb and its read-back
|
|
526
|
+
* use that same reading.
|
|
527
|
+
*
|
|
528
|
+
* · `kind: "acts"` — takes part in checks (`view.rules` when `row` is present; `view.unreadableRows` when `named` is present).
|
|
529
|
+
* · `kind: "inert"` — grants nothing and restricts nothing in checks (`dead` empty-adds row, dropped allow, or
|
|
530
|
+
* `scope_root_not_absolute`).
|
|
531
|
+
*/
|
|
532
|
+
export type DurableRowReading = {
|
|
533
|
+
readonly kind: "acts";
|
|
534
|
+
readonly row?: PersistedRule;
|
|
535
|
+
readonly named?: NamedRow;
|
|
536
|
+
} | {
|
|
537
|
+
readonly kind: "inert";
|
|
538
|
+
readonly row?: PersistedRule;
|
|
539
|
+
readonly dropped?: StoredDroppedRow;
|
|
540
|
+
readonly unread?: true;
|
|
541
|
+
readonly dead?: true;
|
|
542
|
+
};
|
|
543
|
+
export declare function readDurableRuleRow(served: unknown): DurableRowReading;
|
|
377
544
|
/**
|
|
378
|
-
* Apply tombstones to a raw persisted set: an add survives iff its dot appears in no tombstone
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
545
|
+
* Apply tombstones to a raw persisted set: an add survives iff its dot appears in no tombstone of the name the row is read under
|
|
546
|
+
* ({@link sameRuleIdentity}). The criterion is dot IDENTITY — single dots across replicas carry no order to compare — and an add the deleting
|
|
547
|
+
* replica never observed survives (add-wins), because behind every add there is one real human approval. Total over what a backend holds:
|
|
548
|
+
* a row nobody can name, a row whose list of adds does not read and an add whose dot does not read pass through as they are, for the read
|
|
549
|
+
* face to name; a row whose list of adds reads as empty no longer exists.
|
|
382
550
|
*/
|
|
383
551
|
export declare function applyTombstones(rules: readonly PersistedRule[], tombstones: readonly RuleTombstone[]): PersistedRule[];
|
|
384
552
|
/** Fold one delta into a raw rule set, returning the new set. Pure — the backends share it so the file and
|
|
385
|
-
* in-memory forms cannot drift in what a delta MEANS.
|
|
553
|
+
* in-memory forms cannot drift in what a delta MEANS. A held row whose list of adds does not read is carried as it is, and an add of its
|
|
554
|
+
* name lands as a row of its own beside it. */
|
|
386
555
|
export declare function foldDelta(rules: readonly PersistedRule[], delta: RuleAddDelta | RuleTightenAddDelta): PersistedRule[];
|
|
387
556
|
/** Every add dot present in a rule set. */
|
|
388
557
|
export declare function addDotsOf(rules: readonly PersistedRule[]): RuleDot[];
|
|
@@ -615,6 +784,9 @@ export interface RuleSyncJoinBase {
|
|
|
615
784
|
* riding every future round;
|
|
616
785
|
* ⑥ persist the observation vector the delta carries (the client only sends one on a clean round).
|
|
617
786
|
*/
|
|
787
|
+
/** Indices of local rule rows that cannot be read as wire-syncable stored rule rows (missing/invalid behavior, text, scope, or strict sync dots).
|
|
788
|
+
* Shared by `syncPermissionRules` (pre-transport hold) and {@link applySyncJoin} (landing fence). */
|
|
789
|
+
export declare function unreadableLocalRuleIndices(rules: readonly unknown[]): number[];
|
|
618
790
|
export declare function applySyncJoin(cur: RuleSyncJoinBase, delta: RuleSyncJoinDelta, nowMs: number): {
|
|
619
791
|
next: RuleSyncJoinBase;
|
|
620
792
|
report: RuleSyncLandingReport;
|
|
@@ -906,3 +1078,4 @@ export declare class InMemoryDurableRulePartition implements WritableDurableRule
|
|
|
906
1078
|
quarantined(): Promise<QuarantinedRuleAdd[]>;
|
|
907
1079
|
readonly [PERMISSION_RULE_WRITER]: PermissionRuleWriter;
|
|
908
1080
|
}
|
|
1081
|
+
export {};
|