Files
Anandan f922cb378e Add cross-session messaging (#884)
* Add cross-session messaging

* Harden cross-session messaging

Authenticate sender metadata against live registry records, bound peer lifecycle state, preserve records across transient discovery failures, and make receipt delivery direct and bounded.

Also serialize TUI peer approvals, harden platform runtime paths and transport deadlines, widen session references, and add regression coverage for identity spoofing, queue limits, path boundaries, and tool failures.

* Support canonical macOS socket paths

Resolve Unix transport directories to their physical path before applying strict no-symlink traversal, allowing the standard /var to /private/var macOS alias without weakening runtime-directory validation.

* Fix macOS socket path regression test

Create the canonicalization fixture beneath a guaranteed short Unix path so it exercises the primary endpoint on macOS, and report temporary-directory cleanup failures.

* Harden peer messaging lifecycle

* Fix Windows peer directory traversal

* Handle Windows token-owned peer directories

* Accept equivalent Windows ACL masks

* Build Windows peer ACL explicitly

* Pin Windows ACL trustee SIDs

* Validate Windows peer ACL semantics

* Propagate Windows peer handle cleanup errors

* Use null handle for Windows close failure test

* Test held-message eviction callback
2026-08-09 18:12:09 +05:30

111 lines
2.9 KiB
Go

package peermsg
import "time"
const (
ProtocolVersion = 1
maxMessageBytes = 64 * 1024
maxFrameBytes = 128 * 1024
)
type PermissionClass string
const (
PermissionPrompting PermissionClass = "prompting"
PermissionBypass PermissionClass = "bypass"
)
type DeliveryStatus string
const (
DeliveryAccepted DeliveryStatus = "accepted"
DeliveryHeld DeliveryStatus = "held"
DeliveryRefused DeliveryStatus = "refused"
DeliveryDelivered DeliveryStatus = "delivered"
DeliveryDenied DeliveryStatus = "denied"
DeliveryExpired DeliveryStatus = "expired"
)
type InboundPolicy string
const (
InboundPolicyParity InboundPolicy = ""
InboundPolicyAccept InboundPolicy = "accept"
InboundPolicyHold InboundPolicy = "hold"
InboundPolicyRefuse InboundPolicy = "refuse"
)
type HoldCause string
const (
HoldCauseModeMismatch HoldCause = "mode-mismatch"
HoldCauseExplicit HoldCause = "explicit-setting"
HoldCauseModeUnknown HoldCause = "mode-unknown"
)
// Identity is the model-independent identity published by one live Zero
// process. SessionID and Name are updated when the TUI creates, resumes, or
// renames its active session.
type Identity struct {
SessionID string `json:"sessionId,omitempty"`
Name string `json:"name,omitempty"`
Cwd string `json:"cwd,omitempty"`
PermissionClass PermissionClass `json:"permissionClass"`
}
// Peer is one reachable local Zero session.
type Peer struct {
Identity
Endpoint string `json:"endpoint"`
PID int `json:"pid"`
StartedAt time.Time `json:"startedAt"`
UpdatedAt time.Time `json:"updatedAt"`
Ref string `json:"ref"`
}
// InboundMessage is delivered to the receiving application. RequiresApproval
// is true when local policy requires the user to approve delivery.
type InboundMessage struct {
ID string
From Peer
Body string
Summary string
ReceivedAt time.Time
RequiresApproval bool
HoldCause HoldCause
HopChain []string
}
type sendFrame struct {
Version int `json:"version"`
Type string `json:"type"`
ID string `json:"id"`
From Peer `json:"from"`
To string `json:"to"`
Summary string `json:"summary"`
Body string `json:"body"`
HopChain []string `json:"hopChain,omitempty"`
OrigID string `json:"origMessageId,omitempty"`
Status DeliveryStatus `json:"status,omitempty"`
}
type responseFrame struct {
Version int `json:"version"`
Type string `json:"type"`
ID string `json:"id"`
Status DeliveryStatus `json:"status"`
Error string `json:"error,omitempty"`
}
type SendResult struct {
MessageID string
Peer Peer
Status DeliveryStatus
}
type StatusEvent struct {
MessageID string
Peer Peer
Status DeliveryStatus
}