@byollm/protocol 0.1.0-alpha.91 → 0.1.0-alpha.93

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  > [!WARNING]
2
- > **Alpha (`0.1.0-alpha.91`) — under active development. Don't use this yet.**
2
+ > **Alpha (`0.1.0-alpha.93`) — under active development. Don't use this yet.**
3
3
  >
4
4
  > Install it deliberately: `npm install @byollm/protocol@alpha`.
5
5
  >
package/dist/index.d.ts CHANGED
@@ -2972,4 +2972,227 @@ declare const MUST_IDS: readonly ("PAIR_ONE_USER" | "PAIR_INTERACTIVE" | "PAIR_C
2972
2972
  /** Every MUST verified a particular way. */
2973
2973
  declare function mustsVerifiedBy(kind: MustVerification): MustId[];
2974
2974
 
2975
- export { ABOUT, ABOUT_SHORT, ABOUT_SHORT_LEDE, ABOUT_SHORT_TAIL, AUDIENCES, Audience, BACKENDS, BACKEND_CLASSES, BACKEND_IDS, BackendClass, BackendCost, type BackendDescriptor, type BackendId, BackendIdSchema, CLOCK_ATTRIBUTION_MS, CLOCK_SKEW_WARN_MS, Capability, CapabilityMatrix, ChatMessage, ChatPayload, ClaimRequest, ClaimResponse, ClaimedJob, ClaimedStub, DeliveredResult, ENCRYPTION_KEY_CONTEXT, ENDPOINTS, ENVELOPE_MAX_AGE_MS, ERROR_STATUS, type Endpoint, type EnvelopeContext, EnvelopeDirection, type EnvelopeFailure, FetchRequest, FetchResponse, type FloorRefusal, GRANT_CONTEXT, GRANT_MAX_AGE_MS, GRANT_SIGNED_FIELDS, GeneratePayload, type GrantClaims, GrantRef, type GrantRefusal, HeartbeatRequest, HeartbeatResponse, JOB_KINDS, JobKind, JobOutcome, JobPayload, JobRefused, JobResultCanceled, JobResultError, JobResultOk, JobState, JobStub, KindedPayload, Lease, MAX_CLOCK_SKEW_MS, MAX_ENVELOPE_BYTES, MAX_PURPOSES, MAX_SUCCESSION_CHAIN, MIN_PROTOCOL_VERSION, MUSTS, MUST_IDS, Manifest, type MatchDaemon, type MatchJob, MatchRefusal, type MatchResult, type Must, type MustEnforcer, type MustId, type MustVerification, type MustVerifiedBy, OFFER_SCOPES, OfferScope, type OpenResult, PAYLOAD_LIMITS, PROTOCOL_PREFIX, PROTOCOL_VERSION, PairPollRequest, PairPollResponse, PairRequest, PairStartRequest, PairStartResponse, type PayloadFor, PublicIdentity, Purpose, REFUSAL_MESSAGES, REFUSAL_TEXT, RESERVED_PURPOSE, RETIREMENT_WINDOW_MS, RefusalReason, ReleaseRequest, ReleaseResponse, RequestSignature, ResultDisposition, ResultProvenance, ResultRequest, ResultResponse, RunMetadata, SIZE_CLASSES, SIZE_CLASS_LIMITS, SUCCESSION_CONTEXT, SUPPORTED_PROTOCOL_VERSIONS, SealedEnvelope, SealedOutcome, type SignatureFailure, SignedGrant, SizeClass, type SpendConsent, type StopReason, StopReasonSchema, StoredKeys, Succession, type SuccessionFailure, type SuccessionWalk, TERMINAL_STATES, UPDATE_OFFER_SINCE, UPGRADE_COMMAND, type VersionRefusal, WireError, WireErrorCode, WithheldKind, backendDescriptor, backendName, canTransition, canonicalRequest, checkDaemonFloor, checkProtocolVersion, classifyCost, compareVersions, cryptoReady, declaredVersion, describeBytes, effectiveOfferScope, envelopeBytes, fingerprint, generateKeys, grantStatement, isBackendId, isCloudTaggedModel, isJobKind, isLocalHost, isTerminal, keyId, kindsOf, matchAudience, mayOfferUpdate, mentionsWireField, mustsVerifiedBy, open, payloadTextLength, provenanceFor, publicIdentityOf, resolveCost, seal, signGrant, signRequest, signSiteRequest, signSuccession, signWith, singlePurposeManifest, sizeClassCeiling, sizeClassOf, successionStatement, tooLargeMessage, updateOfferFor, verifyGrant, verifyLink, verifyPublicIdentity, verifyRequest, verifySiteRequest, verifyWith, walkSuccession, withoutComments };
2975
+ /**
2976
+ * The terminal stream a hosted box's console runs over — byollm_018 §"Console
2977
+ * redesign: brokered E2E replaces SSH-first (RULED, Todd 2026-09-03)".
2978
+ *
2979
+ * The ruling's item 3 is the whole reason this file exists: *"The terminal
2980
+ * stream is E2E encrypted browser↔agent with the sealed-channel pattern jobs
2981
+ * use; the hub routes ciphertext."* So the bytes are carried by
2982
+ * {@link seal}/{@link open} exactly as a job's payload is, and what is defined
2983
+ * here is the thing a sealed envelope does not carry: **what a frame means,
2984
+ * and where it sits in the stream.**
2985
+ *
2986
+ * ## Why an ordering rule is protocol and not an implementation detail
2987
+ *
2988
+ * Sealing makes the hub unable to READ the stream. It does nothing to make
2989
+ * the hub unable to reshape it. A router that holds ciphertext can drop a
2990
+ * frame, deliver two out of order, or send the same frame twice, and every
2991
+ * envelope still opens, still verifies against the pinned identity, and still
2992
+ * looks perfect to the receiver — because each envelope is authenticated on
2993
+ * its own and says nothing about the ones around it.
2994
+ *
2995
+ * On a terminal that is not a theoretical loss of tidiness. A dropped
2996
+ * keystroke is a different command; two frames swapped is a different command;
2997
+ * a replayed frame is a command run twice. The console carries vendor
2998
+ * sign-in flows (byollm_018 item 5), so "a different command" can mean an auth
2999
+ * code going somewhere it was not typed.
3000
+ *
3001
+ * Hence {@link consoleOrder}: a sequence inside the ciphertext, checked by
3002
+ * both ends. Inside, because a counter the hub could see is a counter the hub
3003
+ * could rewrite.
3004
+ *
3005
+ * ## One definition, both ends, and there are three ends
3006
+ *
3007
+ * The browser, the box's agent, and the hub broker all handle these frames,
3008
+ * and the first two must agree byte for byte or the stream silently corrupts.
3009
+ * The hub must NOT be able to agree — it only ever sees the sealed envelope.
3010
+ * This module is the single definition the two real ends share; neither
3011
+ * retypes it.
3012
+ *
3013
+ * ## The pinned box key is the PAIRING key (CCB's call, 09-16)
3014
+ *
3015
+ * The ruling says "box key pinned at first session", and the backlog left one
3016
+ * delta open: whether the identity the owner already approved at pairing can
3017
+ * serve as that pinned key. It can, and it should, for three reasons.
3018
+ *
3019
+ * 1. **The pairing key is the only one a human ever chose.** `PairStartRequest`
3020
+ * carries the device's {@link PublicIdentity} and says why: *"Pairing is
3021
+ * where the two parties learn each other's identities, because it is the
3022
+ * one moment a human is already deciding to trust: the approval click. A
3023
+ * key exchanged anywhere else would be a key nobody chose."* A fresh
3024
+ * trust-on-first-use pin at the first console session is precisely a key
3025
+ * nobody chose — it trusts whoever answers first, which on a brokered
3026
+ * channel is whoever the broker points at.
3027
+ * 2. **Two pins of one box can disagree, and silently.** A console pin
3028
+ * separate from the pairing pin is a second record of the same fact, which
3029
+ * is this project's most-repeated defect. When they diverge, nothing reads
3030
+ * both, so nothing notices.
3031
+ * 3. **Alarm-on-change comes free from the split already in `keys.ts`.** The
3032
+ * Ed25519 identity is the pinned half and the X25519 encryption key is
3033
+ * signed by it, so {@link verifyPublicIdentity} lets the box rotate its
3034
+ * encryption key without a new ceremony while an IDENTITY change fails to
3035
+ * verify and alarms — which is what the ruling asks for, and it is already
3036
+ * written.
3037
+ *
3038
+ * **What this does not claim.** Pinning the pairing key does not make the hub
3039
+ * unable to lie about which key that was; the hub is the one telling the
3040
+ * browser. The ruling is explicit that we build the operator-ACCOUNTABLE
3041
+ * version, not the operator-incapable one, and item 4's session feed is where
3042
+ * that accountability is paid. What the pin buys is that a CHANGE is
3043
+ * detectable, and that the key being pinned is one an owner approved rather
3044
+ * than one a broker supplied.
3045
+ */
3046
+ /** Domain tag for the plaintext inside a console envelope. */
3047
+ declare const CONSOLE_FRAME_VERSION = "byollm/v1/console";
3048
+ /**
3049
+ * The largest `data` payload one frame may carry, before base64.
3050
+ *
3051
+ * Far below {@link MAX_ENVELOPE_BYTES}, and deliberately: an envelope cap
3052
+ * stops a memory attack, while this stops a latency one. A console is
3053
+ * interactive, so a peer that batches a megabyte into one frame has made the
3054
+ * stream unusable without ever exceeding a limit.
3055
+ */
3056
+ declare const CONSOLE_MAX_DATA_BYTES: number;
3057
+ declare const ConsoleHello: z.ZodObject<{
3058
+ v: z.ZodLiteral<"byollm/v1/console">;
3059
+ kind: z.ZodLiteral<"hello">;
3060
+ seq: z.ZodLiteral<1>;
3061
+ browser: z.ZodObject<{
3062
+ identity: z.ZodString;
3063
+ encryption: z.ZodString;
3064
+ encryptionSig: z.ZodString;
3065
+ }, z.core.$strict>;
3066
+ cols: z.ZodNumber;
3067
+ rows: z.ZodNumber;
3068
+ }, z.core.$strict>;
3069
+ type ConsoleHello = z.infer<typeof ConsoleHello>;
3070
+ /**
3071
+ * Two schemas rather than one with a `kind: z.enum([...])`, because the union
3072
+ * below discriminates on `kind` and a discriminator that is itself a set is
3073
+ * how a union quietly stops discriminating.
3074
+ */
3075
+ declare const ConsoleStdin: z.ZodObject<{
3076
+ v: z.ZodLiteral<"byollm/v1/console">;
3077
+ kind: z.ZodLiteral<"stdin">;
3078
+ seq: z.ZodNumber;
3079
+ data: z.ZodString;
3080
+ }, z.core.$strict>;
3081
+ type ConsoleStdin = z.infer<typeof ConsoleStdin>;
3082
+ declare const ConsoleStdout: z.ZodObject<{
3083
+ v: z.ZodLiteral<"byollm/v1/console">;
3084
+ kind: z.ZodLiteral<"stdout">;
3085
+ seq: z.ZodNumber;
3086
+ data: z.ZodString;
3087
+ }, z.core.$strict>;
3088
+ type ConsoleStdout = z.infer<typeof ConsoleStdout>;
3089
+ declare const ConsoleResize: z.ZodObject<{
3090
+ v: z.ZodLiteral<"byollm/v1/console">;
3091
+ kind: z.ZodLiteral<"resize">;
3092
+ seq: z.ZodNumber;
3093
+ cols: z.ZodNumber;
3094
+ rows: z.ZodNumber;
3095
+ }, z.core.$strict>;
3096
+ type ConsoleResize = z.infer<typeof ConsoleResize>;
3097
+ declare const ConsoleBye: z.ZodObject<{
3098
+ v: z.ZodLiteral<"byollm/v1/console">;
3099
+ kind: z.ZodLiteral<"bye">;
3100
+ seq: z.ZodNumber;
3101
+ reason: z.ZodString;
3102
+ }, z.core.$strict>;
3103
+ type ConsoleBye = z.infer<typeof ConsoleBye>;
3104
+ declare const ConsoleFrame: z.ZodDiscriminatedUnion<[z.ZodObject<{
3105
+ v: z.ZodLiteral<"byollm/v1/console">;
3106
+ kind: z.ZodLiteral<"hello">;
3107
+ seq: z.ZodLiteral<1>;
3108
+ browser: z.ZodObject<{
3109
+ identity: z.ZodString;
3110
+ encryption: z.ZodString;
3111
+ encryptionSig: z.ZodString;
3112
+ }, z.core.$strict>;
3113
+ cols: z.ZodNumber;
3114
+ rows: z.ZodNumber;
3115
+ }, z.core.$strict>, z.ZodObject<{
3116
+ v: z.ZodLiteral<"byollm/v1/console">;
3117
+ kind: z.ZodLiteral<"stdin">;
3118
+ seq: z.ZodNumber;
3119
+ data: z.ZodString;
3120
+ }, z.core.$strict>, z.ZodObject<{
3121
+ v: z.ZodLiteral<"byollm/v1/console">;
3122
+ kind: z.ZodLiteral<"stdout">;
3123
+ seq: z.ZodNumber;
3124
+ data: z.ZodString;
3125
+ }, z.core.$strict>, z.ZodObject<{
3126
+ v: z.ZodLiteral<"byollm/v1/console">;
3127
+ kind: z.ZodLiteral<"resize">;
3128
+ seq: z.ZodNumber;
3129
+ cols: z.ZodNumber;
3130
+ rows: z.ZodNumber;
3131
+ }, z.core.$strict>, z.ZodObject<{
3132
+ v: z.ZodLiteral<"byollm/v1/console">;
3133
+ kind: z.ZodLiteral<"bye">;
3134
+ seq: z.ZodNumber;
3135
+ reason: z.ZodString;
3136
+ }, z.core.$strict>], "kind">;
3137
+ type ConsoleFrame = z.infer<typeof ConsoleFrame>;
3138
+ /**
3139
+ * The envelope context for a console frame.
3140
+ *
3141
+ * Exported so that neither end computes it: the session id goes in `jobId`
3142
+ * and the direction is derived, and if the two ends disagreed about either,
3143
+ * every envelope would fail to open with `not-for-us` — a failure that looks
3144
+ * exactly like an attack.
3145
+ */
3146
+ declare function consoleEnvelope(input: {
3147
+ sessionId: string;
3148
+ from: "browser" | "box";
3149
+ senderKeyId: string;
3150
+ recipientKeyId: string;
3151
+ deadlineAt: number;
3152
+ }): EnvelopeContext;
3153
+ /** Why a frame was refused. Each one is a distinct thing a router can do. */
3154
+ type ConsoleOrderFault =
3155
+ /** Seq went backwards or repeated — the router sent it twice. */
3156
+ "replayed"
3157
+ /** Seq skipped — the router dropped what was between. */
3158
+ | "gap"
3159
+ /** A `hello` that was not the first frame, or a first frame that was not `hello`. */
3160
+ | "out-of-turn"
3161
+ /** A `stdin` from the box, or a `stdout` from the browser. */
3162
+ | "wrong-way"
3163
+ /** Anything after `bye`. The stream is over. */
3164
+ | "closed";
3165
+ type ConsoleOrderResult = {
3166
+ readonly ok: true;
3167
+ } | {
3168
+ readonly ok: false;
3169
+ readonly fault: ConsoleOrderFault;
3170
+ };
3171
+ /**
3172
+ * One direction's ordering rule, which both ends run over what they receive.
3173
+ *
3174
+ * **Strictly +1, not merely increasing.** Increasing would catch replay and
3175
+ * reorder while letting a DROP through silently, and a dropped frame on a
3176
+ * terminal is a truncated command that still runs. There is no benign gap
3177
+ * here to tolerate: the transport underneath is an ordered, reliable stream,
3178
+ * so a gap means something between the ends removed a frame.
3179
+ *
3180
+ * Every fault is fatal to the session by design. A console has no
3181
+ * resynchronisation story that is safe — you cannot ask "what did I miss" of
3182
+ * a party that may be the one who took it.
3183
+ */
3184
+ /**
3185
+ * One direction's receiver-side ordering state.
3186
+ *
3187
+ * Named as an interface rather than inferred, so the box's agent and the
3188
+ * browser hold the SAME type — an inferred one would let the two ends drift
3189
+ * apart without a compiler ever objecting.
3190
+ */
3191
+ interface ConsoleOrder {
3192
+ /** The last sequence accepted. 0 before anything has been. */
3193
+ readonly seen: number;
3194
+ accept(frame: ConsoleFrame): ConsoleOrderResult;
3195
+ }
3196
+ declare function consoleOrder(from: "browser" | "box"): ConsoleOrder;
3197
+
3198
+ export { ABOUT, ABOUT_SHORT, ABOUT_SHORT_LEDE, ABOUT_SHORT_TAIL, AUDIENCES, Audience, BACKENDS, BACKEND_CLASSES, BACKEND_IDS, BackendClass, BackendCost, type BackendDescriptor, type BackendId, BackendIdSchema, CLOCK_ATTRIBUTION_MS, CLOCK_SKEW_WARN_MS, CONSOLE_FRAME_VERSION, CONSOLE_MAX_DATA_BYTES, Capability, CapabilityMatrix, ChatMessage, ChatPayload, ClaimRequest, ClaimResponse, ClaimedJob, ClaimedStub, ConsoleBye, ConsoleFrame, ConsoleHello, type ConsoleOrder, type ConsoleOrderFault, type ConsoleOrderResult, ConsoleResize, ConsoleStdin, ConsoleStdout, DeliveredResult, ENCRYPTION_KEY_CONTEXT, ENDPOINTS, ENVELOPE_MAX_AGE_MS, ERROR_STATUS, type Endpoint, type EnvelopeContext, EnvelopeDirection, type EnvelopeFailure, FetchRequest, FetchResponse, type FloorRefusal, GRANT_CONTEXT, GRANT_MAX_AGE_MS, GRANT_SIGNED_FIELDS, GeneratePayload, type GrantClaims, GrantRef, type GrantRefusal, HeartbeatRequest, HeartbeatResponse, JOB_KINDS, JobKind, JobOutcome, JobPayload, JobRefused, JobResultCanceled, JobResultError, JobResultOk, JobState, JobStub, KindedPayload, Lease, MAX_CLOCK_SKEW_MS, MAX_ENVELOPE_BYTES, MAX_PURPOSES, MAX_SUCCESSION_CHAIN, MIN_PROTOCOL_VERSION, MUSTS, MUST_IDS, Manifest, type MatchDaemon, type MatchJob, MatchRefusal, type MatchResult, type Must, type MustEnforcer, type MustId, type MustVerification, type MustVerifiedBy, OFFER_SCOPES, OfferScope, type OpenResult, PAYLOAD_LIMITS, PROTOCOL_PREFIX, PROTOCOL_VERSION, PairPollRequest, PairPollResponse, PairRequest, PairStartRequest, PairStartResponse, type PayloadFor, PublicIdentity, Purpose, REFUSAL_MESSAGES, REFUSAL_TEXT, RESERVED_PURPOSE, RETIREMENT_WINDOW_MS, RefusalReason, ReleaseRequest, ReleaseResponse, RequestSignature, ResultDisposition, ResultProvenance, ResultRequest, ResultResponse, RunMetadata, SIZE_CLASSES, SIZE_CLASS_LIMITS, SUCCESSION_CONTEXT, SUPPORTED_PROTOCOL_VERSIONS, SealedEnvelope, SealedOutcome, type SignatureFailure, SignedGrant, SizeClass, type SpendConsent, type StopReason, StopReasonSchema, StoredKeys, Succession, type SuccessionFailure, type SuccessionWalk, TERMINAL_STATES, UPDATE_OFFER_SINCE, UPGRADE_COMMAND, type VersionRefusal, WireError, WireErrorCode, WithheldKind, backendDescriptor, backendName, canTransition, canonicalRequest, checkDaemonFloor, checkProtocolVersion, classifyCost, compareVersions, consoleEnvelope, consoleOrder, cryptoReady, declaredVersion, describeBytes, effectiveOfferScope, envelopeBytes, fingerprint, generateKeys, grantStatement, isBackendId, isCloudTaggedModel, isJobKind, isLocalHost, isTerminal, keyId, kindsOf, matchAudience, mayOfferUpdate, mentionsWireField, mustsVerifiedBy, open, payloadTextLength, provenanceFor, publicIdentityOf, resolveCost, seal, signGrant, signRequest, signSiteRequest, signSuccession, signWith, singlePurposeManifest, sizeClassCeiling, sizeClassOf, successionStatement, tooLargeMessage, updateOfferFor, verifyGrant, verifyLink, verifyPublicIdentity, verifyRequest, verifySiteRequest, verifyWith, walkSuccession, withoutComments };
package/dist/index.js CHANGED
@@ -89,16 +89,16 @@ function verifyPublicIdentity(identity) {
89
89
  return false;
90
90
  }
91
91
  }
92
- function signWith(keys, data) {
93
- return sign(null, data, importPrivate(keys.identityPrivate)).toString(
92
+ function signWith(keys, data2) {
93
+ return sign(null, data2, importPrivate(keys.identityPrivate)).toString(
94
94
  "base64url"
95
95
  );
96
96
  }
97
- function verifyWith(identityPublic, data, signature) {
97
+ function verifyWith(identityPublic, data2, signature) {
98
98
  try {
99
99
  return verify(
100
100
  null,
101
- data,
101
+ data2,
102
102
  importPublic(identityPublic, "Ed25519"),
103
103
  Buffer.from(signature, "base64url")
104
104
  );
@@ -2663,6 +2663,118 @@ var MUST_IDS = Object.freeze(Object.keys(MUSTS));
2663
2663
  function mustsVerifiedBy(kind) {
2664
2664
  return MUST_IDS.filter((id) => kindsOf(MUSTS[id]).includes(kind));
2665
2665
  }
2666
+
2667
+ // src/console.ts
2668
+ import { z as z12 } from "zod";
2669
+ var CONSOLE_FRAME_VERSION = "byollm/v1/console";
2670
+ var CONSOLE_MAX_DATA_BYTES = 64 * 1024;
2671
+ var data = z12.string().max(Math.ceil(CONSOLE_MAX_DATA_BYTES * 4 / 3) + 4).describe("base64");
2672
+ var cols = z12.number().int().min(1).max(1e4);
2673
+ var rows = z12.number().int().min(1).max(1e4);
2674
+ var seq = z12.number().int().positive();
2675
+ var ConsoleHello = z12.object({
2676
+ v: z12.literal(CONSOLE_FRAME_VERSION),
2677
+ kind: z12.literal("hello"),
2678
+ seq: z12.literal(1),
2679
+ /**
2680
+ * The browser's EPHEMERAL identity for this session, and the reason hello
2681
+ * exists as its own frame.
2682
+ *
2683
+ * A browser has no long-term key — it is a tab, not a machine — so it
2684
+ * generates one per session and the box seals its output to it. That key
2685
+ * has to reach the box without the hub being able to substitute one of its
2686
+ * own, which is the classic broker attack. So it travels SEALED TO THE
2687
+ * BOX'S PINNED IDENTITY like every other frame: the hub cannot read it and
2688
+ * cannot replace it, because replacing it means producing a sealed box
2689
+ * the box's key opens and the browser's key signed.
2690
+ *
2691
+ * The box does not pin this. It cannot — it is new every session, and
2692
+ * nothing authorises it cryptographically. What authorises the browser is
2693
+ * the hub's per-session grant (ruling item 2); what this key does is keep
2694
+ * the hub from READING what it authorised.
2695
+ */
2696
+ browser: PublicIdentity,
2697
+ cols,
2698
+ rows
2699
+ }).strict();
2700
+ var ConsoleStdin = z12.object({
2701
+ v: z12.literal(CONSOLE_FRAME_VERSION),
2702
+ /** Browser→box only. A `stdin` arriving from the box is `wrong-way`. */
2703
+ kind: z12.literal("stdin"),
2704
+ seq,
2705
+ data
2706
+ }).strict();
2707
+ var ConsoleStdout = z12.object({
2708
+ v: z12.literal(CONSOLE_FRAME_VERSION),
2709
+ /** Box→browser only. */
2710
+ kind: z12.literal("stdout"),
2711
+ seq,
2712
+ data
2713
+ }).strict();
2714
+ var ConsoleResize = z12.object({
2715
+ v: z12.literal(CONSOLE_FRAME_VERSION),
2716
+ kind: z12.literal("resize"),
2717
+ seq,
2718
+ cols,
2719
+ rows
2720
+ }).strict();
2721
+ var ConsoleBye = z12.object({
2722
+ v: z12.literal(CONSOLE_FRAME_VERSION),
2723
+ kind: z12.literal("bye"),
2724
+ seq,
2725
+ /** Shown to the owner in the session feed, so it is a sentence. */
2726
+ reason: z12.string().min(1).max(200)
2727
+ }).strict();
2728
+ var ConsoleFrame = z12.discriminatedUnion("kind", [
2729
+ ConsoleHello,
2730
+ ConsoleStdin,
2731
+ ConsoleStdout,
2732
+ ConsoleResize,
2733
+ ConsoleBye
2734
+ ]);
2735
+ function consoleEnvelope(input) {
2736
+ return {
2737
+ jobId: input.sessionId,
2738
+ senderKeyId: input.senderKeyId,
2739
+ recipientKeyId: input.recipientKeyId,
2740
+ deadlineAt: input.deadlineAt,
2741
+ direction: input.from === "browser" ? "payload" : "result"
2742
+ };
2743
+ }
2744
+ function consoleOrder(from) {
2745
+ const maySend = {
2746
+ // The browser drives: it opens, it types, it sets the size, it leaves.
2747
+ browser: ["hello", "stdin", "resize", "bye"],
2748
+ // The box answers, and can end a session. Nothing else.
2749
+ box: ["stdout", "bye"]
2750
+ };
2751
+ const allowed = maySend[from];
2752
+ const opensWithHello = from === "browser";
2753
+ let last = 0;
2754
+ let closed = false;
2755
+ return {
2756
+ /** The last sequence accepted. 0 before anything has been. */
2757
+ get seen() {
2758
+ return last;
2759
+ },
2760
+ accept(frame) {
2761
+ if (closed) return { ok: false, fault: "closed" };
2762
+ if (!allowed.includes(frame.kind)) {
2763
+ return { ok: false, fault: "wrong-way" };
2764
+ }
2765
+ const isFirst = last === 0;
2766
+ const wantsHello = isFirst && opensWithHello;
2767
+ if (wantsHello !== (frame.kind === "hello")) {
2768
+ return { ok: false, fault: "out-of-turn" };
2769
+ }
2770
+ if (frame.seq <= last) return { ok: false, fault: "replayed" };
2771
+ if (frame.seq !== last + 1) return { ok: false, fault: "gap" };
2772
+ last = frame.seq;
2773
+ if (frame.kind === "bye") closed = true;
2774
+ return { ok: true };
2775
+ }
2776
+ };
2777
+ }
2666
2778
  export {
2667
2779
  ABOUT,
2668
2780
  ABOUT_SHORT,
@@ -2678,6 +2790,8 @@ export {
2678
2790
  BackendIdSchema,
2679
2791
  CLOCK_ATTRIBUTION_MS,
2680
2792
  CLOCK_SKEW_WARN_MS,
2793
+ CONSOLE_FRAME_VERSION,
2794
+ CONSOLE_MAX_DATA_BYTES,
2681
2795
  Capability,
2682
2796
  CapabilityMatrix,
2683
2797
  ChatMessage,
@@ -2686,6 +2800,12 @@ export {
2686
2800
  ClaimResponse,
2687
2801
  ClaimedJob,
2688
2802
  ClaimedStub,
2803
+ ConsoleBye,
2804
+ ConsoleFrame,
2805
+ ConsoleHello,
2806
+ ConsoleResize,
2807
+ ConsoleStdin,
2808
+ ConsoleStdout,
2689
2809
  DeliveredResult,
2690
2810
  ENCRYPTION_KEY_CONTEXT,
2691
2811
  ENDPOINTS,
@@ -2772,6 +2892,8 @@ export {
2772
2892
  checkProtocolVersion,
2773
2893
  classifyCost,
2774
2894
  compareVersions,
2895
+ consoleEnvelope,
2896
+ consoleOrder,
2775
2897
  cryptoReady,
2776
2898
  declaredVersion,
2777
2899
  describeBytes,